智巡告警阈值优化

This commit is contained in:
weitang 2025-05-09 09:40:59 +08:00
parent 02585710b1
commit 6759aeb774
9 changed files with 477 additions and 187 deletions

View File

@ -290,6 +290,9 @@ public class TaskResult implements Serializable {
*/ */
private String custom3; private String custom3;
/**
* <1>:=A <2>:=B <3>:=C 多个相位采用""分隔
*/
private String phase;
} }

View File

@ -206,5 +206,5 @@ public interface TaskResultMapper extends BaseMapper<TaskResult> {
List<Map<String, Object>> getValueByDeviceId(String deviceId); List<Map<String, Object>> getValueByDeviceId(String deviceId);
Page<Map<String, Object>> getResultByPatroldevice(Page<Map<String, Object>> page, String internationalId,String mainDeviceId, String taskName, String recognitionType, String valid,String isReport,String startDate,String endDate); Page<Map<String, Object>> getResultByPatroldevice(Page<Map<String, Object>> page, String internationalId,String mainDeviceId, String taskName, String recognitionType, String valid,String isReport,String startDate,String endDate);
List<TaskResult> getNonCoherentResult(String areaId,String bayId,String mainDeviceId,String componentId,String recognitionTypeList,String meterType,String resultId,String taskTodoId,String phase);
} }

View File

