heheng
2024-11-20 2d27b24029adafdbfc5703b38a519d65beda6a68
expert-admin/src/main/java/com/gkhy/web/controller/system/SysDeptController.java
@@ -1,32 +1,33 @@
package com.gkhy.web.controller.system;
import java.util.List;
import org.apache.commons.lang3.ArrayUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
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 com.gkhy.common.annotation.Anonymous;
import com.gkhy.common.annotation.Log;
import com.gkhy.common.constant.UserConstants;
import com.gkhy.common.core.controller.BaseController;
import com.gkhy.common.core.domain.AjaxResult;
import com.gkhy.common.core.domain.R;
import com.gkhy.common.core.domain.entity.SysDept;
import com.gkhy.common.enums.BusinessType;
import com.gkhy.common.utils.StringUtils;
import com.gkhy.system.service.ISysDeptService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
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.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
 * 部门信息
 * 
 * @author expert
 */
@Api(tags = "部门-业务处室")
@RestController
@RequestMapping("/system/dept")
public class SysDeptController extends BaseController
@@ -39,10 +40,22 @@
     */
    @PreAuthorize("@ss.hasPermi('system:dept:list')")
    @GetMapping("/list")
    public AjaxResult list(SysDept dept)
    @ApiOperation(value = "获取部门列表")
    public R<List<SysDept>> list(SysDept dept)
    {
        List<SysDept> depts = deptService.selectDeptList(dept);
        return success(depts);
        return R.ok(depts);
    }
    //    @PreAuthorize("@ss.hasPermi('system:dept:list')")
    @GetMapping("/getOutDeptList")
    @ApiOperation(value = "获取部门列表(公开)")
    @Anonymous
    public R<List<SysDept>> getOutDeptList(SysDept dept)
    {
        List<SysDept> depts = deptService.getOutDeptList(dept);
        return R.ok(depts);
    }
    /**
@@ -50,11 +63,15 @@
     */
    @PreAuthorize("@ss.hasPermi('system:dept:list')")
    @GetMapping("/list/exclude/{deptId}")
    public AjaxResult excludeChild(@PathVariable(value = "deptId", required = false) Long deptId)
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "deptId", dataType = "Long", required = true, value = "部门id"),
    })
    @ApiOperation(value = "查询部门列表(排除节点)")
    public R<List<SysDept>> excludeChild(@PathVariable(value = "deptId", required = false) Long deptId)
    {
        List<SysDept> depts = deptService.selectDeptList(new SysDept());
        depts.removeIf(d -> d.getDeptId().intValue() == deptId || ArrayUtils.contains(StringUtils.split(d.getAncestors(), ","), deptId + ""));
        return success(depts);
        return R.ok(depts);
    }
    /**
@@ -62,10 +79,14 @@
     */
    @PreAuthorize("@ss.hasPermi('system:dept:query')")
    @GetMapping(value = "/{deptId}")
    public AjaxResult getInfo(@PathVariable Long deptId)
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "deptId", dataType = "Long", required = true, value = "部门id"),
    })
    @ApiOperation(value = "根据部门编号获取详细信息")
    public R<SysDept> getInfo(@PathVariable Long deptId)
    {
        deptService.checkDeptDataScope(deptId);
        return success(deptService.selectDeptById(deptId));
        return  R.ok(deptService.selectDeptById(deptId));
    }
    /**
@@ -73,7 +94,8 @@
     */
    @PreAuthorize("@ss.hasPermi('system:dept:add')")
    @Log(title = "部门管理", businessType = BusinessType.INSERT)
    @PostMapping
    @PostMapping("/add")
    @ApiOperation(value = "新增部门业务处室")
    public AjaxResult add(@Validated @RequestBody SysDept dept)
    {
        if (!deptService.checkDeptNameUnique(dept))
@@ -89,6 +111,7 @@
     */
    @PreAuthorize("@ss.hasPermi('system:dept:edit')")
    @Log(title = "部门管理", businessType = BusinessType.UPDATE)
    @ApiOperation(value = "修改部门门业务处室")
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody SysDept dept)
    {
@@ -116,6 +139,7 @@
    @PreAuthorize("@ss.hasPermi('system:dept:remove')")
    @Log(title = "部门管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{deptId}")
    @ApiOperation(value = "删除部门门业务处室")
    public AjaxResult remove(@PathVariable Long deptId)
    {
        if (deptService.hasChildByDeptId(deptId))
@@ -126,6 +150,7 @@
        {
            return warn("部门存在用户,不允许删除");
        }
        //todo  校验专家是否申请复用
        deptService.checkDeptDataScope(deptId);
        return toAjax(deptService.deleteDeptById(deptId));
    }