Compare commits
13 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0cd8e454fc | ||
|
|
95005d2462 | ||
|
|
16ace94f8d | ||
|
|
ca9885c5dc | ||
|
|
78b52fa336 | ||
|
|
da08271f76 | ||
|
|
75bc44172b | ||
|
|
95544f1dc6 | ||
| 7a8071c9d7 | |||
| 75b19eb6ab | |||
|
|
efb379d6a4 | ||
|
|
cf2dcf8ff4 | ||
|
|
4d52e9c820 |
@@ -12,9 +12,11 @@ import com.njcn.gather.detection.lock.DetectionLockManager;
|
|||||||
import com.njcn.gather.detection.lock.DetectionLockManager.AcquireResult;
|
import com.njcn.gather.detection.lock.DetectionLockManager.AcquireResult;
|
||||||
import com.njcn.gather.detection.pojo.enums.DetectionResponseEnum;
|
import com.njcn.gather.detection.pojo.enums.DetectionResponseEnum;
|
||||||
import com.njcn.gather.detection.pojo.param.ContrastDetectionParam;
|
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.PreDetectionParam;
|
||||||
import com.njcn.gather.detection.pojo.param.SimulateDetectionParam;
|
import com.njcn.gather.detection.pojo.param.SimulateDetectionParam;
|
||||||
import com.njcn.gather.detection.pojo.vo.DetectionLockHolderVO;
|
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.service.PreDetectionService;
|
||||||
import com.njcn.gather.detection.util.socket.FormalTestManager;
|
import com.njcn.gather.detection.util.socket.FormalTestManager;
|
||||||
import com.njcn.gather.user.user.pojo.po.SysUser;
|
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);
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 开始比对检测(包括预检测、正式检测)通用入口
|
* 开始比对检测(包括预检测、正式检测)通用入口
|
||||||
|
|||||||
@@ -41,6 +41,7 @@ import com.njcn.gather.monitor.service.IPqMonitorService;
|
|||||||
import com.njcn.gather.plan.pojo.enums.DataSourceEnum;
|
import com.njcn.gather.plan.pojo.enums.DataSourceEnum;
|
||||||
import com.njcn.gather.plan.service.IAdPlanService;
|
import com.njcn.gather.plan.service.IAdPlanService;
|
||||||
import com.njcn.gather.plan.service.IAdPlanTestConfigService;
|
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.ContrastHarmonicResult;
|
||||||
import com.njcn.gather.storage.pojo.po.ContrastNonHarmonicResult;
|
import com.njcn.gather.storage.pojo.po.ContrastNonHarmonicResult;
|
||||||
import com.njcn.gather.storage.service.DetectionDataDealService;
|
import com.njcn.gather.storage.service.DetectionDataDealService;
|
||||||
@@ -132,17 +133,17 @@ public class SocketContrastResponseService {
|
|||||||
private final PathConfig pathConfig;
|
private final PathConfig pathConfig;
|
||||||
|
|
||||||
public static final Map<String, List<String>> testItemCodeMap = new HashMap() {{
|
public static final Map<String, List<String>> testItemCodeMap = new HashMap() {{
|
||||||
put("FREQ", Arrays.asList(DetectionCodeEnum.FREQ.getCode()));
|
put(PowerIndexEnum.FREQ.getKey(), Arrays.asList(DetectionCodeEnum.FREQ.getCode()));
|
||||||
put("V", Arrays.asList(DetectionCodeEnum.VRMS.getCode(), DetectionCodeEnum.PVRMS.getCode()));
|
put(PowerIndexEnum.V.getKey(), Arrays.asList(DetectionCodeEnum.VRMS.getCode(), DetectionCodeEnum.PVRMS.getCode()));
|
||||||
put("HV", Arrays.asList(DetectionCodeEnum.V2_50.getCode(), DetectionCodeEnum.PV2_50.getCode()));
|
put(PowerIndexEnum.HV.getKey(), Arrays.asList(DetectionCodeEnum.V2_50.getCode(), DetectionCodeEnum.PV2_50.getCode()));
|
||||||
put("HI", Arrays.asList(DetectionCodeEnum.I2_50.getCode()));
|
put(PowerIndexEnum.HI.getKey(), Arrays.asList(DetectionCodeEnum.I2_50.getCode()));
|
||||||
put("HP", Arrays.asList(DetectionCodeEnum.P2_50.getCode()));
|
put(PowerIndexEnum.HP.getKey(), Arrays.asList(DetectionCodeEnum.P2_50.getCode()));
|
||||||
put("HSV", Arrays.asList(DetectionCodeEnum.SV_1_49.getCode(), DetectionCodeEnum.PSV_1_49.getCode()));
|
put(PowerIndexEnum.HSV.getKey(), Arrays.asList(DetectionCodeEnum.SV_1_49.getCode(), DetectionCodeEnum.PSV_1_49.getCode()));
|
||||||
put("HSI", Arrays.asList(DetectionCodeEnum.SI_1_49.getCode()));
|
put(PowerIndexEnum.HSI.getKey(), Arrays.asList(DetectionCodeEnum.SI_1_49.getCode()));
|
||||||
put("I", Arrays.asList(DetectionCodeEnum.IRMS.getCode()));
|
put(PowerIndexEnum.I.getKey(), Arrays.asList(DetectionCodeEnum.IRMS.getCode()));
|
||||||
put("IMBV", Arrays.asList(DetectionCodeEnum.V_UNBAN.getCode()));
|
put(PowerIndexEnum.IMBV.getKey(), Arrays.asList(DetectionCodeEnum.V_UNBAN.getCode()));
|
||||||
put("IMBA", Arrays.asList(DetectionCodeEnum.I_UNBAN.getCode()));
|
put(PowerIndexEnum.IMBA.getKey(), Arrays.asList(DetectionCodeEnum.I_UNBAN.getCode()));
|
||||||
put("F", Arrays.asList(DetectionCodeEnum.PST.getCode()));
|
put(PowerIndexEnum.F.getKey(), Arrays.asList(DetectionCodeEnum.PST.getCode()));
|
||||||
}};
|
}};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -307,7 +308,7 @@ public class SocketContrastResponseService {
|
|||||||
FormalTestManager.numMap.clear();
|
FormalTestManager.numMap.clear();
|
||||||
FormalTestManager.numMap.putAll(numMap);
|
FormalTestManager.numMap.putAll(numMap);
|
||||||
SysTestConfig oneConfig = sysTestConfigService.getOneConfig();
|
SysTestConfig oneConfig = sysTestConfigService.getOneConfig();
|
||||||
if (param.getTestItemList().get(2)) {
|
if (param.isFormalTestSelected()) {
|
||||||
numMap.forEach((devMonitorId, num) -> {
|
numMap.forEach((devMonitorId, num) -> {
|
||||||
if (oneConfig.getMaxTime() < num) {
|
if (oneConfig.getMaxTime() < num) {
|
||||||
throw new BusinessException(DetectionResponseEnum.EXCEED_MAX_TIME);
|
throw new BusinessException(DetectionResponseEnum.EXCEED_MAX_TIME);
|
||||||
@@ -1154,7 +1155,7 @@ public class SocketContrastResponseService {
|
|||||||
|
|
||||||
private void sendFormalTest(String s, PreDetectionParam param, SourceOperateCodeEnum requestOperateCode, SourceOperateCodeEnum quitOperateCode) {
|
private void sendFormalTest(String s, PreDetectionParam param, SourceOperateCodeEnum requestOperateCode, SourceOperateCodeEnum quitOperateCode) {
|
||||||
// 后续做正式检测
|
// 后续做正式检测
|
||||||
if (param.getTestItemList().get(2)) {
|
if (param.isFormalTestSelected()) {
|
||||||
System.out.println("开始正式检测!");
|
System.out.println("开始正式检测!");
|
||||||
if (ObjectUtil.isNotNull(FormalTestManager.nonWaveDataSourceEnum)) {
|
if (ObjectUtil.isNotNull(FormalTestManager.nonWaveDataSourceEnum)) {
|
||||||
SocketMsg<String> socketMsg = new SocketMsg<>();
|
SocketMsg<String> socketMsg = new SocketMsg<>();
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ import com.njcn.gather.device.service.IPqDevService;
|
|||||||
import com.njcn.gather.device.service.IPqDevSubService;
|
import com.njcn.gather.device.service.IPqDevSubService;
|
||||||
import com.njcn.gather.plan.pojo.po.AdPlan;
|
import com.njcn.gather.plan.pojo.po.AdPlan;
|
||||||
import com.njcn.gather.plan.service.IAdPlanService;
|
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.result.service.IResultService;
|
||||||
import com.njcn.gather.script.pojo.param.PqScriptCheckDataParam;
|
import com.njcn.gather.script.pojo.param.PqScriptCheckDataParam;
|
||||||
import com.njcn.gather.script.pojo.param.PqScriptIssueParam;
|
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.enums.DictDataEnum;
|
||||||
import com.njcn.gather.system.dictionary.pojo.po.DictData;
|
import com.njcn.gather.system.dictionary.pojo.po.DictData;
|
||||||
import com.njcn.gather.system.dictionary.service.IDictDataService;
|
import com.njcn.gather.system.dictionary.service.IDictDataService;
|
||||||
import com.njcn.gather.system.pojo.enums.DicDataEnum;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
@@ -69,7 +68,7 @@ public class SocketDevResponseService {
|
|||||||
|
|
||||||
private List<String> icdTypeList;
|
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 IPqDevService iPqDevService;
|
||||||
private final IPqDevSubService iPqDevSubService;
|
private final IPqDevSubService iPqDevSubService;
|
||||||
@@ -398,72 +397,8 @@ public class SocketDevResponseService {
|
|||||||
sendWebSocket(param.getUserPageId(), SourceOperateCodeEnum.Coefficient_Check.getValue(), SourceOperateCodeEnum.small_comp_end.getValue(), XiNumberManager.devParameterList.get(1));
|
sendWebSocket(param.getUserPageId(), SourceOperateCodeEnum.Coefficient_Check.getValue(), SourceOperateCodeEnum.small_comp_end.getValue(), XiNumberManager.devParameterList.get(1));
|
||||||
System.out.println("-------------------------已经全部结束----------------------");
|
System.out.println("-------------------------已经全部结束----------------------");
|
||||||
|
|
||||||
if (param.getTestItemList().get(2)) {
|
if (param.isFormalTestSelected()) {
|
||||||
//如果后续做正式检测
|
startFormalScripts(param, null, param.isResumeFormal());
|
||||||
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为大项code,value为小项个数
|
|
||||||
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));
|
|
||||||
} else {
|
} else {
|
||||||
//后续什么都不做
|
//后续什么都不做
|
||||||
CnSocketUtil.quitSend(param);
|
CnSocketUtil.quitSend(param);
|
||||||
@@ -615,7 +550,7 @@ public class SocketDevResponseService {
|
|||||||
private BigDecimal rangeNum(double num1, double num2, String type) {
|
private BigDecimal rangeNum(double num1, double num2, String type) {
|
||||||
double diff = Math.abs(num1 - num2);
|
double diff = Math.abs(num1 - num2);
|
||||||
double larger = Math.max(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);
|
return BigDecimal.valueOf(num1 - num2).setScale(4, RoundingMode.HALF_UP);
|
||||||
} else {
|
} else {
|
||||||
return BigDecimal.valueOf(diff / larger).multiply(BigDecimal.valueOf(100)).setScale(4, RoundingMode.HALF_UP);
|
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.setBIeXi(isWithinTenPercent(optionalIB, devParameter.getDevCurr(), iLimit) ? "合格" : "不合格");
|
||||||
coefficientVO.setCIeXi(isWithinTenPercent(optionalIC, devParameter.getDevCurr(), iLimit) ? "合格" : "不合格");
|
coefficientVO.setCIeXi(isWithinTenPercent(optionalIC, devParameter.getDevCurr(), iLimit) ? "合格" : "不合格");
|
||||||
|
|
||||||
coefficientVO.setAV(rangeNum(optionalA, devParameter.getDevVolt(), DicDataEnum.V.getCode()).toString());
|
coefficientVO.setAV(rangeNum(optionalA, devParameter.getDevVolt(), PowerIndexEnum.V.getKey()).toString());
|
||||||
coefficientVO.setBV(rangeNum(optionalB, devParameter.getDevVolt(), DicDataEnum.V.getCode()).toString());
|
coefficientVO.setBV(rangeNum(optionalB, devParameter.getDevVolt(), PowerIndexEnum.V.getKey()).toString());
|
||||||
coefficientVO.setCV(rangeNum(optionalC, devParameter.getDevVolt(), DicDataEnum.V.getCode()).toString());
|
coefficientVO.setCV(rangeNum(optionalC, devParameter.getDevVolt(), PowerIndexEnum.V.getKey()).toString());
|
||||||
coefficientVO.setAI(rangeNum(optionalIA, devParameter.getDevCurr(), DicDataEnum.I.getCode()).toString());
|
coefficientVO.setAI(rangeNum(optionalIA, devParameter.getDevCurr(), PowerIndexEnum.I.getKey()).toString());
|
||||||
coefficientVO.setBI(rangeNum(optionalIB, devParameter.getDevCurr(), DicDataEnum.I.getCode()).toString());
|
coefficientVO.setBI(rangeNum(optionalIB, devParameter.getDevCurr(), PowerIndexEnum.I.getKey()).toString());
|
||||||
coefficientVO.setCI(rangeNum(optionalIC, devParameter.getDevCurr(), DicDataEnum.I.getCode()).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())) {
|
if ("不合格".equals(coefficientVO.getAVuXi()) || "不合格".equals(coefficientVO.getBVuXi()) || "不合格".equals(coefficientVO.getCVuXi()) || "不合格".equals(coefficientVO.getAIeXi()) || "不合格".equals(coefficientVO.getBIeXi()) || "不合格".equals(coefficientVO.getCIeXi())) {
|
||||||
coefficientVO.setResultFlag(0);
|
coefficientVO.setResultFlag(0);
|
||||||
@@ -912,68 +847,70 @@ public class SocketDevResponseService {
|
|||||||
socketMsg.setOperateCode(SourceOperateCodeEnum.OPER_GATHER.getValue());
|
socketMsg.setOperateCode(SourceOperateCodeEnum.OPER_GATHER.getValue());
|
||||||
List<SourceIssue> sourceIssues;
|
List<SourceIssue> sourceIssues;
|
||||||
// 做预检测、后续做系数校准
|
// 做预检测、后续做系数校准
|
||||||
if (param.getTestItemList().get(0) || param.getTestItemList().get(1)) {
|
// if (param.isPreTestSelected() || param.isCoefficientSelected() || param.isFormalTestSelected()) {
|
||||||
issueParam.setIsPhaseSequence(CommonEnum.PHASE_TEST.getValue());
|
issueParam.setIsPhaseSequence(CommonEnum.PHASE_TEST.getValue());
|
||||||
sourceIssues = pqScriptDtlsService.listSourceIssue(issueParam);
|
sourceIssues = pqScriptDtlsService.listSourceIssue(issueParam);
|
||||||
socketMsg.setRequestId(SourceOperateCodeEnum.YJC_XUJY.getValue());
|
socketMsg.setRequestId(SourceOperateCodeEnum.YJC_XUJY.getValue());
|
||||||
socketMsg.setData(JSON.toJSONString(sourceIssues.get(0)));
|
socketMsg.setData(JSON.toJSONString(sourceIssues.get(0)));
|
||||||
SocketManager.sendMsg(param.getUserPageId() + CnSocketUtil.SOURCE_TAG, JSON.toJSONString(socketMsg));
|
SocketManager.sendMsg(param.getUserPageId() + CnSocketUtil.SOURCE_TAG, JSON.toJSONString(socketMsg));
|
||||||
} else if (param.getTestItemList().get(2)) {
|
// }
|
||||||
// 后续做正式检测
|
// else if (param.isFormalTestSelected()) {
|
||||||
if (param.getReCheckType().equals(SourceOperateCodeEnum.RE_ERROR_TEST.getValue())) {
|
// // 后续做正式检测
|
||||||
//不合格项复检
|
// if (param.getReCheckType().equals(SourceOperateCodeEnum.RE_ERROR_TEST.getValue())) {
|
||||||
Set<Integer> indexes = new HashSet<>();
|
// //不合格项复检
|
||||||
StorageParam storageParam = new StorageParam();
|
// Set<Integer> indexes = new HashSet<>();
|
||||||
storageParam.setCode(param.getCode());
|
// StorageParam storageParam = new StorageParam();
|
||||||
storageParam.setScriptId(param.getScriptId());
|
// storageParam.setCode(param.getCode());
|
||||||
param.getDevIds().forEach(devId -> {
|
// storageParam.setScriptId(param.getScriptId());
|
||||||
storageParam.setDevId(devId);
|
// param.getDevIds().forEach(devId -> {
|
||||||
indexes.addAll(adHarmonicService.getIndex(storageParam));
|
// storageParam.setDevId(devId);
|
||||||
});
|
// indexes.addAll(adHarmonicService.getIndex(storageParam));
|
||||||
issueParam.setIndexList(indexes.stream().collect(Collectors.toList()));
|
// });
|
||||||
issueParam.setIsPhaseSequence(SourceOperateCodeEnum.RE_ERROR_TEST.getValue());
|
// issueParam.setIndexList(indexes.stream().collect(Collectors.toList()));
|
||||||
} else {
|
// issueParam.setIsPhaseSequence(SourceOperateCodeEnum.RE_ERROR_TEST.getValue());
|
||||||
issueParam.setIsPhaseSequence(CommonEnum.FORMAL_TEST.getValue());
|
// } else {
|
||||||
}
|
// issueParam.setIsPhaseSequence(CommonEnum.FORMAL_TEST.getValue());
|
||||||
//正式检测
|
// }
|
||||||
sourceIssues = pqScriptDtlsService.listSourceIssue(issueParam);
|
// //正式检测
|
||||||
sourceIssues = sourceIssues.stream().sorted(Comparator.comparing(SourceIssue::getIndex)).collect(Collectors.toList());
|
// sourceIssues = pqScriptDtlsService.listSourceIssue(issueParam);
|
||||||
// 使用 LinkedHashMap 保持分组顺序
|
// sourceIssues = sourceIssues.stream().sorted(Comparator.comparing(SourceIssue::getIndex)).collect(Collectors.toList());
|
||||||
Map<String, List<SourceIssue>> groupedIssues = sourceIssues.stream()
|
// // 使用 LinkedHashMap 保持分组顺序
|
||||||
.collect(Collectors.groupingBy(
|
// Map<String, List<SourceIssue>> groupedIssues = sourceIssues.stream()
|
||||||
SourceIssue::getType,
|
// .collect(Collectors.groupingBy(
|
||||||
LinkedHashMap::new,
|
// SourceIssue::getType,
|
||||||
Collectors.toList()
|
// LinkedHashMap::new,
|
||||||
));
|
// Collectors.toList()
|
||||||
|
// ));
|
||||||
// 将分组后的元素合并成一个新的集合,保持原有顺序
|
//
|
||||||
sourceIssues = groupedIssues.values().stream()
|
// // 将分组后的元素合并成一个新的集合,保持原有顺序
|
||||||
.flatMap(List::stream)
|
// sourceIssues = groupedIssues.values().stream()
|
||||||
.collect(Collectors.toList());
|
// .flatMap(List::stream)
|
||||||
// 存放所有检测小项
|
// .collect(Collectors.toList());
|
||||||
SocketManager.addSourceList(sourceIssues);
|
// // 存放所有检测小项
|
||||||
// 按照大项分组。key为大项code,value为小项个数
|
// SocketManager.addSourceList(sourceIssues);
|
||||||
Map<String, Long> sourceIssueMap = sourceIssues.stream().collect(Collectors.groupingBy(SourceIssue::getType, Collectors.counting()));
|
// // 按照大项分组。key为大项code,value为小项个数
|
||||||
SocketManager.initMap(sourceIssueMap);
|
// 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();
|
// WebSocketVO<Object> webSocketVO = new WebSocketVO<>();
|
||||||
if (ResultUnitEnum.P.getCode().equals(type)) {
|
// String type = sourceIssues.get(0).getType();
|
||||||
sourceIssues.get(0).setType(ResultUnitEnum.V_ABSOLUTELY.getCode());
|
// if (StrUtil.isNotBlank(sourceIssues.get(0).getOtherType())) {
|
||||||
webSocketVO.setRequestId(ResultUnitEnum.P.getCode() + CnSocketUtil.START_TAG);
|
// sourceIssues.get(0).setType(PowerIndexEnum.V.getKey());
|
||||||
} else {
|
// webSocketVO.setRequestId(sourceIssues.get(0).getOtherType() + CnSocketUtil.START_TAG);
|
||||||
webSocketVO.setRequestId(sourceIssues.get(0).getType() + CnSocketUtil.START_TAG);
|
// type = sourceIssues.get(0).getOtherType();
|
||||||
}
|
// } else {
|
||||||
FormalTestManager.currentIssue = sourceIssues.get(0);
|
// 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);
|
// FormalTestManager.currentIssue = sourceIssues.get(0);
|
||||||
socketMsg.setOperateCode(SourceOperateCodeEnum.OPER_GATHER.getValue());
|
// socketMsg.setData(JSON.toJSONString(sourceIssues.get(0)));
|
||||||
SocketManager.sendMsg(param.getUserPageId() + CnSocketUtil.SOURCE_TAG, JSON.toJSONString(socketMsg));
|
// socketMsg.setRequestId(SourceOperateCodeEnum.FORMAL_REAL.getValue() + CnSocketUtil.STEP_TAG + type);
|
||||||
|
// socketMsg.setOperateCode(SourceOperateCodeEnum.OPER_GATHER.getValue());
|
||||||
webSocketVO.setDesc(null);
|
// SocketManager.sendMsg(param.getUserPageId() + CnSocketUtil.SOURCE_TAG, JSON.toJSONString(socketMsg));
|
||||||
WebServiceManager.sendMsg(param.getUserPageId(), JSON.toJSONString(webSocketVO));
|
//
|
||||||
}
|
// webSocketVO.setDesc(null);
|
||||||
|
// WebServiceManager.sendMsg(param.getUserPageId(), JSON.toJSONString(webSocketVO));
|
||||||
|
// }
|
||||||
} else {
|
} else {
|
||||||
// 发送下一个脚本与icd校验
|
// 发送下一个脚本与icd校验
|
||||||
String icdType = icdTypeList.stream().filter(it -> !icdCheckDataMap.containsKey(it)).findFirst().orElse(null);
|
String icdType = icdTypeList.stream().filter(it -> !icdCheckDataMap.containsKey(it)).findFirst().orElse(null);
|
||||||
@@ -1146,7 +1083,7 @@ public class SocketDevResponseService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 后续做系数校准
|
// 后续做系数校准
|
||||||
if (param.getTestItemList().get(1)) {
|
if (param.isCoefficientSelected()) {
|
||||||
WebSocketVO<Object> webSocketVO = new WebSocketVO<>();
|
WebSocketVO<Object> webSocketVO = new WebSocketVO<>();
|
||||||
webSocketVO.setRequestId(SourceOperateCodeEnum.Coefficient_Check.getValue());
|
webSocketVO.setRequestId(SourceOperateCodeEnum.Coefficient_Check.getValue());
|
||||||
webSocketVO.setOperateCode(SourceOperateCodeEnum.big_start.getValue());
|
webSocketVO.setOperateCode(SourceOperateCodeEnum.big_start.getValue());
|
||||||
@@ -1170,67 +1107,8 @@ public class SocketDevResponseService {
|
|||||||
XiNumberManager.smallDevXiNumDataMap.clear();
|
XiNumberManager.smallDevXiNumDataMap.clear();
|
||||||
|
|
||||||
System.out.println("开始系数校准》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》");
|
System.out.println("开始系数校准》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》");
|
||||||
} else if (param.getTestItemList().get(2)) {
|
} else if (param.isFormalTestSelected()) {
|
||||||
// 后续做正式检测
|
startFormalScripts(param, null, param.isResumeFormal());
|
||||||
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为大项code,value为小项个数
|
|
||||||
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 (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);
|
|
||||||
}
|
|
||||||
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 {
|
} else {
|
||||||
//后续什么都不做
|
//后续什么都不做
|
||||||
System.out.println("预检测流程结束-----------------关闭源");
|
System.out.println("预检测流程结束-----------------关闭源");
|
||||||
@@ -1275,6 +1153,97 @@ public class SocketDevResponseService {
|
|||||||
// key为 检测大项对应的code,value为当前大项的检测结果
|
// key为 检测大项对应的code,value为当前大项的检测结果
|
||||||
Map<String, List<DevLineTestResult>> targetTestMap = new HashMap<>();
|
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));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 正式检测
|
* 正式检测
|
||||||
*/
|
*/
|
||||||
@@ -1316,9 +1285,9 @@ public class SocketDevResponseService {
|
|||||||
|
|
||||||
//小项检测完后小项数减一,并更新map
|
//小项检测完后小项数减一,并更新map
|
||||||
long residueCount = 0;
|
long residueCount = 0;
|
||||||
if (sourceIssue.getIsP()) {
|
if (StrUtil.isNotBlank(sourceIssue.getOtherType())) {
|
||||||
residueCount = SocketManager.getSourceTarget(ResultUnitEnum.P.getCode()) - 1;
|
residueCount = SocketManager.getSourceTarget(sourceIssue.getOtherType()) - 1;
|
||||||
SocketManager.addTargetMap(ResultUnitEnum.P.getCode(), residueCount);
|
SocketManager.addTargetMap(sourceIssue.getOtherType(), residueCount);
|
||||||
} else {
|
} else {
|
||||||
residueCount = SocketManager.getSourceTarget(sourceIssue.getType()) - 1;
|
residueCount = SocketManager.getSourceTarget(sourceIssue.getType()) - 1;
|
||||||
SocketManager.addTargetMap(sourceIssue.getType(), residueCount);
|
SocketManager.addTargetMap(sourceIssue.getType(), residueCount);
|
||||||
@@ -1362,14 +1331,15 @@ public class SocketDevResponseService {
|
|||||||
List<SourceIssue> sourceIssueList = SocketManager.getSourceList();
|
List<SourceIssue> sourceIssueList = SocketManager.getSourceList();
|
||||||
if (CollUtil.isNotEmpty(sourceIssueList)) {
|
if (CollUtil.isNotEmpty(sourceIssueList)) {
|
||||||
SourceIssue sourceIssues = SocketManager.getSourceList().get(0);
|
SourceIssue sourceIssues = SocketManager.getSourceList().get(0);
|
||||||
|
|
||||||
|
String type = sourceIssues.getType();
|
||||||
|
if (StrUtil.isNotBlank(sourceIssues.getOtherType())) {
|
||||||
|
sourceIssues.setType(PowerIndexEnum.V.getKey());
|
||||||
|
type = sourceIssues.getOtherType();
|
||||||
|
}
|
||||||
// 如果上一个大项检测完成,则检测下一个大项,并向前端推送消息
|
// 如果上一个大项检测完成,则检测下一个大项,并向前端推送消息
|
||||||
if (residueCount == 0) {
|
if (residueCount == 0) {
|
||||||
WebServiceManager.sendDetectionMessage(param.getUserPageId(), sourceIssues.getType() + CnSocketUtil.START_TAG, null, new ArrayList<>(), null);
|
WebServiceManager.sendDetectionMessage(param.getUserPageId(), type + CnSocketUtil.START_TAG, null, new ArrayList<>(), null);
|
||||||
}
|
|
||||||
String type = sourceIssues.getType();
|
|
||||||
if (sourceIssues.getIsP()) {
|
|
||||||
sourceIssues.setType(ResultUnitEnum.V_ABSOLUTELY.getCode());
|
|
||||||
type = ResultUnitEnum.P.getCode();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//控源下发下一个小项脚本
|
//控源下发下一个小项脚本
|
||||||
@@ -1810,7 +1780,7 @@ public class SocketDevResponseService {
|
|||||||
//字典树
|
//字典树
|
||||||
SocketManager.valueTypeMap = iPqScriptCheckDataService.getValueTypeMap(param.getScriptId());
|
SocketManager.valueTypeMap = iPqScriptCheckDataService.getValueTypeMap(param.getScriptId());
|
||||||
|
|
||||||
if (param.getTestItemList().get(1)) {
|
if (param.isCoefficientSelected()) {
|
||||||
initXiManager(param);
|
initXiManager(param);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1967,9 +1937,6 @@ public class SocketDevResponseService {
|
|||||||
|
|
||||||
if (nonHarmonicList.contains(sourceIssue.getType())) {
|
if (nonHarmonicList.contains(sourceIssue.getType())) {
|
||||||
for (DevData.SqlDataDTO sqlDataDTO : data.getSqlData()) {
|
for (DevData.SqlDataDTO sqlDataDTO : data.getSqlData()) {
|
||||||
if (sqlDataDTO.getDesc().equals("PF")) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
DevData.SqlDataDTO.ListDTO listDTO = sqlDataDTO.getList();
|
DevData.SqlDataDTO.ListDTO listDTO = sqlDataDTO.getList();
|
||||||
SimAndDigNonHarmonicResult adNonHarmonicResult = new SimAndDigNonHarmonicResult();
|
SimAndDigNonHarmonicResult adNonHarmonicResult = new SimAndDigNonHarmonicResult();
|
||||||
adNonHarmonicResult.setTimeId(localDateTime);
|
adNonHarmonicResult.setTimeId(localDateTime);
|
||||||
@@ -2012,7 +1979,7 @@ public class SocketDevResponseService {
|
|||||||
adHarmonicResult.setAdType(checkDataMap.get(sqlDataDTO.getDesc()));
|
adHarmonicResult.setAdType(checkDataMap.get(sqlDataDTO.getDesc()));
|
||||||
adHarmonicResult.setDataType(sourceIssue.getDataType());
|
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())) {
|
if (CollUtil.isNotEmpty(data.getSqlData())) {
|
||||||
DevData.SqlDataDTO.ListDTO vvv = data.getSqlData().stream().filter(it -> it.getDesc().equals(dui)).collect(Collectors.toList()).get(0).getList();
|
DevData.SqlDataDTO.ListDTO vvv = data.getSqlData().stream().filter(it -> it.getDesc().equals(dui)).collect(Collectors.toList()).get(0).getList();
|
||||||
Double aV = vvv.getA();
|
Double aV = vvv.getA();
|
||||||
@@ -2037,7 +2004,7 @@ public class SocketDevResponseService {
|
|||||||
List<String> c = tem.getC();
|
List<String> c = tem.getC();
|
||||||
|
|
||||||
Class<SimAndDigHarmonicResult> example = (Class<SimAndDigHarmonicResult>) adHarmonicResult.getClass();
|
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++) {
|
for (int i = 1; i < a.size() + 1; i++) {
|
||||||
try {
|
try {
|
||||||
Field aField = example.getDeclaredField("aValue" + i);
|
Field aField = example.getDeclaredField("aValue" + i);
|
||||||
|
|||||||
@@ -17,11 +17,10 @@ import com.njcn.gather.device.pojo.vo.PreDetection;
|
|||||||
import com.njcn.gather.device.service.IPqDevService;
|
import com.njcn.gather.device.service.IPqDevService;
|
||||||
import com.njcn.gather.plan.pojo.po.AdPlanSource;
|
import com.njcn.gather.plan.pojo.po.AdPlanSource;
|
||||||
import com.njcn.gather.plan.service.IAdPlanSourceService;
|
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.script.pojo.po.SourceIssue;
|
||||||
import com.njcn.gather.source.pojo.po.SourceInitialize;
|
import com.njcn.gather.source.pojo.po.SourceInitialize;
|
||||||
import com.njcn.gather.source.service.IPqSourceService;
|
import com.njcn.gather.source.service.IPqSourceService;
|
||||||
import com.njcn.gather.system.pojo.enums.DicDataEnum;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.collections4.CollectionUtils;
|
import org.apache.commons.collections4.CollectionUtils;
|
||||||
@@ -386,8 +385,8 @@ public class SocketSourceResponseService {
|
|||||||
|
|
||||||
//重新下发脚本
|
//重新下发脚本
|
||||||
String type = FormalTestManager.currentIssue.getType();
|
String type = FormalTestManager.currentIssue.getType();
|
||||||
if (ResultUnitEnum.P.getCode().equals(type)) {
|
if (PowerIndexEnum.P.getKey().equals(type)) {
|
||||||
FormalTestManager.currentIssue.setType(ResultUnitEnum.V_ABSOLUTELY.getCode());
|
FormalTestManager.currentIssue.setType(PowerIndexEnum.V.getKey());
|
||||||
}
|
}
|
||||||
socketMsg.setOperateCode(SourceOperateCodeEnum.OPER_GATHER.getValue());
|
socketMsg.setOperateCode(SourceOperateCodeEnum.OPER_GATHER.getValue());
|
||||||
socketMsg.setData(JSON.toJSONString(FormalTestManager.currentIssue));
|
socketMsg.setData(JSON.toJSONString(FormalTestManager.currentIssue));
|
||||||
@@ -538,14 +537,14 @@ public class SocketSourceResponseService {
|
|||||||
int ignoreCount;
|
int ignoreCount;
|
||||||
int readData;
|
int readData;
|
||||||
|
|
||||||
if (DicDataEnum.F.getCode().equals(sourceIssue.getType())) {
|
if (PowerIndexEnum.F.getKey().equals(sourceIssue.getType())) {
|
||||||
// 闪变检测:数据变化较慢,只需少量预热和读取
|
// 闪变检测:数据变化较慢,只需少量预热和读取
|
||||||
// 闪变测量稳定性好,预热1次即可
|
// 闪变测量稳定性好,预热1次即可
|
||||||
ignoreCount = 1;
|
ignoreCount = 1;
|
||||||
// 读取2次数据计算闪变值
|
// 读取2次数据计算闪变值
|
||||||
readData = 2;
|
readData = 2;
|
||||||
socketMsg.setOperateCode(SourceOperateCodeEnum.DEV_DATA_REQUEST_01.getValue());
|
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次预热确保触发稳定
|
// 暂态事件需要5次预热确保触发稳定
|
||||||
ignoreCount = 5;
|
ignoreCount = 5;
|
||||||
@@ -575,9 +574,6 @@ public class SocketSourceResponseService {
|
|||||||
DevPhaseSequenceParam phaseSequenceParam = new DevPhaseSequenceParam();
|
DevPhaseSequenceParam phaseSequenceParam = new DevPhaseSequenceParam();
|
||||||
// 设置监测点ID列表
|
// 设置监测点ID列表
|
||||||
phaseSequenceParam.setMoniterIdList(monitorIdList);
|
phaseSequenceParam.setMoniterIdList(monitorIdList);
|
||||||
if (socketDataMsg.getRequestId().equals(SourceOperateCodeEnum.FORMAL_REAL.getValue() + CnSocketUtil.STEP_TAG + "P")) {
|
|
||||||
comm.add("real$PF");
|
|
||||||
}
|
|
||||||
// 设置数据类型列表
|
// 设置数据类型列表
|
||||||
phaseSequenceParam.setDataType(comm);
|
phaseSequenceParam.setDataType(comm);
|
||||||
// 设置读取次数
|
// 设置读取次数
|
||||||
|
|||||||
@@ -37,11 +37,15 @@ public enum DetectionCodeEnum {
|
|||||||
I_UNBAN("I_UNBAN", "三相电流负序不平衡度"),
|
I_UNBAN("I_UNBAN", "三相电流负序不平衡度"),
|
||||||
SeqA("SeqA", "电流序分量"),
|
SeqA("SeqA", "电流序分量"),
|
||||||
PST("PST", "短时间闪变"),
|
PST("PST", "短时间闪变"),
|
||||||
W("W", "有功功率"),
|
W("W", "总有功功率"),
|
||||||
VARW("VARW", "无功功率"),
|
VARW("VARW", "总无功功率"),
|
||||||
VAW("VAW", "视在功率"),
|
VAW("VAW", "总视在功率"),
|
||||||
// PF("PF", "功率因数"),
|
PF("PF", "功率因数"),
|
||||||
// P_FUND("P_FUND", "基波有功功率"),
|
TOTW("TotW", "三相总有功功率"),
|
||||||
|
TOTVA("TotVA", "三相总视在功率"),
|
||||||
|
TOTVAR("TotVAr", "三相总无功功率"),
|
||||||
|
TOTPF("TotPF","三相功率因数"),
|
||||||
|
// P_FUND("P_FUND", "基波有功功率"),
|
||||||
// P_HVAR("P_HVAR", "基波无功功率"),
|
// P_HVAR("P_HVAR", "基波无功功率"),
|
||||||
// P_HVA("P_HVA", "基波视在功率"),
|
// P_HVA("P_HVA", "基波视在功率"),
|
||||||
I1("I1", "基波电流"),
|
I1("I1", "基波电流"),
|
||||||
|
|||||||
@@ -38,10 +38,31 @@ public class ContrastDetectionParam {
|
|||||||
@NotEmpty(message = DetectionValidMessage.PAIRS_NOT_EMPTY)
|
@NotEmpty(message = DetectionValidMessage.PAIRS_NOT_EMPTY)
|
||||||
private Map<String, String> pairs;
|
private Map<String, String> pairs;
|
||||||
/**
|
/**
|
||||||
* 检测项列表。第一个元素为预检测、第二个元素为系数校准、第三个元素为正式检测
|
* 检测项列表。第一个元素为预检测、第二个元素为系数校准、第三个元素为守时校验、第四个元素为正式检测。
|
||||||
|
* 比对场景暂不支持系数校准和守时校验,第二、第三个元素固定为 false。
|
||||||
*/
|
*/
|
||||||
private List<Boolean> testItemList;
|
private List<Boolean> testItemList;
|
||||||
|
|
||||||
|
public boolean isPreTestSelected() {
|
||||||
|
return isTestItemSelected(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isCoefficientSelected() {
|
||||||
|
return isTestItemSelected(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isTimeCheckSelected() {
|
||||||
|
return isTestItemSelected(2);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isFormalTestSelected() {
|
||||||
|
return isTestItemSelected(3);
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isTestItemSelected(int index) {
|
||||||
|
return testItemList != null && testItemList.size() > index && Boolean.TRUE.equals(testItemList.get(index));
|
||||||
|
}
|
||||||
|
|
||||||
private String userId;
|
private String userId;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -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;
|
||||||
|
}
|
||||||
@@ -5,7 +5,6 @@ import lombok.Data;
|
|||||||
import javax.validation.constraints.NotBlank;
|
import javax.validation.constraints.NotBlank;
|
||||||
import javax.validation.constraints.NotEmpty;
|
import javax.validation.constraints.NotEmpty;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author wr
|
* @author wr
|
||||||
@@ -76,7 +75,36 @@ public class PreDetectionParam {
|
|||||||
private Float humidity;
|
private Float humidity;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 检测项列表。第一个元素为预检测、第二个元素为系数校准、第三个元素为正式检测
|
* 检测项列表。第一个元素为预检测、第二个元素为系数校准、第三个元素为守时校验、第四个元素为正式检测
|
||||||
*/
|
*/
|
||||||
private List<Boolean> testItemList;
|
private List<Boolean> testItemList;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否从正式检测暂存进度续检
|
||||||
|
*/
|
||||||
|
private Boolean resumeFormal;
|
||||||
|
|
||||||
|
public boolean isPreTestSelected() {
|
||||||
|
return isTestItemSelected(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isCoefficientSelected() {
|
||||||
|
return isTestItemSelected(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isTimeCheckSelected() {
|
||||||
|
return isTestItemSelected(2);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isFormalTestSelected() {
|
||||||
|
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));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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<>();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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);
|
||||||
|
}
|
||||||
@@ -1,8 +1,10 @@
|
|||||||
package com.njcn.gather.detection.service;
|
package com.njcn.gather.detection.service;
|
||||||
|
|
||||||
import com.njcn.gather.detection.pojo.param.ContrastDetectionParam;
|
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.PreDetectionParam;
|
||||||
import com.njcn.gather.detection.pojo.param.SimulateDetectionParam;
|
import com.njcn.gather.detection.pojo.param.SimulateDetectionParam;
|
||||||
|
import com.njcn.gather.detection.pojo.vo.FormalProgressVO;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -33,6 +35,10 @@ public interface PreDetectionService {
|
|||||||
|
|
||||||
boolean restartTemTest(PreDetectionParam param);
|
boolean restartTemTest(PreDetectionParam param);
|
||||||
|
|
||||||
|
void saveFormalProgress(FormalProgressParam param);
|
||||||
|
|
||||||
|
FormalProgressVO formalProgress(FormalProgressParam param);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 模拟测试-源通讯校验
|
* 模拟测试-源通讯校验
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import cn.hutool.core.bean.BeanUtil;
|
|||||||
import cn.hutool.core.collection.CollUtil;
|
import cn.hutool.core.collection.CollUtil;
|
||||||
import cn.hutool.core.util.NumberUtil;
|
import cn.hutool.core.util.NumberUtil;
|
||||||
import cn.hutool.core.util.ObjectUtil;
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
import com.github.yulichang.wrapper.MPJLambdaWrapper;
|
import com.github.yulichang.wrapper.MPJLambdaWrapper;
|
||||||
import com.njcn.gather.detection.pojo.enums.DetectionCodeEnum;
|
import com.njcn.gather.detection.pojo.enums.DetectionCodeEnum;
|
||||||
@@ -27,7 +28,7 @@ import com.njcn.gather.monitor.pojo.po.PqMonitor;
|
|||||||
import com.njcn.gather.monitor.service.IPqMonitorService;
|
import com.njcn.gather.monitor.service.IPqMonitorService;
|
||||||
import com.njcn.gather.plan.pojo.enums.DataSourceEnum;
|
import com.njcn.gather.plan.pojo.enums.DataSourceEnum;
|
||||||
import com.njcn.gather.report.pojo.enums.PowerIndexEnum;
|
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.PqScriptCheckData;
|
||||||
import com.njcn.gather.script.pojo.po.SourceIssue;
|
import com.njcn.gather.script.pojo.po.SourceIssue;
|
||||||
import com.njcn.gather.script.service.IPqScriptCheckDataService;
|
import com.njcn.gather.script.service.IPqScriptCheckDataService;
|
||||||
@@ -72,6 +73,7 @@ public class DetectionServiceImpl {
|
|||||||
private final IPqMonitorService pqMonitorService;
|
private final IPqMonitorService pqMonitorService;
|
||||||
private final IPqDevService pqDevService;
|
private final IPqDevService pqDevService;
|
||||||
private final IPqStandardDevGainRecordService pqStandardDevGainRecordService;
|
private final IPqStandardDevGainRecordService pqStandardDevGainRecordService;
|
||||||
|
private final PqScriptMapper pqScriptMapper;
|
||||||
|
|
||||||
public static final String TYPE_A = "A";
|
public static final String TYPE_A = "A";
|
||||||
public static final String TYPE_B = "B";
|
public static final String TYPE_B = "B";
|
||||||
@@ -79,7 +81,6 @@ public class DetectionServiceImpl {
|
|||||||
public static final String TYPE_T = "T";
|
public static final String TYPE_T = "T";
|
||||||
private final String U = "U";
|
private final String U = "U";
|
||||||
private final String I = "I";
|
private final String I = "I";
|
||||||
private final String F = "F";
|
|
||||||
private final String HP = "HP";
|
private final String HP = "HP";
|
||||||
private final String P = "P";
|
private final String P = "P";
|
||||||
private final String MAG = "MAG";
|
private final String MAG = "MAG";
|
||||||
@@ -160,30 +161,31 @@ public class DetectionServiceImpl {
|
|||||||
param.setIn(sourceIssue.getFIn());
|
param.setIn(sourceIssue.getFIn());
|
||||||
SysTestConfig oneConfig = sysTestConfigService.getOneConfig();
|
SysTestConfig oneConfig = sysTestConfigService.getOneConfig();
|
||||||
List<ErrDtlsCheckDataVO> errDtlsCheckData = pqErrSysDtlsService.listByPqErrSysIdAndTypes(param);
|
List<ErrDtlsCheckDataVO> errDtlsCheckData = pqErrSysDtlsService.listByPqErrSysIdAndTypes(param);
|
||||||
ResultUnitEnum resultUnitEnumByCode = ResultUnitEnum.getResultUnitEnumByCode(sourceIssue.getType());
|
PowerIndexEnum powerIndexEnum = PowerIndexEnum.getByKey(sourceIssue.getType());
|
||||||
if (sourceIssue.getIsP()) {
|
if (StrUtil.isNotBlank(sourceIssue.getOtherType())) {
|
||||||
resultUnitEnumByCode = ResultUnitEnum.P;
|
powerIndexEnum = PowerIndexEnum.getByKey(sourceIssue.getOtherType());
|
||||||
}
|
}
|
||||||
switch (resultUnitEnumByCode) {
|
|
||||||
|
switch (powerIndexEnum) {
|
||||||
/**
|
/**
|
||||||
* 频率
|
* 频率
|
||||||
*/
|
*/
|
||||||
case FREQ:
|
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:
|
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, PowerIndexEnum.ANGLE.getKey(), sourceIssue, dataRule, code, oneConfig.getScale());
|
||||||
/**
|
/**
|
||||||
* 电压
|
* 电压
|
||||||
*/
|
*/
|
||||||
case V_RELATIVE:
|
case V:
|
||||||
case V_ABSOLUTELY:
|
return isQualified(dev, devIdMapComm, errDtlsCheckData, PowerIndexEnum.V.getKey(), sourceIssue, dataRule, code, oneConfig.getScale());
|
||||||
return isQualified(dev, devIdMapComm, errDtlsCheckData, U, sourceIssue, dataRule, code, oneConfig.getScale());
|
|
||||||
/**
|
/**
|
||||||
* 电流
|
* 电流
|
||||||
*/
|
*/
|
||||||
case I_RELATIVE:
|
case I:
|
||||||
case I_ABSOLUTELY:
|
return isQualified(dev, devIdMapComm, errDtlsCheckData, PowerIndexEnum.I.getKey(), sourceIssue, dataRule, code, oneConfig.getScale());
|
||||||
return isQualified(dev, devIdMapComm, errDtlsCheckData, I, sourceIssue, dataRule, code, oneConfig.getScale());
|
|
||||||
/**
|
/**
|
||||||
* 谐波
|
* 谐波
|
||||||
*/
|
*/
|
||||||
@@ -228,8 +230,7 @@ public class DetectionServiceImpl {
|
|||||||
/**
|
/**
|
||||||
* 暂态
|
* 暂态
|
||||||
*/
|
*/
|
||||||
case VOLTAGE_MAG:
|
case VOLTAGE:
|
||||||
case VOLTAGE_DUR:
|
|
||||||
return isVoltageQualified(dev, devIdMapComm, errDtlsCheckData, sourceIssue, dataRule, code, oneConfig.getScale());
|
return isVoltageQualified(dev, devIdMapComm, errDtlsCheckData, sourceIssue, dataRule, code, oneConfig.getScale());
|
||||||
default:
|
default:
|
||||||
return isUnknownQualified(dev, devIdMapComm, errDtlsCheckData, sourceIssue, dataRule, code, oneConfig.getScale());
|
return isUnknownQualified(dev, devIdMapComm, errDtlsCheckData, sourceIssue, dataRule, code, oneConfig.getScale());
|
||||||
@@ -414,30 +415,36 @@ public class DetectionServiceImpl {
|
|||||||
List<SimAndDigNonHarmonicResult> info = new ArrayList<>();
|
List<SimAndDigNonHarmonicResult> info = new ArrayList<>();
|
||||||
List<String> devValueTypeList = sourceIssue.getDevValueTypeList();
|
List<String> devValueTypeList = sourceIssue.getDevValueTypeList();
|
||||||
for (String s : devValueTypeList) {
|
for (String s : devValueTypeList) {
|
||||||
if ((DetectionCodeEnum.REAL_PREFIX.getCode() + "PF").equals(s)) {
|
String[] splitArr = s.split("\\$");
|
||||||
continue;
|
|
||||||
}
|
|
||||||
// 根据数据处理规则取值。key为相别,value为值列表
|
// 根据数据处理规则取值。key为相别,value为值列表
|
||||||
Map<String, List<Double>> map = devListMap(dev, dataRule, s.split("\\$")[1]);
|
Map<String, List<Double>> map = devListMap(dev, dataRule, splitArr[1]);
|
||||||
List<ErrDtlsCheckDataVO> dtlsCheckData = null;
|
List<ErrDtlsCheckDataVO> dtlsCheckData = null;
|
||||||
if (CollUtil.isNotEmpty(errDtlsCheckData)) {
|
if (CollUtil.isNotEmpty(errDtlsCheckData)) {
|
||||||
dtlsCheckData = errDtlsCheckData.stream().filter(x -> x.getValueTypeCode().equals(s.split("\\$")[1])).collect(Collectors.toList());
|
dtlsCheckData = errDtlsCheckData.stream().filter(x -> x.getValueTypeCode().equals(splitArr[1])).collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
Double fData = 1.0;
|
Double fData = 1.0;
|
||||||
if (U.equals(type)) {
|
if (PowerIndexEnum.V.getKey().equals(type)) {
|
||||||
fData = sourceIssue.getFUn();
|
fData = sourceIssue.getFUn();
|
||||||
}
|
}
|
||||||
if (I.equals(type)) {
|
if (PowerIndexEnum.I.getKey().equals(type)) {
|
||||||
fData = sourceIssue.getFIn();
|
fData = sourceIssue.getFIn();
|
||||||
}
|
}
|
||||||
if (F.equals(type)) {
|
if (PowerIndexEnum.FREQ.getKey().equals(type)) {
|
||||||
fData = sourceIssue.getFFreq();
|
fData = sourceIssue.getFFreq();
|
||||||
}
|
}
|
||||||
if (P.equals(type)) {
|
if (PowerIndexEnum.P.getKey().equals(type)) {
|
||||||
fData = sourceIssue.getFUn() * sourceIssue.getFIn() * 0.01;
|
if (!DetectionCodeEnum.PF.getCode().equals(splitArr[1]) && !DetectionCodeEnum.TOTPF.getCode().equals(splitArr[1])) {
|
||||||
|
Boolean valueType = pqScriptMapper.selectScriptIsValueType(sourceIssue.getScriptId());
|
||||||
|
if (valueType) {
|
||||||
|
fData = sourceIssue.getFUn() * sourceIssue.getFIn() / 100;
|
||||||
|
}
|
||||||
Double finalFData = fData;
|
Double finalFData = fData;
|
||||||
dtlsCheckData.stream().forEach(x -> x.setValue(x.getValue() * finalFData));
|
dtlsCheckData.stream().forEach(x -> x.setValue(x.getValue() * finalFData));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
// if (ResultUnitEnum.ANGLE.getCode().equals(type)) {
|
||||||
|
// fData = null;
|
||||||
|
// }
|
||||||
SimAndDigNonHarmonicResult result = new SimAndDigNonHarmonicResult();
|
SimAndDigNonHarmonicResult result = new SimAndDigNonHarmonicResult();
|
||||||
String[] split = dev.get(0).getId().split("_");
|
String[] split = dev.get(0).getId().split("_");
|
||||||
String devID = devIdMapComm.get(split[0]);
|
String devID = devIdMapComm.get(split[0]);
|
||||||
@@ -476,6 +483,19 @@ public class DetectionServiceImpl {
|
|||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
if (CollUtil.isNotEmpty(checkData)) {
|
if (CollUtil.isNotEmpty(checkData)) {
|
||||||
List<Double> phaseValue = map.get(phase);
|
List<Double> phaseValue = map.get(phase);
|
||||||
|
if (PowerIndexEnum.ANGLE.getKey().equals(type)) {
|
||||||
|
phaseValue = phaseValue.stream().map(x -> {
|
||||||
|
// 原始误差值
|
||||||
|
double originDiff = x - checkData.get(0).getValue();
|
||||||
|
// 转换误差值
|
||||||
|
double translateDiff = Math.abs(originDiff) - 360;
|
||||||
|
if (Math.abs(translateDiff) <= 10) {
|
||||||
|
return Math.abs(x);
|
||||||
|
} else {
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
}).collect(Collectors.toList());
|
||||||
|
}
|
||||||
// 注意:如果map中不存在该phase的键,phaseValue可能为null,需确保map包含该键
|
// 注意:如果map中不存在该phase的键,phaseValue可能为null,需确保map包含该键
|
||||||
DetectionData detectionData = rangeComparisonList(phaseValue, isQualified, pqErrSysDtls, fData, checkData.get(0).getValue(), dataRule, scale);
|
DetectionData detectionData = rangeComparisonList(phaseValue, isQualified, pqErrSysDtls, fData, checkData.get(0).getValue(), dataRule, scale);
|
||||||
resultFlag.add(detectionData);
|
resultFlag.add(detectionData);
|
||||||
@@ -518,11 +538,15 @@ public class DetectionServiceImpl {
|
|||||||
SourceIssue sourceIssue,
|
SourceIssue sourceIssue,
|
||||||
DictDataEnum dataRule,
|
DictDataEnum dataRule,
|
||||||
Integer num, Integer scale) {
|
Integer num, Integer scale) {
|
||||||
Double fData = 1.0;
|
Double fDataA = 1.0;
|
||||||
|
Double fDataB = 1.0;
|
||||||
|
Double fDataC = 1.0;
|
||||||
String fundCode = "";
|
String fundCode = "";
|
||||||
String harmCode = "";
|
String harmCode = "";
|
||||||
if (U.equals(type)) {
|
if (U.equals(type)) {
|
||||||
fData = sourceIssue.getFUn();
|
fDataA = sourceIssue.getChannelList().stream().filter(x -> x.getChannelType().contains("Ua")).findFirst().get().getFAmp();
|
||||||
|
fDataB = sourceIssue.getChannelList().stream().filter(x -> x.getChannelType().contains("Ub")).findFirst().get().getFAmp();
|
||||||
|
fDataC = sourceIssue.getChannelList().stream().filter(x -> x.getChannelType().contains("Uc")).findFirst().get().getFAmp();
|
||||||
fundCode = DetectionCodeEnum.U1.getCode();
|
fundCode = DetectionCodeEnum.U1.getCode();
|
||||||
if (num == 1) {
|
if (num == 1) {
|
||||||
harmCode = DetectionCodeEnum.SV_1_49.getCode();
|
harmCode = DetectionCodeEnum.SV_1_49.getCode();
|
||||||
@@ -531,7 +555,9 @@ public class DetectionServiceImpl {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (I.equals(type)) {
|
if (I.equals(type)) {
|
||||||
fData = sourceIssue.getFIn();
|
fDataA = sourceIssue.getChannelList().stream().filter(x -> x.getChannelType().contains("Ia")).findFirst().get().getFAmp();
|
||||||
|
fDataB = sourceIssue.getChannelList().stream().filter(x -> x.getChannelType().contains("Ib")).findFirst().get().getFAmp();
|
||||||
|
fDataC = sourceIssue.getChannelList().stream().filter(x -> x.getChannelType().contains("Ic")).findFirst().get().getFAmp();
|
||||||
fundCode = DetectionCodeEnum.I1.getCode();
|
fundCode = DetectionCodeEnum.I1.getCode();
|
||||||
if (num == 1) {
|
if (num == 1) {
|
||||||
harmCode = DetectionCodeEnum.SI_1_49.getCode();
|
harmCode = DetectionCodeEnum.SI_1_49.getCode();
|
||||||
@@ -540,7 +566,9 @@ public class DetectionServiceImpl {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (HP.equals(type)) {
|
if (HP.equals(type)) {
|
||||||
fData = (sourceIssue.getFIn() * sourceIssue.getFUn()) * 0.01;
|
fDataA = (sourceIssue.getFIn() * sourceIssue.getFUn()) * 0.01;
|
||||||
|
fDataB = (sourceIssue.getFIn() * sourceIssue.getFUn()) * 0.01;
|
||||||
|
fDataC = (sourceIssue.getFIn() * sourceIssue.getFUn()) * 0.01;
|
||||||
harmCode = DetectionCodeEnum.P2_50.getCode();
|
harmCode = DetectionCodeEnum.P2_50.getCode();
|
||||||
}
|
}
|
||||||
// if (P.equals(type)) {
|
// if (P.equals(type)) {
|
||||||
@@ -566,9 +594,9 @@ public class DetectionServiceImpl {
|
|||||||
pqErrSysDtls = adDtlsCheckData.get(0).getErrSysDtls();
|
pqErrSysDtls = adDtlsCheckData.get(0).getErrSysDtls();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
List<DetectionData> integerBooleanA = harmRangeComparison(isQualified, pqErrSysDtls, type, TYPE_A, sourceIssue, dataRule, devMap.get(TYPE_A), fData, num, scale);
|
List<DetectionData> integerBooleanA = harmRangeComparison(isQualified, pqErrSysDtls, type, TYPE_A, sourceIssue, dataRule, devMap.get(TYPE_A), fDataA, num, scale);
|
||||||
List<DetectionData> integerBooleanB = harmRangeComparison(isQualified, pqErrSysDtls, type, TYPE_B, sourceIssue, dataRule, devMap.get(TYPE_B), fData, num, scale);
|
List<DetectionData> integerBooleanB = harmRangeComparison(isQualified, pqErrSysDtls, type, TYPE_B, sourceIssue, dataRule, devMap.get(TYPE_B), fDataB, num, scale);
|
||||||
List<DetectionData> integerBooleanC = harmRangeComparison(isQualified, pqErrSysDtls, type, TYPE_C, sourceIssue, dataRule, devMap.get(TYPE_C), fData, num, scale);
|
List<DetectionData> integerBooleanC = harmRangeComparison(isQualified, pqErrSysDtls, type, TYPE_C, sourceIssue, dataRule, devMap.get(TYPE_C), fDataC, num, scale);
|
||||||
harmonicResult.setDataType(sourceIssue.getDataType());
|
harmonicResult.setDataType(sourceIssue.getDataType());
|
||||||
reflectHarmonic(false, "a", integerBooleanA, harmonicResult, num);
|
reflectHarmonic(false, "a", integerBooleanA, harmonicResult, num);
|
||||||
reflectHarmonic(false, "b", integerBooleanB, harmonicResult, num);
|
reflectHarmonic(false, "b", integerBooleanB, harmonicResult, num);
|
||||||
|
|||||||
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,8 +3,11 @@ package com.njcn.gather.detection.service.impl;
|
|||||||
|
|
||||||
import cn.hutool.core.collection.CollUtil;
|
import cn.hutool.core.collection.CollUtil;
|
||||||
import cn.hutool.core.util.ObjectUtil;
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
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.common.pojo.exception.BusinessException;
|
||||||
import com.njcn.gather.detection.handler.SocketContrastResponseService;
|
import com.njcn.gather.detection.handler.SocketContrastResponseService;
|
||||||
import com.njcn.gather.detection.handler.SocketDevResponseService;
|
import com.njcn.gather.detection.handler.SocketDevResponseService;
|
||||||
@@ -13,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.DetectionResponseEnum;
|
||||||
import com.njcn.gather.detection.pojo.enums.SourceOperateCodeEnum;
|
import com.njcn.gather.detection.pojo.enums.SourceOperateCodeEnum;
|
||||||
import com.njcn.gather.detection.pojo.param.ContrastDetectionParam;
|
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.PreDetectionParam;
|
||||||
import com.njcn.gather.detection.pojo.param.SimulateDetectionParam;
|
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.pojo.vo.SocketMsg;
|
||||||
|
import com.njcn.gather.detection.service.FormalProgressService;
|
||||||
import com.njcn.gather.detection.service.PreDetectionService;
|
import com.njcn.gather.detection.service.PreDetectionService;
|
||||||
import com.njcn.gather.detection.util.business.DetectionCommunicateUtil;
|
import com.njcn.gather.detection.util.business.DetectionCommunicateUtil;
|
||||||
import com.njcn.gather.detection.util.socket.CnSocketUtil;
|
import com.njcn.gather.detection.util.socket.CnSocketUtil;
|
||||||
@@ -24,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.XiNumberManager;
|
||||||
import com.njcn.gather.detection.util.socket.cilent.NettyContrastClientHandler;
|
import com.njcn.gather.detection.util.socket.cilent.NettyContrastClientHandler;
|
||||||
import com.njcn.gather.detection.util.socket.websocket.WebServiceManager;
|
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.PqDev;
|
||||||
|
import com.njcn.gather.device.pojo.po.PqDevSub;
|
||||||
import com.njcn.gather.device.pojo.vo.PreDetection;
|
import com.njcn.gather.device.pojo.vo.PreDetection;
|
||||||
import com.njcn.gather.device.service.IPqDevService;
|
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.enums.DataSourceEnum;
|
||||||
import com.njcn.gather.plan.pojo.po.AdPlan;
|
import com.njcn.gather.plan.pojo.po.AdPlan;
|
||||||
import com.njcn.gather.plan.pojo.po.AdPlanSource;
|
import com.njcn.gather.plan.pojo.po.AdPlanSource;
|
||||||
import com.njcn.gather.plan.service.IAdPlanService;
|
import com.njcn.gather.plan.service.IAdPlanService;
|
||||||
import com.njcn.gather.plan.service.IAdPlanSourceService;
|
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.PqScriptCheckDataParam;
|
||||||
import com.njcn.gather.script.pojo.param.PqScriptIssueParam;
|
import com.njcn.gather.script.pojo.param.PqScriptIssueParam;
|
||||||
import com.njcn.gather.script.pojo.po.SourceIssue;
|
import com.njcn.gather.script.pojo.po.SourceIssue;
|
||||||
@@ -40,6 +51,8 @@ import com.njcn.gather.script.service.IPqScriptCheckDataService;
|
|||||||
import com.njcn.gather.script.service.IPqScriptDtlsService;
|
import com.njcn.gather.script.service.IPqScriptDtlsService;
|
||||||
import com.njcn.gather.source.pojo.po.SourceInitialize;
|
import com.njcn.gather.source.pojo.po.SourceInitialize;
|
||||||
import com.njcn.gather.source.service.IPqSourceService;
|
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.cfg.service.ISysTestConfigService;
|
||||||
import com.njcn.gather.system.config.PathConfig;
|
import com.njcn.gather.system.config.PathConfig;
|
||||||
import com.njcn.gather.system.dictionary.pojo.enums.DictDataEnum;
|
import com.njcn.gather.system.dictionary.pojo.enums.DictDataEnum;
|
||||||
@@ -49,7 +62,6 @@ import com.njcn.web.utils.RequestUtil;
|
|||||||
import io.netty.channel.Channel;
|
import io.netty.channel.Channel;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import javax.servlet.ServletOutputStream;
|
import javax.servlet.ServletOutputStream;
|
||||||
@@ -81,9 +93,13 @@ public class PreDetectionServiceImpl implements PreDetectionService {
|
|||||||
private final IPqScriptCheckDataService iPqScriptCheckDataService;
|
private final IPqScriptCheckDataService iPqScriptCheckDataService;
|
||||||
private final SocketManager socketManager;
|
private final SocketManager socketManager;
|
||||||
private final ISysTestConfigService sysTestConfigService;
|
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 String alignDataFilePath;
|
||||||
private final PathConfig pathConfig;
|
private final PathConfig pathConfig;
|
||||||
|
|
||||||
@@ -102,6 +118,28 @@ public class PreDetectionServiceImpl implements PreDetectionService {
|
|||||||
param.setScriptId(plan.getScriptId());
|
param.setScriptId(plan.getScriptId());
|
||||||
param.setErrorSysId(plan.getErrorSysId());
|
param.setErrorSysId(plan.getErrorSysId());
|
||||||
param.setCode(String.valueOf(plan.getCode()));
|
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)) {
|
if (ObjectUtil.isNotNull(plan)) {
|
||||||
String code = dictDataService.getDictDataById(plan.getPattern()).getCode();
|
String code = dictDataService.getDictDataById(plan.getPattern()).getCode();
|
||||||
DictDataEnum dictDataEnumByCode = DictDataEnum.getDictDataEnumByCode(code);
|
DictDataEnum dictDataEnumByCode = DictDataEnum.getDictDataEnumByCode(code);
|
||||||
@@ -246,33 +284,254 @@ public class PreDetectionServiceImpl implements PreDetectionService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean restartTemTest(PreDetectionParam param) {
|
public boolean restartTemTest(PreDetectionParam param) {
|
||||||
|
PreDetectionParam runtimeParam = WebServiceManager.getPreDetectionParam(param.getUserPageId());
|
||||||
|
if (runtimeParam == null) {
|
||||||
|
if (StrUtil.isBlank(param.getSourceId()) || StrUtil.isBlank(param.getScriptId()) || StrUtil.isBlank(param.getCode())) {
|
||||||
|
throw new BusinessException(CommonResponseEnum.FAIL, "未找到暂停检测上下文,请重新开始检测");
|
||||||
|
}
|
||||||
|
runtimeParam = param;
|
||||||
|
}
|
||||||
FormalTestManager.stopFlag = false;
|
FormalTestManager.stopFlag = false;
|
||||||
socketDevResponseService.initRestart();
|
socketDevResponseService.initRestart();
|
||||||
List<SourceIssue> sourceIssueList = SocketManager.getSourceList();
|
List<SourceIssue> sourceIssueList = SocketManager.getSourceList();
|
||||||
SourceInitialize sourceInitialize = pqSourceService.getSourceInitializeParam(param.getSourceId());
|
if (StrUtil.isBlank(runtimeParam.getSourceName()) && StrUtil.isNotBlank(runtimeParam.getSourceId())) {
|
||||||
param.setSourceName(sourceInitialize.getSourceId());
|
SourceInitialize sourceInitialize = pqSourceService.getSourceInitializeParam(runtimeParam.getSourceId());
|
||||||
|
if (sourceInitialize == null) {
|
||||||
|
throw new BusinessException(DetectionResponseEnum.SOURCE_INFO_NOT);
|
||||||
|
}
|
||||||
|
runtimeParam.setSourceName(sourceInitialize.getSourceId());
|
||||||
|
}
|
||||||
if (CollUtil.isNotEmpty(sourceIssueList)) {
|
if (CollUtil.isNotEmpty(sourceIssueList)) {
|
||||||
SourceIssue sourceIssues = SocketManager.getSourceList().get(0);
|
SourceIssue sourceIssues = SocketManager.getSourceList().get(0);
|
||||||
|
String type = resolveFormalIssueType(sourceIssues);
|
||||||
|
sendBigItemStartIfFirstFormalIssue(runtimeParam, sourceIssues, type);
|
||||||
|
if (StrUtil.isNotBlank(sourceIssues.getOtherType())) {
|
||||||
|
sourceIssues.setType(PowerIndexEnum.V.getKey());
|
||||||
|
}
|
||||||
SocketMsg<String> xuMsg = new SocketMsg<>();
|
SocketMsg<String> xuMsg = new SocketMsg<>();
|
||||||
xuMsg.setOperateCode(SourceOperateCodeEnum.OPER_GATHER.getValue());
|
xuMsg.setOperateCode(SourceOperateCodeEnum.OPER_GATHER.getValue());
|
||||||
xuMsg.setData(JSON.toJSONString(sourceIssues));
|
xuMsg.setData(JSON.toJSONString(sourceIssues));
|
||||||
xuMsg.setRequestId(SourceOperateCodeEnum.FORMAL_REAL.getValue() + "&&" + sourceIssues.getType());
|
xuMsg.setRequestId(SourceOperateCodeEnum.FORMAL_REAL.getValue() + "&&" + type);
|
||||||
SocketManager.sendMsg(param.getUserPageId() + DetectionCommunicateConstant.SOURCE, JSON.toJSONString(xuMsg));
|
SocketManager.sendMsg(runtimeParam.getUserPageId() + DetectionCommunicateConstant.SOURCE, JSON.toJSONString(xuMsg));
|
||||||
// Resume_Success
|
// Resume_Success
|
||||||
} else {
|
} else {
|
||||||
//TODO 是否最终检测完成需要推送给用户 检测完成
|
//TODO 是否最终检测完成需要推送给用户 检测完成
|
||||||
PqScriptCheckDataParam checkDataParam = new PqScriptCheckDataParam();
|
PqScriptCheckDataParam checkDataParam = new PqScriptCheckDataParam();
|
||||||
checkDataParam.setScriptId(param.getScriptId());
|
checkDataParam.setScriptId(runtimeParam.getScriptId());
|
||||||
checkDataParam.setIsValueTypeName(false);
|
checkDataParam.setIsValueTypeName(false);
|
||||||
List<String> adType = iPqScriptCheckDataService.getValueType(checkDataParam);
|
List<String> adType = iPqScriptCheckDataService.getValueType(checkDataParam);
|
||||||
|
|
||||||
iPqDevService.updateResult(param.getDevIds(), adType, param.getCode(), param.getUserId(), param.getTemperature(), param.getHumidity(), true);
|
iPqDevService.updateResult(runtimeParam.getDevIds(), adType, runtimeParam.getCode(), runtimeParam.getUserId(), runtimeParam.getTemperature(), runtimeParam.getHumidity(), true);
|
||||||
CnSocketUtil.quitSend(param);
|
CnSocketUtil.quitSend(runtimeParam);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
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 sendBigItemStartIfFirstFormalIssue(PreDetectionParam param, SourceIssue currentIssue, String type) {
|
||||||
|
if (param == null || currentIssue == null || currentIssue.getIndex() == null || StrUtil.isBlank(type)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
List<SourceIssue> allIssues = buildAllFormalIssues(param);
|
||||||
|
if (isFirstFormalIssueOfBigItem(allIssues, currentIssue, type)) {
|
||||||
|
WebServiceManager.sendDetectionMessage(param.getUserPageId(), type + CnSocketUtil.START_TAG, null, new ArrayList<>(), null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static boolean isFirstFormalIssueOfBigItem(List<SourceIssue> allIssues, SourceIssue currentIssue, String type) {
|
||||||
|
if (CollUtil.isEmpty(allIssues) || currentIssue == null || currentIssue.getIndex() == null || StrUtil.isBlank(type)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
Integer firstSort = allIssues.stream()
|
||||||
|
.filter(issue -> type.equals(resolveFormalIssueType(issue)))
|
||||||
|
.map(SourceIssue::getIndex)
|
||||||
|
.filter(Objects::nonNull)
|
||||||
|
.min(Integer::compareTo)
|
||||||
|
.orElse(null);
|
||||||
|
return Objects.equals(firstSort, currentIssue.getIndex());
|
||||||
|
}
|
||||||
|
|
||||||
|
static String resolveFormalIssueType(SourceIssue issue) {
|
||||||
|
if (issue == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return StrUtil.isNotBlank(issue.getOtherType()) ? issue.getOtherType() : issue.getType();
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
@Override
|
||||||
public void ytxCheckSimulate(SimulateDetectionParam param) {
|
public void ytxCheckSimulate(SimulateDetectionParam param) {
|
||||||
PreDetectionParam preDetectionParam = new PreDetectionParam();
|
PreDetectionParam preDetectionParam = new PreDetectionParam();
|
||||||
@@ -310,9 +569,9 @@ public class PreDetectionServiceImpl implements PreDetectionService {
|
|||||||
|
|
||||||
SourceIssue sourceIssue = sourceIssues.get(0);
|
SourceIssue sourceIssue = sourceIssues.get(0);
|
||||||
String type = sourceIssue.getType();
|
String type = sourceIssue.getType();
|
||||||
if (sourceIssue.getIsP()) {
|
if (StrUtil.isNotBlank(sourceIssue.getOtherType())) {
|
||||||
sourceIssue.setType(ResultUnitEnum.V_ABSOLUTELY.getCode());
|
sourceIssue.setType(PowerIndexEnum.V.getKey());
|
||||||
type = ResultUnitEnum.P.getCode();
|
type = sourceIssue.getOtherType();
|
||||||
}
|
}
|
||||||
|
|
||||||
List<String> comm = sourceIssue.getDevValueTypeList();
|
List<String> comm = sourceIssue.getDevValueTypeList();
|
||||||
|
|||||||
@@ -220,9 +220,29 @@ public class FormalTestManager {
|
|||||||
*/
|
*/
|
||||||
public static LocalDateTime checkStartTime;
|
public static LocalDateTime checkStartTime;
|
||||||
|
|
||||||
|
public static boolean resumeFormalPending;
|
||||||
|
|
||||||
|
public static Integer resumeNextSort;
|
||||||
|
|
||||||
|
public static Integer resumeBaseFormalCheckTime;
|
||||||
|
|
||||||
|
public static LocalDateTime resumeFormalStartTime;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 数模式 检测类型"1"-"全部检测" , "2"-"不合格项复检"
|
* 数模式 检测类型"1"-"全部检测" , "2"-"不合格项复检"
|
||||||
*/
|
*/
|
||||||
public static String reCheckType;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -343,6 +343,11 @@ public class SocketManager {
|
|||||||
return targetMap.get(scriptType);
|
return targetMap.get(scriptType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void clearFormalRuntime() {
|
||||||
|
sourceIssueList.clear();
|
||||||
|
targetMap.clear();
|
||||||
|
valueTypeMap.clear();
|
||||||
|
clockMap.clear();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -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.SocketManager;
|
||||||
import com.njcn.gather.detection.util.socket.websocket.WebServiceManager;
|
import com.njcn.gather.detection.util.socket.websocket.WebServiceManager;
|
||||||
import com.njcn.gather.device.pojo.vo.PreDetection;
|
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.script.pojo.po.SourceIssue;
|
||||||
import com.njcn.gather.system.pojo.enums.DicDataEnum;
|
|
||||||
import io.netty.channel.Channel;
|
import io.netty.channel.Channel;
|
||||||
import io.netty.channel.ChannelHandlerContext;
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
import io.netty.channel.SimpleChannelInboundHandler;
|
import io.netty.channel.SimpleChannelInboundHandler;
|
||||||
@@ -55,19 +55,19 @@ import java.util.stream.Collectors;
|
|||||||
public class NettyDevClientHandler extends SimpleChannelInboundHandler<String> {
|
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 = 60L;
|
private static final long REALTIME_TIMEOUT = 60 * 3L;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 暂停操作超时时间:10分钟(600秒)
|
* 暂停操作超时时间:10分钟(600秒)
|
||||||
@@ -305,10 +305,10 @@ public class NettyDevClientHandler extends SimpleChannelInboundHandler<String> {
|
|||||||
String type = sourceIssue.getType();
|
String type = sourceIssue.getType();
|
||||||
|
|
||||||
// 根据不同检测类型使用不同的超时阈值
|
// 根据不同检测类型使用不同的超时阈值
|
||||||
if (DicDataEnum.F.getCode().equals(type)) {
|
if (PowerIndexEnum.F.getKey().equals(type)) {
|
||||||
// 闪变检测:需要更长时间,20分钟超时
|
// 闪变检测:需要更长时间,20分钟超时
|
||||||
return currentTime >= FLICKER_TIMEOUT;
|
return currentTime >= SHORT_FLICKER_TIMEOUT;
|
||||||
} else if (DicDataEnum.VOLTAGE.getCode().equals(type) || DicDataEnum.HP.getCode().equals(type)) {
|
} else if (PowerIndexEnum.VOLTAGE.getKey().equals(type) || PowerIndexEnum.HP.getKey().equals(type)) {
|
||||||
// 统计数据类型(电压、谐波):中等时间,3分钟超时
|
// 统计数据类型(电压、谐波):中等时间,3分钟超时
|
||||||
return currentTime >= STATISTICS_TIMEOUT;
|
return currentTime >= STATISTICS_TIMEOUT;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ import io.swagger.annotations.ApiImplicitParams;
|
|||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.http.MediaType;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
@@ -69,10 +70,10 @@ public class PqDevController extends BaseController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@OperateInfo(operateType = OperateType.ADD)
|
@OperateInfo(operateType = OperateType.ADD)
|
||||||
@PostMapping("/add")
|
@PostMapping(value = "/add", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
||||||
@ApiOperation("新增被检设备")
|
@ApiOperation("新增被检设备")
|
||||||
@ApiImplicitParam(name = "pqDevParam", value = "被检设备", required = true)
|
@ApiImplicitParam(name = "pqDevParam", value = "被检设备", required = true)
|
||||||
public HttpResult<Boolean> add(@RequestBody @Validated PqDevParam pqDevParam) {
|
public HttpResult<Boolean> add(@ModelAttribute @Validated PqDevParam pqDevParam) {
|
||||||
String methodDescribe = getMethodDescribe("add");
|
String methodDescribe = getMethodDescribe("add");
|
||||||
LogUtil.njcnDebug(log, "{},新增数据为:{}", methodDescribe, pqDevParam);
|
LogUtil.njcnDebug(log, "{},新增数据为:{}", methodDescribe, pqDevParam);
|
||||||
boolean result = pqDevService.addPqDev(pqDevParam);
|
boolean result = pqDevService.addPqDev(pqDevParam);
|
||||||
@@ -84,10 +85,10 @@ public class PqDevController extends BaseController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@OperateInfo(operateType = OperateType.UPDATE)
|
@OperateInfo(operateType = OperateType.UPDATE)
|
||||||
@PostMapping("/update")
|
@PostMapping(value = "/update", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
||||||
@ApiOperation("修改被检设备")
|
@ApiOperation("修改被检设备")
|
||||||
@ApiImplicitParam(name = "updateParam", value = "被检设备", required = true)
|
@ApiImplicitParam(name = "updateParam", value = "被检设备", required = true)
|
||||||
public HttpResult<Boolean> update(@RequestBody @Validated PqDevParam.UpdateParam updateParam) {
|
public HttpResult<Boolean> update(@ModelAttribute @Validated PqDevParam.UpdateParam updateParam) {
|
||||||
String methodDescribe = getMethodDescribe("update");
|
String methodDescribe = getMethodDescribe("update");
|
||||||
LogUtil.njcnDebug(log, "{},修改数据为:{}", methodDescribe, updateParam);
|
LogUtil.njcnDebug(log, "{},修改数据为:{}", methodDescribe, updateParam);
|
||||||
boolean result = pqDevService.updatePqDev(updateParam);
|
boolean result = pqDevService.updatePqDev(updateParam);
|
||||||
@@ -98,6 +99,14 @@ public class PqDevController extends BaseController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@OperateInfo(info = LogEnum.BUSINESS_COMMON, operateType = OperateType.DOWNLOAD)
|
||||||
|
@GetMapping("/image/download")
|
||||||
|
@ApiOperation("下载设备图片")
|
||||||
|
@ApiImplicitParam(name = "id", value = "被检设备id", required = true)
|
||||||
|
public void downloadImage(@RequestParam("id") String id, HttpServletResponse response) {
|
||||||
|
pqDevService.downloadImage(id, response);
|
||||||
|
}
|
||||||
|
|
||||||
@OperateInfo(operateType = OperateType.DELETE)
|
@OperateInfo(operateType = OperateType.DELETE)
|
||||||
@PostMapping("/delete")
|
@PostMapping("/delete")
|
||||||
@ApiOperation("删除被检设备")
|
@ApiOperation("删除被检设备")
|
||||||
|
|||||||
@@ -86,8 +86,45 @@
|
|||||||
WHERE id = #{planId}
|
WHERE id = #{planId}
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
<sql id="DevColumnsNoImage">
|
||||||
|
dev.Id,
|
||||||
|
dev.Name,
|
||||||
|
dev.Pattern,
|
||||||
|
dev.Dev_Type,
|
||||||
|
dev.Manufacturer,
|
||||||
|
dev.Create_Date,
|
||||||
|
dev.Create_Id,
|
||||||
|
dev.Hardware_Version,
|
||||||
|
dev.Software_Version,
|
||||||
|
dev.Protocol,
|
||||||
|
dev.IP,
|
||||||
|
dev.Port,
|
||||||
|
dev.Encryption_Flag,
|
||||||
|
dev.Series,
|
||||||
|
dev.Dev_Key,
|
||||||
|
dev.Sample_Id,
|
||||||
|
dev.Arrived_Date,
|
||||||
|
dev.City_Name,
|
||||||
|
dev.Gd_Name,
|
||||||
|
dev.Sub_Name,
|
||||||
|
dev.Report_Path,
|
||||||
|
dev.Plan_Id,
|
||||||
|
dev.Factor_Flag,
|
||||||
|
dev.Preinvestment_Plan,
|
||||||
|
dev.Delegate,
|
||||||
|
dev.Inspect_Channel,
|
||||||
|
dev.Inspect_Date,
|
||||||
|
dev.Harm_Sys_Id,
|
||||||
|
dev.Import_Flag,
|
||||||
|
dev.State,
|
||||||
|
dev.Create_By,
|
||||||
|
dev.Create_Time,
|
||||||
|
dev.Update_By,
|
||||||
|
dev.Update_Time
|
||||||
|
</sql>
|
||||||
|
|
||||||
<select id="selectByQueryParam" resultType="com.njcn.gather.device.pojo.vo.PqDevVO">
|
<select id="selectByQueryParam" resultType="com.njcn.gather.device.pojo.vo.PqDevVO">
|
||||||
SELECT dev.*,dev_sub.* FROM pq_dev dev
|
SELECT <include refid="DevColumnsNoImage"/>, dev_sub.* FROM pq_dev dev
|
||||||
left JOIN pq_dev_sub dev_sub ON dev.Id = dev_sub.Dev_Id
|
left JOIN pq_dev_sub dev_sub ON dev.Id = dev_sub.Dev_Id
|
||||||
<where>
|
<where>
|
||||||
dev.state = 1
|
dev.state = 1
|
||||||
@@ -124,7 +161,7 @@
|
|||||||
</select>
|
</select>
|
||||||
|
|
||||||
<select id="listByDevIds" resultType="com.njcn.gather.device.pojo.vo.PqDevVO">
|
<select id="listByDevIds" resultType="com.njcn.gather.device.pojo.vo.PqDevVO">
|
||||||
SELECT dev.*, dev_sub.*
|
SELECT <include refid="DevColumnsNoImage"/>, dev_sub.*
|
||||||
FROM pq_dev dev
|
FROM pq_dev dev
|
||||||
left JOIN pq_dev_sub dev_sub ON dev.Id = dev_sub.Dev_Id
|
left JOIN pq_dev_sub dev_sub ON dev.Id = dev_sub.Dev_Id
|
||||||
WHERE dev.state = 1
|
WHERE dev.state = 1
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ public enum CheckStateEnum {
|
|||||||
CHECKING("检测中", 1),
|
CHECKING("检测中", 1),
|
||||||
CHECKED("检测完成", 2),
|
CHECKED("检测完成", 2),
|
||||||
/**
|
/**
|
||||||
* 检测计划没有该状态,只有未检、检测中、检测完成三种状态。被检设备有这种状态
|
* 检测计划没有归档状态,只有未检、检测中、检测完成三种状态。被检设备有归档状态
|
||||||
*/
|
*/
|
||||||
DOCUMENTED("归档", 3);
|
DOCUMENTED("归档", 3);
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import io.swagger.annotations.ApiModelProperty;
|
|||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
import org.hibernate.validator.constraints.Range;
|
import org.hibernate.validator.constraints.Range;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
import javax.validation.Valid;
|
import javax.validation.Valid;
|
||||||
import javax.validation.constraints.*;
|
import javax.validation.constraints.*;
|
||||||
@@ -136,6 +137,9 @@ public class PqDevParam {
|
|||||||
@ApiModelProperty("是否为导入设备")
|
@ApiModelProperty("是否为导入设备")
|
||||||
private Integer importFlag;
|
private Integer importFlag;
|
||||||
|
|
||||||
|
@ApiModelProperty("设备图片")
|
||||||
|
private MultipartFile image;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 更新操作实体
|
* 更新操作实体
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package com.njcn.gather.device.pojo.po;
|
|||||||
import com.baomidou.mybatisplus.annotation.FieldFill;
|
import com.baomidou.mybatisplus.annotation.FieldFill;
|
||||||
import com.baomidou.mybatisplus.annotation.TableField;
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
import com.baomidou.mybatisplus.annotation.TableName;
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||||
@@ -184,6 +185,9 @@ public class PqDev extends BaseEntity implements Serializable {
|
|||||||
*/
|
*/
|
||||||
private Integer importFlag;
|
private Integer importFlag;
|
||||||
|
|
||||||
|
@JsonIgnore
|
||||||
|
private byte[] image;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 状态:0-删除 1-正常
|
* 状态:0-删除 1-正常
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -122,4 +122,10 @@ public class PqDevVO extends PqDev {
|
|||||||
* 检测点结果
|
* 检测点结果
|
||||||
*/
|
*/
|
||||||
private List<Integer> monitorResults;
|
private List<Integer> monitorResults;
|
||||||
|
|
||||||
|
private Boolean hasImage;
|
||||||
|
|
||||||
|
private String imageBase64;
|
||||||
|
|
||||||
|
private String imageContentType;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -96,6 +96,14 @@ public interface IPqDevService extends IService<PqDev> {
|
|||||||
*/
|
*/
|
||||||
PqDevVO getPqDevById(String id);
|
PqDevVO getPqDevById(String id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 下载设备图片
|
||||||
|
*
|
||||||
|
* @param id 设备id
|
||||||
|
* @param response 响应
|
||||||
|
*/
|
||||||
|
void downloadImage(String id, HttpServletResponse response);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取装置信息和装置下监测点信息
|
* 获取装置信息和装置下监测点信息
|
||||||
*
|
*
|
||||||
@@ -121,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);
|
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);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 比对式-修改设备状态
|
* 比对式-修改设备状态
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import cn.afterturn.easypoi.excel.entity.ExportParams;
|
|||||||
import cn.afterturn.easypoi.excel.entity.ImportParams;
|
import cn.afterturn.easypoi.excel.entity.ImportParams;
|
||||||
import cn.afterturn.easypoi.excel.entity.result.ExcelImportResult;
|
import cn.afterturn.easypoi.excel.entity.result.ExcelImportResult;
|
||||||
import cn.hutool.core.bean.BeanUtil;
|
import cn.hutool.core.bean.BeanUtil;
|
||||||
|
import cn.hutool.core.bean.copier.CopyOptions;
|
||||||
import cn.hutool.core.collection.CollUtil;
|
import cn.hutool.core.collection.CollUtil;
|
||||||
import cn.hutool.core.collection.CollectionUtil;
|
import cn.hutool.core.collection.CollectionUtil;
|
||||||
import cn.hutool.core.util.ObjectUtil;
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
@@ -37,6 +38,7 @@ import com.njcn.gather.device.pojo.po.PqDevSub;
|
|||||||
import com.njcn.gather.device.pojo.vo.*;
|
import com.njcn.gather.device.pojo.vo.*;
|
||||||
import com.njcn.gather.device.service.IPqDevService;
|
import com.njcn.gather.device.service.IPqDevService;
|
||||||
import com.njcn.gather.device.service.IPqDevSubService;
|
import com.njcn.gather.device.service.IPqDevSubService;
|
||||||
|
import com.njcn.gather.device.util.PqDevImageSupport;
|
||||||
import com.njcn.gather.monitor.pojo.po.PqMonitor;
|
import com.njcn.gather.monitor.pojo.po.PqMonitor;
|
||||||
import com.njcn.gather.monitor.pojo.vo.PqMonitorExcel;
|
import com.njcn.gather.monitor.pojo.vo.PqMonitorExcel;
|
||||||
import com.njcn.gather.monitor.service.IPqMonitorService;
|
import com.njcn.gather.monitor.service.IPqMonitorService;
|
||||||
@@ -71,6 +73,7 @@ import org.springframework.transaction.annotation.Transactional;
|
|||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.io.IOException;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
@@ -138,7 +141,8 @@ public class PqDevServiceImpl extends ServiceImpl<PqDevMapper, PqDev> implements
|
|||||||
this.checkRepeat(pqDevParam, false);
|
this.checkRepeat(pqDevParam, false);
|
||||||
|
|
||||||
PqDev pqDev = new PqDev();
|
PqDev pqDev = new PqDev();
|
||||||
BeanUtil.copyProperties(pqDevParam, pqDev);
|
BeanUtil.copyProperties(pqDevParam, pqDev, CopyOptions.create().setIgnoreProperties("image"));
|
||||||
|
fillImage(pqDev, pqDevParam);
|
||||||
String currrentScene = sysTestConfigService.getCurrrentScene();
|
String currrentScene = sysTestConfigService.getCurrrentScene();
|
||||||
this.checkParams(pqDev, currrentScene);
|
this.checkParams(pqDev, currrentScene);
|
||||||
|
|
||||||
@@ -169,6 +173,19 @@ public class PqDevServiceImpl extends ServiceImpl<PqDevMapper, PqDev> implements
|
|||||||
return this.save(pqDev);
|
return this.save(pqDev);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void fillImage(PqDev pqDev, PqDevParam pqDevParam) {
|
||||||
|
try {
|
||||||
|
byte[] image = PqDevImageSupport.processUpload(pqDevParam.getImage());
|
||||||
|
if (image != null) {
|
||||||
|
pqDev.setImage(image);
|
||||||
|
}
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
throw new BusinessException(CommonResponseEnum.FAIL, e.getMessage());
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new BusinessException(CommonResponseEnum.FAIL, "图片处理失败");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 校验参数
|
* 校验参数
|
||||||
*
|
*
|
||||||
@@ -211,7 +228,8 @@ public class PqDevServiceImpl extends ServiceImpl<PqDevMapper, PqDev> implements
|
|||||||
this.checkRepeat(updateParam, true);
|
this.checkRepeat(updateParam, true);
|
||||||
|
|
||||||
PqDev pqDev = new PqDev();
|
PqDev pqDev = new PqDev();
|
||||||
BeanUtil.copyProperties(updateParam, pqDev);
|
BeanUtil.copyProperties(updateParam, pqDev, CopyOptions.create().setIgnoreProperties("image"));
|
||||||
|
fillImage(pqDev, updateParam);
|
||||||
String currrentScene = sysTestConfigService.getCurrrentScene();
|
String currrentScene = sysTestConfigService.getCurrrentScene();
|
||||||
this.checkParams(pqDev, currrentScene);
|
this.checkParams(pqDev, currrentScene);
|
||||||
|
|
||||||
@@ -278,6 +296,8 @@ public class PqDevServiceImpl extends ServiceImpl<PqDevMapper, PqDev> implements
|
|||||||
@Override
|
@Override
|
||||||
public List<Map<String, Object>> listUnbound(String pattern) {
|
public List<Map<String, Object>> listUnbound(String pattern) {
|
||||||
List<PqDev> pqDevList = this.lambdaQuery()
|
List<PqDev> pqDevList = this.lambdaQuery()
|
||||||
|
.select(PqDev::getId, PqDev::getName, PqDev::getDevType, PqDev::getManufacturer,
|
||||||
|
PqDev::getCityName, PqDev::getGdName, PqDev::getSubName)
|
||||||
.eq(PqDev::getPattern, pattern)
|
.eq(PqDev::getPattern, pattern)
|
||||||
.eq(PqDev::getState, DataStateEnum.ENABLE.getCode())
|
.eq(PqDev::getState, DataStateEnum.ENABLE.getCode())
|
||||||
.isNull(PqDev::getPlanId)
|
.isNull(PqDev::getPlanId)
|
||||||
@@ -347,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());
|
List<String> notUnchecked = list.stream().filter(x -> !CheckStateEnum.UNCHECKED.getValue().equals(x.getCheckState())).map(PqDevSub::getDevId).distinct().collect(Collectors.toList());
|
||||||
|
|
||||||
if (CollUtil.isNotEmpty(notUnchecked)) {
|
if (CollUtil.isNotEmpty(notUnchecked)) {
|
||||||
List<String> unchecked = list.stream().filter(x -> CheckStateEnum.UNCHECKED.getValue().equals(x.getCheckState())).map(PqDevSub::getDevId).distinct().collect(Collectors.toList());
|
boolean allArchived = list.stream().allMatch(x -> x.getCheckState() != null && x.getCheckState() >= CheckStateEnum.DOCUMENTED.getValue());
|
||||||
//计划未检测
|
return allArchived ? CheckStateEnum.CHECKED.getValue() : CheckStateEnum.CHECKING.getValue();
|
||||||
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();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return CheckStateEnum.UNCHECKED.getValue();
|
return CheckStateEnum.UNCHECKED.getValue();
|
||||||
@@ -392,6 +396,10 @@ public class PqDevServiceImpl extends ServiceImpl<PqDevMapper, PqDev> implements
|
|||||||
@Override
|
@Override
|
||||||
public PqDevVO getPqDevById(String id) {
|
public PqDevVO getPqDevById(String id) {
|
||||||
PqDevVO pqDevVO = this.baseMapper.selectByDevId(id);
|
PqDevVO pqDevVO = this.baseMapper.selectByDevId(id);
|
||||||
|
if (ObjectUtil.isNull(pqDevVO)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
setImageEchoFields(pqDevVO);
|
||||||
if (StrUtil.isNotBlank(pqDevVO.getSeries())) {
|
if (StrUtil.isNotBlank(pqDevVO.getSeries())) {
|
||||||
pqDevVO.setSeries(EncryptionUtil.decoderString(1, pqDevVO.getSeries()));
|
pqDevVO.setSeries(EncryptionUtil.decoderString(1, pqDevVO.getSeries()));
|
||||||
}
|
}
|
||||||
@@ -420,6 +428,37 @@ public class PqDevServiceImpl extends ServiceImpl<PqDevMapper, PqDev> implements
|
|||||||
return pqDevVO;
|
return pqDevVO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void downloadImage(String id, HttpServletResponse response) {
|
||||||
|
PqDev pqDev = this.getById(id);
|
||||||
|
if (ObjectUtil.isNull(pqDev) || pqDev.getImage() == null || pqDev.getImage().length == 0) {
|
||||||
|
throw new BusinessException(CommonResponseEnum.FAIL, "设备图片不存在");
|
||||||
|
}
|
||||||
|
String contentType = PqDevImageSupport.detectContentType(pqDev.getImage());
|
||||||
|
String filename = "device-image-" + id + "." + PqDevImageSupport.getExtension(contentType);
|
||||||
|
response.setContentType(contentType);
|
||||||
|
response.setContentLength(pqDev.getImage().length);
|
||||||
|
response.setHeader("Content-Disposition", "attachment; filename=\"" + filename + "\"");
|
||||||
|
try {
|
||||||
|
response.getOutputStream().write(pqDev.getImage());
|
||||||
|
response.flushBuffer();
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new BusinessException(CommonResponseEnum.FAIL, "设备图片下载失败");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setImageEchoFields(PqDevVO pqDevVO) {
|
||||||
|
try {
|
||||||
|
PqDevImageSupport.ImageEchoPayload payload = PqDevImageSupport.buildEchoPayload(pqDevVO.getImage());
|
||||||
|
pqDevVO.setHasImage(payload.isHasImage());
|
||||||
|
pqDevVO.setImageBase64(payload.getImageBase64());
|
||||||
|
pqDevVO.setImageContentType(payload.getImageContentType());
|
||||||
|
pqDevVO.setImage(null);
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
throw new BusinessException(CommonResponseEnum.FAIL, e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取查询条件wrapper
|
* 获取查询条件wrapper
|
||||||
@@ -429,6 +468,7 @@ public class PqDevServiceImpl extends ServiceImpl<PqDevMapper, PqDev> implements
|
|||||||
*/
|
*/
|
||||||
private Wrapper getQueryWrapper(PqDevParam.QueryParam queryParam) {
|
private Wrapper getQueryWrapper(PqDevParam.QueryParam queryParam) {
|
||||||
QueryWrapper<PqDev> queryWrapper = new QueryWrapper<>();
|
QueryWrapper<PqDev> queryWrapper = new QueryWrapper<>();
|
||||||
|
queryWrapper.select("pq_dev.Id");
|
||||||
if (ObjectUtil.isNotNull(queryParam)) {
|
if (ObjectUtil.isNotNull(queryParam)) {
|
||||||
queryWrapper
|
queryWrapper
|
||||||
.like(StrUtil.isNotBlank(queryParam.getName()), "pq_dev.name", queryParam.getName())
|
.like(StrUtil.isNotBlank(queryParam.getName()), "pq_dev.name", queryParam.getName())
|
||||||
@@ -491,6 +531,45 @@ public class PqDevServiceImpl extends ServiceImpl<PqDevMapper, PqDev> implements
|
|||||||
return preDetections;
|
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
|
@Override
|
||||||
public boolean updateResult(List<String> ids, List<String> adType, String code, String userId, Float temperature, Float humidity, boolean updateCheckNum) {
|
public boolean updateResult(List<String> ids, List<String> adType, String code, String userId, Float temperature, Float humidity, boolean updateCheckNum) {
|
||||||
@@ -534,6 +613,21 @@ public class PqDevServiceImpl extends ServiceImpl<PqDevMapper, PqDev> implements
|
|||||||
}
|
}
|
||||||
wrapper.set(PqDevSub::getReportState, DevReportStateEnum.NOT_GENERATED.getValue());
|
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)
|
wrapper.set(PqDevSub::getRecheckNum, i)
|
||||||
.set(PqDevSub::getCheckState, checkState);
|
.set(PqDevSub::getCheckState, checkState);
|
||||||
pqDevSubService.update(wrapper);
|
pqDevSubService.update(wrapper);
|
||||||
@@ -552,16 +646,12 @@ public class PqDevServiceImpl extends ServiceImpl<PqDevMapper, PqDev> implements
|
|||||||
this.baseMapper.updatePlanCheckResult(pqDevVo.getPlanId(), CheckResultEnum.ACCORD.getValue());
|
this.baseMapper.updatePlanCheckResult(pqDevVo.getPlanId(), CheckResultEnum.ACCORD.getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
set = pqDevVOList.stream().map(PqDevVO::getCheckState).collect(Collectors.toSet());
|
boolean allUnchecked = pqDevVOList.stream().allMatch(obj -> CheckStateEnum.UNCHECKED.getValue().equals(obj.getCheckState()));
|
||||||
if (set.contains(CheckStateEnum.UNCHECKED.getValue())) {
|
boolean allArchived = pqDevVOList.stream().allMatch(obj -> obj.getCheckState() != null && obj.getCheckState() >= CheckStateEnum.DOCUMENTED.getValue());
|
||||||
this.baseMapper.updatePlanTestState(pqDevVo.getPlanId(), CheckStateEnum.CHECKING.getValue());
|
if (allUnchecked) {
|
||||||
} else {
|
this.baseMapper.updatePlanTestState(pqDevVo.getPlanId(), CheckStateEnum.UNCHECKED.getValue());
|
||||||
if (checkState.equals(CheckStateEnum.DOCUMENTED.getValue())) {
|
} else if (allArchived) {
|
||||||
long count = pqDevVOList.stream().filter(obj -> !CheckStateEnum.DOCUMENTED.getValue().equals(obj.getCheckState())).count();
|
this.baseMapper.updatePlanTestState(pqDevVo.getPlanId(), CheckStateEnum.CHECKED.getValue());
|
||||||
if (count == 0) {
|
|
||||||
// 如果非归档状态的设备数量为0,则更新计划已完成
|
|
||||||
this.baseMapper.finishPlan(pqDevVo.getPlanId());
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
this.baseMapper.updatePlanTestState(pqDevVo.getPlanId(), CheckStateEnum.CHECKING.getValue());
|
this.baseMapper.updatePlanTestState(pqDevVo.getPlanId(), CheckStateEnum.CHECKING.getValue());
|
||||||
}
|
}
|
||||||
@@ -569,7 +659,6 @@ public class PqDevServiceImpl extends ServiceImpl<PqDevMapper, PqDev> implements
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -621,7 +710,7 @@ public class PqDevServiceImpl extends ServiceImpl<PqDevMapper, PqDev> implements
|
|||||||
List<PqDevVO> pqDevVOList = this.baseMapper.selectByQueryParam(param);
|
List<PqDevVO> pqDevVOList = this.baseMapper.selectByQueryParam(param);
|
||||||
|
|
||||||
if (CollUtil.isNotEmpty(pqDevVOList)) {
|
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()) {
|
if (checkState == CheckStateEnum.CHECKED.getValue()) {
|
||||||
set.add(checkResult);
|
set.add(checkResult);
|
||||||
}
|
}
|
||||||
@@ -638,20 +727,22 @@ public class PqDevServiceImpl extends ServiceImpl<PqDevMapper, PqDev> implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
set = pqDevVOList.stream().map(PqDevVO::getCheckState).collect(Collectors.toSet());
|
boolean allUnchecked = pqDevVOList.stream().allMatch(obj -> CheckStateEnum.UNCHECKED.getValue().equals(obj.getCheckState()));
|
||||||
if (set.contains(CheckStateEnum.UNCHECKED.getValue())) {
|
boolean allArchived = pqDevVOList.stream().allMatch(obj -> obj.getCheckState() != null && obj.getCheckState() >= CheckStateEnum.DOCUMENTED.getValue());
|
||||||
this.baseMapper.updatePlanTestState(planId, CheckStateEnum.CHECKING.getValue());
|
if (allUnchecked) {
|
||||||
} else if (set.contains(CheckStateEnum.CHECKING.getValue())) {
|
this.baseMapper.updatePlanTestState(planId, CheckStateEnum.UNCHECKED.getValue());
|
||||||
this.baseMapper.updatePlanTestState(planId, CheckStateEnum.CHECKING.getValue());
|
} else if (allArchived) {
|
||||||
} else {
|
|
||||||
this.baseMapper.updatePlanTestState(planId, CheckStateEnum.CHECKED.getValue());
|
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) {
|
private void saveCheckHistory(PqDevVO pqDevVo, Integer recheckNum, Integer checkState, String userId) {
|
||||||
if (ObjectUtil.isNull(pqDevVo)
|
if (ObjectUtil.isNull(pqDevVo)
|
||||||
|| (!CheckStateEnum.CHECKED.getValue().equals(checkState) && !CheckStateEnum.DOCUMENTED.getValue().equals(checkState))) {
|
|| checkState == null
|
||||||
|
|| checkState < CheckStateEnum.CHECKED.getValue()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
AdPlan plan = adPlanMapper.selectById(pqDevVo.getPlanId());
|
AdPlan plan = adPlanMapper.selectById(pqDevVo.getPlanId());
|
||||||
@@ -667,7 +758,8 @@ public class PqDevServiceImpl extends ServiceImpl<PqDevMapper, PqDev> implements
|
|||||||
private void saveCheckHistory(String devId, String userId) {
|
private void saveCheckHistory(String devId, String userId) {
|
||||||
PqDevVO pqDevVo = this.baseMapper.selectByDevId(devId);
|
PqDevVO pqDevVo = this.baseMapper.selectByDevId(devId);
|
||||||
if (ObjectUtil.isNull(pqDevVo)
|
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;
|
return;
|
||||||
}
|
}
|
||||||
AdPlan plan = adPlanMapper.selectById(pqDevVo.getPlanId());
|
AdPlan plan = adPlanMapper.selectById(pqDevVo.getPlanId());
|
||||||
@@ -1659,7 +1751,10 @@ public class PqDevServiceImpl extends ServiceImpl<PqDevMapper, PqDev> implements
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<String, List<String>> listSelectOptions(String pattern) {
|
public Map<String, List<String>> listSelectOptions(String pattern) {
|
||||||
List<PqDev> pqDevList = this.lambdaQuery().eq(PqDev::getPattern, pattern)
|
List<PqDev> pqDevList = this.lambdaQuery()
|
||||||
|
.select(PqDev::getCityName, PqDev::getGdName, PqDev::getSubName,
|
||||||
|
PqDev::getHardwareVersion, PqDev::getSoftwareVersion)
|
||||||
|
.eq(PqDev::getPattern, pattern)
|
||||||
.eq(PqDev::getState, DataStateEnum.ENABLE.getCode())
|
.eq(PqDev::getState, DataStateEnum.ENABLE.getCode())
|
||||||
.list();
|
.list();
|
||||||
String[] devKeyArray = new String[]{"cityName", "gdName", "subName", "hardwareVersion", "softwareVersion"};
|
String[] devKeyArray = new String[]{"cityName", "gdName", "subName", "hardwareVersion", "softwareVersion"};
|
||||||
|
|||||||
@@ -0,0 +1,181 @@
|
|||||||
|
package com.njcn.gather.device.util;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import javax.imageio.IIOImage;
|
||||||
|
import javax.imageio.ImageIO;
|
||||||
|
import javax.imageio.ImageWriteParam;
|
||||||
|
import javax.imageio.ImageWriter;
|
||||||
|
import javax.imageio.stream.ImageOutputStream;
|
||||||
|
import java.awt.Graphics2D;
|
||||||
|
import java.awt.RenderingHints;
|
||||||
|
import java.awt.image.BufferedImage;
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.util.Base64;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
|
public final class PqDevImageSupport {
|
||||||
|
|
||||||
|
private static final long MAX_FILE_SIZE = 10L * 1024L * 1024L;
|
||||||
|
private static final int MAX_EDGE = 1600;
|
||||||
|
private static final float JPEG_QUALITY = 0.82f;
|
||||||
|
|
||||||
|
private PqDevImageSupport() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ImageEchoPayload buildEchoPayload(byte[] imageBytes) {
|
||||||
|
if (imageBytes == null || imageBytes.length == 0) {
|
||||||
|
return new ImageEchoPayload(false, null, null);
|
||||||
|
}
|
||||||
|
return new ImageEchoPayload(true, Base64.getEncoder().encodeToString(imageBytes), detectContentType(imageBytes));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String detectContentType(byte[] imageBytes) {
|
||||||
|
if (imageBytes == null || imageBytes.length < 4) {
|
||||||
|
throw new IllegalArgumentException("图片内容无效");
|
||||||
|
}
|
||||||
|
if (isPng(imageBytes)) {
|
||||||
|
return "image/png";
|
||||||
|
}
|
||||||
|
if (isJpeg(imageBytes)) {
|
||||||
|
return "image/jpeg";
|
||||||
|
}
|
||||||
|
throw new IllegalArgumentException("仅支持 JPG、PNG 图片");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static byte[] processUpload(MultipartFile image) throws IOException {
|
||||||
|
if (image == null || image.isEmpty()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (image.getSize() > MAX_FILE_SIZE) {
|
||||||
|
throw new IllegalArgumentException("图片大小不能超过 10MB");
|
||||||
|
}
|
||||||
|
|
||||||
|
String normalizedName = normalize(image.getOriginalFilename());
|
||||||
|
String normalizedContentType = normalize(image.getContentType());
|
||||||
|
boolean allowedType = normalizedContentType.equals("image/jpeg")
|
||||||
|
|| normalizedContentType.equals("image/png")
|
||||||
|
|| normalizedName.endsWith(".jpg")
|
||||||
|
|| normalizedName.endsWith(".jpeg")
|
||||||
|
|| normalizedName.endsWith(".png");
|
||||||
|
if (!allowedType) {
|
||||||
|
throw new IllegalArgumentException("仅支持 JPG、PNG 图片");
|
||||||
|
}
|
||||||
|
|
||||||
|
byte[] originalBytes = image.getBytes();
|
||||||
|
String contentType = detectContentType(originalBytes);
|
||||||
|
BufferedImage source;
|
||||||
|
try (InputStream inputStream = image.getInputStream()) {
|
||||||
|
source = ImageIO.read(inputStream);
|
||||||
|
}
|
||||||
|
if (source == null) {
|
||||||
|
throw new IllegalArgumentException("图片内容无效");
|
||||||
|
}
|
||||||
|
|
||||||
|
BufferedImage target = scaleIfNeeded(source);
|
||||||
|
if ("image/png".equals(contentType)) {
|
||||||
|
return writePng(target);
|
||||||
|
}
|
||||||
|
return writeJpeg(target);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getExtension(String contentType) {
|
||||||
|
return "image/png".equals(contentType) ? "png" : "jpg";
|
||||||
|
}
|
||||||
|
|
||||||
|
private static BufferedImage scaleIfNeeded(BufferedImage source) {
|
||||||
|
int width = source.getWidth();
|
||||||
|
int height = source.getHeight();
|
||||||
|
int max = Math.max(width, height);
|
||||||
|
if (max <= MAX_EDGE) {
|
||||||
|
return source;
|
||||||
|
}
|
||||||
|
|
||||||
|
double scale = (double) MAX_EDGE / max;
|
||||||
|
int targetWidth = Math.max(1, (int) Math.round(width * scale));
|
||||||
|
int targetHeight = Math.max(1, (int) Math.round(height * scale));
|
||||||
|
int type = source.getType() == BufferedImage.TYPE_CUSTOM ? BufferedImage.TYPE_INT_ARGB : source.getType();
|
||||||
|
BufferedImage target = new BufferedImage(targetWidth, targetHeight, type);
|
||||||
|
Graphics2D graphics = target.createGraphics();
|
||||||
|
try {
|
||||||
|
graphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
|
||||||
|
graphics.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
|
||||||
|
graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
||||||
|
graphics.drawImage(source, 0, 0, targetWidth, targetHeight, null);
|
||||||
|
} finally {
|
||||||
|
graphics.dispose();
|
||||||
|
}
|
||||||
|
return target;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static byte[] writePng(BufferedImage image) throws IOException {
|
||||||
|
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||||
|
ImageIO.write(image, "png", outputStream);
|
||||||
|
return outputStream.toByteArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static byte[] writeJpeg(BufferedImage image) throws IOException {
|
||||||
|
BufferedImage rgbImage = new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_INT_RGB);
|
||||||
|
Graphics2D graphics = rgbImage.createGraphics();
|
||||||
|
try {
|
||||||
|
graphics.drawImage(image, 0, 0, null);
|
||||||
|
} finally {
|
||||||
|
graphics.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
Iterator<ImageWriter> writers = ImageIO.getImageWritersByFormatName("jpg");
|
||||||
|
if (!writers.hasNext()) {
|
||||||
|
throw new IOException("未找到 JPG 图片编码器");
|
||||||
|
}
|
||||||
|
ImageWriter writer = writers.next();
|
||||||
|
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||||
|
try (ImageOutputStream imageOutputStream = ImageIO.createImageOutputStream(outputStream)) {
|
||||||
|
writer.setOutput(imageOutputStream);
|
||||||
|
ImageWriteParam writeParam = writer.getDefaultWriteParam();
|
||||||
|
if (writeParam.canWriteCompressed()) {
|
||||||
|
writeParam.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
|
||||||
|
writeParam.setCompressionQuality(JPEG_QUALITY);
|
||||||
|
}
|
||||||
|
writer.write(null, new IIOImage(rgbImage, null, null), writeParam);
|
||||||
|
} finally {
|
||||||
|
writer.dispose();
|
||||||
|
}
|
||||||
|
return outputStream.toByteArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean isPng(byte[] imageBytes) {
|
||||||
|
return imageBytes.length >= 8
|
||||||
|
&& (imageBytes[0] & 0xFF) == 0x89
|
||||||
|
&& imageBytes[1] == 0x50
|
||||||
|
&& imageBytes[2] == 0x4E
|
||||||
|
&& imageBytes[3] == 0x47
|
||||||
|
&& imageBytes[4] == 0x0D
|
||||||
|
&& imageBytes[5] == 0x0A
|
||||||
|
&& imageBytes[6] == 0x1A
|
||||||
|
&& imageBytes[7] == 0x0A;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean isJpeg(byte[] imageBytes) {
|
||||||
|
return imageBytes.length >= 3
|
||||||
|
&& (imageBytes[0] & 0xFF) == 0xFF
|
||||||
|
&& (imageBytes[1] & 0xFF) == 0xD8
|
||||||
|
&& (imageBytes[2] & 0xFF) == 0xFF;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String normalize(String value) {
|
||||||
|
return value == null ? "" : value.toLowerCase(Locale.ROOT);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
public static class ImageEchoPayload {
|
||||||
|
private boolean hasImage;
|
||||||
|
private String imageBase64;
|
||||||
|
private String imageContentType;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -99,7 +99,7 @@ public class PqMonitorServiceImpl extends ServiceImpl<PqMonitorMapper, PqMonitor
|
|||||||
this.baseMapper.updateDeviceReportRState(devId, DevReportStateEnum.NOT_GENERATED.getValue());
|
this.baseMapper.updateDeviceReportRState(devId, DevReportStateEnum.NOT_GENERATED.getValue());
|
||||||
}
|
}
|
||||||
if (enableCheckMonitorList.size() > checkedMonitorList.size() && checkedMonitorList.size() > 0) {
|
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());
|
this.baseMapper.updateDeviceReportRState(devId, DevReportStateEnum.NOT_GENERATED.getValue());
|
||||||
}
|
}
|
||||||
if (enableCheckMonitorList.size() > 0 && checkedMonitorList.size() == 0) {
|
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> devSubList = this.baseMapper.listDevSubByPlanId(plan.getId());
|
||||||
|
|
||||||
List<PqDevSub> checkedDevSubList = devSubList.stream().filter(pqDevSub -> pqDevSub.getCheckState() == CheckStateEnum.CHECKED.getValue()).collect(Collectors.toList());
|
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());
|
boolean allUnchecked = devSubList.stream().allMatch(pqDevSub -> CheckStateEnum.UNCHECKED.getValue().equals(pqDevSub.getCheckState()));
|
||||||
if (checkedDevSubList.size() == devSubList.size() && devSubList.size() > 0) {
|
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());
|
this.baseMapper.updatePlanCheckState(plan.getId(), CheckStateEnum.CHECKED.getValue());
|
||||||
} else if (checkedDevSubList.size() > 0 || checkingDevSubList.size() > 0) {
|
} else if (allUnchecked) {
|
||||||
this.baseMapper.updatePlanCheckState(plan.getId(), CheckStateEnum.CHECKING.getValue());
|
|
||||||
} else {
|
|
||||||
this.baseMapper.updatePlanCheckState(plan.getId(), CheckStateEnum.UNCHECKED.getValue());
|
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());
|
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)) {
|
if (checkedNumList.containsAll(allNumList)) {
|
||||||
return CheckStateEnum.CHECKED.getValue();
|
return CheckStateEnum.CHECKED.getValue();
|
||||||
} else {
|
|
||||||
if (checkedNumList.size() > 0) {
|
|
||||||
return CheckStateEnum.CHECKING.getValue();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return CheckStateEnum.UNCHECKED.getValue();
|
return CheckStateEnum.UNCHECKED.getValue();
|
||||||
|
|||||||
@@ -36,6 +36,11 @@ public class PlanStatisticsVO {
|
|||||||
*/
|
*/
|
||||||
private Integer uncheckedDeviceCount;
|
private Integer uncheckedDeviceCount;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检测中设备总数。
|
||||||
|
*/
|
||||||
|
private Integer checkingDeviceCount;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 第一次检测合格的设备数量。
|
* 第一次检测合格的设备数量。
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -436,21 +436,15 @@ public class AsyncPlanHandler {
|
|||||||
planIds.add(planId);
|
planIds.add(planId);
|
||||||
List<String> devIds = pqDevService.lambdaQuery().in(PqDev::getPlanId, planIds).list().stream().map(PqDev::getId).collect(Collectors.toList());
|
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();
|
List<PqDevSub> devSubs = pqDevSubService.lambdaQuery().in(PqDevSub::getDevId, devIds).list();
|
||||||
long checkedCount = devSubs.stream().filter(sub -> sub.getCheckState().equals(CheckStateEnum.CHECKED.getValue())).count();
|
boolean allUnchecked = devSubs.stream().allMatch(sub -> CheckStateEnum.UNCHECKED.getValue().equals(sub.getCheckState()));
|
||||||
if (checkedCount > 0) {
|
boolean allArchived = devSubs.stream().allMatch(sub -> sub.getCheckState() != null && sub.getCheckState() >= CheckStateEnum.DOCUMENTED.getValue());
|
||||||
plan.setTestState(CheckStateEnum.CHECKING.getValue());
|
if (allUnchecked) {
|
||||||
// 都已检测完成
|
|
||||||
if (checkedCount == devSubs.size()) {
|
|
||||||
plan.setTestState(CheckStateEnum.CHECKED.getValue());
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
plan.setTestState(CheckStateEnum.UNCHECKED.getValue());
|
plan.setTestState(CheckStateEnum.UNCHECKED.getValue());
|
||||||
// 是否有检测中
|
} else if (allArchived && !devSubs.isEmpty()) {
|
||||||
long checkingCount = devSubs.stream().filter(sub -> sub.getCheckState().equals(CheckStateEnum.CHECKING.getValue())).count();
|
plan.setTestState(CheckStateEnum.CHECKED.getValue());
|
||||||
if (checkingCount > 0) {
|
} else {
|
||||||
plan.setTestState(CheckStateEnum.CHECKING.getValue());
|
plan.setTestState(CheckStateEnum.CHECKING.getValue());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
adPlanService.updateById(plan);
|
adPlanService.updateById(plan);
|
||||||
LocalDateTime endTime = LocalDateTime.now();
|
LocalDateTime endTime = LocalDateTime.now();
|
||||||
log.info("数据合并完成,耗时:{}s", Duration.between(startTime, endTime).getSeconds());
|
log.info("数据合并完成,耗时:{}s", Duration.between(startTime, endTime).getSeconds());
|
||||||
|
|||||||
@@ -216,7 +216,7 @@ public class AdPlanServiceImpl extends ServiceImpl<AdPlanMapper, AdPlan> impleme
|
|||||||
}
|
}
|
||||||
List<PqDevVO> pqDevVOList = pqDevMapper.selectByQueryParam(queryParam1);
|
List<PqDevVO> pqDevVOList = pqDevMapper.selectByQueryParam(queryParam1);
|
||||||
if (CollUtil.isNotEmpty(pqDevVOList)) {
|
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());
|
adPlanVO.setProgress((float) count / pqDevVOList.size());
|
||||||
} else {
|
} else {
|
||||||
adPlanVO.setProgress(0.0f);
|
adPlanVO.setProgress(0.0f);
|
||||||
@@ -405,10 +405,13 @@ public class AdPlanServiceImpl extends ServiceImpl<AdPlanMapper, AdPlan> impleme
|
|||||||
PqDevParam.QueryParam queryParam = new PqDevParam.QueryParam();
|
PqDevParam.QueryParam queryParam = new PqDevParam.QueryParam();
|
||||||
queryParam.setPlanIdList(Collections.singletonList(plan1.getId()));
|
queryParam.setPlanIdList(Collections.singletonList(plan1.getId()));
|
||||||
List<PqDevVO> pqDevVOS = pqDevService.listByPlanId(queryParam);
|
List<PqDevVO> pqDevVOS = pqDevService.listByPlanId(queryParam);
|
||||||
long checkedCount = pqDevVOS.stream().filter(pqDevVO -> pqDevVO.getCheckState().equals(CheckStateEnum.CHECKED.getValue())).count();
|
boolean allUnchecked = pqDevVOS.stream().allMatch(pqDevVO -> CheckStateEnum.UNCHECKED.getValue().equals(pqDevVO.getCheckState()));
|
||||||
if (checkedCount == pqDevVOS.size()) {
|
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());
|
plan1.setTestState(CheckStateEnum.CHECKED.getValue());
|
||||||
} else if (checkedCount > 0) {
|
} else {
|
||||||
plan1.setTestState(CheckStateEnum.CHECKING.getValue());
|
plan1.setTestState(CheckStateEnum.CHECKING.getValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -832,12 +835,19 @@ public class AdPlanServiceImpl extends ServiceImpl<AdPlanMapper, AdPlan> impleme
|
|||||||
List<PqDevVO> checkedDevices = planDevices.stream()
|
List<PqDevVO> checkedDevices = planDevices.stream()
|
||||||
.filter(this::isCheckedDevice)
|
.filter(this::isCheckedDevice)
|
||||||
.collect(Collectors.toList());
|
.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();
|
PlanStatisticsVO statistics = new PlanStatisticsVO();
|
||||||
statistics.setPlanId(plan.getId());
|
statistics.setPlanId(plan.getId());
|
||||||
statistics.setPlanName(plan.getName());
|
statistics.setPlanName(plan.getName());
|
||||||
statistics.setManufacturerOptions(buildManufacturerOptions(allPlanDevices, param.getDevType()));
|
statistics.setManufacturerOptions(buildManufacturerOptions(allPlanDevices, param.getDevType()));
|
||||||
statistics.setDevTypeOptions(buildDevTypeOptions(allPlanDevices, param.getManufacturer()));
|
statistics.setDevTypeOptions(buildDevTypeOptions(allPlanDevices, param.getManufacturer()));
|
||||||
statistics.setUncheckedDeviceCount(planDevices.size() - checkedDevices.size());
|
statistics.setUncheckedDeviceCount(uncheckedDeviceCount);
|
||||||
|
statistics.setCheckingDeviceCount(checkingDeviceCount);
|
||||||
statistics.setCheckedDeviceCount(checkedDevices.size());
|
statistics.setCheckedDeviceCount(checkedDevices.size());
|
||||||
statistics.setTotalCheckCount(checkedDevices.stream().mapToInt(dev -> defaultZero(dev.getRecheckNum())).sum());
|
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) {
|
private boolean isCheckedDevice(PqDevVO dev) {
|
||||||
return (Objects.equals(dev.getCheckState(), CheckStateEnum.CHECKED.getValue())
|
Integer checkState = dev.getCheckState();
|
||||||
|| Objects.equals(dev.getCheckState(), CheckStateEnum.DOCUMENTED.getValue()))
|
return checkState != null && checkState >= CheckStateEnum.CHECKED.getValue();
|
||||||
&& !Objects.equals(dev.getCheckResult(), CheckResultEnum.UNCHECKED.getValue());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<PlanStatisticsItemVO> buildItemDistributions(AdPlan plan, List<PqDevVO> checkedDevices) {
|
private List<PlanStatisticsItemVO> buildItemDistributions(AdPlan plan, List<PqDevVO> checkedDevices) {
|
||||||
@@ -1235,26 +1244,22 @@ public class AdPlanServiceImpl extends ServiceImpl<AdPlanMapper, AdPlan> impleme
|
|||||||
// 0-解绑、1-绑定
|
// 0-解绑、1-绑定
|
||||||
if (param.getBindFlag().equals(1)) {
|
if (param.getBindFlag().equals(1)) {
|
||||||
pqDevService.lambdaUpdate().set(PqDev::getPlanId, plan.getId()).in(PqDev::getId, param.getDevIds()).update();
|
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 {
|
} else {
|
||||||
pqDevService.lambdaUpdate().set(PqDev::getPlanId, plan.getFatherPlanId()).in(PqDev::getId, param.getDevIds()).update();
|
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();
|
PqDevParam.QueryParam queryParam = new PqDevParam.QueryParam();
|
||||||
queryParam.setPlanIdList(Collections.singletonList(plan.getId()));
|
queryParam.setPlanIdList(Collections.singletonList(plan.getId()));
|
||||||
List<PqDevVO> pqDevVOS = pqDevService.listByPlanId(queryParam);
|
List<PqDevVO> pqDevVOS = pqDevService.listByPlanId(queryParam);
|
||||||
long checkedCount = pqDevVOS.stream().filter(pqDevVO -> pqDevVO.getCheckState().equals(CheckStateEnum.CHECKED.getValue())).count();
|
boolean allUnchecked = pqDevVOS.stream().allMatch(pqDevVO -> CheckStateEnum.UNCHECKED.getValue().equals(pqDevVO.getCheckState()));
|
||||||
if (checkedCount == pqDevVOS.size()) {
|
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());
|
plan.setTestState(CheckStateEnum.CHECKED.getValue());
|
||||||
|
} else {
|
||||||
|
plan.setTestState(CheckStateEnum.CHECKING.getValue());
|
||||||
|
}
|
||||||
this.updateById(plan);
|
this.updateById(plan);
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,68 @@
|
|||||||
|
package com.njcn.gather.report.pojo.constant;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.LinkedHashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* "指标锚点"新型模板的书签命名空间常量。
|
||||||
|
* 设计文档:docs/superpowers/specs/2026-07-02-item-anchor-report-template-design.md §3.1
|
||||||
|
*
|
||||||
|
* @author hongawen
|
||||||
|
*/
|
||||||
|
public interface ItemAnchorConstant {
|
||||||
|
|
||||||
|
/** 数据锚点书签前缀:item_{scriptCode},锚点处按回路插入检测数据表 */
|
||||||
|
String ITEM_PREFIX = "item_";
|
||||||
|
|
||||||
|
/** 区段书签前缀:sect_{scriptCode} / sect_{GRP_XXX},指标无数据时整段删除 */
|
||||||
|
String SECT_PREFIX = "sect_";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 父节 → 子节 scriptCode 映射;一个父节的全部子节都隐藏时,父节(组标题+组内公共文字)一并隐藏。
|
||||||
|
* key 与模板中 sect_GRP_* 书签名的 GRP_* 部分一致。
|
||||||
|
*/
|
||||||
|
Map<String, List<String>> GRP_CHILDREN = buildGrpChildren();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 已知指标 scriptCode 白名单(规范大写,即云南模板 11 个锚点)。
|
||||||
|
* 分流与锚点解析以此为准:白名单外的 item_* 书签一律视为无效,防止老模板中
|
||||||
|
* 作者手工遗留的同前缀书签(如 item_1)把整份报告误路由进新路径。
|
||||||
|
*/
|
||||||
|
Set<String> KNOWN_SCRIPT_CODES = buildKnownScriptCodes();
|
||||||
|
|
||||||
|
static Map<String, List<String>> buildGrpChildren() {
|
||||||
|
Map<String, List<String>> map = new LinkedHashMap<>();
|
||||||
|
map.put("GRP_FUND", Arrays.asList("V", "I", "P", "ANGLE"));
|
||||||
|
map.put("GRP_UNB", Arrays.asList("IMBV", "IMBA"));
|
||||||
|
map.put("GRP_HARM", Arrays.asList("HV", "HI", "HP"));
|
||||||
|
return Collections.unmodifiableMap(map);
|
||||||
|
}
|
||||||
|
|
||||||
|
static Set<String> buildKnownScriptCodes() {
|
||||||
|
return Collections.unmodifiableSet(new LinkedHashSet<>(Arrays.asList(
|
||||||
|
"V", "I", "P", "ANGLE", "FREQ", "F", "IMBV", "IMBA", "HV", "HI", "HP")));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 从书签名解析指标锚点的 scriptCode。
|
||||||
|
*
|
||||||
|
* @param bookmarkName 书签名
|
||||||
|
* @return 规范大写 scriptCode(scriptMap / 模板 H5 分组 key 均为大写);
|
||||||
|
* 非 item_ 前缀、空 code 或不在 {@link #KNOWN_SCRIPT_CODES} 白名单内返回 null
|
||||||
|
*/
|
||||||
|
static String resolveItemScriptCode(String bookmarkName) {
|
||||||
|
if (bookmarkName == null || bookmarkName.length() <= ITEM_PREFIX.length()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (!bookmarkName.substring(0, ITEM_PREFIX.length()).equalsIgnoreCase(ITEM_PREFIX)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
String code = bookmarkName.substring(ITEM_PREFIX.length()).toUpperCase();
|
||||||
|
return KNOWN_SCRIPT_CODES.contains(code) ? code : null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -26,12 +26,15 @@ public enum BaseReportKeyEnum {
|
|||||||
MANUFACTURER("manufacturer","设备厂家、制造厂商"),
|
MANUFACTURER("manufacturer","设备厂家、制造厂商"),
|
||||||
SAMPLE_ID("sampleId","样品编号"),
|
SAMPLE_ID("sampleId","样品编号"),
|
||||||
ARRIVED_DATE("arrivedDate","收样日期"),
|
ARRIVED_DATE("arrivedDate","收样日期"),
|
||||||
|
ARRIVED_DATE_C("arrivedDateC","收样日期"),
|
||||||
TEST_DATE("testDate","检测日期"),
|
TEST_DATE("testDate","检测日期"),
|
||||||
|
TEST_DATE_C("testDateC","检测日期"),
|
||||||
INSPECTOR("inspector","检测员"),
|
INSPECTOR("inspector","检测员"),
|
||||||
YEAR("year","年份"),
|
YEAR("year","年份"),
|
||||||
MONTH("month","月份"),
|
MONTH("month","月份"),
|
||||||
DAY("day","日"),
|
DAY("day","日"),
|
||||||
YEAR_MONTH_DAY("year-month-day","年-月-日"),
|
YEAR_MONTH_DAY("year-month-day","年-月-日"),
|
||||||
|
YEAR_MONTH_DAY_UP("year-month-day-up","中文数字 年-月-日"),
|
||||||
REPORT_DATE("reportDate","年-月-日"),
|
REPORT_DATE("reportDate","年-月-日"),
|
||||||
GD_NAME("gdName","供电部门"),
|
GD_NAME("gdName","供电部门"),
|
||||||
SUB_NAME("subName","变电站"),
|
SUB_NAME("subName","变电站"),
|
||||||
|
|||||||
@@ -45,7 +45,34 @@ public enum ItemReportKeyEnum {
|
|||||||
RESULT_B("resultB", "结论 比如:合格/不合格"),
|
RESULT_B("resultB", "结论 比如:合格/不合格"),
|
||||||
RESULT_C("resultC", "结论 比如:合格/不合格"),
|
RESULT_C("resultC", "结论 比如:合格/不合格"),
|
||||||
RESULT_MAG("resultMag", "特征幅值结论 比如:合格/不合格"),
|
RESULT_MAG("resultMag", "特征幅值结论 比如:合格/不合格"),
|
||||||
RESULT_DUR("resultDur", "持续时间结论 比如:合格/不合格");
|
RESULT_DUR("resultDur", "持续时间结论 比如:合格/不合格"),
|
||||||
|
|
||||||
|
// ===== 以下为"指标锚点"新型模板(云南检定报告)新增 key,见 docs/superpowers/specs/2026-07-02-item-anchor-report-template-design.md §5 =====
|
||||||
|
STANDARD_V("standardV", "P表:基波电压设置值"),
|
||||||
|
STANDARD_I("standardI", "P表:基波电流设置值"),
|
||||||
|
STANDARD_U_ANGLE("standardUAngle", "P表:电压相角设置值"),
|
||||||
|
STANDARD_I_ANGLE("standardIAngle", "P表:电流相角设置值"),
|
||||||
|
ACTIVE_POWER("activePower", "P表:有功功率实测值(三相之和)"),
|
||||||
|
REACTIVE_POWER("reactivePower", "P表:无功功率实测值(数据侧暂无,留空)"),
|
||||||
|
APPARENT_POWER("apparentPower", "P表:视在功率实测值(数据侧暂无,留空)"),
|
||||||
|
POWER_FACTOR("powerFactor", "P表:功率因数实测值(数据侧暂无,留空)"),
|
||||||
|
POS_SEQ("posSeq", "不平衡表:基波正序(数据侧暂无,留空)"),
|
||||||
|
NEG_SEQ("negSeq", "不平衡表:基波负序(数据侧暂无,留空)"),
|
||||||
|
ZERO_SEQ("zeroSeq", "不平衡表:基波零序(数据侧暂无,留空)"),
|
||||||
|
BASE_CURRENT_A("baseCurrentA", "HI表:A相基波电流幅值,用于计算谐波电流含有率"),
|
||||||
|
BASE_CURRENT_B("baseCurrentB", "HI表:B相基波电流幅值,用于计算谐波电流含有率"),
|
||||||
|
BASE_CURRENT_C("baseCurrentC", "HI表:C相基波电流幅值,用于计算谐波电流含有率"),
|
||||||
|
STANDARD_RATE("standardRate", "HI表:标准源输出含有率"),
|
||||||
|
TEST_RATE_A("testRateA", "HI表:A相谐波电流含有率"),
|
||||||
|
TEST_RATE_B("testRateB", "HI表:B相谐波电流含有率"),
|
||||||
|
TEST_RATE_C("testRateC", "HI表:C相谐波电流含有率"),
|
||||||
|
ERROR_RATE_A("errorRateA", "HI表:A相谐波电流含有率误差"),
|
||||||
|
ERROR_RATE_B("errorRateB", "HI表:B相谐波电流含有率误差"),
|
||||||
|
ERROR_RATE_C("errorRateC", "HI表:C相谐波电流含有率误差"),
|
||||||
|
STANDARD_THD("standardThd", "HV/HI表:标准源总谐波畸变率"),
|
||||||
|
THD_A("thdA", "HV/HI表:A相总谐波畸变率"),
|
||||||
|
THD_B("thdB", "HV/HI表:B相总谐波畸变率"),
|
||||||
|
THD_C("thdC", "HV/HI表:C相总谐波畸变率");
|
||||||
|
|
||||||
private String key;
|
private String key;
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import lombok.Getter;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 电能质量测试大项枚举
|
* 电能质量测试大项枚举
|
||||||
|
*
|
||||||
* @author hongawen
|
* @author hongawen
|
||||||
* @version 1.0
|
* @version 1.0
|
||||||
* @data 2025/3/27 18:29
|
* @data 2025/3/27 18:29
|
||||||
@@ -13,21 +14,21 @@ public enum PowerIndexEnum {
|
|||||||
|
|
||||||
|
|
||||||
UNKNOWN("UNKNOWN", "未知指标"),
|
UNKNOWN("UNKNOWN", "未知指标"),
|
||||||
FREQ("FREQ", "频率"),
|
|
||||||
LINE_TITLE("LINE_TITLE", "测量回路"),
|
LINE_TITLE("LINE_TITLE", "测量回路"),
|
||||||
|
FREQ("FREQ", "频率"),
|
||||||
V("V", "电压"),
|
V("V", "电压"),
|
||||||
I("I", "电流"),
|
|
||||||
P("P", "功率"),
|
|
||||||
IMBV("IMBV", "负序电压不平衡度"),
|
|
||||||
IMBA("IMBA", "负序电流不平衡度"),
|
|
||||||
F("F", "短时电压闪变"),
|
|
||||||
HP("HP", "谐波有功功率"),
|
|
||||||
HV("HV", "谐波电压"),
|
HV("HV", "谐波电压"),
|
||||||
HI("HI", "谐波电流"),
|
HI("HI", "谐波电流"),
|
||||||
|
HP("HP", "谐波有功功率"),
|
||||||
HSV("HSV", "间谐波电压"),
|
HSV("HSV", "间谐波电压"),
|
||||||
HSI("HSI", "间谐波电流"),
|
HSI("HSI", "间谐波电流"),
|
||||||
VOLTAGE("VOLTAGE", "电压暂降、暂升及短时中断"),
|
VOLTAGE("VOLTAGE", "电压暂降、暂升及短时中断"),
|
||||||
PST("PST", "短时间闪变");
|
I("I", "电流"),
|
||||||
|
IMBV("IMBV", "负序电压不平衡度"),
|
||||||
|
IMBA("IMBA", "负序电流不平衡度"),
|
||||||
|
F("F", "短时电压闪变"),
|
||||||
|
P("P", "功率"),
|
||||||
|
ANGLE("Angle", "基波相位");
|
||||||
|
|
||||||
private String key;
|
private String key;
|
||||||
|
|
||||||
|
|||||||
@@ -52,6 +52,7 @@ import com.njcn.gather.plan.service.IAdPlanTestConfigService;
|
|||||||
import com.njcn.gather.pojo.enums.DetectionResponseEnum;
|
import com.njcn.gather.pojo.enums.DetectionResponseEnum;
|
||||||
import com.njcn.gather.report.mapper.PqReportMapper;
|
import com.njcn.gather.report.mapper.PqReportMapper;
|
||||||
import com.njcn.gather.report.pojo.DevReportParam;
|
import com.njcn.gather.report.pojo.DevReportParam;
|
||||||
|
import com.njcn.gather.report.pojo.constant.ItemAnchorConstant;
|
||||||
import com.njcn.gather.report.pojo.constant.PowerConstant;
|
import com.njcn.gather.report.pojo.constant.PowerConstant;
|
||||||
import com.njcn.gather.report.pojo.enums.*;
|
import com.njcn.gather.report.pojo.enums.*;
|
||||||
import com.njcn.gather.report.pojo.param.ReportParam;
|
import com.njcn.gather.report.pojo.param.ReportParam;
|
||||||
@@ -60,6 +61,8 @@ import com.njcn.gather.report.pojo.result.ContrastTestResult;
|
|||||||
import com.njcn.gather.report.pojo.result.SingleTestResult;
|
import com.njcn.gather.report.pojo.result.SingleTestResult;
|
||||||
import com.njcn.gather.report.pojo.vo.PqReportVO;
|
import com.njcn.gather.report.pojo.vo.PqReportVO;
|
||||||
import com.njcn.gather.report.service.IPqReportService;
|
import com.njcn.gather.report.service.IPqReportService;
|
||||||
|
import com.njcn.gather.report.util.ItemAnchorAssembler;
|
||||||
|
import com.njcn.gather.report.util.ItemAnchorSectionUtil;
|
||||||
import com.njcn.gather.result.service.IResultService;
|
import com.njcn.gather.result.service.IResultService;
|
||||||
import com.njcn.gather.script.pojo.vo.PqScriptDtlDataVO;
|
import com.njcn.gather.script.pojo.vo.PqScriptDtlDataVO;
|
||||||
import com.njcn.gather.script.service.IPqScriptDtlsService;
|
import com.njcn.gather.script.service.IPqScriptDtlsService;
|
||||||
@@ -117,6 +120,7 @@ import java.nio.file.Files;
|
|||||||
import java.nio.file.NoSuchFileException;
|
import java.nio.file.NoSuchFileException;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
|
import java.time.LocalDate;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -144,6 +148,7 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
|
|||||||
* 的真实业务取值撞车。
|
* 的真实业务取值撞车。
|
||||||
*/
|
*/
|
||||||
private static final String RESULT_MAP_NO_DATA_FLAG = "__internal_no_data__";
|
private static final String RESULT_MAP_NO_DATA_FLAG = "__internal_no_data__";
|
||||||
|
private static final String[] CHINESE_DIGITS = {"O", "一", "二", "三", "四", "五", "六", "七", "八", "九"};
|
||||||
|
|
||||||
// @Value("${report.template:D:\\template}")
|
// @Value("${report.template:D:\\template}")
|
||||||
// private String templatePath;
|
// private String templatePath;
|
||||||
@@ -860,6 +865,7 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
|
|||||||
Docx4jUtil.addWatermarkToDocument(baseModelDocument, "非正式");
|
Docx4jUtil.addWatermarkToDocument(baseModelDocument, "非正式");
|
||||||
}
|
}
|
||||||
Docx4jUtil.cleanBlankPagesAndRedundantPageBreaks(baseModelDocument);
|
Docx4jUtil.cleanBlankPagesAndRedundantPageBreaks(baseModelDocument);
|
||||||
|
Docx4jUtil.enableUpdateFieldsOnOpen(baseModelDocument);
|
||||||
baseModelDocument.save(new File(dirPath.concat(File.separator).concat(fileName)));
|
baseModelDocument.save(new File(dirPath.concat(File.separator).concat(fileName)));
|
||||||
this.updateDevAndPlanState(devId, devReportParam.getPlanId());
|
this.updateDevAndPlanState(devId, devReportParam.getPlanId());
|
||||||
} catch (NoSuchFileException e) {
|
} catch (NoSuchFileException e) {
|
||||||
@@ -926,12 +932,21 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
|
|||||||
|
|
||||||
// 获取数据模版页内容,根据脚本动态组装数据页内容
|
// 获取数据模版页内容,根据脚本动态组装数据页内容
|
||||||
MainDocumentPart detailDocumentPart = detailModelDocument.getMainDocumentPart();
|
MainDocumentPart detailDocumentPart = detailModelDocument.getMainDocumentPart();
|
||||||
|
// 新旧模板分流:base 含白名单内 item_ 前缀书签 → 指标锚点新型模板(云南检定报告类),走独立旁路;
|
||||||
|
// 否则走原路径,行为与改动前完全一致。设计文档 specs/2026-07-02-item-anchor-report-template-design.md §4.1
|
||||||
|
// 书签全文档扫描只做一次,分流判断与新路径共用;老路径方法签名不动,内部自扫
|
||||||
|
List<BookmarkUtil.BookmarkInfo> baseBookmarks = BookmarkUtil.findAllBookmarks(baseDocumentPart);
|
||||||
|
if (hasItemAnchor(baseBookmarks)) {
|
||||||
|
dealDataModelByItemAnchor(baseDocumentPart, detailDocumentPart, devReportParam, pqDevVO, baseBookmarks);
|
||||||
|
} else {
|
||||||
dealDataModelScatteredByBookmark(baseDocumentPart, detailDocumentPart, devReportParam, pqDevVO);
|
dealDataModelScatteredByBookmark(baseDocumentPart, detailDocumentPart, devReportParam, pqDevVO);
|
||||||
|
}
|
||||||
|
|
||||||
// 保存新的文档
|
// 保存新的文档
|
||||||
String dirPath = pathConfig.getReportPath().concat(File.separator).concat(FilePathSanitizer.toSafeFileName(devType.getName()));
|
String dirPath = pathConfig.getReportPath().concat(File.separator).concat(FilePathSanitizer.toSafeFileName(devType.getName()));
|
||||||
// 确保目录存在
|
// 确保目录存在
|
||||||
ensureDirectoryExists(dirPath);
|
ensureDirectoryExists(dirPath);
|
||||||
|
Docx4jUtil.enableUpdateFieldsOnOpen(baseModelDocument);
|
||||||
baseModelDocument.save(new File(dirPath.concat(File.separator).concat(pqDevVO.getCreateId()).concat(ReportConstant.DOCX)));
|
baseModelDocument.save(new File(dirPath.concat(File.separator).concat(pqDevVO.getCreateId()).concat(ReportConstant.DOCX)));
|
||||||
this.updateDevAndPlanState(devId, devReportParam.getPlanId());
|
this.updateDevAndPlanState(devId, devReportParam.getPlanId());
|
||||||
} catch (NoSuchFileException e) {
|
} catch (NoSuchFileException e) {
|
||||||
@@ -1229,6 +1244,131 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 判断 base 文档是否为"指标锚点"新型模板(含任一白名单内 item_ 前缀书签)。
|
||||||
|
* 白名单校验在 resolveItemScriptCode 内:老模板中手工遗留的同前缀书签(如 item_1)
|
||||||
|
* 不会触发新路径,避免整份报告错路由导致 DATA_LINE / TEST_RESULT_* 全不填。
|
||||||
|
*
|
||||||
|
* @param bookmarks base 文档书签集合(调用方已扫,避免全文档重复扫描)
|
||||||
|
*/
|
||||||
|
private boolean hasItemAnchor(List<BookmarkUtil.BookmarkInfo> bookmarks) {
|
||||||
|
for (BookmarkUtil.BookmarkInfo info : bookmarks) {
|
||||||
|
if (ItemAnchorConstant.resolveItemScriptCode(info.bookmark.getName()) != null) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* "指标锚点"新型模板装配(云南检定报告类)。
|
||||||
|
* 流程:逐 item_* 锚点 → detail 池取 H5 模板表 → 按回路构造成品表插入锚点;
|
||||||
|
* 无数据/无模板的指标记入隐藏集合 → 区段删除 → 第 7 节编号重排 → 残留书签清理。
|
||||||
|
* 设计文档:docs/superpowers/specs/2026-07-02-item-anchor-report-template-design.md §4.2
|
||||||
|
*/
|
||||||
|
private void dealDataModelByItemAnchor(MainDocumentPart baseDocumentPart, MainDocumentPart detailDocumentPart,
|
||||||
|
DevReportParam devReportParam, PqDevVO pqDevVO,
|
||||||
|
List<BookmarkUtil.BookmarkInfo> bookmarks) {
|
||||||
|
ObjectFactory factory = new ObjectFactory();
|
||||||
|
// 检测脚本明细按 scriptCode 分组
|
||||||
|
List<PqScriptDtlDataVO> pqScriptDtlsList = pqScriptDtlsService.getScriptDtlsDataList(devReportParam.getScriptId());
|
||||||
|
Map<String, List<PqScriptDtlDataVO>> scriptMap = pqScriptDtlsList.stream()
|
||||||
|
.collect(Collectors.groupingBy(item -> itemAnchorGroupKey(item.getScriptCode()), LinkedHashMap::new, Collectors.toList()));
|
||||||
|
// detail 模板池按 H5 分组
|
||||||
|
List<Docx4jUtil.HeadingContent> headingContents = Docx4jUtil.extractHeading5Contents(detailDocumentPart.getContent(), detailDocumentPart);
|
||||||
|
Map<String, List<Docx4jUtil.HeadingContent>> contentMap = headingContents.stream()
|
||||||
|
.collect(Collectors.groupingBy(item -> itemAnchorGroupKey(item.getHeadingText()), LinkedHashMap::new, Collectors.toList()));
|
||||||
|
int devChns = pqDevVO.getDevChns() == null ? 1 : pqDevVO.getDevChns();
|
||||||
|
Set<String> hiddenCodes = new LinkedHashSet<>();
|
||||||
|
for (BookmarkUtil.BookmarkInfo info : bookmarks) {
|
||||||
|
String scriptCode = ItemAnchorConstant.resolveItemScriptCode(info.bookmark.getName());
|
||||||
|
if (scriptCode == null) {
|
||||||
|
// 新路径按设计忽略老锚点(互斥分流,spec §4.1);发现 BookmarkEnum 残留提示模板可能混用
|
||||||
|
if (Objects.nonNull(BookmarkEnum.getByKey(info.bookmark.getName()))) {
|
||||||
|
log.warn("指标锚点模板中发现老模板锚点书签 {},新路径不处理该书签", info.bookmark.getName());
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
List<PqScriptDtlDataVO> itemDtls = scriptMap.get(scriptCode);
|
||||||
|
List<Docx4jUtil.HeadingContent> tpl = contentMap.get(scriptCode);
|
||||||
|
if (CollUtil.isEmpty(itemDtls) || CollUtil.isEmpty(tpl)) {
|
||||||
|
log.warn("指标锚点 {} 无脚本数据或无模板分组,整节隐藏", info.bookmark.getName());
|
||||||
|
hiddenCodes.add(scriptCode);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
List<String> tableKeys = ItemAnchorAssembler.extractTableKeys(tpl);
|
||||||
|
// 有脚本明细且模板分组在,keys 仍取不到属模板错误 → 显性中断,不得静默走"未测→整节隐藏"
|
||||||
|
ItemAnchorAssembler.requireTableKeys(scriptCode, tableKeys);
|
||||||
|
List<Object> todoInsertList = new ArrayList<>();
|
||||||
|
for (int line = 0; line < devChns; line++) {
|
||||||
|
List<SingleTestResult> results = new ArrayList<>();
|
||||||
|
if (PowerConstant.TIME.contains(scriptCode)) {
|
||||||
|
// 谐波类:一个 scriptIndex 一张表(与老路径语义一致)
|
||||||
|
Map<Integer, List<PqScriptDtlDataVO>> scriptIndexMap = itemDtls.stream()
|
||||||
|
.collect(Collectors.groupingBy(PqScriptDtlDataVO::getScriptIndex, TreeMap::new, Collectors.toList()));
|
||||||
|
for (List<PqScriptDtlDataVO> indexItem : scriptIndexMap.values()) {
|
||||||
|
SingleTestResult single = resultService.getFinalContent(indexItem, devReportParam.getPlanCode(), pqDevVO.getId(), line + 1, tableKeys);
|
||||||
|
if (Objects.nonNull(single)) {
|
||||||
|
results.add(single);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
SingleTestResult single = resultService.getFinalContent(itemDtls, devReportParam.getPlanCode(), pqDevVO.getId(), line + 1, tableKeys);
|
||||||
|
if (Objects.nonNull(single)) {
|
||||||
|
results.add(single);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
List<Object> lineTables = ItemAnchorAssembler.buildTables(scriptCode, results, tpl.get(0), tableKeys, factory);
|
||||||
|
if (lineTables.isEmpty()) {
|
||||||
|
// 该回路无数据,跳过;是否整节隐藏由所有回路汇总后判断
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
// 回路标题:单回路省略;多回路"测量回路{n}"从 1 起(spec §4.2)
|
||||||
|
if (devChns > 1) {
|
||||||
|
todoInsertList.add(buildItemLineTitle(contentMap, line, factory));
|
||||||
|
}
|
||||||
|
todoInsertList.addAll(lineTables);
|
||||||
|
}
|
||||||
|
if (todoInsertList.isEmpty()) {
|
||||||
|
log.warn("指标 {} 所有回路均无检测数据,整节隐藏", scriptCode);
|
||||||
|
hiddenCodes.add(scriptCode);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
BookmarkUtil.insertElement(info, todoInsertList);
|
||||||
|
// 已填充节不再需要 item/sect 标记:空锚点段直接删除,避免表格前残留空行;
|
||||||
|
// 若未来模板把锚点放进非空段,则只清书签保留段落正文。
|
||||||
|
if (!ItemAnchorSectionUtil.removeEmptyItemAnchorParagraph(info)) {
|
||||||
|
BookmarkUtil.removeBookmark(info);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ItemAnchorSectionUtil.removeSectRanges(baseDocumentPart, hiddenCodes);
|
||||||
|
ItemAnchorSectionUtil.renumberChapter7(baseDocumentPart);
|
||||||
|
ItemAnchorSectionUtil.stripItemAnchorBookmarks(baseDocumentPart);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String itemAnchorGroupKey(String value) {
|
||||||
|
return value == null ? "" : value.trim().toUpperCase(Locale.ROOT);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新型模板的回路标题(仅多回路时被调用):"测量回路{n}",n 从 1 起。
|
||||||
|
* 与老路径 getLineTitle 的差异(有意):不带 "n." 前缀、单回路由调用方直接省略。
|
||||||
|
*/
|
||||||
|
private P buildItemLineTitle(Map<String, List<Docx4jUtil.HeadingContent>> contentMap, int lineIndex, ObjectFactory factory) {
|
||||||
|
int lineNo = lineIndex + 1;
|
||||||
|
P titleParagraph = factory.createP();
|
||||||
|
PPr pPr = factory.createPPr();
|
||||||
|
PPrBase.Spacing spacing = factory.createPPrBaseSpacing();
|
||||||
|
spacing.setBefore(BigInteger.valueOf(60));
|
||||||
|
spacing.setAfter(BigInteger.valueOf(20));
|
||||||
|
spacing.setLine(BigInteger.valueOf(240));
|
||||||
|
spacing.setLineRule(STLineSpacingRule.AUTO);
|
||||||
|
pPr.setSpacing(spacing);
|
||||||
|
titleParagraph.setPPr(pPr);
|
||||||
|
Docx4jUtil.createTitle(factory, titleParagraph, "测量回路" + lineNo, 24, true);
|
||||||
|
return titleParagraph;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 通过提前在模板文档里埋下书签
|
* 通过提前在模板文档里埋下书签
|
||||||
* 1、目录信息
|
* 1、目录信息
|
||||||
@@ -2080,7 +2220,7 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
|
|||||||
queryParam.setPlanIdList(Arrays.asList(tempPqDevVO.getPlanId()));
|
queryParam.setPlanIdList(Arrays.asList(tempPqDevVO.getPlanId()));
|
||||||
List<PqDevVO> pqDevVOList1 = pqDevMapper.selectByQueryParam(queryParam);
|
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) {
|
if (count == 0) {
|
||||||
// 如果非归档状态的设备数量为0,则更新计划已完成
|
// 如果非归档状态的设备数量为0,则更新计划已完成
|
||||||
pqDevMapper.finishPlan(pqDevVO.getPlanId());
|
pqDevMapper.finishPlan(pqDevVO.getPlanId());
|
||||||
@@ -2168,14 +2308,17 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
|
|||||||
baseModelMap.put(BaseReportKeyEnum.SAMPLE_ID.getKey(), StrUtil.isEmpty(pqDevVO.getSampleId()) ? StrPool.TAB : pqDevVO.getSampleId());
|
baseModelMap.put(BaseReportKeyEnum.SAMPLE_ID.getKey(), StrUtil.isEmpty(pqDevVO.getSampleId()) ? StrPool.TAB : pqDevVO.getSampleId());
|
||||||
// 收样日期
|
// 收样日期
|
||||||
baseModelMap.put(BaseReportKeyEnum.ARRIVED_DATE.getKey(), Objects.isNull(pqDevVO.getArrivedDate()) ? StrPool.TAB : String.valueOf(pqDevVO.getArrivedDate()));
|
baseModelMap.put(BaseReportKeyEnum.ARRIVED_DATE.getKey(), Objects.isNull(pqDevVO.getArrivedDate()) ? StrPool.TAB : String.valueOf(pqDevVO.getArrivedDate()));
|
||||||
|
baseModelMap.put(BaseReportKeyEnum.ARRIVED_DATE_C.getKey(), Objects.isNull(pqDevVO.getArrivedDate()) ? StrPool.TAB : formatNumberChineseDate(pqDevVO.getArrivedDate()));
|
||||||
// 检测日期
|
// 检测日期
|
||||||
baseModelMap.put(BaseReportKeyEnum.TEST_DATE.getKey(), Objects.isNull(pqDevVO.getCheckEndTime()) ? StrPool.TAB : String.valueOf(pqDevVO.getCheckEndTime()).substring(0, 10));
|
baseModelMap.put(BaseReportKeyEnum.TEST_DATE.getKey(), Objects.isNull(pqDevVO.getCheckEndTime()) ? StrPool.TAB : String.valueOf(pqDevVO.getCheckEndTime()).substring(0, 10));
|
||||||
|
baseModelMap.put(BaseReportKeyEnum.TEST_DATE_C.getKey(), Objects.isNull(pqDevVO.getCheckEndTime()) ? StrPool.TAB : formatNumberChineseDate(pqDevVO.getCheckEndTime().toLocalDate()));
|
||||||
baseModelMap.put(BaseReportKeyEnum.TEMPERATURE.getKey(), Objects.isNull(pqDevVO.getTemperature()) ? StrPool.TAB : pqDevVO.getTemperature().toString());
|
baseModelMap.put(BaseReportKeyEnum.TEMPERATURE.getKey(), Objects.isNull(pqDevVO.getTemperature()) ? StrPool.TAB : pqDevVO.getTemperature().toString());
|
||||||
baseModelMap.put(BaseReportKeyEnum.HUMIDITY.getKey(), Objects.isNull(pqDevVO.getHumidity()) ? StrPool.TAB : pqDevVO.getHumidity().toString());
|
baseModelMap.put(BaseReportKeyEnum.HUMIDITY.getKey(), Objects.isNull(pqDevVO.getHumidity()) ? StrPool.TAB : pqDevVO.getHumidity().toString());
|
||||||
baseModelMap.put(BaseReportKeyEnum.YEAR.getKey(), DateUtil.format(new Date(), DatePattern.NORM_YEAR_PATTERN));
|
baseModelMap.put(BaseReportKeyEnum.YEAR.getKey(), DateUtil.format(new Date(), DatePattern.NORM_YEAR_PATTERN));
|
||||||
baseModelMap.put(BaseReportKeyEnum.MONTH.getKey(), DateUtil.format(new Date(), DatePattern.SIMPLE_MONTH_PATTERN).substring(4));
|
baseModelMap.put(BaseReportKeyEnum.MONTH.getKey(), DateUtil.format(new Date(), DatePattern.SIMPLE_MONTH_PATTERN).substring(4));
|
||||||
baseModelMap.put(BaseReportKeyEnum.DAY.getKey(), DateUtil.format(new Date(), DatePattern.PURE_DATE_PATTERN).substring(6));
|
baseModelMap.put(BaseReportKeyEnum.DAY.getKey(), DateUtil.format(new Date(), DatePattern.PURE_DATE_PATTERN).substring(6));
|
||||||
baseModelMap.put(BaseReportKeyEnum.YEAR_MONTH_DAY.getKey(), DateUtil.format(new Date(), DatePattern.NORM_DATE_PATTERN));
|
baseModelMap.put(BaseReportKeyEnum.YEAR_MONTH_DAY.getKey(), DateUtil.format(new Date(), DatePattern.NORM_DATE_PATTERN));
|
||||||
|
baseModelMap.put(BaseReportKeyEnum.YEAR_MONTH_DAY_UP.getKey(), formatChineseReportDate(LocalDate.now()));
|
||||||
baseModelMap.put(BaseReportKeyEnum.REPORT_DATE.getKey(), DateUtil.format(new Date(), DatePattern.CHINESE_DATE_PATTERN));
|
baseModelMap.put(BaseReportKeyEnum.REPORT_DATE.getKey(), DateUtil.format(new Date(), DatePattern.CHINESE_DATE_PATTERN));
|
||||||
return baseModelMap;
|
return baseModelMap;
|
||||||
}
|
}
|
||||||
@@ -2480,6 +2623,40 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
|
|||||||
return String.format("%.4f", bp.setScale(i, RoundingMode.HALF_UP).doubleValue());
|
return String.format("%.4f", bp.setScale(i, RoundingMode.HALF_UP).doubleValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static String formatChineseReportDate(LocalDate date) {
|
||||||
|
Objects.requireNonNull(date, "date");
|
||||||
|
return formatChineseYear(date.getYear()) + "年"
|
||||||
|
+ formatChineseMonthDayNumber(date.getMonthValue()) + "月"
|
||||||
|
+ formatChineseMonthDayNumber(date.getDayOfMonth()) + "日";
|
||||||
|
}
|
||||||
|
|
||||||
|
static String formatNumberChineseDate(LocalDate date) {
|
||||||
|
Objects.requireNonNull(date, "date");
|
||||||
|
return date.getYear() + "年" + date.getMonthValue() + "月" + date.getDayOfMonth() + "日";
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String formatChineseYear(int year) {
|
||||||
|
String yearValue = String.valueOf(year);
|
||||||
|
StringBuilder builder = new StringBuilder(yearValue.length());
|
||||||
|
for (int i = 0; i < yearValue.length(); i++) {
|
||||||
|
builder.append(CHINESE_DIGITS[yearValue.charAt(i) - '0']);
|
||||||
|
}
|
||||||
|
return builder.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String formatChineseMonthDayNumber(int value) {
|
||||||
|
if (value < 10) {
|
||||||
|
return CHINESE_DIGITS[value];
|
||||||
|
}
|
||||||
|
if (value == 10) {
|
||||||
|
return "十";
|
||||||
|
}
|
||||||
|
if (value < 20) {
|
||||||
|
return "十" + CHINESE_DIGITS[value % 10];
|
||||||
|
}
|
||||||
|
return CHINESE_DIGITS[value / 10] + "十" + (value % 10 == 0 ? "" : CHINESE_DIGITS[value % 10]);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private void ensureDirectoryExists(String directoryPath) {
|
private void ensureDirectoryExists(String directoryPath) {
|
||||||
File directory = new File(directoryPath);
|
File directory = new File(directoryPath);
|
||||||
|
|||||||
@@ -0,0 +1,532 @@
|
|||||||
|
package com.njcn.gather.report.util;
|
||||||
|
|
||||||
|
import cn.hutool.core.collection.CollUtil;
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import com.njcn.common.pojo.exception.BusinessException;
|
||||||
|
import com.njcn.gather.report.pojo.enums.ItemReportKeyEnum;
|
||||||
|
import com.njcn.gather.report.pojo.result.SingleTestResult;
|
||||||
|
import com.njcn.gather.tools.report.util.Docx4jUtil;
|
||||||
|
import org.docx4j.wml.ObjectFactory;
|
||||||
|
import org.docx4j.wml.P;
|
||||||
|
import org.docx4j.wml.R;
|
||||||
|
import org.docx4j.wml.RPr;
|
||||||
|
import org.docx4j.wml.Tbl;
|
||||||
|
import org.docx4j.wml.Tc;
|
||||||
|
import org.docx4j.wml.TcPr;
|
||||||
|
import org.docx4j.wml.Text;
|
||||||
|
import org.docx4j.wml.Tr;
|
||||||
|
import org.docx4j.wml.TrPr;
|
||||||
|
|
||||||
|
import javax.xml.bind.JAXBElement;
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* "指标锚点"模板的表格装配器:模板表(末行为 key 行)+ SingleTestResult → 成品表列表。
|
||||||
|
* 只服务新路径,不被老路径引用;对 Docx4jUtil 只调用不修改。
|
||||||
|
* 设计文档:docs/superpowers/specs/2026-07-02-item-anchor-report-template-design.md §4.2 / §6
|
||||||
|
*
|
||||||
|
* @author hongawen
|
||||||
|
*/
|
||||||
|
public final class ItemAnchorAssembler {
|
||||||
|
|
||||||
|
private ItemAnchorAssembler() {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 构造成品表。results 每个有效元素产出一张表(谐波类调用方按 scriptIndex 拆分后传入)。
|
||||||
|
*
|
||||||
|
* @param scriptCode 指标编码(P 走有功功率特例映射)
|
||||||
|
* @param results 检测结果列表,null/空 detail 的元素跳过
|
||||||
|
* @param template detail 模板池中该指标的 H5 分组(取其中第一张表为模板)
|
||||||
|
* @param tableKeys key 行的占位符列表(调用方经 Docx4jUtil.getTableFillKeys 读出)
|
||||||
|
* @param factory docx4j 工厂
|
||||||
|
* @return 待插入锚点的表格元素列表(JAXBElement<Tbl>)
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public static List<Object> buildTables(String scriptCode, List<SingleTestResult> results,
|
||||||
|
Docx4jUtil.HeadingContent template, List<String> tableKeys,
|
||||||
|
ObjectFactory factory) {
|
||||||
|
List<Object> out = new ArrayList<>();
|
||||||
|
JAXBElement<Tbl> templateTbl = findFirstTable(template);
|
||||||
|
if (templateTbl == null || CollUtil.isEmpty(results) || CollUtil.isEmpty(tableKeys)) {
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
int tableNo = 0;
|
||||||
|
for (SingleTestResult result : results) {
|
||||||
|
List<Map<String, String>> rows = flattenRows(result, scriptCode);
|
||||||
|
if (rows.isEmpty()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
tableNo++;
|
||||||
|
applyHarmonicDerivedValues(rows, scriptCode);
|
||||||
|
Map<String, String> fixedPlaceholders = buildHarmonicFixedPlaceholders(rows, scriptCode);
|
||||||
|
JAXBElement<Tbl> copied;
|
||||||
|
try {
|
||||||
|
copied = Docx4jUtil.deepCopyTbl(templateTbl);
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException("指标锚点模板表深拷贝失败: " + scriptCode, e);
|
||||||
|
}
|
||||||
|
Tbl tbl = copied.getValue();
|
||||||
|
replaceFixedPlaceholders(tbl, fixedPlaceholders);
|
||||||
|
applyHarmonicPowerHeader(tbl, scriptCode, tableNo, rows);
|
||||||
|
List<Object> trs = tbl.getContent();
|
||||||
|
// 模板规范约定:最后一行是 key 行(不走 judgeTableCross,新路径自带定位依据);
|
||||||
|
// 从尾部找最后一个真正的 Tr——Word 重存可能把 bookmarkStart/End 漏成 w:tbl 直接子节点(本仓 _GoBack 先例)
|
||||||
|
Tr keyRow = findLastRow(trs);
|
||||||
|
if (keyRow == null) {
|
||||||
|
throw new BusinessException("指标 " + scriptCode + " 的模板表无有效行,请检查 detail 模板该分组表格");
|
||||||
|
}
|
||||||
|
TrPr trPr = keyRow.getTrPr();
|
||||||
|
List<TcPr> tcPrList = new ArrayList<>();
|
||||||
|
RPr templateRPr = null;
|
||||||
|
for (Object cellObj : keyRow.getContent()) {
|
||||||
|
if (cellObj instanceof JAXBElement) {
|
||||||
|
Tc cell = ((JAXBElement<Tc>) cellObj).getValue();
|
||||||
|
TcPr tcPr = cell.getTcPr() != null ? cell.getTcPr() : factory.createTcPr();
|
||||||
|
// 注意:不覆写 tcW(老 fill 的 5000/n 均分会破坏客户模板列宽),沿用模板原宽
|
||||||
|
tcPrList.add(tcPr);
|
||||||
|
if (templateRPr == null && !cell.getContent().isEmpty() && cell.getContent().get(0) instanceof P) {
|
||||||
|
templateRPr = Docx4jUtil.getTcPrFromParagraph((P) cell.getContent().get(0));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
trs.remove(keyRow);
|
||||||
|
for (Map<String, String> row : rows) {
|
||||||
|
// 缺失 key 一律补空串:"拿不到的先空着"(spec §6 #2)
|
||||||
|
for (String key : tableKeys) {
|
||||||
|
row.putIfAbsent(key, "");
|
||||||
|
}
|
||||||
|
Tr newRow = Docx4jUtil.createCustomRow(factory, row, tableKeys, trPr, tcPrList, templateRPr, true);
|
||||||
|
// Docx4jUtil.createCustomRow 产出的单元格是裸 Tc(未包 JAXBElement),
|
||||||
|
// 与模板行(真实 docx4j 解析结果 / deepCopy 而来)里统一的 JAXBElement<Tc> 不一致;
|
||||||
|
// 这里做一次归一化包装,避免下游按 JAXBElement 读取该行时 ClassCastException(不改 createCustomRow 本身)
|
||||||
|
List<Object> normalized = new ArrayList<>();
|
||||||
|
for (Object cellObj : newRow.getContent()) {
|
||||||
|
if (cellObj instanceof Tc) {
|
||||||
|
normalized.add(factory.createTrTc((Tc) cellObj));
|
||||||
|
} else {
|
||||||
|
normalized.add(cellObj);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
newRow.getContent().clear();
|
||||||
|
newRow.getContent().addAll(normalized);
|
||||||
|
trs.add(newRow);
|
||||||
|
}
|
||||||
|
out.add(copied);
|
||||||
|
}
|
||||||
|
// 多表(谐波类多 scriptIndex)背靠背插入时,OOXML 相邻 w:tbl 会被 Word 合并渲染成一张大表;
|
||||||
|
// 只插入空段落做结构分隔。测点号属于 HP 表内标题单元格,不能作为表外可见段落。
|
||||||
|
if (out.size() > 1) {
|
||||||
|
List<Object> withSeparators = new ArrayList<>(out.size() * 2 - 1);
|
||||||
|
for (int i = 0; i < out.size(); i++) {
|
||||||
|
withSeparators.add(out.get(i));
|
||||||
|
if (i < out.size() - 1) {
|
||||||
|
withSeparators.add(factory.createP());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return withSeparators;
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 校验模板 key 行占位符已成功取出。调用方仅在"该指标有脚本明细且模板分组存在"时调用:
|
||||||
|
* 此时 keys 为空属模板错误(key 行缺失或表结构不符合 getTableFillKeys 的识别规则),
|
||||||
|
* 必须显性中断报告生成,不得静默走"未测→整节隐藏"(否则有数据的节凭空消失,违反红线 2)。
|
||||||
|
*/
|
||||||
|
public static void requireTableKeys(String scriptCode, List<String> tableKeys) {
|
||||||
|
if (CollUtil.isEmpty(tableKeys)) {
|
||||||
|
throw new BusinessException("指标 " + scriptCode + " 的模板表 key 行占位符解析为空,请检查 detail 模板该分组的表格(表末行应为占位符 key 行),已中断报告生成");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 指标锚点模板专用 key 读取:按 spec 直接取 H5 分组第一张表的最后一个真实 Tr。
|
||||||
|
* 不复用旧 getTableFillKeys 的横/纵表启发式,避免 HV/HI/HP 标题区末格为数值时被误判。
|
||||||
|
*/
|
||||||
|
public static List<String> extractTableKeys(List<Docx4jUtil.HeadingContent> tempContent) {
|
||||||
|
List<String> keys = new ArrayList<>();
|
||||||
|
if (CollUtil.isEmpty(tempContent)) {
|
||||||
|
return keys;
|
||||||
|
}
|
||||||
|
JAXBElement<Tbl> table = findFirstTable(tempContent.get(0));
|
||||||
|
if (table == null) {
|
||||||
|
return keys;
|
||||||
|
}
|
||||||
|
Tr keyRow = findLastRow(table.getValue().getContent());
|
||||||
|
if (keyRow == null) {
|
||||||
|
return keys;
|
||||||
|
}
|
||||||
|
for (Object cellObj : keyRow.getContent()) {
|
||||||
|
Object value = cellObj instanceof JAXBElement ? ((JAXBElement<?>) cellObj).getValue() : cellObj;
|
||||||
|
if (value instanceof Tc) {
|
||||||
|
keys.add(Docx4jUtil.getTextFromCell((Tc) value));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return keys;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 从尾部向前找最后一个真正的 Tr(含 JAXBElement 解包);无 Tr 返回 null */
|
||||||
|
private static Tr findLastRow(List<Object> content) {
|
||||||
|
for (int i = content.size() - 1; i >= 0; i--) {
|
||||||
|
Object v = content.get(i) instanceof JAXBElement
|
||||||
|
? ((JAXBElement<?>) content.get(i)).getValue() : content.get(i);
|
||||||
|
if (v instanceof Tr) {
|
||||||
|
return (Tr) v;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 把 SingleTestResult 的三层嵌套 detail 摊平成行列表,并做新模板专属的行级补充:
|
||||||
|
* errorScope 注入(HV/HI/HP 的标准限值列)、time 缺失时"测点{n}"兜底(F/IMBV/IMBA)、P 有功特例。
|
||||||
|
*/
|
||||||
|
static List<Map<String, String>> flattenRows(SingleTestResult result, String scriptCode) {
|
||||||
|
List<Map<String, String>> out = new ArrayList<>();
|
||||||
|
if (result == null || CollUtil.isEmpty(result.getDetail())) {
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
int seq = 0;
|
||||||
|
for (Map.Entry<String, List<Map<String, List<Map<String, String>>>>> influenceEntry : result.getDetail().entrySet()) {
|
||||||
|
if (influenceEntry.getValue() == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
for (Map<String, List<Map<String, String>>> byError : influenceEntry.getValue()) {
|
||||||
|
if (byError == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
for (Map.Entry<String, List<Map<String, String>>> errorEntry : byError.entrySet()) {
|
||||||
|
String errorScope = errorEntry.getKey();
|
||||||
|
if (errorEntry.getValue() == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
for (Map<String, String> raw : errorEntry.getValue()) {
|
||||||
|
seq++;
|
||||||
|
Map<String, String> row = new LinkedHashMap<>(raw);
|
||||||
|
applyErrorScope(row, scriptCode, errorScope);
|
||||||
|
if (StrUtil.isBlank(row.get(ItemReportKeyEnum.TIME.getKey()))) {
|
||||||
|
row.put(ItemReportKeyEnum.TIME.getKey(), "测点" + seq);
|
||||||
|
}
|
||||||
|
if ("P".equalsIgnoreCase(scriptCode)) {
|
||||||
|
applyPowerMapping(row);
|
||||||
|
}
|
||||||
|
out.add(row);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void applyErrorScope(Map<String, String> row, String scriptCode, String errorScope) {
|
||||||
|
String key = ItemReportKeyEnum.ERROR_SCOPE.getKey();
|
||||||
|
if ("HV".equalsIgnoreCase(scriptCode) || "HP".equalsIgnoreCase(scriptCode)) {
|
||||||
|
String value = StrUtil.isBlank(row.get(key)) ? errorScope : row.get(key);
|
||||||
|
row.put(key, stripTrailingUnit(value));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
row.putIfAbsent(key, errorScope);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String stripTrailingUnit(String value) {
|
||||||
|
if (StrUtil.isBlank(value)) {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
return value.trim().replaceFirst("\\s*(?:(?:[%%‰°℃]|[a-zA-Z]+|[\\u4e00-\\u9fa5]+)\\s*)+$", "");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* P(有功功率)特例:activePower = 三相实测之和;设置类与无功/视在/功率因数数据侧暂无,留空。
|
||||||
|
* spec §6 #2 处置。
|
||||||
|
*/
|
||||||
|
static void applyPowerMapping(Map<String, String> row) {
|
||||||
|
BigDecimal sum = BigDecimal.ZERO;
|
||||||
|
boolean hasValue = false;
|
||||||
|
for (String key : Arrays.asList(ItemReportKeyEnum.TEST_A.getKey(),
|
||||||
|
ItemReportKeyEnum.TEST_B.getKey(), ItemReportKeyEnum.TEST_C.getKey())) {
|
||||||
|
String value = row.get(key);
|
||||||
|
if (StrUtil.isNotBlank(value)) {
|
||||||
|
try {
|
||||||
|
sum = sum.add(new BigDecimal(value.trim()));
|
||||||
|
hasValue = true;
|
||||||
|
} catch (NumberFormatException ignored) {
|
||||||
|
// 非数值(如"--")不参与求和
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
String activePower = row.get(ItemReportKeyEnum.ACTIVE_POWER.getKey());
|
||||||
|
if (hasValue && (StrUtil.isBlank(activePower) || "/".equals(activePower))) {
|
||||||
|
row.put(ItemReportKeyEnum.ACTIVE_POWER.getKey(), sum.toPlainString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void applyHarmonicDerivedValues(List<Map<String, String>> rows, String scriptCode) {
|
||||||
|
if (!"HI".equalsIgnoreCase(scriptCode)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (Map<String, String> row : rows) {
|
||||||
|
String scriptStandardRate = row.get(ItemReportKeyEnum.STANDARD_RATE.getKey());
|
||||||
|
String standardRate = parseNumber(scriptStandardRate) == null ? "" : scriptStandardRate;
|
||||||
|
String testRateA = rate(row.get(ItemReportKeyEnum.TEST_A.getKey()), row.get(ItemReportKeyEnum.BASE_CURRENT_A.getKey()));
|
||||||
|
String testRateB = rate(row.get(ItemReportKeyEnum.TEST_B.getKey()), row.get(ItemReportKeyEnum.BASE_CURRENT_B.getKey()));
|
||||||
|
String testRateC = rate(row.get(ItemReportKeyEnum.TEST_C.getKey()), row.get(ItemReportKeyEnum.BASE_CURRENT_C.getKey()));
|
||||||
|
String errorRateA = difference(testRateA, standardRate);
|
||||||
|
String errorRateB = difference(testRateB, standardRate);
|
||||||
|
String errorRateC = difference(testRateC, standardRate);
|
||||||
|
row.put(ItemReportKeyEnum.STANDARD_RATE.getKey(), standardRate);
|
||||||
|
row.put(ItemReportKeyEnum.TEST_RATE_A.getKey(), testRateA);
|
||||||
|
row.put(ItemReportKeyEnum.TEST_RATE_B.getKey(), testRateB);
|
||||||
|
row.put(ItemReportKeyEnum.TEST_RATE_C.getKey(), testRateC);
|
||||||
|
row.put(ItemReportKeyEnum.ERROR_RATE_A.getKey(), errorRateA);
|
||||||
|
row.put(ItemReportKeyEnum.ERROR_RATE_B.getKey(), errorRateB);
|
||||||
|
row.put(ItemReportKeyEnum.ERROR_RATE_C.getKey(), errorRateC);
|
||||||
|
row.put(ItemReportKeyEnum.ERROR_SCOPE.getKey(), harmonicCurrentErrorScope(standardRate));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String harmonicCurrentErrorScope(String standardRateText) {
|
||||||
|
Double standardRate = parseNumber(standardRateText);
|
||||||
|
if (standardRate == null) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
double limit = standardRate >= 3D ? standardRate * 0.05D : 0.15D;
|
||||||
|
return "±" + format4(limit);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Map<String, String> buildHarmonicFixedPlaceholders(List<Map<String, String>> rows, String scriptCode) {
|
||||||
|
Map<String, String> placeholders = new LinkedHashMap<>();
|
||||||
|
if ("HV".equalsIgnoreCase(scriptCode)) {
|
||||||
|
placeholders.put(ItemReportKeyEnum.STANDARD_THD.getKey(), thd(rows, ItemReportKeyEnum.STANDARD.getKey()));
|
||||||
|
placeholders.put(ItemReportKeyEnum.THD_A.getKey(), thd(rows, ItemReportKeyEnum.TEST_A.getKey()));
|
||||||
|
placeholders.put(ItemReportKeyEnum.THD_B.getKey(), thd(rows, ItemReportKeyEnum.TEST_B.getKey()));
|
||||||
|
placeholders.put(ItemReportKeyEnum.THD_C.getKey(), thd(rows, ItemReportKeyEnum.TEST_C.getKey()));
|
||||||
|
} else if ("HI".equalsIgnoreCase(scriptCode)) {
|
||||||
|
placeholders.put(ItemReportKeyEnum.STANDARD_THD.getKey(), thd(rows, ItemReportKeyEnum.STANDARD_RATE.getKey()));
|
||||||
|
placeholders.put(ItemReportKeyEnum.THD_A.getKey(), thd(rows, ItemReportKeyEnum.TEST_RATE_A.getKey()));
|
||||||
|
placeholders.put(ItemReportKeyEnum.THD_B.getKey(), thd(rows, ItemReportKeyEnum.TEST_RATE_B.getKey()));
|
||||||
|
placeholders.put(ItemReportKeyEnum.THD_C.getKey(), thd(rows, ItemReportKeyEnum.TEST_RATE_C.getKey()));
|
||||||
|
}
|
||||||
|
return placeholders;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void applyHarmonicPowerHeader(Tbl tbl, String scriptCode, int pointNo, List<Map<String, String>> rows) {
|
||||||
|
if (!"HP".equalsIgnoreCase(scriptCode)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Tr firstRow = findFirstRow(tbl.getContent());
|
||||||
|
if (firstRow == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Tc titleCell = cellAt(firstRow, 0);
|
||||||
|
if (titleCell == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
String title = Docx4jUtil.getTextFromCell(titleCell);
|
||||||
|
String baseTitle = StrUtil.blankToDefault(title, StrUtil.EMPTY)
|
||||||
|
.replaceFirst("(测点\\s*\\d+)$", "");
|
||||||
|
setCellText(titleCell, baseTitle + "(测点" + pointNo + ")");
|
||||||
|
fillNextCellByLabel(tbl, "基波电压", firstDataValue(rows, ItemReportKeyEnum.STANDARD_V.getKey()));
|
||||||
|
fillNextCellByLabel(tbl, "基波电流", firstDataValue(rows, ItemReportKeyEnum.STANDARD_I.getKey()));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String firstDataValue(List<Map<String, String>> rows, String key) {
|
||||||
|
if (CollUtil.isEmpty(rows)) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
for (Map<String, String> row : rows) {
|
||||||
|
String value = row.get(key);
|
||||||
|
if (StrUtil.isNotBlank(value) && !"/".equals(value.trim())) {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void fillNextCellByLabel(Tbl tbl, String label, String value) {
|
||||||
|
if (StrUtil.isBlank(value) || tbl == null || tbl.getContent() == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (Object o : tbl.getContent()) {
|
||||||
|
Object v = o instanceof JAXBElement ? ((JAXBElement<?>) o).getValue() : o;
|
||||||
|
if (v instanceof Tr && fillNextCellByLabel((Tr) v, label, value)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean fillNextCellByLabel(Tr row, String label, String value) {
|
||||||
|
if (StrUtil.isBlank(value) || row == null || row.getContent() == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
List<Object> cells = row.getContent();
|
||||||
|
for (int i = 0; i < cells.size() - 1; i++) {
|
||||||
|
Tc labelCell = cellAt(row, i);
|
||||||
|
if (labelCell != null && Docx4jUtil.getTextFromCell(labelCell).contains(label)) {
|
||||||
|
Tc valueCell = cellAt(row, i + 1);
|
||||||
|
if (valueCell != null) {
|
||||||
|
setCellText(valueCell, value);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Tr findFirstRow(List<Object> content) {
|
||||||
|
for (Object o : content) {
|
||||||
|
Object v = o instanceof JAXBElement ? ((JAXBElement<?>) o).getValue() : o;
|
||||||
|
if (v instanceof Tr) {
|
||||||
|
return (Tr) v;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Tc cellAt(Tr row, int index) {
|
||||||
|
if (row == null || row.getContent() == null || row.getContent().size() <= index) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
Object cellObj = row.getContent().get(index);
|
||||||
|
Object value = cellObj instanceof JAXBElement ? ((JAXBElement<?>) cellObj).getValue() : cellObj;
|
||||||
|
return value instanceof Tc ? (Tc) value : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String rate(String numeratorText, String denominatorText) {
|
||||||
|
Double numerator = parseNumber(numeratorText);
|
||||||
|
Double denominator = parseNumber(denominatorText);
|
||||||
|
if (numerator == null || denominator == null || denominator == 0D) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
return format4(numerator / denominator * 100D);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String difference(String minuendText, String subtrahendText) {
|
||||||
|
Double minuend = parseNumber(minuendText);
|
||||||
|
Double subtrahend = parseNumber(subtrahendText);
|
||||||
|
if (minuend == null || subtrahend == null) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
return format4(minuend - subtrahend);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String thd(List<Map<String, String>> rows, String key) {
|
||||||
|
double sum = 0D;
|
||||||
|
boolean hasValue = false;
|
||||||
|
for (Map<String, String> row : rows) {
|
||||||
|
Double value = parseNumber(row.get(key));
|
||||||
|
if (value != null) {
|
||||||
|
sum += value * value;
|
||||||
|
hasValue = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return hasValue ? format4(Math.sqrt(sum)) : "";
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Double parseNumber(String text) {
|
||||||
|
if (StrUtil.isBlank(text) || "/".equals(text.trim()) || "--".equals(text.trim())) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
return Double.parseDouble(text.trim());
|
||||||
|
} catch (NumberFormatException ignored) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String format4(double value) {
|
||||||
|
return String.format(Locale.ROOT, "%.4f", value);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void replaceFixedPlaceholders(Tbl tbl, Map<String, String> values) {
|
||||||
|
if (values.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (Object rowObj : tbl.getContent()) {
|
||||||
|
Object rowValue = rowObj instanceof JAXBElement ? ((JAXBElement<?>) rowObj).getValue() : rowObj;
|
||||||
|
if (!(rowValue instanceof Tr)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
for (Object cellObj : ((Tr) rowValue).getContent()) {
|
||||||
|
Object cellValue = cellObj instanceof JAXBElement ? ((JAXBElement<?>) cellObj).getValue() : cellObj;
|
||||||
|
if (cellValue instanceof Tc) {
|
||||||
|
Tc cell = (Tc) cellValue;
|
||||||
|
String replacement = values.get(Docx4jUtil.getTextFromCell(cell));
|
||||||
|
if (replacement != null) {
|
||||||
|
setCellText(cell, replacement);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void setCellText(Tc cell, String value) {
|
||||||
|
P firstParagraph = null;
|
||||||
|
for (Object content : cell.getContent()) {
|
||||||
|
if (content instanceof P) {
|
||||||
|
firstParagraph = (P) content;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (firstParagraph == null) {
|
||||||
|
firstParagraph = new P();
|
||||||
|
cell.getContent().add(firstParagraph);
|
||||||
|
}
|
||||||
|
boolean written = false;
|
||||||
|
for (Object paragraphObj : cell.getContent()) {
|
||||||
|
if (!(paragraphObj instanceof P)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
P paragraph = (P) paragraphObj;
|
||||||
|
for (Object runObj : paragraph.getContent()) {
|
||||||
|
if (!(runObj instanceof R)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
R run = (R) runObj;
|
||||||
|
for (Object textObj : run.getContent()) {
|
||||||
|
Text text = unwrapText(textObj);
|
||||||
|
if (text != null) {
|
||||||
|
text.setValue(written ? "" : value);
|
||||||
|
written = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!written) {
|
||||||
|
R run = new R();
|
||||||
|
Text text = new Text();
|
||||||
|
text.setValue(value);
|
||||||
|
run.getContent().add(text);
|
||||||
|
firstParagraph.getContent().add(run);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Text unwrapText(Object textObj) {
|
||||||
|
if (textObj instanceof Text) {
|
||||||
|
return (Text) textObj;
|
||||||
|
}
|
||||||
|
if (textObj instanceof JAXBElement && ((JAXBElement<?>) textObj).getValue() instanceof Text) {
|
||||||
|
return (Text) ((JAXBElement<?>) textObj).getValue();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
private static JAXBElement<Tbl> findFirstTable(Docx4jUtil.HeadingContent template) {
|
||||||
|
if (template == null || CollUtil.isEmpty(template.getSubContent())) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
for (Object o : template.getSubContent()) {
|
||||||
|
if (o instanceof JAXBElement && ((JAXBElement<?>) o).getValue() instanceof Tbl) {
|
||||||
|
return (JAXBElement<Tbl>) o;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,276 @@
|
|||||||
|
package com.njcn.gather.report.util;
|
||||||
|
|
||||||
|
import com.njcn.gather.report.pojo.constant.ItemAnchorConstant;
|
||||||
|
import com.njcn.gather.tools.report.util.BookmarkUtil;
|
||||||
|
import com.njcn.gather.tools.report.util.Docx4jUtil;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart;
|
||||||
|
import org.docx4j.wml.CTBookmark;
|
||||||
|
import org.docx4j.wml.CTMarkupRange;
|
||||||
|
import org.docx4j.wml.P;
|
||||||
|
import org.docx4j.wml.R;
|
||||||
|
import org.docx4j.wml.Text;
|
||||||
|
|
||||||
|
import javax.xml.bind.JAXBElement;
|
||||||
|
import java.math.BigInteger;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* "指标锚点"模板的区段隐藏 / 编号重排 / 书签清理工具。
|
||||||
|
* 只服务新路径 dealDataModelByItemAnchor,不被老路径引用。
|
||||||
|
* 设计文档:docs/superpowers/specs/2026-07-02-item-anchor-report-template-design.md §4.2
|
||||||
|
*
|
||||||
|
* @author hongawen
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
public final class ItemAnchorSectionUtil {
|
||||||
|
|
||||||
|
private ItemAnchorSectionUtil() {
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 三级编号:7.x.y(半角点) */
|
||||||
|
private static final Pattern LEVEL3 = Pattern.compile("^7\\.(\\d+)\\.(\\d+)");
|
||||||
|
/** 二级编号:7.x(半角点,排除 7.x.y) */
|
||||||
|
private static final Pattern LEVEL2 = Pattern.compile("^7\\.(\\d+)(?![\\.\\d])");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除已填充 item_* 的空锚点段,避免插入表格前残留一行空段落。
|
||||||
|
* 只处理指标锚点新路径的白名单 item_*;段落内存在正文时保留,防止模板内容被误删。
|
||||||
|
*/
|
||||||
|
public static boolean removeEmptyItemAnchorParagraph(BookmarkUtil.BookmarkInfo info) {
|
||||||
|
if (info == null || info.bookmark == null || info.parentParagraph == null || info.parentContainer == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (ItemAnchorConstant.resolveItemScriptCode(info.bookmark.getName()) == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
String text = Docx4jUtil.getTextFromP(info.parentParagraph);
|
||||||
|
if (text != null && !text.trim().isEmpty()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return info.parentContainer.getContent().remove(info.parentParagraph);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除隐藏指标对应的 sect_{code} 区段(body 块级整段删除)。
|
||||||
|
* GRP 折叠规则:GRP_CHILDREN 中某组的子节全部在 hiddenCodes 中时,删父节区段(含组标题与组内公共文字),
|
||||||
|
* 不再单删子节;父区段定位失败时回退按子节各自删除,避免组和子节一个都删不掉(静默违反红线 2)。
|
||||||
|
*/
|
||||||
|
public static void removeSectRanges(MainDocumentPart part, Set<String> hiddenCodes) {
|
||||||
|
if (part == null || hiddenCodes == null || hiddenCodes.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
List<Object> body = part.getContent();
|
||||||
|
// 单遍扫描收集全部书签区段,后续按名 O(1) 取用
|
||||||
|
Map<String, int[]> allRanges = locateRanges(body);
|
||||||
|
List<int[]> ranges = new ArrayList<>();
|
||||||
|
Set<String> coveredByGrp = new HashSet<>();
|
||||||
|
for (Map.Entry<String, List<String>> entry : ItemAnchorConstant.GRP_CHILDREN.entrySet()) {
|
||||||
|
if (!hiddenCodes.containsAll(entry.getValue())) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
int[] grpRange = allRanges.get((ItemAnchorConstant.SECT_PREFIX + entry.getKey()).toLowerCase());
|
||||||
|
if (grpRange != null) {
|
||||||
|
ranges.add(grpRange);
|
||||||
|
coveredByGrp.addAll(entry.getValue());
|
||||||
|
} else {
|
||||||
|
log.warn("父区段书签 {}{} 定位失败,回退按子节区段各自删除,请检查模板书签是否完整",
|
||||||
|
ItemAnchorConstant.SECT_PREFIX, entry.getKey());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (String code : hiddenCodes) {
|
||||||
|
if (coveredByGrp.contains(code)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
int[] range = allRanges.get((ItemAnchorConstant.SECT_PREFIX + code).toLowerCase());
|
||||||
|
if (range != null) {
|
||||||
|
ranges.add(range);
|
||||||
|
} else {
|
||||||
|
log.warn("区段书签 {}{} 定位失败,该节无法隐藏,请检查模板书签是否完整",
|
||||||
|
ItemAnchorConstant.SECT_PREFIX, code);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 起点降序删除,避免前面的删除让后面的索引失效
|
||||||
|
ranges.sort((a, b) -> Integer.compare(b[0], a[0]));
|
||||||
|
for (int[] range : ranges) {
|
||||||
|
for (int i = range[1]; i >= range[0]; i--) {
|
||||||
|
if (i < body.size()) {
|
||||||
|
body.remove(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 清理全文残留的 item_ / sect_ 书签(start 与配对的 end),其他书签不动。
|
||||||
|
* 已填充节的 sect end 会被 BookmarkUtil.removeBookmark 顺带清掉,留下无 end 的 start,本方法兜底清理。
|
||||||
|
*/
|
||||||
|
public static void stripItemAnchorBookmarks(MainDocumentPart part) {
|
||||||
|
if (part == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Set<BigInteger> ourIds = new HashSet<>();
|
||||||
|
// 第一遍:删 start 并记 id
|
||||||
|
for (Object block : part.getContent()) {
|
||||||
|
P p = asP(block);
|
||||||
|
if (p == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
Iterator<Object> it = p.getContent().iterator();
|
||||||
|
while (it.hasNext()) {
|
||||||
|
Object v = unwrap(it.next());
|
||||||
|
if (v instanceof CTBookmark) {
|
||||||
|
String name = ((CTBookmark) v).getName();
|
||||||
|
if (isOurNamespace(name)) {
|
||||||
|
ourIds.add(((CTBookmark) v).getId());
|
||||||
|
it.remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 第二遍:删配对 end
|
||||||
|
for (Object block : part.getContent()) {
|
||||||
|
P p = asP(block);
|
||||||
|
if (p == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
Iterator<Object> it = p.getContent().iterator();
|
||||||
|
while (it.hasNext()) {
|
||||||
|
Object v = unwrap(it.next());
|
||||||
|
if (v instanceof CTMarkupRange && !(v instanceof CTBookmark)
|
||||||
|
&& ourIds.contains(((CTMarkupRange) v).getId())) {
|
||||||
|
it.remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 第 7 节编号重排:区段删除后,把剩余的 7.x / 7.x.y 标题按出现顺序重写为连续编号。
|
||||||
|
* 顶级"7.准确度检查:"用全角点,正则天然不匹配,保持不动。
|
||||||
|
*/
|
||||||
|
public static void renumberChapter7(MainDocumentPart part) {
|
||||||
|
if (part == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
int l2 = 0;
|
||||||
|
int l3 = 0;
|
||||||
|
for (Object block : part.getContent()) {
|
||||||
|
P p = asP(block);
|
||||||
|
if (p == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
String text = Docx4jUtil.getTextFromP(p);
|
||||||
|
if (text == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
Matcher m3 = LEVEL3.matcher(text);
|
||||||
|
if (m3.find()) {
|
||||||
|
l3++;
|
||||||
|
String newPrefix = "7." + l2 + "." + l3;
|
||||||
|
if (!m3.group().equals(newPrefix)) {
|
||||||
|
replacePrefix(p, m3.group().length(), newPrefix);
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
Matcher m2 = LEVEL2.matcher(text);
|
||||||
|
if (m2.find()) {
|
||||||
|
l2++;
|
||||||
|
l3 = 0;
|
||||||
|
String newPrefix = "7." + l2;
|
||||||
|
if (!m2.group().equals(newPrefix)) {
|
||||||
|
replacePrefix(p, m2.group().length(), newPrefix);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 单遍扫描 body,收集全部段落内书签区段:书签名(小写)→ [start块下标, end块下标]。
|
||||||
|
* 同名书签只记首个(与逐名定位"取第一处命中"语义一致);无配对 end 的 start 不产出条目。
|
||||||
|
*/
|
||||||
|
private static Map<String, int[]> locateRanges(List<Object> body) {
|
||||||
|
Map<String, int[]> out = new HashMap<>();
|
||||||
|
Map<BigInteger, String> openNames = new HashMap<>();
|
||||||
|
Map<BigInteger, Integer> openStarts = new HashMap<>();
|
||||||
|
for (int i = 0; i < body.size(); i++) {
|
||||||
|
P p = asP(body.get(i));
|
||||||
|
if (p == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
for (Object o : p.getContent()) {
|
||||||
|
Object v = unwrap(o);
|
||||||
|
// CTBookmark 继承 CTMarkupRange:先判 start,else 分支天然排除 CTBookmark,即 bookmarkEnd
|
||||||
|
if (v instanceof CTBookmark) {
|
||||||
|
CTBookmark start = (CTBookmark) v;
|
||||||
|
if (start.getName() != null && start.getId() != null) {
|
||||||
|
openNames.put(start.getId(), start.getName().toLowerCase());
|
||||||
|
openStarts.put(start.getId(), i);
|
||||||
|
}
|
||||||
|
} else if (v instanceof CTMarkupRange) {
|
||||||
|
BigInteger id = ((CTMarkupRange) v).getId();
|
||||||
|
String name = openNames.remove(id);
|
||||||
|
if (name != null) {
|
||||||
|
out.putIfAbsent(name, new int[]{openStarts.remove(id), i});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean isOurNamespace(String name) {
|
||||||
|
if (name == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
String lower = name.toLowerCase();
|
||||||
|
return lower.startsWith(ItemAnchorConstant.ITEM_PREFIX) || lower.startsWith(ItemAnchorConstant.SECT_PREFIX);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Object unwrap(Object o) {
|
||||||
|
return (o instanceof JAXBElement) ? ((JAXBElement<?>) o).getValue() : o;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static P asP(Object block) {
|
||||||
|
Object v = unwrap(block);
|
||||||
|
return (v instanceof P) ? (P) v : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 跨 run 替换段首前 oldLen 个字符为 newPrefix(编号可能被 Word 拆进多个 text 节点) */
|
||||||
|
private static void replacePrefix(P p, int oldLen, String newPrefix) {
|
||||||
|
List<Text> texts = new ArrayList<>();
|
||||||
|
collectTexts(p.getContent(), texts);
|
||||||
|
int remaining = oldLen;
|
||||||
|
boolean inserted = false;
|
||||||
|
for (Text t : texts) {
|
||||||
|
if (remaining <= 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
String value = t.getValue() == null ? "" : t.getValue();
|
||||||
|
int cut = Math.min(remaining, value.length());
|
||||||
|
remaining -= cut;
|
||||||
|
String rest = value.substring(cut);
|
||||||
|
t.setValue(inserted ? rest : newPrefix + rest);
|
||||||
|
inserted = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void collectTexts(List<Object> content, List<Text> out) {
|
||||||
|
for (Object o : content) {
|
||||||
|
Object v = unwrap(o);
|
||||||
|
if (v instanceof R) {
|
||||||
|
collectTexts(((R) v).getContent(), out);
|
||||||
|
} else if (v instanceof Text) {
|
||||||
|
out.add((Text) v);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -26,6 +26,7 @@ public enum ResultUnitEnum {
|
|||||||
IMBA("%", "电流不平衡度","IMBA"),
|
IMBA("%", "电流不平衡度","IMBA"),
|
||||||
F("","闪变","F"),
|
F("","闪变","F"),
|
||||||
P("W", "功率","P"),
|
P("W", "功率","P"),
|
||||||
|
ANGLE("°", "相角","Angle"),
|
||||||
|
|
||||||
UNKNOWN("","未知","UNKNOWN"),
|
UNKNOWN("","未知","UNKNOWN"),
|
||||||
;
|
;
|
||||||
|
|||||||
@@ -64,6 +64,9 @@ import com.njcn.gather.result.pojo.param.ResultParam;
|
|||||||
import com.njcn.gather.result.pojo.vo.*;
|
import com.njcn.gather.result.pojo.vo.*;
|
||||||
import com.njcn.gather.result.service.DataCheckAsyncNotifier;
|
import com.njcn.gather.result.service.DataCheckAsyncNotifier;
|
||||||
import com.njcn.gather.result.service.IResultService;
|
import com.njcn.gather.result.service.IResultService;
|
||||||
|
import com.njcn.gather.result.util.AngleResultAssembler;
|
||||||
|
import com.njcn.gather.result.util.PowerResultAssembler;
|
||||||
|
import com.njcn.gather.result.util.UnbalanceResultAssembler;
|
||||||
import com.njcn.gather.script.mapper.PqScriptMapper;
|
import com.njcn.gather.script.mapper.PqScriptMapper;
|
||||||
import com.njcn.gather.script.pojo.param.PqScriptCheckDataParam;
|
import com.njcn.gather.script.pojo.param.PqScriptCheckDataParam;
|
||||||
import com.njcn.gather.script.pojo.param.PqScriptIssueParam;
|
import com.njcn.gather.script.pojo.param.PqScriptIssueParam;
|
||||||
@@ -89,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.pojo.po.DictTree;
|
||||||
import com.njcn.gather.system.dictionary.service.IDictDataService;
|
import com.njcn.gather.system.dictionary.service.IDictDataService;
|
||||||
import com.njcn.gather.system.dictionary.service.IDictTreeService;
|
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.gather.util.StorageUtil;
|
||||||
import com.njcn.http.util.RestTemplateUtil;
|
import com.njcn.http.util.RestTemplateUtil;
|
||||||
import com.njcn.web.utils.ExcelUtil;
|
import com.njcn.web.utils.ExcelUtil;
|
||||||
@@ -536,15 +538,6 @@ public class ResultServiceImpl implements IResultService {
|
|||||||
|
|
||||||
private void ratedScriptTypeName(List<PqScriptDtls> scriptDtlIndexList, Boolean isValueType, TreeDataVO dtlType, DictTree dictTree) {
|
private void ratedScriptTypeName(List<PqScriptDtls> scriptDtlIndexList, Boolean isValueType, TreeDataVO dtlType, DictTree dictTree) {
|
||||||
ResultUnitEnum resultUnitEnumByCode = ResultUnitEnum.getResultUnitEnumByCode(dictTree.getCode());
|
ResultUnitEnum resultUnitEnumByCode = ResultUnitEnum.getResultUnitEnumByCode(dictTree.getCode());
|
||||||
switch (resultUnitEnumByCode) {
|
|
||||||
/**
|
|
||||||
* 频率
|
|
||||||
*/
|
|
||||||
case FREQ:
|
|
||||||
List<PqScriptDtls> f = scriptDtlIndexList.stream().filter(x -> "Freq".equals(x.getValueType())).collect(Collectors.toList());
|
|
||||||
dtlType.setScriptTypeName(dictTree.getName() + "=" + f.get(0).getValue() + ResultUnitEnum.FREQ.getUnit());
|
|
||||||
break;
|
|
||||||
case P: {
|
|
||||||
String unitV;
|
String unitV;
|
||||||
String unitI;
|
String unitI;
|
||||||
if (isValueType) {
|
if (isValueType) {
|
||||||
@@ -554,6 +547,15 @@ public class ResultServiceImpl implements IResultService {
|
|||||||
unitV = ResultUnitEnum.V_ABSOLUTELY.getUnit();
|
unitV = ResultUnitEnum.V_ABSOLUTELY.getUnit();
|
||||||
unitI = ResultUnitEnum.I_ABSOLUTELY.getUnit();
|
unitI = ResultUnitEnum.I_ABSOLUTELY.getUnit();
|
||||||
}
|
}
|
||||||
|
switch (resultUnitEnumByCode) {
|
||||||
|
/**
|
||||||
|
* 频率
|
||||||
|
*/
|
||||||
|
case FREQ:
|
||||||
|
List<PqScriptDtls> f = scriptDtlIndexList.stream().filter(x -> "Freq".equals(x.getValueType())).collect(Collectors.toList());
|
||||||
|
dtlType.setScriptTypeName(dictTree.getName() + "=" + f.get(0).getValue() + ResultUnitEnum.FREQ.getUnit());
|
||||||
|
break;
|
||||||
|
case P: {
|
||||||
List<PqScriptDtls> v = scriptDtlIndexList.stream().filter(x -> "VOL".equals(x.getValueType())).collect(Collectors.toList());
|
List<PqScriptDtls> v = scriptDtlIndexList.stream().filter(x -> "VOL".equals(x.getValueType())).collect(Collectors.toList());
|
||||||
List<PqScriptDtls> i = scriptDtlIndexList.stream().filter(x -> "CUR".equals(x.getValueType())).collect(Collectors.toList());
|
List<PqScriptDtls> i = scriptDtlIndexList.stream().filter(x -> "CUR".equals(x.getValueType())).collect(Collectors.toList());
|
||||||
List<PqScriptDtls> aDtl1 = scriptDtlIndexList.stream().filter(x -> "A".equals(x.getPhase()) && "VOL".equals(x.getValueType())).collect(Collectors.toList());
|
List<PqScriptDtls> aDtl1 = scriptDtlIndexList.stream().filter(x -> "A".equals(x.getPhase()) && "VOL".equals(x.getValueType())).collect(Collectors.toList());
|
||||||
@@ -572,26 +574,14 @@ public class ResultServiceImpl implements IResultService {
|
|||||||
*/
|
*/
|
||||||
case V_RELATIVE:
|
case V_RELATIVE:
|
||||||
case V_ABSOLUTELY:
|
case V_ABSOLUTELY:
|
||||||
String unit;
|
|
||||||
if (isValueType) {
|
|
||||||
unit = ResultUnitEnum.V_RELATIVE.getUnit();
|
|
||||||
} else {
|
|
||||||
unit = ResultUnitEnum.V_ABSOLUTELY.getUnit();
|
|
||||||
}
|
|
||||||
List<PqScriptDtls> v = scriptDtlIndexList.stream().filter(x -> "VOL".equals(x.getValueType())).collect(Collectors.toList());
|
List<PqScriptDtls> v = scriptDtlIndexList.stream().filter(x -> "VOL".equals(x.getValueType())).collect(Collectors.toList());
|
||||||
dtlType.setScriptTypeName(dictTree.getName() + "=" + v.get(0).getValue() + unit);
|
dtlType.setScriptTypeName(dictTree.getName() + "=" + v.get(0).getValue() + unitV);
|
||||||
break;
|
break;
|
||||||
/**
|
/**
|
||||||
* 电流
|
* 电流
|
||||||
*/
|
*/
|
||||||
case I_RELATIVE:
|
case I_RELATIVE:
|
||||||
case I_ABSOLUTELY:
|
case I_ABSOLUTELY:
|
||||||
String unitI;
|
|
||||||
if (isValueType) {
|
|
||||||
unitI = ResultUnitEnum.I_RELATIVE.getUnit();
|
|
||||||
} else {
|
|
||||||
unitI = ResultUnitEnum.I_ABSOLUTELY.getUnit();
|
|
||||||
}
|
|
||||||
List<PqScriptDtls> I = scriptDtlIndexList.stream().filter(x -> "CUR".equals(x.getValueType())).collect(Collectors.toList());
|
List<PqScriptDtls> I = scriptDtlIndexList.stream().filter(x -> "CUR".equals(x.getValueType())).collect(Collectors.toList());
|
||||||
dtlType.setScriptTypeName(dictTree.getName() + "=" + I.get(0).getValue() + unitI);
|
dtlType.setScriptTypeName(dictTree.getName() + "=" + I.get(0).getValue() + unitI);
|
||||||
break;
|
break;
|
||||||
@@ -745,6 +735,35 @@ public class ResultServiceImpl implements IResultService {
|
|||||||
*/
|
*/
|
||||||
case VOLTAGE_MAG:
|
case VOLTAGE_MAG:
|
||||||
case VOLTAGE_DUR:
|
case VOLTAGE_DUR:
|
||||||
|
case ANGLE: {
|
||||||
|
List<PqScriptDtls> aDtlV = scriptDtlIndexList.stream().filter(x -> "A".equals(x.getPhase()) && "VOL".equals(x.getValueType())).collect(Collectors.toList());
|
||||||
|
List<PqScriptDtls> aDtlI = scriptDtlIndexList.stream().filter(x -> "A".equals(x.getPhase()) && "CUR".equals(x.getValueType())).collect(Collectors.toList());
|
||||||
|
List<PqScriptDtls> bDtlV = scriptDtlIndexList.stream().filter(x -> "B".equals(x.getPhase()) && "VOL".equals(x.getValueType())).collect(Collectors.toList());
|
||||||
|
List<PqScriptDtls> bDtlI = scriptDtlIndexList.stream().filter(x -> "B".equals(x.getPhase()) && "CUR".equals(x.getValueType())).collect(Collectors.toList());
|
||||||
|
List<PqScriptDtls> cDtlV = scriptDtlIndexList.stream().filter(x -> "C".equals(x.getPhase()) && "VOL".equals(x.getValueType())).collect(Collectors.toList());
|
||||||
|
List<PqScriptDtls> cDtlI = scriptDtlIndexList.stream().filter(x -> "C".equals(x.getPhase()) && "CUR".equals(x.getValueType())).collect(Collectors.toList());
|
||||||
|
|
||||||
|
StringBuilder scriptTypeName = new StringBuilder();
|
||||||
|
if (CollUtil.isNotEmpty(aDtlV)) {
|
||||||
|
scriptTypeName.append("A相:电压相角=" + aDtlV.get(0).getAngle() + ResultUnitEnum.ANGLE.getUnit());
|
||||||
|
}
|
||||||
|
if (CollUtil.isNotEmpty(aDtlI)) {
|
||||||
|
scriptTypeName.append(",电流相角=" + aDtlI.get(0).getAngle() + ResultUnitEnum.ANGLE.getUnit());
|
||||||
|
}
|
||||||
|
if (CollUtil.isNotEmpty(bDtlV)) {
|
||||||
|
scriptTypeName.append(";B相:电压相角=" + bDtlV.get(0).getAngle() + ResultUnitEnum.ANGLE.getUnit());
|
||||||
|
}
|
||||||
|
if (CollUtil.isNotEmpty(bDtlI)) {
|
||||||
|
scriptTypeName.append(",电流相角=" + bDtlI.get(0).getAngle() + ResultUnitEnum.ANGLE.getUnit());
|
||||||
|
}
|
||||||
|
if (CollUtil.isNotEmpty(cDtlV)) {
|
||||||
|
scriptTypeName.append(";C相:电压相角=" + cDtlV.get(0).getAngle() + ResultUnitEnum.ANGLE.getUnit());
|
||||||
|
}
|
||||||
|
if (CollUtil.isNotEmpty(cDtlI)) {
|
||||||
|
scriptTypeName.append(",电流相角=" + cDtlI.get(0).getAngle() + ResultUnitEnum.ANGLE.getUnit());
|
||||||
|
}
|
||||||
|
dtlType.setScriptTypeName(scriptTypeName.toString());
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
@@ -1451,6 +1470,55 @@ public class ResultServiceImpl implements IResultService {
|
|||||||
List<Integer> indexList = scriptDtlDataVOList.stream().map(PqScriptDtlDataVO::getScriptIndex).distinct().collect(Collectors.toList());
|
List<Integer> indexList = scriptDtlDataVOList.stream().map(PqScriptDtlDataVO::getScriptIndex).distinct().collect(Collectors.toList());
|
||||||
List<PqScriptCheckData> scriptCheckDataList = pqScriptCheckDataService.listCheckData(scriptId, indexList);
|
List<PqScriptCheckData> scriptCheckDataList = pqScriptCheckDataService.listCheckData(scriptId, indexList);
|
||||||
List<String> valueTypeList = scriptCheckDataList.stream().map(PqScriptCheckData::getValueType).distinct().collect(Collectors.toList());
|
List<String> valueTypeList = scriptCheckDataList.stream().map(PqScriptCheckData::getValueType).distinct().collect(Collectors.toList());
|
||||||
|
if (PowerIndexEnum.P.getKey().equalsIgnoreCase(scriptCode)) {
|
||||||
|
SingleNonHarmParam param = new SingleNonHarmParam(planCode, devId, lineNo, valueTypeList, indexList);
|
||||||
|
List<SimAndDigNonHarmonicResult> powerResults = simAndDigNonHarmonicService.queryBySortListWithAdTypeCode(param);
|
||||||
|
List<Map<String, String>> keyFillMapList = PowerResultAssembler.assembleRows(powerResults, scriptDtlDataVOList);
|
||||||
|
if (CollUtil.isEmpty(keyFillMapList)) {
|
||||||
|
log.warn("生成功率类表格数据跳过,结果表数据为空,planCode={}, devId={}, lineNo={}, scriptCode={}, scriptIndexList={}",
|
||||||
|
planCode, devId, lineNo, scriptCode, indexList);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Map<String, List<Map<String, String>>> errorScoperMap = keyFillMapList.stream()
|
||||||
|
.collect(Collectors.groupingBy(map -> map.get(ItemReportKeyEnum.ERROR_SCOPE.getKey()), LinkedHashMap::new, Collectors.toList()));
|
||||||
|
List<Map<String, List<Map<String, String>>>> errorList = new ArrayList<>();
|
||||||
|
errorList.add(errorScoperMap);
|
||||||
|
finalContent.put(affectName, errorList);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (PowerIndexEnum.ANGLE.getKey().equalsIgnoreCase(scriptCode)) {
|
||||||
|
SingleNonHarmParam param = new SingleNonHarmParam(planCode, devId, lineNo, valueTypeList, indexList);
|
||||||
|
List<SimAndDigNonHarmonicResult> angleResults = simAndDigNonHarmonicService.queryBySortListWithAdTypeCode(param);
|
||||||
|
List<Map<String, String>> keyFillMapList = AngleResultAssembler.assembleRows(angleResults);
|
||||||
|
if (CollUtil.isEmpty(keyFillMapList)) {
|
||||||
|
log.warn("生成基波相位类表格数据跳过,结果表数据为空,planCode={}, devId={}, lineNo={}, scriptCode={}, scriptIndexList={}",
|
||||||
|
planCode, devId, lineNo, scriptCode, indexList);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Map<String, List<Map<String, String>>> errorScoperMap = keyFillMapList.stream()
|
||||||
|
.collect(Collectors.groupingBy(map -> map.get(ItemReportKeyEnum.ERROR_SCOPE.getKey()), LinkedHashMap::new, Collectors.toList()));
|
||||||
|
List<Map<String, List<Map<String, String>>>> errorList = new ArrayList<>();
|
||||||
|
errorList.add(errorScoperMap);
|
||||||
|
finalContent.put(affectName, errorList);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (PowerIndexEnum.IMBV.getKey().equalsIgnoreCase(scriptCode)
|
||||||
|
|| PowerIndexEnum.IMBA.getKey().equalsIgnoreCase(scriptCode)) {
|
||||||
|
SingleNonHarmParam param = new SingleNonHarmParam(planCode, devId, lineNo, valueTypeList, indexList);
|
||||||
|
List<SimAndDigNonHarmonicResult> unbalanceResults = simAndDigNonHarmonicService.queryBySortListWithAdTypeCode(param);
|
||||||
|
List<Map<String, String>> keyFillMapList = UnbalanceResultAssembler.assembleRows(unbalanceResults);
|
||||||
|
if (CollUtil.isEmpty(keyFillMapList)) {
|
||||||
|
log.warn("生成不平衡度类表格数据跳过,结果表数据为空,planCode={}, devId={}, lineNo={}, scriptCode={}, scriptIndexList={}",
|
||||||
|
planCode, devId, lineNo, scriptCode, indexList);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Map<String, List<Map<String, String>>> errorScoperMap = keyFillMapList.stream()
|
||||||
|
.collect(Collectors.groupingBy(map -> map.get(ItemReportKeyEnum.ERROR_SCOPE.getKey()), LinkedHashMap::new, Collectors.toList()));
|
||||||
|
List<Map<String, List<Map<String, String>>>> errorList = new ArrayList<>();
|
||||||
|
errorList.add(errorScoperMap);
|
||||||
|
finalContent.put(affectName, errorList);
|
||||||
|
return;
|
||||||
|
}
|
||||||
// 稍作区分,暂态的脚本同一个scriptIndex可以有两个指标,其余脚本每个checkData的valueType对应一个指标结果
|
// 稍作区分,暂态的脚本同一个scriptIndex可以有两个指标,其余脚本每个checkData的valueType对应一个指标结果
|
||||||
if (PowerConstant.VOLTAGE.equalsIgnoreCase(scriptCode)) {
|
if (PowerConstant.VOLTAGE.equalsIgnoreCase(scriptCode)) {
|
||||||
// 暂态的valueType通常只有2个,一个特征幅值,一个持续时间
|
// 暂态的valueType通常只有2个,一个特征幅值,一个持续时间
|
||||||
@@ -1517,6 +1585,8 @@ public class ResultServiceImpl implements IResultService {
|
|||||||
int timeInt = (int) timeDouble;
|
int timeInt = (int) timeDouble;
|
||||||
// 填充结果数据
|
// 填充结果数据
|
||||||
if (fillThreePhaseData(singleResult, timeInt, keyFillMap, scriptCode)) {
|
if (fillThreePhaseData(singleResult, timeInt, keyFillMap, scriptCode)) {
|
||||||
|
fillHarmonicScriptStandard(keyFillMap, scriptCode, dtlsList);
|
||||||
|
fillHarmonicPowerSourceSettings(keyFillMap, scriptCode, scriptDtlDataVOList);
|
||||||
keyFillMapList.add(keyFillMap);
|
keyFillMapList.add(keyFillMap);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -1719,9 +1789,100 @@ public class ResultServiceImpl implements IResultService {
|
|||||||
keyFillMap.put(ItemReportKeyEnum.RESULT.getKey(), result);
|
keyFillMap.put(ItemReportKeyEnum.RESULT.getKey(), result);
|
||||||
errorScope = dealErrorScope(errorScope).concat(unit);
|
errorScope = dealErrorScope(errorScope).concat(unit);
|
||||||
keyFillMap.put(ItemReportKeyEnum.ERROR_SCOPE.getKey(), errorScope);
|
keyFillMap.put(ItemReportKeyEnum.ERROR_SCOPE.getKey(), errorScope);
|
||||||
|
if (PowerIndexEnum.HI.getKey().equalsIgnoreCase(scriptCode)) {
|
||||||
|
fillBaseCurrentData(singleResult, keyFillMap);
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* HI 新模板明细显示谐波电流含有率,装配期需要同一条谐波结果中的三相基波电流作为分母。
|
||||||
|
*/
|
||||||
|
private void fillBaseCurrentData(Object singleResult, Map<String, String> keyFillMap) {
|
||||||
|
putBaseCurrent(singleResult, PowerConstant.PHASE_A, ItemReportKeyEnum.BASE_CURRENT_A.getKey(), keyFillMap);
|
||||||
|
putBaseCurrent(singleResult, PowerConstant.PHASE_B, ItemReportKeyEnum.BASE_CURRENT_B.getKey(), keyFillMap);
|
||||||
|
putBaseCurrent(singleResult, PowerConstant.PHASE_C, ItemReportKeyEnum.BASE_CURRENT_C.getKey(), keyFillMap);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void putBaseCurrent(Object singleResult, String phase, String testKey, Map<String, String> keyFillMap) {
|
||||||
|
DetectionData base = getResultData(singleResult, 1, phase);
|
||||||
|
keyFillMap.put(testKey, formatBaseCurrent(base == null ? null : base.getData()));
|
||||||
|
}
|
||||||
|
|
||||||
|
private String formatBaseCurrent(Double value) {
|
||||||
|
String formatted = value == null ? "" : PubUtils.doubleRoundStr(4, value);
|
||||||
|
return formatted == null ? "" : formatted;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* HI 的标准源输出值在云南模板中展示含有率,优先沿用脚本下发的百分比值。
|
||||||
|
*/
|
||||||
|
private void fillHarmonicScriptStandard(Map<String, String> keyFillMap, String scriptCode, List<PqScriptCheckData> checkDataList) {
|
||||||
|
if (!PowerIndexEnum.HI.getKey().equalsIgnoreCase(scriptCode) || CollUtil.isEmpty(checkDataList)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (StrUtil.isNotBlank(keyFillMap.get(ItemReportKeyEnum.STANDARD_RATE.getKey()))) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
PqScriptCheckData standard = firstCheckValue(checkDataList);
|
||||||
|
if (standard == null || standard.getValue() == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
String value = PubUtils.doubleRoundStr(4, standard.getValue());
|
||||||
|
if (value != null) {
|
||||||
|
keyFillMap.put(ItemReportKeyEnum.STANDARD_RATE.getKey(), value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private PqScriptCheckData firstCheckValue(List<PqScriptCheckData> checkDataList) {
|
||||||
|
for (String phase : Arrays.asList(PowerConstant.PHASE_A, PowerConstant.PHASE_B, PowerConstant.PHASE_C)) {
|
||||||
|
for (PqScriptCheckData data : checkDataList) {
|
||||||
|
if (phase.equalsIgnoreCase(data.getPhase()) && data.getValue() != null) {
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return checkDataList.stream().filter(data -> data.getValue() != null).findFirst().orElse(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* HP 新模板表头需要基波电压/基波电流设置值,来源是同一 scriptIndex 的 VOL/CUR 脚本明细。
|
||||||
|
*/
|
||||||
|
private void fillHarmonicPowerSourceSettings(Map<String, String> keyFillMap, String scriptCode,
|
||||||
|
List<? extends PqScriptDtls> scriptDetails) {
|
||||||
|
if (!PowerIndexEnum.HP.getKey().equalsIgnoreCase(scriptCode) || CollUtil.isEmpty(scriptDetails)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
putScriptSetting(keyFillMap, ItemReportKeyEnum.STANDARD_V.getKey(), firstScriptSetting(scriptDetails, "VOL"));
|
||||||
|
putScriptSetting(keyFillMap, ItemReportKeyEnum.STANDARD_I.getKey(), firstScriptSetting(scriptDetails, "CUR"));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void putScriptSetting(Map<String, String> keyFillMap, String key, PqScriptDtls detail) {
|
||||||
|
if (detail == null || detail.getValue() == null || StrUtil.isNotBlank(keyFillMap.get(key))) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
String value = PubUtils.doubleRoundStr(4, detail.getValue());
|
||||||
|
if (StrUtil.isNotBlank(value)) {
|
||||||
|
keyFillMap.put(key, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private PqScriptDtls firstScriptSetting(List<? extends PqScriptDtls> scriptDetails, String valueType) {
|
||||||
|
for (String phase : Arrays.asList(PowerConstant.PHASE_A, PowerConstant.PHASE_B, PowerConstant.PHASE_C)) {
|
||||||
|
for (PqScriptDtls detail : scriptDetails) {
|
||||||
|
if (valueType.equalsIgnoreCase(detail.getValueType())
|
||||||
|
&& phase.equalsIgnoreCase(detail.getPhase())
|
||||||
|
&& detail.getValue() != null) {
|
||||||
|
return detail;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return scriptDetails.stream()
|
||||||
|
.filter(detail -> valueType.equalsIgnoreCase(detail.getValueType()) && detail.getValue() != null)
|
||||||
|
.findFirst()
|
||||||
|
.orElse(null);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 针对浙江杭州处理脚本输出细节,todo... 需要更改更合理的方式,现在算是写死的了部分
|
* 针对浙江杭州处理脚本输出细节,todo... 需要更改更合理的方式,现在算是写死的了部分
|
||||||
* 目前浙江这边就是(间)谐波电压/电流
|
* 目前浙江这边就是(间)谐波电压/电流
|
||||||
@@ -2042,15 +2203,15 @@ public class ResultServiceImpl implements IResultService {
|
|||||||
DictTree dictTree = dictTreeList.get(0);
|
DictTree dictTree = dictTreeList.get(0);
|
||||||
|
|
||||||
String unit = StorageUtil.unit(dictTree.getCode());
|
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 = "%";
|
unit = "%";
|
||||||
if (DicDataEnum.HI.getCode().equals(dictTree.getCode())) {
|
if (PowerIndexEnum.HI.getKey().equals(dictTree.getCode())) {
|
||||||
unit = "A";
|
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 = "%";
|
unit = "%";
|
||||||
if (DicDataEnum.HSI.getCode().equals(dictTree.getCode())) {
|
if (PowerIndexEnum.HSI.getKey().equals(dictTree.getCode())) {
|
||||||
unit = "A";
|
unit = "A";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3262,10 +3423,10 @@ public class ResultServiceImpl implements IResultService {
|
|||||||
if (CollUtil.isNotEmpty(contrastHarmonicResults)) {
|
if (CollUtil.isNotEmpty(contrastHarmonicResults)) {
|
||||||
ContrastHarmonicResult contrastHarmonicResult = contrastHarmonicResults.get(0);
|
ContrastHarmonicResult contrastHarmonicResult = contrastHarmonicResults.get(0);
|
||||||
List<Double> harmonicNum = null;
|
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());
|
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());
|
harmonicNum = Stream.iterate(0.5, n -> n + 1).limit(50).collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
for (Double n : harmonicNum) {
|
for (Double n : harmonicNum) {
|
||||||
@@ -3331,7 +3492,7 @@ public class ResultServiceImpl implements IResultService {
|
|||||||
|
|
||||||
ContrastNonHarmonicResult contrastNonHarmonicResultStdDev = stdDevNonHarmonicRawDataList.get(i);
|
ContrastNonHarmonicResult contrastNonHarmonicResultStdDev = stdDevNonHarmonicRawDataList.get(i);
|
||||||
rawDataVO.setTimeStdDev(contrastNonHarmonicResultStdDev.getTimeId().format(dtf));
|
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.setUaDev(getValue(contrastNonHarmonicResultDev.getAValue()));
|
||||||
rawDataVO.setUcDev(getValue(contrastNonHarmonicResultDev.getCValue()));
|
rawDataVO.setUcDev(getValue(contrastNonHarmonicResultDev.getCValue()));
|
||||||
rawDataVO.setUaStdDev(getValue(contrastNonHarmonicResultStdDev.getAValue()));
|
rawDataVO.setUaStdDev(getValue(contrastNonHarmonicResultStdDev.getAValue()));
|
||||||
@@ -3350,11 +3511,11 @@ public class ResultServiceImpl implements IResultService {
|
|||||||
if (CollUtil.isNotEmpty(devHarmonicRawDataList) && CollUtil.isNotEmpty(stdDevHarmonicRawDataList)) {
|
if (CollUtil.isNotEmpty(devHarmonicRawDataList) && CollUtil.isNotEmpty(stdDevHarmonicRawDataList)) {
|
||||||
List<Double> harmonicNum = null;
|
List<Double> harmonicNum = null;
|
||||||
boolean isHarm = true;
|
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());
|
harmonicNum = Stream.iterate(2.0, n -> n + 1).limit(49).collect(Collectors.toList());
|
||||||
isHarm = true;
|
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());
|
harmonicNum = Stream.iterate(0.5, n -> n + 1).limit(50).collect(Collectors.toList());
|
||||||
isHarm = false;
|
isHarm = false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,191 @@
|
|||||||
|
package com.njcn.gather.result.util;
|
||||||
|
|
||||||
|
import cn.hutool.core.collection.CollUtil;
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import cn.hutool.json.JSONUtil;
|
||||||
|
import com.njcn.gather.detection.pojo.enums.DetectionCodeEnum;
|
||||||
|
import com.njcn.gather.detection.pojo.vo.DetectionData;
|
||||||
|
import com.njcn.gather.report.pojo.enums.ItemReportKeyEnum;
|
||||||
|
import com.njcn.gather.storage.pojo.po.SimAndDigNonHarmonicResult;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.math.RoundingMode;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.TreeMap;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 基波相位报告结果行装配:云南模板以电压相角为 0 度基准,取 I1A 的 A/B/C 三相电流相角填表。
|
||||||
|
*/
|
||||||
|
public final class AngleResultAssembler {
|
||||||
|
|
||||||
|
private AngleResultAssembler() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<Map<String, String>> assembleRows(List<SimAndDigNonHarmonicResult> results) {
|
||||||
|
List<Map<String, String>> rows = new ArrayList<>();
|
||||||
|
if (CollUtil.isEmpty(results)) {
|
||||||
|
return rows;
|
||||||
|
}
|
||||||
|
Map<Integer, List<SimAndDigNonHarmonicResult>> bySort = results.stream()
|
||||||
|
.filter(result -> result.getSort() != null)
|
||||||
|
.collect(Collectors.groupingBy(SimAndDigNonHarmonicResult::getSort, TreeMap::new, Collectors.toList()));
|
||||||
|
for (List<SimAndDigNonHarmonicResult> sameSortResults : bySort.values()) {
|
||||||
|
SimAndDigNonHarmonicResult currentAngle = firstCurrentAngle(sameSortResults);
|
||||||
|
if (currentAngle == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
DetectionData[] phases = phases(currentAngle);
|
||||||
|
DetectionData primary = firstPresent(phases);
|
||||||
|
if (primary == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
Map<String, String> row = defaultAngleRow();
|
||||||
|
row.put(ItemReportKeyEnum.STANDARD.getKey(), valueOrSlash(primary.getResultData()));
|
||||||
|
putPhaseDetails(row, phases);
|
||||||
|
row.put(ItemReportKeyEnum.ERROR_SCOPE.getKey(), errorScope(primary));
|
||||||
|
row.put(ItemReportKeyEnum.RESULT.getKey(), overallResult(phases));
|
||||||
|
rows.add(row);
|
||||||
|
}
|
||||||
|
return rows;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static SimAndDigNonHarmonicResult firstCurrentAngle(List<SimAndDigNonHarmonicResult> results) {
|
||||||
|
if (CollUtil.isEmpty(results)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
for (SimAndDigNonHarmonicResult result : results) {
|
||||||
|
if (DetectionCodeEnum.I1A.getCode().equalsIgnoreCase(result.getAdType())) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Map<String, String> defaultAngleRow() {
|
||||||
|
Map<String, String> row = new LinkedHashMap<>();
|
||||||
|
for (ItemReportKeyEnum key : Arrays.asList(
|
||||||
|
ItemReportKeyEnum.STANDARD,
|
||||||
|
ItemReportKeyEnum.TEST_A,
|
||||||
|
ItemReportKeyEnum.TEST_B,
|
||||||
|
ItemReportKeyEnum.TEST_C,
|
||||||
|
ItemReportKeyEnum.ERROR_A,
|
||||||
|
ItemReportKeyEnum.ERROR_B,
|
||||||
|
ItemReportKeyEnum.ERROR_C,
|
||||||
|
ItemReportKeyEnum.ERROR_SCOPE,
|
||||||
|
ItemReportKeyEnum.RESULT,
|
||||||
|
ItemReportKeyEnum.RESULT_A,
|
||||||
|
ItemReportKeyEnum.RESULT_B,
|
||||||
|
ItemReportKeyEnum.RESULT_C)) {
|
||||||
|
row.put(key.getKey(), "/");
|
||||||
|
}
|
||||||
|
return row;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static DetectionData[] phases(SimAndDigNonHarmonicResult result) {
|
||||||
|
return new DetectionData[]{
|
||||||
|
parse(result.getAValue()),
|
||||||
|
parse(result.getBValue()),
|
||||||
|
parse(result.getCValue())
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void putPhaseDetails(Map<String, String> row, DetectionData[] phases) {
|
||||||
|
List<String> tests = Arrays.asList(ItemReportKeyEnum.TEST_A.getKey(),
|
||||||
|
ItemReportKeyEnum.TEST_B.getKey(), ItemReportKeyEnum.TEST_C.getKey());
|
||||||
|
List<String> errors = Arrays.asList(ItemReportKeyEnum.ERROR_A.getKey(),
|
||||||
|
ItemReportKeyEnum.ERROR_B.getKey(), ItemReportKeyEnum.ERROR_C.getKey());
|
||||||
|
List<String> results = Arrays.asList(ItemReportKeyEnum.RESULT_A.getKey(),
|
||||||
|
ItemReportKeyEnum.RESULT_B.getKey(), ItemReportKeyEnum.RESULT_C.getKey());
|
||||||
|
for (int i = 0; i < phases.length; i++) {
|
||||||
|
DetectionData phase = phases[i];
|
||||||
|
row.put(tests.get(i), phase == null ? "/" : valueOrSlash(phase.getData()));
|
||||||
|
row.put(errors.get(i), phase == null || phase.getErrorData() == null ? "/" : format(phase.getErrorData()));
|
||||||
|
row.put(results.get(i), phase == null ? "/" : resultText(phase.getIsData()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static DetectionData firstPresent(DetectionData[] values) {
|
||||||
|
for (DetectionData value : values) {
|
||||||
|
if (value != null) {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static DetectionData parse(String value) {
|
||||||
|
if (StrUtil.isBlank(value)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return JSONUtil.toBean(value, DetectionData.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String overallResult(DetectionData[] phases) {
|
||||||
|
boolean hasResult = false;
|
||||||
|
for (DetectionData phase : phases) {
|
||||||
|
if (phase == null || phase.getIsData() == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
hasResult = true;
|
||||||
|
if (phase.getIsData() == 2) {
|
||||||
|
return "不合格";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return hasResult ? "合格" : "/";
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String resultText(Integer isData) {
|
||||||
|
if (isData == null) {
|
||||||
|
return "/";
|
||||||
|
}
|
||||||
|
if (isData == 1) {
|
||||||
|
return "合格";
|
||||||
|
}
|
||||||
|
if (isData == 2) {
|
||||||
|
return "不合格";
|
||||||
|
}
|
||||||
|
return "/";
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String errorScope(DetectionData primary) {
|
||||||
|
String scope = dealErrorScope(primary.getRadius());
|
||||||
|
if (StrUtil.isNotBlank(primary.getUnit()) && !"/".equals(scope)) {
|
||||||
|
return scope + primary.getUnit();
|
||||||
|
}
|
||||||
|
return scope;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String dealErrorScope(String errorScope) {
|
||||||
|
if (StrUtil.isBlank(errorScope)) {
|
||||||
|
return "/";
|
||||||
|
}
|
||||||
|
if (errorScope.contains("~")) {
|
||||||
|
String[] split = errorScope.split("~");
|
||||||
|
String begin = split[0];
|
||||||
|
if (begin.startsWith("-")) {
|
||||||
|
begin = begin.substring(1);
|
||||||
|
}
|
||||||
|
if (split.length > 1 && split[1].equalsIgnoreCase(begin)) {
|
||||||
|
return "±" + begin;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return errorScope;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String valueOrSlash(Double value) {
|
||||||
|
return value == null ? "/" : format(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String format(Double value) {
|
||||||
|
return value == null ? "/" : BigDecimal.valueOf(value).setScale(4, RoundingMode.HALF_UP).toPlainString();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String format(BigDecimal value) {
|
||||||
|
return value == null ? "/" : value.setScale(4, RoundingMode.HALF_UP).toPlainString();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,342 @@
|
|||||||
|
package com.njcn.gather.result.util;
|
||||||
|
|
||||||
|
import cn.hutool.core.collection.CollUtil;
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import cn.hutool.json.JSONUtil;
|
||||||
|
import com.njcn.gather.detection.pojo.vo.DetectionData;
|
||||||
|
import com.njcn.gather.report.pojo.enums.ItemReportKeyEnum;
|
||||||
|
import com.njcn.gather.script.pojo.po.PqScriptDtls;
|
||||||
|
import com.njcn.gather.storage.pojo.po.SimAndDigNonHarmonicResult;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.math.RoundingMode;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.TreeMap;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 功率 P 报告结果行装配:同一 sort 下可能同时存在总有功、总无功、总视在等结果。
|
||||||
|
*/
|
||||||
|
public final class PowerResultAssembler {
|
||||||
|
|
||||||
|
private PowerResultAssembler() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<Map<String, String>> assembleRows(List<SimAndDigNonHarmonicResult> results) {
|
||||||
|
return assembleRows(results, Collections.emptyList());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<Map<String, String>> assembleRows(List<SimAndDigNonHarmonicResult> results,
|
||||||
|
List<? extends PqScriptDtls> scriptDetails) {
|
||||||
|
if (CollUtil.isEmpty(results)) {
|
||||||
|
return new ArrayList<>();
|
||||||
|
}
|
||||||
|
Map<Integer, List<PqScriptDtls>> scriptDetailsBySort = groupScriptDetailsBySort(scriptDetails);
|
||||||
|
Map<Integer, List<SimAndDigNonHarmonicResult>> bySort = results.stream()
|
||||||
|
.filter(result -> result.getSort() != null)
|
||||||
|
.collect(Collectors.groupingBy(SimAndDigNonHarmonicResult::getSort, TreeMap::new, Collectors.toList()));
|
||||||
|
List<Map<String, String>> rows = new ArrayList<>();
|
||||||
|
for (Map.Entry<Integer, List<SimAndDigNonHarmonicResult>> sortEntry : bySort.entrySet()) {
|
||||||
|
List<SimAndDigNonHarmonicResult> sameSortResults = sortEntry.getValue();
|
||||||
|
Map<String, String> row = defaultPowerRow();
|
||||||
|
DetectionData primary = null;
|
||||||
|
boolean hasPowerValue = false;
|
||||||
|
for (SimAndDigNonHarmonicResult result : sameSortResults) {
|
||||||
|
String code = result.getAdType();
|
||||||
|
if (equalsCode(code, "TotW")) {
|
||||||
|
DetectionData data = parse(result.getTValue());
|
||||||
|
hasPowerValue |= putData(row, ItemReportKeyEnum.ACTIVE_POWER.getKey(), data);
|
||||||
|
primary = firstPresent(data, primary);
|
||||||
|
} else if (equalsCode(code, "TotVAr")) {
|
||||||
|
hasPowerValue |= putData(row, ItemReportKeyEnum.REACTIVE_POWER.getKey(), parse(result.getTValue()));
|
||||||
|
} else if (equalsCode(code, "TotVA")) {
|
||||||
|
hasPowerValue |= putData(row, ItemReportKeyEnum.APPARENT_POWER.getKey(), parse(result.getTValue()));
|
||||||
|
} else if (equalsCode(code, "TotPF")) {
|
||||||
|
DetectionData data = parse(result.getTValue());
|
||||||
|
hasPowerValue |= putData(row, ItemReportKeyEnum.POWER_FACTOR.getKey(), data);
|
||||||
|
} else if (equalsCode(code, "PF")) {
|
||||||
|
if (isBlankPowerValue(row, ItemReportKeyEnum.POWER_FACTOR.getKey())) {
|
||||||
|
DetectionData data = firstPresent(parse(result.getTValue()), phaseAverage(result));
|
||||||
|
hasPowerValue |= putData(row, ItemReportKeyEnum.POWER_FACTOR.getKey(), data);
|
||||||
|
}
|
||||||
|
} else if (equalsCode(code, "W")) {
|
||||||
|
DetectionData[] phases = phases(result);
|
||||||
|
if (isBlankPowerValue(row, ItemReportKeyEnum.ACTIVE_POWER.getKey())) {
|
||||||
|
hasPowerValue |= putSum(row, ItemReportKeyEnum.ACTIVE_POWER.getKey(), phases);
|
||||||
|
}
|
||||||
|
putPhaseDetails(row, phases);
|
||||||
|
primary = preferPrimary(primary, firstPresent(phases));
|
||||||
|
} else if (equalsCode(code, "VARW")) {
|
||||||
|
if (isBlankPowerValue(row, ItemReportKeyEnum.REACTIVE_POWER.getKey())) {
|
||||||
|
hasPowerValue |= putSum(row, ItemReportKeyEnum.REACTIVE_POWER.getKey(), phases(result));
|
||||||
|
}
|
||||||
|
} else if (equalsCode(code, "VAW")) {
|
||||||
|
if (isBlankPowerValue(row, ItemReportKeyEnum.APPARENT_POWER.getKey())) {
|
||||||
|
hasPowerValue |= putSum(row, ItemReportKeyEnum.APPARENT_POWER.getKey(), phases(result));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (primary != null) {
|
||||||
|
putPrimary(row, primary);
|
||||||
|
}
|
||||||
|
if (hasPowerValue) {
|
||||||
|
putStandardSourceValues(row, sortEntry.getKey(), scriptDetailsBySort);
|
||||||
|
rows.add(row);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return rows;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Map<String, String> defaultPowerRow() {
|
||||||
|
Map<String, String> row = new LinkedHashMap<>();
|
||||||
|
List<ItemReportKeyEnum> defaultKeys = Arrays.asList(
|
||||||
|
ItemReportKeyEnum.SCRIPT_DETAIL,
|
||||||
|
ItemReportKeyEnum.STANDARD,
|
||||||
|
ItemReportKeyEnum.STANDARD_A,
|
||||||
|
ItemReportKeyEnum.STANDARD_B,
|
||||||
|
ItemReportKeyEnum.STANDARD_C,
|
||||||
|
ItemReportKeyEnum.STANDARD_V,
|
||||||
|
ItemReportKeyEnum.STANDARD_I,
|
||||||
|
ItemReportKeyEnum.STANDARD_U_ANGLE,
|
||||||
|
ItemReportKeyEnum.STANDARD_I_ANGLE,
|
||||||
|
ItemReportKeyEnum.TEST,
|
||||||
|
ItemReportKeyEnum.TEST_A,
|
||||||
|
ItemReportKeyEnum.TEST_B,
|
||||||
|
ItemReportKeyEnum.TEST_C,
|
||||||
|
ItemReportKeyEnum.ERROR,
|
||||||
|
ItemReportKeyEnum.ERROR_A,
|
||||||
|
ItemReportKeyEnum.ERROR_B,
|
||||||
|
ItemReportKeyEnum.ERROR_C,
|
||||||
|
ItemReportKeyEnum.ERROR_SCOPE,
|
||||||
|
ItemReportKeyEnum.RESULT,
|
||||||
|
ItemReportKeyEnum.RESULT_A,
|
||||||
|
ItemReportKeyEnum.RESULT_B,
|
||||||
|
ItemReportKeyEnum.RESULT_C,
|
||||||
|
ItemReportKeyEnum.ACTIVE_POWER,
|
||||||
|
ItemReportKeyEnum.REACTIVE_POWER,
|
||||||
|
ItemReportKeyEnum.APPARENT_POWER,
|
||||||
|
ItemReportKeyEnum.POWER_FACTOR
|
||||||
|
);
|
||||||
|
for (ItemReportKeyEnum key : defaultKeys) {
|
||||||
|
row.put(key.getKey(), "/");
|
||||||
|
}
|
||||||
|
return row;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Map<Integer, List<PqScriptDtls>> groupScriptDetailsBySort(List<? extends PqScriptDtls> scriptDetails) {
|
||||||
|
Map<Integer, List<PqScriptDtls>> bySort = new TreeMap<>();
|
||||||
|
if (CollUtil.isEmpty(scriptDetails)) {
|
||||||
|
return bySort;
|
||||||
|
}
|
||||||
|
for (PqScriptDtls detail : scriptDetails) {
|
||||||
|
if (detail == null || detail.getScriptIndex() == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
bySort.computeIfAbsent(detail.getScriptIndex(), key -> new ArrayList<>()).add(detail);
|
||||||
|
}
|
||||||
|
return bySort;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void putStandardSourceValues(Map<String, String> row, Integer sort,
|
||||||
|
Map<Integer, List<PqScriptDtls>> scriptDetailsBySort) {
|
||||||
|
List<PqScriptDtls> sameSortDetails = scriptDetailsBySort.get(sort);
|
||||||
|
if (CollUtil.isEmpty(sameSortDetails)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
PqScriptDtls voltage = pickPhaseDetail(sameSortDetails, "VOL");
|
||||||
|
PqScriptDtls current = pickPhaseDetail(sameSortDetails, "CUR");
|
||||||
|
putDouble(row, ItemReportKeyEnum.STANDARD_V.getKey(), voltage == null ? null : voltage.getValue());
|
||||||
|
putDouble(row, ItemReportKeyEnum.STANDARD_I.getKey(), current == null ? null : current.getValue());
|
||||||
|
putDouble(row, ItemReportKeyEnum.STANDARD_U_ANGLE.getKey(), voltage == null ? null : voltage.getAngle());
|
||||||
|
putDouble(row, ItemReportKeyEnum.STANDARD_I_ANGLE.getKey(), current == null ? null : current.getAngle());
|
||||||
|
}
|
||||||
|
|
||||||
|
private static PqScriptDtls pickPhaseDetail(List<PqScriptDtls> details, String valueType) {
|
||||||
|
for (String phase : Arrays.asList("A", "B", "C")) {
|
||||||
|
PqScriptDtls detail = firstMatchingDetail(details, valueType, phase);
|
||||||
|
if (detail != null) {
|
||||||
|
return detail;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return firstMatchingDetail(details, valueType, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static PqScriptDtls firstMatchingDetail(List<PqScriptDtls> details, String valueType, String phase) {
|
||||||
|
for (PqScriptDtls detail : details) {
|
||||||
|
if (!equalsCode(detail.getValueType(), valueType)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (phase != null && !equalsCode(detail.getPhase(), phase)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (detail.getValue() != null || detail.getAngle() != null) {
|
||||||
|
return detail;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void putDouble(Map<String, String> row, String key, Double value) {
|
||||||
|
if (value != null) {
|
||||||
|
row.put(key, format(value));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean putData(Map<String, String> row, String key, DetectionData data) {
|
||||||
|
if (data == null || data.getData() == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
row.put(key, format(data.getData()));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean putSum(Map<String, String> row, String key, DetectionData[] phases) {
|
||||||
|
BigDecimal sum = BigDecimal.ZERO;
|
||||||
|
boolean hasValue = false;
|
||||||
|
for (DetectionData phase : phases) {
|
||||||
|
if (phase != null && phase.getData() != null) {
|
||||||
|
sum = sum.add(BigDecimal.valueOf(phase.getData()));
|
||||||
|
hasValue = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (hasValue) {
|
||||||
|
row.put(key, format(sum));
|
||||||
|
}
|
||||||
|
return hasValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean isBlankPowerValue(Map<String, String> row, String key) {
|
||||||
|
String value = row.get(key);
|
||||||
|
return StrUtil.isBlank(value) || "/".equals(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void putPrimary(Map<String, String> row, DetectionData primary) {
|
||||||
|
row.put(ItemReportKeyEnum.STANDARD.getKey(), valueOrSlash(primary.getResultData()));
|
||||||
|
row.put(ItemReportKeyEnum.TEST.getKey(), valueOrSlash(primary.getData()));
|
||||||
|
row.put(ItemReportKeyEnum.ERROR.getKey(), primary.getErrorData() == null ? "/" : format(primary.getErrorData()));
|
||||||
|
row.put(ItemReportKeyEnum.RESULT.getKey(), resultText(primary.getIsData()));
|
||||||
|
String errorScope = dealErrorScope(primary.getRadius());
|
||||||
|
if (StrUtil.isNotBlank(primary.getUnit()) && !"/".equals(errorScope)) {
|
||||||
|
errorScope = errorScope.concat(primary.getUnit());
|
||||||
|
}
|
||||||
|
row.put(ItemReportKeyEnum.ERROR_SCOPE.getKey(), errorScope);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void putPhaseDetails(Map<String, String> row, DetectionData[] phases) {
|
||||||
|
List<String> standards = Arrays.asList(ItemReportKeyEnum.STANDARD_A.getKey(),
|
||||||
|
ItemReportKeyEnum.STANDARD_B.getKey(), ItemReportKeyEnum.STANDARD_C.getKey());
|
||||||
|
List<String> tests = Arrays.asList(ItemReportKeyEnum.TEST_A.getKey(),
|
||||||
|
ItemReportKeyEnum.TEST_B.getKey(), ItemReportKeyEnum.TEST_C.getKey());
|
||||||
|
List<String> errors = Arrays.asList(ItemReportKeyEnum.ERROR_A.getKey(),
|
||||||
|
ItemReportKeyEnum.ERROR_B.getKey(), ItemReportKeyEnum.ERROR_C.getKey());
|
||||||
|
List<String> results = Arrays.asList(ItemReportKeyEnum.RESULT_A.getKey(),
|
||||||
|
ItemReportKeyEnum.RESULT_B.getKey(), ItemReportKeyEnum.RESULT_C.getKey());
|
||||||
|
for (int i = 0; i < phases.length; i++) {
|
||||||
|
DetectionData phase = phases[i];
|
||||||
|
row.put(standards.get(i), phase == null ? "/" : valueOrSlash(phase.getResultData()));
|
||||||
|
row.put(tests.get(i), phase == null ? "/" : valueOrSlash(phase.getData()));
|
||||||
|
row.put(errors.get(i), phase == null || phase.getErrorData() == null ? "/" : format(phase.getErrorData()));
|
||||||
|
row.put(results.get(i), phase == null ? "/" : resultText(phase.getIsData()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static DetectionData phaseAverage(SimAndDigNonHarmonicResult result) {
|
||||||
|
DetectionData[] phases = phases(result);
|
||||||
|
BigDecimal sum = BigDecimal.ZERO;
|
||||||
|
int count = 0;
|
||||||
|
for (DetectionData phase : phases) {
|
||||||
|
if (phase != null && phase.getData() != null) {
|
||||||
|
sum = sum.add(BigDecimal.valueOf(phase.getData()));
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (count == 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
DetectionData data = new DetectionData();
|
||||||
|
data.setData(sum.divide(BigDecimal.valueOf(count), 8, RoundingMode.HALF_UP).doubleValue());
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static DetectionData[] phases(SimAndDigNonHarmonicResult result) {
|
||||||
|
return new DetectionData[]{
|
||||||
|
parse(result.getAValue()),
|
||||||
|
parse(result.getBValue()),
|
||||||
|
parse(result.getCValue())
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private static DetectionData firstPresent(DetectionData... values) {
|
||||||
|
if (values == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
for (DetectionData value : values) {
|
||||||
|
if (value != null) {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static DetectionData preferPrimary(DetectionData current, DetectionData candidate) {
|
||||||
|
return current != null ? current : candidate;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static DetectionData parse(String value) {
|
||||||
|
if (StrUtil.isBlank(value)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return JSONUtil.toBean(value, DetectionData.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean equalsCode(String actual, String expected) {
|
||||||
|
return expected.equalsIgnoreCase(actual);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String resultText(Integer isData) {
|
||||||
|
if (isData == null) {
|
||||||
|
return "/";
|
||||||
|
}
|
||||||
|
if (isData == 1) {
|
||||||
|
return "合格";
|
||||||
|
}
|
||||||
|
if (isData == 2) {
|
||||||
|
return "不合格";
|
||||||
|
}
|
||||||
|
return "/";
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String valueOrSlash(Double value) {
|
||||||
|
return value == null ? "/" : format(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String format(Double value) {
|
||||||
|
return value == null ? "/" : format(BigDecimal.valueOf(value));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String format(BigDecimal value) {
|
||||||
|
return value.setScale(4, RoundingMode.HALF_UP).toPlainString();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String dealErrorScope(String errorScope) {
|
||||||
|
if (StrUtil.isBlank(errorScope)) {
|
||||||
|
return "/";
|
||||||
|
}
|
||||||
|
if (errorScope.contains("~")) {
|
||||||
|
String[] split = errorScope.split("~");
|
||||||
|
String begin = split[0];
|
||||||
|
if (begin.startsWith("-")) {
|
||||||
|
begin = begin.substring(1);
|
||||||
|
}
|
||||||
|
if (split.length > 1 && split[1].equalsIgnoreCase(begin)) {
|
||||||
|
return "±" + begin;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return errorScope;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,165 @@
|
|||||||
|
package com.njcn.gather.result.util;
|
||||||
|
|
||||||
|
import cn.hutool.core.collection.CollUtil;
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import cn.hutool.json.JSONUtil;
|
||||||
|
import com.njcn.gather.detection.pojo.vo.DetectionData;
|
||||||
|
import com.njcn.gather.report.pojo.enums.ItemReportKeyEnum;
|
||||||
|
import com.njcn.gather.storage.pojo.po.SimAndDigNonHarmonicResult;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.math.RoundingMode;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.TreeMap;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* IMBV/IMBA 报告结果行装配:同一 sort 下的不平衡度 T 值与序分量 ABC 值合并为一行。
|
||||||
|
*/
|
||||||
|
public final class UnbalanceResultAssembler {
|
||||||
|
|
||||||
|
private UnbalanceResultAssembler() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<Map<String, String>> assembleRows(List<SimAndDigNonHarmonicResult> results) {
|
||||||
|
if (CollUtil.isEmpty(results)) {
|
||||||
|
return java.util.Collections.emptyList();
|
||||||
|
}
|
||||||
|
Map<Integer, List<SimAndDigNonHarmonicResult>> bySort = results.stream()
|
||||||
|
.filter(result -> result.getSort() != null)
|
||||||
|
.collect(Collectors.groupingBy(SimAndDigNonHarmonicResult::getSort, TreeMap::new, Collectors.toList()));
|
||||||
|
return bySort.values().stream()
|
||||||
|
.map(UnbalanceResultAssembler::assembleRow)
|
||||||
|
.filter(row -> row != null)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Map<String, String> assembleRow(List<SimAndDigNonHarmonicResult> sameSortResults) {
|
||||||
|
Map<String, String> row = defaultRow();
|
||||||
|
boolean hasData = false;
|
||||||
|
for (SimAndDigNonHarmonicResult result : sameSortResults) {
|
||||||
|
String code = result.getAdType();
|
||||||
|
if (equalsAny(code, "V_UNBAN", "I_UNBAN")) {
|
||||||
|
DetectionData data = parse(result.getTValue());
|
||||||
|
if (data != null) {
|
||||||
|
putPrimary(row, data);
|
||||||
|
hasData = true;
|
||||||
|
}
|
||||||
|
} else if (equalsAny(code, "SeqV", "SeqA")) {
|
||||||
|
hasData |= putSequence(row, result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return hasData ? row : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Map<String, String> defaultRow() {
|
||||||
|
Map<String, String> row = new LinkedHashMap<>();
|
||||||
|
for (ItemReportKeyEnum key : Arrays.asList(
|
||||||
|
ItemReportKeyEnum.STANDARD,
|
||||||
|
ItemReportKeyEnum.TEST,
|
||||||
|
ItemReportKeyEnum.ERROR,
|
||||||
|
ItemReportKeyEnum.ERROR_SCOPE,
|
||||||
|
ItemReportKeyEnum.POS_SEQ,
|
||||||
|
ItemReportKeyEnum.NEG_SEQ,
|
||||||
|
ItemReportKeyEnum.ZERO_SEQ,
|
||||||
|
ItemReportKeyEnum.RESULT)) {
|
||||||
|
row.put(key.getKey(), "/");
|
||||||
|
}
|
||||||
|
return row;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void putPrimary(Map<String, String> row, DetectionData data) {
|
||||||
|
row.put(ItemReportKeyEnum.STANDARD.getKey(), valueOrSlash(data.getResultData()));
|
||||||
|
row.put(ItemReportKeyEnum.TEST.getKey(), valueOrSlash(data.getData()));
|
||||||
|
row.put(ItemReportKeyEnum.ERROR.getKey(), data.getErrorData() == null ? "/" : format(data.getErrorData()));
|
||||||
|
String errorScope = dealErrorScope(data.getRadius());
|
||||||
|
if (StrUtil.isNotBlank(data.getUnit()) && !"/".equals(errorScope)) {
|
||||||
|
errorScope = errorScope.concat(data.getUnit());
|
||||||
|
}
|
||||||
|
row.put(ItemReportKeyEnum.ERROR_SCOPE.getKey(), errorScope);
|
||||||
|
row.put(ItemReportKeyEnum.RESULT.getKey(), resultText(data.getIsData()));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean putSequence(Map<String, String> row, SimAndDigNonHarmonicResult result) {
|
||||||
|
boolean hasData = false;
|
||||||
|
hasData |= putData(row, ItemReportKeyEnum.POS_SEQ.getKey(), parse(result.getAValue()));
|
||||||
|
hasData |= putData(row, ItemReportKeyEnum.NEG_SEQ.getKey(), parse(result.getBValue()));
|
||||||
|
hasData |= putData(row, ItemReportKeyEnum.ZERO_SEQ.getKey(), parse(result.getCValue()));
|
||||||
|
return hasData;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean putData(Map<String, String> row, String key, DetectionData data) {
|
||||||
|
if (data == null || data.getData() == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
row.put(key, format(data.getData()));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static DetectionData parse(String value) {
|
||||||
|
if (StrUtil.isBlank(value)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return JSONUtil.toBean(value, DetectionData.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String resultText(Integer isData) {
|
||||||
|
if (isData == null) {
|
||||||
|
return "/";
|
||||||
|
}
|
||||||
|
if (isData == 1) {
|
||||||
|
return "合格";
|
||||||
|
}
|
||||||
|
if (isData == 2) {
|
||||||
|
return "不合格";
|
||||||
|
}
|
||||||
|
if (isData == 4) {
|
||||||
|
return "无法比较";
|
||||||
|
}
|
||||||
|
return "/";
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String valueOrSlash(Double value) {
|
||||||
|
return value == null ? "/" : format(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String format(Double value) {
|
||||||
|
return value == null ? "/" : format(BigDecimal.valueOf(value));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String format(BigDecimal value) {
|
||||||
|
return value.setScale(4, RoundingMode.HALF_UP).toPlainString();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String dealErrorScope(String errorScope) {
|
||||||
|
if (StrUtil.isBlank(errorScope)) {
|
||||||
|
return "/";
|
||||||
|
}
|
||||||
|
if (errorScope.contains("~")) {
|
||||||
|
String[] split = errorScope.split("~");
|
||||||
|
String begin = split[0];
|
||||||
|
if (begin.startsWith("-")) {
|
||||||
|
begin = begin.substring(1);
|
||||||
|
}
|
||||||
|
if (split.length > 1 && split[1].equalsIgnoreCase(begin)) {
|
||||||
|
return "±" + begin;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return errorScope;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean equalsAny(String actual, String... expectedValues) {
|
||||||
|
if (actual == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
for (String expected : expectedValues) {
|
||||||
|
if (expected.equalsIgnoreCase(actual)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -104,6 +104,18 @@ public class PqScriptDtls implements Serializable {
|
|||||||
@TableField("FAfterTime")
|
@TableField("FAfterTime")
|
||||||
private Double fAfterTime;
|
private Double fAfterTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 暂态写入时间(S)
|
||||||
|
*/
|
||||||
|
@TableField("FRampIn")
|
||||||
|
private Double fRampIn;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 暂态写出时间(S)
|
||||||
|
*/
|
||||||
|
@TableField("FRampOut")
|
||||||
|
private Double fRampOut;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 变动频度(次/min)
|
* 变动频度(次/min)
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -65,10 +65,10 @@ public class SourceIssue {
|
|||||||
private String type;
|
private String type;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 是否是功率
|
* 是否按电压执行
|
||||||
*/
|
*/
|
||||||
@JSONField(serialize = false)
|
@JSONField(serialize = false)
|
||||||
private Boolean isP;
|
private String otherType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 多量响量
|
* 多量响量
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ import com.njcn.gather.device.pojo.vo.PqDevVO;
|
|||||||
import com.njcn.gather.device.service.IPqDevService;
|
import com.njcn.gather.device.service.IPqDevService;
|
||||||
import com.njcn.gather.plan.mapper.AdPlanMapper;
|
import com.njcn.gather.plan.mapper.AdPlanMapper;
|
||||||
import com.njcn.gather.plan.pojo.po.AdPlan;
|
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.PqScriptCheckDataMapper;
|
||||||
import com.njcn.gather.script.mapper.PqScriptDtlsMapper;
|
import com.njcn.gather.script.mapper.PqScriptDtlsMapper;
|
||||||
import com.njcn.gather.script.mapper.PqScriptMapper;
|
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.source.service.IPqSourceService;
|
||||||
import com.njcn.gather.system.dictionary.pojo.po.DictTree;
|
import com.njcn.gather.system.dictionary.pojo.po.DictTree;
|
||||||
import com.njcn.gather.system.dictionary.service.IDictTreeService;
|
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.pojo.po.DevType;
|
||||||
import com.njcn.gather.type.service.IDevTypeService;
|
import com.njcn.gather.type.service.IDevTypeService;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
@@ -71,11 +69,11 @@ public class PqScriptDtlsServiceImpl extends ServiceImpl<PqScriptDtlsMapper, PqS
|
|||||||
private final static String FLICKER = "Flicker";
|
private final static String FLICKER = "Flicker";
|
||||||
// @Value("${Dip.fPreTime}")
|
// @Value("${Dip.fPreTime}")
|
||||||
// private Double fPreTime;
|
// private Double fPreTime;
|
||||||
@Value("${Dip.fRampIn}")
|
// @Value("${Dip.fRampIn}")
|
||||||
private Double fRampIn;
|
// private Double fRampIn;
|
||||||
@Value("${Dip.fRampOut}")
|
// @Value("${Dip.fRampOut}")
|
||||||
private Double fRampOut;
|
// private Double fRampOut;
|
||||||
// @Value("${Dip.fAfterTime}")
|
// @Value("${Dip.fAfterTime}")
|
||||||
// private Double fAfterTime;
|
// private Double fAfterTime;
|
||||||
private static final String waveFluType = "CPM";
|
private static final String waveFluType = "CPM";
|
||||||
private static final String waveType = "SQU";
|
private static final String waveType = "SQU";
|
||||||
@@ -205,7 +203,7 @@ public class PqScriptDtlsServiceImpl extends ServiceImpl<PqScriptDtlsMapper, PqS
|
|||||||
checkDataParam.setScriptId(freqDtls.getScriptId());
|
checkDataParam.setScriptId(freqDtls.getScriptId());
|
||||||
checkDataParam.setIndex(freqDtls.getScriptIndex());
|
checkDataParam.setIndex(freqDtls.getScriptIndex());
|
||||||
checkDataParam.setIsValueTypeName(true);
|
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");
|
checkDataParam.setDataType("avg");
|
||||||
issue.setDataType("avg");
|
issue.setDataType("avg");
|
||||||
} else {
|
} else {
|
||||||
@@ -247,10 +245,10 @@ public class PqScriptDtlsServiceImpl extends ServiceImpl<PqScriptDtlsMapper, PqS
|
|||||||
issueAdd(curList, dtlsIList, HARM_I, INHARM_I, freqDtls.getValue(), "I", channelListDTOS, checkDataParam, devFly, isValueType);
|
issueAdd(curList, dtlsIList, HARM_I, INHARM_I, freqDtls.getValue(), "I", channelListDTOS, checkDataParam, devFly, isValueType);
|
||||||
|
|
||||||
issue.setChannelList(channelListDTOS);
|
issue.setChannelList(channelListDTOS);
|
||||||
if (ResultUnitEnum.P.getCode().equals(issue.getType())) {
|
if (PowerIndexEnum.P.getKey().equals(issue.getType()) || PowerIndexEnum.ANGLE.getKey().equals(issue.getType())) {
|
||||||
issue.setIsP(true);
|
issue.setOtherType(issue.getType());
|
||||||
} else {
|
} else {
|
||||||
issue.setIsP(false);
|
issue.setOtherType(null);
|
||||||
}
|
}
|
||||||
sourceIssues.add(issue);
|
sourceIssues.add(issue);
|
||||||
}
|
}
|
||||||
@@ -386,6 +384,8 @@ public class PqScriptDtlsServiceImpl extends ServiceImpl<PqScriptDtlsMapper, PqS
|
|||||||
dip.setRetainTime(dipData.getRetainTime());
|
dip.setRetainTime(dipData.getRetainTime());
|
||||||
dip.setFPreTime(dipData.getFPreTime());
|
dip.setFPreTime(dipData.getFPreTime());
|
||||||
dip.setFAfterTime(dipData.getFAfterTime());
|
dip.setFAfterTime(dipData.getFAfterTime());
|
||||||
|
dip.setFRampIn(dipData.getFRampIn());
|
||||||
|
dip.setFRampOut(dipData.getFRampOut());
|
||||||
info.add(dip);
|
info.add(dip);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -421,7 +421,11 @@ public class PqScriptDtlsServiceImpl extends ServiceImpl<PqScriptDtlsMapper, PqS
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<PqScriptDtlsParam.CheckData> scriptDtlsCheckDataList(PqScriptDtlsParam sourceIssue) {
|
public List<PqScriptDtlsParam.CheckData> scriptDtlsCheckDataList(PqScriptDtlsParam sourceIssue) {
|
||||||
// Boolean valueType = pqScriptMapper.selectScriptIsValueType(sourceIssue.getScriptId());
|
Boolean valueType = pqScriptMapper.selectScriptIsValueType(sourceIssue.getScriptId());
|
||||||
|
double radio = 1;
|
||||||
|
if (valueType) {
|
||||||
|
radio = 100;
|
||||||
|
}
|
||||||
|
|
||||||
List<PqScriptDtlsParam.CheckData> info = new ArrayList<>();
|
List<PqScriptDtlsParam.CheckData> info = new ArrayList<>();
|
||||||
//获取所有下拉值情况
|
//获取所有下拉值情况
|
||||||
@@ -482,6 +486,7 @@ public class PqScriptDtlsServiceImpl extends ServiceImpl<PqScriptDtlsMapper, PqS
|
|||||||
rmsCheck(info, channelListDTO, channelU, checkArchive, true);
|
rmsCheck(info, channelListDTO, channelU, checkArchive, true);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case U1A:
|
||||||
case VA:
|
case VA:
|
||||||
if (CollUtil.isNotEmpty(channelList)) {
|
if (CollUtil.isNotEmpty(channelList)) {
|
||||||
channelU = channelList.stream().filter(x -> x.getChannelType().contains("U")).collect(Collectors.toList());
|
channelU = channelList.stream().filter(x -> x.getChannelType().contains("U")).collect(Collectors.toList());
|
||||||
@@ -583,6 +588,23 @@ public class PqScriptDtlsServiceImpl extends ServiceImpl<PqScriptDtlsMapper, PqS
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case IRMS:
|
case IRMS:
|
||||||
|
case I1A:
|
||||||
|
if (CollUtil.isNotEmpty(channelList)) {
|
||||||
|
channelI = channelList.stream().filter(x -> x.getChannelType().contains("I")).collect(Collectors.toList());
|
||||||
|
for (PqScriptDtlsParam.ChannelListDTO listDTO : channelI) {
|
||||||
|
if (listDTO.getChannelFlag()) {
|
||||||
|
checkData = new PqScriptDtlsParam.CheckData();
|
||||||
|
checkData.setErrorFlag(channelListDTO.getErrorFlag());
|
||||||
|
checkData.setEnable(channelListDTO.getEnable());
|
||||||
|
checkData.setValue(listDTO.getFPhase());
|
||||||
|
checkData.setValueType(channelListDTO.getValueType());
|
||||||
|
checkData.setPid(channelListDTO.getPid());
|
||||||
|
setCheckValue(checkArchive, checkData, listDTO);
|
||||||
|
info.add(checkData);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
case IA:
|
case IA:
|
||||||
if (CollUtil.isNotEmpty(channelList)) {
|
if (CollUtil.isNotEmpty(channelList)) {
|
||||||
channelI = channelList.stream().filter(x -> x.getChannelType().contains("I")).collect(Collectors.toList());
|
channelI = channelList.stream().filter(x -> x.getChannelType().contains("I")).collect(Collectors.toList());
|
||||||
@@ -637,10 +659,12 @@ public class PqScriptDtlsServiceImpl extends ServiceImpl<PqScriptDtlsMapper, PqS
|
|||||||
checkData.setErrorFlag(channelListDTO.getErrorFlag());
|
checkData.setErrorFlag(channelListDTO.getErrorFlag());
|
||||||
checkData.setEnable(channelListDTO.getEnable());
|
checkData.setEnable(channelListDTO.getEnable());
|
||||||
//电压*电流*cos(电压角度-电流角度)
|
//电压*电流*cos(电压角度-电流角度)
|
||||||
checkData.setValue(channelI.get(0).getFAmp() * listDTO.getFAmp() / 100 * Math.cos((listDTO.getFPhase() - channelI.get(0).getFPhase()) * Math.PI / 180));
|
double v = listDTO.getFPhase() - channelI.get(0).getFPhase();
|
||||||
// if (valueType) {
|
if (v == 90 || v == -90 || v == 270 || v == -270) {
|
||||||
// checkData.setValue(checkData.getValue() * 57.74 * 5);
|
checkData.setValue(0.0);
|
||||||
// }
|
} else {
|
||||||
|
checkData.setValue(channelI.get(0).getFAmp() * listDTO.getFAmp() / radio * Math.cos(v * Math.PI / 180));
|
||||||
|
}
|
||||||
setCheck(info, checkData, channelListDTO, checkArchive, listDTO);
|
setCheck(info, checkData, channelListDTO, checkArchive, listDTO);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -659,8 +683,13 @@ public class PqScriptDtlsServiceImpl extends ServiceImpl<PqScriptDtlsMapper, PqS
|
|||||||
checkData = new PqScriptDtlsParam.CheckData();
|
checkData = new PqScriptDtlsParam.CheckData();
|
||||||
checkData.setErrorFlag(channelListDTO.getErrorFlag());
|
checkData.setErrorFlag(channelListDTO.getErrorFlag());
|
||||||
checkData.setEnable(channelListDTO.getEnable());
|
checkData.setEnable(channelListDTO.getEnable());
|
||||||
//电压*电流*cos(电压角度-电流角度)
|
//电压*电流*sin(电压角度-电流角度)
|
||||||
checkData.setValue(channelI.get(0).getFAmp() * listDTO.getFAmp() / 100 * Math.sin((listDTO.getFPhase() - channelI.get(0).getFPhase()) * Math.PI / 180));
|
double v = listDTO.getFPhase() - channelI.get(0).getFPhase();
|
||||||
|
if (v == 0 || v == 360 || v == 180 || v == -180) {
|
||||||
|
checkData.setValue(0.0);
|
||||||
|
} else {
|
||||||
|
checkData.setValue(channelI.get(0).getFAmp() * listDTO.getFAmp() / radio * Math.sin(v * Math.PI / 180));
|
||||||
|
}
|
||||||
// if (valueType) {
|
// if (valueType) {
|
||||||
// checkData.setValue(checkData.getValue() * 57.74 * 5);
|
// checkData.setValue(checkData.getValue() * 57.74 * 5);
|
||||||
// }
|
// }
|
||||||
@@ -682,16 +711,151 @@ public class PqScriptDtlsServiceImpl extends ServiceImpl<PqScriptDtlsMapper, PqS
|
|||||||
checkData = new PqScriptDtlsParam.CheckData();
|
checkData = new PqScriptDtlsParam.CheckData();
|
||||||
checkData.setErrorFlag(channelListDTO.getErrorFlag());
|
checkData.setErrorFlag(channelListDTO.getErrorFlag());
|
||||||
checkData.setEnable(channelListDTO.getEnable());
|
checkData.setEnable(channelListDTO.getEnable());
|
||||||
//电压*电流*cos(电压角度-电流角度)
|
checkData.setValue(channelI.get(0).getFAmp() * listDTO.getFAmp() / radio);
|
||||||
checkData.setValue(channelI.get(0).getFAmp() * listDTO.getFAmp() / 100);
|
|
||||||
// if (valueType) {
|
|
||||||
// checkData.setValue(checkData.getValue() * 57.74 * 5);
|
|
||||||
// }
|
|
||||||
setCheck(info, checkData, channelListDTO, checkArchive, listDTO);
|
setCheck(info, checkData, channelListDTO, checkArchive, listDTO);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case PF:
|
||||||
|
channelU = channelList.stream().filter(x -> x.getChannelType().contains("U")).collect(Collectors.toList());
|
||||||
|
if (CollUtil.isNotEmpty(channelU)) {
|
||||||
|
for (PqScriptDtlsParam.ChannelListDTO listDTO : channelU) {
|
||||||
|
//获取电流通道
|
||||||
|
channelI = channelList.stream()
|
||||||
|
// .filter(PqScriptDtlsParam.ChannelListDTO::getHarmFlag)
|
||||||
|
.filter(x -> x.getChannelType().contains("I" + listDTO.getChannelType().substring(1, 2)))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
if (CollUtil.isNotEmpty(channelI)) {
|
||||||
|
checkData = new PqScriptDtlsParam.CheckData();
|
||||||
|
checkData.setErrorFlag(channelListDTO.getErrorFlag());
|
||||||
|
checkData.setEnable(channelListDTO.getEnable());
|
||||||
|
//cos(电压角度-电流角度)
|
||||||
|
double v = listDTO.getFPhase() - channelI.get(0).getFPhase();
|
||||||
|
if (v == 90 || v == -90 || v == 270 || v == -270) {
|
||||||
|
checkData.setValue(0.0);
|
||||||
|
} else {
|
||||||
|
checkData.setValue(Math.cos(v * Math.PI / 180));
|
||||||
|
}
|
||||||
|
setCheck(info, checkData, channelListDTO, checkArchive, listDTO);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case TOTW:
|
||||||
|
channelU = channelList.stream().filter(x -> x.getChannelType().contains("U")).collect(Collectors.toList());
|
||||||
|
if (CollUtil.isNotEmpty(channelU)) {
|
||||||
|
Double value = 0.0;
|
||||||
|
for (PqScriptDtlsParam.ChannelListDTO listDTO : channelU) {
|
||||||
|
//获取电流通道
|
||||||
|
channelI = channelList.stream()
|
||||||
|
// .filter(PqScriptDtlsParam.ChannelListDTO::getHarmFlag)
|
||||||
|
.filter(x -> x.getChannelType().contains("I" + listDTO.getChannelType().substring(1, 2)))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
if (CollUtil.isNotEmpty(channelI)) {
|
||||||
|
//cos(电压角度-电流角度)
|
||||||
|
double v = listDTO.getFPhase() - channelI.get(0).getFPhase();
|
||||||
|
if (v == 90 || v == -90 || v == 270 || v == -270) {
|
||||||
|
value += 0.0;
|
||||||
|
} else {
|
||||||
|
value += channelI.get(0).getFAmp() * listDTO.getFAmp() / radio * Math.cos(v * Math.PI / 180);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
checkData = new PqScriptDtlsParam.CheckData();
|
||||||
|
checkData.setErrorFlag(channelListDTO.getErrorFlag());
|
||||||
|
checkData.setEnable(channelListDTO.getEnable());
|
||||||
|
checkData.setValue(value);
|
||||||
|
checkData.setPhase("T");
|
||||||
|
checkData.setPid(channelListDTO.getPid());
|
||||||
|
checkData.setValueType(channelListDTO.getValueType());
|
||||||
|
info.add(checkData);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case TOTVAR:
|
||||||
|
channelU = channelList.stream().filter(x -> x.getChannelType().contains("U")).collect(Collectors.toList());
|
||||||
|
if (CollUtil.isNotEmpty(channelU)) {
|
||||||
|
Double value = 0.0;
|
||||||
|
for (PqScriptDtlsParam.ChannelListDTO listDTO : channelU) {
|
||||||
|
//获取电流通道
|
||||||
|
channelI = channelList.stream()
|
||||||
|
.filter(x -> x.getChannelType().contains("I" + listDTO.getChannelType().substring(1, 2)))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
if (CollUtil.isNotEmpty(channelI)) {
|
||||||
|
//电压*电流*sin(电压角度-电流角度)
|
||||||
|
double v = listDTO.getFPhase() - channelI.get(0).getFPhase();
|
||||||
|
if (v == 0 || v == 360 || v == 180 || v == -180) {
|
||||||
|
value += 0.0;
|
||||||
|
} else {
|
||||||
|
value += channelI.get(0).getFAmp() * listDTO.getFAmp() / radio * Math.sin(v * Math.PI / 180);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
checkData = new PqScriptDtlsParam.CheckData();
|
||||||
|
checkData.setErrorFlag(channelListDTO.getErrorFlag());
|
||||||
|
checkData.setEnable(channelListDTO.getEnable());
|
||||||
|
checkData.setValue(value);
|
||||||
|
checkData.setPhase("T");
|
||||||
|
checkData.setPid(channelListDTO.getPid());
|
||||||
|
checkData.setValueType(channelListDTO.getValueType());
|
||||||
|
info.add(checkData);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case TOTVA:
|
||||||
|
channelU = channelList.stream().filter(x -> x.getChannelType().contains("U")).collect(Collectors.toList());
|
||||||
|
if (CollUtil.isNotEmpty(channelU)) {
|
||||||
|
Double value = 0.0;
|
||||||
|
for (PqScriptDtlsParam.ChannelListDTO listDTO : channelU) {
|
||||||
|
//获取电流通道
|
||||||
|
channelI = channelList.stream()
|
||||||
|
.filter(x -> x.getChannelType().contains("I" + listDTO.getChannelType().substring(1, 2)))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
if (CollUtil.isNotEmpty(channelI)) {
|
||||||
|
value += channelI.get(0).getFAmp() * listDTO.getFAmp() / radio;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
checkData = new PqScriptDtlsParam.CheckData();
|
||||||
|
checkData.setErrorFlag(channelListDTO.getErrorFlag());
|
||||||
|
checkData.setEnable(channelListDTO.getEnable());
|
||||||
|
checkData.setValue(value);
|
||||||
|
checkData.setPhase("T");
|
||||||
|
checkData.setPid(channelListDTO.getPid());
|
||||||
|
checkData.setValueType(channelListDTO.getValueType());
|
||||||
|
info.add(checkData);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case TOTPF:
|
||||||
|
channelU = channelList.stream().filter(x -> x.getChannelType().contains("U")).collect(Collectors.toList());
|
||||||
|
if (CollUtil.isNotEmpty(channelU)) {
|
||||||
|
Double valueTotW = 0.0;
|
||||||
|
Double valueTotVA = 0.0;
|
||||||
|
for (PqScriptDtlsParam.ChannelListDTO listDTO : channelU) {
|
||||||
|
//获取电流通道
|
||||||
|
channelI = channelList.stream()
|
||||||
|
// .filter(PqScriptDtlsParam.ChannelListDTO::getHarmFlag)
|
||||||
|
.filter(x -> x.getChannelType().contains("I" + listDTO.getChannelType().substring(1, 2)))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
if (CollUtil.isNotEmpty(channelI)) {
|
||||||
|
//cos(电压角度-电流角度)
|
||||||
|
double v = listDTO.getFPhase() - channelI.get(0).getFPhase();
|
||||||
|
if (v == 90 || v == -90 || v == 270 || v == -270) {
|
||||||
|
valueTotW += 0.0;
|
||||||
|
} else {
|
||||||
|
valueTotW += channelI.get(0).getFAmp() * listDTO.getFAmp() / radio * Math.cos(v * Math.PI / 180);
|
||||||
|
}
|
||||||
|
valueTotVA += channelI.get(0).getFAmp() * listDTO.getFAmp() / radio;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
checkData = new PqScriptDtlsParam.CheckData();
|
||||||
|
checkData.setErrorFlag(channelListDTO.getErrorFlag());
|
||||||
|
checkData.setEnable(channelListDTO.getEnable());
|
||||||
|
checkData.setValue(valueTotW / valueTotVA);
|
||||||
|
checkData.setPhase("T");
|
||||||
|
checkData.setPid(channelListDTO.getPid());
|
||||||
|
checkData.setValueType(channelListDTO.getValueType());
|
||||||
|
info.add(checkData);
|
||||||
|
}
|
||||||
|
break;
|
||||||
case UNKNOWN_ERROR:
|
case UNKNOWN_ERROR:
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@@ -1151,8 +1315,8 @@ public class PqScriptDtlsServiceImpl extends ServiceImpl<PqScriptDtlsMapper, PqS
|
|||||||
dipDataDTO.setFRetainTime(0.0);
|
dipDataDTO.setFRetainTime(0.0);
|
||||||
|
|
||||||
// dipDataDTO.setFPreTime(fPreTime);
|
// dipDataDTO.setFPreTime(fPreTime);
|
||||||
dipDataDTO.setFRampIn(fRampIn);
|
// dipDataDTO.setFRampIn(fRampIn);
|
||||||
dipDataDTO.setFRampOut(fRampOut);
|
// dipDataDTO.setFRampOut(fRampOut);
|
||||||
// dipDataDTO.setFAfterTime(fAfterTime);
|
// dipDataDTO.setFAfterTime(fAfterTime);
|
||||||
|
|
||||||
|
|
||||||
@@ -1209,6 +1373,8 @@ public class PqScriptDtlsServiceImpl extends ServiceImpl<PqScriptDtlsMapper, PqS
|
|||||||
dipDataDTO.setFTransValue(dip.getTransValue());
|
dipDataDTO.setFTransValue(dip.getTransValue());
|
||||||
dipDataDTO.setFPreTime(dip.getFPreTime());
|
dipDataDTO.setFPreTime(dip.getFPreTime());
|
||||||
dipDataDTO.setFAfterTime(dip.getFAfterTime());
|
dipDataDTO.setFAfterTime(dip.getFAfterTime());
|
||||||
|
dipDataDTO.setFRampIn(dip.getFRampIn());
|
||||||
|
dipDataDTO.setFRampOut(dip.getFRampOut());
|
||||||
if (devFly) {
|
if (devFly) {
|
||||||
// if (isValueType) {
|
// if (isValueType) {
|
||||||
dipDataDTO.setFTransValue(dip.getTransValue());
|
dipDataDTO.setFTransValue(dip.getTransValue());
|
||||||
|
|||||||
@@ -0,0 +1,47 @@
|
|||||||
|
package com.njcn.gather.detection.service.impl;
|
||||||
|
|
||||||
|
import com.njcn.gather.script.pojo.po.SourceIssue;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertFalse;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
|
public class PreDetectionServiceImplTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void isFirstFormalIssueOfBigItem_returnsTrueForFirstIssueOfType() {
|
||||||
|
List<SourceIssue> allIssues = Arrays.asList(issue(10, "voltage"), issue(20, "voltage"), issue(30, "current"));
|
||||||
|
|
||||||
|
assertTrue(PreDetectionServiceImpl.isFirstFormalIssueOfBigItem(allIssues, issue(10, "voltage"), "voltage"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void isFirstFormalIssueOfBigItem_returnsFalseWhenResumingInsideSameBigItem() {
|
||||||
|
List<SourceIssue> allIssues = Arrays.asList(issue(10, "voltage"), issue(20, "voltage"), issue(30, "current"));
|
||||||
|
|
||||||
|
assertFalse(PreDetectionServiceImpl.isFirstFormalIssueOfBigItem(allIssues, issue(20, "voltage"), "voltage"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void isFirstFormalIssueOfBigItem_usesOtherTypeAsBigItemType() {
|
||||||
|
List<SourceIssue> allIssues = Arrays.asList(otherTypeIssue(10, "V", "voltage"), otherTypeIssue(20, "V", "voltage"));
|
||||||
|
|
||||||
|
assertTrue(PreDetectionServiceImpl.isFirstFormalIssueOfBigItem(allIssues, otherTypeIssue(10, "V", "voltage"), "voltage"));
|
||||||
|
}
|
||||||
|
|
||||||
|
private SourceIssue issue(Integer index, String type) {
|
||||||
|
SourceIssue issue = new SourceIssue();
|
||||||
|
issue.setIndex(index);
|
||||||
|
issue.setType(type);
|
||||||
|
return issue;
|
||||||
|
}
|
||||||
|
|
||||||
|
private SourceIssue otherTypeIssue(Integer index, String type, String otherType) {
|
||||||
|
SourceIssue issue = issue(index, type);
|
||||||
|
issue.setOtherType(otherType);
|
||||||
|
return issue;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,55 @@
|
|||||||
|
package com.njcn.gather.device.util;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import javax.imageio.ImageIO;
|
||||||
|
import java.awt.Color;
|
||||||
|
import java.awt.image.BufferedImage;
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertFalse;
|
||||||
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
import static org.junit.Assert.assertNull;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
|
public class PqDevImageSupportTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void buildEchoPayloadReturnsEmptyFieldsWhenImageMissing() {
|
||||||
|
PqDevImageSupport.ImageEchoPayload payload = PqDevImageSupport.buildEchoPayload(null);
|
||||||
|
|
||||||
|
assertFalse(payload.isHasImage());
|
||||||
|
assertNull(payload.getImageBase64());
|
||||||
|
assertNull(payload.getImageContentType());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void buildEchoPayloadDetectsPngAndCreatesBase64() throws Exception {
|
||||||
|
byte[] imageBytes = createImageBytes("png");
|
||||||
|
|
||||||
|
PqDevImageSupport.ImageEchoPayload payload = PqDevImageSupport.buildEchoPayload(imageBytes);
|
||||||
|
|
||||||
|
assertTrue(payload.isHasImage());
|
||||||
|
assertEquals("image/png", payload.getImageContentType());
|
||||||
|
assertNotNull(payload.getImageBase64());
|
||||||
|
assertFalse(payload.getImageBase64().isEmpty());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = IllegalArgumentException.class)
|
||||||
|
public void detectContentTypeRejectsInvalidImageBytes() {
|
||||||
|
PqDevImageSupport.detectContentType(new byte[]{1, 2, 3, 4});
|
||||||
|
}
|
||||||
|
|
||||||
|
private byte[] createImageBytes(String format) throws Exception {
|
||||||
|
BufferedImage image = new BufferedImage(2, 2, BufferedImage.TYPE_INT_RGB);
|
||||||
|
image.setRGB(0, 0, Color.RED.getRGB());
|
||||||
|
image.setRGB(1, 0, Color.GREEN.getRGB());
|
||||||
|
image.setRGB(0, 1, Color.BLUE.getRGB());
|
||||||
|
image.setRGB(1, 1, Color.WHITE.getRGB());
|
||||||
|
|
||||||
|
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||||
|
ImageIO.write(image, format, outputStream);
|
||||||
|
return outputStream.toByteArray();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
package com.njcn.gather.report.pojo.constant;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
public class ItemAnchorConstantTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void resolveItemScriptCode_normal() {
|
||||||
|
assertEquals("V", ItemAnchorConstant.resolveItemScriptCode("item_V"));
|
||||||
|
assertEquals("FREQ", ItemAnchorConstant.resolveItemScriptCode("ITEM_FREQ")); // 前缀大小写不敏感
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void resolveItemScriptCode_nonAnchor() {
|
||||||
|
assertNull(ItemAnchorConstant.resolveItemScriptCode("_GoBack"));
|
||||||
|
assertNull(ItemAnchorConstant.resolveItemScriptCode("data_line"));
|
||||||
|
assertNull(ItemAnchorConstant.resolveItemScriptCode("sect_V"));
|
||||||
|
assertNull(ItemAnchorConstant.resolveItemScriptCode(null));
|
||||||
|
assertNull(ItemAnchorConstant.resolveItemScriptCode("item_")); // 空 code 视为非法
|
||||||
|
}
|
||||||
|
|
||||||
|
/** F3:白名单外的 item_ 书签(如作者手工遗留的 item_1)不得解析成功,否则老模板会整体误入新路径 */
|
||||||
|
@Test
|
||||||
|
public void resolveItemScriptCode_unknownCode_rejected() {
|
||||||
|
assertNull(ItemAnchorConstant.resolveItemScriptCode("item_1"));
|
||||||
|
assertNull(ItemAnchorConstant.resolveItemScriptCode("item_XYZ"));
|
||||||
|
assertNull(ItemAnchorConstant.resolveItemScriptCode("item_HSV")); // TIME 里有但云南模板白名单没有
|
||||||
|
}
|
||||||
|
|
||||||
|
/** F3:白名单命中时大小写归一为规范大写(scriptMap / 模板 H5 分组 key 均为大写) */
|
||||||
|
@Test
|
||||||
|
public void resolveItemScriptCode_caseNormalized() {
|
||||||
|
assertEquals("HV", ItemAnchorConstant.resolveItemScriptCode("item_hv"));
|
||||||
|
assertEquals("IMBV", ItemAnchorConstant.resolveItemScriptCode("Item_imbv"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void grpChildren_mapping() {
|
||||||
|
assertEquals(java.util.Arrays.asList("V", "I", "P", "ANGLE"), ItemAnchorConstant.GRP_CHILDREN.get("GRP_FUND"));
|
||||||
|
assertEquals(java.util.Arrays.asList("IMBV", "IMBA"), ItemAnchorConstant.GRP_CHILDREN.get("GRP_UNB"));
|
||||||
|
assertEquals(java.util.Arrays.asList("HV", "HI", "HP"), ItemAnchorConstant.GRP_CHILDREN.get("GRP_HARM"));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,74 @@
|
|||||||
|
package com.njcn.gather.report.service.impl;
|
||||||
|
|
||||||
|
import com.njcn.gather.report.pojo.enums.PowerIndexEnum;
|
||||||
|
import com.njcn.gather.tools.report.util.Docx4jUtil;
|
||||||
|
import org.docx4j.wml.ObjectFactory;
|
||||||
|
import org.docx4j.wml.P;
|
||||||
|
import org.docx4j.wml.R;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.lang.reflect.Constructor;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.math.BigInteger;
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
import static org.junit.Assert.assertNull;
|
||||||
|
|
||||||
|
public class PqReportServiceImplTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void formatChineseReportDateUsesChineseNumerals() {
|
||||||
|
assertEquals("二O二六年一月七日", PqReportServiceImpl.formatChineseReportDate(LocalDate.of(2026, 1, 7)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void formatChineseReportDateHandlesTwoDigitMonthAndDay() {
|
||||||
|
assertEquals("二O二六年十二月三十一日", PqReportServiceImpl.formatChineseReportDate(LocalDate.of(2026, 12, 31)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void formatNumberChineseDateUsesChineseDateSeparators() {
|
||||||
|
assertEquals("2021年1月1日", PqReportServiceImpl.formatNumberChineseDate(LocalDate.of(2021, 1, 1)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void buildItemLineTitleCreatesNormalSmallParagraph() throws Exception {
|
||||||
|
PqReportServiceImpl service = newReportService();
|
||||||
|
ObjectFactory factory = new ObjectFactory();
|
||||||
|
Docx4jUtil.HeadingContent lineTitleTemplate = new Docx4jUtil.HeadingContent();
|
||||||
|
lineTitleTemplate.setHeadingText(PowerIndexEnum.LINE_TITLE.getKey());
|
||||||
|
Map<String, List<Docx4jUtil.HeadingContent>> contentMap = new HashMap<>();
|
||||||
|
contentMap.put(PowerIndexEnum.LINE_TITLE.getKey(), Collections.singletonList(lineTitleTemplate));
|
||||||
|
|
||||||
|
Method method = PqReportServiceImpl.class.getDeclaredMethod("buildItemLineTitle", Map.class, int.class, ObjectFactory.class);
|
||||||
|
method.setAccessible(true);
|
||||||
|
P paragraph = (P) method.invoke(service, contentMap, 0, factory);
|
||||||
|
|
||||||
|
assertEquals("测量回路1", Docx4jUtil.getTextFromP(paragraph));
|
||||||
|
assertNull(paragraph.getPPr().getOutlineLvl());
|
||||||
|
R run = (R) paragraph.getContent().get(0);
|
||||||
|
assertNotNull(run.getRPr());
|
||||||
|
assertEquals(BigInteger.valueOf(24), run.getRPr().getSz().getVal());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void itemAnchorGroupKeyNormalizesAngleScriptCode() throws Exception {
|
||||||
|
Method method = PqReportServiceImpl.class.getDeclaredMethod("itemAnchorGroupKey", String.class);
|
||||||
|
method.setAccessible(true);
|
||||||
|
|
||||||
|
assertEquals("ANGLE", method.invoke(null, "Angle"));
|
||||||
|
assertEquals("ANGLE", method.invoke(null, "ANGLE"));
|
||||||
|
}
|
||||||
|
|
||||||
|
private PqReportServiceImpl newReportService() throws Exception {
|
||||||
|
Constructor<?> constructor = PqReportServiceImpl.class.getDeclaredConstructors()[0];
|
||||||
|
constructor.setAccessible(true);
|
||||||
|
return (PqReportServiceImpl) constructor.newInstance(new Object[constructor.getParameterCount()]);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
package com.njcn.gather.report.util;
|
||||||
|
|
||||||
|
import com.njcn.gather.tools.report.util.BookmarkUtil;
|
||||||
|
import com.njcn.gather.tools.report.util.Docx4jUtil;
|
||||||
|
import org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart;
|
||||||
|
import org.docx4j.wml.P;
|
||||||
|
|
||||||
|
import javax.xml.bind.JAXBElement;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/** 单测辅助:读块文本 / 收集书签名 */
|
||||||
|
final class Docx4jUtilTextHelper {
|
||||||
|
|
||||||
|
private Docx4jUtilTextHelper() {
|
||||||
|
}
|
||||||
|
|
||||||
|
static String textOf(MainDocumentPart mdp, int blockIndex) {
|
||||||
|
Object o = mdp.getContent().get(blockIndex);
|
||||||
|
Object v = (o instanceof JAXBElement) ? ((JAXBElement<?>) o).getValue() : o;
|
||||||
|
return (v instanceof P) ? Docx4jUtil.getTextFromP((P) v) : "";
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 直接复用生产扫描器 BookmarkUtil.findAllBookmarks,保证与生产"可见书签"语义一致(含表格内书签) */
|
||||||
|
static List<String> allBookmarkNames(MainDocumentPart mdp) {
|
||||||
|
List<String> names = new ArrayList<>();
|
||||||
|
for (BookmarkUtil.BookmarkInfo info : BookmarkUtil.findAllBookmarks(mdp)) {
|
||||||
|
names.add(info.bookmark.getName());
|
||||||
|
}
|
||||||
|
return names;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
package com.njcn.gather.report.util;
|
||||||
|
|
||||||
|
import com.njcn.gather.tools.report.util.Docx4jUtil;
|
||||||
|
import org.docx4j.openpackaging.packages.WordprocessingMLPackage;
|
||||||
|
import org.docx4j.openpackaging.parts.WordprocessingML.DocumentSettingsPart;
|
||||||
|
import org.docx4j.wml.CTSettings;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
|
public class Docx4jUtilUpdateFieldsTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void enableUpdateFieldsOnOpenSetsWordSettingsFlag() throws Exception {
|
||||||
|
WordprocessingMLPackage wordPackage = WordprocessingMLPackage.createPackage();
|
||||||
|
|
||||||
|
Docx4jUtil.enableUpdateFieldsOnOpen(wordPackage);
|
||||||
|
|
||||||
|
DocumentSettingsPart settingsPart = wordPackage.getMainDocumentPart().getDocumentSettingsPart();
|
||||||
|
assertNotNull(settingsPart);
|
||||||
|
CTSettings settings = settingsPart.getContents();
|
||||||
|
assertNotNull(settings.getUpdateFields());
|
||||||
|
assertTrue(settings.getUpdateFields().isVal());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,601 @@
|
|||||||
|
package com.njcn.gather.report.util;
|
||||||
|
|
||||||
|
import com.njcn.common.pojo.exception.BusinessException;
|
||||||
|
import com.njcn.gather.report.pojo.result.SingleTestResult;
|
||||||
|
import com.njcn.gather.tools.report.util.Docx4jUtil;
|
||||||
|
import org.docx4j.wml.CTMarkupRange;
|
||||||
|
import org.docx4j.wml.ObjectFactory;
|
||||||
|
import org.docx4j.wml.P;
|
||||||
|
import org.docx4j.wml.R;
|
||||||
|
import org.docx4j.wml.Tbl;
|
||||||
|
import org.docx4j.wml.Tc;
|
||||||
|
import org.docx4j.wml.Text;
|
||||||
|
import org.docx4j.wml.Tr;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import javax.xml.bind.JAXBElement;
|
||||||
|
import javax.xml.namespace.QName;
|
||||||
|
import java.math.BigInteger;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
|
public class ItemAnchorAssemblerTest {
|
||||||
|
|
||||||
|
private static final String W_NS = "http://schemas.openxmlformats.org/wordprocessingml/2006/main";
|
||||||
|
|
||||||
|
private final ObjectFactory f = new ObjectFactory();
|
||||||
|
|
||||||
|
private P para(String text) {
|
||||||
|
P p = f.createP();
|
||||||
|
R r = f.createR();
|
||||||
|
Text t = f.createText();
|
||||||
|
t.setValue(text);
|
||||||
|
r.getContent().add(t);
|
||||||
|
p.getContent().add(r);
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Tc cell(String text) {
|
||||||
|
Tc tc = f.createTc();
|
||||||
|
tc.getContent().add(para(text));
|
||||||
|
return tc;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Tr row(String... cellTexts) {
|
||||||
|
Tr tr = f.createTr();
|
||||||
|
for (String t : cellTexts) {
|
||||||
|
tr.getContent().add(f.createTrTc(cell(t)));
|
||||||
|
}
|
||||||
|
return tr;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 模板:1 行表头 + 1 行 key 行(standard/test/error/result) */
|
||||||
|
private Docx4jUtil.HeadingContent template(String... keys) {
|
||||||
|
Tbl tbl = f.createTbl();
|
||||||
|
String[] headers = new String[keys.length];
|
||||||
|
Arrays.fill(headers, "表头");
|
||||||
|
tbl.getContent().add(row(headers));
|
||||||
|
tbl.getContent().add(row(keys));
|
||||||
|
JAXBElement<Tbl> el = new JAXBElement<>(new QName(W_NS, "tbl"), Tbl.class, tbl);
|
||||||
|
Docx4jUtil.HeadingContent hc = new Docx4jUtil.HeadingContent();
|
||||||
|
hc.setHeadingText("FREQ");
|
||||||
|
hc.addSubContent(el);
|
||||||
|
return hc;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Docx4jUtil.HeadingContent hvTemplate(String... keys) {
|
||||||
|
Tbl tbl = f.createTbl();
|
||||||
|
tbl.getContent().add(row("谐波电压检验结果", "基波电压(V)", "57.7000"));
|
||||||
|
tbl.getContent().add(row("总谐波畸变率(%)", "", "standardThd", "", ""));
|
||||||
|
tbl.getContent().add(row("测点", "标准源输出值", "被检仪器测量值", "误差", "标准限值", "检验结论"));
|
||||||
|
tbl.getContent().add(row("", "", "A", "B", "C", "A", "B", "C", "", "A", "B", "C"));
|
||||||
|
tbl.getContent().add(row("THD", "standardThd", "thdA", "thdB", "thdC", "", "", "", "", "", "", ""));
|
||||||
|
tbl.getContent().add(row(keys));
|
||||||
|
JAXBElement<Tbl> el = new JAXBElement<>(new QName(W_NS, "tbl"), Tbl.class, tbl);
|
||||||
|
Docx4jUtil.HeadingContent hc = new Docx4jUtil.HeadingContent();
|
||||||
|
hc.setHeadingText("HV");
|
||||||
|
hc.addSubContent(el);
|
||||||
|
return hc;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Docx4jUtil.HeadingContent hpTemplate(String... keys) {
|
||||||
|
Tbl tbl = f.createTbl();
|
||||||
|
tbl.getContent().add(row("谐波功率检验结果", "基波电压(V)", "", "基波电流(A)", ""));
|
||||||
|
tbl.getContent().add(row("谐波次数", "标准源输出值", "被检仪器测量值", "误差", "允许误差", "检定结论"));
|
||||||
|
tbl.getContent().add(row("", "", "L1", "L2", "L3", "L1", "L2", "L3", "", ""));
|
||||||
|
tbl.getContent().add(row(keys));
|
||||||
|
JAXBElement<Tbl> el = new JAXBElement<>(new QName(W_NS, "tbl"), Tbl.class, tbl);
|
||||||
|
Docx4jUtil.HeadingContent hc = new Docx4jUtil.HeadingContent();
|
||||||
|
hc.setHeadingText("HP");
|
||||||
|
hc.addSubContent(el);
|
||||||
|
return hc;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Docx4jUtil.HeadingContent hpTemplateWithSplitHeader(String... keys) {
|
||||||
|
Tbl tbl = f.createTbl();
|
||||||
|
tbl.getContent().add(row("谐波功率检验结果", "基波电压(V)", ""));
|
||||||
|
tbl.getContent().add(row("", "基波电流(A)", ""));
|
||||||
|
tbl.getContent().add(row("谐波次数", "标准源输出值", "被检仪器测量值", "误差", "允许误差", "检定结论"));
|
||||||
|
tbl.getContent().add(row("", "", "L1", "L2", "L3", "L1", "L2", "L3", "", ""));
|
||||||
|
tbl.getContent().add(row(keys));
|
||||||
|
JAXBElement<Tbl> el = new JAXBElement<>(new QName(W_NS, "tbl"), Tbl.class, tbl);
|
||||||
|
Docx4jUtil.HeadingContent hc = new Docx4jUtil.HeadingContent();
|
||||||
|
hc.setHeadingText("HP");
|
||||||
|
hc.addSubContent(el);
|
||||||
|
return hc;
|
||||||
|
}
|
||||||
|
|
||||||
|
private SingleTestResult resultWithRows(String errorScope, List<Map<String, String>> rows) {
|
||||||
|
Map<String, List<Map<String, String>>> byError = new LinkedHashMap<>();
|
||||||
|
byError.put(errorScope, rows);
|
||||||
|
Map<String, List<Map<String, List<Map<String, String>>>>> detail = new LinkedHashMap<>();
|
||||||
|
detail.put("额定工作条件", Collections.singletonList(byError));
|
||||||
|
SingleTestResult r = new SingleTestResult();
|
||||||
|
r.setDetail(detail);
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String cellText(Tbl tbl, int rowIdx, int colIdx) {
|
||||||
|
Tr tr = (Tr) tbl.getContent().get(rowIdx);
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
JAXBElement<Tc> tc = (JAXBElement<Tc>) tr.getContent().get(colIdx);
|
||||||
|
return Docx4jUtil.getTextFromCell(tc.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void buildTables_fillsRowsAndRemovesKeyRow() {
|
||||||
|
Docx4jUtil.HeadingContent tpl = template("standard", "test", "error", "result");
|
||||||
|
Map<String, String> row1 = new HashMap<>();
|
||||||
|
row1.put("standard", "50.0000");
|
||||||
|
row1.put("test", "50.0001");
|
||||||
|
row1.put("error", "0.0001");
|
||||||
|
row1.put("result", "合格");
|
||||||
|
Map<String, String> row2 = new HashMap<>(row1);
|
||||||
|
row2.put("standard", "48.0000");
|
||||||
|
SingleTestResult r = resultWithRows("0.01", Arrays.asList(row1, row2));
|
||||||
|
List<Object> out = ItemAnchorAssembler.buildTables("FREQ", Collections.singletonList(r), tpl,
|
||||||
|
Arrays.asList("standard", "test", "error", "result"), f);
|
||||||
|
assertEquals(1, out.size());
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
Tbl tbl = ((JAXBElement<Tbl>) out.get(0)).getValue();
|
||||||
|
// 表头 + 2 行数据(key 行已删)
|
||||||
|
assertEquals(3, tbl.getContent().size());
|
||||||
|
assertEquals("50.0000", cellText(tbl, 1, 0));
|
||||||
|
assertEquals("48.0000", cellText(tbl, 2, 0));
|
||||||
|
assertEquals("合格", cellText(tbl, 1, 3));
|
||||||
|
// 原模板未被改动(深拷贝)
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
Tbl original = ((JAXBElement<Tbl>) tpl.getSubContent().get(0)).getValue();
|
||||||
|
assertEquals(2, original.getContent().size());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void buildTables_missingKeysBlank_andErrorScopeInjected() {
|
||||||
|
Docx4jUtil.HeadingContent tpl = template("time", "standard", "errorScope", "posSeq");
|
||||||
|
Map<String, String> row1 = new HashMap<>();
|
||||||
|
row1.put("standard", "0.0000"); // 无 time/posSeq/errorScope
|
||||||
|
SingleTestResult r = resultWithRows("0.15%", Collections.singletonList(row1));
|
||||||
|
List<Object> out = ItemAnchorAssembler.buildTables("IMBV", Collections.singletonList(r), tpl,
|
||||||
|
Arrays.asList("time", "standard", "errorScope", "posSeq"), f);
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
Tbl tbl = ((JAXBElement<Tbl>) out.get(0)).getValue();
|
||||||
|
assertEquals("测点1", cellText(tbl, 1, 0)); // time 缺失 → 测点{n} 兜底
|
||||||
|
assertEquals("0.15%", cellText(tbl, 1, 2)); // errorScope ← 分组 key
|
||||||
|
assertEquals("", cellText(tbl, 1, 3)); // 数据侧没有的列留空
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void buildTables_harmonicVoltageAndPowerStripErrorScopeUnit() {
|
||||||
|
Docx4jUtil.HeadingContent tpl = template("time", "errorScope");
|
||||||
|
Map<String, String> row = new HashMap<>();
|
||||||
|
row.put("time", "2");
|
||||||
|
SingleTestResult hv = resultWithRows("0.15%", Collections.singletonList(row));
|
||||||
|
SingleTestResult hp = resultWithRows("-0.1~0.1W", Collections.singletonList(row));
|
||||||
|
|
||||||
|
List<Object> hvOut = ItemAnchorAssembler.buildTables("HV", Collections.singletonList(hv), tpl,
|
||||||
|
Arrays.asList("time", "errorScope"), f);
|
||||||
|
List<Object> hpOut = ItemAnchorAssembler.buildTables("HP", Collections.singletonList(hp), tpl,
|
||||||
|
Arrays.asList("time", "errorScope"), f);
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
Tbl hvTbl = ((JAXBElement<Tbl>) hvOut.get(0)).getValue();
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
Tbl hpTbl = ((JAXBElement<Tbl>) hpOut.get(0)).getValue();
|
||||||
|
assertEquals("0.15", cellText(hvTbl, 1, 1));
|
||||||
|
assertEquals("-0.1~0.1", cellText(hpTbl, 1, 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void buildTables_powerMapping_sumsThreePhases() {
|
||||||
|
Docx4jUtil.HeadingContent tpl = template("standardV", "activePower", "reactivePower");
|
||||||
|
Map<String, String> row1 = new HashMap<>();
|
||||||
|
row1.put("testA", "288.4515");
|
||||||
|
row1.put("testB", "288.4515");
|
||||||
|
row1.put("testC", "288.4515");
|
||||||
|
SingleTestResult r = resultWithRows("1%", Collections.singletonList(row1));
|
||||||
|
List<Object> out = ItemAnchorAssembler.buildTables("P", Collections.singletonList(r), tpl,
|
||||||
|
Arrays.asList("standardV", "activePower", "reactivePower"), f);
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
Tbl tbl = ((JAXBElement<Tbl>) out.get(0)).getValue();
|
||||||
|
assertEquals("", cellText(tbl, 1, 0)); // 设置值数据侧暂无 → 留空
|
||||||
|
assertEquals("865.3545", cellText(tbl, 1, 1)); // 有功 = 三相实测之和
|
||||||
|
assertEquals("", cellText(tbl, 1, 2)); // 无功暂无 → 留空
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void buildTables_powerMapping_keepsExistingActivePower() {
|
||||||
|
Docx4jUtil.HeadingContent tpl = template("activePower");
|
||||||
|
Map<String, String> row1 = new HashMap<>();
|
||||||
|
row1.put("activePower", "1000.0000");
|
||||||
|
row1.put("testA", "1.0");
|
||||||
|
row1.put("testB", "2.0");
|
||||||
|
row1.put("testC", "3.0");
|
||||||
|
SingleTestResult r = resultWithRows("1%", Collections.singletonList(row1));
|
||||||
|
|
||||||
|
List<Object> out = ItemAnchorAssembler.buildTables("P", Collections.singletonList(r), tpl,
|
||||||
|
Collections.singletonList("activePower"), f);
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
Tbl tbl = ((JAXBElement<Tbl>) out.get(0)).getValue();
|
||||||
|
assertEquals("1000.0000", cellText(tbl, 1, 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void buildTables_multipleResults_multipleTables() {
|
||||||
|
Docx4jUtil.HeadingContent tpl = template("time", "standard");
|
||||||
|
Map<String, String> row = new HashMap<>();
|
||||||
|
row.put("time", "2");
|
||||||
|
row.put("standard", "0.5000");
|
||||||
|
SingleTestResult r1 = resultWithRows("0.05", Collections.singletonList(row));
|
||||||
|
SingleTestResult r2 = resultWithRows("0.05", Collections.singletonList(row));
|
||||||
|
SingleTestResult empty = new SingleTestResult(); // detail 为 null → 跳过
|
||||||
|
List<Object> out = ItemAnchorAssembler.buildTables("HV", Arrays.asList(r1, empty, r2), tpl,
|
||||||
|
Arrays.asList("time", "standard"), f);
|
||||||
|
// 空结果跳过 → 2 张表;多表之间允许有空段落防止 Word 合并,但不得出现可见的表外"测点"标题
|
||||||
|
assertEquals(2, countTables(out));
|
||||||
|
assertTrue(nonBlankParagraphTexts(out).isEmpty());
|
||||||
|
}
|
||||||
|
|
||||||
|
/** HP 多测点:测点号必须写在表格首行标题单元格内,不能生成表外可见标题段 */
|
||||||
|
@Test
|
||||||
|
public void buildTables_harmonicPowerMultipleTables_putsPointCaptionInTitleCell() {
|
||||||
|
List<String> keys = Arrays.asList("time", "standard");
|
||||||
|
Docx4jUtil.HeadingContent tpl = hpTemplate(keys.toArray(new String[0]));
|
||||||
|
Map<String, String> row = new HashMap<>();
|
||||||
|
row.put("time", "3");
|
||||||
|
row.put("standard", "0.5000");
|
||||||
|
SingleTestResult r1 = resultWithRows("0.05", Collections.singletonList(row));
|
||||||
|
SingleTestResult r2 = resultWithRows("0.05", Collections.singletonList(row));
|
||||||
|
List<Object> out = ItemAnchorAssembler.buildTables("HP", Arrays.asList(r1, r2), tpl, keys, f);
|
||||||
|
|
||||||
|
assertEquals(2, countTables(out));
|
||||||
|
assertTrue(nonBlankParagraphTexts(out).isEmpty());
|
||||||
|
List<Tbl> tables = collectTables(out);
|
||||||
|
assertEquals("谐波功率检验结果(测点1)", cellText(tables.get(0), 0, 0));
|
||||||
|
assertEquals("谐波功率检验结果(测点2)", cellText(tables.get(1), 0, 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void buildTables_harmonicPowerFillsBaseVoltageAndCurrentHeaderCells() {
|
||||||
|
List<String> keys = Arrays.asList("time", "standard");
|
||||||
|
Docx4jUtil.HeadingContent tpl = hpTemplate(keys.toArray(new String[0]));
|
||||||
|
Map<String, String> row = new HashMap<>();
|
||||||
|
row.put("time", "3");
|
||||||
|
row.put("standard", "23.0800");
|
||||||
|
row.put("standardV", "57.7000");
|
||||||
|
row.put("standardI", "5.0000");
|
||||||
|
SingleTestResult result = resultWithRows("1.5W", Collections.singletonList(row));
|
||||||
|
|
||||||
|
List<Object> out = ItemAnchorAssembler.buildTables("HP", Collections.singletonList(result), tpl, keys, f);
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
Tbl tbl = ((JAXBElement<Tbl>) out.get(0)).getValue();
|
||||||
|
assertEquals("57.7000", cellText(tbl, 0, 2));
|
||||||
|
assertEquals("5.0000", cellText(tbl, 0, 4));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void buildTables_harmonicPowerFillsCurrentWhenHeaderIsOnSecondRow() {
|
||||||
|
List<String> keys = Arrays.asList("time", "standard");
|
||||||
|
Docx4jUtil.HeadingContent tpl = hpTemplateWithSplitHeader(keys.toArray(new String[0]));
|
||||||
|
Map<String, String> row = new HashMap<>();
|
||||||
|
row.put("time", "3");
|
||||||
|
row.put("standard", "23.0800");
|
||||||
|
row.put("standardV", "57.7000");
|
||||||
|
row.put("standardI", "5.0000");
|
||||||
|
SingleTestResult result = resultWithRows("1.5W", Collections.singletonList(row));
|
||||||
|
|
||||||
|
List<Object> out = ItemAnchorAssembler.buildTables("HP", Collections.singletonList(result), tpl, keys, f);
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
Tbl tbl = ((JAXBElement<Tbl>) out.get(0)).getValue();
|
||||||
|
assertEquals("57.7000", cellText(tbl, 0, 2));
|
||||||
|
assertEquals("5.0000", cellText(tbl, 1, 2));
|
||||||
|
}
|
||||||
|
|
||||||
|
/** F1 边界:单表不加标题段,既有单表输出不变 */
|
||||||
|
@Test
|
||||||
|
public void buildTables_singleTable_noCaption() {
|
||||||
|
Docx4jUtil.HeadingContent tpl = template("time", "standard");
|
||||||
|
Map<String, String> row = new HashMap<>();
|
||||||
|
row.put("time", "2");
|
||||||
|
row.put("standard", "0.5000");
|
||||||
|
SingleTestResult r1 = resultWithRows("0.05", Collections.singletonList(row));
|
||||||
|
List<Object> out = ItemAnchorAssembler.buildTables("HV", Collections.singletonList(r1), tpl,
|
||||||
|
Arrays.asList("time", "standard"), f);
|
||||||
|
assertEquals(1, out.size());
|
||||||
|
assertTrue(unwrap(out.get(0)) instanceof Tbl);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** F4:bookmarkEnd 漏成 w:tbl 直接子节点(本仓 _GoBack 崩溃同类)时,key 行定位不得 ClassCastException */
|
||||||
|
@Test
|
||||||
|
public void buildTables_bookmarkEndAsTblChild_noClassCast() {
|
||||||
|
Docx4jUtil.HeadingContent tpl = template("standard", "test");
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
Tbl tplTbl = ((JAXBElement<Tbl>) tpl.getSubContent().get(0)).getValue();
|
||||||
|
CTMarkupRange end = f.createCTMarkupRange();
|
||||||
|
end.setId(BigInteger.ONE);
|
||||||
|
tplTbl.getContent().add(f.createPBookmarkEnd(end));
|
||||||
|
Map<String, String> row1 = new HashMap<>();
|
||||||
|
row1.put("standard", "50.0000");
|
||||||
|
row1.put("test", "50.0001");
|
||||||
|
SingleTestResult r = resultWithRows("0.01", Collections.singletonList(row1));
|
||||||
|
List<Object> out = ItemAnchorAssembler.buildTables("FREQ", Collections.singletonList(r), tpl,
|
||||||
|
Arrays.asList("standard", "test"), f);
|
||||||
|
assertEquals(1, out.size());
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
Tbl tbl = ((JAXBElement<Tbl>) out.get(0)).getValue();
|
||||||
|
// 表头 + 数据行(key 行已删,bookmarkEnd 保留不参与行计数)
|
||||||
|
List<Tr> trs = collectTrs(tbl);
|
||||||
|
assertEquals(2, trs.size());
|
||||||
|
assertEquals("50.0000", Docx4jUtil.getTextFromCell(cellOf(trs.get(1), 0)));
|
||||||
|
}
|
||||||
|
|
||||||
|
/** F2:模板 key 行取不到占位符属模板错误,必须显性报错而不是静默走"未测→整节隐藏" */
|
||||||
|
@Test
|
||||||
|
public void requireTableKeys_empty_throwsWithScriptCode() {
|
||||||
|
try {
|
||||||
|
ItemAnchorAssembler.requireTableKeys("FREQ", Collections.<String>emptyList());
|
||||||
|
fail("空 tableKeys 应抛 BusinessException");
|
||||||
|
} catch (BusinessException e) {
|
||||||
|
assertTrue(String.valueOf(e.getMessage()), String.valueOf(e.getMessage()).contains("FREQ"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void requireTableKeys_nonEmpty_passes() {
|
||||||
|
ItemAnchorAssembler.requireTableKeys("FREQ", Collections.singletonList("standard"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void extractTableKeys_itemAnchorReadsLastRowEvenWhenOldCrossHeuristicRejectsFirstRow() {
|
||||||
|
List<String> expected = Arrays.asList("time", "standard", "testA", "testB", "testC",
|
||||||
|
"errorA", "errorB", "errorC", "errorScope", "resultA", "resultB", "resultC");
|
||||||
|
Docx4jUtil.HeadingContent tpl = hvTemplate(expected.toArray(new String[0]));
|
||||||
|
assertTrue("old getTableFillKeys should reject this HV title row",
|
||||||
|
Docx4jUtil.getTableFillKeys(Collections.singletonList(tpl)).isEmpty());
|
||||||
|
|
||||||
|
assertEquals(expected, ItemAnchorAssembler.extractTableKeys(Collections.singletonList(tpl)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void buildTables_harmonicVoltageCalculatesThdFixedRowFromPhaseRates() {
|
||||||
|
List<String> keys = Arrays.asList("time", "standard", "testA", "testB", "testC",
|
||||||
|
"errorA", "errorB", "errorC", "errorScope", "resultA", "resultB", "resultC");
|
||||||
|
Docx4jUtil.HeadingContent tpl = hvTemplate(keys.toArray(new String[0]));
|
||||||
|
Map<String, String> row1 = harmonicRow("2", "3.0000", "6.0000", "8.0000");
|
||||||
|
row1.put("standard", "3.0000");
|
||||||
|
Map<String, String> row2 = harmonicRow("3", "4.0000", "8.0000", "15.0000");
|
||||||
|
row2.put("standard", "4.0000");
|
||||||
|
SingleTestResult r = resultWithRows("0.05", Arrays.asList(row1, row2));
|
||||||
|
|
||||||
|
List<Object> out = ItemAnchorAssembler.buildTables("HV", Collections.singletonList(r), tpl, keys, f);
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
Tbl tbl = ((JAXBElement<Tbl>) out.get(0)).getValue();
|
||||||
|
assertEquals("5.0000", cellText(tbl, 1, 2));
|
||||||
|
assertEquals("5.0000", cellText(tbl, 4, 1));
|
||||||
|
assertEquals("5.0000", cellText(tbl, 4, 2));
|
||||||
|
assertEquals("10.0000", cellText(tbl, 4, 3));
|
||||||
|
assertEquals("17.0000", cellText(tbl, 4, 4));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void buildTables_harmonicCurrentCalculatesRateRowsAndThdFromBaseCurrent() {
|
||||||
|
List<String> keys = Arrays.asList("time", "standardRate", "testRateA", "testRateB", "testRateC",
|
||||||
|
"errorRateA", "errorRateB", "errorRateC", "errorScope", "resultA", "resultB", "resultC");
|
||||||
|
Docx4jUtil.HeadingContent tpl = hvTemplate(keys.toArray(new String[0]));
|
||||||
|
Map<String, String> row1 = harmonicRow("2", "1.2000", "1.6000", "2.0000");
|
||||||
|
row1.put("standard", "1.0000");
|
||||||
|
row1.put("standardRate", "25.0000");
|
||||||
|
row1.put("errorA", "0.2000");
|
||||||
|
row1.put("errorB", "0.6000");
|
||||||
|
row1.put("errorC", "1.0000");
|
||||||
|
row1.put("baseCurrentA", "4.0000");
|
||||||
|
row1.put("baseCurrentB", "4.0000");
|
||||||
|
row1.put("baseCurrentC", "4.0000");
|
||||||
|
Map<String, String> row2 = harmonicRow("3", "0.9000", "1.2000", "1.5000");
|
||||||
|
row2.put("standard", "1.0000");
|
||||||
|
row2.put("standardRate", "25.0000");
|
||||||
|
row2.put("errorA", "-0.1000");
|
||||||
|
row2.put("errorB", "0.2000");
|
||||||
|
row2.put("errorC", "0.5000");
|
||||||
|
row2.put("baseCurrentA", "4.0000");
|
||||||
|
row2.put("baseCurrentB", "4.0000");
|
||||||
|
row2.put("baseCurrentC", "4.0000");
|
||||||
|
SingleTestResult r = resultWithRows("0.05", Arrays.asList(row1, row2));
|
||||||
|
|
||||||
|
List<Object> out = ItemAnchorAssembler.buildTables("HI", Collections.singletonList(r), tpl, keys, f);
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
Tbl tbl = ((JAXBElement<Tbl>) out.get(0)).getValue();
|
||||||
|
assertEquals("35.3553", cellText(tbl, 1, 2));
|
||||||
|
assertEquals("35.3553", cellText(tbl, 4, 1));
|
||||||
|
assertEquals("37.5000", cellText(tbl, 4, 2));
|
||||||
|
assertEquals("50.0000", cellText(tbl, 4, 3));
|
||||||
|
assertEquals("62.5000", cellText(tbl, 4, 4));
|
||||||
|
assertEquals("25.0000", cellText(tbl, 5, 1));
|
||||||
|
assertEquals("30.0000", cellText(tbl, 5, 2));
|
||||||
|
assertEquals("40.0000", cellText(tbl, 5, 3));
|
||||||
|
assertEquals("50.0000", cellText(tbl, 5, 4));
|
||||||
|
assertEquals("5.0000", cellText(tbl, 5, 5));
|
||||||
|
assertEquals("15.0000", cellText(tbl, 5, 6));
|
||||||
|
assertEquals("25.0000", cellText(tbl, 5, 7));
|
||||||
|
assertEquals("±1.2500", cellText(tbl, 5, 8));
|
||||||
|
assertEquals("±1.2500", cellText(tbl, 6, 8));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void buildTables_harmonicCurrentLeavesStandardRateBlankWhenScriptRateMissing() {
|
||||||
|
List<String> keys = Arrays.asList("time", "standardRate", "testRateA", "testRateB", "testRateC",
|
||||||
|
"errorRateA", "errorRateB", "errorRateC", "errorScope", "resultA", "resultB", "resultC");
|
||||||
|
Docx4jUtil.HeadingContent tpl = hvTemplate(keys.toArray(new String[0]));
|
||||||
|
Map<String, String> row = harmonicRow("2", "1.0000", "1.0000", "1.0000");
|
||||||
|
row.put("standard", "1.0000");
|
||||||
|
row.put("baseCurrentA", "5.0000");
|
||||||
|
row.put("baseCurrentB", "5.0000");
|
||||||
|
row.put("baseCurrentC", "5.0000");
|
||||||
|
SingleTestResult r = resultWithRows("0.05", Collections.singletonList(row));
|
||||||
|
|
||||||
|
List<Object> out = ItemAnchorAssembler.buildTables("HI", Collections.singletonList(r), tpl, keys, f);
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
Tbl tbl = ((JAXBElement<Tbl>) out.get(0)).getValue();
|
||||||
|
assertEquals("", cellText(tbl, 1, 2));
|
||||||
|
assertEquals("", cellText(tbl, 4, 1));
|
||||||
|
assertEquals("", cellText(tbl, 5, 1));
|
||||||
|
assertEquals("20.0000", cellText(tbl, 5, 2));
|
||||||
|
assertEquals("", cellText(tbl, 5, 5));
|
||||||
|
assertEquals("", cellText(tbl, 5, 8));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void buildTables_harmonicCurrentKeepsScriptStandardRateWhenAmplitudeAvailable() {
|
||||||
|
List<String> keys = Arrays.asList("time", "standardRate", "testRateA", "testRateB", "testRateC",
|
||||||
|
"errorRateA", "errorRateB", "errorRateC", "errorScope", "resultA", "resultB", "resultC");
|
||||||
|
Docx4jUtil.HeadingContent tpl = hvTemplate(keys.toArray(new String[0]));
|
||||||
|
Map<String, String> row = harmonicRow("2", "1.0000", "1.0000", "1.0000");
|
||||||
|
row.put("standard", "2.0000");
|
||||||
|
row.put("standardRate", "1.0000");
|
||||||
|
row.put("baseCurrentA", "10.0000");
|
||||||
|
row.put("baseCurrentB", "10.0000");
|
||||||
|
row.put("baseCurrentC", "10.0000");
|
||||||
|
SingleTestResult r = resultWithRows("0.05", Collections.singletonList(row));
|
||||||
|
|
||||||
|
List<Object> out = ItemAnchorAssembler.buildTables("HI", Collections.singletonList(r), tpl, keys, f);
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
Tbl tbl = ((JAXBElement<Tbl>) out.get(0)).getValue();
|
||||||
|
assertEquals("1.0000", cellText(tbl, 5, 1));
|
||||||
|
assertEquals("9.0000", cellText(tbl, 5, 5));
|
||||||
|
assertEquals("±0.1500", cellText(tbl, 5, 8));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void buildTables_harmonicCurrentErrorRateUsesRateDifference() {
|
||||||
|
List<String> keys = Arrays.asList("time", "standardRate", "testRateA", "testRateB", "testRateC",
|
||||||
|
"errorRateA", "errorRateB", "errorRateC", "errorScope", "resultA", "resultB", "resultC");
|
||||||
|
Docx4jUtil.HeadingContent tpl = hvTemplate(keys.toArray(new String[0]));
|
||||||
|
Map<String, String> row = harmonicRow("2", "2.0000", "1.0000", "1.0000");
|
||||||
|
row.put("standard", "1.0000");
|
||||||
|
row.put("standardRate", "10.0000");
|
||||||
|
row.put("errorA", "0.0100");
|
||||||
|
row.put("baseCurrentA", "10.0000");
|
||||||
|
row.put("baseCurrentB", "10.0000");
|
||||||
|
row.put("baseCurrentC", "10.0000");
|
||||||
|
SingleTestResult r = resultWithRows("0.05", Collections.singletonList(row));
|
||||||
|
|
||||||
|
List<Object> out = ItemAnchorAssembler.buildTables("HI", Collections.singletonList(r), tpl, keys, f);
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
Tbl tbl = ((JAXBElement<Tbl>) out.get(0)).getValue();
|
||||||
|
assertEquals("10.0000", cellText(tbl, 5, 1));
|
||||||
|
assertEquals("20.0000", cellText(tbl, 5, 2));
|
||||||
|
assertEquals("10.0000", cellText(tbl, 5, 5));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void buildTables_harmonicCurrentKeepsScriptStandardRateWhenAmplitudeMissing() {
|
||||||
|
List<String> keys = Arrays.asList("time", "standardRate", "testRateA", "testRateB", "testRateC",
|
||||||
|
"errorRateA", "errorRateB", "errorRateC", "errorScope", "resultA", "resultB", "resultC");
|
||||||
|
Docx4jUtil.HeadingContent tpl = hvTemplate(keys.toArray(new String[0]));
|
||||||
|
Map<String, String> row = harmonicRow("2", "0.040144", "0.040248", "0.040116");
|
||||||
|
row.put("standard", "/");
|
||||||
|
row.put("standardRate", "1.0000");
|
||||||
|
row.put("baseCurrentA", "4.0000");
|
||||||
|
row.put("baseCurrentB", "4.0000");
|
||||||
|
row.put("baseCurrentC", "4.0000");
|
||||||
|
SingleTestResult r = resultWithRows("0.0075A", Collections.singletonList(row));
|
||||||
|
|
||||||
|
List<Object> out = ItemAnchorAssembler.buildTables("HI", Collections.singletonList(r), tpl, keys, f);
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
Tbl tbl = ((JAXBElement<Tbl>) out.get(0)).getValue();
|
||||||
|
assertEquals("1.0000", cellText(tbl, 1, 2));
|
||||||
|
assertEquals("1.0000", cellText(tbl, 4, 1));
|
||||||
|
assertEquals("1.0000", cellText(tbl, 5, 1));
|
||||||
|
assertEquals("1.0036", cellText(tbl, 5, 2));
|
||||||
|
assertEquals("0.0036", cellText(tbl, 5, 5));
|
||||||
|
}
|
||||||
|
|
||||||
|
private Map<String, String> harmonicRow(String time, String testA, String testB, String testC) {
|
||||||
|
Map<String, String> row = new HashMap<>();
|
||||||
|
row.put("time", time);
|
||||||
|
row.put("standard", "0.0000");
|
||||||
|
row.put("testA", testA);
|
||||||
|
row.put("testB", testB);
|
||||||
|
row.put("testC", testC);
|
||||||
|
row.put("errorA", "0.0000");
|
||||||
|
row.put("errorB", "0.0000");
|
||||||
|
row.put("errorC", "0.0000");
|
||||||
|
row.put("resultA", "合格");
|
||||||
|
row.put("resultB", "合格");
|
||||||
|
row.put("resultC", "合格");
|
||||||
|
return row;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Object unwrap(Object o) {
|
||||||
|
return (o instanceof JAXBElement) ? ((JAXBElement<?>) o).getValue() : o;
|
||||||
|
}
|
||||||
|
|
||||||
|
private int countTables(List<Object> out) {
|
||||||
|
int n = 0;
|
||||||
|
for (Object o : out) {
|
||||||
|
if (unwrap(o) instanceof Tbl) {
|
||||||
|
n++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<Tbl> collectTables(List<Object> out) {
|
||||||
|
List<Tbl> tables = new ArrayList<>();
|
||||||
|
for (Object o : out) {
|
||||||
|
Object v = unwrap(o);
|
||||||
|
if (v instanceof Tbl) {
|
||||||
|
tables.add((Tbl) v);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return tables;
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<String> nonBlankParagraphTexts(List<Object> out) {
|
||||||
|
List<String> texts = new ArrayList<>();
|
||||||
|
for (Object o : out) {
|
||||||
|
Object v = unwrap(o);
|
||||||
|
if (v instanceof P) {
|
||||||
|
String text = Docx4jUtil.getTextFromP((P) v);
|
||||||
|
if (text != null && !text.trim().isEmpty()) {
|
||||||
|
texts.add(text);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return texts;
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<Tr> collectTrs(Tbl tbl) {
|
||||||
|
List<Tr> trs = new ArrayList<>();
|
||||||
|
for (Object o : tbl.getContent()) {
|
||||||
|
Object v = unwrap(o);
|
||||||
|
if (v instanceof Tr) {
|
||||||
|
trs.add((Tr) v);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return trs;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Tc cellOf(Tr tr, int colIdx) {
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
JAXBElement<Tc> tc = (JAXBElement<Tc>) tr.getContent().get(colIdx);
|
||||||
|
return tc.getValue();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,254 @@
|
|||||||
|
package com.njcn.gather.report.util;
|
||||||
|
|
||||||
|
import com.njcn.gather.tools.report.util.BookmarkUtil;
|
||||||
|
import org.docx4j.openpackaging.packages.WordprocessingMLPackage;
|
||||||
|
import org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart;
|
||||||
|
import org.docx4j.wml.CTBookmark;
|
||||||
|
import org.docx4j.wml.CTMarkupRange;
|
||||||
|
import org.docx4j.wml.ObjectFactory;
|
||||||
|
import org.docx4j.wml.P;
|
||||||
|
import org.docx4j.wml.R;
|
||||||
|
import org.docx4j.wml.Text;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.math.BigInteger;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.LinkedHashSet;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
|
public class ItemAnchorSectionUtilTest {
|
||||||
|
|
||||||
|
private final ObjectFactory f = new ObjectFactory();
|
||||||
|
|
||||||
|
private P para(String text) {
|
||||||
|
P p = f.createP();
|
||||||
|
R r = f.createR();
|
||||||
|
Text t = f.createText();
|
||||||
|
t.setValue(text);
|
||||||
|
r.getContent().add(t);
|
||||||
|
p.getContent().add(r);
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addStart(P p, long id, String name) {
|
||||||
|
CTBookmark b = f.createCTBookmark();
|
||||||
|
b.setId(BigInteger.valueOf(id));
|
||||||
|
b.setName(name);
|
||||||
|
p.getContent().add(0, f.createPBookmarkStart(b));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addEnd(P p, long id) {
|
||||||
|
CTMarkupRange e = f.createCTMarkupRange();
|
||||||
|
e.setId(BigInteger.valueOf(id));
|
||||||
|
p.getContent().add(f.createPBookmarkEnd(e));
|
||||||
|
}
|
||||||
|
|
||||||
|
private BookmarkUtil.BookmarkInfo addBookmarkPair(P p, long id, String name, MainDocumentPart mdp) {
|
||||||
|
CTBookmark b = f.createCTBookmark();
|
||||||
|
b.setId(BigInteger.valueOf(id));
|
||||||
|
b.setName(name);
|
||||||
|
p.getContent().add(0, f.createPBookmarkStart(b));
|
||||||
|
addEnd(p, id);
|
||||||
|
|
||||||
|
BookmarkUtil.BookmarkInfo info = new BookmarkUtil.BookmarkInfo();
|
||||||
|
info.bookmark = b;
|
||||||
|
info.parentParagraph = p;
|
||||||
|
info.parentContainer = mdp;
|
||||||
|
return info;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 构造文档骨架(模拟 base 第 7 节):
|
||||||
|
* [0] 7.1 标题 {start sect_GRP_FUND}
|
||||||
|
* [1] 7.1.1 标题 {start sect_V}
|
||||||
|
* [2] item_V 锚点段 {end sect_V}
|
||||||
|
* [3] 7.1.2 标题 {start sect_I}
|
||||||
|
* [4] item_I 锚点段 {end sect_I, end sect_GRP_FUND}
|
||||||
|
* [5] 7.2 标题 {start sect_FREQ}
|
||||||
|
* [6] item_FREQ 锚点 {end sect_FREQ}
|
||||||
|
*/
|
||||||
|
private MainDocumentPart buildDoc() throws Exception {
|
||||||
|
WordprocessingMLPackage pkg = WordprocessingMLPackage.createPackage();
|
||||||
|
MainDocumentPart mdp = pkg.getMainDocumentPart();
|
||||||
|
P p71 = para("7.1 基波测试");
|
||||||
|
addStart(p71, 100, "sect_GRP_FUND");
|
||||||
|
P p711 = para("7.1.1 电压");
|
||||||
|
addStart(p711, 101, "sect_V");
|
||||||
|
P aV = para("");
|
||||||
|
addEnd(aV, 101);
|
||||||
|
P p712 = para("7.1.2 电流");
|
||||||
|
addStart(p712, 102, "sect_I");
|
||||||
|
P aI = para("");
|
||||||
|
addEnd(aI, 102);
|
||||||
|
addEnd(aI, 100);
|
||||||
|
P p72 = para("7.2 频率");
|
||||||
|
addStart(p72, 103, "sect_FREQ");
|
||||||
|
P aF = para("");
|
||||||
|
addEnd(aF, 103);
|
||||||
|
mdp.getContent().addAll(Arrays.asList(p71, p711, aV, p712, aI, p72, aF));
|
||||||
|
return mdp;
|
||||||
|
}
|
||||||
|
|
||||||
|
private MainDocumentPart docWithTexts(String... texts) throws Exception {
|
||||||
|
WordprocessingMLPackage pkg = WordprocessingMLPackage.createPackage();
|
||||||
|
MainDocumentPart mdp = pkg.getMainDocumentPart();
|
||||||
|
for (String t : texts) {
|
||||||
|
mdp.getContent().add(para(t));
|
||||||
|
}
|
||||||
|
return mdp;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void removeSingleChildSect() throws Exception {
|
||||||
|
MainDocumentPart mdp = buildDoc();
|
||||||
|
ItemAnchorSectionUtil.removeSectRanges(mdp, new LinkedHashSet<>(Collections.singletonList("V")));
|
||||||
|
// 删除 [1][2] 两块,剩 5 块
|
||||||
|
assertEquals(5, mdp.getContent().size());
|
||||||
|
assertTrue(Docx4jUtilTextHelper.textOf(mdp, 0).startsWith("7.1 "));
|
||||||
|
assertTrue(Docx4jUtilTextHelper.textOf(mdp, 1).startsWith("7.1.2"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void removeWholeGroupWhenAllChildrenHidden() throws Exception {
|
||||||
|
MainDocumentPart mdp = buildDoc();
|
||||||
|
// GRP_FUND 子节全集是 V/I/P/ANGLE;文档里只有 V、I,但隐藏集合包含全部四个 → 整组删除
|
||||||
|
ItemAnchorSectionUtil.removeSectRanges(mdp, new LinkedHashSet<>(Arrays.asList("V", "I", "P", "ANGLE")));
|
||||||
|
// [0]~[4] 全删,剩 7.2 两块
|
||||||
|
assertEquals(2, mdp.getContent().size());
|
||||||
|
assertTrue(Docx4jUtilTextHelper.textOf(mdp, 0).startsWith("7.2"));
|
||||||
|
}
|
||||||
|
|
||||||
|
/** F6:父 sect_GRP_* 书签缺失(如 Word 重存丢书签)时,必须回退按子节各自删除,不能一个都删不掉 */
|
||||||
|
@Test
|
||||||
|
public void removeGroup_parentRangeMissing_fallsBackToChildren() throws Exception {
|
||||||
|
WordprocessingMLPackage pkg = WordprocessingMLPackage.createPackage();
|
||||||
|
MainDocumentPart mdp = pkg.getMainDocumentPart();
|
||||||
|
P p71 = para("7.1 基波测试"); // 故意不挂 sect_GRP_FUND
|
||||||
|
P p711 = para("7.1.1 电压");
|
||||||
|
addStart(p711, 101, "sect_V");
|
||||||
|
P aV = para("");
|
||||||
|
addEnd(aV, 101);
|
||||||
|
P p712 = para("7.1.2 电流");
|
||||||
|
addStart(p712, 102, "sect_I");
|
||||||
|
P aI = para("");
|
||||||
|
addEnd(aI, 102);
|
||||||
|
P p72 = para("7.2 频率");
|
||||||
|
addStart(p72, 103, "sect_FREQ");
|
||||||
|
P aF = para("");
|
||||||
|
addEnd(aF, 103);
|
||||||
|
mdp.getContent().addAll(Arrays.asList(p71, p711, aV, p712, aI, p72, aF));
|
||||||
|
ItemAnchorSectionUtil.removeSectRanges(mdp, new LinkedHashSet<>(Arrays.asList("V", "I", "P", "ANGLE")));
|
||||||
|
// 父范围定位失败 → 回退删 sect_V/sect_I 各自范围;组标题 7.1(无书签定位不了)与 7.2 保留
|
||||||
|
assertEquals(3, mdp.getContent().size());
|
||||||
|
assertTrue(Docx4jUtilTextHelper.textOf(mdp, 0).startsWith("7.1 "));
|
||||||
|
assertTrue(Docx4jUtilTextHelper.textOf(mdp, 1).startsWith("7.2"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void stripBookmarks_removesOnlyOurNamespace() throws Exception {
|
||||||
|
MainDocumentPart mdp = buildDoc();
|
||||||
|
// 额外放一个第三方书签,应保留
|
||||||
|
P other = (P) mdp.getContent().get(0);
|
||||||
|
CTBookmark foreign = f.createCTBookmark();
|
||||||
|
foreign.setId(BigInteger.valueOf(999));
|
||||||
|
foreign.setName("bgbh1");
|
||||||
|
other.getContent().add(f.createPBookmarkStart(foreign));
|
||||||
|
ItemAnchorSectionUtil.stripItemAnchorBookmarks(mdp);
|
||||||
|
// 全文不再有 sect_/item_ 书签,但 bgbh1 保留
|
||||||
|
java.util.List<String> names = Docx4jUtilTextHelper.allBookmarkNames(mdp);
|
||||||
|
assertEquals(Collections.singletonList("bgbh1"), names);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void removeEmptyItemAnchorParagraph_removesStandaloneItemAnchorParagraph() throws Exception {
|
||||||
|
MainDocumentPart mdp = docWithTexts("7.1.1 电压");
|
||||||
|
P anchor = para("");
|
||||||
|
BookmarkUtil.BookmarkInfo info = addBookmarkPair(anchor, 9000, "item_V", mdp);
|
||||||
|
addEnd(anchor, 9011);
|
||||||
|
mdp.getContent().add(anchor);
|
||||||
|
|
||||||
|
assertTrue(ItemAnchorSectionUtil.removeEmptyItemAnchorParagraph(info));
|
||||||
|
|
||||||
|
assertEquals(1, mdp.getContent().size());
|
||||||
|
assertEquals("7.1.1 电压", Docx4jUtilTextHelper.textOf(mdp, 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void removeEmptyItemAnchorParagraph_keepsItemAnchorParagraphWithText() throws Exception {
|
||||||
|
MainDocumentPart mdp = docWithTexts("7.1.1 电压");
|
||||||
|
P anchor = para("保留文本");
|
||||||
|
BookmarkUtil.BookmarkInfo info = addBookmarkPair(anchor, 9000, "item_V", mdp);
|
||||||
|
mdp.getContent().add(anchor);
|
||||||
|
|
||||||
|
assertTrue(!ItemAnchorSectionUtil.removeEmptyItemAnchorParagraph(info));
|
||||||
|
|
||||||
|
assertEquals(2, mdp.getContent().size());
|
||||||
|
assertEquals("保留文本", Docx4jUtilTextHelper.textOf(mdp, 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void removeEmptyItemAnchorParagraph_ignoresNonItemAnchor() throws Exception {
|
||||||
|
MainDocumentPart mdp = docWithTexts("7.1.1 电压");
|
||||||
|
P anchor = para("");
|
||||||
|
BookmarkUtil.BookmarkInfo info = addBookmarkPair(anchor, 1, "data_line", mdp);
|
||||||
|
mdp.getContent().add(anchor);
|
||||||
|
|
||||||
|
assertTrue(!ItemAnchorSectionUtil.removeEmptyItemAnchorParagraph(info));
|
||||||
|
|
||||||
|
assertEquals(2, mdp.getContent().size());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void renumber_afterMiddleRemoval() throws Exception {
|
||||||
|
// 模拟 7.1.1 已被删除:7.1.2→7.1.1,7.1.4→…按序补位;7.2 及以后不变
|
||||||
|
MainDocumentPart mdp = docWithTexts(
|
||||||
|
"7.准确度检查:",
|
||||||
|
"7.1 基波测试",
|
||||||
|
"7.1.2 电流",
|
||||||
|
"7.1.4 相位",
|
||||||
|
"7.2 频率",
|
||||||
|
"7.6.1 频率变化影响");
|
||||||
|
ItemAnchorSectionUtil.renumberChapter7(mdp);
|
||||||
|
assertEquals("7.准确度检查:", Docx4jUtilTextHelper.textOf(mdp, 0)); // 全角点不动
|
||||||
|
assertEquals("7.1 基波测试", Docx4jUtilTextHelper.textOf(mdp, 1));
|
||||||
|
assertEquals("7.1.1 电流", Docx4jUtilTextHelper.textOf(mdp, 2));
|
||||||
|
assertEquals("7.1.2 相位", Docx4jUtilTextHelper.textOf(mdp, 3));
|
||||||
|
assertEquals("7.2 频率", Docx4jUtilTextHelper.textOf(mdp, 4));
|
||||||
|
assertEquals("7.2.1 频率变化影响", Docx4jUtilTextHelper.textOf(mdp, 5));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void renumber_afterLevel2Removal() throws Exception {
|
||||||
|
// 模拟整个 7.1 组已删除:7.2→7.1,7.5.1→7.4.1 之类整体前移
|
||||||
|
MainDocumentPart mdp = docWithTexts("7.2 频率", "7.3 闪变", "7.5 谐波", "7.5.1 谐波电压");
|
||||||
|
ItemAnchorSectionUtil.renumberChapter7(mdp);
|
||||||
|
assertEquals("7.1 频率", Docx4jUtilTextHelper.textOf(mdp, 0));
|
||||||
|
assertEquals("7.2 闪变", Docx4jUtilTextHelper.textOf(mdp, 1));
|
||||||
|
assertEquals("7.3 谐波", Docx4jUtilTextHelper.textOf(mdp, 2));
|
||||||
|
assertEquals("7.3.1 谐波电压", Docx4jUtilTextHelper.textOf(mdp, 3));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void renumber_prefixSplitAcrossRuns() throws Exception {
|
||||||
|
// 编号被拆在两个 run 里:"7." + "2 频率"
|
||||||
|
WordprocessingMLPackage pkg = WordprocessingMLPackage.createPackage();
|
||||||
|
MainDocumentPart mdp = pkg.getMainDocumentPart();
|
||||||
|
P p = f.createP();
|
||||||
|
R r1 = f.createR();
|
||||||
|
Text t1 = f.createText();
|
||||||
|
t1.setValue("7.");
|
||||||
|
r1.getContent().add(t1);
|
||||||
|
R r2 = f.createR();
|
||||||
|
Text t2 = f.createText();
|
||||||
|
t2.setValue("2 频率");
|
||||||
|
r2.getContent().add(t2);
|
||||||
|
p.getContent().add(r1);
|
||||||
|
p.getContent().add(r2);
|
||||||
|
mdp.getContent().add(p);
|
||||||
|
ItemAnchorSectionUtil.renumberChapter7(mdp);
|
||||||
|
assertEquals("7.1 频率", Docx4jUtilTextHelper.textOf(mdp, 0));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,232 @@
|
|||||||
|
package com.njcn.gather.result.service.impl;
|
||||||
|
|
||||||
|
import com.njcn.gather.report.pojo.enums.ItemReportKeyEnum;
|
||||||
|
import com.njcn.gather.report.pojo.result.SingleTestResult;
|
||||||
|
import com.njcn.gather.script.pojo.po.PqScriptCheckData;
|
||||||
|
import com.njcn.gather.script.pojo.vo.PqScriptDtlDataVO;
|
||||||
|
import com.njcn.gather.script.service.IPqScriptCheckDataService;
|
||||||
|
import com.njcn.gather.storage.pojo.po.SimAndDigHarmonicResult;
|
||||||
|
import com.njcn.gather.storage.pojo.po.SimAndDigNonHarmonicResult;
|
||||||
|
import com.njcn.gather.storage.pojo.param.SingleNonHarmParam;
|
||||||
|
import com.njcn.gather.storage.service.SimAndDigHarmonicService;
|
||||||
|
import com.njcn.gather.storage.service.SimAndDigNonHarmonicService;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.lang.reflect.Constructor;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
|
import static org.mockito.ArgumentMatchers.anyList;
|
||||||
|
import static org.mockito.ArgumentMatchers.eq;
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
public class ResultServiceImplTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void fillThreePhaseData_harmonicCurrentCarriesBaseCurrentForRateCalculation() throws Exception {
|
||||||
|
SimAndDigHarmonicResult result = new SimAndDigHarmonicResult();
|
||||||
|
result.setAValue1(detectionData("4.0000", "10.0000"));
|
||||||
|
result.setBValue1(detectionData("5.0000", "11.0000"));
|
||||||
|
result.setCValue1(detectionData("6.0000", "12.0000"));
|
||||||
|
result.setAValue2(detectionData("1.0000"));
|
||||||
|
result.setBValue2(detectionData("1.5000"));
|
||||||
|
result.setCValue2(detectionData("2.0000"));
|
||||||
|
Map<String, String> row = new HashMap<>();
|
||||||
|
|
||||||
|
Method method = ResultServiceImpl.class.getDeclaredMethod(
|
||||||
|
"fillThreePhaseData", Object.class, Integer.class, Map.class, String.class);
|
||||||
|
method.setAccessible(true);
|
||||||
|
|
||||||
|
boolean filled = (Boolean) method.invoke(newResultService(), result, 2, row, "HI");
|
||||||
|
|
||||||
|
assertTrue(filled);
|
||||||
|
assertEquals("4.0000", row.get(ItemReportKeyEnum.BASE_CURRENT_A.getKey()));
|
||||||
|
assertEquals("5.0000", row.get(ItemReportKeyEnum.BASE_CURRENT_B.getKey()));
|
||||||
|
assertEquals("6.0000", row.get(ItemReportKeyEnum.BASE_CURRENT_C.getKey()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void fillThreePhaseData_harmonicCurrentUsesBaseCurrentDataWhenResultDataMissing() throws Exception {
|
||||||
|
SimAndDigHarmonicResult result = new SimAndDigHarmonicResult();
|
||||||
|
result.setAValue1(detectionDataOnlyData("1.0000"));
|
||||||
|
result.setBValue1(detectionDataOnlyData("2.0000"));
|
||||||
|
result.setCValue1(detectionDataOnlyData("3.0000"));
|
||||||
|
result.setAValue2(detectionData("0.1000"));
|
||||||
|
result.setBValue2(detectionData("0.2000"));
|
||||||
|
result.setCValue2(detectionData("0.3000"));
|
||||||
|
Map<String, String> row = new HashMap<>();
|
||||||
|
|
||||||
|
Method method = ResultServiceImpl.class.getDeclaredMethod(
|
||||||
|
"fillThreePhaseData", Object.class, Integer.class, Map.class, String.class);
|
||||||
|
method.setAccessible(true);
|
||||||
|
|
||||||
|
boolean filled = (Boolean) method.invoke(newResultService(), result, 2, row, "HI");
|
||||||
|
|
||||||
|
assertTrue(filled);
|
||||||
|
assertEquals("1.0000", row.get(ItemReportKeyEnum.BASE_CURRENT_A.getKey()));
|
||||||
|
assertEquals("2.0000", row.get(ItemReportKeyEnum.BASE_CURRENT_B.getKey()));
|
||||||
|
assertEquals("3.0000", row.get(ItemReportKeyEnum.BASE_CURRENT_C.getKey()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void fillHarmonicScriptStandard_harmonicCurrentCopiesScriptPercentToStandardRate() throws Exception {
|
||||||
|
Map<String, String> row = new HashMap<>();
|
||||||
|
List<PqScriptCheckData> checkData = Arrays.asList(
|
||||||
|
checkData("A", 2D, 1D),
|
||||||
|
checkData("B", 2D, 1D),
|
||||||
|
checkData("C", 2D, 1D)
|
||||||
|
);
|
||||||
|
|
||||||
|
Method method = ResultServiceImpl.class.getDeclaredMethod(
|
||||||
|
"fillHarmonicScriptStandard", Map.class, String.class, List.class);
|
||||||
|
method.setAccessible(true);
|
||||||
|
|
||||||
|
method.invoke(newResultService(), row, "HI", checkData);
|
||||||
|
|
||||||
|
assertEquals("1.0000", row.get(ItemReportKeyEnum.STANDARD_RATE.getKey()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getFinalContent_harmonicPowerCarriesBaseVoltageAndCurrentFromScriptDetails() throws Exception {
|
||||||
|
IPqScriptCheckDataService checkDataService = mock(IPqScriptCheckDataService.class);
|
||||||
|
SimAndDigHarmonicService harmonicService = mock(SimAndDigHarmonicService.class);
|
||||||
|
when(checkDataService.listCheckData(eq("script"), anyList()))
|
||||||
|
.thenReturn(Collections.singletonList(checkData("A", 3D, 23.08D)));
|
||||||
|
SimAndDigHarmonicResult harmonicResult = new SimAndDigHarmonicResult();
|
||||||
|
harmonicResult.setAValue3(detectionData("23.0745", "23.0800"));
|
||||||
|
harmonicResult.setBValue3(detectionData("23.0809", "23.0800"));
|
||||||
|
harmonicResult.setCValue3(detectionData("23.0814", "23.0800"));
|
||||||
|
when(harmonicService.getSingleResult(any())).thenReturn(harmonicResult);
|
||||||
|
List<PqScriptDtlDataVO> scriptDetails = Arrays.asList(
|
||||||
|
scriptDetail("VOL", "A", 57.7D),
|
||||||
|
scriptDetail("CUR", "A", 5.0D)
|
||||||
|
);
|
||||||
|
|
||||||
|
SingleTestResult result = newResultService(harmonicService, checkDataService)
|
||||||
|
.getFinalContent(scriptDetails, "plan", "dev", 1,
|
||||||
|
Arrays.asList("time", "standardV", "standardI"));
|
||||||
|
|
||||||
|
Map<String, String> row = firstRow(result);
|
||||||
|
assertEquals("57.7000", row.get(ItemReportKeyEnum.STANDARD_V.getKey()));
|
||||||
|
assertEquals("5.0000", row.get(ItemReportKeyEnum.STANDARD_I.getKey()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getFinalContent_angleUsesCurrentAngleResultRows() throws Exception {
|
||||||
|
IPqScriptCheckDataService checkDataService = mock(IPqScriptCheckDataService.class);
|
||||||
|
SimAndDigNonHarmonicService nonHarmonicService = mock(SimAndDigNonHarmonicService.class);
|
||||||
|
when(checkDataService.listCheckData(eq("script"), anyList())).thenReturn(Collections.emptyList());
|
||||||
|
SimAndDigNonHarmonicResult result = new SimAndDigNonHarmonicResult();
|
||||||
|
result.setSort(21);
|
||||||
|
result.setAdType("I1A");
|
||||||
|
result.setAValue(detectionAngleData("61.4", "60", "1.4", 2));
|
||||||
|
result.setBValue(detectionAngleData("61", "60", "1", 1));
|
||||||
|
result.setCValue(detectionAngleData("61", "60", "1", 1));
|
||||||
|
when(nonHarmonicService.queryBySortListWithAdTypeCode(any(SingleNonHarmParam.class)))
|
||||||
|
.thenReturn(Collections.singletonList(result));
|
||||||
|
|
||||||
|
SingleTestResult reportResult = newResultService(null, checkDataService, nonHarmonicService)
|
||||||
|
.getFinalContent(Collections.singletonList(scriptDetail("Angle", "Base", 21)),
|
||||||
|
"plan", "dev", 1, Arrays.asList("standard", "testA", "testB", "testC"));
|
||||||
|
|
||||||
|
Map<String, String> row = firstRow(reportResult);
|
||||||
|
assertEquals("60.0000", row.get(ItemReportKeyEnum.STANDARD.getKey()));
|
||||||
|
assertEquals("61.4000", row.get(ItemReportKeyEnum.TEST_A.getKey()));
|
||||||
|
assertEquals("61.0000", row.get(ItemReportKeyEnum.TEST_B.getKey()));
|
||||||
|
assertEquals("61.0000", row.get(ItemReportKeyEnum.TEST_C.getKey()));
|
||||||
|
assertEquals("不合格", row.get(ItemReportKeyEnum.RESULT_A.getKey()));
|
||||||
|
assertEquals("合格", row.get(ItemReportKeyEnum.RESULT_B.getKey()));
|
||||||
|
assertEquals("合格", row.get(ItemReportKeyEnum.RESULT_C.getKey()));
|
||||||
|
}
|
||||||
|
|
||||||
|
private ResultServiceImpl newResultService() throws Exception {
|
||||||
|
return newResultService(null, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
private ResultServiceImpl newResultService(SimAndDigHarmonicService harmonicService,
|
||||||
|
IPqScriptCheckDataService checkDataService) throws Exception {
|
||||||
|
return newResultService(harmonicService, checkDataService, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
private ResultServiceImpl newResultService(SimAndDigHarmonicService harmonicService,
|
||||||
|
IPqScriptCheckDataService checkDataService,
|
||||||
|
SimAndDigNonHarmonicService nonHarmonicService) throws Exception {
|
||||||
|
Constructor<?> constructor = ResultServiceImpl.class.getDeclaredConstructors()[0];
|
||||||
|
constructor.setAccessible(true);
|
||||||
|
Class<?>[] parameterTypes = constructor.getParameterTypes();
|
||||||
|
Object[] args = new Object[parameterTypes.length];
|
||||||
|
for (int i = 0; i < parameterTypes.length; i++) {
|
||||||
|
if (nonHarmonicService != null && parameterTypes[i].equals(SimAndDigNonHarmonicService.class)) {
|
||||||
|
args[i] = nonHarmonicService;
|
||||||
|
} else if (harmonicService != null && parameterTypes[i].equals(SimAndDigHarmonicService.class)) {
|
||||||
|
args[i] = harmonicService;
|
||||||
|
} else if (checkDataService != null && parameterTypes[i].equals(IPqScriptCheckDataService.class)) {
|
||||||
|
args[i] = checkDataService;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return (ResultServiceImpl) constructor.newInstance(args);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Map<String, String> firstRow(SingleTestResult result) {
|
||||||
|
return result.getDetail().values().iterator().next()
|
||||||
|
.get(0).values().iterator().next()
|
||||||
|
.get(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String detectionData(String value) {
|
||||||
|
return detectionData(value, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String detectionData(String data, String resultData) {
|
||||||
|
return "{\"isData\":1,\"data\":" + data + ",\"resultData\":" + resultData
|
||||||
|
+ ",\"radius\":\"0.05\",\"unit\":\"A\"}";
|
||||||
|
}
|
||||||
|
|
||||||
|
private String detectionDataOnlyData(String data) {
|
||||||
|
return "{\"num\":1,\"isData\":4,\"data\":" + data + ",\"radius\":\"0.05\",\"unit\":\"A\"}";
|
||||||
|
}
|
||||||
|
|
||||||
|
private String detectionAngleData(String data, String resultData, String errorData, int isData) {
|
||||||
|
return "{\"isData\":" + isData + ",\"data\":" + data + ",\"resultData\":" + resultData
|
||||||
|
+ ",\"errorData\":" + errorData + ",\"radius\":\"-1.0~1.0\",\"unit\":\"\\u00b0\"}";
|
||||||
|
}
|
||||||
|
|
||||||
|
private PqScriptCheckData checkData(String phase, Double harmNum, Double value) {
|
||||||
|
PqScriptCheckData data = new PqScriptCheckData();
|
||||||
|
data.setScriptIndex(3);
|
||||||
|
data.setValueType("HP");
|
||||||
|
data.setPhase(phase);
|
||||||
|
data.setHarmNum(harmNum);
|
||||||
|
data.setValue(value);
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
private PqScriptDtlDataVO scriptDetail(String valueType, String phase, Double value) {
|
||||||
|
PqScriptDtlDataVO detail = new PqScriptDtlDataVO();
|
||||||
|
detail.setScriptId("script");
|
||||||
|
detail.setScriptCode("HP");
|
||||||
|
detail.setScriptSubType("Base");
|
||||||
|
detail.setScriptIndex(3);
|
||||||
|
detail.setValueType(valueType);
|
||||||
|
detail.setPhase(phase);
|
||||||
|
detail.setValue(value);
|
||||||
|
return detail;
|
||||||
|
}
|
||||||
|
|
||||||
|
private PqScriptDtlDataVO scriptDetail(String scriptCode, String scriptSubType, Integer scriptIndex) {
|
||||||
|
PqScriptDtlDataVO detail = new PqScriptDtlDataVO();
|
||||||
|
detail.setScriptId("script");
|
||||||
|
detail.setScriptCode(scriptCode);
|
||||||
|
detail.setScriptSubType(scriptSubType);
|
||||||
|
detail.setScriptIndex(scriptIndex);
|
||||||
|
return detail;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,64 @@
|
|||||||
|
package com.njcn.gather.result.util;
|
||||||
|
|
||||||
|
import com.njcn.gather.report.pojo.enums.ItemReportKeyEnum;
|
||||||
|
import com.njcn.gather.storage.pojo.po.SimAndDigNonHarmonicResult;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
|
public class AngleResultAssemblerTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void assembleRows_usesCurrentAngleI1AAndIgnoresVoltageAngleU1A() {
|
||||||
|
SimAndDigNonHarmonicResult voltageAngle = result("U1A",
|
||||||
|
data(0D, 0D, 0D, 1), data(0D, 0D, 0D, 1), data(0D, 0D, 0D, 1));
|
||||||
|
SimAndDigNonHarmonicResult currentAngle = result("I1A",
|
||||||
|
data(61.4D, 60D, 1.4D, 2), data(61D, 60D, 1D, 1), data(61D, 60D, 1D, 1));
|
||||||
|
|
||||||
|
List<Map<String, String>> rows = AngleResultAssembler.assembleRows(Arrays.asList(voltageAngle, currentAngle));
|
||||||
|
|
||||||
|
assertEquals(1, rows.size());
|
||||||
|
Map<String, String> row = rows.get(0);
|
||||||
|
assertEquals("60.0000", row.get(ItemReportKeyEnum.STANDARD.getKey()));
|
||||||
|
assertEquals("61.4000", row.get(ItemReportKeyEnum.TEST_A.getKey()));
|
||||||
|
assertEquals("61.0000", row.get(ItemReportKeyEnum.TEST_B.getKey()));
|
||||||
|
assertEquals("61.0000", row.get(ItemReportKeyEnum.TEST_C.getKey()));
|
||||||
|
assertEquals("1.4000", row.get(ItemReportKeyEnum.ERROR_A.getKey()));
|
||||||
|
assertEquals("1.0000", row.get(ItemReportKeyEnum.ERROR_B.getKey()));
|
||||||
|
assertEquals("1.0000", row.get(ItemReportKeyEnum.ERROR_C.getKey()));
|
||||||
|
assertEquals("不合格", row.get(ItemReportKeyEnum.RESULT_A.getKey()));
|
||||||
|
assertEquals("合格", row.get(ItemReportKeyEnum.RESULT_B.getKey()));
|
||||||
|
assertEquals("合格", row.get(ItemReportKeyEnum.RESULT_C.getKey()));
|
||||||
|
assertEquals("\u00b11.0\u00b0", row.get(ItemReportKeyEnum.ERROR_SCOPE.getKey()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void assembleRows_voltageAngleOnlyReturnsNoRows() {
|
||||||
|
SimAndDigNonHarmonicResult voltageAngle = result("U1A",
|
||||||
|
data(0D, 0D, 0D, 1), data(0D, 0D, 0D, 1), data(0D, 0D, 0D, 1));
|
||||||
|
|
||||||
|
assertTrue(AngleResultAssembler.assembleRows(Collections.singletonList(voltageAngle)).isEmpty());
|
||||||
|
}
|
||||||
|
|
||||||
|
private SimAndDigNonHarmonicResult result(String adType, String a, String b, String c) {
|
||||||
|
SimAndDigNonHarmonicResult result = new SimAndDigNonHarmonicResult();
|
||||||
|
result.setSort(21);
|
||||||
|
result.setAdType(adType);
|
||||||
|
result.setAValue(a);
|
||||||
|
result.setBValue(b);
|
||||||
|
result.setCValue(c);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String data(Double data, Double resultData, Double errorData, Integer isData) {
|
||||||
|
return "{\"data\":" + data + ",\"unit\":\"\\u00b0\",\"isData\":" + isData
|
||||||
|
+ ",\"radius\":\"-1.0~1.0\",\"errorData\":" + errorData
|
||||||
|
+ ",\"resultData\":" + resultData + "}";
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,173 @@
|
|||||||
|
package com.njcn.gather.result.util;
|
||||||
|
|
||||||
|
import com.njcn.gather.report.pojo.enums.ItemReportKeyEnum;
|
||||||
|
import com.njcn.gather.script.pojo.vo.PqScriptDtlDataVO;
|
||||||
|
import com.njcn.gather.storage.pojo.po.SimAndDigNonHarmonicResult;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
|
public class PowerResultAssemblerTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void assembleRows_mergesTotalPowerResultsBySort() {
|
||||||
|
List<SimAndDigNonHarmonicResult> results = Arrays.asList(
|
||||||
|
total("TotW", 14, "{\"data\": -1079.364014, \"unit\": \"%\", \"isData\": 1, \"radius\": \"-0.5~0.5\", \"errorData\": -0.058888, \"resultData\": -1080}"),
|
||||||
|
total("TotVAr", 14, "{\"data\": 12.16591, \"isData\": 5, \"resultData\": 0}"),
|
||||||
|
total("TotVA", 14, "{\"data\": 1079.463013, \"isData\": 5, \"resultData\": 1080}")
|
||||||
|
);
|
||||||
|
|
||||||
|
List<Map<String, String>> rows = PowerResultAssembler.assembleRows(results);
|
||||||
|
|
||||||
|
assertEquals(1, rows.size());
|
||||||
|
Map<String, String> row = rows.get(0);
|
||||||
|
assertEquals("-1079.3640", row.get(ItemReportKeyEnum.ACTIVE_POWER.getKey()));
|
||||||
|
assertEquals("12.1659", row.get(ItemReportKeyEnum.REACTIVE_POWER.getKey()));
|
||||||
|
assertEquals("1079.4630", row.get(ItemReportKeyEnum.APPARENT_POWER.getKey()));
|
||||||
|
assertEquals("-1080.0000", row.get(ItemReportKeyEnum.STANDARD.getKey()));
|
||||||
|
assertEquals("合格", row.get(ItemReportKeyEnum.RESULT.getKey()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void assembleRows_sumsPhasePowerWhenTotalPowerIsAbsent() {
|
||||||
|
SimAndDigNonHarmonicResult result = new SimAndDigNonHarmonicResult();
|
||||||
|
result.setAdType("W");
|
||||||
|
result.setSort(15);
|
||||||
|
result.setAValue("{\"data\": 100.1, \"isData\": 1, \"resultData\": 100}");
|
||||||
|
result.setBValue("{\"data\": 200.2, \"isData\": 1, \"resultData\": 200}");
|
||||||
|
result.setCValue("{\"data\": 300.3, \"isData\": 1, \"resultData\": 300}");
|
||||||
|
|
||||||
|
List<Map<String, String>> rows = PowerResultAssembler.assembleRows(Arrays.asList(result));
|
||||||
|
|
||||||
|
assertEquals(1, rows.size());
|
||||||
|
assertEquals("600.6000", rows.get(0).get(ItemReportKeyEnum.ACTIVE_POWER.getKey()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void assembleRows_prefersTotalPowerWhenTotalAndPhaseBothExist() {
|
||||||
|
SimAndDigNonHarmonicResult total = total("TotW", 16,
|
||||||
|
"{\"data\": 1000.0, \"isData\": 1, \"resultData\": 1000}");
|
||||||
|
SimAndDigNonHarmonicResult phases = new SimAndDigNonHarmonicResult();
|
||||||
|
phases.setAdType("W");
|
||||||
|
phases.setSort(16);
|
||||||
|
phases.setAValue("{\"data\": 1.0, \"isData\": 1, \"resultData\": 1}");
|
||||||
|
phases.setBValue("{\"data\": 2.0, \"isData\": 1, \"resultData\": 2}");
|
||||||
|
phases.setCValue("{\"data\": 3.0, \"isData\": 1, \"resultData\": 3}");
|
||||||
|
|
||||||
|
List<Map<String, String>> rows = PowerResultAssembler.assembleRows(Arrays.asList(total, phases));
|
||||||
|
|
||||||
|
assertEquals(1, rows.size());
|
||||||
|
assertEquals("1000.0000", rows.get(0).get(ItemReportKeyEnum.ACTIVE_POWER.getKey()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void assembleRows_usesTotalPowerAsPrimaryWhenPhaseResultComesFirst() {
|
||||||
|
SimAndDigNonHarmonicResult phases = new SimAndDigNonHarmonicResult();
|
||||||
|
phases.setAdType("W");
|
||||||
|
phases.setSort(17);
|
||||||
|
phases.setAValue("{\"data\": 1.0, \"isData\": 1, \"resultData\": 1}");
|
||||||
|
phases.setBValue("{\"data\": 2.0, \"isData\": 1, \"resultData\": 2}");
|
||||||
|
phases.setCValue("{\"data\": 3.0, \"isData\": 1, \"resultData\": 3}");
|
||||||
|
SimAndDigNonHarmonicResult total = total("TotW", 17,
|
||||||
|
"{\"data\": 1000.0, \"isData\": 1, \"resultData\": 2000}");
|
||||||
|
|
||||||
|
List<Map<String, String>> rows = PowerResultAssembler.assembleRows(Arrays.asList(phases, total));
|
||||||
|
|
||||||
|
assertEquals(1, rows.size());
|
||||||
|
assertEquals("1000.0000", rows.get(0).get(ItemReportKeyEnum.ACTIVE_POWER.getKey()));
|
||||||
|
assertEquals("2000.0000", rows.get(0).get(ItemReportKeyEnum.STANDARD.getKey()));
|
||||||
|
assertEquals("1000.0000", rows.get(0).get(ItemReportKeyEnum.TEST.getKey()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void assembleRows_prefersTotalPowerFactorWhenTotalAndPhaseBothExist() {
|
||||||
|
SimAndDigNonHarmonicResult total = total("TotPF", 18,
|
||||||
|
"{\"data\": 0.9900, \"isData\": 1, \"resultData\": 1.0}");
|
||||||
|
SimAndDigNonHarmonicResult phases = new SimAndDigNonHarmonicResult();
|
||||||
|
phases.setAdType("PF");
|
||||||
|
phases.setSort(18);
|
||||||
|
phases.setAValue("{\"data\": 0.7, \"isData\": 1, \"resultData\": 1.0}");
|
||||||
|
phases.setBValue("{\"data\": 0.8, \"isData\": 1, \"resultData\": 1.0}");
|
||||||
|
phases.setCValue("{\"data\": 0.9, \"isData\": 1, \"resultData\": 1.0}");
|
||||||
|
|
||||||
|
List<Map<String, String>> rows = PowerResultAssembler.assembleRows(Arrays.asList(total, phases));
|
||||||
|
|
||||||
|
assertEquals(1, rows.size());
|
||||||
|
assertEquals("0.9900", rows.get(0).get(ItemReportKeyEnum.POWER_FACTOR.getKey()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void assembleRows_defaultsMissingPowerKeysToSlash() {
|
||||||
|
SimAndDigNonHarmonicResult total = total("TotW", 18,
|
||||||
|
"{\"data\": 1000.0, \"isData\": 1, \"resultData\": 1000}");
|
||||||
|
|
||||||
|
List<Map<String, String>> rows = PowerResultAssembler.assembleRows(Arrays.asList(total));
|
||||||
|
|
||||||
|
assertEquals(1, rows.size());
|
||||||
|
assertEquals("/", rows.get(0).get(ItemReportKeyEnum.STANDARD_V.getKey()));
|
||||||
|
assertEquals("/", rows.get(0).get(ItemReportKeyEnum.STANDARD_A.getKey()));
|
||||||
|
assertEquals("/", rows.get(0).get(ItemReportKeyEnum.POWER_FACTOR.getKey()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void assembleRows_fillsStandardSourceValuesFromScriptDetailsPreferringPhaseA() {
|
||||||
|
SimAndDigNonHarmonicResult total = total("TotW", 19,
|
||||||
|
"{\"data\": 1000.0, \"isData\": 1, \"resultData\": 1000}");
|
||||||
|
List<PqScriptDtlDataVO> scriptDetails = Arrays.asList(
|
||||||
|
scriptDetail(19, "VOL", "B", 58.0, 120.0),
|
||||||
|
scriptDetail(19, "CUR", "B", 6.0, 90.0),
|
||||||
|
scriptDetail(19, "VOL", "A", 57.74, 0.0),
|
||||||
|
scriptDetail(19, "CUR", "A", 5.0, -30.0)
|
||||||
|
);
|
||||||
|
|
||||||
|
List<Map<String, String>> rows = PowerResultAssembler.assembleRows(Arrays.asList(total), scriptDetails);
|
||||||
|
|
||||||
|
assertEquals(1, rows.size());
|
||||||
|
assertEquals("57.7400", rows.get(0).get(ItemReportKeyEnum.STANDARD_V.getKey()));
|
||||||
|
assertEquals("5.0000", rows.get(0).get(ItemReportKeyEnum.STANDARD_I.getKey()));
|
||||||
|
assertEquals("0.0000", rows.get(0).get(ItemReportKeyEnum.STANDARD_U_ANGLE.getKey()));
|
||||||
|
assertEquals("-30.0000", rows.get(0).get(ItemReportKeyEnum.STANDARD_I_ANGLE.getKey()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void assembleRows_fallsBackToPhaseBForStandardSourceValuesWhenPhaseAIsAbsent() {
|
||||||
|
SimAndDigNonHarmonicResult total = total("TotW", 20,
|
||||||
|
"{\"data\": 1000.0, \"isData\": 1, \"resultData\": 1000}");
|
||||||
|
List<PqScriptDtlDataVO> scriptDetails = Arrays.asList(
|
||||||
|
scriptDetail(20, "VOL", "C", 59.0, 240.0),
|
||||||
|
scriptDetail(20, "CUR", "C", 7.0, 210.0),
|
||||||
|
scriptDetail(20, "VOL", "B", 58.0, 120.0),
|
||||||
|
scriptDetail(20, "CUR", "B", 6.0, 90.0)
|
||||||
|
);
|
||||||
|
|
||||||
|
List<Map<String, String>> rows = PowerResultAssembler.assembleRows(Arrays.asList(total), scriptDetails);
|
||||||
|
|
||||||
|
assertEquals(1, rows.size());
|
||||||
|
assertEquals("58.0000", rows.get(0).get(ItemReportKeyEnum.STANDARD_V.getKey()));
|
||||||
|
assertEquals("6.0000", rows.get(0).get(ItemReportKeyEnum.STANDARD_I.getKey()));
|
||||||
|
assertEquals("120.0000", rows.get(0).get(ItemReportKeyEnum.STANDARD_U_ANGLE.getKey()));
|
||||||
|
assertEquals("90.0000", rows.get(0).get(ItemReportKeyEnum.STANDARD_I_ANGLE.getKey()));
|
||||||
|
}
|
||||||
|
|
||||||
|
private SimAndDigNonHarmonicResult total(String code, Integer sort, String tValue) {
|
||||||
|
SimAndDigNonHarmonicResult result = new SimAndDigNonHarmonicResult();
|
||||||
|
result.setAdType(code);
|
||||||
|
result.setSort(sort);
|
||||||
|
result.setTValue(tValue);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private PqScriptDtlDataVO scriptDetail(Integer sort, String valueType, String phase, Double value, Double angle) {
|
||||||
|
PqScriptDtlDataVO detail = new PqScriptDtlDataVO();
|
||||||
|
detail.setScriptIndex(sort);
|
||||||
|
detail.setValueType(valueType);
|
||||||
|
detail.setPhase(phase);
|
||||||
|
detail.setValue(value);
|
||||||
|
detail.setAngle(angle);
|
||||||
|
return detail;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,104 @@
|
|||||||
|
package com.njcn.gather.result.util;
|
||||||
|
|
||||||
|
import com.njcn.gather.report.pojo.enums.ItemReportKeyEnum;
|
||||||
|
import com.njcn.gather.storage.pojo.po.SimAndDigNonHarmonicResult;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertNull;
|
||||||
|
|
||||||
|
public class UnbalanceResultAssemblerTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void assembleRows_mergesVoltageUnbalanceAndSequenceBySort() {
|
||||||
|
SimAndDigNonHarmonicResult unbalance = total("V_UNBAN", 31,
|
||||||
|
"{\"data\": 0.002506, \"unit\": \"%\", \"isData\": 4, \"radius\": \"-0.2~0.2\", \"errorData\": 0.002506, \"resultData\": 0}");
|
||||||
|
SimAndDigNonHarmonicResult sequence = sequence("SeqV", 31,
|
||||||
|
"{\"data\": 57.728199, \"isData\": 5, \"resultData\": 33.31598}",
|
||||||
|
"{\"data\": 0.004355, \"isData\": 5, \"resultData\": 0}",
|
||||||
|
"{\"data\": 0.00516, \"isData\": 5, \"resultData\": 0}");
|
||||||
|
|
||||||
|
List<Map<String, String>> rows = UnbalanceResultAssembler.assembleRows(Arrays.asList(unbalance, sequence));
|
||||||
|
|
||||||
|
assertEquals(1, rows.size());
|
||||||
|
Map<String, String> row = rows.get(0);
|
||||||
|
assertEquals("0.0000", row.get(ItemReportKeyEnum.STANDARD.getKey()));
|
||||||
|
assertEquals("0.0025", row.get(ItemReportKeyEnum.TEST.getKey()));
|
||||||
|
assertEquals("0.0025", row.get(ItemReportKeyEnum.ERROR.getKey()));
|
||||||
|
assertEquals("±0.2%", row.get(ItemReportKeyEnum.ERROR_SCOPE.getKey()));
|
||||||
|
assertEquals("无法比较", row.get(ItemReportKeyEnum.RESULT.getKey()));
|
||||||
|
assertEquals("57.7282", row.get(ItemReportKeyEnum.POS_SEQ.getKey()));
|
||||||
|
assertEquals("0.0044", row.get(ItemReportKeyEnum.NEG_SEQ.getKey()));
|
||||||
|
assertEquals("0.0052", row.get(ItemReportKeyEnum.ZERO_SEQ.getKey()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void assembleRows_mergesCurrentUnbalanceAndSequenceBySort() {
|
||||||
|
SimAndDigNonHarmonicResult unbalance = total("I_UNBAN", 12,
|
||||||
|
"{\"data\": 0.31, \"unit\": \"%\", \"isData\": 2, \"radius\": \"-0.1~0.1\", \"errorData\": 0.21, \"resultData\": 0.1}");
|
||||||
|
SimAndDigNonHarmonicResult sequence = sequence("SeqA", 12,
|
||||||
|
"{\"data\": 4.9999, \"isData\": 5, \"resultData\": 5}",
|
||||||
|
"{\"data\": 0.0021, \"isData\": 5, \"resultData\": 0}",
|
||||||
|
"{\"data\": 0.0008, \"isData\": 5, \"resultData\": 0}");
|
||||||
|
|
||||||
|
List<Map<String, String>> rows = UnbalanceResultAssembler.assembleRows(Arrays.asList(sequence, unbalance));
|
||||||
|
|
||||||
|
assertEquals(1, rows.size());
|
||||||
|
Map<String, String> row = rows.get(0);
|
||||||
|
assertEquals("0.1000", row.get(ItemReportKeyEnum.STANDARD.getKey()));
|
||||||
|
assertEquals("0.3100", row.get(ItemReportKeyEnum.TEST.getKey()));
|
||||||
|
assertEquals("0.2100", row.get(ItemReportKeyEnum.ERROR.getKey()));
|
||||||
|
assertEquals("不合格", row.get(ItemReportKeyEnum.RESULT.getKey()));
|
||||||
|
assertEquals("4.9999", row.get(ItemReportKeyEnum.POS_SEQ.getKey()));
|
||||||
|
assertEquals("0.0021", row.get(ItemReportKeyEnum.NEG_SEQ.getKey()));
|
||||||
|
assertEquals("0.0008", row.get(ItemReportKeyEnum.ZERO_SEQ.getKey()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void assembleRows_defaultsMissingSequenceValuesToSlash() {
|
||||||
|
SimAndDigNonHarmonicResult unbalance = total("V_UNBAN", 7,
|
||||||
|
"{\"data\": 0.05, \"unit\": \"%\", \"isData\": 1, \"radius\": \"-0.2~0.2\", \"errorData\": 0.01, \"resultData\": 0.04}");
|
||||||
|
|
||||||
|
List<Map<String, String>> rows = UnbalanceResultAssembler.assembleRows(Arrays.asList(unbalance));
|
||||||
|
|
||||||
|
assertEquals(1, rows.size());
|
||||||
|
Map<String, String> row = rows.get(0);
|
||||||
|
assertEquals("/", row.get(ItemReportKeyEnum.POS_SEQ.getKey()));
|
||||||
|
assertEquals("/", row.get(ItemReportKeyEnum.NEG_SEQ.getKey()));
|
||||||
|
assertEquals("/", row.get(ItemReportKeyEnum.ZERO_SEQ.getKey()));
|
||||||
|
assertEquals("合格", row.get(ItemReportKeyEnum.RESULT.getKey()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void assembleRows_leavesTimeUnsetForItemAnchorPointFallback() {
|
||||||
|
SimAndDigNonHarmonicResult unbalance = total("V_UNBAN", 7,
|
||||||
|
"{\"data\": 0.05, \"unit\": \"%\", \"isData\": 1, \"radius\": \"-0.2~0.2\", \"errorData\": 0.01, \"resultData\": 0.04}");
|
||||||
|
|
||||||
|
List<Map<String, String>> rows = UnbalanceResultAssembler.assembleRows(Arrays.asList(unbalance));
|
||||||
|
|
||||||
|
assertEquals(1, rows.size());
|
||||||
|
assertNull(rows.get(0).get(ItemReportKeyEnum.TIME.getKey()));
|
||||||
|
}
|
||||||
|
|
||||||
|
private SimAndDigNonHarmonicResult total(String code, Integer sort, String tValue) {
|
||||||
|
SimAndDigNonHarmonicResult result = new SimAndDigNonHarmonicResult();
|
||||||
|
result.setAdType(code);
|
||||||
|
result.setSort(sort);
|
||||||
|
result.setTValue(tValue);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private SimAndDigNonHarmonicResult sequence(String code, Integer sort, String aValue, String bValue, String cValue) {
|
||||||
|
SimAndDigNonHarmonicResult result = new SimAndDigNonHarmonicResult();
|
||||||
|
result.setAdType(code);
|
||||||
|
result.setSort(sort);
|
||||||
|
result.setAValue(aValue);
|
||||||
|
result.setBValue(bValue);
|
||||||
|
result.setCValue(cValue);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -66,13 +66,13 @@ webSocket:
|
|||||||
sntp:
|
sntp:
|
||||||
port: 123
|
port: 123
|
||||||
|
|
||||||
Dip:
|
#Dip:
|
||||||
# 暂态前时间(s)
|
# 暂态前时间(s)
|
||||||
# fPreTime: 2f
|
# fPreTime: 2f
|
||||||
#写入时间(s)
|
#写入时间(s)
|
||||||
fRampIn: 0.001f
|
# fRampIn: 0.001f
|
||||||
#写出时间(s)
|
#写出时间(s)
|
||||||
fRampOut: 0.001f
|
# fRampOut: 0.001f
|
||||||
# 暂态后时间(s)
|
# 暂态后时间(s)
|
||||||
# fAfterTime: 3f
|
# fAfterTime: 3f
|
||||||
|
|
||||||
|
|||||||
@@ -74,4 +74,10 @@ public interface SimAndDigHarmonicService extends IService<SimAndDigHarmonicResu
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
List<SimAndDigHarmonicResult> listAllRawData(String scriptId, String code, String devId);
|
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);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -62,6 +62,12 @@ public interface SimAndDigNonHarmonicService extends IService<SimAndDigNonHarmon
|
|||||||
*/
|
*/
|
||||||
List<SimAndDigNonHarmonicResult> queryByCondition(SingleNonHarmParam param);
|
List<SimAndDigNonHarmonicResult> queryByCondition(SingleNonHarmParam param);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 按设备回路和 sort 查询所有非谐波结果,并把 adType 映射为字典 CODE。
|
||||||
|
* 用于功率 P:同一 sort 下可能同时存在 TotW/TotVAr/TotVA 等总量结果。
|
||||||
|
*/
|
||||||
|
List<SimAndDigNonHarmonicResult> queryBySortListWithAdTypeCode(SingleNonHarmParam param);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@@ -73,4 +79,10 @@ public interface SimAndDigNonHarmonicService extends IService<SimAndDigNonHarmon
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
List<SimAndDigNonHarmonicResult> listAllSimAndDigRawData(String scriptId, String code, String devId);
|
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);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -276,4 +276,96 @@ public class SimAndDigHarmonicServiceImpl extends ServiceImpl<SimAndDigHarmonicM
|
|||||||
DynamicTableNameHandler.remove();
|
DynamicTableNameHandler.remove();
|
||||||
return results;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import cn.hutool.core.date.DatePattern;
|
|||||||
import cn.hutool.core.util.ObjectUtil;
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import com.github.yulichang.wrapper.MPJLambdaWrapper;
|
import com.github.yulichang.wrapper.MPJLambdaWrapper;
|
||||||
import com.njcn.db.mybatisplus.handler.DynamicTableNameHandler;
|
import com.njcn.db.mybatisplus.handler.DynamicTableNameHandler;
|
||||||
@@ -104,7 +105,6 @@ public class SimAndDigNonHarmonicServiceImpl extends ServiceImpl<SimAndDigNonHar
|
|||||||
|
|
||||||
Map<String, List<RawResultDataVO>> info = new LinkedHashMap<>(2);
|
Map<String, List<RawResultDataVO>> info = new LinkedHashMap<>(2);
|
||||||
Map<String, SimAndDigNonHarmonicResult> adTypeMap = SimAndDigHarmonicResults.stream()
|
Map<String, SimAndDigNonHarmonicResult> adTypeMap = SimAndDigHarmonicResults.stream()
|
||||||
.sorted(Comparator.comparing(SimAndDigNonHarmonicResult::getResultFlag))
|
|
||||||
.collect(Collectors.toMap(SimAndDigNonHarmonicResult::getAdType, Function.identity(), (a, b) -> a, LinkedHashMap::new));
|
.collect(Collectors.toMap(SimAndDigNonHarmonicResult::getAdType, Function.identity(), (a, b) -> a, LinkedHashMap::new));
|
||||||
List<DictTree> dictTreeById = dictTreeService.getDictTreeById(new ArrayList<>(adTypeMap.keySet()));
|
List<DictTree> dictTreeById = dictTreeService.getDictTreeById(new ArrayList<>(adTypeMap.keySet()));
|
||||||
Map<String, DictTree> dictTreeByName = dictTreeById.stream().collect(Collectors.toMap(DictTree::getId, Function.identity()));
|
Map<String, DictTree> dictTreeByName = dictTreeById.stream().collect(Collectors.toMap(DictTree::getId, Function.identity()));
|
||||||
@@ -181,6 +181,21 @@ public class SimAndDigNonHarmonicServiceImpl extends ServiceImpl<SimAndDigNonHar
|
|||||||
return adNonHarmonicResults;
|
return adNonHarmonicResults;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<SimAndDigNonHarmonicResult> queryBySortListWithAdTypeCode(SingleNonHarmParam param) {
|
||||||
|
String prefix = "ad_non_harmonic_result_";
|
||||||
|
DynamicTableNameHandler.setTableName(prefix + param.getPlanCode());
|
||||||
|
MPJLambdaWrapper<SimAndDigNonHarmonicResult> wrapper = new MPJLambdaWrapper<>();
|
||||||
|
wrapper.selectAll(SimAndDigNonHarmonicResult.class)
|
||||||
|
.selectAs(DictTree::getCode, SimAndDigNonHarmonicResult::getAdType)
|
||||||
|
.leftJoin(DictTree.class, DictTree::getId, SimAndDigNonHarmonicResult::getAdType)
|
||||||
|
.like(SimAndDigNonHarmonicResult::getDevMonitorId, param.getDevId() + "_" + param.getChannelNo())
|
||||||
|
.in(SimAndDigNonHarmonicResult::getSort, param.getSortList());
|
||||||
|
List<SimAndDigNonHarmonicResult> adNonHarmonicResults = this.getBaseMapper().selectJoinList(SimAndDigNonHarmonicResult.class, wrapper);
|
||||||
|
DynamicTableNameHandler.remove();
|
||||||
|
return adNonHarmonicResults;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<SimAndDigNonHarmonicResult> listAllSimAndDigRawData(String scriptId, String code, String devId) {
|
public List<SimAndDigNonHarmonicResult> listAllSimAndDigRawData(String scriptId, String code, String devId) {
|
||||||
@@ -197,5 +212,96 @@ public class SimAndDigNonHarmonicServiceImpl extends ServiceImpl<SimAndDigNonHar
|
|||||||
return results;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -90,10 +90,14 @@ public class StorageUtil {
|
|||||||
*/
|
*/
|
||||||
case "P":
|
case "P":
|
||||||
case "W":
|
case "W":
|
||||||
case "VARW":
|
|
||||||
case "VAW":
|
|
||||||
unit = "W";
|
unit = "W";
|
||||||
break;
|
break;
|
||||||
|
case "VARW":
|
||||||
|
unit = "Var";
|
||||||
|
break;
|
||||||
|
case "VAW":
|
||||||
|
unit = "VA";
|
||||||
|
break;
|
||||||
/**
|
/**
|
||||||
* 闪变
|
* 闪变
|
||||||
*/
|
*/
|
||||||
@@ -116,6 +120,8 @@ public class StorageUtil {
|
|||||||
*/
|
*/
|
||||||
case "VA":
|
case "VA":
|
||||||
case "IA":
|
case "IA":
|
||||||
|
case "U1A":
|
||||||
|
case "I1A":
|
||||||
unit = "°";
|
unit = "°";
|
||||||
break;
|
break;
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -83,9 +83,9 @@ public class DictTreeServiceImpl extends ServiceImpl<DictTreeMapper, DictTree> i
|
|||||||
public boolean updateDictTree(DictTreeParam.UpdateParam param) {
|
public boolean updateDictTree(DictTreeParam.UpdateParam param) {
|
||||||
param.setName(param.getName().trim());
|
param.setName(param.getName().trim());
|
||||||
DictTree dictTree = this.getById(param.getId());
|
DictTree dictTree = this.getById(param.getId());
|
||||||
if ("975f63baeb6f653c54fca226a9ae36ca".equals(param.getId()) || dictTree.getPids().contains("975f63baeb6f653c54fca226a9ae36ca")) {
|
// if ("975f63baeb6f653c54fca226a9ae36ca".equals(param.getId()) || dictTree.getPids().contains("975f63baeb6f653c54fca226a9ae36ca")) {
|
||||||
throw new BusinessException(SystemResponseEnum.CAN_NOT_UPDATE_USED_DICT);
|
// throw new BusinessException(SystemResponseEnum.CAN_NOT_UPDATE_USED_DICT);
|
||||||
}
|
// }
|
||||||
checkRepeat(param, true);
|
checkRepeat(param, true);
|
||||||
DictTree copyDictTree = new DictTree();
|
DictTree copyDictTree = new DictTree();
|
||||||
BeanUtils.copyProperties(param, copyDictTree);
|
BeanUtils.copyProperties(param, copyDictTree);
|
||||||
|
|||||||
@@ -1,57 +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","闪变"),
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
;
|
|
||||||
|
|
||||||
|
|
||||||
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 "";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -8,6 +8,7 @@ import lombok.Setter;
|
|||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.docx4j.XmlUtils;
|
import org.docx4j.XmlUtils;
|
||||||
import org.docx4j.openpackaging.packages.WordprocessingMLPackage;
|
import org.docx4j.openpackaging.packages.WordprocessingMLPackage;
|
||||||
|
import org.docx4j.openpackaging.parts.WordprocessingML.DocumentSettingsPart;
|
||||||
import org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart;
|
import org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart;
|
||||||
import org.docx4j.wml.*;
|
import org.docx4j.wml.*;
|
||||||
import org.docx4j.wml.TcPrInner.GridSpan;
|
import org.docx4j.wml.TcPrInner.GridSpan;
|
||||||
@@ -31,6 +32,27 @@ import java.util.Map;
|
|||||||
@Slf4j
|
@Slf4j
|
||||||
public class Docx4jUtil {
|
public class Docx4jUtil {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 让 Word 打开文档时自动刷新 PAGE / NUMPAGES 等域,避免动态插表后页码显示旧值。
|
||||||
|
*/
|
||||||
|
public static void enableUpdateFieldsOnOpen(WordprocessingMLPackage wordPackage) throws Exception {
|
||||||
|
if (wordPackage == null || wordPackage.getMainDocumentPart() == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
DocumentSettingsPart settingsPart = wordPackage.getMainDocumentPart().getDocumentSettingsPart(true);
|
||||||
|
CTSettings settings = settingsPart.getContents();
|
||||||
|
if (settings == null) {
|
||||||
|
settings = new CTSettings();
|
||||||
|
settingsPart.setJaxbElement(settings);
|
||||||
|
}
|
||||||
|
BooleanDefaultTrue updateFields = settings.getUpdateFields();
|
||||||
|
if (updateFields == null) {
|
||||||
|
updateFields = new BooleanDefaultTrue();
|
||||||
|
settings.setUpdateFields(updateFields);
|
||||||
|
}
|
||||||
|
updateFields.setVal(Boolean.TRUE);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建标题
|
* 创建标题
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user