|
@@ -15,6 +15,7 @@ import com.usky.sas.common.global.SasWebSocket;
|
|
|
import com.usky.sas.domain.*;
|
|
import com.usky.sas.domain.*;
|
|
|
import com.usky.sas.mapper.*;
|
|
import com.usky.sas.mapper.*;
|
|
|
import com.usky.sas.mqtt.dto.*;
|
|
import com.usky.sas.mqtt.dto.*;
|
|
|
|
|
+import com.usky.sas.mqtt.dto.EntranceEventInfoVo;
|
|
|
import com.usky.sas.service.*;
|
|
import com.usky.sas.service.*;
|
|
|
import com.usky.sas.service.dto.agbox.JsonRpcRequest;
|
|
import com.usky.sas.service.dto.agbox.JsonRpcRequest;
|
|
|
import com.usky.sas.service.vo.*;
|
|
import com.usky.sas.service.vo.*;
|
|
@@ -479,73 +480,39 @@ public class MqttService {
|
|
|
message.setEventCode(root.get("code").asInt());
|
|
message.setEventCode(root.get("code").asInt());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- SasDevice device = findDevice(message.getDeviceId(), SystemTypeCodeEnum.entrance.getCode());
|
|
|
|
|
- if (device == null) {
|
|
|
|
|
- log.warn("设备不存在,丢弃门禁事件: deviceId={}", message.getDeviceId());
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- SasEntranceEvent event = new SasEntranceEvent();
|
|
|
|
|
- String eventId = message.getId() != null && !message.getId().isEmpty()
|
|
|
|
|
- ? message.getId()
|
|
|
|
|
- : IdUtil.randomUUID();
|
|
|
|
|
- // 如果该事件已存在(设备重发/重复消息),避免主键冲突,直接跳过
|
|
|
|
|
- if (entranceEventService.getById(eventId) != null) {
|
|
|
|
|
- log.info("门禁事件已存在, 跳过保存, eventId={}", eventId);
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
- event.setEventId(eventId);
|
|
|
|
|
- BeanUtil.copyProperties(message, event, "eventId");
|
|
|
|
|
- event.setCardId(message.getIcId());
|
|
|
|
|
- event.setTriggerTime(parseTime(message.getTriggerTime()));
|
|
|
|
|
- event.setCreateTime(LocalDateTime.now());
|
|
|
|
|
- event.setUpdateTime(LocalDateTime.now());
|
|
|
|
|
-
|
|
|
|
|
- // 处理图片信息
|
|
|
|
|
- if (message.getEntrancePic() != null) {
|
|
|
|
|
- EntranceEventMessage.PicInfo picInfo = message.getEntrancePic();
|
|
|
|
|
- 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());
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ // 【HTTP增强】尝试通过HTTP获取详细信息
|
|
|
|
|
+ SasConfig config = sasConfigService.getConfig();
|
|
|
|
|
+ if (config != null && StrUtil.isNotBlank(config.getHost()) && StrUtil.isNotBlank(config.getKeyds())) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
|
|
+ map.put("eventId", message.getId());
|
|
|
|
|
+ JsonRpcRequest getEntranceEventInfoJson = new JsonRpcRequest("getEvent", map, (Long)null);
|
|
|
|
|
+ Map<String, Object> getEntranceEventInfo = new HashMap<>();
|
|
|
|
|
+ getEntranceEventInfo.put("key", config.getKeyds());
|
|
|
|
|
+ getEntranceEventInfo.put("json", getEntranceEventInfoJson.toString());
|
|
|
|
|
+ log.info("【门禁】请求AG详细信息报文:{}", JSONUtil.toJsonStr(getEntranceEventInfo));
|
|
|
|
|
|
|
|
- entranceEventService.save(event);
|
|
|
|
|
|
|
+ String resultEvent = HttpUtil.post(config.getHost() + "/agbox/device/entrance", getEntranceEventInfo);
|
|
|
|
|
+ log.info("【门禁】请求AG响应:{}", resultEvent);
|
|
|
|
|
|
|
|
- BrieflyEventInfo info = BeanUtil.toBean(event, BrieflyEventInfo.class);
|
|
|
|
|
- info.setTriggerTime(message.getTriggerTime());
|
|
|
|
|
- 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 (StrUtil.isNotBlank(resultEvent)) {
|
|
|
|
|
+ EntranceEventInfoVo entranceEventInfoVo = mapper.readValue(resultEvent, EntranceEventInfoVo.class);
|
|
|
|
|
+ if (entranceEventInfoVo != null && entranceEventInfoVo.getResult() != null && entranceEventInfoVo.getResult().getEventInfo() != null) {
|
|
|
|
|
+ // HTTP获取成功,使用详细信息处理
|
|
|
|
|
+ EntranceEventInfo eventInfo = entranceEventInfoVo.getResult().getEventInfo();
|
|
|
|
|
+ processEntranceEventWithHttpInfo(eventInfo, message);
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (Exception httpEx) {
|
|
|
|
|
+ log.warn("【门禁】HTTP获取详细信息失败,降级到MQTT处理:{}", httpEx.getMessage());
|
|
|
|
|
+ // 降级到MQTT处理
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- SasEntranceEventCode code = entranceEventCodeMapper.selectById(event.getEventCode());
|
|
|
|
|
- if (code != null) {
|
|
|
|
|
- info.setEventTypeName(code.getName());
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- enrichDeviceInfo(info, device);
|
|
|
|
|
- SasEventTypeGroup eventTypeGroup = findEventTypeGroup(SystemTypeCodeEnum.entrance.getCode());
|
|
|
|
|
- if (eventTypeGroup != null) {
|
|
|
|
|
- info.setEventLevelId(eventTypeGroup.getEventLevel());
|
|
|
|
|
- }
|
|
|
|
|
- info.setDeviceType(SystemTypeCodeEnum.entrance.getCode());
|
|
|
|
|
- SasWebSocket.sendAll(info);
|
|
|
|
|
-
|
|
|
|
|
- log.info("门禁事件保存并推送成功, eventId={}", event.getEventId());
|
|
|
|
|
|
|
+ // MQTT基础处理(降级方案)
|
|
|
|
|
+ log.info("【门禁】使用MQTT基础信息处理");
|
|
|
|
|
+ processEntranceEventWithMqttInfo(message);
|
|
|
} else if ("heart".equals(method)) {
|
|
} else if ("heart".equals(method)) {
|
|
|
handleHeartbeat(payload, SystemTypeCodeEnum.entrance.getCode());
|
|
handleHeartbeat(payload, SystemTypeCodeEnum.entrance.getCode());
|
|
|
}
|
|
}
|
|
@@ -1556,9 +1523,168 @@ public class MqttService {
|
|
|
info.setDeviceType(SystemTypeCodeEnum.parking.getCode());
|
|
info.setDeviceType(SystemTypeCodeEnum.parking.getCode());
|
|
|
SasWebSocket.sendAll(info);
|
|
SasWebSocket.sendAll(info);
|
|
|
|
|
|
|
|
- } catch (Exception e) {
|
|
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
log.error("【车辆抓拍-MQTT】处理失败", e);
|
|
log.error("【车辆抓拍-MQTT】处理失败", e);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 使用HTTP获取的详细信息处理门禁事件
|
|
|
|
|
+ */
|
|
|
|
|
+ private void processEntranceEventWithHttpInfo(EntranceEventInfo eventInfo, EntranceEventMessage mqttMessage) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ SasDevice device = findDevice(eventInfo.getDeviceId(), SystemTypeCodeEnum.entrance.getCode());
|
|
|
|
|
+ if (device == null) {
|
|
|
|
|
+ log.warn("【门禁-HTTP】设备不存在,丢弃事件:deviceId={}", eventInfo.getDeviceId());
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ String eventId = StrUtil.isNotBlank(eventInfo.getId()) ? eventInfo.getId() :
|
|
|
|
|
+ (StrUtil.isNotBlank(mqttMessage.getId()) ? mqttMessage.getId() : IdUtil.randomUUID());
|
|
|
|
|
+ if (entranceEventService.getById(eventId) != null) {
|
|
|
|
|
+ log.info("【门禁-HTTP】事件已存在,跳过保存:eventId={}", eventId);
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ SasEntranceEvent event = new SasEntranceEvent();
|
|
|
|
|
+ event.setEventId(eventId);
|
|
|
|
|
+
|
|
|
|
|
+ // 从HTTP响应中获取详细信息
|
|
|
|
|
+ BeanUtil.copyProperties(eventInfo, event);
|
|
|
|
|
+ event.setCardId(eventInfo.getCardId());
|
|
|
|
|
+ event.setTriggerTime(parseTime(eventInfo.getTriggerTime()));
|
|
|
|
|
+ event.setCreateTime(LocalDateTime.now());
|
|
|
|
|
+ event.setUpdateTime(LocalDateTime.now());
|
|
|
|
|
+
|
|
|
|
|
+ // 处理HTTP中的图片信息
|
|
|
|
|
+ if (eventInfo.getEventPic() != null) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ SasPic pic = new SasPic();
|
|
|
|
|
+ pic.setUrl(eventInfo.getEventPic().getUrl());
|
|
|
|
|
+ pic.setPath(eventInfo.getEventPic().getPath());
|
|
|
|
|
+ pic.setId(IdUtil.randomUUID());
|
|
|
|
|
+ pic.setCreateTime(LocalDateTime.now());
|
|
|
|
|
+ pic.setUpdateTime(LocalDateTime.now());
|
|
|
|
|
+ sasPicMapper.insert(pic);
|
|
|
|
|
+ event.setPicId(pic.getId());
|
|
|
|
|
+ log.info("【门禁-HTTP】图片保存成功,picId={}", pic.getId());
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ log.error("【门禁-HTTP】图片保存失败", e);
|
|
|
|
|
+ // 图片保存失败不影响主流程
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 保存到数据库
|
|
|
|
|
+ entranceEventService.save(event);
|
|
|
|
|
+ log.info("【门禁-HTTP】保存成功!eventId={}, deviceId={}, eventCode={}",
|
|
|
|
|
+ eventId, eventInfo.getDeviceId(), eventInfo.getEventCode());
|
|
|
|
|
+
|
|
|
|
|
+ // WebSocket推送
|
|
|
|
|
+ BrieflyEventInfo info = BeanUtil.toBean(event, BrieflyEventInfo.class);
|
|
|
|
|
+ info.setTriggerTime(eventInfo.getTriggerTime());
|
|
|
|
|
+ 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());
|
|
|
|
|
+ log.debug("【门禁-HTTP】图片URL设置成功:{}", info.getEventUrl());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ SasEntranceEventCode code = entranceEventCodeMapper.selectById(eventInfo.getEventCode());
|
|
|
|
|
+ if (code != null) {
|
|
|
|
|
+ info.setEventTypeName(code.getName());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ enrichDeviceInfo(info, device);
|
|
|
|
|
+ SasEventTypeGroup eventTypeGroup = findEventTypeGroup(SystemTypeCodeEnum.entrance.getCode());
|
|
|
|
|
+ if (eventTypeGroup != null) {
|
|
|
|
|
+ info.setEventLevelId(eventTypeGroup.getEventLevel());
|
|
|
|
|
+ }
|
|
|
|
|
+ info.setDeviceType(SystemTypeCodeEnum.entrance.getCode());
|
|
|
|
|
+ SasWebSocket.sendAll(info);
|
|
|
|
|
+
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ log.error("【门禁-HTTP】处理失败", e);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 使用MQTT基础信息处理门禁事件(降级方案)
|
|
|
|
|
+ */
|
|
|
|
|
+ private void processEntranceEventWithMqttInfo(EntranceEventMessage message) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ SasDevice device = findDevice(message.getDeviceId(), SystemTypeCodeEnum.entrance.getCode());
|
|
|
|
|
+ if (device == null) {
|
|
|
|
|
+ log.warn("【门禁-MQTT】设备不存在,丢弃门禁事件: deviceId={}", message.getDeviceId());
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ SasEntranceEvent event = new SasEntranceEvent();
|
|
|
|
|
+ String eventId = message.getId() != null && !message.getId().isEmpty()
|
|
|
|
|
+ ? message.getId()
|
|
|
|
|
+ : IdUtil.randomUUID();
|
|
|
|
|
+ // 如果该事件已存在(设备重发/重复消息),避免主键冲突,直接跳过
|
|
|
|
|
+ if (entranceEventService.getById(eventId) != null) {
|
|
|
|
|
+ log.info("【门禁-MQTT】门禁事件已存在, 跳过保存, eventId={}", eventId);
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ event.setEventId(eventId);
|
|
|
|
|
+ BeanUtil.copyProperties(message, event, "eventId");
|
|
|
|
|
+ event.setCardId(message.getIcId());
|
|
|
|
|
+ event.setTriggerTime(parseTime(message.getTriggerTime()));
|
|
|
|
|
+ event.setCreateTime(LocalDateTime.now());
|
|
|
|
|
+ event.setUpdateTime(LocalDateTime.now());
|
|
|
|
|
+
|
|
|
|
|
+ // 处理图片信息
|
|
|
|
|
+ if (message.getEntrancePic() != null) {
|
|
|
|
|
+ EntranceEventMessage.PicInfo picInfo = message.getEntrancePic();
|
|
|
|
|
+ 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());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ entranceEventService.save(event);
|
|
|
|
|
+
|
|
|
|
|
+ BrieflyEventInfo info = BeanUtil.toBean(event, BrieflyEventInfo.class);
|
|
|
|
|
+ info.setTriggerTime(message.getTriggerTime());
|
|
|
|
|
+ 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());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ SasEntranceEventCode code = entranceEventCodeMapper.selectById(event.getEventCode());
|
|
|
|
|
+ if (code != null) {
|
|
|
|
|
+ info.setEventTypeName(code.getName());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ enrichDeviceInfo(info, device);
|
|
|
|
|
+ SasEventTypeGroup eventTypeGroup = findEventTypeGroup(SystemTypeCodeEnum.entrance.getCode());
|
|
|
|
|
+ if (eventTypeGroup != null) {
|
|
|
|
|
+ info.setEventLevelId(eventTypeGroup.getEventLevel());
|
|
|
|
|
+ }
|
|
|
|
|
+ info.setDeviceType(SystemTypeCodeEnum.entrance.getCode());
|
|
|
|
|
+ SasWebSocket.sendAll(info);
|
|
|
|
|
+
|
|
|
|
|
+ log.info("【门禁-MQTT】门禁事件保存并推送成功, eventId={}", event.getEventId());
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ log.error("【门禁-MQTT】处理门禁事件失败", e);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|