package com.engine.organization.service.impl; import com.engine.core.impl.Service; import com.engine.organization.entity.map.JclOrgMap; import com.engine.organization.entity.version.HrmSubCompanyVersion; import com.engine.organization.enums.ModuleTypeEnum; import com.engine.organization.mapper.jclorgmap.JclOrgMapper; import com.engine.organization.mapper.trigger.CompTriggerMapper; import com.engine.organization.mapper.version.CompanyVersionMapper; import com.engine.organization.service.VersionManageService; import com.engine.organization.util.OrganizationDateUtil; import com.engine.organization.util.db.MapperProxyFactory; import weaver.common.DateUtil; import weaver.hrm.User; import java.sql.Date; import java.util.Calendar; import java.util.Map; /** * @Author weaver_cl * @Description: * @Date 2022/12/8 * @Version V1.0 **/ public class VersionManageServiceImpl extends Service implements VersionManageService { private CompanyVersionMapper getCompanyVersionMapper(){ return MapperProxyFactory.getProxy(CompanyVersionMapper.class); } private JclOrgMapper getJclOrgMapMapper(){ return MapperProxyFactory.getProxy(JclOrgMapper.class); } @Override public void save(ModuleTypeEnum moduleTypeEnum, Map params, User user) { switch (moduleTypeEnum.getValue()){ case 1: saveSubComToMap(params); saveSubComToVersion(params,user); break; case 2: break; case 4: break; default: break; } } /** * 分部保存至map表 */ void saveSubComToMap(Map params) { String id = (String) params.get("id"); String currentDate = OrganizationDateUtil.getFormatLocalDate(new java.util.Date()); JclOrgMap jclOrgMap = new JclOrgMap(); jclOrgMap.setId(Integer.parseInt((String) params.get("id"))); jclOrgMap.setFType(1); jclOrgMap.setFObjId(Integer.parseInt((String) params.get("id"))); jclOrgMap.setFClass(0); jclOrgMap.setFClassName("行政维度"); jclOrgMap.setFName((String) params.get("departmentName")); jclOrgMap.setFParentId(Integer.parseInt((String) params.get("supSubComId"))); jclOrgMap.setFIsVitual(0); jclOrgMap.setFDateBegin(new Date(OrganizationDateUtil.stringToDate(currentDate).getTime())); jclOrgMap.setFDateEnd(new Date(OrganizationDateUtil.stringToDate("2022-12-31").getTime())); JclOrgMap jclOrgMapByFParentId = getJclOrgMapMapper().getJclOrgMapByFParentId(jclOrgMap.getFDateBegin(), id); jclOrgMap.setFPlan(jclOrgMapByFParentId.getFPlan()); jclOrgMap.setFOnJob(jclOrgMapByFParentId.getFOnJob()); Calendar cal = Calendar.getInstance(); cal.setTime(jclOrgMap.getFDateBegin()); Calendar calendar = DateUtil.addDay(cal, -1); Date time = new Date(calendar.getTime().getTime()); MapperProxyFactory.getProxy(CompTriggerMapper.class).deleteMap(jclOrgMap.getFType(), jclOrgMap.getFObjId(), jclOrgMap.getFDateBegin()); MapperProxyFactory.getProxy(CompTriggerMapper.class).updateMap(jclOrgMap.getFType(), jclOrgMap.getFObjId(), jclOrgMap.getFDateBegin(), time); getJclOrgMapMapper().insertMap(jclOrgMap); } /** * 分部保存至版本表 */ void saveSubComToVersion(Map params,User user) { String id = (String) params.get("id"); String currentDate = OrganizationDateUtil.getFormatLocalDate(new java.util.Date()); HrmSubCompanyVersion hrmSubCompanyVersion = new HrmSubCompanyVersion(); hrmSubCompanyVersion.setSubComId(Integer.parseInt(id)); hrmSubCompanyVersion.setSubCompanyDesc((String) params.get("subCompanyDesc")); hrmSubCompanyVersion.setSubCompanyCode((String) params.get("subCompanyCode")); hrmSubCompanyVersion.setSubCompanyName((String) params.get("subCompanyName")); hrmSubCompanyVersion.setSupsSubComId(Integer.parseInt((String) params.get("supSubComId"))); hrmSubCompanyVersion.setShowOrder(Integer.parseInt((String) params.get("showOrder"))); hrmSubCompanyVersion.setCanceled(Integer.parseInt((String) params.get("canceled"))); hrmSubCompanyVersion.setDescription((String) params.get("description")); hrmSubCompanyVersion.setOperator(user.getUsername()); hrmSubCompanyVersion.setVersion(genVersionId(id)); hrmSubCompanyVersion.setOperateTime(new Date(OrganizationDateUtil.stringToDate(currentDate).getTime())); getCompanyVersionMapper().insertHrmSubComVersion(hrmSubCompanyVersion); } /** * 版本号生成 */ private String genVersionId(String sid) { // 版本V1.0 + 0.1 (默认字段) double id = 1.0; HrmSubCompanyVersion hrmSubCompanyVersion = getCompanyVersionMapper().getMaxVersion(sid); if (null != hrmSubCompanyVersion) { id = id + Double.parseDouble(hrmSubCompanyVersion.getVersion()); } return String.valueOf(id); } }