From 9c254c1cb5c853f02d2413e44fd8d6f809d2182f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?LAPTOP-S9HJSOEB=5C=E6=98=8A=E5=A4=A9?= Date: Fri, 1 Dec 2023 11:06:06 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8A=A5=E8=AD=A6=EF=BC=8C=E5=B7=A1=E6=A3=80?= =?UTF-8?q?=E7=9B=B8=E5=85=B3=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../web/controller/DeviceController.java | 33 ++++++++++--- .../java/com/leaper/web/entity/DeviceReq.java | 19 ++++++++ .../main/java/com/leaper/web/entity/Warn.java | 1 + .../com/leaper/web/service/PlcService.java | 47 +++++++++++++++++++ 4 files changed, 94 insertions(+), 6 deletions(-) create mode 100644 web/src/main/java/com/leaper/web/entity/DeviceReq.java diff --git a/web/src/main/java/com/leaper/web/controller/DeviceController.java b/web/src/main/java/com/leaper/web/controller/DeviceController.java index 80285bf..4e031f9 100644 --- a/web/src/main/java/com/leaper/web/controller/DeviceController.java +++ b/web/src/main/java/com/leaper/web/controller/DeviceController.java @@ -3,23 +3,28 @@ package com.leaper.web.controller; import com.github.pagehelper.PageInfo; import com.leaper.common.util.ValidatorUtil; import com.leaper.web.entity.CheckLog; +import com.leaper.web.entity.DeviceReq; import com.leaper.web.pojo.stock.CheckLogSearch; import com.leaper.web.service.CheckLogService; +import com.leaper.web.service.PlcService; import com.zhehekeji.core.pojo.Result; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; +import lombok.extern.slf4j.Slf4j; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import javax.annotation.Resource; +import java.util.List; +import java.util.Map; - -@Api(tags = "盘点历史") +@Api(tags = "设备相关") @RequestMapping("/device") @RestController +@Slf4j public class DeviceController { @@ -28,11 +33,27 @@ public class DeviceController { @Resource private ValidatorUtil validatorUtil; - @ApiOperation("盘点历史") - @PostMapping("") - public Result> list(@RequestBody CheckLogSearch checkLogSearch){ - return Result.success(checkLogService.list(checkLogSearch)); + @Resource + PlcService plcService; + + @ApiOperation("设备报警") + @PostMapping("warn") + public Result>> warn(@RequestBody DeviceReq deviceReq) { + log.info("{}设备报警", deviceReq.getDeviceCode()); + + plcService.warnStart(deviceReq); + Map> map = + + return Result.success(checkLogService.list()); } + @ApiOperation("设备报警") + @PostMapping("巡检") + public Result>> inspection(@RequestBody DeviceReq deviceReq) { + + + return Result.success(checkLogService.list()); + } + } diff --git a/web/src/main/java/com/leaper/web/entity/DeviceReq.java b/web/src/main/java/com/leaper/web/entity/DeviceReq.java new file mode 100644 index 0000000..03119b3 --- /dev/null +++ b/web/src/main/java/com/leaper/web/entity/DeviceReq.java @@ -0,0 +1,19 @@ +package com.leaper.web.entity; + +import lombok.Data; + +import java.util.List; + +@Data +public class DeviceReq { + String deviceCode ; + String warmName ; + List cameraList ; + @Data + public static class CameraList { + String cameraCode ; + String cameraName ; + String cameraId ; + String warnCode ; + } +} diff --git a/web/src/main/java/com/leaper/web/entity/Warn.java b/web/src/main/java/com/leaper/web/entity/Warn.java index eaf3450..59edac4 100644 --- a/web/src/main/java/com/leaper/web/entity/Warn.java +++ b/web/src/main/java/com/leaper/web/entity/Warn.java @@ -17,6 +17,7 @@ public class Warn { @TableId(type = IdType.AUTO) private Long id; + private Integer deviceCode; private Integer streetId; @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss") diff --git a/web/src/main/java/com/leaper/web/service/PlcService.java b/web/src/main/java/com/leaper/web/service/PlcService.java index 9674cd5..f5a65a8 100644 --- a/web/src/main/java/com/leaper/web/service/PlcService.java +++ b/web/src/main/java/com/leaper/web/service/PlcService.java @@ -516,6 +516,53 @@ public class PlcService { } } + + /** + * 收到告警异常信号 + * 1.判断是否有正在进行订单,有的话,不做处理 + * 2.没有订单,新增告警记录 + * + * @param deviceReq + */ + public void warn(DeviceReq deviceReq) { + Warn warn = new Warn(); + warn.setStartTime(LocalDateTime.now()); + warn.setStreetId(street.getId()); + String orderNum = OrderRealtime.getOrderByStreetId(street.getId()); + if (StringUtils.isEmpty(orderNum)) { + log.debug("{}:warn start...., but no order running", plcId); + } else { + //不为空的话,填写工单的位置 + Order order = orderMapper.getOneByOrderNum(orderNum); + if (order != null) { + //stop the order + log.debug("plcId:{},warn start and stop the order",plcId); + orderStopByWarn(orderNum); + OrderVO orderVO = new OrderVO(); + BeanUtils.copyProperties(order, orderVO); + String location = orderService.location(orderVO, street); + warn.setLocation(location); + warn.setOrderId(order.getId()); + } + } + //没有正在执行的工单 不需要填写location + warn.setSignal(signal); + warnMapper.insert(warn); + OrderRealtime.startWarn(street.getId(), warn.getId()); + Street street = streetService.getStreetByPlcId(plcId); + if (street == null) { + return; + } + synchronized (plcId.intern()) { + //新增 告警 + if (OrderRealtime.getWarnId(street.getId()) != null) { + log.debug("{}:exist warn", plcId); + return; + } + //不存在正在执行的告警记录,就新增 + + } + } /** * 告警结束信号 * 是否存在订单,存在-》保存该订单的视频