Compare commits
135 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
391646d416 | ||
|
|
4f3f0833d5 | ||
|
|
924c2e8f45 | ||
|
|
8dca7bf537 | ||
|
|
7e6fb2d981 | ||
|
|
ec9a0ca236 | ||
|
|
7ab5b9a501 | ||
|
|
3959b96040 | ||
|
|
ae5370abdf | ||
|
|
1894cb07a2 | ||
|
|
08dff063c9 | ||
|
|
f640afb4ed | ||
|
|
503018a721 | ||
|
|
391fd0cf4f | ||
|
|
99c7448544 | ||
|
|
83296d257c | ||
|
|
e020aa466e | ||
|
|
f20e2c9b32 | ||
|
|
e03c3e3607 | ||
|
|
27f25d2404 | ||
|
|
a77313171c | ||
|
|
a658d6e81a | ||
|
|
ab11c91579 | ||
|
|
a2468f1353 | ||
|
|
d8bcca1ede | ||
|
|
c5e77ee9b1 | ||
|
|
2293d81b71 | ||
|
|
97157a5ccf | ||
|
|
fd7c6ada6b | ||
|
|
c148bddfc9 | ||
|
|
f0857b7c46 | ||
| 9b1c6f61e6 | |||
|
|
3f72c52cdc | ||
|
|
ef757c52ea | ||
|
|
4110a835c8 | ||
|
|
e78ce544e3 | ||
|
|
c10d54e79a | ||
|
|
2796558040 | ||
|
|
920a808729 | ||
|
|
8e24ac4b71 | ||
|
|
3eb2736edb | ||
|
|
8c3eba9224 | ||
|
|
6288aa565e | ||
|
|
0fa7ec91c4 | ||
|
|
fdb4b7060a | ||
| 3f47b0f008 | |||
|
|
cb431b5af1 | ||
|
|
153428b24f | ||
|
|
d92544f7c4 | ||
|
|
3f1ae1886a | ||
|
|
af4863af65 | ||
|
|
4b7c1259a7 | ||
|
|
de1496389e | ||
| 79003cd0f4 | |||
|
|
c3443fcc91 | ||
|
|
5105e77823 | ||
|
|
eb068b76a4 | ||
| 9f11f7ec11 | |||
| 2012221b73 | |||
|
|
9ab5d42439 | ||
| 7abcaefeb1 | |||
|
|
f4df52dd1c | ||
| db115bb27d | |||
|
|
68d96e67aa | ||
| 3f94012faa | |||
| 41c557118c | |||
| 6596a572d6 | |||
| 139c7b0651 | |||
|
|
ab236cd34f | ||
|
|
786bd5d660 | ||
|
|
21d2c2b7a7 | ||
|
|
48fa4c2390 | ||
|
|
033330b005 | ||
|
|
f81123c3f7 | ||
|
|
5539cb2887 | ||
|
|
1df9c8d703 | ||
|
|
1cbed2a620 | ||
| 89667367ea | |||
| 92b95dd86d | |||
|
|
6b7e38fef6 | ||
|
|
f10debe2f2 | ||
|
|
9d15351fba | ||
|
|
2339a006ec | ||
|
|
7fd904ab79 | ||
|
|
61f149b562 | ||
|
|
57ee3a4d43 | ||
| 563eb80b65 | |||
|
|
dae10378dd | ||
|
|
40cb153656 | ||
|
|
af4f000b13 | ||
|
|
f922ee97aa | ||
|
|
321ec97130 | ||
|
|
0dd3502942 | ||
|
|
26c5e933f5 | ||
|
|
00ba09faae | ||
|
|
40e39d651b | ||
|
|
02c8164b7e | ||
|
|
8c598aec1e | ||
|
|
2c59defdc2 | ||
|
|
5642bf2b31 | ||
|
|
ba76df66b0 | ||
|
|
57c419eb70 | ||
|
|
98f4ecef6c | ||
|
|
20e07712cb | ||
|
|
ac1d98efdc | ||
|
|
5d161acfad | ||
|
|
1534327f6f | ||
|
|
04ada8740a | ||
|
|
98cca582f6 | ||
|
|
a2de4b80a7 | ||
|
|
c7d8fc3168 | ||
|
|
071c6e3d64 | ||
| b4878d4a25 | |||
|
|
bb22857fc9 | ||
|
|
b0a4458c56 | ||
| 6357cde72b | |||
| dddffe43cb | |||
|
|
51fdf6bf59 | ||
|
|
b53ef274cf | ||
|
|
90d618b66f | ||
| e81413eaa9 | |||
| 33cefdd0b1 | |||
| 80a886a5eb | |||
| 0a85b433ba | |||
|
|
66786200bd | ||
| 15e93b6734 | |||
|
|
6843497908 | ||
|
|
cd486f419f | ||
|
|
7394762e28 | ||
|
|
2f75fe062b | ||
|
|
d4e09a09cf | ||
|
|
d58452012d | ||
|
|
014ac7931e | ||
|
|
6ef908ff60 | ||
|
|
7461801657 |
@@ -139,6 +139,12 @@
|
||||
<artifactId>report-generator</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</dependency>
|
||||
<!--激活工具-->
|
||||
<dependency>
|
||||
<groupId>com.njcn.gather</groupId>
|
||||
<artifactId>activate-tool</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ import com.njcn.gather.detection.pojo.param.ContrastDetectionParam;
|
||||
import com.njcn.gather.detection.pojo.param.PreDetectionParam;
|
||||
import com.njcn.gather.detection.pojo.param.SimulateDetectionParam;
|
||||
import com.njcn.gather.detection.service.PreDetectionService;
|
||||
import com.njcn.gather.detection.util.socket.CnSocketUtil;
|
||||
import com.njcn.web.controller.BaseController;
|
||||
import com.njcn.web.utils.HttpResultUtil;
|
||||
import io.swagger.annotations.Api;
|
||||
@@ -155,4 +156,47 @@ public class PreDetectionController extends BaseController {
|
||||
LogUtil.njcnDebug(log, "{}", methodDescribe);
|
||||
preDetectionService.exportAlignData();
|
||||
}
|
||||
|
||||
@OperateInfo(info = LogEnum.SYSTEM_COMMON)
|
||||
@GetMapping("/canCoefficient")
|
||||
@ApiOperation("比对模式是否能够进行系数校验")
|
||||
public HttpResult<Boolean> canCoefficient() {
|
||||
String methodDescribe = getMethodDescribe("canCoefficient");
|
||||
LogUtil.njcnDebug(log, "{}", methodDescribe);
|
||||
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, preDetectionService.getCanCoefficient(), methodDescribe);
|
||||
}
|
||||
|
||||
@OperateInfo(info = LogEnum.SYSTEM_COMMON)
|
||||
@GetMapping("/startCoefficient")
|
||||
@ApiOperation("比对模式开启系数校验")
|
||||
public HttpResult<String> startCoefficient() {
|
||||
String methodDescribe = getMethodDescribe("startCoefficient");
|
||||
LogUtil.njcnDebug(log, "{}", methodDescribe);
|
||||
|
||||
preDetectionService.startCoefficient();
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
|
||||
}
|
||||
|
||||
@OperateInfo(info = LogEnum.SYSTEM_COMMON)
|
||||
@GetMapping("/startFreqConverter")
|
||||
@ApiOperation("开启变频器测试")
|
||||
public HttpResult<String> startFreqConverter(@RequestParam("userId") String userId, @RequestParam("converterId") String converterId, @RequestParam("monitorId") String monitorId, @RequestParam("reset") Boolean reset) {
|
||||
String methodDescribe = getMethodDescribe("startFreqConverter");
|
||||
LogUtil.njcnDebug(log, "{}", methodDescribe);
|
||||
|
||||
preDetectionService.startFreqConverter(userId, converterId, monitorId,reset);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
|
||||
}
|
||||
|
||||
@OperateInfo(info = LogEnum.SYSTEM_COMMON)
|
||||
@GetMapping("/stopFreqConverter")
|
||||
@ApiOperation("关闭变频器测试")
|
||||
public HttpResult<String> stopFreqConverter(@RequestParam("userId") String userId) {
|
||||
String methodDescribe = getMethodDescribe("stopFreqConverter");
|
||||
LogUtil.njcnDebug(log, "{}", methodDescribe);
|
||||
|
||||
preDetectionService.stopFreqConverter(userId + CnSocketUtil.FREQ_CONVERTER_TAG, userId + CnSocketUtil.DEV_TAG);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -439,6 +439,7 @@ public class SocketDevResponseService {
|
||||
|
||||
//告诉前端当前项开始了
|
||||
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());
|
||||
@@ -612,7 +613,7 @@ public class SocketDevResponseService {
|
||||
|
||||
private void assemblyEntity(List<DevData> deList, DevXiNumData.F F, DevXiNumData.GF startF, CoefficientVO coefficientVO, CoefficientVO.DevParameter devParameter) {
|
||||
//表示接收完成,必须保证3个数
|
||||
if (deList.size() >= 3) {
|
||||
if (deList.size() >= 7) {
|
||||
List<Double> aList = deList.stream().map(it -> it.getSqlData().get(0).getList().getA()).collect(Collectors.toList());
|
||||
List<Double> bList = deList.stream().map(it -> it.getSqlData().get(0).getList().getB()).collect(Collectors.toList());
|
||||
List<Double> cList = deList.stream().map(it -> it.getSqlData().get(0).getList().getC()).collect(Collectors.toList());
|
||||
@@ -687,7 +688,7 @@ public class SocketDevResponseService {
|
||||
*/
|
||||
private Double reduceList(List<Double> valList) {
|
||||
// valList.subList(0, 5).clear();
|
||||
// valList.subList(valList.size() - 3, valList.size() - 1).clear();
|
||||
valList.subList(valList.size() - 2, valList.size()).clear();
|
||||
return valList.stream().mapToDouble(Double::doubleValue).average().getAsDouble();
|
||||
}
|
||||
|
||||
@@ -953,6 +954,7 @@ public class SocketDevResponseService {
|
||||
} 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());
|
||||
@@ -1210,6 +1212,7 @@ public class SocketDevResponseService {
|
||||
} 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());
|
||||
@@ -1782,6 +1785,7 @@ public class SocketDevResponseService {
|
||||
} else {
|
||||
dataRule = DictDataEnum.SECTION_VALUE;
|
||||
}
|
||||
FormalTestManager.currentTestPlan = plan;
|
||||
|
||||
String code = dictDataService.getDictDataById(plan.getPattern()).getCode();
|
||||
FormalTestManager.patternEnum = PatternEnum.getEnum(code);
|
||||
|
||||
@@ -0,0 +1,369 @@
|
||||
package com.njcn.gather.detection.handler;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.collection.ListUtil;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.njcn.db.mybatisplus.handler.DynamicTableNameHandler;
|
||||
import com.njcn.gather.detection.pojo.enums.DetectionCodeEnum;
|
||||
import com.njcn.gather.detection.pojo.enums.SourceOperateCodeEnum;
|
||||
import com.njcn.gather.detection.pojo.enums.SourceResponseCodeEnum;
|
||||
import com.njcn.gather.detection.pojo.param.DevPhaseSequenceParam;
|
||||
import com.njcn.gather.detection.pojo.po.DevData;
|
||||
import com.njcn.gather.detection.pojo.vo.SocketDataMsg;
|
||||
import com.njcn.gather.detection.pojo.vo.SocketMsg;
|
||||
import com.njcn.gather.detection.util.socket.CnSocketUtil;
|
||||
import com.njcn.gather.detection.util.socket.FormalTestManager;
|
||||
import com.njcn.gather.detection.util.socket.MsgUtil;
|
||||
import com.njcn.gather.detection.util.socket.SocketManager;
|
||||
import com.njcn.gather.detection.util.socket.cilent.NettyClient;
|
||||
import com.njcn.gather.detection.util.socket.cilent.NettyFreqConverterDevClientHandler;
|
||||
import com.njcn.gather.detection.util.socket.config.SocketConnectionConfig;
|
||||
import com.njcn.gather.detection.util.socket.websocket.WebServiceManager;
|
||||
import com.njcn.gather.device.pojo.po.PqDev;
|
||||
import com.njcn.gather.device.pojo.vo.PreDetection;
|
||||
import com.njcn.gather.device.service.IPqDevService;
|
||||
import com.njcn.gather.dip.pojo.po.PqDipData;
|
||||
import com.njcn.gather.dip.service.IPqDipDataService;
|
||||
import com.njcn.gather.freqConverter.config.FreqConverterConfig;
|
||||
import com.njcn.gather.freqConverter.pojo.po.FreqConverterStatus;
|
||||
import com.njcn.gather.freqConverter.pojo.po.PqFreqConverterTestRes;
|
||||
import com.njcn.gather.freqConverter.service.IFreqConverterService;
|
||||
import com.njcn.gather.freqConverter.service.IPqFreqConverterTestResService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class SocketFreqConverterDevService {
|
||||
|
||||
private final SocketConnectionConfig socketConnectionConfig;
|
||||
private final IPqDevService pqDevService;
|
||||
private final IPqDipDataService pqDipDataService;
|
||||
private final IFreqConverterService freqConverterService;
|
||||
private final IPqFreqConverterTestResService pqFreqConverterTestResService;
|
||||
private final FreqConverterConfig freqConverterConfig;
|
||||
private String monitorId;
|
||||
private String userId;
|
||||
|
||||
public static final String DIP_DATA_SUFFIX = "&&VOLTAGE";
|
||||
|
||||
/**
|
||||
* 连接设备Socket
|
||||
*
|
||||
* @param devTag 设备Channel唯一标识符
|
||||
*/
|
||||
public void connectSocket(String devTag) {
|
||||
if (SocketManager.isChannelActive(devTag)) {
|
||||
return;
|
||||
}
|
||||
String ip = socketConnectionConfig.getDevice().getIp();
|
||||
Integer port = socketConnectionConfig.getDevice().getPort();
|
||||
|
||||
NettyFreqConverterDevClientHandler handler = new NettyFreqConverterDevClientHandler(devTag, this);
|
||||
CompletableFuture.runAsync(() -> {
|
||||
NettyClient.commonConnect(ip, port, devTag, handler);
|
||||
});
|
||||
}
|
||||
|
||||
private void init(String userId, String converterId, String monitorId, Boolean reset) {
|
||||
FormalTestManager.freqConverterDevStep = null;
|
||||
// FormalTestManager.stopFlag = false;
|
||||
FormalTestManager.isRemoveSocket = false;
|
||||
FormalTestManager.pendingDipTaskMap.clear();
|
||||
if (reset) {
|
||||
pqDipDataService.clearAllData(FormalTestManager.freqConverterTableSuffix);
|
||||
pqFreqConverterTestResService.clearAllData(FormalTestManager.freqConverterTableSuffix);
|
||||
}
|
||||
this.userId = userId;
|
||||
this.monitorId = monitorId;
|
||||
}
|
||||
|
||||
/**
|
||||
* 连接设备
|
||||
*/
|
||||
public void connectionDev(String userId, String devTag, String converterId, String monitorId, Boolean reset) {
|
||||
this.init(userId, converterId, monitorId, reset);
|
||||
|
||||
String payload = buildSingleMonitorPayload(monitorId);
|
||||
if (StrUtil.isBlank(payload)) {
|
||||
return;
|
||||
}
|
||||
|
||||
SocketMsg<String> socketMsg = new SocketMsg<>();
|
||||
socketMsg.setRequestId(SourceOperateCodeEnum.YJC_SBTXJY.getValue());
|
||||
socketMsg.setOperateCode(SourceOperateCodeEnum.DEV_INIT_GATHER_03.getValue());
|
||||
socketMsg.setData(payload);
|
||||
SocketManager.sendMsg(devTag, JSON.toJSONString(socketMsg));
|
||||
FormalTestManager.freqConverterDevStep = SourceOperateCodeEnum.YJC_SBTXJY;
|
||||
}
|
||||
|
||||
public void handleRead(String devTag, String msg) {
|
||||
SocketDataMsg socketDataMsg = MsgUtil.socketDataMsg(msg);
|
||||
|
||||
switch (FormalTestManager.freqConverterDevStep) {
|
||||
case YJC_SBTXJY:
|
||||
handleYjcSbtxjy(devTag, socketDataMsg);
|
||||
break;
|
||||
case FORMAL_REAL:
|
||||
handleFormalReal(devTag, socketDataMsg);
|
||||
break;
|
||||
case QUITE:
|
||||
handleQuit(devTag, socketDataMsg);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void handleYjcSbtxjy(String devTag, SocketDataMsg socketDataMsg) {
|
||||
SourceResponseCodeEnum responseCodeEnum = SourceResponseCodeEnum.getDictDataEnumByCode(socketDataMsg.getCode());
|
||||
switch (Objects.requireNonNull(responseCodeEnum)) {
|
||||
case UNPROCESSED_BUSINESS:
|
||||
break;
|
||||
case RE_OPERATE:
|
||||
WebServiceManager.sendMsg(this.userId, JSON.toJSONString(socketDataMsg));
|
||||
break;
|
||||
case SUCCESS:
|
||||
// 暂态协议触发后等待5秒,将装置历史缓存的暂态数据给抛掉
|
||||
CompletableFuture.runAsync(() -> {
|
||||
try {
|
||||
Thread.sleep(5000);
|
||||
this.sendGetDipDataMsg(devTag);
|
||||
FormalTestManager.freqConverterDevStep = SourceOperateCodeEnum.FORMAL_REAL;
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
log.error("异步调用sendGetDipDataMsg被中断", e);
|
||||
}
|
||||
});
|
||||
break;
|
||||
default:
|
||||
log.warn("设备响应异常,devTag={}, operateCode={}, code={}, data={}", devTag, socketDataMsg.getOperateCode(), socketDataMsg.getCode(), socketDataMsg.getData());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void handleFormalReal(String devTag, SocketDataMsg socketDataMsg) {
|
||||
SourceResponseCodeEnum responseCodeEnum = SourceResponseCodeEnum.getDictDataEnumByCode(socketDataMsg.getCode());
|
||||
|
||||
switch (responseCodeEnum) {
|
||||
case UNPROCESSED_BUSINESS:
|
||||
break;
|
||||
case SUCCESS:
|
||||
case NORMAL_RESPONSE:
|
||||
DevData devData = JSON.parseObject(socketDataMsg.getData(), DevData.class);
|
||||
// 如果变频器不是处于 “故障中” 状态,就保存数据,反之,这段时期内的数据不保存
|
||||
// if (!FormalTestManager.stopFlag) {
|
||||
// saveDipData(devData);
|
||||
// }
|
||||
saveDipData(devData);
|
||||
break;
|
||||
case DEV_ERROR:
|
||||
case DEV_TARGET:
|
||||
case COMMUNICATION_ERR:
|
||||
case DATA_RESOLVE:
|
||||
case NO_INIT_DEV:
|
||||
default:
|
||||
log.warn("设备响应异常,devTag={}, operateCode={}, code={}, data={}", devTag, socketDataMsg.getOperateCode(), socketDataMsg.getCode(), socketDataMsg.getData());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void handleQuit(String devTag, SocketDataMsg socketDataMsg) {
|
||||
SourceResponseCodeEnum responseCodeEnum = SourceResponseCodeEnum.getDictDataEnumByCode(socketDataMsg.getCode());
|
||||
|
||||
switch (responseCodeEnum) {
|
||||
case UNPROCESSED_BUSINESS:
|
||||
break;
|
||||
case SUCCESS:
|
||||
cleanup(devTag);
|
||||
break;
|
||||
default:
|
||||
log.warn("设备关闭响应失败,devTag={}, operateCode={}, code={}, data={}", devTag, socketDataMsg.getOperateCode(), socketDataMsg.getCode(), socketDataMsg.getData());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void stopTest(String converterTag, String devTag) {
|
||||
FormalTestManager.freqConverterDevStep = SourceOperateCodeEnum.QUITE;
|
||||
sendQuitMsg(devTag, SourceOperateCodeEnum.QUIT_INIT_03);
|
||||
}
|
||||
|
||||
|
||||
private String buildSingleMonitorPayload(String monitorId) {
|
||||
String[] split = monitorId.split(CnSocketUtil.SPLIT_TAG);
|
||||
if (split.length < 2 || StrUtil.isBlank(split[0]) || StrUtil.isBlank(split[1])) {
|
||||
return null;
|
||||
}
|
||||
|
||||
List<PreDetection> preDetections = pqDevService.getDevInfo(Collections.singletonList(split[0]));
|
||||
if (CollUtil.isEmpty(preDetections)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
PreDetection preDetection = preDetections.get(0);
|
||||
List<PreDetection.MonitorListDTO> monitorList = preDetection.getMonitorList();
|
||||
if (CollUtil.isEmpty(monitorList)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
List<PreDetection.MonitorListDTO> matchedMonitorList = monitorList.stream()
|
||||
.filter(item -> split[1].equals(StrUtil.EMPTY + item.getLine()))
|
||||
.collect(Collectors.toList());
|
||||
if (CollUtil.isEmpty(matchedMonitorList)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
preDetection.setMonitorList(matchedMonitorList);
|
||||
Map<String, List<PreDetection>> payload = new HashMap<>(1);
|
||||
payload.put("deviceList", Collections.singletonList(preDetection));
|
||||
return JSON.toJSONString(payload);
|
||||
}
|
||||
|
||||
private void sendGetDipDataMsg(String devTag) {
|
||||
SocketMsg<String> socketMsg = new SocketMsg<>();
|
||||
socketMsg.setRequestId(SourceOperateCodeEnum.FORMAL_REAL.getValue() + DIP_DATA_SUFFIX);
|
||||
socketMsg.setOperateCode(SourceOperateCodeEnum.OPER_GATHER.getValue());
|
||||
|
||||
DevPhaseSequenceParam phaseSequenceParam = new DevPhaseSequenceParam();
|
||||
String[] split = this.monitorId.split(String.valueOf(StrUtil.C_UNDERLINE));
|
||||
PqDev dev = pqDevService.getById(split[0]);
|
||||
|
||||
// 设置监测点ID列表
|
||||
phaseSequenceParam.setMoniterIdList(ListUtil.of(dev.getIp() + StrUtil.C_UNDERLINE + split[1]));
|
||||
|
||||
// 设置数据类型列表
|
||||
phaseSequenceParam.setDataType(ListUtil.of("avg$MAG", "avg$DUR"));
|
||||
// 设置读取次数
|
||||
phaseSequenceParam.setReadCount(0);
|
||||
// 设置忽略次数
|
||||
phaseSequenceParam.setIgnoreCount(0);
|
||||
socketMsg.setData(JSON.toJSONString(phaseSequenceParam));
|
||||
socketMsg.setOperateCode(SourceOperateCodeEnum.DEV_DATA_REQUEST_03.getValue());
|
||||
SocketManager.sendMsg(devTag, JSON.toJSONString(socketMsg));
|
||||
}
|
||||
|
||||
private void sendQuitMsg(String devTag, SourceOperateCodeEnum operateCodeEnum) {
|
||||
SocketMsg<String> socketMsg = new SocketMsg<>();
|
||||
socketMsg.setRequestId(SourceOperateCodeEnum.QUITE.getValue());
|
||||
socketMsg.setOperateCode(operateCodeEnum.getValue());
|
||||
SocketManager.sendMsg(devTag, JSON.toJSONString(socketMsg));
|
||||
}
|
||||
|
||||
private void saveDipData(DevData devData) {
|
||||
if (Objects.isNull(devData) || CollUtil.isEmpty(devData.getSqlData())) {
|
||||
return;
|
||||
}
|
||||
|
||||
Double residualVoltage = null;
|
||||
Integer durationMs = null;
|
||||
for (DevData.SqlDataDTO sqlDataDTO : devData.getSqlData()) {
|
||||
if (Objects.isNull(sqlDataDTO) || Objects.isNull(sqlDataDTO.getList())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Double value = getSqlDataValue(sqlDataDTO.getList());
|
||||
if (Objects.isNull(value)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (DetectionCodeEnum.MAG.getCode().equalsIgnoreCase(sqlDataDTO.getDesc())) {
|
||||
residualVoltage = value;
|
||||
} else if (DetectionCodeEnum.DUR.getCode().equalsIgnoreCase(sqlDataDTO.getDesc())) {
|
||||
durationMs = (int) Math.round(value * 1000);
|
||||
}
|
||||
}
|
||||
|
||||
PqDipData pqDipData = new PqDipData();
|
||||
pqDipData.setId(IdUtil.fastSimpleUUID());
|
||||
pqDipData.setStartTime(LocalDateTime.parse(devData.getTime()));
|
||||
pqDipData.setResidualVoltage(residualVoltage);
|
||||
pqDipData.setDurationMs(durationMs);
|
||||
DynamicTableNameHandler.setTableName("pq_dip_data_" + FormalTestManager.freqConverterTableSuffix);
|
||||
pqDipDataService.save(pqDipData);
|
||||
DynamicTableNameHandler.remove();
|
||||
|
||||
this.initDipTestRes(pqDipData);
|
||||
}
|
||||
|
||||
private void initDipTestRes(PqDipData pqDipData) {
|
||||
Integer suffix = FormalTestManager.freqConverterTableSuffix;
|
||||
FreqConverterStatus lastStatusData = freqConverterService.getLastStatusData(suffix, pqDipData.getStartTime());
|
||||
if (Objects.isNull(lastStatusData)) {
|
||||
return;
|
||||
}
|
||||
|
||||
List<FreqConverterStatus> statusList = freqConverterService.getDipDurationStatusData(suffix, lastStatusData.getTimestamp(), pqDipData.getStartTime().plusNanos(pqDipData.getDurationMs() * 1000_000L));
|
||||
Integer originalTolerant = (lastStatusData.getStatusWord1() == freqConverterConfig.getTolerant()) ? 1 : 0;
|
||||
LocalDateTime targetEndTime = pqDipData.getStartTime()
|
||||
.plusNanos(pqDipData.getDurationMs() * 1000_000L)
|
||||
.plusNanos(freqConverterConfig.getDt() * 1000_000L);
|
||||
|
||||
if (CollUtil.isNotEmpty(statusList)) {
|
||||
FreqConverterStatus status = statusList.get(statusList.size() - 1);
|
||||
PqFreqConverterTestRes testRes = new PqFreqConverterTestRes();
|
||||
testRes.setId(IdUtil.fastSimpleUUID());
|
||||
testRes.setTolerant(originalTolerant == 1 ?
|
||||
(status.getStatusWord1() == freqConverterConfig.getTolerant() ? 1 : 0)
|
||||
: 0);
|
||||
testRes.setDurationMs(pqDipData.getDurationMs());
|
||||
testRes.setResidualVoltage(pqDipData.getResidualVoltage());
|
||||
testRes.setTime(LocalDateTime.now());
|
||||
|
||||
FormalTestManager.pendingDipTaskMap.put(testRes.getId(), new FormalTestManager.PendingDipTask(
|
||||
pqDipData,
|
||||
targetEndTime,
|
||||
originalTolerant
|
||||
));
|
||||
|
||||
pqFreqConverterTestResService.saveTestRes(suffix, Collections.singletonList(testRes));
|
||||
}
|
||||
}
|
||||
|
||||
private Double getSqlDataValue(DevData.SqlDataDTO.ListDTO listDTO) {
|
||||
if (Objects.nonNull(listDTO.getA())) {
|
||||
return listDTO.getA();
|
||||
}
|
||||
if (Objects.nonNull(listDTO.getB())) {
|
||||
return listDTO.getB();
|
||||
}
|
||||
if (Objects.nonNull(listDTO.getC())) {
|
||||
return listDTO.getC();
|
||||
}
|
||||
return listDTO.getT();
|
||||
}
|
||||
|
||||
public void cleanup(String devTag) {
|
||||
String currentUserId = this.userId;
|
||||
FormalTestManager.freqConverterDevStep = null;
|
||||
FormalTestManager.isRemoveSocket = true;
|
||||
SocketManager.removeUser(devTag);
|
||||
clearStateIfStopped(currentUserId);
|
||||
this.userId = null;
|
||||
this.monitorId = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 如果设备已停止,则清除共享的运行时状态
|
||||
*
|
||||
* @param currentUserId 当前用户ID
|
||||
*/
|
||||
private void clearStateIfStopped(String currentUserId) {
|
||||
if (StrUtil.isBlank(currentUserId)) {
|
||||
FormalTestManager.clearFreqConverterRuntimeState();
|
||||
return;
|
||||
}
|
||||
String freqConverterTag = currentUserId + CnSocketUtil.FREQ_CONVERTER_TAG;
|
||||
// 避免过早把 freqConverterTableSuffix 等全局值清掉,造成变频器无法使用全局变量
|
||||
if (!SocketManager.isChannelActive(freqConverterTag)) {
|
||||
FormalTestManager.freqConverterStep = null;
|
||||
FormalTestManager.clearFreqConverterRuntimeState();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,433 @@
|
||||
package com.njcn.gather.detection.handler;
|
||||
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.json.JSONObject;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.njcn.gather.detection.pojo.dto.FreqConverterRespDTO;
|
||||
import com.njcn.gather.detection.pojo.enums.SourceOperateCodeEnum;
|
||||
import com.njcn.gather.detection.pojo.vo.SocketDataMsg;
|
||||
import com.njcn.gather.detection.pojo.vo.SocketMsg;
|
||||
import com.njcn.gather.detection.util.socket.CnSocketUtil;
|
||||
import com.njcn.gather.detection.util.socket.FormalTestManager;
|
||||
import com.njcn.gather.detection.util.socket.SocketManager;
|
||||
import com.njcn.gather.detection.util.socket.cilent.NettyClient;
|
||||
import com.njcn.gather.detection.util.socket.cilent.NettyFreqConverterClientHandler;
|
||||
import com.njcn.gather.detection.util.socket.config.SocketConnectionConfig;
|
||||
import com.njcn.gather.detection.util.socket.websocket.WebServiceManager;
|
||||
import com.njcn.gather.freqConverter.config.FreqConverterConfig;
|
||||
import com.njcn.gather.freqConverter.pojo.po.FreqConverterStatus;
|
||||
import com.njcn.gather.freqConverter.pojo.po.PqFreqConverterConfig;
|
||||
import com.njcn.gather.freqConverter.pojo.po.PqFreqConverterTestRes;
|
||||
import com.njcn.gather.freqConverter.pojo.vo.TolerantPointVO;
|
||||
import com.njcn.gather.freqConverter.service.IFreqConverterService;
|
||||
import com.njcn.gather.freqConverter.service.IPqFreqConverterConfigService;
|
||||
import com.njcn.gather.freqConverter.service.IPqFreqConverterTestResService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* @author czh
|
||||
* @version 1.0
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class SocketFreqConverterService {
|
||||
private final IFreqConverterService freqConverterService;
|
||||
|
||||
private final SocketConnectionConfig socketConnectionConfig;
|
||||
|
||||
private final IPqFreqConverterConfigService pqFreqConverterConfigService;
|
||||
private final IPqFreqConverterTestResService pqFreqConverterTestResService;
|
||||
private String userId;
|
||||
/**
|
||||
* 上一个暂降点耐受检测结果
|
||||
*/
|
||||
private TolerantPointVO lastTolerancePoint;
|
||||
private final FreqConverterConfig freqConverterConfig;
|
||||
|
||||
/**
|
||||
* 连接变频器Socket
|
||||
*
|
||||
* @param converterChannelTag 变频器Channel唯一标识符
|
||||
*/
|
||||
public void connectSocket(String converterChannelTag) {
|
||||
if (SocketManager.isChannelActive(converterChannelTag)) {
|
||||
return;
|
||||
}
|
||||
String ip = socketConnectionConfig.getFreqConverter().getIp();
|
||||
Integer port = socketConnectionConfig.getFreqConverter().getPort();
|
||||
|
||||
NettyFreqConverterClientHandler handler = new NettyFreqConverterClientHandler(converterChannelTag, this);
|
||||
|
||||
CompletableFuture.runAsync(() -> {
|
||||
NettyClient.commonConnect(ip, port, converterChannelTag, handler);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 重连
|
||||
*
|
||||
* @param converterChannelTag
|
||||
*/
|
||||
public void reconnect(String converterChannelTag) {
|
||||
SocketManager.removeUser(converterChannelTag);
|
||||
|
||||
String ip = socketConnectionConfig.getFreqConverter().getIp();
|
||||
Integer port = socketConnectionConfig.getFreqConverter().getPort();
|
||||
|
||||
NettyFreqConverterClientHandler handler = new NettyFreqConverterClientHandler(converterChannelTag, this);
|
||||
|
||||
CompletableFuture.runAsync(() -> {
|
||||
NettyClient.commonConnect(ip, port, converterChannelTag, handler);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 重试连接成功,重新开启定时任务,获取变频器状态数据
|
||||
*
|
||||
* @param converterChannelTag
|
||||
*/
|
||||
public void onReconnectSuccess(String converterChannelTag) {
|
||||
log.info("变频器重连成功,恢复数据采集,converterChannelTag={}", converterChannelTag);
|
||||
|
||||
// FormalTestManager.stopFlag = false;
|
||||
|
||||
if (FormalTestManager.scheduler == null) {
|
||||
FormalTestManager.scheduler = Executors.newScheduledThreadPool(1);
|
||||
FormalTestManager.scheduledFuture = FormalTestManager.scheduler.scheduleAtFixedRate(() -> {
|
||||
this.sendGetDeviceStatusMsg(converterChannelTag);
|
||||
}, 0l, 200l, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
}
|
||||
|
||||
public void init(String userId, String converterId, String monitorId, Boolean reset) {
|
||||
this.lastTolerancePoint = null;
|
||||
this.userId = userId;
|
||||
FormalTestManager.freqConverterStep = null;
|
||||
FormalTestManager.currentFreqConverterId = converterId;
|
||||
Integer suffix = pqFreqConverterConfigService.getSuffix(converterId);
|
||||
if (reset) {
|
||||
freqConverterService.clearAllData(suffix);
|
||||
}
|
||||
FormalTestManager.freqConverterTableSuffix = suffix;
|
||||
FormalTestManager.isRemoveSocket = false;
|
||||
FormalTestManager.pendingDipTaskMap.clear();
|
||||
pqFreqConverterConfigService.updateTestStatus(converterId, 0);
|
||||
clearScheduleTask();
|
||||
}
|
||||
|
||||
/**
|
||||
* 连接变频器
|
||||
*/
|
||||
public void connectionFreqConverter(String userId, String freqConverterTag, String converterId, String monitorId, Boolean reset) {
|
||||
this.init(userId, converterId, monitorId, reset);
|
||||
|
||||
SocketMsg<Map<String, Object>> socketMsg = new SocketMsg<>();
|
||||
socketMsg.setOperateCode(SourceOperateCodeEnum.CMD_INIT_SERIAL.getValue());
|
||||
String requestId = IdUtil.fastSimpleUUID();
|
||||
socketMsg.setRequestId(requestId);
|
||||
|
||||
PqFreqConverterConfig freqConverterConfig = pqFreqConverterConfigService.getById(converterId);
|
||||
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("portName", freqConverterConfig.getPortName());
|
||||
map.put("slaveAddress", freqConverterConfig.getSlaveAddress());
|
||||
map.put("baudRate", freqConverterConfig.getBaudRate());
|
||||
map.put("parity", freqConverterConfig.getParity());
|
||||
map.put("dataBits", freqConverterConfig.getDataBits());
|
||||
map.put("stopBits", freqConverterConfig.getStopBits());
|
||||
map.put("timeoutMs", freqConverterConfig.getTimeoutMs());
|
||||
socketMsg.setData(map);
|
||||
|
||||
SocketManager.sendMsg(freqConverterTag, JSON.toJSONString(socketMsg));
|
||||
FormalTestManager.freqConverterStep = SourceOperateCodeEnum.CMD_INIT_SERIAL;
|
||||
}
|
||||
|
||||
public void handleRead(String converterChannelTag, String msg) {
|
||||
FreqConverterRespDTO respDTO = JSON.parseObject(msg, FreqConverterRespDTO.class);
|
||||
|
||||
if (respDTO.getCode() != 0) {
|
||||
SocketDataMsg socketDataMsg = new SocketDataMsg();
|
||||
socketDataMsg.setRequestId(FormalTestManager.freqConverterStep.getValue());
|
||||
socketDataMsg.setCode(respDTO.getCode());
|
||||
WebServiceManager.sendMsg(this.userId, JSON.toJSONString(socketDataMsg));
|
||||
} else {
|
||||
switch (FormalTestManager.freqConverterStep) {
|
||||
case CMD_INIT_SERIAL:
|
||||
handleInitSerial(converterChannelTag, respDTO);
|
||||
break;
|
||||
case CMD_GET_DEVICE_STATUS:
|
||||
handleGetDeviceStatus(converterChannelTag, respDTO);
|
||||
break;
|
||||
case CMD_CLOSE_SERIAL:
|
||||
handleCloseSerial(converterChannelTag, respDTO);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void stopTest(String converterTag, String devTag) {
|
||||
FormalTestManager.freqConverterStep = SourceOperateCodeEnum.CMD_CLOSE_SERIAL;
|
||||
this.sendClose(converterTag);
|
||||
}
|
||||
|
||||
public void cleanup(String converterChannelTag) {
|
||||
String currentUserId = this.userId;
|
||||
clearScheduleTask();
|
||||
FormalTestManager.freqConverterStep = null;
|
||||
// FormalTestManager.stopFlag = false;
|
||||
FormalTestManager.isRemoveSocket = true;
|
||||
SocketManager.removeUser(converterChannelTag);
|
||||
updateCurrentTestStatus();
|
||||
clearStateIfStopped(currentUserId);
|
||||
this.userId = null;
|
||||
this.lastTolerancePoint = null;
|
||||
}
|
||||
|
||||
private void handleInitSerial(String converterChannelTag, FreqConverterRespDTO respDTO) {
|
||||
if (respDTO.getCode() == 0 && respDTO.getSuccess()) {
|
||||
FormalTestManager.freqConverterStep = SourceOperateCodeEnum.CMD_GET_DEVICE_STATUS;
|
||||
|
||||
if (Objects.isNull(FormalTestManager.scheduler)) {
|
||||
FormalTestManager.scheduler = Executors.newScheduledThreadPool(1);
|
||||
FormalTestManager.scheduledFuture = FormalTestManager.scheduler.scheduleAtFixedRate(() -> {
|
||||
this.sendGetDeviceStatusMsg(converterChannelTag);
|
||||
}, 0l, freqConverterConfig.getSchedulePeriod(), TimeUnit.MILLISECONDS);
|
||||
}
|
||||
} else {
|
||||
log.warn("变频器初始化串口失败,converterChannelTag={}, converterId={}, converterTag={}, msg={}", converterChannelTag, converterChannelTag, converterChannelTag, respDTO.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private void handleGetDeviceStatus(String converterChannelTag, FreqConverterRespDTO respDTO) {
|
||||
JSONObject obj = JSONUtil.parseObj(respDTO.getData().toString());
|
||||
String timestamp = (String) obj.get("Timestamp");
|
||||
timestamp = timestamp.replace("+08:00", StrUtil.EMPTY);
|
||||
obj.set("Timestamp", timestamp);
|
||||
|
||||
FreqConverterStatus freqConverterStatus = JSON.parseObject(obj.toString(), FreqConverterStatus.class);
|
||||
// 变频器故障中,移除这段时期内的设备数据
|
||||
// if (freqConverterStatus.getStatusWord1() == freqConverterConfig.getNoTolerant()) {
|
||||
// FormalTestManager.stopFlag = true;
|
||||
// } else {
|
||||
// FormalTestManager.stopFlag = false;
|
||||
// }
|
||||
this.consumePendingDipTasks(freqConverterStatus);
|
||||
freqConverterService.saveFreqConverterStatus(FormalTestManager.freqConverterTableSuffix, freqConverterStatus);
|
||||
}
|
||||
|
||||
private void handleCloseSerial(String converterChannelTag, FreqConverterRespDTO respDTO) {
|
||||
if (respDTO.getCode() == 0 && respDTO.getSuccess()) {
|
||||
if (FormalTestManager.currentFreqConverterId != null) {
|
||||
pqFreqConverterConfigService.updateTestStatus(FormalTestManager.currentFreqConverterId, 1);
|
||||
}
|
||||
cleanup(converterChannelTag);
|
||||
} else {
|
||||
this.sendClose(converterChannelTag);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void sendGetDeviceStatusMsg(String converterId) {
|
||||
SocketMsg<Map<String, Object>> socketMsg = new SocketMsg<>();
|
||||
socketMsg.setOperateCode(SourceOperateCodeEnum.CMD_GET_DEVICE_STATUS.getValue());
|
||||
String requestId = IdUtil.fastSimpleUUID();
|
||||
socketMsg.setRequestId(requestId);
|
||||
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
socketMsg.setData(map);
|
||||
SocketManager.sendMsg(converterId, JSON.toJSONString(socketMsg));
|
||||
}
|
||||
|
||||
private void sendClose(String converterTag) {
|
||||
SocketMsg<Map<String, Object>> socketMsg = new SocketMsg<>();
|
||||
socketMsg.setOperateCode(SourceOperateCodeEnum.CMD_CLOSE_SERIAL.getValue());
|
||||
String requestId = IdUtil.fastSimpleUUID();
|
||||
socketMsg.setRequestId(requestId);
|
||||
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
socketMsg.setData(map);
|
||||
SocketManager.sendMsg(converterTag, JSON.toJSONString(socketMsg));
|
||||
}
|
||||
|
||||
|
||||
private void clearScheduleTask() {
|
||||
if (FormalTestManager.scheduledFuture != null) {
|
||||
FormalTestManager.scheduledFuture.cancel(true);
|
||||
FormalTestManager.scheduledFuture = null;
|
||||
}
|
||||
if (FormalTestManager.scheduler != null) {
|
||||
FormalTestManager.scheduler.shutdown();
|
||||
FormalTestManager.scheduler = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void updateCurrentTestStatus() {
|
||||
if (StrUtil.isNotBlank(FormalTestManager.currentFreqConverterId)) {
|
||||
pqFreqConverterConfigService.updateTestStatus(FormalTestManager.currentFreqConverterId, 1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 如果变频器已停止,则清除共享的运行时状态
|
||||
*
|
||||
* @param currentUserId 当前用户ID
|
||||
*/
|
||||
private void clearStateIfStopped(String currentUserId) {
|
||||
if (StrUtil.isBlank(currentUserId)) {
|
||||
FormalTestManager.clearFreqConverterRuntimeState();
|
||||
return;
|
||||
}
|
||||
String devTag = currentUserId + CnSocketUtil.DEV_TAG;
|
||||
// 避免过早把 freqConverterTableSuffix 等全局值清掉,造成设备无法使用全局变量
|
||||
if (!SocketManager.isChannelActive(devTag)) {
|
||||
FormalTestManager.freqConverterDevStep = null;
|
||||
FormalTestManager.clearFreqConverterRuntimeState();
|
||||
}
|
||||
}
|
||||
|
||||
private void consumePendingDipTasks(FreqConverterStatus freqConverterStatus) {
|
||||
if (FormalTestManager.pendingDipTaskMap.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Integer suffix = FormalTestManager.freqConverterTableSuffix;
|
||||
List<String> finishedTestResIdList = new ArrayList<>();
|
||||
List<PqFreqConverterTestRes> saveTestResList = new ArrayList<>();
|
||||
List<PqFreqConverterTestRes> updateTestResList = new ArrayList<>();
|
||||
|
||||
FormalTestManager.pendingDipTaskMap.forEach((key, task) -> {
|
||||
if (freqConverterStatus.getTimestamp().isAfter(task.getTargetEndTime())) {
|
||||
PqFreqConverterTestRes testRes = new PqFreqConverterTestRes();
|
||||
testRes.setId(key);
|
||||
testRes.setDurationMs(task.getPqDipData().getDurationMs());
|
||||
testRes.setResidualVoltage(task.getPqDipData().getResidualVoltage());
|
||||
testRes.setTolerant(task.getOriginalTolerant() & (freqConverterStatus.getStatusWord1() == freqConverterConfig.getTolerant() ? 1 : 0));
|
||||
|
||||
finishedTestResIdList.add(key);
|
||||
|
||||
SocketDataMsg socketDataMsg = new SocketDataMsg();
|
||||
socketDataMsg.setRequestId(SourceOperateCodeEnum.FORMAL_REAL + SocketFreqConverterDevService.DIP_DATA_SUFFIX);
|
||||
|
||||
TolerantPointVO newTolerantPointVO = new TolerantPointVO();
|
||||
newTolerantPointVO.setResidualVoltage(task.getPqDipData().getResidualVoltage());
|
||||
newTolerantPointVO.setDurationMs(task.getPqDipData().getDurationMs());
|
||||
newTolerantPointVO.setTolerant(testRes.getTolerant());
|
||||
socketDataMsg.setData(JSON.toJSONString(newTolerantPointVO));
|
||||
WebServiceManager.sendMsg(this.userId, JSON.toJSONString(socketDataMsg));
|
||||
|
||||
if (testRes.getTolerant() == 0) {
|
||||
if (ObjectUtil.isNotNull(this.lastTolerancePoint) && this.lastTolerancePoint.getTolerant() == 1) {
|
||||
TolerantPointVO featurePointVO = new TolerantPointVO();
|
||||
|
||||
featurePointVO.setResidualVoltage(Math.round((task.getPqDipData().getResidualVoltage() + this.lastTolerancePoint.getResidualVoltage()) / 2D * 100) / 100D);
|
||||
featurePointVO.setDurationMs(Integer.valueOf((task.getPqDipData().getDurationMs().intValue() + this.lastTolerancePoint.getDurationMs().intValue()) / 2));
|
||||
featurePointVO.setTolerant(2);
|
||||
socketDataMsg.setData(JSON.toJSONString(featurePointVO));
|
||||
WebServiceManager.sendMsg(this.userId, JSON.toJSONString(socketDataMsg));
|
||||
|
||||
PqFreqConverterTestRes featureTestRes = new PqFreqConverterTestRes();
|
||||
featureTestRes.setId(IdUtil.fastSimpleUUID());
|
||||
featureTestRes.setDurationMs(featurePointVO.getDurationMs());
|
||||
featureTestRes.setResidualVoltage(featurePointVO.getResidualVoltage());
|
||||
featureTestRes.setTolerant(2);
|
||||
featureTestRes.setTime(LocalDateTime.now());
|
||||
saveTestResList.add(featureTestRes);
|
||||
}
|
||||
|
||||
// 从数据库按照列查询距离该暂降点最近的一个暂降点
|
||||
if (freqConverterConfig.getDirection() == 0) {
|
||||
PqFreqConverterTestRes lastByDuration = pqFreqConverterTestResService.getLastByDuration(suffix, key, task.getPqDipData().getDurationMs());
|
||||
if (ObjectUtil.isNotNull(lastByDuration) && lastByDuration.getTolerant() == 1) {
|
||||
TolerantPointVO featurePointVO = new TolerantPointVO();
|
||||
|
||||
featurePointVO.setResidualVoltage(Math.round((task.getPqDipData().getResidualVoltage() + lastByDuration.getResidualVoltage()) / 2D * 100) / 100D);
|
||||
featurePointVO.setDurationMs(Integer.valueOf((task.getPqDipData().getDurationMs().intValue() + lastByDuration.getDurationMs().intValue()) / 2));
|
||||
featurePointVO.setTolerant(2);
|
||||
socketDataMsg.setData(JSON.toJSONString(featurePointVO));
|
||||
WebServiceManager.sendMsg(this.userId, JSON.toJSONString(socketDataMsg));
|
||||
|
||||
PqFreqConverterTestRes featureTestRes = new PqFreqConverterTestRes();
|
||||
featureTestRes.setId(IdUtil.fastSimpleUUID());
|
||||
featureTestRes.setDurationMs(featurePointVO.getDurationMs());
|
||||
featureTestRes.setResidualVoltage(featurePointVO.getResidualVoltage());
|
||||
featureTestRes.setTolerant(2);
|
||||
featureTestRes.setTime(LocalDateTime.now());
|
||||
saveTestResList.add(featureTestRes);
|
||||
}
|
||||
}
|
||||
// 从数据库按照行查询距离该暂降点最近的一个暂降点
|
||||
if (freqConverterConfig.getDirection() == 1) {
|
||||
PqFreqConverterTestRes lastByResidualVoltage = pqFreqConverterTestResService.getLastByResidualVoltage(suffix, key, task.getPqDipData().getResidualVoltage());
|
||||
if (ObjectUtil.isNotNull(lastByResidualVoltage) && lastByResidualVoltage.getTolerant() == 1) {
|
||||
TolerantPointVO featurePointVO = new TolerantPointVO();
|
||||
|
||||
featurePointVO.setResidualVoltage(Math.round((task.getPqDipData().getResidualVoltage() + lastByResidualVoltage.getResidualVoltage()) / 2D * 100) / 100D);
|
||||
featurePointVO.setDurationMs(Integer.valueOf((task.getPqDipData().getDurationMs().intValue() + lastByResidualVoltage.getDurationMs().intValue()) / 2));
|
||||
featurePointVO.setTolerant(2);
|
||||
socketDataMsg.setData(JSON.toJSONString(featurePointVO));
|
||||
WebServiceManager.sendMsg(this.userId, JSON.toJSONString(socketDataMsg));
|
||||
|
||||
PqFreqConverterTestRes featureTestRes = new PqFreqConverterTestRes();
|
||||
featureTestRes.setId(IdUtil.fastSimpleUUID());
|
||||
featureTestRes.setDurationMs(featurePointVO.getDurationMs());
|
||||
featureTestRes.setResidualVoltage(featurePointVO.getResidualVoltage());
|
||||
featureTestRes.setTolerant(2);
|
||||
featureTestRes.setTime(LocalDateTime.now());
|
||||
saveTestResList.add(featureTestRes);
|
||||
}
|
||||
}
|
||||
}
|
||||
this.lastTolerancePoint = newTolerantPointVO;
|
||||
updateTestResList.add(testRes);
|
||||
}
|
||||
});
|
||||
|
||||
if (!saveTestResList.isEmpty()) {
|
||||
pqFreqConverterTestResService.saveTestRes(suffix, saveTestResList);
|
||||
}
|
||||
if (!updateTestResList.isEmpty()) {
|
||||
pqFreqConverterTestResService.updateTestRes(suffix, updateTestResList);
|
||||
}
|
||||
|
||||
for (String dipId : finishedTestResIdList) {
|
||||
FormalTestManager.pendingDipTaskMap.remove(dipId);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否为新的一组测试脚本
|
||||
*
|
||||
* @param lastTolerancePoint 上一个暂降点
|
||||
* @param newTolerantPointVO 最新的暂降点
|
||||
* @return
|
||||
*/
|
||||
private boolean isNewGroup(TolerantPointVO lastTolerancePoint, TolerantPointVO newTolerantPointVO) {
|
||||
// 横向分组
|
||||
if (freqConverterConfig.getDirection() == 0) {
|
||||
return lastTolerancePoint.getDurationMs() - newTolerantPointVO.getDurationMs() >= 10;
|
||||
}
|
||||
// 纵向分租
|
||||
if (freqConverterConfig.getDirection() == 1) {
|
||||
return lastTolerancePoint.getResidualVoltage() - newTolerantPointVO.getResidualVoltage() <= -2;
|
||||
}
|
||||
|
||||
// if (Math.abs(lastTolerancePoint.getDurationMs() - newTolerantPointVO.getDurationMs()) >= 10 && Math.abs(lastTolerancePoint.getResidualVoltage() - newTolerantPointVO.getResidualVoltage()) >= 2) {
|
||||
// return true;
|
||||
// }
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.njcn.gather.detection.handler;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.njcn.gather.detection.pojo.enums.SourceOperateCodeEnum;
|
||||
import com.njcn.gather.detection.pojo.enums.SourceResponseCodeEnum;
|
||||
import com.njcn.gather.detection.pojo.param.DevPhaseSequenceParam;
|
||||
@@ -14,7 +15,12 @@ import com.njcn.gather.detection.util.socket.*;
|
||||
import com.njcn.gather.detection.util.socket.websocket.WebServiceManager;
|
||||
import com.njcn.gather.device.pojo.vo.PreDetection;
|
||||
import com.njcn.gather.device.service.IPqDevService;
|
||||
import com.njcn.gather.plan.pojo.po.AdPlanSource;
|
||||
import com.njcn.gather.plan.service.IAdPlanSourceService;
|
||||
import com.njcn.gather.result.pojo.enums.ResultUnitEnum;
|
||||
import com.njcn.gather.script.pojo.po.SourceIssue;
|
||||
import com.njcn.gather.source.pojo.po.SourceInitialize;
|
||||
import com.njcn.gather.source.service.IPqSourceService;
|
||||
import com.njcn.gather.system.pojo.enums.DicDataEnum;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -56,6 +62,8 @@ public class SocketSourceResponseService {
|
||||
* 设备信息服务,提供设备基础信息查询功能
|
||||
*/
|
||||
private final IPqDevService iPqDevService;
|
||||
private final IAdPlanSourceService adPlanSourceService;
|
||||
private final IPqSourceService pqSourceService;
|
||||
|
||||
/**
|
||||
* Socket连接管理器,负责管理设备和源的Socket连接
|
||||
@@ -334,9 +342,9 @@ public class SocketSourceResponseService {
|
||||
// 系数校验固定检测项:实时电压有效值和实时电流有效值
|
||||
phaseSequenceParam.setDataType(Arrays.asList("real$VRMS", "real$IRMS"));
|
||||
// 读取3次数据用于系数计算
|
||||
phaseSequenceParam.setReadCount(3);
|
||||
phaseSequenceParam.setReadCount(7); //3
|
||||
// 忽略前4次数据,等待测量稳定
|
||||
phaseSequenceParam.setIgnoreCount(4);
|
||||
phaseSequenceParam.setIgnoreCount(3); //4
|
||||
socketMsg.setData(JSON.toJSONString(phaseSequenceParam));
|
||||
SocketManager.sendMsg(s, JSON.toJSONString(socketMsg));
|
||||
|
||||
@@ -363,18 +371,32 @@ public class SocketSourceResponseService {
|
||||
SocketMsg<String> socketMsg = new SocketMsg<>();
|
||||
switch (dictDataEnumByCode) {
|
||||
case SUCCESS:
|
||||
//todo 前端推送收到的消息暂未处理好
|
||||
sendWebSocketMessage(param.getUserPageId(), socketDataMsg);
|
||||
//开始设备通讯检测(发送设备初始化)
|
||||
Map<String, List<PreDetection>> map = new HashMap<>(1);
|
||||
map.put("deviceList", FormalTestManager.devList);
|
||||
String jsonString = JSON.toJSONString(map);
|
||||
socketMsg.setRequestId(SourceOperateCodeEnum.YJC_SBTXJY.getValue());
|
||||
socketMsg.setOperateCode(SourceOperateCodeEnum.DEV_INIT_GATHER_01.getValue());
|
||||
socketMsg.setData(jsonString);
|
||||
String json = JSON.toJSONString(socketMsg);
|
||||
// 使用智能发送工具类,自动管理设备连接
|
||||
socketManager.smartSendToDevice(param, json);
|
||||
if (FormalTestManager.unknownError) {
|
||||
FormalTestManager.unknownError = false;
|
||||
|
||||
//重新下发脚本
|
||||
String type = FormalTestManager.currentIssue.getType();
|
||||
if (ResultUnitEnum.P.getCode().equals(type)) {
|
||||
FormalTestManager.currentIssue.setType(ResultUnitEnum.V_ABSOLUTELY.getCode());
|
||||
}
|
||||
socketMsg.setOperateCode(SourceOperateCodeEnum.OPER_GATHER.getValue());
|
||||
socketMsg.setData(JSON.toJSONString(FormalTestManager.currentIssue));
|
||||
socketMsg.setRequestId(SourceOperateCodeEnum.FORMAL_REAL.getValue() + CnSocketUtil.STEP_TAG + type);
|
||||
SocketManager.sendMsg(param.getUserPageId() + CnSocketUtil.SOURCE_TAG, JSON.toJSONString(socketMsg));
|
||||
} else {
|
||||
//todo 前端推送收到的消息暂未处理好
|
||||
sendWebSocketMessage(param.getUserPageId(), socketDataMsg);
|
||||
//开始设备通讯检测(发送设备初始化)
|
||||
Map<String, List<PreDetection>> map = new HashMap<>(1);
|
||||
map.put("deviceList", FormalTestManager.devList);
|
||||
String jsonString = JSON.toJSONString(map);
|
||||
socketMsg.setRequestId(SourceOperateCodeEnum.YJC_SBTXJY.getValue());
|
||||
socketMsg.setOperateCode(SourceOperateCodeEnum.DEV_INIT_GATHER_01.getValue());
|
||||
socketMsg.setData(jsonString);
|
||||
String json = JSON.toJSONString(socketMsg);
|
||||
// 使用智能发送工具类,自动管理设备连接
|
||||
socketManager.smartSendToDevice(param, json);
|
||||
}
|
||||
break;
|
||||
case UNPROCESSED_BUSINESS:
|
||||
sendWebSocketMessage(param.getUserPageId(), socketDataMsg);
|
||||
@@ -570,6 +592,10 @@ public class SocketSourceResponseService {
|
||||
case UNPROCESSED_BUSINESS:
|
||||
sendWebSocketMessage(param.getUserPageId(), socketDataMsg);
|
||||
break;
|
||||
case UNKNOWN_ERROR: //-1源未知异常
|
||||
CnSocketUtil.quitSendSource(param);
|
||||
FormalTestManager.unknownError = true;
|
||||
break;
|
||||
default:
|
||||
sendErrorAndQuit(param, socketDataMsg, dictDataEnumByCode);
|
||||
break;
|
||||
@@ -601,9 +627,23 @@ public class SocketSourceResponseService {
|
||||
SourceResponseCodeEnum dictDataEnumByCode = SourceResponseCodeEnum.getDictDataEnumByCode(socketDataMsg.getCode());
|
||||
switch (Objects.requireNonNull(dictDataEnumByCode)) {
|
||||
case SUCCESS:
|
||||
//通讯校验成功
|
||||
SocketManager.removeUser(param.getUserPageId() + CnSocketUtil.SOURCE_TAG);
|
||||
sendWebSocketMessage(param.getUserPageId(), socketDataMsg);
|
||||
if (FormalTestManager.unknownError) {
|
||||
//获取源初始化参数
|
||||
AdPlanSource planSource = adPlanSourceService.getOne(new LambdaQueryWrapper<AdPlanSource>().eq(AdPlanSource::getPlanId, param.getPlanId()));
|
||||
SourceInitialize sourceParam = pqSourceService.getSourceInitializeParam(planSource.getSourceId());
|
||||
if (ObjectUtil.isNotNull(sourceParam)) {
|
||||
SocketMsg<String> socketMsg1 = new SocketMsg<>();
|
||||
socketMsg1.setRequestId(SourceOperateCodeEnum.YJC_YTXJY.getValue());
|
||||
socketMsg1.setOperateCode(SourceOperateCodeEnum.INIT_GATHER.getValue());
|
||||
socketMsg1.setData(JSON.toJSONString(sourceParam));
|
||||
//使用智能发送工具类,自动管理与源控程序的socket连接
|
||||
socketManager.smartSendToSource(param, JSON.toJSONString(socketMsg1));
|
||||
}
|
||||
} else {
|
||||
//通讯校验成功
|
||||
SocketManager.removeUser(param.getUserPageId() + CnSocketUtil.SOURCE_TAG);
|
||||
sendWebSocketMessage(param.getUserPageId(), socketDataMsg);
|
||||
}
|
||||
break;
|
||||
case UNPROCESSED_BUSINESS:
|
||||
break;
|
||||
@@ -653,6 +693,8 @@ public class SocketSourceResponseService {
|
||||
|
||||
// 同步更新系数管理器中的设备列表
|
||||
XiNumberManager.xiDevList = devList;
|
||||
FormalTestManager.unknownError = false;
|
||||
FormalTestManager.currentIssue = null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
package com.njcn.gather.detection.pojo.dto;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonAlias;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @data 2026-04-08
|
||||
*/
|
||||
@Data
|
||||
public class FreqConverterRespDTO {
|
||||
/**
|
||||
* 请求编号
|
||||
*/
|
||||
@JsonAlias({"RequestId"})
|
||||
private String requestId;
|
||||
|
||||
/**
|
||||
* 是否成功
|
||||
*/
|
||||
@JsonAlias({"Success"})
|
||||
private Boolean success;
|
||||
|
||||
/**
|
||||
* 状态码
|
||||
*/
|
||||
@JsonAlias({"Code"})
|
||||
private Integer code;
|
||||
|
||||
/**
|
||||
* 消息
|
||||
*/
|
||||
@JsonAlias({"Message"})
|
||||
private String message;
|
||||
|
||||
/**
|
||||
* 数据
|
||||
*/
|
||||
@JsonAlias({"Data"})
|
||||
private Object data;
|
||||
}
|
||||
@@ -19,7 +19,8 @@ public enum DetectionResponseEnum {
|
||||
|
||||
|
||||
SCRIPT_CHECK_DATA_NOT_EXIST("A020040","测试脚本项暂无配置" ),
|
||||
EXCEED_MAX_TIME("A020041","检测次数超出最大限制!" );
|
||||
EXCEED_MAX_TIME("A020041","检测次数超出最大限制!" ),
|
||||
SOCKET_CONNECT_TIMEOUT("A020042","socket连接超时!");
|
||||
|
||||
private final String code;
|
||||
private final String message;
|
||||
|
||||
@@ -52,7 +52,7 @@ public enum SourceOperateCodeEnum {
|
||||
YJC_MXYZXJY("yjc_mxyzxjy", "模型一致性校验"),
|
||||
FORMAL_REAL("formal_real","正式检测"),
|
||||
RECORD_WAVE_STEP1("record_wave_step1","启动录波_step1"),
|
||||
// RECORD_WAVE_STEP2("record_wave_step2","启动录波_step2"),
|
||||
// RECORD_WAVE_STEP2("record_wave_step2","启动录波_step2"),
|
||||
// SIMULATE_REAL("simulate_real","模拟检测"),
|
||||
Coefficient_Check("Coefficient_Check","系数校验"),
|
||||
QUITE("quit","关闭设备通讯初始化"),
|
||||
@@ -67,8 +67,7 @@ public enum SourceOperateCodeEnum {
|
||||
SERVER_ERROR("server_error","服务端主动关闭连接,请稍后再试"),
|
||||
DEVICE_ERROR("device_error","设备主动关闭连接,请稍后再试"),
|
||||
|
||||
|
||||
|
||||
FLICKER_DATA_CHECK("flicker_data_check","闪变数据校验"),
|
||||
|
||||
|
||||
/**
|
||||
@@ -98,12 +97,17 @@ public enum SourceOperateCodeEnum {
|
||||
small_comp_start("small_comp_start","小电压校准开始"),
|
||||
small_comp_end("small_comp_end","小电压校准结束"),
|
||||
|
||||
|
||||
/**
|
||||
* ftp文件传送指令
|
||||
*/
|
||||
FTP_SEND_01("FTP_SEND$01", "发送文件"),
|
||||
RDRE$01("RDRE$01", "启动录波");
|
||||
RDRE$01("RDRE$01", "启动录波"),
|
||||
|
||||
CMD_PING("ping", "检查 TCP 服务是否在线"),
|
||||
CMD_INIT_SERIAL("initSerial", "初始化并打开串口连接"),
|
||||
CMD_GET_SERIAL_CONFIG("getSerialConfig", "获取当前串口配置"),
|
||||
CMD_GET_DEVICE_STATUS("getDeviceStatus", "读取变频器运行状态"),
|
||||
CMD_CLOSE_SERIAL("closeSerial", "关闭串口"),;
|
||||
|
||||
private final String value;
|
||||
private final String msg;
|
||||
|
||||
@@ -42,8 +42,9 @@ public enum SourceResponseCodeEnum {
|
||||
FAIL(25002,"失败"),
|
||||
ALL_FAIL(25003,"校验失败"),
|
||||
RECEIVE_DATA_TIME_OUT(25004,"接收数据超时"),
|
||||
REAL_DATA_CHECK_FAIL(25005,"实时数据校验失败"),
|
||||
STATISTICS_DATA_CHECK_FAIL(25006,"统计数据校验失败")
|
||||
REAL_DATA_CHECK_FAIL(25005,"实时数据不符合"),
|
||||
STATISTICS_DATA_CHECK_FAIL(25006,"统计数据不符合"),
|
||||
FLICKER_DATA_START(25007,"开始接收闪变数据")
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -43,4 +43,9 @@ public class ContrastDetectionParam {
|
||||
private List<Boolean> testItemList;
|
||||
|
||||
private String userId;
|
||||
|
||||
/**
|
||||
* 是否进行相许校验
|
||||
*/
|
||||
private Integer phaseCheck;
|
||||
}
|
||||
|
||||
@@ -53,4 +53,9 @@ public class DetectionData {
|
||||
* 误差体系详情ID(比对式使用)
|
||||
*/
|
||||
private String errorDtlId;
|
||||
|
||||
/**
|
||||
* 有效组数
|
||||
*/
|
||||
private Integer validGroupNum;
|
||||
}
|
||||
|
||||
@@ -4,8 +4,6 @@ import com.njcn.gather.detection.pojo.param.ContrastDetectionParam;
|
||||
import com.njcn.gather.detection.pojo.param.PreDetectionParam;
|
||||
import com.njcn.gather.detection.pojo.param.SimulateDetectionParam;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
/**
|
||||
* @author wr
|
||||
@@ -54,7 +52,6 @@ public interface PreDetectionService {
|
||||
void closeTestSimulate(SimulateDetectionParam param);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param param
|
||||
*/
|
||||
void startContrastTest(ContrastDetectionParam param);
|
||||
@@ -63,4 +60,12 @@ public interface PreDetectionService {
|
||||
* 导出实时数据对齐过程中的数据
|
||||
*/
|
||||
void exportAlignData();
|
||||
|
||||
boolean getCanCoefficient();
|
||||
|
||||
void startCoefficient();
|
||||
|
||||
void startFreqConverter(String userId, String converterId, String monitorId,Boolean reset);
|
||||
|
||||
void stopFreqConverter(String converterId, String monitorId);
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -6,9 +6,7 @@ import cn.hutool.core.util.ObjectUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.njcn.common.pojo.exception.BusinessException;
|
||||
import com.njcn.gather.detection.handler.SocketContrastResponseService;
|
||||
import com.njcn.gather.detection.handler.SocketDevResponseService;
|
||||
import com.njcn.gather.detection.handler.SocketSourceResponseService;
|
||||
import com.njcn.gather.detection.handler.*;
|
||||
import com.njcn.gather.detection.pojo.constant.DetectionCommunicateConstant;
|
||||
import com.njcn.gather.detection.pojo.enums.DetectionResponseEnum;
|
||||
import com.njcn.gather.detection.pojo.enums.SourceOperateCodeEnum;
|
||||
@@ -21,6 +19,8 @@ import com.njcn.gather.detection.util.business.DetectionCommunicateUtil;
|
||||
import com.njcn.gather.detection.util.socket.CnSocketUtil;
|
||||
import com.njcn.gather.detection.util.socket.FormalTestManager;
|
||||
import com.njcn.gather.detection.util.socket.SocketManager;
|
||||
import com.njcn.gather.detection.util.socket.XiNumberManager;
|
||||
import com.njcn.gather.detection.util.socket.cilent.NettyContrastClientHandler;
|
||||
import com.njcn.gather.detection.util.socket.websocket.WebServiceManager;
|
||||
import com.njcn.gather.device.pojo.po.PqDev;
|
||||
import com.njcn.gather.device.pojo.vo.PreDetection;
|
||||
@@ -38,6 +38,7 @@ import com.njcn.gather.script.service.IPqScriptCheckDataService;
|
||||
import com.njcn.gather.script.service.IPqScriptDtlsService;
|
||||
import com.njcn.gather.source.pojo.po.SourceInitialize;
|
||||
import com.njcn.gather.source.service.IPqSourceService;
|
||||
import com.njcn.gather.system.cfg.service.ISysTestConfigService;
|
||||
import com.njcn.gather.system.dictionary.pojo.enums.DictDataEnum;
|
||||
import com.njcn.gather.system.dictionary.service.IDictDataService;
|
||||
import com.njcn.web.utils.HttpServletUtil;
|
||||
@@ -73,10 +74,14 @@ public class PreDetectionServiceImpl implements PreDetectionService {
|
||||
private final SocketDevResponseService socketDevResponseService;
|
||||
private final SocketSourceResponseService socketSourceResponseService;
|
||||
private final SocketContrastResponseService socketContrastResponseService;
|
||||
private final SocketFreqConverterService socketFreqConverterService;
|
||||
private final SocketFreqConverterDevService socketFreqConverterDevService;
|
||||
private final IPqScriptCheckDataService iPqScriptCheckDataService;
|
||||
private final SocketManager socketManager;
|
||||
private final ISysTestConfigService sysTestConfigService;
|
||||
|
||||
@Value("${log.homeDir}")
|
||||
|
||||
@Value("${report.reportDir}")
|
||||
private String alignDataFilePath;
|
||||
|
||||
|
||||
@@ -337,7 +342,7 @@ public class PreDetectionServiceImpl implements PreDetectionService {
|
||||
|
||||
@Override
|
||||
public void exportAlignData() {
|
||||
String fileName = "实时数据.xlsx";
|
||||
String fileName = "对齐数据.xlsx";
|
||||
HttpServletResponse response = HttpServletUtil.getResponse();
|
||||
response.reset();
|
||||
response.setHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\"");
|
||||
@@ -358,6 +363,68 @@ public class PreDetectionServiceImpl implements PreDetectionService {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getCanCoefficient() {
|
||||
return CollUtil.isNotEmpty(DetectionServiceImpl.vAndIResultMap);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startCoefficient() {
|
||||
if (CollUtil.isNotEmpty(DetectionServiceImpl.vAndIResultMap)) {
|
||||
// 是否进行系数校准
|
||||
//万一录波了这里就进不来了,但是在误差处理的时候DetectionServiceImpl.vAndIResultMap该集合会保留不符合的结果
|
||||
|
||||
XiNumberManager.xiDevList.clear();
|
||||
XiNumberManager.devXiNumDataMap.clear();
|
||||
List<String> stdIpList = DetectionServiceImpl.vAndIResultMap.values().stream().map(DetectionServiceImpl.VAndIResult::getIp).collect(Collectors.toList());
|
||||
XiNumberManager.xiDevList = FormalTestManager.standardDevList.stream().filter(d -> stdIpList.contains(d.getDevIP())).collect(Collectors.toList());
|
||||
// 逐一设备向通讯模块要原始系数
|
||||
SocketMsg<String> socketMsg = new SocketMsg<>();
|
||||
socketMsg.setRequestId(SourceOperateCodeEnum.Coefficient_Check.getValue());
|
||||
socketMsg.setOperateCode(SourceOperateCodeEnum.DATA_CHNFACTOR$01.getValue());
|
||||
PreDetection preDetection = XiNumberManager.xiDevList.get(0);
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("devIP", preDetection.getDevIP());
|
||||
map.put("chnNum", preDetection.getDevChns());
|
||||
socketMsg.setData(JSON.toJSONString(map));
|
||||
SocketManager.sendMsg(NettyContrastClientHandler.param.getUserPageId() + CnSocketUtil.CONTRAST_DEV_TAG, JSON.toJSONString(socketMsg));
|
||||
|
||||
FormalTestManager.currentStep = SourceOperateCodeEnum.Coefficient_Check;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startFreqConverter(String userId, String converterId, String monitorId, Boolean reset) {
|
||||
String freqConverterTag = userId + CnSocketUtil.FREQ_CONVERTER_TAG;
|
||||
String devTag = userId + CnSocketUtil.DEV_TAG;
|
||||
// socketFreqConverterService.init(userId, converterId, monitorId);
|
||||
socketFreqConverterService.connectSocket(freqConverterTag);
|
||||
socketFreqConverterDevService.connectSocket(devTag);
|
||||
|
||||
long startTime = System.currentTimeMillis();
|
||||
long timeout = 3000; // 3秒超时时间
|
||||
while (true) {
|
||||
if (SocketManager.isChannelActive(freqConverterTag) && SocketManager.isChannelActive(devTag)) {
|
||||
// if (SocketManager.isChannelActive(devTag)) {
|
||||
socketFreqConverterService.connectionFreqConverter(userId, freqConverterTag, converterId, monitorId, reset);
|
||||
socketFreqConverterDevService.connectionDev(userId, devTag, converterId, monitorId,reset);
|
||||
break;
|
||||
}
|
||||
|
||||
// 检查是否超时
|
||||
if (System.currentTimeMillis() - startTime > timeout) {
|
||||
throw new BusinessException(DetectionResponseEnum.SOCKET_CONNECT_TIMEOUT);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stopFreqConverter(String converterTag, String devTag) {
|
||||
socketFreqConverterService.stopTest(converterTag, devTag);
|
||||
socketFreqConverterDevService.stopTest(converterTag, devTag);
|
||||
}
|
||||
|
||||
/**
|
||||
* 比对式-与通信模块进行连接
|
||||
*
|
||||
@@ -416,4 +483,4 @@ public class PreDetectionServiceImpl implements PreDetectionService {
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.njcn.gather.detection.util;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.util.NumberUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.njcn.gather.detection.pojo.po.DevData;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -421,7 +422,7 @@ public class DetectionUtil {
|
||||
}
|
||||
return newList;
|
||||
}
|
||||
return null;
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -437,4 +438,94 @@ public class DetectionUtil {
|
||||
System.out.println(" 文件大小: " + file.length() + " bytes");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取皮尔逊系数
|
||||
*
|
||||
* <p>相关系数绝对值|r|所代表的相关强度</p>
|
||||
* <ul>
|
||||
* <li>0.8 - 1.0:极强相关</li>
|
||||
* <li>0.6 - 0.8:强相关</li>
|
||||
* <li>0.4 - 0.6:中等程度相关</li>
|
||||
* <li>0.2 - 0.4:弱相关</li>
|
||||
* <li>0.0 - 0.2:极弱相关或无相关</li>
|
||||
* </ul>
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static BigDecimal getPearsonCorrelationCoefficient(List<Double> x, List<Double> y) {
|
||||
Double xAvg = x.parallelStream().mapToDouble(Double::doubleValue).average().orElse(0.0);
|
||||
Double yAvg = y.parallelStream().mapToDouble(Double::doubleValue).average().orElse(0.0);
|
||||
|
||||
// 协方差求和
|
||||
BigDecimal covarianceSum = BigDecimal.ZERO;
|
||||
// x的方差
|
||||
BigDecimal varianceX = BigDecimal.ZERO;
|
||||
// y的方差
|
||||
BigDecimal varianceY = BigDecimal.ZERO;
|
||||
for (int i = 0; i < x.size(); i++) {
|
||||
covarianceSum = covarianceSum.add(BigDecimal.valueOf((x.get(i) - xAvg) * (y.get(i) - yAvg)));
|
||||
varianceX = varianceX.add(BigDecimal.valueOf(Math.pow(x.get(i) - xAvg, 2)));
|
||||
varianceY = varianceY.add(BigDecimal.valueOf(Math.pow(y.get(i) - yAvg, 2)));
|
||||
}
|
||||
BigDecimal fm = BigDecimal.valueOf(Math.sqrt(varianceX.doubleValue()) * Math.sqrt(varianceY.doubleValue()));
|
||||
if (NumberUtil.equals(fm.doubleValue(), BigDecimal.ZERO.doubleValue())) {
|
||||
if (NumberUtil.equals(covarianceSum, BigDecimal.ZERO)) {
|
||||
return BigDecimal.valueOf(1.0);
|
||||
} else {
|
||||
return BigDecimal.ZERO;
|
||||
}
|
||||
} else {
|
||||
return BigDecimal.valueOf(Math.abs(covarianceSum.divide(fm, 8, BigDecimal.ROUND_HALF_UP).doubleValue())); //相关系数
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 比值一致性,获取CV系数
|
||||
*
|
||||
* <p>一致性等级</p>
|
||||
* <ul>
|
||||
* <li>CV<1%:非常优秀</li>
|
||||
* <li>1%≤CV<5%:优良</li>
|
||||
* <li>5%≤CV<10%:良好</li>
|
||||
* <li>10%≤CV<20%:中等</li>
|
||||
* <li>20%≤CV:较差</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param x
|
||||
* @param y
|
||||
* @return
|
||||
*/
|
||||
public static BigDecimal getCvCoefficient(List<Double> x, List<Double> y) {
|
||||
List<BigDecimal> ratioList = new ArrayList<>();
|
||||
for (int i = 0; i < x.size(); i++) {
|
||||
ratioList.add(BigDecimal.valueOf(x.get(i) / y.get(i)));
|
||||
}
|
||||
|
||||
BigDecimal avg = BigDecimal.valueOf(ratioList.parallelStream().mapToDouble(BigDecimal::doubleValue).average().orElse(0.0));
|
||||
BigDecimal variance = BigDecimal.valueOf(
|
||||
ratioList.parallelStream().mapToDouble(BigDecimal::doubleValue)
|
||||
.map(v -> Math.pow(v - avg.doubleValue(), 2)).average().orElse(0.0));
|
||||
|
||||
return BigDecimal.valueOf(Math.sqrt(variance.doubleValue()) / avg.doubleValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算新的系数
|
||||
*
|
||||
* @param devList
|
||||
* @param stdDevList
|
||||
* @return
|
||||
*/
|
||||
public static Double getNewXi(List<Double> devList, List<Double> stdDevList) {
|
||||
ArrayList<Double> xiList = new ArrayList<>();
|
||||
for (int i = 0; i < stdDevList.size(); i++) {
|
||||
if (!stdDevList.get(i).equals(0)) {
|
||||
BigDecimal bigDecimalDev = BigDecimal.valueOf(devList.get(i));
|
||||
BigDecimal bigDecimalStdDev = BigDecimal.valueOf(stdDevList.get(i));
|
||||
xiList.add((bigDecimalDev.subtract(bigDecimalStdDev)).divide(BigDecimal.valueOf(2.0).multiply(bigDecimalDev), 8, BigDecimal.ROUND_HALF_UP).doubleValue() + 1.0);
|
||||
}
|
||||
}
|
||||
return xiList.stream().mapToDouble(Double::doubleValue).average().orElse(1.0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,6 +14,8 @@ import com.njcn.gather.detection.util.socket.websocket.WebServiceManager;
|
||||
*/
|
||||
public class CnSocketUtil {
|
||||
|
||||
public final static String FREQ_CONVERTER_TAG="_FreqConverter";
|
||||
|
||||
public final static String DEV_TAG = "_Dev";
|
||||
|
||||
public final static String CONTRAST_DEV_TAG = "_Contrast_Dev";
|
||||
|
||||
@@ -7,11 +7,15 @@ import com.njcn.gather.detection.pojo.po.DevData;
|
||||
import com.njcn.gather.detection.pojo.vo.DevLineTestResult;
|
||||
import com.njcn.gather.device.pojo.enums.PatternEnum;
|
||||
import com.njcn.gather.device.pojo.vo.PreDetection;
|
||||
import com.njcn.gather.dip.pojo.po.PqDipData;
|
||||
import com.njcn.gather.plan.pojo.enums.DataSourceEnum;
|
||||
import com.njcn.gather.plan.pojo.po.AdPlan;
|
||||
import com.njcn.gather.plan.pojo.po.AdPlanTestConfig;
|
||||
import com.njcn.gather.script.pojo.po.SourceIssue;
|
||||
import com.njcn.gather.system.dictionary.pojo.enums.DictDataEnum;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@@ -30,6 +34,20 @@ public class FormalTestManager {
|
||||
// 当前步骤
|
||||
public static SourceOperateCodeEnum currentStep;
|
||||
|
||||
public static SourceOperateCodeEnum freqConverterStep;
|
||||
public static SourceOperateCodeEnum freqConverterDevStep;
|
||||
/**
|
||||
* 变频器存放数据的表后缀
|
||||
*/
|
||||
public static Integer freqConverterTableSuffix;
|
||||
|
||||
public static String currentFreqConverterId;
|
||||
|
||||
/**
|
||||
* 待采集后续变频器状态的Dip任务
|
||||
*/
|
||||
public static Map<String, PendingDipTask> pendingDipTaskMap = new ConcurrentHashMap<>();
|
||||
|
||||
/**
|
||||
* key:设备ip,value:当前设备下面的监测点ID(ip_通道号)
|
||||
*/
|
||||
@@ -180,4 +198,54 @@ public class FormalTestManager {
|
||||
|
||||
|
||||
public static boolean isWaveCheck;
|
||||
|
||||
public static List<String> pstDataType;
|
||||
|
||||
public static boolean isPstData;
|
||||
|
||||
/**
|
||||
* 是否在检测中
|
||||
*/
|
||||
public static boolean isTesting;
|
||||
|
||||
public static boolean realProtocol;
|
||||
|
||||
public static boolean statisticsProtocol;
|
||||
|
||||
public static boolean voltageProtocol;
|
||||
|
||||
public static boolean unknownError;
|
||||
|
||||
/**
|
||||
* 当前下发的脚本
|
||||
*/
|
||||
public static SourceIssue currentIssue;
|
||||
|
||||
/**
|
||||
* 是否进行相序校验
|
||||
*/
|
||||
public static boolean isXu;
|
||||
|
||||
/**
|
||||
* 清理变频器耐受实验运行态数据
|
||||
*/
|
||||
public static void clearFreqConverterRuntimeState() {
|
||||
currentFreqConverterId = null;
|
||||
freqConverterTableSuffix = null;
|
||||
pendingDipTaskMap.clear();
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class PendingDipTask {
|
||||
private PqDipData pqDipData;
|
||||
|
||||
private LocalDateTime targetEndTime;
|
||||
private Integer originalTolerant;
|
||||
|
||||
public PendingDipTask(PqDipData pqDipData, LocalDateTime targetEndTime, Integer originalTolerant) {
|
||||
this.pqDipData = pqDipData;
|
||||
this.targetEndTime = targetEndTime;
|
||||
this.originalTolerant = originalTolerant;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -315,4 +315,4 @@ public class SocketManager {
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -56,6 +56,109 @@ public class NettyClient {
|
||||
*/
|
||||
private static NettyClient instance;
|
||||
|
||||
/**
|
||||
* 静态方法:智能连接变频器设备(兼容性包装)
|
||||
*
|
||||
* @param ip IP地址
|
||||
* @param port 端口号
|
||||
* @param ChannelId Channel唯一标识
|
||||
* @param handler 变频器处理器
|
||||
*/
|
||||
public static void commonConnect(String ip, Integer port, String ChannelId,
|
||||
SimpleChannelInboundHandler handler) {
|
||||
if (instance != null) {
|
||||
instance.executeCommonConnect(ip, port, ChannelId, handler);
|
||||
} else {
|
||||
log.error("NettyClient未初始化,无法创建连接");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行变频器Socket连接建立流程
|
||||
*
|
||||
* @param ip 目标服务器IP地址
|
||||
* @param port 目标服务器端口号
|
||||
* @param ChannelId Channel唯一标识id
|
||||
* @param handler 变频器业务处理器
|
||||
*/
|
||||
private static void executeCommonConnect(String ip, Integer port,
|
||||
String ChannelId,
|
||||
SimpleChannelInboundHandler handler) {
|
||||
NioEventLoopGroup group = createEventLoopGroup();
|
||||
|
||||
try {
|
||||
Bootstrap bootstrap = configureBootstrap(group);
|
||||
ChannelInitializer<NioSocketChannel> initializer = createCommonChannelInitializer(ChannelId, handler);
|
||||
bootstrap.handler(initializer);
|
||||
ChannelFuture channelFuture = bootstrap.connect(ip, port).sync();
|
||||
handleCommonConnectionResult(channelFuture, ChannelId, handler, group);
|
||||
} catch (Exception e) {
|
||||
handleCommonConnectionException(e, ChannelId, handler, group);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建通用通道初始化器
|
||||
*
|
||||
* @param channelId Channel唯一标识id
|
||||
* @param handler 通用业务处理器
|
||||
* @return ChannelInitializer 通道初始化器
|
||||
*/
|
||||
private static ChannelInitializer<NioSocketChannel> createCommonChannelInitializer(
|
||||
String channelId, SimpleChannelInboundHandler handler) {
|
||||
return new ChannelInitializer<NioSocketChannel>() {
|
||||
@Override
|
||||
protected void initChannel(NioSocketChannel ch) {
|
||||
ch.pipeline()
|
||||
.addLast(new LineBasedFrameDecoder(10240 * 2))
|
||||
.addLast(new StringDecoder(CharsetUtil.UTF_8))
|
||||
.addLast(new StringEncoder(CharsetUtil.UTF_8))
|
||||
.addLast(new IdleStateHandler(60, 0, 0, TimeUnit.SECONDS))
|
||||
.addLast(handler);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理通用连接结果
|
||||
*
|
||||
* @param channelFuture 连接Future对象
|
||||
* @param channelId Channel唯一标识符
|
||||
* @param handler 通用业务处理器
|
||||
* @param group 事件循环组
|
||||
*/
|
||||
private static void handleCommonConnectionResult(ChannelFuture channelFuture,
|
||||
String channelId,
|
||||
SimpleChannelInboundHandler handler,
|
||||
NioEventLoopGroup group) {
|
||||
channelFuture.addListener((ChannelFutureListener) ch -> {
|
||||
if (!ch.isSuccess()) {
|
||||
log.error("连接Socket失败,channelId={}", channelId);
|
||||
group.shutdownGracefully();
|
||||
} else {
|
||||
log.info("连接Socket成功,channel={}, channelId={}",
|
||||
channelId, channelFuture.channel().id());
|
||||
SocketManager.addGroup(channelId, group);
|
||||
SocketManager.addUser(channelId, channelFuture.channel());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理通用连接异常
|
||||
*
|
||||
* @param e 异常对象
|
||||
* @param channelId Channel唯一标识id
|
||||
* @param handler 通用业务处理器
|
||||
* @param group 事件循环组
|
||||
*/
|
||||
private static void handleCommonConnectionException(Exception e, String channelId,
|
||||
SimpleChannelInboundHandler handler,
|
||||
NioEventLoopGroup group) {
|
||||
log.error("连接Socket服务端发生异常,channelId={}, error={}", channelId, e.getMessage(), e);
|
||||
group.shutdownGracefully();
|
||||
}
|
||||
|
||||
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
|
||||
@@ -88,20 +88,33 @@ public class NettyContrastClientHandler extends SimpleChannelInboundHandler<Stri
|
||||
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) {
|
||||
if (evt instanceof IdleStateEvent) { //IdleState.在一段时间内没有收到任何消息时,会触发该事件
|
||||
if (((IdleStateEvent) evt).state() == IdleState.READER_IDLE) {
|
||||
System.out.println(LocalDateTime.now() + "contrastClientHandler触发读超时函数**************************************");
|
||||
if (FormalTestManager.isTesting) {
|
||||
System.out.println(LocalDateTime.now() + "contrastClientHandler触发读超时函数**************************************");
|
||||
|
||||
if (!FormalTestManager.isRemoveSocket && ObjectUtil.isNotNull(FormalTestManager.nonWaveDataSourceEnum)) {
|
||||
long time = SocketManager.contrastClockMap.get(FormalTestManager.nonWaveDataSourceEnum) + 60L;
|
||||
SocketManager.contrastClockMap.put(FormalTestManager.nonWaveDataSourceEnum, time);
|
||||
if (!FormalTestManager.isRemoveSocket && ObjectUtil.isNotNull(FormalTestManager.nonWaveDataSourceEnum)) {
|
||||
long time = SocketManager.contrastClockMap.get(FormalTestManager.nonWaveDataSourceEnum) + 60L;
|
||||
SocketManager.contrastClockMap.put(FormalTestManager.nonWaveDataSourceEnum, time);
|
||||
|
||||
if (DataSourceEnum.REAL_DATA == FormalTestManager.nonWaveDataSourceEnum) {
|
||||
if (time >= 60) {
|
||||
CnSocketUtil.contrastSendquit(param.getUserPageId(), SourceOperateCodeEnum.QUIT_INIT_02, true);
|
||||
timeoutSend(SourceOperateCodeEnum.QUIT_INIT_02);
|
||||
if (FormalTestManager.isPstData) {
|
||||
if (time > 60 * 10) {
|
||||
if (DataSourceEnum.REAL_DATA == FormalTestManager.nonWaveDataSourceEnum) {
|
||||
CnSocketUtil.contrastSendquit(param.getUserPageId(), SourceOperateCodeEnum.QUIT_INIT_02, true);
|
||||
}
|
||||
if (FormalTestManager.isWaveCheck) {
|
||||
CnSocketUtil.contrastSendquit(param.getUserPageId(), SourceOperateCodeEnum.QUIT_INIT_03, true);
|
||||
}
|
||||
CnSocketUtil.contrastSendquit(param.getUserPageId(), SourceOperateCodeEnum.QUIT_INIT_01, true);
|
||||
timeoutSend(SourceOperateCodeEnum.QUIT_INIT_01);
|
||||
}
|
||||
} else if (DataSourceEnum.REAL_DATA == FormalTestManager.nonWaveDataSourceEnum) {
|
||||
if (time >= 60) {
|
||||
CnSocketUtil.contrastSendquit(param.getUserPageId(), SourceOperateCodeEnum.QUIT_INIT_02, true);
|
||||
timeoutSend(SourceOperateCodeEnum.QUIT_INIT_02);
|
||||
}
|
||||
} else if (time >= FormalTestManager.maxTime) {
|
||||
CnSocketUtil.contrastSendquit(param.getUserPageId(), SourceOperateCodeEnum.QUIT_INIT_01, true);
|
||||
timeoutSend(SourceOperateCodeEnum.QUIT_INIT_01);
|
||||
}
|
||||
} else if (time >= FormalTestManager.maxTime) {
|
||||
CnSocketUtil.contrastSendquit(param.getUserPageId(), SourceOperateCodeEnum.QUIT_INIT_02, true);
|
||||
timeoutSend(SourceOperateCodeEnum.QUIT_INIT_01);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -336,7 +336,7 @@ public class NettyDevClientHandler extends SimpleChannelInboundHandler<String> {
|
||||
devLineTestResult.setDeviceName(dev.getDevName());
|
||||
|
||||
Integer[] resultFlags = dev.getMonitorList().stream()
|
||||
.map(monitor -> ResultEnum.NETWORK_TIMEOUT)
|
||||
.map(monitor -> ResultEnum.NETWORK_TIMEOUT.getValue())
|
||||
.toArray(Integer[]::new);
|
||||
devLineTestResult.setChnResult(resultFlags);
|
||||
|
||||
|
||||
@@ -0,0 +1,147 @@
|
||||
package com.njcn.gather.detection.util.socket.cilent;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.njcn.gather.detection.handler.SocketFreqConverterService;
|
||||
import com.njcn.gather.detection.util.socket.FormalTestManager;
|
||||
import com.njcn.gather.detection.util.socket.SocketManager;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.SimpleChannelInboundHandler;
|
||||
import io.netty.handler.timeout.IdleState;
|
||||
import io.netty.handler.timeout.IdleStateEvent;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* 变频器Netty客户端处理器
|
||||
*/
|
||||
@Slf4j
|
||||
public class NettyFreqConverterClientHandler extends SimpleChannelInboundHandler<String> {
|
||||
|
||||
/**
|
||||
* 变频器Channel唯一标识符
|
||||
*/
|
||||
private final String converterChannelTag;
|
||||
|
||||
|
||||
/**
|
||||
* 变频器Socket响应服务
|
||||
*/
|
||||
private final SocketFreqConverterService socketFreqConverterService;
|
||||
|
||||
/**
|
||||
* 重连次数
|
||||
*/
|
||||
private int reconnectAttempts = 0;
|
||||
|
||||
/**
|
||||
* 最大重连次数
|
||||
*/
|
||||
private static final int MAX_RECONNECT_ATTEMPTS = 3;
|
||||
|
||||
/**
|
||||
* 重连间隔(毫秒)
|
||||
*/
|
||||
private static final long RECONNECT_INTERVAL_MS = 5000;
|
||||
|
||||
/**
|
||||
* 是否正在重连
|
||||
*/
|
||||
private volatile boolean isReconnecting = false;
|
||||
|
||||
/**
|
||||
* 构造方法
|
||||
*
|
||||
* @param converterChannelTag 变频器Chanel唯一标识符
|
||||
* @param socketFreqConverterService 变频器Socket响应服务
|
||||
*/
|
||||
public NettyFreqConverterClientHandler(String converterChannelTag, SocketFreqConverterService socketFreqConverterService) {
|
||||
this.converterChannelTag = converterChannelTag;
|
||||
this.socketFreqConverterService = socketFreqConverterService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void channelActive(ChannelHandlerContext ctx) throws Exception {
|
||||
log.info("变频器连接已建立,converterChannelTag={}, channelId={}", converterChannelTag, ctx.channel().id());
|
||||
|
||||
// 注册Channel到SocketManager
|
||||
SocketManager.addUser(converterChannelTag, ctx.channel());
|
||||
|
||||
if (reconnectAttempts > 0) {
|
||||
log.info("变频器重连成功,converterChannelTag={}, 重连次数={}", converterChannelTag, reconnectAttempts);
|
||||
reconnectAttempts = 0;
|
||||
isReconnecting = false;
|
||||
socketFreqConverterService.onReconnectSuccess(converterChannelTag);
|
||||
}
|
||||
|
||||
super.channelActive(ctx);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void channelRead0(ChannelHandlerContext ctx, String msg) throws Exception {
|
||||
if (StrUtil.isBlank(msg)) {
|
||||
log.debug("收到空消息,忽略,converterChannelTag={}", converterChannelTag);
|
||||
return;
|
||||
}
|
||||
|
||||
log.info("收到变频器消息,converterChannelTag={}, msg={}", converterChannelTag, msg);
|
||||
|
||||
// 处理状态数据
|
||||
socketFreqConverterService.handleRead(converterChannelTag, msg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
|
||||
log.warn("变频器连接已断开,converterChannelTag={}", converterChannelTag);
|
||||
|
||||
socketFreqConverterService.cleanup(converterChannelTag);
|
||||
|
||||
if (!isReconnecting && reconnectAttempts < MAX_RECONNECT_ATTEMPTS && !FormalTestManager.isRemoveSocket) {
|
||||
attemptReconnect(ctx);
|
||||
} else if (reconnectAttempts >= MAX_RECONNECT_ATTEMPTS) {
|
||||
log.error("变频器重连失败,已达到最大重连次数{}次,converterChannelTag={}", MAX_RECONNECT_ATTEMPTS, converterChannelTag);
|
||||
}
|
||||
|
||||
super.channelInactive(ctx);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
|
||||
log.error("变频器连接发生异常,converterChannelTag={}, error={}", converterChannelTag, cause.getMessage(), cause);
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
|
||||
if (evt instanceof IdleStateEvent) {
|
||||
IdleStateEvent event = (IdleStateEvent) evt;
|
||||
if (event.state() == IdleState.READER_IDLE) {
|
||||
log.warn("变频器连接读空闲,converterChannelTag={}", converterChannelTag);
|
||||
// 可以选择发送心跳或关闭连接
|
||||
}
|
||||
}
|
||||
super.userEventTriggered(ctx, evt);
|
||||
}
|
||||
|
||||
private void attemptReconnect(ChannelHandlerContext ctx) {
|
||||
isReconnecting = true;
|
||||
reconnectAttempts++;
|
||||
|
||||
log.info("准备重连变频器,converterChannelTag={}, 第{}/{}次重连,{}秒后开始",
|
||||
converterChannelTag, reconnectAttempts, MAX_RECONNECT_ATTEMPTS, RECONNECT_INTERVAL_MS / 1000);
|
||||
|
||||
ctx.executor().schedule(() -> {
|
||||
try {
|
||||
log.info("开始执行变频器重连,converterChannelTag={}", converterChannelTag);
|
||||
socketFreqConverterService.reconnect(converterChannelTag);
|
||||
} catch (Exception e) {
|
||||
log.error("变频器重连触发失败,converterChannelTag={}, error={}", converterChannelTag, e.getMessage(), e);
|
||||
isReconnecting = false;
|
||||
|
||||
if (reconnectAttempts < MAX_RECONNECT_ATTEMPTS) {
|
||||
log.warn("将在{}秒后进行下一次重试", RECONNECT_INTERVAL_MS / 1000);
|
||||
ctx.executor().schedule(() -> attemptReconnect(ctx), RECONNECT_INTERVAL_MS, java.util.concurrent.TimeUnit.MILLISECONDS);
|
||||
}
|
||||
}
|
||||
}, RECONNECT_INTERVAL_MS, java.util.concurrent.TimeUnit.MILLISECONDS);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
package com.njcn.gather.detection.util.socket.cilent;
|
||||
|
||||
import com.njcn.gather.detection.handler.SocketFreqConverterDevService;
|
||||
import com.njcn.gather.detection.util.socket.FormalTestManager;
|
||||
import com.njcn.gather.detection.util.socket.SocketManager;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.SimpleChannelInboundHandler;
|
||||
import io.netty.handler.timeout.IdleState;
|
||||
import io.netty.handler.timeout.IdleStateEvent;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* 设备 Netty 客户端处理器
|
||||
*/
|
||||
@Slf4j
|
||||
public class NettyFreqConverterDevClientHandler extends SimpleChannelInboundHandler<String> {
|
||||
|
||||
private final String devChannelTag;
|
||||
private final SocketFreqConverterDevService socketFreqConverterDevService;
|
||||
|
||||
public NettyFreqConverterDevClientHandler(String devChannelTag, SocketFreqConverterDevService socketFreqConverterDevService) {
|
||||
this.devChannelTag = devChannelTag;
|
||||
this.socketFreqConverterDevService = socketFreqConverterDevService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void channelActive(ChannelHandlerContext ctx) throws Exception {
|
||||
log.info("设备连接已建立,devChannelTag={}, channelId={}", devChannelTag, ctx.channel().id());
|
||||
SocketManager.addUser(devChannelTag, ctx.channel());
|
||||
super.channelActive(ctx);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void channelRead0(ChannelHandlerContext ctx, String msg) throws Exception {
|
||||
log.info("收到设备消息,devChannelTag={}, msg={}", devChannelTag, msg);
|
||||
|
||||
socketFreqConverterDevService.handleRead(devChannelTag, msg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
|
||||
log.warn("设备连接已断开,devChannelTag={}", devChannelTag);
|
||||
socketFreqConverterDevService.cleanup(devChannelTag);
|
||||
super.channelInactive(ctx);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
|
||||
log.error("设备连接发生异常,devChannelTag={}, error={}", devChannelTag, cause.getMessage(), cause);
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
|
||||
if (evt instanceof IdleStateEvent) {
|
||||
IdleStateEvent event = (IdleStateEvent) evt;
|
||||
if (event.state() == IdleState.READER_IDLE) {
|
||||
log.warn("设备连接读空闲,devChannelTag={}", devChannelTag);
|
||||
}
|
||||
}
|
||||
super.userEventTriggered(ctx, evt);
|
||||
}
|
||||
}
|
||||
@@ -18,29 +18,21 @@ import java.util.Set;
|
||||
@Component
|
||||
@ConfigurationProperties(prefix = "socket")
|
||||
public class SocketConnectionConfig {
|
||||
/**
|
||||
* 被检设备配置
|
||||
*/
|
||||
private DeviceConfig device = new DeviceConfig();
|
||||
|
||||
/**
|
||||
* 程控源设备配置
|
||||
*/
|
||||
private SourceConfig source = new SourceConfig();
|
||||
|
||||
/**
|
||||
* 被检设备配置
|
||||
*/
|
||||
private DeviceConfig device = new DeviceConfig();
|
||||
|
||||
@Data
|
||||
public static class SourceConfig {
|
||||
/**
|
||||
* 程控源IP地址
|
||||
*/
|
||||
private String ip;
|
||||
|
||||
/**
|
||||
* 程控源端口号
|
||||
*/
|
||||
private Integer port;
|
||||
}
|
||||
/**
|
||||
* 变频器配置
|
||||
*/
|
||||
private DeviceConfig freqConverter = new DeviceConfig();
|
||||
|
||||
@Data
|
||||
public static class DeviceConfig {
|
||||
@@ -48,13 +40,33 @@ public class SocketConnectionConfig {
|
||||
* 被检设备IP地址
|
||||
*/
|
||||
private String ip;
|
||||
|
||||
|
||||
/**
|
||||
* 被检设备端口号
|
||||
*/
|
||||
private Integer port;
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class SourceConfig {
|
||||
/**
|
||||
* 程控源IP地址
|
||||
*/
|
||||
private String ip;
|
||||
|
||||
/**
|
||||
* 程控源端口号
|
||||
*/
|
||||
private Integer port;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取被检设备配置
|
||||
*/
|
||||
public DeviceConfig getDevice() {
|
||||
return device;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取程控源配置
|
||||
*/
|
||||
@@ -63,10 +75,10 @@ public class SocketConnectionConfig {
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取被检设备配置
|
||||
* 获取变频器配置
|
||||
*/
|
||||
public DeviceConfig getDevice() {
|
||||
return device;
|
||||
public DeviceConfig getFreqConverter() {
|
||||
return freqConverter;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -5,9 +5,7 @@ import com.njcn.gather.detection.pojo.enums.SourceOperateCodeEnum;
|
||||
import com.njcn.gather.detection.pojo.param.PreDetectionParam;
|
||||
import com.njcn.gather.detection.util.socket.CnSocketUtil;
|
||||
import com.njcn.gather.detection.util.socket.FormalTestManager;
|
||||
import com.njcn.gather.detection.util.socket.SocketManager;
|
||||
import com.njcn.gather.device.pojo.enums.PatternEnum;
|
||||
import com.njcn.gather.plan.pojo.enums.DataSourceEnum;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.SimpleChannelInboundHandler;
|
||||
import io.netty.handler.codec.CorruptedFrameException;
|
||||
@@ -373,34 +371,43 @@ public class WebSocketHandler extends SimpleChannelInboundHandler<TextWebSocketF
|
||||
// 使用该用户的检测参数关闭Socket连接
|
||||
log.info("使用用户检测参数关闭Socket连接,userId: {}", userId);
|
||||
if (FormalTestManager.patternEnum.equals(PatternEnum.CONTRAST)) {
|
||||
if (FormalTestManager.isRemoveSocket) {
|
||||
boolean channelActive = SocketManager.isChannelActive(preDetectionParam.getUserPageId() + CnSocketUtil.CONTRAST_DEV_TAG);
|
||||
if (channelActive) {
|
||||
SocketManager.removeUser(preDetectionParam.getUserPageId() + CnSocketUtil.CONTRAST_DEV_TAG);
|
||||
}
|
||||
} else {
|
||||
if (FormalTestManager.currentStep == SourceOperateCodeEnum.RECORD_WAVE_STEP1) {
|
||||
CnSocketUtil.contrastSendquit(preDetectionParam.getUserPageId(), SourceOperateCodeEnum.QUIT_INIT_03, true);
|
||||
} else if (FormalTestManager.currentStep != SourceOperateCodeEnum.QUITE) {
|
||||
if (ObjectUtil.isNotNull(FormalTestManager.nonWaveDataSourceEnum)) {
|
||||
if (FormalTestManager.nonWaveDataSourceEnum == DataSourceEnum.REAL_DATA) {
|
||||
CnSocketUtil.contrastSendquit(preDetectionParam.getUserPageId(), SourceOperateCodeEnum.QUIT_INIT_02, false);
|
||||
} else {
|
||||
CnSocketUtil.contrastSendquit(preDetectionParam.getUserPageId(), SourceOperateCodeEnum.QUIT_INIT_01, false);
|
||||
}
|
||||
if (FormalTestManager.isWaveCheck) {
|
||||
CnSocketUtil.contrastSendquit(preDetectionParam.getUserPageId(), SourceOperateCodeEnum.QUIT_INIT_03, true);
|
||||
}
|
||||
} else {
|
||||
if (FormalTestManager.isWaveCheck) {
|
||||
CnSocketUtil.contrastSendquit(preDetectionParam.getUserPageId(), SourceOperateCodeEnum.QUIT_INIT_02, false);
|
||||
CnSocketUtil.contrastSendquit(preDetectionParam.getUserPageId(), SourceOperateCodeEnum.QUIT_INIT_03, true);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
SocketManager.removeUser(preDetectionParam.getUserPageId() + CnSocketUtil.CONTRAST_DEV_TAG);
|
||||
}
|
||||
}
|
||||
CnSocketUtil.contrastSendquit(preDetectionParam.getUserPageId(), SourceOperateCodeEnum.QUIT_INIT_01, false);
|
||||
CnSocketUtil.contrastSendquit(preDetectionParam.getUserPageId(), SourceOperateCodeEnum.QUIT_INIT_02, false);
|
||||
CnSocketUtil.contrastSendquit(preDetectionParam.getUserPageId(), SourceOperateCodeEnum.QUIT_INIT_03, false);
|
||||
// if (FormalTestManager.isRemoveSocket) {
|
||||
// boolean channelActive = SocketManager.isChannelActive(preDetectionParam.getUserPageId() + CnSocketUtil.CONTRAST_DEV_TAG);
|
||||
// if (channelActive) {
|
||||
// SocketManager.removeUser(preDetectionParam.getUserPageId() + CnSocketUtil.CONTRAST_DEV_TAG);
|
||||
// }
|
||||
// } else {
|
||||
// if (FormalTestManager.currentStep == SourceOperateCodeEnum.RECORD_WAVE_STEP1) {
|
||||
// CnSocketUtil.contrastSendquit(preDetectionParam.getUserPageId(), SourceOperateCodeEnum.QUIT_INIT_03, false);
|
||||
// } else if (FormalTestManager.currentStep != SourceOperateCodeEnum.QUITE) {
|
||||
// if (ObjectUtil.isNotNull(FormalTestManager.nonWaveDataSourceEnum)) {
|
||||
// if (FormalTestManager.nonWaveDataSourceEnum == DataSourceEnum.REAL_DATA) {
|
||||
// CnSocketUtil.contrastSendquit(preDetectionParam.getUserPageId(), SourceOperateCodeEnum.QUIT_INIT_02, false);
|
||||
// if (FormalTestManager.statisticsProtocol) {
|
||||
// CnSocketUtil.contrastSendquit(preDetectionParam.getUserPageId(), SourceOperateCodeEnum.QUIT_INIT_01, false);
|
||||
// }
|
||||
// } else {
|
||||
// CnSocketUtil.contrastSendquit(preDetectionParam.getUserPageId(), SourceOperateCodeEnum.QUIT_INIT_01, false);
|
||||
// }
|
||||
// if (FormalTestManager.isWaveCheck) {
|
||||
// CnSocketUtil.contrastSendquit(preDetectionParam.getUserPageId(), SourceOperateCodeEnum.QUIT_INIT_03, false);
|
||||
// }
|
||||
// } else {
|
||||
// if (FormalTestManager.statisticsProtocol) {
|
||||
// CnSocketUtil.contrastSendquit(preDetectionParam.getUserPageId(), SourceOperateCodeEnum.QUIT_INIT_01, false);
|
||||
// }
|
||||
// if (FormalTestManager.isWaveCheck) {
|
||||
// CnSocketUtil.contrastSendquit(preDetectionParam.getUserPageId(), SourceOperateCodeEnum.QUIT_INIT_02, false);
|
||||
// CnSocketUtil.contrastSendquit(preDetectionParam.getUserPageId(), SourceOperateCodeEnum.QUIT_INIT_03, false);
|
||||
// }
|
||||
// }
|
||||
// } else {
|
||||
// SocketManager.removeUser(preDetectionParam.getUserPageId() + CnSocketUtil.CONTRAST_DEV_TAG);
|
||||
// }
|
||||
// }
|
||||
} else {
|
||||
CnSocketUtil.quitSendSource(preDetectionParam);
|
||||
CnSocketUtil.quitSend(preDetectionParam);
|
||||
|
||||
@@ -12,7 +12,6 @@ import com.njcn.common.utils.LogUtil;
|
||||
import com.njcn.gather.device.pojo.param.PqDevParam;
|
||||
import com.njcn.gather.device.pojo.vo.PqDevVO;
|
||||
import com.njcn.gather.device.service.IPqDevService;
|
||||
import com.njcn.gather.monitor.pojo.po.PqMonitor;
|
||||
import com.njcn.gather.type.service.IDevTypeService;
|
||||
import com.njcn.web.controller.BaseController;
|
||||
import com.njcn.web.utils.FileUtil;
|
||||
@@ -101,7 +100,7 @@ public class PqDevController extends BaseController {
|
||||
@OperateInfo(operateType = OperateType.DELETE)
|
||||
@PostMapping("/delete")
|
||||
@ApiOperation("删除被检设备")
|
||||
@ApiImplicitParam(name = "ids", value = "被检设备id", required = true)
|
||||
@ApiImplicitParam(name = "param", value = "删除参数", required = true)
|
||||
public HttpResult<Boolean> delete(@RequestBody @Validated PqDevParam.DeleteParam param) {
|
||||
String methodDescribe = getMethodDescribe("delete");
|
||||
LogUtil.njcnDebug(log, "{},删除ID数据为:{}", methodDescribe, String.join(StrUtil.COMMA, param.getIds()));
|
||||
@@ -137,7 +136,7 @@ public class PqDevController extends BaseController {
|
||||
@ApiImplicitParam(name = "file", value = "被检设备数据文件", required = true),
|
||||
@ApiImplicitParam(name = "patternId", value = "模式id", required = true)
|
||||
})
|
||||
public HttpResult<Boolean> importDev(@RequestParam("file") MultipartFile file, @RequestParam("patternId") String patternId, @RequestParam("planId") String planId, HttpServletResponse response) {
|
||||
public HttpResult importDev(@RequestParam("file") MultipartFile file, @RequestParam("patternId") String patternId, @RequestParam("planId") String planId, @RequestParam(value = "cover", defaultValue = "0") Integer cover, HttpServletResponse response) {
|
||||
String methodDescribe = getMethodDescribe("importDev");
|
||||
LogUtil.njcnDebug(log, "{},上传文件为:{}", methodDescribe, file.getOriginalFilename());
|
||||
boolean fileType = FileUtil.judgeFileIsExcel(file.getOriginalFilename());
|
||||
@@ -147,12 +146,7 @@ public class PqDevController extends BaseController {
|
||||
if ("null".equals(planId)) {
|
||||
planId = null;
|
||||
}
|
||||
Boolean result = pqDevService.importDev(file, patternId, planId, response);
|
||||
if (result) {
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, methodDescribe);
|
||||
} else {
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, false, methodDescribe);
|
||||
}
|
||||
return pqDevService.importDev(file, patternId, planId, response, cover);
|
||||
}
|
||||
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
@@ -168,10 +162,41 @@ public class PqDevController extends BaseController {
|
||||
|
||||
@OperateInfo
|
||||
@GetMapping("/getSelectOptions")
|
||||
@ApiOperation("根据历史记录信息来获取下拉框内容")
|
||||
@ApiOperation("从历史数据中查询下拉框选项")
|
||||
@ApiImplicitParam(name = "pattern", value = "模式id", required = true)
|
||||
public HttpResult<Map<String, List<String>>> getSelectOptions(@RequestParam("pattern") String pattern) {
|
||||
String methodDescribe = getMethodDescribe("getSelectOptions");
|
||||
Map<String, List<String>> result = pqDevService.listSelectOptions(pattern);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
|
||||
}
|
||||
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON, operateType = OperateType.UPLOAD)
|
||||
@PostMapping(value = "/ttt")
|
||||
@ApiOperation("批量导入被检设备")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "file", value = "被检设备数据文件", required = true),
|
||||
@ApiImplicitParam(name = "patternId", value = "模式id", required = true)
|
||||
})
|
||||
public HttpResult ttt(@RequestParam("file") MultipartFile file, @RequestParam("patternId") String patternId, @RequestParam("planId") String planId, @RequestParam(value = "cover", defaultValue = "0") Integer cover, HttpServletResponse response) {
|
||||
String methodDescribe = getMethodDescribe("ttt");
|
||||
LogUtil.njcnDebug(log, "{},上传文件为:{}", methodDescribe, file.getOriginalFilename());
|
||||
boolean fileType = FileUtil.judgeFileIsExcel(file.getOriginalFilename());
|
||||
if (!fileType) {
|
||||
throw new BusinessException(CommonResponseEnum.FILE_XLSX_ERROR);
|
||||
}
|
||||
if ("null".equals(planId)) {
|
||||
planId = null;
|
||||
}
|
||||
return pqDevService.importDev(file, patternId, planId, response, cover);
|
||||
}
|
||||
|
||||
@OperateInfo
|
||||
@GetMapping("/listAll")
|
||||
@ApiOperation("查询所有未删除设备数据")
|
||||
public HttpResult<List<PqDevVO>> listAll() {
|
||||
String methodDescribe = getMethodDescribe("listAll");
|
||||
LogUtil.njcnDebug(log, "{},查询所有设备", methodDescribe);
|
||||
List<PqDevVO> result = pqDevService.listAll();
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ import com.njcn.common.pojo.response.HttpResult;
|
||||
import com.njcn.common.utils.LogUtil;
|
||||
import com.njcn.gather.device.pojo.param.PqStandardDevParam;
|
||||
import com.njcn.gather.device.pojo.po.PqStandardDev;
|
||||
import com.njcn.gather.device.pojo.vo.PqStandardDevVO;
|
||||
import com.njcn.gather.device.service.IPqStandardDevService;
|
||||
import com.njcn.web.controller.BaseController;
|
||||
import com.njcn.web.utils.FileUtil;
|
||||
@@ -55,10 +56,10 @@ public class PqStandardDevController extends BaseController {
|
||||
@GetMapping("/getById")
|
||||
@ApiOperation("根据id查询标准设备")
|
||||
@ApiImplicitParam(name = "id", value = "标准设备id", required = true)
|
||||
public HttpResult<PqStandardDev> getById(@RequestParam("id") String id) {
|
||||
public HttpResult<PqStandardDevVO> getById(@RequestParam("id") String id) {
|
||||
String methodDescribe = getMethodDescribe("getById");
|
||||
LogUtil.njcnDebug(log, "{},查询ID为:{}", methodDescribe, id);
|
||||
PqStandardDev result = pqStandardDevService.getPqStandardDevById(id);
|
||||
PqStandardDevVO result = pqStandardDevService.getPqStandardDevById(id);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
|
||||
}
|
||||
|
||||
@@ -149,17 +150,17 @@ public class PqStandardDevController extends BaseController {
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
|
||||
}
|
||||
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
@PostMapping("/listByPlanId")
|
||||
@ApiOperation("查询出指定计划已关联的标准设备")
|
||||
@ApiImplicitParam(name = "planId", value = "计划id", required = true)
|
||||
public HttpResult<List<PqStandardDev>> listByPlanId(@RequestParam("planId") String planId) {
|
||||
String methodDescribe = getMethodDescribe("listByPlanId");
|
||||
LogUtil.njcnDebug(log, "{},查询数据为:{}", methodDescribe, planId);
|
||||
List<PqStandardDev> pqDevVOList = pqStandardDevService.listByPlanId(planId);
|
||||
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, pqDevVOList, methodDescribe);
|
||||
}
|
||||
// @OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
// @PostMapping("/listByPlanId")
|
||||
// @ApiOperation("查询出指定计划已关联的标准设备")
|
||||
// @ApiImplicitParam(name = "planId", value = "计划id", required = true)
|
||||
// public HttpResult<List<PqStandardDev>> listByPlanId(@RequestParam("planId") String planId) {
|
||||
// String methodDescribe = getMethodDescribe("listByPlanId");
|
||||
// LogUtil.njcnDebug(log, "{},查询数据为:{}", methodDescribe, planId);
|
||||
// List<PqStandardDev> pqDevVOList = pqStandardDevService.listByPlanId(planId);
|
||||
//
|
||||
// return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, pqDevVOList, methodDescribe);
|
||||
// }
|
||||
|
||||
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.njcn.gather.device.mapper;
|
||||
|
||||
import com.github.yulichang.base.MPJBaseMapper;
|
||||
import com.njcn.gather.device.pojo.po.PqStandardDevGain;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @date 2026-01-12
|
||||
*/
|
||||
public interface PqStandardDevGainMapper extends MPJBaseMapper<PqStandardDevGain> {
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.njcn.gather.device.mapper;
|
||||
|
||||
import com.github.yulichang.base.MPJBaseMapper;
|
||||
import com.njcn.gather.device.pojo.po.PqStandardDevGainRecord;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @date 2026-01-15
|
||||
*/
|
||||
public interface PqStandardDevGainRecordMapper extends MPJBaseMapper<PqStandardDevGainRecord> {
|
||||
|
||||
}
|
||||
|
||||
@@ -134,6 +134,7 @@
|
||||
#{item}
|
||||
</foreach>
|
||||
</if>
|
||||
order by dev.Create_Time DESC, dev.Name ASC
|
||||
</select>
|
||||
</mapper>
|
||||
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.njcn.gather.device.mapper.PqStandardDevGainMapper">
|
||||
|
||||
|
||||
</mapper>
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.njcn.gather.device.mapper.PqStandardDevGainRecordMapper">
|
||||
|
||||
|
||||
</mapper>
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
package com.njcn.gather.device.pojo.po;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.njcn.db.mybatisplus.bo.BaseEntity;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @date 2026-01-12
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@TableName("pq_standard_dev_gain")
|
||||
public class PqStandardDevGain extends BaseEntity implements Serializable {
|
||||
private static final long serialVersionUID = -46280767885558804L;
|
||||
|
||||
|
||||
/**
|
||||
* 标准设备Id_通道号
|
||||
*/
|
||||
@TableId
|
||||
private String stdDevMonitorId;
|
||||
|
||||
private Integer uaGain;
|
||||
|
||||
private Integer ubGain;
|
||||
|
||||
|
||||
private Integer ucGain;
|
||||
|
||||
|
||||
private Integer u0Gain;
|
||||
|
||||
|
||||
private Integer iaGain;
|
||||
|
||||
|
||||
private Integer ibGain;
|
||||
|
||||
|
||||
private Integer icGain;
|
||||
|
||||
|
||||
private Integer i0Gain;
|
||||
|
||||
|
||||
private Integer uabGain;
|
||||
|
||||
|
||||
private Integer ubcGain;
|
||||
|
||||
|
||||
private Integer ucaGain;
|
||||
|
||||
private Integer state;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
package com.njcn.gather.device.pojo.po;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.njcn.db.mybatisplus.bo.BaseEntity;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @date 2026-01-15
|
||||
*/
|
||||
@Data
|
||||
@TableName("pq_standard_dev_gain_record")
|
||||
public class PqStandardDevGainRecord implements Serializable {
|
||||
private static final long serialVersionUID = 477276215572686991L;
|
||||
|
||||
/**
|
||||
* 标准设备监测点id,由设备id_通道号组成
|
||||
*/
|
||||
private String stdDevMonitorId;
|
||||
|
||||
/**
|
||||
* 被检设备监测点id,由设备id_通道号组成
|
||||
*/
|
||||
private String devMonitorId;
|
||||
|
||||
/**
|
||||
* 系数下发次数
|
||||
*/
|
||||
private Integer num;
|
||||
|
||||
}
|
||||
|
||||
@@ -38,8 +38,8 @@ public class ContrastDevExcel implements Serializable {
|
||||
@Pattern(regexp = PatternRegex.DEV_NAME_REGEX, message = DetectionValidMessage.NAME_FORMAT_ERROR)
|
||||
private String name;
|
||||
|
||||
@Excel(name = "设备序列号*", width = 20, needMerge = true, orderNum = "5")
|
||||
@NotBlank(message = DetectionValidMessage.FACTORYNO_NOT_BLANK)
|
||||
@Excel(name = "设备序列号", width = 20, needMerge = true, orderNum = "5")
|
||||
// @NotBlank(message = DetectionValidMessage.FACTORYNO_NOT_BLANK)
|
||||
private String createId;
|
||||
|
||||
@Excel(name = "设备类型*", width = 20, needMerge = true, orderNum = "6")
|
||||
@@ -91,8 +91,8 @@ public class ContrastDevExcel implements Serializable {
|
||||
@NotNull(message = DetectionValidMessage.INSPECT_DATE_NOT_NULL)
|
||||
private LocalDate inspectDate;
|
||||
|
||||
@Excel(name = "谐波系统设备id*", width = 30, needMerge = true, orderNum = "18")
|
||||
@NotBlank(message = DetectionValidMessage.HARM_SYS_ID_NOT_BLANK)
|
||||
@Excel(name = "谐波系统设备id", width = 30, needMerge = true, orderNum = "18")
|
||||
// @NotBlank(message = DetectionValidMessage.HARM_SYS_ID_NOT_BLANK)
|
||||
private String harmSysId;
|
||||
|
||||
@ExcelCollection(name = "监测点信息", orderNum = "19")
|
||||
|
||||
@@ -111,4 +111,9 @@ public class PqDevVO extends PqDev {
|
||||
* 是否已经分配。0-未分配、1-已分配、2-所有
|
||||
*/
|
||||
private Integer assign;
|
||||
|
||||
/**
|
||||
* 检测点结果
|
||||
*/
|
||||
private List<Integer> monitorResults;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.njcn.gather.device.pojo.vo;
|
||||
|
||||
import com.njcn.gather.device.pojo.po.PqStandardDev;
|
||||
import com.njcn.gather.device.pojo.po.PqStandardDevGain;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @data 2026-01-19
|
||||
*/
|
||||
@Data
|
||||
public class PqStandardDevVO extends PqStandardDev {
|
||||
|
||||
/**
|
||||
* 通道系数
|
||||
*/
|
||||
List<PqStandardDevGain> gainList;
|
||||
}
|
||||
@@ -3,6 +3,7 @@ package com.njcn.gather.device.service;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.njcn.common.pojo.poi.PullDown;
|
||||
import com.njcn.common.pojo.response.HttpResult;
|
||||
import com.njcn.gather.device.pojo.enums.TimeCheckResultEnum;
|
||||
import com.njcn.gather.device.pojo.param.PqDevParam;
|
||||
import com.njcn.gather.device.pojo.po.PqDev;
|
||||
@@ -124,7 +125,7 @@ public interface IPqDevService extends IService<PqDev> {
|
||||
* @param devId
|
||||
* @param userId
|
||||
*/
|
||||
void updateResult(String devId,String userId);
|
||||
void updateResult(String devId, String userId);
|
||||
|
||||
void updatePqDevReportState(String devId, int i);
|
||||
|
||||
@@ -160,7 +161,7 @@ public interface IPqDevService extends IService<PqDev> {
|
||||
* @param planId 计划Id
|
||||
* @param response 响应
|
||||
*/
|
||||
boolean importDev(MultipartFile file, String patternId, String planId, HttpServletResponse response);
|
||||
HttpResult importDev(MultipartFile file, String patternId, String planId, HttpServletResponse response, Integer cover);
|
||||
|
||||
/**
|
||||
* 导入灿能二楼设备数据
|
||||
@@ -254,7 +255,7 @@ public interface IPqDevService extends IService<PqDev> {
|
||||
* @param planId 计划Id
|
||||
* @param response 响应
|
||||
*/
|
||||
boolean importContrastDev(MultipartFile file, String patternId, String planId, HttpServletResponse response);
|
||||
HttpResult importContrastDev(MultipartFile file, String patternId, String planId, HttpServletResponse response, Integer cover);
|
||||
|
||||
/**
|
||||
* 导入比对式设备数据
|
||||
@@ -262,7 +263,7 @@ public interface IPqDevService extends IService<PqDev> {
|
||||
* @param contrastDevExcelList
|
||||
* @param patternId
|
||||
*/
|
||||
boolean importContrastDev(List<ContrastDevExcel> contrastDevExcelList, String patternId, String planId);
|
||||
HttpResult importContrastDev(List<ContrastDevExcel> contrastDevExcelList, String patternId, String planId, Integer cover);
|
||||
|
||||
/**
|
||||
* 获取比对式设备导出、导出文件模板的下拉列表
|
||||
@@ -287,4 +288,6 @@ public interface IPqDevService extends IService<PqDev> {
|
||||
* @return
|
||||
*/
|
||||
List<ContrastDevExcel> getExportContrastDevData(List<PqDevVO> pqDevVOList);
|
||||
|
||||
List<PqDevVO> listAll();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.njcn.gather.device.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.njcn.gather.device.pojo.po.PqStandardDevGainRecord;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @date 2026-01-15
|
||||
*/
|
||||
public interface IPqStandardDevGainRecordService extends IService<PqStandardDevGainRecord> {
|
||||
|
||||
/**
|
||||
* 获取最大下发系数的次数
|
||||
*
|
||||
* @param stdDevMonitorId
|
||||
* @param devMonitorId
|
||||
* @return
|
||||
*/
|
||||
int getMaxNum(String stdDevMonitorId, String devMonitorId);
|
||||
|
||||
/**
|
||||
* 批量新增或更新记录
|
||||
* @param recordList
|
||||
* @return
|
||||
*/
|
||||
boolean addOrUpdate(List<PqStandardDevGainRecord> recordList);
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.njcn.gather.device.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.njcn.gather.device.pojo.po.PqStandardDevGain;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @date 2026-01-12
|
||||
*/
|
||||
public interface IPqStandardDevGainService extends IService<PqStandardDevGain> {
|
||||
|
||||
boolean add(List<PqStandardDevGain> pqStandardDevGainList);
|
||||
|
||||
PqStandardDevGain get(String stdDevMonitorId);
|
||||
|
||||
List<PqStandardDevGain> list(String stdDevId);
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.njcn.gather.device.pojo.param.PqStandardDevParam;
|
||||
import com.njcn.gather.device.pojo.po.PqStandardDev;
|
||||
import com.njcn.gather.device.pojo.vo.PqStandardDevVO;
|
||||
import com.njcn.gather.device.pojo.vo.PreDetection;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
@@ -30,7 +31,7 @@ public interface IPqStandardDevService extends IService<PqStandardDev> {
|
||||
* @param id 设备id
|
||||
* @return 设备对象
|
||||
*/
|
||||
PqStandardDev getPqStandardDevById(String id);
|
||||
PqStandardDevVO getPqStandardDevById(String id);
|
||||
|
||||
/**
|
||||
* 新增标准设备
|
||||
@@ -82,7 +83,7 @@ public interface IPqStandardDevService extends IService<PqStandardDev> {
|
||||
* @param planId
|
||||
* @return
|
||||
*/
|
||||
List<PqStandardDev> listByPlanId(String planId);
|
||||
// List<PqStandardDev> listByPlanId(String planId);
|
||||
|
||||
/**
|
||||
* 查询出标准设备所需的检测信息
|
||||
|
||||
@@ -11,6 +11,7 @@ import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.ReflectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.baomidou.mybatisplus.extension.conditions.update.LambdaUpdateChainWrapper;
|
||||
@@ -19,8 +20,10 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.github.yulichang.wrapper.MPJLambdaWrapper;
|
||||
import com.njcn.common.pojo.constant.PatternRegex;
|
||||
import com.njcn.common.pojo.enums.common.DataStateEnum;
|
||||
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
|
||||
import com.njcn.common.pojo.exception.BusinessException;
|
||||
import com.njcn.common.pojo.poi.PullDown;
|
||||
import com.njcn.common.pojo.response.HttpResult;
|
||||
import com.njcn.common.utils.EncryptionUtil;
|
||||
import com.njcn.db.mybatisplus.constant.DbConstant;
|
||||
import com.njcn.gather.device.mapper.PqDevMapper;
|
||||
@@ -34,6 +37,7 @@ import com.njcn.gather.device.service.IPqDevSubService;
|
||||
import com.njcn.gather.monitor.pojo.po.PqMonitor;
|
||||
import com.njcn.gather.monitor.pojo.vo.PqMonitorExcel;
|
||||
import com.njcn.gather.monitor.service.IPqMonitorService;
|
||||
import com.njcn.gather.plan.pojo.enums.DataSourceEnum;
|
||||
import com.njcn.gather.pojo.enums.DetectionResponseEnum;
|
||||
import com.njcn.gather.storage.service.DetectionDataDealService;
|
||||
import com.njcn.gather.system.cfg.pojo.enums.SceneEnum;
|
||||
@@ -49,6 +53,7 @@ import com.njcn.gather.user.user.pojo.po.SysUser;
|
||||
import com.njcn.gather.user.user.service.ISysUserService;
|
||||
import com.njcn.web.factory.PageFactory;
|
||||
import com.njcn.web.utils.ExcelUtil;
|
||||
import com.njcn.web.utils.HttpResultUtil;
|
||||
import com.njcn.web.utils.PoiUtil;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -63,6 +68,7 @@ import java.time.LocalDateTime;
|
||||
import java.util.*;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
@@ -212,7 +218,8 @@ public class PqDevServiceImpl extends ServiceImpl<PqDevMapper, PqDev> implements
|
||||
if (PatternEnum.CONTRAST.getValue().equals(dictDataService.getDictDataById(param.getPattern()).getCode())) {
|
||||
for (String id : param.getIds()) {
|
||||
if (ObjectUtils.isNotEmpty(pqMonitorService.listPqMonitorByDevIds(Collections.singletonList(id)))) {
|
||||
throw new BusinessException(DetectionResponseEnum.PQ_DEV_HAS_MONITOR);
|
||||
// throw new BusinessException(DetectionResponseEnum.PQ_DEV_HAS_MONITOR);
|
||||
pqMonitorService.removeByDevId(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -286,6 +293,33 @@ public class PqDevServiceImpl extends ServiceImpl<PqDevMapper, PqDev> implements
|
||||
return Collections.emptyList();
|
||||
}
|
||||
List<PqDevVO> pqDevList = this.baseMapper.selectByQueryParam(param);
|
||||
pqDevList.forEach(pqDev -> {
|
||||
List<PqMonitor> monitorList = pqMonitorService.listPqMonitorByDevIds(Collections.singletonList(pqDev.getId()));
|
||||
List<PqMonitor> enabledMonitorList = monitorList.stream().filter(x -> x.getCheckFlag() == 1).collect(Collectors.toList());
|
||||
pqDev.setMonitorResults(enabledMonitorList.stream().map(x -> {
|
||||
if (ObjectUtil.isNull(x.getResultType())) {
|
||||
return CheckResultEnum.UNCHECKED.getValue();
|
||||
} else {
|
||||
DataSourceEnum dataSourceEnum = DataSourceEnum.ofByValue(x.getResultType());
|
||||
|
||||
switch (dataSourceEnum) {
|
||||
case REAL_DATA:
|
||||
return x.getRealtimeResult();
|
||||
case MINUTE_STATISTICS_AVG:
|
||||
case MINUTE_STATISTICS_CP95:
|
||||
case MINUTE_STATISTICS_MIN:
|
||||
case MINUTE_STATISTICS_MAX:
|
||||
return x.getStatisticsResult();
|
||||
case WAVE_DATA:
|
||||
return x.getRecordedResult();
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
return CheckResultEnum.UNCHECKED.getValue();
|
||||
}).collect(Collectors.toList()));
|
||||
});
|
||||
|
||||
return pqDevList;
|
||||
}
|
||||
|
||||
@@ -529,19 +563,27 @@ public class PqDevServiceImpl extends ServiceImpl<PqDevMapper, PqDev> implements
|
||||
PqDev dev = this.getById(devId);
|
||||
Integer checkState = pqMonitorService.getDevCheckState(devId);
|
||||
Integer checkResult = pqMonitorService.getDevCheckResult(devId);
|
||||
if (checkResult == 1) {
|
||||
checkResult = CheckResultEnum.ACCORD.getValue();
|
||||
}
|
||||
if (checkResult == 2) {
|
||||
checkResult = CheckResultEnum.NOT_ACCORD.getValue();
|
||||
}
|
||||
|
||||
|
||||
SysUser user = userService.getById(userId);
|
||||
|
||||
LambdaUpdateChainWrapper<PqDevSub> w = pqDevSubService.lambdaUpdate()
|
||||
.set(PqDevSub::getCheckState, checkState)
|
||||
.set(PqDevSub::getCheckResult, checkResult)
|
||||
.set(PqDevSub::getReportState, DevReportStateEnum.NOT_GENERATED.getValue())
|
||||
.set(PqDevSub::getCheckTime, LocalDateTime.now())
|
||||
.eq(PqDevSub::getDevId, devId);
|
||||
|
||||
if(ObjectUtil.isNotNull(user)){
|
||||
if (ObjectUtil.isNotNull(user)) {
|
||||
w.set(PqDevSub::getCheckBy, user.getName());
|
||||
}
|
||||
if(checkState.equals(CheckStateEnum.CHECKED.getValue())){
|
||||
if (checkState.equals(CheckStateEnum.CHECKED.getValue())) {
|
||||
w.set(PqDevSub::getReportState, DevReportStateEnum.NOT_GENERATED.getValue());
|
||||
}
|
||||
w.update();
|
||||
@@ -552,15 +594,23 @@ public class PqDevServiceImpl extends ServiceImpl<PqDevMapper, PqDev> implements
|
||||
List<PqDevVO> pqDevVOList = this.baseMapper.selectByQueryParam(param);
|
||||
|
||||
if (CollUtil.isNotEmpty(pqDevVOList)) {
|
||||
Set<Integer> set = pqDevVOList.stream().map(PqDevVO::getCheckResult).collect(Collectors.toSet());
|
||||
if (set.contains(CheckResultEnum.NOT_ACCORD.getValue())) {
|
||||
this.baseMapper.updatePlanCheckResult(planId, CheckResultEnum.NOT_ACCORD.getValue());
|
||||
} else if (set.contains(CheckResultEnum.UNCHECKED.getValue())) {
|
||||
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());
|
||||
if (checkState == CheckStateEnum.CHECKED.getValue()) {
|
||||
set.add(checkResult);
|
||||
}
|
||||
if (CollUtil.isEmpty(set)) {
|
||||
this.baseMapper.updatePlanCheckResult(planId, CheckResultEnum.UNCHECKED.getValue());
|
||||
} else {
|
||||
this.baseMapper.updatePlanCheckResult(planId, CheckResultEnum.ACCORD.getValue());
|
||||
if (set.contains(CheckResultEnum.NOT_ACCORD.getValue())) {
|
||||
this.baseMapper.updatePlanCheckResult(planId, CheckResultEnum.NOT_ACCORD.getValue());
|
||||
} else if (set.contains(CheckResultEnum.UNCHECKED.getValue())) {
|
||||
this.baseMapper.updatePlanCheckResult(planId, CheckResultEnum.UNCHECKED.getValue());
|
||||
} else {
|
||||
this.baseMapper.updatePlanCheckResult(planId, CheckResultEnum.ACCORD.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
set = pqDevVOList.stream().map(PqDevVO::getCheckState).collect(Collectors.toSet());
|
||||
if (set.contains(CheckStateEnum.UNCHECKED.getValue())) {
|
||||
this.baseMapper.updatePlanTestState(planId, CheckStateEnum.CHECKING.getValue());
|
||||
@@ -643,25 +693,31 @@ public class PqDevServiceImpl extends ServiceImpl<PqDevMapper, PqDev> implements
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean importDev(MultipartFile file, String patternId, String planId, HttpServletResponse response) {
|
||||
public HttpResult importDev(MultipartFile file, String patternId, String planId, HttpServletResponse response, Integer cover) {
|
||||
DictData dictData = dictDataService.getDictDataById(patternId);
|
||||
if (PatternEnum.CONTRAST.getValue().equals(dictData.getCode())) {
|
||||
return this.importContrastDev(file, patternId, planId, response);
|
||||
return this.importContrastDev(file, patternId, planId, response, cover);
|
||||
} else {
|
||||
String currrentScene = sysTestConfigService.getCurrrentScene();
|
||||
SceneEnum sceneEnum = SceneEnum.getSceneEnum(currrentScene);
|
||||
switch (sceneEnum) {
|
||||
case PROVINCE_PLATFORM:
|
||||
return this.importProvinceDev(file, patternId, planId, response);
|
||||
boolean result = this.importProvinceDev(file, patternId, planId, response);
|
||||
if (result) {
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, "导入成功");
|
||||
}
|
||||
case LEAVE_FACTORY_TEST:
|
||||
return this.importCNDev(file, patternId, planId, response);
|
||||
result = this.importCNDev(file, patternId, planId, response);
|
||||
if (result) {
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, "导入成功");
|
||||
}
|
||||
case SELF_TEST:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, false, "导入失败");
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -788,21 +844,15 @@ public class PqDevServiceImpl extends ServiceImpl<PqDevMapper, PqDev> implements
|
||||
* @param isExcludeSelf 是否排除自己
|
||||
*/
|
||||
private void checkRepeat(PqDevParam param, boolean isExcludeSelf) {
|
||||
QueryWrapper<PqDev> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper
|
||||
.eq("state", DataStateEnum.ENABLE.getCode())
|
||||
.eq(StrUtil.isNotBlank(param.getDevType()), "Dev_Type", param.getDevType())
|
||||
.eq(StrUtil.isNotBlank(param.getPattern()), "pattern", param.getPattern())
|
||||
.eq(StrUtil.isNotBlank(param.getCityName()), "City_Name", param.getCityName())
|
||||
.eq(StrUtil.isNotBlank(param.getGdName()), "Gd_Name", param.getGdName())
|
||||
.eq(StrUtil.isNotBlank(param.getSubName()), "Sub_Name", param.getSubName())
|
||||
.and(q -> q.eq(StrUtil.isNotBlank(param.getName()), "name", param.getName()).or()
|
||||
.eq(StrUtil.isNotBlank(param.getCreateId()), "Create_Id", param.getCreateId())); //设备序列号重复
|
||||
// .eq("manufacturer", param.getManufacturer())
|
||||
// .eq("Dev_Type", param.getDevType()).or()
|
||||
LambdaQueryWrapper<PqDev> queryWrapper = new LambdaQueryWrapper<PqDev>()
|
||||
.eq(PqDev::getState, DataStateEnum.ENABLE.getCode())
|
||||
.eq(StrUtil.isNotBlank(param.getIp()), PqDev::getIp, param.getIp())
|
||||
.eq(ObjectUtil.isNotNull(param.getPort()), PqDev::getPort, param.getPort())
|
||||
.eq(StrUtil.isNotBlank(param.getPattern()), PqDev::getPattern, param.getPattern())
|
||||
.eq(StrUtil.isNotBlank(param.getCreateId()), PqDev::getCreateId, param.getCreateId());
|
||||
if (isExcludeSelf) {
|
||||
if (param instanceof PqDevParam.UpdateParam) {
|
||||
queryWrapper.ne("id", ((PqDevParam.UpdateParam) param).getId());
|
||||
queryWrapper.ne(PqDev::getId, ((PqDevParam.UpdateParam) param).getId());
|
||||
}
|
||||
}
|
||||
int count = this.count(queryWrapper);
|
||||
@@ -1181,7 +1231,7 @@ public class PqDevServiceImpl extends ServiceImpl<PqDevMapper, PqDev> implements
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean importContrastDev(MultipartFile file, String patternId, String planId, HttpServletResponse response) {
|
||||
public HttpResult importContrastDev(MultipartFile file, String patternId, String planId, HttpServletResponse response, Integer cover) {
|
||||
ImportParams params = new ImportParams();
|
||||
params.setStartSheetIndex(0);
|
||||
params.setSheetNum(1);
|
||||
@@ -1201,52 +1251,56 @@ public class PqDevServiceImpl extends ServiceImpl<PqDevMapper, PqDev> implements
|
||||
} catch (Exception e) {
|
||||
throw new BusinessException(DetectionResponseEnum.IMPORT_DATA_FAIL);
|
||||
}
|
||||
return this.importContrastDev(contrastDevExcelList, patternId, planId);
|
||||
return this.importContrastDev(contrastDevExcelList, patternId, planId, cover);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public boolean importContrastDev(List<ContrastDevExcel> contrastDevExcelList, String patternId, String planId) {
|
||||
public HttpResult importContrastDev(List<ContrastDevExcel> contrastDevExcelList, String patternId, String planId, Integer cover) {
|
||||
if (CollUtil.isNotEmpty(contrastDevExcelList)) {
|
||||
// 根据设备名称分组
|
||||
Map<String, List<ContrastDevExcel>> listMap = contrastDevExcelList.stream()
|
||||
.collect(Collectors.groupingBy(ContrastDevExcel::getName, LinkedHashMap::new, Collectors.toList()));
|
||||
List<PqDev> oldDevList = new ArrayList<>(listMap.size());
|
||||
List<PqMonitor> finalMonitorList = new ArrayList<>();
|
||||
List<PqDev> newDevList = new ArrayList<>(listMap.size());
|
||||
List<PqDev> updateDevList = new ArrayList<>();
|
||||
List<PqDev> finalUpdateDevList = new ArrayList<>();
|
||||
for (Map.Entry<String, List<ContrastDevExcel>> entry : listMap.entrySet()) {
|
||||
String name = entry.getKey();
|
||||
|
||||
List<ContrastDevExcel> devExcelList = entry.getValue();
|
||||
// 监测点数据
|
||||
List<PqMonitorExcel> pqMonitorExcelList = devExcelList.stream()
|
||||
.map(ContrastDevExcel::getPqMonitorExcelList)
|
||||
.filter(Objects::nonNull)
|
||||
.flatMap(List::stream)
|
||||
// 过滤掉没有线路号的数据
|
||||
.filter(item -> ObjectUtil.isNotNull(item.getNum()))
|
||||
.collect(Collectors.toList());
|
||||
// 取第一条为设备基本信息
|
||||
ContrastDevExcel devExcel = devExcelList.get(0);
|
||||
PqDev pqDev = BeanUtil.copyProperties(devExcel, PqDev.class);
|
||||
if (pqDev.getEncryptionFlag() == 1) {
|
||||
if (StrUtil.isNotBlank(pqDev.getSeries()) && StrUtil.isNotBlank(pqDev.getDevKey())) {
|
||||
pqDev.setSeries(EncryptionUtil.encodeString(1, pqDev.getSeries()));
|
||||
pqDev.setDevKey(EncryptionUtil.encodeString(1, pqDev.getDevKey()));
|
||||
PqDev importPqDev = BeanUtil.copyProperties(devExcel, PqDev.class);
|
||||
if (importPqDev.getEncryptionFlag() == 1) {
|
||||
if (StrUtil.isNotBlank(importPqDev.getSeries()) && StrUtil.isNotBlank(importPqDev.getDevKey())) {
|
||||
importPqDev.setSeries(EncryptionUtil.encodeString(1, importPqDev.getSeries()));
|
||||
importPqDev.setDevKey(EncryptionUtil.encodeString(1, importPqDev.getDevKey()));
|
||||
} else {
|
||||
throw new BusinessException(DetectionResponseEnum.SERIES_AND_DEVKEY_NOT_BLANK);
|
||||
}
|
||||
}
|
||||
DevType devType = devTypeService.getByName(pqDev.getDevType());
|
||||
DevType devType = devTypeService.getByName(importPqDev.getDevType());
|
||||
if (ObjectUtil.isNull(devType)) {
|
||||
throw new BusinessException(DetectionResponseEnum.DEV_TYPE_NOT_EXIST);
|
||||
}
|
||||
// 校验监测点数量
|
||||
int devChns = devType.getDevChns();
|
||||
if (pqMonitorExcelList.size() != devChns) {
|
||||
throw new BusinessException(DetectionResponseEnum.IMPORT_DATA_FAIL, "【" + name + "】的设备类型必须具备" + devChns + "个监测点信息!");
|
||||
}
|
||||
// if (pqMonitorExcelList.size() != devChns) {
|
||||
// throw new BusinessException(DetectionResponseEnum.IMPORT_DATA_FAIL, "【" + name + "】的设备类型必须具备" + devChns + "个监测点信息!");
|
||||
// }
|
||||
List<Integer> numList = pqMonitorExcelList.stream().map(PqMonitorExcel::getNum).collect(Collectors.toList());
|
||||
// 判断是否有重复的num
|
||||
Set<Integer> uniqueNumSet = new HashSet<>(numList);
|
||||
if (uniqueNumSet.size() != numList.size()) {
|
||||
throw new BusinessException(DetectionResponseEnum.MONITOR_NUM_REPEAT);
|
||||
throw new BusinessException(DetectionResponseEnum.MONITOR_NUM_REPEAT, "【" + name + "】该被检设备下存在相同线路号的监测点!");
|
||||
}
|
||||
Integer max = CollectionUtil.max(numList);
|
||||
Integer min = CollectionUtil.min(numList);
|
||||
@@ -1254,90 +1308,144 @@ public class PqDevServiceImpl extends ServiceImpl<PqDevMapper, PqDev> implements
|
||||
throw new BusinessException(DetectionResponseEnum.MONITOR_NUM_OUT_OF_RANGE);
|
||||
}
|
||||
|
||||
pqDev.setDevType(devType.getId());
|
||||
pqDev.setImportFlag(1);
|
||||
pqDev.setId(UUID.randomUUID().toString().replaceAll("-", ""));
|
||||
pqDev.setCreateId(pqDev.getName()); //导入时设备序列号默认与设备名称相同
|
||||
List<PqMonitor> monitorList = new ArrayList<>();
|
||||
importPqDev.setDevType(devType.getId());
|
||||
importPqDev.setImportFlag(1);
|
||||
importPqDev.setId(UUID.randomUUID().toString().replaceAll("-", ""));
|
||||
|
||||
if (StrUtil.isEmpty(importPqDev.getCreateId())) {
|
||||
// 与设备名称相同
|
||||
importPqDev.setCreateId(importPqDev.getName());
|
||||
}
|
||||
// 根据num排序
|
||||
pqMonitorExcelList.sort(Comparator.comparingInt(PqMonitorExcel::getNum));
|
||||
for (PqMonitorExcel pqMonitorExcel : pqMonitorExcelList) {
|
||||
PqMonitor monitor = BeanUtil.copyProperties(pqMonitorExcel, PqMonitor.class);
|
||||
monitor.setDevId(pqDev.getId());
|
||||
monitorList.add(monitor);
|
||||
}
|
||||
StringBuilder inspectChannelBuilder = new StringBuilder();
|
||||
for (int i = 1; i <= devChns; i++) {
|
||||
inspectChannelBuilder.append(i);
|
||||
if (i < devChns) {
|
||||
inspectChannelBuilder.append(",");
|
||||
for (int i = 0; i < numList.size(); i++) {
|
||||
inspectChannelBuilder.append(numList.get(i));
|
||||
if (i < numList.size() - 1) {
|
||||
inspectChannelBuilder.append(StrUtil.COMMA);
|
||||
}
|
||||
}
|
||||
pqDev.setInspectChannel(inspectChannelBuilder.toString());
|
||||
oldDevList.add(pqDev);
|
||||
finalMonitorList.addAll(monitorList);
|
||||
}
|
||||
//逆向可视化
|
||||
this.reverseVisualizeProvinceDev(oldDevList, patternId);
|
||||
|
||||
List<PqDev> newDevList = new ArrayList<>();
|
||||
oldDevList.forEach(pqDev -> {
|
||||
PqDevParam param = BeanUtil.copyProperties(pqDev, PqDevParam.class);
|
||||
this.checkRepeat(param, false);
|
||||
long count = newDevList.stream().filter(dev ->
|
||||
dev.getDevType().equals(pqDev.getDevType())
|
||||
&& dev.getCityName().equals(pqDev.getCityName())
|
||||
&& dev.getGdName().equals(pqDev.getGdName())
|
||||
&& dev.getSubName().equals(pqDev.getSubName())
|
||||
&& (dev.getName().equals(pqDev.getName()) || dev.getCreateId().equals(pqDev.getCreateId())))
|
||||
.count();
|
||||
if (count == 0) {
|
||||
pqDev.setPlanId(planId);
|
||||
newDevList.add(pqDev);
|
||||
}
|
||||
});
|
||||
QueryWrapper<PqDev> wrapper1 = new QueryWrapper<PqDev>()
|
||||
.eq("pq_dev.State", DataStateEnum.ENABLE.getCode())
|
||||
.in("pq_dev.Harm_Sys_Id", newDevList.stream().map(PqDev::getHarmSysId).collect(Collectors.toList()));
|
||||
List<PqDev> oldDevList1 = this.list(wrapper1);
|
||||
if (CollUtil.isNotEmpty(oldDevList1)) {
|
||||
oldDevList1.stream().forEach(oldDev -> {
|
||||
PqDev newDev = newDevList.stream().filter(dev -> dev.getHarmSysId().equals(oldDev.getHarmSysId())).findFirst().orElse(null);
|
||||
if (ObjectUtil.isNotNull(newDev)) {
|
||||
newDevList.remove(newDev);
|
||||
finalMonitorList.stream()
|
||||
.filter(monitor -> monitor.getDevId().equals(newDev.getId()))
|
||||
.forEach(monitor -> monitor.setDevId(oldDev.getId()));
|
||||
BeanUtil.copyProperties(newDev, oldDev, "id");
|
||||
importPqDev.setInspectChannel(inspectChannelBuilder.toString());
|
||||
List<PqMonitor> monitorList = new ArrayList<>();
|
||||
// 1、先判断是否有谐波系统ID
|
||||
boolean hasHarmSys = false;
|
||||
if (StrUtil.isNotBlank(importPqDev.getHarmSysId())) {
|
||||
// 1.1、如果有则判断是否已存在
|
||||
List<PqDev> hasList = this.lambdaQuery()
|
||||
.eq(PqDev::getState, DataStateEnum.ENABLE.getCode())
|
||||
.eq(PqDev::getPattern, patternId)
|
||||
.eq(PqDev::getHarmSysId, importPqDev.getHarmSysId())
|
||||
.isNull(PqDev::getPlanId)
|
||||
.orderByDesc(PqDev::getCreateTime).list();
|
||||
// 1.2、 存在则放入强制更新list
|
||||
if (CollUtil.isNotEmpty(hasList)) {
|
||||
importPqDev.setId(hasList.get(0).getId());
|
||||
for (PqMonitorExcel pqMonitorExcel : pqMonitorExcelList) {
|
||||
PqMonitor monitor = BeanUtil.copyProperties(pqMonitorExcel, PqMonitor.class);
|
||||
monitor.setDevId(importPqDev.getId());
|
||||
monitor.setPt(pqMonitorExcel.getPt1() + StrUtil.C_COLON + pqMonitorExcel.getPt2());
|
||||
monitor.setCt(pqMonitorExcel.getCt1() + StrUtil.C_COLON + pqMonitorExcel.getCt2());
|
||||
monitorList.add(monitor);
|
||||
}
|
||||
importPqDev.setMonitorList(monitorList);
|
||||
finalUpdateDevList.add(importPqDev);
|
||||
hasHarmSys = true;
|
||||
}
|
||||
});
|
||||
this.updateBatchById(oldDevList1);
|
||||
}
|
||||
this.saveBatch(newDevList);
|
||||
List<PqDevSub> pqDevSubList = new ArrayList<>();
|
||||
for (PqDev dev : newDevList) {
|
||||
PqDevSub pqDevSub = new PqDevSub();
|
||||
pqDevSub.setDevId(dev.getId());
|
||||
pqDevSub.setCheckState(CheckStateEnum.UNCHECKED.getValue());
|
||||
pqDevSub.setCheckResult(CheckResultEnum.UNCHECKED.getValue());
|
||||
pqDevSub.setReportState(DevReportStateEnum.UNCHECKED.getValue());
|
||||
pqDevSub.setTimeCheckResult(TimeCheckResultEnum.UNKNOWN.getValue());
|
||||
pqDevSub.setFactorCheckResult(FactorCheckResultEnum.UNKNOWN.getValue());
|
||||
pqDevSubList.add(pqDevSub);
|
||||
}
|
||||
pqDevSubService.saveBatch(pqDevSubList);
|
||||
|
||||
List<String> devIdList = oldDevList1.stream().map(PqDev::getId).collect(Collectors.toList());
|
||||
if (CollUtil.isNotEmpty(devIdList)) {
|
||||
QueryWrapper<PqMonitor> wrapper = new QueryWrapper<PqMonitor>()
|
||||
.in("pq_monitor.Dev_Id", devIdList);
|
||||
pqMonitorService.remove(wrapper);
|
||||
}
|
||||
if (!hasHarmSys) {
|
||||
// 2、查询 ip + 端口 + 序列号 + patternId + Plan_Id为空 是否存在
|
||||
List<PqDev> hasList = this.lambdaQuery()
|
||||
.eq(PqDev::getState, DataStateEnum.ENABLE.getCode())
|
||||
.eq(PqDev::getIp, devExcel.getIp())
|
||||
.eq(PqDev::getPort, devExcel.getPort())
|
||||
.eq(PqDev::getPattern, patternId)
|
||||
.eq(PqDev::getCreateId, devExcel.getCreateId())
|
||||
.isNull(PqDev::getPlanId)
|
||||
.orderByDesc(PqDev::getCreateTime).list();
|
||||
// 2.1、存在则放入更新list
|
||||
if (CollUtil.isNotEmpty(hasList)) {
|
||||
importPqDev.setId(hasList.get(0).getId());
|
||||
for (PqMonitorExcel pqMonitorExcel : pqMonitorExcelList) {
|
||||
PqMonitor monitor = BeanUtil.copyProperties(pqMonitorExcel, PqMonitor.class);
|
||||
monitor.setDevId(importPqDev.getId());
|
||||
monitor.setPt(pqMonitorExcel.getPt1() + StrUtil.C_COLON + pqMonitorExcel.getPt2());
|
||||
monitor.setCt(pqMonitorExcel.getCt1() + StrUtil.C_COLON + pqMonitorExcel.getCt2());
|
||||
monitorList.add(monitor);
|
||||
}
|
||||
importPqDev.setMonitorList(monitorList);
|
||||
updateDevList.add(importPqDev);
|
||||
} else {
|
||||
//2.2、不存在则放入新增list
|
||||
for (PqMonitorExcel pqMonitorExcel : pqMonitorExcelList) {
|
||||
PqMonitor monitor = BeanUtil.copyProperties(pqMonitorExcel, PqMonitor.class);
|
||||
monitor.setDevId(importPqDev.getId());
|
||||
monitor.setPt(pqMonitorExcel.getPt1() + StrUtil.C_COLON + pqMonitorExcel.getPt2());
|
||||
monitor.setCt(pqMonitorExcel.getCt1() + StrUtil.C_COLON + pqMonitorExcel.getCt2());
|
||||
monitorList.add(monitor);
|
||||
}
|
||||
importPqDev.setMonitorList(monitorList);
|
||||
newDevList.add(importPqDev);
|
||||
}
|
||||
}
|
||||
}
|
||||
pqMonitorService.reverseVisualizeMonitor(finalMonitorList);
|
||||
pqMonitorService.saveBatch(finalMonitorList);
|
||||
return true;
|
||||
// 3、是否有重复的设备
|
||||
if (CollUtil.isNotEmpty(updateDevList)) {
|
||||
// 3.1、有则让用户确认是否覆盖
|
||||
if (cover == 0) {
|
||||
List<String> existDevList = new ArrayList<>();
|
||||
updateDevList.forEach(pqDev -> {
|
||||
existDevList.add(pqDev.getName() + "(" + pqDev.getIp() + ":" + pqDev.getPort() + ")");
|
||||
});
|
||||
return HttpResultUtil.assembleResult(DetectionResponseEnum.DEV_IP_PORT_EXIST.getCode(), existDevList, "请确认是否覆盖");
|
||||
|
||||
} else {
|
||||
// 3.2、确认覆盖则放入强制更新list
|
||||
finalUpdateDevList.addAll(updateDevList);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 4、新增list
|
||||
if (CollUtil.isNotEmpty(newDevList)) {
|
||||
//逆向可视化
|
||||
this.reverseVisualizeProvinceDev(newDevList, patternId);
|
||||
this.saveBatch(newDevList);
|
||||
List<PqDevSub> pqDevSubList = new ArrayList<>();
|
||||
List<PqMonitor> newMonitorList = new ArrayList<>();
|
||||
for (PqDev dev : newDevList) {
|
||||
PqDevSub pqDevSub = new PqDevSub();
|
||||
pqDevSub.setDevId(dev.getId());
|
||||
pqDevSub.setCheckState(CheckStateEnum.UNCHECKED.getValue());
|
||||
pqDevSub.setCheckResult(CheckResultEnum.UNCHECKED.getValue());
|
||||
pqDevSub.setReportState(DevReportStateEnum.UNCHECKED.getValue());
|
||||
pqDevSub.setTimeCheckResult(TimeCheckResultEnum.UNKNOWN.getValue());
|
||||
pqDevSub.setFactorCheckResult(FactorCheckResultEnum.UNKNOWN.getValue());
|
||||
pqDevSubList.add(pqDevSub);
|
||||
newMonitorList.addAll(dev.getMonitorList());
|
||||
}
|
||||
pqMonitorService.reverseVisualizeMonitor(newMonitorList);
|
||||
pqMonitorService.saveBatch(newMonitorList);
|
||||
pqDevSubService.saveBatch(pqDevSubList);
|
||||
}
|
||||
// 5、更新list
|
||||
if (CollUtil.isNotEmpty(finalUpdateDevList)) {
|
||||
//逆向可视化
|
||||
this.reverseVisualizeProvinceDev(finalUpdateDevList, patternId);
|
||||
this.updateBatchById(finalUpdateDevList);
|
||||
List<PqMonitor> updateMonitorList = new ArrayList<>();
|
||||
for (PqDev dev : finalUpdateDevList) {
|
||||
updateMonitorList.addAll(dev.getMonitorList());
|
||||
}
|
||||
pqMonitorService.reverseVisualizeMonitor(updateMonitorList);
|
||||
for (PqMonitor monitor : updateMonitorList) {
|
||||
pqMonitorService.update(monitor, new LambdaUpdateWrapper<PqMonitor>().eq(PqMonitor::getDevId, monitor.getDevId()));
|
||||
}
|
||||
}
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, "导入成功");
|
||||
}
|
||||
return false;
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, false, "导入失败");
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1395,13 +1503,19 @@ public class PqDevServiceImpl extends ServiceImpl<PqDevMapper, PqDev> implements
|
||||
if (ObjectUtil.isNotNull(dictType)) {
|
||||
dictDataList = dictDataService.getDictDataByTypeId(dictType.getId());
|
||||
pullDown = new PullDown();
|
||||
pullDown.setFirstCol(startCol + 24);
|
||||
pullDown.setLastCol(startCol + 24);
|
||||
pullDown.setFirstCol(startCol + 26);
|
||||
pullDown.setLastCol(startCol + 26);
|
||||
|
||||
pullDown.setStrings(dictDataList.stream().map(DictData::getName).collect(Collectors.toList()));
|
||||
pullDowns.add(pullDown);
|
||||
}
|
||||
|
||||
pullDown = new PullDown();
|
||||
pullDown.setFirstCol(startCol + 27);
|
||||
pullDown.setLastCol(startCol + 27);
|
||||
pullDown.setStrings(Stream.iterate(1, x -> x + 1).limit(10).map(String::valueOf).collect(Collectors.toList()));
|
||||
pullDowns.add(pullDown);
|
||||
|
||||
return pullDowns;
|
||||
}
|
||||
|
||||
@@ -1463,7 +1577,22 @@ public class PqDevServiceImpl extends ServiceImpl<PqDevMapper, PqDev> implements
|
||||
contrastDevExcels.forEach(contrastDevExcel -> {
|
||||
List<PqMonitor> monitorList = pqMonitorService.listPqMonitorByDevIds(Collections.singletonList(contrastDevExcel.getId()));
|
||||
pqMonitorService.visualizeMonitor(monitorList);
|
||||
List<PqMonitorExcel> pqMonitorExcelList = BeanUtil.copyToList(monitorList, PqMonitorExcel.class);
|
||||
List<PqMonitorExcel> pqMonitorExcelList = new ArrayList<>();
|
||||
for (int i = 0; i < monitorList.size(); i++) {
|
||||
PqMonitor pqMonitor = monitorList.get(i);
|
||||
PqMonitorExcel pqMonitorExcel = BeanUtil.copyProperties(pqMonitor, PqMonitorExcel.class);
|
||||
String pt = pqMonitor.getPt();
|
||||
String[] split1 = pt.split(String.valueOf(StrUtil.C_COLON));
|
||||
pqMonitorExcel.setPt1(split1[0]);
|
||||
pqMonitorExcel.setPt2(split1[1]);
|
||||
|
||||
String ct = pqMonitor.getCt();
|
||||
String[] split2 = ct.split(String.valueOf(StrUtil.C_COLON));
|
||||
pqMonitorExcel.setCt1(split2[0]);
|
||||
pqMonitorExcel.setCt2(split2[1]);
|
||||
|
||||
pqMonitorExcelList.add(pqMonitorExcel);
|
||||
}
|
||||
contrastDevExcel.setPqMonitorExcelList(pqMonitorExcelList);
|
||||
});
|
||||
}
|
||||
@@ -1496,4 +1625,31 @@ public class PqDevServiceImpl extends ServiceImpl<PqDevMapper, PqDev> implements
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PqDevVO> listAll() {
|
||||
return this.lambdaQuery()
|
||||
.eq(PqDev::getState, DataStateEnum.ENABLE.getCode())
|
||||
.orderByDesc(PqDev::getCreateTime)
|
||||
.list().stream().map(pqDev -> {
|
||||
PqDevVO pqDevVO = new PqDevVO();
|
||||
BeanUtil.copyProperties(pqDev, pqDevVO);
|
||||
// 解密序列号和密钥
|
||||
if (StrUtil.isNotBlank(pqDevVO.getSeries())) {
|
||||
pqDevVO.setSeries(EncryptionUtil.decoderString(1, pqDevVO.getSeries()));
|
||||
}
|
||||
if (StrUtil.isNotBlank(pqDevVO.getDevKey())) {
|
||||
pqDevVO.setDevKey(EncryptionUtil.decoderString(1, pqDevVO.getDevKey()));
|
||||
}
|
||||
// 填充设备类型信息
|
||||
DevType devType = devTypeService.getById(pqDevVO.getDevType());
|
||||
if (ObjectUtil.isNotNull(devType)) {
|
||||
pqDevVO.setDevType(devType.getName());
|
||||
pqDevVO.setDevChns(devType.getDevChns());
|
||||
pqDevVO.setDevVolt(devType.getDevVolt());
|
||||
pqDevVO.setDevCurr(devType.getDevCurr());
|
||||
}
|
||||
return pqDevVO;
|
||||
}).collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
package com.njcn.gather.device.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.njcn.gather.device.mapper.PqStandardDevGainRecordMapper;
|
||||
import com.njcn.gather.device.pojo.po.PqStandardDevGainRecord;
|
||||
import com.njcn.gather.device.service.IPqStandardDevGainRecordService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @date 2026-01-15
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class PqStandardDevGainRecordServiceImpl extends ServiceImpl<PqStandardDevGainRecordMapper, PqStandardDevGainRecord> implements IPqStandardDevGainRecordService {
|
||||
|
||||
@Override
|
||||
public int getMaxNum(String stdDevMonitorId, String devMonitorId) {
|
||||
return this.lambdaQuery().eq(PqStandardDevGainRecord::getStdDevMonitorId, stdDevMonitorId)
|
||||
.eq(PqStandardDevGainRecord::getDevMonitorId, devMonitorId)
|
||||
.list().stream().mapToInt(PqStandardDevGainRecord::getNum).max().orElse(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addOrUpdate(List<PqStandardDevGainRecord> recordList) {
|
||||
recordList.forEach(record -> {
|
||||
List<PqStandardDevGainRecord> list = this.lambdaQuery().eq(PqStandardDevGainRecord::getStdDevMonitorId, record.getStdDevMonitorId())
|
||||
.eq(PqStandardDevGainRecord::getDevMonitorId, record.getDevMonitorId()).list();
|
||||
if (CollectionUtil.isNotEmpty(list)) {
|
||||
this.lambdaUpdate().eq(PqStandardDevGainRecord::getStdDevMonitorId, record.getStdDevMonitorId())
|
||||
.eq(PqStandardDevGainRecord::getDevMonitorId, record.getDevMonitorId())
|
||||
.set(PqStandardDevGainRecord::getNum, record.getNum()).update();
|
||||
} else {
|
||||
this.save(record);
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package com.njcn.gather.device.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.njcn.gather.device.mapper.PqStandardDevGainMapper;
|
||||
import com.njcn.gather.device.pojo.po.PqStandardDevGain;
|
||||
import com.njcn.gather.device.service.IPqStandardDevGainService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @date 2026-01-12
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class PqStandardDevGainServiceImpl extends ServiceImpl<PqStandardDevGainMapper, PqStandardDevGain> implements IPqStandardDevGainService {
|
||||
|
||||
@Override
|
||||
public boolean add(List<PqStandardDevGain> pqStandardDevGainList) {
|
||||
log.info("add PqStandardDevGainList: {}", pqStandardDevGainList.size());
|
||||
List<String> stdMonitorIdList = pqStandardDevGainList.stream().map(PqStandardDevGain::getStdDevMonitorId).distinct().collect(Collectors.toList());
|
||||
List<String> existingStdMonitorIdList = this.listByIds(stdMonitorIdList).stream().map(PqStandardDevGain::getStdDevMonitorId).collect(Collectors.toList());
|
||||
|
||||
pqStandardDevGainList = pqStandardDevGainList.stream().filter(pqStandardDevGain -> !existingStdMonitorIdList.contains(pqStandardDevGain.getStdDevMonitorId())).collect(Collectors.toList());
|
||||
return this.saveBatch(pqStandardDevGainList);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PqStandardDevGain get(String stdDevMonitorId) {
|
||||
return this.lambdaQuery().eq(PqStandardDevGain::getStdDevMonitorId, stdDevMonitorId).one();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PqStandardDevGain> list(String stdDevId) {
|
||||
return this.lambdaQuery().likeRight(PqStandardDevGain::getStdDevMonitorId, stdDevId).orderByAsc(PqStandardDevGain::getStdDevMonitorId).list();
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,6 @@ import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.extra.spring.SpringUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
@@ -18,17 +17,15 @@ import com.njcn.common.pojo.exception.BusinessException;
|
||||
import com.njcn.common.pojo.poi.PullDown;
|
||||
import com.njcn.common.utils.EncryptionUtil;
|
||||
import com.njcn.gather.device.mapper.PqStandardDevMapper;
|
||||
import com.njcn.gather.device.pojo.enums.CheckStateEnum;
|
||||
import com.njcn.gather.device.pojo.enums.CommonEnum;
|
||||
import com.njcn.gather.device.pojo.param.PqStandardDevParam;
|
||||
import com.njcn.gather.device.pojo.po.PqStandardDev;
|
||||
import com.njcn.gather.device.pojo.po.PqStandardDevGain;
|
||||
import com.njcn.gather.device.pojo.vo.PqStandardDevExcel;
|
||||
import com.njcn.gather.device.pojo.vo.PqStandardDevVO;
|
||||
import com.njcn.gather.device.pojo.vo.PreDetection;
|
||||
import com.njcn.gather.device.service.IPqStandardDevGainService;
|
||||
import com.njcn.gather.device.service.IPqStandardDevService;
|
||||
import com.njcn.gather.plan.mapper.AdPlanStandardDevMapper;
|
||||
import com.njcn.gather.plan.pojo.po.AdPlan;
|
||||
import com.njcn.gather.plan.pojo.po.AdPlanStandardDev;
|
||||
import com.njcn.gather.plan.service.IAdPlanService;
|
||||
import com.njcn.gather.plan.service.IAdPlanStandardDevService;
|
||||
import com.njcn.gather.pojo.enums.DetectionResponseEnum;
|
||||
import com.njcn.gather.system.dictionary.pojo.po.DictData;
|
||||
@@ -64,8 +61,7 @@ public class PqStandardDevServiceImpl extends ServiceImpl<PqStandardDevMapper, P
|
||||
private final IDevTypeService devTypeService;
|
||||
private final IDictDataService dictDataService;
|
||||
private final IDictTypeService dictTypeService;
|
||||
private final AdPlanStandardDevMapper adPlanStandardDevMapper;
|
||||
private final IAdPlanStandardDevService adPlanStandardDevService;
|
||||
private final IPqStandardDevGainService pqStandardDevGainService;
|
||||
|
||||
@Override
|
||||
public Page<PqStandardDev> listPqStandardDevs(PqStandardDevParam.QueryParam queryParam) {
|
||||
@@ -73,18 +69,23 @@ public class PqStandardDevServiceImpl extends ServiceImpl<PqStandardDevMapper, P
|
||||
wrapper.like(StrUtil.isNotBlank(queryParam.getName()), "name", queryParam.getName())
|
||||
.eq(StrUtil.isNotBlank(queryParam.getManufacturer()), "manufacturer", queryParam.getManufacturer())
|
||||
.eq(StrUtil.isNotBlank(queryParam.getDevType()), "dev_type", queryParam.getDevType())
|
||||
.eq("state", DataStateEnum.ENABLE.getCode());
|
||||
.eq("state", DataStateEnum.ENABLE.getCode())
|
||||
.orderByDesc("create_time");
|
||||
return this.page(new Page<>(PageFactory.getPageNum(queryParam), PageFactory.getPageSize(queryParam)), wrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PqStandardDev getPqStandardDevById(String id) {
|
||||
public PqStandardDevVO getPqStandardDevById(String id) {
|
||||
PqStandardDev standardDev = this.getById(id);
|
||||
PqStandardDevVO pqStandardDevVO = BeanUtil.copyProperties(standardDev, PqStandardDevVO.class);
|
||||
if (standardDev.getEncryptionFlag() == 1) {
|
||||
standardDev.setSeries(EncryptionUtil.decoderString(1, standardDev.getSeries()));
|
||||
standardDev.setDevKey(EncryptionUtil.decoderString(1, standardDev.getDevKey()));
|
||||
pqStandardDevVO.setSeries(EncryptionUtil.decoderString(1, standardDev.getSeries()));
|
||||
pqStandardDevVO.setDevKey(EncryptionUtil.decoderString(1, standardDev.getDevKey()));
|
||||
}
|
||||
return standardDev;
|
||||
|
||||
List<PqStandardDevGain> gainList = pqStandardDevGainService.list(id);
|
||||
pqStandardDevVO.setGainList(gainList);
|
||||
return pqStandardDevVO;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -159,10 +160,10 @@ public class PqStandardDevServiceImpl extends ServiceImpl<PqStandardDevMapper, P
|
||||
this.importData(contrastDevExcelList);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PqStandardDev> listByPlanId(String planId) {
|
||||
return adPlanStandardDevMapper.listByPlanId(Collections.singletonList(planId));
|
||||
}
|
||||
// @Override
|
||||
// public List<PqStandardDev> listByPlanId(String planId) {
|
||||
// return adPlanStandardDevMapper.listByPlanId(Collections.singletonList(planId));
|
||||
// }
|
||||
|
||||
@Override
|
||||
public List<PreDetection> listStandardDevPreDetection(List<String> ids) {
|
||||
@@ -311,7 +312,7 @@ public class PqStandardDevServiceImpl extends ServiceImpl<PqStandardDevMapper, P
|
||||
|
||||
@Override
|
||||
public List<PqStandardDev> canBindingList() {
|
||||
List<String> excludeStandardDevIds = new ArrayList<>();
|
||||
/*List<String> excludeStandardDevIds = new ArrayList<>();
|
||||
// 获取所有已绑定的标准设备
|
||||
List<AdPlanStandardDev> boundList = adPlanStandardDevService.list();
|
||||
if (CollectionUtil.isNotEmpty(boundList)) {
|
||||
@@ -350,13 +351,13 @@ public class PqStandardDevServiceImpl extends ServiceImpl<PqStandardDevMapper, P
|
||||
.collect(Collectors.toList());
|
||||
excludeStandardDevIds = excludeBoundList.stream().map(AdPlanStandardDev::getStandardDevId).collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
}*/
|
||||
List<PqStandardDev> list = this.lambdaQuery()
|
||||
.eq(PqStandardDev::getState, DataStateEnum.ENABLE.getCode())
|
||||
.list();
|
||||
for (PqStandardDev pqStandardDev : list) {
|
||||
/*for (PqStandardDev pqStandardDev : list) {
|
||||
pqStandardDev.setDisabled(excludeStandardDevIds.contains(pqStandardDev.getId()));
|
||||
}
|
||||
}*/
|
||||
return list;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.njcn.gather.dip.mapper;
|
||||
|
||||
import com.github.yulichang.base.MPJBaseMapper;
|
||||
import com.njcn.gather.dip.pojo.po.PqDipData;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @date 2026-04-09
|
||||
*/
|
||||
public interface PqDipDataMapper extends MPJBaseMapper<PqDipData> {
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package com.njcn.gather.dip.pojo.po;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 电压暂降数据
|
||||
*
|
||||
* @author caozehui
|
||||
* @date 2026-04-09
|
||||
*/
|
||||
@Data
|
||||
@TableName(value = "ad_harmonic_xx")
|
||||
public class PqDipData {
|
||||
|
||||
/**
|
||||
* 主键ID
|
||||
*/
|
||||
private String id;
|
||||
|
||||
/**
|
||||
* 起始时间戳
|
||||
*/
|
||||
private LocalDateTime startTime;
|
||||
|
||||
/**
|
||||
* 残余电压,单位:%Ur
|
||||
*/
|
||||
private Double residualVoltage;
|
||||
|
||||
/**
|
||||
* 持续时间,单位:ms
|
||||
*/
|
||||
private Integer durationMs;
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.njcn.gather.dip.pojo.po.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @data 2026-04-16
|
||||
*/
|
||||
@Data
|
||||
public class DipPoint {
|
||||
|
||||
/**
|
||||
* 残余电压,单位:%Ur
|
||||
*/
|
||||
private Double residualVoltage;
|
||||
|
||||
/**
|
||||
* 持续时间,单位:ms
|
||||
*/
|
||||
private Integer durationMs;
|
||||
|
||||
/**
|
||||
* 0为不耐受,1为耐受
|
||||
*/
|
||||
private Boolean tolerant;
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.njcn.gather.dip.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.njcn.gather.dip.pojo.po.PqDipData;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @date 2026-04-09
|
||||
*/
|
||||
public interface IPqDipDataService extends IService<PqDipData> {
|
||||
|
||||
/**
|
||||
* 查询指定变频器所对应的电压暂降数据
|
||||
*
|
||||
* @param suffix 表后缀
|
||||
* @return
|
||||
*/
|
||||
List<PqDipData> listDipData(Integer suffix);
|
||||
|
||||
void clearAllData(Integer suffix);
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package com.njcn.gather.dip.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.njcn.db.mybatisplus.handler.DynamicTableNameHandler;
|
||||
import com.njcn.gather.dip.mapper.PqDipDataMapper;
|
||||
import com.njcn.gather.dip.pojo.po.PqDipData;
|
||||
import com.njcn.gather.dip.service.IPqDipDataService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @date 2026-04-09
|
||||
*/
|
||||
@Service
|
||||
public class PqDipDataServiceImpl extends ServiceImpl<PqDipDataMapper, PqDipData> implements IPqDipDataService {
|
||||
@Override
|
||||
public List<PqDipData> listDipData(Integer suffix) {
|
||||
DynamicTableNameHandler.setTableName("pq_dip_data_" + suffix);
|
||||
LambdaQueryChainWrapper<PqDipData> wrapper = this.lambdaQuery().orderByAsc(PqDipData::getStartTime);
|
||||
List<PqDipData> result = wrapper.list();
|
||||
DynamicTableNameHandler.remove();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearAllData(Integer suffix) {
|
||||
DynamicTableNameHandler.setTableName("pq_dip_data_" + suffix);
|
||||
this.remove(null);
|
||||
DynamicTableNameHandler.remove();
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.njcn.common.pojo.enums.common.DataStateEnum;
|
||||
import com.njcn.common.pojo.exception.BusinessException;
|
||||
import com.njcn.gather.detection.pojo.enums.DetectionCodeEnum;
|
||||
import com.njcn.gather.err.mapper.PqErrSysMapper;
|
||||
import com.njcn.gather.err.pojo.param.PqErrSysDtlsParam;
|
||||
import com.njcn.gather.err.pojo.param.PqErrSysParam;
|
||||
@@ -18,6 +19,7 @@ import com.njcn.gather.err.pojo.vo.PqErrSysDtlsVO;
|
||||
import com.njcn.gather.err.service.IPqErrSysDtlsService;
|
||||
import com.njcn.gather.err.service.IPqErrSysService;
|
||||
import com.njcn.gather.pojo.enums.DetectionResponseEnum;
|
||||
import com.njcn.gather.report.pojo.enums.PowerIndexEnum;
|
||||
import com.njcn.gather.system.dictionary.pojo.po.DictData;
|
||||
import com.njcn.gather.system.dictionary.pojo.po.DictTree;
|
||||
import com.njcn.gather.system.dictionary.service.IDictDataService;
|
||||
@@ -219,7 +221,9 @@ public class PqErrSysServiceImpl extends ServiceImpl<PqErrSysMapper, PqErrSys> i
|
||||
List<DictTree> parentDictTreeList = dictTreeService.listByIds(pids);
|
||||
Map<String, String> map = new HashMap<>();
|
||||
parentDictTreeList.forEach(dictTree -> {
|
||||
map.put(dictTree.getId(), dictTree.getName());
|
||||
if(!dictTree.getCode().equals(PowerIndexEnum.VOLTAGE.getKey())&&!dictTree.getCode().equals(PowerIndexEnum.P.getKey())){
|
||||
map.put(dictTree.getId(), dictTree.getName());
|
||||
}
|
||||
});
|
||||
return map;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.njcn.gather.freqConverter.config;
|
||||
|
||||
import lombok.Data;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @data 2026-04-15
|
||||
*/
|
||||
@Data
|
||||
@Component
|
||||
@ConfigurationProperties(prefix = "freq-converter")
|
||||
public class FreqConverterConfig {
|
||||
private Long schedulePeriod;
|
||||
private Integer tolerant;
|
||||
private Integer dt;
|
||||
private Integer direction;
|
||||
private Integer allowErrorDuration;
|
||||
private Double allowErrorResidualVoltage;
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
package com.njcn.gather.freqConverter.controller;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.njcn.common.pojo.annotation.OperateInfo;
|
||||
import com.njcn.common.pojo.constant.OperateType;
|
||||
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
|
||||
import com.njcn.common.pojo.response.HttpResult;
|
||||
import com.njcn.common.utils.LogUtil;
|
||||
import com.njcn.gather.freqConverter.pojo.param.PqFreqConverterParam;
|
||||
import com.njcn.gather.freqConverter.pojo.po.PqFreqConverterConfig;
|
||||
import com.njcn.gather.freqConverter.pojo.vo.TolerantPointVO;
|
||||
import com.njcn.gather.freqConverter.service.IFreqConverterService;
|
||||
import com.njcn.gather.freqConverter.service.IPqFreqConverterConfigService;
|
||||
import com.njcn.web.controller.BaseController;
|
||||
import com.njcn.web.utils.HttpResultUtil;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @data 2026-04-13
|
||||
*/
|
||||
@Slf4j
|
||||
@Api(tags = "变频器")
|
||||
@RestController
|
||||
@RequestMapping("/freqConverter")
|
||||
@RequiredArgsConstructor
|
||||
public class FreqConverterController extends BaseController {
|
||||
private final IFreqConverterService freqConverterService;
|
||||
private final IPqFreqConverterConfigService pqFreqConverterConfigService;
|
||||
|
||||
|
||||
@OperateInfo
|
||||
@PostMapping("/list")
|
||||
@ApiOperation("分页查询变频器列表")
|
||||
@ApiImplicitParam(name = "queryParam", value = "查询参数", required = true)
|
||||
public HttpResult<Page<PqFreqConverterConfig>> list(@RequestBody @Validated PqFreqConverterParam.QueryParam queryParam) {
|
||||
String methodDescribe = getMethodDescribe("list");
|
||||
LogUtil.njcnDebug(log, "{},查询数据为:{}", methodDescribe, queryParam);
|
||||
Page<PqFreqConverterConfig> result = pqFreqConverterConfigService.listPqFreqConverterConfigs(queryParam);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
|
||||
}
|
||||
|
||||
@OperateInfo(operateType = OperateType.ADD)
|
||||
@PostMapping("/add")
|
||||
@ApiOperation("新增变频器")
|
||||
@ApiImplicitParam(name = "pqDevParam", value = "被检设备", required = true)
|
||||
public HttpResult<Boolean> add(@RequestBody @Validated PqFreqConverterParam param) {
|
||||
String methodDescribe = getMethodDescribe("add");
|
||||
LogUtil.njcnDebug(log, "{},新增数据为:{}", methodDescribe, param);
|
||||
boolean result = pqFreqConverterConfigService.addPqFreqConverterConfig(param);
|
||||
if (result) {
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, methodDescribe);
|
||||
} else {
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, false, methodDescribe);
|
||||
}
|
||||
}
|
||||
|
||||
@OperateInfo(operateType = OperateType.UPDATE)
|
||||
@PostMapping("/update")
|
||||
@ApiOperation("修改变频器")
|
||||
@ApiImplicitParam(name = "updateParam", value = "被检设备", required = true)
|
||||
public HttpResult<Boolean> update(@RequestBody @Validated PqFreqConverterParam.UpdateParam param) {
|
||||
String methodDescribe = getMethodDescribe("update");
|
||||
LogUtil.njcnDebug(log, "{},修改数据为:{}", methodDescribe, param);
|
||||
boolean result = pqFreqConverterConfigService.updatePqFreqConverterConfig(param);
|
||||
if (result) {
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, methodDescribe);
|
||||
} else {
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, false, methodDescribe);
|
||||
}
|
||||
}
|
||||
|
||||
@OperateInfo(operateType = OperateType.DELETE)
|
||||
@PostMapping("/delete")
|
||||
@ApiOperation("删除变频器")
|
||||
@ApiImplicitParam(name = "param", value = "删除参数", required = true)
|
||||
public HttpResult<Boolean> delete(@RequestBody @Validated List<String> ids) {
|
||||
String methodDescribe = getMethodDescribe("delete");
|
||||
LogUtil.njcnDebug(log, "{},删除ID数据为:{}", methodDescribe, String.join(StrUtil.COMMA, ids));
|
||||
boolean result = pqFreqConverterConfigService.deletePqFreqConverterConfig(ids);
|
||||
if (result) {
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, methodDescribe);
|
||||
} else {
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, false, methodDescribe);
|
||||
}
|
||||
}
|
||||
|
||||
@GetMapping("/result")
|
||||
@ApiOperation("查询变频器测试结果")
|
||||
@ApiImplicitParam(name = "param", value = "查询参数", required = true)
|
||||
public HttpResult<List<TolerantPointVO>> result(@RequestParam("converterId") String converterId) {
|
||||
String methodDescribe = getMethodDescribe("result");
|
||||
LogUtil.njcnDebug(log, "{},查询ID数据为:{}", methodDescribe, converterId);
|
||||
List<TolerantPointVO> tolerantPoints = freqConverterService.getDipPoints(converterId);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, tolerantPoints, methodDescribe);
|
||||
}
|
||||
|
||||
// @GetMapping("/scurve")
|
||||
// @ApiOperation("获取绘制特性曲线的point点")
|
||||
// @ApiImplicitParam(name = "converterId", value = "变频器ID", required = true)
|
||||
// public HttpResult<List<TolerantPointVO>> getScurvePoints(@RequestParam("converterId") String converterId) {
|
||||
// String methodDescribe = getMethodDescribe("getScurvePoints");
|
||||
// LogUtil.njcnDebug(log, "{},查询ID数据为:{}", methodDescribe, converterId);
|
||||
// List<TolerantPointVO> tolerantPoints = freqConverterService.getFeaturesScurvePoints(converterId);
|
||||
// return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, tolerantPoints, methodDescribe);
|
||||
// }
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.njcn.gather.freqConverter.mapper;
|
||||
|
||||
import com.github.yulichang.base.MPJBaseMapper;
|
||||
import com.njcn.gather.freqConverter.pojo.po.FreqConverterStatus;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @data 2026-04-07
|
||||
*/
|
||||
public interface FreqConverterStatusMapper extends MPJBaseMapper<FreqConverterStatus> {
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.njcn.gather.freqConverter.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.njcn.gather.freqConverter.pojo.po.PqFreqConverterConfig;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @data 2026-04-08
|
||||
*/
|
||||
public interface PqFreqConverterConfigMapper extends BaseMapper<PqFreqConverterConfig> {
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.njcn.gather.freqConverter.mapper;
|
||||
|
||||
import com.github.yulichang.base.MPJBaseMapper;
|
||||
import com.njcn.gather.freqConverter.pojo.po.PqFreqConverterTestRes;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @data 2026-04-14
|
||||
*/
|
||||
public interface PqFreqConverterTestResMapper extends MPJBaseMapper<PqFreqConverterTestRes> {
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
package com.njcn.gather.freqConverter.pojo.param;
|
||||
|
||||
import com.njcn.common.pojo.constant.PatternRegex;
|
||||
import com.njcn.gather.pojo.constant.DetectionValidMessage;
|
||||
import com.njcn.web.pojo.param.BaseParam;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.Pattern;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @data 2026-04-13
|
||||
*/
|
||||
@Data
|
||||
public class PqFreqConverterParam {
|
||||
@ApiModelProperty(value = "名称", required = true)
|
||||
private String name;
|
||||
|
||||
@ApiModelProperty(value = "电脑串口名", required = true)
|
||||
private String portName;
|
||||
|
||||
@ApiModelProperty(value = "变频器设置从机地址", required = true)
|
||||
private Integer slaveAddress;
|
||||
|
||||
@ApiModelProperty(value = "变频器设置波特率", required = true)
|
||||
private Integer baudRate;
|
||||
|
||||
@ApiModelProperty(value = "奇偶校验类型: None, Even, Odd", required = true)
|
||||
private String parity;
|
||||
|
||||
@ApiModelProperty(value = "变频器数据位", required = true)
|
||||
private Integer dataBits;
|
||||
|
||||
@ApiModelProperty(value = "变频器停止位,当前只支持 1 或 2", required = true)
|
||||
private Integer stopBits;
|
||||
|
||||
@ApiModelProperty(value = "串口读写超时,单位毫秒", required = true)
|
||||
private Integer timeoutMs;
|
||||
private Integer testStatus;
|
||||
|
||||
/**
|
||||
* 分页查询实体
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public static class QueryParam extends BaseParam {
|
||||
@ApiModelProperty(value = "名称", required = true)
|
||||
private String name;
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新操作实体
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public static class UpdateParam extends PqFreqConverterParam {
|
||||
|
||||
@ApiModelProperty(value = "id", required = true)
|
||||
@NotBlank(message = DetectionValidMessage.ID_NOT_BLANK)
|
||||
@Pattern(regexp = PatternRegex.SYSTEM_ID, message = DetectionValidMessage.ID_FORMAT_ERROR)
|
||||
private String id;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package com.njcn.gather.freqConverter.pojo.po;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @data 2026-04-07
|
||||
*/
|
||||
@Data
|
||||
@TableName(value = "ad_harmonic_xx")
|
||||
public class FreqConverterStatus {
|
||||
|
||||
/**
|
||||
* 主键ID
|
||||
*/
|
||||
private String id;
|
||||
|
||||
private Integer slaveAddress;
|
||||
|
||||
private Integer statusWord1;
|
||||
|
||||
private String statusWord1Hex;
|
||||
|
||||
/**
|
||||
* 状态记录时刻(时间戳)
|
||||
*/
|
||||
private LocalDateTime timestamp;
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
package com.njcn.gather.freqConverter.pojo.po;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.njcn.db.mybatisplus.bo.BaseEntity;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 变频器配置实体类
|
||||
*/
|
||||
@Data
|
||||
@TableName("pq_freq_converter_config")
|
||||
public class PqFreqConverterConfig extends BaseEntity {
|
||||
|
||||
/**
|
||||
* 主键ID
|
||||
*/
|
||||
private String id;
|
||||
|
||||
/**
|
||||
* 变频器名称
|
||||
*/
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 电脑串口名,如COM1
|
||||
*/
|
||||
private String portName;
|
||||
|
||||
/**
|
||||
* 变频器设置从机地址,范围1~127
|
||||
*/
|
||||
private Integer slaveAddress;
|
||||
|
||||
/**
|
||||
* 变频器设置波特率,如19200
|
||||
*/
|
||||
private Integer baudRate;
|
||||
|
||||
/**
|
||||
* 奇偶校验类型: None, Even, Odd
|
||||
*/
|
||||
private String parity;
|
||||
|
||||
/**
|
||||
* 变频器数据位
|
||||
*/
|
||||
private Integer dataBits;
|
||||
|
||||
/**
|
||||
* 变频器停止位,当前只支持 1 或 2
|
||||
*/
|
||||
private Integer stopBits;
|
||||
|
||||
/**
|
||||
* 串口读写超时,单位毫秒
|
||||
*/
|
||||
private Integer timeoutMs;
|
||||
|
||||
/**
|
||||
* 数据表后缀
|
||||
*/
|
||||
private Integer suffix;
|
||||
|
||||
/**
|
||||
* 检测状态,0未检测,1检测完成
|
||||
*/
|
||||
private Integer testStatus;
|
||||
|
||||
/**
|
||||
* 状态:0-删除 1-正常
|
||||
*/
|
||||
private Integer state;
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package com.njcn.gather.freqConverter.pojo.po;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @data 2026-04-14
|
||||
*/
|
||||
@Data
|
||||
@TableName(value = "ad_harmonic_xx")
|
||||
public class PqFreqConverterTestRes {
|
||||
/**
|
||||
* 主键ID
|
||||
*/
|
||||
private String id;
|
||||
|
||||
/**
|
||||
* 残余电压,单位:%Ur
|
||||
*/
|
||||
private Double residualVoltage;
|
||||
|
||||
/**
|
||||
* 持续时间,单位:ms
|
||||
*/
|
||||
private Integer durationMs;
|
||||
|
||||
/**
|
||||
* 0为不耐受,1为耐受,2为特性曲线点
|
||||
*/
|
||||
private Integer tolerant;
|
||||
|
||||
/**
|
||||
* 时间
|
||||
*/
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss.SSS", timezone = "GMT+8")
|
||||
private LocalDateTime time;
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package com.njcn.gather.freqConverter.pojo.vo;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @data 2026-04-13
|
||||
*/
|
||||
@Data
|
||||
public class TolerantPointVO {
|
||||
/**
|
||||
* 持续时间,单位ms
|
||||
*/
|
||||
private Integer durationMs;
|
||||
|
||||
/**
|
||||
* 残余电压,单位:%Ur
|
||||
*/
|
||||
private Double residualVoltage;
|
||||
|
||||
/**
|
||||
* 是否耐受。0-否,1-是,2-表示特性曲线点
|
||||
*/
|
||||
private Integer tolerant;
|
||||
|
||||
/**
|
||||
* 时间
|
||||
*/
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss.SSS", timezone = "GMT+8")
|
||||
private LocalDateTime time;
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
package com.njcn.gather.freqConverter.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.njcn.gather.freqConverter.pojo.po.FreqConverterStatus;
|
||||
import com.njcn.gather.freqConverter.pojo.vo.TolerantPointVO;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @data 2026-04-07
|
||||
*/
|
||||
public interface IFreqConverterService extends IService<FreqConverterStatus> {
|
||||
|
||||
|
||||
/**
|
||||
* 保存变频器状态数据
|
||||
*
|
||||
* @param suffix 表后缀
|
||||
* @param status 变频器状态数据
|
||||
* @return 是否保存成功
|
||||
*/
|
||||
boolean saveFreqConverterStatus(Integer suffix, FreqConverterStatus status);
|
||||
|
||||
|
||||
/**
|
||||
* 查询指定变频器的状态历史
|
||||
*
|
||||
* @param converterId 变频器ID
|
||||
* @return 状态数据列表
|
||||
*/
|
||||
List<FreqConverterStatus> listStatusData(String converterId);
|
||||
|
||||
/**
|
||||
* 清空所有数据
|
||||
*
|
||||
* @param converterId 变频器ID
|
||||
* @return
|
||||
*/
|
||||
void clearAllData(Integer converterId);
|
||||
|
||||
/**
|
||||
* 根据设备暂降数据判断变频器是否耐受
|
||||
*
|
||||
* @param converterId 变频器Id
|
||||
* @return 是否耐受
|
||||
*/
|
||||
List<TolerantPointVO> getDipPoints(String converterId);
|
||||
|
||||
List<FreqConverterStatus> getDipDurationStatusData(Integer suffix, LocalDateTime startTime, LocalDateTime endTime);
|
||||
|
||||
FreqConverterStatus getLastStatusData(Integer suffix, LocalDateTime startTime);
|
||||
|
||||
/**
|
||||
* 获取变频器特性曲线点
|
||||
*
|
||||
* @param converterId 变频器ID
|
||||
* @return
|
||||
*/
|
||||
List<TolerantPointVO> getFeaturesScurvePoints(String converterId);
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.njcn.gather.freqConverter.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.njcn.gather.freqConverter.pojo.param.PqFreqConverterParam;
|
||||
import com.njcn.gather.freqConverter.pojo.po.PqFreqConverterConfig;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @data 2026-04-08
|
||||
*/
|
||||
public interface IPqFreqConverterConfigService extends IService<PqFreqConverterConfig> {
|
||||
Page<PqFreqConverterConfig> listPqFreqConverterConfigs(PqFreqConverterParam.QueryParam queryParam);
|
||||
|
||||
Integer getSuffix(String converterId);
|
||||
|
||||
boolean addPqFreqConverterConfig(PqFreqConverterParam param);
|
||||
|
||||
boolean updatePqFreqConverterConfig(PqFreqConverterParam.UpdateParam param);
|
||||
|
||||
boolean deletePqFreqConverterConfig(List<String> ids);
|
||||
|
||||
boolean updateTestStatus(String converterId, Integer testStatus);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package com.njcn.gather.freqConverter.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.njcn.gather.freqConverter.pojo.po.PqFreqConverterTestRes;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @data 2026-04-14
|
||||
*/
|
||||
public interface IPqFreqConverterTestResService extends IService<PqFreqConverterTestRes> {
|
||||
/**
|
||||
* 清空所有数据
|
||||
*
|
||||
* @param suffix 表后缀
|
||||
* @return
|
||||
*/
|
||||
void clearAllData(Integer suffix);
|
||||
|
||||
/**
|
||||
* 新增结果记录
|
||||
*
|
||||
* @param suffix 表后缀
|
||||
* @param testResList 结果数据
|
||||
* @return 是否成功
|
||||
*/
|
||||
boolean saveTestRes(Integer suffix, List<PqFreqConverterTestRes> testResList);
|
||||
|
||||
/**
|
||||
* 更新结果记录
|
||||
*
|
||||
* @param suffix 表后缀
|
||||
* @param testResList 结果数据
|
||||
* @return 是否成功
|
||||
*/
|
||||
boolean updateTestRes(Integer suffix, List<PqFreqConverterTestRes> testResList);
|
||||
|
||||
/**
|
||||
* 查询结果记录
|
||||
*
|
||||
* @param suffix 表后缀
|
||||
* @return 结果列表
|
||||
*/
|
||||
List<PqFreqConverterTestRes> listTestRes(Integer suffix);
|
||||
|
||||
PqFreqConverterTestRes getLastByDuration(Integer suffix, String id, Integer durationMs);
|
||||
|
||||
PqFreqConverterTestRes getLastByResidualVoltage(Integer suffix, String id, Double residualVoltage);
|
||||
}
|
||||
@@ -0,0 +1,172 @@
|
||||
package com.njcn.gather.freqConverter.service.impl;
|
||||
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.njcn.db.mybatisplus.handler.DynamicTableNameHandler;
|
||||
import com.njcn.gather.dip.service.IPqDipDataService;
|
||||
import com.njcn.gather.freqConverter.mapper.FreqConverterStatusMapper;
|
||||
import com.njcn.gather.freqConverter.pojo.po.FreqConverterStatus;
|
||||
import com.njcn.gather.freqConverter.pojo.po.PqFreqConverterTestRes;
|
||||
import com.njcn.gather.freqConverter.pojo.vo.TolerantPointVO;
|
||||
import com.njcn.gather.freqConverter.service.IFreqConverterService;
|
||||
import com.njcn.gather.freqConverter.service.IPqFreqConverterConfigService;
|
||||
import com.njcn.gather.freqConverter.service.IPqFreqConverterTestResService;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 变频器状态数据Service实现类
|
||||
* <p>
|
||||
* 实现变频器状态数据的存储、查询和清理功能。
|
||||
* 当数据量超过阈值时,自动清理无效或过期数据,避免内存和数据库资源浪费。
|
||||
* </p>
|
||||
*
|
||||
* @author CN_Gather Detection Team
|
||||
* @version 1.0
|
||||
* @since 2026
|
||||
*/
|
||||
@Service
|
||||
@AllArgsConstructor
|
||||
public class FreqConverterServiceImpl extends ServiceImpl<FreqConverterStatusMapper, FreqConverterStatus> implements IFreqConverterService {
|
||||
private final IPqFreqConverterConfigService pqFreqConverterConfigService;
|
||||
private final IPqDipDataService dipDataService;
|
||||
private final IPqFreqConverterTestResService pqFreqConverterTestResService;
|
||||
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean saveFreqConverterStatus(Integer suffix, FreqConverterStatus status) {
|
||||
if (status.getId() == null) {
|
||||
status.setId(IdUtil.fastSimpleUUID());
|
||||
}
|
||||
DynamicTableNameHandler.setTableName(PqFreqConverterConfigServiceImpl.PQ_FREQ_CONVERTER_STATUS_TB_PREFIX + suffix);
|
||||
boolean result = this.save(status);
|
||||
DynamicTableNameHandler.remove();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<FreqConverterStatus> listStatusData(String converterId) {
|
||||
Integer suffix = pqFreqConverterConfigService.getSuffix(converterId);
|
||||
|
||||
DynamicTableNameHandler.setTableName(PqFreqConverterConfigServiceImpl.PQ_FREQ_CONVERTER_STATUS_TB_PREFIX + suffix);
|
||||
LambdaQueryChainWrapper<FreqConverterStatus> wrapper = this.lambdaQuery().orderByAsc(FreqConverterStatus::getTimestamp);
|
||||
List<FreqConverterStatus> result = wrapper.list();
|
||||
DynamicTableNameHandler.remove();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void clearAllData(Integer suffix) {
|
||||
DynamicTableNameHandler.setTableName(PqFreqConverterConfigServiceImpl.PQ_FREQ_CONVERTER_STATUS_TB_PREFIX + suffix);
|
||||
this.remove(null);
|
||||
DynamicTableNameHandler.remove();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TolerantPointVO> getDipPoints(String converterId) {
|
||||
Integer suffix = pqFreqConverterConfigService.getSuffix(converterId);
|
||||
|
||||
DynamicTableNameHandler.setTableName(PqFreqConverterConfigServiceImpl.PQ_FREQ_CONVERTER_TEST_RES_TB_PREFIX + suffix);
|
||||
List<PqFreqConverterTestRes> pqFreqConverterTestResList = pqFreqConverterTestResService.list();
|
||||
DynamicTableNameHandler.remove();
|
||||
List<TolerantPointVO> result = pqFreqConverterTestResList.stream().map(item -> {
|
||||
TolerantPointVO tolerantPointVO = new TolerantPointVO();
|
||||
tolerantPointVO.setDurationMs(item.getDurationMs());
|
||||
tolerantPointVO.setResidualVoltage(item.getResidualVoltage());
|
||||
tolerantPointVO.setTolerant(item.getTolerant());
|
||||
tolerantPointVO.setTime(item.getTime());
|
||||
return tolerantPointVO;
|
||||
})
|
||||
.sorted(Comparator.comparingInt(TolerantPointVO::getDurationMs))
|
||||
.sorted(Comparator.comparingDouble(TolerantPointVO::getResidualVoltage)).collect(Collectors.toList());
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<FreqConverterStatus> getDipDurationStatusData(Integer suffix, LocalDateTime startTime, LocalDateTime endTime) {
|
||||
DynamicTableNameHandler.setTableName(PqFreqConverterConfigServiceImpl.PQ_FREQ_CONVERTER_STATUS_TB_PREFIX + suffix);
|
||||
List<FreqConverterStatus> result = this.lambdaQuery()
|
||||
.between(FreqConverterStatus::getTimestamp, startTime, endTime)
|
||||
.orderByAsc(FreqConverterStatus::getTimestamp)
|
||||
.list();
|
||||
DynamicTableNameHandler.remove();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FreqConverterStatus getLastStatusData(Integer suffix, LocalDateTime startTime) {
|
||||
DynamicTableNameHandler.setTableName(PqFreqConverterConfigServiceImpl.PQ_FREQ_CONVERTER_STATUS_TB_PREFIX + suffix);
|
||||
FreqConverterStatus one = this.lambdaQuery().le(FreqConverterStatus::getTimestamp, startTime)
|
||||
.orderByDesc(FreqConverterStatus::getTimestamp)
|
||||
.last("limit 1")
|
||||
.one();
|
||||
DynamicTableNameHandler.remove();
|
||||
return one;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TolerantPointVO> getFeaturesScurvePoints(String converterId) {
|
||||
List<TolerantPointVO> dipPoints = this.getDipPoints(converterId);
|
||||
if (dipPoints == null || dipPoints.isEmpty()) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
Map<Integer, List<TolerantPointVO>> durationPointMap = dipPoints.stream()
|
||||
.collect(Collectors.groupingBy(TolerantPointVO::getDurationMs, TreeMap::new, Collectors.toList()));
|
||||
if (durationPointMap.size() < 2) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
List<TolerantPointVO> result = new ArrayList<>();
|
||||
|
||||
TolerantPointVO firstPoint = new TolerantPointVO();
|
||||
|
||||
List<Integer> keyList = durationPointMap.keySet().stream().collect(Collectors.toList());
|
||||
Integer i1 = keyList.get(0);
|
||||
List<TolerantPointVO> tolerantPointVOS1 = durationPointMap.get(i1);
|
||||
Collections.sort(tolerantPointVOS1, Comparator.comparing(TolerantPointVO::getResidualVoltage));
|
||||
TolerantPointVO tolerantPointVO1 = tolerantPointVOS1.get(0);
|
||||
|
||||
Integer i2 = keyList.get(1);
|
||||
List<TolerantPointVO> tolerantPointVOS2 = durationPointMap.get(i2);
|
||||
Collections.sort(tolerantPointVOS2, Comparator.comparing(TolerantPointVO::getResidualVoltage));
|
||||
TolerantPointVO tolerantPointVO2 = tolerantPointVOS2.get(0);
|
||||
|
||||
firstPoint.setDurationMs((i1 + i2) / 2);
|
||||
firstPoint.setResidualVoltage((tolerantPointVO1.getResidualVoltage() + tolerantPointVO2.getResidualVoltage()) / 2D);
|
||||
firstPoint.setTolerant(2);
|
||||
result.add(firstPoint);
|
||||
|
||||
durationPointMap.entrySet().stream()
|
||||
.forEach(entry -> {
|
||||
List<TolerantPointVO> sameDurationPoints = entry.getValue().stream()
|
||||
.sorted(Comparator.comparing(TolerantPointVO::getResidualVoltage, Comparator.reverseOrder()))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
for (int index = 0; index < sameDurationPoints.size() - 1; index++) {
|
||||
TolerantPointVO currentPoint = sameDurationPoints.get(index);
|
||||
TolerantPointVO nextPoint = sameDurationPoints.get(index + 1);
|
||||
if (!Objects.equals(currentPoint.getTolerant(), nextPoint.getTolerant())) {
|
||||
TolerantPointVO featurePoint = new TolerantPointVO();
|
||||
featurePoint.setDurationMs(entry.getKey());
|
||||
featurePoint.setResidualVoltage((currentPoint.getResidualVoltage() + nextPoint.getResidualVoltage()) / 2D);
|
||||
featurePoint.setTolerant(2);
|
||||
result.add(featurePoint);
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,136 @@
|
||||
package com.njcn.gather.freqConverter.service.impl;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.njcn.common.pojo.enums.common.DataStateEnum;
|
||||
import com.njcn.gather.freqConverter.mapper.PqFreqConverterConfigMapper;
|
||||
import com.njcn.gather.freqConverter.pojo.param.PqFreqConverterParam;
|
||||
import com.njcn.gather.freqConverter.pojo.po.PqFreqConverterConfig;
|
||||
import com.njcn.gather.freqConverter.service.IPqFreqConverterConfigService;
|
||||
import com.njcn.gather.storage.mapper.TableGenMapper;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @data 2026-04-08
|
||||
*/
|
||||
@Service
|
||||
@AllArgsConstructor
|
||||
public class PqFreqConverterConfigServiceImpl extends ServiceImpl<PqFreqConverterConfigMapper, PqFreqConverterConfig> implements IPqFreqConverterConfigService {
|
||||
private final TableGenMapper tableGenMapper;
|
||||
|
||||
/**
|
||||
* 表名前缀
|
||||
*/
|
||||
public static final String PQ_FREQ_CONVERTER_STATUS_TB_PREFIX = "pq_freq_converter_status_";
|
||||
public static final String PQ_DIP_DATA_TB_PREFIX = "pq_dip_data_";
|
||||
public static final String PQ_FREQ_CONVERTER_TEST_RES_TB_PREFIX = "pq_freq_converter_test_res_";
|
||||
|
||||
@Override
|
||||
public Page<PqFreqConverterConfig> listPqFreqConverterConfigs(PqFreqConverterParam.QueryParam queryParam) {
|
||||
QueryWrapper wrapper = new QueryWrapper<>();
|
||||
wrapper.like(StrUtil.isNotBlank(queryParam.getName()), "name", queryParam.getName());
|
||||
wrapper.eq("state", 1);
|
||||
return this.page(new Page<>(queryParam.getPageNum(), queryParam.getPageSize()), wrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getSuffix(String converterId) {
|
||||
PqFreqConverterConfig freqConverterConfig = this.lambdaQuery().eq(PqFreqConverterConfig::getId, converterId).one();
|
||||
return freqConverterConfig.getSuffix();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean addPqFreqConverterConfig(PqFreqConverterParam param) {
|
||||
// 建表
|
||||
PqFreqConverterConfig freqConverterConfig = this.lambdaQuery().orderByDesc(PqFreqConverterConfig::getSuffix)
|
||||
.last("limit 1").one();
|
||||
Integer maxSuffix = 1;
|
||||
if (ObjectUtil.isNotNull(freqConverterConfig)) {
|
||||
maxSuffix = freqConverterConfig.getSuffix() + 1;
|
||||
}
|
||||
|
||||
String tableSql = "CREATE TABLE `" + PQ_FREQ_CONVERTER_STATUS_TB_PREFIX + maxSuffix + "`(" +
|
||||
" `id` char(32) NOT NULL COMMENT '主键ID'," +
|
||||
" `slave_address` int(11) DEFAULT NULL COMMENT '从机地址'," +
|
||||
" `status_word1` int(11) DEFAULT NULL COMMENT '状态字1'," +
|
||||
" `status_word1_hex` varchar(20) DEFAULT NULL COMMENT '状态字1十六进制'," +
|
||||
" `timestamp` datetime(3) NOT NULL COMMENT '状态记录时刻(时间戳)'," +
|
||||
" PRIMARY KEY (`id`) USING BTREE" +
|
||||
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='变频器状态表';";
|
||||
tableGenMapper.genTable(tableSql);
|
||||
|
||||
tableSql = "CREATE TABLE `" + PQ_DIP_DATA_TB_PREFIX + maxSuffix + "` (" +
|
||||
" `id` char(32) NOT NULL COMMENT '主键ID'," +
|
||||
" `start_time` datetime(3) NOT NULL COMMENT '起始时间戳'," +
|
||||
" `residual_voltage` decimal(6,2) NOT NULL COMMENT '残余电压(%Ur)'," +
|
||||
" `duration_ms` int(11) NOT NULL COMMENT '持续时间(ms)'," +
|
||||
" PRIMARY KEY (`id`)" +
|
||||
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='电压暂降数据表';";
|
||||
tableGenMapper.genTable(tableSql);
|
||||
|
||||
tableSql = "CREATE TABLE `" + PQ_FREQ_CONVERTER_TEST_RES_TB_PREFIX + maxSuffix + "` (" +
|
||||
" `id` char(32) NOT NULL COMMENT '主键ID'," +
|
||||
" `residual_voltage` decimal(6,2) NOT NULL COMMENT '残余电压(%Ur)'," +
|
||||
" `duration_ms` int(11) NOT NULL COMMENT '持续时间(ms)'," +
|
||||
" `tolerant` tinyInt(1) NOT NULL COMMENT '0为不耐受,1为耐受,2为特征点'," +
|
||||
" `time` datetime(3) DEFAULT NULL COMMENT '时间',"+
|
||||
" PRIMARY KEY (`id`)" +
|
||||
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='变频器耐受实验结果';";
|
||||
tableGenMapper.genTable(tableSql);
|
||||
|
||||
PqFreqConverterConfig pqFreqConverterConfig = BeanUtil.copyProperties(param, PqFreqConverterConfig.class);
|
||||
pqFreqConverterConfig.setSuffix(maxSuffix);
|
||||
pqFreqConverterConfig.setTestStatus(0);
|
||||
pqFreqConverterConfig.setState(DataStateEnum.ENABLE.getCode());
|
||||
return this.save(pqFreqConverterConfig);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean updatePqFreqConverterConfig(PqFreqConverterParam.UpdateParam param) {
|
||||
PqFreqConverterConfig pqFreqConverterConfig = BeanUtil.copyProperties(param, PqFreqConverterConfig.class);
|
||||
return this.updateById(pqFreqConverterConfig);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean deletePqFreqConverterConfig(List<String> ids) {
|
||||
StringBuffer sql = new StringBuffer();
|
||||
sql.append("drop table if exists ");
|
||||
|
||||
List<PqFreqConverterConfig> pqFreqConverterConfigs = this.listByIds(ids);
|
||||
for (PqFreqConverterConfig pqFreqConverterConfig : pqFreqConverterConfigs) {
|
||||
Integer suffix = pqFreqConverterConfig.getSuffix();
|
||||
sql.append(PQ_FREQ_CONVERTER_STATUS_TB_PREFIX + suffix + ",")
|
||||
.append(PQ_DIP_DATA_TB_PREFIX + suffix + ",")
|
||||
.append(PQ_FREQ_CONVERTER_TEST_RES_TB_PREFIX + suffix + ",");
|
||||
}
|
||||
|
||||
sql.deleteCharAt(sql.length() - 1);
|
||||
// 删除表
|
||||
tableGenMapper.genTable(sql.toString());
|
||||
return this.lambdaUpdate()
|
||||
.in(CollectionUtil.isNotEmpty(ids), PqFreqConverterConfig::getId, ids)
|
||||
.set(PqFreqConverterConfig::getState, 0).update();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean updateTestStatus(String converterId, Integer testStatus) {
|
||||
return this.lambdaUpdate()
|
||||
.eq(PqFreqConverterConfig::getId, converterId)
|
||||
.set(PqFreqConverterConfig::getTestStatus, testStatus)
|
||||
.update();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
package com.njcn.gather.freqConverter.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.njcn.db.mybatisplus.handler.DynamicTableNameHandler;
|
||||
import com.njcn.gather.freqConverter.config.FreqConverterConfig;
|
||||
import com.njcn.gather.freqConverter.mapper.PqFreqConverterTestResMapper;
|
||||
import com.njcn.gather.freqConverter.pojo.po.PqFreqConverterTestRes;
|
||||
import com.njcn.gather.freqConverter.service.IPqFreqConverterTestResService;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @data 2026-04-14
|
||||
*/
|
||||
@Service
|
||||
@AllArgsConstructor
|
||||
public class PqFreqConverterTestResServiceImpl extends ServiceImpl<PqFreqConverterTestResMapper, PqFreqConverterTestRes> implements IPqFreqConverterTestResService {
|
||||
private final FreqConverterConfig freqConverterConfig;
|
||||
|
||||
@Override
|
||||
public void clearAllData(Integer suffix) {
|
||||
DynamicTableNameHandler.setTableName(PqFreqConverterConfigServiceImpl.PQ_FREQ_CONVERTER_TEST_RES_TB_PREFIX + suffix);
|
||||
this.remove(null);
|
||||
DynamicTableNameHandler.remove();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean saveTestRes(Integer suffix, List<PqFreqConverterTestRes> testResList) {
|
||||
DynamicTableNameHandler.setTableName(PqFreqConverterConfigServiceImpl.PQ_FREQ_CONVERTER_TEST_RES_TB_PREFIX + suffix);
|
||||
this.saveBatch(testResList);
|
||||
DynamicTableNameHandler.remove();
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updateTestRes(Integer suffix, List<PqFreqConverterTestRes> testResList) {
|
||||
DynamicTableNameHandler.setTableName(PqFreqConverterConfigServiceImpl.PQ_FREQ_CONVERTER_TEST_RES_TB_PREFIX + suffix);
|
||||
this.updateBatchById(testResList);
|
||||
DynamicTableNameHandler.remove();
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PqFreqConverterTestRes> listTestRes(Integer suffix) {
|
||||
DynamicTableNameHandler.setTableName(PqFreqConverterConfigServiceImpl.PQ_FREQ_CONVERTER_TEST_RES_TB_PREFIX + suffix);
|
||||
List<PqFreqConverterTestRes> result = this.list();
|
||||
DynamicTableNameHandler.remove();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PqFreqConverterTestRes getLastByDuration(Integer suffix, String id, Integer durationMs) {
|
||||
DynamicTableNameHandler.setTableName(PqFreqConverterConfigServiceImpl.PQ_FREQ_CONVERTER_TEST_RES_TB_PREFIX + suffix);
|
||||
LambdaQueryWrapper<PqFreqConverterTestRes> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.between(PqFreqConverterTestRes::getDurationMs, durationMs - freqConverterConfig.getAllowErrorDuration(), durationMs + freqConverterConfig.getAllowErrorDuration())
|
||||
.ne(PqFreqConverterTestRes::getId, id)
|
||||
.orderByAsc(PqFreqConverterTestRes::getResidualVoltage)
|
||||
.last("limit 1");
|
||||
PqFreqConverterTestRes result = this.getOne(queryWrapper);
|
||||
DynamicTableNameHandler.remove();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PqFreqConverterTestRes getLastByResidualVoltage(Integer suffix, String id, Double residualVoltage) {
|
||||
DynamicTableNameHandler.setTableName(PqFreqConverterConfigServiceImpl.PQ_FREQ_CONVERTER_TEST_RES_TB_PREFIX + suffix);
|
||||
LambdaQueryWrapper<PqFreqConverterTestRes> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.between(PqFreqConverterTestRes::getResidualVoltage, residualVoltage - freqConverterConfig.getAllowErrorResidualVoltage(), residualVoltage + freqConverterConfig.getAllowErrorResidualVoltage())
|
||||
.ne(PqFreqConverterTestRes::getId, id)
|
||||
.orderByDesc(PqFreqConverterTestRes::getDurationMs)
|
||||
.last("limit 1");
|
||||
PqFreqConverterTestRes result = this.getOne(queryWrapper);
|
||||
DynamicTableNameHandler.remove();
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -60,7 +60,7 @@ public class PqIcdPathController extends BaseController {
|
||||
@PostMapping("/add")
|
||||
@ApiOperation("新增icd")
|
||||
@ApiImplicitParam(name = "param", value = "icd新增参数", required = true)
|
||||
public HttpResult<Boolean> add(@RequestBody @Validated PqIcdPathParam param) {
|
||||
public HttpResult<Boolean> add(PqIcdPathParam param) {
|
||||
String methodDescribe = getMethodDescribe("add");
|
||||
LogUtil.njcnDebug(log, "{},新增数据为:{}", methodDescribe, param);
|
||||
|
||||
@@ -76,7 +76,7 @@ public class PqIcdPathController extends BaseController {
|
||||
@PostMapping("/update")
|
||||
@ApiOperation("修改icd")
|
||||
@ApiImplicitParam(name = "param", value = "icd修改参数", required = true)
|
||||
public HttpResult<Boolean> update(@RequestBody @Validated PqIcdPathParam.UpdateParam param) {
|
||||
public HttpResult<Boolean> update(PqIcdPathParam.UpdateParam param) {
|
||||
String methodDescribe = getMethodDescribe("update");
|
||||
LogUtil.njcnDebug(log, "{},修改数据为:{}", methodDescribe, param);
|
||||
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.njcn.gather.icd.pojo.enums;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @data 2025-11-11
|
||||
*/
|
||||
public enum IcdResponseEnum {
|
||||
FILE_NOT_NULL("A018001", "映射文件不能为空"),
|
||||
FILE_TYPE_ERROR("A018002", "映射文件类型错误"),
|
||||
FILE_SIZE_ERROR("A018003", "映射文件大小超出限制");
|
||||
|
||||
private String code;
|
||||
private String message;
|
||||
|
||||
IcdResponseEnum(String code, String message) {
|
||||
this.code = code;
|
||||
this.message = message;
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import com.njcn.web.pojo.param.BaseParam;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.Pattern;
|
||||
@@ -32,6 +33,9 @@ public class PqIcdPathParam {
|
||||
@ApiModelProperty(value = "角型接线时是否使用相别的指标来进行检测,0表示否,1表示是", required = true)
|
||||
private Integer usePhaseIndex;
|
||||
|
||||
@ApiModelProperty(value = "映射文件", required = true)
|
||||
private MultipartFile mappingFile;
|
||||
|
||||
/**
|
||||
* 分页查询实体
|
||||
*/
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.njcn.gather.icd.pojo.po;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.njcn.db.mybatisplus.bo.BaseEntity;
|
||||
import lombok.Data;
|
||||
@@ -46,5 +47,18 @@ public class PqIcdPath extends BaseEntity implements Serializable {
|
||||
* 角型接线时是否使用相别的指标来进行检测,0表示否,1表示是
|
||||
*/
|
||||
private Integer usePhaseIndex;
|
||||
|
||||
/**
|
||||
* 映射文件路径
|
||||
*/
|
||||
@TableField(exist = false)
|
||||
private FileVO mappingFile;
|
||||
|
||||
@Data
|
||||
public static class FileVO{
|
||||
private String name;
|
||||
|
||||
private String url;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.njcn.gather.icd.service.impl;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
@@ -7,17 +8,26 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.njcn.common.pojo.enums.common.DataStateEnum;
|
||||
import com.njcn.common.pojo.exception.BusinessException;
|
||||
import com.njcn.gather.icd.mapper.PqIcdPathMapper;
|
||||
import com.njcn.gather.icd.pojo.enums.IcdResponseEnum;
|
||||
import com.njcn.gather.icd.pojo.param.PqIcdPathParam;
|
||||
import com.njcn.gather.icd.pojo.po.PqIcdPath;
|
||||
import com.njcn.gather.icd.service.IPqIcdPathService;
|
||||
import com.njcn.gather.pojo.enums.DetectionResponseEnum;
|
||||
import com.njcn.gather.report.pojo.enums.ReportResponseEnum;
|
||||
import com.njcn.web.factory.PageFactory;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -41,6 +51,13 @@ public class PqIcdPathServiceImpl extends ServiceImpl<PqIcdPathMapper, PqIcdPath
|
||||
.like(StrUtil.isNotBlank(param.getName()), PqIcdPath::getName, param.getName())
|
||||
.orderByDesc(PqIcdPath::getCreateTime);
|
||||
Page<PqIcdPath> page = this.page(new Page<>(PageFactory.getPageNum(param), PageFactory.getPageSize(param)), wrapper);
|
||||
String commInstallPath = this.getCommInstallPath();
|
||||
page.getRecords().forEach(pqIcdPath -> {
|
||||
PqIcdPath.FileVO fileVO = new PqIcdPath.FileVO();
|
||||
fileVO.setUrl(commInstallPath + "\\DeviceControl\\Config\\" + pqIcdPath.getName() + ".txt");
|
||||
fileVO.setName(pqIcdPath.getName() + ".txt");
|
||||
pqIcdPath.setMappingFile(fileVO);
|
||||
});
|
||||
return page;
|
||||
}
|
||||
|
||||
@@ -52,9 +69,81 @@ public class PqIcdPathServiceImpl extends ServiceImpl<PqIcdPathMapper, PqIcdPath
|
||||
PqIcdPath pqIcdPath = new PqIcdPath();
|
||||
BeanUtils.copyProperties(param, pqIcdPath);
|
||||
pqIcdPath.setState(DataStateEnum.ENABLE.getCode());
|
||||
|
||||
String commInstallPath = this.getCommInstallPath();
|
||||
System.out.println("commInstallPath = " + commInstallPath);
|
||||
long FILE_SIZE_LIMIT = 1 * 1024 * 1024;
|
||||
MultipartFile mappingFile = param.getMappingFile();
|
||||
|
||||
System.out.println("mappingFile = " + ObjectUtil.isNotNull(mappingFile) + " " + !mappingFile.isEmpty());
|
||||
if (ObjectUtil.isNotNull(mappingFile) && !mappingFile.isEmpty()) {
|
||||
String mappingFilename = mappingFile.getOriginalFilename();
|
||||
|
||||
if (!mappingFilename.endsWith(".txt")) {
|
||||
throw new BusinessException(IcdResponseEnum.FILE_TYPE_ERROR);
|
||||
}
|
||||
if (mappingFile.getSize() > FILE_SIZE_LIMIT) {
|
||||
throw new BusinessException(IcdResponseEnum.FILE_SIZE_ERROR);
|
||||
}
|
||||
|
||||
try {
|
||||
// 如果文件存在,则先删除
|
||||
String mappingFilePath = commInstallPath + "\\DeviceControl\\Config\\" + mappingFilename;
|
||||
System.out.println("mappingFilePath = " + mappingFilePath);
|
||||
Path path = Paths.get(mappingFilePath);
|
||||
File file = path.toFile();
|
||||
if (file.exists()) {
|
||||
file.delete();
|
||||
}
|
||||
|
||||
// 保存文件
|
||||
byte[] bytes = mappingFile.getBytes();
|
||||
BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(new FileOutputStream(mappingFilePath));
|
||||
bufferedOutputStream.write(bytes);
|
||||
bufferedOutputStream.flush();
|
||||
|
||||
bufferedOutputStream.close();
|
||||
System.out.println("File saved successfully");
|
||||
} catch (IOException e) {
|
||||
throw new BusinessException(ReportResponseEnum.FILE_UPLOAD_FAILED);
|
||||
}
|
||||
} else {
|
||||
System.out.println("mappingFile is null or empty");
|
||||
throw new BusinessException(IcdResponseEnum.FILE_NOT_NULL);
|
||||
}
|
||||
|
||||
this.executeRestartCmd(commInstallPath);
|
||||
|
||||
return this.save(pqIcdPath);
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行重启通讯服务脚本
|
||||
*
|
||||
* @param commInstallPath
|
||||
*/
|
||||
private void executeRestartCmd(String commInstallPath) {
|
||||
// 以管理员身份运行bat脚本
|
||||
String batFilePath = commInstallPath + "\\重启所有服务.bat";
|
||||
try {
|
||||
Runtime.getRuntime().exec(batFilePath);
|
||||
} catch (IOException e) {
|
||||
log.error("重启通讯服务失败", e);
|
||||
}
|
||||
}
|
||||
|
||||
private String getCommInstallPath() {
|
||||
String workDir = System.getProperty("user.dir");
|
||||
// String workDir = "D:\\program\\CN_Gather";
|
||||
// 获取映射文件存放文件夹
|
||||
String dirPath = workDir + "\\9100";
|
||||
int index = workDir.indexOf("\\resources\\extraResources\\java");
|
||||
if (index != -1) {
|
||||
dirPath = workDir.substring(0, workDir.indexOf("\\resources\\extraResources\\java")) + "\\9100";
|
||||
}
|
||||
return dirPath;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public boolean updateIcd(PqIcdPathParam.UpdateParam param) {
|
||||
@@ -62,12 +151,60 @@ public class PqIcdPathServiceImpl extends ServiceImpl<PqIcdPathMapper, PqIcdPath
|
||||
this.checkRepeat(param, true);
|
||||
PqIcdPath pqIcdPath = new PqIcdPath();
|
||||
BeanUtils.copyProperties(param, pqIcdPath);
|
||||
|
||||
String commInstallPath = this.getCommInstallPath();
|
||||
long FILE_SIZE_LIMIT = 1 * 1024 * 1024;
|
||||
MultipartFile mappingFile = param.getMappingFile();
|
||||
if (ObjectUtil.isNotNull(mappingFile) && !mappingFile.isEmpty()) {
|
||||
String mappingFilename = mappingFile.getOriginalFilename();
|
||||
|
||||
if (!mappingFilename.endsWith(".txt")) {
|
||||
throw new BusinessException(IcdResponseEnum.FILE_TYPE_ERROR);
|
||||
}
|
||||
if (mappingFile.getSize() > FILE_SIZE_LIMIT) {
|
||||
throw new BusinessException(IcdResponseEnum.FILE_SIZE_ERROR);
|
||||
}
|
||||
|
||||
try {
|
||||
// 如果文件存在,则先删除
|
||||
String mappingFilePath = commInstallPath + "\\DeviceControl\\Config\\" + mappingFilename;
|
||||
Path path = Paths.get(mappingFilePath);
|
||||
File file = path.toFile();
|
||||
if (file.exists()) {
|
||||
file.delete();
|
||||
}
|
||||
|
||||
// 保存文件
|
||||
byte[] bytes = mappingFile.getBytes();
|
||||
BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(new FileOutputStream(mappingFilePath));
|
||||
bufferedOutputStream.write(bytes);
|
||||
bufferedOutputStream.flush();
|
||||
|
||||
bufferedOutputStream.close();
|
||||
} catch (IOException e) {
|
||||
throw new BusinessException(ReportResponseEnum.FILE_UPLOAD_FAILED);
|
||||
}
|
||||
}
|
||||
|
||||
this.executeRestartCmd(commInstallPath);
|
||||
|
||||
return this.updateById(pqIcdPath);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public boolean deleteIcd(List<String> ids) {
|
||||
List<PqIcdPath> pqIcdPaths = this.listByIds(ids);
|
||||
String commInstallPath = this.getCommInstallPath();
|
||||
pqIcdPaths.forEach(pqIcdPath -> {
|
||||
String mappingFilePath = commInstallPath + "\\DeviceControl\\Config\\" + pqIcdPath.getName() + ".txt";
|
||||
Path path = Paths.get(mappingFilePath);
|
||||
File file = path.toFile();
|
||||
if (file.exists()) {
|
||||
file.delete();
|
||||
}
|
||||
});
|
||||
|
||||
return this.lambdaUpdate().in(PqIcdPath::getId, ids).set(PqIcdPath::getState, DataStateEnum.DELETED.getCode()).update();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
package com.njcn.gather.monitor.mapper;
|
||||
|
||||
import com.github.yulichang.base.MPJBaseMapper;
|
||||
import com.njcn.gather.device.pojo.po.PqDevSub;
|
||||
import com.njcn.gather.device.pojo.vo.PreDetection;
|
||||
import com.njcn.gather.monitor.pojo.po.PqMonitor;
|
||||
import com.njcn.gather.plan.pojo.po.AdPlan;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
@@ -33,5 +35,21 @@ public interface PqMonitorMapper extends MPJBaseMapper<PqMonitor> {
|
||||
PqMonitor getByDevIdAndNum(@Param("devId") String devId, @Param("num") Integer num);
|
||||
|
||||
List<PqMonitor> listByDevIds(@Param("devIds") List<String> devIds);
|
||||
|
||||
void updateDeviceCheckState(@Param("devId")String devId, @Param("value") Integer value);
|
||||
|
||||
void updateDeviceCheckResult(@Param("devId")String devId, @Param("value") Integer value);
|
||||
|
||||
void updateDeviceReportRState(@Param("devId")String devId, @Param("value") Integer value);
|
||||
|
||||
AdPlan getPlanByDevId(@Param("devId") String devId);
|
||||
|
||||
List<PqDevSub> listDevSubByPlanId(@Param("planId") String planId);
|
||||
|
||||
void updatePlanCheckState(@Param("planId") String planId, @Param("value") Integer value);
|
||||
|
||||
void updatePlanCheckResult(@Param("planId") String planId, @Param("value") Integer value);
|
||||
|
||||
void updatePlanReportRState(@Param("planId") String planId, @Param("value") Integer value);
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.njcn.gather.monitor.mapper.PqMonitorMapper">
|
||||
|
||||
|
||||
<select id="selectMonitorInfo"
|
||||
resultType="com.njcn.gather.device.pojo.vo.PreDetection$MonitorListDTO">
|
||||
SELECT CONCAT(pq_dev.IP, '_', Num) as lineId,
|
||||
@@ -41,5 +42,55 @@
|
||||
</foreach>
|
||||
order by Num
|
||||
</select>
|
||||
|
||||
<update id="updateDeviceCheckState">
|
||||
update pq_dev_sub
|
||||
set Check_State = #{value}
|
||||
where dev_Id = #{devId}
|
||||
</update>
|
||||
|
||||
<update id="updateDeviceCheckResult">
|
||||
update pq_dev_sub
|
||||
set Check_Result = #{value}
|
||||
where dev_Id = #{devId}
|
||||
</update>
|
||||
|
||||
<update id="updateDeviceReportRState">
|
||||
update pq_dev_sub
|
||||
set Report_State = #{value}
|
||||
where dev_Id = #{devId}
|
||||
</update>
|
||||
|
||||
<select id="getPlanByDevId" resultType="com.njcn.gather.plan.pojo.po.AdPlan">
|
||||
select *
|
||||
from ad_plan
|
||||
inner join pq_dev on ad_plan.id = pq_dev.Plan_Id
|
||||
where pq_dev.Id = #{devId}
|
||||
</select>
|
||||
|
||||
<select id="listDevSubByPlanId" resultType="com.njcn.gather.device.pojo.po.PqDevSub">
|
||||
select *
|
||||
from pq_dev_sub
|
||||
inner join pq_dev on pq_dev_sub.dev_Id = pq_dev.Id
|
||||
where pq_dev.Plan_Id = #{planId}
|
||||
</select>
|
||||
|
||||
<update id="updatePlanCheckState">
|
||||
update ad_plan
|
||||
set Test_State = #{value}
|
||||
where id = #{planId}
|
||||
</update>
|
||||
|
||||
<update id="updatePlanCheckResult">
|
||||
update ad_plan
|
||||
set Result = #{value}
|
||||
where id = #{planId}
|
||||
</update>
|
||||
|
||||
<update id="updatePlanReportRState">
|
||||
update ad_plan
|
||||
set Report_State = #{value}
|
||||
where id = #{planId}
|
||||
</update>
|
||||
</mapper>
|
||||
|
||||
|
||||
@@ -52,7 +52,7 @@ public class PqMonitorParam {
|
||||
private Integer statInterval;
|
||||
|
||||
@ApiModelProperty(value = "谐波系统监测点id")
|
||||
@NotBlank(message = DetectionValidMessage.MONITOR_ID_NOT_BLANK)
|
||||
// @NotBlank(message = DetectionValidMessage.MONITOR_ID_NOT_BLANK)
|
||||
private String harmSysId;
|
||||
|
||||
@ApiModelProperty(value = "是否做检测")
|
||||
|
||||
@@ -14,11 +14,11 @@ import javax.validation.constraints.NotNull;
|
||||
@Data
|
||||
public class PqMonitorExcel {
|
||||
|
||||
@Excel(name = "谐波系统监测点ID*", width = 20, orderNum = "1")
|
||||
@NotBlank(message = DetectionValidMessage.MONITOR_ID_NOT_BLANK)
|
||||
@Excel(name = "谐波系统监测点ID", width = 20, orderNum = "1")
|
||||
// @NotBlank(message = DetectionValidMessage.MONITOR_ID_NOT_BLANK)
|
||||
private String harmSysId;
|
||||
|
||||
@Excel(name = "所属母线*", width = 20, orderNum = "2")
|
||||
@Excel(name = "母线名称*", width = 20, orderNum = "2")
|
||||
@NotBlank(message = DetectionValidMessage.BELONG_LINE_NOT_BLANK)
|
||||
private String busbar;
|
||||
|
||||
@@ -30,19 +30,27 @@ public class PqMonitorExcel {
|
||||
@NotNull(message = DetectionValidMessage.MONITOR_NUM_NOT_NULL)
|
||||
private Integer num;
|
||||
|
||||
@Excel(name = "PT变比(pt1:pt2)*", width = 20, orderNum = "5")
|
||||
@Excel(name = "PT一次变比*", width = 20, orderNum = "5")
|
||||
@NotBlank(message = DetectionValidMessage.PT_NOT_BLANK)
|
||||
private String pt;
|
||||
private String pt1;
|
||||
|
||||
@Excel(name = "CT变比(ct1:ct2)*", width = 20, orderNum = "6")
|
||||
@Excel(name = "PT二次变比*", width = 20, orderNum = "6")
|
||||
@NotBlank(message = DetectionValidMessage.PT_NOT_BLANK)
|
||||
private String pt2;
|
||||
|
||||
@Excel(name = "CT一次变比*", width = 20, orderNum = "7")
|
||||
@NotBlank(message = DetectionValidMessage.CT_NOT_BLANK)
|
||||
private String ct;
|
||||
private String ct1;
|
||||
|
||||
@Excel(name = "接线方式*", width = 20, orderNum = "7")
|
||||
@Excel(name = "CT二次变比*", width = 20, orderNum = "8")
|
||||
@NotBlank(message = DetectionValidMessage.CT_NOT_BLANK)
|
||||
private String ct2;
|
||||
|
||||
@Excel(name = "接线方式*", width = 20, orderNum = "9")
|
||||
@NotBlank(message = DetectionValidMessage.CONNECTION_NOT_BLANK)
|
||||
private String connection;
|
||||
|
||||
@Excel(name = "统计间隔*", width = 10, orderNum = "8")
|
||||
@Excel(name = "统计间隔*", width = 20, orderNum = "10")
|
||||
@NotNull(message = DetectionValidMessage.STAT_INTERVAL_NOT_NULL)
|
||||
private Integer statInterval;
|
||||
}
|
||||
|
||||
@@ -6,7 +6,6 @@ import com.njcn.gather.monitor.pojo.po.PqMonitor;
|
||||
import com.njcn.gather.plan.pojo.enums.DataSourceEnum;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
@@ -112,4 +111,18 @@ public interface IPqMonitorService extends IService<PqMonitor> {
|
||||
*/
|
||||
Integer getDevCheckResult(String devId);
|
||||
|
||||
/**
|
||||
* 根据被检设备id删除监测点信息
|
||||
*
|
||||
* @param devId
|
||||
* @return
|
||||
*/
|
||||
boolean removeByDevId(String devId);
|
||||
|
||||
/**
|
||||
* 根据被检设备id和监测点编号获取监测点信息
|
||||
* @param devId 设备id
|
||||
* @param monitorNum 监测点编号
|
||||
*/
|
||||
PqMonitor getByDevIdAndNum(String devId, int monitorNum);
|
||||
}
|
||||
|
||||
@@ -10,11 +10,15 @@ import com.njcn.common.pojo.exception.BusinessException;
|
||||
import com.njcn.gather.detection.util.socket.CnSocketUtil;
|
||||
import com.njcn.gather.device.pojo.enums.CheckResultEnum;
|
||||
import com.njcn.gather.device.pojo.enums.CheckStateEnum;
|
||||
import com.njcn.gather.device.pojo.enums.DevReportStateEnum;
|
||||
import com.njcn.gather.device.pojo.po.PqDevSub;
|
||||
import com.njcn.gather.monitor.mapper.PqMonitorMapper;
|
||||
import com.njcn.gather.monitor.pojo.param.PqMonitorParam;
|
||||
import com.njcn.gather.monitor.pojo.po.PqMonitor;
|
||||
import com.njcn.gather.monitor.service.IPqMonitorService;
|
||||
import com.njcn.gather.plan.pojo.enums.DataSourceEnum;
|
||||
import com.njcn.gather.plan.pojo.enums.PlanReportStateEnum;
|
||||
import com.njcn.gather.plan.pojo.po.AdPlan;
|
||||
import com.njcn.gather.pojo.enums.DetectionResponseEnum;
|
||||
import com.njcn.gather.storage.service.DetectionDataDealService;
|
||||
import com.njcn.gather.storage.service.impl.DetectionDataServiceImpl;
|
||||
@@ -26,6 +30,7 @@ import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
@@ -62,11 +67,110 @@ public class PqMonitorServiceImpl extends ServiceImpl<PqMonitorMapper, PqMonitor
|
||||
@Transactional
|
||||
public boolean updatePqMonitorByDevId(String devId, List<PqMonitorParam> paramList) {
|
||||
// 先删除原有数据
|
||||
this.deletePqMonitorByDevId(devId);
|
||||
// 再添加新数据
|
||||
// this.deletePqMonitorByDevId(devId);
|
||||
|
||||
// 添加新数据
|
||||
List<PqMonitor> pqMonitorList = BeanUtil.copyToList(paramList, PqMonitor.class);
|
||||
pqMonitorList.forEach(pqMonitor -> pqMonitor.setDevId(devId));
|
||||
return this.saveBatch(pqMonitorList);
|
||||
|
||||
List<PqMonitor> existedMonitorList = this.listPqMonitorByDevIds(Collections.singletonList(devId));
|
||||
|
||||
Map<Integer, List<PqMonitor>> map = pqMonitorList.stream().collect(Collectors.groupingBy(PqMonitor::getNum));
|
||||
|
||||
List<PqMonitor> newMonitorList = new ArrayList<>();
|
||||
map.forEach((num, monitorList) -> {
|
||||
PqMonitor pqMonitor = existedMonitorList.stream().filter(monitor -> monitor.getNum() == num).findFirst().orElse(null);
|
||||
|
||||
if (ObjectUtil.isNotNull(pqMonitor)) {
|
||||
BeanUtil.copyProperties(monitorList.get(0), pqMonitor, "id", "realtimeResult", "statisticsResult", "recordedResult", "realtimeNum", "statisticsNum", "recordedNum", "resultType", "qualifiedNum");
|
||||
newMonitorList.add(pqMonitor);
|
||||
existedMonitorList.remove(pqMonitor);
|
||||
} else {
|
||||
newMonitorList.addAll(monitorList);
|
||||
}
|
||||
});
|
||||
|
||||
// 同步更新设备的状态
|
||||
List<PqMonitor> enableCheckMonitorList = newMonitorList.stream().filter(pqMonitor -> pqMonitor.getCheckFlag() == 1).collect(Collectors.toList());
|
||||
List<PqMonitor> checkedMonitorList = enableCheckMonitorList.stream().filter(pqMonitor -> ObjectUtil.isNotNull(pqMonitor.getResultType())).collect(Collectors.toList());
|
||||
|
||||
if (enableCheckMonitorList.size() == checkedMonitorList.size() && checkedMonitorList.size() > 0) {
|
||||
this.baseMapper.updateDeviceCheckState(devId, CheckStateEnum.CHECKED.getValue());
|
||||
this.baseMapper.updateDeviceReportRState(devId, DevReportStateEnum.NOT_GENERATED.getValue());
|
||||
}
|
||||
if (enableCheckMonitorList.size() > checkedMonitorList.size() && checkedMonitorList.size() > 0) {
|
||||
this.baseMapper.updateDeviceCheckState(devId, CheckStateEnum.CHECKING.getValue());
|
||||
this.baseMapper.updateDeviceReportRState(devId, DevReportStateEnum.NOT_GENERATED.getValue());
|
||||
}
|
||||
if (enableCheckMonitorList.size() > 0 && checkedMonitorList.size() == 0) {
|
||||
this.baseMapper.updateDeviceCheckState(devId, CheckStateEnum.UNCHECKED.getValue());
|
||||
}
|
||||
|
||||
List<Integer> monitorResultList = checkedMonitorList.stream().map(pqMonitor -> {
|
||||
String resultType = pqMonitor.getResultType();
|
||||
DataSourceEnum dataSourceEnum = DataSourceEnum.ofByValue(resultType);
|
||||
switch (dataSourceEnum) {
|
||||
case REAL_DATA:
|
||||
return pqMonitor.getRealtimeResult();
|
||||
case WAVE_DATA:
|
||||
return pqMonitor.getRecordedResult();
|
||||
case MINUTE_STATISTICS_MAX:
|
||||
case MINUTE_STATISTICS_MIN:
|
||||
case MINUTE_STATISTICS_AVG:
|
||||
case MINUTE_STATISTICS_CP95:
|
||||
return pqMonitor.getStatisticsResult();
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return null;
|
||||
}).collect(Collectors.toList());
|
||||
|
||||
long qualifiedCount = monitorResultList.stream().filter(result -> result != null && result == 1).count();
|
||||
if (qualifiedCount == monitorResultList.size() && monitorResultList.size() > 0) {
|
||||
this.baseMapper.updateDeviceCheckResult(devId, CheckResultEnum.ACCORD.getValue());
|
||||
} else if (monitorResultList.size() > 0) {
|
||||
this.baseMapper.updateDeviceCheckResult(devId, CheckResultEnum.NOT_ACCORD.getValue());
|
||||
} else {
|
||||
this.baseMapper.updateDeviceCheckResult(devId, CheckResultEnum.UNCHECKED.getValue());
|
||||
}
|
||||
|
||||
// 同步更新计划的状态
|
||||
AdPlan plan = this.baseMapper.getPlanByDevId(devId);
|
||||
if (ObjectUtil.isNotNull(plan)) {
|
||||
|
||||
|
||||
List<PqDevSub> devSubList = this.baseMapper.listDevSubByPlanId(plan.getId());
|
||||
|
||||
List<PqDevSub> checkedDevSubList = devSubList.stream().filter(pqDevSub -> pqDevSub.getCheckState() == CheckStateEnum.CHECKED.getValue()).collect(Collectors.toList());
|
||||
List<PqDevSub> checkingDevSubList = devSubList.stream().filter(pqDevSub -> pqDevSub.getCheckState() == CheckStateEnum.CHECKING.getValue()).collect(Collectors.toList());
|
||||
if (checkedDevSubList.size() == devSubList.size() && devSubList.size() > 0) {
|
||||
this.baseMapper.updatePlanCheckState(plan.getId(), CheckStateEnum.CHECKED.getValue());
|
||||
} else if (checkedDevSubList.size() > 0 || checkingDevSubList.size() > 0) {
|
||||
this.baseMapper.updatePlanCheckState(plan.getId(), CheckStateEnum.CHECKING.getValue());
|
||||
} else {
|
||||
this.baseMapper.updatePlanCheckState(plan.getId(), CheckStateEnum.UNCHECKED.getValue());
|
||||
}
|
||||
|
||||
List<PqDevSub> accordDevSubList = checkedDevSubList.stream().filter(pqDevSub -> pqDevSub.getCheckResult() == CheckResultEnum.ACCORD.getValue()).collect(Collectors.toList());
|
||||
if (accordDevSubList.size() == checkedDevSubList.size() && checkedDevSubList.size() > 0) {
|
||||
this.baseMapper.updatePlanCheckResult(plan.getId(), CheckResultEnum.ACCORD.getValue());
|
||||
} else if (accordDevSubList.size() > 0) {
|
||||
this.baseMapper.updatePlanCheckResult(plan.getId(), CheckResultEnum.NOT_ACCORD.getValue());
|
||||
} else {
|
||||
this.baseMapper.updatePlanCheckResult(plan.getId(), CheckResultEnum.UNCHECKED.getValue());
|
||||
}
|
||||
|
||||
List<PqDevSub> generatedDevSubList = checkedDevSubList.stream().filter(pqDevSub -> pqDevSub.getReportState() == DevReportStateEnum.GENERATED.getValue()).collect(Collectors.toList());
|
||||
if (generatedDevSubList.size() == checkedDevSubList.size() && checkedDevSubList.size() > 0) {
|
||||
this.baseMapper.updatePlanReportRState(plan.getId(), PlanReportStateEnum.REPORT_STATE_ALL_GENERATED.getValue());
|
||||
} else if (generatedDevSubList.size() > 0) {
|
||||
this.baseMapper.updatePlanReportRState(plan.getId(), PlanReportStateEnum.REPORT_STATE_PARTIALLY_GENERATED.getValue());
|
||||
} else {
|
||||
this.baseMapper.updatePlanReportRState(plan.getId(), PlanReportStateEnum.REPORT_STATE_NOT_GENERATED.getValue());
|
||||
}
|
||||
}
|
||||
this.removeByIds(existedMonitorList.stream().map(PqMonitor::getId).collect(Collectors.toList()));
|
||||
return this.saveOrUpdateBatch(newMonitorList);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -163,10 +267,19 @@ public class PqMonitorServiceImpl extends ServiceImpl<PqMonitorMapper, PqMonitor
|
||||
} else {
|
||||
newWaveNum.set(waveNum);
|
||||
newMonitorResult = waveNumResultMap.get(waveNum);
|
||||
if (newMonitorResult == 2) {
|
||||
newMonitorResult = CheckResultEnum.NOT_ACCORD.getValue();
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
newMonitorResult = detectionDataDealService.getMonitorResult(monitorId, adTypes, dataSourceEnum.getValue(), num, null, code);
|
||||
if (newMonitorResult == 2) {
|
||||
newMonitorResult = CheckResultEnum.NOT_ACCORD.getValue();
|
||||
}
|
||||
if (newMonitorResult == 1) {
|
||||
newMonitorResult = CheckResultEnum.ACCORD.getValue();
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -188,7 +301,18 @@ public class PqMonitorServiceImpl extends ServiceImpl<PqMonitorMapper, PqMonitor
|
||||
|
||||
if (CheckResultEnum.ACCORD.getValue().equals(oldMonitorResult)) {
|
||||
if (CheckResultEnum.ACCORD.getValue().equals(newMonitorResult)) {
|
||||
qualifiedNum += 1;
|
||||
String oldNum = "";
|
||||
if (DataSourceEnum.REAL_DATA.getValue().equals(resultType)) {
|
||||
oldNum = monitor.getRealtimeNum();
|
||||
} else if (DataSourceEnum.WAVE_DATA.getValue().equals(resultType)) {
|
||||
oldNum = monitor.getRecordedNum();
|
||||
} else {
|
||||
oldNum = monitor.getStatisticsNum();
|
||||
}
|
||||
String[] split1 = oldNum.split(CnSocketUtil.SPLIT_TAG);
|
||||
if (!split1[0].equals(num.toString())) {
|
||||
qualifiedNum += 1;
|
||||
}
|
||||
updateFlag = true;
|
||||
}
|
||||
} else {
|
||||
@@ -269,15 +393,61 @@ public class PqMonitorServiceImpl extends ServiceImpl<PqMonitorMapper, PqMonitor
|
||||
String resultType = monitor.getResultType();
|
||||
if (StrUtil.isNotBlank(resultType)) {
|
||||
if (DataSourceEnum.REAL_DATA.getValue().equals(resultType)) {
|
||||
allResultFlags.add(monitor.getRealtimeResult());
|
||||
//allResultFlags.add(monitor.getRealtimeResult());
|
||||
if (monitor.getRealtimeResult() == 0) {
|
||||
allResultFlags.add(2);
|
||||
}
|
||||
if (monitor.getRealtimeResult() == 1) {
|
||||
allResultFlags.add(1);
|
||||
}
|
||||
if (monitor.getRealtimeResult() == 4) {
|
||||
allResultFlags.add(4);
|
||||
}
|
||||
} else if (DataSourceEnum.WAVE_DATA.getValue().equals(resultType)) {
|
||||
allResultFlags.add(monitor.getRecordedResult());
|
||||
//allResultFlags.add(monitor.getRecordedResult());
|
||||
if (monitor.getRecordedResult() == 0) {
|
||||
allResultFlags.add(2);
|
||||
}
|
||||
if (monitor.getRecordedResult() == 1) {
|
||||
allResultFlags.add(1);
|
||||
}
|
||||
if (monitor.getRecordedResult() == 4) {
|
||||
allResultFlags.add(4);
|
||||
}
|
||||
} else {
|
||||
allResultFlags.add(monitor.getStatisticsResult());
|
||||
//allResultFlags.add(monitor.getStatisticsResult());
|
||||
if (monitor.getStatisticsResult() == 0) {
|
||||
allResultFlags.add(2);
|
||||
}
|
||||
if (monitor.getStatisticsResult() == 1) {
|
||||
allResultFlags.add(1);
|
||||
}
|
||||
if (monitor.getStatisticsResult() == 4) {
|
||||
allResultFlags.add(4);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return DetectionDataServiceImpl.isResultFlag(allResultFlags);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeByDevId(String devId) {
|
||||
QueryWrapper<PqMonitor> wrapper = new QueryWrapper<>();
|
||||
wrapper.eq("pq_monitor.Dev_Id", devId);
|
||||
return this.remove(wrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PqMonitor getByDevIdAndNum(String devId, int monitorNum) {
|
||||
QueryWrapper<PqMonitor> wrapper = new QueryWrapper<>();
|
||||
wrapper.eq("pq_monitor.Dev_Id", devId)
|
||||
.eq("pq_monitor.Num", monitorNum);
|
||||
List<PqMonitor> pqMonitors = this.list(wrapper);
|
||||
if (CollUtil.isNotEmpty(pqMonitors)) {
|
||||
return pqMonitors.get(0);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,6 +42,8 @@ import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -178,7 +180,7 @@ public class AdPlanController extends BaseController {
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
@PostMapping("/getBigTestItem")
|
||||
@ApiOperation("获取检测大项数据")
|
||||
@ApiImplicitParam(name = "id", value = "检测计划id", required = true)
|
||||
@ApiImplicitParam(name = "checkParam", value = "检测计划id", required = true)
|
||||
public HttpResult<List<Map<String, String>>> getBigTestItem(@RequestBody AdPlanParam.CheckParam checkParam) {
|
||||
String methodDescribe = getMethodDescribe("getBigTestItem");
|
||||
LogUtil.njcnDebug(log, "{},查询数据为:{}", methodDescribe, checkParam);
|
||||
@@ -189,7 +191,7 @@ public class AdPlanController extends BaseController {
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON, operateType = OperateType.DOWNLOAD)
|
||||
@PostMapping("/analyse")
|
||||
@ApiOperation("检测数据分析")
|
||||
@ApiImplicitParam(name = "planId", value = "检测计划id", required = true)
|
||||
@ApiImplicitParam(name = "ids", value = "检测计划id", required = true)
|
||||
public void analyse(@RequestBody List<String> ids) {
|
||||
String methodDescribe = getMethodDescribe("analyse");
|
||||
LogUtil.njcnDebug(log, "{},查询数据为:{}", methodDescribe, String.join(StrUtil.COMMA, ids));
|
||||
@@ -199,7 +201,7 @@ public class AdPlanController extends BaseController {
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
@PostMapping("/listByPlanId")
|
||||
@ApiOperation("查询出所有已绑定的设备")
|
||||
@ApiImplicitParam(name = "planId", value = "计划id", required = true)
|
||||
@ApiImplicitParam(name = "param", value = "查询参数", required = true)
|
||||
public HttpResult<List<PqDevVO>> listByPlanId(@RequestBody @Validated PqDevParam.QueryParam param) {
|
||||
String methodDescribe = getMethodDescribe("listByPlanId");
|
||||
LogUtil.njcnDebug(log, "{},查询数据为:{}", methodDescribe, param);
|
||||
@@ -239,7 +241,7 @@ public class AdPlanController extends BaseController {
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
@PostMapping("/listDevByPlanId")
|
||||
@ApiOperation("根据计划id分页查询被检设备")
|
||||
@ApiImplicitParam(name = "queryParam", value = "查询参数", required = true)
|
||||
@ApiImplicitParam(name = "param", value = "查询参数", required = true)
|
||||
public HttpResult<Page<PqDevVO>> listDevByPlanId(@RequestBody @Validated PqDevParam.QueryParam param) {
|
||||
String methodDescribe = getMethodDescribe("listDevByPlanId");
|
||||
LogUtil.njcnDebug(log, "{},查询数据为:{}", methodDescribe, param);
|
||||
@@ -452,7 +454,17 @@ public class AdPlanController extends BaseController {
|
||||
fileTypeError.setMessage("请上传zip文件");
|
||||
throw new BusinessException(fileTypeError);
|
||||
}
|
||||
asyncPlanHandler.importAndMergePlanCheckData(file, getUserId(), planId);
|
||||
// 创建临时文件
|
||||
File tempFile = cn.hutool.core.io.FileUtil.createTempFile();
|
||||
// 将MultipartFile内容写入临时文件
|
||||
try {
|
||||
file.transferTo(tempFile);
|
||||
} catch (IOException e) {
|
||||
throw new BusinessException(CommonResponseEnum.FAIL, "文件保存失败");
|
||||
}
|
||||
// 获取文件路径
|
||||
String filePath = tempFile.getAbsolutePath();
|
||||
asyncPlanHandler.importAndMergePlanCheckData(filePath, getUserId(), planId);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, methodDescribe);
|
||||
|
||||
}
|
||||
|
||||
@@ -37,10 +37,8 @@ import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.scheduling.annotation.EnableAsync;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.time.Duration;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
@@ -65,6 +63,8 @@ public class AsyncPlanHandler {
|
||||
private final IAdPariService adPairService;
|
||||
|
||||
private final JdbcTemplate jdbcTemplate;
|
||||
|
||||
|
||||
@Value("${report.reportDir}")
|
||||
private String reportPath;
|
||||
@Value("${data.homeDir}")
|
||||
@@ -235,35 +235,28 @@ public class AsyncPlanHandler {
|
||||
}
|
||||
|
||||
|
||||
@Transactional
|
||||
@Async
|
||||
public void importAndMergePlanCheckData(MultipartFile file, String uid, String planId) {
|
||||
public void importAndMergePlanCheckData(String zipFilePath, String uid, String planId) {
|
||||
importAndMergePlanCheckDataLogic(zipFilePath, uid, planId);
|
||||
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void importAndMergePlanCheckDataLogic(String zipFilePath, String uid, String planId) {
|
||||
NonWebAutoFillValueHandler.setCurrentUserId(uid);
|
||||
LocalDateTime startTime = LocalDateTime.now();
|
||||
AtomicInteger progress = new AtomicInteger(0);
|
||||
AtomicInteger currentProgress = new AtomicInteger(0);
|
||||
AtomicInteger dataCount = new AtomicInteger(0);
|
||||
try {
|
||||
sseClient.sendMessage(uid, planId, HttpResultUtil.assembleResult(CommonResponseEnum.SUCCESS.getCode(), progress, "开始保存文件,请耐心等待..."));
|
||||
// 创建临时目录用于解压文件
|
||||
File tempDir = FileUtil.mkdir(FileUtil.getTmpDirPath() + "import_plan_check_data_" + System.currentTimeMillis() + "/");
|
||||
|
||||
// 将上传的zip文件保存到临时目录
|
||||
File zipFile = FileUtil.file(tempDir, file.getOriginalFilename());
|
||||
try {
|
||||
// 直接获取文件字节,避免依赖Tomcat临时文件
|
||||
byte[] fileBytes = file.getBytes();
|
||||
FileUtil.writeBytes(fileBytes, zipFile);
|
||||
} catch (IOException e) {
|
||||
log.error("保存上传文件失败", e);
|
||||
throw e;
|
||||
}
|
||||
progress.addAndGet(1);
|
||||
sseClient.sendMessage(uid, planId, HttpResultUtil.assembleResult(CommonResponseEnum.SUCCESS.getCode(), progress, "开始解压文件,请耐心等待..."));
|
||||
|
||||
// 解压zip文件
|
||||
File unzipDir = FileUtil.mkdir(FileUtil.file(tempDir, "unzip"));
|
||||
ZipUtil.unzip(zipFile.getAbsolutePath(), unzipDir.getAbsolutePath());
|
||||
ZipUtil.unzip(zipFilePath, unzipDir.getAbsolutePath());
|
||||
|
||||
// 查找解压目录中的json文件
|
||||
File[] files = unzipDir.listFiles();
|
||||
@@ -464,14 +457,14 @@ public class AsyncPlanHandler {
|
||||
sseClient.sendMessage(uid, planId, HttpResultUtil.assembleResult(CommonResponseEnum.SUCCESS.getCode(), progress, "数据合并完成"));
|
||||
|
||||
} catch (Exception e) {
|
||||
|
||||
log.error("导入数据失败", e);
|
||||
sseClient.sendMessage(uid, planId, HttpResultUtil.assembleResult(CommonResponseEnum.FAIL.getCode(), progress.get() + currentProgress.get(), "导入失败"));
|
||||
} finally {
|
||||
NonWebAutoFillValueHandler.clearCurrentUserId();
|
||||
}
|
||||
|
||||
FileUtil.del(zipFilePath);
|
||||
sseClient.closeSse(uid);
|
||||
|
||||
}
|
||||
|
||||
// 构建分页查询SQL
|
||||
|
||||
@@ -207,7 +207,7 @@ public class AdPlanServiceImpl extends ServiceImpl<AdPlanMapper, AdPlan> impleme
|
||||
}
|
||||
List<PqDevVO> pqDevVOList = pqDevMapper.selectByQueryParam(queryParam1);
|
||||
if (CollUtil.isNotEmpty(pqDevVOList)) {
|
||||
long count = pqDevVOList.stream().filter(pqDev -> CheckStateEnum.CHECKED.getValue().equals(pqDev.getCheckState())).count();
|
||||
long count = pqDevVOList.stream().filter(pqDev -> CheckStateEnum.CHECKED.getValue().equals(pqDev.getCheckState()) || CheckStateEnum.DOCUMENTED.getValue().equals(pqDev.getCheckState())).count();
|
||||
adPlanVO.setProgress((float) count / pqDevVOList.size());
|
||||
} else {
|
||||
adPlanVO.setProgress(0.0f);
|
||||
@@ -531,7 +531,7 @@ public class AdPlanServiceImpl extends ServiceImpl<AdPlanMapper, AdPlan> impleme
|
||||
|
||||
@Override
|
||||
public List<Map<String, Object>> listByPattern(String pattern) {
|
||||
List<AdPlan> adPlanList = this.lambdaQuery().eq(AdPlan::getPattern, pattern).eq(AdPlan::getState, DataStateEnum.ENABLE.getCode()).list();
|
||||
List<AdPlan> adPlanList = this.lambdaQuery().eq(AdPlan::getPattern, pattern).eq(AdPlan::getState, DataStateEnum.ENABLE.getCode()).orderByDesc(AdPlan::getCreateTime).list();
|
||||
Map<Integer, List<AdPlan>> map1 = adPlanList.stream().collect(Collectors.groupingBy(AdPlan::getTestState));
|
||||
|
||||
List<Map<String, Object>> result = new ArrayList<>();
|
||||
@@ -554,6 +554,7 @@ public class AdPlanServiceImpl extends ServiceImpl<AdPlanMapper, AdPlan> impleme
|
||||
child.put("pid", adPlan.getFatherPlanId());
|
||||
child.put("name", adPlan.getName());
|
||||
child.put("timeCheck", adPlan.getTimeCheck());
|
||||
child.put("dataRule", adPlan.getDataRule());
|
||||
|
||||
List<PqStandardDev> pqStandardDevs = adPlanStandardDevMapper.listByPlanId(Collections.singletonList(adPlan.getId()));
|
||||
List<String> devTypeIdList = pqStandardDevs.stream().map(PqStandardDev::getDevType).collect(Collectors.toList());
|
||||
@@ -630,7 +631,7 @@ public class AdPlanServiceImpl extends ServiceImpl<AdPlanMapper, AdPlan> impleme
|
||||
|| datasourceId.contains(DataSourceEnum.MINUTE_STATISTICS_MAX.getValue())
|
||||
|| datasourceId.contains(DataSourceEnum.MINUTE_STATISTICS_MIN.getValue())) {
|
||||
String[] split = adPlan.getTestItem().split(StrUtil.COMMA);
|
||||
List<DictTree> dictTreeList = dictTreeService.list(new QueryWrapper<DictTree>().in("id", split).eq("state", DataStateEnum.DELETED.getCode()));
|
||||
List<DictTree> dictTreeList = dictTreeService.list(new QueryWrapper<DictTree>().in("id", split).eq("state", DataStateEnum.DELETED.getCode()).orderByAsc("sort"));
|
||||
|
||||
for (DictTree dictTree : dictTreeList) {
|
||||
Map<String, String> map = new HashMap<>();
|
||||
@@ -1264,7 +1265,7 @@ public class AdPlanServiceImpl extends ServiceImpl<AdPlanMapper, AdPlan> impleme
|
||||
for (int i = 1; i <= maxTime; i++) {
|
||||
row2[i] = i + "次检测";
|
||||
int tempI = i;
|
||||
List<PqDevVO> tempDevList = devList.stream().filter(dev -> dev.getRecheckNum() <= tempI).collect(Collectors.toList());
|
||||
List<PqDevVO> tempDevList = devList.stream().filter(dev -> dev.getRecheckNum() == tempI).collect(Collectors.toList());
|
||||
long passCount = tempDevList.stream().filter(dev -> dev.getCheckResult() == CheckResultEnum.ACCORD.getValue()).count();
|
||||
row3[i] = passCount + "";
|
||||
row4[i] = total + "";
|
||||
@@ -1554,8 +1555,8 @@ public class AdPlanServiceImpl extends ServiceImpl<AdPlanMapper, AdPlan> impleme
|
||||
}
|
||||
|
||||
// 检测脚本
|
||||
List<Map<String, Object>> maps1 = pqScriptService.listAllPqScript(null);
|
||||
List<String> scriptNameList = maps1.stream().map(m -> (String) m.get("name")).collect(Collectors.toList());
|
||||
List<PqScript> pqScriptList = pqScriptService.listAllPqScript(null);
|
||||
List<String> scriptNameList = pqScriptList.stream().map(m -> m.getName()).collect(Collectors.toList());
|
||||
pullDown = new PullDown();
|
||||
pullDown.setFirstCol(3);
|
||||
pullDown.setLastCol(3);
|
||||
@@ -1721,8 +1722,8 @@ public class AdPlanServiceImpl extends ServiceImpl<AdPlanMapper, AdPlan> impleme
|
||||
String zipFileName = URLEncoder.encode(subPlan.getName() + ".zip", "UTF-8");
|
||||
File zipFile = FileUtil.file(tempDir, zipFileName);
|
||||
|
||||
// 先将json文件添加到zip中
|
||||
ZipUtil.zip(jsonFile.getAbsolutePath(), zipFile.getAbsolutePath());
|
||||
// 先将json文件添加到zip中(使用UTF-8编码)
|
||||
ZipUtil.zip(zipFile, CharsetUtil.CHARSET_UTF_8, false, jsonFile);
|
||||
|
||||
|
||||
// 创建一个临时目录存放两个文件
|
||||
@@ -1744,8 +1745,8 @@ public class AdPlanServiceImpl extends ServiceImpl<AdPlanMapper, AdPlan> impleme
|
||||
}
|
||||
|
||||
|
||||
// 重新创建zip文件,包含所有文件
|
||||
ZipUtil.zip(tempZipDir.getAbsolutePath(), zipFile.getAbsolutePath());
|
||||
// 重新创建zip文件,包含所有文件,使用UTF-8编码
|
||||
ZipUtil.zip(zipFile, CharsetUtil.CHARSET_UTF_8, false, FileUtil.file(tempZipDir));
|
||||
|
||||
// 删除临时目录
|
||||
FileUtil.del(tempZipDir);
|
||||
@@ -1779,9 +1780,9 @@ public class AdPlanServiceImpl extends ServiceImpl<AdPlanMapper, AdPlan> impleme
|
||||
File zipFile = FileUtil.file(tempDir, file.getOriginalFilename());
|
||||
file.transferTo(zipFile);
|
||||
|
||||
// 解压zip文件
|
||||
// 解压zip文件,使用UTF-8编码
|
||||
File unzipDir = FileUtil.mkdir(FileUtil.file(tempDir, "unzip"));
|
||||
ZipUtil.unzip(zipFile.getAbsolutePath(), unzipDir.getAbsolutePath());
|
||||
ZipUtil.unzip(zipFile, unzipDir, CharsetUtil.CHARSET_UTF_8);
|
||||
|
||||
// 查找解压目录中的json文件
|
||||
File[] files = unzipDir.listFiles();
|
||||
@@ -2099,8 +2100,8 @@ public class AdPlanServiceImpl extends ServiceImpl<AdPlanMapper, AdPlan> impleme
|
||||
}
|
||||
}
|
||||
|
||||
// 重新创建zip文件,包含所有文件
|
||||
ZipUtil.zip(tempZipDir.getAbsolutePath(), zipFile.getAbsolutePath());
|
||||
// 重新创建zip文件,包含所有文件,使用UTF-8编码
|
||||
ZipUtil.zip(zipFile, CharsetUtil.CHARSET_UTF_8, false, FileUtil.file(tempZipDir));
|
||||
|
||||
// 删除临时目录
|
||||
FileUtil.del(tempZipDir);
|
||||
|
||||
@@ -73,8 +73,9 @@ public enum DetectionResponseEnum {
|
||||
MONITOR_NUM_REPEAT("A02094", "该被检设备下存在相同线路号的监测点"),
|
||||
PLAN_HAS_CHILDREN("A02095", "该计划下存在子计划,请先删除子计划"),
|
||||
PLAN_REPEATED_IN_SAME_LEVEL("A02096", "该父计划下存在同名的子计划"),
|
||||
PLEASE_UNASSIGN_STANDARD_DEV("A02097","存在已分配给子计划的标准设备,请先解除分配" ),
|
||||
PLEASE_UNASSIGN_DEVICE("A02098", "存在已分配给计划的被检设备,请先解除分配");
|
||||
PLEASE_UNASSIGN_STANDARD_DEV("A02097", "存在已分配给子计划的标准设备,请先解除分配"),
|
||||
PLEASE_UNASSIGN_DEVICE("A02098", "存在已分配给计划的被检设备,请先解除分配"),
|
||||
DEV_IP_PORT_EXIST("A02099", "存在重复被检设备");
|
||||
|
||||
private final String code;
|
||||
|
||||
|
||||
@@ -31,22 +31,22 @@ import java.util.List;
|
||||
* @data 2025/1/9 14:02
|
||||
*/
|
||||
@Slf4j
|
||||
@Api(tags = "报表管理")
|
||||
@Api(tags = "报告管理")
|
||||
@RestController
|
||||
@RequestMapping("/report")
|
||||
@RequiredArgsConstructor
|
||||
public class ReportController extends BaseController {
|
||||
public class ReportController extends BaseController {
|
||||
|
||||
private final IPqReportService pqReportService;
|
||||
|
||||
/**
|
||||
* 此方法临时的,给楼下使用,实际需要优化
|
||||
* 1、不同的设备需要不同的模板;
|
||||
* 2、数据页的内容暂时是固定的,后期可能是动态的;
|
||||
* 2、数据页的内容暂时是固定的,后期可能是动态 的;
|
||||
*/
|
||||
@OperateInfo
|
||||
@PostMapping("/generateReport")
|
||||
@ApiOperation("生成测试报告")
|
||||
@ApiOperation("生成报告")
|
||||
@ApiImplicitParam(name = "param", value = "查询参数", required = true)
|
||||
public HttpResult<Object> generateReport(@RequestBody DevReportParam devReportParam) {
|
||||
String methodDescribe = getMethodDescribe("generateReport");
|
||||
@@ -60,7 +60,7 @@ public class ReportController extends BaseController {
|
||||
*/
|
||||
@OperateInfo
|
||||
@PostMapping("/downloadReport")
|
||||
@ApiOperation("下载测试报告")
|
||||
@ApiOperation("下载报告")
|
||||
@ApiImplicitParam(name = "param", value = "查询参数", required = true)
|
||||
public void downloadReport(@RequestBody DevReportParam devReportParam, HttpServletResponse response) {
|
||||
String methodDescribe = getMethodDescribe("downloadReport");
|
||||
@@ -91,7 +91,7 @@ public class ReportController extends BaseController {
|
||||
@OperateInfo(operateType = OperateType.ADD)
|
||||
@PostMapping("/add")
|
||||
@ApiOperation("新增报告模板")
|
||||
@ApiImplicitParam(name = "param", value = "报告模板参数", required = true)
|
||||
@ApiImplicitParam(name = "reportParam", value = "报告模板参数", required = true)
|
||||
public HttpResult<Boolean> add(ReportParam reportParam) {
|
||||
String methodDescribe = getMethodDescribe("add");
|
||||
LogUtil.njcnDebug(log, "{},新增参数为:{}", methodDescribe, reportParam);
|
||||
@@ -106,7 +106,7 @@ public class ReportController extends BaseController {
|
||||
@OperateInfo(operateType = OperateType.UPDATE)
|
||||
@PostMapping("/update")
|
||||
@ApiOperation("更新报告模板")
|
||||
@ApiImplicitParam(name = "param", value = "报告模板参数", required = true)
|
||||
@ApiImplicitParam(name = "reportParam", value = "报告模板参数", required = true)
|
||||
public HttpResult<Boolean> update(ReportParam.UpdateParam reportParam) {
|
||||
String methodDescribe = getMethodDescribe("update");
|
||||
LogUtil.njcnDebug(log, "{},修改参数为:{}", methodDescribe, reportParam);
|
||||
@@ -136,7 +136,6 @@ public class ReportController extends BaseController {
|
||||
@OperateInfo
|
||||
@GetMapping("/listAllName")
|
||||
@ApiOperation("查询所有报告模板名称")
|
||||
@ApiImplicitParam(name = "param", value = "查询参数", required = true)
|
||||
public HttpResult<List<String>> listAllName() {
|
||||
String methodDescribe = getMethodDescribe("listAllName");
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, pqReportService.listAllName(), methodDescribe);
|
||||
@@ -145,7 +144,7 @@ public class ReportController extends BaseController {
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON, operateType = OperateType.UPDATE)
|
||||
@PostMapping("/documented")
|
||||
@ApiOperation("设备归档")
|
||||
@ApiImplicitParam(name = "id", value = "设备id", required = true)
|
||||
@ApiImplicitParam(name = "ids", value = "设备id", required = true)
|
||||
public HttpResult<Boolean> documented(@RequestBody List<String> ids) {
|
||||
String methodDescribe = getMethodDescribe("documented");
|
||||
LogUtil.njcnDebug(log, "{},设备id为:{}", methodDescribe, ids);
|
||||
|
||||
@@ -31,6 +31,7 @@ public enum BaseReportKeyEnum {
|
||||
DAY("day","日"),
|
||||
YEAR_MONTH_DAY("year-month-day","年-月-日"),
|
||||
REPORT_DATE("reportDate","年-月-日"),
|
||||
GD_NAME("gdName","供电部门"),
|
||||
SUB_NAME("subName","变电站"),
|
||||
CHECK_BY("checkBy","检测人"),
|
||||
AUDIT_BY("auditBy","负责人、审核人"),
|
||||
@@ -38,7 +39,10 @@ public enum BaseReportKeyEnum {
|
||||
CREATE_DATE("createDate","生产日期"),
|
||||
TEMPERATURE("temp","温度"),
|
||||
HUMIDITY("hum","相对湿度"),
|
||||
DELEGATE("delegate","委托方");
|
||||
DELEGATE("delegate","委托方"),
|
||||
CREATEDATE("createDate","出厂日期"),
|
||||
HW_VERSION("hardwareVersion","硬件版本"),
|
||||
SW_VERSION("softwareVersion","软件版本");
|
||||
|
||||
private String key;
|
||||
|
||||
|
||||
@@ -39,6 +39,8 @@ import com.njcn.gather.device.service.IPqDevService;
|
||||
import com.njcn.gather.device.service.IPqDevSubService;
|
||||
import com.njcn.gather.err.pojo.po.PqErrSys;
|
||||
import com.njcn.gather.err.service.IPqErrSysService;
|
||||
import com.njcn.gather.monitor.pojo.po.PqMonitor;
|
||||
import com.njcn.gather.monitor.service.IPqMonitorService;
|
||||
import com.njcn.gather.plan.pojo.enums.DataSourceEnum;
|
||||
import com.njcn.gather.plan.pojo.enums.PlanReportStateEnum;
|
||||
import com.njcn.gather.plan.pojo.po.AdPlan;
|
||||
@@ -59,6 +61,7 @@ import com.njcn.gather.report.service.IPqReportService;
|
||||
import com.njcn.gather.result.service.IResultService;
|
||||
import com.njcn.gather.script.pojo.vo.PqScriptDtlDataVO;
|
||||
import com.njcn.gather.script.service.IPqScriptDtlsService;
|
||||
import com.njcn.gather.storage.pojo.param.SingleNonHarmParam;
|
||||
import com.njcn.gather.storage.pojo.po.SimAndDigHarmonicResult;
|
||||
import com.njcn.gather.storage.pojo.po.SimAndDigNonHarmonicResult;
|
||||
import com.njcn.gather.storage.service.SimAndDigHarmonicService;
|
||||
@@ -67,6 +70,7 @@ import com.njcn.gather.system.cfg.pojo.enums.SceneEnum;
|
||||
import com.njcn.gather.system.cfg.service.ISysTestConfigService;
|
||||
import com.njcn.gather.system.dictionary.pojo.po.DictData;
|
||||
import com.njcn.gather.system.dictionary.service.IDictDataService;
|
||||
import com.njcn.gather.system.pojo.enums.SystemResponseEnum;
|
||||
import com.njcn.gather.tools.report.model.constant.ReportConstant;
|
||||
import com.njcn.gather.tools.report.service.IWordReportService;
|
||||
import com.njcn.gather.tools.report.util.BookmarkUtil;
|
||||
@@ -85,11 +89,11 @@ import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.net.ftp.FTPClient;
|
||||
import org.apache.commons.net.ftp.FTPReply;
|
||||
import org.apache.poi.xwpf.usermodel.XWPFDocument;
|
||||
import org.docx4j.jaxb.Context;
|
||||
import org.docx4j.openpackaging.packages.WordprocessingMLPackage;
|
||||
import org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart;
|
||||
import org.docx4j.wml.*;
|
||||
import org.docx4j.wml.Color;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
@@ -109,9 +113,11 @@ import java.math.BigInteger;
|
||||
import java.math.RoundingMode;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.NoSuchFileException;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
@@ -161,6 +167,8 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
|
||||
@Value("${qr.gcDev.path}")
|
||||
private String gcDevPath;
|
||||
|
||||
@Value("${report.dateFormat}")
|
||||
private String dateFormat;
|
||||
|
||||
private final IPqDevService iPqDevService;
|
||||
private final PqDevMapper pqDevMapper;
|
||||
@@ -178,6 +186,7 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
|
||||
private final ISysUserService sysUserService;
|
||||
private final IPqErrSysService pqErrSysService;
|
||||
private final IAdPlanTestConfigService adPlanTestConfigService;
|
||||
private final IPqMonitorService pqMonitorService;
|
||||
|
||||
@Resource
|
||||
private RestTemplateUtil restTemplateUtil;
|
||||
@@ -306,7 +315,8 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
|
||||
private void uploadFile(ReportParam reportParam, PqReport pqReport, boolean isAdd) {
|
||||
MultipartFile baseFile = reportParam.getBaseFile();
|
||||
MultipartFile detailFile = reportParam.getDetailFile();
|
||||
String newDir = templatePath + File.separator + reportParam.getName() + File.separator + reportParam.getVersion() + File.separator;
|
||||
String relativePath = reportParam.getName() + File.separator + reportParam.getVersion() + File.separator;
|
||||
String newDir = templatePath + File.separator + relativePath;
|
||||
|
||||
long FILE_SIZE_LIMIT = 5 * 1024 * 1024;
|
||||
if (isAdd) {
|
||||
@@ -325,13 +335,13 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
|
||||
throw new BusinessException(ReportResponseEnum.FILE_SIZE_ERROR);
|
||||
}
|
||||
|
||||
pqReport.setBasePath(newDir + baseOriginalFilename);
|
||||
pqReport.setDetailPath(newDir + detailOriginalFilename);
|
||||
pqReport.setBasePath(relativePath + baseOriginalFilename);
|
||||
pqReport.setDetailPath(relativePath + detailOriginalFilename);
|
||||
|
||||
this.createDirectory(newDir);
|
||||
this.clearDirectory(newDir);
|
||||
this.uploadFile(baseFile, pqReport.getBasePath());
|
||||
this.uploadFile(detailFile, pqReport.getDetailPath());
|
||||
this.uploadFile(baseFile, newDir + baseOriginalFilename);
|
||||
this.uploadFile(detailFile, newDir + detailOriginalFilename);
|
||||
} else {
|
||||
throw new BusinessException(ReportResponseEnum.FILE_NOT_NULL);
|
||||
}
|
||||
@@ -379,34 +389,34 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
|
||||
|
||||
//若修改了文件名称、版本号,则需要重命名文件
|
||||
this.createDirectory(newDir);
|
||||
if (!oldDir.equals(newDir)) {
|
||||
if (!oldDir.equals(relativePath)) {
|
||||
// 文件夹重命名
|
||||
String oldBasePathStr = oldPqReport.getBasePath();
|
||||
String baseName = oldBasePathStr.substring(oldBasePathStr.lastIndexOf(File.separator) + 1);
|
||||
Path oldBasePath = Paths.get(oldBasePathStr);
|
||||
Path oldBasePath = Paths.get(templatePath + File.separator + oldBasePathStr);
|
||||
Path newBasePath = Paths.get(newDir + baseName);
|
||||
pqReport.setBasePath(newDir + baseName);
|
||||
pqReport.setBasePath(relativePath + baseName);
|
||||
|
||||
String oldDetailPathStr = oldPqReport.getDetailPath();
|
||||
String detailName = oldDetailPathStr.substring(oldDetailPathStr.lastIndexOf(File.separator) + 1);
|
||||
Path oldDetailPath = Paths.get(oldDetailPathStr);
|
||||
Path oldDetailPath = Paths.get(templatePath + File.separator + oldDetailPathStr);
|
||||
Path newDetailPath = Paths.get(newDir + detailName);
|
||||
pqReport.setDetailPath(newDir + detailName);
|
||||
pqReport.setDetailPath(relativePath + detailName);
|
||||
|
||||
try {
|
||||
// windows下文件夹名称不区分大小写
|
||||
if (!oldDir.equalsIgnoreCase(newDir)) {
|
||||
if (!oldDir.equalsIgnoreCase(relativePath)) {
|
||||
this.clearDirectory(newDir);
|
||||
Files.move(oldBasePath, newBasePath);
|
||||
Files.move(oldDetailPath, newDetailPath);
|
||||
if (!oldPqReport.getName().equals(reportParam.getName()) && !this.existSameName(pqReport.getId(), oldPqReport.getName())) {
|
||||
this.recursionDeleteDirectory(templatePath + File.separator + oldPqReport.getName());
|
||||
} else {
|
||||
Paths.get(oldDir).toFile().delete();
|
||||
Paths.get(templatePath + oldDir).toFile().delete();
|
||||
}
|
||||
} else {
|
||||
// 文件夹重命名
|
||||
Paths.get(oldDir).toFile().renameTo(Paths.get(newDir).toFile());
|
||||
Paths.get(templatePath + oldDir).toFile().renameTo(Paths.get(newDir).toFile());
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new BusinessException(ReportResponseEnum.FILE_RENAME_FAILED);
|
||||
@@ -414,16 +424,16 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
|
||||
}
|
||||
|
||||
if (!baseFileOriginalFilename.isEmpty()) {
|
||||
pqReport.setBasePath(newDir + baseFileOriginalFilename);
|
||||
Paths.get(oldPqReport.getBasePath()).toFile().delete();
|
||||
pqReport.setBasePath(relativePath + baseFileOriginalFilename);
|
||||
Paths.get(templatePath + File.separator + oldPqReport.getBasePath()).toFile().delete();
|
||||
Paths.get(newDir + oldPqReport.getBasePath().substring(oldPqReport.getBasePath().lastIndexOf(File.separator) + 1)).toFile().delete();
|
||||
this.uploadFile(baseFile, pqReport.getBasePath());
|
||||
this.uploadFile(baseFile, newDir + baseFileOriginalFilename);
|
||||
}
|
||||
if (!detailFileOriginalFilename.isEmpty()) {
|
||||
pqReport.setDetailPath(newDir + detailFileOriginalFilename);
|
||||
Paths.get(oldPqReport.getDetailPath()).toFile().delete();
|
||||
pqReport.setDetailPath(relativePath + detailFileOriginalFilename);
|
||||
Paths.get(templatePath + File.separator + oldPqReport.getDetailPath()).toFile().delete();
|
||||
Paths.get(newDir + oldPqReport.getDetailPath().substring(oldPqReport.getDetailPath().lastIndexOf(File.separator) + 1)).toFile().delete();
|
||||
this.uploadFile(detailFile, pqReport.getDetailPath());
|
||||
this.uploadFile(detailFile, newDir + detailFileOriginalFilename);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -571,7 +581,6 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* 根据设备类型生成报告
|
||||
* 注:该方法目前仅支持楼下出厂检测场景,属于模板占位符替换方式,后期可能会有调整
|
||||
*
|
||||
@@ -641,6 +650,13 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
|
||||
}
|
||||
}
|
||||
});
|
||||
} catch (NoSuchFileException e) {
|
||||
String filePath = e.getFile() != null ? e.getFile().replaceAll("\\\\", "/") : "未知文件";
|
||||
log.error("报告模板文件不存在 - 文件路径: {}", filePath, e);
|
||||
throw new BusinessException(SystemResponseEnum.FILE_NOT_FOUND);
|
||||
} catch (IOException e) {
|
||||
log.error("报告文件读写异常", e);
|
||||
throw new BusinessException(SystemResponseEnum.FILE_IO_ERROR);
|
||||
} catch (Exception e) {
|
||||
log.error(ReportResponseEnum.GENERATE_REPORT_ERROR.getMessage(), e);
|
||||
throw new BusinessException(ReportResponseEnum.GENERATE_REPORT_ERROR);
|
||||
@@ -779,46 +795,63 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
|
||||
if (Objects.isNull(pqDevVO)) {
|
||||
throw new BusinessException(ReportResponseEnum.DEVICE_NOT_EXIST);
|
||||
}
|
||||
devReportParam.setDevId(devId);
|
||||
// 获取设备型号
|
||||
DevType devType = devTypeService.getById(pqDevVO.getDevType());
|
||||
if (Objects.isNull(devType)) {
|
||||
throw new BusinessException(ReportResponseEnum.DEVICE_TYPE_NOT_EXIST);
|
||||
}
|
||||
PqReport report = this.lambdaQuery().eq(PqReport::getId, plan.getReportTemplateId()).eq(PqReport::getState, DataStateEnum.ENABLE.getCode()).one();
|
||||
if (Objects.isNull(report)) {
|
||||
throw new BusinessException(ReportResponseEnum.REPORT_TEMPLATE_NOT_EXIST);
|
||||
}
|
||||
Path basePath = Paths.get(report.getBasePath());
|
||||
Path detailPath = Paths.get(report.getDetailPath());
|
||||
try (InputStream baseInputStream = Files.newInputStream(basePath);
|
||||
InputStream detailInputStream = Files.newInputStream(detailPath)) {
|
||||
WordprocessingMLPackage detailModelDocument = WordprocessingMLPackage.load(detailInputStream);
|
||||
// 获取文档基础部分,并替换占位符
|
||||
Map<String, String> baseModelDataMap = dealBaseModelContrastData(plan, pqDevVO, devType);
|
||||
InputStream wordFinishInputStream = wordReportService.replacePlaceholders(baseInputStream, baseModelDataMap);
|
||||
WordprocessingMLPackage baseModelDocument = WordprocessingMLPackage.load(wordFinishInputStream);
|
||||
MainDocumentPart baseDocumentPart = baseModelDocument.getMainDocumentPart();
|
||||
if (CheckStateEnum.CHECKED.getValue().compareTo(pqDevVO.getCheckState()) <= 0) {
|
||||
devReportParam.setDevId(devId);
|
||||
// 获取设备型号
|
||||
DevType devType = devTypeService.getById(pqDevVO.getDevType());
|
||||
if (Objects.isNull(devType)) {
|
||||
throw new BusinessException(ReportResponseEnum.DEVICE_TYPE_NOT_EXIST);
|
||||
}
|
||||
PqReport report = this.lambdaQuery().eq(PqReport::getId, plan.getReportTemplateId()).eq(PqReport::getState, DataStateEnum.ENABLE.getCode()).one();
|
||||
if (Objects.isNull(report)) {
|
||||
throw new BusinessException(ReportResponseEnum.REPORT_TEMPLATE_NOT_EXIST);
|
||||
}
|
||||
Path basePath = Paths.get(templatePath + File.separator + report.getBasePath());
|
||||
Path detailPath = Paths.get(templatePath + File.separator + report.getDetailPath());
|
||||
try (InputStream baseInputStream = Files.newInputStream(basePath);
|
||||
InputStream detailInputStream = Files.newInputStream(detailPath)) {
|
||||
WordprocessingMLPackage detailModelDocument = WordprocessingMLPackage.load(detailInputStream);
|
||||
// 获取文档基础部分,并替换占位符
|
||||
Map<String, String> baseModelDataMap = dealBaseModelContrastData(plan, pqDevVO, devType);
|
||||
InputStream wordFinishInputStream = wordReportService.replacePlaceholders(baseInputStream, baseModelDataMap);
|
||||
WordprocessingMLPackage baseModelDocument = WordprocessingMLPackage.load(wordFinishInputStream);
|
||||
MainDocumentPart baseDocumentPart = baseModelDocument.getMainDocumentPart();
|
||||
|
||||
// 获取数据模版页内容,根据脚本动态组装数据页内容
|
||||
MainDocumentPart detailDocumentPart = detailModelDocument.getMainDocumentPart();
|
||||
dealDataModelScatteredByBookmarkByPlanContrast(baseDocumentPart, detailDocumentPart, devReportParam, pqDevVO);
|
||||
// 保存新的文档
|
||||
String dirPath = reportPath.concat(File.separator).concat(plan.getName());
|
||||
// 确保目录存在
|
||||
ensureDirectoryExists(dirPath);
|
||||
// 构建文件名:cityName_gdName_subName_name.docx
|
||||
String fileName = String.format("%s_%s_%s_%s.docx",
|
||||
pqDevVO.getCityName() != null ? pqDevVO.getCityName() : "未知地市",
|
||||
pqDevVO.getGdName() != null ? pqDevVO.getGdName() : "未知供电公司",
|
||||
pqDevVO.getSubName() != null ? pqDevVO.getSubName() : "未知电站",
|
||||
pqDevVO.getName() != null ? pqDevVO.getName() : "未知设备");
|
||||
Docx4jUtil.cleanBlankPagesAndRedundantPageBreaks(baseModelDocument);
|
||||
baseModelDocument.save(new File(dirPath.concat(File.separator).concat(fileName)));
|
||||
this.updateDevAndPlanState(devId, devReportParam.getPlanId());
|
||||
} catch (Exception e) {
|
||||
log.error(ReportResponseEnum.GENERATE_REPORT_ERROR.getMessage(), e);
|
||||
throw new BusinessException(ReportResponseEnum.GENERATE_REPORT_ERROR);
|
||||
// 获取数据模版页内容,根据脚本动态组装数据页内容
|
||||
MainDocumentPart detailDocumentPart = detailModelDocument.getMainDocumentPart();
|
||||
dealDataModelScatteredByBookmarkByPlanContrast(baseDocumentPart, detailDocumentPart, devReportParam, pqDevVO);
|
||||
// 保存新的文档
|
||||
String dirPath = reportPath.concat(File.separator).concat(plan.getName());
|
||||
// 确保目录存在
|
||||
ensureDirectoryExists(dirPath);
|
||||
// 构建文件名:cityName_gdName_subName_name.docx
|
||||
String fileName = String.format("%s_%s_%s_%s.docx",
|
||||
pqDevVO.getCityName() != null ? pqDevVO.getCityName() : "未知地市",
|
||||
pqDevVO.getGdName() != null ? pqDevVO.getGdName() : "未知供电公司",
|
||||
pqDevVO.getSubName() != null ? pqDevVO.getSubName() : "未知电站",
|
||||
pqDevVO.getName() != null ? pqDevVO.getName() : "未知设备");
|
||||
// 判断是否需要在报告上输出水印
|
||||
String leader = baseModelDataMap.get(BaseReportKeyEnum.AUDIT_BY.getKey());
|
||||
String loginName = RequestUtil.getLoginNameByToken();
|
||||
SysUser user = sysUserService.getUserByLoginName(loginName);
|
||||
if (!leader.equals(user.getName())) {
|
||||
log.info("当前用户不是审核人,添加非正式水印");
|
||||
Docx4jUtil.addWatermarkToDocument(baseModelDocument, "非正式");
|
||||
}
|
||||
Docx4jUtil.cleanBlankPagesAndRedundantPageBreaks(baseModelDocument);
|
||||
baseModelDocument.save(new File(dirPath.concat(File.separator).concat(fileName)));
|
||||
this.updateDevAndPlanState(devId, devReportParam.getPlanId());
|
||||
} catch (NoSuchFileException e) {
|
||||
String filePath = e.getFile() != null ? e.getFile().replaceAll("\\\\", "/") : "未知文件";
|
||||
log.error("报告模板文件不存在 - 文件路径: {}", filePath, e);
|
||||
throw new BusinessException(SystemResponseEnum.FILE_NOT_FOUND);
|
||||
} catch (IOException e) {
|
||||
log.error("报告文件读写异常", e);
|
||||
throw new BusinessException(SystemResponseEnum.FILE_IO_ERROR);
|
||||
} catch (Exception e) {
|
||||
log.error(ReportResponseEnum.GENERATE_REPORT_ERROR.getMessage(), e);
|
||||
throw new BusinessException(ReportResponseEnum.GENERATE_REPORT_ERROR);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -850,8 +883,8 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
|
||||
if (Objects.isNull(report)) {
|
||||
throw new BusinessException(ReportResponseEnum.REPORT_TEMPLATE_NOT_EXIST);
|
||||
}
|
||||
Path basePath = Paths.get(report.getBasePath());
|
||||
Path detailPath = Paths.get(report.getDetailPath());
|
||||
Path basePath = Paths.get(templatePath + File.separator + report.getBasePath());
|
||||
Path detailPath = Paths.get(templatePath + File.separator + report.getDetailPath());
|
||||
try (InputStream baseInputStream = Files.newInputStream(basePath);
|
||||
InputStream detailInputStream = Files.newInputStream(detailPath)) {
|
||||
WordprocessingMLPackage detailModelDocument = WordprocessingMLPackage.load(detailInputStream);
|
||||
@@ -871,6 +904,13 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
|
||||
ensureDirectoryExists(dirPath);
|
||||
baseModelDocument.save(new File(dirPath.concat(File.separator).concat(pqDevVO.getCreateId()).concat(ReportConstant.DOCX)));
|
||||
this.updateDevAndPlanState(devId, devReportParam.getPlanId());
|
||||
} catch (NoSuchFileException e) {
|
||||
String filePath = e.getFile() != null ? e.getFile().replaceAll("\\\\", "/") : "未知文件";
|
||||
log.error("报告模板文件不存在 - 文件路径: {}", filePath, e);
|
||||
throw new BusinessException(SystemResponseEnum.FILE_NOT_FOUND);
|
||||
} catch (IOException e) {
|
||||
log.error("报告文件读写异常", e);
|
||||
throw new BusinessException(SystemResponseEnum.FILE_IO_ERROR);
|
||||
} catch (Exception e) {
|
||||
log.error(ReportResponseEnum.GENERATE_REPORT_ERROR.getMessage(), e);
|
||||
throw new BusinessException(ReportResponseEnum.GENERATE_REPORT_ERROR);
|
||||
@@ -1065,7 +1105,6 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
|
||||
* 实时数据:3秒数据(150周波数据)
|
||||
* 录波:录波数据
|
||||
* 分钟统计数据:分钟统计数据-最大值、分钟统计数据-最小值、分钟统计数据-平均值、分钟统计数据-CP95值
|
||||
*
|
||||
*/
|
||||
private String getDataTypeFromParam(AdPlan adPlan) {
|
||||
String dataSource = adPlan.getDatasourceId();
|
||||
@@ -1088,11 +1127,11 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
|
||||
AdPlanTestConfig adPlanTestConfig = adPlanTestConfigService.getByPlanId(adPlan.getId());
|
||||
StringBuilder sampleCount = new StringBuilder();
|
||||
for (String item : dataSourceArray) {
|
||||
if(item.equalsIgnoreCase(DataSourceEnum.REAL_DATA.getValue())){
|
||||
if (item.equalsIgnoreCase(DataSourceEnum.REAL_DATA.getValue())) {
|
||||
sampleCount.append("实时数据采集").append(adPlanTestConfig.getRealTime()).append("组,");
|
||||
}else if(item.equalsIgnoreCase(DataSourceEnum.WAVE_DATA.getValue())){
|
||||
} else if (item.equalsIgnoreCase(DataSourceEnum.WAVE_DATA.getValue())) {
|
||||
sampleCount.append("录波数据采集").append(adPlanTestConfig.getWaveRecord()).append("组,");
|
||||
}else{
|
||||
} else {
|
||||
sampleCount.append("统计数据采集").append(adPlanTestConfig.getStatistics()).append("组,");
|
||||
}
|
||||
}
|
||||
@@ -1134,10 +1173,11 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
|
||||
Integer monitorNum = next.getKey();
|
||||
// 线路下的指标数据
|
||||
List<ContrastTestResult> contrastTestResults = next.getValue();
|
||||
PqMonitor pqMonitor = pqMonitorService.getByDevIdAndNum(pqDevVO.getId(), monitorNum);
|
||||
// 插入回路号前,先换个页
|
||||
todoInsertList.add(Docx4jUtil.createPageBreakParagraph());
|
||||
// 回路标题
|
||||
todoInsertList.add(getContrastLineTitle(contentMap, monitorNum, stepIndex, factory));
|
||||
todoInsertList.add(getContrastLineTitle(contentMap, monitorNum, stepIndex, factory, pqDevVO));
|
||||
int scriptIndex = 1;
|
||||
for (ContrastTestResult contrastTestResult : contrastTestResults) {
|
||||
// 比如电压 V
|
||||
@@ -1148,7 +1188,7 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
|
||||
// 根据code获取对应需要填充的内容
|
||||
List<Docx4jUtil.HeadingContent> tempContent = contentMap.get(scriptCode);
|
||||
// 需要区分下谐波类和非谐波类
|
||||
List<Object> tempList = fillContentInTemplateContrast(tempContent, factory, contrastTestResult);
|
||||
List<Object> tempList = fillContentInTemplateContrast(tempContent, factory, contrastTestResult, pqMonitor);
|
||||
todoInsertList.addAll(tempList);
|
||||
scriptIndex++;
|
||||
}
|
||||
@@ -1566,18 +1606,37 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
|
||||
|
||||
// 获取现有行的样式
|
||||
Tr existingRow = (Tr) tbl.getContent().get(rows.size() - 1);
|
||||
|
||||
// 获取现有样式
|
||||
TrPr trPr = existingRow.getTrPr();
|
||||
JAXBElement<Tc> element = (JAXBElement<Tc>) existingRow.getContent().get(0);
|
||||
TcPr tcPr = element.getValue().getTcPr();
|
||||
TblWidth cellWidth = factory.createTblWidth();
|
||||
cellWidth.setType("dxa");
|
||||
cellWidth.setW(BigInteger.valueOf(5000 / tableKeys.size()));
|
||||
tcPr.setTcW(cellWidth);
|
||||
// 获取每个单元格的TcPr(保留各单元格独立的边框设置)
|
||||
List<TcPr> tcPrList = new ArrayList<>();
|
||||
RPr templateRPr = null;
|
||||
for (Object cellObj : existingRow.getContent()) {
|
||||
if (cellObj instanceof JAXBElement) {
|
||||
JAXBElement<Tc> cellElement = (JAXBElement<Tc>) cellObj;
|
||||
Tc templateCell = cellElement.getValue();
|
||||
TcPr tcPr = templateCell.getTcPr();
|
||||
// 设置单元格宽度
|
||||
if (tcPr == null) {
|
||||
tcPr = factory.createTcPr();
|
||||
}
|
||||
TblWidth cellWidth = factory.createTblWidth();
|
||||
cellWidth.setType("dxa");
|
||||
cellWidth.setW(BigInteger.valueOf(5000 / tableKeys.size()));
|
||||
tcPr.setTcW(cellWidth);
|
||||
tcPrList.add(tcPr);
|
||||
// 从第一个单元格获取字体样式
|
||||
if (templateRPr == null && !templateCell.getContent().isEmpty() && templateCell.getContent().get(0) instanceof P) {
|
||||
P templateP = (P) templateCell.getContent().get(0);
|
||||
templateRPr = Docx4jUtil.getTcPrFromParagraph(templateP);
|
||||
}
|
||||
}
|
||||
}
|
||||
tbl.getContent().remove(existingRow);
|
||||
// 迭代增加行,需要填充的表格keys在tableKeys集合中
|
||||
for (Map<String, String> stringStringMap : dataList) {
|
||||
Tr newRow = Docx4jUtil.createCustomRow(factory, stringStringMap, tableKeys, trPr, tcPr, true);
|
||||
Tr newRow = Docx4jUtil.createCustomRow(factory, stringStringMap, tableKeys, trPr, tcPrList, templateRPr, true);
|
||||
tbl.getContent().add(newRow);
|
||||
}
|
||||
} else {
|
||||
@@ -1604,7 +1663,7 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private List<Object> fillContentInTemplateContrast(List<Docx4jUtil.HeadingContent> tempContent, ObjectFactory factory, ContrastTestResult contrastTestResult) {
|
||||
private List<Object> fillContentInTemplateContrast(List<Docx4jUtil.HeadingContent> tempContent, ObjectFactory factory, ContrastTestResult contrastTestResult, PqMonitor pqMonitor) {
|
||||
List<Object> todoInsertList = new ArrayList<>();
|
||||
Docx4jUtil.HeadingContent headingContent = tempContent.get(0);
|
||||
List<String> tableKeys = Docx4jUtil.getTableFillKeys(tempContent);
|
||||
@@ -1718,9 +1777,47 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
|
||||
// 纵向表格暂不考虑
|
||||
}
|
||||
|
||||
// 如果存在特殊说明,在表格后添加一个段落
|
||||
if (StrUtil.isNotBlank(contrastTestResult.getSpecialCase())) {
|
||||
P specialCaseP = Docx4jUtil.createSpecialCaseParagraph(factory, contrastTestResult.getSpecialCase());
|
||||
StringBuilder description = new StringBuilder();
|
||||
if (contrastTestResult.getScriptCode().equalsIgnoreCase("I")) {
|
||||
// 获取该通道的额定电流
|
||||
String ct = pqMonitor.getCt();
|
||||
// 理论上ct是 xxx:xxx的格式。比如10:1,100:5
|
||||
if (ct.indexOf(":") > 0) {
|
||||
String[] ctArray = ct.split(":");
|
||||
description.append("注:当前回路额定电流为:").append(ctArray[1]).append("A。");
|
||||
}
|
||||
} else if (contrastTestResult.getScriptCode().equalsIgnoreCase("V")) {
|
||||
// 获取该通道的额定电压
|
||||
String pt = pqMonitor.getPt();
|
||||
// 理论上pt是 xxx:xxx的格式。比如380:380,10000:100
|
||||
if (pt.indexOf(":") > 0) {
|
||||
String[] ptArray = pt.split(":");
|
||||
// 电压需要特殊处理下,处理为相电压值
|
||||
String voltage = ptArray[1];
|
||||
if (voltage.equalsIgnoreCase("100")) {
|
||||
voltage = "57.74";
|
||||
} else if (voltage.equalsIgnoreCase("380")) {
|
||||
voltage = "220";
|
||||
} else {
|
||||
// 其他场景下就除以根号3
|
||||
double result = Double.parseDouble(voltage) / Math.sqrt(3);
|
||||
voltage = doubleRound(2, result);
|
||||
}
|
||||
description.append("注:当前回路额定电流为:").append(voltage).append("V。");
|
||||
}
|
||||
}
|
||||
|
||||
// 如果存在特殊说明,在表格后添加一个段落 如果有电压和电流需要把额定电压和电流标注进来 pqMonitor
|
||||
if (StrUtil.isNotBlank(contrastTestResult.getSpecialCase()) || StrUtil.isNotBlank(description.toString())) {
|
||||
P specialCaseP;
|
||||
if (StrUtil.isNotBlank(description.toString())) {
|
||||
if (StrUtil.isNotBlank(contrastTestResult.getSpecialCase())) {
|
||||
description.append(contrastTestResult.getSpecialCase().replace("注:", ""));
|
||||
}
|
||||
specialCaseP = Docx4jUtil.createSpecialCaseParagraph(factory, description.toString());
|
||||
} else {
|
||||
specialCaseP = Docx4jUtil.createSpecialCaseParagraph(factory, contrastTestResult.getSpecialCase());
|
||||
}
|
||||
todoInsertList.add(specialCaseP);
|
||||
}
|
||||
}
|
||||
@@ -1805,10 +1902,10 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
|
||||
if (dictDataById != null && "Contrast".equals(dictDataById.getCode())) {
|
||||
// 比对模式:使用新的路径结构
|
||||
String fileName = String.format("%s_%s_%s_%s.docx",
|
||||
pqDevVO.getCityName() != null ? pqDevVO.getCityName() : "未知地市",
|
||||
pqDevVO.getGdName() != null ? pqDevVO.getGdName() : "未知供电公司",
|
||||
pqDevVO.getSubName() != null ? pqDevVO.getSubName() : "未知电站",
|
||||
pqDevVO.getName() != null ? pqDevVO.getName() : "未知设备");
|
||||
pqDevVO.getCityName() != null ? pqDevVO.getCityName() : "未知地市",
|
||||
pqDevVO.getGdName() != null ? pqDevVO.getGdName() : "未知供电公司",
|
||||
pqDevVO.getSubName() != null ? pqDevVO.getSubName() : "未知电站",
|
||||
pqDevVO.getName() != null ? pqDevVO.getName() : "未知设备");
|
||||
filePath = reportPath.concat(File.separator).concat(plan.getName()).concat(File.separator).concat(fileName);
|
||||
downloadFileName = fileName;
|
||||
} else {
|
||||
@@ -1837,7 +1934,7 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
|
||||
try {
|
||||
// 对中文文件名进行URL编码// 将+号替换为%20(空格的正确编码)
|
||||
String encodedFileName = URLEncoder.encode(downloadFileName, "UTF-8")
|
||||
.replaceAll("\\+", "%20");
|
||||
.replaceAll("\\+", "%20");
|
||||
|
||||
// 使用RFC 5987标准格式
|
||||
response.setHeader("Content-Disposition",
|
||||
@@ -1879,12 +1976,12 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
|
||||
|
||||
for (int i = 0; i < pqDevVOList.size(); i++) {
|
||||
pqDevVO = pqDevVOList.get(i);
|
||||
tempPqDevVO = pqDevVO;
|
||||
if (!pqDevVO.getCheckState().equals(CheckStateEnum.CHECKED.getValue())) {
|
||||
throw new BusinessException(DetectionResponseEnum.DEV_UN_CHECKED);
|
||||
}
|
||||
if (!pqDevVO.getReportState().equals(DevReportStateEnum.GENERATED.getValue())) {
|
||||
devIds.add(pqDevVO.getId());
|
||||
tempPqDevVO = pqDevVO;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1928,6 +2025,18 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
|
||||
baseModelMap.put(BaseReportKeyEnum.DEV_TYPE.getKey(), devType.getName());
|
||||
// 检测员
|
||||
baseModelMap.put(BaseReportKeyEnum.INSPECTOR.getKey(), pqDevVO.getCheckBy() + "");
|
||||
baseModelMap.put(BaseReportKeyEnum.INSPECTOR.getKey(), pqDevVO.getCheckBy() + "");
|
||||
String datePattern = DatePattern.NORM_DATE_PATTERN;
|
||||
if (DatePattern.CHINESE_DATE_PATTERN.equals(dateFormat)) {
|
||||
datePattern = DatePattern.CHINESE_DATE_PATTERN;
|
||||
}
|
||||
|
||||
// 出厂日期
|
||||
baseModelMap.put(BaseReportKeyEnum.CREATEDATE.getKey(), pqDevVO.getCreateDate().format(DateTimeFormatter.ofPattern(datePattern)));
|
||||
// 硬件版本
|
||||
baseModelMap.put(BaseReportKeyEnum.HW_VERSION.getKey(), StrUtil.isNotBlank(pqDevVO.getHardwareVersion()) ? pqDevVO.getHardwareVersion() : StrUtil.EMPTY);
|
||||
// 软件版本
|
||||
baseModelMap.put(BaseReportKeyEnum.SW_VERSION.getKey(), StrUtil.isNotBlank(pqDevVO.getSoftwareVersion()) ? pqDevVO.getSoftwareVersion() : StrUtil.EMPTY);
|
||||
// 调试日期
|
||||
if (pqDevVO.getCheckTime() != null) {
|
||||
baseModelMap.put(BaseReportKeyEnum.TEST_DATE.getKey(), DateUtil.format(pqDevVO.getCheckTime(), DatePattern.CHINESE_DATE_PATTERN));
|
||||
@@ -1986,7 +2095,6 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* 比对模式下需要获取的数据
|
||||
* 处理基础模版中的信息,非数据页报告
|
||||
* 因为Docx4j工具包替换时会默认增加${}
|
||||
@@ -1997,7 +2105,7 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
|
||||
// 委托方
|
||||
String delegate = pqDevVO.getDelegate();
|
||||
if (StrUtil.isNotBlank(delegate)) {
|
||||
DictData delegateDictData = dictDataService.getDictDataById(pqDevVO.getManufacturer());
|
||||
DictData delegateDictData = dictDataService.getDictDataById(pqDevVO.getDelegate());
|
||||
if (ObjectUtil.isNotNull(delegateDictData)) {
|
||||
baseModelMap.put(BaseReportKeyEnum.DELEGATE.getKey(), delegateDictData.getName());
|
||||
} else {
|
||||
@@ -2010,6 +2118,8 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
|
||||
baseModelMap.put(BaseReportKeyEnum.SAMPLE_ID.getKey(), StrUtil.isEmpty(pqDevVO.getName()) ? StrPool.TAB : pqDevVO.getName());
|
||||
// 报告日期
|
||||
baseModelMap.put(BaseReportKeyEnum.REPORT_DATE.getKey(), DateUtil.format(new Date(), DatePattern.CHINESE_DATE_PATTERN));
|
||||
// 供电部门
|
||||
baseModelMap.put(BaseReportKeyEnum.GD_NAME.getKey(), pqDevVO.getGdName());
|
||||
// 变电站名称
|
||||
baseModelMap.put(BaseReportKeyEnum.SUB_NAME.getKey(), pqDevVO.getSubName());
|
||||
// 检测人
|
||||
@@ -2067,7 +2177,19 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
|
||||
private void dealDataModel(List<InputStream> wordFileInputStreams, DevReportParam devReportParam, PqDevVO pqDevVO) throws Exception {
|
||||
Integer devChns = pqDevVO.getDevChns();
|
||||
for (int i = 1; i <= devChns; i++) {
|
||||
ClassPathResource resource = new ClassPathResource("/model/report_table.docx");
|
||||
String path = "/model/report_table.docx";
|
||||
DevType devType = devTypeService.getById(pqDevVO.getDevType());
|
||||
if (devType.getName().equals("PQ-COM")) {
|
||||
path = "/model/report_table - PQ-COM.docx";
|
||||
}
|
||||
ClassPathResource resource = new ClassPathResource(path);
|
||||
XWPFDocument dataModelDocumentTemp = new XWPFDocument(resource.getInputStream());
|
||||
|
||||
SingleNonHarmParam singleNonHarmParam = new SingleNonHarmParam();
|
||||
singleNonHarmParam.setPlanCode(devReportParam.getPlanCode());
|
||||
singleNonHarmParam.setDevId(pqDevVO.getId());
|
||||
singleNonHarmParam.setChannelNo(i);
|
||||
|
||||
// 获取数据
|
||||
Map<String, String> dataModelMap = new HashMap<>(16);
|
||||
// 读取模板文件中的占位符
|
||||
@@ -2085,11 +2207,20 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
|
||||
List<SimAndDigHarmonicResult> adHarmonicResultList = adHarmonicService.listAllResultData(devReportParam.getScriptId(), devReportParam.getPlanCode(), devReportParam.getDevId() + "_" + i);
|
||||
|
||||
// 填充数据
|
||||
int finalI = i;
|
||||
indexKeysMap.forEach((index, keys) -> {
|
||||
String s1 = keys.stream().findFirst().get();
|
||||
// 谐波类
|
||||
if (DetectionCodeEnum.V2_50.getCode().equals(s1) || DetectionCodeEnum.I2_50.getCode().equals(s1) || DetectionCodeEnum.SV_1_49.getCode().equals(s1) || DetectionCodeEnum.SI_1_49.getCode().equals(s1)) {
|
||||
fillMapValueHarm(adHarmonicResultList, dataModelMap, keys, index);
|
||||
// 查找一下U1
|
||||
double u1 = 57.74;
|
||||
List<SimAndDigHarmonicResult> rawData = adHarmonicService.listAllRawData(devReportParam.getScriptId(), devReportParam.getPlanCode(), devReportParam.getDevId() + "_" + finalI);
|
||||
SimAndDigHarmonicResult adHarmonicResult = rawData.stream().filter(obj -> obj.getAdType().equals(DetectionCodeEnum.V2_50.getCode())).sorted((obj1, obj2) -> obj2.getTimeId().compareTo(obj1.getTimeId())).findFirst().orElse(null);
|
||||
if (ObjectUtil.isNotNull(adHarmonicResult)) {
|
||||
String aValue1 = adHarmonicResult.getAValue1();
|
||||
u1 = Double.parseDouble(aValue1);
|
||||
}
|
||||
fillMapValueHarm(adHarmonicResultList, dataModelMap, keys, index, u1);
|
||||
} else {
|
||||
// 非谐波类
|
||||
if (DetectionCodeEnum.V_UNBAN.getCode().equals(s1) || DetectionCodeEnum.FREQ.getCode().equals(s1)) {
|
||||
@@ -2157,14 +2288,14 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
|
||||
* @param keys key
|
||||
* @param index index
|
||||
*/
|
||||
private void fillMapValueHarm(List<SimAndDigHarmonicResult> allHarmonicResultList, Map<String, String> dataModelMap, Set<String> keys, String index) {
|
||||
private void fillMapValueHarm(List<SimAndDigHarmonicResult> allHarmonicResultList, Map<String, String> dataModelMap, Set<String> keys, String index, double baseValue) {
|
||||
keys.forEach(key -> {
|
||||
List<SimAndDigHarmonicResult> resultList = allHarmonicResultList.stream().filter(obj -> obj.getAdType().equals(key) && obj.getSort().toString().equals(index)).collect(Collectors.toList());
|
||||
if (CollectionUtil.isNotEmpty(resultList)) {
|
||||
SimAndDigHarmonicResult adHarmonicResult = resultList.get(0);
|
||||
if (Objects.nonNull(adHarmonicResult)) {
|
||||
if (DetectionCodeEnum.V2_50.getCode().equals(key) || DetectionCodeEnum.SV_1_49.getCode().equals(key)) {
|
||||
fillHarm(dataModelMap, adHarmonicResult, index, key, 57.74, 100);
|
||||
fillHarm(dataModelMap, adHarmonicResult, index, key, baseValue, 100);
|
||||
}
|
||||
if (DetectionCodeEnum.I2_50.getCode().equals(key) || DetectionCodeEnum.SI_1_49.getCode().equals(key)) {
|
||||
fillHarm(dataModelMap, adHarmonicResult, index, key, 1, 1);
|
||||
@@ -2371,16 +2502,21 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
|
||||
/**
|
||||
* 创建回路标题到报告中
|
||||
*/
|
||||
private P getContrastLineTitle(Map<String, List<Docx4jUtil.HeadingContent>> contentMap, int monitorNum, int index, ObjectFactory factory) {
|
||||
private P getContrastLineTitle(Map<String, List<Docx4jUtil.HeadingContent>> contentMap, int monitorNum, int index, ObjectFactory factory, PqDevVO pqDevVO) {
|
||||
PqMonitor pqMonitor = pqMonitorService.getByDevIdAndNum(pqDevVO.getId(), monitorNum);
|
||||
String monitorInfoName = "";
|
||||
if (StrUtil.isNotBlank(pqDevVO.getSubName()) && Objects.nonNull(pqMonitor)) {
|
||||
monitorInfoName = "(" + pqDevVO.getSubName() + "-" + pqMonitor.getName() + ")";
|
||||
}
|
||||
List<Docx4jUtil.HeadingContent> headingContents = contentMap.get(PowerIndexEnum.LINE_TITLE.getKey());
|
||||
// 如果contentMap中有指定内容,创建大纲级别为2的标题
|
||||
if (CollUtil.isNotEmpty(headingContents)) {
|
||||
return Docx4jUtil.createTitle(factory, 2, index + ".测量回路" + monitorNum,
|
||||
return Docx4jUtil.createTitle(factory, 2, index + ".测量回路" + monitorNum + monitorInfoName,
|
||||
"SimSun", 30, true);
|
||||
}
|
||||
// 没有模板配置时,创建默认样式段落
|
||||
P titleParagraph = factory.createP();
|
||||
Docx4jUtil.createTitle(factory, titleParagraph, "测量回路" + monitorNum,
|
||||
Docx4jUtil.createTitle(factory, titleParagraph, "测量回路" + monitorNum + monitorInfoName,
|
||||
28, true);
|
||||
return titleParagraph;
|
||||
}
|
||||
|
||||
@@ -90,7 +90,7 @@ public class ResultController extends BaseController {
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON, operateType = OperateType.UPDATE)
|
||||
@PostMapping("/reCalculate")
|
||||
@ApiOperation("重新计算检测结果")
|
||||
@ApiImplicitParam(name = "queryParam", value = "查询参数", required = true)
|
||||
@ApiImplicitParam(name = "param", value = "重新计算参数", required = true)
|
||||
public HttpResult<Object> reCalculate(@RequestBody @Validated ResultParam.ChangeErrorSystemParam param) {
|
||||
String methodDescribe = getMethodDescribe("reCalculate");
|
||||
LogUtil.njcnDebug(log, "{},查询数据为:{}", methodDescribe, param);
|
||||
@@ -115,7 +115,7 @@ public class ResultController extends BaseController {
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON, operateType = OperateType.DELETE)
|
||||
@GetMapping("/deleteTempTable")
|
||||
@ApiOperation("删除临时表")
|
||||
@ApiImplicitParam(name = "param", value = "删除参数", required = true)
|
||||
@ApiImplicitParam(name = "code", value = "计划对应的表后缀code", required = true)
|
||||
public HttpResult<Object> deleteTempTable(@RequestParam("code") String code) {
|
||||
String methodDescribe = getMethodDescribe("deleteTempTable");
|
||||
LogUtil.njcnDebug(log, "{},查询数据为:{}", methodDescribe, code);
|
||||
@@ -127,7 +127,7 @@ public class ResultController extends BaseController {
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
@PostMapping("/getContrastFormContent")
|
||||
@ApiOperation("获取比对式检测结果-表单内容")
|
||||
@ApiImplicitParam(name = "param", value = "查询参数", required = true)
|
||||
@ApiImplicitParam(name = "queryParam", value = "查询参数", required = true)
|
||||
public HttpResult<FormContentVO> getContrastFormContent(@RequestBody @Validated ResultParam.QueryParam queryParam) {
|
||||
String methodDescribe = getMethodDescribe("getContrastFormContent");
|
||||
LogUtil.njcnDebug(log, "{},查询数据为:{}", methodDescribe, queryParam);
|
||||
@@ -139,7 +139,7 @@ public class ResultController extends BaseController {
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
@PostMapping("/getContrastResult")
|
||||
@ApiOperation("获取比对式检测结果")
|
||||
@ApiImplicitParam(name = "param", value = "查询参数", required = true)
|
||||
@ApiImplicitParam(name = "queryParam", value = "查询参数", required = true)
|
||||
public HttpResult<ContrastResultVO> getContrastResult(@RequestBody @Validated ResultParam.QueryParam queryParam) {
|
||||
String methodDescribe = getMethodDescribe("getContrastResult");
|
||||
LogUtil.njcnDebug(log, "{},查询数据为:{}", methodDescribe, queryParam);
|
||||
@@ -154,7 +154,7 @@ public class ResultController extends BaseController {
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
@PostMapping("/getMonitorResult")
|
||||
@ApiOperation("获取监测点的检测结果")
|
||||
@ApiImplicitParam(name = "param", value = "查询参数", required = true)
|
||||
@ApiImplicitParam(name = "devId", value = "设备id", required = true)
|
||||
public HttpResult<List<MonitorResultVO>> getMonitorResult(@RequestParam("devId") String devId) {
|
||||
String methodDescribe = getMethodDescribe("getMonitorResult");
|
||||
LogUtil.njcnDebug(log, "{},查询数据为:{}", methodDescribe, devId);
|
||||
@@ -180,7 +180,7 @@ public class ResultController extends BaseController {
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
@PostMapping("/updateMonitorResult")
|
||||
@ApiOperation("更新监测点的检测结果")
|
||||
@ApiImplicitParam(name = "result", value = "更新内容", required = true)
|
||||
@ApiImplicitParam(name = "resultParams", value = "更新内容", required = true)
|
||||
public HttpResult<Boolean> updateMonitorResult(@RequestBody @Validated MonitorResultVO resultParams) {
|
||||
String methodDescribe = getMethodDescribe("updateMonitorResult");
|
||||
LogUtil.njcnDebug(log, "{},更新数据为:{}", methodDescribe, resultParams);
|
||||
@@ -198,7 +198,7 @@ public class ResultController extends BaseController {
|
||||
String methodDescribe = getMethodDescribe("getCheckItem");
|
||||
|
||||
LogUtil.njcnDebug(log, "{},查询数据为:{}", methodDescribe, monitorQueryParam);
|
||||
List<ContrastTestItemVO> result = resultService.getCheckItem(monitorQueryParam.getDevId(),monitorQueryParam.getChnNum(), monitorQueryParam.getNum());
|
||||
List<ContrastTestItemVO> result = resultService.getCheckItem(monitorQueryParam.getPlanId(), monitorQueryParam.getDevId(), monitorQueryParam.getChnNum(), monitorQueryParam.getNum(), monitorQueryParam.getCode());
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,4 +15,8 @@ public class MonitorQueryParam {
|
||||
private Integer num;
|
||||
|
||||
private Integer waveNum;
|
||||
|
||||
private String planId;
|
||||
|
||||
private String code;
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.njcn.gather.result.pojo.param;
|
||||
|
||||
import com.njcn.common.pojo.constant.PatternRegex;
|
||||
import com.njcn.gather.pojo.constant.DetectionValidMessage;
|
||||
import io.swagger.annotations.ApiImplicitParams;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
@@ -74,6 +75,8 @@ public class ResultParam {
|
||||
|
||||
// 模式id
|
||||
private String patternId;
|
||||
|
||||
private String code;
|
||||
}
|
||||
|
||||
@Data
|
||||
@@ -83,7 +86,7 @@ public class ResultParam {
|
||||
@Pattern(regexp = PatternRegex.SYSTEM_ID, message = DetectionValidMessage.PLAN_ID_FORMAT_ERROR)
|
||||
private String planId;
|
||||
|
||||
@ApiModelProperty(value = "脚本Id", required = false)
|
||||
@ApiModelProperty(value = "脚本Id")
|
||||
private String scriptId;
|
||||
|
||||
@ApiModelProperty(value = "误差体系Id", required = true)
|
||||
@@ -95,9 +98,16 @@ public class ResultParam {
|
||||
@Pattern(regexp = PatternRegex.SYSTEM_ID, message = DetectionValidMessage.DEV_ID_FORMAT_ERROR)
|
||||
private String deviceId;
|
||||
|
||||
@ApiModelProperty(value = "计划对应表后缀", required = true)
|
||||
private String code;
|
||||
|
||||
@ApiModelProperty(value = "模式Id", required = true)
|
||||
private String patternId;
|
||||
|
||||
@ApiModelProperty(value = "通道号", required = true)
|
||||
private String chnNum;
|
||||
|
||||
@ApiModelProperty(value = "数据处理原则", required = true)
|
||||
private String dataRuleId;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,58 +14,38 @@ import javax.validation.constraints.NotNull;
|
||||
@Data
|
||||
public class MonitorResultVO implements Comparable<MonitorResultVO> {
|
||||
|
||||
/**
|
||||
* 监测点id
|
||||
*/
|
||||
@ApiModelProperty(value = "监测点id", required = true)
|
||||
@NotBlank(message = DetectionValidMessage.DEV_MONITOR_ID_NOT_BLANK)
|
||||
private String monitorId;
|
||||
|
||||
/**
|
||||
* 监测点序号
|
||||
*/
|
||||
@ApiModelProperty(value = "监测点序号")
|
||||
private Integer monitorNum;
|
||||
|
||||
/**
|
||||
* 总检测次数
|
||||
*/
|
||||
@ApiModelProperty(value = "总检测次数")
|
||||
private Integer totalNum;
|
||||
|
||||
/**
|
||||
* 合格检测次数
|
||||
*/
|
||||
@ApiModelProperty(value = "合格检测次数")
|
||||
private Integer qualifiedNum;
|
||||
|
||||
/**
|
||||
* 不合格检测次数
|
||||
*/
|
||||
@ApiModelProperty(value = "不合格检测次数")
|
||||
private Integer unQualifiedNum;
|
||||
|
||||
/**
|
||||
* 误差体系名称
|
||||
*/
|
||||
@ApiModelProperty(value = "误差体系名称")
|
||||
private String errorSysName;
|
||||
|
||||
/**
|
||||
* 检测结果
|
||||
*/
|
||||
@ApiModelProperty(value = "检测结果", required = true)
|
||||
@NotNull(message = DetectionValidMessage.DEV_MONITOR_RESULT_NOT_NULL)
|
||||
private Integer checkResult;
|
||||
|
||||
/**
|
||||
* 结论来源
|
||||
*/
|
||||
|
||||
@ApiModelProperty(value = "结论来源")
|
||||
private String resultOrigin;
|
||||
/**
|
||||
* 哪次
|
||||
*/
|
||||
|
||||
@ApiModelProperty(value = "使用哪次检测结果", required = true)
|
||||
@NotNull(message = DetectionValidMessage.DEV_MONITOR_RESULT_NUM_NOT_BLANK)
|
||||
private String whichTime;
|
||||
/**
|
||||
* 数据源类型
|
||||
*/
|
||||
|
||||
|
||||
@ApiModelProperty(value = "数据源类型", required = true)
|
||||
@NotBlank(message = DetectionValidMessage.DEV_MONITOR_RESULT_TYPE_NOT_BLANK)
|
||||
private String resultType;
|
||||
|
||||
@@ -119,17 +119,20 @@ public interface IResultService {
|
||||
/**
|
||||
* 获取检测项
|
||||
*
|
||||
* @param planId
|
||||
* @param devId
|
||||
* @param chnNum
|
||||
* @param num
|
||||
* @param code
|
||||
* @return
|
||||
*/
|
||||
List<ContrastTestItemVO> getCheckItem(String devId, String chnNum, Integer num);
|
||||
List<ContrastTestItemVO> getCheckItem(String planId, String devId, String chnNum, Integer num,String code);
|
||||
|
||||
/**
|
||||
* 获取设备比对式结果,用于出比对检测的报告
|
||||
*
|
||||
* @param devReportParam 设备报告参数
|
||||
* @param pqDevVO 设备信息 省去一次sql查询
|
||||
* @param pqDevVO 设备信息 省去一次sql查询
|
||||
* @return 该设备的比对式结果
|
||||
*/
|
||||
Map<Integer, List<ContrastTestResult>> getContrastResultForReport(DevReportParam devReportParam, PqDevVO pqDevVO);
|
||||
|
||||
@@ -22,6 +22,7 @@ import com.njcn.common.pojo.exception.BusinessException;
|
||||
import com.njcn.common.utils.PubUtils;
|
||||
import com.njcn.gather.detection.handler.SocketContrastResponseService;
|
||||
import com.njcn.gather.detection.pojo.enums.DetectionCodeEnum;
|
||||
import com.njcn.gather.detection.pojo.enums.ResultEnum;
|
||||
import com.njcn.gather.detection.pojo.param.PreDetectionParam;
|
||||
import com.njcn.gather.detection.pojo.po.AdPair;
|
||||
import com.njcn.gather.detection.pojo.po.DevData;
|
||||
@@ -99,6 +100,8 @@ import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static com.njcn.gather.plan.pojo.enums.DataSourceEnum.*;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @data 2024-12-30
|
||||
@@ -111,6 +114,7 @@ public class ResultServiceImpl implements IResultService {
|
||||
private final IAdPlanService adPlanService;
|
||||
private final IAdPlanTestConfigService adPlanTestConfigService;
|
||||
private final IPqDevService pqDevService;
|
||||
private final IPqStandardDevService pqStandardDevService;
|
||||
private final SimAndDigNonHarmonicService simAndDigNonHarmonicService;
|
||||
private final SimAndDigHarmonicService simAndDigHarmonicService;
|
||||
private final ContrastHarmonicService contrastHarmonicService;
|
||||
@@ -142,11 +146,11 @@ public class ResultServiceImpl implements IResultService {
|
||||
formContentVO.setErrorSysId(plan.getErrorSysId());
|
||||
String scriptId = null;
|
||||
if (ObjectUtil.isNotNull(plan)) {
|
||||
formContentVO.setDataRule(plan.getDataRule());
|
||||
scriptId = plan.getScriptId();
|
||||
adPlanService.visualize(Collections.singletonList(plan));
|
||||
formContentVO.setScriptName(plan.getScriptId());
|
||||
}
|
||||
formContentVO.setScriptName(plan.getScriptId());
|
||||
formContentVO.setDataRule(plan.getDataRule());
|
||||
formContentVO.setDeviceName(pqDevService.getById(queryParam.getDeviceId()).getName());
|
||||
|
||||
List<Map<String, String>> chnList = new ArrayList<>();
|
||||
@@ -337,10 +341,19 @@ public class ResultServiceImpl implements IResultService {
|
||||
private void dipScriptTypeName(List<PqScriptDtls> subValue, List<TreeDataVO> subTypeList, Map<Integer, Set<Integer>> finalResultMap, Boolean isValueType, String name, Integer start, Integer end) {
|
||||
List<TreeDataVO> info = new ArrayList<>();
|
||||
List<PqScriptDtls> dip = subValue.stream()
|
||||
.filter(x -> "Dip".equals(x.getValueType()) && "A".equals(x.getPhase()))
|
||||
// .filter(x -> "Dip".equals(x.getValueType()) && "A".equals(x.getPhase()))
|
||||
.filter(x -> "Dip".equals(x.getValueType()))
|
||||
.filter(x -> x.getTransValue() >= start && x.getTransValue() <= end)
|
||||
.sorted(Comparator.comparing(PqScriptDtls::getScriptIndex))
|
||||
.collect(Collectors.toList());
|
||||
LinkedHashMap<Integer, List<PqScriptDtls>> idxDipMap = dip.stream().collect(Collectors.groupingBy(d -> d.getScriptIndex(), LinkedHashMap::new, Collectors.toList()));
|
||||
|
||||
dip.clear();
|
||||
idxDipMap.forEach((idx, scriptDtlList) -> {
|
||||
scriptDtlList.sort(Comparator.comparing(PqScriptDtls::getPhase));
|
||||
dip.add(scriptDtlList.get(0));
|
||||
});
|
||||
|
||||
TreeDataVO vo = new TreeDataVO();
|
||||
vo.setScriptTypeName(name);
|
||||
vo.setScriptTypeCode("Base_" + start + "_" + end);
|
||||
@@ -394,8 +407,8 @@ public class ResultServiceImpl implements IResultService {
|
||||
double cosValue = Math.cos((aDtl1.get(0).getAngle() - aDtl2.get(0).getAngle()) / 180 * Math.PI);
|
||||
BigDecimal bigDecimal = BigDecimal.valueOf(cosValue).setScale(6, BigDecimal.ROUND_HALF_UP);
|
||||
|
||||
dtlType.setScriptTypeName(ResultUnitEnum.V_RELATIVE.getName() + "=" + v.get(0).getValue().intValue() + unitV
|
||||
+ " " + ResultUnitEnum.I_RELATIVE.getName() + "=" + i.get(0).getValue().intValue() + unitI
|
||||
dtlType.setScriptTypeName(ResultUnitEnum.V_RELATIVE.getName() + "=" + v.get(0).getValue() + unitV
|
||||
+ " " + ResultUnitEnum.I_RELATIVE.getName() + "=" + i.get(0).getValue() + unitI
|
||||
+ " cos(φ)=" + bigDecimal.doubleValue());
|
||||
}
|
||||
break;
|
||||
@@ -411,7 +424,7 @@ public class ResultServiceImpl implements IResultService {
|
||||
unit = ResultUnitEnum.V_ABSOLUTELY.getUnit();
|
||||
}
|
||||
List<PqScriptDtls> v = scriptDtlIndexList.stream().filter(x -> "VOL".equals(x.getValueType())).collect(Collectors.toList());
|
||||
dtlType.setScriptTypeName(dictTree.getName() + "=" + v.get(0).getValue().intValue() + unit);
|
||||
dtlType.setScriptTypeName(dictTree.getName() + "=" + v.get(0).getValue() + unit);
|
||||
break;
|
||||
/**
|
||||
* 电流
|
||||
@@ -425,7 +438,7 @@ public class ResultServiceImpl implements IResultService {
|
||||
unitI = ResultUnitEnum.I_ABSOLUTELY.getUnit();
|
||||
}
|
||||
List<PqScriptDtls> I = scriptDtlIndexList.stream().filter(x -> "CUR".equals(x.getValueType())).collect(Collectors.toList());
|
||||
dtlType.setScriptTypeName(dictTree.getName() + "=" + I.get(0).getValue().intValue() + unitI);
|
||||
dtlType.setScriptTypeName(dictTree.getName() + "=" + I.get(0).getValue() + unitI);
|
||||
break;
|
||||
/**
|
||||
* 谐波电压
|
||||
@@ -445,12 +458,12 @@ public class ResultServiceImpl implements IResultService {
|
||||
.collect(Collectors.groupingBy(PqScriptDtls::getHarmNum, LinkedHashMap::new, Collectors.toList()));
|
||||
if (harmNumMap.size() > 1) {
|
||||
//叠加2~50次谐波电压(含有率为GB/T)
|
||||
dtlType.setScriptTypeName("叠加" + harmNumMap.entrySet().iterator().next().getValue().get(0).getHarmNum().intValue() + "~" +
|
||||
new ArrayList<>(harmNumMap.entrySet()).get(harmNumMap.size() - 1).getValue().get(0).getHarmNum().intValue()
|
||||
dtlType.setScriptTypeName("叠加" + harmNumMap.entrySet().iterator().next().getValue().get(0).getHarmNum() + "~" +
|
||||
new ArrayList<>(harmNumMap.entrySet()).get(harmNumMap.size() - 1).getValue().get(0).getHarmNum()
|
||||
+ "次" + dictTree.getName()); // + "(含有率为GB/T)"
|
||||
} else {
|
||||
//叠加5%的2次谐波电压
|
||||
dtlType.setScriptTypeName("叠加" + hv.get(0).getValue().intValue() + ResultUnitEnum.HV.getUnit() + "的" + hv.get(0).getHarmNum().intValue() + "次" + dictTree.getName());
|
||||
dtlType.setScriptTypeName("叠加" + hv.get(0).getValue() + ResultUnitEnum.HV.getUnit() + "的" + hv.get(0).getHarmNum() + "次" + dictTree.getName());
|
||||
}
|
||||
break;
|
||||
/**
|
||||
@@ -484,7 +497,7 @@ public class ResultServiceImpl implements IResultService {
|
||||
dtlType.setScriptTypeName(a.toString());
|
||||
} else {
|
||||
//叠加5%的2次谐波电压
|
||||
dtlType.setScriptTypeName("叠加" + harmInNumList.get(0).getValue().intValue() + ResultUnitEnum.HV.getUnit() + "的" + harmInNumList.get(0).getHarmNum() + "次" + dictTree.getName());
|
||||
dtlType.setScriptTypeName("叠加" + harmInNumList.get(0).getValue() + ResultUnitEnum.HV.getUnit() + "的" + harmInNumList.get(0).getHarmNum() + "次" + dictTree.getName());
|
||||
}
|
||||
|
||||
break;
|
||||
@@ -979,10 +992,10 @@ public class ResultServiceImpl implements IResultService {
|
||||
DictData dictData = dictDataService.getDictDataById(param.getPatternId());
|
||||
if (PatternEnum.CONTRAST.getValue().equals(dictData.getCode())) {
|
||||
this.createTempResultTable(param.getCode() + "_temp", true);
|
||||
this.contrastCalculateResult(param.getPlanId(), param.getCode() + "_temp", param.getErrorSysId(), param.getDeviceId());
|
||||
this.contrastCalculateResult(param.getPlanId(), param.getCode() + "_temp", param.getErrorSysId(), param.getDeviceId(), false, param.getDataRuleId());
|
||||
} else {
|
||||
this.createTempResultTable(param.getCode() + "_temp", false);
|
||||
this.simAndDigCalculateResult(param.getPlanId(), param.getScriptId(), param.getCode() + "_temp", param.getErrorSysId(), param.getDeviceId());
|
||||
this.simAndDigCalculateResult(param.getPlanId(), param.getScriptId(), param.getCode() + "_temp", param.getErrorSysId(), param.getDeviceId(), param.getDataRuleId());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -996,9 +1009,9 @@ public class ResultServiceImpl implements IResultService {
|
||||
public void reCalculate(ResultParam.ChangeErrorSystemParam param) {
|
||||
DictData dictData = dictDataService.getDictDataById(param.getPatternId());
|
||||
if (PatternEnum.CONTRAST.getValue().equals(dictData.getCode())) {
|
||||
this.contrastCalculateResult(param.getPlanId(), param.getCode(), param.getErrorSysId(), param.getDeviceId());
|
||||
this.contrastCalculateResult(param.getPlanId(), param.getCode(), param.getErrorSysId(), param.getDeviceId(), true, param.getDataRuleId());
|
||||
} else {
|
||||
this.simAndDigCalculateResult(param.getPlanId(), param.getScriptId(), param.getCode(), param.getErrorSysId(), param.getDeviceId());
|
||||
this.simAndDigCalculateResult(param.getPlanId(), param.getScriptId(), param.getCode(), param.getErrorSysId(), param.getDeviceId(), param.getDataRuleId());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1529,8 +1542,7 @@ public class ResultServiceImpl implements IResultService {
|
||||
|
||||
AdPlan plan = adPlanService.getById(queryParam.getPlanId());
|
||||
PqDev dev = pqDevService.getById(queryParam.getDeviceId());
|
||||
DictData dictData = dictDataService.getById(plan.getDataRule());
|
||||
formContentVO.setDataRule(dictData.getName());
|
||||
formContentVO.setDataRule(plan.getDataRule());
|
||||
formContentVO.setDeviceName(dev.getName());
|
||||
formContentVO.setErrorSysId(plan.getErrorSysId());
|
||||
|
||||
@@ -1550,10 +1562,10 @@ public class ResultServiceImpl implements IResultService {
|
||||
}
|
||||
List<ContrastBaseResult> allResultList = new ArrayList<>();
|
||||
|
||||
List<ContrastNonHarmonicResult> contrastNonHarmonicResults = contrastNonHarmonicService.listAllResultData(String.valueOf(plan.getCode()), null, null, false, queryParam.getDeviceId(), adTypeList);
|
||||
contrastNonHarmonicResults.addAll(contrastNonHarmonicService.listAllResultData(String.valueOf(plan.getCode()), null, null, true, queryParam.getDeviceId(), adTypeList));
|
||||
List<ContrastHarmonicResult> contrastHarmonicResults = contrastHarmonicService.listAllResultData(String.valueOf(plan.getCode()), null, null, false, queryParam.getDeviceId(), adTypeList);
|
||||
contrastHarmonicResults.addAll(contrastHarmonicService.listAllResultData(String.valueOf(plan.getCode()), null, null, true, queryParam.getDeviceId(), adTypeList));
|
||||
List<ContrastNonHarmonicResult> contrastNonHarmonicResults = contrastNonHarmonicService.listAllResultData(String.valueOf(plan.getCode()), null, null, false, null, queryParam.getDeviceId(), adTypeList);
|
||||
contrastNonHarmonicResults.addAll(contrastNonHarmonicService.listAllResultData(String.valueOf(plan.getCode()), null, null, true, null, queryParam.getDeviceId(), adTypeList));
|
||||
List<ContrastHarmonicResult> contrastHarmonicResults = contrastHarmonicService.listAllResultData(String.valueOf(plan.getCode()), null, null, false, null, queryParam.getDeviceId(), adTypeList);
|
||||
contrastHarmonicResults.addAll(contrastHarmonicService.listAllResultData(String.valueOf(plan.getCode()), null, null, true, null, queryParam.getDeviceId(), adTypeList));
|
||||
allResultList.addAll(contrastHarmonicResults);
|
||||
allResultList.addAll(contrastNonHarmonicResults);
|
||||
|
||||
@@ -1577,8 +1589,6 @@ public class ResultServiceImpl implements IResultService {
|
||||
public ContrastResultVO getContrastResult(ResultParam.QueryParam queryParam) {
|
||||
ContrastResultVO contrastResultVO = new ContrastResultVO();
|
||||
|
||||
AdPlan plan = adPlanService.getById(queryParam.getPlanId());
|
||||
|
||||
List<DictTree> dictTreeList = dictTreeService.getDictTreeById(Collections.singletonList(queryParam.getScriptType()));
|
||||
|
||||
List<String> fatherIdList = dictTreeList.stream().map(DictTree::getId).collect(Collectors.toList());
|
||||
@@ -1600,8 +1610,8 @@ public class ResultServiceImpl implements IResultService {
|
||||
}
|
||||
}
|
||||
|
||||
contrastResultVO.setResultMap(this.getResultMap(dictTree, adTypeList, queryParam.getDeviceId() + CnSocketUtil.SPLIT_TAG + queryParam.getChnNum(), unit, queryParam.getNum(), queryParam.getWaveNum(), queryParam.getIsWave(), String.valueOf(plan.getCode())));
|
||||
contrastResultVO.setRawDataMap(this.getRawDataMap(dictTree, adTypeList, queryParam.getDeviceId() + CnSocketUtil.SPLIT_TAG + queryParam.getChnNum(), unit, queryParam.getNum(), queryParam.getWaveNum(), queryParam.getIsWave(), String.valueOf(plan.getCode())));
|
||||
contrastResultVO.setResultMap(this.getResultMap(dictTree, adTypeList, queryParam.getDeviceId() + CnSocketUtil.SPLIT_TAG + queryParam.getChnNum(), unit, queryParam.getNum(), queryParam.getWaveNum(), queryParam.getIsWave(), queryParam.getCode()));
|
||||
contrastResultVO.setRawDataMap(this.getRawDataMap(dictTree, adTypeList, queryParam.getDeviceId() + CnSocketUtil.SPLIT_TAG + queryParam.getChnNum(), unit, queryParam.getNum(), queryParam.getWaveNum(), queryParam.getIsWave(), queryParam.getCode(), contrastResultVO.getResultMap().keySet().stream().collect(Collectors.toList())));
|
||||
return contrastResultVO;
|
||||
}
|
||||
|
||||
@@ -1654,6 +1664,26 @@ public class ResultServiceImpl implements IResultService {
|
||||
result.setResultType(resultType + CnSocketUtil.SPLIT_TAG + waveData.get(1));
|
||||
result.setResultOrigin(dataSourceEnum.getMsg() + waveData.get(1));
|
||||
break;
|
||||
case MINUTE_STATISTICS_AVG:
|
||||
result.setCheckResult(pqMonitor.getStatisticsResult());
|
||||
result.setWhichTime(pqMonitor.getStatisticsNum());
|
||||
result.setResultOrigin(dataSourceEnum.getMsg());
|
||||
break;
|
||||
case MINUTE_STATISTICS_MAX:
|
||||
result.setCheckResult(pqMonitor.getStatisticsResult());
|
||||
result.setWhichTime(pqMonitor.getStatisticsNum());
|
||||
result.setResultOrigin(dataSourceEnum.getMsg());
|
||||
break;
|
||||
case MINUTE_STATISTICS_MIN:
|
||||
result.setCheckResult(pqMonitor.getStatisticsResult());
|
||||
result.setWhichTime(pqMonitor.getStatisticsNum());
|
||||
result.setResultOrigin(dataSourceEnum.getMsg());
|
||||
break;
|
||||
case MINUTE_STATISTICS_CP95:
|
||||
result.setCheckResult(pqMonitor.getStatisticsResult());
|
||||
result.setWhichTime(pqMonitor.getStatisticsNum());
|
||||
result.setResultOrigin(dataSourceEnum.getMsg());
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -1679,27 +1709,27 @@ public class ResultServiceImpl implements IResultService {
|
||||
}
|
||||
AdPlan finalPlan = plan;
|
||||
// 实时数据结果
|
||||
List<ContrastNonHarmonicResult> realNonHarmonicResults = contrastNonHarmonicService.listAllResultData(String.valueOf(finalPlan.getCode()), null, null, false, monitorId, null);
|
||||
Map<Integer, List<ContrastNonHarmonicResult>> numNonHarmonicMap = realNonHarmonicResults.stream()
|
||||
List<ContrastNonHarmonicResult> realNonHarmonicResults = contrastNonHarmonicService.listAllResultData(String.valueOf(finalPlan.getCode()), null, null, false, DataSourceEnum.REAL_DATA.getValue(), monitorId, null);
|
||||
Map<Integer, List<ContrastNonHarmonicResult>> realNumNonHarmonicMap = realNonHarmonicResults.stream()
|
||||
.sorted(Comparator.comparing(ContrastNonHarmonicResult::getNum))
|
||||
.collect(Collectors.groupingBy(ContrastNonHarmonicResult::getNum, LinkedHashMap::new, Collectors.toList()));
|
||||
|
||||
List<ContrastHarmonicResult> realHarmonicResults = contrastHarmonicService.listAllResultData(String.valueOf(finalPlan.getCode()), null, null, false, monitorId, null);
|
||||
Map<Integer, List<ContrastHarmonicResult>> numHarmonicMap = realHarmonicResults.stream()
|
||||
List<ContrastHarmonicResult> realHarmonicResults = contrastHarmonicService.listAllResultData(String.valueOf(finalPlan.getCode()), null, null, false, DataSourceEnum.REAL_DATA.getValue(), monitorId, null);
|
||||
Map<Integer, List<ContrastHarmonicResult>> realNumHarmonicMap = realHarmonicResults.stream()
|
||||
.sorted(Comparator.comparing(ContrastHarmonicResult::getNum))
|
||||
.collect(Collectors.groupingBy(ContrastHarmonicResult::getNum, LinkedHashMap::new, Collectors.toList()));
|
||||
|
||||
Map<Integer, List<Integer>> numResutMap = new TreeMap<>();
|
||||
numNonHarmonicMap.forEach((num, resultList) -> {
|
||||
numResutMap.put(num, resultList.stream().map(ContrastNonHarmonicResult::getResultFlag).distinct().collect(Collectors.toList()));
|
||||
Map<Integer, List<Integer>> realNumResutMap = new TreeMap<>();
|
||||
realNumNonHarmonicMap.forEach((num, resultList) -> {
|
||||
realNumResutMap.put(num, resultList.stream().map(ContrastNonHarmonicResult::getResultFlag).distinct().collect(Collectors.toList()));
|
||||
});
|
||||
numHarmonicMap.forEach((num, resultList) -> {
|
||||
List<Integer> list = numResutMap.getOrDefault(num, new ArrayList<>());
|
||||
realNumHarmonicMap.forEach((num, resultList) -> {
|
||||
List<Integer> list = realNumResutMap.getOrDefault(num, new ArrayList<>());
|
||||
list.addAll(resultList.stream().map(ContrastHarmonicResult::getResultFlag).distinct().collect(Collectors.toList()));
|
||||
numResutMap.put(num, list);
|
||||
realNumResutMap.put(num, list);
|
||||
});
|
||||
|
||||
numResutMap.forEach((num, resultList) -> {
|
||||
realNumResutMap.forEach((num, resultList) -> {
|
||||
List<DataSourceResultVO> dataSourceResultVOList = new ArrayList<>();
|
||||
DataSourceResultVO realDataSourceResultVO = new DataSourceResultVO();
|
||||
realDataSourceResultVO.setDataSourceCode(DataSourceEnum.REAL_DATA.getValue());
|
||||
@@ -1710,14 +1740,14 @@ public class ResultServiceImpl implements IResultService {
|
||||
result.put(num, dataSourceResultVOList);
|
||||
});
|
||||
|
||||
Map<Integer, Map<Integer, List<Integer>>> waveNumMap = new TreeMap<>();
|
||||
|
||||
// 录波数据结果
|
||||
List<ContrastNonHarmonicResult> waveNonHarmonicResults = contrastNonHarmonicService.listAllResultData(String.valueOf(finalPlan.getCode()), null, null, true, monitorId, null);
|
||||
Map<Integer, Map<Integer, List<Integer>>> waveNumMap = new TreeMap<>();
|
||||
List<ContrastNonHarmonicResult> waveNonHarmonicResults = contrastNonHarmonicService.listAllResultData(String.valueOf(finalPlan.getCode()), null, null, true, null, monitorId, null);
|
||||
Map<Integer, List<ContrastNonHarmonicResult>> waveNumNonHarmonicMap = waveNonHarmonicResults.stream()
|
||||
.sorted(Comparator.comparing(ContrastNonHarmonicResult::getNum))
|
||||
.collect(Collectors.groupingBy(ContrastNonHarmonicResult::getNum, LinkedHashMap::new, Collectors.toList()));
|
||||
List<ContrastHarmonicResult> waveHarmonicResults = contrastHarmonicService.listAllResultData(String.valueOf(finalPlan.getCode()), null, null, true, monitorId, null);
|
||||
List<ContrastHarmonicResult> waveHarmonicResults = contrastHarmonicService.listAllResultData(String.valueOf(finalPlan.getCode()), null, null, true, null, monitorId, null);
|
||||
Map<Integer, List<ContrastHarmonicResult>> waveNumHarmonicMap = waveHarmonicResults.stream()
|
||||
.sorted(Comparator.comparing(ContrastHarmonicResult::getNum))
|
||||
.collect(Collectors.groupingBy(ContrastHarmonicResult::getNum, LinkedHashMap::new, Collectors.toList()));
|
||||
@@ -1759,6 +1789,62 @@ public class ResultServiceImpl implements IResultService {
|
||||
result.put(num, orDefault);
|
||||
});
|
||||
|
||||
String dataRule = finalPlan.getDatasourceId();
|
||||
String[] split1 = dataRule.split(CnSocketUtil.SPLIT_TAG);
|
||||
DataSourceEnum dataType = null;
|
||||
for (String s : split1) {
|
||||
if (MINUTE_STATISTICS_AVG.getValue().equals(s)) {
|
||||
dataType = MINUTE_STATISTICS_AVG;
|
||||
break;
|
||||
}
|
||||
if (MINUTE_STATISTICS_CP95.getValue().equals(s)) {
|
||||
dataType = MINUTE_STATISTICS_CP95;
|
||||
break;
|
||||
}
|
||||
if (MINUTE_STATISTICS_MAX.getValue().equals(s)) {
|
||||
dataType = MINUTE_STATISTICS_MAX;
|
||||
break;
|
||||
}
|
||||
if (MINUTE_STATISTICS_MIN.getValue().equals(s)) {
|
||||
dataType = MINUTE_STATISTICS_MIN;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// 统计数据
|
||||
if (ObjectUtil.isNotNull(dataType)) {
|
||||
List<ContrastNonHarmonicResult> statisticsNonHarmonicResults = contrastNonHarmonicService.listAllResultData(String.valueOf(finalPlan.getCode()), null, null, false, dataType.getValue(), monitorId, null);
|
||||
Map<Integer, List<ContrastNonHarmonicResult>> statisticsNumNonHarmonicMap = statisticsNonHarmonicResults.stream()
|
||||
.sorted(Comparator.comparing(ContrastNonHarmonicResult::getNum))
|
||||
.collect(Collectors.groupingBy(ContrastNonHarmonicResult::getNum, LinkedHashMap::new, Collectors.toList()));
|
||||
|
||||
List<ContrastHarmonicResult> statisticsHarmonicResults = contrastHarmonicService.listAllResultData(String.valueOf(finalPlan.getCode()), null, null, false, dataType.getValue(), monitorId, null);
|
||||
Map<Integer, List<ContrastHarmonicResult>> statisticsNumHarmonicMap = statisticsHarmonicResults.stream()
|
||||
.sorted(Comparator.comparing(ContrastHarmonicResult::getNum))
|
||||
.collect(Collectors.groupingBy(ContrastHarmonicResult::getNum, LinkedHashMap::new, Collectors.toList()));
|
||||
|
||||
Map<Integer, List<Integer>> statisticsNumResutMap = new TreeMap<>();
|
||||
statisticsNumNonHarmonicMap.forEach((num, resultList) -> {
|
||||
statisticsNumResutMap.put(num, resultList.stream().map(ContrastNonHarmonicResult::getResultFlag).distinct().collect(Collectors.toList()));
|
||||
});
|
||||
statisticsNumHarmonicMap.forEach((num, resultList) -> {
|
||||
List<Integer> list = statisticsNumResutMap.getOrDefault(num, new ArrayList<>());
|
||||
list.addAll(resultList.stream().map(ContrastHarmonicResult::getResultFlag).distinct().collect(Collectors.toList()));
|
||||
statisticsNumResutMap.put(num, list);
|
||||
});
|
||||
|
||||
DataSourceEnum finalDataType = dataType;
|
||||
statisticsNumResutMap.forEach((num, resultList) -> {
|
||||
List<DataSourceResultVO> dataSourceResultVOList = new ArrayList<>();
|
||||
DataSourceResultVO realDataSourceResultVO = new DataSourceResultVO();
|
||||
realDataSourceResultVO.setDataSourceCode(finalDataType.getValue());
|
||||
realDataSourceResultVO.setDataSourceName(finalDataType.getMsg());
|
||||
realDataSourceResultVO.setCheckResult(StorageUtil.getInteger(resultList));
|
||||
dataSourceResultVOList.add(realDataSourceResultVO);
|
||||
|
||||
result.put(num, dataSourceResultVOList);
|
||||
});
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -1798,20 +1884,23 @@ public class ResultServiceImpl implements IResultService {
|
||||
monitor.setRecordedResult(null);
|
||||
monitor.setRecordedNum(null);
|
||||
}
|
||||
boolean flag = pqMonitorService.updateById(monitor);
|
||||
|
||||
return pqMonitorService.updateById(monitor);
|
||||
pqDevService.updateResult(split[0], null);
|
||||
|
||||
return flag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ContrastTestItemVO> getCheckItem(String devId, String chnNum, Integer num) {
|
||||
PqDev dev = pqDevService.getById(devId);
|
||||
AdPlan plan = adPlanService.getById(dev.getPlanId());
|
||||
String code = String.valueOf(plan.getCode());
|
||||
public List<ContrastTestItemVO> getCheckItem(String planId, String devId, String chnNum, Integer num, String code) {
|
||||
// PqDev dev = pqDevService.getById(devId);
|
||||
AdPlan plan = adPlanService.getById(planId);
|
||||
// String code = String.valueOf(plan.getCode());
|
||||
|
||||
String monitorId = devId + CnSocketUtil.SPLIT_TAG + chnNum;
|
||||
|
||||
List<ContrastNonHarmonicResult> realNoHarmonicResults = contrastNonHarmonicService.listAllResultData(code, num, null, false, monitorId, null);
|
||||
List<ContrastHarmonicResult> realHarmonicResults = contrastHarmonicService.listAllResultData(code, num, null, false, monitorId, null);
|
||||
List<ContrastNonHarmonicResult> realNoHarmonicResults = contrastNonHarmonicService.listAllResultData(code, num, null, false, null, monitorId, null);
|
||||
List<ContrastHarmonicResult> realHarmonicResults = contrastHarmonicService.listAllResultData(code, num, null, false, null, monitorId, null);
|
||||
|
||||
Map<String, List<Integer>> checkItemResultMap = realNoHarmonicResults.stream().collect(Collectors.groupingBy(ContrastNonHarmonicResult::getAdType, Collectors.mapping(ContrastNonHarmonicResult::getResultFlag, Collectors.toList())));
|
||||
checkItemResultMap.putAll(realHarmonicResults.stream().collect(Collectors.groupingBy(ContrastHarmonicResult::getAdType, Collectors.mapping(ContrastHarmonicResult::getResultFlag, Collectors.toList()))));
|
||||
@@ -1830,8 +1919,8 @@ public class ResultServiceImpl implements IResultService {
|
||||
|
||||
checkItemResultMap.clear();
|
||||
|
||||
List<ContrastNonHarmonicResult> waveNoHarmonicResults = contrastNonHarmonicService.listAllResultData(code, num, null, true, monitorId, null);
|
||||
List<ContrastHarmonicResult> waveHarmonicResults = contrastHarmonicService.listAllResultData(code, num, null, true, monitorId, null);
|
||||
List<ContrastNonHarmonicResult> waveNoHarmonicResults = contrastNonHarmonicService.listAllResultData(code, num, null, true, null, monitorId, null);
|
||||
List<ContrastHarmonicResult> waveHarmonicResults = contrastHarmonicService.listAllResultData(code, num, null, true, null, monitorId, null);
|
||||
if (CollUtil.isNotEmpty(waveNoHarmonicResults) && CollUtil.isNotEmpty(waveHarmonicResults)) {
|
||||
checkItemResultMap.putAll(waveNoHarmonicResults.stream().collect(Collectors.groupingBy(ContrastNonHarmonicResult::getAdType, Collectors.mapping(ContrastNonHarmonicResult::getResultFlag, Collectors.toList()))));
|
||||
checkItemResultMap.putAll(waveHarmonicResults.stream().collect(Collectors.groupingBy(ContrastHarmonicResult::getAdType, Collectors.mapping(ContrastHarmonicResult::getResultFlag, Collectors.toList()))));
|
||||
@@ -1951,8 +2040,10 @@ public class ResultServiceImpl implements IResultService {
|
||||
int totalDataPoints = 0; // 统计总的数据点数
|
||||
int zeroFilteredPoints = 0; // 统计双零过滤的数据点数
|
||||
|
||||
// 遍历 2~50 次谐波
|
||||
for (int harmNum = 2; harmNum <= 50; harmNum++) {
|
||||
// 间谐波从1开始,普通谐波从2开始
|
||||
int startHarmNum = isInterHarmonic ? 1 : 2;
|
||||
// 遍历谐波次数
|
||||
for (int harmNum = startHarmNum; harmNum <= 50; harmNum++) {
|
||||
String harmKey = String.valueOf(harmNum);
|
||||
Map<String, Map<String, Map<String, String>>> checkResultHarmonic = new LinkedHashMap<>();
|
||||
List<String> zeroFilteredPhases = new ArrayList<>(); // 当前次数被过滤的相别
|
||||
@@ -1982,7 +2073,7 @@ public class ResultServiceImpl implements IResultService {
|
||||
// 双零情况,记录但不加入结果判定
|
||||
zeroFilteredPhases.add(phase.toUpperCase() + "相");
|
||||
// 将结果改为特殊标记,不参与整体结论判定
|
||||
singlePhaseData.put(ItemReportKeyEnum.RESULT.getKey(), "双零过滤");
|
||||
singlePhaseData.put(ItemReportKeyEnum.RESULT.getKey(), "符合");
|
||||
} else {
|
||||
// 有非双零数据
|
||||
hasNonZeroData = true;
|
||||
@@ -1990,7 +2081,6 @@ public class ResultServiceImpl implements IResultService {
|
||||
String resultTemp = singlePhaseData.get(ItemReportKeyEnum.RESULT.getKey());
|
||||
if (StrUtil.isNotBlank(resultTemp)) {
|
||||
allResult.add(resultTemp);
|
||||
|
||||
// 收集特殊情况
|
||||
if ("无法比较".equals(resultTemp)) {
|
||||
String numOfDataStr = singlePhaseData.get(ItemReportKeyEnum.NUM_OF_DATA.getKey());
|
||||
@@ -2133,7 +2223,11 @@ public class ResultServiceImpl implements IResultService {
|
||||
String phases = phaseEntry.getKey();
|
||||
List<Integer> harmNums = phaseEntry.getValue();
|
||||
specialCaseDesc.append("第").append(formatHarmNumbers(harmNums, isInterHarmonic)).append("次谐波");
|
||||
specialCaseDesc.append(phases).append("无样本数据满足误差比较的前置条件,无法执行有效性判定。");
|
||||
// 如果是T相,则不拼接相别
|
||||
if (!"T相".equals(phases)) {
|
||||
specialCaseDesc.append(phases);
|
||||
}
|
||||
specialCaseDesc.append("无样本数据满足误差比较的前置条件,无法执行有效性判定。");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2294,10 +2388,8 @@ public class ResultServiceImpl implements IResultService {
|
||||
contrastTestResult.setHarmonic(false);
|
||||
List<String> allResult = new ArrayList<>();
|
||||
Map<String, Map<String, String>> checkResultNonHarmonic = new LinkedHashMap<>();
|
||||
|
||||
// 根据指标代码确定小数位数
|
||||
Integer decimalPlaces = getDecimalPlacesByScriptCode(dictTree.getCode());
|
||||
|
||||
try {
|
||||
// 非谐波的需要注意是否为T相还是ABC三相的
|
||||
if (PowerConstant.T_PHASE.contains(dictTree.getCode())) {
|
||||
@@ -2357,10 +2449,16 @@ public class ResultServiceImpl implements IResultService {
|
||||
// 生成无法比较的描述
|
||||
if (!unComparablePhases.isEmpty()) {
|
||||
specialCaseDesc.append("注:");
|
||||
if (unComparablePhases.size() == 1) {
|
||||
specialCaseDesc.append(unComparablePhases.get(0));
|
||||
// 如果只有T相,则不拼接相别
|
||||
if (unComparablePhases.size() == 1 && "T相".equals(unComparablePhases.get(0))) {
|
||||
// T相不拼接相别
|
||||
} else {
|
||||
specialCaseDesc.append(String.join("、", unComparablePhases));
|
||||
// 其他情况拼接相别
|
||||
if (unComparablePhases.size() == 1) {
|
||||
specialCaseDesc.append(unComparablePhases.get(0));
|
||||
} else {
|
||||
specialCaseDesc.append(String.join("、", unComparablePhases));
|
||||
}
|
||||
}
|
||||
specialCaseDesc.append("无样本数据满足误差比较的前置条件,无法执行有效性判定。");
|
||||
}
|
||||
@@ -2417,40 +2515,38 @@ public class ResultServiceImpl implements IResultService {
|
||||
Map<String, String> dataMap = new LinkedHashMap<>();
|
||||
if (CollUtil.isNotEmpty(dataList)) {
|
||||
DetectionData detectionData = dataList.get(0);
|
||||
|
||||
// 相别
|
||||
dataMap.put(ItemReportKeyEnum.PHASE.getKey(), phase);
|
||||
// 有效组数 todo... 目前是对齐组数
|
||||
dataMap.put(ItemReportKeyEnum.NUM_OF_DATA.getKey(), String.valueOf(numOfData));
|
||||
|
||||
// 标准值 - 根据参数决定是否格式化
|
||||
String standardValue = String.valueOf(detectionData.getResultData());
|
||||
if (decimalPlaces != null && detectionData.getResultData() != null) {
|
||||
standardValue = formatSignificantDigits(detectionData.getResultData(), decimalPlaces);
|
||||
}
|
||||
dataMap.put(ItemReportKeyEnum.STANDARD.getKey(), standardValue);
|
||||
|
||||
// 被检值 - 根据参数决定是否格式化
|
||||
String testValue = String.valueOf(detectionData.getData());
|
||||
if (decimalPlaces != null && detectionData.getData() != null) {
|
||||
testValue = formatSignificantDigits(detectionData.getData(), decimalPlaces);
|
||||
}
|
||||
dataMap.put(ItemReportKeyEnum.TEST.getKey(), testValue);
|
||||
|
||||
// 误差 - 根据参数决定是否格式化
|
||||
String errorValue = String.valueOf(detectionData.getErrorData());
|
||||
if (decimalPlaces != null && detectionData.getErrorData() != null) {
|
||||
errorValue = formatSignificantDigits(detectionData.getErrorData().doubleValue(), decimalPlaces);
|
||||
} else {
|
||||
errorValue = "/";
|
||||
}
|
||||
dataMap.put(ItemReportKeyEnum.ERROR.getKey(), errorValue);
|
||||
|
||||
// 误差范围 - 根据参数决定是否格式化
|
||||
String errorScope = String.valueOf(detectionData.getRadius());
|
||||
if (decimalPlaces != null && detectionData.getRadius() != null) {
|
||||
errorScope = formatErrorRange(detectionData.getRadius(), decimalPlaces);
|
||||
} else {
|
||||
errorScope = "/";
|
||||
}
|
||||
dataMap.put(ItemReportKeyEnum.A_ERROR_SCOPE.getKey(), errorScope);
|
||||
|
||||
// 结论
|
||||
dataMap.put(ItemReportKeyEnum.RESULT.getKey(), getTestResult(detectionData.getIsData()));
|
||||
} else {
|
||||
@@ -2545,8 +2641,20 @@ public class ResultServiceImpl implements IResultService {
|
||||
Map<String, String> dataMap = new LinkedHashMap<>();
|
||||
if (CollUtil.isNotEmpty(dataList)) {
|
||||
DetectionData detectionData = dataList.get(0);
|
||||
// 次数
|
||||
dataMap.put(ItemReportKeyEnum.TIME.getKey(), String.valueOf(harmNum));
|
||||
// 次数 - 从数据对象中获取实际次数(间谐波为1.5、2.5等)
|
||||
String timeValue;
|
||||
if (detectionData.getNum() != null) {
|
||||
double numValue = detectionData.getNum();
|
||||
// 如果是整数,则只显示整数部分(如2.0显示为2)
|
||||
if (numValue == Math.floor(numValue)) {
|
||||
timeValue = String.valueOf((int) numValue);
|
||||
} else {
|
||||
timeValue = String.valueOf(numValue);
|
||||
}
|
||||
} else {
|
||||
timeValue = String.valueOf(harmNum);
|
||||
}
|
||||
dataMap.put(ItemReportKeyEnum.TIME.getKey(), timeValue);
|
||||
// 相别
|
||||
dataMap.put(ItemReportKeyEnum.PHASE.getKey(), phase);
|
||||
// 有效组数 todo... 目前是对齐组数
|
||||
@@ -2570,6 +2678,8 @@ public class ResultServiceImpl implements IResultService {
|
||||
String errorValue = String.valueOf(detectionData.getErrorData());
|
||||
if (decimalPlaces != null && detectionData.getErrorData() != null) {
|
||||
errorValue = formatSignificantDigits(detectionData.getErrorData().doubleValue(), decimalPlaces);
|
||||
} else {
|
||||
errorValue = "/";
|
||||
}
|
||||
dataMap.put(ItemReportKeyEnum.ERROR.getKey(), errorValue);
|
||||
|
||||
@@ -2577,13 +2687,15 @@ public class ResultServiceImpl implements IResultService {
|
||||
String errorScope = String.valueOf(detectionData.getRadius());
|
||||
if (decimalPlaces != null && detectionData.getRadius() != null) {
|
||||
errorScope = formatErrorRange(detectionData.getRadius(), decimalPlaces);
|
||||
} else {
|
||||
errorScope = "/";
|
||||
}
|
||||
dataMap.put(ItemReportKeyEnum.A_ERROR_SCOPE.getKey(), errorScope);
|
||||
|
||||
// 结论
|
||||
dataMap.put(ItemReportKeyEnum.RESULT.getKey(), getTestResult(detectionData.getIsData()));
|
||||
} else {
|
||||
// 次数
|
||||
// 次数 - 数据为空时用循环变量作为兜底
|
||||
dataMap.put(ItemReportKeyEnum.TIME.getKey(), String.valueOf(harmNum));
|
||||
// 相别
|
||||
dataMap.put(ItemReportKeyEnum.PHASE.getKey(), phase);
|
||||
@@ -2658,8 +2770,8 @@ public class ResultServiceImpl implements IResultService {
|
||||
private Map<String, List<RawResultDataVO>> getResultMap(DictTree dictTree, List<String> adTypeList, String monitorId, String unit, Integer num, Integer waveNum, Boolean isWave, String code) {
|
||||
Map<String, List<RawResultDataVO>> resultMap = new LinkedHashMap<>();
|
||||
|
||||
List<ContrastNonHarmonicResult> contrastNonHarmonicResults = contrastNonHarmonicService.listAllResultData(code, num, waveNum, isWave, monitorId, adTypeList);
|
||||
List<ContrastHarmonicResult> contrastHarmonicResults = contrastHarmonicService.listAllResultData(code, num, waveNum, isWave, monitorId, adTypeList);
|
||||
List<ContrastNonHarmonicResult> contrastNonHarmonicResults = contrastNonHarmonicService.listAllResultData(code, num, waveNum, isWave, null, monitorId, adTypeList);
|
||||
List<ContrastHarmonicResult> contrastHarmonicResults = contrastHarmonicService.listAllResultData(code, num, waveNum, isWave, null, monitorId, adTypeList);
|
||||
|
||||
if (CollUtil.isNotEmpty(contrastNonHarmonicResults)) {
|
||||
ContrastNonHarmonicResult contrastNonHarmonicResult = contrastNonHarmonicResults.get(0);
|
||||
@@ -2705,7 +2817,7 @@ public class ResultServiceImpl implements IResultService {
|
||||
if (CollUtil.isNotEmpty(contrastHarmonicResults)) {
|
||||
ContrastHarmonicResult contrastHarmonicResult = contrastHarmonicResults.get(0);
|
||||
List<Double> harmonicNum = null;
|
||||
if (DicDataEnum.HV.getCode().equals(dictTree.getCode()) || DicDataEnum.HI.getCode().equals(dictTree.getCode())) {
|
||||
if (DicDataEnum.HV.getCode().equals(dictTree.getCode()) || DicDataEnum.HI.getCode().equals(dictTree.getCode()) || DicDataEnum.HP.getCode().equals(dictTree.getCode())) {
|
||||
harmonicNum = Stream.iterate(2.0, n -> n + 1).limit(49).collect(Collectors.toList());
|
||||
}
|
||||
if (DicDataEnum.HSV.getCode().equals(dictTree.getCode()) || DicDataEnum.HSI.getCode().equals(dictTree.getCode())) {
|
||||
@@ -2728,6 +2840,7 @@ public class ResultServiceImpl implements IResultService {
|
||||
List<RawResultDataVO.DetectionData> cList = JSON.parseArray(fieldC.get(contrastHarmonicResult) + "", RawResultDataVO.DetectionData.class);
|
||||
|
||||
List<RawResultDataVO> rawResultDataVOList = new ArrayList<>();
|
||||
List<Integer> isDataList = new ArrayList<>();
|
||||
for (int j = 0; j < aList.size(); j++) {
|
||||
RawResultDataVO dataVO = new RawResultDataVO();
|
||||
dataVO.setHarmNum(n);
|
||||
@@ -2737,9 +2850,11 @@ public class ResultServiceImpl implements IResultService {
|
||||
dataVO.setDataC(cList.get(j));
|
||||
dataVO.setRadius(aList.get(j).getRadius());
|
||||
dataVO.setIsData(StorageUtil.setResultFlag(Arrays.asList(aList.get(j), bList.get(j), cList.get(j))));
|
||||
isDataList.add(dataVO.getIsData());
|
||||
rawResultDataVOList.add(dataVO);
|
||||
}
|
||||
resultMap.put(String.valueOf(n), rawResultDataVOList);
|
||||
Integer isData = StorageUtil.getInteger(isDataList);
|
||||
resultMap.put(n + (isData == ResultEnum.NOT_QUALIFIED.getValue() ? "(不符合)" : (isData == ResultEnum.NO_ERROR_SYS.getValue() ? "(/)" : "")), rawResultDataVOList);
|
||||
} catch (NoSuchFieldException e) {
|
||||
throw new RuntimeException(e);
|
||||
} catch (IllegalAccessException e) {
|
||||
@@ -2750,36 +2865,36 @@ public class ResultServiceImpl implements IResultService {
|
||||
return resultMap;
|
||||
}
|
||||
|
||||
private Map<String, List<AlignDataVO.RawData>> getRawDataMap(DictTree dictTree, List<String> adTypeList, String monitorId, String unit, Integer num, Integer waveNum, Boolean isWave, String code) {
|
||||
private Map<String, List<AlignDataVO.RawData>> getRawDataMap(DictTree dictTree, List<String> adTypeList, String monitorId, String unit, Integer num, Integer waveNum, Boolean isWave, String code, List<String> keys) {
|
||||
Map<String, List<AlignDataVO.RawData>> rawMap = new LinkedHashMap<>();
|
||||
|
||||
List<ContrastNonHarmonicResult> devNonHarmonicRawDataList = contrastNonHarmonicService.listAllRawData(code, num, waveNum, isWave, 0, monitorId, adTypeList);
|
||||
List<ContrastNonHarmonicResult> stdDevNonHarmonicRawDataList = contrastNonHarmonicService.listAllRawData(code, num, waveNum, isWave, 1, monitorId, adTypeList);
|
||||
List<ContrastHarmonicResult> devHarmonicRawDataList = contrastHarmonicService.listAllRawData(code, num, waveNum, isWave, 0, monitorId, adTypeList);
|
||||
List<ContrastHarmonicResult> stdDevHarmonicRawDataList = contrastHarmonicService.listAllRawData(code, num, waveNum, isWave, 1, monitorId, adTypeList);
|
||||
List<ContrastNonHarmonicResult> devNonHarmonicRawDataList = contrastNonHarmonicService.listAllRawData(code, num, waveNum, isWave, null, 0, monitorId, adTypeList);
|
||||
List<ContrastNonHarmonicResult> stdDevNonHarmonicRawDataList = contrastNonHarmonicService.listAllRawData(code, num, waveNum, isWave, null, 1, monitorId, adTypeList);
|
||||
List<ContrastHarmonicResult> devHarmonicRawDataList = contrastHarmonicService.listAllRawData(code, num, waveNum, isWave, null, 0, monitorId, adTypeList);
|
||||
List<ContrastHarmonicResult> stdDevHarmonicRawDataList = contrastHarmonicService.listAllRawData(code, num, waveNum, isWave, null, 1, monitorId, adTypeList);
|
||||
|
||||
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS");
|
||||
List<AlignDataVO.RawData> rawDataVOList = new ArrayList<>();
|
||||
for (int i = 0; i < devNonHarmonicRawDataList.size(); i++) {
|
||||
AlignDataVO.RawData rawDataVO = new AlignDataVO.RawData();
|
||||
rawDataVO.setUnit(unit);
|
||||
ContrastNonHarmonicResult contrastNonHarmonicResult = devNonHarmonicRawDataList.get(i);
|
||||
rawDataVO.setTimeDev(contrastNonHarmonicResult.getTimeId().format(dtf));
|
||||
ContrastNonHarmonicResult contrastNonHarmonicResultDev = devNonHarmonicRawDataList.get(i);
|
||||
rawDataVO.setTimeDev(contrastNonHarmonicResultDev.getTimeId().format(dtf));
|
||||
|
||||
rawDataVO.setUbDev(getValue(contrastNonHarmonicResult.getBValue()));
|
||||
rawDataVO.setUtDev(getValue(contrastNonHarmonicResult.getTValue()));
|
||||
rawDataVO.setUbDev(getValue(contrastNonHarmonicResultDev.getBValue()));
|
||||
rawDataVO.setUtDev(getValue(contrastNonHarmonicResultDev.getTValue()));
|
||||
|
||||
contrastNonHarmonicResult = stdDevNonHarmonicRawDataList.get(i);
|
||||
rawDataVO.setTimeStdDev(contrastNonHarmonicResult.getTimeId().format(dtf));
|
||||
ContrastNonHarmonicResult contrastNonHarmonicResultStdDev = stdDevNonHarmonicRawDataList.get(i);
|
||||
rawDataVO.setTimeStdDev(contrastNonHarmonicResultStdDev.getTimeId().format(dtf));
|
||||
if (!DicDataEnum.IMBV.getCode().equals(dictTree.getCode()) && !DicDataEnum.IMBA.getCode().equals(dictTree.getCode())) {
|
||||
rawDataVO.setUaDev(getValue(contrastNonHarmonicResult.getAValue()));
|
||||
rawDataVO.setUcDev(getValue(contrastNonHarmonicResult.getCValue()));
|
||||
rawDataVO.setUaStdDev(getValue(contrastNonHarmonicResult.getAValue()));
|
||||
rawDataVO.setUcStdDev(getValue(contrastNonHarmonicResult.getCValue()));
|
||||
rawDataVO.setUaDev(getValue(contrastNonHarmonicResultDev.getAValue()));
|
||||
rawDataVO.setUcDev(getValue(contrastNonHarmonicResultDev.getCValue()));
|
||||
rawDataVO.setUaStdDev(getValue(contrastNonHarmonicResultStdDev.getAValue()));
|
||||
rawDataVO.setUcStdDev(getValue(contrastNonHarmonicResultStdDev.getCValue()));
|
||||
}
|
||||
|
||||
rawDataVO.setUbStdDev(getValue(contrastNonHarmonicResult.getBValue()));
|
||||
rawDataVO.setUtStdDev(getValue(contrastNonHarmonicResult.getTValue()));
|
||||
rawDataVO.setUbStdDev(getValue(contrastNonHarmonicResultStdDev.getBValue()));
|
||||
rawDataVO.setUtStdDev(getValue(contrastNonHarmonicResultStdDev.getTValue()));
|
||||
|
||||
rawDataVOList.add(rawDataVO);
|
||||
}
|
||||
@@ -2789,11 +2904,14 @@ public class ResultServiceImpl implements IResultService {
|
||||
|
||||
if (CollUtil.isNotEmpty(devHarmonicRawDataList) && CollUtil.isNotEmpty(stdDevHarmonicRawDataList)) {
|
||||
List<Double> harmonicNum = null;
|
||||
if (DicDataEnum.HV.getCode().equals(dictTree.getCode()) || DicDataEnum.HI.getCode().equals(dictTree.getCode())) {
|
||||
boolean isHarm = true;
|
||||
if (DicDataEnum.HV.getCode().equals(dictTree.getCode()) || DicDataEnum.HI.getCode().equals(dictTree.getCode()) || DicDataEnum.HP.getCode().equals(dictTree.getCode())) {
|
||||
harmonicNum = Stream.iterate(2.0, n -> n + 1).limit(49).collect(Collectors.toList());
|
||||
isHarm = true;
|
||||
}
|
||||
if (DicDataEnum.HSV.getCode().equals(dictTree.getCode()) || DicDataEnum.HSI.getCode().equals(dictTree.getCode())) {
|
||||
harmonicNum = Stream.iterate(0.5, n -> n + 1).limit(50).collect(Collectors.toList());
|
||||
isHarm = false;
|
||||
}
|
||||
for (Double n : harmonicNum) {
|
||||
List<AlignDataVO.RawData> rawDataVOList1 = new ArrayList<>();
|
||||
@@ -2844,7 +2962,10 @@ public class ResultServiceImpl implements IResultService {
|
||||
}
|
||||
rawDataVOList1.add(rawDataVO);
|
||||
}
|
||||
rawMap.put(String.valueOf(n), rawDataVOList1);
|
||||
int num1 = n.intValue();
|
||||
num1 = isHarm ? num1 - 2 : num1;
|
||||
String key = keys.get(num1);
|
||||
rawMap.put(key, rawDataVOList1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2921,6 +3042,7 @@ public class ResultServiceImpl implements IResultService {
|
||||
"A_Value_0 json NULL COMMENT 'A相基波有效值',\n" +
|
||||
"B_Value_0 json NULL COMMENT 'B相基波有效值',\n" +
|
||||
"C_Value_0 json NULL COMMENT 'B相基波有效值',\n" +
|
||||
"Wave_Num tinyint(1) unsigned DEFAULT null COMMENT '录波数据第几组',\n" +
|
||||
"PRIMARY KEY (Id)\n"
|
||||
:
|
||||
" Script_Id CHAR(32) NOT NULL COMMENT '检测脚本表Id',\n" +
|
||||
@@ -2951,7 +3073,7 @@ public class ResultServiceImpl implements IResultService {
|
||||
* @param errorSysId
|
||||
* @param devId
|
||||
*/
|
||||
private void simAndDigCalculateResult(String planId, String scriptId, String code, String errorSysId, String devId) {
|
||||
private void simAndDigCalculateResult(String planId, String scriptId, String code, String errorSysId, String devId, String dataRuleId) {
|
||||
String oldCode = code.replace("_temp", "");
|
||||
PreDetectionParam param = new PreDetectionParam();
|
||||
param.setCode(code);
|
||||
@@ -2969,8 +3091,8 @@ public class ResultServiceImpl implements IResultService {
|
||||
// } else {
|
||||
// dataRule = DictDataEnum.SECTION_VALUE;
|
||||
// }
|
||||
AdPlan plan = adPlanService.getById(planId);
|
||||
DictData dictData = dictDataService.getDictDataById(plan.getDataRule());
|
||||
// AdPlan plan = adPlanService.getById(planId);
|
||||
DictData dictData = dictDataService.getDictDataById(dataRuleId);
|
||||
if (ObjectUtil.isNotNull(dictData)) {
|
||||
dataRule = DictDataEnum.getDictDataEnumByCode(dictData.getCode());
|
||||
} else {
|
||||
@@ -3028,8 +3150,9 @@ public class ResultServiceImpl implements IResultService {
|
||||
* @param code
|
||||
* @param errorSysId
|
||||
* @param deviceId
|
||||
* @param updateResult
|
||||
*/
|
||||
private void contrastCalculateResult(String planId, String code, String errorSysId, String deviceId) {
|
||||
private void contrastCalculateResult(String planId, String code, String errorSysId, String deviceId, boolean updateResult, String dataRuleId) {
|
||||
String oldCode = code.replace("_temp", "");
|
||||
|
||||
Map<String, String> devIdMapComm = new HashMap<>();
|
||||
@@ -3043,18 +3166,19 @@ public class ResultServiceImpl implements IResultService {
|
||||
|
||||
DataSourceEnum nonWaveDataSourceEnum = DataSourceEnum.REAL_DATA;
|
||||
for (String ds : dataSourceIds) {
|
||||
switch (DataSourceEnum.valueOf(ds)) {
|
||||
DataSourceEnum dataSourceEnum = DataSourceEnum.ofByValue(ds);
|
||||
switch (dataSourceEnum) {
|
||||
case MINUTE_STATISTICS_MIN:
|
||||
nonWaveDataSourceEnum = DataSourceEnum.MINUTE_STATISTICS_MIN;
|
||||
nonWaveDataSourceEnum = MINUTE_STATISTICS_MIN;
|
||||
break;
|
||||
case MINUTE_STATISTICS_MAX:
|
||||
nonWaveDataSourceEnum = DataSourceEnum.MINUTE_STATISTICS_MAX;
|
||||
nonWaveDataSourceEnum = MINUTE_STATISTICS_MAX;
|
||||
break;
|
||||
case MINUTE_STATISTICS_AVG:
|
||||
nonWaveDataSourceEnum = DataSourceEnum.MINUTE_STATISTICS_AVG;
|
||||
break;
|
||||
case MINUTE_STATISTICS_CP95:
|
||||
nonWaveDataSourceEnum = DataSourceEnum.MINUTE_STATISTICS_CP95;
|
||||
nonWaveDataSourceEnum = MINUTE_STATISTICS_CP95;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -3071,33 +3195,38 @@ public class ResultServiceImpl implements IResultService {
|
||||
}
|
||||
|
||||
DictDataEnum dataRule;
|
||||
DictData dictData = dictDataService.getDictDataById(plan.getDataRule());
|
||||
DictData dictData = dictDataService.getDictDataById(dataRuleId);
|
||||
if (ObjectUtil.isNotNull(dictData)) {
|
||||
dataRule = DictDataEnum.getDictDataEnumByCode(dictData.getCode());
|
||||
} else {
|
||||
dataRule = DictDataEnum.SECTION_VALUE;
|
||||
}
|
||||
|
||||
pqMonitorService.lambdaUpdate().set(PqMonitor::getRecordedResult, null)
|
||||
.set(PqMonitor::getRealtimeNum, null)
|
||||
.set(PqMonitor::getRecordedResult, null)
|
||||
.set(PqMonitor::getRecordedNum, null)
|
||||
.set(PqMonitor::getStatisticsResult, null)
|
||||
.set(PqMonitor::getStatisticsNum, null)
|
||||
.set(PqMonitor::getResultType, null)
|
||||
.set(PqMonitor::getQualifiedNum, 0)
|
||||
.eq(PqMonitor::getDevId, deviceId)
|
||||
.eq(PqMonitor::getCheckFlag, 1)
|
||||
.update();
|
||||
if (updateResult) {
|
||||
pqMonitorService.lambdaUpdate().set(PqMonitor::getRecordedResult, null)
|
||||
.set(PqMonitor::getRealtimeNum, null)
|
||||
.set(PqMonitor::getRecordedResult, null)
|
||||
.set(PqMonitor::getRecordedNum, null)
|
||||
.set(PqMonitor::getStatisticsResult, null)
|
||||
.set(PqMonitor::getStatisticsNum, null)
|
||||
.set(PqMonitor::getResultType, null)
|
||||
.set(PqMonitor::getQualifiedNum, 0)
|
||||
.eq(PqMonitor::getDevId, deviceId)
|
||||
// .eq(PqMonitor::getNum, Integer.parseInt(chnNum))
|
||||
.eq(PqMonitor::getCheckFlag, 1)
|
||||
.update();
|
||||
}
|
||||
|
||||
// String monitorId = deviceId + CnSocketUtil.SPLIT_TAG + chnNum;
|
||||
List<AdPair> adPairList = adPairService.listByDevIds(Arrays.asList(deviceId));
|
||||
Map<Integer, List<AdPair>> numAdPairsMap = adPairList.stream().collect(Collectors.groupingBy(AdPair::getNum, Collectors.toList()));
|
||||
|
||||
numAdPairsMap.forEach((num, pairList) -> {
|
||||
BiMap<String, String> parsIp = HashBiMap.create();
|
||||
BiMap<String, String> parsId = HashBiMap.create();
|
||||
Map<String, Integer> numMap = new HashMap<>();
|
||||
Map<String, List<AdPair>> devMonitroIdMap = pairList.stream().collect(Collectors.groupingBy(AdPair::getDevMonitorId, Collectors.toList()));
|
||||
devMonitroIdMap.forEach((devMonitorId, pairList1) -> {
|
||||
BiMap<String, String> parsIp = HashBiMap.create();
|
||||
BiMap<String, String> parsId = HashBiMap.create();
|
||||
String[] split1 = devMonitorId.split(CnSocketUtil.SPLIT_TAG);
|
||||
AdPair adPair = pairList1.get(0);
|
||||
String[] split2 = adPair.getStdDevMonitorId().split(CnSocketUtil.SPLIT_TAG);
|
||||
@@ -3107,40 +3236,41 @@ public class ResultServiceImpl implements IResultService {
|
||||
parsId.put(dev.getId() + CnSocketUtil.SPLIT_TAG + split1[1], standardDev.getId() + CnSocketUtil.SPLIT_TAG + split2[1]);
|
||||
numMap.put(devMonitorId, num);
|
||||
numMap.put(adPair.getStdDevMonitorId(), num);
|
||||
});
|
||||
devIdMapComm.put(standardDev.getIp(), standardDev.getId());
|
||||
|
||||
List<ContrastNonHarmonicResult> devNonHarmonicRawDataList = contrastNonHarmonicService.listAllRawData(oldCode, num, null, false, 0, deviceId, null);
|
||||
List<ContrastNonHarmonicResult> stdDevNonHarmonicRawDataList = contrastNonHarmonicService.listAllRawData(oldCode, num, null, false, 1, deviceId, null);
|
||||
List<ContrastHarmonicResult> devHarmonicRawDataList = contrastHarmonicService.listAllRawData(oldCode, num, null, false, 0, deviceId, null);
|
||||
List<ContrastHarmonicResult> stdDevHarmonicRawDataList = contrastHarmonicService.listAllRawData(oldCode, num, null, false, 1, deviceId, null);
|
||||
List<ContrastNonHarmonicResult> devNonHarmonicRawDataList = contrastNonHarmonicService.listAllRawData(oldCode, num, null, false, null, 0, devMonitorId, null);
|
||||
List<ContrastNonHarmonicResult> stdDevNonHarmonicRawDataList = contrastNonHarmonicService.listAllRawData(oldCode, num, null, false, null, 1, devMonitorId, null);
|
||||
List<ContrastHarmonicResult> devHarmonicRawDataList = contrastHarmonicService.listAllRawData(oldCode, num, null, false, null, 0, devMonitorId, null);
|
||||
List<ContrastHarmonicResult> stdDevHarmonicRawDataList = contrastHarmonicService.listAllRawData(oldCode, num, null, false, null, 1, devMonitorId, null);
|
||||
|
||||
List<DevData> devData = contrastToList(devNonHarmonicRawDataList, devHarmonicRawDataList, testItemMap);
|
||||
List<DevData> standardDevData = contrastToList(stdDevNonHarmonicRawDataList, stdDevHarmonicRawDataList, testItemMap);
|
||||
List<DevData> devData = contrastToList(devNonHarmonicRawDataList, devHarmonicRawDataList, testItemMap, 0);
|
||||
List<DevData> standardDevData = contrastToList(stdDevNonHarmonicRawDataList, stdDevHarmonicRawDataList, testItemMap, 1);
|
||||
|
||||
detectionServiceImpl.processing(devData, standardDevData, parsIp, devIdMapComm, testItemMap.keySet().stream().collect(Collectors.toList()), errorSysId, dataRule, numMap, code, null, finalNonWaveDataSourceEnum);
|
||||
if (CollUtil.isNotEmpty(devData) && CollUtil.isNotEmpty(standardDevData)) {
|
||||
detectionServiceImpl.processing(devData, standardDevData, parsIp, devIdMapComm, testItemMap.keySet().stream().collect(Collectors.toList()), errorSysId, dataRule, numMap, code, null, finalNonWaveDataSourceEnum);
|
||||
|
||||
parsId.forEach((devMonitorId, stdDevMonitorId) -> {
|
||||
String[] split = devMonitorId.split(CnSocketUtil.SPLIT_TAG);
|
||||
pqMonitorService.updateMonitorResult(devMonitorId, null, finalNonWaveDataSourceEnum, num, null, oldCode);
|
||||
pqDevService.updateResult(split[0], null);
|
||||
});
|
||||
if (updateResult) {
|
||||
pqMonitorService.updateMonitorResult(devMonitorId, null, finalNonWaveDataSourceEnum, num, null, oldCode);
|
||||
pqDevService.updateResult(split1[0], null);
|
||||
}
|
||||
}
|
||||
|
||||
AdPlanTestConfig adPlanTestConfig = adPlanTestConfigService.getByPlanId(planId);
|
||||
for (int i = 1; i <= adPlanTestConfig.getWaveRecord(); i++) {
|
||||
devNonHarmonicRawDataList = contrastNonHarmonicService.listAllRawData(oldCode, num, i, true, 0, deviceId, null);
|
||||
stdDevNonHarmonicRawDataList = contrastNonHarmonicService.listAllRawData(oldCode, num, i, true, 1, deviceId, null);
|
||||
devHarmonicRawDataList = contrastHarmonicService.listAllRawData(oldCode, num, i, true, 0, deviceId, null);
|
||||
stdDevHarmonicRawDataList = contrastHarmonicService.listAllRawData(oldCode, num, i, true, 1, deviceId, null);
|
||||
AdPlanTestConfig adPlanTestConfig = adPlanTestConfigService.getByPlanId(planId);
|
||||
for (int i = 1; i <= adPlanTestConfig.getWaveRecord(); i++) {
|
||||
devNonHarmonicRawDataList = contrastNonHarmonicService.listAllRawData(oldCode, num, i, true, null, 0, devMonitorId, null);
|
||||
stdDevNonHarmonicRawDataList = contrastNonHarmonicService.listAllRawData(oldCode, num, i, true, null, 1, devMonitorId, null);
|
||||
devHarmonicRawDataList = contrastHarmonicService.listAllRawData(oldCode, num, i, true, null, 0, devMonitorId, null);
|
||||
stdDevHarmonicRawDataList = contrastHarmonicService.listAllRawData(oldCode, num, i, true, null, 1, devMonitorId, null);
|
||||
|
||||
devData = contrastToList(devNonHarmonicRawDataList, devHarmonicRawDataList, testItemMap);
|
||||
standardDevData = contrastToList(stdDevNonHarmonicRawDataList, stdDevHarmonicRawDataList, testItemMap);
|
||||
detectionServiceImpl.processing(devData, standardDevData, parsIp, devIdMapComm, testItemMap.keySet().stream().collect(Collectors.toList()), errorSysId, dataRule, numMap, oldCode, i, DataSourceEnum.WAVE_DATA);
|
||||
}
|
||||
devData = contrastToList(devNonHarmonicRawDataList, devHarmonicRawDataList, testItemMap, 0);
|
||||
standardDevData = contrastToList(stdDevNonHarmonicRawDataList, stdDevHarmonicRawDataList, testItemMap, 1);
|
||||
detectionServiceImpl.processing(devData, standardDevData, parsIp, devIdMapComm, testItemMap.keySet().stream().collect(Collectors.toList()), errorSysId, dataRule, numMap, oldCode, i, DataSourceEnum.WAVE_DATA);
|
||||
}
|
||||
|
||||
parsId.forEach((devMonitorId, stdDevMonitorId) -> {
|
||||
String[] split = devMonitorId.split(CnSocketUtil.SPLIT_TAG);
|
||||
pqMonitorService.updateMonitorResult(devMonitorId, null, finalNonWaveDataSourceEnum, num, adPlanTestConfig.getWaveRecord(), oldCode);
|
||||
pqDevService.updateResult(split[0], null);
|
||||
if (updateResult) {
|
||||
pqMonitorService.updateMonitorResult(devMonitorId, null, WAVE_DATA, num, adPlanTestConfig.getWaveRecord(), oldCode);
|
||||
pqDevService.updateResult(split1[0], null);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -3230,58 +3360,88 @@ public class ResultServiceImpl implements IResultService {
|
||||
return info;
|
||||
}
|
||||
|
||||
private List<DevData> contrastToList(List<ContrastNonHarmonicResult> nonHarm, List<ContrastHarmonicResult> harm, BiMap<String, String> testItemMap) {
|
||||
private List<DevData> contrastToList(List<ContrastNonHarmonicResult> nonHarm, List<ContrastHarmonicResult> harm, BiMap<String, String> testItemMap, Integer flag) {
|
||||
List<DevData> info = new ArrayList<>();
|
||||
if (CollUtil.isNotEmpty(nonHarm)) {
|
||||
Map<String, List<ContrastNonHarmonicResult>> devMonitorIdMap = nonHarm.stream().collect(Collectors.groupingBy(ContrastNonHarmonicResult::getDevMonitorId, Collectors.toList()));
|
||||
devMonitorIdMap.forEach((devMonitorId, value) -> {
|
||||
|
||||
Map<String, List<ContrastNonHarmonicResult>> devMonitorIdMap1 = null;
|
||||
if (flag == 0) {
|
||||
devMonitorIdMap1 = nonHarm.stream().collect(Collectors.groupingBy(ContrastNonHarmonicResult::getDevMonitorId, Collectors.toList()));
|
||||
} else {
|
||||
devMonitorIdMap1 = nonHarm.stream().collect(Collectors.groupingBy(ContrastNonHarmonicResult::getStdDevMonitorId, Collectors.toList()));
|
||||
}
|
||||
devMonitorIdMap1.forEach((devMonitorId, value) -> {
|
||||
Map<LocalDateTime, List<ContrastNonHarmonicResult>> timeListMap = value.stream().collect(Collectors.groupingBy(ContrastNonHarmonicResult::getTimeId, Collectors.toList()));
|
||||
timeListMap.forEach((time, value1) -> {
|
||||
DevData devData = new DevData();
|
||||
String[] split = devMonitorId.split(CnSocketUtil.SPLIT_TAG);
|
||||
PqDev dev = pqDevService.getById(split[0]);
|
||||
devData.setId(dev.getIp() + CnSocketUtil.SPLIT_TAG + split[1]);
|
||||
Map<LocalDateTime, List<ContrastNonHarmonicResult>> timeListMap = value.stream().collect(Collectors.groupingBy(ContrastNonHarmonicResult::getTimeId, Collectors.toList()));
|
||||
timeListMap.forEach((time, value1) -> {
|
||||
List<DevData.SqlDataDTO> sqlData = new ArrayList<>();
|
||||
devData.setTime(time.format(DateTimeFormatter.ofPattern(DatePattern.ISO8601_PATTERN)));
|
||||
if (flag == 0) {
|
||||
PqDev dev = pqDevService.getById(split[0]);
|
||||
devData.setId(dev.getIp() + CnSocketUtil.SPLIT_TAG + split[1]);
|
||||
} else {
|
||||
PqStandardDev standardDev = pqStandardDevService.getById(split[0]);
|
||||
devData.setId(standardDev.getIp() + CnSocketUtil.SPLIT_TAG + split[1]);
|
||||
}
|
||||
devData.setTime(time.format(DateTimeFormatter.ofPattern(DatePattern.ISO8601_PATTERN)));
|
||||
List<DevData.SqlDataDTO> sqlData = new ArrayList<>();
|
||||
|
||||
value1.forEach(x -> {
|
||||
DevData.SqlDataDTO sqlDataDTO = new DevData.SqlDataDTO();
|
||||
DevData.SqlDataDTO.ListDTO listDTO = new DevData.SqlDataDTO.ListDTO();
|
||||
listDTO.setA(StrUtil.isNotBlank(x.getAValue()) ? Double.valueOf(x.getAValue()) : null);
|
||||
listDTO.setB(StrUtil.isNotBlank(x.getBValue()) ? Double.valueOf(x.getBValue()) : null);
|
||||
listDTO.setC(StrUtil.isNotBlank(x.getCValue()) ? Double.valueOf(x.getCValue()) : null);
|
||||
listDTO.setT(StrUtil.isNotBlank(x.getTValue()) ? Double.valueOf(x.getTValue()) : null);
|
||||
sqlDataDTO.setType(x.getDataType());
|
||||
sqlDataDTO.setDesc(testItemMap.inverse().get(x.getAdType()).replace(DetectionCodeEnum.REAL_PREFIX.getCode(), ""));
|
||||
sqlDataDTO.setList(listDTO);
|
||||
sqlData.add(sqlDataDTO);
|
||||
});
|
||||
devData.setSqlData(sqlData);
|
||||
value1.forEach(x -> {
|
||||
DevData.SqlDataDTO sqlDataDTO = new DevData.SqlDataDTO();
|
||||
DevData.SqlDataDTO.ListDTO listDTO = new DevData.SqlDataDTO.ListDTO();
|
||||
listDTO.setA(StrUtil.isNotBlank(x.getAValue()) ? Double.valueOf(x.getAValue()) : null);
|
||||
listDTO.setB(StrUtil.isNotBlank(x.getBValue()) ? Double.valueOf(x.getBValue()) : null);
|
||||
listDTO.setC(StrUtil.isNotBlank(x.getCValue()) ? Double.valueOf(x.getCValue()) : null);
|
||||
listDTO.setT(StrUtil.isNotBlank(x.getTValue()) ? Double.valueOf(x.getTValue()) : null);
|
||||
sqlDataDTO.setType(x.getDataType());
|
||||
sqlDataDTO.setDesc(testItemMap.inverse().get(x.getAdType()).replace(DetectionCodeEnum.REAL_PREFIX.getCode(), ""));
|
||||
sqlDataDTO.setList(listDTO);
|
||||
sqlData.add(sqlDataDTO);
|
||||
});
|
||||
devData.setSqlData(sqlData);
|
||||
info.add(devData);
|
||||
});
|
||||
});
|
||||
|
||||
Map<String, List<ContrastHarmonicResult>> devMonitorIdMap2 = null;
|
||||
if (flag == 0) {
|
||||
devMonitorIdMap2 = harm.stream().collect(Collectors.groupingBy(ContrastHarmonicResult::getDevMonitorId, Collectors.toList()));
|
||||
} else {
|
||||
devMonitorIdMap2 = harm.stream().collect(Collectors.groupingBy(ContrastHarmonicResult::getStdDevMonitorId, Collectors.toList()));
|
||||
}
|
||||
if (CollUtil.isNotEmpty(harm)) {
|
||||
Map<String, List<ContrastHarmonicResult>> devMonitorIdMap = harm.stream().collect(Collectors.groupingBy(ContrastHarmonicResult::getDevMonitorId, Collectors.toList()));
|
||||
devMonitorIdMap.forEach((devMonitorId, value) -> {
|
||||
DevData devData = new DevData();
|
||||
String[] split = devMonitorId.split(CnSocketUtil.SPLIT_TAG);
|
||||
PqDev dev = pqDevService.getById(split[0]);
|
||||
devData.setId(dev.getIp() + CnSocketUtil.SPLIT_TAG + split[1]);
|
||||
Map<LocalDateTime, List<ContrastHarmonicResult>> timeListMap = value.stream().collect(Collectors.groupingBy(ContrastHarmonicResult::getTimeId, Collectors.toList()));
|
||||
|
||||
timeListMap.forEach((time, value1) -> {
|
||||
devMonitorIdMap2.forEach((devMonitorId, value) -> {
|
||||
Map<LocalDateTime, List<ContrastHarmonicResult>> timeListMap = value.stream().collect(Collectors.groupingBy(ContrastHarmonicResult::getTimeId, Collectors.toList()));
|
||||
|
||||
String[] split1 = devMonitorId.split(CnSocketUtil.SPLIT_TAG);
|
||||
timeListMap.forEach((time, value1) -> {
|
||||
// DevData devData = info.stream().filter(x -> x.getTime().equals(time.format(DateTimeFormatter.ofPattern(DatePattern.ISO8601_PATTERN)))).findFirst().orElse(null);
|
||||
DevData devData = null;
|
||||
for (int i = 0; i < info.size(); i++) {
|
||||
DevData devData1 = info.get(i);
|
||||
if (time.format(DateTimeFormatter.ofPattern(DatePattern.ISO8601_PATTERN)).equals(devData1.getTime()) && devData1.getId().split(CnSocketUtil.SPLIT_TAG)[1].equals(split1[1])) {
|
||||
devData = devData1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (ObjectUtil.isNotNull(devData)) {
|
||||
String[] split = devMonitorId.split(CnSocketUtil.SPLIT_TAG);
|
||||
if (flag == 0) {
|
||||
PqDev dev = pqDevService.getById(split[0]);
|
||||
devData.setId(dev.getIp() + CnSocketUtil.SPLIT_TAG + split[1]);
|
||||
} else {
|
||||
PqStandardDev standardDev = pqStandardDevService.getById(split[0]);
|
||||
devData.setId(standardDev.getIp() + CnSocketUtil.SPLIT_TAG + split[1]);
|
||||
}
|
||||
|
||||
devData.setTime(time.format(DateTimeFormatter.ofPattern(DatePattern.ISO8601_PATTERN)));
|
||||
List<DevData.SqlDataDTO> sqlData = new ArrayList<>();
|
||||
List<DevData.SqlDataDTO> sqlData = devData.getSqlData();
|
||||
List<DevData.SqlDataHarmDTO> sqlDataHarm = new ArrayList<>();
|
||||
|
||||
value1.forEach(x -> {
|
||||
DevData.SqlDataHarmDTO dataHarmDTO = new DevData.SqlDataHarmDTO();
|
||||
dataHarmDTO.setType(x.getDataType());
|
||||
String desc = testItemMap.inverse().get(x.getAdType()).replace(DetectionCodeEnum.REAL_PREFIX.getCode(), "");
|
||||
dataHarmDTO.setDesc(desc);
|
||||
boolean notContainBaseHarm = false;
|
||||
if (DetectionCodeEnum.V2_50.getCode().equals(desc) || DetectionCodeEnum.PV2_50.getCode().equals(desc) || DetectionCodeEnum.I2_50.getCode().equals(desc)) {
|
||||
if (DetectionCodeEnum.V2_50.getCode().equals(desc) || DetectionCodeEnum.PV2_50.getCode().equals(desc) || DetectionCodeEnum.I2_50.getCode().equals(desc) || DetectionCodeEnum.P2_50.getCode().equals(desc)) {
|
||||
dataHarmDTO.setNum(49);
|
||||
notContainBaseHarm = true;
|
||||
}
|
||||
@@ -3316,12 +3476,13 @@ public class ResultServiceImpl implements IResultService {
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
devData.setSqlDataHarm(sqlDataHarm);
|
||||
devData.setSqlData(sqlData);
|
||||
});
|
||||
info.add(devData);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
return info;
|
||||
}
|
||||
|
||||
@@ -3450,10 +3611,10 @@ public class ResultServiceImpl implements IResultService {
|
||||
switch (scriptCode) {
|
||||
// 保留2位小数
|
||||
case "FREQ": // 频率
|
||||
return 2;
|
||||
return 4;
|
||||
// 保留3位小数
|
||||
case "I": // 电流
|
||||
return 3;
|
||||
return 5;
|
||||
// 保留4位小数
|
||||
case "IMBV": // 电压不平衡度
|
||||
case "IMBA": // 电流不平衡度
|
||||
|
||||
@@ -58,7 +58,7 @@ public class PqScriptController extends BaseController {
|
||||
@OperateInfo(operateType = OperateType.ADD)
|
||||
@PostMapping("/add")
|
||||
@ApiOperation("新增检测脚本")
|
||||
@ApiImplicitParam(name = "pqDevParam", value = "检测脚本", required = true)
|
||||
@ApiImplicitParam(name = "param", value = "检测脚本", required = true)
|
||||
public HttpResult<String> add(@RequestBody @Validated PqScriptParam param) {
|
||||
String methodDescribe = getMethodDescribe("add");
|
||||
LogUtil.njcnDebug(log, "{},新增数据为:{}", methodDescribe, param);
|
||||
@@ -69,7 +69,7 @@ public class PqScriptController extends BaseController {
|
||||
@OperateInfo(operateType = OperateType.UPDATE)
|
||||
@PostMapping("/update")
|
||||
@ApiOperation("修改检测脚本")
|
||||
@ApiImplicitParam(name = "updateParam", value = "检测脚本", required = true)
|
||||
@ApiImplicitParam(name = "param", value = "检测脚本", required = true)
|
||||
public HttpResult<Boolean> update(@RequestBody @Validated PqScriptParam.UpdateParam param) {
|
||||
String methodDescribe = getMethodDescribe("update");
|
||||
LogUtil.njcnDebug(log, "{},修改数据为:{}", methodDescribe, param);
|
||||
@@ -126,10 +126,10 @@ public class PqScriptController extends BaseController {
|
||||
@GetMapping("/getAll")
|
||||
@ApiOperation("获取指定模式下的所有检测脚本")
|
||||
@ApiImplicitParam(name = "patternId", value = "模式Id", required = true)
|
||||
public HttpResult<List<Map<String, Object>>> getAllPqScript(@RequestParam("patternId") String patternId) {
|
||||
public HttpResult<List<PqScript>> getAllPqScript(@RequestParam("patternId") String patternId) {
|
||||
String methodDescribe = getMethodDescribe("getAllPqScript");
|
||||
LogUtil.njcnDebug(log, "{},查询数据为:{}", methodDescribe, patternId);
|
||||
List<Map<String, Object>> result = pqScriptService.listAllPqScript(patternId);
|
||||
List<PqScript> result = pqScriptService.listAllPqScript(patternId);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
|
||||
}
|
||||
|
||||
|
||||
@@ -72,6 +72,9 @@ public class PqScriptParam {
|
||||
@Max(value = 20, message = DetectionValidMessage.SCRIPT_CURR_FORMAT_ERROR)
|
||||
private Double ratedCurr;
|
||||
|
||||
@ApiModelProperty("是否为Fluke专用脚本")
|
||||
private Integer fluke;
|
||||
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
|
||||
@@ -73,6 +73,11 @@ public class PqScript extends BaseEntity implements Serializable {
|
||||
*/
|
||||
private Double ratedCurr;
|
||||
|
||||
/**
|
||||
* 是否为福禄克专用脚本。0-否 1-是
|
||||
*/
|
||||
private Integer fluke;
|
||||
|
||||
/**
|
||||
* 状态:0-删除 1-正常
|
||||
*/
|
||||
|
||||
@@ -92,6 +92,18 @@ public class PqScriptDtls implements Serializable {
|
||||
@TableField("RetainTime")
|
||||
private Double retainTime;
|
||||
|
||||
/**
|
||||
* 暂态前延时间(S)
|
||||
*/
|
||||
@TableField("FPreTime")
|
||||
private Double fPreTime;
|
||||
|
||||
/**
|
||||
* 暂态后延时间(S)
|
||||
*/
|
||||
@TableField("FAfterTime")
|
||||
private Double fAfterTime;
|
||||
|
||||
/**
|
||||
* 变动频度(次/min)
|
||||
*/
|
||||
|
||||
@@ -68,7 +68,7 @@ public interface IPqScriptService extends IService<PqScript> {
|
||||
* @param patternId 模式id
|
||||
* @return 检测脚本列表
|
||||
*/
|
||||
List<Map<String, Object>> listAllPqScript(String patternId);
|
||||
List<PqScript> listAllPqScript(String patternId);
|
||||
|
||||
/**
|
||||
* 根据脚本名称查询脚本
|
||||
|
||||
@@ -13,6 +13,7 @@ import com.njcn.gather.detection.pojo.enums.DetectionCodeEnum;
|
||||
import com.njcn.gather.detection.pojo.param.PreDetectionParam;
|
||||
import com.njcn.gather.device.pojo.enums.CommonEnum;
|
||||
import com.njcn.gather.device.pojo.po.PqDev;
|
||||
import com.njcn.gather.device.pojo.vo.PqDevVO;
|
||||
import com.njcn.gather.device.service.IPqDevService;
|
||||
import com.njcn.gather.plan.mapper.AdPlanMapper;
|
||||
import com.njcn.gather.plan.pojo.po.AdPlan;
|
||||
@@ -67,14 +68,14 @@ public class PqScriptDtlsServiceImpl extends ServiceImpl<PqScriptDtlsMapper, PqS
|
||||
private final static String INHARM_I = "InHarm_I";
|
||||
private final static String DIP = "Dip";
|
||||
private final static String FLICKER = "Flicker";
|
||||
@Value("${Dip.fPreTime}")
|
||||
private Double fPreTime;
|
||||
// @Value("${Dip.fPreTime}")
|
||||
// private Double fPreTime;
|
||||
@Value("${Dip.fRampIn}")
|
||||
private Double fRampIn;
|
||||
@Value("${Dip.fRampOut}")
|
||||
private Double fRampOut;
|
||||
@Value("${Dip.fAfterTime}")
|
||||
private Double fAfterTime;
|
||||
// @Value("${Dip.fAfterTime}")
|
||||
// private Double fAfterTime;
|
||||
@Value("${Flicker.waveFluType}")
|
||||
private String waveFluType;
|
||||
@Value("${Flicker.waveType}")
|
||||
@@ -384,6 +385,8 @@ public class PqScriptDtlsServiceImpl extends ServiceImpl<PqScriptDtlsMapper, PqS
|
||||
dip.setPhase(phase);
|
||||
dip.setTransValue(dipData.getFTransValue());
|
||||
dip.setRetainTime(dipData.getRetainTime());
|
||||
dip.setFPreTime(dipData.getFPreTime());
|
||||
dip.setFAfterTime(dipData.getFAfterTime());
|
||||
info.add(dip);
|
||||
}
|
||||
}
|
||||
@@ -959,6 +962,22 @@ public class PqScriptDtlsServiceImpl extends ServiceImpl<PqScriptDtlsMapper, PqS
|
||||
queryWrapper.eq(PqScriptDtls::getScriptIndex, -1)
|
||||
.eq(PqScriptDtls::getEnable, 1);
|
||||
pqScriptDtls = this.list(queryWrapper);
|
||||
// 相序校验中电流需加量需要依据企标10650.2中章节5.5.3的描述过载能力:2 倍额定电流连续,10 倍额定电流持续 1 s。
|
||||
// 考虑到有可能存在1A的额定电流,本处做特殊处理,加量分别为额定电流的0.2/0.4/0.6的标幺乘积加量
|
||||
// 电压暂不做处理,原因:1、电压的企标描述过载能力为4倍,空间较大;2、额定电压比如57.74V为浮点数,存在不确定小数位,避免引起算术误差;
|
||||
// 1. 获取额定电流,前端已做限制,相同额定电流才能一起检测
|
||||
String deviceId = param.getDevIds().get(0);
|
||||
PqDevVO pqDev = pqDevService.getPqDevById(deviceId);
|
||||
String devTypeId = pqDev.getDevType();
|
||||
DevType devType = devTypeService.getById(devTypeId);
|
||||
Double devCurr = devType.getDevCurr();
|
||||
for (int i = 0; i < pqScriptDtls.size(); i++) {
|
||||
PqScriptDtls scriptDtls = pqScriptDtls.get(i);
|
||||
// 注意此处scriptDtls.getValue() < 1.0,考虑到有些已经投入运行的地方,可能没有改库,避免不必要的异常
|
||||
if(scriptDtls.getValueType().equalsIgnoreCase("CUR") && scriptDtls.getValue() < 1.0){
|
||||
scriptDtls.setValue(devCurr * scriptDtls.getValue());
|
||||
}
|
||||
}
|
||||
} else if (param.getIsPhaseSequence().equals(CommonEnum.COEFFICIENT_TEST.getValue())) {
|
||||
//系数
|
||||
queryWrapper.in(PqScriptDtls::getScriptIndex, param.getIndexList())
|
||||
@@ -1037,10 +1056,10 @@ public class PqScriptDtlsServiceImpl extends ServiceImpl<PqScriptDtlsMapper, PqS
|
||||
dipDataDTO.setFTransValue(0.0);
|
||||
dipDataDTO.setFRetainTime(0.0);
|
||||
|
||||
dipDataDTO.setFPreTime(fPreTime);
|
||||
// dipDataDTO.setFPreTime(fPreTime);
|
||||
dipDataDTO.setFRampIn(fRampIn);
|
||||
dipDataDTO.setFRampOut(fRampOut);
|
||||
dipDataDTO.setFAfterTime(fAfterTime);
|
||||
// dipDataDTO.setFAfterTime(fAfterTime);
|
||||
|
||||
|
||||
channelListDTO.setDipData(dipDataDTO);
|
||||
@@ -1087,6 +1106,8 @@ public class PqScriptDtlsServiceImpl extends ServiceImpl<PqScriptDtlsMapper, PqS
|
||||
if (CollUtil.isNotEmpty(dipList)) {
|
||||
PqScriptDtls dip = dipList.get(0);
|
||||
dipDataDTO.setFTransValue(dip.getTransValue());
|
||||
dipDataDTO.setFPreTime(dip.getFPreTime());
|
||||
dipDataDTO.setFAfterTime(dip.getFAfterTime());
|
||||
if (devFly) {
|
||||
// if (isValueType) {
|
||||
dipDataDTO.setFTransValue(dip.getTransValue());
|
||||
|
||||
@@ -112,15 +112,15 @@ public class PqScriptServiceImpl extends ServiceImpl<PqScriptMapper, PqScript> i
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Map<String, Object>> listAllPqScript(String patternId) {
|
||||
public List<PqScript> listAllPqScript(String patternId) {
|
||||
List<PqScript> pqScriptList = this.lambdaQuery().eq(StrUtil.isNotBlank(patternId), PqScript::getPattern, patternId).eq(PqScript::getState, DataStateEnum.ENABLE.getCode()).list();
|
||||
List<Map<String, Object>> result = pqScriptList.stream().map(pqScript -> {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("id", pqScript.getId());
|
||||
map.put("name", pqScript.getName());
|
||||
return map;
|
||||
}).collect(Collectors.toList());
|
||||
return result;
|
||||
// List<Map<String, Object>> result = pqScriptList.stream().map(pqScript -> {
|
||||
// Map<String, Object> map = new HashMap<>();
|
||||
// map.put("id", pqScript.getId());
|
||||
// map.put("name", pqScript.getName());
|
||||
// return map;
|
||||
// }).collect(Collectors.toList());
|
||||
return pqScriptList;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -139,7 +139,7 @@ public class PqScriptServiceImpl extends ServiceImpl<PqScriptMapper, PqScript> i
|
||||
wrapper.eq("state", DataStateEnum.ENABLE.getCode());
|
||||
wrapper.eq("name", param.getName());
|
||||
if (isExcludeSelf) {
|
||||
if(param instanceof PqScriptParam.UpdateParam){
|
||||
if (param instanceof PqScriptParam.UpdateParam) {
|
||||
wrapper.ne("id", ((PqScriptParam.UpdateParam) param).getId());
|
||||
}
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user