|
|
@@ -3,14 +3,12 @@ package com.xunmei.mediator.api.service.impl;
|
|
|
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
-import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.xunmei.common.core.constant.SecurityConstants;
|
|
|
-import com.xunmei.common.core.domain.iot.domain.IotDevice;
|
|
|
-import com.xunmei.common.core.domain.iot.domain.IotDvrDisk;
|
|
|
+import com.xunmei.common.core.constant.SystemParameterConstant;
|
|
|
import com.xunmei.common.core.domain.iot.domain.IotDvrHardDiskDetection;
|
|
|
import com.xunmei.common.core.domain.iot.domain.IotSensor;
|
|
|
import com.xunmei.common.core.domain.mediator.domain.IotAlarmData;
|
|
|
@@ -18,7 +16,6 @@ import com.xunmei.common.core.domain.mediator.domain.IotAlarmRuleExpress;
|
|
|
import com.xunmei.common.core.domain.mediator.domain.IotAlarmRuleSource;
|
|
|
import com.xunmei.common.core.domain.mediator.domain.IotAlarmSystemField;
|
|
|
import com.xunmei.common.core.domain.video.MediatorVideoDiagnosisRecord;
|
|
|
-import com.xunmei.common.core.enums.CategoryDataEnum;
|
|
|
import com.xunmei.common.core.utils.DateUtils;
|
|
|
import com.xunmei.common.core.utils.StringUtils;
|
|
|
import com.xunmei.mediator.api.enums.AlarmDataTypeEnum;
|
|
|
@@ -26,7 +23,9 @@ import com.xunmei.mediator.api.enums.AlarmRuleExpressOperateEnum;
|
|
|
import com.xunmei.mediator.api.enums.AlarmVideoTypeEnum;
|
|
|
import com.xunmei.mediator.api.mapper.*;
|
|
|
import com.xunmei.mediator.api.service.IotAlarmDataService;
|
|
|
+import com.xunmei.system.api.RemoteConfigService;
|
|
|
import com.xunmei.system.api.RemoteSmsService;
|
|
|
+import com.xunmei.system.api.domain.SysConfig;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
import lombok.Data;
|
|
|
import lombok.NoArgsConstructor;
|
|
|
@@ -65,10 +64,11 @@ public class IotAlarmDataServiceImpl extends ServiceImpl<IotAlarmDataMapper, Iot
|
|
|
private IotSensorMapper iotSensorMapper;
|
|
|
|
|
|
@Autowired
|
|
|
- private IotDeviceMapper iotDeviceMapper;
|
|
|
+ private RemoteConfigService remoteConfigService;
|
|
|
|
|
|
@Autowired
|
|
|
private RemoteSmsService remoteSmsService;
|
|
|
+
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
@Override
|
|
|
public void dealSensorData(IotSensor iotSensor) throws Exception {
|
|
|
@@ -95,9 +95,8 @@ public class IotAlarmDataServiceImpl extends ServiceImpl<IotAlarmDataMapper, Iot
|
|
|
//获取该设备对应的规则
|
|
|
int weekDay = DateUtil.thisDayOfWeek() - 1;
|
|
|
// 0 代表星期天, 规则表中星期天存的为7,需要做一下转换
|
|
|
- if(weekDay==0)
|
|
|
- {
|
|
|
- weekDay =7;
|
|
|
+ if (weekDay == 0) {
|
|
|
+ weekDay = 7;
|
|
|
}
|
|
|
System.out.println(weekDay);
|
|
|
QueryWrapper<IotAlarmRuleExpress> ruleExpress = new QueryWrapper<>();
|
|
|
@@ -139,41 +138,38 @@ public class IotAlarmDataServiceImpl extends ServiceImpl<IotAlarmDataMapper, Iot
|
|
|
this.saveBatch(list);
|
|
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
|
for (IotAlarmData alarm : list) {
|
|
|
- if(alarm.getSmsType()){
|
|
|
+ if (alarm.getSmsType()) {
|
|
|
//需要发送短信
|
|
|
LocalDateTime time = alarm.getTime();
|
|
|
String timeStr = time.format(formatter);
|
|
|
- remoteSmsService.sendSmsIot(iotSensor.getOrgId(),alarm.getContent(),timeStr);
|
|
|
+ remoteSmsService.sendSmsIot(iotSensor.getOrgId(), alarm.getContent(), timeStr);
|
|
|
}
|
|
|
}
|
|
|
- if (ObjectUtil.notEqual(iotSensor.getState(),1)) {
|
|
|
+ if (ObjectUtil.notEqual(iotSensor.getState(), 1)) {
|
|
|
iotSensor.setState(1);
|
|
|
iotSensor.setStateUpdateTime(LocalDateTime.now());
|
|
|
iotSensor.setStateStartTime(LocalDateTime.now());
|
|
|
iotSensorMapper.updateById(iotSensor);
|
|
|
}
|
|
|
- }
|
|
|
- else{
|
|
|
+ } else {
|
|
|
// 本次上传的设备状态数据 没有生成告警
|
|
|
if (isExpress && !isAlarm) {
|
|
|
//报警恢复
|
|
|
- if( alarms.size() != 0){
|
|
|
+ if (alarms.size() != 0) {
|
|
|
// 温湿度一个设备 存在同时2条告警的情况
|
|
|
- if(alarms.size()>1)
|
|
|
- {
|
|
|
+ if (alarms.size() > 1) {
|
|
|
for (IotAlarmData oldAlarm : alarms) {
|
|
|
oldAlarm.setEndTime(LocalDateTime.now());
|
|
|
this.updateById(oldAlarm);
|
|
|
}
|
|
|
- }
|
|
|
- else {
|
|
|
+ } else {
|
|
|
IotAlarmData iotAlarmData = alarms.get(0);
|
|
|
iotAlarmData.setEndTime(LocalDateTime.now());
|
|
|
this.updateById(iotAlarmData);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- if (ObjectUtil.notEqual(iotSensor.getState(),0)) {
|
|
|
+ if (ObjectUtil.notEqual(iotSensor.getState(), 0)) {
|
|
|
iotSensor.setStateUpdateTime(LocalDateTime.now());
|
|
|
iotSensor.setStateStartTime(LocalDateTime.now());
|
|
|
iotSensor.setState(0);
|
|
|
@@ -181,10 +177,8 @@ public class IotAlarmDataServiceImpl extends ServiceImpl<IotAlarmDataMapper, Iot
|
|
|
}
|
|
|
}
|
|
|
// 处理温湿度 一个设备 2 种告警, 可能会单个恢复的情况
|
|
|
- else if(isAlarm && isExpress)
|
|
|
- {
|
|
|
- if(ObjectUtil.notEqual(list.size(),alarms.size()))
|
|
|
- {
|
|
|
+ else if (isAlarm && isExpress) {
|
|
|
+ if (ObjectUtil.notEqual(list.size(), alarms.size())) {
|
|
|
List<IotAlarmData> noAlarmData = alarms.stream().filter(x -> !list.stream().anyMatch(y -> ObjectUtil.equal(y.getFieldCode(), x.getFieldCode()))).collect(Collectors.toList());
|
|
|
for (IotAlarmData oldAlarm : noAlarmData) {
|
|
|
oldAlarm.setEndTime(LocalDateTime.now());
|
|
|
@@ -218,40 +212,71 @@ public class IotAlarmDataServiceImpl extends ServiceImpl<IotAlarmDataMapper, Iot
|
|
|
//机构id
|
|
|
Long orgId = videoDiagnosis.getOrgId();
|
|
|
|
|
|
+
|
|
|
+ List<SysConfig> configList = getVideoDiagnosisSystemParamConfig();
|
|
|
+ SysConfig signalLostConfig = getConfig(configList, SystemParameterConstant.SIGNAL_LOST_ALARM);
|
|
|
+ SysConfig occludeConfig = getConfig(configList, SystemParameterConstant.OCCLUDE_ALARM);
|
|
|
+ SysConfig brightnessConfig = getConfig(configList, SystemParameterConstant.BRIGHTNESS_ALARM);
|
|
|
+ SysConfig colorCastConfig = getConfig(configList, SystemParameterConstant.COLOR_CAST_ALARM);
|
|
|
+ SysConfig snowflakeConfig = getConfig(configList, SystemParameterConstant.SNOWFLAKE_ALARM);
|
|
|
+ SysConfig stripeConfig = getConfig(configList, SystemParameterConstant.STRIPE_ALARM);
|
|
|
+ SysConfig contrastConfig = getConfig(configList, SystemParameterConstant.CONTRAST_ALARM);
|
|
|
+ SysConfig blurryConfig = getConfig(configList, SystemParameterConstant.BLURRY_ALARM);
|
|
|
+
|
|
|
//信号丢失 0: 正常 | 1:异常 1001
|
|
|
Integer signalLost = videoDiagnosis.getSignalLost();
|
|
|
- dealAlarmVideo(AlarmVideoTypeEnum.SIGNALLOST.getValue(), signalLost, deviceName, channelName, deviceId, orgId);
|
|
|
+ dealAlarmVideo(AlarmVideoTypeEnum.SIGNALLOST.getValue(), signalLost, deviceName, channelName, deviceId, orgId, signalLostConfig);
|
|
|
|
|
|
//遮挡 0: 正常 | 1:异常 1002
|
|
|
Integer occlude = videoDiagnosis.getOcclude();
|
|
|
- dealAlarmVideo(AlarmVideoTypeEnum.OCCLUDE.getValue(), occlude, deviceName, channelName, deviceId, orgId);
|
|
|
+ dealAlarmVideo(AlarmVideoTypeEnum.OCCLUDE.getValue(), occlude, deviceName, channelName, deviceId, orgId, occludeConfig);
|
|
|
|
|
|
//亮度 0: 正常 | 1:异常 1003
|
|
|
Integer brightness = videoDiagnosis.getBrightness();
|
|
|
- dealAlarmVideo(AlarmVideoTypeEnum.BRIGHTNESS.getValue(), brightness, deviceName, channelName, deviceId, orgId);
|
|
|
+ dealAlarmVideo(AlarmVideoTypeEnum.BRIGHTNESS.getValue(), brightness, deviceName, channelName, deviceId, orgId, brightnessConfig);
|
|
|
|
|
|
//偏色 0: 正常 | 1:异常 1004
|
|
|
Integer colorCast = videoDiagnosis.getColorCast();
|
|
|
- dealAlarmVideo(AlarmVideoTypeEnum.COLORCAST.getValue(), colorCast, deviceName, channelName, deviceId, orgId);
|
|
|
+ dealAlarmVideo(AlarmVideoTypeEnum.COLORCAST.getValue(), colorCast, deviceName, channelName, deviceId, orgId, colorCastConfig);
|
|
|
|
|
|
//雪花 0: 正常 | 1:异常 1005
|
|
|
Integer snowflake = videoDiagnosis.getSnowflake();
|
|
|
- dealAlarmVideo(AlarmVideoTypeEnum.SNOWFLAKE.getValue(), snowflake, deviceName, channelName, deviceId, orgId);
|
|
|
+ dealAlarmVideo(AlarmVideoTypeEnum.SNOWFLAKE.getValue(), snowflake, deviceName, channelName, deviceId, orgId, snowflakeConfig);
|
|
|
|
|
|
//条纹 0: 正常 | 1:异常 1006
|
|
|
Integer stripe = videoDiagnosis.getStripe();
|
|
|
- dealAlarmVideo(AlarmVideoTypeEnum.STRIPE.getValue(), stripe, deviceName, channelName, deviceId, orgId);
|
|
|
+ dealAlarmVideo(AlarmVideoTypeEnum.STRIPE.getValue(), stripe, deviceName, channelName, deviceId, orgId, stripeConfig);
|
|
|
|
|
|
//对比度 0: 正常 | 1:异常 1007
|
|
|
Integer contrast = videoDiagnosis.getContrast();
|
|
|
- dealAlarmVideo(AlarmVideoTypeEnum.CONTRAST.getValue(), contrast, deviceName, channelName, deviceId, orgId);
|
|
|
+ dealAlarmVideo(AlarmVideoTypeEnum.CONTRAST.getValue(), contrast, deviceName, channelName, deviceId, orgId, contrastConfig);
|
|
|
|
|
|
//模糊 0: 正常 | 1:异常 1008
|
|
|
Integer blurry = videoDiagnosis.getBlurry();
|
|
|
- dealAlarmVideo(AlarmVideoTypeEnum.BLURRY.getValue(), blurry, deviceName, channelName, deviceId, orgId);
|
|
|
+ dealAlarmVideo(AlarmVideoTypeEnum.BLURRY.getValue(), blurry, deviceName, channelName, deviceId, orgId, blurryConfig);
|
|
|
|
|
|
}
|
|
|
|
|
|
+ private List<SysConfig> getVideoDiagnosisSystemParamConfig() {
|
|
|
+ List<String> list = new ArrayList<>();
|
|
|
+ Collections.addAll(list,
|
|
|
+ SystemParameterConstant.SIGNAL_LOST_ALARM,
|
|
|
+ SystemParameterConstant.OCCLUDE_ALARM,
|
|
|
+ SystemParameterConstant.BRIGHTNESS_ALARM,
|
|
|
+ SystemParameterConstant.COLOR_CAST_ALARM,
|
|
|
+ SystemParameterConstant.SNOWFLAKE_ALARM,
|
|
|
+ SystemParameterConstant.STRIPE_ALARM,
|
|
|
+ SystemParameterConstant.CONTRAST_ALARM,
|
|
|
+ SystemParameterConstant.BLURRY_ALARM
|
|
|
+ );
|
|
|
+
|
|
|
+ return remoteConfigService.findConfigByCodeList(list, SecurityConstants.INNER);
|
|
|
+ }
|
|
|
+
|
|
|
+ private SysConfig getConfig(List<SysConfig> configList, String systemParamConstant) {
|
|
|
+ return configList.stream().filter(x -> ObjectUtil.equal(x.getConfigKey(), systemParamConstant)).findFirst().orElse(null);
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public void dealDvrDiskData(IotDvrHardDiskDetection iotDvrDisk) throws Exception {
|
|
|
@@ -314,14 +339,14 @@ public class IotAlarmDataServiceImpl extends ServiceImpl<IotAlarmDataMapper, Iot
|
|
|
return iotAlarmData;
|
|
|
}
|
|
|
|
|
|
- private void dealAlarmVideo(int diagnosisType, Integer diagnosisValue, String deviceName, String channelName, String deviceId, Long orgId) {
|
|
|
+ private void dealAlarmVideo(int diagnosisType, Integer diagnosisValue, String deviceName, String channelName, String deviceId, Long orgId, SysConfig sysConfig) {
|
|
|
|
|
|
QueryWrapper<IotAlarmData> qw = new QueryWrapper<>();
|
|
|
qw.lambda().eq(IotAlarmData::getDeviceId, deviceId).eq(IotAlarmData::getOrgId, orgId)
|
|
|
.eq(IotAlarmData::getSourceType, diagnosisType).isNull(IotAlarmData::getEndTime);
|
|
|
List<IotAlarmData> iots = baseMapper.selectList(qw);
|
|
|
-
|
|
|
- if (diagnosisValue == 1 && iots.size() == 0) {
|
|
|
+ //对于未配置需要告警的视频质量类型,不产生告警,但是允许将设备恢复正常,结束告警时间
|
|
|
+ if (diagnosisValue == 1 && iots.isEmpty() && (sysConfig != null && "1".equals(sysConfig.getConfigValue()))) {
|
|
|
/**
|
|
|
* 报警处理逻辑
|
|
|
* 1、判断报警表中是否有该类报警的数据;
|
|
|
@@ -334,7 +359,7 @@ public class IotAlarmDataServiceImpl extends ServiceImpl<IotAlarmDataMapper, Iot
|
|
|
|
|
|
|
|
|
}
|
|
|
- if (diagnosisValue == 0 && iots.size() > 0) {
|
|
|
+ if (diagnosisValue == 0 && !iots.isEmpty()) {
|
|
|
IotAlarmData iotAlarmData = iots.get(0);
|
|
|
iotAlarmData.setEndTime(LocalDateTime.now());
|
|
|
this.updateById(iotAlarmData);
|
|
|
@@ -354,7 +379,7 @@ public class IotAlarmDataServiceImpl extends ServiceImpl<IotAlarmDataMapper, Iot
|
|
|
//所以在判断此类规则的时候将值转为了BigDecimal进行判断; parseInt会在有小数的时候报错
|
|
|
if (AlarmRuleExpressOperateEnum.EQUALS.getText().equals(operator)) {
|
|
|
// sensorValue 存在为null的情况, deviceType和 infos.name 不对应的情况
|
|
|
- if (ObjectUtil.equal(sensorValue,settingValue)) {
|
|
|
+ if (ObjectUtil.equal(sensorValue, settingValue)) {
|
|
|
//对上了
|
|
|
iotAlarmData = builderAlarm(sensorValue, field, express, iotSensor);
|
|
|
}
|
|
|
@@ -403,11 +428,9 @@ public class IotAlarmDataServiceImpl extends ServiceImpl<IotAlarmDataMapper, Iot
|
|
|
IotAlarmData iotAlarmData = new IotAlarmData();
|
|
|
iotAlarmData.setAlarmValue("异常");
|
|
|
iotAlarmData.setTime(LocalDateTime.now());
|
|
|
- if(ObjectUtil.equal(deviceName,channelName)){
|
|
|
+ if (ObjectUtil.equal(deviceName, channelName)) {
|
|
|
iotAlarmData.setDeviceName(channelName);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
+ } else {
|
|
|
iotAlarmData.setDeviceName(deviceName + "-" + channelName);
|
|
|
}
|
|
|
iotAlarmData.setRuleId(1L);
|