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);
|
}
|
}
|