455 lines
18 KiB
Java
455 lines
18 KiB
Java
package com.engine.organization.thread;
|
||
|
||
import com.engine.common.util.ServiceUtil;
|
||
import com.engine.hrm.service.impl.HrmJobServiceImpl;
|
||
import com.engine.hrm.service.impl.OrganizationServiceImpl;
|
||
import com.engine.organization.entity.commom.RecordInfo;
|
||
import com.engine.organization.entity.job.po.JobPO;
|
||
import com.engine.organization.enums.LogModuleNameEnum;
|
||
import com.engine.organization.enums.OperateTypeEnum;
|
||
import com.engine.organization.mapper.hrmresource.SystemDataMapper;
|
||
import com.engine.organization.mapper.job.JobMapper;
|
||
import com.engine.organization.util.OrganizationAssert;
|
||
import com.engine.organization.util.db.MapperProxyFactory;
|
||
import com.engine.organization.util.relation.EcHrmRelationUtil;
|
||
import com.engine.organization.util.relation.ResourceSyncUtil;
|
||
import org.apache.commons.collections.CollectionUtils;
|
||
import weaver.conn.RecordSet;
|
||
import weaver.general.Util;
|
||
import weaver.hrm.User;
|
||
|
||
import java.util.HashMap;
|
||
import java.util.List;
|
||
import java.util.Map;
|
||
import java.util.stream.Collectors;
|
||
|
||
/**
|
||
* @author:dxfeng
|
||
* @createTime: 2022/08/26
|
||
* @version: 1.0
|
||
*/
|
||
public class OrganizationSyncEc {
|
||
private final LogModuleNameEnum moduleName;
|
||
private final OperateTypeEnum operateType;
|
||
private Map<String, Object> params;
|
||
private final User user;
|
||
private JobPO oldJobPO;
|
||
Map<String, Object> resultMap;
|
||
private boolean throwException = true;
|
||
|
||
private SystemDataMapper getSystemDataMapper() {
|
||
return MapperProxyFactory.getProxy(SystemDataMapper.class);
|
||
}
|
||
|
||
public OrganizationSyncEc(User user, LogModuleNameEnum moduleName, OperateTypeEnum operateType, Map<String, Object> params) {
|
||
this.moduleName = moduleName;
|
||
this.operateType = operateType;
|
||
this.params = params;
|
||
this.user = user;
|
||
}
|
||
|
||
public OrganizationSyncEc(User user, LogModuleNameEnum moduleName, OperateTypeEnum operateType, Map<String, Object> params, boolean throwException) {
|
||
this.moduleName = moduleName;
|
||
this.operateType = operateType;
|
||
this.params = params;
|
||
this.user = user;
|
||
this.throwException = throwException;
|
||
}
|
||
|
||
public OrganizationSyncEc(User user, LogModuleNameEnum moduleName, OperateTypeEnum operateType, Map<String, Object> params, JobPO oldJobPO) {
|
||
this.moduleName = moduleName;
|
||
this.operateType = operateType;
|
||
this.params = params;
|
||
this.user = user;
|
||
this.oldJobPO = oldJobPO;
|
||
}
|
||
|
||
public OrganizationSyncEc(User user, LogModuleNameEnum moduleName, OperateTypeEnum operateType, Map<String, Object> params, JobPO oldJobPO, boolean throwException) {
|
||
this.moduleName = moduleName;
|
||
this.operateType = operateType;
|
||
this.params = params;
|
||
this.user = user;
|
||
this.oldJobPO = oldJobPO;
|
||
this.throwException = throwException;
|
||
}
|
||
|
||
public Map<String, Object> sync() {
|
||
switch (moduleName) {
|
||
case COMPANY:
|
||
refreshCompany();
|
||
break;
|
||
case DEPARTMENT:
|
||
refreshDepartment();
|
||
break;
|
||
case JOB:
|
||
refreshJob();
|
||
break;
|
||
case RESOURCE:
|
||
refreshResource();
|
||
default:
|
||
break;
|
||
}
|
||
if (throwException && null != resultMap) {
|
||
OrganizationAssert.isTrue("1".equals(Util.null2String(resultMap.get("status"))) || "1".equals(Util.null2String(resultMap.get("sign"))), Util.null2String(resultMap.get("message")));
|
||
}
|
||
return resultMap;
|
||
}
|
||
|
||
|
||
/**
|
||
* 刷新HrmSubCompany表数据
|
||
*/
|
||
private void refreshCompany() {
|
||
switch (operateType) {
|
||
case ADD:
|
||
addCompany();
|
||
break;
|
||
case UPDATE:
|
||
updateCompany();
|
||
break;
|
||
case CANCELED:
|
||
cancelCompany();
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 刷新HrmDepartment表数据
|
||
*/
|
||
private void refreshDepartment() {
|
||
switch (operateType) {
|
||
case ADD:
|
||
addDepartment();
|
||
break;
|
||
case UPDATE:
|
||
updateDepartment();
|
||
break;
|
||
case CANCELED:
|
||
cancelDepartment();
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
}
|
||
|
||
private void refreshJob() {
|
||
switch (operateType) {
|
||
case ADD:
|
||
addJob();
|
||
break;
|
||
case UPDATE:
|
||
updateJob();
|
||
break;
|
||
case CANCELED:
|
||
cancelJob();
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
}
|
||
|
||
private void refreshResource() {
|
||
switch (operateType) {
|
||
case ADD:
|
||
addResource();
|
||
break;
|
||
case UPDATE:
|
||
updateResource();
|
||
break;
|
||
case CANCELED:
|
||
default:
|
||
break;
|
||
}
|
||
}
|
||
|
||
private void addResource() {
|
||
Map<String, Object> convertParams = ResourceSyncUtil.convertEcResourceParams(params);
|
||
this.resultMap = ResourceSyncUtil.addResource(user, convertParams);
|
||
}
|
||
|
||
private void updateResource() {
|
||
Map<String, Object> convertParams = ResourceSyncUtil.convertEcResourceParams(params);
|
||
this.resultMap = ResourceSyncUtil.editResourceBase(user, convertParams);
|
||
}
|
||
|
||
|
||
/**
|
||
* 新增岗位
|
||
*
|
||
* <p>
|
||
* 1、EC表HrmJobTitles
|
||
* <p>
|
||
* 2、系统中新建“聚才林”、“默认职务”(sql写入)
|
||
* <p>
|
||
* 3、检索岗位名称jobtitlename,如果已存在,判断是否封存,对已封存数据解封操作
|
||
* <p>
|
||
* 4、如果不存在,在“聚才林--默认职务”下新建岗位
|
||
*/
|
||
private void addJob() {
|
||
// 判断是否存在同名岗位、存在不做处理,不存在,在“默认职务分类--默认职务”下新建岗位
|
||
String jobName = Util.null2String(params.get("job_name"));
|
||
RecordInfo hrmJobActivity = getSystemDataMapper().getHrmJobTitleByName(jobName);
|
||
Map<String, Object> map = new HashMap<>();
|
||
//存在且已封存,对岗位解封
|
||
if (null != hrmJobActivity) {
|
||
map.put("ids", hrmJobActivity.getId());
|
||
map.put("canceled", "docanceled");
|
||
this.resultMap = ServiceUtil.getService(HrmJobServiceImpl.class, user).doCanceled(map, user);
|
||
} else {
|
||
// 不存在则新建职务
|
||
map.put("operateIp", Util.null2String(user.getLoginip()));
|
||
map.put("jobtitlemark", jobName);
|
||
map.put("jobtitlename", jobName);
|
||
map.put("jobactivityid", Util.null2String(params.get("jobactivityid")));
|
||
map.put("jobresponsibility", Util.null2String(params.get("work_duty")));
|
||
map.put("jobcompetency", Util.null2String(params.get("work_authority")));
|
||
map.put("jobtitleremark", Util.null2String(params.get("description")));
|
||
map.put("jobtitlecode", Util.null2String(params.get("job_no")));
|
||
|
||
this.resultMap = ServiceUtil.getService(HrmJobServiceImpl.class, user).addJobTitle(map, user);
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 更新岗位
|
||
*/
|
||
private void updateJob() {
|
||
Long jclJobId = oldJobPO.getId();
|
||
String oldName = oldJobPO.getJobName();
|
||
|
||
String newName = Util.null2String(params.get("job_name"));
|
||
if (newName.equals(oldName)) {
|
||
this.resultMap = new HashMap<>();
|
||
this.resultMap.put("sign", "1");
|
||
return;
|
||
}
|
||
RecordInfo oldHrmJobTitle = getSystemDataMapper().getHrmJobTitleByName(oldName);
|
||
|
||
Map<String, Object> map = new HashMap<>();
|
||
// 修改前不存在共用
|
||
if (EcHrmRelationUtil.isNotExistJob(oldName, jclJobId)) {
|
||
// 修改后不存在共用、直接修改EC岗位表数据
|
||
if (EcHrmRelationUtil.isNotExistJob(newName, jclJobId)) {
|
||
// 查询ec表ID
|
||
RecordInfo hrmJobTitle = getSystemDataMapper().getHrmJobTitleByName(newName);
|
||
if (null != hrmJobTitle) {
|
||
map.put("id", Util.null2String(hrmJobTitle.getId()));
|
||
map.put("operateIp", Util.null2String(user.getLoginip()));
|
||
map.put("jobtitlemark", newName);
|
||
map.put("jobtitlename", newName);
|
||
map.put("jobactivityid", Util.null2String(params.get("jobactivityid")));
|
||
map.put("jobresponsibility", Util.null2String(params.get("work_duty")));
|
||
map.put("jobcompetency", Util.null2String(params.get("work_authority")));
|
||
map.put("jobtitleremark", Util.null2String(params.get("description")));
|
||
map.put("jobtitlecode", Util.null2String(params.get("job_no")) + "_" + System.currentTimeMillis());
|
||
// 修改岗位表数据
|
||
this.resultMap = ServiceUtil.getService(HrmJobServiceImpl.class, user).editJobTitle(map, user);
|
||
} else {
|
||
// 不存在则新建职务
|
||
map.put("operateIp", Util.null2String(user.getLoginip()));
|
||
map.put("jobtitlemark", newName);
|
||
map.put("jobtitlename", newName);
|
||
map.put("jobactivityid", Util.null2String(params.get("jobactivityid")));
|
||
map.put("jobresponsibility", Util.null2String(params.get("work_duty")));
|
||
map.put("jobcompetency", Util.null2String(params.get("work_authority")));
|
||
map.put("jobtitleremark", Util.null2String(params.get("description")));
|
||
map.put("jobtitlecode", Util.null2String(params.get("job_no")) + "_" + System.currentTimeMillis());
|
||
this.resultMap = ServiceUtil.getService(HrmJobServiceImpl.class, user).addJobTitle(map, user);
|
||
}
|
||
} else {
|
||
// 修改后存在共用、不修改岗位表数据,更新对应人员的岗位信息为当前岗位的ID
|
||
RecordInfo hrmJobTitle = getSystemDataMapper().getHrmJobTitleByName(newName);
|
||
// 查询原分部、原岗位下的人员,并更新岗位ID
|
||
List<Long> hrmResourceIds = getSystemDataMapper().getHrmResourceIds(oldJobPO.getParentDept(), oldHrmJobTitle.getId());
|
||
if (CollectionUtils.isNotEmpty(hrmResourceIds)) {
|
||
getSystemDataMapper().updateResourceJobTitleByIds(Util.null2String(hrmJobTitle.getId()), hrmResourceIds);
|
||
}
|
||
// 封存原名称岗位
|
||
map.put("ids", oldHrmJobTitle.getId());
|
||
map.put("canceled", "canceled");
|
||
this.resultMap = ServiceUtil.getService(HrmJobServiceImpl.class, user).doCanceled(map, user);
|
||
}
|
||
} else {
|
||
// 修改前存在共用,不对原有数据进行操作。
|
||
|
||
// 修改后不存在共用、新建岗位,更新原有岗位下人员的岗位ID
|
||
if (EcHrmRelationUtil.isNotExistJob(newName, jclJobId)) {
|
||
RecordInfo hrmJobActivity = getSystemDataMapper().getHrmJobTitleByName(newName);
|
||
//存在且已封存,对岗位解封
|
||
if (null != hrmJobActivity) {
|
||
map.put("ids", hrmJobActivity.getId());
|
||
map.put("canceled", "docanceled");
|
||
this.resultMap = ServiceUtil.getService(HrmJobServiceImpl.class, user).doCanceled(map, user);
|
||
} else {
|
||
// 不存在则新建职务
|
||
map.put("operateIp", Util.null2String(user.getLoginip()));
|
||
map.put("jobtitlemark", newName);
|
||
map.put("jobtitlename", newName);
|
||
map.put("jobactivityid", Util.null2String(params.get("jobactivityid")));
|
||
map.put("jobresponsibility", Util.null2String(params.get("work_duty")));
|
||
map.put("jobcompetency", Util.null2String(params.get("work_authority")));
|
||
map.put("jobtitleremark", Util.null2String(params.get("description")));
|
||
map.put("jobtitlecode", Util.null2String(params.get("job_no")));
|
||
|
||
this.resultMap = ServiceUtil.getService(HrmJobServiceImpl.class, user).addJobTitle(map, user);
|
||
}
|
||
} else {
|
||
this.resultMap = new HashMap<>();
|
||
this.resultMap.put("sign", "1");
|
||
}
|
||
// 查询原分部、原岗位下的人员,并更新岗位ID
|
||
RecordInfo hrmJobTitle = getSystemDataMapper().getHrmJobTitleByName(newName);
|
||
List<Long> hrmResourceIds = getSystemDataMapper().getHrmResourceIds(oldJobPO.getParentDept(), oldHrmJobTitle.getId());
|
||
if (CollectionUtils.isNotEmpty(hrmResourceIds)) {
|
||
getSystemDataMapper().updateResourceJobTitleByIds(Util.null2String(hrmJobTitle.getId()), hrmResourceIds);
|
||
}
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 封存、解封岗位
|
||
*/
|
||
private void cancelJob() {
|
||
Map<String, Object> map = new HashMap<>();
|
||
RecordInfo hrmJobTitleByName = getSystemDataMapper().getHrmJobTitleByName(oldJobPO.getJobName());
|
||
if (null == hrmJobTitleByName) {
|
||
return;
|
||
}
|
||
if (0 == oldJobPO.getForbiddenTag()) {
|
||
// 启用
|
||
map.put("ids", hrmJobTitleByName.getId());
|
||
map.put("canceled", "docanceled");
|
||
this.resultMap = ServiceUtil.getService(HrmJobServiceImpl.class, user).doCanceled(map, user);
|
||
} else {
|
||
// 禁用
|
||
List<JobPO> jobPOS = MapperProxyFactory.getProxy(JobMapper.class).listByNameExceptId(oldJobPO.getJobName(), oldJobPO.getId());
|
||
// 不存在共用
|
||
if (CollectionUtils.isEmpty(jobPOS)) {
|
||
map.put("ids", hrmJobTitleByName.getId());
|
||
map.put("canceled", "canceled");
|
||
this.resultMap = ServiceUtil.getService(HrmJobServiceImpl.class, user).doCanceled(map, user);
|
||
} else {
|
||
List<JobPO> collect = jobPOS.stream().filter(item -> 0 == item.getForbiddenTag()).collect(Collectors.toList());
|
||
// 不存在非禁用
|
||
if (CollectionUtils.isEmpty(collect)) {
|
||
map.put("ids", hrmJobTitleByName.getId());
|
||
map.put("canceled", "canceled");
|
||
this.resultMap = ServiceUtil.getService(HrmJobServiceImpl.class, user).doCanceled(map, user);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 新增部门
|
||
*/
|
||
private void addDepartment() {
|
||
this.resultMap = ServiceUtil.getService(OrganizationServiceImpl.class, user).addDepartment(params, user);
|
||
}
|
||
|
||
/**
|
||
* 封存、解封部门
|
||
*/
|
||
private void cancelDepartment() {
|
||
String forbiddenTag = Util.null2String(params.get("forbiddenTag"));
|
||
if ("0".equals(forbiddenTag)) {
|
||
// 解封
|
||
this.resultMap = ServiceUtil.getService(OrganizationServiceImpl.class, user).doDepartmentISCanceled(params, user);
|
||
} else {
|
||
// 封存
|
||
this.resultMap = ServiceUtil.getService(OrganizationServiceImpl.class, user).doDepartmentCancel(params, user);
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 更新部门
|
||
*/
|
||
private void updateDepartment() {
|
||
Map<String, Object> map = new HashMap<>();
|
||
buildEcDepartmentData(map);
|
||
map.putAll(params);
|
||
this.resultMap = ServiceUtil.getService(OrganizationServiceImpl.class, user).editDepartment(map, user);
|
||
}
|
||
|
||
/**
|
||
* 新增分部
|
||
*/
|
||
private void addCompany() {
|
||
this.resultMap = ServiceUtil.getService(OrganizationServiceImpl.class, user).addSubCompany(params, user);
|
||
}
|
||
|
||
/**
|
||
* 更新分部
|
||
*/
|
||
private void updateCompany() {
|
||
Map<String, Object> map = new HashMap<>();
|
||
buildEcCompanyData(map);
|
||
map.putAll(params);
|
||
this.resultMap = ServiceUtil.getService(OrganizationServiceImpl.class, user).editSubCompany(map, user);
|
||
}
|
||
|
||
/**
|
||
* 封存、解封分部
|
||
*/
|
||
private void cancelCompany() {
|
||
// TODO
|
||
String forbiddenTag = Util.null2String(params.get("forbiddenTag"));
|
||
if ("0".equals(forbiddenTag)) {
|
||
// 解封
|
||
this.resultMap = ServiceUtil.getService(OrganizationServiceImpl.class, user).doSubCompanyISCanceled(params, user);
|
||
} else {
|
||
// 删除封存、禁用封存
|
||
this.resultMap = ServiceUtil.getService(OrganizationServiceImpl.class, user).doSubCompanyCancel(params, user);
|
||
}
|
||
}
|
||
|
||
private void buildEcCompanyData(Map<String, Object> map) {
|
||
String ecCompanyId = Util.null2String(params.get("id"));
|
||
|
||
map.put("id", ecCompanyId);
|
||
RecordSet rs = new RecordSet();
|
||
// 先查拓展表
|
||
rs.execute("select * from hrmsubcompanydefined where subcomid = '" + ecCompanyId + "'");
|
||
int colcount = rs.getColCounts();
|
||
if (rs.next()) {
|
||
for (int i = 1; i <= colcount; i++) {
|
||
map.put(rs.getColumnName(i).toLowerCase(), Util.null2String(rs.getString(i)));
|
||
}
|
||
}
|
||
// 再查主表
|
||
rs.execute("select * from hrmsubcompany where id = '" + ecCompanyId + "'");
|
||
colcount = rs.getColCounts();
|
||
if (rs.next()) {
|
||
for (int i = 1; i <= colcount; i++) {
|
||
map.put(rs.getColumnName(i).toLowerCase(), Util.null2String(rs.getString(i)));
|
||
}
|
||
}
|
||
}
|
||
|
||
private void buildEcDepartmentData(Map<String, Object> map) {
|
||
String ecDepartment = Util.null2String(params.get("id"));
|
||
|
||
map.put("id", ecDepartment);
|
||
RecordSet rs = new RecordSet();
|
||
// 先查拓展表
|
||
rs.execute("select * from hrmdepartmentdefined where deptid = '" + ecDepartment + "'");
|
||
int colcount = rs.getColCounts();
|
||
if (rs.next()) {
|
||
for (int i = 1; i <= colcount; i++) {
|
||
map.put(rs.getColumnName(i).toLowerCase(), Util.null2String(rs.getString(i)));
|
||
}
|
||
}
|
||
// 再查主表
|
||
rs.execute("select * from hrmdepartment where id = '" + ecDepartment + "'");
|
||
colcount = rs.getColCounts();
|
||
if (rs.next()) {
|
||
for (int i = 1; i <= colcount; i++) {
|
||
map.put(rs.getColumnName(i).toLowerCase(), Util.null2String(rs.getString(i)));
|
||
}
|
||
}
|
||
}
|
||
|
||
}
|