从实体类中取值 ,获取修改记录信息,保存修改记录信息

public boolean saveEmployeeBasicInformation(Map<String,Object> map) {
        log.info("map================"+map);
        if(Func.isNotEmpty(map)){
            EmployeeBasicInformation employee = JSONObject.parseObject(JSONObject.toJSONString(map), EmployeeBasicInformation.class);
            log.info("employee============="+employee);
            boolean isUpdate=false;
            if(!Func.isEmpty(employee.getId())){
                isUpdate=true;
            }
            AllEmployeeBasicInformation original=employeeBasicInformationMapper.getOneAllEmployeeInfo(employee.getId(),AuthUtil.getTenantId());//通过id获取原有数据
            saveOrUpdate(employee);
            //将信息保存到用户数据表
            User user = JSONObject.parseObject(JSONObject.toJSONString(map), User.class);
            user.setId(employee.getId());
            user.setCreateDept(employee.getCreateDept());
            user.setCreateTime(employee.getCreateTime());
            user.setUpdateUser(employee.getUpdateUser());
            user.setUpdateTime(employee.getUpdateTime());
            user.setStatus(employee.getStatus());
            user.setIsDeleted(employee.getIsDeleted());
            user.setPassword(DigestUtil.encrypt(EmployeeConstant.default_password));
            log.info("将信息保存到用户数据表user============"+user);
            userClient.saveUser(user);
            if(isUpdate){
                log.info("通过id获取原有数据original======="+original);
                userClient.updateUser(user);
                if(Func.isNotEmpty(original)&&Func.isNotEmpty(map)){
                    saveRecordMsg(original,map);
                }
            }
        }
        return true;
    }
/**
     * 获取修改记录信息,保存修改记录信息
     * @return
     */
    @Transactional(rollbackFor = Exception.class)
    public void saveRecordMsg(AllEmployeeBasicInformation original,Map<String,Object>map){
        String updateTime= new SimpleDateFormat("yyyy-MM-dd HH:mm:SSS").format(new Date());
        String ids=original.getId().toString();
        log.info("保存修改记录信息ids==========="+ids);
        String operationName=map.get("operationName").toString();
        String personName=original.getRealName();
        List<EmployeeBasicInformationUpdateRecord> recordList=new ArrayList<EmployeeBasicInformationUpdateRecord>();
        String[] nameList= EmployeeConstant.EMPLOYEE_INFO.split(",");//属性名称对应的中文名称
        //将实体类转换成map
        Map<String,Object>mapOriginal=JSONObject.parseObject(JSONObject.toJSONString(original),Map.class);//原内容
        for(String name:nameList){
            EmployeeBasicInformationUpdateRecord record=new EmployeeBasicInformationUpdateRecord();
            //修改之前的数据
            if(Func.isNotEmpty(mapOriginal)&& Func.isNotEmpty(map.get(name.split(":")[0]))){
                record.setUpdateItem(name.split(":")[1]);//变更项目
                record.setUpdateTime(updateTime);//修改时间
                record.setOriginalContent(String.valueOf(mapOriginal.get(name.split(":")[0])));//原内容
                record.setUpdateContent(String.valueOf(map.get(name.split(":")[0])));//修改内容
                record.setAfterUpdateContent(String.valueOf(map.get(name.split(":")[0])));//修改后的内容
                record.setUpdatePeople(operationName);//修改人名称
                record.setId(ids);//用户id
                record.setTenantId(AuthUtil.getTenantId());//租户id
                record.setPersonName(personName);
                //将信息插入记录表
                updateRecordServiceImpl.save(record);
            }
        }
    }
package org.springblade.constant;

public interface EmployeeConstant {
    String EMPLOYEE_INFO="idCardNumber:身份证号码,entryDate:入职日期,entryMonths:入职月数,becomeFullMemberDate:转正日期,department:入职部门名称,groups:组别," +
        "groupCode:组编号,position:职位,function:职能(角色),positionRank:职级名称,positionRankCode:职级编号,isMarry:婚否,contractStartDate:合同开始日期," +
        "contractEndDate:合同结束日期,profession:专业,educationBackground:学历,politicsStatus:政治面貌,schoolOfGraduation:毕业院校,censusRegisterAddress:户籍地址," +
        "registeredResidenceType:户口类型,temporaryAddress:暂住地址,emergencyContact:紧急联系人,emergencyContactPhone:紧急联系人电话,workingState:在职状态0在职1离职," +
        "realName:员工姓名,phone:手机,birthday:生日,termContract:合同年限,contractType:合同类型,remark:备注";

     String default_password="123456";
}

 

上一篇:Spring boot中使用Retrofit拦截器增加日志打印功能


下一篇:android开发使用Glide加载图片模糊不清的解决方法