lyh
2025-01-13 48e850f8721a5562c2d0c23f9281f92ec1ba947a
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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
package org.jeecg.modules.dnc.controller;
 
import cn.hutool.core.util.StrUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.SecurityUtils;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.modules.dnc.entity.ProductInfo;
import org.jeecg.modules.dnc.response.CommonCode;
import org.jeecg.modules.dnc.response.CommonGenericTree;
import org.jeecg.modules.dnc.response.QueryListResponseResult;
import org.jeecg.modules.dnc.response.ResponseResult;
import org.jeecg.modules.dnc.service.IProductInfoService;
import org.jeecg.modules.dnc.ucenter.Department;
import org.jeecg.modules.dnc.ucenter.UserDepartExt;
import org.jeecg.modules.dnc.utils.ValidateUtil;
import org.jeecg.modules.system.entity.SysUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
 
import java.util.Collections;
import java.util.List;
@Slf4j
@Api(tags = "产品表")
@RestController
@RequestMapping("/nc/product")
public class ProductInfoController extends JeecgController<ProductInfo, IProductInfoService> {
 
    @Autowired
    private IProductInfoService productInfoService;
 
    @AutoLog(value = "产品表-新增产品信息")
    @ApiOperation(value = "产品表-新增产品信息", notes = "产品表-新增产品信息")
    @PostMapping("/add")
    public ResponseResult addProductInfo(@RequestBody ProductInfo productInfo) {
        boolean b = productInfoService.addProductInfo(productInfo);
        if(b) {
            return new ResponseResult(CommonCode.SUCCESS);
        }
        return new ResponseResult(CommonCode.FAIL);
    }
 
    @AutoLog(value = "产品表-编辑产品信息")
    @ApiOperation(value = "产品表-编辑产品信息", notes = "产品表-编辑产品信息")
    @PutMapping("/edit/{id}")
    public ResponseResult editProductInfo(@PathVariable("id") String id,@RequestBody ProductInfo productInfo) {
        boolean b = productInfoService.editProductInfo(id, productInfo);
        if(b) {
            return new ResponseResult(CommonCode.SUCCESS);
        }
        return new ResponseResult(CommonCode.FAIL);
    }
 
    @AutoLog(value = "产品表-获取产品结构树接口")
    @ApiOperation(value = "产品表-获取产品结构树接口", notes = "产品表-获取产品结构树接口")
    @GetMapping("/load/tree")
    public QueryListResponseResult<CommonGenericTree> loadProductTree() {
        LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        String userId = user.getId();
        if(!ValidateUtil.validateString(userId))
            return new QueryListResponseResult<>(CommonCode.SUCCESS, Collections.emptyList());
        List<CommonGenericTree> list = productInfoService.loadProductTree(userId);
        if(list == null)
            list = Collections.emptyList();
        return new QueryListResponseResult<>(CommonCode.SUCCESS, list);
    }
 
    @AutoLog(value = "产品表-获取产品树的第一级和第二级")
    @ApiOperation(value = "产品表-获取产品树的第一级和第二级", notes = "产品表-获取产品树的第一级和第二级")
    @GetMapping("/load/tree/base")
    public QueryListResponseResult<CommonGenericTree> loadBaseTree() {
        LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        String userId = user.getId();
        if(!ValidateUtil.validateString(userId))
            return new QueryListResponseResult<>(CommonCode.SUCCESS, Collections.emptyList());
        List<CommonGenericTree> list = productInfoService.loadBaseTree(userId);
        if(list == null)
            list = Collections.emptyList();
        return new QueryListResponseResult<>(CommonCode.SUCCESS, list);
    }
 
    @AutoLog(value = "产品表-加载产品树子节点数据")
    @ApiOperation(value = "产品表-加载产品树子节点数据", notes = "产品表-加载产品树子节点数据")
    @GetMapping("/load/tree/child/{nodeType}/{paramId}")
    public QueryListResponseResult<CommonGenericTree> loadTree(@PathVariable("nodeType") Integer nodeType, @PathVariable("paramId") String paramId) {
        LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        String userId = user.getId();
        if(!ValidateUtil.validateString(userId))
            return new QueryListResponseResult<>(CommonCode.SUCCESS, Collections.emptyList());
        List<CommonGenericTree> list = productInfoService.loadTree(userId, nodeType, paramId);
        if(list == null)
            list = Collections.emptyList();
        return new QueryListResponseResult<>(CommonCode.SUCCESS, list);
    }
 
 
    @AutoLog(value = "产品表-删除产品")
    @ApiOperation(value = "产品表-删除产品", notes = "产品表-删除产品")
    @DeleteMapping("/delete")
    public ResponseResult deleteProductInfo(@RequestParam("id") String id) {
        boolean b = productInfoService.deleteProductInfo(id);
        if(b) {
            return new ResponseResult(CommonCode.SUCCESS);
        }
        return new ResponseResult(CommonCode.FAIL);
    }
 
