郑永安
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
package com.gk.hotwork.Controller;
 
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.gk.hotwork.Controller.Base.BaseController;
import com.gk.hotwork.Domain.*;
import com.gk.hotwork.Domain.Enum.ErrorCode;
import com.gk.hotwork.Domain.Utils.BeanUtils;
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.Domain.Vo.EquipmentVo;
import com.gk.hotwork.Domain.Vo.TaskCheck;
import com.gk.hotwork.Service.*;
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.validation.BindingResult;
import org.springframework.validation.FieldError;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
 
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.stream.Collectors;
 
@Api(tags = "作业设备数据接口")
@RestController
public class TaskEquipmentController extends BaseController {
    @Autowired
    TaskEquipmentBindService taskEquipmentBindService;
    @Autowired
    TaskGasService taskGasService;
    @Autowired
    TaskLocationService taskLocationService;
    @Autowired
    EquipmentService equipmentService;
    @Autowired
    GasWarnService gasWarnService;
    @Autowired
    VideoService videoService;
    @Autowired
    TaskService taskService;
 
    @PostMapping("/addTaskEquipment")
    @ApiOperation(value = "添加作业设备数据",response = Msg.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "taskcode",value = "作业编号"),
            @ApiImplicitParam(name = "equipmentnumber",value = "设备条码"),
    })
    public Msg addTaskEquipment(@Validated @RequestBody TaskEquipmentBindInfo taskEquipmentBindInfo, BindingResult bindingResult){
        Msg msg = new Msg();
        msg.setCode("200");
        msg.setMessage("success");
 
        if (bindingResult.hasErrors()) {
            StringBuilder stringBuilder = new StringBuilder();
            for (String s : bindingResult.getFieldErrors().stream()
                    .map(FieldError::getDefaultMessage).collect(Collectors.toList())) {
                stringBuilder.append(s).append(",");
            }
            return new Msg(ErrorCode.ERROR_10002,stringBuilder.toString());
        }
 
        EquipmentInfo equipmentInfo = equipmentService.selectByNumber(taskEquipmentBindInfo.getEquipmentnumber());
        if (equipmentInfo == null){
            msg.setCode(ErrorCode.ERROR_10004.getCode());
            msg.setMessage("未找到该条码对应的设备");
            return msg;
        }else {
            taskEquipmentBindInfo.setEquipmentname(equipmentInfo.getName());
        }
 
        taskEquipmentBindInfo.setUpdateby(getUser().getRealname());
        taskEquipmentBindInfo.setUpdatetime(new Date());
        taskEquipmentBindService.save(taskEquipmentBindInfo);
        return msg;
    }
 
    @PostMapping("/addTaskGas")
    @ApiOperation(value = "添加作业气体数据",response = Msg.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "taskcode",value = "作业编号"),
            @ApiImplicitParam(name = "gastype",value = "气体类型"),
            @ApiImplicitParam(name = "gasvalue",value = "气体浓度值"),
            @ApiImplicitParam(name = "gasunit",value = "气体单位"),
    })
    public Msg addTaskGas(@Validated @RequestBody List<TaskGasInfo> taskGasInfoList, BindingResult bindingResult){
        Msg msg = new Msg();
        msg.setCode("200");
        msg.setMessage("success");
        if (bindingResult.hasErrors()) {
            StringBuilder stringBuilder = new StringBuilder();
            for (String s : bindingResult.getFieldErrors().stream()
                    .map(FieldError::getDefaultMessage).collect(Collectors.toList())) {
                stringBuilder.append(s).append(",");
            }
            return new Msg(ErrorCode.ERROR_10002,stringBuilder.toString());
        }
        for (TaskGasInfo taskGasInfo : taskGasInfoList){
            TaskInfo taskInfo = taskService.getTaskByCode(taskGasInfo.getTaskcode());
            if (!taskInfo.getFlag().equals(TaskInfo.DOING)){
                return success();
            }
            taskGasInfo.setIswarn((byte)0);
            taskGasInfo.setIsyujing((byte)0);
            GasWarnInfo gasWarnInfo = gasWarnService.selectByType(taskGasInfo.getGastype(),"报警");
            if (gasWarnInfo != null){
                if (taskGasInfo.getGasvalue().compareTo(gasWarnInfo.getMax()) > 0
                || taskGasInfo.getGasvalue().compareTo(gasWarnInfo.getMin()) < 0){
                    taskGasInfo.setIswarn((byte)1);
                }
            }
 
            GasWarnInfo gasWarnInfo1 = gasWarnService.selectByType(taskGasInfo.getGastype(),"预警");
            if (gasWarnInfo1 != null){
                if (taskGasInfo.getGasvalue().compareTo(gasWarnInfo1.getMax()) > 0
                        || taskGasInfo.getGasvalue().compareTo(gasWarnInfo1.getMin()) < 0){
                    taskGasInfo.setIsyujing((byte)1);
                }
            }
            taskGasInfo.setIssms((byte)0);
            taskGasInfo.setIsmend((byte)0);
            taskGasInfo.setTaskworker(getUser().getRealname());
            taskGasInfo.setUpdatetime(new Date());
            taskGasService.save(taskGasInfo);
        }
        return msg;
    }
 
    @PostMapping("/addTaskLocation")
    @ApiOperation(value = "添加作业人员位置数据",response = Msg.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "taskcode",value = "作业编号"),
            @ApiImplicitParam(name = "gastype",value = "气体类型"),
            @ApiImplicitParam(name = "gasvalue",value = "气体浓度值"),
            @ApiImplicitParam(name = "gasunit",value = "气体单位"),
    })
    public Msg addTaskLocation(@Validated @RequestBody TaskLocationInfo taskLocationInfo, BindingResult bindingResult){
        Msg msg = new Msg();
        msg.setCode("200");
        msg.setMessage("success");
        if (bindingResult.hasErrors()) {
            StringBuilder stringBuilder = new StringBuilder();
            for (String s : bindingResult.getFieldErrors().stream()
                    .map(FieldError::getDefaultMessage).collect(Collectors.toList())) {
                stringBuilder.append(s).append(",");
            }
            return new Msg(ErrorCode.ERROR_10002,stringBuilder.toString());
        }
        TaskInfo taskInfo = taskService.getTaskByCode(taskLocationInfo.getTaskcode());
        if (!taskInfo.getFlag().equals(TaskInfo.DOING)){
            return success();
        }
 
        taskLocationInfo.setTaskworker(getUser().getRealname());
        taskLocationInfo.setUpdatetime(new Date());
        taskLocationService.save(taskLocationInfo);
        return msg;
    }
 
    @GetMapping("/getTaskGas")
    @ApiOperation(value = "获取作业气体浓度",response = Msg.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageIndex",value = "当前页码"),
            @ApiImplicitParam(name = "pageSize",value = "每页行数"),
            @ApiImplicitParam(name = "sort",value = "排序规则"),
            @ApiImplicitParam(name = "order",value = "排序字段"),
            @ApiImplicitParam(name = "taskcode",value = "作业编号"),
            @ApiImplicitParam(name = "gastype",value = "气体类型")
    })
    public Msg getTaskGas(@RequestParam(defaultValue = "0") Integer pageIndex, @RequestParam(defaultValue = "10") Integer pageSize, String sort, String order,
                          String taskcode, String gastype){
        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(taskcode)) {
            condition.put("taskcode", taskcode.trim());
        }
 
        pageInfo.setCondition(condition);
        taskGasService.selectDataGrid(pageInfo);
        msg.setResult(pageInfo);
        return msg;
    }
 
    @GetMapping("/getTaskVideo")
    @ApiOperation(value = "获取视频token",response = Msg.class)
    public Msg getTaskVideo(){
        Msg msg = new Msg();
        msg.setCode("200");
        msg.setMessage("success");
        VideoInfo videoInfo = videoService.getById(1);
        msg.setResult(videoInfo.getToken());
        return msg;
    }
 
    @GetMapping("getEquipment")
    @ApiOperation(value = "根据Number获取设备信息",response = Msg.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "number",value = "设备编号"),
    })
    public Msg getEquipmentByNumber(@RequestParam("number") String number){
        if (StringUtils.isBlank(number)){
            return new Msg(ErrorCode.ERROR_10001);
        }
        EquipmentInfo equipmentInfo = equipmentService.selectByNumber(number);
        return success(equipmentInfo);
    }
 
    @PostMapping("getEquipments")
    @ApiOperation(value = "根据Number获取设备信息",response = Msg.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "number",value = "设备编号"),
    })
    public Msg getEquipmentsByNumbers(@RequestBody JSONObject jsonObject){
        JSONArray array = jsonObject.getJSONArray("numbers");
        if (array == null || array.size() < 1){
            return new Msg(ErrorCode.ERROR_10001);
        }
        List<EquipmentInfo> equipmentInfos = new ArrayList<>();
        for (int i = 0; i < array.size(); i++){
            String number = array.getString(i);
            if (StringUtils.isBlank(number)){
                return new Msg(ErrorCode.ERROR_10001);
            }
            EquipmentInfo equipmentInfo = equipmentService.selectByNumber(number);
            equipmentInfos.add(equipmentInfo);
        }
        return success(equipmentInfos);
    }
 
    @GetMapping("/lastGas")
    public Msg getLastGas(@RequestParam("taskCode") String taskCode,
                          @RequestParam("worker") String worker){
        if (StringUtils.isBlank(taskCode)){
            return new Msg(ErrorCode.ERROR_10001);
        }
        List<TaskGasInfo> taskGasInfos = taskGasService.selectLastGas(taskCode,worker);
        return success(taskGasInfos);
    }
}