部门合并重写
This commit is contained in:
parent
70aa760abc
commit
f6c41a3467
|
|
@ -0,0 +1,20 @@
|
|||
package com.engine.organization.entity.fieldset.param;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* @author:dxfeng
|
||||
* @createTime: 2022/09/08
|
||||
* @version: 1.0
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class FieldTransferParam {
|
||||
private String id;
|
||||
private String name;
|
||||
}
|
||||
|
|
@ -43,6 +43,8 @@ public interface SystemDataMapper {
|
|||
|
||||
List<Long> getHrmResourceIds(@Param("departmentId") Long departmentId, @Param("jobTitle") String jobTitle);
|
||||
|
||||
List<Long> getHrmResourceIdsByDept(@Param("departmentId") String departmentId);
|
||||
|
||||
/**
|
||||
* 更新人员岗位
|
||||
*
|
||||
|
|
|
|||
|
|
@ -181,6 +181,11 @@
|
|||
select max(id)
|
||||
from hrmresource
|
||||
</select>
|
||||
<select id="getHrmResourceIdsByDept" resultType="java.lang.Long">
|
||||
select id
|
||||
from hrmresource
|
||||
where departmentid = #{departmentId}
|
||||
</select>
|
||||
|
||||
|
||||
</mapper>
|
||||
|
|
@ -206,6 +206,8 @@ public class CompServiceImpl extends Service implements CompService {
|
|||
String ecCompany = Util.null2String(params.get("ec_company"));
|
||||
if (StringUtils.isNotBlank(ecCompany)) {
|
||||
params.put("parent_company", EcHrmRelationUtil.getJclCompanyId(ecCompany).getId());
|
||||
}else{
|
||||
params.put("parent_company", "");
|
||||
}
|
||||
new OrganizationSyncEc(user, LogModuleNameEnum.COMPANY, OperateTypeEnum.UPDATE, params).sync();
|
||||
// 更新主表数据
|
||||
|
|
@ -371,6 +373,8 @@ public class CompServiceImpl extends Service implements CompService {
|
|||
CompPO jclCompanyId = EcHrmRelationUtil.getJclCompanyId(targetCompanyId + "");
|
||||
if (null != jclCompanyId) {
|
||||
compPO.setParentCompany(jclCompanyId.getId());
|
||||
} else {
|
||||
compPO.setParentCompany(null);
|
||||
}
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("id", compPO.getId());
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ import com.engine.common.util.ServiceUtil;
|
|||
import com.engine.core.impl.Service;
|
||||
import com.engine.hrm.entity.RuleCodeType;
|
||||
import com.engine.organization.component.OrganizationWeaTable;
|
||||
import com.engine.organization.entity.DeleteParam;
|
||||
import com.engine.organization.entity.codesetting.po.CodeRulePO;
|
||||
import com.engine.organization.entity.commom.RecordInfo;
|
||||
import com.engine.organization.entity.company.bo.CompBO;
|
||||
|
|
@ -38,6 +39,7 @@ import com.engine.organization.mapper.job.JobMapper;
|
|||
import com.engine.organization.service.DepartmentService;
|
||||
import com.engine.organization.service.ExtService;
|
||||
import com.engine.organization.thread.DepartmentTriggerRunnable;
|
||||
import com.engine.organization.thread.HrmResourceTriggerRunnable;
|
||||
import com.engine.organization.thread.JobTriggerRunnable;
|
||||
import com.engine.organization.thread.OrganizationSyncEc;
|
||||
import com.engine.organization.util.*;
|
||||
|
|
@ -50,6 +52,7 @@ import com.engine.organization.util.relation.EcHrmRelationUtil;
|
|||
import com.engine.organization.util.tree.SearchTreeUtil;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import weaver.conn.RecordSet;
|
||||
import weaver.general.StringUtil;
|
||||
import weaver.general.Util;
|
||||
import weaver.hrm.User;
|
||||
|
|
@ -293,6 +296,8 @@ public class DepartmentServiceImpl extends Service implements DepartmentService
|
|||
params.put("ec_company", EcHrmRelationUtil.getEcCompanyId(jclDepartmentId.getParentComp() + ""));
|
||||
}
|
||||
|
||||
} else {
|
||||
params.put("parent_dept", "");
|
||||
}
|
||||
new OrganizationSyncEc(user, LogModuleNameEnum.DEPARTMENT, OperateTypeEnum.UPDATE, params).sync();
|
||||
// 更新主表数据
|
||||
|
|
@ -307,7 +312,8 @@ public class DepartmentServiceImpl extends Service implements DepartmentService
|
|||
// 刷新岗位所属分部
|
||||
refreshJobComp(searchParam.getId(), parentComp);
|
||||
List<DepartmentPO> childList = getDepartmentMapper().getDeptListByPId(searchParam.getId());
|
||||
forbiddenChildTag(parentComp, childList, false);
|
||||
String ecCompanyId = EcHrmRelationUtil.getEcCompanyId(Util.null2String(parentComp));
|
||||
forbiddenChildTag(parentComp, ecCompanyId, childList);
|
||||
|
||||
return searchParam.getId();
|
||||
}
|
||||
|
|
@ -549,19 +555,20 @@ public class DepartmentServiceImpl extends Service implements DepartmentService
|
|||
|
||||
@Override
|
||||
public int mergeDepartment(DepartmentMergeParam mergeParam) {
|
||||
//TODO 逻辑重写,被合并部门,子元素全部转移。被合并部门删除、封存
|
||||
HasRightUtil.hasRight(user, RIGHT_NAME, false);
|
||||
int updateCount;
|
||||
// 被合并部门
|
||||
Long ecParamDepartment = mergeParam.getDepartment();
|
||||
DepartmentPO jclDepartmentId = EcHrmRelationUtil.getJclDepartmentId(ecParamDepartment + "");
|
||||
Long jclParamDepartment = jclDepartmentId.getId();
|
||||
OrganizationAssert.isFalse(mergeParam.getId().equals(jclParamDepartment), "所选部门与待合并部门一致,无需操作");
|
||||
DepartmentPO targetDepartment = EcHrmRelationUtil.getJclDepartmentId(ecParamDepartment + "");
|
||||
|
||||
// 断言判断
|
||||
OrganizationAssert.isFalse(null == targetDepartment, "被合并部门数据有误,暂时无法合并");
|
||||
OrganizationAssert.isFalse(mergeParam.getId().equals(targetDepartment.getId()), "所选部门与待合并部门一致,无需操作");
|
||||
OrganizationAssert.notNull(mergeParam.getDepartment(), "请选择需要合并的部门");
|
||||
OrganizationAssert.notBlank(mergeParam.getMergeName(), "请输入合并后的名称");
|
||||
// 合并到的部门
|
||||
DepartmentPO targetDepartment = getDepartmentMapper().getDeptById(jclParamDepartment);
|
||||
|
||||
// 不可选择合并的数据,本身及子部门
|
||||
Set<Long> disableIds = new HashSet<>();
|
||||
// 添加选择部门本身
|
||||
disableIds.add(mergeParam.getId());
|
||||
List<DepartmentPO> deptListByPId = getDepartmentMapper().getDeptListByPId(mergeParam.getId());
|
||||
if (CollectionUtils.isNotEmpty(deptListByPId)) {
|
||||
|
|
@ -569,31 +576,56 @@ public class DepartmentServiceImpl extends Service implements DepartmentService
|
|||
}
|
||||
OrganizationAssert.isFalse(disableIds.contains(targetDepartment.getId()), "请勿选择当前部门本身及其子部门");
|
||||
|
||||
//TODO 被合并部门
|
||||
DepartmentPO mergeDepartment = getDepartmentMapper().getDeptById(mergeParam.getId());
|
||||
mergeDepartment.setDeptName(mergeParam.getMergeName());
|
||||
mergeDepartment.setDeptNameShort(mergeParam.getMergeName());
|
||||
|
||||
mergeDepartment.setParentDept(jclParamDepartment);
|
||||
mergeDepartment.setEcDepartment(ecParamDepartment);
|
||||
mergeDepartment.setParentComp(targetDepartment.getParentComp());
|
||||
mergeDepartment.setEcCompany(targetDepartment.getEcCompany());
|
||||
// 禁用
|
||||
mergeDepartment.setForbiddenTag(1);
|
||||
// 更新EC表部门
|
||||
updateEcDepartment(mergeDepartment);
|
||||
// 封存EC表部门
|
||||
cancelEcDepartment(mergeDepartment.getId());
|
||||
|
||||
updateCount = getDepartmentMapper().updateBaseDept(mergeDepartment);
|
||||
// 查询该部门下一级部门
|
||||
List<DepartmentPO> firstChildDeptList = getDepartmentMapper().getDeptListByPId(mergeParam.getId());
|
||||
// 更新所属部门、所属分部
|
||||
for (DepartmentPO departmentPO : firstChildDeptList) {
|
||||
departmentPO.setParentDept(targetDepartment.getId());
|
||||
departmentPO.setEcDepartment(ecParamDepartment);
|
||||
departmentPO.setParentComp(targetDepartment.getParentComp());
|
||||
departmentPO.setEcCompany(targetDepartment.getEcCompany());
|
||||
updateEcDepartment(departmentPO);
|
||||
getDepartmentMapper().updateBaseDept(departmentPO);
|
||||
// 更新组织架构图
|
||||
new Thread(new DepartmentTriggerRunnable(departmentPO.getId())).start();
|
||||
}
|
||||
// 查询该部门一级岗位、更新岗位所属分部、所属部门
|
||||
//List<JobPO> firstChildJobList = getJobMapper().listJobsByDepartmentId(mergeParam.getId());
|
||||
// 批量更新部门、所属分部
|
||||
RecordSet rs = new RecordSet();
|
||||
String targetEcDeptId = EcHrmRelationUtil.getEcDepartmentId(targetDepartment.getId().toString());
|
||||
String mergeEcDeptId = EcHrmRelationUtil.getEcDepartmentId(mergeParam.getId().toString());
|
||||
rs.executeUpdate("update jcl_org_job set parent_comp =?,ec_company =?,parent_dept =?,ec_department =? where parent_dept =?", targetDepartment.getParentComp(), targetDepartment.getEcCompany(), targetDepartment.getId(), targetEcDeptId, mergeParam.getId());
|
||||
// 更新当前部门下的人员
|
||||
List<Long> hrmResourceIds = getSystemDataMapper().getHrmResourceIdsByDept(mergeEcDeptId);
|
||||
rs.executeUpdate("update hrmresource set SUBCOMPANYID1 =?,DEPARTMENTID =? where DEPARTMENTID =?", targetDepartment.getEcCompany(), targetEcDeptId, mergeEcDeptId);
|
||||
// 更新人员组织架构图
|
||||
for (Long hrmResourceId : hrmResourceIds) {
|
||||
new Thread(new HrmResourceTriggerRunnable(hrmResourceId)).start();
|
||||
}
|
||||
// 更新子部门下岗位的所属分部
|
||||
for (DepartmentPO departmentPO : firstChildDeptList) {
|
||||
List<DepartmentPO> deptList = getDepartmentMapper().getDeptListByPId(departmentPO.getId());
|
||||
forbiddenChildTag(targetDepartment.getParentComp(), Util.null2String(targetDepartment.getEcCompany()), deptList);
|
||||
}
|
||||
// 原部门删除
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("id", mergeParam.getId());
|
||||
new OrganizationSyncEc(user, LogModuleNameEnum.DEPARTMENT, OperateTypeEnum.CANCELED, map).sync();
|
||||
// 删除拓展表、明细表
|
||||
MapperProxyFactory.getProxy(ExtMapper.class).deleteByID("jcl_org_deptext", mergeParam.getId());
|
||||
MapperProxyFactory.getProxy(ExtDTMapper.class).deleteByMainID("jcl_org_deptext_dt1", mergeParam.getId());
|
||||
getDepartmentMapper().deleteByIds(DeleteParam.builder().ids(mergeParam.getId().toString()).build().getIds());
|
||||
// 更新组织架构图
|
||||
new Thread(new DepartmentTriggerRunnable(mergeDepartment.getId())).start();
|
||||
// 刷新岗位分部
|
||||
refreshJobComp(mergeDepartment.getId(), mergeDepartment.getParentComp());
|
||||
// 合并后部门及子部门禁用
|
||||
List<DepartmentPO> deptList = getDepartmentMapper().getDeptListByPId(mergeParam.getId());
|
||||
forbiddenChildTag(targetDepartment.getParentComp(), deptList, true);
|
||||
return updateCount;
|
||||
new Thread(new DepartmentTriggerRunnable(getDepartmentMapper().getDeptById(mergeParam.getId()))).start();
|
||||
// 更新部门合并后名称
|
||||
targetDepartment.setDeptName(mergeParam.getMergeName());
|
||||
targetDepartment.setDeptNameShort(mergeParam.getMergeName());
|
||||
updateEcDepartment(targetDepartment);
|
||||
getDepartmentMapper().updateBaseDept(targetDepartment);
|
||||
// 更新组织架构图
|
||||
new Thread(new DepartmentTriggerRunnable(targetDepartment.getId())).start();
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -656,7 +688,8 @@ public class DepartmentServiceImpl extends Service implements DepartmentService
|
|||
// 刷新岗位分部
|
||||
refreshJobComp(deptById.getId(), deptById.getParentComp());
|
||||
List<DepartmentPO> deptList = getDepartmentMapper().getDeptListByPId(deptById.getId());
|
||||
forbiddenChildTag(deptById.getParentComp(), deptList, false);
|
||||
String ecCompanyId = EcHrmRelationUtil.getEcCompanyId(Util.null2String(deptById.getParentComp()));
|
||||
forbiddenChildTag(deptById.getParentComp(), ecCompanyId, deptList);
|
||||
// 递归更新下级部门、岗位
|
||||
return updateBaseDept;
|
||||
}
|
||||
|
|
@ -667,19 +700,11 @@ public class DepartmentServiceImpl extends Service implements DepartmentService
|
|||
* @param parentComp
|
||||
* @param deptList
|
||||
*/
|
||||
void forbiddenChildTag(Long parentComp, List<DepartmentPO> deptList, boolean isForbidden) {
|
||||
void forbiddenChildTag(Long parentComp, String ecCompanyId, List<DepartmentPO> deptList) {
|
||||
if (CollectionUtils.isNotEmpty(deptList)) {
|
||||
for (DepartmentPO departmentPO : deptList) {
|
||||
departmentPO.setParentComp(parentComp);
|
||||
String ecCompanyId = EcHrmRelationUtil.getEcCompanyId(parentComp + "");
|
||||
if (StringUtils.isNotBlank(ecCompanyId)) {
|
||||
departmentPO.setEcCompany(Long.parseLong(ecCompanyId));
|
||||
}
|
||||
if (isForbidden) {
|
||||
departmentPO.setForbiddenTag(1);
|
||||
// 封存EC表部门
|
||||
cancelEcDepartment(departmentPO.getId());
|
||||
}
|
||||
departmentPO.setEcCompany(Long.parseLong(ecCompanyId));
|
||||
// 更新EC表部门
|
||||
updateEcDepartment(departmentPO);
|
||||
|
||||
|
|
@ -688,8 +713,16 @@ public class DepartmentServiceImpl extends Service implements DepartmentService
|
|||
new Thread(new DepartmentTriggerRunnable(departmentPO.getId())).start();
|
||||
// 刷新岗位所属分部
|
||||
refreshJobComp(departmentPO.getId(), parentComp);
|
||||
// 更新当前部门下的人员
|
||||
List<Long> hrmResourceIds = getSystemDataMapper().getHrmResourceIdsByDept(departmentPO.getId().toString());
|
||||
String ecDepartmentId = EcHrmRelationUtil.getEcDepartmentId(departmentPO.getId().toString());
|
||||
new RecordSet().executeUpdate("update hrmresource set SUBCOMPANYID1 =? where DEPARTMENTID =?", ecCompanyId, ecDepartmentId);
|
||||
// 更新人员组织架构图
|
||||
for (Long hrmResourceId : hrmResourceIds) {
|
||||
new Thread(new HrmResourceTriggerRunnable(hrmResourceId)).start();
|
||||
}
|
||||
List<DepartmentPO> childList = getDepartmentMapper().getDeptListByPId(departmentPO.getId());
|
||||
forbiddenChildTag(parentComp, childList, isForbidden);
|
||||
forbiddenChildTag(parentComp, ecCompanyId, childList);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ import com.engine.organization.entity.SelectOptionParam;
|
|||
import com.engine.organization.entity.commom.RecordInfo;
|
||||
import com.engine.organization.entity.extend.param.ExtendInfoParams;
|
||||
import com.engine.organization.entity.extend.po.ExtendInfoPO;
|
||||
import com.engine.organization.entity.fieldset.param.FieldTypeTreeParam;
|
||||
import com.engine.organization.entity.fieldset.param.FieldTransferParam;
|
||||
import com.engine.organization.entity.jclimport.po.CusFormFieldPO;
|
||||
import com.engine.organization.entity.jclimport.po.JclImportHistoryDetailPO;
|
||||
import com.engine.organization.entity.jclimport.po.JclImportHistoryPO;
|
||||
|
|
@ -153,16 +153,15 @@ public class ImportCommonServiceImpl extends Service implements ImportCommonServ
|
|||
mergeList.addAll(hrmFieldBeanList);
|
||||
mergeList.addAll(customFieldList);
|
||||
|
||||
// TODO 分部、部门
|
||||
List<FieldTypeTreeParam> fieldDatas = mergeList.stream().map(item -> FieldTypeTreeParam.builder().id(item.getFieldId()).name(item.getFieldLabel()).build()).collect(Collectors.toList());
|
||||
List<Long> selectedKeys = mergeList.stream().filter(item -> ("1".equals(item.getRequired()) || "workcode".equals(item.getFieldName()) || "subcompanyid1".equals(item.getFieldName()) || "departmentid".equals(item.getFieldName()))).map(CusFormFieldPO::getFieldId).collect(Collectors.toList());
|
||||
List<FieldTransferParam> fieldDatas = mergeList.stream().map(item -> FieldTransferParam.builder().id(item.getTableName() + +item.getFieldId()).name(item.getFieldLabel()).build()).collect(Collectors.toList());
|
||||
List<String> selectedKeys = mergeList.stream().filter(item -> ("1".equals(item.getRequired()) || "workcode".equals(item.getFieldName()) || "subcompanyid1".equals(item.getFieldName()) || "departmentid".equals(item.getFieldName()))).map(item->item.getTableName()+item.getFieldId()).collect(Collectors.toList());
|
||||
|
||||
returnMaps.put("data", fieldDatas);
|
||||
returnMaps.put("selectedKeys", selectedKeys);
|
||||
} else {
|
||||
List<ExtendInfoPO> infoPOList = getExtendInfoMapper().listFields(extendType, "", tableName, "", "1");
|
||||
List<ExtendInfoPO> filterList = infoPOList.stream().filter(item -> !excludeFields.contains(item.getFieldName()) && 6 != item.getControlType()).collect(Collectors.toList());
|
||||
List<FieldTypeTreeParam> fieldDatas = filterList.stream().map(item -> FieldTypeTreeParam.builder().id(item.getId()).name(item.getFieldNameDesc()).build()).collect(Collectors.toList());
|
||||
List<FieldTransferParam> fieldDatas = filterList.stream().map(item -> FieldTransferParam.builder().id(item.getId().toString()).name(item.getFieldNameDesc()).build()).collect(Collectors.toList());
|
||||
List<Long> selectedKeys = filterList.stream().filter(item -> (0 == item.getIsSystemDefault()) && 1 == item.getIsrequired()).map(ExtendInfoPO::getId).collect(Collectors.toList());
|
||||
returnMaps.put("data", fieldDatas);
|
||||
returnMaps.put("selectedKeys", selectedKeys);
|
||||
|
|
|
|||
|
|
@ -50,6 +50,9 @@ public class EcHrmRelationUtil {
|
|||
public static String getEcCompanyId(String companyId) {
|
||||
CompPO compPO = getCompMapper().listById(Long.parseLong(companyId));
|
||||
RecordInfo supSubCompany = getSystemDataMapper().getHrmObjectByUUID(HRM_COMPANY, compPO.getUuid());
|
||||
if (null == supSubCompany) {
|
||||
return "0";
|
||||
}
|
||||
return supSubCompany.getId();
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue