@ -0,0 +1,26 @@
|
||||
package com.engine.organization.mapper.trigger;
|
||||
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
/**
|
||||
* @author:dxfeng
|
||||
* @createTime: 2022/09/21
|
||||
* @version: 1.0
|
||||
*/
|
||||
public interface StaffTriggerMapper {
|
||||
Integer countCompanyUsers(@Param("ecCompanyId") String ecCompanyId);
|
||||
|
||||
Integer countDepartmentUsers(@Param("ecDepartmentId") String ecDepartmentId);
|
||||
|
||||
Integer countJobUsers(@Param("jobTitle") String jobTitle);
|
||||
|
||||
Integer countAllusers();
|
||||
|
||||
Integer countCompanyStaffNum(@Param("currentDate") String currentDate, @Param("companyId") Long companyId);
|
||||
|
||||
Integer countDepartmentStaffNum(@Param("currentDate") String currentDate, @Param("departmentId") Long departmentId);
|
||||
|
||||
Integer countJobStaffNum(@Param("currentDate") String currentDate, @Param("jobId") Long jobId);
|
||||
|
||||
Integer updateOrgStaffs(@Param("currentDate") String currentDate, @Param("fType") String fType, @Param("fObjId") String fObjId, @Param("fPlan") Integer fPlan, @Param("fOnJob") Integer fOnJob);
|
||||
}
|
@ -0,0 +1,73 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
||||
<mapper namespace="com.engine.organization.mapper.trigger.StaffTriggerMapper">
|
||||
<update id="updateOrgStaffs">
|
||||
update jcl_org_map
|
||||
<set>
|
||||
FPLAN = #{fPlan},
|
||||
FONJOB = #{fOnJob},
|
||||
</set>
|
||||
where FTYPE =#{fType} and FOBJID=#{fObjId}
|
||||
AND FDATEBEGIN <= #{currentDate}
|
||||
AND FDATEEND >= #{currentDate}
|
||||
</update>
|
||||
|
||||
|
||||
<select id="countCompanyUsers" resultType="java.lang.Integer">
|
||||
select count(1)
|
||||
from hrmresource
|
||||
where status <= 3
|
||||
and subcompanyid1 = #{ecCompanyId}
|
||||
</select>
|
||||
<select id="countDepartmentUsers" resultType="java.lang.Integer">
|
||||
select count(1)
|
||||
from hrmresource
|
||||
where status <= 3
|
||||
and departmentid = #{ecDepartmentId}
|
||||
</select>
|
||||
|
||||
<select id="countJobUsers" resultType="java.lang.Integer">
|
||||
select count(1)
|
||||
from hrmresource
|
||||
where status <= 3
|
||||
and jobtitle = #{jobTitle}
|
||||
</select>
|
||||
<select id="countAllusers" resultType="java.lang.Integer">
|
||||
select count(1)
|
||||
from hrmresource
|
||||
where status <= 3
|
||||
</select>
|
||||
<select id="countCompanyStaffNum" resultType="java.lang.Integer">
|
||||
select sum(staff_num)
|
||||
from JCL_ORG_STAFF
|
||||
where plan_id in (select id
|
||||
from JCL_ORG_STAFFPLAN
|
||||
where time_start <= #{currentDate}
|
||||
and time_end >= #{currentDate}
|
||||
and delete_type = 0)
|
||||
and comp_id = #{companyId}
|
||||
and delete_type = 0
|
||||
</select>
|
||||
<select id="countDepartmentStaffNum" resultType="java.lang.Integer">
|
||||
select sum(staff_num)
|
||||
from JCL_ORG_STAFF
|
||||
where plan_id in (select id
|
||||
from JCL_ORG_STAFFPLAN
|
||||
where time_start <= #{currentDate}
|
||||
and time_end >= #{currentDate}
|
||||
and delete_type = 0)
|
||||
and dept_id = #{departmentId}
|
||||
and delete_type = 0
|
||||
</select>
|
||||
<select id="countJobStaffNum" resultType="java.lang.Integer">
|
||||
select sum(staff_num)
|
||||
from JCL_ORG_STAFF
|
||||
where plan_id in (select id
|
||||
from JCL_ORG_STAFFPLAN
|
||||
where time_start <= #{currentDate}
|
||||
and time_end >= #{currentDate}
|
||||
and delete_type = 0)
|
||||
and job_id = #{jobId}
|
||||
and delete_type = 0
|
||||
</select>
|
||||
</mapper>
|
@ -0,0 +1,145 @@
|
||||
package com.engine.organization.thread;
|
||||
|
||||
import com.engine.organization.entity.commom.RecordInfo;
|
||||
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.entity.staff.po.StaffPO;
|
||||
import com.engine.organization.entity.staff.po.StaffPlanPO;
|
||||
import com.engine.organization.mapper.comp.CompMapper;
|
||||
import com.engine.organization.mapper.department.DepartmentMapper;
|
||||
import com.engine.organization.mapper.hrmresource.SystemDataMapper;
|
||||
import com.engine.organization.mapper.job.JobMapper;
|
||||
import com.engine.organization.mapper.staff.StaffPlanMapper;
|
||||
import com.engine.organization.mapper.trigger.StaffTriggerMapper;
|
||||
import com.engine.organization.util.OrganizationDateUtil;
|
||||
import com.engine.organization.util.db.MapperProxyFactory;
|
||||
import com.engine.organization.util.relation.EcHrmRelationUtil;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import weaver.general.Util;
|
||||
|
||||
/**
|
||||
* @author:dxfeng
|
||||
* @createTime: 2022/09/21
|
||||
* @version: 1.0
|
||||
*/
|
||||
public class StaffTriggerRunnable implements Runnable {
|
||||
StaffPO staffPO;
|
||||
|
||||
private StaffPlanMapper getStaffPlanMapper() {
|
||||
return MapperProxyFactory.getProxy(StaffPlanMapper.class);
|
||||
}
|
||||
|
||||
private StaffTriggerMapper getStaffTriggerMapper() {
|
||||
return MapperProxyFactory.getProxy(StaffTriggerMapper.class);
|
||||
}
|
||||
|
||||
private CompMapper getCompMapper() {
|
||||
return MapperProxyFactory.getProxy(CompMapper.class);
|
||||
}
|
||||
|
||||
private DepartmentMapper getDepartmentMapper() {
|
||||
return MapperProxyFactory.getProxy(DepartmentMapper.class);
|
||||
}
|
||||
|
||||
private JobMapper getJobMapper() {
|
||||
return MapperProxyFactory.getProxy(JobMapper.class);
|
||||
}
|
||||
|
||||
private final String currentDate;
|
||||
|
||||
public StaffTriggerRunnable(StaffPO staffPO) {
|
||||
this.staffPO = staffPO;
|
||||
currentDate = OrganizationDateUtil.getFormatLocalDate(new java.util.Date());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (null != staffPO) {
|
||||
StaffPlanPO staffPlanByID = getStaffPlanMapper().getStaffPlanByID(staffPO.getPlanId());
|
||||
if (null != staffPlanByID && StringUtils.isNotBlank(staffPlanByID.getControlDimension())) {
|
||||
String fType = staffPlanByID.getControlDimension();
|
||||
switch (fType) {
|
||||
case "1":
|
||||
// 更新分部编制
|
||||
refreshCompanyStaff(staffPO.getCompId(), 0);
|
||||
break;
|
||||
case "2":
|
||||
// 更新部门编制
|
||||
refreshCompanyStaff(staffPO.getCompId(), 0);
|
||||
refreshDepartmentStaff(staffPO.getDeptId(), 0);
|
||||
break;
|
||||
case "3":
|
||||
// 更新岗位编制
|
||||
refreshCompanyStaff(staffPO.getCompId(), 0);
|
||||
refreshDepartmentStaff(staffPO.getDeptId(), 0);
|
||||
refreshJobStaff(staffPO.getJobId(), 0);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void refreshCompanyStaff(Long companyId, Integer fPlan) {
|
||||
if (null == companyId) {
|
||||
return;
|
||||
}
|
||||
CompPO compPO = getCompMapper().listById(companyId);
|
||||
if (null != compPO) {
|
||||
String ecCompanyId = EcHrmRelationUtil.getEcCompanyId(Util.null2String(companyId));
|
||||
String fObjId = Util.null2String(companyId);
|
||||
int fOnJob = getStaffTriggerMapper().countCompanyUsers(ecCompanyId);
|
||||
Integer staffSum = getStaffTriggerMapper().countCompanyStaffNum(currentDate, companyId);
|
||||
fPlan += null == staffSum ? 0 : staffSum;
|
||||
getStaffTriggerMapper().updateOrgStaffs(currentDate, "1", fObjId, fPlan < 0 ? 0 : fPlan, fOnJob);
|
||||
if (null != compPO.getParentCompany() && 0 != compPO.getParentCompany()) {
|
||||
refreshCompanyStaff(compPO.getParentCompany(), fPlan);
|
||||
} else {
|
||||
refreshGroupStaff(fPlan);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void refreshDepartmentStaff(Long departmentId, Integer fPlan) {
|
||||
if (null == departmentId) {
|
||||
return;
|
||||
}
|
||||
DepartmentPO deptById = getDepartmentMapper().getDeptById(departmentId);
|
||||
if (null != deptById) {
|
||||
String ecDepartmentId = EcHrmRelationUtil.getEcDepartmentId(Util.null2String(departmentId));
|
||||
String fObjId = Util.null2String(departmentId);
|
||||
int fOnJob = getStaffTriggerMapper().countDepartmentUsers(ecDepartmentId);
|
||||
Integer staffSum = getStaffTriggerMapper().countDepartmentStaffNum(currentDate, departmentId);
|
||||
fPlan += null == staffSum ? 0 : staffSum;
|
||||
getStaffTriggerMapper().updateOrgStaffs(currentDate, "2", fObjId, fPlan < 0 ? 0 : fPlan, fOnJob);
|
||||
if (null != deptById.getParentDept() && 0 != deptById.getParentDept()) {
|
||||
refreshDepartmentStaff(deptById.getParentDept(), fPlan);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void refreshJobStaff(Long jobId, Integer fPlan) {
|
||||
if (null == jobId) {
|
||||
return;
|
||||
}
|
||||
JobPO jobById = getJobMapper().getJobById(jobId);
|
||||
if (null != jobById) {
|
||||
String fObjId = Util.null2String(jobId);
|
||||
RecordInfo hrmJobTitleByName = MapperProxyFactory.getProxy(SystemDataMapper.class).getHrmJobTitleByName(jobById.getJobName());
|
||||
int fOnJob = getStaffTriggerMapper().countJobUsers(hrmJobTitleByName.getId());
|
||||
Integer staffSum = getStaffTriggerMapper().countJobStaffNum(currentDate, jobId);
|
||||
fPlan += null == staffSum ? 0 : staffSum;
|
||||
getStaffTriggerMapper().updateOrgStaffs(currentDate, "3", fObjId, fPlan < 0 ? 0 : fPlan, fOnJob);
|
||||
//if (null != jobById.getParentJob() && 0 != jobById.getParentJob()) {
|
||||
// refreshJobStaff(jobById.getParentJob(), fPlan);
|
||||
//}
|
||||
}
|
||||
}
|
||||
|
||||
private void refreshGroupStaff(Integer fPlan) {
|
||||
Integer fOnJob = getStaffTriggerMapper().countAllusers();
|
||||
getStaffTriggerMapper().updateOrgStaffs(currentDate, "0", "0", fPlan < 0 ? 0 : fPlan, fOnJob);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue