黎星凯
2024-04-15 62b6a7fac3f2acde70b578431147c4a01f19c182
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
package com.consum.base.controller;
 
import java.util.List;
 
import cn.hutool.core.collection.CollectionUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
 
import com.consum.base.BaseController;
import com.consum.base.core.type.StatesType;
import com.consum.base.core.utils.CommonUtil;
import com.consum.base.pojo.FinSysTenantDepartmentParam;
import com.consum.base.service.FinSysTenantDepartmentService;
import com.consum.model.po.FinSysTenantDepartment;
import com.consum.model.po.FinSysTenantUser;
import com.walker.db.page.GenericPager;
import com.walker.infrastructure.utils.StringUtils;
import com.walker.web.ResponseValue;
 
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
 
/**
 * @Description 部门管理
 * @Author 卢庆阳
 * @Date 2023/10/26
 */
@Api(value = "部门管理", tags = "部门管理")
@RestController
@RequestMapping("/pc/fin/sys/tenant/department")
public class FinSysTenantDepartmentController extends BaseController {
 
    @Autowired
    private FinSysTenantDepartmentService departmentService;
 
    /**
     * @Description 新增
     * @Author 卢庆阳
     * @Date 2023/10/26
     */
    @ApiOperation(value = "新增", notes = "新增")
    @ApiImplicitParams(value = {
        @ApiImplicitParam(name = "param", value = "部门信息", required = true, dataType = "FinSysTenantDepartmentParam")})
    @PostMapping("/add")
    public ResponseValue add() {
        FinSysTenantDepartmentParam param = CommonUtil.getObjFromReqBody(FinSysTenantDepartmentParam.class);
        FinSysTenantDepartmentParam finSysTenantDepartmentParam = new FinSysTenantDepartmentParam();
        CommonUtil.copyProperties(param, finSysTenantDepartmentParam);
        param = finSysTenantDepartmentParam;
 
        if (StringUtils.isEmpty(param.getName())) {
            return ResponseValue.error("部门名称为空");
        }
        if (StringUtils.isEmpty(param.getCode())) {
            return ResponseValue.error("编号为空");
        }
        FinSysTenantDepartment tenantDepartment =
            departmentService.getTenantDepartment(null, param.getTenantId(), param.getCode());
        if (tenantDepartment != null) {
            return ResponseValue.error("部门编号已存在");
        }
        // 判断同一机构id下 部门名称 是否重复
        FinSysTenantDepartment department =
            departmentService.getTenantDepartment(param.getName(), param.getTenantId(), null);
        if (department != null) {
            return ResponseValue.error("部门名称已存在");
        }
        // 部门编号
        FinSysTenantDepartmentParam finSysTenantDepartmentParam1 = new FinSysTenantDepartmentParam();
        finSysTenantDepartmentParam1.setCode(param.getCode());
        List<FinSysTenantDepartment> datas = departmentService.queryDataList(finSysTenantDepartmentParam1);
        if(!CollectionUtil.isEmpty(datas)){
            return ResponseValue.error("此编号已存在");
        }
        int result = this.departmentService.add(param, this.getSysInfo());
        if (result > 0) {
            return ResponseValue.success();
        }
        return ResponseValue.error("新增失败!");
    }
 
    /**
     * @Description 部门列表查询
     * @Author 卢庆阳
     * @Date 2023/10/26
     */
    // 如果不传机构id,默认查省级机构的部门
    @GetMapping("/list")
    public ResponseValue queryList() {
        FinSysTenantDepartmentParam param = CommonUtil.getObjFromReq(FinSysTenantDepartmentParam.class);
        FinSysTenantDepartmentParam param2 = new FinSysTenantDepartmentParam();
        CommonUtil.copyProperties(param, param2);
        param = param2;
 
        FinSysTenantUser sysInfo = this.getSysInfo();
        if (sysInfo == null) {
            return ResponseValue.error("登录用户信息不存在");
        }
        GenericPager<FinSysTenantDepartment> pager = this.departmentService.queryList(param);
        return ResponseValue.success(pager);
    }
 
    @ApiOperation(value = "根据机构id查询所有部门列表信息", notes = "根据机构id查询所有部门列表信息")
    @ApiImplicitParams(value = {
        @ApiImplicitParam(name = "param", value = "部门信息", required = true, dataType = "FinSysTenantDepartmentParam")})
    @GetMapping("/list/all")
    public ResponseValue queryAllDepartment(Long tenantId) {
        FinSysTenantUser sysInfo = this.getSysInfo();
        if (sysInfo == null) {
            return ResponseValue.error("登录用户信息不存在");
        }
        FinSysTenantDepartment finSysTenantDepartment = new FinSysTenantDepartment();
        finSysTenantDepartment.setTenantId(tenantId);
        finSysTenantDepartment.setStatus(StatesType.NORMAL.getValue());
        List<FinSysTenantDepartment> finSysTenantDepartments = this.departmentService.select(finSysTenantDepartment);
        return ResponseValue.success(finSysTenantDepartments);
    }
 
    /**
     * @Description 编辑(修改状态)
     * @Author 卢庆阳
     * @Date 2023/10/26
     */
    @PostMapping("/edit")
    public ResponseValue edit() {
        FinSysTenantDepartment param = CommonUtil.getObjFromReqBody(FinSysTenantDepartment.class);
        FinSysTenantDepartment finSysTenantDepartment = new FinSysTenantDepartment();
        CommonUtil.copyProperties(param, finSysTenantDepartment);
        param = finSysTenantDepartment;
 
        Long id = param.getId();
        if (id == null || id <= 0) {
            return ResponseValue.error("编辑的部门不存在");
        }
        if (StringUtils.isEmpty(param.getName())) {
            return ResponseValue.error("部门名称为空");
        }
        if (StringUtils.isEmpty(param.getCode())) {
            return ResponseValue.error("部门编号为空");
        }
        FinSysTenantUser sysInfo = this.getSysInfo();
        if (sysInfo == null) {
            return ResponseValue.error("登录用户信息不存在");
        }
        FinSysTenantDepartment tenantDepartment =
            this.departmentService.getTenantDepartment(null, param.getTenantId(), param.getCode());
        if (tenantDepartment != null) {
            //return ResponseValue.error("部门编号已存在");
        }
        // 部门编号
        FinSysTenantDepartmentParam finSysTenantDepartmentParam1 = new FinSysTenantDepartmentParam();
        finSysTenantDepartmentParam1.setCode(param.getCode());
        List<FinSysTenantDepartment> datas = departmentService.queryDataList(finSysTenantDepartmentParam1);
        if(!CollectionUtil.isEmpty(datas)){
            FinSysTenantDepartment finSysTenantDepartment1 = datas.get(0);
            if(!finSysTenantDepartment1.getId().equals(param.getId())){
                return ResponseValue.error("此编号已存在");
            }
        }
        int num = this.departmentService.updateFinSysTenantDepartment(param, sysInfo);
        return num > 0 ? ResponseValue.success() : ResponseValue.error("编辑失败!");
    }
 
    /**
     * 根据部门id查询部门详情
     *
     * @author 卢庆阳
     * @Date 2023/10/26
     */
    @GetMapping("/detail")
    public ResponseValue getById(Long id) {
        if (id == null) {
            return ResponseValue.error("部门id为空");
        }
        FinSysTenantDepartment department = this.departmentService.getById(id);
        if (department == null) {
            return ResponseValue.error("查询失败!");
        }
        return ResponseValue.success("查询成功!", department);
    }
 
    /**
     * @Description 根据id删除部门
     * @Author 卢庆阳
     * @Date 2023/10/26
     */
    @DeleteMapping("/del")
    public ResponseValue updateById() {
        FinSysTenantDepartment param = CommonUtil.getObjFromReqBody(FinSysTenantDepartment.class);
        FinSysTenantDepartment finSysTenantDepartment = new FinSysTenantDepartment();
        CommonUtil.copyProperties(param, finSysTenantDepartment);
        param = finSysTenantDepartment;
 
        if (param.getId() == null) {
            return ResponseValue.error("部门id为空");
        }
        FinSysTenantUser sysInfo = this.getSysInfo();
        if (sysInfo == null) {
            return ResponseValue.error("登录用户信息不存在");
        }
        int num = this.departmentService.updateById(param, sysInfo);
 
        return num > 0 ? ResponseValue.success(1) : ResponseValue.error("删除失败!");
    }
 
}