@ -26,14 +26,12 @@ import com.yfd.platform.modules.auxcontrol.domain.MeterDevice;
import com.yfd.platform.modules.auxcontrol.mapper.DeviceAlarmParameterMapper; import com.yfd.platform.modules.auxcontrol.mapper.DeviceAlarmParameterMapper;
import com.yfd.platform.modules.auxcontrol.mapper.DeviceSignalMapper; import com.yfd.platform.modules.auxcontrol.mapper.DeviceSignalMapper;
import com.yfd.platform.modules.auxcontrol.mapper.MeterDeviceMapper; import com.yfd.platform.modules.auxcontrol.mapper.MeterDeviceMapper;
import com.yfd.platform.modules.basedata.domain.LinkageSignal; import com.yfd.platform.modules.basedata.domain.*;
import com.yfd.platform.modules.basedata.domain.Substation;
import com.yfd.platform.modules.basedata.domain.SubstationDevice;
import com.yfd.platform.modules.basedata.domain.SubstationPatroldevice;
import com.yfd.platform.modules.basedata.mapper.LinkageSignalMapper; import com.yfd.platform.modules.basedata.mapper.LinkageSignalMapper;
import com.yfd.platform.modules.basedata.mapper.SubstationDeviceMapper; import com.yfd.platform.modules.basedata.mapper.SubstationDeviceMapper;
import com.yfd.platform.modules.basedata.mapper.SubstationMapper; import com.yfd.platform.modules.basedata.mapper.SubstationMapper;
import com.yfd.platform.modules.basedata.mapper.SubstationPatroldeviceMapper; import com.yfd.platform.modules.basedata.mapper.SubstationPatroldeviceMapper;
import com.yfd.platform.modules.basedata.service.IAlarmThresholdService;
import com.yfd.platform.modules.patroltask.domain.AlarmLog; import com.yfd.platform.modules.patroltask.domain.AlarmLog;
import com.yfd.platform.modules.patroltask.domain.TaskResult; import com.yfd.platform.modules.patroltask.domain.TaskResult;
import com.yfd.platform.modules.patroltask.domain.TaskTodo; import com.yfd.platform.modules.patroltask.domain.TaskTodo;
@ -133,6 +131,8 @@ public class AlarmLogServiceImpl extends ServiceImpl<AlarmLogMapper, AlarmLog> i
@Resource @Resource
private DeviceAlarmParameterMapper deviceAlarmParameterMapper; private DeviceAlarmParameterMapper deviceAlarmParameterMapper;
@Resource
private IAlarmThresholdService alarmThresholdService;
@Override @Override
public synchronized boolean updateTaskResult(JSONObject jsonObject) throws Exception { public synchronized boolean updateTaskResult(JSONObject jsonObject) throws Exception {
@ -446,17 +446,6 @@ public class AlarmLogServiceImpl extends ServiceImpl<AlarmLogMapper, AlarmLog> i
String filename = ""; String filename = "";
JSONArray posArray = new JSONArray(); JSONArray posArray = new JSONArray();
Map<String, Object> map = new HashMap<>(); Map<String, Object> map = new HashMap<>();
// String filePath1 = URLDecoder.decode(taskResult.getFilePath(), "utf-8");
// String fileName = StrUtil.subAfter(filePath1, "/", true).replace("_原图.jpg", ".txt").replace("_原图.jpeg", ".txt").replace("_原图.JPG", ".txt").replace("_原图.png", ".txt");
// 获取todo信息创建文件
// TaskTodo taskTodo = taskTodoMapper.selectById(taskResult.getTaskTodoId());
// String planStartTime = taskTodo.getPlanStartTime();
// DateTime date = DateUtil.parse(planStartTime);
// String dateFormat = DateUtil.format(date, "yyyyMMddHHmmss");
// String recognition = taskTodo.getTaskName() + dateFormat;
// String filePath = httpServerConfig.getSnapFilePath() + recognition + File.separator + fileName;
// File file = cn.hutool.core.io.FileUtil.touch(filePath);
// FileWriter writer = new FileWriter(file);
for (int a = 0; a < results.size(); a++) { for (int a = 0; a < results.size(); a++) {
JSONObject result = results.getJSONObject(a); JSONObject result = results.getJSONObject(a);
String code = result.getStr("code"); String code = result.getStr("code");
@ -471,11 +460,7 @@ public class AlarmLogServiceImpl extends ServiceImpl<AlarmLogMapper, AlarmLog> i
confList.add(conf); confList.add(conf);
} }
validList.add("1"); validList.add("1");
String posStr = "";
if (!"infrared".equals(result.getStr("type")) && !"sound".equals(result.getStr("type")) && !"yjsk".equals(result.getStr("type")) && !"isolator".equals(result.getStr("type"))) { if (!"infrared".equals(result.getStr("type")) && !"sound".equals(result.getStr("type")) && !"yjsk".equals(result.getStr("type")) && !"isolator".equals(result.getStr("type"))) {
//图片 排除声音
// filename = StrUtil.subAfter(URLDecoder.decode(result.getStr("resImagePath"), "utf-8"), "=",
// true);
filename = result.getStr("resImagePath"); filename = result.getStr("resImagePath");
String pos = result.getStr("pos"); String pos = result.getStr("pos");
// 将框坐标统一存储画框 // 将框坐标统一存储画框
@ -489,7 +474,6 @@ public class AlarmLogServiceImpl extends ServiceImpl<AlarmLogMapper, AlarmLog> i
JSONArray areas = jsonObject.getJSONArray("areas"); JSONArray areas = jsonObject.getJSONArray("areas");
JSONObject jsonObject1 = areas.getJSONObject(0); JSONObject jsonObject1 = areas.getJSONObject(0);
JSONObject jsonObject2 = areas.getJSONObject(1); JSONObject jsonObject2 = areas.getJSONObject(1);
posStr = " " + jsonObject1.getStr("x") + " " + jsonObject1.getStr("y") + " " + jsonObject2.getStr("x") + " " + jsonObject2.getStr("y");
} }
} }
@ -500,7 +484,6 @@ public class AlarmLogServiceImpl extends ServiceImpl<AlarmLogMapper, AlarmLog> i
String valueType = taskResult.getValueType(); String valueType = taskResult.getValueType();
Map<String, Object> judgeresult = judgeAbnormal(result.getStr("type"), result.getStr("value"), Map<String, Object> judgeresult = judgeAbnormal(result.getStr("type"), result.getStr("value"),
result.getStr("conf"), taskResult.getDeviceId(), taskResult.getResultId()); result.getStr("conf"), taskResult.getDeviceId(), taskResult.getResultId());
// || "yjsk".equals(result.getStr("type"))
log.info("=======================发送结果=======================" + result.getStr("type")); log.info("=======================发送结果=======================" + result.getStr("type"));
if (!("meter".equals(type) || "infrared".equals(type) || "sound".equals(type) || StrUtil.isBlank(type) || "yjsk".equals(result.getStr("type")) || "isolator".equals(result.getStr("type")))) { if (!("meter".equals(type) || "infrared".equals(type) || "sound".equals(type) || StrUtil.isBlank(type) || "yjsk".equals(result.getStr("type")) || "isolator".equals(result.getStr("type")))) {
// 图像缺陷分析类型 // 图像缺陷分析类型
@ -524,24 +507,28 @@ public class AlarmLogServiceImpl extends ServiceImpl<AlarmLogMapper, AlarmLog> i
} }
} else { } else {
log.info("==============================进入===========================" + result.getStr(
"type"));
valueList.add(value); valueList.add(value);
descList.add(desc); descList.add(desc);
desc = ""; desc = "";
} }
log.info("=========================================================" + judgeresult.get(
"isNormal").toString()); map.put("link_point", judgeresult.get("link_point"));
map.put("alarmAnalysisType", judgeresult.get("alarmAnalysisType"));
map.put("oldContent", judgeresult.get("oldContent"));
map.put("isSame", judgeresult.get("isSame"));
if (ObjectUtil.isNotEmpty(judgeresult.get("alarmlevel"))) {
map.put("alarmlevel", judgeresult.get("alarmlevel"));
}
if (ObjectUtil.isNotEmpty(judgeresult.get("alarmtype"))) {
map.put("alarmtype", judgeresult.get("alarmtype"));
}
//判定为异常 //判定为异常
// String resultStr = "";
if ("0".equals(judgeresult.get("isNormal").toString())) { if ("0".equals(judgeresult.get("isNormal").toString())) {
map.put("alarmlevel", judgeresult.get("alarmlevel")); map.put("alarmlevel", judgeresult.get("alarmlevel"));
//判定为异常 //判定为异常
validList.add("2"); validList.add("2");
// resultStr = result.getStr("type") + " " + result.getStr("conf") + posStr + "\n";
} }
// writer.write(resultStr);
if (StrUtil.isNotBlank(desc) && ("0".equals(judgeresult.get("isNormal").toString()) || valueType.contains("fhz") || valueType.contains("isolator"))) { if (StrUtil.isNotBlank(desc) && ("0".equals(judgeresult.get("isNormal").toString()) || valueType.contains("fhz") || valueType.contains("isolator"))) {
descList.add(desc); descList.add(desc);
} }
@ -552,7 +539,6 @@ public class AlarmLogServiceImpl extends ServiceImpl<AlarmLogMapper, AlarmLog> i
} }
} }
log.info("========================validList.toString()=================================" + validList.toString()); log.info("========================validList.toString()=================================" + validList.toString());
// writer.close();
// 识别成功 // 识别成功
taskResult.setValue(StrUtil.join(",", valueList)); taskResult.setValue(StrUtil.join(",", valueList));
String descJoin = StrUtil.join(",", descList); String descJoin = StrUtil.join(",", descList);
@ -1209,7 +1195,7 @@ public class AlarmLogServiceImpl extends ServiceImpl<AlarmLogMapper, AlarmLog> i
} }
//根据识别类型和结果值判断是否为异常 //根据识别类型和结果值判断是否为异常
private Map<String, Object> judgeAbnormal(String type, String value, String conf, String deviceid, private Map<String, Object> judgeAbnormal_bak(String type, String value, String conf, String deviceid,
String resultId) throws Exception { String resultId) throws Exception {
Map<String, Object> result = new HashMap<>(); Map<String, Object> result = new HashMap<>();
SubstationDevice substationDevice = deviceMapper.selectById(deviceid); SubstationDevice substationDevice = deviceMapper.selectById(deviceid);
@ -1217,6 +1203,9 @@ public class AlarmLogServiceImpl extends ServiceImpl<AlarmLogMapper, AlarmLog> i
JSONObject jsonObject = JSONUtil.parseObj(pictureAnalysisTypeList); JSONObject jsonObject = JSONUtil.parseObj(pictureAnalysisTypeList);
String pictureDefectAnalysisType = jsonObject.getStr("PictureDefectAnalysisType"); String pictureDefectAnalysisType = jsonObject.getStr("PictureDefectAnalysisType");
result.put("isNormal", "1"); result.put("isNormal", "1");
List<AlarmThreshold> list =
alarmThresholdService.list(new LambdaQueryWrapper<AlarmThreshold>().eq(AlarmThreshold::getDeviceId,
deviceid));
if (StrUtil.isNotBlank(pictureDefectAnalysisType)) { if (StrUtil.isNotBlank(pictureDefectAnalysisType)) {
// 缺陷告警设置 // 缺陷告警设置
// List<Map<String, Object>> mapList = sysDictionaryItemsService.getDeviceByType // List<Map<String, Object>> mapList = sysDictionaryItemsService.getDeviceByType
@ -1396,6 +1385,336 @@ public class AlarmLogServiceImpl extends ServiceImpl<AlarmLogMapper, AlarmLog> i
return result; return result;
} }
//根据识别类型和结果值判断是否为异常
private Map<String, Object> judgeAbnormal(String type, String value, String desc, String deviceid,
String resultId) {
Map<String, Object> result = new HashMap<>();
result.put("type", "0");
result.put("isNormal", "1");
result.put("link_point", deviceid);
if ("sound".equals(type)) {
if ("2".equals(value)) {
result.put("isNormal", "0");
result.put("alarmtype", "5");
}
return result;
}
if ("yjsk".equals(type)) {
if (!("1".equals(value) || "3".equals(value))) {
result.put("isNormal", "0");
}
return result;
}
List<AlarmThreshold> list =
alarmThresholdService.list(new LambdaQueryWrapper<AlarmThreshold>().eq(AlarmThreshold::getDeviceId,
deviceid));
SubstationDevice substationDevice = deviceMapper.selectById(deviceid);
TaskResult taskResult = taskResultMapper.selectById(resultId);
String pictureAnalysisTypeList = substationDevice.getPictureAnalysisTypeList();
JSONObject jsonObject = JSONUtil.parseObj(pictureAnalysisTypeList);
String pictureDefectAnalysisType = jsonObject.getStr("PictureDefectAnalysisType");
if (StrUtil.isNotBlank(pictureDefectAnalysisType)) {
// 缺陷告警设置
// List<Map<String, Object>> mapList = sysDictionaryItemsService.getDeviceByType
// ("PictureDefectAnalysisType");
if ("1".equals(value)) {
result.put("isNormal", "0");
result.put("alarmAnalysisType", "2");
}
return result;
}
String PictureDiscriminateAnalysisType = jsonObject.getStr("PictureDiscriminateAnalysisType");
if (StrUtil.isNotBlank(PictureDiscriminateAnalysisType)) {
if ("1".equals(value)) {
result.put("isNormal", "0");
result.put("type", "1");
result.put("alarmAnalysisType", "3");
}
return result;
}
if (list.size() <= 0) {
return result;
}
AlarmThreshold alarmThreshold = list.get(0);
if ("0".equals(alarmThreshold.getIsenable())) {
return result;
}
// 阈值类型或趋势类getStationInfo
if ("1".equals(alarmThreshold.getAlarmClass()) || "3".equals(alarmThreshold.getAlarmClass())) {
Map<String, String> map = alarmThresholdService.getThresholdInterval(alarmThreshold.getDeviceId());
if (map == null) {
return result;
}
String commonLower = map.get("commonLower");
String commonUpper = map.get("commonUpper");
String seriousLower = map.get("seriousLower");
String seriousUpper = map.get("seriousUpper");
String dangerLower = map.get("dangerLower");
String dangerUpper = map.get("dangerUpper");
List<String> valueList = StrUtil.split(value, ",");
double resultvalue = Double.parseDouble(valueList.get(0));
// 判断是否是非同源
String patroldeviceJson = substationDevice.getPatroldeviceJson();
if (JSONUtil.isTypeJSONArray(patroldeviceJson)) {
JSONArray jsonArray = JSONUtil.parseArray(patroldeviceJson);
if (jsonArray.size() > 1) {
// 非同源告警
LambdaQueryWrapper<TaskResult> queryWrapper = new LambdaQueryWrapper<>();
// TaskTodo taskTodo = taskTodoService.getById(taskResult.getResultId());
queryWrapper.eq(TaskResult::getDeviceId, deviceid).eq(TaskResult::getTaskTodoId,
taskResult.getTaskTodoId()).eq(TaskResult::getFlag, "2").ne(TaskResult::getResultId,
resultId);
List<TaskResult> taskResultList = taskResultMapper.selectList(queryWrapper);
Optional<TaskResult> maxDifferenceTaskResult =
taskResultList.stream().filter(t -> StrUtil.isNotBlank(t.getValue())).max(Comparator.comparingDouble(t -> Math.abs(NumberUtil.parseDouble(t.getValue()) - NumberUtil.parseDouble(value))));
if (maxDifferenceTaskResult.isPresent()) {
TaskResult oldResult = maxDifferenceTaskResult.get();
resultvalue = Math.abs(resultvalue - NumberUtil.parseDouble(oldResult.getValue()));
result.put("isSame", "1");
result.put("oldContent",
oldResult.getPatroldeviceName() + "设备识别结果为" + oldResult.getValue() + "");
} else {
return result;
}
}
if (jsonArray.size() == 1) {
// 非同源告警
LambdaQueryWrapper<TaskResult> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(TaskResult::getDeviceId, deviceid).eq(TaskResult::getTaskTodoId,
taskResult.getTaskTodoId()).eq(TaskResult::getFlag, "2").ne(TaskResult::getResultId,
resultId);
List<TaskResult> taskResultList = taskResultMapper.selectList(queryWrapper);
// List<String> values = taskResultList.stream().filter(v->StrUtil.isNotBlank
// (v.getValue())).map(TaskResult::getValue).collect(Collectors.toList());
Optional<TaskResult> maxDifferenceTaskResult =
taskResultList.stream().filter(t -> StrUtil.isNotBlank(t.getValue())).max(Comparator.comparingDouble(t -> Math.abs(NumberUtil.parseDouble(t.getValue()) - NumberUtil.parseDouble(value))));
if (maxDifferenceTaskResult.isPresent()) {
TaskResult oldResult = maxDifferenceTaskResult.get();
resultvalue = Math.abs(resultvalue - NumberUtil.parseDouble(oldResult.getValue()));
result.put("isSame", "1");
result.put("oldContent",
oldResult.getPatroldeviceName() + "设备识别结果为" + oldResult.getValue() + "");
} else {
return result;
}
}
}
// 三相温差告警仪表三项对比
if ("3".equals(alarmThreshold.getAlarmType()) || "9".equals(alarmThreshold.getAlarmType())) {
// 获取到不同相位的最新数据
List<TaskResult> nonCoherentResult =
taskResultMapper.getNonCoherentResult(taskResult.getAreaId(), taskResult.getBayId(),
taskResult.getMainDeviceId(), taskResult.getComponentId(),
taskResult.getRecognitionType(), substationDevice.getMeterType(),
taskResult.getResultId(), taskResult.getTaskTodoId(), taskResult.getPhase());
taskResult.setValue(value);
nonCoherentResult.add(taskResult);
if (nonCoherentResult.size() < 3) {
return result;
}
List<String> values =
nonCoherentResult.stream().filter(n -> ObjectUtil.isNotEmpty(n.getValue())).map(TaskResult::getValue).collect(Collectors.toList());
String max = CollectionUtil.max(values);
String min = CollectionUtil.min(values);
// 最大值减去最小值
resultvalue = NumberUtil.sub(Double.parseDouble(max), Double.parseDouble(min));
Map<String, String> phaseToValueMap = nonCoherentResult.stream()
.collect(Collectors.toMap(
TaskResult::getPhase,
TaskResult::getValue,
(existingValue, newValue) -> existingValue
));
String phaseA = phaseToValueMap.get("1");
String phaseB = phaseToValueMap.get("2");
String phaseC = phaseToValueMap.get("3");
result.put("oldContent", "[A]相结果" + phaseA + "" + "[B]相结果" + phaseB + "" + "[C]相结果" + phaseC +
"");
result.put("isSame", "0");
}
if ("3".equals(alarmThreshold.getAlarmClass())) {
// 对比趋势变化率
if ("1".equals(alarmThreshold.getIsLastContrast())) {
LambdaQueryWrapper<TaskResult> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(TaskResult::getDeviceId, deviceid).ne(TaskResult::getValue, "").isNotNull(TaskResult::getPatroldeviceDate).isNotNull(TaskResult::getValue).lt(TaskResult::getPatroldeviceDate,
taskResult.getPatroldeviceDate()).orderByDesc(TaskResult::getPatroldeviceDate).last(
"limit 0," +
"1");
List<TaskResult> taskResultList = taskResultMapper.selectList(queryWrapper);
if (taskResultList.size() <= 0) {
return result;
}
TaskResult taskResultBase = taskResultList.get(0);
// 基准值
double baseValue = Double.parseDouble(taskResultBase.getValue());
resultvalue = Math.abs(resultvalue - baseValue) / baseValue * 100;
result.put("oldContent", "点位上次识别结果为" + baseValue + "");
} else {
// 基准值
double alarmValue = Double.parseDouble(alarmThreshold.getBaseValue());
resultvalue = Math.abs(resultvalue - alarmValue) / alarmValue * 100;
result.put("oldContent", "点位基准值为" + alarmValue + "");
}
}
if (StrUtil.isNotBlank(commonLower) && StrUtil.isNotBlank(commonUpper)) {
if (NumberUtil.compare(resultvalue, Double.parseDouble(commonLower)) >= 0 && NumberUtil.compare(resultvalue,
Double.parseDouble(commonUpper)) < 0) {
result.put("alarmlevel", "1");
result.put("isNormal", "0");
result.put("alarmtype", alarmThreshold.getAlarmType());
}
}
if (StrUtil.isNotBlank(seriousLower) && StrUtil.isNotBlank(seriousUpper)) {
if (NumberUtil.compare(resultvalue, Double.parseDouble(seriousLower)) >= 0 && NumberUtil.compare(resultvalue,
Double.parseDouble(seriousUpper)) < 0) {
result.put("alarmlevel", "2");
result.put("isNormal", "0");
result.put("alarmtype", alarmThreshold.getAlarmType());
}
}
if (StrUtil.isNotBlank(dangerLower) && StrUtil.isNotBlank(dangerUpper)) {
if (NumberUtil.compare(resultvalue, Double.parseDouble(dangerLower)) >= 0 && NumberUtil.compare(resultvalue,
Double.parseDouble(dangerUpper)) < 0) {
result.put("alarmlevel", "3");
result.put("isNormal", "0");
result.put("alarmtype", alarmThreshold.getAlarmType());
}
}
return result;
}
// 状态分析类型
if ("2".equals(alarmThreshold.getAlarmClass())) {
// 三相对比告警
if ("4".equals(alarmThreshold.getAlarmType())) {
// 获取到不同相位的最新数据
List<TaskResult> nonCoherentResult =
taskResultMapper.getNonCoherentResult(taskResult.getAreaId(), taskResult.getBayId(),
taskResult.getMainDeviceId(), taskResult.getComponentId(),
taskResult.getRecognitionType(), substationDevice.getMeterType(),
taskResult.getResultId(), taskResult.getTaskTodoId(), taskResult.getPhase());
taskResult.setValue(value);
taskResult.setDesc(desc);
nonCoherentResult.add(taskResult);
if (nonCoherentResult.size() < 3) {
return result;
}
Set<String> values =
nonCoherentResult.stream().filter(n -> ObjectUtil.isNotEmpty(n.getValue()))
.map(TaskResult::getValue).collect(Collectors.toSet());
// values.add(value);
// 如果三相任意一相不等于基准值判定为异常
if (values.size() > 1) {
Set<String> ids =
nonCoherentResult.stream().filter(n -> ObjectUtil.isNotEmpty(n.getValue())).map(TaskResult::getDeviceId).collect(Collectors.toSet());
result.put("link_point", StrUtil.join(",", ids));
ids.add(deviceid);
result.put("isNormal", "0");
result.put("alarmtype", alarmThreshold.getAlarmType());
Map<String, String> phaseToValueMap = nonCoherentResult.stream()
.collect(Collectors.toMap(
TaskResult::getPhase,
TaskResult::getDesc,
(existingValue, newValue) -> existingValue
));
String phaseA = phaseToValueMap.get("1");
String phaseB = phaseToValueMap.get("2");
String phaseC = phaseToValueMap.get("3");
result.put("oldContent", "[A]相结果" + phaseA + "" + "[B]相结果" + phaseB + "" + "[C]相结果" + phaseC +
"");
result.put("isSame", "0");
}
return result;
}
String patroldeviceJson = substationDevice.getPatroldeviceJson();
if (JSONUtil.isTypeJSONArray(patroldeviceJson)) {
JSONArray jsonArray = JSONUtil.parseArray(patroldeviceJson);
if (jsonArray.size() > 1) {
// 非同源告警
LambdaQueryWrapper<TaskResult> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(TaskResult::getDeviceId, deviceid).eq(TaskResult::getTaskTodoId,
taskResult.getTaskTodoId()).eq(TaskResult::getFlag, "2").ne(TaskResult::getResultId,
resultId);
List<TaskResult> taskResultList = taskResultMapper.selectList(queryWrapper);
Optional<TaskResult> first =
taskResultList.stream().filter(f -> StrUtil.isNotBlank(f.getValue()) && !value.equals(f.getValue())).findFirst();
if (!first.isPresent()) {
return result;
}
TaskResult oldResult = first.get();
result.put("oldContent",
oldResult.getPatroldeviceName() + "设备识别结果为" + oldResult.getDesc() + "");
result.put("isNormal", "0");
result.put("alarmtype", alarmThreshold.getAlarmType());
result.put("alarmlevel", "4");
result.put("isSame", "1");
}
if (jsonArray.size() == 1) {
// 非同源告警
LambdaQueryWrapper<TaskResult> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(TaskResult::getDeviceId, deviceid).eq(TaskResult::getTaskTodoId,
taskResult.getTaskTodoId()).eq(TaskResult::getFlag, "2").ne(TaskResult::getResultId,
resultId);
List<TaskResult> taskResultList = taskResultMapper.selectList(queryWrapper);
Optional<TaskResult> first =
taskResultList.stream().filter(f -> StrUtil.isNotBlank(f.getValue()) && !value.equals(f.getValue())).findFirst();
if (!first.isPresent()) {
return result;
}
TaskResult oldResult = first.get();
result.put("oldContent",
oldResult.getPatroldeviceName() + "设备识别结果为" + oldResult.getDesc() + "");
result.put("isNormal", "0");
result.put("alarmtype", alarmThreshold.getAlarmType());
result.put("alarmlevel", "4");
result.put("isSame", "1");
}
return result;
}
if ("1".equals(alarmThreshold.getIsLastContrast())) {
LambdaQueryWrapper<TaskResult> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(TaskResult::getDeviceId, deviceid).isNotNull(TaskResult::getPatroldeviceDate).lt(TaskResult::getPatroldeviceDate,
taskResult.getPatroldeviceDate()).orderByDesc(TaskResult::getPatroldeviceDate).last("limit 0," +
"1");
List<TaskResult> taskResultList = taskResultMapper.selectList(queryWrapper);
if (taskResultList.size() <= 0) {
return result;
}
TaskResult taskResultBase = taskResultList.get(0);
// 基准值
String baseValue = taskResultBase.getValue();
if (!baseValue.equals(value)) {
result.put("isNormal", "0");
result.put("alarmtype", alarmThreshold.getAlarmType());
String oldValue = "fhz".equals(type) ? taskResultBase.getDesc() : baseValue;
result.put("oldContent", "点位上次识别结果为" + oldValue + "");
}
} else {
// 基准值
String alarmValue = alarmThreshold.getBaseValue();
if (!value.equals(alarmValue)) {
String oldValue = alarmValue;
result.put("isNormal", "0");
result.put("alarmtype", alarmThreshold.getAlarmType());
if ("fhz".equals(type)) {
if ("1".equals(alarmValue)) {
oldValue = "分合闸_分";
}
if ("2".equals(alarmValue)) {
oldValue = "分合闸_合";
}
if ("3".equals(alarmValue)) {
oldValue = "分合闸_状态异常";
}
}
result.put("oldContent", "点位基准值为" + oldValue + "");
}
}
return result;
}
return result;
}
/********************************** /**********************************
* 用途说明: 生成报警记录(点位) * 用途说明: 生成报警记录(点位)
* 参数说明 taskResult * 参数说明 taskResult
@ -1448,16 +1767,13 @@ public class AlarmLogServiceImpl extends ServiceImpl<AlarmLogMapper, AlarmLog> i
type, type,
DateUtil.format(DateUtil.date(), "yyyyMM") DateUtil.format(DateUtil.date(), "yyyyMM")
); );
log.info(
"============================================拷贝原图到报警目录下============================================");
//拷贝原图到报警目录下 //拷贝原图到报警目录下
String fullfilename = URLDecoder.decode(taskResult.getFilePath(), "utf-8"); String fullfilename = URLDecoder.decode(taskResult.getFilePath(), "utf-8");
String alarmfullfilename = alarmfilepath + StrUtil.subAfter(fullfilename, "/", true); String alarmfullfilename = alarmfilepath + StrUtil.subAfter(fullfilename, "/", true);
FileUtil.copy(Config.getSnapFilePath() + fullfilename, Config.getAlarmFilePath() + alarmfullfilename, true); FileUtil.copy(Config.getSnapFilePath() + fullfilename, Config.getAlarmFilePath() + alarmfullfilename, true);
alarmLog.setFilePath(URLEncoder.encode(alarmfullfilename, "utf-8"));//原图文件名称含路径 alarmLog.setFilePath(URLEncoder.encode(alarmfullfilename, "utf-8"));//原图文件名称含路径
alarmLog.setDefectType(taskResult.getValueType());//'缺陷类别' alarmLog.setDefectType(taskResult.getValueType());//'缺陷类别'
log.info(
"============================================拷贝识别图到报警目录下============================================");
//拷贝识别图到报警目录下 //拷贝识别图到报警目录下
if (ObjUtil.isNotEmpty(taskResult.getDefectFilePath())) { if (ObjUtil.isNotEmpty(taskResult.getDefectFilePath())) {
String fulldefectfilename = URLDecoder.decode(taskResult.getDefectFilePath(), "utf-8"); String fulldefectfilename = URLDecoder.decode(taskResult.getDefectFilePath(), "utf-8");
@ -1467,8 +1783,6 @@ public class AlarmLogServiceImpl extends ServiceImpl<AlarmLogMapper, AlarmLog> i
true); true);
alarmLog.setDefectFilePath(URLEncoder.encode(fullalarmfile, "utf-8"));//标注了识别框和信息 alarmLog.setDefectFilePath(URLEncoder.encode(fullalarmfile, "utf-8"));//标注了识别框和信息
} }
log.info(
"============================================图形识别结果(值)============================================");
alarmLog.setValue(taskResult.getValue());//图形识别结果 alarmLog.setValue(taskResult.getValue());//图形识别结果
alarmLog.setUnit(taskResult.getUnit()); alarmLog.setUnit(taskResult.getUnit());
String alarminfo = ""; String alarminfo = "";
@ -1477,45 +1791,69 @@ public class AlarmLogServiceImpl extends ServiceImpl<AlarmLogMapper, AlarmLog> i
if (StrUtil.isNotBlank(taskResult.getUnit())) { if (StrUtil.isNotBlank(taskResult.getUnit())) {
unit = taskResult.getUnit(); unit = taskResult.getUnit();
} }
if ("meter".equals(taskResult.getValueType())) { List<AlarmThreshold> list =
alarminfo = String.format("%s-%s的%s识别结果为%s%s判定为[%s]超限缺陷!", taskResult.getMainDeviceName(), alarmThresholdService.list(new LambdaQueryWrapper<AlarmThreshold>().eq(AlarmThreshold::getDeviceId,
taskResult.getComponentName(), taskResult.getDeviceName(), value, deviceid));
String alarmDesc = "";
if (list.size() > 0) {
AlarmThreshold alarmThreshold = list.get(0);
String alarmClass = "";
if ("1".equals(alarmThreshold.getAlarmClass())) {
alarmClass = "[阈值类]";
}
if ("2".equals(alarmThreshold.getAlarmClass())) {
alarmClass = "[状态类]";
}
if ("3".equals(alarmThreshold.getAlarmClass())) {
alarmClass = "[趋势类]";
}
if (ObjectUtil.isNotEmpty(map.get("isSame")) && "1".equals(map.get("isSame").toString())) {
alarmDesc = "" + alarmClass + "告警类型为:非同源告警";
} else {
List<SysDictionaryItems> itemsList = sysDictionaryItemsService.getDictItemByType("AlarmType",
alarmThreshold.getAlarmType());
if (itemsList.size() == 1) {
SysDictionaryItems sysDictionaryItems = itemsList.get(0);
alarmDesc = "" + alarmClass + "告警类型为:" + sysDictionaryItems.getDictName();
}
}
}
String oldContent = ObjectUtil.isEmpty(map.get("oldContent")) ? "" : map.get("oldContent").toString();
if ("meter".equals(taskResult.getValueType()) || "partial".equals(taskResult.getValueType())) {
alarminfo = String.format("%s-%s的%s%s%s本次识别结果为%s%s判定为[%s]异常", taskResult.getMainDeviceName(),
taskResult.getComponentName(), taskResult.getDeviceName(), alarmDesc, oldContent,
taskResult.getValue(),
unit, taskResult.getDesc()); unit, taskResult.getDesc());
} }
if ("infrared".equals(taskResult.getValueType())) { if ("infrared".equals(taskResult.getValueType())) {
alarminfo = String.format("%s-%s的%s识别温度%s单位%s判定为[%s]超限缺陷!", taskResult.getMainDeviceName(), alarminfo = String.format("%s-%s的%s%s%s本次识别温度%s单位%s判定为[%s]超限缺陷!", taskResult.getMainDeviceName(),
taskResult.getComponentName(), taskResult.getDeviceName(), value, taskResult.getComponentName(), taskResult.getDeviceName(), alarmDesc, oldContent,
taskResult.getValue(),
unit, taskResult.getDesc()); unit, taskResult.getDesc());
} }
if ("sound".equals(taskResult.getValueType())) { if ("sound".equals(taskResult.getValueType())) {
alarminfo = "声音检测异常!"; alarminfo = "声音检测异常,%s本次识别结果为[" + taskResult.getDesc() + "]";
}
String pictureAnalysisTypeList = device.getPictureAnalysisTypeList();
if (StrUtil.isNotBlank(pictureAnalysisTypeList)) {
JSONObject pictureAnalysisType = JSONUtil.parseObj(pictureAnalysisTypeList);
if (StrUtil.isNotBlank(pictureAnalysisType.getStr("PictureDefectAnalysisType"))) {
alarminfo = String.format("%s-%s的%s%s%s本次识别结果为%s判定为[%s]异常!", taskResult.getMainDeviceName(),
taskResult.getComponentName(), taskResult.getDeviceName(), alarmDesc, oldContent,
taskResult.getDesc(),
taskResult.getDesc());
}
}
if (ObjectUtil.isNotEmpty(map.get("isSame")) && "0".equals(map.get("isSame").toString())) {
alarminfo = String.format("%s-%s的%s%s%s判定为三相对比异常", taskResult.getMainDeviceName(),
taskResult.getComponentName(), taskResult.getDeviceName(), alarmDesc, oldContent);
} }
if (StrUtil.isBlank(alarminfo)) { if (StrUtil.isBlank(alarminfo)) {
// // 图像缺陷分析类型 alarminfo = String.format("%s-%s的%s%s%s本次识别结果为%s%s判定为[%s]异常!", taskResult.getMainDeviceName(),
// List<Map<String, Object>> pictureDefectAnalysisTypeList = sysDictionaryItemsService.getDeviceByType( taskResult.getComponentName(), taskResult.getDeviceName(), alarmDesc, oldContent,
// "PictureDefectAnalysisType"); taskResult.getDesc(),
// String valueType = taskResult.getValueType(); unit, taskResult.getDesc());
// Set<String> customList = pictureDefectAnalysisTypeList.stream().filter(c -> ObjectUtil.isNotEmpty(c.get(
// "custom1"))).map(c -> c.get("custom1").toString()).collect(Collectors.toSet());
// for (String custom : customList) {
// if (JSONUtil.isTypeJSONArray(custom)) {
// JSONArray jsonArray = JSONUtil.parseArray(custom);
// for (int i = 0; i < jsonArray.size(); i++) {
// JSONObject jsonObject = jsonArray.getJSONObject(i);
// // 检查当前对象的key字段是否与目标key匹配
// if (jsonObject.getStr("key").equals(valueType)) {
// // 如果匹配取出对应的value字段的值
// value = jsonObject.getStr("value");
// taskResult.setValue(value);
// break; // 找到后跳出循环
// }
// }
// }
//
// }
alarminfo = String.format("%s-%s的%s识别结果为%s%s判定为[%s]异常!", taskResult.getMainDeviceName(),
taskResult.getComponentName(), taskResult.getDeviceName(), value, unit
, taskResult.getDesc());
} }
alarmLog.setContent(alarminfo);//告警描述信息 alarmLog.setContent(alarminfo);//告警描述信息
alarmLog.setAlarmDate(alarmDate);//发送报警时间 alarmLog.setAlarmDate(alarmDate);//发送报警时间
@ -1562,126 +1900,11 @@ public class AlarmLogServiceImpl extends ServiceImpl<AlarmLogMapper, AlarmLog> i
jsonObject.putOpt("seriousMax", device.getSeriousMax()); jsonObject.putOpt("seriousMax", device.getSeriousMax());
jsonObject.putOpt("criticalMin", device.getCriticalMin()); jsonObject.putOpt("criticalMin", device.getCriticalMin());
jsonObject.putOpt("criticalMax", device.getCriticalMax()); jsonObject.putOpt("criticalMax", device.getCriticalMax());
log.info(
"============================================如果是站端则区域也需要发送告警============================================");
// 如果是站端则区域也需要发送告警 // 如果是站端则区域也需要发送告警
if (!"0".equals(parentid)) { if (!"0".equals(parentid)) {
WebSocketServer.sendInfo(parentid, jsonObject.toString()); WebSocketServer.sendInfo(parentid, jsonObject.toString());
} }
WebSocketServer.sendInfo(stationId, jsonObject.toString()); WebSocketServer.sendInfo(stationId, jsonObject.toString());
log.info(
"============================================发送告警============================================");
// // 向算法管理平台发送告警信息
// JSONObject alarmContent = new JSONObject();
// alarmContent.putOnce("province_name", substation.getProvinceName());
// alarmContent.putOnce("city_name", substation.getCityName());
// alarmContent.putOnce("volt_level", substation.getVoltLevel());
// alarmContent.putOnce("station_name", substation.getStationName());
// alarmContent.putOnce("section_ip", substation.getStationIp());
// alarmContent.putOnce("node_id", substation.getNodeId());
// alarmContent.putOnce("msg_type", "alarm");
// JSONArray alarmArray = new JSONArray();
// JSONObject alarmObject = new JSONObject();
// alarmObject.putOnce("bay_name", "");
// alarmObject.putOnce("device_name", "");
// alarmObject.putOnce("point_name", "");
// alarmObject.putOnce("time", DateUtil.now());
//
// // 获取坐标
// String rectangle = taskResult.getRectangle();
// JSONArray defectArray = new JSONArray();
// JSONObject defectObject = new JSONObject();
// defectObject.putOnce("type", alarmLog.getDefectType());
// defectObject.putOnce("confidence", taskResult.getConf());
// defectObject.putOnce("desc", alarmLog.getContent());
// if (StrUtil.isNotBlank(rectangle)) {
// JSONArray rectangleArray = JSONUtil.parseArray(rectangle);
// JSONArray differentArray = new JSONArray();
// for (int i = 0; i < rectangleArray.size(); i++) {
// JSONObject coorsObject = rectangleArray.getJSONObject(i);
// // 坐标数组
// JSONArray coorsArray = coorsObject.getJSONArray("areas");
// JSONObject different = new JSONObject();
// for (int j = 0; j < coorsArray.size(); j++) {
// JSONObject dataObject = coorsArray.getJSONObject(j);
// for (String data : dataObject.keySet()) {
// different.putOnce(data + (j + 1), dataObject.getStr(data));
// defectObject.putOpt(data + (j + 1), dataObject.getStr(data));
// }
// }
// differentArray.add(different);
// }
// alarmObject.putOnce("different", differentArray);
// } else {
// alarmObject.putOnce("different", new JSONArray());
// }
// defectArray.add(defectObject);
// alarmObject.putOnce("defect", defectArray);
// alarmArray.add(alarmObject);
// alarmContent.putOnce("alarm", alarmArray);
//
// // 原图
// String picRaw = "";
// if (ObjectUtil.isNotEmpty(taskResult.getFilePath())) {
// picRaw = URLDecoder.decode(taskResult.getFilePath(), "utf-8");
// }
// alarmObject.putOnce("pic_raw", picRaw);
// // 识别图
// String picDefect = "";
// if (ObjectUtil.isNotEmpty(taskResult.getDefectFilePath())) {
// picDefect = URLDecoder.decode(taskResult.getDefectFilePath(), "utf-8");
// }
// alarmObject.putOnce("pic_defect", picDefect);
//
// //TODO 缺少基准图判别图
// alarmObject.putOnce("pic_different", "");
// alarmObject.putOnce("pic_diff_base", "");
// //文件转化为图片
// Image srcImg = null;
// try {
// if (StrUtil.isNotBlank(picDefect)) {
// String imagePath = httpServerConfig.getSnapFilePath() + picDefect;
// String ext = imagePath.substring(imagePath.lastIndexOf(".") + 1);
// if ("jpg".equals(ext) || "JPG".equals(ext)) {
// srcImg = ImageIO.read(new File(imagePath));
// //获取图片的宽
// int srcImgWidth = srcImg.getWidth(null);
// //获取图片的高
// int srcImgHeight = srcImg.getHeight(null);
// alarmObject.putOnce("pic_width", srcImgWidth);
// alarmObject.putOnce("pic_height", srcImgHeight);
// }
// } else {
// alarmObject.putOnce("pic_width", 0);
// alarmObject.putOnce("pic_height", 0);
// }
// } catch (IOException e) {
// log.error("发生错误", e);
// throw new RuntimeException(e.getMessage());
// }
//// mqttGateway.sendToMqtt( "nodes/java/user/alert/2", 2,alarmContent.toString());
//
// // 区域巡视主机生成告警数据时主动向上级系统上报告警并接收响应消息
// JSONObject alarmData = new JSONObject();
// alarmData.set("patroldevice_name", alarmLog.getPatroldeviceName());
// alarmData.set("patroldevice_code", alarmLog.getPatroldeviceCode());
// alarmData.set("task_name", alarmLog.getTaskName());
// alarmData.set("task_code", alarmLog.getTaskCode());
// alarmData.set("device_name", alarmLog.getDeviceName());
// alarmData.set("device_id", alarmLog.getDeviceId());
// alarmData.set("alarm_level", alarmLog.getAlarmLevel());
// alarmData.set("alarm_type", alarmLog.getAlarmType());
// alarmData.set("recognition_type", alarmLog.getRecognitionType());
// alarmData.set("defect_type", alarmLog.getDefectType());
// alarmData.set("file_type", alarmLog.getFileType());
// alarmData.set("file_path", alarmLog.getFilePath());
// alarmData.set("value", alarmLog.getPatroldeviceName());
// alarmData.set("value_unit", alarmLog.getValue());
// alarmData.set("unit", alarmLog.getUnit());
// alarmData.set("time", taskResult.getTime());
// alarmData.set("link_point", taskResult.getDeviceId());
// alarmData.set("task_patrolled_id", alarmLog.getTaskPatrolledId());
// alarmData.set("content", alarmLog.getContent());
// this.sendTaskData("62", "", alarmLog.getStationCode(), alarmData.toString()); // this.sendTaskData("62", "", alarmLog.getStationCode(), alarmData.toString());
return true; return true;
} }

View File

@ -547,6 +547,9 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task> implements IT
String isAlarm = substationDevice.getIsAlarm(); String isAlarm = substationDevice.getIsAlarm();
taskResult.setIsAlarm(isAlarm); taskResult.setIsAlarm(isAlarm);
// 相位
taskResult.setPhase(substationDevice.getPhase());
//数据来源 //数据来源
String dataType = substationDevice.getDataType(); String dataType = substationDevice.getDataType();
taskResult.setDataType(dataType); taskResult.setDataType(dataType);

View File

@ -3,6 +3,8 @@ package com.yfd.platform.system.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yfd.platform.system.domain.SysDictionaryItems; import com.yfd.platform.system.domain.SysDictionaryItems;
import java.util.List;
/** /**
* <p> * <p>
* 数据字典明细 Mapper 接口 * 数据字典明细 Mapper 接口
@ -12,5 +14,5 @@ import com.yfd.platform.system.domain.SysDictionaryItems;
* @since 2023-03-08 * @since 2023-03-08
*/ */
public interface SysDictionaryItemsMapper extends BaseMapper<SysDictionaryItems> { public interface SysDictionaryItemsMapper extends BaseMapper<SysDictionaryItems> {
List<SysDictionaryItems> getDictItemByType(String dictcode, String alarmType);
} }

View File

@ -52,4 +52,6 @@ public interface ISysDictionaryItemsService extends IService<SysDictionaryItems>
* 返回值说明: java.util.List<java.util.Map<java.lang.String,java.lang.Object>> * 返回值说明: java.util.List<java.util.Map<java.lang.String,java.lang.Object>>
***********************************/ ***********************************/
List<Map<String, Object>> getDeviceByType(String dictcode); List<Map<String, Object>> getDeviceByType(String dictcode);
List<SysDictionaryItems> getDictItemByType(String dictcode, String alarmType);
} }