    @AutoLog(value = "产品表-检查产品树节点的查看权限")
    @ApiOperation(value = "产品表-检查产品树节点的查看权限", notes = "产品表-检查产品树节点的查看权限")
    @GetMapping("/check/{nodeType}/{paramId}")
    public ResponseResult checkProductPerm(@PathVariable("nodeType") Integer nodeType, @PathVariable("paramId") String paramId) {
        boolean b = productInfoService.checkProductPerm(nodeType, paramId);
        if(b) {
            return new ResponseResult(CommonCode.SUCCESS);
        }
        return new ResponseResult(CommonCode.UNAUTHORISE);
    }
 
    @AutoLog(value = "产品表-获取已分配的用户")
    @ApiOperation(value = "产品表-获取已分配的用户", notes = "产品表-获取已分配的用户")
    @GetMapping("/get/perm/user/{nodeType}/{paramId}")
    public QueryListResponseResult<UserDepartExt> getUserPermsList(@PathVariable("nodeType") Integer nodeType, @PathVariable("paramId")  String paramId) {
        List<UserDepartExt> list = productInfoService.getUserPermsList(nodeType, paramId);
        if(list == null)
            list = Collections.emptyList();
        return new QueryListResponseResult(CommonCode.SUCCESS, list);
    }
 
    @AutoLog(value = "产品表-获取未分配的用户")
    @ApiOperation(value = "产品表-获取未分配的用户", notes = "产品表-获取未分配的用户")
    @GetMapping("/get/non/perm/user/{nodeType}/{paramId}")
    public QueryListResponseResult<SysUser> getUserNonPermsList(@PathVariable("nodeType") Integer nodeType, @PathVariable("paramId")  String paramId) {
        List<SysUser> list = productInfoService.getUserNonPermsList(nodeType, paramId);
        if(list == null)
            list = Collections.emptyList();
        return new QueryListResponseResult(CommonCode.SUCCESS, list);
    }
 
    @AutoLog(value = "产品表-获取已分配的部门")
    @ApiOperation(value = "产品表-获取已分配的部门", notes = "产品表-获取已分配的部门")
    @GetMapping("/get/perm/depart/{nodeType}/{paramId}")
    public QueryListResponseResult<Department> getDepartPermsList(@PathVariable("nodeType") Integer nodeType, @PathVariable("paramId")  String paramId) {
        List<Department> list = productInfoService.getDepartPermsList(nodeType, paramId);
        if(list == null)
            list = Collections.emptyList();
        return new QueryListResponseResult(CommonCode.SUCCESS, list);
    }
 
    @AutoLog(value = "产品表-获取未分配的部门")
    @ApiOperation(value = "产品表-获取未分配的部门", notes = "产品表-获取未分配的部门")
    @GetMapping("/get/non/perm/depart/{nodeType}/{paramId}")
    public QueryListResponseResult<Department> getDepartNonPermsList(@PathVariable("nodeType") Integer nodeType, @PathVariable("paramId")  String paramId) {
        List<Department> list = productInfoService.getDepartNonPermsList(nodeType, paramId);
        if(list == null)
            list = Collections.emptyList();
        return new QueryListResponseResult(CommonCode.SUCCESS, list);
    }
 
    /**
     * 指派产品树节点的用户权限
     * @param nodeType 1 产品 2 部件 3 零件
     * @param paramId 产品树节点id
     * @param userIds 添加用户ids
     * @param relativeFlag 1 是 2 否
     * @return
     */
    @AutoLog(value = "产品表-指派产品树节点的用户权限")
    @ApiOperation(value = "产品表-指派产品树节点的用户权限", notes = "产品表-指派产品树节点的用户权限")
    @PostMapping("/assign/add/user/{nodeType}/{paramId}/{relativeFlag}")
    public ResponseResult assignAddUser(@PathVariable("nodeType") Integer nodeType, @PathVariable("paramId") String paramId, @PathVariable("relativeFlag") Integer relativeFlag, @RequestBody String[] userIds) {
        boolean b = productInfoService.assignAddUser(nodeType, paramId, relativeFlag, userIds);
        if(b) {
            return new ResponseResult(CommonCode.SUCCESS);
        }
        return new ResponseResult(CommonCode.FAIL);
    }
 
