比对相关代码

This commit is contained in:
caozehui
2025-08-04 10:27:00 +08:00
parent 417a53a835
commit 2d889b07f7
63 changed files with 3987 additions and 863 deletions

View File

@@ -17,6 +17,7 @@ import com.njcn.gather.detection.pojo.po.IcdCheckData;
import com.njcn.gather.detection.pojo.po.SourceCompareDev;
import com.njcn.gather.detection.pojo.vo.*;
import com.njcn.gather.detection.service.impl.DetectionServiceImpl;
import com.njcn.gather.detection.util.DetectionUtil;
import com.njcn.gather.detection.util.socket.*;
import com.njcn.gather.device.pojo.enums.CommonEnum;
import com.njcn.gather.device.pojo.po.PqDevSub;
@@ -31,10 +32,10 @@ import com.njcn.gather.script.pojo.po.SourceIssue;
import com.njcn.gather.script.service.IPqScriptCheckDataService;
import com.njcn.gather.script.service.IPqScriptDtlsService;
import com.njcn.gather.storage.pojo.param.StorageParam;
import com.njcn.gather.storage.pojo.po.AdHarmonicResult;
import com.njcn.gather.storage.pojo.po.AdNonHarmonicResult;
import com.njcn.gather.storage.service.AdHarmonicService;
import com.njcn.gather.storage.pojo.po.SimAndDigHarmonicResult;
import com.njcn.gather.storage.pojo.po.SimAndDigNonHarmonicResult;
import com.njcn.gather.storage.service.DetectionDataDealService;
import com.njcn.gather.storage.service.SimAndDigHarmonicService;
import com.njcn.gather.system.cfg.service.ISysTestConfigService;
import com.njcn.gather.system.dictionary.pojo.enums.DictDataEnum;
import com.njcn.gather.system.dictionary.pojo.po.DictData;
@@ -49,10 +50,7 @@ import java.lang.reflect.Field;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
import java.util.*;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.Function;
@@ -85,7 +83,7 @@ public class SocketDevResponseService {
private final ISysRegResService iSysRegResService;
private final IPqScriptCheckDataService iPqScriptCheckDataService;
private final ISysTestConfigService sysTestConfigService;
private final AdHarmonicService adHarmonicService;
private final SimAndDigHarmonicService adHarmonicService;
private final IAdPlanService adPlanService;
private final IPqScriptCheckDataService pqScriptCheckDataService;
private final IDictDataService dictDataService;
@@ -712,19 +710,18 @@ public class SocketDevResponseService {
case SUCCESS:
String result = socketDataMsg.getData();
successComm.add(result);
//通讯校验成功
if (!param.getOperateType().equals(SourceOperateCodeEnum.TEST_TEM_START.getValue())) {
WebServiceManager.sendMsg(param.getUserPageId(), MsgUtil.msgToWebData(socketDataMsg, FormalTestManager.devNameMapComm, 1));
}
//单个测点通讯成功
WebServiceManager.sendMsg(param.getUserPageId(), MsgUtil.msgToWebData(socketDataMsg, FormalTestManager.devNameMapComm, 1));
System.out.println("设备通讯校验!" + successComm.size() + "=====" + FormalTestManager.monitorIdListComm.size());
if (successComm.size() == FormalTestManager.monitorIdListComm.size()) {
if (!param.getOperateType().equals(SourceOperateCodeEnum.TEST_TEM_START.getValue())) {
SocketDataMsg temMsg = new SocketDataMsg();
temMsg.setCode(SourceResponseCodeEnum.DEV_COMM_ALL_SUCCESS.getCode());
temMsg.setOperateCode(SourceOperateCodeEnum.DEV_INIT_GATHER_01.getValue());
temMsg.setRequestId(SourceOperateCodeEnum.YJC_SBTXJY.getValue());
WebServiceManager.sendMsg(param.getUserPageId(), JSON.toJSONString(temMsg));
}
// 通知前端整个装置通讯检测过程成功
SocketDataMsg temMsg = new SocketDataMsg();
temMsg.setCode(SourceResponseCodeEnum.DEV_COMM_ALL_SUCCESS.getCode());
temMsg.setOperateCode(SourceOperateCodeEnum.DEV_INIT_GATHER_01.getValue());
temMsg.setRequestId(SourceOperateCodeEnum.YJC_SBTXJY.getValue());
WebServiceManager.sendMsg(param.getUserPageId(), JSON.toJSONString(temMsg));
//开始进行协议校验
successComm.clear();
failComm.clear();
@@ -1011,7 +1008,7 @@ public class SocketDevResponseService {
* @param list
* @return
*/
private Integer getErrorType(String desc, DevData.SqlDataDTO.ListDTO list) {
public static Integer getErrorType(String desc, DevData.SqlDataDTO.ListDTO list) {
if (ObjectUtil.isNotNull(list)) {
if (DetectionCodeEnum.MAG.getCode().equals(desc) || DetectionCodeEnum.DUR.getCode().equals(desc)) {
if (ObjectUtil.isNull(list.getA()) && ObjectUtil.isNull(list.getB()) && ObjectUtil.isNull(list.getC()) && ObjectUtil.isNull(list.getT())) {
@@ -1190,7 +1187,6 @@ public class SocketDevResponseService {
case UNPROCESSED_BUSINESS:
break;
case NORMAL_RESPONSE:
if (devData.getResult()) {
devInfo.add(devData);
@@ -1479,7 +1475,7 @@ public class SocketDevResponseService {
switch (operateCodeEnum) {
case QUIT_INIT_01:
SocketManager.removeUser(s);
CnSocketUtil.quitSendSource(param);
// CnSocketUtil.quitSendSource(param);
break;
case QUIT_INIT_02:
socketMsg.setRequestId(SourceOperateCodeEnum.QUITE.getValue());
@@ -1666,26 +1662,10 @@ public class SocketDevResponseService {
* @return
*/
private Boolean phaseBoolean(SourceIssue.ChannelListDTO channelListDTO, Double devPhase) {
Double phase = devPhase;
if (devPhase < -180) {
phase = devPhase + 360;
}
if (devPhase > 180) {
phase = devPhase - 360;
}
devPhase = DetectionUtil.adjustPhase(devPhase);
Double fPhase = channelListDTO.getFPhase();
if (fPhase < -180) {
fPhase = fPhase + 360;
}
if (fPhase > 180) {
fPhase = fPhase - 360;
}
return
NumberUtil.isIn(BigDecimal.valueOf(phase),
BigDecimal.valueOf(fPhase - 1),
BigDecimal.valueOf(fPhase + 1));
fPhase = DetectionUtil.adjustPhase(fPhase);
return NumberUtil.isIn(BigDecimal.valueOf(devPhase), BigDecimal.valueOf(fPhase - 1), BigDecimal.valueOf(fPhase + 1));
}
@@ -1811,10 +1791,10 @@ public class SocketDevResponseService {
// Runnable runnable = () -> {
System.out.println("原始数据插入数据库开始执行=========================================");
List<AdNonHarmonicResult> adNonHarmonicResultList = new ArrayList<>();
List<AdHarmonicResult> adHarmonicResultList = new ArrayList<>();
List<SimAndDigNonHarmonicResult> simAndDigNonHarmonicResultList = new ArrayList<>();
List<SimAndDigHarmonicResult> adHarmonicResultList = new ArrayList<>();
for (DevData data : devDataList) {
LocalDateTime localDateTime = timeFormat(data.getTime(), formatter);
LocalDateTime localDateTime = DetectionUtil.timeFormat(data.getTime(), formatter);
if (Objects.nonNull(localDateTime)) {
String[] splitArr = data.getId().split(CnSocketUtil.SPLIT_TAG);
@@ -1823,7 +1803,7 @@ public class SocketDevResponseService {
if (nonHarmonicList.contains(sourceIssue.getType())) {
for (DevData.SqlDataDTO sqlDataDTO : data.getSqlData()) {
DevData.SqlDataDTO.ListDTO listDTO = sqlDataDTO.getList();
AdNonHarmonicResult adNonHarmonicResult = new AdNonHarmonicResult();
SimAndDigNonHarmonicResult adNonHarmonicResult = new SimAndDigNonHarmonicResult();
adNonHarmonicResult.setTimeId(localDateTime);
adNonHarmonicResult.setMonitorId(temId);
adNonHarmonicResult.setScriptId(param.getScriptId());
@@ -1848,14 +1828,14 @@ public class SocketDevResponseService {
if (Objects.nonNull(d)) {
adNonHarmonicResult.setTValue(String.format("%.7f", d));
}
adNonHarmonicResultList.add(adNonHarmonicResult);
simAndDigNonHarmonicResultList.add(adNonHarmonicResult);
}
} else {
for (int j = 0; j < data.getSqlDataHarm().size(); j++) {
DevData.SqlDataHarmDTO sqlDataDTO = data.getSqlDataHarm().get(j);
String dui = harmonicRelationMap.get(sqlDataDTO.getDesc());
AdHarmonicResult adHarmonicResult = new AdHarmonicResult();
SimAndDigHarmonicResult adHarmonicResult = new SimAndDigHarmonicResult();
adHarmonicResult.setTimeId(localDateTime);
adHarmonicResult.setMonitorId(temId);
@@ -1888,7 +1868,7 @@ public class SocketDevResponseService {
List<String> b = tem.getB();
List<String> c = tem.getC();
Class<AdHarmonicResult> example = (Class<AdHarmonicResult>) adHarmonicResult.getClass();
Class<SimAndDigHarmonicResult> example = (Class<SimAndDigHarmonicResult>) adHarmonicResult.getClass();
if (DicDataEnum.HSV.getCode().equals(sourceIssue.getType()) || DicDataEnum.HSI.getCode().equals(sourceIssue.getType())) {
for (int i = 1; i < a.size() + 1; i++) {
try {
@@ -1930,9 +1910,9 @@ public class SocketDevResponseService {
}
}
if (CollUtil.isNotEmpty(adNonHarmonicResultList)) {
Map<String, List<AdNonHarmonicResult>> map = adNonHarmonicResultList.stream().collect(Collectors.groupingBy(x -> x.getMonitorId() + x.getTimeId() + x.getScriptId() + x.getSort() + x.getAdType() + x.getDataType()));
List<AdNonHarmonicResult> info = new ArrayList<>();
if (CollUtil.isNotEmpty(simAndDigNonHarmonicResultList)) {
Map<String, List<SimAndDigNonHarmonicResult>> map = simAndDigNonHarmonicResultList.stream().collect(Collectors.groupingBy(x -> x.getMonitorId() + x.getTimeId() + x.getScriptId() + x.getSort() + x.getAdType() + x.getDataType()));
List<SimAndDigNonHarmonicResult> info = new ArrayList<>();
map.forEach((key, value) -> {
if (value.size() > 1) {
System.err.println("重复时间戳->" + key + value);
@@ -1944,8 +1924,8 @@ public class SocketDevResponseService {
detectionDataDealService.acceptAdNon(info, param.getCode());
}
if (CollUtil.isNotEmpty(adHarmonicResultList)) {
Map<String, List<AdHarmonicResult>> map = adHarmonicResultList.stream().collect(Collectors.groupingBy(x -> x.getMonitorId() + x.getTimeId() + x.getScriptId() + x.getSort() + x.getAdType() + x.getDataType()));
List<AdHarmonicResult> info = new ArrayList<>();
Map<String, List<SimAndDigHarmonicResult>> map = adHarmonicResultList.stream().collect(Collectors.groupingBy(x -> x.getMonitorId() + x.getTimeId() + x.getScriptId() + x.getSort() + x.getAdType() + x.getDataType()));
List<SimAndDigHarmonicResult> info = new ArrayList<>();
map.forEach((key, value) -> {
if (value.size() > 1) {
System.err.println("重复时间戳->" + key + value);
@@ -1961,18 +1941,6 @@ public class SocketDevResponseService {
}
private LocalDateTime timeFormat(String dateTimeStr, DateTimeFormatter formatter) {
try {
ZonedDateTime zonedDateTime = ZonedDateTime.parse(dateTimeStr, formatter.withZone(ZoneId.of("UTC")));
LocalDateTime localDateTime = zonedDateTime.toLocalDateTime();
return localDateTime;
} catch (DateTimeParseException e) {
System.err.println("日期时间字符串格式错误: " + e.getMessage());
return null;
}
}
/**
* 向前端推送消息
*

View File

@@ -29,16 +29,12 @@ public enum DetectionCodeEnum {
I_UNBAN("I_UNBAN", "三相电流负序不平衡度"),
PST("PST", "短时间闪变"),
P_FUND("P_FUND", "功率"),
I1("I1", "基波电流"),
UNKNOWN_ERROR("-1", "未知异常"),
;
STAR("Star","星型接线"),
DELTA("Delta","角型接线");
private final String code;
private final String message;

View File

@@ -48,6 +48,8 @@ public enum SourceOperateCodeEnum {
YJC_SBTXJY("yjc_sbtxjy", "设备通讯检测"),
YJC_XYJY("yjc_xyjy", "协议校验"),
YJC_XUJY("YJC_xujy", "相序校验"),
YJC_ALIGN("YJC_align","实时数据对齐校验"),
YJC_MXYZXJY("YJC_mxyzxjy", "模型一致性校验"),
FORMAL_REAL("formal_real","正式检测"),
// SIMULATE_REAL("simulate_real","模拟检测"),
Coefficient_Check("Coefficient_Check","系数校验"),
@@ -78,7 +80,6 @@ public enum SourceOperateCodeEnum {
// TEST_TEM_STOP("5","临时停止"),
ALL_TEST("1","全部检测"),
RE_ERROR_TEST("2","不合格项复检"),
TEST_TEM_START("3","继续检测"),
SIMULATE_TEST("4","模拟检测"),
//TEST_STOP("7","停止检测"),
//FAST_TEST("10","一键检测"),
@@ -99,10 +100,7 @@ public enum SourceOperateCodeEnum {
/**
* ftp文件传送指令
*/
FTP_SEND_01("FTP_SEND$01", "发送文件")
;
FTP_SEND_01("FTP_SEND$01", "发送文件"),;
private final String value;
private final String msg;

View File

@@ -31,6 +31,9 @@ public class ContrastDetectionParam {
@NotEmpty(message = DetectionValidMessage.STANDARD_DEV_IDS_NOT_EMPTY)
private List<String> standardDevIds;
/**
* key为 标准设备ID_检测点序号、value为 被检设备ID_检测点序号
*/
@ApiModelProperty("配对关系")
@NotEmpty(message = DetectionValidMessage.PAIRS_NOT_EMPTY)
private Map<String,String> pairs;

View File

@@ -1,6 +1,7 @@
package com.njcn.gather.detection.service.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSON;
@@ -23,8 +24,10 @@ import com.njcn.gather.detection.util.socket.FormalTestManager;
import com.njcn.gather.detection.util.socket.SocketManager;
import com.njcn.gather.detection.util.socket.WebServiceManager;
import com.njcn.gather.detection.util.socket.cilent.NettyClient;
import com.njcn.gather.detection.util.socket.cilent.NettyContrastClientHandler;
import com.njcn.gather.detection.util.socket.cilent.NettySourceClientHandler;
import com.njcn.gather.device.pojo.po.PqDev;
import com.njcn.gather.device.pojo.vo.PreDetection;
import com.njcn.gather.device.service.IPqDevService;
import com.njcn.gather.plan.pojo.po.AdPlan;
import com.njcn.gather.plan.pojo.po.AdPlanSource;
@@ -45,7 +48,10 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;
@@ -292,19 +298,35 @@ public class PreDetectionServiceImpl implements PreDetectionService {
private void sendContrastSocket(ContrastDetectionParam param) {
String s = param.getUserId() + CnSocketUtil.DEV_TAG;
// Map<String, List<PreDetection>> map = new HashMap<>(1);
// List<PreDetection> preDetections = BeanUtil.copyToList(FormalTestManager.devList, PreDetection.class);
// preDetections.forEach(x -> {
// x.setDevType(x.getIcdType());
// });
// map.put("deviceList", preDetections);
// String jsonString = JSON.toJSONString(map);
// socketMsg.setRequestId(SourceOperateCodeEnum.YJC_SBTXJY.getValue());
// socketMsg.setOperateCode(SourceOperateCodeEnum.DEV_INIT_GATHER_01.getValue());
// socketMsg.setData(jsonString);
// String json = JSON.toJSONString(socketMsg);
// SocketManager.sendMsg(s,json);
// NettyClient.socketClient(ip, port, param, json, new NettyDevClientHandler(param, socketDevResponseService));
Map<String, List<PreDetection>> map = new HashMap<>(1);
List<PreDetection> preDetections = BeanUtil.copyToList(FormalTestManager.devList, PreDetection.class);
preDetections.addAll(BeanUtil.copyToList(FormalTestManager.standardDevList, PreDetection.class));
preDetections.forEach(x -> {
x.setDevType(x.getIcdType());
x.getMonitorList().forEach(y -> {
String pt = y.getPt();
int i = pt.indexOf(":");
y.setPt(BigDecimal.valueOf(Double.parseDouble(pt.substring(0, i))).divide(BigDecimal.valueOf(Double.parseDouble(pt.substring(i + 1))), 5, BigDecimal.ROUND_HALF_UP) + "");
String ct = y.getCt();
i = ct.indexOf(":");
y.setCt(BigDecimal.valueOf(Double.parseDouble(ct.substring(0, i))).divide(BigDecimal.valueOf(Double.parseDouble(ct.substring(i + 1))), 5, BigDecimal.ROUND_HALF_UP) + "");
});
});
map.put("deviceList", preDetections);
String jsonString = JSON.toJSONString(map);
SocketMsg<String> socketMsg = new SocketMsg<>();
socketMsg.setRequestId(SourceOperateCodeEnum.YJC_SBTXJY.getValue());
socketMsg.setOperateCode(SourceOperateCodeEnum.DEV_INIT_GATHER_01.getValue());
socketMsg.setData(jsonString);
String json = JSON.toJSONString(socketMsg);
SocketManager.sendMsg(s, json);
PreDetectionParam preDetectionParam = new PreDetectionParam();
preDetectionParam.setUserPageId(param.getUserId());
NettyClient.socketClient(ip, port, preDetectionParam, json, new NettyContrastClientHandler(preDetectionParam, socketContrastResponseService));
}
/**

View File

@@ -0,0 +1,219 @@
package com.njcn.gather.detection.util;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjectUtil;
import com.njcn.gather.detection.pojo.po.DevData;
import com.njcn.gather.detection.service.impl.DetectionServiceImpl;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
/**
* @author caozehui
* @data 2025-07-28
*/
public class DetectionUtil {
/**
* 相角矫正到统一个区间
*
* @param phase
* @return
*/
public static Double adjustPhase(Double phase) {
if (phase < -180) {
return phase + 360;
}
if (phase > 180) {
return phase - 360;
}
return phase;
}
/**
* 判断数据是否对齐
*
* @param devData 被检设备数据
* @param standardDevData 标准设备数据
* @return
*/
public static boolean isAlignData(DevData devData, DevData standardDevData) {
if (ObjectUtil.isNotNull(devData) && ObjectUtil.isNotNull(standardDevData)) {
long devMillis = getMillis(devData.getTime());
long standardMillis = getMillis(standardDevData.getTime());
if (BigDecimal.valueOf(devMillis).divide(BigDecimal.valueOf(10), 0, BigDecimal.ROUND_HALF_UP).compareTo(BigDecimal.valueOf(standardMillis).divide(BigDecimal.valueOf(10), 0, BigDecimal.ROUND_HALF_UP)) == 0) {
return true;
} else if (Math.abs(devMillis - standardMillis) < 100) {
return true;
}
}
return false;
}
/**
* 将字符串日期时间转换为指定格式的LocalDateTime
*
* @param dateTimeStr
* @param formatter
* @return
*/
public static LocalDateTime timeFormat(String dateTimeStr, DateTimeFormatter formatter) {
try {
ZonedDateTime zonedDateTime = ZonedDateTime.parse(dateTimeStr, formatter.withZone(ZoneId.of("UTC")));
LocalDateTime localDateTime = zonedDateTime.toLocalDateTime();
return localDateTime;
} catch (DateTimeParseException e) {
System.err.println("日期时间字符串格式错误: " + e.getMessage());
return null;
}
}
/**
* 获取字符串日期时间对应的毫秒数
*
* @param dateTimeStr
* @return
*/
public static long getMillis(String dateTimeStr) {
LocalDateTime localDateTime = timeFormat(dateTimeStr, DateTimeFormatter.ISO_DATE_TIME);
return getMillis(localDateTime);
}
/**
* 获取LocalDateTime的所对应的毫秒数
*
* @param localDateTime
* @return
*/
public static long getMillis(LocalDateTime localDateTime) {
return localDateTime.atZone(ZoneId.of("UTC")).toInstant().toEpochMilli();
}
/**
* 判断value是否为0
* @param value
* @return
*/
public static boolean isZero(Double value) {
BigDecimal bd = BigDecimal.valueOf(value);
if(bd.subtract(BigDecimal.ZERO).abs().compareTo(BigDecimal.valueOf(0.001)) < 0){
return true;
}
return false;
}
/**
* 获取CP95值
*
* @param t
* @return
*/
public static List<Double> getCP95Doubles(List<Double> t) {
if (CollUtil.isNotEmpty(t)) {
if (t.size() < 21) {
if (t.size() == 1) {
return t;
}
if (t.size() > 1) {
return t.subList(1, 2);
}
} else {
int v = (int) (t.size() * 0.5);
return t.subList(v, v + 1);
}
}
return t;
}
/**
* 获取CP95值所在索引
*
* @param t
* @return
*/
public static int getCP95Idx(List<Double> t) {
if (CollUtil.isNotEmpty(t)) {
if (t.size() < 21) {
if (t.size() == 1) {
return 0;
}
if (t.size() > 1) {
return 1;
}
} else {
int v = (int) (t.size() * 0.5);
return v;
}
}
return -1;
}
/**
* 获取部分值
*
* @param t
* @return
*/
public static List<Double> getSectionValueDoubles(List<Double> t) {
if (CollUtil.isNotEmpty(t)) {
if (t.size() > 2) {
Double max = Collections.max(t);
Double min = Collections.min(t);
t.remove(max);
t.remove(min);
}
}
return t;
}
/**
* 获取平均值
*
* @param t
* @return
*/
public static List<Double> getAvgDoubles(List<Double> t) {
if (CollUtil.isNotEmpty(t)) {
t = Arrays.asList(t.stream().mapToDouble(Double::doubleValue).average().orElse(0.0));
}
return t;
}
/**
* 对list进行从大到小排序并返回排序后的索引序列
*
* @param list
* @return
*/
public static List<Integer> sort(List<Double> list) {
List<Integer> indexList = Stream.iterate(0, i -> i + 1).limit(list.size()).collect(Collectors.toList());
for (int i = 0; i < list.size(); i++) {
int maxIdx = i;
for (int j = i + 1; j < list.size(); j++) {
if (list.get(j) > list.get(maxIdx)) {
maxIdx = j;
}
}
if (maxIdx != i) {
double temp = list.get(i);
list.set(i, list.get(maxIdx));
list.set(maxIdx, temp);
int tempIdx = indexList.get(i);
indexList.set(i, indexList.get(maxIdx));
indexList.set(maxIdx, tempIdx);
}
}
return indexList;
}
}

View File

@@ -1,8 +1,11 @@
package com.njcn.gather.detection.util.socket;
import com.google.common.collect.HashBiMap;
import com.njcn.gather.detection.pojo.po.DevData;
import com.njcn.gather.device.pojo.po.PqStandardDev;
import com.njcn.gather.device.pojo.vo.PreDetection;
import com.njcn.gather.plan.pojo.po.AdPlan;
import com.njcn.gather.system.dictionary.pojo.enums.DictDataEnum;
import java.util.ArrayList;
import java.util.HashMap;
@@ -13,68 +16,98 @@ import java.util.concurrent.ConcurrentHashMap;
/**
* @Author: cdf
* @CreateTime: 2025-01-08
* @Description: 正式检测对象管理
* @Description: 正式(预)检测对象管理
*/
public class FormalTestManager {
/**
* key:设备ip,value:当前设备下面的通道
* key:设备ip,value:当前设备下面的通道号
*/
public static Map<String,List<String>> devMapMonitorNum = new ConcurrentHashMap<>();
public static Map<String, List<String>> devMapMonitorNum = new ConcurrentHashMap<>();
/**
* 所有参与检测的装置
* 所有参与检测的被检设备
*/
public static List<PreDetection> devList = new ArrayList<>();
/**
* 所有参与检测的标准设备
*/
public static List<PreDetection> standardDevList = new ArrayList<>();
/**
* 所有参与检测的监测点
*/
public static List<String> monitorIdListComm = new ArrayList<>();
/**
* 所有参与检测的监测点。key:监测点idip_通道号,value:检测点实体
*/
public static Map<String, PreDetection.MonitorListDTO> monitorMap = new HashMap<>();
//用于存储所有测点的实时数据
/**
* 用于存储所有测点的实时数据
*/
public static List<DevData> realDataXiList = new ArrayList<>();
/**
* key:设备ip,value:装置名称
*/
public static Map<String, String> devNameMapComm = new HashMap<>();
/**
* key:设备ip,value:装置id
*/
public static Map<String, String> devIdMapComm = new HashMap<>();
/**
* 停止触发标识
*/
public static Boolean stopFlag = false;
/**
* 已经暂停后的标识
*/
public static Boolean hasStopFlag = false;
/**
* 暂停后的超时计时时间
*/
public static Integer stopTime = 0;
/**
* 强行赋值关系
*/
public static Map<String,String> harmonicRelationMap = new HashMap<>();
public static Map<String, String> harmonicRelationMap = new HashMap<>();
/**
* 当前正在检测的计划
*/
public static AdPlan currentTestPlan;
/**
* 比对式检测-检测项。
*/
public static List<String> testItemCodeList = new ArrayList<>();
/**
* 数据处理原则
*/
public static DictDataEnum dataRule;
/**
* 所有参与比对式检测的被检设备、标准设备配对关系。key:标准设备id_通道号,value:被检设备id_通道号
*/
public static Map<String, String> pairsMap = HashBiMap.create();
/**
* 被检设备的数据。key:设备ip_通道号,value:DevData数据集合
*/
public static Map<String, List<DevData>> devDataMap = new HashMap<>();
/**
* 标准设备的数据。key:设备ip_通道号,value:DevData数据集合
*/
public static Map<String, List<DevData>> standardDevDataMap = new HashMap<>();
}

View File

@@ -1,6 +1,7 @@
package com.njcn.gather.detection.util.socket;
import cn.hutool.core.util.ObjectUtil;
import com.njcn.gather.plan.pojo.enums.DataSourceEnum;
import com.njcn.gather.script.pojo.po.SourceIssue;
import io.netty.channel.Channel;
import io.netty.channel.nio.NioEventLoopGroup;
@@ -94,6 +95,10 @@ public class SocketManager {
*/
public static volatile Map<Integer,Long> clockMap = new ConcurrentHashMap<>();
/**
* 用于存储比对式测试时间。
*/
public static volatile Map<DataSourceEnum, Long> contrastClockMap = new ConcurrentHashMap<>();

View File

@@ -106,9 +106,12 @@ public class NettyClient {
socketDataMsg.setRequestId("connect");
if (handler instanceof NettySourceClientHandler) {
socketDataMsg.setOperateCode("Source");
} else {
} else if (handler instanceof NettyDevClientHandler) {
CnSocketUtil.quitSendSource(param);
socketDataMsg.setOperateCode("Dev");
} else {
socketDataMsg.setOperateCode("Dev");
CnSocketUtil.quitSend(param);
}
WebServiceManager.sendMsg(param.getUserPageId(), JSON.toJSONString(socketDataMsg));
} finally {

View File

@@ -1,23 +1,181 @@
package com.njcn.gather.detection.util.socket.cilent;
import com.njcn.gather.detection.handler.SocketContrastResponseService;
import com.njcn.gather.detection.pojo.enums.SourceOperateCodeEnum;
import com.njcn.gather.detection.pojo.param.PreDetectionParam;
import com.njcn.gather.detection.util.socket.CnSocketUtil;
import com.njcn.gather.detection.util.socket.SocketManager;
import com.njcn.gather.plan.pojo.enums.DataSourceEnum;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.handler.timeout.IdleState;
import io.netty.handler.timeout.IdleStateEvent;
import io.netty.handler.timeout.TimeoutException;
import lombok.RequiredArgsConstructor;
import java.io.IOException;
import java.net.ConnectException;
import java.net.ProtocolException;
import java.time.LocalDateTime;
import java.util.Objects;
/**
* @author caozehui
* @data 2025-07-18
* @data 2025-07-25
*/
@RequiredArgsConstructor
public class NettyContrastClientHandler extends SimpleChannelInboundHandler<String> {
private final PreDetectionParam param;
private final SocketContrastResponseService socketContrastResponseService;
@Override
protected void channelRead0(ChannelHandlerContext channelHandlerContext, String s) throws Exception {
public void channelActive(ChannelHandlerContext ctx) throws Exception {
System.out.println("客户端通道已建立" + ctx.channel().id());
Channel channel = SocketManager.getChannelByUserId(param.getUserPageId() + CnSocketUtil.DEV_TAG);
if (Objects.nonNull(channel)) {
try {
channel.close().sync();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
SocketManager.addUser(param.getUserPageId() + CnSocketUtil.DEV_TAG, ctx.channel());
}
@Override
protected void channelRead0(ChannelHandlerContext ctx, String msg) throws InterruptedException {
System.out.println("contrastClientHandler接收server端数据>>>>>>" + msg);
try {
socketContrastResponseService.deal(param, msg);
} catch (Exception e) {
e.printStackTrace();
CnSocketUtil.quitSend(param);
}
}
@Override
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
System.out.println("与通信模块端断线");
ctx.close();
SocketManager.removeUser(param.getUserPageId() + CnSocketUtil.DEV_TAG);
}
/**
* 用户事件的回调方法(自定义事件用于心跳机制)
*
* @param ctx
* @param evt
*/
@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) {
if (evt instanceof IdleStateEvent) { //IdleState.在一段时间内没有收到任何消息时,会触发该事件
if (((IdleStateEvent) evt).state() == IdleState.READER_IDLE) {
System.out.println(LocalDateTime.now() + "contrastClientHandler触发读超时函数**************************************");
SocketManager.contrastClockMap.put(DataSourceEnum.REAL_DATA, SocketManager.contrastClockMap.get(DataSourceEnum.REAL_DATA) + 60L);
//实时数据
if (SocketManager.contrastClockMap.get(DataSourceEnum.REAL_DATA) >= 60) {
CnSocketUtil.quitSend(param);
System.out.println("超时处理-----》" + "实时数据已超时----------------关闭");
timeoutSend();
}
// if (!FormalTestManager.hasStopFlag) {
// if (CollUtil.isNotEmpty(SocketManager.getSourceList())) {
// SourceIssue sourceIssue = SocketManager.getSourceList().get(0);
// if (SocketManager.clockMap.containsKey(sourceIssue.getIndex())) {
// SocketManager.clockMap.put(sourceIssue.getIndex(), SocketManager.clockMap.get(sourceIssue.getIndex()) + 60L);
// } else {
// SocketManager.clockMap.put(sourceIssue.getIndex(), 60L);
// }
//
// if (sourceIssue.getType().equals(DicDataEnum.F.getCode())) {
// //闪变,正常抛一轮最大等待20分钟超时
// if (SocketManager.clockMap.get(sourceIssue.getIndex()) > 1300) {
// fly = true;
// System.out.println("超时处理-----》" + sourceIssue.getType() + "已超时----------------关闭");
// CnSocketUtil.quitSend(param);
// timeoutSend(sourceIssue);
// }
// } else if (sourceIssue.getType().equals(DicDataEnum.VOLTAGE.getCode()) || sourceIssue.getType().equals(DicDataEnum.HP.getCode())) {
// //统计数据项,正常抛一轮数据,超时
// if (SocketManager.clockMap.get(sourceIssue.getIndex()) > 180) {
// fly = true;
// CnSocketUtil.quitSend(param);
// System.out.println("超时处理-----》" + sourceIssue.getType() + "已超时----------------关闭");
// timeoutSend(sourceIssue);
// }
// } else {
// //实时数据
// if (SocketManager.clockMap.get(sourceIssue.getIndex()) > 60) {
// fly = true;
// CnSocketUtil.quitSend(param);
// System.out.println("超时处理-----》" + sourceIssue.getType() + "已超时----------------关闭");
// timeoutSend(sourceIssue);
// }
// }
// } else {
// fly = true;
// //为空则认为是常规步骤,设定一分钟超时
// CnSocketUtil.quitSend(param);
// CnSocketUtil.sendToWebSocket(param.getUserPageId(), SourceOperateCodeEnum.SOCKET_TIMEOUT.getValue(), SourceOperateCodeEnum.SOCKET_TIMEOUT.getValue(), SourceOperateCodeEnum.SOCKET_TIMEOUT.getMsg(), null);
// }
// if (fly) {
// socketContrastResponseService.backCheckState(param);
// }
// } else {
// //如果是暂停操作后
// FormalTestManager.stopTime += 60;
// System.out.println("当前进入暂停操作超时函数-----------------" + FormalTestManager.stopTime);
// if (FormalTestManager.stopTime > 600) {
// CnSocketUtil.quitSend(param);
// CnSocketUtil.sendToWebSocket(param.getUserPageId(), SourceOperateCodeEnum.FORMAL_REAL.getValue(), SourceOperateCodeEnum.STOP_TIMEOUT.getValue(), SourceOperateCodeEnum.STOP_TIMEOUT.getMsg(), null);
// }
// }
}
}
}
@Override
public void handlerAdded(ChannelHandlerContext ctx) {
System.out.println("有通道准备接入" + ctx.channel());
}
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
System.out.println("捕获到通信模块服务异常。。。。。。。");
// 处理异常,例如记录日志、关闭连接等
cause.printStackTrace();
// 根据异常类型进行不同的处理
if (cause instanceof ConnectException) {
System.out.println("连接socket服务端异常");
} else if (cause instanceof IOException) {
System.out.println("IOException caught: There was an I/O error.");
CnSocketUtil.sendToWebSocket(param.getUserPageId(), SourceOperateCodeEnum.DEVICE_ERROR.getValue(), SourceOperateCodeEnum.DEVICE_ERROR.getValue(), SourceOperateCodeEnum.DEVICE_ERROR.getMsg(), null);
} else if (cause instanceof TimeoutException) {
System.out.println("TimeoutException caught: Operation timed out.");
} else if (cause instanceof ProtocolException) {
System.out.println("ProtocolException caught: Invalid protocol message.");
} else {
// 处理其他类型的异常
System.out.println("Unknown exception caught: " + cause.getMessage());
CnSocketUtil.sendToWebSocket(param.getUserPageId(), SourceOperateCodeEnum.DEVICE_ERROR.getValue(), SourceOperateCodeEnum.DEVICE_ERROR.getValue(), SourceOperateCodeEnum.DEVICE_ERROR.getMsg(), null);
}
CnSocketUtil.quitSend(param);
// socketContrastResponseService.backCheckState(param);
ctx.close();
}
/**
* 接收数据超时处理
*/
private void timeoutSend() {
}
}

View File

@@ -6,10 +6,11 @@ import com.njcn.gather.detection.handler.SocketDevResponseService;
import com.njcn.gather.detection.pojo.enums.SourceOperateCodeEnum;
import com.njcn.gather.detection.pojo.param.PreDetectionParam;
import com.njcn.gather.detection.pojo.vo.DevLineTestResult;
import com.njcn.gather.detection.pojo.vo.SocketDataMsg;
import com.njcn.gather.detection.pojo.vo.SocketMsg;
import com.njcn.gather.detection.pojo.vo.WebSocketVO;
import com.njcn.gather.detection.util.socket.*;
import com.njcn.gather.detection.util.socket.CnSocketUtil;
import com.njcn.gather.detection.util.socket.FormalTestManager;
import com.njcn.gather.detection.util.socket.SocketManager;
import com.njcn.gather.detection.util.socket.WebServiceManager;
import com.njcn.gather.device.pojo.vo.PreDetection;
import com.njcn.gather.script.pojo.po.SourceIssue;
import com.njcn.gather.system.pojo.enums.DicDataEnum;
@@ -25,11 +26,9 @@ import java.io.IOException;
import java.net.ConnectException;
import java.net.ProtocolException;
import java.time.LocalDateTime;
import java.util.*;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
/**
@@ -41,8 +40,6 @@ import java.util.concurrent.TimeUnit;
@RequiredArgsConstructor
public class NettyDevClientHandler extends SimpleChannelInboundHandler<String> {
private final String dev = "_Dev";
private final PreDetectionParam param;
private final SocketDevResponseService socketResponseService;
@@ -56,7 +53,7 @@ public class NettyDevClientHandler extends SimpleChannelInboundHandler<String> {
@Override
public void channelActive(ChannelHandlerContext ctx) throws Exception {
System.out.println("客户端通道已建立" + ctx.channel().id());
Channel channel = SocketManager.getChannelByUserId(param.getUserPageId() + dev);
Channel channel = SocketManager.getChannelByUserId(param.getUserPageId() + CnSocketUtil.DEV_TAG);
if (Objects.nonNull(channel)) {
try {
channel.close().sync();
@@ -64,7 +61,7 @@ public class NettyDevClientHandler extends SimpleChannelInboundHandler<String> {
e.printStackTrace();
}
}
SocketManager.addUser(param.getUserPageId() + dev, ctx.channel());
SocketManager.addUser(param.getUserPageId() + CnSocketUtil.DEV_TAG, ctx.channel());
}
/**
@@ -79,8 +76,6 @@ public class NettyDevClientHandler extends SimpleChannelInboundHandler<String> {
e.printStackTrace();
CnSocketUtil.quitSend(param);
}
}
/**
@@ -92,7 +87,7 @@ public class NettyDevClientHandler extends SimpleChannelInboundHandler<String> {
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
System.out.println("设备通讯客户端断线");
ctx.close();
SocketManager.removeUser(param.getUserPageId() + dev);
SocketManager.removeUser(param.getUserPageId() + CnSocketUtil.DEV_TAG);
CnSocketUtil.quitSendSource(param);
}
@@ -243,7 +238,7 @@ public class NettyDevClientHandler extends SimpleChannelInboundHandler<String> {
devListRes.add(devLineTestResult);
});
WebSocketVO<List<DevLineTestResult>> socketVO = new WebSocketVO<>();
socketVO.setRequestId(sourceIssue.getType() + "_End");
socketVO.setRequestId(sourceIssue.getType() + CnSocketUtil.END_TAG);
socketVO.setOperateCode(sourceIssue.getType());
socketVO.setData(devListRes);
WebServiceManager.sendMsg(param.getUserPageId(), JSON.toJSONString(socketVO));

View File

@@ -28,7 +28,6 @@ import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
/**
* @author caozehui
* @date 2025-07-02

View File

@@ -2,6 +2,10 @@ package com.njcn.gather.device.mapper;
import com.github.yulichang.base.MPJBaseMapper;
import com.njcn.gather.device.pojo.po.PqStandardDev;
import com.njcn.gather.device.pojo.vo.PreDetection;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* @author makejava
@@ -9,5 +13,6 @@ import com.njcn.gather.device.pojo.po.PqStandardDev;
*/
public interface PqStandardDevMapper extends MPJBaseMapper<PqStandardDev> {
List<PreDetection> listStandardDevPreDetection(@Param("devIds") List<String> ids);
}

View File

@@ -2,6 +2,47 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.njcn.gather.device.mapper.PqStandardDevMapper">
<!-- 通用查询映射结果 -->
<resultMap id="standardDevResultMap" type="com.njcn.gather.device.pojo.vo.PreDetection">
<id column="Id" property="devId"/>
<id column="Name" property="devName"/>
<id column="IP" property="devIP"/>
<result column="Port" property="port"/>
<result column="Dev_Type" property="devType"/>
<result column="Series" property="devCode"/>
<result column="Dev_Key" property="devKey"/>
<result column="icdType" property="icdType"/>
<result column="Dev_Chns" property="devChns"/>
<result column="Dev_Volt" property="devVolt"/>
<result column="Dev_Curr" property="devCurr"/>
<!-- <collection-->
<!-- property="monitorList"-->
<!-- column="{ devId = Id}"-->
<!-- select="com.njcn.gather.monitor.mapper.PqMonitorMapper.selectMonitorInfo"-->
<!-- >-->
<!-- </collection>-->
</resultMap>
<select id="listStandardDevPreDetection" resultMap="standardDevResultMap">
select
standard_dev.Id,
standard_dev.Name,
standard_dev.IP,
standard_dev.Port,
standard_dev.Dev_Type,
standard_dev.Series,
standard_dev.Dev_Key,
dev_type.icdType,
dev_type.Dev_Chns,
dev_type.Dev_Volt,
dev_type.Dev_Curr
from pq_standard_dev standard_dev
inner join pq_dev_type dev_type on standard_dev.Dev_Type = dev_type.id
where standard_dev.Id in
<foreach collection="ids" item="id" open="(" separator="," close=")">
#{id}
</foreach>
</select>
</mapper>

View File

@@ -125,7 +125,7 @@ public class PqDevParam {
private String delegate;
@ApiModelProperty("被检通道")
private List<String> inspectChannel;
private String inspectChannel;
@ApiModelProperty("投运日期")
@DateTimeStrValid(message = DetectionValidMessage.OPERATION_DATE_FORMAT_ERROR)

View File

@@ -50,51 +50,51 @@ public class ContrastDevExcel implements Serializable {
@NotBlank(message = DetectionValidMessage.MANUFACTURER_NOT_BLANK)
private String manufacturer;
@Excel(name = "被检通道", width = 20, needMerge = true, orderNum = "8")
private String inspectChannel;
// @Excel(name = "被检通道", width = 20, needMerge = true, orderNum = "8")
// private String inspectChannel;
@Excel(name = "固件版本", width = 15, needMerge = true, orderNum = "9")
@Excel(name = "固件版本", width = 15, needMerge = true, orderNum = "8")
private String hardwareVersion;
@Excel(name = "软件版本", width = 15, needMerge = true, orderNum = "10")
@Excel(name = "软件版本", width = 15, needMerge = true, orderNum = "9")
private String softwareVersion;
@Excel(name = "通讯协议*", width = 15, needMerge = true, orderNum = "11")
@Excel(name = "通讯协议*", width = 15, needMerge = true, orderNum = "10")
@NotBlank(message = DetectionValidMessage.PROTOCOL_NOT_BLANK)
private String protocol;
@Excel(name = "是否加密*", width = 20, needMerge = true, replace = {"否_0", "是_1"}, orderNum = "12")
@Excel(name = "是否加密*", width = 20, needMerge = true, replace = {"否_0", "是_1"}, orderNum = "11")
@NotNull(message = DetectionValidMessage.ENCRYPTION_NOT_NULL)
private Integer encryptionFlag;
@Excel(name = "识别码(当加密时必填)", width = 30, needMerge = true, orderNum = "13")
@Excel(name = "识别码(当加密时必填)", width = 30, needMerge = true, orderNum = "12")
private String series;
@Excel(name = "秘钥(当加密时必填)", width = 30, needMerge = true, orderNum = "14")
@Excel(name = "秘钥(当加密时必填)", width = 30, needMerge = true, orderNum = "13")
private String devKey;
@Excel(name = "IP地址*", width = 20, needMerge = true, orderNum = "15")
@Excel(name = "IP地址*", width = 20, needMerge = true, orderNum = "14")
@NotBlank(message = DetectionValidMessage.IP_NOT_BLANK)
@Pattern(regexp = PatternRegex.IP_REGEX, message = DetectionValidMessage.IP_FORMAT_ERROR)
private String ip;
@Excel(name = "端口号*", width = 15, needMerge = true, orderNum = "16")
@Excel(name = "端口号*", width = 15, needMerge = true, orderNum = "15")
@NotNull(message = DetectionValidMessage.PORT_NOT_NULL)
@Range(min = 1, max = 65535, message = DetectionValidMessage.PORT_RANGE_ERROR)
private Integer port;
@Excel(name = "投运日期yyyy-MM-dd*", width = 30, needMerge = true, orderNum = "17", format = "yyyy-MM-dd")
@Excel(name = "投运日期yyyy-MM-dd*", width = 30, needMerge = true, orderNum = "16", format = "yyyy-MM-dd")
@NotNull(message = DetectionValidMessage.CREATE_DATE_NOT_NULL)
private LocalDate createDate;
@Excel(name = "定检日期yyyy-MM-dd*", width = 30, needMerge = true, orderNum = "18", format = "yyyy-MM-dd")
@Excel(name = "定检日期yyyy-MM-dd*", width = 30, needMerge = true, orderNum = "17", format = "yyyy-MM-dd")
@NotNull(message = DetectionValidMessage.INSPECT_DATE_NOT_NULL)
private LocalDate inspectDate;
@Excel(name = "谐波系统设备id*", width = 30, needMerge = true, orderNum = "19")
@Excel(name = "谐波系统设备id*", width = 30, needMerge = true, orderNum = "18")
@NotBlank(message = DetectionValidMessage.HARM_SYS_ID_NOT_BLANK)
private String harmSysId;
@ExcelCollection(name = "监测点信息", orderNum = "22")
@ExcelCollection(name = "监测点信息", orderNum = "19")
private List<PqMonitorExcel> pqMonitorExcelList;
}

View File

@@ -18,7 +18,7 @@ import java.util.List;
public class PreDetection {
/**
* 装置ip
* 装置id
*/
@JSONField(serialize = false)
private String devId;
@@ -95,16 +95,28 @@ public class PreDetection {
private Integer line;
/**
* 监测点线路号
* pt
*/
@JSONField(name = "pt")
private Integer pt;
private String pt;
/**
* 监测点线路号
* ct
*/
@JSONField(name = "ct") //todo 是否改为ct
private Integer ct;
private String ct;
/**
* 统计间隔
*/
@JSONField(name = "statInterval")
private Integer statInterval;
/**
* 接线方式
*/
@JSONField(name = "connection")
private String connection;
}
public String getDevKey() {

View File

@@ -2,12 +2,11 @@ package com.njcn.gather.device.service;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import com.njcn.gather.device.pojo.param.PqDevParam;
import com.njcn.gather.device.pojo.param.PqStandardDevParam;
import com.njcn.gather.device.pojo.po.PqStandardDev;
import com.njcn.gather.device.pojo.vo.PreDetection;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
@@ -84,4 +83,12 @@ public interface IPqStandardDevService extends IService<PqStandardDev> {
* @return
*/
List<PqStandardDev> listByPlanId(String planId);
/**
* 查询出标准设备所需的检测信息
*
* @param ids
* @return
*/
List<PreDetection> listStandardDevPreDetection(List<String> ids);
}

View File

@@ -57,6 +57,7 @@ import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.*;
import java.util.regex.Pattern;
@@ -144,7 +145,6 @@ public class PqDevServiceImpl extends ServiceImpl<PqDevMapper, PqDev> implements
if (ObjectUtil.isNotEmpty(pqDevParam.getMonitorList())) {
pqMonitorService.addPqMonitorByDevId(id, pqDevParam.getMonitorList());
}
pqDev.setInspectChannel(String.join(StrUtil.COMMA, pqDevParam.getInspectChannel()));
}
pqDev.setImportFlag(0);
pqDev.setState(DataStateEnum.ENABLE.getCode());
@@ -201,7 +201,6 @@ public class PqDevServiceImpl extends ServiceImpl<PqDevMapper, PqDev> implements
// 比对式设备修改监测点
if (PatternEnum.CONTRAST.getValue().equals(dictDataService.getDictDataById(updateParam.getPattern()).getCode())) {
pqMonitorService.updatePqMonitorByDevId(updateParam.getId(), updateParam.getMonitorList());
pqDev.setInspectChannel(String.join(StrUtil.COMMA, updateParam.getInspectChannel()));
}
return this.updateById(pqDev);
}
@@ -419,8 +418,8 @@ public class PqDevServiceImpl extends ServiceImpl<PqDevMapper, PqDev> implements
monitorListDTO = new PreDetection.MonitorListDTO();
monitorListDTO.setLineId(preDetection.getDevIP() + "_" + i);
monitorListDTO.setLine(i);
monitorListDTO.setPt(1);
monitorListDTO.setCt(1);
monitorListDTO.setPt("1");
monitorListDTO.setCt("1");
monitorList.add(monitorListDTO);
}
preDetection.setMonitorList(monitorList);
@@ -1290,8 +1289,8 @@ public class PqDevServiceImpl extends ServiceImpl<PqDevMapper, PqDev> implements
dictDataList = dictDataService.getDictDataByTypeId(dictType.getId());
pullDown = new PullDown();
pullDown.setFirstCol(startCol + 10);
pullDown.setLastCol(startCol + 10);
pullDown.setFirstCol(startCol + 9);
pullDown.setLastCol(startCol + 9);
pullDown.setStrings(dictDataList.stream().map(DictData::getName).collect(Collectors.toList()));
pullDowns.add(pullDown);
@@ -1299,20 +1298,19 @@ public class PqDevServiceImpl extends ServiceImpl<PqDevMapper, PqDev> implements
// 是否加密
pullDown = new PullDown();
pullDown.setFirstCol(startCol + 11);
pullDown.setLastCol(startCol + 11);
pullDown.setFirstCol(startCol + 10);
pullDown.setLastCol(startCol + 10);
pullDown.setStrings(Arrays.asList("", ""));
pullDowns.add(pullDown);
// 接线方式
dictType = dictTypeService.getByCode("Dev_Connect");
if (ObjectUtil.isNotNull(dictType)) {
dictDataList = dictDataService.getDictDataByTypeId(dictType.getId());
pullDown = new PullDown();
pullDown.setFirstCol(startCol + 25);
pullDown.setLastCol(startCol + 25);
pullDown.setFirstCol(startCol + 24);
pullDown.setLastCol(startCol + 24);
pullDown.setStrings(dictDataList.stream().map(DictData::getName).collect(Collectors.toList()));
pullDowns.add(pullDown);

View File

@@ -20,6 +20,7 @@ import com.njcn.gather.device.mapper.PqStandardDevMapper;
import com.njcn.gather.device.pojo.param.PqStandardDevParam;
import com.njcn.gather.device.pojo.po.PqStandardDev;
import com.njcn.gather.device.pojo.vo.PqStandardDevExcel;
import com.njcn.gather.device.pojo.vo.PreDetection;
import com.njcn.gather.device.service.IPqStandardDevService;
import com.njcn.gather.plan.mapper.AdPlanStandardDevMapper;
import com.njcn.gather.pojo.enums.DetectionResponseEnum;
@@ -155,6 +156,14 @@ public class PqStandardDevServiceImpl extends ServiceImpl<PqStandardDevMapper, P
return adPlanStandardDevMapper.listByPlanId(Collections.singletonList(planId));
}
@Override
public List<PreDetection> listStandardDevPreDetection(List<String> ids) {
if (CollectionUtil.isNotEmpty(ids)) {
return this.baseMapper.listStandardDevPreDetection(ids);
}
return Collections.emptyList();
}
/**
* 导入数据
*

View File

@@ -57,4 +57,10 @@ public interface IPqErrSysDtlsService extends IService<PqErrSysDtls> {
* @return
*/
List<ErrDtlsCheckDataVO> listByPqErrSysIdAndTypes(PqErrSysParam.DetectionParam param);
/**
* 根据误差体系id和脚本类型查询脚本类型
* @return
*/
List<PqErrSysDtls> listPqErrSysDtlsByPqErrSysIdAndScriptType(String errSysId, String scriptType);
}

View File

@@ -155,4 +155,14 @@ public class PqErrSysDtlsServiceImpl extends ServiceImpl<PqErrSysDtlsMapper, PqE
}
return info;
}
@Override
public List<PqErrSysDtls> listPqErrSysDtlsByPqErrSysIdAndScriptType(String errSysId, String scriptType) {
MPJLambdaWrapper<PqErrSysDtls> wrapper = new MPJLambdaWrapper<>();
wrapper.selectAll(PqErrSysDtls.class)
.leftJoin(DictTree.class, DictTree::getId, PqErrSysDtls::getScriptType)
.eq(PqErrSysDtls::getErrorSysId, errSysId)
.eq(DictTree::getId, scriptType);
return this.list(wrapper);
}
}

View File

@@ -4,15 +4,16 @@
<select id="selectMonitorInfo"
resultType="com.njcn.gather.device.pojo.vo.PreDetection$MonitorListDTO">
SELECT
Id as lineId,
Num as line,
pt as pt,
ct as ct
FROM
pq_monitor
WHERE
dev_id = #{devId}
SELECT CONCAT(pq_dev.IP, '_', Num) as lineId,
Num as line,
pt as pt,
ct as ct,
Stat_Interval,
sys_dict_data.Code as `Connection`
FROM pq_monitor
inner join sys_dict_data on pq_monitor.Connection = sys_dict_data.id
inner join pq_dev on pq_monitor.Dev_Id = pq_dev.Id
WHERE Dev_Id = #{devId}
</select>
</mapper>

View File

@@ -30,11 +30,11 @@ public class PqMonitorExcel {
@NotNull(message = DetectionValidMessage.MONITOR_NUM_NOT_NULL)
private Integer num;
@Excel(name = "PT变比*", width = 20, orderNum = "5")
@Excel(name = "PT变比(pt1:pt2)*", width = 20, orderNum = "5")
@NotBlank(message = DetectionValidMessage.PT_NOT_BLANK)
private String pt;
@Excel(name = "CT变比*", width = 20, orderNum = "6")
@Excel(name = "CT变比(ct1:ct2)*", width = 20, orderNum = "6")
@NotBlank(message = DetectionValidMessage.CT_NOT_BLANK)
private String ct;

View File

@@ -8,7 +8,7 @@ import lombok.Getter;
*/
@Getter
public enum DataSourceEnum {
THREE_SENSE_ACTUAL_TIME_DATA("real", "3s实时数据"),
REAL_DATA("real", "3s实时数据"),
MINUTE_STATISTICS_MAX("max", "分钟统计数据-最大"),
MINUTE_STATISTICS_MIN("min", "分钟统计数据-最小"),

View File

@@ -53,7 +53,7 @@ import com.njcn.gather.script.service.IPqScriptService;
import com.njcn.gather.source.pojo.po.PqSource;
import com.njcn.gather.source.service.IPqSourceService;
import com.njcn.gather.storage.pojo.param.StorageParam;
import com.njcn.gather.storage.service.AdHarmonicService;
import com.njcn.gather.storage.service.SimAndDigHarmonicService;
import com.njcn.gather.storage.service.TableGenService;
import com.njcn.gather.system.cfg.pojo.enums.SceneEnum;
import com.njcn.gather.system.cfg.pojo.po.SysTestConfig;
@@ -110,7 +110,7 @@ public class AdPlanServiceImpl extends ServiceImpl<AdPlanMapper, AdPlan> impleme
private final ISysTestConfigService sysTestConfigService;
private final IDevTypeService devTypeService;
private final IDictTypeService dictTypeService;
private final AdHarmonicService adHarmonicService;
private final SimAndDigHarmonicService adHarmonicService;
private final PqDevMapper pqDevMapper;
private final IPqDevSubService pqDevSubService;
private final IAdPlanStandardDevService adPlanStandardDevService;
@@ -192,7 +192,7 @@ public class AdPlanServiceImpl extends ServiceImpl<AdPlanMapper, AdPlan> impleme
}
Map<String, Integer> standardDevIds = adPlanVO.getStandardDevMap();
standardDevIds.putAll(pqStandardDevs.stream().collect(Collectors.toMap(PqStandardDev::getId, obj -> 1)));
adPlanVO.setStandardDevNameStr(adPlanVO.getStandardDevNameStr() + pqStandardDevs.stream().map(PqStandardDev::getName).reduce((a, b) -> a + "," + b).orElse(""));
// adPlanVO.setStandardDevNameStr(adPlanVO.getStandardDevNameStr() + pqStandardDevs.stream().map(PqStandardDev::getName).reduce((a, b) -> a + "," + b).orElse(""));
}
}
@@ -260,9 +260,9 @@ public class AdPlanServiceImpl extends ServiceImpl<AdPlanMapper, AdPlan> impleme
} else {
// 关联检测源
adPlanSourceService.addAdPlanSource(planId, param.getSourceIds());
tableGenService.deleteTable(Arrays.asList(adPlan.getCode().toString()));
tableGenService.genAdNonHarmonicTable(adPlan.getCode().toString());
}
tableGenService.deleteTable(Arrays.asList(adPlan.getCode().toString()));
tableGenService.genTable(adPlan.getCode().toString(), PatternEnum.CONTRAST.getValue().equals(dictData.getCode()));
return true;
}
@@ -332,11 +332,11 @@ public class AdPlanServiceImpl extends ServiceImpl<AdPlanMapper, AdPlan> impleme
List<String> devIds = pqDevVOList.stream().map(PqDevVO::getId).collect(Collectors.toList());
param.getDevIds().removeAll(devIds);
plan2.setTestState(pqDevService.bind(param.getId(), param.getDevIds()));
} else {
// 修改检测计划、检测源关联
adPlanSourceService.updateAdPlanSource(param.getId(), param.getSourceIds());
}
plan2.setTestState(pqDevService.bind(param.getId(), param.getDevIds()));
// 若修改了名称,则修改相关子计划的来源字段
if (!plan1.getName().equals(param.getName()) && CommonEnum.FATHER_ID.getValue().equals(plan1.getFatherPlanId())) {
this.lambdaUpdate().in(AdPlan::getFatherPlanId, plan1.getId()).eq(AdPlan::getState, DataStateEnum.ENABLE.getCode())
@@ -401,6 +401,17 @@ public class AdPlanServiceImpl extends ServiceImpl<AdPlanMapper, AdPlan> impleme
child.put("pid", adPlan.getFatherPlanId());
child.put("name", adPlan.getName());
child.put("timeCheck", adPlan.getTimeCheck());
List<PqStandardDev> pqStandardDevs = adPlanStandardDevMapper.listByPlanId(Collections.singletonList(adPlan.getId()));
List<String> devTypeIdList = pqStandardDevs.stream().map(PqStandardDev::getDevType).collect(Collectors.toList());
if (devTypeIdList.size() > 0) {
List<DevType> devTypeList = devTypeService.listByIds(devTypeIdList);
pqStandardDevs.forEach(pqStandardDev -> {
DevType devType1 = devTypeList.stream().filter(devType -> devType.getId().equals(pqStandardDev.getDevType())).findFirst().get();
pqStandardDev.setDevType(devType1.getName());
});
}
child.put("standardDevs", pqStandardDevs);
children.add(child);
});
}
@@ -463,13 +474,13 @@ public class AdPlanServiceImpl extends ServiceImpl<AdPlanMapper, AdPlan> impleme
// 不合格项复检
if (reCheckType == 0) {
// List<AdBaseResult> allResultList = new ArrayList<>();
// List<SimAndDigBaseResult> allResultList = new ArrayList<>();
// allResultList.addAll(adHarmonicService.get(scriptId, null, devId, "-1", adPlan.getCode()));
// allResultList.addAll(adNonHarmonicService.get(scriptId, null, devId, "-1", adPlan.getCode()));
//
// if (ObjectUtil.isNotEmpty(allResultList)) {
// List<AdBaseResult> passList = allResultList.stream().filter(obj -> obj.getResultFlag() == 1).collect(Collectors.toList());
// TreeSet<Integer> sortSet = passList.stream().map(AdBaseResult::getSort).collect(Collectors.toCollection(TreeSet::new));
// List<SimAndDigBaseResult> passList = allResultList.stream().filter(obj -> obj.getResultFlag() == 1).collect(Collectors.toList());
// TreeSet<Integer> sortSet = passList.stream().map(SimAndDigBaseResult::getSort).collect(Collectors.toCollection(TreeSet::new));
//
// scriptDtlsList = scriptDtlsList.stream().filter(obj -> !sortSet.contains(obj.getScriptIndex())).collect(Collectors.toList());
// }
@@ -909,7 +920,7 @@ public class AdPlanServiceImpl extends ServiceImpl<AdPlanMapper, AdPlan> impleme
pqDevService.importCNDev(cnDevExcelList, patternId, planId);
tableGenService.deleteTable(Arrays.asList(code.toString()));
tableGenService.genAdNonHarmonicTable(code.toString());
tableGenService.genTable(code.toString(), PatternEnum.CONTRAST.getValue().equals(patternCode));
}
// 逆向可视化
this.reverseVisualize(adPlans);
@@ -967,7 +978,7 @@ public class AdPlanServiceImpl extends ServiceImpl<AdPlanMapper, AdPlan> impleme
adPlans.get(i).setCode(code);
tableGenService.deleteTable(Arrays.asList(code.toString()));
tableGenService.genAdNonHarmonicTable(code.toString());
tableGenService.genTable(code.toString(), PatternEnum.CONTRAST.getValue().equals(patternCode));
String source = planExcel.getSource();
String[] sourceNames = source.split(StrUtil.COMMA);

View File

@@ -68,7 +68,7 @@ public enum DetectionResponseEnum {
IMPORT_FLAG_NOT_UPDATE("A02091", "从谐波系统导入的设备不支持修改"),
CONNECTION_NOT_EXIST("A02092", "该连接不存在,请先在\"接线方式\"字典中添加"),
MONITOR_NUM_OUT_OF_RANGE("A02093", "检测点线路号超出范围,请检查线路号"),
MONITOR_NUM_REPEAT("A02094", "被检设备下存在相同线路号的监测点"),
MONITOR_NUM_REPEAT("A02094", "被检设备下存在相同线路号的监测点"),
PLAN_HAS_CHILDREN("A02095", "该计划下存在子计划,请先删除子计划"),
PLAN_REPEATED_IN_SAME_LEVEL("A02096", "该父计划下存在同名的子计划"),
PLEASE_UNASSIGN_STANDARD_DEV("A02097","存在已分配给子计划的标准设备,请先解除分配" ),

View File

@@ -12,6 +12,7 @@ import cn.hutool.extra.qrcode.QrCodeUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@@ -31,9 +32,11 @@ import com.njcn.gather.detection.util.socket.SocketManager;
import com.njcn.gather.detection.util.socket.cilent.NettyClient;
import com.njcn.gather.detection.util.socket.cilent.NettyDevClientHandler;
import com.njcn.gather.device.mapper.PqDevMapper;
import com.njcn.gather.device.mapper.PqDevSubMapper;
import com.njcn.gather.device.pojo.enums.CheckStateEnum;
import com.njcn.gather.device.pojo.enums.DevReportStateEnum;
import com.njcn.gather.device.pojo.param.PqDevParam;
import com.njcn.gather.device.pojo.po.PqDev;
import com.njcn.gather.device.pojo.po.PqDevSub;
import com.njcn.gather.device.pojo.vo.PqDevVO;
import com.njcn.gather.device.service.IPqDevService;
@@ -59,10 +62,10 @@ import com.njcn.gather.result.service.IResultService;
import com.njcn.gather.script.pojo.vo.PqScriptDtlDataVO;
import com.njcn.gather.script.service.IPqScriptDtlsService;
import com.njcn.gather.storage.pojo.param.SingleNonHarmParam;
import com.njcn.gather.storage.pojo.po.AdHarmonicResult;
import com.njcn.gather.storage.pojo.po.AdNonHarmonicResult;
import com.njcn.gather.storage.service.AdHarmonicService;
import com.njcn.gather.storage.service.AdNonHarmonicService;
import com.njcn.gather.storage.pojo.po.SimAndDigHarmonicResult;
import com.njcn.gather.storage.pojo.po.SimAndDigNonHarmonicResult;
import com.njcn.gather.storage.service.SimAndDigHarmonicService;
import com.njcn.gather.storage.service.SimAndDigNonHarmonicService;
import com.njcn.gather.system.cfg.pojo.enums.SceneEnum;
import com.njcn.gather.system.cfg.service.ISysTestConfigService;
import com.njcn.gather.system.dictionary.pojo.po.DictData;
@@ -158,6 +161,7 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
@Value("${qr.gcDev.path}")
private String gcDevPath;
private final IPqDevService iPqDevService;
private final PqDevMapper pqDevMapper;
private final IPqDevSubService iPqDevSubService;
@@ -168,9 +172,9 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
private final IPqScriptDtlsService pqScriptDtlsService;
private final AdNonHarmonicService adNonHarmonicService;
private final SimAndDigNonHarmonicService adNonHarmonicService;
private final AdHarmonicService adHarmonicService;
private final SimAndDigHarmonicService adHarmonicService;
private final IDevTypeService devTypeService;
@@ -1500,8 +1504,8 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
return obj.substring(index1, obj.indexOf("#", index1));
}, Collectors.toSet()))); //key为indexvalue为该index下所有测试项对应的code
List<AdNonHarmonicResult> adNonHarmonicResultList = adNonHarmonicService.listAllResultData(devReportParam.getScriptId(), devReportParam.getPlanCode(), devReportParam.getDevId() + "_" + i);
List<AdHarmonicResult> adHarmonicResultList = adHarmonicService.listAllResultData(devReportParam.getScriptId(), devReportParam.getPlanCode(), devReportParam.getDevId() + "_" + i);
List<SimAndDigNonHarmonicResult> simAndDigNonHarmonicResultList = adNonHarmonicService.listSimAndDigBaseResult(devReportParam.getScriptId(), devReportParam.getPlanCode(), devReportParam.getDevId() + "_" + i);
List<SimAndDigHarmonicResult> adHarmonicResultList = adHarmonicService.listAllResultData(devReportParam.getScriptId(), devReportParam.getPlanCode(), devReportParam.getDevId() + "_" + i);
// 填充数据
indexKeysMap.forEach((index, keys) -> {
@@ -1512,9 +1516,9 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
} else {
// 非谐波类
if (DetectionCodeEnum.V_UNBAN.getCode().equals(s1) || DetectionCodeEnum.FREQ.getCode().equals(s1)) {
fillMapValueT(adNonHarmonicResultList, dataModelMap, keys, index);
fillMapValueT(simAndDigNonHarmonicResultList, dataModelMap, keys, index);
} else {
fillMapValueABC(adNonHarmonicResultList, dataModelMap, keys, index);
fillMapValueABC(simAndDigNonHarmonicResultList, dataModelMap, keys, index);
}
}
});
@@ -1534,11 +1538,11 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
* @param keys
* @param index
*/
private void fillMapValueABC(List<AdNonHarmonicResult> allNonHarmonicResultList, Map<String, String> dataModelMap, Set<String> keys, String index) {
private void fillMapValueABC(List<SimAndDigNonHarmonicResult> allNonHarmonicResultList, Map<String, String> dataModelMap, Set<String> keys, String index) {
keys.forEach(key -> {
List<AdNonHarmonicResult> resultList = allNonHarmonicResultList.stream().filter(obj -> obj.getAdType().equals(key) && obj.getSort().toString().equals(index)).collect(Collectors.toList());
List<SimAndDigNonHarmonicResult> resultList = allNonHarmonicResultList.stream().filter(obj -> obj.getAdType().equals(key) && obj.getSort().toString().equals(index)).collect(Collectors.toList());
if (CollectionUtil.isNotEmpty(resultList)) {
AdNonHarmonicResult adNonHarmonicResult = resultList.get(0);
SimAndDigNonHarmonicResult adNonHarmonicResult = resultList.get(0);
if (ObjectUtil.isNotNull(adNonHarmonicResult)) {
dataModelMap.put("${" + index + "#" + key + "#A}", devValue(adNonHarmonicResult.getAValue(), 1, 1));
dataModelMap.put("${" + index + "#" + key + "#B}", devValue(adNonHarmonicResult.getBValue(), 1, 1));
@@ -1556,11 +1560,11 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
* @param keys
* @param index
*/
private void fillMapValueT(List<AdNonHarmonicResult> allNonHarmonicResultList, Map<String, String> dataModelMap, Set<String> keys, String index) {
private void fillMapValueT(List<SimAndDigNonHarmonicResult> allNonHarmonicResultList, Map<String, String> dataModelMap, Set<String> keys, String index) {
keys.forEach(key -> {
List<AdNonHarmonicResult> resultList = allNonHarmonicResultList.stream().filter(obj -> obj.getAdType().equals(key) && obj.getSort().toString().equals(index)).collect(Collectors.toList());
List<SimAndDigNonHarmonicResult> resultList = allNonHarmonicResultList.stream().filter(obj -> obj.getAdType().equals(key) && obj.getSort().toString().equals(index)).collect(Collectors.toList());
if (CollectionUtil.isNotEmpty(resultList)) {
AdNonHarmonicResult adNonHarmonicResult = resultList.get(0);
SimAndDigNonHarmonicResult adNonHarmonicResult = resultList.get(0);
if (ObjectUtil.isNotNull(adNonHarmonicResult)) {
dataModelMap.put("${" + index + "#" + key + "#T}", devValue(adNonHarmonicResult.getTValue(), 1, 1));
}
@@ -1576,11 +1580,11 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
* @param keys
* @param index
*/
private void fillMapValueHarm(List<AdHarmonicResult> allHarmonicResultList, Map<String, String> dataModelMap, Set<String> keys, String index) {
private void fillMapValueHarm(List<SimAndDigHarmonicResult> allHarmonicResultList, Map<String, String> dataModelMap, Set<String> keys, String index) {
keys.forEach(key -> {
List<AdHarmonicResult> resultList = allHarmonicResultList.stream().filter(obj -> obj.getAdType().equals(key) && obj.getSort().toString().equals(index)).collect(Collectors.toList());
List<SimAndDigHarmonicResult> resultList = allHarmonicResultList.stream().filter(obj -> obj.getAdType().equals(key) && obj.getSort().toString().equals(index)).collect(Collectors.toList());
if (CollectionUtil.isNotEmpty(resultList)) {
AdHarmonicResult adHarmonicResult = resultList.get(0);
SimAndDigHarmonicResult adHarmonicResult = resultList.get(0);
if (Objects.nonNull(adHarmonicResult)) {
if (DetectionCodeEnum.V2_50.getCode().equals(key) || DetectionCodeEnum.SV_1_49.getCode().equals(key)) {
fillHarm(dataModelMap, adHarmonicResult, index, key, 57.74, 100);
@@ -1603,7 +1607,7 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
* @param baseValue
* @param percent
*/
private void fillHarm(Map<String, String> dataModelMap, AdHarmonicResult adHarmonicResult, String index, String key, double baseValue, int percent) {
private void fillHarm(Map<String, String> dataModelMap, SimAndDigHarmonicResult adHarmonicResult, String index, String key, double baseValue, int percent) {
// 要处理 2 5 7 11 23 35 43 50
String aBase = devValue(adHarmonicResult.getAValue1(), 1, 1);
@@ -1753,16 +1757,14 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
public void uploadReportToCloud(List<String> deviceIds) {
log.info("开始批量上传检测报告到云端设备ID列表{}", deviceIds);
// 查询条件:报告状态为已生成(1)的设备
LambdaQueryWrapper<PqDev> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(PqDev::getReportState, DevReportStateEnum.GENERATED.getValue());
// 如果指定了设备ID列表则只查询这些设备
if (CollUtil.isNotEmpty(deviceIds)) {
wrapper.in(PqDev::getId, deviceIds);
}
List<PqDevSub> deviceSubs = iPqDevSubService.lambdaQuery()
.eq(PqDevSub::getReportState, DevReportStateEnum.GENERATED.getValue())
.in(CollUtil.isNotEmpty(deviceIds),PqDevSub::getDevId, deviceIds).list();
List<String> devIds = deviceSubs.stream().map(PqDevSub::getDevId).collect(Collectors.toList());
List<PqDev> devices = iPqDevService.list(wrapper);
List<PqDev> devices = iPqDevService.lambdaQuery()
.in(CollUtil.isNotEmpty(devIds), PqDev::getId, devIds).list();
if (CollUtil.isEmpty(devices)) {
log.warn("未找到符合条件的设备,无需上传");

View File

@@ -48,12 +48,12 @@ import com.njcn.gather.script.util.ScriptDtlsDesc;
import com.njcn.gather.storage.mapper.TableGenMapper;
import com.njcn.gather.storage.pojo.param.SingleNonHarmParam;
import com.njcn.gather.storage.pojo.param.StorageParam;
import com.njcn.gather.storage.pojo.po.AdBaseResult;
import com.njcn.gather.storage.pojo.po.AdHarmonicResult;
import com.njcn.gather.storage.pojo.po.AdNonHarmonicResult;
import com.njcn.gather.storage.pojo.po.SimAndDigBaseResult;
import com.njcn.gather.storage.pojo.po.SimAndDigHarmonicResult;
import com.njcn.gather.storage.pojo.po.SimAndDigNonHarmonicResult;
import com.njcn.gather.storage.pojo.vo.RawDataVO;
import com.njcn.gather.storage.service.AdHarmonicService;
import com.njcn.gather.storage.service.AdNonHarmonicService;
import com.njcn.gather.storage.service.SimAndDigHarmonicService;
import com.njcn.gather.storage.service.SimAndDigNonHarmonicService;
import com.njcn.gather.system.dictionary.pojo.enums.DictDataEnum;
import com.njcn.gather.system.dictionary.pojo.po.DictData;
import com.njcn.gather.system.dictionary.pojo.po.DictTree;
@@ -82,8 +82,8 @@ public class ResultServiceImpl implements IResultService {
private final IAdPlanService adPlanService;
private final IPqDevService pqDevService;
private final AdNonHarmonicService adNonHarmonicService;
private final AdHarmonicService adHarmonicService;
private final SimAndDigNonHarmonicService adNonHarmonicService;
private final SimAndDigHarmonicService adHarmonicService;
private final IPqScriptDtlsService pqScriptDtlsService;
private final PqScriptMapper scriptMapper;
private final IDictTreeService dictTreeService;
@@ -116,7 +116,7 @@ public class ResultServiceImpl implements IResultService {
List<Map<String, String>> chnList = new ArrayList<>();
List<AdBaseResult> allResultList = new ArrayList<>();
List<SimAndDigBaseResult> allResultList = new ArrayList<>();
//只查询指定的脚本类型
if (ObjectUtil.isNotNull(queryParam.getScriptType())) {
List<Integer> indexList = pqScriptDtlsService.getIndexList(queryParam.getScriptType(), scriptId);
@@ -125,22 +125,22 @@ public class ResultServiceImpl implements IResultService {
if (HARMONIC_TYPE_CODE.contains(dictTree.getCode())) {
allResultList.addAll(adHarmonicService.get(scriptId, indexList, queryParam.getDeviceId(), queryParam.getChnNum(), plan.getCode() + ""));
} else {
allResultList.addAll(adNonHarmonicService.get(scriptId, indexList, queryParam.getDeviceId(), queryParam.getChnNum(), plan.getCode() + ""));
allResultList.addAll(adNonHarmonicService.listSimAndDigBaseResult(scriptId, indexList, queryParam.getDeviceId(), queryParam.getChnNum(), plan.getCode() + ""));
}
} else { //查询所有的脚本类型
allResultList.addAll(adHarmonicService.get(scriptId, null, queryParam.getDeviceId(), queryParam.getChnNum(), plan.getCode() + ""));
allResultList.addAll(adNonHarmonicService.get(scriptId, null, queryParam.getDeviceId(), queryParam.getChnNum(), plan.getCode() + ""));
allResultList.addAll(adNonHarmonicService.listSimAndDigBaseResult(scriptId, null, queryParam.getDeviceId(), queryParam.getChnNum(), plan.getCode() + ""));
}
if (ObjectUtil.isNotEmpty(allResultList)) {
Map<String, List<AdBaseResult>> chnMap = allResultList.stream().collect(
Map<String, List<SimAndDigBaseResult>> chnMap = allResultList.stream().collect(
Collectors.groupingBy(obj -> obj.getMonitorId().substring(obj.getMonitorId().lastIndexOf("_") + 1))
);
chnMap.forEach((chn, list) -> {
Map<String, String> map = new HashMap<>();
map.put("value", chn);
Set<Integer> collect = list.stream().filter(obj -> obj.getResultFlag() != 4).map(AdBaseResult::getResultFlag).collect(Collectors.toSet());
Set<Integer> collect = list.stream().filter(obj -> obj.getResultFlag() != 4).map(SimAndDigBaseResult::getResultFlag).collect(Collectors.toSet());
map.put("label", conform(collect) + "");
chnList.add(map);
@@ -164,15 +164,15 @@ public class ResultServiceImpl implements IResultService {
);
Map<Integer, Set<Integer>> resultMap = new HashMap<>(5);
if (StrUtil.isNotBlank(param.getDevId())) {
List<AdBaseResult> allResultList = new ArrayList<>();
List<SimAndDigBaseResult> allResultList = new ArrayList<>();
List<Integer> indexList = new ArrayList<>();
if (StrUtil.isNotBlank(param.getScriptType())) {
indexList = pqScriptDtlsService.getIndexList(param.getScriptType(), param.getScriptId());
}
allResultList.addAll(adNonHarmonicService.get(param.getScriptId(), indexList, param.getDevId(), param.getDevNum(), param.getCode()));
allResultList.addAll(adNonHarmonicService.listSimAndDigBaseResult(param.getScriptId(), indexList, param.getDevId(), param.getDevNum(), param.getCode()));
allResultList.addAll(adHarmonicService.get(param.getScriptId(), indexList, param.getDevId(), param.getDevNum(), param.getCode()));
if (CollUtil.isNotEmpty(allResultList)) {
resultMap = allResultList.stream().collect(Collectors.groupingBy(AdBaseResult::getSort, Collectors.mapping(AdBaseResult::getResultFlag, Collectors.toSet())));
resultMap = allResultList.stream().collect(Collectors.groupingBy(SimAndDigBaseResult::getSort, Collectors.mapping(SimAndDigBaseResult::getResultFlag, Collectors.toSet())));
}
}
@@ -971,7 +971,7 @@ public class ResultServiceImpl implements IResultService {
List<Map<String, String>> keyFillMapList = new ArrayList<>();
for (Integer sort : indexList) {
SingleNonHarmParam param = new SingleNonHarmParam(planCode, devId, lineNo, valueTypeList, Collections.singletonList(sort));
List<AdNonHarmonicResult> nonHarmList = adNonHarmonicService.queryByCondition(param);
List<SimAndDigNonHarmonicResult> nonHarmList = adNonHarmonicService.queryByCondition(param);
if (CollUtil.isNotEmpty(nonHarmList)) {
Map<String, String> keyFillMap = new HashMap<>(16);
fillVoltagePhaseData(nonHarmList, keyFillMap, tableKeys);
@@ -996,7 +996,7 @@ public class ResultServiceImpl implements IResultService {
if (indexList.size() == 1) {
// 获取谐波数据
SingleNonHarmParam param = new SingleNonHarmParam(planCode, devId, lineNo, valueType, indexList.get(0));
AdHarmonicResult singleResult = adHarmonicService.getSingleResult(param);
SimAndDigHarmonicResult singleResult = adHarmonicService.getSingleResult(param);
// 注如果ABC的标准值一致则同步到standard中
Map<Double, List<PqScriptCheckData>> checkDataHarmNumMap = scriptCheckDataList.stream().collect(Collectors.groupingBy(PqScriptCheckData::getHarmNum));
List<Map<String, String>> keyFillMapList = new ArrayList<>();
@@ -1039,12 +1039,12 @@ public class ResultServiceImpl implements IResultService {
if (PowerConstant.THREE_PHASE.contains(scriptCode)) {
// 获取该三相的数据
SingleNonHarmParam param = new SingleNonHarmParam(planCode, devId, lineNo, Collections.singletonList(valueType), indexList);
List<AdNonHarmonicResult> nonHarmList = adNonHarmonicService.queryByCondition(param);
List<SimAndDigNonHarmonicResult> nonHarmList = adNonHarmonicService.queryByCondition(param);
if (CollUtil.isNotEmpty(nonHarmList)) {
List<Map<String, String>> keyFillMapList = new ArrayList<>();
for (AdNonHarmonicResult adNonHarmonicResult : nonHarmList) {
for (SimAndDigNonHarmonicResult SimAndDigNonHarmonicResult : nonHarmList) {
Map<String, String> keyFillMap = new HashMap<>(16);
fillThreePhaseData(adNonHarmonicResult, null, keyFillMap, scriptCode);
fillThreePhaseData(SimAndDigNonHarmonicResult, null, keyFillMap, scriptCode);
keyFillMapList.add(keyFillMap);
}
if (CollUtil.isNotEmpty(keyFillMapList)) {
@@ -1067,11 +1067,11 @@ public class ResultServiceImpl implements IResultService {
// 非三相且非暂态,通常只有一个数据,所以直接赋值即可
List<Map<String, String>> keyFillMapList = new ArrayList<>();
SingleNonHarmParam param = new SingleNonHarmParam(planCode, devId, lineNo, Collections.singletonList(valueType), indexList);
List<AdNonHarmonicResult> nonHarmList = adNonHarmonicService.queryByCondition(param);
List<SimAndDigNonHarmonicResult> nonHarmList = adNonHarmonicService.queryByCondition(param);
if (CollUtil.isNotEmpty(nonHarmList)) {
for (AdNonHarmonicResult adNonHarmonicResult : nonHarmList) {
for (SimAndDigNonHarmonicResult simAndDigNonHarmonicResult : nonHarmList) {
Map<String, String> keyFillMap = new HashMap<>(8);
fillTPhaseData(adNonHarmonicResult, null, keyFillMap);
fillTPhaseData(simAndDigNonHarmonicResult, null, keyFillMap);
keyFillMapList.add(keyFillMap);
}
}
@@ -1286,14 +1286,14 @@ public class ResultServiceImpl implements IResultService {
* @param keyFillMap 待填充的集合Map
* @param tableKeys 模板表格中的key
*/
private void fillVoltagePhaseData(List<AdNonHarmonicResult> nonHarmList, Map<String, String> keyFillMap, List<String> tableKeys) {
private void fillVoltagePhaseData(List<SimAndDigNonHarmonicResult> nonHarmList, Map<String, String> keyFillMap, List<String> tableKeys) {
String standardMag = "/", standardDur = "/",
testMag = "/", testDur = "/",
errorMag = "/", errorDur = "/",
resultMag = "/", resultDur = "/", result,
errorScope, errorScopeMag = "/", errorScopeDur = "/",
unitMag = "", unitDur = "";
for (AdNonHarmonicResult adNonHarmonicResult : nonHarmList) {
for (SimAndDigNonHarmonicResult adNonHarmonicResult : nonHarmList) {
DetectionData tempT = getResultData(adNonHarmonicResult, null, PowerConstant.PHASE_T);
// 需要判断adNonHarmonicResult是特征幅值还是持续时间
String adType = adNonHarmonicResult.getAdType();
@@ -1520,7 +1520,7 @@ public class ResultServiceImpl implements IResultService {
private void createTempResultTable(String code) {
this.dropTempResultTable(code);
String oldCode = code.replace("_temp", "");
tableGenMapper.genAdNonHarmonicResultTable(code);
tableGenMapper.genNonHarmonicResultTable(code, false);
StringBuilder A = new StringBuilder();
StringBuilder B = new StringBuilder();
StringBuilder C = new StringBuilder();
@@ -1596,12 +1596,12 @@ public class ResultServiceImpl implements IResultService {
dataRule = DictDataEnum.SECTION_VALUE;
}
List<AdNonHarmonicResult> allNonHarmonicRawData = adNonHarmonicService.listAllRawData(scriptId, oldCode, devId);
LinkedHashMap<Integer, List<AdNonHarmonicResult>> nonHarmonicMap = allNonHarmonicRawData.stream().sorted(Comparator.comparing(AdNonHarmonicResult::getSort))
.collect(Collectors.groupingBy(AdNonHarmonicResult::getSort, LinkedHashMap::new, Collectors.toList()));
List<AdHarmonicResult> allHarmonicRawData = adHarmonicService.listAllRawData(scriptId, oldCode, devId);
LinkedHashMap<Integer, List<AdHarmonicResult>> harmonicMap = allHarmonicRawData.stream().sorted(Comparator.comparing(AdHarmonicResult::getSort))
.collect(Collectors.groupingBy(AdHarmonicResult::getSort, LinkedHashMap::new, Collectors.toList()));
List<SimAndDigNonHarmonicResult> allNonHarmonicRawData = adNonHarmonicService.listAllSimAndDigRawData(scriptId, oldCode, devId);
LinkedHashMap<Integer, List<SimAndDigNonHarmonicResult>> nonHarmonicMap = allNonHarmonicRawData.stream().sorted(Comparator.comparing(SimAndDigNonHarmonicResult::getSort))
.collect(Collectors.groupingBy(SimAndDigNonHarmonicResult::getSort, LinkedHashMap::new, Collectors.toList()));
List<SimAndDigHarmonicResult> allHarmonicRawData = adHarmonicService.listAllRawData(scriptId, oldCode, devId);
LinkedHashMap<Integer, List<SimAndDigHarmonicResult>> harmonicMap = allHarmonicRawData.stream().sorted(Comparator.comparing(SimAndDigHarmonicResult::getSort))
.collect(Collectors.groupingBy(SimAndDigHarmonicResult::getSort, LinkedHashMap::new, Collectors.toList()));
PqScriptIssueParam issueParam = new PqScriptIssueParam();
issueParam.setPlanId(planId);
@@ -1615,8 +1615,8 @@ public class ResultServiceImpl implements IResultService {
List<SourceIssue> sourceIssues = pqScriptDtlsService.listSourceIssue(issueParam);
sourceIssues.forEach(sourceIssue -> {
List<AdNonHarmonicResult> nonHarmonicResults = nonHarmonicMap.get(sourceIssue.getIndex());
List<AdHarmonicResult> harmonicResults = harmonicMap.get(sourceIssue.getIndex());
List<SimAndDigNonHarmonicResult> nonHarmonicResults = nonHarmonicMap.get(sourceIssue.getIndex());
List<SimAndDigHarmonicResult> harmonicResults = harmonicMap.get(sourceIssue.getIndex());
List<DevData> realDataXiList = new ArrayList<>();
if (CollUtil.isNotEmpty(nonHarmonicResults)) {
realDataXiList.addAll(this.toList(nonHarmonicResults, null, true));
@@ -1640,11 +1640,11 @@ public class ResultServiceImpl implements IResultService {
iPqDevService.updateResult(param.getDevIds(), valueType, param.getCode(), null, param.getTemperature(), param.getHumidity());
}
private List<DevData> toList(List<AdNonHarmonicResult> nonHarm, List<AdHarmonicResult> harm, boolean containBaseHarm) {
private List<DevData> toList(List<SimAndDigNonHarmonicResult> nonHarm, List<SimAndDigHarmonicResult> harm, boolean containBaseHarm) {
List<DevData> info = new ArrayList<>();
// if (CollUtil.isNotEmpty(nonHarm)) {
if (CollUtil.isNotEmpty(nonHarm)) {
Map<String, List<AdNonHarmonicResult>> noHarmMap = nonHarm.stream()
Map<String, List<SimAndDigNonHarmonicResult>> noHarmMap = nonHarm.stream()
.collect(Collectors.groupingBy(x -> x.getMonitorId() + "_" + x.getTimeId().format(DateTimeFormatter.ofPattern(DatePattern.UTC_SIMPLE_MS_PATTERN)) + "_" + x.getSort()));
noHarmMap.forEach((key, value) -> {
String[] split = key.split("_");
@@ -1653,7 +1653,7 @@ public class ResultServiceImpl implements IResultService {
data.setId(split[0] + "_" + split[1]);
List<DevData.SqlDataDTO> sqlDataDTOS = new ArrayList<>();
DevData.SqlDataDTO sqlDataDTO;
for (AdNonHarmonicResult result : value) {
for (SimAndDigNonHarmonicResult result : value) {
sqlDataDTO = new DevData.SqlDataDTO();
sqlDataDTO.setType(result.getDataType());
sqlDataDTO.setDesc(result.getAdType());
@@ -1670,7 +1670,7 @@ public class ResultServiceImpl implements IResultService {
});
}
if (CollUtil.isNotEmpty(harm)) {
Map<String, List<AdHarmonicResult>> harmMap = harm.stream()
Map<String, List<SimAndDigHarmonicResult>> harmMap = harm.stream()
.collect(Collectors.groupingBy(x -> x.getMonitorId() + "_" + x.getTimeId().format(DateTimeFormatter.ofPattern(DatePattern.UTC_SIMPLE_MS_PATTERN))));
harmMap.forEach((key, value) -> {
List<DevData> collect = info.stream().filter(x -> key.equals(x.getId() + "_" + x.getTime())).collect(Collectors.toList());
@@ -1678,7 +1678,7 @@ public class ResultServiceImpl implements IResultService {
DevData.SqlDataDTO sqlDataDTO;
List<DevData.SqlDataHarmDTO> sqlDataHarmDTOS = new ArrayList<>();
DevData.SqlDataHarmDTO dataHarmDTO;
for (AdHarmonicResult harmonicResult : value) {
for (SimAndDigHarmonicResult harmonicResult : value) {
if (containBaseHarm) {
sqlDataDTO = new DevData.SqlDataDTO();
sqlDataDTO.setType(harmonicResult.getDataType());
@@ -1725,12 +1725,12 @@ public class ResultServiceImpl implements IResultService {
return info;
}
private List<String> reflectHarmonicValue(String phase, AdHarmonicResult adHarmonicResult, boolean notContainBaseHarm) {
private List<String> reflectHarmonicValue(String phase, SimAndDigHarmonicResult adHarmonicResult, boolean notContainBaseHarm) {
List<String> info = new ArrayList<>();
for (int i = notContainBaseHarm ? 2 : 1; i <= 50; i++) {
String fieldName = phase + "Value" + i;
try {
Field idField = AdHarmonicResult.class.getDeclaredField(fieldName);
Field idField = SimAndDigHarmonicResult.class.getDeclaredField(fieldName);
idField.setAccessible(true);
String value = idField.get(adHarmonicResult) + "";
info.add(value);