View File

@ -148,4 +148,10 @@ public class SysDictionaryItemsServiceImpl extends ServiceImpl<SysDictionaryItem
return itemCode; return itemCode;
} }
@Override
public List<SysDictionaryItems> getDictItemByType(String dictcode, String alarmType) {
return sysDictionaryItemsMapper.getDictItemByType(dictcode,alarmType);
}
} }

View File

@ -836,7 +836,48 @@ ORDER BY
ORDER BY ORDER BY
t.order_num ASC t.order_num ASC
</select> </select>
<select id="getNonCoherentResult" resultType="com.yfd.platform.modules.patroltask.domain.TaskResult">
SELECT
a.*
FROM
iis_task_result a,iis_substation_device sd,
( SELECT phase, max( patroldevice_date ) patroldevice_date FROM iis_task_result WHERE phase IS NOT NULL and phase != '' AND flag = '2' GROUP BY phase ) b
WHERE
a.device_id=sd.device_id
AND a.flag = '2'
AND a.value != ''
AND a.value is not null
AND a.phase = b.phase
AND a.patroldevice_date = b.patroldevice_date
<if test="areaId != null and areaId != ''">
AND a.area_id = #{areaId}
</if>
<if test="bayId != null and bayId != ''">
AND a.bay_id = #{bayId}
</if>
<if test="mainDeviceId != null and mainDeviceId != ''">
AND a.main_device_id = #{mainDeviceId}
</if>
<if test="componentId != null and componentId != ''">
AND a.component_id = #{componentId}
</if>
<if test="recognitionTypeList != null and recognitionTypeList != ''">
AND a.recognition_type = #{recognitionTypeList}
</if>
<if test="meterType != null and meterType != ''">
AND sd.meter_type = #{meterType}
</if>
<if test="resultId != null and resultId != ''">
AND a.result_id != #{resultId}
</if>
<if test="taskTodoId != null and taskTodoId != ''">
AND a.task_todo_id = #{taskTodoId}
</if>
<if test="phase != null and phase != ''">
AND a.phase != #{phase}
</if>
</select>
<select id="getValueByDeviceId" resultType="java.util.Map"> <select id="getValueByDeviceId" resultType="java.util.Map">
SELECT * FROM iis_recognition WHERE device_id=#{deviceId} SELECT * FROM iis_recognition WHERE device_id=#{deviceId}
</select> </select>

View File

@ -1,5 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.yfd.platform.system.mapper.SysDictionaryItemsMapper"> <mapper namespace="com.yfd.platform.system.mapper.SysDictionaryItemsMapper">
<select id="getDictItemByType" resultType="com.yfd.platform.system.domain.SysDictionaryItems">
SELECT
di.*
FROM
sys_dictionary_items di
INNER JOIN sys_dictionary d ON di.dictid = d.id
WHERE
d.dictcode = #{dictcode}
AND di.itemcode = #{alarmType}
limit 1
</select>
</mapper> </mapper>