126 Commits

Author SHA1 Message Date
caozehui
6c34c4a968 微调 2025-04-03 08:37:50 +08:00
caozehui
186d701dcb 微调 2025-04-01 14:38:11 +08:00
caozehui
9b1b21dad5 代码调整 2025-04-01 09:50:53 +08:00
caozehui
00bda55ddd 微调 2025-04-01 09:48:17 +08:00
wr
593b7e9d7b 参数返回信息解决 2025-03-31 14:41:01 +08:00
f842886c00 测试提交 2025-03-31 13:53:37 +08:00
caozehui
af58306d96 微调 2025-03-31 11:25:06 +08:00
wr
09972e0764 新增检测详情参数组装接口 2025-03-31 10:06:48 +08:00
wr
7ba71562d8 正式检测检测结果增加单位信息 2025-03-28 15:24:55 +08:00
caozehui
71ba7fa139 代码调整 2025-03-28 15:06:57 +08:00
caozehui
48408859b1 代码调整、修改设备检测人bug 2025-03-28 09:32:50 +08:00
caozehui
fef01b692a 调整报告模板修改接口 2025-03-27 13:55:04 +08:00
caozehui
55208ecf69 整理代码、修改登录接口使用密文传输 2025-03-26 15:43:39 +08:00
caozehui
9a7d841d9c 整理代码 2025-03-26 10:01:56 +08:00
caozehui
4ef5c982de 微调 2025-03-26 08:52:14 +08:00
caozehui
22028fe7eb 调整检测计划导入、导出功能 2025-03-25 16:10:17 +08:00
wr
6ff3d7e336 1.添加相角启用配置和逻辑处理
2.修正数据处理逻辑以支持相角启用配置
2025-03-25 14:28:29 +08:00
fe7af8a632 小项结果汇集大项结果逻辑调整 2025-03-25 11:32:31 +08:00
caozehui
c67a2c8323 微调 2025-03-24 20:38:24 +08:00
wr
ce217b8b86 修正默认参与比较值逻辑,增加不参与误差比较状态 2025-03-24 18:56:03 +08:00
caozehui
ebc52eb8ba 微调 2025-03-24 15:43:20 +08:00
caozehui
0e1fb0e254 微调 2025-03-24 10:50:22 +08:00
caozehui
4d61cfc490 微调 2025-03-24 10:34:19 +08:00
caozehui
d0491b4850 微调 2025-03-24 10:34:07 +08:00
caozehui
610a3c1d13 微调 2025-03-24 08:58:37 +08:00
caozehui
ac0a9dd777 微调 2025-03-20 13:44:16 +08:00
caozehui
f294cb315f 微调 2025-03-20 11:15:20 +08:00
caozehui
051e7fe14a 微调 2025-03-20 09:02:21 +08:00
caozehui
38cbb22eff 微调 2025-03-18 13:49:46 +08:00
caozehui
423fa581b4 微调 2025-03-18 13:45:34 +08:00
caozehui
279a8a6e83 微调 2025-03-17 15:46:23 +08:00
caozehui
a108b295d1 复制误差体系 2025-03-17 11:18:44 +08:00
wr
04bd8a7db3 Merge remote-tracking branch 'origin/master'
# Conflicts:
#	detection/src/main/java/com/njcn/gather/detection/service/impl/DetectionServiceImpl.java
2025-03-14 16:36:14 +08:00
wr
d084950090 解决精度问题 2025-03-14 16:32:47 +08:00
caozehui
ff53c91279 微调 2025-03-14 16:31:20 +08:00
wr
751dc56568 解决误差值问题 2025-03-14 16:12:32 +08:00
7f42a21536 系数代码提交 2025-03-14 13:32:57 +08:00
caozehui
8ca804283a 微调 2025-03-14 11:07:13 +08:00
wr
c43c5b4342 微调 2025-03-14 10:49:58 +08:00
wr
03ec551f71 Merge remote-tracking branch 'origin/master' 2025-03-13 19:59:26 +08:00
wr
0ddf98e1af 检测脚本增加额定电压和电流(取消装置层获取) 2025-03-13 19:58:28 +08:00
caozehui
1c014a75a7 微调 2025-03-12 15:04:01 +08:00
caozehui
c80ae2f95f 微调 2025-03-12 10:36:13 +08:00
wr
d633b0bd35 微调 2025-03-11 18:46:29 +08:00
wr
81645ae1ba 微调 2025-03-11 18:24:02 +08:00
caozehui
708a4e6fbd 脚本详情项禁用后,该脚本详情项的结果不参与装置的检测结果 2025-03-11 15:31:26 +08:00
caozehui
c60d41af10 微调 2025-03-11 09:31:21 +08:00
wr
91e2e9e7fe 微调 2025-03-11 09:00:02 +08:00
wr
d1101cd157 1.解决间谐波存值问题,取消基波存值
2.解决原始值和结果值入库不一致问题
2025-03-10 20:52:36 +08:00
wr
7594657021 Merge remote-tracking branch 'origin/master' 2025-03-10 18:57:59 +08:00
wr
9bef1331f2 解决间谐波检测脚本问题 2025-03-10 18:44:47 +08:00
caozehui
77e2a73345 微调 2025-03-10 18:38:41 +08:00
wr
1b518e508e 解决间谐波检测脚本问题 2025-03-10 18:08:53 +08:00
wr
1c12187d93 解决间谐波检测脚本问题 2025-03-10 16:49:02 +08:00
wr
67b6f822c3 调整检测详情展示单位 2025-03-10 10:51:55 +08:00
caozehui
337797b0ed 微调 2025-03-10 10:12:52 +08:00
caozehui
1075a72375 微调 2025-03-08 17:51:22 +08:00
caozehui
9fcf4e39a4 微调 2025-03-08 17:45:02 +08:00
caozehui
189ffad11d 微调 2025-03-08 16:49:54 +08:00
wr
efccaae69e 微调 2025-03-08 14:33:42 +08:00
caozehui
34d4321290 微调 2025-03-08 14:26:01 +08:00
caozehui
6cca428d62 微调 2025-03-08 10:13:35 +08:00
caozehui
653c556867 微调 2025-03-07 16:15:12 +08:00
caozehui
8c4ce5d8af 微调 2025-03-07 14:51:52 +08:00
caozehui
2261a786a4 微调 2025-03-07 14:30:02 +08:00
wr
1f5916e898 微调 2025-03-07 12:28:20 +08:00
wr
fe9a81a3a3 微调 2025-03-07 11:35:51 +08:00
wr
c0466ed189 Merge remote-tracking branch 'origin/master' 2025-03-07 11:24:34 +08:00
wr
bc37e47b43 微调 2025-03-07 11:22:29 +08:00
caozehui
6968bf437d 切换误差体系-未做完 2025-03-07 10:31:32 +08:00
caozehui
08be6c15fb 程控源功能 2025-03-07 09:16:18 +08:00
wr
1d7440b4f7 微调 2025-03-07 08:44:07 +08:00
wr
e0e1b6ea9e 微调 2025-03-06 16:00:15 +08:00
wr
646e33d93a 微调 2025-03-06 15:51:58 +08:00
wr
8419450427 微调 2025-03-06 08:46:15 +08:00
wr
ae94e35607 微调 2025-03-05 16:49:17 +08:00
wr
6fb6733727 增加部分教学模式,微调部分代码,增加原始数据转换工具类 2025-03-05 11:44:08 +08:00
caozehui
273dd18405 微调 2025-03-05 11:39:09 +08:00
caozehui
8e78ae4e4c 微调 2025-03-04 14:30:02 +08:00
caozehui
dda18320f8 微调 2025-03-04 14:10:44 +08:00
wr
993ac5f019 微调 2025-03-04 11:34:38 +08:00
caozehui
98dd7894b8 微调 2025-03-04 09:23:09 +08:00
wr
f34a996705 微调 2025-03-03 15:27:50 +08:00
caozehui
bc20fc0705 不合格项复检 2025-03-03 11:35:35 +08:00
5d606673a6 加固代码提交 2025-03-03 11:07:45 +08:00
wr
a4f5034c7f 1.增加脚本修改值类型 2025-02-27 16:23:59 +08:00
caozehui
6e6a6512c9 微调 2025-02-27 15:09:45 +08:00
wr
c7ac87c930 微调 2025-02-27 14:53:16 +08:00
wr
06b13fdfe1 微调 2025-02-27 14:51:50 +08:00
wr
a2ac240150 微调 2025-02-27 14:08:38 +08:00
wr
19e99fda9e 1.解决相对值脚本电压电流问题 2025-02-27 10:26:51 +08:00
wr
bf94ed37d9 1.微调 2025-02-26 20:09:31 +08:00
wr
5ee33fabdf 1.解决误差为0是不符合问题
2.优化检测脚本回显和通讯脚本默认值问题
3.调整三相不平衡度公式工具类
2025-02-25 20:57:41 +08:00
wr
d65b68bbf4 Merge remote-tracking branch 'origin/master' 2025-02-24 16:38:23 +08:00
wr
6fb57f8422 微调 2025-02-24 16:38:04 +08:00
caozehui
cbbf2db4eb 检测计划-检测中、检测完成不能修改脚本、误差体系,数据分析微调 2025-02-24 16:31:22 +08:00
837ea9e369 楼下报告调整 2025-02-24 11:02:59 +08:00
caozehui
496c7a7908 微调 2025-02-24 10:40:38 +08:00
caozehui
758b2a9033 微调 2025-02-24 10:00:58 +08:00
caozehui
913a86dcc7 调整使用RequestUtil工具类来获取登录用户的信息 2025-02-24 09:43:59 +08:00
wr
84879b8d18 1.微调 2025-02-21 15:59:29 +08:00
caozehui
79b89e7e8b 当检测计划的检测状态为检测完成时,才能进行数据分析 2025-02-21 13:55:15 +08:00
wr
cb06b77aef 1.解决mysql index关键字
2.增加通讯脚本相关接口
2025-02-21 10:41:57 +08:00
wr
b746a6445f 装置下发参数公式接口编写 2025-02-19 16:51:13 +08:00
caozehui
c062e2a47f 检测计划导出、导入功能调整 2025-02-19 08:42:52 +08:00
wr
5828a52329 微调 2025-02-18 15:40:33 +08:00
wr
bb9a0f586f 调整检测脚本新增,增加设定值表新增 2025-02-18 15:38:54 +08:00
8cef3c8358 加固代码提交 2025-02-18 14:58:52 +08:00
caozehui
0c012152bb 数据分析微调 2025-02-17 17:59:37 +08:00
wr
76ec26dca0 新增检测脚本,调整检测脚本返回值 2025-02-17 16:32:07 +08:00
caozehui
a5472781de 数据分析微调 2025-02-17 15:11:01 +08:00
caozehui
ff7fbf92e6 日志删除 2025-02-17 14:29:35 +08:00
158422860d 楼下报告调整 2025-02-17 11:28:05 +08:00
422645bcfd 楼下报告调整 2025-02-17 11:14:01 +08:00
caozehui
dd96bc4171 微调 2025-02-14 16:34:37 +08:00
caozehui
2c950b3ac5 微调 2025-02-14 16:24:13 +08:00
wr
25e975fbc8 Merge remote-tracking branch 'origin/master' 2025-02-14 10:59:22 +08:00
wr
a006c0df33 微调 2025-02-14 10:58:09 +08:00
caozehui
b5cee74731 微调 2025-02-14 10:32:31 +08:00
caozehui
801e17e274 移除headers中的Refresh-Token,添加Is-Refresh-Token 2025-02-13 21:04:55 +08:00
wr
93d649162d 微调 2025-02-13 16:25:23 +08:00
cc529b7e91 心跳日志注释 2025-02-13 16:19:49 +08:00
caozehui
8f719e5a73 调整复检次数 2025-02-12 15:22:24 +08:00
wr
8f8788b43c 正式检测系统加固 2025-02-12 15:14:29 +08:00
caozehui
04135f7044 日志相关 2025-02-12 14:44:29 +08:00
caozehui
aca953e827 微调-设备复检次数大于等于3次时,计划状态改为检测完成 2025-02-12 14:43:56 +08:00
224 changed files with 9631 additions and 4517 deletions

View File

@@ -3,14 +3,12 @@ package com.njcn.gather.detection.controller;
import com.njcn.common.pojo.annotation.OperateInfo;
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
import com.njcn.common.pojo.response.HttpResult;
import com.njcn.gather.detection.handler.SocketDevResponseService;
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.service.impl.DetectionServiceImpl;
import com.njcn.gather.detection.util.socket.MsgUtil;
import com.njcn.gather.device.pojo.vo.PreDetection;
import com.njcn.gather.device.service.IPqDevService;
import com.njcn.gather.script.pojo.param.PqScriptIssueParam;
import com.njcn.gather.script.pojo.po.SourceIssue;
import com.njcn.gather.script.service.IPqScriptDtlsService;
import com.njcn.web.controller.BaseController;
import com.njcn.web.utils.HttpResultUtil;
@@ -22,10 +20,6 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@Slf4j
@Api(tags = "预检测")
@@ -42,8 +36,7 @@ public class PreDetectionController extends BaseController {
private final IPqDevService iPqDevService;
private final SocketDevResponseService socketDevResponseService;
/**
@@ -53,12 +46,54 @@ public class PreDetectionController extends BaseController {
@OperateInfo
@ApiOperation("开始检测")
@ApiImplicitParam(name = "param", value = "查询参数", required = true)
public HttpResult<String> startPreTest(@RequestBody @Validated PreDetectionParam param){
public HttpResult<String> startPreTest(@RequestBody @Validated PreDetectionParam param) {
String methodDescribe = getMethodDescribe("startPreTest");
preDetectionService.sourceCommunicationCheck(param);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
}
/**
* 程控源-源通讯校验
*
* @param param
* @return
*/
@PostMapping("/ytxCheckSimulate")
@OperateInfo
@ApiOperation("源通讯校验")
@ApiImplicitParam(name = "param", value = "查询参数", required = true)
public HttpResult<String> ytxCheckSimulate(@RequestBody @Validated SimulateDetectionParam param) {
String methodDescribe = getMethodDescribe("ytxCheckSimulate");
preDetectionService.ytxCheckSimulate(param);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
}
/**
* 程控源检测
*/
@PostMapping("/startSimulateTest")
@OperateInfo
@ApiOperation("启动")
@ApiImplicitParam(name = "param", value = "查询参数", required = true)
public HttpResult<String> startTestSimulate(@RequestBody @Validated SimulateDetectionParam param) {
String methodDescribe = getMethodDescribe("startTestSimulate");
preDetectionService.sendScript(param);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
}
/**
* 关闭检测-程控源
*/
@PostMapping("/closeSimulateTest")
@OperateInfo
@ApiOperation("停止")
@ApiImplicitParam(name = "param", value = "查询参数", required = true)
public HttpResult<String> closeSimulateTest(@RequestBody @Validated SimulateDetectionParam param) {
String methodDescribe = getMethodDescribe("closeSimulateTest");
preDetectionService.closeTestSimulate(param);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
}
/**
* 系数校验
@@ -67,7 +102,7 @@ public class PreDetectionController extends BaseController {
@OperateInfo
@ApiOperation("系数校验")
@ApiImplicitParam(name = "param", value = "查询参数", required = true)
public HttpResult<String> coefficientCheck(@RequestBody PreDetectionParam param){
public HttpResult<String> coefficientCheck(@RequestBody PreDetectionParam param) {
String methodDescribe = getMethodDescribe("coefficientCheck");
preDetectionService.coefficientCheck(param);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
@@ -81,7 +116,7 @@ public class PreDetectionController extends BaseController {
@OperateInfo
@ApiOperation("暂停检测")
@ApiImplicitParam(name = "param", value = "参数", required = true)
public HttpResult<String> temStopTest(){
public HttpResult<String> temStopTest() {
String methodDescribe = getMethodDescribe("temStopTest");
preDetectionService.temStopTest();
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
@@ -94,126 +129,9 @@ public class PreDetectionController extends BaseController {
@OperateInfo
@ApiOperation("重新开始检测")
@ApiImplicitParam(name = "param", value = "参数", required = true)
public HttpResult<String> restartTemTest(@RequestBody PreDetectionParam param){
public HttpResult<String> restartTemTest(@RequestBody PreDetectionParam param) {
String methodDescribe = getMethodDescribe("restartTemTest");
preDetectionService.restartTemTest(param);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
}
/**
* 测试
*/
@PostMapping("/startTest")
@OperateInfo
@ApiOperation("测试")
@ApiImplicitParam(name = "param", value = "查询参数", required = true)
public HttpResult<String> startTest(@RequestBody PreDetectionParam param){
String methodDescribe = getMethodDescribe("startTest");
//preDetectionService.startTest(param);
MsgUtil.socketDataMsg("{\"Time\":\"2025-01-15T15:49:50.815\",\"ID\":\"172.17.102.204_2\",\"result\":false,\"SqlData\":[{\"type\":\"real\",\"desc\":\"FREQ\",\"list\":{\"A\":null,\"B\":null,\"C\":null,\"T\":\"50.001000\"}}],\"SqlDataHarm\":[]}");
MsgUtil.socketDataMsg("{\"Time\":\"2025-01-15T15:49:50.815\",\"ID\":\"172.17.102.204_3\",\"result\":false,\"SqlData\":[{\"type\":\"real\",\"desc\":\"FREQ\",\"list\":{\"A\":null,\"B\":null,\"C\":null,\"T\":\"50.001100\"}}],\"SqlDataHarm\":[]}");
MsgUtil.socketDataMsg("{\"Time\":\"2025-01-15T15:49:50.815\",\"ID\":\"172.17.102.204_4\",\"result\":false,\"SqlData\":[{\"type\":\"real\",\"desc\":\"FREQ\",\"list\":{\"A\":null,\"B\":null,\"C\":null,\"T\":\"50.001100\"}}],\"SqlDataHarm\":[]}");
MsgUtil.socketDataMsg("{\"Time\":\"2025-01-15T15:49:53.815\",\"ID\":\"172.17.102.204_1\",\"result\":false,\"SqlData\":[{\"type\":\"real\",\"desc\":\"FREQ\",\"list\":{\"A\":null,\"B\":null,\"C\":null,\"T\":\"50.001000\"}}],\"SqlDataHarm\":[]}");
MsgUtil.socketDataMsg("{\"Time\":\"2025-01-15T15:49:53.815\",\"ID\":\"172.17.102.204_2\",\"result\":false,\"SqlData\":[{\"type\":\"real\",\"desc\":\"FREQ\",\"list\":{\"A\":null,\"B\":null,\"C\":null,\"T\":\"50.001000\"}}],\"SqlDataHarm\":[]}");
MsgUtil.socketDataMsg("{\"Time\":\"2025-01-15T15:49:53.815\",\"ID\":\"172.17.102.204_3\",\"result\":false,\"SqlData\":[{\"type\":\"real\",\"desc\":\"FREQ\",\"list\":{\"A\":null,\"B\":null,\"C\":null,\"T\":\"50.001000\"}}],\"SqlDataHarm\":[]}");
MsgUtil.socketDataMsg("{\"Time\":\"2025-01-15T15:49:53.815\",\"ID\":\"172.17.102.204_4\",\"result\":false,\"SqlData\":[{\"type\":\"real\",\"desc\":\"FREQ\",\"list\":{\"A\":null,\"B\":null,\"C\":null,\"T\":\"50.001000\"}}],\"SqlDataHarm\":[]}");
MsgUtil.socketDataMsg("{\"Time\":\"2025-01-15T15:49:56.815\",\"ID\":\"172.17.102.204_1\",\"result\":false,\"SqlData\":[{\"type\":\"real\",\"desc\":\"FREQ\",\"list\":{\"A\":null,\"B\":null,\"C\":null,\"T\":\"50.001000\"}}],\"SqlDataHarm\":[]}");
MsgUtil.socketDataMsg("{\"Time\":\"2025-01-15T15:49:56.815\",\"ID\":\"172.17.102.204_2\",\"result\":false,\"SqlData\":[{\"type\":\"real\",\"desc\":\"FREQ\",\"list\":{\"A\":null,\"B\":null,\"C\":null,\"T\":\"50.001000\"}}],\"SqlDataHarm\":[]}");
MsgUtil.socketDataMsg("{\"Time\":\"2025-01-15T15:49:56.815\",\"ID\":\"172.17.102.204_3\",\"result\":false,\"SqlData\":[{\"type\":\"real\",\"desc\":\"FREQ\",\"list\":{\"A\":null,\"B\":null,\"C\":null,\"T\":\"50.001000\"}}],\"SqlDataHarm\":[]}");
MsgUtil.socketDataMsg("{\"Time\":\"2025-01-15T15:49:56.815\",\"ID\":\"172.17.102.204_4\",\"result\":false,\"SqlData\":[{\"type\":\"real\",\"desc\":\"FREQ\",\"list\":{\"A\":null,\"B\":null,\"C\":null,\"T\":\"50.001000\"}}],\"SqlDataHarm\":[]}");
MsgUtil.socketDataMsg("{\"Time\":\"2025-01-15T15:49:59.815\",\"ID\":\"172.17.102.204_1\",\"result\":false,\"SqlData\":[{\"type\":\"real\",\"desc\":\"FREQ\",\"list\":{\"A\":null,\"B\":null,\"C\":null,\"T\":\"50.001100\"}}],\"SqlDataHarm\":[]}");
MsgUtil.socketDataMsg("{\"Time\":\"2025-01-15T15:49:59.815\",\"ID\":\"172.17.102.204_2\",\"result\":false,\"SqlData\":[{\"type\":\"real\",\"desc\":\"FREQ\",\"list\":{\"A\":null,\"B\":null,\"C\":null,\"T\":\"50.001000\"}}],\"SqlDataHarm\":[]}");
MsgUtil.socketDataMsg("{\"Time\":\"2025-01-15T15:49:59.815\",\"ID\":\"172.17.102.204_3\",\"result\":false,\"SqlData\":[{\"type\":\"real\",\"desc\":\"FREQ\",\"list\":{\"A\":null,\"B\":null,\"C\":null,\"T\":\"50.001000\"}}],\"SqlDataHarm\":[]}");
MsgUtil.socketDataMsg("{\"Time\":\"2025-01-15T15:49:59.815\",\"ID\":\"172.17.102.204_4\",\"result\":false,\"SqlData\":[{\"type\":\"real\",\"desc\":\"FREQ\",\"list\":{\"A\":null,\"B\":null,\"C\":null,\"T\":\"50.001000\"}}],\"SqlDataHarm\":[]}");
MsgUtil.socketDataMsg("{\"Time\":\"2025-01-15T15:50:02.8\",\"ID\":\"172.17.102.204_1\",\"result\":false,\"SqlData\":[{\"type\":\"real\",\"desc\":\"FREQ\",\"list\":{\"A\":null,\"B\":null,\"C\":null,\"T\":\"50.001000\"}}],\"SqlDataHarm\":[]}");
MsgUtil.socketDataMsg("{\"Time\":\"2025-01-15T15:50:02.8\",\"ID\":\"172.17.102.204_2\",\"result\":false,\"SqlData\":[{\"type\":\"real\",\"desc\":\"FREQ\",\"list\":{\"A\":null,\"B\":null,\"C\":null,\"T\":\"50.001000\"}}],\"SqlDataHarm\":[]}");
MsgUtil.socketDataMsg("{\"Time\":\"2025-01-15T15:50:02.8\",\"ID\":\"172.17.102.204_3\",\"result\":false,\"SqlData\":[{\"type\":\"real\",\"desc\":\"FREQ\",\"list\":{\"A\":null,\"B\":null,\"C\":null,\"T\":\"50.001000\"}}],\"SqlDataHarm\":[]}");
MsgUtil.socketDataMsg("{\"Time\":\"2025-01-15T15:50:02.8\",\"ID\":\"172.17.102.204_4\",\"result\":false,\"SqlData\":[{\"type\":\"real\",\"desc\":\"FREQ\",\"list\":{\"A\":null,\"B\":null,\"C\":null,\"T\":\"50.001000\"}}],\"SqlDataHarm\":[]}");
MsgUtil.socketDataMsg("{\"Time\":\"2025-01-15T15:50:03\",\"ID\":\"172.17.102.204_1\",\"result\":false,\"SqlData\":[{\"type\":\"real\",\"desc\":\"FREQ\",\"list\":{\"A\":null,\"B\":null,\"C\":null,\"T\":\"50.001000\"}}],\"SqlDataHarm\":[]}");
MsgUtil.socketDataMsg("{\"Time\":\"2025-01-15T15:50:03\",\"ID\":\"172.17.102.204_2\",\"result\":false,\"SqlData\":[{\"type\":\"real\",\"desc\":\"FREQ\",\"list\":{\"A\":null,\"B\":null,\"C\":null,\"T\":\"50.001000\"}}],\"SqlDataHarm\":[]}");
MsgUtil.socketDataMsg("{\"Time\":\"2025-01-15T15:50:03\",\"ID\":\"172.17.102.204_3\",\"result\":false,\"SqlData\":[{\"type\":\"real\",\"desc\":\"FREQ\",\"list\":{\"A\":null,\"B\":null,\"C\":null,\"T\":\"50.001000\"}}],\"SqlDataHarm\":[]}");
MsgUtil.socketDataMsg("{\"Time\":\"2025-01-15T15:50:03\",\"ID\":\"172.17.102.204_4\",\"result\":false,\"SqlData\":[{\"type\":\"real\",\"desc\":\"FREQ\",\"list\":{\"A\":null,\"B\":null,\"C\":null,\"T\":\"50.001000\"}}],\"SqlDataHarm\":[]}");
MsgUtil.socketDataMsg("{\"Time\":\"2025-01-15T15:50:06\",\"ID\":\"172.17.102.204_1\",\"result\":false,\"SqlData\":[{\"type\":\"real\",\"desc\":\"FREQ\",\"list\":{\"A\":null,\"B\":null,\"C\":null,\"T\":\"50.001100\"}}],\"SqlDataHarm\":[]}");
MsgUtil.socketDataMsg("{\"Time\":\"2025-01-15T15:50:06\",\"ID\":\"172.17.102.204_2\",\"result\":false,\"SqlData\":[{\"type\":\"real\",\"desc\":\"FREQ\",\"list\":{\"A\":null,\"B\":null,\"C\":null,\"T\":\"50.001100\"}}],\"SqlDataHarm\":[]}");
MsgUtil.socketDataMsg("{\"Time\":\"2025-01-15T15:50:06\",\"ID\":\"172.17.102.204_3\",\"result\":false,\"SqlData\":[{\"type\":\"real\",\"desc\":\"FREQ\",\"list\":{\"A\":null,\"B\":null,\"C\":null,\"T\":\"50.001000\"}}],\"SqlDataHarm\":[]}");
MsgUtil.socketDataMsg("{\"Time\":\"2025-01-15T15:50:06\",\"ID\":\"172.17.102.204_4\",\"result\":false,\"SqlData\":[{\"type\":\"real\",\"desc\":\"FREQ\",\"list\":{\"A\":null,\"B\":null,\"C\":null,\"T\":\"50.001100\"}}],\"SqlDataHarm\":[]}");
MsgUtil.socketDataMsg("{\"Time\":\"2025-01-15T15:50:09\",\"ID\":\"172.17.102.204_1\",\"result\":false,\"SqlData\":[{\"type\":\"real\",\"desc\":\"FREQ\",\"list\":{\"A\":null,\"B\":null,\"C\":null,\"T\":\"50.001000\"}}],\"SqlDataHarm\":[]}");
MsgUtil.socketDataMsg("{\"Time\":\"2025-01-15T15:50:09\",\"ID\":\"172.17.102.204_2\",\"result\":false,\"SqlData\":[{\"type\":\"real\",\"desc\":\"FREQ\",\"list\":{\"A\":null,\"B\":null,\"C\":null,\"T\":\"50.001000\"}}],\"SqlDataHarm\":[]}");
MsgUtil.socketDataMsg("{\"Time\":\"2025-01-15T15:50:09\",\"ID\":\"172.17.102.204_3\",\"result\":false,\"SqlData\":[{\"type\":\"real\",\"desc\":\"FREQ\",\"list\":{\"A\":null,\"B\":null,\"C\":null,\"T\":\"50.001000\"}}],\"SqlDataHarm\":[]}");
MsgUtil.socketDataMsg("{\"Time\":\"2025-01-15T15:50:09\",\"ID\":\"172.17.102.204_4\",\"result\":false,\"SqlData\":[{\"type\":\"real\",\"desc\":\"FREQ\",\"list\":{\"A\":null,\"B\":null,\"C\":null,\"T\":\"50.001000\"}}],\"SqlDataHarm\":[]}");
MsgUtil.socketDataMsg("{\"Time\":\"2025-01-15T15:50:12\",\"ID\":\"172.17.102.204_1\",\"result\":false,\"SqlData\":[{\"type\":\"real\",\"desc\":\"FREQ\",\"list\":{\"A\":null,\"B\":null,\"C\":null,\"T\":\"50.001000\"}}],\"SqlDataHarm\":[]}");
MsgUtil.socketDataMsg("{\"Time\":\"2025-01-15T15:50:12\",\"ID\":\"172.17.102.204_2\",\"result\":false,\"SqlData\":[{\"type\":\"real\",\"desc\":\"FREQ\",\"list\":{\"A\":null,\"B\":null,\"C\":null,\"T\":\"50.001000\"}}],\"SqlDataHarm\":[]}");
MsgUtil.socketDataMsg("{\"Time\":\"2025-01-15T15:50:12\",\"ID\":\"172.17.102.204_3\",\"result\":false,\"SqlData\":[{\"type\":\"real\",\"desc\":\"FREQ\",\"list\":{\"A\":null,\"B\":null,\"C\":null,\"T\":\"50.001000\"}}],\"SqlDataHarm\":[]}");
MsgUtil.socketDataMsg("{\"Time\":\"2025-01-15T15:50:12\",\"ID\":\"172.17.102.204_4\",\"result\":false,\"SqlData\":[{\"type\":\"real\",\"desc\":\"FREQ\",\"list\":{\"A\":null,\"B\":null,\"C\":null,\"T\":\"50.001000\"}}],\"SqlDataHarm\":[]}");
MsgUtil.socketDataMsg("{\"Time\":\"2025-01-15T15:50:15\",\"ID\":\"172.17.102.204_1\",\"result\":false,\"SqlData\":[{\"type\":\"real\",\"desc\":\"FREQ\",\"list\":{\"A\":null,\"B\":null,\"C\":null,\"T\":\"50.001100\"}}],\"SqlDataHarm\":[]}");
MsgUtil.socketDataMsg("{\"Time\":\"2025-01-15T15:50:15\",\"ID\":\"172.17.102.204_2\",\"result\":false,\"SqlData\":[{\"type\":\"real\",\"desc\":\"FREQ\",\"list\":{\"A\":null,\"B\":null,\"C\":null,\"T\":\"50.001100\"}}],\"SqlDataHarm\":[]}");
MsgUtil.socketDataMsg("{\"Time\":\"2025-01-15T15:50:15\",\"ID\":\"172.17.102.204_3\",\"result\":false,\"SqlData\":[{\"type\":\"real\",\"desc\":\"FREQ\",\"list\":{\"A\":null,\"B\":null,\"C\":null,\"T\":\"50.001000\"}}],\"SqlDataHarm\":[]}");
MsgUtil.socketDataMsg("{\"Time\":\"2025-01-15T15:50:15\",\"ID\":\"172.17.102.204_4\",\"result\":false,\"SqlData\":[{\"type\":\"real\",\"desc\":\"FREQ\",\"list\":{\"A\":null,\"B\":null,\"C\":null,\"T\":\"50.001100\"}}],\"SqlDataHarm\":[]}");
MsgUtil.socketDataMsg("{\"Time\":\"2025-01-15T15:50:18\",\"ID\":\"172.17.102.204_1\",\"result\":false,\"SqlData\":[{\"type\":\"real\",\"desc\":\"FREQ\",\"list\":{\"A\":null,\"B\":null,\"C\":null,\"T\":\"50.001000\"}}],\"SqlDataHarm\":[]}");
MsgUtil.socketDataMsg("{\"Time\":\"2025-01-15T15:50:18\",\"ID\":\"172.17.102.204_2\",\"result\":false,\"SqlData\":[{\"type\":\"real\",\"desc\":\"FREQ\",\"list\":{\"A\":null,\"B\":null,\"C\":null,\"T\":\"50.001000\"}}],\"SqlDataHarm\":[]}");
MsgUtil.socketDataMsg("{\"Time\":\"2025-01-15T15:50:18\",\"ID\":\"172.17.102.204_3\",\"result\":false,\"SqlData\":[{\"type\":\"real\",\"desc\":\"FREQ\",\"list\":{\"A\":null,\"B\":null,\"C\":null,\"T\":\"50.001000\"}}],\"SqlDataHarm\":[]}");
MsgUtil.socketDataMsg("{\"Time\":\"2025-01-15T15:50:18\",\"ID\":\"172.17.102.204_4\",\"result\":false,\"SqlData\":[{\"type\":\"real\",\"desc\":\"FREQ\",\"list\":{\"A\":null,\"B\":null,\"C\":null,\"T\":\"50.001000\"}}],\"SqlDataHarm\":[]}");
MsgUtil.socketDataMsg("{\"Time\":\"2025-01-15T15:50:21\",\"ID\":\"172.17.102.204_1\",\"result\":false,\"SqlData\":[{\"type\":\"real\",\"desc\":\"FREQ\",\"list\":{\"A\":null,\"B\":null,\"C\":null,\"T\":\"50.001000\"}}],\"SqlDataHarm\":[]}");
MsgUtil.socketDataMsg("{\"Time\":\"2025-01-15T15:50:21\",\"ID\":\"172.17.102.204_2\",\"result\":false,\"SqlData\":[{\"type\":\"real\",\"desc\":\"FREQ\",\"list\":{\"A\":null,\"B\":null,\"C\":null,\"T\":\"50.001000\"}}],\"SqlDataHarm\":[]}");
MsgUtil.socketDataMsg("{\"Time\":\"2025-01-15T15:50:21\",\"ID\":\"172.17.102.204_3\",\"result\":false,\"SqlData\":[{\"type\":\"real\",\"desc\":\"FREQ\",\"list\":{\"A\":null,\"B\":null,\"C\":null,\"T\":\"50.001000\"}}],\"SqlDataHarm\":[]}");
MsgUtil.socketDataMsg("{\"Time\":\"2025-01-15T15:50:21\",\"ID\":\"172.17.102.204_4\",\"result\":false,\"SqlData\":[{\"type\":\"real\",\"desc\":\"FREQ\",\"list\":{\"A\":null,\"B\":null,\"C\":null,\"T\":\"50.001000\"}}],\"SqlDataHarm\":[]}");
MsgUtil.socketDataMsg("{\"Time\":\"2025-01-15T15:50:24\",\"ID\":\"172.17.102.204_1\",\"result\":false,\"SqlData\":[{\"type\":\"real\",\"desc\":\"FREQ\",\"list\":{\"A\":null,\"B\":null,\"C\":null,\"T\":\"50.001000\"}}],\"SqlDataHarm\":[]}");
MsgUtil.socketDataMsg("{\"Time\":\"2025-01-15T15:50:24\",\"ID\":\"172.17.102.204_2\",\"result\":false,\"SqlData\":[{\"type\":\"real\",\"desc\":\"FREQ\",\"list\":{\"A\":null,\"B\":null,\"C\":null,\"T\":\"50.001000\"}}],\"SqlDataHarm\":[]}");
MsgUtil.socketDataMsg("{\"Time\":\"2025-01-15T15:50:24\",\"ID\":\"172.17.102.204_3\",\"result\":false,\"SqlData\":[{\"type\":\"real\",\"desc\":\"FREQ\",\"list\":{\"A\":null,\"B\":null,\"C\":null,\"T\":\"50.001100\"}}],\"SqlDataHarm\":[]}");
MsgUtil.socketDataMsg("{\"Time\":\"2025-01-15T15:50:24\",\"ID\":\"172.17.102.204_4\",\"result\":false,\"SqlData\":[{\"type\":\"real\",\"desc\":\"FREQ\",\"list\":{\"A\":null,\"B\":null,\"C\":null,\"T\":\"50.001000\"}}],\"SqlDataHarm\":[]}");
MsgUtil.socketDataMsg("{\"Time\":\"2025-01-15T15:50:27\",\"ID\":\"172.17.102.204_1\",\"result\":false,\"SqlData\":[{\"type\":\"real\",\"desc\":\"FREQ\",\"list\":{\"A\":null,\"B\":null,\"C\":null,\"T\":\"50.001000\"}}],\"SqlDataHarm\":[]}");
MsgUtil.socketDataMsg("{\"Time\":\"2025-01-15T15:50:27\",\"ID\":\"172.17.102.204_2\",\"result\":false,\"SqlData\":[{\"type\":\"real\",\"desc\":\"FREQ\",\"list\":{\"A\":null,\"B\":null,\"C\":null,\"T\":\"50.001000\"}}],\"SqlDataHarm\":[]}");
MsgUtil.socketDataMsg("{\"Time\":\"2025-01-15T15:50:27\",\"ID\":\"172.17.102.204_3\",\"result\":false,\"SqlData\":[{\"type\":\"real\",\"desc\":\"FREQ\",\"list\":{\"A\":null,\"B\":null,\"C\":null,\"T\":\"50.001000\"}}],\"SqlDataHarm\":[]}");
MsgUtil.socketDataMsg("{\"Time\":\"2025-01-15T15:50:27\",\"ID\":\"172.17.102.204_4\",\"result\":false,\"SqlData\":[{\"type\":\"real\",\"desc\":\"FREQ\",\"list\":{\"A\":null,\"B\":null,\"C\":null,\"T\":\"50.001000\"}}],\"SqlDataHarm\":[]}");
MsgUtil.socketDataMsg("{\"Time\":\"2025-01-15T15:50:30\",\"ID\":\"172.17.102.204_1\",\"result\":false,\"SqlData\":[{\"type\":\"real\",\"desc\":\"FREQ\",\"list\":{\"A\":null,\"B\":null,\"C\":null,\"T\":\"50.001000\"}}],\"SqlDataHarm\":[]}");
MsgUtil.socketDataMsg("{\"Time\":\"2025-01-15T15:50:30\",\"ID\":\"172.17.102.204_2\",\"result\":false,\"SqlData\":[{\"type\":\"real\",\"desc\":\"FREQ\",\"list\":{\"A\":null,\"B\":null,\"C\":null,\"T\":\"50.001000\"}}],\"SqlDataHarm\":[]}");
MsgUtil.socketDataMsg("{\"Time\":\"2025-01-15T15:50:30\",\"ID\":\"172.17.102.204_3\",\"result\":false,\"SqlData\":[{\"type\":\"real\",\"desc\":\"FREQ\",\"list\":{\"A\":null,\"B\":null,\"C\":null,\"T\":\"50.001000\"}}],\"SqlDataHarm\":[]}");
MsgUtil.socketDataMsg("{\"Time\":\"2025-01-15T15:50:30\",\"ID\":\"172.17.102.204_4\",\"result\":false,\"SqlData\":[{\"type\":\"real\",\"desc\":\"FREQ\",\"list\":{\"A\":null,\"B\":null,\"C\":null,\"T\":\"50.001000\"}}],\"SqlDataHarm\":[]}");
MsgUtil.socketDataMsg("{\"Time\":\"2025-01-15T15:50:33\",\"ID\":\"172.17.102.204_1\",\"result\":false,\"SqlData\":[{\"type\":\"real\",\"desc\":\"FREQ\",\"list\":{\"A\":null,\"B\":null,\"C\":null,\"T\":\"50.001000\"}}],\"SqlDataHarm\":[]}");
MsgUtil.socketDataMsg("{\"Time\":\"2025-01-15T15:50:33\",\"ID\":\"172.17.102.204_2\",\"result\":false,\"SqlData\":[{\"type\":\"real\",\"desc\":\"FREQ\",\"list\":{\"A\":null,\"B\":null,\"C\":null,\"T\":\"50.001000\"}}],\"SqlDataHarm\":[]}");
MsgUtil.socketDataMsg("{\"Time\":\"2025-01-15T15:50:33\",\"ID\":\"172.17.102.204_3\",\"result\":false,\"SqlData\":[{\"type\":\"real\",\"desc\":\"FREQ\",\"list\":{\"A\":null,\"B\":null,\"C\":null,\"T\":\"50.001000\"}}],\"SqlDataHarm\":[]}");
MsgUtil.socketDataMsg("{\"Time\":\"2025-01-15T15:50:33\",\"ID\":\"172.17.102.204_4\",\"result\":false,\"SqlData\":[{\"type\":\"real\",\"desc\":\"FREQ\",\"list\":{\"A\":null,\"B\":null,\"C\":null,\"T\":\"50.001000\"}}],\"SqlDataHarm\":[]}");
MsgUtil.socketDataMsg("{\"Time\":\"2025-01-15T15:50:36\",\"ID\":\"172.17.102.204_1\",\"result\":false,\"SqlData\":[{\"type\":\"real\",\"desc\":\"FREQ\",\"list\":{\"A\":null,\"B\":null,\"C\":null,\"T\":\"50.001000\"}}],\"SqlDataHarm\":[]}");
MsgUtil.socketDataMsg("{\"Time\":\"2025-01-15T15:50:36\",\"ID\":\"172.17.102.204_2\",\"result\":false,\"SqlData\":[{\"type\":\"real\",\"desc\":\"FREQ\",\"list\":{\"A\":null,\"B\":null,\"C\":null,\"T\":\"50.001000\"}}],\"SqlDataHarm\":[]}");
MsgUtil.socketDataMsg("{\"Time\":\"2025-01-15T15:50:36\",\"ID\":\"172.17.102.204_3\",\"result\":false,\"SqlData\":[{\"type\":\"real\",\"desc\":\"FREQ\",\"list\":{\"A\":null,\"B\":null,\"C\":null,\"T\":\"50.001000\"}}],\"SqlDataHarm\":[]}");
MsgUtil.socketDataMsg("{\"Time\":\"2025-01-15T15:50:36\",\"ID\":\"172.17.102.204_4\",\"result\":false,\"SqlData\":[{\"type\":\"real\",\"desc\":\"FREQ\",\"list\":{\"A\":null,\"B\":null,\"C\":null,\"T\":\"50.001000\"}}],\"SqlDataHarm\":[]}");
MsgUtil.socketDataMsg("{\"Time\":\"2025-01-15T15:50:39\",\"ID\":\"172.17.102.204_1\",\"result\":false,\"SqlData\":[{\"type\":\"real\",\"desc\":\"FREQ\",\"list\":{\"A\":null,\"B\":null,\"C\":null,\"T\":\"50.001000\"}}],\"SqlDataHarm\":[]}");
MsgUtil.socketDataMsg("{\"Time\":\"2025-01-15T15:50:39\",\"ID\":\"172.17.102.204_2\",\"result\":false,\"SqlData\":[{\"type\":\"real\",\"desc\":\"FREQ\",\"list\":{\"A\":null,\"B\":null,\"C\":null,\"T\":\"50.001000\"}}],\"SqlDataHarm\":[]}");
MsgUtil.socketDataMsg("{\"Time\":\"2025-01-15T15:50:39\",\"ID\":\"172.17.102.204_3\",\"result\":false,\"SqlData\":[{\"type\":\"real\",\"desc\":\"FREQ\",\"list\":{\"A\":null,\"B\":null,\"C\":null,\"T\":\"50.001000\"}}],\"SqlDataHarm\":[]}");
MsgUtil.socketDataMsg("{\"Time\":\"2025-01-15T15:50:39\",\"ID\":\"172.17.102.204_4\",\"result\":false,\"SqlData\":[{\"type\":\"real\",\"desc\":\"FREQ\",\"list\":{\"A\":null,\"B\":null,\"C\":null,\"T\":\"50.001000\"}}],\"SqlDataHarm\":[]}");
MsgUtil.socketDataMsg("{\"Time\":\"2025-01-15T15:50:42.001\",\"ID\":\"172.17.102.204_1\",\"result\":false,\"SqlData\":[{\"type\":\"real\",\"desc\":\"FREQ\",\"list\":{\"A\":null,\"B\":null,\"C\":null,\"T\":\"50.001000\"}}],\"SqlDataHarm\":[]}");
MsgUtil.socketDataMsg("{\"Time\":\"2025-01-15T15:50:42.001\",\"ID\":\"172.17.102.204_2\",\"result\":false,\"SqlData\":[{\"type\":\"real\",\"desc\":\"FREQ\",\"list\":{\"A\":null,\"B\":null,\"C\":null,\"T\":\"50.001000\"}}],\"SqlDataHarm\":[]}");
MsgUtil.socketDataMsg("{\"Time\":\"2025-01-15T15:50:42.001\",\"ID\":\"172.17.102.204_3\",\"result\":false,\"SqlData\":[{\"type\":\"real\",\"desc\":\"FREQ\",\"list\":{\"A\":null,\"B\":null,\"C\":null,\"T\":\"50.001000\"}}],\"SqlDataHarm\":[]}");
MsgUtil.socketDataMsg("{\"Time\":\"2025-01-15T15:50:42.001\",\"ID\":\"172.17.102.204_4\",\"result\":false,\"SqlData\":[{\"type\":\"real\",\"desc\":\"FREQ\",\"list\":{\"A\":null,\"B\":null,\"C\":null,\"T\":\"50.001000\"}}],\"SqlDataHarm\":[]}");
MsgUtil.socketDataMsg("{\"Time\":\"2025-01-15T15:50:45.001\",\"ID\":\"172.17.102.204_1\",\"result\":false,\"SqlData\":[{\"type\":\"real\",\"desc\":\"FREQ\",\"list\":{\"A\":null,\"B\":null,\"C\":null,\"T\":\"50.001000\"}}],\"SqlDataHarm\":[]}");
MsgUtil.socketDataMsg("{\"Time\":\"2025-01-15T15:50:45.001\",\"ID\":\"172.17.102.204_2\",\"result\":false,\"SqlData\":[{\"type\":\"real\",\"desc\":\"FREQ\",\"list\":{\"A\":null,\"B\":null,\"C\":null,\"T\":\"50.001000\"}}],\"SqlDataHarm\":[]}");
MsgUtil.socketDataMsg("{\"Time\":\"2025-01-15T15:50:45.001\",\"ID\":\"172.17.102.204_3\",\"result\":false,\"SqlData\":[{\"type\":\"real\",\"desc\":\"FREQ\",\"list\":{\"A\":null,\"B\":null,\"C\":null,\"T\":\"50.001000\"}}],\"SqlDataHarm\":[]}");
MsgUtil.socketDataMsg("{\"Time\":\"2025-01-15T15:50:45.001\",\"ID\":\"172.17.102.204_4\",\"result\":false,\"SqlData\":[{\"type\":\"real\",\"desc\":\"FREQ\",\"list\":{\"A\":null,\"B\":null,\"C\":null,\"T\":\"50.001100\"}}],\"SqlDataHarm\":[]}");
PqScriptIssueParam issueParam = new PqScriptIssueParam();
issueParam.setPlanId(param.getPlanId());
issueParam.setSourceId(param.getSourceId());
issueParam.setDevIds(param.getDevIds());
issueParam.setScriptId("a303b2224845fcc6f60198b8ca23dca9");
//issueParam.setIsPhaseSequence(false);
SourceIssue sourceIssues = pqScriptDtlsService.listSourceIssue(issueParam).get(0);
List<PreDetection> pqDevList = iPqDevService.getDevInfo(param.getDevIds());
Map<String, String> devIdMapComm = pqDevList.stream().collect(Collectors.toMap(PreDetection::getDevIP, PreDetection::getDevId));
//detectionServiceImpl.processing(devDataList,param,devIdMapComm,sourceIssues, DictDataEnum.AT_WILL_VALUE);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
}
}

View File

@@ -29,12 +29,13 @@ import com.njcn.gather.storage.pojo.po.AdHarmonicResult;
import com.njcn.gather.storage.pojo.po.AdNonHarmonicResult;
import com.njcn.gather.storage.service.AdHarmonicService;
import com.njcn.gather.storage.service.DetectionDataDealService;
import com.njcn.gather.system.config.pojo.po.SysTestConfig;
import com.njcn.gather.system.config.service.ISysTestConfigService;
import com.njcn.gather.system.cfg.pojo.po.SysTestConfig;
import com.njcn.gather.system.cfg.service.ISysTestConfigService;
import com.njcn.gather.system.dictionary.pojo.enums.DictDataEnum;
import com.njcn.gather.system.pojo.enums.DicDataEnum;
import com.njcn.gather.system.reg.service.ISysRegResService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import java.lang.reflect.Field;
@@ -81,7 +82,8 @@ public class SocketDevResponseService {
private final ISysTestConfigService sysTestConfigService;
private final AdHarmonicService adHarmonicService;
private final IAdPlanService adPlanService;
@Value("${phaseAngle.isEnable}")
private Boolean isPhaseAngle;
// private final ExecutorService executorPool = Executors.newFixedThreadPool(10);
@@ -91,7 +93,7 @@ public class SocketDevResponseService {
*/
List<DevData> devInfo = new ArrayList<>();
Map<String, DevData> devDataMap = new HashMap<>();
//Map<String, DevData> devDataMap = new HashMap<>();
/**
* 成功结束的测点
@@ -142,13 +144,12 @@ public class SocketDevResponseService {
case QUITE:
quitDeal(socketDataMsg, param, msg);
break;
case YXT:
break;
}
}
//用于存储所有测点的试试数据
private final List<DevData> realDataXiList = new ArrayList<>();
/**
* 系数校验
*/
@@ -161,6 +162,39 @@ public class SocketDevResponseService {
switch (Objects.requireNonNull(sourceOperateCodeEnum)) {
case DATA_CHNFACTOR$01:
//获取系数
switch (Objects.requireNonNull(dictDataEnumByCode)) {
case SUCCESS:
if (CollUtil.isNotEmpty(XiNumberManager.xiDevList)) {
List<DevXiNumData.GF> gfList = JSON.parseArray(socketDataMsg.getData(), DevXiNumData.GF.class);
DevXiNumData devXiNumData = new DevXiNumData();
devXiNumData.setDevIP(XiNumberManager.xiDevList.get(0).getDevIP());
devXiNumData.setGf(gfList);
XiNumberManager.devXiNumDataMap.put(XiNumberManager.xiDevList.get(0).getDevIP(), devXiNumData);
XiNumberManager.xiDevList.remove(0);
if (CollUtil.isEmpty(XiNumberManager.xiDevList)) {
xiSocket.setRequestId(SourceOperateCodeEnum.Coefficient_Check.getValue());
xiSocket.setOperateCode(SourceOperateCodeEnum.OPER_GATHER.getValue());
xiSocket.setData(JSON.toJSONString(XiNumberManager.xiSourceIssueList.get(0)));
SocketManager.sendMsg(param.getUserPageId() + handlerSourceStr, JSON.toJSONString(xiSocket));
}
}
break;
case UNPROCESSED_BUSINESS:
break;
case NORMAL_RESPONSE:
break;
case DATA_RESOLVE:
break;
case COMMUNICATION_ERR:
break;
default:
break;
}
break;
case DATA_CHNFACTOR$02:
@@ -183,7 +217,6 @@ public class SocketDevResponseService {
//为空则认为所有装置都已经下发,开始进行小电压的申请,步骤进行+1
XiNumberManager.stepNumber = 1;
sendWebSocket(param.getUserPageId(), SourceOperateCodeEnum.Coefficient_Check.getValue(), SourceOperateCodeEnum.big_end.getValue(), XiNumberManager.devParameterList.get(0));
sendWebSocket(param.getUserPageId(), SourceOperateCodeEnum.Coefficient_Check.getValue(), SourceOperateCodeEnum.small_start.getValue(), XiNumberManager.devParameterList.get(1));
System.out.println("第一步结束开始配置小电压电流参数下发给源----------------------");
@@ -200,7 +233,7 @@ public class SocketDevResponseService {
SocketManager.sendMsg(param.getUserPageId() + handlerSourceStr, JSON.toJSONString(xiSocket));
XiNumberManager.stepNumber = 2;
}
realDataXiList.clear();
FormalTestManager.realDataXiList.clear();
successComm.clear();
XiNumberManager.devXiList.clear();
}
@@ -222,7 +255,7 @@ public class SocketDevResponseService {
case COMMUNICATION_ERR:
break;
default:
break;
}
break;
case DEV_DATA_REQUEST_02:
@@ -232,195 +265,19 @@ public class SocketDevResponseService {
if (ObjectUtil.isNotNull(dictDataEnumByCode)) {
switch (dictDataEnumByCode) {
case SUCCESS:
realDataXiList.add(devData);
FormalTestManager.realDataXiList.add(devData);
successComm.add(devData.getId());
System.out.println(successComm.size() + " ==" + FormalTestManager.monitorIdListComm.size() + "realDataXiList:" + realDataXiList.size() + "当前步骤" + XiNumberManager.stepNumber);
System.out.println(successComm.size() + " ==" + FormalTestManager.monitorIdListComm.size() + "FormalTestManager.realDataXiList:" + FormalTestManager.realDataXiList.size() + "当前步骤" + XiNumberManager.stepNumber);
if (successComm.size() == FormalTestManager.monitorIdListComm.size()) {
System.out.println("从装置中已经完成获取原始数据,准备开始计算----------------------");
//获取数据流程结束,先把所有数据存到内存中
Map<String, List<DevData>> realDataXiMap = realDataXiList.stream().collect(Collectors.groupingBy(it -> it.getId().split(splitTag)[0]));
realDataXiMap.forEach((devIp, dataList) -> {
AtomicBoolean xiFlag = new AtomicBoolean(true);
XiNumberManager.devXiList.add(devIp);
Map<String, List<DevData>> monitorMap = dataList.stream().collect(Collectors.groupingBy(DevData::getId));
List<DevXiNumData.GF> gf = new ArrayList<>();
monitorMap.forEach((monitorId, list) -> {
DevXiNumData.F F = new DevXiNumData.F();
CoefficientVO.DevParameter devParameter;
CoefficientVO coefficientVO = new CoefficientVO();
if (XiNumberManager.stepNumber == 0 || XiNumberManager.stepNumber == 2) {
devParameter = XiNumberManager.devParameterList.get(0);
coefficientVO.setType("big");
} else {
devParameter = XiNumberManager.devParameterList.get(1);
coefficientVO.setType("small");
}
String[] splitStr = monitorId.split(splitTag);
coefficientVO.setMonitorNum(splitStr[1]);
coefficientVO.setDevName(FormalTestManager.devNameMapComm.get(splitStr[0]));
coefficientVO.setDesc((XiNumberManager.stepNumber == 0 || XiNumberManager.stepNumber == 1) ? "系数下装" : "系数校准");
assemblyEntity(list, F, coefficientVO, devParameter);
if (Objects.nonNull(coefficientVO.getResultFlag()) && coefficientVO.getResultFlag() == 0) {
xiFlag.set(false);
}
DevXiNumData.GF gfItem = new DevXiNumData.GF();
gfItem.setUMonitorPoint(Integer.parseInt(splitStr[1]) - 1);
gfItem.setF(F);
gf.add(gfItem);
//表格数据
WebSocketVO<Object> webSocketVO = new WebSocketVO<>();
webSocketVO.setRequestId(SourceOperateCodeEnum.Coefficient_Check.getValue());
webSocketVO.setOperateCode(SourceOperateCodeEnum.DATA_CHNFACTOR$02.getValue());
webSocketVO.setData(coefficientVO);
WebServiceManager.sendMessage(param.getUserPageId(), webSocketVO);
});
DevXiNumData devXiNumData = new DevXiNumData();
devXiNumData.setChnNum(0);
devXiNumData.setDevIP(devIp);
devXiNumData.setGf(gf);
if (xiFlag.get()) {
devXiNumData.setResultFlag(1);
} else {
devXiNumData.setResultFlag(0);
}
if (XiNumberManager.stepNumber == 0 || XiNumberManager.stepNumber == 2) {
XiNumberManager.devXiNumDataMap.put(devIp, devXiNumData);
} else if (XiNumberManager.stepNumber == 1 || XiNumberManager.stepNumber == 3) {
XiNumberManager.smallDevXiNumDataMap.put(devIp, devXiNumData);
}
});
if (XiNumberManager.stepNumber == 0) {
//开始发送修改系数命令
xiSocket.setRequestId(SourceOperateCodeEnum.Coefficient_Check.getValue());
xiSocket.setOperateCode(SourceOperateCodeEnum.DATA_CHNFACTOR$02.getValue());
xiSocket.setData(JSON.toJSONString(XiNumberManager.devXiNumDataMap.get(XiNumberManager.devXiList.get(0))));
SocketManager.sendMsg(param.getUserPageId() + handlerStr, JSON.toJSONString(xiSocket));
} else if (XiNumberManager.stepNumber == 1) {
System.out.println("进入小电压步骤》》》》》》》》》》》》》》》》》》》》》》》》");
//判断小电压是否系数超过大电压10%
double limit = 0.1;
XiNumberManager.smallDevXiNumDataMap.forEach((devIp, devXiNumDataSmall) -> {
//定义一个标识: false:表示小电流系数和大电流系数
boolean flag = true;
DevXiNumData devXiNumDataBig = XiNumberManager.devXiNumDataMap.get(devIp);
Map<Integer, DevXiNumData.GF> gfMapSmall = devXiNumDataSmall.getGf().stream().collect(Collectors.toMap(DevXiNumData.GF::getUMonitorPoint, Function.identity()));
for (DevXiNumData.GF bigGf : devXiNumDataBig.getGf()) {
DevXiNumData.F smallF = gfMapSmall.get(bigGf.getUMonitorPoint()).getF();
DevXiNumData.F bigF = bigGf.getF();
boolean ia = isWithinTenPercent(smallF.getIa_gain(), bigF.getIa_gain(), limit);
boolean ib = isWithinTenPercent(smallF.getIb_gain(), bigF.getIb_gain(), limit);
boolean ic = isWithinTenPercent(smallF.getIc_gain(), bigF.getIc_gain(), limit);
boolean va = isWithinTenPercent(smallF.getUa_gain(), bigF.getUa_gain(), limit);
boolean vb = isWithinTenPercent(smallF.getUb_gain(), bigF.getUb_gain(), limit);
boolean vc = isWithinTenPercent(smallF.getUc_gain(), bigF.getUc_gain(), limit);
if (ia && ib && ic && va && vb && vc) {
} else {
flag = false;
//继续下发一轮
if (!ia) {
Integer newIa = (smallF.getIa_gain() + bigF.getIa_gain()) / 2;
bigF.setIa_gain(newIa);
}
if (!ib) {
Integer newIb = (smallF.getIb_gain() + bigF.getIb_gain()) / 2;
bigF.setIb_gain(newIb);
}
if (!ic) {
Integer newIc = (smallF.getIc_gain() + bigF.getIc_gain()) / 2;
bigF.setIc_gain(newIc);
}
if (!va) {
Integer newVa = (smallF.getUa_gain() + bigF.getUa_gain()) / 2;
bigF.setUa_gain(newVa);
}
if (!vb) {
Integer newUb = (smallF.getUb_gain() + bigF.getUb_gain()) / 2;
bigF.setUb_gain(newUb);
}
if (!vc) {
Integer newUc = (smallF.getUc_gain() + bigF.getUc_gain()) / 2;
bigF.setUc_gain(newUc);
}
}
}
if (flag) {
//如果系数没问题则不需要
XiNumberManager.devXiList.removeIf(it -> it.equals(devIp));
}
});
//如果差距超过10%则再次下发系数
if (CollUtil.isNotEmpty(XiNumberManager.devXiList)) {
xiSocket.setOperateCode(SourceOperateCodeEnum.DATA_CHNFACTOR$02.getValue());
xiSocket.setData(JSON.toJSONString(XiNumberManager.devXiNumDataMap.get(XiNumberManager.devXiList.get(0))));
SocketManager.sendMsg(param.getUserPageId() + handlerStr, JSON.toJSONString(xiSocket));
} else {
//存在小电压系数在误差范围内情况,直接结束。
sendWebSocket(param.getUserPageId(), SourceOperateCodeEnum.Coefficient_Check.getValue(), SourceOperateCodeEnum.small_end.getValue(), XiNumberManager.devParameterList.get(1));
sendWebSocket(param.getUserPageId(), SourceOperateCodeEnum.Coefficient_Check.getValue(), SourceOperateCodeEnum.big_comp_start.getValue(), XiNumberManager.devParameterList.get(0));
//小电流系数下发完毕;开始重新测试一次大电压
xiSocket.setOperateCode(SourceOperateCodeEnum.OPER_GATHER.getValue());
xiSocket.setData(JSON.toJSONString(XiNumberManager.xiSourceIssueList.get(0)));
SocketManager.sendMsg(param.getUserPageId() + handlerSourceStr, JSON.toJSONString(xiSocket));
XiNumberManager.stepNumber = 2;
realDataXiList.clear();
successComm.clear();
}
} else if (XiNumberManager.stepNumber == 2) {
//大电压处理
sendWebSocket(param.getUserPageId(), SourceOperateCodeEnum.Coefficient_Check.getValue(), SourceOperateCodeEnum.big_comp_end.getValue(), XiNumberManager.devParameterList.get(0));
sendWebSocket(param.getUserPageId(), SourceOperateCodeEnum.Coefficient_Check.getValue(), SourceOperateCodeEnum.small_comp_start.getValue(), XiNumberManager.devParameterList.get(1));
xiSocket.setOperateCode(SourceOperateCodeEnum.OPER_GATHER.getValue());
xiSocket.setData(JSON.toJSONString(XiNumberManager.xiSourceIssueList.get(1)));
SocketManager.sendMsg(param.getUserPageId() + handlerSourceStr, JSON.toJSONString(xiSocket));
XiNumberManager.stepNumber = 3;
realDataXiList.clear();
successComm.clear();
} else if (XiNumberManager.stepNumber == 3) {
sendWebSocket(param.getUserPageId(), SourceOperateCodeEnum.Coefficient_Check.getValue(), SourceOperateCodeEnum.small_comp_end.getValue(), XiNumberManager.devParameterList.get(1));
System.out.println("-------------------------已经全部结束----------------------");
CnSocketUtil.quitSend(param);
//修改设备表Factor_Check_Result字段
XiNumberManager.devXiNumDataMap.forEach((key, val) -> {
DevXiNumData small = XiNumberManager.smallDevXiNumDataMap.get(key);
LambdaUpdateWrapper<PqDev> updateWrapper = new LambdaUpdateWrapper<>();
updateWrapper.eq(PqDev::getId, FormalTestManager.devIdMapComm.get(key));
if (val.getResultFlag() == 0 || small.getResultFlag() == 0) {
updateWrapper.set(PqDev::getFactorCheckResult, 0);
} else {
updateWrapper.set(PqDev::getFactorCheckResult, 1);
}
iPqDevService.update(updateWrapper);
updateWrapper.clear();
});
}
processData(param, xiSocket);
}
break;
case UNPROCESSED_BUSINESS:
WebServiceManager.sendMsg(param.getUserPageId(), JSON.toJSONString(socketDataMsg));
break;
case NORMAL_RESPONSE:
realDataXiList.add(devData);
FormalTestManager.realDataXiList.add(devData);
break;
default:
xiSocket.setRequestId(socketDataMsg.getRequestId());
@@ -440,9 +297,223 @@ public class SocketDevResponseService {
}
private void processData(PreDetectionParam param, SocketMsg<String> xiSocket) {
System.out.println(XiNumberManager.stepNumber + "从装置中已经完成获取测试数据,准备开始计算----------------------");
Map<String, List<DevData>> realDataXiMap = FormalTestManager.realDataXiList.stream().collect(Collectors.groupingBy(it -> it.getId().split(splitTag)[0]));
realDataXiMap.forEach((devIp, dataList) -> processDeviceData(devIp, dataList, param));
handleStep(XiNumberManager.stepNumber, param, xiSocket);
}
private void handleStep(int stepNumber, PreDetectionParam param, SocketMsg<String> xiSocket) {
switch (stepNumber) {
case 0:
sendModifyCoefficientCommand(param, xiSocket);
break;
case 1:
handleSmallVoltageStep(param, xiSocket);
break;
case 2:
handleBigVoltageStep(param, xiSocket);
break;
case 3:
handleFinalStep(param);
break;
}
}
/**
* 系数校验
* 修改系数命令下发
*/
private void sendModifyCoefficientCommand(PreDetectionParam param, SocketMsg<String> xiSocket) {
xiSocket.setRequestId(SourceOperateCodeEnum.Coefficient_Check.getValue());
xiSocket.setOperateCode(SourceOperateCodeEnum.DATA_CHNFACTOR$02.getValue());
xiSocket.setData(JSON.toJSONString(XiNumberManager.devXiNumDataMap.get(XiNumberManager.devXiList.get(0))));
SocketManager.sendMsg(param.getUserPageId() + handlerStr, JSON.toJSONString(xiSocket));
}
private void handleSmallVoltageStep(PreDetectionParam param, SocketMsg<String> xiSocket) {
System.out.println("进入小电压步骤》》》》》》》》》》》》》》》》》》》》》》》》");
double limit = 0.1;
XiNumberManager.smallDevXiNumDataMap.forEach((devIp, devXiNumDataSmall) -> {
boolean flag = checkCoefficientDifference(devIp, devXiNumDataSmall, limit);
if (flag) {
XiNumberManager.devXiList.removeIf(it -> it.equals(devIp));
}
});
//如果差距超过10%则再次下发系数
if (CollUtil.isNotEmpty(XiNumberManager.devXiList)) {
xiSocket.setOperateCode(SourceOperateCodeEnum.DATA_CHNFACTOR$02.getValue());
xiSocket.setData(JSON.toJSONString(XiNumberManager.devXiNumDataMap.get(XiNumberManager.devXiList.get(0))));
SocketManager.sendMsg(param.getUserPageId() + handlerStr, JSON.toJSONString(xiSocket));
} else {
//存在小电压系数在误差范围内情况,直接结束。
sendWebSocket(param.getUserPageId(), SourceOperateCodeEnum.Coefficient_Check.getValue(), SourceOperateCodeEnum.small_end.getValue(), XiNumberManager.devParameterList.get(1));
sendWebSocket(param.getUserPageId(), SourceOperateCodeEnum.Coefficient_Check.getValue(), SourceOperateCodeEnum.big_comp_start.getValue(), XiNumberManager.devParameterList.get(0));
//小电流系数下发完毕;开始重新测试一次大电压
xiSocket.setOperateCode(SourceOperateCodeEnum.OPER_GATHER.getValue());
xiSocket.setData(JSON.toJSONString(XiNumberManager.xiSourceIssueList.get(0)));
SocketManager.sendMsg(param.getUserPageId() + handlerSourceStr, JSON.toJSONString(xiSocket));
XiNumberManager.stepNumber = 2;
FormalTestManager.realDataXiList.clear();
successComm.clear();
}
}
private void handleBigVoltageStep(PreDetectionParam param, SocketMsg<String> xiSocket) {
//大电压处理
sendWebSocket(param.getUserPageId(), SourceOperateCodeEnum.Coefficient_Check.getValue(), SourceOperateCodeEnum.big_comp_end.getValue(), XiNumberManager.devParameterList.get(0));
sendWebSocket(param.getUserPageId(), SourceOperateCodeEnum.Coefficient_Check.getValue(), SourceOperateCodeEnum.small_comp_start.getValue(), XiNumberManager.devParameterList.get(1));
xiSocket.setOperateCode(SourceOperateCodeEnum.OPER_GATHER.getValue());
xiSocket.setData(JSON.toJSONString(XiNumberManager.xiSourceIssueList.get(1)));
SocketManager.sendMsg(param.getUserPageId() + handlerSourceStr, JSON.toJSONString(xiSocket));
XiNumberManager.stepNumber = 3;
FormalTestManager.realDataXiList.clear();
successComm.clear();
}
private void handleFinalStep(PreDetectionParam param) {
sendWebSocket(param.getUserPageId(), SourceOperateCodeEnum.Coefficient_Check.getValue(), SourceOperateCodeEnum.small_comp_end.getValue(), XiNumberManager.devParameterList.get(1));
System.out.println("-------------------------已经全部结束----------------------");
CnSocketUtil.quitSend(param);
//修改设备表Factor_Check_Result字段
XiNumberManager.devXiNumDataMap.forEach((key, val) -> {
DevXiNumData small = XiNumberManager.smallDevXiNumDataMap.get(key);
LambdaUpdateWrapper<PqDev> updateWrapper = new LambdaUpdateWrapper<>();
updateWrapper.eq(PqDev::getId, FormalTestManager.devIdMapComm.get(key));
if (val.getResultFlag() == 0 || small.getResultFlag() == 0) {
updateWrapper.set(PqDev::getFactorCheckResult, 0);
} else {
updateWrapper.set(PqDev::getFactorCheckResult, 1);
}
iPqDevService.update(updateWrapper);
updateWrapper.clear();
});
}
private boolean checkCoefficientDifference(String devIp, DevXiNumData devXiNumDataSmall, double limit) {
boolean flag = true;
DevXiNumData devXiNumDataBig = XiNumberManager.devXiNumDataMap.get(devIp);
Map<Integer, DevXiNumData.GF> gfMapSmall = devXiNumDataSmall.getGf().stream().collect(Collectors.toMap(DevXiNumData.GF::getUMonitorPoint, Function.identity()));
for (DevXiNumData.GF bigGf : devXiNumDataBig.getGf()) {
DevXiNumData.F smallF = gfMapSmall.get(bigGf.getUMonitorPoint()).getF();
DevXiNumData.F bigF = bigGf.getF();
boolean ia = isWithinTenPercent(smallF.getIa_gain(), bigF.getIa_gain(), limit);
boolean ib = isWithinTenPercent(smallF.getIb_gain(), bigF.getIb_gain(), limit);
boolean ic = isWithinTenPercent(smallF.getIc_gain(), bigF.getIc_gain(), limit);
boolean va = isWithinTenPercent(smallF.getUa_gain(), bigF.getUa_gain(), limit);
boolean vb = isWithinTenPercent(smallF.getUb_gain(), bigF.getUb_gain(), limit);
boolean vc = isWithinTenPercent(smallF.getUc_gain(), bigF.getUc_gain(), limit);
if (!(ia && ib && ic && va && vb && vc)) {
flag = false;
adjustCoefficients(smallF, bigF);
}
}
return flag;
}
/**
* 当小电压系数和大电压系数的差距超过 10% 时,对大电压系数进行调整,调整的方式是取小电压系数和大电压系数的平均值。
*/
private void adjustCoefficients(DevXiNumData.F smallF, DevXiNumData.F bigF) {
if (!isWithinTenPercent(smallF.getIa_gain(), bigF.getIa_gain(), 0.1)) {
bigF.setIa_gain((smallF.getIa_gain() + bigF.getIa_gain()) / 2);
}
if (!isWithinTenPercent(smallF.getIb_gain(), bigF.getIb_gain(), 0.1)) {
bigF.setIb_gain((smallF.getIb_gain() + bigF.getIb_gain()) / 2);
}
if (!isWithinTenPercent(smallF.getIc_gain(), bigF.getIc_gain(), 0.1)) {
bigF.setIc_gain((smallF.getIc_gain() + bigF.getIc_gain()) / 2);
}
if (!isWithinTenPercent(smallF.getUa_gain(), bigF.getUa_gain(), 0.1)) {
bigF.setUa_gain((smallF.getUa_gain() + bigF.getUa_gain()) / 2);
}
if (!isWithinTenPercent(smallF.getUb_gain(), bigF.getUb_gain(), 0.1)) {
bigF.setUb_gain((smallF.getUb_gain() + bigF.getUb_gain()) / 2);
}
if (!isWithinTenPercent(smallF.getUc_gain(), bigF.getUc_gain(), 0.1)) {
bigF.setUc_gain((smallF.getUc_gain() + bigF.getUc_gain()) / 2);
}
}
private void processDeviceData(String devIp, List<DevData> dataList, PreDetectionParam param) {
AtomicBoolean xiFlag = new AtomicBoolean(true);
XiNumberManager.devXiList.add(devIp);
DevXiNumData startXiData = XiNumberManager.devXiNumDataMap.get(devIp);
Map<Integer, DevXiNumData.GF> gfMap = startXiData.getGf().stream().collect(Collectors.toMap(DevXiNumData.GF::getUMonitorPoint, Function.identity()));
Map<String, List<DevData>> monitorMap = dataList.stream().collect(Collectors.groupingBy(DevData::getId));
List<DevXiNumData.GF> gf = new ArrayList<>();
monitorMap.forEach((monitorId, list) -> {
CoefficientVO coefficientVO = createCoefficientVO(monitorId);
DevXiNumData.F F = new DevXiNumData.F();
CoefficientVO.DevParameter devParameter = getDevParameter();
assemblyEntity(list, F, gfMap.get(Integer.parseInt(monitorId.split(splitTag)[1]) - 1), coefficientVO, devParameter);
if (Objects.nonNull(coefficientVO.getResultFlag()) && coefficientVO.getResultFlag() == 0) {
xiFlag.set(false);
}
DevXiNumData.GF gfItem = createGFItem(monitorId, F);
gf.add(gfItem);
//表格数据
CnSocketUtil.sendToWebSocket(param.getUserPageId(), SourceOperateCodeEnum.Coefficient_Check.getValue(), SourceOperateCodeEnum.DATA_CHNFACTOR$02.getValue(), coefficientVO, null);
});
DevXiNumData devXiNumData = createDevXiNumData(devIp, gf, xiFlag.get());
saveDevXiNumData(devIp, devXiNumData);
}
private CoefficientVO createCoefficientVO(String monitorId) {
CoefficientVO coefficientVO = new CoefficientVO();
String[] splitStr = monitorId.split(splitTag);
if (XiNumberManager.stepNumber == 0 || XiNumberManager.stepNumber == 2) {
coefficientVO.setType("big");
} else {
coefficientVO.setType("small");
}
coefficientVO.setMonitorNum(splitStr[1]);
coefficientVO.setDevName(FormalTestManager.devNameMapComm.get(splitStr[0]));
coefficientVO.setDesc((XiNumberManager.stepNumber == 0 || XiNumberManager.stepNumber == 1) ? "系数下装" : "系数校准");
return coefficientVO;
}
private CoefficientVO.DevParameter getDevParameter() {
return (XiNumberManager.stepNumber == 0 || XiNumberManager.stepNumber == 2) ? XiNumberManager.devParameterList.get(0) : XiNumberManager.devParameterList.get(1);
}
private DevXiNumData.GF createGFItem(String monitorId, DevXiNumData.F F) {
DevXiNumData.GF gfItem = new DevXiNumData.GF();
gfItem.setUMonitorPoint(Integer.parseInt(monitorId.split(splitTag)[1]) - 1);
gfItem.setF(F);
return gfItem;
}
private DevXiNumData createDevXiNumData(String devIp, List<DevXiNumData.GF> gf, boolean xiFlag) {
DevXiNumData devXiNumData = new DevXiNumData();
devXiNumData.setChnNum(0);
devXiNumData.setDevIP(devIp);
devXiNumData.setGf(gf);
devXiNumData.setResultFlag(xiFlag ? 1 : 0);
return devXiNumData;
}
private void saveDevXiNumData(String devIp, DevXiNumData devXiNumData) {
if (XiNumberManager.stepNumber == 0 || XiNumberManager.stepNumber == 2) {
XiNumberManager.devXiNumDataMap.put(devIp, devXiNumData);
} else if (XiNumberManager.stepNumber == 1 || XiNumberManager.stepNumber == 3) {
XiNumberManager.smallDevXiNumDataMap.put(devIp, devXiNumData);
}
}
/**
@@ -466,7 +537,7 @@ public class SocketDevResponseService {
}
private void assemblyEntity(List<DevData> deList, DevXiNumData.F F, CoefficientVO coefficientVO, CoefficientVO.DevParameter devParameter) {
private void assemblyEntity(List<DevData> deList, DevXiNumData.F F, DevXiNumData.GF startF, CoefficientVO coefficientVO, CoefficientVO.DevParameter devParameter) {
//表示接收完成,必须保证10个数
if (deList.size() >= 10) {
@@ -494,12 +565,12 @@ public class SocketDevResponseService {
coefficientVO.setCIeData(String.valueOf(optionalIC));
if (XiNumberManager.stepNumber == 0 || XiNumberManager.stepNumber == 1) {
Integer aXi = (int) ((2 - (optionalA / devParameter.getDevVolt())) * 10000);
Integer bXi = (int) ((2 - (optionalB / devParameter.getDevVolt())) * 10000);
Integer cXi = (int) ((2 - (optionalC / devParameter.getDevVolt())) * 10000);
Integer aIXi = (int) ((2 - (optionalIA / devParameter.getDevCurr())) * 10000);
Integer bIXi = (int) ((2 - (optionalIB / devParameter.getDevCurr())) * 10000);
Integer cIXi = (int) ((2 - (optionalIC / devParameter.getDevCurr())) * 10000);
Integer aXi = BigDecimal.valueOf(devParameter.getDevVolt() * startF.getF().getUa_gain() / optionalA).setScale(0, RoundingMode.HALF_UP).intValue();
Integer bXi = BigDecimal.valueOf(devParameter.getDevVolt() * startF.getF().getUb_gain() / optionalB).setScale(0, RoundingMode.HALF_UP).intValue();
Integer cXi = BigDecimal.valueOf(devParameter.getDevVolt() * startF.getF().getUc_gain() / optionalC).setScale(0, RoundingMode.HALF_UP).intValue();
Integer aIXi = BigDecimal.valueOf(devParameter.getDevCurr() * startF.getF().getIa_gain() / optionalIA).setScale(0, RoundingMode.HALF_UP).intValue();
Integer bIXi = BigDecimal.valueOf(devParameter.getDevCurr() * startF.getF().getIb_gain() / optionalIB).setScale(0, RoundingMode.HALF_UP).intValue();
Integer cIXi = BigDecimal.valueOf(devParameter.getDevCurr() * startF.getF().getIc_gain() / optionalIC).setScale(0, RoundingMode.HALF_UP).intValue();
coefficientVO.setAVuXi(aXi.toString());
coefficientVO.setBVuXi(bXi.toString());
@@ -515,7 +586,7 @@ public class SocketDevResponseService {
F.setIb_gain(bIXi);
F.setIc_gain(cIXi);
} else {
double vLimit = 0.1 * devParameter.getDevVolt() / 100;
double vLimit = 0.1 / 100 * devParameter.getDevVolt();
double iLimit = 0.005;
coefficientVO.setAVuXi(isWithinTenPercent(optionalA, devParameter.getDevVolt(), vLimit) ? "合格" : "不合格");
coefficientVO.setBVuXi(isWithinTenPercent(optionalB, devParameter.getDevVolt(), vLimit) ? "合格" : "不合格");
@@ -710,18 +781,20 @@ public class SocketDevResponseService {
if (param.getOperateType().equals(SourceOperateCodeEnum.RE_ERROR_TEST.getValue())) {
//不合格项复检
StorageParam storageParam = new StorageParam();
storageParam.setCode(Integer.valueOf(param.getPlanCode()));
storageParam.setCode(param.getCode());
storageParam.setScriptId(param.getScriptId());
List<Integer> indexes = adHarmonicService.getIndex(storageParam);
List<Integer> indexes = adHarmonicService.getIndex(storageParam, true);
issueParam.setIndexList(indexes);
issueParam.setIsPhaseSequence(SourceOperateCodeEnum.COEFFICIENT_TEST.getValue());
issueParam.setIsPhaseSequence(SourceOperateCodeEnum.RE_ERROR_TEST.getValue());
} else {
issueParam.setIsPhaseSequence(SourceOperateCodeEnum.FORMAL_TEST.getValue());
}
//正式检测
sourceIssues = pqScriptDtlsService.listSourceIssue(issueParam);
sourceIssues = sourceIssues.stream().sorted(Comparator.comparing(SourceIssue::getIndex)).collect(Collectors.toList());
// 存放所有检测小项
SocketManager.addSourceList(sourceIssues);
// 按照大项分组。key为大项codevalue为小项个数
Map<String, Long> sourceIssueMap = sourceIssues.stream().collect(Collectors.groupingBy(SourceIssue::getType, Collectors.counting()));
SocketManager.initMap(sourceIssueMap);
@@ -731,7 +804,7 @@ public class SocketDevResponseService {
//告诉前端当前项开始了
WebSocketVO<Object> webSocketVO = new WebSocketVO();
WebSocketVO<Object> webSocketVO = new WebSocketVO<>();
webSocketVO.setRequestId(sourceIssues.get(0).getType() + stepBegin);
webSocketVO.setDesc(null);
WebServiceManager.sendMsg(param.getUserPageId(), JSON.toJSONString(webSocketVO));
@@ -864,10 +937,16 @@ public class SocketDevResponseService {
webSocketVO.setData(XiNumberManager.devParameterList.get(0));
WebServiceManager.sendMsg(param.getUserPageId(), JSON.toJSONString(webSocketVO));
//下发命令获取所有装置通道系数,首先需要获取所有装置,通过所有装置下发获取系数命令,目前只支持单台装置获取系数
socketMsg.setRequestId(SourceOperateCodeEnum.Coefficient_Check.getValue());
socketMsg.setOperateCode(SourceOperateCodeEnum.OPER_GATHER.getValue());
socketMsg.setData(JSON.toJSONString(XiNumberManager.xiSourceIssueList.get(0)));
SocketManager.sendMsg(param.getUserPageId() + handlerSourceStr, JSON.toJSONString(socketMsg));
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(param.getUserPageId() + handlerStr, JSON.toJSONString(socketMsg));
XiNumberManager.stepNumber = 0;
XiNumberManager.devXiList.clear();
@@ -906,6 +985,7 @@ public class SocketDevResponseService {
}
// key为 检测大项对应的codevalue为当前大项的检测结果
Map<String, List<DevLineTestResult>> targetTestMap = new HashMap<>();
/**
@@ -913,13 +993,13 @@ public class SocketDevResponseService {
*/
public void formalDeal(PreDetectionParam param, SocketDataMsg socketDataMsg) {
String data = socketDataMsg.getData();
DevData devData = JSON.parseObject(data, DevData.class);
DevData devData = JSON.parseObject(data, DevData.class); //DevData的id值为 设备id_通道号 这种形式
SourceResponseCodeEnum dictDataEnumByCode = SourceResponseCodeEnum.getDictDataEnumByCode(socketDataMsg.getCode());
SourceIssue sourceIssue = SocketManager.getSourceList().get(0);
switch (Objects.requireNonNull(dictDataEnumByCode)) {
case SUCCESS:
realDataXiList.add(devData);
FormalTestManager.realDataXiList.add(devData);
successComm.add(devData.getId());
if (SocketManager.clockMap.containsKey(sourceIssue.getIndex())) {
@@ -929,13 +1009,14 @@ public class SocketDevResponseService {
if (successComm.size() == FormalTestManager.monitorIdListComm.size()) {
System.out.println(sourceIssue.getType() + splitTag + sourceIssue.getIndex() + "当前测试小项读取数据已经全部结束。。。。。。。。。");
//修改装置为监测中
adPlanService.updateTestState(param.getPlanId(), param.getDevIds());
// adPlanService.updateTestState(param.getPlanId(), param.getDevIds());
//开启线程进行入库原始数据操作
baseDataInsert(realDataXiList, sourceIssue, param, SocketManager.valueTypeMap);
baseDataInsert(FormalTestManager.realDataXiList, sourceIssue, param, SocketManager.valueTypeMap);
//调用判断方法
Map<String, Integer> textResult = detectionServiceImpl.processing(realDataXiList, param, FormalTestManager.devIdMapComm, sourceIssue, dataRule);
Map<String, Integer> textResult = detectionServiceImpl.processing(FormalTestManager.realDataXiList, param, FormalTestManager.devIdMapComm, sourceIssue, dataRule);
System.out.println(textResult);
//组装实体推送给前台
assWebJson(param, textResult, socketDataMsg, sourceIssue);
@@ -950,6 +1031,7 @@ public class SocketDevResponseService {
System.out.println(sourceIssue.getType() + sourceIssue.getIndex() + "当前测试大项已经全部结束》》》》》》》》");
//当residueCount为0则认为大项中的小项已经全部跑完开始组装信息推送给前端
List<DevLineTestResult> resultList = new ArrayList<>();
// 获取当前检测大项的所有设备的检测结果
List<DevLineTestResult> allDevTestList = targetTestMap.get(sourceIssue.getType());
Map<String, List<DevLineTestResult>> map = allDevTestList.stream().collect(Collectors.groupingBy(DevLineTestResult::getDeviceId));
map.forEach((dev, list) -> {
@@ -967,13 +1049,12 @@ public class SocketDevResponseService {
allDevTestList.clear();
CnSocketUtil.sendToWebSocket(param.getUserPageId(), socketDataMsg.getRequestId().split(stepTag)[1] + stepEnd, null, resultList, null);
}
//在这一步判断是否已经触发暂停按钮
if (FormalTestManager.stopFlag && CollUtil.isNotEmpty(SocketManager.getSourceList())) {
FormalTestManager.stopTime = 0;
FormalTestManager.hasStopFlag = true;
successComm.clear();
realDataXiList.clear();
FormalTestManager.realDataXiList.clear();
sendWebSocket(param.getUserPageId(), "preStopTest", "stop", null);
return;
}
@@ -982,6 +1063,7 @@ public class SocketDevResponseService {
List<SourceIssue> sourceIssueList = SocketManager.getSourceList();
if (CollUtil.isNotEmpty(sourceIssueList)) {
SourceIssue sourceIssues = SocketManager.getSourceList().get(0);
// 如果上一个大项检测完成,则检测下一个大项,并向前端推送消息
if (residueCount == 0) {
CnSocketUtil.sendToWebSocket(param.getUserPageId(), sourceIssues.getType() + stepBegin, null, new ArrayList<>(), null);
}
@@ -998,11 +1080,11 @@ public class SocketDevResponseService {
checkDataParam.setIsValueTypeName(false);
List<String> valueType = iPqScriptCheckDataService.getValueType(checkDataParam);
iPqDevService.updateResult(param.getDevIds(), valueType, param.getCode());
iPqDevService.updateResult(param.getDevIds(), valueType, param.getCode(),param.getUserId());
CnSocketUtil.quitSend(param);
}
successComm.clear();
realDataXiList.clear();
FormalTestManager.realDataXiList.clear();
}
break;
@@ -1011,7 +1093,7 @@ public class SocketDevResponseService {
break;
case NORMAL_RESPONSE:
realDataXiList.add(devData);
FormalTestManager.realDataXiList.add(devData);
break;
case DEV_ERROR:
@@ -1031,6 +1113,43 @@ public class SocketDevResponseService {
}
/*
private void processData(List<DevData> FormalTestManager.realDataXiList, List<String> successComm, SourceIssue sourceIssue, PreDetectionParam param, SocketDataMsg socketDataMsg, Object dataRule, String handlerSourceStr) {
if (SocketManager.clockMap.containsKey(sourceIssue.getIndex())) {
SocketManager.clockMap.put(sourceIssue.getIndex(), 0L);
}
if (successComm.size() == FormalTestManager.monitorIdListComm.size()) {
System.out.println(sourceIssue.getType() + stepTag + sourceIssue.getIndex() + "当前测试小项读取数据已经全部结束。。。。。。。。。");
handleSmallItemCompletion(FormalTestManager.realDataXiList, sourceIssue, param, socketDataMsg, dataRule);
if (handlePauseCondition(param, successComm, FormalTestManager.realDataXiList)) {
return;
}
startNextDetection(sourceIssue, param, socketDataMsg, handlerSourceStr);
successComm.clear();
FormalTestManager.realDataXiList.clear();
}
}
private static void handleSmallItemCompletion(List<DevData> FormalTestManager.realDataXiList, SourceIssue sourceIssue, PreDetectionParam param, SocketDataMsg socketDataMsg, Object dataRule) {
adPlanService.updateTestState(param.getPlanId(), param.getDevIds());
baseDataInsertService.insert(FormalTestManager.realDataXiList, sourceIssue, param, SocketManager.valueTypeMap);
Map<String, Integer> textResult = detectionServiceImpl.processing(FormalTestManager.realDataXiList, param, FormalTestManager.devIdMapComm, sourceIssue, dataRule);
assWebJson(param, textResult, socketDataMsg, sourceIssue);
SocketManager.delSource(sourceIssue.getIndex());
System.out.println("当前小项结束进行删除============" + sourceIssue.getType() + stepTag + sourceIssue.getIndex());
long residueCount = SocketManager.getSourceTarget(sourceIssue.getType()) - 1;
SocketManager.addTargetMap(sourceIssue.getType(), residueCount);
System.out.println("该大项还有" + residueCount + "个小项没有进行检测!!!!!!!!");
if (residueCount == 0) {
handleLargeItemCompletion(sourceIssue, param, socketDataMsg);
}
}
*/
/**
* 组装实体推送给前端
*/
@@ -1066,7 +1185,7 @@ public class SocketDevResponseService {
}
/**
* 返回大项检测结果
* 返回大项检测结果,默认遇到 45时认为不参与计算
*/
public Integer[] getMaxIntArray(List<Integer[]> arrays) {
int length = arrays.get(0).length;
@@ -1075,14 +1194,14 @@ public class SocketDevResponseService {
int maxValue = -1;
for (Integer[] array : arrays) {
int value = array[i];
if (value != 4) {
if (value != 4 && value != 5) {
if (value > maxValue) {
maxValue = value;
}
}
}
if (maxValue == -1) {
maxArray[i] = 4;
maxArray[i] = arrays.get(0)[i];
} else {
maxArray[i] = maxValue;
}
@@ -1107,7 +1226,7 @@ public class SocketDevResponseService {
case QUIT_INIT_01:
//关闭所有
SocketManager.removeUser(s);
CnSocketUtil.quitSendSource(param);
// CnSocketUtil.quitSendSource(param);
break;
case QUIT_INIT_02:
socketMsg.setRequestId(SourceOperateCodeEnum.QUITE.getValue());
@@ -1150,6 +1269,11 @@ public class SocketDevResponseService {
}
/**
*
* @param issue
* @return key为V或Ivalue为对应的源下发信息
*/
private Map<String, String> sourceMessage(SourceIssue issue) {
//Ua=59.0V,相角=0.0° Ub=59.0V,相角=0.0° Uc=59.0V,相角=0.0°)
Map<String, String> map = new HashMap<>();
@@ -1174,13 +1298,22 @@ public class SocketDevResponseService {
List<DevData.SqlDataDTO> data,
List<DevData.SqlDataDTO> dataPhase) {
StringBuffer str = new StringBuffer();
if (data.size() == dataPhase.size()) {
if(isPhaseAngle){
if(CollUtil.isNotEmpty(data)&&CollUtil.isNotEmpty(dataPhase)){
if (data.size() == dataPhase.size()) {
DevData.SqlDataDTO.ListDTO dto = data.get(0).getList();
DevData.SqlDataDTO.ListDTO phase = dataPhase.get(0).getList();
str.append("装置(" + type + "a=" + String.format("%.4f", dto.getA()) + ",相角=" + String.format("%.4f", phase.getA()) + "° " +
type + "b=" + String.format("%.4f", dto.getB()) + ",相角=" + String.format("%.4f", phase.getB()) + "° " +
type + "c=" + String.format("%.4f", dto.getC()) + ",相角=" + String.format("%.4f", phase.getC()) + "° ");
str.append(")");
}
}
}else{
DevData.SqlDataDTO.ListDTO dto = data.get(0).getList();
DevData.SqlDataDTO.ListDTO phase = dataPhase.get(0).getList();
str.append("装置(" + type + "a=" + String.format("%.4f", dto.getA()) + ",相角=" + String.format("%.4f", phase.getA()) + "° " +
type + "b=" + String.format("%.4f", dto.getB()) + ",相角=" + String.format("%.4f", phase.getB()) + "° " +
type + "c=" + String.format("%.4f", dto.getC()) + ",相角=" + String.format("%.4f", phase.getC()) + "° ");
str.append("装置(" + type + "a=" + String.format("%.4f", dto.getA()) +
type + "b=" + String.format("%.4f", dto.getB()) +
type + "c=" + String.format("%.4f", dto.getC()) );
str.append(")");
}
return str.toString();
@@ -1255,32 +1388,52 @@ public class SocketDevResponseService {
//源信息
Map<String, SourceIssue.ChannelListDTO> sourceMap = channelList.stream()
.collect(Collectors.toMap(x -> x.getChannelType(), Function.identity()));
Boolean a = getaBoolean(sourceMap.get(type + "a"), data.get(0).getList().getA(), dataPhase.get(0).getList().getA());
Boolean b = getaBoolean(sourceMap.get(type + "b"), data.get(0).getList().getB(), dataPhase.get(0).getList().getB());
Boolean c = getaBoolean(sourceMap.get(type + "c"), data.get(0).getList().getC(), dataPhase.get(0).getList().getC());
Boolean a = getaBoolean(sourceMap.get(type + "a"), CollUtil.isNotEmpty(data) ? data.get(0).getList().getA() : null,
CollUtil.isNotEmpty(dataPhase) ? dataPhase.get(0).getList().getA(): null);
Boolean b = getaBoolean(sourceMap.get(type + "b"), CollUtil.isNotEmpty(data) ? data.get(0).getList().getB(): null,
CollUtil.isNotEmpty(dataPhase) ? dataPhase.get(0).getList().getB(): null);
Boolean c = getaBoolean(sourceMap.get(type + "c"), CollUtil.isNotEmpty(data) ? data.get(0).getList().getC(): null,
CollUtil.isNotEmpty(dataPhase) ? dataPhase.get(0).getList().getC(): null);
compareDev.setIsQualified(a && b && c);
compareDev.setDesc(name + (compareDev.getIsQualified() ? "合格->" : "不合格->") + stepTag + desc + stepTag + devMessage(type, data, dataPhase));
return compareDev;
}
private static Boolean getaBoolean(SourceIssue.ChannelListDTO channelListDTO, Double devData, Double devPhase) {
return NumberUtil.isIn(BigDecimal.valueOf(devData),
BigDecimal.valueOf(channelListDTO.getFAmp() * 0.95),
BigDecimal.valueOf(channelListDTO.getFAmp() * 1.05))
&&
phaseBoolean(channelListDTO, devPhase);
/**
* 相须校验-从幅值、相角两个维度判断是否合格
* @param channelListDTO
* @param devData
* @param devPhase
* @return
*/
private Boolean getaBoolean(SourceIssue.ChannelListDTO channelListDTO, Double devData, Double devPhase) {
Boolean isDev = false;
Boolean isPhase = false;
if(ObjectUtil.isNotNull(devData)){
isDev= NumberUtil.isIn(BigDecimal.valueOf(devData),
BigDecimal.valueOf(channelListDTO.getFAmp() * 0.95),
BigDecimal.valueOf(channelListDTO.getFAmp() * 1.05));
}
if(isPhaseAngle){
if(ObjectUtil.isNotNull(devPhase)){
isPhase = phaseBoolean(channelListDTO, devPhase);
}
}else{
isPhase=true;
}
return isDev && isPhase;
}
/**
* 判断相角(-180° ~ 180°
* +360° ~ -360°
* +360° ~ -360°
*
* @param channelListDTO 源下发角度
* @param devPhase 装置返回角度
* @return
*/
private static Boolean phaseBoolean(SourceIssue.ChannelListDTO channelListDTO, Double devPhase) {
private Boolean phaseBoolean(SourceIssue.ChannelListDTO channelListDTO, Double devPhase) {
Double phase = devPhase;
if (devPhase < -180) {
phase = devPhase + 360;
@@ -1288,10 +1441,18 @@ public class SocketDevResponseService {
if (devPhase > 180) {
phase = devPhase - 360;
}
Double fPhase = channelListDTO.getFPhase();
if (fPhase < -180) {
fPhase = fPhase + 360;
}
if (fPhase > 180) {
fPhase = fPhase - 360;
}
return
NumberUtil.isIn(BigDecimal.valueOf(phase),
BigDecimal.valueOf(channelListDTO.getFPhase() - 1),
BigDecimal.valueOf(channelListDTO.getFPhase() + 1));
BigDecimal.valueOf(fPhase - 1),
BigDecimal.valueOf(fPhase + 1));
}
@@ -1301,7 +1462,7 @@ public class SocketDevResponseService {
*/
public void initRestart() {
this.successComm.clear();
this.realDataXiList.clear();
FormalTestManager.realDataXiList.clear();
}
@@ -1321,8 +1482,8 @@ public class SocketDevResponseService {
//初始化相序集合
this.devInfo.clear();
this.devDataMap.clear();
this.realDataXiList.clear();
//this.devDataMap.clear(); //好像没有用到
FormalTestManager.realDataXiList.clear();
this.targetTestMap.clear();
List<PreDetection> pqDevList = iPqDevService.getDevInfo(param.getDevIds());
@@ -1459,7 +1620,7 @@ public class SocketDevResponseService {
adHarmonicResult.setAdType(checkDataMap.get(sqlDataDTO.getDesc()));
adHarmonicResult.setDataType("avg");
if (!DicDataEnum.HI.getCode().equals(sourceIssue.getType()) && !DicDataEnum.HSI.getCode().equals(sourceIssue.getType()) && !DicDataEnum.HP.getCode().equals(sourceIssue.getType())) {
if (!DicDataEnum.HSV.getCode().equals(sourceIssue.getType()) && !DicDataEnum.HSI.getCode().equals(sourceIssue.getType()) && !DicDataEnum.HP.getCode().equals(sourceIssue.getType())) {
if (CollUtil.isNotEmpty(data.getSqlData())) {
DevData.SqlDataDTO.ListDTO vvv = data.getSqlData().get(0).getList();
Double aV = vvv.getA();
@@ -1484,22 +1645,39 @@ public class SocketDevResponseService {
List<String> c = tem.getC();
Class<AdHarmonicResult> example = (Class<AdHarmonicResult>) adHarmonicResult.getClass();
for (int i = 2; i <= 50; i++) {
// 通过反射设置name字段的值
try {
// 假设这些字段已经以正确的方式定义在AdHarmonicResult类中
Field aField = example.getDeclaredField("aValue" + i);
Field bField = example.getDeclaredField("bValue" + i);
Field cField = example.getDeclaredField("cValue" + i);
if (DicDataEnum.HSV.getCode().equals(sourceIssue.getType()) || DicDataEnum.HSI.getCode().equals(sourceIssue.getType())) {
for (int i = 1; i < a.size() + 1; i++) {
try {
Field aField = example.getDeclaredField("aValue" + i);
Field bField = example.getDeclaredField("bValue" + i);
Field cField = example.getDeclaredField("cValue" + i);
aField.setAccessible(true);
aField.set(adHarmonicResult, a.get(i - 2));
bField.setAccessible(true);
bField.set(adHarmonicResult, b.get(i - 2));
cField.setAccessible(true);
cField.set(adHarmonicResult, c.get(i - 2));
} catch (NoSuchFieldException | IllegalAccessException e) {
e.printStackTrace();
aField.setAccessible(true);
aField.set(adHarmonicResult, a.get(i - 1));
bField.setAccessible(true);
bField.set(adHarmonicResult, b.get(i - 1));
cField.setAccessible(true);
cField.set(adHarmonicResult, c.get(i - 1));
} catch (NoSuchFieldException | IllegalAccessException e) {
e.printStackTrace();
}
}
} else {
for (int i = 2; i <= a.size() + 1; i++) {
try {
Field aField = example.getDeclaredField("aValue" + i);
Field bField = example.getDeclaredField("bValue" + i);
Field cField = example.getDeclaredField("cValue" + i);
aField.setAccessible(true);
aField.set(adHarmonicResult, a.get(i - 2));
bField.setAccessible(true);
bField.set(adHarmonicResult, b.get(i - 2));
cField.setAccessible(true);
cField.set(adHarmonicResult, c.get(i - 2));
} catch (NoSuchFieldException | IllegalAccessException e) {
e.printStackTrace();
}
}
}
adHarmonicResultList.add(adHarmonicResult);
@@ -1544,9 +1722,7 @@ public class SocketDevResponseService {
private LocalDateTime timeFormat(String dateTimeStr, DateTimeFormatter formatter) {
try {
// 假设输入是UTC时间将其解析为ZonedDateTime
ZonedDateTime zonedDateTime = ZonedDateTime.parse(dateTimeStr, formatter.withZone(ZoneId.of("UTC")));
// 将ZonedDateTime转换为LocalDateTime去除时区信息
LocalDateTime localDateTime = zonedDateTime.toLocalDateTime();
return localDateTime;
} catch (DateTimeParseException e) {

View File

@@ -10,10 +10,7 @@ import com.njcn.gather.detection.pojo.vo.DevLineTestResult;
import com.njcn.gather.detection.pojo.vo.SocketDataMsg;
import com.njcn.gather.detection.pojo.vo.SocketMsg;
import com.njcn.gather.detection.pojo.vo.WebSocketVO;
import com.njcn.gather.detection.util.socket.CnSocketUtil;
import com.njcn.gather.detection.util.socket.MsgUtil;
import com.njcn.gather.detection.util.socket.SocketManager;
import com.njcn.gather.detection.util.socket.WebServiceManager;
import com.njcn.gather.detection.util.socket.*;
import com.njcn.gather.detection.util.socket.cilent.NettyClient;
import com.njcn.gather.detection.util.socket.cilent.NettyDevClientHandler;
import com.njcn.gather.device.pojo.vo.PreDetection;
@@ -64,7 +61,12 @@ public class SocketSourceResponseService {
switch (enumByCode) {
//源初始化
case YJC_YTXJY:
detectionDev(param, socketDataMsg);
if (ObjectUtil.isNotNull(param.getPlanId())) {
detectionDev(param, socketDataMsg);
} else {
// 程控源-源通信校验
handleYtxjySimulate(param, socketDataMsg);
}
break;
//相序检测
case YJC_XUJY:
@@ -72,7 +74,11 @@ public class SocketSourceResponseService {
break;
//正式检测
case FORMAL_REAL:
senParamToDev(param, socketDataMsg);
if (ObjectUtil.isNotNull(param.getPlanId())) {
senParamToDev(param, socketDataMsg);
} else {
handleSimulateTest(param, socketDataMsg);
}
break;
//系数校验
case Coefficient_Check:
@@ -83,13 +89,92 @@ public class SocketSourceResponseService {
break;
case YXT:
break;
}
} else {
System.out.println("fggggggggggggggggggggg" + enumByCode);
}
}
private void handleYtxjySimulate(PreDetectionParam param, SocketDataMsg socketDataMsg) {
SourceResponseCodeEnum dictDataEnumByCode = SourceResponseCodeEnum.getDictDataEnumByCode(socketDataMsg.getCode());
if (ObjectUtil.isNotNull(dictDataEnumByCode)) {
switch (dictDataEnumByCode) {
case SUCCESS:
if (param.getSendWebMsg()) {
WebServiceManager.sendMsg(param.getUserPageId(), JSON.toJSONString(socketDataMsg));
}
System.out.println(param.getSendWebMsg() + "模拟检测-源初始化成功");
break;
case UNPROCESSED_BUSINESS:
WebServiceManager.sendMsg(param.getUserPageId(), JSON.toJSONString(socketDataMsg));
break;
case SOURCE_CONNECTION_ERROR:
CnSocketUtil.quitSendSource(param);
WebServiceManager.sendMsg(param.getUserPageId(), JSON.toJSONString(socketDataMsg));
break;
case CONTROLLED_SOURCE_ERROR:
CnSocketUtil.quitSendSource(param);
WebServiceManager.sendMsg(param.getUserPageId(), JSON.toJSONString(socketDataMsg));
break;
case TEST_ITEM_PARSING_ERROR:
CnSocketUtil.quitSendSource(param);
WebServiceManager.sendMsg(param.getUserPageId(), JSON.toJSONString(socketDataMsg));
break;
case SOURCE_CONTROL_ERROR:
CnSocketUtil.quitSendSource(param);
WebServiceManager.sendMsg(param.getUserPageId(), JSON.toJSONString(socketDataMsg));
break;
case TARGET_SOURCE_ERROR:
CnSocketUtil.quitSendSource(param);
WebServiceManager.sendMsg(param.getUserPageId(), JSON.toJSONString(socketDataMsg));
break;
case NOT_INITIALIZED:
CnSocketUtil.quitSendSource(param);
WebServiceManager.sendMsg(param.getUserPageId(), JSON.toJSONString(socketDataMsg));
break;
case UNKNOWN_ERROR:
CnSocketUtil.quitSendSource(param);
WebServiceManager.sendMsg(param.getUserPageId(), JSON.toJSONString(socketDataMsg));
break;
case UNABLE_TO_RESPOND:
CnSocketUtil.quitSendSource(param);
WebServiceManager.sendMsg(param.getUserPageId(), JSON.toJSONString(socketDataMsg));
break;
default:
CnSocketUtil.sendUnSocket(param.getUserPageId());
break;
}
}
}
/**
* 处理模拟检测时,通信模块返回报文
*
* @param param
* @param socketDataMsg
*/
private void handleSimulateTest(PreDetectionParam param, SocketDataMsg socketDataMsg) {
SourceResponseCodeEnum dictDataEnumByCode = SourceResponseCodeEnum.getDictDataEnumByCode(socketDataMsg.getCode());
if (ObjectUtil.isNotNull(dictDataEnumByCode)) {
switch (dictDataEnumByCode) {
case SUCCESS:
WebServiceManager.sendMsg(param.getUserPageId(), JSON.toJSONString(socketDataMsg));
System.out.println("模拟检测-源成功执行脚本" + JSON.toJSONString(socketDataMsg));
break;
case UNPROCESSED_BUSINESS:
WebServiceManager.sendMsg(param.getUserPageId(), JSON.toJSONString(socketDataMsg));
break;
default:
CnSocketUtil.quitSendSource(param);
SocketMsg<String> socketMsg = new SocketMsg<>();
socketMsg.setRequestId(socketDataMsg.getRequestId());
socketMsg.setOperateCode(socketDataMsg.getOperateCode());
socketMsg.setData(dictDataEnumByCode.getMessage());
WebServiceManager.sendMsg(param.getUserPageId(), JSON.toJSONString(socketMsg));
break;
}
}
}
@@ -116,7 +201,6 @@ public class SocketSourceResponseService {
socketMsg.setData(JSON.toJSONString(phaseSequenceParam));
SocketManager.sendMsg(s, JSON.toJSONString(socketMsg));
break;
case UNPROCESSED_BUSINESS:
WebServiceManager.sendMsg(param.getUserPageId(), JSON.toJSONString(socketDataMsg));
@@ -166,6 +250,7 @@ public class SocketSourceResponseService {
case SOURCE_CONNECTION_ERROR:
CnSocketUtil.quitSendSource(param);
WebServiceManager.sendMsg(param.getUserPageId(), JSON.toJSONString(socketDataMsg));
break;
case CONTROLLED_SOURCE_ERROR:
CnSocketUtil.quitSendSource(param);
WebServiceManager.sendMsg(param.getUserPageId(), JSON.toJSONString(socketDataMsg));
@@ -267,7 +352,7 @@ public class SocketSourceResponseService {
String s = param.getUserPageId() + DEV;
SourceIssue sourceIssue = SocketManager.getSourceList().get(0);
List<String> comm = sourceIssue.getDevValueTypeList();
List<String> comm = sourceIssue.getDevValueTypeList(); //形如:类型&小项code这种形式。例如real$VRMS、real$IRMS
System.out.println("向装置下发的参数>>>>>>>>" + comm);
socketMsg.setRequestId(SourceOperateCodeEnum.FORMAL_REAL.getValue() + stepTag + sourceIssue.getType());
int ignoreCount;
@@ -337,6 +422,7 @@ public class SocketSourceResponseService {
case SUCCESS:
//通讯校验成功
SocketManager.removeUser(param.getUserPageId() + source);
WebServiceManager.sendMsg(param.getUserPageId(), JSON.toJSONString(socketDataMsg));
break;
case UNPROCESSED_BUSINESS:
break;
@@ -361,6 +447,7 @@ public class SocketSourceResponseService {
this.monitorIdList = devList.stream().flatMap(x -> x.getMonitorList().stream())
.map(PreDetection.MonitorListDTO::getLineId)
.collect(Collectors.toList());
XiNumberManager.xiDevList = devList;
}
}

View File

@@ -0,0 +1,58 @@
package com.njcn.gather.detection.pojo.enums;
import cn.hutool.core.util.ObjectUtil;
import lombok.Getter;
/**
* @Description:
* @Author: wr
* @Date: 2025/2/12 10:15
*/
@Getter
public enum DetectionCodeEnum {
FREQ("FREQ", "频率"),
VRMS("VRMS", "相电压有效值"),
DELTA_V("DELTA_V", "电压偏差"),
VA("VA", "电压相角"),
U1("U1", "基波电压"),
V2_50("V2-50", "谐波电压"),
I2_50("I2-50", "谐波电流"),
P2_50("P2-50", "谐波有功功率"),
SV_1_49("SV_1-49", "间谐波电压"),
SI_1_49("SI_1-49", "间谐波电流"),
MAG("MAG", "电压幅值"),
DUR("DUR", "持续时间"),
IRMS("IRMS", "电流有效值"),
IA("IA", "电流相角"),
V_UNBAN("V_UNBAN", "三相电压负序不平衡度"),
I_UNBAN("I_UNBAN", "三相电流负序不平衡度"),
PST("PST", "短时间闪变"),
P("P", "功率"),
I1("I1", "基波电流"),
UNKNOWN_ERROR("-1", "未知异常"),
;
private final String code;
private final String message;
DetectionCodeEnum(String code, String message) {
this.code = code;
this.message = message;
}
public static DetectionCodeEnum getDetectionCodeByCode(String code) {
for (DetectionCodeEnum detectionCodeEnum : DetectionCodeEnum.values()) {
if (ObjectUtil.equals(code, detectionCodeEnum.getCode())) {
return detectionCodeEnum;
}
}
return UNKNOWN_ERROR;
}
}

View File

@@ -9,11 +9,15 @@ import lombok.Getter;
@Getter
public enum DetectionResponseEnum {
PLAN_PATTERN_NOT("A020001", "计划模式查询为空"),
SCRIPT_PATTERN_NOT("A020001", "检测脚本查询为空"),
SOURCE_INFO_NOT("A020002", "源表信息不存在"),
PLAN_AND_SOURCE_NOT("A020003", "计划和源关系不存在"),
ITEM_TEST_NOT("A020004", "检测项为空"),
PLAN_DEV_IP_HAS("A20005","当前计划检测装置ip重复")
;
PLAN_DEV_IP_HAS("A20005","当前计划检测装置ip重复"),
SOURCE_NOT_CONNECT("A020006", "源未连接"),
SCRIPT_CHECK_DATA_NOT_EXIST("A020040","测试脚本项暂无配置" );
private final String code;
private final String message;

View File

@@ -47,6 +47,7 @@ public enum SourceOperateCodeEnum {
YJC_XYJY("yjc_xyjy", "协议校验"),
YJC_XUJY("YJC_xujy", "相序校验"),
FORMAL_REAL("formal_real","正式检测"),
// SIMULATE_REAL("simulate_real","模拟检测"),
Coefficient_Check("Coefficient_Check","系数校验"),
QUITE("quit","关闭设备通讯初始化"),
QUITE_SOURCE("close_source","关闭源通讯"),
@@ -74,6 +75,7 @@ public enum SourceOperateCodeEnum {
TEST_TEM_START("6","继续检测"),
TEST_STOP("7","停止检测"),
RE_ERROR_TEST("8","不合格项复检"),
SIMULATE_TEST("9","模拟检测"),
/**

View File

@@ -25,10 +25,6 @@ public class PreDetectionParam {
@NotBlank(message = "计划id不可为空")
private String planId;
/**
* 检测计划code
*/
private String planCode;
/**
* 数字、模拟、比对
@@ -65,4 +61,8 @@ public class PreDetectionParam {
* 自动生成,用于生成数据表后缀
*/
private String code;
private Boolean sendWebMsg;
private String userId;
}

View File

@@ -0,0 +1,40 @@
package com.njcn.gather.detection.pojo.param;
import com.njcn.gather.pojo.constant.DetectionValidMessage;
import lombok.Data;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
/**
* @author caozehui
* @data 2025-03-06
*/
@Data
public class SimulateDetectionParam {
/**
* 操作类型 9.模拟检测
*/
private String operateType = "9";
/**
* 用户功能组成唯一标识 zhangsan_test
*/
private String userPageId;
/**
* 检测脚本Id
*/
private String scriptId;
@NotNull(message = DetectionValidMessage.INDEX_NOT_NULL)
private Integer scriptIndex;
/**
* 源id
*/
@NotBlank(message = DetectionValidMessage.SOURCE_ID_NOT_BLANK)
private String sourceId;
}

View File

@@ -3,6 +3,8 @@ package com.njcn.gather.detection.pojo.vo;
import lombok.Data;
import java.math.BigDecimal;
/**
* @author wr
* @description
@@ -37,4 +39,13 @@ public class DetectionData {
*/
private String radius;
/**
* 误差值
*/
private BigDecimal errorData;
/**
* 单位
*/
private String unit;
}

View File

@@ -1,7 +1,7 @@
package com.njcn.gather.detection.service;
import com.njcn.gather.detection.pojo.param.PreDetectionParam;
import com.njcn.gather.detection.pojo.param.SimulateDetectionParam;
/**
@@ -13,7 +13,8 @@ public interface PreDetectionService {
/**
* 源通讯校验socket入参拼接
* @param param
*
* @param param
* @Author: wr
* @Date: 2024/12/11 13:26
*/
@@ -23,14 +24,29 @@ public interface PreDetectionService {
void coefficientCheck(PreDetectionParam param);
boolean startTest(PreDetectionParam param);
boolean temStopTest();
boolean restartTemTest(PreDetectionParam param);
/**
* 模拟测试-源通讯校验
*
* @param param
*/
void ytxCheckSimulate(SimulateDetectionParam param);
/**
* 模拟测试-向源发送脚本
*
* @param param
*/
void sendScript(SimulateDetectionParam param);
/**
* 模拟测试-停止
*
* @param param
*/
void closeTestSimulate(SimulateDetectionParam param);
}

View File

@@ -8,6 +8,7 @@ import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.njcn.gather.detection.pojo.enums.DetectionCodeEnum;
import com.njcn.gather.detection.pojo.param.PreDetectionParam;
import com.njcn.gather.detection.pojo.po.DevData;
import com.njcn.gather.detection.pojo.vo.DetectionData;
@@ -34,6 +35,9 @@ import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
import static com.njcn.gather.detection.util.socket.UnitUtil.unit;
/**
* @author wr
* @description
@@ -62,6 +66,7 @@ public class DetectionServiceImpl {
/**
* 开始处理指标类型
* 一共20组数据开始处理格式
* 返回值key为设备id_通道号value为检测结果
*/
public Map<String, Integer> processing(List<DevData> dev, PreDetectionParam detection, Map<String, String> devIdMapComm, SourceIssue issue, DictDataEnum dataRule) {
Map<String, List<DevData>> devDataMap = dev.stream().collect(Collectors.groupingBy(DevData::getId));
@@ -87,6 +92,8 @@ public class DetectionServiceImpl {
param.setIndex(sourceIssue.getIndex());
param.setScriptId(sourceIssue.getScriptId());
param.setErrorSysId(errorSysId);
param.setUn(sourceIssue.getFUn());
param.setIn(sourceIssue.getFIn());
List<ErrDtlsCheckDataVO> errDtlsCheckData = pqErrSysDtlsService.listByPqErrSysIdAndTypes(param);
ResultUnitEnum resultUnitEnumByCode = ResultUnitEnum.getResultUnitEnumByCode(sourceIssue.getType());
switch (resultUnitEnumByCode) {
@@ -112,57 +119,81 @@ public class DetectionServiceImpl {
*/
case HV:
AdHarmonicResult harmV = isHarmQualified(dev, devIdMapComm, errDtlsCheckData, U, sourceIssue, dataRule, 2);
detectionDataDealService.acceptAdResult(Arrays.asList(harmV), code);
return harmV.getResultFlag();
if (ObjectUtil.isNotNull(harmV)) {
detectionDataDealService.acceptAdResult(Arrays.asList(harmV), code);
return harmV.getResultFlag();
}
return 4;
/**
* 谐波电流
*/
case HI:
AdHarmonicResult harmI = isHarmQualified(dev, devIdMapComm, errDtlsCheckData, I, sourceIssue, dataRule, 2);
detectionDataDealService.acceptAdResult(Arrays.asList(harmI), code);
return harmI.getResultFlag();
if (ObjectUtil.isNotNull(harmI)) {
detectionDataDealService.acceptAdResult(Arrays.asList(harmI), code);
return harmI.getResultFlag();
}
return 4;
/**
* 间谐波电压
*/
case HSV:
AdHarmonicResult harmInV = isHarmQualified(dev, devIdMapComm, errDtlsCheckData, U, sourceIssue, dataRule, 1);
detectionDataDealService.acceptAdResult(Arrays.asList(harmInV), code);
return harmInV.getResultFlag();
if (ObjectUtil.isNotNull(harmInV)) {
detectionDataDealService.acceptAdResult(Arrays.asList(harmInV), code);
return harmInV.getResultFlag();
}
return 4;
/**
* 间谐波电流
*/
case HSI:
AdHarmonicResult harmInI = isHarmQualified(dev, devIdMapComm, errDtlsCheckData, I, sourceIssue, dataRule, 1);
detectionDataDealService.acceptAdResult(Arrays.asList(harmInI), code);
return harmInI.getResultFlag();
if (ObjectUtil.isNotNull(harmInI)) {
detectionDataDealService.acceptAdResult(Arrays.asList(harmInI), code);
return harmInI.getResultFlag();
}
return 4;
/**
* 三相电压不平衡度
*/
case IMBV:
AdNonHarmonicResult vUnban = isUnBalanceOrFlickerQualified(dev, devIdMapComm, errDtlsCheckData, U, sourceIssue, dataRule, "V_UNBAN");
detectionDataDealService.acceptAdNonResult(Arrays.asList(vUnban), code);
return vUnban.getResultFlag();
if (ObjectUtil.isNotNull(vUnban)) {
detectionDataDealService.acceptAdNonResult(Arrays.asList(vUnban), code);
return vUnban.getResultFlag();
}
return 4;
/**
* 三相电流不平衡度
*/
case IMBA:
AdNonHarmonicResult iUnban = isUnBalanceOrFlickerQualified(dev, devIdMapComm, errDtlsCheckData, I, sourceIssue, dataRule, "I_UNBAN");
detectionDataDealService.acceptAdNonResult(Arrays.asList(iUnban), code);
return iUnban.getResultFlag();
if (ObjectUtil.isNotNull(iUnban)) {
detectionDataDealService.acceptAdNonResult(Arrays.asList(iUnban), code);
return iUnban.getResultFlag();
}
return 4;
/**
* 谐波有功功率
*/
case HP:
AdHarmonicResult harmP = isHarmQualified(dev, devIdMapComm, errDtlsCheckData, P, sourceIssue, dataRule, 2);
detectionDataDealService.acceptAdResult(Arrays.asList(harmP), code);
return harmP.getResultFlag();
if (ObjectUtil.isNotNull(harmP)) {
detectionDataDealService.acceptAdResult(Arrays.asList(harmP), code);
return harmP.getResultFlag();
}
return 4;
/**
* 闪变
*/
case F:
AdNonHarmonicResult pst = isUnBalanceOrFlickerQualified(dev, devIdMapComm, errDtlsCheckData, null, sourceIssue, dataRule, "PST");
detectionDataDealService.acceptAdNonResult(Arrays.asList(pst), code);
return pst.getResultFlag();
if (ObjectUtil.isNotNull(pst)) {
detectionDataDealService.acceptAdNonResult(Arrays.asList(pst), code);
return pst.getResultFlag();
}
return 4;
/**
* 暂态
*/
@@ -170,8 +201,7 @@ public class DetectionServiceImpl {
case VOLTAGE_DUR:
return isVoltageQualified(dev, devIdMapComm, errDtlsCheckData, sourceIssue, dataRule, code);
default:
// return isUnknownQualified(dev, devIdMapComm, errDtlsCheckData, sourceIssue, dataRule, code);
return 4;
return isUnknownQualified(dev, devIdMapComm, errDtlsCheckData, sourceIssue, dataRule, code);
}
}
@@ -182,49 +212,142 @@ public class DetectionServiceImpl {
DictDataEnum dataRule,
String code) {
List<AdNonHarmonicResult> info = new ArrayList<>();
List<AdHarmonicResult> harmonicResultList = new ArrayList<>();
List<String> devValueTypeList = sourceIssue.getDevValueTypeList();
//非谐波指标
List<String> harmDesc = dev.stream().flatMap(x -> x.getSqlData().stream()).map(DevData.SqlDataDTO::getDesc).distinct().collect(Collectors.toList());
//谐波类型
List<String> inHarm = dev.stream().flatMap(x -> x.getSqlDataHarm().stream()).map(DevData.SqlDataHarmDTO::getDesc).distinct().collect(Collectors.toList());
for (String s : devValueTypeList) {
//基本数据
Map<String, List<Double>> map = devListMap(dev, dataRule, s.split("\\$")[1]);
AdNonHarmonicResult result = new AdNonHarmonicResult();
String[] split = dev.get(0).getId().split("_");
String devID = devIdMapComm.get(split[0]);
result.setMonitorId(devID + "_" + split[1]);
result.setScriptId(sourceIssue.getScriptId());
result.setSort(sourceIssue.getIndex());
result.setDataType("avg");
List<ErrDtlsCheckDataVO> dtlsCheckData = errDtlsCheckData.stream().filter(x -> x.getValueTypeCode().equals(s.split("\\$")[1])).collect(Collectors.toList());
List<DetectionData> resultFlag = new ArrayList<>();
map.forEach((key, value) -> {
List<ErrDtlsCheckDataVO> checkData = dtlsCheckData.stream().filter(x -> key.equals(x.getPhase())).collect(Collectors.toList());
DetectionData detectionData = rangeComparisonList(value, new ArrayList<>(), null, checkData.get(0).getValue(), dataRule);
if (key.equals(TYPE_T)) {
result.setTValue(JSON.toJSONString(detectionData));
String devIndex = s.split("\\$")[1];
if (harmDesc.contains(devIndex)) {
//基本数据(频率,电压,电流)
Map<String, List<Double>> map = devListMap(dev, dataRule, devIndex);
AdNonHarmonicResult result = new AdNonHarmonicResult();
String[] split = dev.get(0).getId().split("_");
String devID = devIdMapComm.get(split[0]);
result.setMonitorId(devID + "_" + split[1]);
result.setScriptId(sourceIssue.getScriptId());
result.setSort(sourceIssue.getIndex());
result.setDataType("avg");
Integer isQualified;
String valueTypeCode;
List<ErrDtlsCheckDataVO> dtlsCheckData = errDtlsCheckData.stream().filter(x -> x.getValueTypeCode().equals(s.split("\\$")[1])).collect(Collectors.toList());
if (CollUtil.isNotEmpty(dtlsCheckData)) {
result.setAdType(dtlsCheckData.get(0).getValueType());
isQualified = dtlsCheckData.get(0).getIsQualified();
valueTypeCode = dtlsCheckData.get(0).getValueTypeCode();
} else {
isQualified = 4;
valueTypeCode = "";
}
if (key.equals(TYPE_A)) {
result.setAValue(JSON.toJSONString(detectionData));
List<DetectionData> resultFlag = new ArrayList<>();
map.forEach((key, value) -> {
List<ErrDtlsCheckDataVO> checkData = dtlsCheckData.stream().filter(x -> key.equals(x.getPhase())).collect(Collectors.toList());
if (CollUtil.isNotEmpty(checkData)) {
DetectionData detectionData;
if (DUR.equals(devIndex)) {
detectionData = rangeDURComparisonList(value, isQualified, valueTypeCode, new ArrayList<>(), sourceIssue.getFFreq(), checkData.get(0).getValue(), dataRule);
} else {
detectionData = rangeComparisonList(value, isQualified, valueTypeCode, new ArrayList<>(), null, checkData.get(0).getValue(), dataRule);
}
if (key.equals(TYPE_T)) {
result.setTValue(JSON.toJSONString(detectionData));
}
if (key.equals(TYPE_A)) {
result.setAValue(JSON.toJSONString(detectionData));
}
if (key.equals(TYPE_B)) {
result.setBValue(JSON.toJSONString(detectionData));
}
if (key.equals(TYPE_C)) {
result.setCValue(JSON.toJSONString(detectionData));
}
resultFlag.add(detectionData);
}
});
result.setResultFlag(setResultFlag(resultFlag));
info.add(result);
}
if (inHarm.contains(devIndex)) {
String fundCode = "";
String harmCode = "";
Integer num = 1;
String type = "";
Double fData = 1.0;
if (devIndex.contains("V")) {
fundCode = DetectionCodeEnum.U1.getCode();
num = 2;
type = U;
fData = sourceIssue.getFUn();
if (devIndex.contains("50")) {
harmCode = DetectionCodeEnum.V2_50.getCode();
}
if (devIndex.contains("49")) {
harmCode = DetectionCodeEnum.SV_1_49.getCode();
}
}
if (key.equals(TYPE_B)) {
result.setBValue(JSON.toJSONString(detectionData));
if (devIndex.contains("I")) {
fundCode = DetectionCodeEnum.I1.getCode();
;
type = I;
fData = sourceIssue.getFIn();
if (devIndex.contains("50")) {
harmCode = DetectionCodeEnum.I2_50.getCode();
}
if (devIndex.contains("49")) {
harmCode = DetectionCodeEnum.SI_1_49.getCode();
}
}
if (key.equals(TYPE_C)) {
result.setCValue(JSON.toJSONString(detectionData));
if (devIndex.contains("P")) {
type = P;
harmCode = DetectionCodeEnum.P2_50.getCode();
fData = sourceIssue.getFIn() * sourceIssue.getFUn() * 0.01;
}
resultFlag.add(detectionData);
});
result.setResultFlag(setResultFlag(resultFlag));
info.add(result);
//谐波
Map<String, Map<Double, List<Double>>> devHarmMap = devHarmListMap(dev, sourceIssue, dataRule, 2);
List<DetectionData> detectionData = harmRangeComparison(new ArrayList<>(), null, TYPE_T, sourceIssue, dataRule, devHarmMap.get(TYPE_T), sourceIssue.getFUn(), 2);
//间谐波
Map<String, Map<Double, List<Double>>> devInHarmMap = devHarmListMap(dev, sourceIssue, dataRule, 1);
Map<String, Map<Double, List<Double>>> devHarmMap = devHarmListMap(dev, sourceIssue, dataRule, fundCode, harmCode, num);
if (CollUtil.isNotEmpty(devHarmMap)) {
AdHarmonicResult harmonicResult = new AdHarmonicResult();
String[] split = dev.get(0).getId().split("_");
String devID = devIdMapComm.get(split[0]);
harmonicResult.setMonitorId(devID + "_" + split[1]);
harmonicResult.setScriptId(sourceIssue.getScriptId());
harmonicResult.setSort(sourceIssue.getIndex());
Integer isQualified;
String valueTypeCode;
List<ErrDtlsCheckDataVO> dtlsCheckData = errDtlsCheckData.stream().filter(x -> x.getValueTypeCode().equals(s.split("\\$")[1])).collect(Collectors.toList());
if (CollUtil.isNotEmpty(dtlsCheckData)) {
harmonicResult.setAdType(dtlsCheckData.get(0).getValueType());
isQualified = dtlsCheckData.get(0).getIsQualified();
valueTypeCode = dtlsCheckData.get(0).getValueTypeCode();
} else {
isQualified = 4;
valueTypeCode = "";
}
//电压下百分比给百分比直接算 电流是是下百分比给的是幅值要转换算
List<DetectionData> integerBooleanA = harmRangeComparison(isQualified, valueTypeCode, new ArrayList<>(), type, TYPE_A, sourceIssue, dataRule, devHarmMap.get(TYPE_A), fData, num);
List<DetectionData> integerBooleanB = harmRangeComparison(isQualified, valueTypeCode, new ArrayList<>(), type, TYPE_B, sourceIssue, dataRule, devHarmMap.get(TYPE_B), fData, num);
List<DetectionData> integerBooleanC = harmRangeComparison(isQualified, valueTypeCode, new ArrayList<>(), type, TYPE_C, sourceIssue, dataRule, devHarmMap.get(TYPE_C), fData, num);
harmonicResult.setDataType("avg");
reflectHarmonic("a", integerBooleanA, harmonicResult, num);
reflectHarmonic("b", integerBooleanB, harmonicResult, num);
reflectHarmonic("c", integerBooleanC, harmonicResult, num);
List<DetectionData> list = new ArrayList<>();
list.addAll(integerBooleanA.stream().distinct().collect(Collectors.toList()));
list.addAll(integerBooleanB.stream().distinct().collect(Collectors.toList()));
list.addAll(integerBooleanC.stream().distinct().collect(Collectors.toList()));
harmonicResult.setResultFlag(setResultFlag(list));
harmonicResultList.add(harmonicResult);
}
}
}
if (CollUtil.isNotEmpty(info)) {
detectionDataDealService.acceptAdNonResult(info, code);
List<Integer> resultFlag = info.stream().filter(x -> 4 != x.getResultFlag()).map(AdNonHarmonicResult::getResultFlag).distinct().collect(Collectors.toList());
return getInteger(resultFlag);
}
if (CollUtil.isNotEmpty(harmonicResultList)) {
detectionDataDealService.acceptAdResult(harmonicResultList, code);
}
return 4;
}
@@ -250,6 +373,7 @@ public class DetectionServiceImpl {
List<AdNonHarmonicResult> info = new ArrayList<>();
List<String> devValueTypeList = sourceIssue.getDevValueTypeList();
for (String s : devValueTypeList) {
// 根据数据处理规则取值。key为相别value为值列表
Map<String, List<Double>> map = devListMap(dev, dataRule, s.split("\\$")[1]);
Double fData = 1.0;
if (U.equals(type)) {
@@ -269,10 +393,14 @@ public class DetectionServiceImpl {
result.setSort(sourceIssue.getIndex());
result.setDataType("avg");
List<PqErrSysDtls> pqErrSysDtls = new ArrayList<>();
Integer isQualified = 4;
String valueTypeCode = "";
if (CollUtil.isNotEmpty(errDtlsCheckData)) {
List<ErrDtlsCheckDataVO> dtlsCheckData = errDtlsCheckData.stream().filter(x -> x.getValueTypeCode().equals(s.split("\\$")[1])).collect(Collectors.toList());
if (CollUtil.isNotEmpty(dtlsCheckData)) {
result.setAdType(dtlsCheckData.get(0).getValueType());
isQualified = dtlsCheckData.get(0).getIsQualified();
valueTypeCode = dtlsCheckData.get(0).getValueTypeCode();
if (CollUtil.isNotEmpty(dtlsCheckData.get(0).getErrSysDtls())) {
pqErrSysDtls = dtlsCheckData.get(0).getErrSysDtls();
}
@@ -280,7 +408,7 @@ public class DetectionServiceImpl {
if (map.containsKey(TYPE_T)) {
List<ErrDtlsCheckDataVO> checkDataT = dtlsCheckData.stream().filter(x -> TYPE_T.equals(x.getPhase())).collect(Collectors.toList());
if (CollUtil.isNotEmpty(checkDataT)) {
DetectionData t = rangeComparisonList(map.get(TYPE_T), pqErrSysDtls, fData, checkDataT.get(0).getValue(), dataRule);
DetectionData t = rangeComparisonList(map.get(TYPE_T), isQualified, valueTypeCode, pqErrSysDtls, fData, checkDataT.get(0).getValue(), dataRule);
result.setTValue(JSON.toJSONString(t));
result.setResultFlag(t.getIsData());
}
@@ -289,19 +417,19 @@ public class DetectionServiceImpl {
//取出源所对应的相别信息
List<ErrDtlsCheckDataVO> checkDataA = dtlsCheckData.stream().filter(x -> TYPE_A.equals(x.getPhase())).collect(Collectors.toList());
if (CollUtil.isNotEmpty(checkDataA)) {
DetectionData a = rangeComparisonList(map.get(TYPE_A), pqErrSysDtls, fData, checkDataA.get(0).getValue(), dataRule);
DetectionData a = rangeComparisonList(map.get(TYPE_A), isQualified, valueTypeCode, pqErrSysDtls, fData, checkDataA.get(0).getValue(), dataRule);
resultFlag.add(a);
result.setAValue(JSON.toJSONString(a));
}
List<ErrDtlsCheckDataVO> checkDataB = dtlsCheckData.stream().filter(x -> TYPE_B.equals(x.getPhase())).collect(Collectors.toList());
if (CollUtil.isNotEmpty(checkDataB)) {
DetectionData b = rangeComparisonList(map.get(TYPE_B), pqErrSysDtls, fData, checkDataB.get(0).getValue(), dataRule);
DetectionData b = rangeComparisonList(map.get(TYPE_B), isQualified, valueTypeCode, pqErrSysDtls, fData, checkDataB.get(0).getValue(), dataRule);
resultFlag.add(b);
result.setBValue(JSON.toJSONString(b));
}
List<ErrDtlsCheckDataVO> checkDataC = dtlsCheckData.stream().filter(x -> TYPE_C.equals(x.getPhase())).collect(Collectors.toList());
if (CollUtil.isNotEmpty(checkDataC)) {
DetectionData c = rangeComparisonList(map.get(TYPE_C), pqErrSysDtls, fData, checkDataC.get(0).getValue(), dataRule);
DetectionData c = rangeComparisonList(map.get(TYPE_C), isQualified, valueTypeCode, pqErrSysDtls, fData, checkDataC.get(0).getValue(), dataRule);
resultFlag.add(c);
result.setCValue(JSON.toJSONString(c));
}
@@ -312,7 +440,7 @@ public class DetectionServiceImpl {
}
if (CollUtil.isNotEmpty(info)) {
detectionDataDealService.acceptAdNonResult(info, code);
List<Integer> resultFlag = info.stream().filter(x -> 4 != x.getResultFlag()).map(AdNonHarmonicResult::getResultFlag).distinct().collect(Collectors.toList());
List<Integer> resultFlag = info.stream().map(AdNonHarmonicResult::getResultFlag).distinct().collect(Collectors.toList());
return getInteger(resultFlag);
}
return 4;
@@ -336,45 +464,66 @@ public class DetectionServiceImpl {
SourceIssue sourceIssue,
DictDataEnum dataRule,
Integer num) {
Map<String, Map<Double, List<Double>>> devMap = devHarmListMap(dev, sourceIssue, dataRule, num);
Double fData = 1.0;
String fundCode = "";
String harmCode = "";
if (U.equals(type)) {
fData = sourceIssue.getFUn();
fundCode = DetectionCodeEnum.U1.getCode();
if (num == 1) {
harmCode = DetectionCodeEnum.SV_1_49.getCode();
} else {
harmCode = DetectionCodeEnum.V2_50.getCode();
}
}
if (I.equals(type)) {
fData = sourceIssue.getFIn();
fundCode = DetectionCodeEnum.I1.getCode();
;
if (num == 1) {
harmCode = DetectionCodeEnum.SI_1_49.getCode();
} else {
harmCode = DetectionCodeEnum.I2_50.getCode();
}
}
if (P.equals(type)) {
fData = sourceIssue.getFIn() * sourceIssue.getFUn() * 0.01;
harmCode = DetectionCodeEnum.P2_50.getCode();
}
AdHarmonicResult harmonicResult = new AdHarmonicResult();
String[] split = dev.get(0).getId().split("_");
String devID = devIdMapComm.get(split[0]);
harmonicResult.setMonitorId(devID + "_" + split[1]);
harmonicResult.setScriptId(sourceIssue.getScriptId());
harmonicResult.setSort(sourceIssue.getIndex());
List<PqErrSysDtls> pqErrSysDtls = new ArrayList<>();
if (CollUtil.isNotEmpty(errDtlsCheckData)) {
harmonicResult.setAdType(errDtlsCheckData.get(0).getValueType());
if (CollUtil.isNotEmpty(errDtlsCheckData.get(0).getErrSysDtls())) {
pqErrSysDtls = errDtlsCheckData.get(0).getErrSysDtls();
Map<String, Map<Double, List<Double>>> devMap = devHarmListMap(dev, sourceIssue, dataRule, fundCode, harmCode, num);
if (CollUtil.isNotEmpty(devMap)) {
AdHarmonicResult harmonicResult = new AdHarmonicResult();
String[] split = dev.get(0).getId().split("_");
String devID = devIdMapComm.get(split[0]);
harmonicResult.setMonitorId(devID + "_" + split[1]);
harmonicResult.setScriptId(sourceIssue.getScriptId());
harmonicResult.setSort(sourceIssue.getIndex());
List<PqErrSysDtls> pqErrSysDtls = new ArrayList<>();
Integer isQualified = 4;
String valueTypeCode = "";
if (CollUtil.isNotEmpty(errDtlsCheckData)) {
harmonicResult.setAdType(errDtlsCheckData.get(0).getValueType());
isQualified = errDtlsCheckData.get(0).getIsQualified();
valueTypeCode = errDtlsCheckData.get(0).getValueTypeCode();
if (CollUtil.isNotEmpty(errDtlsCheckData.get(0).getErrSysDtls())) {
pqErrSysDtls = errDtlsCheckData.get(0).getErrSysDtls();
}
}
List<DetectionData> integerBooleanA = harmRangeComparison(isQualified, valueTypeCode, pqErrSysDtls, type, TYPE_A, sourceIssue, dataRule, devMap.get(TYPE_A), fData, num);
List<DetectionData> integerBooleanB = harmRangeComparison(isQualified, valueTypeCode, pqErrSysDtls, type, TYPE_B, sourceIssue, dataRule, devMap.get(TYPE_B), fData, num);
List<DetectionData> integerBooleanC = harmRangeComparison(isQualified, valueTypeCode, pqErrSysDtls, type, TYPE_C, sourceIssue, dataRule, devMap.get(TYPE_C), fData, num);
harmonicResult.setDataType("avg");
reflectHarmonic("a", integerBooleanA, harmonicResult, num);
reflectHarmonic("b", integerBooleanB, harmonicResult, num);
reflectHarmonic("c", integerBooleanC, harmonicResult, num);
List<DetectionData> list = new ArrayList<>();
list.addAll(integerBooleanA.stream().filter(x -> 1 != x.getNum()).distinct().collect(Collectors.toList()));
list.addAll(integerBooleanB.stream().filter(x -> 1 != x.getNum()).distinct().collect(Collectors.toList()));
list.addAll(integerBooleanC.stream().filter(x -> 1 != x.getNum()).distinct().collect(Collectors.toList()));
harmonicResult.setResultFlag(setResultFlag(list));
return harmonicResult;
}
List<DetectionData> integerBooleanA = harmRangeComparison(pqErrSysDtls, type, TYPE_A, sourceIssue, dataRule, devMap.get(TYPE_A), fData, num);
List<DetectionData> integerBooleanB = harmRangeComparison(pqErrSysDtls, type, TYPE_B, sourceIssue, dataRule, devMap.get(TYPE_B), fData, num);
List<DetectionData> integerBooleanC = harmRangeComparison(pqErrSysDtls, type, TYPE_C, sourceIssue, dataRule, devMap.get(TYPE_C), fData, num);
harmonicResult.setDataType("avg");
reflectHarmonic("a", integerBooleanA, harmonicResult, num);
reflectHarmonic("b", integerBooleanB, harmonicResult, num);
reflectHarmonic("c", integerBooleanC, harmonicResult, num);
List<DetectionData> list = new ArrayList<>();
list.addAll(integerBooleanA.stream().distinct().collect(Collectors.toList()));
list.addAll(integerBooleanB.stream().distinct().collect(Collectors.toList()));
list.addAll(integerBooleanC.stream().distinct().collect(Collectors.toList()));
harmonicResult.setResultFlag(setResultFlag(list));
return harmonicResult;
return null;
}
@@ -396,61 +545,68 @@ public class DetectionServiceImpl {
DictDataEnum dataRule,
String code) {
List<PqScriptCheckData> checkData = pqScriptCheckDataService.list(new MPJLambdaWrapper<PqScriptCheckData>()
.eq(PqScriptCheckData::getIndex, sourceIssue.getIndex())
.eq(PqScriptCheckData::getScriptIndex, sourceIssue.getIndex())
.eq(PqScriptCheckData::getScriptId, sourceIssue.getScriptId())
);
Map<String, List<Double>> map = devListMap(dev, dataRule, code);
Double fData = 1.0;
if (U.equals(type)) {
fData = sourceIssue.getFUn();
}
if (I.equals(type)) {
fData = sourceIssue.getFIn();
}
AdNonHarmonicResult result = new AdNonHarmonicResult();
String[] split = dev.get(0).getId().split("_");
String devID = devIdMapComm.get(split[0]);
result.setMonitorId(devID + "_" + split[1]);
result.setScriptId(sourceIssue.getScriptId());
result.setSort(sourceIssue.getIndex());
List<PqErrSysDtls> pqErrSysDtls = new ArrayList<>();
if (CollUtil.isNotEmpty(errDtlsCheckData)) {
result.setAdType(errDtlsCheckData.get(0).getValueType());
if (CollUtil.isNotEmpty(errDtlsCheckData.get(0).getErrSysDtls())) {
pqErrSysDtls = errDtlsCheckData.get(0).getErrSysDtls();
if (CollUtil.isNotEmpty(map)) {
Double fData = 1.0;
if (U.equals(type)) {
fData = sourceIssue.getFUn();
}
if (I.equals(type)) {
fData = sourceIssue.getFIn();
}
AdNonHarmonicResult result = new AdNonHarmonicResult();
String[] split = dev.get(0).getId().split("_");
String devID = devIdMapComm.get(split[0]);
result.setMonitorId(devID + "_" + split[1]);
result.setScriptId(sourceIssue.getScriptId());
result.setSort(sourceIssue.getIndex());
List<PqErrSysDtls> pqErrSysDtls = new ArrayList<>();
Integer isQualified = 4;
String valueTypeCode = "";
if (CollUtil.isNotEmpty(errDtlsCheckData)) {
result.setAdType(errDtlsCheckData.get(0).getValueType());
isQualified = errDtlsCheckData.get(0).getIsQualified();
valueTypeCode = errDtlsCheckData.get(0).getValueTypeCode();
if (CollUtil.isNotEmpty(errDtlsCheckData.get(0).getErrSysDtls())) {
pqErrSysDtls = errDtlsCheckData.get(0).getErrSysDtls();
}
}
result.setDataType("avg");
if (StrUtil.isBlank(type)) {
//取出源所对应的相别信息
List<PqScriptCheckData> channelTypeAList = checkData.stream()
.filter(x -> TYPE_A.equals(x.getPhase()))
.collect(Collectors.toList());
DetectionData a = rangeComparisonList(map.get(TYPE_A), isQualified, valueTypeCode, pqErrSysDtls, fData, channelTypeAList.get(0).getValue(), dataRule);
result.setAValue(JSON.toJSONString(a));
List<PqScriptCheckData> channelTypeBList = checkData.stream()
.filter(x -> TYPE_B.equals(x.getPhase()))
.collect(Collectors.toList());
DetectionData b = rangeComparisonList(map.get(TYPE_B), isQualified, valueTypeCode, pqErrSysDtls, fData, channelTypeBList.get(0).getValue(), dataRule);
result.setBValue(JSON.toJSONString(b));
List<PqScriptCheckData> channelTypeCList = checkData.stream()
.filter(x -> TYPE_C.equals(x.getPhase()))
.collect(Collectors.toList());
DetectionData c = rangeComparisonList(map.get(TYPE_C), isQualified, valueTypeCode, pqErrSysDtls, fData, channelTypeCList.get(0).getValue(), dataRule);
result.setCValue(JSON.toJSONString(c));
result.setResultFlag(setResultFlag(Arrays.asList(a, b, c)));
} else {
List<PqScriptCheckData> channelTypeBList = checkData.stream()
.filter(x -> TYPE_T.equals(x.getPhase()))
.collect(Collectors.toList());
DetectionData t = rangeComparisonList(map.get(TYPE_B), isQualified, valueTypeCode, pqErrSysDtls, fData, channelTypeBList.get(0).getValue(), dataRule);
result.setTValue(JSON.toJSONString(t));
result.setResultFlag(setResultFlag(Arrays.asList(t)));
}
return result;
}
result.setDataType("avg");
if (StrUtil.isBlank(type)) {
//取出源所对应的相别信息
List<PqScriptCheckData> channelTypeAList = checkData.stream()
.filter(x -> TYPE_A.equals(x.getPhase()))
.collect(Collectors.toList());
DetectionData a = rangeComparisonList(map.get(TYPE_A), pqErrSysDtls, fData, channelTypeAList.get(0).getValue(), dataRule);
result.setAValue(JSON.toJSONString(a));
List<PqScriptCheckData> channelTypeBList = checkData.stream()
.filter(x -> TYPE_B.equals(x.getPhase()))
.collect(Collectors.toList());
DetectionData b = rangeComparisonList(map.get(TYPE_B), pqErrSysDtls, fData, channelTypeBList.get(0).getValue(), dataRule);
result.setBValue(JSON.toJSONString(b));
List<PqScriptCheckData> channelTypeCList = checkData.stream()
.filter(x -> TYPE_C.equals(x.getPhase()))
.collect(Collectors.toList());
DetectionData c = rangeComparisonList(map.get(TYPE_C), pqErrSysDtls, fData, channelTypeCList.get(0).getValue(), dataRule);
result.setCValue(JSON.toJSONString(c));
result.setResultFlag(setResultFlag(Arrays.asList(a, b, c)));
} else {
List<PqScriptCheckData> channelTypeBList = checkData.stream()
.filter(x -> TYPE_T.equals(x.getPhase()))
.collect(Collectors.toList());
DetectionData t = rangeComparisonList(map.get(TYPE_B), pqErrSysDtls, fData, channelTypeBList.get(0).getValue(), dataRule);
result.setTValue(JSON.toJSONString(t));
result.setResultFlag(setResultFlag(Arrays.asList(t)));
}
return result;
return null;
}
@@ -483,7 +639,7 @@ public class DetectionServiceImpl {
AdNonHarmonicResult magResult = voltageResult(dev.get(0).getId(), devIdMapComm, sourceIssue, dataRule, mag, magErrList, sourceIssue.getFUn(), MAG);
AdNonHarmonicResult durResult = voltageResult(dev.get(0).getId(), devIdMapComm, sourceIssue, dataRule, dur, durErrList, sourceIssue.getFFreq(), DUR);
detectionDataDealService.acceptAdNonResult(Arrays.asList(magResult, durResult), code);
List<Integer> numbers = Arrays.asList(magResult.getResultFlag(), durResult.getResultFlag()).stream().filter(x -> 4 != x).distinct().collect(Collectors.toList());
List<Integer> numbers = Arrays.asList(magResult.getResultFlag(), durResult.getResultFlag()).stream().distinct().collect(Collectors.toList());
return getInteger(numbers);
}
@@ -517,8 +673,12 @@ public class DetectionServiceImpl {
result.setSort(sourceIssue.getIndex());
result.setDataType("avg");
List<PqErrSysDtls> magErrList = new ArrayList<>();
Integer isQualified = 4;
String valueTypeCode = "";
if (CollUtil.isNotEmpty(errDtlsCheckData)) {
result.setAdType(errDtlsCheckData.get(0).getValueType());
isQualified = errDtlsCheckData.get(0).getIsQualified();
valueTypeCode = errDtlsCheckData.get(0).getValueTypeCode();
if (CollUtil.isNotEmpty(errDtlsCheckData.get(0).getErrSysDtls())) {
magErrList = errDtlsCheckData.get(0).getErrSysDtls();
}
@@ -527,53 +687,66 @@ public class DetectionServiceImpl {
List<SourceIssue.ChannelListDTO> channelTypeAList = sourceIssue.getChannelList().stream()
.filter(x -> ("Ua").equals(x.getChannelType()))
.collect(Collectors.toList());
DetectionData a = setDetectionData(dataRule, mag, fData, dur, magErrList, channelTypeAList, TYPE_A);
DetectionData a = setDetectionData(isQualified, valueTypeCode, dataRule, mag, fData, dur, magErrList, channelTypeAList, TYPE_A);
result.setAValue(JSON.toJSONString(a));
List<SourceIssue.ChannelListDTO> channelTypeBList = sourceIssue.getChannelList().stream()
.filter(x -> ("Ub").equals(x.getChannelType()))
.collect(Collectors.toList());
DetectionData b = setDetectionData(dataRule, mag, fData, dur, magErrList, channelTypeBList, TYPE_B);
DetectionData b = setDetectionData(isQualified, valueTypeCode, dataRule, mag, fData, dur, magErrList, channelTypeBList, TYPE_B);
result.setBValue(JSON.toJSONString(b));
List<SourceIssue.ChannelListDTO> channelTypeCList = sourceIssue.getChannelList().stream()
.filter(x -> ("Uc").equals(x.getChannelType()))
.collect(Collectors.toList());
DetectionData c = setDetectionData(dataRule, mag, fData, dur, magErrList, channelTypeCList, TYPE_C);
DetectionData c = setDetectionData(isQualified, valueTypeCode, dataRule, mag, fData, dur, magErrList, channelTypeCList, TYPE_C);
result.setCValue(JSON.toJSONString(c));
result.setResultFlag(setResultFlag(Arrays.asList(a, b, c)));
return result;
}
private DetectionData setDetectionData(DictDataEnum dataRule, Map<String, List<Double>> mag, Double fData, String dur, List<PqErrSysDtls> magErrList, List<SourceIssue.ChannelListDTO> channelTypeCList, String typeC) {
private DetectionData setDetectionData(Integer isQualified, String valueTypeCode, DictDataEnum dataRule, Map<String, List<Double>> mag, Double fData, String dur, List<PqErrSysDtls> magErrList, List<SourceIssue.ChannelListDTO> channelTypeCList, String typeC) {
DetectionData c;
if (DUR.equals(dur)) {
c = rangeDURComparisonList(mag.get(typeC), magErrList, fData, channelTypeCList.get(0).getDipData().getRetainTime(), dataRule);
c = rangeDURComparisonList(mag.get(typeC), isQualified, valueTypeCode, magErrList, fData, channelTypeCList.get(0).getDipData().getRetainTime(), dataRule);
} else {
c = rangeComparisonList(mag.get(typeC), magErrList, fData, channelTypeCList.get(0).getDipData().getFTransValue(), dataRule);
List<Double> ampData = mag.get(typeC).stream()
.filter(x -> ObjectUtil.isNotNull(x))
.map(x -> x * channelTypeCList.get(0).getFAmp() * 0.01)
.collect(Collectors.toList());
c = rangeComparisonList(ampData, isQualified, valueTypeCode, magErrList, fData, channelTypeCList.get(0).getDipData().getFTransValue(), dataRule);
}
return c;
}
private Integer setResultFlag(List<DetectionData> numbers) {
List<Integer> isData = numbers.stream().filter(x -> ObjectUtil.isNotNull(x.getData())).filter(x -> 4 != x.getIsData()).map(DetectionData::getIsData).distinct().collect(Collectors.toList());
List<Integer> isData = numbers.stream().filter(x -> ObjectUtil.isNotNull(x.getData())).map(DetectionData::getIsData).distinct().collect(Collectors.toList());
return getInteger(isData);
}
private static Integer getInteger(List<Integer> isData) {
if (CollUtil.isNotEmpty(isData)) {
if (isData.size() > 1) {
if (isData.contains(2)) {
return 2;
List<Integer> isQualified = isData.stream().filter(x -> 1 == x || 2 == x).collect(Collectors.toList());
if (CollUtil.isNotEmpty(isQualified)) {
if (isQualified.size() > 1) {
if (isQualified.contains(2)) {
return 2;
}
}
return isQualified.get(0);
} else {
if (isData.contains(4)) {
return 4;
}
if (isData.contains(5)) {
return 5;
}
}
return isData.get(0);
} else {
return 4;
}
return 4;
}
/**
@@ -669,7 +842,9 @@ public class DetectionServiceImpl {
* @param fData
* @return
*/
public List<DetectionData> harmRangeComparison(List<PqErrSysDtls> pqErrSysDtls,
public List<DetectionData> harmRangeComparison(Integer isQualified,
String valueTypeCode,
List<PqErrSysDtls> pqErrSysDtls,
String type,
String phase,
SourceIssue sourceIssue,
@@ -681,7 +856,7 @@ public class DetectionServiceImpl {
Map<Double, Double> issueHarmMap;
if (P.equals(type)) {
List<PqScriptCheckData> checkData = pqScriptCheckDataService.list(new MPJLambdaWrapper<PqScriptCheckData>()
.eq(PqScriptCheckData::getIndex, sourceIssue.getIndex())
.eq(PqScriptCheckData::getScriptIndex, sourceIssue.getIndex())
.eq(PqScriptCheckData::getPhase, phase)
.eq(PqScriptCheckData::getScriptId, sourceIssue.getScriptId())
);
@@ -689,8 +864,10 @@ public class DetectionServiceImpl {
} else {
Double percent;
if (I.equals(type)) {
//电流是百分比转换成赋值算的
percent = fData * 0.01;
} else {
//电压是百分比算的
percent = 1.0;
}
if (1 == num) {
@@ -719,25 +896,30 @@ public class DetectionServiceImpl {
errSysDtlMap.put(key, null);
}
});
devMap.forEach((harm, harmDataList) -> {
PqErrSysDtls errSysDtl = errSysDtlMap.get(harm);
DetectionData data = new DetectionData();
data.setIsData(4);
data.setNum(harm);
data.setData(harmDataList.get(0));
Double v = issueHarmMap.get(harm);
data.setResultData(v);
if (ObjectUtil.isNotNull(errSysDtl)) {
PqErrSysDtls errSys = BeanUtil.copyProperties(errSysDtl, PqErrSysDtls.class);
errSys.setMaxErrorValue(maxErrorMultiply(errSys.getMaxErrorValue(), fData, issueHarmMap.get(harm), errSys.getErrorValueType()));
NumberFormat nf = NumberFormat.getInstance();
nf.setMaximumFractionDigits(6);
nf.setGroupingUsed(false);
data.setRadius(nf.format(-errSys.getMaxErrorValue()) + "~" + nf.format(errSys.getMaxErrorValue()));
setDetection(dataRule, harmDataList, errSys, data, v);
}
info.add(data);
});
if (CollUtil.isNotEmpty(devMap)) {
devMap.forEach((harm, harmDataList) -> {
PqErrSysDtls errSysDtl = errSysDtlMap.get(harm);
DetectionData data = new DetectionData();
data.setIsData(isQualified);
data.setNum(harm);
if (CollUtil.isNotEmpty(harmDataList)) {
data.setData(harmDataList.get(0));
}
Double v = issueHarmMap.get(harm);
data.setResultData(v);
if (ObjectUtil.isNotNull(errSysDtl)) {
PqErrSysDtls errSys = BeanUtil.copyProperties(errSysDtl, PqErrSysDtls.class);
errSys.setMaxErrorValue(maxErrorMultiply(errSys.getMaxErrorValue(), fData, issueHarmMap.get(harm), errSys.getErrorValueType()));
NumberFormat nf = NumberFormat.getInstance();
nf.setMaximumFractionDigits(6);
nf.setGroupingUsed(false);
data.setUnit(unit(valueTypeCode, errSysDtl.getErrorValueType()));
data.setRadius(nf.format(-errSys.getMaxErrorValue()) + "~" + nf.format(errSys.getMaxErrorValue()));
setDetection(dataRule, harmDataList, errSys, data, v);
}
info.add(data);
});
}
return info;
}
@@ -752,11 +934,23 @@ public class DetectionServiceImpl {
* @Date: 2024/12/29 18:10
*/
private void setDetection(DictDataEnum dataRule, List<Double> harmDataList, PqErrSysDtls errSysDtl, DetectionData data, Double v) {
List<Double> qualifiedList = harmDataList.stream()
.filter(x -> x > 0 && NumberUtil.isIn(devSubtractChannelData(x, v, errSysDtl.getErrorValueType()),
BigDecimal.valueOf(-errSysDtl.getMaxErrorValue()),
BigDecimal.valueOf(errSysDtl.getMaxErrorValue()))).collect(Collectors.toList());
isData(dataRule, harmDataList, data, qualifiedList);
if (CollUtil.isNotEmpty(harmDataList)) {
// 存放合格的数据
List<Double> qualifiedList = harmDataList.stream()
.filter(x -> v == 0 ? NumberUtil.isIn(devSubtractChannelData(x, v, errSysDtl.getErrorValueType()),
BigDecimal.valueOf(-errSysDtl.getMaxErrorValue()),
BigDecimal.valueOf(errSysDtl.getMaxErrorValue()))
:
x != 0 && NumberUtil.isIn(devSubtractChannelData(x, v, errSysDtl.getErrorValueType()),
BigDecimal.valueOf(-errSysDtl.getMaxErrorValue()),
BigDecimal.valueOf(errSysDtl.getMaxErrorValue()))).collect(Collectors.toList());
if (CollUtil.isNotEmpty(qualifiedList)) {
data.setErrorData(devSubtractChannelData(qualifiedList.get(0), v, errSysDtl.getErrorValueType()));
} else {
data.setErrorData(devSubtractChannelData(harmDataList.get(0), v, errSysDtl.getErrorValueType()));
}
isData(dataRule, harmDataList, data, qualifiedList);
}
}
private void isData(DictDataEnum dataRule, List<Double> harmDataList, DetectionData data, List<Double> qualifiedList) {
@@ -788,31 +982,42 @@ public class DetectionServiceImpl {
/**
* @param dev 原始数据
* @param sourceIssue
* @param dataRule
* @param num
* @param sourceIssue 源下发参数
* @param dataRule 数据处理原则
* @param fundCode 装置下发基波code
* @param harmCode 装置下发谐波信息
* @param num 区分谐波还是间谐波1谐波2间谐波
* @return
*/
public Map<String, Map<Double, List<Double>>> devHarmListMap(List<DevData> dev, SourceIssue sourceIssue, DictDataEnum dataRule, Integer num) {
public Map<String, Map<Double, List<Double>>> devHarmListMap(List<DevData> dev,
SourceIssue sourceIssue,
DictDataEnum dataRule,
String fundCode,
String harmCode,
Integer num) {
Map<String, Map<Double, List<Double>>> map = new HashMap<>(3);
List<Double> harmNum = new ArrayList<>();
harmNum.add(1.0);
if (1 == num) {
harmNum.addAll(sourceIssue.getChannelList().stream()
.flatMap(x -> x.getInharmList().stream().map(f -> f.getInharm()))
.sorted().distinct().collect(Collectors.toList()));
} else {
harmNum.add(1.0);
harmNum.addAll(sourceIssue.getChannelList().stream()
.flatMap(x -> x.getHarmList().stream().map(f -> f.getHarm()))
.sorted().distinct().collect(Collectors.toList()));
}
for (DevData devData : dev) {
Optional<DevData.SqlDataDTO> first = devData.getSqlData().stream().collect(Collectors.toList()).stream().findFirst();
List<DevData.SqlDataDTO> sqlDataDTOS = devData.getSqlData();
Optional<DevData.SqlDataDTO> first = Optional.empty();
if (CollUtil.isNotEmpty(sqlDataDTOS)) {
first = sqlDataDTOS.stream().filter(x -> x.getDesc().equals(fundCode)).collect(Collectors.toList()).stream().findFirst();
}
DevData.SqlDataDTO fund = null;
if (first.isPresent()) {
fund = devData.getSqlData().stream().collect(Collectors.toList()).stream().findFirst().get();
fund = first.get();
}
List<DevData.SqlDataHarmDTO> harmList = devData.getSqlDataHarm().stream().collect(Collectors.toList());
List<DevData.SqlDataHarmDTO> harmList = devData.getSqlDataHarm().stream().filter(x -> x.getDesc().equals(harmCode)).collect(Collectors.toList());
if (CollUtil.isNotEmpty(harmList)) {
DevData.SqlDataHarmDTO harm = harmList.get(0);
if (ObjectUtil.isNotNull(fund)) {
@@ -873,9 +1078,9 @@ public class DetectionServiceImpl {
* @param dataRule 数据处理原则
* @returnd
*/
public DetectionData rangeComparisonList(List<Double> list, List<PqErrSysDtls> pqErrSysDtls, Double data, Double channelData, DictDataEnum dataRule) {
public DetectionData rangeComparisonList(List<Double> list, Integer isQualified, String valueTypeCode, List<PqErrSysDtls> pqErrSysDtls, Double data, Double channelData, DictDataEnum dataRule) {
DetectionData detectionData = new DetectionData();
detectionData.setIsData(4);
detectionData.setIsData(isQualified);
if (CollUtil.isNotEmpty(list)) {
detectionData.setData(list.get(0));
detectionData.setResultData(channelData);
@@ -891,6 +1096,7 @@ public class DetectionServiceImpl {
NumberFormat nf = NumberFormat.getInstance();
nf.setMaximumFractionDigits(6);
nf.setGroupingUsed(false);
detectionData.setUnit(unit(valueTypeCode, errSysDtl.getErrorValueType()));
errSysDtl.setMaxErrorValue(maxErrorMultiply(errSysDtl.getMaxErrorValue(), data, channelData, errSysDtl.getErrorValueType()));
detectionData.setRadius(nf.format(-errSysDtl.getMaxErrorValue()) + "~" + nf.format(errSysDtl.getMaxErrorValue()));
setDetection(dataRule, list, errSysDtl, detectionData, channelData);
@@ -899,9 +1105,9 @@ public class DetectionServiceImpl {
return detectionData;
}
public DetectionData rangeDURComparisonList(List<Double> list, List<PqErrSysDtls> pqErrSysDtls, Double data, Double channelData, DictDataEnum dataRule) {
public DetectionData rangeDURComparisonList(List<Double> list, Integer isQualified, String valueTypeCode, List<PqErrSysDtls> pqErrSysDtls, Double data, Double channelData, DictDataEnum dataRule) {
DetectionData detectionData = new DetectionData();
detectionData.setIsData(4);
detectionData.setIsData(isQualified);
if (CollUtil.isNotEmpty(list)) {
detectionData.setData(list.get(0));
detectionData.setResultData(BigDecimal.valueOf(1.0 / data).doubleValue() * channelData);
@@ -918,6 +1124,7 @@ public class DetectionServiceImpl {
NumberFormat nf = NumberFormat.getInstance();
nf.setMaximumFractionDigits(6);
nf.setGroupingUsed(false);
detectionData.setUnit(unit(valueTypeCode, errSysDtl.getErrorValueType()));
detectionData.setRadius(nf.format(BigDecimal.valueOf(1.0 / data * (channelData - errSysDtl.getMaxErrorValue())))
+ "~" + nf.format(BigDecimal.valueOf(1.0 / data * (channelData + errSysDtl.getMaxErrorValue()))));
List<Double> qualifiedList = list.stream()
@@ -925,6 +1132,15 @@ public class DetectionServiceImpl {
BigDecimal.valueOf(1.0 / data * (channelData - errSysDtl.getMaxErrorValue())),
BigDecimal.valueOf(1.0 / data * (channelData + errSysDtl.getMaxErrorValue())))
).collect(Collectors.toList());
if (CollUtil.isNotEmpty(qualifiedList)) {
BigDecimal subtract = BigDecimal.valueOf(qualifiedList.get(0))
.subtract(BigDecimal.valueOf(1.0 / data * (channelData - errSysDtl.getMaxErrorValue())));
detectionData.setErrorData(subtract);
} else {
BigDecimal subtract = BigDecimal.valueOf(list.get(0))
.subtract(BigDecimal.valueOf(1.0 / data * (channelData - errSysDtl.getMaxErrorValue())));
detectionData.setErrorData(subtract);
}
isData(dataRule, qualifiedList, detectionData, qualifiedList);
}
}
@@ -981,20 +1197,21 @@ public class DetectionServiceImpl {
* @return
*/
public BigDecimal devSubtractChannelData(Double devData, Double channelData, Integer errorValueType) {
if (devData - channelData != 0) {
BigDecimal subtract = BigDecimal.valueOf(devData).subtract(BigDecimal.valueOf(channelData));
if (subtract.doubleValue() != 0) {
switch (errorValueType) {
case 2:
//下发的谐波电压幅值,返回的是谐波电压含有率,拿(含有率值*基波 - 源下发对应谐波值幅值)/下发的幅值
return BigDecimal.valueOf(devData - channelData)
return subtract.multiply(BigDecimal.valueOf(100))
.divide(BigDecimal.valueOf(channelData), 4, RoundingMode.HALF_UP);
case 3:
//下发的谐波电压幅值,返回的是谐波电压含有率,拿(含有率值*基波 - 源下发对应谐波值幅值)/装置返回值
return BigDecimal.valueOf(devData - channelData)
return subtract.multiply(BigDecimal.valueOf(100))
.divide(BigDecimal.valueOf(devData), 4, RoundingMode.HALF_UP);
}
return BigDecimal.valueOf(devData - channelData);
return subtract;
}
return BigDecimal.valueOf(devData);
return BigDecimal.valueOf(0);
}
public BigDecimal divide(Double devData, Double channelData) {
@@ -1046,7 +1263,7 @@ public class DetectionServiceImpl {
.setScale(4, RoundingMode.HALF_UP).doubleValue();
case 2:
case 3:
return BigDecimal.valueOf(errorValue).multiply(BigDecimal.valueOf(harmData))
return BigDecimal.valueOf(errorValue).multiply(BigDecimal.valueOf(100))
.setScale(4, RoundingMode.HALF_UP).doubleValue();
default:
return errorValue;
@@ -1076,17 +1293,25 @@ public class DetectionServiceImpl {
Map<Double, List<Double>> integerListMap = map.get(type);
for (Double i : harmNum) {
if (integerListMap.containsKey(i)) {
if (i.equals(1.0)) {
if (i.equals(1.0) && num != 1) {
integerListMap.get(1.0).add(multiply(fund, fund));
} else {
double v = (num == 1 ? i : (i - num));
if (type.equals("A")) {
integerListMap.get(i).add(multiply(harm.getList().getA().get((int) (i - num)), fund));
if ((int) v < harm.getList().getA().size()) {
integerListMap.get(i).add(multiply(harm.getList().getA().get((int) v), fund));
}
}
if (type.equals("B")) {
integerListMap.get(i).add(multiply(harm.getList().getB().get((int) (i - num)), fund));
if ((int) v < harm.getList().getB().size()) {
integerListMap.get(i).add(multiply(harm.getList().getB().get((int) v), fund));
}
}
if (type.equals("C")) {
integerListMap.get(i).add(multiply(harm.getList().getC().get((int) (i - num)), fund));
if ((int) v < harm.getList().getC().size()) {
integerListMap.get(i).add(multiply(harm.getList().getC().get((int) v), fund));
}
}
}
}
@@ -1095,18 +1320,25 @@ public class DetectionServiceImpl {
Map<Double, List<Double>> integerListMap = new LinkedHashMap<>(5);
for (Double i : harmNum) {
List<Double> integerList = new ArrayList<>();
if (i.equals(1.0)) {
if (i.equals(1.0) && num != 1) {
integerList.add(multiply(fund, fund));
integerListMap.put(1.0, integerList);
} else {
double v = (num == 1 ? i : (i - num));
if (type.equals("A")) {
integerList.add(multiply(harm.getList().getA().get((int) (i - num)), fund));
if ((int) v < harm.getList().getA().size()) {
integerList.add(multiply(harm.getList().getA().get((int) v), fund));
}
}
if (type.equals("B")) {
integerList.add(multiply(harm.getList().getB().get((int) (i - num)), fund));
if ((int) v < harm.getList().getB().size()) {
integerList.add(multiply(harm.getList().getB().get((int) v), fund));
}
}
if (type.equals("C")) {
integerList.add(multiply(harm.getList().getC().get((int) (i - num)), fund));
if ((int) v < harm.getList().getC().size()) {
integerList.add(multiply(harm.getList().getC().get((int) v), fund));
}
}
integerListMap.put(i, integerList);
}

View File

@@ -11,34 +11,37 @@ import com.njcn.gather.detection.handler.SocketSourceResponseService;
import com.njcn.gather.detection.pojo.enums.DetectionResponseEnum;
import com.njcn.gather.detection.pojo.enums.SourceOperateCodeEnum;
import com.njcn.gather.detection.pojo.param.PreDetectionParam;
import com.njcn.gather.detection.pojo.param.SimulateDetectionParam;
import com.njcn.gather.detection.pojo.vo.SocketMsg;
import com.njcn.gather.detection.service.PreDetectionService;
import com.njcn.gather.detection.util.socket.CnSocketUtil;
import com.njcn.gather.detection.util.socket.FormalTestManager;
import com.njcn.gather.detection.util.socket.SocketManager;
import com.njcn.gather.detection.util.socket.WebServiceManager;
import com.njcn.gather.detection.util.socket.cilent.NettyClient;
import com.njcn.gather.detection.util.socket.cilent.NettySourceClientHandler;
import com.njcn.gather.device.pojo.enums.DevResponseEnum;
import com.njcn.gather.device.pojo.po.PqDev;
import com.njcn.gather.device.service.IPqDevService;
import com.njcn.gather.plan.pojo.po.AdPlan;
import com.njcn.gather.plan.pojo.po.AdPlanSource;
import com.njcn.gather.plan.service.IAdPlanService;
import com.njcn.gather.plan.service.IAdPlanSourceService;
import com.njcn.gather.script.pojo.param.PqScriptCheckDataParam;
import com.njcn.gather.script.pojo.param.PqScriptIssueParam;
import com.njcn.gather.script.pojo.po.SourceIssue;
import com.njcn.gather.script.service.IPqScriptCheckDataService;
import com.njcn.gather.script.service.IPqScriptDtlsService;
import com.njcn.gather.source.pojo.po.SourceInitialize;
import com.njcn.gather.source.service.IPqSourceService;
import com.njcn.gather.plan.pojo.po.AdPlan;
import com.njcn.gather.plan.pojo.po.AdPlanSource;
import com.njcn.gather.plan.service.IAdPlanService;
import com.njcn.gather.plan.service.IAdPlanSourceService;
import com.njcn.gather.system.dictionary.pojo.enums.DictDataEnum;
import com.njcn.gather.system.dictionary.service.IDictDataService;
import io.netty.channel.Channel;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import java.util.Comparator;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
@@ -46,10 +49,13 @@ import java.util.stream.Collectors;
@Service
@RequiredArgsConstructor
@Slf4j
public class PreDetectionServiceImpl implements PreDetectionService {
private final String source = "_Source";
private final String dev = "_Dev";
private final String stepTag = "&&";
private final String handlerSourceStr = "_Source";
private final IPqDevService iPqDevService;
private final IDictDataService dictDataService;
@@ -62,10 +68,10 @@ public class PreDetectionServiceImpl implements PreDetectionService {
private final SocketSourceResponseService socketSourceResponseService;
private final IPqScriptCheckDataService iPqScriptCheckDataService;
@Value("${socket.source.ip:192.168.1.136}")
@Value("${socket.source.ip:192.168.1.138}")
private String ip;
@Value("${socket.source.port:10086}")
@Value("${socket.source.port:61000}")
private Integer port;
private final SocketSourceResponseService sourceResponseService;
@@ -138,12 +144,11 @@ public class PreDetectionServiceImpl implements PreDetectionService {
//开始组装socket报文请求头
socketDevResponseService.initList(param);
socketSourceResponseService.initList(param);
SocketMsg<String> msg = new SocketMsg<>();
msg.setRequestId(SourceOperateCodeEnum.YJC_YTXJY.getValue());
msg.setOperateCode(SourceOperateCodeEnum.INIT_GATHER.getValue());
msg.setData(JSON.toJSONString(sourceParam));
NettyClient.socketClient(ip, port, param, JSON.toJSONString(msg), new NettySourceClientHandler(param, sourceResponseService));
SocketMsg<String> socketMsg = new SocketMsg<>();
socketMsg.setRequestId(SourceOperateCodeEnum.YJC_YTXJY.getValue());
socketMsg.setOperateCode(SourceOperateCodeEnum.INIT_GATHER.getValue());
socketMsg.setData(JSON.toJSONString(sourceParam));
NettyClient.socketClient(ip, port, param, JSON.toJSONString(socketMsg), new NettySourceClientHandler(param, sourceResponseService));
} else {
throw new BusinessException(DetectionResponseEnum.SOURCE_INFO_NOT);
}
@@ -152,13 +157,19 @@ public class PreDetectionServiceImpl implements PreDetectionService {
}
}
@Override
public boolean startTest(PreDetectionParam param) {
socketDevResponseService.initList(param);
NettyClient.socketClient(ip, port, param, "start\n", new NettySourceClientHandler(param, sourceResponseService));
return true;
private void sendYtxSocketSimulate(PreDetectionParam param) {
SourceInitialize sourceParam = pqSourceService.getSourceInitializeParam(param.getSourceId());
param.setSourceId(sourceParam.getSourceId());
WebServiceManager.addPreDetectionParam(param);
if (ObjectUtil.isNotNull(sourceParam)) {
SocketMsg<String> socketMsg = new SocketMsg<>();
socketMsg.setRequestId(SourceOperateCodeEnum.YJC_YTXJY.getValue());
socketMsg.setOperateCode(SourceOperateCodeEnum.INIT_GATHER.getValue());
socketMsg.setData(JSON.toJSONString(sourceParam));
NettyClient.socketClient(ip, port, param, JSON.toJSONString(socketMsg), new NettySourceClientHandler(param, sourceResponseService));
} else {
throw new BusinessException(DetectionResponseEnum.SOURCE_INFO_NOT);
}
}
@Override
@@ -170,6 +181,7 @@ public class PreDetectionServiceImpl implements PreDetectionService {
@Override
public boolean restartTemTest(PreDetectionParam param) {
FormalTestManager.stopFlag = false;
socketDevResponseService.initRestart();
List<SourceIssue> sourceIssueList = SocketManager.getSourceList();
if (CollUtil.isNotEmpty(sourceIssueList)) {
SourceIssue sourceIssues = SocketManager.getSourceList().get(0);
@@ -180,42 +192,132 @@ public class PreDetectionServiceImpl implements PreDetectionService {
SocketManager.sendMsg(param.getUserPageId() + source, JSON.toJSONString(xuMsg));
} else {
//TODO 是否最终检测完成需要推送给用户
PqScriptCheckDataParam checkDataParam=new PqScriptCheckDataParam();
PqScriptCheckDataParam checkDataParam = new PqScriptCheckDataParam();
checkDataParam.setScriptId(param.getScriptId());
checkDataParam.setIsValueTypeName(false);
List<String> valueType = iPqScriptCheckDataService.getValueType(checkDataParam);
iPqDevService.updateResult(param.getDevIds(), valueType,param.getCode());
iPqDevService.updateResult(param.getDevIds(), valueType, param.getCode(),param.getUserId());
CnSocketUtil.quitSend(param);
}
return true;
}
@Override
public void ytxCheckSimulate(SimulateDetectionParam param) {
PreDetectionParam preDetectionParam = new PreDetectionParam();
preDetectionParam.setSourceId(param.getSourceId());
preDetectionParam.setUserPageId(param.getUserPageId());
preDetectionParam.setSendWebMsg(true);
specialDealSimulate(preDetectionParam);
sendYtxSocketSimulate(preDetectionParam);
}
@Override
public void sendScript(SimulateDetectionParam param) {
Channel channel = SocketManager.getChannelByUserId(param.getUserPageId() + source);
if (Objects.isNull(channel) || !channel.isActive()) {
// 进行源通信连接
PreDetectionParam preDetectionParam = new PreDetectionParam();
preDetectionParam.setSourceId(param.getSourceId());
preDetectionParam.setUserPageId(param.getUserPageId());
preDetectionParam.setSendWebMsg(false);
this.sendYtxSocketSimulate(preDetectionParam);
}
//组装源控制脚本
PqScriptIssueParam issueParam = new PqScriptIssueParam();
issueParam.setSourceId(param.getSourceId());
issueParam.setScriptId(param.getScriptId());
issueParam.setType(1);
issueParam.setIsPhaseSequence(SourceOperateCodeEnum.SIMULATE_TEST.getValue());
List<SourceIssue> sourceIssues = pqScriptDtlsService.listSourceIssue(issueParam);
sourceIssues = sourceIssues.stream()
.filter(s -> s.getIndex().equals(param.getScriptIndex()))
.collect(Collectors.toList());
SourceIssue sourceIssue = sourceIssues.get(0);
List<String> comm = sourceIssue.getDevValueTypeList();
System.out.println("向装置下发的参数ddd>>>>>>>>" + comm);
SocketMsg<String> socketMsg = new SocketMsg<>();
socketMsg.setOperateCode(SourceOperateCodeEnum.OPER_GATHER.getValue());
socketMsg.setRequestId(SourceOperateCodeEnum.FORMAL_REAL.getValue() + stepTag + sourceIssue.getType());
socketMsg.setData(JSON.toJSONString(sourceIssues.get(0)));
SocketManager.sendMsg(param.getUserPageId() + handlerSourceStr, JSON.toJSONString(socketMsg));
}
@Override
public void closeTestSimulate(SimulateDetectionParam param) {
Channel channel = SocketManager.getChannelByUserId(param.getUserPageId() + source);
if (Objects.isNull(channel) || !channel.isActive()) {
throw new BusinessException(DetectionResponseEnum.SOURCE_NOT_CONNECT);
}
SourceInitialize sourceParam = pqSourceService.getSourceInitializeParam(param.getSourceId());
PreDetectionParam preDetectionParam = new PreDetectionParam();
preDetectionParam.setSourceId(sourceParam.getSourceId());
preDetectionParam.setUserPageId(param.getUserPageId());
CnSocketUtil.quitSendSource(preDetectionParam);
WebServiceManager.removePreDetectionParam();
}
/**
* 对重复发起或者异常发起的检测进行关闭源操作
*
* @param param
*/
private void specialDeal(PreDetectionParam param) {
Channel channel = SocketManager.getChannelByUserId(param.getUserPageId() + source);
Channel channelDev = SocketManager.getChannelByUserId(param.getUserPageId() + dev);
if (Objects.nonNull(channel) && channel.isActive()) {
System.out.println("进入关闭源。。//////");
System.out.println("发送关闭源指令。。。。。。。。");
CnSocketUtil.quitSendSource(param);
}
if (Objects.nonNull(channelDev) && channelDev.isActive()) {
System.out.println("发送关闭设备通讯指令。。。。。。。。");
CnSocketUtil.quitSend(param);
}
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
SocketManager.removeUser(param.getUserPageId() + source);
SocketManager.removeUser(param.getUserPageId() + dev);
try {
Thread.sleep(4000);
} catch (InterruptedException e) {
log.error(e.getMessage());
}
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
SocketManager.removeUser(param.getUserPageId() + source);
SocketManager.removeUser(param.getUserPageId() + dev);
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
log.error(e.getMessage());
}
}
/**
* 对重复发起或者异常发起的检测进行关闭源操作-模拟检测
*
* @param param
*/
private void specialDealSimulate(PreDetectionParam param) {
Channel channel = SocketManager.getChannelByUserId(param.getUserPageId() + source);
if (Objects.nonNull(channel) && channel.isActive()) {
System.out.println("发送关闭源指令。。。。。。。。");
CnSocketUtil.quitSendSource(param);
}
try {
Thread.sleep(4000);
} catch (InterruptedException e) {
log.error(e.getMessage());
}
SocketManager.removeUser(param.getUserPageId() + source);
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
log.error(e.getMessage());
}
}
@@ -223,10 +325,10 @@ public class PreDetectionServiceImpl implements PreDetectionService {
/**
* 校验
*/
private void commCheck(PreDetectionParam param){
private void commCheck(PreDetectionParam param) {
List<PqDev> pqDevList = iPqDevService.listByIds(param.getDevIds());
List<String> ipList = pqDevList.stream().map(PqDev::getIp).distinct().collect(Collectors.toList());
if(ipList.size()!=param.getDevIds().size()){
if (ipList.size() != param.getDevIds().size()) {
throw new BusinessException(DetectionResponseEnum.PLAN_DEV_IP_HAS);
}
}

View File

@@ -1,5 +1,6 @@
package com.njcn.gather.detection.util.socket;
import com.njcn.gather.detection.pojo.po.DevData;
import com.njcn.gather.device.pojo.vo.PreDetection;
import java.util.ArrayList;
@@ -33,7 +34,8 @@ public class FormalTestManager {
//用于存储所有测点的实时数据
public static List<DevData> realDataXiList = new ArrayList<>();
/**

View File

@@ -3,10 +3,7 @@ package com.njcn.gather.detection.util.socket;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.njcn.gather.detection.pojo.enums.SourceOperateCodeEnum;
import com.njcn.gather.detection.pojo.param.PreDetectionParam;
import com.njcn.gather.detection.pojo.vo.SocketDataMsg;
import com.njcn.gather.detection.pojo.vo.SocketMsg;
import java.util.Map;
@@ -19,9 +16,8 @@ import java.util.Map;
public class MsgUtil {
public static SocketDataMsg socketDataMsg(String textMsg){
return JSON.parseObject(textMsg,SocketDataMsg.class);
public static SocketDataMsg socketDataMsg(String textMsg) {
return JSON.parseObject(textMsg, SocketDataMsg.class);
}
/**
@@ -46,13 +42,12 @@ public class MsgUtil {
/**
*
* @param socketDataMsg
* @param devMap
* @param type 0.装置 1.监测点
* @param type 0.装置 1.监测点
* @return
*/
public static String msgToWebData(SocketDataMsg socketDataMsg, Map<String,String> devMap,Integer type){
public static String msgToWebData(SocketDataMsg socketDataMsg, Map<String, String> devMap, Integer type) {
String data = socketDataMsg.getData();
if (StrUtil.isNotBlank(data)) {
String[] parts = data.split("_");
@@ -60,17 +55,14 @@ public class MsgUtil {
String key = parts[0];
String newValue = devMap.get(key);
if (newValue != null) {
if(type == 0) {
if (type == 0) {
socketDataMsg.setData(newValue);
}else {
socketDataMsg.setData(newValue+"_"+parts[1]+"");
} else {
socketDataMsg.setData(newValue + "_" + parts[1] + "");
}
}
}
}
return JSON.toJSONString(socketDataMsg);
}
}

View File

@@ -19,7 +19,10 @@ import java.util.concurrent.CopyOnWriteArrayList;
*/
public class SocketManager {
// key为userIdxxx_Source、xxx_Devvalue为channel
private static final Map<String, Channel> socketSessions = new ConcurrentHashMap<>();
// key为userIdxxx_Source、xxx_Devvalue为group
private static final Map<String, NioEventLoopGroup> socketGroup = new ConcurrentHashMap<>();
public static void addUser(String userId, Channel channel) {

View File

@@ -0,0 +1,63 @@
package com.njcn.gather.detection.util.socket;
import com.njcn.gather.detection.pojo.enums.DetectionCodeEnum;
import java.util.Arrays;
/**
* @author wr
* @description
* @date 2025/3/27 14:58
*/
public class UnitUtil {
public static String unit(String code, Integer fly) {
String unit = "";
if (Arrays.asList(0, 1).contains(fly)) {
if (DetectionCodeEnum.FREQ.getCode().equals(code)) {
unit = "Hz";
}
if (DetectionCodeEnum.VRMS.getCode().equals(code)) {
unit = "V";
}
if (DetectionCodeEnum.IRMS.getCode().equals(code)) {
unit = "A";
}
if (DetectionCodeEnum.V2_50.getCode().equals(code) ||
DetectionCodeEnum.SV_1_49.getCode().equals(code)||
DetectionCodeEnum.V_UNBAN.getCode().equals(code) ||
DetectionCodeEnum.I_UNBAN.getCode().equals(code)
) {
unit = "%";
}
if (DetectionCodeEnum.I2_50.getCode().equals(code) ||
DetectionCodeEnum.SI_1_49.getCode().equals(code)
) {
unit = "A";
}
if (DetectionCodeEnum.P2_50.getCode().equals(code)) {
unit = "W";
}
if (DetectionCodeEnum.P.getCode().equals(code)) {
unit = "P";
}
if (DetectionCodeEnum.MAG.getCode().equals(code)) {
unit = "%";
}
if (DetectionCodeEnum.DUR.getCode().equals(code)) {
unit = "s";
}
if (DetectionCodeEnum.VA.getCode().equals(code) ||
DetectionCodeEnum.IA.getCode().equals(code)
) {
unit = "°";
}
if (DetectionCodeEnum.DELTA_V.getCode().equals(code)
) {
unit = "%";
}
}else{
unit = "%";
}
return unit;
}
}

View File

@@ -1,6 +1,7 @@
package com.njcn.gather.detection.util.socket;
import com.alibaba.fastjson.JSON;
import com.njcn.gather.detection.pojo.param.PreDetectionParam;
import com.njcn.gather.detection.pojo.vo.WebSocketVO;
import io.netty.channel.Channel;
import io.netty.handler.codec.http.websocketx.TextWebSocketFrame;
@@ -24,6 +25,8 @@ public class WebServiceManager {
//key:页面 value:channel
private static final Map<String, Channel> userSessions = new ConcurrentHashMap<>();
// 检测参数。key固定为preDetectionParam, value:检测参数
private static final Map<String, PreDetectionParam> preDetectionParamMap = new ConcurrentHashMap<>();
public static void addUser(String userId, Channel channel) {
userSessions.put(userId, channel);
@@ -35,7 +38,7 @@ public class WebServiceManager {
Iterator<Map.Entry<String, Channel>> iterator = userSessions.entrySet().iterator();
while (iterator.hasNext()) {
Map.Entry<String, Channel> entry = iterator.next();
if (entry.getValue().id().equals(channelId)) {
if (entry.getValue().id().toString().equals(channelId)) {
iterator.remove();
}
}
@@ -66,5 +69,15 @@ public class WebServiceManager {
}
}
public static void addPreDetectionParam(PreDetectionParam preDetectionParam) {
preDetectionParamMap.put("preDetectionParam", preDetectionParam);
}
public static PreDetectionParam getPreDetectionParam() {
return preDetectionParamMap.get("preDetectionParam");
}
public static void removePreDetectionParam() {
preDetectionParamMap.clear();
}
}

View File

@@ -2,6 +2,7 @@ package com.njcn.gather.detection.util.socket;
import com.njcn.gather.detection.pojo.dto.DevXiNumData;
import com.njcn.gather.detection.pojo.vo.CoefficientVO;
import com.njcn.gather.device.pojo.vo.PreDetection;
import com.njcn.gather.script.pojo.po.SourceIssue;
import java.util.ArrayList;
@@ -27,7 +28,7 @@ public class XiNumberManager {
public static List<String> devXiList = new ArrayList<>();
/**
* 存储所有测点的大电压系数
* 最开始存储装置通道原始系数后续存储大电压计算出来的系数。key为装置ip
*/
public static Map<String, DevXiNumData> devXiNumDataMap = new ConcurrentHashMap<>();
@@ -42,10 +43,19 @@ public class XiNumberManager {
public static Integer stepNumber = 0;
// 存放大电压、小电压、大电流、小电流的数值
public static List<CoefficientVO.DevParameter> devParameterList = new ArrayList<>();
/**
* 因为只支持单台装置获取系数,用于记录未获取到系数的装置,获取到一个删除一个
*/
public static List<PreDetection> xiDevList = new ArrayList<>();
}

View File

@@ -0,0 +1,120 @@
package com.njcn.gather.detection.util.socket.cilent;
import com.alibaba.fastjson.JSON;
import com.njcn.gather.detection.pojo.enums.SourceOperateCodeEnum;
import com.njcn.gather.detection.pojo.param.PreDetectionParam;
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.MsgUtil;
import com.njcn.gather.detection.util.socket.SocketManager;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelDuplexHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import lombok.RequiredArgsConstructor;
import java.time.LocalDateTime;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
/**
* @Author: cdf
* @CreateTime: 2025-02-11
* @Description: 心跳处理类
*/
public class HeartbeatHandler extends SimpleChannelInboundHandler<String> {
private final ScheduledExecutorService heartbeatExecutor = Executors.newScheduledThreadPool(1);
private final String dev = "_Dev";
private final String sourceTag = "_Source";
private final PreDetectionParam param;
private final String handlerType;
// 允许连续未收到心跳响应的最大次数
private static final int MAX_HEARTBEAT_MISSES = 3;
// 连续未收到心跳响应的次数
private int consecutiveHeartbeatMisses = 0;
public HeartbeatHandler(PreDetectionParam param,String type){
this.param = param;
this.handlerType = type;
}
@Override
public void channelActive(ChannelHandlerContext ctx) {
// 启动心跳定时任务
scheduleHeartbeat(ctx);
ctx.fireChannelActive();
}
@Override
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
heartbeatExecutor.shutdown();
super.channelInactive(ctx);
}
// 每30秒发送一次心跳
private void scheduleHeartbeat(ChannelHandlerContext ctx) {
heartbeatExecutor.scheduleAtFixedRate(() -> {
if (ctx.channel().isActive()) {
// 发送心跳包
SocketMsg<String> msg = new SocketMsg<>();
msg.setRequestId("yxt");
msg.setOperateCode(SourceOperateCodeEnum.HEARTBEAT.getValue());
msg.setData("");
ctx.channel().writeAndFlush(JSON.toJSONString(msg)+"\n");
System.out.println(handlerType+"♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥send"+LocalDateTime.now());
consecutiveHeartbeatMisses++;
if (consecutiveHeartbeatMisses >= MAX_HEARTBEAT_MISSES) {
// 连续三次未收到心跳响应,断开连接
System.out.println(handlerType+"连续三次未收到心跳响应,断开连接");
if (dev.equals(handlerType)) {
//CnSocketUtil.sendToWebSocket(param.getUserPageId(),);
CnSocketUtil.quitSend(param);
} else {
CnSocketUtil.quitSendSource(param);
}
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
System.err.println("线程中断异常: " + e.getMessage());
}
String key = dev.equals(handlerType) ? param.getUserPageId() + dev : param.getUserPageId() + sourceTag;
SocketManager.removeUser(key);
consecutiveHeartbeatMisses = 0; // 重置连续心跳丢失次数
}
}
}, 3, 10, TimeUnit.SECONDS);
}
@Override
protected void channelRead0(ChannelHandlerContext ctx, String msg) throws Exception {
// 过滤心跳包,避免进入业务逻辑
if (isHeartbeatPacket(msg)) {
System.out.println(handlerType+"♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥response"+LocalDateTime.now());
consecutiveHeartbeatMisses = 0;
return;
}
// 处理业务数据
ctx.fireChannelRead(msg);
}
private boolean isHeartbeatPacket(String msg) {
// 判断是否为心跳包
SocketDataMsg socketDataMsg = MsgUtil.socketDataMsg(msg);
return socketDataMsg.getOperateCode().equals(SourceOperateCodeEnum.HEARTBEAT.getValue());
}
}

View File

@@ -31,6 +31,9 @@ import java.util.concurrent.TimeUnit;
@Getter
public class NettyClient {
private static final String dev = "_Dev";
private static final String source = "_Source";
public static void socketClient(String ip, Integer port, PreDetectionParam param, String msg, SimpleChannelInboundHandler<String> handler) {
NioEventLoopGroup group = new NioEventLoopGroup();
Bootstrap bootstrap = new Bootstrap();
@@ -46,18 +49,21 @@ public class NettyClient {
//空闲状态的handler
// 添加LineBasedFrameDecoder来按行分割数据
.addLast(new LineBasedFrameDecoder(10240))
.addLast(new IdleStateHandler(0, 10, 0, TimeUnit.SECONDS))
// .addLast(new IdleStateHandler(0, 10, 0, TimeUnit.SECONDS))
.addLast(new StringDecoder(CharsetUtil.UTF_8))
.addLast(new StringEncoder(CharsetUtil.UTF_8))
.addLast(new HeartbeatHandler(param,source))
.addLast(handler);
} else {
ch.pipeline()
//空闲状态的handler
// 添加LineBasedFrameDecoder来按行分割数据
.addLast(new LineBasedFrameDecoder(10240))
.addLast(new IdleStateHandler(60, 0, 0, TimeUnit.SECONDS))
.addLast(new StringDecoder(CharsetUtil.UTF_8))
.addLast(new StringEncoder(CharsetUtil.UTF_8))
.addLast(new HeartbeatHandler(param,dev))
//空闲状态的handler
.addLast(new IdleStateHandler(60, 0, 0, TimeUnit.SECONDS))
.addLast(handler);
}
@@ -69,7 +75,7 @@ public class NettyClient {
System.out.println("链接服务端失败...");
} else {
System.out.println("链接服务端成功...");
System.out.println("客户端向服务端发送消息:"+msg);
System.out.println("客户端向服务端发送消息:"+port+msg);
channelFuture.channel().writeAndFlush(msg+"\n");
}
});
@@ -78,9 +84,9 @@ public class NettyClient {
groupByUserId.shutdownGracefully();
}else{
if (handler instanceof NettySourceClientHandler) {
SocketManager.addGroup(param.getUserPageId()+"_Source",group);
SocketManager.addGroup(param.getUserPageId()+source,group);
}else{
SocketManager.addGroup(param.getUserPageId()+"_Dev",group);
SocketManager.addGroup(param.getUserPageId()+dev,group);
}
}
} catch (Exception e) {

View File

@@ -6,6 +6,8 @@ import com.njcn.gather.detection.handler.SocketDevResponseService;
import com.njcn.gather.detection.pojo.enums.SourceOperateCodeEnum;
import com.njcn.gather.detection.pojo.param.PreDetectionParam;
import com.njcn.gather.detection.pojo.vo.DevLineTestResult;
import com.njcn.gather.detection.pojo.vo.SocketDataMsg;
import com.njcn.gather.detection.pojo.vo.SocketMsg;
import com.njcn.gather.detection.pojo.vo.WebSocketVO;
import com.njcn.gather.detection.util.socket.*;
import com.njcn.gather.device.pojo.vo.PreDetection;
@@ -22,9 +24,12 @@ import lombok.RequiredArgsConstructor;
import java.io.IOException;
import java.net.ConnectException;
import java.net.ProtocolException;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.time.LocalDateTime;
import java.util.*;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
/**
@@ -102,7 +107,8 @@ public class NettyDevClientHandler extends SimpleChannelInboundHandler<String> {
Boolean fly = false;
if (evt instanceof IdleStateEvent) {
if (((IdleStateEvent) evt).state() == IdleState.READER_IDLE) {
if(!FormalTestManager.hasStopFlag) {
System.out.println(LocalDateTime.now() + "devHandler触发读超时函数**************************************");
if (!FormalTestManager.hasStopFlag) {
if (CollUtil.isNotEmpty(SocketManager.getSourceList())) {
SourceIssue sourceIssue = SocketManager.getSourceList().get(0);
if (SocketManager.clockMap.containsKey(sourceIssue.getIndex())) {
@@ -114,7 +120,7 @@ public class NettyDevClientHandler extends SimpleChannelInboundHandler<String> {
if (sourceIssue.getType().equals(DicDataEnum.F.getCode())) {
//闪变,正常抛一轮最大等待20分钟超时
if (SocketManager.clockMap.get(sourceIssue.getIndex()) > 1300) {
fly=true;
fly = true;
System.out.println("超时处理-----》" + sourceIssue.getType() + "已超时----------------关闭");
CnSocketUtil.quitSend(param);
timeoutSend(sourceIssue);
@@ -122,37 +128,35 @@ public class NettyDevClientHandler extends SimpleChannelInboundHandler<String> {
} else if (sourceIssue.getType().equals(DicDataEnum.VOLTAGE.getCode()) || sourceIssue.getType().equals(DicDataEnum.HP.getCode())) {
//统计数据项,正常抛一轮数据,超时
if (SocketManager.clockMap.get(sourceIssue.getIndex()) > 180) {
fly=true;
fly = true;
CnSocketUtil.quitSend(param);
System.out.println("超时处理-----》" + sourceIssue.getType() + "已超时----------------关闭");
timeoutSend(sourceIssue);
}
} else {
//实时数据
if (SocketManager.clockMap.get(sourceIssue.getIndex()) > 60) {
fly=true;
fly = true;
CnSocketUtil.quitSend(param);
System.out.println("超时处理-----》" + sourceIssue.getType() + "已超时----------------关闭");
timeoutSend(sourceIssue);
}
}
} else {
fly=true;
fly = true;
//为空则认为是常规步骤,设定一分钟超时
CnSocketUtil.quitSend(param);
}
if(fly){
if (fly) {
socketResponseService.backCheckState(param);
}
System.out.println("已经等了一分钟了。。。。。。。。。。。。");
}else {
} else {
//如果是暂停操作后
FormalTestManager.stopTime+=60;
System.out.println("当前进入暂停操作超时函数-----------------"+FormalTestManager.stopTime);
if(FormalTestManager.stopTime > 600){
FormalTestManager.stopTime += 60;
System.out.println("当前进入暂停操作超时函数-----------------" + FormalTestManager.stopTime);
if (FormalTestManager.stopTime > 600) {
CnSocketUtil.quitSend(param);
CnSocketUtil.sendToWebSocket(param.getUserPageId(),SourceOperateCodeEnum.FORMAL_REAL.getValue(),SourceOperateCodeEnum.STOP_TIMEOUT.getValue(),SourceOperateCodeEnum.STOP_TIMEOUT.getMsg(),null);
CnSocketUtil.sendToWebSocket(param.getUserPageId(), SourceOperateCodeEnum.FORMAL_REAL.getValue(), SourceOperateCodeEnum.STOP_TIMEOUT.getValue(), SourceOperateCodeEnum.STOP_TIMEOUT.getMsg(), null);
}
}
}
@@ -162,8 +166,6 @@ public class NettyDevClientHandler extends SimpleChannelInboundHandler<String> {
}
@Override
public void handlerAdded(ChannelHandlerContext ctx) {
System.out.println("有通道准备接入" + ctx.channel());
@@ -183,7 +185,7 @@ public class NettyDevClientHandler extends SimpleChannelInboundHandler<String> {
} else if (cause instanceof IOException) {
// 处理I/O异常例如读写错误
System.out.println("IOException caught: There was an I/O error.");
CnSocketUtil.sendToWebSocket(param.getUserPageId(),SourceOperateCodeEnum.SERVER_ERROR.getValue(),SourceOperateCodeEnum.SERVER_ERROR.getValue(),SourceOperateCodeEnum.SERVER_ERROR.getMsg(),null );
CnSocketUtil.sendToWebSocket(param.getUserPageId(), SourceOperateCodeEnum.SERVER_ERROR.getValue(), SourceOperateCodeEnum.SERVER_ERROR.getValue(), SourceOperateCodeEnum.SERVER_ERROR.getMsg(), null);
// 例如可以记录更详细的I/O错误信息
} else if (cause instanceof TimeoutException) {
@@ -206,9 +208,26 @@ public class NettyDevClientHandler extends SimpleChannelInboundHandler<String> {
/**
*
* 发送业务消息时候开启计时器,
* @param requestId
*/
private void timeoutSend(SourceIssue sourceIssue){
/* private void scheduleTimeoutTask(String requestId) {
ScheduledFuture<?> future = scheduler.schedule(() -> {
if (requestTimeoutTasks.containsKey(requestId)) {
// 处理超时逻辑
System.out.println("Business request with ID " + requestId + " timed out.");
requestTimeoutTasks.remove(requestId);
ctx.close();
}
}, BUSINESS_REQUEST_TIMEOUT, TimeUnit.MILLISECONDS);
requestTimeoutTasks.put(requestId, future);
}*/
/**
* 超时后的处理
*/
private void timeoutSend(SourceIssue sourceIssue) {
List<DevLineTestResult> devListRes = new ArrayList<>();
FormalTestManager.devList.forEach(dev -> {
DevLineTestResult devLineTestResult = new DevLineTestResult();
@@ -221,7 +240,7 @@ public class NettyDevClientHandler extends SimpleChannelInboundHandler<String> {
devListRes.add(devLineTestResult);
});
WebSocketVO<List<DevLineTestResult>> socketVO = new WebSocketVO<>();
socketVO.setRequestId(sourceIssue.getType()+"_End");
socketVO.setRequestId(sourceIssue.getType() + "_End");
socketVO.setOperateCode(sourceIssue.getType());
socketVO.setData(devListRes);
WebServiceManager.sendMsg(param.getUserPageId(), JSON.toJSONString(socketVO));

View File

@@ -95,11 +95,11 @@ public class NettySourceClientHandler extends SimpleChannelInboundHandler<String
if (evt instanceof IdleStateEvent) {
if (((IdleStateEvent) evt).state() == IdleState.WRITER_IDLE) {
//发送ping 保持心跳链接
SocketMsg msg = new SocketMsg();
/* SocketMsg<String> msg = new SocketMsg<>();
msg.setRequestId("yxt");
msg.setOperateCode(SourceOperateCodeEnum.HEARTBEAT.getValue());
msg.setData("");
ctx.writeAndFlush(JSON.toJSONString(msg)+"\n");
ctx.writeAndFlush(JSON.toJSONString(msg)+"\n");*/
}
} else {
//防止堆栈溢出
@@ -126,6 +126,7 @@ public class NettySourceClientHandler extends SimpleChannelInboundHandler<String
} else if (cause instanceof IOException) {
// 处理I/O异常例如读写错误
CnSocketUtil.sendToWebSocket(webUser.getUserPageId(),SourceOperateCodeEnum.SERVER_ERROR.getValue(),SourceOperateCodeEnum.SERVER_ERROR.getValue(),SourceOperateCodeEnum.SERVER_ERROR.getMsg(),null );
// 例如可以记录更详细的I/O错误信息
} else if (cause instanceof TimeoutException) {
// 处理超时异常

View File

@@ -0,0 +1,149 @@
package com.njcn.gather.detection.util.socket.service;
import com.alibaba.fastjson.JSONObject;
import com.njcn.gather.detection.pojo.enums.SourceOperateCodeEnum;
import com.njcn.gather.detection.pojo.vo.SocketDataMsg;
import com.njcn.gather.detection.util.socket.MsgUtil;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import java.util.Objects;
/**
* @Description: 客户端业务处理
* @Author: wr
* @Date: 2024/12/10 14:18
*/
public class DevNettyServerHandler extends SimpleChannelInboundHandler<String> {
private final String DEV = "_Dev";
private final String source = "_Source";
private final String stepTag = "&&";
private final String stepBegin = "_Start";
private final String stepEnd = "_End";
public static final DevNettyServerHandler INSTANCE = new DevNettyServerHandler();
/**
* @Description: 当通道进行连接时推送消息
* @Author: wr
* @Date: 2024/12/10 14:19
*/
@Override
public void channelActive(ChannelHandlerContext ctx) throws Exception {
System.out.println("服务端监听到" + ctx.channel().id() + "连接");
super.channelActive(ctx);
}
/**
* 处理消息信息
*/
@Override
public void channelRead0(ChannelHandlerContext ctx, String msg) {
System.out.println(ctx.channel().id() + "NettyServer服务端接收到客户端消息" + msg);
Channel channel = ctx.channel();
SocketDataMsg socketDataMsg = MsgUtil.socketDataMsg(msg);
String[] tem = socketDataMsg.getRequestId().split(stepTag);
SourceOperateCodeEnum sourceOperateCodeEnum = SourceOperateCodeEnum.getDictDataEnumByCode(tem[0]);
switch (Objects.requireNonNull(sourceOperateCodeEnum)) {
//设备通讯校验
case YJC_SBTXJY:
String aa = "{\"requestId\":\"yjc_sbtxjy\",\"operateCode\":\"INIT_GATHER$01\",\"data\":null,\"code\":10201}";
String bb = "{\"requestId\":\"yjc_sbtxjy\",\"operateCode\":\"INIT_GATHER$01\",\"data\":null,\"code\":10201}";
String cc = "{\"requestId\":\"yjc_sbtxjy\",\"operateCode\":\"INIT_GATHER$01\",\"data\":\"192.168.1.237_1\",\"code\":10200}";
channel.writeAndFlush(aa+"\n");
channel.writeAndFlush(bb+"\n");
channel.writeAndFlush(cc+"\n");
break;
//协议校验
case YJC_XYJY:
String dd="{\"requestId\":\"yjc_xyjy\",\"operateCode\":\"INIT_GATHER$02\",\"data\":null,\"code\":10201}";
String ee = "{\"requestId\":\"yjc_xyjy\",\"operateCode\":\"INIT_GATHER$02\",\"data\":\"192.168.1.237_1\",\"code\":10200}";
channel.writeAndFlush(dd+"\n");
channel.writeAndFlush(ee+"\n");
String ff = "{\"requestId\":\"yjc_xyjy\",\"operateCode\":\"INIT_GATHER$03\",\"data\":null,\"code\":10201}";
String gg ="{\"requestId\":\"yjc_xyjy\",\"operateCode\":\"INIT_GATHER$03\",\"data\":\"192.168.1.237_1\",\"code\":10200}";
channel.writeAndFlush(ff+"\n");
channel.writeAndFlush(gg+"\n");
break;
//相序校验
case YJC_XUJY:
String hh = "{\"requestId\":\"YJC_xujy\",\"operateCode\":\"DATA_REQUEST$02\",\"data\":null,\"code\":10201}";
String ii = "{\"requestId\":\"YJC_xujy\",\"operateCode\":\"DATA_REQUEST$02\",\"data\":\"{\\\"Time\\\":\\\"2025-02-14T15:09:06.004\\\",\\\"ID\\\":\\\"192.168.1.237_1\\\",\\\"result\\\":false,\\\"SqlData\\\":[{\\\"type\\\":\\\"real\\\",\\\"desc\\\":\\\"VRMS\\\",\\\"list\\\":{\\\"A\\\":\\\"59.969920\\\",\\\"B\\\":\\\"49.963360\\\",\\\"C\\\":\\\"39.971470\\\",\\\"T\\\":null}},{\\\"type\\\":\\\"real\\\",\\\"desc\\\":\\\"VA\\\",\\\"list\\\":{\\\"A\\\":\\\"0.000000\\\",\\\"B\\\":\\\"-119.864000\\\",\\\"C\\\":\\\"120.052000\\\",\\\"T\\\":null}},{\\\"type\\\":\\\"real\\\",\\\"desc\\\":\\\"IRMS\\\",\\\"list\\\":{\\\"A\\\":\\\"1.000979\\\",\\\"B\\\":\\\"1.998939\\\",\\\"C\\\":\\\"3.000807\\\",\\\"T\\\":null}},{\\\"type\\\":\\\"real\\\",\\\"desc\\\":\\\"IA\\\",\\\"list\\\":{\\\"A\\\":\\\"-0.038000\\\",\\\"B\\\":\\\"-120.052000\\\",\\\"C\\\":\\\"119.941000\\\",\\\"T\\\":null}}],\\\"SqlDataHarm\\\":[]}\",\"code\":10200}\n";
channel.writeAndFlush(hh+"\n");
channel.writeAndFlush(ii+"\n");
break;
//正式检测
case FORMAL_REAL:
break;
//系数校验
case Coefficient_Check:
String a = "{\"requestId\":\"Coefficient_Check\",\"operateCode\":\"DATA_CHNFACTOR$01\",\"data\":null,\"code\":10201}";
String b = "{\"requestId\":\"Coefficient_Check\",\"operateCode\":\"DATA_CHNFACTOR$01\",\"data\":\"[{\\\"uMonitorPoint\\\":0,\\\"f\\\":{\\\"Ua_gain\\\":9999,\\\"Ub_gain\\\":10008,\\\"Uc_gain\\\":10000,\\\"U0_gain\\\":10000,\\\"Ia_gain\\\":9997,\\\"Ib_gain\\\":9997,\\\"Ic_gain\\\":10001,\\\"I0_gain\\\":10000,\\\"Uab_gain\\\":9999,\\\"Ubc_gain\\\":10008,\\\"Uca_gain\\\":10000}}]\",\"code\":10200}";
channel.writeAndFlush(a+"\n");
channel.writeAndFlush(b+"\n");
switch (Objects.requireNonNull(sourceOperateCodeEnum)) {
case DATA_CHNFACTOR$01:
break;
}
break;
//退出关闭
case QUITE:
// quitDeal(socketDataMsg, param, msg);
break;
case YXT:
break;
}
}
@Override
public void handlerAdded(ChannelHandlerContext ctx) {
System.out.println("有新连接加入了++++......" + ctx.channel());
}
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
cause.printStackTrace();
ctx.close();
}
@Override
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
// Client disconnected, close the server-side channel too
System.out.println("NettyServer服务端监听到" + ctx.channel().id() + "关闭连接");
ctx.close(); // This will trigger the close event on the server side
super.channelInactive(ctx);
}
/**
* 用户事件的回调方法(自定义事件用于心跳机制)
*/
@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
//空闲状态的事件
// if (evt instanceof IdleStateEvent) {
// IdleStateEvent event = (IdleStateEvent) evt;
// System.out.println(event.state() + ">>>" + ctx.channel().id());
// //已经10秒钟没有读时间了
// if (event.state().equals(IdleState.READER_IDLE)){
// // 心跳包丢失10秒没有收到客户端心跳 (断开连接)
// ctx.channel().close().sync();
// System.out.println("已与 "+ctx.channel().remoteAddress()+" 断开连接");
// }
// }
}
}

View File

@@ -6,6 +6,11 @@ import io.netty.channel.ChannelInitializer;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.ServerSocketChannel;
import io.netty.channel.socket.nio.NioServerSocketChannel;
import io.netty.channel.socket.nio.NioSocketChannel;
import io.netty.handler.codec.LineBasedFrameDecoder;
import io.netty.handler.codec.string.StringDecoder;
import io.netty.handler.codec.string.StringEncoder;
import io.netty.util.CharsetUtil;
/**
@@ -25,11 +30,17 @@ public class NettyServer {
public static void main(String[] args) {
NettyServer nettyServer = new NettyServer();
nettyServer.run();
nettyServer.runSource();
}
private void run() {
public static void sourceMain(String[] args) {
NettyServer nettyServer = new NettyServer();
nettyServer.runDev();
}
private void runSource() {
NioEventLoopGroup boss = new NioEventLoopGroup(1);
NioEventLoopGroup work = new NioEventLoopGroup();
try {
@@ -39,19 +50,30 @@ public class NettyServer {
.handler(new ChannelInitializer<ServerSocketChannel>() {
@Override
protected void initChannel(ServerSocketChannel ch) {
System.out.println("服务正在启动中......");
System.out.println("源通讯服务正在启动中......");
}
})
//业务处理
.childHandler(NettyServerChannelInitializer.INSTANCE);
.childHandler(new ChannelInitializer<NioSocketChannel>() {
@Override
protected void initChannel(NioSocketChannel ch) {
ch.pipeline()
//空闲状态的handler
// 添加LineBasedFrameDecoder来按行分割数据
.addLast(new LineBasedFrameDecoder(10240))
.addLast(new StringDecoder(CharsetUtil.UTF_8))
.addLast(new StringEncoder(CharsetUtil.UTF_8))
.addLast(new DevNettyServerHandler());
}
});
ChannelFuture future = bootstrap.bind(port).sync();
future.addListener(f -> {
if (future.isSuccess()) {
System.out.println("服务启动成功");
System.out.println("源通讯服务启动成功");
} else {
System.out.println("服务启动失败");
System.out.println("源通讯服务启动失败");
}
});
future.channel().closeFuture().sync();
@@ -63,4 +85,52 @@ public class NettyServer {
work.shutdownGracefully();
}
}
private void runDev() {
NioEventLoopGroup boss = new NioEventLoopGroup(1);
NioEventLoopGroup work = new NioEventLoopGroup();
try {
ServerBootstrap bootstrap = new ServerBootstrap().group(boss, work);
bootstrap.channel(NioServerSocketChannel.class)
//这个处理器可以不写
.handler(new ChannelInitializer<ServerSocketChannel>() {
@Override
protected void initChannel(ServerSocketChannel ch) {
System.out.println("设备通讯服务正在启动中......");
}
})
//业务处理
.childHandler(new ChannelInitializer<NioSocketChannel>() {
@Override
protected void initChannel(NioSocketChannel ch) {
ch.pipeline()
//空闲状态的handler
// 添加LineBasedFrameDecoder来按行分割数据
.addLast(new LineBasedFrameDecoder(10240))
.addLast(new StringDecoder(CharsetUtil.UTF_8))
.addLast(new StringEncoder(CharsetUtil.UTF_8))
.addLast(new SourceNettyServerHandler());
}
});
ChannelFuture future = bootstrap.bind(port).sync();
future.addListener(f -> {
if (future.isSuccess()) {
System.out.println("设备通讯服务启动成功");
} else {
System.out.println("设备通讯服务启动失败");
}
});
future.channel().closeFuture().sync();
} catch (InterruptedException e) {
e.printStackTrace();
} finally {
boss.shutdownGracefully();
work.shutdownGracefully();
}
}
}

View File

@@ -23,7 +23,7 @@ public class NettyServerChannelInitializer extends ChannelInitializer<NioSocketC
// .addLast(new IdleStateHandler(10, 0, 0, TimeUnit.SECONDS))
.addLast(new StringDecoder(CharsetUtil.UTF_8))
.addLast(new StringEncoder(CharsetUtil.UTF_8))
.addLast(new NettyServerHandler());
.addLast(new DevNettyServerHandler());
}

View File

@@ -1,130 +0,0 @@
package com.njcn.gather.detection.util.socket.service;
import com.alibaba.fastjson.JSONObject;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
/**
* @Description: 客户端业务处理
* @Author: wr
* @Date: 2024/12/10 14:18
*/
public class NettyServerHandler extends SimpleChannelInboundHandler<String> {
public static final NettyServerHandler INSTANCE = new NettyServerHandler();
/**
* @Description: 当通道进行连接时推送消息
* @Author: wr
* @Date: 2024/12/10 14:19
*/
@Override
public void channelActive(ChannelHandlerContext ctx) throws Exception {
System.out.println("服务端监听到"+ctx.channel().id()+"连接");
super.channelActive(ctx);
}
/**
* 处理消息信息
*/
@Override
public void channelRead0(ChannelHandlerContext ctx, String msg) {
System.out.println(ctx.channel().id()+"NettyServer服务端接收到客户端消息"+msg);
Channel channel = ctx.channel();
/*
if(msg.endsWith("结束")) {
channel.writeAndFlush("socket指令结果"+msg);
for (int i = 0; i < 5; i++) {
channel.writeAndFlush("socket指令结果"+msg);
}
}else{
channel.writeAndFlush("socket指令结果成功指令");
}*/
if(!msg.contains("HeartBeat")){
if(msg.contains("start")){
JSONObject jsonObject1 = new JSONObject();
jsonObject1.put("requestId","yjc_ytxjy");
jsonObject1.put("operateCode","INIT_GATHER");
jsonObject1.put("code","10201");
channel.writeAndFlush(jsonObject1.toJSONString()+'\n');
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
JSONObject jsonObject = new JSONObject();
jsonObject.put("requestId","yjc_ytxjy");
jsonObject.put("operateCode","INIT_GATHER");
jsonObject.put("code","10200");
channel.writeAndFlush(jsonObject.toJSONString()+'\n');
}else if(msg.contains("YJC_xujy")){
JSONObject jsonObject = new JSONObject();
jsonObject.put("requestId","YJC_xujy");
jsonObject.put("operateCode","OPER_GATHER");
jsonObject.put("code","10201");
channel.writeAndFlush(jsonObject.toJSONString()+'\n');
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
JSONObject jsonObject1 = new JSONObject();
jsonObject1.put("requestId","YJC_xujy");
jsonObject1.put("operateCode","OPER_GATHER");
jsonObject1.put("code","10200");
channel.writeAndFlush(jsonObject1.toJSONString()+'\n');
}
}
}
@Override
public void handlerAdded(ChannelHandlerContext ctx) {
System.out.println("有新连接加入了++++......" + ctx.channel());
}
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
cause.printStackTrace();
ctx.close();
}
@Override
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
// Client disconnected, close the server-side channel too
System.out.println("NettyServer服务端监听到"+ctx.channel().id()+"关闭连接");
ctx.close(); // This will trigger the close event on the server side
super.channelInactive(ctx);
}
/**
* 用户事件的回调方法(自定义事件用于心跳机制)
*/
@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
//空闲状态的事件
// if (evt instanceof IdleStateEvent) {
// IdleStateEvent event = (IdleStateEvent) evt;
// System.out.println(event.state() + ">>>" + ctx.channel().id());
// //已经10秒钟没有读时间了
// if (event.state().equals(IdleState.READER_IDLE)){
// // 心跳包丢失10秒没有收到客户端心跳 (断开连接)
// ctx.channel().close().sync();
// System.out.println("已与 "+ctx.channel().remoteAddress()+" 断开连接");
// }
// }
}
}

View File

@@ -0,0 +1,133 @@
package com.njcn.gather.detection.util.socket.service;
import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSONObject;
import com.njcn.gather.detection.pojo.enums.SourceOperateCodeEnum;
import com.njcn.gather.detection.pojo.vo.SocketDataMsg;
import com.njcn.gather.detection.util.socket.MsgUtil;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
/**
* @Description: 客户端业务处理
* @Author: wr
* @Date: 2024/12/10 14:18
*/
public class SourceNettyServerHandler extends SimpleChannelInboundHandler<String> {
private final String DEV = "_Dev";
private final String source = "_Source";
private final String stepTag = "&&";
private final String stepBegin = "_Start";
private final String stepEnd = "_End";
public static final SourceNettyServerHandler INSTANCE = new SourceNettyServerHandler();
/**
* @Description: 当通道进行连接时推送消息
* @Author: wr
* @Date: 2024/12/10 14:19
*/
@Override
public void channelActive(ChannelHandlerContext ctx) throws Exception {
System.out.println("服务端监听到" + ctx.channel().id() + "连接");
super.channelActive(ctx);
}
/**
* 处理消息信息
*/
@Override
public void channelRead0(ChannelHandlerContext ctx, String msg) {
System.out.println(ctx.channel().id() + "NettyServer服务端接收到客户端消息" + msg);
Channel channel = ctx.channel();
SocketDataMsg socketDataMsg = MsgUtil.socketDataMsg(msg);
String[] tem = socketDataMsg.getRequestId().split(stepTag);
SourceOperateCodeEnum enumByCode = SourceOperateCodeEnum.getDictDataEnumByCode(tem[0]);
JSONObject jsonObject1 = new JSONObject();
if (ObjectUtil.isNotNull(enumByCode)) {
switch (enumByCode) {
//源初始化
case YJC_YTXJY:
String aa = "{\"requestId\":\"yjc_ytxjy\",\"operateCode\":\"INIT_GATHER\",\"data\":null,\"code\":10201}";
String bb = "{\"requestId\":\"yjc_ytxjy\",\"operateCode\":\"INIT_GATHER\",\"data\":null,\"code\":10200}";
channel.writeAndFlush(aa+"/n");
channel.writeAndFlush(bb+"/n");
break;
//相序检测
case YJC_XUJY:
String hh = "{\"requestId\":\"YJC_xujy\",\"operateCode\":\"OPER_GATHER\",\"data\":null,\"code\":10201}";
String ii = "{\"requestId\":\"YJC_xujy\",\"operateCode\":\"OPER_GATHER\",\"data\":null,\"code\":10200}";
channel.writeAndFlush(hh+"\n");
channel.writeAndFlush(ii+"\n");
break;
//正式检测
case FORMAL_REAL:
break;
//系数校验
case Coefficient_Check:
String a = "{\"requestId\":\"Coefficient_Check\",\"operateCode\":\"OPER_GATHER\",\"data\":null,\"code\":10201}";
String b= "{\"requestId\":\"Coefficient_Check\",\"operateCode\":\"OPER_GATHER\",\"data\":null,\"code\":10200}";
break;
case QUITE_SOURCE:
break;
case YXT:
jsonObject1.put("requestId", "yjc_ytxjy");
jsonObject1.put("operateCode", "INIT_GATHER");
jsonObject1.put("code", "10201");
channel.writeAndFlush(jsonObject1.toJSONString() + '\n');
break;
}
} else {
System.out.println("未知异常" + enumByCode);
}
}
@Override
public void handlerAdded(ChannelHandlerContext ctx) {
System.out.println("有新连接加入了++++......" + ctx.channel());
}
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
cause.printStackTrace();
ctx.close();
}
@Override
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
// Client disconnected, close the server-side channel too
System.out.println("NettyServer服务端监听到" + ctx.channel().id() + "关闭连接");
ctx.close(); // This will trigger the close event on the server side
super.channelInactive(ctx);
}
/**
* 用户事件的回调方法(自定义事件用于心跳机制)
*/
@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
//空闲状态的事件
// if (evt instanceof IdleStateEvent) {
// IdleStateEvent event = (IdleStateEvent) evt;
// System.out.println(event.state() + ">>>" + ctx.channel().id());
// //已经10秒钟没有读时间了
// if (event.state().equals(IdleState.READER_IDLE)){
// // 心跳包丢失10秒没有收到客户端心跳 (断开连接)
// ctx.channel().close().sync();
// System.out.println("已与 "+ctx.channel().remoteAddress()+" 断开连接");
// }
// }
}
}

View File

@@ -1,19 +1,15 @@
package com.njcn.gather.detection.util.socket.web;
import cn.hutool.core.util.ObjectUtil;
import com.njcn.gather.detection.pojo.param.PreDetectionParam;
import com.njcn.gather.detection.util.socket.CnSocketUtil;
import com.njcn.gather.detection.util.socket.SocketManager;
import com.njcn.gather.detection.util.socket.WebServiceManager;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.handler.codec.http.FullHttpRequest;
import io.netty.handler.codec.http.websocketx.TextWebSocketFrame;
import io.netty.handler.timeout.IdleStateEvent;
import io.netty.util.CharsetUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
/**
@@ -57,11 +53,13 @@ public class WebSocketHandler extends SimpleChannelInboundHandler<TextWebSocketF
} else if (msg instanceof TextWebSocketFrame) {
//正常的TEXT消息类型
TextWebSocketFrame frame = (TextWebSocketFrame) msg;
log.info("webSocket服务器收到客户端心跳信息{}", frame.text());
/*if ("alive".equals(frame.text())) {
//log.info("webSocket服务器收到客户端心跳信息{}", frame.text());
if ("alive".equals(frame.text())) {
//System.out.println("webSocket心跳收到时间………………………………………………………………"+LocalDateTime.now());
times = 0;
TextWebSocketFrame wd = new TextWebSocketFrame("over");
ctx.writeAndFlush(wd);
}*/
ctx.channel().writeAndFlush(wd);
}
}
super.channelRead(ctx, msg);
@@ -69,6 +67,7 @@ public class WebSocketHandler extends SimpleChannelInboundHandler<TextWebSocketF
/**
* 根据用户地址获取用户名 ws://127.0.0.1:7777/hello?name=aa
*
* @param url
* @return
*/
@@ -108,7 +107,7 @@ public class WebSocketHandler extends SimpleChannelInboundHandler<TextWebSocketF
}
@Override
public void handlerRemoved(ChannelHandlerContext ctx){
public void handlerRemoved(ChannelHandlerContext ctx) {
// 假设用户 ID 是从某个地方获取的,这里简单示例为 "userId"
System.out.println("weoSocket客户端退出: " + ctx.channel().id());
WebServiceManager.removeChannel(ctx.channel().id().toString());
@@ -120,9 +119,14 @@ public class WebSocketHandler extends SimpleChannelInboundHandler<TextWebSocketF
System.out.println("weoSocket断线" + ctx.channel().id());
ctx.close();
PreDetectionParam param = new PreDetectionParam();
param.setUserPageId("cdf");
CnSocketUtil.quitSend(param);
PreDetectionParam preDetectionParam = WebServiceManager.getPreDetectionParam();
if (ObjectUtil.isNotNull(preDetectionParam)) {
CnSocketUtil.quitSendSource(preDetectionParam); // 能否在这里关闭源socket连接
} else {
preDetectionParam = new PreDetectionParam();
preDetectionParam.setUserPageId("cdf");
CnSocketUtil.quitSend(preDetectionParam);
}
}
@@ -133,11 +137,12 @@ public class WebSocketHandler extends SimpleChannelInboundHandler<TextWebSocketF
switch (event.state()) {
case READER_IDLE:
eventDesc = "读空闲";
System.out.println(ctx.channel().remoteAddress() + "发生超时事件--" + eventDesc);
System.out.println("c端心跳检测发生超时事件--" + eventDesc);
times++;
if (times > 3) {
System.out.println("空闲次数超过三次 关闭连接");
System.out.println("c端心跳检测空闲次数超过三次 关闭连接");
ctx.channel().close();
WebServiceManager.removeChannel(ctx.channel().id().toString());
}
break;
case WRITER_IDLE:
@@ -153,12 +158,6 @@ public class WebSocketHandler extends SimpleChannelInboundHandler<TextWebSocketF
}
/**
* 推送数据至前台
*/
public void sendMsgToUser(String userId, String msg) {
WebServiceManager.sendMsg(userId, msg);
}
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {

View File

@@ -1,12 +1,8 @@
package com.njcn.gather.device.controller;
import cn.afterturn.easypoi.excel.ExcelImportUtil;
import cn.afterturn.easypoi.excel.entity.ImportParams;
import cn.afterturn.easypoi.excel.entity.result.ExcelImportResult;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.njcn.common.pojo.annotation.OperateInfo;
import com.njcn.common.pojo.constant.OperateType;
@@ -15,37 +11,26 @@ import com.njcn.common.pojo.enums.response.CommonResponseEnum;
import com.njcn.common.pojo.exception.BusinessException;
import com.njcn.common.pojo.response.HttpResult;
import com.njcn.common.utils.LogUtil;
import com.njcn.gather.device.pojo.enums.DevResponseEnum;
import com.njcn.gather.device.pojo.enums.PatternEnum;
import com.njcn.gather.device.pojo.param.PqDevParam;
import com.njcn.gather.device.pojo.po.PqDev;
import com.njcn.gather.device.pojo.vo.CNDevExcel;
import com.njcn.gather.device.pojo.vo.PqDevExcel;
import com.njcn.gather.device.pojo.vo.PqDevVO;
import com.njcn.gather.device.pojo.vo.PreDetection;
import com.njcn.gather.device.service.IPqDevService;
import com.njcn.gather.system.dictionary.pojo.po.DictData;
import com.njcn.gather.system.dictionary.service.IDictDataService;
import com.njcn.gather.type.pojo.po.DevType;
import com.njcn.gather.type.service.IDevTypeService;
import com.njcn.web.controller.BaseController;
import com.njcn.web.utils.ExcelUtil;
import com.njcn.web.utils.FileUtil;
import com.njcn.web.utils.HttpResultUtil;
import com.njcn.web.utils.PoiUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -62,24 +47,8 @@ import java.util.Map;
public class PqDevController extends BaseController {
private final IPqDevService pqDevService;
private final IDictDataService dictDataService;
private final IDevTypeService devTypeService;
@OperateInfo
@GetMapping("/aaa")
@ApiOperation("分页查询被检设备")
@ApiImplicitParam(name = "queryParam", value = "查询参数", required = true)
public HttpResult<List<PreDetection>> aaa() {
String methodDescribe = getMethodDescribe("list");
List<PreDetection> devInfo = pqDevService.getDevInfo(Arrays.asList("578c142b7e4e4978a35bd6225aa62a23", "393504f55f1f79bce255bfc195cfdb56"));
Map<String, List<PreDetection>> map = new HashMap();
map.put("deviceList", devInfo);
String jsonString = JSON.toJSONString(map);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, devInfo, methodDescribe);
}
@OperateInfo
@PostMapping("/list")
@ApiOperation("分页查询被检设备")
@@ -106,14 +75,14 @@ public class PqDevController extends BaseController {
@PostMapping("/add")
@ApiOperation("新增被检设备")
@ApiImplicitParam(name = "pqDevParam", value = "被检设备", required = true)
public HttpResult<Object> add(@RequestBody @Validated PqDevParam pqDevParam) {
public HttpResult<Boolean> add(@RequestBody @Validated PqDevParam pqDevParam) {
String methodDescribe = getMethodDescribe("add");
LogUtil.njcnDebug(log, "{},新增数据为:{}", methodDescribe, pqDevParam);
boolean result = pqDevService.addPqDev(pqDevParam);
if (result) {
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, methodDescribe);
} else {
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, null, methodDescribe);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, false, methodDescribe);
}
}
@@ -121,14 +90,14 @@ public class PqDevController extends BaseController {
@PostMapping("/update")
@ApiOperation("修改被检设备")
@ApiImplicitParam(name = "updateParam", value = "被检设备", required = true)
public HttpResult<Object> update(@RequestBody @Validated PqDevParam.UpdateParam updateParam) {
public HttpResult<Boolean> update(@RequestBody @Validated PqDevParam.UpdateParam updateParam) {
String methodDescribe = getMethodDescribe("update");
LogUtil.njcnDebug(log, "{},修改数据为:{}", methodDescribe, updateParam);
boolean result = pqDevService.updatePqDev(updateParam);
if (result) {
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, methodDescribe);
} else {
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, null, methodDescribe);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, false, methodDescribe);
}
}
@@ -136,35 +105,25 @@ public class PqDevController extends BaseController {
@PostMapping("/delete")
@ApiOperation("删除被检设备")
@ApiImplicitParam(name = "ids", value = "被检设备id", required = true)
public HttpResult<Object> delete(@RequestBody @Validated PqDevParam.DeleteParam param) {
public HttpResult<Boolean> delete(@RequestBody @Validated PqDevParam.DeleteParam param) {
String methodDescribe = getMethodDescribe("delete");
LogUtil.njcnDebug(log, "{}删除ID数据为{}", methodDescribe, String.join(StrUtil.COMMA, param.getIds()));
boolean result = pqDevService.deletePqDev(param);
if (result) {
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, methodDescribe);
} else {
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, null, methodDescribe);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, false, methodDescribe);
}
}
@OperateInfo(info = LogEnum.BUSINESS_COMMON, operateType = OperateType.DOWNLOAD)
@PostMapping("/export")
@ApiOperation("导出被检设备数据")
@ApiOperation("批量导出被检设备")
@ApiImplicitParam(name = "queryParam", value = "查询参数", required = true)
public void export(@RequestBody @Validated PqDevParam.QueryParam queryParam) {
String methodDescribe = getMethodDescribe("export");
public void exportDev(@RequestBody @Validated PqDevParam.QueryParam queryParam) {
String methodDescribe = getMethodDescribe("exportDev");
LogUtil.njcnDebug(log, "{},查询数据为:{}", methodDescribe, queryParam);
DictData dictData = dictDataService.getDictDataById(queryParam.getPattern());
if (ObjectUtil.isNotNull(dictData)) {
if (PatternEnum.CONTRAST.getValue().equals(dictData.getCode())) {
List<PqDevExcel.ContrastExportData> data = pqDevService.getContrastExportData(queryParam);
ExcelUtil.exportExcel("被检设备导出数据.xlsx", PqDevExcel.ContrastExportData.class, data);
} else {
List<PqDevExcel.SimulateOrDigitalExportData> data = pqDevService.getSimulateOrDigitExportData(queryParam);
ExcelUtil.exportExcel("被检设备导出数据.xlsx", PqDevExcel.SimulateOrDigitalExportData.class, data);
}
}
pqDevService.exportDev(queryParam);
}
@OperateInfo(info = LogEnum.BUSINESS_COMMON, operateType = OperateType.DOWNLOAD)
@@ -175,102 +134,20 @@ public class PqDevController extends BaseController {
}
@OperateInfo(info = LogEnum.BUSINESS_COMMON, operateType = OperateType.UPLOAD)
@PostMapping(value = "/importContrast")
@ApiOperation("批量导入被检设备数据")
@ApiImplicitParam(name = "file", value = "被检设备数据文件", required = true)
public HttpResult<Object> importContrastData(@RequestParam("file") MultipartFile file, HttpServletResponse response) {
String methodDescribe = getMethodDescribe("importContrastData");
@PostMapping(value = "/import")
@ApiOperation("批量导入被检设备")
@ApiImplicitParams({
@ApiImplicitParam(name = "file", value = "被检设备数据文件", required = true),
@ApiImplicitParam(name = "patternId", value = "模式id", required = true)
})
public HttpResult<Object> importDev(@RequestParam("file") MultipartFile file, @RequestParam("patternId") String patternId, HttpServletResponse response) {
String methodDescribe = getMethodDescribe("importDev");
LogUtil.njcnDebug(log, "{},上传文件为:{}", methodDescribe, file.getOriginalFilename());
ImportParams params = new ImportParams();
params.setHeadRows(2);
params.setNeedVerify(true);
params.setStartSheetIndex(0);
params.setSheetNum(1);
try {
ExcelImportResult<PqDevExcel.ContrastImportData> excelImportResult = ExcelImportUtil.importExcelMore(file.getInputStream(), PqDevExcel.ContrastImportData.class, params);
//如果存在非法数据,将不合格的数据导出
if (excelImportResult.isVerifyFail()) {
// 此处前端要做特殊处理,具体可以参考技术监督的数据导入
Workbook failWorkbook = excelImportResult.getFailWorkbook();
PoiUtil.exportFileByWorkbook(failWorkbook, "非法被检设备数据.xlsx", response);
} else {
//批量录入数据
List<PqDevExcel.ContrastImportData> list = excelImportResult.getList();
pqDevService.importContrastData(list);
}
} catch (Exception e) {
throw new BusinessException(DevResponseEnum.IMPORT_DATA_FAIL);
}
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
}
/**
* 导出灿能二楼设备
*
* @param queryParam
*/
@OperateInfo(info = LogEnum.BUSINESS_COMMON, operateType = OperateType.DOWNLOAD)
@PostMapping("/exportCNDev")
@ApiOperation("导出被检设备数据")
@ApiImplicitParam(name = "queryParam", value = "查询参数", required = true)
public void exportCNDev(@RequestBody @Validated PqDevParam.QueryParam queryParam) {
String methodDescribe = getMethodDescribe("exportCNDev");
LogUtil.njcnDebug(log, "{},查询数据为:{}", methodDescribe, queryParam);
pqDevService.exportCNDev(queryParam);
}
/**
* 下载灿能二楼设备导入文件模板
*/
@OperateInfo(info = LogEnum.BUSINESS_COMMON, operateType = OperateType.DOWNLOAD)
@PostMapping("/downloadCNDevTemplate")
@ApiOperation("下载被检设备导入文件模板")
public void downloadCNDevTemplate() {
pqDevService.downloadCNDevTemplate();
}
/**
* 导入灿能二楼设备
*/
@OperateInfo(info = LogEnum.BUSINESS_COMMON, operateType = OperateType.UPLOAD)
@PostMapping(value = "/importCNDev")
@ApiOperation("批量导入设备数据")
@ApiImplicitParam(name = "file", value = "被检设备数据文件", required = true)
public HttpResult<String> importCNDev(@RequestParam("file") MultipartFile file, String patternId, HttpServletResponse response) {
String methodDescribe = getMethodDescribe("importCNDev");
LogUtil.njcnDebug(log, "{},上传文件为:{}", methodDescribe, file.getOriginalFilename());
boolean fileType = FileUtil.judgeFileIsExcel(file.getOriginalFilename());
if (!fileType) {
throw new BusinessException(CommonResponseEnum.FILE_XLSX_ERROR);
}
ImportParams params = new ImportParams();
params.setStartSheetIndex(0);
params.setSheetNum(1);
params.setHeadRows(1);
params.setNeedVerify(true);
List<CNDevExcel> cnDevExcelList;
try {
ExcelImportResult<CNDevExcel> excelImportResult = ExcelImportUtil.importExcelMore(file.getInputStream(), CNDevExcel.class, params);
if (excelImportResult.isVerifyFail()) {
// 此处前端要做特殊处理,具体可以参考技术监督的数据导入
Workbook failWorkbook = excelImportResult.getFailWorkbook();
PoiUtil.exportFileByWorkbook(failWorkbook, "非法被检设备数据.xlsx", response);
// throw new BusinessException(DevResponseEnum.IMPORT_DATA_FORMAT_FAIL);
return null;
} else {
cnDevExcelList = excelImportResult.getList();
}
} catch (Exception e) {
throw new BusinessException(DevResponseEnum.IMPORT_DATA_FAIL);
}
if (ObjectUtil.isNotEmpty(cnDevExcelList)) {
pqDevService.importCNDev(cnDevExcelList, patternId);
}
pqDevService.importDev(file, patternId, null, response);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
}
@@ -310,29 +187,14 @@ public class PqDevController extends BaseController {
@PostMapping("/documented")
@ApiOperation("设备归档")
@ApiImplicitParam(name = "id", value = "设备id", required = true)
public HttpResult<List<PqDev>> documented(@RequestBody List<String> ids) {
public HttpResult<Boolean> documented(@RequestBody List<String> ids) {
String methodDescribe = getMethodDescribe("documented");
LogUtil.njcnDebug(log, "{}设备id为{}", methodDescribe, ids);
boolean result = pqDevService.documented(ids);
if (result) {
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, methodDescribe);
} else {
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, null, methodDescribe);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, false, methodDescribe);
}
}
// @OperateInfo(operateType = OperateType.UPDATE)
// @PostMapping("/bindDev")
// @ApiOperation("检测计划绑定设备")
// @ApiImplicitParam(name = "bindPlanParam", value = "绑定参数", required = true)
// public HttpResult<Object> bindDev(@RequestBody @Validated PqDevParam.BindPlanParam bindPlanParam) {
// String methodDescribe = getMethodDescribe("bindDev");
// LogUtil.njcnDebug(log, "{}绑定计划数据为planId={}, pqDevIds={}", methodDescribe, bindPlanParam.getPlanId(), String.join(StrUtil.COMMA, bindPlanParam.getPqDevIds()));
// boolean result = pqDevService.bind(bindPlanParam.getPlanId(), bindPlanParam.getPqDevIds());
// if (result) {
// return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
// } else {
// return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, null, methodDescribe);
// }
// }
}

View File

@@ -26,8 +26,27 @@ public interface PqDevMapper extends MPJBaseMapper<PqDev> {
void updateReportState(@Param("id")String id);
/**
* 修改检测计划的检测结果
*
* @param planId
* @param checkResult
*/
void updatePlanCheckResult(@Param("planId")String planId, @Param("checkResult")Integer checkResult);
/**
* 修改检测计划的检测状态
*
* @param planId
* @param testState
*/
void updatePlanTestState(@Param("planId")String planId, @Param("testState")Integer testState);
/**
* 根据计划id获取脚本id
*
* @param planId
*/
String getScriptIdByPlanId(String planId);
}

View File

@@ -66,6 +66,8 @@
update ad_plan set Test_State = #{testState} where id = #{planId}
</update>
<select id="getScriptIdByPlanId" resultType="java.lang.String">
SELECT Script_Id FROM ad_plan WHERE id = #{planId}
</select>
</mapper>

View File

@@ -1,37 +0,0 @@
package com.njcn.gather.device.pojo.enums;
import lombok.Getter;
@Getter
public enum DevResponseEnum {
//NAME_REPEAT("A001001", "名称重复"),
IMPORT_DATA_FAIL("A001002", "导入数据失败"),
SERIES_AND_DEVKEY_NOT_BLANK("A001003", "当为加密设备时,加密设备的序列号和设备密钥不能为空"),
PQ_SOURCE_GEN_NAME_ERROR("A001004", "检测源生成名称出错"),
ERR_SOURCE_GEN_NAME_ERROR("A001005", "误差体系生成名称出错"),
PQ_ERRSYS_GEN_NAME_ERROR("A001005", "误差体系生成名称出错"),
PLAN_HAS_DEVICE_BIND("A001006", "检测计划下已绑定设备,请先解绑设备"),
PQ_DEV_REPEAT("A001007", "重复的被检设备"),
PQ_DEV_HAS_MONITOR("A001008", "该设备下关联有监测点,请先移除监测点"),
HAS_NOT_UNCHECKED_DEVICE("A001009", "设备在检测中或已被检测过,请勿解除绑定"),
IMPORT_PLAN_DATA_FAIL("A001010", "导入的检测计划为空"),
IMPORT_DATA_FORMAT_FAIL("A001011", "导入数据格式错误"),
IMPORT_SOURCE_ERROR("A001012","当前模式下一个检测计划只能有一个检测源" ),
IMPORT_DATASOURCE_ERROR("A001013","当前模式下一个检测计划只能有一个数据源" ),
DEV_UN_CHECKED("A001013","装置还未检测完成!" ),
DEV_UN_REPORT("A001013","装置报告未生成!" ),
DEVICE_DIS_ERROR("A001014","装置配置异常" ),
DEVICE_DELETE("A001015","设备无法删除,已绑定计划!" )
;
private final String message;
private final String code;
DevResponseEnum(String code, String message) {
this.code = code;
this.message = message;
}
}

View File

@@ -2,7 +2,7 @@ package com.njcn.gather.device.pojo.param;
import com.njcn.common.pojo.constant.PatternRegex;
import com.njcn.gather.monitor.pojo.param.PqMonitorParam;
import com.njcn.gather.device.pojo.constant.DevValidMessage;
import com.njcn.gather.pojo.constant.DetectionValidMessage;
import com.njcn.web.pojo.annotation.DateTimeStrValid;
import com.njcn.web.pojo.param.BaseParam;
import io.swagger.annotations.ApiModelProperty;
@@ -22,61 +22,53 @@ import java.util.List;
public class PqDevParam {
@ApiModelProperty(value = "名称", required = true)
//@NotBlank(message = DevValidMessage.NAME_NOT_BLANK)
//@Pattern(regexp = PatternRegex.DEV_NAME_REGEX, message = DevValidMessage.NAME_FORMAT_ERROR)
private String name;
@ApiModelProperty(value = "设备模式,字典表(数字、模拟、比对)", required = true)
@NotBlank(message = DevValidMessage.PATTERN_NOT_BLANK)
@Pattern(regexp = PatternRegex.SYSTEM_ID, message = DevValidMessage.PATTERN_FORMAT_ERROR)
@NotBlank(message = DetectionValidMessage.PATTERN_NOT_BLANK)
@Pattern(regexp = PatternRegex.SYSTEM_ID, message = DetectionValidMessage.PATTERN_FORMAT_ERROR)
private String pattern;
@ApiModelProperty(value = "设备类型,字典表", required = true)
@NotBlank(message = DevValidMessage.DEV_TYPE_NOT_BLANK)
@Pattern(regexp = PatternRegex.SYSTEM_ID, message = DevValidMessage.DEV_TYPE_FORMAT_ERROR)
@NotBlank(message = DetectionValidMessage.DEV_TYPE_NOT_BLANK)
@Pattern(regexp = PatternRegex.SYSTEM_ID, message = DetectionValidMessage.DEV_TYPE_FORMAT_ERROR)
private String devType;
@ApiModelProperty(value = "设备厂家,字典表", required = true)
//@NotBlank(message = DevValidMessage.MANUFACTURER_NOT_BLANK)
//@Pattern(regexp = PatternRegex.SYSTEM_ID, message = DevValidMessage.MANUFACTURER_FORMAT_ERROR)
private String manufacturer;
@ApiModelProperty(value = "出厂日期", required = true)
//@NotBlank(message = DevValidMessage.CREATEDATETIME_NOT_NULL)
//@DateTimeStrValid(format = "yyyy-MM-dd", message = DevValidMessage.CREATEDATETIME_FORMAT_ERROR)
private String createDate;
@ApiModelProperty(value = "设备序列号", required = true)
@NotBlank(message = DevValidMessage.FACTORYNO_NOT_BLANK)
@NotBlank(message = DetectionValidMessage.FACTORYNO_NOT_BLANK)
private String createId;
@ApiModelProperty(value = "固件版本", required = true)
//@NotBlank(message = DevValidMessage.FIRMWARE_NOT_BLANK)
private String hardwareVersion;
@ApiModelProperty(value = "软件版本", required = true)
//@NotBlank(message = DevValidMessage.SOFTWARE_NOT_BLANK)
private String softwareVersion;
@ApiModelProperty(value = "通讯协议", required = true)
@NotBlank(message = DevValidMessage.PROTOCOL_NOT_BLANK)
@Pattern(regexp = PatternRegex.SYSTEM_ID, message = DevValidMessage.PROTOCOL_FORMAT_ERROR)
@NotBlank(message = DetectionValidMessage.PROTOCOL_NOT_BLANK)
@Pattern(regexp = PatternRegex.SYSTEM_ID, message = DetectionValidMessage.PROTOCOL_FORMAT_ERROR)
private String protocol;
@ApiModelProperty(value = "IP地址", required = true)
@NotBlank(message = DevValidMessage.IP_NOT_BLANK)
@Pattern(regexp = PatternRegex.IP_REGEX, message = DevValidMessage.IP_FORMAT_ERROR)
@NotBlank(message = DetectionValidMessage.IP_NOT_BLANK)
@Pattern(regexp = PatternRegex.IP_REGEX, message = DetectionValidMessage.IP_FORMAT_ERROR)
private String ip;
@ApiModelProperty(value = "端口号", required = true)
@NotNull(message = DevValidMessage.PORT_NOT_NULL)
@Range(min = 1, max = 65535, message = DevValidMessage.PORT_RANGE_ERROR)
@NotNull(message = DetectionValidMessage.PORT_NOT_NULL)
@Range(min = 1, max = 65535, message = DetectionValidMessage.PORT_RANGE_ERROR)
private Integer port;
@ApiModelProperty(value = "装置是否为加密版本", required = true)
@NotNull(message = DevValidMessage.ENCRYPTION_NOT_NULL)
@Min(value = 0, message = DevValidMessage.ENCRYPTION_FLAG_FORMAT_ERROR)
@Max(value = 1, message = DevValidMessage.ENCRYPTION_FLAG_FORMAT_ERROR)
@NotNull(message = DetectionValidMessage.ENCRYPTION_NOT_NULL)
@Min(value = 0, message = DetectionValidMessage.ENCRYPTION_FLAG_FORMAT_ERROR)
@Max(value = 1, message = DetectionValidMessage.ENCRYPTION_FLAG_FORMAT_ERROR)
private Integer encryptionFlag;
@ApiModelProperty("装置识别码3ds加密")
@@ -89,7 +81,7 @@ public class PqDevParam {
private String sampleId;
@ApiModelProperty(value = "送样日期")
@DateTimeStrValid(message = DevValidMessage.ARRIVE_DATE_FORMAT_ERROR)
@DateTimeStrValid(message = DetectionValidMessage.ARRIVE_DATE_FORMAT_ERROR)
private String arrivedDate;
@ApiModelProperty("所属地市名称")
@@ -108,13 +100,13 @@ public class PqDevParam {
private String qrCode;
@ApiModelProperty(value = "检测次数,默认为0", required = true)
@NotNull(message = DevValidMessage.RECHECK_NUM_NOT_NULL)
@Min(value = 0, message = DevValidMessage.RECHECK_NUM_FORMAT_ERROR)
@NotNull(message = DetectionValidMessage.RECHECK_NUM_NOT_NULL)
@Min(value = 0, message = DetectionValidMessage.RECHECK_NUM_FORMAT_ERROR)
private Integer reCheckNum;
@ApiModelProperty("是否支持系数校准")
@Min(value = 0, message = DevValidMessage.FACTOR_FLAG_FORMAT_ERROR)
@Max(value = 1, message = DevValidMessage.FACTOR_FLAG_FORMAT_ERROR)
@Min(value = 0, message = DetectionValidMessage.FACTOR_FLAG_FORMAT_ERROR)
@Max(value = 1, message = DetectionValidMessage.FACTOR_FLAG_FORMAT_ERROR)
private String factorFlag;
@ApiModelProperty("监测点台账列表")
@@ -123,9 +115,6 @@ public class PqDevParam {
@ApiModelProperty("icdId")
private String icdId;
//
// @ApiModelProperty("power")
// private String power;
@ApiModelProperty("预投计划")
private String preinvestmentPlan;
@@ -138,29 +127,9 @@ public class PqDevParam {
public static class UpdateParam extends PqDevParam {
@ApiModelProperty(value = "id", required = true)
@NotBlank(message = DevValidMessage.ID_NOT_BLANK)
@Pattern(regexp = PatternRegex.SYSTEM_ID, message = DevValidMessage.ID_FORMAT_ERROR)
@NotBlank(message = DetectionValidMessage.ID_NOT_BLANK)
@Pattern(regexp = PatternRegex.SYSTEM_ID, message = DetectionValidMessage.ID_FORMAT_ERROR)
private String id;
// @ApiModelProperty("检测状态")
// @Min(value = 0, message = DevValidMessage.CHECK_STATE_FORMAT_ERROR)
// @Max(value = 3, message = DevValidMessage.CHECK_STATE_FORMAT_ERROR)
// private Integer checkState;
//
// @ApiModelProperty("检测结果")
// @Min(value = 0, message = DevValidMessage.CHECK_RESULT_FORMAT_ERROR)
// @Max(value = 2, message = DevValidMessage.CHECK_RESULT_FORMAT_ERROR)
// private Integer checkResult;
//
// @ApiModelProperty("报告状态")
// @Min(value = 0, message = DevValidMessage.REPORT_STATE_FORMAT_ERROR)
// @Max(value = 2, message = DevValidMessage.REPORT_STATE_FORMAT_ERROR)
// private Integer reportState;
//
// @ApiModelProperty("归档状态")
// @Min(value = 0, message = DevValidMessage.DOCUMENT_STATE_FORMAT_ERROR)
// @Max(value = 1, message = DevValidMessage.DOCUMENT_STATE_FORMAT_ERROR)
// private Integer documentState;
}
/**
@@ -170,7 +139,6 @@ public class PqDevParam {
@EqualsAndHashCode(callSuper = true)
public static class QueryParam extends BaseParam {
@ApiModelProperty("名称")
// @Pattern(regexp = PatternRegex.DEV_NAME_REGEX, message = DevValidMessage.NAME_FORMAT_ERROR)
private String name;
@ApiModelProperty(value = "设备模式,字典表(数字、模拟、比对)")
@@ -180,22 +148,21 @@ public class PqDevParam {
private String manufacturer;
@ApiModelProperty("检测计划ID")
//@Pattern(regexp = PatternRegex.SYSTEM_ID, message = DevValidMessage.PLAN_ID_FORMAT_ERROR)
private String planId;
@ApiModelProperty("检测状态列表")
private List<
@Min(value = 0, message = DevValidMessage.CHECK_STATE_FORMAT_ERROR)
@Max(value = 3, message = DevValidMessage.CHECK_STATE_FORMAT_ERROR) Integer> checkStateList;
@Min(value = 0, message = DetectionValidMessage.CHECK_STATE_FORMAT_ERROR)
@Max(value = 3, message = DetectionValidMessage.CHECK_STATE_FORMAT_ERROR) Integer> checkStateList;
@ApiModelProperty("检测结果")
@Min(value = 0, message = DevValidMessage.CHECK_RESULT_FORMAT_ERROR)
@Max(value = 2, message = DevValidMessage.CHECK_RESULT_FORMAT_ERROR)
@Min(value = 0, message = DetectionValidMessage.CHECK_RESULT_FORMAT_ERROR)
@Max(value = 2, message = DetectionValidMessage.CHECK_RESULT_FORMAT_ERROR)
private Integer checkResult;
@ApiModelProperty("报告状态")
@Min(value = 0, message = DevValidMessage.REPORT_STATE_FORMAT_ERROR)
@Max(value = 2, message = DevValidMessage.REPORT_STATE_FORMAT_ERROR)
@Min(value = 0, message = DetectionValidMessage.REPORT_STATE_FORMAT_ERROR)
@Max(value = 2, message = DetectionValidMessage.REPORT_STATE_FORMAT_ERROR)
private Integer reportState;
}
@@ -203,23 +170,23 @@ public class PqDevParam {
@Data
public static class DeleteParam {
@ApiModelProperty(value = "ids")
private List<@Pattern(regexp = PatternRegex.SYSTEM_ID, message = DevValidMessage.ID_FORMAT_ERROR) String> ids;
private List<@Pattern(regexp = PatternRegex.SYSTEM_ID, message = DetectionValidMessage.ID_FORMAT_ERROR) String> ids;
@ApiModelProperty(value = "设备模式,字典表(数字、模拟、比对)", required = true)
@NotBlank(message = DevValidMessage.PATTERN_NOT_BLANK)
@Pattern(regexp = PatternRegex.SYSTEM_ID, message = DevValidMessage.PATTERN_FORMAT_ERROR)
@NotBlank(message = DetectionValidMessage.PATTERN_NOT_BLANK)
@Pattern(regexp = PatternRegex.SYSTEM_ID, message = DetectionValidMessage.PATTERN_FORMAT_ERROR)
private String pattern;
}
@Data
public static class BindPlanParam {
@ApiModelProperty("检测计划ID")
@NotNull(message = DevValidMessage.PLAN_ID_NOT_NULL)
@Pattern(regexp = PatternRegex.SYSTEM_ID, message = DevValidMessage.PLAN_ID_FORMAT_ERROR)
@NotNull(message = DetectionValidMessage.PLAN_ID_NOT_NULL)
@Pattern(regexp = PatternRegex.SYSTEM_ID, message = DetectionValidMessage.PLAN_ID_FORMAT_ERROR)
private String planId;
@ApiModelProperty("被检设备ID列表")
@NotNull(message = DevValidMessage.PQ_DEV_IDS_NOT_NULL)
@NotNull(message = DetectionValidMessage.PQ_DEV_IDS_NOT_NULL)
private List<String> pqDevIds;
}
}

View File

@@ -195,6 +195,9 @@ public class PqDev extends BaseEntity implements Serializable {
@TableField("Check_Time")
private LocalDateTime checkTime;
@TableField("Check_By")
private String checkBy;
@TableField("Preinvestment_Plan")
private String preinvestmentPlan;

View File

@@ -2,9 +2,8 @@ package com.njcn.gather.device.pojo.vo;
import cn.afterturn.easypoi.excel.annotation.Excel;
import com.njcn.common.pojo.constant.PatternRegex;
import com.njcn.gather.device.pojo.constant.DevValidMessage;
import com.njcn.gather.pojo.constant.DetectionValidMessage;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.hibernate.validator.constraints.Range;
import javax.validation.constraints.NotBlank;
@@ -19,41 +18,42 @@ import javax.validation.constraints.Pattern;
public class CNDevExcel {
@Excel(name = "预投计划*", width = 20, orderNum = "1")
@NotBlank(message = DetectionValidMessage.PREINVESTMENT_PLAN_NOT_BLANK)
private String preinvestmentPlan;
@Excel(name = "设备编号(开始编号-结束编号,编号为数字)*", width = 50, orderNum = "2")
@NotBlank(message = DevValidMessage.NAME_NOT_BLANK)
@Pattern(regexp = PatternRegex.CN_DEV_NAME_REGEX, message = DevValidMessage.NAME_FORMAT_ERROR)
@NotBlank(message = DetectionValidMessage.NAME_NOT_BLANK)
@Pattern(regexp = PatternRegex.CN_DEV_NAME_REGEX, message = DetectionValidMessage.NAME_FORMAT_ERROR)
private String name;
@Excel(name = "设备类型*", width = 20, orderNum = "3")
@NotBlank(message = DevValidMessage.DEV_TYPE_NOT_BLANK)
@NotBlank(message = DetectionValidMessage.DEV_TYPE_NOT_BLANK)
private String devType;
@Excel(name = "通讯协议*", width = 15, orderNum = "4")
@NotBlank(message = DevValidMessage.PROTOCOL_NOT_BLANK)
@NotBlank(message = DetectionValidMessage.PROTOCOL_NOT_BLANK)
private String protocol;
@Excel(name = "是否加密*", width = 20, replace = {"否_0", "是_1"}, orderNum = "5")
@NotNull(message = DevValidMessage.ENCRYPTION_NOT_NULL)
@NotNull(message = DetectionValidMessage.ENCRYPTION_NOT_NULL)
private Integer encryptionFlag;
@Excel(name = "识别码", width = 30, orderNum = "6")
@Excel(name = "识别码(当加密时必填)", width = 30, orderNum = "6")
private String series;
@Excel(name = "秘钥", width = 30, orderNum = "7")
@Excel(name = "秘钥(当加密时必填)", width = 30, orderNum = "7")
private String devKey;
@Excel(name = "是否支持系数校准*", width = 25, replace = {"否_0", "是_1"}, orderNum = "8")
private Integer factorFlag;
@Excel(name = "IP地址*", width = 20, replace = {"否_0", "是_1"}, orderNum = "9")
@NotBlank(message = DevValidMessage.IP_NOT_BLANK)
@Pattern(regexp = PatternRegex.IP_REGEX, message = DevValidMessage.IP_FORMAT_ERROR)
@Excel(name = "IP地址*", width = 20, orderNum = "9")
@NotBlank(message = DetectionValidMessage.IP_NOT_BLANK)
@Pattern(regexp = PatternRegex.IP_REGEX, message = DetectionValidMessage.IP_FORMAT_ERROR)
private String ip;
@Excel(name = "端口号*", width = 15, orderNum = "10")
@NotNull(message = DevValidMessage.PORT_NOT_NULL)
@Range(min = 1, max = 65535, message = DevValidMessage.PORT_RANGE_ERROR)
@NotNull(message = DetectionValidMessage.PORT_NOT_NULL)
@Range(min = 1, max = 65535, message = DetectionValidMessage.PORT_RANGE_ERROR)
private Integer port;
}

View File

@@ -1,211 +0,0 @@
package com.njcn.gather.device.pojo.vo;
import cn.afterturn.easypoi.excel.annotation.Excel;
import cn.afterturn.easypoi.excel.annotation.ExcelCollection;
import com.njcn.common.pojo.constant.PatternRegex;
import com.njcn.gather.monitor.pojo.vo.PqMonitorExcel;
import com.njcn.gather.device.pojo.constant.DevValidMessage;
import com.njcn.web.pojo.annotation.DateTimeStrValid;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.hibernate.validator.constraints.Range;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import java.io.Serializable;
import java.time.LocalDate;
import java.util.List;
/**
* @author caozehui
* @data 2024/11/7
*/
@Data
public class PqDevExcel implements Serializable {
private static final long serialVersionUID = 1L;
@Excel(name = "名称", width = 20, needMerge = true)
@NotBlank(message = DevValidMessage.NAME_NOT_BLANK)
@Pattern(regexp = PatternRegex.DEV_NAME_REGEX, message = DevValidMessage.NAME_FORMAT_ERROR)
private String name;
@Excel(name = "设备类型", width = 20, orderNum = "2", needMerge = true)
@NotBlank(message = DevValidMessage.DEV_TYPE_NOT_BLANK)
private String devType;
@Excel(name = "设备通道数", width = 20, orderNum = "3", needMerge = true)
@NotNull(message = DevValidMessage.DEV_CHNS_NOT_NULL)
private Integer devChns;
@Excel(name = "额定电压V", width = 15, orderNum = "4", needMerge = true)
@NotNull(message = DevValidMessage.DEV_VOLT_NOT_NULL)
private Float devVolt;
@Excel(name = "额定电流A", width = 15, orderNum = "5", needMerge = true)
@NotNull(message = DevValidMessage.DEV_CURR_NOT_NULL)
private Float devCurr;
@Excel(name = "设备厂家", width = 20, orderNum = "6", needMerge = true)
@NotBlank(message = DevValidMessage.MANUFACTURER_NOT_BLANK)
private String manufacturer;
@Excel(name = "设备序列号", width = 40, orderNum = "8", needMerge = true)
@NotBlank(message = DevValidMessage.FACTORYNO_NOT_BLANK)
private String createId;
@Excel(name = "固件版本", width = 15, orderNum = "9", needMerge = true)
@NotBlank(message = DevValidMessage.FIRMWARE_NOT_BLANK)
private String hardwareVersion;
@Excel(name = "软件版本", width = 15, orderNum = "10", needMerge = true)
@NotBlank(message = DevValidMessage.SOFTWARE_NOT_BLANK)
private String softwareVersion;
@Excel(name = "通讯协议", width = 15, orderNum = "11", needMerge = true)
@NotBlank(message = DevValidMessage.PROTOCOL_NOT_BLANK)
private String protocol;
@Excel(name = "IP地址", width = 20, orderNum = "12", needMerge = true)
@NotBlank(message = DevValidMessage.IP_NOT_BLANK)
@Pattern(regexp = PatternRegex.IP_REGEX, message = DevValidMessage.IP_FORMAT_ERROR)
private String ip;
@Excel(name = "端口号", orderNum = "13", needMerge = true)
@NotNull(message = DevValidMessage.PORT_NOT_NULL)
@Range(min = 1, max = 65535, message = DevValidMessage.PORT_RANGE_ERROR)
private Integer port;
@Excel(name = "是否为加密版本(否\\是)", width = 20, replace = {"否_0", "是_1"}, orderNum = "14", needMerge = true)
@NotNull(message = DevValidMessage.ENCRYPTION_NOT_NULL)
private Integer encryptionFlag;
@Excel(name = "识别码(当为加密版本时必填)", width = 30, orderNum = "15", needMerge = true)
private String series;
@Excel(name = "秘钥(当为加密版本时必填)", width = 30, orderNum = "16", needMerge = true)
private String devKey;
@Excel(name = "所属地市名称", width = 20, orderNum = "19", needMerge = true)
private String cityName;
@Excel(name = "所属供电公司名称", width = 20, orderNum = "20", needMerge = true)
private String gdName;
@Excel(name = "所属电站名称", width = 20, orderNum = "21", needMerge = true)
private String subName;
@Excel(name = "关键信息二维码", width = 20, orderNum = "30", needMerge = true)
private String qrCode;
@Excel(name = "检测次数", width = 15, orderNum = "31", needMerge = true)
@NotNull(message = DevValidMessage.RECHECK_NUM_NOT_NULL)
private Integer reCheckNum;
@Data
@EqualsAndHashCode(callSuper = true)
public static class ExportData extends PqDevExcel {
@Excel(name = "设备模式", width = 20, orderNum = "1", needMerge = true)
@NotBlank(message = DevValidMessage.PATTERN_NOT_BLANK)
private String pattern;
@Excel(name = "出厂日期yyyy-MM-dd", width = 25, format = "yyyy-MM-dd", orderNum = "7", needMerge = true)
@NotNull(message = DevValidMessage.CREATEDATETIME_NOT_NULL)
private LocalDate createDate;
@Excel(name = "是否支持系数校准(否\\是)", width = 15, replace = {"否_0", "是_1"}, orderNum = "22", needMerge = true)
private Integer factorFlag;
@Excel(name = "守时检测结果(不合格\\合格\\/", replace = {"不合格_0", "合格_1", "/_2"}, width = 15, orderNum = "23", needMerge = true)
private Integer timeCheckResult;
@Excel(name = "系数校准结果(不合格\\合格\\/", width = 15, replace = {"不合格_0", "合格_1", "/_2"}, orderNum = "24", needMerge = true)
private Integer factorCheckResult;
@Excel(name = "检测状态(未检\\检测中\\检测完成\\归档)", width = 15, replace = {"未检_0", "检测中_1", "检测完成_2", "归档_3"}, orderNum = "25", needMerge = true)
private Integer checkState;
@Excel(name = "检测结果(不符合\\符合\\未检)", width = 15, replace = {"不符合_0", "符合_1", "未检_2"}, orderNum = "26", needMerge = true)
private Integer checkResult;
@Excel(name = "报告状态(未生成\\已生成\\未检)", width = 15, replace = {"未生成_0", "已生成_1", "未检_2"}, orderNum = "27", needMerge = true)
private Integer reportState;
// @Excel(name = "归档状态(未归档\\归档)", width = 15, replace = {"未归档_0", "归档_1"}, orderNum = "28", needMerge = true)
// private Integer documentState;
@Excel(name = "报告路径", width = 20, orderNum = "29", needMerge = true)
private String reportPath;
}
/**
* 模拟式和比对式设备导出数据
*/
@Data
@EqualsAndHashCode(callSuper = true)
public static class SimulateOrDigitalExportData extends ExportData {
@Excel(name = "样品编号", width = 40, orderNum = "17", needMerge = true)
private String sampleId;
@Excel(name = "送样日期yyyy-MM-dd", width = 25, format = "yyyy-MM-dd", orderNum = "18", needMerge = true)
private LocalDate arrivedDate;
}
/**
* 比对式设备导出数据
*/
@Data
@EqualsAndHashCode(callSuper = true)
public static class ContrastExportData extends ExportData {
@ExcelCollection(name = "检测点台账", orderNum = "32")
List<PqMonitorExcel.ExportData> monitorList;
}
/**
* 被检设备导入数据
*/
@Data
@EqualsAndHashCode(callSuper = true)
public static class ImportData extends PqDevExcel {
@Excel(name = "出厂日期yyyy-MM-dd", width = 25, format = "yyyy-MM-dd", orderNum = "7", needMerge = true)
@NotNull(message = DevValidMessage.CREATEDATETIME_NOT_NULL)
@DateTimeStrValid(message = DevValidMessage.CREATEDATETIME_FORMAT_ERROR)
private String createDate;
@Excel(name = "是否支持系数校准(否\\是)", width = 15, replace = {"否_0", "是_1"}, orderNum = "22", needMerge = true)
@NotBlank(message = DevValidMessage.FACTOR_FLAG_NOT_BLANK)
private String factorFlag;
}
/**
* 模拟式和比对式设备导入数据
*/
@Data
@EqualsAndHashCode(callSuper = true)
public static class SimulateOrDigitalImportData extends ImportData {
@Excel(name = "样品编号", width = 40, orderNum = "17", needMerge = true)
private String sampleId;
@Excel(name = "送样日期yyyy-MM-dd", width = 25, format = "yyyy-MM-dd", orderNum = "18", needMerge = true)
@DateTimeStrValid(message = DevValidMessage.ARRIVE_DATE_FORMAT_ERROR)
private String arrivedDate;
}
/**
* 对比式设备导入数据
*/
@Data
@EqualsAndHashCode(callSuper = true)
public static class ContrastImportData extends ImportData {
@ExcelCollection(name = "检测点台账", orderNum = "32")
List<PqMonitorExcel.ImportData> monitorList;
}
}

View File

@@ -103,7 +103,7 @@ public class PreDetection {
/**
* 监测点线路号
*/
@JSONField(name = "pt")
@JSONField(name = "pt") //todo 是否改为ct
private Integer ct;
}

View File

@@ -0,0 +1,78 @@
package com.njcn.gather.device.pojo.vo;
import cn.afterturn.easypoi.excel.annotation.Excel;
import com.njcn.common.pojo.constant.PatternRegex;
import com.njcn.gather.pojo.constant.DetectionValidMessage;
import lombok.Data;
import org.hibernate.validator.constraints.Range;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import java.io.Serializable;
import java.time.LocalDate;
/**
* @author caozehui
* @data 2024/11/7
* @description 省级平台设备Excel导入导出实体类
*/
@Data
public class ProvinceDevExcel implements Serializable {
private static final long serialVersionUID = 1L;
@Excel(name = "装置编号*", width = 20)
@NotBlank(message = DetectionValidMessage.FACTORYNO_NOT_BLANK)
private String createId;
@Excel(name = "设备名称*", width = 20, orderNum = "2")
@NotBlank(message = DetectionValidMessage.NAME_NOT_BLANK)
@Pattern(regexp = PatternRegex.DEV_NAME_REGEX, message = DetectionValidMessage.NAME_FORMAT_ERROR)
private String name;
@Excel(name = "设备类型*", width = 20, orderNum = "3")
@NotBlank(message = DetectionValidMessage.DEV_TYPE_NOT_BLANK)
private String devType;
@Excel(name = "设备厂家*", width = 20, orderNum = "7")
@NotBlank(message = DetectionValidMessage.MANUFACTURER_NOT_BLANK)
private String manufacturer;
@Excel(name = "出厂日期*", width = 25, format = "yyyy-MM-dd", orderNum = "8")
@NotNull(message = DetectionValidMessage.CREATEDATETIME_NOT_NULL)
private LocalDate createDate;
@Excel(name = "固件版本", width = 15, orderNum = "9")
private String hardwareVersion;
@Excel(name = "软件版本", width = 15, orderNum = "10")
private String softwareVersion;
@Excel(name = "通讯协议*", width = 15, orderNum = "11")
@NotBlank(message = DetectionValidMessage.PROTOCOL_NOT_BLANK)
private String protocol;
@Excel(name = "是否加密*", width = 20, replace = {"否_0", "是_1"}, orderNum = "12")
@NotNull(message = DetectionValidMessage.ENCRYPTION_NOT_NULL)
private Integer encryptionFlag;
@Excel(name = "识别码(当加密时必填)", width = 30, orderNum = "13")
private String series;
@Excel(name = "秘钥(当加密时必填)", width = 30, orderNum = "14")
private String devKey;
@Excel(name = "是否支持系数校准*", width = 25, replace = {"否_0", "是_1"}, orderNum = "15")
private Integer factorFlag;
@Excel(name = "IP地址*", width = 20, orderNum = "16")
@NotBlank(message = DetectionValidMessage.IP_NOT_BLANK)
@Pattern(regexp = PatternRegex.IP_REGEX, message = DetectionValidMessage.IP_FORMAT_ERROR)
private String ip;
@Excel(name = "端口号*", width = 15, orderNum = "17")
@NotNull(message = DetectionValidMessage.PORT_NOT_NULL)
@Range(min = 1, max = 65535, message = DetectionValidMessage.PORT_RANGE_ERROR)
private Integer port;
}

View File

@@ -2,15 +2,18 @@ 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.gather.device.pojo.enums.TimeCheckResultEnum;
import com.njcn.gather.device.pojo.param.PqDevParam;
import com.njcn.gather.device.pojo.po.PqDev;
import com.njcn.gather.device.pojo.vo.CNDevExcel;
import com.njcn.gather.device.pojo.vo.PqDevExcel;
import com.njcn.gather.device.pojo.vo.PqDevVO;
import com.njcn.gather.device.pojo.vo.PreDetection;
import com.njcn.gather.device.pojo.vo.ProvinceDevExcel;
import org.apache.ibatis.annotations.Param;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;
@@ -67,7 +70,7 @@ public interface IPqDevService extends IService<PqDev> {
* @param queryParam 查询参数
* @return
*/
List<PqDevExcel.SimulateOrDigitalExportData> getSimulateOrDigitExportData(PqDevParam.QueryParam queryParam);
//List<PqDevExcel.SimulateOrDigitalExportData> getSimulateOrDigitExportData(PqDevParam.QueryParam queryParam);
/**
* 获取比对式设备导出时所需的数据
@@ -75,26 +78,21 @@ public interface IPqDevService extends IService<PqDev> {
* @param queryParam 查询参数
* @return 比对式设备导出时所需的数据
*/
List<PqDevExcel.ContrastExportData> getContrastExportData(PqDevParam.QueryParam queryParam);
/**
* 下载模板文件
*/
void downloadTemplate();
//List<PqDevExcel.ContrastExportData> getContrastExportData(PqDevParam.QueryParam queryParam);
/**
* 批量导入被检设备信息
*
* @param sgEventExcels 批量导入的数据
*/
void importContrastData(List<PqDevExcel.ContrastImportData> sgEventExcels);
//void importContrastData(List<PqDevExcel.ContrastImportData> sgEventExcels);
/**
* 批量导入被检设备信息
*
* @param sgEventExcels 批量导入的数据
*/
void importSimulateAndDigitalData(List<PqDevExcel.SimulateOrDigitalImportData> sgEventExcels);
//void importSimulateAndDigitalData(List<PqDevExcel.SimulateOrDigitalImportData> sgEventExcels);
/**
* 获取所有未绑定的设备
@@ -121,14 +119,6 @@ public interface IPqDevService extends IService<PqDev> {
*/
Integer bind(String planId, List<String> devIds);
/**
* 获取饼图数据
*
* @param planId 检测计划id
* @return 饼图数据
*/
//List<List<Map<String, Object>>> getPieData(String planId);
/**
* 根据id获取被检设备信息
*
@@ -137,25 +127,6 @@ public interface IPqDevService extends IService<PqDev> {
*/
PqDevVO getPqDevById(String id);
/**
* 获取所有非未检测状态的设备
*
* @return 所有非未检测状态的设备列表
*/
List<PqDev> listUnchecked();
/**
* 可视化各种id回显字典值解码等操作
*
* @param sourceList
*/
void visualize(List<PqDev> sourceList);
/**
* 逆向可视化
*/
void reverseVisualize(List<PqDev> sourceList);
/**
* 获取装置信息和装置下监测点信息
*
@@ -174,38 +145,131 @@ public interface IPqDevService extends IService<PqDev> {
*/
boolean documented(List<String> id);
/**
* 正式监测完成,修改中断状态
*
* @param ids
* @param valueType
* @param code
* @param userId
* @return
*/
boolean updateResult(List<String> ids, List<String> valueType, String code);
boolean updateResult(List<String> ids, List<String> valueType, String code,String userId);
void updatePqDevReportState(String devId, int i);
int countUnReportDev(String planId);
/**
* 导出灿能二楼设备数据
* 根据计划id列表获取设备列表
*
* @param planIds
* @return
*/
List<PqDev> listByPlanIds(List<String> planIds);
/**
* 导出设备数据
*
* @param queryParam
*/
void exportCNDev(PqDevParam.QueryParam queryParam);
void exportDev(PqDevParam.QueryParam queryParam);
/**
* 下载灿能二楼设备模板文件
* 下载模板文件
*/
void downloadCNDevTemplate();
void downloadTemplate();
/**
* 导入设备数据
*
* @param file 上传的文件
* @param patternId 模式Id
* @param planId 计划Id
* @param response 响应
*/
void importDev(MultipartFile file, String patternId, String planId, HttpServletResponse response);
/**
* 导入灿能二楼设备数据
*
* @param cnDevExcelList 灿能二楼设备数据列表
* @param patternId 模式Id
* @param file 上传的文件
* @param patternId 模式Id
* @param planId 计划Id
* @param response 响应
*/
void importCNDev(List<CNDevExcel> cnDevExcelList, String patternId);
void importCNDev(MultipartFile file, String patternId, String planId, HttpServletResponse response);
/**
* 导入灿能二楼设备数据
*
* @param cnDevExcelList
* @param patternId
* @param planId
*/
void importCNDev(List<CNDevExcel> cnDevExcelList, String patternId, String planId);
/**
* 可视化-灿能二楼设备
*
* @param pqDevs
*/
void visualizeCNDev(List<PqDev> pqDevs);
/**
* 逆向可视化-灿能二楼设备
*
* @param pqDevs 设备列表
* @param patternId 模式Id
*/
void reverseVisualizeCNDev(List<PqDev> pqDevs, String patternId);
/**
* 导入省级平台设备数据
*
* @param file 上传的文件
* @param patternId 模式Id
* @param planId 计划Id
* @param response 响应
*/
void importProvinceDev(MultipartFile file, String patternId, String planId, HttpServletResponse response);
/**
* 导入省级平台设备数据
*
* @param proviceDevExcelList
* @param patternId
* @param planId
*/
void importProvinceDev(List<ProvinceDevExcel> proviceDevExcelList, String patternId, String planId);
/**
* 可视化-省级平台设备
*
* @param pqDevs
*/
void visualizeProvinceDev(List<PqDev> pqDevs);
/**
* 逆向可视化-省级平台设备
*
* @param pqDevs 设备列表
* @param patternId 模式Id
*/
void reverseVisualizeProvinceDev(List<PqDev> pqDevs, String patternId);
/**
* 获取省级平台设备导出、导出文件模板的下拉列表
*
* @return
*/
List<PullDown> getProvinceDevPullDownList(int startCol);
/**
* 获取灿能二楼设备导出、导出文件模板的下拉列表
*
* @param startCol 开始列
* @return
*/
List<PullDown> getCNDevPullDownList(int startCol);
}

View File

@@ -63,14 +63,14 @@ public class PqErrSysController extends BaseController {
@PostMapping("/add")
@ApiOperation("新增误差体系")
@ApiImplicitParam(name = "param", value = "误差体系", required = true)
public HttpResult<Object> add(@RequestBody @Validated PqErrSysParam param) {
public HttpResult<Boolean> add(@RequestBody @Validated PqErrSysParam param) {
String methodDescribe = getMethodDescribe("add");
LogUtil.njcnDebug(log, "{},新增数据为:{}", methodDescribe, param);
boolean result = pqErrSysService.addPqErrSys(param);
if (result) {
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, methodDescribe);
} else {
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, null, methodDescribe);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, false, methodDescribe);
}
}
@@ -78,14 +78,14 @@ public class PqErrSysController extends BaseController {
@PostMapping("/update")
@ApiOperation("修改误差体系")
@ApiImplicitParam(name = "param", value = "误差体系", required = true)
public HttpResult<Object> update(@RequestBody @Validated PqErrSysParam.UpdateParam param) {
public HttpResult<Boolean> update(@RequestBody @Validated PqErrSysParam.UpdateParam param) {
String methodDescribe = getMethodDescribe("update");
LogUtil.njcnDebug(log, "{},修改数据为:{}", methodDescribe, param);
boolean result = pqErrSysService.updatePqErrSys(param);
if (result) {
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, methodDescribe);
} else {
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, null, methodDescribe);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, false, methodDescribe);
}
}
@@ -93,14 +93,14 @@ public class PqErrSysController extends BaseController {
@PostMapping("/delete")
@ApiOperation("删除误差体系")
@ApiImplicitParam(name = "ids", value = "误差体系id", required = true)
public HttpResult<Object> delete(@RequestBody List<String> ids) {
public HttpResult<Boolean> delete(@RequestBody List<String> ids) {
String methodDescribe = getMethodDescribe("delete");
LogUtil.njcnDebug(log, "{}删除ID数据为{}", methodDescribe, String.join(StrUtil.COMMA, ids));
boolean result = pqErrSysService.deletePqErrSys(ids);
if (result) {
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, methodDescribe);
} else {
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, null, methodDescribe);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, false, methodDescribe);
}
}
@@ -125,19 +125,19 @@ public class PqErrSysController extends BaseController {
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
}
// @OperateInfo(operateType = OperateType.ADD)
// @GetMapping("/copy")
// @ApiOperation("复制误差体系")
// @ApiImplicitParam(name = "id", value = "误差体系id", required = true)
// public HttpResult<Object> copy(@RequestParam("id") String id) {
// String methodDescribe = getMethodDescribe("copy");
// LogUtil.njcnDebug(log, "{}复制ID为{}", methodDescribe, id);
// boolean result = pqErrSysService.copyPqErrSys(id);
// if (result) {
// return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
// } else {
// return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, null, methodDescribe);
// }
// }
@OperateInfo(operateType = OperateType.ADD)
@GetMapping("/copy")
@ApiOperation("复制误差体系")
@ApiImplicitParam(name = "id", value = "误差体系id", required = true)
public HttpResult<Boolean> copy(@RequestParam("id") String id) {
String methodDescribe = getMethodDescribe("copy");
LogUtil.njcnDebug(log, "{}复制ID为{}", methodDescribe, id);
boolean result = pqErrSysService.copyPqErrSys(id);
if (result) {
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, methodDescribe);
} else {
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, false, methodDescribe);
}
}
}

View File

@@ -2,12 +2,20 @@ package com.njcn.gather.err.mapper;
import com.github.yulichang.base.MPJBaseMapper;
import com.njcn.gather.err.pojo.po.PqErrSys;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* @author caozehui
* @date 2024-11-27
*/
public interface PqErrSysMapper extends MPJBaseMapper<PqErrSys> {
/**
* 根据ids获取绑定的计划数量
* @param ids
* @return
*/
Integer getCountBoundByIds(@Param("ids") List<String> ids);
}

View File

@@ -3,5 +3,16 @@
<mapper namespace="com.njcn.gather.err.mapper.PqErrSysMapper">
<select id="getCountBoundByIds" resultType="java.lang.Integer">
SELECT COUNT(*) FROM ad_plan
<if test="ids!= null and ids.size() > 0">
<where>
AND Error_Sys_Id IN
<foreach collection="ids" item="id" open="(" separator="," close=")">
#{id}
</foreach>
</where>
</if>
</select>
</mapper>

View File

@@ -1,7 +1,7 @@
package com.njcn.gather.err.pojo.param;
import com.njcn.common.pojo.constant.PatternRegex;
import com.njcn.gather.device.pojo.constant.DevValidMessage;
import com.njcn.gather.pojo.constant.DetectionValidMessage;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@@ -17,13 +17,13 @@ import javax.validation.constraints.Pattern;
public class PqErrSysDtlsParam {
@ApiModelProperty(value = "误差项类型", required = true)
@NotBlank(message = DevValidMessage.ERR_SYS_DTLS_ERROR_TYPE_NOT_BLANK)
@Pattern(regexp = PatternRegex.SYSTEM_ID, message = DevValidMessage.ERR_SYS_DTLS_ERROR_TYPE_FORMAT_ERROR)
@NotBlank(message = DetectionValidMessage.ERR_SYS_DTLS_ERROR_TYPE_NOT_BLANK)
@Pattern(regexp = PatternRegex.SYSTEM_ID, message = DetectionValidMessage.ERR_SYS_DTLS_ERROR_TYPE_FORMAT_ERROR)
private String errorType;
@ApiModelProperty(value = "脚本项类型", required = true)
@NotBlank(message = DevValidMessage.ERR_SYS_DTLS_SCRIPT_TYPE_NOT_BLANK)
@Pattern(regexp = PatternRegex.SYSTEM_ID, message = DevValidMessage.ERR_SYS_DTLS_SCRIPT_TYPE_FORMAT_ERROR)
@NotBlank(message = DetectionValidMessage.ERR_SYS_DTLS_SCRIPT_TYPE_NOT_BLANK)
@Pattern(regexp = PatternRegex.SYSTEM_ID, message = DetectionValidMessage.ERR_SYS_DTLS_SCRIPT_TYPE_FORMAT_ERROR)
private String scriptType;
@ApiModelProperty(value = "误差判断起始值", required = true)
@@ -47,15 +47,15 @@ public class PqErrSysDtlsParam {
private Integer conditionType;
@ApiModelProperty(value = "最大值误差", required = true)
@NotNull(message = DevValidMessage.MAX_ERROR_VALUE_NOT_NULL)
@NotNull(message = DetectionValidMessage.MAX_ERROR_VALUE_NOT_NULL)
private Double maxErrorValue;
@ApiModelProperty(value = "误差值类型", required = true)
@NotNull(message = DevValidMessage.ERROR_VALUE_TYPE_NOT_BLANK)
@NotNull(message = DetectionValidMessage.ERROR_VALUE_TYPE_NOT_BLANK)
private Integer errorValueType;
@ApiModelProperty("排序")
@NotNull(message = DevValidMessage.SORT_NOT_NULL)
@NotNull(message = DetectionValidMessage.SORT_NOT_NULL)
private Integer sort;
}

View File

@@ -1,7 +1,7 @@
package com.njcn.gather.err.pojo.param;
import com.njcn.common.pojo.constant.PatternRegex;
import com.njcn.gather.device.pojo.constant.DevValidMessage;
import com.njcn.gather.pojo.constant.DetectionValidMessage;
import com.njcn.web.pojo.annotation.DateTimeStrValid;
import com.njcn.web.pojo.param.BaseParam;
import io.swagger.annotations.ApiModelProperty;
@@ -20,24 +20,24 @@ import java.util.List;
public class PqErrSysParam {
@ApiModelProperty(value = "参照标准名称", required = true)
@NotBlank(message = DevValidMessage.STANDARD_NAME_NOT_BLANK)
@Pattern(regexp = PatternRegex.ERR_SYS_NAME, message = DevValidMessage.STANDARD_NAME_FORMAT_ERROR)
@NotBlank(message = DetectionValidMessage.STANDARD_NAME_NOT_BLANK)
@Pattern(regexp = PatternRegex.ERR_SYS_NAME, message = DetectionValidMessage.STANDARD_NAME_FORMAT_ERROR)
private String standardName;
@ApiModelProperty(value = "标准实施年份", required = true)
@NotBlank(message = DevValidMessage.STANDARD_TIME_NOT_BLANK)
@DateTimeStrValid(format = "yyyy", message = DevValidMessage.STANDARD_TIME_FORMAT_ERROR)
@NotBlank(message = DetectionValidMessage.STANDARD_TIME_NOT_BLANK)
@DateTimeStrValid(format = "yyyy", message = DetectionValidMessage.STANDARD_TIME_FORMAT_ERROR)
private String standardTime;
@ApiModelProperty(value = "设备等级", required = true)
@NotBlank(message = DevValidMessage.DEV_LEVEL_NOT_BLANK)
@Pattern(regexp = PatternRegex.SYSTEM_ID, message = DevValidMessage.DEV_LEVEL_FORMAT_ERROR)
@NotBlank(message = DetectionValidMessage.DEV_LEVEL_NOT_BLANK)
@Pattern(regexp = PatternRegex.SYSTEM_ID, message = DetectionValidMessage.DEV_LEVEL_FORMAT_ERROR)
private String devLevel;
@ApiModelProperty("状态")
@NotNull(message = DevValidMessage.ENABLE_NOT_NULL)
@Min(value = 0, message = DevValidMessage.ENABLE_FORMAT_ERROR)
@Max(value = 1, message = DevValidMessage.ENABLE_FORMAT_ERROR)
@NotNull(message = DetectionValidMessage.ENABLE_NOT_NULL)
@Min(value = 0, message = DetectionValidMessage.ENABLE_FORMAT_ERROR)
@Max(value = 1, message = DetectionValidMessage.ENABLE_FORMAT_ERROR)
private Integer enable;
@ApiModelProperty(value = "误差详情列表", required = true)
@@ -48,11 +48,11 @@ public class PqErrSysParam {
@EqualsAndHashCode(callSuper = false)
public static class QueryParam extends BaseParam {
@ApiModelProperty("标准实施年份")
@DateTimeStrValid(format = "yyyy", message = DevValidMessage.STANDARD_TIME_FORMAT_ERROR)
@DateTimeStrValid(format = "yyyy", message = DetectionValidMessage.STANDARD_TIME_FORMAT_ERROR)
private String standardTime;
@ApiModelProperty("设备等级")
@Pattern(regexp = PatternRegex.SYSTEM_ID, message = DevValidMessage.DEV_LEVEL_FORMAT_ERROR)
@Pattern(regexp = PatternRegex.SYSTEM_ID, message = DetectionValidMessage.DEV_LEVEL_FORMAT_ERROR)
private String devLevel;
}
@@ -60,14 +60,14 @@ public class PqErrSysParam {
@EqualsAndHashCode(callSuper = false)
public static class UpdateParam extends PqErrSysParam {
@ApiModelProperty("id")
@NotBlank(message = DevValidMessage.ID_NOT_BLANK)
@Pattern(regexp = PatternRegex.SYSTEM_ID, message = DevValidMessage.ID_FORMAT_ERROR)
@NotBlank(message = DetectionValidMessage.ID_NOT_BLANK)
@Pattern(regexp = PatternRegex.SYSTEM_ID, message = DetectionValidMessage.ID_FORMAT_ERROR)
private String id;
}
@Data
@EqualsAndHashCode(callSuper = false)
public static class DetectionParam{
public static class DetectionParam {
@ApiModelProperty("所属误差体系ID")
private String errorSysId;
@@ -76,6 +76,14 @@ public class PqErrSysParam {
@ApiModelProperty("所属检测脚本")
private String scriptId;
@ApiModelProperty("电压")
private Double un;
@ApiModelProperty("电流")
private Double in;
}
}

View File

@@ -38,6 +38,11 @@ public class ErrDtlsCheckDataVO implements Serializable {
*/
private String phase;
/**
* 默认参与比较值4.不参与值 5.不参与误差比较)
*/
private Integer isQualified;
/**
* 误差体系
*/

View File

@@ -78,5 +78,5 @@ public interface IPqErrSysService extends IService<PqErrSys> {
* @param id 误差体系id
* @return 成功返回true失败返回false
*/
//boolean copyPqErrSys(String id);
boolean copyPqErrSys(String id);
}

View File

@@ -4,12 +4,14 @@ import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.njcn.gather.detection.pojo.enums.DetectionCodeEnum;
import com.njcn.gather.err.mapper.PqErrSysDtlsMapper;
import com.njcn.gather.err.pojo.param.PqErrSysDtlsParam;
import com.njcn.gather.err.pojo.param.PqErrSysParam;
import com.njcn.gather.err.pojo.po.PqErrSysDtls;
import com.njcn.gather.err.pojo.vo.ErrDtlsCheckDataVO;
import com.njcn.gather.err.service.IPqErrSysDtlsService;
import com.njcn.gather.script.mapper.PqScriptMapper;
import com.njcn.gather.script.pojo.param.PqScriptCheckDataParam;
import com.njcn.gather.script.pojo.po.PqScriptCheckData;
import com.njcn.gather.script.service.IPqScriptCheckDataService;
@@ -20,6 +22,7 @@ import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;
@@ -33,7 +36,7 @@ import java.util.stream.Collectors;
public class PqErrSysDtlsServiceImpl extends ServiceImpl<PqErrSysDtlsMapper, PqErrSysDtls> implements IPqErrSysDtlsService {
private final IPqScriptCheckDataService pqScriptCheckDataService;
private final PqScriptMapper pqScriptMapper;
@Override
public List<PqErrSysDtls> listPqErrSysDtlsByPqErrSysId(String pqErrSysId) {
@@ -41,7 +44,7 @@ public class PqErrSysDtlsServiceImpl extends ServiceImpl<PqErrSysDtlsMapper, PqE
}
@Override
@Transactional(rollbackFor = {Exception.class})
@Transactional
public boolean addPqErrSysDtls(String pqErrSysId, List<PqErrSysDtlsParam> list) {
List<PqErrSysDtls> data = new ArrayList<>();
for (PqErrSysDtlsParam param : list) {
@@ -54,7 +57,7 @@ public class PqErrSysDtlsServiceImpl extends ServiceImpl<PqErrSysDtlsMapper, PqE
}
@Override
@Transactional(rollbackFor = {Exception.class})
@Transactional
public boolean updatePqErrSysDtls(String pqErrSysId, List<PqErrSysDtlsParam> list) {
//先按照pqErrSysId全部删除
this.deletePqErrSysDtlsByPqErrSysId(Collections.singletonList(pqErrSysId));
@@ -64,7 +67,7 @@ public class PqErrSysDtlsServiceImpl extends ServiceImpl<PqErrSysDtlsMapper, PqE
}
@Override
@Transactional(rollbackFor = {Exception.class})
@Transactional
public boolean deletePqErrSysDtlsByPqErrSysId(List<String> pqErrSysIds) {
QueryWrapper<PqErrSysDtls> queryWrapper = new QueryWrapper<>();
queryWrapper.in("pq_err_sys_dtls.Error_Sys_Id", pqErrSysIds);
@@ -91,34 +94,62 @@ public class PqErrSysDtlsServiceImpl extends ServiceImpl<PqErrSysDtlsMapper, PqE
@Override
public List<ErrDtlsCheckDataVO> listByPqErrSysIdAndTypes(PqErrSysParam.DetectionParam param) {
List<ErrDtlsCheckDataVO> info=new ArrayList<>();
List<ErrDtlsCheckDataVO> info = new ArrayList<>();
PqScriptCheckDataParam checkDataParam = new PqScriptCheckDataParam();
checkDataParam.setScriptId(param.getScriptId());
checkDataParam.setIndex(param.getIndex());
//获取检测脚本中所有装置下发的测试项
List<PqScriptCheckData> list = pqScriptCheckDataService.listCheckDataCode(checkDataParam);
Boolean isValueType = pqScriptMapper.selectScriptIsValueType(param.getScriptId());
List<String> valueType = list.stream().filter(x->x.getErrorFlag()!=0).map(PqScriptCheckData::getValueType).collect(Collectors.toList());
Map<String, List<PqErrSysDtls>> errMap =new HashMap<>(3);
if(CollUtil.isNotEmpty(valueType)){
Map<String, Integer> valueType = list.stream().collect(Collectors.toMap(PqScriptCheckData::getValueType, PqScriptCheckData::getErrorFlag,
(key1, key2) -> key1));
//获取误差体系
Map<String, List<PqErrSysDtls>> errMap = new HashMap<>(3); //key为误差详情的ScriptTypevalue为List<PqErrSysDtls>
if (CollUtil.isNotEmpty(valueType)) {
List<PqErrSysDtls> errSysDtls = this.list(new MPJLambdaWrapper<PqErrSysDtls>().selectAll(PqErrSysDtls.class)
.selectAll(PqErrSysDtls.class)
.selectAs(DictTree::getCode, PqErrSysDtls::getScriptCode)
.leftJoin(DictTree.class, DictTree::getId, PqErrSysDtls::getScriptType)
.eq(PqErrSysDtls::getErrorSysId, param.getErrorSysId())
.in(PqErrSysDtls::getScriptType, valueType)
.in(PqErrSysDtls::getScriptType, valueType.keySet())
);
errMap= errSysDtls.stream().collect(Collectors.groupingBy(PqErrSysDtls::getScriptType));
errMap = errSysDtls.stream().collect(Collectors.groupingBy(PqErrSysDtls::getScriptType));
}
ErrDtlsCheckDataVO dataVO;
for (PqScriptCheckData script : list) {
dataVO=new ErrDtlsCheckDataVO();
dataVO = new ErrDtlsCheckDataVO();
dataVO.setCheckDataId(script.getScriptId());
dataVO.setValueTypeCode(script.getValueTypeCode());
dataVO.setValueType(script.getValueType());
dataVO.setValue(script.getValue());
dataVO.setPhase(script.getPhase());
if(errMap.containsKey(script.getValueType())){
dataVO.setErrSysDtls(errMap.get(script.getValueType()));
if (isValueType) {
if (DetectionCodeEnum.VRMS.getCode().equals(script.getValueTypeCode())) {
BigDecimal volValue = new BigDecimal(script.getValue());
BigDecimal result = volValue.multiply(new BigDecimal(param.getUn().toString()))
.divide(new BigDecimal(100), 4, BigDecimal.ROUND_HALF_UP);
dataVO.setValue(result.doubleValue());
}
if (DetectionCodeEnum.IRMS.getCode().equals(script.getValueTypeCode())) {
BigDecimal volValue = new BigDecimal(script.getValue());
BigDecimal result = volValue.multiply(new BigDecimal(param.getIn().toString()))
.divide(new BigDecimal(100), 4, BigDecimal.ROUND_HALF_UP);
dataVO.setValue(result.doubleValue());
}
}
if (valueType.containsKey(script.getValueType())) {
//默认值4.无法处理 5.不参与误差比较
Integer i = valueType.get(script.getValueType());
if (i == 1) { //参与误差比较
dataVO.setIsQualified(4);
if (errMap.containsKey(script.getValueType())) {
dataVO.setErrSysDtls(errMap.get(script.getValueType()));
}
} else { //不参与误差比较
dataVO.setIsQualified(5);
}
}
info.add(dataVO);
}

View File

@@ -1,5 +1,6 @@
package com.njcn.gather.err.service.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.text.StrPool;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
@@ -8,13 +9,14 @@ 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.err.mapper.PqErrSysMapper;
import com.njcn.gather.err.pojo.param.PqErrSysDtlsParam;
import com.njcn.gather.err.pojo.param.PqErrSysParam;
import com.njcn.gather.err.pojo.po.PqErrSys;
import com.njcn.gather.err.pojo.po.PqErrSysDtls;
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.device.pojo.enums.DevResponseEnum;
import com.njcn.gather.pojo.enums.DetectionResponseEnum;
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;
@@ -64,8 +66,9 @@ public class PqErrSysServiceImpl extends ServiceImpl<PqErrSysMapper, PqErrSys> i
}
@Override
@Transactional(rollbackFor = {Exception.class})
@Transactional
public boolean addPqErrSys(PqErrSysParam param) {
this.checkRepeat(param, false);
PqErrSys pqErrSys = new PqErrSys();
BeanUtils.copyProperties(param, pqErrSys);
String id = UUID.randomUUID().toString().replaceAll("-", "");
@@ -78,9 +81,11 @@ public class PqErrSysServiceImpl extends ServiceImpl<PqErrSysMapper, PqErrSys> i
return result1 && result2;
}
@Override
@Transactional(rollbackFor = {Exception.class})
@Transactional
public boolean updatePqErrSys(PqErrSysParam.UpdateParam param) {
this.checkRepeat(param, true);
PqErrSys pqErrSys = new PqErrSys();
BeanUtils.copyProperties(param, pqErrSys);
pqErrSys.setName(generateErrSysName(param));
@@ -91,8 +96,12 @@ public class PqErrSysServiceImpl extends ServiceImpl<PqErrSysMapper, PqErrSys> i
}
@Override
@Transactional(rollbackFor = {Exception.class})
@Transactional
public boolean deletePqErrSys(List<String> ids) {
Integer count = this.baseMapper.getCountBoundByIds(ids);
if (count > 0) {
throw new BusinessException(DetectionResponseEnum.ERR_SYS_BOUND_NOT_DELETE);
}
pqErrSysDtlsService.deletePqErrSysDtlsByPqErrSysId(ids);
this.lambdaUpdate().in(PqErrSys::getId, ids).set(PqErrSys::getState, DataStateEnum.DELETED.getCode()).update();
return true;
@@ -116,9 +125,10 @@ public class PqErrSysServiceImpl extends ServiceImpl<PqErrSysMapper, PqErrSys> i
}
@Override
@Transactional(rollbackFor = {Exception.class})
public List<Map<String, Object>> listAllPqErrSys() {
List<PqErrSys> pqErrSysList = this.lambdaQuery().eq(PqErrSys::getState, DataStateEnum.ENABLE.getCode()).list();
List<PqErrSys> pqErrSysList = this.lambdaQuery()
.eq(PqErrSys::getEnable,DataStateEnum.ENABLE.getCode())
.eq(PqErrSys::getState, DataStateEnum.ENABLE.getCode()).list();
List<Map<String, Object>> result = pqErrSysList.stream().map(pqErrSys -> {
Map<String, Object> map = new HashMap<>();
map.put("id", pqErrSys.getId());
@@ -182,29 +192,41 @@ public class PqErrSysServiceImpl extends ServiceImpl<PqErrSysMapper, PqErrSys> i
if (ObjectUtil.isNotNull(devLevelDictData)) {
return param.getStandardName() + "-" + param.getStandardTime() + "-" + devLevelDictData.getName();
}
throw new BusinessException(DevResponseEnum.PQ_ERRSYS_GEN_NAME_ERROR);
throw new BusinessException(DetectionResponseEnum.PQ_ERRSYS_GEN_NAME_ERROR);
}
// @Override
// public boolean copyPqErrSys(String id) {
// PqErrSys pqErrSys = this.getPqErrSysById(id);
// pqErrSys.setId(UUID.randomUUID().toString().replaceAll("-", ""));
// pqErrSys.setName(pqErrSys.getName() + "_副本");
// pqErrSys.setStandardTime(LocalDate.of(pqErrSys.getStandardTime().getYear(), 1, 1));
// pqErrSys.getPqErrSysDtlsList().forEach(pqErrSysDtls -> pqErrSysDtls.setId(UUID.randomUUID().toString().replaceAll("-", "")));
// return this.save(pqErrSys);
// }
@Override
public boolean copyPqErrSys(String id) {
PqErrSys pqErrSys = this.getPqErrSysById(id);
pqErrSys.setId(UUID.randomUUID().toString().replaceAll("-", ""));
pqErrSys.setName(pqErrSys.getName() + "_copy");
pqErrSys.setStandardName(pqErrSys.getStandardName() + "_copy");
pqErrSys.setStandardTime(LocalDate.of(pqErrSys.getStandardTime().getYear(), 1, 1));
List<PqErrSysDtlsParam> pqErrSysDtlsParams = BeanUtil.copyToList(pqErrSys.getPqErrSysDtlsList(), PqErrSysDtlsParam.class);
pqErrSysDtlsService.addPqErrSysDtls(pqErrSys.getId(), pqErrSysDtlsParams);
return this.save(pqErrSys);
}
/**
* 生成误差体系名称(标准号+年份+设备等级)
* 检查重复
*
* @return 检测源名称
* @param param 检测参数
* @param isExcludeSelf 是否排除自己
*/
private String generatePqSourceName(PqErrSysParam param) {
DictData devLevel = dictDataService.getDictDataById(param.getDevLevel());
if (ObjectUtils.allNotNull(param.getStandardName(), param.getStandardTime(), devLevel)) {
return param.getStandardName() + "-" + param.getStandardTime() + "-" + devLevel.getName();
private void checkRepeat(PqErrSysParam param, boolean isExcludeSelf) {
QueryWrapper<PqErrSys> wrapper = new QueryWrapper<>();
wrapper.eq("Standard_Name", param.getStandardName())
.eq("Standard_Time",param.getStandardTime()+"-01-01")
.eq("Dev_Level",param.getDevLevel())
.eq("state", DataStateEnum.ENABLE.getCode());
if (isExcludeSelf) {
if(param instanceof PqErrSysParam.UpdateParam){
wrapper.ne("Id", ((PqErrSysParam.UpdateParam) param).getId());
}
}
int count = this.count(wrapper);
if (count > 0) {
throw new BusinessException(DetectionResponseEnum.ERR_SYS_REPEAT);
}
throw new BusinessException(DevResponseEnum.ERR_SOURCE_GEN_NAME_ERROR);
}
}

View File

@@ -11,8 +11,6 @@ import com.njcn.common.utils.LogUtil;
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.type.pojo.param.DevTypeParam;
import com.njcn.gather.type.pojo.po.DevType;
import com.njcn.web.controller.BaseController;
import com.njcn.web.utils.HttpResultUtil;
import io.swagger.annotations.Api;
@@ -27,16 +25,15 @@ import java.util.List;
/**
*
* @author caozehui
* @date 2025-02-10
*/
@Slf4j
@Api(tags="icd管理")
@Api(tags = "icd管理")
@RestController
@RequestMapping("/icd")
@RequiredArgsConstructor
public class PqIcdPathController extends BaseController{
public class PqIcdPathController extends BaseController {
private final IPqIcdPathService pqIcdPathService;
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
@@ -63,15 +60,15 @@ public class PqIcdPathController extends BaseController{
@PostMapping("/add")
@ApiOperation("新增icd")
@ApiImplicitParam(name = "param", value = "icd新增参数", required = true)
public HttpResult<String> add(@RequestBody @Validated PqIcdPathParam param) {
public HttpResult<Boolean> add(@RequestBody @Validated PqIcdPathParam param) {
String methodDescribe = getMethodDescribe("add");
LogUtil.njcnDebug(log, "{},新增数据为:{}", methodDescribe, param);
boolean result = pqIcdPathService.addIcd(param);
if (result) {
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, methodDescribe);
} else {
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, null, methodDescribe);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, false, methodDescribe);
}
}
@@ -79,15 +76,15 @@ public class PqIcdPathController extends BaseController{
@PostMapping("/update")
@ApiOperation("修改icd")
@ApiImplicitParam(name = "param", value = "icd修改参数", required = true)
public HttpResult<String> update(@RequestBody @Validated PqIcdPathParam.UpdateParam param) {
public HttpResult<Boolean> update(@RequestBody @Validated PqIcdPathParam.UpdateParam param) {
String methodDescribe = getMethodDescribe("update");
LogUtil.njcnDebug(log, "{},修改数据为:{}", methodDescribe, param);
boolean result = pqIcdPathService.updateIcd(param);
if (result) {
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, methodDescribe);
} else {
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, null, methodDescribe);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, false, methodDescribe);
}
}
@@ -95,14 +92,14 @@ public class PqIcdPathController extends BaseController{
@PostMapping("/delete")
@ApiOperation("删除icd")
@ApiImplicitParam(name = "ids", value = "icd的id列表", required = true)
public HttpResult<String> delete(@RequestBody List<String> ids) {
public HttpResult<Boolean> delete(@RequestBody List<String> ids) {
String methodDescribe = getMethodDescribe("delete");
LogUtil.njcnDebug(log, "{},删除数据为:{}", methodDescribe, String.join(StrUtil.COMMA, ids));
boolean result = pqIcdPathService.deleteIcd(ids);
if (result) {
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, methodDescribe);
} else {
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, null, methodDescribe);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, false, methodDescribe);
}
}

View File

@@ -1,12 +0,0 @@
package com.njcn.gather.icd.pojo.constant;
/**
* @author caozehui
* @data 2025-02-11
*/
public interface PqIcdPathValidMessage {
String ID_NOT_BLANK = "id不能为空请检查id参数";
String ID_FORMAT_ERROR = "id格式错误请检查id参数";
String NAME_NOT_BLANK = "名称不能为空";
String PATH_NOT_BLANK = "icd存储路径不能为空";
}

View File

@@ -1,21 +0,0 @@
package com.njcn.gather.icd.pojo.enums;
import lombok.Getter;
/**
* @author caozehui
* @data 2025-02-11
*/
@Getter
public enum IcdPathResponseEnum {
ICD_PATH_NAME_REPEAT("A004007", "icd名称重复");
private final String code;
private final String message;
IcdPathResponseEnum(String code, String message) {
this.message = message;
this.code = code;
}
}

View File

@@ -1,8 +1,7 @@
package com.njcn.gather.icd.pojo.param;
import com.njcn.common.pojo.constant.PatternRegex;
import com.njcn.gather.icd.pojo.constant.PqIcdPathValidMessage;
import com.njcn.gather.type.pojo.constant.DevTypeValidMessage;
import com.njcn.gather.pojo.constant.DetectionValidMessage;
import com.njcn.web.pojo.param.BaseParam;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@@ -18,11 +17,13 @@ import javax.validation.constraints.Pattern;
@Data
public class PqIcdPathParam {
@ApiModelProperty(value = "名称", required = true)
@NotBlank(message = PqIcdPathValidMessage.NAME_NOT_BLANK)
@NotBlank(message = DetectionValidMessage.NAME_NOT_BLANK)
@Pattern(regexp = PatternRegex.ICD_NAME_REGEX, message = DetectionValidMessage.ICD_NAME_FORMAT_ERROR)
private String name;
@ApiModelProperty(value = "存储路径", required = true)
@NotBlank(message = PqIcdPathValidMessage.PATH_NOT_BLANK)
@NotBlank(message = DetectionValidMessage.ICD_PATH_NOT_BLANK)
@Pattern(regexp = PatternRegex.ICD_PATH_REGEX, message = DetectionValidMessage.ICD_PATH_FORMAT_ERROR)
private String path;
/**
@@ -43,8 +44,8 @@ public class PqIcdPathParam {
@EqualsAndHashCode(callSuper = true)
public static class UpdateParam extends PqIcdPathParam {
@ApiModelProperty(value = "id", required = true)
@NotBlank(message = PqIcdPathValidMessage.ID_NOT_BLANK)
@Pattern(regexp = PatternRegex.SYSTEM_ID, message = PqIcdPathValidMessage.ID_FORMAT_ERROR)
@NotBlank(message = DetectionValidMessage.ID_NOT_BLANK)
@Pattern(regexp = PatternRegex.SYSTEM_ID, message = DetectionValidMessage.ID_FORMAT_ERROR)
private String id;
}
}

View File

@@ -7,16 +7,16 @@ 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.IcdPathResponseEnum;
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.type.pojo.po.DevType;
import com.njcn.gather.pojo.enums.DetectionResponseEnum;
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 java.util.List;
@@ -45,6 +45,7 @@ public class PqIcdPathServiceImpl extends ServiceImpl<PqIcdPathMapper, PqIcdPath
}
@Override
@Transactional
public boolean addIcd(PqIcdPathParam param) {
this.checkRepeat(param, false);
PqIcdPath pqIcdPath = new PqIcdPath();
@@ -54,6 +55,7 @@ public class PqIcdPathServiceImpl extends ServiceImpl<PqIcdPathMapper, PqIcdPath
}
@Override
@Transactional
public boolean updateIcd(PqIcdPathParam.UpdateParam param) {
this.checkRepeat(param, true);
PqIcdPath pqIcdPath = new PqIcdPath();
@@ -62,6 +64,7 @@ public class PqIcdPathServiceImpl extends ServiceImpl<PqIcdPathMapper, PqIcdPath
}
@Override
@Transactional
public boolean deleteIcd(List<String> ids) {
return this.lambdaUpdate().in(PqIcdPath::getId, ids).set(PqIcdPath::getState, DataStateEnum.DELETED.getCode()).update();
}
@@ -77,7 +80,7 @@ public class PqIcdPathServiceImpl extends ServiceImpl<PqIcdPathMapper, PqIcdPath
}
int count = this.count(wrapper);
if (count > 0) {
throw new BusinessException(IcdPathResponseEnum.ICD_PATH_NAME_REPEAT);
throw new BusinessException(DetectionResponseEnum.ICD_PATH_NAME_REPEAT);
}
}
}

View File

@@ -1,10 +1,9 @@
package com.njcn.gather.monitor.pojo.param;
import com.njcn.common.pojo.constant.PatternRegex;
import com.njcn.gather.device.pojo.constant.DevValidMessage;
import com.njcn.gather.pojo.constant.DetectionValidMessage;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
@@ -21,24 +20,24 @@ public class PqMonitorParam {
private String code;
@ApiModelProperty(value = "所属母线")
@NotBlank(message = DevValidMessage.BELONG_LINE_NOT_BLANK)
@NotBlank(message = DetectionValidMessage.BELONG_LINE_NOT_BLANK)
private String name;
@ApiModelProperty(value = "监测点序号")
@NotNull(message = DevValidMessage.MONITOR_NUM_NOT_NULL)
@NotNull(message = DetectionValidMessage.MONITOR_NUM_NOT_NULL)
private Integer num;
@ApiModelProperty(value = "PT变比")
@NotNull(message = DevValidMessage.PT_NOT_NULL)
@NotNull(message = DetectionValidMessage.PT_NOT_NULL)
private Float pt;
@ApiModelProperty(value = "CT变比")
@NotNull(message = DevValidMessage.CT_NOT_NULL)
@NotNull(message = DetectionValidMessage.CT_NOT_NULL)
private Float ct;
@ApiModelProperty(value = "接线方式")
@NotBlank(message = DevValidMessage.WIRING_TYPE_NOT_BLANK)
@Pattern(regexp = PatternRegex.SYSTEM_ID, message = DevValidMessage.WIRING_TYPE_FORMAT_ERROR)
@NotBlank(message = DetectionValidMessage.WIRING_TYPE_NOT_BLANK)
@Pattern(regexp = PatternRegex.SYSTEM_ID, message = DetectionValidMessage.WIRING_TYPE_FORMAT_ERROR)
private String ptType;
}

View File

@@ -2,7 +2,7 @@ package com.njcn.gather.monitor.pojo.vo;
import cn.afterturn.easypoi.excel.annotation.Excel;
import com.njcn.common.pojo.constant.PatternRegex;
import com.njcn.gather.device.pojo.constant.DevValidMessage;
import com.njcn.gather.pojo.constant.DetectionValidMessage;
import lombok.Data;
import lombok.EqualsAndHashCode;
@@ -18,24 +18,24 @@ import javax.validation.constraints.Pattern;
public class PqMonitorExcel {
@Excel(name = "监测点序号", width = 20, orderNum = "1")
@Pattern(regexp = PatternRegex.SYSTEM_ID, message = DevValidMessage.MONITOR_NUM_FORMAT_ERROR)
@Pattern(regexp = PatternRegex.SYSTEM_ID, message = DetectionValidMessage.MONITOR_NUM_FORMAT_ERROR)
private Integer num;
@Excel(name = "所属母线", width = 20, orderNum = "2")
@NotBlank(message = DevValidMessage.BELONG_LINE_NOT_BLANK)
@NotBlank(message = DetectionValidMessage.BELONG_LINE_NOT_BLANK)
private String name;
@Excel(name = "PT变比", width = 20, orderNum = "3")
@NotNull(message = DevValidMessage.PT_NOT_NULL)
@NotNull(message = DetectionValidMessage.PT_NOT_NULL)
private Float pt;
@Excel(name = "CT变比", width = 20, orderNum = "4")
@NotNull(message = DevValidMessage.CT_NOT_NULL)
@NotNull(message = DetectionValidMessage.CT_NOT_NULL)
private Float ct;
@Excel(name = "接线方式", width = 20, orderNum = "5")
@NotBlank(message = DevValidMessage.WIRING_TYPE_NOT_BLANK)
@Pattern(regexp = PatternRegex.SYSTEM_ID, message = DevValidMessage.WIRING_TYPE_FORMAT_ERROR)
@NotBlank(message = DetectionValidMessage.WIRING_TYPE_NOT_BLANK)
@Pattern(regexp = PatternRegex.SYSTEM_ID, message = DetectionValidMessage.WIRING_TYPE_FORMAT_ERROR)
private String ptType;
@Data

View File

@@ -33,7 +33,7 @@ public class PqMonitorServiceImpl extends ServiceImpl<PqMonitorMapper, PqMonitor
}
@Override
@Transactional(rollbackFor = {Exception.class})
@Transactional
public boolean addPqMonitorByDevId(String devId, List<PqMonitorParam> pqMonitorParamList) {
List<PqMonitor> pqMonitorList = BeanUtil.copyToList(pqMonitorParamList, PqMonitor.class);
pqMonitorList.forEach(pqMonitor -> pqMonitor.setDevId(devId));
@@ -41,7 +41,7 @@ public class PqMonitorServiceImpl extends ServiceImpl<PqMonitorMapper, PqMonitor
}
@Override
@Transactional(rollbackFor = {Exception.class})
@Transactional
public boolean deletePqMonitorByDevId(String devId) {
QueryWrapper<PqMonitor> wrapper = new QueryWrapper<>();
wrapper.eq("pq_monitor.Dev_Id", devId);
@@ -49,7 +49,7 @@ public class PqMonitorServiceImpl extends ServiceImpl<PqMonitorMapper, PqMonitor
}
@Override
@Transactional(rollbackFor = {Exception.class})
@Transactional
public boolean updatePqMonitorByDevId(String devId, List<PqMonitorParam> paramList) {
// 先删除原有数据
this.deletePqMonitorByDevId(devId);

View File

@@ -1,9 +1,5 @@
package com.njcn.gather.plan.controller;
import cn.afterturn.easypoi.excel.ExcelImportUtil;
import cn.afterturn.easypoi.excel.entity.ImportParams;
import cn.afterturn.easypoi.excel.entity.result.ExcelImportResult;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.njcn.common.pojo.annotation.OperateInfo;
@@ -13,16 +9,12 @@ import com.njcn.common.pojo.enums.response.CommonResponseEnum;
import com.njcn.common.pojo.exception.BusinessException;
import com.njcn.common.pojo.response.HttpResult;
import com.njcn.common.utils.LogUtil;
import com.njcn.gather.device.service.IPqDevService;
import com.njcn.gather.device.pojo.enums.DevResponseEnum;
import com.njcn.gather.plan.pojo.param.AdPlanParam;
import com.njcn.gather.plan.pojo.vo.AdPlanExcel;
import com.njcn.gather.plan.pojo.vo.AdPlanVO;
import com.njcn.gather.plan.service.IAdPlanService;
import com.njcn.web.controller.BaseController;
import com.njcn.web.utils.ExcelUtil;
import com.njcn.web.utils.FileUtil;
import com.njcn.web.utils.HttpResultUtil;
import com.njcn.web.utils.PoiUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
@@ -51,7 +43,7 @@ public class AdPlanController extends BaseController {
private final IAdPlanService adPlanService;
@OperateInfo
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
@PostMapping("/list")
@ApiOperation("分页查询检测计划")
@ApiImplicitParam(name = "queryParam", value = "查询参数", required = true)
@@ -62,53 +54,53 @@ public class AdPlanController extends BaseController {
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
}
@OperateInfo(operateType = OperateType.ADD)
@OperateInfo(info = LogEnum.BUSINESS_COMMON, operateType = OperateType.ADD)
@PostMapping("/add")
@ApiOperation("新增检测计划")
@ApiImplicitParam(name = "param", value = "检测计划", required = true)
public HttpResult<Object> add(@RequestBody @Validated AdPlanParam param) {
public HttpResult<Boolean> add(@RequestBody @Validated AdPlanParam param) {
String methodDescribe = getMethodDescribe("add");
LogUtil.njcnDebug(log, "{},新增数据为:{}", methodDescribe, param);
boolean result = adPlanService.addAdPlan(param);
if (result) {
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, methodDescribe);
} else {
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, null, methodDescribe);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, false, methodDescribe);
}
}
@OperateInfo(operateType = OperateType.UPDATE)
@OperateInfo(info = LogEnum.BUSINESS_COMMON, operateType = OperateType.UPDATE)
@PostMapping("/update")
@ApiOperation("修改检测计划")
@ApiImplicitParam(name = "updateParam", value = "检测计划", required = true)
public HttpResult<Object> update(@RequestBody @Validated AdPlanParam.UpdateParam updateParam) {
public HttpResult<Boolean> update(@RequestBody @Validated AdPlanParam.UpdateParam updateParam) {
String methodDescribe = getMethodDescribe("update");
LogUtil.njcnDebug(log, "{},修改数据为:{}", methodDescribe, updateParam);
boolean result = adPlanService.updateAdPlan(updateParam);
if (result) {
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, methodDescribe);
} else {
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, null, methodDescribe);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, false, methodDescribe);
}
}
@OperateInfo(operateType = OperateType.DELETE)
@OperateInfo(info = LogEnum.BUSINESS_COMMON, operateType = OperateType.DELETE)
@PostMapping("/delete")
@ApiOperation("删除检测计划")
@ApiImplicitParam(name = "ids", value = "检测计划id", required = true)
public HttpResult<Object> delete(@RequestBody List<String> ids) {
public HttpResult<Boolean> delete(@RequestBody List<String> ids) {
String methodDescribe = getMethodDescribe("delete");
LogUtil.njcnDebug(log, "{}删除ID数据为{}", methodDescribe, String.join(StrUtil.COMMA, ids));
boolean result = adPlanService.deleteAdPlan(ids);
if (result) {
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, methodDescribe);
} else {
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, null, methodDescribe);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, false, methodDescribe);
}
}
@OperateInfo
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
@GetMapping("/listByPattern")
@ApiOperation("按照模式查询检测计划")
@ApiImplicitParam(name = "pattern", value = "模式Id", required = true)
@@ -119,79 +111,62 @@ public class AdPlanController extends BaseController {
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
}
@OperateInfo(info = LogEnum.BUSINESS_COMMON, operateType = OperateType.DOWNLOAD)
@PostMapping("/downloadTemplate")
@ApiOperation("下载监测计划导入文件模板")
public void downloadTemplate() {
adPlanService.downloadTemplate();
}
@OperateInfo(operateType = OperateType.DOWNLOAD)
@PostMapping("/export")
@ApiOperation("导出检测计划")
@ApiImplicitParam(name = "queryParam", value = "查询参数", required = true)
public void export(@RequestBody @Validated AdPlanParam.QueryParam queryParam) {
String methodDescribe = getMethodDescribe("export");
public void exportPlan(@RequestBody @Validated AdPlanParam.QueryParam queryParam) {
String methodDescribe = getMethodDescribe("exportPlan");
LogUtil.njcnDebug(log, "{},查询数据为:{}", methodDescribe, queryParam);
List<AdPlanExcel.ExportData> data = adPlanService.getExportData(queryParam);
ExcelUtil.exportExcel("检测计划导出数据.xlsx", AdPlanExcel.ExportData.class, data);
adPlanService.exportPlan(queryParam);
}
@OperateInfo(info = LogEnum.BUSINESS_COMMON, operateType = OperateType.DOWNLOAD)
@PostMapping("/downloadTemplate")
@ApiOperation("下载检测计划导出模板")
public void downloadTemplate() {
adPlanService.downloadTemplate();
}
@OperateInfo(info = LogEnum.BUSINESS_COMMON, operateType = OperateType.UPLOAD)
@PostMapping(value = "/import")
@ApiOperation("批量导入检测计划数据")
@ApiOperation("导入检测计划数据")
@ApiImplicitParams({
@ApiImplicitParam(name = "file", value = "检测计划数据文件", required = true),
@ApiImplicitParam(name = "pattern", value = "模式Id", required = true)
})
public HttpResult<Object> importData(@RequestParam("file") MultipartFile file, @RequestParam("patternId") String patternId, HttpServletResponse response) {
String methodDescribe = getMethodDescribe("importData");
LogUtil.njcnDebug(log, "{},上传文件为:{}, 模式Id为{}", methodDescribe, file.getOriginalFilename(), patternId);
public HttpResult<Object> importPlan(@RequestParam("file") MultipartFile file, @RequestParam("patternId") String patternId, HttpServletResponse response) {
String methodDescribe = getMethodDescribe("importCNPlan");
LogUtil.njcnDebug(log, "{},上传文件为:{}", methodDescribe, file.getOriginalFilename());
ImportParams params = new ImportParams();
params.setHeadRows(2);
params.setNeedVerify(true);
params.setStartSheetIndex(0);
params.setSheetNum(1);
try {
ExcelImportResult<AdPlanExcel.ImportData> adPlanExcelResult = ExcelImportUtil.importExcelMore(file.getInputStream(), AdPlanExcel.ImportData.class, params);
if (adPlanExcelResult.isVerifyFail()) {
// 此处前端要做特殊处理,具体可以参考技术监督的数据导入
PoiUtil.exportFileByWorkbook(adPlanExcelResult.getFailWorkbook(), "非法检测计划数据.xlsx", response);
} else {
List<AdPlanExcel.ImportData> adPlanExcelList = adPlanExcelResult.getList();
if (ObjectUtil.isNotEmpty(adPlanExcelList)) {
adPlanService.importData(patternId, adPlanExcelList);
}
}
} catch (Exception e) {
throw new BusinessException(DevResponseEnum.IMPORT_DATA_FAIL, e.getMessage());
boolean fileType = FileUtil.judgeFileIsExcel(file.getOriginalFilename());
if (!fileType) {
throw new BusinessException(CommonResponseEnum.FILE_XLSX_ERROR);
}
adPlanService.importPlan(file, patternId, response);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
}
// @OperateInfo
// @GetMapping("/getPieData")
// @ApiOperation("获取饼状图数据")
// @ApiImplicitParam(name = "id", value = "检测计划id", required = true)
// public HttpResult<List<List<Map<String, Object>>>> getPieData(@RequestParam("planId") String planId) {
// String methodDescribe = getMethodDescribe("getPieData");
// LogUtil.njcnDebug(log, "{},查询数据为:{}", methodDescribe, planId);
// List<List<Map<String, Object>>> result = pqDevService.getPieData(planId);
// return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
// }
@OperateInfo
@GetMapping("/getBigTestItem")
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
@PostMapping("/getBigTestItem")
@ApiOperation("获取检测大项数据")
@ApiImplicitParam(name = "id", value = "检测计划id", required = true)
public HttpResult<List<Map<String, String>>> getBigTestItem(@RequestParam("planId") String planId) {
public HttpResult<List<Map<String, String>>> getBigTestItem(@RequestBody AdPlanParam.CheckParam checkParam) {
String methodDescribe = getMethodDescribe("getBigTestItem");
LogUtil.njcnDebug(log, "{},查询数据为:{}", methodDescribe, planId);
List<Map<String, String>> result = adPlanService.getBigTestItem(planId);
LogUtil.njcnDebug(log, "{},查询数据为:{}", methodDescribe, checkParam);
List<Map<String, String>> result = adPlanService.getBigTestItem(checkParam.getReCheckType(), checkParam.getPlanId(), checkParam.getDevId());
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
}
@OperateInfo(info = LogEnum.BUSINESS_COMMON, operateType = OperateType.DOWNLOAD)
@PostMapping("/analyse")
@ApiOperation("检测数据分析")
@ApiImplicitParam(name = "planId", value = "检测计划id", required = true)
public void analyse(@RequestBody List<String> ids) {
String methodDescribe = getMethodDescribe("analyse");
LogUtil.njcnDebug(log, "{},查询数据为:{}", methodDescribe, String.join(StrUtil.COMMA, ids));
adPlanService.analyse(ids);
}
}

View File

@@ -2,6 +2,8 @@ package com.njcn.gather.plan.mapper;
import com.github.yulichang.base.MPJBaseMapper;
import com.njcn.gather.plan.pojo.po.AdPlan;
import com.njcn.gather.report.pojo.po.PqReport;
import org.apache.ibatis.annotations.Param;
/**
* @author caozehui
@@ -9,5 +11,21 @@ import com.njcn.gather.plan.pojo.po.AdPlan;
*/
public interface AdPlanMapper extends MPJBaseMapper<AdPlan> {
/**
* 根据名称和版本获取报告id
*
* @param name
* @param version
* @return
*/
String getReportIdByNameAndVersion(@Param("name") String name, @Param("version") String version);
/**
* 根据id获取报告模板
*
* @param id
* @return
*/
PqReport getPqReportById(String id);
}

View File

@@ -3,5 +3,19 @@
<mapper namespace="com.njcn.gather.plan.mapper.AdPlanMapper">
<select id="getReportIdByNameAndVersion" resultType="java.lang.String">
SELECT id
FROM pq_report
WHERE name = #{name}
AND version = #{version}
and state = 1
</select>
<select id="getPqReportById" resultType="com.njcn.gather.report.pojo.po.PqReport">
SELECT *
FROM pq_report
WHERE id = #{id}
and state = 1
</select>
</mapper>

View File

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

View File

@@ -1,23 +0,0 @@
package com.njcn.gather.plan.pojo.enums;
import lombok.Getter;
/**
* @author caozehui
* @data 2025-01-16
*/
@Getter
public enum PlanResponseEnum {
PLAN_REPEATED("A003014", "当前模式下,该计划已存在"),
PLAN_NOT_EXIST("A003015", "该计划不存在"),
SCRIPT_RELATE_DICT_NOT_EXIST("A003016","脚本关联的字典不存在");
private final String message;
private final String code;
PlanResponseEnum(String code, String message) {
this.code = code;
this.message = message;
}
}

View File

@@ -1,7 +1,7 @@
package com.njcn.gather.plan.pojo.param;
import com.njcn.common.pojo.constant.PatternRegex;
import com.njcn.gather.device.pojo.constant.DevValidMessage;
import com.njcn.gather.pojo.constant.DetectionValidMessage;
import com.njcn.web.pojo.param.BaseParam;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@@ -18,47 +18,53 @@ import java.util.List;
public class AdPlanParam {
@ApiModelProperty(value = "名称", required = true)
@NotBlank(message = DevValidMessage.NAME_NOT_BLANK)
@Pattern(regexp = PatternRegex.PLAN_NAME_REGEX, message = DevValidMessage.NAME_FORMAT_ERROR)
@NotBlank(message = DetectionValidMessage.NAME_NOT_BLANK)
@Pattern(regexp = PatternRegex.PLAN_NAME_REGEX, message = DetectionValidMessage.NAME_FORMAT_ERROR)
private String name;
@ApiModelProperty(value = "模式", required = true)
@NotBlank(message = DevValidMessage.PATTERN_NOT_BLANK)
@Pattern(regexp = PatternRegex.SYSTEM_ID, message = DevValidMessage.PATTERN_FORMAT_ERROR)
@NotBlank(message = DetectionValidMessage.PATTERN_NOT_BLANK)
@Pattern(regexp = PatternRegex.SYSTEM_ID, message = DetectionValidMessage.PATTERN_FORMAT_ERROR)
private String pattern;
// @ApiModelProperty(value = "父计划ID")
// @Pattern(regexp = PatternRegex.SYSTEM_ID, message = DeviceValidMessage.PATTERN_FORMAT_ERROR)
// private String fatherPlanId;
@ApiModelProperty(value = "检测源ID列表",required = true)
@NotEmpty(message = DevValidMessage.SOURCE_IDS_NOT_EMPTY)
private List<@Pattern(regexp = PatternRegex.SYSTEM_ID, message = DevValidMessage.SOURCE_ID_FORMAT_ERROR)String> sourceIds;
@ApiModelProperty(value = "检测源ID列表", required = true)
@NotEmpty(message = DetectionValidMessage.SOURCE_IDS_NOT_EMPTY)
private List<@Pattern(regexp = PatternRegex.SYSTEM_ID, message = DetectionValidMessage.SOURCE_ID_FORMAT_ERROR) String> sourceIds;
@ApiModelProperty(value = "数据源ID列表", required = true)
@NotEmpty(message = DevValidMessage.DATASOURCE_ID_NOT_EMPTY)
@NotEmpty(message = DetectionValidMessage.DATASOURCE_ID_NOT_EMPTY)
private List<String> datasourceIds;
@ApiModelProperty(value = "检测脚本ID", required = true)
@NotBlank(message = DevValidMessage.SCRIPT_ID_NOT_BLANK)
@Pattern(regexp = PatternRegex.SYSTEM_ID, message = DevValidMessage.SCRIPT_ID_FORMAT_ERROR)
@NotBlank(message = DetectionValidMessage.SCRIPT_ID_NOT_BLANK)
@Pattern(regexp = PatternRegex.SYSTEM_ID, message = DetectionValidMessage.SCRIPT_ID_FORMAT_ERROR)
private String scriptId;
@ApiModelProperty(value = "误差体系ID", required = true)
@NotBlank(message = DevValidMessage.ERROR_SYS_ID_NOT_BLANK)
@Pattern(regexp = PatternRegex.SYSTEM_ID, message = DevValidMessage.ERROR_SYS_ID_FORMAT_ERROR)
@NotBlank(message = DetectionValidMessage.ERROR_SYS_ID_NOT_BLANK)
@Pattern(regexp = PatternRegex.SYSTEM_ID, message = DetectionValidMessage.ERROR_SYS_ID_FORMAT_ERROR)
private String errorSysId;
@ApiModelProperty(value = "守时检测")
@NotNull(message = DevValidMessage.TIME_CHECK_NOT_NULL)
@Min(value = 0, message = DevValidMessage.TIME_CHECK_FORMAT_ERROR)
@Max(value = 1, message = DevValidMessage.TIME_CHECK_FORMAT_ERROR)
@NotNull(message = DetectionValidMessage.TIME_CHECK_NOT_NULL)
@Min(value = 0, message = DetectionValidMessage.TIME_CHECK_FORMAT_ERROR)
@Max(value = 1, message = DetectionValidMessage.TIME_CHECK_FORMAT_ERROR)
private Integer timeCheck;
@ApiModelProperty("被检设备ID列表")
@NotNull(message = DevValidMessage.PQ_DEV_IDS_NOT_NULL)
@NotNull(message = DetectionValidMessage.PQ_DEV_IDS_NOT_NULL)
private List<String> devIds;
@ApiModelProperty(value = "是否关联报告")
private Integer associateReport;
@ApiModelProperty(value = "报告模板名称")
private String reportTemplateName;
/**
* 分页查询实体
*/
@@ -66,27 +72,27 @@ public class AdPlanParam {
@EqualsAndHashCode(callSuper = true)
public static class QueryParam extends BaseParam {
@ApiModelProperty("名称")
@Pattern(regexp = PatternRegex.DEV_NAME_REGEX, message = DevValidMessage.NAME_FORMAT_ERROR)
@Pattern(regexp = PatternRegex.DEV_NAME_REGEX, message = DetectionValidMessage.NAME_FORMAT_ERROR)
private String name;
@ApiModelProperty(value = "模式,字典表(数字、模拟、比对)")
@Pattern(regexp = PatternRegex.SYSTEM_ID, message = DevValidMessage.PATTERN_FORMAT_ERROR)
@NotBlank(message = DevValidMessage.PATTERN_NOT_BLANK)
@Pattern(regexp = PatternRegex.SYSTEM_ID, message = DetectionValidMessage.PATTERN_FORMAT_ERROR)
@NotBlank(message = DetectionValidMessage.PATTERN_NOT_BLANK)
private String pattern;
@ApiModelProperty(value = "检测状态")
@Min(value = 0, message = DevValidMessage.TEST_STATE_FORMAT_ERROR)
@Max(value = 2, message = DevValidMessage.TEST_STATE_FORMAT_ERROR)
@Min(value = 0, message = DetectionValidMessage.TEST_STATE_FORMAT_ERROR)
@Max(value = 2, message = DetectionValidMessage.TEST_STATE_FORMAT_ERROR)
private Integer testState;
@ApiModelProperty(value = "报告生成状态")
@Min(value = 0, message = DevValidMessage.REPORT_STATE_FORMAT_ERROR)
@Max(value = 2, message = DevValidMessage.REPORT_STATE_FORMAT_ERROR)
@Min(value = 0, message = DetectionValidMessage.REPORT_STATE_FORMAT_ERROR)
@Max(value = 2, message = DetectionValidMessage.REPORT_STATE_FORMAT_ERROR)
private Integer reportState;
@ApiModelProperty(value = "检测结果")
@Min(value = 0, message = DevValidMessage.CHECK_RESULT_STATE_FORMAT_ERROR)
@Max(value = 2, message = DevValidMessage.CHECK_RESULT_STATE_FORMAT_ERROR)
@Min(value = 0, message = DetectionValidMessage.CHECK_RESULT_STATE_FORMAT_ERROR)
@Max(value = 2, message = DetectionValidMessage.CHECK_RESULT_STATE_FORMAT_ERROR)
private Integer result;
}
@@ -94,36 +100,16 @@ public class AdPlanParam {
@EqualsAndHashCode(callSuper = true)
public static class UpdateParam extends AdPlanParam {
@ApiModelProperty(value = "id", required = true)
@NotBlank(message = DevValidMessage.ID_NOT_BLANK)
@Pattern(regexp = PatternRegex.SYSTEM_ID, message = DevValidMessage.ID_FORMAT_ERROR)
@NotBlank(message = DetectionValidMessage.ID_NOT_BLANK)
@Pattern(regexp = PatternRegex.SYSTEM_ID, message = DetectionValidMessage.ID_FORMAT_ERROR)
private String id;
/**
* 检测状态,字典表(未检、检测中、检测完成)
*/
// @ApiModelProperty(value = "检测状态")
// @NotNull(message = DeviceValidMessage.TEST_STATE_NOT_NULL)
// @Min(value = 0, message = DeviceValidMessage.TEST_STATE_FORMAT_ERROR)
// @Max(value = 2, message = DeviceValidMessage.TEST_STATE_FORMAT_ERROR)
// private Integer testState;
/**
* 报告生成状态,字典表(未生成、部分生成、全部生成)
*/
// @ApiModelProperty(value = "报告生成状态")
// @NotNull(message = DeviceValidMessage.REPORT_STATE_NOT_NULL)
// @Min(value = 0, message = DeviceValidMessage.REPORT_STATE_FORMAT_ERROR)
// @Max(value = 2, message = DeviceValidMessage.REPORT_STATE_FORMAT_ERROR)
// private Integer reportState;
/**
* 检测结果,字典表(符合、不符合、/
*/
// @ApiModelProperty(value = "检测结果")
// @NotNull(message = DeviceValidMessage.CHECK_RESULT_STATE_NOT_NULL)
// @Min(value = 0, message = DeviceValidMessage.CHECK_RESULT_STATE_FORMAT_ERROR)
// @Max(value = 2, message = DeviceValidMessage.CHECK_RESULT_STATE_FORMAT_ERROR)
// private Integer result;
}
@Data
public static class CheckParam {
// 0:不合格项复检 1:全部复检
private Integer reCheckType;
private String planId;
private String devId;
}
}

View File

@@ -78,6 +78,16 @@ public class AdPlan extends BaseEntity implements Serializable {
*/
private Integer code;
/**
* 是否关联报告0-不关联 1-关联
*/
private Integer associateReport;
/**
* 报告模板ID关联PQ_Report表
*/
private String reportTemplateId;
/**
* 状态0-删除 1-正常
*/

View File

@@ -1,19 +1,11 @@
package com.njcn.gather.plan.pojo.vo;
import cn.afterturn.easypoi.excel.annotation.Excel;
import cn.afterturn.easypoi.excel.annotation.ExcelCollection;
import com.njcn.common.pojo.constant.PatternRegex;
import com.njcn.gather.device.pojo.constant.DevValidMessage;
import com.njcn.web.pojo.annotation.DateTimeStrValid;
import com.njcn.gather.pojo.constant.DetectionValidMessage;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.hibernate.validator.constraints.Range;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import java.time.LocalDate;
import java.util.List;
/**
* @author caozehui
@@ -21,164 +13,39 @@ import java.util.List;
*/
@Data
public class AdPlanExcel {
@Excel(name = "名称", width = 40, needMerge = true, orderNum = "0")
@NotBlank(message = DevValidMessage.NAME_NOT_BLANK)
@Excel(name = "名称*", width = 40, needMerge = true, orderNum = "0")
@NotBlank(message = DetectionValidMessage.NAME_NOT_BLANK)
private String name;
@Excel(name = "检测源", width = 40, needMerge = true, orderNum = "1")
@NotBlank(message = DevValidMessage.SOURC_NOT_BLANK)
@Excel(name = "检测源*", width = 40, needMerge = true, orderNum = "1")
@NotBlank(message = DetectionValidMessage.SOURC_NOT_BLANK)
private String source;
@Excel(name = "数据源", width = 20, needMerge = true, orderNum = "2")
@NotBlank(message = DevValidMessage.DATASOURCE_NOT_BLANK)
@Excel(name = "数据源*", width = 20, needMerge = true, orderNum = "2")
@NotBlank(message = DetectionValidMessage.DATASOURCE_NOT_BLANK)
private String datasourceId;
@Excel(name = "脚本", width = 50, needMerge = true, orderNum = "3")
@NotBlank(message = DevValidMessage.SCRIPT_NOT_BLANK)
@Excel(name = "脚本*", width = 100, needMerge = true, orderNum = "3")
@NotBlank(message = DetectionValidMessage.SCRIPT_NOT_BLANK)
private String scriptId;
@Excel(name = "误差体系", width = 30, needMerge = true, orderNum = "4")
@NotBlank(message = DevValidMessage.ERRORSYS_NOT_BLANK)
@Excel(name = "误差体系*", width = 30, needMerge = true, orderNum = "4")
@NotBlank(message = DetectionValidMessage.ERRORSYS_NOT_BLANK)
private String errorSysId;
@Excel(name = "是否做守时检测*", width = 15, replace = {"否_0", "是_1"}, needMerge = true, orderNum = "5")
@NotNull(message = DetectionValidMessage.TIMECHECK_NOT_NULL)
private Integer timeCheck;
@Data
@EqualsAndHashCode(callSuper = true)
public static class ExportData extends AdPlanExcel {
// @Excel(name = "模式", width = 20, needMerge = true, orderNum = "1")
// @NotBlank(message = DevValidMessage.PATTERN_NOT_BLANK)
// private String pattern;
@Excel(name = "检测状态*", width = 10, replace = {"未检_0", "检测中_1", "检测完成_2"}, needMerge = true, orderNum = "6")
@NotNull(message = DetectionValidMessage.TEST_STATE_NOT_NULL)
private Integer testState;
// @Excel(name = "父计划id", width = 25, needMerge = true, orderNum = "3")
// private String fatherPlanId;
@Excel(name = "报告生成状态*", width = 15, replace = {"未生成_0", "部分生成_1", "全部生成_2"}, needMerge = true, orderNum = "7")
@NotNull(message = DetectionValidMessage.REPORT_STATE_NOT_NULL)
private Integer reportState;
@Excel(name = "是否做守时检测(否\\是)", width = 15, replace = {"_0", "是_1"}, needMerge = true, orderNum = "5")
private Integer timeCheck;
@Excel(name = "检测状态(未检\\检测中\\检测完成)", width = 10, replace = {"未检_0", "检测中_1", "检测完成_2"}, needMerge = true, orderNum = "6")
private Integer testState;
@Excel(name = "报告生成状态(未生成\\部分生成\\全部生成)", width = 15, replace = {"未生成_0", "部分生成_1", "全部生成_2"}, needMerge = true, orderNum = "7")
private Integer reportState;
@Excel(name = "检测结果(不符合\\符合\\未检)", width = 10, replace = {"不符合_0", "符合_1", "未检_2"}, needMerge = true, orderNum = "8")
private Integer result;
// @Excel(name = "数据表后缀", width = 20, needMerge = true, orderNum = "11")
// private Integer code;
@ExcelCollection(name = "绑定的设备", orderNum = "9")
private List<BoundExportData> devices;
}
@Data
@EqualsAndHashCode(callSuper = true)
public static class ImportData extends AdPlanExcel {
@Excel(name = "是否做守时检测(否\\是)", width = 15, replace = {"否_0", "是_1"}, needMerge = true, orderNum = "5")
@NotBlank(message = DevValidMessage.TIMECHECK_NOT_BLANK)
private String timeCheck;
@Excel(name = "检测状态(未检\\检测中\\检测完成)", width = 10, replace = {"未检_0", "检测中_1", "检测完成_2"}, needMerge = true, orderNum = "6")
@NotBlank(message = DevValidMessage.TEST_STATE_NOT_NULL)
private String testState;
@Excel(name = "报告生成状态(未生成\\部分生成\\全部生成)", width = 15, replace = {"未生成_0", "部分生成_1", "全部生成_2"}, needMerge = true, orderNum = "7")
@NotBlank(message = DevValidMessage.REPORT_STATE_NOT_NULL)
private String reportState;
@Excel(name = "检测结果(不符合\\符合\\未检)", width = 10, replace = {"不符合_0", "符合_1", "未检_2"}, needMerge = true, orderNum = "8")
@NotBlank(message = DevValidMessage.CHECK_RESULT_STATE_NOT_NULL)
private String result;
@ExcelCollection(name = "绑定的设备", orderNum = "9")
private List<BoundImportData> devices;
}
@Data
public static class BoundData {
@Excel(name = "名称", width = 20)
@NotBlank(message = DevValidMessage.NAME_NOT_BLANK)
@Pattern(regexp = PatternRegex.DEV_NAME_REGEX, message = DevValidMessage.NAME_FORMAT_ERROR)
private String name;
@Excel(name = "设备类型", width = 20, orderNum = "2")
@NotBlank(message = DevValidMessage.DEV_TYPE_NOT_BLANK)
private String devType;
@Excel(name = "设备通道数", width = 20, orderNum = "3")
@NotNull(message = DevValidMessage.DEV_CHNS_NOT_NULL)
private Integer devChns;
@Excel(name = "额定电压V", width = 15, orderNum = "4")
@NotNull(message = DevValidMessage.DEV_VOLT_NOT_NULL)
private Float devVolt;
@Excel(name = "额定电流A", width = 15, orderNum = "5")
@NotNull(message = DevValidMessage.DEV_CURR_NOT_NULL)
private Float devCurr;
@Excel(name = "设备厂家", width = 20, orderNum = "6")
@NotBlank(message = DevValidMessage.MANUFACTURER_NOT_BLANK)
private String manufacturer;
@Excel(name = "设备序列号", width = 40, orderNum = "8")
@NotBlank(message = DevValidMessage.FACTORYNO_NOT_BLANK)
private String createId;
@Excel(name = "固件版本", width = 15, orderNum = "9")
@NotBlank(message = DevValidMessage.FIRMWARE_NOT_BLANK)
private String hardwareVersion;
@Excel(name = "软件版本", width = 15, orderNum = "10")
@NotBlank(message = DevValidMessage.SOFTWARE_NOT_BLANK)
private String softwareVersion;
@Excel(name = "通讯协议", width = 15, orderNum = "11")
@NotBlank(message = DevValidMessage.PROTOCOL_NOT_BLANK)
private String protocol;
@Excel(name = "IP地址", width = 20, orderNum = "12")
@NotBlank(message = DevValidMessage.IP_NOT_BLANK)
@Pattern(regexp = PatternRegex.IP_REGEX, message = DevValidMessage.IP_FORMAT_ERROR)
private String ip;
@Excel(name = "端口号", orderNum = "13")
@NotNull(message = DevValidMessage.PORT_NOT_NULL)
@Range(min = 1, max = 65535, message = DevValidMessage.PORT_RANGE_ERROR)
private Integer port;
@Excel(name = "是否为加密版本(否\\是)", width = 20, replace = {"否_0", "是_1"}, orderNum = "14")
@NotNull(message = DevValidMessage.ENCRYPTION_NOT_NULL)
private Integer encryptionFlag;
@Excel(name = "识别码(当为加密版本时必填)", width = 30, orderNum = "15")
private String series;
@Excel(name = "秘钥(当为加密版本时必填)", width = 30, orderNum = "16")
private String devKey;
}
@Data
@EqualsAndHashCode(callSuper = true)
public static class BoundExportData extends BoundData {
@Excel(name = "出厂日期yyyy-MM-dd", width = 25, format = "yyyy-MM-dd", orderNum = "7")
@NotNull(message = DevValidMessage.CREATEDATETIME_NOT_NULL)
private LocalDate createDate;
@Excel(name = "是否支持系数校准(否\\是)", width = 20, replace = {"否_0", "是_1"}, orderNum = "17", needMerge = true)
private Integer factorFlag;
}
@Data
@EqualsAndHashCode(callSuper = true)
public static class BoundImportData extends BoundData {
@Excel(name = "出厂日期yyyy-MM-dd", width = 25, format = "yyyy-MM-dd", orderNum = "7", needMerge = true)
@NotNull(message = DevValidMessage.CREATEDATETIME_NOT_NULL)
@DateTimeStrValid(message = DevValidMessage.CREATEDATETIME_FORMAT_ERROR)
private String createDate;
@Excel(name = "是否支持系数校准(否\\是)", width = 20, replace = {"否_0", "是_1"}, orderNum = "17", needMerge = true)
@NotBlank(message = DevValidMessage.FACTOR_FLAG_NOT_BLANK)
private String factorFlag;
}
@Excel(name = "检测结果*", width = 10, replace = {"不符合_0", "符合_1", "未检_2"}, needMerge = true, orderNum = "8")
@NotNull(message = DetectionValidMessage.CHECK_RESULT_STATE_NOT_NULL)
private Integer result;
}

View File

@@ -1,5 +1,6 @@
package com.njcn.gather.plan.pojo.vo;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
@@ -97,4 +98,14 @@ public class AdPlanVO {
* 创建时间
*/
private String createTime;
/**
* 是否关联报告0-不关联 1-关联
*/
private Integer associateReport;
/**
* 报告模板名称
*/
private String reportTemplateName;
}

View File

@@ -0,0 +1,19 @@
package com.njcn.gather.plan.pojo.vo;
import cn.afterturn.easypoi.excel.annotation.ExcelCollection;
import com.njcn.gather.device.pojo.vo.CNDevExcel;
import lombok.Data;
import java.util.List;
/**
* @author caozehui
* @data 2025-03-25
*/
@Data
public class CNPlanExcel extends AdPlanExcel {
@ExcelCollection(name = "绑定的设备", orderNum = "9")
private List<CNDevExcel> devices;
}

View File

@@ -0,0 +1,18 @@
package com.njcn.gather.plan.pojo.vo;
import cn.afterturn.easypoi.excel.annotation.ExcelCollection;
import com.njcn.gather.device.pojo.vo.ProvinceDevExcel;
import lombok.Data;
import java.util.List;
/**
* @author caozehui
* @data 2025-03-25
*/
@Data
public class ProvincePlanExcel extends AdPlanExcel {
@ExcelCollection(name = "绑定的设备", orderNum = "9")
private List<ProvinceDevExcel> devices;
}

View File

@@ -3,10 +3,12 @@ package com.njcn.gather.plan.service;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import com.njcn.gather.plan.pojo.param.AdPlanParam;
import com.njcn.gather.plan.pojo.vo.AdPlanVO;
import com.njcn.gather.plan.pojo.po.AdPlan;
import com.njcn.gather.plan.pojo.vo.AdPlanExcel;
import com.njcn.gather.plan.pojo.vo.AdPlanVO;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;
@@ -56,28 +58,6 @@ public interface IAdPlanService extends IService<AdPlan> {
*/
List<Map<String, Object>> listByPattern(String pattern);
/**
* 下载检测计划模板
*/
void downloadTemplate();
/**
* 获取检测计划导出数据
*
* @param queryParam 查询参数
* @return 检测计划导出数据
*/
List<AdPlanExcel.ExportData> getExportData(AdPlanParam.QueryParam queryParam);
/**
* 导入检测计划
* @param patternId 模式Id
* @param adPlanExcelList 检测计划Excel列表
* @return 导入成功则返回true否则返回false
*/
void importData(String patternId, List<AdPlanExcel.ImportData> adPlanExcelList);
/**
* 可视化
*
@@ -88,26 +68,58 @@ public interface IAdPlanService extends IService<AdPlan> {
/**
* 获取检测大项
*
* @param reCheckType 0:不合格项复检 1:全部复检
* @param planId 检测计划Id
* @param devId 设备Id
* @return
*/
List<Map<String, String>> getBigTestItem(String planId);
List<Map<String, String>> getBigTestItem(Integer reCheckType, String planId, String devId);
/**
* 修改计划状态
*
* @param planId
* @param devIds
* @return
*/
boolean updateTestState(String planId,List<String> devIds);
boolean updateTestState(String planId, List<String> devIds);
/**
* 数据状态回退
*
* @param planId
* @param devIds
* @return
*/
boolean updateBackTestState(String planId,List<String> devIds);
boolean updateBackTestState(String planId, List<String> devIds);
void finishPlan(String planId);
/**
* 数据分析
*
* @param ids
*/
void analyse(List<String> ids);
/**
* 导出检测计划数据
*
* @param queryParam
*/
void exportPlan(AdPlanParam.QueryParam queryParam);
/**
* 下载检测计划模板
*/
void downloadTemplate();
/**
* 导入检测计划数据
*
* @param file
* @param patternId
* @param response
*/
void importPlan(MultipartFile file, String patternId, HttpServletResponse response);
}

View File

@@ -1,7 +1,12 @@
package com.njcn.gather.plan.service.impl;
import cn.afterturn.easypoi.excel.ExcelImportUtil;
import cn.afterturn.easypoi.excel.entity.ExportParams;
import cn.afterturn.easypoi.excel.entity.ImportParams;
import cn.afterturn.easypoi.excel.entity.result.ExcelImportResult;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.CharsetUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
@@ -12,39 +17,67 @@ 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.common.pojo.poi.PullDown;
import com.njcn.gather.device.pojo.enums.*;
import com.njcn.gather.device.pojo.param.PqDevParam;
import com.njcn.gather.device.pojo.po.PqDev;
import com.njcn.gather.device.pojo.vo.PqDevVO;
import com.njcn.gather.device.pojo.vo.CNDevExcel;
import com.njcn.gather.device.pojo.vo.ProvinceDevExcel;
import com.njcn.gather.device.service.IPqDevService;
import com.njcn.gather.err.pojo.po.PqErrSys;
import com.njcn.gather.err.service.IPqErrSysService;
import com.njcn.gather.plan.mapper.AdPlanMapper;
import com.njcn.gather.plan.pojo.enums.DataSourceEnum;
import com.njcn.gather.plan.pojo.enums.PlanReportStateEnum;
import com.njcn.gather.plan.pojo.enums.PlanResponseEnum;
import com.njcn.gather.plan.pojo.param.AdPlanParam;
import com.njcn.gather.plan.pojo.po.AdPlan;
import com.njcn.gather.plan.pojo.vo.AdPlanExcel;
import com.njcn.gather.plan.pojo.vo.AdPlanVO;
import com.njcn.gather.plan.pojo.vo.CNPlanExcel;
import com.njcn.gather.plan.pojo.vo.ProvincePlanExcel;
import com.njcn.gather.plan.service.IAdPlanService;
import com.njcn.gather.plan.service.IAdPlanSourceService;
import com.njcn.gather.pojo.enums.DetectionResponseEnum;
import com.njcn.gather.report.pojo.po.PqReport;
import com.njcn.gather.script.pojo.po.PqScriptDtls;
import com.njcn.gather.script.service.IPqScriptDtlsService;
import com.njcn.gather.script.service.IPqScriptService;
import com.njcn.gather.source.pojo.po.PqSource;
import com.njcn.gather.source.service.IPqSourceService;
import com.njcn.gather.storage.pojo.param.StorageParam;
import com.njcn.gather.storage.service.AdHarmonicService;
import com.njcn.gather.storage.service.TableGenService;
import com.njcn.gather.system.cfg.pojo.enums.SceneEnum;
import com.njcn.gather.system.cfg.pojo.po.SysTestConfig;
import com.njcn.gather.system.cfg.service.ISysTestConfigService;
import com.njcn.gather.system.dictionary.pojo.po.DictData;
import com.njcn.gather.system.dictionary.pojo.po.DictTree;
import com.njcn.gather.system.dictionary.pojo.po.DictType;
import com.njcn.gather.system.dictionary.service.IDictDataService;
import com.njcn.gather.system.dictionary.service.IDictTreeService;
import com.njcn.gather.system.dictionary.service.IDictTypeService;
import com.njcn.gather.type.pojo.po.DevType;
import com.njcn.gather.type.service.IDevTypeService;
import com.njcn.web.factory.PageFactory;
import com.njcn.web.utils.ExcelUtil;
import com.njcn.web.utils.HttpServletUtil;
import com.njcn.web.utils.PoiUtil;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.xddf.usermodel.chart.*;
import org.apache.poi.xssf.usermodel.*;
import org.openxmlformats.schemas.drawingml.x2006.chart.CTBarSer;
import org.openxmlformats.schemas.drawingml.x2006.chart.CTPlotArea;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.URLEncoder;
import java.util.*;
import java.util.stream.Collectors;
@@ -66,6 +99,10 @@ public class AdPlanServiceImpl extends ServiceImpl<AdPlanMapper, AdPlan> impleme
private final IPqScriptDtlsService pqScriptDtlsService;
private final IDictTreeService dictTreeService;
private final TableGenService tableGenService;
private final ISysTestConfigService sysTestConfigService;
private final IDevTypeService devTypeService;
private final IDictTypeService dictTypeService;
private final AdHarmonicService adHarmonicService;
@Override
public Page<AdPlanVO> listAdPlan(AdPlanParam.QueryParam queryParam) {
@@ -76,6 +113,10 @@ public class AdPlanServiceImpl extends ServiceImpl<AdPlanMapper, AdPlan> impleme
BeanUtil.copyProperties(adPlan, adPlanVO);
adPlanVO.setCreateTime(adPlanVO.getCreateTime().replace("T", " "));
adPlanVO.setDatasourceIds(Arrays.asList(adPlan.getDatasourceId().split(StrUtil.COMMA)));
if (StrUtil.isNotBlank(adPlan.getReportTemplateId())) {
PqReport report = this.baseMapper.getPqReportById(adPlan.getReportTemplateId());
adPlanVO.setReportTemplateName(report.getName() + "_" + report.getVersion());
}
return adPlanVO;
}).collect(Collectors.toList());
adPlanVOList.forEach(adPlanVO -> {
@@ -96,7 +137,7 @@ public class AdPlanServiceImpl extends ServiceImpl<AdPlanMapper, AdPlan> impleme
}
@Override
@Transactional(rollbackFor = {Exception.class})
@Transactional
public boolean addAdPlan(AdPlanParam param) {
this.checkRepeat(param, false);
AdPlan adPlan = new AdPlan();
@@ -114,6 +155,15 @@ public class AdPlanServiceImpl extends ServiceImpl<AdPlanMapper, AdPlan> impleme
adPlan.setResult(CheckResultEnum.UNCHECKED.getValue());
adPlan.setCode(this.generateCode());
if (param.getAssociateReport() != null && param.getAssociateReport() == 1) {
String reportTemplateName = param.getReportTemplateName();
String[] split = reportTemplateName.split("_");
String reportId = this.baseMapper.getReportIdByNameAndVersion(split[0], split[1]);
if (StrUtil.isNotBlank(reportId)) {
adPlan.setReportTemplateId(reportId);
}
}
// 新增检测计划、检测源关联
adPlanSourceService.addAdPlanSource(planId, param.getSourceIds());
if (ObjectUtil.isNotEmpty(param.getDevIds())) {
@@ -132,37 +182,62 @@ public class AdPlanServiceImpl extends ServiceImpl<AdPlanMapper, AdPlan> impleme
}
@Override
@Transactional(rollbackFor = {Exception.class})
@Transactional
public boolean updateAdPlan(AdPlanParam.UpdateParam param) {
this.checkRepeat(param, true);
AdPlan adPlan = new AdPlan();
BeanUtil.copyProperties(param, adPlan);
AdPlan plan1 = this.getById(param.getId());
AdPlan plan2 = new AdPlan();
adPlan.setDatasourceId(String.join(StrUtil.COMMA, param.getDatasourceIds()));
if (param.getAssociateReport() != null && param.getAssociateReport() == 1) {
String reportTemplateName = param.getReportTemplateName();
String[] split = reportTemplateName.split("_");
String reportId = this.baseMapper.getReportIdByNameAndVersion(split[0], split[1]);
if (plan1.getTestState() != CheckStateEnum.UNCHECKED.getValue()) {
if (!reportId.equals(plan1.getReportTemplateId())) {
throw new BusinessException(DetectionResponseEnum.CANNOT_CHANGE_REPORT_WHEN_CHECKING);
}
}
if (StrUtil.isNotBlank(reportId)) {
plan2.setReportTemplateId(reportId);
}
}
if (plan1.getTestState() != CheckStateEnum.UNCHECKED.getValue()) {
if (!plan1.getScriptId().equals(param.getScriptId())) {
throw new BusinessException(DetectionResponseEnum.CANNOT_CHANGE_SCRIPT_WHEN_CHECKING);
}
if (!plan1.getErrorSysId().equals(param.getErrorSysId())) {
throw new BusinessException(DetectionResponseEnum.CANNOT_CHANGE_ERROR_SYS_WHEN_CHECKING);
}
if (param.getAssociateReport() != null && param.getAssociateReport() != plan1.getAssociateReport()) {
throw new BusinessException(DetectionResponseEnum.CANNOT_CHANGE_REPORT_WHEN_CHECKING);
}
}
BeanUtil.copyProperties(param, plan2);
plan2.setDatasourceId(String.join(StrUtil.COMMA, param.getDatasourceIds()));
// 修改检测计划、检测源关联
adPlanSourceService.updateAdPlanSource(param.getId(), param.getSourceIds());
plan2.setTestState(pqDevService.bind(param.getId(), param.getDevIds()));
adPlan.setTestState(pqDevService.bind(param.getId(), param.getDevIds()));
return this.updateById(adPlan);
return this.updateById(plan2);
}
@Override
@Transactional(rollbackFor = {Exception.class})
@Transactional
public boolean deleteAdPlan(List<String> ids) {
for (String id : ids) {
PqDevParam.QueryParam queryParam = new PqDevParam.QueryParam();
queryParam.setPlanId(id);
if (ObjectUtils.isNotEmpty(pqDevService.listByPlanId(queryParam))) {
throw new BusinessException(DevResponseEnum.PLAN_HAS_DEVICE_BIND);
throw new BusinessException(DetectionResponseEnum.PLAN_HAS_DEVICE_BIND);
}
}
// 删除检测计划、检测源关联
adPlanSourceService.deleteAdPlanSourceByPlanIds(ids);
// 删除相关检测表格
List<String> codeList = this.listByIds(ids).stream().map(plan->String.valueOf(plan.getCode())).collect(Collectors.toList());
List<String> codeList = this.listByIds(ids).stream().map(plan -> String.valueOf(plan.getCode())).collect(Collectors.toList());
tableGenService.deleteTable(codeList);
return this.lambdaUpdate().in(AdPlan::getId, ids).set(AdPlan::getState, DataStateEnum.DELETED.getCode()).update();
@@ -203,97 +278,6 @@ public class AdPlanServiceImpl extends ServiceImpl<AdPlanMapper, AdPlan> impleme
return result;
}
@Override
public void downloadTemplate() {
ExcelUtil.exportExcel("检测计划模板.xlsx", AdPlanExcel.ImportData.class, Collections.emptyList());
}
@Override
public List<AdPlanExcel.ExportData> getExportData(AdPlanParam.QueryParam queryParam) {
List<AdPlan> planList = this.list(this.getQueryWrapper(queryParam));
this.visualize(planList);
List<AdPlanExcel.ExportData> planExcelList = BeanUtil.copyToList(planList, AdPlanExcel.ExportData.class);
for (int i = 0; i < planList.size(); i++) {
List<PqSource> pqSources = adPlanSourceService.listPqSourceByPlanId(planList.get(i).getId());
planExcelList.get(i).setSource(pqSources.stream().map(PqSource::getName).collect(Collectors.joining(StrUtil.COMMA)));
PqDevParam.QueryParam queryParam1 = new PqDevParam.QueryParam();
queryParam1.setPlanId(planList.get(i).getId());
List<PqDev> pqDevs = pqDevService.listByPlanId(queryParam1);
pqDevService.visualize(pqDevs);
planExcelList.get(i).setDevices(BeanUtil.copyToList(pqDevs, AdPlanExcel.BoundExportData.class));
}
return planExcelList;
}
@Override
@Transactional(rollbackFor = Exception.class)
public void importData(String patternId, List<AdPlanExcel.ImportData> adPlanExcelList) {
List<AdPlan> adPlans = BeanUtil.copyToList(adPlanExcelList, AdPlan.class);
List<PqDev> devList = new ArrayList<>();
String patternCode = dictDataService.getDictDataById(patternId).getCode();
for (int i = 0; i < adPlans.size(); i++) {
AdPlanExcel.ImportData adPlanExcel = adPlanExcelList.get(i);
String planId = UUID.randomUUID().toString().replaceAll("-", "");
adPlans.get(i).setId(planId);
adPlans.get(i).setPattern(patternId);
String source = adPlanExcel.getSource();
String[] sourceNames = source.split(StrUtil.COMMA);
// 若非比对模式检测源、数据源有2个以上时不导入
if (!PatternEnum.CONTRAST.getValue().equals(patternCode) && sourceNames.length > 1) {
throw new BusinessException(DevResponseEnum.IMPORT_SOURCE_ERROR);
}
String datasource = adPlanExcel.getDatasourceId();
String[] datasourceIds = datasource.split(StrUtil.COMMA);
// 若非比对模式数据源有2个以上时不导入
if (!PatternEnum.CONTRAST.getValue().equals(patternCode) && datasourceIds.length > 1) {
throw new BusinessException(DevResponseEnum.IMPORT_DATASOURCE_ERROR);
}
List<String> sourceIds = pqSourceService.listPqSourceIdByName(sourceNames);
adPlanSourceService.addAdPlanSource(planId, sourceIds);
List<PqDev> pqDevs = adPlanExcel.getDevices().stream()
.map(planExcel -> {
PqDev dev = new PqDev();
BeanUtil.copyProperties(planExcel, dev);
dev.setPlanId(planId);
dev.setPattern(patternId);
return dev;
}).collect(Collectors.toList());
devList.addAll(pqDevs);
}
// 逆向可视化
this.reverseVisualize(adPlans);
this.saveBatch(adPlans);
pqDevService.reverseVisualize(devList);
pqDevService.saveBatch(devList);
}
/**
* 获取查询条件wrapper
*
* @param queryParam 查询条件
* @return
*/
private Wrapper getQueryWrapper(AdPlanParam.QueryParam queryParam) {
QueryWrapper<AdPlan> queryWrapper = new QueryWrapper<>();
if (ObjectUtil.isNotNull(queryParam)) {
queryWrapper.eq(StrUtil.isNotBlank(queryParam.getPattern()), "ad_plan.pattern", queryParam.getPattern())
.eq(StrUtil.isNotBlank(queryParam.getName()), "ad_plan.name", queryParam.getName())
.eq(ObjectUtil.isNotNull(queryParam.getTestState()), "ad_plan.Test_State", queryParam.getTestState())
.eq(ObjectUtil.isNotNull(queryParam.getReportState()), "ad_plan.Report_State", queryParam.getReportState())
.eq(ObjectUtil.isNotNull(queryParam.getResult()), "ad_plan.result", queryParam.getResult());
}
queryWrapper.eq("ad_plan.state", DataStateEnum.ENABLE.getCode()).orderByDesc("Create_Time");
return queryWrapper;
}
@Override
public void visualize(List<AdPlan> planList) {
planList.forEach(adPlan -> {
@@ -320,18 +304,37 @@ public class AdPlanServiceImpl extends ServiceImpl<AdPlanMapper, AdPlan> impleme
}
@Override
public List<Map<String, String>> getBigTestItem(String planId) {
public List<Map<String, String>> getBigTestItem(Integer reCheckType, String planId, String devId) {
List<Map<String, String>> result = new ArrayList<>();
AdPlan adPlan = this.getById(planId);
if (ObjectUtil.isNull(adPlan)) {
throw new BusinessException(PlanResponseEnum.PLAN_NOT_EXIST);
throw new BusinessException(DetectionResponseEnum.PLAN_NOT_EXIST);
}
String scriptId = adPlan.getScriptId();
List<PqScriptDtls> scriptDtlsList = pqScriptDtlsService.listPqScriptDtlByScriptId(scriptId);
// 不合格项复检
if (reCheckType == 0) {
// List<AdBaseResult> allResultList = new ArrayList<>();
// allResultList.addAll(adHarmonicService.get(scriptId, null, devId, "-1", adPlan.getCode()));
// allResultList.addAll(adNonHarmonicService.get(scriptId, null, devId, "-1", adPlan.getCode()));
//
// if (ObjectUtil.isNotEmpty(allResultList)) {
// List<AdBaseResult> passList = allResultList.stream().filter(obj -> obj.getResultFlag() == 1).collect(Collectors.toList());
// TreeSet<Integer> sortSet = passList.stream().map(AdBaseResult::getSort).collect(Collectors.toCollection(TreeSet::new));
//
// scriptDtlsList = scriptDtlsList.stream().filter(obj -> !sortSet.contains(obj.getScriptIndex())).collect(Collectors.toList());
// }
StorageParam storageParam = new StorageParam();
storageParam.setCode(adPlan.getCode() + "");
storageParam.setScriptId(adPlan.getScriptId());
List<Integer> indexes = adHarmonicService.getIndex(storageParam, true);
scriptDtlsList = scriptDtlsList.stream().filter(obj -> indexes.contains(obj.getScriptIndex())).collect(Collectors.toList());
}
Map<String, List<PqScriptDtls>> collect = scriptDtlsList.stream()
.sorted(Comparator.comparing(PqScriptDtls::getIndex))
.sorted(Comparator.comparing(PqScriptDtls::getScriptIndex))
.collect(Collectors.groupingBy(PqScriptDtls::getScriptType, LinkedHashMap::new, Collectors.toList()));
collect.forEach((key, value) -> {
@@ -342,7 +345,7 @@ public class AdPlanServiceImpl extends ServiceImpl<AdPlanMapper, AdPlan> impleme
map.put("code", dictTree.getCode());
map.put("scriptName", dictTree.getName());
} else {
throw new BusinessException(PlanResponseEnum.SCRIPT_RELATE_DICT_NOT_EXIST);
throw new BusinessException(DetectionResponseEnum.SCRIPT_RELATE_DICT_NOT_EXIST);
}
result.add(map);
});
@@ -396,6 +399,415 @@ public class AdPlanServiceImpl extends ServiceImpl<AdPlanMapper, AdPlan> impleme
.set(AdPlan::getTestState, CheckStateEnum.CHECKED.getValue());
}
@Override
public void analyse(List<String> ids) {
SysTestConfig config = sysTestConfigService.getOneConfig();
if (ObjectUtil.isNotNull(config)) {
Integer maxTime = config.getMaxTime();
List<AdPlan> planList = this.listByIds(ids);
planList.forEach(plan -> {
if (!CheckStateEnum.CHECKED.getValue().equals(plan.getTestState())) {
throw new BusinessException(DetectionResponseEnum.NOT_CHECKED_PLAN_CANNOT_ANALYSE);
}
});
Map<String, List<String[]>> sheets = new TreeMap<>(new Comparator<String>() {
@Override
public int compare(String o1, String o2) {
if (o1.equals("概览")) {
return -1;
} else {
return o1.compareTo(o2);
}
}
});
if (planList.size() > 1) {
StringBuffer allNote = new StringBuffer();
List<PqDev> allDevList = new ArrayList<>();
for (AdPlan plan : planList) {
PqDevParam.QueryParam queryParam = new PqDevParam.QueryParam();
queryParam.setPlanId(plan.getId());
List<PqDev> devList = pqDevService.listByPlanId(queryParam);
devList = devList.stream().filter(x -> !x.getCheckResult().equals(CheckResultEnum.UNCHECKED.getValue())).collect(Collectors.toList());
allDevList.addAll(devList);
allNote.append(plan.getName() + "计划" + devList.size() + "台,");
if (plan.getName().equals("概览")) {
sheets.put(plan.getName() + "检测计划", getRows(plan.getName(), devList, maxTime, getNote(plan, devList)));
} else {
sheets.put(plan.getName(), getRows(plan.getName(), devList, maxTime, getNote(plan, devList)));
}
}
allNote.insert(0, "说明:总计" + allDevList.size() + "台设备,");
allNote.replace(allNote.length() - 1, allNote.length(), "");
sheets.put("概览", getRows("数据分析结果-所有计划", allDevList, maxTime, allNote.toString()));
} else {
AdPlan plan = planList.get(0);
PqDevParam.QueryParam queryParam = new PqDevParam.QueryParam();
queryParam.setPlanId(plan.getId());
List<PqDev> devList = pqDevService.listByPlanId(queryParam);
devList = devList.stream().filter(x -> !x.getCheckResult().equals(CheckResultEnum.UNCHECKED.getValue())).collect(Collectors.toList());
sheets.put(plan.getName(), getRows(plan.getName(), devList, maxTime, getNote(plan, devList)));
}
exportPassRateExcel("数据分析结果.xlsx", maxTime, sheets);
}
}
@Override
public void exportPlan(AdPlanParam.QueryParam queryParam) {
String currrentScene = sysTestConfigService.getCurrrentScene();
SceneEnum sceneEnum = SceneEnum.getSceneEnum(currrentScene);
switch (sceneEnum) {
case PROVINCE_PLATFORM:
this.exportProvincePlan(queryParam);
break;
case LEAVE_FACTORY_TEST:
this.exportCNPlan(queryParam);
break;
case SELF_TEST:
break;
default:
break;
}
}
@Override
public void downloadTemplate() {
String currrentScene = sysTestConfigService.getCurrrentScene();
SceneEnum sceneEnum = SceneEnum.getSceneEnum(currrentScene);
switch (sceneEnum) {
case PROVINCE_PLATFORM:
ExcelUtil.exportExcelPullDown(new ExportParams(), "检测计划模板.xlsx", 2, this.getPullDownList(SceneEnum.PROVINCE_PLATFORM), ProvincePlanExcel.class, Collections.emptyList());
break;
case LEAVE_FACTORY_TEST:
ExcelUtil.exportExcelPullDown(new ExportParams(), "检测计划模板.xlsx", 2, this.getPullDownList(SceneEnum.LEAVE_FACTORY_TEST), CNPlanExcel.class, Collections.emptyList());
break;
case SELF_TEST:
break;
default:
break;
}
}
@Override
public void importPlan(MultipartFile file, String patternId, HttpServletResponse response) {
String currrentScene = sysTestConfigService.getCurrrentScene();
SceneEnum sceneEnum = SceneEnum.getSceneEnum(currrentScene);
switch (sceneEnum) {
case PROVINCE_PLATFORM:
this.importProvincePlan(file, patternId, response);
break;
case LEAVE_FACTORY_TEST:
this.importCNPlan(file, patternId, response);
break;
case SELF_TEST:
break;
default:
break;
}
}
/**
* 省级平台导出检测计划数据
*
* @param queryParam
*/
private void exportProvincePlan(AdPlanParam.QueryParam queryParam) {
List<AdPlan> planList = this.list(this.getQueryWrapper(queryParam));
this.visualize(planList);
List<ProvincePlanExcel> planExcelList = BeanUtil.copyToList(planList, ProvincePlanExcel.class);
for (int i = 0; i < planList.size(); i++) {
List<PqSource> pqSources = adPlanSourceService.listPqSourceByPlanId(planList.get(i).getId());
planExcelList.get(i).setSource(pqSources.stream().map(PqSource::getName).collect(Collectors.joining(StrUtil.COMMA)));
PqDevParam.QueryParam queryParam1 = new PqDevParam.QueryParam();
queryParam1.setPlanId(planList.get(i).getId());
List<PqDev> pqDevs = pqDevService.listByPlanId(queryParam1);
pqDevService.visualizeProvinceDev(pqDevs);
List<ProvinceDevExcel> deviceExportData = BeanUtil.copyToList(pqDevs, ProvinceDevExcel.class);
planExcelList.get(i).setDevices(deviceExportData);
}
ExcelUtil.exportExcelPullDown(new ExportParams(), "检测计划导出数据.xlsx", 2, this.getPullDownList(SceneEnum.PROVINCE_PLATFORM), ProvincePlanExcel.class, planExcelList);
}
/**
* 二楼导出检测计划数据
*
* @param queryParam 查询参数
*/
private void exportCNPlan(AdPlanParam.QueryParam queryParam) {
List<AdPlan> planList = this.list(this.getQueryWrapper(queryParam));
this.visualize(planList);
List<CNPlanExcel> planExcelList = BeanUtil.copyToList(planList, CNPlanExcel.class);
for (int i = 0; i < planList.size(); i++) {
List<PqSource> pqSources = adPlanSourceService.listPqSourceByPlanId(planList.get(i).getId());
planExcelList.get(i).setSource(pqSources.stream().map(PqSource::getName).collect(Collectors.joining(StrUtil.COMMA)));
PqDevParam.QueryParam queryParam1 = new PqDevParam.QueryParam();
queryParam1.setPlanId(planList.get(i).getId());
List<PqDev> pqDevs = pqDevService.listByPlanId(queryParam1);
pqDevService.visualizeCNDev(pqDevs);
List<CNDevExcel> deviceExportData = BeanUtil.copyToList(pqDevs, CNDevExcel.class);
planExcelList.get(i).setDevices(deviceExportData);
}
ExcelUtil.exportExcelPullDown(new ExportParams(), "检测计划导出数据.xlsx", 2, this.getPullDownList(SceneEnum.LEAVE_FACTORY_TEST), CNPlanExcel.class, planExcelList);
}
@Transactional
public void importCNPlan(MultipartFile file, String patternId, HttpServletResponse response) {
ImportParams params = new ImportParams();
params.setStartSheetIndex(0);
params.setSheetNum(1);
params.setHeadRows(2);
params.setNeedVerify(true);
List<CNPlanExcel> planExcelList = null;
try {
ExcelImportResult<CNPlanExcel> excelImportResult = ExcelImportUtil.importExcelMore(file.getInputStream(), CNPlanExcel.class, params);
if (excelImportResult.isVerifyFail()) {
// 此处前端要做特殊处理,具体可以参考技术监督的数据导入
Workbook failWorkbook = excelImportResult.getFailWorkbook();
PoiUtil.exportFileByWorkbook(failWorkbook, "非法检测计划数据.xlsx", response);
} else {
planExcelList = excelImportResult.getList();
}
} catch (Exception e) {
throw new BusinessException(DetectionResponseEnum.IMPORT_DATA_FAIL);
}
if (ObjectUtil.isNotEmpty(planExcelList)) {
this.importCNPlan(planExcelList, patternId);
}
}
/**
* 二楼导入检测计划
*
* @param planExcelList
* @param patternId
*/
@Transactional
public void importCNPlan(List<CNPlanExcel> planExcelList, String patternId) {
List<AdPlan> adPlans = BeanUtil.copyToList(planExcelList, AdPlan.class);
String patternCode = dictDataService.getDictDataById(patternId).getCode();
for (int i = 0; i < adPlans.size(); i++) {
CNPlanExcel planExcel = planExcelList.get(i);
AdPlanParam adPlanParam = new AdPlanParam();
adPlanParam.setName(planExcel.getName());
adPlanParam.setPattern(patternId);
checkRepeat(adPlanParam, false);
String planId = UUID.randomUUID().toString().replaceAll("-", "");
adPlans.get(i).setId(planId);
adPlans.get(i).setPattern(patternId);
Integer code = this.generateCode();
adPlans.get(i).setCode(code);
tableGenService.deleteTable(Arrays.asList(code.toString()));
tableGenService.genAdNonHarmonicTable(code.toString());
String source = planExcel.getSource();
String[] sourceNames = source.split(StrUtil.COMMA);
// 若非比对模式检测源、数据源有2个以上时不导入
if (!PatternEnum.CONTRAST.getValue().equals(patternCode) && sourceNames.length > 1) {
throw new BusinessException(DetectionResponseEnum.IMPORT_SOURCE_ERROR);
}
String datasource = planExcel.getDatasourceId();
String[] datasourceIds = datasource.split(StrUtil.COMMA);
// 若非比对模式数据源有2个以上时不导入
if (!PatternEnum.CONTRAST.getValue().equals(patternCode) && datasourceIds.length > 1) {
throw new BusinessException(DetectionResponseEnum.IMPORT_DATASOURCE_ERROR);
}
List<String> sourceIds = pqSourceService.listPqSourceIdByName(sourceNames);
adPlanSourceService.addAdPlanSource(planId, sourceIds);
List<CNDevExcel> cnDevExcelList = planExcel.getDevices();
pqDevService.importCNDev(cnDevExcelList, patternId, planId);
}
// 逆向可视化
this.reverseVisualize(adPlans);
this.saveBatch(adPlans);
}
@Transactional
public void importProvincePlan(MultipartFile file, String patternId, HttpServletResponse response) {
ImportParams params = new ImportParams();
params.setStartSheetIndex(0);
params.setSheetNum(1);
params.setHeadRows(2);
params.setNeedVerify(true);
List<ProvincePlanExcel> planExcelList = null;
try {
ExcelImportResult<ProvincePlanExcel> excelImportResult = ExcelImportUtil.importExcelMore(file.getInputStream(), ProvincePlanExcel.class, params);
if (excelImportResult.isVerifyFail()) {
// 此处前端要做特殊处理,具体可以参考技术监督的数据导入
Workbook failWorkbook = excelImportResult.getFailWorkbook();
PoiUtil.exportFileByWorkbook(failWorkbook, "非法检测计划数据.xlsx", response);
} else {
planExcelList = excelImportResult.getList();
}
} catch (Exception e) {
throw new BusinessException(DetectionResponseEnum.IMPORT_DATA_FAIL);
}
if (ObjectUtil.isNotEmpty(planExcelList)) {
this.importProvincePlan(planExcelList, patternId);
}
}
/**
* 省级平台导入检测计划
*
* @param planExcelList
* @param patternId
*/
public void importProvincePlan(List<ProvincePlanExcel> planExcelList, String patternId) {
List<AdPlan> adPlans = BeanUtil.copyToList(planExcelList, AdPlan.class);
String patternCode = dictDataService.getDictDataById(patternId).getCode();
for (int i = 0; i < adPlans.size(); i++) {
ProvincePlanExcel planExcel = planExcelList.get(i);
AdPlanParam adPlanParam = new AdPlanParam();
adPlanParam.setName(planExcel.getName());
adPlanParam.setPattern(patternId);
checkRepeat(adPlanParam, false);
String planId = UUID.randomUUID().toString().replaceAll("-", "");
adPlans.get(i).setId(planId);
adPlans.get(i).setPattern(patternId);
Integer code = this.generateCode();
adPlans.get(i).setCode(code);
tableGenService.deleteTable(Arrays.asList(code.toString()));
tableGenService.genAdNonHarmonicTable(code.toString());
String source = planExcel.getSource();
String[] sourceNames = source.split(StrUtil.COMMA);
// 若非比对模式检测源、数据源有2个以上时不导入
if (!PatternEnum.CONTRAST.getValue().equals(patternCode) && sourceNames.length > 1) {
throw new BusinessException(DetectionResponseEnum.IMPORT_SOURCE_ERROR);
}
String datasource = planExcel.getDatasourceId();
String[] datasourceIds = datasource.split(StrUtil.COMMA);
// 若非比对模式数据源有2个以上时不导入
if (!PatternEnum.CONTRAST.getValue().equals(patternCode) && datasourceIds.length > 1) {
throw new BusinessException(DetectionResponseEnum.IMPORT_DATASOURCE_ERROR);
}
List<String> sourceIds = pqSourceService.listPqSourceIdByName(sourceNames);
adPlanSourceService.addAdPlanSource(planId, sourceIds);
List<ProvinceDevExcel> cnDevExcelList = planExcel.getDevices();
pqDevService.importProvinceDev(cnDevExcelList, patternId, planId);
}
// 逆向可视化
this.reverseVisualize(adPlans);
this.saveBatch(adPlans);
}
/**
* 获取查询条件wrapper
*
* @param queryParam 查询条件
* @return
*/
private Wrapper getQueryWrapper(AdPlanParam.QueryParam queryParam) {
QueryWrapper<AdPlan> queryWrapper = new QueryWrapper<>();
if (ObjectUtil.isNotNull(queryParam)) {
queryWrapper.eq(StrUtil.isNotBlank(queryParam.getPattern()), "ad_plan.pattern", queryParam.getPattern())
.like(StrUtil.isNotBlank(queryParam.getName()), "ad_plan.name", queryParam.getName())
.eq(ObjectUtil.isNotNull(queryParam.getTestState()), "ad_plan.Test_State", queryParam.getTestState())
.eq(ObjectUtil.isNotNull(queryParam.getReportState()), "ad_plan.Report_State", queryParam.getReportState())
.eq(ObjectUtil.isNotNull(queryParam.getResult()), "ad_plan.result", queryParam.getResult());
}
queryWrapper.eq("ad_plan.state", DataStateEnum.ENABLE.getCode()).orderByDesc("Create_Time");
return queryWrapper;
}
/**
* 获取备注信息
*
* @param plan 检测计划
* @param devList 设备列表
* @return 备注信息
*/
private String getNote(AdPlan plan, List<PqDev> devList) {
StringBuffer note = new StringBuffer();
note.append("说明:本计划共有" + devList.size() + "台设备,");
Map<String, List<PqDev>> devTypeMap = devList.stream().collect(Collectors.groupingBy(PqDev::getDevType, Collectors.toList()));
devTypeMap.forEach((key, value) -> {
DevType devType = devTypeService.getById(key);
if (ObjectUtil.isNotNull(devType)) {
note.append(devType.getName() + "型号" + value.size() + "台,");
}
});
PqErrSys errSys = pqErrSysService.getById(plan.getErrorSysId());
SysTestConfig config1 = sysTestConfigService.getConfig();
if (ObjectUtil.isNotNull(config1)) {
DictData dictData = dictDataService.getDictDataById(config1.getDataRule());
if (ObjectUtil.isNotNull(errSys) && ObjectUtil.isNotNull(dictData)) {
note.append("测试结果采用\"" + errSys.getName() + "\"误差体系结合\"" + dictData.getName() + "\"数据原则计算得出。");
}
}
return note.toString();
}
/**
* 获取行数据
*
* @param header 表头
* @param devList 设备列表
* @param maxTime 最大复检次数
* @param note 备注
* @return
*/
private List<String[]> getRows(String header, List<PqDev> devList, Integer maxTime, String note) {
List<String[]> rows = new ArrayList<>();
String[] row1 = new String[]{header};
String[] row2 = new String[maxTime + 1];
row2[0] = "\\";
String[] row3 = new String[maxTime + 1];
row3[0] = "合格数量";
String[] row4 = new String[maxTime + 1];
row4[0] = "总数量";
String[] row5 = new String[maxTime + 1];
row5[0] = "合格率";
String[] row6 = new String[maxTime + 1];
row6[0] = note;
long total = devList.size();
for (int i = 1; i <= maxTime; i++) {
row2[i] = i + "次检测";
int tempI = i;
List<PqDev> 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 + "";
if (total != 0) {
row5[i] = String.format("%.2f%%", (float) passCount / total * 100);
} else {
row5[i] = "/";
}
}
rows.add(row1);
rows.add(row2);
rows.add(row3);
rows.add(row4);
rows.add(row5);
rows.add(row6);
return rows;
}
/**
* 逆向可视化
@@ -452,7 +864,236 @@ public class AdPlanServiceImpl extends ServiceImpl<AdPlanMapper, AdPlan> impleme
}
int count = this.count(queryWrapper);
if (count > 0) {
throw new BusinessException(PlanResponseEnum.PLAN_REPEATED);
throw new BusinessException(DetectionResponseEnum.PLAN_REPEATED);
}
}
private void exportPassRateExcel(String fileName, Integer maxTime, Map<String, List<String[]>> sheets) {
HttpServletResponse response = HttpServletUtil.getResponse();
XSSFWorkbook wb = new XSSFWorkbook();
try (ServletOutputStream outputStream = response.getOutputStream()) {
fileName = URLEncoder.encode(fileName, CharsetUtil.UTF_8);
response.reset();
response.setHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\"");
response.setContentType("application/octet-stream;charset=UTF-8");
sheets.forEach((sheetName, rows) -> {
XSSFSheet sheet = wb.createSheet(sheetName);
// 数据行
CellStyle cellStyle = wb.createCellStyle();
cellStyle.setAlignment(HorizontalAlignment.CENTER);
cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
XSSFFont headerFont = wb.createFont();
headerFont.setFontName("Microsoft YaHei");
headerFont.setBold(true);
headerFont.setFontHeightInPoints((short) 14);
cellStyle.setFont(headerFont);
Row row0 = sheet.createRow(0);
Cell row0Cell0 = row0.createCell(0);
row0Cell0.setCellStyle(cellStyle);
row0Cell0.setCellValue(rows.get(0)[0]);
CellRangeAddress mergedRegion = new CellRangeAddress(0, 0, 0, 2 * maxTime + 1);
sheet.addMergedRegion(mergedRegion);
CellStyle commoncellStyle = wb.createCellStyle();
commoncellStyle.setAlignment(HorizontalAlignment.CENTER);
commoncellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
for (int i = 1; i < rows.size() - 1; i++) {
String[] row = rows.get(i);
Row createRow = sheet.createRow(i);
for (int j = 0; j < row.length; j++) {
Cell createCell = createRow.createCell(j);
if (j == 0 || i == 1) {
headerFont.setFontHeightInPoints((short) 11);
createCell.setCellStyle(cellStyle);
} else {
createCell.setCellStyle(commoncellStyle);
}
if ("\\".equals(row[j])) {
CreationHelper helper = wb.getCreationHelper();
XSSFDrawing drawing = sheet.createDrawingPatriarch();
ClientAnchor anchor = helper.createClientAnchor();
// 设置斜线的开始位置
anchor.setCol1(j);
anchor.setRow1(i);
// 设置斜线的结束位置
anchor.setCol2(j + 1);
anchor.setRow2(i + 1);
XSSFSimpleShape shape = drawing.createSimpleShape((XSSFClientAnchor) anchor);
// 设置形状类型为线型
shape.setShapeType(ShapeTypes.LINE);
// 设置线宽
shape.setLineWidth(0.5);
// 设置线的风格
shape.setLineStyle(0);
// 设置线的颜色
shape.setLineStyleColor(0, 0, 0);
} else {
createCell.setCellValue(row[j]);
}
}
}
Row note = sheet.createRow(rows.size() - 1);
Cell noteCell0 = note.createCell(0);
commoncellStyle.setWrapText(true);
noteCell0.setCellStyle(commoncellStyle);
noteCell0.setCellValue(rows.get(rows.size() - 1)[0]);
mergedRegion = new CellRangeAddress(rows.size() - 1, rows.size() + 2, 0, maxTime);
sheet.addMergedRegion(mergedRegion);
// 条形图
XSSFDrawing drawing = sheet.createDrawingPatriarch();
// 前四个默认0[0,5]从0列5行开始;[6,16]:到6列16行结束
// 默认宽度(14-8)*12
XSSFClientAnchor anchor = drawing.createAnchor(0, 0, 0, 0, maxTime + 1, 1, 2 * maxTime + 2, 25);
// 创建一个chart对象
XSSFChart chart = drawing.createChart(anchor);
// 标题
chart.setTitleText("检测结果分析");
// 标题覆盖
chart.setTitleOverlay(false);
// 图例位置
XDDFChartLegend legend = chart.getOrAddLegend();
legend.setPosition(LegendPosition.TOP);
// 分类轴标(X轴),标题位置
XDDFCategoryAxis bottomAxis = chart.createCategoryAxis(AxisPosition.BOTTOM);
bottomAxis.setTitle("检测次数");
// 值(Y轴)轴,标题位置
XDDFValueAxis leftAxis = chart.createValueAxis(AxisPosition.LEFT);
leftAxis.setTitle("合格率(%)");
// CellRangeAddress(起始行号,终止行号, 起始列号,终止列号)
// 分类轴标(X轴)数据,单元格范围位置[1, 1]到[1, maxTime]
XDDFDataSource<String> checkTimes = XDDFDataSourcesFactory.fromStringCellRange(sheet, new CellRangeAddress(1, 1, 1, maxTime));
// 数据
String[] rateStrArr = rows.get(rows.size() - 2);
Double[] rateArr = new Double[maxTime];
for (int i = 1; i < rateStrArr.length; i++) {
if ("/".equals(rateStrArr[i])) {
rateArr[i - 1] = 0.00;
} else {
rateArr[i - 1] = Double.parseDouble(rateStrArr[i].replace("%", ""));
}
}
XDDFNumericalDataSource<Double> rate = XDDFDataSourcesFactory.fromArray(rateArr);
// bar条形图
XDDFBarChartData bar = (XDDFBarChartData) chart.createData(ChartTypes.BAR, bottomAxis, leftAxis);
leftAxis.setCrossBetween(AxisCrossBetween.BETWEEN);
// 设置为可变颜色
bar.setVaryColors(true);// 这里可变颜色要设置成true如果需要设置成自己想要的颜色则置为false然后在下面设置颜色
// 条形图方向,纵向/横向:纵向
bar.setBarDirection(BarDirection.COL);
// 图表加载数据条形图1
bar.addSeries(checkTimes, rate);
CTPlotArea plotArea = chart.getCTChart().getPlotArea();
CTBarSer serArray = plotArea.getBarChartArray(0).getSerArray(0);
serArray.addNewDLbls();
serArray.getDLbls().addNewShowVal().setVal(true);
serArray.getDLbls().addNewShowLegendKey().setVal(false);
serArray.getDLbls().addNewShowCatName().setVal(false);
serArray.getDLbls().addNewShowSerName().setVal(false);
// 打印图表的xml
//System.out.println(chart.getCTChart());
// 绘制
chart.plot(bar);
});
wb.write(outputStream);
wb.close();
} catch (IOException e) {
log.error(">>> 导出数据异常:{}", e.getMessage());
}
}
private List<PullDown> getPullDownList(SceneEnum scene) {
List<PullDown> pullDowns = new ArrayList<>();
PullDown pullDown = null;
// 数据源
DictType dictType = dictTypeService.getByCode("Datasource");
if (ObjectUtil.isNotNull(dictType)) {
List<DictData> dictDataList = dictDataService.getDictDataByTypeId(dictType.getId());
pullDown = new PullDown();
pullDown.setFirstCol(2);
pullDown.setLastCol(2);
pullDown.setStrings(dictDataList.stream().map(DictData::getName).collect(Collectors.toList()));
pullDowns.add(pullDown);
}
// 检测脚本
List<Map<String, Object>> maps1 = pqScriptService.listAllPqScript(null);
List<String> scriptNameList = maps1.stream().map(m -> (String) m.get("name")).collect(Collectors.toList());
pullDown = new PullDown();
pullDown.setFirstCol(3);
pullDown.setLastCol(3);
pullDown.setStrings(scriptNameList);
pullDowns.add(pullDown);
// 误差体系
List<Map<String, Object>> maps2 = pqErrSysService.listAllPqErrSys();
List<String> errSysNameList = maps2.stream().map(m -> (String) m.get("name")).collect(Collectors.toList());
pullDown = new PullDown();
pullDown.setFirstCol(4);
pullDown.setLastCol(4);
pullDown.setStrings(errSysNameList);
pullDowns.add(pullDown);
// 是否做守时检测
pullDown = new PullDown();
pullDown.setFirstCol(5);
pullDown.setLastCol(5);
pullDown.setStrings(Arrays.asList("", ""));
pullDowns.add(pullDown);
// 检测状态
pullDown = new PullDown();
pullDown.setFirstCol(6);
pullDown.setLastCol(6);
pullDown.setStrings(Arrays.asList(CheckStateEnum.UNCHECKED.getMsg(), CheckStateEnum.CHECKING.getMsg(), CheckStateEnum.CHECKED.getMsg()));
pullDowns.add(pullDown);
// 报告生成状态
pullDown = new PullDown();
pullDown.setFirstCol(7);
pullDown.setLastCol(7);
pullDown.setStrings(Arrays.asList(PlanReportStateEnum.REPORT_STATE_NOT_GENERATED.getMsg(), PlanReportStateEnum.REPORT_STATE_PARTIALLY_GENERATED.getMsg(), PlanReportStateEnum.REPORT_STATE_ALL_GENERATED.getMsg()));
pullDowns.add(pullDown);
//检测结果
pullDown = new PullDown();
pullDown.setFirstCol(8);
pullDown.setLastCol(8);
pullDown.setStrings(Arrays.asList(CheckResultEnum.UNCHECKED.getMsg(), CheckResultEnum.ACCORD.getMsg(), CheckResultEnum.UNCHECKED.getMsg()));
pullDowns.add(pullDown);
switch (scene) {
case PROVINCE_PLATFORM:
List<PullDown> provinceDevPullDownList = pqDevService.getProvinceDevPullDownList(9);
pullDowns.addAll(provinceDevPullDownList);
break;
case LEAVE_FACTORY_TEST:
List<PullDown> cnDevPullDownList = pqDevService.getCNDevPullDownList(9);
pullDowns.addAll(cnDevPullDownList);
break;
case SELF_TEST:
break;
default:
break;
}
return pullDowns;
}
}

View File

@@ -32,7 +32,7 @@ public class AdPlanSourceServiceImpl extends ServiceImpl<AdPlanSourceMapper, AdP
}
@Override
@Transactional(rollbackFor = {Exception.class})
@Transactional
public boolean addAdPlanSource(String planId, List<String> sourceIds) {
List<AdPlanSource> adPlanSourceList = new ArrayList<>();
for (String sourceId : sourceIds) {
@@ -42,7 +42,7 @@ public class AdPlanSourceServiceImpl extends ServiceImpl<AdPlanSourceMapper, AdP
}
@Override
@Transactional(rollbackFor = {Exception.class})
@Transactional
public boolean deleteAdPlanSourceByPlanIds(List<String> planIds) {
QueryWrapper<AdPlanSource> queryWrapper = new QueryWrapper<>();
queryWrapper.in("ad_plan_source.Plan_Id", planIds);
@@ -50,7 +50,7 @@ public class AdPlanSourceServiceImpl extends ServiceImpl<AdPlanSourceMapper, AdP
}
@Override
@Transactional(rollbackFor = {Exception.class})
@Transactional
public boolean updateAdPlanSource(String planId, List<String> sourceIds) {
this.deleteAdPlanSourceByPlanIds(Collections.singletonList(planId));
this.addAdPlanSource(planId, sourceIds);

View File

@@ -1,43 +1,45 @@
package com.njcn.gather.device.pojo.constant;
package com.njcn.gather.pojo.constant;
/**
* @author caozehui
* @date 2024/11/06
* @data 2025-03-28
*/
public interface DevValidMessage {
public interface DetectionValidMessage {
String SOURCE_ID_NOT_BLANK = "检测源id不能为空";
String ID_NOT_BLANK = "id不能为空请检查id参数";
String ID_FORMAT_ERROR = "id格式错误请检查id参数";
String NAME_NOT_BLANK = "名称不能为空";
String ICD_NAME_FORMAT_ERROR = "名称格式错误只能包含字母、数字、中文、下划线、中划线、点号长度为1-50个字符";
String ICD_PATH_NOT_BLANK = "icd存储路径不能为空";
String ICD_PATH_FORMAT_ERROR = "ICD路径格式错误";
String ICD_NOT_BLANK = "ICD不能为空";
String POWER_NOT_BLANK = "工作电源不能为空";
String VOLT_NOT_BLANK = "额定电压不能为空";
String CURR_NOT_BLANK = "额定电流不能为空";
String CHNS_NOT_BLANK = "通道数不能为空";
String DEV_CHNS_RANGE_ERROR = "通道数格式错误";
String INDEX_NOT_NULL = "index不能为空";
String VALUE_TYPE_NOT_BLANK = "脚本值类型不能为空";
String SCRIPT_NAME_FORMAT_ERROR = "脚本名称格式错误只能包含字母、数字、中文、下划线、中划线、点号长度为1-50个字符";
String SCRIPT_VOLT_FORMAT_ERROR = "检测脚本额定电压格式错误请检查ratedVolt参数";
String SCRIPT_CURR_FORMAT_ERROR = "检测脚本额定电流格式错误请检查ratedCurr参数";
String PORT_RANGE_ERROR = "端口号范围错误请检查port参数";
String NAME_NOT_BLANK = "名称不能为空请检查name参数";
String NAME_FORMAT_ERROR = "名称格式错误请检查name参数";
String PATTERN_NOT_BLANK = "模式不能为空请检查pattern参数";
String DEV_TYPE_NOT_BLANK = "设备类型不能为空请检查devType参数";
String DEV_TYPE_NOT_BLANK = "设备类型不能为空";
String DEV_CHNS_NOT_NULL = "设备通道系数不能为空请检查devChns参数";
String DEV_VOLT_NOT_NULL = "额定电压不能为空请检查devVolt参数";
String DEV_CURR_NOT_NULL = "额定电流不能为空请检查devCurr参数";
String MANUFACTURER_NOT_BLANK = "设备厂家不能为空请检查manufacturer参数";
String CREATEDATETIME_NOT_NULL = "出厂日期不能为空请检查producedDate参数";
String CREATEDATETIME_FORMAT_ERROR = "出厂日期格式错误请检查createDateTime参数";
String FACTORYNO_NOT_BLANK = "出厂编号不能为空请检查factoryNo参数";
String FIRMWARE_NOT_BLANK = "固件版本不能为空请检查firmware参数";
String SOFTWARE_NOT_BLANK = "软件版本不能为空请检查software参数";
String PROTOCOL_NOT_BLANK = "通讯协议不能为空请检查protocol参数";
String IP_NOT_BLANK = "IP地址不能为空请检查ip参数";
@@ -102,18 +104,6 @@ public interface DevValidMessage {
String ERR_SYS_DTLS_SCRIPT_TYPE_FORMAT_ERROR = "脚本项类型格式错误请检查scriptType参数";
String START_VALUE_NOT_NULL = "起始值不能为空请检查startValue参数";
String START_FLAG_NOT_NULL = "是否包含起始值不能为空请检查startFlag参数";
String END_VALUE_NOT_NULL = "结束值不能为空请检查endValue参数";
String END_FLAG_NOT_NULL = "是否包含结束值不能为空请检查endFlag参数";
String CONDITION_TYPE_NOT_BLANK = "判断条件类型不能为空请检查conditionType参数";
String ERROR_VALUE_FORMAT_ERROR = "误差值格式错误请检查errorValue参数";
String MAX_ERROR_VALUE_NOT_NULL = "最大误差值不能为空请检查maxErrorValue参数";
String ERROR_VALUE_TYPE_NOT_BLANK = "误差值类型不能为空请检查errorValueType参数";
@@ -124,18 +114,6 @@ public interface DevValidMessage {
String ENABLE_NOT_NULL = "状态不能为空请检查enable参数";
String PQ_SOURCE_NAME_FORMAT_ERROR = "检测源名称格式错误请检查pqSourceName参数";
String PQ_SOURCE_PARAMETER_ID_NOT_BLANK = "检测源参数ID不能为空请检查pqSourceParameterId参数";
String PQ_SOURCE_PARAMETER_PID_NOT_BLANK = "检测源参数PID不能为空请检查pqSourceParameterId参数";
String PQ_SOURCE_PARAMETER_TYPE_NOT_BLANK = "检测源参数类型不能为空请检查pqSourceParameterType参数";
String PQ_SOURCE_PARAMETER_REMARK_NOT_BLANK = "检测源参数描述不能为空请检查pqSourceParameterRemark参数";
String PQ_SOURCE_PARAMETER_VALUE_NOT_BLANK = "参数值不能为空请检查pqSourceParameterValue参数";
String DEV_ID_NOT_BLANK = "设备ID不能为空";
String DEV_ID_FORMAT_ERROR = "设备ID格式错误";
@@ -180,10 +158,6 @@ public interface DevValidMessage {
String CHECK_RESULT_FORMAT_ERROR = "检测结果格式错误";
String DOCUMENT_STATE_FORMAT_ERROR = "归档状态格式错误";
String MONITOR_CODE_FORMAT_ERROR = "监测点编码格式错误";
String MONITOR_NUM_NOT_NULL = "监测点序号不能为空";
String FACTOR_FLAG_FORMAT_ERROR = "是否支持系数校准格式错误";
@@ -195,14 +169,9 @@ public interface DevValidMessage {
String DATASOURCE_NOT_BLANK = "数据源不能为空";
String SCRIPT_NOT_BLANK = "检测脚本不能为空";
String ERRORSYS_NOT_BLANK = "误差体系不能为空";
String TIMECHECK_NOT_BLANK = "是否做守时检测不能为空";
String FACTOR_FLAG_NOT_BLANK = "是否支持系数校准不能为空";
String CONDITION_TYPE_FORMAT_ERROR = "判断条件类型格式错误请检查conditionType参数";
String SORT_NOT_NULL = "排序不能为空";
String PREINVESTMENT_PLAN_NOT_BLANK = "预投资计划不能为空";
String TIMECHECK_NOT_NULL = "是否做守时检测不能为空";
}

View File

@@ -0,0 +1,59 @@
package com.njcn.gather.pojo.enums;
import lombok.Getter;
/**
* @author caozehui
* @data 2025-03-26
*/
@Getter
public enum DetectionResponseEnum {
/**
* 检测模块异常响应码的范围:
* A02000 ~ A02
*/
DEV_TYPE_NAME_REPEAT("A02000", "设备类型名称重复"),
SOURCE_BOUND_NOT_DELETE("A02001", "源已被计划所绑定,无法删除!"),
SCRIPT_BOUND_NOT_DELETE("A02003", "脚本已被计划所绑定,无法删除!"),
RAW_DATA_NOT_EXIST("A02004", "原始数据不存在"),
PLAN_REPEATED("A02005", "当前模式下,该计划已存在"),
PLAN_NOT_EXIST("A02006", "该计划不存在"),
SCRIPT_RELATE_DICT_NOT_EXIST("A02007", "脚本关联的字典不存在"),
NOT_CHECKED_PLAN_CANNOT_ANALYSE("A02008", "只有检测状态为检测完成的计划才能进行统计分析"),
CANNOT_CHANGE_SCRIPT_WHEN_CHECKING("A02009", "只有检测状态为未检时,才能修改检测脚本"),
CANNOT_CHANGE_ERROR_SYS_WHEN_CHECKING("A02010", "只有检测状态为未检时,才能修改误差体系"),
CANNOT_CHANGE_REPORT_WHEN_CHECKING("A02011", "只有检测状态为未检时,才能修改绑定报告模板"),
ICD_PATH_NAME_REPEAT("A02012", "icd名称重复"),
ERR_SYS_BOUND_NOT_DELETE("A02013", "误差体系已被计划所绑定,无法删除!"),
ERR_SYS_REPEAT("A02014", "已存在相同标准号、标准推行年份、适用设备等级的误差体系!"),
IMPORT_DATA_FAIL("A02040", "导入数据失败"),
SERIES_AND_DEVKEY_NOT_BLANK("A02041", "当为加密设备时,加密设备的序列号和设备密钥不能为空"),
PQ_SOURCE_GEN_NAME_ERROR("A02042", "检测源生成名称出错"),
ERR_SOURCE_GEN_NAME_ERROR("A02043", "误差体系生成名称出错"),
PQ_ERRSYS_GEN_NAME_ERROR("A02044", "误差体系生成名称出错"),
PLAN_HAS_DEVICE_BIND("A02045", "检测计划下已绑定设备,请先解绑设备"),
PQ_DEV_REPEAT("A02046", "重复的被检设备"),
PQ_DEV_HAS_MONITOR("A02047", "该设备下关联有监测点,请先移除监测点"),
HAS_NOT_UNCHECKED_DEVICE("A02048", "设备在检测中或已被检测过,请勿解除绑定"),
IMPORT_PLAN_DATA_FAIL("A02049", "导入的检测计划为空"),
IMPORT_DATA_FORMAT_FAIL("A02050", "导入数据格式错误"),
IMPORT_SOURCE_ERROR("A02051", "当前模式下一个检测计划只能有一个检测源"),
IMPORT_DATASOURCE_ERROR("A02052", "当前模式下一个检测计划只能有一个数据源"),
DEV_UN_CHECKED("A02053", "装置还未检测完成!"),
DEV_UN_REPORT("A02054", "装置报告未生成!"),
DEVICE_DIS_ERROR("A02055", "装置配置异常"),
DEVICE_DELETE("A02056", "设备无法删除,已绑定计划!"),
CREATE_DIRECTORY_FAILED("A02057", "创建目录失败"),
DELETE_DIRECTORY_FAILED("A02058", "删除目录失败");
private final String code;
private final String message;
DetectionResponseEnum(String code, String message) {
this.code = code;
this.message = message;
}
}

View File

@@ -1,11 +1,15 @@
package com.njcn.gather.report.controller;
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.report.pojo.DevReportParam;
import com.njcn.gather.report.service.IReportService;
import com.njcn.gather.report.pojo.param.ReportParam;
import com.njcn.gather.report.pojo.vo.PqReportVO;
import com.njcn.gather.report.service.IPqReportService;
import com.njcn.web.controller.BaseController;
import com.njcn.web.utils.HttpResultUtil;
import io.swagger.annotations.Api;
@@ -13,9 +17,12 @@ 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 javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.List;
/**
@@ -30,7 +37,7 @@ import javax.servlet.http.HttpServletResponse;
@RequiredArgsConstructor
public class ReportController extends BaseController {
private final IReportService reportService;
private final IPqReportService pqReportService;
/**
* 此方法临时的,给楼下使用,实际需要优化
@@ -44,7 +51,7 @@ public class ReportController extends BaseController {
public HttpResult<Object> generateReport(@RequestBody DevReportParam devReportParam) {
String methodDescribe = getMethodDescribe("generateReport");
LogUtil.njcnDebug(log, "{},终端参数为:{}", methodDescribe, devReportParam);
reportService.generateReport(devReportParam);
pqReportService.generateReport(devReportParam);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
}
@@ -58,9 +65,80 @@ public class ReportController extends BaseController {
public void downloadReport(@RequestBody DevReportParam devReportParam, HttpServletResponse response) {
String methodDescribe = getMethodDescribe("downloadReport");
LogUtil.njcnDebug(log, "{},终端参数为:{}", methodDescribe, devReportParam);
reportService.downloadReport(devReportParam,response);
pqReportService.downloadReport(devReportParam, response);
}
@OperateInfo
@PostMapping("/list")
@ApiOperation("分页查询报告模板")
@ApiImplicitParam(name = "param", value = "查询参数", required = true)
public HttpResult<Page<PqReportVO>> list(@RequestBody @Validated ReportParam.QueryParam queryParam) {
String methodDescribe = getMethodDescribe("list");
LogUtil.njcnDebug(log, "{},查询参数为:{}", methodDescribe, queryParam);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, pqReportService.list(queryParam), methodDescribe);
}
@OperateInfo
@GetMapping("/getById")
@ApiOperation("查询报告模板详情")
@ApiImplicitParam(name = "param", value = "查询参数", required = true)
public HttpResult<PqReportVO> getById(@RequestParam("id") String id) {
String methodDescribe = getMethodDescribe("getById");
LogUtil.njcnDebug(log, "{},查询参数为:{}", methodDescribe, id);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, pqReportService.getByReportId(id), methodDescribe);
}
@OperateInfo(operateType = OperateType.ADD)
@PostMapping("/add")
@ApiOperation("新增报告模板")
@ApiImplicitParam(name = "param", value = "报告模板参数", required = true)
public HttpResult<Boolean> add(ReportParam reportParam) {
String methodDescribe = getMethodDescribe("add");
LogUtil.njcnDebug(log, "{},新增参数为:{}", methodDescribe, reportParam);
boolean result = pqReportService.add(reportParam);
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 = "param", value = "报告模板参数", required = true)
public HttpResult<Boolean> update(ReportParam.UpdateParam reportParam) {
String methodDescribe = getMethodDescribe("update");
LogUtil.njcnDebug(log, "{},修改参数为:{}", methodDescribe, reportParam);
boolean result = pqReportService.update(reportParam);
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 List<String> ids) {
String methodDescribe = getMethodDescribe("delete");
LogUtil.njcnDebug(log, "{},删除参数为:{}", methodDescribe, ids);
boolean result = pqReportService.delete(ids);
if (result) {
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, methodDescribe);
} else {
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, false, methodDescribe);
}
}
@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);
}
}

View File

@@ -0,0 +1,19 @@
package com.njcn.gather.report.mapper;
import com.github.yulichang.base.MPJBaseMapper;
import com.njcn.gather.report.pojo.po.PqReport;
import java.util.List;
/**
* @author makejava
* @date 2025-03-19
*/
public interface PqReportMapper extends MPJBaseMapper<PqReport> {
/**
* 获取所有已被计划绑定的报告模板id
* @return
*/
List<String> getBoundReportIds();
}

View File

@@ -0,0 +1,10 @@
<?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.report.mapper.PqReportMapper">
<select id="getBoundReportIds" resultType="java.lang.String">
select distinct Report_Template_Id from ad_plan where state = 1
</select>
</mapper>

View File

@@ -19,6 +19,16 @@ public class DevReportParam implements Serializable {
*/
private String planId;
/**
* 计划所对应的表code
*/
private String planCode;
/**
* 脚本ID
*/
private String scriptId;
/**
* 被检设备ID
*/

View File

@@ -0,0 +1,34 @@
package com.njcn.gather.report.pojo.enums;
import lombok.Getter;
/**
* @author caozehui
* @data 2025-03-19
*/
@Getter
public enum ReportResponseEnum {
FILE_UPLOAD_FAILED("A012001", "文件上传失败"),
FILE_SUFFIX_ERROR("A012002", "文件后缀错误,请上传.docx文件"),
REPORT_REPEATED("A012003", "已存在相同版本、相同名称的报告"),
FILE_NOT_NULL("A012004", "上传的文件不能为空"),
DELETE_BOUND_REPORT_ERROR("A012005", "已被计划绑定模板的报告不能删除"),
FILE_NAME_SAME_ERROR("A012006", "文件名不能相同"),
DEVICE_NOT_EXIST("A012007", "请检查装置是否存在!"),
DEVICE_TYPE_NOT_EXIST("A012008", "设备类型缺失,请联系管理员!"),
REPORT_TEMPLATE_NOT_EXIST("A012009", "报告模板缺失,请联系管理员!"),
NO_CHECK_DATA("A012010", "没有检测数据,无法生成报告!"),
FILE_RENAME_FAILED("A012011", "文件重命名失败"),
REPORT_NAME_PATTERN_ERROR("A012012","报告名称格式错误可包含中文、字母、数字、中划线长度不能超过50个字符"),
REPORT_VERSION_PATTERN_ERROR("A012013","报告版本号格式错误可包含中文、字母、数字、中划线点号长度不能超过50个字符"),
FILE_SIZE_ERROR("A012014","文件大小不能超过5MB" );
private String code;
private String message;
ReportResponseEnum(String code, String message) {
this.code = code;
this.message = message;
}
}

View File

@@ -0,0 +1,47 @@
package com.njcn.gather.report.pojo.param;
import com.njcn.web.pojo.param.BaseParam;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.web.multipart.MultipartFile;
/**
* @author caozehui
* @data 2025-03-19
*/
@Data
public class ReportParam {
@ApiModelProperty(value = "报告模板名称", required = true)
private String name;
@ApiModelProperty(value = "版本号", required = true)
private String version;
@ApiModelProperty(value = "描述信息", required = true)
private String description;
@ApiModelProperty(value = "基础模板文件", required = true)
private MultipartFile baseFile;
@ApiModelProperty(value = "检测项模版文件", required = true)
private MultipartFile detailFile;
@Data
@EqualsAndHashCode(callSuper = true)
public static class QueryParam extends BaseParam {
@ApiModelProperty(value = "报告模板名称", required = true)
private String name;
@ApiModelProperty(value = "版本号", required = true)
private String version;
}
@Data
@EqualsAndHashCode(callSuper = true)
public static class UpdateParam extends ReportParam {
@ApiModelProperty(value = "id", required = true)
private String id;
}
}

View File

@@ -0,0 +1,27 @@
package com.njcn.gather.report.pojo.po;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.RequiredArgsConstructor;
/**
* @author caozehui
* @data 2025-03-21
*/
@Data
@AllArgsConstructor
public class CellEntity {
private String cellValue;
private String width;
private int rowSpan;
private int colSpan;
/**
* 字体颜色 格式为rgb 例如FF0000
*/
private String color;
}

View File

@@ -0,0 +1,55 @@
package com.njcn.gather.report.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;
import java.time.LocalDateTime;
/**
* @author makejava
* @date 2025-03-19
*/
@Data
@EqualsAndHashCode(callSuper = true)
@TableName("pq_report")
public class PqReport extends BaseEntity implements Serializable {
private static final long serialVersionUID = 582972970946593407L;
/**
* 报告模板id
*/
private String id;
/**
* 报告模板名称
*/
private String name;
/**
* 版本号
*/
private String version;
/**
* 基础模板文件路径
*/
private String basePath;
/**
* 检测项模版文件路径
*/
private String detailPath;
/**
* 描述信息
*/
private String description;
/**
* 状态0-删除 1-正常
*/
private Integer state;
}

View File

@@ -0,0 +1,68 @@
package com.njcn.gather.report.pojo.vo;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
import lombok.Data;
import java.time.LocalDateTime;
/**
* @author caozehui
* @data 2025-03-19
*/
@Data
public class PqReportVO {
/**
* 报告模板id
*/
private String id;
/**
* 报告模板名称
*/
private String name;
/**
* 版本号
*/
private String version;
/**
* 基础模板文件路径
*/
private FileVO baseFileVO;
/**
* 检测项模版文件路径
*/
private FileVO detailFileVO;
/**
* 描述信息
*/
private String description;
/**
* 创建时间
*/
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@JsonDeserialize(using = LocalDateTimeDeserializer.class)
@JsonSerialize(using = LocalDateTimeSerializer.class)
private LocalDateTime createTime;
/**
* 状态0-删除 1-正常
*/
//private Integer state;
@Data
public static class FileVO{
private String name;
private String url;
}
}

View File

@@ -0,0 +1,69 @@
package com.njcn.gather.report.service;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import com.njcn.gather.report.pojo.DevReportParam;
import com.njcn.gather.report.pojo.param.ReportParam;
import com.njcn.gather.report.pojo.po.PqReport;
import com.njcn.gather.report.pojo.vo.PqReportVO;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;
/**
* @author makejava
* @date 2025-03-19
*/
public interface IPqReportService extends IService<PqReport> {
/**
* 分页查询报告列表
*
* @param queryParam
* @return
*/
Page<PqReportVO> list(ReportParam.QueryParam queryParam);
/**
* 根据id查询报告详情
*
* @param id
* @return
*/
PqReportVO getByReportId(String id);
/**
* 新增报告
*
* @param reportParam
* @return
*/
boolean add(ReportParam reportParam);
/**
* 修改报告
*
* @param reportParam
* @return
*/
boolean update(ReportParam.UpdateParam reportParam);
/**
* 批量删除报告
*
* @param ids
* @return
*/
boolean delete(List<String> ids);
/**
* 查询所有报告名称
*
* @return key为报告idvalue为报告名称
*/
List<String> listAllName();
void generateReport(DevReportParam devReportParam);
void downloadReport(DevReportParam devReportParam, HttpServletResponse response);
}

View File

@@ -1,16 +0,0 @@
package com.njcn.gather.report.service;
import com.njcn.gather.report.pojo.DevReportParam;
import javax.servlet.http.HttpServletResponse;
/**
* @author hongawen
* @version 1.0
* @data 2025/1/9 20:59
*/
public interface IReportService {
void generateReport(DevReportParam devReportParam);
void downloadReport(DevReportParam devReportParam, HttpServletResponse response);
}

View File

@@ -1,557 +0,0 @@
package com.njcn.gather.report.service.impl;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.njcn.common.pojo.enums.common.DataStateEnum;
import com.njcn.common.pojo.exception.BusinessException;
import com.njcn.gather.detection.pojo.vo.DetectionData;
import com.njcn.gather.device.pojo.enums.DevReportStateEnum;
import com.njcn.gather.device.pojo.vo.PqDevVO;
import com.njcn.gather.device.service.IPqDevService;
import com.njcn.gather.plan.pojo.enums.PlanReportStateEnum;
import com.njcn.gather.plan.pojo.po.AdPlan;
import com.njcn.gather.plan.service.IAdPlanService;
import com.njcn.gather.report.pojo.DevReportParam;
import com.njcn.gather.report.service.IReportService;
import com.njcn.gather.report.utils.WordUtil;
import com.njcn.gather.script.pojo.po.PqScriptCheckData;
import com.njcn.gather.script.pojo.po.PqScriptDtls;
import com.njcn.gather.script.service.IPqScriptCheckDataService;
import com.njcn.gather.script.service.IPqScriptDtlsService;
import com.njcn.gather.storage.pojo.param.SingleNonHarmParam;
import com.njcn.gather.storage.pojo.po.AdHarmonicResult;
import com.njcn.gather.storage.pojo.po.AdNonHarmonicResult;
import com.njcn.gather.storage.service.AdHarmonicService;
import com.njcn.gather.storage.service.AdNonHarmonicService;
import com.njcn.gather.system.dictionary.service.IDictDataService;
import com.njcn.gather.type.pojo.po.DevType;
import com.njcn.gather.type.service.IDevTypeService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.ClassPathResource;
import org.springframework.stereotype.Service;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.*;
/**
* @author hongawen
* @version 1.0
* @data 2025/1/9 21:00
*/
@Slf4j
@Service
@RequiredArgsConstructor
public class ReportServiceImpl implements IReportService {
@Value("${report.template:D:\\template\\}")
private String templatePath;
@Value("${report.reportDir:D:\\report}")
private String reportPath;
private final IPqDevService iPqDevService;
private final IDictDataService dictDataService;
private final IAdPlanService adPlanService;
private final IPqScriptDtlsService pqScriptDtlsService;
private final IPqScriptCheckDataService pqScriptCheckDataService;
private final AdNonHarmonicService adNonHarmonicService;
private final AdHarmonicService adHarmonicService;
private final IDevTypeService devTypeService;
@Override
public void generateReport(DevReportParam devReportParam) {
// 读取模板文件
ClassPathResource resource = new ClassPathResource("/model/BaseModel.docx");
try (InputStream inputStream = resource.getInputStream()) {
// 加载Word文档
XWPFDocument baseModelDocument = new XWPFDocument(inputStream);
PqDevVO pqDevVO = iPqDevService.getPqDevById(devReportParam.getDevId());
if (Objects.isNull(pqDevVO)) {
throw new BusinessException("请检查装置是否存在!");
}
// 获取设备型号
DevType devType = devTypeService.getById(pqDevVO.getDevType());
if (Objects.isNull(devType)) {
throw new BusinessException("设备类型丢失,请联系管理员!");
}
// 处理基础模版中的信息
dealBaseModel(baseModelDocument, pqDevVO);
// 处理数据页中的信息
dealDataModel(baseModelDocument, devReportParam, pqDevVO);
// 处理需要输出的目录地址 基础路径+设备类型+装置编号.docx
// 最终文件输出的路径
String dirPath = reportPath.concat(File.separator).concat(devType.getName());
ensureDirectoryExists(dirPath); // 确保目录存在
FileOutputStream out = new FileOutputStream(dirPath.concat(File.separator).concat(pqDevVO.getCreateId()).concat(".docx"));
// 4. 保存新的Word文档
try {
baseModelDocument.write(out);
} catch (IOException e) {
throw new BusinessException("生成报告文件失败");
}
out.close();
System.out.println("报告生成成功!");
// 将改设备的报告生成状态调整为已生成
iPqDevService.updatePqDevReportState(devReportParam.getDevId(), DevReportStateEnum.GENERATED.getValue());
// 判断该计划下是否所有设备报告已生成,如果已生成则将计划的报告状态给为已生成
int count = iPqDevService.countUnReportDev(devReportParam.getPlanId());
LambdaUpdateWrapper<AdPlan> updateWrapper = new LambdaUpdateWrapper<>();
updateWrapper.eq(AdPlan::getId, devReportParam.getPlanId());
if (count == 0) {
updateWrapper.set(AdPlan::getReportState, PlanReportStateEnum.REPORT_STATE_ALL_GENERATED.getValue());
} else {
updateWrapper.set(AdPlan::getReportState, PlanReportStateEnum.REPORT_STATE_PARTIALLY_GENERATED.getValue());
}
adPlanService.update(updateWrapper);
} catch (Exception e) {
log.error("生成报告文件失败", e);
throw new RuntimeException(e);
}
}
@Override
public void downloadReport(DevReportParam devReportParam, HttpServletResponse response) {
PqDevVO pqDevVO = iPqDevService.getPqDevById(devReportParam.getDevId());
if (Objects.isNull(pqDevVO)) {
throw new BusinessException("请检查装置是否存在!");
}
// 获取设备型号
DevType devType = devTypeService.getById(pqDevVO.getDevType());
if (Objects.isNull(devType)) {
throw new BusinessException("设备类型丢失,请联系管理员!");
}
// 找到该文件的路径
String filePath = reportPath.concat(File.separator).concat(devType.getName()).concat(File.separator).concat(pqDevVO.getCreateId()).concat(".docx");
File reportFile = new File(filePath);
if (!reportFile.exists()) {
// 如果文件不存在,则将改设备的报告生成状态调整为未生成
iPqDevService.updatePqDevReportState(devReportParam.getDevId(), 0);
throw new BusinessException("报告文件不存在,请重新生成报告!");
} else {
try (FileInputStream fis = new FileInputStream(reportFile);
OutputStream os = response.getOutputStream()) {
// 设置响应头
response.setContentType("application/vnd.openxmlformats-officedocument.wordprocessingml.document");
String fileName = pqDevVO.getCreateId() + ".docx";
response.setHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\"");
// 将文件内容写入响应输出流
byte[] buffer = new byte[1024];
int bytesRead;
while ((bytesRead = fis.read(buffer)) != -1) {
os.write(buffer, 0, bytesRead);
}
// 刷新输出流
os.flush();
} catch (IOException e) {
e.printStackTrace();
response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
}
}
}
/**
* 处理基础模版中的信息,非数据页报告
*
* @param baseModelDocument 模板文件
*/
private void dealBaseModel(XWPFDocument baseModelDocument, PqDevVO pqDevVO) {
// 首先获取非数据页中需要的信息
Map<String, String> baseModelMap = new HashMap<>(16);
// 获取设备型号
DevType devType = devTypeService.getById(pqDevVO.getDevType());
baseModelMap.put("${devType}", devType.getName());
// 调试人员todo... 待咨询曹泽辉如何获取当前用户信息,目前先写死
baseModelMap.put("${userName}", "管理员");
// 调试日期
if (pqDevVO.getCheckTime() != null) {
baseModelMap.put("${testDate}", DateUtil.format(pqDevVO.getCheckTime(), DatePattern.CHINESE_DATE_PATTERN));
} else {
baseModelMap.put("${testDate}", DateUtil.format(new Date(), DatePattern.CHINESE_DATE_PATTERN));
}
// 装置编码
baseModelMap.put("${CreateId}", pqDevVO.getCreateId());
// 额定电流
baseModelMap.put("${devCurr}", pqDevVO.getDevCurr().toString().concat("A"));
// 额定电压
baseModelMap.put("${devVolt}", pqDevVO.getDevVolt().toString().concat("V"));
// 共有多少通道参与测试
// if (CollectionUtil.isEmpty(pqDevById.getMonitorList())) {
// baseModelMap.put("${count}", "0");
// } else {
// baseModelMap.put("${count}", pqDevById.getMonitorList().size() + "");
// }
baseModelMap.put("${count}", pqDevVO.getDevChns().toString());
// 替换模板中的信息,避免信息丢失,段落和表格均参与替换
WordUtil.replacePlaceholdersInParagraphs(baseModelDocument, baseModelMap);
WordUtil.replacePlaceholdersInTables(baseModelDocument, baseModelMap);
}
/**
* 获取数据页的信息
*
* @param baseModelDocument 非数据页的内容
* @param devReportParam 查询参数
*/
private void dealDataModel(XWPFDocument baseModelDocument, DevReportParam devReportParam, PqDevVO pqDevVO) throws IOException {
AdPlan adPlan = adPlanService.getById(devReportParam.getPlanId());
String scriptId = adPlan.getScriptId();
Integer devChns = pqDevVO.getDevChns();
for (int i = 1; i <= devChns; i++) {
ClassPathResource resource = new ClassPathResource("/model/BaseDataModel.docx");
XWPFDocument dataModelDocumentTemp = new XWPFDocument(resource.getInputStream());
SingleNonHarmParam singleNonHarmParam = new SingleNonHarmParam();
singleNonHarmParam.setPlanCode(adPlan.getCode());
singleNonHarmParam.setDevId(pqDevVO.getId());
singleNonHarmParam.setChannelNo(i);
// 获取数据
Map<String, String> dataModelMap = new HashMap<>(16);
dataModelMap.put("${CreateId}", pqDevVO.getCreateId());
dataModelMap.put("${total}", pqDevVO.getDevChns().toString());
dataModelMap.put("${count}", i + "");
// 区分谐波和非谐波数据
// 谐波类
// 非谐波类
// 57V电压 电压&相角 index 不用计算了固定为1
// Integer testItemIndex = getTestItemIndex(scriptId, "e797c4b940389404e64fb92e4507c5f4", "Base", "VOL", 57);
// 获取输出脚本ID
Integer testItemIndex = 1;
// String pqScriptCheckDataService = getPqScriptCheckDataByScriptId(scriptId,testItemIndex,1,Arrays.asList("A","B","C"));
String pqScriptCheckDataService = "8e221487f242c77f1eff05234580d4c5";
// 获取数据
singleNonHarmParam.setAdType(pqScriptCheckDataService);
singleNonHarmParam.setSort(testItemIndex);
fillMapValue(singleNonHarmParam, dataModelMap, "57Ua", "57Ub", "57Uc");
// 57V相角
testItemIndex = 1;
pqScriptCheckDataService = "e8bbfaad7a3fa343d3c46d345fb45fa3";
// 获取数据
singleNonHarmParam.setAdType(pqScriptCheckDataService);
singleNonHarmParam.setSort(testItemIndex);
fillMapValue(singleNonHarmParam, dataModelMap, "57UaA", "57UbA", "57UcA");
// 10V电压
testItemIndex = 2;
pqScriptCheckDataService = "8e221487f242c77f1eff05234580d4c5";
// 获取数据
singleNonHarmParam.setAdType(pqScriptCheckDataService);
singleNonHarmParam.setSort(testItemIndex);
fillMapValue(singleNonHarmParam, dataModelMap, "10Ua", "10Ub", "10Uc");
// 电压偏差
testItemIndex = 3;
pqScriptCheckDataService = "8e221487f242c77f1eff05234580d4c5";
// 获取数据
singleNonHarmParam.setAdType(pqScriptCheckDataService);
singleNonHarmParam.setSort(testItemIndex);
fillMapValue(singleNonHarmParam, dataModelMap, "DELTA_Ua", "DELTA_Ub", "DELTA_Uc");
// 特殊处理电压偏差
specialDealVoltage(dataModelMap, "${DELTA_Ua}");
specialDealVoltage(dataModelMap, "${DELTA_Ub}");
specialDealVoltage(dataModelMap, "${DELTA_Uc}");
// 5A 电流
testItemIndex = 4;
pqScriptCheckDataService = "7fbadbeb9dd5ccb69d216f4f9ad60b4f";
// 获取数据
singleNonHarmParam.setAdType(pqScriptCheckDataService);
singleNonHarmParam.setSort(testItemIndex);
fillMapValue(singleNonHarmParam, dataModelMap, "5Ia", "5Ib", "5Ic");
// 5A 电流相角
testItemIndex = 4;
pqScriptCheckDataService = "fdffc6b5dfdc8751b9fde9b599b8ea51";
// 获取数据
singleNonHarmParam.setAdType(pqScriptCheckDataService);
singleNonHarmParam.setSort(testItemIndex);
fillMapValue(singleNonHarmParam, dataModelMap, "5IaA", "5IbA", "5IcA");
// 1A 电流
testItemIndex = 5;
pqScriptCheckDataService = "7fbadbeb9dd5ccb69d216f4f9ad60b4f";
// 获取数据
singleNonHarmParam.setAdType(pqScriptCheckDataService);
singleNonHarmParam.setSort(testItemIndex);
fillMapValue(singleNonHarmParam, dataModelMap, "1Ia", "1Ib", "1Ic");
// 三相电压不平衡度
testItemIndex = 6;
pqScriptCheckDataService = "9e9910f3627870c7fcf5846342f29d26";
// 获取数据
singleNonHarmParam.setAdType(pqScriptCheckDataService);
singleNonHarmParam.setSort(testItemIndex);
fillMapValueT(singleNonHarmParam, dataModelMap, "V_UNBAN");
// 频率 45
testItemIndex = 7;
pqScriptCheckDataService = "2da2a32c0cd19fb6368b9f4c249c2b3c";
// 获取数据
singleNonHarmParam.setAdType(pqScriptCheckDataService);
singleNonHarmParam.setSort(testItemIndex);
fillMapValueT(singleNonHarmParam, dataModelMap, "FREQ45");
// 频率 50
testItemIndex = 8;
pqScriptCheckDataService = "2da2a32c0cd19fb6368b9f4c249c2b3c";
// 获取数据
singleNonHarmParam.setAdType(pqScriptCheckDataService);
singleNonHarmParam.setSort(testItemIndex);
fillMapValueT(singleNonHarmParam, dataModelMap, "FREQ50");
// 频率 55
testItemIndex = 9;
pqScriptCheckDataService = "2da2a32c0cd19fb6368b9f4c249c2b3c";
// 获取数据
singleNonHarmParam.setAdType(pqScriptCheckDataService);
singleNonHarmParam.setSort(testItemIndex);
fillMapValueT(singleNonHarmParam, dataModelMap, "FREQ55");
// 谐波电压,少了基波 todo...
testItemIndex = 10;
pqScriptCheckDataService = "cce92410f1902897a61f644d875f2216";
// 获取数据
singleNonHarmParam.setAdType(pqScriptCheckDataService);
singleNonHarmParam.setSort(testItemIndex);
fillMapValueHarm(singleNonHarmParam, dataModelMap, "Uha", "Uhb", "Uhc", 57.74, 100);
// 谐波电电流,少了基波 todo...
testItemIndex = 11;
pqScriptCheckDataService = "3e5e384d38485ca4242152fba336de1d";
// 获取数据
singleNonHarmParam.setAdType(pqScriptCheckDataService);
singleNonHarmParam.setSort(testItemIndex);
fillMapValueHarm(singleNonHarmParam, dataModelMap, "Iha", "Ihb", "Ihc", 1, 1);
// 间谐波电压
testItemIndex = 12;
pqScriptCheckDataService = "d57ea0e085ecf6c4e9f4da09b948befe";
// 获取数据
singleNonHarmParam.setAdType(pqScriptCheckDataService);
singleNonHarmParam.setSort(testItemIndex);
fillMapValueHarm(singleNonHarmParam, dataModelMap, "InUa", "InUb", "InUc", 57.74, 100);
// 间谐波电流
testItemIndex = 13;
pqScriptCheckDataService = "6bc58769dcbb2f83a13ff965a20a3cf3";
// 获取数据
singleNonHarmParam.setAdType(pqScriptCheckDataService);
singleNonHarmParam.setSort(testItemIndex);
fillMapValueHarm(singleNonHarmParam, dataModelMap, "InIa", "InIb", "InIc", 1, 1);
// 替换文档内容
WordUtil.replacePlaceholdersInParagraphs(dataModelDocumentTemp, dataModelMap);
WordUtil.replacePlaceholdersInTables(dataModelDocumentTemp, dataModelMap);
WordUtil.appendDocument(baseModelDocument, dataModelDocumentTemp);
}
}
private void specialDealVoltage(Map<String, String> dataModelMap, String symbol) {
String value = dataModelMap.get(symbol);
if (Objects.nonNull(value) && !value.equals("/")) {
Double valueDouble = Double.valueOf(value);
double result = ((valueDouble - 57.74) / 57.74) * 100;
dataModelMap.put(symbol, doubleRound(4, result));
}
}
/**
* 填充谐波Map数据
*/
private void fillMapValueHarm(SingleNonHarmParam singleNonHarmParam, Map<String, String> dataModelMap, String aSymbol, String bSymbol, String cSymbol, double baseValue, int percent) {
AdHarmonicResult adHarmonicResult = adHarmonicService.getSingleResult(singleNonHarmParam);
if (Objects.nonNull(adHarmonicResult)) {
// 要处理 2 5 7 11 23 35 43 50
dataModelMap.put("${" + aSymbol + "2}", devValue(adHarmonicResult.getAValue2(), baseValue, percent));
dataModelMap.put("${" + bSymbol + "2}", devValue(adHarmonicResult.getBValue2(), baseValue, percent));
dataModelMap.put("${" + cSymbol + "2}", devValue(adHarmonicResult.getCValue2(), baseValue, percent));
dataModelMap.put("${" + aSymbol + "5}", devValue(adHarmonicResult.getAValue5(), baseValue, percent));
dataModelMap.put("${" + bSymbol + "5}", devValue(adHarmonicResult.getBValue5(), baseValue, percent));
dataModelMap.put("${" + cSymbol + "5}", devValue(adHarmonicResult.getCValue5(), baseValue, percent));
dataModelMap.put("${" + aSymbol + "7}", devValue(adHarmonicResult.getAValue7(), baseValue, percent));
dataModelMap.put("${" + bSymbol + "7}", devValue(adHarmonicResult.getBValue7(), baseValue, percent));
dataModelMap.put("${" + cSymbol + "7}", devValue(adHarmonicResult.getCValue7(), baseValue, percent));
dataModelMap.put("${" + aSymbol + "11}", devValue(adHarmonicResult.getAValue11(), baseValue, percent));
dataModelMap.put("${" + bSymbol + "11}", devValue(adHarmonicResult.getBValue11(), baseValue, percent));
dataModelMap.put("${" + cSymbol + "11}", devValue(adHarmonicResult.getCValue11(), baseValue, percent));
dataModelMap.put("${" + aSymbol + "23}", devValue(adHarmonicResult.getAValue23(), baseValue, percent));
dataModelMap.put("${" + bSymbol + "23}", devValue(adHarmonicResult.getBValue23(), baseValue, percent));
dataModelMap.put("${" + cSymbol + "23}", devValue(adHarmonicResult.getCValue23(), baseValue, percent));
dataModelMap.put("${" + aSymbol + "35}", devValue(adHarmonicResult.getAValue35(), baseValue, percent));
dataModelMap.put("${" + bSymbol + "35}", devValue(adHarmonicResult.getBValue35(), baseValue, percent));
dataModelMap.put("${" + cSymbol + "35}", devValue(adHarmonicResult.getCValue35(), baseValue, percent));
dataModelMap.put("${" + aSymbol + "43}", devValue(adHarmonicResult.getAValue43(), baseValue, percent));
dataModelMap.put("${" + bSymbol + "43}", devValue(adHarmonicResult.getBValue43(), baseValue, percent));
dataModelMap.put("${" + cSymbol + "43}", devValue(adHarmonicResult.getCValue43(), baseValue, percent));
dataModelMap.put("${" + aSymbol + "50}", devValue(adHarmonicResult.getAValue50(), baseValue, percent));
dataModelMap.put("${" + bSymbol + "50}", devValue(adHarmonicResult.getBValue50(), baseValue, percent));
dataModelMap.put("${" + cSymbol + "50}", devValue(adHarmonicResult.getCValue50(), baseValue, percent));
}
}
private String devValue(String dataJson, double baseValue, Integer percent) {
DetectionData tempA = JSONUtil.toBean(dataJson, DetectionData.class);
if (Objects.nonNull(tempA) && Objects.nonNull(tempA.getData())) {
return doubleRound(4, (tempA.getData() / percent) * baseValue);
}
return "/";
}
/**
* 填充非谐波Map数据ABC三相
*/
private void fillMapValue(SingleNonHarmParam singleNonHarmParam, Map<String, String> dataModelMap, String aSymbol, String bSymbol, String cSymbol) {
AdNonHarmonicResult adNonHarmonicResult = adNonHarmonicService.getSingleResult(singleNonHarmParam);
if (Objects.nonNull(adNonHarmonicResult)) {
dataModelMap.put("${".concat(aSymbol).concat("}"), devValue(adNonHarmonicResult.getAValue(), 1, 1));
dataModelMap.put("${".concat(bSymbol).concat("}"), devValue(adNonHarmonicResult.getBValue(), 1, 1));
dataModelMap.put("${".concat(cSymbol).concat("}"), devValue(adNonHarmonicResult.getCValue(), 1, 1));
}
}
/**
* 填充非谐波Map数据,T相
*/
private void fillMapValueT(SingleNonHarmParam singleNonHarmParam, Map<String, String> dataModelMap, String tSymbol) {
AdNonHarmonicResult adNonHarmonicResult = adNonHarmonicService.getSingleResult(singleNonHarmParam);
if (Objects.nonNull(adNonHarmonicResult)) {
dataModelMap.put("${".concat(tSymbol).concat("}"), devValue(adNonHarmonicResult.getTValue(), 1, 1));
}
}
private String getPqScriptCheckDataByScriptId(String scriptId, Integer index, Integer errFlag, List<String> phase) {
LambdaQueryWrapper<PqScriptCheckData> queryWrapper = new LambdaQueryWrapper<>();
// todo... 不参与比较的数据没有了
queryWrapper.eq(PqScriptCheckData::getScriptId, scriptId)
.eq(PqScriptCheckData::getEnable, DataStateEnum.ENABLE.getCode())
.in(PqScriptCheckData::getPhase, phase)
.eq(PqScriptCheckData::getIndex, index);
List<PqScriptCheckData> list = pqScriptCheckDataService.list(queryWrapper);
if (CollectionUtil.isNotEmpty(list)) {
return list.get(0).getValueType();
}
return null;
}
public static void main(String[] args) throws IOException {
String path = "F:\\gitea\\fusionForce\\CN_Gather\\entrance\\src\\main\\resources\\model\\BaseDataModel.docx";
FileInputStream dataModelFis = new FileInputStream(new File(path));
XWPFDocument dataModelDocumentTemp = new XWPFDocument(dataModelFis);
Map<String, String> dataModelMap = new HashMap<>(16);
dataModelMap.put("${CreateId}", "123");
dataModelMap.put("${total}", "123");
dataModelMap.put("${count}", "1");
dataModelMap.put("${57Ua}", "123456");
dataModelMap.put("${Uha1}", "123456");
dataModelMap.put("${Uha2}", "123456");
WordUtil.replacePlaceholdersInParagraphs(dataModelDocumentTemp, dataModelMap);
WordUtil.replacePlaceholdersInTables(dataModelDocumentTemp, dataModelMap);
//最终文件输出的路径
FileOutputStream out = new FileOutputStream("C:\\Users\\hongawen\\Desktop\\testModel\\BaseDataModel" + DateUtil.format(new Date(), DatePattern.CHINESE_DATE_TIME_PATTERN) + ".docx");
// 4. 保存新的Word文档
try {
dataModelDocumentTemp.write(out);
} catch (IOException e) {
throw new BusinessException("生成报告文件失败");
}
out.close();
System.out.println("报告生成成功!");
}
/**
* 获取测试小项的index
* 注测试项下发的ABCT的index均是一样的
*/
private Integer getTestItemIndex(String scriptId, String sourceScriptId, String subType, String valueType, Integer value) {
LambdaQueryWrapper<PqScriptDtls> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(PqScriptDtls::getScriptId, scriptId)
.eq(PqScriptDtls::getScriptType, sourceScriptId)
.eq(PqScriptDtls::getScriptSubType, subType)
.eq(PqScriptDtls::getValueType, valueType)
.in(PqScriptDtls::getPhase, Arrays.asList("A", "B", "C"))
.eq(PqScriptDtls::getValue, value);
List<PqScriptDtls> pqScriptDtls = pqScriptDtlsService.list(queryWrapper);
if (CollectionUtil.isNotEmpty(pqScriptDtls)) {
return pqScriptDtls.get(0).getIndex();
}
return null;
}
/**
* 根据参数返回double的四舍五入值
*
* @param i 保留的位数
* @param value double原值
*/
public static String doubleRound(int i, double value) {
BigDecimal bp = new BigDecimal(value);
return String.format("%.4f", bp.setScale(i, RoundingMode.HALF_UP).doubleValue());
}
private void ensureDirectoryExists(String directoryPath) {
File directory = new File(directoryPath);
if (!directory.exists()) {
boolean created = directory.mkdirs();
if (!created) {
throw new BusinessException("目录创建失败: " + directoryPath);
}
} else {
System.out.println("目录已存在: " + directoryPath);
}
}
}

View File

@@ -6,7 +6,6 @@ import com.njcn.common.pojo.enums.common.LogEnum;
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.device.pojo.param.PqDevParam;
import com.njcn.gather.result.pojo.param.ResultParam;
import com.njcn.gather.result.pojo.vo.FormContentVO;
import com.njcn.gather.result.pojo.vo.ResultVO;
@@ -20,10 +19,7 @@ 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.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@@ -86,4 +82,41 @@ public class ResultController extends BaseController {
resultService.exportRawData(queryParam);
}
@OperateInfo(info = LogEnum.BUSINESS_COMMON, operateType = OperateType.UPDATE)
@PostMapping("/reCalculate")
@ApiOperation("重新计算检测结果")
@ApiImplicitParam(name = "queryParam", value = "查询参数", required = true)
public HttpResult<Object> reCalculate(@RequestBody @Validated ResultParam.ChangeErrorSystemParam param) {
String methodDescribe = getMethodDescribe("reCalculate");
LogUtil.njcnDebug(log, "{},查询数据为:{}", methodDescribe, param);
resultService.reCalculate(param);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
}
@OperateInfo(info = LogEnum.BUSINESS_COMMON, operateType = OperateType.UPDATE)
@PostMapping("/changeErrorSystem")
@ApiOperation("更换误差体系")
@ApiImplicitParam(name = "param", value = "修改参数", required = true)
public HttpResult<Object> changeErrorSystem(@RequestBody @Validated ResultParam.ChangeErrorSystemParam param) {
String methodDescribe = getMethodDescribe("changeErrorSystem");
LogUtil.njcnDebug(log, "{},查询数据为:{}", methodDescribe, param);
resultService.changeErrorSystem(param);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
}
@OperateInfo(info = LogEnum.BUSINESS_COMMON, operateType = OperateType.DELETE)
@GetMapping("/deleteTempTable")
@ApiOperation("删除临时表")
@ApiImplicitParam(name = "param", value = "删除参数", required = true)
public HttpResult<Object> deleteTempTable(@RequestParam("code") String code) {
String methodDescribe = getMethodDescribe("deleteTempTable");
LogUtil.njcnDebug(log, "{},查询数据为:{}", methodDescribe, code);
resultService.deleteTempTable(code);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
}
}

View File

@@ -1,21 +0,0 @@
package com.njcn.gather.result.pojo.enums;
import lombok.Getter;
/**
* @author caozehui
* @data 2025-01-16
*/
@Getter
public enum ResultResponseEnum {
RAW_DATA_NOT_EXIST("原始数据不存在!", "A001014");
private final String message;
private final String code;
ResultResponseEnum(String code,String message) {
this.code = code;
this.message = message;
}
}

View File

@@ -1,7 +1,7 @@
package com.njcn.gather.result.pojo.param;
import com.njcn.common.pojo.constant.PatternRegex;
import com.njcn.gather.device.pojo.constant.DevValidMessage;
import com.njcn.gather.pojo.constant.DetectionValidMessage;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@@ -38,7 +38,7 @@ public class ResultParam {
/**
* 自动生成,用于生成数据表后缀
*/
private Integer code;
private String code;
/**
* 检测脚本序号
@@ -49,19 +49,43 @@ public class ResultParam {
public static class QueryParam {
@ApiModelProperty(value = "检测计划Id", required = true)
@NotBlank(message = DevValidMessage.PLAN_ID_NOT_NULL)
@Pattern(regexp = PatternRegex.SYSTEM_ID, message = DevValidMessage.PLAN_ID_FORMAT_ERROR)
@NotBlank(message = DetectionValidMessage.PLAN_ID_NOT_NULL)
@Pattern(regexp = PatternRegex.SYSTEM_ID, message = DetectionValidMessage.PLAN_ID_FORMAT_ERROR)
private String planId;
// 脚本类型当为null时表示查询所有脚本类型否则只查询指定脚本类型
private String scriptType;
@ApiModelProperty(value = "设备Id", required = true)
@NotBlank(message = DevValidMessage.DEV_ID_NOT_BLANK)
@Pattern(regexp = PatternRegex.SYSTEM_ID, message = DevValidMessage.DEV_ID_FORMAT_ERROR)
@NotBlank(message = DetectionValidMessage.DEV_ID_NOT_BLANK)
@Pattern(regexp = PatternRegex.SYSTEM_ID, message = DetectionValidMessage.DEV_ID_FORMAT_ERROR)
private String deviceId;
// 通道号,当为-1时表示查询所有通道号否则只查询指定通道号
private String chnNum;
}
@Data
public static class ChangeErrorSystemParam {
@ApiModelProperty(value = "检测计划Id", required = true)
@NotBlank(message = DetectionValidMessage.PLAN_ID_NOT_NULL)
@Pattern(regexp = PatternRegex.SYSTEM_ID, message = DetectionValidMessage.PLAN_ID_FORMAT_ERROR)
private String planId;
@ApiModelProperty(value = "脚本Id", required = true)
@NotBlank(message = DetectionValidMessage.SCRIPT_ID_NOT_BLANK)
@Pattern(regexp = PatternRegex.SYSTEM_ID, message = DetectionValidMessage.SCRIPT_ID_FORMAT_ERROR)
private String scriptId;
@ApiModelProperty(value = "误差体系Id", required = true)
@NotBlank(message = DetectionValidMessage.ERROR_SYS_ID_NOT_BLANK)
private String errorSysId;
@ApiModelProperty(value = "设备Id", required = true)
@NotBlank(message = DetectionValidMessage.DEV_ID_NOT_BLANK)
@Pattern(regexp = PatternRegex.SYSTEM_ID, message = DetectionValidMessage.DEV_ID_FORMAT_ERROR)
private String deviceId;
private String code;
}
}

View File

@@ -14,7 +14,7 @@ public class FormContentVO {
private String scriptName;
private String errorSysName;
private String errorSysId;
private String dataRule;

View File

@@ -1,7 +1,6 @@
package com.njcn.gather.result.pojo.vo;
import cn.afterturn.easypoi.excel.annotation.Excel;
import com.njcn.gather.device.pojo.vo.PqDevExcel;
import lombok.Data;
import lombok.EqualsAndHashCode;

View File

@@ -17,6 +17,11 @@ public class TreeDataVO {
*/
private String scriptTypeName;
/**
* code
*/
private String scriptTypeCode;
/**
* 源下发的描述
*/

View File

@@ -39,10 +39,40 @@ public interface IResultService {
*/
ResultVO resultData(ResultParam param);
/**
* 展示结果数据(用于生成报告)
*
* @param param
* @return
*/
ResultVO resultDataForReport(ResultParam param);
/**
* 导出原始数据
*
* @param param
*/
void exportRawData(ResultParam param);
/**
* 更换误差体系
*
* @param param
*/
void changeErrorSystem(ResultParam.ChangeErrorSystemParam param);
/**
* 删除(更换误差体系时产生的)临时表
*
* @param code
*/
void deleteTempTable(String code);
/**
* 重新计算
*
* @param param
*/
void reCalculate(ResultParam.ChangeErrorSystemParam param);
}

View File

@@ -3,15 +3,21 @@ package com.njcn.gather.result.service.impl;
import cn.afterturn.easypoi.excel.entity.ExportParams;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DatePattern;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
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.detection.pojo.enums.SourceOperateCodeEnum;
import com.njcn.gather.detection.pojo.param.PreDetectionParam;
import com.njcn.gather.detection.pojo.po.DevData;
import com.njcn.gather.detection.service.impl.DetectionServiceImpl;
import com.njcn.gather.device.service.IPqDevService;
import com.njcn.gather.plan.pojo.po.AdPlan;
import com.njcn.gather.plan.service.IAdPlanService;
import com.njcn.gather.result.pojo.enums.ResultResponseEnum;
import com.njcn.gather.pojo.enums.DetectionResponseEnum;
import com.njcn.gather.result.pojo.enums.ResultUnitEnum;
import com.njcn.gather.result.pojo.param.ResultParam;
import com.njcn.gather.result.pojo.vo.FormContentVO;
@@ -20,24 +26,34 @@ import com.njcn.gather.result.pojo.vo.ResultVO;
import com.njcn.gather.result.pojo.vo.TreeDataVO;
import com.njcn.gather.result.service.IResultService;
import com.njcn.gather.script.mapper.PqScriptMapper;
import com.njcn.gather.script.pojo.param.PqScriptIssueParam;
import com.njcn.gather.script.pojo.po.PqScriptCheckData;
import com.njcn.gather.script.pojo.po.PqScriptDtls;
import com.njcn.gather.script.pojo.po.SourceIssue;
import com.njcn.gather.script.service.IPqScriptCheckDataService;
import com.njcn.gather.script.service.IPqScriptDtlsService;
import com.njcn.gather.script.util.ScriptDtlsDesc;
import com.njcn.gather.storage.mapper.TableGenMapper;
import com.njcn.gather.storage.pojo.param.StorageParam;
import com.njcn.gather.storage.pojo.po.AdBaseResult;
import com.njcn.gather.storage.pojo.po.AdHarmonicResult;
import com.njcn.gather.storage.pojo.po.AdNonHarmonicResult;
import com.njcn.gather.storage.pojo.vo.RawDataVO;
import com.njcn.gather.storage.service.AdHarmonicService;
import com.njcn.gather.storage.service.AdNonHarmonicService;
import com.njcn.gather.system.config.service.ISysTestConfigService;
import com.njcn.gather.system.cfg.pojo.po.SysTestConfig;
import com.njcn.gather.system.cfg.service.ISysTestConfigService;
import com.njcn.gather.system.dictionary.pojo.enums.DictDataEnum;
import com.njcn.gather.system.dictionary.pojo.po.DictTree;
import com.njcn.gather.system.dictionary.service.IDictTreeService;
import com.njcn.web.utils.ExcelUtil;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.lang.reflect.Field;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
@@ -60,6 +76,8 @@ public class ResultServiceImpl implements IResultService {
private final PqScriptMapper scriptMapper;
private final IDictTreeService dictTreeService;
private final IPqScriptCheckDataService pqScriptCheckDataService;
private final TableGenMapper tableGenMapper;
private final DetectionServiceImpl detectionServiceImpl;
/**
* 谐波类code取树形字典表中的code
@@ -71,13 +89,13 @@ public class ResultServiceImpl implements IResultService {
public FormContentVO getFormContent(ResultParam.QueryParam queryParam) {
FormContentVO formContentVO = new FormContentVO();
AdPlan plan = adPlanService.getById(queryParam.getPlanId());
formContentVO.setErrorSysId(plan.getErrorSysId());
String scriptId = null;
if (ObjectUtil.isNotNull(plan)) {
scriptId = plan.getScriptId();
adPlanService.visualize(Collections.singletonList(plan));
}
formContentVO.setScriptName(plan.getScriptId());
formContentVO.setErrorSysName(plan.getErrorSysId());
formContentVO.setDataRule(sysTestConfigService.getConfig().getDataRule());
formContentVO.setDeviceName(pqDevService.getById(queryParam.getDeviceId()).getName());
@@ -90,13 +108,13 @@ public class ResultServiceImpl implements IResultService {
DictTree dictTree = dictTreeService.getById(queryParam.getScriptType());
if (HARMONIC_TYPE_CODE.contains(dictTree.getCode())) {
allResultList.addAll(adHarmonicService.get(scriptId, indexList, queryParam.getDeviceId(), queryParam.getChnNum(), plan.getCode()));
allResultList.addAll(adHarmonicService.get(scriptId, indexList, queryParam.getDeviceId(), queryParam.getChnNum(), plan.getCode() + ""));
} else {
allResultList.addAll(adNonHarmonicService.get(scriptId, indexList, queryParam.getDeviceId(), queryParam.getChnNum(), plan.getCode()));
allResultList.addAll(adNonHarmonicService.get(scriptId, indexList, queryParam.getDeviceId(), queryParam.getChnNum(), plan.getCode() + ""));
}
} else { //查询所有的脚本类型
allResultList.addAll(adHarmonicService.get(scriptId, null, queryParam.getDeviceId(), queryParam.getChnNum(), plan.getCode()));
allResultList.addAll(adNonHarmonicService.get(scriptId, null, queryParam.getDeviceId(), queryParam.getChnNum(), plan.getCode()));
allResultList.addAll(adHarmonicService.get(scriptId, null, queryParam.getDeviceId(), queryParam.getChnNum(), plan.getCode() + ""));
allResultList.addAll(adNonHarmonicService.get(scriptId, null, queryParam.getDeviceId(), queryParam.getChnNum(), plan.getCode() + ""));
}
@@ -126,23 +144,25 @@ public class ResultServiceImpl implements IResultService {
.selectAll(PqScriptDtls.class)
.eq(StrUtil.isNotBlank(param.getScriptId()), PqScriptDtls::getScriptId, param.getScriptId())
.eq(StrUtil.isNotBlank(param.getScriptType()), PqScriptDtls::getScriptType, param.getScriptType())
.ne(PqScriptDtls::getIndex, -1)
.eq(PqScriptDtls::getEnable, DataStateEnum.ENABLE.getCode())
.ne(PqScriptDtls::getScriptIndex, -1)
.eq(StrUtil.isNotBlank(param.getDevId()), PqScriptDtls::getEnable, DataStateEnum.ENABLE.getCode())
);
List<AdBaseResult> allResultList = new ArrayList<>();
List<Integer> indexList = new ArrayList<>();
if (StrUtil.isNotBlank(param.getScriptType())) {
indexList = pqScriptDtlsService.getIndexList(param.getScriptType(), param.getScriptId());
}
allResultList.addAll(adNonHarmonicService.get(param.getScriptId(), indexList, param.getDevId(), param.getDevNum(), param.getCode()));
allResultList.addAll(adHarmonicService.get(param.getScriptId(), indexList, param.getDevId(), param.getDevNum(), param.getCode()));
Map<Integer, Set<Integer>> resultMap = new HashMap<>(5);
if (CollUtil.isNotEmpty(allResultList)) {
resultMap = allResultList.stream().collect(Collectors.groupingBy(AdBaseResult::getSort, Collectors.mapping(AdBaseResult::getResultFlag, Collectors.toSet())));
if (StrUtil.isNotBlank(param.getDevId())) {
List<AdBaseResult> allResultList = new ArrayList<>();
List<Integer> indexList = new ArrayList<>();
if (StrUtil.isNotBlank(param.getScriptType())) {
indexList = pqScriptDtlsService.getIndexList(param.getScriptType(), param.getScriptId());
}
allResultList.addAll(adNonHarmonicService.get(param.getScriptId(), indexList, param.getDevId(), param.getDevNum(), param.getCode()));
allResultList.addAll(adHarmonicService.get(param.getScriptId(), indexList, param.getDevId(), param.getDevNum(), param.getCode()));
if (CollUtil.isNotEmpty(allResultList)) {
resultMap = allResultList.stream().collect(Collectors.groupingBy(AdBaseResult::getSort, Collectors.mapping(AdBaseResult::getResultFlag, Collectors.toSet())));
}
}
Map<String, List<PqScriptDtls>> dtlsSortMap = dtlsList.stream()
.sorted(Comparator.comparing(PqScriptDtls::getIndex))
.sorted(Comparator.comparing(PqScriptDtls::getScriptIndex))
.collect(Collectors.groupingBy(PqScriptDtls::getScriptType, LinkedHashMap::new, Collectors.toList()));
List<DictTree> dictTreeById = dictTreeService.getDictTreeById(new ArrayList<>(dtlsSortMap.keySet()));
@@ -165,29 +185,32 @@ public class ResultServiceImpl implements IResultService {
//大相检测信息
TreeDataVO infoVO = new TreeDataVO();
infoVO.setScriptTypeName(dictTree.getName());
infoVO.setScriptTypeCode(dictTree.getId());
//额定条件下频率准确度测试
LinkedHashMap<String, List<PqScriptDtls>> subTypeMap = value.stream()
.sorted(Comparator.comparing(PqScriptDtls::getIndex))
.sorted(Comparator.comparing(PqScriptDtls::getScriptIndex))
.filter(x -> "Base".equals(x.getScriptSubType()))
.collect(Collectors.groupingBy(PqScriptDtls::getScriptSubType, LinkedHashMap::new, Collectors.toList()));
subTypeMap.forEach((subKey, subValue) -> {
if (!"VOLTAGE".equals(dictTree.getCode())) {
TreeDataVO subType = new TreeDataVO();
subType.setScriptTypeName(subName.get(subKey).replace("XX", dictTree.getName()));
subType.setScriptTypeName(!subName.containsKey(subKey) ? "" : subName.get(subKey).replace("XX", dictTree.getName()));
subType.setScriptTypeCode(subKey);
LinkedHashMap<Integer, List<PqScriptDtls>> indexMap = subValue.stream()
.sorted(Comparator.comparing(PqScriptDtls::getIndex))
.collect(Collectors.groupingBy(PqScriptDtls::getIndex, LinkedHashMap::new, Collectors.toList()));
.sorted(Comparator.comparing(PqScriptDtls::getScriptIndex))
.collect(Collectors.groupingBy(PqScriptDtls::getScriptIndex, LinkedHashMap::new, Collectors.toList()));
List<TreeDataVO> subTypeList = new ArrayList<>();
indexMap.forEach((index, scriptDtlIndexList) -> {
TreeDataVO dtlType = new TreeDataVO();
dtlType.setIndex(index);
dtlType.setScriptType(scriptDtlIndexList.get(0).getScriptType());
dtlType.setScriptTypeCode(subKey);
ratedScriptTypeName(scriptDtlIndexList, isValueType, dtlType, dictTree);
dtlType.setSourceDesc(ScriptDtlsDesc.getStringBuffer(scriptDtlIndexList, false, isValueType).toString());
if (finalResultMap.containsKey(index)) {
TreeDataVO dtlType = new TreeDataVO();
dtlType.setIndex(index);
dtlType.setScriptType(scriptDtlIndexList.get(0).getScriptType());
ratedScriptTypeName(scriptDtlIndexList, isValueType, dtlType, dictTree);
dtlType.setSourceDesc(ScriptDtlsDesc.getStringBuffer(scriptDtlIndexList, isValueType).toString());
dtlType.setFly(conform(finalResultMap.get(index)));
subTypeList.add(dtlType);
}
subTypeList.add(dtlType);
});
if (CollUtil.isNotEmpty(subTypeList)) {
subType.setChildren(subTypeList);
@@ -195,7 +218,7 @@ public class ResultServiceImpl implements IResultService {
}
} else {
dipScriptTypeName(subValue, scriptSubList, finalResultMap, isValueType, "电压暂降测量准确度测试", 20, 85);
dipScriptTypeName(subValue, scriptSubList, finalResultMap, isValueType, "电压暂升测量准确度测试", 110, 180);
dipScriptTypeName(subValue, scriptSubList, finalResultMap, isValueType, "电压暂升测量准确度测试", 110, 200);
dipScriptTypeName(subValue, scriptSubList, finalResultMap, isValueType, "电压中断测量准确度测试", 0, 10);
}
@@ -204,40 +227,43 @@ public class ResultServiceImpl implements IResultService {
//单影响量下频率准确度测试
LinkedHashMap<String, List<PqScriptDtls>> subSingleTypeMap = value.stream()
.sorted(Comparator.comparing(PqScriptDtls::getIndex))
.sorted(Comparator.comparing(PqScriptDtls::getScriptIndex))
.filter(x -> !"Base".equals(x.getScriptSubType()))
.collect(Collectors.groupingBy(PqScriptDtls::getScriptSubType, LinkedHashMap::new, Collectors.toList()));
if (CollUtil.isNotEmpty(subSingleTypeMap)) {
TreeDataVO subType = new TreeDataVO();
subType.setScriptTypeName(subName.get("Single").replace("XX", dictTree.getName()));
subType.setScriptTypeName(!subName.containsKey("Single") ? "" : subName.get("Single").replace("XX", dictTree.getName()));
subType.setScriptTypeCode(dictTree.getCode());
//单影响量下频率准测量集合
List<TreeDataVO> subSingleList = new ArrayList<>();
subSingleTypeMap.forEach((subKey, subValue) -> {
TreeDataVO treeDataVO = new TreeDataVO();
treeDataVO.setScriptTypeName(subName.get(subKey).replace("XX", dictTree.getName()));
treeDataVO.setScriptTypeName(!subName.containsKey(subKey) ? "" : subName.get(subKey).replace("XX", dictTree.getName()));
treeDataVO.setScriptTypeCode(subKey);
List<TreeDataVO> subTypeList = new ArrayList<>();
LinkedHashMap<Integer, List<PqScriptDtls>> indexMap = subValue.stream()
.sorted(Comparator.comparing(PqScriptDtls::getIndex))
.collect(Collectors.groupingBy(PqScriptDtls::getIndex, LinkedHashMap::new, Collectors.toList()));
.sorted(Comparator.comparing(PqScriptDtls::getScriptIndex))
.collect(Collectors.groupingBy(PqScriptDtls::getScriptIndex, LinkedHashMap::new, Collectors.toList()));
indexMap.forEach((index, scriptDtlIndexList) -> {
if (finalResultMap.containsKey(index)) {
TreeDataVO dtlType = new TreeDataVO();
dtlType.setIndex(index);
if ("Harm".equals(subKey)) {
harmScriptTypeName(scriptDtlIndexList, dictTree, isValueType, dtlType);
}
if ("VOL".equals(subKey)) {
volScriptTypeName(scriptDtlIndexList, dictTree, isValueType, dtlType);
}
if ("Freq".equals(subKey)) {
freqScriptTypeName(scriptDtlIndexList, dictTree, isValueType, dtlType);
}
dtlType.setSourceDesc(ScriptDtlsDesc.getStringBuffer(scriptDtlIndexList, isValueType).toString());
dtlType.setFly(conform(finalResultMap.get(index)));
subTypeList.add(dtlType);
TreeDataVO dtlType = new TreeDataVO();
dtlType.setIndex(index);
dtlType.setScriptType(scriptDtlIndexList.get(0).getScriptType());
dtlType.setScriptTypeCode(subKey);
if ("Harm".equals(subKey)) {
harmScriptTypeName(scriptDtlIndexList, dictTree, isValueType, dtlType);
}
if ("VOL".equals(subKey)) {
volScriptTypeName(scriptDtlIndexList, dictTree, isValueType, dtlType);
}
if ("Freq".equals(subKey)) {
freqScriptTypeName(scriptDtlIndexList, dictTree, isValueType, dtlType);
}
dtlType.setSourceDesc(ScriptDtlsDesc.getStringBuffer(scriptDtlIndexList, false, isValueType).toString());
if (finalResultMap.containsKey(index)) {
dtlType.setFly(conform(finalResultMap.get(index)));
}
subTypeList.add(dtlType);
});
if (CollUtil.isNotEmpty(subTypeList)) {
treeDataVO.setChildren(subTypeList);
@@ -263,23 +289,25 @@ public class ResultServiceImpl implements IResultService {
List<PqScriptDtls> dip = subValue.stream()
.filter(x -> "Dip".equals(x.getValueType()) && "A".equals(x.getPhase()))
.filter(x -> x.getTransValue() >= start && x.getTransValue() <= end)
.sorted(Comparator.comparing(PqScriptDtls::getIndex))
.sorted(Comparator.comparing(PqScriptDtls::getScriptIndex))
.collect(Collectors.toList());
TreeDataVO vo = new TreeDataVO();
vo.setScriptTypeName(name);
vo.setScriptTypeCode("Base_" + start + "_" + end);
TreeDataVO dlt;
for (PqScriptDtls dtls : dip) {
if (finalResultMap.containsKey(dtls.getIndex())) {
dlt = new TreeDataVO();
List<PqScriptDtls> scriptDtlIndexList = subValue.stream().filter(x -> dtls.getIndex().equals(x.getIndex())).collect(Collectors.toList());
//特征幅值=20%Un持续时间=1周波
dlt.setScriptTypeName("特征幅值=" + dtls.getTransValue() + "%Un持续时间=" + dtls.getRetainTime().intValue() + "周波");
dlt.setIndex(dtls.getIndex());
dlt.setScriptType(scriptDtlIndexList.get(0).getScriptType());
dlt.setSourceDesc(ScriptDtlsDesc.getStringBuffer(scriptDtlIndexList, isValueType).toString());
dlt.setFly(conform(finalResultMap.get(dtls.getIndex())));
info.add(dlt);
dlt = new TreeDataVO();
List<PqScriptDtls> scriptDtlIndexList = subValue.stream().filter(x -> dtls.getScriptIndex().equals(x.getScriptIndex())).collect(Collectors.toList());
//特征幅值=20%Un持续时间=1周波
dlt.setScriptTypeName("特征幅值=" + dtls.getTransValue() + "%Un持续时间=" + dtls.getRetainTime().intValue() + "周波");
dlt.setIndex(dtls.getScriptIndex());
dlt.setScriptType(scriptDtlIndexList.get(0).getScriptType());
dlt.setScriptTypeCode("Base_" + start + "_" + end);
dlt.setSourceDesc(ScriptDtlsDesc.getStringBuffer(scriptDtlIndexList, false, isValueType).toString());
if (finalResultMap.containsKey(dtls.getScriptIndex())) {
dlt.setFly(conform(finalResultMap.get(dtls.getScriptIndex())));
}
info.add(dlt);
}
if (CollUtil.isNotEmpty(info)) {
@@ -393,7 +421,7 @@ public class ResultServiceImpl implements IResultService {
case IMBV:
List<PqScriptCheckData> list = pqScriptCheckDataService.list(new MPJLambdaWrapper<PqScriptCheckData>()
.eq(PqScriptCheckData::getScriptId, scriptDtlIndexList.get(0).getScriptId())
.eq(PqScriptCheckData::getIndex, scriptDtlIndexList.get(0).getIndex())
.eq(PqScriptCheckData::getScriptIndex, scriptDtlIndexList.get(0).getScriptIndex())
);
//三相负序电压不平衡度=0%
dtlType.setScriptTypeName(dictTree.getName() + "=" + list.get(0).getValue() + ResultUnitEnum.IMBV.getUnit());
@@ -404,7 +432,7 @@ public class ResultServiceImpl implements IResultService {
case IMBA:
List<PqScriptCheckData> imba = pqScriptCheckDataService.list(new MPJLambdaWrapper<PqScriptCheckData>()
.eq(PqScriptCheckData::getScriptId, scriptDtlIndexList.get(0).getScriptId())
.eq(PqScriptCheckData::getIndex, scriptDtlIndexList.get(0).getIndex())
.eq(PqScriptCheckData::getScriptIndex, scriptDtlIndexList.get(0).getScriptIndex())
);
//三相负序电流不平衡度=0%
dtlType.setScriptTypeName(dictTree.getName() + "=" + imba.get(0).getValue() + ResultUnitEnum.IMBV.getUnit());
@@ -762,7 +790,7 @@ public class ResultServiceImpl implements IResultService {
.select(PqScriptCheckData::getHarmNum)
.eq(PqScriptCheckData::getScriptId, param.getScriptId())
.isNotNull(PqScriptCheckData::getHarmNum)
.eq(PqScriptCheckData::getIndex, param.getIndex())
.eq(PqScriptCheckData::getScriptIndex, param.getIndex())
);
harmNum = list.stream().sorted(Comparator.comparing(PqScriptCheckData::getHarmNum))
.map(PqScriptCheckData::getHarmNum).distinct().collect(Collectors.toList());
@@ -779,6 +807,37 @@ public class ResultServiceImpl implements IResultService {
return resultVO;
}
@Override
public ResultVO resultDataForReport(ResultParam param) {
StorageParam storage = new StorageParam();
storage.setIndex(param.getIndex());
storage.setScriptId(param.getScriptId());
storage.setDevId(param.getDevId());
storage.setDevNum(param.getDevNum());
storage.setCode(param.getCode());
DictTree dictTree = dictTreeService.getById(param.getScriptType());
List<Double> harmNum = new ArrayList<>();
if (HARMONIC_TYPE_CODE.contains(dictTree.getCode())) {
List<PqScriptCheckData> list = pqScriptCheckDataService.list(new MPJLambdaWrapper<PqScriptCheckData>()
.distinct()
.select(PqScriptCheckData::getHarmNum)
.eq(PqScriptCheckData::getScriptId, param.getScriptId())
.isNotNull(PqScriptCheckData::getHarmNum)
.eq(PqScriptCheckData::getScriptIndex, param.getIndex())
);
harmNum = list.stream().sorted(Comparator.comparing(PqScriptCheckData::getHarmNum))
.map(PqScriptCheckData::getHarmNum).distinct().collect(Collectors.toList());
}
ResultVO resultVO = new ResultVO();
if (CollUtil.isEmpty(harmNum)) {
resultVO.setResultData(adNonHarmonicService.listNonHarmResultData(storage));
} else {
storage.setHarmNum(harmNum);
resultVO.setResultData(adHarmonicService.listHarmResultData(storage));
}
return resultVO;
}
@Override
public void exportRawData(ResultParam param) {
StorageParam storage = new StorageParam();
@@ -795,7 +854,7 @@ public class ResultServiceImpl implements IResultService {
.select(PqScriptCheckData::getHarmNum)
.eq(PqScriptCheckData::getScriptId, param.getScriptId())
.isNotNull(PqScriptCheckData::getHarmNum)
.eq(PqScriptCheckData::getIndex, param.getIndex())
.eq(PqScriptCheckData::getScriptIndex, param.getIndex())
);
harmNum = list.stream().sorted(Comparator.comparing(PqScriptCheckData::getHarmNum))
.map(PqScriptCheckData::getHarmNum).distinct().collect(Collectors.toList());
@@ -829,10 +888,28 @@ public class ResultServiceImpl implements IResultService {
});
ExcelUtil.exportExcel("原始数据.xlsx", sheetsList);
} else {
throw new BusinessException(ResultResponseEnum.RAW_DATA_NOT_EXIST);
throw new BusinessException(DetectionResponseEnum.RAW_DATA_NOT_EXIST);
}
}
@Override
@Transactional
public void changeErrorSystem(ResultParam.ChangeErrorSystemParam param) {
this.createTempResultTable(param.getCode() + "_temp");
this.calculateResult(param.getPlanId(), param.getScriptId(), param.getCode() + "_temp", param.getErrorSysId(), param.getDeviceId());
}
@Override
public void deleteTempTable(String code) {
code = code + "_temp";
this.dropTempResultTable(code);
}
@Override
public void reCalculate(ResultParam.ChangeErrorSystemParam param) {
this.calculateResult(param.getPlanId(), param.getScriptId(), param.getCode(), param.getErrorSysId(), param.getDeviceId());
}
private Integer conform(Set<Integer> numbers) {
if (CollUtil.isNotEmpty(numbers)) {
if (numbers.size() > 1) {
@@ -853,4 +930,226 @@ public class ResultServiceImpl implements IResultService {
}
return false;
}
/**
* 拷贝结果表
*
* @param code
*/
private void createTempResultTable(String code) {
this.dropTempResultTable(code);
String oldCode = code.replace("_temp", "");
tableGenMapper.genAdNonHarmonicResultTable(code);
StringBuilder A = new StringBuilder();
StringBuilder B = new StringBuilder();
StringBuilder C = new StringBuilder();
for (int i = 1; i <= 50; i++) {
if (i == 1) {
A.append("A_Value_").append(i).append(" json NULL COMMENT 'A相基波',");
B.append("B_Value_").append(i).append(" json NULL COMMENT 'B相基波',");
C.append("C_Value_").append(i).append(" json NULL COMMENT 'C相基波',");
} else {
A.append("A_Value_").append(i).append(" json NULL COMMENT '").append(i).append("次A相谐波',");
B.append("B_Value_").append(i).append(" json NULL COMMENT '").append(i).append("次B相谐波',");
C.append("C_Value_").append(i).append(" json NULL COMMENT '").append(i).append("次C相谐波',");
}
}
String sql1 = "CREATE TABLE if not exists AD_Harmonic_Result_" + code + "(\n" +
" Monitor_Id CHAR(60) NOT NULL COMMENT '监测点Id',\n" +
" Time_Id DATETIME NULL COMMENT '时间',\n" +
" Script_Id CHAR(32) NOT NULL COMMENT '检测脚本子表Id字典表',\n" +
" Sort int(5) NOT NULL COMMENT '总检测脚本中的测试项序号',\n" +
" AD_Type CHAR(32) NOT NULL COMMENT '检测指标,字典表',\n" +
" Data_Type CHAR(32) NOT NULL COMMENT '数据指标只有数据源为分钟统计时候才会使用最大、最小、平均、CP95默认平均值字典表',\n" +
" Result_Flag int(1) NOT NULL COMMENT '1合格 2不合格 4无法处理',\n" +
A + B + C +
" PRIMARY KEY (Monitor_Id, Script_Id, Sort, AD_Type)\n" +
") COMMENT='监测数据表';";
tableGenMapper.genAdHarmonicTable(sql1);
sql1 = "CREATE TABLE ad_non_harmonic_" + code + " LIKE ad_non_harmonic_" + oldCode;
tableGenMapper.genAdHarmonicTable(sql1);
sql1 = "INSERT INTO ad_non_harmonic_" + code + " SELECT * FROM ad_non_harmonic_" + oldCode;
tableGenMapper.genAdHarmonicTable(sql1);
sql1 = "CREATE TABLE ad_harmonic_" + code + " LIKE ad_harmonic_" + oldCode;
tableGenMapper.genAdHarmonicTable(sql1);
sql1 = "INSERT INTO ad_harmonic_" + code + " SELECT * FROM ad_harmonic_" + oldCode;
tableGenMapper.genAdHarmonicTable(sql1);
}
private void dropTempResultTable(String code) {
tableGenMapper.genAdHarmonicTable("drop table if exists AD_Non_Harmonic_Result_" + code + ",AD_Harmonic_Result_" + code + "," + "ad_non_harmonic_" + code + "," + "ad_harmonic_" + code);
}
/**
* 根据原始数据、误差体系id、计算检测结果
*
* @param planId
* @param code
* @param errorSysId
* @param devId
*/
private void calculateResult(String planId, String scriptId, String code, String errorSysId, String devId) {
String oldCode = code.replace("_temp", "");
PreDetectionParam param = new PreDetectionParam();
param.setCode(code);
param.setErrorSysId(errorSysId);
param.setDevIds(Arrays.asList(devId));
Map<String, String> devIdMapComm = new HashMap<>();
// PqDev dev = pqDevService.getById(devId);
devIdMapComm.put(devId, devId);
SysTestConfig oneConfig = sysTestConfigService.getOneConfig();
DictDataEnum dataRule;
if (ObjectUtil.isNotNull(oneConfig)) {
dataRule = DictDataEnum.getDictDataEnumByCode(oneConfig.getDataRule());
} else {
dataRule = DictDataEnum.AT_WILL_VALUE;
}
List<AdNonHarmonicResult> allNonHarmonicRawData = adNonHarmonicService.listAll(scriptId, oldCode, devId);
LinkedHashMap<Integer, List<AdNonHarmonicResult>> nonHarmonicMap = allNonHarmonicRawData.stream().sorted(Comparator.comparing(AdNonHarmonicResult::getSort))
.collect(Collectors.groupingBy(AdNonHarmonicResult::getSort, LinkedHashMap::new, Collectors.toList()));
List<AdHarmonicResult> allHarmonicRawData = adHarmonicService.listAll(scriptId, oldCode, devId);
LinkedHashMap<Integer, List<AdHarmonicResult>> harmonicMap = allHarmonicRawData.stream().sorted(Comparator.comparing(AdHarmonicResult::getSort))
.collect(Collectors.groupingBy(AdHarmonicResult::getSort, LinkedHashMap::new, Collectors.toList()));
PqScriptIssueParam issueParam = new PqScriptIssueParam();
issueParam.setPlanId(planId);
// issueParam.setSourceId();
// issueParam.setScriptType();
// issueParam.setScriptSubType();
issueParam.setDevIds(Arrays.asList(devId));
issueParam.setScriptId(scriptId);
issueParam.setIsPhaseSequence(SourceOperateCodeEnum.FORMAL_TEST.getValue());
List<SourceIssue> sourceIssues = pqScriptDtlsService.listSourceIssue(issueParam);
sourceIssues.forEach(sourceIssue -> {
List<AdNonHarmonicResult> nonHarmonicResults = nonHarmonicMap.get(sourceIssue.getIndex());
List<AdHarmonicResult> harmonicResults = harmonicMap.get(sourceIssue.getIndex());
List<DevData> realDataXiList = new ArrayList<>();
if (CollUtil.isNotEmpty(nonHarmonicResults)) {
realDataXiList.addAll(this.toList(nonHarmonicResults, null, true));
}
if (CollUtil.isNotEmpty(harmonicResults)) {
DictTree dictTree = dictTreeService.getById(harmonicResults.get(0).getAdType());
if (ObjectUtil.isNotNull(dictTree)) {
if (DetectionCodeEnum.V2_50.getCode().equals(dictTree.getCode()) || DetectionCodeEnum.I2_50.getCode().equals(dictTree.getCode()) || DetectionCodeEnum.P2_50.getCode().equals(dictTree.getCode())) {
realDataXiList.addAll(this.toList(null, harmonicResults, true));
} else {
realDataXiList.addAll(this.toList(null, harmonicResults, false));
}
}
}
detectionServiceImpl.processing(realDataXiList, param, devIdMapComm, sourceIssue, dataRule);
});
}
private List<DevData> toList(List<AdNonHarmonicResult> nonHarm, List<AdHarmonicResult> harm, boolean containBaseHarm) {
List<DevData> info = new ArrayList<>();
// if (CollUtil.isNotEmpty(nonHarm)) {
if (CollUtil.isNotEmpty(nonHarm)) {
Map<String, List<AdNonHarmonicResult>> noHarmMap = nonHarm.stream()
.collect(Collectors.groupingBy(x -> x.getMonitorId() + "_" + x.getTimeId().format(DateTimeFormatter.ofPattern(DatePattern.UTC_SIMPLE_MS_PATTERN)) + "_" + x.getSort()));
noHarmMap.forEach((key, value) -> {
String[] split = key.split("_");
DevData data = new DevData();
data.setTime(split[2]);
data.setId(split[0] + "_" + split[1]);
List<DevData.SqlDataDTO> sqlDataDTOS = new ArrayList<>();
DevData.SqlDataDTO sqlDataDTO;
for (AdNonHarmonicResult result : value) {
sqlDataDTO = new DevData.SqlDataDTO();
sqlDataDTO.setType(result.getDataType());
DictTree dictTree = dictTreeService.getById(result.getAdType());
sqlDataDTO.setDesc(dictTree.getCode());
DevData.SqlDataDTO.ListDTO listDTO = new DevData.SqlDataDTO.ListDTO();
listDTO.setA(StrUtil.isNotBlank(result.getAValue()) ? Double.valueOf(result.getAValue()) : null);
listDTO.setB(StrUtil.isNotBlank(result.getBValue()) ? Double.valueOf(result.getBValue()) : null);
listDTO.setC(StrUtil.isNotBlank(result.getCValue()) ? Double.valueOf(result.getCValue()) : null);
listDTO.setT(StrUtil.isNotBlank(result.getTValue()) ? Double.valueOf(result.getTValue()) : null);
sqlDataDTO.setList(listDTO);
sqlDataDTOS.add(sqlDataDTO);
}
data.setSqlData(sqlDataDTOS);
info.add(data);
});
}
if (CollUtil.isNotEmpty(harm)) {
Map<String, List<AdHarmonicResult>> harmMap = harm.stream()
.collect(Collectors.groupingBy(x -> x.getMonitorId() + "_" + x.getTimeId().format(DateTimeFormatter.ofPattern(DatePattern.UTC_SIMPLE_MS_PATTERN))));
harmMap.forEach((key, value) -> {
List<DevData> collect = info.stream().filter(x -> key.equals(x.getId() + "_" + x.getTime())).collect(Collectors.toList());
List<DevData.SqlDataDTO> sqlDataDTOS = new ArrayList<>();
DevData.SqlDataDTO sqlDataDTO;
List<DevData.SqlDataHarmDTO> sqlDataHarmDTOS = new ArrayList<>();
DevData.SqlDataHarmDTO dataHarmDTO;
for (AdHarmonicResult harmonicResult : value) {
DictTree dictTree = dictTreeService.getById(harmonicResult.getAdType());
if (containBaseHarm) {
sqlDataDTO = new DevData.SqlDataDTO();
sqlDataDTO.setType(harmonicResult.getDataType());
if (DetectionCodeEnum.V2_50.getCode().equals(dictTree.getCode())) {
sqlDataDTO.setDesc(DetectionCodeEnum.U1.getCode());
} else if (DetectionCodeEnum.I2_50.getCode().equals(dictTree.getCode())) {
sqlDataDTO.setDesc(DetectionCodeEnum.I1.getCode());
} else {
sqlDataDTO.setDesc(dictTree.getCode());
}
DevData.SqlDataDTO.ListDTO listDTO = new DevData.SqlDataDTO.ListDTO();
listDTO.setA(StrUtil.isNotBlank(harmonicResult.getAValue1()) ? Double.valueOf(harmonicResult.getAValue1()) : null);
listDTO.setB(StrUtil.isNotBlank(harmonicResult.getBValue1()) ? Double.valueOf(harmonicResult.getBValue1()) : null);
listDTO.setC(StrUtil.isNotBlank(harmonicResult.getCValue1()) ? Double.valueOf(harmonicResult.getCValue1()) : null);
sqlDataDTO.setList(listDTO);
sqlDataDTOS.add(sqlDataDTO);
}
dataHarmDTO = new DevData.SqlDataHarmDTO();
dataHarmDTO.setType(harmonicResult.getDataType());
dataHarmDTO.setDesc(dictTree.getCode());
dataHarmDTO.setNum(containBaseHarm ? 49 : 50);
DevData.SqlDataHarmDTO.ListDTO listHarmDTO = new DevData.SqlDataHarmDTO.ListDTO();
listHarmDTO.setA(reflectHarmonicValue("a", harmonicResult, containBaseHarm));
listHarmDTO.setB(reflectHarmonicValue("b", harmonicResult, containBaseHarm));
listHarmDTO.setC(reflectHarmonicValue("c", harmonicResult, containBaseHarm));
dataHarmDTO.setList(listHarmDTO);
sqlDataHarmDTOS.add(dataHarmDTO);
}
if (CollUtil.isNotEmpty(collect)) {
collect.get(0).setSqlDataHarm(sqlDataHarmDTOS);
} else {
String[] split = key.split("_");
DevData data = new DevData();
data.setTime(split[2]);
data.setId(split[0] + "_" + split[1]);
data.setSqlData(sqlDataDTOS);
data.setSqlDataHarm(sqlDataHarmDTOS);
info.add(data);
}
});
}
// }
return info;
}
private List<String> reflectHarmonicValue(String phase, AdHarmonicResult adHarmonicResult, boolean notContainBaseHarm) {
List<String> info = new ArrayList<>();
for (int i = notContainBaseHarm ? 2 : 1; i <= 50; i++) {
String fieldName = phase + "Value" + i;
try {
Field idField = AdHarmonicResult.class.getDeclaredField(fieldName);
idField.setAccessible(true);
String value = idField.get(adHarmonicResult) + "";
info.add(value);
} catch (NoSuchFieldException | IllegalAccessException e) {
throw new RuntimeException(e);
}
}
return info;
}
}

View File

@@ -1,17 +1,18 @@
package com.njcn.gather.script.controller;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;
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.script.pojo.param.PqScriptDtlsParam;
import com.njcn.gather.script.pojo.param.PqScriptIssueParam;
import com.njcn.gather.script.pojo.param.PqScriptParam;
import com.njcn.gather.script.pojo.param.ScriptParam;
import com.njcn.gather.script.pojo.po.PqScript;
import com.njcn.gather.script.pojo.po.PqScriptCheckData;
import com.njcn.gather.script.pojo.po.PqScriptDtls;
import com.njcn.gather.script.pojo.po.SourceIssue;
import com.njcn.gather.script.service.IPqScriptDtlsService;
@@ -26,7 +27,6 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;
@@ -59,14 +59,14 @@ public class PqScriptController extends BaseController {
@PostMapping("/add")
@ApiOperation("新增检测脚本")
@ApiImplicitParam(name = "pqDevParam", value = "检测脚本", required = true)
public HttpResult<Object> add(@RequestBody @Validated PqScriptParam param) {
public HttpResult<Boolean> add(@RequestBody @Validated PqScriptParam param) {
String methodDescribe = getMethodDescribe("add");
LogUtil.njcnDebug(log, "{},新增数据为:{}", methodDescribe, param);
boolean result = pqScriptService.addPqScript(param);
Boolean result = pqScriptService.addPqScript(param);
if (result) {
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, methodDescribe);
} else {
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, null, methodDescribe);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, false, methodDescribe);
}
}
@@ -74,14 +74,14 @@ public class PqScriptController extends BaseController {
@PostMapping("/update")
@ApiOperation("修改检测脚本")
@ApiImplicitParam(name = "updateParam", value = "检测脚本", required = true)
public HttpResult<Object> update(@RequestBody @Validated PqScriptParam.UpdateParam param) {
public HttpResult<Boolean> update(@RequestBody @Validated PqScriptParam.UpdateParam param) {
String methodDescribe = getMethodDescribe("update");
LogUtil.njcnDebug(log, "{},修改数据为:{}", methodDescribe, param);
boolean result = pqScriptService.updatePqScript(param);
if (result) {
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, methodDescribe);
} else {
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, null, methodDescribe);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, false, methodDescribe);
}
}
@@ -89,19 +89,19 @@ public class PqScriptController extends BaseController {
@PostMapping("/delete")
@ApiOperation("删除检测脚本")
@ApiImplicitParam(name = "ids", value = "检测脚本id", required = true)
public HttpResult<Object> delete(@RequestBody List<String> ids) {
public HttpResult<Boolean> delete(@RequestBody List<String> ids) {
String methodDescribe = getMethodDescribe("delete");
LogUtil.njcnDebug(log, "{}删除ID数据为{}", methodDescribe, String.join(StrUtil.COMMA, ids));
boolean result = pqScriptService.deletePqScript(ids);
if (result) {
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, methodDescribe);
} else {
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, null, methodDescribe);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, false, methodDescribe);
}
}
@OperateInfo
@GetMapping("getScriptDtlsByScriptId")
@GetMapping("/getScriptDtlsByScriptId")
@ApiOperation("根据脚本id查询检测脚本详情")
@ApiImplicitParam(name = "id", value = "检测脚本id", required = true)
public HttpResult<List<PqScriptDtls>> getScriptDtlsByScriptId(@RequestParam("id") String id) {
@@ -115,14 +115,14 @@ public class PqScriptController extends BaseController {
@GetMapping("/upgradeToTemplate")
@ApiOperation("升级为模板")
@ApiImplicitParam(name = "id", value = "检测脚本id", required = true)
public HttpResult<Object> upgradeToTemplate(@RequestParam("id") String id, HttpServletRequest request) {
public HttpResult<Boolean> upgradeToTemplate(@RequestParam("id") String id) {
String methodDescribe = getMethodDescribe("upgradeToTemplate");
LogUtil.njcnDebug(log, "{}升级ID数据为{}", methodDescribe, id);
boolean result = pqScriptService.upgradeToTemplate(id);
if (result) {
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, methodDescribe);
} else {
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, null, methodDescribe);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, false, methodDescribe);
}
}
@@ -139,19 +139,83 @@ public class PqScriptController extends BaseController {
@OperateInfo
@PostMapping("dls")
@PostMapping("/dlsDetails")
@ApiOperation("根据脚本id查询检测脚本详情")
@ApiImplicitParam(name = "id", value = "检测脚本id", required = true)
public HttpResult<List<SourceIssue>> dls(@RequestBody PqScriptIssueParam param) {
String methodDescribe = getMethodDescribe("list");
@ApiImplicitParam(name = "param", value = "检测脚本", required = true)
public HttpResult<List<SourceIssue>> dlsDetails(@RequestBody PqScriptIssueParam param) {
String methodDescribe = getMethodDescribe("dlsDetails");
LogUtil.njcnDebug(log, "{},查询数据为:{}", methodDescribe, param);
List<SourceIssue> sourceIssues = pqScriptDtlsService.listSourceIssue(param);
for (SourceIssue sourceIssue : sourceIssues) {
String jsonString = JSON.toJSONString(sourceIssue,SerializerFeature.WriteNullStringAsEmpty);
System.out.println();
}
String jsonString =sourceIssues.get(0).toString();
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, sourceIssues, methodDescribe);
}
@OperateInfo
@PostMapping("/addScriptDtls")
@ApiOperation("添加检测脚本")
@ApiImplicitParam(name = "sourceIssue", value = "检测脚本", required = true)
public HttpResult<Boolean> addScriptDtls(@RequestBody PqScriptDtlsParam sourceIssue) {
String methodDescribe = getMethodDescribe("addScriptDtls");
LogUtil.njcnDebug(log, "{},查询数据为:{}", methodDescribe, sourceIssue);
Boolean b = pqScriptDtlsService.saveScriptDtls(sourceIssue);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, b, methodDescribe);
}
@OperateInfo
@PostMapping("/scriptDtlsCheckDataList")
@ApiOperation("根据通讯参数生成装置下发原始数据公式")
@ApiImplicitParam(name = "sourceIssue", value = "检测脚本", required = true)
public HttpResult<List<PqScriptDtlsParam.CheckData>> scriptDtlsCheckDataList(@RequestBody PqScriptDtlsParam sourceIssue) {
String methodDescribe = getMethodDescribe("scriptDtlsCheckDataList");
LogUtil.njcnDebug(log, "{},查询数据为:{}", methodDescribe, sourceIssue);
List<PqScriptDtlsParam.CheckData> checkData = pqScriptDtlsService.scriptDtlsCheckDataList(sourceIssue);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, checkData, methodDescribe);
}
@OperateInfo
@PostMapping("/deleteDtls")
@ApiOperation("删除脚本")
@ApiImplicitParam(name = "sourceIssue", value = "检测脚本", required = true)
public HttpResult<Boolean> deleteDtls(@RequestBody @Validated ScriptParam sourceIssue) {
String methodDescribe = getMethodDescribe("deleteDtls");
LogUtil.njcnDebug(log, "{},查询数据为:{}", methodDescribe, sourceIssue);
Boolean b = pqScriptDtlsService.deleteDtls(sourceIssue);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, b, methodDescribe);
}
@OperateInfo
@PostMapping("/updateDtls")
@ApiOperation("启用关闭脚本")
@ApiImplicitParam(name = "sourceIssue", value = "检测脚本", required = true)
public HttpResult<Boolean> updateDtls(@RequestBody @Validated ScriptParam sourceIssue) {
String methodDescribe = getMethodDescribe("updateDtls");
LogUtil.njcnDebug(log, "{},查询数据为:{}", methodDescribe, sourceIssue);
Boolean b = pqScriptDtlsService.updateDtls(sourceIssue);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, b, methodDescribe);
}
@OperateInfo
@PostMapping("/checkDataList")
@ApiOperation("通讯脚本回显")
@ApiImplicitParam(name = "sourceIssue", value = "检测脚本", required = true)
public HttpResult<List<PqScriptCheckData>> checkDataList(@RequestBody @Validated ScriptParam sourceIssue) {
String methodDescribe = getMethodDescribe("checkDataList");
LogUtil.njcnDebug(log, "{},查询数据为:{}", methodDescribe, sourceIssue);
List<PqScriptCheckData> checkData = pqScriptDtlsService.checkDataList(sourceIssue);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, checkData, methodDescribe);
}
@OperateInfo
@PostMapping("/getScriptDtlsDesc")
@ApiOperation("通讯脚本回显")
@ApiImplicitParam(name = "param", value = "检测脚本", required = true)
public HttpResult<String> getScriptDtlsDesc(@RequestBody @Validated ScriptParam.Desc param) {
String methodDescribe = getMethodDescribe("getScriptDtlsDesc");
String checkData = pqScriptDtlsService.getScriptDtlsDesc(param);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, checkData, methodDescribe);
}
}

View File

@@ -2,6 +2,7 @@ package com.njcn.gather.script.mapper;
import com.github.yulichang.base.MPJBaseMapper;
import com.njcn.gather.script.pojo.po.PqScriptDtls;
import org.apache.ibatis.annotations.Param;
/**
* @author caozehui
@@ -9,5 +10,12 @@ import com.njcn.gather.script.pojo.po.PqScriptDtls;
*/
public interface PqScriptDtlsMapper extends MPJBaseMapper<PqScriptDtls> {
/**
* 获取当前检测脚本最大index值
*
* @param scriptId
* @return
*/
Integer selectMaxIndex(@Param("scriptId") String scriptId);
}

View File

@@ -4,6 +4,8 @@ import com.github.yulichang.base.MPJBaseMapper;
import com.njcn.gather.script.pojo.po.PqScript;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* @author caozehui
* @date 2024-11-18
@@ -12,11 +14,20 @@ public interface PqScriptMapper extends MPJBaseMapper<PqScript> {
/**
* 获取检测脚本信息(先获取检测脚本类型是否相对值 true相对值 false绝对值相对值要乘额定值,绝对值不需要处理))
*
* @param scriptId
* @return: com.njcn.gather.device.script.pojo.po.PqScript
* @Author: wr
* @Date: 2024/12/16 18:08
*/
Boolean selectScriptIsValueType(@Param("scriptId") String scriptId);
/**
* 根据脚本id获取绑定的计划数量
*
* @param scriptIds
* @return
*/
Integer getBoundCountByScriptIds(@Param("scriptIds") List<String> scriptIds);
}

View File

@@ -3,5 +3,12 @@
<mapper namespace="com.njcn.gather.script.mapper.PqScriptDtlsMapper">
<select id="selectMaxIndex" resultType="java.lang.Integer">
SELECT IFNULL(max(t.Script_Index), -1) AS num
FROM pq_script_dtls t
WHERE Script_Id = #{scriptId}
</select>
</mapper>

View File

@@ -12,5 +12,16 @@
State=1
and Id = #{scriptId}
</select>
<select id="getBoundCountByScriptIds" resultType="java.lang.Integer">
SELECT COUNT(*) FROM ad_plan
<if test="scriptIds !=null and scriptIds.size()!=0">
<where>
AND Script_Id in
<foreach collection="scriptIds" item="item" open="(" separator="," close=")">
#{item}
</foreach>
</where>
</if>
</select>
</mapper>

View File

@@ -14,6 +14,12 @@ public class PqScriptCheckDataParam {
@ApiModelProperty("总检测脚本中的测试项序号")
private Integer index;
@ApiModelProperty("检测指标类型,与数据字典关联(例如电压有效值、谐波电压含有率等)")
private String valueType;
@ApiModelProperty("相别,字典表")
private String phase;
@ApiModelProperty("检测指标类型(true:code(I$real) false展示id 默认false)")
private Boolean isValueTypeName=false;

Some files were not shown because too many files have changed in this diff Show More