ruoyi-service/ruoyi-dataInterchange/src/main/java/com/ruoyi/dataInterchange/dao/UPWarnMsgAdptInfoDao.java
@@ -38,6 +38,6 @@ * @param infoId * @return */ UPWarnMsgAdptInfo findByInfoIdIs(Integer infoId); UPWarnMsgAdptInfo findByInfoIdIs(String infoId); } ruoyi-service/ruoyi-dataInterchange/src/main/java/com/ruoyi/dataInterchange/model/UPWarnMsgAdptInfo.java
@@ -1,6 +1,5 @@ package com.ruoyi.dataInterchange.model; import cn.hutool.core.util.ArrayUtil; import com.ruoyi.dataInterchange.pojo.BaseModel; import com.ruoyi.dataInterchange.util.jtt809.common.ByteArrayUtil; import com.ruoyi.dataInterchange.util.jtt809.common.Jtt809Util; @@ -10,9 +9,6 @@ import org.springframework.data.elasticsearch.annotations.Document; import org.springframework.data.elasticsearch.annotations.Field; import org.springframework.data.elasticsearch.annotations.FieldType; import java.util.Arrays; import java.util.List; /** * 上报报警信息 @@ -97,7 +93,7 @@ @Field(type = FieldType.Text) private String driverNo; /** * 报警级别 * 报警级别 0x001:一级报警,0x002: 二级报警 */ @Field(type = FieldType.Integer) private int level; @@ -162,6 +158,11 @@ */ @Field(type = FieldType.Long) private long pushTime; /** * 抓拍图片 */ @Field(type = FieldType.Text) private String picUrl; /** ruoyi-service/ruoyi-dataInterchange/src/main/java/com/ruoyi/dataInterchange/server/WarnMsgService.java
@@ -1,12 +1,17 @@ package com.ruoyi.dataInterchange.server; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson2.JSONObject; import com.ruoyi.dataInterchange.dao.UPExgMsgRealLocationDao; import com.ruoyi.dataInterchange.dao.UPWarnMsgAdptInfoDao; import com.ruoyi.dataInterchange.dao.UPWarnMsgUrgeTodoAckDao; import com.ruoyi.dataInterchange.model.*; import com.ruoyi.dataInterchange.model.enu.DataType; import com.ruoyi.dataInterchange.netty.client.ChannelMap; import com.ruoyi.dataInterchange.util.haikang.model.Alarm; import com.ruoyi.dataInterchange.util.haikang.model.AlarmPic; import com.ruoyi.dataInterchange.util.haikang.model.Event; import com.ruoyi.dataInterchange.util.haikang.model.SubscriptionEvent; import com.ruoyi.dataInterchange.util.jtt809.common.Jtt809Util; import com.ruoyi.dataInterchange.util.jtt809.packet.common.OuterPacket; import io.netty.buffer.ByteBuf; @@ -16,10 +21,12 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Component; import org.springframework.util.StringUtils; import javax.annotation.Resource; import java.time.LocalDateTime; import java.time.ZoneOffset; import java.time.format.DateTimeFormatter; import java.util.Arrays; import java.util.List; @@ -45,7 +52,8 @@ @Resource private UPExgMsgRealLocationDao upExgMsgRealLocationDao; //走川标的公司 private List<Integer> enterprise = Arrays.asList(17458936, 43984060, 13914394); public void up_warn_msg(ChannelHandlerContext ctx, OuterPacket out) { if (!redisTemplate.hasKey("login:" + out.getGnsscenterId())) { @@ -68,7 +76,6 @@ break; } } /** * 解析子业务数据 @@ -98,8 +105,7 @@ warnMsg.setData(data); return warnMsg; } /** * 报警督办应答消息 * @@ -114,13 +120,6 @@ upWarnMsgUrgeTodoAckDao.save(upWarnMsgUrgeTodoAck); } //走川标的公司 private List<Integer> enterprise = Arrays.asList(17458936, 43984060, 13914394); /** * 上报报警信息 * @@ -182,4 +181,229 @@ upWarnMsgAdptInfo.setPushTime(LocalDateTime.now().plusDays(7).toEpochSecond(ZoneOffset.ofHours(8))); upWarnMsgAdptInfoDao.save(upWarnMsgAdptInfo); } /** * 存储mqtt协议报警信息 */ public void saveWarnMsgService(JSONObject jsonObject) { SubscriptionEvent subscriptionEvent = jsonObject.getObject("", SubscriptionEvent.class); List<Event> events = subscriptionEvent.getEvents(); events.forEach(event -> { //车牌号 String srcName = event.getSrcName(); Alarm data = JSONObject.parseObject(event.getData(), Alarm.class); UPWarnMsgAdptInfo upWarnMsgAdptInfo = upWarnMsgAdptInfoDao.findByInfoIdIs(data.getAlarmId()); if(null == upWarnMsgAdptInfo){ upWarnMsgAdptInfo = new UPWarnMsgAdptInfo(); } upWarnMsgAdptInfo.setVehicleNo(srcName); upWarnMsgAdptInfo.setVehicleColor(data.getVehicleLicenseColor()); upWarnMsgAdptInfo.setWarnSrc(data.getSourceType() + 1); upWarnMsgAdptInfo.setWarnType(getAlarmType(data.getEventType())); upWarnMsgAdptInfo.setWarnTime(LocalDateTime.parse(data.getAlarmTime(), DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")).toEpochSecond(ZoneOffset.ofHours(8))); upWarnMsgAdptInfo.setInfoId(data.getAlarmId()); upWarnMsgAdptInfo.setLevel(getLevel(data.getLevel())); upWarnMsgAdptInfo.setLongitude(data.getLongitude().intValue()); upWarnMsgAdptInfo.setLatitude(data.getLatitude().intValue()); upWarnMsgAdptInfo.setAltitude(data.getHeight().intValue() / 10); upWarnMsgAdptInfo.setSpeed(data.getSpeed().intValue() / 10000); upWarnMsgAdptInfo.setVec2(data.getSpeed().intValue()); upWarnMsgAdptInfo.setStatus(data.getStatus()); upWarnMsgAdptInfo.setDirection(data.getDirection() / 100); upWarnMsgAdptInfo.setInfoContent(data.getAlarmInfo()); upWarnMsgAdptInfoDao.save(upWarnMsgAdptInfo); }); } public int getAlarmType(long eventType){ switch ((int) eventType){ case 0x00020501: return 0x0301; case 0x00020502: return 0x0201; case 0x00020503: return 0x0202; case 0x00020504: return 0x0202; case 0x00020505: return 0x0202; case 0x00020506: return 0x0202; case 0x00020507: return 0x0203; case 0x00020508: return 0x0203; case 0x00020509: return 0x0204; case 0x00020510: return 0x0204; case 0x00037017: return 0x00FF; case 0x00020511: return 0x00FF; case 0x00037005: return 0x00FF; case 0x00020512: return 0x0002; case 0x00020513: return 0x0002; case 0x00020514: return 0x00FF; case 0x00020515: return 0x00FF; case 0x00020516: return 0x0214; case 0x00020517: return 0x0213; case 0x00020519: return 0x0215; case 0x00020520: return 0x0234; case 0x00020521: return 0x0234; case 0x00020522: return 0x0234; case 0x00020523: return 0x0241; case 0x00020524: return 0x0242; case 0x00020525: return 0x0243; case 0x00020526: return 0x0243; case 0x00020531: return 0x00FF; case 0x00020532: return 0x00FF; case 0x00020533: return 0x00FF; case 0x00020534: return 0x0218; case 0x00020518: return 0xA0FF; case 0x00037001: return 0xA0FF; case 0x00037002: return 0x0216; case 0x00037006: return 0x0216; case 0x00020535: return 0x0001; case 0x00020536: return 0x0001; case 0x00020537: return 0x000D; case 0x00020102: return 0x0102; case 0x00020538: return 0x0005; case 0x00020539: return 0x0004; case 0x00020540: return 0x0304; case 0x00020541: return 0x0304; case 0x00020542: return 0x000B; case 0x00020543: return 0x0001; case 0x00020544: return 0x0001; case 0x00020545: return 0xA001; case 0x00020546: return 0x0305; case 0x00020547: return 0x0305; case 0x00020548: return 0xA0FF; case 0x00010202: return 0x0103; case 0x00010206: return 0x0103; case 0x00020101: return 0x0101; case 0x00020103: return 0x000C; case 0x00020549: return 0xA00A; case 0x00020550: return 0xA00A; case 0x00020551: return 0xA00A; case 0x00020552: return 0x0308; case 0x00020553: return 0x0308; case 0x00020554: return 0x0308; case 0x00020555: return 0x0308; case 0x00020556: return 0x0308; case 0x00020557: return 0x0308; case 0x00020558: return 0x0308; case 0x00020559: return 0x0003; case 0x00020527: return 0x0301; case 0x00020528: return 0x0201; case 0x00020529: return 0x0302; case 0x00020530: return 0x0302; case 0x00020560: return 0x0009; case 0x00020561: return 0x0306; case 0x00020562: return 0x0307; case 0x00090001: return 0x00FF; default: return 0x00FF; } } public int getLevel(String level){ switch (level){ case "h": case "m": return 1; case "l": case "w": return 2; default: return 0; } } /** * 存储mqtt协议报警图片信息 */ public void saveWarnMsgPicService(JSONObject jsonObject) { SubscriptionEvent subscriptionEvent = jsonObject.getObject("", SubscriptionEvent.class); List<Event> events = subscriptionEvent.getEvents(); events.forEach(event -> { AlarmPic data = JSONObject.parseObject(event.getData(), AlarmPic.class); if(StringUtils.hasLength(data.getAlarmId())){ UPWarnMsgAdptInfo upWarnMsgAdptInfo = upWarnMsgAdptInfoDao.findByInfoIdIs(data.getAlarmId()); if(null != upWarnMsgAdptInfo){ upWarnMsgAdptInfo.setPicUrl(data.getUrl()); upWarnMsgAdptInfoDao.save(upWarnMsgAdptInfo); }else{ upWarnMsgAdptInfo = new UPWarnMsgAdptInfo(); upWarnMsgAdptInfo.setInfoId(data.getAlarmId()); upWarnMsgAdptInfoDao.save(upWarnMsgAdptInfo); } } }); } } ruoyi-service/ruoyi-dataInterchange/src/main/java/com/ruoyi/dataInterchange/util/haikang/model/Alarm.java
New file @@ -0,0 +1,97 @@ package com.ruoyi.dataInterchange.util.haikang.model; import lombok.Data; /** * @author zhibing.pu * @Date 2025/5/23 18:26 */ @Data public class Alarm { /** * 告警id */ private String alarmId; /** * 告警详情 */ private String alarmInfo; /** * 告警时间 */ private String alarmTime; /** * 设备序列号 */ private String deviceIndexCode; /** * 方向 */ private Integer direction; /** * 驾驶员序列号 */ private String driverIndexCode; /** * 驾驶员资格证号 */ private String driverNo; /** * 事件id */ private String eventId; /** * 事件类型 */ private Long eventType; /** * 海拔 */ private Long height; /** * 纬度 */ private Long latitude; /** * 告警级别 */ private String level; /** * 经度 */ private Long longitude; /** * 图片数量 * 报警事件报文中picNum>0时,传入报警事件报文中的alarmId和alarmTime调用#API@根据报警ID获取关联图片信息@#接口查询报警关联图片 */ private Integer picNum; /** * 源类型 0-设备,1-平台,2-人工 */ private Integer sourceType; /** * 速度 */ private Long speed; /** * 状态 */ private Integer status; /** * 车辆编号 */ private String vehicleIndexCode; /** * 车牌/名称 */ private String vehicleLicensePlate; /** * 车牌颜色 */ private Integer vehicleLicenseColor; /** * 视频数量 * 报警事件报文中videoNum>0时,传入报警事件报文中的alarmId和alarmTime调用#API@根据报警ID获取关联短视频信息@#接口查询报警关联短视频 */ private Integer videoNum; } ruoyi-service/ruoyi-dataInterchange/src/main/java/com/ruoyi/dataInterchange/util/haikang/model/AlarmPic.java
New file @@ -0,0 +1,99 @@ package com.ruoyi.dataInterchange.util.haikang.model; import lombok.Data; /** * @author zhibing.pu * @Date 2025/5/23 18:26 */ @Data public class AlarmPic { /** * 车辆编号 */ private String vehicleIndexCode; /** * 设备编号 */ private String deviceIndexCode; /** * 监控点编号 */ private String cameraIndexCode; /** * 存储服务编号 */ private String serviceIndexCode; /** * 缩略图地址ID */ private String thumbUrl; /** * 图片地址 */ private String url; /** * 抓拍时间 */ private String captureTime; /** * 通道号 */ private String channelNum; /** * 图片上传时间 */ private String uploadTime; /** * 经度 */ private Integer longitude; /** * 纬度 */ private Integer latitude; /** * 速度 */ private Integer speed; /** * 方向角 */ private Integer direction; /** * 上传类型 0:定时抓 * 拍,1:手动抓拍,2:报 * 警抓拍,5:人脸(检 * 测)考勤图片,8:事件 * 图片 */ private Integer uploadType; /** * 报警标识 */ private String alarmId; /** * 事件类型 */ private Long alarmType; /** * 设备上报URL */ private String uploadUrl; /** * 设备上报图片ID */ private String originPicId; /** * 本图片锁关联的抓拍图片的唯一标识 */ private String parentPicId; /** * 人脸小图在关联的抓拍图片上的坐标 */ private String faceRect; /** * 1:可见光,2:热成像 */ private Integer picType; } ruoyi-service/ruoyi-dataInterchange/src/main/java/com/ruoyi/dataInterchange/util/haikang/model/Event.java
New file @@ -0,0 +1,56 @@ package com.ruoyi.dataInterchange.util.haikang.model; import lombok.Data; /** * @author zhibing.pu * @Date 2025/5/23 18:24 */ @Data public class Event { /** * 事件Id,标识事件的一次发生,同一 * 事件发送多次需要ID相同 */ private String eventId; /** * 事件源编号,物理设备是资源编号 */ private String srcIndex; /** * 事件源类型 */ private String srcType; /** * 事件源名称,utf8 */ private String srcName; /** * 事件类型 */ private String eventType; /** * 事件状态, 0-瞬时 1-开始 2-停止 3-事件脉冲 4-事件联动结果更新 */ private Integer status; /** * 事件等级:0-未配置, 非0-配置登记的事件,注意,此处事件等级是指在事件联动中配置的等级 */ private Integer eventLvl; /** * 脉冲超时时间,一个持续性的事件,上报的间隔 */ private Integer timeout; /** * 事件发生时间 */ private String happenTime; /** * 事件发生的事件源父设备,无-空字符串 */ private String srcParentIdex; /** * 事件其它扩展信息 */ private String data; } ruoyi-service/ruoyi-dataInterchange/src/main/java/com/ruoyi/dataInterchange/util/haikang/model/SubscriptionEvent.java
@@ -2,6 +2,8 @@ import lombok.Data; import java.util.List; /** * 订阅事件统一格式 * @author zhibing.pu @@ -9,14 +11,6 @@ */ @Data public class SubscriptionEvent { /** * 方法名 */ private String method; /** * 事件参数信息 */ private String params; /** * 事件从接收者发出的时间 */ @@ -28,50 +22,5 @@ /** * 事件信息 */ private String events; /** * 事件Id,标识事件的一次发生,同一 * 事件发送多次需要ID相同 */ private String eventId; /** * 事件源编号,物理设备是资源编号 */ private String srcIndex; /** * 事件源类型 */ private String srcType; /** * 事件源名称,utf8 */ private String srcName; /** * 事件类型 */ private String eventType; /** * 事件状态, 0-瞬时 1-开始 2-停止 3-事件脉冲 4-事件联动结果更新 */ private Integer status; /** * 事件等级:0-未配置, 非0-配置登记的事件,注意,此处事件等级是指在事件联动中配置的等级 */ private Integer eventLvl; /** * 脉冲超时时间,一个持续性的事件,上报的间隔 */ private Integer timeout; /** * 事件发生时间 */ private String happenTime; /** * 事件发生的事件源父设备,无-空字符串 */ private String srcParentIdex; /** * 事件其它扩展信息 */ private String data; private List<Event> events; } ruoyi-service/ruoyi-dataInterchange/src/main/java/com/ruoyi/dataInterchange/util/mqtt/MqttReceiverMessageHandler.java
@@ -1,11 +1,15 @@ package com.ruoyi.dataInterchange.util.mqtt; import com.alibaba.fastjson2.JSONObject; import com.ruoyi.dataInterchange.server.WarnMsgService; import lombok.extern.slf4j.Slf4j; import org.springframework.messaging.Message; import org.springframework.messaging.MessageHandler; import org.springframework.messaging.MessageHeaders; import org.springframework.messaging.MessagingException; import org.springframework.stereotype.Component; import javax.annotation.Resource; /** * @author zhibing.pu @@ -15,12 +19,27 @@ @Component public class MqttReceiverMessageHandler implements MessageHandler { @Resource private WarnMsgService warnMsgService; @Override public void handleMessage(Message<?> message) throws MessagingException { MessageHeaders headers = message.getHeaders(); log.error("线程名称:{},收到消息,主题:{},消息:{}", Thread.currentThread().getName(), headers.get("mqtt_receivedTopic").toString(), message.getPayload()); // log.info("收到消息主题:{}", headers.get("mqtt_receivedTopic").toString()); // log.info("收到消息:{}", message.getPayload()); // 消息保存到内存队列里面,定时批量入库,也可以在这里直接入库 String s = message.getPayload().toString(); JSONObject jsonObject = JSONObject.parseObject(s); String method = jsonObject.getString("method"); JSONObject params = jsonObject.getJSONObject("params"); String ability = params.getString("ability"); switch (ability){ case "event_msa_alarm": warnMsgService.saveWarnMsgService(jsonObject); break; case "event_msa_pic": warnMsgService.saveWarnMsgPicService(jsonObject); break; } } }