85 Commits

Author SHA1 Message Date
caozehui
694a99a96f 检测计划统计弹窗下拉框内容调整 2026-05-29 09:57:55 +08:00
befe5abe0c refactor(detection): 移除测试专用的延迟释放检测锁逻辑
- 删除了测试期间用于模拟BUSY弹窗的延迟释放机制
- 移除了RELEASE_DELAY_FOR_TEST_SECONDS常量和DELAYED_RELEASER调度器
- 简化了连接失败和异常时的检测锁释放逻辑,改为立即释放
- 清理了相关的测试日志输出代码
2026-05-29 09:34:31 +08:00
46ec9923a7 docs(detection): 删除CN_Gather Detection模块Netty通信架构分析文档
- 移除了详细的Netty客户端和服务端组件说明文档
- 删除了WebSocket通信组件的技术细节描述
- 移除了Socket响应处理器和管理工具类的详细分析
- 清理了通信数据对象和流程分析相关内容
- 移除了智能Socket通信机制的技术文档
- 删除了配置管理组件和Spring集成的相关说明
2026-05-28 20:28:37 +08:00
caozehui
d2388576a9 资源管理微调 2026-05-28 16:27:04 +08:00
caozehui
7f21049d0f 检测计划统计功能 2026-05-28 13:27:15 +08:00
caozehui
49ca27d994 微调 2026-05-27 11:20:44 +08:00
3cb4a46a16 refactor(report): 优化报告生成服务的安全性和文档处理
- 添加 FilePathSanitizer 工具类,防止路径穿越和非法字符问题
- 在报告目录路径构建中使用安全的文件名处理
- 为 BookmarkEnum 添加排序字段和注释说明
- 改进书签处理排序逻辑,使用 sort 字段而非依赖枚举声明顺序
- 添加批量处理的语义说明文档
- 优化数据处理流程中的哨兵标记机制
- 为 WordReportService 接口添加详细的资源管理契约文档
- 改进 dealDataLine 方法的职责分离和参数命名
- 修复测试结果详情书签键值引用错误
2026-05-26 19:20:03 +08:00
caozehui
13677f21d9 微调 2026-05-26 15:41:28 +08:00
caozehui
a1941a375b 检测计划统计功能 2026-05-26 09:23:04 +08:00
caozehui
9dc8ecd873 Reapply "统一sourceId"
This reverts commit 7c6c103f17.
2026-05-25 18:41:39 +08:00
caozehui
7c6c103f17 Revert "统一sourceId"
This reverts commit 1cfea7fd6c.
2026-05-25 18:41:19 +08:00
caozehui
b113788e54 Revert "报告生成、检测结果查询调整"
This reverts commit 282f9cf4eb.
2026-05-25 18:41:15 +08:00
caozehui
599edde008 Revert "微调"
This reverts commit 6fd180b4d4.
2026-05-25 18:41:11 +08:00
caozehui
cc0b685c66 Reapply "统一sourceId"
This reverts commit c651b18e72.
2026-05-25 18:41:07 +08:00
caozehui
29b0a4f966 Merge remote-tracking branch 'origin/master' 2026-05-25 18:39:25 +08:00
caozehui
c651b18e72 Revert "统一sourceId"
This reverts commit 1cfea7fd6c.
2026-05-25 18:39:19 +08:00
caozehui
6fd180b4d4 微调 2026-05-25 16:20:06 +08:00
caozehui
282f9cf4eb 报告生成、检测结果查询调整 2026-05-25 14:27:15 +08:00
caozehui
1cfea7fd6c 统一sourceId 2026-05-12 14:34:57 +08:00
caozehui
251e302e59 统一sourceId 2026-05-12 10:36:44 +08:00
caozehui
873e920add 微调 2026-04-22 09:36:35 +08:00
caozehui
fd7c6ada6b 回滚 2026-04-13 15:41:37 +08:00
caozehui
c148bddfc9 Revert "微调"
This reverts commit 4110a835c8.
2026-04-13 15:39:15 +08:00
caozehui
f0857b7c46 Revert "微调"
This reverts commit ef757c52ea.
2026-04-13 15:38:55 +08:00
9b1c6f61e6 revert e78ce544e3
revert 微调
2026-04-13 15:31:24 +08:00
caozehui
3f72c52cdc Revert "微调"
This reverts commit e78ce544e3.
2026-04-13 15:27:55 +08:00
caozehui
ef757c52ea 微调 2026-04-10 15:13:22 +08:00
caozehui
4110a835c8 微调 2026-04-10 14:13:27 +08:00
caozehui
e78ce544e3 微调 2026-03-26 13:23:02 +08:00
caozehui
c10d54e79a 微调 2026-01-30 16:11:14 +08:00
caozehui
2796558040 重采方案 2026-01-26 10:16:48 +08:00
caozehui
920a808729 微调 2026-01-22 15:25:48 +08:00
caozehui
8e24ac4b71 脚本单独配置BC暂态时左侧树形列表展示不全问题 2026-01-22 15:09:02 +08:00
caozehui
3eb2736edb 微调 2026-01-22 11:26:25 +08:00
caozehui
8c3eba9224 平均值时移除误差较大的几组数据 2026-01-21 14:01:07 +08:00
caozehui
6288aa565e 系数下发 2026-01-19 14:23:23 +08:00
caozehui
0fa7ec91c4 微调 2025-12-30 08:36:09 +08:00
caozehui
fdb4b7060a 暂态前后延时间 2025-12-24 14:41:47 +08:00
3f47b0f008 微调 压缩文件的编解码保持一致 2025-12-23 10:29:40 +08:00
caozehui
cb431b5af1 Merge remote-tracking branch 'origin/master'
# Conflicts:
#	entrance/src/main/resources/application.yml
2025-12-23 10:22:04 +08:00
caozehui
153428b24f 合并qr_branch分支代码 2025-12-22 10:30:56 +08:00
caozehui
d92544f7c4 Merge branch 'qr_branch'
# Conflicts:
#	detection/src/main/java/com/njcn/gather/detection/handler/SocketDevResponseService.java
#	detection/src/main/java/com/njcn/gather/detection/handler/SocketSourceResponseService.java
#	detection/src/main/java/com/njcn/gather/detection/service/impl/DetectionServiceImpl.java
#	detection/src/main/java/com/njcn/gather/report/service/impl/PqReportServiceImpl.java
#	detection/src/main/java/com/njcn/gather/report/utils/BookmarkUtil.java
#	detection/src/main/java/com/njcn/gather/report/utils/Docx4jUtil.java
#	detection/src/main/java/com/njcn/gather/result/service/impl/ResultServiceImpl.java
#	entrance/src/main/resources/application.yml
2025-12-22 08:52:13 +08:00
caozehui
3f1ae1886a Merge remote-tracking branch 'origin/qr_branch' into qr_branch 2025-12-19 16:17:40 +08:00
caozehui
af4863af65 2楼报告封面调整:装置编码改成装置编号 2025-12-19 16:17:33 +08:00
caozehui
4b7c1259a7 ICD映射上传路径微调 2025-12-16 16:18:02 +08:00
caozehui
de1496389e 微调 2025-12-11 16:19:26 +08:00
79003cd0f4 微调 2025-12-10 18:48:28 +08:00
caozehui
c3443fcc91 切换数据处理原则 2025-12-10 11:15:43 +08:00
caozehui
5105e77823 微调 2025-12-10 09:17:31 +08:00
caozehui
eb068b76a4 报告模板路径调整 2025-12-09 16:18:53 +08:00
9f11f7ec11 河北报告定制化改动 2025-12-02 13:52:07 +08:00
2012221b73 河北报告定制化改动 2025-12-02 13:37:35 +08:00
caozehui
9ab5d42439 微调 2025-12-01 19:14:29 +08:00
7abcaefeb1 增加回路额定电流描述 2025-11-27 20:03:11 +08:00
caozehui
f4df52dd1c 暂态只有a项时,当a相无数据时判断为不符合 2025-11-27 18:36:38 +08:00
db115bb27d 调整电流的小数位 2025-11-27 17:08:49 +08:00
caozehui
68d96e67aa 重新计算、更换误差体系接口调整,cp95处理原则调整、检测结果原始数据调整 2025-11-26 18:33:35 +08:00
3f94012faa 修复数模式的相序校验电流加量问题 2025-11-26 10:34:25 +08:00
41c557118c Merge remote-tracking branch 'origin/qr_branch' into qr_branch 2025-11-26 10:22:15 +08:00
6596a572d6 修复数模式的相序校验电流加量问题 2025-11-26 10:17:33 +08:00
139c7b0651 微调 2025-11-26 08:36:25 +08:00
caozehui
ab236cd34f 微调 2025-11-21 10:09:48 +08:00
caozehui
786bd5d660 报告调整 2025-11-19 13:20:35 +08:00
caozehui
21d2c2b7a7 报告调整 2025-11-19 13:20:17 +08:00
caozehui
48fa4c2390 报告日期格式根据参数动态变化 2025-11-19 10:43:52 +08:00
caozehui
033330b005 微调 2025-11-19 09:35:49 +08:00
caozehui
f81123c3f7 监测点修改同步状态调整、脚本新增福禄克专用字段 2025-11-17 16:32:52 +08:00
caozehui
5539cb2887 微调 2025-11-14 10:16:08 +08:00
caozehui
1df9c8d703 微调 2025-11-13 14:20:50 +08:00
caozehui
1cbed2a620 icd上传映射文件 2025-11-13 08:37:52 +08:00
89667367ea 添加水印 2025-11-12 11:45:21 +08:00
92b95dd86d 微调 2025-11-11 13:18:42 +08:00
caozehui
6b7e38fef6 处理源未知异常 2025-11-10 14:45:23 +08:00
caozehui
f10debe2f2 比对-被检设备导入微调 2025-11-07 15:13:07 +08:00
caozehui
9d15351fba 微调 2025-11-06 09:25:09 +08:00
caozehui
2339a006ec 补充源未知异常推送消息 2025-11-06 08:51:54 +08:00
caozehui
7fd904ab79 系数校准接收数据个数调整 2025-11-05 16:02:53 +08:00
caozehui
61f149b562 系数校准接收数据个数调整 2025-11-05 13:51:47 +08:00
caozehui
40cb153656 报告模板调整 2025-11-03 08:38:57 +08:00
caozehui
f922ee97aa 报告路径,报告名称修改 2025-10-30 09:06:40 +08:00
caozehui
26c5e933f5 微调 2025-10-29 09:01:45 +08:00
caozehui
c7d8fc3168 报告封面微调 2025-10-22 11:05:21 +08:00
caozehui
bb22857fc9 报告微调 2025-10-21 15:42:22 +08:00
caozehui
6ef908ff60 微调 2025-09-03 20:32:14 +08:00
caozehui
7461801657 微调 2025-09-03 16:18:52 +08:00
117 changed files with 4871 additions and 2349 deletions

5
.gitignore vendored
View File

@@ -48,3 +48,8 @@ rebel.xml
/.fastRequest/collections/Root/Default Group/directory.json /.fastRequest/collections/Root/Default Group/directory.json
/.fastRequest/collections/Root/directory.json /.fastRequest/collections/Root/directory.json
/.fastRequest/config/fastRequestCurrentProjectConfig.json /.fastRequest/config/fastRequestCurrentProjectConfig.json
# 个人工作文档,不与团队共享
CLAUDE.md
docs/
data/

File diff suppressed because it is too large Load Diff

View File

@@ -1,17 +1,27 @@
package com.njcn.gather.detection.controller; package com.njcn.gather.detection.controller;
import cn.hutool.core.util.StrUtil;
import com.njcn.common.pojo.annotation.OperateInfo; import com.njcn.common.pojo.annotation.OperateInfo;
import com.njcn.common.pojo.constant.OperateType; import com.njcn.common.pojo.constant.OperateType;
import com.njcn.common.pojo.enums.common.LogEnum; import com.njcn.common.pojo.enums.common.LogEnum;
import com.njcn.common.pojo.enums.response.CommonResponseEnum; import com.njcn.common.pojo.enums.response.CommonResponseEnum;
import com.njcn.common.pojo.response.HttpResult; import com.njcn.common.pojo.response.HttpResult;
import com.njcn.common.utils.LogUtil; import com.njcn.common.utils.LogUtil;
import com.njcn.gather.detection.lock.DetectionLock;
import com.njcn.gather.detection.lock.DetectionLockManager;
import com.njcn.gather.detection.lock.DetectionLockManager.AcquireResult;
import com.njcn.gather.detection.pojo.enums.DetectionResponseEnum;
import com.njcn.gather.detection.pojo.param.ContrastDetectionParam; import com.njcn.gather.detection.pojo.param.ContrastDetectionParam;
import com.njcn.gather.detection.pojo.param.PreDetectionParam; import com.njcn.gather.detection.pojo.param.PreDetectionParam;
import com.njcn.gather.detection.pojo.param.SimulateDetectionParam; import com.njcn.gather.detection.pojo.param.SimulateDetectionParam;
import com.njcn.gather.detection.pojo.vo.DetectionLockHolderVO;
import com.njcn.gather.detection.service.PreDetectionService; import com.njcn.gather.detection.service.PreDetectionService;
import com.njcn.gather.detection.util.socket.FormalTestManager;
import com.njcn.gather.user.user.pojo.po.SysUser;
import com.njcn.gather.user.user.service.ISysUserService;
import com.njcn.web.controller.BaseController; import com.njcn.web.controller.BaseController;
import com.njcn.web.utils.HttpResultUtil; import com.njcn.web.utils.HttpResultUtil;
import com.njcn.web.utils.RequestUtil;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
@@ -32,6 +42,7 @@ import org.springframework.web.bind.annotation.*;
public class PreDetectionController extends BaseController { public class PreDetectionController extends BaseController {
private final PreDetectionService preDetectionService; private final PreDetectionService preDetectionService;
private final ISysUserService sysUserService;
/** /**
* 开始检测通用入口 * 开始检测通用入口
@@ -42,10 +53,27 @@ public class PreDetectionController extends BaseController {
@OperateInfo @OperateInfo
@ApiOperation("开始检测") @ApiOperation("开始检测")
@ApiImplicitParam(name = "param", value = "查询参数", required = true) @ApiImplicitParam(name = "param", value = "查询参数", required = true)
public HttpResult<String> startPreTest(@RequestBody @Validated PreDetectionParam param) { public HttpResult<?> startPreTest(@RequestBody @Validated PreDetectionParam param) {
String methodDescribe = getMethodDescribe("startPreTest"); String methodDescribe = getMethodDescribe("startPreTest");
preDetectionService.sourceCommunicationCheck(param); HttpResult<DetectionLockHolderVO> busy = tryAcquireLock(param.getUserPageId());
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe); if (busy != null) {
return busy;
}
// 同步阶段抛异常时回滚锁PLAN_AND_SOURCE_NOT / SOURCE_INFO_NOT 等业务异常会被全局处理器吞掉,
// 锁会卡在用户手上直到 4 小时超时,故需 finally 兜底)
boolean keepLock = false;
try {
// 重置 FormalTestManager 暂停计数残留,避免上次暂停残留计数误触发 R4
FormalTestManager.stopTime = 0;
FormalTestManager.hasStopFlag = false;
preDetectionService.sourceCommunicationCheck(param);
keepLock = true;
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
} finally {
if (!keepLock) {
releaseLockSelf("START_PRE_SYNC_FAILED");
}
}
} }
@@ -59,8 +87,12 @@ public class PreDetectionController extends BaseController {
@OperateInfo @OperateInfo
@ApiOperation("源通讯校验") @ApiOperation("源通讯校验")
@ApiImplicitParam(name = "param", value = "查询参数", required = true) @ApiImplicitParam(name = "param", value = "查询参数", required = true)
public HttpResult<String> ytxCheckSimulate(@RequestBody @Validated SimulateDetectionParam param) { public HttpResult<?> ytxCheckSimulate(@RequestBody @Validated SimulateDetectionParam param) {
String methodDescribe = getMethodDescribe("ytxCheckSimulate"); String methodDescribe = getMethodDescribe("ytxCheckSimulate");
HttpResult<DetectionLockHolderVO> busy = requireFreeOrSelf();
if (busy != null) {
return busy;
}
preDetectionService.ytxCheckSimulate(param); preDetectionService.ytxCheckSimulate(param);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe); return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
} }
@@ -72,8 +104,12 @@ public class PreDetectionController extends BaseController {
@OperateInfo @OperateInfo
@ApiOperation("启动") @ApiOperation("启动")
@ApiImplicitParam(name = "param", value = "查询参数", required = true) @ApiImplicitParam(name = "param", value = "查询参数", required = true)
public HttpResult<String> startTestSimulate(@RequestBody @Validated SimulateDetectionParam param) { public HttpResult<?> startTestSimulate(@RequestBody @Validated SimulateDetectionParam param) {
String methodDescribe = getMethodDescribe("startTestSimulate"); String methodDescribe = getMethodDescribe("startTestSimulate");
HttpResult<DetectionLockHolderVO> busy = requireHolderSelf();
if (busy != null) {
return busy;
}
preDetectionService.sendScript(param); preDetectionService.sendScript(param);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe); return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
} }
@@ -85,9 +121,18 @@ public class PreDetectionController extends BaseController {
@OperateInfo @OperateInfo
@ApiOperation("停止") @ApiOperation("停止")
@ApiImplicitParam(name = "param", value = "查询参数", required = true) @ApiImplicitParam(name = "param", value = "查询参数", required = true)
public HttpResult<String> closeSimulateTest(@RequestBody @Validated SimulateDetectionParam param) { public HttpResult<?> closeSimulateTest(@RequestBody @Validated SimulateDetectionParam param) {
String methodDescribe = getMethodDescribe("closeSimulateTest"); String methodDescribe = getMethodDescribe("closeSimulateTest");
preDetectionService.closeTestSimulate(param); HttpResult<DetectionLockHolderVO> busy = requireHolderSelf();
if (busy != null) {
return busy;
}
try {
preDetectionService.closeTestSimulate(param);
} finally {
// 即使业务异常也要释放锁,避免锁残留导致他人无法接手
releaseLockSelf("USER_STOP");
}
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe); return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
} }
@@ -99,8 +144,12 @@ public class PreDetectionController extends BaseController {
@OperateInfo @OperateInfo
@ApiOperation("系数校验") @ApiOperation("系数校验")
@ApiImplicitParam(name = "param", value = "查询参数", required = true) @ApiImplicitParam(name = "param", value = "查询参数", required = true)
public HttpResult<String> coefficientCheck(@RequestBody PreDetectionParam param) { public HttpResult<?> coefficientCheck(@RequestBody PreDetectionParam param) {
String methodDescribe = getMethodDescribe("coefficientCheck"); String methodDescribe = getMethodDescribe("coefficientCheck");
HttpResult<DetectionLockHolderVO> busy = requireHolderSelf();
if (busy != null) {
return busy;
}
preDetectionService.coefficientCheck(param); preDetectionService.coefficientCheck(param);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe); return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
} }
@@ -113,8 +162,13 @@ public class PreDetectionController extends BaseController {
@OperateInfo @OperateInfo
@ApiOperation("暂停检测") @ApiOperation("暂停检测")
@ApiImplicitParam(name = "param", value = "参数", required = true) @ApiImplicitParam(name = "param", value = "参数", required = true)
public HttpResult<String> temStopTest() { public HttpResult<?> temStopTest() {
String methodDescribe = getMethodDescribe("temStopTest"); String methodDescribe = getMethodDescribe("temStopTest");
HttpResult<DetectionLockHolderVO> busy = requireHolderSelf();
if (busy != null) {
return busy;
}
// 暂停保持锁spec §2.3),不释放
preDetectionService.temStopTest(); preDetectionService.temStopTest();
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe); return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
} }
@@ -126,8 +180,12 @@ public class PreDetectionController extends BaseController {
@OperateInfo @OperateInfo
@ApiOperation("重新开始检测") @ApiOperation("重新开始检测")
@ApiImplicitParam(name = "param", value = "参数", required = true) @ApiImplicitParam(name = "param", value = "参数", required = true)
public HttpResult<String> restartTemTest(@RequestBody PreDetectionParam param) { public HttpResult<?> restartTemTest(@RequestBody PreDetectionParam param) {
String methodDescribe = getMethodDescribe("restartTemTest"); String methodDescribe = getMethodDescribe("restartTemTest");
HttpResult<DetectionLockHolderVO> busy = requireHolderSelf();
if (busy != null) {
return busy;
}
preDetectionService.restartTemTest(param); preDetectionService.restartTemTest(param);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe); return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
} }
@@ -140,10 +198,26 @@ public class PreDetectionController extends BaseController {
@OperateInfo @OperateInfo
@ApiOperation("开始比对检测") @ApiOperation("开始比对检测")
@ApiImplicitParam(name = "param", value = "查询参数", required = true) @ApiImplicitParam(name = "param", value = "查询参数", required = true)
public HttpResult<String> startContrastTest(@RequestBody @Validated ContrastDetectionParam param) { public HttpResult<?> startContrastTest(@RequestBody @Validated ContrastDetectionParam param) {
String methodDescribe = getMethodDescribe("startContrastTest"); String methodDescribe = getMethodDescribe("startContrastTest");
preDetectionService.startContrastTest(param); // ContrastDetectionParam 无 userPageId 字段,用 loginName 作为会话标识(与 WS 会话 key 一致)
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe); HttpResult<DetectionLockHolderVO> busy = tryAcquireLock(param.getLoginName());
if (busy != null) {
return busy;
}
// 同步阶段抛异常时回滚锁,理由同 startPreTest
boolean keepLock = false;
try {
FormalTestManager.stopTime = 0;
FormalTestManager.hasStopFlag = false;
preDetectionService.startContrastTest(param);
keepLock = true;
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
} finally {
if (!keepLock) {
releaseLockSelf("START_CONTRAST_SYNC_FAILED");
}
}
} }
@@ -155,4 +229,105 @@ public class PreDetectionController extends BaseController {
LogUtil.njcnDebug(log, "{}", methodDescribe); LogUtil.njcnDebug(log, "{}", methodDescribe);
preDetectionService.exportAlignData(); preDetectionService.exportAlignData();
} }
@OperateInfo(info = LogEnum.SYSTEM_COMMON)
@GetMapping("/canCoefficient")
@ApiOperation("比对模式是否能够进行系数校验")
public HttpResult<Boolean> canCoefficient() {
String methodDescribe = getMethodDescribe("canCoefficient");
LogUtil.njcnDebug(log, "{}", methodDescribe);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, preDetectionService.getCanCoefficient(), methodDescribe);
}
@OperateInfo(info = LogEnum.SYSTEM_COMMON)
@GetMapping("/startCoefficient")
@ApiOperation("比对模式开启系数校验")
public HttpResult<?> startCoefficient() {
String methodDescribe = getMethodDescribe("startCoefficient");
LogUtil.njcnDebug(log, "{}", methodDescribe);
HttpResult<DetectionLockHolderVO> busy = requireHolderSelf();
if (busy != null) {
return busy;
}
preDetectionService.startCoefficient();
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
}
// ============ 检测互斥锁辅助方法 ============
/** 抢锁入口startPreTest / startContrastTest 用)。
* 抢到→null被他人持有或竞态失败→返回 busy 响应;
* 使用方:拿到非 null 返回值直接 return 给上层。 */
private HttpResult<DetectionLockHolderVO> tryAcquireLock(String userPageId) {
String userId = RequestUtil.getUserId();
AcquireResult r = DetectionLockManager.getInstance()
.tryAcquire(userId, resolveDisplayName(userId), userPageId);
if (r.isOk()) {
return null;
}
return HttpResultUtil.assembleResult(
DetectionResponseEnum.DETECTION_BUSY.getCode(),
r.getHolder(),
DetectionResponseEnum.DETECTION_BUSY.getMessage());
}
/** 中间接口校验:要求当前 holder == 自己。
* 空闲 → 返回 busy data=null"请先开始检测"语义);
* 他人持有 → 返回 busy + holder
* 自己持有 → 返回 null放行。 */
private HttpResult<DetectionLockHolderVO> requireHolderSelf() {
DetectionLock cur = DetectionLockManager.getInstance().getCurrent();
String me = RequestUtil.getUserId();
if (cur != null && me.equals(cur.getUserId())) {
return null;
}
DetectionLockHolderVO holder = cur == null ? null : DetectionLockManager.toHolderVO(cur);
return HttpResultUtil.assembleResult(
DetectionResponseEnum.DETECTION_BUSY.getCode(),
holder,
DetectionResponseEnum.DETECTION_BUSY.getMessage());
}
/** 辅助接口规则ytxCheckSimulate锁空闲 → 放行;他人持有 → busy自己持有 → 放行。 */
private HttpResult<DetectionLockHolderVO> requireFreeOrSelf() {
DetectionLock cur = DetectionLockManager.getInstance().getCurrent();
if (cur == null) {
return null;
}
String me = RequestUtil.getUserId();
if (me.equals(cur.getUserId())) {
return null;
}
return HttpResultUtil.assembleResult(
DetectionResponseEnum.DETECTION_BUSY.getCode(),
DetectionLockManager.toHolderVO(cur),
DetectionResponseEnum.DETECTION_BUSY.getMessage());
}
/** 释放锁(用户主动终止)。 */
private void releaseLockSelf(String reason) {
DetectionLockManager.getInstance().releaseIfHeldBy(RequestUtil.getUserId(), reason);
}
/** 解析展示给前端的用户名昵称优先loginName 兜底,避免 BUSY 弹窗显示 "unknown user")。 */
private String resolveDisplayName(String userId) {
if (StrUtil.isBlank(userId)) {
return "";
}
try {
SysUser user = sysUserService.getById(userId);
if (user != null && StrUtil.isNotBlank(user.getName())) {
return user.getName();
}
if (user != null && StrUtil.isNotBlank(user.getLoginName())) {
return user.getLoginName();
}
} catch (Exception e) {
log.warn("解析检测锁持有者昵称失败userId={}", userId, e);
}
// 最终兜底:用 token 里的 loginName不要返回 "unknown user"
String loginName = RequestUtil.getLoginNameByToken();
return StrUtil.isNotBlank(loginName) ? loginName : userId;
}
} }

View File

@@ -11,7 +11,9 @@ import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature; import com.alibaba.fastjson.serializer.SerializerFeature;
import com.google.common.collect.HashBiMap; import com.google.common.collect.HashBiMap;
import com.njcn.common.pojo.enums.common.DataStateEnum;
import com.njcn.common.pojo.exception.BusinessException; import com.njcn.common.pojo.exception.BusinessException;
import com.njcn.gather.detection.pojo.dto.DevXiNumData;
import com.njcn.gather.detection.pojo.dto.WaveCommandDTO; import com.njcn.gather.detection.pojo.dto.WaveCommandDTO;
import com.njcn.gather.detection.pojo.dto.WaveResultDTO; import com.njcn.gather.detection.pojo.dto.WaveResultDTO;
import com.njcn.gather.detection.pojo.enums.*; import com.njcn.gather.detection.pojo.enums.*;
@@ -24,15 +26,17 @@ import com.njcn.gather.detection.pojo.vo.*;
import com.njcn.gather.detection.service.IAdPariService; import com.njcn.gather.detection.service.IAdPariService;
import com.njcn.gather.detection.service.impl.DetectionServiceImpl; import com.njcn.gather.detection.service.impl.DetectionServiceImpl;
import com.njcn.gather.detection.util.DetectionUtil; import com.njcn.gather.detection.util.DetectionUtil;
import com.njcn.gather.detection.util.socket.CnSocketUtil; import com.njcn.gather.detection.util.socket.*;
import com.njcn.gather.detection.util.socket.FormalTestManager;
import com.njcn.gather.detection.util.socket.MsgUtil;
import com.njcn.gather.detection.util.socket.SocketManager;
import com.njcn.gather.detection.util.socket.websocket.WebServiceManager; import com.njcn.gather.detection.util.socket.websocket.WebServiceManager;
import com.njcn.gather.device.pojo.enums.PatternEnum; import com.njcn.gather.device.pojo.enums.PatternEnum;
import com.njcn.gather.device.pojo.po.PqStandardDevGain;
import com.njcn.gather.device.pojo.po.PqStandardDevGainRecord;
import com.njcn.gather.device.pojo.vo.PreDetection; import com.njcn.gather.device.pojo.vo.PreDetection;
import com.njcn.gather.device.service.IPqDevService; import com.njcn.gather.device.service.IPqDevService;
import com.njcn.gather.device.service.IPqStandardDevGainRecordService;
import com.njcn.gather.device.service.IPqStandardDevGainService;
import com.njcn.gather.device.service.IPqStandardDevService; import com.njcn.gather.device.service.IPqStandardDevService;
import com.njcn.gather.monitor.pojo.po.PqMonitor;
import com.njcn.gather.monitor.service.IPqMonitorService; import com.njcn.gather.monitor.service.IPqMonitorService;
import com.njcn.gather.plan.pojo.enums.DataSourceEnum; import com.njcn.gather.plan.pojo.enums.DataSourceEnum;
import com.njcn.gather.plan.service.IAdPlanService; import com.njcn.gather.plan.service.IAdPlanService;
@@ -42,6 +46,7 @@ import com.njcn.gather.storage.pojo.po.ContrastNonHarmonicResult;
import com.njcn.gather.storage.service.DetectionDataDealService; import com.njcn.gather.storage.service.DetectionDataDealService;
import com.njcn.gather.system.cfg.pojo.po.SysTestConfig; import com.njcn.gather.system.cfg.pojo.po.SysTestConfig;
import com.njcn.gather.system.cfg.service.ISysTestConfigService; import com.njcn.gather.system.cfg.service.ISysTestConfigService;
import com.njcn.gather.system.config.PathConfig;
import com.njcn.gather.system.dictionary.pojo.enums.DictDataEnum; import com.njcn.gather.system.dictionary.pojo.enums.DictDataEnum;
import com.njcn.gather.system.dictionary.pojo.po.DictData; import com.njcn.gather.system.dictionary.pojo.po.DictData;
import com.njcn.gather.system.dictionary.pojo.po.DictTree; import com.njcn.gather.system.dictionary.pojo.po.DictTree;
@@ -53,7 +58,6 @@ import com.njcn.gather.tools.comtrade.comparewave.service.ICompareWaveService;
import com.njcn.gather.util.StorageUtil; import com.njcn.gather.util.StorageUtil;
import com.njcn.web.utils.ExcelUtil; import com.njcn.web.utils.ExcelUtil;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.io.FileInputStream; import java.io.FileInputStream;
@@ -62,6 +66,7 @@ import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.DecimalFormat; import java.text.DecimalFormat;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
@@ -92,6 +97,8 @@ public class SocketContrastResponseService {
private final IAdPariService adPairService; private final IAdPariService adPairService;
private final ICompareWaveService compareWaveService; private final ICompareWaveService compareWaveService;
private final IAdPlanTestConfigService adPlanTestConfigService; private final IAdPlanTestConfigService adPlanTestConfigService;
private final IPqStandardDevGainService pqStandardDevGainService;
private final IPqStandardDevGainRecordService pqStandardDevGainRecordService;
/** /**
@@ -120,8 +127,9 @@ public class SocketContrastResponseService {
// private SysRegRes contrastRegRes = null; // private SysRegRes contrastRegRes = null;
@Value("${log.homeDir}") // @Value("${report.reportDir}")
private String alignDataFilePath; // private String alignDataFilePath;
private final PathConfig pathConfig;
public static final Map<String, List<String>> testItemCodeMap = new HashMap() {{ public static final Map<String, List<String>> testItemCodeMap = new HashMap() {{
put("FREQ", Arrays.asList(DetectionCodeEnum.FREQ.getCode())); put("FREQ", Arrays.asList(DetectionCodeEnum.FREQ.getCode()));
@@ -182,7 +190,10 @@ public class SocketContrastResponseService {
FormalTestManager.pstDataType = null; FormalTestManager.pstDataType = null;
FormalTestManager.isPstData = false; FormalTestManager.isPstData = false;
FormalTestManager.isWaveCheck = false; FormalTestManager.isWaveCheck = false;
FormalTestManager.isXu = param.getPhaseCheck() == 1 ? true : false;
// FormalTestManager.isXu = true;
FormalTestManager.nonWaveDataSourceEnum = null; FormalTestManager.nonWaveDataSourceEnum = null;
DetectionServiceImpl.vAndIResultMap = new HashMap<>();
String[] datasourceIds = FormalTestManager.currentTestPlan.getDatasourceId().split(","); String[] datasourceIds = FormalTestManager.currentTestPlan.getDatasourceId().split(",");
for (String datasourceId : datasourceIds) { for (String datasourceId : datasourceIds) {
@@ -219,7 +230,13 @@ public class SocketContrastResponseService {
FormalTestManager.isRemoveSocket = false; FormalTestManager.isRemoveSocket = false;
FormalTestManager.waveCheckFlag = false; FormalTestManager.waveCheckFlag = false;
FormalTestManager.scheduler = null; FormalTestManager.scheduler = null;
FormalTestManager.scheduledFuture = null; if (FormalTestManager.scheduledFuture != null) {
FormalTestManager.scheduledFuture.cancel(true);
if (FormalTestManager.scheduler != null) {
FormalTestManager.scheduler.shutdown();
}
FormalTestManager.scheduledFuture = null;
}
HashBiMap<String, String> hashBiMap = HashBiMap.create(param.getPairs()); HashBiMap<String, String> hashBiMap = HashBiMap.create(param.getPairs());
FormalTestManager.pairsIdMap.clear(); FormalTestManager.pairsIdMap.clear();
@@ -369,6 +386,10 @@ public class SocketContrastResponseService {
case RECORD_WAVE_STEP1: case RECORD_WAVE_STEP1:
this.recordWave(param, socketDataMsg); this.recordWave(param, socketDataMsg);
break; break;
//系数校验
case Coefficient_Check:
this.coefficient(param, socketDataMsg);
break;
//退出关闭 //退出关闭
case QUITE: case QUITE:
quitDeal(socketDataMsg, param); quitDeal(socketDataMsg, param);
@@ -716,9 +737,14 @@ public class SocketContrastResponseService {
} else if (FormalTestManager.isWaveCheck) { } else if (FormalTestManager.isWaveCheck) {
System.out.println("(仅有录波)模型一致性校验成功!》》》》》》》》》》》》》》》》》》》》》》》》》》》开始相序校验》》》》》》》》》》》》》》》》》》》》》》》》》》》"); System.out.println("(仅有录波)模型一致性校验成功!》》》》》》》》》》》》》》》》》》》》》》》》》》》开始相序校验》》》》》》》》》》》》》》》》》》》》》》》》》》》");
this.sendXu(s); if (FormalTestManager.isXu) {
this.resetTimer(); this.sendXu(s);
FormalTestManager.currentStep = SourceOperateCodeEnum.YJC_XUJY; this.resetTimer();
FormalTestManager.currentStep = SourceOperateCodeEnum.YJC_XUJY;
} else {
System.out.println("跳过相序校验!");
this.sendFormalTest(s, param, requestOperateCode, quitOperateCode);
}
} }
} }
} }
@@ -909,9 +935,14 @@ public class SocketContrastResponseService {
this.clearData(); this.clearData();
System.out.println("数据对齐校验成功!》》》》》》》》》》》》》》》》》》》》》》》》》》》》》开始相序校验》》》》》》》》》》》》》》》》"); if (FormalTestManager.isXu) {
this.sendXu(s); System.out.println("数据对齐校验成功!》》》》》》》》》》》》》》》》》》》》》》》》》》》》》开始相序校验》》》》》》》》》》》》》》》》");
FormalTestManager.currentStep = SourceOperateCodeEnum.YJC_XUJY; this.sendXu(s);
FormalTestManager.currentStep = SourceOperateCodeEnum.YJC_XUJY;
} else {
System.out.println("跳过相序校验!");
this.sendFormalTest(s, param, requestOperateCode, quitOperateCode);
}
this.resetTimer(); this.resetTimer();
} }
} }
@@ -1035,60 +1066,7 @@ public class SocketContrastResponseService {
webSend.setCode(SourceResponseCodeEnum.ALL_SUCCESS.getCode());//最终成功推送 webSend.setCode(SourceResponseCodeEnum.ALL_SUCCESS.getCode());//最终成功推送
WebServiceManager.sendMsg(param.getUserPageId(), JSON.toJSONString(webSend)); WebServiceManager.sendMsg(param.getUserPageId(), JSON.toJSONString(webSend));
// 后续做正式检测 this.sendFormalTest(s, param, requestOperateCode, quitOperateCode);
if (param.getTestItemList().get(2)) {
System.out.println("相序校验成功!》》》》》》》》》》》》》》》》》》》》》》》》》》》》》开始正式检测》》》》》》》》》》》》》》》》");
if (ObjectUtil.isNotNull(FormalTestManager.nonWaveDataSourceEnum)) {
SocketMsg<String> socketMsg = new SocketMsg<>();
socketMsg.setRequestId(SourceOperateCodeEnum.FORMAL_REAL.getValue());
socketMsg.setOperateCode(requestOperateCode.getValue());
DevPhaseSequenceParam phaseSequenceParam = new DevPhaseSequenceParam();
phaseSequenceParam.setMoniterIdList(Arrays.asList(FormalTestManager.monitorMap.keySet().toArray(new String[FormalTestManager.monitorMap.size()])));
List<String> allDataType = this.getAllDataType();
FormalTestManager.pstDataType = new ArrayList<>();
if (allDataType.contains(DetectionCodeEnum.AVG_PREFIX.getCode() + DetectionCodeEnum.PST.getCode())) {
FormalTestManager.pstDataType.add(DetectionCodeEnum.AVG_PREFIX.getCode() + DetectionCodeEnum.PST.getCode());
allDataType.remove(DetectionCodeEnum.AVG_PREFIX.getCode() + DetectionCodeEnum.PST.getCode());
}
if (CollUtil.isNotEmpty(allDataType)) {
phaseSequenceParam.setDataType(allDataType);
} else {
if (CollUtil.isNotEmpty(FormalTestManager.pstDataType)) {
FormalTestManager.isPstData = true;
socketMsg.setOperateCode(SourceOperateCodeEnum.DEV_DATA_REQUEST_01.getValue());
phaseSequenceParam.setDataType(FormalTestManager.pstDataType);
}
}
phaseSequenceParam.setReadCount(this.getReadCount(this.getTargetCount()));
phaseSequenceParam.setIgnoreCount(0);
socketMsg.setData(JSON.toJSONString(phaseSequenceParam));
FormalTestManager.currentStep = SourceOperateCodeEnum.FORMAL_REAL;
SocketManager.sendMsg(s, JSON.toJSONString(socketMsg));
this.resetTimer();
checkResult = false;
} else if (FormalTestManager.isWaveCheck) {
if (FormalTestManager.statisticsProtocol && quitOperateCode == SourceOperateCodeEnum.QUIT_INIT_02) {
CnSocketUtil.contrastSendquit(param.getUserPageId(), SourceOperateCodeEnum.QUIT_INIT_01, false);
}
// 录波数据
CnSocketUtil.contrastSendquit(param.getUserPageId(), quitOperateCode, false);
successComm.clear();
failComm.clear();
FormalTestManager.currentStep = SourceOperateCodeEnum.RECORD_WAVE_STEP1;
// 发送录波指令
this.sendRecordWave(s);
}
} else {
if (FormalTestManager.statisticsProtocol && quitOperateCode == SourceOperateCodeEnum.QUIT_INIT_02) {
CnSocketUtil.contrastSendquit(param.getUserPageId(), SourceOperateCodeEnum.QUIT_INIT_01, false);
}
if (FormalTestManager.voltageProtocol) {
CnSocketUtil.contrastSendquit(param.getUserPageId(), SourceOperateCodeEnum.QUIT_INIT_03, false);
}
CnSocketUtil.contrastSendquit(param.getUserPageId(), quitOperateCode, false);
FormalTestManager.isTesting = false;
}
} }
} else if (successComm.size() == FormalTestManager.monitorMap.size()) { } else if (successComm.size() == FormalTestManager.monitorMap.size()) {
this.clearData(); this.clearData();
@@ -1174,6 +1152,63 @@ public class SocketContrastResponseService {
} }
} }
private void sendFormalTest(String s, PreDetectionParam param, SourceOperateCodeEnum requestOperateCode, SourceOperateCodeEnum quitOperateCode) {
// 后续做正式检测
if (param.getTestItemList().get(2)) {
System.out.println("开始正式检测!");
if (ObjectUtil.isNotNull(FormalTestManager.nonWaveDataSourceEnum)) {
SocketMsg<String> socketMsg = new SocketMsg<>();
socketMsg.setRequestId(SourceOperateCodeEnum.FORMAL_REAL.getValue());
socketMsg.setOperateCode(requestOperateCode.getValue());
DevPhaseSequenceParam phaseSequenceParam = new DevPhaseSequenceParam();
phaseSequenceParam.setMoniterIdList(Arrays.asList(FormalTestManager.monitorMap.keySet().toArray(new String[FormalTestManager.monitorMap.size()])));
List<String> allDataType = this.getAllDataType();
FormalTestManager.pstDataType = new ArrayList<>();
if (allDataType.contains(DetectionCodeEnum.AVG_PREFIX.getCode() + DetectionCodeEnum.PST.getCode())) {
FormalTestManager.pstDataType.add(DetectionCodeEnum.AVG_PREFIX.getCode() + DetectionCodeEnum.PST.getCode());
allDataType.remove(DetectionCodeEnum.AVG_PREFIX.getCode() + DetectionCodeEnum.PST.getCode());
}
if (CollUtil.isNotEmpty(allDataType)) {
phaseSequenceParam.setDataType(allDataType);
} else {
if (CollUtil.isNotEmpty(FormalTestManager.pstDataType)) {
FormalTestManager.isPstData = true;
socketMsg.setOperateCode(SourceOperateCodeEnum.DEV_DATA_REQUEST_01.getValue());
phaseSequenceParam.setDataType(FormalTestManager.pstDataType);
}
}
phaseSequenceParam.setReadCount(this.getReadCount(this.getTargetCount()));
phaseSequenceParam.setIgnoreCount(0);
socketMsg.setData(JSON.toJSONString(phaseSequenceParam));
FormalTestManager.currentStep = SourceOperateCodeEnum.FORMAL_REAL;
SocketManager.sendMsg(s, JSON.toJSONString(socketMsg));
this.resetTimer();
checkResult = false;
} else if (FormalTestManager.isWaveCheck) {
if (FormalTestManager.statisticsProtocol && quitOperateCode == SourceOperateCodeEnum.QUIT_INIT_02) {
CnSocketUtil.contrastSendquit(param.getUserPageId(), SourceOperateCodeEnum.QUIT_INIT_01, false);
}
// 录波数据
CnSocketUtil.contrastSendquit(param.getUserPageId(), quitOperateCode, false);
successComm.clear();
failComm.clear();
FormalTestManager.currentStep = SourceOperateCodeEnum.RECORD_WAVE_STEP1;
// 发送录波指令
this.sendRecordWave(s);
}
} else {
if (FormalTestManager.statisticsProtocol && quitOperateCode == SourceOperateCodeEnum.QUIT_INIT_02) {
CnSocketUtil.contrastSendquit(param.getUserPageId(), SourceOperateCodeEnum.QUIT_INIT_01, false);
}
if (FormalTestManager.voltageProtocol) {
CnSocketUtil.contrastSendquit(param.getUserPageId(), SourceOperateCodeEnum.QUIT_INIT_03, false);
}
CnSocketUtil.contrastSendquit(param.getUserPageId(), quitOperateCode, false);
FormalTestManager.isTesting = false;
}
}
/** /**
* 正式检测 * 正式检测
* *
@@ -1208,39 +1243,6 @@ public class SocketContrastResponseService {
} }
} }
this.setScheduler(targetCount, param.getUserPageId(), requestOperateCode, quitOperateCode); this.setScheduler(targetCount, param.getUserPageId(), requestOperateCode, quitOperateCode);
// if (Objects.isNull(FormalTestManager.scheduler)) {
// FormalTestManager.scheduler = Executors.newScheduledThreadPool(1);
// long delay = this.getDelay(targetCount);
// FormalTestManager.scheduledFuture = FormalTestManager.scheduler.schedule(() -> {
// if (!checkResult) {
// System.out.println("正式检测-" + delay + "s内收集数据不完整");
// // 断开与设备的连接,但是不要将Socket移除
// if (FormalTestManager.statisticsProtocol && quitOperateCode == SourceOperateCodeEnum.QUIT_INIT_02) {
// CnSocketUtil.contrastSendquit(param.getUserPageId(), SourceOperateCodeEnum.QUIT_INIT_01, false);
// }
// if (FormalTestManager.voltageProtocol) {
// CnSocketUtil.contrastSendquit(param.getUserPageId(), SourceOperateCodeEnum.QUIT_INIT_03, false);
// }
// CnSocketUtil.contrastSendquit(param.getUserPageId(), quitOperateCode, false);
// FormalTestManager.isTesting = false;
//
// this.clearData();
//
// Collection<String> disjunction = CollectionUtil.disjunction(FormalTestManager.pairsIpMap.keySet(), successPair.keySet());
// // 向前端推送收集数据不完整的配对项
// for (String key : disjunction) {
// webSend.setCode(SourceResponseCodeEnum.FAIL.getCode());
// webSend.setData(MsgUtil.getPairStr(key, FormalTestManager.pairsIpMap.inverse().get(key), FormalTestManager.devNameMapComm) + " 数据收集不完整!");
// WebServiceManager.sendMsg(param.getUserPageId(), JSON.toJSONString(webSend));
// }
// // 推送最终失败结果
// webSend.setCode(SourceResponseCodeEnum.ALL_FAIL.getCode());//最终错误推送
// WebServiceManager.sendMsg(param.getUserPageId(), JSON.toJSONString(webSend));
// }
// FormalTestManager.scheduler.shutdown();
// FormalTestManager.scheduler = null;
// }, delay, TimeUnit.SECONDS);
// }
String monitorId1 = devData.getId(); String monitorId1 = devData.getId();
String devMonitorId = monitorId1; String devMonitorId = monitorId1;
@@ -1416,6 +1418,28 @@ public class SocketContrastResponseService {
pqDevService.updateResult(id1.split(CnSocketUtil.SPLIT_TAG)[0], param.getUserId()); pqDevService.updateResult(id1.split(CnSocketUtil.SPLIT_TAG)[0], param.getUserId());
}); });
FormalTestManager.isTesting = false; FormalTestManager.isTesting = false;
if (CollUtil.isNotEmpty(DetectionServiceImpl.vAndIResultMap)) {
// 是否进行系数校准
//万一录波了这里就进不来了但是在误差处理的时候DetectionServiceImpl.vAndIResultMap该集合会保留不符合的结果
XiNumberManager.xiDevList.clear();
XiNumberManager.devXiNumDataMap.clear();
List<String> stdIpList = DetectionServiceImpl.vAndIResultMap.values().stream().map(DetectionServiceImpl.VAndIResult::getIp).collect(Collectors.toList());
XiNumberManager.xiDevList = FormalTestManager.standardDevList.stream().filter(d -> stdIpList.contains(d.getDevIP())).collect(Collectors.toList());
// 逐一设备向通讯模块要原始系数
SocketMsg<String> socketMsg = new SocketMsg<>();
socketMsg.setRequestId(SourceOperateCodeEnum.Coefficient_Check.getValue());
socketMsg.setOperateCode(SourceOperateCodeEnum.DATA_CHNFACTOR$01.getValue());
PreDetection preDetection = XiNumberManager.xiDevList.get(0);
Map<String, Object> map = new HashMap<>();
map.put("devIP", preDetection.getDevIP());
map.put("chnNum", preDetection.getDevChns());
socketMsg.setData(JSON.toJSONString(map));
SocketManager.sendMsg(param.getUserPageId() + CnSocketUtil.CONTRAST_DEV_TAG, JSON.toJSONString(socketMsg));
FormalTestManager.currentStep = SourceOperateCodeEnum.Coefficient_Check;
}
} }
} else { } else {
// 配对关系入库 // 配对关系入库
@@ -1693,6 +1717,160 @@ public class SocketContrastResponseService {
} }
} }
private void coefficient(PreDetectionParam param, SocketDataMsg socketDataMsg) {
SourceOperateCodeEnum sourceOperateCodeEnum = SourceOperateCodeEnum.getDictDataEnumByCode(socketDataMsg.getOperateCode());
SourceResponseCodeEnum dictDataEnumByCode = SourceResponseCodeEnum.getDictDataEnumByCode(socketDataMsg.getCode());
SocketMsg<String> xiSocket = new SocketMsg<>();
xiSocket.setRequestId(SourceOperateCodeEnum.Coefficient_Check.getValue());
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();
String ip = XiNumberManager.xiDevList.get(0).getDevIP();
devXiNumData.setDevIP(ip);
//String stdMonitorId = DetectionServiceImpl.vAndIResultMap.keySet().stream().filter(key -> key.contains(ip)).findFirst().get();
List<PqStandardDevGain> pqStandardDevGainList = new ArrayList<>();
List<PqStandardDevGainRecord> recordList = new ArrayList<>();
for (int i = 0; i < gfList.size(); i++) {
DevXiNumData.GF gf = gfList.get(i);
String stdDevMonitorId = FormalTestManager.devIdMapComm.get(ip) + CnSocketUtil.SPLIT_TAG + (gf.getUMonitorPoint() + 1);
String devMonitorId = FormalTestManager.pairsIdMap.inverse().get(stdDevMonitorId);
PqStandardDevGain pqStandardDevGain = new PqStandardDevGain();
pqStandardDevGain.setStdDevMonitorId(stdDevMonitorId);
DevXiNumData.F f = gf.getF();
pqStandardDevGain.setUaGain(f.getUa_gain());
pqStandardDevGain.setUbGain(f.getUb_gain());
pqStandardDevGain.setUcGain(f.getUc_gain());
pqStandardDevGain.setU0Gain(f.getU0_gain());
pqStandardDevGain.setIaGain(f.getIa_gain());
pqStandardDevGain.setIbGain(f.getIb_gain());
pqStandardDevGain.setIcGain(f.getIc_gain());
pqStandardDevGain.setI0Gain(f.getI0_gain());
pqStandardDevGain.setUabGain(f.getUab_gain());
pqStandardDevGain.setUbcGain(f.getUbc_gain());
pqStandardDevGain.setUcaGain(f.getUca_gain());
pqStandardDevGain.setState(DataStateEnum.ENABLE.getCode());
pqStandardDevGainList.add(pqStandardDevGain);
DetectionServiceImpl.VAndIResult vAndIResult = DetectionServiceImpl.vAndIResultMap.get(ip + CnSocketUtil.SPLIT_TAG + (gf.getUMonitorPoint() + 1));
if (ObjectUtil.isNotNull(vAndIResult)) {
int maxNum = pqStandardDevGainRecordService.getMaxNum(stdDevMonitorId, devMonitorId);
PqStandardDevGainRecord record = new PqStandardDevGainRecord();
record.setStdDevMonitorId(stdDevMonitorId);
record.setDevMonitorId(devMonitorId);
record.setNum(maxNum + 1);
recordList.add(record);
updateGfList(f, vAndIResult, stdDevMonitorId, maxNum);
}
}
xiSocket.setOperateCode(SourceOperateCodeEnum.DATA_CHNFACTOR$02.getValue());
devXiNumData.setGf(gfList);
xiSocket.setData(JSON.toJSONString(devXiNumData));
SocketManager.sendMsg(param.getUserPageId() + CnSocketUtil.CONTRAST_DEV_TAG, JSON.toJSONString(xiSocket));
// 原始系数入库
pqStandardDevGainService.add(pqStandardDevGainList);
pqStandardDevGainRecordService.addOrUpdate(recordList);
}
break;
case UNPROCESSED_BUSINESS:
break;
case NORMAL_RESPONSE:
break;
case DATA_RESOLVE:
break;
case COMMUNICATION_ERR:
break;
default:
break;
}
break;
case DATA_CHNFACTOR$02:
//系数下发后的响应
switch (Objects.requireNonNull(dictDataEnumByCode)) {
case SUCCESS:
//单台装置系数下发后,需要删除集合中存在的当前装置
XiNumberManager.xiDevList.remove(0);
//继续下发每台装置系数,只到集合为空
if (CollUtil.isNotEmpty(XiNumberManager.xiDevList)) {
xiSocket.setOperateCode(SourceOperateCodeEnum.DATA_CHNFACTOR$01.getValue());
xiSocket.setData(JSON.toJSONString(XiNumberManager.devXiNumDataMap.get(XiNumberManager.xiDevList.get(0))));
PreDetection preDetection = XiNumberManager.xiDevList.get(0);
Map<String, Object> map = new HashMap<>();
map.put("devIP", preDetection.getDevIP());
map.put("chnNum", preDetection.getDevChns());
xiSocket.setData(JSON.toJSONString(map));
SocketManager.sendMsg(param.getUserPageId() + CnSocketUtil.CONTRAST_DEV_TAG, JSON.toJSONString(xiSocket));
} else {
//{"requestId":"Coefficient_Check","operateCode":"DATA_CHNFACTOR$02","data":"end","code":10200}
// 通知前端全部下发系数完成
}
break;
case UNPROCESSED_BUSINESS:
break;
case NORMAL_RESPONSE:
break;
case DATA_RESOLVE:
//quitSend(param);
break;
case COMMUNICATION_ERR:
break;
default:
break;
}
break;
// case DEV_DATA_REQUEST_02:
// //实时采集申请
// String data = socketDataMsg.getData();
// DevData devData = JSON.parseObject(data, DevData.class);
// if (ObjectUtil.isNotNull(dictDataEnumByCode)) {
// switch (dictDataEnumByCode) {
// case SUCCESS:
// if (devData.getResult()) {
// FormalTestManager.realDataXiList.add(devData);
// successComm.add(devData.getId());
// System.out.println(successComm.size() + " ==" + FormalTestManager.monitorIdListComm.size() + "FormalTestManager.realDataXiList:" + FormalTestManager.realDataXiList.size() + "当前步骤" + XiNumberManager.stepNumber);
// if (successComm.size() == FormalTestManager.monitorIdListComm.size()) {
// processData(param, xiSocket);
// }
// } else {
// System.out.println("系数校准抛除数据" + devData);
// }
// break;
// case UNPROCESSED_BUSINESS:
// WebServiceManager.sendMsg(param.getUserPageId(), JSON.toJSONString(socketDataMsg));
// break;
// case NORMAL_RESPONSE:
// if (devData.getResult()) {
// FormalTestManager.realDataXiList.add(devData);
// } else {
// System.out.println("系数校准抛除数据" + devData);
// }
// break;
// default:
// xiSocket.setRequestId(socketDataMsg.getRequestId());
// xiSocket.setOperateCode(socketDataMsg.getOperateCode());
// xiSocket.setData(dictDataEnumByCode.getMessage());
// WebServiceManager.sendMsg(param.getUserPageId(), JSON.toJSONString(xiSocket));
// break;
// }
// }
// break;
default:
WebServiceManager.sendUnknownErrorMessage(param.getUserPageId());
break;
}
}
/** /**
* 退出检测返回 * 退出检测返回
@@ -1867,13 +2045,13 @@ public class SocketContrastResponseService {
*/ */
private Integer getTargetCount() { private Integer getTargetCount() {
if (FormalTestManager.isPstData) { if (FormalTestManager.isPstData) {
return FormalTestManager.curretntTestPlanConfig.getFlicker(); return FormalTestManager.curretntTestPlanConfig.getFlicker() * 2;
} }
if (ObjectUtil.isNotNull(FormalTestManager.nonWaveDataSourceEnum)) { if (ObjectUtil.isNotNull(FormalTestManager.nonWaveDataSourceEnum)) {
if (FormalTestManager.nonWaveDataSourceEnum == DataSourceEnum.REAL_DATA) { if (FormalTestManager.nonWaveDataSourceEnum == DataSourceEnum.REAL_DATA) {
return FormalTestManager.curretntTestPlanConfig.getRealTime(); return FormalTestManager.curretntTestPlanConfig.getRealTime() * 2;
} else { } else {
return FormalTestManager.curretntTestPlanConfig.getStatistics(); return FormalTestManager.curretntTestPlanConfig.getStatistics() * 2;
} }
} }
return -1; return -1;
@@ -1959,8 +2137,13 @@ public class SocketContrastResponseService {
isStar = true; isStar = true;
isDelta = false; isDelta = false;
} else { } else {
isStar = false; if (DetectionCodeEnum.STAR.getCode().equals(monitorListDTO.getConnection())) {
isDelta = true; isStar = true;
isDelta = false;
} else {
isStar = false;
isDelta = true;
}
} }
} }
@@ -2063,8 +2246,13 @@ public class SocketContrastResponseService {
isStar = true; isStar = true;
isDelta = false; isDelta = false;
} else { } else {
isStar = false; if (DetectionCodeEnum.STAR.getCode().equals(monitorListDTO.getConnection())) {
isDelta = true; isStar = true;
isDelta = false;
} else {
isStar = false;
isDelta = true;
}
} }
} }
@@ -2127,7 +2315,7 @@ public class SocketContrastResponseService {
}); });
}); });
ExcelUtil.saveExcel(alignDataFilePath, "实时数据.xlsx", sheetsList); ExcelUtil.saveExcel(pathConfig.getDataPath(), "对齐数据.xlsx", sheetsList);
} }
/** /**
@@ -2284,8 +2472,13 @@ public class SocketContrastResponseService {
isStar = true; isStar = true;
isDelta = false; isDelta = false;
} else { } else {
isStar = false; if (DetectionCodeEnum.STAR.getCode().equals(monitorListDTO.getConnection())) {
isDelta = true; isStar = true;
isDelta = false;
} else {
isStar = false;
isDelta = true;
}
} }
} }
@@ -2603,18 +2796,30 @@ public class SocketContrastResponseService {
devInfo = pqDevService.getDevInfo(Collections.singletonList(devId)); devInfo = pqDevService.getDevInfo(Collections.singletonList(devId));
} }
Integer usePhaseIndex = devInfo.get(0).getUsePhaseIndex(); Integer usePhaseIndex = devInfo.get(0).getUsePhaseIndex();
List<String> allDesc = data.getSqlData().stream().map(x -> x.getDesc()).collect(Collectors.toList()); List<String> allDesc = data.getSqlData().stream().map(x -> x.getDesc()).collect(Collectors.toList());
allDesc.addAll(data.getSqlDataHarm().stream().map(x -> x.getDesc()).collect(Collectors.toList())); allDesc.addAll(data.getSqlDataHarm().stream().map(x -> x.getDesc()).collect(Collectors.toList()));
String bzDevId = devId;
if (isStdDev) {
String s = FormalTestManager.pairsIdMap.inverse().get(devId + CnSocketUtil.SPLIT_TAG + splitArr[1]);
bzDevId = s.split(CnSocketUtil.SPLIT_TAG)[0];
}
PqMonitor monitor = pqMonitorService.getByDevIdAndNum(bzDevId, Integer.parseInt(splitArr[1]));
DictData dictData = dictDataService.getById(monitor.getConnection());
for (DevData.SqlDataDTO sqlDataDTO : data.getSqlData()) { for (DevData.SqlDataDTO sqlDataDTO : data.getSqlData()) {
if (usePhaseIndex.equals(1)) { if (usePhaseIndex.equals(1)) {
if (DetectionCodeEnum.PVRMS.getCode().equals(sqlDataDTO.getDesc()) || DetectionCodeEnum.PU1.getCode().equals(sqlDataDTO.getDesc())) { if (DetectionCodeEnum.PVRMS.getCode().equals(sqlDataDTO.getDesc()) || DetectionCodeEnum.PU1.getCode().equals(sqlDataDTO.getDesc())) {
continue; continue;
} }
} else { } else {
if (DetectionCodeEnum.VRMS.getCode().equals(sqlDataDTO.getDesc()) || DetectionCodeEnum.U1.getCode().equals(sqlDataDTO.getDesc())) { if (DetectionCodeEnum.STAR.getCode().equals(dictData.getCode())) {
continue; if (DetectionCodeEnum.PVRMS.getCode().equals(sqlDataDTO.getDesc()) || DetectionCodeEnum.PU1.getCode().equals(sqlDataDTO.getDesc())) {
continue;
}
} else {
if ((DetectionCodeEnum.VRMS.getCode().equals(sqlDataDTO.getDesc()) || DetectionCodeEnum.U1.getCode().equals(sqlDataDTO.getDesc()))) {
continue;
}
} }
} }
@@ -2662,8 +2867,14 @@ public class SocketContrastResponseService {
continue; continue;
} }
} else { } else {
if (DetectionCodeEnum.V2_50.getCode().equals(sqlDataDTO.getDesc()) || DetectionCodeEnum.SV_1_49.getCode().equals(sqlDataDTO.getDesc())) { if (DetectionCodeEnum.STAR.getCode().equals(dictData.getCode())) {
continue; if (DetectionCodeEnum.PV2_50.getCode().equals(sqlDataDTO.getDesc()) || DetectionCodeEnum.PSV_1_49.getCode().equals(sqlDataDTO.getDesc())) {
continue;
}
} else {
if (DetectionCodeEnum.V2_50.getCode().equals(sqlDataDTO.getDesc()) || DetectionCodeEnum.SV_1_49.getCode().equals(sqlDataDTO.getDesc())) {
continue;
}
} }
} }
@@ -3300,4 +3511,46 @@ public class SocketContrastResponseService {
devData.setSqlDataHarm(sqlDataHarmDTOS); devData.setSqlDataHarm(sqlDataHarmDTOS);
return devData; return devData;
} }
/**
* 修改通道系数
*
* @param f
*/
private void updateGfList(DevXiNumData.F f, DetectionServiceImpl.VAndIResult vAndIResult, String stdDevMonitorId, int maxNum) {
DevXiNumData.F originF = BeanUtil.copyProperties(f, DevXiNumData.F.class);
if (maxNum != 0) {
PqStandardDevGain pqStandardDevGain = pqStandardDevGainService.get(stdDevMonitorId);
originF.setUa_gain(pqStandardDevGain.getUaGain());
originF.setUb_gain(pqStandardDevGain.getUbGain());
originF.setUc_gain(pqStandardDevGain.getUcGain());
originF.setU0_gain(pqStandardDevGain.getU0Gain());
originF.setIa_gain(pqStandardDevGain.getIaGain());
originF.setIb_gain(pqStandardDevGain.getIbGain());
originF.setIc_gain(pqStandardDevGain.getIcGain());
originF.setI0_gain(pqStandardDevGain.getI0Gain());
originF.setUab_gain(pqStandardDevGain.getUabGain());
originF.setUbc_gain(pqStandardDevGain.getUbcGain());
originF.setUca_gain(pqStandardDevGain.getUcaGain());
}
if (vAndIResult.getVa() && NumberUtil.isIn(BigDecimal.valueOf(vAndIResult.getVaXi() * 10000), BigDecimal.valueOf(originF.getUa_gain() * 0.95), BigDecimal.valueOf(originF.getUa_gain() * 1.05))) {
f.setUa_gain(BigDecimal.valueOf(f.getUa_gain()).multiply(BigDecimal.valueOf(vAndIResult.getVaXi())).setScale(0, RoundingMode.HALF_UP).intValue());
}
if (vAndIResult.getVb() && NumberUtil.isIn(BigDecimal.valueOf(vAndIResult.getVbXi() * 10000), BigDecimal.valueOf(originF.getUb_gain() * 0.95), BigDecimal.valueOf(originF.getUb_gain() * 1.05))) {
f.setUb_gain(BigDecimal.valueOf(f.getUb_gain()).multiply(BigDecimal.valueOf(vAndIResult.getVbXi())).setScale(0, RoundingMode.HALF_UP).intValue());
}
if (vAndIResult.getVc() && NumberUtil.isIn(BigDecimal.valueOf(vAndIResult.getVcXi() * 10000), BigDecimal.valueOf(originF.getUc_gain() * 0.95), BigDecimal.valueOf(originF.getUc_gain() * 1.05))) {
f.setUc_gain(BigDecimal.valueOf(f.getUc_gain()).multiply(BigDecimal.valueOf(vAndIResult.getVcXi())).setScale(0, RoundingMode.HALF_UP).intValue());
}
if (vAndIResult.getIa() && NumberUtil.isIn(BigDecimal.valueOf(vAndIResult.getIaXi() * 10000), BigDecimal.valueOf(originF.getIa_gain() * 0.95), BigDecimal.valueOf(originF.getIa_gain() * 1.05))) {
f.setIa_gain(BigDecimal.valueOf(f.getIa_gain()).multiply(BigDecimal.valueOf(vAndIResult.getIaXi())).setScale(0, RoundingMode.HALF_UP).intValue());
}
if (vAndIResult.getIb() && NumberUtil.isIn(BigDecimal.valueOf(vAndIResult.getIbXi() * 10000), BigDecimal.valueOf(originF.getIb_gain() * 0.95), BigDecimal.valueOf(originF.getIb_gain() * 1.05))) {
f.setIb_gain(BigDecimal.valueOf(f.getIb_gain()).multiply(BigDecimal.valueOf(vAndIResult.getIbXi())).setScale(0, RoundingMode.HALF_UP).intValue());
}
if (vAndIResult.getIc() && NumberUtil.isIn(BigDecimal.valueOf(vAndIResult.getIcXi() * 10000), BigDecimal.valueOf(originF.getIc_gain() * 0.95), BigDecimal.valueOf(originF.getIc_gain() * 1.05))) {
f.setIc_gain(BigDecimal.valueOf(f.getIc_gain()).multiply(BigDecimal.valueOf(vAndIResult.getIcXi())).setScale(0, RoundingMode.HALF_UP).intValue());
}
}
} }

View File

@@ -6,6 +6,7 @@ import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.njcn.gather.detection.lock.DetectionLockManager;
import com.njcn.gather.detection.pojo.dto.DevXiNumData; import com.njcn.gather.detection.pojo.dto.DevXiNumData;
import com.njcn.gather.detection.pojo.enums.DetectionCodeEnum; import com.njcn.gather.detection.pojo.enums.DetectionCodeEnum;
import com.njcn.gather.detection.pojo.enums.SourceOperateCodeEnum; import com.njcn.gather.detection.pojo.enums.SourceOperateCodeEnum;
@@ -33,6 +34,7 @@ import com.njcn.gather.script.pojo.param.PqScriptIssueParam;
import com.njcn.gather.script.pojo.po.SourceIssue; import com.njcn.gather.script.pojo.po.SourceIssue;
import com.njcn.gather.script.service.IPqScriptCheckDataService; import com.njcn.gather.script.service.IPqScriptCheckDataService;
import com.njcn.gather.script.service.IPqScriptDtlsService; import com.njcn.gather.script.service.IPqScriptDtlsService;
import com.njcn.gather.source.service.IPqSourceService;
import com.njcn.gather.storage.pojo.param.StorageParam; import com.njcn.gather.storage.pojo.param.StorageParam;
import com.njcn.gather.storage.pojo.po.SimAndDigHarmonicResult; import com.njcn.gather.storage.pojo.po.SimAndDigHarmonicResult;
import com.njcn.gather.storage.pojo.po.SimAndDigNonHarmonicResult; import com.njcn.gather.storage.pojo.po.SimAndDigNonHarmonicResult;
@@ -76,6 +78,7 @@ public class SocketDevResponseService {
private final SimAndDigHarmonicService adHarmonicService; private final SimAndDigHarmonicService adHarmonicService;
private final IAdPlanService adPlanService; private final IAdPlanService adPlanService;
private final IDictDataService dictDataService; private final IDictDataService dictDataService;
private final IPqSourceService pqSourceService;
/** /**
* 存储的装置相序数据 * 存储的装置相序数据
@@ -391,6 +394,7 @@ public class SocketDevResponseService {
if (param.getTestItemList().get(2)) { if (param.getTestItemList().get(2)) {
//如果后续做正式检测 //如果后续做正式检测
PqScriptIssueParam issueParam = new PqScriptIssueParam(); PqScriptIssueParam issueParam = new PqScriptIssueParam();
issueParam.setSourceId(param.getSourceName());
issueParam.setPlanId(param.getPlanId()); issueParam.setPlanId(param.getPlanId());
issueParam.setSourceId(param.getSourceId()); issueParam.setSourceId(param.getSourceId());
issueParam.setDevIds(param.getDevIds()); issueParam.setDevIds(param.getDevIds());
@@ -439,6 +443,7 @@ public class SocketDevResponseService {
//告诉前端当前项开始了 //告诉前端当前项开始了
WebSocketVO<Object> webSocketVO = new WebSocketVO<>(); WebSocketVO<Object> webSocketVO = new WebSocketVO<>();
FormalTestManager.currentIssue = sourceIssues.get(0);
String type = sourceIssues.get(0).getType(); String type = sourceIssues.get(0).getType();
if (ResultUnitEnum.P.getCode().equals(type)) { if (ResultUnitEnum.P.getCode().equals(type)) {
sourceIssues.get(0).setType(ResultUnitEnum.V_ABSOLUTELY.getCode()); sourceIssues.get(0).setType(ResultUnitEnum.V_ABSOLUTELY.getCode());
@@ -612,7 +617,7 @@ public class SocketDevResponseService {
private void assemblyEntity(List<DevData> deList, DevXiNumData.F F, DevXiNumData.GF startF, CoefficientVO coefficientVO, CoefficientVO.DevParameter devParameter) { private void assemblyEntity(List<DevData> deList, DevXiNumData.F F, DevXiNumData.GF startF, CoefficientVO coefficientVO, CoefficientVO.DevParameter devParameter) {
//表示接收完成,必须保证3个数 //表示接收完成,必须保证3个数
if (deList.size() >= 3) { if (deList.size() >= 7) {
List<Double> aList = deList.stream().map(it -> it.getSqlData().get(0).getList().getA()).collect(Collectors.toList()); List<Double> aList = deList.stream().map(it -> it.getSqlData().get(0).getList().getA()).collect(Collectors.toList());
List<Double> bList = deList.stream().map(it -> it.getSqlData().get(0).getList().getB()).collect(Collectors.toList()); List<Double> bList = deList.stream().map(it -> it.getSqlData().get(0).getList().getB()).collect(Collectors.toList());
List<Double> cList = deList.stream().map(it -> it.getSqlData().get(0).getList().getC()).collect(Collectors.toList()); List<Double> cList = deList.stream().map(it -> it.getSqlData().get(0).getList().getC()).collect(Collectors.toList());
@@ -687,7 +692,7 @@ public class SocketDevResponseService {
*/ */
private Double reduceList(List<Double> valList) { private Double reduceList(List<Double> valList) {
// valList.subList(0, 5).clear(); // valList.subList(0, 5).clear();
// valList.subList(valList.size() - 3, valList.size() - 1).clear(); valList.subList(valList.size() - 2, valList.size()).clear();
return valList.stream().mapToDouble(Double::doubleValue).average().getAsDouble(); return valList.stream().mapToDouble(Double::doubleValue).average().getAsDouble();
} }
@@ -893,7 +898,7 @@ public class SocketDevResponseService {
//开始下源控制脚本 //开始下源控制脚本
PqScriptIssueParam issueParam = new PqScriptIssueParam(); PqScriptIssueParam issueParam = new PqScriptIssueParam();
issueParam.setPlanId(param.getPlanId()); issueParam.setPlanId(param.getPlanId());
issueParam.setSourceId(param.getSourceId()); issueParam.setSourceId(param.getSourceName());
issueParam.setDevIds(param.getDevIds()); issueParam.setDevIds(param.getDevIds());
issueParam.setScriptId(param.getScriptId()); issueParam.setScriptId(param.getScriptId());
@@ -953,6 +958,7 @@ public class SocketDevResponseService {
} else { } else {
webSocketVO.setRequestId(sourceIssues.get(0).getType() + CnSocketUtil.START_TAG); webSocketVO.setRequestId(sourceIssues.get(0).getType() + CnSocketUtil.START_TAG);
} }
FormalTestManager.currentIssue = sourceIssues.get(0);
socketMsg.setData(JSON.toJSONString(sourceIssues.get(0))); socketMsg.setData(JSON.toJSONString(sourceIssues.get(0)));
socketMsg.setRequestId(SourceOperateCodeEnum.FORMAL_REAL.getValue() + CnSocketUtil.STEP_TAG + type); socketMsg.setRequestId(SourceOperateCodeEnum.FORMAL_REAL.getValue() + CnSocketUtil.STEP_TAG + type);
socketMsg.setOperateCode(SourceOperateCodeEnum.OPER_GATHER.getValue()); socketMsg.setOperateCode(SourceOperateCodeEnum.OPER_GATHER.getValue());
@@ -1160,8 +1166,8 @@ public class SocketDevResponseService {
} else if (param.getTestItemList().get(2)) { } else if (param.getTestItemList().get(2)) {
// 后续做正式检测 // 后续做正式检测
PqScriptIssueParam issueParam = new PqScriptIssueParam(); PqScriptIssueParam issueParam = new PqScriptIssueParam();
issueParam.setSourceId(param.getSourceName());
issueParam.setPlanId(param.getPlanId()); issueParam.setPlanId(param.getPlanId());
issueParam.setSourceId(param.getSourceId());
issueParam.setDevIds(param.getDevIds()); issueParam.setDevIds(param.getDevIds());
issueParam.setScriptId(param.getScriptId()); issueParam.setScriptId(param.getScriptId());
@@ -1210,6 +1216,7 @@ public class SocketDevResponseService {
} else { } else {
webSocketVO.setRequestId(sourceIssues.get(0).getType() + CnSocketUtil.START_TAG); webSocketVO.setRequestId(sourceIssues.get(0).getType() + CnSocketUtil.START_TAG);
} }
FormalTestManager.currentIssue = sourceIssues.get(0);
socketMsg.setData(JSON.toJSONString(sourceIssues.get(0))); socketMsg.setData(JSON.toJSONString(sourceIssues.get(0)));
socketMsg.setRequestId(SourceOperateCodeEnum.FORMAL_REAL.getValue() + CnSocketUtil.STEP_TAG + type); socketMsg.setRequestId(SourceOperateCodeEnum.FORMAL_REAL.getValue() + CnSocketUtil.STEP_TAG + type);
socketMsg.setOperateCode(SourceOperateCodeEnum.OPER_GATHER.getValue()); socketMsg.setOperateCode(SourceOperateCodeEnum.OPER_GATHER.getValue());
@@ -1371,8 +1378,11 @@ public class SocketDevResponseService {
checkDataParam.setIsValueTypeName(false); checkDataParam.setIsValueTypeName(false);
List<String> valueType = iPqScriptCheckDataService.getValueType(checkDataParam); List<String> valueType = iPqScriptCheckDataService.getValueType(checkDataParam);
iPqDevService.updateResult(param.getDevIds(), valueType, param.getCode(), param.getUserId(), param.getTemperature(), param.getHumidity()); iPqDevService.updateResult(param.getDevIds(), valueType, param.getCode(), param.getUserId(), param.getTemperature(), param.getHumidity(), true);
CnSocketUtil.quitSend(param); CnSocketUtil.quitSend(param);
// 数模式检测全部小项完成 → 释放锁,避免用户必须点"停止"才能让出
DetectionLockManager.getInstance()
.releaseIfMatchPage(param.getUserPageId(), "DEV_TEST_FINISHED");
} }
successComm.clear(); successComm.clear();
FormalTestManager.realDataXiList.clear(); FormalTestManager.realDataXiList.clear();
@@ -1782,6 +1792,7 @@ public class SocketDevResponseService {
} else { } else {
dataRule = DictDataEnum.SECTION_VALUE; dataRule = DictDataEnum.SECTION_VALUE;
} }
FormalTestManager.currentTestPlan = plan;
String code = dictDataService.getDictDataById(plan.getPattern()).getCode(); String code = dictDataService.getDictDataById(plan.getPattern()).getCode();
FormalTestManager.patternEnum = PatternEnum.getEnum(code); FormalTestManager.patternEnum = PatternEnum.getEnum(code);
@@ -1812,8 +1823,8 @@ public class SocketDevResponseService {
XiNumberManager.devParameterList.add(devParameterSmall); XiNumberManager.devParameterList.add(devParameterSmall);
PqScriptIssueParam issueParam = new PqScriptIssueParam(); PqScriptIssueParam issueParam = new PqScriptIssueParam();
issueParam.setSourceId(param.getSourceName());
issueParam.setPlanId(param.getPlanId()); issueParam.setPlanId(param.getPlanId());
issueParam.setSourceId(param.getSourceId());
issueParam.setDevIds(param.getDevIds()); issueParam.setDevIds(param.getDevIds());
issueParam.setScriptId(param.getScriptId()); issueParam.setScriptId(param.getScriptId());
issueParam.setIsPhaseSequence(CommonEnum.COEFFICIENT_TEST.getValue()); issueParam.setIsPhaseSequence(CommonEnum.COEFFICIENT_TEST.getValue());

View File

@@ -2,6 +2,7 @@ package com.njcn.gather.detection.handler;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.njcn.gather.detection.pojo.enums.SourceOperateCodeEnum; import com.njcn.gather.detection.pojo.enums.SourceOperateCodeEnum;
import com.njcn.gather.detection.pojo.enums.SourceResponseCodeEnum; import com.njcn.gather.detection.pojo.enums.SourceResponseCodeEnum;
import com.njcn.gather.detection.pojo.param.DevPhaseSequenceParam; import com.njcn.gather.detection.pojo.param.DevPhaseSequenceParam;
@@ -14,7 +15,12 @@ import com.njcn.gather.detection.util.socket.*;
import com.njcn.gather.detection.util.socket.websocket.WebServiceManager; import com.njcn.gather.detection.util.socket.websocket.WebServiceManager;
import com.njcn.gather.device.pojo.vo.PreDetection; import com.njcn.gather.device.pojo.vo.PreDetection;
import com.njcn.gather.device.service.IPqDevService; import com.njcn.gather.device.service.IPqDevService;
import com.njcn.gather.plan.pojo.po.AdPlanSource;
import com.njcn.gather.plan.service.IAdPlanSourceService;
import com.njcn.gather.result.pojo.enums.ResultUnitEnum;
import com.njcn.gather.script.pojo.po.SourceIssue; import com.njcn.gather.script.pojo.po.SourceIssue;
import com.njcn.gather.source.pojo.po.SourceInitialize;
import com.njcn.gather.source.service.IPqSourceService;
import com.njcn.gather.system.pojo.enums.DicDataEnum; import com.njcn.gather.system.pojo.enums.DicDataEnum;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@@ -56,6 +62,8 @@ public class SocketSourceResponseService {
* 设备信息服务,提供设备基础信息查询功能 * 设备信息服务,提供设备基础信息查询功能
*/ */
private final IPqDevService iPqDevService; private final IPqDevService iPqDevService;
private final IAdPlanSourceService adPlanSourceService;
private final IPqSourceService pqSourceService;
/** /**
* Socket连接管理器负责管理设备和源的Socket连接 * Socket连接管理器负责管理设备和源的Socket连接
@@ -334,9 +342,9 @@ public class SocketSourceResponseService {
// 系数校验固定检测项:实时电压有效值和实时电流有效值 // 系数校验固定检测项:实时电压有效值和实时电流有效值
phaseSequenceParam.setDataType(Arrays.asList("real$VRMS", "real$IRMS")); phaseSequenceParam.setDataType(Arrays.asList("real$VRMS", "real$IRMS"));
// 读取3次数据用于系数计算 // 读取3次数据用于系数计算
phaseSequenceParam.setReadCount(3); phaseSequenceParam.setReadCount(7); //3
// 忽略前4次数据等待测量稳定 // 忽略前4次数据等待测量稳定
phaseSequenceParam.setIgnoreCount(4); phaseSequenceParam.setIgnoreCount(3); //4
socketMsg.setData(JSON.toJSONString(phaseSequenceParam)); socketMsg.setData(JSON.toJSONString(phaseSequenceParam));
SocketManager.sendMsg(s, JSON.toJSONString(socketMsg)); SocketManager.sendMsg(s, JSON.toJSONString(socketMsg));
@@ -363,18 +371,32 @@ public class SocketSourceResponseService {
SocketMsg<String> socketMsg = new SocketMsg<>(); SocketMsg<String> socketMsg = new SocketMsg<>();
switch (dictDataEnumByCode) { switch (dictDataEnumByCode) {
case SUCCESS: case SUCCESS:
//todo 前端推送收到的消息暂未处理好 if (FormalTestManager.unknownError) {
sendWebSocketMessage(param.getUserPageId(), socketDataMsg); FormalTestManager.unknownError = false;
//开始设备通讯检测(发送设备初始化)
Map<String, List<PreDetection>> map = new HashMap<>(1); //重新下发脚本
map.put("deviceList", FormalTestManager.devList); String type = FormalTestManager.currentIssue.getType();
String jsonString = JSON.toJSONString(map); if (ResultUnitEnum.P.getCode().equals(type)) {
socketMsg.setRequestId(SourceOperateCodeEnum.YJC_SBTXJY.getValue()); FormalTestManager.currentIssue.setType(ResultUnitEnum.V_ABSOLUTELY.getCode());
socketMsg.setOperateCode(SourceOperateCodeEnum.DEV_INIT_GATHER_01.getValue()); }
socketMsg.setData(jsonString); socketMsg.setOperateCode(SourceOperateCodeEnum.OPER_GATHER.getValue());
String json = JSON.toJSONString(socketMsg); socketMsg.setData(JSON.toJSONString(FormalTestManager.currentIssue));
// 使用智能发送工具类,自动管理设备连接 socketMsg.setRequestId(SourceOperateCodeEnum.FORMAL_REAL.getValue() + CnSocketUtil.STEP_TAG + type);
socketManager.smartSendToDevice(param, json); SocketManager.sendMsg(param.getUserPageId() + CnSocketUtil.SOURCE_TAG, JSON.toJSONString(socketMsg));
} else {
//todo 前端推送收到的消息暂未处理好
sendWebSocketMessage(param.getUserPageId(), socketDataMsg);
//开始设备通讯检测(发送设备初始化)
Map<String, List<PreDetection>> map = new HashMap<>(1);
map.put("deviceList", FormalTestManager.devList);
String jsonString = JSON.toJSONString(map);
socketMsg.setRequestId(SourceOperateCodeEnum.YJC_SBTXJY.getValue());
socketMsg.setOperateCode(SourceOperateCodeEnum.DEV_INIT_GATHER_01.getValue());
socketMsg.setData(jsonString);
String json = JSON.toJSONString(socketMsg);
// 使用智能发送工具类,自动管理设备连接
socketManager.smartSendToDevice(param, json);
}
break; break;
case UNPROCESSED_BUSINESS: case UNPROCESSED_BUSINESS:
sendWebSocketMessage(param.getUserPageId(), socketDataMsg); sendWebSocketMessage(param.getUserPageId(), socketDataMsg);
@@ -570,6 +592,10 @@ public class SocketSourceResponseService {
case UNPROCESSED_BUSINESS: case UNPROCESSED_BUSINESS:
sendWebSocketMessage(param.getUserPageId(), socketDataMsg); sendWebSocketMessage(param.getUserPageId(), socketDataMsg);
break; break;
case UNKNOWN_ERROR: //-1源未知异常
CnSocketUtil.quitSendSource(param);
FormalTestManager.unknownError = true;
break;
default: default:
sendErrorAndQuit(param, socketDataMsg, dictDataEnumByCode); sendErrorAndQuit(param, socketDataMsg, dictDataEnumByCode);
break; break;
@@ -601,9 +627,23 @@ public class SocketSourceResponseService {
SourceResponseCodeEnum dictDataEnumByCode = SourceResponseCodeEnum.getDictDataEnumByCode(socketDataMsg.getCode()); SourceResponseCodeEnum dictDataEnumByCode = SourceResponseCodeEnum.getDictDataEnumByCode(socketDataMsg.getCode());
switch (Objects.requireNonNull(dictDataEnumByCode)) { switch (Objects.requireNonNull(dictDataEnumByCode)) {
case SUCCESS: case SUCCESS:
//通讯校验成功 if (FormalTestManager.unknownError) {
SocketManager.removeUser(param.getUserPageId() + CnSocketUtil.SOURCE_TAG); //获取源初始化参数
sendWebSocketMessage(param.getUserPageId(), socketDataMsg); AdPlanSource planSource = adPlanSourceService.getOne(new LambdaQueryWrapper<AdPlanSource>().eq(AdPlanSource::getPlanId, param.getPlanId()));
SourceInitialize sourceParam = pqSourceService.getSourceInitializeParam(planSource.getSourceId());
if (ObjectUtil.isNotNull(sourceParam)) {
SocketMsg<String> socketMsg1 = new SocketMsg<>();
socketMsg1.setRequestId(SourceOperateCodeEnum.YJC_YTXJY.getValue());
socketMsg1.setOperateCode(SourceOperateCodeEnum.INIT_GATHER.getValue());
socketMsg1.setData(JSON.toJSONString(sourceParam));
//使用智能发送工具类自动管理与源控程序的socket连接
socketManager.smartSendToSource(param, JSON.toJSONString(socketMsg1));
}
} else {
//通讯校验成功
SocketManager.removeUser(param.getUserPageId() + CnSocketUtil.SOURCE_TAG);
sendWebSocketMessage(param.getUserPageId(), socketDataMsg);
}
break; break;
case UNPROCESSED_BUSINESS: case UNPROCESSED_BUSINESS:
break; break;
@@ -653,6 +693,8 @@ public class SocketSourceResponseService {
// 同步更新系数管理器中的设备列表 // 同步更新系数管理器中的设备列表
XiNumberManager.xiDevList = devList; XiNumberManager.xiDevList = devList;
FormalTestManager.unknownError = false;
FormalTestManager.currentIssue = null;
} }
} }

View File

@@ -0,0 +1,29 @@
package com.njcn.gather.detection.lock;
/**
* 检测互斥锁对象(不可变)。
* 字段含义见 docs/superpowers/specs/2026-05-28-单用户检测互斥-design.md §2.1
*/
public final class DetectionLock {
private final String userId;
private final String userName;
private final String userPageId;
private final long acquireTime;
private final long expireAt;
public DetectionLock(String userId, String userName, String userPageId,
long acquireTime, long expireAt) {
this.userId = userId;
this.userName = userName;
this.userPageId = userPageId;
this.acquireTime = acquireTime;
this.expireAt = expireAt;
}
public String getUserId() { return userId; }
public String getUserName() { return userName; }
public String getUserPageId() { return userPageId; }
public long getAcquireTime() { return acquireTime; }
public long getExpireAt() { return expireAt; }
}

View File

@@ -0,0 +1,134 @@
package com.njcn.gather.detection.lock;
import lombok.extern.slf4j.Slf4j;
import java.util.Date;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
import com.njcn.gather.detection.pojo.vo.DetectionLockHolderVO;
/**
* 检测互斥锁管理器(进程内单例)。
* 详细设计docs/superpowers/specs/2026-05-28-单用户检测互斥-design.md
*/
@Slf4j
public final class DetectionLockManager {
private static final long LOCK_MAX_HOLD_MS = TimeUnit.HOURS.toMillis(4);
private static final DetectionLockManager INSTANCE = new DetectionLockManager();
public static DetectionLockManager getInstance() {
return INSTANCE;
}
private final AtomicReference<DetectionLock> current = new AtomicReference<>(null);
private DetectionLockManager() {}
/** 抢锁。同账号视为重入(刷新 page/expireAt。 */
public AcquireResult tryAcquire(String userId, String userName, String userPageId) {
for (int attempt = 0; attempt < 2; attempt++) {
DetectionLock cur = current.get();
long now = System.currentTimeMillis();
// 空闲 或 绝对超时已过 → 直接抢
if (cur == null || now > cur.getExpireAt()) {
DetectionLock fresh = new DetectionLock(userId, userName, userPageId, now, now + LOCK_MAX_HOLD_MS);
if (current.compareAndSet(cur, fresh)) {
log.info("DetectionLock acquired by userId={}, userName={}, userPageId={}", userId, userName, userPageId);
return AcquireResult.ok();
}
continue; // CAS 失败重试
}
// 同账号重入 → 刷新
if (userId.equals(cur.getUserId())) {
DetectionLock refreshed = new DetectionLock(userId, userName, userPageId, now, now + LOCK_MAX_HOLD_MS);
if (current.compareAndSet(cur, refreshed)) {
log.debug("DetectionLock reentered by userId={}, new userPageId={}", userId, userPageId);
return AcquireResult.ok();
}
continue;
}
// 被他人持有
return AcquireResult.busy(toHolderVO(cur));
}
// 两次 CAS 都失败属于罕见高并发场景:绝不返回 ok()(那样会让调用方误以为持锁)。
// 返回 busydata 可能为 null锁刚被释放调用方/前端按"请重试"处理。
DetectionLock cur = current.get();
return AcquireResult.busy(cur == null ? null : toHolderVO(cur));
}
/** 仅当 holder.userId == userId 才释放(幂等)。
* 循环终止性:每轮 CAS 失败意味着 current 被其他线程改写;
* 下一轮 get 后 cur 可能变成 null 或不再匹配 userId命中前置 return 退出。
* 唯一可能继续的情况是另一线程把它换成了同 userId 的新 lock下一轮 CAS 会再次尝试;
* 最坏情况下 CAS 成功,仍然终止。 */
public void releaseIfHeldBy(String userId, String reason) {
while (true) {
DetectionLock cur = current.get();
if (cur == null || !cur.getUserId().equals(userId)) return;
if (current.compareAndSet(cur, null)) {
log.info("DetectionLock released, reason={}, userId={}", reason, userId);
return;
}
}
}
/** 仅当 holder.userPageId == userPageId 才释放(幂等)。终止性同 releaseIfHeldBy。 */
public void releaseIfMatchPage(String userPageId, String reason) {
while (true) {
DetectionLock cur = current.get();
if (cur == null || !cur.getUserPageId().equals(userPageId)) return;
if (current.compareAndSet(cur, null)) {
log.info("DetectionLock released, reason={}, userPageId={}", reason, userPageId);
return;
}
}
}
/** 管理员强制释放,不校验 holder。 */
public void forceRelease(String operatorUserId, String reason) {
DetectionLock cur = current.getAndSet(null);
if (cur != null) {
log.warn("DetectionLock force-released by operator={}, victim userId={}, reason={}",
operatorUserId, cur.getUserId(), reason);
}
}
/** 返回当前 holder 快照;返回 null 表示空闲。 */
public DetectionLock getCurrent() {
DetectionLock cur = current.get();
// 顺手做惰性超时回收spec R5
if (cur != null && System.currentTimeMillis() > cur.getExpireAt()) {
current.compareAndSet(cur, null);
return null;
}
return cur;
}
/** 把 DetectionLock 转成给前端的 VO。 */
public static DetectionLockHolderVO toHolderVO(DetectionLock lock) {
DetectionLockHolderVO vo = new DetectionLockHolderVO();
vo.setHolderUserId(lock.getUserId());
vo.setHolderUserName(lock.getUserName());
vo.setAcquireTime(new Date(lock.getAcquireTime()));
vo.setExpireAt(new Date(lock.getExpireAt()));
return vo;
}
/** 抢锁结果。 */
public static final class AcquireResult {
private final boolean ok;
private final DetectionLockHolderVO holder;
private AcquireResult(boolean ok, DetectionLockHolderVO holder) {
this.ok = ok;
this.holder = holder;
}
public static AcquireResult ok() { return new AcquireResult(true, null); }
public static AcquireResult busy(DetectionLockHolderVO holder) { return new AcquireResult(false, holder); }
public boolean isOk() { return ok; }
public DetectionLockHolderVO getHolder() { return holder; }
}
}

View File

@@ -19,7 +19,8 @@ public enum DetectionResponseEnum {
SCRIPT_CHECK_DATA_NOT_EXIST("A020040","测试脚本项暂无配置" ), SCRIPT_CHECK_DATA_NOT_EXIST("A020040","测试脚本项暂无配置" ),
EXCEED_MAX_TIME("A020041","检测次数超出最大限制!" ); EXCEED_MAX_TIME("A020041","检测次数超出最大限制!" ),
DETECTION_BUSY("A020042", "检测进行中");
private final String code; private final String code;
private final String message; private final String message;

View File

@@ -43,4 +43,9 @@ public class ContrastDetectionParam {
private List<Boolean> testItemList; private List<Boolean> testItemList;
private String userId; private String userId;
/**
* 是否进行相许校验
*/
private Integer phaseCheck;
} }

View File

@@ -46,6 +46,11 @@ public class PreDetectionParam {
*/ */
private String sourceId; private String sourceId;
/**
* 源名称
*/
private String sourceName;
/** /**
* 所属误差体系 * 所属误差体系
*/ */

View File

@@ -53,4 +53,9 @@ public class DetectionData {
* 误差体系详情ID(比对式使用) * 误差体系详情ID(比对式使用)
*/ */
private String errorDtlId; private String errorDtlId;
/**
* 有效组数
*/
private Integer validGroupNum;
} }

View File

@@ -0,0 +1,22 @@
package com.njcn.gather.detection.pojo.vo;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import java.util.Date;
/**
* 检测锁持有者信息,用于在抢锁失败响应中返回给前端。
*/
@Data
public class DetectionLockHolderVO {
private String holderUserId;
private String holderUserName;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date acquireTime;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date expireAt;
}

View File

@@ -4,6 +4,7 @@ import com.njcn.gather.detection.pojo.param.ContrastDetectionParam;
import com.njcn.gather.detection.pojo.param.PreDetectionParam; import com.njcn.gather.detection.pojo.param.PreDetectionParam;
import com.njcn.gather.detection.pojo.param.SimulateDetectionParam; import com.njcn.gather.detection.pojo.param.SimulateDetectionParam;
import java.util.List;
import java.util.Map; import java.util.Map;
@@ -63,4 +64,8 @@ public interface PreDetectionService {
* 导出实时数据对齐过程中的数据 * 导出实时数据对齐过程中的数据
*/ */
void exportAlignData(); void exportAlignData();
boolean getCanCoefficient();
void startCoefficient();
} }

View File

@@ -21,6 +21,8 @@ import com.njcn.gather.detection.util.business.DetectionCommunicateUtil;
import com.njcn.gather.detection.util.socket.CnSocketUtil; import com.njcn.gather.detection.util.socket.CnSocketUtil;
import com.njcn.gather.detection.util.socket.FormalTestManager; import com.njcn.gather.detection.util.socket.FormalTestManager;
import com.njcn.gather.detection.util.socket.SocketManager; import com.njcn.gather.detection.util.socket.SocketManager;
import com.njcn.gather.detection.util.socket.XiNumberManager;
import com.njcn.gather.detection.util.socket.cilent.NettyContrastClientHandler;
import com.njcn.gather.detection.util.socket.websocket.WebServiceManager; import com.njcn.gather.detection.util.socket.websocket.WebServiceManager;
import com.njcn.gather.device.pojo.po.PqDev; import com.njcn.gather.device.pojo.po.PqDev;
import com.njcn.gather.device.pojo.vo.PreDetection; import com.njcn.gather.device.pojo.vo.PreDetection;
@@ -38,6 +40,8 @@ import com.njcn.gather.script.service.IPqScriptCheckDataService;
import com.njcn.gather.script.service.IPqScriptDtlsService; import com.njcn.gather.script.service.IPqScriptDtlsService;
import com.njcn.gather.source.pojo.po.SourceInitialize; import com.njcn.gather.source.pojo.po.SourceInitialize;
import com.njcn.gather.source.service.IPqSourceService; import com.njcn.gather.source.service.IPqSourceService;
import com.njcn.gather.system.cfg.service.ISysTestConfigService;
import com.njcn.gather.system.config.PathConfig;
import com.njcn.gather.system.dictionary.pojo.enums.DictDataEnum; import com.njcn.gather.system.dictionary.pojo.enums.DictDataEnum;
import com.njcn.gather.system.dictionary.service.IDictDataService; import com.njcn.gather.system.dictionary.service.IDictDataService;
import com.njcn.web.utils.HttpServletUtil; import com.njcn.web.utils.HttpServletUtil;
@@ -50,6 +54,7 @@ import org.springframework.stereotype.Service;
import javax.servlet.ServletOutputStream; import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
@@ -75,9 +80,12 @@ public class PreDetectionServiceImpl implements PreDetectionService {
private final SocketContrastResponseService socketContrastResponseService; private final SocketContrastResponseService socketContrastResponseService;
private final IPqScriptCheckDataService iPqScriptCheckDataService; private final IPqScriptCheckDataService iPqScriptCheckDataService;
private final SocketManager socketManager; private final SocketManager socketManager;
private final ISysTestConfigService sysTestConfigService;
@Value("${log.homeDir}")
private String alignDataFilePath; // @Value("${report.reportDir}")
// private String alignDataFilePath;
private final PathConfig pathConfig;
@Override @Override
@@ -130,6 +138,7 @@ public class PreDetectionServiceImpl implements PreDetectionService {
); );
if (ObjectUtil.isNotNull(planSource)) { if (ObjectUtil.isNotNull(planSource)) {
SourceInitialize sourceParam = pqSourceService.getSourceInitializeParam(planSource.getSourceId()); SourceInitialize sourceParam = pqSourceService.getSourceInitializeParam(planSource.getSourceId());
param.setSourceName(sourceParam.getSourceId());
if (ObjectUtil.isNotNull(sourceParam)) { if (ObjectUtil.isNotNull(sourceParam)) {
//开始组装socket报文请求头 //开始组装socket报文请求头
socketDevResponseService.initList(param); socketDevResponseService.initList(param);
@@ -176,6 +185,7 @@ public class PreDetectionServiceImpl implements PreDetectionService {
if (ObjectUtil.isNotNull(planSource)) { if (ObjectUtil.isNotNull(planSource)) {
//获取源初始化参数 //获取源初始化参数
SourceInitialize sourceParam = pqSourceService.getSourceInitializeParam(planSource.getSourceId()); SourceInitialize sourceParam = pqSourceService.getSourceInitializeParam(planSource.getSourceId());
param.setSourceName(sourceParam.getSourceId());
if (ObjectUtil.isNotNull(sourceParam)) { if (ObjectUtil.isNotNull(sourceParam)) {
//开始组装socket报文请求头 //开始组装socket报文请求头
socketDevResponseService.initList(param); socketDevResponseService.initList(param);
@@ -238,6 +248,8 @@ public class PreDetectionServiceImpl implements PreDetectionService {
FormalTestManager.stopFlag = false; FormalTestManager.stopFlag = false;
socketDevResponseService.initRestart(); socketDevResponseService.initRestart();
List<SourceIssue> sourceIssueList = SocketManager.getSourceList(); List<SourceIssue> sourceIssueList = SocketManager.getSourceList();
SourceInitialize sourceInitialize = pqSourceService.getSourceInitializeParam(param.getSourceId());
param.setSourceName(sourceInitialize.getSourceId());
if (CollUtil.isNotEmpty(sourceIssueList)) { if (CollUtil.isNotEmpty(sourceIssueList)) {
SourceIssue sourceIssues = SocketManager.getSourceList().get(0); SourceIssue sourceIssues = SocketManager.getSourceList().get(0);
SocketMsg<String> xuMsg = new SocketMsg<>(); SocketMsg<String> xuMsg = new SocketMsg<>();
@@ -253,7 +265,7 @@ public class PreDetectionServiceImpl implements PreDetectionService {
checkDataParam.setIsValueTypeName(false); checkDataParam.setIsValueTypeName(false);
List<String> adType = iPqScriptCheckDataService.getValueType(checkDataParam); List<String> adType = iPqScriptCheckDataService.getValueType(checkDataParam);
iPqDevService.updateResult(param.getDevIds(), adType, param.getCode(), param.getUserId(), param.getTemperature(), param.getHumidity()); iPqDevService.updateResult(param.getDevIds(), adType, param.getCode(), param.getUserId(), param.getTemperature(), param.getHumidity(), true);
CnSocketUtil.quitSend(param); CnSocketUtil.quitSend(param);
} }
@@ -284,7 +296,8 @@ public class PreDetectionServiceImpl implements PreDetectionService {
} }
//组装源控制脚本 //组装源控制脚本
PqScriptIssueParam issueParam = new PqScriptIssueParam(); PqScriptIssueParam issueParam = new PqScriptIssueParam();
issueParam.setSourceId(param.getSourceId()); SourceInitialize sourceInitialize = pqSourceService.getSourceInitializeParam(param.getSourceId());
issueParam.setSourceId(sourceInitialize.getSourceId());
issueParam.setScriptId(param.getScriptId()); issueParam.setScriptId(param.getScriptId());
issueParam.setType(1); issueParam.setType(1);
issueParam.setIsPhaseSequence(SourceOperateCodeEnum.SIMULATE_TEST.getValue()); issueParam.setIsPhaseSequence(SourceOperateCodeEnum.SIMULATE_TEST.getValue());
@@ -337,13 +350,13 @@ public class PreDetectionServiceImpl implements PreDetectionService {
@Override @Override
public void exportAlignData() { public void exportAlignData() {
String fileName = "实时数据.xlsx"; String fileName = "对齐数据.xlsx";
HttpServletResponse response = HttpServletUtil.getResponse(); HttpServletResponse response = HttpServletUtil.getResponse();
response.reset(); response.reset();
response.setHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\""); response.setHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\"");
response.setContentType("application/octet-stream;charset=UTF-8"); response.setContentType("application/octet-stream;charset=UTF-8");
try { try {
InputStream inputStream = new FileInputStream(alignDataFilePath + "\\" + fileName); InputStream inputStream = new FileInputStream(pathConfig.getDataPath() + File.separator + fileName);
byte[] buffer = new byte[1024]; byte[] buffer = new byte[1024];
int len = 0; int len = 0;
ServletOutputStream outputStream = response.getOutputStream(); ServletOutputStream outputStream = response.getOutputStream();
@@ -358,6 +371,36 @@ public class PreDetectionServiceImpl implements PreDetectionService {
} }
} }
@Override
public boolean getCanCoefficient() {
return CollUtil.isNotEmpty(DetectionServiceImpl.vAndIResultMap);
}
@Override
public void startCoefficient() {
if (CollUtil.isNotEmpty(DetectionServiceImpl.vAndIResultMap)) {
// 是否进行系数校准
//万一录波了这里就进不来了但是在误差处理的时候DetectionServiceImpl.vAndIResultMap该集合会保留不符合的结果
XiNumberManager.xiDevList.clear();
XiNumberManager.devXiNumDataMap.clear();
List<String> stdIpList = DetectionServiceImpl.vAndIResultMap.values().stream().map(DetectionServiceImpl.VAndIResult::getIp).collect(Collectors.toList());
XiNumberManager.xiDevList = FormalTestManager.standardDevList.stream().filter(d -> stdIpList.contains(d.getDevIP())).collect(Collectors.toList());
// 逐一设备向通讯模块要原始系数
SocketMsg<String> socketMsg = new SocketMsg<>();
socketMsg.setRequestId(SourceOperateCodeEnum.Coefficient_Check.getValue());
socketMsg.setOperateCode(SourceOperateCodeEnum.DATA_CHNFACTOR$01.getValue());
PreDetection preDetection = XiNumberManager.xiDevList.get(0);
Map<String, Object> map = new HashMap<>();
map.put("devIP", preDetection.getDevIP());
map.put("chnNum", preDetection.getDevChns());
socketMsg.setData(JSON.toJSONString(map));
SocketManager.sendMsg(NettyContrastClientHandler.param.getUserPageId() + CnSocketUtil.CONTRAST_DEV_TAG, JSON.toJSONString(socketMsg));
FormalTestManager.currentStep = SourceOperateCodeEnum.Coefficient_Check;
}
}
/** /**
* 比对式-与通信模块进行连接 * 比对式-与通信模块进行连接
* *

View File

@@ -1,6 +1,7 @@
package com.njcn.gather.detection.util; package com.njcn.gather.detection.util;
import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.NumberUtil;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import com.njcn.gather.detection.pojo.po.DevData; import com.njcn.gather.detection.pojo.po.DevData;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@@ -421,7 +422,7 @@ public class DetectionUtil {
} }
return newList; return newList;
} }
return null; return Collections.emptyList();
} }
/** /**
@@ -437,4 +438,94 @@ public class DetectionUtil {
System.out.println(" 文件大小: " + file.length() + " bytes"); System.out.println(" 文件大小: " + file.length() + " bytes");
} }
} }
/**
* 获取皮尔逊系数
*
* <p>相关系数绝对值|r|所代表的相关强度</p>
* <ul>
* <li>0.8 - 1.0:极强相关</li>
* <li>0.6 - 0.8:强相关</li>
* <li>0.4 - 0.6:中等程度相关</li>
* <li>0.2 - 0.4:弱相关</li>
* <li>0.0 - 0.2:极弱相关或无相关</li>
* </ul>
*
* @return
*/
public static BigDecimal getPearsonCorrelationCoefficient(List<Double> x, List<Double> y) {
Double xAvg = x.parallelStream().mapToDouble(Double::doubleValue).average().orElse(0.0);
Double yAvg = y.parallelStream().mapToDouble(Double::doubleValue).average().orElse(0.0);
// 协方差求和
BigDecimal covarianceSum = BigDecimal.ZERO;
// x的方差
BigDecimal varianceX = BigDecimal.ZERO;
// y的方差
BigDecimal varianceY = BigDecimal.ZERO;
for (int i = 0; i < x.size(); i++) {
covarianceSum = covarianceSum.add(BigDecimal.valueOf((x.get(i) - xAvg) * (y.get(i) - yAvg)));
varianceX = varianceX.add(BigDecimal.valueOf(Math.pow(x.get(i) - xAvg, 2)));
varianceY = varianceY.add(BigDecimal.valueOf(Math.pow(y.get(i) - yAvg, 2)));
}
BigDecimal fm = BigDecimal.valueOf(Math.sqrt(varianceX.doubleValue()) * Math.sqrt(varianceY.doubleValue()));
if (NumberUtil.equals(fm.doubleValue(), BigDecimal.ZERO.doubleValue())) {
if (NumberUtil.equals(covarianceSum, BigDecimal.ZERO)) {
return BigDecimal.valueOf(1.0);
} else {
return BigDecimal.ZERO;
}
} else {
return BigDecimal.valueOf(Math.abs(covarianceSum.divide(fm, 8, BigDecimal.ROUND_HALF_UP).doubleValue())); //相关系数
}
}
/**
* 比值一致性获取CV系数
*
* <p>一致性等级</p>
* <ul>
* <li>CV<1%:非常优秀</li>
* <li>1%≤CV5%:优良</li>
* <li>5%≤CV10%:良好</li>
* <li>10%≤CV20%:中等</li>
* <li>20%≤CV较差</li>
* </ul>
*
* @param x
* @param y
* @return
*/
public static BigDecimal getCvCoefficient(List<Double> x, List<Double> y) {
List<BigDecimal> ratioList = new ArrayList<>();
for (int i = 0; i < x.size(); i++) {
ratioList.add(BigDecimal.valueOf(x.get(i) / y.get(i)));
}
BigDecimal avg = BigDecimal.valueOf(ratioList.parallelStream().mapToDouble(BigDecimal::doubleValue).average().orElse(0.0));
BigDecimal variance = BigDecimal.valueOf(
ratioList.parallelStream().mapToDouble(BigDecimal::doubleValue)
.map(v -> Math.pow(v - avg.doubleValue(), 2)).average().orElse(0.0));
return BigDecimal.valueOf(Math.sqrt(variance.doubleValue()) / avg.doubleValue());
}
/**
* 计算新的系数
*
* @param devList
* @param stdDevList
* @return
*/
public static Double getNewXi(List<Double> devList, List<Double> stdDevList) {
ArrayList<Double> xiList = new ArrayList<>();
for (int i = 0; i < stdDevList.size(); i++) {
if (!stdDevList.get(i).equals(0)) {
BigDecimal bigDecimalDev = BigDecimal.valueOf(devList.get(i));
BigDecimal bigDecimalStdDev = BigDecimal.valueOf(stdDevList.get(i));
xiList.add((bigDecimalDev.subtract(bigDecimalStdDev)).divide(BigDecimal.valueOf(2.0).multiply(bigDecimalDev), 8, BigDecimal.ROUND_HALF_UP).doubleValue() + 1.0);
}
}
return xiList.stream().mapToDouble(Double::doubleValue).average().orElse(1.0);
}
} }

View File

@@ -47,7 +47,7 @@ public class CnSocketUtil {
socketMsg.setRequestId(SourceOperateCodeEnum.QUITE_SOURCE.getValue()); socketMsg.setRequestId(SourceOperateCodeEnum.QUITE_SOURCE.getValue());
socketMsg.setOperateCode(SourceOperateCodeEnum.CLOSE_GATHER.getValue()); socketMsg.setOperateCode(SourceOperateCodeEnum.CLOSE_GATHER.getValue());
JSONObject jsonObject = new JSONObject(); JSONObject jsonObject = new JSONObject();
jsonObject.put("sourceId", param.getSourceId()); jsonObject.put("sourceId", param.getSourceName());
socketMsg.setData(jsonObject.toJSONString()); socketMsg.setData(jsonObject.toJSONString());
SocketManager.sendMsg(param.getUserPageId() + SOURCE_TAG, JSON.toJSONString(socketMsg)); SocketManager.sendMsg(param.getUserPageId() + SOURCE_TAG, JSON.toJSONString(socketMsg));
WebServiceManager.removePreDetectionParam(param.getUserPageId()); WebServiceManager.removePreDetectionParam(param.getUserPageId());

View File

@@ -10,6 +10,7 @@ import com.njcn.gather.device.pojo.vo.PreDetection;
import com.njcn.gather.plan.pojo.enums.DataSourceEnum; import com.njcn.gather.plan.pojo.enums.DataSourceEnum;
import com.njcn.gather.plan.pojo.po.AdPlan; import com.njcn.gather.plan.pojo.po.AdPlan;
import com.njcn.gather.plan.pojo.po.AdPlanTestConfig; import com.njcn.gather.plan.pojo.po.AdPlanTestConfig;
import com.njcn.gather.script.pojo.po.SourceIssue;
import com.njcn.gather.system.dictionary.pojo.enums.DictDataEnum; import com.njcn.gather.system.dictionary.pojo.enums.DictDataEnum;
import java.util.ArrayList; import java.util.ArrayList;
@@ -195,4 +196,16 @@ public class FormalTestManager {
public static boolean statisticsProtocol; public static boolean statisticsProtocol;
public static boolean voltageProtocol; public static boolean voltageProtocol;
public static boolean unknownError;
/**
* 当前下发的脚本
*/
public static SourceIssue currentIssue;
/**
* 是否进行相序校验
*/
public static boolean isXu;
} }

View File

@@ -5,6 +5,7 @@ import com.alibaba.fastjson.JSON;
import com.njcn.gather.detection.handler.SocketContrastResponseService; import com.njcn.gather.detection.handler.SocketContrastResponseService;
import com.njcn.gather.detection.handler.SocketDevResponseService; import com.njcn.gather.detection.handler.SocketDevResponseService;
import com.njcn.gather.detection.handler.SocketSourceResponseService; import com.njcn.gather.detection.handler.SocketSourceResponseService;
import com.njcn.gather.detection.lock.DetectionLockManager;
import com.njcn.gather.detection.pojo.enums.SourceResponseCodeEnum; import com.njcn.gather.detection.pojo.enums.SourceResponseCodeEnum;
import com.njcn.gather.detection.pojo.param.ContrastDetectionParam; import com.njcn.gather.detection.pojo.param.ContrastDetectionParam;
import com.njcn.gather.detection.pojo.param.PreDetectionParam; import com.njcn.gather.detection.pojo.param.PreDetectionParam;
@@ -349,7 +350,7 @@ public class NettyClient {
NioEventLoopGroup group, String msg) { NioEventLoopGroup group, String msg) {
channelFuture.addListener((ChannelFutureListener) ch -> { channelFuture.addListener((ChannelFutureListener) ch -> {
if (!ch.isSuccess()) { if (!ch.isSuccess()) {
onConnectionFailure(handler, group); onConnectionFailure(param, handler, group);
} else { } else {
onConnectionSuccess(channelFuture, param, handler, group, msg); onConnectionSuccess(channelFuture, param, handler, group, msg);
} }
@@ -358,15 +359,24 @@ public class NettyClient {
/** /**
* 连接失败处理 * 连接失败处理
* 输出失败信息优雅关闭事件循环组 * 输出失败信息优雅关闭事件循环组、通知前端、释放检测锁
* *
* @param param 检测参数,用于定位锁与前端通知
* @param handler 业务处理器,用于区分设备类型 * @param handler 业务处理器,用于区分设备类型
* @param group 事件循环组 * @param group 事件循环组
*/ */
private static void onConnectionFailure(SimpleChannelInboundHandler<String> handler, NioEventLoopGroup group) { private static void onConnectionFailure(PreDetectionParam param,
SimpleChannelInboundHandler<String> handler, NioEventLoopGroup group) {
String deviceType = getDeviceType(handler); String deviceType = getDeviceType(handler);
log.info("连接{}服务端失败...", deviceType); log.info("连接{}服务端失败...", deviceType);
group.shutdownGracefully(); group.shutdownGracefully();
// 异步建连失败时前端原本静默,补一次通知避免用户黑屏等待
notifyFrontendError(param, handler);
// 释放检测锁:抢锁后由 controller 异步发起的建连若失败,无法走 controller 兜底
if (param != null && param.getUserPageId() != null) {
DetectionLockManager.getInstance()
.releaseIfMatchPage(param.getUserPageId(), "ASYNC_CONNECT_FAILED");
}
} }
/** /**
@@ -455,6 +465,12 @@ public class NettyClient {
// 通过WebSocket通知前端页面 // 通过WebSocket通知前端页面
notifyFrontendError(param, handler); notifyFrontendError(param, handler);
// 释放检测锁,理由同 onConnectionFailure
if (param != null && param.getUserPageId() != null) {
DetectionLockManager.getInstance()
.releaseIfMatchPage(param.getUserPageId(), "ASYNC_CONNECT_EXCEPTION");
}
} }
/** /**

View File

@@ -2,6 +2,7 @@ package com.njcn.gather.detection.util.socket.cilent;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import com.njcn.gather.detection.handler.SocketContrastResponseService; import com.njcn.gather.detection.handler.SocketContrastResponseService;
import com.njcn.gather.detection.lock.DetectionLockManager;
import com.njcn.gather.detection.pojo.enums.SourceOperateCodeEnum; import com.njcn.gather.detection.pojo.enums.SourceOperateCodeEnum;
import com.njcn.gather.detection.pojo.enums.SourceResponseCodeEnum; import com.njcn.gather.detection.pojo.enums.SourceResponseCodeEnum;
import com.njcn.gather.detection.pojo.param.PreDetectionParam; import com.njcn.gather.detection.pojo.param.PreDetectionParam;
@@ -68,6 +69,11 @@ public class NettyContrastClientHandler extends SimpleChannelInboundHandler<Stri
CnSocketUtil.contrastSendquit(param.getUserPageId(), SourceOperateCodeEnum.QUIT_INIT_01, false); CnSocketUtil.contrastSendquit(param.getUserPageId(), SourceOperateCodeEnum.QUIT_INIT_01, false);
CnSocketUtil.contrastSendquit(param.getUserPageId(), SourceOperateCodeEnum.QUIT_INIT_02, false); CnSocketUtil.contrastSendquit(param.getUserPageId(), SourceOperateCodeEnum.QUIT_INIT_02, false);
CnSocketUtil.contrastSendquit(param.getUserPageId(), SourceOperateCodeEnum.QUIT_INIT_03, true); CnSocketUtil.contrastSendquit(param.getUserPageId(), SourceOperateCodeEnum.QUIT_INIT_03, true);
// 业务消息处理异常 → 释放检测锁
if (param != null && param.getUserPageId() != null) {
DetectionLockManager.getInstance()
.releaseIfMatchPage(param.getUserPageId(), "CONTRAST_READ_EXCEPTION");
}
} }
} }
@@ -76,6 +82,11 @@ public class NettyContrastClientHandler extends SimpleChannelInboundHandler<Stri
System.out.println("与通信模块端断线"); System.out.println("与通信模块端断线");
ctx.close(); ctx.close();
SocketManager.removeUser(param.getUserPageId() + CnSocketUtil.CONTRAST_DEV_TAG); SocketManager.removeUser(param.getUserPageId() + CnSocketUtil.CONTRAST_DEV_TAG);
// 比对通信模块主动断开 → 本次检测视为结束,释放检测锁
if (param != null && param.getUserPageId() != null) {
DetectionLockManager.getInstance()
.releaseIfMatchPage(param.getUserPageId(), "CONTRAST_CHANNEL_INACTIVE");
}
} }
/** /**
@@ -150,11 +161,18 @@ public class NettyContrastClientHandler extends SimpleChannelInboundHandler<Stri
CnSocketUtil.contrastSendquit(param.getUserPageId(), SourceOperateCodeEnum.QUIT_INIT_02, false); CnSocketUtil.contrastSendquit(param.getUserPageId(), SourceOperateCodeEnum.QUIT_INIT_02, false);
CnSocketUtil.contrastSendquit(param.getUserPageId(), SourceOperateCodeEnum.QUIT_INIT_03, true); CnSocketUtil.contrastSendquit(param.getUserPageId(), SourceOperateCodeEnum.QUIT_INIT_03, true);
ctx.close(); ctx.close();
// 比对通道异常 → 释放检测锁
if (param != null && param.getUserPageId() != null) {
DetectionLockManager.getInstance()
.releaseIfMatchPage(param.getUserPageId(), "CONTRAST_EXCEPTION");
}
} }
/** /**
* 接收数据超时处理 * 接收数据超时处理
* 比对模式读超时10 分钟 Pst / 1 分钟实时 / 动态统计)都汇到这里,
* 推前端的同时一并释放检测锁(避免锁卡到 4 小时绝对超时)。
*/ */
private void timeoutSend(SourceOperateCodeEnum sourceOperateCodeEnum) { private void timeoutSend(SourceOperateCodeEnum sourceOperateCodeEnum) {
System.out.println("超时处理-----》" + "统计数据已超时----------------关闭"); System.out.println("超时处理-----》" + "统计数据已超时----------------关闭");
@@ -164,6 +182,11 @@ public class NettyContrastClientHandler extends SimpleChannelInboundHandler<Stri
webSend.setData(sourceOperateCodeEnum.getMsg() + SourceResponseCodeEnum.RECEIVE_DATA_TIME_OUT.getMessage()); webSend.setData(sourceOperateCodeEnum.getMsg() + SourceResponseCodeEnum.RECEIVE_DATA_TIME_OUT.getMessage());
webSend.setCode(SourceResponseCodeEnum.RECEIVE_DATA_TIME_OUT.getCode()); webSend.setCode(SourceResponseCodeEnum.RECEIVE_DATA_TIME_OUT.getCode());
WebServiceManager.sendMsg(param.getUserPageId(), MsgUtil.msgToWebData(webSend, FormalTestManager.devNameMapComm, 0)); WebServiceManager.sendMsg(param.getUserPageId(), MsgUtil.msgToWebData(webSend, FormalTestManager.devNameMapComm, 0));
// 比对模式读超时终态 → 释放检测锁
if (param != null && param.getUserPageId() != null) {
DetectionLockManager.getInstance()
.releaseIfMatchPage(param.getUserPageId(), "CONTRAST_IDLE_TIMEOUT");
}
} }
} }

View File

@@ -3,6 +3,8 @@ package com.njcn.gather.detection.util.socket.cilent;
import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollUtil;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.njcn.gather.detection.handler.SocketDevResponseService; import com.njcn.gather.detection.handler.SocketDevResponseService;
import com.njcn.gather.detection.lock.DetectionLock;
import com.njcn.gather.detection.lock.DetectionLockManager;
import com.njcn.gather.detection.pojo.enums.ResultEnum; import com.njcn.gather.detection.pojo.enums.ResultEnum;
import com.njcn.gather.detection.pojo.enums.SourceOperateCodeEnum; import com.njcn.gather.detection.pojo.enums.SourceOperateCodeEnum;
import com.njcn.gather.detection.pojo.param.PreDetectionParam; import com.njcn.gather.detection.pojo.param.PreDetectionParam;
@@ -115,6 +117,9 @@ public class NettyDevClientHandler extends SimpleChannelInboundHandler<String> {
ctx.close(); ctx.close();
SocketManager.removeUser(param.getUserPageId() + CnSocketUtil.DEV_TAG); SocketManager.removeUser(param.getUserPageId() + CnSocketUtil.DEV_TAG);
CnSocketUtil.quitSendSource(param); CnSocketUtil.quitSendSource(param);
// 设备主动断开 → 本次检测视为结束,释放检测锁
DetectionLockManager.getInstance()
.releaseIfMatchPage(param.getUserPageId(), "DEV_CHANNEL_INACTIVE");
} }
/** /**
@@ -132,6 +137,9 @@ public class NettyDevClientHandler extends SimpleChannelInboundHandler<String> {
} catch (Exception e) { } catch (Exception e) {
log.error("处理服务端消息异常", e); log.error("处理服务端消息异常", e);
CnSocketUtil.quitSend(param); CnSocketUtil.quitSend(param);
// 业务消息处理异常 → 退出并释放检测锁
DetectionLockManager.getInstance()
.releaseIfMatchPage(param.getUserPageId(), "DEV_READ_EXCEPTION");
} }
} }
@@ -187,6 +195,9 @@ public class NettyDevClientHandler extends SimpleChannelInboundHandler<String> {
CnSocketUtil.quitSendSource(param); CnSocketUtil.quitSendSource(param);
socketResponseService.backCheckState(param); socketResponseService.backCheckState(param);
ctx.close(); ctx.close();
// 通道异常 → 释放检测锁
DetectionLockManager.getInstance()
.releaseIfMatchPage(param.getUserPageId(), "DEV_EXCEPTION");
} }
/** /**
@@ -231,6 +242,9 @@ public class NettyDevClientHandler extends SimpleChannelInboundHandler<String> {
CnSocketUtil.quitSend(param); CnSocketUtil.quitSend(param);
WebServiceManager.sendDetectionErrorMessage(param.getUserPageId(), SourceOperateCodeEnum.SOCKET_TIMEOUT); WebServiceManager.sendDetectionErrorMessage(param.getUserPageId(), SourceOperateCodeEnum.SOCKET_TIMEOUT);
socketResponseService.backCheckState(param); socketResponseService.backCheckState(param);
// 常规步骤读超时兜底 → 释放检测锁
DetectionLockManager.getInstance()
.releaseIfMatchPage(param.getUserPageId(), "DEV_READ_TIMEOUT");
} }
} }
@@ -244,6 +258,14 @@ public class NettyDevClientHandler extends SimpleChannelInboundHandler<String> {
if (FormalTestManager.stopTime > STOP_TIMEOUT) { if (FormalTestManager.stopTime > STOP_TIMEOUT) {
CnSocketUtil.quitSend(param); CnSocketUtil.quitSend(param);
WebServiceManager.sendDetectionErrorMessage(param.getUserPageId(), SourceOperateCodeEnum.FORMAL_REAL.getValue(), SourceOperateCodeEnum.STOP_TIMEOUT); WebServiceManager.sendDetectionErrorMessage(param.getUserPageId(), SourceOperateCodeEnum.FORMAL_REAL.getValue(), SourceOperateCodeEnum.STOP_TIMEOUT);
// R4 释放:暂停 10 分钟超时视同放弃本次检测
DetectionLock cur = DetectionLockManager.getInstance().getCurrent();
if (cur != null) {
DetectionLockManager.getInstance().releaseIfHeldBy(cur.getUserId(), "PAUSE_TIMEOUT");
}
// 重置 FormalTestManager 状态,避免下次进入误判
FormalTestManager.stopTime = 0;
FormalTestManager.hasStopFlag = false;
} }
} }
@@ -302,6 +324,9 @@ public class NettyDevClientHandler extends SimpleChannelInboundHandler<String> {
CnSocketUtil.quitSend(param); CnSocketUtil.quitSend(param);
timeoutSend(sourceIssue); timeoutSend(sourceIssue);
socketResponseService.backCheckState(param); socketResponseService.backCheckState(param);
// 单项检测超时本质等于整轮中止(已 quitSend释放检测锁
DetectionLockManager.getInstance()
.releaseIfMatchPage(param.getUserPageId(), "DEV_ITEM_TIMEOUT");
} }
/** /**
@@ -336,7 +361,7 @@ public class NettyDevClientHandler extends SimpleChannelInboundHandler<String> {
devLineTestResult.setDeviceName(dev.getDevName()); devLineTestResult.setDeviceName(dev.getDevName());
Integer[] resultFlags = dev.getMonitorList().stream() Integer[] resultFlags = dev.getMonitorList().stream()
.map(monitor -> ResultEnum.NETWORK_TIMEOUT) .map(monitor -> ResultEnum.NETWORK_TIMEOUT.getValue())
.toArray(Integer[]::new); .toArray(Integer[]::new);
devLineTestResult.setChnResult(resultFlags); devLineTestResult.setChnResult(resultFlags);

View File

@@ -1,6 +1,7 @@
package com.njcn.gather.detection.util.socket.cilent; package com.njcn.gather.detection.util.socket.cilent;
import com.njcn.gather.detection.handler.SocketSourceResponseService; import com.njcn.gather.detection.handler.SocketSourceResponseService;
import com.njcn.gather.detection.lock.DetectionLockManager;
import com.njcn.gather.detection.pojo.enums.SourceOperateCodeEnum; import com.njcn.gather.detection.pojo.enums.SourceOperateCodeEnum;
import com.njcn.gather.detection.pojo.param.PreDetectionParam; import com.njcn.gather.detection.pojo.param.PreDetectionParam;
import com.njcn.gather.detection.util.socket.CnSocketUtil; import com.njcn.gather.detection.util.socket.CnSocketUtil;
@@ -70,6 +71,9 @@ public class NettySourceClientHandler extends SimpleChannelInboundHandler<String
// 从Socket管理器中移除用户通道映射 // 从Socket管理器中移除用户通道映射
if (webUser != null && StrUtil.isNotBlank(userId)) { if (webUser != null && StrUtil.isNotBlank(userId)) {
SocketManager.removeUser(userId + CnSocketUtil.SOURCE_TAG); SocketManager.removeUser(userId + CnSocketUtil.SOURCE_TAG);
// 源端主动断开 → 本次检测视为结束,释放检测锁
DetectionLockManager.getInstance()
.releaseIfMatchPage(userId, "SOURCE_CHANNEL_INACTIVE");
} }
} }
@@ -95,6 +99,11 @@ public class NettySourceClientHandler extends SimpleChannelInboundHandler<String
log.error("源设备消息处理异常, userId: {}, message: {}", userId, msg, e); log.error("源设备消息处理异常, userId: {}, message: {}", userId, msg, e);
// 发生异常时退出发送,避免后续问题 // 发生异常时退出发送,避免后续问题
CnSocketUtil.quitSend(webUser); CnSocketUtil.quitSend(webUser);
// 业务消息处理异常 → 释放检测锁
if (StrUtil.isNotBlank(userId)) {
DetectionLockManager.getInstance()
.releaseIfMatchPage(userId, "SOURCE_READ_EXCEPTION");
}
} }
} }
@@ -136,6 +145,13 @@ public class NettySourceClientHandler extends SimpleChannelInboundHandler<String
// 发生异常时关闭通道 // 发生异常时关闭通道
ctx.close(); ctx.close();
// 源通道异常 → 释放检测锁
String userIdForRelease = webUser != null ? webUser.getUserPageId() : null;
if (StrUtil.isNotBlank(userIdForRelease)) {
DetectionLockManager.getInstance()
.releaseIfMatchPage(userIdForRelease, "SOURCE_EXCEPTION");
}
} }
} }

View File

@@ -1,6 +1,7 @@
package com.njcn.gather.detection.util.socket.websocket; package com.njcn.gather.detection.util.socket.websocket;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.njcn.gather.detection.lock.DetectionLockManager;
import com.njcn.gather.detection.pojo.param.PreDetectionParam; import com.njcn.gather.detection.pojo.param.PreDetectionParam;
import com.njcn.gather.detection.pojo.vo.WebSocketVO; import com.njcn.gather.detection.pojo.vo.WebSocketVO;
import com.njcn.gather.detection.pojo.enums.SourceOperateCodeEnum; import com.njcn.gather.detection.pojo.enums.SourceOperateCodeEnum;
@@ -296,6 +297,8 @@ public class WebServiceManager {
webSocketVO.setData(errorType.getMsg()); webSocketVO.setData(errorType.getMsg());
webSocketVO.setOperateCode(errorType.getValue()); webSocketVO.setOperateCode(errorType.getValue());
sendMessage(userId, webSocketVO); sendMessage(userId, webSocketVO);
// 守门员:错误推送即视为本次检测终态,释放检测锁(幂等,与显式释放点叠加双保险)
releaseLockOnTerminal(userId, errorType);
} }
/** /**
@@ -313,6 +316,25 @@ public class WebServiceManager {
webSocketVO.setData(errorType.getMsg()); webSocketVO.setData(errorType.getMsg());
webSocketVO.setOperateCode(errorType.getValue()); webSocketVO.setOperateCode(errorType.getValue());
sendMessage(userId, webSocketVO); sendMessage(userId, webSocketVO);
// 守门员:理由同上
releaseLockOnTerminal(userId, errorType);
}
/**
* 守门员释放锁
* <p>覆盖业务回调里所有走 {@code sendDetectionErrorMessage} 的失败路径,
* 等价于在 detection/handler 全目录的错误终态点显式释放。与各 Netty handler
* 内的显式释放幂等叠加,形成双保险。</p>
*
* <p>注:业务"正常完成"路径不走此方法(数模式 formalDeal 已在 Phase 1 显式释放;
* 比对模式正常完成走 sendMsg 推 ERROR_FLOW_END依赖 WS 断开后心跳超时兜底)。</p>
*/
private static void releaseLockOnTerminal(String userId, SourceOperateCodeEnum errorType) {
if (userId == null || userId.isEmpty()) {
return;
}
DetectionLockManager.getInstance()
.releaseIfMatchPage(userId, "WS_ERROR_PUSH:" + errorType.name());
} }
} }

View File

@@ -1,6 +1,7 @@
package com.njcn.gather.detection.util.socket.websocket; package com.njcn.gather.detection.util.socket.websocket;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import com.njcn.gather.detection.lock.DetectionLockManager;
import com.njcn.gather.detection.pojo.enums.SourceOperateCodeEnum; import com.njcn.gather.detection.pojo.enums.SourceOperateCodeEnum;
import com.njcn.gather.detection.pojo.param.PreDetectionParam; import com.njcn.gather.detection.pojo.param.PreDetectionParam;
import com.njcn.gather.detection.util.socket.CnSocketUtil; import com.njcn.gather.detection.util.socket.CnSocketUtil;
@@ -414,6 +415,11 @@ public class WebSocketHandler extends SimpleChannelInboundHandler<TextWebSocketF
} }
// 清理完成后移除该用户的检测参数 // 清理完成后移除该用户的检测参数
WebServiceManager.removePreDetectionParam(userId); WebServiceManager.removePreDetectionParam(userId);
// R3 释放WS 断开 / 客户端关页面 / 心跳超时后顺手释放检测锁
if (preDetectionParam.getUserPageId() != null) {
DetectionLockManager.getInstance()
.releaseIfMatchPage(preDetectionParam.getUserPageId(), "WS_DISCONNECTED");
}
} }
} catch (Exception e) { } catch (Exception e) {
log.error("清理Socket连接时发生异常userId: {}", userId, e); log.error("清理Socket连接时发生异常userId: {}", userId, e);

View File

@@ -169,4 +169,24 @@ public class PqDevController extends BaseController {
Map<String, List<String>> result = pqDevService.listSelectOptions(pattern); Map<String, List<String>> result = pqDevService.listSelectOptions(pattern);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe); return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
} }
@OperateInfo(info = LogEnum.BUSINESS_COMMON, operateType = OperateType.UPLOAD)
@PostMapping(value = "/ttt")
@ApiOperation("批量导入被检设备")
@ApiImplicitParams({
@ApiImplicitParam(name = "file", value = "被检设备数据文件", required = true),
@ApiImplicitParam(name = "patternId", value = "模式id", required = true)
})
public HttpResult ttt(@RequestParam("file") MultipartFile file, @RequestParam("patternId") String patternId, @RequestParam("planId") String planId, @RequestParam(value = "cover", defaultValue = "0") Integer cover, HttpServletResponse response) {
String methodDescribe = getMethodDescribe("ttt");
LogUtil.njcnDebug(log, "{},上传文件为:{}", methodDescribe, file.getOriginalFilename());
boolean fileType = FileUtil.judgeFileIsExcel(file.getOriginalFilename());
if (!fileType) {
throw new BusinessException(CommonResponseEnum.FILE_XLSX_ERROR);
}
if ("null".equals(planId)) {
planId = null;
}
return pqDevService.importDev(file, patternId, planId, response, cover);
}
} }

View File

@@ -12,6 +12,7 @@ import com.njcn.common.pojo.response.HttpResult;
import com.njcn.common.utils.LogUtil; import com.njcn.common.utils.LogUtil;
import com.njcn.gather.device.pojo.param.PqStandardDevParam; import com.njcn.gather.device.pojo.param.PqStandardDevParam;
import com.njcn.gather.device.pojo.po.PqStandardDev; import com.njcn.gather.device.pojo.po.PqStandardDev;
import com.njcn.gather.device.pojo.vo.PqStandardDevVO;
import com.njcn.gather.device.service.IPqStandardDevService; import com.njcn.gather.device.service.IPqStandardDevService;
import com.njcn.web.controller.BaseController; import com.njcn.web.controller.BaseController;
import com.njcn.web.utils.FileUtil; import com.njcn.web.utils.FileUtil;
@@ -55,10 +56,10 @@ public class PqStandardDevController extends BaseController {
@GetMapping("/getById") @GetMapping("/getById")
@ApiOperation("根据id查询标准设备") @ApiOperation("根据id查询标准设备")
@ApiImplicitParam(name = "id", value = "标准设备id", required = true) @ApiImplicitParam(name = "id", value = "标准设备id", required = true)
public HttpResult<PqStandardDev> getById(@RequestParam("id") String id) { public HttpResult<PqStandardDevVO> getById(@RequestParam("id") String id) {
String methodDescribe = getMethodDescribe("getById"); String methodDescribe = getMethodDescribe("getById");
LogUtil.njcnDebug(log, "{}查询ID为{}", methodDescribe, id); LogUtil.njcnDebug(log, "{}查询ID为{}", methodDescribe, id);
PqStandardDev result = pqStandardDevService.getPqStandardDevById(id); PqStandardDevVO result = pqStandardDevService.getPqStandardDevById(id);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe); return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
} }

View File

@@ -0,0 +1,13 @@
package com.njcn.gather.device.mapper;
import com.github.yulichang.base.MPJBaseMapper;
import com.njcn.gather.device.pojo.po.PqStandardDevGain;
/**
* @author caozehui
* @date 2026-01-12
*/
public interface PqStandardDevGainMapper extends MPJBaseMapper<PqStandardDevGain> {
}

View File

@@ -0,0 +1,13 @@
package com.njcn.gather.device.mapper;
import com.github.yulichang.base.MPJBaseMapper;
import com.njcn.gather.device.pojo.po.PqStandardDevGainRecord;
/**
* @author caozehui
* @date 2026-01-15
*/
public interface PqStandardDevGainRecordMapper extends MPJBaseMapper<PqStandardDevGainRecord> {
}

View File

@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.njcn.gather.device.mapper.PqStandardDevGainMapper">
</mapper>

View File

@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.njcn.gather.device.mapper.PqStandardDevGainRecordMapper">
</mapper>

View File

@@ -0,0 +1,61 @@
package com.njcn.gather.device.pojo.po;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.njcn.db.mybatisplus.bo.BaseEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.io.Serializable;
/**
* @author caozehui
* @date 2026-01-12
*/
@Data
@EqualsAndHashCode(callSuper = true)
@TableName("pq_standard_dev_gain")
public class PqStandardDevGain extends BaseEntity implements Serializable {
private static final long serialVersionUID = -46280767885558804L;
/**
* 标准设备Id_通道号
*/
@TableId
private String stdDevMonitorId;
private Integer uaGain;
private Integer ubGain;
private Integer ucGain;
private Integer u0Gain;
private Integer iaGain;
private Integer ibGain;
private Integer icGain;
private Integer i0Gain;
private Integer uabGain;
private Integer ubcGain;
private Integer ucaGain;
private Integer state;
}

View File

@@ -0,0 +1,35 @@
package com.njcn.gather.device.pojo.po;
import com.baomidou.mybatisplus.annotation.TableName;
import com.njcn.db.mybatisplus.bo.BaseEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.io.Serializable;
/**
* @author caozehui
* @date 2026-01-15
*/
@Data
@TableName("pq_standard_dev_gain_record")
public class PqStandardDevGainRecord implements Serializable {
private static final long serialVersionUID = 477276215572686991L;
/**
* 标准设备监测点id,由设备id_通道号组成
*/
private String stdDevMonitorId;
/**
* 被检设备监测点id,由设备id_通道号组成
*/
private String devMonitorId;
/**
* 系数下发次数
*/
private Integer num;
}

View File

@@ -38,8 +38,8 @@ public class ContrastDevExcel implements Serializable {
@Pattern(regexp = PatternRegex.DEV_NAME_REGEX, message = DetectionValidMessage.NAME_FORMAT_ERROR) @Pattern(regexp = PatternRegex.DEV_NAME_REGEX, message = DetectionValidMessage.NAME_FORMAT_ERROR)
private String name; private String name;
@Excel(name = "设备序列号*", width = 20, needMerge = true, orderNum = "5") @Excel(name = "设备序列号", width = 20, needMerge = true, orderNum = "5")
@NotBlank(message = DetectionValidMessage.FACTORYNO_NOT_BLANK) // @NotBlank(message = DetectionValidMessage.FACTORYNO_NOT_BLANK)
private String createId; private String createId;
@Excel(name = "设备类型*", width = 20, needMerge = true, orderNum = "6") @Excel(name = "设备类型*", width = 20, needMerge = true, orderNum = "6")
@@ -91,8 +91,8 @@ public class ContrastDevExcel implements Serializable {
@NotNull(message = DetectionValidMessage.INSPECT_DATE_NOT_NULL) @NotNull(message = DetectionValidMessage.INSPECT_DATE_NOT_NULL)
private LocalDate inspectDate; private LocalDate inspectDate;
@Excel(name = "谐波系统设备id*", width = 30, needMerge = true, orderNum = "18") @Excel(name = "谐波系统设备id", width = 30, needMerge = true, orderNum = "18")
@NotBlank(message = DetectionValidMessage.HARM_SYS_ID_NOT_BLANK) // @NotBlank(message = DetectionValidMessage.HARM_SYS_ID_NOT_BLANK)
private String harmSysId; private String harmSysId;
@ExcelCollection(name = "监测点信息", orderNum = "19") @ExcelCollection(name = "监测点信息", orderNum = "19")

View File

@@ -0,0 +1,20 @@
package com.njcn.gather.device.pojo.vo;
import com.njcn.gather.device.pojo.po.PqStandardDev;
import com.njcn.gather.device.pojo.po.PqStandardDevGain;
import lombok.Data;
import java.util.List;
/**
* @author caozehui
* @data 2026-01-19
*/
@Data
public class PqStandardDevVO extends PqStandardDev {
/**
* 通道系数
*/
List<PqStandardDevGain> gainList;
}

View File

@@ -115,9 +115,10 @@ public interface IPqDevService extends IService<PqDev> {
* @param userId * @param userId
* @param temperature * @param temperature
* @param humidity * @param humidity
* @param updateCheckNum 是否更新检测次数
* @return * @return
*/ */
boolean updateResult(List<String> ids, List<String> adType, String code, String userId, Float temperature, Float humidity); boolean updateResult(List<String> ids, List<String> adType, String code, String userId, Float temperature, Float humidity, boolean updateCheckNum);
/** /**
* 比对式-修改设备状态 * 比对式-修改设备状态

View File

@@ -0,0 +1,29 @@
package com.njcn.gather.device.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.njcn.gather.device.pojo.po.PqStandardDevGainRecord;
import java.util.List;
/**
* @author caozehui
* @date 2026-01-15
*/
public interface IPqStandardDevGainRecordService extends IService<PqStandardDevGainRecord> {
/**
* 获取最大下发系数的次数
*
* @param stdDevMonitorId
* @param devMonitorId
* @return
*/
int getMaxNum(String stdDevMonitorId, String devMonitorId);
/**
* 批量新增或更新记录
* @param recordList
* @return
*/
boolean addOrUpdate(List<PqStandardDevGainRecord> recordList);
}

View File

@@ -0,0 +1,19 @@
package com.njcn.gather.device.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.njcn.gather.device.pojo.po.PqStandardDevGain;
import java.util.List;
/**
* @author caozehui
* @date 2026-01-12
*/
public interface IPqStandardDevGainService extends IService<PqStandardDevGain> {
boolean add(List<PqStandardDevGain> pqStandardDevGainList);
PqStandardDevGain get(String stdDevMonitorId);
List<PqStandardDevGain> list(String stdDevId);
}

View File

@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import com.njcn.gather.device.pojo.param.PqStandardDevParam; import com.njcn.gather.device.pojo.param.PqStandardDevParam;
import com.njcn.gather.device.pojo.po.PqStandardDev; import com.njcn.gather.device.pojo.po.PqStandardDev;
import com.njcn.gather.device.pojo.vo.PqStandardDevVO;
import com.njcn.gather.device.pojo.vo.PreDetection; import com.njcn.gather.device.pojo.vo.PreDetection;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
@@ -30,7 +31,7 @@ public interface IPqStandardDevService extends IService<PqStandardDev> {
* @param id 设备id * @param id 设备id
* @return 设备对象 * @return 设备对象
*/ */
PqStandardDev getPqStandardDevById(String id); PqStandardDevVO getPqStandardDevById(String id);
/** /**
* 新增标准设备 * 新增标准设备

View File

@@ -38,6 +38,9 @@ import com.njcn.gather.monitor.pojo.po.PqMonitor;
import com.njcn.gather.monitor.pojo.vo.PqMonitorExcel; import com.njcn.gather.monitor.pojo.vo.PqMonitorExcel;
import com.njcn.gather.monitor.service.IPqMonitorService; import com.njcn.gather.monitor.service.IPqMonitorService;
import com.njcn.gather.plan.pojo.enums.DataSourceEnum; import com.njcn.gather.plan.pojo.enums.DataSourceEnum;
import com.njcn.gather.plan.mapper.AdPlanMapper;
import com.njcn.gather.plan.pojo.po.AdPlan;
import com.njcn.gather.plan.service.IPqDevCheckHistoryService;
import com.njcn.gather.pojo.enums.DetectionResponseEnum; import com.njcn.gather.pojo.enums.DetectionResponseEnum;
import com.njcn.gather.storage.service.DetectionDataDealService; import com.njcn.gather.storage.service.DetectionDataDealService;
import com.njcn.gather.system.cfg.pojo.enums.SceneEnum; import com.njcn.gather.system.cfg.pojo.enums.SceneEnum;
@@ -68,6 +71,7 @@ import java.time.LocalDateTime;
import java.util.*; import java.util.*;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.Stream;
/** /**
* @author caozehui * @author caozehui
@@ -86,6 +90,8 @@ public class PqDevServiceImpl extends ServiceImpl<PqDevMapper, PqDev> implements
private final IDictTypeService dictTypeService; private final IDictTypeService dictTypeService;
private final ISysUserService userService; private final ISysUserService userService;
private final IPqDevSubService pqDevSubService; private final IPqDevSubService pqDevSubService;
private final AdPlanMapper adPlanMapper;
private final IPqDevCheckHistoryService pqDevCheckHistoryService;
@Override @Override
public Page<PqDevVO> listPqDevs(PqDevParam.QueryParam queryParam) { public Page<PqDevVO> listPqDevs(PqDevParam.QueryParam queryParam) {
@@ -482,7 +488,7 @@ public class PqDevServiceImpl extends ServiceImpl<PqDevMapper, PqDev> implements
@Override @Override
public boolean updateResult(List<String> ids, List<String> adType, String code, String userId, Float temperature, Float humidity) { public boolean updateResult(List<String> ids, List<String> adType, String code, String userId, Float temperature, Float humidity, boolean updateCheckNum) {
if (CollUtil.isNotEmpty(ids)) { if (CollUtil.isNotEmpty(ids)) {
SysTestConfig config = sysTestConfigService.getOneConfig(); SysTestConfig config = sysTestConfigService.getOneConfig();
@@ -514,13 +520,18 @@ public class PqDevServiceImpl extends ServiceImpl<PqDevMapper, PqDev> implements
checkState = CheckStateEnum.DOCUMENTED.getValue(); checkState = CheckStateEnum.DOCUMENTED.getValue();
i = pqDevVo.getRecheckNum(); i = pqDevVo.getRecheckNum();
} else { } else {
checkState = CheckStateEnum.CHECKED.getValue(); checkState = pqDevVo.getCheckState() == CheckStateEnum.DOCUMENTED.getValue() ? CheckStateEnum.DOCUMENTED.getValue() : CheckStateEnum.CHECKED.getValue();
i = pqDevVo.getRecheckNum() + 1; if (updateCheckNum) {
i = pqDevVo.getRecheckNum() + 1;
} else {
i = pqDevVo.getRecheckNum();
}
wrapper.set(PqDevSub::getReportState, DevReportStateEnum.NOT_GENERATED.getValue()); wrapper.set(PqDevSub::getReportState, DevReportStateEnum.NOT_GENERATED.getValue());
} }
wrapper.set(PqDevSub::getRecheckNum, i) wrapper.set(PqDevSub::getRecheckNum, i)
.set(PqDevSub::getCheckState, checkState); .set(PqDevSub::getCheckState, checkState);
pqDevSubService.update(wrapper); pqDevSubService.update(wrapper);
saveCheckHistory(pqDevVo, i, checkState, userId);
PqDevParam.QueryParam param = new PqDevParam.QueryParam(); PqDevParam.QueryParam param = new PqDevParam.QueryParam();
param.setPlanIdList(Arrays.asList(pqDevVo.getPlanId())); param.setPlanIdList(Arrays.asList(pqDevVo.getPlanId()));
@@ -586,6 +597,7 @@ public class PqDevServiceImpl extends ServiceImpl<PqDevMapper, PqDev> implements
w.set(PqDevSub::getReportState, DevReportStateEnum.NOT_GENERATED.getValue()); w.set(PqDevSub::getReportState, DevReportStateEnum.NOT_GENERATED.getValue());
} }
w.update(); w.update();
saveCheckHistory(devId, userId);
PqDevParam.QueryParam param = new PqDevParam.QueryParam(); PqDevParam.QueryParam param = new PqDevParam.QueryParam();
String planId = dev.getPlanId(); String planId = dev.getPlanId();
@@ -621,6 +633,37 @@ public class PqDevServiceImpl extends ServiceImpl<PqDevMapper, PqDev> implements
} }
} }
private void saveCheckHistory(PqDevVO pqDevVo, Integer recheckNum, Integer checkState, String userId) {
if (ObjectUtil.isNull(pqDevVo)
|| (!CheckStateEnum.CHECKED.getValue().equals(checkState) && !CheckStateEnum.DOCUMENTED.getValue().equals(checkState))) {
return;
}
AdPlan plan = adPlanMapper.selectById(pqDevVo.getPlanId());
if (ObjectUtil.isNull(plan)) {
return;
}
pqDevVo.setRecheckNum(recheckNum);
pqDevVo.setCheckBy(userId);
pqDevVo.setCheckTime(LocalDateTime.now());
pqDevCheckHistoryService.saveOrUpdateDeviceHistory(plan, pqDevVo);
}
private void saveCheckHistory(String devId, String userId) {
PqDevVO pqDevVo = this.baseMapper.selectByDevId(devId);
if (ObjectUtil.isNull(pqDevVo)
|| (!CheckStateEnum.CHECKED.getValue().equals(pqDevVo.getCheckState()) && !CheckStateEnum.DOCUMENTED.getValue().equals(pqDevVo.getCheckState()))) {
return;
}
AdPlan plan = adPlanMapper.selectById(pqDevVo.getPlanId());
if (ObjectUtil.isNull(plan)) {
return;
}
if (StrUtil.isBlank(pqDevVo.getCheckBy())) {
pqDevVo.setCheckBy(userId);
}
pqDevCheckHistoryService.saveOrUpdateDeviceHistory(plan, pqDevVo);
}
@Override @Override
public void updatePqDevReportState(String devId, int reportState) { public void updatePqDevReportState(String devId, int reportState) {
LambdaUpdateWrapper<PqDevSub> updateWrapper = new LambdaUpdateWrapper<>(); LambdaUpdateWrapper<PqDevSub> updateWrapper = new LambdaUpdateWrapper<>();
@@ -1340,9 +1383,11 @@ public class PqDevServiceImpl extends ServiceImpl<PqDevMapper, PqDev> implements
if (CollUtil.isNotEmpty(hasList)) { if (CollUtil.isNotEmpty(hasList)) {
importPqDev.setId(hasList.get(0).getId()); importPqDev.setId(hasList.get(0).getId());
for (PqMonitorExcel pqMonitorExcel : pqMonitorExcelList) { for (PqMonitorExcel pqMonitorExcel : pqMonitorExcelList) {
PqMonitor pqMonitor = BeanUtil.copyProperties(pqMonitorExcel, PqMonitor.class); PqMonitor monitor = BeanUtil.copyProperties(pqMonitorExcel, PqMonitor.class);
pqMonitor.setDevId(importPqDev.getId()); monitor.setDevId(importPqDev.getId());
monitorList.add(pqMonitor); monitor.setPt(pqMonitorExcel.getPt1() + StrUtil.C_COLON + pqMonitorExcel.getPt2());
monitor.setCt(pqMonitorExcel.getCt1() + StrUtil.C_COLON + pqMonitorExcel.getCt2());
monitorList.add(monitor);
} }
importPqDev.setMonitorList(monitorList); importPqDev.setMonitorList(monitorList);
finalUpdateDevList.add(importPqDev); finalUpdateDevList.add(importPqDev);
@@ -1366,6 +1411,8 @@ public class PqDevServiceImpl extends ServiceImpl<PqDevMapper, PqDev> implements
for (PqMonitorExcel pqMonitorExcel : pqMonitorExcelList) { for (PqMonitorExcel pqMonitorExcel : pqMonitorExcelList) {
PqMonitor monitor = BeanUtil.copyProperties(pqMonitorExcel, PqMonitor.class); PqMonitor monitor = BeanUtil.copyProperties(pqMonitorExcel, PqMonitor.class);
monitor.setDevId(importPqDev.getId()); monitor.setDevId(importPqDev.getId());
monitor.setPt(pqMonitorExcel.getPt1() + StrUtil.C_COLON + pqMonitorExcel.getPt2());
monitor.setCt(pqMonitorExcel.getCt1() + StrUtil.C_COLON + pqMonitorExcel.getCt2());
monitorList.add(monitor); monitorList.add(monitor);
} }
importPqDev.setMonitorList(monitorList); importPqDev.setMonitorList(monitorList);
@@ -1375,6 +1422,8 @@ public class PqDevServiceImpl extends ServiceImpl<PqDevMapper, PqDev> implements
for (PqMonitorExcel pqMonitorExcel : pqMonitorExcelList) { for (PqMonitorExcel pqMonitorExcel : pqMonitorExcelList) {
PqMonitor monitor = BeanUtil.copyProperties(pqMonitorExcel, PqMonitor.class); PqMonitor monitor = BeanUtil.copyProperties(pqMonitorExcel, PqMonitor.class);
monitor.setDevId(importPqDev.getId()); monitor.setDevId(importPqDev.getId());
monitor.setPt(pqMonitorExcel.getPt1() + StrUtil.C_COLON + pqMonitorExcel.getPt2());
monitor.setCt(pqMonitorExcel.getCt1() + StrUtil.C_COLON + pqMonitorExcel.getCt2());
monitorList.add(monitor); monitorList.add(monitor);
} }
importPqDev.setMonitorList(monitorList); importPqDev.setMonitorList(monitorList);
@@ -1496,13 +1545,19 @@ public class PqDevServiceImpl extends ServiceImpl<PqDevMapper, PqDev> implements
if (ObjectUtil.isNotNull(dictType)) { if (ObjectUtil.isNotNull(dictType)) {
dictDataList = dictDataService.getDictDataByTypeId(dictType.getId()); dictDataList = dictDataService.getDictDataByTypeId(dictType.getId());
pullDown = new PullDown(); pullDown = new PullDown();
pullDown.setFirstCol(startCol + 24); pullDown.setFirstCol(startCol + 26);
pullDown.setLastCol(startCol + 24); pullDown.setLastCol(startCol + 26);
pullDown.setStrings(dictDataList.stream().map(DictData::getName).collect(Collectors.toList())); pullDown.setStrings(dictDataList.stream().map(DictData::getName).collect(Collectors.toList()));
pullDowns.add(pullDown); pullDowns.add(pullDown);
} }
pullDown = new PullDown();
pullDown.setFirstCol(startCol + 27);
pullDown.setLastCol(startCol + 27);
pullDown.setStrings(Stream.iterate(1, x -> x + 1).limit(10).map(String::valueOf).collect(Collectors.toList()));
pullDowns.add(pullDown);
return pullDowns; return pullDowns;
} }
@@ -1564,7 +1619,22 @@ public class PqDevServiceImpl extends ServiceImpl<PqDevMapper, PqDev> implements
contrastDevExcels.forEach(contrastDevExcel -> { contrastDevExcels.forEach(contrastDevExcel -> {
List<PqMonitor> monitorList = pqMonitorService.listPqMonitorByDevIds(Collections.singletonList(contrastDevExcel.getId())); List<PqMonitor> monitorList = pqMonitorService.listPqMonitorByDevIds(Collections.singletonList(contrastDevExcel.getId()));
pqMonitorService.visualizeMonitor(monitorList); pqMonitorService.visualizeMonitor(monitorList);
List<PqMonitorExcel> pqMonitorExcelList = BeanUtil.copyToList(monitorList, PqMonitorExcel.class); List<PqMonitorExcel> pqMonitorExcelList = new ArrayList<>();
for (int i = 0; i < monitorList.size(); i++) {
PqMonitor pqMonitor = monitorList.get(i);
PqMonitorExcel pqMonitorExcel = BeanUtil.copyProperties(pqMonitor, PqMonitorExcel.class);
String pt = pqMonitor.getPt();
String[] split1 = pt.split(String.valueOf(StrUtil.C_COLON));
pqMonitorExcel.setPt1(split1[0]);
pqMonitorExcel.setPt2(split1[1]);
String ct = pqMonitor.getCt();
String[] split2 = ct.split(String.valueOf(StrUtil.C_COLON));
pqMonitorExcel.setCt1(split2[0]);
pqMonitorExcel.setCt2(split2[1]);
pqMonitorExcelList.add(pqMonitorExcel);
}
contrastDevExcel.setPqMonitorExcelList(pqMonitorExcelList); contrastDevExcel.setPqMonitorExcelList(pqMonitorExcelList);
}); });
} }

View File

@@ -0,0 +1,45 @@
package com.njcn.gather.device.service.impl;
import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.njcn.gather.device.mapper.PqStandardDevGainRecordMapper;
import com.njcn.gather.device.pojo.po.PqStandardDevGainRecord;
import com.njcn.gather.device.service.IPqStandardDevGainRecordService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* @author caozehui
* @date 2026-01-15
*/
@Slf4j
@Service
@RequiredArgsConstructor
public class PqStandardDevGainRecordServiceImpl extends ServiceImpl<PqStandardDevGainRecordMapper, PqStandardDevGainRecord> implements IPqStandardDevGainRecordService {
@Override
public int getMaxNum(String stdDevMonitorId, String devMonitorId) {
return this.lambdaQuery().eq(PqStandardDevGainRecord::getStdDevMonitorId, stdDevMonitorId)
.eq(PqStandardDevGainRecord::getDevMonitorId, devMonitorId)
.list().stream().mapToInt(PqStandardDevGainRecord::getNum).max().orElse(0);
}
@Override
public boolean addOrUpdate(List<PqStandardDevGainRecord> recordList) {
recordList.forEach(record -> {
List<PqStandardDevGainRecord> list = this.lambdaQuery().eq(PqStandardDevGainRecord::getStdDevMonitorId, record.getStdDevMonitorId())
.eq(PqStandardDevGainRecord::getDevMonitorId, record.getDevMonitorId()).list();
if (CollectionUtil.isNotEmpty(list)) {
this.lambdaUpdate().eq(PqStandardDevGainRecord::getStdDevMonitorId, record.getStdDevMonitorId())
.eq(PqStandardDevGainRecord::getDevMonitorId, record.getDevMonitorId())
.set(PqStandardDevGainRecord::getNum, record.getNum()).update();
} else {
this.save(record);
}
});
return true;
}
}

View File

@@ -0,0 +1,42 @@
package com.njcn.gather.device.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.njcn.gather.device.mapper.PqStandardDevGainMapper;
import com.njcn.gather.device.pojo.po.PqStandardDevGain;
import com.njcn.gather.device.service.IPqStandardDevGainService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.stream.Collectors;
/**
* @author caozehui
* @date 2026-01-12
*/
@Slf4j
@Service
@RequiredArgsConstructor
public class PqStandardDevGainServiceImpl extends ServiceImpl<PqStandardDevGainMapper, PqStandardDevGain> implements IPqStandardDevGainService {
@Override
public boolean add(List<PqStandardDevGain> pqStandardDevGainList) {
log.info("add PqStandardDevGainList: {}", pqStandardDevGainList.size());
List<String> stdMonitorIdList = pqStandardDevGainList.stream().map(PqStandardDevGain::getStdDevMonitorId).distinct().collect(Collectors.toList());
List<String> existingStdMonitorIdList = this.listByIds(stdMonitorIdList).stream().map(PqStandardDevGain::getStdDevMonitorId).collect(Collectors.toList());
pqStandardDevGainList = pqStandardDevGainList.stream().filter(pqStandardDevGain -> !existingStdMonitorIdList.contains(pqStandardDevGain.getStdDevMonitorId())).collect(Collectors.toList());
return this.saveBatch(pqStandardDevGainList);
}
@Override
public PqStandardDevGain get(String stdDevMonitorId) {
return this.lambdaQuery().eq(PqStandardDevGain::getStdDevMonitorId, stdDevMonitorId).one();
}
@Override
public List<PqStandardDevGain> list(String stdDevId) {
return this.lambdaQuery().likeRight(PqStandardDevGain::getStdDevMonitorId, stdDevId).orderByAsc(PqStandardDevGain::getStdDevMonitorId).list();
}
}

View File

@@ -19,8 +19,11 @@ import com.njcn.common.utils.EncryptionUtil;
import com.njcn.gather.device.mapper.PqStandardDevMapper; import com.njcn.gather.device.mapper.PqStandardDevMapper;
import com.njcn.gather.device.pojo.param.PqStandardDevParam; import com.njcn.gather.device.pojo.param.PqStandardDevParam;
import com.njcn.gather.device.pojo.po.PqStandardDev; import com.njcn.gather.device.pojo.po.PqStandardDev;
import com.njcn.gather.device.pojo.po.PqStandardDevGain;
import com.njcn.gather.device.pojo.vo.PqStandardDevExcel; import com.njcn.gather.device.pojo.vo.PqStandardDevExcel;
import com.njcn.gather.device.pojo.vo.PqStandardDevVO;
import com.njcn.gather.device.pojo.vo.PreDetection; import com.njcn.gather.device.pojo.vo.PreDetection;
import com.njcn.gather.device.service.IPqStandardDevGainService;
import com.njcn.gather.device.service.IPqStandardDevService; import com.njcn.gather.device.service.IPqStandardDevService;
import com.njcn.gather.plan.mapper.AdPlanStandardDevMapper; import com.njcn.gather.plan.mapper.AdPlanStandardDevMapper;
import com.njcn.gather.plan.service.IAdPlanStandardDevService; import com.njcn.gather.plan.service.IAdPlanStandardDevService;
@@ -58,8 +61,7 @@ public class PqStandardDevServiceImpl extends ServiceImpl<PqStandardDevMapper, P
private final IDevTypeService devTypeService; private final IDevTypeService devTypeService;
private final IDictDataService dictDataService; private final IDictDataService dictDataService;
private final IDictTypeService dictTypeService; private final IDictTypeService dictTypeService;
private final AdPlanStandardDevMapper adPlanStandardDevMapper; private final IPqStandardDevGainService pqStandardDevGainService;
private final IAdPlanStandardDevService adPlanStandardDevService;
@Override @Override
public Page<PqStandardDev> listPqStandardDevs(PqStandardDevParam.QueryParam queryParam) { public Page<PqStandardDev> listPqStandardDevs(PqStandardDevParam.QueryParam queryParam) {
@@ -73,13 +75,17 @@ public class PqStandardDevServiceImpl extends ServiceImpl<PqStandardDevMapper, P
} }
@Override @Override
public PqStandardDev getPqStandardDevById(String id) { public PqStandardDevVO getPqStandardDevById(String id) {
PqStandardDev standardDev = this.getById(id); PqStandardDev standardDev = this.getById(id);
PqStandardDevVO pqStandardDevVO = BeanUtil.copyProperties(standardDev, PqStandardDevVO.class);
if (standardDev.getEncryptionFlag() == 1) { if (standardDev.getEncryptionFlag() == 1) {
standardDev.setSeries(EncryptionUtil.decoderString(1, standardDev.getSeries())); pqStandardDevVO.setSeries(EncryptionUtil.decoderString(1, standardDev.getSeries()));
standardDev.setDevKey(EncryptionUtil.decoderString(1, standardDev.getDevKey())); pqStandardDevVO.setDevKey(EncryptionUtil.decoderString(1, standardDev.getDevKey()));
} }
return standardDev;
List<PqStandardDevGain> gainList = pqStandardDevGainService.list(id);
pqStandardDevVO.setGainList(gainList);
return pqStandardDevVO;
} }
@Override @Override

View File

@@ -60,7 +60,7 @@ public class PqIcdPathController extends BaseController {
@PostMapping("/add") @PostMapping("/add")
@ApiOperation("新增icd") @ApiOperation("新增icd")
@ApiImplicitParam(name = "param", value = "icd新增参数", required = true) @ApiImplicitParam(name = "param", value = "icd新增参数", required = true)
public HttpResult<Boolean> add(@RequestBody @Validated PqIcdPathParam param) { public HttpResult<Boolean> add(PqIcdPathParam param) {
String methodDescribe = getMethodDescribe("add"); String methodDescribe = getMethodDescribe("add");
LogUtil.njcnDebug(log, "{},新增数据为:{}", methodDescribe, param); LogUtil.njcnDebug(log, "{},新增数据为:{}", methodDescribe, param);
@@ -76,7 +76,7 @@ public class PqIcdPathController extends BaseController {
@PostMapping("/update") @PostMapping("/update")
@ApiOperation("修改icd") @ApiOperation("修改icd")
@ApiImplicitParam(name = "param", value = "icd修改参数", required = true) @ApiImplicitParam(name = "param", value = "icd修改参数", required = true)
public HttpResult<Boolean> update(@RequestBody @Validated PqIcdPathParam.UpdateParam param) { public HttpResult<Boolean> update(PqIcdPathParam.UpdateParam param) {
String methodDescribe = getMethodDescribe("update"); String methodDescribe = getMethodDescribe("update");
LogUtil.njcnDebug(log, "{},修改数据为:{}", methodDescribe, param); LogUtil.njcnDebug(log, "{},修改数据为:{}", methodDescribe, param);

View File

@@ -0,0 +1,19 @@
package com.njcn.gather.icd.pojo.enums;
/**
* @author caozehui
* @data 2025-11-11
*/
public enum IcdResponseEnum {
FILE_NOT_NULL("A018001", "映射文件不能为空"),
FILE_TYPE_ERROR("A018002", "映射文件类型错误"),
FILE_SIZE_ERROR("A018003", "映射文件大小超出限制");
private String code;
private String message;
IcdResponseEnum(String code, String message) {
this.code = code;
this.message = message;
}
}

View File

@@ -6,6 +6,7 @@ import com.njcn.web.pojo.param.BaseParam;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
import org.springframework.web.multipart.MultipartFile;
import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Pattern; import javax.validation.constraints.Pattern;
@@ -32,6 +33,9 @@ public class PqIcdPathParam {
@ApiModelProperty(value = "角型接线时是否使用相别的指标来进行检测0表示否1表示是", required = true) @ApiModelProperty(value = "角型接线时是否使用相别的指标来进行检测0表示否1表示是", required = true)
private Integer usePhaseIndex; private Integer usePhaseIndex;
@ApiModelProperty(value = "映射文件", required = true)
private MultipartFile mappingFile;
/** /**
* 分页查询实体 * 分页查询实体
*/ */

View File

@@ -1,5 +1,6 @@
package com.njcn.gather.icd.pojo.po; package com.njcn.gather.icd.pojo.po;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName; import com.baomidou.mybatisplus.annotation.TableName;
import com.njcn.db.mybatisplus.bo.BaseEntity; import com.njcn.db.mybatisplus.bo.BaseEntity;
import lombok.Data; import lombok.Data;
@@ -46,5 +47,18 @@ public class PqIcdPath extends BaseEntity implements Serializable {
* 角型接线时是否使用相别的指标来进行检测0表示否1表示是 * 角型接线时是否使用相别的指标来进行检测0表示否1表示是
*/ */
private Integer usePhaseIndex; private Integer usePhaseIndex;
/**
* 映射文件路径
*/
@TableField(exist = false)
private FileVO mappingFile;
@Data
public static class FileVO{
private String name;
private String url;
}
} }

View File

@@ -1,5 +1,6 @@
package com.njcn.gather.icd.service.impl; package com.njcn.gather.icd.service.impl;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@@ -7,17 +8,26 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.njcn.common.pojo.enums.common.DataStateEnum; import com.njcn.common.pojo.enums.common.DataStateEnum;
import com.njcn.common.pojo.exception.BusinessException; import com.njcn.common.pojo.exception.BusinessException;
import com.njcn.gather.icd.mapper.PqIcdPathMapper; import com.njcn.gather.icd.mapper.PqIcdPathMapper;
import com.njcn.gather.icd.pojo.enums.IcdResponseEnum;
import com.njcn.gather.icd.pojo.param.PqIcdPathParam; import com.njcn.gather.icd.pojo.param.PqIcdPathParam;
import com.njcn.gather.icd.pojo.po.PqIcdPath; import com.njcn.gather.icd.pojo.po.PqIcdPath;
import com.njcn.gather.icd.service.IPqIcdPathService; import com.njcn.gather.icd.service.IPqIcdPathService;
import com.njcn.gather.pojo.enums.DetectionResponseEnum; import com.njcn.gather.pojo.enums.DetectionResponseEnum;
import com.njcn.gather.report.pojo.enums.ReportResponseEnum;
import com.njcn.web.factory.PageFactory; import com.njcn.web.factory.PageFactory;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List; import java.util.List;
/** /**
@@ -41,6 +51,13 @@ public class PqIcdPathServiceImpl extends ServiceImpl<PqIcdPathMapper, PqIcdPath
.like(StrUtil.isNotBlank(param.getName()), PqIcdPath::getName, param.getName()) .like(StrUtil.isNotBlank(param.getName()), PqIcdPath::getName, param.getName())
.orderByDesc(PqIcdPath::getCreateTime); .orderByDesc(PqIcdPath::getCreateTime);
Page<PqIcdPath> page = this.page(new Page<>(PageFactory.getPageNum(param), PageFactory.getPageSize(param)), wrapper); Page<PqIcdPath> page = this.page(new Page<>(PageFactory.getPageNum(param), PageFactory.getPageSize(param)), wrapper);
String commInstallPath = this.getCommInstallPath();
page.getRecords().forEach(pqIcdPath -> {
PqIcdPath.FileVO fileVO = new PqIcdPath.FileVO();
fileVO.setUrl(commInstallPath + "\\DeviceControl\\Config\\" + pqIcdPath.getName() + ".txt");
fileVO.setName(pqIcdPath.getName() + ".txt");
pqIcdPath.setMappingFile(fileVO);
});
return page; return page;
} }
@@ -52,9 +69,81 @@ public class PqIcdPathServiceImpl extends ServiceImpl<PqIcdPathMapper, PqIcdPath
PqIcdPath pqIcdPath = new PqIcdPath(); PqIcdPath pqIcdPath = new PqIcdPath();
BeanUtils.copyProperties(param, pqIcdPath); BeanUtils.copyProperties(param, pqIcdPath);
pqIcdPath.setState(DataStateEnum.ENABLE.getCode()); pqIcdPath.setState(DataStateEnum.ENABLE.getCode());
String commInstallPath = this.getCommInstallPath();
System.out.println("commInstallPath = " + commInstallPath);
long FILE_SIZE_LIMIT = 1 * 1024 * 1024;
MultipartFile mappingFile = param.getMappingFile();
System.out.println("mappingFile = " + ObjectUtil.isNotNull(mappingFile) + " " + !mappingFile.isEmpty());
if (ObjectUtil.isNotNull(mappingFile) && !mappingFile.isEmpty()) {
String mappingFilename = mappingFile.getOriginalFilename();
if (!mappingFilename.endsWith(".txt")) {
throw new BusinessException(IcdResponseEnum.FILE_TYPE_ERROR);
}
if (mappingFile.getSize() > FILE_SIZE_LIMIT) {
throw new BusinessException(IcdResponseEnum.FILE_SIZE_ERROR);
}
try {
// 如果文件存在,则先删除
String mappingFilePath = commInstallPath + "\\DeviceControl\\Config\\" + mappingFilename;
System.out.println("mappingFilePath = " + mappingFilePath);
Path path = Paths.get(mappingFilePath);
File file = path.toFile();
if (file.exists()) {
file.delete();
}
// 保存文件
byte[] bytes = mappingFile.getBytes();
BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(new FileOutputStream(mappingFilePath));
bufferedOutputStream.write(bytes);
bufferedOutputStream.flush();
bufferedOutputStream.close();
System.out.println("File saved successfully");
} catch (IOException e) {
throw new BusinessException(ReportResponseEnum.FILE_UPLOAD_FAILED);
}
} else {
System.out.println("mappingFile is null or empty");
throw new BusinessException(IcdResponseEnum.FILE_NOT_NULL);
}
this.executeRestartCmd(commInstallPath);
return this.save(pqIcdPath); return this.save(pqIcdPath);
} }
/**
* 执行重启通讯服务脚本
*
* @param commInstallPath
*/
private void executeRestartCmd(String commInstallPath) {
// 以管理员身份运行bat脚本
String batFilePath = commInstallPath + "\\重启所有服务.bat";
try {
Runtime.getRuntime().exec(batFilePath);
} catch (IOException e) {
log.error("重启通讯服务失败", e);
}
}
private String getCommInstallPath() {
String workDir = System.getProperty("user.dir");
// String workDir = "D:\\program\\CN_Gather";
// 获取映射文件存放文件夹
String dirPath = workDir + "\\9100";
int index = workDir.indexOf("\\resources\\extraResources\\java");
if (index != -1) {
dirPath = workDir.substring(0, workDir.indexOf("\\resources\\extraResources\\java")) + "\\9100";
}
return dirPath;
}
@Override @Override
@Transactional @Transactional
public boolean updateIcd(PqIcdPathParam.UpdateParam param) { public boolean updateIcd(PqIcdPathParam.UpdateParam param) {
@@ -62,12 +151,60 @@ public class PqIcdPathServiceImpl extends ServiceImpl<PqIcdPathMapper, PqIcdPath
this.checkRepeat(param, true); this.checkRepeat(param, true);
PqIcdPath pqIcdPath = new PqIcdPath(); PqIcdPath pqIcdPath = new PqIcdPath();
BeanUtils.copyProperties(param, pqIcdPath); BeanUtils.copyProperties(param, pqIcdPath);
String commInstallPath = this.getCommInstallPath();
long FILE_SIZE_LIMIT = 1 * 1024 * 1024;
MultipartFile mappingFile = param.getMappingFile();
if (ObjectUtil.isNotNull(mappingFile) && !mappingFile.isEmpty()) {
String mappingFilename = mappingFile.getOriginalFilename();
if (!mappingFilename.endsWith(".txt")) {
throw new BusinessException(IcdResponseEnum.FILE_TYPE_ERROR);
}
if (mappingFile.getSize() > FILE_SIZE_LIMIT) {
throw new BusinessException(IcdResponseEnum.FILE_SIZE_ERROR);
}
try {
// 如果文件存在,则先删除
String mappingFilePath = commInstallPath + "\\DeviceControl\\Config\\" + mappingFilename;
Path path = Paths.get(mappingFilePath);
File file = path.toFile();
if (file.exists()) {
file.delete();
}
// 保存文件
byte[] bytes = mappingFile.getBytes();
BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(new FileOutputStream(mappingFilePath));
bufferedOutputStream.write(bytes);
bufferedOutputStream.flush();
bufferedOutputStream.close();
} catch (IOException e) {
throw new BusinessException(ReportResponseEnum.FILE_UPLOAD_FAILED);
}
}
this.executeRestartCmd(commInstallPath);
return this.updateById(pqIcdPath); return this.updateById(pqIcdPath);
} }
@Override @Override
@Transactional @Transactional
public boolean deleteIcd(List<String> ids) { public boolean deleteIcd(List<String> ids) {
List<PqIcdPath> pqIcdPaths = this.listByIds(ids);
String commInstallPath = this.getCommInstallPath();
pqIcdPaths.forEach(pqIcdPath -> {
String mappingFilePath = commInstallPath + "\\DeviceControl\\Config\\" + pqIcdPath.getName() + ".txt";
Path path = Paths.get(mappingFilePath);
File file = path.toFile();
if (file.exists()) {
file.delete();
}
});
return this.lambdaUpdate().in(PqIcdPath::getId, ids).set(PqIcdPath::getState, DataStateEnum.DELETED.getCode()).update(); return this.lambdaUpdate().in(PqIcdPath::getId, ids).set(PqIcdPath::getState, DataStateEnum.DELETED.getCode()).update();
} }

View File

@@ -14,11 +14,11 @@ import javax.validation.constraints.NotNull;
@Data @Data
public class PqMonitorExcel { public class PqMonitorExcel {
@Excel(name = "谐波系统监测点ID*", width = 20, orderNum = "1") @Excel(name = "谐波系统监测点ID", width = 20, orderNum = "1")
@NotBlank(message = DetectionValidMessage.MONITOR_ID_NOT_BLANK) // @NotBlank(message = DetectionValidMessage.MONITOR_ID_NOT_BLANK)
private String harmSysId; private String harmSysId;
@Excel(name = "所属母线*", width = 20, orderNum = "2") @Excel(name = "母线名称*", width = 20, orderNum = "2")
@NotBlank(message = DetectionValidMessage.BELONG_LINE_NOT_BLANK) @NotBlank(message = DetectionValidMessage.BELONG_LINE_NOT_BLANK)
private String busbar; private String busbar;
@@ -30,19 +30,27 @@ public class PqMonitorExcel {
@NotNull(message = DetectionValidMessage.MONITOR_NUM_NOT_NULL) @NotNull(message = DetectionValidMessage.MONITOR_NUM_NOT_NULL)
private Integer num; private Integer num;
@Excel(name = "PT变比(pt1:pt2)*", width = 20, orderNum = "5") @Excel(name = "PT一次变比*", width = 20, orderNum = "5")
@NotBlank(message = DetectionValidMessage.PT_NOT_BLANK) @NotBlank(message = DetectionValidMessage.PT_NOT_BLANK)
private String pt; private String pt1;
@Excel(name = "CT变比(ct1:ct2)*", width = 20, orderNum = "6") @Excel(name = "PT二次变比*", width = 20, orderNum = "6")
@NotBlank(message = DetectionValidMessage.PT_NOT_BLANK)
private String pt2;
@Excel(name = "CT一次变比*", width = 20, orderNum = "7")
@NotBlank(message = DetectionValidMessage.CT_NOT_BLANK) @NotBlank(message = DetectionValidMessage.CT_NOT_BLANK)
private String ct; private String ct1;
@Excel(name = "接线方式*", width = 20, orderNum = "7") @Excel(name = "CT二次变比*", width = 20, orderNum = "8")
@NotBlank(message = DetectionValidMessage.CT_NOT_BLANK)
private String ct2;
@Excel(name = "接线方式*", width = 20, orderNum = "9")
@NotBlank(message = DetectionValidMessage.CONNECTION_NOT_BLANK) @NotBlank(message = DetectionValidMessage.CONNECTION_NOT_BLANK)
private String connection; private String connection;
@Excel(name = "统计间隔*", width = 10, orderNum = "8") @Excel(name = "统计间隔*", width = 20, orderNum = "10")
@NotNull(message = DetectionValidMessage.STAT_INTERVAL_NOT_NULL) @NotNull(message = DetectionValidMessage.STAT_INTERVAL_NOT_NULL)
private Integer statInterval; private Integer statInterval;
} }

View File

@@ -118,4 +118,11 @@ public interface IPqMonitorService extends IService<PqMonitor> {
* @return * @return
*/ */
boolean removeByDevId(String devId); boolean removeByDevId(String devId);
/**
* 根据被检设备id和监测点编号获取监测点信息
* @param devId 设备id
* @param monitorNum 监测点编号
*/
PqMonitor getByDevIdAndNum(String devId, int monitorNum);
} }

View File

@@ -84,6 +84,7 @@ public class PqMonitorServiceImpl extends ServiceImpl<PqMonitorMapper, PqMonitor
if (ObjectUtil.isNotNull(pqMonitor)) { if (ObjectUtil.isNotNull(pqMonitor)) {
BeanUtil.copyProperties(monitorList.get(0), pqMonitor, "id", "realtimeResult", "statisticsResult", "recordedResult", "realtimeNum", "statisticsNum", "recordedNum", "resultType", "qualifiedNum"); BeanUtil.copyProperties(monitorList.get(0), pqMonitor, "id", "realtimeResult", "statisticsResult", "recordedResult", "realtimeNum", "statisticsNum", "recordedNum", "resultType", "qualifiedNum");
newMonitorList.add(pqMonitor); newMonitorList.add(pqMonitor);
existedMonitorList.remove(pqMonitor);
} else { } else {
newMonitorList.addAll(monitorList); newMonitorList.addAll(monitorList);
} }
@@ -135,35 +136,40 @@ public class PqMonitorServiceImpl extends ServiceImpl<PqMonitorMapper, PqMonitor
// 同步更新计划的状态 // 同步更新计划的状态
AdPlan plan = this.baseMapper.getPlanByDevId(devId); AdPlan plan = this.baseMapper.getPlanByDevId(devId);
List<PqDevSub> devSubList = this.baseMapper.listDevSubByPlanId(plan.getId()); if (ObjectUtil.isNotNull(plan)) {
List<PqDevSub> checkedDevSubList = devSubList.stream().filter(pqDevSub -> pqDevSub.getCheckState() == CheckStateEnum.CHECKED.getValue()).collect(Collectors.toList());
List<PqDevSub> checkingDevSubList = devSubList.stream().filter(pqDevSub -> pqDevSub.getCheckState() == CheckStateEnum.CHECKING.getValue()).collect(Collectors.toList());
if (checkedDevSubList.size() == devSubList.size() && devSubList.size() > 0) {
this.baseMapper.updatePlanCheckState(plan.getId(), CheckStateEnum.CHECKED.getValue());
} else if (checkedDevSubList.size() > 0 || checkingDevSubList.size() > 0) {
this.baseMapper.updatePlanCheckState(plan.getId(), CheckStateEnum.CHECKING.getValue());
} else {
this.baseMapper.updatePlanCheckState(plan.getId(), CheckStateEnum.UNCHECKED.getValue());
}
List<PqDevSub> accordDevSubList = checkedDevSubList.stream().filter(pqDevSub -> pqDevSub.getCheckResult() == CheckResultEnum.ACCORD.getValue()).collect(Collectors.toList()); List<PqDevSub> devSubList = this.baseMapper.listDevSubByPlanId(plan.getId());
if (accordDevSubList.size() == checkedDevSubList.size() && checkedDevSubList.size() > 0) {
this.baseMapper.updatePlanCheckResult(plan.getId(), CheckResultEnum.ACCORD.getValue());
} else if (accordDevSubList.size() > 0) {
this.baseMapper.updatePlanCheckResult(plan.getId(), CheckResultEnum.NOT_ACCORD.getValue());
} else {
this.baseMapper.updatePlanCheckResult(plan.getId(), CheckResultEnum.UNCHECKED.getValue());
}
List<PqDevSub> generatedDevSubList = checkedDevSubList.stream().filter(pqDevSub -> pqDevSub.getReportState() == DevReportStateEnum.GENERATED.getValue()).collect(Collectors.toList()); List<PqDevSub> checkedDevSubList = devSubList.stream().filter(pqDevSub -> pqDevSub.getCheckState() == CheckStateEnum.CHECKED.getValue()).collect(Collectors.toList());
if (generatedDevSubList.size() == checkedDevSubList.size() && checkedDevSubList.size() > 0) { List<PqDevSub> checkingDevSubList = devSubList.stream().filter(pqDevSub -> pqDevSub.getCheckState() == CheckStateEnum.CHECKING.getValue()).collect(Collectors.toList());
this.baseMapper.updatePlanReportRState(plan.getId(), PlanReportStateEnum.REPORT_STATE_ALL_GENERATED.getValue()); if (checkedDevSubList.size() == devSubList.size() && devSubList.size() > 0) {
} else if (generatedDevSubList.size() > 0) { this.baseMapper.updatePlanCheckState(plan.getId(), CheckStateEnum.CHECKED.getValue());
this.baseMapper.updatePlanReportRState(plan.getId(), PlanReportStateEnum.REPORT_STATE_PARTIALLY_GENERATED.getValue()); } else if (checkedDevSubList.size() > 0 || checkingDevSubList.size() > 0) {
} else { this.baseMapper.updatePlanCheckState(plan.getId(), CheckStateEnum.CHECKING.getValue());
this.baseMapper.updatePlanReportRState(plan.getId(), PlanReportStateEnum.REPORT_STATE_NOT_GENERATED.getValue()); } else {
this.baseMapper.updatePlanCheckState(plan.getId(), CheckStateEnum.UNCHECKED.getValue());
}
List<PqDevSub> accordDevSubList = checkedDevSubList.stream().filter(pqDevSub -> pqDevSub.getCheckResult() == CheckResultEnum.ACCORD.getValue()).collect(Collectors.toList());
if (accordDevSubList.size() == checkedDevSubList.size() && checkedDevSubList.size() > 0) {
this.baseMapper.updatePlanCheckResult(plan.getId(), CheckResultEnum.ACCORD.getValue());
} else if (accordDevSubList.size() > 0) {
this.baseMapper.updatePlanCheckResult(plan.getId(), CheckResultEnum.NOT_ACCORD.getValue());
} else {
this.baseMapper.updatePlanCheckResult(plan.getId(), CheckResultEnum.UNCHECKED.getValue());
}
List<PqDevSub> generatedDevSubList = checkedDevSubList.stream().filter(pqDevSub -> pqDevSub.getReportState() == DevReportStateEnum.GENERATED.getValue()).collect(Collectors.toList());
if (generatedDevSubList.size() == checkedDevSubList.size() && checkedDevSubList.size() > 0) {
this.baseMapper.updatePlanReportRState(plan.getId(), PlanReportStateEnum.REPORT_STATE_ALL_GENERATED.getValue());
} else if (generatedDevSubList.size() > 0) {
this.baseMapper.updatePlanReportRState(plan.getId(), PlanReportStateEnum.REPORT_STATE_PARTIALLY_GENERATED.getValue());
} else {
this.baseMapper.updatePlanReportRState(plan.getId(), PlanReportStateEnum.REPORT_STATE_NOT_GENERATED.getValue());
}
} }
this.removeByIds(existedMonitorList.stream().map(PqMonitor::getId).collect(Collectors.toList()));
return this.saveOrUpdateBatch(newMonitorList); return this.saveOrUpdateBatch(newMonitorList);
} }
@@ -432,4 +438,16 @@ public class PqMonitorServiceImpl extends ServiceImpl<PqMonitorMapper, PqMonitor
wrapper.eq("pq_monitor.Dev_Id", devId); wrapper.eq("pq_monitor.Dev_Id", devId);
return this.remove(wrapper); return this.remove(wrapper);
} }
@Override
public PqMonitor getByDevIdAndNum(String devId, int monitorNum) {
QueryWrapper<PqMonitor> wrapper = new QueryWrapper<>();
wrapper.eq("pq_monitor.Dev_Id", devId)
.eq("pq_monitor.Num", monitorNum);
List<PqMonitor> pqMonitors = this.list(wrapper);
if (CollUtil.isNotEmpty(pqMonitors)) {
return pqMonitors.get(0);
}
return null;
}
} }

View File

@@ -22,6 +22,7 @@ import com.njcn.gather.device.service.IPqDevService;
import com.njcn.gather.plan.pojo.param.AdPlanParam; import com.njcn.gather.plan.pojo.param.AdPlanParam;
import com.njcn.gather.plan.pojo.po.AdPlan; import com.njcn.gather.plan.pojo.po.AdPlan;
import com.njcn.gather.plan.pojo.vo.AdPlanVO; import com.njcn.gather.plan.pojo.vo.AdPlanVO;
import com.njcn.gather.plan.pojo.vo.PlanStatisticsVO;
import com.njcn.gather.plan.service.AsyncPlanHandler; import com.njcn.gather.plan.service.AsyncPlanHandler;
import com.njcn.gather.plan.service.IAdPlanService; import com.njcn.gather.plan.service.IAdPlanService;
import com.njcn.gather.type.pojo.po.DevType; import com.njcn.gather.type.pojo.po.DevType;
@@ -198,6 +199,17 @@ public class AdPlanController extends BaseController {
adPlanService.analyse(ids); adPlanService.analyse(ids);
} }
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
@PostMapping("/statistics")
@ApiOperation("检测计划统计")
@ApiImplicitParam(name = "param", value = "检测计划统计参数", required = true)
public HttpResult<PlanStatisticsVO> statistics(@RequestBody @Validated AdPlanParam.StatisticsParam param) {
String methodDescribe = getMethodDescribe("statistics");
LogUtil.njcnDebug(log, "{},查询数据为:{}", methodDescribe, param);
PlanStatisticsVO result = adPlanService.statistics(param);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
}
@OperateInfo(info = LogEnum.BUSINESS_COMMON) @OperateInfo(info = LogEnum.BUSINESS_COMMON)
@PostMapping("/listByPlanId") @PostMapping("/listByPlanId")
@ApiOperation("查询出所有已绑定的设备") @ApiOperation("查询出所有已绑定的设备")

View File

@@ -0,0 +1,15 @@
package com.njcn.gather.plan.mapper;
import com.github.yulichang.base.MPJBaseMapper;
import com.njcn.gather.plan.pojo.po.PqDevCheckHistory;
import com.njcn.gather.plan.pojo.vo.PlanStatisticsItemVO;
import org.apache.ibatis.annotations.Param;
import java.util.List;
public interface PqDevCheckHistoryMapper extends MPJBaseMapper<PqDevCheckHistory> {
List<PlanStatisticsItemVO> listItemDistributions(@Param("planId") String planId,
@Param("manufacturer") String manufacturer,
@Param("devType") String devType);
}

View File

@@ -0,0 +1,24 @@
<?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.plan.mapper.PqDevCheckHistoryMapper">
<select id="listItemDistributions" resultType="com.njcn.gather.plan.pojo.vo.PlanStatisticsItemVO">
SELECT
Item_Id AS itemId,
Item_Name AS itemName,
SUM(CASE WHEN Result = 0 THEN 1 ELSE 0 END) AS unqualifiedCount
FROM pq_dev_check_history
<where>
State = 1
AND Plan_Id = #{planId}
<if test="manufacturer != null and manufacturer != ''">
AND Manufacturer = #{manufacturer}
</if>
<if test="devType != null and devType != ''">
AND Dev_Type = #{devType}
</if>
</where>
GROUP BY Item_Id, Item_Name
ORDER BY unqualifiedCount DESC, Item_Name ASC
</select>
</mapper>

View File

@@ -130,4 +130,17 @@ public class AdPlanParam {
private String patternId; private String patternId;
private String scriptType; private String scriptType;
} }
@Data
public static class StatisticsParam {
@ApiModelProperty(value = "检测计划ID", required = true)
@NotBlank(message = DetectionValidMessage.PLAN_ID_NOT_BLANK)
private String planId;
@ApiModelProperty("设备厂家")
private String manufacturer;
@ApiModelProperty("设备类型")
private String devType;
}
} }

View File

@@ -0,0 +1,60 @@
package com.njcn.gather.plan.pojo.po;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import java.time.LocalDateTime;
@Data
@TableName("pq_dev_check_history")
public class PqDevCheckHistory {
@TableId(value = "Id", type = IdType.ASSIGN_UUID)
private String id;
@TableField("Plan_Id")
private String planId;
@TableField("Dev_Id")
private String devId;
@TableField("Dev_Type")
private String devType;
@TableField("Manufacturer")
private String manufacturer;
@TableField("ReCheck_Num")
private Integer recheckNum;
@TableField("Item_Id")
private String itemId;
@TableField("Item_Name")
private String itemName;
@TableField("Result")
private Integer result;
@TableField("Check_Time")
private LocalDateTime checkTime;
@TableField("State")
private Integer state;
@TableField("Create_By")
private String createBy;
@TableField(value = "Create_Time", fill = FieldFill.INSERT)
private LocalDateTime createTime;
@TableField("Update_By")
private String updateBy;
@TableField(value = "Update_Time", fill = FieldFill.UPDATE)
private LocalDateTime updateTime;
}

View File

@@ -0,0 +1,25 @@
package com.njcn.gather.plan.pojo.vo;
import lombok.Data;
/**
* 检测计划单个检测大项柱状图统计结果。
*/
@Data
public class PlanStatisticsItemVO {
/**
* 检测大项ID。
*/
private String itemId;
/**
* 检测大项名称。
*/
private String itemName;
/**
* 不合格次数。
*/
private Integer unqualifiedCount;
}

View File

@@ -0,0 +1,15 @@
package com.njcn.gather.plan.pojo.vo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@NoArgsConstructor
@AllArgsConstructor
public class PlanStatisticsOptionVO {
private String id;
private String name;
}

View File

@@ -0,0 +1,103 @@
package com.njcn.gather.plan.pojo.vo;
import lombok.Data;
import java.math.BigDecimal;
import java.util.List;
/**
* 检测计划统计结果。
*/
@Data
public class PlanStatisticsVO {
/**
* 检测计划ID。
*/
private String planId;
/**
* 检测计划名称。
*/
private String planName;
/**
* 所有设备检测次数之和。
*/
private Integer totalCheckCount;
/**
* 已检设备总数。
*/
private Integer checkedDeviceCount;
/**
* 未检设备总数。
*/
private Integer uncheckedDeviceCount;
/**
* 第一次检测合格的设备数量。
*/
private Integer firstQualifiedDeviceCount;
/**
* 第二次检测后合格的设备数量。
*/
private Integer secondQualifiedDeviceCount;
/**
* 第三次及以上检测后合格的设备数量。
*/
private Integer thirdOrMoreQualifiedDeviceCount;
/**
* 最终合格的设备数量。
*/
private Integer qualifiedDeviceCount;
/**
* 最终不合格的设备数量。
*/
private Integer unqualifiedDeviceCount;
/**
* 存在不合格结果的检测项数量。
*/
private Integer unqualifiedItemCount;
/**
* 一次合格率,百分制。
*/
private BigDecimal firstPassRate;
/**
* 二次合格率,百分制。
*/
private BigDecimal secondPassRate;
/**
* 三次及以上合格率,百分制。
*/
private BigDecimal thirdOrMorePassRate;
/**
* 不合格率,百分制。
*/
private BigDecimal unqualifiedRate;
/**
* 检测项分布。
*/
private List<PlanStatisticsItemVO> itemDistributions;
/**
* 设备厂家筛选项。
*/
private List<PlanStatisticsOptionVO> manufacturerOptions;
/**
* 设备类型筛选项。
*/
private List<PlanStatisticsOptionVO> devTypeOptions;
}

View File

@@ -23,6 +23,7 @@ import com.njcn.gather.monitor.service.IPqMonitorService;
import com.njcn.gather.plan.pojo.po.AdPlan; import com.njcn.gather.plan.pojo.po.AdPlan;
import com.njcn.gather.plan.pojo.vo.AdPlanCheckDataVO; import com.njcn.gather.plan.pojo.vo.AdPlanCheckDataVO;
import com.njcn.gather.plan.service.util.BatchFileReader; import com.njcn.gather.plan.service.util.BatchFileReader;
import com.njcn.gather.system.config.PathConfig;
import com.njcn.gather.system.config.handler.NonWebAutoFillValueHandler; import com.njcn.gather.system.config.handler.NonWebAutoFillValueHandler;
import com.njcn.gather.tools.report.model.constant.ReportConstant; import com.njcn.gather.tools.report.model.constant.ReportConstant;
import com.njcn.gather.type.pojo.po.DevType; import com.njcn.gather.type.pojo.po.DevType;
@@ -64,11 +65,11 @@ public class AsyncPlanHandler {
private final JdbcTemplate jdbcTemplate; private final JdbcTemplate jdbcTemplate;
private final PathConfig pathConfig;
@Value("${report.reportDir}") // @Value("${report.reportDir}")
private String reportPath; // private String reportPath;
@Value("${data.homeDir}") // @Value("${data.homeDir}")
private String dataPath; // private String dataPath;
private static final int BATCH_SIZE = 10000; private static final int BATCH_SIZE = 10000;
private static final int FINAL_STEP = 85; private static final int FINAL_STEP = 85;
@@ -199,13 +200,13 @@ public class AsyncPlanHandler {
// 创建 ZIP 文件 // 创建 ZIP 文件
String zipFileName = plan.getName() + "_检测数据包.zip"; String zipFileName = plan.getName() + "_检测数据包.zip";
File zipFile = FileUtil.file(dataPath + File.separator + TEST_DATA_DIR + File.separator, zipFileName); File zipFile = FileUtil.file(pathConfig.getDataPath() + File.separator + TEST_DATA_DIR + File.separator, zipFileName);
// 添加检测报告文件 // 添加检测报告文件
if (ObjectUtil.isNotNull(report) && report.equals(1)) { if (ObjectUtil.isNotNull(report) && report.equals(1)) {
for (PqDev dev : devList) { for (PqDev dev : devList) {
DevType devType = devTypeService.getById(dev.getDevType()); DevType devType = devTypeService.getById(dev.getDevType());
String dirPath = reportPath.concat(File.separator).concat(devType.getName()); String dirPath = pathConfig.getReportPath().concat(File.separator).concat(devType.getName());
File reportFile = new File(dirPath.concat(File.separator).concat(dev.getCreateId()).concat(ReportConstant.DOCX)); File reportFile = new File(dirPath.concat(File.separator).concat(dev.getCreateId()).concat(ReportConstant.DOCX));
// 如果reportFile存在则将reportFile中的文件添加到已有的zip文件中 // 如果reportFile存在则将reportFile中的文件添加到已有的zip文件中
if (FileUtil.exist(reportFile)) { if (FileUtil.exist(reportFile)) {
@@ -344,7 +345,7 @@ public class AsyncPlanHandler {
for (File docx : docxFiles) { for (File docx : docxFiles) {
for (PqDev dev : devList) { for (PqDev dev : devList) {
DevType devType = devTypeService.getById(dev.getDevType()); DevType devType = devTypeService.getById(dev.getDevType());
String dirPath = reportPath.concat(File.separator).concat(devType.getName()); String dirPath = pathConfig.getReportPath().concat(File.separator).concat(devType.getName());
File reportFile = new File(dirPath.concat(File.separator).concat(dev.getCreateId()).concat(ReportConstant.DOCX)); File reportFile = new File(dirPath.concat(File.separator).concat(dev.getCreateId()).concat(ReportConstant.DOCX));
// 文件名匹配,复制到对应目录下 // 文件名匹配,复制到对应目录下
if (docx.getName().equals(reportFile.getName())) { if (docx.getName().equals(reportFile.getName())) {

View File

@@ -6,6 +6,7 @@ import com.njcn.gather.device.pojo.po.PqStandardDev;
import com.njcn.gather.plan.pojo.param.AdPlanParam; import com.njcn.gather.plan.pojo.param.AdPlanParam;
import com.njcn.gather.plan.pojo.po.AdPlan; import com.njcn.gather.plan.pojo.po.AdPlan;
import com.njcn.gather.plan.pojo.vo.AdPlanVO; import com.njcn.gather.plan.pojo.vo.AdPlanVO;
import com.njcn.gather.plan.pojo.vo.PlanStatisticsVO;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
@@ -105,6 +106,14 @@ public interface IAdPlanService extends IService<AdPlan> {
*/ */
void analyse(List<String> ids); void analyse(List<String> ids);
/**
* 统计检测计划结果。
*
* @param planId 检测计划ID
* @return 检测计划统计结果
*/
PlanStatisticsVO statistics(AdPlanParam.StatisticsParam param);
/** /**
* 导出检测计划数据 * 导出检测计划数据
* *

View File

@@ -0,0 +1,18 @@
package com.njcn.gather.plan.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.njcn.gather.device.pojo.vo.PqDevVO;
import com.njcn.gather.plan.pojo.po.AdPlan;
import com.njcn.gather.plan.pojo.po.PqDevCheckHistory;
import com.njcn.gather.plan.pojo.vo.PlanStatisticsItemVO;
import java.util.List;
public interface IPqDevCheckHistoryService extends IService<PqDevCheckHistory> {
void saveOrUpdateDeviceHistory(AdPlan plan, PqDevVO device);
void backfillPlanHistoryIfEmpty(AdPlan plan, List<PqDevVO> checkedDevices);
List<PlanStatisticsItemVO> listItemDistributions(String planId, String manufacturer, String devType);
}

View File

@@ -59,6 +59,7 @@ import com.njcn.gather.plan.service.IAdPlanService;
import com.njcn.gather.plan.service.IAdPlanSourceService; import com.njcn.gather.plan.service.IAdPlanSourceService;
import com.njcn.gather.plan.service.IAdPlanStandardDevService; import com.njcn.gather.plan.service.IAdPlanStandardDevService;
import com.njcn.gather.plan.service.IAdPlanTestConfigService; import com.njcn.gather.plan.service.IAdPlanTestConfigService;
import com.njcn.gather.plan.service.IPqDevCheckHistoryService;
import com.njcn.gather.pojo.enums.DetectionResponseEnum; import com.njcn.gather.pojo.enums.DetectionResponseEnum;
import com.njcn.gather.report.pojo.po.PqReport; import com.njcn.gather.report.pojo.po.PqReport;
import com.njcn.gather.report.service.IPqReportService; import com.njcn.gather.report.service.IPqReportService;
@@ -69,11 +70,14 @@ import com.njcn.gather.script.service.IPqScriptService;
import com.njcn.gather.source.pojo.po.PqSource; import com.njcn.gather.source.pojo.po.PqSource;
import com.njcn.gather.source.service.IPqSourceService; import com.njcn.gather.source.service.IPqSourceService;
import com.njcn.gather.storage.pojo.param.StorageParam; import com.njcn.gather.storage.pojo.param.StorageParam;
import com.njcn.gather.storage.pojo.po.SimAndDigBaseResult;
import com.njcn.gather.storage.service.SimAndDigHarmonicService; import com.njcn.gather.storage.service.SimAndDigHarmonicService;
import com.njcn.gather.storage.service.SimAndDigNonHarmonicService;
import com.njcn.gather.storage.service.TableGenService; import com.njcn.gather.storage.service.TableGenService;
import com.njcn.gather.system.cfg.pojo.enums.SceneEnum; import com.njcn.gather.system.cfg.pojo.enums.SceneEnum;
import com.njcn.gather.system.cfg.pojo.po.SysTestConfig; import com.njcn.gather.system.cfg.pojo.po.SysTestConfig;
import com.njcn.gather.system.cfg.service.ISysTestConfigService; import com.njcn.gather.system.cfg.service.ISysTestConfigService;
import com.njcn.gather.system.config.PathConfig;
import com.njcn.gather.system.dictionary.pojo.po.DictData; import com.njcn.gather.system.dictionary.pojo.po.DictData;
import com.njcn.gather.system.dictionary.pojo.po.DictTree; import com.njcn.gather.system.dictionary.pojo.po.DictTree;
import com.njcn.gather.system.dictionary.pojo.po.DictType; import com.njcn.gather.system.dictionary.pojo.po.DictType;
@@ -107,6 +111,8 @@ import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.net.URLEncoder; import java.net.URLEncoder;
import java.util.*; import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@@ -133,6 +139,7 @@ public class AdPlanServiceImpl extends ServiceImpl<AdPlanMapper, AdPlan> impleme
private final IDevTypeService devTypeService; private final IDevTypeService devTypeService;
private final IDictTypeService dictTypeService; private final IDictTypeService dictTypeService;
private final SimAndDigHarmonicService adHarmonicService; private final SimAndDigHarmonicService adHarmonicService;
private final SimAndDigNonHarmonicService adNonHarmonicService;
private final PqDevMapper pqDevMapper; private final PqDevMapper pqDevMapper;
private final IPqDevSubService pqDevSubService; private final IPqDevSubService pqDevSubService;
private final IAdPlanStandardDevService adPlanStandardDevService; private final IAdPlanStandardDevService adPlanStandardDevService;
@@ -145,10 +152,12 @@ public class AdPlanServiceImpl extends ServiceImpl<AdPlanMapper, AdPlan> impleme
private final IAdPariService adPairService; private final IAdPariService adPairService;
private final IAdPlanTestConfigService adPlanTestConfigService; private final IAdPlanTestConfigService adPlanTestConfigService;
private final ISysUserService sysUserService; private final ISysUserService sysUserService;
private final IPqDevCheckHistoryService pqDevCheckHistoryService;
private final JdbcTemplate jdbcTemplate; private final JdbcTemplate jdbcTemplate;
@Value("${report.reportDir}") // @Value("${report.reportDir}")
private String reportPath; // private String reportPath;
private final PathConfig pathConfig;
@Override @Override
public List<AdPlanVO> listAdPlan(AdPlanParam.QueryParam queryParam) { public List<AdPlanVO> listAdPlan(AdPlanParam.QueryParam queryParam) {
@@ -554,6 +563,8 @@ public class AdPlanServiceImpl extends ServiceImpl<AdPlanMapper, AdPlan> impleme
child.put("pid", adPlan.getFatherPlanId()); child.put("pid", adPlan.getFatherPlanId());
child.put("name", adPlan.getName()); child.put("name", adPlan.getName());
child.put("timeCheck", adPlan.getTimeCheck()); child.put("timeCheck", adPlan.getTimeCheck());
child.put("dataRule", adPlan.getDataRule());
child.put("testState", adPlan.getTestState());
List<PqStandardDev> pqStandardDevs = adPlanStandardDevMapper.listByPlanId(Collections.singletonList(adPlan.getId())); List<PqStandardDev> pqStandardDevs = adPlanStandardDevMapper.listByPlanId(Collections.singletonList(adPlan.getId()));
List<String> devTypeIdList = pqStandardDevs.stream().map(PqStandardDev::getDevType).collect(Collectors.toList()); List<String> devTypeIdList = pqStandardDevs.stream().map(PqStandardDev::getDevType).collect(Collectors.toList());
@@ -808,6 +819,290 @@ public class AdPlanServiceImpl extends ServiceImpl<AdPlanMapper, AdPlan> impleme
} }
} }
@Override
public PlanStatisticsVO statistics(AdPlanParam.StatisticsParam param) {
String planId = param.getPlanId();
AdPlan plan = this.getById(planId);
if (ObjectUtil.isNull(plan)) {
throw new BusinessException(DetectionResponseEnum.PLAN_NOT_EXIST);
}
List<PqDevVO> allPlanDevices = listPlanDevices(plan.getId(), null, null);
List<PqDevVO> planDevices = filterPlanDevices(allPlanDevices, param.getManufacturer(), param.getDevType());
List<PqDevVO> checkedDevices = planDevices.stream()
.filter(this::isCheckedDevice)
.collect(Collectors.toList());
PlanStatisticsVO statistics = new PlanStatisticsVO();
statistics.setPlanId(plan.getId());
statistics.setPlanName(plan.getName());
statistics.setManufacturerOptions(buildManufacturerOptions(allPlanDevices, param.getDevType()));
statistics.setDevTypeOptions(buildDevTypeOptions(allPlanDevices, param.getManufacturer()));
statistics.setUncheckedDeviceCount(planDevices.size() - checkedDevices.size());
statistics.setCheckedDeviceCount(checkedDevices.size());
statistics.setTotalCheckCount(checkedDevices.stream().mapToInt(dev -> defaultZero(dev.getRecheckNum())).sum());
int firstQualifiedCount = (int) checkedDevices.stream()
.filter(dev -> Objects.equals(dev.getRecheckNum(), 1))
.filter(dev -> Objects.equals(dev.getCheckResult(), CheckResultEnum.ACCORD.getValue()))
.count();
int secondQualifiedCount = (int) checkedDevices.stream()
.filter(dev -> Objects.equals(dev.getRecheckNum(), 2))
.filter(dev -> Objects.equals(dev.getCheckResult(), CheckResultEnum.ACCORD.getValue()))
.count();
int thirdOrMoreQualifiedCount = (int) checkedDevices.stream()
.filter(dev -> defaultZero(dev.getRecheckNum()) >= 3)
.filter(dev -> Objects.equals(dev.getCheckResult(), CheckResultEnum.ACCORD.getValue()))
.count();
int unqualifiedDeviceCount = (int) checkedDevices.stream()
.filter(dev -> Objects.equals(dev.getCheckResult(), CheckResultEnum.NOT_ACCORD.getValue()))
.count();
statistics.setFirstQualifiedDeviceCount(firstQualifiedCount);
statistics.setSecondQualifiedDeviceCount(secondQualifiedCount);
statistics.setThirdOrMoreQualifiedDeviceCount(thirdOrMoreQualifiedCount);
statistics.setQualifiedDeviceCount(firstQualifiedCount + secondQualifiedCount + thirdOrMoreQualifiedCount);
statistics.setUnqualifiedDeviceCount(unqualifiedDeviceCount);
statistics.setFirstPassRate(rate(firstQualifiedCount, checkedDevices.size()));
statistics.setSecondPassRate(rate(secondQualifiedCount, checkedDevices.size()));
statistics.setThirdOrMorePassRate(rate(thirdOrMoreQualifiedCount, checkedDevices.size()));
statistics.setUnqualifiedRate(rate(unqualifiedDeviceCount, checkedDevices.size()));
pqDevCheckHistoryService.backfillPlanHistoryIfEmpty(plan, checkedDevices);
List<PlanStatisticsItemVO> itemDistributions = pqDevCheckHistoryService.listItemDistributions(plan.getId(), param.getManufacturer(), param.getDevType());
statistics.setItemDistributions(itemDistributions);
statistics.setUnqualifiedItemCount(itemDistributions.stream()
.mapToInt(item -> defaultZero(item.getUnqualifiedCount()))
.sum());
return statistics;
}
private List<PqDevVO> listPlanDevices(String planId, String manufacturer, String devType) {
PqDevParam.QueryParam queryParam = new PqDevParam.QueryParam();
queryParam.setPlanIdList(Collections.singletonList(planId));
List<PqDevVO> pqDevVOList = pqDevMapper.selectByQueryParam(queryParam);
if (CollUtil.isEmpty(pqDevVOList)) {
return Collections.emptyList();
}
return filterPlanDevices(pqDevVOList, manufacturer, devType);
}
private List<PqDevVO> filterPlanDevices(List<PqDevVO> devices, String manufacturer, String devType) {
if (CollUtil.isEmpty(devices)) {
return Collections.emptyList();
}
return devices.stream()
.filter(dev -> StrUtil.isBlank(manufacturer) || Objects.equals(dev.getManufacturer(), manufacturer))
.filter(dev -> StrUtil.isBlank(devType) || Objects.equals(dev.getDevType(), devType))
.collect(Collectors.toList());
}
private List<PlanStatisticsOptionVO> buildManufacturerOptions(List<PqDevVO> devices, String devType) {
if (CollUtil.isEmpty(devices)) {
return Collections.emptyList();
}
List<String> ids = devices.stream()
.filter(dev -> StrUtil.isBlank(devType) || Objects.equals(dev.getDevType(), devType))
.map(PqDevVO::getManufacturer)
.filter(StrUtil::isNotBlank)
.distinct()
.collect(Collectors.toList());
Map<String, String> nameMap = ids.isEmpty()
? Collections.emptyMap()
: dictDataService.listByIds(ids).stream()
.collect(Collectors.toMap(DictData::getId, DictData::getName, (left, right) -> left));
return ids.stream()
.map(id -> new PlanStatisticsOptionVO(id, nameMap.getOrDefault(id, id)))
.collect(Collectors.toList());
}
private List<PlanStatisticsOptionVO> buildDevTypeOptions(List<PqDevVO> devices, String manufacturer) {
if (CollUtil.isEmpty(devices)) {
return Collections.emptyList();
}
List<String> ids = devices.stream()
.filter(dev -> StrUtil.isBlank(manufacturer) || Objects.equals(dev.getManufacturer(), manufacturer))
.map(PqDevVO::getDevType)
.filter(StrUtil::isNotBlank)
.distinct()
.collect(Collectors.toList());
Map<String, String> nameMap = ids.isEmpty()
? Collections.emptyMap()
: devTypeService.listByIds(ids).stream()
.collect(Collectors.toMap(DevType::getId, DevType::getName, (left, right) -> left));
return ids.stream()
.map(id -> new PlanStatisticsOptionVO(id, nameMap.getOrDefault(id, id)))
.collect(Collectors.toList());
}
private boolean isCheckedDevice(PqDevVO dev) {
return (Objects.equals(dev.getCheckState(), CheckStateEnum.CHECKED.getValue())
|| Objects.equals(dev.getCheckState(), CheckStateEnum.DOCUMENTED.getValue()))
&& !Objects.equals(dev.getCheckResult(), CheckResultEnum.UNCHECKED.getValue());
}
private List<PlanStatisticsItemVO> buildItemDistributions(AdPlan plan, List<PqDevVO> checkedDevices) {
if (CollUtil.isEmpty(checkedDevices) || StrUtil.isBlank(plan.getScriptId()) || ObjectUtil.isNull(plan.getCode())) {
return Collections.emptyList();
}
Map<Integer, ScriptItemInfo> scriptItemInfoMap = getScriptItemInfoMap(plan.getScriptId());
if (CollUtil.isEmpty(scriptItemInfoMap)) {
return Collections.emptyList();
}
Map<String, PlanStatisticsItemAccumulator> itemAccumulatorMap = new TreeMap<>();
for (PqDevVO device : checkedDevices) {
List<SimAndDigBaseResult> deviceResultList = new ArrayList<>();
deviceResultList.addAll(adNonHarmonicService.listSimAndDigBaseResult(plan.getScriptId(), plan.getCode() + "", device.getId()));
deviceResultList.addAll(adHarmonicService.listAllResultData(plan.getScriptId(), plan.getCode() + "", device.getId()));
if (CollUtil.isEmpty(deviceResultList)) {
continue;
}
Map<String, List<SimAndDigBaseResult>> deviceItemResultMap = deviceResultList.stream()
.filter(result -> ObjectUtil.isNotNull(result.getSort()))
.map(result -> new AbstractMap.SimpleEntry<>(scriptItemInfoMap.get(result.getSort()), result))
.filter(entry -> ObjectUtil.isNotNull(entry.getKey()))
.collect(Collectors.groupingBy(
entry -> entry.getKey().getItemId(),
TreeMap::new,
Collectors.mapping(Map.Entry::getValue, Collectors.toList())
));
deviceItemResultMap.forEach((itemId, results) -> {
boolean hasUnqualified = results.stream().anyMatch(result -> isUnqualifiedResultFlag(result.getResultFlag()));
boolean hasQualified = results.stream().anyMatch(result -> Objects.equals(result.getResultFlag(), 1));
if (!hasUnqualified && !hasQualified) {
return;
}
ScriptItemInfo itemInfo = scriptItemInfoMap.get(results.get(0).getSort());
PlanStatisticsItemAccumulator accumulator = itemAccumulatorMap.computeIfAbsent(
itemId,
key -> new PlanStatisticsItemAccumulator(itemId, itemInfo.getItemName())
);
accumulator.totalCount++;
if (hasUnqualified) {
accumulator.unqualifiedCount++;
} else {
accumulator.qualifiedCount++;
}
});
}
return itemAccumulatorMap.values().stream()
.map(PlanStatisticsItemAccumulator::toVO)
.collect(Collectors.toList());
}
private Map<Integer, ScriptItemInfo> getScriptItemInfoMap(String scriptId) {
List<PqScriptDtls> scriptDtlsList = pqScriptDtlsService.list(new LambdaQueryWrapper<PqScriptDtls>()
.eq(PqScriptDtls::getScriptId, scriptId)
.ne(PqScriptDtls::getScriptIndex, -1)
.eq(PqScriptDtls::getEnable, DataStateEnum.ENABLE.getCode())
);
if (CollUtil.isEmpty(scriptDtlsList)) {
return Collections.emptyMap();
}
List<String> scriptTypeIds = scriptDtlsList.stream()
.map(PqScriptDtls::getScriptType)
.filter(StrUtil::isNotBlank)
.distinct()
.collect(Collectors.toList());
Map<String, DictTree> dictTreeMap = Collections.emptyMap();
if (CollUtil.isNotEmpty(scriptTypeIds)) {
dictTreeMap = dictTreeService.getDictTreeById(scriptTypeIds).stream()
.collect(Collectors.toMap(DictTree::getId, dictTree -> dictTree, (left, right) -> left));
}
Map<String, DictTree> finalDictTreeMap = dictTreeMap;
return scriptDtlsList.stream()
.collect(Collectors.groupingBy(PqScriptDtls::getScriptIndex, TreeMap::new, Collectors.toList()))
.entrySet()
.stream()
.collect(Collectors.toMap(
Map.Entry::getKey,
entry -> resolveScriptItemInfo(entry.getKey(), entry.getValue(), finalDictTreeMap),
(left, right) -> left,
TreeMap::new
));
}
private ScriptItemInfo resolveScriptItemInfo(Integer sort, List<PqScriptDtls> dtlsList, Map<String, DictTree> dictTreeMap) {
if (CollUtil.isEmpty(dtlsList)) {
return new ScriptItemInfo(String.valueOf(sort), "检测项" + sort);
}
PqScriptDtls first = dtlsList.get(0);
DictTree dictTree = dictTreeMap.get(first.getScriptType());
if (ObjectUtil.isNotNull(dictTree) && StrUtil.isNotBlank(dictTree.getName())) {
return new ScriptItemInfo(dictTree.getId(), dictTree.getName());
}
if (StrUtil.isNotBlank(first.getScriptType())) {
return new ScriptItemInfo(first.getScriptType(), "检测项" + sort);
}
return new ScriptItemInfo(String.valueOf(sort), "检测项" + sort);
}
private boolean isUnqualifiedResultFlag(Integer resultFlag) {
return ObjectUtil.isNotNull(resultFlag)
&& !Objects.equals(resultFlag, 1)
&& !Objects.equals(resultFlag, 4)
&& !Objects.equals(resultFlag, 5);
}
private Integer defaultZero(Integer value) {
return ObjectUtil.isNull(value) ? 0 : value;
}
private BigDecimal rate(Integer numerator, Integer denominator) {
if (ObjectUtil.isNull(denominator) || denominator == 0) {
return BigDecimal.ZERO.setScale(2, RoundingMode.HALF_UP);
}
return BigDecimal.valueOf(defaultZero(numerator))
.multiply(BigDecimal.valueOf(100))
.divide(BigDecimal.valueOf(denominator), 2, RoundingMode.HALF_UP);
}
private class PlanStatisticsItemAccumulator {
private final String itemId;
private final String itemName;
private int totalCount;
private int qualifiedCount;
private int unqualifiedCount;
private PlanStatisticsItemAccumulator(String itemId, String itemName) {
this.itemId = itemId;
this.itemName = itemName;
}
private PlanStatisticsItemVO toVO() {
PlanStatisticsItemVO itemVO = new PlanStatisticsItemVO();
itemVO.setItemId(itemId);
itemVO.setItemName(itemName);
itemVO.setUnqualifiedCount(unqualifiedCount);
return itemVO;
}
}
private static class ScriptItemInfo {
private final String itemId;
private final String itemName;
private ScriptItemInfo(String itemId, String itemName) {
this.itemId = itemId;
this.itemName = itemName;
}
private String getItemId() {
return itemId;
}
private String getItemName() {
return itemName;
}
}
@Override @Override
public void exportPlan(AdPlanParam.QueryParam queryParam) { public void exportPlan(AdPlanParam.QueryParam queryParam) {
DictData dictData = dictDataService.getDictDataById(queryParam.getPatternId()); DictData dictData = dictDataService.getDictDataById(queryParam.getPatternId());
@@ -1264,7 +1559,7 @@ public class AdPlanServiceImpl extends ServiceImpl<AdPlanMapper, AdPlan> impleme
for (int i = 1; i <= maxTime; i++) { for (int i = 1; i <= maxTime; i++) {
row2[i] = i + "次检测"; row2[i] = i + "次检测";
int tempI = i; int tempI = i;
List<PqDevVO> tempDevList = devList.stream().filter(dev -> dev.getRecheckNum() <= tempI).collect(Collectors.toList()); List<PqDevVO> tempDevList = devList.stream().filter(dev -> dev.getRecheckNum() == tempI).collect(Collectors.toList());
long passCount = tempDevList.stream().filter(dev -> dev.getCheckResult() == CheckResultEnum.ACCORD.getValue()).count(); long passCount = tempDevList.stream().filter(dev -> dev.getCheckResult() == CheckResultEnum.ACCORD.getValue()).count();
row3[i] = passCount + ""; row3[i] = passCount + "";
row4[i] = total + ""; row4[i] = total + "";
@@ -1554,8 +1849,8 @@ public class AdPlanServiceImpl extends ServiceImpl<AdPlanMapper, AdPlan> impleme
} }
// 检测脚本 // 检测脚本
List<Map<String, Object>> maps1 = pqScriptService.listAllPqScript(null); List<PqScript> pqScriptList = pqScriptService.listAllPqScript(null);
List<String> scriptNameList = maps1.stream().map(m -> (String) m.get("name")).collect(Collectors.toList()); List<String> scriptNameList = pqScriptList.stream().map(m -> m.getName()).collect(Collectors.toList());
pullDown = new PullDown(); pullDown = new PullDown();
pullDown.setFirstCol(3); pullDown.setFirstCol(3);
pullDown.setLastCol(3); pullDown.setLastCol(3);
@@ -1721,8 +2016,8 @@ public class AdPlanServiceImpl extends ServiceImpl<AdPlanMapper, AdPlan> impleme
String zipFileName = URLEncoder.encode(subPlan.getName() + ".zip", "UTF-8"); String zipFileName = URLEncoder.encode(subPlan.getName() + ".zip", "UTF-8");
File zipFile = FileUtil.file(tempDir, zipFileName); File zipFile = FileUtil.file(tempDir, zipFileName);
// 先将json文件添加到zip中 // 先将json文件添加到zip中使用UTF-8编码
ZipUtil.zip(jsonFile.getAbsolutePath(), zipFile.getAbsolutePath()); ZipUtil.zip(zipFile, CharsetUtil.CHARSET_UTF_8, false, jsonFile);
// 创建一个临时目录存放两个文件 // 创建一个临时目录存放两个文件
@@ -1744,8 +2039,8 @@ public class AdPlanServiceImpl extends ServiceImpl<AdPlanMapper, AdPlan> impleme
} }
// 重新创建zip文件包含所有文件 // 重新创建zip文件包含所有文件使用UTF-8编码
ZipUtil.zip(tempZipDir.getAbsolutePath(), zipFile.getAbsolutePath()); ZipUtil.zip(zipFile, CharsetUtil.CHARSET_UTF_8, false, FileUtil.file(tempZipDir));
// 删除临时目录 // 删除临时目录
FileUtil.del(tempZipDir); FileUtil.del(tempZipDir);
@@ -1779,9 +2074,9 @@ public class AdPlanServiceImpl extends ServiceImpl<AdPlanMapper, AdPlan> impleme
File zipFile = FileUtil.file(tempDir, file.getOriginalFilename()); File zipFile = FileUtil.file(tempDir, file.getOriginalFilename());
file.transferTo(zipFile); file.transferTo(zipFile);
// 解压zip文件 // 解压zip文件使用UTF-8编码
File unzipDir = FileUtil.mkdir(FileUtil.file(tempDir, "unzip")); File unzipDir = FileUtil.mkdir(FileUtil.file(tempDir, "unzip"));
ZipUtil.unzip(zipFile.getAbsolutePath(), unzipDir.getAbsolutePath()); ZipUtil.unzip(zipFile, unzipDir, CharsetUtil.CHARSET_UTF_8);
// 查找解压目录中的json文件 // 查找解压目录中的json文件
File[] files = unzipDir.listFiles(); File[] files = unzipDir.listFiles();
@@ -2088,7 +2383,7 @@ public class AdPlanServiceImpl extends ServiceImpl<AdPlanMapper, AdPlan> impleme
if (ObjectUtil.isNotNull(report) && report.equals(1)) { if (ObjectUtil.isNotNull(report) && report.equals(1)) {
for (PqDev dev : devList) { for (PqDev dev : devList) {
DevType devType = devTypeService.getById(dev.getDevType()); DevType devType = devTypeService.getById(dev.getDevType());
String dirPath = reportPath.concat(File.separator).concat(devType.getName()); String dirPath = pathConfig.getReportPath().concat(File.separator).concat(devType.getName());
File reportFile = new File(dirPath.concat(File.separator).concat(dev.getCreateId()).concat(ReportConstant.DOCX)); File reportFile = new File(dirPath.concat(File.separator).concat(dev.getCreateId()).concat(ReportConstant.DOCX));
// 如果reportFile存在则将reportFile中的文件添加到已有的zip文件中 // 如果reportFile存在则将reportFile中的文件添加到已有的zip文件中
if (FileUtil.exist(reportFile)) { if (FileUtil.exist(reportFile)) {
@@ -2099,8 +2394,8 @@ public class AdPlanServiceImpl extends ServiceImpl<AdPlanMapper, AdPlan> impleme
} }
} }
// 重新创建zip文件包含所有文件 // 重新创建zip文件包含所有文件使用UTF-8编码
ZipUtil.zip(tempZipDir.getAbsolutePath(), zipFile.getAbsolutePath()); ZipUtil.zip(zipFile, CharsetUtil.CHARSET_UTF_8, false, FileUtil.file(tempZipDir));
// 删除临时目录 // 删除临时目录
FileUtil.del(tempZipDir); FileUtil.del(tempZipDir);

View File

@@ -0,0 +1,220 @@
package com.njcn.gather.plan.service.impl;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.njcn.common.pojo.enums.common.DataStateEnum;
import com.njcn.gather.device.pojo.vo.PqDevVO;
import com.njcn.gather.plan.mapper.PqDevCheckHistoryMapper;
import com.njcn.gather.plan.pojo.po.AdPlan;
import com.njcn.gather.plan.pojo.po.PqDevCheckHistory;
import com.njcn.gather.plan.pojo.vo.PlanStatisticsItemVO;
import com.njcn.gather.plan.service.IPqDevCheckHistoryService;
import com.njcn.gather.script.mapper.PqScriptDtlsMapper;
import com.njcn.gather.script.pojo.po.PqScriptDtls;
import com.njcn.gather.storage.pojo.po.SimAndDigBaseResult;
import com.njcn.gather.storage.service.SimAndDigHarmonicService;
import com.njcn.gather.storage.service.SimAndDigNonHarmonicService;
import com.njcn.gather.system.dictionary.pojo.po.DictTree;
import com.njcn.gather.system.dictionary.service.IDictTreeService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.time.LocalDateTime;
import java.util.AbstractMap;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.TreeMap;
import java.util.UUID;
import java.util.stream.Collectors;
@Service
@RequiredArgsConstructor
public class PqDevCheckHistoryServiceImpl extends ServiceImpl<PqDevCheckHistoryMapper, PqDevCheckHistory> implements IPqDevCheckHistoryService {
private final SimAndDigNonHarmonicService adNonHarmonicService;
private final SimAndDigHarmonicService adHarmonicService;
private final PqScriptDtlsMapper pqScriptDtlsMapper;
private final IDictTreeService dictTreeService;
@Override
@Transactional
public void saveOrUpdateDeviceHistory(AdPlan plan, PqDevVO device) {
if (ObjectUtil.isNull(plan)
|| ObjectUtil.isNull(device)
|| StrUtil.isBlank(plan.getScriptId())
|| ObjectUtil.isNull(plan.getCode())
|| StrUtil.isBlank(device.getId())
|| ObjectUtil.isNull(device.getRecheckNum())) {
return;
}
Map<Integer, ScriptItemInfo> scriptItemInfoMap = getScriptItemInfoMap(plan.getScriptId());
if (CollUtil.isEmpty(scriptItemInfoMap)) {
return;
}
List<SimAndDigBaseResult> resultList = new ArrayList<>();
resultList.addAll(adNonHarmonicService.listSimAndDigBaseResult(plan.getScriptId(), plan.getCode() + "", device.getId()));
resultList.addAll(adHarmonicService.listAllResultData(plan.getScriptId(), plan.getCode() + "", device.getId()));
if (CollUtil.isEmpty(resultList)) {
return;
}
Map<String, List<SimAndDigBaseResult>> itemResultMap = resultList.stream()
.filter(result -> ObjectUtil.isNotNull(result.getSort()))
.map(result -> new AbstractMap.SimpleEntry<>(scriptItemInfoMap.get(result.getSort()), result))
.filter(entry -> ObjectUtil.isNotNull(entry.getKey()))
.collect(Collectors.groupingBy(
entry -> entry.getKey().getItemId(),
TreeMap::new,
Collectors.mapping(Map.Entry::getValue, Collectors.toList())
));
LocalDateTime now = LocalDateTime.now();
itemResultMap.forEach((itemId, results) -> {
boolean hasUnqualified = results.stream().anyMatch(result -> isUnqualifiedResultFlag(result.getResultFlag()));
boolean hasQualified = results.stream().anyMatch(result -> Objects.equals(result.getResultFlag(), 1));
if (!hasUnqualified && !hasQualified) {
return;
}
ScriptItemInfo itemInfo = scriptItemInfoMap.get(results.get(0).getSort());
PqDevCheckHistory history = this.getOne(new LambdaQueryWrapper<PqDevCheckHistory>()
.eq(PqDevCheckHistory::getPlanId, plan.getId())
.eq(PqDevCheckHistory::getDevId, device.getId())
.eq(PqDevCheckHistory::getRecheckNum, device.getRecheckNum())
.eq(PqDevCheckHistory::getItemId, itemId)
.last("LIMIT 1"));
if (ObjectUtil.isNull(history)) {
history = new PqDevCheckHistory();
history.setId(UUID.randomUUID().toString().replaceAll("-", ""));
history.setPlanId(plan.getId());
history.setDevId(device.getId());
history.setRecheckNum(device.getRecheckNum());
history.setItemId(itemId);
history.setCreateBy(device.getCheckBy());
history.setCreateTime(now);
}
history.setDevType(device.getDevType());
history.setManufacturer(device.getManufacturer());
history.setItemName(itemInfo.getItemName());
history.setResult(hasUnqualified ? 0 : 1);
history.setCheckTime(ObjectUtil.isNotNull(device.getCheckTime()) ? device.getCheckTime() : now);
history.setState(DataStateEnum.ENABLE.getCode());
history.setUpdateBy(device.getCheckBy());
history.setUpdateTime(now);
this.saveOrUpdate(history);
});
}
@Override
public void backfillPlanHistoryIfEmpty(AdPlan plan, List<PqDevVO> checkedDevices) {
if (ObjectUtil.isNull(plan) || CollUtil.isEmpty(checkedDevices)) {
return;
}
long historyCount = this.count(new LambdaQueryWrapper<PqDevCheckHistory>()
.eq(PqDevCheckHistory::getPlanId, plan.getId())
.eq(PqDevCheckHistory::getState, DataStateEnum.ENABLE.getCode()));
if (historyCount > 0) {
return;
}
checkedDevices.forEach(device -> saveOrUpdateDeviceHistory(plan, device));
}
@Override
public List<PlanStatisticsItemVO> listItemDistributions(String planId, String manufacturer, String devType) {
List<PlanStatisticsItemVO> itemDistributions = this.baseMapper.listItemDistributions(planId, manufacturer, devType);
if (CollUtil.isEmpty(itemDistributions)) {
return Collections.emptyList();
}
itemDistributions.forEach(item -> item.setUnqualifiedCount(defaultZero(item.getUnqualifiedCount())));
return itemDistributions;
}
private Map<Integer, ScriptItemInfo> getScriptItemInfoMap(String scriptId) {
List<PqScriptDtls> scriptDtlsList = pqScriptDtlsMapper.selectList(new LambdaQueryWrapper<PqScriptDtls>()
.eq(PqScriptDtls::getScriptId, scriptId)
.ne(PqScriptDtls::getScriptIndex, -1)
.eq(PqScriptDtls::getEnable, DataStateEnum.ENABLE.getCode())
);
if (CollUtil.isEmpty(scriptDtlsList)) {
return Collections.emptyMap();
}
List<String> scriptTypeIds = scriptDtlsList.stream()
.map(PqScriptDtls::getScriptType)
.filter(StrUtil::isNotBlank)
.distinct()
.collect(Collectors.toList());
Map<String, DictTree> dictTreeMap = Collections.emptyMap();
if (CollUtil.isNotEmpty(scriptTypeIds)) {
dictTreeMap = dictTreeService.getDictTreeById(scriptTypeIds).stream()
.collect(Collectors.toMap(DictTree::getId, dictTree -> dictTree, (left, right) -> left));
}
Map<String, DictTree> finalDictTreeMap = dictTreeMap;
return scriptDtlsList.stream()
.collect(Collectors.groupingBy(PqScriptDtls::getScriptIndex, TreeMap::new, Collectors.toList()))
.entrySet()
.stream()
.collect(Collectors.toMap(
Map.Entry::getKey,
entry -> resolveScriptItemInfo(entry.getKey(), entry.getValue(), finalDictTreeMap),
(left, right) -> left,
TreeMap::new
));
}
private ScriptItemInfo resolveScriptItemInfo(Integer sort, List<PqScriptDtls> dtlsList, Map<String, DictTree> dictTreeMap) {
if (CollUtil.isEmpty(dtlsList)) {
return new ScriptItemInfo(String.valueOf(sort), "检测项" + sort);
}
PqScriptDtls first = dtlsList.get(0);
DictTree dictTree = dictTreeMap.get(first.getScriptType());
if (ObjectUtil.isNotNull(dictTree) && StrUtil.isNotBlank(dictTree.getName())) {
return new ScriptItemInfo(dictTree.getId(), dictTree.getName());
}
if (StrUtil.isNotBlank(first.getScriptType())) {
return new ScriptItemInfo(first.getScriptType(), "检测项" + sort);
}
return new ScriptItemInfo(String.valueOf(sort), "检测项" + sort);
}
private boolean isUnqualifiedResultFlag(Integer resultFlag) {
return ObjectUtil.isNotNull(resultFlag)
&& !Objects.equals(resultFlag, 1)
&& !Objects.equals(resultFlag, 4)
&& !Objects.equals(resultFlag, 5);
}
private Integer defaultZero(Integer value) {
return ObjectUtil.isNull(value) ? 0 : value;
}
private static class ScriptItemInfo {
private final String itemId;
private final String itemName;
private ScriptItemInfo(String itemId, String itemName) {
this.itemId = itemId;
this.itemName = itemName;
}
private String getItemId() {
return itemId;
}
private String getItemName() {
return itemName;
}
}
}

View File

@@ -39,7 +39,10 @@ public enum BaseReportKeyEnum {
CREATE_DATE("createDate","生产日期"), CREATE_DATE("createDate","生产日期"),
TEMPERATURE("temp","温度"), TEMPERATURE("temp","温度"),
HUMIDITY("hum","相对湿度"), HUMIDITY("hum","相对湿度"),
DELEGATE("delegate","委托方"); DELEGATE("delegate","委托方"),
CREATEDATE("createDate","出厂日期"),
HW_VERSION("hardwareVersion","硬件版本"),
SW_VERSION("softwareVersion","软件版本");
private String key; private String key;

View File

@@ -30,6 +30,7 @@ public enum BookmarkEnum {
private String desc; private String desc;
/** 书签处理顺序1=数据项2=结果信息3=目录信息;由 dealDataModelScatteredByBookmark 排序时使用 */
private Integer sort; private Integer sort;
BookmarkEnum(String key, String desc, Integer sort) { BookmarkEnum(String key, String desc, Integer sort) {

View File

@@ -39,6 +39,8 @@ import com.njcn.gather.device.service.IPqDevService;
import com.njcn.gather.device.service.IPqDevSubService; import com.njcn.gather.device.service.IPqDevSubService;
import com.njcn.gather.err.pojo.po.PqErrSys; import com.njcn.gather.err.pojo.po.PqErrSys;
import com.njcn.gather.err.service.IPqErrSysService; import com.njcn.gather.err.service.IPqErrSysService;
import com.njcn.gather.monitor.pojo.po.PqMonitor;
import com.njcn.gather.monitor.service.IPqMonitorService;
import com.njcn.gather.plan.pojo.enums.DataSourceEnum; import com.njcn.gather.plan.pojo.enums.DataSourceEnum;
import com.njcn.gather.plan.pojo.enums.PlanReportStateEnum; import com.njcn.gather.plan.pojo.enums.PlanReportStateEnum;
import com.njcn.gather.plan.pojo.po.AdPlan; import com.njcn.gather.plan.pojo.po.AdPlan;
@@ -59,21 +61,20 @@ import com.njcn.gather.report.service.IPqReportService;
import com.njcn.gather.result.service.IResultService; import com.njcn.gather.result.service.IResultService;
import com.njcn.gather.script.pojo.vo.PqScriptDtlDataVO; import com.njcn.gather.script.pojo.vo.PqScriptDtlDataVO;
import com.njcn.gather.script.service.IPqScriptDtlsService; import com.njcn.gather.script.service.IPqScriptDtlsService;
import com.njcn.gather.storage.pojo.param.SingleNonHarmParam;
import com.njcn.gather.storage.pojo.po.SimAndDigHarmonicResult; import com.njcn.gather.storage.pojo.po.SimAndDigHarmonicResult;
import com.njcn.gather.storage.pojo.po.SimAndDigNonHarmonicResult; import com.njcn.gather.storage.pojo.po.SimAndDigNonHarmonicResult;
import com.njcn.gather.storage.service.SimAndDigHarmonicService; import com.njcn.gather.storage.service.SimAndDigHarmonicService;
import com.njcn.gather.storage.service.SimAndDigNonHarmonicService; import com.njcn.gather.storage.service.SimAndDigNonHarmonicService;
import com.njcn.gather.system.cfg.pojo.enums.SceneEnum; import com.njcn.gather.system.cfg.pojo.enums.SceneEnum;
import com.njcn.gather.system.cfg.service.ISysTestConfigService; import com.njcn.gather.system.cfg.service.ISysTestConfigService;
import com.njcn.gather.system.config.PathConfig;
import com.njcn.gather.system.dictionary.pojo.po.DictData; import com.njcn.gather.system.dictionary.pojo.po.DictData;
import com.njcn.gather.system.dictionary.service.IDictDataService; import com.njcn.gather.system.dictionary.service.IDictDataService;
import com.njcn.gather.system.pojo.enums.SystemResponseEnum; import com.njcn.gather.system.pojo.enums.SystemResponseEnum;
import com.njcn.gather.tools.report.model.constant.ReportConstant; import com.njcn.gather.tools.report.model.constant.ReportConstant;
import com.njcn.gather.tools.report.service.IWordReportService; import com.njcn.gather.tools.report.service.IWordReportService;
import com.njcn.gather.tools.report.util.BookmarkUtil; import com.njcn.gather.tools.report.util.*;
import com.njcn.gather.tools.report.util.Docx4jUtil;
import com.njcn.gather.tools.report.util.DocxMergeUtil;
import com.njcn.gather.tools.report.util.WordDocumentUtil;
import com.njcn.gather.type.pojo.po.DevType; import com.njcn.gather.type.pojo.po.DevType;
import com.njcn.gather.type.service.IDevTypeService; import com.njcn.gather.type.service.IDevTypeService;
import com.njcn.gather.user.user.pojo.po.SysUser; import com.njcn.gather.user.user.pojo.po.SysUser;
@@ -86,6 +87,7 @@ import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.net.ftp.FTPClient; import org.apache.commons.net.ftp.FTPClient;
import org.apache.commons.net.ftp.FTPReply; import org.apache.commons.net.ftp.FTPReply;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.docx4j.jaxb.Context; import org.docx4j.jaxb.Context;
import org.docx4j.openpackaging.packages.WordprocessingMLPackage; import org.docx4j.openpackaging.packages.WordprocessingMLPackage;
import org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart; import org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart;
@@ -113,6 +115,7 @@ import java.nio.file.NoSuchFileException;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List; import java.util.List;
import java.util.*; import java.util.*;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
@@ -128,12 +131,23 @@ import java.util.stream.Collectors;
@RequiredArgsConstructor @RequiredArgsConstructor
public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> implements IPqReportService { public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> implements IPqReportService {
@Value("${report.template:D:\\template}") /**
private String templatePath; * resultMap 内部协议:当 dealDataLine 跑完一轮但未采集到任何有效合格性数据时,
* 在 resultMap 中塞入这个 key 作为"已尝试且无数据"的哨兵,避免后续 TEST_RESULT_*
@Value("${report.reportDir:D:\\report}") * 分支的 fallback 重复调用 dealDataLine 浪费资源;同时 dealTestResultLine 检测到
private String reportPath; * 此 key 存在时跳过结论表生成。
* <p>
* 故意使用明显非业务字符串,避免与任何 PqScriptDtls.scriptCode / PowerIndexEnum
* 的真实业务取值撞车。
*/
private static final String RESULT_MAP_NO_DATA_FLAG = "__internal_no_data__";
// @Value("${report.template:D:\\template}")
// private String templatePath;
//
// @Value("${report.reportDir:D:\\report}")
// private String reportPath;
private final PathConfig pathConfig;
@Value("${qr.cloud}") @Value("${qr.cloud}")
private String cloudUrl; private String cloudUrl;
@@ -162,6 +176,8 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
@Value("${qr.gcDev.path}") @Value("${qr.gcDev.path}")
private String gcDevPath; private String gcDevPath;
@Value("${report.dateFormat}")
private String dateFormat;
private final IPqDevService iPqDevService; private final IPqDevService iPqDevService;
private final PqDevMapper pqDevMapper; private final PqDevMapper pqDevMapper;
@@ -179,6 +195,7 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
private final ISysUserService sysUserService; private final ISysUserService sysUserService;
private final IPqErrSysService pqErrSysService; private final IPqErrSysService pqErrSysService;
private final IAdPlanTestConfigService adPlanTestConfigService; private final IAdPlanTestConfigService adPlanTestConfigService;
private final IPqMonitorService pqMonitorService;
@Resource @Resource
private RestTemplateUtil restTemplateUtil; private RestTemplateUtil restTemplateUtil;
@@ -307,7 +324,8 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
private void uploadFile(ReportParam reportParam, PqReport pqReport, boolean isAdd) { private void uploadFile(ReportParam reportParam, PqReport pqReport, boolean isAdd) {
MultipartFile baseFile = reportParam.getBaseFile(); MultipartFile baseFile = reportParam.getBaseFile();
MultipartFile detailFile = reportParam.getDetailFile(); MultipartFile detailFile = reportParam.getDetailFile();
String newDir = templatePath + File.separator + reportParam.getName() + File.separator + reportParam.getVersion() + File.separator; String relativePath = reportParam.getName() + File.separator + reportParam.getVersion() + File.separator;
String newDir = pathConfig.getReportTemplatePath() + File.separator + relativePath;
long FILE_SIZE_LIMIT = 5 * 1024 * 1024; long FILE_SIZE_LIMIT = 5 * 1024 * 1024;
if (isAdd) { if (isAdd) {
@@ -326,13 +344,13 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
throw new BusinessException(ReportResponseEnum.FILE_SIZE_ERROR); throw new BusinessException(ReportResponseEnum.FILE_SIZE_ERROR);
} }
pqReport.setBasePath(newDir + baseOriginalFilename); pqReport.setBasePath(relativePath + baseOriginalFilename);
pqReport.setDetailPath(newDir + detailOriginalFilename); pqReport.setDetailPath(relativePath + detailOriginalFilename);
this.createDirectory(newDir); this.createDirectory(newDir);
this.clearDirectory(newDir); this.clearDirectory(newDir);
this.uploadFile(baseFile, pqReport.getBasePath()); this.uploadFile(baseFile, newDir + baseOriginalFilename);
this.uploadFile(detailFile, pqReport.getDetailPath()); this.uploadFile(detailFile, newDir + detailOriginalFilename);
} else { } else {
throw new BusinessException(ReportResponseEnum.FILE_NOT_NULL); throw new BusinessException(ReportResponseEnum.FILE_NOT_NULL);
} }
@@ -380,34 +398,34 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
//若修改了文件名称、版本号,则需要重命名文件 //若修改了文件名称、版本号,则需要重命名文件
this.createDirectory(newDir); this.createDirectory(newDir);
if (!oldDir.equals(newDir)) { if (!oldDir.equals(relativePath)) {
// 文件夹重命名 // 文件夹重命名
String oldBasePathStr = oldPqReport.getBasePath(); String oldBasePathStr = oldPqReport.getBasePath();
String baseName = oldBasePathStr.substring(oldBasePathStr.lastIndexOf(File.separator) + 1); String baseName = oldBasePathStr.substring(oldBasePathStr.lastIndexOf(File.separator) + 1);
Path oldBasePath = Paths.get(oldBasePathStr); Path oldBasePath = Paths.get(pathConfig.getReportTemplatePath() + File.separator + oldBasePathStr);
Path newBasePath = Paths.get(newDir + baseName); Path newBasePath = Paths.get(newDir + baseName);
pqReport.setBasePath(newDir + baseName); pqReport.setBasePath(relativePath + baseName);
String oldDetailPathStr = oldPqReport.getDetailPath(); String oldDetailPathStr = oldPqReport.getDetailPath();
String detailName = oldDetailPathStr.substring(oldDetailPathStr.lastIndexOf(File.separator) + 1); String detailName = oldDetailPathStr.substring(oldDetailPathStr.lastIndexOf(File.separator) + 1);
Path oldDetailPath = Paths.get(oldDetailPathStr); Path oldDetailPath = Paths.get(pathConfig.getReportTemplatePath() + File.separator + oldDetailPathStr);
Path newDetailPath = Paths.get(newDir + detailName); Path newDetailPath = Paths.get(newDir + detailName);
pqReport.setDetailPath(newDir + detailName); pqReport.setDetailPath(relativePath + detailName);
try { try {
// windows下文件夹名称不区分大小写 // windows下文件夹名称不区分大小写
if (!oldDir.equalsIgnoreCase(newDir)) { if (!oldDir.equalsIgnoreCase(relativePath)) {
this.clearDirectory(newDir); this.clearDirectory(newDir);
Files.move(oldBasePath, newBasePath); Files.move(oldBasePath, newBasePath);
Files.move(oldDetailPath, newDetailPath); Files.move(oldDetailPath, newDetailPath);
if (!oldPqReport.getName().equals(reportParam.getName()) && !this.existSameName(pqReport.getId(), oldPqReport.getName())) { if (!oldPqReport.getName().equals(reportParam.getName()) && !this.existSameName(pqReport.getId(), oldPqReport.getName())) {
this.recursionDeleteDirectory(templatePath + File.separator + oldPqReport.getName()); this.recursionDeleteDirectory(pathConfig.getReportTemplatePath() + File.separator + oldPqReport.getName());
} else { } else {
Paths.get(oldDir).toFile().delete(); Paths.get(pathConfig.getReportTemplatePath() + oldDir).toFile().delete();
} }
} else { } else {
// 文件夹重命名 // 文件夹重命名
Paths.get(oldDir).toFile().renameTo(Paths.get(newDir).toFile()); Paths.get(pathConfig.getReportTemplatePath() + oldDir).toFile().renameTo(Paths.get(newDir).toFile());
} }
} catch (IOException e) { } catch (IOException e) {
throw new BusinessException(ReportResponseEnum.FILE_RENAME_FAILED); throw new BusinessException(ReportResponseEnum.FILE_RENAME_FAILED);
@@ -415,16 +433,16 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
} }
if (!baseFileOriginalFilename.isEmpty()) { if (!baseFileOriginalFilename.isEmpty()) {
pqReport.setBasePath(newDir + baseFileOriginalFilename); pqReport.setBasePath(relativePath + baseFileOriginalFilename);
Paths.get(oldPqReport.getBasePath()).toFile().delete(); Paths.get(pathConfig.getReportTemplatePath() + File.separator + oldPqReport.getBasePath()).toFile().delete();
Paths.get(newDir + oldPqReport.getBasePath().substring(oldPqReport.getBasePath().lastIndexOf(File.separator) + 1)).toFile().delete(); Paths.get(newDir + oldPqReport.getBasePath().substring(oldPqReport.getBasePath().lastIndexOf(File.separator) + 1)).toFile().delete();
this.uploadFile(baseFile, pqReport.getBasePath()); this.uploadFile(baseFile, newDir + baseFileOriginalFilename);
} }
if (!detailFileOriginalFilename.isEmpty()) { if (!detailFileOriginalFilename.isEmpty()) {
pqReport.setDetailPath(newDir + detailFileOriginalFilename); pqReport.setDetailPath(relativePath + detailFileOriginalFilename);
Paths.get(oldPqReport.getDetailPath()).toFile().delete(); Paths.get(pathConfig.getReportTemplatePath() + File.separator + oldPqReport.getDetailPath()).toFile().delete();
Paths.get(newDir + oldPqReport.getDetailPath().substring(oldPqReport.getDetailPath().lastIndexOf(File.separator) + 1)).toFile().delete(); Paths.get(newDir + oldPqReport.getDetailPath().substring(oldPqReport.getDetailPath().lastIndexOf(File.separator) + 1)).toFile().delete();
this.uploadFile(detailFile, pqReport.getDetailPath()); this.uploadFile(detailFile, newDir + detailFileOriginalFilename);
} }
} }
} }
@@ -507,7 +525,7 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
private void deleteFile(List<String> ids) { private void deleteFile(List<String> ids) {
List<PqReport> pqReports = this.listByIds(ids); List<PqReport> pqReports = this.listByIds(ids);
for (PqReport pqReport : pqReports) { for (PqReport pqReport : pqReports) {
String uploadDir = templatePath + File.separator + pqReport.getName() + File.separator + pqReport.getVersion() + File.separator; String uploadDir = pathConfig.getReportTemplatePath() + File.separator + pqReport.getName() + File.separator + pqReport.getVersion() + File.separator;
Path uploadPath = Paths.get(uploadDir); Path uploadPath = Paths.get(uploadDir);
if (Files.exists(uploadPath)) { if (Files.exists(uploadPath)) {
//清空目录下的文件 //清空目录下的文件
@@ -519,7 +537,7 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
} }
} }
file1.delete(); file1.delete();
String dir = templatePath + File.separator + pqReport.getName() + File.separator; String dir = pathConfig.getReportTemplatePath() + File.separator + pqReport.getName() + File.separator;
Path dirPath = Paths.get(dir); Path dirPath = Paths.get(dir);
File dirFile = dirPath.toFile(); File dirFile = dirPath.toFile();
File[] fileArr2 = dirFile.listFiles(); File[] fileArr2 = dirFile.listFiles();
@@ -574,6 +592,11 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
/** /**
* 根据设备类型生成报告 * 根据设备类型生成报告
* 注:该方法目前仅支持楼下出厂检测场景,属于模板占位符替换方式,后期可能会有调整 * 注:该方法目前仅支持楼下出厂检测场景,属于模板占位符替换方式,后期可能会有调整
* <p>
* 批量语义:采用"任一设备失败则整批中断"——forEach 循环内任一设备抛 BusinessException
* 会终止整个循环,已生成的报告文件保留,中断之后的设备不再处理;失败原因通过异常抛给
* 调用方,调用方应提示用户修复问题后重新发起批量。此为有意保留的批量原子语义,
* 而非待修复缺陷。
* *
* @param devReportParam 被检设备信息 * @param devReportParam 被检设备信息
*/ */
@@ -608,8 +631,8 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
InputStream finalWordStream = DocxMergeUtil.mergeDocuments(wordFileInputStreams); InputStream finalWordStream = DocxMergeUtil.mergeDocuments(wordFileInputStreams);
// 处理需要输出的目录地址 基础路径+设备类型+装置编号.docx // 处理需要输出的目录地址 基础路径+设备类型+装置编号.docx
// 最终文件输出的路径 // 最终文件输出的路径
// String dirPath = reportPath.concat(File.separator).concat(devType.getName()); // String dirPath = pathConfig.getReportPath().concat(File.separator).concat(devType.getName());
String dirPath = reportPath; String dirPath = pathConfig.getReportPath();
// 确保目录存在 // 确保目录存在
ensureDirectoryExists(dirPath); ensureDirectoryExists(dirPath);
String reportFullPath = dirPath.concat(File.separator).concat(pqDevVO.getCreateId()).concat(ReportConstant.DOCX); String reportFullPath = dirPath.concat(File.separator).concat(pqDevVO.getCreateId()).concat(ReportConstant.DOCX);
@@ -774,6 +797,11 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
/** /**
* 需要支持批量生成,如果用户选择批量生成,则默认都采用测试数据的第一个合格,如果 * 需要支持批量生成,如果用户选择批量生成,则默认都采用测试数据的第一个合格,如果
* 比对模式下生成检测报告,实际后期需要根据用户选择的检测数据或者某次波形数据生成报告 * 比对模式下生成检测报告,实际后期需要根据用户选择的检测数据或者某次波形数据生成报告
* <p>
* 批量语义:采用"任一设备失败则整批中断"——forEach 循环内任一设备抛 BusinessException
* 会终止整个循环,已生成的报告文件保留,中断之后的设备不再处理;失败原因通过异常抛给
* 调用方,调用方应提示用户修复问题后重新发起批量。此为有意保留的批量原子语义,
* 而非待修复缺陷。
* *
* @param plan 计划信息 * @param plan 计划信息
* @param devReportParam 设备信息 * @param devReportParam 设备信息
@@ -786,53 +814,63 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
if (Objects.isNull(pqDevVO)) { if (Objects.isNull(pqDevVO)) {
throw new BusinessException(ReportResponseEnum.DEVICE_NOT_EXIST); throw new BusinessException(ReportResponseEnum.DEVICE_NOT_EXIST);
} }
devReportParam.setDevId(devId); if (CheckStateEnum.CHECKED.getValue().compareTo(pqDevVO.getCheckState()) <= 0) {
// 获取设备型号 devReportParam.setDevId(devId);
DevType devType = devTypeService.getById(pqDevVO.getDevType()); // 获取设备型号
if (Objects.isNull(devType)) { DevType devType = devTypeService.getById(pqDevVO.getDevType());
throw new BusinessException(ReportResponseEnum.DEVICE_TYPE_NOT_EXIST); if (Objects.isNull(devType)) {
} throw new BusinessException(ReportResponseEnum.DEVICE_TYPE_NOT_EXIST);
PqReport report = this.lambdaQuery().eq(PqReport::getId, plan.getReportTemplateId()).eq(PqReport::getState, DataStateEnum.ENABLE.getCode()).one(); }
if (Objects.isNull(report)) { PqReport report = this.lambdaQuery().eq(PqReport::getId, plan.getReportTemplateId()).eq(PqReport::getState, DataStateEnum.ENABLE.getCode()).one();
throw new BusinessException(ReportResponseEnum.REPORT_TEMPLATE_NOT_EXIST); if (Objects.isNull(report)) {
} throw new BusinessException(ReportResponseEnum.REPORT_TEMPLATE_NOT_EXIST);
Path basePath = Paths.get(report.getBasePath()); }
Path detailPath = Paths.get(report.getDetailPath()); Path basePath = Paths.get(pathConfig.getReportTemplatePath() + File.separator + report.getBasePath());
try (InputStream baseInputStream = Files.newInputStream(basePath); Path detailPath = Paths.get(pathConfig.getReportTemplatePath() + File.separator + report.getDetailPath());
InputStream detailInputStream = Files.newInputStream(detailPath)) { try (InputStream baseInputStream = Files.newInputStream(basePath);
WordprocessingMLPackage detailModelDocument = WordprocessingMLPackage.load(detailInputStream); InputStream detailInputStream = Files.newInputStream(detailPath)) {
// 获取文档基础部分,并替换占位符 WordprocessingMLPackage detailModelDocument = WordprocessingMLPackage.load(detailInputStream);
Map<String, String> baseModelDataMap = dealBaseModelContrastData(plan, pqDevVO, devType); // 获取文档基础部分,并替换占位符
InputStream wordFinishInputStream = wordReportService.replacePlaceholders(baseInputStream, baseModelDataMap); Map<String, String> baseModelDataMap = dealBaseModelContrastData(plan, pqDevVO, devType);
WordprocessingMLPackage baseModelDocument = WordprocessingMLPackage.load(wordFinishInputStream); InputStream wordFinishInputStream = wordReportService.replacePlaceholders(baseInputStream, baseModelDataMap);
MainDocumentPart baseDocumentPart = baseModelDocument.getMainDocumentPart(); WordprocessingMLPackage baseModelDocument = WordprocessingMLPackage.load(wordFinishInputStream);
MainDocumentPart baseDocumentPart = baseModelDocument.getMainDocumentPart();
// 获取数据模版页内容,根据脚本动态组装数据页内容 // 获取数据模版页内容,根据脚本动态组装数据页内容
MainDocumentPart detailDocumentPart = detailModelDocument.getMainDocumentPart(); MainDocumentPart detailDocumentPart = detailModelDocument.getMainDocumentPart();
dealDataModelScatteredByBookmarkByPlanContrast(baseDocumentPart, detailDocumentPart, devReportParam, pqDevVO); dealDataModelScatteredByBookmarkByPlanContrast(baseDocumentPart, detailDocumentPart, devReportParam, pqDevVO);
// 保存新的文档 // 保存新的文档
String dirPath = reportPath.concat(File.separator).concat(plan.getName()); String dirPath = pathConfig.getReportPath().concat(File.separator).concat(FilePathSanitizer.toSafeFileName(plan.getName()));
// 确保目录存在 // 确保目录存在
ensureDirectoryExists(dirPath); ensureDirectoryExists(dirPath);
// 构建文件名cityName_gdName_subName_name.docx // 构建文件名cityName_gdName_subName_name.docx
String fileName = String.format("%s_%s_%s_%s.docx", String fileName = String.format("%s_%s_%s_%s.docx",
pqDevVO.getCityName() != null ? pqDevVO.getCityName() : "未知地市", pqDevVO.getCityName() != null ? pqDevVO.getCityName() : "未知地市",
pqDevVO.getGdName() != null ? pqDevVO.getGdName() : "未知供电公司", pqDevVO.getGdName() != null ? pqDevVO.getGdName() : "未知供电公司",
pqDevVO.getSubName() != null ? pqDevVO.getSubName() : "未知电站", pqDevVO.getSubName() != null ? pqDevVO.getSubName() : "未知电站",
pqDevVO.getName() != null ? pqDevVO.getName() : "未知设备"); pqDevVO.getName() != null ? pqDevVO.getName() : "未知设备");
Docx4jUtil.cleanBlankPagesAndRedundantPageBreaks(baseModelDocument); // 判断是否需要在报告上输出水印
baseModelDocument.save(new File(dirPath.concat(File.separator).concat(fileName))); String leader = baseModelDataMap.get(BaseReportKeyEnum.AUDIT_BY.getKey());
this.updateDevAndPlanState(devId, devReportParam.getPlanId()); String loginName = RequestUtil.getLoginNameByToken();
} catch (NoSuchFileException e) { SysUser user = sysUserService.getUserByLoginName(loginName);
String filePath = e.getFile() != null ? e.getFile().replaceAll("\\\\", "/") : "未知文件"; if (!leader.equals(user.getName())) {
log.error("报告模板文件不存在 - 文件路径: {}", filePath, e); log.info("当前用户不是审核人,添加非正式水印");
throw new BusinessException(SystemResponseEnum.FILE_NOT_FOUND); Docx4jUtil.addWatermarkToDocument(baseModelDocument, "非正式");
} catch (IOException e) { }
log.error("报告文件读写异常", e); Docx4jUtil.cleanBlankPagesAndRedundantPageBreaks(baseModelDocument);
throw new BusinessException(SystemResponseEnum.FILE_IO_ERROR); baseModelDocument.save(new File(dirPath.concat(File.separator).concat(fileName)));
} catch (Exception e) { this.updateDevAndPlanState(devId, devReportParam.getPlanId());
log.error(ReportResponseEnum.GENERATE_REPORT_ERROR.getMessage(), e); } catch (NoSuchFileException e) {
throw new BusinessException(ReportResponseEnum.GENERATE_REPORT_ERROR); String filePath = e.getFile() != null ? e.getFile().replaceAll("\\\\", "/") : "未知文件";
log.error("报告模板文件不存在 - 文件路径: {}", filePath, e);
throw new BusinessException(SystemResponseEnum.FILE_NOT_FOUND);
} catch (IOException e) {
log.error("报告文件读写异常", e);
throw new BusinessException(SystemResponseEnum.FILE_IO_ERROR);
} catch (Exception e) {
log.error(ReportResponseEnum.GENERATE_REPORT_ERROR.getMessage(), e);
throw new BusinessException(ReportResponseEnum.GENERATE_REPORT_ERROR);
}
} }
}); });
@@ -842,6 +880,11 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
/** /**
* 根据计划绑定的报告模板生成报告 * 根据计划绑定的报告模板生成报告
* 注:该方法目前属于同用信息占位符替换,数据页为面向对象动态填充拼凑方式 * 注:该方法目前属于同用信息占位符替换,数据页为面向对象动态填充拼凑方式
* <p>
* 批量语义:采用"任一设备失败则整批中断"——forEach 循环内任一设备抛 BusinessException
* 会终止整个循环,已生成的报告文件保留,中断之后的设备不再处理;失败原因通过异常抛给
* 调用方,调用方应提示用户修复问题后重新发起批量。此为有意保留的批量原子语义,
* 而非待修复缺陷。
* *
* @param plan 计划信息 * @param plan 计划信息
* @param devReportParam 设备信息 * @param devReportParam 设备信息
@@ -864,8 +907,8 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
if (Objects.isNull(report)) { if (Objects.isNull(report)) {
throw new BusinessException(ReportResponseEnum.REPORT_TEMPLATE_NOT_EXIST); throw new BusinessException(ReportResponseEnum.REPORT_TEMPLATE_NOT_EXIST);
} }
Path basePath = Paths.get(report.getBasePath()); Path basePath = Paths.get(pathConfig.getReportTemplatePath() + File.separator + report.getBasePath());
Path detailPath = Paths.get(report.getDetailPath()); Path detailPath = Paths.get(pathConfig.getReportTemplatePath() + File.separator + report.getDetailPath());
try (InputStream baseInputStream = Files.newInputStream(basePath); try (InputStream baseInputStream = Files.newInputStream(basePath);
InputStream detailInputStream = Files.newInputStream(detailPath)) { InputStream detailInputStream = Files.newInputStream(detailPath)) {
WordprocessingMLPackage detailModelDocument = WordprocessingMLPackage.load(detailInputStream); WordprocessingMLPackage detailModelDocument = WordprocessingMLPackage.load(detailInputStream);
@@ -880,7 +923,7 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
dealDataModelScatteredByBookmark(baseDocumentPart, detailDocumentPart, devReportParam, pqDevVO); dealDataModelScatteredByBookmark(baseDocumentPart, detailDocumentPart, devReportParam, pqDevVO);
// 保存新的文档 // 保存新的文档
String dirPath = reportPath.concat(File.separator).concat(devType.getName()); String dirPath = pathConfig.getReportPath().concat(File.separator).concat(FilePathSanitizer.toSafeFileName(devType.getName()));
// 确保目录存在 // 确保目录存在
ensureDirectoryExists(dirPath); ensureDirectoryExists(dirPath);
baseModelDocument.save(new File(dirPath.concat(File.separator).concat(pqDevVO.getCreateId()).concat(ReportConstant.DOCX))); baseModelDocument.save(new File(dirPath.concat(File.separator).concat(pqDevVO.getCreateId()).concat(ReportConstant.DOCX)));
@@ -931,9 +974,9 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
* 1、数据项 * 1、数据项
* 2、结果信息 * 2、结果信息
* 3、目录信息 * 3、目录信息
* 所以要先先获取的书签进行操作排 * 按 BookmarkEnum.sort 字段排序,避免依赖枚举常量声明顺
* */ * */
Collections.sort(bookmarkEnums); bookmarkEnums.sort(Comparator.comparingInt(BookmarkEnum::getSort).thenComparingInt(Enum::ordinal));
List<Object> todoInsertList; List<Object> todoInsertList;
BookmarkUtil.BookmarkInfo bookmarkInfo; BookmarkUtil.BookmarkInfo bookmarkInfo;
Map<Integer/*回路号*/, List<ContrastTestResult>> resultMap = null; Map<Integer/*回路号*/, List<ContrastTestResult>> resultMap = null;
@@ -1154,10 +1197,11 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
Integer monitorNum = next.getKey(); Integer monitorNum = next.getKey();
// 线路下的指标数据 // 线路下的指标数据
List<ContrastTestResult> contrastTestResults = next.getValue(); List<ContrastTestResult> contrastTestResults = next.getValue();
PqMonitor pqMonitor = pqMonitorService.getByDevIdAndNum(pqDevVO.getId(), monitorNum);
// 插入回路号前,先换个页 // 插入回路号前,先换个页
todoInsertList.add(Docx4jUtil.createPageBreakParagraph()); todoInsertList.add(Docx4jUtil.createPageBreakParagraph());
// 回路标题 // 回路标题
todoInsertList.add(getContrastLineTitle(contentMap, monitorNum, stepIndex, factory)); todoInsertList.add(getContrastLineTitle(contentMap, monitorNum, stepIndex, factory, pqDevVO));
int scriptIndex = 1; int scriptIndex = 1;
for (ContrastTestResult contrastTestResult : contrastTestResults) { for (ContrastTestResult contrastTestResult : contrastTestResults) {
// 比如电压 V // 比如电压 V
@@ -1168,7 +1212,7 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
// 根据code获取对应需要填充的内容 // 根据code获取对应需要填充的内容
List<Docx4jUtil.HeadingContent> tempContent = contentMap.get(scriptCode); List<Docx4jUtil.HeadingContent> tempContent = contentMap.get(scriptCode);
// 需要区分下谐波类和非谐波类 // 需要区分下谐波类和非谐波类
List<Object> tempList = fillContentInTemplateContrast(tempContent, factory, contrastTestResult); List<Object> tempList = fillContentInTemplateContrast(tempContent, factory, contrastTestResult, pqMonitor);
todoInsertList.addAll(tempList); todoInsertList.addAll(tempList);
scriptIndex++; scriptIndex++;
} }
@@ -1210,9 +1254,9 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
* 1、数据项 * 1、数据项
* 2、结果信息 * 2、结果信息
* 3、目录信息 * 3、目录信息
* 所以要先先获取的书签进行操作排 * 按 BookmarkEnum.sort 字段排序,避免依赖枚举常量声明顺
* */ * */
Collections.sort(bookmarkEnums); bookmarkEnums.sort(Comparator.comparingInt(BookmarkEnum::getSort).thenComparingInt(Enum::ordinal));
// 定义个结果,以便存在结果信息的书签 // 定义个结果,以便存在结果信息的书签
Map<String/*指标名称*/, List<Boolean/*以回路的顺序填充结果*/>> resultMap = new HashMap<>(); Map<String/*指标名称*/, List<Boolean/*以回路的顺序填充结果*/>> resultMap = new HashMap<>();
List<Object> todoInsertList; List<Object> todoInsertList;
@@ -1261,7 +1305,7 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
if (CollUtil.isEmpty(resultMap)) { if (CollUtil.isEmpty(resultMap)) {
dealDataLine(baseDocumentPart, devReportParam, pqDevVO, resultMap); dealDataLine(baseDocumentPart, devReportParam, pqDevVO, resultMap);
} }
bookmarkInfo = BookmarkUtil.getBookmarkInfo(BookmarkEnum.TEST_RESULT_LINE.getKey(), bookmarks); bookmarkInfo = BookmarkUtil.getBookmarkInfo(BookmarkEnum.TEST_RESULT_DETAIL.getKey(), bookmarks);
todoInsertList = dealTestResultLine(devReportParam, resultMap, DocAnchorEnum.TEST_RESULT_DETAIL); todoInsertList = dealTestResultLine(devReportParam, resultMap, DocAnchorEnum.TEST_RESULT_DETAIL);
if (Objects.nonNull(bookmarkInfo) && CollectionUtil.isNotEmpty(todoInsertList)) { if (Objects.nonNull(bookmarkInfo) && CollectionUtil.isNotEmpty(todoInsertList)) {
BookmarkUtil.insertElement(bookmarkInfo, todoInsertList); BookmarkUtil.insertElement(bookmarkInfo, todoInsertList);
@@ -1286,8 +1330,8 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
*/ */
private List<Object> dealTestResultLine(DevReportParam devReportParam, Map<String, List<Boolean>> resultMap, DocAnchorEnum docAnchorEnum) { private List<Object> dealTestResultLine(DevReportParam devReportParam, Map<String, List<Boolean>> resultMap, DocAnchorEnum docAnchorEnum) {
List<Object> todoInsertList = new ArrayList<>(); List<Object> todoInsertList = new ArrayList<>();
// 先判断数据有没有,如果没有,则不处理 // 先判断数据有没有,如果没有,则不处理(哨兵协议详见 RESULT_MAP_NO_DATA_FLAG 注释)
if (CollUtil.isEmpty(resultMap.get(PowerIndexEnum.UNKNOWN.getKey()))) { if (!resultMap.containsKey(RESULT_MAP_NO_DATA_FLAG)) {
ObjectFactory factory = Context.getWmlObjectFactory(); ObjectFactory factory = Context.getWmlObjectFactory();
// 源文档的内容 // 源文档的内容
// 创建表格示例为3列列数可任意调整 // 创建表格示例为3列列数可任意调整
@@ -1376,13 +1420,27 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
/** /**
* 处理以回路维度数据项,书签占位符的方式 * 以回路维度处理数据项,并填充 resultMap指标合格性结论
* <p>
* 本方法承担双重职责:
* <ol>
* <li><b>返回值</b>:根据 modelPart 中的 H5 分组表格模板,灌入实测数据后生成可插入文档的元素列表;</li>
* <li><b>副作用</b>:把每个指标在各回路上的合格性写入 resultMap供后续 dealTestResultLine 构造结论表使用。</li>
* </ol>
* 调用约定(务必区分以下两条路径,避免误解形参用途):
* <ul>
* <li><b>常规路径</b>DATA_LINE 分支modelPart 传 detail 文档(数据页模板池),返回值会被插入 DATA_LINE 书签锚点。</li>
* <li><b>fallback 路径</b>TEST_RESULT_* 分支且 resultMap 为空时modelPart 允许传 base 文档(封面页);此时模板池为空,返回值无业务意义,调用方应丢弃,仅借此触发 resultMap 计算。</li>
* </ul>
* 因此 modelPart 命名保持中性,不要改回 detailXxx 等带语义偏向的名字。
* *
* @param detailModelDocument 数据项模板 * @param modelPart 文档模板部分;常规传 detail 文档fallback 仅需算 resultMap 时可传 base 文档
* @param devReportParam 测试报告参数 * @param devReportParam 测试报告参数
* @param pqDevVO 被检设备 * @param pqDevVO 被检设备
* @param resultMap 结果性数据集合被本方法写入fallback 路径正是借此计算)
* @return 待插入文档的元素列表fallback 路径下应被调用方丢弃
*/ */
private List<Object> dealDataLine(MainDocumentPart detailModelDocument, DevReportParam devReportParam, PqDevVO pqDevVO, Map<String, List<Boolean>> resultMap) { private List<Object> dealDataLine(MainDocumentPart modelPart, DevReportParam devReportParam, PqDevVO pqDevVO, Map<String, List<Boolean>> resultMap) {
List<Object> todoInsertList = new ArrayList<>(); List<Object> todoInsertList = new ArrayList<>();
// 以回路维度处理数据项 // 以回路维度处理数据项
Integer devChns = pqDevVO.getDevChns(); Integer devChns = pqDevVO.getDevChns();
@@ -1390,8 +1448,8 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
// 读取该计划的检测大项组装数据内容 // 读取该计划的检测大项组装数据内容
List<PqScriptDtlDataVO> pqScriptDtlsList = pqScriptDtlsService.getScriptDtlsDataList(devReportParam.getScriptId()); List<PqScriptDtlDataVO> pqScriptDtlsList = pqScriptDtlsService.getScriptDtlsDataList(devReportParam.getScriptId());
Map<String, List<PqScriptDtlDataVO>> scriptMap = pqScriptDtlsList.stream().collect(Collectors.groupingBy(PqScriptDtlDataVO::getScriptCode, LinkedHashMap::new, Collectors.toList())); Map<String, List<PqScriptDtlDataVO>> scriptMap = pqScriptDtlsList.stream().collect(Collectors.groupingBy(PqScriptDtlDataVO::getScriptCode, LinkedHashMap::new, Collectors.toList()));
List<Object> allContent = detailModelDocument.getContent(); List<Object> allContent = modelPart.getContent();
List<Docx4jUtil.HeadingContent> headingContents = Docx4jUtil.extractHeading5Contents(allContent, detailModelDocument); List<Docx4jUtil.HeadingContent> headingContents = Docx4jUtil.extractHeading5Contents(allContent, modelPart);
Map<String, List<Docx4jUtil.HeadingContent>> contentMap = headingContents.stream().collect(Collectors.groupingBy(Docx4jUtil.HeadingContent::getHeadingText, Collectors.toList())); Map<String, List<Docx4jUtil.HeadingContent>> contentMap = headingContents.stream().collect(Collectors.groupingBy(Docx4jUtil.HeadingContent::getHeadingText, Collectors.toList()));
for (int i = 0; i < devChns; i++) { for (int i = 0; i < devChns; i++) {
// 回路标题 // 回路标题
@@ -1459,9 +1517,11 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
} }
} }
} }
// 如果经过一处理后,结果性数据集合还是空,塞个特殊数据进去,避免嵌套循环 // 经过一处理仍未采集到任何合格性数据时,塞入哨兵:
// 一是让后续 TEST_RESULT_* 分支的 fallback 看到 resultMap 非空而跳过重复调用本方法,
// 二是供 dealTestResultLine 据此跳过结论表生成(哨兵协议详见 RESULT_MAP_NO_DATA_FLAG 注释)。
if (CollUtil.isEmpty(resultMap)) { if (CollUtil.isEmpty(resultMap)) {
resultMap.put(PowerIndexEnum.UNKNOWN.getKey(), Collections.singletonList(false)); resultMap.put(RESULT_MAP_NO_DATA_FLAG, Collections.singletonList(false));
} }
return todoInsertList; return todoInsertList;
} }
@@ -1586,18 +1646,37 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
// 获取现有行的样式 // 获取现有行的样式
Tr existingRow = (Tr) tbl.getContent().get(rows.size() - 1); Tr existingRow = (Tr) tbl.getContent().get(rows.size() - 1);
// 获取现有样式 // 获取现有样式
TrPr trPr = existingRow.getTrPr(); TrPr trPr = existingRow.getTrPr();
JAXBElement<Tc> element = (JAXBElement<Tc>) existingRow.getContent().get(0); // 获取每个单元格的TcPr保留各单元格独立的边框设置
TcPr tcPr = element.getValue().getTcPr(); List<TcPr> tcPrList = new ArrayList<>();
TblWidth cellWidth = factory.createTblWidth(); RPr templateRPr = null;
cellWidth.setType("dxa"); for (Object cellObj : existingRow.getContent()) {
cellWidth.setW(BigInteger.valueOf(5000 / tableKeys.size())); if (cellObj instanceof JAXBElement) {
tcPr.setTcW(cellWidth); JAXBElement<Tc> cellElement = (JAXBElement<Tc>) cellObj;
Tc templateCell = cellElement.getValue();
TcPr tcPr = templateCell.getTcPr();
// 设置单元格宽度
if (tcPr == null) {
tcPr = factory.createTcPr();
}
TblWidth cellWidth = factory.createTblWidth();
cellWidth.setType("dxa");
cellWidth.setW(BigInteger.valueOf(5000 / tableKeys.size()));
tcPr.setTcW(cellWidth);
tcPrList.add(tcPr);
// 从第一个单元格获取字体样式
if (templateRPr == null && !templateCell.getContent().isEmpty() && templateCell.getContent().get(0) instanceof P) {
P templateP = (P) templateCell.getContent().get(0);
templateRPr = Docx4jUtil.getTcPrFromParagraph(templateP);
}
}
}
tbl.getContent().remove(existingRow); tbl.getContent().remove(existingRow);
// 迭代增加行,需要填充的表格keys在tableKeys集合中 // 迭代增加行,需要填充的表格keys在tableKeys集合中
for (Map<String, String> stringStringMap : dataList) { for (Map<String, String> stringStringMap : dataList) {
Tr newRow = Docx4jUtil.createCustomRow(factory, stringStringMap, tableKeys, trPr, tcPr, true); Tr newRow = Docx4jUtil.createCustomRow(factory, stringStringMap, tableKeys, trPr, tcPrList, templateRPr, true);
tbl.getContent().add(newRow); tbl.getContent().add(newRow);
} }
} else { } else {
@@ -1624,7 +1703,7 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
* *
* @return * @return
*/ */
private List<Object> fillContentInTemplateContrast(List<Docx4jUtil.HeadingContent> tempContent, ObjectFactory factory, ContrastTestResult contrastTestResult) { private List<Object> fillContentInTemplateContrast(List<Docx4jUtil.HeadingContent> tempContent, ObjectFactory factory, ContrastTestResult contrastTestResult, PqMonitor pqMonitor) {
List<Object> todoInsertList = new ArrayList<>(); List<Object> todoInsertList = new ArrayList<>();
Docx4jUtil.HeadingContent headingContent = tempContent.get(0); Docx4jUtil.HeadingContent headingContent = tempContent.get(0);
List<String> tableKeys = Docx4jUtil.getTableFillKeys(tempContent); List<String> tableKeys = Docx4jUtil.getTableFillKeys(tempContent);
@@ -1738,9 +1817,47 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
// 纵向表格暂不考虑 // 纵向表格暂不考虑
} }
// 如果存在特殊说明,在表格后添加一个段落 StringBuilder description = new StringBuilder();
if (StrUtil.isNotBlank(contrastTestResult.getSpecialCase())) { if (contrastTestResult.getScriptCode().equalsIgnoreCase("I")) {
P specialCaseP = Docx4jUtil.createSpecialCaseParagraph(factory, contrastTestResult.getSpecialCase()); // 获取该通道的额定电流
String ct = pqMonitor.getCt();
// 理论上ct是 xxx:xxx的格式。比如10:1100:5
if (ct.indexOf(":") > 0) {
String[] ctArray = ct.split(":");
description.append("注:当前回路额定电流为:").append(ctArray[1]).append("A。");
}
} else if (contrastTestResult.getScriptCode().equalsIgnoreCase("V")) {
// 获取该通道的额定电压
String pt = pqMonitor.getPt();
// 理论上pt是 xxx:xxx的格式。比如380:38010000:100
if (pt.indexOf(":") > 0) {
String[] ptArray = pt.split(":");
// 电压需要特殊处理下,处理为相电压值
String voltage = ptArray[1];
if (voltage.equalsIgnoreCase("100")) {
voltage = "57.74";
} else if (voltage.equalsIgnoreCase("380")) {
voltage = "220";
} else {
// 其他场景下就除以根号3
double result = Double.parseDouble(voltage) / Math.sqrt(3);
voltage = doubleRound(2, result);
}
description.append("注:当前回路额定电流为:").append(voltage).append("V。");
}
}
// 如果存在特殊说明,在表格后添加一个段落 如果有电压和电流需要把额定电压和电流标注进来 pqMonitor
if (StrUtil.isNotBlank(contrastTestResult.getSpecialCase()) || StrUtil.isNotBlank(description.toString())) {
P specialCaseP;
if (StrUtil.isNotBlank(description.toString())) {
if (StrUtil.isNotBlank(contrastTestResult.getSpecialCase())) {
description.append(contrastTestResult.getSpecialCase().replace("注:", ""));
}
specialCaseP = Docx4jUtil.createSpecialCaseParagraph(factory, description.toString());
} else {
specialCaseP = Docx4jUtil.createSpecialCaseParagraph(factory, contrastTestResult.getSpecialCase());
}
todoInsertList.add(specialCaseP); todoInsertList.add(specialCaseP);
} }
} }
@@ -1817,7 +1934,7 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
if (SceneEnum.LEAVE_FACTORY_TEST.getValue().equals(currrentScene)) { if (SceneEnum.LEAVE_FACTORY_TEST.getValue().equals(currrentScene)) {
// 出厂测试场景 // 出厂测试场景
filePath = reportPath.concat(File.separator).concat(pqDevVO.getCreateId()).concat(ReportConstant.DOCX); filePath = pathConfig.getReportPath().concat(File.separator).concat(pqDevVO.getCreateId()).concat(ReportConstant.DOCX);
downloadFileName = pqDevVO.getCreateId() + ReportConstant.DOCX; downloadFileName = pqDevVO.getCreateId() + ReportConstant.DOCX;
} else if (plan != null) { } else if (plan != null) {
// 根据计划模式确定路径结构 // 根据计划模式确定路径结构
@@ -1829,16 +1946,16 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
pqDevVO.getGdName() != null ? pqDevVO.getGdName() : "未知供电公司", pqDevVO.getGdName() != null ? pqDevVO.getGdName() : "未知供电公司",
pqDevVO.getSubName() != null ? pqDevVO.getSubName() : "未知电站", pqDevVO.getSubName() != null ? pqDevVO.getSubName() : "未知电站",
pqDevVO.getName() != null ? pqDevVO.getName() : "未知设备"); pqDevVO.getName() != null ? pqDevVO.getName() : "未知设备");
filePath = reportPath.concat(File.separator).concat(plan.getName()).concat(File.separator).concat(fileName); filePath = pathConfig.getReportPath().concat(File.separator).concat(FilePathSanitizer.toSafeFileName(plan.getName())).concat(File.separator).concat(fileName);
downloadFileName = fileName; downloadFileName = fileName;
} else { } else {
// 数字/模拟模式:使用原来的路径结构 // 数字/模拟模式:使用原来的路径结构
filePath = reportPath.concat(File.separator).concat(devType.getName()).concat(File.separator).concat(pqDevVO.getCreateId()).concat(ReportConstant.DOCX); filePath = pathConfig.getReportPath().concat(File.separator).concat(FilePathSanitizer.toSafeFileName(devType.getName())).concat(File.separator).concat(pqDevVO.getCreateId()).concat(ReportConstant.DOCX);
downloadFileName = pqDevVO.getCreateId() + ReportConstant.DOCX; downloadFileName = pqDevVO.getCreateId() + ReportConstant.DOCX;
} }
} else { } else {
// 兜底:使用旧的路径结构 // 兜底:使用旧的路径结构
filePath = reportPath.concat(File.separator).concat(devType.getName()).concat(File.separator).concat(pqDevVO.getCreateId()).concat(ReportConstant.DOCX); filePath = pathConfig.getReportPath().concat(File.separator).concat(FilePathSanitizer.toSafeFileName(devType.getName())).concat(File.separator).concat(pqDevVO.getCreateId()).concat(ReportConstant.DOCX);
downloadFileName = pqDevVO.getCreateId() + ReportConstant.DOCX; downloadFileName = pqDevVO.getCreateId() + ReportConstant.DOCX;
} }
@@ -1948,6 +2065,18 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
baseModelMap.put(BaseReportKeyEnum.DEV_TYPE.getKey(), devType.getName()); baseModelMap.put(BaseReportKeyEnum.DEV_TYPE.getKey(), devType.getName());
// 检测员 // 检测员
baseModelMap.put(BaseReportKeyEnum.INSPECTOR.getKey(), pqDevVO.getCheckBy() + ""); baseModelMap.put(BaseReportKeyEnum.INSPECTOR.getKey(), pqDevVO.getCheckBy() + "");
baseModelMap.put(BaseReportKeyEnum.INSPECTOR.getKey(), pqDevVO.getCheckBy() + "");
String datePattern = DatePattern.NORM_DATE_PATTERN;
if (DatePattern.CHINESE_DATE_PATTERN.equals(dateFormat)) {
datePattern = DatePattern.CHINESE_DATE_PATTERN;
}
// 出厂日期
baseModelMap.put(BaseReportKeyEnum.CREATEDATE.getKey(), pqDevVO.getCreateDate().format(DateTimeFormatter.ofPattern(datePattern)));
// 硬件版本
baseModelMap.put(BaseReportKeyEnum.HW_VERSION.getKey(), StrUtil.isNotBlank(pqDevVO.getHardwareVersion()) ? pqDevVO.getHardwareVersion() : StrUtil.EMPTY);
// 软件版本
baseModelMap.put(BaseReportKeyEnum.SW_VERSION.getKey(), StrUtil.isNotBlank(pqDevVO.getSoftwareVersion()) ? pqDevVO.getSoftwareVersion() : StrUtil.EMPTY);
// 调试日期 // 调试日期
if (pqDevVO.getCheckTime() != null) { if (pqDevVO.getCheckTime() != null) {
baseModelMap.put(BaseReportKeyEnum.TEST_DATE.getKey(), DateUtil.format(pqDevVO.getCheckTime(), DatePattern.CHINESE_DATE_PATTERN)); baseModelMap.put(BaseReportKeyEnum.TEST_DATE.getKey(), DateUtil.format(pqDevVO.getCheckTime(), DatePattern.CHINESE_DATE_PATTERN));
@@ -2016,7 +2145,7 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
// 委托方 // 委托方
String delegate = pqDevVO.getDelegate(); String delegate = pqDevVO.getDelegate();
if (StrUtil.isNotBlank(delegate)) { if (StrUtil.isNotBlank(delegate)) {
DictData delegateDictData = dictDataService.getDictDataById(pqDevVO.getManufacturer()); DictData delegateDictData = dictDataService.getDictDataById(pqDevVO.getDelegate());
if (ObjectUtil.isNotNull(delegateDictData)) { if (ObjectUtil.isNotNull(delegateDictData)) {
baseModelMap.put(BaseReportKeyEnum.DELEGATE.getKey(), delegateDictData.getName()); baseModelMap.put(BaseReportKeyEnum.DELEGATE.getKey(), delegateDictData.getName());
} else { } else {
@@ -2088,7 +2217,19 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
private void dealDataModel(List<InputStream> wordFileInputStreams, DevReportParam devReportParam, PqDevVO pqDevVO) throws Exception { private void dealDataModel(List<InputStream> wordFileInputStreams, DevReportParam devReportParam, PqDevVO pqDevVO) throws Exception {
Integer devChns = pqDevVO.getDevChns(); Integer devChns = pqDevVO.getDevChns();
for (int i = 1; i <= devChns; i++) { for (int i = 1; i <= devChns; i++) {
ClassPathResource resource = new ClassPathResource("/model/report_table.docx"); String path = "/model/report_table.docx";
DevType devType = devTypeService.getById(pqDevVO.getDevType());
if (devType.getName().equals("PQ-COM")) {
path = "/model/report_table - PQ-COM.docx";
}
ClassPathResource resource = new ClassPathResource(path);
XWPFDocument dataModelDocumentTemp = new XWPFDocument(resource.getInputStream());
SingleNonHarmParam singleNonHarmParam = new SingleNonHarmParam();
singleNonHarmParam.setPlanCode(devReportParam.getPlanCode());
singleNonHarmParam.setDevId(pqDevVO.getId());
singleNonHarmParam.setChannelNo(i);
// 获取数据 // 获取数据
Map<String, String> dataModelMap = new HashMap<>(16); Map<String, String> dataModelMap = new HashMap<>(16);
// 读取模板文件中的占位符 // 读取模板文件中的占位符
@@ -2106,11 +2247,20 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
List<SimAndDigHarmonicResult> adHarmonicResultList = adHarmonicService.listAllResultData(devReportParam.getScriptId(), devReportParam.getPlanCode(), devReportParam.getDevId() + "_" + i); List<SimAndDigHarmonicResult> adHarmonicResultList = adHarmonicService.listAllResultData(devReportParam.getScriptId(), devReportParam.getPlanCode(), devReportParam.getDevId() + "_" + i);
// 填充数据 // 填充数据
int finalI = i;
indexKeysMap.forEach((index, keys) -> { indexKeysMap.forEach((index, keys) -> {
String s1 = keys.stream().findFirst().get(); String s1 = keys.stream().findFirst().get();
// 谐波类 // 谐波类
if (DetectionCodeEnum.V2_50.getCode().equals(s1) || DetectionCodeEnum.I2_50.getCode().equals(s1) || DetectionCodeEnum.SV_1_49.getCode().equals(s1) || DetectionCodeEnum.SI_1_49.getCode().equals(s1)) { if (DetectionCodeEnum.V2_50.getCode().equals(s1) || DetectionCodeEnum.I2_50.getCode().equals(s1) || DetectionCodeEnum.SV_1_49.getCode().equals(s1) || DetectionCodeEnum.SI_1_49.getCode().equals(s1)) {
fillMapValueHarm(adHarmonicResultList, dataModelMap, keys, index); // 查找一下U1
double u1 = 57.74;
List<SimAndDigHarmonicResult> rawData = adHarmonicService.listAllRawData(devReportParam.getScriptId(), devReportParam.getPlanCode(), devReportParam.getDevId() + "_" + finalI);
SimAndDigHarmonicResult adHarmonicResult = rawData.stream().filter(obj -> obj.getAdType().equals(DetectionCodeEnum.V2_50.getCode())).sorted((obj1, obj2) -> obj2.getTimeId().compareTo(obj1.getTimeId())).findFirst().orElse(null);
if (ObjectUtil.isNotNull(adHarmonicResult)) {
String aValue1 = adHarmonicResult.getAValue1();
u1 = Double.parseDouble(aValue1);
}
fillMapValueHarm(adHarmonicResultList, dataModelMap, keys, index, u1);
} else { } else {
// 非谐波类 // 非谐波类
if (DetectionCodeEnum.V_UNBAN.getCode().equals(s1) || DetectionCodeEnum.FREQ.getCode().equals(s1)) { if (DetectionCodeEnum.V_UNBAN.getCode().equals(s1) || DetectionCodeEnum.FREQ.getCode().equals(s1)) {
@@ -2178,14 +2328,14 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
* @param keys key * @param keys key
* @param index index * @param index index
*/ */
private void fillMapValueHarm(List<SimAndDigHarmonicResult> allHarmonicResultList, Map<String, String> dataModelMap, Set<String> keys, String index) { private void fillMapValueHarm(List<SimAndDigHarmonicResult> allHarmonicResultList, Map<String, String> dataModelMap, Set<String> keys, String index, double baseValue) {
keys.forEach(key -> { keys.forEach(key -> {
List<SimAndDigHarmonicResult> resultList = allHarmonicResultList.stream().filter(obj -> obj.getAdType().equals(key) && obj.getSort().toString().equals(index)).collect(Collectors.toList()); List<SimAndDigHarmonicResult> resultList = allHarmonicResultList.stream().filter(obj -> obj.getAdType().equals(key) && obj.getSort().toString().equals(index)).collect(Collectors.toList());
if (CollectionUtil.isNotEmpty(resultList)) { if (CollectionUtil.isNotEmpty(resultList)) {
SimAndDigHarmonicResult adHarmonicResult = resultList.get(0); SimAndDigHarmonicResult adHarmonicResult = resultList.get(0);
if (Objects.nonNull(adHarmonicResult)) { if (Objects.nonNull(adHarmonicResult)) {
if (DetectionCodeEnum.V2_50.getCode().equals(key) || DetectionCodeEnum.SV_1_49.getCode().equals(key)) { if (DetectionCodeEnum.V2_50.getCode().equals(key) || DetectionCodeEnum.SV_1_49.getCode().equals(key)) {
fillHarm(dataModelMap, adHarmonicResult, index, key, 57.74, 100); fillHarm(dataModelMap, adHarmonicResult, index, key, baseValue, 100);
} }
if (DetectionCodeEnum.I2_50.getCode().equals(key) || DetectionCodeEnum.SI_1_49.getCode().equals(key)) { if (DetectionCodeEnum.I2_50.getCode().equals(key) || DetectionCodeEnum.SI_1_49.getCode().equals(key)) {
fillHarm(dataModelMap, adHarmonicResult, index, key, 1, 1); fillHarm(dataModelMap, adHarmonicResult, index, key, 1, 1);
@@ -2333,7 +2483,7 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
return; return;
} }
log.info("找到{}台设备需要上传报告", devices.size()); log.info("找到{}台设备需要上传报告", devices.size());
String dirPath = reportPath; String dirPath = pathConfig.getReportPath();
// 确保目录存在 // 确保目录存在
ensureDirectoryExists(dirPath); ensureDirectoryExists(dirPath);
// 异步批量上传每台设备的报告 // 异步批量上传每台设备的报告
@@ -2392,16 +2542,21 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
/** /**
* 创建回路标题到报告中 * 创建回路标题到报告中
*/ */
private P getContrastLineTitle(Map<String, List<Docx4jUtil.HeadingContent>> contentMap, int monitorNum, int index, ObjectFactory factory) { private P getContrastLineTitle(Map<String, List<Docx4jUtil.HeadingContent>> contentMap, int monitorNum, int index, ObjectFactory factory, PqDevVO pqDevVO) {
PqMonitor pqMonitor = pqMonitorService.getByDevIdAndNum(pqDevVO.getId(), monitorNum);
String monitorInfoName = "";
if (StrUtil.isNotBlank(pqDevVO.getSubName()) && Objects.nonNull(pqMonitor)) {
monitorInfoName = "(" + pqDevVO.getSubName() + "-" + pqMonitor.getName() + ")";
}
List<Docx4jUtil.HeadingContent> headingContents = contentMap.get(PowerIndexEnum.LINE_TITLE.getKey()); List<Docx4jUtil.HeadingContent> headingContents = contentMap.get(PowerIndexEnum.LINE_TITLE.getKey());
// 如果contentMap中有指定内容创建大纲级别为2的标题 // 如果contentMap中有指定内容创建大纲级别为2的标题
if (CollUtil.isNotEmpty(headingContents)) { if (CollUtil.isNotEmpty(headingContents)) {
return Docx4jUtil.createTitle(factory, 2, index + ".测量回路" + monitorNum, return Docx4jUtil.createTitle(factory, 2, index + ".测量回路" + monitorNum + monitorInfoName,
"SimSun", 30, true); "SimSun", 30, true);
} }
// 没有模板配置时,创建默认样式段落 // 没有模板配置时,创建默认样式段落
P titleParagraph = factory.createP(); P titleParagraph = factory.createP();
Docx4jUtil.createTitle(factory, titleParagraph, "测量回路" + monitorNum, Docx4jUtil.createTitle(factory, titleParagraph, "测量回路" + monitorNum + monitorInfoName,
28, true); 28, true);
return titleParagraph; return titleParagraph;
} }

View File

@@ -198,7 +198,7 @@ public class ResultController extends BaseController {
String methodDescribe = getMethodDescribe("getCheckItem"); String methodDescribe = getMethodDescribe("getCheckItem");
LogUtil.njcnDebug(log, "{},查询数据为:{}", methodDescribe, monitorQueryParam); LogUtil.njcnDebug(log, "{},查询数据为:{}", methodDescribe, monitorQueryParam);
List<ContrastTestItemVO> result = resultService.getCheckItem(monitorQueryParam.getPlanId(), monitorQueryParam.getDevId(), monitorQueryParam.getChnNum(), monitorQueryParam.getNum()); List<ContrastTestItemVO> result = resultService.getCheckItem(monitorQueryParam.getPlanId(), monitorQueryParam.getDevId(), monitorQueryParam.getChnNum(), monitorQueryParam.getNum(), monitorQueryParam.getCode());
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe); return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
} }
} }

View File

@@ -17,4 +17,6 @@ public class MonitorQueryParam {
private Integer waveNum; private Integer waveNum;
private String planId; private String planId;
private String code;
} }

View File

@@ -2,6 +2,7 @@ package com.njcn.gather.result.pojo.param;
import com.njcn.common.pojo.constant.PatternRegex; import com.njcn.common.pojo.constant.PatternRegex;
import com.njcn.gather.pojo.constant.DetectionValidMessage; import com.njcn.gather.pojo.constant.DetectionValidMessage;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
@@ -74,6 +75,8 @@ public class ResultParam {
// 模式id // 模式id
private String patternId; private String patternId;
private String code;
} }
@Data @Data
@@ -100,5 +103,11 @@ public class ResultParam {
@ApiModelProperty(value = "模式Id", required = true) @ApiModelProperty(value = "模式Id", required = true)
private String patternId; private String patternId;
@ApiModelProperty(value = "通道号", required = true)
private String chnNum;
@ApiModelProperty(value = "数据处理原则", required = true)
private String dataRuleId;
} }
} }

View File

@@ -123,9 +123,10 @@ public interface IResultService {
* @param devId * @param devId
* @param chnNum * @param chnNum
* @param num * @param num
* @param code
* @return * @return
*/ */
List<ContrastTestItemVO> getCheckItem(String planId, String devId, String chnNum, Integer num); List<ContrastTestItemVO> getCheckItem(String planId, String devId, String chnNum, Integer num,String code);
/** /**
* 获取设备比对式结果,用于出比对检测的报告 * 获取设备比对式结果,用于出比对检测的报告

View File

@@ -146,11 +146,11 @@ public class ResultServiceImpl implements IResultService {
formContentVO.setErrorSysId(plan.getErrorSysId()); formContentVO.setErrorSysId(plan.getErrorSysId());
String scriptId = null; String scriptId = null;
if (ObjectUtil.isNotNull(plan)) { if (ObjectUtil.isNotNull(plan)) {
formContentVO.setDataRule(plan.getDataRule());
scriptId = plan.getScriptId(); scriptId = plan.getScriptId();
adPlanService.visualize(Collections.singletonList(plan)); adPlanService.visualize(Collections.singletonList(plan));
formContentVO.setScriptName(plan.getScriptId());
} }
formContentVO.setScriptName(plan.getScriptId());
formContentVO.setDataRule(plan.getDataRule());
formContentVO.setDeviceName(pqDevService.getById(queryParam.getDeviceId()).getName()); formContentVO.setDeviceName(pqDevService.getById(queryParam.getDeviceId()).getName());
List<Map<String, String>> chnList = new ArrayList<>(); List<Map<String, String>> chnList = new ArrayList<>();
@@ -341,10 +341,19 @@ public class ResultServiceImpl implements IResultService {
private void dipScriptTypeName(List<PqScriptDtls> subValue, List<TreeDataVO> subTypeList, Map<Integer, Set<Integer>> finalResultMap, Boolean isValueType, String name, Integer start, Integer end) { private void dipScriptTypeName(List<PqScriptDtls> subValue, List<TreeDataVO> subTypeList, Map<Integer, Set<Integer>> finalResultMap, Boolean isValueType, String name, Integer start, Integer end) {
List<TreeDataVO> info = new ArrayList<>(); List<TreeDataVO> info = new ArrayList<>();
List<PqScriptDtls> dip = subValue.stream() List<PqScriptDtls> dip = subValue.stream()
.filter(x -> "Dip".equals(x.getValueType()) && "A".equals(x.getPhase())) // .filter(x -> "Dip".equals(x.getValueType()) && "A".equals(x.getPhase()))
.filter(x -> "Dip".equals(x.getValueType()))
.filter(x -> x.getTransValue() >= start && x.getTransValue() <= end) .filter(x -> x.getTransValue() >= start && x.getTransValue() <= end)
.sorted(Comparator.comparing(PqScriptDtls::getScriptIndex)) .sorted(Comparator.comparing(PqScriptDtls::getScriptIndex))
.collect(Collectors.toList()); .collect(Collectors.toList());
LinkedHashMap<Integer, List<PqScriptDtls>> idxDipMap = dip.stream().collect(Collectors.groupingBy(d -> d.getScriptIndex(), LinkedHashMap::new, Collectors.toList()));
dip.clear();
idxDipMap.forEach((idx, scriptDtlList) -> {
scriptDtlList.sort(Comparator.comparing(PqScriptDtls::getPhase));
dip.add(scriptDtlList.get(0));
});
TreeDataVO vo = new TreeDataVO(); TreeDataVO vo = new TreeDataVO();
vo.setScriptTypeName(name); vo.setScriptTypeName(name);
vo.setScriptTypeCode("Base_" + start + "_" + end); vo.setScriptTypeCode("Base_" + start + "_" + end);
@@ -983,10 +992,10 @@ public class ResultServiceImpl implements IResultService {
DictData dictData = dictDataService.getDictDataById(param.getPatternId()); DictData dictData = dictDataService.getDictDataById(param.getPatternId());
if (PatternEnum.CONTRAST.getValue().equals(dictData.getCode())) { if (PatternEnum.CONTRAST.getValue().equals(dictData.getCode())) {
this.createTempResultTable(param.getCode() + "_temp", true); this.createTempResultTable(param.getCode() + "_temp", true);
this.contrastCalculateResult(param.getPlanId(), param.getCode() + "_temp", param.getErrorSysId(), param.getDeviceId()); this.contrastCalculateResult(param.getPlanId(), param.getCode() + "_temp", param.getErrorSysId(), param.getDeviceId(), false, param.getDataRuleId());
} else { } else {
this.createTempResultTable(param.getCode() + "_temp", false); this.createTempResultTable(param.getCode() + "_temp", false);
this.simAndDigCalculateResult(param.getPlanId(), param.getScriptId(), param.getCode() + "_temp", param.getErrorSysId(), param.getDeviceId()); this.simAndDigCalculateResult(param.getPlanId(), param.getScriptId(), param.getCode() + "_temp", param.getErrorSysId(), param.getDeviceId(), param.getDataRuleId());
} }
} }
@@ -1000,9 +1009,9 @@ public class ResultServiceImpl implements IResultService {
public void reCalculate(ResultParam.ChangeErrorSystemParam param) { public void reCalculate(ResultParam.ChangeErrorSystemParam param) {
DictData dictData = dictDataService.getDictDataById(param.getPatternId()); DictData dictData = dictDataService.getDictDataById(param.getPatternId());
if (PatternEnum.CONTRAST.getValue().equals(dictData.getCode())) { if (PatternEnum.CONTRAST.getValue().equals(dictData.getCode())) {
this.contrastCalculateResult(param.getPlanId(), param.getCode(), param.getErrorSysId(), param.getDeviceId()); this.contrastCalculateResult(param.getPlanId(), param.getCode(), param.getErrorSysId(), param.getDeviceId(), true, param.getDataRuleId());
} else { } else {
this.simAndDigCalculateResult(param.getPlanId(), param.getScriptId(), param.getCode(), param.getErrorSysId(), param.getDeviceId()); this.simAndDigCalculateResult(param.getPlanId(), param.getScriptId(), param.getCode(), param.getErrorSysId(), param.getDeviceId(), param.getDataRuleId());
} }
} }
@@ -1533,8 +1542,7 @@ public class ResultServiceImpl implements IResultService {
AdPlan plan = adPlanService.getById(queryParam.getPlanId()); AdPlan plan = adPlanService.getById(queryParam.getPlanId());
PqDev dev = pqDevService.getById(queryParam.getDeviceId()); PqDev dev = pqDevService.getById(queryParam.getDeviceId());
DictData dictData = dictDataService.getById(plan.getDataRule()); formContentVO.setDataRule(plan.getDataRule());
formContentVO.setDataRule(dictData.getName());
formContentVO.setDeviceName(dev.getName()); formContentVO.setDeviceName(dev.getName());
formContentVO.setErrorSysId(plan.getErrorSysId()); formContentVO.setErrorSysId(plan.getErrorSysId());
@@ -1581,8 +1589,6 @@ public class ResultServiceImpl implements IResultService {
public ContrastResultVO getContrastResult(ResultParam.QueryParam queryParam) { public ContrastResultVO getContrastResult(ResultParam.QueryParam queryParam) {
ContrastResultVO contrastResultVO = new ContrastResultVO(); ContrastResultVO contrastResultVO = new ContrastResultVO();
AdPlan plan = adPlanService.getById(queryParam.getPlanId());
List<DictTree> dictTreeList = dictTreeService.getDictTreeById(Collections.singletonList(queryParam.getScriptType())); List<DictTree> dictTreeList = dictTreeService.getDictTreeById(Collections.singletonList(queryParam.getScriptType()));
List<String> fatherIdList = dictTreeList.stream().map(DictTree::getId).collect(Collectors.toList()); List<String> fatherIdList = dictTreeList.stream().map(DictTree::getId).collect(Collectors.toList());
@@ -1604,8 +1610,8 @@ public class ResultServiceImpl implements IResultService {
} }
} }
contrastResultVO.setResultMap(this.getResultMap(dictTree, adTypeList, queryParam.getDeviceId() + CnSocketUtil.SPLIT_TAG + queryParam.getChnNum(), unit, queryParam.getNum(), queryParam.getWaveNum(), queryParam.getIsWave(), String.valueOf(plan.getCode()))); contrastResultVO.setResultMap(this.getResultMap(dictTree, adTypeList, queryParam.getDeviceId() + CnSocketUtil.SPLIT_TAG + queryParam.getChnNum(), unit, queryParam.getNum(), queryParam.getWaveNum(), queryParam.getIsWave(), queryParam.getCode()));
contrastResultVO.setRawDataMap(this.getRawDataMap(dictTree, adTypeList, queryParam.getDeviceId() + CnSocketUtil.SPLIT_TAG + queryParam.getChnNum(), unit, queryParam.getNum(), queryParam.getWaveNum(), queryParam.getIsWave(), String.valueOf(plan.getCode()), contrastResultVO.getResultMap().keySet().stream().collect(Collectors.toList()))); contrastResultVO.setRawDataMap(this.getRawDataMap(dictTree, adTypeList, queryParam.getDeviceId() + CnSocketUtil.SPLIT_TAG + queryParam.getChnNum(), unit, queryParam.getNum(), queryParam.getWaveNum(), queryParam.getIsWave(), queryParam.getCode(), contrastResultVO.getResultMap().keySet().stream().collect(Collectors.toList())));
return contrastResultVO; return contrastResultVO;
} }
@@ -1886,10 +1892,10 @@ public class ResultServiceImpl implements IResultService {
} }
@Override @Override
public List<ContrastTestItemVO> getCheckItem(String planId, String devId, String chnNum, Integer num) { public List<ContrastTestItemVO> getCheckItem(String planId, String devId, String chnNum, Integer num, String code) {
// PqDev dev = pqDevService.getById(devId); // PqDev dev = pqDevService.getById(devId);
AdPlan plan = adPlanService.getById(planId); AdPlan plan = adPlanService.getById(planId);
String code = String.valueOf(plan.getCode()); // String code = String.valueOf(plan.getCode());
String monitorId = devId + CnSocketUtil.SPLIT_TAG + chnNum; String monitorId = devId + CnSocketUtil.SPLIT_TAG + chnNum;
@@ -2872,23 +2878,23 @@ public class ResultServiceImpl implements IResultService {
for (int i = 0; i < devNonHarmonicRawDataList.size(); i++) { for (int i = 0; i < devNonHarmonicRawDataList.size(); i++) {
AlignDataVO.RawData rawDataVO = new AlignDataVO.RawData(); AlignDataVO.RawData rawDataVO = new AlignDataVO.RawData();
rawDataVO.setUnit(unit); rawDataVO.setUnit(unit);
ContrastNonHarmonicResult contrastNonHarmonicResult = devNonHarmonicRawDataList.get(i); ContrastNonHarmonicResult contrastNonHarmonicResultDev = devNonHarmonicRawDataList.get(i);
rawDataVO.setTimeDev(contrastNonHarmonicResult.getTimeId().format(dtf)); rawDataVO.setTimeDev(contrastNonHarmonicResultDev.getTimeId().format(dtf));
rawDataVO.setUbDev(getValue(contrastNonHarmonicResult.getBValue())); rawDataVO.setUbDev(getValue(contrastNonHarmonicResultDev.getBValue()));
rawDataVO.setUtDev(getValue(contrastNonHarmonicResult.getTValue())); rawDataVO.setUtDev(getValue(contrastNonHarmonicResultDev.getTValue()));
contrastNonHarmonicResult = stdDevNonHarmonicRawDataList.get(i); ContrastNonHarmonicResult contrastNonHarmonicResultStdDev = stdDevNonHarmonicRawDataList.get(i);
rawDataVO.setTimeStdDev(contrastNonHarmonicResult.getTimeId().format(dtf)); rawDataVO.setTimeStdDev(contrastNonHarmonicResultStdDev.getTimeId().format(dtf));
if (!DicDataEnum.IMBV.getCode().equals(dictTree.getCode()) && !DicDataEnum.IMBA.getCode().equals(dictTree.getCode())) { if (!DicDataEnum.IMBV.getCode().equals(dictTree.getCode()) && !DicDataEnum.IMBA.getCode().equals(dictTree.getCode())) {
rawDataVO.setUaDev(getValue(contrastNonHarmonicResult.getAValue())); rawDataVO.setUaDev(getValue(contrastNonHarmonicResultDev.getAValue()));
rawDataVO.setUcDev(getValue(contrastNonHarmonicResult.getCValue())); rawDataVO.setUcDev(getValue(contrastNonHarmonicResultDev.getCValue()));
rawDataVO.setUaStdDev(getValue(contrastNonHarmonicResult.getAValue())); rawDataVO.setUaStdDev(getValue(contrastNonHarmonicResultStdDev.getAValue()));
rawDataVO.setUcStdDev(getValue(contrastNonHarmonicResult.getCValue())); rawDataVO.setUcStdDev(getValue(contrastNonHarmonicResultStdDev.getCValue()));
} }
rawDataVO.setUbStdDev(getValue(contrastNonHarmonicResult.getBValue())); rawDataVO.setUbStdDev(getValue(contrastNonHarmonicResultStdDev.getBValue()));
rawDataVO.setUtStdDev(getValue(contrastNonHarmonicResult.getTValue())); rawDataVO.setUtStdDev(getValue(contrastNonHarmonicResultStdDev.getTValue()));
rawDataVOList.add(rawDataVO); rawDataVOList.add(rawDataVO);
} }
@@ -3067,7 +3073,7 @@ public class ResultServiceImpl implements IResultService {
* @param errorSysId * @param errorSysId
* @param devId * @param devId
*/ */
private void simAndDigCalculateResult(String planId, String scriptId, String code, String errorSysId, String devId) { private void simAndDigCalculateResult(String planId, String scriptId, String code, String errorSysId, String devId, String dataRuleId) {
String oldCode = code.replace("_temp", ""); String oldCode = code.replace("_temp", "");
PreDetectionParam param = new PreDetectionParam(); PreDetectionParam param = new PreDetectionParam();
param.setCode(code); param.setCode(code);
@@ -3085,8 +3091,8 @@ public class ResultServiceImpl implements IResultService {
// } else { // } else {
// dataRule = DictDataEnum.SECTION_VALUE; // dataRule = DictDataEnum.SECTION_VALUE;
// } // }
AdPlan plan = adPlanService.getById(planId); // AdPlan plan = adPlanService.getById(planId);
DictData dictData = dictDataService.getDictDataById(plan.getDataRule()); DictData dictData = dictDataService.getDictDataById(dataRuleId);
if (ObjectUtil.isNotNull(dictData)) { if (ObjectUtil.isNotNull(dictData)) {
dataRule = DictDataEnum.getDictDataEnumByCode(dictData.getCode()); dataRule = DictDataEnum.getDictDataEnumByCode(dictData.getCode());
} else { } else {
@@ -3134,7 +3140,7 @@ public class ResultServiceImpl implements IResultService {
checkDataParam.setIsValueTypeName(false); checkDataParam.setIsValueTypeName(false);
List<String> valueType = iPqScriptCheckDataService.getValueType(checkDataParam); List<String> valueType = iPqScriptCheckDataService.getValueType(checkDataParam);
iPqDevService.updateResult(param.getDevIds(), valueType, param.getCode(), param.getUserId(), param.getTemperature(), param.getHumidity()); iPqDevService.updateResult(param.getDevIds(), valueType, param.getCode(), param.getUserId(), param.getTemperature(), param.getHumidity(), false);
} }
/** /**
@@ -3144,8 +3150,9 @@ public class ResultServiceImpl implements IResultService {
* @param code * @param code
* @param errorSysId * @param errorSysId
* @param deviceId * @param deviceId
* @param updateResult
*/ */
private void contrastCalculateResult(String planId, String code, String errorSysId, String deviceId) { private void contrastCalculateResult(String planId, String code, String errorSysId, String deviceId, boolean updateResult, String dataRuleId) {
String oldCode = code.replace("_temp", ""); String oldCode = code.replace("_temp", "");
Map<String, String> devIdMapComm = new HashMap<>(); Map<String, String> devIdMapComm = new HashMap<>();
@@ -3188,33 +3195,38 @@ public class ResultServiceImpl implements IResultService {
} }
DictDataEnum dataRule; DictDataEnum dataRule;
DictData dictData = dictDataService.getDictDataById(plan.getDataRule()); DictData dictData = dictDataService.getDictDataById(dataRuleId);
if (ObjectUtil.isNotNull(dictData)) { if (ObjectUtil.isNotNull(dictData)) {
dataRule = DictDataEnum.getDictDataEnumByCode(dictData.getCode()); dataRule = DictDataEnum.getDictDataEnumByCode(dictData.getCode());
} else { } else {
dataRule = DictDataEnum.SECTION_VALUE; dataRule = DictDataEnum.SECTION_VALUE;
} }
pqMonitorService.lambdaUpdate().set(PqMonitor::getRecordedResult, null) if (updateResult) {
.set(PqMonitor::getRealtimeNum, null) pqMonitorService.lambdaUpdate().set(PqMonitor::getRecordedResult, null)
.set(PqMonitor::getRecordedResult, null) .set(PqMonitor::getRealtimeNum, null)
.set(PqMonitor::getRecordedNum, null) .set(PqMonitor::getRecordedResult, null)
.set(PqMonitor::getStatisticsResult, null) .set(PqMonitor::getRecordedNum, null)
.set(PqMonitor::getStatisticsNum, null) .set(PqMonitor::getStatisticsResult, null)
.set(PqMonitor::getResultType, null) .set(PqMonitor::getStatisticsNum, null)
.set(PqMonitor::getQualifiedNum, 0) .set(PqMonitor::getResultType, null)
.eq(PqMonitor::getDevId, deviceId) .set(PqMonitor::getQualifiedNum, 0)
.eq(PqMonitor::getCheckFlag, 1) .eq(PqMonitor::getDevId, deviceId)
.update(); // .eq(PqMonitor::getNum, Integer.parseInt(chnNum))
.eq(PqMonitor::getCheckFlag, 1)
.update();
}
// String monitorId = deviceId + CnSocketUtil.SPLIT_TAG + chnNum;
List<AdPair> adPairList = adPairService.listByDevIds(Arrays.asList(deviceId)); List<AdPair> adPairList = adPairService.listByDevIds(Arrays.asList(deviceId));
Map<Integer, List<AdPair>> numAdPairsMap = adPairList.stream().collect(Collectors.groupingBy(AdPair::getNum, Collectors.toList())); Map<Integer, List<AdPair>> numAdPairsMap = adPairList.stream().collect(Collectors.groupingBy(AdPair::getNum, Collectors.toList()));
numAdPairsMap.forEach((num, pairList) -> { numAdPairsMap.forEach((num, pairList) -> {
BiMap<String, String> parsIp = HashBiMap.create();
BiMap<String, String> parsId = HashBiMap.create();
Map<String, Integer> numMap = new HashMap<>(); Map<String, Integer> numMap = new HashMap<>();
Map<String, List<AdPair>> devMonitroIdMap = pairList.stream().collect(Collectors.groupingBy(AdPair::getDevMonitorId, Collectors.toList())); Map<String, List<AdPair>> devMonitroIdMap = pairList.stream().collect(Collectors.groupingBy(AdPair::getDevMonitorId, Collectors.toList()));
devMonitroIdMap.forEach((devMonitorId, pairList1) -> { devMonitroIdMap.forEach((devMonitorId, pairList1) -> {
BiMap<String, String> parsIp = HashBiMap.create();
BiMap<String, String> parsId = HashBiMap.create();
String[] split1 = devMonitorId.split(CnSocketUtil.SPLIT_TAG); String[] split1 = devMonitorId.split(CnSocketUtil.SPLIT_TAG);
AdPair adPair = pairList1.get(0); AdPair adPair = pairList1.get(0);
String[] split2 = adPair.getStdDevMonitorId().split(CnSocketUtil.SPLIT_TAG); String[] split2 = adPair.getStdDevMonitorId().split(CnSocketUtil.SPLIT_TAG);
@@ -3225,42 +3237,40 @@ public class ResultServiceImpl implements IResultService {
numMap.put(devMonitorId, num); numMap.put(devMonitorId, num);
numMap.put(adPair.getStdDevMonitorId(), num); numMap.put(adPair.getStdDevMonitorId(), num);
devIdMapComm.put(standardDev.getIp(), standardDev.getId()); devIdMapComm.put(standardDev.getIp(), standardDev.getId());
});
List<ContrastNonHarmonicResult> devNonHarmonicRawDataList = contrastNonHarmonicService.listAllRawData(oldCode, num, null, false, null, 0, deviceId, null); List<ContrastNonHarmonicResult> devNonHarmonicRawDataList = contrastNonHarmonicService.listAllRawData(oldCode, num, null, false, null, 0, devMonitorId, null);
List<ContrastNonHarmonicResult> stdDevNonHarmonicRawDataList = contrastNonHarmonicService.listAllRawData(oldCode, num, null, false, null, 1, deviceId, null); List<ContrastNonHarmonicResult> stdDevNonHarmonicRawDataList = contrastNonHarmonicService.listAllRawData(oldCode, num, null, false, null, 1, devMonitorId, null);
List<ContrastHarmonicResult> devHarmonicRawDataList = contrastHarmonicService.listAllRawData(oldCode, num, null, false, null, 0, deviceId, null); List<ContrastHarmonicResult> devHarmonicRawDataList = contrastHarmonicService.listAllRawData(oldCode, num, null, false, null, 0, devMonitorId, null);
List<ContrastHarmonicResult> stdDevHarmonicRawDataList = contrastHarmonicService.listAllRawData(oldCode, num, null, false, null, 1, deviceId, null); List<ContrastHarmonicResult> stdDevHarmonicRawDataList = contrastHarmonicService.listAllRawData(oldCode, num, null, false, null, 1, devMonitorId, null);
List<DevData> devData = contrastToList(devNonHarmonicRawDataList, devHarmonicRawDataList, testItemMap, 0); List<DevData> devData = contrastToList(devNonHarmonicRawDataList, devHarmonicRawDataList, testItemMap, 0);
List<DevData> standardDevData = contrastToList(stdDevNonHarmonicRawDataList, stdDevHarmonicRawDataList, testItemMap, 1); List<DevData> standardDevData = contrastToList(stdDevNonHarmonicRawDataList, stdDevHarmonicRawDataList, testItemMap, 1);
if (CollUtil.isNotEmpty(devData) && CollUtil.isNotEmpty(standardDevData)) { if (CollUtil.isNotEmpty(devData) && CollUtil.isNotEmpty(standardDevData)) {
detectionServiceImpl.processing(devData, standardDevData, parsIp, devIdMapComm, testItemMap.keySet().stream().collect(Collectors.toList()), errorSysId, dataRule, numMap, code, null, finalNonWaveDataSourceEnum); detectionServiceImpl.processing(devData, standardDevData, parsIp, devIdMapComm, testItemMap.keySet().stream().collect(Collectors.toList()), errorSysId, dataRule, numMap, code, null, finalNonWaveDataSourceEnum);
parsId.forEach((devMonitorId, stdDevMonitorId) -> { if (updateResult) {
String[] split = devMonitorId.split(CnSocketUtil.SPLIT_TAG); pqMonitorService.updateMonitorResult(devMonitorId, null, finalNonWaveDataSourceEnum, num, null, oldCode);
pqMonitorService.updateMonitorResult(devMonitorId, null, finalNonWaveDataSourceEnum, num, null, oldCode); pqDevService.updateResult(split1[0], null);
pqDevService.updateResult(split[0], null); }
}); }
}
AdPlanTestConfig adPlanTestConfig = adPlanTestConfigService.getByPlanId(planId); AdPlanTestConfig adPlanTestConfig = adPlanTestConfigService.getByPlanId(planId);
for (int i = 1; i <= adPlanTestConfig.getWaveRecord(); i++) { for (int i = 1; i <= adPlanTestConfig.getWaveRecord(); i++) {
devNonHarmonicRawDataList = contrastNonHarmonicService.listAllRawData(oldCode, num, i, true, null, 0, deviceId, null); devNonHarmonicRawDataList = contrastNonHarmonicService.listAllRawData(oldCode, num, i, true, null, 0, devMonitorId, null);
stdDevNonHarmonicRawDataList = contrastNonHarmonicService.listAllRawData(oldCode, num, i, true, null, 1, deviceId, null); stdDevNonHarmonicRawDataList = contrastNonHarmonicService.listAllRawData(oldCode, num, i, true, null, 1, devMonitorId, null);
devHarmonicRawDataList = contrastHarmonicService.listAllRawData(oldCode, num, i, true, null, 0, deviceId, null); devHarmonicRawDataList = contrastHarmonicService.listAllRawData(oldCode, num, i, true, null, 0, devMonitorId, null);
stdDevHarmonicRawDataList = contrastHarmonicService.listAllRawData(oldCode, num, i, true, null, 1, deviceId, null); stdDevHarmonicRawDataList = contrastHarmonicService.listAllRawData(oldCode, num, i, true, null, 1, devMonitorId, null);
devData = contrastToList(devNonHarmonicRawDataList, devHarmonicRawDataList, testItemMap, 0); devData = contrastToList(devNonHarmonicRawDataList, devHarmonicRawDataList, testItemMap, 0);
standardDevData = contrastToList(stdDevNonHarmonicRawDataList, stdDevHarmonicRawDataList, testItemMap, 1); standardDevData = contrastToList(stdDevNonHarmonicRawDataList, stdDevHarmonicRawDataList, testItemMap, 1);
detectionServiceImpl.processing(devData, standardDevData, parsIp, devIdMapComm, testItemMap.keySet().stream().collect(Collectors.toList()), errorSysId, dataRule, numMap, oldCode, i, DataSourceEnum.WAVE_DATA); detectionServiceImpl.processing(devData, standardDevData, parsIp, devIdMapComm, testItemMap.keySet().stream().collect(Collectors.toList()), errorSysId, dataRule, numMap, oldCode, i, DataSourceEnum.WAVE_DATA);
} }
parsId.forEach((devMonitorId, stdDevMonitorId) -> { if (updateResult) {
String[] split = devMonitorId.split(CnSocketUtil.SPLIT_TAG); pqMonitorService.updateMonitorResult(devMonitorId, null, WAVE_DATA, num, adPlanTestConfig.getWaveRecord(), oldCode);
pqMonitorService.updateMonitorResult(devMonitorId, null, WAVE_DATA, num, adPlanTestConfig.getWaveRecord(), oldCode); pqDevService.updateResult(split1[0], null);
pqDevService.updateResult(split[0], null); }
}); });
}); });
} }
@@ -3604,7 +3614,7 @@ public class ResultServiceImpl implements IResultService {
return 4; return 4;
// 保留3位小数 // 保留3位小数
case "I": // 电流 case "I": // 电流
return 3; return 5;
// 保留4位小数 // 保留4位小数
case "IMBV": // 电压不平衡度 case "IMBV": // 电压不平衡度
case "IMBA": // 电流不平衡度 case "IMBA": // 电流不平衡度

View File

@@ -126,10 +126,10 @@ public class PqScriptController extends BaseController {
@GetMapping("/getAll") @GetMapping("/getAll")
@ApiOperation("获取指定模式下的所有检测脚本") @ApiOperation("获取指定模式下的所有检测脚本")
@ApiImplicitParam(name = "patternId", value = "模式Id", required = true) @ApiImplicitParam(name = "patternId", value = "模式Id", required = true)
public HttpResult<List<Map<String, Object>>> getAllPqScript(@RequestParam("patternId") String patternId) { public HttpResult<List<PqScript>> getAllPqScript(@RequestParam("patternId") String patternId) {
String methodDescribe = getMethodDescribe("getAllPqScript"); String methodDescribe = getMethodDescribe("getAllPqScript");
LogUtil.njcnDebug(log, "{},查询数据为:{}", methodDescribe, patternId); LogUtil.njcnDebug(log, "{},查询数据为:{}", methodDescribe, patternId);
List<Map<String, Object>> result = pqScriptService.listAllPqScript(patternId); List<PqScript> result = pqScriptService.listAllPqScript(patternId);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe); return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
} }

View File

@@ -72,6 +72,9 @@ public class PqScriptParam {
@Max(value = 20, message = DetectionValidMessage.SCRIPT_CURR_FORMAT_ERROR) @Max(value = 20, message = DetectionValidMessage.SCRIPT_CURR_FORMAT_ERROR)
private Double ratedCurr; private Double ratedCurr;
@ApiModelProperty("是否为Fluke专用脚本")
private Integer fluke;
@Data @Data
@EqualsAndHashCode(callSuper = true) @EqualsAndHashCode(callSuper = true)

View File

@@ -73,6 +73,11 @@ public class PqScript extends BaseEntity implements Serializable {
*/ */
private Double ratedCurr; private Double ratedCurr;
/**
* 是否为福禄克专用脚本。0-否 1-是
*/
private Integer fluke;
/** /**
* 状态0-删除 1-正常 * 状态0-删除 1-正常
*/ */

View File

@@ -92,6 +92,18 @@ public class PqScriptDtls implements Serializable {
@TableField("RetainTime") @TableField("RetainTime")
private Double retainTime; private Double retainTime;
/**
* 暂态前延时间S
*/
@TableField("FPreTime")
private Double fPreTime;
/**
* 暂态后延时间S
*/
@TableField("FAfterTime")
private Double fAfterTime;
/** /**
* 变动频度(次/min * 变动频度(次/min
*/ */

View File

@@ -68,7 +68,7 @@ public interface IPqScriptService extends IService<PqScript> {
* @param patternId 模式id * @param patternId 模式id
* @return 检测脚本列表 * @return 检测脚本列表
*/ */
List<Map<String, Object>> listAllPqScript(String patternId); List<PqScript> listAllPqScript(String patternId);
/** /**
* 根据脚本名称查询脚本 * 根据脚本名称查询脚本

View File

@@ -13,6 +13,7 @@ import com.njcn.gather.detection.pojo.enums.DetectionCodeEnum;
import com.njcn.gather.detection.pojo.param.PreDetectionParam; import com.njcn.gather.detection.pojo.param.PreDetectionParam;
import com.njcn.gather.device.pojo.enums.CommonEnum; import com.njcn.gather.device.pojo.enums.CommonEnum;
import com.njcn.gather.device.pojo.po.PqDev; import com.njcn.gather.device.pojo.po.PqDev;
import com.njcn.gather.device.pojo.vo.PqDevVO;
import com.njcn.gather.device.service.IPqDevService; import com.njcn.gather.device.service.IPqDevService;
import com.njcn.gather.plan.mapper.AdPlanMapper; import com.njcn.gather.plan.mapper.AdPlanMapper;
import com.njcn.gather.plan.pojo.po.AdPlan; import com.njcn.gather.plan.pojo.po.AdPlan;
@@ -33,6 +34,7 @@ import com.njcn.gather.script.service.IPqScriptCheckDataService;
import com.njcn.gather.script.service.IPqScriptDtlsService; import com.njcn.gather.script.service.IPqScriptDtlsService;
import com.njcn.gather.script.util.ScriptDtlsDesc; import com.njcn.gather.script.util.ScriptDtlsDesc;
import com.njcn.gather.script.util.ThreePhaseUnbalance; import com.njcn.gather.script.util.ThreePhaseUnbalance;
import com.njcn.gather.source.service.IPqSourceService;
import com.njcn.gather.system.dictionary.pojo.po.DictTree; import com.njcn.gather.system.dictionary.pojo.po.DictTree;
import com.njcn.gather.system.dictionary.service.IDictTreeService; import com.njcn.gather.system.dictionary.service.IDictTreeService;
import com.njcn.gather.system.pojo.enums.DicDataEnum; import com.njcn.gather.system.pojo.enums.DicDataEnum;
@@ -67,20 +69,17 @@ public class PqScriptDtlsServiceImpl extends ServiceImpl<PqScriptDtlsMapper, PqS
private final static String INHARM_I = "InHarm_I"; private final static String INHARM_I = "InHarm_I";
private final static String DIP = "Dip"; private final static String DIP = "Dip";
private final static String FLICKER = "Flicker"; private final static String FLICKER = "Flicker";
@Value("${Dip.fPreTime}") // @Value("${Dip.fPreTime}")
private Double fPreTime; // private Double fPreTime;
@Value("${Dip.fRampIn}") @Value("${Dip.fRampIn}")
private Double fRampIn; private Double fRampIn;
@Value("${Dip.fRampOut}") @Value("${Dip.fRampOut}")
private Double fRampOut; private Double fRampOut;
@Value("${Dip.fAfterTime}") // @Value("${Dip.fAfterTime}")
private Double fAfterTime; // private Double fAfterTime;
@Value("${Flicker.waveFluType}") private static final String waveFluType = "SQU";
private String waveFluType; private static final String waveType = "CPM";
@Value("${Flicker.waveType}") private static final Double fDutyCycle = 50.0;
private String waveType;
@Value("${Flicker.fDutyCycle}")
private Double fDutyCycle;
private final IPqDevService pqDevService; private final IPqDevService pqDevService;
@@ -90,6 +89,7 @@ public class PqScriptDtlsServiceImpl extends ServiceImpl<PqScriptDtlsMapper, PqS
private final IDevTypeService devTypeService; private final IDevTypeService devTypeService;
private final IDictTreeService dictTreeService; private final IDictTreeService dictTreeService;
private final AdPlanMapper adPlanMapper; private final AdPlanMapper adPlanMapper;
private final IPqSourceService pqSourceService;
@Override @Override
@Transactional @Transactional
@@ -384,6 +384,8 @@ public class PqScriptDtlsServiceImpl extends ServiceImpl<PqScriptDtlsMapper, PqS
dip.setPhase(phase); dip.setPhase(phase);
dip.setTransValue(dipData.getFTransValue()); dip.setTransValue(dipData.getFTransValue());
dip.setRetainTime(dipData.getRetainTime()); dip.setRetainTime(dipData.getRetainTime());
dip.setFPreTime(dipData.getFPreTime());
dip.setFAfterTime(dipData.getFAfterTime());
info.add(dip); info.add(dip);
} }
} }
@@ -419,7 +421,7 @@ public class PqScriptDtlsServiceImpl extends ServiceImpl<PqScriptDtlsMapper, PqS
@Override @Override
public List<PqScriptDtlsParam.CheckData> scriptDtlsCheckDataList(PqScriptDtlsParam sourceIssue) { public List<PqScriptDtlsParam.CheckData> scriptDtlsCheckDataList(PqScriptDtlsParam sourceIssue) {
Boolean valueType = pqScriptMapper.selectScriptIsValueType(sourceIssue.getScriptId()); // Boolean valueType = pqScriptMapper.selectScriptIsValueType(sourceIssue.getScriptId());
List<PqScriptDtlsParam.CheckData> info = new ArrayList<>(); List<PqScriptDtlsParam.CheckData> info = new ArrayList<>();
//获取所有下拉值情况 //获取所有下拉值情况
@@ -627,9 +629,9 @@ public class PqScriptDtlsServiceImpl extends ServiceImpl<PqScriptDtlsMapper, PqS
checkData.setErrorFlag(channelListDTO.getErrorFlag()); checkData.setErrorFlag(channelListDTO.getErrorFlag());
checkData.setEnable(channelListDTO.getEnable()); checkData.setEnable(channelListDTO.getEnable());
//电压*电流*cos电压角度-电流角度) //电压*电流*cos电压角度-电流角度)
checkData.setValue(channelI.get(0).getFAmp() * listDTO.getFAmp() / 10000 * Math.cos((listDTO.getFPhase() - channelI.get(0).getFPhase()) * Math.PI / 180)); checkData.setValue(channelI.get(0).getFAmp() * listDTO.getFAmp() / 100 * Math.cos((listDTO.getFPhase() - channelI.get(0).getFPhase()) * Math.PI / 180));
// if (valueType) { // if (valueType) {
checkData.setValue(checkData.getValue() * 57.74 * 5); // checkData.setValue(checkData.getValue() * 57.74 * 5);
// } // }
setCheck(info, checkData, channelListDTO, checkArchive, listDTO); setCheck(info, checkData, channelListDTO, checkArchive, listDTO);
} }
@@ -650,9 +652,9 @@ public class PqScriptDtlsServiceImpl extends ServiceImpl<PqScriptDtlsMapper, PqS
checkData.setErrorFlag(channelListDTO.getErrorFlag()); checkData.setErrorFlag(channelListDTO.getErrorFlag());
checkData.setEnable(channelListDTO.getEnable()); checkData.setEnable(channelListDTO.getEnable());
//电压*电流*cos电压角度-电流角度) //电压*电流*cos电压角度-电流角度)
checkData.setValue(channelI.get(0).getFAmp() * listDTO.getFAmp() / 10000 * Math.sin((listDTO.getFPhase() - channelI.get(0).getFPhase()) * Math.PI / 180)); checkData.setValue(channelI.get(0).getFAmp() * listDTO.getFAmp() / 100 * Math.sin((listDTO.getFPhase() - channelI.get(0).getFPhase()) * Math.PI / 180));
// if (valueType) { // if (valueType) {
checkData.setValue(checkData.getValue() * 57.74 * 5); // checkData.setValue(checkData.getValue() * 57.74 * 5);
// } // }
setCheck(info, checkData, channelListDTO, checkArchive, listDTO); setCheck(info, checkData, channelListDTO, checkArchive, listDTO);
} }
@@ -673,9 +675,9 @@ public class PqScriptDtlsServiceImpl extends ServiceImpl<PqScriptDtlsMapper, PqS
checkData.setErrorFlag(channelListDTO.getErrorFlag()); checkData.setErrorFlag(channelListDTO.getErrorFlag());
checkData.setEnable(channelListDTO.getEnable()); checkData.setEnable(channelListDTO.getEnable());
//电压*电流*cos电压角度-电流角度) //电压*电流*cos电压角度-电流角度)
checkData.setValue(channelI.get(0).getFAmp() * listDTO.getFAmp() / 10000); checkData.setValue(channelI.get(0).getFAmp() * listDTO.getFAmp() / 100);
// if (valueType) { // if (valueType) {
checkData.setValue(checkData.getValue() * 57.74 * 5); // checkData.setValue(checkData.getValue() * 57.74 * 5);
// } // }
setCheck(info, checkData, channelListDTO, checkArchive, listDTO); setCheck(info, checkData, channelListDTO, checkArchive, listDTO);
} }
@@ -778,7 +780,7 @@ public class PqScriptDtlsServiceImpl extends ServiceImpl<PqScriptDtlsMapper, PqS
@Override @Override
public Set<String> getScriptToIcdCheckInfo(PreDetectionParam param) { public Set<String> getScriptToIcdCheckInfo(PreDetectionParam param) {
PqScriptIssueParam issueParam = new PqScriptIssueParam(); PqScriptIssueParam issueParam = new PqScriptIssueParam();
issueParam.setSourceId(param.getSourceId()); issueParam.setSourceId(param.getSourceName());
issueParam.setDevIds(param.getDevIds()); issueParam.setDevIds(param.getDevIds());
issueParam.setScriptId(param.getScriptId()); issueParam.setScriptId(param.getScriptId());
issueParam.setIsPhaseSequence(CommonEnum.FORMAL_TEST.getValue()); issueParam.setIsPhaseSequence(CommonEnum.FORMAL_TEST.getValue());
@@ -959,6 +961,22 @@ public class PqScriptDtlsServiceImpl extends ServiceImpl<PqScriptDtlsMapper, PqS
queryWrapper.eq(PqScriptDtls::getScriptIndex, -1) queryWrapper.eq(PqScriptDtls::getScriptIndex, -1)
.eq(PqScriptDtls::getEnable, 1); .eq(PqScriptDtls::getEnable, 1);
pqScriptDtls = this.list(queryWrapper); pqScriptDtls = this.list(queryWrapper);
// 相序校验中电流需加量需要依据企标10650.2中章节5.5.3的描述过载能力2 倍额定电流连续10 倍额定电流持续 1 s。
// 考虑到有可能存在1A的额定电流本处做特殊处理加量分别为额定电流的0.2/0.4/0.6的标幺乘积加量
// 电压暂不做处理原因1、电压的企标描述过载能力为4倍空间较大2、额定电压比如57.74V为浮点数,存在不确定小数位,避免引起算术误差;
// 1. 获取额定电流,前端已做限制,相同额定电流才能一起检测
String deviceId = param.getDevIds().get(0);
PqDevVO pqDev = pqDevService.getPqDevById(deviceId);
String devTypeId = pqDev.getDevType();
DevType devType = devTypeService.getById(devTypeId);
Double devCurr = devType.getDevCurr();
for (int i = 0; i < pqScriptDtls.size(); i++) {
PqScriptDtls scriptDtls = pqScriptDtls.get(i);
// 注意此处scriptDtls.getValue() < 1.0,考虑到有些已经投入运行的地方,可能没有改库,避免不必要的异常
if (scriptDtls.getValueType().equalsIgnoreCase("CUR") && scriptDtls.getValue() < 1.0) {
scriptDtls.setValue(devCurr * scriptDtls.getValue());
}
}
} else if (param.getIsPhaseSequence().equals(CommonEnum.COEFFICIENT_TEST.getValue())) { } else if (param.getIsPhaseSequence().equals(CommonEnum.COEFFICIENT_TEST.getValue())) {
//系数 //系数
queryWrapper.in(PqScriptDtls::getScriptIndex, param.getIndexList()) queryWrapper.in(PqScriptDtls::getScriptIndex, param.getIndexList())
@@ -1037,18 +1055,25 @@ public class PqScriptDtlsServiceImpl extends ServiceImpl<PqScriptDtlsMapper, PqS
dipDataDTO.setFTransValue(0.0); dipDataDTO.setFTransValue(0.0);
dipDataDTO.setFRetainTime(0.0); dipDataDTO.setFRetainTime(0.0);
dipDataDTO.setFPreTime(fPreTime); // dipDataDTO.setFPreTime(fPreTime);
dipDataDTO.setFRampIn(fRampIn); dipDataDTO.setFRampIn(fRampIn);
dipDataDTO.setFRampOut(fRampOut); dipDataDTO.setFRampOut(fRampOut);
dipDataDTO.setFAfterTime(fAfterTime); // dipDataDTO.setFAfterTime(fAfterTime);
channelListDTO.setDipData(dipDataDTO); channelListDTO.setDipData(dipDataDTO);
//闪变数据 //闪变数据
SourceIssue.ChannelListDTO.FlickerDataDTO flickerDataDTO = new SourceIssue.ChannelListDTO.FlickerDataDTO(); SourceIssue.ChannelListDTO.FlickerDataDTO flickerDataDTO = new SourceIssue.ChannelListDTO.FlickerDataDTO();
flickerDataDTO.setWaveFluType(waveFluType); SourceIssue.ChannelListDTO.FlickerDataDTO flickerData = channelListDTO.getFlickerData();
flickerDataDTO.setWaveType(waveType); if (ObjectUtil.isNotNull(flickerData)) {
flickerDataDTO.setFDutyCycle(fDutyCycle); flickerDataDTO.setWaveFluType(flickerData.getWaveFluType());
flickerDataDTO.setWaveType(flickerData.getWaveType());
flickerDataDTO.setFDutyCycle(flickerData.getFDutyCycle());
} else {
flickerDataDTO.setWaveFluType(waveFluType);
flickerDataDTO.setWaveType(waveType);
flickerDataDTO.setFDutyCycle(fDutyCycle);
}
flickerDataDTO.setFChagFre(0.0); flickerDataDTO.setFChagFre(0.0);
flickerDataDTO.setFChagValue(0.0); flickerDataDTO.setFChagValue(0.0);
@@ -1087,6 +1112,8 @@ public class PqScriptDtlsServiceImpl extends ServiceImpl<PqScriptDtlsMapper, PqS
if (CollUtil.isNotEmpty(dipList)) { if (CollUtil.isNotEmpty(dipList)) {
PqScriptDtls dip = dipList.get(0); PqScriptDtls dip = dipList.get(0);
dipDataDTO.setFTransValue(dip.getTransValue()); dipDataDTO.setFTransValue(dip.getTransValue());
dipDataDTO.setFPreTime(dip.getFPreTime());
dipDataDTO.setFAfterTime(dip.getFAfterTime());
if (devFly) { if (devFly) {
// if (isValueType) { // if (isValueType) {
dipDataDTO.setFTransValue(dip.getTransValue()); dipDataDTO.setFTransValue(dip.getTransValue());

View File

@@ -112,15 +112,15 @@ public class PqScriptServiceImpl extends ServiceImpl<PqScriptMapper, PqScript> i
} }
@Override @Override
public List<Map<String, Object>> listAllPqScript(String patternId) { public List<PqScript> listAllPqScript(String patternId) {
List<PqScript> pqScriptList = this.lambdaQuery().eq(StrUtil.isNotBlank(patternId), PqScript::getPattern, patternId).eq(PqScript::getState, DataStateEnum.ENABLE.getCode()).list(); List<PqScript> pqScriptList = this.lambdaQuery().eq(StrUtil.isNotBlank(patternId), PqScript::getPattern, patternId).eq(PqScript::getState, DataStateEnum.ENABLE.getCode()).list();
List<Map<String, Object>> result = pqScriptList.stream().map(pqScript -> { // List<Map<String, Object>> result = pqScriptList.stream().map(pqScript -> {
Map<String, Object> map = new HashMap<>(); // Map<String, Object> map = new HashMap<>();
map.put("id", pqScript.getId()); // map.put("id", pqScript.getId());
map.put("name", pqScript.getName()); // map.put("name", pqScript.getName());
return map; // return map;
}).collect(Collectors.toList()); // }).collect(Collectors.toList());
return result; return pqScriptList;
} }
@Override @Override
@@ -139,7 +139,7 @@ public class PqScriptServiceImpl extends ServiceImpl<PqScriptMapper, PqScript> i
wrapper.eq("state", DataStateEnum.ENABLE.getCode()); wrapper.eq("state", DataStateEnum.ENABLE.getCode());
wrapper.eq("name", param.getName()); wrapper.eq("name", param.getName());
if (isExcludeSelf) { if (isExcludeSelf) {
if(param instanceof PqScriptParam.UpdateParam){ if (param instanceof PqScriptParam.UpdateParam) {
wrapper.ne("id", ((PqScriptParam.UpdateParam) param).getId()); wrapper.ne("id", ((PqScriptParam.UpdateParam) param).getId());
} }
} }

View File

@@ -0,0 +1,33 @@
package com.njcn.gather.plan.pojo.vo;
import org.junit.Assert;
import org.junit.Test;
import java.util.Collections;
public class PlanStatisticsVOTest {
@Test
public void shouldExposeQualifiedDeviceCount() {
PlanStatisticsVO statistics = new PlanStatisticsVO();
statistics.setQualifiedDeviceCount(6);
Assert.assertEquals(Integer.valueOf(6), statistics.getQualifiedDeviceCount());
}
@Test
public void shouldExposeLinkedFilterOptions() {
PlanStatisticsVO statistics = new PlanStatisticsVO();
PlanStatisticsOptionVO manufacturer = new PlanStatisticsOptionVO("manufacturer-1", "厂家A");
PlanStatisticsOptionVO devType = new PlanStatisticsOptionVO("dev-type-1", "PQS-882A");
statistics.setManufacturerOptions(Collections.singletonList(manufacturer));
statistics.setDevTypeOptions(Collections.singletonList(devType));
Assert.assertEquals("manufacturer-1", statistics.getManufacturerOptions().get(0).getId());
Assert.assertEquals("厂家A", statistics.getManufacturerOptions().get(0).getName());
Assert.assertEquals("dev-type-1", statistics.getDevTypeOptions().get(0).getId());
Assert.assertEquals("PQS-882A", statistics.getDevTypeOptions().get(0).getName());
}
}

View File

@@ -1,15 +1,15 @@
server: server:
port: 18092 port: 18093
spring: spring:
application: application:
name: entrance name: entrance
datasource: datasource:
druid: druid:
driver-class-name: com.mysql.cj.jdbc.Driver driver-class-name: com.mysql.cj.jdbc.Driver
# url: jdbc:mysql://192.168.1.24:13306/pqs91002?useUnicode=true&characterEncoding=utf-8&useSSL=true&serverTimezone=Asia/Shanghai&rewriteBatchedStatements=true url: jdbc:mysql://192.168.1.24:13306/pqs9100?useUnicode=true&characterEncoding=utf-8&useSSL=true&serverTimezone=Asia/Shanghai&rewriteBatchedStatements=true
# username: root # username: root
# password: njcnpqs # password: njcnpqs
url: jdbc:mysql://localhost:13306/pqs9100w?useUnicode=true&characterEncoding=utf-8&useSSL=true&serverTimezone=Asia/Shanghai&rewriteBatchedStatements=true # url: jdbc:mysql://127.0.0.1:3306/pqs9100?useUnicode=true&characterEncoding=utf-8&useSSL=true&serverTimezone=Asia/Shanghai&rewriteBatchedStatements=true
username: root username: root
password: njcnpqs password: njcnpqs
#初始化建立物理连接的个数、最小、最大连接数 #初始化建立物理连接的个数、最小、最大连接数
@@ -36,9 +36,9 @@ mybatis-plus:
#驼峰命名 #驼峰命名
map-underscore-to-camel-case: true map-underscore-to-camel-case: true
#配置sql日志输出 #配置sql日志输出
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl # log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
#关闭日志输出 #关闭日志输出
# log-impl: org.apache.ibatis.logging.nologging.NoLoggingImpl log-impl: org.apache.ibatis.logging.nologging.NoLoggingImpl
global-config: global-config:
db-config: db-config:
#指定主键生成策略 #指定主键生成策略
@@ -64,29 +64,32 @@ webSocket:
#源参数下发,暂态数据默认值 #源参数下发,暂态数据默认值
Dip: Dip:
#暂态前时间s # 暂态前时间s
fPreTime: 2f # fPreTime: 2f
#写入时间s #写入时间s
fRampIn: 0.001f fRampIn: 0.001f
#写出时间s #写出时间s
fRampOut: 0.001f fRampOut: 0.001f
#暂态后时间s # 暂态后时间s
fAfterTime: 3f # fAfterTime: 3f
Flicker: #Flicker:
waveFluType: CPM # waveFluType: CPM
waveType: SQU # waveType: SQU
fDutyCycle: 50f # fDutyCycle: 50f
log: #log:
homeDir: D:\logs # homeDir: D:\logs
commonLevel: info # commonLevel: info
report: report:
template: D:\template # template: D:\template
reportDir: D:\report # reportDir: D:\report
data: dateFormat: yyyy年MM月dd日
homeDir: D:\data #data:
# homeDir: D:\data
#resource:
# videoDir: ${data.homeDir}\resources\videos
qr: qr:
cloud: http://pqmcc.com:18082/api/file cloud: http://pqmcc.com:18082/api/file
dev: dev:

View File

@@ -5,7 +5,7 @@
<!-- 直接使用固定配置避免Spring配置解析时机问题 --> <!-- 直接使用固定配置避免Spring配置解析时机问题 -->
<property name="log.projectName" value="entrance"/> <property name="log.projectName" value="entrance"/>
<property name="logCommonLevel" value="info"/> <property name="logCommonLevel" value="info"/>
<property name="logHomeDir" value="D:\logs"/> <property name="logHomeDir" value="${logHomeDir:-D:\logs}"/>
<conversionRule conversionWord="clr" converterClass="org.springframework.boot.logging.logback.ColorConverter" /> <conversionRule conversionWord="clr" converterClass="org.springframework.boot.logging.logback.ColorConverter" />
<conversionRule conversionWord="wex" <conversionRule conversionWord="wex"

View File

@@ -25,10 +25,10 @@ public class AnalysisServiceStreamTest {
private ICompareWaveService compareWaveServiceImpl; private ICompareWaveService compareWaveServiceImpl;
// 测试文件路径 - 请根据实际情况修改 // 测试文件路径 - 请根据实际情况修改
private static final String SOURCE_CFG_PATH = "C:\\Users\\Administrator\\Desktop\\wavedata\\192.168.1.200\\PQ_PQLD1_000020_20251017_140358_193.cfg"; private static final String SOURCE_CFG_PATH = "C:\\Users\\Administrator\\Desktop\\wave\\192.168.1.241\\PQ_PQLD2_000177_20251028_112422_833.cfg";
private static final String SOURCE_DAT_PATH = "C:\\Users\\Administrator\\Desktop\\wavedata\\192.168.1.200\\PQ_PQLD1_000020_20251017_140358_193.dat"; private static final String SOURCE_DAT_PATH = "C:\\Users\\Administrator\\Desktop\\wave\\192.168.1.241\\PQ_PQLD2_000177_20251028_112422_833.dat";
private static final String TARGET_CFG_PATH = "C:\\Users\\Administrator\\Desktop\\wavedata\\192.168.1.168\\PQ_PQLD1_000018_20251017_140357_625.cfg"; private static final String TARGET_CFG_PATH = "C:\\Users\\Administrator\\Desktop\\wave\\192.168.1.242\\PQ_PQLD2_000238_20251028_112422_518.cfg";
private static final String TARGET_DAT_PATH = "C:\\Users\\Administrator\\Desktop\\wavedata\\192.168.1.168\\PQ_PQLD1_000018_20251017_140357_625.dat"; private static final String TARGET_DAT_PATH = "C:\\Users\\Administrator\\Desktop\\wave\\192.168.1.242\\PQ_PQLD2_000238_20251028_112422_518.dat";
// private static final String SOURCE_CFG_PATH = "F:\\hatch\\wavecompare\\数据比对\\统计数据1\\B码\\217\\PQMonitor_PQM1_000006_20200430_115517_889.cfg"; // private static final String SOURCE_CFG_PATH = "F:\\hatch\\wavecompare\\数据比对\\统计数据1\\B码\\217\\PQMonitor_PQM1_000006_20200430_115517_889.cfg";

1
license.key Normal file
View File

@@ -0,0 +1 @@
AoNUHvLQag9nPPxWDsf5EwwBqifh5wnoFjrU01w+kIA7TPdRl0AQDBSA3IU7AY28Liubt6Rl8CsDtxEDrz8L5m0FqQrmZ1TmIJtZWbBR16NxXRgf8izM5JurYEY6ZbjU021yCu0fitxB0DJZ8LB8zfUDsV1MFGHl+yPjh4ZQrYDffID4rk/mRe/EE6F7bS19upStSOnQxVQVJSXwCVVHgsuFXqiuagM21OmxpYNjqaPnvAKoHRXTTxXn9BrSgZBocxuHB/IE+a0a+Q2eQo4RZa2IQpneEA/QIKEqezqsABxmM33duQ4eKt17hAttISV1J0R1cKpwZ4tYuSoHCuMONA==

View File

@@ -325,7 +325,7 @@ public class DetectionDataServiceImpl extends ReplenishMybatisServiceImpl<Detect
resultFlags = resultFlags.stream().filter(x -> 4 != x && 5 != x).distinct().collect(Collectors.toList()); resultFlags = resultFlags.stream().filter(x -> 4 != x && 5 != x).distinct().collect(Collectors.toList());
if (CollUtil.isNotEmpty(resultFlags)) { if (CollUtil.isNotEmpty(resultFlags)) {
if (resultFlags.contains(2)) { if (resultFlags.contains(2)) {
return 2; return 0;
} else { } else {
switch (resultFlags.get(0)) { switch (resultFlags.get(0)) {
case 1: case 1:

View File

@@ -28,6 +28,9 @@ public class SysTestConfigParam {
@ApiModelProperty(value = "场景") @ApiModelProperty(value = "场景")
private String scene; private String scene;
@ApiModelProperty(value = "比对监测后,当电压、电流不符合时,是否对标准设备进行系数校准")
private Integer coefficient;
@Data @Data
public static class UpdateParam extends SysTestConfigParam { public static class UpdateParam extends SysTestConfigParam {
@ApiModelProperty("id") @ApiModelProperty("id")

View File

@@ -51,6 +51,11 @@ public class SysTestConfig extends BaseEntity implements Serializable {
*/ */
private Integer scale; private Integer scale;
/**
* 比对监测后,当电压、电流不符合时,是否对标准设备进行系数校准
*/
private Integer coefficient;
/** /**
* 状态0-删除 1-正常 * 状态0-删除 1-正常

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