Przeglądaj źródła

单位本级和子孙及

hexiao 2 lat temu
rodzic
commit
7a47d931c9

+ 28 - 30
purchase-admin/src/main/java/com/ozs/web/controller/system/SysDeptController.java

@@ -1,5 +1,6 @@
 package com.ozs.web.controller.system;
 
+import java.util.ArrayList;
 import java.util.List;
 
 import io.swagger.annotations.Api;
@@ -7,6 +8,7 @@ import io.swagger.annotations.ApiOperation;
 import org.apache.commons.lang3.ArrayUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.security.access.prepost.PreAuthorize;
+import org.springframework.util.ObjectUtils;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.DeleteMapping;
 import org.springframework.web.bind.annotation.GetMapping;
@@ -30,11 +32,10 @@ import com.ozs.system.service.ISysDeptService;
  *
  * @author ruoyi
  */
-@Api(tags="部门信息")
+@Api(tags = "部门信息")
 @RestController
 @RequestMapping("/system/dept")
-public class SysDeptController extends BaseController
-{
+public class SysDeptController extends BaseController {
     @Autowired
     private ISysDeptService deptService;
 
@@ -55,8 +56,17 @@ public class SysDeptController extends BaseController
     @GetMapping("/listByUser")
     @ApiOperation("根据获取本级和子孙级部门列表")
     public AjaxResult listByUser() {
-        List<SysDept> depts = deptService.selectDeptList(dept);
-        return success(depts);
+        Long deptId = getDeptId();
+        List<SysDept> list = new ArrayList<>();
+        SysDept s = deptService.selectById(deptId);
+        if (!ObjectUtils.isEmpty(s)) {
+            list.add(s);
+            List<SysDept> sl = deptService.selectChildrenDeptById(deptId);
+            if (!ObjectUtils.isEmpty(sl)) {
+                list.addAll(sl);
+            }
+        }
+        return success(list);
     }
 
     /**
@@ -76,8 +86,7 @@ public class SysDeptController extends BaseController
      */
     @GetMapping(value = "/{deptId}")
     @ApiOperation("根据部门编号获取详细信息")
-    public AjaxResult getInfo(@PathVariable Long deptId)
-    {
+    public AjaxResult getInfo(@PathVariable Long deptId) {
         deptService.checkDeptDataScope(deptId);
         return success(deptService.selectDeptById(deptId));
     }
@@ -86,13 +95,11 @@ public class SysDeptController extends BaseController
      * 新增部门
      */
     @PreAuthorize("@ss.hasPermi('system:dept:add')")
-    @Log(title = "部门管理", businessType = BusinessType.INSERT)
+    @Log(title = "部门管理" , businessType = BusinessType.INSERT)
     @PostMapping
     @ApiOperation("新增部门")
-    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 error("新增部门'" + dept.getDeptName() + "'失败,部门名称已存在");
         }
         dept.setCreateBy(getUsername());
@@ -103,23 +110,17 @@ public class SysDeptController extends BaseController
      * 修改部门
      */
     @PreAuthorize("@ss.hasPermi('system:dept:edit')")
-    @Log(title = "部门管理", businessType = BusinessType.UPDATE)
+    @Log(title = "部门管理" , businessType = BusinessType.UPDATE)
     @PutMapping
     @ApiOperation("修改部门")
-    public AjaxResult edit(@Validated @RequestBody SysDept dept)
-    {
+    public AjaxResult edit(@Validated @RequestBody SysDept dept) {
         Long deptId = dept.getDeptId();
         deptService.checkDeptDataScope(deptId);
-        if (UserConstants.NOT_UNIQUE.equals(deptService.checkDeptNameUnique(dept)))
-        {
+        if (UserConstants.NOT_UNIQUE.equals(deptService.checkDeptNameUnique(dept))) {
             return error("修改部门'" + dept.getDeptName() + "'失败,部门名称已存在");
-        }
-        else if (dept.getParentId().equals(deptId))
-        {
+        } else if (dept.getParentId().equals(deptId)) {
             return error("修改部门'" + dept.getDeptName() + "'失败,上级部门不能是自己");
-        }
-        else if (StringUtils.equals(UserConstants.DEPT_DISABLE, dept.getStatus()) && deptService.selectNormalChildrenDeptById(deptId) > 0)
-        {
+        } else if (StringUtils.equals(UserConstants.DEPT_DISABLE, dept.getStatus()) && deptService.selectNormalChildrenDeptById(deptId) > 0) {
             return error("该部门包含未停用的子部门!");
         }
         dept.setUpdateBy(getUsername());
@@ -130,17 +131,14 @@ public class SysDeptController extends BaseController
      * 删除部门
      */
     @PreAuthorize("@ss.hasPermi('system:dept:remove')")
-    @Log(title = "部门管理", businessType = BusinessType.DELETE)
+    @Log(title = "部门管理" , businessType = BusinessType.DELETE)
     @DeleteMapping("/{deptId}")
     @ApiOperation("删除部门")
-    public AjaxResult remove(@PathVariable Long deptId)
-    {
-        if (deptService.hasChildByDeptId(deptId))
-        {
+    public AjaxResult remove(@PathVariable Long deptId) {
+        if (deptService.hasChildByDeptId(deptId)) {
             return warn("存在下级部门,不允许删除");
         }
-        if (deptService.checkDeptExistUser(deptId))
-        {
+        if (deptService.checkDeptExistUser(deptId)) {
             return warn("部门存在用户,不允许删除");
         }
         deptService.checkDeptDataScope(deptId);

+ 2 - 0
purchase-system/src/main/java/com/ozs/system/service/ISysDeptService.java

@@ -127,4 +127,6 @@ public interface ISysDeptService {
     public String isExcessOrNo(String projectType, BigDecimal evaluation, Long deptId);
 
     public SysDept selectById(Long deptId);
+
+    public List<SysDept> selectChildrenDeptById(Long deptId);
 }

+ 5 - 0
purchase-system/src/main/java/com/ozs/system/service/impl/SysDeptServiceImpl.java

@@ -362,4 +362,9 @@ public class SysDeptServiceImpl implements ISysDeptService {
     public SysDept selectById(Long deptId) {
         return deptMapper.selectDeptById(deptId);
     }
+
+    @Override
+    public List<SysDept> selectChildrenDeptById(Long deptId) {
+        return deptMapper.selectChildrenDeptById(deptId);
+    }
 }