diff --git a/casic-server/src/main/java/com/casic/missiles/modular/neutron/service/impl/PsdServiceImpl.java b/casic-server/src/main/java/com/casic/missiles/modular/neutron/service/impl/PsdServiceImpl.java index 251ac1e..16a463e 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/neutron/service/impl/PsdServiceImpl.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/neutron/service/impl/PsdServiceImpl.java @@ -3,7 +3,9 @@ import cn.hutool.core.date.DateUnit; import cn.hutool.core.date.DateUtil; import cn.hutool.core.util.ObjectUtil; +import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.casic.missiles.common.WebSocket; import com.casic.missiles.core.application.service.AbstractDictService; import com.casic.missiles.core.cache.CacheUtil; import com.casic.missiles.modular.constants.RobotDictConstants; @@ -49,7 +51,12 @@ private IAlarmRecordService iAlarmRecordService; @Autowired private IRobotCacheService iRobotCacheService; - + @Autowired + private WebSocket webSocket; + //记录推送次数 + private static volatile long times = 0; + //记录报警是否推送 + private static volatile boolean flag = true; @Override public List dataList(Long taskId) { @@ -125,7 +132,7 @@ @Override public void insertPsdAlarms() { - + times++; //先查询正在巡检任务信息 List taskInfoList = iTaskInfoService.getTaskListByStatus(0, 1, 1); List alarmRecordList = new ArrayList<>(); @@ -147,8 +154,8 @@ } } } + double psdVal = count * 1.000 / 5; if (count > 0) { - double psdVal = count * 1.000 / 5; if (psdVal >= 13) { AlarmRecord alarmRecord = new AlarmRecord(robotId, new BigDecimal(psdVal), @@ -167,10 +174,37 @@ alarmRecord.setYGrid(new BigDecimal(pointNextDTo.getY())); } alarmRecordList.add(alarmRecord); + if (flag) { + //推送报警信息 + JSONObject headerJson = new JSONObject(); + headerJson.put("msgKey", "alarm"); + JSONObject jsonObject = new JSONObject(); + jsonObject.put("robotId", robotId); + jsonObject.put("taskType", ObjectUtil.isNotEmpty(taskInfo.getTaskType()) ? dictService.getDictNameByCode("taskType", taskInfo.getTaskType() + "") : ""); + jsonObject.put("discernType", ObjectUtil.isNotEmpty(taskInfo.getDiscernType()) ? dictService.getDictNameByCode("discernType", taskInfo.getDiscernType() + "") : ""); + jsonObject.put("taskId", taskInfo.getId()); + jsonObject.put("psd", 13); + jsonObject.put("x", alarmRecord.getXGrid()); + jsonObject.put("y", alarmRecord.getYGrid()); + jsonObject.put("alarmTime", new Date()); + headerJson.put("data", jsonObject); + webSocket.sendAllMessage(headerJson.toJSONString()); + flag = false; + } } //写入缓存 CacheUtil.put(RobotDictConstants.CACHE_SCHEMA, RobotDictConstants.KEY_PSD_DATA_ID + robotId, psdVal); } + //每隔5秒实时推送psd数据 + JSONObject headerJson = new JSONObject(); + headerJson.put("msgKey", "psd"); + JSONObject jsonObject = new JSONObject(); + jsonObject.put("robotId", robotId); + jsonObject.put("taskId", taskInfo.getId()); + jsonObject.put("psd", psdVal); + jsonObject.put("time", times * 5); + headerJson.put("data", jsonObject); + webSocket.sendAllMessage(headerJson.toJSONString()); } if (null != alarmRecordList && alarmRecordList.size() > 0) { iAlarmRecordService.saveBatch(alarmRecordList); diff --git a/casic-server/src/main/java/com/casic/missiles/modular/neutron/service/impl/PsdServiceImpl.java b/casic-server/src/main/java/com/casic/missiles/modular/neutron/service/impl/PsdServiceImpl.java index 251ac1e..16a463e 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/neutron/service/impl/PsdServiceImpl.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/neutron/service/impl/PsdServiceImpl.java @@ -3,7 +3,9 @@ import cn.hutool.core.date.DateUnit; import cn.hutool.core.date.DateUtil; import cn.hutool.core.util.ObjectUtil; +import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.casic.missiles.common.WebSocket; import com.casic.missiles.core.application.service.AbstractDictService; import com.casic.missiles.core.cache.CacheUtil; import com.casic.missiles.modular.constants.RobotDictConstants; @@ -49,7 +51,12 @@ private IAlarmRecordService iAlarmRecordService; @Autowired private IRobotCacheService iRobotCacheService; - + @Autowired + private WebSocket webSocket; + //记录推送次数 + private static volatile long times = 0; + //记录报警是否推送 + private static volatile boolean flag = true; @Override public List dataList(Long taskId) { @@ -125,7 +132,7 @@ @Override public void insertPsdAlarms() { - + times++; //先查询正在巡检任务信息 List taskInfoList = iTaskInfoService.getTaskListByStatus(0, 1, 1); List alarmRecordList = new ArrayList<>(); @@ -147,8 +154,8 @@ } } } + double psdVal = count * 1.000 / 5; if (count > 0) { - double psdVal = count * 1.000 / 5; if (psdVal >= 13) { AlarmRecord alarmRecord = new AlarmRecord(robotId, new BigDecimal(psdVal), @@ -167,10 +174,37 @@ alarmRecord.setYGrid(new BigDecimal(pointNextDTo.getY())); } alarmRecordList.add(alarmRecord); + if (flag) { + //推送报警信息 + JSONObject headerJson = new JSONObject(); + headerJson.put("msgKey", "alarm"); + JSONObject jsonObject = new JSONObject(); + jsonObject.put("robotId", robotId); + jsonObject.put("taskType", ObjectUtil.isNotEmpty(taskInfo.getTaskType()) ? dictService.getDictNameByCode("taskType", taskInfo.getTaskType() + "") : ""); + jsonObject.put("discernType", ObjectUtil.isNotEmpty(taskInfo.getDiscernType()) ? dictService.getDictNameByCode("discernType", taskInfo.getDiscernType() + "") : ""); + jsonObject.put("taskId", taskInfo.getId()); + jsonObject.put("psd", 13); + jsonObject.put("x", alarmRecord.getXGrid()); + jsonObject.put("y", alarmRecord.getYGrid()); + jsonObject.put("alarmTime", new Date()); + headerJson.put("data", jsonObject); + webSocket.sendAllMessage(headerJson.toJSONString()); + flag = false; + } } //写入缓存 CacheUtil.put(RobotDictConstants.CACHE_SCHEMA, RobotDictConstants.KEY_PSD_DATA_ID + robotId, psdVal); } + //每隔5秒实时推送psd数据 + JSONObject headerJson = new JSONObject(); + headerJson.put("msgKey", "psd"); + JSONObject jsonObject = new JSONObject(); + jsonObject.put("robotId", robotId); + jsonObject.put("taskId", taskInfo.getId()); + jsonObject.put("psd", psdVal); + jsonObject.put("time", times * 5); + headerJson.put("data", jsonObject); + webSocket.sendAllMessage(headerJson.toJSONString()); } if (null != alarmRecordList && alarmRecordList.size() > 0) { iAlarmRecordService.saveBatch(alarmRecordList); diff --git a/casic-server/src/main/java/com/casic/missiles/modular/robot/vo/DetectorInfoVO.java b/casic-server/src/main/java/com/casic/missiles/modular/robot/vo/DetectorInfoVO.java index 7e394c1..dc6683f 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/robot/vo/DetectorInfoVO.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/robot/vo/DetectorInfoVO.java @@ -17,21 +17,25 @@ public class DetectorInfoVO { private static final long serialVersionUID = 1L; - /** 机器人ID */ - @ApiModelProperty(value = "机器人ID" , dataType = "Long") - private Long robotId; - /** 探测器名称 */ - @ApiModelProperty(value = "探测器名称" , dataType = "String") - private String detectorName; + /** + * 机器人ID + */ + @ApiModelProperty(value = "机器人ID", dataType = "Long") + private Long robotId; + /** + * 探测器名称 + */ + @ApiModelProperty(value = "探测器名称", dataType = "String") + private String detectorName; public QueryWrapper genQuery() { QueryWrapper query = new QueryWrapper<>(); -if (robotId!=null) { - query.eq("robot_id",robotId); -} -if (StrUtil.isNotEmpty(detectorName)) { - query.like("detector_name",detectorName); -} + if (robotId != null) { + query.eq("robot_id", robotId); + } + if (StrUtil.isNotEmpty(detectorName)) { + query.like("detector_name", detectorName); + } return query; } }