package com.engine.organization.trigger.cusfielddata; import com.engine.organization.entity.commom.RecordInfo; import com.engine.organization.entity.cusfielddata.po.CusFieldData; import com.engine.organization.entity.extend.param.ExtendInfoParams; import com.engine.organization.entity.job.po.JobPO; import com.engine.organization.entity.postion.po.PostInfoPO; import com.engine.organization.entity.postion.po.PostPO; import com.engine.organization.entity.scheme.po.GradePO; import com.engine.organization.entity.scheme.po.LevelPO; import com.engine.organization.entity.scheme.po.SchemePO; import com.engine.organization.entity.sequence.po.SequencePO; import com.engine.organization.mapper.extend.ExtMapper; import com.engine.organization.mapper.hrmresource.SystemDataMapper; import com.engine.organization.mapper.job.JobMapper; import com.engine.organization.mapper.post.PostInfoMapper; import com.engine.organization.mapper.post.PostMapper; import com.engine.organization.mapper.scheme.GradeMapper; import com.engine.organization.mapper.scheme.LevelMapper; import com.engine.organization.mapper.scheme.SchemeMapper; import com.engine.organization.mapper.sequence.SequenceMapper; import com.engine.organization.thread.HrmResourceTriggerRunnable; import com.engine.organization.util.db.MapperProxyFactory; import com.wbi.util.Util; import org.apache.commons.lang3.StringUtils; import java.util.HashMap; import java.util.Map; /** * @author:dxfeng * @createTime: 2022/08/01 * @version: 1.0 */ public class CusFieldDataTrigger { public static void run(Long id) { if (null == id) { // 查询人员表最新插入的ID id = MapperProxyFactory.getProxy(SystemDataMapper.class).getHrmResourceMaxId(); if (null == id) { return; } } boolean updateFlag = false; // 查询当前操作的数据 CusFieldData sourceData = MapperProxyFactory.getProxy(SystemDataMapper.class).getHrmCusFieldDataByIdAndScopeId(id, -1L); String sourceField100001 = sourceData.getField100001(); String sourceField100002 = sourceData.getField100002(); String sourceField100003 = sourceData.getField100003(); // 查询需要更新的数据,没有则创建数据 CusFieldData directionData = MapperProxyFactory.getProxy(SystemDataMapper.class).getHrmCusFieldDataByIdAndScopeId(id, 3L); if (null == directionData) { directionData = new CusFieldData(); directionData.setScope("HrmCustomFieldByInfoType"); directionData.setScopeId(3L); directionData.setId(id); MapperProxyFactory.getProxy(SystemDataMapper.class).insertCusFieldData(directionData); } // field100002更新 if (StringUtils.isNotBlank(sourceField100002)) { directionData.setField100002(sourceField100002); Long gwId = Long.parseLong(sourceField100002); JobPO jobById = MapperProxyFactory.getProxy(JobMapper.class).getJobById(gwId); if (null != jobById) { RecordInfo hrmJobTitleByName = MapperProxyFactory.getProxy(SystemDataMapper.class).getHrmJobTitleByName(jobById.getJobName()); Long ecGwId = StringUtils.isNotBlank(hrmJobTitleByName.getId()) ? Long.parseLong(hrmJobTitleByName.getId()) : null; Long ecBmId = jobById.getEcDepartment(); Long ecGsId = jobById.getEcCompany(); Map hrmResourceMap = new HashMap<>(); // 岗位 hrmResourceMap.put("jobtitle", ecGwId); // 部门 hrmResourceMap.put("departmentid", ecBmId); // 公司 hrmResourceMap.put("subcompanyid1", ecGsId); MapperProxyFactory.getProxy(ExtMapper.class).updateTable(ExtendInfoParams.builder().id(id).tableName("hrmresource").params(hrmResourceMap).build()); updateFlag = true; // 职等职级为空,从岗位取值、更新 if (StringUtils.isBlank(sourceField100001)) { if (StringUtils.isNotBlank(jobById.getLevelId())) { // 通过岗位关联,如有多个职等,选取第一个 String[] levelArray = jobById.getLevelId().split(","); LevelPO levelByID = MapperProxyFactory.getProxy(LevelMapper.class).getLevelByID(Long.parseLong(levelArray[0])); directionData.setField100008(levelByID.getLevelName()); } else { directionData.setField100008(null); } // 职等职级方案 if (StringUtils.isNotBlank(Util.null2String(jobById.getSchemeId()))) { SchemePO schemeByID = MapperProxyFactory.getProxy(SchemeMapper.class).getSchemeByID(jobById.getSchemeId()); directionData.setField100006(schemeByID.getSchemeName()); } else { directionData.setField100006(null); } // 职级 if (StringUtils.isNotBlank(jobById.getGradeId())) { GradePO gradeByLevelId = MapperProxyFactory.getProxy(GradeMapper.class).getGradeByID(Long.parseLong(jobById.getGradeId())); directionData.setField100007(gradeByLevelId.getGradeName()); } else { directionData.setField100007(null); } // 岗位序列 if (StringUtils.isNotBlank(Util.null2String(jobById.getSequenceId()))) { SequencePO sequenceBySchemeId = MapperProxyFactory.getProxy(SequenceMapper.class).getSequenceByID(jobById.getSequenceId()); directionData.setField100005(sequenceBySchemeId.getSequenceName()); } else { directionData.setField100005(null); } } } } else { directionData.setField100002(null); directionData.setField100008(null); directionData.setField100006(null); directionData.setField100007(null); directionData.setField100005(null); } // field100001更新,职等职级 if (null != sourceField100001 && sourceField100001.split("A").length == 3 && !sourceField100001.equals(directionData.getField100001())) { directionData.setField100001(sourceField100001); String[] field100001Array = sourceField100001.split("A"); // 职等 long zdId = Long.parseLong(field100001Array[2]); long zjId = Long.parseLong(field100001Array[1]); long xlId = Long.parseLong(field100001Array[0].split("_")[1]); LevelPO levelByID = MapperProxyFactory.getProxy(LevelMapper.class).getLevelByID(zdId); directionData.setField100008(levelByID.getLevelName()); // 职等职级方案 SchemePO schemeByID = MapperProxyFactory.getProxy(SchemeMapper.class).getSchemeByID(levelByID.getSchemeId()); directionData.setField100006(schemeByID.getSchemeName()); // 职级 GradePO gradeByLevelId = MapperProxyFactory.getProxy(GradeMapper.class).getGradeByID(zjId); directionData.setField100007(gradeByLevelId.getGradeName()); // 岗位序列 SequencePO sequenceBySchemeId = MapperProxyFactory.getProxy(SequenceMapper.class).getSequenceByID(xlId); directionData.setField100005(sequenceBySchemeId.getSequenceName()); updateFlag = true; } if (null != sourceField100003 && sourceField100003.split("_").length == 2 && !sourceField100003.equals(directionData.getField100003())) { directionData.setField100003(sourceField100003); String[] field100003Array = sourceField100003.split("_"); long zwId = Long.parseLong(field100003Array[1]); // 职务 PostInfoPO postInfoByID = MapperProxyFactory.getProxy(PostInfoMapper.class).getPostInfoByID(zwId); directionData.setField100010(postInfoByID.getPostInfoName()); // 职务分类 PostPO postByID = MapperProxyFactory.getProxy(PostMapper.class).getPostByID(postInfoByID.getPostId()); directionData.setField100009(postByID.getPostName()); updateFlag = true; } // 更新数据 if (updateFlag) { MapperProxyFactory.getProxy(SystemDataMapper.class).updateCusFieldData(directionData); } // 刷新组织结构图 new Thread(new HrmResourceTriggerRunnable(id)).start(); } }