diff --git a/src/com/engine/organization/service/DepartmentService.java b/src/com/engine/organization/service/DepartmentService.java index 04791771..f60f2c2a 100644 --- a/src/com/engine/organization/service/DepartmentService.java +++ b/src/com/engine/organization/service/DepartmentService.java @@ -160,4 +160,11 @@ public interface DepartmentService { */ int moveDepartment(DepartmentMoveParam moveParam); + + /** + * 拖拽转移部门 + * @param params + * @return + */ + int dragDepartment(Map params); } diff --git a/src/com/engine/organization/service/impl/DepartmentServiceImpl.java b/src/com/engine/organization/service/impl/DepartmentServiceImpl.java index 93218c65..a353edf3 100644 --- a/src/com/engine/organization/service/impl/DepartmentServiceImpl.java +++ b/src/com/engine/organization/service/impl/DepartmentServiceImpl.java @@ -578,6 +578,9 @@ public class DepartmentServiceImpl extends Service implements DepartmentService Map map = new HashMap<>(); map.put("id", Util.null2String(mergeParam.getId())); ServiceUtil.getService(OrganizationServiceImpl.class, user).doDepartmentCancel(map, user); + // 删除原部门下的岗位 + + // 更新组织架构图 // new DepartmentTriggerRunnable(mergeDepartment).run(); // 更新部门合并后名称 @@ -662,6 +665,82 @@ public class DepartmentServiceImpl extends Service implements DepartmentService return 1; } + @Override + public int dragDepartment(Map params) { +// OrganizationAssert.notNull(params.get("sourcekey"), "请选择一个拖拽源"); +// OrganizationAssert.notNull(params.get("targetkey"), "请选择一个拖拽目的地"); + + String sourceKey = Util.null2String(params.get("sourcekey"));// 原目标 + String targetKey = Util.null2String(params.get("targetkey"));// 目的地 + String dragPostion = Util.null2String(params.get("dragpostion"));// 0:目的里面 1:目的外边 + + DepartmentPO deptById = getDepartmentMapper().getDeptById(Util.getIntValue(sourceKey.substring(1))); + + + RecordSet recordSet = new RecordSet(); + // 部门不能到集团下 + + String targetType = targetKey.substring(0, 1); + String targetId = targetKey.substring(1); + String supId = null; + String querySupIdSql = null; + if ("s".equals(targetType)) {// 分部 + querySupIdSql = "select supsubcomid as supId from hrmsubcompany where id = ?"; + } else { + querySupIdSql = "select supdepid as supId from hrmdepartment where id = ?"; + } + if ("1".equals(dragPostion)) { + recordSet.executeQuery(querySupIdSql, targetId); + if (recordSet.next()) { + supId = Util.null2String(recordSet.getString("supId")); + } + OrganizationAssert.isFalse("0".equals(supId), "部门不能直接拖拽至集团下"); + + if ("s".equals(targetType)) { + // 转移到分部外 + deptById.setSubCompanyId1(Util.getIntValue(supId)); + deptById.setSupDepId(null); + } else { + // 转移到部门外 + List deptListByPId = getDepartmentMapper().getDeptListByPId(Util.getIntValue(supId)); + Set disableIds = new HashSet<>(); + disableIds.add(Util.getIntValue(sourceKey.substring(1))); + if (CollectionUtils.isNotEmpty(deptListByPId)) { + addDisableIds(disableIds, deptListByPId); + } + OrganizationAssert.isFalse(disableIds.contains(Util.getIntValue(targetId)), "请勿选择当前部门本身及其子部门"); + deptById.setSupDepId(Util.getIntValue(supId)); + DepartmentPO parentDepartment = getDepartmentMapper().getDeptById(Util.getIntValue(supId)); + deptById.setSubCompanyId1(parentDepartment.getSubCompanyId1()); + } + + } else { + if ("s".equals(targetType)) { + //转移到分部下 + deptById.setSubCompanyId1(Util.getIntValue(targetId)); + deptById.setSupDepId(null); + } else { + //转移到部门下 + List deptListByPId = getDepartmentMapper().getDeptListByPId(Util.getIntValue(targetId)); + Set disableIds = new HashSet<>(); + disableIds.add(Util.getIntValue(sourceKey.substring(1))); + if (CollectionUtils.isNotEmpty(deptListByPId)) { + addDisableIds(disableIds, deptListByPId); + } + OrganizationAssert.isFalse(disableIds.contains(Util.getIntValue(targetId)), "请勿选择当前部门本身及其子部门"); + deptById.setSupDepId(Util.getIntValue(targetId)); + DepartmentPO parentDepartment = getDepartmentMapper().getDeptById(Util.getIntValue(targetId)); + deptById.setSubCompanyId1(parentDepartment.getSubCompanyId1()); + } + } + // 更新EC部门 + updateEcDepartment(deptById); + // 刷新岗位分部 + List deptList = getDepartmentMapper().getDeptListByPId(deptById.getId()); + forbiddenChildTag(deptById.getSubCompanyId1(), deptList); + return 1; + } + /** * 获取所有子部门id * diff --git a/src/com/engine/organization/web/DepartmentController.java b/src/com/engine/organization/web/DepartmentController.java index bba9f0c9..99397e1f 100644 --- a/src/com/engine/organization/web/DepartmentController.java +++ b/src/com/engine/organization/web/DepartmentController.java @@ -332,5 +332,17 @@ public class DepartmentController { return ReturnResult.exceptionHandle(e); } } + @POST + @Path("/dragDepartment") + @Produces(MediaType.APPLICATION_JSON) + public ReturnResult dragDepartment(@Context HttpServletRequest request, @Context HttpServletResponse response) { + try { + User user = HrmUserVarify.getUser(request, response); + Map params = ParamUtil.request2Map(request); + return ReturnResult.successed(getDepartmentWrapper(user).dragDepartment(params)); + } catch (Exception e) { + return ReturnResult.exceptionHandle(e); + } + } } diff --git a/src/com/engine/organization/wrapper/DepartmentWrapper.java b/src/com/engine/organization/wrapper/DepartmentWrapper.java index 0fb057db..1f7441b5 100644 --- a/src/com/engine/organization/wrapper/DepartmentWrapper.java +++ b/src/com/engine/organization/wrapper/DepartmentWrapper.java @@ -21,6 +21,7 @@ import com.engine.organization.util.db.MapperProxyFactory; import com.engine.organization.util.page.PageInfo; import com.engine.organization.util.response.ReturnResult; import org.apache.commons.lang.StringUtils; +import weaver.general.Util; import weaver.hrm.User; import java.util.Collection; @@ -259,4 +260,19 @@ public class DepartmentWrapper extends OrganizationWrapper { }.getClass(), departmentPO.getDepartmentName(), JSON.toJSONString(moveParam), departmentPO, getDepartmentMapper().getDeptById(departmentPO.getId())); return moveDepartment; } + + /** + * 拖拽转移到指定分部或部门 + * + * @param moveParam + * @return + */ + @Log(operateType = OperateTypeEnum.MOVE, operateDesc = "拖拽转移部门", operateModule = LogModuleNameEnum.DEPARTMENT) + public int dragDepartment(Map params) { + DepartmentPO departmentPO = getDepartmentMapper().getDeptById(Util.getIntValue(Util.null2String(params.get("sourceKey")).substring(1))); + int moveDepartment = getDepartmentService(user).dragDepartment(params); + writeOperateLog(new Object() { + }.getClass(), departmentPO.getDepartmentName(), JSON.toJSONString(params), departmentPO, getDepartmentMapper().getDeptById(departmentPO.getId())); + return moveDepartment; + } }