部门复制

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

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

Loading…
Cancel
Save