Compare commits
72 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0cd8e454fc | ||
|
|
95005d2462 | ||
|
|
16ace94f8d | ||
|
|
ca9885c5dc | ||
|
|
78b52fa336 | ||
|
|
da08271f76 | ||
|
|
75bc44172b | ||
|
|
95544f1dc6 | ||
| 7a8071c9d7 | |||
| 75b19eb6ab | |||
|
|
efb379d6a4 | ||
|
|
cf2dcf8ff4 | ||
|
|
4d52e9c820 | ||
|
|
be318b2b54 | ||
| e3478e71d5 | |||
| 88d3e00559 | |||
|
|
1de66ce4dc | ||
|
|
597f70edd1 | ||
|
|
6f8acd3fb5 | ||
|
|
3c0d7a6268 | ||
|
|
7fd1563f3a | ||
|
|
4fd813f476 | ||
|
|
9dfb42f917 | ||
|
|
9990183c5d | ||
|
|
d746e68d63 | ||
|
|
1ff2d373f5 | ||
|
|
f298a7bb56 | ||
|
|
aafa38000d | ||
|
|
287ca2cddc | ||
|
|
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 |
9
.gitignore
vendored
9
.gitignore
vendored
@@ -48,3 +48,12 @@ 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/
|
||||||
|
.m2
|
||||||
|
|
||||||
|
# Windows 保留设备名误生成的真实文件(在 Git Bash 里把 2>nul 当成丢弃报错的写法,会真的建出名为 nul 的文件)
|
||||||
|
nul
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -145,6 +145,11 @@
|
|||||||
<artifactId>activate-tool</artifactId>
|
<artifactId>activate-tool</artifactId>
|
||||||
<version>1.0.0</version>
|
<version>1.0.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-test</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -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,29 @@
|
|||||||
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.FormalProgressParam;
|
||||||
import com.njcn.gather.detection.pojo.param.PreDetectionParam;
|
import com.njcn.gather.detection.pojo.param.PreDetectionParam;
|
||||||
import com.njcn.gather.detection.pojo.param.SimulateDetectionParam;
|
import com.njcn.gather.detection.pojo.param.SimulateDetectionParam;
|
||||||
|
import com.njcn.gather.detection.pojo.vo.DetectionLockHolderVO;
|
||||||
|
import com.njcn.gather.detection.pojo.vo.FormalProgressVO;
|
||||||
import com.njcn.gather.detection.service.PreDetectionService;
|
import com.njcn.gather.detection.service.PreDetectionService;
|
||||||
|
import com.njcn.gather.detection.util.socket.FormalTestManager;
|
||||||
|
import com.njcn.gather.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 +44,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 +55,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");
|
||||||
|
HttpResult<DetectionLockHolderVO> busy = tryAcquireLock(param.getUserPageId());
|
||||||
|
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);
|
preDetectionService.sourceCommunicationCheck(param);
|
||||||
|
keepLock = true;
|
||||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
|
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
|
||||||
|
} finally {
|
||||||
|
if (!keepLock) {
|
||||||
|
releaseLockSelf("START_PRE_SYNC_FAILED");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -59,8 +89,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,10 +106,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> startTestSimulate(@RequestBody @Validated SimulateDetectionParam param) {
|
public HttpResult<?> startTestSimulate(@RequestBody @Validated SimulateDetectionParam param) {
|
||||||
String methodDescribe = getMethodDescribe("startTestSimulate");
|
String methodDescribe = getMethodDescribe("startSimulateTest");
|
||||||
|
// ContrastDetectionParam 无 userPageId 字段,用 loginName 作为会话标识(与 WS 会话 key 一致)
|
||||||
|
HttpResult<DetectionLockHolderVO> busy = tryAcquireLock(param.getUserPageId());
|
||||||
|
if (busy != null) {
|
||||||
|
return busy;
|
||||||
|
}
|
||||||
|
// 同步阶段抛异常时回滚锁,理由同 startPreTest
|
||||||
|
boolean keepLock = false;
|
||||||
|
try {
|
||||||
|
FormalTestManager.stopTime = 0;
|
||||||
|
FormalTestManager.hasStopFlag = false;
|
||||||
preDetectionService.sendScript(param);
|
preDetectionService.sendScript(param);
|
||||||
|
keepLock = true;
|
||||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
|
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
|
||||||
|
} finally {
|
||||||
|
if (!keepLock) {
|
||||||
|
releaseLockSelf("START_SIMULATE_TEST_SYNC_FAILED");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -85,9 +135,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");
|
||||||
|
HttpResult<DetectionLockHolderVO> busy = requireHolderSelf();
|
||||||
|
if (busy != null) {
|
||||||
|
return busy;
|
||||||
|
}
|
||||||
|
try {
|
||||||
preDetectionService.closeTestSimulate(param);
|
preDetectionService.closeTestSimulate(param);
|
||||||
|
} finally {
|
||||||
|
// 即使业务异常也要释放锁,避免锁残留导致他人无法接手
|
||||||
|
releaseLockSelf("USER_STOP");
|
||||||
|
}
|
||||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
|
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -99,8 +158,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 +176,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,12 +194,46 @@ 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PostMapping("/saveFormalProgress")
|
||||||
|
@OperateInfo
|
||||||
|
@ApiOperation("保存正式检测暂存进度")
|
||||||
|
public HttpResult<?> saveFormalProgress(@RequestBody @Validated FormalProgressParam param) {
|
||||||
|
String methodDescribe = getMethodDescribe("saveFormalProgress");
|
||||||
|
HttpResult<DetectionLockHolderVO> busy = requireHolderSelf();
|
||||||
|
if (busy != null) {
|
||||||
|
return busy;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
preDetectionService.saveFormalProgress(param);
|
||||||
|
} finally {
|
||||||
|
releaseLockSelf("SAVE_FORMAL_PROGRESS");
|
||||||
|
}
|
||||||
|
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/formalProgress")
|
||||||
|
@OperateInfo
|
||||||
|
@ApiOperation("查询正式检测暂存进度并放行续检")
|
||||||
|
public HttpResult<?> formalProgress(@RequestBody @Validated FormalProgressParam param) {
|
||||||
|
String methodDescribe = getMethodDescribe("formalProgress");
|
||||||
|
HttpResult<DetectionLockHolderVO> busy = requireHolderSelf();
|
||||||
|
if (busy != null) {
|
||||||
|
return busy;
|
||||||
|
}
|
||||||
|
FormalProgressVO data = preDetectionService.formalProgress(param);
|
||||||
|
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, data, methodDescribe);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 开始比对检测(包括预检测、正式检测)通用入口
|
* 开始比对检测(包括预检测、正式检测)通用入口
|
||||||
@@ -140,10 +242,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");
|
||||||
|
// ContrastDetectionParam 无 userPageId 字段,用 loginName 作为会话标识(与 WS 会话 key 一致)
|
||||||
|
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);
|
preDetectionService.startContrastTest(param);
|
||||||
|
keepLock = true;
|
||||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
|
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
|
||||||
|
} finally {
|
||||||
|
if (!keepLock) {
|
||||||
|
releaseLockSelf("START_CONTRAST_SYNC_FAILED");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -169,11 +287,91 @@ public class PreDetectionController extends BaseController {
|
|||||||
@OperateInfo(info = LogEnum.SYSTEM_COMMON)
|
@OperateInfo(info = LogEnum.SYSTEM_COMMON)
|
||||||
@GetMapping("/startCoefficient")
|
@GetMapping("/startCoefficient")
|
||||||
@ApiOperation("比对模式开启系数校验")
|
@ApiOperation("比对模式开启系数校验")
|
||||||
public HttpResult<String> startCoefficient() {
|
public HttpResult<?> startCoefficient() {
|
||||||
String methodDescribe = getMethodDescribe("startCoefficient");
|
String methodDescribe = getMethodDescribe("startCoefficient");
|
||||||
LogUtil.njcnDebug(log, "{}", methodDescribe);
|
LogUtil.njcnDebug(log, "{}", methodDescribe);
|
||||||
|
HttpResult<DetectionLockHolderVO> busy = requireHolderSelf();
|
||||||
|
if (busy != null) {
|
||||||
|
return busy;
|
||||||
|
}
|
||||||
preDetectionService.startCoefficient();
|
preDetectionService.startCoefficient();
|
||||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -41,11 +41,13 @@ import com.njcn.gather.monitor.service.IPqMonitorService;
|
|||||||
import com.njcn.gather.plan.pojo.enums.DataSourceEnum;
|
import com.njcn.gather.plan.pojo.enums.DataSourceEnum;
|
||||||
import com.njcn.gather.plan.service.IAdPlanService;
|
import com.njcn.gather.plan.service.IAdPlanService;
|
||||||
import com.njcn.gather.plan.service.IAdPlanTestConfigService;
|
import com.njcn.gather.plan.service.IAdPlanTestConfigService;
|
||||||
|
import com.njcn.gather.report.pojo.enums.PowerIndexEnum;
|
||||||
import com.njcn.gather.storage.pojo.po.ContrastHarmonicResult;
|
import com.njcn.gather.storage.pojo.po.ContrastHarmonicResult;
|
||||||
import com.njcn.gather.storage.pojo.po.ContrastNonHarmonicResult;
|
import com.njcn.gather.storage.pojo.po.ContrastNonHarmonicResult;
|
||||||
import com.njcn.gather.storage.service.DetectionDataDealService;
|
import com.njcn.gather.storage.service.DetectionDataDealService;
|
||||||
import com.njcn.gather.system.cfg.pojo.po.SysTestConfig;
|
import com.njcn.gather.system.cfg.pojo.po.SysTestConfig;
|
||||||
import com.njcn.gather.system.cfg.service.ISysTestConfigService;
|
import com.njcn.gather.system.cfg.service.ISysTestConfigService;
|
||||||
|
import com.njcn.gather.system.config.PathConfig;
|
||||||
import com.njcn.gather.system.dictionary.pojo.enums.DictDataEnum;
|
import com.njcn.gather.system.dictionary.pojo.enums.DictDataEnum;
|
||||||
import com.njcn.gather.system.dictionary.pojo.po.DictData;
|
import com.njcn.gather.system.dictionary.pojo.po.DictData;
|
||||||
import com.njcn.gather.system.dictionary.pojo.po.DictTree;
|
import com.njcn.gather.system.dictionary.pojo.po.DictTree;
|
||||||
@@ -57,7 +59,6 @@ import com.njcn.gather.tools.comtrade.comparewave.service.ICompareWaveService;
|
|||||||
import com.njcn.gather.util.StorageUtil;
|
import com.njcn.gather.util.StorageUtil;
|
||||||
import com.njcn.web.utils.ExcelUtil;
|
import com.njcn.web.utils.ExcelUtil;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
@@ -127,21 +128,22 @@ public class SocketContrastResponseService {
|
|||||||
// private SysRegRes contrastRegRes = null;
|
// private SysRegRes contrastRegRes = null;
|
||||||
|
|
||||||
|
|
||||||
@Value("${report.reportDir}")
|
// @Value("${report.reportDir}")
|
||||||
private String alignDataFilePath;
|
// private String alignDataFilePath;
|
||||||
|
private final PathConfig pathConfig;
|
||||||
|
|
||||||
public static final Map<String, List<String>> testItemCodeMap = new HashMap() {{
|
public static final Map<String, List<String>> testItemCodeMap = new HashMap() {{
|
||||||
put("FREQ", Arrays.asList(DetectionCodeEnum.FREQ.getCode()));
|
put(PowerIndexEnum.FREQ.getKey(), Arrays.asList(DetectionCodeEnum.FREQ.getCode()));
|
||||||
put("V", Arrays.asList(DetectionCodeEnum.VRMS.getCode(), DetectionCodeEnum.PVRMS.getCode()));
|
put(PowerIndexEnum.V.getKey(), Arrays.asList(DetectionCodeEnum.VRMS.getCode(), DetectionCodeEnum.PVRMS.getCode()));
|
||||||
put("HV", Arrays.asList(DetectionCodeEnum.V2_50.getCode(), DetectionCodeEnum.PV2_50.getCode()));
|
put(PowerIndexEnum.HV.getKey(), Arrays.asList(DetectionCodeEnum.V2_50.getCode(), DetectionCodeEnum.PV2_50.getCode()));
|
||||||
put("HI", Arrays.asList(DetectionCodeEnum.I2_50.getCode()));
|
put(PowerIndexEnum.HI.getKey(), Arrays.asList(DetectionCodeEnum.I2_50.getCode()));
|
||||||
put("HP", Arrays.asList(DetectionCodeEnum.P2_50.getCode()));
|
put(PowerIndexEnum.HP.getKey(), Arrays.asList(DetectionCodeEnum.P2_50.getCode()));
|
||||||
put("HSV", Arrays.asList(DetectionCodeEnum.SV_1_49.getCode(), DetectionCodeEnum.PSV_1_49.getCode()));
|
put(PowerIndexEnum.HSV.getKey(), Arrays.asList(DetectionCodeEnum.SV_1_49.getCode(), DetectionCodeEnum.PSV_1_49.getCode()));
|
||||||
put("HSI", Arrays.asList(DetectionCodeEnum.SI_1_49.getCode()));
|
put(PowerIndexEnum.HSI.getKey(), Arrays.asList(DetectionCodeEnum.SI_1_49.getCode()));
|
||||||
put("I", Arrays.asList(DetectionCodeEnum.IRMS.getCode()));
|
put(PowerIndexEnum.I.getKey(), Arrays.asList(DetectionCodeEnum.IRMS.getCode()));
|
||||||
put("IMBV", Arrays.asList(DetectionCodeEnum.V_UNBAN.getCode()));
|
put(PowerIndexEnum.IMBV.getKey(), Arrays.asList(DetectionCodeEnum.V_UNBAN.getCode()));
|
||||||
put("IMBA", Arrays.asList(DetectionCodeEnum.I_UNBAN.getCode()));
|
put(PowerIndexEnum.IMBA.getKey(), Arrays.asList(DetectionCodeEnum.I_UNBAN.getCode()));
|
||||||
put("F", Arrays.asList(DetectionCodeEnum.PST.getCode()));
|
put(PowerIndexEnum.F.getKey(), Arrays.asList(DetectionCodeEnum.PST.getCode()));
|
||||||
}};
|
}};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -306,7 +308,7 @@ public class SocketContrastResponseService {
|
|||||||
FormalTestManager.numMap.clear();
|
FormalTestManager.numMap.clear();
|
||||||
FormalTestManager.numMap.putAll(numMap);
|
FormalTestManager.numMap.putAll(numMap);
|
||||||
SysTestConfig oneConfig = sysTestConfigService.getOneConfig();
|
SysTestConfig oneConfig = sysTestConfigService.getOneConfig();
|
||||||
if (param.getTestItemList().get(2)) {
|
if (param.isFormalTestSelected()) {
|
||||||
numMap.forEach((devMonitorId, num) -> {
|
numMap.forEach((devMonitorId, num) -> {
|
||||||
if (oneConfig.getMaxTime() < num) {
|
if (oneConfig.getMaxTime() < num) {
|
||||||
throw new BusinessException(DetectionResponseEnum.EXCEED_MAX_TIME);
|
throw new BusinessException(DetectionResponseEnum.EXCEED_MAX_TIME);
|
||||||
@@ -355,6 +357,7 @@ public class SocketContrastResponseService {
|
|||||||
|
|
||||||
|
|
||||||
FormalTestManager.currentStep = SourceOperateCodeEnum.YJC_SBTXJY;
|
FormalTestManager.currentStep = SourceOperateCodeEnum.YJC_SBTXJY;
|
||||||
|
FormalTestManager.checkStartTime = LocalDateTime.now();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void deal(PreDetectionParam param, String msg) throws Exception {
|
public void deal(PreDetectionParam param, String msg) throws Exception {
|
||||||
@@ -553,7 +556,6 @@ public class SocketContrastResponseService {
|
|||||||
this.sendAlignData(s, requestOperateCode);
|
this.sendAlignData(s, requestOperateCode);
|
||||||
|
|
||||||
FormalTestManager.currentStep = SourceOperateCodeEnum.YJC_ALIGN;
|
FormalTestManager.currentStep = SourceOperateCodeEnum.YJC_ALIGN;
|
||||||
|
|
||||||
// if (FormalTestManager.isWaveCheck) {
|
// if (FormalTestManager.isWaveCheck) {
|
||||||
// System.out.println("(仅有闪变、录波)模型一致性校验成功!》》》》》》》》》》》》》》》》》》》》》》》》》》》》》开始相序校验》》》》》》》》》》》》》》》》");
|
// System.out.println("(仅有闪变、录波)模型一致性校验成功!》》》》》》》》》》》》》》》》》》》》》》》》》》》》》开始相序校验》》》》》》》》》》》》》》》》");
|
||||||
// this.sendXu(s);
|
// this.sendXu(s);
|
||||||
@@ -1153,7 +1155,7 @@ public class SocketContrastResponseService {
|
|||||||
|
|
||||||
private void sendFormalTest(String s, PreDetectionParam param, SourceOperateCodeEnum requestOperateCode, SourceOperateCodeEnum quitOperateCode) {
|
private void sendFormalTest(String s, PreDetectionParam param, SourceOperateCodeEnum requestOperateCode, SourceOperateCodeEnum quitOperateCode) {
|
||||||
// 后续做正式检测
|
// 后续做正式检测
|
||||||
if (param.getTestItemList().get(2)) {
|
if (param.isFormalTestSelected()) {
|
||||||
System.out.println("开始正式检测!");
|
System.out.println("开始正式检测!");
|
||||||
if (ObjectUtil.isNotNull(FormalTestManager.nonWaveDataSourceEnum)) {
|
if (ObjectUtil.isNotNull(FormalTestManager.nonWaveDataSourceEnum)) {
|
||||||
SocketMsg<String> socketMsg = new SocketMsg<>();
|
SocketMsg<String> socketMsg = new SocketMsg<>();
|
||||||
@@ -2314,7 +2316,7 @@ public class SocketContrastResponseService {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
ExcelUtil.saveExcel(alignDataFilePath, "对齐数据.xlsx", sheetsList);
|
ExcelUtil.saveExcel(pathConfig.getDataPath(), "对齐数据.xlsx", sheetsList);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -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;
|
||||||
@@ -27,12 +28,15 @@ import com.njcn.gather.device.service.IPqDevService;
|
|||||||
import com.njcn.gather.device.service.IPqDevSubService;
|
import com.njcn.gather.device.service.IPqDevSubService;
|
||||||
import com.njcn.gather.plan.pojo.po.AdPlan;
|
import com.njcn.gather.plan.pojo.po.AdPlan;
|
||||||
import com.njcn.gather.plan.service.IAdPlanService;
|
import com.njcn.gather.plan.service.IAdPlanService;
|
||||||
import com.njcn.gather.result.pojo.enums.ResultUnitEnum;
|
import com.njcn.gather.report.pojo.enums.PowerIndexEnum;
|
||||||
|
import com.njcn.gather.result.service.IResultService;
|
||||||
import com.njcn.gather.script.pojo.param.PqScriptCheckDataParam;
|
import com.njcn.gather.script.pojo.param.PqScriptCheckDataParam;
|
||||||
import com.njcn.gather.script.pojo.param.PqScriptIssueParam;
|
import com.njcn.gather.script.pojo.param.PqScriptIssueParam;
|
||||||
import com.njcn.gather.script.pojo.po.SourceIssue;
|
import com.njcn.gather.script.pojo.po.SourceIssue;
|
||||||
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;
|
||||||
@@ -41,8 +45,8 @@ import com.njcn.gather.storage.service.SimAndDigHarmonicService;
|
|||||||
import com.njcn.gather.system.dictionary.pojo.enums.DictDataEnum;
|
import com.njcn.gather.system.dictionary.pojo.enums.DictDataEnum;
|
||||||
import com.njcn.gather.system.dictionary.pojo.po.DictData;
|
import com.njcn.gather.system.dictionary.pojo.po.DictData;
|
||||||
import com.njcn.gather.system.dictionary.service.IDictDataService;
|
import com.njcn.gather.system.dictionary.service.IDictDataService;
|
||||||
import com.njcn.gather.system.pojo.enums.DicDataEnum;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
@@ -64,7 +68,7 @@ public class SocketDevResponseService {
|
|||||||
|
|
||||||
private List<String> icdTypeList;
|
private List<String> icdTypeList;
|
||||||
|
|
||||||
private final List<String> nonHarmonicList = Stream.of(DicDataEnum.FREQ.getCode(), DicDataEnum.V.getCode(), DicDataEnum.I.getCode(), DicDataEnum.IMBV.getCode(), DicDataEnum.IMBA.getCode(), DicDataEnum.VOLTAGE.getCode(), DicDataEnum.F.getCode()).collect(Collectors.toList());
|
private final List<String> nonHarmonicList = Stream.of(PowerIndexEnum.FREQ.getKey(), PowerIndexEnum.V.getKey(), PowerIndexEnum.I.getKey(), PowerIndexEnum.IMBV.getKey(), PowerIndexEnum.IMBA.getKey(), PowerIndexEnum.VOLTAGE.getKey(), PowerIndexEnum.F.getKey()).collect(Collectors.toList());
|
||||||
|
|
||||||
private final IPqDevService iPqDevService;
|
private final IPqDevService iPqDevService;
|
||||||
private final IPqDevSubService iPqDevSubService;
|
private final IPqDevSubService iPqDevSubService;
|
||||||
@@ -76,6 +80,11 @@ 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;
|
||||||
|
private final IResultService resultService;
|
||||||
|
|
||||||
|
@Value("${dataCheck.enable}")
|
||||||
|
private Boolean dataCheck;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 存储的装置相序数据
|
* 存储的装置相序数据
|
||||||
@@ -388,71 +397,8 @@ public class SocketDevResponseService {
|
|||||||
sendWebSocket(param.getUserPageId(), SourceOperateCodeEnum.Coefficient_Check.getValue(), SourceOperateCodeEnum.small_comp_end.getValue(), XiNumberManager.devParameterList.get(1));
|
sendWebSocket(param.getUserPageId(), SourceOperateCodeEnum.Coefficient_Check.getValue(), SourceOperateCodeEnum.small_comp_end.getValue(), XiNumberManager.devParameterList.get(1));
|
||||||
System.out.println("-------------------------已经全部结束----------------------");
|
System.out.println("-------------------------已经全部结束----------------------");
|
||||||
|
|
||||||
if (param.getTestItemList().get(2)) {
|
if (param.isFormalTestSelected()) {
|
||||||
//如果后续做正式检测
|
startFormalScripts(param, null, param.isResumeFormal());
|
||||||
PqScriptIssueParam issueParam = new PqScriptIssueParam();
|
|
||||||
issueParam.setPlanId(param.getPlanId());
|
|
||||||
issueParam.setSourceId(param.getSourceId());
|
|
||||||
issueParam.setDevIds(param.getDevIds());
|
|
||||||
issueParam.setScriptId(param.getScriptId());
|
|
||||||
|
|
||||||
if (param.getReCheckType().equals(SourceOperateCodeEnum.RE_ERROR_TEST.getValue())) {
|
|
||||||
//不合格项复检
|
|
||||||
Set<Integer> indexes = new HashSet<>();
|
|
||||||
StorageParam storageParam = new StorageParam();
|
|
||||||
storageParam.setCode(param.getCode());
|
|
||||||
storageParam.setScriptId(param.getScriptId());
|
|
||||||
param.getDevIds().forEach(devId -> {
|
|
||||||
storageParam.setDevId(devId);
|
|
||||||
indexes.addAll(adHarmonicService.getIndex(storageParam));
|
|
||||||
});
|
|
||||||
issueParam.setIndexList(indexes.stream().collect(Collectors.toList()));
|
|
||||||
issueParam.setIsPhaseSequence(SourceOperateCodeEnum.RE_ERROR_TEST.getValue());
|
|
||||||
} else {
|
|
||||||
issueParam.setIsPhaseSequence(CommonEnum.FORMAL_TEST.getValue());
|
|
||||||
}
|
|
||||||
|
|
||||||
SocketMsg<String> socketMsg = new SocketMsg<>();
|
|
||||||
socketMsg.setOperateCode(SourceOperateCodeEnum.OPER_GATHER.getValue());
|
|
||||||
List<SourceIssue> sourceIssues;
|
|
||||||
|
|
||||||
//正式检测
|
|
||||||
sourceIssues = pqScriptDtlsService.listSourceIssue(issueParam);
|
|
||||||
sourceIssues = sourceIssues.stream().sorted(Comparator.comparing(SourceIssue::getIndex)).collect(Collectors.toList());
|
|
||||||
// 使用 LinkedHashMap 保持分组顺序
|
|
||||||
Map<String, List<SourceIssue>> groupedIssues = sourceIssues.stream()
|
|
||||||
.collect(Collectors.groupingBy(
|
|
||||||
SourceIssue::getType,
|
|
||||||
LinkedHashMap::new,
|
|
||||||
Collectors.toList()
|
|
||||||
));
|
|
||||||
|
|
||||||
// 将分组后的元素合并成一个新的集合,保持原有顺序
|
|
||||||
sourceIssues = groupedIssues.values().stream()
|
|
||||||
.flatMap(List::stream)
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
// 存放所有检测小项
|
|
||||||
SocketManager.addSourceList(sourceIssues);
|
|
||||||
// 按照大项分组。key为大项code,value为小项个数
|
|
||||||
Map<String, Long> sourceIssueMap = sourceIssues.stream().collect(Collectors.groupingBy(SourceIssue::getType, Collectors.counting()));
|
|
||||||
SocketManager.initMap(sourceIssueMap);
|
|
||||||
|
|
||||||
//告诉前端当前项开始了
|
|
||||||
WebSocketVO<Object> webSocketVO = new WebSocketVO<>();
|
|
||||||
FormalTestManager.currentIssue = sourceIssues.get(0);
|
|
||||||
String type = sourceIssues.get(0).getType();
|
|
||||||
if (ResultUnitEnum.P.getCode().equals(type)) {
|
|
||||||
sourceIssues.get(0).setType(ResultUnitEnum.V_ABSOLUTELY.getCode());
|
|
||||||
webSocketVO.setRequestId(ResultUnitEnum.P.getCode() + CnSocketUtil.START_TAG);
|
|
||||||
} else {
|
|
||||||
webSocketVO.setRequestId(sourceIssues.get(0).getType() + CnSocketUtil.START_TAG);
|
|
||||||
}
|
|
||||||
socketMsg.setData(JSON.toJSONString(sourceIssues.get(0)));
|
|
||||||
socketMsg.setRequestId(SourceOperateCodeEnum.FORMAL_REAL.getValue() + CnSocketUtil.STEP_TAG + type);
|
|
||||||
SocketManager.sendMsg(param.getUserPageId() + CnSocketUtil.SOURCE_TAG, JSON.toJSONString(socketMsg));
|
|
||||||
|
|
||||||
webSocketVO.setDesc(null);
|
|
||||||
WebServiceManager.sendMsg(param.getUserPageId(), JSON.toJSONString(webSocketVO));
|
|
||||||
} else {
|
} else {
|
||||||
//后续什么都不做
|
//后续什么都不做
|
||||||
CnSocketUtil.quitSend(param);
|
CnSocketUtil.quitSend(param);
|
||||||
@@ -604,7 +550,7 @@ public class SocketDevResponseService {
|
|||||||
private BigDecimal rangeNum(double num1, double num2, String type) {
|
private BigDecimal rangeNum(double num1, double num2, String type) {
|
||||||
double diff = Math.abs(num1 - num2);
|
double diff = Math.abs(num1 - num2);
|
||||||
double larger = Math.max(num1, num2);
|
double larger = Math.max(num1, num2);
|
||||||
if (DicDataEnum.V.getCode().equals(type)) {
|
if (PowerIndexEnum.V.getKey().equals(type)) {
|
||||||
return BigDecimal.valueOf(num1 - num2).setScale(4, RoundingMode.HALF_UP);
|
return BigDecimal.valueOf(num1 - num2).setScale(4, RoundingMode.HALF_UP);
|
||||||
} else {
|
} else {
|
||||||
return BigDecimal.valueOf(diff / larger).multiply(BigDecimal.valueOf(100)).setScale(4, RoundingMode.HALF_UP);
|
return BigDecimal.valueOf(diff / larger).multiply(BigDecimal.valueOf(100)).setScale(4, RoundingMode.HALF_UP);
|
||||||
@@ -667,12 +613,12 @@ public class SocketDevResponseService {
|
|||||||
coefficientVO.setBIeXi(isWithinTenPercent(optionalIB, devParameter.getDevCurr(), iLimit) ? "合格" : "不合格");
|
coefficientVO.setBIeXi(isWithinTenPercent(optionalIB, devParameter.getDevCurr(), iLimit) ? "合格" : "不合格");
|
||||||
coefficientVO.setCIeXi(isWithinTenPercent(optionalIC, devParameter.getDevCurr(), iLimit) ? "合格" : "不合格");
|
coefficientVO.setCIeXi(isWithinTenPercent(optionalIC, devParameter.getDevCurr(), iLimit) ? "合格" : "不合格");
|
||||||
|
|
||||||
coefficientVO.setAV(rangeNum(optionalA, devParameter.getDevVolt(), DicDataEnum.V.getCode()).toString());
|
coefficientVO.setAV(rangeNum(optionalA, devParameter.getDevVolt(), PowerIndexEnum.V.getKey()).toString());
|
||||||
coefficientVO.setBV(rangeNum(optionalB, devParameter.getDevVolt(), DicDataEnum.V.getCode()).toString());
|
coefficientVO.setBV(rangeNum(optionalB, devParameter.getDevVolt(), PowerIndexEnum.V.getKey()).toString());
|
||||||
coefficientVO.setCV(rangeNum(optionalC, devParameter.getDevVolt(), DicDataEnum.V.getCode()).toString());
|
coefficientVO.setCV(rangeNum(optionalC, devParameter.getDevVolt(), PowerIndexEnum.V.getKey()).toString());
|
||||||
coefficientVO.setAI(rangeNum(optionalIA, devParameter.getDevCurr(), DicDataEnum.I.getCode()).toString());
|
coefficientVO.setAI(rangeNum(optionalIA, devParameter.getDevCurr(), PowerIndexEnum.I.getKey()).toString());
|
||||||
coefficientVO.setBI(rangeNum(optionalIB, devParameter.getDevCurr(), DicDataEnum.I.getCode()).toString());
|
coefficientVO.setBI(rangeNum(optionalIB, devParameter.getDevCurr(), PowerIndexEnum.I.getKey()).toString());
|
||||||
coefficientVO.setCI(rangeNum(optionalIC, devParameter.getDevCurr(), DicDataEnum.I.getCode()).toString());
|
coefficientVO.setCI(rangeNum(optionalIC, devParameter.getDevCurr(), PowerIndexEnum.I.getKey()).toString());
|
||||||
|
|
||||||
if ("不合格".equals(coefficientVO.getAVuXi()) || "不合格".equals(coefficientVO.getBVuXi()) || "不合格".equals(coefficientVO.getCVuXi()) || "不合格".equals(coefficientVO.getAIeXi()) || "不合格".equals(coefficientVO.getBIeXi()) || "不合格".equals(coefficientVO.getCIeXi())) {
|
if ("不合格".equals(coefficientVO.getAVuXi()) || "不合格".equals(coefficientVO.getBVuXi()) || "不合格".equals(coefficientVO.getCVuXi()) || "不合格".equals(coefficientVO.getAIeXi()) || "不合格".equals(coefficientVO.getBIeXi()) || "不合格".equals(coefficientVO.getCIeXi())) {
|
||||||
coefficientVO.setResultFlag(0);
|
coefficientVO.setResultFlag(0);
|
||||||
@@ -894,75 +840,77 @@ 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());
|
||||||
|
|
||||||
socketMsg.setOperateCode(SourceOperateCodeEnum.OPER_GATHER.getValue());
|
socketMsg.setOperateCode(SourceOperateCodeEnum.OPER_GATHER.getValue());
|
||||||
List<SourceIssue> sourceIssues;
|
List<SourceIssue> sourceIssues;
|
||||||
// 做预检测、后续做系数校准
|
// 做预检测、后续做系数校准
|
||||||
if (param.getTestItemList().get(0) || param.getTestItemList().get(1)) {
|
// if (param.isPreTestSelected() || param.isCoefficientSelected() || param.isFormalTestSelected()) {
|
||||||
issueParam.setIsPhaseSequence(CommonEnum.PHASE_TEST.getValue());
|
issueParam.setIsPhaseSequence(CommonEnum.PHASE_TEST.getValue());
|
||||||
sourceIssues = pqScriptDtlsService.listSourceIssue(issueParam);
|
sourceIssues = pqScriptDtlsService.listSourceIssue(issueParam);
|
||||||
socketMsg.setRequestId(SourceOperateCodeEnum.YJC_XUJY.getValue());
|
socketMsg.setRequestId(SourceOperateCodeEnum.YJC_XUJY.getValue());
|
||||||
socketMsg.setData(JSON.toJSONString(sourceIssues.get(0)));
|
socketMsg.setData(JSON.toJSONString(sourceIssues.get(0)));
|
||||||
SocketManager.sendMsg(param.getUserPageId() + CnSocketUtil.SOURCE_TAG, JSON.toJSONString(socketMsg));
|
SocketManager.sendMsg(param.getUserPageId() + CnSocketUtil.SOURCE_TAG, JSON.toJSONString(socketMsg));
|
||||||
} else if (param.getTestItemList().get(2)) {
|
// }
|
||||||
// 后续做正式检测
|
// else if (param.isFormalTestSelected()) {
|
||||||
if (param.getReCheckType().equals(SourceOperateCodeEnum.RE_ERROR_TEST.getValue())) {
|
// // 后续做正式检测
|
||||||
//不合格项复检
|
// if (param.getReCheckType().equals(SourceOperateCodeEnum.RE_ERROR_TEST.getValue())) {
|
||||||
Set<Integer> indexes = new HashSet<>();
|
// //不合格项复检
|
||||||
StorageParam storageParam = new StorageParam();
|
// Set<Integer> indexes = new HashSet<>();
|
||||||
storageParam.setCode(param.getCode());
|
// StorageParam storageParam = new StorageParam();
|
||||||
storageParam.setScriptId(param.getScriptId());
|
// storageParam.setCode(param.getCode());
|
||||||
param.getDevIds().forEach(devId -> {
|
// storageParam.setScriptId(param.getScriptId());
|
||||||
storageParam.setDevId(devId);
|
// param.getDevIds().forEach(devId -> {
|
||||||
indexes.addAll(adHarmonicService.getIndex(storageParam));
|
// storageParam.setDevId(devId);
|
||||||
});
|
// indexes.addAll(adHarmonicService.getIndex(storageParam));
|
||||||
issueParam.setIndexList(indexes.stream().collect(Collectors.toList()));
|
// });
|
||||||
issueParam.setIsPhaseSequence(SourceOperateCodeEnum.RE_ERROR_TEST.getValue());
|
// issueParam.setIndexList(indexes.stream().collect(Collectors.toList()));
|
||||||
} else {
|
// issueParam.setIsPhaseSequence(SourceOperateCodeEnum.RE_ERROR_TEST.getValue());
|
||||||
issueParam.setIsPhaseSequence(CommonEnum.FORMAL_TEST.getValue());
|
// } else {
|
||||||
}
|
// issueParam.setIsPhaseSequence(CommonEnum.FORMAL_TEST.getValue());
|
||||||
//正式检测
|
// }
|
||||||
sourceIssues = pqScriptDtlsService.listSourceIssue(issueParam);
|
// //正式检测
|
||||||
sourceIssues = sourceIssues.stream().sorted(Comparator.comparing(SourceIssue::getIndex)).collect(Collectors.toList());
|
// sourceIssues = pqScriptDtlsService.listSourceIssue(issueParam);
|
||||||
// 使用 LinkedHashMap 保持分组顺序
|
// sourceIssues = sourceIssues.stream().sorted(Comparator.comparing(SourceIssue::getIndex)).collect(Collectors.toList());
|
||||||
Map<String, List<SourceIssue>> groupedIssues = sourceIssues.stream()
|
// // 使用 LinkedHashMap 保持分组顺序
|
||||||
.collect(Collectors.groupingBy(
|
// Map<String, List<SourceIssue>> groupedIssues = sourceIssues.stream()
|
||||||
SourceIssue::getType,
|
// .collect(Collectors.groupingBy(
|
||||||
LinkedHashMap::new,
|
// SourceIssue::getType,
|
||||||
Collectors.toList()
|
// LinkedHashMap::new,
|
||||||
));
|
// Collectors.toList()
|
||||||
|
// ));
|
||||||
// 将分组后的元素合并成一个新的集合,保持原有顺序
|
//
|
||||||
sourceIssues = groupedIssues.values().stream()
|
// // 将分组后的元素合并成一个新的集合,保持原有顺序
|
||||||
.flatMap(List::stream)
|
// sourceIssues = groupedIssues.values().stream()
|
||||||
.collect(Collectors.toList());
|
// .flatMap(List::stream)
|
||||||
// 存放所有检测小项
|
// .collect(Collectors.toList());
|
||||||
SocketManager.addSourceList(sourceIssues);
|
// // 存放所有检测小项
|
||||||
// 按照大项分组。key为大项code,value为小项个数
|
// SocketManager.addSourceList(sourceIssues);
|
||||||
Map<String, Long> sourceIssueMap = sourceIssues.stream().collect(Collectors.groupingBy(SourceIssue::getType, Collectors.counting()));
|
// // 按照大项分组。key为大项code,value为小项个数
|
||||||
SocketManager.initMap(sourceIssueMap);
|
// Map<String, Long> sourceIssueMap = sourceIssues.stream().collect(Collectors.groupingBy(SourceIssue::getType, Collectors.counting()));
|
||||||
|
// SocketManager.initMap(sourceIssueMap);
|
||||||
//告诉前端当前项开始了
|
//
|
||||||
WebSocketVO<Object> webSocketVO = new WebSocketVO<>();
|
// //告诉前端当前项开始了
|
||||||
String type = sourceIssues.get(0).getType();
|
// WebSocketVO<Object> webSocketVO = new WebSocketVO<>();
|
||||||
if (ResultUnitEnum.P.getCode().equals(type)) {
|
// String type = sourceIssues.get(0).getType();
|
||||||
sourceIssues.get(0).setType(ResultUnitEnum.V_ABSOLUTELY.getCode());
|
// if (StrUtil.isNotBlank(sourceIssues.get(0).getOtherType())) {
|
||||||
webSocketVO.setRequestId(ResultUnitEnum.P.getCode() + CnSocketUtil.START_TAG);
|
// sourceIssues.get(0).setType(PowerIndexEnum.V.getKey());
|
||||||
} else {
|
// webSocketVO.setRequestId(sourceIssues.get(0).getOtherType() + CnSocketUtil.START_TAG);
|
||||||
webSocketVO.setRequestId(sourceIssues.get(0).getType() + CnSocketUtil.START_TAG);
|
// type = sourceIssues.get(0).getOtherType();
|
||||||
}
|
// } else {
|
||||||
FormalTestManager.currentIssue = sourceIssues.get(0);
|
// webSocketVO.setRequestId(sourceIssues.get(0).getType() + CnSocketUtil.START_TAG);
|
||||||
socketMsg.setData(JSON.toJSONString(sourceIssues.get(0)));
|
// }
|
||||||
socketMsg.setRequestId(SourceOperateCodeEnum.FORMAL_REAL.getValue() + CnSocketUtil.STEP_TAG + type);
|
// FormalTestManager.currentIssue = sourceIssues.get(0);
|
||||||
socketMsg.setOperateCode(SourceOperateCodeEnum.OPER_GATHER.getValue());
|
// socketMsg.setData(JSON.toJSONString(sourceIssues.get(0)));
|
||||||
SocketManager.sendMsg(param.getUserPageId() + CnSocketUtil.SOURCE_TAG, JSON.toJSONString(socketMsg));
|
// socketMsg.setRequestId(SourceOperateCodeEnum.FORMAL_REAL.getValue() + CnSocketUtil.STEP_TAG + type);
|
||||||
|
// socketMsg.setOperateCode(SourceOperateCodeEnum.OPER_GATHER.getValue());
|
||||||
webSocketVO.setDesc(null);
|
// SocketManager.sendMsg(param.getUserPageId() + CnSocketUtil.SOURCE_TAG, JSON.toJSONString(socketMsg));
|
||||||
WebServiceManager.sendMsg(param.getUserPageId(), JSON.toJSONString(webSocketVO));
|
//
|
||||||
}
|
// webSocketVO.setDesc(null);
|
||||||
|
// WebServiceManager.sendMsg(param.getUserPageId(), JSON.toJSONString(webSocketVO));
|
||||||
|
// }
|
||||||
} else {
|
} else {
|
||||||
// 发送下一个脚本与icd校验
|
// 发送下一个脚本与icd校验
|
||||||
String icdType = icdTypeList.stream().filter(it -> !icdCheckDataMap.containsKey(it)).findFirst().orElse(null);
|
String icdType = icdTypeList.stream().filter(it -> !icdCheckDataMap.containsKey(it)).findFirst().orElse(null);
|
||||||
@@ -1135,7 +1083,7 @@ public class SocketDevResponseService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 后续做系数校准
|
// 后续做系数校准
|
||||||
if (param.getTestItemList().get(1)) {
|
if (param.isCoefficientSelected()) {
|
||||||
WebSocketVO<Object> webSocketVO = new WebSocketVO<>();
|
WebSocketVO<Object> webSocketVO = new WebSocketVO<>();
|
||||||
webSocketVO.setRequestId(SourceOperateCodeEnum.Coefficient_Check.getValue());
|
webSocketVO.setRequestId(SourceOperateCodeEnum.Coefficient_Check.getValue());
|
||||||
webSocketVO.setOperateCode(SourceOperateCodeEnum.big_start.getValue());
|
webSocketVO.setOperateCode(SourceOperateCodeEnum.big_start.getValue());
|
||||||
@@ -1159,67 +1107,8 @@ public class SocketDevResponseService {
|
|||||||
XiNumberManager.smallDevXiNumDataMap.clear();
|
XiNumberManager.smallDevXiNumDataMap.clear();
|
||||||
|
|
||||||
System.out.println("开始系数校准》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》");
|
System.out.println("开始系数校准》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》");
|
||||||
} else if (param.getTestItemList().get(2)) {
|
} else if (param.isFormalTestSelected()) {
|
||||||
// 后续做正式检测
|
startFormalScripts(param, null, param.isResumeFormal());
|
||||||
PqScriptIssueParam issueParam = new PqScriptIssueParam();
|
|
||||||
issueParam.setPlanId(param.getPlanId());
|
|
||||||
issueParam.setSourceId(param.getSourceId());
|
|
||||||
issueParam.setDevIds(param.getDevIds());
|
|
||||||
issueParam.setScriptId(param.getScriptId());
|
|
||||||
|
|
||||||
if (param.getReCheckType().equals(SourceOperateCodeEnum.RE_ERROR_TEST.getValue())) {
|
|
||||||
//不合格项复检
|
|
||||||
Set<Integer> indexes = new HashSet<>();
|
|
||||||
StorageParam storageParam = new StorageParam();
|
|
||||||
storageParam.setCode(param.getCode());
|
|
||||||
storageParam.setScriptId(param.getScriptId());
|
|
||||||
param.getDevIds().forEach(devId -> {
|
|
||||||
storageParam.setDevId(devId);
|
|
||||||
indexes.addAll(adHarmonicService.getIndex(storageParam));
|
|
||||||
});
|
|
||||||
issueParam.setIndexList(indexes.stream().collect(Collectors.toList()));
|
|
||||||
issueParam.setIsPhaseSequence(SourceOperateCodeEnum.RE_ERROR_TEST.getValue());
|
|
||||||
} else {
|
|
||||||
issueParam.setIsPhaseSequence(CommonEnum.FORMAL_TEST.getValue());
|
|
||||||
}
|
|
||||||
//正式检测
|
|
||||||
sourceIssues = pqScriptDtlsService.listSourceIssue(issueParam);
|
|
||||||
sourceIssues = sourceIssues.stream().sorted(Comparator.comparing(SourceIssue::getIndex)).collect(Collectors.toList());
|
|
||||||
// 使用 LinkedHashMap 保持分组顺序
|
|
||||||
Map<String, List<SourceIssue>> groupedIssues = sourceIssues.stream()
|
|
||||||
.collect(Collectors.groupingBy(
|
|
||||||
SourceIssue::getType,
|
|
||||||
LinkedHashMap::new,
|
|
||||||
Collectors.toList()
|
|
||||||
));
|
|
||||||
|
|
||||||
// 将分组后的元素合并成一个新的集合,保持原有顺序
|
|
||||||
sourceIssues = groupedIssues.values().stream()
|
|
||||||
.flatMap(List::stream)
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
// 存放所有检测小项
|
|
||||||
SocketManager.addSourceList(sourceIssues);
|
|
||||||
// 按照大项分组。key为大项code,value为小项个数
|
|
||||||
Map<String, Long> sourceIssueMap = sourceIssues.stream().collect(Collectors.groupingBy(SourceIssue::getType, Collectors.counting()));
|
|
||||||
SocketManager.initMap(sourceIssueMap);
|
|
||||||
|
|
||||||
//告诉前端当前项开始了
|
|
||||||
WebSocketVO<Object> webSocketVO = new WebSocketVO<>();
|
|
||||||
String type = sourceIssues.get(0).getType();
|
|
||||||
if (ResultUnitEnum.P.getCode().equals(type)) {
|
|
||||||
sourceIssues.get(0).setType(ResultUnitEnum.V_ABSOLUTELY.getCode());
|
|
||||||
webSocketVO.setRequestId(ResultUnitEnum.P.getCode() + CnSocketUtil.START_TAG);
|
|
||||||
} else {
|
|
||||||
webSocketVO.setRequestId(sourceIssues.get(0).getType() + CnSocketUtil.START_TAG);
|
|
||||||
}
|
|
||||||
FormalTestManager.currentIssue = sourceIssues.get(0);
|
|
||||||
socketMsg.setData(JSON.toJSONString(sourceIssues.get(0)));
|
|
||||||
socketMsg.setRequestId(SourceOperateCodeEnum.FORMAL_REAL.getValue() + CnSocketUtil.STEP_TAG + type);
|
|
||||||
socketMsg.setOperateCode(SourceOperateCodeEnum.OPER_GATHER.getValue());
|
|
||||||
SocketManager.sendMsg(param.getUserPageId() + CnSocketUtil.SOURCE_TAG, JSON.toJSONString(socketMsg));
|
|
||||||
|
|
||||||
webSocketVO.setDesc(null);
|
|
||||||
WebServiceManager.sendMsg(param.getUserPageId(), JSON.toJSONString(webSocketVO));
|
|
||||||
} else {
|
} else {
|
||||||
//后续什么都不做
|
//后续什么都不做
|
||||||
System.out.println("预检测流程结束-----------------关闭源");
|
System.out.println("预检测流程结束-----------------关闭源");
|
||||||
@@ -1264,6 +1153,97 @@ public class SocketDevResponseService {
|
|||||||
// key为 检测大项对应的code,value为当前大项的检测结果
|
// key为 检测大项对应的code,value为当前大项的检测结果
|
||||||
Map<String, List<DevLineTestResult>> targetTestMap = new HashMap<>();
|
Map<String, List<DevLineTestResult>> targetTestMap = new HashMap<>();
|
||||||
|
|
||||||
|
public void startFormalAfterProgressRestore(PreDetectionParam param, Integer nextSort) {
|
||||||
|
FormalTestManager.resumeFormalPending = false;
|
||||||
|
FormalTestManager.resumeNextSort = nextSort;
|
||||||
|
if (nextSort == null) {
|
||||||
|
WebServiceManager.sendDetectionMessage(param.getUserPageId(), "formal_progress_no_next", null, null, null);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
startFormalScripts(param, nextSort, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void startFormalScripts(PreDetectionParam param, Integer startSort, boolean waitForProgressRestore) {
|
||||||
|
List<SourceIssue> sourceIssues = buildFormalIssues(param);
|
||||||
|
if (ObjectUtil.isNotNull(startSort)) {
|
||||||
|
sourceIssues = sourceIssues.stream()
|
||||||
|
.filter(issue -> issue.getIndex() >= startSort)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
sourceIssues = sourceIssues.stream()
|
||||||
|
.sorted(Comparator.comparing(SourceIssue::getIndex))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
Map<String, List<SourceIssue>> groupedIssues = sourceIssues.stream()
|
||||||
|
.collect(Collectors.groupingBy(SourceIssue::getType, LinkedHashMap::new, Collectors.toList()));
|
||||||
|
sourceIssues = groupedIssues.values().stream().flatMap(List::stream).collect(Collectors.toList());
|
||||||
|
if (!param.isResumeFormal() && CollUtil.isNotEmpty(sourceIssues)) {
|
||||||
|
iPqDevService.clearFormalProgressForNewRun(param.getDevIds());
|
||||||
|
}
|
||||||
|
SocketManager.addSourceList(sourceIssues);
|
||||||
|
Map<String, Long> sourceIssueMap = sourceIssues.stream()
|
||||||
|
.collect(Collectors.groupingBy(SourceIssue::getType, Collectors.counting()));
|
||||||
|
SocketManager.initMap(sourceIssueMap);
|
||||||
|
|
||||||
|
if (waitForProgressRestore) {
|
||||||
|
FormalTestManager.resumeFormalPending = true;
|
||||||
|
WebServiceManager.sendDetectionMessage(param.getUserPageId(), "formal_progress_required", null, null, null);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
sendFirstFormalIssue(param, sourceIssues);
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<SourceIssue> buildFormalIssues(PreDetectionParam param) {
|
||||||
|
PqScriptIssueParam issueParam = new PqScriptIssueParam();
|
||||||
|
issueParam.setSourceId(param.getSourceName());
|
||||||
|
issueParam.setPlanId(param.getPlanId());
|
||||||
|
issueParam.setDevIds(param.getDevIds());
|
||||||
|
issueParam.setScriptId(param.getScriptId());
|
||||||
|
|
||||||
|
if (!param.isResumeFormal() && SourceOperateCodeEnum.RE_ERROR_TEST.getValue().equals(param.getReCheckType())) {
|
||||||
|
Set<Integer> indexes = new HashSet<>();
|
||||||
|
StorageParam storageParam = new StorageParam();
|
||||||
|
storageParam.setCode(param.getCode());
|
||||||
|
storageParam.setScriptId(param.getScriptId());
|
||||||
|
param.getDevIds().forEach(devId -> {
|
||||||
|
storageParam.setDevId(devId);
|
||||||
|
indexes.addAll(adHarmonicService.getIndex(storageParam));
|
||||||
|
});
|
||||||
|
issueParam.setIndexList(indexes.stream().collect(Collectors.toList()));
|
||||||
|
issueParam.setIsPhaseSequence(SourceOperateCodeEnum.RE_ERROR_TEST.getValue());
|
||||||
|
} else {
|
||||||
|
issueParam.setIsPhaseSequence(CommonEnum.FORMAL_TEST.getValue());
|
||||||
|
}
|
||||||
|
return pqScriptDtlsService.listSourceIssue(issueParam);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void sendFirstFormalIssue(PreDetectionParam param, List<SourceIssue> sourceIssues) {
|
||||||
|
if (CollUtil.isEmpty(sourceIssues)) {
|
||||||
|
WebServiceManager.sendDetectionMessage(param.getUserPageId(), "formal_progress_no_next", null, null, null);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
SourceIssue firstIssue = sourceIssues.get(0);
|
||||||
|
WebSocketVO<Object> webSocketVO = new WebSocketVO<>();
|
||||||
|
String type = firstIssue.getType();
|
||||||
|
if (StrUtil.isNotBlank(firstIssue.getOtherType())) {
|
||||||
|
firstIssue.setType(PowerIndexEnum.V.getKey());
|
||||||
|
webSocketVO.setRequestId(firstIssue.getOtherType() + CnSocketUtil.START_TAG);
|
||||||
|
type = firstIssue.getOtherType();
|
||||||
|
} else {
|
||||||
|
webSocketVO.setRequestId(firstIssue.getType() + CnSocketUtil.START_TAG);
|
||||||
|
}
|
||||||
|
FormalTestManager.currentIssue = firstIssue;
|
||||||
|
FormalTestManager.resumeFormalStartTime = LocalDateTime.now();
|
||||||
|
|
||||||
|
SocketMsg<String> socketMsg = new SocketMsg<>();
|
||||||
|
socketMsg.setOperateCode(SourceOperateCodeEnum.OPER_GATHER.getValue());
|
||||||
|
socketMsg.setData(JSON.toJSONString(firstIssue));
|
||||||
|
socketMsg.setRequestId(SourceOperateCodeEnum.FORMAL_REAL.getValue() + CnSocketUtil.STEP_TAG + type);
|
||||||
|
SocketManager.sendMsg(param.getUserPageId() + CnSocketUtil.SOURCE_TAG, JSON.toJSONString(socketMsg));
|
||||||
|
|
||||||
|
webSocketVO.setDesc(null);
|
||||||
|
WebServiceManager.sendMsg(param.getUserPageId(), JSON.toJSONString(webSocketVO));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 正式检测
|
* 正式检测
|
||||||
*/
|
*/
|
||||||
@@ -1305,9 +1285,9 @@ public class SocketDevResponseService {
|
|||||||
|
|
||||||
//小项检测完后小项数减一,并更新map
|
//小项检测完后小项数减一,并更新map
|
||||||
long residueCount = 0;
|
long residueCount = 0;
|
||||||
if (sourceIssue.getIsP()) {
|
if (StrUtil.isNotBlank(sourceIssue.getOtherType())) {
|
||||||
residueCount = SocketManager.getSourceTarget(ResultUnitEnum.P.getCode()) - 1;
|
residueCount = SocketManager.getSourceTarget(sourceIssue.getOtherType()) - 1;
|
||||||
SocketManager.addTargetMap(ResultUnitEnum.P.getCode(), residueCount);
|
SocketManager.addTargetMap(sourceIssue.getOtherType(), residueCount);
|
||||||
} else {
|
} else {
|
||||||
residueCount = SocketManager.getSourceTarget(sourceIssue.getType()) - 1;
|
residueCount = SocketManager.getSourceTarget(sourceIssue.getType()) - 1;
|
||||||
SocketManager.addTargetMap(sourceIssue.getType(), residueCount);
|
SocketManager.addTargetMap(sourceIssue.getType(), residueCount);
|
||||||
@@ -1351,14 +1331,15 @@ public class SocketDevResponseService {
|
|||||||
List<SourceIssue> sourceIssueList = SocketManager.getSourceList();
|
List<SourceIssue> sourceIssueList = SocketManager.getSourceList();
|
||||||
if (CollUtil.isNotEmpty(sourceIssueList)) {
|
if (CollUtil.isNotEmpty(sourceIssueList)) {
|
||||||
SourceIssue sourceIssues = SocketManager.getSourceList().get(0);
|
SourceIssue sourceIssues = SocketManager.getSourceList().get(0);
|
||||||
|
|
||||||
|
String type = sourceIssues.getType();
|
||||||
|
if (StrUtil.isNotBlank(sourceIssues.getOtherType())) {
|
||||||
|
sourceIssues.setType(PowerIndexEnum.V.getKey());
|
||||||
|
type = sourceIssues.getOtherType();
|
||||||
|
}
|
||||||
// 如果上一个大项检测完成,则检测下一个大项,并向前端推送消息
|
// 如果上一个大项检测完成,则检测下一个大项,并向前端推送消息
|
||||||
if (residueCount == 0) {
|
if (residueCount == 0) {
|
||||||
WebServiceManager.sendDetectionMessage(param.getUserPageId(), sourceIssues.getType() + CnSocketUtil.START_TAG, null, new ArrayList<>(), null);
|
WebServiceManager.sendDetectionMessage(param.getUserPageId(), type + CnSocketUtil.START_TAG, null, new ArrayList<>(), null);
|
||||||
}
|
|
||||||
String type = sourceIssues.getType();
|
|
||||||
if (sourceIssues.getIsP()) {
|
|
||||||
sourceIssues.setType(ResultUnitEnum.V_ABSOLUTELY.getCode());
|
|
||||||
type = ResultUnitEnum.P.getCode();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//控源下发下一个小项脚本
|
//控源下发下一个小项脚本
|
||||||
@@ -1374,8 +1355,14 @@ 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);
|
||||||
|
if (Boolean.TRUE.equals(dataCheck)) {
|
||||||
|
resultService.tryNotifyThirdPartyAfterFormalTest(param);
|
||||||
|
}
|
||||||
CnSocketUtil.quitSend(param);
|
CnSocketUtil.quitSend(param);
|
||||||
|
// 数模式检测全部小项完成 → 释放锁,避免用户必须点"停止"才能让出
|
||||||
|
DetectionLockManager.getInstance()
|
||||||
|
.releaseIfMatchPage(param.getUserPageId(), "DEV_TEST_FINISHED");
|
||||||
}
|
}
|
||||||
successComm.clear();
|
successComm.clear();
|
||||||
FormalTestManager.realDataXiList.clear();
|
FormalTestManager.realDataXiList.clear();
|
||||||
@@ -1554,6 +1541,7 @@ public class SocketDevResponseService {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param issue
|
* @param issue
|
||||||
* @return key为V或I,value为对应的源下发信息
|
* @return key为V或I,value为对应的源下发信息
|
||||||
@@ -1792,9 +1780,87 @@ public class SocketDevResponseService {
|
|||||||
//字典树
|
//字典树
|
||||||
SocketManager.valueTypeMap = iPqScriptCheckDataService.getValueTypeMap(param.getScriptId());
|
SocketManager.valueTypeMap = iPqScriptCheckDataService.getValueTypeMap(param.getScriptId());
|
||||||
|
|
||||||
if (param.getTestItemList().get(1)) {
|
if (param.isCoefficientSelected()) {
|
||||||
initXiManager(param);
|
initXiManager(param);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FormalTestManager.overload = getOverloadResult(param);
|
||||||
|
FormalTestManager.checkStartTime = LocalDateTime.now();
|
||||||
|
FormalTestManager.reCheckType = param.getReCheckType();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取过载测试结果
|
||||||
|
*
|
||||||
|
* @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 thd = harmList.stream().map(harmModel -> harmModel.getFAmp() * harmModel.getFAmp() / 10000).mapToDouble(x -> x).sum();
|
||||||
|
if (maxVoltage.compareTo(BigDecimal.valueOf(Math.sqrt(1 + thd) * fAmp)) < 0) {
|
||||||
|
return channelType.contains("U") ? 1 : 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 间谐波判断
|
||||||
|
if (channelListDTO.getInHarmFlag()) {
|
||||||
|
List<SourceIssue.ChannelListDTO.InharmModel> inharmList = channelListDTO.getInharmList();
|
||||||
|
double thd = inharmList.stream().map(harmModel -> harmModel.getFAmp() * harmModel.getFAmp() / 10000).mapToDouble(x -> x).sum();
|
||||||
|
if (maxVoltage.compareTo(BigDecimal.valueOf(Math.sqrt(1 + thd) * fAmp)) < 0) {
|
||||||
|
return channelType.contains("U") ? 1 : 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
//初始化系数校验参数
|
//初始化系数校验参数
|
||||||
@@ -1816,8 +1882,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());
|
||||||
@@ -1871,9 +1937,6 @@ public class SocketDevResponseService {
|
|||||||
|
|
||||||
if (nonHarmonicList.contains(sourceIssue.getType())) {
|
if (nonHarmonicList.contains(sourceIssue.getType())) {
|
||||||
for (DevData.SqlDataDTO sqlDataDTO : data.getSqlData()) {
|
for (DevData.SqlDataDTO sqlDataDTO : data.getSqlData()) {
|
||||||
if (sqlDataDTO.getDesc().equals("PF")) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
DevData.SqlDataDTO.ListDTO listDTO = sqlDataDTO.getList();
|
DevData.SqlDataDTO.ListDTO listDTO = sqlDataDTO.getList();
|
||||||
SimAndDigNonHarmonicResult adNonHarmonicResult = new SimAndDigNonHarmonicResult();
|
SimAndDigNonHarmonicResult adNonHarmonicResult = new SimAndDigNonHarmonicResult();
|
||||||
adNonHarmonicResult.setTimeId(localDateTime);
|
adNonHarmonicResult.setTimeId(localDateTime);
|
||||||
@@ -1916,7 +1979,7 @@ public class SocketDevResponseService {
|
|||||||
adHarmonicResult.setAdType(checkDataMap.get(sqlDataDTO.getDesc()));
|
adHarmonicResult.setAdType(checkDataMap.get(sqlDataDTO.getDesc()));
|
||||||
adHarmonicResult.setDataType(sourceIssue.getDataType());
|
adHarmonicResult.setDataType(sourceIssue.getDataType());
|
||||||
|
|
||||||
if (!DicDataEnum.HSV.getCode().equals(sourceIssue.getType()) && !DicDataEnum.HSI.getCode().equals(sourceIssue.getType()) && !DicDataEnum.HP.getCode().equals(sourceIssue.getType())) {
|
if (!PowerIndexEnum.HSV.getKey().equals(sourceIssue.getType()) && !PowerIndexEnum.HSI.getKey().equals(sourceIssue.getType()) && !PowerIndexEnum.HP.getKey().equals(sourceIssue.getType())) {
|
||||||
if (CollUtil.isNotEmpty(data.getSqlData())) {
|
if (CollUtil.isNotEmpty(data.getSqlData())) {
|
||||||
DevData.SqlDataDTO.ListDTO vvv = data.getSqlData().stream().filter(it -> it.getDesc().equals(dui)).collect(Collectors.toList()).get(0).getList();
|
DevData.SqlDataDTO.ListDTO vvv = data.getSqlData().stream().filter(it -> it.getDesc().equals(dui)).collect(Collectors.toList()).get(0).getList();
|
||||||
Double aV = vvv.getA();
|
Double aV = vvv.getA();
|
||||||
@@ -1941,7 +2004,7 @@ public class SocketDevResponseService {
|
|||||||
List<String> c = tem.getC();
|
List<String> c = tem.getC();
|
||||||
|
|
||||||
Class<SimAndDigHarmonicResult> example = (Class<SimAndDigHarmonicResult>) adHarmonicResult.getClass();
|
Class<SimAndDigHarmonicResult> example = (Class<SimAndDigHarmonicResult>) adHarmonicResult.getClass();
|
||||||
if (DicDataEnum.HSV.getCode().equals(sourceIssue.getType()) || DicDataEnum.HSI.getCode().equals(sourceIssue.getType())) {
|
if (PowerIndexEnum.HSV.getKey().equals(sourceIssue.getType()) || PowerIndexEnum.HSI.getKey().equals(sourceIssue.getType())) {
|
||||||
for (int i = 1; i < a.size() + 1; i++) {
|
for (int i = 1; i < a.size() + 1; i++) {
|
||||||
try {
|
try {
|
||||||
Field aField = example.getDeclaredField("aValue" + i);
|
Field aField = example.getDeclaredField("aValue" + i);
|
||||||
|
|||||||
@@ -17,11 +17,10 @@ import com.njcn.gather.device.pojo.vo.PreDetection;
|
|||||||
import com.njcn.gather.device.service.IPqDevService;
|
import com.njcn.gather.device.service.IPqDevService;
|
||||||
import com.njcn.gather.plan.pojo.po.AdPlanSource;
|
import com.njcn.gather.plan.pojo.po.AdPlanSource;
|
||||||
import com.njcn.gather.plan.service.IAdPlanSourceService;
|
import com.njcn.gather.plan.service.IAdPlanSourceService;
|
||||||
import com.njcn.gather.result.pojo.enums.ResultUnitEnum;
|
import com.njcn.gather.report.pojo.enums.PowerIndexEnum;
|
||||||
import com.njcn.gather.script.pojo.po.SourceIssue;
|
import com.njcn.gather.script.pojo.po.SourceIssue;
|
||||||
import com.njcn.gather.source.pojo.po.SourceInitialize;
|
import com.njcn.gather.source.pojo.po.SourceInitialize;
|
||||||
import com.njcn.gather.source.service.IPqSourceService;
|
import com.njcn.gather.source.service.IPqSourceService;
|
||||||
import com.njcn.gather.system.pojo.enums.DicDataEnum;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.collections4.CollectionUtils;
|
import org.apache.commons.collections4.CollectionUtils;
|
||||||
@@ -121,6 +120,15 @@ public class SocketSourceResponseService {
|
|||||||
sendErrorAndQuit(param, socketDataMsg, errorCode.getMessage());
|
sendErrorAndQuit(param, socketDataMsg, errorCode.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void sendSimulateInitFailure(PreDetectionParam param, String errorMessage) {
|
||||||
|
SocketDataMsg socketDataMsg = new SocketDataMsg();
|
||||||
|
socketDataMsg.setRequestId(SourceOperateCodeEnum.YJC_YTXJY.getValue());
|
||||||
|
socketDataMsg.setOperateCode(SourceOperateCodeEnum.INIT_GATHER.getValue());
|
||||||
|
socketDataMsg.setCode(SourceResponseCodeEnum.UNKNOWN_ERROR.getCode());
|
||||||
|
socketDataMsg.setData(errorMessage);
|
||||||
|
sendWebSocketMessage(param.getUserPageId(), socketDataMsg);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 当前检测会话中的设备列表
|
* 当前检测会话中的设备列表
|
||||||
@@ -214,12 +222,12 @@ public class SocketSourceResponseService {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
// TODO: 记录未知操作码到日志,并向前端发送友好提示
|
sendSimulateInitFailure(param, "未知操作码");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// TODO: 向前端发送错误提示
|
|
||||||
log.error("程控源响应消息操作码解析失败,原始消息: {}, 解析结果: {}", msg, enumByCode);
|
log.error("程控源响应消息操作码解析失败,原始消息: {}, 解析结果: {}", msg, enumByCode);
|
||||||
|
sendSimulateInitFailure(param, "未知操作码");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -272,10 +280,11 @@ public class SocketSourceResponseService {
|
|||||||
sendWebSocketMessage(param.getUserPageId(), socketDataMsg);
|
sendWebSocketMessage(param.getUserPageId(), socketDataMsg);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
// 未识别的响应码:发送通用错误消息
|
sendSimulateInitFailure(param, "未知状态码");
|
||||||
WebServiceManager.sendUnknownErrorMessage(param.getUserPageId());
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
sendSimulateInitFailure(param, "未知状态码");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -376,13 +385,21 @@ public class SocketSourceResponseService {
|
|||||||
|
|
||||||
//重新下发脚本
|
//重新下发脚本
|
||||||
String type = FormalTestManager.currentIssue.getType();
|
String type = FormalTestManager.currentIssue.getType();
|
||||||
if (ResultUnitEnum.P.getCode().equals(type)) {
|
if (PowerIndexEnum.P.getKey().equals(type)) {
|
||||||
FormalTestManager.currentIssue.setType(ResultUnitEnum.V_ABSOLUTELY.getCode());
|
FormalTestManager.currentIssue.setType(PowerIndexEnum.V.getKey());
|
||||||
}
|
}
|
||||||
socketMsg.setOperateCode(SourceOperateCodeEnum.OPER_GATHER.getValue());
|
socketMsg.setOperateCode(SourceOperateCodeEnum.OPER_GATHER.getValue());
|
||||||
socketMsg.setData(JSON.toJSONString(FormalTestManager.currentIssue));
|
socketMsg.setData(JSON.toJSONString(FormalTestManager.currentIssue));
|
||||||
socketMsg.setRequestId(SourceOperateCodeEnum.FORMAL_REAL.getValue() + CnSocketUtil.STEP_TAG + type);
|
socketMsg.setRequestId(SourceOperateCodeEnum.FORMAL_REAL.getValue() + CnSocketUtil.STEP_TAG + type);
|
||||||
SocketManager.sendMsg(param.getUserPageId() + CnSocketUtil.SOURCE_TAG, JSON.toJSONString(socketMsg));
|
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 {
|
} else {
|
||||||
//todo 前端推送收到的消息暂未处理好
|
//todo 前端推送收到的消息暂未处理好
|
||||||
sendWebSocketMessage(param.getUserPageId(), socketDataMsg);
|
sendWebSocketMessage(param.getUserPageId(), socketDataMsg);
|
||||||
@@ -397,6 +414,7 @@ public class SocketSourceResponseService {
|
|||||||
// 使用智能发送工具类,自动管理设备连接
|
// 使用智能发送工具类,自动管理设备连接
|
||||||
socketManager.smartSendToDevice(param, json);
|
socketManager.smartSendToDevice(param, json);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case UNPROCESSED_BUSINESS:
|
case UNPROCESSED_BUSINESS:
|
||||||
sendWebSocketMessage(param.getUserPageId(), socketDataMsg);
|
sendWebSocketMessage(param.getUserPageId(), socketDataMsg);
|
||||||
@@ -519,14 +537,14 @@ public class SocketSourceResponseService {
|
|||||||
int ignoreCount;
|
int ignoreCount;
|
||||||
int readData;
|
int readData;
|
||||||
|
|
||||||
if (DicDataEnum.F.getCode().equals(sourceIssue.getType())) {
|
if (PowerIndexEnum.F.getKey().equals(sourceIssue.getType())) {
|
||||||
// 闪变检测:数据变化较慢,只需少量预热和读取
|
// 闪变检测:数据变化较慢,只需少量预热和读取
|
||||||
// 闪变测量稳定性好,预热1次即可
|
// 闪变测量稳定性好,预热1次即可
|
||||||
ignoreCount = 1;
|
ignoreCount = 1;
|
||||||
// 读取2次数据计算闪变值
|
// 读取2次数据计算闪变值
|
||||||
readData = 2;
|
readData = 2;
|
||||||
socketMsg.setOperateCode(SourceOperateCodeEnum.DEV_DATA_REQUEST_01.getValue());
|
socketMsg.setOperateCode(SourceOperateCodeEnum.DEV_DATA_REQUEST_01.getValue());
|
||||||
} else if (DicDataEnum.VOLTAGE.getCode().equals(sourceIssue.getType())) {
|
} else if (PowerIndexEnum.VOLTAGE.getKey().equals(sourceIssue.getType())) {
|
||||||
// 暂态电压检测:需要更多预热时间,但只读取一次快照
|
// 暂态电压检测:需要更多预热时间,但只读取一次快照
|
||||||
// 暂态事件需要5次预热确保触发稳定
|
// 暂态事件需要5次预热确保触发稳定
|
||||||
ignoreCount = 5;
|
ignoreCount = 5;
|
||||||
@@ -556,9 +574,6 @@ public class SocketSourceResponseService {
|
|||||||
DevPhaseSequenceParam phaseSequenceParam = new DevPhaseSequenceParam();
|
DevPhaseSequenceParam phaseSequenceParam = new DevPhaseSequenceParam();
|
||||||
// 设置监测点ID列表
|
// 设置监测点ID列表
|
||||||
phaseSequenceParam.setMoniterIdList(monitorIdList);
|
phaseSequenceParam.setMoniterIdList(monitorIdList);
|
||||||
if (socketDataMsg.getRequestId().equals(SourceOperateCodeEnum.FORMAL_REAL.getValue() + CnSocketUtil.STEP_TAG + "P")) {
|
|
||||||
comm.add("real$PF");
|
|
||||||
}
|
|
||||||
// 设置数据类型列表
|
// 设置数据类型列表
|
||||||
phaseSequenceParam.setDataType(comm);
|
phaseSequenceParam.setDataType(comm);
|
||||||
// 设置读取次数
|
// 设置读取次数
|
||||||
|
|||||||
@@ -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; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -33,13 +33,19 @@ public enum DetectionCodeEnum {
|
|||||||
IA("IA", "电流相角"),
|
IA("IA", "电流相角"),
|
||||||
I1A("I1A", "电流基波角度值"),
|
I1A("I1A", "电流基波角度值"),
|
||||||
V_UNBAN("V_UNBAN", "三相电压负序不平衡度"),
|
V_UNBAN("V_UNBAN", "三相电压负序不平衡度"),
|
||||||
|
SeqV("SeqV", "电压序分量"),
|
||||||
I_UNBAN("I_UNBAN", "三相电流负序不平衡度"),
|
I_UNBAN("I_UNBAN", "三相电流负序不平衡度"),
|
||||||
|
SeqA("SeqA", "电流序分量"),
|
||||||
PST("PST", "短时间闪变"),
|
PST("PST", "短时间闪变"),
|
||||||
W("W", "有功功率"),
|
W("W", "总有功功率"),
|
||||||
VARW("VARW", "无功功率"),
|
VARW("VARW", "总无功功率"),
|
||||||
VAW("VAW", "视在功率"),
|
VAW("VAW", "总视在功率"),
|
||||||
// PF("PF", "功率因数"),
|
PF("PF", "功率因数"),
|
||||||
// P_FUND("P_FUND", "基波有功功率"),
|
TOTW("TotW", "三相总有功功率"),
|
||||||
|
TOTVA("TotVA", "三相总视在功率"),
|
||||||
|
TOTVAR("TotVAr", "三相总无功功率"),
|
||||||
|
TOTPF("TotPF","三相功率因数"),
|
||||||
|
// P_FUND("P_FUND", "基波有功功率"),
|
||||||
// P_HVAR("P_HVAR", "基波无功功率"),
|
// P_HVAR("P_HVAR", "基波无功功率"),
|
||||||
// P_HVA("P_HVA", "基波视在功率"),
|
// P_HVA("P_HVA", "基波视在功率"),
|
||||||
I1("I1", "基波电流"),
|
I1("I1", "基波电流"),
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|||||||
@@ -38,10 +38,31 @@ public class ContrastDetectionParam {
|
|||||||
@NotEmpty(message = DetectionValidMessage.PAIRS_NOT_EMPTY)
|
@NotEmpty(message = DetectionValidMessage.PAIRS_NOT_EMPTY)
|
||||||
private Map<String, String> pairs;
|
private Map<String, String> pairs;
|
||||||
/**
|
/**
|
||||||
* 检测项列表。第一个元素为预检测、第二个元素为系数校准、第三个元素为正式检测
|
* 检测项列表。第一个元素为预检测、第二个元素为系数校准、第三个元素为守时校验、第四个元素为正式检测。
|
||||||
|
* 比对场景暂不支持系数校准和守时校验,第二、第三个元素固定为 false。
|
||||||
*/
|
*/
|
||||||
private List<Boolean> testItemList;
|
private List<Boolean> testItemList;
|
||||||
|
|
||||||
|
public boolean isPreTestSelected() {
|
||||||
|
return isTestItemSelected(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isCoefficientSelected() {
|
||||||
|
return isTestItemSelected(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isTimeCheckSelected() {
|
||||||
|
return isTestItemSelected(2);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isFormalTestSelected() {
|
||||||
|
return isTestItemSelected(3);
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isTestItemSelected(int index) {
|
||||||
|
return testItemList != null && testItemList.size() > index && Boolean.TRUE.equals(testItemList.get(index));
|
||||||
|
}
|
||||||
|
|
||||||
private String userId;
|
private String userId;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
package com.njcn.gather.detection.pojo.param;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import javax.validation.constraints.NotBlank;
|
||||||
|
import javax.validation.constraints.NotEmpty;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class FormalProgressParam {
|
||||||
|
@NotBlank(message = "计划id不可为空")
|
||||||
|
private String planId;
|
||||||
|
|
||||||
|
@NotEmpty(message = "装置不能为空")
|
||||||
|
private List<String> devIds;
|
||||||
|
|
||||||
|
private String userPageId;
|
||||||
|
|
||||||
|
private String userId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 保存暂存进度时必传;查询/放行续检时以后端设备表为准。
|
||||||
|
*/
|
||||||
|
private Integer formalCheckTime;
|
||||||
|
}
|
||||||
@@ -5,7 +5,6 @@ import lombok.Data;
|
|||||||
import javax.validation.constraints.NotBlank;
|
import javax.validation.constraints.NotBlank;
|
||||||
import javax.validation.constraints.NotEmpty;
|
import javax.validation.constraints.NotEmpty;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author wr
|
* @author wr
|
||||||
@@ -46,6 +45,11 @@ public class PreDetectionParam {
|
|||||||
*/
|
*/
|
||||||
private String sourceId;
|
private String sourceId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 源名称
|
||||||
|
*/
|
||||||
|
private String sourceName;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 所属误差体系
|
* 所属误差体系
|
||||||
*/
|
*/
|
||||||
@@ -71,7 +75,36 @@ public class PreDetectionParam {
|
|||||||
private Float humidity;
|
private Float humidity;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 检测项列表。第一个元素为预检测、第二个元素为系数校准、第三个元素为正式检测
|
* 检测项列表。第一个元素为预检测、第二个元素为系数校准、第三个元素为守时校验、第四个元素为正式检测
|
||||||
*/
|
*/
|
||||||
private List<Boolean> testItemList;
|
private List<Boolean> testItemList;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否从正式检测暂存进度续检
|
||||||
|
*/
|
||||||
|
private Boolean resumeFormal;
|
||||||
|
|
||||||
|
public boolean isPreTestSelected() {
|
||||||
|
return isTestItemSelected(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isCoefficientSelected() {
|
||||||
|
return isTestItemSelected(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isTimeCheckSelected() {
|
||||||
|
return isTestItemSelected(2);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isFormalTestSelected() {
|
||||||
|
return isTestItemSelected(3);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isResumeFormal() {
|
||||||
|
return Boolean.TRUE.equals(resumeFormal);
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isTestItemSelected(int index) {
|
||||||
|
return testItemList != null && testItemList.size() > index && Boolean.TRUE.equals(testItemList.get(index));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,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;
|
||||||
|
}
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
package com.njcn.gather.detection.pojo.vo;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class FormalProgressVO {
|
||||||
|
private Integer formalCheckTime;
|
||||||
|
private Integer minMaxSort;
|
||||||
|
private Integer nextSort;
|
||||||
|
private Double process;
|
||||||
|
private List<TableRow> tableRows = new ArrayList<>();
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public static class TableRow {
|
||||||
|
private String scriptType;
|
||||||
|
private String scriptCode;
|
||||||
|
private String scriptName;
|
||||||
|
private List<DeviceResult> devices = new ArrayList<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public static class DeviceResult {
|
||||||
|
private String deviceId;
|
||||||
|
private String deviceName;
|
||||||
|
private List<Integer> chnResult = new ArrayList<>();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
package com.njcn.gather.detection.service;
|
||||||
|
|
||||||
|
import com.njcn.gather.detection.pojo.param.FormalProgressParam;
|
||||||
|
import com.njcn.gather.detection.pojo.param.PreDetectionParam;
|
||||||
|
import com.njcn.gather.detection.pojo.vo.FormalProgressVO;
|
||||||
|
|
||||||
|
public interface FormalProgressService {
|
||||||
|
FormalProgressVO restoreAndRelease(FormalProgressParam param);
|
||||||
|
|
||||||
|
Integer calculateNextSort(PreDetectionParam param);
|
||||||
|
}
|
||||||
@@ -1,8 +1,10 @@
|
|||||||
package com.njcn.gather.detection.service;
|
package com.njcn.gather.detection.service;
|
||||||
|
|
||||||
import com.njcn.gather.detection.pojo.param.ContrastDetectionParam;
|
import com.njcn.gather.detection.pojo.param.ContrastDetectionParam;
|
||||||
|
import com.njcn.gather.detection.pojo.param.FormalProgressParam;
|
||||||
import com.njcn.gather.detection.pojo.param.PreDetectionParam;
|
import com.njcn.gather.detection.pojo.param.PreDetectionParam;
|
||||||
import com.njcn.gather.detection.pojo.param.SimulateDetectionParam;
|
import com.njcn.gather.detection.pojo.param.SimulateDetectionParam;
|
||||||
|
import com.njcn.gather.detection.pojo.vo.FormalProgressVO;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -33,6 +35,10 @@ public interface PreDetectionService {
|
|||||||
|
|
||||||
boolean restartTemTest(PreDetectionParam param);
|
boolean restartTemTest(PreDetectionParam param);
|
||||||
|
|
||||||
|
void saveFormalProgress(FormalProgressParam param);
|
||||||
|
|
||||||
|
FormalProgressVO formalProgress(FormalProgressParam param);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 模拟测试-源通讯校验
|
* 模拟测试-源通讯校验
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ import com.njcn.gather.monitor.pojo.po.PqMonitor;
|
|||||||
import com.njcn.gather.monitor.service.IPqMonitorService;
|
import com.njcn.gather.monitor.service.IPqMonitorService;
|
||||||
import com.njcn.gather.plan.pojo.enums.DataSourceEnum;
|
import com.njcn.gather.plan.pojo.enums.DataSourceEnum;
|
||||||
import com.njcn.gather.report.pojo.enums.PowerIndexEnum;
|
import com.njcn.gather.report.pojo.enums.PowerIndexEnum;
|
||||||
import com.njcn.gather.result.pojo.enums.ResultUnitEnum;
|
import com.njcn.gather.script.mapper.PqScriptMapper;
|
||||||
import com.njcn.gather.script.pojo.po.PqScriptCheckData;
|
import com.njcn.gather.script.pojo.po.PqScriptCheckData;
|
||||||
import com.njcn.gather.script.pojo.po.SourceIssue;
|
import com.njcn.gather.script.pojo.po.SourceIssue;
|
||||||
import com.njcn.gather.script.service.IPqScriptCheckDataService;
|
import com.njcn.gather.script.service.IPqScriptCheckDataService;
|
||||||
@@ -73,6 +73,7 @@ public class DetectionServiceImpl {
|
|||||||
private final IPqMonitorService pqMonitorService;
|
private final IPqMonitorService pqMonitorService;
|
||||||
private final IPqDevService pqDevService;
|
private final IPqDevService pqDevService;
|
||||||
private final IPqStandardDevGainRecordService pqStandardDevGainRecordService;
|
private final IPqStandardDevGainRecordService pqStandardDevGainRecordService;
|
||||||
|
private final PqScriptMapper pqScriptMapper;
|
||||||
|
|
||||||
public static final String TYPE_A = "A";
|
public static final String TYPE_A = "A";
|
||||||
public static final String TYPE_B = "B";
|
public static final String TYPE_B = "B";
|
||||||
@@ -80,7 +81,6 @@ public class DetectionServiceImpl {
|
|||||||
public static final String TYPE_T = "T";
|
public static final String TYPE_T = "T";
|
||||||
private final String U = "U";
|
private final String U = "U";
|
||||||
private final String I = "I";
|
private final String I = "I";
|
||||||
private final String F = "F";
|
|
||||||
private final String HP = "HP";
|
private final String HP = "HP";
|
||||||
private final String P = "P";
|
private final String P = "P";
|
||||||
private final String MAG = "MAG";
|
private final String MAG = "MAG";
|
||||||
@@ -161,30 +161,31 @@ public class DetectionServiceImpl {
|
|||||||
param.setIn(sourceIssue.getFIn());
|
param.setIn(sourceIssue.getFIn());
|
||||||
SysTestConfig oneConfig = sysTestConfigService.getOneConfig();
|
SysTestConfig oneConfig = sysTestConfigService.getOneConfig();
|
||||||
List<ErrDtlsCheckDataVO> errDtlsCheckData = pqErrSysDtlsService.listByPqErrSysIdAndTypes(param);
|
List<ErrDtlsCheckDataVO> errDtlsCheckData = pqErrSysDtlsService.listByPqErrSysIdAndTypes(param);
|
||||||
ResultUnitEnum resultUnitEnumByCode = ResultUnitEnum.getResultUnitEnumByCode(sourceIssue.getType());
|
PowerIndexEnum powerIndexEnum = PowerIndexEnum.getByKey(sourceIssue.getType());
|
||||||
if (sourceIssue.getIsP()) {
|
if (StrUtil.isNotBlank(sourceIssue.getOtherType())) {
|
||||||
resultUnitEnumByCode = ResultUnitEnum.P;
|
powerIndexEnum = PowerIndexEnum.getByKey(sourceIssue.getOtherType());
|
||||||
}
|
}
|
||||||
switch (resultUnitEnumByCode) {
|
|
||||||
|
switch (powerIndexEnum) {
|
||||||
/**
|
/**
|
||||||
* 频率
|
* 频率
|
||||||
*/
|
*/
|
||||||
case FREQ:
|
case FREQ:
|
||||||
return isQualified(dev, devIdMapComm, errDtlsCheckData, F, sourceIssue, dataRule, code, oneConfig.getScale());
|
return isQualified(dev, devIdMapComm, errDtlsCheckData, PowerIndexEnum.FREQ.getKey(), sourceIssue, dataRule, code, oneConfig.getScale());
|
||||||
case P:
|
case P:
|
||||||
return isQualified(dev, devIdMapComm, errDtlsCheckData, P, sourceIssue, dataRule, code, oneConfig.getScale());
|
return isQualified(dev, devIdMapComm, errDtlsCheckData, PowerIndexEnum.P.getKey(), sourceIssue, dataRule, code, oneConfig.getScale());
|
||||||
|
case ANGLE:
|
||||||
|
return isQualified(dev, devIdMapComm, errDtlsCheckData, PowerIndexEnum.ANGLE.getKey(), sourceIssue, dataRule, code, oneConfig.getScale());
|
||||||
/**
|
/**
|
||||||
* 电压
|
* 电压
|
||||||
*/
|
*/
|
||||||
case V_RELATIVE:
|
case V:
|
||||||
case V_ABSOLUTELY:
|
return isQualified(dev, devIdMapComm, errDtlsCheckData, PowerIndexEnum.V.getKey(), sourceIssue, dataRule, code, oneConfig.getScale());
|
||||||
return isQualified(dev, devIdMapComm, errDtlsCheckData, U, sourceIssue, dataRule, code, oneConfig.getScale());
|
|
||||||
/**
|
/**
|
||||||
* 电流
|
* 电流
|
||||||
*/
|
*/
|
||||||
case I_RELATIVE:
|
case I:
|
||||||
case I_ABSOLUTELY:
|
return isQualified(dev, devIdMapComm, errDtlsCheckData, PowerIndexEnum.I.getKey(), sourceIssue, dataRule, code, oneConfig.getScale());
|
||||||
return isQualified(dev, devIdMapComm, errDtlsCheckData, I, sourceIssue, dataRule, code, oneConfig.getScale());
|
|
||||||
/**
|
/**
|
||||||
* 谐波
|
* 谐波
|
||||||
*/
|
*/
|
||||||
@@ -205,22 +206,12 @@ public class DetectionServiceImpl {
|
|||||||
* 三相电压不平衡度
|
* 三相电压不平衡度
|
||||||
*/
|
*/
|
||||||
case IMBV:
|
case IMBV:
|
||||||
SimAndDigNonHarmonicResult vUnban = isUnBalanceOrFlickerQualified(dev, devIdMapComm, errDtlsCheckData, U, sourceIssue, dataRule, "V_UNBAN", oneConfig.getScale());
|
return isUnBalanceOrFlickerQualified(dev, devIdMapComm, errDtlsCheckData, U, sourceIssue, dataRule, code, oneConfig.getScale());
|
||||||
if (ObjectUtil.isNotNull(vUnban)) {
|
|
||||||
detectionDataDealService.acceptNonHarmonicResult(Arrays.asList(vUnban), code);
|
|
||||||
return vUnban.getResultFlag();
|
|
||||||
}
|
|
||||||
return 4;
|
|
||||||
/**
|
/**
|
||||||
* 三相电流不平衡度
|
* 三相电流不平衡度
|
||||||
*/
|
*/
|
||||||
case IMBA:
|
case IMBA:
|
||||||
SimAndDigNonHarmonicResult iUnban = isUnBalanceOrFlickerQualified(dev, devIdMapComm, errDtlsCheckData, I, sourceIssue, dataRule, "I_UNBAN", oneConfig.getScale());
|
return isUnBalanceOrFlickerQualified(dev, devIdMapComm, errDtlsCheckData, I, sourceIssue, dataRule, code, oneConfig.getScale());
|
||||||
if (ObjectUtil.isNotNull(iUnban)) {
|
|
||||||
detectionDataDealService.acceptNonHarmonicResult(Arrays.asList(iUnban), code);
|
|
||||||
return iUnban.getResultFlag();
|
|
||||||
}
|
|
||||||
return 4;
|
|
||||||
/**
|
/**
|
||||||
* 谐波有功功率
|
* 谐波有功功率
|
||||||
*/
|
*/
|
||||||
@@ -235,17 +226,11 @@ public class DetectionServiceImpl {
|
|||||||
* 闪变
|
* 闪变
|
||||||
*/
|
*/
|
||||||
case F:
|
case F:
|
||||||
SimAndDigNonHarmonicResult pst = isUnBalanceOrFlickerQualified(dev, devIdMapComm, errDtlsCheckData, null, sourceIssue, dataRule, "PST", oneConfig.getScale());
|
return isUnBalanceOrFlickerQualified(dev, devIdMapComm, errDtlsCheckData, DetectionCodeEnum.PST.getCode(), sourceIssue, dataRule, code, oneConfig.getScale());
|
||||||
if (ObjectUtil.isNotNull(pst)) {
|
|
||||||
detectionDataDealService.acceptNonHarmonicResult(Arrays.asList(pst), code);
|
|
||||||
return pst.getResultFlag();
|
|
||||||
}
|
|
||||||
return 4;
|
|
||||||
/**
|
/**
|
||||||
* 暂态
|
* 暂态
|
||||||
*/
|
*/
|
||||||
case VOLTAGE_MAG:
|
case VOLTAGE:
|
||||||
case VOLTAGE_DUR:
|
|
||||||
return isVoltageQualified(dev, devIdMapComm, errDtlsCheckData, sourceIssue, dataRule, code, oneConfig.getScale());
|
return isVoltageQualified(dev, devIdMapComm, errDtlsCheckData, sourceIssue, dataRule, code, oneConfig.getScale());
|
||||||
default:
|
default:
|
||||||
return isUnknownQualified(dev, devIdMapComm, errDtlsCheckData, sourceIssue, dataRule, code, oneConfig.getScale());
|
return isUnknownQualified(dev, devIdMapComm, errDtlsCheckData, sourceIssue, dataRule, code, oneConfig.getScale());
|
||||||
@@ -430,24 +415,36 @@ public class DetectionServiceImpl {
|
|||||||
List<SimAndDigNonHarmonicResult> info = new ArrayList<>();
|
List<SimAndDigNonHarmonicResult> info = new ArrayList<>();
|
||||||
List<String> devValueTypeList = sourceIssue.getDevValueTypeList();
|
List<String> devValueTypeList = sourceIssue.getDevValueTypeList();
|
||||||
for (String s : devValueTypeList) {
|
for (String s : devValueTypeList) {
|
||||||
if ((DetectionCodeEnum.REAL_PREFIX.getCode() + "PF").equals(s)) {
|
String[] splitArr = s.split("\\$");
|
||||||
continue;
|
|
||||||
}
|
|
||||||
// 根据数据处理规则取值。key为相别,value为值列表
|
// 根据数据处理规则取值。key为相别,value为值列表
|
||||||
Map<String, List<Double>> map = devListMap(dev, dataRule, s.split("\\$")[1]);
|
Map<String, List<Double>> map = devListMap(dev, dataRule, splitArr[1]);
|
||||||
|
List<ErrDtlsCheckDataVO> dtlsCheckData = null;
|
||||||
|
if (CollUtil.isNotEmpty(errDtlsCheckData)) {
|
||||||
|
dtlsCheckData = errDtlsCheckData.stream().filter(x -> x.getValueTypeCode().equals(splitArr[1])).collect(Collectors.toList());
|
||||||
|
}
|
||||||
Double fData = 1.0;
|
Double fData = 1.0;
|
||||||
if (U.equals(type)) {
|
if (PowerIndexEnum.V.getKey().equals(type)) {
|
||||||
fData = sourceIssue.getFUn();
|
fData = sourceIssue.getFUn();
|
||||||
}
|
}
|
||||||
if (I.equals(type)) {
|
if (PowerIndexEnum.I.getKey().equals(type)) {
|
||||||
fData = sourceIssue.getFIn();
|
fData = sourceIssue.getFIn();
|
||||||
}
|
}
|
||||||
if (F.equals(type)) {
|
if (PowerIndexEnum.FREQ.getKey().equals(type)) {
|
||||||
fData = sourceIssue.getFFreq();
|
fData = sourceIssue.getFFreq();
|
||||||
}
|
}
|
||||||
if (P.equals(type)) {
|
if (PowerIndexEnum.P.getKey().equals(type)) {
|
||||||
fData = sourceIssue.getFUn() * sourceIssue.getFIn();
|
if (!DetectionCodeEnum.PF.getCode().equals(splitArr[1]) && !DetectionCodeEnum.TOTPF.getCode().equals(splitArr[1])) {
|
||||||
|
Boolean valueType = pqScriptMapper.selectScriptIsValueType(sourceIssue.getScriptId());
|
||||||
|
if (valueType) {
|
||||||
|
fData = sourceIssue.getFUn() * sourceIssue.getFIn() / 100;
|
||||||
}
|
}
|
||||||
|
Double finalFData = fData;
|
||||||
|
dtlsCheckData.stream().forEach(x -> x.setValue(x.getValue() * finalFData));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// if (ResultUnitEnum.ANGLE.getCode().equals(type)) {
|
||||||
|
// fData = null;
|
||||||
|
// }
|
||||||
SimAndDigNonHarmonicResult result = new SimAndDigNonHarmonicResult();
|
SimAndDigNonHarmonicResult result = new SimAndDigNonHarmonicResult();
|
||||||
String[] split = dev.get(0).getId().split("_");
|
String[] split = dev.get(0).getId().split("_");
|
||||||
String devID = devIdMapComm.get(split[0]);
|
String devID = devIdMapComm.get(split[0]);
|
||||||
@@ -457,8 +454,6 @@ public class DetectionServiceImpl {
|
|||||||
result.setDataType(sourceIssue.getDataType());
|
result.setDataType(sourceIssue.getDataType());
|
||||||
List<PqErrSysDtls> pqErrSysDtls = new ArrayList<>();
|
List<PqErrSysDtls> pqErrSysDtls = new ArrayList<>();
|
||||||
Integer isQualified = 4;
|
Integer isQualified = 4;
|
||||||
if (CollUtil.isNotEmpty(errDtlsCheckData)) {
|
|
||||||
List<ErrDtlsCheckDataVO> dtlsCheckData = errDtlsCheckData.stream().filter(x -> x.getValueTypeCode().equals(s.split("\\$")[1])).collect(Collectors.toList());
|
|
||||||
if (CollUtil.isNotEmpty(dtlsCheckData)) {
|
if (CollUtil.isNotEmpty(dtlsCheckData)) {
|
||||||
result.setAdType(dtlsCheckData.get(0).getValueType());
|
result.setAdType(dtlsCheckData.get(0).getValueType());
|
||||||
isQualified = dtlsCheckData.get(0).getIsQualified();
|
isQualified = dtlsCheckData.get(0).getIsQualified();
|
||||||
@@ -466,6 +461,7 @@ public class DetectionServiceImpl {
|
|||||||
pqErrSysDtls = dtlsCheckData.get(0).getErrSysDtls();
|
pqErrSysDtls = dtlsCheckData.get(0).getErrSysDtls();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
result.setResultFlag(isQualified);
|
||||||
if (map.containsKey(TYPE_T)) {
|
if (map.containsKey(TYPE_T)) {
|
||||||
List<ErrDtlsCheckDataVO> checkDataT = dtlsCheckData.stream().filter(x -> TYPE_T.equals(x.getPhase())).collect(Collectors.toList());
|
List<ErrDtlsCheckDataVO> checkDataT = dtlsCheckData.stream().filter(x -> TYPE_T.equals(x.getPhase())).collect(Collectors.toList());
|
||||||
if (CollUtil.isNotEmpty(checkDataT)) {
|
if (CollUtil.isNotEmpty(checkDataT)) {
|
||||||
@@ -487,6 +483,19 @@ public class DetectionServiceImpl {
|
|||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
if (CollUtil.isNotEmpty(checkData)) {
|
if (CollUtil.isNotEmpty(checkData)) {
|
||||||
List<Double> phaseValue = map.get(phase);
|
List<Double> phaseValue = map.get(phase);
|
||||||
|
if (PowerIndexEnum.ANGLE.getKey().equals(type)) {
|
||||||
|
phaseValue = phaseValue.stream().map(x -> {
|
||||||
|
// 原始误差值
|
||||||
|
double originDiff = x - checkData.get(0).getValue();
|
||||||
|
// 转换误差值
|
||||||
|
double translateDiff = Math.abs(originDiff) - 360;
|
||||||
|
if (Math.abs(translateDiff) <= 10) {
|
||||||
|
return Math.abs(x);
|
||||||
|
} else {
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
}).collect(Collectors.toList());
|
||||||
|
}
|
||||||
// 注意:如果map中不存在该phase的键,phaseValue可能为null,需确保map包含该键
|
// 注意:如果map中不存在该phase的键,phaseValue可能为null,需确保map包含该键
|
||||||
DetectionData detectionData = rangeComparisonList(phaseValue, isQualified, pqErrSysDtls, fData, checkData.get(0).getValue(), dataRule, scale);
|
DetectionData detectionData = rangeComparisonList(phaseValue, isQualified, pqErrSysDtls, fData, checkData.get(0).getValue(), dataRule, scale);
|
||||||
resultFlag.add(detectionData);
|
resultFlag.add(detectionData);
|
||||||
@@ -503,7 +512,6 @@ public class DetectionServiceImpl {
|
|||||||
}
|
}
|
||||||
info.add(result);
|
info.add(result);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if (CollUtil.isNotEmpty(info)) {
|
if (CollUtil.isNotEmpty(info)) {
|
||||||
detectionDataDealService.acceptNonHarmonicResult(info, code);
|
detectionDataDealService.acceptNonHarmonicResult(info, code);
|
||||||
List<Integer> resultFlag = info.stream().map(SimAndDigNonHarmonicResult::getResultFlag).distinct().collect(Collectors.toList());
|
List<Integer> resultFlag = info.stream().map(SimAndDigNonHarmonicResult::getResultFlag).distinct().collect(Collectors.toList());
|
||||||
@@ -530,11 +538,15 @@ public class DetectionServiceImpl {
|
|||||||
SourceIssue sourceIssue,
|
SourceIssue sourceIssue,
|
||||||
DictDataEnum dataRule,
|
DictDataEnum dataRule,
|
||||||
Integer num, Integer scale) {
|
Integer num, Integer scale) {
|
||||||
Double fData = 1.0;
|
Double fDataA = 1.0;
|
||||||
|
Double fDataB = 1.0;
|
||||||
|
Double fDataC = 1.0;
|
||||||
String fundCode = "";
|
String fundCode = "";
|
||||||
String harmCode = "";
|
String harmCode = "";
|
||||||
if (U.equals(type)) {
|
if (U.equals(type)) {
|
||||||
fData = sourceIssue.getFUn();
|
fDataA = sourceIssue.getChannelList().stream().filter(x -> x.getChannelType().contains("Ua")).findFirst().get().getFAmp();
|
||||||
|
fDataB = sourceIssue.getChannelList().stream().filter(x -> x.getChannelType().contains("Ub")).findFirst().get().getFAmp();
|
||||||
|
fDataC = sourceIssue.getChannelList().stream().filter(x -> x.getChannelType().contains("Uc")).findFirst().get().getFAmp();
|
||||||
fundCode = DetectionCodeEnum.U1.getCode();
|
fundCode = DetectionCodeEnum.U1.getCode();
|
||||||
if (num == 1) {
|
if (num == 1) {
|
||||||
harmCode = DetectionCodeEnum.SV_1_49.getCode();
|
harmCode = DetectionCodeEnum.SV_1_49.getCode();
|
||||||
@@ -543,7 +555,9 @@ public class DetectionServiceImpl {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (I.equals(type)) {
|
if (I.equals(type)) {
|
||||||
fData = sourceIssue.getFIn();
|
fDataA = sourceIssue.getChannelList().stream().filter(x -> x.getChannelType().contains("Ia")).findFirst().get().getFAmp();
|
||||||
|
fDataB = sourceIssue.getChannelList().stream().filter(x -> x.getChannelType().contains("Ib")).findFirst().get().getFAmp();
|
||||||
|
fDataC = sourceIssue.getChannelList().stream().filter(x -> x.getChannelType().contains("Ic")).findFirst().get().getFAmp();
|
||||||
fundCode = DetectionCodeEnum.I1.getCode();
|
fundCode = DetectionCodeEnum.I1.getCode();
|
||||||
if (num == 1) {
|
if (num == 1) {
|
||||||
harmCode = DetectionCodeEnum.SI_1_49.getCode();
|
harmCode = DetectionCodeEnum.SI_1_49.getCode();
|
||||||
@@ -552,7 +566,9 @@ public class DetectionServiceImpl {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (HP.equals(type)) {
|
if (HP.equals(type)) {
|
||||||
fData = (sourceIssue.getFIn() * sourceIssue.getFUn()) * 0.01;
|
fDataA = (sourceIssue.getFIn() * sourceIssue.getFUn()) * 0.01;
|
||||||
|
fDataB = (sourceIssue.getFIn() * sourceIssue.getFUn()) * 0.01;
|
||||||
|
fDataC = (sourceIssue.getFIn() * sourceIssue.getFUn()) * 0.01;
|
||||||
harmCode = DetectionCodeEnum.P2_50.getCode();
|
harmCode = DetectionCodeEnum.P2_50.getCode();
|
||||||
}
|
}
|
||||||
// if (P.equals(type)) {
|
// if (P.equals(type)) {
|
||||||
@@ -578,9 +594,9 @@ public class DetectionServiceImpl {
|
|||||||
pqErrSysDtls = adDtlsCheckData.get(0).getErrSysDtls();
|
pqErrSysDtls = adDtlsCheckData.get(0).getErrSysDtls();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
List<DetectionData> integerBooleanA = harmRangeComparison(isQualified, pqErrSysDtls, type, TYPE_A, sourceIssue, dataRule, devMap.get(TYPE_A), fData, num, scale);
|
List<DetectionData> integerBooleanA = harmRangeComparison(isQualified, pqErrSysDtls, type, TYPE_A, sourceIssue, dataRule, devMap.get(TYPE_A), fDataA, num, scale);
|
||||||
List<DetectionData> integerBooleanB = harmRangeComparison(isQualified, pqErrSysDtls, type, TYPE_B, sourceIssue, dataRule, devMap.get(TYPE_B), fData, num, scale);
|
List<DetectionData> integerBooleanB = harmRangeComparison(isQualified, pqErrSysDtls, type, TYPE_B, sourceIssue, dataRule, devMap.get(TYPE_B), fDataB, num, scale);
|
||||||
List<DetectionData> integerBooleanC = harmRangeComparison(isQualified, pqErrSysDtls, type, TYPE_C, sourceIssue, dataRule, devMap.get(TYPE_C), fData, num, scale);
|
List<DetectionData> integerBooleanC = harmRangeComparison(isQualified, pqErrSysDtls, type, TYPE_C, sourceIssue, dataRule, devMap.get(TYPE_C), fDataC, num, scale);
|
||||||
harmonicResult.setDataType(sourceIssue.getDataType());
|
harmonicResult.setDataType(sourceIssue.getDataType());
|
||||||
reflectHarmonic(false, "a", integerBooleanA, harmonicResult, num);
|
reflectHarmonic(false, "a", integerBooleanA, harmonicResult, num);
|
||||||
reflectHarmonic(false, "b", integerBooleanB, harmonicResult, num);
|
reflectHarmonic(false, "b", integerBooleanB, harmonicResult, num);
|
||||||
@@ -605,19 +621,27 @@ public class DetectionServiceImpl {
|
|||||||
* @param dataRule 数据处理原则
|
* @param dataRule 数据处理原则
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public SimAndDigNonHarmonicResult isUnBalanceOrFlickerQualified(List<DevData> dev,
|
public Integer isUnBalanceOrFlickerQualified(List<DevData> dev,
|
||||||
Map<String, String> devIdMapComm,
|
Map<String, String> devIdMapComm,
|
||||||
List<ErrDtlsCheckDataVO> errDtlsCheckData,
|
List<ErrDtlsCheckDataVO> errDtlsCheckData,
|
||||||
String type,
|
String type,
|
||||||
SourceIssue sourceIssue,
|
SourceIssue sourceIssue,
|
||||||
DictDataEnum dataRule,
|
DictDataEnum dataRule,
|
||||||
String code, Integer scale) {
|
String code, Integer scale) {
|
||||||
|
List<SimAndDigNonHarmonicResult> info = new ArrayList<>();
|
||||||
List<PqScriptCheckData> checkData = pqScriptCheckDataService.list(new MPJLambdaWrapper<PqScriptCheckData>()
|
List<PqScriptCheckData> checkData = pqScriptCheckDataService.list(new MPJLambdaWrapper<PqScriptCheckData>()
|
||||||
.eq(PqScriptCheckData::getScriptIndex, sourceIssue.getIndex())
|
.eq(PqScriptCheckData::getScriptIndex, sourceIssue.getIndex())
|
||||||
.eq(PqScriptCheckData::getScriptId, sourceIssue.getScriptId())
|
.eq(PqScriptCheckData::getScriptId, sourceIssue.getScriptId())
|
||||||
);
|
);
|
||||||
Map<String, List<Double>> map = devListMap(dev, dataRule, code);
|
List<String> devValueTypeList = sourceIssue.getDevValueTypeList();
|
||||||
|
for (String s : devValueTypeList) {
|
||||||
|
String[] splitArr = s.split("\\$");
|
||||||
|
Map<String, List<Double>> map = devListMap(dev, dataRule, splitArr[1]);
|
||||||
if (CollUtil.isNotEmpty(map)) {
|
if (CollUtil.isNotEmpty(map)) {
|
||||||
|
List<ErrDtlsCheckDataVO> dtlsCheckData = null;
|
||||||
|
if (CollUtil.isNotEmpty(errDtlsCheckData)) {
|
||||||
|
dtlsCheckData = errDtlsCheckData.stream().filter(x -> x.getValueTypeCode().equals(s.split("\\$")[1])).collect(Collectors.toList());
|
||||||
|
}
|
||||||
Double fData = 1.0;
|
Double fData = 1.0;
|
||||||
if (U.equals(type)) {
|
if (U.equals(type)) {
|
||||||
fData = sourceIssue.getFUn();
|
fData = sourceIssue.getFUn();
|
||||||
@@ -631,38 +655,60 @@ public class DetectionServiceImpl {
|
|||||||
result.setDevMonitorId(devID + "_" + split[1]);
|
result.setDevMonitorId(devID + "_" + split[1]);
|
||||||
result.setScriptId(sourceIssue.getScriptId());
|
result.setScriptId(sourceIssue.getScriptId());
|
||||||
result.setSort(sourceIssue.getIndex());
|
result.setSort(sourceIssue.getIndex());
|
||||||
|
result.setDataType(sourceIssue.getDataType());
|
||||||
List<PqErrSysDtls> pqErrSysDtls = new ArrayList<>();
|
List<PqErrSysDtls> pqErrSysDtls = new ArrayList<>();
|
||||||
Integer isQualified = 4;
|
Integer isQualified = 4;
|
||||||
if (CollUtil.isNotEmpty(errDtlsCheckData)) {
|
if (CollUtil.isNotEmpty(dtlsCheckData)) {
|
||||||
result.setAdType(errDtlsCheckData.get(0).getValueType());
|
result.setAdType(dtlsCheckData.get(0).getValueType());
|
||||||
isQualified = errDtlsCheckData.get(0).getIsQualified();
|
isQualified = dtlsCheckData.get(0).getIsQualified();
|
||||||
if (CollUtil.isNotEmpty(errDtlsCheckData.get(0).getErrSysDtls())) {
|
if (CollUtil.isNotEmpty(dtlsCheckData.get(0).getErrSysDtls())) {
|
||||||
pqErrSysDtls = errDtlsCheckData.get(0).getErrSysDtls();
|
pqErrSysDtls = dtlsCheckData.get(0).getErrSysDtls();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
result.setDataType(sourceIssue.getDataType());
|
result.setResultFlag(isQualified);
|
||||||
if (StrUtil.isBlank(type)) {
|
// 闪变
|
||||||
|
if (DetectionCodeEnum.PST.getCode().equals(splitArr[1]) || DetectionCodeEnum.SeqV.getCode().equals(splitArr[1]) || DetectionCodeEnum.SeqA.getCode().equals(splitArr[1])) {
|
||||||
|
|
||||||
//取出源所对应的相别信息
|
//取出源所对应的相别信息
|
||||||
List<PqScriptCheckData> channelTypeAList = checkData.stream()
|
List<PqScriptCheckData> channelTypeAList = checkData.stream()
|
||||||
.filter(x -> TYPE_A.equals(x.getPhase()))
|
.filter(x -> TYPE_A.equals(x.getPhase()))
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
DetectionData a = rangeComparisonList(map.get(TYPE_A), isQualified, pqErrSysDtls, fData, channelTypeAList.get(0).getValue(), dataRule, scale);
|
Double channelDataA = channelTypeAList.get(0).getValue();
|
||||||
|
if (DetectionCodeEnum.SeqV.getCode().equals(splitArr[1]) || DetectionCodeEnum.SeqA.getCode().equals(splitArr[1])) {
|
||||||
|
channelDataA = BigDecimal.valueOf(channelDataA / 100 * fData)
|
||||||
|
.setScale(scale, RoundingMode.HALF_UP)
|
||||||
|
.doubleValue();
|
||||||
|
}
|
||||||
|
DetectionData a = rangeComparisonList(map.get(TYPE_A), isQualified, pqErrSysDtls, fData, channelDataA, dataRule, scale);
|
||||||
result.setAValue(JSON.toJSONString(a));
|
result.setAValue(JSON.toJSONString(a));
|
||||||
|
|
||||||
List<PqScriptCheckData> channelTypeBList = checkData.stream()
|
List<PqScriptCheckData> channelTypeBList = checkData.stream()
|
||||||
.filter(x -> TYPE_B.equals(x.getPhase()))
|
.filter(x -> TYPE_B.equals(x.getPhase()))
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
DetectionData b = rangeComparisonList(map.get(TYPE_B), isQualified, pqErrSysDtls, fData, channelTypeBList.get(0).getValue(), dataRule, scale);
|
Double channelDataB = channelTypeBList.get(0).getValue();
|
||||||
|
if (DetectionCodeEnum.SeqV.getCode().equals(splitArr[1]) || DetectionCodeEnum.SeqA.getCode().equals(splitArr[1])) {
|
||||||
|
channelDataB = BigDecimal.valueOf(channelDataB / 100 * fData)
|
||||||
|
.setScale(scale, RoundingMode.HALF_UP)
|
||||||
|
.doubleValue();
|
||||||
|
}
|
||||||
|
DetectionData b = rangeComparisonList(map.get(TYPE_B), isQualified, pqErrSysDtls, fData, channelDataB, dataRule, scale);
|
||||||
result.setBValue(JSON.toJSONString(b));
|
result.setBValue(JSON.toJSONString(b));
|
||||||
|
|
||||||
List<PqScriptCheckData> channelTypeCList = checkData.stream()
|
List<PqScriptCheckData> channelTypeCList = checkData.stream()
|
||||||
.filter(x -> TYPE_C.equals(x.getPhase()))
|
.filter(x -> TYPE_C.equals(x.getPhase()))
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
DetectionData c = rangeComparisonList(map.get(TYPE_C), isQualified, pqErrSysDtls, fData, channelTypeCList.get(0).getValue(), dataRule, scale);
|
Double channelDataC = channelTypeCList.get(0).getValue();
|
||||||
|
if (DetectionCodeEnum.SeqV.getCode().equals(splitArr[1]) || DetectionCodeEnum.SeqA.getCode().equals(splitArr[1])) {
|
||||||
|
channelDataC = BigDecimal.valueOf(channelDataC / 100 * fData)
|
||||||
|
.setScale(scale, RoundingMode.HALF_UP)
|
||||||
|
.doubleValue();
|
||||||
|
}
|
||||||
|
DetectionData c = rangeComparisonList(map.get(TYPE_C), isQualified, pqErrSysDtls, fData, channelDataC, dataRule, scale);
|
||||||
result.setCValue(JSON.toJSONString(c));
|
result.setCValue(JSON.toJSONString(c));
|
||||||
|
|
||||||
result.setResultFlag(setResultFlag(Arrays.asList(a, b, c)));
|
result.setResultFlag(setResultFlag(Arrays.asList(a, b, c)));
|
||||||
} else {
|
} else {
|
||||||
|
// 三项不平衡
|
||||||
List<PqScriptCheckData> channelTypeBList = checkData.stream()
|
List<PqScriptCheckData> channelTypeBList = checkData.stream()
|
||||||
.filter(x -> TYPE_T.equals(x.getPhase()))
|
.filter(x -> TYPE_T.equals(x.getPhase()))
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
@@ -670,9 +716,15 @@ public class DetectionServiceImpl {
|
|||||||
result.setTValue(JSON.toJSONString(t));
|
result.setTValue(JSON.toJSONString(t));
|
||||||
result.setResultFlag(setResultFlag(Arrays.asList(t)));
|
result.setResultFlag(setResultFlag(Arrays.asList(t)));
|
||||||
}
|
}
|
||||||
return result;
|
info.add(result);
|
||||||
}
|
}
|
||||||
return null;
|
}
|
||||||
|
if (CollUtil.isNotEmpty(info)) {
|
||||||
|
detectionDataDealService.acceptNonHarmonicResult(info, code);
|
||||||
|
List<Integer> resultFlag = info.stream().map(SimAndDigNonHarmonicResult::getResultFlag).distinct().collect(Collectors.toList());
|
||||||
|
return StorageUtil.getInteger(resultFlag);
|
||||||
|
}
|
||||||
|
return 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,218 @@
|
|||||||
|
package com.njcn.gather.detection.service.impl;
|
||||||
|
|
||||||
|
import cn.hutool.core.collection.CollUtil;
|
||||||
|
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
|
||||||
|
import com.njcn.common.pojo.exception.BusinessException;
|
||||||
|
import com.njcn.gather.detection.handler.SocketDevResponseService;
|
||||||
|
import com.njcn.gather.detection.pojo.param.FormalProgressParam;
|
||||||
|
import com.njcn.gather.detection.pojo.param.PreDetectionParam;
|
||||||
|
import com.njcn.gather.detection.pojo.vo.FormalProgressVO;
|
||||||
|
import com.njcn.gather.detection.service.FormalProgressService;
|
||||||
|
import com.njcn.gather.detection.util.socket.websocket.WebServiceManager;
|
||||||
|
import com.njcn.gather.device.pojo.enums.CommonEnum;
|
||||||
|
import com.njcn.gather.device.pojo.vo.PreDetection;
|
||||||
|
import com.njcn.gather.device.service.IPqDevService;
|
||||||
|
import com.njcn.gather.script.pojo.param.PqScriptIssueParam;
|
||||||
|
import com.njcn.gather.script.pojo.po.SourceIssue;
|
||||||
|
import com.njcn.gather.script.service.IPqScriptDtlsService;
|
||||||
|
import com.njcn.gather.storage.pojo.po.SimAndDigBaseResult;
|
||||||
|
import com.njcn.gather.storage.service.SimAndDigHarmonicService;
|
||||||
|
import com.njcn.gather.storage.service.SimAndDigNonHarmonicService;
|
||||||
|
import com.njcn.gather.system.dictionary.pojo.po.DictTree;
|
||||||
|
import com.njcn.gather.system.dictionary.service.IDictTreeService;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@Slf4j
|
||||||
|
public class FormalProgressServiceImpl implements FormalProgressService {
|
||||||
|
|
||||||
|
private static final long RESUME_RELEASE_DELAY_MILLIS = 300L;
|
||||||
|
|
||||||
|
private final IPqDevService pqDevService;
|
||||||
|
private final IPqScriptDtlsService pqScriptDtlsService;
|
||||||
|
private final IDictTreeService dictTreeService;
|
||||||
|
private final SimAndDigHarmonicService harmonicService;
|
||||||
|
private final SimAndDigNonHarmonicService nonHarmonicService;
|
||||||
|
private final SocketDevResponseService socketDevResponseService;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FormalProgressVO restoreAndRelease(FormalProgressParam param) {
|
||||||
|
PreDetectionParam preParam = WebServiceManager.getPreDetectionParam(param.getUserPageId());
|
||||||
|
if (preParam == null) {
|
||||||
|
throw new BusinessException(CommonResponseEnum.FAIL, "未找到续检上下文,请重新开始检测");
|
||||||
|
}
|
||||||
|
FormalProgressVO vo = buildSnapshot(preParam, param.getDevIds());
|
||||||
|
releaseResumeAfterSnapshotApplied(preParam, vo.getNextSort());
|
||||||
|
return vo;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Integer calculateNextSort(PreDetectionParam param) {
|
||||||
|
return buildSnapshot(param, param.getDevIds()).getNextSort();
|
||||||
|
}
|
||||||
|
|
||||||
|
private FormalProgressVO buildSnapshot(PreDetectionParam param, List<String> devIds) {
|
||||||
|
FormalProgressVO vo = new FormalProgressVO();
|
||||||
|
vo.setFormalCheckTime(pqDevService.getMinFormalCheckTime(devIds));
|
||||||
|
|
||||||
|
Map<String, Integer> harmonicMax = harmonicService.maxSortByDevIds(param.getCode(), param.getScriptId(), devIds);
|
||||||
|
Map<String, Integer> nonHarmonicMax = nonHarmonicService.maxSortByDevIds(param.getCode(), param.getScriptId(), devIds);
|
||||||
|
|
||||||
|
Integer minMaxSort = devIds.stream()
|
||||||
|
.map(devId -> Math.max(harmonicMax.getOrDefault(devId, -1), nonHarmonicMax.getOrDefault(devId, -1)))
|
||||||
|
.min(Integer::compareTo)
|
||||||
|
.orElse(-1);
|
||||||
|
vo.setMinMaxSort(minMaxSort);
|
||||||
|
|
||||||
|
List<SourceIssue> allIssues = buildAllFormalIssues(param);
|
||||||
|
List<Integer> allSorts = allIssues.stream()
|
||||||
|
.map(SourceIssue::getIndex)
|
||||||
|
.filter(sort -> sort != null && sort >= 0)
|
||||||
|
.sorted()
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
Integer nextSort = allSorts.stream()
|
||||||
|
.filter(sort -> sort > minMaxSort)
|
||||||
|
.findFirst()
|
||||||
|
.orElse(null);
|
||||||
|
vo.setNextSort(nextSort);
|
||||||
|
|
||||||
|
Set<String> completedTypes = completedBigTypes(allIssues, minMaxSort);
|
||||||
|
long totalBigTypes = allIssues.stream().map(SourceIssue::getType).distinct().count();
|
||||||
|
vo.setProcess(totalBigTypes == 0 ? 0D : completedTypes.size() * 100D / totalBigTypes);
|
||||||
|
vo.setTableRows(buildRows(param, devIds, allIssues, completedTypes));
|
||||||
|
return vo;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void releaseResumeAfterSnapshotApplied(PreDetectionParam preParam, Integer nextSort) {
|
||||||
|
CompletableFuture.runAsync(() -> {
|
||||||
|
try {
|
||||||
|
Thread.sleep(RESUME_RELEASE_DELAY_MILLIS);
|
||||||
|
socketDevResponseService.startFormalAfterProgressRestore(preParam, nextSort);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
Thread.currentThread().interrupt();
|
||||||
|
log.warn("正式检测续检放行等待被中断", e);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("正式检测续检放行失败", e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<SourceIssue> buildAllFormalIssues(PreDetectionParam param) {
|
||||||
|
PqScriptIssueParam issueParam = new PqScriptIssueParam();
|
||||||
|
issueParam.setPlanId(param.getPlanId());
|
||||||
|
issueParam.setSourceId(param.getSourceName());
|
||||||
|
issueParam.setDevIds(param.getDevIds());
|
||||||
|
issueParam.setScriptId(param.getScriptId());
|
||||||
|
issueParam.setIsPhaseSequence(CommonEnum.FORMAL_TEST.getValue());
|
||||||
|
return pqScriptDtlsService.listSourceIssue(issueParam)
|
||||||
|
.stream()
|
||||||
|
.sorted(Comparator.comparing(SourceIssue::getIndex))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
private Set<String> completedBigTypes(List<SourceIssue> issues, Integer minMaxSort) {
|
||||||
|
return issues.stream()
|
||||||
|
.collect(Collectors.groupingBy(SourceIssue::getType, LinkedHashMap::new, Collectors.toList()))
|
||||||
|
.entrySet()
|
||||||
|
.stream()
|
||||||
|
.filter(entry -> entry.getValue().stream().allMatch(issue -> issue.getIndex() <= minMaxSort))
|
||||||
|
.map(Map.Entry::getKey)
|
||||||
|
.collect(Collectors.toCollection(LinkedHashSet::new));
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<FormalProgressVO.TableRow> buildRows(PreDetectionParam param,
|
||||||
|
List<String> devIds,
|
||||||
|
List<SourceIssue> issues,
|
||||||
|
Set<String> completedTypes) {
|
||||||
|
Map<String, List<SourceIssue>> byType = issues.stream()
|
||||||
|
.collect(Collectors.groupingBy(SourceIssue::getType, LinkedHashMap::new, Collectors.toList()));
|
||||||
|
if (byType.isEmpty()) {
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
Map<String, DictTree> dictTreeByCode = dictTreeService.lambdaQuery()
|
||||||
|
.in(DictTree::getCode, byType.keySet())
|
||||||
|
.list()
|
||||||
|
.stream()
|
||||||
|
.collect(Collectors.toMap(DictTree::getCode, dictTree -> dictTree, (left, right) -> left));
|
||||||
|
return byType.entrySet().stream().map(entry -> {
|
||||||
|
List<SourceIssue> typeIssues = entry.getValue();
|
||||||
|
boolean completed = completedTypes.contains(entry.getKey());
|
||||||
|
DictTree dictTree = dictTreeByCode.get(entry.getKey());
|
||||||
|
FormalProgressVO.TableRow row = new FormalProgressVO.TableRow();
|
||||||
|
row.setScriptCode(entry.getKey());
|
||||||
|
row.setScriptName(dictTree.getName());
|
||||||
|
row.setScriptType(dictTree.getId());
|
||||||
|
row.setDevices(completed
|
||||||
|
? buildCompletedDeviceResults(param, devIds, typeIssues)
|
||||||
|
: buildUnknownDeviceResults(devIds));
|
||||||
|
return row;
|
||||||
|
}).collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<FormalProgressVO.DeviceResult> buildUnknownDeviceResults(List<String> devIds) {
|
||||||
|
return pqDevService.getDevInfo(devIds).stream().map(dev -> {
|
||||||
|
FormalProgressVO.DeviceResult item = new FormalProgressVO.DeviceResult();
|
||||||
|
item.setDeviceId(dev.getDevId());
|
||||||
|
item.setDeviceName(dev.getDevName());
|
||||||
|
item.setChnResult(dev.getMonitorList().stream().map(monitor -> -1).collect(Collectors.toList()));
|
||||||
|
return item;
|
||||||
|
}).collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<FormalProgressVO.DeviceResult> buildCompletedDeviceResults(PreDetectionParam param,
|
||||||
|
List<String> devIds,
|
||||||
|
List<SourceIssue> typeIssues) {
|
||||||
|
List<Integer> sorts = typeIssues.stream().map(SourceIssue::getIndex).distinct().collect(Collectors.toList());
|
||||||
|
List<SimAndDigBaseResult> rows = new ArrayList<>();
|
||||||
|
rows.addAll(harmonicService.listByDevIdsAndSorts(param.getCode(), param.getScriptId(), devIds, sorts));
|
||||||
|
rows.addAll(nonHarmonicService.listByDevIdsAndSorts(param.getCode(), param.getScriptId(), devIds, sorts));
|
||||||
|
|
||||||
|
Map<String, List<Integer>> flagMap = rows.stream()
|
||||||
|
.filter(row -> row.getResultFlag() != null)
|
||||||
|
.collect(Collectors.groupingBy(SimAndDigBaseResult::getDevMonitorId,
|
||||||
|
Collectors.mapping(SimAndDigBaseResult::getResultFlag, Collectors.toList())));
|
||||||
|
|
||||||
|
return pqDevService.getDevInfo(devIds).stream().map(dev -> {
|
||||||
|
FormalProgressVO.DeviceResult item = new FormalProgressVO.DeviceResult();
|
||||||
|
item.setDeviceId(dev.getDevId());
|
||||||
|
item.setDeviceName(dev.getDevName());
|
||||||
|
item.setChnResult(dev.getMonitorList().stream()
|
||||||
|
.map(monitor -> mergeResultFlags(resolveResultFlags(flagMap, dev, monitor)))
|
||||||
|
.collect(Collectors.toList()));
|
||||||
|
return item;
|
||||||
|
}).collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<Integer> resolveResultFlags(Map<String, List<Integer>> flagMap, PreDetection dev, PreDetection.MonitorListDTO monitor) {
|
||||||
|
List<Integer> flags = new ArrayList<>();
|
||||||
|
List<Integer> byDevLine = flagMap.get(dev.getDevId() + "_" + monitor.getLine());
|
||||||
|
if (CollUtil.isNotEmpty(byDevLine)) {
|
||||||
|
flags.addAll(byDevLine);
|
||||||
|
}
|
||||||
|
List<Integer> byLineId = flagMap.get(monitor.getLineId());
|
||||||
|
if (CollUtil.isNotEmpty(byLineId)) {
|
||||||
|
flags.addAll(byLineId);
|
||||||
|
}
|
||||||
|
return flags;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Integer mergeResultFlags(List<Integer> flags) {
|
||||||
|
if (CollUtil.isEmpty(flags)) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
List<Integer> effective = flags.stream()
|
||||||
|
.filter(flag -> flag != null && flag != 4 && flag != 5)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
if (CollUtil.isNotEmpty(effective)) {
|
||||||
|
return effective.stream().max(Integer::compareTo).orElse(1);
|
||||||
|
}
|
||||||
|
return flags.get(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,8 +3,11 @@ package com.njcn.gather.detection.service.impl;
|
|||||||
|
|
||||||
import cn.hutool.core.collection.CollUtil;
|
import cn.hutool.core.collection.CollUtil;
|
||||||
import cn.hutool.core.util.ObjectUtil;
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||||
|
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
|
||||||
import com.njcn.common.pojo.exception.BusinessException;
|
import com.njcn.common.pojo.exception.BusinessException;
|
||||||
import com.njcn.gather.detection.handler.SocketContrastResponseService;
|
import com.njcn.gather.detection.handler.SocketContrastResponseService;
|
||||||
import com.njcn.gather.detection.handler.SocketDevResponseService;
|
import com.njcn.gather.detection.handler.SocketDevResponseService;
|
||||||
@@ -13,9 +16,12 @@ import com.njcn.gather.detection.pojo.constant.DetectionCommunicateConstant;
|
|||||||
import com.njcn.gather.detection.pojo.enums.DetectionResponseEnum;
|
import com.njcn.gather.detection.pojo.enums.DetectionResponseEnum;
|
||||||
import com.njcn.gather.detection.pojo.enums.SourceOperateCodeEnum;
|
import com.njcn.gather.detection.pojo.enums.SourceOperateCodeEnum;
|
||||||
import com.njcn.gather.detection.pojo.param.ContrastDetectionParam;
|
import com.njcn.gather.detection.pojo.param.ContrastDetectionParam;
|
||||||
|
import com.njcn.gather.detection.pojo.param.FormalProgressParam;
|
||||||
import com.njcn.gather.detection.pojo.param.PreDetectionParam;
|
import com.njcn.gather.detection.pojo.param.PreDetectionParam;
|
||||||
import com.njcn.gather.detection.pojo.param.SimulateDetectionParam;
|
import com.njcn.gather.detection.pojo.param.SimulateDetectionParam;
|
||||||
|
import com.njcn.gather.detection.pojo.vo.FormalProgressVO;
|
||||||
import com.njcn.gather.detection.pojo.vo.SocketMsg;
|
import com.njcn.gather.detection.pojo.vo.SocketMsg;
|
||||||
|
import com.njcn.gather.detection.service.FormalProgressService;
|
||||||
import com.njcn.gather.detection.service.PreDetectionService;
|
import com.njcn.gather.detection.service.PreDetectionService;
|
||||||
import com.njcn.gather.detection.util.business.DetectionCommunicateUtil;
|
import com.njcn.gather.detection.util.business.DetectionCommunicateUtil;
|
||||||
import com.njcn.gather.detection.util.socket.CnSocketUtil;
|
import com.njcn.gather.detection.util.socket.CnSocketUtil;
|
||||||
@@ -24,15 +30,20 @@ import com.njcn.gather.detection.util.socket.SocketManager;
|
|||||||
import com.njcn.gather.detection.util.socket.XiNumberManager;
|
import com.njcn.gather.detection.util.socket.XiNumberManager;
|
||||||
import com.njcn.gather.detection.util.socket.cilent.NettyContrastClientHandler;
|
import com.njcn.gather.detection.util.socket.cilent.NettyContrastClientHandler;
|
||||||
import com.njcn.gather.detection.util.socket.websocket.WebServiceManager;
|
import com.njcn.gather.detection.util.socket.websocket.WebServiceManager;
|
||||||
|
import com.njcn.gather.device.pojo.enums.CheckResultEnum;
|
||||||
|
import com.njcn.gather.device.pojo.enums.CheckStateEnum;
|
||||||
|
import com.njcn.gather.device.pojo.enums.CommonEnum;
|
||||||
import com.njcn.gather.device.pojo.po.PqDev;
|
import com.njcn.gather.device.pojo.po.PqDev;
|
||||||
|
import com.njcn.gather.device.pojo.po.PqDevSub;
|
||||||
import com.njcn.gather.device.pojo.vo.PreDetection;
|
import com.njcn.gather.device.pojo.vo.PreDetection;
|
||||||
import com.njcn.gather.device.service.IPqDevService;
|
import com.njcn.gather.device.service.IPqDevService;
|
||||||
|
import com.njcn.gather.device.service.IPqDevSubService;
|
||||||
import com.njcn.gather.plan.pojo.enums.DataSourceEnum;
|
import com.njcn.gather.plan.pojo.enums.DataSourceEnum;
|
||||||
import com.njcn.gather.plan.pojo.po.AdPlan;
|
import com.njcn.gather.plan.pojo.po.AdPlan;
|
||||||
import com.njcn.gather.plan.pojo.po.AdPlanSource;
|
import com.njcn.gather.plan.pojo.po.AdPlanSource;
|
||||||
import com.njcn.gather.plan.service.IAdPlanService;
|
import com.njcn.gather.plan.service.IAdPlanService;
|
||||||
import com.njcn.gather.plan.service.IAdPlanSourceService;
|
import com.njcn.gather.plan.service.IAdPlanSourceService;
|
||||||
import com.njcn.gather.result.pojo.enums.ResultUnitEnum;
|
import com.njcn.gather.report.pojo.enums.PowerIndexEnum;
|
||||||
import com.njcn.gather.script.pojo.param.PqScriptCheckDataParam;
|
import com.njcn.gather.script.pojo.param.PqScriptCheckDataParam;
|
||||||
import com.njcn.gather.script.pojo.param.PqScriptIssueParam;
|
import com.njcn.gather.script.pojo.param.PqScriptIssueParam;
|
||||||
import com.njcn.gather.script.pojo.po.SourceIssue;
|
import com.njcn.gather.script.pojo.po.SourceIssue;
|
||||||
@@ -40,7 +51,10 @@ import com.njcn.gather.script.service.IPqScriptCheckDataService;
|
|||||||
import com.njcn.gather.script.service.IPqScriptDtlsService;
|
import com.njcn.gather.script.service.IPqScriptDtlsService;
|
||||||
import com.njcn.gather.source.pojo.po.SourceInitialize;
|
import com.njcn.gather.source.pojo.po.SourceInitialize;
|
||||||
import com.njcn.gather.source.service.IPqSourceService;
|
import com.njcn.gather.source.service.IPqSourceService;
|
||||||
|
import com.njcn.gather.storage.service.SimAndDigHarmonicService;
|
||||||
|
import com.njcn.gather.storage.service.SimAndDigNonHarmonicService;
|
||||||
import com.njcn.gather.system.cfg.service.ISysTestConfigService;
|
import com.njcn.gather.system.cfg.service.ISysTestConfigService;
|
||||||
|
import com.njcn.gather.system.config.PathConfig;
|
||||||
import com.njcn.gather.system.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;
|
||||||
@@ -48,11 +62,11 @@ import com.njcn.web.utils.RequestUtil;
|
|||||||
import io.netty.channel.Channel;
|
import io.netty.channel.Channel;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import javax.servlet.ServletOutputStream;
|
import javax.servlet.ServletOutputStream;
|
||||||
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;
|
||||||
@@ -79,10 +93,15 @@ public class PreDetectionServiceImpl implements PreDetectionService {
|
|||||||
private final IPqScriptCheckDataService iPqScriptCheckDataService;
|
private final IPqScriptCheckDataService iPqScriptCheckDataService;
|
||||||
private final SocketManager socketManager;
|
private final SocketManager socketManager;
|
||||||
private final ISysTestConfigService sysTestConfigService;
|
private final ISysTestConfigService sysTestConfigService;
|
||||||
|
private final FormalProgressService formalProgressService;
|
||||||
|
private final IPqDevSubService pqDevSubService;
|
||||||
|
private final SimAndDigHarmonicService harmonicService;
|
||||||
|
private final SimAndDigNonHarmonicService nonHarmonicService;
|
||||||
|
|
||||||
|
|
||||||
@Value("${report.reportDir}")
|
// @Value("${report.reportDir}")
|
||||||
private String alignDataFilePath;
|
// private String alignDataFilePath;
|
||||||
|
private final PathConfig pathConfig;
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -99,6 +118,28 @@ public class PreDetectionServiceImpl implements PreDetectionService {
|
|||||||
param.setScriptId(plan.getScriptId());
|
param.setScriptId(plan.getScriptId());
|
||||||
param.setErrorSysId(plan.getErrorSysId());
|
param.setErrorSysId(plan.getErrorSysId());
|
||||||
param.setCode(String.valueOf(plan.getCode()));
|
param.setCode(String.valueOf(plan.getCode()));
|
||||||
|
if (param.isFormalTestSelected()) {
|
||||||
|
List<PqDevSub> devSubs = pqDevSubService.lambdaQuery()
|
||||||
|
.in(PqDevSub::getDevId, param.getDevIds())
|
||||||
|
.list();
|
||||||
|
boolean hasSaved = devSubs.stream().anyMatch(this::isSavedFormalProgress);
|
||||||
|
if (param.isResumeFormal() && !hasSaved) {
|
||||||
|
throw new BusinessException(CommonResponseEnum.FAIL, "未找到正式检测暂存进度");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (param.isFormalTestSelected() && !param.isResumeFormal()) {
|
||||||
|
FormalTestManager.resumeBaseFormalCheckTime = null;
|
||||||
|
FormalTestManager.resumeFormalStartTime = null;
|
||||||
|
FormalTestManager.resumeNextSort = null;
|
||||||
|
FormalTestManager.resumeFormalPending = false;
|
||||||
|
}
|
||||||
|
if (param.isFormalTestSelected() && param.isResumeFormal()) {
|
||||||
|
FormalTestManager.resumeBaseFormalCheckTime = iPqDevService.getMinFormalCheckTime(param.getDevIds());
|
||||||
|
pqDevSubService.lambdaUpdate()
|
||||||
|
.set(PqDevSub::getCheckState, CheckStateEnum.CHECKING.getValue())
|
||||||
|
.in(PqDevSub::getDevId, param.getDevIds())
|
||||||
|
.update();
|
||||||
|
}
|
||||||
if (ObjectUtil.isNotNull(plan)) {
|
if (ObjectUtil.isNotNull(plan)) {
|
||||||
String code = dictDataService.getDictDataById(plan.getPattern()).getCode();
|
String code = dictDataService.getDictDataById(plan.getPattern()).getCode();
|
||||||
DictDataEnum dictDataEnumByCode = DictDataEnum.getDictDataEnumByCode(code);
|
DictDataEnum dictDataEnumByCode = DictDataEnum.getDictDataEnumByCode(code);
|
||||||
@@ -135,6 +176,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);
|
||||||
@@ -181,6 +223,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);
|
||||||
@@ -218,6 +261,7 @@ public class PreDetectionServiceImpl implements PreDetectionService {
|
|||||||
private void sendYtxSocketSimulate(PreDetectionParam param) {
|
private void sendYtxSocketSimulate(PreDetectionParam param) {
|
||||||
SourceInitialize sourceParam = pqSourceService.getSourceInitializeParam(param.getSourceId());
|
SourceInitialize sourceParam = pqSourceService.getSourceInitializeParam(param.getSourceId());
|
||||||
param.setSourceId(sourceParam.getSourceId());
|
param.setSourceId(sourceParam.getSourceId());
|
||||||
|
param.setSourceName(sourceParam.getSourceId());
|
||||||
String loginName = RequestUtil.getLoginNameByToken();
|
String loginName = RequestUtil.getLoginNameByToken();
|
||||||
WebServiceManager.addPreDetectionParam(loginName, param);
|
WebServiceManager.addPreDetectionParam(loginName, param);
|
||||||
if (ObjectUtil.isNotNull(sourceParam)) {
|
if (ObjectUtil.isNotNull(sourceParam)) {
|
||||||
@@ -240,31 +284,254 @@ public class PreDetectionServiceImpl implements PreDetectionService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean restartTemTest(PreDetectionParam param) {
|
public boolean restartTemTest(PreDetectionParam param) {
|
||||||
|
PreDetectionParam runtimeParam = WebServiceManager.getPreDetectionParam(param.getUserPageId());
|
||||||
|
if (runtimeParam == null) {
|
||||||
|
if (StrUtil.isBlank(param.getSourceId()) || StrUtil.isBlank(param.getScriptId()) || StrUtil.isBlank(param.getCode())) {
|
||||||
|
throw new BusinessException(CommonResponseEnum.FAIL, "未找到暂停检测上下文,请重新开始检测");
|
||||||
|
}
|
||||||
|
runtimeParam = param;
|
||||||
|
}
|
||||||
FormalTestManager.stopFlag = false;
|
FormalTestManager.stopFlag = false;
|
||||||
socketDevResponseService.initRestart();
|
socketDevResponseService.initRestart();
|
||||||
List<SourceIssue> sourceIssueList = SocketManager.getSourceList();
|
List<SourceIssue> sourceIssueList = SocketManager.getSourceList();
|
||||||
|
if (StrUtil.isBlank(runtimeParam.getSourceName()) && StrUtil.isNotBlank(runtimeParam.getSourceId())) {
|
||||||
|
SourceInitialize sourceInitialize = pqSourceService.getSourceInitializeParam(runtimeParam.getSourceId());
|
||||||
|
if (sourceInitialize == null) {
|
||||||
|
throw new BusinessException(DetectionResponseEnum.SOURCE_INFO_NOT);
|
||||||
|
}
|
||||||
|
runtimeParam.setSourceName(sourceInitialize.getSourceId());
|
||||||
|
}
|
||||||
if (CollUtil.isNotEmpty(sourceIssueList)) {
|
if (CollUtil.isNotEmpty(sourceIssueList)) {
|
||||||
SourceIssue sourceIssues = SocketManager.getSourceList().get(0);
|
SourceIssue sourceIssues = SocketManager.getSourceList().get(0);
|
||||||
|
String type = resolveFormalIssueType(sourceIssues);
|
||||||
|
sendBigItemStartIfFirstFormalIssue(runtimeParam, sourceIssues, type);
|
||||||
|
if (StrUtil.isNotBlank(sourceIssues.getOtherType())) {
|
||||||
|
sourceIssues.setType(PowerIndexEnum.V.getKey());
|
||||||
|
}
|
||||||
SocketMsg<String> xuMsg = new SocketMsg<>();
|
SocketMsg<String> xuMsg = new SocketMsg<>();
|
||||||
xuMsg.setOperateCode(SourceOperateCodeEnum.OPER_GATHER.getValue());
|
xuMsg.setOperateCode(SourceOperateCodeEnum.OPER_GATHER.getValue());
|
||||||
xuMsg.setData(JSON.toJSONString(sourceIssues));
|
xuMsg.setData(JSON.toJSONString(sourceIssues));
|
||||||
xuMsg.setRequestId(SourceOperateCodeEnum.FORMAL_REAL.getValue() + "&&" + sourceIssues.getType());
|
xuMsg.setRequestId(SourceOperateCodeEnum.FORMAL_REAL.getValue() + "&&" + type);
|
||||||
SocketManager.sendMsg(param.getUserPageId() + DetectionCommunicateConstant.SOURCE, JSON.toJSONString(xuMsg));
|
SocketManager.sendMsg(runtimeParam.getUserPageId() + DetectionCommunicateConstant.SOURCE, JSON.toJSONString(xuMsg));
|
||||||
// Resume_Success
|
// Resume_Success
|
||||||
} else {
|
} else {
|
||||||
//TODO 是否最终检测完成需要推送给用户 检测完成
|
//TODO 是否最终检测完成需要推送给用户 检测完成
|
||||||
PqScriptCheckDataParam checkDataParam = new PqScriptCheckDataParam();
|
PqScriptCheckDataParam checkDataParam = new PqScriptCheckDataParam();
|
||||||
checkDataParam.setScriptId(param.getScriptId());
|
checkDataParam.setScriptId(runtimeParam.getScriptId());
|
||||||
checkDataParam.setIsValueTypeName(false);
|
checkDataParam.setIsValueTypeName(false);
|
||||||
List<String> adType = iPqScriptCheckDataService.getValueType(checkDataParam);
|
List<String> adType = iPqScriptCheckDataService.getValueType(checkDataParam);
|
||||||
|
|
||||||
iPqDevService.updateResult(param.getDevIds(), adType, param.getCode(), param.getUserId(), param.getTemperature(), param.getHumidity());
|
iPqDevService.updateResult(runtimeParam.getDevIds(), adType, runtimeParam.getCode(), runtimeParam.getUserId(), runtimeParam.getTemperature(), runtimeParam.getHumidity(), true);
|
||||||
CnSocketUtil.quitSend(param);
|
CnSocketUtil.quitSend(runtimeParam);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void saveFormalProgress(FormalProgressParam param) {
|
||||||
|
if (param.getFormalCheckTime() == null) {
|
||||||
|
throw new BusinessException(CommonResponseEnum.FAIL, "正式检测耗时不能为空");
|
||||||
|
}
|
||||||
|
PreDetectionParam preParam = WebServiceManager.getPreDetectionParam(param.getUserPageId());
|
||||||
|
Map<String, Integer> checkResultMap = summarizeSavedFormalCheckResult(param, preParam);
|
||||||
|
Integer formalCheckTime = Math.max(param.getFormalCheckTime(), 1);
|
||||||
|
Map<Integer, List<String>> devIdsByResult = param.getDevIds().stream()
|
||||||
|
.collect(Collectors.groupingBy(devId -> checkResultMap.getOrDefault(devId, CheckResultEnum.UNCHECKED.getValue())));
|
||||||
|
devIdsByResult.forEach((checkResult, devIds) -> pqDevSubService.update(new LambdaUpdateWrapper<PqDevSub>()
|
||||||
|
.set(PqDevSub::getCheckState, CheckStateEnum.CHECKING.getValue())
|
||||||
|
.set(PqDevSub::getFormalCheckTime, formalCheckTime)
|
||||||
|
.set(PqDevSub::getCheckResult, checkResult)
|
||||||
|
.in(PqDevSub::getDevId, devIds)));
|
||||||
|
refreshPlanTestState(param.getPlanId());
|
||||||
|
|
||||||
|
if (preParam != null) {
|
||||||
|
CnSocketUtil.quitSend(preParam);
|
||||||
|
}
|
||||||
|
SocketManager.clearFormalRuntime();
|
||||||
|
FormalTestManager.clearFormalRuntime();
|
||||||
|
WebServiceManager.removePreDetectionParam(param.getUserPageId());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FormalProgressVO formalProgress(FormalProgressParam param) {
|
||||||
|
return formalProgressService.restoreAndRelease(param);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Map<String, Integer> summarizeSavedFormalCheckResult(FormalProgressParam param, PreDetectionParam preParam) {
|
||||||
|
Map<String, Integer> result = new HashMap<>();
|
||||||
|
if (CollUtil.isEmpty(param.getDevIds())) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
param.getDevIds().forEach(devId -> result.put(devId, CheckResultEnum.UNCHECKED.getValue()));
|
||||||
|
|
||||||
|
AdPlan plan = iAdPlanService.getById(param.getPlanId());
|
||||||
|
String code = preParam != null && StrUtil.isNotBlank(preParam.getCode())
|
||||||
|
? preParam.getCode()
|
||||||
|
: plan != null && plan.getCode() != null ? String.valueOf(plan.getCode()) : null;
|
||||||
|
String scriptId = preParam != null && StrUtil.isNotBlank(preParam.getScriptId())
|
||||||
|
? preParam.getScriptId()
|
||||||
|
: plan != null ? plan.getScriptId() : null;
|
||||||
|
if (StrUtil.isBlank(code) || StrUtil.isBlank(scriptId)) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
List<Integer> completedSorts = resolveCompletedFormalSorts(preParam);
|
||||||
|
if (completedSorts != null && CollUtil.isEmpty(completedSorts)) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, List<Integer>> resultFlags = new HashMap<>();
|
||||||
|
mergeResultFlags(resultFlags, nonHarmonicService.resultFlagsByDevIdsAndSorts(code, scriptId, param.getDevIds(), completedSorts));
|
||||||
|
mergeResultFlags(resultFlags, harmonicService.resultFlagsByDevIdsAndSorts(code, scriptId, param.getDevIds(), completedSorts));
|
||||||
|
param.getDevIds().forEach(devId -> result.put(devId, toCheckResult(resultFlags.get(devId))));
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<Integer> resolveCompletedFormalSorts(PreDetectionParam preParam) {
|
||||||
|
if (preParam == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
List<SourceIssue> allIssues = buildAllFormalIssues(preParam);
|
||||||
|
if (CollUtil.isEmpty(allIssues)) {
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
List<SourceIssue> remainingIssues = SocketManager.getSourceList();
|
||||||
|
Set<Integer> remainingSorts = CollUtil.isEmpty(remainingIssues)
|
||||||
|
? Collections.emptySet()
|
||||||
|
: remainingIssues.stream()
|
||||||
|
.map(SourceIssue::getIndex)
|
||||||
|
.filter(Objects::nonNull)
|
||||||
|
.collect(Collectors.toSet());
|
||||||
|
return allIssues.stream()
|
||||||
|
.map(SourceIssue::getIndex)
|
||||||
|
.filter(Objects::nonNull)
|
||||||
|
.filter(sort -> !remainingSorts.contains(sort))
|
||||||
|
.distinct()
|
||||||
|
.sorted()
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<SourceIssue> buildAllFormalIssues(PreDetectionParam param) {
|
||||||
|
PqScriptIssueParam issueParam = new PqScriptIssueParam();
|
||||||
|
issueParam.setPlanId(param.getPlanId());
|
||||||
|
issueParam.setSourceId(param.getSourceName());
|
||||||
|
issueParam.setDevIds(param.getDevIds());
|
||||||
|
issueParam.setScriptId(param.getScriptId());
|
||||||
|
issueParam.setIsPhaseSequence(CommonEnum.FORMAL_TEST.getValue());
|
||||||
|
return pqScriptDtlsService.listSourceIssue(issueParam);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void sendBigItemStartIfFirstFormalIssue(PreDetectionParam param, SourceIssue currentIssue, String type) {
|
||||||
|
if (param == null || currentIssue == null || currentIssue.getIndex() == null || StrUtil.isBlank(type)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
List<SourceIssue> allIssues = buildAllFormalIssues(param);
|
||||||
|
if (isFirstFormalIssueOfBigItem(allIssues, currentIssue, type)) {
|
||||||
|
WebServiceManager.sendDetectionMessage(param.getUserPageId(), type + CnSocketUtil.START_TAG, null, new ArrayList<>(), null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static boolean isFirstFormalIssueOfBigItem(List<SourceIssue> allIssues, SourceIssue currentIssue, String type) {
|
||||||
|
if (CollUtil.isEmpty(allIssues) || currentIssue == null || currentIssue.getIndex() == null || StrUtil.isBlank(type)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
Integer firstSort = allIssues.stream()
|
||||||
|
.filter(issue -> type.equals(resolveFormalIssueType(issue)))
|
||||||
|
.map(SourceIssue::getIndex)
|
||||||
|
.filter(Objects::nonNull)
|
||||||
|
.min(Integer::compareTo)
|
||||||
|
.orElse(null);
|
||||||
|
return Objects.equals(firstSort, currentIssue.getIndex());
|
||||||
|
}
|
||||||
|
|
||||||
|
static String resolveFormalIssueType(SourceIssue issue) {
|
||||||
|
if (issue == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return StrUtil.isNotBlank(issue.getOtherType()) ? issue.getOtherType() : issue.getType();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void mergeResultFlags(Map<String, List<Integer>> target, Map<String, List<Integer>> source) {
|
||||||
|
if (CollUtil.isEmpty(source)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
source.forEach((devId, flags) -> target.computeIfAbsent(devId, key -> new ArrayList<>()).addAll(flags));
|
||||||
|
}
|
||||||
|
|
||||||
|
private Integer toCheckResult(List<Integer> resultFlags) {
|
||||||
|
if (CollUtil.isEmpty(resultFlags)) {
|
||||||
|
return CheckResultEnum.UNCHECKED.getValue();
|
||||||
|
}
|
||||||
|
List<Integer> effectiveFlags = resultFlags.stream()
|
||||||
|
.filter(flag -> flag != null && flag != 4 && flag != 5)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
if (CollUtil.isEmpty(effectiveFlags)) {
|
||||||
|
return CheckResultEnum.ACCORD.getValue();
|
||||||
|
}
|
||||||
|
boolean hasFailed = effectiveFlags.stream().anyMatch(flag -> !Objects.equals(flag, 1));
|
||||||
|
return hasFailed ? CheckResultEnum.NOT_ACCORD.getValue() : CheckResultEnum.ACCORD.getValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isSavedFormalProgress(PqDevSub dev) {
|
||||||
|
return CheckStateEnum.CHECKING.getValue().equals(dev.getCheckState())
|
||||||
|
&& ObjectUtil.isNotNull(dev.getFormalCheckTime())
|
||||||
|
&& dev.getFormalCheckTime() > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void refreshPlanTestState(String planId) {
|
||||||
|
if (StrUtil.isBlank(planId)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
List<String> planDevIds = iPqDevService.lambdaQuery()
|
||||||
|
.eq(PqDev::getPlanId, planId)
|
||||||
|
.list()
|
||||||
|
.stream()
|
||||||
|
.map(PqDev::getId)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
if (CollUtil.isEmpty(planDevIds)) {
|
||||||
|
iAdPlanService.lambdaUpdate()
|
||||||
|
.set(AdPlan::getTestState, CheckStateEnum.UNCHECKED.getValue())
|
||||||
|
.set(AdPlan::getResult, CheckResultEnum.UNCHECKED.getValue())
|
||||||
|
.eq(AdPlan::getId, planId)
|
||||||
|
.update();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
List<PqDevSub> devSubs = pqDevSubService.lambdaQuery()
|
||||||
|
.in(PqDevSub::getDevId, planDevIds)
|
||||||
|
.list();
|
||||||
|
boolean allUnchecked = devSubs.stream()
|
||||||
|
.allMatch(dev -> CheckStateEnum.UNCHECKED.getValue().equals(dev.getCheckState()));
|
||||||
|
boolean allArchived = CollUtil.isNotEmpty(devSubs) && devSubs.stream()
|
||||||
|
.allMatch(dev -> dev.getCheckState() != null && dev.getCheckState() >= CheckStateEnum.DOCUMENTED.getValue());
|
||||||
|
Integer testState = allUnchecked
|
||||||
|
? CheckStateEnum.UNCHECKED.getValue()
|
||||||
|
: allArchived ? CheckStateEnum.CHECKED.getValue() : CheckStateEnum.CHECKING.getValue();
|
||||||
|
Integer planResult = resolvePlanCheckResult(devSubs);
|
||||||
|
iAdPlanService.lambdaUpdate()
|
||||||
|
.set(AdPlan::getTestState, testState)
|
||||||
|
.set(AdPlan::getResult, planResult)
|
||||||
|
.eq(AdPlan::getId, planId)
|
||||||
|
.update();
|
||||||
|
}
|
||||||
|
|
||||||
|
private Integer resolvePlanCheckResult(List<PqDevSub> devSubs) {
|
||||||
|
if (CollUtil.isEmpty(devSubs)) {
|
||||||
|
return CheckResultEnum.UNCHECKED.getValue();
|
||||||
|
}
|
||||||
|
Set<Integer> resultSet = devSubs.stream()
|
||||||
|
.map(PqDevSub::getCheckResult)
|
||||||
|
.filter(Objects::nonNull)
|
||||||
|
.collect(Collectors.toSet());
|
||||||
|
if (resultSet.contains(CheckResultEnum.NOT_ACCORD.getValue())) {
|
||||||
|
return CheckResultEnum.NOT_ACCORD.getValue();
|
||||||
|
}
|
||||||
|
if (resultSet.contains(CheckResultEnum.UNCHECKED.getValue()) || CollUtil.isEmpty(resultSet)) {
|
||||||
|
return CheckResultEnum.UNCHECKED.getValue();
|
||||||
|
}
|
||||||
|
return CheckResultEnum.ACCORD.getValue();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void ytxCheckSimulate(SimulateDetectionParam param) {
|
public void ytxCheckSimulate(SimulateDetectionParam param) {
|
||||||
PreDetectionParam preDetectionParam = new PreDetectionParam();
|
PreDetectionParam preDetectionParam = new PreDetectionParam();
|
||||||
@@ -289,7 +556,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());
|
||||||
@@ -301,9 +569,9 @@ public class PreDetectionServiceImpl implements PreDetectionService {
|
|||||||
|
|
||||||
SourceIssue sourceIssue = sourceIssues.get(0);
|
SourceIssue sourceIssue = sourceIssues.get(0);
|
||||||
String type = sourceIssue.getType();
|
String type = sourceIssue.getType();
|
||||||
if (sourceIssue.getIsP()) {
|
if (StrUtil.isNotBlank(sourceIssue.getOtherType())) {
|
||||||
sourceIssue.setType(ResultUnitEnum.V_ABSOLUTELY.getCode());
|
sourceIssue.setType(PowerIndexEnum.V.getKey());
|
||||||
type = ResultUnitEnum.P.getCode();
|
type = sourceIssue.getOtherType();
|
||||||
}
|
}
|
||||||
|
|
||||||
List<String> comm = sourceIssue.getDevValueTypeList();
|
List<String> comm = sourceIssue.getDevValueTypeList();
|
||||||
@@ -325,6 +593,7 @@ public class PreDetectionServiceImpl implements PreDetectionService {
|
|||||||
SourceInitialize sourceParam = pqSourceService.getSourceInitializeParam(param.getSourceId());
|
SourceInitialize sourceParam = pqSourceService.getSourceInitializeParam(param.getSourceId());
|
||||||
PreDetectionParam preDetectionParam = new PreDetectionParam();
|
PreDetectionParam preDetectionParam = new PreDetectionParam();
|
||||||
preDetectionParam.setSourceId(sourceParam.getSourceId());
|
preDetectionParam.setSourceId(sourceParam.getSourceId());
|
||||||
|
preDetectionParam.setSourceName(sourceParam.getSourceId());
|
||||||
preDetectionParam.setUserPageId(param.getUserPageId());
|
preDetectionParam.setUserPageId(param.getUserPageId());
|
||||||
CnSocketUtil.quitSendSource(preDetectionParam);
|
CnSocketUtil.quitSendSource(preDetectionParam);
|
||||||
WebServiceManager.removePreDetectionParam();
|
WebServiceManager.removePreDetectionParam();
|
||||||
@@ -348,7 +617,7 @@ public class PreDetectionServiceImpl implements PreDetectionService {
|
|||||||
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();
|
||||||
|
|||||||
@@ -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;
|
||||||
|
}
|
||||||
@@ -47,9 +47,13 @@ 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));
|
String sourceKey = param.getUserPageId() + SOURCE_TAG;
|
||||||
|
if (SocketManager.isChannelActive(sourceKey)) {
|
||||||
|
SocketManager.markActiveClose(sourceKey);
|
||||||
|
}
|
||||||
|
SocketManager.sendMsg(sourceKey, JSON.toJSONString(socketMsg));
|
||||||
WebServiceManager.removePreDetectionParam(param.getUserPageId());
|
WebServiceManager.removePreDetectionParam(param.getUserPageId());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import com.njcn.gather.plan.pojo.po.AdPlanTestConfig;
|
|||||||
import com.njcn.gather.script.pojo.po.SourceIssue;
|
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;
|
||||||
@@ -208,4 +209,40 @@ public class FormalTestManager {
|
|||||||
* 是否进行相序校验
|
* 是否进行相序校验
|
||||||
*/
|
*/
|
||||||
public static boolean isXu;
|
public static boolean isXu;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 过载信息,如果检测到电压过载,overload=1;如果检测到电流过载,overload=2;如果检测到电压&&电流过载,overload=3;反之,overload=4
|
||||||
|
*/
|
||||||
|
public static int overload;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检测开始时间
|
||||||
|
*/
|
||||||
|
public static LocalDateTime checkStartTime;
|
||||||
|
|
||||||
|
public static boolean resumeFormalPending;
|
||||||
|
|
||||||
|
public static Integer resumeNextSort;
|
||||||
|
|
||||||
|
public static Integer resumeBaseFormalCheckTime;
|
||||||
|
|
||||||
|
public static LocalDateTime resumeFormalStartTime;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数模式 检测类型"1"-"全部检测" , "2"-"不合格项复检"
|
||||||
|
*/
|
||||||
|
public static String reCheckType;
|
||||||
|
|
||||||
|
public static void clearFormalRuntime() {
|
||||||
|
stopFlag = false;
|
||||||
|
hasStopFlag = false;
|
||||||
|
stopTime = 0;
|
||||||
|
resumeFormalPending = false;
|
||||||
|
resumeNextSort = null;
|
||||||
|
resumeBaseFormalCheckTime = null;
|
||||||
|
resumeFormalStartTime = null;
|
||||||
|
realDataXiList.clear();
|
||||||
|
currentIssue = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -55,6 +55,11 @@ public class SocketManager {
|
|||||||
*/
|
*/
|
||||||
private static final Map<String, NioEventLoopGroup> socketGroup = new ConcurrentHashMap<>();
|
private static final Map<String, NioEventLoopGroup> socketGroup = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 主动关闭中的连接。用于区分业务主动 close 和对端异常断线。
|
||||||
|
*/
|
||||||
|
private static final Map<String, Boolean> activeClosingUsers = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
public static void addUser(String userId, Channel channel) {
|
public static void addUser(String userId, Channel channel) {
|
||||||
socketSessions.put(userId, channel);
|
socketSessions.put(userId, channel);
|
||||||
}
|
}
|
||||||
@@ -65,20 +70,31 @@ public class SocketManager {
|
|||||||
|
|
||||||
public static void removeUser(String userId) {
|
public static void removeUser(String userId) {
|
||||||
Channel channel = socketSessions.get(userId);
|
Channel channel = socketSessions.get(userId);
|
||||||
|
removeMapping(userId, false);
|
||||||
if (ObjectUtil.isNotNull(channel)) {
|
if (ObjectUtil.isNotNull(channel)) {
|
||||||
try {
|
try {
|
||||||
|
markActiveClose(userId);
|
||||||
channel.close().sync();
|
channel.close().sync();
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
NioEventLoopGroup eventExecutors = socketGroup.get(userId);
|
|
||||||
if (ObjectUtil.isNotNull(eventExecutors)) {
|
|
||||||
eventExecutors.shutdownGracefully();
|
|
||||||
System.out.println(userId + "__" + channel.id() + "关闭了客户端");
|
System.out.println(userId + "__" + channel.id() + "关闭了客户端");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void removeMapping(String userId) {
|
||||||
|
removeMapping(userId, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void removeMapping(String userId, boolean clearActiveClose) {
|
||||||
socketSessions.remove(userId);
|
socketSessions.remove(userId);
|
||||||
socketGroup.remove(userId);
|
NioEventLoopGroup eventExecutors = socketGroup.remove(userId);
|
||||||
|
if (clearActiveClose) {
|
||||||
|
consumeActiveClose(userId);
|
||||||
|
}
|
||||||
|
if (ObjectUtil.isNotNull(eventExecutors)) {
|
||||||
|
eventExecutors.shutdownGracefully();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Channel getChannelByUserId(String userId) {
|
public static Channel getChannelByUserId(String userId) {
|
||||||
@@ -89,6 +105,20 @@ public class SocketManager {
|
|||||||
return socketGroup.get(userId);
|
return socketGroup.get(userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void markActiveClose(String userId) {
|
||||||
|
if (StrUtil.isNotBlank(userId)) {
|
||||||
|
activeClosingUsers.put(userId, Boolean.TRUE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean consumeActiveClose(String userId) {
|
||||||
|
return StrUtil.isNotBlank(userId) && activeClosingUsers.remove(userId) != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isActiveClosing(String userId) {
|
||||||
|
return StrUtil.isNotBlank(userId) && activeClosingUsers.containsKey(userId);
|
||||||
|
}
|
||||||
|
|
||||||
public static void sendMsg(String userId, String msg) {
|
public static void sendMsg(String userId, String msg) {
|
||||||
Channel channel = socketSessions.get(userId);
|
Channel channel = socketSessions.get(userId);
|
||||||
if (ObjectUtil.isNotNull(channel)) {
|
if (ObjectUtil.isNotNull(channel)) {
|
||||||
@@ -313,6 +343,11 @@ public class SocketManager {
|
|||||||
return targetMap.get(scriptType);
|
return targetMap.get(scriptType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void clearFormalRuntime() {
|
||||||
|
sourceIssueList.clear();
|
||||||
|
targetMap.clear();
|
||||||
|
valueTypeMap.clear();
|
||||||
|
clockMap.clear();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -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");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -150,11 +161,18 @@ public class NettyContrastClientHandler extends SimpleChannelInboundHandler<Stri
|
|||||||
CnSocketUtil.contrastSendquit(param.getUserPageId(), SourceOperateCodeEnum.QUIT_INIT_02, false);
|
CnSocketUtil.contrastSendquit(param.getUserPageId(), SourceOperateCodeEnum.QUIT_INIT_02, false);
|
||||||
CnSocketUtil.contrastSendquit(param.getUserPageId(), SourceOperateCodeEnum.QUIT_INIT_03, true);
|
CnSocketUtil.contrastSendquit(param.getUserPageId(), SourceOperateCodeEnum.QUIT_INIT_03, true);
|
||||||
ctx.close();
|
ctx.close();
|
||||||
|
// 比对通道异常 → 释放检测锁
|
||||||
|
if (param != null && param.getUserPageId() != null) {
|
||||||
|
DetectionLockManager.getInstance()
|
||||||
|
.releaseIfMatchPage(param.getUserPageId(), "CONTRAST_EXCEPTION");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 接收数据超时处理
|
* 接收数据超时处理
|
||||||
|
* 比对模式读超时(10 分钟 Pst / 1 分钟实时 / 动态统计)都汇到这里,
|
||||||
|
* 推前端的同时一并释放检测锁(避免锁卡到 4 小时绝对超时)。
|
||||||
*/
|
*/
|
||||||
private void timeoutSend(SourceOperateCodeEnum sourceOperateCodeEnum) {
|
private void timeoutSend(SourceOperateCodeEnum sourceOperateCodeEnum) {
|
||||||
System.out.println("超时处理-----》" + "统计数据已超时----------------关闭");
|
System.out.println("超时处理-----》" + "统计数据已超时----------------关闭");
|
||||||
@@ -164,6 +182,11 @@ public class NettyContrastClientHandler extends SimpleChannelInboundHandler<Stri
|
|||||||
webSend.setData(sourceOperateCodeEnum.getMsg() + SourceResponseCodeEnum.RECEIVE_DATA_TIME_OUT.getMessage());
|
webSend.setData(sourceOperateCodeEnum.getMsg() + SourceResponseCodeEnum.RECEIVE_DATA_TIME_OUT.getMessage());
|
||||||
webSend.setCode(SourceResponseCodeEnum.RECEIVE_DATA_TIME_OUT.getCode());
|
webSend.setCode(SourceResponseCodeEnum.RECEIVE_DATA_TIME_OUT.getCode());
|
||||||
WebServiceManager.sendMsg(param.getUserPageId(), MsgUtil.msgToWebData(webSend, FormalTestManager.devNameMapComm, 0));
|
WebServiceManager.sendMsg(param.getUserPageId(), MsgUtil.msgToWebData(webSend, FormalTestManager.devNameMapComm, 0));
|
||||||
|
// 比对模式读超时终态 → 释放检测锁
|
||||||
|
if (param != null && param.getUserPageId() != null) {
|
||||||
|
DetectionLockManager.getInstance()
|
||||||
|
.releaseIfMatchPage(param.getUserPageId(), "CONTRAST_IDLE_TIMEOUT");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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;
|
||||||
@@ -13,8 +15,8 @@ import com.njcn.gather.detection.util.socket.FormalTestManager;
|
|||||||
import com.njcn.gather.detection.util.socket.SocketManager;
|
import com.njcn.gather.detection.util.socket.SocketManager;
|
||||||
import com.njcn.gather.detection.util.socket.websocket.WebServiceManager;
|
import com.njcn.gather.detection.util.socket.websocket.WebServiceManager;
|
||||||
import com.njcn.gather.device.pojo.vo.PreDetection;
|
import com.njcn.gather.device.pojo.vo.PreDetection;
|
||||||
|
import com.njcn.gather.report.pojo.enums.PowerIndexEnum;
|
||||||
import com.njcn.gather.script.pojo.po.SourceIssue;
|
import com.njcn.gather.script.pojo.po.SourceIssue;
|
||||||
import com.njcn.gather.system.pojo.enums.DicDataEnum;
|
|
||||||
import io.netty.channel.Channel;
|
import io.netty.channel.Channel;
|
||||||
import io.netty.channel.ChannelHandlerContext;
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
import io.netty.channel.SimpleChannelInboundHandler;
|
import io.netty.channel.SimpleChannelInboundHandler;
|
||||||
@@ -53,19 +55,19 @@ import java.util.stream.Collectors;
|
|||||||
public class NettyDevClientHandler extends SimpleChannelInboundHandler<String> {
|
public class NettyDevClientHandler extends SimpleChannelInboundHandler<String> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 闪变检测超时时间:20分钟(1300秒)
|
* 短闪检测超时时间:20分钟+100秒(1300秒)
|
||||||
*/
|
*/
|
||||||
private static final long FLICKER_TIMEOUT = 1300L;
|
private static final long SHORT_FLICKER_TIMEOUT = 1300L;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 统计数据检测超时时间:3分钟(180秒)
|
* 统计数据检测超时时间:3分钟+100秒(190秒)
|
||||||
*/
|
*/
|
||||||
private static final long STATISTICS_TIMEOUT = 180L;
|
private static final long STATISTICS_TIMEOUT = 190L;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 实时数据检测超时时间:1分钟(60秒)
|
* 实时数据检测超时时间:1分钟*3
|
||||||
*/
|
*/
|
||||||
private static final long REALTIME_TIMEOUT = 60L;
|
private static final long REALTIME_TIMEOUT = 60 * 3L;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 暂停操作超时时间:10分钟(600秒)
|
* 暂停操作超时时间:10分钟(600秒)
|
||||||
@@ -113,8 +115,15 @@ public class NettyDevClientHandler extends SimpleChannelInboundHandler<String> {
|
|||||||
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
|
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
|
||||||
log.warn("设备通讯客户端断线");
|
log.warn("设备通讯客户端断线");
|
||||||
ctx.close();
|
ctx.close();
|
||||||
SocketManager.removeUser(param.getUserPageId() + CnSocketUtil.DEV_TAG);
|
String key = param.getUserPageId() + CnSocketUtil.DEV_TAG;
|
||||||
|
if (SocketManager.consumeActiveClose(key)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
SocketManager.removeUser(key);
|
||||||
CnSocketUtil.quitSendSource(param);
|
CnSocketUtil.quitSendSource(param);
|
||||||
|
// 设备主动断开 → 本次检测视为结束,释放检测锁
|
||||||
|
DetectionLockManager.getInstance()
|
||||||
|
.releaseIfMatchPage(param.getUserPageId(), "DEV_CHANNEL_INACTIVE");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -132,6 +141,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 +199,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 +246,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 +262,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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -279,10 +305,10 @@ public class NettyDevClientHandler extends SimpleChannelInboundHandler<String> {
|
|||||||
String type = sourceIssue.getType();
|
String type = sourceIssue.getType();
|
||||||
|
|
||||||
// 根据不同检测类型使用不同的超时阈值
|
// 根据不同检测类型使用不同的超时阈值
|
||||||
if (DicDataEnum.F.getCode().equals(type)) {
|
if (PowerIndexEnum.F.getKey().equals(type)) {
|
||||||
// 闪变检测:需要更长时间,20分钟超时
|
// 闪变检测:需要更长时间,20分钟超时
|
||||||
return currentTime >= FLICKER_TIMEOUT;
|
return currentTime >= SHORT_FLICKER_TIMEOUT;
|
||||||
} else if (DicDataEnum.VOLTAGE.getCode().equals(type) || DicDataEnum.HP.getCode().equals(type)) {
|
} else if (PowerIndexEnum.VOLTAGE.getKey().equals(type) || PowerIndexEnum.HP.getKey().equals(type)) {
|
||||||
// 统计数据类型(电压、谐波):中等时间,3分钟超时
|
// 统计数据类型(电压、谐波):中等时间,3分钟超时
|
||||||
return currentTime >= STATISTICS_TIMEOUT;
|
return currentTime >= STATISTICS_TIMEOUT;
|
||||||
} else {
|
} else {
|
||||||
@@ -302,6 +328,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");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -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;
|
||||||
@@ -69,7 +70,15 @@ public class NettySourceClientHandler extends SimpleChannelInboundHandler<String
|
|||||||
ctx.close();
|
ctx.close();
|
||||||
// 从Socket管理器中移除用户通道映射
|
// 从Socket管理器中移除用户通道映射
|
||||||
if (webUser != null && StrUtil.isNotBlank(userId)) {
|
if (webUser != null && StrUtil.isNotBlank(userId)) {
|
||||||
SocketManager.removeUser(userId + CnSocketUtil.SOURCE_TAG);
|
String key = userId + CnSocketUtil.SOURCE_TAG;
|
||||||
|
if (SocketManager.isActiveClosing(key)) {
|
||||||
|
SocketManager.removeMapping(key);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
SocketManager.removeUser(key);
|
||||||
|
// 源端主动断开 → 本次检测视为结束,释放检测锁
|
||||||
|
DetectionLockManager.getInstance()
|
||||||
|
.releaseIfMatchPage(userId, "SOURCE_CHANNEL_INACTIVE");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -86,7 +95,7 @@ public class NettySourceClientHandler extends SimpleChannelInboundHandler<String
|
|||||||
}
|
}
|
||||||
|
|
||||||
String userId = webUser.getUserPageId();
|
String userId = webUser.getUserPageId();
|
||||||
log.debug("源设备接收服务端数据, userId: {}, message: {}", userId, msg);
|
log.info("source接收server端数据, userId: {}, message: {}", userId, msg);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// 委托给专门的响应处理服务处理业务逻辑
|
// 委托给专门的响应处理服务处理业务逻辑
|
||||||
@@ -95,6 +104,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");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -111,6 +125,11 @@ public class NettySourceClientHandler extends SimpleChannelInboundHandler<String
|
|||||||
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
|
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
|
||||||
String userId = webUser != null ? webUser.getUserPageId() : "unknown";
|
String userId = webUser != null ? webUser.getUserPageId() : "unknown";
|
||||||
String channelId = ctx.channel().id().toString();
|
String channelId = ctx.channel().id().toString();
|
||||||
|
if (StrUtil.isNotBlank(userId) && SocketManager.isActiveClosing(userId + CnSocketUtil.SOURCE_TAG)) {
|
||||||
|
log.debug("ignore source exception during active close, channelId: {}, userId: {}", channelId, userId);
|
||||||
|
ctx.close();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// 根据异常类型进行分类处理和日志记录
|
// 根据异常类型进行分类处理和日志记录
|
||||||
if (cause instanceof ConnectException) {
|
if (cause instanceof ConnectException) {
|
||||||
@@ -136,6 +155,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,6 +1,7 @@
|
|||||||
package com.njcn.gather.detection.util.socket.websocket;
|
package com.njcn.gather.detection.util.socket.websocket;
|
||||||
|
|
||||||
import cn.hutool.core.util.ObjectUtil;
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
|
import com.njcn.gather.detection.lock.DetectionLockManager;
|
||||||
import com.njcn.gather.detection.pojo.enums.SourceOperateCodeEnum;
|
import com.njcn.gather.detection.pojo.enums.SourceOperateCodeEnum;
|
||||||
import com.njcn.gather.detection.pojo.param.PreDetectionParam;
|
import com.njcn.gather.detection.pojo.param.PreDetectionParam;
|
||||||
import com.njcn.gather.detection.util.socket.CnSocketUtil;
|
import com.njcn.gather.detection.util.socket.CnSocketUtil;
|
||||||
@@ -110,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());
|
||||||
@@ -167,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());
|
||||||
}
|
}
|
||||||
@@ -325,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);
|
||||||
@@ -414,6 +415,11 @@ public class WebSocketHandler extends SimpleChannelInboundHandler<TextWebSocketF
|
|||||||
}
|
}
|
||||||
// 清理完成后移除该用户的检测参数
|
// 清理完成后移除该用户的检测参数
|
||||||
WebServiceManager.removePreDetectionParam(userId);
|
WebServiceManager.removePreDetectionParam(userId);
|
||||||
|
// R3 释放:WS 断开 / 客户端关页面 / 心跳超时后顺手释放检测锁
|
||||||
|
if (preDetectionParam.getUserPageId() != null) {
|
||||||
|
DetectionLockManager.getInstance()
|
||||||
|
.releaseIfMatchPage(preDetectionParam.getUserPageId(), "WS_DISCONNECTED");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("清理Socket连接时发生异常,userId: {}", userId, e);
|
log.error("清理Socket连接时发生异常,userId: {}", userId, e);
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ 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;
|
||||||
@@ -22,6 +23,7 @@ import io.swagger.annotations.ApiImplicitParams;
|
|||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.http.MediaType;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
@@ -68,10 +70,10 @@ public class PqDevController extends BaseController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@OperateInfo(operateType = OperateType.ADD)
|
@OperateInfo(operateType = OperateType.ADD)
|
||||||
@PostMapping("/add")
|
@PostMapping(value = "/add", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
||||||
@ApiOperation("新增被检设备")
|
@ApiOperation("新增被检设备")
|
||||||
@ApiImplicitParam(name = "pqDevParam", value = "被检设备", required = true)
|
@ApiImplicitParam(name = "pqDevParam", value = "被检设备", required = true)
|
||||||
public HttpResult<Boolean> add(@RequestBody @Validated PqDevParam pqDevParam) {
|
public HttpResult<Boolean> add(@ModelAttribute @Validated PqDevParam pqDevParam) {
|
||||||
String methodDescribe = getMethodDescribe("add");
|
String methodDescribe = getMethodDescribe("add");
|
||||||
LogUtil.njcnDebug(log, "{},新增数据为:{}", methodDescribe, pqDevParam);
|
LogUtil.njcnDebug(log, "{},新增数据为:{}", methodDescribe, pqDevParam);
|
||||||
boolean result = pqDevService.addPqDev(pqDevParam);
|
boolean result = pqDevService.addPqDev(pqDevParam);
|
||||||
@@ -83,10 +85,10 @@ public class PqDevController extends BaseController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@OperateInfo(operateType = OperateType.UPDATE)
|
@OperateInfo(operateType = OperateType.UPDATE)
|
||||||
@PostMapping("/update")
|
@PostMapping(value = "/update", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
||||||
@ApiOperation("修改被检设备")
|
@ApiOperation("修改被检设备")
|
||||||
@ApiImplicitParam(name = "updateParam", value = "被检设备", required = true)
|
@ApiImplicitParam(name = "updateParam", value = "被检设备", required = true)
|
||||||
public HttpResult<Boolean> update(@RequestBody @Validated PqDevParam.UpdateParam updateParam) {
|
public HttpResult<Boolean> update(@ModelAttribute @Validated PqDevParam.UpdateParam updateParam) {
|
||||||
String methodDescribe = getMethodDescribe("update");
|
String methodDescribe = getMethodDescribe("update");
|
||||||
LogUtil.njcnDebug(log, "{},修改数据为:{}", methodDescribe, updateParam);
|
LogUtil.njcnDebug(log, "{},修改数据为:{}", methodDescribe, updateParam);
|
||||||
boolean result = pqDevService.updatePqDev(updateParam);
|
boolean result = pqDevService.updatePqDev(updateParam);
|
||||||
@@ -97,6 +99,14 @@ public class PqDevController extends BaseController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@OperateInfo(info = LogEnum.BUSINESS_COMMON, operateType = OperateType.DOWNLOAD)
|
||||||
|
@GetMapping("/image/download")
|
||||||
|
@ApiOperation("下载设备图片")
|
||||||
|
@ApiImplicitParam(name = "id", value = "被检设备id", required = true)
|
||||||
|
public void downloadImage(@RequestParam("id") String id, HttpServletResponse response) {
|
||||||
|
pqDevService.downloadImage(id, response);
|
||||||
|
}
|
||||||
|
|
||||||
@OperateInfo(operateType = OperateType.DELETE)
|
@OperateInfo(operateType = OperateType.DELETE)
|
||||||
@PostMapping("/delete")
|
@PostMapping("/delete")
|
||||||
@ApiOperation("删除被检设备")
|
@ApiOperation("删除被检设备")
|
||||||
@@ -170,23 +180,14 @@ public class PqDevController extends BaseController {
|
|||||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
|
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
|
||||||
}
|
}
|
||||||
|
|
||||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON, operateType = OperateType.UPLOAD)
|
@OperateInfo
|
||||||
@PostMapping(value = "/ttt")
|
@GetMapping("/getDataCheckRes")
|
||||||
@ApiOperation("批量导入被检设备")
|
@ApiOperation("获取接入测试-数据校验结果")
|
||||||
@ApiImplicitParams({
|
@ApiImplicitParam(name = "monitorId", value = "监测点id", required = true)
|
||||||
@ApiImplicitParam(name = "file", value = "被检设备数据文件", required = true),
|
public HttpResult<DataCheckResDTO> getDataCheckRes(@RequestParam("monitorId") String monitorId) {
|
||||||
@ApiImplicitParam(name = "patternId", value = "模式id", required = true)
|
String methodDescribe = getMethodDescribe("getDataCheckRes");
|
||||||
})
|
DataCheckResDTO dataCheckRes = pqDevService.getDataCheckRes(monitorId);
|
||||||
public HttpResult ttt(@RequestParam("file") MultipartFile file, @RequestParam("patternId") String patternId, @RequestParam("planId") String planId, @RequestParam(value = "cover", defaultValue = "0") Integer cover, HttpServletResponse response) {
|
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, dataCheckRes, methodDescribe);
|
||||||
String methodDescribe = getMethodDescribe("ttt");
|
|
||||||
LogUtil.njcnDebug(log, "{},上传文件为:{}", methodDescribe, file.getOriginalFilename());
|
|
||||||
boolean fileType = FileUtil.judgeFileIsExcel(file.getOriginalFilename());
|
|
||||||
if (!fileType) {
|
|
||||||
throw new BusinessException(CommonResponseEnum.FILE_XLSX_ERROR);
|
|
||||||
}
|
|
||||||
if ("null".equals(planId)) {
|
|
||||||
planId = null;
|
|
||||||
}
|
|
||||||
return pqDevService.importDev(file, patternId, planId, response, cover);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -86,8 +86,45 @@
|
|||||||
WHERE id = #{planId}
|
WHERE id = #{planId}
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
<sql id="DevColumnsNoImage">
|
||||||
|
dev.Id,
|
||||||
|
dev.Name,
|
||||||
|
dev.Pattern,
|
||||||
|
dev.Dev_Type,
|
||||||
|
dev.Manufacturer,
|
||||||
|
dev.Create_Date,
|
||||||
|
dev.Create_Id,
|
||||||
|
dev.Hardware_Version,
|
||||||
|
dev.Software_Version,
|
||||||
|
dev.Protocol,
|
||||||
|
dev.IP,
|
||||||
|
dev.Port,
|
||||||
|
dev.Encryption_Flag,
|
||||||
|
dev.Series,
|
||||||
|
dev.Dev_Key,
|
||||||
|
dev.Sample_Id,
|
||||||
|
dev.Arrived_Date,
|
||||||
|
dev.City_Name,
|
||||||
|
dev.Gd_Name,
|
||||||
|
dev.Sub_Name,
|
||||||
|
dev.Report_Path,
|
||||||
|
dev.Plan_Id,
|
||||||
|
dev.Factor_Flag,
|
||||||
|
dev.Preinvestment_Plan,
|
||||||
|
dev.Delegate,
|
||||||
|
dev.Inspect_Channel,
|
||||||
|
dev.Inspect_Date,
|
||||||
|
dev.Harm_Sys_Id,
|
||||||
|
dev.Import_Flag,
|
||||||
|
dev.State,
|
||||||
|
dev.Create_By,
|
||||||
|
dev.Create_Time,
|
||||||
|
dev.Update_By,
|
||||||
|
dev.Update_Time
|
||||||
|
</sql>
|
||||||
|
|
||||||
<select id="selectByQueryParam" resultType="com.njcn.gather.device.pojo.vo.PqDevVO">
|
<select id="selectByQueryParam" resultType="com.njcn.gather.device.pojo.vo.PqDevVO">
|
||||||
SELECT dev.*,dev_sub.* FROM pq_dev dev
|
SELECT <include refid="DevColumnsNoImage"/>, dev_sub.* FROM pq_dev dev
|
||||||
left JOIN pq_dev_sub dev_sub ON dev.Id = dev_sub.Dev_Id
|
left JOIN pq_dev_sub dev_sub ON dev.Id = dev_sub.Dev_Id
|
||||||
<where>
|
<where>
|
||||||
dev.state = 1
|
dev.state = 1
|
||||||
@@ -124,7 +161,7 @@
|
|||||||
</select>
|
</select>
|
||||||
|
|
||||||
<select id="listByDevIds" resultType="com.njcn.gather.device.pojo.vo.PqDevVO">
|
<select id="listByDevIds" resultType="com.njcn.gather.device.pojo.vo.PqDevVO">
|
||||||
SELECT dev.*, dev_sub.*
|
SELECT <include refid="DevColumnsNoImage"/>, dev_sub.*
|
||||||
FROM pq_dev dev
|
FROM pq_dev dev
|
||||||
left JOIN pq_dev_sub dev_sub ON dev.Id = dev_sub.Dev_Id
|
left JOIN pq_dev_sub dev_sub ON dev.Id = dev_sub.Dev_Id
|
||||||
WHERE dev.state = 1
|
WHERE dev.state = 1
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
package com.njcn.gather.device.pojo.dto;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author caozehui
|
||||||
|
* @data 2026-06-15
|
||||||
|
*/
|
||||||
|
public class DataCheckResDTO {
|
||||||
|
}
|
||||||
@@ -12,7 +12,7 @@ public enum CheckStateEnum {
|
|||||||
CHECKING("检测中", 1),
|
CHECKING("检测中", 1),
|
||||||
CHECKED("检测完成", 2),
|
CHECKED("检测完成", 2),
|
||||||
/**
|
/**
|
||||||
* 检测计划没有该状态,只有未检、检测中、检测完成三种状态。被检设备有这种状态
|
* 检测计划没有归档状态,只有未检、检测中、检测完成三种状态。被检设备有归档状态
|
||||||
*/
|
*/
|
||||||
DOCUMENTED("归档", 3);
|
DOCUMENTED("归档", 3);
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import io.swagger.annotations.ApiModelProperty;
|
|||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
import org.hibernate.validator.constraints.Range;
|
import org.hibernate.validator.constraints.Range;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
import javax.validation.Valid;
|
import javax.validation.Valid;
|
||||||
import javax.validation.constraints.*;
|
import javax.validation.constraints.*;
|
||||||
@@ -136,6 +137,9 @@ public class PqDevParam {
|
|||||||
@ApiModelProperty("是否为导入设备")
|
@ApiModelProperty("是否为导入设备")
|
||||||
private Integer importFlag;
|
private Integer importFlag;
|
||||||
|
|
||||||
|
@ApiModelProperty("设备图片")
|
||||||
|
private MultipartFile image;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 更新操作实体
|
* 更新操作实体
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package com.njcn.gather.device.pojo.po;
|
|||||||
import com.baomidou.mybatisplus.annotation.FieldFill;
|
import com.baomidou.mybatisplus.annotation.FieldFill;
|
||||||
import com.baomidou.mybatisplus.annotation.TableField;
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
import com.baomidou.mybatisplus.annotation.TableName;
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||||
@@ -184,6 +185,9 @@ public class PqDev extends BaseEntity implements Serializable {
|
|||||||
*/
|
*/
|
||||||
private Integer importFlag;
|
private Integer importFlag;
|
||||||
|
|
||||||
|
@JsonIgnore
|
||||||
|
private byte[] image;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 状态:0-删除 1-正常
|
* 状态:0-删除 1-正常
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 预检测耗时
|
* 预检测耗时
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.njcn.gather.device.pojo.vo;
|
package com.njcn.gather.device.pojo.vo;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
import com.njcn.gather.device.pojo.po.PqDev;
|
import com.njcn.gather.device.pojo.po.PqDev;
|
||||||
import com.njcn.gather.monitor.pojo.po.PqMonitor;
|
import com.njcn.gather.monitor.pojo.po.PqMonitor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
@@ -73,9 +74,14 @@ public class PqDevVO extends PqDev {
|
|||||||
private String checkBy;
|
private String checkBy;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 检测时间
|
* 检测开始时间
|
||||||
*/
|
*/
|
||||||
private LocalDateTime checkTime;
|
private LocalDateTime checkStartTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检测结束时间
|
||||||
|
*/
|
||||||
|
private LocalDateTime checkEndTime;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 预检测耗时
|
* 预检测耗时
|
||||||
@@ -116,4 +122,10 @@ public class PqDevVO extends PqDev {
|
|||||||
* 检测点结果
|
* 检测点结果
|
||||||
*/
|
*/
|
||||||
private List<Integer> monitorResults;
|
private List<Integer> monitorResults;
|
||||||
|
|
||||||
|
private Boolean hasImage;
|
||||||
|
|
||||||
|
private String imageBase64;
|
||||||
|
|
||||||
|
private String imageContentType;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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.common.pojo.poi.PullDown;
|
import com.njcn.common.pojo.poi.PullDown;
|
||||||
import com.njcn.common.pojo.response.HttpResult;
|
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;
|
||||||
@@ -95,6 +96,14 @@ public interface IPqDevService extends IService<PqDev> {
|
|||||||
*/
|
*/
|
||||||
PqDevVO getPqDevById(String id);
|
PqDevVO getPqDevById(String id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 下载设备图片
|
||||||
|
*
|
||||||
|
* @param id 设备id
|
||||||
|
* @param response 响应
|
||||||
|
*/
|
||||||
|
void downloadImage(String id, HttpServletResponse response);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取装置信息和装置下监测点信息
|
* 获取装置信息和装置下监测点信息
|
||||||
*
|
*
|
||||||
@@ -115,9 +124,17 @@ 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);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新一轮正式检测真正开始前,仅清理原检测中设备的暂存耗时,并把本次设备置为检测中。
|
||||||
|
*/
|
||||||
|
void clearFormalProgressForNewRun(List<String> devIds);
|
||||||
|
|
||||||
|
Integer getMinFormalCheckTime(List<String> devIds);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 比对式-修改设备状态
|
* 比对式-修改设备状态
|
||||||
@@ -288,4 +305,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);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,10 +3,14 @@ package com.njcn.gather.device.service;
|
|||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
import com.njcn.gather.device.pojo.po.PqDevSub;
|
import com.njcn.gather.device.pojo.po.PqDevSub;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author caozehui
|
* @author caozehui
|
||||||
* @date 2025-07-04
|
* @date 2025-07-04
|
||||||
*/
|
*/
|
||||||
public interface IPqDevSubService extends IService<PqDevSub> {
|
public interface IPqDevSubService extends IService<PqDevSub> {
|
||||||
|
|
||||||
|
LocalDateTime resolveBatchMaxCheckEndTime(List<String> devIds);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import cn.afterturn.easypoi.excel.entity.ExportParams;
|
|||||||
import cn.afterturn.easypoi.excel.entity.ImportParams;
|
import cn.afterturn.easypoi.excel.entity.ImportParams;
|
||||||
import cn.afterturn.easypoi.excel.entity.result.ExcelImportResult;
|
import cn.afterturn.easypoi.excel.entity.result.ExcelImportResult;
|
||||||
import cn.hutool.core.bean.BeanUtil;
|
import cn.hutool.core.bean.BeanUtil;
|
||||||
|
import cn.hutool.core.bean.copier.CopyOptions;
|
||||||
import cn.hutool.core.collection.CollUtil;
|
import cn.hutool.core.collection.CollUtil;
|
||||||
import cn.hutool.core.collection.CollectionUtil;
|
import cn.hutool.core.collection.CollectionUtil;
|
||||||
import cn.hutool.core.util.ObjectUtil;
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
@@ -26,7 +27,10 @@ import com.njcn.common.pojo.poi.PullDown;
|
|||||||
import com.njcn.common.pojo.response.HttpResult;
|
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.pojo.enums.SourceOperateCodeEnum;
|
||||||
|
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,10 +38,14 @@ import com.njcn.gather.device.pojo.po.PqDevSub;
|
|||||||
import com.njcn.gather.device.pojo.vo.*;
|
import com.njcn.gather.device.pojo.vo.*;
|
||||||
import com.njcn.gather.device.service.IPqDevService;
|
import com.njcn.gather.device.service.IPqDevService;
|
||||||
import com.njcn.gather.device.service.IPqDevSubService;
|
import com.njcn.gather.device.service.IPqDevSubService;
|
||||||
|
import com.njcn.gather.device.util.PqDevImageSupport;
|
||||||
import com.njcn.gather.monitor.pojo.po.PqMonitor;
|
import com.njcn.gather.monitor.pojo.po.PqMonitor;
|
||||||
import com.njcn.gather.monitor.pojo.vo.PqMonitorExcel;
|
import com.njcn.gather.monitor.pojo.vo.PqMonitorExcel;
|
||||||
import com.njcn.gather.monitor.service.IPqMonitorService;
|
import com.njcn.gather.monitor.service.IPqMonitorService;
|
||||||
|
import com.njcn.gather.plan.mapper.AdPlanMapper;
|
||||||
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.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;
|
||||||
@@ -51,6 +59,7 @@ 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.HttpResultUtil;
|
||||||
@@ -64,6 +73,7 @@ import org.springframework.transaction.annotation.Transactional;
|
|||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.io.IOException;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
@@ -87,6 +97,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) {
|
||||||
@@ -128,7 +141,8 @@ public class PqDevServiceImpl extends ServiceImpl<PqDevMapper, PqDev> implements
|
|||||||
this.checkRepeat(pqDevParam, false);
|
this.checkRepeat(pqDevParam, false);
|
||||||
|
|
||||||
PqDev pqDev = new PqDev();
|
PqDev pqDev = new PqDev();
|
||||||
BeanUtil.copyProperties(pqDevParam, pqDev);
|
BeanUtil.copyProperties(pqDevParam, pqDev, CopyOptions.create().setIgnoreProperties("image"));
|
||||||
|
fillImage(pqDev, pqDevParam);
|
||||||
String currrentScene = sysTestConfigService.getCurrrentScene();
|
String currrentScene = sysTestConfigService.getCurrrentScene();
|
||||||
this.checkParams(pqDev, currrentScene);
|
this.checkParams(pqDev, currrentScene);
|
||||||
|
|
||||||
@@ -159,6 +173,19 @@ public class PqDevServiceImpl extends ServiceImpl<PqDevMapper, PqDev> implements
|
|||||||
return this.save(pqDev);
|
return this.save(pqDev);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void fillImage(PqDev pqDev, PqDevParam pqDevParam) {
|
||||||
|
try {
|
||||||
|
byte[] image = PqDevImageSupport.processUpload(pqDevParam.getImage());
|
||||||
|
if (image != null) {
|
||||||
|
pqDev.setImage(image);
|
||||||
|
}
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
throw new BusinessException(CommonResponseEnum.FAIL, e.getMessage());
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new BusinessException(CommonResponseEnum.FAIL, "图片处理失败");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 校验参数
|
* 校验参数
|
||||||
*
|
*
|
||||||
@@ -201,7 +228,8 @@ public class PqDevServiceImpl extends ServiceImpl<PqDevMapper, PqDev> implements
|
|||||||
this.checkRepeat(updateParam, true);
|
this.checkRepeat(updateParam, true);
|
||||||
|
|
||||||
PqDev pqDev = new PqDev();
|
PqDev pqDev = new PqDev();
|
||||||
BeanUtil.copyProperties(updateParam, pqDev);
|
BeanUtil.copyProperties(updateParam, pqDev, CopyOptions.create().setIgnoreProperties("image"));
|
||||||
|
fillImage(pqDev, updateParam);
|
||||||
String currrentScene = sysTestConfigService.getCurrrentScene();
|
String currrentScene = sysTestConfigService.getCurrrentScene();
|
||||||
this.checkParams(pqDev, currrentScene);
|
this.checkParams(pqDev, currrentScene);
|
||||||
|
|
||||||
@@ -268,6 +296,8 @@ public class PqDevServiceImpl extends ServiceImpl<PqDevMapper, PqDev> implements
|
|||||||
@Override
|
@Override
|
||||||
public List<Map<String, Object>> listUnbound(String pattern) {
|
public List<Map<String, Object>> listUnbound(String pattern) {
|
||||||
List<PqDev> pqDevList = this.lambdaQuery()
|
List<PqDev> pqDevList = this.lambdaQuery()
|
||||||
|
.select(PqDev::getId, PqDev::getName, PqDev::getDevType, PqDev::getManufacturer,
|
||||||
|
PqDev::getCityName, PqDev::getGdName, PqDev::getSubName)
|
||||||
.eq(PqDev::getPattern, pattern)
|
.eq(PqDev::getPattern, pattern)
|
||||||
.eq(PqDev::getState, DataStateEnum.ENABLE.getCode())
|
.eq(PqDev::getState, DataStateEnum.ENABLE.getCode())
|
||||||
.isNull(PqDev::getPlanId)
|
.isNull(PqDev::getPlanId)
|
||||||
@@ -337,24 +367,8 @@ public class PqDevServiceImpl extends ServiceImpl<PqDevMapper, PqDev> implements
|
|||||||
List<String> notUnchecked = list.stream().filter(x -> !CheckStateEnum.UNCHECKED.getValue().equals(x.getCheckState())).map(PqDevSub::getDevId).distinct().collect(Collectors.toList());
|
List<String> notUnchecked = list.stream().filter(x -> !CheckStateEnum.UNCHECKED.getValue().equals(x.getCheckState())).map(PqDevSub::getDevId).distinct().collect(Collectors.toList());
|
||||||
|
|
||||||
if (CollUtil.isNotEmpty(notUnchecked)) {
|
if (CollUtil.isNotEmpty(notUnchecked)) {
|
||||||
List<String> unchecked = list.stream().filter(x -> CheckStateEnum.UNCHECKED.getValue().equals(x.getCheckState())).map(PqDevSub::getDevId).distinct().collect(Collectors.toList());
|
boolean allArchived = list.stream().allMatch(x -> x.getCheckState() != null && x.getCheckState() >= CheckStateEnum.DOCUMENTED.getValue());
|
||||||
//计划未检测
|
return allArchived ? CheckStateEnum.CHECKED.getValue() : CheckStateEnum.CHECKING.getValue();
|
||||||
if (CollUtil.isNotEmpty(unchecked)) {
|
|
||||||
return CheckStateEnum.CHECKING.getValue();
|
|
||||||
}
|
|
||||||
//计划检测中
|
|
||||||
List<String> checking = list.stream().filter(x -> x.getCheckState().equals(CheckStateEnum.CHECKED.getValue()) &&
|
|
||||||
!CheckStateEnum.DOCUMENTED.getValue().equals(x.getCheckState())
|
|
||||||
).map(PqDevSub::getDevId).distinct().collect(Collectors.toList());
|
|
||||||
if (checking.size() == notUnchecked.size()) {
|
|
||||||
return CheckStateEnum.CHECKING.getValue();
|
|
||||||
}
|
|
||||||
//检测完成
|
|
||||||
List<String> checked = list.stream().filter(x -> CheckStateEnum.DOCUMENTED.getValue().equals(x.getCheckState())).map(PqDevSub::getDevId).distinct().collect(Collectors.toList());
|
|
||||||
if (checked.size() == notUnchecked.size()) {
|
|
||||||
return CheckStateEnum.CHECKED.getValue();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return CheckStateEnum.UNCHECKED.getValue();
|
return CheckStateEnum.UNCHECKED.getValue();
|
||||||
@@ -382,6 +396,10 @@ public class PqDevServiceImpl extends ServiceImpl<PqDevMapper, PqDev> implements
|
|||||||
@Override
|
@Override
|
||||||
public PqDevVO getPqDevById(String id) {
|
public PqDevVO getPqDevById(String id) {
|
||||||
PqDevVO pqDevVO = this.baseMapper.selectByDevId(id);
|
PqDevVO pqDevVO = this.baseMapper.selectByDevId(id);
|
||||||
|
if (ObjectUtil.isNull(pqDevVO)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
setImageEchoFields(pqDevVO);
|
||||||
if (StrUtil.isNotBlank(pqDevVO.getSeries())) {
|
if (StrUtil.isNotBlank(pqDevVO.getSeries())) {
|
||||||
pqDevVO.setSeries(EncryptionUtil.decoderString(1, pqDevVO.getSeries()));
|
pqDevVO.setSeries(EncryptionUtil.decoderString(1, pqDevVO.getSeries()));
|
||||||
}
|
}
|
||||||
@@ -410,6 +428,37 @@ public class PqDevServiceImpl extends ServiceImpl<PqDevMapper, PqDev> implements
|
|||||||
return pqDevVO;
|
return pqDevVO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void downloadImage(String id, HttpServletResponse response) {
|
||||||
|
PqDev pqDev = this.getById(id);
|
||||||
|
if (ObjectUtil.isNull(pqDev) || pqDev.getImage() == null || pqDev.getImage().length == 0) {
|
||||||
|
throw new BusinessException(CommonResponseEnum.FAIL, "设备图片不存在");
|
||||||
|
}
|
||||||
|
String contentType = PqDevImageSupport.detectContentType(pqDev.getImage());
|
||||||
|
String filename = "device-image-" + id + "." + PqDevImageSupport.getExtension(contentType);
|
||||||
|
response.setContentType(contentType);
|
||||||
|
response.setContentLength(pqDev.getImage().length);
|
||||||
|
response.setHeader("Content-Disposition", "attachment; filename=\"" + filename + "\"");
|
||||||
|
try {
|
||||||
|
response.getOutputStream().write(pqDev.getImage());
|
||||||
|
response.flushBuffer();
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new BusinessException(CommonResponseEnum.FAIL, "设备图片下载失败");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setImageEchoFields(PqDevVO pqDevVO) {
|
||||||
|
try {
|
||||||
|
PqDevImageSupport.ImageEchoPayload payload = PqDevImageSupport.buildEchoPayload(pqDevVO.getImage());
|
||||||
|
pqDevVO.setHasImage(payload.isHasImage());
|
||||||
|
pqDevVO.setImageBase64(payload.getImageBase64());
|
||||||
|
pqDevVO.setImageContentType(payload.getImageContentType());
|
||||||
|
pqDevVO.setImage(null);
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
throw new BusinessException(CommonResponseEnum.FAIL, e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取查询条件wrapper
|
* 获取查询条件wrapper
|
||||||
@@ -419,6 +468,7 @@ public class PqDevServiceImpl extends ServiceImpl<PqDevMapper, PqDev> implements
|
|||||||
*/
|
*/
|
||||||
private Wrapper getQueryWrapper(PqDevParam.QueryParam queryParam) {
|
private Wrapper getQueryWrapper(PqDevParam.QueryParam queryParam) {
|
||||||
QueryWrapper<PqDev> queryWrapper = new QueryWrapper<>();
|
QueryWrapper<PqDev> queryWrapper = new QueryWrapper<>();
|
||||||
|
queryWrapper.select("pq_dev.Id");
|
||||||
if (ObjectUtil.isNotNull(queryParam)) {
|
if (ObjectUtil.isNotNull(queryParam)) {
|
||||||
queryWrapper
|
queryWrapper
|
||||||
.like(StrUtil.isNotBlank(queryParam.getName()), "pq_dev.name", queryParam.getName())
|
.like(StrUtil.isNotBlank(queryParam.getName()), "pq_dev.name", queryParam.getName())
|
||||||
@@ -481,9 +531,48 @@ public class PqDevServiceImpl extends ServiceImpl<PqDevMapper, PqDev> implements
|
|||||||
return preDetections;
|
return preDetections;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void clearFormalProgressForNewRun(List<String> devIds) {
|
||||||
|
if (CollUtil.isEmpty(devIds)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
List<PqDevSub> devSubs = pqDevSubService.lambdaQuery()
|
||||||
|
.in(PqDevSub::getDevId, devIds)
|
||||||
|
.list();
|
||||||
|
List<String> resetFormalCheckIds = devSubs.stream()
|
||||||
|
.filter(dev -> CheckStateEnum.CHECKING.getValue().equals(dev.getCheckState()))
|
||||||
|
.map(PqDevSub::getDevId)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
if (CollUtil.isNotEmpty(resetFormalCheckIds)) {
|
||||||
|
pqDevSubService.lambdaUpdate()
|
||||||
|
.set(PqDevSub::getFormalCheckTime, 0)
|
||||||
|
.in(PqDevSub::getDevId, resetFormalCheckIds)
|
||||||
|
.update();
|
||||||
|
}
|
||||||
|
pqDevSubService.lambdaUpdate()
|
||||||
|
.set(PqDevSub::getCheckState, CheckStateEnum.CHECKING.getValue())
|
||||||
|
.in(PqDevSub::getDevId, devIds)
|
||||||
|
.update();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean updateResult(List<String> ids, List<String> adType, String code, String userId, Float temperature, Float humidity) {
|
public Integer getMinFormalCheckTime(List<String> devIds) {
|
||||||
|
if (CollUtil.isEmpty(devIds)) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return pqDevSubService.lambdaQuery()
|
||||||
|
.in(PqDevSub::getDevId, devIds)
|
||||||
|
.list()
|
||||||
|
.stream()
|
||||||
|
.map(PqDevSub::getFormalCheckTime)
|
||||||
|
.filter(Objects::nonNull)
|
||||||
|
.min(Integer::compareTo)
|
||||||
|
.orElse(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
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();
|
||||||
@@ -500,7 +589,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 && SourceOperateCodeEnum.ALL_TEST.getValue().equals(FormalTestManager.reCheckType), PqDevSub::getCheckEndTime, LocalDateTime.now())
|
||||||
|
.set(updateCheckNum && SourceOperateCodeEnum.ALL_TEST.getValue().equals(FormalTestManager.reCheckType) && 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)) {
|
||||||
@@ -515,13 +605,33 @@ 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();
|
||||||
|
if (updateCheckNum) {
|
||||||
i = pqDevVo.getRecheckNum() + 1;
|
i = pqDevVo.getRecheckNum() + 1;
|
||||||
|
} else {
|
||||||
|
i = pqDevVo.getRecheckNum();
|
||||||
|
}
|
||||||
wrapper.set(PqDevSub::getReportState, DevReportStateEnum.NOT_GENERATED.getValue());
|
wrapper.set(PqDevSub::getReportState, DevReportStateEnum.NOT_GENERATED.getValue());
|
||||||
}
|
}
|
||||||
|
if (ObjectUtil.isNotNull(FormalTestManager.resumeBaseFormalCheckTime)
|
||||||
|
&& ObjectUtil.isNotNull(FormalTestManager.resumeFormalStartTime)) {
|
||||||
|
int elapsedSeconds = (int) java.time.Duration.between(
|
||||||
|
FormalTestManager.resumeFormalStartTime,
|
||||||
|
LocalDateTime.now()
|
||||||
|
).getSeconds();
|
||||||
|
wrapper.set(PqDevSub::getFormalCheckTime,
|
||||||
|
FormalTestManager.resumeBaseFormalCheckTime + Math.max(elapsedSeconds, 0));
|
||||||
|
} else if (updateCheckNum && ObjectUtil.isNotNull(FormalTestManager.checkStartTime)) {
|
||||||
|
int elapsedSeconds = (int) java.time.Duration.between(
|
||||||
|
FormalTestManager.checkStartTime,
|
||||||
|
LocalDateTime.now()
|
||||||
|
).getSeconds();
|
||||||
|
wrapper.set(PqDevSub::getFormalCheckTime, Math.max(elapsedSeconds, 0));
|
||||||
|
}
|
||||||
wrapper.set(PqDevSub::getRecheckNum, i)
|
wrapper.set(PqDevSub::getRecheckNum, i)
|
||||||
.set(PqDevSub::getCheckState, checkState);
|
.set(PqDevSub::getCheckState, checkState);
|
||||||
pqDevSubService.update(wrapper);
|
pqDevSubService.update(wrapper);
|
||||||
|
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()));
|
||||||
@@ -536,16 +646,12 @@ public class PqDevServiceImpl extends ServiceImpl<PqDevMapper, PqDev> implements
|
|||||||
this.baseMapper.updatePlanCheckResult(pqDevVo.getPlanId(), CheckResultEnum.ACCORD.getValue());
|
this.baseMapper.updatePlanCheckResult(pqDevVo.getPlanId(), CheckResultEnum.ACCORD.getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
set = pqDevVOList.stream().map(PqDevVO::getCheckState).collect(Collectors.toSet());
|
boolean allUnchecked = pqDevVOList.stream().allMatch(obj -> CheckStateEnum.UNCHECKED.getValue().equals(obj.getCheckState()));
|
||||||
if (set.contains(CheckStateEnum.UNCHECKED.getValue())) {
|
boolean allArchived = pqDevVOList.stream().allMatch(obj -> obj.getCheckState() != null && obj.getCheckState() >= CheckStateEnum.DOCUMENTED.getValue());
|
||||||
this.baseMapper.updatePlanTestState(pqDevVo.getPlanId(), CheckStateEnum.CHECKING.getValue());
|
if (allUnchecked) {
|
||||||
} else {
|
this.baseMapper.updatePlanTestState(pqDevVo.getPlanId(), CheckStateEnum.UNCHECKED.getValue());
|
||||||
if (checkState.equals(CheckStateEnum.DOCUMENTED.getValue())) {
|
} else if (allArchived) {
|
||||||
long count = pqDevVOList.stream().filter(obj -> !CheckStateEnum.DOCUMENTED.getValue().equals(obj.getCheckState())).count();
|
this.baseMapper.updatePlanTestState(pqDevVo.getPlanId(), CheckStateEnum.CHECKED.getValue());
|
||||||
if (count == 0) {
|
|
||||||
// 如果非归档状态的设备数量为0,则更新计划已完成
|
|
||||||
this.baseMapper.finishPlan(pqDevVo.getPlanId());
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
this.baseMapper.updatePlanTestState(pqDevVo.getPlanId(), CheckStateEnum.CHECKING.getValue());
|
this.baseMapper.updatePlanTestState(pqDevVo.getPlanId(), CheckStateEnum.CHECKING.getValue());
|
||||||
}
|
}
|
||||||
@@ -553,7 +659,6 @@ public class PqDevServiceImpl extends ServiceImpl<PqDevMapper, PqDev> implements
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -573,13 +678,23 @@ public class PqDevServiceImpl extends ServiceImpl<PqDevMapper, PqDev> implements
|
|||||||
|
|
||||||
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::getReportState, DevReportStateEnum.NOT_GENERATED.getValue())
|
.set(PqDevSub::getReportState, DevReportStateEnum.NOT_GENERATED.getValue())
|
||||||
.set(PqDevSub::getCheckTime, LocalDateTime.now())
|
|
||||||
.eq(PqDevSub::getDevId, devId);
|
.eq(PqDevSub::getDevId, devId);
|
||||||
|
|
||||||
|
// 只有当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)) {
|
if (ObjectUtil.isNotNull(user)) {
|
||||||
w.set(PqDevSub::getCheckBy, user.getName());
|
w.set(PqDevSub::getCheckBy, user.getName());
|
||||||
}
|
}
|
||||||
@@ -587,6 +702,7 @@ public class PqDevServiceImpl extends ServiceImpl<PqDevMapper, PqDev> implements
|
|||||||
w.set(PqDevSub::getReportState, DevReportStateEnum.NOT_GENERATED.getValue());
|
w.set(PqDevSub::getReportState, DevReportStateEnum.NOT_GENERATED.getValue());
|
||||||
}
|
}
|
||||||
w.update();
|
w.update();
|
||||||
|
saveCheckHistory(devId, userId);
|
||||||
|
|
||||||
PqDevParam.QueryParam param = new PqDevParam.QueryParam();
|
PqDevParam.QueryParam param = new PqDevParam.QueryParam();
|
||||||
String planId = dev.getPlanId();
|
String planId = dev.getPlanId();
|
||||||
@@ -594,7 +710,7 @@ public class PqDevServiceImpl extends ServiceImpl<PqDevMapper, PqDev> implements
|
|||||||
List<PqDevVO> pqDevVOList = this.baseMapper.selectByQueryParam(param);
|
List<PqDevVO> pqDevVOList = this.baseMapper.selectByQueryParam(param);
|
||||||
|
|
||||||
if (CollUtil.isNotEmpty(pqDevVOList)) {
|
if (CollUtil.isNotEmpty(pqDevVOList)) {
|
||||||
Set<Integer> set = pqDevVOList.stream().filter(obj -> CheckStateEnum.CHECKED.getValue().equals(obj.getCheckState()) || CheckStateEnum.DOCUMENTED.getValue().equals(obj.getCheckState())).map(PqDevVO::getCheckResult).collect(Collectors.toSet());
|
Set<Integer> set = pqDevVOList.stream().filter(obj -> obj.getCheckState() != null && obj.getCheckState() >= CheckStateEnum.CHECKED.getValue()).map(PqDevVO::getCheckResult).collect(Collectors.toSet());
|
||||||
if (checkState == CheckStateEnum.CHECKED.getValue()) {
|
if (checkState == CheckStateEnum.CHECKED.getValue()) {
|
||||||
set.add(checkResult);
|
set.add(checkResult);
|
||||||
}
|
}
|
||||||
@@ -611,17 +727,51 @@ public class PqDevServiceImpl extends ServiceImpl<PqDevMapper, PqDev> implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
set = pqDevVOList.stream().map(PqDevVO::getCheckState).collect(Collectors.toSet());
|
boolean allUnchecked = pqDevVOList.stream().allMatch(obj -> CheckStateEnum.UNCHECKED.getValue().equals(obj.getCheckState()));
|
||||||
if (set.contains(CheckStateEnum.UNCHECKED.getValue())) {
|
boolean allArchived = pqDevVOList.stream().allMatch(obj -> obj.getCheckState() != null && obj.getCheckState() >= CheckStateEnum.DOCUMENTED.getValue());
|
||||||
this.baseMapper.updatePlanTestState(planId, CheckStateEnum.CHECKING.getValue());
|
if (allUnchecked) {
|
||||||
} else if (set.contains(CheckStateEnum.CHECKING.getValue())) {
|
this.baseMapper.updatePlanTestState(planId, CheckStateEnum.UNCHECKED.getValue());
|
||||||
this.baseMapper.updatePlanTestState(planId, CheckStateEnum.CHECKING.getValue());
|
} else if (allArchived) {
|
||||||
} else {
|
|
||||||
this.baseMapper.updatePlanTestState(planId, CheckStateEnum.CHECKED.getValue());
|
this.baseMapper.updatePlanTestState(planId, CheckStateEnum.CHECKED.getValue());
|
||||||
|
} else {
|
||||||
|
this.baseMapper.updatePlanTestState(planId, CheckStateEnum.CHECKING.getValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void saveCheckHistory(PqDevVO pqDevVo, Integer recheckNum, Integer checkState, String userId) {
|
||||||
|
if (ObjectUtil.isNull(pqDevVo)
|
||||||
|
|| checkState == null
|
||||||
|
|| checkState < CheckStateEnum.CHECKED.getValue()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
AdPlan plan = adPlanMapper.selectById(pqDevVo.getPlanId());
|
||||||
|
if (ObjectUtil.isNull(plan)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
pqDevVo.setRecheckNum(recheckNum);
|
||||||
|
pqDevVo.setCheckBy(userId);
|
||||||
|
pqDevVo.setCheckEndTime(LocalDateTime.now());
|
||||||
|
pqDevCheckHistoryService.saveOrUpdateDeviceHistory(plan, pqDevVo);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void saveCheckHistory(String devId, String userId) {
|
||||||
|
PqDevVO pqDevVo = this.baseMapper.selectByDevId(devId);
|
||||||
|
if (ObjectUtil.isNull(pqDevVo)
|
||||||
|
|| pqDevVo.getCheckState() == null
|
||||||
|
|| pqDevVo.getCheckState() < CheckStateEnum.CHECKED.getValue()) {
|
||||||
|
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<>();
|
||||||
@@ -1601,7 +1751,10 @@ public class PqDevServiceImpl extends ServiceImpl<PqDevMapper, PqDev> implements
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<String, List<String>> listSelectOptions(String pattern) {
|
public Map<String, List<String>> listSelectOptions(String pattern) {
|
||||||
List<PqDev> pqDevList = this.lambdaQuery().eq(PqDev::getPattern, pattern)
|
List<PqDev> pqDevList = this.lambdaQuery()
|
||||||
|
.select(PqDev::getCityName, PqDev::getGdName, PqDev::getSubName,
|
||||||
|
PqDev::getHardwareVersion, PqDev::getSoftwareVersion)
|
||||||
|
.eq(PqDev::getPattern, pattern)
|
||||||
.eq(PqDev::getState, DataStateEnum.ENABLE.getCode())
|
.eq(PqDev::getState, DataStateEnum.ENABLE.getCode())
|
||||||
.list();
|
.list();
|
||||||
String[] devKeyArray = new String[]{"cityName", "gdName", "subName", "hardwareVersion", "softwareVersion"};
|
String[] devKeyArray = new String[]{"cityName", "gdName", "subName", "hardwareVersion", "softwareVersion"};
|
||||||
@@ -1625,4 +1778,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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,20 @@
|
|||||||
package com.njcn.gather.device.service.impl;
|
package com.njcn.gather.device.service.impl;
|
||||||
|
|
||||||
|
import cn.hutool.core.collection.CollUtil;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import com.njcn.gather.device.pojo.po.PqDevSub;
|
|
||||||
import com.njcn.gather.device.mapper.PqDevSubMapper;
|
import com.njcn.gather.device.mapper.PqDevSubMapper;
|
||||||
|
import com.njcn.gather.device.pojo.po.PqDevSub;
|
||||||
import com.njcn.gather.device.service.IPqDevSubService;
|
import com.njcn.gather.device.service.IPqDevSubService;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.Comparator;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author caozehui
|
* @author caozehui
|
||||||
* @date 2025-07-04
|
* @date 2025-07-04
|
||||||
@@ -17,4 +24,18 @@ import org.springframework.stereotype.Service;
|
|||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class PqDevSubServiceImpl extends ServiceImpl<PqDevSubMapper, PqDevSub> implements IPqDevSubService {
|
public class PqDevSubServiceImpl extends ServiceImpl<PqDevSubMapper, PqDevSub> implements IPqDevSubService {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public LocalDateTime resolveBatchMaxCheckEndTime(List<String> devIds) {
|
||||||
|
if (CollUtil.isEmpty(devIds)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return this.list(new LambdaQueryWrapper<PqDevSub>()
|
||||||
|
.in(PqDevSub::getDevId, devIds)
|
||||||
|
.isNotNull(PqDevSub::getCheckEndTime))
|
||||||
|
.stream()
|
||||||
|
.map(PqDevSub::getCheckEndTime)
|
||||||
|
.filter(Objects::nonNull)
|
||||||
|
.max(Comparator.naturalOrder())
|
||||||
|
.orElse(null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,181 @@
|
|||||||
|
package com.njcn.gather.device.util;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import javax.imageio.IIOImage;
|
||||||
|
import javax.imageio.ImageIO;
|
||||||
|
import javax.imageio.ImageWriteParam;
|
||||||
|
import javax.imageio.ImageWriter;
|
||||||
|
import javax.imageio.stream.ImageOutputStream;
|
||||||
|
import java.awt.Graphics2D;
|
||||||
|
import java.awt.RenderingHints;
|
||||||
|
import java.awt.image.BufferedImage;
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.util.Base64;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
|
public final class PqDevImageSupport {
|
||||||
|
|
||||||
|
private static final long MAX_FILE_SIZE = 10L * 1024L * 1024L;
|
||||||
|
private static final int MAX_EDGE = 1600;
|
||||||
|
private static final float JPEG_QUALITY = 0.82f;
|
||||||
|
|
||||||
|
private PqDevImageSupport() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ImageEchoPayload buildEchoPayload(byte[] imageBytes) {
|
||||||
|
if (imageBytes == null || imageBytes.length == 0) {
|
||||||
|
return new ImageEchoPayload(false, null, null);
|
||||||
|
}
|
||||||
|
return new ImageEchoPayload(true, Base64.getEncoder().encodeToString(imageBytes), detectContentType(imageBytes));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String detectContentType(byte[] imageBytes) {
|
||||||
|
if (imageBytes == null || imageBytes.length < 4) {
|
||||||
|
throw new IllegalArgumentException("图片内容无效");
|
||||||
|
}
|
||||||
|
if (isPng(imageBytes)) {
|
||||||
|
return "image/png";
|
||||||
|
}
|
||||||
|
if (isJpeg(imageBytes)) {
|
||||||
|
return "image/jpeg";
|
||||||
|
}
|
||||||
|
throw new IllegalArgumentException("仅支持 JPG、PNG 图片");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static byte[] processUpload(MultipartFile image) throws IOException {
|
||||||
|
if (image == null || image.isEmpty()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (image.getSize() > MAX_FILE_SIZE) {
|
||||||
|
throw new IllegalArgumentException("图片大小不能超过 10MB");
|
||||||
|
}
|
||||||
|
|
||||||
|
String normalizedName = normalize(image.getOriginalFilename());
|
||||||
|
String normalizedContentType = normalize(image.getContentType());
|
||||||
|
boolean allowedType = normalizedContentType.equals("image/jpeg")
|
||||||
|
|| normalizedContentType.equals("image/png")
|
||||||
|
|| normalizedName.endsWith(".jpg")
|
||||||
|
|| normalizedName.endsWith(".jpeg")
|
||||||
|
|| normalizedName.endsWith(".png");
|
||||||
|
if (!allowedType) {
|
||||||
|
throw new IllegalArgumentException("仅支持 JPG、PNG 图片");
|
||||||
|
}
|
||||||
|
|
||||||
|
byte[] originalBytes = image.getBytes();
|
||||||
|
String contentType = detectContentType(originalBytes);
|
||||||
|
BufferedImage source;
|
||||||
|
try (InputStream inputStream = image.getInputStream()) {
|
||||||
|
source = ImageIO.read(inputStream);
|
||||||
|
}
|
||||||
|
if (source == null) {
|
||||||
|
throw new IllegalArgumentException("图片内容无效");
|
||||||
|
}
|
||||||
|
|
||||||
|
BufferedImage target = scaleIfNeeded(source);
|
||||||
|
if ("image/png".equals(contentType)) {
|
||||||
|
return writePng(target);
|
||||||
|
}
|
||||||
|
return writeJpeg(target);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getExtension(String contentType) {
|
||||||
|
return "image/png".equals(contentType) ? "png" : "jpg";
|
||||||
|
}
|
||||||
|
|
||||||
|
private static BufferedImage scaleIfNeeded(BufferedImage source) {
|
||||||
|
int width = source.getWidth();
|
||||||
|
int height = source.getHeight();
|
||||||
|
int max = Math.max(width, height);
|
||||||
|
if (max <= MAX_EDGE) {
|
||||||
|
return source;
|
||||||
|
}
|
||||||
|
|
||||||
|
double scale = (double) MAX_EDGE / max;
|
||||||
|
int targetWidth = Math.max(1, (int) Math.round(width * scale));
|
||||||
|
int targetHeight = Math.max(1, (int) Math.round(height * scale));
|
||||||
|
int type = source.getType() == BufferedImage.TYPE_CUSTOM ? BufferedImage.TYPE_INT_ARGB : source.getType();
|
||||||
|
BufferedImage target = new BufferedImage(targetWidth, targetHeight, type);
|
||||||
|
Graphics2D graphics = target.createGraphics();
|
||||||
|
try {
|
||||||
|
graphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
|
||||||
|
graphics.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
|
||||||
|
graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
||||||
|
graphics.drawImage(source, 0, 0, targetWidth, targetHeight, null);
|
||||||
|
} finally {
|
||||||
|
graphics.dispose();
|
||||||
|
}
|
||||||
|
return target;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static byte[] writePng(BufferedImage image) throws IOException {
|
||||||
|
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||||
|
ImageIO.write(image, "png", outputStream);
|
||||||
|
return outputStream.toByteArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static byte[] writeJpeg(BufferedImage image) throws IOException {
|
||||||
|
BufferedImage rgbImage = new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_INT_RGB);
|
||||||
|
Graphics2D graphics = rgbImage.createGraphics();
|
||||||
|
try {
|
||||||
|
graphics.drawImage(image, 0, 0, null);
|
||||||
|
} finally {
|
||||||
|
graphics.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
Iterator<ImageWriter> writers = ImageIO.getImageWritersByFormatName("jpg");
|
||||||
|
if (!writers.hasNext()) {
|
||||||
|
throw new IOException("未找到 JPG 图片编码器");
|
||||||
|
}
|
||||||
|
ImageWriter writer = writers.next();
|
||||||
|
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||||
|
try (ImageOutputStream imageOutputStream = ImageIO.createImageOutputStream(outputStream)) {
|
||||||
|
writer.setOutput(imageOutputStream);
|
||||||
|
ImageWriteParam writeParam = writer.getDefaultWriteParam();
|
||||||
|
if (writeParam.canWriteCompressed()) {
|
||||||
|
writeParam.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
|
||||||
|
writeParam.setCompressionQuality(JPEG_QUALITY);
|
||||||
|
}
|
||||||
|
writer.write(null, new IIOImage(rgbImage, null, null), writeParam);
|
||||||
|
} finally {
|
||||||
|
writer.dispose();
|
||||||
|
}
|
||||||
|
return outputStream.toByteArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean isPng(byte[] imageBytes) {
|
||||||
|
return imageBytes.length >= 8
|
||||||
|
&& (imageBytes[0] & 0xFF) == 0x89
|
||||||
|
&& imageBytes[1] == 0x50
|
||||||
|
&& imageBytes[2] == 0x4E
|
||||||
|
&& imageBytes[3] == 0x47
|
||||||
|
&& imageBytes[4] == 0x0D
|
||||||
|
&& imageBytes[5] == 0x0A
|
||||||
|
&& imageBytes[6] == 0x1A
|
||||||
|
&& imageBytes[7] == 0x0A;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean isJpeg(byte[] imageBytes) {
|
||||||
|
return imageBytes.length >= 3
|
||||||
|
&& (imageBytes[0] & 0xFF) == 0xFF
|
||||||
|
&& (imageBytes[1] & 0xFF) == 0xD8
|
||||||
|
&& (imageBytes[2] & 0xFF) == 0xFF;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String normalize(String value) {
|
||||||
|
return value == null ? "" : value.toLowerCase(Locale.ROOT);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
public static class ImageEchoPayload {
|
||||||
|
private boolean hasImage;
|
||||||
|
private String imageBase64;
|
||||||
|
private String imageContentType;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,13 +1,16 @@
|
|||||||
package com.njcn.gather.icd.controller;
|
package com.njcn.gather.icd.controller;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
import com.njcn.common.pojo.exception.BusinessException;
|
||||||
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.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;
|
||||||
@@ -18,12 +21,20 @@ 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.multipart.MultipartFile;
|
||||||
|
import org.springframework.web.util.UriUtils;
|
||||||
|
|
||||||
|
import javax.validation.Valid;
|
||||||
|
import java.time.LocalDate;
|
||||||
|
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 +49,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 +71,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(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 +83,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(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 +115,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 +148,70 @@ 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));
|
||||||
|
}
|
||||||
|
|
||||||
|
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||||
|
@PostMapping("/export/json")
|
||||||
|
@ApiOperation("导出icd json")
|
||||||
|
@ApiImplicitParam(name = "ids", value = "id集合", required = true)
|
||||||
|
public ResponseEntity<ByteArrayResource> exportJson(@RequestBody List<String> ids) {
|
||||||
|
byte[] body = pqIcdPathService.exportIcdJson(ids);
|
||||||
|
String fileName = UriUtils.encode(LocalDate.now() + ".json", StandardCharsets.UTF_8);
|
||||||
|
return ResponseEntity.ok()
|
||||||
|
.header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename*=UTF-8''" + fileName)
|
||||||
|
.contentType(MediaType.APPLICATION_JSON)
|
||||||
|
.contentLength(body.length)
|
||||||
|
.body(new ByteArrayResource(body));
|
||||||
|
}
|
||||||
|
|
||||||
|
@OperateInfo(info = LogEnum.BUSINESS_COMMON, operateType = OperateType.ADD)
|
||||||
|
@PostMapping("/import/json")
|
||||||
|
@ApiOperation("导入icd json")
|
||||||
|
@ApiImplicitParam(name = "file", value = "json文件", required = true)
|
||||||
|
public HttpResult<Boolean> importJson(@RequestParam("file") MultipartFile file) {
|
||||||
|
String methodDescribe = getMethodDescribe("importJson");
|
||||||
|
LogUtil.njcnDebug(log, "{},导入文件为:{}", methodDescribe, file == null ? null : file.getOriginalFilename());
|
||||||
|
|
||||||
|
List<PqIcdPathParam.ExternalCreateParam> param = parseExternalCreateParams(file);
|
||||||
|
boolean result = pqIcdPathService.addUpstreamIcd(param);
|
||||||
|
if (result) {
|
||||||
|
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, methodDescribe);
|
||||||
|
} else {
|
||||||
|
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, false, methodDescribe);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<PqIcdPathParam.ExternalCreateParam> parseExternalCreateParams(MultipartFile file) {
|
||||||
|
if (file == null || file.isEmpty()) {
|
||||||
|
throw new BusinessException(IcdResponseEnum.ICD_FILE_NOT_NULL);
|
||||||
|
}
|
||||||
|
String fileName = file.getOriginalFilename();
|
||||||
|
if (fileName == null || !fileName.toLowerCase().endsWith(".json")) {
|
||||||
|
throw new BusinessException(IcdResponseEnum.JSON_FORMAT_ERROR);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
String content = new String(file.getBytes(), StandardCharsets.UTF_8);
|
||||||
|
List<PqIcdPathParam.ExternalCreateParam> params = JSON.parseArray(content, PqIcdPathParam.ExternalCreateParam.class);
|
||||||
|
if (params == null) {
|
||||||
|
throw new BusinessException(IcdResponseEnum.JSON_FORMAT_ERROR);
|
||||||
|
}
|
||||||
|
return params;
|
||||||
|
} catch (BusinessException ex) {
|
||||||
|
throw ex;
|
||||||
|
} catch (Exception ex) {
|
||||||
|
throw new BusinessException(IcdResponseEnum.JSON_FORMAT_ERROR);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,9 +1,13 @@
|
|||||||
package com.njcn.gather.icd.mapper;
|
package com.njcn.gather.icd.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.github.yulichang.base.MPJBaseMapper;
|
import com.github.yulichang.base.MPJBaseMapper;
|
||||||
import com.njcn.gather.icd.pojo.po.PqIcdPath;
|
import com.njcn.gather.icd.pojo.po.PqIcdPath;
|
||||||
|
import com.njcn.gather.icd.pojo.vo.PqIcdExportJsonVO;
|
||||||
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 +21,21 @@ 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);
|
||||||
|
|
||||||
|
List<PqIcdExportJsonVO> selectExportJsonByIds(@Param("ids") List<String> ids);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,10 +4,135 @@
|
|||||||
|
|
||||||
|
|
||||||
<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>
|
||||||
|
|
||||||
|
<select id="selectExportJsonByIds" resultType="com.njcn.gather.icd.pojo.vo.PqIcdExportJsonVO">
|
||||||
|
select id,
|
||||||
|
name,
|
||||||
|
Icd as rawIcd,
|
||||||
|
angle,
|
||||||
|
use_phase_index as usePhaseIndex,
|
||||||
|
Json_Str as jsonStr,
|
||||||
|
Xml_Str as xmlStr,
|
||||||
|
Result as result,
|
||||||
|
Msg as msg,
|
||||||
|
Type as type,
|
||||||
|
Reference_Icd_Id as referenceIcdId
|
||||||
|
from pq_icd_path
|
||||||
|
where state = 1
|
||||||
|
and id in
|
||||||
|
<foreach collection="ids" item="id" open="(" separator="," close=")">
|
||||||
|
#{id}
|
||||||
|
</foreach>
|
||||||
|
</select>
|
||||||
</mapper>
|
</mapper>
|
||||||
|
|
||||||
|
|||||||
@@ -1,16 +1,45 @@
|
|||||||
package com.njcn.gather.icd.pojo.enums;
|
package com.njcn.gather.icd.pojo.enums;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author caozehui
|
* @author caozehui
|
||||||
* @data 2025-11-11
|
* @data 2025-11-11
|
||||||
*/
|
*/
|
||||||
|
@Getter
|
||||||
public enum IcdResponseEnum {
|
public enum IcdResponseEnum {
|
||||||
FILE_NOT_NULL("A018001", "映射文件不能为空"),
|
FILE_NOT_NULL("A018001", "映射文件不能为空"),
|
||||||
FILE_TYPE_ERROR("A018002", "映射文件类型错误"),
|
FILE_TYPE_ERROR("A018002", "映射文件类型错误"),
|
||||||
FILE_SIZE_ERROR("A018003", "映射文件大小超出限制");
|
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名称不存在"),
|
||||||
|
EXTERNAL_ICD_ITEM_NOT_NULL("A018022", "导入数据项不能为空"),
|
||||||
|
EXTERNAL_ICD_ID_REPEAT("A018023", "导入数据中存在重复id"),
|
||||||
|
EXTERNAL_ICD_DELETED_NOT_ALLOW_OVERWRITE("A018024", "该ICD已删除,不允许通过导入覆盖"),
|
||||||
|
EXTERNAL_ICD_IMPORT_FAILED("A018025", "ICD导入失败"),
|
||||||
|
ANGLE_NOT_NULL("A018026", "是否支持相角不能为空"),
|
||||||
|
ANGLE_VALUE_ERROR("A018027", "是否支持相角取值错误"),
|
||||||
|
USE_PHASE_INDEX_NOT_NULL("A018028", "是否使用相别指标不能为空"),
|
||||||
|
USE_PHASE_INDEX_VALUE_ERROR("A018029", "是否使用相别指标取值错误");
|
||||||
|
|
||||||
private String code;
|
private final String code;
|
||||||
private String message;
|
private final String message;
|
||||||
|
|
||||||
IcdResponseEnum(String code, String message) {
|
IcdResponseEnum(String code, String message) {
|
||||||
this.code = code;
|
this.code = code;
|
||||||
|
|||||||
@@ -17,39 +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 = "映射文件", required = true)
|
@ApiModelProperty(value = "jsonStr")
|
||||||
private MultipartFile mappingFile;
|
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 = "icd", required = true)
|
||||||
|
@NotBlank(message = IcdExternalValidMessage.ICD_FILE_NOT_BLANK)
|
||||||
|
private String icd;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 更新参数
|
|
||||||
*/
|
|
||||||
@Data
|
@Data
|
||||||
@EqualsAndHashCode(callSuper = true)
|
@EqualsAndHashCode(callSuper = true)
|
||||||
public static class UpdateParam extends PqIcdPathParam {
|
public static class UpdateParam extends PqIcdPathParam {
|
||||||
@@ -57,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原始文件不能为空";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,11 +28,6 @@ public class PqIcdPath extends BaseEntity implements Serializable {
|
|||||||
*/
|
*/
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
/**
|
|
||||||
* icd存储地址
|
|
||||||
*/
|
|
||||||
private String path;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 状态:0-删除 1-正常
|
* 状态:0-删除 1-正常
|
||||||
*/
|
*/
|
||||||
@@ -46,19 +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)
|
@TableField(exist = false)
|
||||||
private FileVO mappingFile;
|
private String referenceIcdName;
|
||||||
|
|
||||||
@Data
|
@TableField(exist = false)
|
||||||
public static class FileVO{
|
private Boolean hasIcdFile;
|
||||||
private String name;
|
|
||||||
|
|
||||||
private String url;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,38 @@
|
|||||||
|
package com.njcn.gather.icd.pojo.vo;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.annotation.JSONField;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ICD JSON export item.
|
||||||
|
*
|
||||||
|
* @author caozehui
|
||||||
|
* @date 2026-06-17
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class PqIcdExportJsonVO {
|
||||||
|
private String id;
|
||||||
|
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
@JSONField(serialize = false)
|
||||||
|
private byte[] rawIcd;
|
||||||
|
|
||||||
|
private String icd;
|
||||||
|
|
||||||
|
private Integer angle;
|
||||||
|
|
||||||
|
private Integer usePhaseIndex;
|
||||||
|
|
||||||
|
private String jsonStr;
|
||||||
|
|
||||||
|
private String xmlStr;
|
||||||
|
|
||||||
|
private Integer result;
|
||||||
|
|
||||||
|
private String msg;
|
||||||
|
|
||||||
|
private Integer type;
|
||||||
|
|
||||||
|
private String referenceIcdId;
|
||||||
|
}
|
||||||
@@ -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,24 @@ 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);
|
||||||
|
|
||||||
|
byte[] exportIcdJson(List<String> ids);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据设备类型id获取Icd
|
* 根据设备类型id获取Icd
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -1,34 +1,42 @@
|
|||||||
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.ObjectUtil;
|
||||||
|
import cn.hutool.core.util.ReUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.alibaba.fastjson.JSON;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
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.common.pojo.constant.PatternRegex;
|
||||||
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.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.pojo.vo.PqIcdExportJsonVO;
|
||||||
|
import com.njcn.gather.pojo.constant.DetectionValidMessage;
|
||||||
import com.njcn.gather.icd.service.IPqIcdPathService;
|
import com.njcn.gather.icd.service.IPqIcdPathService;
|
||||||
import com.njcn.gather.pojo.enums.DetectionResponseEnum;
|
import com.njcn.gather.icd.service.support.IcdArchiveBuilder;
|
||||||
import com.njcn.gather.report.pojo.enums.ReportResponseEnum;
|
import com.njcn.gather.icd.service.support.IcdPayloadAssembler;
|
||||||
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 org.springframework.web.multipart.MultipartFile;
|
|
||||||
|
|
||||||
import java.io.BufferedOutputStream;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileOutputStream;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
|
import java.nio.file.StandardOpenOption;
|
||||||
|
import java.util.Base64;
|
||||||
|
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
|
||||||
@@ -38,174 +46,165 @@ 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);
|
|
||||||
String commInstallPath = this.getCommInstallPath();
|
|
||||||
page.getRecords().forEach(pqIcdPath -> {
|
|
||||||
PqIcdPath.FileVO fileVO = new PqIcdPath.FileVO();
|
|
||||||
fileVO.setUrl(commInstallPath + "\\DeviceControl\\Config\\" + pqIcdPath.getName() + ".txt");
|
|
||||||
fileVO.setName(pqIcdPath.getName() + ".txt");
|
|
||||||
pqIcdPath.setMappingFile(fileVO);
|
|
||||||
});
|
|
||||||
return page;
|
return page;
|
||||||
}
|
}
|
||||||
|
|
||||||
@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) {
|
||||||
|
writeIcdTextFile(resolveIcdTxtDir(), pqIcdPath.getName(), pqIcdPath.getJsonStr());
|
||||||
String commInstallPath = this.getCommInstallPath();
|
|
||||||
System.out.println("commInstallPath = " + commInstallPath);
|
|
||||||
long FILE_SIZE_LIMIT = 1 * 1024 * 1024;
|
|
||||||
MultipartFile mappingFile = param.getMappingFile();
|
|
||||||
|
|
||||||
System.out.println("mappingFile = " + ObjectUtil.isNotNull(mappingFile) + " " + !mappingFile.isEmpty());
|
|
||||||
if (ObjectUtil.isNotNull(mappingFile) && !mappingFile.isEmpty()) {
|
|
||||||
String mappingFilename = mappingFile.getOriginalFilename();
|
|
||||||
|
|
||||||
if (!mappingFilename.endsWith(".txt")) {
|
|
||||||
throw new BusinessException(IcdResponseEnum.FILE_TYPE_ERROR);
|
|
||||||
}
|
}
|
||||||
if (mappingFile.getSize() > FILE_SIZE_LIMIT) {
|
return saved;
|
||||||
throw new BusinessException(IcdResponseEnum.FILE_SIZE_ERROR);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
@Override
|
||||||
// 如果文件存在,则先删除
|
@Transactional
|
||||||
String mappingFilePath = commInstallPath + "\\DeviceControl\\Config\\" + mappingFilename;
|
public boolean addUpstreamIcd(List<PqIcdPathParam.ExternalCreateParam> param) {
|
||||||
System.out.println("mappingFilePath = " + mappingFilePath);
|
if (CollUtil.isEmpty(param)) {
|
||||||
Path path = Paths.get(mappingFilePath);
|
return true;
|
||||||
File file = path.toFile();
|
|
||||||
if (file.exists()) {
|
|
||||||
file.delete();
|
|
||||||
}
|
}
|
||||||
|
validateExternalItems(param);
|
||||||
// 保存文件
|
Set<String> requestStandardIds = collectRequestStandardIds(param);
|
||||||
byte[] bytes = mappingFile.getBytes();
|
Path directory = resolveIcdTxtDir();
|
||||||
BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(new FileOutputStream(mappingFilePath));
|
for (PqIcdPathParam.ExternalCreateParam item : param) {
|
||||||
bufferedOutputStream.write(bytes);
|
validateBusinessFields(item, null);
|
||||||
bufferedOutputStream.flush();
|
PqIcdPath current = this.baseMapper.selectById(item.getId());
|
||||||
|
if (current != null && !ObjectUtil.equals(current.getState(), DataStateEnum.ENABLE.getCode())) {
|
||||||
bufferedOutputStream.close();
|
throw new BusinessException(IcdResponseEnum.EXTERNAL_ICD_DELETED_NOT_ALLOW_OVERWRITE);
|
||||||
System.out.println("File saved successfully");
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new BusinessException(ReportResponseEnum.FILE_UPLOAD_FAILED);
|
|
||||||
}
|
}
|
||||||
|
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) {
|
||||||
|
throw new BusinessException(IcdResponseEnum.EXTERNAL_ICD_IMPORT_FAILED);
|
||||||
|
}
|
||||||
|
if (current == null) {
|
||||||
|
writeIcdTextFile(directory, pqIcdPath.getName(), pqIcdPath.getJsonStr());
|
||||||
} else {
|
} else {
|
||||||
System.out.println("mappingFile is null or empty");
|
syncUpdatedIcdTextFile(directory, oldName, pqIcdPath.getName(), pqIcdPath.getJsonStr());
|
||||||
throw new BusinessException(IcdResponseEnum.FILE_NOT_NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.executeRestartCmd(commInstallPath);
|
|
||||||
|
|
||||||
return this.save(pqIcdPath);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 执行重启通讯服务脚本
|
|
||||||
*
|
|
||||||
* @param commInstallPath
|
|
||||||
*/
|
|
||||||
private void executeRestartCmd(String commInstallPath) {
|
|
||||||
// 以管理员身份运行bat脚本
|
|
||||||
String batFilePath = commInstallPath + "\\重启所有服务.bat";
|
|
||||||
try {
|
|
||||||
Runtime.getRuntime().exec(batFilePath);
|
|
||||||
} catch (IOException e) {
|
|
||||||
log.error("重启通讯服务失败", e);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
private String getCommInstallPath() {
|
|
||||||
String workDir = System.getProperty("user.dir");
|
|
||||||
// String workDir = "D:\\program\\CN_Gather";
|
|
||||||
// 获取映射文件存放文件夹
|
|
||||||
String dirPath = workDir + "\\9100";
|
|
||||||
int index = workDir.indexOf("\\resources\\extraResources\\java");
|
|
||||||
if (index != -1) {
|
|
||||||
dirPath = workDir.substring(0, workDir.indexOf("\\resources\\extraResources\\java")) + "\\9100";
|
|
||||||
}
|
|
||||||
return dirPath;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional
|
@Transactional
|
||||||
public boolean updateIcd(PqIcdPathParam.UpdateParam param) {
|
public boolean updateIcd(PqIcdPathParam.UpdateParam param) {
|
||||||
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);
|
||||||
|
validateReferenceIcd(pqIcdPath.getType(), pqIcdPath.getReferenceIcdId(), current.getId());
|
||||||
String commInstallPath = this.getCommInstallPath();
|
boolean updated = this.updateById(pqIcdPath);
|
||||||
long FILE_SIZE_LIMIT = 1 * 1024 * 1024;
|
if (updated) {
|
||||||
MultipartFile mappingFile = param.getMappingFile();
|
syncUpdatedIcdTextFile(resolveIcdTxtDir(), oldName, pqIcdPath.getName(), pqIcdPath.getJsonStr());
|
||||||
if (ObjectUtil.isNotNull(mappingFile) && !mappingFile.isEmpty()) {
|
|
||||||
String mappingFilename = mappingFile.getOriginalFilename();
|
|
||||||
|
|
||||||
if (!mappingFilename.endsWith(".txt")) {
|
|
||||||
throw new BusinessException(IcdResponseEnum.FILE_TYPE_ERROR);
|
|
||||||
}
|
}
|
||||||
if (mappingFile.getSize() > FILE_SIZE_LIMIT) {
|
return updated;
|
||||||
throw new BusinessException(IcdResponseEnum.FILE_SIZE_ERROR);
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
// 如果文件存在,则先删除
|
|
||||||
String mappingFilePath = commInstallPath + "\\DeviceControl\\Config\\" + mappingFilename;
|
|
||||||
Path path = Paths.get(mappingFilePath);
|
|
||||||
File file = path.toFile();
|
|
||||||
if (file.exists()) {
|
|
||||||
file.delete();
|
|
||||||
}
|
|
||||||
|
|
||||||
// 保存文件
|
|
||||||
byte[] bytes = mappingFile.getBytes();
|
|
||||||
BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(new FileOutputStream(mappingFilePath));
|
|
||||||
bufferedOutputStream.write(bytes);
|
|
||||||
bufferedOutputStream.flush();
|
|
||||||
|
|
||||||
bufferedOutputStream.close();
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new BusinessException(ReportResponseEnum.FILE_UPLOAD_FAILED);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
this.executeRestartCmd(commInstallPath);
|
|
||||||
|
|
||||||
return this.updateById(pqIcdPath);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional
|
@Transactional
|
||||||
public boolean deleteIcd(List<String> ids) {
|
public boolean deleteIcd(List<String> ids) {
|
||||||
List<PqIcdPath> pqIcdPaths = this.listByIds(ids);
|
if (CollUtil.isEmpty(ids)) {
|
||||||
String commInstallPath = this.getCommInstallPath();
|
return true;
|
||||||
pqIcdPaths.forEach(pqIcdPath -> {
|
}
|
||||||
String mappingFilePath = commInstallPath + "\\DeviceControl\\Config\\" + pqIcdPath.getName() + ".txt";
|
List<PqIcdPath> pqIcdPaths = this.baseMapper.selectByIdsWithoutBlob(ids);
|
||||||
Path path = Paths.get(mappingFilePath);
|
List<String> standardIds = pqIcdPaths.stream()
|
||||||
File file = path.toFile();
|
.filter(pqIcdPath -> ObjectUtil.equals(pqIcdPath.getType(), TYPE_STANDARD))
|
||||||
if (file.exists()) {
|
.map(PqIcdPath::getId)
|
||||||
file.delete();
|
.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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
|
||||||
return this.lambdaUpdate().in(PqIcdPath::getId, ids).set(PqIcdPath::getState, DataStateEnum.DELETED.getCode()).update();
|
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
|
||||||
|
public byte[] exportIcdJson(List<String> ids) {
|
||||||
|
if (CollUtil.isEmpty(ids)) {
|
||||||
|
throw new BusinessException(IcdResponseEnum.ICD_NOT_FOUND);
|
||||||
|
}
|
||||||
|
List<PqIcdExportJsonVO> details = this.baseMapper.selectExportJsonByIds(ids);
|
||||||
|
if (CollUtil.isEmpty(details)) {
|
||||||
|
throw new BusinessException(IcdResponseEnum.ICD_NOT_FOUND);
|
||||||
|
}
|
||||||
|
for (PqIcdExportJsonVO detail : details) {
|
||||||
|
detail.setIcd(encodeIcdFile(detail.getRawIcd()));
|
||||||
|
normalizeExportDetail(detail);
|
||||||
|
}
|
||||||
|
return JSON.toJSONString(details).getBytes(StandardCharsets.UTF_8);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -213,18 +212,188 @@ 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 (ObjectUtil.equals(param.getResult(), RESULT_NO) && StrUtil.isBlank(param.getMsg())) {
|
||||||
if (param instanceof PqIcdPathParam.UpdateParam) {
|
throw new BusinessException(IcdResponseEnum.MSG_NOT_BLANK);
|
||||||
wrapper.ne(PqIcdPath::getId, ((PqIcdPathParam.UpdateParam) param).getId());
|
}
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
int count = this.count(wrapper);
|
|
||||||
if (count > 0) {
|
private void validateReferenceIcd(Integer type, String referenceIcdId, String currentId) {
|
||||||
throw new BusinessException(DetectionResponseEnum.ICD_PATH_NAME_REPEAT);
|
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 void validateExternalItems(List<PqIcdPathParam.ExternalCreateParam> params) {
|
||||||
|
Set<String> ids = new HashSet<>();
|
||||||
|
for (PqIcdPathParam.ExternalCreateParam param : params) {
|
||||||
|
if (param == null) {
|
||||||
|
throw new BusinessException(IcdResponseEnum.EXTERNAL_ICD_ITEM_NOT_NULL);
|
||||||
|
}
|
||||||
|
validateExternalItem(param);
|
||||||
|
String trimmedId = StrUtil.trim(param.getId());
|
||||||
|
if (!ids.add(trimmedId)) {
|
||||||
|
throw new BusinessException(IcdResponseEnum.EXTERNAL_ICD_ID_REPEAT);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void validateExternalItem(PqIcdPathParam.ExternalCreateParam param) {
|
||||||
|
if (StrUtil.isBlank(param.getId())) {
|
||||||
|
throw new BusinessException(DetectionValidMessage.ID_NOT_BLANK);
|
||||||
|
}
|
||||||
|
if (!ReUtil.isMatch(PatternRegex.SYSTEM_ID, StrUtil.trim(param.getId()))) {
|
||||||
|
throw new BusinessException(DetectionValidMessage.ID_FORMAT_ERROR);
|
||||||
|
}
|
||||||
|
if (StrUtil.isBlank(param.getName())) {
|
||||||
|
throw new BusinessException(DetectionValidMessage.NAME_NOT_BLANK);
|
||||||
|
}
|
||||||
|
if (!ReUtil.isMatch(PatternRegex.SCRIPT_NAME_REGEX, StrUtil.trim(param.getName()))) {
|
||||||
|
throw new BusinessException(DetectionValidMessage.ICD_NAME_FORMAT_ERROR);
|
||||||
|
}
|
||||||
|
if (StrUtil.isBlank(param.getIcd())) {
|
||||||
|
throw new BusinessException(IcdResponseEnum.ICD_FILE_NOT_NULL);
|
||||||
|
}
|
||||||
|
if (ObjectUtil.isNull(param.getAngle())) {
|
||||||
|
throw new BusinessException(IcdResponseEnum.ANGLE_NOT_NULL);
|
||||||
|
}
|
||||||
|
if (!ObjectUtil.equals(param.getAngle(), 0) && !ObjectUtil.equals(param.getAngle(), 1)) {
|
||||||
|
throw new BusinessException(IcdResponseEnum.ANGLE_VALUE_ERROR);
|
||||||
|
}
|
||||||
|
if (ObjectUtil.isNull(param.getUsePhaseIndex())) {
|
||||||
|
throw new BusinessException(IcdResponseEnum.USE_PHASE_INDEX_NOT_NULL);
|
||||||
|
}
|
||||||
|
if (!ObjectUtil.equals(param.getUsePhaseIndex(), 0) && !ObjectUtil.equals(param.getUsePhaseIndex(), 1)) {
|
||||||
|
throw new BusinessException(IcdResponseEnum.USE_PHASE_INDEX_VALUE_ERROR);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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");
|
||||||
|
}
|
||||||
|
|
||||||
|
private String encodeIcdFile(byte[] rawValue) {
|
||||||
|
if (rawValue == null || rawValue.length == 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return Base64.getEncoder().encodeToString(rawValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void normalizeExportDetail(PqIcdExportJsonVO detail) {
|
||||||
|
detail.setRawIcd(null);
|
||||||
|
detail.setAngle(detail.getAngle() == null ? 0 : detail.getAngle());
|
||||||
|
detail.setUsePhaseIndex(detail.getUsePhaseIndex() == null ? 1 : detail.getUsePhaseIndex());
|
||||||
|
if (isStandardType(detail.getType())) {
|
||||||
|
detail.setType(TYPE_UPSTREAM_STANDARD);
|
||||||
|
detail.setReferenceIcdId(null);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
detail.setType(TYPE_UPSTREAM_NON_STANDARD);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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.getIcd());
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -99,7 +99,7 @@ public class PqMonitorServiceImpl extends ServiceImpl<PqMonitorMapper, PqMonitor
|
|||||||
this.baseMapper.updateDeviceReportRState(devId, DevReportStateEnum.NOT_GENERATED.getValue());
|
this.baseMapper.updateDeviceReportRState(devId, DevReportStateEnum.NOT_GENERATED.getValue());
|
||||||
}
|
}
|
||||||
if (enableCheckMonitorList.size() > checkedMonitorList.size() && checkedMonitorList.size() > 0) {
|
if (enableCheckMonitorList.size() > checkedMonitorList.size() && checkedMonitorList.size() > 0) {
|
||||||
this.baseMapper.updateDeviceCheckState(devId, CheckStateEnum.CHECKING.getValue());
|
this.baseMapper.updateDeviceCheckState(devId, CheckStateEnum.UNCHECKED.getValue());
|
||||||
this.baseMapper.updateDeviceReportRState(devId, DevReportStateEnum.NOT_GENERATED.getValue());
|
this.baseMapper.updateDeviceReportRState(devId, DevReportStateEnum.NOT_GENERATED.getValue());
|
||||||
}
|
}
|
||||||
if (enableCheckMonitorList.size() > 0 && checkedMonitorList.size() == 0) {
|
if (enableCheckMonitorList.size() > 0 && checkedMonitorList.size() == 0) {
|
||||||
@@ -142,13 +142,14 @@ public class PqMonitorServiceImpl extends ServiceImpl<PqMonitorMapper, PqMonitor
|
|||||||
List<PqDevSub> devSubList = this.baseMapper.listDevSubByPlanId(plan.getId());
|
List<PqDevSub> devSubList = this.baseMapper.listDevSubByPlanId(plan.getId());
|
||||||
|
|
||||||
List<PqDevSub> checkedDevSubList = devSubList.stream().filter(pqDevSub -> pqDevSub.getCheckState() == CheckStateEnum.CHECKED.getValue()).collect(Collectors.toList());
|
List<PqDevSub> checkedDevSubList = devSubList.stream().filter(pqDevSub -> pqDevSub.getCheckState() == CheckStateEnum.CHECKED.getValue()).collect(Collectors.toList());
|
||||||
List<PqDevSub> checkingDevSubList = devSubList.stream().filter(pqDevSub -> pqDevSub.getCheckState() == CheckStateEnum.CHECKING.getValue()).collect(Collectors.toList());
|
boolean allUnchecked = devSubList.stream().allMatch(pqDevSub -> CheckStateEnum.UNCHECKED.getValue().equals(pqDevSub.getCheckState()));
|
||||||
if (checkedDevSubList.size() == devSubList.size() && devSubList.size() > 0) {
|
boolean allArchived = devSubList.stream().allMatch(pqDevSub -> pqDevSub.getCheckState() != null && pqDevSub.getCheckState() >= CheckStateEnum.DOCUMENTED.getValue());
|
||||||
|
if (allArchived && CollUtil.isNotEmpty(devSubList)) {
|
||||||
this.baseMapper.updatePlanCheckState(plan.getId(), CheckStateEnum.CHECKED.getValue());
|
this.baseMapper.updatePlanCheckState(plan.getId(), CheckStateEnum.CHECKED.getValue());
|
||||||
} else if (checkedDevSubList.size() > 0 || checkingDevSubList.size() > 0) {
|
} else if (allUnchecked) {
|
||||||
this.baseMapper.updatePlanCheckState(plan.getId(), CheckStateEnum.CHECKING.getValue());
|
|
||||||
} else {
|
|
||||||
this.baseMapper.updatePlanCheckState(plan.getId(), CheckStateEnum.UNCHECKED.getValue());
|
this.baseMapper.updatePlanCheckState(plan.getId(), CheckStateEnum.UNCHECKED.getValue());
|
||||||
|
} else {
|
||||||
|
this.baseMapper.updatePlanCheckState(plan.getId(), CheckStateEnum.CHECKING.getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
List<PqDevSub> accordDevSubList = checkedDevSubList.stream().filter(pqDevSub -> pqDevSub.getCheckResult() == CheckResultEnum.ACCORD.getValue()).collect(Collectors.toList());
|
List<PqDevSub> accordDevSubList = checkedDevSubList.stream().filter(pqDevSub -> pqDevSub.getCheckResult() == CheckResultEnum.ACCORD.getValue()).collect(Collectors.toList());
|
||||||
@@ -372,10 +373,6 @@ public class PqMonitorServiceImpl extends ServiceImpl<PqMonitorMapper, PqMonitor
|
|||||||
|
|
||||||
if (checkedNumList.containsAll(allNumList)) {
|
if (checkedNumList.containsAll(allNumList)) {
|
||||||
return CheckStateEnum.CHECKED.getValue();
|
return CheckStateEnum.CHECKED.getValue();
|
||||||
} else {
|
|
||||||
if (checkedNumList.size() > 0) {
|
|
||||||
return CheckStateEnum.CHECKING.getValue();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return CheckStateEnum.UNCHECKED.getValue();
|
return CheckStateEnum.UNCHECKED.getValue();
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ import com.njcn.gather.device.service.IPqDevService;
|
|||||||
import com.njcn.gather.plan.pojo.param.AdPlanParam;
|
import com.njcn.gather.plan.pojo.param.AdPlanParam;
|
||||||
import com.njcn.gather.plan.pojo.po.AdPlan;
|
import com.njcn.gather.plan.pojo.po.AdPlan;
|
||||||
import com.njcn.gather.plan.pojo.vo.AdPlanVO;
|
import com.njcn.gather.plan.pojo.vo.AdPlanVO;
|
||||||
|
import com.njcn.gather.plan.pojo.vo.PlanStatisticsVO;
|
||||||
import com.njcn.gather.plan.service.AsyncPlanHandler;
|
import com.njcn.gather.plan.service.AsyncPlanHandler;
|
||||||
import com.njcn.gather.plan.service.IAdPlanService;
|
import com.njcn.gather.plan.service.IAdPlanService;
|
||||||
import com.njcn.gather.type.pojo.po.DevType;
|
import com.njcn.gather.type.pojo.po.DevType;
|
||||||
@@ -198,6 +199,17 @@ public class AdPlanController extends BaseController {
|
|||||||
adPlanService.analyse(ids);
|
adPlanService.analyse(ids);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||||
|
@PostMapping("/statistics")
|
||||||
|
@ApiOperation("检测计划统计")
|
||||||
|
@ApiImplicitParam(name = "param", value = "检测计划统计参数", required = true)
|
||||||
|
public HttpResult<PlanStatisticsVO> statistics(@RequestBody @Validated AdPlanParam.StatisticsParam param) {
|
||||||
|
String methodDescribe = getMethodDescribe("statistics");
|
||||||
|
LogUtil.njcnDebug(log, "{},查询数据为:{}", methodDescribe, param);
|
||||||
|
PlanStatisticsVO result = adPlanService.statistics(param);
|
||||||
|
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
|
||||||
|
}
|
||||||
|
|
||||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||||
@PostMapping("/listByPlanId")
|
@PostMapping("/listByPlanId")
|
||||||
@ApiOperation("查询出所有已绑定的设备")
|
@ApiOperation("查询出所有已绑定的设备")
|
||||||
|
|||||||
@@ -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,63 @@
|
|||||||
|
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,108 @@
|
|||||||
|
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 checkingDeviceCount;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 第一次检测合格的设备数量。
|
||||||
|
*/
|
||||||
|
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;
|
||||||
@@ -64,11 +65,11 @@ public class AsyncPlanHandler {
|
|||||||
|
|
||||||
private final JdbcTemplate jdbcTemplate;
|
private final JdbcTemplate jdbcTemplate;
|
||||||
|
|
||||||
|
private final PathConfig pathConfig;
|
||||||
@Value("${report.reportDir}")
|
// @Value("${report.reportDir}")
|
||||||
private String reportPath;
|
// private String reportPath;
|
||||||
@Value("${data.homeDir}")
|
// @Value("${data.homeDir}")
|
||||||
private String dataPath;
|
// private String dataPath;
|
||||||
|
|
||||||
private static final int BATCH_SIZE = 10000;
|
private static final int BATCH_SIZE = 10000;
|
||||||
private static final int FINAL_STEP = 85;
|
private static final int FINAL_STEP = 85;
|
||||||
@@ -199,13 +200,13 @@ public class AsyncPlanHandler {
|
|||||||
|
|
||||||
// 创建 ZIP 文件
|
// 创建 ZIP 文件
|
||||||
String zipFileName = plan.getName() + "_检测数据包.zip";
|
String zipFileName = plan.getName() + "_检测数据包.zip";
|
||||||
File zipFile = FileUtil.file(dataPath + File.separator + TEST_DATA_DIR + File.separator, zipFileName);
|
File zipFile = FileUtil.file(pathConfig.getDataPath() + File.separator + TEST_DATA_DIR + File.separator, zipFileName);
|
||||||
|
|
||||||
// 添加检测报告文件
|
// 添加检测报告文件
|
||||||
if (ObjectUtil.isNotNull(report) && report.equals(1)) {
|
if (ObjectUtil.isNotNull(report) && report.equals(1)) {
|
||||||
for (PqDev dev : devList) {
|
for (PqDev dev : devList) {
|
||||||
DevType devType = devTypeService.getById(dev.getDevType());
|
DevType devType = devTypeService.getById(dev.getDevType());
|
||||||
String dirPath = reportPath.concat(File.separator).concat(devType.getName());
|
String dirPath = pathConfig.getReportPath().concat(File.separator).concat(devType.getName());
|
||||||
File reportFile = new File(dirPath.concat(File.separator).concat(dev.getCreateId()).concat(ReportConstant.DOCX));
|
File reportFile = new File(dirPath.concat(File.separator).concat(dev.getCreateId()).concat(ReportConstant.DOCX));
|
||||||
// 如果reportFile存在,则将reportFile中的文件添加到已有的zip文件中
|
// 如果reportFile存在,则将reportFile中的文件添加到已有的zip文件中
|
||||||
if (FileUtil.exist(reportFile)) {
|
if (FileUtil.exist(reportFile)) {
|
||||||
@@ -344,7 +345,7 @@ public class AsyncPlanHandler {
|
|||||||
for (File docx : docxFiles) {
|
for (File docx : docxFiles) {
|
||||||
for (PqDev dev : devList) {
|
for (PqDev dev : devList) {
|
||||||
DevType devType = devTypeService.getById(dev.getDevType());
|
DevType devType = devTypeService.getById(dev.getDevType());
|
||||||
String dirPath = reportPath.concat(File.separator).concat(devType.getName());
|
String dirPath = pathConfig.getReportPath().concat(File.separator).concat(devType.getName());
|
||||||
File reportFile = new File(dirPath.concat(File.separator).concat(dev.getCreateId()).concat(ReportConstant.DOCX));
|
File reportFile = new File(dirPath.concat(File.separator).concat(dev.getCreateId()).concat(ReportConstant.DOCX));
|
||||||
// 文件名匹配,复制到对应目录下
|
// 文件名匹配,复制到对应目录下
|
||||||
if (docx.getName().equals(reportFile.getName())) {
|
if (docx.getName().equals(reportFile.getName())) {
|
||||||
@@ -435,21 +436,15 @@ public class AsyncPlanHandler {
|
|||||||
planIds.add(planId);
|
planIds.add(planId);
|
||||||
List<String> devIds = pqDevService.lambdaQuery().in(PqDev::getPlanId, planIds).list().stream().map(PqDev::getId).collect(Collectors.toList());
|
List<String> devIds = pqDevService.lambdaQuery().in(PqDev::getPlanId, planIds).list().stream().map(PqDev::getId).collect(Collectors.toList());
|
||||||
List<PqDevSub> devSubs = pqDevSubService.lambdaQuery().in(PqDevSub::getDevId, devIds).list();
|
List<PqDevSub> devSubs = pqDevSubService.lambdaQuery().in(PqDevSub::getDevId, devIds).list();
|
||||||
long checkedCount = devSubs.stream().filter(sub -> sub.getCheckState().equals(CheckStateEnum.CHECKED.getValue())).count();
|
boolean allUnchecked = devSubs.stream().allMatch(sub -> CheckStateEnum.UNCHECKED.getValue().equals(sub.getCheckState()));
|
||||||
if (checkedCount > 0) {
|
boolean allArchived = devSubs.stream().allMatch(sub -> sub.getCheckState() != null && sub.getCheckState() >= CheckStateEnum.DOCUMENTED.getValue());
|
||||||
plan.setTestState(CheckStateEnum.CHECKING.getValue());
|
if (allUnchecked) {
|
||||||
// 都已检测完成
|
|
||||||
if (checkedCount == devSubs.size()) {
|
|
||||||
plan.setTestState(CheckStateEnum.CHECKED.getValue());
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
plan.setTestState(CheckStateEnum.UNCHECKED.getValue());
|
plan.setTestState(CheckStateEnum.UNCHECKED.getValue());
|
||||||
// 是否有检测中
|
} else if (allArchived && !devSubs.isEmpty()) {
|
||||||
long checkingCount = devSubs.stream().filter(sub -> sub.getCheckState().equals(CheckStateEnum.CHECKING.getValue())).count();
|
plan.setTestState(CheckStateEnum.CHECKED.getValue());
|
||||||
if (checkingCount > 0) {
|
} else {
|
||||||
plan.setTestState(CheckStateEnum.CHECKING.getValue());
|
plan.setTestState(CheckStateEnum.CHECKING.getValue());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
adPlanService.updateById(plan);
|
adPlanService.updateById(plan);
|
||||||
LocalDateTime endTime = LocalDateTime.now();
|
LocalDateTime endTime = LocalDateTime.now();
|
||||||
log.info("数据合并完成,耗时:{}s", Duration.between(startTime, endTime).getSeconds());
|
log.info("数据合并完成,耗时:{}s", Duration.between(startTime, endTime).getSeconds());
|
||||||
|
|||||||
@@ -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()) || CheckStateEnum.DOCUMENTED.getValue().equals(pqDev.getCheckState())).count();
|
long count = pqDevVOList.stream().filter(pqDev -> pqDev.getCheckState() != null && pqDev.getCheckState() >= CheckStateEnum.CHECKED.getValue()).count();
|
||||||
adPlanVO.setProgress((float) count / pqDevVOList.size());
|
adPlanVO.setProgress((float) count / pqDevVOList.size());
|
||||||
} else {
|
} else {
|
||||||
adPlanVO.setProgress(0.0f);
|
adPlanVO.setProgress(0.0f);
|
||||||
@@ -396,10 +405,13 @@ public class AdPlanServiceImpl extends ServiceImpl<AdPlanMapper, AdPlan> impleme
|
|||||||
PqDevParam.QueryParam queryParam = new PqDevParam.QueryParam();
|
PqDevParam.QueryParam queryParam = new PqDevParam.QueryParam();
|
||||||
queryParam.setPlanIdList(Collections.singletonList(plan1.getId()));
|
queryParam.setPlanIdList(Collections.singletonList(plan1.getId()));
|
||||||
List<PqDevVO> pqDevVOS = pqDevService.listByPlanId(queryParam);
|
List<PqDevVO> pqDevVOS = pqDevService.listByPlanId(queryParam);
|
||||||
long checkedCount = pqDevVOS.stream().filter(pqDevVO -> pqDevVO.getCheckState().equals(CheckStateEnum.CHECKED.getValue())).count();
|
boolean allUnchecked = pqDevVOS.stream().allMatch(pqDevVO -> CheckStateEnum.UNCHECKED.getValue().equals(pqDevVO.getCheckState()));
|
||||||
if (checkedCount == pqDevVOS.size()) {
|
boolean allArchived = pqDevVOS.stream().allMatch(pqDevVO -> pqDevVO.getCheckState() != null && pqDevVO.getCheckState() >= CheckStateEnum.DOCUMENTED.getValue());
|
||||||
|
if (allUnchecked) {
|
||||||
|
plan1.setTestState(CheckStateEnum.UNCHECKED.getValue());
|
||||||
|
} else if (allArchived && !pqDevVOS.isEmpty()) {
|
||||||
plan1.setTestState(CheckStateEnum.CHECKED.getValue());
|
plan1.setTestState(CheckStateEnum.CHECKED.getValue());
|
||||||
} else if (checkedCount > 0) {
|
} else {
|
||||||
plan1.setTestState(CheckStateEnum.CHECKING.getValue());
|
plan1.setTestState(CheckStateEnum.CHECKING.getValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -555,6 +567,7 @@ public class AdPlanServiceImpl extends ServiceImpl<AdPlanMapper, AdPlan> impleme
|
|||||||
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("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());
|
||||||
@@ -809,6 +822,296 @@ 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());
|
||||||
|
int uncheckedDeviceCount = (int) planDevices.stream()
|
||||||
|
.filter(dev -> Objects.equals(dev.getCheckState(), CheckStateEnum.UNCHECKED.getValue()))
|
||||||
|
.count();
|
||||||
|
int checkingDeviceCount = (int) planDevices.stream()
|
||||||
|
.filter(dev -> Objects.equals(dev.getCheckState(), CheckStateEnum.CHECKING.getValue()))
|
||||||
|
.count();
|
||||||
|
PlanStatisticsVO statistics = new PlanStatisticsVO();
|
||||||
|
statistics.setPlanId(plan.getId());
|
||||||
|
statistics.setPlanName(plan.getName());
|
||||||
|
statistics.setManufacturerOptions(buildManufacturerOptions(allPlanDevices, param.getDevType()));
|
||||||
|
statistics.setDevTypeOptions(buildDevTypeOptions(allPlanDevices, param.getManufacturer()));
|
||||||
|
statistics.setUncheckedDeviceCount(uncheckedDeviceCount);
|
||||||
|
statistics.setCheckingDeviceCount(checkingDeviceCount);
|
||||||
|
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) {
|
||||||
|
Integer checkState = dev.getCheckState();
|
||||||
|
return checkState != null && checkState >= CheckStateEnum.CHECKED.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());
|
||||||
@@ -941,26 +1244,22 @@ public class AdPlanServiceImpl extends ServiceImpl<AdPlanMapper, AdPlan> impleme
|
|||||||
// 0-解绑、1-绑定
|
// 0-解绑、1-绑定
|
||||||
if (param.getBindFlag().equals(1)) {
|
if (param.getBindFlag().equals(1)) {
|
||||||
pqDevService.lambdaUpdate().set(PqDev::getPlanId, plan.getId()).in(PqDev::getId, param.getDevIds()).update();
|
pqDevService.lambdaUpdate().set(PqDev::getPlanId, plan.getId()).in(PqDev::getId, param.getDevIds()).update();
|
||||||
// 绑定被检设备,若检测计划已检测完成,则修改为检测中
|
|
||||||
if (plan.getTestState().equals(CheckStateEnum.CHECKED.getValue())) {
|
|
||||||
plan.setTestState(CheckStateEnum.CHECKING.getValue());
|
|
||||||
this.updateById(plan);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
pqDevService.lambdaUpdate().set(PqDev::getPlanId, plan.getFatherPlanId()).in(PqDev::getId, param.getDevIds()).update();
|
pqDevService.lambdaUpdate().set(PqDev::getPlanId, plan.getFatherPlanId()).in(PqDev::getId, param.getDevIds()).update();
|
||||||
// 解绑被检设备,若检测计划检测中,且所有设备已检测完成,则修改为检测完成
|
}
|
||||||
if (plan.getTestState().equals(CheckStateEnum.CHECKING.getValue())) {
|
|
||||||
PqDevParam.QueryParam queryParam = new PqDevParam.QueryParam();
|
PqDevParam.QueryParam queryParam = new PqDevParam.QueryParam();
|
||||||
queryParam.setPlanIdList(Collections.singletonList(plan.getId()));
|
queryParam.setPlanIdList(Collections.singletonList(plan.getId()));
|
||||||
List<PqDevVO> pqDevVOS = pqDevService.listByPlanId(queryParam);
|
List<PqDevVO> pqDevVOS = pqDevService.listByPlanId(queryParam);
|
||||||
long checkedCount = pqDevVOS.stream().filter(pqDevVO -> pqDevVO.getCheckState().equals(CheckStateEnum.CHECKED.getValue())).count();
|
boolean allUnchecked = pqDevVOS.stream().allMatch(pqDevVO -> CheckStateEnum.UNCHECKED.getValue().equals(pqDevVO.getCheckState()));
|
||||||
if (checkedCount == pqDevVOS.size()) {
|
boolean allArchived = pqDevVOS.stream().allMatch(pqDevVO -> pqDevVO.getCheckState() != null && pqDevVO.getCheckState() >= CheckStateEnum.DOCUMENTED.getValue());
|
||||||
|
if (allUnchecked) {
|
||||||
|
plan.setTestState(CheckStateEnum.UNCHECKED.getValue());
|
||||||
|
} else if (allArchived && !pqDevVOS.isEmpty()) {
|
||||||
plan.setTestState(CheckStateEnum.CHECKED.getValue());
|
plan.setTestState(CheckStateEnum.CHECKED.getValue());
|
||||||
|
} else {
|
||||||
|
plan.setTestState(CheckStateEnum.CHECKING.getValue());
|
||||||
|
}
|
||||||
this.updateById(plan);
|
this.updateById(plan);
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1265,7 +1564,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 + "";
|
||||||
@@ -1612,7 +1911,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);
|
||||||
@@ -2089,7 +2390,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)) {
|
||||||
|
|||||||
@@ -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.getCheckEndTime()) ? device.getCheckEndTime() : 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -75,7 +75,8 @@ public enum DetectionResponseEnum {
|
|||||||
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", "存在重复被检设备");
|
DEV_IP_PORT_EXIST("A02099", "存在重复被检设备"),
|
||||||
|
PQDIF_NOT_EXIST("A02100", "PQDIF不存在");
|
||||||
|
|
||||||
private final String code;
|
private final String code;
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,94 @@
|
|||||||
|
package com.njcn.gather.pqdif.controller;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
import com.njcn.common.pojo.annotation.OperateInfo;
|
||||||
|
import com.njcn.common.pojo.constant.OperateType;
|
||||||
|
import com.njcn.common.pojo.enums.common.LogEnum;
|
||||||
|
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
|
||||||
|
import com.njcn.common.pojo.exception.BusinessException;
|
||||||
|
import com.njcn.common.pojo.response.HttpResult;
|
||||||
|
import com.njcn.common.utils.LogUtil;
|
||||||
|
import com.njcn.gather.pqdif.pojo.enums.PqdifResponseEnum;
|
||||||
|
import com.njcn.gather.pqdif.pojo.param.PqPqdifPathParam;
|
||||||
|
import com.njcn.gather.pqdif.pojo.po.PqPqdifPath;
|
||||||
|
import com.njcn.gather.pqdif.service.IPqPqdifPathService;
|
||||||
|
import com.njcn.gather.pqdif.service.support.PqdifImportParser;
|
||||||
|
import com.njcn.web.controller.BaseController;
|
||||||
|
import com.njcn.web.utils.HttpResultUtil;
|
||||||
|
import io.swagger.annotations.Api;
|
||||||
|
import io.swagger.annotations.ApiImplicitParam;
|
||||||
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@Api(tags = "PQDIF管理")
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/pqdif")
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class PqPqdifPathController extends BaseController {
|
||||||
|
private final IPqPqdifPathService pqPqdifPathService;
|
||||||
|
|
||||||
|
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||||
|
@GetMapping("/listAll")
|
||||||
|
@ApiOperation("获取全部PQDIF")
|
||||||
|
public HttpResult<List<PqPqdifPath>> listAll() {
|
||||||
|
String methodDescribe = getMethodDescribe("listAll");
|
||||||
|
List<PqPqdifPath> result = pqPqdifPathService.listAll();
|
||||||
|
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
|
||||||
|
}
|
||||||
|
|
||||||
|
@OperateInfo
|
||||||
|
@PostMapping("/list")
|
||||||
|
@ApiOperation("分页查询PQDIF")
|
||||||
|
@ApiImplicitParam(name = "param", value = "查询参数", required = true)
|
||||||
|
public HttpResult<Page<PqPqdifPath>> list(@RequestBody @Validated PqPqdifPathParam.QueryParam param) {
|
||||||
|
String methodDescribe = getMethodDescribe("list");
|
||||||
|
LogUtil.njcnDebug(log, "{},查询数据为:{}", methodDescribe, param);
|
||||||
|
Page<PqPqdifPath> result = pqPqdifPathService.listPqdif(param);
|
||||||
|
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
|
||||||
|
}
|
||||||
|
|
||||||
|
@OperateInfo(info = LogEnum.BUSINESS_COMMON, operateType = OperateType.ADD)
|
||||||
|
@PostMapping("/import/json")
|
||||||
|
@ApiOperation("导入PQDIF json")
|
||||||
|
@ApiImplicitParam(name = "file", value = "json文件", required = true)
|
||||||
|
public HttpResult<Boolean> importJson(@RequestParam("file") MultipartFile file) {
|
||||||
|
String methodDescribe = getMethodDescribe("importJson");
|
||||||
|
LogUtil.njcnDebug(log, "{},导入文件为:{}", methodDescribe, file == null ? null : file.getOriginalFilename());
|
||||||
|
List<PqPqdifPathParam.ImportItem> items = parseImportItems(file);
|
||||||
|
boolean result = pqPqdifPathService.importPqdif(items);
|
||||||
|
if (result) {
|
||||||
|
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, methodDescribe);
|
||||||
|
}
|
||||||
|
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, false, methodDescribe);
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<PqPqdifPathParam.ImportItem> parseImportItems(MultipartFile file) {
|
||||||
|
if (file == null || file.isEmpty()) {
|
||||||
|
throw new BusinessException(PqdifResponseEnum.JSON_FILE_NOT_NULL);
|
||||||
|
}
|
||||||
|
String fileName = file.getOriginalFilename();
|
||||||
|
if (fileName == null || !fileName.toLowerCase().endsWith(".json")) {
|
||||||
|
throw new BusinessException(PqdifResponseEnum.JSON_FORMAT_ERROR);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
return PqdifImportParser.parse(new String(file.getBytes(), StandardCharsets.UTF_8));
|
||||||
|
} catch (BusinessException ex) {
|
||||||
|
throw ex;
|
||||||
|
} catch (Exception ex) {
|
||||||
|
throw new BusinessException(PqdifResponseEnum.JSON_FORMAT_ERROR);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
package com.njcn.gather.pqdif.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
import com.github.yulichang.base.MPJBaseMapper;
|
||||||
|
import com.njcn.gather.pqdif.pojo.po.PqPqdifPath;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public interface PqPqdifPathMapper extends MPJBaseMapper<PqPqdifPath> {
|
||||||
|
List<PqPqdifPath> selectPageList(Page<PqPqdifPath> page, @Param("name") String name, @Param("result") Integer result);
|
||||||
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
<?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.pqdif.mapper.PqPqdifPathMapper">
|
||||||
|
<select id="selectPageList" resultType="com.njcn.gather.pqdif.pojo.po.PqPqdifPath">
|
||||||
|
select id,
|
||||||
|
Name as name,
|
||||||
|
File_Path as filePath,
|
||||||
|
Record_Count as recordCount,
|
||||||
|
Observation_Count as observationCount,
|
||||||
|
Sample_Value_Count as sampleValueCount,
|
||||||
|
Result as result,
|
||||||
|
Msg as msg,
|
||||||
|
State as state,
|
||||||
|
Create_By as createBy,
|
||||||
|
Create_Time as createTime,
|
||||||
|
Update_By as updateBy,
|
||||||
|
Update_Time as updateTime
|
||||||
|
from pq_pqdif_path
|
||||||
|
where State = 1
|
||||||
|
<if test="name != null and name != ''">
|
||||||
|
and Name like concat('%', #{name}, '%')
|
||||||
|
</if>
|
||||||
|
<if test="result != null">
|
||||||
|
and Result = #{result}
|
||||||
|
</if>
|
||||||
|
order by Update_Time desc, Create_Time desc
|
||||||
|
</select>
|
||||||
|
</mapper>
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
package com.njcn.gather.pqdif.pojo.enums;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
public enum PqdifResponseEnum {
|
||||||
|
JSON_FILE_NOT_NULL("A019001", "JSON文件不能为空"),
|
||||||
|
JSON_FORMAT_ERROR("A019002", "JSON格式错误"),
|
||||||
|
IMPORT_ITEM_NOT_NULL("A019003", "导入数据项不能为空"),
|
||||||
|
IMPORT_ID_REPEAT("A019004", "导入数据中存在重复id"),
|
||||||
|
IMPORT_FAILED("A019005", "PQDIF导入失败");
|
||||||
|
|
||||||
|
private final String code;
|
||||||
|
private final String message;
|
||||||
|
|
||||||
|
PqdifResponseEnum(String code, String message) {
|
||||||
|
this.code = code;
|
||||||
|
this.message = message;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
package com.njcn.gather.pqdif.pojo.param;
|
||||||
|
|
||||||
|
import com.njcn.web.pojo.param.BaseParam;
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class PqPqdifPathParam {
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
public static class QueryParam extends BaseParam {
|
||||||
|
@ApiModelProperty(value = "name")
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "result")
|
||||||
|
private Integer result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public static class ImportItem {
|
||||||
|
private String id;
|
||||||
|
private String name;
|
||||||
|
private String filePath;
|
||||||
|
private Long recordCount;
|
||||||
|
private Long observationCount;
|
||||||
|
private Integer sampleValueCount;
|
||||||
|
private Integer result;
|
||||||
|
private String msg;
|
||||||
|
private Integer state;
|
||||||
|
private Object parseResult;
|
||||||
|
private String createBy;
|
||||||
|
private String createTime;
|
||||||
|
private String updateBy;
|
||||||
|
private String updateTime;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
package com.njcn.gather.pqdif.pojo.po;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import com.njcn.db.mybatisplus.bo.BaseEntity;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
@TableName("pq_pqdif_path")
|
||||||
|
public class PqPqdifPath extends BaseEntity implements Serializable {
|
||||||
|
private static final long serialVersionUID = 2536904714178389110L;
|
||||||
|
|
||||||
|
private String id;
|
||||||
|
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
@TableField("File_Path")
|
||||||
|
private String filePath;
|
||||||
|
|
||||||
|
@TableField("Record_Count")
|
||||||
|
private Long recordCount;
|
||||||
|
|
||||||
|
@TableField("Observation_Count")
|
||||||
|
private Long observationCount;
|
||||||
|
|
||||||
|
@TableField("Sample_Value_Count")
|
||||||
|
private Integer sampleValueCount;
|
||||||
|
|
||||||
|
@TableField("Result")
|
||||||
|
private Integer result;
|
||||||
|
|
||||||
|
@TableField("Msg")
|
||||||
|
private String msg;
|
||||||
|
|
||||||
|
@TableField("State")
|
||||||
|
private Integer state;
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package com.njcn.gather.pqdif.service;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
import com.njcn.gather.pqdif.pojo.param.PqPqdifPathParam;
|
||||||
|
import com.njcn.gather.pqdif.pojo.po.PqPqdifPath;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public interface IPqPqdifPathService extends IService<PqPqdifPath> {
|
||||||
|
List<PqPqdifPath> listAll();
|
||||||
|
|
||||||
|
Page<PqPqdifPath> listPqdif(PqPqdifPathParam.QueryParam param);
|
||||||
|
|
||||||
|
boolean importPqdif(List<PqPqdifPathParam.ImportItem> items);
|
||||||
|
}
|
||||||
@@ -0,0 +1,114 @@
|
|||||||
|
package com.njcn.gather.pqdif.service.impl;
|
||||||
|
|
||||||
|
import cn.hutool.core.collection.CollUtil;
|
||||||
|
import cn.hutool.core.util.ReUtil;
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.njcn.common.pojo.constant.PatternRegex;
|
||||||
|
import com.njcn.common.pojo.enums.common.DataStateEnum;
|
||||||
|
import com.njcn.common.pojo.exception.BusinessException;
|
||||||
|
import com.njcn.gather.pojo.constant.DetectionValidMessage;
|
||||||
|
import com.njcn.gather.pqdif.mapper.PqPqdifPathMapper;
|
||||||
|
import com.njcn.gather.pqdif.pojo.enums.PqdifResponseEnum;
|
||||||
|
import com.njcn.gather.pqdif.pojo.param.PqPqdifPathParam;
|
||||||
|
import com.njcn.gather.pqdif.pojo.po.PqPqdifPath;
|
||||||
|
import com.njcn.gather.pqdif.service.IPqPqdifPathService;
|
||||||
|
import com.njcn.web.factory.PageFactory;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@Service
|
||||||
|
public class PqPqdifPathServiceImpl extends ServiceImpl<PqPqdifPathMapper, PqPqdifPath> implements IPqPqdifPathService {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<PqPqdifPath> listAll() {
|
||||||
|
return this.lambdaQuery()
|
||||||
|
.select(PqPqdifPath::getId, PqPqdifPath::getName)
|
||||||
|
.eq(PqPqdifPath::getState, DataStateEnum.ENABLE.getCode())
|
||||||
|
.orderByDesc(PqPqdifPath::getCreateTime)
|
||||||
|
.list();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Page<PqPqdifPath> listPqdif(PqPqdifPathParam.QueryParam param) {
|
||||||
|
Page<PqPqdifPath> page = new Page<>(PageFactory.getPageNum(param), PageFactory.getPageSize(param));
|
||||||
|
page.setRecords(this.baseMapper.selectPageList(page, StrUtil.trim(param.getName()), param.getResult()));
|
||||||
|
return page;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional
|
||||||
|
public boolean importPqdif(List<PqPqdifPathParam.ImportItem> items) {
|
||||||
|
if (CollUtil.isEmpty(items)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
validateItems(items);
|
||||||
|
for (PqPqdifPathParam.ImportItem item : items) {
|
||||||
|
PqPqdifPath entity = toEntity(item);
|
||||||
|
boolean saved = this.saveOrUpdate(entity);
|
||||||
|
if (!saved) {
|
||||||
|
throw new BusinessException(PqdifResponseEnum.IMPORT_FAILED);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void validateItems(List<PqPqdifPathParam.ImportItem> items) {
|
||||||
|
Set<String> ids = new HashSet<>();
|
||||||
|
for (PqPqdifPathParam.ImportItem item : items) {
|
||||||
|
if (item == null) {
|
||||||
|
throw new BusinessException(PqdifResponseEnum.IMPORT_ITEM_NOT_NULL);
|
||||||
|
}
|
||||||
|
String id = StrUtil.trim(item.getId());
|
||||||
|
if (StrUtil.isBlank(id)) {
|
||||||
|
throw new BusinessException(DetectionValidMessage.ID_NOT_BLANK);
|
||||||
|
}
|
||||||
|
if (!ReUtil.isMatch(PatternRegex.SYSTEM_ID, id)) {
|
||||||
|
throw new BusinessException(DetectionValidMessage.ID_FORMAT_ERROR);
|
||||||
|
}
|
||||||
|
if (!ids.add(id)) {
|
||||||
|
throw new BusinessException(PqdifResponseEnum.IMPORT_ID_REPEAT);
|
||||||
|
}
|
||||||
|
if (StrUtil.isBlank(item.getName())) {
|
||||||
|
throw new BusinessException(DetectionValidMessage.NAME_NOT_BLANK);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private PqPqdifPath toEntity(PqPqdifPathParam.ImportItem item) {
|
||||||
|
PqPqdifPath entity = new PqPqdifPath();
|
||||||
|
entity.setId(StrUtil.trim(item.getId()));
|
||||||
|
entity.setName(StrUtil.trim(item.getName()));
|
||||||
|
entity.setFilePath(StrUtil.trim(item.getFilePath()));
|
||||||
|
entity.setRecordCount(item.getRecordCount());
|
||||||
|
entity.setObservationCount(item.getObservationCount());
|
||||||
|
entity.setSampleValueCount(item.getSampleValueCount());
|
||||||
|
entity.setResult(item.getResult());
|
||||||
|
entity.setMsg(item.getMsg());
|
||||||
|
entity.setState(item.getState() == null ? DataStateEnum.ENABLE.getCode() : item.getState());
|
||||||
|
entity.setCreateBy(StrUtil.trim(item.getCreateBy()));
|
||||||
|
entity.setUpdateBy(StrUtil.trim(item.getUpdateBy()));
|
||||||
|
entity.setCreateTime(parseDateTime(item.getCreateTime()));
|
||||||
|
entity.setUpdateTime(parseDateTime(item.getUpdateTime()));
|
||||||
|
return entity;
|
||||||
|
}
|
||||||
|
|
||||||
|
private LocalDateTime parseDateTime(String value) {
|
||||||
|
if (StrUtil.isBlank(value)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
return LocalDateTime.parse(StrUtil.trim(value));
|
||||||
|
} catch (Exception ex) {
|
||||||
|
throw new BusinessException(PqdifResponseEnum.JSON_FORMAT_ERROR);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
package com.njcn.gather.pqdif.service.support;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import com.alibaba.fastjson.JSONArray;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.njcn.common.pojo.exception.BusinessException;
|
||||||
|
import com.njcn.gather.pqdif.pojo.enums.PqdifResponseEnum;
|
||||||
|
import com.njcn.gather.pqdif.pojo.param.PqPqdifPathParam;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public final class PqdifImportParser {
|
||||||
|
|
||||||
|
private PqdifImportParser() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<PqPqdifPathParam.ImportItem> parse(String content) {
|
||||||
|
try {
|
||||||
|
JSONArray jsonArray = JSON.parseArray(content);
|
||||||
|
if (jsonArray == null) {
|
||||||
|
throw new BusinessException(PqdifResponseEnum.JSON_FORMAT_ERROR);
|
||||||
|
}
|
||||||
|
List<PqPqdifPathParam.ImportItem> items = new ArrayList<>();
|
||||||
|
for (int i = 0; i < jsonArray.size(); i++) {
|
||||||
|
JSONObject jsonObject = jsonArray.getJSONObject(i);
|
||||||
|
if (jsonObject == null) {
|
||||||
|
throw new BusinessException(PqdifResponseEnum.IMPORT_ITEM_NOT_NULL);
|
||||||
|
}
|
||||||
|
PqPqdifPathParam.ImportItem item = jsonObject.toJavaObject(PqPqdifPathParam.ImportItem.class);
|
||||||
|
Object msg = jsonObject.get("msg");
|
||||||
|
item.setMsg(normalizeMsg(msg));
|
||||||
|
items.add(item);
|
||||||
|
}
|
||||||
|
return items;
|
||||||
|
} catch (BusinessException ex) {
|
||||||
|
throw ex;
|
||||||
|
} catch (Exception ex) {
|
||||||
|
throw new BusinessException(PqdifResponseEnum.JSON_FORMAT_ERROR);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String normalizeMsg(Object msg) {
|
||||||
|
if (msg == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (msg instanceof String) {
|
||||||
|
return (String) msg;
|
||||||
|
}
|
||||||
|
return JSON.toJSONString(msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -134,11 +134,12 @@ public class ReportController extends BaseController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@OperateInfo
|
@OperateInfo
|
||||||
@GetMapping("/listAllName")
|
@GetMapping("/listOptions")
|
||||||
@ApiOperation("查询所有报告模板名称")
|
@ApiOperation("查询所有报告模板名称")
|
||||||
public HttpResult<List<String>> listAllName() {
|
public HttpResult<List<PqReportVO.OptionVO>> listOptions(@RequestParam("pattern") String pattern) {
|
||||||
String methodDescribe = getMethodDescribe("listAllName");
|
String methodDescribe = getMethodDescribe("listOptions");
|
||||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, pqReportService.listAllName(), methodDescribe);
|
LogUtil.njcnDebug(log, "{}锛屾煡璇㈠弬鏁颁负锛歿}", methodDescribe, pattern);
|
||||||
|
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)
|
||||||
|
|||||||
@@ -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>
|
||||||
|
|||||||
@@ -0,0 +1,68 @@
|
|||||||
|
package com.njcn.gather.report.pojo.constant;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.LinkedHashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* "指标锚点"新型模板的书签命名空间常量。
|
||||||
|
* 设计文档:docs/superpowers/specs/2026-07-02-item-anchor-report-template-design.md §3.1
|
||||||
|
*
|
||||||
|
* @author hongawen
|
||||||
|
*/
|
||||||
|
public interface ItemAnchorConstant {
|
||||||
|
|
||||||
|
/** 数据锚点书签前缀:item_{scriptCode},锚点处按回路插入检测数据表 */
|
||||||
|
String ITEM_PREFIX = "item_";
|
||||||
|
|
||||||
|
/** 区段书签前缀:sect_{scriptCode} / sect_{GRP_XXX},指标无数据时整段删除 */
|
||||||
|
String SECT_PREFIX = "sect_";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 父节 → 子节 scriptCode 映射;一个父节的全部子节都隐藏时,父节(组标题+组内公共文字)一并隐藏。
|
||||||
|
* key 与模板中 sect_GRP_* 书签名的 GRP_* 部分一致。
|
||||||
|
*/
|
||||||
|
Map<String, List<String>> GRP_CHILDREN = buildGrpChildren();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 已知指标 scriptCode 白名单(规范大写,即云南模板 11 个锚点)。
|
||||||
|
* 分流与锚点解析以此为准:白名单外的 item_* 书签一律视为无效,防止老模板中
|
||||||
|
* 作者手工遗留的同前缀书签(如 item_1)把整份报告误路由进新路径。
|
||||||
|
*/
|
||||||
|
Set<String> KNOWN_SCRIPT_CODES = buildKnownScriptCodes();
|
||||||
|
|
||||||
|
static Map<String, List<String>> buildGrpChildren() {
|
||||||
|
Map<String, List<String>> map = new LinkedHashMap<>();
|
||||||
|
map.put("GRP_FUND", Arrays.asList("V", "I", "P", "ANGLE"));
|
||||||
|
map.put("GRP_UNB", Arrays.asList("IMBV", "IMBA"));
|
||||||
|
map.put("GRP_HARM", Arrays.asList("HV", "HI", "HP"));
|
||||||
|
return Collections.unmodifiableMap(map);
|
||||||
|
}
|
||||||
|
|
||||||
|
static Set<String> buildKnownScriptCodes() {
|
||||||
|
return Collections.unmodifiableSet(new LinkedHashSet<>(Arrays.asList(
|
||||||
|
"V", "I", "P", "ANGLE", "FREQ", "F", "IMBV", "IMBA", "HV", "HI", "HP")));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 从书签名解析指标锚点的 scriptCode。
|
||||||
|
*
|
||||||
|
* @param bookmarkName 书签名
|
||||||
|
* @return 规范大写 scriptCode(scriptMap / 模板 H5 分组 key 均为大写);
|
||||||
|
* 非 item_ 前缀、空 code 或不在 {@link #KNOWN_SCRIPT_CODES} 白名单内返回 null
|
||||||
|
*/
|
||||||
|
static String resolveItemScriptCode(String bookmarkName) {
|
||||||
|
if (bookmarkName == null || bookmarkName.length() <= ITEM_PREFIX.length()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (!bookmarkName.substring(0, ITEM_PREFIX.length()).equalsIgnoreCase(ITEM_PREFIX)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
String code = bookmarkName.substring(ITEM_PREFIX.length()).toUpperCase();
|
||||||
|
return KNOWN_SCRIPT_CODES.contains(code) ? code : null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -12,18 +12,32 @@ import lombok.Getter;
|
|||||||
public enum AffectEnum {
|
public enum AffectEnum {
|
||||||
|
|
||||||
|
|
||||||
BASE("base", "额定工作条件下的检测"),
|
// 第三个参数 sort 为报告小节排序档位:额定=1、单影响量=2、多影响量=3(同档内再按 Script_Index 升序)
|
||||||
VOL("vol", "电压对XX测量的影响"),
|
BASE("Base", "额定条件XX准确度测试", 1),
|
||||||
FREQ("freq", "频率对XX测量的影响"),
|
VOL("VOL", "电压幅值对XX测量的影响", 2),
|
||||||
HARM("harm", "谐波对XX测量的影响");
|
FREQ("Freq", "频率变化对XX测量的影响", 2),
|
||||||
|
HARM("Harm", "谐波对XX测量的影响", 2),
|
||||||
|
// Single / Many 是检测树的分组标题,不会作为叶子 Script_SubType 落到设备数据上
|
||||||
|
SINGLE("Single", "单影响量下XX准确度测试", 2),
|
||||||
|
MANY("Many", "多影响量下XX准确度测试", 3),
|
||||||
|
// 以下为真实的多影响量组合 Script_SubType(报告与检测树共用同一份文案)
|
||||||
|
MANY_VOL_HARM_INHARM("Many-Vol-Harm-InHarm", "电压和谐波和间谐波对XX的影响", 3),
|
||||||
|
MANY_IMBV_HARM_INHARM("Many-IMBV-Harm-InHarm", "三项电压不平衡和谐波和间谐波对XX的影响", 3),
|
||||||
|
MANY_FREQ_HARM_INHARM("Many-Freq-Harm-InHarm", "频率和谐波和间谐波对XX的影响", 3);
|
||||||
|
|
||||||
private String key;
|
private String key;
|
||||||
|
|
||||||
private String desc;
|
private String desc;
|
||||||
|
|
||||||
AffectEnum(String key, String desc) {
|
/**
|
||||||
|
* 报告小节排序档位:额定=1、单影响量=2、多影响量=3;同档内再按 Script_Index 升序
|
||||||
|
*/
|
||||||
|
private int sort;
|
||||||
|
|
||||||
|
AffectEnum(String key, String desc, int sort) {
|
||||||
this.key = key;
|
this.key = key;
|
||||||
this.desc = desc;
|
this.desc = desc;
|
||||||
|
this.sort = sort;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -17,19 +17,24 @@ public enum BaseReportKeyEnum {
|
|||||||
|
|
||||||
DEV_TYPE("devType","设备型号、规格"),
|
DEV_TYPE("devType","设备型号、规格"),
|
||||||
DEV_CODE("createId","装置编号"),
|
DEV_CODE("createId","装置编号"),
|
||||||
|
DEV_NAME("devName","装置名称"),
|
||||||
POWER("power","工作电源"),
|
POWER("power","工作电源"),
|
||||||
DEV_CURR("devCurr","额定电流"),
|
DEV_CURR("devCurr","额定电流"),
|
||||||
DEV_VOLT("devVolt","额定电压"),
|
DEV_VOLT("devVolt","额定电压"),
|
||||||
|
SOURCE_NAME("sourceName","检测源名称"),
|
||||||
COUNT("count","通道数"),
|
COUNT("count","通道数"),
|
||||||
MANUFACTURER("manufacturer","设备厂家、制造厂商"),
|
MANUFACTURER("manufacturer","设备厂家、制造厂商"),
|
||||||
SAMPLE_ID("sampleId","样品编号"),
|
SAMPLE_ID("sampleId","样品编号"),
|
||||||
ARRIVED_DATE("arrivedDate","收样日期"),
|
ARRIVED_DATE("arrivedDate","收样日期"),
|
||||||
|
ARRIVED_DATE_C("arrivedDateC","收样日期"),
|
||||||
TEST_DATE("testDate","检测日期"),
|
TEST_DATE("testDate","检测日期"),
|
||||||
|
TEST_DATE_C("testDateC","检测日期"),
|
||||||
INSPECTOR("inspector","检测员"),
|
INSPECTOR("inspector","检测员"),
|
||||||
YEAR("year","年份"),
|
YEAR("year","年份"),
|
||||||
MONTH("month","月份"),
|
MONTH("month","月份"),
|
||||||
DAY("day","日"),
|
DAY("day","日"),
|
||||||
YEAR_MONTH_DAY("year-month-day","年-月-日"),
|
YEAR_MONTH_DAY("year-month-day","年-月-日"),
|
||||||
|
YEAR_MONTH_DAY_UP("year-month-day-up","中文数字 年-月-日"),
|
||||||
REPORT_DATE("reportDate","年-月-日"),
|
REPORT_DATE("reportDate","年-月-日"),
|
||||||
GD_NAME("gdName","供电部门"),
|
GD_NAME("gdName","供电部门"),
|
||||||
SUB_NAME("subName","变电站"),
|
SUB_NAME("subName","变电站"),
|
||||||
|
|||||||
@@ -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) {
|
||||||
|
|||||||
@@ -45,7 +45,34 @@ public enum ItemReportKeyEnum {
|
|||||||
RESULT_B("resultB", "结论 比如:合格/不合格"),
|
RESULT_B("resultB", "结论 比如:合格/不合格"),
|
||||||
RESULT_C("resultC", "结论 比如:合格/不合格"),
|
RESULT_C("resultC", "结论 比如:合格/不合格"),
|
||||||
RESULT_MAG("resultMag", "特征幅值结论 比如:合格/不合格"),
|
RESULT_MAG("resultMag", "特征幅值结论 比如:合格/不合格"),
|
||||||
RESULT_DUR("resultDur", "持续时间结论 比如:合格/不合格");
|
RESULT_DUR("resultDur", "持续时间结论 比如:合格/不合格"),
|
||||||
|
|
||||||
|
// ===== 以下为"指标锚点"新型模板(云南检定报告)新增 key,见 docs/superpowers/specs/2026-07-02-item-anchor-report-template-design.md §5 =====
|
||||||
|
STANDARD_V("standardV", "P表:基波电压设置值"),
|
||||||
|
STANDARD_I("standardI", "P表:基波电流设置值"),
|
||||||
|
STANDARD_U_ANGLE("standardUAngle", "P表:电压相角设置值"),
|
||||||
|
STANDARD_I_ANGLE("standardIAngle", "P表:电流相角设置值"),
|
||||||
|
ACTIVE_POWER("activePower", "P表:有功功率实测值(三相之和)"),
|
||||||
|
REACTIVE_POWER("reactivePower", "P表:无功功率实测值(数据侧暂无,留空)"),
|
||||||
|
APPARENT_POWER("apparentPower", "P表:视在功率实测值(数据侧暂无,留空)"),
|
||||||
|
POWER_FACTOR("powerFactor", "P表:功率因数实测值(数据侧暂无,留空)"),
|
||||||
|
POS_SEQ("posSeq", "不平衡表:基波正序(数据侧暂无,留空)"),
|
||||||
|
NEG_SEQ("negSeq", "不平衡表:基波负序(数据侧暂无,留空)"),
|
||||||
|
ZERO_SEQ("zeroSeq", "不平衡表:基波零序(数据侧暂无,留空)"),
|
||||||
|
BASE_CURRENT_A("baseCurrentA", "HI表:A相基波电流幅值,用于计算谐波电流含有率"),
|
||||||
|
BASE_CURRENT_B("baseCurrentB", "HI表:B相基波电流幅值,用于计算谐波电流含有率"),
|
||||||
|
BASE_CURRENT_C("baseCurrentC", "HI表:C相基波电流幅值,用于计算谐波电流含有率"),
|
||||||
|
STANDARD_RATE("standardRate", "HI表:标准源输出含有率"),
|
||||||
|
TEST_RATE_A("testRateA", "HI表:A相谐波电流含有率"),
|
||||||
|
TEST_RATE_B("testRateB", "HI表:B相谐波电流含有率"),
|
||||||
|
TEST_RATE_C("testRateC", "HI表:C相谐波电流含有率"),
|
||||||
|
ERROR_RATE_A("errorRateA", "HI表:A相谐波电流含有率误差"),
|
||||||
|
ERROR_RATE_B("errorRateB", "HI表:B相谐波电流含有率误差"),
|
||||||
|
ERROR_RATE_C("errorRateC", "HI表:C相谐波电流含有率误差"),
|
||||||
|
STANDARD_THD("standardThd", "HV/HI表:标准源总谐波畸变率"),
|
||||||
|
THD_A("thdA", "HV/HI表:A相总谐波畸变率"),
|
||||||
|
THD_B("thdB", "HV/HI表:B相总谐波畸变率"),
|
||||||
|
THD_C("thdC", "HV/HI表:C相总谐波畸变率");
|
||||||
|
|
||||||
private String key;
|
private String key;
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import lombok.Getter;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 电能质量测试大项枚举
|
* 电能质量测试大项枚举
|
||||||
|
*
|
||||||
* @author hongawen
|
* @author hongawen
|
||||||
* @version 1.0
|
* @version 1.0
|
||||||
* @data 2025/3/27 18:29
|
* @data 2025/3/27 18:29
|
||||||
@@ -13,21 +14,21 @@ public enum PowerIndexEnum {
|
|||||||
|
|
||||||
|
|
||||||
UNKNOWN("UNKNOWN", "未知指标"),
|
UNKNOWN("UNKNOWN", "未知指标"),
|
||||||
FREQ("FREQ", "频率"),
|
|
||||||
LINE_TITLE("LINE_TITLE", "测量回路"),
|
LINE_TITLE("LINE_TITLE", "测量回路"),
|
||||||
|
FREQ("FREQ", "频率"),
|
||||||
V("V", "电压"),
|
V("V", "电压"),
|
||||||
I("I", "电流"),
|
|
||||||
P("P", "功率"),
|
|
||||||
IMBV("IMBV", "负序电压不平衡度"),
|
|
||||||
IMBA("IMBA", "负序电流不平衡度"),
|
|
||||||
F("F", "短时电压闪变"),
|
|
||||||
HP("HP", "谐波有功功率"),
|
|
||||||
HV("HV", "谐波电压"),
|
HV("HV", "谐波电压"),
|
||||||
HI("HI", "谐波电流"),
|
HI("HI", "谐波电流"),
|
||||||
|
HP("HP", "谐波有功功率"),
|
||||||
HSV("HSV", "间谐波电压"),
|
HSV("HSV", "间谐波电压"),
|
||||||
HSI("HSI", "间谐波电流"),
|
HSI("HSI", "间谐波电流"),
|
||||||
VOLTAGE("VOLTAGE", "电压暂降、暂升及短时中断"),
|
VOLTAGE("VOLTAGE", "电压暂降、暂升及短时中断"),
|
||||||
PST("PST", "短时间闪变");
|
I("I", "电流"),
|
||||||
|
IMBV("IMBV", "负序电压不平衡度"),
|
||||||
|
IMBA("IMBA", "负序电流不平衡度"),
|
||||||
|
F("F", "短时电压闪变"),
|
||||||
|
P("P", "功率"),
|
||||||
|
ANGLE("Angle", "基波相位");
|
||||||
|
|
||||||
private String key;
|
private String key;
|
||||||
|
|
||||||
|
|||||||
@@ -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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user