lyh
2025-04-11 2cf1565485060fd56e1f1f1cffbba7a4d70d42a6
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
package org.jeecg.modules.dnc.controller;
 
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecg.modules.dnc.entity.DeviceInfo;
import org.jeecg.modules.dnc.response.*;
import org.jeecg.modules.dnc.service.IDeviceInfoService;
import org.jeecg.modules.dnc.service.IDevicePermissionService;
import org.jeecg.modules.mdc.model.MdcEquipmentTree;
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/device")
public class DeviceInfoController extends JeecgController<DeviceInfo, IDeviceInfoService> {
    @Autowired
    private IDeviceInfoService deviceInfoService;
    @Autowired
    private IDevicePermissionService devicePermissionService;
 
    @AutoLog(value = "设备表-新增设备")
    @ApiOperation(value = "设备表-新增设备", notes = "设备表-新增设备")
    @PostMapping("/add")
    public ResponseResult addDeviceInfo(@RequestBody DeviceInfo deviceInfo) {
        boolean b = deviceInfoService.addDeviceInfo(deviceInfo);
        if(b) {
            return new ResponseResult(CommonCode.SUCCESS);
        }
        return new ResponseResult(CommonCode.FAIL);
    }
 
    @AutoLog(value = "设备表-编辑设备信息")
    @ApiOperation(value = "设备表-编辑设备信息", notes = "设备表-编辑设备信息")
    @PutMapping("/edit/{id}")
    public ResponseResult editDeviceInfo(@PathVariable("id") String id, @RequestBody DeviceInfo deviceInfo) {
        boolean b = deviceInfoService.editDeviceInfo(id, deviceInfo);
        if(b) {
            return new ResponseResult(CommonCode.SUCCESS);
        }
        return new ResponseResult(CommonCode.FAIL);
    }
 
    @AutoLog(value = "设备表-删除设备")
    @ApiOperation(value = "设备表-删除设备", notes = "设备表-删除设备")
    @DeleteMapping("/delete")
    public ResponseResult deleteDeviceInfo(@RequestParam("id") String id) {
        boolean b = deviceInfoService.deleteDeviceInfo(id);
        if(b) {
            return new ResponseResult(CommonCode.SUCCESS);
        }
        return new ResponseResult(CommonCode.FAIL);
    }
 
    @AutoLog(value = "设备表-根据用户权限获取树")
    @ApiOperation(value = "设备表-根据用户权限获取树", notes = "设备表-根据用户权限获取树")
    @GetMapping("/load/tree")
    public QueryListResponseResult<CommonGenericTree> loadTree() {
        List<CommonGenericTree> list = deviceInfoService.loadTree();
        if(list == null)
            list = Collections.emptyList();
        return new QueryListResponseResult(CommonCode.SUCCESS, list);
    }
 
    @AutoLog(value = "设备表-获取节点已分配的用户")
    @ApiOperation(value = "设备表-获取节点已分配的用户", notes = "设备表-获取节点已分配的用户")
    @GetMapping("/get/perm/user/{nodeType}/{paramId}")
    public QueryListResponseResult<SysUser> getUserPermsList(@PathVariable("nodeType") Integer nodeType, @PathVariable("paramId") String paramId) {
        List<SysUser> list = deviceInfoService.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 = deviceInfoService.getUserNonPermsList(nodeType, paramId);
        if(list == null)
            list = Collections.emptyList();
        return new QueryListResponseResult(CommonCode.SUCCESS, list);
    }
 
    /**
     * 检查用户是否有该设备的权限
     * @param nodeType 1 设备分组 2 设备
     * @param paramId
     * @return
     */
    @AutoLog(value = "设备表-检查用户是否有该设备的权限 1 设备分组 2 设备")
    @ApiOperation(value = "设备表-检查用户是否有该设备的权限 1 设备分组 2 设备", notes = "设备表-检查用户是否有该设备的权限 1 设备分组 2 设备")
    @GetMapping("/check/{nodeType}/{paramId}")
    public ResponseResult checkDevicePerm(@PathVariable("nodeType") Integer nodeType,@PathVariable("paramId") String paramId) {
        boolean b = deviceInfoService.checkDevicePerm(nodeType, paramId);
        if(b) {
            return new ResponseResult(CommonCode.SUCCESS);
        }
        return new ResponseResult(CommonCode.UNAUTHORISE);
    }
 
    @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 = deviceInfoService.assignAddUser(nodeType, paramId, relativeFlag, userIds);
        if(b) {
            return new ResponseResult(CommonCode.SUCCESS);
        }
        return new ResponseResult(CommonCode.FAIL);
    }
 
    @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 = deviceInfoService.assignRemoveUser(nodeType, paramId, relativeFlag, userIds);
        if(b) {
            return new ResponseResult(CommonCode.SUCCESS);
        }
        return new ResponseResult(CommonCode.FAIL);
    }
 
    @AutoLog(value = "设备表-全部设备列表")
    @ApiOperation(value = "设备表-全部设备列表", notes = "设备表-全部设备列表")
    @GetMapping("/list/all")
    public QueryListResponseResult<DeviceInfo> findListAll() {
        List<DeviceInfo> list = deviceInfoService.list();
        if(list == null)
            list = Collections.emptyList();
        return new QueryListResponseResult(CommonCode.SUCCESS, list);
    }
 
    @AutoLog(value = "设备表-指派到设备 设备树")
    @ApiOperation(value = "设备表-指派到设备 设备树", notes = "设备表-指派到设备 设备树")
    @GetMapping("/load/depart/tree/{nodeType}/{paramId}")
    public QueryListResponseResult<CommonGenericTree> loadDepartTree(@PathVariable("nodeType") Integer nodeType,@PathVariable("paramId") String paramId) {
        List<CommonGenericTree> list = deviceInfoService.loadDepartTree(nodeType, paramId);
        if(list == null)
            list = Collections.emptyList();
        return new QueryListResponseResult(CommonCode.SUCCESS, list);
    }
 
    @AutoLog(value = "设备表-获取唯一 设备编号")
    @ApiOperation(value = "设备表-获取唯一 设备编号", notes = "设备表-获取唯一 设备编号")
    @GetMapping("/valid/device")
    public ResponseResult validateDeviceNo(String deviceNo) {
        DeviceInfo byDeviceNo = deviceInfoService.getByDeviceNo(deviceNo);
        if(byDeviceNo == null) {
            return new ResponseResult(DeviceCode.DEVICE_NOT_EXIST);
        }
        return new ResponseResult(CommonCode.SUCCESS);
    }
 
    /**
     * 加载产线设备树
     */
    @AutoLog(value = "设备表-加载产线设备树")
    @ApiOperation(value = "设备表-加载产线设备树", notes = "设备表-加载产线设备树")
    @GetMapping(value = "/queryTreeListByProduction")
    public Result<List<MdcEquipmentTree>> queryTreeListByProduction() {
        Result<List<MdcEquipmentTree>> result = new Result<>();
        try {
            List<MdcEquipmentTree> mdcEquipmentTreeList = devicePermissionService.DncLoadTreeListByProduction();
            result.setSuccess(true);
            result.setResult(mdcEquipmentTreeList);
        } catch (Exception e) {
            return Result.error("加载产线设备树失败!" + e.getMessage());
        }
        return result;
    }
}