部门复制

pull/235/MERGE^2
dxfeng 3 years ago
parent 8e385537da
commit 34d44b6c91

@ -23,4 +23,13 @@ public class DeptCopyParam {
* *
*/ */
private String copyJob; private String copyJob;
/**
*
*/
private String copySubDept;
/**
*
*/
private String copySubJob;
} }

@ -50,6 +50,7 @@ import com.engine.organization.util.page.PageInfo;
import com.engine.organization.util.page.PageUtil; import com.engine.organization.util.page.PageUtil;
import com.engine.organization.util.relation.EcHrmRelationUtil; import com.engine.organization.util.relation.EcHrmRelationUtil;
import com.engine.organization.util.tree.SearchTreeUtil; import com.engine.organization.util.tree.SearchTreeUtil;
import com.google.common.collect.Lists;
import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import weaver.conn.RecordSet; import weaver.conn.RecordSet;
@ -473,13 +474,16 @@ public class DepartmentServiceImpl extends Service implements DepartmentService
List<SearchConditionItem> condition = new ArrayList<>(); List<SearchConditionItem> condition = new ArrayList<>();
SearchConditionItem compBrowserItem = OrganizationFormItemUtil.browserItem(user, 2, 16, 3, false, "复制到", "164", "company", ""); SearchConditionItem compBrowserItem = OrganizationFormItemUtil.browserItem(user, 2, 16, 3, false, "复制到", "164", "company", "");
compBrowserItem.setRules("required|string"); compBrowserItem.setRules("required|string");
List<SearchConditionOption> selectOptions = new ArrayList<>(); SearchConditionItem isCheckItem = OrganizationFormItemUtil.selectItem(user, Lists.newArrayList(new SearchConditionOption("1", "")), 2, 5, 10, false, "是否复制岗位信息", "copyJob");
SearchConditionOption Option = new SearchConditionOption("1", "");
selectOptions.add(Option);
SearchConditionItem isCheckItem = OrganizationFormItemUtil.selectItem(user, selectOptions, 2, 5, 10, false, "是否复制岗位信息", "copyJob");
isCheckItem.setDetailtype(2); isCheckItem.setDetailtype(2);
SearchConditionItem copySubDeptItem = OrganizationFormItemUtil.selectItem(user, Lists.newArrayList(new SearchConditionOption("1", "")), 2, 5, 10, false, "是否复制子部门信息", "copySubDept");
copySubDeptItem.setDetailtype(2);
SearchConditionItem copySubJob = OrganizationFormItemUtil.selectItem(user, Lists.newArrayList(new SearchConditionOption("1", "")), 2, 5, 10, false, "是否复制子部门岗位信息", "copySubJob");
copySubJob.setDetailtype(2);
condition.add(compBrowserItem); condition.add(compBrowserItem);
condition.add(isCheckItem); condition.add(isCheckItem);
condition.add(copySubDeptItem);
condition.add(copySubJob);
addGroups.add(new SearchConditionGroup("", true, condition)); addGroups.add(new SearchConditionGroup("", true, condition));
return addGroups; return addGroups;
} }
@ -492,26 +496,41 @@ public class DepartmentServiceImpl extends Service implements DepartmentService
*/ */
@Override @Override
public int copyDepartment(DeptCopyParam copyParam) { public int copyDepartment(DeptCopyParam copyParam) {
// TODO 是否复制子部门信息,是否复制子部门岗位信息 // 批量复制,后续优化
HasRightUtil.hasRight(user, RIGHT_NAME, false); HasRightUtil.hasRight(user, RIGHT_NAME, false);
OrganizationAssert.notBlank(copyParam.getCompany(), "请指定需要复制的公司/分部"); OrganizationAssert.notBlank(copyParam.getCompany(), "请指定需要复制的公司/分部");
int insertCount = 0; int insertCount = 0;
// 需复制的部门
List<Long> idList = Arrays.stream(copyParam.getIds().split(",")).map(Long::parseLong).collect(Collectors.toList()); List<Long> idList = Arrays.stream(copyParam.getIds().split(",")).map(Long::parseLong).collect(Collectors.toList());
Integer maxShowOrder = getDepartmentMapper().getMaxShowOrder(); Integer maxShowOrder = getDepartmentMapper().getMaxShowOrder();
maxShowOrder = null == maxShowOrder ? 0 : maxShowOrder; maxShowOrder = null == maxShowOrder ? 0 : maxShowOrder;
for (int i = 0; i < idList.size(); i++) { for (Long departmentId : idList) {
DepartmentPO deptById = getDepartmentMapper().getDeptById(idList.get(i)); // 复制当前部门
recursionCopyDept(departmentId, null, Long.parseLong(copyParam.getCompany()), maxShowOrder, copyParam.getCopyJob(), copyParam.getCopySubDept(), copyParam.getCopySubJob());
}
return insertCount;
}
private void recursionCopyDept(Long originalDeptId, Long parentDepartmentId, Long companyId, Integer maxShowOrder, String copyJob, String copySubDept, String copySubJob) {
// 源部门
DepartmentPO deptById = getDepartmentMapper().getDeptById(originalDeptId);
long timeMillis = System.currentTimeMillis(); long timeMillis = System.currentTimeMillis();
deptById.setDeptName(deptById.getDeptName() + "_" + timeMillis); deptById.setDeptName(deptById.getDeptName() + "_" + timeMillis);
deptById.setDeptNameShort(deptById.getDeptNameShort()); deptById.setDeptNameShort(deptById.getDeptNameShort() + "_" + timeMillis);
// 处理自动编号 // 处理自动编号
deptById.setDeptNo(CodeRuleUtil.generateCode(RuleCodeType.DEPARTMENT, deptById.getDeptNo(), timeMillis)); deptById.setDeptNo(CodeRuleUtil.generateCode(RuleCodeType.DEPARTMENT, deptById.getDeptNo(), timeMillis));
deptById.setParentComp(EcHrmRelationUtil.getJclCompanyId(copyParam.getCompany()).getId()); // 设置上级分部
deptById.setEcCompany(Long.parseLong(copyParam.getCompany())); deptById.setParentComp(EcHrmRelationUtil.getJclCompanyId(Util.null2String(companyId)).getId());
deptById.setParentDept(null); deptById.setEcCompany(companyId);
deptById.setParentDept(parentDepartmentId);
if (null != parentDepartmentId) {
deptById.setEcDepartment(Long.parseLong(EcHrmRelationUtil.getEcDepartmentId(Util.null2String(parentDepartmentId))));
}
// 显示顺序字段 // 显示顺序字段
deptById.setShowOrder(maxShowOrder + i + 1); deptById.setShowOrder(++maxShowOrder);
deptById.setCreator((long) user.getUID());
deptById.setCreateTime(new Date()); deptById.setCreateTime(new Date());
// 新增EC表部门 // 新增EC表部门
Map<String, Object> syncMap = addEcDepartment(deptById); Map<String, Object> syncMap = addEcDepartment(deptById);
String ecDepartmentID = Util.null2String(syncMap.get("id")); String ecDepartmentID = Util.null2String(syncMap.get("id"));
@ -519,21 +538,30 @@ public class DepartmentServiceImpl extends Service implements DepartmentService
// 查询UUID // 查询UUID
RecordInfo recordInfo = getSystemDataMapper().getHrmObjectByID(HRM_DEPARTMENT, ecDepartmentID); RecordInfo recordInfo = getSystemDataMapper().getHrmObjectByID(HRM_DEPARTMENT, ecDepartmentID);
deptById.setUuid(recordInfo.getUuid()); deptById.setUuid(recordInfo.getUuid());
insertCount += getDepartmentMapper().insertIgnoreNull(deptById); getDepartmentMapper().insertIgnoreNull(deptById);
// 更新组织架构图 // 更新组织架构图
new Thread(new DepartmentTriggerRunnable(deptById.getId())).start(); new Thread(new DepartmentTriggerRunnable(deptById.getId())).start();
// 新增岗位信息 // 复制当前部门岗位信息
if ("1".equals(copyParam.getCopyJob())) { if ("1".equals(copyJob)) {
List<JobPO> jobPOS = MapperProxyFactory.getProxy(JobMapper.class).listJobsByDepartmentId(idList.get(i)); List<JobPO> jobPOS = MapperProxyFactory.getProxy(JobMapper.class).listJobsByDepartmentId(originalDeptId);
jobPOS = jobPOS.stream().filter(item -> null == item.getParentJob() || 0 == item.getParentJob()).collect(Collectors.toList());
Integer maxJobOrder = MapperProxyFactory.getProxy(JobMapper.class).getMaxShowOrder(); Integer maxJobOrder = MapperProxyFactory.getProxy(JobMapper.class).getMaxShowOrder();
if (maxJobOrder == null) { if (maxJobOrder == null) {
maxJobOrder = 0; maxJobOrder = 0;
} }
recursionCopyJob((long) user.getUID(), jobPOS, deptById.getParentComp(), deptById.getId(), maxJobOrder, timeMillis); recursionCopyJob(jobPOS, companyId, deptById.getId(), null, maxJobOrder, timeMillis);
}
// 是否复制子部门信息
if ("1".equals(copySubDept)) {
// 查询当前部门的子部门
List<DepartmentPO> deptListByPId = getDepartmentMapper().getDeptListByPId(originalDeptId);
for (DepartmentPO departmentPO : deptListByPId) {
// 复制子部门信息、子部门岗位信息
recursionCopyDept(departmentPO.getId(), deptById.getId(), companyId, maxShowOrder, copySubJob, copySubDept, copySubJob);
} }
} }
return insertCount;
} }
@Override @Override
@ -558,7 +586,7 @@ public class DepartmentServiceImpl extends Service implements DepartmentService
HasRightUtil.hasRight(user, RIGHT_NAME, false); HasRightUtil.hasRight(user, RIGHT_NAME, false);
// 被合并部门 // 被合并部门
Long ecParamDepartment = mergeParam.getDepartment(); Long ecParamDepartment = mergeParam.getDepartment();
DepartmentPO targetDepartment = EcHrmRelationUtil.getJclDepartmentId( Util.null2String(ecParamDepartment)); DepartmentPO targetDepartment = EcHrmRelationUtil.getJclDepartmentId(Util.null2String(ecParamDepartment));
// 断言判断 // 断言判断
OrganizationAssert.isFalse(null == targetDepartment, "被合并部门数据有误,暂时无法合并"); OrganizationAssert.isFalse(null == targetDepartment, "被合并部门数据有误,暂时无法合并");
@ -591,6 +619,7 @@ public class DepartmentServiceImpl extends Service implements DepartmentService
} }
// 查询该部门一级岗位、更新岗位所属分部、所属部门 // 查询该部门一级岗位、更新岗位所属分部、所属部门
List<JobPO> firstChildJobList = getJobMapper().listJobsByDepartmentId(mergeParam.getId()); List<JobPO> firstChildJobList = getJobMapper().listJobsByDepartmentId(mergeParam.getId());
firstChildJobList = firstChildJobList.stream().filter(item -> null == item.getParentJob() || 0 == item.getParentJob()).collect(Collectors.toList());
// 批量更新部门、所属分部 // 批量更新部门、所属分部
RecordSet rs = new RecordSet(); RecordSet rs = new RecordSet();
String targetEcDeptId = EcHrmRelationUtil.getEcDepartmentId(targetDepartment.getId().toString()); String targetEcDeptId = EcHrmRelationUtil.getEcDepartmentId(targetDepartment.getId().toString());
@ -668,11 +697,11 @@ public class DepartmentServiceImpl extends Service implements DepartmentService
Long company = moveParam.getCompany(); Long company = moveParam.getCompany();
OrganizationAssert.notNull(company, "请选择要转移到的分部"); OrganizationAssert.notNull(company, "请选择要转移到的分部");
deptById.setEcCompany(company); deptById.setEcCompany(company);
deptById.setParentComp(Objects.requireNonNull(EcHrmRelationUtil.getJclCompanyId( Util.null2String(company))).getId()); deptById.setParentComp(Objects.requireNonNull(EcHrmRelationUtil.getJclCompanyId(Util.null2String(company))).getId());
deptById.setParentDept(null); deptById.setParentDept(null);
} else if ("1".equals(moveParam.getMoveType())) { } else if ("1".equals(moveParam.getMoveType())) {
Long department = moveParam.getDepartment(); Long department = moveParam.getDepartment();
Long departmentId = Objects.requireNonNull(EcHrmRelationUtil.getJclDepartmentId( Util.null2String(department))).getId(); Long departmentId = Objects.requireNonNull(EcHrmRelationUtil.getJclDepartmentId(Util.null2String(department))).getId();
OrganizationAssert.notNull(departmentId, "请选择要转移到的部门"); OrganizationAssert.notNull(departmentId, "请选择要转移到的部门");
List<DepartmentPO> deptListByPId = getDepartmentMapper().getDeptListByPId(moveParam.getId()); List<DepartmentPO> deptListByPId = getDepartmentMapper().getDeptListByPId(moveParam.getId());
Set<Long> disableIds = new HashSet<>(); Set<Long> disableIds = new HashSet<>();
@ -827,29 +856,42 @@ public class DepartmentServiceImpl extends Service implements DepartmentService
/** /**
* *
* *
* @param creator
* @param jobPOS * @param jobPOS
* @param parentCompId * @param parentCompId
* @param parentDeptId * @param parentDeptId
* @param orderNum * @param orderNum
*/ */
private void recursionCopyJob(Long creator, List<JobPO> jobPOS, Long parentCompId, Long parentDeptId, int orderNum, long timeMillis) { private void recursionCopyJob(List<JobPO> jobPOS, Long parentCompId, Long parentDeptId, Long currentParentJobId, int orderNum, long timeMillis) {
for (JobPO jobPO : jobPOS) { for (JobPO jobPO : jobPOS) {
orderNum++; orderNum++;
// 查询源岗位的下级岗位
List<JobPO> jobsByPid = MapperProxyFactory.getProxy(JobMapper.class).getJobsByPid(jobPO.getId());
// 处理自动编号 // 处理自动编号
jobPO.setJobNo(CodeRuleUtil.generateCode(RuleCodeType.JOBTITLES, jobPO.getJobNo(), timeMillis)); jobPO.setJobNo(CodeRuleUtil.generateCode(RuleCodeType.JOBTITLES, jobPO.getJobNo(), timeMillis));
jobPO.setParentDept(parentDeptId); jobPO.setEcDepartment(parentDeptId);
jobPO.setCreator(creator); DepartmentPO jclDepartmentId = EcHrmRelationUtil.getJclDepartmentId(Util.null2String(parentDeptId));
jobPO.setCreateTime(new Date()); if (null != jclDepartmentId) {
jobPO.setParentDept(jclDepartmentId.getId());
}
jobPO.setEcCompany(parentCompId);
CompPO jclCompanyId = EcHrmRelationUtil.getJclCompanyId(Util.null2String(parentCompId));
if (null != jclCompanyId) {
jobPO.setParentComp(parentCompId); jobPO.setParentComp(parentCompId);
}
// 指定上级岗位
jobPO.setParentJob(currentParentJobId);
jobPO.setCreator((long) user.getUID());
jobPO.setCreateTime(new Date());
jobPO.setShowOrder(orderNum); jobPO.setShowOrder(orderNum);
MapperProxyFactory.getProxy(JobMapper.class).insertIgnoreNull(jobPO); MapperProxyFactory.getProxy(JobMapper.class).insertIgnoreNull(jobPO);
// 更新组织架构图 // 更新组织架构图
new Thread(new JobTriggerRunnable(jobPO.getId())).start(); new Thread(new JobTriggerRunnable(jobPO.getId())).start();
// 处理子级元素 // 处理子级元素
List<JobPO> jobsByPid = MapperProxyFactory.getProxy(JobMapper.class).getJobsByPid(jobPO.getId());
if (CollectionUtils.isNotEmpty(jobsByPid)) { if (CollectionUtils.isNotEmpty(jobsByPid)) {
recursionCopyJob(creator, jobsByPid, parentCompId, parentDeptId, orderNum, timeMillis); recursionCopyJob(jobsByPid, parentCompId, parentDeptId, jobPO.getId(), orderNum, timeMillis);
} }
} }
} }
@ -919,6 +961,7 @@ public class DepartmentServiceImpl extends Service implements DepartmentService
*/ */
private void refreshJobComp(Long parentDepartment, Long parentComp) { private void refreshJobComp(Long parentDepartment, Long parentComp) {
List<JobPO> jobPOS = getJobMapper().listJobsByDepartmentId(parentDepartment); List<JobPO> jobPOS = getJobMapper().listJobsByDepartmentId(parentDepartment);
jobPOS = jobPOS.stream().filter(item -> null == item.getParentJob() || 0 == item.getParentJob()).collect(Collectors.toList());
if (CollectionUtils.isNotEmpty(jobPOS)) { if (CollectionUtils.isNotEmpty(jobPOS)) {
String ecCompanyId = EcHrmRelationUtil.getEcCompanyId(parentComp.toString()); String ecCompanyId = EcHrmRelationUtil.getEcCompanyId(parentComp.toString());
getJobMapper().updateJobCompany(jobPOS.stream().map(JobPO::getId).collect(Collectors.toList()), parentComp, ecCompanyId); getJobMapper().updateJobCompany(jobPOS.stream().map(JobPO::getId).collect(Collectors.toList()), parentComp, ecCompanyId);

Loading…
Cancel
Save