Browse Source

websocket推送待处理数量

develop
lau572 6 months ago
parent
commit
7f8015910c
  1. 14
      ruoyi-common/src/main/java/com/zc/common/core/websocket/constant/WebSocketEvent.java
  2. 8
      zc-business/src/main/java/com/zc/business/controller/DcEventController.java
  3. 18
      zc-business/src/main/java/com/zc/business/message/device/handler/DeviceMessageHandler.java
  4. 4
      zc-business/src/main/java/com/zc/business/service/IDcEventService.java
  5. 38
      zc-business/src/main/java/com/zc/business/service/impl/DcEventServiceImpl.java
  6. 22
      zc-business/src/main/java/com/zc/business/service/impl/DcWarningServiceImpl.java

14
ruoyi-common/src/main/java/com/zc/common/core/websocket/constant/WebSocketEvent.java

@ -3,4 +3,18 @@ package com.zc.common.core.websocket.constant;
public class WebSocketEvent { public class WebSocketEvent {
public static final String REACTIVE = "reactive"; public static final String REACTIVE = "reactive";
//感知事件
public static final String WARNING = "1";
//交通事件
public static final String EVENT = "0";
//感知事件+待确认数量统计
public static final String EVENT_COUNT = "eventCount";
//设备状态
public static final String DEVICE_STATE = "deviceState";
} }

8
zc-business/src/main/java/com/zc/business/controller/DcEventController.java

@ -233,12 +233,12 @@ public class DcEventController extends BaseController
* *
* @author liuwenge * @author liuwenge
* @date 2024/6/6 18:45 * @date 2024/6/6 18:45
* @param type * @param
* @return com.ruoyi.common.core.domain.AjaxResult * @return com.ruoyi.common.core.domain.AjaxResult
*/ */
@ApiOperation("获取事件数量") @ApiOperation("获取事件数量")
@GetMapping( "/getCountNum/{type}") @GetMapping( "/getCountNum")
public AjaxResult getCountNum(@ApiParam(name = "type", value = "类型 1:告警 2:待确认 3:处置中", required = true) @PathVariable("type") String type){ public Long getCountNum(){
return dcEventService.getCountNum(type); return dcEventService.getCountNum();
} }
} }

18
zc-business/src/main/java/com/zc/business/message/device/handler/DeviceMessageHandler.java

@ -17,6 +17,7 @@ import com.zc.business.enums.WarningStateEnum;
import com.zc.business.enums.WarningSubclassEnum; import com.zc.business.enums.WarningSubclassEnum;
import com.zc.business.service.*; import com.zc.business.service.*;
import com.zc.common.core.websocket.WebSocketService; import com.zc.common.core.websocket.WebSocketService;
import com.zc.common.core.websocket.constant.WebSocketEvent;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -50,6 +51,9 @@ public class DeviceMessageHandler {
@Resource @Resource
private IDcWarningService dcWarningService; private IDcWarningService dcWarningService;
@Resource
private IDcEventService dcEventService;
@Resource @Resource
private IMiddleDatabaseService middleDatabaseService; private IMiddleDatabaseService middleDatabaseService;
@ -88,7 +92,7 @@ public class DeviceMessageHandler {
} }
}); });
WebSocketService.broadcast(DEVICE_STATE, dcDevices); //推送设备状态更新 WebSocketService.broadcast(WebSocketEvent.DEVICE_STATE, dcDevices); //推送设备状态更新
// 批量更新中间库设备状态 // 批量更新中间库设备状态
middleDatabaseService.updateMiddleDatabaseDeviceByList(dcDevices); middleDatabaseService.updateMiddleDatabaseDeviceByList(dcDevices);
} }
@ -593,7 +597,7 @@ public class DeviceMessageHandler {
//todo 首页推送事件消息 3气象检测器 //todo 首页推送事件消息 3气象检测器
if (!meteorologicalDetectorData.getPrecipitationType().equals("0")) {//降水类型 0=无降;1=雨;2=雪;3=毛毛雨;4=雨夹雪; if (!meteorologicalDetectorData.getPrecipitationType().equals("0")) {//降水类型 0=无降;1=雨;2=雪;3=毛毛雨;4=雨夹雪;
WebSocketService.broadcast("3", meteorologicalDetectorData); WebSocketService.broadcast(WebSocketEvent.WARNING, meteorologicalDetectorData);
JSONObject object = new JSONObject(); JSONObject object = new JSONObject();
object.put("meteorologicalDetectorData", meteorologicalDetectorData); object.put("meteorologicalDetectorData", meteorologicalDetectorData);
String string = object.toString(); String string = object.toString();
@ -604,9 +608,13 @@ public class DeviceMessageHandler {
dcWarning.setOtherConfig(string); dcWarning.setOtherConfig(string);
dcWarning.setWarningTitle("气象预警"); dcWarning.setWarningTitle("气象预警");
dcWarningService.insertDcWarning(dcWarning); dcWarningService.insertDcWarning(dcWarning);
//待确认数量
Long count = dcEventService.getCountNum();
WebSocketService.broadcast(WebSocketEvent.EVENT_COUNT, count);
} }
if (!meteorologicalDetectorData.getVisibilityType().equals("4")) {// 能见度类型,4 表示能见度良好3表示阴霾 2表示雾 1表示浓雾; if (!meteorologicalDetectorData.getVisibilityType().equals("4")) {// 能见度类型,4 表示能见度良好3表示阴霾 2表示雾 1表示浓雾;
WebSocketService.broadcast("3", meteorologicalDetectorData); WebSocketService.broadcast(WebSocketEvent.WARNING, meteorologicalDetectorData);
JSONObject object = new JSONObject(); JSONObject object = new JSONObject();
object.put("meteorologicalDetectorData", meteorologicalDetectorData); object.put("meteorologicalDetectorData", meteorologicalDetectorData);
String string = object.toString(); String string = object.toString();
@ -617,6 +625,10 @@ public class DeviceMessageHandler {
dcWarning.setWarningTitle("气象预警"); dcWarning.setWarningTitle("气象预警");
dcWarningService.insertDcWarning(dcWarning); dcWarningService.insertDcWarning(dcWarning);
//待确认数量
Long count = dcEventService.getCountNum();
WebSocketService.broadcast(WebSocketEvent.EVENT_COUNT, count);
} }

4
zc-business/src/main/java/com/zc/business/service/IDcEventService.java

@ -145,8 +145,8 @@ public interface IDcEventService
* *
* @author liuwenge * @author liuwenge
* @date 2024/6/6 18:45 * @date 2024/6/6 18:45
* @param type 类型 1:告警 2:待确认 3:处置中 * @param
* @return com.ruoyi.common.core.domain.AjaxResult * @return com.ruoyi.common.core.domain.AjaxResult
*/ */
AjaxResult getCountNum(String type); Long getCountNum();
} }

