From fadfd7f1680d4b07269cac0b79318e2012288a17 Mon Sep 17 00:00:00 2001
From: Pu Zhibing <393733352@qq.com>
Date: 星期三, 04 六月 2025 15:32:44 +0800
Subject: [PATCH] 处理川标报警附件协议

---
 ruoyi-service/ruoyi-dataInterchange/src/main/java/com/ruoyi/dataInterchange/server/WarnMsgService.java |  141 +++++++++++++++++++++++++++++++++++++---------
 1 files changed, 113 insertions(+), 28 deletions(-)

diff --git a/ruoyi-service/ruoyi-dataInterchange/src/main/java/com/ruoyi/dataInterchange/server/WarnMsgService.java b/ruoyi-service/ruoyi-dataInterchange/src/main/java/com/ruoyi/dataInterchange/server/WarnMsgService.java
index 50040d3..9b7cc4a 100644
--- a/ruoyi-service/ruoyi-dataInterchange/src/main/java/com/ruoyi/dataInterchange/server/WarnMsgService.java
+++ b/ruoyi-service/ruoyi-dataInterchange/src/main/java/com/ruoyi/dataInterchange/server/WarnMsgService.java
@@ -1,17 +1,16 @@
 package com.ruoyi.dataInterchange.server;
 
 import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson2.JSONArray;
 import com.alibaba.fastjson2.JSONObject;
-import com.ruoyi.dataInterchange.dao.UPExgMsgRealLocationDao;
-import com.ruoyi.dataInterchange.dao.UPWarnMsgAdptInfoDao;
-import com.ruoyi.dataInterchange.dao.UPWarnMsgOperationInfoDao;
-import com.ruoyi.dataInterchange.dao.UPWarnMsgUrgeTodoAckDao;
+import com.ruoyi.dataInterchange.dao.*;
 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.Artemis;
 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.FindPicturesByAlarmIdRequest;
 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;
@@ -30,6 +29,7 @@
 import java.time.format.DateTimeFormatter;
 import java.util.Arrays;
 import java.util.List;
