|
|
@@ -4,6 +4,8 @@ import cn.hutool.core.bean.BeanUtil;
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
import cn.hutool.core.util.IdUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
+import cn.hutool.http.HttpUtil;
|
|
|
+import cn.hutool.json.JSONUtil;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.fasterxml.jackson.databind.DeserializationFeature;
|
|
|
import com.fasterxml.jackson.databind.JsonNode;
|
|
|
@@ -14,6 +16,8 @@ import com.usky.sas.domain.*;
|
|
|
import com.usky.sas.mapper.*;
|
|
|
import com.usky.sas.mqtt.dto.*;
|
|
|
import com.usky.sas.service.*;
|
|
|
+import com.usky.sas.service.dto.agbox.JsonRpcRequest;
|
|
|
+import com.usky.sas.service.vo.*;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.eclipse.paho.client.mqttv3.*;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
@@ -26,7 +30,9 @@ import javax.annotation.PreDestroy;
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
import java.util.Arrays;
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@Slf4j
|
|
|
@@ -75,6 +81,8 @@ public class MqttService {
|
|
|
@Autowired
|
|
|
private SasEventTypeGroupService eventTypeGroupService;
|
|
|
@Autowired
|
|
|
+ private SasPatrolUserParamService sasPatrolUserParamService;
|
|
|
+ @Autowired
|
|
|
private SasGisMapper gisMapper;
|
|
|
|
|
|
@Autowired
|
|
|
@@ -378,66 +386,68 @@ public class MqttService {
|
|
|
String method = root.path("method").asText();
|
|
|
|
|
|
if ("event".equals(method)) {
|
|
|
- SnapEventMessage message = mapper.readValue(payload, SnapEventMessage.class);
|
|
|
- if(message.getEventCode() == null && root.get("code") != null) {
|
|
|
- message.setEventCode(root.get("code").asInt());
|
|
|
+ SnapEventResult eventResult = (SnapEventResult)this.mapper.readValue(payload, SnapEventResult.class);
|
|
|
+ log.info("实时智能分析");
|
|
|
+ Map<String, Object> map = new HashMap();
|
|
|
+ map.put("eventId", eventResult.getId());
|
|
|
+ JsonRpcRequest getEventInfoJson = new JsonRpcRequest("getEvent", map, (Long)null);
|
|
|
+ Map<String, Object> getEventInfo = new HashMap();
|
|
|
+ getEventInfo.put("key", this.sasConfigService.getConfig().getKeyds());
|
|
|
+ getEventInfo.put("json", getEventInfoJson.toString());
|
|
|
+ log.info("请求AG报文:{}", JSONUtil.toJsonStr(getEventInfo));
|
|
|
+ String resultEvent = HttpUtil.post(this.sasConfigService.getConfig().getHost() + "/agbox/device/snap", getEventInfo);
|
|
|
+ log.info("请求AG响应:{}", resultEvent);
|
|
|
+ SnapEventInfoVo eventInfoVo = (SnapEventInfoVo)this.mapper.readValue(resultEvent, SnapEventInfoVo.class);
|
|
|
+ SnapEventInfoResult result = eventInfoVo.getResult();
|
|
|
+ SnapEventInfo eventInfo = result.getEventInfo();
|
|
|
+ SasSnapEvent bean = (SasSnapEvent)BeanUtil.toBean(eventInfo, SasSnapEvent.class);
|
|
|
+ BrieflyEventInfo info = (BrieflyEventInfo)BeanUtil.toBeanIgnoreError(bean, BrieflyEventInfo.class);
|
|
|
+ if (eventInfo.getEventPic() != null) {
|
|
|
+ SasPic pic = (SasPic)BeanUtil.toBean(eventInfo.getEventPic(), SasPic.class);
|
|
|
+ pic.setId(IdUtil.randomUUID());
|
|
|
+ this.sasPicMapper.insert(pic);
|
|
|
+ bean.setEventPicId(pic.getId());
|
|
|
+ info.setEventUrl(pic.getUrl() + pic.getPath());
|
|
|
+ }
|
|
|
+
|
|
|
+ if (eventInfo.getScenePic() != null) {
|
|
|
+ SasPic pic = (SasPic)BeanUtil.toBean(eventInfo.getScenePic(), SasPic.class);
|
|
|
+ pic.setId(IdUtil.randomUUID());
|
|
|
+ this.sasPicMapper.insert(pic);
|
|
|
+ bean.setScenePicId(pic.getId());
|
|
|
+ info.setSceneUrl(pic.getUrl() + pic.getPath());
|
|
|
+ }
|
|
|
+ if(eventInfo.getEventCode() == null && root.get("code") != null) {
|
|
|
+ eventInfo.setEventCode(root.get("code").asInt());
|
|
|
}
|
|
|
|
|
|
// 1. 检查设备是否存在
|
|
|
- SasDevice device = findDevice(message.getDeviceId(), message.getChannel(), SystemTypeCodeEnum.snap.getCode());
|
|
|
+ SasDevice device = findDevice(eventInfo.getDeviceId(), eventInfo.getChannel(), SystemTypeCodeEnum.snap.getCode());
|
|
|
if (device == null) {
|
|
|
- log.warn("设备不存在,丢弃抓拍事件: deviceId={}, channel={}", message.getDeviceId(), message.getChannel());
|
|
|
+ log.warn("设备不存在,丢弃抓拍事件: deviceId={}, channel={}", eventInfo.getDeviceId(), eventInfo.getChannel());
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- SasSnapEvent event = new SasSnapEvent();
|
|
|
-
|
|
|
- String eventId = message.getId() != null && !message.getId().isEmpty()
|
|
|
- ? message.getId()
|
|
|
+ String eventId = eventResult.getId() != null && !eventResult.getId().isEmpty()
|
|
|
+ ? eventResult.getId()
|
|
|
: IdUtil.randomUUID();
|
|
|
// 如果该事件已存在(设备重发/重复消息),避免主键冲突,直接跳过
|
|
|
if (snapEventService.getById(eventId) != null) {
|
|
|
log.info("抓拍事件已存在, 跳过保存, eventId={}", eventId);
|
|
|
return;
|
|
|
}
|
|
|
- event.setEventId(eventId);
|
|
|
- BeanUtil.copyProperties(message, event, "eventId");
|
|
|
- event.setTriggerTime(parseTime(message.getTriggerTime()));
|
|
|
- event.setCreateTime(LocalDateTime.now());
|
|
|
- event.setUpdateTime(LocalDateTime.now());
|
|
|
+ bean.setEventId(eventId);
|
|
|
+ BeanUtil.copyProperties(eventInfo, bean, "eventId");
|
|
|
+ bean.setTriggerTime(parseTime(eventInfo.getTriggerTime()));
|
|
|
+ bean.setCreateTime(LocalDateTime.now());
|
|
|
+ bean.setUpdateTime(LocalDateTime.now());
|
|
|
|
|
|
- // 处理图片信息
|
|
|
- if (message.getSnapPic() != null) {
|
|
|
- SnapEventMessage.PicInfo picInfo = message.getSnapPic();
|
|
|
- if (picInfo != null && StrUtil.isNotBlank(picInfo.getUrl()) && StrUtil.isNotBlank(picInfo.getPath())) {
|
|
|
- SasPic pic = new SasPic();
|
|
|
- pic.setId(IdUtil.randomUUID());
|
|
|
- pic.setUrl(picInfo.getUrl());
|
|
|
- pic.setPath(picInfo.getPath());
|
|
|
- pic.setCreateTime(LocalDateTime.now());
|
|
|
- pic.setUpdateTime(LocalDateTime.now());
|
|
|
- sasPicMapper.insert(pic);
|
|
|
-
|
|
|
- // 设置事件图片ID
|
|
|
- event.setEventPicId(pic.getId());
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- snapEventService.save(event);
|
|
|
+ snapEventService.save(bean);
|
|
|
|
|
|
- BrieflyEventInfo info = BeanUtil.toBean(event, BrieflyEventInfo.class);
|
|
|
- info.setTriggerTime(message.getTriggerTime());
|
|
|
+ info.setTriggerTime(eventInfo.getTriggerTime());
|
|
|
info.setCreateTime(LocalDateTime.now().format(formatter));
|
|
|
|
|
|
- // 如果前面已经设置了eventUrl,这里需要保持
|
|
|
- if (info.getEventUrl() == null && event.getEventPicId() != null) {
|
|
|
- SasPic pic = sasPicMapper.selectById(event.getEventPicId());
|
|
|
- if (pic != null && StrUtil.isNotBlank(pic.getUrl()) && StrUtil.isNotBlank(pic.getPath())) {
|
|
|
- info.setEventUrl(pic.getUrl() + pic.getPath());
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- SasSnapTypeCode code = snapTypeCodeMapper.selectById(event.getEventCode());
|
|
|
+ SasSnapTypeCode code = snapTypeCodeMapper.selectById(bean.getEventCode());
|
|
|
if (code != null) {
|
|
|
info.setEventTypeName(code.getName());
|
|
|
}
|
|
|
@@ -450,7 +460,7 @@ public class MqttService {
|
|
|
info.setDeviceType(SystemTypeCodeEnum.snap.getCode());
|
|
|
SasWebSocket.sendAll(info);
|
|
|
|
|
|
- log.info("抓拍事件保存并推送成功, eventId={}", event.getEventId());
|
|
|
+ log.info("抓拍事件保存并推送成功, eventId={}", bean.getEventId());
|
|
|
} else if ("heart".equals(method)) {
|
|
|
handleHeartbeat(payload, SystemTypeCodeEnum.snap.getCode());
|
|
|
}
|
|
|
@@ -554,21 +564,53 @@ public class MqttService {
|
|
|
String method = root.path("method").asText();
|
|
|
|
|
|
if ("event".equals(method)) {
|
|
|
- ParkingEventMessage message = mapper.readValue(payload, ParkingEventMessage.class);
|
|
|
- if(message.getEventCode() == null && root.get("code") != null) {
|
|
|
- message.setEventCode(root.get("code").asInt());
|
|
|
+ ParkingEventResult eventResult = (ParkingEventResult)this.mapper.readValue(payload, ParkingEventResult.class);
|
|
|
+ Map<String, Object> map = new HashMap();
|
|
|
+ map.put("eventId", eventResult.getId());
|
|
|
+ JsonRpcRequest getParkingEventInfoJson = new JsonRpcRequest("getEvent", map, (Long)null);
|
|
|
+ Map<String, Object> getParkingEventInfo = new HashMap();
|
|
|
+ getParkingEventInfo.put("key", this.sasConfigService.getConfig().getKeyds());
|
|
|
+ getParkingEventInfo.put("json", getParkingEventInfoJson.toString());
|
|
|
+ log.info("请求AG报文:{}", JSONUtil.toJsonStr(getParkingEventInfo));
|
|
|
+ String resultEvent = HttpUtil.post(this.sasConfigService.getConfig().getHost() + "/agbox/device/parking", getParkingEventInfo);
|
|
|
+ log.info("请求AG响应:{}", resultEvent);
|
|
|
+ ParkingEventInfoVo parkingEventInfoVo = (ParkingEventInfoVo)this.mapper.readValue(resultEvent, ParkingEventInfoVo.class);
|
|
|
+ ParkingEventInfoResult result = parkingEventInfoVo.getResult();
|
|
|
+ ParkingEventInfo eventInfo = result.getEventInfo();
|
|
|
+ SasParkingEvent bean = (SasParkingEvent)BeanUtil.toBean(eventInfo, SasParkingEvent.class);
|
|
|
+ bean.setCreateTime(LocalDateTime.parse(eventInfo.getReceivingTime(), this.formatter));
|
|
|
+ bean.setTriggerTime(LocalDateTime.parse(eventInfo.getTriggerTime(), this.formatter));
|
|
|
+ bean.setEventId(eventResult.getId());
|
|
|
+ bean.setAccessType(eventInfo.getIo());
|
|
|
+ bean.setCarType(eventInfo.getCarCode());
|
|
|
+ bean.setPlateType(eventInfo.getPlateCode());
|
|
|
+ if (eventInfo.getEventPic() != null) {
|
|
|
+ SasPic pic = (SasPic)BeanUtil.toBean(eventInfo.getEventPic(), SasPic.class);
|
|
|
+ pic.setId(IdUtil.randomUUID());
|
|
|
+ this.sasPicMapper.insert(pic);
|
|
|
+ bean.setEventPicId(pic.getId());
|
|
|
+ }
|
|
|
+
|
|
|
+ if (eventInfo.getPlacePic() != null) {
|
|
|
+ SasPic pic = (SasPic)BeanUtil.toBean(eventInfo.getPlacePic(), SasPic.class);
|
|
|
+ pic.setId(IdUtil.randomUUID());
|
|
|
+ this.sasPicMapper.insert(pic);
|
|
|
+ bean.setPlatePicId(pic.getId());
|
|
|
+ }
|
|
|
+ if(eventInfo.getEventCode() == null && root.get("code") != null) {
|
|
|
+ eventInfo.setEventCode(root.get("code").asInt());
|
|
|
}
|
|
|
|
|
|
// 1. 检查设备是否存在
|
|
|
- SasDevice device = findDevice(message.getDeviceId(), message.getChannel(), SystemTypeCodeEnum.parking.getCode());
|
|
|
+ SasDevice device = findDevice(eventInfo.getDeviceId(), eventInfo.getChannel(), SystemTypeCodeEnum.parking.getCode());
|
|
|
if (device == null) {
|
|
|
- log.warn("设备不存在,丢弃停车场事件: deviceId={}, channel={}", message.getDeviceId(), message.getChannel());
|
|
|
+ log.warn("设备不存在,丢弃停车场事件: deviceId={}, channel={}", eventInfo.getDeviceId(), eventInfo.getChannel());
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
SasParkingEvent event = new SasParkingEvent();
|
|
|
- String eventId = message.getId() != null && !message.getId().isEmpty()
|
|
|
- ? message.getId()
|
|
|
+ String eventId = eventResult.getId() != null && !eventResult.getId().isEmpty()
|
|
|
+ ? eventResult.getId()
|
|
|
: IdUtil.randomUUID();
|
|
|
// 如果该事件已存在(设备重发/重复消息),避免主键冲突,直接跳过
|
|
|
if (parkingEventService.getById(eventId) != null) {
|
|
|
@@ -576,40 +618,24 @@ public class MqttService {
|
|
|
return;
|
|
|
}
|
|
|
event.setEventId(eventId);
|
|
|
- BeanUtil.copyProperties(message, event, "eventId");
|
|
|
- event.setTriggerTime(parseTime(message.getTriggerTime()));
|
|
|
+ BeanUtil.copyProperties(eventInfo, event, "eventId");
|
|
|
+ event.setTriggerTime(parseTime(eventInfo.getTriggerTime()));
|
|
|
event.setCreateTime(LocalDateTime.now());
|
|
|
event.setUpdateTime(LocalDateTime.now());
|
|
|
|
|
|
- // 处理图片信息
|
|
|
- if (message.getPlatePic() != null) {
|
|
|
- ParkingEventMessage.PicInfo picInfo = message.getPlatePic();
|
|
|
- if (picInfo != null && StrUtil.isNotBlank(picInfo.getUrl()) && StrUtil.isNotBlank(picInfo.getPath())) {
|
|
|
- SasPic pic = new SasPic();
|
|
|
- pic.setId(IdUtil.randomUUID());
|
|
|
- pic.setUrl(picInfo.getUrl());
|
|
|
- pic.setPath(picInfo.getPath());
|
|
|
- pic.setCreateTime(LocalDateTime.now());
|
|
|
- pic.setUpdateTime(LocalDateTime.now());
|
|
|
- sasPicMapper.insert(pic);
|
|
|
-
|
|
|
- // 设置车牌图片ID
|
|
|
- event.setPlatePicId(pic.getId());
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
parkingEventService.save(event);
|
|
|
|
|
|
BrieflyEventInfo info = BeanUtil.toBean(event, BrieflyEventInfo.class);
|
|
|
- info.setTriggerTime(message.getTriggerTime());
|
|
|
+ info.setTriggerTime(eventInfo.getTriggerTime());
|
|
|
info.setCreateTime(LocalDateTime.now().format(formatter));
|
|
|
|
|
|
// 设置图片URL(如果有)
|
|
|
- if (event.getPlatePicId() != null) {
|
|
|
- SasPic pic = sasPicMapper.selectById(event.getPlatePicId());
|
|
|
- if (pic != null && StrUtil.isNotBlank(pic.getUrl()) && StrUtil.isNotBlank(pic.getPath())) {
|
|
|
- info.setEventUrl(pic.getUrl() + pic.getPath());
|
|
|
- }
|
|
|
+ if (eventInfo.getEventPic() != null) {
|
|
|
+ info.setEventUrl(eventInfo.getEventPic().getUrl() + eventInfo.getEventPic().getPath());
|
|
|
+ }
|
|
|
+
|
|
|
+ if (eventInfo.getPlacePic() != null) {
|
|
|
+ info.setEventUrl(eventInfo.getPlacePic().getUrl() + eventInfo.getPlacePic().getPath());
|
|
|
}
|
|
|
|
|
|
SasParkingEventCode code = parkingEventCodeMapper.selectById(event.getEventCode());
|
|
|
@@ -728,21 +754,46 @@ public class MqttService {
|
|
|
String method = root.path("method").asText();
|
|
|
|
|
|
if ("event".equals(method)) {
|
|
|
- AlarsasEventMessage message = mapper.readValue(payload, AlarsasEventMessage.class);
|
|
|
- if(message.getEventCode() == null && root.get("code") != null) {
|
|
|
- message.setEventCode(root.get("code").asInt());
|
|
|
+ AlarmEventResult eventResult = (AlarmEventResult)this.mapper.readValue(payload, AlarmEventResult.class);
|
|
|
+ Map<String, Object> map = new HashMap();
|
|
|
+ map.put("eventId", eventResult.getId());
|
|
|
+ JsonRpcRequest getAlarmEventInfoJson = new JsonRpcRequest("getEvent", map, (Long)null);
|
|
|
+ Map<String, Object> getAlarmEventInfo = new HashMap();
|
|
|
+ getAlarmEventInfo.put("key", this.sasConfigService.getConfig().getKeyds());
|
|
|
+ getAlarmEventInfo.put("json", getAlarmEventInfoJson.toString());
|
|
|
+ log.info("请求AG报文:{}", JSONUtil.toJsonStr(getAlarmEventInfo));
|
|
|
+ String resultEvent = HttpUtil.post(this.sasConfigService.getConfig().getHost() + "/agbox/device/alarm", getAlarmEventInfo);
|
|
|
+ log.info("请求AG响应:{}", resultEvent);
|
|
|
+ AlarmEventInfoVo alarmEventInfoVo = (AlarmEventInfoVo)this.mapper.readValue(resultEvent, AlarmEventInfoVo.class);
|
|
|
+ AlarmEventInfoResult result = alarmEventInfoVo.getResult();
|
|
|
+ AlarmEventInfo eventInfo = result.getEventInfo();
|
|
|
+
|
|
|
+ SasAlarsasEvent event = new SasAlarsasEvent();
|
|
|
+ if (eventInfo.getEventPic() != null) {
|
|
|
+ SasPic pic = (SasPic)BeanUtil.toBean(eventInfo.getEventPic(), SasPic.class);
|
|
|
+ pic.setId(IdUtil.randomUUID());
|
|
|
+ this.sasPicMapper.insert(pic);
|
|
|
+ event.setPicId(pic.getId());
|
|
|
+ }
|
|
|
+
|
|
|
+ if (eventInfo.getGis() != null) {
|
|
|
+ SasGis gis = (SasGis)BeanUtil.toBean(eventInfo.getGis(), SasGis.class);
|
|
|
+ gis.setId(IdUtil.randomUUID());
|
|
|
+ this.gisMapper.insert(gis);
|
|
|
+ event.setGisId(gis.getId());
|
|
|
+ }
|
|
|
+ if(eventInfo.getEventCode() == null && root.get("code") != null) {
|
|
|
+ eventInfo.setEventCode(root.get("code").asInt());
|
|
|
}
|
|
|
|
|
|
// 1. 检查设备是否存在
|
|
|
- SasDevice device = findDevice(message.getDeviceId(), message.getChannel(), SystemTypeCodeEnum.alarm.getCode());
|
|
|
+ SasDevice device = findDevice(eventInfo.getDeviceId(), eventInfo.getChannel(), SystemTypeCodeEnum.alarm.getCode());
|
|
|
if (device == null) {
|
|
|
- log.warn("设备不存在,丢弃入侵报警事件: deviceId={}, channel={}", message.getDeviceId(), message.getChannel());
|
|
|
+ log.warn("设备不存在,丢弃入侵报警事件: deviceId={}, channel={}", eventInfo.getDeviceId(), eventInfo.getChannel());
|
|
|
return;
|
|
|
}
|
|
|
-
|
|
|
- SasAlarsasEvent event = new SasAlarsasEvent();
|
|
|
- String eventId = message.getId() != null && !message.getId().isEmpty()
|
|
|
- ? message.getId()
|
|
|
+ String eventId = eventResult.getId() != null && !eventResult.getId().isEmpty()
|
|
|
+ ? eventResult.getId()
|
|
|
: IdUtil.randomUUID();
|
|
|
// 如果该事件已存在(设备重发/重复消息),避免主键冲突,直接跳过
|
|
|
// if (alarsasEventService.getById(eventId) != null) {
|
|
|
@@ -750,32 +801,15 @@ public class MqttService {
|
|
|
// return;
|
|
|
// }
|
|
|
event.setEventId(eventId);
|
|
|
- BeanUtil.copyProperties(message, event, "eventId");
|
|
|
- event.setTriggerTime(parseTime(message.getTriggerTime()));
|
|
|
+ BeanUtil.copyProperties(eventResult, event, "eventId");
|
|
|
+ event.setTriggerTime(parseTime(eventInfo.getTriggerTime()));
|
|
|
event.setCreateTime(LocalDateTime.now());
|
|
|
event.setUpdateTime(LocalDateTime.now());
|
|
|
|
|
|
- // 处理图片信息
|
|
|
- if (message.getAlarmPic() != null) {
|
|
|
- AlarsasEventMessage.PicInfo picInfo = message.getAlarmPic();
|
|
|
- if (picInfo != null && StrUtil.isNotBlank(picInfo.getUrl()) && StrUtil.isNotBlank(picInfo.getPath())) {
|
|
|
- SasPic pic = new SasPic();
|
|
|
- pic.setId(IdUtil.randomUUID());
|
|
|
- pic.setUrl(picInfo.getUrl());
|
|
|
- pic.setPath(picInfo.getPath());
|
|
|
- pic.setCreateTime(LocalDateTime.now());
|
|
|
- pic.setUpdateTime(LocalDateTime.now());
|
|
|
- sasPicMapper.insert(pic);
|
|
|
-
|
|
|
- // 设置事件图片ID
|
|
|
- event.setPicId(pic.getId());
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
alarsasEventService.saveOrUpdate(event);
|
|
|
|
|
|
BrieflyEventInfo info = BeanUtil.toBean(event, BrieflyEventInfo.class);
|
|
|
- info.setTriggerTime(message.getTriggerTime());
|
|
|
+ info.setTriggerTime(eventInfo.getTriggerTime());
|
|
|
info.setCreateTime(LocalDateTime.now().format(formatter));
|
|
|
|
|
|
// 设置图片URL(如果有)
|
|
|
@@ -815,21 +849,30 @@ public class MqttService {
|
|
|
String method = root.path("method").asText();
|
|
|
|
|
|
if ("event".equals(method)) {
|
|
|
- PatrolEventMessage message = mapper.readValue(payload, PatrolEventMessage.class);
|
|
|
- if(message.getEventCode() == null && root.get("code") != null) {
|
|
|
- message.setEventCode(root.get("code").asInt());
|
|
|
- }
|
|
|
+ PatrolEventResult eventResult = (PatrolEventResult)this.mapper.readValue(payload, PatrolEventResult.class);
|
|
|
+ Map<String, Object> map = new HashMap();
|
|
|
+ map.put("eventId", eventResult.getId());
|
|
|
+ JsonRpcRequest getPatrolEventInfoJson = new JsonRpcRequest("getEvent", map, (Long)null);
|
|
|
+ Map<String, Object> getPatrolEventInfo = new HashMap();
|
|
|
+ getPatrolEventInfo.put("key", this.sasConfigService.getConfig().getKeyds());
|
|
|
+ getPatrolEventInfo.put("json", getPatrolEventInfoJson.toString());
|
|
|
+ log.info("请求AG报文:{}", JSONUtil.toJsonStr(getPatrolEventInfo));
|
|
|
+ String resultEvent = HttpUtil.post(this.sasConfigService.getConfig().getHost() + "/agbox/device/patrol", getPatrolEventInfo);
|
|
|
+ log.info("请求AG响应:{}", resultEvent);
|
|
|
+ PatrolEventInfoVo patrolEventInfoVo = (PatrolEventInfoVo)this.mapper.readValue(resultEvent, PatrolEventInfoVo.class);
|
|
|
+ PatrolEventInfoResult result = patrolEventInfoVo.getResult();
|
|
|
+ PatrolEventInfo eventInfo = result.getEventInfo();
|
|
|
|
|
|
// 1. 检查设备是否存在
|
|
|
- SasDevice device = findDevice(message.getDeviceId(), 0, SystemTypeCodeEnum.patrol.getCode());
|
|
|
+ SasDevice device = findDevice(eventInfo.getDeviceId(), 0, SystemTypeCodeEnum.patrol.getCode());
|
|
|
if (device == null) {
|
|
|
- log.warn("设备不存在,丢弃巡检事件: deviceId={}, channel={}", message.getDeviceId(), message.getChannel());
|
|
|
+ log.warn("设备不存在,丢弃巡检事件: deviceId={}, channel={}", eventInfo.getDeviceId(), eventInfo.getChannel());
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
SasPatrolEvent event = new SasPatrolEvent();
|
|
|
- String eventId = message.getId() != null && !message.getId().isEmpty()
|
|
|
- ? message.getId()
|
|
|
+ String eventId = patrolEventInfoVo.getId() != null && !patrolEventInfoVo.getId().isEmpty()
|
|
|
+ ? patrolEventInfoVo.getId()
|
|
|
: IdUtil.randomUUID();
|
|
|
// 如果该事件已存在(设备重发/重复消息),避免主键冲突,直接跳过
|
|
|
if (patrolEventService.getById(eventId) != null) {
|
|
|
@@ -837,32 +880,30 @@ public class MqttService {
|
|
|
return;
|
|
|
}
|
|
|
event.setEventId(eventId);
|
|
|
- BeanUtil.copyProperties(message, event, "eventId");
|
|
|
- event.setTriggerTime(parseTime(message.getTriggerTime()));
|
|
|
+ BeanUtil.copyProperties(eventInfo, event, "eventId");
|
|
|
+ event.setTriggerTime(LocalDateTime.parse(eventInfo.getTriggerTime()));
|
|
|
event.setCreateTime(LocalDateTime.now());
|
|
|
event.setUpdateTime(LocalDateTime.now());
|
|
|
|
|
|
// 处理图片信息
|
|
|
- if (message.getPatrolPic() != null) {
|
|
|
- PatrolEventMessage.PicInfo picInfo = message.getPatrolPic();
|
|
|
- if (picInfo != null && StrUtil.isNotBlank(picInfo.getUrl()) && StrUtil.isNotBlank(picInfo.getPath())) {
|
|
|
- SasPic pic = new SasPic();
|
|
|
- pic.setId(IdUtil.randomUUID());
|
|
|
- pic.setUrl(picInfo.getUrl());
|
|
|
- pic.setPath(picInfo.getPath());
|
|
|
- pic.setCreateTime(LocalDateTime.now());
|
|
|
- pic.setUpdateTime(LocalDateTime.now());
|
|
|
- sasPicMapper.insert(pic);
|
|
|
-
|
|
|
- // 设置事件图片ID
|
|
|
- event.setPicId(pic.getId());
|
|
|
- }
|
|
|
+ if (eventInfo.getEventPic() != null) {
|
|
|
+ SasPic pic = (SasPic) BeanUtil.toBean(eventInfo.getEventPic(), SasPic.class);
|
|
|
+ pic.setId(IdUtil.randomUUID());
|
|
|
+ this.sasPicMapper.insert(pic);
|
|
|
+ event.setPicId(pic.getId());
|
|
|
+ }
|
|
|
+
|
|
|
+ if (eventInfo.getUserParams() != null) {
|
|
|
+ SasPatrolUserParam userParam = (SasPatrolUserParam)BeanUtil.toBean(eventInfo.getUserParams(), SasPatrolUserParam.class);
|
|
|
+ userParam.setId(IdUtil.randomUUID());
|
|
|
+ this.sasPatrolUserParamService.save(userParam);
|
|
|
+ event.setUserParasasId(userParam.getId());
|
|
|
}
|
|
|
|
|
|
patrolEventService.save(event);
|
|
|
|
|
|
BrieflyEventInfo info = BeanUtil.toBean(event, BrieflyEventInfo.class);
|
|
|
- info.setTriggerTime(message.getTriggerTime());
|
|
|
+ info.setTriggerTime(eventInfo.getTriggerTime());
|
|
|
info.setCreateTime(LocalDateTime.now().format(formatter));
|
|
|
|
|
|
// 设置图片URL(如果有)
|
|
|
@@ -1104,20 +1145,18 @@ public class MqttService {
|
|
|
event.setUpdateTime(LocalDateTime.now());
|
|
|
|
|
|
// 处理图片信息
|
|
|
- if (message.getCollectionPic() != null) {
|
|
|
- CollectionEventMessage.PicInfo picInfo = message.getCollectionPic();
|
|
|
- if (picInfo != null && StrUtil.isNotBlank(picInfo.getUrl()) && StrUtil.isNotBlank(picInfo.getPath())) {
|
|
|
- SasPic pic = new SasPic();
|
|
|
- pic.setId(IdUtil.randomUUID());
|
|
|
- pic.setUrl(picInfo.getUrl());
|
|
|
- pic.setPath(picInfo.getPath());
|
|
|
- pic.setCreateTime(LocalDateTime.now());
|
|
|
- pic.setUpdateTime(LocalDateTime.now());
|
|
|
- sasPicMapper.insert(pic);
|
|
|
-
|
|
|
- // 设置事件图片ID
|
|
|
- event.setPicId(pic.getId());
|
|
|
- }
|
|
|
+ if (message.getScenePicInfo() != null) {
|
|
|
+ SasPic bean = (SasPic)BeanUtil.toBean(message.getScenePicInfo(), SasPic.class);
|
|
|
+ bean.setId(IdUtil.randomUUID());
|
|
|
+ this.sasPicMapper.insert(bean);
|
|
|
+ event.setScenePicId(bean.getId());
|
|
|
+ }
|
|
|
+
|
|
|
+ if (message.getEventPicInfo() != null) {
|
|
|
+ SasPic bean = (SasPic)BeanUtil.toBean(message.getEventPicInfo(), SasPic.class);
|
|
|
+ bean.setId(IdUtil.randomUUID());
|
|
|
+ this.sasPicMapper.insert(bean);
|
|
|
+ event.setPicId(bean.getId());
|
|
|
}
|
|
|
|
|
|
collectionEventService.save(event);
|
|
|
@@ -1127,11 +1166,12 @@ public class MqttService {
|
|
|
info.setCreateTime(LocalDateTime.now().format(formatter));
|
|
|
|
|
|
// 设置图片URL(如果有)
|
|
|
- if (event.getPicId() != null) {
|
|
|
- SasPic pic = sasPicMapper.selectById(event.getPicId());
|
|
|
- if (pic != null && StrUtil.isNotBlank(pic.getUrl()) && StrUtil.isNotBlank(pic.getPath())) {
|
|
|
- info.setEventUrl(pic.getUrl() + pic.getPath());
|
|
|
- }
|
|
|
+ if (message.getEventPicInfo() != null) {
|
|
|
+ info.setEventUrl(message.getEventPicInfo().getUrl() + message.getEventPicInfo().getPath());
|
|
|
+ }
|
|
|
+
|
|
|
+ if (message.getScenePicInfo() != null) {
|
|
|
+ info.setEventUrl(message.getScenePicInfo().getUrl() + message.getScenePicInfo().getPath());
|
|
|
}
|
|
|
|
|
|
SasCollectionEventCode code = collectionEventCodeMapper.selectById(event.getEventCode());
|
|
|
@@ -1294,4 +1334,6 @@ public class MqttService {
|
|
|
log.error("断开MQTT连接失败", e);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
}
|