|
|
@@ -34,6 +34,7 @@ import com.zd.model.entity.SysFile;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.data.redis.connection.Message;
|
|
|
import org.springframework.data.redis.listener.KeyExpirationEventMessageListener;
|
|
|
import org.springframework.data.redis.listener.RedisMessageListenerContainer;
|
|
|
@@ -96,6 +97,12 @@ public class RedisExpiredPhotographListener extends KeyExpirationEventMessageLis
|
|
|
@Autowired
|
|
|
private RemoteMessageService remoteMessageService;
|
|
|
|
|
|
+ private final String testFormat = "【实验室安全智能】{}发生{}{}";
|
|
|
+ private final String streamUrlFormat = "rtsp://admin:hk123456@{}:554/h264/ch1/main/av_stream";
|
|
|
+
|
|
|
+ @Value("${file.path}")
|
|
|
+ private String rootPath;
|
|
|
+
|
|
|
/**
|
|
|
* Creates new {@link MessageListener} for {@code __keyevent@*__:expired} messages.
|
|
|
*
|
|
|
@@ -111,39 +118,56 @@ public class RedisExpiredPhotographListener extends KeyExpirationEventMessageLis
|
|
|
if (key.indexOf(BaseConstants.PHOTOGRAPH_QUEUE) != -1) {
|
|
|
log.info("预警异常,缓存信息:" + key);
|
|
|
String[] keyStr = key.split("~");
|
|
|
- WarningNoticeLog warningNoticeLog = JSON.parseObject(JSON.toJSONString(JSON.parseObject(keyStr[1]).getJSONObject("photographQueue")), WarningNoticeLog.class);
|
|
|
+ WarningNoticeLog warningNoticeLog = JSON.parseObject(JSON.toJSONString(JSON.parseObject(keyStr[1]).getJSONObject(BaseConstants.PHOTOGRAPH_QUEUE)), WarningNoticeLog.class);
|
|
|
//调用拍摄照片接口
|
|
|
LabHardware labHardware = labHardwareService.findCameraByType(warningNoticeLog.getSubId(), 4, "1");
|
|
|
if (labHardware != null && StringUtils.isNotBlank(labHardware.getIpAddress())) {
|
|
|
//拼装StreamUrl
|
|
|
- String streamUrl = "rtsp://admin:hk123456@" + labHardware.getIpAddress() + ":554/h264/ch1/main/av_stream";
|
|
|
- R<SysFile> fileR = remoteForwardService.photograph(streamUrl);
|
|
|
+ String streamUrl = StrUtil.format(streamUrlFormat,labHardware.getIpAddress());
|
|
|
+ R<SysFile> fileR = remoteForwardService.photograph(streamUrl);
|
|
|
log.info("文件上传状态:{},接口返回消息:{},文件上传路径:{}", fileR.getCode(), fileR.getMsg(), fileR.getData());
|
|
|
//调用照片到算法服务,返回结果
|
|
|
AlgorithmWarningBo algorithmWarningBo = new AlgorithmWarningBo();
|
|
|
- algorithmWarningBo.setId(warningNoticeLog.getId());
|
|
|
algorithmWarningBo.setSubId(warningNoticeLog.getSubId());
|
|
|
algorithmWarningBo.setSubName(warningNoticeLog.getSubName());
|
|
|
- algorithmWarningBo.setFile(fileR.getData().getMultipartFile());
|
|
|
+ algorithmWarningBo.setId(warningNoticeLog.getId());
|
|
|
+ algorithmWarningBo.setFileUrl(fileR.getData().getUrl());
|
|
|
+ //algorithmWarningBo.setFileUrl("d:\\test.jpg");
|
|
|
ResultData resultData = remoteForwardService.warningCheck(algorithmWarningBo);
|
|
|
if (HttpStatus.SUCCESS == resultData.getCode()) {
|
|
|
- AlgorithmWarningVo algorithmWarningVo = JSON.parseObject(JSONObject.toJSONString(resultData.getData()), AlgorithmWarningVo.class);
|
|
|
- WarningDetail warningDetail = new WarningDetail();
|
|
|
- warningDetail.setLogId(warningNoticeLog.getId());
|
|
|
- warningDetail.setSubId(warningNoticeLog.getSubId());
|
|
|
- //预警类型(1预案抓拍 2穿戴抓拍)
|
|
|
-// warningDetail.setType(2);
|
|
|
- warningDetail.setPhotoUrl(fileR.getData().getUrl());
|
|
|
+ //算法调用 默认返回成功!
|
|
|
+ //if (HttpStatus.SUCCESS != 200) {
|
|
|
+ log.error("调用算法服务失败!{}",resultData);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ AlgorithmWarningVo algorithmWarningVo = JSON.parseObject(JSONObject.toJSONString(resultData.getData()), AlgorithmWarningVo.class);
|
|
|
+
|
|
|
+ //==========================test code 算法调用 默认返回异常假数据=========================
|
|
|
+ //AlgorithmWarningVo algorithmWarningVo = new AlgorithmWarningVo();
|
|
|
+ //algorithmWarningVo.setOriginalImage("/statics/2023/06/27/8897e540-481d-4731-a199-29bb1a9ad30f.jpg");
|
|
|
+ //algorithmWarningVo.setIsAlert(Boolean.TRUE);
|
|
|
+ //algorithmWarningVo.setId(warningNoticeLog.getId());
|
|
|
+ //==========================test code 算法调用 默认返回异常假数据=========================
|
|
|
+
|
|
|
+
|
|
|
+ WarningDetail warningDetail = new WarningDetail();
|
|
|
+ warningDetail.setLogId(warningNoticeLog.getId());
|
|
|
+ warningDetail.setSubId(warningNoticeLog.getSubId());
|
|
|
+ //预警类型(1预案抓拍 2穿戴抓拍)
|
|
|
+ //warningDetail.setType(2);
|
|
|
+ warningDetail.setPhotoUrl(fileR.getData().getUrl());
|
|
|
+ if(algorithmWarningVo.getIsAlert()){
|
|
|
warningDetail.setCallbackPhotoUrl(algorithmWarningVo.getResultImage());
|
|
|
- warningDetail.setResult(algorithmWarningVo.getIsAlert());
|
|
|
- warningDetail.setCreateTime(LocalDateTime.now());
|
|
|
- warningDetailService.save(warningDetail);
|
|
|
}
|
|
|
+ warningDetail.setResult(algorithmWarningVo.getIsAlert());
|
|
|
+ warningDetail.setCreateTime(LocalDateTime.now());
|
|
|
+ warningDetailService.save(warningDetail);
|
|
|
|
|
|
+ StringBuffer userIds = new StringBuffer();
|
|
|
+ StringBuffer phones = new StringBuffer();
|
|
|
if (!redisService.hasKey(key)) {
|
|
|
//如果没有这个key了 则统计异常率
|
|
|
//查询配置
|
|
|
- long count1 = warningNoticeLogService.count(new LambdaQueryWrapper<WarningNoticeLog>().eq(WarningNoticeLog::getSubId, warningNoticeLog.getSubId()));
|
|
|
WarningConfig warningConfig = warningConfigService.getOne(new LambdaQueryWrapper<WarningConfig>().eq(WarningConfig::getWarningType, 1));
|
|
|
List<WarningDetail> list = warningDetailService.list(new LambdaQueryWrapper<WarningDetail>().eq(WarningDetail::getLogId, warningNoticeLog.getId()));
|
|
|
if (list.size() > 0) {
|
|
|
@@ -152,14 +176,13 @@ public class RedisExpiredPhotographListener extends KeyExpirationEventMessageLis
|
|
|
if (div > warningConfig.getAnomalyRate()) {
|
|
|
|
|
|
WarningNoticeLogDto warningNoticeLogDto = new WarningNoticeLogDto();
|
|
|
+ warningNoticeLogDto.setId(warningNoticeLog.getId());
|
|
|
warningNoticeLogDto.setWarningType(1);
|
|
|
warningNoticeLogDto.setWarningContent("未穿戴实验服");
|
|
|
warningNoticeLogDto.setWarningTime(LocalDateTime.now());
|
|
|
warningNoticeLogDto.setWarningWay(warningConfig.getIllegalRemoval());
|
|
|
//查询到实验室负责人id 安全责任人id
|
|
|
List<CheckSubjectDto> subjectInfoList = labSubjectService.findSubjectInfoList(String.valueOf(warningNoticeLog.getSubId()));
|
|
|
- StringBuffer userIds = new StringBuffer();
|
|
|
- StringBuffer phones = new StringBuffer();
|
|
|
if (subjectInfoList.size() > 0) {
|
|
|
CheckSubjectDto i = subjectInfoList.get(0);
|
|
|
warningNoticeLogDto.setSubId(i.getSubId());
|
|
|
@@ -168,69 +191,73 @@ public class RedisExpiredPhotographListener extends KeyExpirationEventMessageLis
|
|
|
warningNoticeLogDto.setFloorId(i.getFloorId());
|
|
|
warningNoticeLogDto.setFloorName(i.getFloorName());
|
|
|
warningNoticeLogDto.setRoomNum(i.getRoomNumber());
|
|
|
+ warningNoticeLogDto.setIsDeleted(Boolean.FALSE);
|
|
|
userIds.append(i.getSafeUserId()).append(",").append(i.getAdminId());
|
|
|
phones.append(i.getAdminPhone()).append(",").append(i.getSafeUserPhone());
|
|
|
}
|
|
|
- ResultData result = remoteLaboratoryService.addWarningNoticeLog(warningNoticeLogDto);
|
|
|
+ ResultData result = remoteLaboratoryService.updateWarningNoticeLog(warningNoticeLogDto);
|
|
|
if (HttpStatus.SUCCESS == result.getCode()) {
|
|
|
log.info("未穿戴实验服保存日志成功!");
|
|
|
}
|
|
|
- ResultData urlScheme = remoteMessageService.getUrlScheme(Long.valueOf(String.valueOf(result.getData())));
|
|
|
- if(urlScheme.getCode() != HttpStatus.SUCCESS){
|
|
|
- log.error("获取urlScheme失败!");
|
|
|
- }
|
|
|
- String text = "【实验室安全系统】"+warningNoticeLogDto.getSubName()+"-监测到实验人员违规未穿戴实验服,请尽快确认。点击查看:https://lab.zjznai.com/labAppTest/earlyWarning/index.html?id="+result.getData()+"&urlScheme="+urlScheme.getData();
|
|
|
- //系统 短信 语音通知
|
|
|
- if (warningConfig.getSystemNotice() != null && count1 > warningConfig.getSystemNotice()) {
|
|
|
- //系统通知
|
|
|
- LabMessageContent labMessageContent = new LabMessageContent();
|
|
|
- labMessageContent.setSendMode(2);
|
|
|
- labMessageContent.setSendRange(3);
|
|
|
- labMessageContent.setMessClass(1);
|
|
|
- labMessageContent.setMessType(13);
|
|
|
- labMessageContent.setSubIds(String.valueOf(warningNoticeLog.getSubId()));
|
|
|
- labMessageContent.setUserIds(userIds.toString());
|
|
|
- labMessageContent.setContent(text);
|
|
|
- labMessageContentService.sendMessage(labMessageContent);
|
|
|
- }
|
|
|
- if (warningConfig.getMessageNotice() != null && count1 > warningConfig.getMessageNotice()) {
|
|
|
- //短信通知
|
|
|
- String[] strings = Stream.of(phones.toString().split(",")).filter(a -> StrUtil.isNotBlank(a)).collect(Collectors.joining(",")).split(",");
|
|
|
-
|
|
|
- if (strings != null) {
|
|
|
- AlarmEntrty alarmEntrty = new AlarmEntrty(Routes.NoticePush, strings, SendTypes.SMS.toString(), text);
|
|
|
- remoteAlarmService.send(alarmEntrty);
|
|
|
- log.info("未穿戴实验服发送短信打电话消息推送完成!");
|
|
|
- }
|
|
|
- }
|
|
|
- if (warningConfig.getVoiceNotcie() != null && count1 > warningConfig.getVoiceNotcie()) {
|
|
|
- //短信通知
|
|
|
- log.info("打开喇叭-远程调用查询喇叭列表,实验室id={}", warningNoticeLog.getSubId());
|
|
|
- Integer count = labSparseHardwareService.selectSpeakerCount();
|
|
|
- R deviceList = remoteSpeakService.getDeviceList(1, count + 10, -99L, warningNoticeLog.getSubId());
|
|
|
- log.info("打开喇叭-远程调用喇叭列表返回内容: deviceList={}", JSON.toJSONString(deviceList));
|
|
|
- if (deviceList.getCode() == 200) {
|
|
|
- List<PlayVo> playVoList = new ArrayList<>();
|
|
|
- List<Map<String, Object>> mapList = (List<Map<String, Object>>) deviceList.getData();
|
|
|
- for (Map<String, Object> map : mapList) {
|
|
|
- if (com.zd.common.core.utils.StringUtils.isNotNull(map.get("deviceSn")) && com.zd.common.core.utils.StringUtils.isNotNull(map.get("port"))) {
|
|
|
- PlayVo playVo = new PlayVo();
|
|
|
- playVo.setSn(map.get("deviceSn") + "");
|
|
|
- playVo.setDeviceIp(map.get("deviceIp") + "");
|
|
|
- playVo.setPort(Integer.parseInt(map.get("port") + ""));
|
|
|
- ParamVo paramVo = new ParamVo();
|
|
|
- paramVo.setVol(Integer.parseInt(map.get("deviceVol").toString()));
|
|
|
- playVo.setParams(paramVo);
|
|
|
- playVoList.add(playVo);
|
|
|
- } else {
|
|
|
- log.info("打开喇叭-喇叭deviceSn/port为空!");
|
|
|
- }
|
|
|
- }
|
|
|
- log.info("打开喇叭-远程调用喇叭播放音乐,playVoList={}", JSON.toJSONString(playVoList));
|
|
|
- R r = remoteSpeakService.textParseUrlIps("sss", playVoList);
|
|
|
- log.info("打开喇叭-远程调用喇叭播放音乐返回信息:{}", JSON.toJSONString(r));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //是否通知
|
|
|
+ long count1 = warningNoticeLogService.count(new LambdaQueryWrapper<WarningNoticeLog>().eq(WarningNoticeLog::getSubId, warningNoticeLog.getSubId()));
|
|
|
+ ResultData urlScheme = remoteMessageService.getUrlScheme(warningNoticeLog.getId());
|
|
|
+ if(urlScheme.getCode() != HttpStatus.SUCCESS){
|
|
|
+ log.error("获取urlScheme失败!");
|
|
|
+ }
|
|
|
+ String text = "【实验室安全系统】"+warningNoticeLog.getSubName()+"-监测到实验人员违规未穿戴实验服,请尽快确认。点击查看:https://lab.zjznai.com/labAppTest/earlyWarning/index.html?id="+warningNoticeLog.getId()+"&urlScheme="+urlScheme.getData();
|
|
|
+ //系统 短信 语音通知
|
|
|
+ if (warningConfig.getSystemNotice() != null && count1 > warningConfig.getSystemNotice()) {
|
|
|
+ //系统通知
|
|
|
+ LabMessageContent labMessageContent = new LabMessageContent();
|
|
|
+ labMessageContent.setSendMode(2);
|
|
|
+ labMessageContent.setSendRange(3);
|
|
|
+ labMessageContent.setMessClass(1);
|
|
|
+ labMessageContent.setMessType(13);
|
|
|
+ labMessageContent.setSubIds(String.valueOf(warningNoticeLog.getSubId()));
|
|
|
+ labMessageContent.setUserIds(userIds.toString());
|
|
|
+ labMessageContent.setContent(text);
|
|
|
+ labMessageContentService.sendMessage(labMessageContent);
|
|
|
+ }
|
|
|
+ if (warningConfig.getMessageNotice() != null && count1 > warningConfig.getMessageNotice()) {
|
|
|
+ //短信通知
|
|
|
+ String[] strings = Stream.of(phones.toString().split(",")).filter(a -> StrUtil.isNotBlank(a)).collect(Collectors.joining(",")).split(",");
|
|
|
+
|
|
|
+ if (strings != null) {
|
|
|
+ AlarmEntrty alarmEntrty = new AlarmEntrty(Routes.NoticePush, strings, SendTypes.SMS.toString(), text);
|
|
|
+ remoteAlarmService.send(alarmEntrty);
|
|
|
+ log.info("未穿戴实验服发送短信打电话消息推送完成!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (warningConfig.getVoiceNotcie() != null && count1 > warningConfig.getVoiceNotcie()) {
|
|
|
+ //短信通知
|
|
|
+ log.info("打开喇叭-远程调用查询喇叭列表,实验室id={}", warningNoticeLog.getSubId());
|
|
|
+ Integer count = labSparseHardwareService.selectSpeakerCount();
|
|
|
+ R deviceList = remoteSpeakService.getDeviceList(1, count + 10, -99L, warningNoticeLog.getSubId());
|
|
|
+ log.info("打开喇叭-远程调用喇叭列表返回内容: deviceList={}", JSON.toJSONString(deviceList));
|
|
|
+ if (deviceList.getCode() == 200) {
|
|
|
+ List<PlayVo> playVoList = new ArrayList<>();
|
|
|
+ List<Map<String, Object>> mapList = (List<Map<String, Object>>) deviceList.getData();
|
|
|
+ for (Map<String, Object> map : mapList) {
|
|
|
+ if (com.zd.common.core.utils.StringUtils.isNotNull(map.get("deviceSn")) && com.zd.common.core.utils.StringUtils.isNotNull(map.get("port"))) {
|
|
|
+ PlayVo playVo = new PlayVo();
|
|
|
+ playVo.setSn(map.get("deviceSn") + "");
|
|
|
+ playVo.setDeviceIp(map.get("deviceIp") + "");
|
|
|
+ playVo.setPort(Integer.parseInt(map.get("port") + ""));
|
|
|
+ ParamVo paramVo = new ParamVo();
|
|
|
+ paramVo.setVol(Integer.parseInt(map.get("deviceVol").toString()));
|
|
|
+ playVo.setParams(paramVo);
|
|
|
+ playVoList.add(playVo);
|
|
|
+ } else {
|
|
|
+ log.info("打开喇叭-喇叭deviceSn/port为空!");
|
|
|
}
|
|
|
}
|
|
|
+ log.info("打开喇叭-远程调用喇叭播放音乐,playVoList={}", JSON.toJSONString(playVoList));
|
|
|
+ R r = remoteSpeakService.textParseUrlIps("sss", playVoList);
|
|
|
+ log.info("打开喇叭-远程调用喇叭播放音乐返回信息:{}", JSON.toJSONString(r));
|
|
|
}
|
|
|
}
|
|
|
}
|