    /**
     * 移除产品树节点的用户权限
     * @param nodeType 1 产品 2 部件 3 零件
     * @param paramId 产品树节点id
     * @param userIds 移除用户ids
     * @param relativeFlag 1 是 2 否
     * @return
     */
    @AutoLog(value = "产品表-移除产品树节点的用户权限")
    @ApiOperation(value = "产品表-移除产品树节点的用户权限", notes = "产品表-移除产品树节点的用户权限")
    @PostMapping("/assign/remove/user/{nodeType}/{paramId}/{relativeFlag}")
    public ResponseResult assignRemoveUser(@PathVariable("nodeType") Integer nodeType, @PathVariable("paramId") String paramId, @PathVariable("relativeFlag") Integer relativeFlag, @RequestBody String[] userIds) {
        boolean b = productInfoService.assignRemoveUser(nodeType, paramId, relativeFlag, userIds);
        if(b) {
            return new ResponseResult(CommonCode.SUCCESS);
        }
        return new ResponseResult(CommonCode.FAIL);
    }
 
    /**
     * 指派产品树节点的部门权限
     * @param nodeType 1 产品 2 部件 3 零件
     * @param paramId 产品树节点id
     * @param departmentIds 添加部门ids
     * @param relativeFlag 1 是 2 否
     * @return
     */
    @AutoLog(value = "产品表-指派产品树节点的部门权限")
    @ApiOperation(value = "产品表-指派产品树节点的部门权限", notes = "产品表-指派产品树节点的部门权限")
    @PostMapping("/assign/add/department/{nodeType}/{paramId}/{relativeFlag}")
    public ResponseResult assignAddDepartment(@PathVariable("nodeType") Integer nodeType, @PathVariable("paramId") String paramId, @PathVariable("relativeFlag") Integer relativeFlag, @RequestBody String[] departmentIds) {
        boolean b = productInfoService.assignAddDepartment(nodeType, paramId, relativeFlag, departmentIds);
        if(b) {
            return new ResponseResult(CommonCode.SUCCESS);
        }
        return new ResponseResult(CommonCode.FAIL);
    }
 
    /**
     * 移除产品树节点的部门权限
     * @param nodeType 1 产品 2 部件 3 零件
     * @param paramId 产品树节点id
     * @param departmentIds 移除部门ids
     * @param relativeFlag 1 是 2 否
     * @return
     */
    @AutoLog(value = "产品表-移除产品树节点的部门权限")
    @ApiOperation(value = "产品表-移除产品树节点的部门权限", notes = "产品表-移除产品树节点的部门权限")
    @PostMapping("/assign/remove/department/{nodeType}/{paramId}/{relativeFlag}")
    public ResponseResult assignRemoveDepartment(@PathVariable("nodeType") Integer nodeType, @PathVariable("paramId") String paramId, @PathVariable("relativeFlag") Integer relativeFlag, @RequestBody String[] departmentIds) {
        boolean b = productInfoService.assignRemoveDepartment(nodeType, paramId, relativeFlag, departmentIds);
        if(b) {
            return new ResponseResult(CommonCode.SUCCESS);
        }
        return new ResponseResult(CommonCode.FAIL);
    }
 
    /**
     * 搜索接口
     * @param queryParam
     * @return
     */
    @AutoLog(value = "产品表-搜索接口")
    @ApiOperation(value = "产品表-搜索接口", notes = "产品表-搜索接口")
    @GetMapping("/search")
    public QueryListResponseResult<CommonGenericTree> searchProductTree(String queryParam) {
        LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        String userId = user.getId();
        if(!ValidateUtil.validateString(userId))
            return new QueryListResponseResult<>(CommonCode.SUCCESS, Collections.emptyList());
        List<CommonGenericTree> list = productInfoService.searchProductTree(userId,  queryParam);
        if(list == null)
            list = Collections.emptyList();
        return new QueryListResponseResult<>(CommonCode.SUCCESS, list);
    }
}