+import java.util.StringJoiner;
 
 /**
  * @author zhibing.pu
@@ -50,6 +50,9 @@
 	
 	@Resource
 	private UPWarnMsgOperationInfoDao upWarnMsgOperationInfoDao;
+	
+	@Resource
+	private UpWarnMsgFileListAckDao upWarnMsgFileListAckDao;
 	
 	@Resource
 	private RedisTemplate redisTemplate;
@@ -82,6 +85,10 @@
 			case UP_WARN_MSG_OPERATION_INFO:
 				log.info("上报报警处理信息({}):{}", DataType.UP_WARN_MSG_OPERATION_INFO.getCode(), out);
 				up_warn_msg_operation_info(ctx, out.getGnsscenterId(), warnMsg);
+				break;
+			case UP_WARN_MSG_FILELIST_ACK:
+				log.info("报警附件目录请求应答({}):{}", DataType.UP_WARN_MSG_FILELIST_ACK.getCode(), out);
+				up_warn_msg_filelist_ack(ctx, out.getGnsscenterId(), warnMsg);
 				break;
 			default:
 				break;
@@ -156,6 +163,24 @@
 			}
 		}
 		upWarnMsgAdptInfoDao.save(upWarnMsgAdptInfo);
+		
+		//请求报警附件(川标协议)
+		if(enterprise.contains(inferiorPlatformId)){
+			DOWNWarnMsgFileListReq downWarnMsgFileListReq = new DOWNWarnMsgFileListReq();
+			downWarnMsgFileListReq.setVehicleNo(upWarnMsgAdptInfo.getVehicleNo());
+			downWarnMsgFileListReq.setVehicleColor(upWarnMsgAdptInfo.getVehicleColor());
+			downWarnMsgFileListReq.setDataType(DataType.DOWN_WARN_MSG_FILELIST_REQ.getCode());
+			downWarnMsgFileListReq.setDataLength(32);
+			downWarnMsgFileListReq.setInfoId(upWarnMsgAdptInfo.getInfoId());
+			byte[] body = downWarnMsgFileListReq.encode();
+			OuterPacket out = new OuterPacket(DataType.DOWN_WARN_MSG.getCode(), inferiorPlatformId, body);
+			//获取从链路通道
+			Channel channel = ChannelMap.getClientChannel(inferiorPlatformId);
+			if (null != channel && channel.isActive()) {
+				channel.writeAndFlush(out);
+				log.info("报警附件目录请求({}):{}", DataType.DOWN_WARN_MSG_FILELIST_REQ.getCode(), JSON.toJSONString(downWarnMsgFileListReq));
+			}
+		}
 	}
 	
 	
@@ -178,11 +203,71 @@
 	
 	
 	/**
+	 * 报警附件目录请求应答
+	 * @param ctx
+	 * @param inferiorPlatformId
+	 * @param warnMsg
+	 */
+	public void up_warn_msg_filelist_ack(ChannelHandlerContext ctx, int inferiorPlatformId, WarnMsg warnMsg){
+		UpWarnMsgFileListAck upWarnMsgFileListAck = new UpWarnMsgFileListAck().decode(warnMsg).decode(warnMsg);
+		upWarnMsgFileListAck.setInferiorPlatformId(inferiorPlatformId);
+		upWarnMsgFileListAck.setCreateTime(LocalDateTime.now().toEpochSecond(ZoneOffset.ofHours(8)));
+		upWarnMsgFileListAckDao.save(upWarnMsgFileListAck);
+		//修改报警处理结果
+		UPWarnMsgAdptInfo upWarnMsgAdptInfo = upWarnMsgAdptInfoDao.findByInfoIdIs(upWarnMsgFileListAck.getInfoId());
+		StringJoiner joiner = new StringJoiner(",");
+		upWarnMsgFileListAck.getFileList().forEach(file->{
+			if(file.getFileType() == 0x00){
+				joiner.add(file.getFileUrl());
+			}
+		});
+		upWarnMsgAdptInfo.setPicUrl(joiner.toString());
+		upWarnMsgAdptInfoDao.save(upWarnMsgAdptInfo);
+	}
+	
+	
+	
+	/**
 	 * 定时任务督办报警请求
 	 */
 	public void taskUrgeTodo() {
 		List<UPWarnMsgAdptInfo> list = upWarnMsgAdptInfoDao.findByResultIsAndLevelNotNullAndPushTimeBefore(0x00, LocalDateTime.now().toEpochSecond(ZoneOffset.ofHours(8)));
 		for (UPWarnMsgAdptInfo upWarnMsgAdptInfo : list) {
+			Integer inferiorPlatformId = upWarnMsgAdptInfo.getInferiorPlatformId();
+			//海康威视直接走接口
+			if(25439966 == inferiorPlatformId){
+				try {
+					if("***".equals(upWarnMsgAdptInfo.getPicUrl())){
+						FindPicturesByAlarmIdRequest findPicturesByAlarmIdRequest = new FindPicturesByAlarmIdRequest();
+						findPicturesByAlarmIdRequest.setAlarmId(upWarnMsgAdptInfo.getInfoId());
+						long warnTime = upWarnMsgAdptInfo.getWarnTime();
+						findPicturesByAlarmIdRequest.setAlarmTime(LocalDateTime.ofEpochSecond(warnTime, 0, ZoneOffset.ofHours(8)).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
+						String pictures = Artemis.findPicturesByAlarmId(findPicturesByAlarmIdRequest);
+						JSONObject jsonObject = JSONObject.parseObject(pictures);
+						Integer code = jsonObject.getInteger("code");
+						if(0 == code){
+							JSONArray data = jsonObject.getJSONArray("data");
+							StringJoiner joiner = new StringJoiner(",");
+							for (int i = 0; i < data.size(); i++) {
+								JSONObject jsonObject1 = data.getJSONObject(0);
+								String url = jsonObject1.getString("url");
+								joiner.add(url);
+							}
+							upWarnMsgAdptInfo.setPicUrl(joiner.toString());
+							upWarnMsgAdptInfoDao.save(upWarnMsgAdptInfo);
+						}
+					}
+					
+					
+					
+					
+					
+				}catch (Exception e){
+					e.printStackTrace();
+				}
+			}
+			
+			
 			down_warn_msg_urge_todo_req(upWarnMsgAdptInfo);
 		}
 	}
@@ -266,7 +351,30 @@
 					if(!warnType.contains(upWarnMsgAdptInfo.getWarnType())){
 						return;
 					}
+					upWarnMsgAdptInfo.setResult(0x00);
+					
+					//获取报警抓拍图片
+					if(data.getPicNum() > 0){
+						upWarnMsgAdptInfo.setPicUrl("***");
+						FindPicturesByAlarmIdRequest findPicturesByAlarmIdRequest = new FindPicturesByAlarmIdRequest();
+						findPicturesByAlarmIdRequest.setAlarmId(data.getAlarmId());
+						findPicturesByAlarmIdRequest.setAlarmTime(data.getAlarmTime());
+						String pictures = Artemis.findPicturesByAlarmId(findPicturesByAlarmIdRequest);
+						JSONObject jsonObject1 = JSONObject.parseObject(pictures);
+						Integer code = jsonObject1.getInteger("code");
+						if(0 == code){
+							JSONArray data1 = jsonObject1.getJSONArray("data");
+							StringJoiner joiner = new StringJoiner(",");
+							for (int i = 0; i < data1.size(); i++) {
+								JSONObject jsonObject2 = data1.getJSONObject(0);
+								String url = jsonObject2.getString("url");
+								joiner.add(url);
+							}
+							upWarnMsgAdptInfo.setPicUrl(joiner.toString());
+						}
+					}
 					upWarnMsgAdptInfoDao.save(upWarnMsgAdptInfo);
+					
 				}catch (Exception e){
 					e.printStackTrace();
 				}
@@ -439,29 +547,6 @@
 				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);
-				}
-			}
-		});
-	}
-	
 	
 	
 }

--
Gitblit v1.7.1