38
zc-business/src/main/java/com/zc/business/service/impl/DcEventServiceImpl.java

@ -21,6 +21,7 @@ import com.zc.business.utils.StakeMarkUtils;
import com.zc.business.utils.diff.Diff; import com.zc.business.utils.diff.Diff;
import com.zc.business.utils.diff.model.Result; import com.zc.business.utils.diff.model.Result;
import com.zc.common.core.websocket.WebSocketService; import com.zc.common.core.websocket.WebSocketService;
import com.zc.common.core.websocket.constant.WebSocketEvent;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
@ -573,7 +574,12 @@ public class DcEventServiceImpl extends ServiceImpl<DcEventMapper, DcEvent> impl
Map<String, Object> contentMap = new HashMap<>(); Map<String, Object> contentMap = new HashMap<>();
contentMap.put("content", content); contentMap.put("content", content);
contentMap.put("event", dcEvent); contentMap.put("event", dcEvent);
WebSocketService.broadcast(SUBEVENT, contentMap); //推送事件消息 0不是感知事件
WebSocketService.broadcast(WebSocketEvent.EVENT, contentMap); //推送事件消息 0不是感知事件
Long count = getCountNum();
WebSocketService.broadcast(WebSocketEvent.EVENT_COUNT, count);
} }
//根据路网设施查询桩号 //根据路网设施查询桩号
@ -1051,6 +1057,9 @@ public class DcEventServiceImpl extends ServiceImpl<DcEventMapper, DcEvent> impl
break; break;
} }
} }
//推送待处理数量
Long count = getCountNum();
WebSocketService.broadcast(WebSocketEvent.EVENT_COUNT,count);
return i7; return i7;
} }
@ -1223,6 +1232,11 @@ public class DcEventServiceImpl extends ServiceImpl<DcEventMapper, DcEvent> impl
int i = dcEventMapper.updateDcEventState(id, state); int i = dcEventMapper.updateDcEventState(id, state);
if (i > 0) { if (i > 0) {
//推送待处理数量
Long count = getCountNum();
WebSocketService.broadcast(WebSocketEvent.EVENT_COUNT,count);
DcEvent dcEvent = dcEventMapper.selectDcEventMainById(id); DcEvent dcEvent = dcEventMapper.selectDcEventMainById(id);
//中间库 //中间库
@ -1929,26 +1943,18 @@ public class DcEventServiceImpl extends ServiceImpl<DcEventMapper, DcEvent> impl
* *
* @author liuwenge * @author liuwenge
* @date 2024/6/6 18:45 * @date 2024/6/6 18:45
* @param type 类型 1:告警 2:待确认 3:处置中 * @param
* @return com.ruoyi.common.core.domain.AjaxResult * @return com.ruoyi.common.core.domain.AjaxResult
*/ */
@Override @Override
public AjaxResult getCountNum(String type){ public Long getCountNum(){
if (StringUtils.isEmpty(type)){
return AjaxResult.error("类型不能为空"); Long warningCount = dcWarningMapper.selectWarningNum();
}
Long eventCount = dcEventMapper.selectEventNumByStatus("0");
Long num = 0L;
//告警
if (type.equals("1")){
num = dcWarningMapper.selectWarningNum();
} else if (type.equals("2")){
num = dcEventMapper.selectEventNumByStatus("0");
} else if (type.equals("3")){
num = dcEventMapper.selectEventNumByStatus("1");
}
return AjaxResult.success(num); return warningCount + eventCount;
} }

22
zc-business/src/main/java/com/zc/business/service/impl/DcWarningServiceImpl.java

@ -18,6 +18,7 @@ import com.zc.business.service.IDcTrafficPoliceService;
import com.zc.business.service.IDcWarningService; import com.zc.business.service.IDcWarningService;
import com.zc.business.utils.StakeMarkUtils; import com.zc.business.utils.StakeMarkUtils;
import com.zc.common.core.websocket.WebSocketService; import com.zc.common.core.websocket.WebSocketService;
import com.zc.common.core.websocket.constant.WebSocketEvent;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONObject; import org.json.JSONObject;
@ -167,9 +168,12 @@ public class DcWarningServiceImpl implements IDcWarningService
redisCache.deleteObject(WARNINGDATA+key); redisCache.deleteObject(WARNINGDATA+key);
String id = dcWarning.getId(); String id = dcWarning.getId();
redisCache.setCacheObject(WARNINGDATA+key,id,Integer.parseInt(strategyTime),TimeUnit.MINUTES); redisCache.setCacheObject(WARNINGDATA+key,id,Integer.parseInt(strategyTime),TimeUnit.MINUTES);
int i = dcWarningMapper.insertDcWarning(dcWarning);
//事件推送至 Websocket //事件推送至 Websocket
extracted(dcWarning); extracted(dcWarning);
return dcWarningMapper.insertDcWarning(dcWarning);
return i;
} }
String otherConfig=""; String otherConfig="";
if (map.get("otherConfig")!=null){ if (map.get("otherConfig")!=null){
@ -201,8 +205,9 @@ public class DcWarningServiceImpl implements IDcWarningService
dcWarning.setEndTime(DateUtils.getObtainDateAfter(60));//注入过期时间(默认值为60分钟) dcWarning.setEndTime(DateUtils.getObtainDateAfter(60));//注入过期时间(默认值为60分钟)
} }
//事件推送至 Websocket //事件推送至 Websocket
int i = dcWarningMapper.insertDcWarning(dcWarning);//如果没有配置策略直接加入数据库;
extracted(dcWarning); extracted(dcWarning);
return dcWarningMapper.insertDcWarning(dcWarning);//如果没有配置策略直接加入数据库; return i;
} }
/** /**
@ -227,7 +232,9 @@ public class DcWarningServiceImpl implements IDcWarningService
Map<String,Object> contentMap = new HashMap<>(); Map<String,Object> contentMap = new HashMap<>();
contentMap.put("content",content); contentMap.put("content",content);
contentMap.put("event",dcWarning); contentMap.put("event",dcWarning);
WebSocketService.broadcast(SUBEVENT, contentMap); //推送事件消息 0不是感知事件 WebSocketService.broadcast(WebSocketEvent.WARNING, contentMap); //推送事件消息 0不是感知事件
Long count = dcEventService.getCountNum();
WebSocketService.broadcast(WebSocketEvent.EVENT_COUNT, count); //推送待处理数量
} }
//优先级策略(还差优先级策略需要配置) //优先级策略(还差优先级策略需要配置)
@ -516,6 +523,9 @@ public class DcWarningServiceImpl implements IDcWarningService
if (insertDcEvent==0){ if (insertDcEvent==0){
return AjaxResult.error("操作失败"); return AjaxResult.error("操作失败");
} }
//推送待处理数量
Long count = dcEventService.getCountNum();
WebSocketService.broadcast(WebSocketEvent.EVENT_COUNT,count);
return AjaxResult.success("操作成功"); return AjaxResult.success("操作成功");
} }
@ -924,7 +934,11 @@ public class DcWarningServiceImpl implements IDcWarningService
@Override @Override
public Integer falseAlarmResolution(DcWarning dcWarning) { public Integer falseAlarmResolution(DcWarning dcWarning) {
dcWarning.setUpdateTime(DateUtils.getNowDate()); dcWarning.setUpdateTime(DateUtils.getNowDate());
return dcWarningMapper.falseAlarmResolution(dcWarning); Integer i = dcWarningMapper.falseAlarmResolution(dcWarning);
//推送待处理数量
Long count = dcEventService.getCountNum();
WebSocketService.broadcast(WebSocketEvent.EVENT_COUNT,count);
return i;
} }
} }

Loading…
Cancel
Save