jinlin
2024-01-15 1a7af6fff5185bb257c16b0445140c93263a3331
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/**
 * Copyright (c) 2018 人人开源 All rights reserved.
 *
 * https://www.renren.io
 *
 * 版权所有,侵权必究!
 */
 
package com.zt.modules.sys.controller;
 
import com.zt.common.annotation.LogOperation;
import com.zt.common.constant.Constant;
import com.zt.common.servlet.Result;
import com.zt.common.validator.AssertUtils;
import com.zt.common.validator.ValidatorUtils;
import com.zt.common.validator.group.DefaultGroup;
import com.zt.common.validator.group.UpdateGroup;
import com.zt.core.sys.model.SysDept;
import com.zt.modules.sys.service.SysDeptService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
 
import java.util.List;
 
/**
 * 部门管理
 *
 * @author hehz
 */
@RestController
@RequestMapping("/sys/dept")
@Api(tags = "部门管理")
public class SysDeptController {
    @Autowired
    private SysDeptService sysDeptService;
 
    @GetMapping("list")
    @ApiOperation("公司下部门列表")
    @RequiresPermissions("sys:dept:list")
    public Result<List<SysDept>> pageList(@RequestParam Long companyId) {
        List<SysDept> list = sysDeptService.getDeptList(companyId);
        return Result.ok(list);
    }
 
    @GetMapping("getList")
    @ApiOperation("部门列表")
    // @RequiresPermissions("sys:dept:list")
    public Result<List<SysDept>> getlist() {
        List<SysDept> list = sysDeptService.getDeptList3();
        return Result.ok(list);
    }
 
    @GetMapping("tree")
    @ApiOperation("部门树")
    // @RequiresPermissions("sys:dept:list")
    public Result<List<SysDept>> list() {
        List<SysDept> list = sysDeptService.getDeptTree();
        return Result.ok(list);
    }
 
    @GetMapping("treeRegister")
    @ApiOperation("部门树")
    // @RequiresPermissions("sys:dept:list")
    public Result<List<SysDept>> list2() {
        List<SysDept> list = sysDeptService.getDeptTreeRegister();
        return Result.ok(list);
    }
 
    @GetMapping("{id}")
    @ApiOperation("信息")
    @RequiresPermissions("sys:dept:info")
    public Result<SysDept> get(@PathVariable("id") Long id) {
        SysDept data = sysDeptService.get(id);
 
        return Result.ok(data);
    }
 
    @PostMapping
    @ApiOperation("新增")
    @LogOperation("部门管理模块--->新增")
    @RequiresPermissions("sys:dept")
    public Result insert(@RequestBody SysDept entity) {
        // // 效验数据
        // ValidatorUtils.validateEntity(entity, AddGroup.class,
        // DefaultGroup.class);
        // 默认基础信息
        entity.setCompany(false);
        // entity.setNature(Constant.DeptType.DEPT);
        // 如果为公司下的一级部门,则pid为公司Id
        if (entity.getPid() == Constant.Sys.DEPT_ROOT) {
            entity.setPid(entity.getCompanyId());
        }
 
        sysDeptService.insert(entity);
 
        return Result.ok();
    }
 
    @PutMapping
    @ApiOperation("修改")
    @LogOperation("部门管理模块--->修改")
    @RequiresPermissions("sys:dept:update")
    public Result update(@RequestBody SysDept entity) {
        // 效验数据
        ValidatorUtils.validateEntity(entity, UpdateGroup.class, DefaultGroup.class);
 
        sysDeptService.update(entity);
 
        return Result.ok();
    }
 
    @DeleteMapping
    @ApiOperation("删除")
    @LogOperation("部门管理模块--->删除")
    @RequiresPermissions("sys:dept:delete")
    public Result delete(@RequestBody Long[] ids) {
        // 效验数据
        AssertUtils.isArrayEmpty(ids, "ids");
 
        for (Long id : ids) {
            sysDeptService.delete(id);
        }
 
        return Result.ok();
    }
 
}