diff --git a/riis-system/src/main/java/com/yfd/platform/modules/patroltask/domain/TaskResult.java b/riis-system/src/main/java/com/yfd/platform/modules/patroltask/domain/TaskResult.java index 331cb71..062cebc 100644 --- a/riis-system/src/main/java/com/yfd/platform/modules/patroltask/domain/TaskResult.java +++ b/riis-system/src/main/java/com/yfd/platform/modules/patroltask/domain/TaskResult.java @@ -290,6 +290,9 @@ public class TaskResult implements Serializable { */ private String custom3; - + /** + * <1>:=A 相<2>:=B 相<3>:=C 相 多个相位,采用","分隔 + */ + private String phase; } diff --git a/riis-system/src/main/java/com/yfd/platform/modules/patroltask/mapper/TaskResultMapper.java b/riis-system/src/main/java/com/yfd/platform/modules/patroltask/mapper/TaskResultMapper.java index 3061ecd..9c5fb2b 100644 --- a/riis-system/src/main/java/com/yfd/platform/modules/patroltask/mapper/TaskResultMapper.java +++ b/riis-system/src/main/java/com/yfd/platform/modules/patroltask/mapper/TaskResultMapper.java @@ -206,5 +206,5 @@ public interface TaskResultMapper extends BaseMapper { List> getValueByDeviceId(String deviceId); Page> getResultByPatroldevice(Page> page, String internationalId,String mainDeviceId, String taskName, String recognitionType, String valid,String isReport,String startDate,String endDate); - + List getNonCoherentResult(String areaId,String bayId,String mainDeviceId,String componentId,String recognitionTypeList,String meterType,String resultId,String taskTodoId,String phase); } diff --git a/riis-system/src/main/java/com/yfd/platform/modules/patroltask/service/impl/AlarmLogServiceImpl.java b/riis-system/src/main/java/com/yfd/platform/modules/patroltask/service/impl/AlarmLogServiceImpl.java index ee13622..0cc1a06 100644 --- a/riis-system/src/main/java/com/yfd/platform/modules/patroltask/service/impl/AlarmLogServiceImpl.java +++ b/riis-system/src/main/java/com/yfd/platform/modules/patroltask/service/impl/AlarmLogServiceImpl.java @@ -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.DeviceSignalMapper; import com.yfd.platform.modules.auxcontrol.mapper.MeterDeviceMapper; -import com.yfd.platform.modules.basedata.domain.LinkageSignal; -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.domain.*; import com.yfd.platform.modules.basedata.mapper.LinkageSignalMapper; import com.yfd.platform.modules.basedata.mapper.SubstationDeviceMapper; import com.yfd.platform.modules.basedata.mapper.SubstationMapper; 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.TaskResult; import com.yfd.platform.modules.patroltask.domain.TaskTodo; @@ -133,6 +131,8 @@ public class AlarmLogServiceImpl extends ServiceImpl i @Resource private DeviceAlarmParameterMapper deviceAlarmParameterMapper; + @Resource + private IAlarmThresholdService alarmThresholdService; @Override public synchronized boolean updateTaskResult(JSONObject jsonObject) throws Exception { @@ -446,17 +446,6 @@ public class AlarmLogServiceImpl extends ServiceImpl i String filename = ""; JSONArray posArray = new JSONArray(); Map 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++) { JSONObject result = results.getJSONObject(a); String code = result.getStr("code"); @@ -471,11 +460,7 @@ public class AlarmLogServiceImpl extends ServiceImpl i confList.add(conf); } 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"))) { - //图片 排除声音 -// filename = StrUtil.subAfter(URLDecoder.decode(result.getStr("resImagePath"), "utf-8"), "=", -// true); filename = result.getStr("resImagePath"); String pos = result.getStr("pos"); // 将框坐标统一存储画框 @@ -489,7 +474,6 @@ public class AlarmLogServiceImpl extends ServiceImpl i JSONArray areas = jsonObject.getJSONArray("areas"); JSONObject jsonObject1 = areas.getJSONObject(0); 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 i String valueType = taskResult.getValueType(); Map judgeresult = judgeAbnormal(result.getStr("type"), result.getStr("value"), result.getStr("conf"), taskResult.getDeviceId(), taskResult.getResultId()); - // || "yjsk".equals(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")))) { // 图像缺陷分析类型 @@ -524,24 +507,28 @@ public class AlarmLogServiceImpl extends ServiceImpl i } } else { - log.info("==============================进入===========================" + result.getStr( - "type")); valueList.add(value); descList.add(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())) { map.put("alarmlevel", judgeresult.get("alarmlevel")); //判定为异常 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"))) { descList.add(desc); } @@ -552,7 +539,6 @@ public class AlarmLogServiceImpl extends ServiceImpl i } } log.info("========================validList.toString()=================================" + validList.toString()); -// writer.close(); // 识别成功 taskResult.setValue(StrUtil.join(",", valueList)); String descJoin = StrUtil.join(",", descList); @@ -1209,14 +1195,17 @@ public class AlarmLogServiceImpl extends ServiceImpl i } //根据识别类型和结果值判断是否为异常 - private Map judgeAbnormal(String type, String value, String conf, String deviceid, - String resultId) throws Exception { + private Map judgeAbnormal_bak(String type, String value, String conf, String deviceid, + String resultId) throws Exception { Map result = new HashMap<>(); SubstationDevice substationDevice = deviceMapper.selectById(deviceid); String pictureAnalysisTypeList = substationDevice.getPictureAnalysisTypeList(); JSONObject jsonObject = JSONUtil.parseObj(pictureAnalysisTypeList); String pictureDefectAnalysisType = jsonObject.getStr("PictureDefectAnalysisType"); result.put("isNormal", "1"); + List list = + alarmThresholdService.list(new LambdaQueryWrapper().eq(AlarmThreshold::getDeviceId, + deviceid)); if (StrUtil.isNotBlank(pictureDefectAnalysisType)) { // 缺陷告警设置 // List> mapList = sysDictionaryItemsService.getDeviceByType @@ -1396,6 +1385,336 @@ public class AlarmLogServiceImpl extends ServiceImpl i return result; } + //根据识别类型和结果值判断是否为异常 + private Map judgeAbnormal(String type, String value, String desc, String deviceid, + String resultId) { + Map 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 list = + alarmThresholdService.list(new LambdaQueryWrapper().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> 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 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 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 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 taskResultList = taskResultMapper.selectList(queryWrapper); + Optional 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 queryWrapper = new LambdaQueryWrapper<>(); + queryWrapper.eq(TaskResult::getDeviceId, deviceid).eq(TaskResult::getTaskTodoId, + taskResult.getTaskTodoId()).eq(TaskResult::getFlag, "2").ne(TaskResult::getResultId, + resultId); + List taskResultList = taskResultMapper.selectList(queryWrapper); + // List values = taskResultList.stream().filter(v->StrUtil.isNotBlank + // (v.getValue())).map(TaskResult::getValue).collect(Collectors.toList()); + Optional 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 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 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 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 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 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 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 values = + nonCoherentResult.stream().filter(n -> ObjectUtil.isNotEmpty(n.getValue())) + .map(TaskResult::getValue).collect(Collectors.toSet()); + // values.add(value); + // 如果三相任意一相不等于基准值判定为异常 + if (values.size() > 1) { + Set 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 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 queryWrapper = new LambdaQueryWrapper<>(); + queryWrapper.eq(TaskResult::getDeviceId, deviceid).eq(TaskResult::getTaskTodoId, + taskResult.getTaskTodoId()).eq(TaskResult::getFlag, "2").ne(TaskResult::getResultId, + resultId); + List taskResultList = taskResultMapper.selectList(queryWrapper); + Optional 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 queryWrapper = new LambdaQueryWrapper<>(); + queryWrapper.eq(TaskResult::getDeviceId, deviceid).eq(TaskResult::getTaskTodoId, + taskResult.getTaskTodoId()).eq(TaskResult::getFlag, "2").ne(TaskResult::getResultId, + resultId); + List taskResultList = taskResultMapper.selectList(queryWrapper); + Optional 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 queryWrapper = new LambdaQueryWrapper<>(); + queryWrapper.eq(TaskResult::getDeviceId, deviceid).isNotNull(TaskResult::getPatroldeviceDate).lt(TaskResult::getPatroldeviceDate, + taskResult.getPatroldeviceDate()).orderByDesc(TaskResult::getPatroldeviceDate).last("limit 0," + + "1"); + List 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 @@ -1448,16 +1767,13 @@ public class AlarmLogServiceImpl extends ServiceImpl i type, DateUtil.format(DateUtil.date(), "yyyyMM") ); - log.info( - "============================================拷贝原图到报警目录下============================================"); //拷贝原图到报警目录下 String fullfilename = URLDecoder.decode(taskResult.getFilePath(), "utf-8"); String alarmfullfilename = alarmfilepath + StrUtil.subAfter(fullfilename, "/", true); FileUtil.copy(Config.getSnapFilePath() + fullfilename, Config.getAlarmFilePath() + alarmfullfilename, true); alarmLog.setFilePath(URLEncoder.encode(alarmfullfilename, "utf-8"));//原图文件名称(含路径) alarmLog.setDefectType(taskResult.getValueType());//'缺陷类别' - log.info( - "============================================拷贝识别图到报警目录下============================================"); + //拷贝识别图到报警目录下 if (ObjUtil.isNotEmpty(taskResult.getDefectFilePath())) { String fulldefectfilename = URLDecoder.decode(taskResult.getDefectFilePath(), "utf-8"); @@ -1467,8 +1783,6 @@ public class AlarmLogServiceImpl extends ServiceImpl i true); alarmLog.setDefectFilePath(URLEncoder.encode(fullalarmfile, "utf-8"));//标注了识别框和信息 } - log.info( - "============================================图形识别结果(值)============================================"); alarmLog.setValue(taskResult.getValue());//图形识别结果(值) alarmLog.setUnit(taskResult.getUnit()); String alarminfo = ""; @@ -1477,45 +1791,69 @@ public class AlarmLogServiceImpl extends ServiceImpl i if (StrUtil.isNotBlank(taskResult.getUnit())) { unit = taskResult.getUnit(); } - if ("meter".equals(taskResult.getValueType())) { - alarminfo = String.format("%s-%s的%s,识别结果为%s%s,判定为[%s]超限缺陷!", taskResult.getMainDeviceName(), - taskResult.getComponentName(), taskResult.getDeviceName(), value, + List list = + alarmThresholdService.list(new LambdaQueryWrapper().eq(AlarmThreshold::getDeviceId, + 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 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()); } if ("infrared".equals(taskResult.getValueType())) { - alarminfo = String.format("%s-%s的%s,识别温度:%s单位:%s,判定为[%s]超限缺陷!", taskResult.getMainDeviceName(), - taskResult.getComponentName(), taskResult.getDeviceName(), value, + alarminfo = String.format("%s-%s的%s%s,%s本次识别温度:%s单位:%s,判定为[%s]超限缺陷!", taskResult.getMainDeviceName(), + taskResult.getComponentName(), taskResult.getDeviceName(), alarmDesc, oldContent, + taskResult.getValue(), unit, taskResult.getDesc()); } 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)) { -// // 图像缺陷分析类型 -// List> pictureDefectAnalysisTypeList = sysDictionaryItemsService.getDeviceByType( -// "PictureDefectAnalysisType"); -// String valueType = taskResult.getValueType(); -// Set 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()); + alarminfo = String.format("%s-%s的%s%s,%s本次识别结果为%s%s,判定为[%s]异常!", taskResult.getMainDeviceName(), + taskResult.getComponentName(), taskResult.getDeviceName(), alarmDesc, oldContent, + taskResult.getDesc(), + unit, taskResult.getDesc()); } alarmLog.setContent(alarminfo);//告警描述信息 alarmLog.setAlarmDate(alarmDate);//发送报警时间 @@ -1562,126 +1900,11 @@ public class AlarmLogServiceImpl extends ServiceImpl i jsonObject.putOpt("seriousMax", device.getSeriousMax()); jsonObject.putOpt("criticalMin", device.getCriticalMin()); jsonObject.putOpt("criticalMax", device.getCriticalMax()); - log.info( - "============================================如果是站端则区域也需要发送告警============================================"); // 如果是站端则区域也需要发送告警 if (!"0".equals(parentid)) { WebSocketServer.sendInfo(parentid, 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()); return true; } diff --git a/riis-system/src/main/java/com/yfd/platform/modules/patroltask/service/impl/TaskServiceImpl.java b/riis-system/src/main/java/com/yfd/platform/modules/patroltask/service/impl/TaskServiceImpl.java index c77b003..610c6fe 100644 --- a/riis-system/src/main/java/com/yfd/platform/modules/patroltask/service/impl/TaskServiceImpl.java +++ b/riis-system/src/main/java/com/yfd/platform/modules/patroltask/service/impl/TaskServiceImpl.java @@ -547,6 +547,9 @@ public class TaskServiceImpl extends ServiceImpl implements IT String isAlarm = substationDevice.getIsAlarm(); taskResult.setIsAlarm(isAlarm); + // 相位 + taskResult.setPhase(substationDevice.getPhase()); + //数据来源 String dataType = substationDevice.getDataType(); taskResult.setDataType(dataType); diff --git a/riis-system/src/main/java/com/yfd/platform/system/mapper/SysDictionaryItemsMapper.java b/riis-system/src/main/java/com/yfd/platform/system/mapper/SysDictionaryItemsMapper.java index 6374974..7f122ea 100644 --- a/riis-system/src/main/java/com/yfd/platform/system/mapper/SysDictionaryItemsMapper.java +++ b/riis-system/src/main/java/com/yfd/platform/system/mapper/SysDictionaryItemsMapper.java @@ -3,6 +3,8 @@ package com.yfd.platform.system.mapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.yfd.platform.system.domain.SysDictionaryItems; +import java.util.List; + /** *

* 数据字典明细 Mapper 接口 @@ -12,5 +14,5 @@ import com.yfd.platform.system.domain.SysDictionaryItems; * @since 2023-03-08 */ public interface SysDictionaryItemsMapper extends BaseMapper { - + List getDictItemByType(String dictcode, String alarmType); } diff --git a/riis-system/src/main/java/com/yfd/platform/system/service/ISysDictionaryItemsService.java b/riis-system/src/main/java/com/yfd/platform/system/service/ISysDictionaryItemsService.java index 10dc53e..69b025b 100644 --- a/riis-system/src/main/java/com/yfd/platform/system/service/ISysDictionaryItemsService.java +++ b/riis-system/src/main/java/com/yfd/platform/system/service/ISysDictionaryItemsService.java @@ -52,4 +52,6 @@ public interface ISysDictionaryItemsService extends IService * 返回值说明: java.util.List> ***********************************/ List> getDeviceByType(String dictcode); + + List getDictItemByType(String dictcode, String alarmType); } diff --git a/riis-system/src/main/java/com/yfd/platform/system/service/impl/SysDictionaryItemsServiceImpl.java b/riis-system/src/main/java/com/yfd/platform/system/service/impl/SysDictionaryItemsServiceImpl.java index 0d97311..6708dd8 100644 --- a/riis-system/src/main/java/com/yfd/platform/system/service/impl/SysDictionaryItemsServiceImpl.java +++ b/riis-system/src/main/java/com/yfd/platform/system/service/impl/SysDictionaryItemsServiceImpl.java @@ -148,4 +148,10 @@ public class SysDictionaryItemsServiceImpl extends ServiceImpl getDictItemByType(String dictcode, String alarmType) { + return sysDictionaryItemsMapper.getDictItemByType(dictcode,alarmType); + } + + } diff --git a/riis-system/src/main/resources/mapper/patroltask/TaskResultMapper.xml b/riis-system/src/main/resources/mapper/patroltask/TaskResultMapper.xml index f1f47a5..d532d9d 100644 --- a/riis-system/src/main/resources/mapper/patroltask/TaskResultMapper.xml +++ b/riis-system/src/main/resources/mapper/patroltask/TaskResultMapper.xml @@ -836,7 +836,48 @@ ORDER BY ORDER BY t.order_num ASC + diff --git a/riis-system/src/main/resources/mapper/system/SysDictionaryItemsMapper.xml b/riis-system/src/main/resources/mapper/system/SysDictionaryItemsMapper.xml index 1bf0942..de73b92 100644 --- a/riis-system/src/main/resources/mapper/system/SysDictionaryItemsMapper.xml +++ b/riis-system/src/main/resources/mapper/system/SysDictionaryItemsMapper.xml @@ -1,5 +1,15 @@ - +