package com.engine.organization.service.impl; import com.engine.core.impl.Service; import com.engine.organization.entity.hrmresource.po.HrmResourcePO; import com.engine.organization.entity.map.JclOrgMap; import com.engine.organization.entity.version.HrmDepartmentVersion; import com.engine.organization.entity.version.HrmResourceVersion; 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.resource.ResourceMapper; 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 org.apache.commons.lang3.StringUtils; import weaver.common.DateUtil; import weaver.conn.RecordSet; import weaver.general.Util; import weaver.hrm.User; import java.sql.Date; import java.sql.Timestamp; 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: saveDeptToVersion(params, user); saveDeptToMap(params); break; case 4: saveHrmToMap(params); saveHrmToVersion(params, user); break; default: break; } } @Override public Map getVersion(ModuleTypeEnum moduleTypeEnum, Map params) { return null; } /** * 分部保存至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("subCompanyName")); String supSubComId = (String) params.get("supSubComId"); 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().getSumPlanAndJobByFParentId(jclOrgMap.getFDateBegin(), String.valueOf(jclOrgMap.getId())); if(jclOrgMapByFParentId !=null){ jclOrgMap.setFPlan(jclOrgMapByFParentId.getFPlan()); jclOrgMap.setFOnJob(jclOrgMapByFParentId.getFOnJob()); }else{ jclOrgMap.setFPlan(0); jclOrgMap.setFOnJob(0); } Calendar cal = Calendar.getInstance(); cal.setTime(jclOrgMap.getFDateBegin()); Calendar calendar = DateUtil.addDay(cal, -1); Date time = new Date(calendar.getTime().getTime()); getJclOrgMapMapper().deleteMap("1", id, jclOrgMap.getFDateBegin()); getJclOrgMapMapper().updateMap("1", id, jclOrgMap.getFDateBegin(), time); getJclOrgMapMapper().insertMap(jclOrgMap); } /** * 部门保存到map表 */ void saveDeptToMap(Map params) { String id = (String) params.get("id"); int st = 100000000; String currentDate = OrganizationDateUtil.getFormatLocalDate(new java.util.Date()); JclOrgMap jclOrgMap = new JclOrgMap(); jclOrgMap.setId(st + Integer.parseInt(id)); jclOrgMap.setFType(2); jclOrgMap.setFObjId(Integer.parseInt(id)); jclOrgMap.setFClass(0); jclOrgMap.setFClassName("行政维度"); String bmfzr = (String) params.get("bmfzr"); if (StringUtils.isNotBlank(bmfzr)) { jclOrgMap.setFLeader(Integer.parseInt(bmfzr)); HrmResourcePO hrmResourcePO = MapperProxyFactory.getProxy(ResourceMapper.class).getResourceById(bmfzr); jclOrgMap.setFLeaderImg(hrmResourcePO.getResourceImageId()); jclOrgMap.setFLeaderName(hrmResourcePO.getLastName()); jclOrgMap.setFLeaderJobId(Math.toIntExact(hrmResourcePO.getJobTitle())); } jclOrgMap.setFName((String) params.get("departmentName")); String subCompanyId1 = (String) params.get("subCompanyId1"); String supdepid = (String) params.get("supDepId"); if (supdepid!=null){ jclOrgMap.setFParentId(st + Integer.parseInt(supdepid)); } if ("0".equals(supdepid)){ jclOrgMap.setFParentId(Integer.parseInt(subCompanyId1)); } jclOrgMap.setFDateBegin(new Date(OrganizationDateUtil.stringToDate(currentDate).getTime())); jclOrgMap.setFDateEnd(new Date(OrganizationDateUtil.stringToDate("2022-12-31").getTime())); jclOrgMap.setFIsVitual(0); JclOrgMap jclOrgMapByFParentId = getJclOrgMapMapper().getSumPlanAndJobByFParentId(jclOrgMap.getFDateBegin(), String.valueOf(jclOrgMap.getId())); if (null != jclOrgMapByFParentId) { jclOrgMap.setFPlan(jclOrgMapByFParentId.getFPlan()); jclOrgMap.setFOnJob(jclOrgMapByFParentId.getFOnJob()); } else { jclOrgMap.setFPlan(0); jclOrgMap.setFOnJob(0); } Calendar cal = Calendar.getInstance(); cal.setTime(jclOrgMap.getFDateBegin()); Calendar calendar = DateUtil.addDay(cal, -1); Date time = new Date(calendar.getTime().getTime()); getJclOrgMapMapper().deleteMap("2", id, jclOrgMap.getFDateBegin()); getJclOrgMapMapper().updateMap("2", id, jclOrgMap.getFDateBegin(), time); getJclOrgMapMapper().insertMap(jclOrgMap); } /** * 人员保存至map */ void saveHrmToMap(Map params){ String id = (String) params.get("id"); String currentDate = OrganizationDateUtil.getFormatLocalDate(new java.util.Date()); int sk = 300000000; RecordSet rs = new RecordSet(); JclOrgMap jclOrgMap = new JclOrgMap(); jclOrgMap.setId(sk + Integer.parseInt(id)); jclOrgMap.setFType(4); jclOrgMap.setFObjId(Integer.parseInt(id)); jclOrgMap.setFClass(0); jclOrgMap.setFClassName("行政维度"); jclOrgMap.setFName((String) params.get("lastname")); if (StringUtils.isNotBlank(id)) { rs.executeQuery("select messagerurl, lastname, jobtitle from hrmresource where id="+id+";"); if (rs.next()){ jclOrgMap.setFLeaderImg(Util.null2String(rs.getString("messagerurl"))); jclOrgMap.setFLeaderName(Util.null2String(rs.getString("lastname"))); jclOrgMap.setFLeaderJobId(Integer.valueOf(rs.getString("jobtitle"))); } } jclOrgMap.setFParentId(sk+Integer.parseInt((String) params.get("jobtitle"))); JclOrgMap jclOrgMapByFParentId = getJclOrgMapMapper().getSumPlanAndJobByFParentId(jclOrgMap.getFDateBegin(), String.valueOf(jclOrgMap.getFParentId())); if (null != jclOrgMapByFParentId) { jclOrgMap.setFPlan(jclOrgMapByFParentId.getFPlan()); jclOrgMap.setFOnJob(jclOrgMapByFParentId.getFOnJob()); } else { jclOrgMap.setFPlan(0); jclOrgMap.setFOnJob(0); } jclOrgMap.setFIsVitual(0); jclOrgMap.setFDateBegin(new Date(OrganizationDateUtil.stringToDate(currentDate).getTime())); jclOrgMap.setFDateEnd(new Date(OrganizationDateUtil.stringToDate("2022-12-31").getTime())); Calendar cal = Calendar.getInstance(); cal.setTime(jclOrgMap.getFDateBegin()); Calendar calendar = DateUtil.addDay(cal, -1); Date time = new Date(calendar.getTime().getTime()); getJclOrgMapMapper().deleteMap("4", id, jclOrgMap.getFDateBegin()); getJclOrgMapMapper().updateMap("4", id, jclOrgMap.getFDateBegin(), time); getJclOrgMapMapper().insertMap(jclOrgMap); } /** * 分部保存至版本表 */ void saveSubComToVersion(Map params,User user) { String id = (String) params.get("id"); String currentDate = OrganizationDateUtil.getFormatLocalDateTime(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"))); String showOrder = (String) params.get("showOrder"); hrmSubCompanyVersion.setShowOrder(null==showOrder ? null : Integer.parseInt(showOrder)); hrmSubCompanyVersion.setCanceled(Integer.parseInt((String) params.get("canceled"))); hrmSubCompanyVersion.setDescription((String) params.get("description")); hrmSubCompanyVersion.setOperator(user.getUsername()); hrmSubCompanyVersion.setVersion(genVersionId(1,id)); hrmSubCompanyVersion.setOperateTime(new Timestamp(OrganizationDateUtil.stringToDateTime(currentDate).getTime())); getCompanyVersionMapper().insertHrmSubComVersion(hrmSubCompanyVersion); } /** * 部门保存至版本 */ void saveDeptToVersion(Map params,User user) { String id = (String) params.get("id"); String currentDate = OrganizationDateUtil.getFormatLocalDateTime(new java.util.Date()); HrmDepartmentVersion hrmDepartmentVersion = new HrmDepartmentVersion(); hrmDepartmentVersion.setDepartmentId(Integer.parseInt(id)); hrmDepartmentVersion.setDepartmentMark((String) params.get("departmentMark")); hrmDepartmentVersion.setDepartmentCode((String) params.get("departmentCode")); hrmDepartmentVersion.setDepartmentName((String) params.get("departmentName")); hrmDepartmentVersion.setSubCompanyId1(Integer.parseInt((String) params.get("subCompanyId1"))); String supDepId = (String) params.get("supDepId"); if (supDepId!=null){ hrmDepartmentVersion.setSupDepId(Integer.parseInt(supDepId)); } String bmfzr = (String) params.get("bmfzr"); if (!"".equals(bmfzr) && bmfzr!=null){ hrmDepartmentVersion.setBmfzr(Integer.parseInt(bmfzr)); } String showOrder = (String) params.get("showOrder"); hrmDepartmentVersion.setShowOrder(null==showOrder ? null : Integer.parseInt(showOrder)); hrmDepartmentVersion.setCanceled(Integer.parseInt((String) params.get("canceled"))); hrmDepartmentVersion.setDescription((String) params.get("description")); hrmDepartmentVersion.setOperator(user.getLastname()); hrmDepartmentVersion.setVersion(genVersionId(2,id)); hrmDepartmentVersion.setOperateTime(new Timestamp(OrganizationDateUtil.stringToDateTime(currentDate).getTime())); getCompanyVersionMapper().insertHrmDeptVersion(hrmDepartmentVersion); } /** * 人员保存至版本 */ void saveHrmToVersion(Map params,User user){ String id = (String) params.get("id"); String currentDate = OrganizationDateUtil.getFormatLocalDateTime(new java.util.Date()); HrmResourceVersion hrmResourceVersion = new HrmResourceVersion(); hrmResourceVersion.setResourceid(Integer.parseInt(id)); /* hrmResourceVersion.setCompanystartdate(new Date(OrganizationDateUtil.stringToDate((String) params.get("companystartdate")).getTime())); hrmResourceVersion.setCompanyworkyear(Integer.parseInt((String) params.get("companyworkyear"))); hrmResourceVersion.setWorkstartdate(new Date(OrganizationDateUtil.stringToDate((String) params.get("workstartdate")).getTime()));*/ hrmResourceVersion.setDepartmentid(Integer.parseInt((String) params.get("departmentid"))); hrmResourceVersion.setDsporder(Double.valueOf((String) params.get("dsporder")).intValue()); hrmResourceVersion.setSubcompanyid1(Integer.parseInt((String) params.get("subcompanyid1"))); hrmResourceVersion.setJobtitle(Integer.parseInt((String) params.get("jobtitle"))); hrmResourceVersion.setMobile((String) params.get("mobile")); hrmResourceVersion.setTelephone((String) params.get("telephone")); String managerid = (String) params.get("managerid"); hrmResourceVersion.setManagerid(StringUtils.isNotBlank(managerid) ? Integer.parseInt(managerid):null); hrmResourceVersion.setLastname((String) params.get("lastname")); hrmResourceVersion.setOperator(user.getLastname()); hrmResourceVersion.setVersion(genVersionId(4,id)); hrmResourceVersion.setOperateTime(new Timestamp(OrganizationDateUtil.stringToDateTime(currentDate).getTime())); getCompanyVersionMapper().insertHrmResourceVersion(hrmResourceVersion); } /** * 版本号生成 */ private Double genVersionId(int fType,String sid) { // 版本V1.0 + 0.1 (默认字段) double id = 1.0; switch (fType) { case 1: HrmSubCompanyVersion hrmSubCompanyVersion = getCompanyVersionMapper().getMaxVersion(sid); if (null != hrmSubCompanyVersion) { id = 0.1 + hrmSubCompanyVersion.getVersion(); } break; case 2: HrmDepartmentVersion hrmDepartmentVersion = getCompanyVersionMapper().getMaxDeptVersion(sid); if (null != hrmDepartmentVersion) { id = 0.1 + hrmDepartmentVersion.getVersion(); } break; case 3: HrmResourceVersion hrmResourceVersion = getCompanyVersionMapper().getMaxHrmVersion(sid); if (null != hrmResourceVersion) { id = 0.1 + hrmResourceVersion.getVersion(); } break; } return id; } }