package com.engine.organization.thread; import com.alibaba.fastjson.JSONObject; import com.engine.organization.entity.company.po.CompPO; import com.engine.organization.entity.extend.param.ExtendInfoParams; import com.engine.organization.entity.logview.bo.FieldBaseEquator; import com.engine.organization.mapper.comp.CompMapper; import com.engine.organization.mapper.extend.ExtMapper; import com.engine.organization.mapper.trigger.CompTriggerMapper; import com.engine.organization.util.OrganizationDateUtil; import com.engine.organization.util.db.MapperProxyFactory; import org.apache.commons.collections.CollectionUtils; import weaver.common.DateUtil; import weaver.hrm.passwordprotection.domain.HrmResource; import java.sql.Date; import java.util.Calendar; import java.util.HashMap; import java.util.List; import java.util.Map; /** * @author:dxfeng * @createTime: 2022/08/30 * @version: 1.0 */ public class CompanyTriggerRunnable implements Runnable { private final CompPO oldCompany; private final CompPO newCompany; private CompTriggerMapper getCompTriggerMapper() { return MapperProxyFactory.getProxy(CompTriggerMapper.class); } public CompanyTriggerRunnable(CompPO oldCompany, CompPO newCompany) { this.oldCompany = oldCompany; this.newCompany = newCompany; } public CompanyTriggerRunnable(Long companyId) { this.oldCompany = new CompPO(); this.newCompany = MapperProxyFactory.getProxy(CompMapper.class).listById(companyId); } public CompanyTriggerRunnable(CompPO newCompany) { this.oldCompany = new CompPO(); this.newCompany = newCompany; this.newCompany.setDeleteType(1); } @Override public void run() { FieldBaseEquator fieldBaseEquator = new FieldBaseEquator(); List diffFields = fieldBaseEquator.getDiffFieldList(oldCompany, newCompany); if (CollectionUtils.isEmpty(diffFields)) { return; } // 判断 if (diffFields.contains("compName") || diffFields.contains("compPrincipal") || diffFields.contains("parentCompany") || diffFields.contains("forbiddenTag") || diffFields.contains("deleteType")) { Integer fType = 1; // 更新逻辑 Integer fObjId = newCompany.getId().intValue(); Integer id = newCompany.getId().intValue(); String uuid = newCompany.getUuid(); String fNumber = newCompany.getCompNo(); String fName = newCompany.getCompName(); Integer fLeader = newCompany.getCompPrincipal(); Integer fParentId = null == newCompany.getParentCompany() ? 0 : newCompany.getParentCompany().intValue(); Integer fObjParentId = null == newCompany.getParentCompany() ? 0 : newCompany.getParentCompany().intValue(); // delete Integer fEcId = getCompTriggerMapper().getEcCompanyIdByUuid(uuid); int fClass = 0; String fClassName = "行政维度"; HrmResource hrmResourceById = getCompTriggerMapper().getHrmResourceById(fLeader); String fLeaderImg = ""; String fLeaderName = ""; Integer fLeaderJobId = 0; if (null != hrmResourceById) { fLeaderImg = hrmResourceById.getMessagerurl(); fLeaderName = hrmResourceById.getLastname(); fLeaderJobId = hrmResourceById.getJobtitle(); } String fLeaderJob = getCompTriggerMapper().getJobTitleMarkById(fLeaderJobId); JSONObject cusFieldDataById = getCompTriggerMapper().getCusFieldDataById(fLeader); String fLeaderSt = ""; String fLeaderLv = ""; if (null != cusFieldDataById) { fLeaderSt = cusFieldDataById.getString("field100008"); fLeaderLv = cusFieldDataById.getString("field100007"); } Date fDateBegin = new Date(System.currentTimeMillis()); Date fDateEnd = new Date(OrganizationDateUtil.stringToDate("2099-12-31").getTime()); Integer fPlan = getCompTriggerMapper().sumStaffNum(fDateBegin, fObjId); Integer fonJob = getCompTriggerMapper().countHrmResource(fEcId); int fIsVitual = 0; Calendar cal = Calendar.getInstance(); cal.setTime(fDateBegin); Calendar calendar = DateUtil.addDay(cal, -1); Date time = new Date(calendar.getTime().getTime()); getCompTriggerMapper().deleteMap(fType, fObjId, fDateBegin); getCompTriggerMapper().updateMap(fType, fObjId, fDateBegin, time); if (1 != newCompany.getDeleteType() && 1 != newCompany.getForbiddenTag()) { Map params = new HashMap<>(); params.put("id", id); params.put("ftype", fType); params.put("fobjid", fObjId); params.put("fecid", fEcId); params.put("uuid", uuid); params.put("fclass", fClass); params.put("fclassname", fClassName); params.put("fnumber", fNumber); params.put("fname", fName); params.put("fleader", fLeader); params.put("fleaderimg", fLeaderImg); params.put("fleadername", fLeaderName); params.put("fleaderjobid", fLeaderJobId); params.put("fleaderjob", fLeaderJob); params.put("fleaderlv", fLeaderLv); params.put("fleaderst", fLeaderSt); params.put("fparentid", fParentId); params.put("fobjparentid", fObjParentId); params.put("fplan", null == fPlan ? 0 : fPlan); params.put("fonjob", fonJob); params.put("fisvitual", fIsVitual); params.put("fdatebegin", fDateBegin); params.put("fdateend", fDateEnd); ExtendInfoParams infoParams = ExtendInfoParams.builder().tableName("jcl_org_map").params(params).build(); MapperProxyFactory.getProxy(ExtMapper.class).insertTable(infoParams); } } } }