郑永安
2023-09-19 69185134fcfaf913ea45f1255677225a2cc311a4
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
package com.gk.hotwork.Controller;
 
import com.alibaba.fastjson.JSONObject;
import com.gk.hotwork.Controller.Base.BaseController;
import com.gk.hotwork.Domain.Enum.ErrorCode;
import com.gk.hotwork.Domain.EquipmentInfo;
import com.gk.hotwork.Domain.GasWarnInfo;
import com.gk.hotwork.Domain.Utils.Msg;
import com.gk.hotwork.Domain.Utils.PageInfo;
import com.gk.hotwork.Domain.Utils.StringUtils;
import com.gk.hotwork.Service.EquipmentService;
import com.gk.hotwork.Service.GasWarnService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
 
import java.util.Date;
import java.util.HashMap;
 
@Api(tags = "设备数据接口")
@RestController
public class EquipmentController extends BaseController {
    @Autowired
    EquipmentService equipmentService;
    @Autowired
    GasWarnService gasWarnService;
 
    @GetMapping("/gasWarn")
    @ApiOperation(value = "获取气体阈值信息",response = Msg.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageIndex",value = "当前页码"),
            @ApiImplicitParam(name = "pageSize",value = "每页行数"),
            @ApiImplicitParam(name = "sort",value = "排序规则"),
            @ApiImplicitParam(name = "order",value = "排序字段"),
            @ApiImplicitParam(name = "gastype",value = "气体类型"),
            @ApiImplicitParam(name = "warntype",value = "报警类型")
    })
    public Msg getGasWarn(@RequestParam(defaultValue = "0") Integer pageIndex, @RequestParam(defaultValue = "10") Integer pageSize, String sort, String order,
                                 String gastype, String warntype){
        Msg msg = new Msg();
        msg.setCode("200");
        msg.setMessage("success");
 
        PageInfo pageInfo = new PageInfo(pageIndex, pageSize,sort,order);
        HashMap<String, Object> condition = new HashMap<String, Object>();
 
        if (StringUtils.isNotBlank(gastype)) {
            condition.put("gastype", gastype.trim());
        }
 
        if (StringUtils.isNotBlank(warntype)) {
            condition.put("warntype", warntype.trim());
        }
 
        pageInfo.setCondition(condition);
        gasWarnService.selectDataGrid(pageInfo);
        msg.setResult(pageInfo);
        return msg;
    }
 
    @PostMapping("/addGasWarn")
    @ApiOperation(value = "添加气体阈值信息",response = Msg.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "gastype",value = "气体类型"),
            @ApiImplicitParam(name = "warntype",value = "报警类型"),
            @ApiImplicitParam(name = "max",value = "最大值"),
            @ApiImplicitParam(name = "min",value = "最小值"),
            @ApiImplicitParam(name = "gasunit",value = "气体单位"),
    })
    public Msg addGasWarn(@RequestBody GasWarnInfo gasWarnInfo){
        Msg msg = new Msg();
        msg.setCode("200");
        msg.setMessage("success");
        if (StringUtils.isBlank(gasWarnInfo.getGastype())||StringUtils.isBlank(gasWarnInfo.getWarntype())){
            msg.setCode(ErrorCode.ERROR_10004.getCode());
            msg.setMessage("气体类型、报警类型不能为空");
            return msg;
        }
        GasWarnInfo gasWarnInfoExist = gasWarnService.selectExistByType(null,gasWarnInfo.getWarntype(),gasWarnInfo.getGastype());
        if (gasWarnInfoExist != null){
            msg.setCode(ErrorCode.ERROR_10004.getCode());
            msg.setMessage("存在相同气体类型、报警类型的配置");
            return msg;
        }
        gasWarnInfo.setUpdateby(getUser().getRealname());
        gasWarnInfo.setUpdatetime(new Date());
        gasWarnService.save(gasWarnInfo);
        return msg;
    }
 
    @PostMapping("/putGasWarn")
    @ApiOperation(value = "修改气体阈值信息",response = Msg.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "gastype",value = "气体类型"),
            @ApiImplicitParam(name = "warntype",value = "报警类型"),
            @ApiImplicitParam(name = "max",value = "最大值"),
            @ApiImplicitParam(name = "min",value = "最小值"),
            @ApiImplicitParam(name = "gasunit",value = "气体单位"),
    })
    public Msg putGasWarn(@RequestBody GasWarnInfo gasWarnInfo){
        Msg msg = new Msg();
        msg.setCode("200");
        msg.setMessage("success");
        if (StringUtils.isBlank(gasWarnInfo.getGastype())||StringUtils.isBlank(gasWarnInfo.getWarntype())){
            msg.setCode(ErrorCode.ERROR_10004.getCode());
            msg.setMessage("气体类型、报警类型不能为空");
            return msg;
        }
        GasWarnInfo gasWarnInfoExist = gasWarnService.selectExistByType(gasWarnInfo.getId(),gasWarnInfo.getWarntype(),gasWarnInfo.getGastype());
        if (gasWarnInfoExist != null){
            msg.setCode(ErrorCode.ERROR_10004.getCode());
            msg.setMessage("存在相同气体类型、报警类型的配置");
            return msg;
        }
        gasWarnInfo.setUpdateby(getUser().getRealname());
        gasWarnInfo.setUpdatetime(new Date());
        gasWarnService.updateById(gasWarnInfo);
        return msg;
    }
 
    @PostMapping("/delGasWarn")
    @ApiOperation(value = "删除气体阈值信息",response = Msg.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "id"),
    })
    public Msg delGasWarn(@RequestBody JSONObject jsonObject){
        Msg msg = new Msg();
        msg.setCode("200");
        msg.setMessage("success");
        Long id = jsonObject.getLong("id");
 
        if (id == null){
            msg.setCode(ErrorCode.ERROR_10004.getCode());
            msg.setMessage("id不能为空");
            return msg;
        }
        gasWarnService.removeById(id);
        return msg;
    }
 
    @GetMapping("/equipment")
    @ApiOperation(value = "获取设备信息",response = Msg.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageIndex",value = "当前页码"),
            @ApiImplicitParam(name = "pageSize",value = "每页行数"),
            @ApiImplicitParam(name = "sort",value = "排序规则"),
            @ApiImplicitParam(name = "order",value = "排序字段"),
            @ApiImplicitParam(name = "name",value = "设备名称"),
            @ApiImplicitParam(name = "number",value = "设备条码")
    })
    public Msg equipmentService(@RequestParam(defaultValue = "0") Integer pageIndex, @RequestParam(defaultValue = "10") Integer pageSize, String sort, String order,
                                 String name, String number){
        Msg msg = new Msg();
        msg.setCode("200");
        msg.setMessage("success");
 
        PageInfo pageInfo = new PageInfo(pageIndex, pageSize,sort,order);
        HashMap<String, Object> condition = new HashMap<String, Object>();
 
        if (StringUtils.isNotBlank(name)) {
            condition.put("name", name.trim());
        }
 
        if (StringUtils.isNotBlank(number)) {
            condition.put("number", number.trim());
        }
 
        pageInfo.setCondition(condition);
        equipmentService.selectDataGrid(pageInfo);
        msg.setResult(pageInfo);
        return msg;
    }
 
    @PostMapping("/addEquipment")
    @ApiOperation(value = "添加设备信息",response = Msg.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name",value = "设备名称"),
            @ApiImplicitParam(name = "number",value = "设备条码"),
            @ApiImplicitParam(name = "isphoto",value = "是否有摄像头 1是 0否"),
            @ApiImplicitParam(name = "photoname",value = "摄像头名称"),
            @ApiImplicitParam(name = "photoaddress",value = "摄像头地址"),
    })
    public Msg addEquipment(@RequestBody EquipmentInfo equipmentInfo){
        Msg msg = new Msg();
        msg.setCode("200");
        msg.setMessage("success");
        if (StringUtils.isBlank(equipmentInfo.getName())||StringUtils.isBlank(equipmentInfo.getNumber())){
            msg.setCode(ErrorCode.ERROR_10004.getCode());
            msg.setMessage("设备名称、设备条码不能为空");
            return msg;
        }
        EquipmentInfo equipmentInfoExist = equipmentService.selectExistByNumber(null,equipmentInfo.getNumber());
        if (equipmentInfoExist != null){
            msg.setCode(ErrorCode.ERROR_10004.getCode());
            msg.setMessage("存在相同设备条码");
            return msg;
        }
        if (equipmentInfo.getIsphoto() == 1 && (StringUtils.isBlank(equipmentInfo.getPhotoname())
        || StringUtils.isBlank(equipmentInfo.getPhotoaddress()))){
            msg.setCode(ErrorCode.ERROR_10004.getCode());
            msg.setMessage("摄像头名称、地址不能为空");
            return msg;
        }
        equipmentInfo.setUpdateby(getUser().getRealname());
        equipmentInfo.setUpdatetime(new Date());
        equipmentService.save(equipmentInfo);
        return msg;
    }
 
    @PostMapping("/putEquipment")
    @ApiOperation(value = "修改设备信息",response = Msg.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "id"),
            @ApiImplicitParam(name = "name",value = "设备名称"),
            @ApiImplicitParam(name = "number",value = "设备条码"),
            @ApiImplicitParam(name = "isphoto",value = "是否有摄像头 1是 0否"),
            @ApiImplicitParam(name = "photoname",value = "摄像头名称"),
            @ApiImplicitParam(name = "photoaddress",value = "摄像头地址"),
    })
    public Msg putEquipment(@RequestBody EquipmentInfo equipmentInfo){
        Msg msg = new Msg();
        msg.setCode("200");
        msg.setMessage("success");
        if (StringUtils.isBlank(equipmentInfo.getName())||StringUtils.isBlank(equipmentInfo.getNumber())){
            msg.setCode(ErrorCode.ERROR_10004.getCode());
            msg.setMessage("设备名称、设备条码不能为空");
            return msg;
        }
        EquipmentInfo equipmentInfoExist = equipmentService.selectExistByNumber(equipmentInfo.getId(),equipmentInfo.getNumber());
        if (equipmentInfoExist != null){
            msg.setCode(ErrorCode.ERROR_10004.getCode());
            msg.setMessage("存在相同设备条码");
            return msg;
        }
        if (equipmentInfo.getIsphoto() == 1 && (StringUtils.isBlank(equipmentInfo.getPhotoname())
                || StringUtils.isBlank(equipmentInfo.getPhotoaddress()))){
            msg.setCode(ErrorCode.ERROR_10004.getCode());
            msg.setMessage("摄像头名称、地址不能为空");
            return msg;
        }
        equipmentInfo.setUpdateby(getUser().getRealname());
        equipmentInfo.setUpdatetime(new Date());
        equipmentService.updateById(equipmentInfo);
        return msg;
    }
 
    @PostMapping("/delEquipment")
    @ApiOperation(value = "删除设备信息",response = Msg.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "id"),
    })
    public Msg delEquipment(@RequestBody JSONObject jsonObject){
        Msg msg = new Msg();
        msg.setCode("200");
        msg.setMessage("success");
        Long id = jsonObject.getLong("id");
 
        if (id == null){
            msg.setCode(ErrorCode.ERROR_10004.getCode());
            msg.setMessage("id不能为空");
            return msg;
        }
        equipmentService.removeById(id);
        return msg;
    }
 
}