Compare commits
143 Commits
1abba4a528
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
82fdd7664b | ||
|
|
547d40ce99 | ||
|
|
49599582ba | ||
|
|
31a956a1fc | ||
|
|
55fe1fe05f | ||
| 366d1fadfa | |||
|
|
b35bbf11f7 | ||
| e2c7e745c8 | |||
|
|
29ddc8c2de | ||
|
|
212f1295eb | ||
|
|
7366e7815f | ||
|
|
a4858a818e | ||
|
|
de83f98845 | ||
|
|
061b65be1b | ||
|
|
694a99a96f | ||
| befe5abe0c | |||
| 46ec9923a7 | |||
|
|
d2388576a9 | ||
|
|
7f21049d0f | ||
|
|
49ca27d994 | ||
| 3cb4a46a16 | |||
|
|
13677f21d9 | ||
|
|
a1941a375b | ||
|
|
9dc8ecd873 | ||
|
|
7c6c103f17 | ||
|
|
b113788e54 | ||
|
|
599edde008 | ||
|
|
cc0b685c66 | ||
|
|
29b0a4f966 | ||
|
|
c651b18e72 | ||
|
|
6fd180b4d4 | ||
|
|
282f9cf4eb | ||
|
|
1cfea7fd6c | ||
|
|
251e302e59 | ||
|
|
873e920add | ||
|
|
fd7c6ada6b | ||
|
|
c148bddfc9 | ||
|
|
f0857b7c46 | ||
| 9b1c6f61e6 | |||
|
|
3f72c52cdc | ||
|
|
ef757c52ea | ||
|
|
4110a835c8 | ||
|
|
e78ce544e3 | ||
|
|
c10d54e79a | ||
|
|
2796558040 | ||
|
|
920a808729 | ||
|
|
8e24ac4b71 | ||
|
|
3eb2736edb | ||
|
|
8c3eba9224 | ||
|
|
6288aa565e | ||
|
|
0fa7ec91c4 | ||
|
|
fdb4b7060a | ||
| 3f47b0f008 | |||
|
|
cb431b5af1 | ||
|
|
153428b24f | ||
|
|
d92544f7c4 | ||
|
|
3f1ae1886a | ||
|
|
af4863af65 | ||
|
|
4b7c1259a7 | ||
|
|
de1496389e | ||
| 79003cd0f4 | |||
|
|
c3443fcc91 | ||
|
|
5105e77823 | ||
|
|
eb068b76a4 | ||
| 9f11f7ec11 | |||
| 2012221b73 | |||
|
|
9ab5d42439 | ||
| 7abcaefeb1 | |||
|
|
f4df52dd1c | ||
| db115bb27d | |||
|
|
68d96e67aa | ||
| 3f94012faa | |||
| 41c557118c | |||
| 6596a572d6 | |||
| 139c7b0651 | |||
|
|
ab236cd34f | ||
|
|
786bd5d660 | ||
|
|
21d2c2b7a7 | ||
|
|
48fa4c2390 | ||
|
|
033330b005 | ||
|
|
f81123c3f7 | ||
|
|
5539cb2887 | ||
|
|
1df9c8d703 | ||
|
|
1cbed2a620 | ||
| 89667367ea | |||
| 92b95dd86d | |||
|
|
6b7e38fef6 | ||
|
|
f10debe2f2 | ||
|
|
9d15351fba | ||
|
|
2339a006ec | ||
|
|
7fd904ab79 | ||
|
|
61f149b562 | ||
|
|
57ee3a4d43 | ||
| 563eb80b65 | |||
|
|
dae10378dd | ||
|
|
40cb153656 | ||
|
|
af4f000b13 | ||
|
|
f922ee97aa | ||
|
|
321ec97130 | ||
|
|
0dd3502942 | ||
|
|
26c5e933f5 | ||
|
|
00ba09faae | ||
|
|
40e39d651b | ||
|
|
02c8164b7e | ||
|
|
8c598aec1e | ||
|
|
2c59defdc2 | ||
|
|
5642bf2b31 | ||
|
|
ba76df66b0 | ||
|
|
57c419eb70 | ||
|
|
98f4ecef6c | ||
|
|
20e07712cb | ||
|
|
ac1d98efdc | ||
|
|
5d161acfad | ||
|
|
1534327f6f | ||
|
|
04ada8740a | ||
|
|
98cca582f6 | ||
|
|
a2de4b80a7 | ||
|
|
c7d8fc3168 | ||
|
|
071c6e3d64 | ||
| b4878d4a25 | |||
|
|
bb22857fc9 | ||
|
|
b0a4458c56 | ||
| 6357cde72b | |||
| dddffe43cb | |||
|
|
51fdf6bf59 | ||
|
|
b53ef274cf | ||
|
|
90d618b66f | ||
| e81413eaa9 | |||
| 33cefdd0b1 | |||
| 80a886a5eb | |||
| 0a85b433ba | |||
|
|
66786200bd | ||
| 15e93b6734 | |||
|
|
6843497908 | ||
|
|
cd486f419f | ||
|
|
7394762e28 | ||
|
|
2f75fe062b | ||
|
|
d4e09a09cf | ||
|
|
d58452012d | ||
|
|
014ac7931e | ||
| 3d4fb44b3a | |||
|
|
6ef908ff60 | ||
|
|
7461801657 |
5
.gitignore
vendored
5
.gitignore
vendored
@@ -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
@@ -139,7 +139,18 @@
|
|||||||
<artifactId>report-generator</artifactId>
|
<artifactId>report-generator</artifactId>
|
||||||
<version>1.0.0</version>
|
<version>1.0.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<!--激活工具-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.njcn.gather</groupId>
|
||||||
|
<artifactId>activate-tool</artifactId>
|
||||||
|
<version>1.0.0</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-test</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
|||||||
@@ -0,0 +1,54 @@
|
|||||||
|
package com.njcn.gather.detection.controller;
|
||||||
|
|
||||||
|
import com.njcn.common.pojo.annotation.OperateInfo;
|
||||||
|
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
|
||||||
|
import com.njcn.common.pojo.response.HttpResult;
|
||||||
|
import com.njcn.gather.detection.lock.DetectionLock;
|
||||||
|
import com.njcn.gather.detection.lock.DetectionLockManager;
|
||||||
|
import com.njcn.gather.detection.pojo.vo.DetectionLockHolderVO;
|
||||||
|
import com.njcn.web.controller.BaseController;
|
||||||
|
import com.njcn.web.utils.HttpResultUtil;
|
||||||
|
import com.njcn.web.utils.RequestUtil;
|
||||||
|
import io.swagger.annotations.Api;
|
||||||
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检测互斥锁管理接口。
|
||||||
|
* - GET /detection/lock/current 查询当前持锁状态;空闲返回 data=null
|
||||||
|
* - POST /detection/lock/forceRelease 管理员强制释放
|
||||||
|
*
|
||||||
|
* 鉴权:默认由 AuthGlobalFilter 做 JWT 校验,登录用户均可访问;
|
||||||
|
* 强释操作通过 @OperateInfo 落审计日志,谁操作谁担责。
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@Api(tags = "检测互斥锁")
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/detection/lock")
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class LockController extends BaseController {
|
||||||
|
|
||||||
|
@GetMapping("/current")
|
||||||
|
@ApiOperation("查询当前持锁状态;空闲返回 data=null")
|
||||||
|
public HttpResult<DetectionLockHolderVO> current() {
|
||||||
|
String methodDescribe = getMethodDescribe("current");
|
||||||
|
DetectionLock cur = DetectionLockManager.getInstance().getCurrent();
|
||||||
|
DetectionLockHolderVO data = cur == null ? null : DetectionLockManager.toHolderVO(cur);
|
||||||
|
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, data, methodDescribe);
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/forceRelease")
|
||||||
|
@OperateInfo
|
||||||
|
@ApiOperation("管理员强制释放检测锁")
|
||||||
|
public HttpResult<?> forceRelease() {
|
||||||
|
String methodDescribe = getMethodDescribe("forceRelease");
|
||||||
|
String operator = RequestUtil.getUserId();
|
||||||
|
DetectionLockManager.getInstance().forceRelease(operator, "ADMIN_FORCE");
|
||||||
|
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,44 @@
|
|||||||
|
package com.njcn.gather.detection.controller;
|
||||||
|
|
||||||
|
import com.njcn.common.pojo.annotation.OperateInfo;
|
||||||
|
import com.njcn.common.pojo.enums.common.LogEnum;
|
||||||
|
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
|
||||||
|
import com.njcn.common.pojo.response.HttpResult;
|
||||||
|
import com.njcn.gather.detection.sntp.SntpServerManager;
|
||||||
|
import com.njcn.web.controller.BaseController;
|
||||||
|
import com.njcn.web.utils.HttpResultUtil;
|
||||||
|
import io.swagger.annotations.Api;
|
||||||
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@Api(tags = "SNTP对时")
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/sntp")
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class SntpController extends BaseController {
|
||||||
|
|
||||||
|
private final SntpServerManager sntpServerManager;
|
||||||
|
|
||||||
|
@OperateInfo(info = LogEnum.SYSTEM_COMMON)
|
||||||
|
@PostMapping("/start")
|
||||||
|
@ApiOperation("启动SNTP对时服务")
|
||||||
|
public HttpResult<?> start() {
|
||||||
|
String methodDescribe = getMethodDescribe("start");
|
||||||
|
sntpServerManager.start();
|
||||||
|
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
|
||||||
|
}
|
||||||
|
|
||||||
|
@OperateInfo(info = LogEnum.SYSTEM_COMMON)
|
||||||
|
@PostMapping("/stop")
|
||||||
|
@ApiOperation("停止SNTP对时服务")
|
||||||
|
public HttpResult<?> stop() {
|
||||||
|
String methodDescribe = getMethodDescribe("stop");
|
||||||
|
sntpServerManager.stop();
|
||||||
|
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
|
||||||
|
}
|
||||||
|
}
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -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,8 @@ 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.pojo.po.PqSource;
|
||||||
|
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 +79,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 +395,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 +444,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 +618,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 +693,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 +899,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 +959,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 +1167,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 +1217,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 +1379,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 +1793,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);
|
||||||
@@ -1791,6 +1803,83 @@ public class SocketDevResponseService {
|
|||||||
if (param.getTestItemList().get(1)) {
|
if (param.getTestItemList().get(1)) {
|
||||||
initXiManager(param);
|
initXiManager(param);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FormalTestManager.overload = getOverloadResult(param);
|
||||||
|
FormalTestManager.checkStartTime = LocalDateTime.now();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取过载测试结果
|
||||||
|
*
|
||||||
|
* @return 如果检测到电压过载,overload=1;如果检测到电流过载,overload=2;如果检测到电压&&电流过载,overload=3;反之,overload=4
|
||||||
|
*/
|
||||||
|
private int getOverloadResult(PreDetectionParam param) {
|
||||||
|
PqSource pqSource = pqSourceService.getPqSourceById(param.getSourceId());
|
||||||
|
BigDecimal maxVoltage = pqSource.getMaxVoltage();
|
||||||
|
BigDecimal maxCurrent = pqSource.getMaxCurrent();
|
||||||
|
|
||||||
|
PqScriptIssueParam issueParam = new PqScriptIssueParam();
|
||||||
|
issueParam.setSourceId(pqSource.getName());
|
||||||
|
issueParam.setPlanId(param.getPlanId());
|
||||||
|
issueParam.setDevIds(param.getDevIds());
|
||||||
|
issueParam.setScriptId(param.getScriptId());
|
||||||
|
issueParam.setIsPhaseSequence(CommonEnum.FORMAL_TEST.getValue());
|
||||||
|
List<SourceIssue> sourceIssues = pqScriptDtlsService.listSourceIssue(issueParam);
|
||||||
|
|
||||||
|
for (int i = 0; i < sourceIssues.size(); i++) {
|
||||||
|
SourceIssue sourceIssue = sourceIssues.get(i);
|
||||||
|
List<SourceIssue.ChannelListDTO> channelList = sourceIssue.getChannelList();
|
||||||
|
for (int j = 0; j < channelList.size(); j++) {
|
||||||
|
SourceIssue.ChannelListDTO channelListDTO = channelList.get(j);
|
||||||
|
Double fAmp = channelListDTO.getFAmp();
|
||||||
|
String channelType = channelListDTO.getChannelType();
|
||||||
|
|
||||||
|
if (ObjectUtil.isNotNull(fAmp)) {
|
||||||
|
if (channelType.contains("U")) {
|
||||||
|
// 电压判断
|
||||||
|
if (maxVoltage.compareTo(BigDecimal.valueOf(fAmp)) < 0) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// 电流判断
|
||||||
|
if (maxCurrent.compareTo(BigDecimal.valueOf(fAmp)) < 0) {
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 暂态判断
|
||||||
|
if (channelListDTO.getDipFlag()) {
|
||||||
|
SourceIssue.ChannelListDTO.DipDataDTO dipData = channelListDTO.getDipData();
|
||||||
|
if (ObjectUtil.isNotNull(dipData)) {
|
||||||
|
Double fTransValue = dipData.getFTransValue();
|
||||||
|
if (ObjectUtil.isNotNull(fTransValue) && ObjectUtil.isNotNull(fAmp)) {
|
||||||
|
if (maxVoltage.compareTo(BigDecimal.valueOf(fTransValue / 100).max(BigDecimal.valueOf(fAmp))) < 0) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 谐波判断
|
||||||
|
if (channelListDTO.getHarmFlag()) {
|
||||||
|
List<SourceIssue.ChannelListDTO.HarmModel> harmList = channelListDTO.getHarmList();
|
||||||
|
double sum = harmList.stream().map(harmModel -> harmModel.getFAmp() * harmModel.getFAmp() / 10000).mapToDouble(x -> x).sum();
|
||||||
|
if (maxVoltage.compareTo(BigDecimal.valueOf(Math.sqrt(1 + sum) * fAmp)) < 0) {
|
||||||
|
return channelType.contains("U") ? 1 : 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 间谐波判断
|
||||||
|
if (channelListDTO.getInHarmFlag()) {
|
||||||
|
List<SourceIssue.ChannelListDTO.InharmModel> inharmList = channelListDTO.getInharmList();
|
||||||
|
double sum = inharmList.stream().map(harmModel -> harmModel.getFAmp() * harmModel.getFAmp() / 10000).mapToDouble(x -> x).sum();
|
||||||
|
if (maxVoltage.compareTo(BigDecimal.valueOf(Math.sqrt(1 + sum) * fAmp)) < 0) {
|
||||||
|
return channelType.contains("U") ? 1 : 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
//初始化系数校验参数
|
//初始化系数校验参数
|
||||||
@@ -1812,8 +1901,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());
|
||||||
|
|||||||
@@ -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,41 @@ 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 {
|
||||||
|
// 推送过载测试结果
|
||||||
|
SocketDataMsg overloadSocketDataMsg = new SocketDataMsg();
|
||||||
|
overloadSocketDataMsg.setRequestId("overloadTest");
|
||||||
|
overloadSocketDataMsg.setCode(FormalTestManager.overload);
|
||||||
|
sendWebSocketMessage(param.getUserPageId(), overloadSocketDataMsg);
|
||||||
|
if (FormalTestManager.overload != 4) {
|
||||||
|
CnSocketUtil.quitSendSource(param);
|
||||||
|
} 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 +601,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 +636,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 +702,8 @@ public class SocketSourceResponseService {
|
|||||||
|
|
||||||
// 同步更新系数管理器中的设备列表
|
// 同步更新系数管理器中的设备列表
|
||||||
XiNumberManager.xiDevList = devList;
|
XiNumberManager.xiDevList = devList;
|
||||||
|
FormalTestManager.unknownError = false;
|
||||||
|
FormalTestManager.currentIssue = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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; }
|
||||||
|
}
|
||||||
@@ -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()(那样会让调用方误以为持锁)。
|
||||||
|
// 返回 busy,data 可能为 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; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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;
|
||||||
|
|||||||
@@ -67,6 +67,8 @@ public enum SourceOperateCodeEnum {
|
|||||||
SERVER_ERROR("server_error","服务端主动关闭连接,请稍后再试"),
|
SERVER_ERROR("server_error","服务端主动关闭连接,请稍后再试"),
|
||||||
DEVICE_ERROR("device_error","设备主动关闭连接,请稍后再试"),
|
DEVICE_ERROR("device_error","设备主动关闭连接,请稍后再试"),
|
||||||
|
|
||||||
|
FLICKER_DATA_CHECK("flicker_data_check","闪变数据校验"),
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -42,8 +42,9 @@ public enum SourceResponseCodeEnum {
|
|||||||
FAIL(25002,"失败"),
|
FAIL(25002,"失败"),
|
||||||
ALL_FAIL(25003,"校验失败"),
|
ALL_FAIL(25003,"校验失败"),
|
||||||
RECEIVE_DATA_TIME_OUT(25004,"接收数据超时"),
|
RECEIVE_DATA_TIME_OUT(25004,"接收数据超时"),
|
||||||
REAL_DATA_CHECK_FAIL(25005,"实时数据校验失败"),
|
REAL_DATA_CHECK_FAIL(25005,"实时数据不符合"),
|
||||||
STATISTICS_DATA_CHECK_FAIL(25006,"统计数据校验失败")
|
STATISTICS_DATA_CHECK_FAIL(25006,"统计数据不符合"),
|
||||||
|
FLICKER_DATA_START(25007,"开始接收闪变数据")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -43,4 +43,9 @@ public class ContrastDetectionParam {
|
|||||||
private List<Boolean> testItemList;
|
private List<Boolean> testItemList;
|
||||||
|
|
||||||
private String userId;
|
private String userId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否进行相许校验
|
||||||
|
*/
|
||||||
|
private Integer phaseCheck;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,6 +46,11 @@ public class PreDetectionParam {
|
|||||||
*/
|
*/
|
||||||
private String sourceId;
|
private String sourceId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 源名称
|
||||||
|
*/
|
||||||
|
private String sourceName;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 所属误差体系
|
* 所属误差体系
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -53,4 +53,9 @@ public class DetectionData {
|
|||||||
* 误差体系详情ID(比对式使用)
|
* 误差体系详情ID(比对式使用)
|
||||||
*/
|
*/
|
||||||
private String errorDtlId;
|
private String errorDtlId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 有效组数
|
||||||
|
*/
|
||||||
|
private Integer validGroupNum;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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;
|
||||||
|
}
|
||||||
@@ -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();
|
||||||
}
|
}
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 比对式-与通信模块进行连接
|
* 比对式-与通信模块进行连接
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -0,0 +1,20 @@
|
|||||||
|
package com.njcn.gather.detection.sntp;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.net.InetSocketAddress;
|
||||||
|
import java.time.Instant;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class SntpExchange {
|
||||||
|
|
||||||
|
private InetSocketAddress clientAddress;
|
||||||
|
|
||||||
|
private int version;
|
||||||
|
|
||||||
|
private Instant deviceInstant;
|
||||||
|
|
||||||
|
private byte[] clientTransmitTimestamp;
|
||||||
|
}
|
||||||
@@ -0,0 +1,110 @@
|
|||||||
|
package com.njcn.gather.detection.sntp;
|
||||||
|
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.net.InetSocketAddress;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.time.Instant;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.time.ZoneId;
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class SntpPacketService {
|
||||||
|
|
||||||
|
private static final int MIN_PACKET_LENGTH = 48;
|
||||||
|
private static final int CLIENT_MODE = 3;
|
||||||
|
private static final int SERVER_MODE = 4;
|
||||||
|
// NTP纪元偏移量:2208988800秒(1900年到1970年的秒数差)
|
||||||
|
private static final long NTP_EPOCH_OFFSET = 2208988800L;
|
||||||
|
private static final ZoneId SHANGHAI_ZONE = ZoneId.of("Asia/Shanghai");
|
||||||
|
private static final byte[] REFERENCE_ID = "LOCL".getBytes(StandardCharsets.US_ASCII);
|
||||||
|
|
||||||
|
public SntpExchange parseRequest(byte[] request, InetSocketAddress clientAddress) {
|
||||||
|
if (request == null || request.length < MIN_PACKET_LENGTH) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
int mode = request[0] & 0x07;
|
||||||
|
if (mode != CLIENT_MODE) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
int version = (request[0] >> 3) & 0x07;
|
||||||
|
byte[] clientTransmitTimestamp = Arrays.copyOfRange(request, 40, 48);
|
||||||
|
Instant deviceInstant = fromNtpTimestamp(clientTransmitTimestamp);
|
||||||
|
return new SntpExchange(clientAddress, version == 0 ? 3 : version, deviceInstant, clientTransmitTimestamp);
|
||||||
|
}
|
||||||
|
|
||||||
|
public byte[] buildResponse(SntpExchange exchange, Instant receiveInstant, Instant transmitInstant) {
|
||||||
|
byte[] response = new byte[MIN_PACKET_LENGTH];
|
||||||
|
int version = exchange.getVersion() == 0 ? 3 : exchange.getVersion();
|
||||||
|
response[0] = (byte) ((version << 3) | SERVER_MODE);
|
||||||
|
response[1] = 0x01;
|
||||||
|
response[2] = 0x04;
|
||||||
|
response[3] = (byte) 0xEC;
|
||||||
|
System.arraycopy(REFERENCE_ID, 0, response, 12, REFERENCE_ID.length);
|
||||||
|
|
||||||
|
byte[] receiveTimestamp = toNtpTimestamp(receiveInstant);
|
||||||
|
byte[] transmitTimestamp = toNtpTimestamp(transmitInstant);
|
||||||
|
|
||||||
|
System.arraycopy(receiveTimestamp, 0, response, 16, receiveTimestamp.length);
|
||||||
|
System.arraycopy(exchange.getClientTransmitTimestamp(), 0, response, 24, exchange.getClientTransmitTimestamp().length);
|
||||||
|
System.arraycopy(receiveTimestamp, 0, response, 32, receiveTimestamp.length);
|
||||||
|
System.arraycopy(transmitTimestamp, 0, response, 40, transmitTimestamp.length);
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
|
public SntpPushMessage toPushMessage(String deviceIp, Instant computerInstant, Instant deviceInstant) {
|
||||||
|
long computerTimestampMs = computerInstant.toEpochMilli();
|
||||||
|
long deviceTimestampMs = deviceInstant.toEpochMilli();
|
||||||
|
return new SntpPushMessage(
|
||||||
|
"sntp_time_update",
|
||||||
|
deviceIp,
|
||||||
|
formatShanghaiTime(computerInstant),
|
||||||
|
formatShanghaiTime(deviceInstant),
|
||||||
|
computerTimestampMs,
|
||||||
|
deviceTimestampMs,
|
||||||
|
computerTimestampMs - deviceTimestampMs
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static byte[] toNtpTimestamp(Instant instant) {
|
||||||
|
long ntpSeconds = instant.getEpochSecond() + NTP_EPOCH_OFFSET;
|
||||||
|
long fraction = ((long) instant.getNano() << 32) / 1_000_000_000L;
|
||||||
|
byte[] bytes = new byte[8];
|
||||||
|
writeUnsignedInt(bytes, 0, ntpSeconds);
|
||||||
|
writeUnsignedInt(bytes, 4, fraction);
|
||||||
|
return bytes;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Instant fromNtpTimestamp(byte[] bytes) {
|
||||||
|
long seconds = readUnsignedInt(bytes, 0);
|
||||||
|
long fraction = readUnsignedInt(bytes, 4);
|
||||||
|
long epochSeconds = seconds - NTP_EPOCH_OFFSET;
|
||||||
|
long nanos = ((fraction * 1_000_000_000L) + 0x80000000L) >>> 32;
|
||||||
|
if (nanos >= 1_000_000_000L) {
|
||||||
|
epochSeconds += 1;
|
||||||
|
nanos -= 1_000_000_000L;
|
||||||
|
}
|
||||||
|
return Instant.ofEpochSecond(epochSeconds, nanos);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String formatShanghaiTime(Instant instant) {
|
||||||
|
return LocalDateTime.ofInstant(instant, SHANGHAI_ZONE).toString().replace('T', ' ');
|
||||||
|
}
|
||||||
|
|
||||||
|
private static long readUnsignedInt(byte[] bytes, int offset) {
|
||||||
|
return ((long) bytes[offset] & 0xFF) << 24
|
||||||
|
| ((long) bytes[offset + 1] & 0xFF) << 16
|
||||||
|
| ((long) bytes[offset + 2] & 0xFF) << 8
|
||||||
|
| ((long) bytes[offset + 3] & 0xFF);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void writeUnsignedInt(byte[] target, int offset, long value) {
|
||||||
|
target[offset] = (byte) ((value >>> 24) & 0xFF);
|
||||||
|
target[offset + 1] = (byte) ((value >>> 16) & 0xFF);
|
||||||
|
target[offset + 2] = (byte) ((value >>> 8) & 0xFF);
|
||||||
|
target[offset + 3] = (byte) (value & 0xFF);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
package com.njcn.gather.detection.sntp;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class SntpPushMessage {
|
||||||
|
|
||||||
|
private String type = "sntp_time_update";
|
||||||
|
|
||||||
|
private String deviceIp;
|
||||||
|
|
||||||
|
private String computerTime;
|
||||||
|
|
||||||
|
private String deviceTime;
|
||||||
|
|
||||||
|
private Long computerTimestampMs;
|
||||||
|
|
||||||
|
private Long deviceTimestampMs;
|
||||||
|
|
||||||
|
private Long errorMs;
|
||||||
|
}
|
||||||
@@ -0,0 +1,168 @@
|
|||||||
|
package com.njcn.gather.detection.sntp;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
|
||||||
|
import com.njcn.common.pojo.exception.BusinessException;
|
||||||
|
import com.njcn.gather.detection.util.socket.websocket.WebServiceManager;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import javax.annotation.PreDestroy;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.DatagramPacket;
|
||||||
|
import java.net.DatagramSocket;
|
||||||
|
import java.net.InetSocketAddress;
|
||||||
|
import java.net.SocketException;
|
||||||
|
import java.time.Instant;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.concurrent.ExecutorService;
|
||||||
|
import java.util.concurrent.Executors;
|
||||||
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@Service
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class SntpServerManager {
|
||||||
|
|
||||||
|
private final SntpServerProperties sntpServerProperties;
|
||||||
|
private final SntpPacketService sntpPacketService;
|
||||||
|
|
||||||
|
private final AtomicBoolean running = new AtomicBoolean(false);
|
||||||
|
private final Object lifecycleMonitor = new Object();
|
||||||
|
|
||||||
|
private volatile DatagramSocket datagramSocket;
|
||||||
|
private volatile ExecutorService executorService;
|
||||||
|
|
||||||
|
public void start() {
|
||||||
|
// 使用同步锁和原子变量防止重复启动
|
||||||
|
synchronized (lifecycleMonitor) {
|
||||||
|
if (running.get()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
int port = resolvePort();
|
||||||
|
DatagramSocket socket = createSocket(port);
|
||||||
|
ExecutorService executor = Executors.newSingleThreadExecutor(runnable -> {
|
||||||
|
Thread thread = new Thread(runnable, "sntp-server");
|
||||||
|
thread.setDaemon(true);
|
||||||
|
return thread;
|
||||||
|
});
|
||||||
|
|
||||||
|
datagramSocket = socket;
|
||||||
|
executorService = executor;
|
||||||
|
running.set(true);
|
||||||
|
executor.submit(this::receiveLoop);
|
||||||
|
log.info("SNTP服务已启动,监听端口: {}", port);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void stop() {
|
||||||
|
synchronized (lifecycleMonitor) {
|
||||||
|
if (!running.get()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
running.set(false);
|
||||||
|
closeSocketQuietly(datagramSocket);
|
||||||
|
datagramSocket = null;
|
||||||
|
if (executorService != null) {
|
||||||
|
executorService.shutdownNow();
|
||||||
|
executorService = null;
|
||||||
|
}
|
||||||
|
log.info("SNTP服务已停止");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isRunning() {
|
||||||
|
return running.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
@PreDestroy
|
||||||
|
public void destroy() {
|
||||||
|
stop();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void receiveLoop() {
|
||||||
|
byte[] buffer = new byte[512];
|
||||||
|
while (running.get()) {
|
||||||
|
DatagramSocket socket = datagramSocket;
|
||||||
|
if (socket == null || socket.isClosed()) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
DatagramPacket packet = new DatagramPacket(buffer, buffer.length);
|
||||||
|
try {
|
||||||
|
socket.receive(packet);
|
||||||
|
handlePacket(socket, packet);
|
||||||
|
log.info("SNTP服务接收报文: {}", Arrays.toString(packet.getData()));
|
||||||
|
} catch (SocketException e) {
|
||||||
|
if (running.get()) {
|
||||||
|
log.error("SNTP服务接收报文失败", e);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("SNTP服务处理报文失败", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
synchronized (lifecycleMonitor) {
|
||||||
|
if (running.get()) {
|
||||||
|
running.set(false);
|
||||||
|
closeSocketQuietly(datagramSocket);
|
||||||
|
datagramSocket = null;
|
||||||
|
if (executorService != null) {
|
||||||
|
executorService.shutdownNow();
|
||||||
|
executorService = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void handlePacket(DatagramSocket socket, DatagramPacket packet) throws IOException {
|
||||||
|
Instant receiveInstant = Instant.now(); //T2:服务器接收请求时间
|
||||||
|
byte[] request = Arrays.copyOf(packet.getData(), packet.getLength());
|
||||||
|
InetSocketAddress clientAddress = new InetSocketAddress(packet.getAddress(), packet.getPort());
|
||||||
|
SntpExchange exchange = sntpPacketService.parseRequest(request, clientAddress);
|
||||||
|
if (exchange == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Instant transmitInstant = Instant.now(); //T3:服务器发送响应时间
|
||||||
|
byte[] response = sntpPacketService.buildResponse(exchange, receiveInstant, transmitInstant);
|
||||||
|
DatagramPacket responsePacket = new DatagramPacket(response, response.length, packet.getAddress(), packet.getPort());
|
||||||
|
socket.send(responsePacket);
|
||||||
|
|
||||||
|
String deviceIp = clientAddress.getAddress().getHostAddress();
|
||||||
|
// SntpPushMessage pushMessage = sntpPacketService.toPushMessage(deviceIp, transmitInstant, exchange.getDeviceInstant());
|
||||||
|
SntpPushMessage pushMessage = sntpPacketService.toPushMessage(deviceIp, receiveInstant, exchange.getDeviceInstant());
|
||||||
|
WebServiceManager.broadcast(JSON.toJSONString(pushMessage));
|
||||||
|
}
|
||||||
|
|
||||||
|
private DatagramSocket createSocket(int port) {
|
||||||
|
try {
|
||||||
|
DatagramSocket socket = new DatagramSocket(port);
|
||||||
|
socket.setReuseAddress(true);
|
||||||
|
return socket;
|
||||||
|
} catch (SocketException e) {
|
||||||
|
throw new BusinessException(CommonResponseEnum.FAIL, "SNTP服务启动失败,端口绑定异常");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private int resolvePort() {
|
||||||
|
Integer port = sntpServerProperties.getPort();
|
||||||
|
if (port == null || port < 1 || port > 65535) {
|
||||||
|
throw new BusinessException(CommonResponseEnum.FAIL, "SNTP服务启动失败,端口配置无效");
|
||||||
|
}
|
||||||
|
return port;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 关闭UDP Socket
|
||||||
|
*
|
||||||
|
* @param socket
|
||||||
|
*/
|
||||||
|
private void closeSocketQuietly(DatagramSocket socket) {
|
||||||
|
if (socket != null && !socket.isClosed()) {
|
||||||
|
socket.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
package com.njcn.gather.detection.sntp;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Component
|
||||||
|
@ConfigurationProperties(prefix = "sntp")
|
||||||
|
public class SntpServerProperties {
|
||||||
|
|
||||||
|
private Integer port = 123;
|
||||||
|
}
|
||||||
@@ -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%≤CV<5%:优良</li>
|
||||||
|
* <li>5%≤CV<10%:良好</li>
|
||||||
|
* <li>10%≤CV<20%:中等</li>
|
||||||
|
* <li>20%≤CV:较差</li>
|
||||||
|
* </ul>
|
||||||
|
*
|
||||||
|
* @param x
|
||||||
|
* @param y
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static BigDecimal getCvCoefficient(List<Double> x, List<Double> y) {
|
||||||
|
List<BigDecimal> ratioList = new ArrayList<>();
|
||||||
|
for (int i = 0; i < x.size(); i++) {
|
||||||
|
ratioList.add(BigDecimal.valueOf(x.get(i) / y.get(i)));
|
||||||
|
}
|
||||||
|
|
||||||
|
BigDecimal avg = BigDecimal.valueOf(ratioList.parallelStream().mapToDouble(BigDecimal::doubleValue).average().orElse(0.0));
|
||||||
|
BigDecimal variance = BigDecimal.valueOf(
|
||||||
|
ratioList.parallelStream().mapToDouble(BigDecimal::doubleValue)
|
||||||
|
.map(v -> Math.pow(v - avg.doubleValue(), 2)).average().orElse(0.0));
|
||||||
|
|
||||||
|
return BigDecimal.valueOf(Math.sqrt(variance.doubleValue()) / avg.doubleValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 计算新的系数
|
||||||
|
*
|
||||||
|
* @param devList
|
||||||
|
* @param stdDevList
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static Double getNewXi(List<Double> devList, List<Double> stdDevList) {
|
||||||
|
ArrayList<Double> xiList = new ArrayList<>();
|
||||||
|
for (int i = 0; i < stdDevList.size(); i++) {
|
||||||
|
if (!stdDevList.get(i).equals(0)) {
|
||||||
|
BigDecimal bigDecimalDev = BigDecimal.valueOf(devList.get(i));
|
||||||
|
BigDecimal bigDecimalStdDev = BigDecimal.valueOf(stdDevList.get(i));
|
||||||
|
xiList.add((bigDecimalDev.subtract(bigDecimalStdDev)).divide(BigDecimal.valueOf(2.0).multiply(bigDecimalDev), 8, BigDecimal.ROUND_HALF_UP).doubleValue() + 1.0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return xiList.stream().mapToDouble(Double::doubleValue).average().orElse(1.0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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());
|
||||||
|
|||||||
@@ -10,8 +10,10 @@ 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.time.LocalDateTime;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -180,4 +182,41 @@ public class FormalTestManager {
|
|||||||
|
|
||||||
|
|
||||||
public static boolean isWaveCheck;
|
public static boolean isWaveCheck;
|
||||||
|
|
||||||
|
public static List<String> pstDataType;
|
||||||
|
|
||||||
|
public static boolean isPstData;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否在检测中
|
||||||
|
*/
|
||||||
|
public static boolean isTesting;
|
||||||
|
|
||||||
|
public static boolean realProtocol;
|
||||||
|
|
||||||
|
public static boolean statisticsProtocol;
|
||||||
|
|
||||||
|
public static boolean voltageProtocol;
|
||||||
|
|
||||||
|
public static boolean unknownError;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 当前下发的脚本
|
||||||
|
*/
|
||||||
|
public static SourceIssue currentIssue;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否进行相序校验
|
||||||
|
*/
|
||||||
|
public static boolean isXu;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 过载信息,如果检测到电压过载,overload=1;如果检测到电流过载,overload=2;如果检测到电压&&电流过载,overload=3;反之,overload=4
|
||||||
|
*/
|
||||||
|
public static int overload;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检测开始时间
|
||||||
|
*/
|
||||||
|
public static LocalDateTime checkStartTime;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -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");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -88,20 +99,33 @@ public class NettyContrastClientHandler extends SimpleChannelInboundHandler<Stri
|
|||||||
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) {
|
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) {
|
||||||
if (evt instanceof IdleStateEvent) { //IdleState.在一段时间内没有收到任何消息时,会触发该事件
|
if (evt instanceof IdleStateEvent) { //IdleState.在一段时间内没有收到任何消息时,会触发该事件
|
||||||
if (((IdleStateEvent) evt).state() == IdleState.READER_IDLE) {
|
if (((IdleStateEvent) evt).state() == IdleState.READER_IDLE) {
|
||||||
System.out.println(LocalDateTime.now() + "contrastClientHandler触发读超时函数**************************************");
|
if (FormalTestManager.isTesting) {
|
||||||
|
System.out.println(LocalDateTime.now() + "contrastClientHandler触发读超时函数**************************************");
|
||||||
|
|
||||||
if (!FormalTestManager.isRemoveSocket && ObjectUtil.isNotNull(FormalTestManager.nonWaveDataSourceEnum)) {
|
if (!FormalTestManager.isRemoveSocket && ObjectUtil.isNotNull(FormalTestManager.nonWaveDataSourceEnum)) {
|
||||||
long time = SocketManager.contrastClockMap.get(FormalTestManager.nonWaveDataSourceEnum) + 60L;
|
long time = SocketManager.contrastClockMap.get(FormalTestManager.nonWaveDataSourceEnum) + 60L;
|
||||||
SocketManager.contrastClockMap.put(FormalTestManager.nonWaveDataSourceEnum, time);
|
SocketManager.contrastClockMap.put(FormalTestManager.nonWaveDataSourceEnum, time);
|
||||||
|
|
||||||
if (DataSourceEnum.REAL_DATA == FormalTestManager.nonWaveDataSourceEnum) {
|
if (FormalTestManager.isPstData) {
|
||||||
if (time >= 60) {
|
if (time > 60 * 10) {
|
||||||
CnSocketUtil.contrastSendquit(param.getUserPageId(), SourceOperateCodeEnum.QUIT_INIT_02, true);
|
if (DataSourceEnum.REAL_DATA == FormalTestManager.nonWaveDataSourceEnum) {
|
||||||
timeoutSend(SourceOperateCodeEnum.QUIT_INIT_02);
|
CnSocketUtil.contrastSendquit(param.getUserPageId(), SourceOperateCodeEnum.QUIT_INIT_02, true);
|
||||||
|
}
|
||||||
|
if (FormalTestManager.isWaveCheck) {
|
||||||
|
CnSocketUtil.contrastSendquit(param.getUserPageId(), SourceOperateCodeEnum.QUIT_INIT_03, true);
|
||||||
|
}
|
||||||
|
CnSocketUtil.contrastSendquit(param.getUserPageId(), SourceOperateCodeEnum.QUIT_INIT_01, true);
|
||||||
|
timeoutSend(SourceOperateCodeEnum.QUIT_INIT_01);
|
||||||
|
}
|
||||||
|
} else if (DataSourceEnum.REAL_DATA == FormalTestManager.nonWaveDataSourceEnum) {
|
||||||
|
if (time >= 60) {
|
||||||
|
CnSocketUtil.contrastSendquit(param.getUserPageId(), SourceOperateCodeEnum.QUIT_INIT_02, true);
|
||||||
|
timeoutSend(SourceOperateCodeEnum.QUIT_INIT_02);
|
||||||
|
}
|
||||||
|
} else if (time >= FormalTestManager.maxTime) {
|
||||||
|
CnSocketUtil.contrastSendquit(param.getUserPageId(), SourceOperateCodeEnum.QUIT_INIT_01, true);
|
||||||
|
timeoutSend(SourceOperateCodeEnum.QUIT_INIT_01);
|
||||||
}
|
}
|
||||||
} else if (time >= FormalTestManager.maxTime) {
|
|
||||||
CnSocketUtil.contrastSendquit(param.getUserPageId(), SourceOperateCodeEnum.QUIT_INIT_02, true);
|
|
||||||
timeoutSend(SourceOperateCodeEnum.QUIT_INIT_01);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -137,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("超时处理-----》" + "统计数据已超时----------------关闭");
|
||||||
@@ -151,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");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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);
|
||||||
|
|
||||||
|
|||||||
@@ -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");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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;
|
||||||
@@ -86,6 +87,16 @@ public class WebServiceManager {
|
|||||||
return userSessions.remove(userId);
|
return userSessions.remove(userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 仅当当前会话仍绑定到指定通道时才移除,避免旧连接误删新连接映射。
|
||||||
|
*/
|
||||||
|
public static boolean removeByUserId(String userId, Channel channel) {
|
||||||
|
if (userId == null || channel == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return userSessions.remove(userId, channel);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据channelId移除会话(兼容老版本)
|
* 根据channelId移除会话(兼容老版本)
|
||||||
* 时间复杂度:O(n),建议使用removeByUserId替代
|
* 时间复杂度:O(n),建议使用removeByUserId替代
|
||||||
@@ -142,6 +153,19 @@ public class WebServiceManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void broadcast(String msg) {
|
||||||
|
for (Map.Entry<String, Channel> entry : userSessions.entrySet()) {
|
||||||
|
String userId = entry.getKey();
|
||||||
|
Channel channel = entry.getValue();
|
||||||
|
if (Objects.nonNull(channel) && channel.isActive()) {
|
||||||
|
channel.writeAndFlush(new TextWebSocketFrame(msg));
|
||||||
|
} else {
|
||||||
|
log.error("WebSocket broadcast failed, disconnected user, time: {}, userId: {}", LocalDateTime.now(), userId);
|
||||||
|
WebSocketHandler.cleanupSocketResources(userId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 存储检测参数(基于用户ID)
|
* 存储检测参数(基于用户ID)
|
||||||
* 支持多用户并发检测,每个用户的检测参数独立存储
|
* 支持多用户并发检测,每个用户的检测参数独立存储
|
||||||
@@ -296,6 +320,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 +339,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());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,13 +1,12 @@
|
|||||||
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;
|
||||||
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.device.pojo.enums.PatternEnum;
|
import com.njcn.gather.device.pojo.enums.PatternEnum;
|
||||||
import com.njcn.gather.plan.pojo.enums.DataSourceEnum;
|
|
||||||
import io.netty.channel.ChannelHandlerContext;
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
import io.netty.channel.SimpleChannelInboundHandler;
|
import io.netty.channel.SimpleChannelInboundHandler;
|
||||||
import io.netty.handler.codec.CorruptedFrameException;
|
import io.netty.handler.codec.CorruptedFrameException;
|
||||||
@@ -112,7 +111,7 @@ public class WebSocketHandler extends SimpleChannelInboundHandler<TextWebSocketF
|
|||||||
public void handlerRemoved(ChannelHandlerContext ctx) {
|
public void handlerRemoved(ChannelHandlerContext ctx) {
|
||||||
log.info("webSocket客户端退出,channelId: {}, userId: {}", ctx.channel().id(), this.userId);
|
log.info("webSocket客户端退出,channelId: {}, userId: {}", ctx.channel().id(), this.userId);
|
||||||
if (this.userId != null) {
|
if (this.userId != null) {
|
||||||
WebServiceManager.removeByUserId(this.userId);
|
WebServiceManager.removeByUserId(this.userId, ctx.channel());
|
||||||
} else {
|
} else {
|
||||||
// 备用方案:如果userId为空,使用传统方法
|
// 备用方案:如果userId为空,使用传统方法
|
||||||
WebServiceManager.removeChannel(ctx.channel().id().toString());
|
WebServiceManager.removeChannel(ctx.channel().id().toString());
|
||||||
@@ -169,7 +168,7 @@ public class WebSocketHandler extends SimpleChannelInboundHandler<TextWebSocketF
|
|||||||
log.error("客户端心跳检测空闲次数超过{}次,关闭连接,channelId: {}, userId: {}", MAX_HEARTBEAT_MISS_COUNT, ctx.channel().id(), this.userId);
|
log.error("客户端心跳检测空闲次数超过{}次,关闭连接,channelId: {}, userId: {}", MAX_HEARTBEAT_MISS_COUNT, ctx.channel().id(), this.userId);
|
||||||
ctx.channel().close();
|
ctx.channel().close();
|
||||||
if (this.userId != null) {
|
if (this.userId != null) {
|
||||||
WebServiceManager.removeByUserId(this.userId);
|
WebServiceManager.removeByUserId(this.userId, ctx.channel());
|
||||||
} else {
|
} else {
|
||||||
WebServiceManager.removeChannel(ctx.channel().id().toString());
|
WebServiceManager.removeChannel(ctx.channel().id().toString());
|
||||||
}
|
}
|
||||||
@@ -327,7 +326,7 @@ public class WebSocketHandler extends SimpleChannelInboundHandler<TextWebSocketF
|
|||||||
|
|
||||||
// 清理会话
|
// 清理会话
|
||||||
if (this.userId != null) {
|
if (this.userId != null) {
|
||||||
WebServiceManager.removeByUserId(this.userId);
|
WebServiceManager.removeByUserId(this.userId, ctx.channel());
|
||||||
log.debug("已清理WebSocket会话,userId: {}, channelId: {}", this.userId, channelId);
|
log.debug("已清理WebSocket会话,userId: {}, channelId: {}", this.userId, channelId);
|
||||||
} else {
|
} else {
|
||||||
WebServiceManager.removeChannel(channelId);
|
WebServiceManager.removeChannel(channelId);
|
||||||
@@ -373,40 +372,54 @@ public class WebSocketHandler extends SimpleChannelInboundHandler<TextWebSocketF
|
|||||||
// 使用该用户的检测参数关闭Socket连接
|
// 使用该用户的检测参数关闭Socket连接
|
||||||
log.info("使用用户检测参数关闭Socket连接,userId: {}", userId);
|
log.info("使用用户检测参数关闭Socket连接,userId: {}", userId);
|
||||||
if (FormalTestManager.patternEnum.equals(PatternEnum.CONTRAST)) {
|
if (FormalTestManager.patternEnum.equals(PatternEnum.CONTRAST)) {
|
||||||
if (FormalTestManager.isRemoveSocket) {
|
CnSocketUtil.contrastSendquit(preDetectionParam.getUserPageId(), SourceOperateCodeEnum.QUIT_INIT_01, false);
|
||||||
boolean channelActive = SocketManager.isChannelActive(preDetectionParam.getUserPageId() + CnSocketUtil.CONTRAST_DEV_TAG);
|
CnSocketUtil.contrastSendquit(preDetectionParam.getUserPageId(), SourceOperateCodeEnum.QUIT_INIT_02, false);
|
||||||
if (channelActive) {
|
CnSocketUtil.contrastSendquit(preDetectionParam.getUserPageId(), SourceOperateCodeEnum.QUIT_INIT_03, false);
|
||||||
SocketManager.removeUser(preDetectionParam.getUserPageId() + CnSocketUtil.CONTRAST_DEV_TAG);
|
// if (FormalTestManager.isRemoveSocket) {
|
||||||
}
|
// boolean channelActive = SocketManager.isChannelActive(preDetectionParam.getUserPageId() + CnSocketUtil.CONTRAST_DEV_TAG);
|
||||||
} else {
|
// if (channelActive) {
|
||||||
if (FormalTestManager.currentStep == SourceOperateCodeEnum.RECORD_WAVE_STEP1) {
|
// SocketManager.removeUser(preDetectionParam.getUserPageId() + CnSocketUtil.CONTRAST_DEV_TAG);
|
||||||
CnSocketUtil.contrastSendquit(preDetectionParam.getUserPageId(), SourceOperateCodeEnum.QUIT_INIT_03, true);
|
// }
|
||||||
} else if (FormalTestManager.currentStep != SourceOperateCodeEnum.QUITE) {
|
// } else {
|
||||||
if (ObjectUtil.isNotNull(FormalTestManager.nonWaveDataSourceEnum)) {
|
// if (FormalTestManager.currentStep == SourceOperateCodeEnum.RECORD_WAVE_STEP1) {
|
||||||
if (FormalTestManager.nonWaveDataSourceEnum == DataSourceEnum.REAL_DATA) {
|
// CnSocketUtil.contrastSendquit(preDetectionParam.getUserPageId(), SourceOperateCodeEnum.QUIT_INIT_03, false);
|
||||||
CnSocketUtil.contrastSendquit(preDetectionParam.getUserPageId(), SourceOperateCodeEnum.QUIT_INIT_02, false);
|
// } else if (FormalTestManager.currentStep != SourceOperateCodeEnum.QUITE) {
|
||||||
} else {
|
// if (ObjectUtil.isNotNull(FormalTestManager.nonWaveDataSourceEnum)) {
|
||||||
CnSocketUtil.contrastSendquit(preDetectionParam.getUserPageId(), SourceOperateCodeEnum.QUIT_INIT_01, false);
|
// if (FormalTestManager.nonWaveDataSourceEnum == DataSourceEnum.REAL_DATA) {
|
||||||
}
|
// CnSocketUtil.contrastSendquit(preDetectionParam.getUserPageId(), SourceOperateCodeEnum.QUIT_INIT_02, false);
|
||||||
if (FormalTestManager.isWaveCheck) {
|
// if (FormalTestManager.statisticsProtocol) {
|
||||||
CnSocketUtil.contrastSendquit(preDetectionParam.getUserPageId(), SourceOperateCodeEnum.QUIT_INIT_03, true);
|
// CnSocketUtil.contrastSendquit(preDetectionParam.getUserPageId(), SourceOperateCodeEnum.QUIT_INIT_01, false);
|
||||||
}
|
// }
|
||||||
} else {
|
// } else {
|
||||||
if (FormalTestManager.isWaveCheck) {
|
// CnSocketUtil.contrastSendquit(preDetectionParam.getUserPageId(), SourceOperateCodeEnum.QUIT_INIT_01, false);
|
||||||
CnSocketUtil.contrastSendquit(preDetectionParam.getUserPageId(), SourceOperateCodeEnum.QUIT_INIT_02, false);
|
// }
|
||||||
CnSocketUtil.contrastSendquit(preDetectionParam.getUserPageId(), SourceOperateCodeEnum.QUIT_INIT_03, true);
|
// if (FormalTestManager.isWaveCheck) {
|
||||||
}
|
// CnSocketUtil.contrastSendquit(preDetectionParam.getUserPageId(), SourceOperateCodeEnum.QUIT_INIT_03, false);
|
||||||
}
|
// }
|
||||||
} else {
|
// } else {
|
||||||
SocketManager.removeUser(preDetectionParam.getUserPageId() + CnSocketUtil.CONTRAST_DEV_TAG);
|
// if (FormalTestManager.statisticsProtocol) {
|
||||||
}
|
// CnSocketUtil.contrastSendquit(preDetectionParam.getUserPageId(), SourceOperateCodeEnum.QUIT_INIT_01, false);
|
||||||
}
|
// }
|
||||||
|
// if (FormalTestManager.isWaveCheck) {
|
||||||
|
// CnSocketUtil.contrastSendquit(preDetectionParam.getUserPageId(), SourceOperateCodeEnum.QUIT_INIT_02, false);
|
||||||
|
// CnSocketUtil.contrastSendquit(preDetectionParam.getUserPageId(), SourceOperateCodeEnum.QUIT_INIT_03, false);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// } else {
|
||||||
|
// SocketManager.removeUser(preDetectionParam.getUserPageId() + CnSocketUtil.CONTRAST_DEV_TAG);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
} else {
|
} else {
|
||||||
CnSocketUtil.quitSendSource(preDetectionParam);
|
CnSocketUtil.quitSendSource(preDetectionParam);
|
||||||
CnSocketUtil.quitSend(preDetectionParam);
|
CnSocketUtil.quitSend(preDetectionParam);
|
||||||
}
|
}
|
||||||
// 清理完成后移除该用户的检测参数
|
// 清理完成后移除该用户的检测参数
|
||||||
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);
|
||||||
@@ -414,4 +427,4 @@ public class WebSocketHandler extends SimpleChannelInboundHandler<TextWebSocketF
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ================================ URL解析工具已移至WebSocketPreprocessor ================================
|
// ================================ URL解析工具已移至WebSocketPreprocessor ================================
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,10 +9,10 @@ import com.njcn.common.pojo.enums.response.CommonResponseEnum;
|
|||||||
import com.njcn.common.pojo.exception.BusinessException;
|
import com.njcn.common.pojo.exception.BusinessException;
|
||||||
import com.njcn.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.device.pojo.dto.DataCheckResDTO;
|
||||||
import com.njcn.gather.device.pojo.param.PqDevParam;
|
import com.njcn.gather.device.pojo.param.PqDevParam;
|
||||||
import com.njcn.gather.device.pojo.vo.PqDevVO;
|
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.monitor.pojo.po.PqMonitor;
|
|
||||||
import com.njcn.gather.type.service.IDevTypeService;
|
import com.njcn.gather.type.service.IDevTypeService;
|
||||||
import com.njcn.web.controller.BaseController;
|
import com.njcn.web.controller.BaseController;
|
||||||
import com.njcn.web.utils.FileUtil;
|
import com.njcn.web.utils.FileUtil;
|
||||||
@@ -101,7 +101,7 @@ public class PqDevController extends BaseController {
|
|||||||
@OperateInfo(operateType = OperateType.DELETE)
|
@OperateInfo(operateType = OperateType.DELETE)
|
||||||
@PostMapping("/delete")
|
@PostMapping("/delete")
|
||||||
@ApiOperation("删除被检设备")
|
@ApiOperation("删除被检设备")
|
||||||
@ApiImplicitParam(name = "ids", value = "被检设备id", required = true)
|
@ApiImplicitParam(name = "param", value = "删除参数", required = true)
|
||||||
public HttpResult<Boolean> delete(@RequestBody @Validated PqDevParam.DeleteParam param) {
|
public HttpResult<Boolean> delete(@RequestBody @Validated PqDevParam.DeleteParam param) {
|
||||||
String methodDescribe = getMethodDescribe("delete");
|
String methodDescribe = getMethodDescribe("delete");
|
||||||
LogUtil.njcnDebug(log, "{},删除ID数据为:{}", methodDescribe, String.join(StrUtil.COMMA, param.getIds()));
|
LogUtil.njcnDebug(log, "{},删除ID数据为:{}", methodDescribe, String.join(StrUtil.COMMA, param.getIds()));
|
||||||
@@ -137,7 +137,7 @@ public class PqDevController extends BaseController {
|
|||||||
@ApiImplicitParam(name = "file", value = "被检设备数据文件", required = true),
|
@ApiImplicitParam(name = "file", value = "被检设备数据文件", required = true),
|
||||||
@ApiImplicitParam(name = "patternId", value = "模式id", required = true)
|
@ApiImplicitParam(name = "patternId", value = "模式id", required = true)
|
||||||
})
|
})
|
||||||
public HttpResult<Boolean> importDev(@RequestParam("file") MultipartFile file, @RequestParam("patternId") String patternId, @RequestParam("planId") String planId, HttpServletResponse response) {
|
public HttpResult importDev(@RequestParam("file") MultipartFile file, @RequestParam("patternId") String patternId, @RequestParam("planId") String planId, @RequestParam(value = "cover", defaultValue = "0") Integer cover, HttpServletResponse response) {
|
||||||
String methodDescribe = getMethodDescribe("importDev");
|
String methodDescribe = getMethodDescribe("importDev");
|
||||||
LogUtil.njcnDebug(log, "{},上传文件为:{}", methodDescribe, file.getOriginalFilename());
|
LogUtil.njcnDebug(log, "{},上传文件为:{}", methodDescribe, file.getOriginalFilename());
|
||||||
boolean fileType = FileUtil.judgeFileIsExcel(file.getOriginalFilename());
|
boolean fileType = FileUtil.judgeFileIsExcel(file.getOriginalFilename());
|
||||||
@@ -147,12 +147,7 @@ public class PqDevController extends BaseController {
|
|||||||
if ("null".equals(planId)) {
|
if ("null".equals(planId)) {
|
||||||
planId = null;
|
planId = null;
|
||||||
}
|
}
|
||||||
Boolean result = pqDevService.importDev(file, patternId, planId, response);
|
return pqDevService.importDev(file, patternId, planId, response, cover);
|
||||||
if (result) {
|
|
||||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, methodDescribe);
|
|
||||||
} else {
|
|
||||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, false, methodDescribe);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||||
@@ -168,10 +163,22 @@ public class PqDevController extends BaseController {
|
|||||||
|
|
||||||
@OperateInfo
|
@OperateInfo
|
||||||
@GetMapping("/getSelectOptions")
|
@GetMapping("/getSelectOptions")
|
||||||
@ApiOperation("根据历史记录信息来获取下拉框内容")
|
@ApiOperation("从历史数据中查询下拉框选项")
|
||||||
|
@ApiImplicitParam(name = "pattern", value = "模式id", required = true)
|
||||||
public HttpResult<Map<String, List<String>>> getSelectOptions(@RequestParam("pattern") String pattern) {
|
public HttpResult<Map<String, List<String>>> getSelectOptions(@RequestParam("pattern") String pattern) {
|
||||||
String methodDescribe = getMethodDescribe("getSelectOptions");
|
String methodDescribe = getMethodDescribe("getSelectOptions");
|
||||||
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
|
||||||
|
@GetMapping("/getDataCheckRes")
|
||||||
|
@ApiOperation("获取接入测试-数据校验结果")
|
||||||
|
@ApiImplicitParam(name = "monitorId", value = "监测点id", required = true)
|
||||||
|
public HttpResult<DataCheckResDTO> getDataCheckRes(@RequestParam("monitorId") String monitorId) {
|
||||||
|
String methodDescribe = getMethodDescribe("getDataCheckRes");
|
||||||
|
DataCheckResDTO dataCheckRes = pqDevService.getDataCheckRes(monitorId);
|
||||||
|
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, dataCheckRes, methodDescribe);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -149,17 +150,17 @@ public class PqStandardDevController extends BaseController {
|
|||||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
|
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
|
||||||
}
|
}
|
||||||
|
|
||||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
// @OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||||
@PostMapping("/listByPlanId")
|
// @PostMapping("/listByPlanId")
|
||||||
@ApiOperation("查询出指定计划已关联的标准设备")
|
// @ApiOperation("查询出指定计划已关联的标准设备")
|
||||||
@ApiImplicitParam(name = "planId", value = "计划id", required = true)
|
// @ApiImplicitParam(name = "planId", value = "计划id", required = true)
|
||||||
public HttpResult<List<PqStandardDev>> listByPlanId(@RequestParam("planId") String planId) {
|
// public HttpResult<List<PqStandardDev>> listByPlanId(@RequestParam("planId") String planId) {
|
||||||
String methodDescribe = getMethodDescribe("listByPlanId");
|
// String methodDescribe = getMethodDescribe("listByPlanId");
|
||||||
LogUtil.njcnDebug(log, "{},查询数据为:{}", methodDescribe, planId);
|
// LogUtil.njcnDebug(log, "{},查询数据为:{}", methodDescribe, planId);
|
||||||
List<PqStandardDev> pqDevVOList = pqStandardDevService.listByPlanId(planId);
|
// List<PqStandardDev> pqDevVOList = pqStandardDevService.listByPlanId(planId);
|
||||||
|
//
|
||||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, pqDevVOList, methodDescribe);
|
// return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, pqDevVOList, methodDescribe);
|
||||||
}
|
// }
|
||||||
|
|
||||||
|
|
||||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
package com.njcn.gather.device.mapper;
|
||||||
|
|
||||||
|
import com.github.yulichang.base.MPJBaseMapper;
|
||||||
|
import com.njcn.gather.device.pojo.po.PqStandardDevGain;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author caozehui
|
||||||
|
* @date 2026-01-12
|
||||||
|
*/
|
||||||
|
public interface PqStandardDevGainMapper extends MPJBaseMapper<PqStandardDevGain> {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
package com.njcn.gather.device.mapper;
|
||||||
|
|
||||||
|
import com.github.yulichang.base.MPJBaseMapper;
|
||||||
|
import com.njcn.gather.device.pojo.po.PqStandardDevGainRecord;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author caozehui
|
||||||
|
* @date 2026-01-15
|
||||||
|
*/
|
||||||
|
public interface PqStandardDevGainRecordMapper extends MPJBaseMapper<PqStandardDevGainRecord> {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@@ -134,6 +134,7 @@
|
|||||||
#{item}
|
#{item}
|
||||||
</foreach>
|
</foreach>
|
||||||
</if>
|
</if>
|
||||||
|
order by dev.Create_Time DESC, dev.Name ASC
|
||||||
</select>
|
</select>
|
||||||
</mapper>
|
</mapper>
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
|
<mapper namespace="com.njcn.gather.device.mapper.PqStandardDevGainMapper">
|
||||||
|
|
||||||
|
|
||||||
|
</mapper>
|
||||||
|
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
|
<mapper namespace="com.njcn.gather.device.mapper.PqStandardDevGainRecordMapper">
|
||||||
|
|
||||||
|
|
||||||
|
</mapper>
|
||||||
|
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
package com.njcn.gather.device.pojo.dto;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author caozehui
|
||||||
|
* @data 2026-06-15
|
||||||
|
*/
|
||||||
|
public class DataCheckResDTO {
|
||||||
|
}
|
||||||
@@ -56,10 +56,16 @@ public class PqDevSub {
|
|||||||
private String checkBy;
|
private String checkBy;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 检测时间
|
* 检测开始时间
|
||||||
*/
|
*/
|
||||||
@TableField("Check_Time")
|
@TableField("Check_Start_Time")
|
||||||
private LocalDateTime checkTime;
|
private LocalDateTime checkStartTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检测开始时间
|
||||||
|
*/
|
||||||
|
@TableField("Check_End_Time")
|
||||||
|
private LocalDateTime checkEndTime;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 预检测耗时
|
* 预检测耗时
|
||||||
|
|||||||
@@ -0,0 +1,61 @@
|
|||||||
|
package com.njcn.gather.device.pojo.po;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import com.njcn.db.mybatisplus.bo.BaseEntity;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author caozehui
|
||||||
|
* @date 2026-01-12
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
@TableName("pq_standard_dev_gain")
|
||||||
|
public class PqStandardDevGain extends BaseEntity implements Serializable {
|
||||||
|
private static final long serialVersionUID = -46280767885558804L;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 标准设备Id_通道号
|
||||||
|
*/
|
||||||
|
@TableId
|
||||||
|
private String stdDevMonitorId;
|
||||||
|
|
||||||
|
private Integer uaGain;
|
||||||
|
|
||||||
|
private Integer ubGain;
|
||||||
|
|
||||||
|
|
||||||
|
private Integer ucGain;
|
||||||
|
|
||||||
|
|
||||||
|
private Integer u0Gain;
|
||||||
|
|
||||||
|
|
||||||
|
private Integer iaGain;
|
||||||
|
|
||||||
|
|
||||||
|
private Integer ibGain;
|
||||||
|
|
||||||
|
|
||||||
|
private Integer icGain;
|
||||||
|
|
||||||
|
|
||||||
|
private Integer i0Gain;
|
||||||
|
|
||||||
|
|
||||||
|
private Integer uabGain;
|
||||||
|
|
||||||
|
|
||||||
|
private Integer ubcGain;
|
||||||
|
|
||||||
|
|
||||||
|
private Integer ucaGain;
|
||||||
|
|
||||||
|
private Integer state;
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
package com.njcn.gather.device.pojo.po;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import com.njcn.db.mybatisplus.bo.BaseEntity;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author caozehui
|
||||||
|
* @date 2026-01-15
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@TableName("pq_standard_dev_gain_record")
|
||||||
|
public class PqStandardDevGainRecord implements Serializable {
|
||||||
|
private static final long serialVersionUID = 477276215572686991L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 标准设备监测点id,由设备id_通道号组成
|
||||||
|
*/
|
||||||
|
private String stdDevMonitorId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 被检设备监测点id,由设备id_通道号组成
|
||||||
|
*/
|
||||||
|
private String devMonitorId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 系数下发次数
|
||||||
|
*/
|
||||||
|
private Integer num;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@@ -38,8 +38,8 @@ public class ContrastDevExcel implements Serializable {
|
|||||||
@Pattern(regexp = PatternRegex.DEV_NAME_REGEX, message = DetectionValidMessage.NAME_FORMAT_ERROR)
|
@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")
|
||||||
|
|||||||
@@ -111,4 +111,9 @@ public class PqDevVO extends PqDev {
|
|||||||
* 是否已经分配。0-未分配、1-已分配、2-所有
|
* 是否已经分配。0-未分配、1-已分配、2-所有
|
||||||
*/
|
*/
|
||||||
private Integer assign;
|
private Integer assign;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检测点结果
|
||||||
|
*/
|
||||||
|
private List<Integer> monitorResults;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,20 @@
|
|||||||
|
package com.njcn.gather.device.pojo.vo;
|
||||||
|
|
||||||
|
import com.njcn.gather.device.pojo.po.PqStandardDev;
|
||||||
|
import com.njcn.gather.device.pojo.po.PqStandardDevGain;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author caozehui
|
||||||
|
* @data 2026-01-19
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class PqStandardDevVO extends PqStandardDev {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通道系数
|
||||||
|
*/
|
||||||
|
List<PqStandardDevGain> gainList;
|
||||||
|
}
|
||||||
@@ -3,6 +3,8 @@ package com.njcn.gather.device.service;
|
|||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
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.common.pojo.poi.PullDown;
|
import com.njcn.common.pojo.poi.PullDown;
|
||||||
|
import com.njcn.common.pojo.response.HttpResult;
|
||||||
|
import com.njcn.gather.device.pojo.dto.DataCheckResDTO;
|
||||||
import com.njcn.gather.device.pojo.enums.TimeCheckResultEnum;
|
import com.njcn.gather.device.pojo.enums.TimeCheckResultEnum;
|
||||||
import com.njcn.gather.device.pojo.param.PqDevParam;
|
import com.njcn.gather.device.pojo.param.PqDevParam;
|
||||||
import com.njcn.gather.device.pojo.po.PqDev;
|
import com.njcn.gather.device.pojo.po.PqDev;
|
||||||
@@ -114,9 +116,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);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 比对式-修改设备状态
|
* 比对式-修改设备状态
|
||||||
@@ -124,7 +127,7 @@ public interface IPqDevService extends IService<PqDev> {
|
|||||||
* @param devId
|
* @param devId
|
||||||
* @param userId
|
* @param userId
|
||||||
*/
|
*/
|
||||||
void updateResult(String devId,String userId);
|
void updateResult(String devId, String userId);
|
||||||
|
|
||||||
void updatePqDevReportState(String devId, int i);
|
void updatePqDevReportState(String devId, int i);
|
||||||
|
|
||||||
@@ -160,7 +163,7 @@ public interface IPqDevService extends IService<PqDev> {
|
|||||||
* @param planId 计划Id
|
* @param planId 计划Id
|
||||||
* @param response 响应
|
* @param response 响应
|
||||||
*/
|
*/
|
||||||
boolean importDev(MultipartFile file, String patternId, String planId, HttpServletResponse response);
|
HttpResult importDev(MultipartFile file, String patternId, String planId, HttpServletResponse response, Integer cover);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 导入灿能二楼设备数据
|
* 导入灿能二楼设备数据
|
||||||
@@ -254,7 +257,7 @@ public interface IPqDevService extends IService<PqDev> {
|
|||||||
* @param planId 计划Id
|
* @param planId 计划Id
|
||||||
* @param response 响应
|
* @param response 响应
|
||||||
*/
|
*/
|
||||||
boolean importContrastDev(MultipartFile file, String patternId, String planId, HttpServletResponse response);
|
HttpResult importContrastDev(MultipartFile file, String patternId, String planId, HttpServletResponse response, Integer cover);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 导入比对式设备数据
|
* 导入比对式设备数据
|
||||||
@@ -262,7 +265,7 @@ public interface IPqDevService extends IService<PqDev> {
|
|||||||
* @param contrastDevExcelList
|
* @param contrastDevExcelList
|
||||||
* @param patternId
|
* @param patternId
|
||||||
*/
|
*/
|
||||||
boolean importContrastDev(List<ContrastDevExcel> contrastDevExcelList, String patternId, String planId);
|
HttpResult importContrastDev(List<ContrastDevExcel> contrastDevExcelList, String patternId, String planId, Integer cover);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取比对式设备导出、导出文件模板的下拉列表
|
* 获取比对式设备导出、导出文件模板的下拉列表
|
||||||
@@ -287,4 +290,11 @@ public interface IPqDevService extends IService<PqDev> {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
List<ContrastDevExcel> getExportContrastDevData(List<PqDevVO> pqDevVOList);
|
List<ContrastDevExcel> getExportContrastDevData(List<PqDevVO> pqDevVOList);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取接入测试-数据校验结果
|
||||||
|
* @param monitorId
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
DataCheckResDTO getDataCheckRes(String monitorId);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,29 @@
|
|||||||
|
package com.njcn.gather.device.service;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
import com.njcn.gather.device.pojo.po.PqStandardDevGainRecord;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author caozehui
|
||||||
|
* @date 2026-01-15
|
||||||
|
*/
|
||||||
|
public interface IPqStandardDevGainRecordService extends IService<PqStandardDevGainRecord> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取最大下发系数的次数
|
||||||
|
*
|
||||||
|
* @param stdDevMonitorId
|
||||||
|
* @param devMonitorId
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
int getMaxNum(String stdDevMonitorId, String devMonitorId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量新增或更新记录
|
||||||
|
* @param recordList
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
boolean addOrUpdate(List<PqStandardDevGainRecord> recordList);
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
package com.njcn.gather.device.service;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
import com.njcn.gather.device.pojo.po.PqStandardDevGain;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author caozehui
|
||||||
|
* @date 2026-01-12
|
||||||
|
*/
|
||||||
|
public interface IPqStandardDevGainService extends IService<PqStandardDevGain> {
|
||||||
|
|
||||||
|
boolean add(List<PqStandardDevGain> pqStandardDevGainList);
|
||||||
|
|
||||||
|
PqStandardDevGain get(String stdDevMonitorId);
|
||||||
|
|
||||||
|
List<PqStandardDevGain> list(String stdDevId);
|
||||||
|
}
|
||||||
@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
import com.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);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 新增标准设备
|
* 新增标准设备
|
||||||
@@ -82,7 +83,7 @@ public interface IPqStandardDevService extends IService<PqStandardDev> {
|
|||||||
* @param planId
|
* @param planId
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
List<PqStandardDev> listByPlanId(String planId);
|
// List<PqStandardDev> listByPlanId(String planId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询出标准设备所需的检测信息
|
* 查询出标准设备所需的检测信息
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import cn.hutool.core.util.ObjectUtil;
|
|||||||
import cn.hutool.core.util.ReflectUtil;
|
import cn.hutool.core.util.ReflectUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||||
import com.baomidou.mybatisplus.extension.conditions.update.LambdaUpdateChainWrapper;
|
import com.baomidou.mybatisplus.extension.conditions.update.LambdaUpdateChainWrapper;
|
||||||
@@ -19,11 +20,15 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|||||||
import com.github.yulichang.wrapper.MPJLambdaWrapper;
|
import com.github.yulichang.wrapper.MPJLambdaWrapper;
|
||||||
import com.njcn.common.pojo.constant.PatternRegex;
|
import com.njcn.common.pojo.constant.PatternRegex;
|
||||||
import com.njcn.common.pojo.enums.common.DataStateEnum;
|
import com.njcn.common.pojo.enums.common.DataStateEnum;
|
||||||
|
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
|
||||||
import com.njcn.common.pojo.exception.BusinessException;
|
import com.njcn.common.pojo.exception.BusinessException;
|
||||||
import com.njcn.common.pojo.poi.PullDown;
|
import com.njcn.common.pojo.poi.PullDown;
|
||||||
|
import com.njcn.common.pojo.response.HttpResult;
|
||||||
import com.njcn.common.utils.EncryptionUtil;
|
import com.njcn.common.utils.EncryptionUtil;
|
||||||
import com.njcn.db.mybatisplus.constant.DbConstant;
|
import com.njcn.db.mybatisplus.constant.DbConstant;
|
||||||
|
import com.njcn.gather.detection.util.socket.FormalTestManager;
|
||||||
import com.njcn.gather.device.mapper.PqDevMapper;
|
import com.njcn.gather.device.mapper.PqDevMapper;
|
||||||
|
import com.njcn.gather.device.pojo.dto.DataCheckResDTO;
|
||||||
import com.njcn.gather.device.pojo.enums.*;
|
import com.njcn.gather.device.pojo.enums.*;
|
||||||
import com.njcn.gather.device.pojo.param.PqDevParam;
|
import com.njcn.gather.device.pojo.param.PqDevParam;
|
||||||
import com.njcn.gather.device.pojo.po.PqDev;
|
import com.njcn.gather.device.pojo.po.PqDev;
|
||||||
@@ -34,6 +39,10 @@ import com.njcn.gather.device.service.IPqDevSubService;
|
|||||||
import com.njcn.gather.monitor.pojo.po.PqMonitor;
|
import com.njcn.gather.monitor.pojo.po.PqMonitor;
|
||||||
import com.njcn.gather.monitor.pojo.vo.PqMonitorExcel;
|
import com.njcn.gather.monitor.pojo.vo.PqMonitorExcel;
|
||||||
import com.njcn.gather.monitor.service.IPqMonitorService;
|
import com.njcn.gather.monitor.service.IPqMonitorService;
|
||||||
|
import com.njcn.gather.plan.mapper.AdPlanMapper;
|
||||||
|
import com.njcn.gather.plan.pojo.enums.DataSourceEnum;
|
||||||
|
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;
|
||||||
@@ -47,8 +56,10 @@ 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;
|
||||||
import com.njcn.gather.user.user.service.ISysUserService;
|
import com.njcn.gather.user.user.service.ISysUserService;
|
||||||
|
import com.njcn.http.util.RestTemplateUtil;
|
||||||
import com.njcn.web.factory.PageFactory;
|
import com.njcn.web.factory.PageFactory;
|
||||||
import com.njcn.web.utils.ExcelUtil;
|
import com.njcn.web.utils.ExcelUtil;
|
||||||
|
import com.njcn.web.utils.HttpResultUtil;
|
||||||
import com.njcn.web.utils.PoiUtil;
|
import com.njcn.web.utils.PoiUtil;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
@@ -63,6 +74,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
|
||||||
@@ -81,6 +93,9 @@ 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;
|
||||||
|
private final RestTemplateUtil restTemplateUtil;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Page<PqDevVO> listPqDevs(PqDevParam.QueryParam queryParam) {
|
public Page<PqDevVO> listPqDevs(PqDevParam.QueryParam queryParam) {
|
||||||
@@ -212,7 +227,8 @@ public class PqDevServiceImpl extends ServiceImpl<PqDevMapper, PqDev> implements
|
|||||||
if (PatternEnum.CONTRAST.getValue().equals(dictDataService.getDictDataById(param.getPattern()).getCode())) {
|
if (PatternEnum.CONTRAST.getValue().equals(dictDataService.getDictDataById(param.getPattern()).getCode())) {
|
||||||
for (String id : param.getIds()) {
|
for (String id : param.getIds()) {
|
||||||
if (ObjectUtils.isNotEmpty(pqMonitorService.listPqMonitorByDevIds(Collections.singletonList(id)))) {
|
if (ObjectUtils.isNotEmpty(pqMonitorService.listPqMonitorByDevIds(Collections.singletonList(id)))) {
|
||||||
throw new BusinessException(DetectionResponseEnum.PQ_DEV_HAS_MONITOR);
|
// throw new BusinessException(DetectionResponseEnum.PQ_DEV_HAS_MONITOR);
|
||||||
|
pqMonitorService.removeByDevId(id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -286,6 +302,33 @@ public class PqDevServiceImpl extends ServiceImpl<PqDevMapper, PqDev> implements
|
|||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
List<PqDevVO> pqDevList = this.baseMapper.selectByQueryParam(param);
|
List<PqDevVO> pqDevList = this.baseMapper.selectByQueryParam(param);
|
||||||
|
pqDevList.forEach(pqDev -> {
|
||||||
|
List<PqMonitor> monitorList = pqMonitorService.listPqMonitorByDevIds(Collections.singletonList(pqDev.getId()));
|
||||||
|
List<PqMonitor> enabledMonitorList = monitorList.stream().filter(x -> x.getCheckFlag() == 1).collect(Collectors.toList());
|
||||||
|
pqDev.setMonitorResults(enabledMonitorList.stream().map(x -> {
|
||||||
|
if (ObjectUtil.isNull(x.getResultType())) {
|
||||||
|
return CheckResultEnum.UNCHECKED.getValue();
|
||||||
|
} else {
|
||||||
|
DataSourceEnum dataSourceEnum = DataSourceEnum.ofByValue(x.getResultType());
|
||||||
|
|
||||||
|
switch (dataSourceEnum) {
|
||||||
|
case REAL_DATA:
|
||||||
|
return x.getRealtimeResult();
|
||||||
|
case MINUTE_STATISTICS_AVG:
|
||||||
|
case MINUTE_STATISTICS_CP95:
|
||||||
|
case MINUTE_STATISTICS_MIN:
|
||||||
|
case MINUTE_STATISTICS_MAX:
|
||||||
|
return x.getStatisticsResult();
|
||||||
|
case WAVE_DATA:
|
||||||
|
return x.getRecordedResult();
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return CheckResultEnum.UNCHECKED.getValue();
|
||||||
|
}).collect(Collectors.toList()));
|
||||||
|
});
|
||||||
|
|
||||||
return pqDevList;
|
return pqDevList;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -449,7 +492,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();
|
||||||
@@ -466,7 +509,8 @@ public class PqDevServiceImpl extends ServiceImpl<PqDevMapper, PqDev> implements
|
|||||||
LambdaUpdateWrapper<PqDevSub> wrapper = new LambdaUpdateWrapper<PqDevSub>()
|
LambdaUpdateWrapper<PqDevSub> wrapper = new LambdaUpdateWrapper<PqDevSub>()
|
||||||
.set(PqDevSub::getCheckResult, result.get(pqDevVo.getId()))
|
.set(PqDevSub::getCheckResult, result.get(pqDevVo.getId()))
|
||||||
.set(StrUtil.isNotBlank(userId), PqDevSub::getCheckBy, userId)
|
.set(StrUtil.isNotBlank(userId), PqDevSub::getCheckBy, userId)
|
||||||
.set(PqDevSub::getCheckTime, LocalDateTime.now())
|
.set(updateCheckNum, PqDevSub::getCheckEndTime, LocalDateTime.now())
|
||||||
|
.set(updateCheckNum && ObjectUtil.isNotNull(FormalTestManager.checkStartTime), PqDevSub::getCheckStartTime, FormalTestManager.checkStartTime)
|
||||||
.eq(PqDevSub::getDevId, pqDevVo.getId());
|
.eq(PqDevSub::getDevId, pqDevVo.getId());
|
||||||
String currrentScene = sysTestConfigService.getCurrrentScene();
|
String currrentScene = sysTestConfigService.getCurrrentScene();
|
||||||
if (SceneEnum.PROVINCE_PLATFORM.getValue().equals(currrentScene)) {
|
if (SceneEnum.PROVINCE_PLATFORM.getValue().equals(currrentScene)) {
|
||||||
@@ -481,13 +525,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()));
|
||||||
@@ -529,22 +578,41 @@ public class PqDevServiceImpl extends ServiceImpl<PqDevMapper, PqDev> implements
|
|||||||
PqDev dev = this.getById(devId);
|
PqDev dev = this.getById(devId);
|
||||||
Integer checkState = pqMonitorService.getDevCheckState(devId);
|
Integer checkState = pqMonitorService.getDevCheckState(devId);
|
||||||
Integer checkResult = pqMonitorService.getDevCheckResult(devId);
|
Integer checkResult = pqMonitorService.getDevCheckResult(devId);
|
||||||
|
if (checkResult == 1) {
|
||||||
|
checkResult = CheckResultEnum.ACCORD.getValue();
|
||||||
|
}
|
||||||
|
if (checkResult == 2) {
|
||||||
|
checkResult = CheckResultEnum.NOT_ACCORD.getValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
SysUser user = userService.getById(userId);
|
SysUser user = userService.getById(userId);
|
||||||
|
|
||||||
|
// 查询当前设备的检测时间
|
||||||
|
PqDevSub currentDevSub = pqDevSubService.lambdaQuery()
|
||||||
|
.eq(PqDevSub::getDevId, devId)
|
||||||
|
.one();
|
||||||
|
|
||||||
LambdaUpdateChainWrapper<PqDevSub> w = pqDevSubService.lambdaUpdate()
|
LambdaUpdateChainWrapper<PqDevSub> w = pqDevSubService.lambdaUpdate()
|
||||||
.set(PqDevSub::getCheckState, checkState)
|
.set(PqDevSub::getCheckState, checkState)
|
||||||
.set(PqDevSub::getCheckResult, checkResult)
|
.set(PqDevSub::getCheckResult, checkResult)
|
||||||
.set(PqDevSub::getCheckTime, LocalDateTime.now())
|
.set(PqDevSub::getReportState, DevReportStateEnum.NOT_GENERATED.getValue())
|
||||||
.eq(PqDevSub::getDevId, devId);
|
.eq(PqDevSub::getDevId, devId);
|
||||||
|
|
||||||
if(ObjectUtil.isNotNull(user)){
|
// 只有当checkTime为空时,才设置为当前时间
|
||||||
|
if (currentDevSub != null && currentDevSub.getCheckEndTime() == null) {
|
||||||
|
w.set(PqDevSub::getCheckEndTime, LocalDateTime.now());
|
||||||
|
w.set(ObjectUtil.isNotNull(FormalTestManager.checkStartTime), PqDevSub::getCheckStartTime, currentDevSub.getCheckStartTime());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ObjectUtil.isNotNull(user)) {
|
||||||
w.set(PqDevSub::getCheckBy, user.getName());
|
w.set(PqDevSub::getCheckBy, user.getName());
|
||||||
}
|
}
|
||||||
if(checkState.equals(CheckStateEnum.CHECKED.getValue())){
|
if (checkState.equals(CheckStateEnum.CHECKED.getValue())) {
|
||||||
w.set(PqDevSub::getReportState, DevReportStateEnum.NOT_GENERATED.getValue());
|
w.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();
|
||||||
@@ -552,15 +620,23 @@ public class PqDevServiceImpl extends ServiceImpl<PqDevMapper, PqDev> implements
|
|||||||
List<PqDevVO> pqDevVOList = this.baseMapper.selectByQueryParam(param);
|
List<PqDevVO> pqDevVOList = this.baseMapper.selectByQueryParam(param);
|
||||||
|
|
||||||
if (CollUtil.isNotEmpty(pqDevVOList)) {
|
if (CollUtil.isNotEmpty(pqDevVOList)) {
|
||||||
Set<Integer> set = pqDevVOList.stream().map(PqDevVO::getCheckResult).collect(Collectors.toSet());
|
Set<Integer> set = pqDevVOList.stream().filter(obj -> CheckStateEnum.CHECKED.getValue().equals(obj.getCheckState()) || CheckStateEnum.DOCUMENTED.getValue().equals(obj.getCheckState())).map(PqDevVO::getCheckResult).collect(Collectors.toSet());
|
||||||
if (set.contains(CheckResultEnum.NOT_ACCORD.getValue())) {
|
if (checkState == CheckStateEnum.CHECKED.getValue()) {
|
||||||
this.baseMapper.updatePlanCheckResult(planId, CheckResultEnum.NOT_ACCORD.getValue());
|
set.add(checkResult);
|
||||||
} else if (set.contains(CheckResultEnum.UNCHECKED.getValue())) {
|
}
|
||||||
|
if (CollUtil.isEmpty(set)) {
|
||||||
this.baseMapper.updatePlanCheckResult(planId, CheckResultEnum.UNCHECKED.getValue());
|
this.baseMapper.updatePlanCheckResult(planId, CheckResultEnum.UNCHECKED.getValue());
|
||||||
} else {
|
} else {
|
||||||
this.baseMapper.updatePlanCheckResult(planId, CheckResultEnum.ACCORD.getValue());
|
if (set.contains(CheckResultEnum.NOT_ACCORD.getValue())) {
|
||||||
|
this.baseMapper.updatePlanCheckResult(planId, CheckResultEnum.NOT_ACCORD.getValue());
|
||||||
|
} else if (set.contains(CheckResultEnum.UNCHECKED.getValue())) {
|
||||||
|
this.baseMapper.updatePlanCheckResult(planId, CheckResultEnum.UNCHECKED.getValue());
|
||||||
|
} else {
|
||||||
|
this.baseMapper.updatePlanCheckResult(planId, CheckResultEnum.ACCORD.getValue());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
set = pqDevVOList.stream().map(PqDevVO::getCheckState).collect(Collectors.toSet());
|
set = pqDevVOList.stream().map(PqDevVO::getCheckState).collect(Collectors.toSet());
|
||||||
if (set.contains(CheckStateEnum.UNCHECKED.getValue())) {
|
if (set.contains(CheckStateEnum.UNCHECKED.getValue())) {
|
||||||
this.baseMapper.updatePlanTestState(planId, CheckStateEnum.CHECKING.getValue());
|
this.baseMapper.updatePlanTestState(planId, CheckStateEnum.CHECKING.getValue());
|
||||||
@@ -572,6 +648,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<>();
|
||||||
@@ -643,25 +750,31 @@ public class PqDevServiceImpl extends ServiceImpl<PqDevMapper, PqDev> implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean importDev(MultipartFile file, String patternId, String planId, HttpServletResponse response) {
|
public HttpResult importDev(MultipartFile file, String patternId, String planId, HttpServletResponse response, Integer cover) {
|
||||||
DictData dictData = dictDataService.getDictDataById(patternId);
|
DictData dictData = dictDataService.getDictDataById(patternId);
|
||||||
if (PatternEnum.CONTRAST.getValue().equals(dictData.getCode())) {
|
if (PatternEnum.CONTRAST.getValue().equals(dictData.getCode())) {
|
||||||
return this.importContrastDev(file, patternId, planId, response);
|
return this.importContrastDev(file, patternId, planId, response, cover);
|
||||||
} else {
|
} else {
|
||||||
String currrentScene = sysTestConfigService.getCurrrentScene();
|
String currrentScene = sysTestConfigService.getCurrrentScene();
|
||||||
SceneEnum sceneEnum = SceneEnum.getSceneEnum(currrentScene);
|
SceneEnum sceneEnum = SceneEnum.getSceneEnum(currrentScene);
|
||||||
switch (sceneEnum) {
|
switch (sceneEnum) {
|
||||||
case PROVINCE_PLATFORM:
|
case PROVINCE_PLATFORM:
|
||||||
return this.importProvinceDev(file, patternId, planId, response);
|
boolean result = this.importProvinceDev(file, patternId, planId, response);
|
||||||
|
if (result) {
|
||||||
|
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, "导入成功");
|
||||||
|
}
|
||||||
case LEAVE_FACTORY_TEST:
|
case LEAVE_FACTORY_TEST:
|
||||||
return this.importCNDev(file, patternId, planId, response);
|
result = this.importCNDev(file, patternId, planId, response);
|
||||||
|
if (result) {
|
||||||
|
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, "导入成功");
|
||||||
|
}
|
||||||
case SELF_TEST:
|
case SELF_TEST:
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, false, "导入失败");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -788,21 +901,15 @@ public class PqDevServiceImpl extends ServiceImpl<PqDevMapper, PqDev> implements
|
|||||||
* @param isExcludeSelf 是否排除自己
|
* @param isExcludeSelf 是否排除自己
|
||||||
*/
|
*/
|
||||||
private void checkRepeat(PqDevParam param, boolean isExcludeSelf) {
|
private void checkRepeat(PqDevParam param, boolean isExcludeSelf) {
|
||||||
QueryWrapper<PqDev> queryWrapper = new QueryWrapper<>();
|
LambdaQueryWrapper<PqDev> queryWrapper = new LambdaQueryWrapper<PqDev>()
|
||||||
queryWrapper
|
.eq(PqDev::getState, DataStateEnum.ENABLE.getCode())
|
||||||
.eq("state", DataStateEnum.ENABLE.getCode())
|
.eq(StrUtil.isNotBlank(param.getIp()), PqDev::getIp, param.getIp())
|
||||||
.eq(StrUtil.isNotBlank(param.getDevType()), "Dev_Type", param.getDevType())
|
.eq(ObjectUtil.isNotNull(param.getPort()), PqDev::getPort, param.getPort())
|
||||||
.eq(StrUtil.isNotBlank(param.getPattern()), "pattern", param.getPattern())
|
.eq(StrUtil.isNotBlank(param.getPattern()), PqDev::getPattern, param.getPattern())
|
||||||
.eq(StrUtil.isNotBlank(param.getCityName()), "City_Name", param.getCityName())
|
.eq(StrUtil.isNotBlank(param.getCreateId()), PqDev::getCreateId, param.getCreateId());
|
||||||
.eq(StrUtil.isNotBlank(param.getGdName()), "Gd_Name", param.getGdName())
|
|
||||||
.eq(StrUtil.isNotBlank(param.getSubName()), "Sub_Name", param.getSubName())
|
|
||||||
.and(q -> q.eq(StrUtil.isNotBlank(param.getName()), "name", param.getName()).or()
|
|
||||||
.eq(StrUtil.isNotBlank(param.getCreateId()), "Create_Id", param.getCreateId())); //设备序列号重复
|
|
||||||
// .eq("manufacturer", param.getManufacturer())
|
|
||||||
// .eq("Dev_Type", param.getDevType()).or()
|
|
||||||
if (isExcludeSelf) {
|
if (isExcludeSelf) {
|
||||||
if (param instanceof PqDevParam.UpdateParam) {
|
if (param instanceof PqDevParam.UpdateParam) {
|
||||||
queryWrapper.ne("id", ((PqDevParam.UpdateParam) param).getId());
|
queryWrapper.ne(PqDev::getId, ((PqDevParam.UpdateParam) param).getId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
int count = this.count(queryWrapper);
|
int count = this.count(queryWrapper);
|
||||||
@@ -1181,7 +1288,7 @@ public class PqDevServiceImpl extends ServiceImpl<PqDevMapper, PqDev> implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean importContrastDev(MultipartFile file, String patternId, String planId, HttpServletResponse response) {
|
public HttpResult importContrastDev(MultipartFile file, String patternId, String planId, HttpServletResponse response, Integer cover) {
|
||||||
ImportParams params = new ImportParams();
|
ImportParams params = new ImportParams();
|
||||||
params.setStartSheetIndex(0);
|
params.setStartSheetIndex(0);
|
||||||
params.setSheetNum(1);
|
params.setSheetNum(1);
|
||||||
@@ -1201,52 +1308,56 @@ public class PqDevServiceImpl extends ServiceImpl<PqDevMapper, PqDev> implements
|
|||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new BusinessException(DetectionResponseEnum.IMPORT_DATA_FAIL);
|
throw new BusinessException(DetectionResponseEnum.IMPORT_DATA_FAIL);
|
||||||
}
|
}
|
||||||
return this.importContrastDev(contrastDevExcelList, patternId, planId);
|
return this.importContrastDev(contrastDevExcelList, patternId, planId, cover);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional
|
@Transactional
|
||||||
public boolean importContrastDev(List<ContrastDevExcel> contrastDevExcelList, String patternId, String planId) {
|
public HttpResult importContrastDev(List<ContrastDevExcel> contrastDevExcelList, String patternId, String planId, Integer cover) {
|
||||||
if (CollUtil.isNotEmpty(contrastDevExcelList)) {
|
if (CollUtil.isNotEmpty(contrastDevExcelList)) {
|
||||||
// 根据设备名称分组
|
// 根据设备名称分组
|
||||||
Map<String, List<ContrastDevExcel>> listMap = contrastDevExcelList.stream()
|
Map<String, List<ContrastDevExcel>> listMap = contrastDevExcelList.stream()
|
||||||
.collect(Collectors.groupingBy(ContrastDevExcel::getName, LinkedHashMap::new, Collectors.toList()));
|
.collect(Collectors.groupingBy(ContrastDevExcel::getName, LinkedHashMap::new, Collectors.toList()));
|
||||||
List<PqDev> oldDevList = new ArrayList<>(listMap.size());
|
List<PqDev> newDevList = new ArrayList<>(listMap.size());
|
||||||
List<PqMonitor> finalMonitorList = new ArrayList<>();
|
List<PqDev> updateDevList = new ArrayList<>();
|
||||||
|
List<PqDev> finalUpdateDevList = new ArrayList<>();
|
||||||
for (Map.Entry<String, List<ContrastDevExcel>> entry : listMap.entrySet()) {
|
for (Map.Entry<String, List<ContrastDevExcel>> entry : listMap.entrySet()) {
|
||||||
String name = entry.getKey();
|
String name = entry.getKey();
|
||||||
|
|
||||||
List<ContrastDevExcel> devExcelList = entry.getValue();
|
List<ContrastDevExcel> devExcelList = entry.getValue();
|
||||||
// 监测点数据
|
// 监测点数据
|
||||||
List<PqMonitorExcel> pqMonitorExcelList = devExcelList.stream()
|
List<PqMonitorExcel> pqMonitorExcelList = devExcelList.stream()
|
||||||
.map(ContrastDevExcel::getPqMonitorExcelList)
|
.map(ContrastDevExcel::getPqMonitorExcelList)
|
||||||
.filter(Objects::nonNull)
|
.filter(Objects::nonNull)
|
||||||
.flatMap(List::stream)
|
.flatMap(List::stream)
|
||||||
|
// 过滤掉没有线路号的数据
|
||||||
|
.filter(item -> ObjectUtil.isNotNull(item.getNum()))
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
// 取第一条为设备基本信息
|
// 取第一条为设备基本信息
|
||||||
ContrastDevExcel devExcel = devExcelList.get(0);
|
ContrastDevExcel devExcel = devExcelList.get(0);
|
||||||
PqDev pqDev = BeanUtil.copyProperties(devExcel, PqDev.class);
|
PqDev importPqDev = BeanUtil.copyProperties(devExcel, PqDev.class);
|
||||||
if (pqDev.getEncryptionFlag() == 1) {
|
if (importPqDev.getEncryptionFlag() == 1) {
|
||||||
if (StrUtil.isNotBlank(pqDev.getSeries()) && StrUtil.isNotBlank(pqDev.getDevKey())) {
|
if (StrUtil.isNotBlank(importPqDev.getSeries()) && StrUtil.isNotBlank(importPqDev.getDevKey())) {
|
||||||
pqDev.setSeries(EncryptionUtil.encodeString(1, pqDev.getSeries()));
|
importPqDev.setSeries(EncryptionUtil.encodeString(1, importPqDev.getSeries()));
|
||||||
pqDev.setDevKey(EncryptionUtil.encodeString(1, pqDev.getDevKey()));
|
importPqDev.setDevKey(EncryptionUtil.encodeString(1, importPqDev.getDevKey()));
|
||||||
} else {
|
} else {
|
||||||
throw new BusinessException(DetectionResponseEnum.SERIES_AND_DEVKEY_NOT_BLANK);
|
throw new BusinessException(DetectionResponseEnum.SERIES_AND_DEVKEY_NOT_BLANK);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
DevType devType = devTypeService.getByName(pqDev.getDevType());
|
DevType devType = devTypeService.getByName(importPqDev.getDevType());
|
||||||
if (ObjectUtil.isNull(devType)) {
|
if (ObjectUtil.isNull(devType)) {
|
||||||
throw new BusinessException(DetectionResponseEnum.DEV_TYPE_NOT_EXIST);
|
throw new BusinessException(DetectionResponseEnum.DEV_TYPE_NOT_EXIST);
|
||||||
}
|
}
|
||||||
// 校验监测点数量
|
// 校验监测点数量
|
||||||
int devChns = devType.getDevChns();
|
int devChns = devType.getDevChns();
|
||||||
if (pqMonitorExcelList.size() != devChns) {
|
// if (pqMonitorExcelList.size() != devChns) {
|
||||||
throw new BusinessException(DetectionResponseEnum.IMPORT_DATA_FAIL, "【" + name + "】的设备类型必须具备" + devChns + "个监测点信息!");
|
// throw new BusinessException(DetectionResponseEnum.IMPORT_DATA_FAIL, "【" + name + "】的设备类型必须具备" + devChns + "个监测点信息!");
|
||||||
}
|
// }
|
||||||
List<Integer> numList = pqMonitorExcelList.stream().map(PqMonitorExcel::getNum).collect(Collectors.toList());
|
List<Integer> numList = pqMonitorExcelList.stream().map(PqMonitorExcel::getNum).collect(Collectors.toList());
|
||||||
// 判断是否有重复的num
|
// 判断是否有重复的num
|
||||||
Set<Integer> uniqueNumSet = new HashSet<>(numList);
|
Set<Integer> uniqueNumSet = new HashSet<>(numList);
|
||||||
if (uniqueNumSet.size() != numList.size()) {
|
if (uniqueNumSet.size() != numList.size()) {
|
||||||
throw new BusinessException(DetectionResponseEnum.MONITOR_NUM_REPEAT);
|
throw new BusinessException(DetectionResponseEnum.MONITOR_NUM_REPEAT, "【" + name + "】该被检设备下存在相同线路号的监测点!");
|
||||||
}
|
}
|
||||||
Integer max = CollectionUtil.max(numList);
|
Integer max = CollectionUtil.max(numList);
|
||||||
Integer min = CollectionUtil.min(numList);
|
Integer min = CollectionUtil.min(numList);
|
||||||
@@ -1254,90 +1365,144 @@ public class PqDevServiceImpl extends ServiceImpl<PqDevMapper, PqDev> implements
|
|||||||
throw new BusinessException(DetectionResponseEnum.MONITOR_NUM_OUT_OF_RANGE);
|
throw new BusinessException(DetectionResponseEnum.MONITOR_NUM_OUT_OF_RANGE);
|
||||||
}
|
}
|
||||||
|
|
||||||
pqDev.setDevType(devType.getId());
|
importPqDev.setDevType(devType.getId());
|
||||||
pqDev.setImportFlag(1);
|
importPqDev.setImportFlag(1);
|
||||||
pqDev.setId(UUID.randomUUID().toString().replaceAll("-", ""));
|
importPqDev.setId(UUID.randomUUID().toString().replaceAll("-", ""));
|
||||||
pqDev.setCreateId(pqDev.getName()); //导入时设备序列号默认与设备名称相同
|
|
||||||
List<PqMonitor> monitorList = new ArrayList<>();
|
if (StrUtil.isEmpty(importPqDev.getCreateId())) {
|
||||||
|
// 与设备名称相同
|
||||||
|
importPqDev.setCreateId(importPqDev.getName());
|
||||||
|
}
|
||||||
// 根据num排序
|
// 根据num排序
|
||||||
pqMonitorExcelList.sort(Comparator.comparingInt(PqMonitorExcel::getNum));
|
pqMonitorExcelList.sort(Comparator.comparingInt(PqMonitorExcel::getNum));
|
||||||
for (PqMonitorExcel pqMonitorExcel : pqMonitorExcelList) {
|
|
||||||
PqMonitor monitor = BeanUtil.copyProperties(pqMonitorExcel, PqMonitor.class);
|
|
||||||
monitor.setDevId(pqDev.getId());
|
|
||||||
monitorList.add(monitor);
|
|
||||||
}
|
|
||||||
StringBuilder inspectChannelBuilder = new StringBuilder();
|
StringBuilder inspectChannelBuilder = new StringBuilder();
|
||||||
for (int i = 1; i <= devChns; i++) {
|
for (int i = 0; i < numList.size(); i++) {
|
||||||
inspectChannelBuilder.append(i);
|
inspectChannelBuilder.append(numList.get(i));
|
||||||
if (i < devChns) {
|
if (i < numList.size() - 1) {
|
||||||
inspectChannelBuilder.append(",");
|
inspectChannelBuilder.append(StrUtil.COMMA);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pqDev.setInspectChannel(inspectChannelBuilder.toString());
|
importPqDev.setInspectChannel(inspectChannelBuilder.toString());
|
||||||
oldDevList.add(pqDev);
|
List<PqMonitor> monitorList = new ArrayList<>();
|
||||||
finalMonitorList.addAll(monitorList);
|
// 1、先判断是否有谐波系统ID
|
||||||
}
|
boolean hasHarmSys = false;
|
||||||
//逆向可视化
|
if (StrUtil.isNotBlank(importPqDev.getHarmSysId())) {
|
||||||
this.reverseVisualizeProvinceDev(oldDevList, patternId);
|
// 1.1、如果有则判断是否已存在
|
||||||
|
List<PqDev> hasList = this.lambdaQuery()
|
||||||
List<PqDev> newDevList = new ArrayList<>();
|
.eq(PqDev::getState, DataStateEnum.ENABLE.getCode())
|
||||||
oldDevList.forEach(pqDev -> {
|
.eq(PqDev::getPattern, patternId)
|
||||||
PqDevParam param = BeanUtil.copyProperties(pqDev, PqDevParam.class);
|
.eq(PqDev::getHarmSysId, importPqDev.getHarmSysId())
|
||||||
this.checkRepeat(param, false);
|
.isNull(PqDev::getPlanId)
|
||||||
long count = newDevList.stream().filter(dev ->
|
.orderByDesc(PqDev::getCreateTime).list();
|
||||||
dev.getDevType().equals(pqDev.getDevType())
|
// 1.2、 存在则放入强制更新list
|
||||||
&& dev.getCityName().equals(pqDev.getCityName())
|
if (CollUtil.isNotEmpty(hasList)) {
|
||||||
&& dev.getGdName().equals(pqDev.getGdName())
|
importPqDev.setId(hasList.get(0).getId());
|
||||||
&& dev.getSubName().equals(pqDev.getSubName())
|
for (PqMonitorExcel pqMonitorExcel : pqMonitorExcelList) {
|
||||||
&& (dev.getName().equals(pqDev.getName()) || dev.getCreateId().equals(pqDev.getCreateId())))
|
PqMonitor monitor = BeanUtil.copyProperties(pqMonitorExcel, PqMonitor.class);
|
||||||
.count();
|
monitor.setDevId(importPqDev.getId());
|
||||||
if (count == 0) {
|
monitor.setPt(pqMonitorExcel.getPt1() + StrUtil.C_COLON + pqMonitorExcel.getPt2());
|
||||||
pqDev.setPlanId(planId);
|
monitor.setCt(pqMonitorExcel.getCt1() + StrUtil.C_COLON + pqMonitorExcel.getCt2());
|
||||||
newDevList.add(pqDev);
|
monitorList.add(monitor);
|
||||||
}
|
}
|
||||||
});
|
importPqDev.setMonitorList(monitorList);
|
||||||
QueryWrapper<PqDev> wrapper1 = new QueryWrapper<PqDev>()
|
finalUpdateDevList.add(importPqDev);
|
||||||
.eq("pq_dev.State", DataStateEnum.ENABLE.getCode())
|
hasHarmSys = true;
|
||||||
.in("pq_dev.Harm_Sys_Id", newDevList.stream().map(PqDev::getHarmSysId).collect(Collectors.toList()));
|
|
||||||
List<PqDev> oldDevList1 = this.list(wrapper1);
|
|
||||||
if (CollUtil.isNotEmpty(oldDevList1)) {
|
|
||||||
oldDevList1.stream().forEach(oldDev -> {
|
|
||||||
PqDev newDev = newDevList.stream().filter(dev -> dev.getHarmSysId().equals(oldDev.getHarmSysId())).findFirst().orElse(null);
|
|
||||||
if (ObjectUtil.isNotNull(newDev)) {
|
|
||||||
newDevList.remove(newDev);
|
|
||||||
finalMonitorList.stream()
|
|
||||||
.filter(monitor -> monitor.getDevId().equals(newDev.getId()))
|
|
||||||
.forEach(monitor -> monitor.setDevId(oldDev.getId()));
|
|
||||||
BeanUtil.copyProperties(newDev, oldDev, "id");
|
|
||||||
}
|
}
|
||||||
});
|
|
||||||
this.updateBatchById(oldDevList1);
|
|
||||||
}
|
|
||||||
this.saveBatch(newDevList);
|
|
||||||
List<PqDevSub> pqDevSubList = new ArrayList<>();
|
|
||||||
for (PqDev dev : newDevList) {
|
|
||||||
PqDevSub pqDevSub = new PqDevSub();
|
|
||||||
pqDevSub.setDevId(dev.getId());
|
|
||||||
pqDevSub.setCheckState(CheckStateEnum.UNCHECKED.getValue());
|
|
||||||
pqDevSub.setCheckResult(CheckResultEnum.UNCHECKED.getValue());
|
|
||||||
pqDevSub.setReportState(DevReportStateEnum.UNCHECKED.getValue());
|
|
||||||
pqDevSub.setTimeCheckResult(TimeCheckResultEnum.UNKNOWN.getValue());
|
|
||||||
pqDevSub.setFactorCheckResult(FactorCheckResultEnum.UNKNOWN.getValue());
|
|
||||||
pqDevSubList.add(pqDevSub);
|
|
||||||
}
|
|
||||||
pqDevSubService.saveBatch(pqDevSubList);
|
|
||||||
|
|
||||||
List<String> devIdList = oldDevList1.stream().map(PqDev::getId).collect(Collectors.toList());
|
}
|
||||||
if (CollUtil.isNotEmpty(devIdList)) {
|
if (!hasHarmSys) {
|
||||||
QueryWrapper<PqMonitor> wrapper = new QueryWrapper<PqMonitor>()
|
// 2、查询 ip + 端口 + 序列号 + patternId + Plan_Id为空 是否存在
|
||||||
.in("pq_monitor.Dev_Id", devIdList);
|
List<PqDev> hasList = this.lambdaQuery()
|
||||||
pqMonitorService.remove(wrapper);
|
.eq(PqDev::getState, DataStateEnum.ENABLE.getCode())
|
||||||
|
.eq(PqDev::getIp, devExcel.getIp())
|
||||||
|
.eq(PqDev::getPort, devExcel.getPort())
|
||||||
|
.eq(PqDev::getPattern, patternId)
|
||||||
|
.eq(PqDev::getCreateId, devExcel.getCreateId())
|
||||||
|
.isNull(PqDev::getPlanId)
|
||||||
|
.orderByDesc(PqDev::getCreateTime).list();
|
||||||
|
// 2.1、存在则放入更新list
|
||||||
|
if (CollUtil.isNotEmpty(hasList)) {
|
||||||
|
importPqDev.setId(hasList.get(0).getId());
|
||||||
|
for (PqMonitorExcel pqMonitorExcel : pqMonitorExcelList) {
|
||||||
|
PqMonitor monitor = BeanUtil.copyProperties(pqMonitorExcel, PqMonitor.class);
|
||||||
|
monitor.setDevId(importPqDev.getId());
|
||||||
|
monitor.setPt(pqMonitorExcel.getPt1() + StrUtil.C_COLON + pqMonitorExcel.getPt2());
|
||||||
|
monitor.setCt(pqMonitorExcel.getCt1() + StrUtil.C_COLON + pqMonitorExcel.getCt2());
|
||||||
|
monitorList.add(monitor);
|
||||||
|
}
|
||||||
|
importPqDev.setMonitorList(monitorList);
|
||||||
|
updateDevList.add(importPqDev);
|
||||||
|
} else {
|
||||||
|
//2.2、不存在则放入新增list
|
||||||
|
for (PqMonitorExcel pqMonitorExcel : pqMonitorExcelList) {
|
||||||
|
PqMonitor monitor = BeanUtil.copyProperties(pqMonitorExcel, PqMonitor.class);
|
||||||
|
monitor.setDevId(importPqDev.getId());
|
||||||
|
monitor.setPt(pqMonitorExcel.getPt1() + StrUtil.C_COLON + pqMonitorExcel.getPt2());
|
||||||
|
monitor.setCt(pqMonitorExcel.getCt1() + StrUtil.C_COLON + pqMonitorExcel.getCt2());
|
||||||
|
monitorList.add(monitor);
|
||||||
|
}
|
||||||
|
importPqDev.setMonitorList(monitorList);
|
||||||
|
newDevList.add(importPqDev);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
pqMonitorService.reverseVisualizeMonitor(finalMonitorList);
|
// 3、是否有重复的设备
|
||||||
pqMonitorService.saveBatch(finalMonitorList);
|
if (CollUtil.isNotEmpty(updateDevList)) {
|
||||||
return true;
|
// 3.1、有则让用户确认是否覆盖
|
||||||
|
if (cover == 0) {
|
||||||
|
List<String> existDevList = new ArrayList<>();
|
||||||
|
updateDevList.forEach(pqDev -> {
|
||||||
|
existDevList.add(pqDev.getName() + "(" + pqDev.getIp() + ":" + pqDev.getPort() + ")");
|
||||||
|
});
|
||||||
|
return HttpResultUtil.assembleResult(DetectionResponseEnum.DEV_IP_PORT_EXIST.getCode(), existDevList, "请确认是否覆盖");
|
||||||
|
|
||||||
|
} else {
|
||||||
|
// 3.2、确认覆盖则放入强制更新list
|
||||||
|
finalUpdateDevList.addAll(updateDevList);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// 4、新增list
|
||||||
|
if (CollUtil.isNotEmpty(newDevList)) {
|
||||||
|
//逆向可视化
|
||||||
|
this.reverseVisualizeProvinceDev(newDevList, patternId);
|
||||||
|
this.saveBatch(newDevList);
|
||||||
|
List<PqDevSub> pqDevSubList = new ArrayList<>();
|
||||||
|
List<PqMonitor> newMonitorList = new ArrayList<>();
|
||||||
|
for (PqDev dev : newDevList) {
|
||||||
|
PqDevSub pqDevSub = new PqDevSub();
|
||||||
|
pqDevSub.setDevId(dev.getId());
|
||||||
|
pqDevSub.setCheckState(CheckStateEnum.UNCHECKED.getValue());
|
||||||
|
pqDevSub.setCheckResult(CheckResultEnum.UNCHECKED.getValue());
|
||||||
|
pqDevSub.setReportState(DevReportStateEnum.UNCHECKED.getValue());
|
||||||
|
pqDevSub.setTimeCheckResult(TimeCheckResultEnum.UNKNOWN.getValue());
|
||||||
|
pqDevSub.setFactorCheckResult(FactorCheckResultEnum.UNKNOWN.getValue());
|
||||||
|
pqDevSubList.add(pqDevSub);
|
||||||
|
newMonitorList.addAll(dev.getMonitorList());
|
||||||
|
}
|
||||||
|
pqMonitorService.reverseVisualizeMonitor(newMonitorList);
|
||||||
|
pqMonitorService.saveBatch(newMonitorList);
|
||||||
|
pqDevSubService.saveBatch(pqDevSubList);
|
||||||
|
}
|
||||||
|
// 5、更新list
|
||||||
|
if (CollUtil.isNotEmpty(finalUpdateDevList)) {
|
||||||
|
//逆向可视化
|
||||||
|
this.reverseVisualizeProvinceDev(finalUpdateDevList, patternId);
|
||||||
|
this.updateBatchById(finalUpdateDevList);
|
||||||
|
List<PqMonitor> updateMonitorList = new ArrayList<>();
|
||||||
|
for (PqDev dev : finalUpdateDevList) {
|
||||||
|
updateMonitorList.addAll(dev.getMonitorList());
|
||||||
|
}
|
||||||
|
pqMonitorService.reverseVisualizeMonitor(updateMonitorList);
|
||||||
|
for (PqMonitor monitor : updateMonitorList) {
|
||||||
|
pqMonitorService.update(monitor, new LambdaUpdateWrapper<PqMonitor>().eq(PqMonitor::getDevId, monitor.getDevId()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, "导入成功");
|
||||||
}
|
}
|
||||||
return false;
|
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, false, "导入失败");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -1395,13 +1560,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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1463,7 +1634,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);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -1496,4 +1682,11 @@ public class PqDevServiceImpl extends ServiceImpl<PqDevMapper, PqDev> implements
|
|||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public DataCheckResDTO getDataCheckRes(String monitorId) {
|
||||||
|
// restTemplateUtil.postJson();
|
||||||
|
DataCheckResDTO dataCheckResDTO = restTemplateUtil.postJson("http://localhost:8080/api/v1/dataCheck/getDataCheckRes", monitorId, DataCheckResDTO.class);
|
||||||
|
return dataCheckResDTO;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,45 @@
|
|||||||
|
package com.njcn.gather.device.service.impl;
|
||||||
|
|
||||||
|
import cn.hutool.core.collection.CollectionUtil;
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.njcn.gather.device.mapper.PqStandardDevGainRecordMapper;
|
||||||
|
import com.njcn.gather.device.pojo.po.PqStandardDevGainRecord;
|
||||||
|
import com.njcn.gather.device.service.IPqStandardDevGainRecordService;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author caozehui
|
||||||
|
* @date 2026-01-15
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@Service
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class PqStandardDevGainRecordServiceImpl extends ServiceImpl<PqStandardDevGainRecordMapper, PqStandardDevGainRecord> implements IPqStandardDevGainRecordService {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getMaxNum(String stdDevMonitorId, String devMonitorId) {
|
||||||
|
return this.lambdaQuery().eq(PqStandardDevGainRecord::getStdDevMonitorId, stdDevMonitorId)
|
||||||
|
.eq(PqStandardDevGainRecord::getDevMonitorId, devMonitorId)
|
||||||
|
.list().stream().mapToInt(PqStandardDevGainRecord::getNum).max().orElse(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean addOrUpdate(List<PqStandardDevGainRecord> recordList) {
|
||||||
|
recordList.forEach(record -> {
|
||||||
|
List<PqStandardDevGainRecord> list = this.lambdaQuery().eq(PqStandardDevGainRecord::getStdDevMonitorId, record.getStdDevMonitorId())
|
||||||
|
.eq(PqStandardDevGainRecord::getDevMonitorId, record.getDevMonitorId()).list();
|
||||||
|
if (CollectionUtil.isNotEmpty(list)) {
|
||||||
|
this.lambdaUpdate().eq(PqStandardDevGainRecord::getStdDevMonitorId, record.getStdDevMonitorId())
|
||||||
|
.eq(PqStandardDevGainRecord::getDevMonitorId, record.getDevMonitorId())
|
||||||
|
.set(PqStandardDevGainRecord::getNum, record.getNum()).update();
|
||||||
|
} else {
|
||||||
|
this.save(record);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
package com.njcn.gather.device.service.impl;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.njcn.gather.device.mapper.PqStandardDevGainMapper;
|
||||||
|
import com.njcn.gather.device.pojo.po.PqStandardDevGain;
|
||||||
|
import com.njcn.gather.device.service.IPqStandardDevGainService;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author caozehui
|
||||||
|
* @date 2026-01-12
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@Service
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class PqStandardDevGainServiceImpl extends ServiceImpl<PqStandardDevGainMapper, PqStandardDevGain> implements IPqStandardDevGainService {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean add(List<PqStandardDevGain> pqStandardDevGainList) {
|
||||||
|
log.info("add PqStandardDevGainList: {}", pqStandardDevGainList.size());
|
||||||
|
List<String> stdMonitorIdList = pqStandardDevGainList.stream().map(PqStandardDevGain::getStdDevMonitorId).distinct().collect(Collectors.toList());
|
||||||
|
List<String> existingStdMonitorIdList = this.listByIds(stdMonitorIdList).stream().map(PqStandardDevGain::getStdDevMonitorId).collect(Collectors.toList());
|
||||||
|
|
||||||
|
pqStandardDevGainList = pqStandardDevGainList.stream().filter(pqStandardDevGain -> !existingStdMonitorIdList.contains(pqStandardDevGain.getStdDevMonitorId())).collect(Collectors.toList());
|
||||||
|
return this.saveBatch(pqStandardDevGainList);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PqStandardDevGain get(String stdDevMonitorId) {
|
||||||
|
return this.lambdaQuery().eq(PqStandardDevGain::getStdDevMonitorId, stdDevMonitorId).one();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<PqStandardDevGain> list(String stdDevId) {
|
||||||
|
return this.lambdaQuery().likeRight(PqStandardDevGain::getStdDevMonitorId, stdDevId).orderByAsc(PqStandardDevGain::getStdDevMonitorId).list();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -8,7 +8,6 @@ import cn.hutool.core.bean.BeanUtil;
|
|||||||
import cn.hutool.core.collection.CollectionUtil;
|
import cn.hutool.core.collection.CollectionUtil;
|
||||||
import cn.hutool.core.util.ObjectUtil;
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import cn.hutool.extra.spring.SpringUtil;
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
@@ -18,17 +17,15 @@ import com.njcn.common.pojo.exception.BusinessException;
|
|||||||
import com.njcn.common.pojo.poi.PullDown;
|
import com.njcn.common.pojo.poi.PullDown;
|
||||||
import com.njcn.common.utils.EncryptionUtil;
|
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.enums.CheckStateEnum;
|
|
||||||
import com.njcn.gather.device.pojo.enums.CommonEnum;
|
|
||||||
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.pojo.po.AdPlan;
|
|
||||||
import com.njcn.gather.plan.pojo.po.AdPlanStandardDev;
|
|
||||||
import com.njcn.gather.plan.service.IAdPlanService;
|
|
||||||
import com.njcn.gather.plan.service.IAdPlanStandardDevService;
|
import com.njcn.gather.plan.service.IAdPlanStandardDevService;
|
||||||
import com.njcn.gather.pojo.enums.DetectionResponseEnum;
|
import com.njcn.gather.pojo.enums.DetectionResponseEnum;
|
||||||
import com.njcn.gather.system.dictionary.pojo.po.DictData;
|
import com.njcn.gather.system.dictionary.pojo.po.DictData;
|
||||||
@@ -64,8 +61,7 @@ public class PqStandardDevServiceImpl extends ServiceImpl<PqStandardDevMapper, P
|
|||||||
private final IDevTypeService devTypeService;
|
private final 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,18 +69,23 @@ public class PqStandardDevServiceImpl extends ServiceImpl<PqStandardDevMapper, P
|
|||||||
wrapper.like(StrUtil.isNotBlank(queryParam.getName()), "name", queryParam.getName())
|
wrapper.like(StrUtil.isNotBlank(queryParam.getName()), "name", queryParam.getName())
|
||||||
.eq(StrUtil.isNotBlank(queryParam.getManufacturer()), "manufacturer", queryParam.getManufacturer())
|
.eq(StrUtil.isNotBlank(queryParam.getManufacturer()), "manufacturer", queryParam.getManufacturer())
|
||||||
.eq(StrUtil.isNotBlank(queryParam.getDevType()), "dev_type", queryParam.getDevType())
|
.eq(StrUtil.isNotBlank(queryParam.getDevType()), "dev_type", queryParam.getDevType())
|
||||||
.eq("state", DataStateEnum.ENABLE.getCode());
|
.eq("state", DataStateEnum.ENABLE.getCode())
|
||||||
|
.orderByDesc("create_time");
|
||||||
return this.page(new Page<>(PageFactory.getPageNum(queryParam), PageFactory.getPageSize(queryParam)), wrapper);
|
return this.page(new Page<>(PageFactory.getPageNum(queryParam), PageFactory.getPageSize(queryParam)), wrapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
@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
|
||||||
@@ -159,10 +160,10 @@ public class PqStandardDevServiceImpl extends ServiceImpl<PqStandardDevMapper, P
|
|||||||
this.importData(contrastDevExcelList);
|
this.importData(contrastDevExcelList);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
// @Override
|
||||||
public List<PqStandardDev> listByPlanId(String planId) {
|
// public List<PqStandardDev> listByPlanId(String planId) {
|
||||||
return adPlanStandardDevMapper.listByPlanId(Collections.singletonList(planId));
|
// return adPlanStandardDevMapper.listByPlanId(Collections.singletonList(planId));
|
||||||
}
|
// }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<PreDetection> listStandardDevPreDetection(List<String> ids) {
|
public List<PreDetection> listStandardDevPreDetection(List<String> ids) {
|
||||||
@@ -311,7 +312,7 @@ public class PqStandardDevServiceImpl extends ServiceImpl<PqStandardDevMapper, P
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<PqStandardDev> canBindingList() {
|
public List<PqStandardDev> canBindingList() {
|
||||||
List<String> excludeStandardDevIds = new ArrayList<>();
|
/*List<String> excludeStandardDevIds = new ArrayList<>();
|
||||||
// 获取所有已绑定的标准设备
|
// 获取所有已绑定的标准设备
|
||||||
List<AdPlanStandardDev> boundList = adPlanStandardDevService.list();
|
List<AdPlanStandardDev> boundList = adPlanStandardDevService.list();
|
||||||
if (CollectionUtil.isNotEmpty(boundList)) {
|
if (CollectionUtil.isNotEmpty(boundList)) {
|
||||||
@@ -350,13 +351,13 @@ public class PqStandardDevServiceImpl extends ServiceImpl<PqStandardDevMapper, P
|
|||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
excludeStandardDevIds = excludeBoundList.stream().map(AdPlanStandardDev::getStandardDevId).collect(Collectors.toList());
|
excludeStandardDevIds = excludeBoundList.stream().map(AdPlanStandardDev::getStandardDevId).collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
List<PqStandardDev> list = this.lambdaQuery()
|
List<PqStandardDev> list = this.lambdaQuery()
|
||||||
.eq(PqStandardDev::getState, DataStateEnum.ENABLE.getCode())
|
.eq(PqStandardDev::getState, DataStateEnum.ENABLE.getCode())
|
||||||
.list();
|
.list();
|
||||||
for (PqStandardDev pqStandardDev : list) {
|
/*for (PqStandardDev pqStandardDev : list) {
|
||||||
pqStandardDev.setDisabled(excludeStandardDevIds.contains(pqStandardDev.getId()));
|
pqStandardDev.setDisabled(excludeStandardDevIds.contains(pqStandardDev.getId()));
|
||||||
}
|
}*/
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
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.detection.pojo.enums.DetectionCodeEnum;
|
||||||
import com.njcn.gather.err.mapper.PqErrSysMapper;
|
import com.njcn.gather.err.mapper.PqErrSysMapper;
|
||||||
import com.njcn.gather.err.pojo.param.PqErrSysDtlsParam;
|
import com.njcn.gather.err.pojo.param.PqErrSysDtlsParam;
|
||||||
import com.njcn.gather.err.pojo.param.PqErrSysParam;
|
import com.njcn.gather.err.pojo.param.PqErrSysParam;
|
||||||
@@ -18,6 +19,7 @@ import com.njcn.gather.err.pojo.vo.PqErrSysDtlsVO;
|
|||||||
import com.njcn.gather.err.service.IPqErrSysDtlsService;
|
import com.njcn.gather.err.service.IPqErrSysDtlsService;
|
||||||
import com.njcn.gather.err.service.IPqErrSysService;
|
import com.njcn.gather.err.service.IPqErrSysService;
|
||||||
import com.njcn.gather.pojo.enums.DetectionResponseEnum;
|
import com.njcn.gather.pojo.enums.DetectionResponseEnum;
|
||||||
|
import com.njcn.gather.report.pojo.enums.PowerIndexEnum;
|
||||||
import com.njcn.gather.system.dictionary.pojo.po.DictData;
|
import com.njcn.gather.system.dictionary.pojo.po.DictData;
|
||||||
import com.njcn.gather.system.dictionary.pojo.po.DictTree;
|
import com.njcn.gather.system.dictionary.pojo.po.DictTree;
|
||||||
import com.njcn.gather.system.dictionary.service.IDictDataService;
|
import com.njcn.gather.system.dictionary.service.IDictDataService;
|
||||||
@@ -219,7 +221,9 @@ public class PqErrSysServiceImpl extends ServiceImpl<PqErrSysMapper, PqErrSys> i
|
|||||||
List<DictTree> parentDictTreeList = dictTreeService.listByIds(pids);
|
List<DictTree> parentDictTreeList = dictTreeService.listByIds(pids);
|
||||||
Map<String, String> map = new HashMap<>();
|
Map<String, String> map = new HashMap<>();
|
||||||
parentDictTreeList.forEach(dictTree -> {
|
parentDictTreeList.forEach(dictTree -> {
|
||||||
map.put(dictTree.getId(), dictTree.getName());
|
if(!dictTree.getCode().equals(PowerIndexEnum.VOLTAGE.getKey())&&!dictTree.getCode().equals(PowerIndexEnum.P.getKey())){
|
||||||
|
map.put(dictTree.getId(), dictTree.getName());
|
||||||
|
}
|
||||||
});
|
});
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,12 +18,18 @@ import io.swagger.annotations.ApiImplicitParam;
|
|||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.core.io.ByteArrayResource;
|
||||||
|
import org.springframework.http.HttpHeaders;
|
||||||
|
import org.springframework.http.MediaType;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
import org.springframework.web.util.UriUtils;
|
||||||
|
|
||||||
|
import javax.validation.Valid;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author caozehui
|
* @author caozehui
|
||||||
* @date 2025-02-10
|
* @date 2025-02-10
|
||||||
@@ -38,7 +44,7 @@ public class PqIcdPathController extends BaseController {
|
|||||||
|
|
||||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||||
@GetMapping("/listAll")
|
@GetMapping("/listAll")
|
||||||
@ApiOperation("获取所有icd")
|
@ApiOperation("获取全部icd")
|
||||||
public HttpResult<List<PqIcdPath>> listAll() {
|
public HttpResult<List<PqIcdPath>> listAll() {
|
||||||
String methodDescribe = getMethodDescribe("listAll");
|
String methodDescribe = getMethodDescribe("listAll");
|
||||||
List<PqIcdPath> result = pqIcdPathService.listAll();
|
List<PqIcdPath> result = pqIcdPathService.listAll();
|
||||||
@@ -60,7 +66,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(@Validated PqIcdPathParam.CreateParam param) {
|
||||||
String methodDescribe = getMethodDescribe("add");
|
String methodDescribe = getMethodDescribe("add");
|
||||||
LogUtil.njcnDebug(log, "{},新增数据为:{}", methodDescribe, param);
|
LogUtil.njcnDebug(log, "{},新增数据为:{}", methodDescribe, param);
|
||||||
|
|
||||||
@@ -72,11 +78,27 @@ public class PqIcdPathController extends BaseController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@OperateInfo(info = LogEnum.BUSINESS_COMMON, operateType = OperateType.ADD)
|
||||||
|
@PostMapping("/external/add")
|
||||||
|
@ApiOperation("外部系统新增icd")
|
||||||
|
@ApiImplicitParam(name = "param", value = "外部系统icd新增参数", required = true)
|
||||||
|
public HttpResult<Boolean> externalAdd(@RequestBody List<PqIcdPathParam.ExternalCreateParam> param) {
|
||||||
|
String methodDescribe = getMethodDescribe("externalAdd");
|
||||||
|
LogUtil.njcnDebug(log, "{},外部新增数据为:{}", methodDescribe, param);
|
||||||
|
|
||||||
|
boolean result = pqIcdPathService.addUpstreamIcd(param);
|
||||||
|
if (result) {
|
||||||
|
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, methodDescribe);
|
||||||
|
} else {
|
||||||
|
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, false, methodDescribe);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON, operateType = OperateType.UPDATE)
|
@OperateInfo(info = LogEnum.BUSINESS_COMMON, operateType = OperateType.UPDATE)
|
||||||
@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(@Validated PqIcdPathParam.UpdateParam param) {
|
||||||
String methodDescribe = getMethodDescribe("update");
|
String methodDescribe = getMethodDescribe("update");
|
||||||
LogUtil.njcnDebug(log, "{},修改数据为:{}", methodDescribe, param);
|
LogUtil.njcnDebug(log, "{},修改数据为:{}", methodDescribe, param);
|
||||||
|
|
||||||
@@ -88,6 +110,24 @@ public class PqIcdPathController extends BaseController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||||
|
@GetMapping("/standard-list")
|
||||||
|
@ApiOperation("获取标准ICD列表")
|
||||||
|
public HttpResult<List<PqIcdPath>> standardList() {
|
||||||
|
String methodDescribe = getMethodDescribe("standardList");
|
||||||
|
List<PqIcdPath> result = pqIcdPathService.listStandardIcd();
|
||||||
|
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
|
||||||
|
}
|
||||||
|
|
||||||
|
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||||
|
@GetMapping("/getById")
|
||||||
|
@ApiOperation("根据id获取ICD详情")
|
||||||
|
public HttpResult<PqIcdPath> getById(@RequestParam String id) {
|
||||||
|
String methodDescribe = getMethodDescribe("getById");
|
||||||
|
PqIcdPath result = pqIcdPathService.getIcdById(id);
|
||||||
|
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
|
||||||
|
}
|
||||||
|
|
||||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON, operateType = OperateType.DELETE)
|
@OperateInfo(info = LogEnum.BUSINESS_COMMON, operateType = OperateType.DELETE)
|
||||||
@PostMapping("/delete")
|
@PostMapping("/delete")
|
||||||
@ApiOperation("删除icd")
|
@ApiOperation("删除icd")
|
||||||
@@ -103,5 +143,17 @@ public class PqIcdPathController extends BaseController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||||
|
@GetMapping("/export/{id}")
|
||||||
|
@ApiOperation("导出icd")
|
||||||
|
public ResponseEntity<ByteArrayResource> export(@PathVariable String id) {
|
||||||
|
PqIcdPath detail = pqIcdPathService.getIcdById(id);
|
||||||
|
byte[] body = pqIcdPathService.exportIcd(id);
|
||||||
|
String fileName = UriUtils.encode(detail.getName() + ".zip", StandardCharsets.UTF_8);
|
||||||
|
return ResponseEntity.ok()
|
||||||
|
.header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename*=UTF-8''" + fileName)
|
||||||
|
.contentType(MediaType.APPLICATION_OCTET_STREAM)
|
||||||
|
.contentLength(body.length)
|
||||||
|
.body(new ByteArrayResource(body));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,12 @@
|
|||||||
package com.njcn.gather.icd.mapper;
|
package com.njcn.gather.icd.mapper;
|
||||||
|
|
||||||
import com.github.yulichang.base.MPJBaseMapper;
|
import com.github.yulichang.base.MPJBaseMapper;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.njcn.gather.icd.pojo.po.PqIcdPath;
|
import com.njcn.gather.icd.pojo.po.PqIcdPath;
|
||||||
import org.apache.ibatis.annotations.Param;
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author caozehui
|
* @author caozehui
|
||||||
* @date 2025-02-10
|
* @date 2025-02-10
|
||||||
@@ -17,5 +20,19 @@ public interface PqIcdPathMapper extends MPJBaseMapper<PqIcdPath> {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
PqIcdPath selectIcdByDevType(@Param("devTypeId") String devTypeId);
|
PqIcdPath selectIcdByDevType(@Param("devTypeId") String devTypeId);
|
||||||
|
|
||||||
|
List<PqIcdPath> selectPageList(Page<PqIcdPath> page, @Param("name") String name);
|
||||||
|
|
||||||
|
List<PqIcdPath> selectStandardList();
|
||||||
|
|
||||||
|
PqIcdPath selectStandardByName(@Param("name") String name);
|
||||||
|
|
||||||
|
List<PqIcdPath> selectByIdsWithoutBlob(@Param("ids") List<String> ids);
|
||||||
|
|
||||||
|
Long countActiveReferencesToStandards(@Param("standardIds") List<String> standardIds);
|
||||||
|
|
||||||
|
PqIcdPath selectDetailById(@Param("id") String id);
|
||||||
|
|
||||||
|
PqIcdPath selectExportById(@Param("id") String id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,10 +4,115 @@
|
|||||||
|
|
||||||
|
|
||||||
<select id="selectIcdByDevType" resultType="com.njcn.gather.icd.pojo.po.PqIcdPath">
|
<select id="selectIcdByDevType" resultType="com.njcn.gather.icd.pojo.po.PqIcdPath">
|
||||||
select *
|
select path.*
|
||||||
from pq_icd_path path
|
from pq_icd_path path
|
||||||
inner join pq_dev_type type on path.id = type.icd
|
inner join pq_dev_type type on path.id = type.icd
|
||||||
where type.id = #{devTypeId}
|
where type.id = #{devTypeId}
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
<select id="selectPageList" resultType="com.njcn.gather.icd.pojo.po.PqIcdPath">
|
||||||
|
select p.id,
|
||||||
|
p.name,
|
||||||
|
p.state,
|
||||||
|
p.angle,
|
||||||
|
p.use_phase_index as usePhaseIndex,
|
||||||
|
p.Json_Str as jsonStr,
|
||||||
|
p.Xml_Str as xmlStr,
|
||||||
|
p.Result as result,
|
||||||
|
p.Msg as msg,
|
||||||
|
p.Type as type,
|
||||||
|
p.Reference_Icd_Id as referenceIcdId,
|
||||||
|
ref.name as referenceIcdName,
|
||||||
|
case when p.Icd is null then false else true end as hasIcdFile,
|
||||||
|
p.create_by as createBy,
|
||||||
|
p.create_time as createTime,
|
||||||
|
p.update_by as updateBy,
|
||||||
|
p.update_time as updateTime
|
||||||
|
from pq_icd_path p
|
||||||
|
left join pq_icd_path ref on p.Reference_Icd_Id = ref.id
|
||||||
|
and ref.state = 1
|
||||||
|
and ref.Type in (1, 3)
|
||||||
|
where p.state = 1
|
||||||
|
<if test="name != null and name != ''">
|
||||||
|
and p.name like concat('%', #{name}, '%')
|
||||||
|
</if>
|
||||||
|
order by p.create_time desc
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<select id="selectStandardList" resultType="com.njcn.gather.icd.pojo.po.PqIcdPath">
|
||||||
|
select id, name, Type as type
|
||||||
|
from pq_icd_path
|
||||||
|
where state = 1
|
||||||
|
and Type in (1, 3)
|
||||||
|
order by create_time desc
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<select id="selectStandardByName" resultType="com.njcn.gather.icd.pojo.po.PqIcdPath">
|
||||||
|
select id, name, Type as type, state
|
||||||
|
from pq_icd_path
|
||||||
|
where state = 1
|
||||||
|
and Type in (1, 3)
|
||||||
|
and name = #{name}
|
||||||
|
limit 1
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<select id="selectByIdsWithoutBlob" resultType="com.njcn.gather.icd.pojo.po.PqIcdPath">
|
||||||
|
select id, name, Type as type, state
|
||||||
|
from pq_icd_path
|
||||||
|
where id in
|
||||||
|
<foreach collection="ids" item="id" open="(" separator="," close=")">
|
||||||
|
#{id}
|
||||||
|
</foreach>
|
||||||
|
and state = 1
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<select id="countActiveReferencesToStandards" resultType="java.lang.Long">
|
||||||
|
select count(1)
|
||||||
|
from pq_icd_path
|
||||||
|
where state = 1
|
||||||
|
and Type in (2, 4)
|
||||||
|
and Reference_Icd_Id in
|
||||||
|
<foreach collection="standardIds" item="id" open="(" separator="," close=")">
|
||||||
|
#{id}
|
||||||
|
</foreach>
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<select id="selectDetailById" resultType="com.njcn.gather.icd.pojo.po.PqIcdPath">
|
||||||
|
select p.id,
|
||||||
|
p.name,
|
||||||
|
p.state,
|
||||||
|
p.angle,
|
||||||
|
p.use_phase_index as usePhaseIndex,
|
||||||
|
p.Json_Str as jsonStr,
|
||||||
|
p.Xml_Str as xmlStr,
|
||||||
|
p.Result as result,
|
||||||
|
p.Msg as msg,
|
||||||
|
p.Type as type,
|
||||||
|
p.Reference_Icd_Id as referenceIcdId,
|
||||||
|
ref.name as referenceIcdName,
|
||||||
|
case when p.Icd is null then false else true end as hasIcdFile,
|
||||||
|
p.create_by as createBy,
|
||||||
|
p.create_time as createTime,
|
||||||
|
p.update_by as updateBy,
|
||||||
|
p.update_time as updateTime
|
||||||
|
from pq_icd_path p
|
||||||
|
left join pq_icd_path ref on p.Reference_Icd_Id = ref.id
|
||||||
|
and ref.state = 1
|
||||||
|
and ref.Type in (1, 3)
|
||||||
|
where p.id = #{id}
|
||||||
|
and p.state = 1
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<select id="selectExportById" resultType="com.njcn.gather.icd.pojo.po.PqIcdPath">
|
||||||
|
select id,
|
||||||
|
name,
|
||||||
|
state,
|
||||||
|
Json_Str as jsonStr,
|
||||||
|
Xml_Str as xmlStr,
|
||||||
|
Icd as icd
|
||||||
|
from pq_icd_path
|
||||||
|
where id = #{id}
|
||||||
|
and state = 1
|
||||||
|
</select>
|
||||||
</mapper>
|
</mapper>
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,40 @@
|
|||||||
|
package com.njcn.gather.icd.pojo.enums;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author caozehui
|
||||||
|
* @data 2025-11-11
|
||||||
|
*/
|
||||||
|
@Getter
|
||||||
|
public enum IcdResponseEnum {
|
||||||
|
FILE_NOT_NULL("A018001", "映射文件不能为空"),
|
||||||
|
FILE_TYPE_ERROR("A018002", "映射文件类型错误"),
|
||||||
|
FILE_SIZE_ERROR("A018003", "映射文件大小超出限制"),
|
||||||
|
ICD_FILE_NOT_NULL("A018004", "ICD原始文件不能为空"),
|
||||||
|
ICD_FILE_TYPE_ERROR("A018005", "ICD原始文件类型错误"),
|
||||||
|
ICD_FILE_READ_ERROR("A018006", "ICD原始文件读取失败"),
|
||||||
|
JSON_FORMAT_ERROR("A018007", "JSON格式错误"),
|
||||||
|
XML_FORMAT_ERROR("A018008", "XML格式错误"),
|
||||||
|
STANDARD_ICD_IN_USE("A018009", "该标准ICD已被非标准ICD引用,禁止删除"),
|
||||||
|
ICD_FILE_NOT_FOUND("A018010", "ICD原始文件不存在"),
|
||||||
|
ICD_EXPORT_FAILED("A018011", "ICD导出失败"),
|
||||||
|
ICD_NOT_FOUND("A018012", "ICD不存在"),
|
||||||
|
RESULT_NOT_NULL("A018013", "结论不能为空"),
|
||||||
|
MSG_NOT_BLANK("A018014", "当结论为否时,描述不能为空"),
|
||||||
|
TYPE_NOT_NULL("A018015", "ICD类型不能为空"),
|
||||||
|
TYPE_VALUE_ERROR("A018016", "ICD类型取值错误"),
|
||||||
|
REFERENCE_ICD_NOT_BLANK("A018017", "非标准ICD必须选择参照标准ICD"),
|
||||||
|
REFERENCE_ICD_INVALID("A018018", "参照标准ICD无效"),
|
||||||
|
GENERATE_FILE("A018019", "文件生成失败"),
|
||||||
|
ICD_TXT_SYNC_FAILED("A018020", "ICD txt文件同步失败"),
|
||||||
|
REFERENCE_STANDARD_ICD_NAME_NOT_FOUND("A018021", "参照标准ICD名称不存在");
|
||||||
|
|
||||||
|
private final String code;
|
||||||
|
private final String message;
|
||||||
|
|
||||||
|
IcdResponseEnum(String code, String message) {
|
||||||
|
this.code = code;
|
||||||
|
this.message = message;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,6 +6,7 @@ import com.njcn.web.pojo.param.BaseParam;
|
|||||||
import io.swagger.annotations.ApiModelProperty;
|
import 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;
|
||||||
@@ -16,36 +17,63 @@ import javax.validation.constraints.Pattern;
|
|||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
public class PqIcdPathParam {
|
public class PqIcdPathParam {
|
||||||
@ApiModelProperty(value = "名称", required = true)
|
@ApiModelProperty(value = "angle", required = true)
|
||||||
@NotBlank(message = DetectionValidMessage.NAME_NOT_BLANK)
|
|
||||||
@Pattern(regexp = PatternRegex.ICD_NAME_REGEX, message = DetectionValidMessage.ICD_NAME_FORMAT_ERROR)
|
|
||||||
private String name;
|
|
||||||
|
|
||||||
@ApiModelProperty(value = "存储路径", required = true)
|
|
||||||
@NotBlank(message = DetectionValidMessage.ICD_PATH_NOT_BLANK)
|
|
||||||
@Pattern(regexp = PatternRegex.ICD_PATH_REGEX, message = DetectionValidMessage.ICD_PATH_FORMAT_ERROR)
|
|
||||||
private String path;
|
|
||||||
|
|
||||||
@ApiModelProperty(value = "是否支持电压相角、电流相角指标,0表示否,1表示是", required = true)
|
|
||||||
private Integer angle;
|
private Integer angle;
|
||||||
|
|
||||||
@ApiModelProperty(value = "角型接线时是否使用相别的指标来进行检测,0表示否,1表示是", required = true)
|
@ApiModelProperty(value = "usePhaseIndex", required = true)
|
||||||
private Integer usePhaseIndex;
|
private Integer usePhaseIndex;
|
||||||
|
|
||||||
/**
|
@ApiModelProperty(value = "jsonStr")
|
||||||
* 分页查询实体
|
private String jsonStr;
|
||||||
*/
|
|
||||||
|
@ApiModelProperty(value = "xmlStr")
|
||||||
|
private String xmlStr;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "result")
|
||||||
|
private Integer result;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "msg")
|
||||||
|
private String msg;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "type")
|
||||||
|
private Integer type;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "referenceIcdId")
|
||||||
|
private String referenceIcdId;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
@EqualsAndHashCode(callSuper = true)
|
@EqualsAndHashCode(callSuper = true)
|
||||||
public static class QueryParam extends BaseParam {
|
public static class QueryParam extends BaseParam {
|
||||||
@ApiModelProperty(value = "名称", required = true)
|
@ApiModelProperty(value = "name", required = true)
|
||||||
private String name;
|
private String name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
public static class CreateParam extends PqIcdPathParam {
|
||||||
|
@ApiModelProperty(value = "icdFile", required = true)
|
||||||
|
private MultipartFile icdFile;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
public static class ExternalCreateParam extends PqIcdPathParam {
|
||||||
|
@ApiModelProperty(value = "id", required = true)
|
||||||
|
@NotBlank(message = DetectionValidMessage.ID_NOT_BLANK)
|
||||||
|
@Pattern(regexp = PatternRegex.SYSTEM_ID, message = DetectionValidMessage.ID_FORMAT_ERROR)
|
||||||
|
private String id;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "name", required = true)
|
||||||
|
@NotBlank(message = DetectionValidMessage.NAME_NOT_BLANK)
|
||||||
|
@Pattern(regexp = PatternRegex.SCRIPT_NAME_REGEX, message = DetectionValidMessage.ICD_NAME_FORMAT_ERROR)
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "icdFile", required = true)
|
||||||
|
@NotBlank(message = IcdExternalValidMessage.ICD_FILE_NOT_BLANK)
|
||||||
|
private String icdFile;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 更新参数
|
|
||||||
*/
|
|
||||||
@Data
|
@Data
|
||||||
@EqualsAndHashCode(callSuper = true)
|
@EqualsAndHashCode(callSuper = true)
|
||||||
public static class UpdateParam extends PqIcdPathParam {
|
public static class UpdateParam extends PqIcdPathParam {
|
||||||
@@ -53,5 +81,12 @@ public class PqIcdPathParam {
|
|||||||
@NotBlank(message = DetectionValidMessage.ID_NOT_BLANK)
|
@NotBlank(message = DetectionValidMessage.ID_NOT_BLANK)
|
||||||
@Pattern(regexp = PatternRegex.SYSTEM_ID, message = DetectionValidMessage.ID_FORMAT_ERROR)
|
@Pattern(regexp = PatternRegex.SYSTEM_ID, message = DetectionValidMessage.ID_FORMAT_ERROR)
|
||||||
private String id;
|
private String id;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "icdFile")
|
||||||
|
private MultipartFile icdFile;
|
||||||
|
}
|
||||||
|
|
||||||
|
private interface IcdExternalValidMessage {
|
||||||
|
String ICD_FILE_NOT_BLANK = "ICD原始文件不能为空";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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;
|
||||||
@@ -27,11 +28,6 @@ public class PqIcdPath extends BaseEntity implements Serializable {
|
|||||||
*/
|
*/
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
/**
|
|
||||||
* icd存储地址
|
|
||||||
*/
|
|
||||||
private String path;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 状态:0-删除 1-正常
|
* 状态:0-删除 1-正常
|
||||||
*/
|
*/
|
||||||
@@ -45,6 +41,55 @@ public class PqIcdPath extends BaseEntity implements Serializable {
|
|||||||
/**
|
/**
|
||||||
* 角型接线时是否使用相别的指标来进行检测,0表示否,1表示是
|
* 角型接线时是否使用相别的指标来进行检测,0表示否,1表示是
|
||||||
*/
|
*/
|
||||||
|
@TableField("use_phase_index")
|
||||||
private Integer usePhaseIndex;
|
private Integer usePhaseIndex;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 解析后的json字符串
|
||||||
|
*/
|
||||||
|
@TableField("Json_Str")
|
||||||
|
private String jsonStr;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 解析后的xml字符串
|
||||||
|
*/
|
||||||
|
@TableField("Xml_Str")
|
||||||
|
private String xmlStr;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ICD原始文件二进制
|
||||||
|
*/
|
||||||
|
@TableField("Icd")
|
||||||
|
private byte[] icd;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 结论
|
||||||
|
*/
|
||||||
|
@TableField("Result")
|
||||||
|
private Integer result;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 结论描述
|
||||||
|
*/
|
||||||
|
@TableField("Msg")
|
||||||
|
private String msg;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ICD类型
|
||||||
|
*/
|
||||||
|
@TableField("Type")
|
||||||
|
private Integer type;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 参照标准ICD
|
||||||
|
*/
|
||||||
|
@TableField("Reference_Icd_Id")
|
||||||
|
private String referenceIcdId;
|
||||||
|
|
||||||
|
@TableField(exist = false)
|
||||||
|
private String referenceIcdName;
|
||||||
|
|
||||||
|
@TableField(exist = false)
|
||||||
|
private Boolean hasIcdFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -28,13 +28,22 @@ public interface IPqIcdPathService extends IService<PqIcdPath> {
|
|||||||
*/
|
*/
|
||||||
Page<PqIcdPath> listIcd(PqIcdPathParam.QueryParam param);
|
Page<PqIcdPath> listIcd(PqIcdPathParam.QueryParam param);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取所有标准ICD
|
||||||
|
*
|
||||||
|
* @return 标准ICD列表
|
||||||
|
*/
|
||||||
|
List<PqIcdPath> listStandardIcd();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 新增Icd
|
* 新增Icd
|
||||||
*
|
*
|
||||||
* @param param 新增Icd参数
|
* @param param 新增Icd参数
|
||||||
* @return 成功返回true,失败返回false
|
* @return 成功返回true,失败返回false
|
||||||
*/
|
*/
|
||||||
boolean addIcd(PqIcdPathParam param);
|
boolean addIcd(PqIcdPathParam.CreateParam param);
|
||||||
|
|
||||||
|
boolean addUpstreamIcd(List<PqIcdPathParam.ExternalCreateParam> param);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 修改Icd
|
* 修改Icd
|
||||||
@@ -52,6 +61,22 @@ public interface IPqIcdPathService extends IService<PqIcdPath> {
|
|||||||
*/
|
*/
|
||||||
boolean deleteIcd(List<String> ids);
|
boolean deleteIcd(List<String> ids);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据id获取ICD详情
|
||||||
|
*
|
||||||
|
* @param id ICD id
|
||||||
|
* @return ICD详情
|
||||||
|
*/
|
||||||
|
PqIcdPath getIcdById(String id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 导出ICD压缩包
|
||||||
|
*
|
||||||
|
* @param id ICD id
|
||||||
|
* @return zip字节数组
|
||||||
|
*/
|
||||||
|
byte[] exportIcd(String id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据设备类型id获取Icd
|
* 根据设备类型id获取Icd
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package com.njcn.gather.icd.service.impl;
|
package com.njcn.gather.icd.service.impl;
|
||||||
|
|
||||||
|
import cn.hutool.core.collection.CollUtil;
|
||||||
|
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,18 +9,30 @@ 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.icd.service.support.IcdArchiveBuilder;
|
||||||
|
import com.njcn.gather.icd.service.support.IcdPayloadAssembler;
|
||||||
import com.njcn.gather.pojo.enums.DetectionResponseEnum;
|
import com.njcn.gather.pojo.enums.DetectionResponseEnum;
|
||||||
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.factory.annotation.Value;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.Paths;
|
||||||
|
import java.nio.file.StandardOpenOption;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author caozehui
|
* @author caozehui
|
||||||
@@ -28,47 +42,147 @@ import java.util.List;
|
|||||||
@Service
|
@Service
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class PqIcdPathServiceImpl extends ServiceImpl<PqIcdPathMapper, PqIcdPath> implements IPqIcdPathService {
|
public class PqIcdPathServiceImpl extends ServiceImpl<PqIcdPathMapper, PqIcdPath> implements IPqIcdPathService {
|
||||||
|
// 手动录入标准ICD
|
||||||
|
private static final int TYPE_STANDARD = 1;
|
||||||
|
// 手动录入非标准ICD
|
||||||
|
private static final int TYPE_NON_STANDARD = 2;
|
||||||
|
// 上游录入的标准ICD
|
||||||
|
private static final int TYPE_UPSTREAM_STANDARD = 3;
|
||||||
|
|
||||||
|
// 上游录入的非标准ICD
|
||||||
|
private static final int TYPE_UPSTREAM_NON_STANDARD = 4;
|
||||||
|
private static final int RESULT_NO = 0;
|
||||||
|
private static final int RESULT_YES = 1;
|
||||||
|
|
||||||
|
@Value("${icd.txt-dir}")
|
||||||
|
private String icdTxtDir;
|
||||||
|
|
||||||
|
private final IcdPayloadAssembler icdPayloadAssembler;
|
||||||
|
private final IcdArchiveBuilder icdArchiveBuilder;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<PqIcdPath> listAll() {
|
public List<PqIcdPath> listAll() {
|
||||||
return this.lambdaQuery().eq(PqIcdPath::getState, DataStateEnum.ENABLE.getCode()).list();
|
return this.lambdaQuery()
|
||||||
|
.select(PqIcdPath::getId, PqIcdPath::getName, PqIcdPath::getType, PqIcdPath::getReferenceIcdId)
|
||||||
|
.eq(PqIcdPath::getState, DataStateEnum.ENABLE.getCode())
|
||||||
|
.orderByDesc(PqIcdPath::getCreateTime)
|
||||||
|
.list();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<PqIcdPath> listStandardIcd() {
|
||||||
|
return this.baseMapper.selectStandardList();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Page<PqIcdPath> listIcd(PqIcdPathParam.QueryParam param) {
|
public Page<PqIcdPath> listIcd(PqIcdPathParam.QueryParam param) {
|
||||||
LambdaQueryWrapper<PqIcdPath> wrapper = new LambdaQueryWrapper<>();
|
Page<PqIcdPath> page = new Page<>(PageFactory.getPageNum(param), PageFactory.getPageSize(param));
|
||||||
wrapper.eq(PqIcdPath::getState, DataStateEnum.ENABLE.getCode())
|
page.setRecords(this.baseMapper.selectPageList(page, StrUtil.trim(param.getName())));
|
||||||
.like(StrUtil.isNotBlank(param.getName()), PqIcdPath::getName, param.getName())
|
|
||||||
.orderByDesc(PqIcdPath::getCreateTime);
|
|
||||||
Page<PqIcdPath> page = this.page(new Page<>(PageFactory.getPageNum(param), PageFactory.getPageSize(param)), wrapper);
|
|
||||||
return page;
|
return page;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional
|
@Transactional
|
||||||
public boolean addIcd(PqIcdPathParam param) {
|
public boolean addIcd(PqIcdPathParam.CreateParam param) {
|
||||||
param.setName(param.getName().trim());
|
validateBusinessFields(param, null);
|
||||||
this.checkRepeat(param, false);
|
PqIcdPath pqIcdPath = icdPayloadAssembler.fromCreate(param);
|
||||||
PqIcdPath pqIcdPath = new PqIcdPath();
|
validateReferenceIcd(pqIcdPath.getType(), pqIcdPath.getReferenceIcdId(), null);
|
||||||
BeanUtils.copyProperties(param, pqIcdPath);
|
boolean saved = this.save(pqIcdPath);
|
||||||
pqIcdPath.setState(DataStateEnum.ENABLE.getCode());
|
if (saved) {
|
||||||
return this.save(pqIcdPath);
|
writeIcdTextFile(resolveIcdTxtDir(), pqIcdPath.getName(), pqIcdPath.getJsonStr());
|
||||||
|
}
|
||||||
|
return saved;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional
|
||||||
|
public boolean addUpstreamIcd(List<PqIcdPathParam.ExternalCreateParam> param) {
|
||||||
|
if (CollUtil.isEmpty(param)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
Set<String> requestStandardIds = collectRequestStandardIds(param);
|
||||||
|
boolean allSaved = true;
|
||||||
|
Path directory = resolveIcdTxtDir();
|
||||||
|
for (PqIcdPathParam.ExternalCreateParam item : param) {
|
||||||
|
validateBusinessFields(item, null);
|
||||||
|
PqIcdPath current = this.baseMapper.selectById(item.getId());
|
||||||
|
PqIcdPath pqIcdPath = icdPayloadAssembler.fromExternalCreate(item, item.getType(), item.getAngle(), item.getUsePhaseIndex());
|
||||||
|
String currentId = current == null ? null : current.getId();
|
||||||
|
String oldName = current == null ? null : current.getName();
|
||||||
|
validateExternalReferenceIcd(pqIcdPath.getType(), pqIcdPath.getReferenceIcdId(), currentId, requestStandardIds);
|
||||||
|
boolean saved = current == null ? this.save(pqIcdPath) : this.updateById(pqIcdPath);
|
||||||
|
if (!saved) {
|
||||||
|
allSaved = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (current == null) {
|
||||||
|
writeIcdTextFile(directory, pqIcdPath.getName(), pqIcdPath.getJsonStr());
|
||||||
|
} else {
|
||||||
|
syncUpdatedIcdTextFile(directory, oldName, pqIcdPath.getName(), pqIcdPath.getJsonStr());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return allSaved;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional
|
@Transactional
|
||||||
public boolean updateIcd(PqIcdPathParam.UpdateParam param) {
|
public boolean updateIcd(PqIcdPathParam.UpdateParam param) {
|
||||||
param.setName(param.getName().trim());
|
PqIcdPath current = getActiveEntity(param.getId());
|
||||||
this.checkRepeat(param, true);
|
String oldName = current.getName();
|
||||||
PqIcdPath pqIcdPath = new PqIcdPath();
|
validateBusinessFields(param, current.getId());
|
||||||
BeanUtils.copyProperties(param, pqIcdPath);
|
PqIcdPath pqIcdPath = icdPayloadAssembler.merge(current, param);
|
||||||
return this.updateById(pqIcdPath);
|
validateReferenceIcd(pqIcdPath.getType(), pqIcdPath.getReferenceIcdId(), current.getId());
|
||||||
|
boolean updated = this.updateById(pqIcdPath);
|
||||||
|
if (updated) {
|
||||||
|
syncUpdatedIcdTextFile(resolveIcdTxtDir(), oldName, pqIcdPath.getName(), pqIcdPath.getJsonStr());
|
||||||
|
}
|
||||||
|
return updated;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional
|
@Transactional
|
||||||
public boolean deleteIcd(List<String> ids) {
|
public boolean deleteIcd(List<String> ids) {
|
||||||
return this.lambdaUpdate().in(PqIcdPath::getId, ids).set(PqIcdPath::getState, DataStateEnum.DELETED.getCode()).update();
|
if (CollUtil.isEmpty(ids)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
List<PqIcdPath> pqIcdPaths = this.baseMapper.selectByIdsWithoutBlob(ids);
|
||||||
|
List<String> standardIds = pqIcdPaths.stream()
|
||||||
|
.filter(pqIcdPath -> ObjectUtil.equals(pqIcdPath.getType(), TYPE_STANDARD))
|
||||||
|
.map(PqIcdPath::getId)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
if (!standardIds.isEmpty()) {
|
||||||
|
Long count = this.baseMapper.countActiveReferencesToStandards(standardIds);
|
||||||
|
if (ObjectUtil.isNotNull(count) && count > 0) {
|
||||||
|
throw new BusinessException(IcdResponseEnum.STANDARD_ICD_IN_USE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean deleted = this.lambdaUpdate().in(PqIcdPath::getId, ids).set(PqIcdPath::getState, DataStateEnum.DELETED.getCode()).update();
|
||||||
|
if (deleted) {
|
||||||
|
Path directory = resolveIcdTxtDir();
|
||||||
|
for (PqIcdPath pqIcdPath : pqIcdPaths) {
|
||||||
|
deleteIcdTextFile(directory, pqIcdPath.getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return deleted;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PqIcdPath getIcdById(String id) {
|
||||||
|
PqIcdPath detail = this.baseMapper.selectDetailById(id);
|
||||||
|
if (ObjectUtil.isNull(detail)) {
|
||||||
|
throw new BusinessException(IcdResponseEnum.ICD_NOT_FOUND);
|
||||||
|
}
|
||||||
|
return detail;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte[] exportIcd(String id) {
|
||||||
|
PqIcdPath detail = this.baseMapper.selectExportById(id);
|
||||||
|
if (ObjectUtil.isNull(detail)) {
|
||||||
|
throw new BusinessException(IcdResponseEnum.ICD_NOT_FOUND);
|
||||||
|
}
|
||||||
|
return icdArchiveBuilder.build(detail);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -76,18 +190,125 @@ public class PqIcdPathServiceImpl extends ServiceImpl<PqIcdPathMapper, PqIcdPath
|
|||||||
return this.baseMapper.selectIcdByDevType(devTypeId);
|
return this.baseMapper.selectIcdByDevType(devTypeId);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkRepeat(PqIcdPathParam param, boolean isExcludeSelf) {
|
private void validateBusinessFields(PqIcdPathParam param, String currentId) {
|
||||||
LambdaQueryWrapper<PqIcdPath> wrapper = new LambdaQueryWrapper<>();
|
if (ObjectUtil.isNull(param.getResult())) {
|
||||||
wrapper.eq(PqIcdPath::getName, param.getName())
|
throw new BusinessException(IcdResponseEnum.RESULT_NOT_NULL);
|
||||||
.eq(PqIcdPath::getState, DataStateEnum.ENABLE.getCode());
|
|
||||||
if (isExcludeSelf) {
|
|
||||||
if (param instanceof PqIcdPathParam.UpdateParam) {
|
|
||||||
wrapper.ne(PqIcdPath::getId, ((PqIcdPathParam.UpdateParam) param).getId());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
int count = this.count(wrapper);
|
if (ObjectUtil.equals(param.getResult(), RESULT_NO) && StrUtil.isBlank(param.getMsg())) {
|
||||||
if (count > 0) {
|
throw new BusinessException(IcdResponseEnum.MSG_NOT_BLANK);
|
||||||
throw new BusinessException(DetectionResponseEnum.ICD_PATH_NAME_REPEAT);
|
}
|
||||||
|
if (ObjectUtil.isNull(param.getType())) {
|
||||||
|
throw new BusinessException(IcdResponseEnum.TYPE_NOT_NULL);
|
||||||
|
}
|
||||||
|
if (!ObjectUtil.equals(param.getType(), TYPE_STANDARD)
|
||||||
|
&& !ObjectUtil.equals(param.getType(), TYPE_NON_STANDARD)
|
||||||
|
&& !ObjectUtil.equals(param.getType(), TYPE_UPSTREAM_STANDARD)
|
||||||
|
&& !ObjectUtil.equals(param.getType(), TYPE_UPSTREAM_NON_STANDARD)) {
|
||||||
|
throw new BusinessException(IcdResponseEnum.TYPE_VALUE_ERROR);
|
||||||
|
}
|
||||||
|
if (requiresReferenceIcd(param.getType()) && StrUtil.isBlank(param.getReferenceIcdId())) {
|
||||||
|
throw new BusinessException(IcdResponseEnum.REFERENCE_ICD_NOT_BLANK);
|
||||||
|
}
|
||||||
|
if (StrUtil.isNotBlank(currentId) && StrUtil.equals(currentId, StrUtil.trim(param.getReferenceIcdId()))) {
|
||||||
|
throw new BusinessException(IcdResponseEnum.REFERENCE_ICD_INVALID);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void validateReferenceIcd(Integer type, String referenceIcdId, String currentId) {
|
||||||
|
if (!requiresReferenceIcd(type)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (StrUtil.isNotBlank(currentId) && StrUtil.equals(currentId, referenceIcdId)) {
|
||||||
|
throw new BusinessException(IcdResponseEnum.REFERENCE_ICD_INVALID);
|
||||||
|
}
|
||||||
|
long count = this.lambdaQuery()
|
||||||
|
.eq(PqIcdPath::getId, referenceIcdId)
|
||||||
|
.in(PqIcdPath::getType, TYPE_STANDARD, TYPE_UPSTREAM_STANDARD)
|
||||||
|
.eq(PqIcdPath::getState, DataStateEnum.ENABLE.getCode())
|
||||||
|
.count();
|
||||||
|
if (count <= 0L) {
|
||||||
|
throw new BusinessException(IcdResponseEnum.REFERENCE_ICD_INVALID);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void validateExternalReferenceIcd(Integer type, String referenceIcdId, String currentId, Set<String> requestStandardIds) {
|
||||||
|
if (!requiresReferenceIcd(type)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
String trimmedReferenceId = StrUtil.trim(referenceIcdId);
|
||||||
|
if (StrUtil.isNotBlank(currentId) && StrUtil.equals(currentId, trimmedReferenceId)) {
|
||||||
|
throw new BusinessException(IcdResponseEnum.REFERENCE_ICD_INVALID);
|
||||||
|
}
|
||||||
|
if (StrUtil.isNotBlank(trimmedReferenceId) && requestStandardIds.contains(trimmedReferenceId)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
validateReferenceIcd(type, trimmedReferenceId, currentId);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Set<String> collectRequestStandardIds(List<PqIcdPathParam.ExternalCreateParam> params) {
|
||||||
|
Set<String> ids = new HashSet<>();
|
||||||
|
for (PqIcdPathParam.ExternalCreateParam param : params) {
|
||||||
|
if (isStandardType(param.getType()) && StrUtil.isNotBlank(param.getId())) {
|
||||||
|
ids.add(StrUtil.trim(param.getId()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ids;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean requiresReferenceIcd(Integer type) {
|
||||||
|
return ObjectUtil.equals(type, TYPE_NON_STANDARD) || ObjectUtil.equals(type, TYPE_UPSTREAM_NON_STANDARD);
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isStandardType(Integer type) {
|
||||||
|
return ObjectUtil.equals(type, TYPE_STANDARD) || ObjectUtil.equals(type, TYPE_UPSTREAM_STANDARD);
|
||||||
|
}
|
||||||
|
|
||||||
|
private PqIcdPath getActiveEntity(String id) {
|
||||||
|
PqIcdPath current = this.lambdaQuery()
|
||||||
|
.eq(PqIcdPath::getId, id)
|
||||||
|
.eq(PqIcdPath::getState, DataStateEnum.ENABLE.getCode())
|
||||||
|
.one();
|
||||||
|
if (ObjectUtil.isNull(current)) {
|
||||||
|
throw new BusinessException(IcdResponseEnum.ICD_NOT_FOUND);
|
||||||
|
}
|
||||||
|
return current;
|
||||||
|
}
|
||||||
|
|
||||||
|
Path resolveIcdTxtDir() {
|
||||||
|
if (StrUtil.isBlank(icdTxtDir)) {
|
||||||
|
throw new BusinessException(IcdResponseEnum.ICD_TXT_SYNC_FAILED);
|
||||||
|
}
|
||||||
|
return Paths.get(icdTxtDir.trim());
|
||||||
|
}
|
||||||
|
|
||||||
|
void writeIcdTextFile(Path directory, String name, String jsonStr) {
|
||||||
|
try {
|
||||||
|
Files.createDirectories(directory);
|
||||||
|
Files.write(resolveTxtFile(directory, name), StrUtil.nullToDefault(jsonStr, "").getBytes(StandardCharsets.UTF_8),
|
||||||
|
StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING, StandardOpenOption.WRITE);
|
||||||
|
} catch (IOException ex) {
|
||||||
|
log.error("sync icd txt file failed, name={}", name, ex);
|
||||||
|
throw new BusinessException(IcdResponseEnum.ICD_TXT_SYNC_FAILED);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void syncUpdatedIcdTextFile(Path directory, String oldName, String newName, String jsonStr) {
|
||||||
|
if (StrUtil.isNotBlank(oldName) && !StrUtil.equals(oldName, newName)) {
|
||||||
|
deleteIcdTextFile(directory, oldName);
|
||||||
|
}
|
||||||
|
writeIcdTextFile(directory, newName, jsonStr);
|
||||||
|
}
|
||||||
|
|
||||||
|
void deleteIcdTextFile(Path directory, String name) {
|
||||||
|
try {
|
||||||
|
Files.deleteIfExists(resolveTxtFile(directory, name));
|
||||||
|
} catch (IOException ex) {
|
||||||
|
log.error("delete icd txt file failed, name={}", name, ex);
|
||||||
|
throw new BusinessException(IcdResponseEnum.ICD_TXT_SYNC_FAILED);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Path resolveTxtFile(Path directory, String name) {
|
||||||
|
return directory.resolve(name + ".txt");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,62 @@
|
|||||||
|
package com.njcn.gather.icd.service.support;
|
||||||
|
|
||||||
|
import com.njcn.common.pojo.exception.BusinessException;
|
||||||
|
import com.njcn.gather.icd.pojo.enums.IcdResponseEnum;
|
||||||
|
import com.njcn.gather.icd.pojo.po.PqIcdPath;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.util.zip.ZipEntry;
|
||||||
|
import java.util.zip.ZipOutputStream;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class IcdArchiveBuilder {
|
||||||
|
|
||||||
|
public byte[] build(PqIcdPath item) {
|
||||||
|
if (item == null || item.getIcd() == null || item.getIcd().length == 0) {
|
||||||
|
throw new BusinessException(IcdResponseEnum.ICD_FILE_NOT_FOUND);
|
||||||
|
}
|
||||||
|
try (ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||||
|
ZipOutputStream zos = new ZipOutputStream(bos, StandardCharsets.UTF_8)) {
|
||||||
|
writeTextEntry(zos, item.getName() + ".json", item.getJsonStr());
|
||||||
|
writeTextEntry(zos, item.getName() + ".xml", item.getXmlStr());
|
||||||
|
writeBinaryEntry(zos, item.getName() + ".icd", item.getIcd());
|
||||||
|
zos.finish();
|
||||||
|
return bos.toByteArray();
|
||||||
|
} catch (IOException ex) {
|
||||||
|
throw new BusinessException(IcdResponseEnum.ICD_EXPORT_FAILED);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 向ZIP流中写入文本条目
|
||||||
|
*
|
||||||
|
* @param zos ZIP输出流
|
||||||
|
* @param name 条目名称(文件路径)
|
||||||
|
* @param value 文本内容,如果为null则写入空字节数组
|
||||||
|
* @throws IOException 写入异常
|
||||||
|
*/
|
||||||
|
private void writeTextEntry(ZipOutputStream zos, String name, String value) throws IOException {
|
||||||
|
// 将文本转换为UTF-8编码的字节数组,null值转换为空数组
|
||||||
|
writeBinaryEntry(zos, name, value == null ? new byte[0] : value.getBytes(StandardCharsets.UTF_8));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 向ZIP流中写入二进制条目
|
||||||
|
*
|
||||||
|
* @param zos ZIP输出流
|
||||||
|
* @param name 条目名称(文件路径)
|
||||||
|
* @param data 二进制数据
|
||||||
|
* @throws IOException 写入异常
|
||||||
|
*/
|
||||||
|
private void writeBinaryEntry(ZipOutputStream zos, String name, byte[] data) throws IOException {
|
||||||
|
// 创建新的ZIP条目并设置文件名
|
||||||
|
zos.putNextEntry(new ZipEntry(name));
|
||||||
|
// 写入二进制数据
|
||||||
|
zos.write(data);
|
||||||
|
// 关闭当前条目,准备写入下一个条目
|
||||||
|
zos.closeEntry();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,90 @@
|
|||||||
|
package com.njcn.gather.icd.service.support;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import com.njcn.common.pojo.enums.common.DataStateEnum;
|
||||||
|
import com.njcn.common.pojo.exception.BusinessException;
|
||||||
|
import com.njcn.gather.icd.pojo.enums.IcdResponseEnum;
|
||||||
|
import com.njcn.gather.icd.pojo.param.PqIcdPathParam;
|
||||||
|
import com.njcn.gather.icd.pojo.po.PqIcdPath;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class IcdPayloadAssembler {
|
||||||
|
|
||||||
|
private final IcdPayloadValidator validator;
|
||||||
|
|
||||||
|
public PqIcdPath fromCreate(PqIcdPathParam.CreateParam param) {
|
||||||
|
MultipartFile file = validator.validateIcdFile(param.getIcdFile(), true);
|
||||||
|
validator.validateJson(param.getJsonStr());
|
||||||
|
validator.validateXml(param.getXmlStr());
|
||||||
|
|
||||||
|
PqIcdPath entity = new PqIcdPath();
|
||||||
|
applyCommonFields(entity, param);
|
||||||
|
entity.setName(validator.extractName(file.getOriginalFilename()));
|
||||||
|
entity.setIcd(getBytes(file));
|
||||||
|
entity.setState(DataStateEnum.ENABLE.getCode());
|
||||||
|
return entity;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PqIcdPath fromExternalCreate(PqIcdPathParam.ExternalCreateParam param, int type, int angle, int usePhaseIndex) {
|
||||||
|
byte[] fileBytes = validator.decodeExternalIcdFile(param.getIcdFile());
|
||||||
|
validator.validateJson(param.getJsonStr());
|
||||||
|
validator.validateXml(param.getXmlStr());
|
||||||
|
|
||||||
|
PqIcdPath entity = new PqIcdPath();
|
||||||
|
entity.setId(normalizeNullableText(param.getId()));
|
||||||
|
param.setType(type);
|
||||||
|
param.setAngle(angle);
|
||||||
|
param.setUsePhaseIndex(usePhaseIndex);
|
||||||
|
applyCommonFields(entity, param);
|
||||||
|
entity.setName(normalizeNullableText(param.getName()));
|
||||||
|
entity.setIcd(fileBytes);
|
||||||
|
entity.setState(DataStateEnum.ENABLE.getCode());
|
||||||
|
return entity;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PqIcdPath merge(PqIcdPath current, PqIcdPathParam.UpdateParam param) {
|
||||||
|
MultipartFile file = validator.validateIcdFile(param.getIcdFile(), false);
|
||||||
|
validator.validateJson(param.getJsonStr());
|
||||||
|
validator.validateXml(param.getXmlStr());
|
||||||
|
|
||||||
|
applyCommonFields(current, param);
|
||||||
|
if (file != null && !file.isEmpty()) {
|
||||||
|
current.setName(validator.extractName(file.getOriginalFilename()));
|
||||||
|
current.setIcd(getBytes(file));
|
||||||
|
}
|
||||||
|
return current;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void applyCommonFields(PqIcdPath entity, PqIcdPathParam param) {
|
||||||
|
entity.setAngle(param.getAngle());
|
||||||
|
entity.setUsePhaseIndex(param.getUsePhaseIndex());
|
||||||
|
entity.setJsonStr(param.getJsonStr());
|
||||||
|
entity.setXmlStr(param.getXmlStr());
|
||||||
|
entity.setResult(param.getResult());
|
||||||
|
entity.setMsg(param.getResult() != null && param.getResult() == 1 ? null : normalizeNullableText(param.getMsg()));
|
||||||
|
entity.setType(param.getType());
|
||||||
|
entity.setReferenceIcdId(requiresReferenceIcd(param.getType()) ? normalizeNullableText(param.getReferenceIcdId()) : null);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String normalizeNullableText(String value) {
|
||||||
|
return StrUtil.emptyToNull(StrUtil.trim(value));
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean requiresReferenceIcd(Integer type) {
|
||||||
|
return type != null && (type == 2 || type == 4);
|
||||||
|
}
|
||||||
|
|
||||||
|
private byte[] getBytes(MultipartFile file) {
|
||||||
|
try {
|
||||||
|
return file.getBytes();
|
||||||
|
} catch (IOException ex) {
|
||||||
|
throw new BusinessException(IcdResponseEnum.ICD_FILE_READ_ERROR);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,66 @@
|
|||||||
|
package com.njcn.gather.icd.service.support;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import com.njcn.common.pojo.exception.BusinessException;
|
||||||
|
import com.njcn.gather.icd.pojo.enums.IcdResponseEnum;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
import org.xml.sax.InputSource;
|
||||||
|
|
||||||
|
import javax.xml.parsers.DocumentBuilderFactory;
|
||||||
|
import java.io.StringReader;
|
||||||
|
import java.util.Base64;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class IcdPayloadValidator {
|
||||||
|
|
||||||
|
public MultipartFile validateIcdFile(MultipartFile file, boolean required) {
|
||||||
|
if ((file == null || file.isEmpty()) && required) {
|
||||||
|
throw new BusinessException(IcdResponseEnum.ICD_FILE_NOT_NULL);
|
||||||
|
}
|
||||||
|
if (file == null || file.isEmpty()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
String originalName = file.getOriginalFilename();
|
||||||
|
if (originalName == null || !originalName.toLowerCase(Locale.ROOT).endsWith(".icd")) {
|
||||||
|
throw new BusinessException(IcdResponseEnum.ICD_FILE_TYPE_ERROR);
|
||||||
|
}
|
||||||
|
return file;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String extractName(String originalName) {
|
||||||
|
int suffixIndex = originalName.toLowerCase(Locale.ROOT).lastIndexOf(".icd");
|
||||||
|
return suffixIndex >= 0 ? originalName.substring(0, suffixIndex) : originalName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public byte[] decodeExternalIcdFile(String base64Content) {
|
||||||
|
if (base64Content == null || base64Content.trim().isEmpty()) {
|
||||||
|
throw new BusinessException(IcdResponseEnum.ICD_FILE_NOT_NULL);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
return Base64.getDecoder().decode(base64Content.trim());
|
||||||
|
} catch (IllegalArgumentException ex) {
|
||||||
|
throw new BusinessException(IcdResponseEnum.ICD_FILE_READ_ERROR);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void validateJson(String jsonStr) {
|
||||||
|
try {
|
||||||
|
JSON.parse(jsonStr);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
throw new BusinessException(IcdResponseEnum.JSON_FORMAT_ERROR);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void validateXml(String xmlStr) {
|
||||||
|
try {
|
||||||
|
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
||||||
|
// 禁用 DOCTYPE 声明
|
||||||
|
factory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
|
||||||
|
factory.newDocumentBuilder().parse(new InputSource(new StringReader(xmlStr)));
|
||||||
|
} catch (Exception ex) {
|
||||||
|
throw new BusinessException(IcdResponseEnum.XML_FORMAT_ERROR);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,8 +1,10 @@
|
|||||||
package com.njcn.gather.monitor.mapper;
|
package com.njcn.gather.monitor.mapper;
|
||||||
|
|
||||||
import com.github.yulichang.base.MPJBaseMapper;
|
import com.github.yulichang.base.MPJBaseMapper;
|
||||||
|
import com.njcn.gather.device.pojo.po.PqDevSub;
|
||||||
import com.njcn.gather.device.pojo.vo.PreDetection;
|
import com.njcn.gather.device.pojo.vo.PreDetection;
|
||||||
import com.njcn.gather.monitor.pojo.po.PqMonitor;
|
import com.njcn.gather.monitor.pojo.po.PqMonitor;
|
||||||
|
import com.njcn.gather.plan.pojo.po.AdPlan;
|
||||||
import org.apache.ibatis.annotations.Param;
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -33,5 +35,21 @@ public interface PqMonitorMapper extends MPJBaseMapper<PqMonitor> {
|
|||||||
PqMonitor getByDevIdAndNum(@Param("devId") String devId, @Param("num") Integer num);
|
PqMonitor getByDevIdAndNum(@Param("devId") String devId, @Param("num") Integer num);
|
||||||
|
|
||||||
List<PqMonitor> listByDevIds(@Param("devIds") List<String> devIds);
|
List<PqMonitor> listByDevIds(@Param("devIds") List<String> devIds);
|
||||||
|
|
||||||
|
void updateDeviceCheckState(@Param("devId")String devId, @Param("value") Integer value);
|
||||||
|
|
||||||
|
void updateDeviceCheckResult(@Param("devId")String devId, @Param("value") Integer value);
|
||||||
|
|
||||||
|
void updateDeviceReportRState(@Param("devId")String devId, @Param("value") Integer value);
|
||||||
|
|
||||||
|
AdPlan getPlanByDevId(@Param("devId") String devId);
|
||||||
|
|
||||||
|
List<PqDevSub> listDevSubByPlanId(@Param("planId") String planId);
|
||||||
|
|
||||||
|
void updatePlanCheckState(@Param("planId") String planId, @Param("value") Integer value);
|
||||||
|
|
||||||
|
void updatePlanCheckResult(@Param("planId") String planId, @Param("value") Integer value);
|
||||||
|
|
||||||
|
void updatePlanReportRState(@Param("planId") String planId, @Param("value") Integer value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
<mapper namespace="com.njcn.gather.monitor.mapper.PqMonitorMapper">
|
<mapper namespace="com.njcn.gather.monitor.mapper.PqMonitorMapper">
|
||||||
|
|
||||||
|
|
||||||
<select id="selectMonitorInfo"
|
<select id="selectMonitorInfo"
|
||||||
resultType="com.njcn.gather.device.pojo.vo.PreDetection$MonitorListDTO">
|
resultType="com.njcn.gather.device.pojo.vo.PreDetection$MonitorListDTO">
|
||||||
SELECT CONCAT(pq_dev.IP, '_', Num) as lineId,
|
SELECT CONCAT(pq_dev.IP, '_', Num) as lineId,
|
||||||
@@ -41,5 +42,55 @@
|
|||||||
</foreach>
|
</foreach>
|
||||||
order by Num
|
order by Num
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
<update id="updateDeviceCheckState">
|
||||||
|
update pq_dev_sub
|
||||||
|
set Check_State = #{value}
|
||||||
|
where dev_Id = #{devId}
|
||||||
|
</update>
|
||||||
|
|
||||||
|
<update id="updateDeviceCheckResult">
|
||||||
|
update pq_dev_sub
|
||||||
|
set Check_Result = #{value}
|
||||||
|
where dev_Id = #{devId}
|
||||||
|
</update>
|
||||||
|
|
||||||
|
<update id="updateDeviceReportRState">
|
||||||
|
update pq_dev_sub
|
||||||
|
set Report_State = #{value}
|
||||||
|
where dev_Id = #{devId}
|
||||||
|
</update>
|
||||||
|
|
||||||
|
<select id="getPlanByDevId" resultType="com.njcn.gather.plan.pojo.po.AdPlan">
|
||||||
|
select *
|
||||||
|
from ad_plan
|
||||||
|
inner join pq_dev on ad_plan.id = pq_dev.Plan_Id
|
||||||
|
where pq_dev.Id = #{devId}
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<select id="listDevSubByPlanId" resultType="com.njcn.gather.device.pojo.po.PqDevSub">
|
||||||
|
select *
|
||||||
|
from pq_dev_sub
|
||||||
|
inner join pq_dev on pq_dev_sub.dev_Id = pq_dev.Id
|
||||||
|
where pq_dev.Plan_Id = #{planId}
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<update id="updatePlanCheckState">
|
||||||
|
update ad_plan
|
||||||
|
set Test_State = #{value}
|
||||||
|
where id = #{planId}
|
||||||
|
</update>
|
||||||
|
|
||||||
|
<update id="updatePlanCheckResult">
|
||||||
|
update ad_plan
|
||||||
|
set Result = #{value}
|
||||||
|
where id = #{planId}
|
||||||
|
</update>
|
||||||
|
|
||||||
|
<update id="updatePlanReportRState">
|
||||||
|
update ad_plan
|
||||||
|
set Report_State = #{value}
|
||||||
|
where id = #{planId}
|
||||||
|
</update>
|
||||||
</mapper>
|
</mapper>
|
||||||
|
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ public class PqMonitorParam {
|
|||||||
private Integer statInterval;
|
private Integer statInterval;
|
||||||
|
|
||||||
@ApiModelProperty(value = "谐波系统监测点id")
|
@ApiModelProperty(value = "谐波系统监测点id")
|
||||||
@NotBlank(message = DetectionValidMessage.MONITOR_ID_NOT_BLANK)
|
// @NotBlank(message = DetectionValidMessage.MONITOR_ID_NOT_BLANK)
|
||||||
private String harmSysId;
|
private String harmSysId;
|
||||||
|
|
||||||
@ApiModelProperty(value = "是否做检测")
|
@ApiModelProperty(value = "是否做检测")
|
||||||
|
|||||||
@@ -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;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import com.njcn.gather.monitor.pojo.po.PqMonitor;
|
|||||||
import com.njcn.gather.plan.pojo.enums.DataSourceEnum;
|
import com.njcn.gather.plan.pojo.enums.DataSourceEnum;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author caozehui
|
* @author caozehui
|
||||||
@@ -112,4 +111,18 @@ public interface IPqMonitorService extends IService<PqMonitor> {
|
|||||||
*/
|
*/
|
||||||
Integer getDevCheckResult(String devId);
|
Integer getDevCheckResult(String devId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据被检设备id删除监测点信息
|
||||||
|
*
|
||||||
|
* @param devId
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
boolean removeByDevId(String devId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据被检设备id和监测点编号获取监测点信息
|
||||||
|
* @param devId 设备id
|
||||||
|
* @param monitorNum 监测点编号
|
||||||
|
*/
|
||||||
|
PqMonitor getByDevIdAndNum(String devId, int monitorNum);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,11 +10,15 @@ import com.njcn.common.pojo.exception.BusinessException;
|
|||||||
import com.njcn.gather.detection.util.socket.CnSocketUtil;
|
import com.njcn.gather.detection.util.socket.CnSocketUtil;
|
||||||
import com.njcn.gather.device.pojo.enums.CheckResultEnum;
|
import com.njcn.gather.device.pojo.enums.CheckResultEnum;
|
||||||
import com.njcn.gather.device.pojo.enums.CheckStateEnum;
|
import com.njcn.gather.device.pojo.enums.CheckStateEnum;
|
||||||
|
import com.njcn.gather.device.pojo.enums.DevReportStateEnum;
|
||||||
|
import com.njcn.gather.device.pojo.po.PqDevSub;
|
||||||
import com.njcn.gather.monitor.mapper.PqMonitorMapper;
|
import com.njcn.gather.monitor.mapper.PqMonitorMapper;
|
||||||
import com.njcn.gather.monitor.pojo.param.PqMonitorParam;
|
import com.njcn.gather.monitor.pojo.param.PqMonitorParam;
|
||||||
import com.njcn.gather.monitor.pojo.po.PqMonitor;
|
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.pojo.enums.PlanReportStateEnum;
|
||||||
|
import com.njcn.gather.plan.pojo.po.AdPlan;
|
||||||
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.storage.service.impl.DetectionDataServiceImpl;
|
import com.njcn.gather.storage.service.impl.DetectionDataServiceImpl;
|
||||||
@@ -26,6 +30,7 @@ import org.springframework.stereotype.Service;
|
|||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
@@ -62,11 +67,110 @@ public class PqMonitorServiceImpl extends ServiceImpl<PqMonitorMapper, PqMonitor
|
|||||||
@Transactional
|
@Transactional
|
||||||
public boolean updatePqMonitorByDevId(String devId, List<PqMonitorParam> paramList) {
|
public boolean updatePqMonitorByDevId(String devId, List<PqMonitorParam> paramList) {
|
||||||
// 先删除原有数据
|
// 先删除原有数据
|
||||||
this.deletePqMonitorByDevId(devId);
|
// this.deletePqMonitorByDevId(devId);
|
||||||
// 再添加新数据
|
|
||||||
|
// 添加新数据
|
||||||
List<PqMonitor> pqMonitorList = BeanUtil.copyToList(paramList, PqMonitor.class);
|
List<PqMonitor> pqMonitorList = BeanUtil.copyToList(paramList, PqMonitor.class);
|
||||||
pqMonitorList.forEach(pqMonitor -> pqMonitor.setDevId(devId));
|
pqMonitorList.forEach(pqMonitor -> pqMonitor.setDevId(devId));
|
||||||
return this.saveBatch(pqMonitorList);
|
|
||||||
|
List<PqMonitor> existedMonitorList = this.listPqMonitorByDevIds(Collections.singletonList(devId));
|
||||||
|
|
||||||
|
Map<Integer, List<PqMonitor>> map = pqMonitorList.stream().collect(Collectors.groupingBy(PqMonitor::getNum));
|
||||||
|
|
||||||
|
List<PqMonitor> newMonitorList = new ArrayList<>();
|
||||||
|
map.forEach((num, monitorList) -> {
|
||||||
|
PqMonitor pqMonitor = existedMonitorList.stream().filter(monitor -> monitor.getNum() == num).findFirst().orElse(null);
|
||||||
|
|
||||||
|
if (ObjectUtil.isNotNull(pqMonitor)) {
|
||||||
|
BeanUtil.copyProperties(monitorList.get(0), pqMonitor, "id", "realtimeResult", "statisticsResult", "recordedResult", "realtimeNum", "statisticsNum", "recordedNum", "resultType", "qualifiedNum");
|
||||||
|
newMonitorList.add(pqMonitor);
|
||||||
|
existedMonitorList.remove(pqMonitor);
|
||||||
|
} else {
|
||||||
|
newMonitorList.addAll(monitorList);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// 同步更新设备的状态
|
||||||
|
List<PqMonitor> enableCheckMonitorList = newMonitorList.stream().filter(pqMonitor -> pqMonitor.getCheckFlag() == 1).collect(Collectors.toList());
|
||||||
|
List<PqMonitor> checkedMonitorList = enableCheckMonitorList.stream().filter(pqMonitor -> ObjectUtil.isNotNull(pqMonitor.getResultType())).collect(Collectors.toList());
|
||||||
|
|
||||||
|
if (enableCheckMonitorList.size() == checkedMonitorList.size() && checkedMonitorList.size() > 0) {
|
||||||
|
this.baseMapper.updateDeviceCheckState(devId, CheckStateEnum.CHECKED.getValue());
|
||||||
|
this.baseMapper.updateDeviceReportRState(devId, DevReportStateEnum.NOT_GENERATED.getValue());
|
||||||
|
}
|
||||||
|
if (enableCheckMonitorList.size() > checkedMonitorList.size() && checkedMonitorList.size() > 0) {
|
||||||
|
this.baseMapper.updateDeviceCheckState(devId, CheckStateEnum.CHECKING.getValue());
|
||||||
|
this.baseMapper.updateDeviceReportRState(devId, DevReportStateEnum.NOT_GENERATED.getValue());
|
||||||
|
}
|
||||||
|
if (enableCheckMonitorList.size() > 0 && checkedMonitorList.size() == 0) {
|
||||||
|
this.baseMapper.updateDeviceCheckState(devId, CheckStateEnum.UNCHECKED.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
List<Integer> monitorResultList = checkedMonitorList.stream().map(pqMonitor -> {
|
||||||
|
String resultType = pqMonitor.getResultType();
|
||||||
|
DataSourceEnum dataSourceEnum = DataSourceEnum.ofByValue(resultType);
|
||||||
|
switch (dataSourceEnum) {
|
||||||
|
case REAL_DATA:
|
||||||
|
return pqMonitor.getRealtimeResult();
|
||||||
|
case WAVE_DATA:
|
||||||
|
return pqMonitor.getRecordedResult();
|
||||||
|
case MINUTE_STATISTICS_MAX:
|
||||||
|
case MINUTE_STATISTICS_MIN:
|
||||||
|
case MINUTE_STATISTICS_AVG:
|
||||||
|
case MINUTE_STATISTICS_CP95:
|
||||||
|
return pqMonitor.getStatisticsResult();
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}).collect(Collectors.toList());
|
||||||
|
|
||||||
|
long qualifiedCount = monitorResultList.stream().filter(result -> result != null && result == 1).count();
|
||||||
|
if (qualifiedCount == monitorResultList.size() && monitorResultList.size() > 0) {
|
||||||
|
this.baseMapper.updateDeviceCheckResult(devId, CheckResultEnum.ACCORD.getValue());
|
||||||
|
} else if (monitorResultList.size() > 0) {
|
||||||
|
this.baseMapper.updateDeviceCheckResult(devId, CheckResultEnum.NOT_ACCORD.getValue());
|
||||||
|
} else {
|
||||||
|
this.baseMapper.updateDeviceCheckResult(devId, CheckResultEnum.UNCHECKED.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
// 同步更新计划的状态
|
||||||
|
AdPlan plan = this.baseMapper.getPlanByDevId(devId);
|
||||||
|
if (ObjectUtil.isNotNull(plan)) {
|
||||||
|
|
||||||
|
|
||||||
|
List<PqDevSub> devSubList = this.baseMapper.listDevSubByPlanId(plan.getId());
|
||||||
|
|
||||||
|
List<PqDevSub> checkedDevSubList = devSubList.stream().filter(pqDevSub -> pqDevSub.getCheckState() == CheckStateEnum.CHECKED.getValue()).collect(Collectors.toList());
|
||||||
|
List<PqDevSub> checkingDevSubList = devSubList.stream().filter(pqDevSub -> pqDevSub.getCheckState() == CheckStateEnum.CHECKING.getValue()).collect(Collectors.toList());
|
||||||
|
if (checkedDevSubList.size() == devSubList.size() && devSubList.size() > 0) {
|
||||||
|
this.baseMapper.updatePlanCheckState(plan.getId(), CheckStateEnum.CHECKED.getValue());
|
||||||
|
} else if (checkedDevSubList.size() > 0 || checkingDevSubList.size() > 0) {
|
||||||
|
this.baseMapper.updatePlanCheckState(plan.getId(), CheckStateEnum.CHECKING.getValue());
|
||||||
|
} else {
|
||||||
|
this.baseMapper.updatePlanCheckState(plan.getId(), CheckStateEnum.UNCHECKED.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
List<PqDevSub> accordDevSubList = checkedDevSubList.stream().filter(pqDevSub -> pqDevSub.getCheckResult() == CheckResultEnum.ACCORD.getValue()).collect(Collectors.toList());
|
||||||
|
if (accordDevSubList.size() == checkedDevSubList.size() && checkedDevSubList.size() > 0) {
|
||||||
|
this.baseMapper.updatePlanCheckResult(plan.getId(), CheckResultEnum.ACCORD.getValue());
|
||||||
|
} else if (accordDevSubList.size() > 0) {
|
||||||
|
this.baseMapper.updatePlanCheckResult(plan.getId(), CheckResultEnum.NOT_ACCORD.getValue());
|
||||||
|
} else {
|
||||||
|
this.baseMapper.updatePlanCheckResult(plan.getId(), CheckResultEnum.UNCHECKED.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
List<PqDevSub> generatedDevSubList = checkedDevSubList.stream().filter(pqDevSub -> pqDevSub.getReportState() == DevReportStateEnum.GENERATED.getValue()).collect(Collectors.toList());
|
||||||
|
if (generatedDevSubList.size() == checkedDevSubList.size() && checkedDevSubList.size() > 0) {
|
||||||
|
this.baseMapper.updatePlanReportRState(plan.getId(), PlanReportStateEnum.REPORT_STATE_ALL_GENERATED.getValue());
|
||||||
|
} else if (generatedDevSubList.size() > 0) {
|
||||||
|
this.baseMapper.updatePlanReportRState(plan.getId(), PlanReportStateEnum.REPORT_STATE_PARTIALLY_GENERATED.getValue());
|
||||||
|
} else {
|
||||||
|
this.baseMapper.updatePlanReportRState(plan.getId(), PlanReportStateEnum.REPORT_STATE_NOT_GENERATED.getValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.removeByIds(existedMonitorList.stream().map(PqMonitor::getId).collect(Collectors.toList()));
|
||||||
|
return this.saveOrUpdateBatch(newMonitorList);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -163,10 +267,19 @@ public class PqMonitorServiceImpl extends ServiceImpl<PqMonitorMapper, PqMonitor
|
|||||||
} else {
|
} else {
|
||||||
newWaveNum.set(waveNum);
|
newWaveNum.set(waveNum);
|
||||||
newMonitorResult = waveNumResultMap.get(waveNum);
|
newMonitorResult = waveNumResultMap.get(waveNum);
|
||||||
|
if (newMonitorResult == 2) {
|
||||||
|
newMonitorResult = CheckResultEnum.NOT_ACCORD.getValue();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
newMonitorResult = detectionDataDealService.getMonitorResult(monitorId, adTypes, dataSourceEnum.getValue(), num, null, code);
|
newMonitorResult = detectionDataDealService.getMonitorResult(monitorId, adTypes, dataSourceEnum.getValue(), num, null, code);
|
||||||
|
if (newMonitorResult == 2) {
|
||||||
|
newMonitorResult = CheckResultEnum.NOT_ACCORD.getValue();
|
||||||
|
}
|
||||||
|
if (newMonitorResult == 1) {
|
||||||
|
newMonitorResult = CheckResultEnum.ACCORD.getValue();
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -188,7 +301,18 @@ public class PqMonitorServiceImpl extends ServiceImpl<PqMonitorMapper, PqMonitor
|
|||||||
|
|
||||||
if (CheckResultEnum.ACCORD.getValue().equals(oldMonitorResult)) {
|
if (CheckResultEnum.ACCORD.getValue().equals(oldMonitorResult)) {
|
||||||
if (CheckResultEnum.ACCORD.getValue().equals(newMonitorResult)) {
|
if (CheckResultEnum.ACCORD.getValue().equals(newMonitorResult)) {
|
||||||
qualifiedNum += 1;
|
String oldNum = "";
|
||||||
|
if (DataSourceEnum.REAL_DATA.getValue().equals(resultType)) {
|
||||||
|
oldNum = monitor.getRealtimeNum();
|
||||||
|
} else if (DataSourceEnum.WAVE_DATA.getValue().equals(resultType)) {
|
||||||
|
oldNum = monitor.getRecordedNum();
|
||||||
|
} else {
|
||||||
|
oldNum = monitor.getStatisticsNum();
|
||||||
|
}
|
||||||
|
String[] split1 = oldNum.split(CnSocketUtil.SPLIT_TAG);
|
||||||
|
if (!split1[0].equals(num.toString())) {
|
||||||
|
qualifiedNum += 1;
|
||||||
|
}
|
||||||
updateFlag = true;
|
updateFlag = true;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -269,15 +393,61 @@ public class PqMonitorServiceImpl extends ServiceImpl<PqMonitorMapper, PqMonitor
|
|||||||
String resultType = monitor.getResultType();
|
String resultType = monitor.getResultType();
|
||||||
if (StrUtil.isNotBlank(resultType)) {
|
if (StrUtil.isNotBlank(resultType)) {
|
||||||
if (DataSourceEnum.REAL_DATA.getValue().equals(resultType)) {
|
if (DataSourceEnum.REAL_DATA.getValue().equals(resultType)) {
|
||||||
allResultFlags.add(monitor.getRealtimeResult());
|
//allResultFlags.add(monitor.getRealtimeResult());
|
||||||
|
if (monitor.getRealtimeResult() == 0) {
|
||||||
|
allResultFlags.add(2);
|
||||||
|
}
|
||||||
|
if (monitor.getRealtimeResult() == 1) {
|
||||||
|
allResultFlags.add(1);
|
||||||
|
}
|
||||||
|
if (monitor.getRealtimeResult() == 4) {
|
||||||
|
allResultFlags.add(4);
|
||||||
|
}
|
||||||
} else if (DataSourceEnum.WAVE_DATA.getValue().equals(resultType)) {
|
} else if (DataSourceEnum.WAVE_DATA.getValue().equals(resultType)) {
|
||||||
allResultFlags.add(monitor.getRecordedResult());
|
//allResultFlags.add(monitor.getRecordedResult());
|
||||||
|
if (monitor.getRecordedResult() == 0) {
|
||||||
|
allResultFlags.add(2);
|
||||||
|
}
|
||||||
|
if (monitor.getRecordedResult() == 1) {
|
||||||
|
allResultFlags.add(1);
|
||||||
|
}
|
||||||
|
if (monitor.getRecordedResult() == 4) {
|
||||||
|
allResultFlags.add(4);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
allResultFlags.add(monitor.getStatisticsResult());
|
//allResultFlags.add(monitor.getStatisticsResult());
|
||||||
|
if (monitor.getStatisticsResult() == 0) {
|
||||||
|
allResultFlags.add(2);
|
||||||
|
}
|
||||||
|
if (monitor.getStatisticsResult() == 1) {
|
||||||
|
allResultFlags.add(1);
|
||||||
|
}
|
||||||
|
if (monitor.getStatisticsResult() == 4) {
|
||||||
|
allResultFlags.add(4);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return DetectionDataServiceImpl.isResultFlag(allResultFlags);
|
return DetectionDataServiceImpl.isResultFlag(allResultFlags);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean removeByDevId(String devId) {
|
||||||
|
QueryWrapper<PqMonitor> wrapper = new QueryWrapper<>();
|
||||||
|
wrapper.eq("pq_monitor.Dev_Id", devId);
|
||||||
|
return this.remove(wrapper);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PqMonitor getByDevIdAndNum(String devId, int monitorNum) {
|
||||||
|
QueryWrapper<PqMonitor> wrapper = new QueryWrapper<>();
|
||||||
|
wrapper.eq("pq_monitor.Dev_Id", devId)
|
||||||
|
.eq("pq_monitor.Num", monitorNum);
|
||||||
|
List<PqMonitor> pqMonitors = this.list(wrapper);
|
||||||
|
if (CollUtil.isNotEmpty(pqMonitors)) {
|
||||||
|
return pqMonitors.get(0);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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;
|
||||||
@@ -42,6 +43,8 @@ import org.springframework.web.bind.annotation.*;
|
|||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -178,7 +181,7 @@ public class AdPlanController extends BaseController {
|
|||||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||||
@PostMapping("/getBigTestItem")
|
@PostMapping("/getBigTestItem")
|
||||||
@ApiOperation("获取检测大项数据")
|
@ApiOperation("获取检测大项数据")
|
||||||
@ApiImplicitParam(name = "id", value = "检测计划id", required = true)
|
@ApiImplicitParam(name = "checkParam", value = "检测计划id", required = true)
|
||||||
public HttpResult<List<Map<String, String>>> getBigTestItem(@RequestBody AdPlanParam.CheckParam checkParam) {
|
public HttpResult<List<Map<String, String>>> getBigTestItem(@RequestBody AdPlanParam.CheckParam checkParam) {
|
||||||
String methodDescribe = getMethodDescribe("getBigTestItem");
|
String methodDescribe = getMethodDescribe("getBigTestItem");
|
||||||
LogUtil.njcnDebug(log, "{},查询数据为:{}", methodDescribe, checkParam);
|
LogUtil.njcnDebug(log, "{},查询数据为:{}", methodDescribe, checkParam);
|
||||||
@@ -189,17 +192,28 @@ public class AdPlanController extends BaseController {
|
|||||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON, operateType = OperateType.DOWNLOAD)
|
@OperateInfo(info = LogEnum.BUSINESS_COMMON, operateType = OperateType.DOWNLOAD)
|
||||||
@PostMapping("/analyse")
|
@PostMapping("/analyse")
|
||||||
@ApiOperation("检测数据分析")
|
@ApiOperation("检测数据分析")
|
||||||
@ApiImplicitParam(name = "planId", value = "检测计划id", required = true)
|
@ApiImplicitParam(name = "ids", value = "检测计划id", required = true)
|
||||||
public void analyse(@RequestBody List<String> ids) {
|
public void analyse(@RequestBody List<String> ids) {
|
||||||
String methodDescribe = getMethodDescribe("analyse");
|
String methodDescribe = getMethodDescribe("analyse");
|
||||||
LogUtil.njcnDebug(log, "{},查询数据为:{}", methodDescribe, String.join(StrUtil.COMMA, ids));
|
LogUtil.njcnDebug(log, "{},查询数据为:{}", methodDescribe, String.join(StrUtil.COMMA, ids));
|
||||||
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("查询出所有已绑定的设备")
|
||||||
@ApiImplicitParam(name = "planId", value = "计划id", required = true)
|
@ApiImplicitParam(name = "param", value = "查询参数", required = true)
|
||||||
public HttpResult<List<PqDevVO>> listByPlanId(@RequestBody @Validated PqDevParam.QueryParam param) {
|
public HttpResult<List<PqDevVO>> listByPlanId(@RequestBody @Validated PqDevParam.QueryParam param) {
|
||||||
String methodDescribe = getMethodDescribe("listByPlanId");
|
String methodDescribe = getMethodDescribe("listByPlanId");
|
||||||
LogUtil.njcnDebug(log, "{},查询数据为:{}", methodDescribe, param);
|
LogUtil.njcnDebug(log, "{},查询数据为:{}", methodDescribe, param);
|
||||||
@@ -239,7 +253,7 @@ public class AdPlanController extends BaseController {
|
|||||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||||
@PostMapping("/listDevByPlanId")
|
@PostMapping("/listDevByPlanId")
|
||||||
@ApiOperation("根据计划id分页查询被检设备")
|
@ApiOperation("根据计划id分页查询被检设备")
|
||||||
@ApiImplicitParam(name = "queryParam", value = "查询参数", required = true)
|
@ApiImplicitParam(name = "param", value = "查询参数", required = true)
|
||||||
public HttpResult<Page<PqDevVO>> listDevByPlanId(@RequestBody @Validated PqDevParam.QueryParam param) {
|
public HttpResult<Page<PqDevVO>> listDevByPlanId(@RequestBody @Validated PqDevParam.QueryParam param) {
|
||||||
String methodDescribe = getMethodDescribe("listDevByPlanId");
|
String methodDescribe = getMethodDescribe("listDevByPlanId");
|
||||||
LogUtil.njcnDebug(log, "{},查询数据为:{}", methodDescribe, param);
|
LogUtil.njcnDebug(log, "{},查询数据为:{}", methodDescribe, param);
|
||||||
@@ -452,7 +466,17 @@ public class AdPlanController extends BaseController {
|
|||||||
fileTypeError.setMessage("请上传zip文件");
|
fileTypeError.setMessage("请上传zip文件");
|
||||||
throw new BusinessException(fileTypeError);
|
throw new BusinessException(fileTypeError);
|
||||||
}
|
}
|
||||||
asyncPlanHandler.importAndMergePlanCheckData(file, getUserId(), planId);
|
// 创建临时文件
|
||||||
|
File tempFile = cn.hutool.core.io.FileUtil.createTempFile();
|
||||||
|
// 将MultipartFile内容写入临时文件
|
||||||
|
try {
|
||||||
|
file.transferTo(tempFile);
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new BusinessException(CommonResponseEnum.FAIL, "文件保存失败");
|
||||||
|
}
|
||||||
|
// 获取文件路径
|
||||||
|
String filePath = tempFile.getAbsolutePath();
|
||||||
|
asyncPlanHandler.importAndMergePlanCheckData(filePath, getUserId(), planId);
|
||||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, methodDescribe);
|
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, methodDescribe);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,13 +29,4 @@ public interface AdPlanMapper extends MPJBaseMapper<AdPlan> {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
PqReport getPqReportById(String id);
|
PqReport getPqReportById(String id);
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取所有报告模板名称
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
List<String> listAllReportTemplateName();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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);
|
||||||
|
}
|
||||||
@@ -2,7 +2,6 @@
|
|||||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
<!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.AdPlanMapper">
|
<mapper namespace="com.njcn.gather.plan.mapper.AdPlanMapper">
|
||||||
|
|
||||||
|
|
||||||
<select id="getReportIdByNameAndVersion" resultType="java.lang.String">
|
<select id="getReportIdByNameAndVersion" resultType="java.lang.String">
|
||||||
SELECT id
|
SELECT id
|
||||||
FROM pq_report
|
FROM pq_report
|
||||||
@@ -17,10 +16,4 @@
|
|||||||
WHERE id = #{id}
|
WHERE id = #{id}
|
||||||
and state = 1
|
and state = 1
|
||||||
</select>
|
</select>
|
||||||
<select id="listAllReportTemplateName" resultType="java.lang.String">
|
|
||||||
SELECT concat(name, '_', version) as name
|
|
||||||
FROM pq_report
|
|
||||||
WHERE state = 1
|
|
||||||
</select>
|
|
||||||
</mapper>
|
</mapper>
|
||||||
|
|
||||||
|
|||||||
@@ -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>
|
||||||
@@ -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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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;
|
||||||
|
}
|
||||||
@@ -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;
|
||||||
|
}
|
||||||
@@ -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;
|
||||||
|
}
|
||||||
@@ -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;
|
||||||
|
}
|
||||||
@@ -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;
|
||||||
@@ -37,10 +38,8 @@ import org.springframework.scheduling.annotation.Async;
|
|||||||
import org.springframework.scheduling.annotation.EnableAsync;
|
import org.springframework.scheduling.annotation.EnableAsync;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
|
||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -65,10 +64,12 @@ public class AsyncPlanHandler {
|
|||||||
private final IAdPariService adPairService;
|
private final IAdPariService adPairService;
|
||||||
|
|
||||||
private final JdbcTemplate jdbcTemplate;
|
private final JdbcTemplate jdbcTemplate;
|
||||||
@Value("${report.reportDir}")
|
|
||||||
private String reportPath;
|
private final PathConfig pathConfig;
|
||||||
@Value("${data.homeDir}")
|
// @Value("${report.reportDir}")
|
||||||
private String dataPath;
|
// private String reportPath;
|
||||||
|
// @Value("${data.homeDir}")
|
||||||
|
// 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)) {
|
||||||
@@ -235,35 +236,28 @@ public class AsyncPlanHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Transactional
|
|
||||||
@Async
|
@Async
|
||||||
public void importAndMergePlanCheckData(MultipartFile file, String uid, String planId) {
|
public void importAndMergePlanCheckData(String zipFilePath, String uid, String planId) {
|
||||||
|
importAndMergePlanCheckDataLogic(zipFilePath, uid, planId);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
public void importAndMergePlanCheckDataLogic(String zipFilePath, String uid, String planId) {
|
||||||
NonWebAutoFillValueHandler.setCurrentUserId(uid);
|
NonWebAutoFillValueHandler.setCurrentUserId(uid);
|
||||||
LocalDateTime startTime = LocalDateTime.now();
|
LocalDateTime startTime = LocalDateTime.now();
|
||||||
AtomicInteger progress = new AtomicInteger(0);
|
AtomicInteger progress = new AtomicInteger(0);
|
||||||
AtomicInteger currentProgress = new AtomicInteger(0);
|
AtomicInteger currentProgress = new AtomicInteger(0);
|
||||||
AtomicInteger dataCount = new AtomicInteger(0);
|
AtomicInteger dataCount = new AtomicInteger(0);
|
||||||
try {
|
try {
|
||||||
sseClient.sendMessage(uid, planId, HttpResultUtil.assembleResult(CommonResponseEnum.SUCCESS.getCode(), progress, "开始保存文件,请耐心等待..."));
|
|
||||||
// 创建临时目录用于解压文件
|
// 创建临时目录用于解压文件
|
||||||
File tempDir = FileUtil.mkdir(FileUtil.getTmpDirPath() + "import_plan_check_data_" + System.currentTimeMillis() + "/");
|
File tempDir = FileUtil.mkdir(FileUtil.getTmpDirPath() + "import_plan_check_data_" + System.currentTimeMillis() + "/");
|
||||||
|
|
||||||
// 将上传的zip文件保存到临时目录
|
|
||||||
File zipFile = FileUtil.file(tempDir, file.getOriginalFilename());
|
|
||||||
try {
|
|
||||||
// 直接获取文件字节,避免依赖Tomcat临时文件
|
|
||||||
byte[] fileBytes = file.getBytes();
|
|
||||||
FileUtil.writeBytes(fileBytes, zipFile);
|
|
||||||
} catch (IOException e) {
|
|
||||||
log.error("保存上传文件失败", e);
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
progress.addAndGet(1);
|
progress.addAndGet(1);
|
||||||
sseClient.sendMessage(uid, planId, HttpResultUtil.assembleResult(CommonResponseEnum.SUCCESS.getCode(), progress, "开始解压文件,请耐心等待..."));
|
sseClient.sendMessage(uid, planId, HttpResultUtil.assembleResult(CommonResponseEnum.SUCCESS.getCode(), progress, "开始解压文件,请耐心等待..."));
|
||||||
|
|
||||||
// 解压zip文件
|
// 解压zip文件
|
||||||
File unzipDir = FileUtil.mkdir(FileUtil.file(tempDir, "unzip"));
|
File unzipDir = FileUtil.mkdir(FileUtil.file(tempDir, "unzip"));
|
||||||
ZipUtil.unzip(zipFile.getAbsolutePath(), unzipDir.getAbsolutePath());
|
ZipUtil.unzip(zipFilePath, unzipDir.getAbsolutePath());
|
||||||
|
|
||||||
// 查找解压目录中的json文件
|
// 查找解压目录中的json文件
|
||||||
File[] files = unzipDir.listFiles();
|
File[] files = unzipDir.listFiles();
|
||||||
@@ -351,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())) {
|
||||||
@@ -464,14 +458,14 @@ public class AsyncPlanHandler {
|
|||||||
sseClient.sendMessage(uid, planId, HttpResultUtil.assembleResult(CommonResponseEnum.SUCCESS.getCode(), progress, "数据合并完成"));
|
sseClient.sendMessage(uid, planId, HttpResultUtil.assembleResult(CommonResponseEnum.SUCCESS.getCode(), progress, "数据合并完成"));
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|
||||||
log.error("导入数据失败", e);
|
log.error("导入数据失败", e);
|
||||||
sseClient.sendMessage(uid, planId, HttpResultUtil.assembleResult(CommonResponseEnum.FAIL.getCode(), progress.get() + currentProgress.get(), "导入失败"));
|
sseClient.sendMessage(uid, planId, HttpResultUtil.assembleResult(CommonResponseEnum.FAIL.getCode(), progress.get() + currentProgress.get(), "导入失败"));
|
||||||
} finally {
|
} finally {
|
||||||
NonWebAutoFillValueHandler.clearCurrentUserId();
|
NonWebAutoFillValueHandler.clearCurrentUserId();
|
||||||
}
|
}
|
||||||
|
FileUtil.del(zipFilePath);
|
||||||
sseClient.closeSse(uid);
|
sseClient.closeSse(uid);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 构建分页查询SQL
|
// 构建分页查询SQL
|
||||||
|
|||||||
@@ -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);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 导出检测计划数据
|
* 导出检测计划数据
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -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);
|
||||||
|
}
|
||||||
@@ -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) {
|
||||||
@@ -207,7 +216,7 @@ public class AdPlanServiceImpl extends ServiceImpl<AdPlanMapper, AdPlan> impleme
|
|||||||
}
|
}
|
||||||
List<PqDevVO> pqDevVOList = pqDevMapper.selectByQueryParam(queryParam1);
|
List<PqDevVO> pqDevVOList = pqDevMapper.selectByQueryParam(queryParam1);
|
||||||
if (CollUtil.isNotEmpty(pqDevVOList)) {
|
if (CollUtil.isNotEmpty(pqDevVOList)) {
|
||||||
long count = pqDevVOList.stream().filter(pqDev -> CheckStateEnum.CHECKED.getValue().equals(pqDev.getCheckState())).count();
|
long count = pqDevVOList.stream().filter(pqDev -> CheckStateEnum.CHECKED.getValue().equals(pqDev.getCheckState()) || CheckStateEnum.DOCUMENTED.getValue().equals(pqDev.getCheckState())).count();
|
||||||
adPlanVO.setProgress((float) count / pqDevVOList.size());
|
adPlanVO.setProgress((float) count / pqDevVOList.size());
|
||||||
} else {
|
} else {
|
||||||
adPlanVO.setProgress(0.0f);
|
adPlanVO.setProgress(0.0f);
|
||||||
@@ -531,7 +540,7 @@ public class AdPlanServiceImpl extends ServiceImpl<AdPlanMapper, AdPlan> impleme
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Map<String, Object>> listByPattern(String pattern) {
|
public List<Map<String, Object>> listByPattern(String pattern) {
|
||||||
List<AdPlan> adPlanList = this.lambdaQuery().eq(AdPlan::getPattern, pattern).eq(AdPlan::getState, DataStateEnum.ENABLE.getCode()).list();
|
List<AdPlan> adPlanList = this.lambdaQuery().eq(AdPlan::getPattern, pattern).eq(AdPlan::getState, DataStateEnum.ENABLE.getCode()).orderByDesc(AdPlan::getCreateTime).list();
|
||||||
Map<Integer, List<AdPlan>> map1 = adPlanList.stream().collect(Collectors.groupingBy(AdPlan::getTestState));
|
Map<Integer, List<AdPlan>> map1 = adPlanList.stream().collect(Collectors.groupingBy(AdPlan::getTestState));
|
||||||
|
|
||||||
List<Map<String, Object>> result = new ArrayList<>();
|
List<Map<String, Object>> result = new ArrayList<>();
|
||||||
@@ -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());
|
||||||
@@ -630,7 +641,7 @@ public class AdPlanServiceImpl extends ServiceImpl<AdPlanMapper, AdPlan> impleme
|
|||||||
|| datasourceId.contains(DataSourceEnum.MINUTE_STATISTICS_MAX.getValue())
|
|| datasourceId.contains(DataSourceEnum.MINUTE_STATISTICS_MAX.getValue())
|
||||||
|| datasourceId.contains(DataSourceEnum.MINUTE_STATISTICS_MIN.getValue())) {
|
|| datasourceId.contains(DataSourceEnum.MINUTE_STATISTICS_MIN.getValue())) {
|
||||||
String[] split = adPlan.getTestItem().split(StrUtil.COMMA);
|
String[] split = adPlan.getTestItem().split(StrUtil.COMMA);
|
||||||
List<DictTree> dictTreeList = dictTreeService.list(new QueryWrapper<DictTree>().in("id", split).eq("state", DataStateEnum.DELETED.getCode()));
|
List<DictTree> dictTreeList = dictTreeService.list(new QueryWrapper<DictTree>().in("id", split).eq("state", DataStateEnum.DELETED.getCode()).orderByAsc("sort"));
|
||||||
|
|
||||||
for (DictTree dictTree : dictTreeList) {
|
for (DictTree dictTree : dictTreeList) {
|
||||||
Map<String, String> map = new HashMap<>();
|
Map<String, String> map = new HashMap<>();
|
||||||
@@ -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);
|
||||||
@@ -1611,7 +1906,9 @@ public class AdPlanServiceImpl extends ServiceImpl<AdPlanMapper, AdPlan> impleme
|
|||||||
pullDowns.add(pullDown);
|
pullDowns.add(pullDown);
|
||||||
|
|
||||||
// 报告模板
|
// 报告模板
|
||||||
List<String> strings = this.baseMapper.listAllReportTemplateName();
|
List<String> strings = SpringUtil.getBean(IPqReportService.class).listOptions(patternId).stream()
|
||||||
|
.map(option -> option.getDisplayName())
|
||||||
|
.collect(Collectors.toList());
|
||||||
pullDown = new PullDown();
|
pullDown = new PullDown();
|
||||||
pullDown.setFirstCol(8);
|
pullDown.setFirstCol(8);
|
||||||
pullDown.setLastCol(8);
|
pullDown.setLastCol(8);
|
||||||
@@ -1721,8 +2018,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 +2041,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 +2076,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 +2385,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 +2396,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);
|
||||||
|
|||||||
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -73,8 +73,9 @@ public enum DetectionResponseEnum {
|
|||||||
MONITOR_NUM_REPEAT("A02094", "该被检设备下存在相同线路号的监测点"),
|
MONITOR_NUM_REPEAT("A02094", "该被检设备下存在相同线路号的监测点"),
|
||||||
PLAN_HAS_CHILDREN("A02095", "该计划下存在子计划,请先删除子计划"),
|
PLAN_HAS_CHILDREN("A02095", "该计划下存在子计划,请先删除子计划"),
|
||||||
PLAN_REPEATED_IN_SAME_LEVEL("A02096", "该父计划下存在同名的子计划"),
|
PLAN_REPEATED_IN_SAME_LEVEL("A02096", "该父计划下存在同名的子计划"),
|
||||||
PLEASE_UNASSIGN_STANDARD_DEV("A02097","存在已分配给子计划的标准设备,请先解除分配" ),
|
PLEASE_UNASSIGN_STANDARD_DEV("A02097", "存在已分配给子计划的标准设备,请先解除分配"),
|
||||||
PLEASE_UNASSIGN_DEVICE("A02098", "存在已分配给计划的被检设备,请先解除分配");
|
PLEASE_UNASSIGN_DEVICE("A02098", "存在已分配给计划的被检设备,请先解除分配"),
|
||||||
|
DEV_IP_PORT_EXIST("A02099", "存在重复被检设备");
|
||||||
|
|
||||||
private final String code;
|
private final String code;
|
||||||
|
|
||||||
|
|||||||
@@ -31,22 +31,22 @@ import java.util.List;
|
|||||||
* @data 2025/1/9 14:02
|
* @data 2025/1/9 14:02
|
||||||
*/
|
*/
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Api(tags = "报表管理")
|
@Api(tags = "报告管理")
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/report")
|
@RequestMapping("/report")
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class ReportController extends BaseController {
|
public class ReportController extends BaseController {
|
||||||
|
|
||||||
private final IPqReportService pqReportService;
|
private final IPqReportService pqReportService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 此方法临时的,给楼下使用,实际需要优化
|
* 此方法临时的,给楼下使用,实际需要优化
|
||||||
* 1、不同的设备需要不同的模板;
|
* 1、不同的设备需要不同的模板;
|
||||||
* 2、数据页的内容暂时是固定的,后期可能是动态的;
|
* 2、数据页的内容暂时是固定的,后期可能是动态 的;
|
||||||
*/
|
*/
|
||||||
@OperateInfo
|
@OperateInfo
|
||||||
@PostMapping("/generateReport")
|
@PostMapping("/generateReport")
|
||||||
@ApiOperation("生成测试报告")
|
@ApiOperation("生成报告")
|
||||||
@ApiImplicitParam(name = "param", value = "查询参数", required = true)
|
@ApiImplicitParam(name = "param", value = "查询参数", required = true)
|
||||||
public HttpResult<Object> generateReport(@RequestBody DevReportParam devReportParam) {
|
public HttpResult<Object> generateReport(@RequestBody DevReportParam devReportParam) {
|
||||||
String methodDescribe = getMethodDescribe("generateReport");
|
String methodDescribe = getMethodDescribe("generateReport");
|
||||||
@@ -60,7 +60,7 @@ public class ReportController extends BaseController {
|
|||||||
*/
|
*/
|
||||||
@OperateInfo
|
@OperateInfo
|
||||||
@PostMapping("/downloadReport")
|
@PostMapping("/downloadReport")
|
||||||
@ApiOperation("下载测试报告")
|
@ApiOperation("下载报告")
|
||||||
@ApiImplicitParam(name = "param", value = "查询参数", required = true)
|
@ApiImplicitParam(name = "param", value = "查询参数", required = true)
|
||||||
public void downloadReport(@RequestBody DevReportParam devReportParam, HttpServletResponse response) {
|
public void downloadReport(@RequestBody DevReportParam devReportParam, HttpServletResponse response) {
|
||||||
String methodDescribe = getMethodDescribe("downloadReport");
|
String methodDescribe = getMethodDescribe("downloadReport");
|
||||||
@@ -91,7 +91,7 @@ public class ReportController extends BaseController {
|
|||||||
@OperateInfo(operateType = OperateType.ADD)
|
@OperateInfo(operateType = OperateType.ADD)
|
||||||
@PostMapping("/add")
|
@PostMapping("/add")
|
||||||
@ApiOperation("新增报告模板")
|
@ApiOperation("新增报告模板")
|
||||||
@ApiImplicitParam(name = "param", value = "报告模板参数", required = true)
|
@ApiImplicitParam(name = "reportParam", value = "报告模板参数", required = true)
|
||||||
public HttpResult<Boolean> add(ReportParam reportParam) {
|
public HttpResult<Boolean> add(ReportParam reportParam) {
|
||||||
String methodDescribe = getMethodDescribe("add");
|
String methodDescribe = getMethodDescribe("add");
|
||||||
LogUtil.njcnDebug(log, "{},新增参数为:{}", methodDescribe, reportParam);
|
LogUtil.njcnDebug(log, "{},新增参数为:{}", methodDescribe, reportParam);
|
||||||
@@ -106,7 +106,7 @@ public class ReportController extends BaseController {
|
|||||||
@OperateInfo(operateType = OperateType.UPDATE)
|
@OperateInfo(operateType = OperateType.UPDATE)
|
||||||
@PostMapping("/update")
|
@PostMapping("/update")
|
||||||
@ApiOperation("更新报告模板")
|
@ApiOperation("更新报告模板")
|
||||||
@ApiImplicitParam(name = "param", value = "报告模板参数", required = true)
|
@ApiImplicitParam(name = "reportParam", value = "报告模板参数", required = true)
|
||||||
public HttpResult<Boolean> update(ReportParam.UpdateParam reportParam) {
|
public HttpResult<Boolean> update(ReportParam.UpdateParam reportParam) {
|
||||||
String methodDescribe = getMethodDescribe("update");
|
String methodDescribe = getMethodDescribe("update");
|
||||||
LogUtil.njcnDebug(log, "{},修改参数为:{}", methodDescribe, reportParam);
|
LogUtil.njcnDebug(log, "{},修改参数为:{}", methodDescribe, reportParam);
|
||||||
@@ -134,18 +134,18 @@ public class ReportController extends BaseController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@OperateInfo
|
@OperateInfo
|
||||||
@GetMapping("/listAllName")
|
@GetMapping("/listOptions")
|
||||||
@ApiOperation("查询所有报告模板名称")
|
@ApiOperation("查询所有报告模板名称")
|
||||||
@ApiImplicitParam(name = "param", value = "查询参数", required = true)
|
public HttpResult<List<PqReportVO.OptionVO>> listOptions(@RequestParam("pattern") String pattern) {
|
||||||
public HttpResult<List<String>> listAllName() {
|
String methodDescribe = getMethodDescribe("listOptions");
|
||||||
String methodDescribe = getMethodDescribe("listAllName");
|
LogUtil.njcnDebug(log, "{}锛屾煡璇㈠弬鏁颁负锛歿}", methodDescribe, pattern);
|
||||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, pqReportService.listAllName(), methodDescribe);
|
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, pqReportService.listOptions(pattern), methodDescribe);
|
||||||
}
|
}
|
||||||
|
|
||||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON, operateType = OperateType.UPDATE)
|
@OperateInfo(info = LogEnum.BUSINESS_COMMON, operateType = OperateType.UPDATE)
|
||||||
@PostMapping("/documented")
|
@PostMapping("/documented")
|
||||||
@ApiOperation("设备归档")
|
@ApiOperation("设备归档")
|
||||||
@ApiImplicitParam(name = "id", value = "设备id", required = true)
|
@ApiImplicitParam(name = "ids", value = "设备id", required = true)
|
||||||
public HttpResult<Boolean> documented(@RequestBody List<String> ids) {
|
public HttpResult<Boolean> documented(@RequestBody List<String> ids) {
|
||||||
String methodDescribe = getMethodDescribe("documented");
|
String methodDescribe = getMethodDescribe("documented");
|
||||||
LogUtil.njcnDebug(log, "{},设备id为:{}", methodDescribe, ids);
|
LogUtil.njcnDebug(log, "{},设备id为:{}", methodDescribe, ids);
|
||||||
|
|||||||
@@ -2,18 +2,17 @@ package com.njcn.gather.report.mapper;
|
|||||||
|
|
||||||
import com.github.yulichang.base.MPJBaseMapper;
|
import com.github.yulichang.base.MPJBaseMapper;
|
||||||
import com.njcn.gather.report.pojo.po.PqReport;
|
import com.njcn.gather.report.pojo.po.PqReport;
|
||||||
|
import com.njcn.gather.report.pojo.vo.PqReportVO;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
|
||||||
* @author makejava
|
|
||||||
* @date 2025-03-19
|
|
||||||
*/
|
|
||||||
public interface PqReportMapper extends MPJBaseMapper<PqReport> {
|
public interface PqReportMapper extends MPJBaseMapper<PqReport> {
|
||||||
/**
|
/**
|
||||||
* 获取所有已被计划绑定的报告模板id
|
* 获取所有已被计划绑定的报告模板id
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
List<String> getBoundReportIds();
|
List<String> getBoundReportIds();
|
||||||
}
|
|
||||||
|
|
||||||
|
List<PqReportVO.OptionVO> listOptionsByPattern(@Param("pattern") String pattern);
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,9 +2,19 @@
|
|||||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
<mapper namespace="com.njcn.gather.report.mapper.PqReportMapper">
|
<mapper namespace="com.njcn.gather.report.mapper.PqReportMapper">
|
||||||
|
|
||||||
|
|
||||||
<select id="getBoundReportIds" resultType="java.lang.String">
|
<select id="getBoundReportIds" resultType="java.lang.String">
|
||||||
select distinct Report_Template_Id from ad_plan where state = 1
|
select distinct Report_Template_Id from ad_plan where state = 1
|
||||||
</select>
|
</select>
|
||||||
</mapper>
|
|
||||||
|
|
||||||
|
<select id="listOptionsByPattern" resultType="com.njcn.gather.report.pojo.vo.PqReportVO$OptionVO">
|
||||||
|
select
|
||||||
|
id,
|
||||||
|
name,
|
||||||
|
version,
|
||||||
|
concat(name, '_', version) as displayName
|
||||||
|
from pq_report
|
||||||
|
where state = 1
|
||||||
|
and pattern = #{pattern}
|
||||||
|
order by update_time desc
|
||||||
|
</select>
|
||||||
|
</mapper>
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ public enum BaseReportKeyEnum {
|
|||||||
DAY("day","日"),
|
DAY("day","日"),
|
||||||
YEAR_MONTH_DAY("year-month-day","年-月-日"),
|
YEAR_MONTH_DAY("year-month-day","年-月-日"),
|
||||||
REPORT_DATE("reportDate","年-月-日"),
|
REPORT_DATE("reportDate","年-月-日"),
|
||||||
|
GD_NAME("gdName","供电部门"),
|
||||||
SUB_NAME("subName","变电站"),
|
SUB_NAME("subName","变电站"),
|
||||||
CHECK_BY("checkBy","检测人"),
|
CHECK_BY("checkBy","检测人"),
|
||||||
AUDIT_BY("auditBy","负责人、审核人"),
|
AUDIT_BY("auditBy","负责人、审核人"),
|
||||||
@@ -38,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;
|
||||||
|
|
||||||
|
|||||||
@@ -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) {
|
||||||
|
|||||||
@@ -6,10 +6,6 @@ import lombok.Data;
|
|||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
/**
|
|
||||||
* @author caozehui
|
|
||||||
* @data 2025-03-19
|
|
||||||
*/
|
|
||||||
@Data
|
@Data
|
||||||
public class ReportParam {
|
public class ReportParam {
|
||||||
|
|
||||||
@@ -19,23 +15,29 @@ public class ReportParam {
|
|||||||
@ApiModelProperty(value = "版本号", required = true)
|
@ApiModelProperty(value = "版本号", required = true)
|
||||||
private String version;
|
private String version;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "模式id", required = true)
|
||||||
|
private String pattern;
|
||||||
|
|
||||||
@ApiModelProperty(value = "描述信息", required = true)
|
@ApiModelProperty(value = "描述信息", required = true)
|
||||||
private String description;
|
private String description;
|
||||||
|
|
||||||
@ApiModelProperty(value = "基础模板文件", required = true)
|
@ApiModelProperty(value = "基础模板文件", required = true)
|
||||||
private MultipartFile baseFile;
|
private MultipartFile baseFile;
|
||||||
|
|
||||||
@ApiModelProperty(value = "检测项模版文件", required = true)
|
@ApiModelProperty(value = "检测项模板文件", required = true)
|
||||||
private MultipartFile detailFile;
|
private MultipartFile detailFile;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
@EqualsAndHashCode(callSuper = true)
|
@EqualsAndHashCode(callSuper = true)
|
||||||
public static class QueryParam extends BaseParam {
|
public static class QueryParam extends BaseParam {
|
||||||
@ApiModelProperty(value = "报告模板名称", required = true)
|
@ApiModelProperty(value = "报告模板名称")
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
@ApiModelProperty(value = "版本号", required = true)
|
@ApiModelProperty(value = "版本号")
|
||||||
private String version;
|
private String version;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "模式id", required = true)
|
||||||
|
private String pattern;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
|
|||||||
@@ -6,17 +6,13 @@ import lombok.Data;
|
|||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.time.LocalDateTime;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author makejava
|
|
||||||
* @date 2025-03-19
|
|
||||||
*/
|
|
||||||
@Data
|
@Data
|
||||||
@EqualsAndHashCode(callSuper = true)
|
@EqualsAndHashCode(callSuper = true)
|
||||||
@TableName("pq_report")
|
@TableName("pq_report")
|
||||||
public class PqReport extends BaseEntity implements Serializable {
|
public class PqReport extends BaseEntity implements Serializable {
|
||||||
private static final long serialVersionUID = 582972970946593407L;
|
private static final long serialVersionUID = 582972970946593407L;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 报告模板id
|
* 报告模板id
|
||||||
*/
|
*/
|
||||||
@@ -32,13 +28,18 @@ public class PqReport extends BaseEntity implements Serializable {
|
|||||||
*/
|
*/
|
||||||
private String version;
|
private String version;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 模式id
|
||||||
|
*/
|
||||||
|
private String pattern;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 基础模板文件路径
|
* 基础模板文件路径
|
||||||
*/
|
*/
|
||||||
private String basePath;
|
private String basePath;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 检测项模版文件路径
|
* 检测项模板文件路径
|
||||||
*/
|
*/
|
||||||
private String detailPath;
|
private String detailPath;
|
||||||
|
|
||||||
@@ -52,4 +53,3 @@ public class PqReport extends BaseEntity implements Serializable {
|
|||||||
*/
|
*/
|
||||||
private Integer state;
|
private Integer state;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,60 +9,42 @@ import lombok.Data;
|
|||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
/**
|
|
||||||
* @author caozehui
|
|
||||||
* @data 2025-03-19
|
|
||||||
*/
|
|
||||||
@Data
|
@Data
|
||||||
public class PqReportVO {
|
public class PqReportVO {
|
||||||
/**
|
|
||||||
* 报告模板id
|
|
||||||
*/
|
|
||||||
private String id;
|
private String id;
|
||||||
|
|
||||||
/**
|
|
||||||
* 报告模板名称
|
|
||||||
*/
|
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
/**
|
|
||||||
* 版本号
|
|
||||||
*/
|
|
||||||
private String version;
|
private String version;
|
||||||
|
|
||||||
|
private String pattern;
|
||||||
|
|
||||||
/**
|
|
||||||
* 基础模板文件路径
|
|
||||||
*/
|
|
||||||
private FileVO baseFileVO;
|
private FileVO baseFileVO;
|
||||||
|
|
||||||
/**
|
|
||||||
* 检测项模版文件路径
|
|
||||||
*/
|
|
||||||
private FileVO detailFileVO;
|
private FileVO detailFileVO;
|
||||||
|
|
||||||
/**
|
|
||||||
* 描述信息
|
|
||||||
*/
|
|
||||||
private String description;
|
private String description;
|
||||||
|
|
||||||
/**
|
|
||||||
* 创建时间
|
|
||||||
*/
|
|
||||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||||
@JsonDeserialize(using = LocalDateTimeDeserializer.class)
|
@JsonDeserialize(using = LocalDateTimeDeserializer.class)
|
||||||
@JsonSerialize(using = LocalDateTimeSerializer.class)
|
@JsonSerialize(using = LocalDateTimeSerializer.class)
|
||||||
private LocalDateTime createTime;
|
private LocalDateTime createTime;
|
||||||
|
|
||||||
/**
|
|
||||||
* 状态:0-删除 1-正常
|
|
||||||
*/
|
|
||||||
//private Integer state;
|
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
public static class FileVO{
|
public static class FileVO {
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
private String url;
|
private String url;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public static class OptionVO {
|
||||||
|
private String id;
|
||||||
|
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
private String version;
|
||||||
|
|
||||||
|
private String displayName;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -55,19 +55,12 @@ public interface IPqReportService extends IService<PqReport> {
|
|||||||
*/
|
*/
|
||||||
boolean delete(List<String> ids);
|
boolean delete(List<String> ids);
|
||||||
|
|
||||||
/**
|
List<PqReportVO.OptionVO> listOptions(String pattern);
|
||||||
* 查询所有报告名称
|
|
||||||
*
|
|
||||||
* @return key为报告id,value为报告名称
|
|
||||||
*/
|
|
||||||
List<String> listAllName();
|
|
||||||
|
|
||||||
void generateReport(DevReportParam devReportParam);
|
void generateReport(DevReportParam devReportParam);
|
||||||
|
|
||||||
|
|
||||||
void downloadReport(DevReportParam devReportParam, HttpServletResponse response);
|
void downloadReport(DevReportParam devReportParam, HttpServletResponse response);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 设备归档操作
|
* 设备归档操作
|
||||||
*
|
*
|
||||||
@@ -82,5 +75,4 @@ public interface IPqReportService extends IService<PqReport> {
|
|||||||
* @param deviceIds 被检设备ID列表,为空时上传所有已生成报告的设备
|
* @param deviceIds 被检设备ID列表,为空时上传所有已生成报告的设备
|
||||||
*/
|
*/
|
||||||
void uploadReportToCloud(List<String> deviceIds);
|
void uploadReportToCloud(List<String> deviceIds);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user