暂存功能

This commit is contained in:
caozehui
2026-07-15 11:01:49 +08:00
parent 16ace94f8d
commit 95005d2462
31 changed files with 1135 additions and 429 deletions

View File

@@ -12,9 +12,11 @@ import com.njcn.gather.detection.lock.DetectionLockManager;
import com.njcn.gather.detection.lock.DetectionLockManager.AcquireResult;
import com.njcn.gather.detection.pojo.enums.DetectionResponseEnum;
import com.njcn.gather.detection.pojo.param.ContrastDetectionParam;
import com.njcn.gather.detection.pojo.param.FormalProgressParam;
import com.njcn.gather.detection.pojo.param.PreDetectionParam;
import com.njcn.gather.detection.pojo.param.SimulateDetectionParam;
import com.njcn.gather.detection.pojo.vo.DetectionLockHolderVO;
import com.njcn.gather.detection.pojo.vo.FormalProgressVO;
import com.njcn.gather.detection.service.PreDetectionService;
import com.njcn.gather.detection.util.socket.FormalTestManager;
import com.njcn.gather.user.user.pojo.po.SysUser;
@@ -202,6 +204,36 @@ public class PreDetectionController extends BaseController {
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
}
@PostMapping("/saveFormalProgress")
@OperateInfo
@ApiOperation("保存正式检测暂存进度")
public HttpResult<?> saveFormalProgress(@RequestBody @Validated FormalProgressParam param) {
String methodDescribe = getMethodDescribe("saveFormalProgress");
HttpResult<DetectionLockHolderVO> busy = requireHolderSelf();
if (busy != null) {
return busy;
}
try {
preDetectionService.saveFormalProgress(param);
} finally {
releaseLockSelf("SAVE_FORMAL_PROGRESS");
}
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
}
@PostMapping("/formalProgress")
@OperateInfo
@ApiOperation("查询正式检测暂存进度并放行续检")
public HttpResult<?> formalProgress(@RequestBody @Validated FormalProgressParam param) {
String methodDescribe = getMethodDescribe("formalProgress");
HttpResult<DetectionLockHolderVO> busy = requireHolderSelf();
if (busy != null) {
return busy;
}
FormalProgressVO data = preDetectionService.formalProgress(param);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, data, methodDescribe);
}
/**
* 开始比对检测(包括预检测、正式检测)通用入口

View File

@@ -41,6 +41,7 @@ import com.njcn.gather.monitor.service.IPqMonitorService;
import com.njcn.gather.plan.pojo.enums.DataSourceEnum;
import com.njcn.gather.plan.service.IAdPlanService;
import com.njcn.gather.plan.service.IAdPlanTestConfigService;
import com.njcn.gather.report.pojo.enums.PowerIndexEnum;
import com.njcn.gather.storage.pojo.po.ContrastHarmonicResult;
import com.njcn.gather.storage.pojo.po.ContrastNonHarmonicResult;
import com.njcn.gather.storage.service.DetectionDataDealService;
@@ -132,17 +133,17 @@ public class SocketContrastResponseService {
private final PathConfig pathConfig;
public static final Map<String, List<String>> testItemCodeMap = new HashMap() {{
put("FREQ", Arrays.asList(DetectionCodeEnum.FREQ.getCode()));
put("V", Arrays.asList(DetectionCodeEnum.VRMS.getCode(), DetectionCodeEnum.PVRMS.getCode()));
put("HV", Arrays.asList(DetectionCodeEnum.V2_50.getCode(), DetectionCodeEnum.PV2_50.getCode()));
put("HI", Arrays.asList(DetectionCodeEnum.I2_50.getCode()));
put("HP", Arrays.asList(DetectionCodeEnum.P2_50.getCode()));
put("HSV", Arrays.asList(DetectionCodeEnum.SV_1_49.getCode(), DetectionCodeEnum.PSV_1_49.getCode()));
put("HSI", Arrays.asList(DetectionCodeEnum.SI_1_49.getCode()));
put("I", Arrays.asList(DetectionCodeEnum.IRMS.getCode()));
put("IMBV", Arrays.asList(DetectionCodeEnum.V_UNBAN.getCode()));
put("IMBA", Arrays.asList(DetectionCodeEnum.I_UNBAN.getCode()));
put("F", Arrays.asList(DetectionCodeEnum.PST.getCode()));
put(PowerIndexEnum.FREQ.getKey(), Arrays.asList(DetectionCodeEnum.FREQ.getCode()));
put(PowerIndexEnum.V.getKey(), Arrays.asList(DetectionCodeEnum.VRMS.getCode(), DetectionCodeEnum.PVRMS.getCode()));
put(PowerIndexEnum.HV.getKey(), Arrays.asList(DetectionCodeEnum.V2_50.getCode(), DetectionCodeEnum.PV2_50.getCode()));
put(PowerIndexEnum.HI.getKey(), Arrays.asList(DetectionCodeEnum.I2_50.getCode()));
put(PowerIndexEnum.HP.getKey(), Arrays.asList(DetectionCodeEnum.P2_50.getCode()));
put(PowerIndexEnum.HSV.getKey(), Arrays.asList(DetectionCodeEnum.SV_1_49.getCode(), DetectionCodeEnum.PSV_1_49.getCode()));
put(PowerIndexEnum.HSI.getKey(), Arrays.asList(DetectionCodeEnum.SI_1_49.getCode()));
put(PowerIndexEnum.I.getKey(), Arrays.asList(DetectionCodeEnum.IRMS.getCode()));
put(PowerIndexEnum.IMBV.getKey(), Arrays.asList(DetectionCodeEnum.V_UNBAN.getCode()));
put(PowerIndexEnum.IMBA.getKey(), Arrays.asList(DetectionCodeEnum.I_UNBAN.getCode()));
put(PowerIndexEnum.F.getKey(), Arrays.asList(DetectionCodeEnum.PST.getCode()));
}};
/**

View File

@@ -28,7 +28,7 @@ import com.njcn.gather.device.service.IPqDevService;
import com.njcn.gather.device.service.IPqDevSubService;
import com.njcn.gather.plan.pojo.po.AdPlan;
import com.njcn.gather.plan.service.IAdPlanService;
import com.njcn.gather.result.pojo.enums.ResultUnitEnum;
import com.njcn.gather.report.pojo.enums.PowerIndexEnum;
import com.njcn.gather.result.service.IResultService;
import com.njcn.gather.script.pojo.param.PqScriptCheckDataParam;
import com.njcn.gather.script.pojo.param.PqScriptIssueParam;
@@ -45,7 +45,6 @@ import com.njcn.gather.storage.service.SimAndDigHarmonicService;
import com.njcn.gather.system.dictionary.pojo.enums.DictDataEnum;
import com.njcn.gather.system.dictionary.pojo.po.DictData;
import com.njcn.gather.system.dictionary.service.IDictDataService;
import com.njcn.gather.system.pojo.enums.DicDataEnum;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
@@ -69,7 +68,7 @@ public class SocketDevResponseService {
private List<String> icdTypeList;
private final List<String> nonHarmonicList = Stream.of(DicDataEnum.FREQ.getCode(), DicDataEnum.V.getCode(), DicDataEnum.I.getCode(), DicDataEnum.IMBV.getCode(), DicDataEnum.IMBA.getCode(), DicDataEnum.VOLTAGE.getCode(), DicDataEnum.F.getCode()).collect(Collectors.toList());
private final List<String> nonHarmonicList = Stream.of(PowerIndexEnum.FREQ.getKey(), PowerIndexEnum.V.getKey(), PowerIndexEnum.I.getKey(), PowerIndexEnum.IMBV.getKey(), PowerIndexEnum.IMBA.getKey(), PowerIndexEnum.VOLTAGE.getKey(), PowerIndexEnum.F.getKey()).collect(Collectors.toList());
private final IPqDevService iPqDevService;
private final IPqDevSubService iPqDevSubService;
@@ -399,71 +398,7 @@ public class SocketDevResponseService {
System.out.println("-------------------------已经全部结束----------------------");
if (param.isFormalTestSelected()) {
//如果后续做正式检测
PqScriptIssueParam issueParam = new PqScriptIssueParam();
issueParam.setSourceId(param.getSourceName());
issueParam.setPlanId(param.getPlanId());
issueParam.setSourceId(param.getSourceId());
issueParam.setDevIds(param.getDevIds());
issueParam.setScriptId(param.getScriptId());
if (param.getReCheckType().equals(SourceOperateCodeEnum.RE_ERROR_TEST.getValue())) {
//不合格项复检
Set<Integer> indexes = new HashSet<>();
StorageParam storageParam = new StorageParam();
storageParam.setCode(param.getCode());
storageParam.setScriptId(param.getScriptId());
param.getDevIds().forEach(devId -> {
storageParam.setDevId(devId);
indexes.addAll(adHarmonicService.getIndex(storageParam));
});
issueParam.setIndexList(indexes.stream().collect(Collectors.toList()));
issueParam.setIsPhaseSequence(SourceOperateCodeEnum.RE_ERROR_TEST.getValue());
} else {
issueParam.setIsPhaseSequence(CommonEnum.FORMAL_TEST.getValue());
}
SocketMsg<String> socketMsg = new SocketMsg<>();
socketMsg.setOperateCode(SourceOperateCodeEnum.OPER_GATHER.getValue());
List<SourceIssue> sourceIssues;
//正式检测
sourceIssues = pqScriptDtlsService.listSourceIssue(issueParam);
sourceIssues = sourceIssues.stream().sorted(Comparator.comparing(SourceIssue::getIndex)).collect(Collectors.toList());
// 使用 LinkedHashMap 保持分组顺序
Map<String, List<SourceIssue>> groupedIssues = sourceIssues.stream()
.collect(Collectors.groupingBy(
SourceIssue::getType,
LinkedHashMap::new,
Collectors.toList()
));
// 将分组后的元素合并成一个新的集合,保持原有顺序
sourceIssues = groupedIssues.values().stream()
.flatMap(List::stream)
.collect(Collectors.toList());
// 存放所有检测小项
SocketManager.addSourceList(sourceIssues);
// 按照大项分组。key为大项codevalue为小项个数
Map<String, Long> sourceIssueMap = sourceIssues.stream().collect(Collectors.groupingBy(SourceIssue::getType, Collectors.counting()));
SocketManager.initMap(sourceIssueMap);
//告诉前端当前项开始了
WebSocketVO<Object> webSocketVO = new WebSocketVO<>();
FormalTestManager.currentIssue = sourceIssues.get(0);
String type = sourceIssues.get(0).getType();
if (ResultUnitEnum.P.getCode().equals(type)) {
sourceIssues.get(0).setType(ResultUnitEnum.V_ABSOLUTELY.getCode());
webSocketVO.setRequestId(ResultUnitEnum.P.getCode() + CnSocketUtil.START_TAG);
} else {
webSocketVO.setRequestId(sourceIssues.get(0).getType() + CnSocketUtil.START_TAG);
}
socketMsg.setData(JSON.toJSONString(sourceIssues.get(0)));
socketMsg.setRequestId(SourceOperateCodeEnum.FORMAL_REAL.getValue() + CnSocketUtil.STEP_TAG + type);
SocketManager.sendMsg(param.getUserPageId() + CnSocketUtil.SOURCE_TAG, JSON.toJSONString(socketMsg));
webSocketVO.setDesc(null);
WebServiceManager.sendMsg(param.getUserPageId(), JSON.toJSONString(webSocketVO));
startFormalScripts(param, null, param.isResumeFormal());
} else {
//后续什么都不做
CnSocketUtil.quitSend(param);
@@ -615,7 +550,7 @@ public class SocketDevResponseService {
private BigDecimal rangeNum(double num1, double num2, String type) {
double diff = Math.abs(num1 - num2);
double larger = Math.max(num1, num2);
if (DicDataEnum.V.getCode().equals(type)) {
if (PowerIndexEnum.V.getKey().equals(type)) {
return BigDecimal.valueOf(num1 - num2).setScale(4, RoundingMode.HALF_UP);
} else {
return BigDecimal.valueOf(diff / larger).multiply(BigDecimal.valueOf(100)).setScale(4, RoundingMode.HALF_UP);
@@ -678,12 +613,12 @@ public class SocketDevResponseService {
coefficientVO.setBIeXi(isWithinTenPercent(optionalIB, devParameter.getDevCurr(), iLimit) ? "合格" : "不合格");
coefficientVO.setCIeXi(isWithinTenPercent(optionalIC, devParameter.getDevCurr(), iLimit) ? "合格" : "不合格");
coefficientVO.setAV(rangeNum(optionalA, devParameter.getDevVolt(), DicDataEnum.V.getCode()).toString());
coefficientVO.setBV(rangeNum(optionalB, devParameter.getDevVolt(), DicDataEnum.V.getCode()).toString());
coefficientVO.setCV(rangeNum(optionalC, devParameter.getDevVolt(), DicDataEnum.V.getCode()).toString());
coefficientVO.setAI(rangeNum(optionalIA, devParameter.getDevCurr(), DicDataEnum.I.getCode()).toString());
coefficientVO.setBI(rangeNum(optionalIB, devParameter.getDevCurr(), DicDataEnum.I.getCode()).toString());
coefficientVO.setCI(rangeNum(optionalIC, devParameter.getDevCurr(), DicDataEnum.I.getCode()).toString());
coefficientVO.setAV(rangeNum(optionalA, devParameter.getDevVolt(), PowerIndexEnum.V.getKey()).toString());
coefficientVO.setBV(rangeNum(optionalB, devParameter.getDevVolt(), PowerIndexEnum.V.getKey()).toString());
coefficientVO.setCV(rangeNum(optionalC, devParameter.getDevVolt(), PowerIndexEnum.V.getKey()).toString());
coefficientVO.setAI(rangeNum(optionalIA, devParameter.getDevCurr(), PowerIndexEnum.I.getKey()).toString());
coefficientVO.setBI(rangeNum(optionalIB, devParameter.getDevCurr(), PowerIndexEnum.I.getKey()).toString());
coefficientVO.setCI(rangeNum(optionalIC, devParameter.getDevCurr(), PowerIndexEnum.I.getKey()).toString());
if ("不合格".equals(coefficientVO.getAVuXi()) || "不合格".equals(coefficientVO.getBVuXi()) || "不合格".equals(coefficientVO.getCVuXi()) || "不合格".equals(coefficientVO.getAIeXi()) || "不合格".equals(coefficientVO.getBIeXi()) || "不合格".equals(coefficientVO.getCIeXi())) {
coefficientVO.setResultFlag(0);
@@ -912,69 +847,70 @@ public class SocketDevResponseService {
socketMsg.setOperateCode(SourceOperateCodeEnum.OPER_GATHER.getValue());
List<SourceIssue> sourceIssues;
// 做预检测、后续做系数校准
if (param.isPreTestSelected() || param.isCoefficientSelected()) {
issueParam.setIsPhaseSequence(CommonEnum.PHASE_TEST.getValue());
sourceIssues = pqScriptDtlsService.listSourceIssue(issueParam);
socketMsg.setRequestId(SourceOperateCodeEnum.YJC_XUJY.getValue());
socketMsg.setData(JSON.toJSONString(sourceIssues.get(0)));
SocketManager.sendMsg(param.getUserPageId() + CnSocketUtil.SOURCE_TAG, JSON.toJSONString(socketMsg));
} else if (param.isFormalTestSelected()) {
// 后续做正式检测
if (param.getReCheckType().equals(SourceOperateCodeEnum.RE_ERROR_TEST.getValue())) {
//不合格项复检
Set<Integer> indexes = new HashSet<>();
StorageParam storageParam = new StorageParam();
storageParam.setCode(param.getCode());
storageParam.setScriptId(param.getScriptId());
param.getDevIds().forEach(devId -> {
storageParam.setDevId(devId);
indexes.addAll(adHarmonicService.getIndex(storageParam));
});
issueParam.setIndexList(indexes.stream().collect(Collectors.toList()));
issueParam.setIsPhaseSequence(SourceOperateCodeEnum.RE_ERROR_TEST.getValue());
} else {
issueParam.setIsPhaseSequence(CommonEnum.FORMAL_TEST.getValue());
}
//正式检测
sourceIssues = pqScriptDtlsService.listSourceIssue(issueParam);
sourceIssues = sourceIssues.stream().sorted(Comparator.comparing(SourceIssue::getIndex)).collect(Collectors.toList());
// 使用 LinkedHashMap 保持分组顺序
Map<String, List<SourceIssue>> groupedIssues = sourceIssues.stream()
.collect(Collectors.groupingBy(
SourceIssue::getType,
LinkedHashMap::new,
Collectors.toList()
));
// 将分组后的元素合并成一个新的集合,保持原有顺序
sourceIssues = groupedIssues.values().stream()
.flatMap(List::stream)
.collect(Collectors.toList());
// 存放所有检测小项
SocketManager.addSourceList(sourceIssues);
// 按照大项分组。key为大项codevalue为小项个数
Map<String, Long> sourceIssueMap = sourceIssues.stream().collect(Collectors.groupingBy(SourceIssue::getType, Collectors.counting()));
SocketManager.initMap(sourceIssueMap);
//告诉前端当前项开始了
WebSocketVO<Object> webSocketVO = new WebSocketVO<>();
String type = sourceIssues.get(0).getType();
if (StrUtil.isNotBlank(sourceIssues.get(0).getOtherType())) {
sourceIssues.get(0).setType(ResultUnitEnum.V_ABSOLUTELY.getCode());
webSocketVO.setRequestId(sourceIssues.get(0).getOtherType() + CnSocketUtil.START_TAG);
type = sourceIssues.get(0).getOtherType();
} else {
webSocketVO.setRequestId(sourceIssues.get(0).getType() + CnSocketUtil.START_TAG);
}
FormalTestManager.currentIssue = sourceIssues.get(0);
socketMsg.setData(JSON.toJSONString(sourceIssues.get(0)));
socketMsg.setRequestId(SourceOperateCodeEnum.FORMAL_REAL.getValue() + CnSocketUtil.STEP_TAG + type);
socketMsg.setOperateCode(SourceOperateCodeEnum.OPER_GATHER.getValue());
SocketManager.sendMsg(param.getUserPageId() + CnSocketUtil.SOURCE_TAG, JSON.toJSONString(socketMsg));
webSocketVO.setDesc(null);
WebServiceManager.sendMsg(param.getUserPageId(), JSON.toJSONString(webSocketVO));
}
// if (param.isPreTestSelected() || param.isCoefficientSelected() || param.isFormalTestSelected()) {
issueParam.setIsPhaseSequence(CommonEnum.PHASE_TEST.getValue());
sourceIssues = pqScriptDtlsService.listSourceIssue(issueParam);
socketMsg.setRequestId(SourceOperateCodeEnum.YJC_XUJY.getValue());
socketMsg.setData(JSON.toJSONString(sourceIssues.get(0)));
SocketManager.sendMsg(param.getUserPageId() + CnSocketUtil.SOURCE_TAG, JSON.toJSONString(socketMsg));
// }
// else if (param.isFormalTestSelected()) {
// // 后续做正式检测
// if (param.getReCheckType().equals(SourceOperateCodeEnum.RE_ERROR_TEST.getValue())) {
// //不合格项复检
// Set<Integer> indexes = new HashSet<>();
// StorageParam storageParam = new StorageParam();
// storageParam.setCode(param.getCode());
// storageParam.setScriptId(param.getScriptId());
// param.getDevIds().forEach(devId -> {
// storageParam.setDevId(devId);
// indexes.addAll(adHarmonicService.getIndex(storageParam));
// });
// issueParam.setIndexList(indexes.stream().collect(Collectors.toList()));
// issueParam.setIsPhaseSequence(SourceOperateCodeEnum.RE_ERROR_TEST.getValue());
// } else {
// issueParam.setIsPhaseSequence(CommonEnum.FORMAL_TEST.getValue());
// }
// //正式检测
// sourceIssues = pqScriptDtlsService.listSourceIssue(issueParam);
// sourceIssues = sourceIssues.stream().sorted(Comparator.comparing(SourceIssue::getIndex)).collect(Collectors.toList());
// // 使用 LinkedHashMap 保持分组顺序
// Map<String, List<SourceIssue>> groupedIssues = sourceIssues.stream()
// .collect(Collectors.groupingBy(
// SourceIssue::getType,
// LinkedHashMap::new,
// Collectors.toList()
// ));
//
// // 将分组后的元素合并成一个新的集合,保持原有顺序
// sourceIssues = groupedIssues.values().stream()
// .flatMap(List::stream)
// .collect(Collectors.toList());
// // 存放所有检测小项
// SocketManager.addSourceList(sourceIssues);
// // 按照大项分组。key为大项codevalue为小项个数
// Map<String, Long> sourceIssueMap = sourceIssues.stream().collect(Collectors.groupingBy(SourceIssue::getType, Collectors.counting()));
// SocketManager.initMap(sourceIssueMap);
//
// //告诉前端当前项开始了
// WebSocketVO<Object> webSocketVO = new WebSocketVO<>();
// String type = sourceIssues.get(0).getType();
// if (StrUtil.isNotBlank(sourceIssues.get(0).getOtherType())) {
// sourceIssues.get(0).setType(PowerIndexEnum.V.getKey());
// webSocketVO.setRequestId(sourceIssues.get(0).getOtherType() + CnSocketUtil.START_TAG);
// type = sourceIssues.get(0).getOtherType();
// } else {
// webSocketVO.setRequestId(sourceIssues.get(0).getType() + CnSocketUtil.START_TAG);
// }
// FormalTestManager.currentIssue = sourceIssues.get(0);
// socketMsg.setData(JSON.toJSONString(sourceIssues.get(0)));
// socketMsg.setRequestId(SourceOperateCodeEnum.FORMAL_REAL.getValue() + CnSocketUtil.STEP_TAG + type);
// socketMsg.setOperateCode(SourceOperateCodeEnum.OPER_GATHER.getValue());
// SocketManager.sendMsg(param.getUserPageId() + CnSocketUtil.SOURCE_TAG, JSON.toJSONString(socketMsg));
//
// webSocketVO.setDesc(null);
// WebServiceManager.sendMsg(param.getUserPageId(), JSON.toJSONString(webSocketVO));
// }
} else {
// 发送下一个脚本与icd校验
String icdType = icdTypeList.stream().filter(it -> !icdCheckDataMap.containsKey(it)).findFirst().orElse(null);
@@ -1172,69 +1108,7 @@ public class SocketDevResponseService {
System.out.println("开始系数校准》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》");
} else if (param.isFormalTestSelected()) {
// 后续做正式检测
PqScriptIssueParam issueParam = new PqScriptIssueParam();
issueParam.setSourceId(param.getSourceName());
issueParam.setPlanId(param.getPlanId());
issueParam.setDevIds(param.getDevIds());
issueParam.setScriptId(param.getScriptId());
if (param.getReCheckType().equals(SourceOperateCodeEnum.RE_ERROR_TEST.getValue())) {
//不合格项复检
Set<Integer> indexes = new HashSet<>();
StorageParam storageParam = new StorageParam();
storageParam.setCode(param.getCode());
storageParam.setScriptId(param.getScriptId());
param.getDevIds().forEach(devId -> {
storageParam.setDevId(devId);
indexes.addAll(adHarmonicService.getIndex(storageParam));
});
issueParam.setIndexList(indexes.stream().collect(Collectors.toList()));
issueParam.setIsPhaseSequence(SourceOperateCodeEnum.RE_ERROR_TEST.getValue());
} else {
issueParam.setIsPhaseSequence(CommonEnum.FORMAL_TEST.getValue());
}
//正式检测
sourceIssues = pqScriptDtlsService.listSourceIssue(issueParam);
sourceIssues = sourceIssues.stream().sorted(Comparator.comparing(SourceIssue::getIndex)).collect(Collectors.toList());
// 使用 LinkedHashMap 保持分组顺序
Map<String, List<SourceIssue>> groupedIssues = sourceIssues.stream()
.collect(Collectors.groupingBy(
SourceIssue::getType,
LinkedHashMap::new,
Collectors.toList()
));
// 将分组后的元素合并成一个新的集合,保持原有顺序
sourceIssues = groupedIssues.values().stream()
.flatMap(List::stream)
.collect(Collectors.toList());
// 存放所有检测小项
SocketManager.addSourceList(sourceIssues);
// 按照大项分组。key为大项codevalue为小项个数
Map<String, Long> sourceIssueMap = sourceIssues.stream().collect(Collectors.groupingBy(SourceIssue::getType, Collectors.counting()));
SocketManager.initMap(sourceIssueMap);
//告诉前端当前项开始了
WebSocketVO<Object> webSocketVO = new WebSocketVO<>();
String type = sourceIssues.get(0).getType();
if (StrUtil.isNotBlank(sourceIssues.get(0).getOtherType())) {
sourceIssues.get(0).setType(ResultUnitEnum.V_ABSOLUTELY.getCode());
webSocketVO.setRequestId(sourceIssues.get(0).getOtherType() + CnSocketUtil.START_TAG);
type = sourceIssues.get(0).getOtherType();
} else {
webSocketVO.setRequestId(sourceIssues.get(0).getType() + CnSocketUtil.START_TAG);
}
FormalTestManager.currentIssue = sourceIssues.get(0);
socketMsg.setData(JSON.toJSONString(sourceIssues.get(0)));
socketMsg.setRequestId(SourceOperateCodeEnum.FORMAL_REAL.getValue() + CnSocketUtil.STEP_TAG + type);
socketMsg.setOperateCode(SourceOperateCodeEnum.OPER_GATHER.getValue());
SocketManager.sendMsg(param.getUserPageId() + CnSocketUtil.SOURCE_TAG, JSON.toJSONString(socketMsg));
webSocketVO.setDesc(null);
WebServiceManager.sendMsg(param.getUserPageId(), JSON.toJSONString(webSocketVO));
startFormalScripts(param, null, param.isResumeFormal());
} else {
//后续什么都不做
System.out.println("预检测流程结束-----------------关闭源");
@@ -1279,6 +1153,97 @@ public class SocketDevResponseService {
// key为 检测大项对应的codevalue为当前大项的检测结果
Map<String, List<DevLineTestResult>> targetTestMap = new HashMap<>();
public void startFormalAfterProgressRestore(PreDetectionParam param, Integer nextSort) {
FormalTestManager.resumeFormalPending = false;
FormalTestManager.resumeNextSort = nextSort;
if (nextSort == null) {
WebServiceManager.sendDetectionMessage(param.getUserPageId(), "formal_progress_no_next", null, null, null);
return;
}
startFormalScripts(param, nextSort, false);
}
private void startFormalScripts(PreDetectionParam param, Integer startSort, boolean waitForProgressRestore) {
List<SourceIssue> sourceIssues = buildFormalIssues(param);
if (ObjectUtil.isNotNull(startSort)) {
sourceIssues = sourceIssues.stream()
.filter(issue -> issue.getIndex() >= startSort)
.collect(Collectors.toList());
}
sourceIssues = sourceIssues.stream()
.sorted(Comparator.comparing(SourceIssue::getIndex))
.collect(Collectors.toList());
Map<String, List<SourceIssue>> groupedIssues = sourceIssues.stream()
.collect(Collectors.groupingBy(SourceIssue::getType, LinkedHashMap::new, Collectors.toList()));
sourceIssues = groupedIssues.values().stream().flatMap(List::stream).collect(Collectors.toList());
if (!param.isResumeFormal() && CollUtil.isNotEmpty(sourceIssues)) {
iPqDevService.clearFormalProgressForNewRun(param.getDevIds());
}
SocketManager.addSourceList(sourceIssues);
Map<String, Long> sourceIssueMap = sourceIssues.stream()
.collect(Collectors.groupingBy(SourceIssue::getType, Collectors.counting()));
SocketManager.initMap(sourceIssueMap);
if (waitForProgressRestore) {
FormalTestManager.resumeFormalPending = true;
WebServiceManager.sendDetectionMessage(param.getUserPageId(), "formal_progress_required", null, null, null);
return;
}
sendFirstFormalIssue(param, sourceIssues);
}
private List<SourceIssue> buildFormalIssues(PreDetectionParam param) {
PqScriptIssueParam issueParam = new PqScriptIssueParam();
issueParam.setSourceId(param.getSourceName());
issueParam.setPlanId(param.getPlanId());
issueParam.setDevIds(param.getDevIds());
issueParam.setScriptId(param.getScriptId());
if (!param.isResumeFormal() && SourceOperateCodeEnum.RE_ERROR_TEST.getValue().equals(param.getReCheckType())) {
Set<Integer> indexes = new HashSet<>();
StorageParam storageParam = new StorageParam();
storageParam.setCode(param.getCode());
storageParam.setScriptId(param.getScriptId());
param.getDevIds().forEach(devId -> {
storageParam.setDevId(devId);
indexes.addAll(adHarmonicService.getIndex(storageParam));
});
issueParam.setIndexList(indexes.stream().collect(Collectors.toList()));
issueParam.setIsPhaseSequence(SourceOperateCodeEnum.RE_ERROR_TEST.getValue());
} else {
issueParam.setIsPhaseSequence(CommonEnum.FORMAL_TEST.getValue());
}
return pqScriptDtlsService.listSourceIssue(issueParam);
}
private void sendFirstFormalIssue(PreDetectionParam param, List<SourceIssue> sourceIssues) {
if (CollUtil.isEmpty(sourceIssues)) {
WebServiceManager.sendDetectionMessage(param.getUserPageId(), "formal_progress_no_next", null, null, null);
return;
}
SourceIssue firstIssue = sourceIssues.get(0);
WebSocketVO<Object> webSocketVO = new WebSocketVO<>();
String type = firstIssue.getType();
if (StrUtil.isNotBlank(firstIssue.getOtherType())) {
firstIssue.setType(PowerIndexEnum.V.getKey());
webSocketVO.setRequestId(firstIssue.getOtherType() + CnSocketUtil.START_TAG);
type = firstIssue.getOtherType();
} else {
webSocketVO.setRequestId(firstIssue.getType() + CnSocketUtil.START_TAG);
}
FormalTestManager.currentIssue = firstIssue;
FormalTestManager.resumeFormalStartTime = LocalDateTime.now();
SocketMsg<String> socketMsg = new SocketMsg<>();
socketMsg.setOperateCode(SourceOperateCodeEnum.OPER_GATHER.getValue());
socketMsg.setData(JSON.toJSONString(firstIssue));
socketMsg.setRequestId(SourceOperateCodeEnum.FORMAL_REAL.getValue() + CnSocketUtil.STEP_TAG + type);
SocketManager.sendMsg(param.getUserPageId() + CnSocketUtil.SOURCE_TAG, JSON.toJSONString(socketMsg));
webSocketVO.setDesc(null);
WebServiceManager.sendMsg(param.getUserPageId(), JSON.toJSONString(webSocketVO));
}
/**
* 正式检测
*/
@@ -1369,7 +1334,7 @@ public class SocketDevResponseService {
String type = sourceIssues.getType();
if (StrUtil.isNotBlank(sourceIssues.getOtherType())) {
sourceIssues.setType(ResultUnitEnum.V_ABSOLUTELY.getCode());
sourceIssues.setType(PowerIndexEnum.V.getKey());
type = sourceIssues.getOtherType();
}
// 如果上一个大项检测完成,则检测下一个大项,并向前端推送消息
@@ -2014,7 +1979,7 @@ public class SocketDevResponseService {
adHarmonicResult.setAdType(checkDataMap.get(sqlDataDTO.getDesc()));
adHarmonicResult.setDataType(sourceIssue.getDataType());
if (!DicDataEnum.HSV.getCode().equals(sourceIssue.getType()) && !DicDataEnum.HSI.getCode().equals(sourceIssue.getType()) && !DicDataEnum.HP.getCode().equals(sourceIssue.getType())) {
if (!PowerIndexEnum.HSV.getKey().equals(sourceIssue.getType()) && !PowerIndexEnum.HSI.getKey().equals(sourceIssue.getType()) && !PowerIndexEnum.HP.getKey().equals(sourceIssue.getType())) {
if (CollUtil.isNotEmpty(data.getSqlData())) {
DevData.SqlDataDTO.ListDTO vvv = data.getSqlData().stream().filter(it -> it.getDesc().equals(dui)).collect(Collectors.toList()).get(0).getList();
Double aV = vvv.getA();
@@ -2039,7 +2004,7 @@ public class SocketDevResponseService {
List<String> c = tem.getC();
Class<SimAndDigHarmonicResult> example = (Class<SimAndDigHarmonicResult>) adHarmonicResult.getClass();
if (DicDataEnum.HSV.getCode().equals(sourceIssue.getType()) || DicDataEnum.HSI.getCode().equals(sourceIssue.getType())) {
if (PowerIndexEnum.HSV.getKey().equals(sourceIssue.getType()) || PowerIndexEnum.HSI.getKey().equals(sourceIssue.getType())) {
for (int i = 1; i < a.size() + 1; i++) {
try {
Field aField = example.getDeclaredField("aValue" + i);

View File

@@ -17,11 +17,10 @@ import com.njcn.gather.device.pojo.vo.PreDetection;
import com.njcn.gather.device.service.IPqDevService;
import com.njcn.gather.plan.pojo.po.AdPlanSource;
import com.njcn.gather.plan.service.IAdPlanSourceService;
import com.njcn.gather.result.pojo.enums.ResultUnitEnum;
import com.njcn.gather.report.pojo.enums.PowerIndexEnum;
import com.njcn.gather.script.pojo.po.SourceIssue;
import com.njcn.gather.source.pojo.po.SourceInitialize;
import com.njcn.gather.source.service.IPqSourceService;
import com.njcn.gather.system.pojo.enums.DicDataEnum;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
@@ -386,8 +385,8 @@ public class SocketSourceResponseService {
//重新下发脚本
String type = FormalTestManager.currentIssue.getType();
if (ResultUnitEnum.P.getCode().equals(type)) {
FormalTestManager.currentIssue.setType(ResultUnitEnum.V_ABSOLUTELY.getCode());
if (PowerIndexEnum.P.getKey().equals(type)) {
FormalTestManager.currentIssue.setType(PowerIndexEnum.V.getKey());
}
socketMsg.setOperateCode(SourceOperateCodeEnum.OPER_GATHER.getValue());
socketMsg.setData(JSON.toJSONString(FormalTestManager.currentIssue));
@@ -538,14 +537,14 @@ public class SocketSourceResponseService {
int ignoreCount;
int readData;
if (DicDataEnum.F.getCode().equals(sourceIssue.getType())) {
if (PowerIndexEnum.F.getKey().equals(sourceIssue.getType())) {
// 闪变检测:数据变化较慢,只需少量预热和读取
// 闪变测量稳定性好预热1次即可
ignoreCount = 1;
// 读取2次数据计算闪变值
readData = 2;
socketMsg.setOperateCode(SourceOperateCodeEnum.DEV_DATA_REQUEST_01.getValue());
} else if (DicDataEnum.VOLTAGE.getCode().equals(sourceIssue.getType())) {
} else if (PowerIndexEnum.VOLTAGE.getKey().equals(sourceIssue.getType())) {
// 暂态电压检测:需要更多预热时间,但只读取一次快照
// 暂态事件需要5次预热确保触发稳定
ignoreCount = 5;

View File

@@ -0,0 +1,25 @@
package com.njcn.gather.detection.pojo.param;
import lombok.Data;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotEmpty;
import java.util.List;
@Data
public class FormalProgressParam {
@NotBlank(message = "计划id不可为空")
private String planId;
@NotEmpty(message = "装置不能为空")
private List<String> devIds;
private String userPageId;
private String userId;
/**
* 保存暂存进度时必传;查询/放行续检时以后端设备表为准。
*/
private Integer formalCheckTime;
}

View File

@@ -79,6 +79,11 @@ public class PreDetectionParam {
*/
private List<Boolean> testItemList;
/**
* 是否从正式检测暂存进度续检
*/
private Boolean resumeFormal;
public boolean isPreTestSelected() {
return isTestItemSelected(0);
}
@@ -95,6 +100,10 @@ public class PreDetectionParam {
return isTestItemSelected(3);
}
public boolean isResumeFormal() {
return Boolean.TRUE.equals(resumeFormal);
}
private boolean isTestItemSelected(int index) {
return testItemList != null && testItemList.size() > index && Boolean.TRUE.equals(testItemList.get(index));
}

View File

@@ -0,0 +1,30 @@
package com.njcn.gather.detection.pojo.vo;
import lombok.Data;
import java.util.ArrayList;
import java.util.List;
@Data
public class FormalProgressVO {
private Integer formalCheckTime;
private Integer minMaxSort;
private Integer nextSort;
private Double process;
private List<TableRow> tableRows = new ArrayList<>();
@Data
public static class TableRow {
private String scriptType;
private String scriptCode;
private String scriptName;
private List<DeviceResult> devices = new ArrayList<>();
}
@Data
public static class DeviceResult {
private String deviceId;
private String deviceName;
private List<Integer> chnResult = new ArrayList<>();
}
}

View File

@@ -0,0 +1,11 @@
package com.njcn.gather.detection.service;
import com.njcn.gather.detection.pojo.param.FormalProgressParam;
import com.njcn.gather.detection.pojo.param.PreDetectionParam;
import com.njcn.gather.detection.pojo.vo.FormalProgressVO;
public interface FormalProgressService {
FormalProgressVO restoreAndRelease(FormalProgressParam param);
Integer calculateNextSort(PreDetectionParam param);
}

View File

@@ -1,8 +1,10 @@
package com.njcn.gather.detection.service;
import com.njcn.gather.detection.pojo.param.ContrastDetectionParam;
import com.njcn.gather.detection.pojo.param.FormalProgressParam;
import com.njcn.gather.detection.pojo.param.PreDetectionParam;
import com.njcn.gather.detection.pojo.param.SimulateDetectionParam;
import com.njcn.gather.detection.pojo.vo.FormalProgressVO;
import java.util.List;
import java.util.Map;
@@ -33,6 +35,10 @@ public interface PreDetectionService {
boolean restartTemTest(PreDetectionParam param);
void saveFormalProgress(FormalProgressParam param);
FormalProgressVO formalProgress(FormalProgressParam param);
/**
* 模拟测试-源通讯校验
*

View File

@@ -28,7 +28,6 @@ import com.njcn.gather.monitor.pojo.po.PqMonitor;
import com.njcn.gather.monitor.service.IPqMonitorService;
import com.njcn.gather.plan.pojo.enums.DataSourceEnum;
import com.njcn.gather.report.pojo.enums.PowerIndexEnum;
import com.njcn.gather.result.pojo.enums.ResultUnitEnum;
import com.njcn.gather.script.mapper.PqScriptMapper;
import com.njcn.gather.script.pojo.po.PqScriptCheckData;
import com.njcn.gather.script.pojo.po.SourceIssue;
@@ -82,7 +81,6 @@ public class DetectionServiceImpl {
public static final String TYPE_T = "T";
private final String U = "U";
private final String I = "I";
private final String F = "F";
private final String HP = "HP";
private final String P = "P";
private final String MAG = "MAG";
@@ -163,33 +161,31 @@ public class DetectionServiceImpl {
param.setIn(sourceIssue.getFIn());
SysTestConfig oneConfig = sysTestConfigService.getOneConfig();
List<ErrDtlsCheckDataVO> errDtlsCheckData = pqErrSysDtlsService.listByPqErrSysIdAndTypes(param);
ResultUnitEnum resultUnitEnumByCode = ResultUnitEnum.getResultUnitEnumByCode(sourceIssue.getType());
PowerIndexEnum powerIndexEnum = PowerIndexEnum.getByKey(sourceIssue.getType());
if (StrUtil.isNotBlank(sourceIssue.getOtherType())) {
resultUnitEnumByCode = ResultUnitEnum.getResultUnitEnumByCode(sourceIssue.getOtherType());
powerIndexEnum = PowerIndexEnum.getByKey(sourceIssue.getOtherType());
}
switch (resultUnitEnumByCode) {
switch (powerIndexEnum) {
/**
* 频率
*/
case FREQ:
return isQualified(dev, devIdMapComm, errDtlsCheckData, F, sourceIssue, dataRule, code, oneConfig.getScale());
return isQualified(dev, devIdMapComm, errDtlsCheckData, PowerIndexEnum.FREQ.getKey(), sourceIssue, dataRule, code, oneConfig.getScale());
case P:
return isQualified(dev, devIdMapComm, errDtlsCheckData, P, sourceIssue, dataRule, code, oneConfig.getScale());
return isQualified(dev, devIdMapComm, errDtlsCheckData, PowerIndexEnum.P.getKey(), sourceIssue, dataRule, code, oneConfig.getScale());
case ANGLE:
return isQualified(dev, devIdMapComm, errDtlsCheckData, resultUnitEnumByCode.getCode(), sourceIssue, dataRule, code, oneConfig.getScale());
return isQualified(dev, devIdMapComm, errDtlsCheckData, PowerIndexEnum.ANGLE.getKey(), sourceIssue, dataRule, code, oneConfig.getScale());
/**
* 电压
*/
case V_RELATIVE:
case V_ABSOLUTELY:
return isQualified(dev, devIdMapComm, errDtlsCheckData, U, sourceIssue, dataRule, code, oneConfig.getScale());
case V:
return isQualified(dev, devIdMapComm, errDtlsCheckData, PowerIndexEnum.V.getKey(), sourceIssue, dataRule, code, oneConfig.getScale());
/**
* 电流
*/
case I_RELATIVE:
case I_ABSOLUTELY:
return isQualified(dev, devIdMapComm, errDtlsCheckData, I, sourceIssue, dataRule, code, oneConfig.getScale());
case I:
return isQualified(dev, devIdMapComm, errDtlsCheckData, PowerIndexEnum.I.getKey(), sourceIssue, dataRule, code, oneConfig.getScale());
/**
* 谐波
*/
@@ -234,8 +230,7 @@ public class DetectionServiceImpl {
/**
* 暂态
*/
case VOLTAGE_MAG:
case VOLTAGE_DUR:
case VOLTAGE:
return isVoltageQualified(dev, devIdMapComm, errDtlsCheckData, sourceIssue, dataRule, code, oneConfig.getScale());
default:
return isUnknownQualified(dev, devIdMapComm, errDtlsCheckData, sourceIssue, dataRule, code, oneConfig.getScale());
@@ -428,16 +423,16 @@ public class DetectionServiceImpl {
dtlsCheckData = errDtlsCheckData.stream().filter(x -> x.getValueTypeCode().equals(splitArr[1])).collect(Collectors.toList());
}
Double fData = 1.0;
if (U.equals(type)) {
if (PowerIndexEnum.V.getKey().equals(type)) {
fData = sourceIssue.getFUn();
}
if (I.equals(type)) {
if (PowerIndexEnum.I.getKey().equals(type)) {
fData = sourceIssue.getFIn();
}
if (F.equals(type)) {
if (PowerIndexEnum.FREQ.getKey().equals(type)) {
fData = sourceIssue.getFFreq();
}
if (P.equals(type)) {
if (PowerIndexEnum.P.getKey().equals(type)) {
if (!DetectionCodeEnum.PF.getCode().equals(splitArr[1])) {
Boolean valueType = pqScriptMapper.selectScriptIsValueType(sourceIssue.getScriptId());
if (valueType) {
@@ -488,7 +483,7 @@ public class DetectionServiceImpl {
.collect(Collectors.toList());
if (CollUtil.isNotEmpty(checkData)) {
List<Double> phaseValue = map.get(phase);
if (ResultUnitEnum.ANGLE.getCode().equals(type)) {
if (PowerIndexEnum.ANGLE.getKey().equals(type)) {
phaseValue = phaseValue.stream().map(x -> {
// 原始误差值
double originDiff = x - checkData.get(0).getValue();

View File

@@ -0,0 +1,218 @@
package com.njcn.gather.detection.service.impl;
import cn.hutool.core.collection.CollUtil;
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
import com.njcn.common.pojo.exception.BusinessException;
import com.njcn.gather.detection.handler.SocketDevResponseService;
import com.njcn.gather.detection.pojo.param.FormalProgressParam;
import com.njcn.gather.detection.pojo.param.PreDetectionParam;
import com.njcn.gather.detection.pojo.vo.FormalProgressVO;
import com.njcn.gather.detection.service.FormalProgressService;
import com.njcn.gather.detection.util.socket.websocket.WebServiceManager;
import com.njcn.gather.device.pojo.enums.CommonEnum;
import com.njcn.gather.device.pojo.vo.PreDetection;
import com.njcn.gather.device.service.IPqDevService;
import com.njcn.gather.script.pojo.param.PqScriptIssueParam;
import com.njcn.gather.script.pojo.po.SourceIssue;
import com.njcn.gather.script.service.IPqScriptDtlsService;
import com.njcn.gather.storage.pojo.po.SimAndDigBaseResult;
import com.njcn.gather.storage.service.SimAndDigHarmonicService;
import com.njcn.gather.storage.service.SimAndDigNonHarmonicService;
import com.njcn.gather.system.dictionary.pojo.po.DictTree;
import com.njcn.gather.system.dictionary.service.IDictTreeService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors;
@Service
@RequiredArgsConstructor
@Slf4j
public class FormalProgressServiceImpl implements FormalProgressService {
private static final long RESUME_RELEASE_DELAY_MILLIS = 300L;
private final IPqDevService pqDevService;
private final IPqScriptDtlsService pqScriptDtlsService;
private final IDictTreeService dictTreeService;
private final SimAndDigHarmonicService harmonicService;
private final SimAndDigNonHarmonicService nonHarmonicService;
private final SocketDevResponseService socketDevResponseService;
@Override
public FormalProgressVO restoreAndRelease(FormalProgressParam param) {
PreDetectionParam preParam = WebServiceManager.getPreDetectionParam(param.getUserPageId());
if (preParam == null) {
throw new BusinessException(CommonResponseEnum.FAIL, "未找到续检上下文,请重新开始检测");
}
FormalProgressVO vo = buildSnapshot(preParam, param.getDevIds());
releaseResumeAfterSnapshotApplied(preParam, vo.getNextSort());
return vo;
}
@Override
public Integer calculateNextSort(PreDetectionParam param) {
return buildSnapshot(param, param.getDevIds()).getNextSort();
}
private FormalProgressVO buildSnapshot(PreDetectionParam param, List<String> devIds) {
FormalProgressVO vo = new FormalProgressVO();
vo.setFormalCheckTime(pqDevService.getMinFormalCheckTime(devIds));
Map<String, Integer> harmonicMax = harmonicService.maxSortByDevIds(param.getCode(), param.getScriptId(), devIds);
Map<String, Integer> nonHarmonicMax = nonHarmonicService.maxSortByDevIds(param.getCode(), param.getScriptId(), devIds);
Integer minMaxSort = devIds.stream()
.map(devId -> Math.max(harmonicMax.getOrDefault(devId, -1), nonHarmonicMax.getOrDefault(devId, -1)))
.min(Integer::compareTo)
.orElse(-1);
vo.setMinMaxSort(minMaxSort);
List<SourceIssue> allIssues = buildAllFormalIssues(param);
List<Integer> allSorts = allIssues.stream()
.map(SourceIssue::getIndex)
.filter(sort -> sort != null && sort >= 0)
.sorted()
.collect(Collectors.toList());
Integer nextSort = allSorts.stream()
.filter(sort -> sort > minMaxSort)
.findFirst()
.orElse(null);
vo.setNextSort(nextSort);
Set<String> completedTypes = completedBigTypes(allIssues, minMaxSort);
long totalBigTypes = allIssues.stream().map(SourceIssue::getType).distinct().count();
vo.setProcess(totalBigTypes == 0 ? 0D : completedTypes.size() * 100D / totalBigTypes);
vo.setTableRows(buildRows(param, devIds, allIssues, completedTypes));
return vo;
}
private void releaseResumeAfterSnapshotApplied(PreDetectionParam preParam, Integer nextSort) {
CompletableFuture.runAsync(() -> {
try {
Thread.sleep(RESUME_RELEASE_DELAY_MILLIS);
socketDevResponseService.startFormalAfterProgressRestore(preParam, nextSort);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
log.warn("正式检测续检放行等待被中断", e);
} catch (Exception e) {
log.error("正式检测续检放行失败", e);
}
});
}
private List<SourceIssue> buildAllFormalIssues(PreDetectionParam param) {
PqScriptIssueParam issueParam = new PqScriptIssueParam();
issueParam.setPlanId(param.getPlanId());
issueParam.setSourceId(param.getSourceName());
issueParam.setDevIds(param.getDevIds());
issueParam.setScriptId(param.getScriptId());
issueParam.setIsPhaseSequence(CommonEnum.FORMAL_TEST.getValue());
return pqScriptDtlsService.listSourceIssue(issueParam)
.stream()
.sorted(Comparator.comparing(SourceIssue::getIndex))
.collect(Collectors.toList());
}
private Set<String> completedBigTypes(List<SourceIssue> issues, Integer minMaxSort) {
return issues.stream()
.collect(Collectors.groupingBy(SourceIssue::getType, LinkedHashMap::new, Collectors.toList()))
.entrySet()
.stream()
.filter(entry -> entry.getValue().stream().allMatch(issue -> issue.getIndex() <= minMaxSort))
.map(Map.Entry::getKey)
.collect(Collectors.toCollection(LinkedHashSet::new));
}
private List<FormalProgressVO.TableRow> buildRows(PreDetectionParam param,
List<String> devIds,
List<SourceIssue> issues,
Set<String> completedTypes) {
Map<String, List<SourceIssue>> byType = issues.stream()
.collect(Collectors.groupingBy(SourceIssue::getType, LinkedHashMap::new, Collectors.toList()));
if (byType.isEmpty()) {
return Collections.emptyList();
}
Map<String, DictTree> dictTreeByCode = dictTreeService.lambdaQuery()
.in(DictTree::getCode, byType.keySet())
.list()
.stream()
.collect(Collectors.toMap(DictTree::getCode, dictTree -> dictTree, (left, right) -> left));
return byType.entrySet().stream().map(entry -> {
List<SourceIssue> typeIssues = entry.getValue();
boolean completed = completedTypes.contains(entry.getKey());
DictTree dictTree = dictTreeByCode.get(entry.getKey());
FormalProgressVO.TableRow row = new FormalProgressVO.TableRow();
row.setScriptCode(entry.getKey());
row.setScriptName(dictTree.getName());
row.setScriptType(dictTree.getId());
row.setDevices(completed
? buildCompletedDeviceResults(param, devIds, typeIssues)
: buildUnknownDeviceResults(devIds));
return row;
}).collect(Collectors.toList());
}
private List<FormalProgressVO.DeviceResult> buildUnknownDeviceResults(List<String> devIds) {
return pqDevService.getDevInfo(devIds).stream().map(dev -> {
FormalProgressVO.DeviceResult item = new FormalProgressVO.DeviceResult();
item.setDeviceId(dev.getDevId());
item.setDeviceName(dev.getDevName());
item.setChnResult(dev.getMonitorList().stream().map(monitor -> -1).collect(Collectors.toList()));
return item;
}).collect(Collectors.toList());
}
private List<FormalProgressVO.DeviceResult> buildCompletedDeviceResults(PreDetectionParam param,
List<String> devIds,
List<SourceIssue> typeIssues) {
List<Integer> sorts = typeIssues.stream().map(SourceIssue::getIndex).distinct().collect(Collectors.toList());
List<SimAndDigBaseResult> rows = new ArrayList<>();
rows.addAll(harmonicService.listByDevIdsAndSorts(param.getCode(), param.getScriptId(), devIds, sorts));
rows.addAll(nonHarmonicService.listByDevIdsAndSorts(param.getCode(), param.getScriptId(), devIds, sorts));
Map<String, List<Integer>> flagMap = rows.stream()
.filter(row -> row.getResultFlag() != null)
.collect(Collectors.groupingBy(SimAndDigBaseResult::getDevMonitorId,
Collectors.mapping(SimAndDigBaseResult::getResultFlag, Collectors.toList())));
return pqDevService.getDevInfo(devIds).stream().map(dev -> {
FormalProgressVO.DeviceResult item = new FormalProgressVO.DeviceResult();
item.setDeviceId(dev.getDevId());
item.setDeviceName(dev.getDevName());
item.setChnResult(dev.getMonitorList().stream()
.map(monitor -> mergeResultFlags(resolveResultFlags(flagMap, dev, monitor)))
.collect(Collectors.toList()));
return item;
}).collect(Collectors.toList());
}
private List<Integer> resolveResultFlags(Map<String, List<Integer>> flagMap, PreDetection dev, PreDetection.MonitorListDTO monitor) {
List<Integer> flags = new ArrayList<>();
List<Integer> byDevLine = flagMap.get(dev.getDevId() + "_" + monitor.getLine());
if (CollUtil.isNotEmpty(byDevLine)) {
flags.addAll(byDevLine);
}
List<Integer> byLineId = flagMap.get(monitor.getLineId());
if (CollUtil.isNotEmpty(byLineId)) {
flags.addAll(byLineId);
}
return flags;
}
private Integer mergeResultFlags(List<Integer> flags) {
if (CollUtil.isEmpty(flags)) {
return -1;
}
List<Integer> effective = flags.stream()
.filter(flag -> flag != null && flag != 4 && flag != 5)
.collect(Collectors.toList());
if (CollUtil.isNotEmpty(effective)) {
return effective.stream().max(Integer::compareTo).orElse(1);
}
return flags.get(0);
}
}

View File

@@ -6,6 +6,8 @@ import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
import com.njcn.common.pojo.exception.BusinessException;
import com.njcn.gather.detection.handler.SocketContrastResponseService;
import com.njcn.gather.detection.handler.SocketDevResponseService;
@@ -14,9 +16,12 @@ import com.njcn.gather.detection.pojo.constant.DetectionCommunicateConstant;
import com.njcn.gather.detection.pojo.enums.DetectionResponseEnum;
import com.njcn.gather.detection.pojo.enums.SourceOperateCodeEnum;
import com.njcn.gather.detection.pojo.param.ContrastDetectionParam;
import com.njcn.gather.detection.pojo.param.FormalProgressParam;
import com.njcn.gather.detection.pojo.param.PreDetectionParam;
import com.njcn.gather.detection.pojo.param.SimulateDetectionParam;
import com.njcn.gather.detection.pojo.vo.FormalProgressVO;
import com.njcn.gather.detection.pojo.vo.SocketMsg;
import com.njcn.gather.detection.service.FormalProgressService;
import com.njcn.gather.detection.service.PreDetectionService;
import com.njcn.gather.detection.util.business.DetectionCommunicateUtil;
import com.njcn.gather.detection.util.socket.CnSocketUtil;
@@ -25,15 +30,20 @@ import com.njcn.gather.detection.util.socket.SocketManager;
import com.njcn.gather.detection.util.socket.XiNumberManager;
import com.njcn.gather.detection.util.socket.cilent.NettyContrastClientHandler;
import com.njcn.gather.detection.util.socket.websocket.WebServiceManager;
import com.njcn.gather.device.pojo.enums.CheckResultEnum;
import com.njcn.gather.device.pojo.enums.CheckStateEnum;
import com.njcn.gather.device.pojo.enums.CommonEnum;
import com.njcn.gather.device.pojo.po.PqDev;
import com.njcn.gather.device.pojo.po.PqDevSub;
import com.njcn.gather.device.pojo.vo.PreDetection;
import com.njcn.gather.device.service.IPqDevService;
import com.njcn.gather.device.service.IPqDevSubService;
import com.njcn.gather.plan.pojo.enums.DataSourceEnum;
import com.njcn.gather.plan.pojo.po.AdPlan;
import com.njcn.gather.plan.pojo.po.AdPlanSource;
import com.njcn.gather.plan.service.IAdPlanService;
import com.njcn.gather.plan.service.IAdPlanSourceService;
import com.njcn.gather.result.pojo.enums.ResultUnitEnum;
import com.njcn.gather.report.pojo.enums.PowerIndexEnum;
import com.njcn.gather.script.pojo.param.PqScriptCheckDataParam;
import com.njcn.gather.script.pojo.param.PqScriptIssueParam;
import com.njcn.gather.script.pojo.po.SourceIssue;
@@ -41,6 +51,8 @@ import com.njcn.gather.script.service.IPqScriptCheckDataService;
import com.njcn.gather.script.service.IPqScriptDtlsService;
import com.njcn.gather.source.pojo.po.SourceInitialize;
import com.njcn.gather.source.service.IPqSourceService;
import com.njcn.gather.storage.service.SimAndDigHarmonicService;
import com.njcn.gather.storage.service.SimAndDigNonHarmonicService;
import com.njcn.gather.system.cfg.service.ISysTestConfigService;
import com.njcn.gather.system.config.PathConfig;
import com.njcn.gather.system.dictionary.pojo.enums.DictDataEnum;
@@ -50,7 +62,6 @@ import com.njcn.web.utils.RequestUtil;
import io.netty.channel.Channel;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import javax.servlet.ServletOutputStream;
@@ -82,9 +93,13 @@ public class PreDetectionServiceImpl implements PreDetectionService {
private final IPqScriptCheckDataService iPqScriptCheckDataService;
private final SocketManager socketManager;
private final ISysTestConfigService sysTestConfigService;
private final FormalProgressService formalProgressService;
private final IPqDevSubService pqDevSubService;
private final SimAndDigHarmonicService harmonicService;
private final SimAndDigNonHarmonicService nonHarmonicService;
// @Value("${report.reportDir}")
// @Value("${report.reportDir}")
// private String alignDataFilePath;
private final PathConfig pathConfig;
@@ -103,6 +118,28 @@ public class PreDetectionServiceImpl implements PreDetectionService {
param.setScriptId(plan.getScriptId());
param.setErrorSysId(plan.getErrorSysId());
param.setCode(String.valueOf(plan.getCode()));
if (param.isFormalTestSelected()) {
List<PqDevSub> devSubs = pqDevSubService.lambdaQuery()
.in(PqDevSub::getDevId, param.getDevIds())
.list();
boolean hasSaved = devSubs.stream().anyMatch(this::isSavedFormalProgress);
if (param.isResumeFormal() && !hasSaved) {
throw new BusinessException(CommonResponseEnum.FAIL, "未找到正式检测暂存进度");
}
}
if (param.isFormalTestSelected() && !param.isResumeFormal()) {
FormalTestManager.resumeBaseFormalCheckTime = null;
FormalTestManager.resumeFormalStartTime = null;
FormalTestManager.resumeNextSort = null;
FormalTestManager.resumeFormalPending = false;
}
if (param.isFormalTestSelected() && param.isResumeFormal()) {
FormalTestManager.resumeBaseFormalCheckTime = iPqDevService.getMinFormalCheckTime(param.getDevIds());
pqDevSubService.lambdaUpdate()
.set(PqDevSub::getCheckState, CheckStateEnum.CHECKING.getValue())
.in(PqDevSub::getDevId, param.getDevIds())
.update();
}
if (ObjectUtil.isNotNull(plan)) {
String code = dictDataService.getDictDataById(plan.getPattern()).getCode();
DictDataEnum dictDataEnumByCode = DictDataEnum.getDictDataEnumByCode(code);
@@ -274,6 +311,180 @@ public class PreDetectionServiceImpl implements PreDetectionService {
return true;
}
@Override
public void saveFormalProgress(FormalProgressParam param) {
if (param.getFormalCheckTime() == null) {
throw new BusinessException(CommonResponseEnum.FAIL, "正式检测耗时不能为空");
}
PreDetectionParam preParam = WebServiceManager.getPreDetectionParam(param.getUserPageId());
Map<String, Integer> checkResultMap = summarizeSavedFormalCheckResult(param, preParam);
Integer formalCheckTime = Math.max(param.getFormalCheckTime(), 1);
Map<Integer, List<String>> devIdsByResult = param.getDevIds().stream()
.collect(Collectors.groupingBy(devId -> checkResultMap.getOrDefault(devId, CheckResultEnum.UNCHECKED.getValue())));
devIdsByResult.forEach((checkResult, devIds) -> pqDevSubService.update(new LambdaUpdateWrapper<PqDevSub>()
.set(PqDevSub::getCheckState, CheckStateEnum.CHECKING.getValue())
.set(PqDevSub::getFormalCheckTime, formalCheckTime)
.set(PqDevSub::getCheckResult, checkResult)
.in(PqDevSub::getDevId, devIds)));
refreshPlanTestState(param.getPlanId());
if (preParam != null) {
CnSocketUtil.quitSend(preParam);
}
SocketManager.clearFormalRuntime();
FormalTestManager.clearFormalRuntime();
WebServiceManager.removePreDetectionParam(param.getUserPageId());
}
@Override
public FormalProgressVO formalProgress(FormalProgressParam param) {
return formalProgressService.restoreAndRelease(param);
}
private Map<String, Integer> summarizeSavedFormalCheckResult(FormalProgressParam param, PreDetectionParam preParam) {
Map<String, Integer> result = new HashMap<>();
if (CollUtil.isEmpty(param.getDevIds())) {
return result;
}
param.getDevIds().forEach(devId -> result.put(devId, CheckResultEnum.UNCHECKED.getValue()));
AdPlan plan = iAdPlanService.getById(param.getPlanId());
String code = preParam != null && StrUtil.isNotBlank(preParam.getCode())
? preParam.getCode()
: plan != null && plan.getCode() != null ? String.valueOf(plan.getCode()) : null;
String scriptId = preParam != null && StrUtil.isNotBlank(preParam.getScriptId())
? preParam.getScriptId()
: plan != null ? plan.getScriptId() : null;
if (StrUtil.isBlank(code) || StrUtil.isBlank(scriptId)) {
return result;
}
List<Integer> completedSorts = resolveCompletedFormalSorts(preParam);
if (completedSorts != null && CollUtil.isEmpty(completedSorts)) {
return result;
}
Map<String, List<Integer>> resultFlags = new HashMap<>();
mergeResultFlags(resultFlags, nonHarmonicService.resultFlagsByDevIdsAndSorts(code, scriptId, param.getDevIds(), completedSorts));
mergeResultFlags(resultFlags, harmonicService.resultFlagsByDevIdsAndSorts(code, scriptId, param.getDevIds(), completedSorts));
param.getDevIds().forEach(devId -> result.put(devId, toCheckResult(resultFlags.get(devId))));
return result;
}
private List<Integer> resolveCompletedFormalSorts(PreDetectionParam preParam) {
if (preParam == null) {
return null;
}
List<SourceIssue> allIssues = buildAllFormalIssues(preParam);
if (CollUtil.isEmpty(allIssues)) {
return Collections.emptyList();
}
List<SourceIssue> remainingIssues = SocketManager.getSourceList();
Set<Integer> remainingSorts = CollUtil.isEmpty(remainingIssues)
? Collections.emptySet()
: remainingIssues.stream()
.map(SourceIssue::getIndex)
.filter(Objects::nonNull)
.collect(Collectors.toSet());
return allIssues.stream()
.map(SourceIssue::getIndex)
.filter(Objects::nonNull)
.filter(sort -> !remainingSorts.contains(sort))
.distinct()
.sorted()
.collect(Collectors.toList());
}
private List<SourceIssue> buildAllFormalIssues(PreDetectionParam param) {
PqScriptIssueParam issueParam = new PqScriptIssueParam();
issueParam.setPlanId(param.getPlanId());
issueParam.setSourceId(param.getSourceName());
issueParam.setDevIds(param.getDevIds());
issueParam.setScriptId(param.getScriptId());
issueParam.setIsPhaseSequence(CommonEnum.FORMAL_TEST.getValue());
return pqScriptDtlsService.listSourceIssue(issueParam);
}
private void mergeResultFlags(Map<String, List<Integer>> target, Map<String, List<Integer>> source) {
if (CollUtil.isEmpty(source)) {
return;
}
source.forEach((devId, flags) -> target.computeIfAbsent(devId, key -> new ArrayList<>()).addAll(flags));
}
private Integer toCheckResult(List<Integer> resultFlags) {
if (CollUtil.isEmpty(resultFlags)) {
return CheckResultEnum.UNCHECKED.getValue();
}
List<Integer> effectiveFlags = resultFlags.stream()
.filter(flag -> flag != null && flag != 4 && flag != 5)
.collect(Collectors.toList());
if (CollUtil.isEmpty(effectiveFlags)) {
return CheckResultEnum.ACCORD.getValue();
}
boolean hasFailed = effectiveFlags.stream().anyMatch(flag -> !Objects.equals(flag, 1));
return hasFailed ? CheckResultEnum.NOT_ACCORD.getValue() : CheckResultEnum.ACCORD.getValue();
}
private boolean isSavedFormalProgress(PqDevSub dev) {
return CheckStateEnum.CHECKING.getValue().equals(dev.getCheckState())
&& ObjectUtil.isNotNull(dev.getFormalCheckTime())
&& dev.getFormalCheckTime() > 0;
}
private void refreshPlanTestState(String planId) {
if (StrUtil.isBlank(planId)) {
return;
}
List<String> planDevIds = iPqDevService.lambdaQuery()
.eq(PqDev::getPlanId, planId)
.list()
.stream()
.map(PqDev::getId)
.collect(Collectors.toList());
if (CollUtil.isEmpty(planDevIds)) {
iAdPlanService.lambdaUpdate()
.set(AdPlan::getTestState, CheckStateEnum.UNCHECKED.getValue())
.set(AdPlan::getResult, CheckResultEnum.UNCHECKED.getValue())
.eq(AdPlan::getId, planId)
.update();
return;
}
List<PqDevSub> devSubs = pqDevSubService.lambdaQuery()
.in(PqDevSub::getDevId, planDevIds)
.list();
boolean allUnchecked = devSubs.stream()
.allMatch(dev -> CheckStateEnum.UNCHECKED.getValue().equals(dev.getCheckState()));
boolean allArchived = CollUtil.isNotEmpty(devSubs) && devSubs.stream()
.allMatch(dev -> dev.getCheckState() != null && dev.getCheckState() >= CheckStateEnum.DOCUMENTED.getValue());
Integer testState = allUnchecked
? CheckStateEnum.UNCHECKED.getValue()
: allArchived ? CheckStateEnum.CHECKED.getValue() : CheckStateEnum.CHECKING.getValue();
Integer planResult = resolvePlanCheckResult(devSubs);
iAdPlanService.lambdaUpdate()
.set(AdPlan::getTestState, testState)
.set(AdPlan::getResult, planResult)
.eq(AdPlan::getId, planId)
.update();
}
private Integer resolvePlanCheckResult(List<PqDevSub> devSubs) {
if (CollUtil.isEmpty(devSubs)) {
return CheckResultEnum.UNCHECKED.getValue();
}
Set<Integer> resultSet = devSubs.stream()
.map(PqDevSub::getCheckResult)
.filter(Objects::nonNull)
.collect(Collectors.toSet());
if (resultSet.contains(CheckResultEnum.NOT_ACCORD.getValue())) {
return CheckResultEnum.NOT_ACCORD.getValue();
}
if (resultSet.contains(CheckResultEnum.UNCHECKED.getValue()) || CollUtil.isEmpty(resultSet)) {
return CheckResultEnum.UNCHECKED.getValue();
}
return CheckResultEnum.ACCORD.getValue();
}
@Override
public void ytxCheckSimulate(SimulateDetectionParam param) {
PreDetectionParam preDetectionParam = new PreDetectionParam();
@@ -312,7 +523,7 @@ public class PreDetectionServiceImpl implements PreDetectionService {
SourceIssue sourceIssue = sourceIssues.get(0);
String type = sourceIssue.getType();
if (StrUtil.isNotBlank(sourceIssue.getOtherType())) {
sourceIssue.setType(ResultUnitEnum.V_ABSOLUTELY.getCode());
sourceIssue.setType(PowerIndexEnum.V.getKey());
type = sourceIssue.getOtherType();
}
@@ -462,4 +673,4 @@ public class PreDetectionServiceImpl implements PreDetectionService {
}
}
}
}

View File

@@ -220,9 +220,29 @@ public class FormalTestManager {
*/
public static LocalDateTime checkStartTime;
public static boolean resumeFormalPending;
public static Integer resumeNextSort;
public static Integer resumeBaseFormalCheckTime;
public static LocalDateTime resumeFormalStartTime;
/**
* 数模式 检测类型"1"-"全部检测" , "2"-"不合格项复检"
*/
public static String reCheckType;
public static void clearFormalRuntime() {
stopFlag = false;
hasStopFlag = false;
stopTime = 0;
resumeFormalPending = false;
resumeNextSort = null;
resumeBaseFormalCheckTime = null;
resumeFormalStartTime = null;
realDataXiList.clear();
currentIssue = null;
}
}

View File

@@ -343,6 +343,11 @@ public class SocketManager {
return targetMap.get(scriptType);
}
public static void clearFormalRuntime() {
sourceIssueList.clear();
targetMap.clear();
valueTypeMap.clear();
clockMap.clear();
}
}

View File

@@ -15,8 +15,8 @@ import com.njcn.gather.detection.util.socket.FormalTestManager;
import com.njcn.gather.detection.util.socket.SocketManager;
import com.njcn.gather.detection.util.socket.websocket.WebServiceManager;
import com.njcn.gather.device.pojo.vo.PreDetection;
import com.njcn.gather.report.pojo.enums.PowerIndexEnum;
import com.njcn.gather.script.pojo.po.SourceIssue;
import com.njcn.gather.system.pojo.enums.DicDataEnum;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
@@ -55,17 +55,17 @@ import java.util.stream.Collectors;
public class NettyDevClientHandler extends SimpleChannelInboundHandler<String> {
/**
* 闪检测超时时间20分钟1300秒
* 闪检测超时时间20分钟+100秒1300秒
*/
private static final long FLICKER_TIMEOUT = 1300L;
private static final long SHORT_FLICKER_TIMEOUT = 1300L;
/**
* 统计数据检测超时时间3分钟180秒
* 统计数据检测超时时间3分钟+100秒190秒
*/
private static final long STATISTICS_TIMEOUT = 180L;
private static final long STATISTICS_TIMEOUT = 190L;
/**
* 实时数据检测超时时间1分钟60秒
* 实时数据检测超时时间1分钟*3
*/
private static final long REALTIME_TIMEOUT = 60 * 3L;
@@ -305,10 +305,10 @@ public class NettyDevClientHandler extends SimpleChannelInboundHandler<String> {
String type = sourceIssue.getType();
// 根据不同检测类型使用不同的超时阈值
if (DicDataEnum.F.getCode().equals(type)) {
if (PowerIndexEnum.F.getKey().equals(type)) {
// 闪变检测需要更长时间20分钟超时
return currentTime >= FLICKER_TIMEOUT;
} else if (DicDataEnum.VOLTAGE.getCode().equals(type) || DicDataEnum.HP.getCode().equals(type)) {
return currentTime >= SHORT_FLICKER_TIMEOUT;
} else if (PowerIndexEnum.VOLTAGE.getKey().equals(type) || PowerIndexEnum.HP.getKey().equals(type)) {
// 统计数据类型电压、谐波中等时间3分钟超时
return currentTime >= STATISTICS_TIMEOUT;
} else {

View File

@@ -12,7 +12,7 @@ public enum CheckStateEnum {
CHECKING("检测中", 1),
CHECKED("检测完成", 2),
/**
* 检测计划没有状态,只有未检、检测中、检测完成三种状态。被检设备有这种状态
* 检测计划没有归档状态,只有未检、检测中、检测完成三种状态。被检设备有归档状态
*/
DOCUMENTED("归档", 3);

View File

@@ -129,6 +129,13 @@ public interface IPqDevService extends IService<PqDev> {
*/
boolean updateResult(List<String> ids, List<String> adType, String code, String userId, Float temperature, Float humidity, boolean updateCheckNum);
/**
* 新一轮正式检测真正开始前,仅清理原检测中设备的暂存耗时,并把本次设备置为检测中。
*/
void clearFormalProgressForNewRun(List<String> devIds);
Integer getMinFormalCheckTime(List<String> devIds);
/**
* 比对式-修改设备状态
*

View File

@@ -367,24 +367,8 @@ public class PqDevServiceImpl extends ServiceImpl<PqDevMapper, PqDev> implements
List<String> notUnchecked = list.stream().filter(x -> !CheckStateEnum.UNCHECKED.getValue().equals(x.getCheckState())).map(PqDevSub::getDevId).distinct().collect(Collectors.toList());
if (CollUtil.isNotEmpty(notUnchecked)) {
List<String> unchecked = list.stream().filter(x -> CheckStateEnum.UNCHECKED.getValue().equals(x.getCheckState())).map(PqDevSub::getDevId).distinct().collect(Collectors.toList());
//计划未检测
if (CollUtil.isNotEmpty(unchecked)) {
return CheckStateEnum.CHECKING.getValue();
}
//计划检测中
List<String> checking = list.stream().filter(x -> x.getCheckState().equals(CheckStateEnum.CHECKED.getValue()) &&
!CheckStateEnum.DOCUMENTED.getValue().equals(x.getCheckState())
).map(PqDevSub::getDevId).distinct().collect(Collectors.toList());
if (checking.size() == notUnchecked.size()) {
return CheckStateEnum.CHECKING.getValue();
}
//检测完成
List<String> checked = list.stream().filter(x -> CheckStateEnum.DOCUMENTED.getValue().equals(x.getCheckState())).map(PqDevSub::getDevId).distinct().collect(Collectors.toList());
if (checked.size() == notUnchecked.size()) {
return CheckStateEnum.CHECKED.getValue();
}
boolean allArchived = list.stream().allMatch(x -> x.getCheckState() != null && x.getCheckState() >= CheckStateEnum.DOCUMENTED.getValue());
return allArchived ? CheckStateEnum.CHECKED.getValue() : CheckStateEnum.CHECKING.getValue();
}
}
return CheckStateEnum.UNCHECKED.getValue();
@@ -547,6 +531,45 @@ public class PqDevServiceImpl extends ServiceImpl<PqDevMapper, PqDev> implements
return preDetections;
}
@Override
public void clearFormalProgressForNewRun(List<String> devIds) {
if (CollUtil.isEmpty(devIds)) {
return;
}
List<PqDevSub> devSubs = pqDevSubService.lambdaQuery()
.in(PqDevSub::getDevId, devIds)
.list();
List<String> resetFormalCheckIds = devSubs.stream()
.filter(dev -> CheckStateEnum.CHECKING.getValue().equals(dev.getCheckState()))
.map(PqDevSub::getDevId)
.collect(Collectors.toList());
if (CollUtil.isNotEmpty(resetFormalCheckIds)) {
pqDevSubService.lambdaUpdate()
.set(PqDevSub::getFormalCheckTime, 0)
.in(PqDevSub::getDevId, resetFormalCheckIds)
.update();
}
pqDevSubService.lambdaUpdate()
.set(PqDevSub::getCheckState, CheckStateEnum.CHECKING.getValue())
.in(PqDevSub::getDevId, devIds)
.update();
}
@Override
public Integer getMinFormalCheckTime(List<String> devIds) {
if (CollUtil.isEmpty(devIds)) {
return 0;
}
return pqDevSubService.lambdaQuery()
.in(PqDevSub::getDevId, devIds)
.list()
.stream()
.map(PqDevSub::getFormalCheckTime)
.filter(Objects::nonNull)
.min(Integer::compareTo)
.orElse(0);
}
@Override
public boolean updateResult(List<String> ids, List<String> adType, String code, String userId, Float temperature, Float humidity, boolean updateCheckNum) {
@@ -590,6 +613,21 @@ public class PqDevServiceImpl extends ServiceImpl<PqDevMapper, PqDev> implements
}
wrapper.set(PqDevSub::getReportState, DevReportStateEnum.NOT_GENERATED.getValue());
}
if (ObjectUtil.isNotNull(FormalTestManager.resumeBaseFormalCheckTime)
&& ObjectUtil.isNotNull(FormalTestManager.resumeFormalStartTime)) {
int elapsedSeconds = (int) java.time.Duration.between(
FormalTestManager.resumeFormalStartTime,
LocalDateTime.now()
).getSeconds();
wrapper.set(PqDevSub::getFormalCheckTime,
FormalTestManager.resumeBaseFormalCheckTime + Math.max(elapsedSeconds, 0));
} else if (updateCheckNum && ObjectUtil.isNotNull(FormalTestManager.checkStartTime)) {
int elapsedSeconds = (int) java.time.Duration.between(
FormalTestManager.checkStartTime,
LocalDateTime.now()
).getSeconds();
wrapper.set(PqDevSub::getFormalCheckTime, Math.max(elapsedSeconds, 0));
}
wrapper.set(PqDevSub::getRecheckNum, i)
.set(PqDevSub::getCheckState, checkState);
pqDevSubService.update(wrapper);
@@ -608,19 +646,14 @@ public class PqDevServiceImpl extends ServiceImpl<PqDevMapper, PqDev> implements
this.baseMapper.updatePlanCheckResult(pqDevVo.getPlanId(), CheckResultEnum.ACCORD.getValue());
}
set = pqDevVOList.stream().map(PqDevVO::getCheckState).collect(Collectors.toSet());
if (set.contains(CheckStateEnum.UNCHECKED.getValue())) {
this.baseMapper.updatePlanTestState(pqDevVo.getPlanId(), CheckStateEnum.CHECKING.getValue());
boolean allUnchecked = pqDevVOList.stream().allMatch(obj -> CheckStateEnum.UNCHECKED.getValue().equals(obj.getCheckState()));
boolean allArchived = pqDevVOList.stream().allMatch(obj -> obj.getCheckState() != null && obj.getCheckState() >= CheckStateEnum.DOCUMENTED.getValue());
if (allUnchecked) {
this.baseMapper.updatePlanTestState(pqDevVo.getPlanId(), CheckStateEnum.UNCHECKED.getValue());
} else if (allArchived) {
this.baseMapper.updatePlanTestState(pqDevVo.getPlanId(), CheckStateEnum.CHECKED.getValue());
} else {
if (checkState.equals(CheckStateEnum.DOCUMENTED.getValue())) {
long count = pqDevVOList.stream().filter(obj -> !CheckStateEnum.DOCUMENTED.getValue().equals(obj.getCheckState())).count();
if (count == 0) {
// 如果非归档状态的设备数量为0则更新计划已完成
this.baseMapper.finishPlan(pqDevVo.getPlanId());
}
} else {
this.baseMapper.updatePlanTestState(pqDevVo.getPlanId(), CheckStateEnum.CHECKING.getValue());
}
this.baseMapper.updatePlanTestState(pqDevVo.getPlanId(), CheckStateEnum.CHECKING.getValue());
}
}
}
@@ -677,7 +710,7 @@ public class PqDevServiceImpl extends ServiceImpl<PqDevMapper, PqDev> implements
List<PqDevVO> pqDevVOList = this.baseMapper.selectByQueryParam(param);
if (CollUtil.isNotEmpty(pqDevVOList)) {
Set<Integer> set = pqDevVOList.stream().filter(obj -> CheckStateEnum.CHECKED.getValue().equals(obj.getCheckState()) || CheckStateEnum.DOCUMENTED.getValue().equals(obj.getCheckState())).map(PqDevVO::getCheckResult).collect(Collectors.toSet());
Set<Integer> set = pqDevVOList.stream().filter(obj -> obj.getCheckState() != null && obj.getCheckState() >= CheckStateEnum.CHECKED.getValue()).map(PqDevVO::getCheckResult).collect(Collectors.toSet());
if (checkState == CheckStateEnum.CHECKED.getValue()) {
set.add(checkResult);
}
@@ -694,20 +727,22 @@ public class PqDevServiceImpl extends ServiceImpl<PqDevMapper, PqDev> implements
}
set = pqDevVOList.stream().map(PqDevVO::getCheckState).collect(Collectors.toSet());
if (set.contains(CheckStateEnum.UNCHECKED.getValue())) {
this.baseMapper.updatePlanTestState(planId, CheckStateEnum.CHECKING.getValue());
} else if (set.contains(CheckStateEnum.CHECKING.getValue())) {
this.baseMapper.updatePlanTestState(planId, CheckStateEnum.CHECKING.getValue());
} else {
boolean allUnchecked = pqDevVOList.stream().allMatch(obj -> CheckStateEnum.UNCHECKED.getValue().equals(obj.getCheckState()));
boolean allArchived = pqDevVOList.stream().allMatch(obj -> obj.getCheckState() != null && obj.getCheckState() >= CheckStateEnum.DOCUMENTED.getValue());
if (allUnchecked) {
this.baseMapper.updatePlanTestState(planId, CheckStateEnum.UNCHECKED.getValue());
} else if (allArchived) {
this.baseMapper.updatePlanTestState(planId, CheckStateEnum.CHECKED.getValue());
} else {
this.baseMapper.updatePlanTestState(planId, CheckStateEnum.CHECKING.getValue());
}
}
}
private void saveCheckHistory(PqDevVO pqDevVo, Integer recheckNum, Integer checkState, String userId) {
if (ObjectUtil.isNull(pqDevVo)
|| (!CheckStateEnum.CHECKED.getValue().equals(checkState) && !CheckStateEnum.DOCUMENTED.getValue().equals(checkState))) {
|| checkState == null
|| checkState < CheckStateEnum.CHECKED.getValue()) {
return;
}
AdPlan plan = adPlanMapper.selectById(pqDevVo.getPlanId());
@@ -723,7 +758,8 @@ public class PqDevServiceImpl extends ServiceImpl<PqDevMapper, PqDev> implements
private void saveCheckHistory(String devId, String userId) {
PqDevVO pqDevVo = this.baseMapper.selectByDevId(devId);
if (ObjectUtil.isNull(pqDevVo)
|| (!CheckStateEnum.CHECKED.getValue().equals(pqDevVo.getCheckState()) && !CheckStateEnum.DOCUMENTED.getValue().equals(pqDevVo.getCheckState()))) {
|| pqDevVo.getCheckState() == null
|| pqDevVo.getCheckState() < CheckStateEnum.CHECKED.getValue()) {
return;
}
AdPlan plan = adPlanMapper.selectById(pqDevVo.getPlanId());

View File

@@ -99,7 +99,7 @@ public class PqMonitorServiceImpl extends ServiceImpl<PqMonitorMapper, PqMonitor
this.baseMapper.updateDeviceReportRState(devId, DevReportStateEnum.NOT_GENERATED.getValue());
}
if (enableCheckMonitorList.size() > checkedMonitorList.size() && checkedMonitorList.size() > 0) {
this.baseMapper.updateDeviceCheckState(devId, CheckStateEnum.CHECKING.getValue());
this.baseMapper.updateDeviceCheckState(devId, CheckStateEnum.UNCHECKED.getValue());
this.baseMapper.updateDeviceReportRState(devId, DevReportStateEnum.NOT_GENERATED.getValue());
}
if (enableCheckMonitorList.size() > 0 && checkedMonitorList.size() == 0) {
@@ -142,13 +142,14 @@ public class PqMonitorServiceImpl extends ServiceImpl<PqMonitorMapper, PqMonitor
List<PqDevSub> devSubList = this.baseMapper.listDevSubByPlanId(plan.getId());
List<PqDevSub> checkedDevSubList = devSubList.stream().filter(pqDevSub -> pqDevSub.getCheckState() == CheckStateEnum.CHECKED.getValue()).collect(Collectors.toList());
List<PqDevSub> checkingDevSubList = devSubList.stream().filter(pqDevSub -> pqDevSub.getCheckState() == CheckStateEnum.CHECKING.getValue()).collect(Collectors.toList());
if (checkedDevSubList.size() == devSubList.size() && devSubList.size() > 0) {
boolean allUnchecked = devSubList.stream().allMatch(pqDevSub -> CheckStateEnum.UNCHECKED.getValue().equals(pqDevSub.getCheckState()));
boolean allArchived = devSubList.stream().allMatch(pqDevSub -> pqDevSub.getCheckState() != null && pqDevSub.getCheckState() >= CheckStateEnum.DOCUMENTED.getValue());
if (allArchived && CollUtil.isNotEmpty(devSubList)) {
this.baseMapper.updatePlanCheckState(plan.getId(), CheckStateEnum.CHECKED.getValue());
} else if (checkedDevSubList.size() > 0 || checkingDevSubList.size() > 0) {
this.baseMapper.updatePlanCheckState(plan.getId(), CheckStateEnum.CHECKING.getValue());
} else {
} else if (allUnchecked) {
this.baseMapper.updatePlanCheckState(plan.getId(), CheckStateEnum.UNCHECKED.getValue());
} else {
this.baseMapper.updatePlanCheckState(plan.getId(), CheckStateEnum.CHECKING.getValue());
}
List<PqDevSub> accordDevSubList = checkedDevSubList.stream().filter(pqDevSub -> pqDevSub.getCheckResult() == CheckResultEnum.ACCORD.getValue()).collect(Collectors.toList());
@@ -372,10 +373,6 @@ public class PqMonitorServiceImpl extends ServiceImpl<PqMonitorMapper, PqMonitor
if (checkedNumList.containsAll(allNumList)) {
return CheckStateEnum.CHECKED.getValue();
} else {
if (checkedNumList.size() > 0) {
return CheckStateEnum.CHECKING.getValue();
}
}
}
return CheckStateEnum.UNCHECKED.getValue();

View File

@@ -36,6 +36,11 @@ public class PlanStatisticsVO {
*/
private Integer uncheckedDeviceCount;
/**
* 检测中设备总数。
*/
private Integer checkingDeviceCount;
/**
* 第一次检测合格的设备数量。
*/

View File

@@ -436,20 +436,14 @@ public class AsyncPlanHandler {
planIds.add(planId);
List<String> devIds = pqDevService.lambdaQuery().in(PqDev::getPlanId, planIds).list().stream().map(PqDev::getId).collect(Collectors.toList());
List<PqDevSub> devSubs = pqDevSubService.lambdaQuery().in(PqDevSub::getDevId, devIds).list();
long checkedCount = devSubs.stream().filter(sub -> sub.getCheckState().equals(CheckStateEnum.CHECKED.getValue())).count();
if (checkedCount > 0) {
plan.setTestState(CheckStateEnum.CHECKING.getValue());
// 都已检测完成
if (checkedCount == devSubs.size()) {
plan.setTestState(CheckStateEnum.CHECKED.getValue());
}
} else {
boolean allUnchecked = devSubs.stream().allMatch(sub -> CheckStateEnum.UNCHECKED.getValue().equals(sub.getCheckState()));
boolean allArchived = devSubs.stream().allMatch(sub -> sub.getCheckState() != null && sub.getCheckState() >= CheckStateEnum.DOCUMENTED.getValue());
if (allUnchecked) {
plan.setTestState(CheckStateEnum.UNCHECKED.getValue());
// 是否有检测中
long checkingCount = devSubs.stream().filter(sub -> sub.getCheckState().equals(CheckStateEnum.CHECKING.getValue())).count();
if (checkingCount > 0) {
plan.setTestState(CheckStateEnum.CHECKING.getValue());
}
} else if (allArchived && !devSubs.isEmpty()) {
plan.setTestState(CheckStateEnum.CHECKED.getValue());
} else {
plan.setTestState(CheckStateEnum.CHECKING.getValue());
}
adPlanService.updateById(plan);
LocalDateTime endTime = LocalDateTime.now();

View File

@@ -216,7 +216,7 @@ public class AdPlanServiceImpl extends ServiceImpl<AdPlanMapper, AdPlan> impleme
}
List<PqDevVO> pqDevVOList = pqDevMapper.selectByQueryParam(queryParam1);
if (CollUtil.isNotEmpty(pqDevVOList)) {
long count = pqDevVOList.stream().filter(pqDev -> CheckStateEnum.CHECKED.getValue().equals(pqDev.getCheckState()) || CheckStateEnum.DOCUMENTED.getValue().equals(pqDev.getCheckState())).count();
long count = pqDevVOList.stream().filter(pqDev -> pqDev.getCheckState() != null && pqDev.getCheckState() >= CheckStateEnum.CHECKED.getValue()).count();
adPlanVO.setProgress((float) count / pqDevVOList.size());
} else {
adPlanVO.setProgress(0.0f);
@@ -405,10 +405,13 @@ public class AdPlanServiceImpl extends ServiceImpl<AdPlanMapper, AdPlan> impleme
PqDevParam.QueryParam queryParam = new PqDevParam.QueryParam();
queryParam.setPlanIdList(Collections.singletonList(plan1.getId()));
List<PqDevVO> pqDevVOS = pqDevService.listByPlanId(queryParam);
long checkedCount = pqDevVOS.stream().filter(pqDevVO -> pqDevVO.getCheckState().equals(CheckStateEnum.CHECKED.getValue())).count();
if (checkedCount == pqDevVOS.size()) {
boolean allUnchecked = pqDevVOS.stream().allMatch(pqDevVO -> CheckStateEnum.UNCHECKED.getValue().equals(pqDevVO.getCheckState()));
boolean allArchived = pqDevVOS.stream().allMatch(pqDevVO -> pqDevVO.getCheckState() != null && pqDevVO.getCheckState() >= CheckStateEnum.DOCUMENTED.getValue());
if (allUnchecked) {
plan1.setTestState(CheckStateEnum.UNCHECKED.getValue());
} else if (allArchived && !pqDevVOS.isEmpty()) {
plan1.setTestState(CheckStateEnum.CHECKED.getValue());
} else if (checkedCount > 0) {
} else {
plan1.setTestState(CheckStateEnum.CHECKING.getValue());
}
}
@@ -832,12 +835,19 @@ public class AdPlanServiceImpl extends ServiceImpl<AdPlanMapper, AdPlan> impleme
List<PqDevVO> checkedDevices = planDevices.stream()
.filter(this::isCheckedDevice)
.collect(Collectors.toList());
int uncheckedDeviceCount = (int) planDevices.stream()
.filter(dev -> Objects.equals(dev.getCheckState(), CheckStateEnum.UNCHECKED.getValue()))
.count();
int checkingDeviceCount = (int) planDevices.stream()
.filter(dev -> Objects.equals(dev.getCheckState(), CheckStateEnum.CHECKING.getValue()))
.count();
PlanStatisticsVO statistics = new PlanStatisticsVO();
statistics.setPlanId(plan.getId());
statistics.setPlanName(plan.getName());
statistics.setManufacturerOptions(buildManufacturerOptions(allPlanDevices, param.getDevType()));
statistics.setDevTypeOptions(buildDevTypeOptions(allPlanDevices, param.getManufacturer()));
statistics.setUncheckedDeviceCount(planDevices.size() - checkedDevices.size());
statistics.setUncheckedDeviceCount(uncheckedDeviceCount);
statistics.setCheckingDeviceCount(checkingDeviceCount);
statistics.setCheckedDeviceCount(checkedDevices.size());
statistics.setTotalCheckCount(checkedDevices.stream().mapToInt(dev -> defaultZero(dev.getRecheckNum())).sum());
@@ -935,9 +945,8 @@ public class AdPlanServiceImpl extends ServiceImpl<AdPlanMapper, AdPlan> impleme
}
private boolean isCheckedDevice(PqDevVO dev) {
return (Objects.equals(dev.getCheckState(), CheckStateEnum.CHECKED.getValue())
|| Objects.equals(dev.getCheckState(), CheckStateEnum.DOCUMENTED.getValue()))
&& !Objects.equals(dev.getCheckResult(), CheckResultEnum.UNCHECKED.getValue());
Integer checkState = dev.getCheckState();
return checkState != null && checkState >= CheckStateEnum.CHECKED.getValue();
}
private List<PlanStatisticsItemVO> buildItemDistributions(AdPlan plan, List<PqDevVO> checkedDevices) {
@@ -1235,26 +1244,22 @@ public class AdPlanServiceImpl extends ServiceImpl<AdPlanMapper, AdPlan> impleme
// 0-解绑、1-绑定
if (param.getBindFlag().equals(1)) {
pqDevService.lambdaUpdate().set(PqDev::getPlanId, plan.getId()).in(PqDev::getId, param.getDevIds()).update();
// 绑定被检设备,若检测计划已检测完成,则修改为检测中
if (plan.getTestState().equals(CheckStateEnum.CHECKED.getValue())) {
plan.setTestState(CheckStateEnum.CHECKING.getValue());
this.updateById(plan);
}
} else {
pqDevService.lambdaUpdate().set(PqDev::getPlanId, plan.getFatherPlanId()).in(PqDev::getId, param.getDevIds()).update();
// 解绑被检设备,若检测计划检测中,且所有设备已检测完成,则修改为检测完成
if (plan.getTestState().equals(CheckStateEnum.CHECKING.getValue())) {
PqDevParam.QueryParam queryParam = new PqDevParam.QueryParam();
queryParam.setPlanIdList(Collections.singletonList(plan.getId()));
List<PqDevVO> pqDevVOS = pqDevService.listByPlanId(queryParam);
long checkedCount = pqDevVOS.stream().filter(pqDevVO -> pqDevVO.getCheckState().equals(CheckStateEnum.CHECKED.getValue())).count();
if (checkedCount == pqDevVOS.size()) {
plan.setTestState(CheckStateEnum.CHECKED.getValue());
this.updateById(plan);
}
}
}
PqDevParam.QueryParam queryParam = new PqDevParam.QueryParam();
queryParam.setPlanIdList(Collections.singletonList(plan.getId()));
List<PqDevVO> pqDevVOS = pqDevService.listByPlanId(queryParam);
boolean allUnchecked = pqDevVOS.stream().allMatch(pqDevVO -> CheckStateEnum.UNCHECKED.getValue().equals(pqDevVO.getCheckState()));
boolean allArchived = pqDevVOS.stream().allMatch(pqDevVO -> pqDevVO.getCheckState() != null && pqDevVO.getCheckState() >= CheckStateEnum.DOCUMENTED.getValue());
if (allUnchecked) {
plan.setTestState(CheckStateEnum.UNCHECKED.getValue());
} else if (allArchived && !pqDevVOS.isEmpty()) {
plan.setTestState(CheckStateEnum.CHECKED.getValue());
} else {
plan.setTestState(CheckStateEnum.CHECKING.getValue());
}
this.updateById(plan);
return true;
}

View File

@@ -4,6 +4,7 @@ import lombok.Getter;
/**
* 电能质量测试大项枚举
*
* @author hongawen
* @version 1.0
* @data 2025/3/27 18:29
@@ -13,22 +14,21 @@ public enum PowerIndexEnum {
UNKNOWN("UNKNOWN", "未知指标"),
FREQ("FREQ", "频率"),
LINE_TITLE("LINE_TITLE", "测量回路"),
FREQ("FREQ", "频率"),
V("V", "电压"),
I("I", "电流"),
P("P", "功率"),
ANGLE("Angle", "基波相位"),
IMBV("IMBV", "负序电压不平衡度"),
IMBA("IMBA", "负序电流不平衡度"),
F("F", "短时电压闪变"),
HP("HP", "谐波有功功率"),
HV("HV", "谐波电压"),
HI("HI", "谐波电流"),
HP("HP", "谐波有功功率"),
HSV("HSV", "间谐波电压"),
HSI("HSI", "间谐波电流"),
VOLTAGE("VOLTAGE", "电压暂降、暂升及短时中断"),
PST("PST", "短时间闪变");
I("I", "电流"),
IMBV("IMBV", "负序电压不平衡度"),
IMBA("IMBA", "负序电流不平衡度"),
F("F", "短时电压闪变"),
P("P", "功率"),
ANGLE("Angle", "基波相位");
private String key;

View File

@@ -2220,7 +2220,7 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
queryParam.setPlanIdList(Arrays.asList(tempPqDevVO.getPlanId()));
List<PqDevVO> pqDevVOList1 = pqDevMapper.selectByQueryParam(queryParam);
long count = pqDevVOList1.stream().filter(obj -> !CheckStateEnum.DOCUMENTED.getValue().equals(obj.getCheckState())).count();
long count = pqDevVOList1.stream().filter(obj -> obj.getCheckState() == null || obj.getCheckState() < CheckStateEnum.DOCUMENTED.getValue()).count();
if (count == 0) {
// 如果非归档状态的设备数量为0则更新计划已完成
pqDevMapper.finishPlan(pqDevVO.getPlanId());

View File

@@ -92,7 +92,6 @@ import com.njcn.gather.system.dictionary.pojo.po.DictData;
import com.njcn.gather.system.dictionary.pojo.po.DictTree;
import com.njcn.gather.system.dictionary.service.IDictDataService;
import com.njcn.gather.system.dictionary.service.IDictTreeService;
import com.njcn.gather.system.pojo.enums.DicDataEnum;
import com.njcn.gather.util.StorageUtil;
import com.njcn.http.util.RestTemplateUtil;
import com.njcn.web.utils.ExcelUtil;
@@ -2204,15 +2203,15 @@ public class ResultServiceImpl implements IResultService {
DictTree dictTree = dictTreeList.get(0);
String unit = StorageUtil.unit(dictTree.getCode());
if (DicDataEnum.HV.getCode().equals(dictTree.getCode()) || DicDataEnum.HI.getCode().equals(dictTree.getCode())) {
if (PowerIndexEnum.HV.getKey().equals(dictTree.getCode()) || PowerIndexEnum.HI.getKey().equals(dictTree.getCode())) {
unit = "%";
if (DicDataEnum.HI.getCode().equals(dictTree.getCode())) {
if (PowerIndexEnum.HI.getKey().equals(dictTree.getCode())) {
unit = "A";
}
}
if (DicDataEnum.HSV.getCode().equals(dictTree.getCode()) || DicDataEnum.HSI.getCode().equals(dictTree.getCode())) {
if (PowerIndexEnum.HSV.getKey().equals(dictTree.getCode()) || PowerIndexEnum.HSI.getKey().equals(dictTree.getCode())) {
unit = "%";
if (DicDataEnum.HSI.getCode().equals(dictTree.getCode())) {
if (PowerIndexEnum.HSI.getKey().equals(dictTree.getCode())) {
unit = "A";
}
}
@@ -3424,10 +3423,10 @@ public class ResultServiceImpl implements IResultService {
if (CollUtil.isNotEmpty(contrastHarmonicResults)) {
ContrastHarmonicResult contrastHarmonicResult = contrastHarmonicResults.get(0);
List<Double> harmonicNum = null;
if (DicDataEnum.HV.getCode().equals(dictTree.getCode()) || DicDataEnum.HI.getCode().equals(dictTree.getCode()) || DicDataEnum.HP.getCode().equals(dictTree.getCode())) {
if (PowerIndexEnum.HV.getKey().equals(dictTree.getCode()) || PowerIndexEnum.HI.getKey().equals(dictTree.getCode()) || PowerIndexEnum.HP.getKey().equals(dictTree.getCode())) {
harmonicNum = Stream.iterate(2.0, n -> n + 1).limit(49).collect(Collectors.toList());
}
if (DicDataEnum.HSV.getCode().equals(dictTree.getCode()) || DicDataEnum.HSI.getCode().equals(dictTree.getCode())) {
if (PowerIndexEnum.HSV.getKey().equals(dictTree.getCode()) || PowerIndexEnum.HSI.getKey().equals(dictTree.getCode())) {
harmonicNum = Stream.iterate(0.5, n -> n + 1).limit(50).collect(Collectors.toList());
}
for (Double n : harmonicNum) {
@@ -3493,7 +3492,7 @@ public class ResultServiceImpl implements IResultService {
ContrastNonHarmonicResult contrastNonHarmonicResultStdDev = stdDevNonHarmonicRawDataList.get(i);
rawDataVO.setTimeStdDev(contrastNonHarmonicResultStdDev.getTimeId().format(dtf));
if (!DicDataEnum.IMBV.getCode().equals(dictTree.getCode()) && !DicDataEnum.IMBA.getCode().equals(dictTree.getCode())) {
if (!PowerIndexEnum.IMBV.getKey().equals(dictTree.getCode()) && !PowerIndexEnum.IMBA.getKey().equals(dictTree.getCode())) {
rawDataVO.setUaDev(getValue(contrastNonHarmonicResultDev.getAValue()));
rawDataVO.setUcDev(getValue(contrastNonHarmonicResultDev.getCValue()));
rawDataVO.setUaStdDev(getValue(contrastNonHarmonicResultStdDev.getAValue()));
@@ -3512,11 +3511,11 @@ public class ResultServiceImpl implements IResultService {
if (CollUtil.isNotEmpty(devHarmonicRawDataList) && CollUtil.isNotEmpty(stdDevHarmonicRawDataList)) {
List<Double> harmonicNum = null;
boolean isHarm = true;
if (DicDataEnum.HV.getCode().equals(dictTree.getCode()) || DicDataEnum.HI.getCode().equals(dictTree.getCode()) || DicDataEnum.HP.getCode().equals(dictTree.getCode())) {
if (PowerIndexEnum.HV.getKey().equals(dictTree.getCode()) || PowerIndexEnum.HI.getKey().equals(dictTree.getCode()) || PowerIndexEnum.HP.getKey().equals(dictTree.getCode())) {
harmonicNum = Stream.iterate(2.0, n -> n + 1).limit(49).collect(Collectors.toList());
isHarm = true;
}
if (DicDataEnum.HSV.getCode().equals(dictTree.getCode()) || DicDataEnum.HSI.getCode().equals(dictTree.getCode())) {
if (PowerIndexEnum.HSV.getKey().equals(dictTree.getCode()) || PowerIndexEnum.HSI.getKey().equals(dictTree.getCode())) {
harmonicNum = Stream.iterate(0.5, n -> n + 1).limit(50).collect(Collectors.toList());
isHarm = false;
}

View File

@@ -17,7 +17,7 @@ import com.njcn.gather.device.pojo.vo.PqDevVO;
import com.njcn.gather.device.service.IPqDevService;
import com.njcn.gather.plan.mapper.AdPlanMapper;
import com.njcn.gather.plan.pojo.po.AdPlan;
import com.njcn.gather.result.pojo.enums.ResultUnitEnum;
import com.njcn.gather.report.pojo.enums.PowerIndexEnum;
import com.njcn.gather.script.mapper.PqScriptCheckDataMapper;
import com.njcn.gather.script.mapper.PqScriptDtlsMapper;
import com.njcn.gather.script.mapper.PqScriptMapper;
@@ -37,12 +37,10 @@ import com.njcn.gather.script.util.ThreePhaseUnbalance;
import com.njcn.gather.source.service.IPqSourceService;
import com.njcn.gather.system.dictionary.pojo.po.DictTree;
import com.njcn.gather.system.dictionary.service.IDictTreeService;
import com.njcn.gather.system.pojo.enums.DicDataEnum;
import com.njcn.gather.type.pojo.po.DevType;
import com.njcn.gather.type.service.IDevTypeService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -69,7 +67,7 @@ public class PqScriptDtlsServiceImpl extends ServiceImpl<PqScriptDtlsMapper, PqS
private final static String INHARM_I = "InHarm_I";
private final static String DIP = "Dip";
private final static String FLICKER = "Flicker";
// @Value("${Dip.fPreTime}")
// @Value("${Dip.fPreTime}")
// private Double fPreTime;
// @Value("${Dip.fRampIn}")
// private Double fRampIn;
@@ -205,7 +203,7 @@ public class PqScriptDtlsServiceImpl extends ServiceImpl<PqScriptDtlsMapper, PqS
checkDataParam.setScriptId(freqDtls.getScriptId());
checkDataParam.setIndex(freqDtls.getScriptIndex());
checkDataParam.setIsValueTypeName(true);
if (DicDataEnum.F.getCode().equals(issue.getType()) || DicDataEnum.VOLTAGE.getCode().equals(issue.getType())) {
if (PowerIndexEnum.F.getKey().equals(issue.getType()) || PowerIndexEnum.VOLTAGE.getKey().equals(issue.getType())) {
checkDataParam.setDataType("avg");
issue.setDataType("avg");
} else {
@@ -247,7 +245,7 @@ public class PqScriptDtlsServiceImpl extends ServiceImpl<PqScriptDtlsMapper, PqS
issueAdd(curList, dtlsIList, HARM_I, INHARM_I, freqDtls.getValue(), "I", channelListDTOS, checkDataParam, devFly, isValueType);
issue.setChannelList(channelListDTOS);
if (ResultUnitEnum.P.getCode().equals(issue.getType()) || ResultUnitEnum.ANGLE.getCode().equals(issue.getType())) {
if (PowerIndexEnum.P.getKey().equals(issue.getType()) || PowerIndexEnum.ANGLE.getKey().equals(issue.getType())) {
issue.setOtherType(issue.getType());
} else {
issue.setOtherType(null);

View File

@@ -74,4 +74,10 @@ public interface SimAndDigHarmonicService extends IService<SimAndDigHarmonicResu
* @return
*/
List<SimAndDigHarmonicResult> listAllRawData(String scriptId, String code, String devId);
Map<String, Integer> maxSortByDevIds(String code, String scriptId, List<String> devIds);
List<SimAndDigHarmonicResult> listByDevIdsAndSorts(String code, String scriptId, List<String> devIds, List<Integer> sorts);
Map<String, List<Integer>> resultFlagsByDevIdsAndSorts(String code, String scriptId, List<String> devIds, List<Integer> sorts);
}

View File

@@ -79,4 +79,10 @@ public interface SimAndDigNonHarmonicService extends IService<SimAndDigNonHarmon
* @return
*/
List<SimAndDigNonHarmonicResult> listAllSimAndDigRawData(String scriptId, String code, String devId);
Map<String, Integer> maxSortByDevIds(String code, String scriptId, List<String> devIds);
List<SimAndDigNonHarmonicResult> listByDevIdsAndSorts(String code, String scriptId, List<String> devIds, List<Integer> sorts);
Map<String, List<Integer>> resultFlagsByDevIdsAndSorts(String code, String scriptId, List<String> devIds, List<Integer> sorts);
}

View File

@@ -276,4 +276,96 @@ public class SimAndDigHarmonicServiceImpl extends ServiceImpl<SimAndDigHarmonicM
DynamicTableNameHandler.remove();
return results;
}
@Override
public Map<String, Integer> maxSortByDevIds(String code, String scriptId, List<String> devIds) {
Map<String, Integer> result = new HashMap<>();
if (CollUtil.isEmpty(devIds)) {
return result;
}
DynamicTableNameHandler.setTableName("ad_harmonic_result_" + code);
try {
LambdaQueryWrapper<SimAndDigHarmonicResult> wrapper = new LambdaQueryWrapper<>();
wrapper.select(SimAndDigHarmonicResult::getDevMonitorId, SimAndDigHarmonicResult::getSort)
.eq(SimAndDigHarmonicResult::getScriptId, scriptId)
.and(w -> {
for (String devId : devIds) {
w.or().likeRight(SimAndDigHarmonicResult::getDevMonitorId, devId + "_");
}
});
this.list(wrapper).forEach(row -> {
String devId = row.getDevMonitorId().split("_")[0];
result.merge(devId, row.getSort(), Math::max);
});
return result;
} finally {
DynamicTableNameHandler.remove();
}
}
@Override
public List<SimAndDigHarmonicResult> listByDevIdsAndSorts(String code, String scriptId, List<String> devIds, List<Integer> sorts) {
if (CollUtil.isEmpty(devIds) || CollUtil.isEmpty(sorts)) {
return Collections.emptyList();
}
DynamicTableNameHandler.setTableName("ad_harmonic_result_" + code);
try {
LambdaQueryWrapper<SimAndDigHarmonicResult> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(SimAndDigHarmonicResult::getScriptId, scriptId)
.in(SimAndDigHarmonicResult::getSort, sorts)
.and(w -> {
for (String devId : devIds) {
w.or().likeRight(SimAndDigHarmonicResult::getDevMonitorId, devId + "_");
}
});
return this.list(wrapper);
} finally {
DynamicTableNameHandler.remove();
}
}
@Override
public Map<String, List<Integer>> resultFlagsByDevIdsAndSorts(String code, String scriptId, List<String> devIds, List<Integer> sorts) {
Map<String, List<Integer>> result = new HashMap<>();
if (CollUtil.isEmpty(devIds) || StrUtil.isBlank(code)) {
return result;
}
if (sorts != null && CollUtil.isEmpty(sorts)) {
return result;
}
DynamicTableNameHandler.setTableName("ad_harmonic_result_" + code);
try {
LambdaQueryWrapper<SimAndDigHarmonicResult> wrapper = new LambdaQueryWrapper<>();
wrapper.select(SimAndDigHarmonicResult::getDevMonitorId,
SimAndDigHarmonicResult::getResultFlag)
.eq(StrUtil.isNotBlank(scriptId), SimAndDigHarmonicResult::getScriptId, scriptId)
.in(CollUtil.isNotEmpty(sorts), SimAndDigHarmonicResult::getSort, sorts)
.and(w -> {
for (String devId : devIds) {
w.or().likeRight(SimAndDigHarmonicResult::getDevMonitorId, devId + "_");
}
});
this.list(wrapper).forEach(row -> {
String devId = resolveDevId(row.getDevMonitorId(), devIds);
if (StrUtil.isNotBlank(devId) && row.getResultFlag() != null) {
result.computeIfAbsent(devId, key -> new ArrayList<>()).add(row.getResultFlag());
}
});
return result;
} finally {
DynamicTableNameHandler.remove();
}
}
private String resolveDevId(String devMonitorId, List<String> devIds) {
if (StrUtil.isBlank(devMonitorId)) {
return null;
}
for (String devId : devIds) {
if (StrUtil.isNotBlank(devId) && devMonitorId.startsWith(devId + "_")) {
return devId;
}
}
return null;
}
}

View File

@@ -7,6 +7,7 @@ import cn.hutool.core.date.DatePattern;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.njcn.db.mybatisplus.handler.DynamicTableNameHandler;
@@ -211,5 +212,96 @@ public class SimAndDigNonHarmonicServiceImpl extends ServiceImpl<SimAndDigNonHar
return results;
}
@Override
public Map<String, Integer> maxSortByDevIds(String code, String scriptId, List<String> devIds) {
Map<String, Integer> result = new HashMap<>();
if (CollUtil.isEmpty(devIds)) {
return result;
}
DynamicTableNameHandler.setTableName("ad_non_harmonic_result_" + code);
try {
LambdaQueryWrapper<SimAndDigNonHarmonicResult> wrapper = new LambdaQueryWrapper<>();
wrapper.select(SimAndDigNonHarmonicResult::getDevMonitorId, SimAndDigNonHarmonicResult::getSort)
.eq(SimAndDigNonHarmonicResult::getScriptId, scriptId)
.and(w -> {
for (String devId : devIds) {
w.or().likeRight(SimAndDigNonHarmonicResult::getDevMonitorId, devId + "_");
}
});
this.list(wrapper).forEach(row -> {
String devId = row.getDevMonitorId().split("_")[0];
result.merge(devId, row.getSort(), Math::max);
});
return result;
} finally {
DynamicTableNameHandler.remove();
}
}
@Override
public List<SimAndDigNonHarmonicResult> listByDevIdsAndSorts(String code, String scriptId, List<String> devIds, List<Integer> sorts) {
if (CollUtil.isEmpty(devIds) || CollUtil.isEmpty(sorts)) {
return Collections.emptyList();
}
DynamicTableNameHandler.setTableName("ad_non_harmonic_result_" + code);
try {
LambdaQueryWrapper<SimAndDigNonHarmonicResult> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(SimAndDigNonHarmonicResult::getScriptId, scriptId)
.in(SimAndDigNonHarmonicResult::getSort, sorts)
.and(w -> {
for (String devId : devIds) {
w.or().likeRight(SimAndDigNonHarmonicResult::getDevMonitorId, devId + "_");
}
});
return this.list(wrapper);
} finally {
DynamicTableNameHandler.remove();
}
}
@Override
public Map<String, List<Integer>> resultFlagsByDevIdsAndSorts(String code, String scriptId, List<String> devIds, List<Integer> sorts) {
Map<String, List<Integer>> result = new HashMap<>();
if (CollUtil.isEmpty(devIds) || StrUtil.isBlank(code)) {
return result;
}
if (sorts != null && CollUtil.isEmpty(sorts)) {
return result;
}
DynamicTableNameHandler.setTableName("ad_non_harmonic_result_" + code);
try {
LambdaQueryWrapper<SimAndDigNonHarmonicResult> wrapper = new LambdaQueryWrapper<>();
wrapper.select(SimAndDigNonHarmonicResult::getDevMonitorId,
SimAndDigNonHarmonicResult::getResultFlag)
.eq(StrUtil.isNotBlank(scriptId), SimAndDigNonHarmonicResult::getScriptId, scriptId)
.in(CollUtil.isNotEmpty(sorts), SimAndDigNonHarmonicResult::getSort, sorts)
.and(w -> {
for (String devId : devIds) {
w.or().likeRight(SimAndDigNonHarmonicResult::getDevMonitorId, devId + "_");
}
});
this.list(wrapper).forEach(row -> {
String devId = resolveDevId(row.getDevMonitorId(), devIds);
if (StrUtil.isNotBlank(devId) && row.getResultFlag() != null) {
result.computeIfAbsent(devId, key -> new ArrayList<>()).add(row.getResultFlag());
}
});
return result;
} finally {
DynamicTableNameHandler.remove();
}
}
private String resolveDevId(String devMonitorId, List<String> devIds) {
if (StrUtil.isBlank(devMonitorId)) {
return null;
}
for (String devId : devIds) {
if (StrUtil.isNotBlank(devId) && devMonitorId.startsWith(devId + "_")) {
return devId;
}
}
return null;
}
}

View File

@@ -1,58 +0,0 @@
package com.njcn.gather.system.pojo.enums;
import lombok.Getter;
/**
* @author cdf
* @version 1.0.0
*/
@Getter
public enum DicDataEnum {
FREQ("FREQ","频率"),
V("V","电压"),
I("I","电流"),
IMBV("IMBV","三相电压不平衡度"),
IMBA("IMBA","三相电流不平衡度"),
HV("HV","谐波电压"),
HI("HI","谐波电流"),
HP("HP","谐波有功功率"),
HSV("HSV","间谐波电压"),
HSI("HSI","间谐波电流"),
VOLTAGE("VOLTAGE","暂态"),
F("F","闪变"),
P("P","功率")
;
private final String code;
private final String message;
DicDataEnum(String code, String message) {
this.code = code;
this.message = message;
}
public static DicDataEnum getEnumByCode(String code) {
for (DicDataEnum e : DicDataEnum.values()) {
if (e.getCode().equals(code)) {
return e;
}
}
return null;
}
public static String getMessageByCode(String code) {
DicDataEnum e = getEnumByCode(code);
if (e!= null) {
return e.getMessage();
}
return "";
}
}