diff --git a/interface/RefreshPlan.jsp b/interface/RefreshPlan.jsp new file mode 100644 index 00000000..d0522aa0 --- /dev/null +++ b/interface/RefreshPlan.jsp @@ -0,0 +1,63 @@ +<%@ page import="com.engine.organization.thread.CompanyTriggerRunnable" %> +<%@ page import="com.engine.organization.thread.DepartmentTriggerRunnable" %> +<%@ page import="com.engine.organization.thread.JobTriggerRunnable" %> +<%@ page import="org.apache.commons.lang3.StringUtils" %> +<%@ page import="weaver.conn.RecordSet" %> +<%@ page import="weaver.general.Util" %> +<%@ page import="java.util.HashSet" %> +<%@ page import="java.util.Set" %> +<%@ page import="com.engine.organization.util.db.MapperProxyFactory" %> +<%@ page import="com.engine.organization.mapper.job.JobMapper" %> +<%@ page import="com.engine.organization.entity.job.po.JobPO" %> +<%@ page import="com.engine.organization.entity.department.po.DepartmentPO" %> +<%@ page import="com.engine.organization.mapper.department.DepartmentMapper" %> +<%@ page import="com.engine.organization.mapper.comp.CompMapper" %> +<%@ page import="com.engine.organization.entity.company.po.CompPO" %> +<%@ page import="com.engine.organization.initdata.RefreshPlan" %> +<%@ page contentType="text/html; charset=UTF-8" %> +<% + RecordSet rs = new RecordSet(); + // 刷新岗位 + Set jobSet = new HashSet<>(); + Set departmentSet = new HashSet<>(); + Set companySet = new HashSet<>(); + rs.executeQuery("select id, parent_job from jcl_org_job where id not in( select ifnull(parent_job, '') from jcl_org_job where delete_type =0) and delete_type =0"); + while (rs.next()) { + Long jobId = Long.parseLong(Util.null2String(rs.getString("id"))); + JobPO jobPO = MapperProxyFactory.getProxy(JobMapper.class).getJobById(jobId); + RefreshPlan.updateResourceJob(jobId); + new JobTriggerRunnable(jobPO, jobPO).run(); + + String parentJobId = Util.null2String(rs.getString("parent_job")); + if (StringUtils.isNotBlank(parentJobId)) { + RefreshPlan.refreshJob(Long.parseLong(parentJobId), jobSet); + } + } + // 刷新部门 + rs.executeQuery("select id, parent_dept from jcl_org_dept where id not in( select ifnull(parent_dept , '') from jcl_org_dept where delete_type =0) and delete_type =0"); + while (rs.next()) { + Long departmentId = Long.parseLong(Util.null2String(rs.getString("id"))); + DepartmentPO deptById = MapperProxyFactory.getProxy(DepartmentMapper.class).getDeptById(departmentId); + new DepartmentTriggerRunnable(deptById, deptById).run(); + + String parentDepartmentId = Util.null2String(rs.getString("parent_dept")); + if (StringUtils.isNotBlank(parentDepartmentId)) { + RefreshPlan.refreshDepartment(Long.parseLong(parentDepartmentId), departmentSet); + } + } + + // 刷新分部 + rs.executeQuery("select id, parent_company from jcl_org_comp where id not in( select ifnull(parent_company , '') from jcl_org_comp where delete_type =0) and delete_type =0"); + while (rs.next()) { + Long companyId = Long.parseLong(Util.null2String(rs.getString("id"))); + CompPO compPO = MapperProxyFactory.getProxy(CompMapper.class).listById(companyId); + new CompanyTriggerRunnable(compPO, compPO).run(); + + String parentCompanyId = Util.null2String(rs.getString("parent_company")); + if (StringUtils.isNotBlank(parentCompanyId)) { + RefreshPlan.refreshCompany(Long.parseLong(parentCompanyId), companySet); + } + } + out.println("数据刷新完成"); + +%> diff --git a/src/com/engine/organization/initdata/RefreshPlan.java b/src/com/engine/organization/initdata/RefreshPlan.java new file mode 100644 index 00000000..66b3baf2 --- /dev/null +++ b/src/com/engine/organization/initdata/RefreshPlan.java @@ -0,0 +1,87 @@ +package com.engine.organization.initdata; + +import com.engine.organization.entity.company.po.CompPO; +import com.engine.organization.entity.department.po.DepartmentPO; +import com.engine.organization.entity.job.po.JobPO; +import com.engine.organization.mapper.comp.CompMapper; +import com.engine.organization.mapper.department.DepartmentMapper; +import com.engine.organization.mapper.job.JobMapper; +import com.engine.organization.thread.CompanyTriggerRunnable; +import com.engine.organization.thread.DepartmentTriggerRunnable; +import com.engine.organization.thread.HrmResourceTriggerRunnable; +import com.engine.organization.thread.JobTriggerRunnable; +import com.engine.organization.util.db.MapperProxyFactory; +import weaver.conn.RecordSet; + +import java.util.Set; + +/** + * @author:dxfeng + * @createTime: 2022/11/07 + * @version: 1.0 + */ +public class RefreshPlan { + + private static JobMapper getJobMapper() { + return MapperProxyFactory.getProxy(JobMapper.class); + } + + private static CompMapper getCompMapper() { + return MapperProxyFactory.getProxy(CompMapper.class); + } + + private static DepartmentMapper getDepartmentMapper() { + return MapperProxyFactory.getProxy(DepartmentMapper.class); + } + + // 递归刷新岗位 + public static void refreshJob(Long parentJobId, Set jobSet) { + if (null == parentJobId || jobSet.contains(parentJobId)) { + return; + } + // 获取父级岗位、同步数据 + JobPO jobById = getJobMapper().getJobById(parentJobId); + if (null != jobById) { + updateResourceJob(parentJobId); + new JobTriggerRunnable(jobById, jobById).run(); + refreshJob(jobById.getParentJob(), jobSet); + } + jobSet.add(parentJobId); + } + + // 递归刷新部门 + public static void refreshDepartment(Long parentDepartmentId, Set departmentSet) { + if (null == parentDepartmentId || departmentSet.contains(parentDepartmentId)) { + return; + } + // 获取父级岗位、同步数据 + DepartmentPO deptById = getDepartmentMapper().getDeptById(parentDepartmentId); + if (null != deptById) { + new DepartmentTriggerRunnable(deptById, deptById).run(); + refreshDepartment(deptById.getParentDept(), departmentSet); + } + departmentSet.add(parentDepartmentId); + } + + public static void refreshCompany(Long parentCompanyId, Set companySet) { + if (null == parentCompanyId || companySet.contains(parentCompanyId)) { + return; + } + // 获取父级分部、同步数据 + CompPO compPO = getCompMapper().listById(parentCompanyId); + if (null != compPO) { + new CompanyTriggerRunnable(compPO, compPO).run(); + refreshCompany(compPO.getParentCompany(), companySet); + } + companySet.add(parentCompanyId); + } + + public static void updateResourceJob(Long jobId) { + RecordSet rs = new RecordSet(); + rs.executeQuery("select id from cus_fielddata where scope = 'hrmcustomfieldbyinfotype' and scopeid = -1 and field100002 = ?", jobId); + while (rs.next()) { + Long resourceId = Long.parseLong(rs.getString("id")); + new HrmResourceTriggerRunnable(resourceId).run(); + } + } +} diff --git a/src/com/engine/organization/thread/DepartmentTriggerRunnable.java b/src/com/engine/organization/thread/DepartmentTriggerRunnable.java index 94021377..1f6421c7 100644 --- a/src/com/engine/organization/thread/DepartmentTriggerRunnable.java +++ b/src/com/engine/organization/thread/DepartmentTriggerRunnable.java @@ -2,7 +2,6 @@ package com.engine.organization.thread; import com.engine.organization.entity.cusfielddata.po.CusFieldData; import com.engine.organization.entity.department.po.DepartmentPO; -import com.engine.organization.entity.logview.bo.FieldBaseEquator; import com.engine.organization.entity.map.JclOrgMap; import com.engine.organization.entity.staff.po.StaffPO; import com.engine.organization.enums.ModuleTypeEnum; @@ -13,14 +12,12 @@ import com.engine.organization.mapper.trigger.CompTriggerMapper; import com.engine.organization.mapper.trigger.DepartmentTriggerMapper; 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.general.Util; import weaver.hrm.passwordprotection.domain.HrmResource; import java.sql.Date; import java.util.Calendar; -import java.util.List; /** * @author:dxfeng @@ -78,11 +75,6 @@ public class DepartmentTriggerRunnable implements Runnable { @Override public void run() { - FieldBaseEquator fieldBaseEquator = new FieldBaseEquator(); - List diffFields = fieldBaseEquator.getDiffFieldList(oldDepartment, newDepartment); - if (CollectionUtils.isEmpty(diffFields)) { - return; - } // 判断 JclOrgMap jclMap = new JclOrgMap(); diff --git a/src/com/engine/organization/thread/JobTriggerRunnable.java b/src/com/engine/organization/thread/JobTriggerRunnable.java index 81effe44..95bf6746 100644 --- a/src/com/engine/organization/thread/JobTriggerRunnable.java +++ b/src/com/engine/organization/thread/JobTriggerRunnable.java @@ -1,7 +1,6 @@ package com.engine.organization.thread; import com.engine.organization.entity.job.po.JobPO; -import com.engine.organization.entity.logview.bo.FieldBaseEquator; import com.engine.organization.entity.map.JclOrgMap; import com.engine.organization.entity.staff.po.StaffPO; import com.engine.organization.enums.ModuleTypeEnum; @@ -12,12 +11,11 @@ import com.engine.organization.mapper.trigger.CompTriggerMapper; import com.engine.organization.mapper.trigger.JobTriggerMapper; 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.general.Util; import java.sql.Date; import java.util.Calendar; -import java.util.List; /** * @author:dxfeng @@ -67,11 +65,6 @@ public class JobTriggerRunnable implements Runnable { @Override public void run() { - FieldBaseEquator fieldBaseEquator = new FieldBaseEquator(); - List diffFields = fieldBaseEquator.getDiffFieldList(oldJob, newJob); - if (CollectionUtils.isEmpty(diffFields)) { - return; - } // 判断 JclOrgMap jclMap = new JclOrgMap(); int st = 100000000; @@ -132,7 +125,7 @@ public class JobTriggerRunnable implements Runnable { getCompTriggerMapper().deleteMap(jclMap.getFType(), jclMap.getFObjId(), jclMap.getFDateBegin()); getCompTriggerMapper().updateMap(jclMap.getFType(), jclMap.getFObjId(), jclMap.getFDateBegin(), time); - if (1 != newJob.getDeleteType() && 1 != newJob.getForbiddenTag()) { + if (!"1".equals(Util.null2String(newJob.getDeleteType())) && !"1".equals(Util.null2String(newJob.getForbiddenTag()))) { MapperProxyFactory.getProxy(JclOrgMapper.class).insertMap(jclMap); } if (null != jclOrgMapByObjID) {