|
@@ -1,10 +1,7 @@
|
|
package com.ruoyi.web.controller.system;
|
|
package com.ruoyi.web.controller.system;
|
|
|
|
|
|
import cn.hutool.core.util.ArrayUtil;
|
|
import cn.hutool.core.util.ArrayUtil;
|
|
-import cn.hutool.core.util.StrUtil;
|
|
|
|
import cn.hutool.json.JSONObject;
|
|
import cn.hutool.json.JSONObject;
|
|
-import cn.hutool.json.JSONUtil;
|
|
|
|
-import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
|
|
|
import com.ruoyi.common.annotation.Log;
|
|
import com.ruoyi.common.annotation.Log;
|
|
import com.ruoyi.common.constant.UserConstants;
|
|
import com.ruoyi.common.constant.UserConstants;
|
|
import com.ruoyi.common.core.controller.BaseController;
|
|
import com.ruoyi.common.core.controller.BaseController;
|
|
@@ -16,12 +13,18 @@ import com.ruoyi.system.service.ISysDeptService;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.security.access.prepost.PreAuthorize;
|
|
import org.springframework.security.access.prepost.PreAuthorize;
|
|
import org.springframework.validation.annotation.Validated;
|
|
import org.springframework.validation.annotation.Validated;
|
|
-import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
+import org.springframework.web.bind.annotation.DeleteMapping;
|
|
|
|
+import org.springframework.web.bind.annotation.GetMapping;
|
|
|
|
+import org.springframework.web.bind.annotation.PathVariable;
|
|
|
|
+import org.springframework.web.bind.annotation.PostMapping;
|
|
|
|
+import org.springframework.web.bind.annotation.PutMapping;
|
|
|
|
+import org.springframework.web.bind.annotation.RequestBody;
|
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
import java.util.Date;
|
|
import java.util.Date;
|
|
import java.util.HashMap;
|
|
import java.util.HashMap;
|
|
-import java.util.Iterator;
|
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
|
|
|
|
@@ -32,8 +35,7 @@ import java.util.Map;
|
|
*/
|
|
*/
|
|
@RestController
|
|
@RestController
|
|
@RequestMapping("/system/dept")
|
|
@RequestMapping("/system/dept")
|
|
-public class SysDeptController extends BaseController
|
|
|
|
-{
|
|
|
|
|
|
+public class SysDeptController extends BaseController {
|
|
@Autowired
|
|
@Autowired
|
|
private ISysDeptService deptService;
|
|
private ISysDeptService deptService;
|
|
|
|
|
|
@@ -42,8 +44,7 @@ public class SysDeptController extends BaseController
|
|
*/
|
|
*/
|
|
@PreAuthorize("@ss.hasPermi('system:dept:list')")
|
|
@PreAuthorize("@ss.hasPermi('system:dept:list')")
|
|
@GetMapping("/list")
|
|
@GetMapping("/list")
|
|
- public AjaxResult list(SysDept dept)
|
|
|
|
- {
|
|
|
|
|
|
+ public AjaxResult list(SysDept dept) {
|
|
List<SysDept> depts = deptService.selectDeptList(dept);
|
|
List<SysDept> depts = deptService.selectDeptList(dept);
|
|
return AjaxResult.success(depts);
|
|
return AjaxResult.success(depts);
|
|
}
|
|
}
|
|
@@ -53,8 +54,7 @@ public class SysDeptController extends BaseController
|
|
*/
|
|
*/
|
|
@PreAuthorize("@ss.hasPermi('system:dept:list')")
|
|
@PreAuthorize("@ss.hasPermi('system:dept:list')")
|
|
@GetMapping("/list/exclude/{deptId}")
|
|
@GetMapping("/list/exclude/{deptId}")
|
|
- public AjaxResult excludeChild(@PathVariable(value = "deptId", required = false) String deptId)
|
|
|
|
- {
|
|
|
|
|
|
+ public AjaxResult excludeChild(@PathVariable(value = "deptId", required = false) String deptId) {
|
|
List<SysDept> depts = deptService.selectDeptList(new SysDept());
|
|
List<SysDept> depts = deptService.selectDeptList(new SysDept());
|
|
depts.removeIf(d -> d.getDeptId().equals(deptId)
|
|
depts.removeIf(d -> d.getDeptId().equals(deptId)
|
|
|| ArrayUtil.contains(StringUtils.split(d.getAncestors(), ","), deptId + ""));
|
|
|| ArrayUtil.contains(StringUtils.split(d.getAncestors(), ","), deptId + ""));
|
|
@@ -66,8 +66,7 @@ public class SysDeptController extends BaseController
|
|
*/
|
|
*/
|
|
@PreAuthorize("@ss.hasPermi('system:dept:query')")
|
|
@PreAuthorize("@ss.hasPermi('system:dept:query')")
|
|
@GetMapping(value = "/{deptId}")
|
|
@GetMapping(value = "/{deptId}")
|
|
- public AjaxResult getInfo(@PathVariable String deptId)
|
|
|
|
- {
|
|
|
|
|
|
+ public AjaxResult getInfo(@PathVariable String deptId) {
|
|
deptService.checkDeptDataScope(deptId);
|
|
deptService.checkDeptDataScope(deptId);
|
|
return AjaxResult.success(deptService.selectDeptById(deptId));
|
|
return AjaxResult.success(deptService.selectDeptById(deptId));
|
|
}
|
|
}
|
|
@@ -76,8 +75,7 @@ public class SysDeptController extends BaseController
|
|
* 获取部门下拉树列表
|
|
* 获取部门下拉树列表
|
|
*/
|
|
*/
|
|
@GetMapping("/treeselect")
|
|
@GetMapping("/treeselect")
|
|
- public AjaxResult treeselect(SysDept dept)
|
|
|
|
- {
|
|
|
|
|
|
+ public AjaxResult treeselect(SysDept dept) {
|
|
List<SysDept> depts = deptService.selectDeptList(dept);
|
|
List<SysDept> depts = deptService.selectDeptList(dept);
|
|
return AjaxResult.success(deptService.buildDeptTreeSelect(depts));
|
|
return AjaxResult.success(deptService.buildDeptTreeSelect(depts));
|
|
}
|
|
}
|
|
@@ -86,10 +84,9 @@ public class SysDeptController extends BaseController
|
|
* 加载对应角色部门列表树
|
|
* 加载对应角色部门列表树
|
|
*/
|
|
*/
|
|
@GetMapping(value = "/roleDeptTreeselect/{roleId}")
|
|
@GetMapping(value = "/roleDeptTreeselect/{roleId}")
|
|
- public AjaxResult roleDeptTreeselect(@PathVariable("roleId") String roleId)
|
|
|
|
- {
|
|
|
|
|
|
+ public AjaxResult roleDeptTreeselect(@PathVariable("roleId") String 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 AjaxResult.success(ajax);
|
|
return AjaxResult.success(ajax);
|
|
@@ -101,10 +98,8 @@ public class SysDeptController extends BaseController
|
|
@PreAuthorize("@ss.hasPermi('system:dept:add')")
|
|
@PreAuthorize("@ss.hasPermi('system:dept:add')")
|
|
@Log(title = "部门管理", businessType = BusinessType.INSERT)
|
|
@Log(title = "部门管理", businessType = BusinessType.INSERT)
|
|
@PostMapping
|
|
@PostMapping
|
|
- public AjaxResult add(@Validated @RequestBody SysDept dept)
|
|
|
|
- {
|
|
|
|
- if (UserConstants.NOT_UNIQUE.equals(deptService.checkDeptNameUnique(dept)))
|
|
|
|
- {
|
|
|
|
|
|
+ public AjaxResult add(@Validated @RequestBody SysDept dept) {
|
|
|
|
+ if (UserConstants.NOT_UNIQUE.equals(deptService.checkDeptNameUnique(dept))) {
|
|
return AjaxResult.error("新增部门'" + dept.getDeptName() + "'失败,部门名称已存在");
|
|
return AjaxResult.error("新增部门'" + dept.getDeptName() + "'失败,部门名称已存在");
|
|
}
|
|
}
|
|
dept.setCreateBy(getUsername());
|
|
dept.setCreateBy(getUsername());
|
|
@@ -117,19 +112,13 @@ public class SysDeptController extends BaseController
|
|
@PreAuthorize("@ss.hasPermi('system:dept:edit')")
|
|
@PreAuthorize("@ss.hasPermi('system:dept:edit')")
|
|
@Log(title = "部门管理", businessType = BusinessType.UPDATE)
|
|
@Log(title = "部门管理", businessType = BusinessType.UPDATE)
|
|
@PutMapping
|
|
@PutMapping
|
|
- public AjaxResult edit(@Validated @RequestBody SysDept dept)
|
|
|
|
- {
|
|
|
|
- if (UserConstants.NOT_UNIQUE.equals(deptService.checkDeptNameUnique(dept)))
|
|
|
|
- {
|
|
|
|
|
|
+ public AjaxResult edit(@Validated @RequestBody SysDept dept) {
|
|
|
|
+ if (UserConstants.NOT_UNIQUE.equals(deptService.checkDeptNameUnique(dept))) {
|
|
return AjaxResult.error("修改部门'" + dept.getDeptName() + "'失败,部门名称已存在");
|
|
return AjaxResult.error("修改部门'" + dept.getDeptName() + "'失败,部门名称已存在");
|
|
- }
|
|
|
|
- else if (dept.getParentId().equals(dept.getDeptId()))
|
|
|
|
- {
|
|
|
|
|
|
+ } else if (dept.getParentId().equals(dept.getDeptId())) {
|
|
return AjaxResult.error("修改部门'" + dept.getDeptName() + "'失败,上级部门不能是自己");
|
|
return AjaxResult.error("修改部门'" + 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 AjaxResult.error("该部门包含未停用的子部门!");
|
|
return AjaxResult.error("该部门包含未停用的子部门!");
|
|
}
|
|
}
|
|
dept.setUpdateBy(getUsername());
|
|
dept.setUpdateBy(getUsername());
|
|
@@ -142,14 +131,11 @@ public class SysDeptController extends BaseController
|
|
@PreAuthorize("@ss.hasPermi('system:dept:remove')")
|
|
@PreAuthorize("@ss.hasPermi('system:dept:remove')")
|
|
@Log(title = "部门管理", businessType = BusinessType.DELETE)
|
|
@Log(title = "部门管理", businessType = BusinessType.DELETE)
|
|
@DeleteMapping("/{deptId}")
|
|
@DeleteMapping("/{deptId}")
|
|
- public AjaxResult remove(@PathVariable String deptId)
|
|
|
|
- {
|
|
|
|
- if (deptService.hasChildByDeptId(deptId))
|
|
|
|
- {
|
|
|
|
|
|
+ public AjaxResult remove(@PathVariable String deptId) {
|
|
|
|
+ if (deptService.hasChildByDeptId(deptId)) {
|
|
return AjaxResult.error("存在下级部门,不允许删除");
|
|
return AjaxResult.error("存在下级部门,不允许删除");
|
|
}
|
|
}
|
|
- if (deptService.checkDeptExistUser(deptId))
|
|
|
|
- {
|
|
|
|
|
|
+ if (deptService.checkDeptExistUser(deptId)) {
|
|
return AjaxResult.error("部门存在用户,不允许删除");
|
|
return AjaxResult.error("部门存在用户,不允许删除");
|
|
}
|
|
}
|
|
return toAjax(deptService.deleteDeptById(deptId));
|
|
return toAjax(deptService.deleteDeptById(deptId));
|
|
@@ -168,8 +154,6 @@ public class SysDeptController extends BaseController
|
|
sysDept.setUpdateBy("system");
|
|
sysDept.setUpdateBy("system");
|
|
sysDept.setCreateTime(new Date());
|
|
sysDept.setCreateTime(new Date());
|
|
sysDept.setUpdateTime(new Date());
|
|
sysDept.setUpdateTime(new Date());
|
|
- sysDept.setOrgId(jsonObject.getStr("orgId"));
|
|
|
|
- sysDept.setDeptShortName(jsonObject.getStr("deptShortName"));
|
|
|
|
sysDepts.add(sysDept);
|
|
sysDepts.add(sysDept);
|
|
}
|
|
}
|
|
deptService.saveBatch(sysDepts);
|
|
deptService.saveBatch(sysDepts);
|