|
@@ -6,8 +6,10 @@ import com.usky.common.core.exception.BusinessErrorCode;
|
|
import com.usky.common.core.util.StringUtils;
|
|
import com.usky.common.core.util.StringUtils;
|
|
import com.usky.common.security.utils.SecurityUtils;
|
|
import com.usky.common.security.utils.SecurityUtils;
|
|
import com.usky.system.domain.SysDept;
|
|
import com.usky.system.domain.SysDept;
|
|
|
|
+import com.usky.system.domain.SysUser;
|
|
import com.usky.system.domain.constants.UserConstants;
|
|
import com.usky.system.domain.constants.UserConstants;
|
|
import com.usky.system.service.ISysDeptService;
|
|
import com.usky.system.service.ISysDeptService;
|
|
|
|
+import com.usky.system.service.ISysUserService;
|
|
import org.apache.commons.lang3.ArrayUtils;
|
|
import org.apache.commons.lang3.ArrayUtils;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.validation.annotation.Validated;
|
|
import org.springframework.validation.annotation.Validated;
|
|
@@ -21,22 +23,23 @@ import java.util.Map;
|
|
|
|
|
|
/**
|
|
/**
|
|
* 部门信息
|
|
* 部门信息
|
|
- *
|
|
|
|
|
|
+ *
|
|
* @author yq
|
|
* @author yq
|
|
*/
|
|
*/
|
|
@RestController
|
|
@RestController
|
|
@RequestMapping("/dept")
|
|
@RequestMapping("/dept")
|
|
-public class SysDeptController extends BaseController
|
|
|
|
-{
|
|
|
|
|
|
+public class SysDeptController extends BaseController {
|
|
@Autowired
|
|
@Autowired
|
|
private ISysDeptService deptService;
|
|
private ISysDeptService deptService;
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ private ISysUserService iSysUserService;
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 获取部门列表
|
|
* 获取部门列表
|
|
*/
|
|
*/
|
|
@GetMapping("/list")
|
|
@GetMapping("/list")
|
|
- public ApiResult list(SysDept dept)
|
|
|
|
- {
|
|
|
|
|
|
+ public ApiResult list(SysDept dept) {
|
|
List<SysDept> depts = deptService.selectDeptList(dept);
|
|
List<SysDept> depts = deptService.selectDeptList(dept);
|
|
return ApiResult.success(depts);
|
|
return ApiResult.success(depts);
|
|
}
|
|
}
|
|
@@ -45,16 +48,13 @@ public class SysDeptController extends BaseController
|
|
* 查询部门列表(排除节点)
|
|
* 查询部门列表(排除节点)
|
|
*/
|
|
*/
|
|
@GetMapping("/list/exclude/{deptId}")
|
|
@GetMapping("/list/exclude/{deptId}")
|
|
- public ApiResult excludeChild(@PathVariable(value = "deptId", required = false) Long deptId)
|
|
|
|
- {
|
|
|
|
|
|
+ public ApiResult excludeChild(@PathVariable(value = "deptId", required = false) Long deptId) {
|
|
List<SysDept> depts = deptService.selectDeptList(new SysDept());
|
|
List<SysDept> depts = deptService.selectDeptList(new SysDept());
|
|
Iterator<SysDept> it = depts.iterator();
|
|
Iterator<SysDept> it = depts.iterator();
|
|
- while (it.hasNext())
|
|
|
|
- {
|
|
|
|
|
|
+ while (it.hasNext()) {
|
|
SysDept d = (SysDept) it.next();
|
|
SysDept d = (SysDept) it.next();
|
|
if (d.getDeptId().intValue() == deptId
|
|
if (d.getDeptId().intValue() == deptId
|
|
- || ArrayUtils.contains(StringUtils.split(d.getAncestors(), ","), deptId + ""))
|
|
|
|
- {
|
|
|
|
|
|
+ || ArrayUtils.contains(StringUtils.split(d.getAncestors(), ","), deptId + "")) {
|
|
it.remove();
|
|
it.remove();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -65,8 +65,7 @@ public class SysDeptController extends BaseController
|
|
* 根据部门编号获取详细信息
|
|
* 根据部门编号获取详细信息
|
|
*/
|
|
*/
|
|
@GetMapping(value = "/{deptId}")
|
|
@GetMapping(value = "/{deptId}")
|
|
- public ApiResult getInfo(@PathVariable Long deptId)
|
|
|
|
- {
|
|
|
|
|
|
+ public ApiResult getInfo(@PathVariable Long deptId) {
|
|
return ApiResult.success(deptService.selectDeptById(deptId));
|
|
return ApiResult.success(deptService.selectDeptById(deptId));
|
|
}
|
|
}
|
|
|
|
|
|
@@ -74,20 +73,28 @@ public class SysDeptController extends BaseController
|
|
* 获取部门下拉树列表
|
|
* 获取部门下拉树列表
|
|
*/
|
|
*/
|
|
@GetMapping("/treeselect")
|
|
@GetMapping("/treeselect")
|
|
- public ApiResult treeselect(SysDept dept)
|
|
|
|
- {
|
|
|
|
|
|
+ public ApiResult treeselect(SysDept dept) {
|
|
List<SysDept> depts = deptService.selectDeptList(dept);
|
|
List<SysDept> depts = deptService.selectDeptList(dept);
|
|
return ApiResult.success(deptService.buildDeptTreeSelect(depts));
|
|
return ApiResult.success(deptService.buildDeptTreeSelect(depts));
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 获取部门下拉树列表
|
|
|
|
+ */
|
|
|
|
+ @GetMapping("/deptUserTreeSelect")
|
|
|
|
+ public ApiResult treeselect(SysDept dept, SysUser user) {
|
|
|
|
+ List<SysDept> depts = deptService.selectDeptList(dept);
|
|
|
|
+ List<SysUser> users = iSysUserService.selectUserList(user);
|
|
|
|
+ return ApiResult.success(deptService.buildDeptUserTreeSelect(depts, users));
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 加载对应角色部门列表树
|
|
* 加载对应角色部门列表树
|
|
*/
|
|
*/
|
|
@GetMapping(value = "/roleDeptTreeselect/{roleId}")
|
|
@GetMapping(value = "/roleDeptTreeselect/{roleId}")
|
|
- public ApiResult roleDeptTreeselect(@PathVariable("roleId") Long roleId)
|
|
|
|
- {
|
|
|
|
|
|
+ public ApiResult roleDeptTreeselect(@PathVariable("roleId") Long roleId) {
|
|
List<SysDept> depts = deptService.selectDeptList(new SysDept());
|
|
List<SysDept> depts = deptService.selectDeptList(new SysDept());
|
|
- Map<String,Object> ajax = new HashMap<>();
|
|
|
|
|
|
+ Map<String, Object> ajax = new HashMap<>();
|
|
ajax.put("checkedKeys", deptService.selectDeptListByRoleId(roleId));
|
|
ajax.put("checkedKeys", deptService.selectDeptListByRoleId(roleId));
|
|
ajax.put("depts", deptService.buildDeptTreeSelect(depts));
|
|
ajax.put("depts", deptService.buildDeptTreeSelect(depts));
|
|
return ApiResult.success(ajax);
|
|
return ApiResult.success(ajax);
|
|
@@ -97,10 +104,8 @@ public class SysDeptController extends BaseController
|
|
* 新增部门
|
|
* 新增部门
|
|
*/
|
|
*/
|
|
@PostMapping
|
|
@PostMapping
|
|
- public ApiResult add(@Validated @RequestBody SysDept dept)
|
|
|
|
- {
|
|
|
|
- if (UserConstants.NOT_UNIQUE.equals(deptService.checkDeptNameUnique(dept)))
|
|
|
|
- {
|
|
|
|
|
|
+ public ApiResult add(@Validated @RequestBody SysDept dept) {
|
|
|
|
+ if (UserConstants.NOT_UNIQUE.equals(deptService.checkDeptNameUnique(dept))) {
|
|
return ApiResult.error(BusinessErrorCode.BIZ_BUSINESS_ERROR.getCode(), "新增部门'" + dept.getDeptName() + "'失败,部门名称已存在");
|
|
return ApiResult.error(BusinessErrorCode.BIZ_BUSINESS_ERROR.getCode(), "新增部门'" + dept.getDeptName() + "'失败,部门名称已存在");
|
|
}
|
|
}
|
|
dept.setTenantId(SecurityUtils.getTenantId());
|
|
dept.setTenantId(SecurityUtils.getTenantId());
|
|
@@ -112,19 +117,13 @@ public class SysDeptController extends BaseController
|
|
* 修改部门
|
|
* 修改部门
|
|
*/
|
|
*/
|
|
@PutMapping
|
|
@PutMapping
|
|
- public ApiResult edit(@Validated @RequestBody SysDept dept)
|
|
|
|
- {
|
|
|
|
- if (UserConstants.NOT_UNIQUE.equals(deptService.checkDeptNameUnique(dept)))
|
|
|
|
- {
|
|
|
|
|
|
+ public ApiResult edit(@Validated @RequestBody SysDept dept) {
|
|
|
|
+ if (UserConstants.NOT_UNIQUE.equals(deptService.checkDeptNameUnique(dept))) {
|
|
return ApiResult.error(BusinessErrorCode.BIZ_BUSINESS_ERROR.getCode(), "修改部门'" + dept.getDeptName() + "'失败,部门名称已存在");
|
|
return ApiResult.error(BusinessErrorCode.BIZ_BUSINESS_ERROR.getCode(), "修改部门'" + dept.getDeptName() + "'失败,部门名称已存在");
|
|
- }
|
|
|
|
- else if (dept.getParentId().equals(dept.getDeptId()))
|
|
|
|
- {
|
|
|
|
|
|
+ } else if (dept.getParentId().equals(dept.getDeptId())) {
|
|
return ApiResult.error(BusinessErrorCode.BIZ_BUSINESS_ERROR.getCode(), "修改部门'" + dept.getDeptName() + "'失败,上级部门不能是自己");
|
|
return ApiResult.error(BusinessErrorCode.BIZ_BUSINESS_ERROR.getCode(), "修改部门'" + dept.getDeptName() + "'失败,上级部门不能是自己");
|
|
- }
|
|
|
|
- else if (StringUtils.equals(UserConstants.DEPT_DISABLE, dept.getStatus())
|
|
|
|
- && deptService.selectNormalChildrenDeptById(dept.getDeptId()) > 0)
|
|
|
|
- {
|
|
|
|
|
|
+ } else if (StringUtils.equals(UserConstants.DEPT_DISABLE, dept.getStatus())
|
|
|
|
+ && deptService.selectNormalChildrenDeptById(dept.getDeptId()) > 0) {
|
|
return ApiResult.error(BusinessErrorCode.BIZ_BUSINESS_ERROR.getCode(), "该部门包含未停用的子部门!");
|
|
return ApiResult.error(BusinessErrorCode.BIZ_BUSINESS_ERROR.getCode(), "该部门包含未停用的子部门!");
|
|
}
|
|
}
|
|
dept.setUpdateBy(SecurityUtils.getUsername());
|
|
dept.setUpdateBy(SecurityUtils.getUsername());
|
|
@@ -135,14 +134,11 @@ public class SysDeptController extends BaseController
|
|
* 删除部门
|
|
* 删除部门
|
|
*/
|
|
*/
|
|
@DeleteMapping("/{deptId}")
|
|
@DeleteMapping("/{deptId}")
|
|
- public ApiResult remove(@PathVariable Long deptId)
|
|
|
|
- {
|
|
|
|
- if (deptService.hasChildByDeptId(deptId))
|
|
|
|
- {
|
|
|
|
|
|
+ public ApiResult remove(@PathVariable Long deptId) {
|
|
|
|
+ if (deptService.hasChildByDeptId(deptId)) {
|
|
return ApiResult.error(BusinessErrorCode.BIZ_BUSINESS_ERROR.getCode(), "存在下级部门,不允许删除");
|
|
return ApiResult.error(BusinessErrorCode.BIZ_BUSINESS_ERROR.getCode(), "存在下级部门,不允许删除");
|
|
}
|
|
}
|
|
- if (deptService.checkDeptExistUser(deptId))
|
|
|
|
- {
|
|
|
|
|
|
+ if (deptService.checkDeptExistUser(deptId)) {
|
|
return ApiResult.error(BusinessErrorCode.BIZ_BUSINESS_ERROR.getCode(), "部门存在用户,不允许删除");
|
|
return ApiResult.error(BusinessErrorCode.BIZ_BUSINESS_ERROR.getCode(), "部门存在用户,不允许删除");
|
|
}
|
|
}
|
|
return toAjax(deptService.deleteDeptById(deptId));
|
|
return toAjax(deptService.deleteDeptById(deptId));
|