44323
2024-05-16 80870e154d7755c36cdb345147532c131858e270
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package com.ruoyi.system.controller;
 
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.PageInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.common.security.utils.SecurityUtils;
import com.ruoyi.system.api.domain.SysDept;
import com.ruoyi.system.api.dto.SysDeptAddDTO;
import com.ruoyi.system.service.ISysDeptService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
 
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
 
/**
 * 部门信息
 * 
 * @author ruoyi
 */
@RestController
@RequestMapping("/dept")
@Api(tags = "部门管理")
public class SysDeptController extends BaseController
{
    @Autowired
    private ISysDeptService deptService;
 
    @GetMapping("/list")
    @ApiOperation("部门列表")
    public AjaxResult<PageInfo<SysDept>> list(String deptName, int pageNumber, int pageSize) {
        PageInfo<SysDept> pageInfo = new PageInfo<>(pageNumber, pageSize);
        PageInfo<SysDept> page = deptService.getList(pageInfo, deptName);
        List<SysDept> records = page.getRecords();
        SimpleDateFormat format = new SimpleDateFormat("yyyy.MM.dd");
        for (SysDept record : records) {
            Date createTime = record.getCreateTime();
            String format1 = format.format(createTime);
            record.setCreateTime1(format1);
        }
        return AjaxResult.success(page);
    }
 
    /**
     * 新增部门
     */
    @Log(title = "部门管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ApiOperation("部门添加")
    public AjaxResult add(@Validated @RequestBody SysDeptAddDTO dto)
    {
        SysDept sysDept = new SysDept();
        sysDept.setDeptName(dto.getDeptName());
        sysDept.setCreateTime(new Date());
        if (!deptService.checkDeptNameUnique(sysDept))
        {return error("新增部门'" + dto.getDeptName() + "'失败,部门名称已存在");}
        sysDept.setCreateBy(SecurityUtils.getUsername());
        return toAjax(deptService.insertDept(sysDept));
    }
 
    /**
     * 修改部门
     */
    @Log(title = "部门管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ApiOperation("部门修改")
    public AjaxResult edit(@Validated @RequestBody SysDeptAddDTO dept)
    {
        SysDept sysDept = new SysDept();
        sysDept.setDeptId(dept.getDeptId());
        sysDept.setDeptName(dept.getDeptName());
        if (!deptService.checkDeptNameUnique(sysDept))
        {
            return error("修改部门'" + dept.getDeptName() + "'失败,部门名称已存在");
        }
        sysDept.setUpdateBy(SecurityUtils.getUsername());
        return toAjax(deptService.updateDept(sysDept));
    }
 
    /**
     * 删除部门
     */
    @RequiresPermissions("system:dept:remove")
    @Log(title = "部门管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{deptId}")
    @ApiOperation("删除部门")
    public AjaxResult remove(@PathVariable Long deptId)
    {
        if (deptService.checkDeptExistUser(deptId)) {
            return warn("部门存在用户,不允许删除");
        }
        return toAjax(deptService.deleteDeptById(deptId));
    }
 
}