cjl
2023-10-13 100690a225167806a08f64eafff3326564a7154a
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
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
package com.moral.api.controller;
 
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
 
import java.util.List;
import java.util.Map;
 
import javax.servlet.http.HttpServletRequest;
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.moral.api.entity.Device;
 
import com.moral.api.entity.SpecialDevice;
import com.moral.api.entity.Version;
import com.moral.api.service.DeviceService;
import com.moral.api.service.SpecialDeviceService;
import com.moral.api.service.VersionService;
import com.moral.constant.Constants;
import com.moral.constant.ResponseCodeEnum;
import com.moral.constant.ResultMessage;
import com.moral.util.WebUtils;
 
@Slf4j
@Api(tags = {"设备管理"})
@RestController
@RequestMapping(value = "/device")
public class DeviceController {
 
    @Autowired
    private DeviceService deviceService;
 
    @Autowired
    private VersionService versionService;
 
    @Autowired
    private SpecialDeviceService specialDeviceService;
 
    @ApiOperation(value = "添加设备", notes = "添加设备")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "token", required = true, paramType = "header", dataType = "String")
    })
    @RequestMapping(value = "insert", method = RequestMethod.POST)
    public ResultMessage insert(@RequestBody Device device) {
        String name = device.getName();
        String mac = device.getMac();
        Integer monitorPointId = device.getMonitorPointId();
        Integer versionId = device.getDeviceVersionId();
        if (ObjectUtils.isEmpty(name) || ObjectUtils.isEmpty(mac) || ObjectUtils.isEmpty(monitorPointId) || ObjectUtils.isEmpty(versionId)) {
            return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(),
                    ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg());
        }
        //判断mac是否已存在,普通设备表和特殊设备表都要判断
        QueryWrapper<Device> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("mac", device.getMac()).eq("is_delete", Constants.NOT_DELETE);
 
        QueryWrapper<SpecialDevice> specialDeviceQueryWrapper = new QueryWrapper<>();
        specialDeviceQueryWrapper.eq("mac", device.getMac()).eq("is_delete", Constants.NOT_DELETE);
 
        if (deviceService.getOne(queryWrapper) != null || specialDeviceService.getOne(specialDeviceQueryWrapper) != null) {
            return ResultMessage.fail(ResponseCodeEnum.MAC_IS_EXIST.getCode(), ResponseCodeEnum.MAC_IS_EXIST.getMsg());
        }
        deviceService.insert(device);
        return ResultMessage.ok();
    }
 
    @ApiOperation(value = "删除设备", notes = "删除设备")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "token", required = true, paramType = "header", dataType = "String")
    })
    @RequestMapping(value = "delete", method = RequestMethod.GET)
    public ResultMessage delete(Integer deviceId) {
        if (deviceId == null) {
            return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(),
                    ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg());
        }
        deviceService.delete(deviceId);
        return ResultMessage.ok();
    }
 
    @ApiOperation(value = "修改设备", notes = "修改设备")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "token", required = true, paramType = "header", dataType = "String")
    })
    @RequestMapping(value = "update", method = RequestMethod.POST)
    public ResultMessage update(@RequestBody Device device) {
        if (device.getId() == null) {
            return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(),
                    ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg());
        }
        if (device.getMac() != null) {
            //判断mac是否已存在,普通设备表和特殊设备表都要判断
            QueryWrapper<Device> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("mac", device.getMac()).eq("is_delete", Constants.NOT_DELETE);
 
            QueryWrapper<SpecialDevice> specialDeviceQueryWrapper = new QueryWrapper<>();
            specialDeviceQueryWrapper.eq("mac", device.getMac()).eq("is_delete", Constants.NOT_DELETE);
            if (deviceService.getOne(queryWrapper) != null || specialDeviceService.getOne(specialDeviceQueryWrapper) != null) {
                return ResultMessage.fail(ResponseCodeEnum.MAC_IS_EXIST.getCode(), ResponseCodeEnum.MAC_IS_EXIST.getMsg());
            }
        }
        deviceService.update(device);
        return ResultMessage.ok();
    }
 
    @ApiOperation(value = "分页设备列表", notes = "分页设备列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "当前页", required = false, paramType = "query", dataType = "int"),
            @ApiImplicitParam(name = "size", value = "每页条数", required = false, paramType = "query", dataType = "int"),
            @ApiImplicitParam(name = "order", value = "排序字段", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "orderType", value = "排序类型,升序:0,降序:1", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "token", value = "token", required = true, paramType = "header", dataType = "String"),
            @ApiImplicitParam(name = "name", value = "设备名称模糊查询", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "mac", value = "mac模糊查询", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "organizationId", value = "根据组织查询", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "monitorPointId", value = "站点id", required = false, paramType = "query", dataType = "String")
 
    })
    @RequestMapping(value = "select", method = RequestMethod.GET)
    public ResultMessage select(HttpServletRequest request) {
        Map<String, Object> parameters = WebUtils.getParametersStartingWith(request, null);
        Map<String, Object> result = deviceService.selectDevices(parameters);
        return ResultMessage.ok(result);
    }
 
    @ApiOperation(value = "所有组织", notes = "所有组织")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "token", required = true, paramType = "header", dataType = "String")
    })
    @RequestMapping(value = "allOrganization", method = RequestMethod.GET)
    public ResultMessage selectAllOrganization() {
        List<Map<String, Object>> organizations = deviceService.selectAllOrganization();
        return ResultMessage.ok(organizations);
    }
 
    @ApiOperation(value = "所有站点", notes = "所有站点")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "token", required = true, paramType = "header", dataType = "String")
    })
    @RequestMapping(value = "allMonitorPoint", method = RequestMethod.GET)
    public ResultMessage selectAllMonitorPoint() {
        List<Map<String, Object>> organizations = deviceService.selectAllMonitorPoint();
        return ResultMessage.ok(organizations);
    }
 
    @ApiOperation(value = "根据组织查站点", notes = "根据组织查站点")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "token", required = true, paramType = "header", dataType = "String")
    })
    @RequestMapping(value = "monitorPoints", method = RequestMethod.GET)
    public ResultMessage selectMonitorPoints(Integer orgId) {
        List<Map<String, Object>> monitorPoints = deviceService.selectMonitorsByOrgId(orgId);
        return ResultMessage.ok(monitorPoints);
    }
 
    @ApiOperation(value = "根据组织查设备", notes = "根据组织查设备")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "当前页", required = false, paramType = "query", dataType = "int"),
            @ApiImplicitParam(name = "size", value = "每页条数", required = false, paramType = "query", dataType = "int"),
            @ApiImplicitParam(name = "order", value = "排序字段", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "orderType", value = "排序类型,升序:0,降序:1", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "token", value = "token", required = true, paramType = "header", dataType = "String"),
            @ApiImplicitParam(name = "organizationId", value = "组织id", required = false, paramType = "query", dataType = "int"),
    })
    @RequestMapping(value = "devicesByOrgId", method = RequestMethod.GET)
    public ResultMessage selectDevicesByOrg(HttpServletRequest request) {
        Map<String, Object> parameters = WebUtils.getParametersStartingWith(request, null);
        if (parameters.get("organizationId") == null) {
            return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(),
                    ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg());
        }
        Map<String, Object> devices = deviceService.selectDevicesByOrgId(parameters);
        return ResultMessage.ok(devices);
    }
 
    @ApiOperation(value = "根据站点查设备", notes = "根据站点查设备")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "当前页", required = false, paramType = "query", dataType = "int"),
            @ApiImplicitParam(name = "size", value = "每页条数", required = false, paramType = "query", dataType = "int"),
            @ApiImplicitParam(name = "order", value = "排序字段", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "orderType", value = "排序类型,升序:0,降序:1", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "token", value = "token", required = true, paramType = "header", dataType = "String"),
            @ApiImplicitParam(name = "monitorPointId", value = "站点id", required = false, paramType = "query", dataType = "int"),
    })
    @RequestMapping(value = "devicesByMpId", method = RequestMethod.GET)
    public ResultMessage selectDevicesByMp(HttpServletRequest request) {
        Map<String, Object> parameters = WebUtils.getParametersStartingWith(request, null);
        if (parameters.get("monitorPointId") == null) {
            return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(),
                    ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg());
        }
        Map<String, Object> devices = deviceService.selectDevicesByMpId(parameters);
        return ResultMessage.ok(devices);
    }
 
    @ApiOperation(value = "型号列表", notes = "型号列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "token", required = true, paramType = "header", dataType = "String")
    })
    @RequestMapping(value = "versions", method = RequestMethod.GET)
    public ResultMessage selectVersions() {
        QueryWrapper<Version> queryWrapper = new QueryWrapper<>();
        queryWrapper.select("id", "name").eq("is_delete", Constants.NOT_DELETE);
        List<Map<String, Object>> maps = versionService.listMaps(queryWrapper);
        return ResultMessage.ok(maps);
    }
 
    @ApiOperation(value = "维护人列表", notes = "维护人列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "token", required = true, paramType = "header", dataType = "String")
    })
    @RequestMapping(value = "operators", method = RequestMethod.GET)
    public ResultMessage selectOperators() {
        return ResultMessage.ok(deviceService.selectAllOperators());
    }
 
    @ApiOperation(value = "所有行业", notes = "所有行业")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "token", required = true, paramType = "header", dataType = "String")
    })
    @RequestMapping(value = "professions", method = RequestMethod.GET)
    public ResultMessage selectProfessions() {
        List<Map<String, Object>> professions = deviceService.selectDeviceDictData(Constants.SYSTEM_DICT_TYPE_PROFESSION);
        return ResultMessage.ok(professions);
    }
 
    @ApiOperation(value = "所有工艺", notes = "所有工艺")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "token", required = true, paramType = "header", dataType = "String")
    })
    @RequestMapping(value = "techs", method = RequestMethod.GET)
    public ResultMessage selectTechs() {
        List<Map<String, Object>> professions = deviceService.selectDeviceDictData(Constants.SYSTEM_DICT_TYPE_TECH);
        return ResultMessage.ok(professions);
    }
 
    @ApiOperation(value = "所有设备检测器", notes = "所有设备检测器")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "token", required = true, paramType = "header", dataType = "String")
    })
    @RequestMapping(value = "detectors", method = RequestMethod.GET)
    public ResultMessage selectDetectors() {
        List<Map<String, Object>> professions = deviceService.selectDeviceDictData(Constants.SYSTEM_DICT_TYPE_DETECTOR);
        return ResultMessage.ok(professions);
    }
 
    @ApiOperation(value = "所有采购商", notes = "所有采购商")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "token", required = true, paramType = "header", dataType = "String")
    })
    @RequestMapping(value = "purchasers", method = RequestMethod.GET)
    public ResultMessage selectPurchasers() {
        List<Map<String, Object>> professions = deviceService.selectDeviceDictData(Constants.SYSTEM_DICT_TYPE_PURCHASER);
        return ResultMessage.ok(professions);
    }
 
    @RequestMapping(value = "selectMonitorPiontAndDeviceByOrgId", method = RequestMethod.GET)
    public ResultMessage selectMonitorPiontAndDeviceByOrgId(HttpServletRequest request){
        Map parames = WebUtils.getParametersStartingWith(request,null);
        int id = Integer.parseInt(parames.get("organization_id").toString());
        List<Map<String, Object>> maps = deviceService.selectMonitorPiontAndDeviceByOrgId(id);
        return ResultMessage.ok(maps);
    }
}