Compare commits
33 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0787901d60 | ||
|
|
4afcec7fb9 | ||
|
|
a48dad40f6 | ||
|
|
c8217046c6 | ||
|
|
0a16a1fee5 | ||
|
|
391646d416 | ||
|
|
4f3f0833d5 | ||
|
|
924c2e8f45 | ||
|
|
8dca7bf537 | ||
|
|
7e6fb2d981 | ||
|
|
ec9a0ca236 | ||
|
|
7ab5b9a501 | ||
|
|
3959b96040 | ||
|
|
ae5370abdf | ||
|
|
1894cb07a2 | ||
|
|
08dff063c9 | ||
|
|
f640afb4ed | ||
|
|
503018a721 | ||
|
|
391fd0cf4f | ||
|
|
99c7448544 | ||
|
|
83296d257c | ||
|
|
e020aa466e | ||
|
|
f20e2c9b32 | ||
|
|
e03c3e3607 | ||
|
|
27f25d2404 | ||
|
|
a77313171c | ||
|
|
a658d6e81a | ||
|
|
ab11c91579 | ||
|
|
a2468f1353 | ||
|
|
d8bcca1ede | ||
|
|
c5e77ee9b1 | ||
|
|
2293d81b71 | ||
|
|
97157a5ccf |
9
.gitignore
vendored
9
.gitignore
vendored
@@ -48,12 +48,3 @@ 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
|
|
||||||
1675
CN_Gather_Detection_Netty架构详细分析文档.md
Normal file
1675
CN_Gather_Detection_Netty架构详细分析文档.md
Normal file
File diff suppressed because it is too large
Load Diff
@@ -145,12 +145,7 @@
|
|||||||
<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>
|
||||||
|
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
@@ -1,54 +0,0 @@
|
|||||||
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,29 +1,18 @@
|
|||||||
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.detection.util.socket.CnSocketUtil;
|
||||||
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;
|
||||||
@@ -44,7 +33,6 @@ 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;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 开始检测通用入口
|
* 开始检测通用入口
|
||||||
@@ -55,27 +43,10 @@ public class PreDetectionController extends BaseController {
|
|||||||
@OperateInfo
|
@OperateInfo
|
||||||
@ApiOperation("开始检测")
|
@ApiOperation("开始检测")
|
||||||
@ApiImplicitParam(name = "param", value = "查询参数", required = true)
|
@ApiImplicitParam(name = "param", value = "查询参数", required = true)
|
||||||
public HttpResult<?> startPreTest(@RequestBody @Validated PreDetectionParam param) {
|
public HttpResult<String> startPreTest(@RequestBody @Validated PreDetectionParam param) {
|
||||||
String methodDescribe = getMethodDescribe("startPreTest");
|
String methodDescribe = getMethodDescribe("startPreTest");
|
||||||
HttpResult<DetectionLockHolderVO> busy = tryAcquireLock(param.getUserPageId());
|
preDetectionService.sourceCommunicationCheck(param);
|
||||||
if (busy != null) {
|
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
|
||||||
return busy;
|
|
||||||
}
|
|
||||||
// 同步阶段抛异常时回滚锁(PLAN_AND_SOURCE_NOT / SOURCE_INFO_NOT 等业务异常会被全局处理器吞掉,
|
|
||||||
// 锁会卡在用户手上直到 4 小时超时,故需 finally 兜底)
|
|
||||||
boolean keepLock = false;
|
|
||||||
try {
|
|
||||||
// 重置 FormalTestManager 暂停计数残留,避免上次暂停残留计数误触发 R4
|
|
||||||
FormalTestManager.stopTime = 0;
|
|
||||||
FormalTestManager.hasStopFlag = false;
|
|
||||||
preDetectionService.sourceCommunicationCheck(param);
|
|
||||||
keepLock = true;
|
|
||||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
|
|
||||||
} finally {
|
|
||||||
if (!keepLock) {
|
|
||||||
releaseLockSelf("START_PRE_SYNC_FAILED");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -89,12 +60,8 @@ public class PreDetectionController extends BaseController {
|
|||||||
@OperateInfo
|
@OperateInfo
|
||||||
@ApiOperation("源通讯校验")
|
@ApiOperation("源通讯校验")
|
||||||
@ApiImplicitParam(name = "param", value = "查询参数", required = true)
|
@ApiImplicitParam(name = "param", value = "查询参数", required = true)
|
||||||
public HttpResult<?> ytxCheckSimulate(@RequestBody @Validated SimulateDetectionParam param) {
|
public HttpResult<String> 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);
|
||||||
}
|
}
|
||||||
@@ -106,26 +73,10 @@ public class PreDetectionController extends BaseController {
|
|||||||
@OperateInfo
|
@OperateInfo
|
||||||
@ApiOperation("启动")
|
@ApiOperation("启动")
|
||||||
@ApiImplicitParam(name = "param", value = "查询参数", required = true)
|
@ApiImplicitParam(name = "param", value = "查询参数", required = true)
|
||||||
public HttpResult<?> startTestSimulate(@RequestBody @Validated SimulateDetectionParam param) {
|
public HttpResult<String> startTestSimulate(@RequestBody @Validated SimulateDetectionParam param) {
|
||||||
String methodDescribe = getMethodDescribe("startSimulateTest");
|
String methodDescribe = getMethodDescribe("startTestSimulate");
|
||||||
// ContrastDetectionParam 无 userPageId 字段,用 loginName 作为会话标识(与 WS 会话 key 一致)
|
preDetectionService.sendScript(param);
|
||||||
HttpResult<DetectionLockHolderVO> busy = tryAcquireLock(param.getUserPageId());
|
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
|
||||||
if (busy != null) {
|
|
||||||
return busy;
|
|
||||||
}
|
|
||||||
// 同步阶段抛异常时回滚锁,理由同 startPreTest
|
|
||||||
boolean keepLock = false;
|
|
||||||
try {
|
|
||||||
FormalTestManager.stopTime = 0;
|
|
||||||
FormalTestManager.hasStopFlag = false;
|
|
||||||
preDetectionService.sendScript(param);
|
|
||||||
keepLock = true;
|
|
||||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
|
|
||||||
} finally {
|
|
||||||
if (!keepLock) {
|
|
||||||
releaseLockSelf("START_SIMULATE_TEST_SYNC_FAILED");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -135,18 +86,9 @@ public class PreDetectionController extends BaseController {
|
|||||||
@OperateInfo
|
@OperateInfo
|
||||||
@ApiOperation("停止")
|
@ApiOperation("停止")
|
||||||
@ApiImplicitParam(name = "param", value = "查询参数", required = true)
|
@ApiImplicitParam(name = "param", value = "查询参数", required = true)
|
||||||
public HttpResult<?> closeSimulateTest(@RequestBody @Validated SimulateDetectionParam param) {
|
public HttpResult<String> closeSimulateTest(@RequestBody @Validated SimulateDetectionParam param) {
|
||||||
String methodDescribe = getMethodDescribe("closeSimulateTest");
|
String methodDescribe = getMethodDescribe("closeSimulateTest");
|
||||||
HttpResult<DetectionLockHolderVO> busy = requireHolderSelf();
|
preDetectionService.closeTestSimulate(param);
|
||||||
if (busy != null) {
|
|
||||||
return busy;
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
preDetectionService.closeTestSimulate(param);
|
|
||||||
} finally {
|
|
||||||
// 即使业务异常也要释放锁,避免锁残留导致他人无法接手
|
|
||||||
releaseLockSelf("USER_STOP");
|
|
||||||
}
|
|
||||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
|
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -158,12 +100,8 @@ public class PreDetectionController extends BaseController {
|
|||||||
@OperateInfo
|
@OperateInfo
|
||||||
@ApiOperation("系数校验")
|
@ApiOperation("系数校验")
|
||||||
@ApiImplicitParam(name = "param", value = "查询参数", required = true)
|
@ApiImplicitParam(name = "param", value = "查询参数", required = true)
|
||||||
public HttpResult<?> coefficientCheck(@RequestBody PreDetectionParam param) {
|
public HttpResult<String> 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);
|
||||||
}
|
}
|
||||||
@@ -176,13 +114,8 @@ public class PreDetectionController extends BaseController {
|
|||||||
@OperateInfo
|
@OperateInfo
|
||||||
@ApiOperation("暂停检测")
|
@ApiOperation("暂停检测")
|
||||||
@ApiImplicitParam(name = "param", value = "参数", required = true)
|
@ApiImplicitParam(name = "param", value = "参数", required = true)
|
||||||
public HttpResult<?> temStopTest() {
|
public HttpResult<String> 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);
|
||||||
}
|
}
|
||||||
@@ -194,46 +127,12 @@ public class PreDetectionController extends BaseController {
|
|||||||
@OperateInfo
|
@OperateInfo
|
||||||
@ApiOperation("重新开始检测")
|
@ApiOperation("重新开始检测")
|
||||||
@ApiImplicitParam(name = "param", value = "参数", required = true)
|
@ApiImplicitParam(name = "param", value = "参数", required = true)
|
||||||
public HttpResult<?> restartTemTest(@RequestBody PreDetectionParam param) {
|
public HttpResult<String> 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);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 开始比对检测(包括预检测、正式检测)通用入口
|
* 开始比对检测(包括预检测、正式检测)通用入口
|
||||||
@@ -242,26 +141,10 @@ public class PreDetectionController extends BaseController {
|
|||||||
@OperateInfo
|
@OperateInfo
|
||||||
@ApiOperation("开始比对检测")
|
@ApiOperation("开始比对检测")
|
||||||
@ApiImplicitParam(name = "param", value = "查询参数", required = true)
|
@ApiImplicitParam(name = "param", value = "查询参数", required = true)
|
||||||
public HttpResult<?> startContrastTest(@RequestBody @Validated ContrastDetectionParam param) {
|
public HttpResult<String> startContrastTest(@RequestBody @Validated ContrastDetectionParam param) {
|
||||||
String methodDescribe = getMethodDescribe("startContrastTest");
|
String methodDescribe = getMethodDescribe("startContrastTest");
|
||||||
// ContrastDetectionParam 无 userPageId 字段,用 loginName 作为会话标识(与 WS 会话 key 一致)
|
preDetectionService.startContrastTest(param);
|
||||||
HttpResult<DetectionLockHolderVO> busy = tryAcquireLock(param.getLoginName());
|
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
|
||||||
if (busy != null) {
|
|
||||||
return busy;
|
|
||||||
}
|
|
||||||
// 同步阶段抛异常时回滚锁,理由同 startPreTest
|
|
||||||
boolean keepLock = false;
|
|
||||||
try {
|
|
||||||
FormalTestManager.stopTime = 0;
|
|
||||||
FormalTestManager.hasStopFlag = false;
|
|
||||||
preDetectionService.startContrastTest(param);
|
|
||||||
keepLock = true;
|
|
||||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
|
|
||||||
} finally {
|
|
||||||
if (!keepLock) {
|
|
||||||
releaseLockSelf("START_CONTRAST_SYNC_FAILED");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -287,91 +170,33 @@ public class PreDetectionController extends BaseController {
|
|||||||
@OperateInfo(info = LogEnum.SYSTEM_COMMON)
|
@OperateInfo(info = LogEnum.SYSTEM_COMMON)
|
||||||
@GetMapping("/startCoefficient")
|
@GetMapping("/startCoefficient")
|
||||||
@ApiOperation("比对模式开启系数校验")
|
@ApiOperation("比对模式开启系数校验")
|
||||||
public HttpResult<?> startCoefficient() {
|
public HttpResult<String> 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ============ 检测互斥锁辅助方法 ============
|
@OperateInfo(info = LogEnum.SYSTEM_COMMON)
|
||||||
|
@GetMapping("/startFreqConverter")
|
||||||
|
@ApiOperation("开启变频器测试")
|
||||||
|
public HttpResult<String> startFreqConverter(@RequestParam("userId") String userId, @RequestParam("converterId") String converterId, @RequestParam("monitorId") String monitorId, @RequestParam("reset") Boolean reset) {
|
||||||
|
String methodDescribe = getMethodDescribe("startFreqConverter");
|
||||||
|
LogUtil.njcnDebug(log, "{}", methodDescribe);
|
||||||
|
|
||||||
/** 抢锁入口(startPreTest / startContrastTest 用)。
|
preDetectionService.startFreqConverter(userId, converterId, monitorId,reset);
|
||||||
* 抢到→null;被他人持有或竞态失败→返回 busy 响应;
|
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
|
||||||
* 使用方:拿到非 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 == 自己。
|
@OperateInfo(info = LogEnum.SYSTEM_COMMON)
|
||||||
* 空闲 → 返回 busy data=null("请先开始检测"语义);
|
@GetMapping("/stopFreqConverter")
|
||||||
* 他人持有 → 返回 busy + holder;
|
@ApiOperation("关闭变频器测试")
|
||||||
* 自己持有 → 返回 null(放行)。 */
|
public HttpResult<String> stopFreqConverter(@RequestParam("userId") String userId) {
|
||||||
private HttpResult<DetectionLockHolderVO> requireHolderSelf() {
|
String methodDescribe = getMethodDescribe("stopFreqConverter");
|
||||||
DetectionLock cur = DetectionLockManager.getInstance().getCurrent();
|
LogUtil.njcnDebug(log, "{}", methodDescribe);
|
||||||
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;自己持有 → 放行。 */
|
preDetectionService.stopFreqConverter(userId + CnSocketUtil.FREQ_CONVERTER_TAG, userId + CnSocketUtil.DEV_TAG);
|
||||||
private HttpResult<DetectionLockHolderVO> requireFreeOrSelf() {
|
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,44 +0,0 @@
|
|||||||
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,13 +41,11 @@ 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;
|
||||||
@@ -59,6 +57,7 @@ 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;
|
||||||
@@ -128,22 +127,21 @@ 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(PowerIndexEnum.FREQ.getKey(), Arrays.asList(DetectionCodeEnum.FREQ.getCode()));
|
put("FREQ", Arrays.asList(DetectionCodeEnum.FREQ.getCode()));
|
||||||
put(PowerIndexEnum.V.getKey(), Arrays.asList(DetectionCodeEnum.VRMS.getCode(), DetectionCodeEnum.PVRMS.getCode()));
|
put("V", Arrays.asList(DetectionCodeEnum.VRMS.getCode(), DetectionCodeEnum.PVRMS.getCode()));
|
||||||
put(PowerIndexEnum.HV.getKey(), Arrays.asList(DetectionCodeEnum.V2_50.getCode(), DetectionCodeEnum.PV2_50.getCode()));
|
put("HV", Arrays.asList(DetectionCodeEnum.V2_50.getCode(), DetectionCodeEnum.PV2_50.getCode()));
|
||||||
put(PowerIndexEnum.HI.getKey(), Arrays.asList(DetectionCodeEnum.I2_50.getCode()));
|
put("HI", Arrays.asList(DetectionCodeEnum.I2_50.getCode()));
|
||||||
put(PowerIndexEnum.HP.getKey(), Arrays.asList(DetectionCodeEnum.P2_50.getCode()));
|
put("HP", Arrays.asList(DetectionCodeEnum.P2_50.getCode()));
|
||||||
put(PowerIndexEnum.HSV.getKey(), Arrays.asList(DetectionCodeEnum.SV_1_49.getCode(), DetectionCodeEnum.PSV_1_49.getCode()));
|
put("HSV", Arrays.asList(DetectionCodeEnum.SV_1_49.getCode(), DetectionCodeEnum.PSV_1_49.getCode()));
|
||||||
put(PowerIndexEnum.HSI.getKey(), Arrays.asList(DetectionCodeEnum.SI_1_49.getCode()));
|
put("HSI", Arrays.asList(DetectionCodeEnum.SI_1_49.getCode()));
|
||||||
put(PowerIndexEnum.I.getKey(), Arrays.asList(DetectionCodeEnum.IRMS.getCode()));
|
put("I", Arrays.asList(DetectionCodeEnum.IRMS.getCode()));
|
||||||
put(PowerIndexEnum.IMBV.getKey(), Arrays.asList(DetectionCodeEnum.V_UNBAN.getCode()));
|
put("IMBV", Arrays.asList(DetectionCodeEnum.V_UNBAN.getCode()));
|
||||||
put(PowerIndexEnum.IMBA.getKey(), Arrays.asList(DetectionCodeEnum.I_UNBAN.getCode()));
|
put("IMBA", Arrays.asList(DetectionCodeEnum.I_UNBAN.getCode()));
|
||||||
put(PowerIndexEnum.F.getKey(), Arrays.asList(DetectionCodeEnum.PST.getCode()));
|
put("F", Arrays.asList(DetectionCodeEnum.PST.getCode()));
|
||||||
}};
|
}};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -308,7 +306,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.isFormalTestSelected()) {
|
if (param.getTestItemList().get(2)) {
|
||||||
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);
|
||||||
@@ -357,7 +355,6 @@ 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 {
|
||||||
@@ -556,6 +553,7 @@ 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);
|
||||||
@@ -1155,7 +1153,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.isFormalTestSelected()) {
|
if (param.getTestItemList().get(2)) {
|
||||||
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<>();
|
||||||
@@ -2316,7 +2314,7 @@ public class SocketContrastResponseService {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
ExcelUtil.saveExcel(pathConfig.getDataPath(), "对齐数据.xlsx", sheetsList);
|
ExcelUtil.saveExcel(alignDataFilePath, "对齐数据.xlsx", sheetsList);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ 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;
|
||||||
@@ -28,14 +27,13 @@ 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.report.pojo.enums.PowerIndexEnum;
|
import com.njcn.gather.result.pojo.enums.ResultUnitEnum;
|
||||||
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.pojo.po.SourceInitialize;
|
||||||
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.SimAndDigHarmonicResult;
|
import com.njcn.gather.storage.pojo.po.SimAndDigHarmonicResult;
|
||||||
@@ -45,8 +43,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;
|
||||||
@@ -68,7 +66,7 @@ public class SocketDevResponseService {
|
|||||||
|
|
||||||
private List<String> icdTypeList;
|
private List<String> icdTypeList;
|
||||||
|
|
||||||
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 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 IPqDevService iPqDevService;
|
private final IPqDevService iPqDevService;
|
||||||
private final IPqDevSubService iPqDevSubService;
|
private final IPqDevSubService iPqDevSubService;
|
||||||
@@ -81,10 +79,6 @@ public class SocketDevResponseService {
|
|||||||
private final IAdPlanService adPlanService;
|
private final IAdPlanService adPlanService;
|
||||||
private final IDictDataService dictDataService;
|
private final IDictDataService dictDataService;
|
||||||
private final IPqSourceService pqSourceService;
|
private final IPqSourceService pqSourceService;
|
||||||
private final IResultService resultService;
|
|
||||||
|
|
||||||
@Value("${dataCheck.enable}")
|
|
||||||
private Boolean dataCheck;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 存储的装置相序数据
|
* 存储的装置相序数据
|
||||||
@@ -397,8 +391,73 @@ 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.isFormalTestSelected()) {
|
if (param.getTestItemList().get(2)) {
|
||||||
startFormalScripts(param, null, param.isResumeFormal());
|
//如果后续做正式检测
|
||||||
|
PqScriptIssueParam issueParam = new PqScriptIssueParam();
|
||||||
|
SourceInitialize sourceInitialize = pqSourceService.getSourceInitializeParam(param.getSourceId());
|
||||||
|
issueParam.setSourceId(sourceInitialize.getSourceId());
|
||||||
|
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);
|
||||||
@@ -550,7 +609,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 (PowerIndexEnum.V.getKey().equals(type)) {
|
if (DicDataEnum.V.getCode().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);
|
||||||
@@ -613,12 +672,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(), PowerIndexEnum.V.getKey()).toString());
|
coefficientVO.setAV(rangeNum(optionalA, devParameter.getDevVolt(), DicDataEnum.V.getCode()).toString());
|
||||||
coefficientVO.setBV(rangeNum(optionalB, devParameter.getDevVolt(), PowerIndexEnum.V.getKey()).toString());
|
coefficientVO.setBV(rangeNum(optionalB, devParameter.getDevVolt(), DicDataEnum.V.getCode()).toString());
|
||||||
coefficientVO.setCV(rangeNum(optionalC, devParameter.getDevVolt(), PowerIndexEnum.V.getKey()).toString());
|
coefficientVO.setCV(rangeNum(optionalC, devParameter.getDevVolt(), DicDataEnum.V.getCode()).toString());
|
||||||
coefficientVO.setAI(rangeNum(optionalIA, devParameter.getDevCurr(), PowerIndexEnum.I.getKey()).toString());
|
coefficientVO.setAI(rangeNum(optionalIA, devParameter.getDevCurr(), DicDataEnum.I.getCode()).toString());
|
||||||
coefficientVO.setBI(rangeNum(optionalIB, devParameter.getDevCurr(), PowerIndexEnum.I.getKey()).toString());
|
coefficientVO.setBI(rangeNum(optionalIB, devParameter.getDevCurr(), DicDataEnum.I.getCode()).toString());
|
||||||
coefficientVO.setCI(rangeNum(optionalIC, devParameter.getDevCurr(), PowerIndexEnum.I.getKey()).toString());
|
coefficientVO.setCI(rangeNum(optionalIC, devParameter.getDevCurr(), DicDataEnum.I.getCode()).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);
|
||||||
@@ -634,7 +693,7 @@ public class SocketDevResponseService {
|
|||||||
*/
|
*/
|
||||||
private Double reduceList(List<Double> valList) {
|
private Double reduceList(List<Double> valList) {
|
||||||
// valList.subList(0, 5).clear();
|
// valList.subList(0, 5).clear();
|
||||||
valList.subList(valList.size() - 2, valList.size()).clear();
|
valList.subList(valList.size() - 2, valList.size()).clear();
|
||||||
return valList.stream().mapToDouble(Double::doubleValue).average().getAsDouble();
|
return valList.stream().mapToDouble(Double::doubleValue).average().getAsDouble();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -839,78 +898,75 @@ public class SocketDevResponseService {
|
|||||||
|
|
||||||
//开始下源控制脚本
|
//开始下源控制脚本
|
||||||
PqScriptIssueParam issueParam = new PqScriptIssueParam();
|
PqScriptIssueParam issueParam = new PqScriptIssueParam();
|
||||||
|
SourceInitialize sourceInitialize = pqSourceService.getSourceInitializeParam(param.getSourceId());
|
||||||
|
issueParam.setSourceId(sourceInitialize.getSourceId());
|
||||||
issueParam.setPlanId(param.getPlanId());
|
issueParam.setPlanId(param.getPlanId());
|
||||||
issueParam.setSourceId(param.getSourceName());
|
|
||||||
issueParam.setDevIds(param.getDevIds());
|
|
||||||
issueParam.setScriptId(param.getScriptId());
|
|
||||||
|
|
||||||
socketMsg.setOperateCode(SourceOperateCodeEnum.OPER_GATHER.getValue());
|
socketMsg.setOperateCode(SourceOperateCodeEnum.OPER_GATHER.getValue());
|
||||||
List<SourceIssue> sourceIssues;
|
List<SourceIssue> sourceIssues;
|
||||||
// 做预检测、后续做系数校准
|
// 做预检测、后续做系数校准
|
||||||
// if (param.isPreTestSelected() || param.isCoefficientSelected() || param.isFormalTestSelected()) {
|
if (param.getTestItemList().get(0) || param.getTestItemList().get(1)) {
|
||||||
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<>();
|
||||||
// Set<Integer> indexes = new HashSet<>();
|
StorageParam storageParam = new StorageParam();
|
||||||
// StorageParam storageParam = new StorageParam();
|
storageParam.setCode(param.getCode());
|
||||||
// storageParam.setCode(param.getCode());
|
storageParam.setScriptId(param.getScriptId());
|
||||||
// storageParam.setScriptId(param.getScriptId());
|
param.getDevIds().forEach(devId -> {
|
||||||
// param.getDevIds().forEach(devId -> {
|
storageParam.setDevId(devId);
|
||||||
// storageParam.setDevId(devId);
|
indexes.addAll(adHarmonicService.getIndex(storageParam));
|
||||||
// indexes.addAll(adHarmonicService.getIndex(storageParam));
|
});
|
||||||
// });
|
issueParam.setIndexList(indexes.stream().collect(Collectors.toList()));
|
||||||
// issueParam.setIndexList(indexes.stream().collect(Collectors.toList()));
|
issueParam.setIsPhaseSequence(SourceOperateCodeEnum.RE_ERROR_TEST.getValue());
|
||||||
// issueParam.setIsPhaseSequence(SourceOperateCodeEnum.RE_ERROR_TEST.getValue());
|
} else {
|
||||||
// } else {
|
issueParam.setIsPhaseSequence(CommonEnum.FORMAL_TEST.getValue());
|
||||||
// issueParam.setIsPhaseSequence(CommonEnum.FORMAL_TEST.getValue());
|
}
|
||||||
// }
|
//正式检测
|
||||||
// //正式检测
|
sourceIssues = pqScriptDtlsService.listSourceIssue(issueParam);
|
||||||
// sourceIssues = pqScriptDtlsService.listSourceIssue(issueParam);
|
sourceIssues = sourceIssues.stream().sorted(Comparator.comparing(SourceIssue::getIndex)).collect(Collectors.toList());
|
||||||
// sourceIssues = sourceIssues.stream().sorted(Comparator.comparing(SourceIssue::getIndex)).collect(Collectors.toList());
|
// 使用 LinkedHashMap 保持分组顺序
|
||||||
// // 使用 LinkedHashMap 保持分组顺序
|
Map<String, List<SourceIssue>> groupedIssues = sourceIssues.stream()
|
||||||
// Map<String, List<SourceIssue>> groupedIssues = sourceIssues.stream()
|
.collect(Collectors.groupingBy(
|
||||||
// .collect(Collectors.groupingBy(
|
SourceIssue::getType,
|
||||||
// SourceIssue::getType,
|
LinkedHashMap::new,
|
||||||
// LinkedHashMap::new,
|
Collectors.toList()
|
||||||
// Collectors.toList()
|
));
|
||||||
// ));
|
|
||||||
//
|
// 将分组后的元素合并成一个新的集合,保持原有顺序
|
||||||
// // 将分组后的元素合并成一个新的集合,保持原有顺序
|
sourceIssues = groupedIssues.values().stream()
|
||||||
// sourceIssues = groupedIssues.values().stream()
|
.flatMap(List::stream)
|
||||||
// .flatMap(List::stream)
|
.collect(Collectors.toList());
|
||||||
// .collect(Collectors.toList());
|
// 存放所有检测小项
|
||||||
// // 存放所有检测小项
|
SocketManager.addSourceList(sourceIssues);
|
||||||
// SocketManager.addSourceList(sourceIssues);
|
// 按照大项分组。key为大项code,value为小项个数
|
||||||
// // 按照大项分组。key为大项code,value为小项个数
|
Map<String, Long> sourceIssueMap = sourceIssues.stream().collect(Collectors.groupingBy(SourceIssue::getType, Collectors.counting()));
|
||||||
// Map<String, Long> sourceIssueMap = sourceIssues.stream().collect(Collectors.groupingBy(SourceIssue::getType, Collectors.counting()));
|
SocketManager.initMap(sourceIssueMap);
|
||||||
// SocketManager.initMap(sourceIssueMap);
|
|
||||||
//
|
//告诉前端当前项开始了
|
||||||
// //告诉前端当前项开始了
|
WebSocketVO<Object> webSocketVO = new WebSocketVO<>();
|
||||||
// WebSocketVO<Object> webSocketVO = new WebSocketVO<>();
|
String type = sourceIssues.get(0).getType();
|
||||||
// String type = sourceIssues.get(0).getType();
|
if (ResultUnitEnum.P.getCode().equals(type)) {
|
||||||
// if (StrUtil.isNotBlank(sourceIssues.get(0).getOtherType())) {
|
sourceIssues.get(0).setType(ResultUnitEnum.V_ABSOLUTELY.getCode());
|
||||||
// sourceIssues.get(0).setType(PowerIndexEnum.V.getKey());
|
webSocketVO.setRequestId(ResultUnitEnum.P.getCode() + CnSocketUtil.START_TAG);
|
||||||
// webSocketVO.setRequestId(sourceIssues.get(0).getOtherType() + CnSocketUtil.START_TAG);
|
} else {
|
||||||
// type = sourceIssues.get(0).getOtherType();
|
webSocketVO.setRequestId(sourceIssues.get(0).getType() + 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)));
|
||||||
// FormalTestManager.currentIssue = sourceIssues.get(0);
|
socketMsg.setRequestId(SourceOperateCodeEnum.FORMAL_REAL.getValue() + CnSocketUtil.STEP_TAG + type);
|
||||||
// socketMsg.setData(JSON.toJSONString(sourceIssues.get(0)));
|
socketMsg.setOperateCode(SourceOperateCodeEnum.OPER_GATHER.getValue());
|
||||||
// socketMsg.setRequestId(SourceOperateCodeEnum.FORMAL_REAL.getValue() + CnSocketUtil.STEP_TAG + type);
|
SocketManager.sendMsg(param.getUserPageId() + CnSocketUtil.SOURCE_TAG, JSON.toJSONString(socketMsg));
|
||||||
// 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));
|
||||||
// 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);
|
||||||
@@ -1083,7 +1139,7 @@ public class SocketDevResponseService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 后续做系数校准
|
// 后续做系数校准
|
||||||
if (param.isCoefficientSelected()) {
|
if (param.getTestItemList().get(1)) {
|
||||||
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());
|
||||||
@@ -1107,8 +1163,68 @@ public class SocketDevResponseService {
|
|||||||
XiNumberManager.smallDevXiNumDataMap.clear();
|
XiNumberManager.smallDevXiNumDataMap.clear();
|
||||||
|
|
||||||
System.out.println("开始系数校准》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》");
|
System.out.println("开始系数校准》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》");
|
||||||
} else if (param.isFormalTestSelected()) {
|
} else if (param.getTestItemList().get(2)) {
|
||||||
startFormalScripts(param, null, param.isResumeFormal());
|
// 后续做正式检测
|
||||||
|
PqScriptIssueParam issueParam = new PqScriptIssueParam();
|
||||||
|
SourceInitialize sourceInitialize = pqSourceService.getSourceInitializeParam(param.getSourceId());
|
||||||
|
issueParam.setSourceId(sourceInitialize.getSourceId());
|
||||||
|
issueParam.setPlanId(param.getPlanId());
|
||||||
|
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("预检测流程结束-----------------关闭源");
|
||||||
@@ -1153,97 +1269,6 @@ 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));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 正式检测
|
* 正式检测
|
||||||
*/
|
*/
|
||||||
@@ -1285,9 +1310,9 @@ public class SocketDevResponseService {
|
|||||||
|
|
||||||
//小项检测完后小项数减一,并更新map
|
//小项检测完后小项数减一,并更新map
|
||||||
long residueCount = 0;
|
long residueCount = 0;
|
||||||
if (StrUtil.isNotBlank(sourceIssue.getOtherType())) {
|
if (sourceIssue.getIsP()) {
|
||||||
residueCount = SocketManager.getSourceTarget(sourceIssue.getOtherType()) - 1;
|
residueCount = SocketManager.getSourceTarget(ResultUnitEnum.P.getCode()) - 1;
|
||||||
SocketManager.addTargetMap(sourceIssue.getOtherType(), residueCount);
|
SocketManager.addTargetMap(ResultUnitEnum.P.getCode(), 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);
|
||||||
@@ -1331,15 +1356,14 @@ 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(), type + CnSocketUtil.START_TAG, null, new ArrayList<>(), null);
|
WebServiceManager.sendDetectionMessage(param.getUserPageId(), sourceIssues.getType() + CnSocketUtil.START_TAG, null, new ArrayList<>(), null);
|
||||||
|
}
|
||||||
|
String type = sourceIssues.getType();
|
||||||
|
if (sourceIssues.getIsP()) {
|
||||||
|
sourceIssues.setType(ResultUnitEnum.V_ABSOLUTELY.getCode());
|
||||||
|
type = ResultUnitEnum.P.getCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
//控源下发下一个小项脚本
|
//控源下发下一个小项脚本
|
||||||
@@ -1355,14 +1379,8 @@ 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(), true);
|
iPqDevService.updateResult(param.getDevIds(), valueType, param.getCode(), param.getUserId(), param.getTemperature(), param.getHumidity());
|
||||||
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();
|
||||||
@@ -1541,7 +1559,6 @@ public class SocketDevResponseService {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param issue
|
* @param issue
|
||||||
* @return key为V或I,value为对应的源下发信息
|
* @return key为V或I,value为对应的源下发信息
|
||||||
@@ -1780,87 +1797,9 @@ public class SocketDevResponseService {
|
|||||||
//字典树
|
//字典树
|
||||||
SocketManager.valueTypeMap = iPqScriptCheckDataService.getValueTypeMap(param.getScriptId());
|
SocketManager.valueTypeMap = iPqScriptCheckDataService.getValueTypeMap(param.getScriptId());
|
||||||
|
|
||||||
if (param.isCoefficientSelected()) {
|
if (param.getTestItemList().get(1)) {
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//初始化系数校验参数
|
//初始化系数校验参数
|
||||||
@@ -1882,7 +1821,8 @@ public class SocketDevResponseService {
|
|||||||
XiNumberManager.devParameterList.add(devParameterSmall);
|
XiNumberManager.devParameterList.add(devParameterSmall);
|
||||||
|
|
||||||
PqScriptIssueParam issueParam = new PqScriptIssueParam();
|
PqScriptIssueParam issueParam = new PqScriptIssueParam();
|
||||||
issueParam.setSourceId(param.getSourceName());
|
SourceInitialize sourceInitialize = pqSourceService.getSourceInitializeParam(param.getSourceId());
|
||||||
|
issueParam.setSourceId(sourceInitialize.getSourceId());
|
||||||
issueParam.setPlanId(param.getPlanId());
|
issueParam.setPlanId(param.getPlanId());
|
||||||
issueParam.setDevIds(param.getDevIds());
|
issueParam.setDevIds(param.getDevIds());
|
||||||
issueParam.setScriptId(param.getScriptId());
|
issueParam.setScriptId(param.getScriptId());
|
||||||
@@ -1937,6 +1877,9 @@ 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);
|
||||||
@@ -1979,7 +1922,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 (!PowerIndexEnum.HSV.getKey().equals(sourceIssue.getType()) && !PowerIndexEnum.HSI.getKey().equals(sourceIssue.getType()) && !PowerIndexEnum.HP.getKey().equals(sourceIssue.getType())) {
|
if (!DicDataEnum.HSV.getCode().equals(sourceIssue.getType()) && !DicDataEnum.HSI.getCode().equals(sourceIssue.getType()) && !DicDataEnum.HP.getCode().equals(sourceIssue.getType())) {
|
||||||
if (CollUtil.isNotEmpty(data.getSqlData())) {
|
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();
|
||||||
@@ -2004,7 +1947,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 (PowerIndexEnum.HSV.getKey().equals(sourceIssue.getType()) || PowerIndexEnum.HSI.getKey().equals(sourceIssue.getType())) {
|
if (DicDataEnum.HSV.getCode().equals(sourceIssue.getType()) || DicDataEnum.HSI.getCode().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);
|
||||||
|
|||||||
@@ -0,0 +1,372 @@
|
|||||||
|
package com.njcn.gather.detection.handler;
|
||||||
|
|
||||||
|
import cn.hutool.core.collection.CollUtil;
|
||||||
|
import cn.hutool.core.collection.ListUtil;
|
||||||
|
import cn.hutool.core.util.IdUtil;
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import com.njcn.db.mybatisplus.handler.DynamicTableNameHandler;
|
||||||
|
import com.njcn.gather.detection.pojo.enums.DetectionCodeEnum;
|
||||||
|
import com.njcn.gather.detection.pojo.enums.SourceOperateCodeEnum;
|
||||||
|
import com.njcn.gather.detection.pojo.enums.SourceResponseCodeEnum;
|
||||||
|
import com.njcn.gather.detection.pojo.param.DevPhaseSequenceParam;
|
||||||
|
import com.njcn.gather.detection.pojo.po.DevData;
|
||||||
|
import com.njcn.gather.detection.pojo.vo.SocketDataMsg;
|
||||||
|
import com.njcn.gather.detection.pojo.vo.SocketMsg;
|
||||||
|
import com.njcn.gather.detection.util.socket.CnSocketUtil;
|
||||||
|
import com.njcn.gather.detection.util.socket.FormalTestManager;
|
||||||
|
import com.njcn.gather.detection.util.socket.MsgUtil;
|
||||||
|
import com.njcn.gather.detection.util.socket.SocketManager;
|
||||||
|
import com.njcn.gather.detection.util.socket.cilent.NettyClient;
|
||||||
|
import com.njcn.gather.detection.util.socket.cilent.NettyFreqConverterDevClientHandler;
|
||||||
|
import com.njcn.gather.detection.util.socket.config.SocketConnectionConfig;
|
||||||
|
import com.njcn.gather.detection.util.socket.websocket.WebServiceManager;
|
||||||
|
import com.njcn.gather.device.pojo.po.PqDev;
|
||||||
|
import com.njcn.gather.device.pojo.vo.PreDetection;
|
||||||
|
import com.njcn.gather.device.service.IPqDevService;
|
||||||
|
import com.njcn.gather.dip.pojo.po.PqDipData;
|
||||||
|
import com.njcn.gather.dip.service.IPqDipDataService;
|
||||||
|
import com.njcn.gather.freqConverter.config.FreqConverterConfig;
|
||||||
|
import com.njcn.gather.freqConverter.pojo.po.FreqConverterStatus;
|
||||||
|
import com.njcn.gather.freqConverter.pojo.po.PqFreqConverterTestRes;
|
||||||
|
import com.njcn.gather.freqConverter.service.IFreqConverterService;
|
||||||
|
import com.njcn.gather.freqConverter.service.IPqFreqConverterTestResService;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@Service
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class SocketFreqConverterDevService {
|
||||||
|
|
||||||
|
private final SocketConnectionConfig socketConnectionConfig;
|
||||||
|
private final IPqDevService pqDevService;
|
||||||
|
private final IPqDipDataService pqDipDataService;
|
||||||
|
private final IFreqConverterService freqConverterService;
|
||||||
|
private final IPqFreqConverterTestResService pqFreqConverterTestResService;
|
||||||
|
private final FreqConverterConfig freqConverterConfig;
|
||||||
|
private String monitorId;
|
||||||
|
private String userId;
|
||||||
|
|
||||||
|
public static final String DIP_DATA_SUFFIX = "&&VOLTAGE";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 连接设备Socket
|
||||||
|
*
|
||||||
|
* @param devTag 设备Channel唯一标识符
|
||||||
|
*/
|
||||||
|
public void connectSocket(String devTag) {
|
||||||
|
if (SocketManager.isChannelActive(devTag)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
String ip = socketConnectionConfig.getDevice().getIp();
|
||||||
|
Integer port = socketConnectionConfig.getDevice().getPort();
|
||||||
|
|
||||||
|
NettyFreqConverterDevClientHandler handler = new NettyFreqConverterDevClientHandler(devTag, this);
|
||||||
|
CompletableFuture.runAsync(() -> {
|
||||||
|
NettyClient.commonConnect(ip, port, devTag, handler);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void init(String userId, String converterId, String monitorId, Boolean reset) {
|
||||||
|
FormalTestManager.freqConverterDevStep = null;
|
||||||
|
// FormalTestManager.stopFlag = false;
|
||||||
|
FormalTestManager.isRemoveSocket = false;
|
||||||
|
FormalTestManager.pendingDipTaskMap.clear();
|
||||||
|
if (reset) {
|
||||||
|
pqDipDataService.clearAllData(FormalTestManager.freqConverterTableSuffix);
|
||||||
|
pqFreqConverterTestResService.clearAllData(FormalTestManager.freqConverterTableSuffix);
|
||||||
|
}
|
||||||
|
this.userId = userId;
|
||||||
|
this.monitorId = monitorId;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 连接设备
|
||||||
|
*/
|
||||||
|
public void connectionDev(String userId, String devTag, String converterId, String monitorId, Boolean reset) {
|
||||||
|
this.init(userId, converterId, monitorId, reset);
|
||||||
|
|
||||||
|
String payload = buildSingleMonitorPayload(monitorId);
|
||||||
|
if (StrUtil.isBlank(payload)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
SocketMsg<String> socketMsg = new SocketMsg<>();
|
||||||
|
socketMsg.setRequestId(SourceOperateCodeEnum.YJC_SBTXJY.getValue());
|
||||||
|
socketMsg.setOperateCode(SourceOperateCodeEnum.DEV_INIT_GATHER_03.getValue());
|
||||||
|
socketMsg.setData(payload);
|
||||||
|
SocketManager.sendMsg(devTag, JSON.toJSONString(socketMsg));
|
||||||
|
FormalTestManager.freqConverterDevStep = SourceOperateCodeEnum.YJC_SBTXJY;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void handleRead(String devTag, String msg) {
|
||||||
|
SocketDataMsg socketDataMsg = MsgUtil.socketDataMsg(msg);
|
||||||
|
|
||||||
|
switch (FormalTestManager.freqConverterDevStep) {
|
||||||
|
case YJC_SBTXJY:
|
||||||
|
handleYjcSbtxjy(devTag, socketDataMsg);
|
||||||
|
break;
|
||||||
|
case FORMAL_REAL:
|
||||||
|
handleFormalReal(devTag, socketDataMsg);
|
||||||
|
break;
|
||||||
|
case QUITE:
|
||||||
|
handleQuit(devTag, socketDataMsg);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void handleYjcSbtxjy(String devTag, SocketDataMsg socketDataMsg) {
|
||||||
|
SourceResponseCodeEnum responseCodeEnum = SourceResponseCodeEnum.getDictDataEnumByCode(socketDataMsg.getCode());
|
||||||
|
switch (Objects.requireNonNull(responseCodeEnum)) {
|
||||||
|
case UNPROCESSED_BUSINESS:
|
||||||
|
break;
|
||||||
|
case RE_OPERATE:
|
||||||
|
WebServiceManager.sendMsg(this.userId, JSON.toJSONString(socketDataMsg));
|
||||||
|
break;
|
||||||
|
case SUCCESS:
|
||||||
|
// 暂态协议触发后等待5秒,将装置历史缓存的暂态数据给抛掉
|
||||||
|
CompletableFuture.runAsync(() -> {
|
||||||
|
try {
|
||||||
|
Thread.sleep(5000);
|
||||||
|
this.sendGetDipDataMsg(devTag);
|
||||||
|
FormalTestManager.freqConverterDevStep = SourceOperateCodeEnum.FORMAL_REAL;
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
Thread.currentThread().interrupt();
|
||||||
|
log.error("异步调用sendGetDipDataMsg被中断", e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
log.warn("设备响应异常,devTag={}, operateCode={}, code={}, data={}", devTag, socketDataMsg.getOperateCode(), socketDataMsg.getCode(), socketDataMsg.getData());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void handleFormalReal(String devTag, SocketDataMsg socketDataMsg) {
|
||||||
|
SourceResponseCodeEnum responseCodeEnum = SourceResponseCodeEnum.getDictDataEnumByCode(socketDataMsg.getCode());
|
||||||
|
|
||||||
|
switch (responseCodeEnum) {
|
||||||
|
case UNPROCESSED_BUSINESS:
|
||||||
|
break;
|
||||||
|
case SUCCESS:
|
||||||
|
case NORMAL_RESPONSE:
|
||||||
|
DevData devData = JSON.parseObject(socketDataMsg.getData(), DevData.class);
|
||||||
|
// 如果变频器不是处于 “故障中” 状态,就保存数据,反之,这段时期内的数据不保存
|
||||||
|
// if (!FormalTestManager.stopFlag) {
|
||||||
|
// saveDipData(devData);
|
||||||
|
// }
|
||||||
|
saveDipData(devData);
|
||||||
|
break;
|
||||||
|
case DEV_ERROR:
|
||||||
|
case DEV_TARGET:
|
||||||
|
case COMMUNICATION_ERR:
|
||||||
|
case DATA_RESOLVE:
|
||||||
|
case NO_INIT_DEV:
|
||||||
|
default:
|
||||||
|
log.warn("设备响应异常,devTag={}, operateCode={}, code={}, data={}", devTag, socketDataMsg.getOperateCode(), socketDataMsg.getCode(), socketDataMsg.getData());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void handleQuit(String devTag, SocketDataMsg socketDataMsg) {
|
||||||
|
SourceResponseCodeEnum responseCodeEnum = SourceResponseCodeEnum.getDictDataEnumByCode(socketDataMsg.getCode());
|
||||||
|
|
||||||
|
switch (responseCodeEnum) {
|
||||||
|
case UNPROCESSED_BUSINESS:
|
||||||
|
break;
|
||||||
|
case SUCCESS:
|
||||||
|
cleanup(devTag);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
log.warn("设备关闭响应失败,devTag={}, operateCode={}, code={}, data={}", devTag, socketDataMsg.getOperateCode(), socketDataMsg.getCode(), socketDataMsg.getData());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void stopTest(String converterTag, String devTag) {
|
||||||
|
FormalTestManager.freqConverterDevStep = SourceOperateCodeEnum.QUITE;
|
||||||
|
sendQuitMsg(devTag, SourceOperateCodeEnum.QUIT_INIT_03);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private String buildSingleMonitorPayload(String monitorId) {
|
||||||
|
String[] split = monitorId.split(CnSocketUtil.SPLIT_TAG);
|
||||||
|
if (split.length < 2 || StrUtil.isBlank(split[0]) || StrUtil.isBlank(split[1])) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
List<PreDetection> preDetections = pqDevService.getDevInfo(Collections.singletonList(split[0]));
|
||||||
|
if (CollUtil.isEmpty(preDetections)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
PreDetection preDetection = preDetections.get(0);
|
||||||
|
List<PreDetection.MonitorListDTO> monitorList = preDetection.getMonitorList();
|
||||||
|
if (CollUtil.isEmpty(monitorList)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
List<PreDetection.MonitorListDTO> matchedMonitorList = monitorList.stream()
|
||||||
|
.filter(item -> split[1].equals(StrUtil.EMPTY + item.getLine()))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
if (CollUtil.isEmpty(matchedMonitorList)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
preDetection.setMonitorList(matchedMonitorList);
|
||||||
|
Map<String, List<PreDetection>> payload = new HashMap<>(1);
|
||||||
|
payload.put("deviceList", Collections.singletonList(preDetection));
|
||||||
|
return JSON.toJSONString(payload);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void sendGetDipDataMsg(String devTag) {
|
||||||
|
SocketMsg<String> socketMsg = new SocketMsg<>();
|
||||||
|
socketMsg.setRequestId(SourceOperateCodeEnum.FORMAL_REAL.getValue() + DIP_DATA_SUFFIX);
|
||||||
|
socketMsg.setOperateCode(SourceOperateCodeEnum.OPER_GATHER.getValue());
|
||||||
|
|
||||||
|
DevPhaseSequenceParam phaseSequenceParam = new DevPhaseSequenceParam();
|
||||||
|
String[] split = this.monitorId.split(String.valueOf(StrUtil.C_UNDERLINE));
|
||||||
|
PqDev dev = pqDevService.getById(split[0]);
|
||||||
|
|
||||||
|
// 设置监测点ID列表
|
||||||
|
phaseSequenceParam.setMoniterIdList(ListUtil.of(dev.getIp() + StrUtil.C_UNDERLINE + split[1]));
|
||||||
|
|
||||||
|
// 设置数据类型列表
|
||||||
|
phaseSequenceParam.setDataType(ListUtil.of("avg$MAG", "avg$DUR"));
|
||||||
|
// 设置读取次数
|
||||||
|
phaseSequenceParam.setReadCount(0);
|
||||||
|
// 设置忽略次数
|
||||||
|
phaseSequenceParam.setIgnoreCount(0);
|
||||||
|
socketMsg.setData(JSON.toJSONString(phaseSequenceParam));
|
||||||
|
socketMsg.setOperateCode(SourceOperateCodeEnum.DEV_DATA_REQUEST_03.getValue());
|
||||||
|
SocketManager.sendMsg(devTag, JSON.toJSONString(socketMsg));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void sendQuitMsg(String devTag, SourceOperateCodeEnum operateCodeEnum) {
|
||||||
|
SocketMsg<String> socketMsg = new SocketMsg<>();
|
||||||
|
socketMsg.setRequestId(SourceOperateCodeEnum.QUITE.getValue());
|
||||||
|
socketMsg.setOperateCode(operateCodeEnum.getValue());
|
||||||
|
SocketManager.sendMsg(devTag, JSON.toJSONString(socketMsg));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void saveDipData(DevData devData) {
|
||||||
|
if (Objects.isNull(devData) || CollUtil.isEmpty(devData.getSqlData())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Double residualVoltage = null;
|
||||||
|
Integer durationMs = null;
|
||||||
|
for (DevData.SqlDataDTO sqlDataDTO : devData.getSqlData()) {
|
||||||
|
if (Objects.isNull(sqlDataDTO) || Objects.isNull(sqlDataDTO.getList())) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
Double value = getSqlDataValue(sqlDataDTO.getList());
|
||||||
|
if (Objects.isNull(value)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (DetectionCodeEnum.MAG.getCode().equalsIgnoreCase(sqlDataDTO.getDesc())) {
|
||||||
|
residualVoltage = value;
|
||||||
|
if (residualVoltage <= 6) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} else if (DetectionCodeEnum.DUR.getCode().equalsIgnoreCase(sqlDataDTO.getDesc())) {
|
||||||
|
durationMs = (int) Math.round(value * 1000);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
PqDipData pqDipData = new PqDipData();
|
||||||
|
pqDipData.setId(IdUtil.fastSimpleUUID());
|
||||||
|
pqDipData.setStartTime(LocalDateTime.parse(devData.getTime()));
|
||||||
|
pqDipData.setResidualVoltage(residualVoltage);
|
||||||
|
pqDipData.setDurationMs(durationMs);
|
||||||
|
DynamicTableNameHandler.setTableName("pq_dip_data_" + FormalTestManager.freqConverterTableSuffix);
|
||||||
|
pqDipDataService.save(pqDipData);
|
||||||
|
DynamicTableNameHandler.remove();
|
||||||
|
|
||||||
|
this.initDipTestRes(pqDipData);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initDipTestRes(PqDipData pqDipData) {
|
||||||
|
Integer suffix = FormalTestManager.freqConverterTableSuffix;
|
||||||
|
FreqConverterStatus lastStatusData = freqConverterService.getLastStatusData(suffix, pqDipData.getStartTime());
|
||||||
|
if (Objects.isNull(lastStatusData)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
List<FreqConverterStatus> statusList = freqConverterService.getDipDurationStatusData(suffix, lastStatusData.getTimestamp(), pqDipData.getStartTime().plusNanos(pqDipData.getDurationMs() * 1000_000L));
|
||||||
|
Integer originalTolerant = (lastStatusData.getStatusWord1() == freqConverterConfig.getTolerant()) ? 1 : 0;
|
||||||
|
LocalDateTime targetEndTime = pqDipData.getStartTime()
|
||||||
|
.plusNanos(pqDipData.getDurationMs() * 1000_000L)
|
||||||
|
.plusNanos(freqConverterConfig.getDt() * 1000_000L);
|
||||||
|
|
||||||
|
if (CollUtil.isNotEmpty(statusList)) {
|
||||||
|
FreqConverterStatus status = statusList.get(statusList.size() - 1);
|
||||||
|
PqFreqConverterTestRes testRes = new PqFreqConverterTestRes();
|
||||||
|
testRes.setId(IdUtil.fastSimpleUUID());
|
||||||
|
testRes.setTolerant(originalTolerant == 1 ?
|
||||||
|
(status.getStatusWord1() == freqConverterConfig.getTolerant() ? 1 : 0)
|
||||||
|
: 0);
|
||||||
|
testRes.setDurationMs(pqDipData.getDurationMs());
|
||||||
|
testRes.setResidualVoltage(pqDipData.getResidualVoltage());
|
||||||
|
testRes.setTime(LocalDateTime.now());
|
||||||
|
|
||||||
|
FormalTestManager.pendingDipTaskMap.put(testRes.getId(), new FormalTestManager.PendingDipTask(
|
||||||
|
pqDipData,
|
||||||
|
targetEndTime,
|
||||||
|
originalTolerant
|
||||||
|
));
|
||||||
|
|
||||||
|
pqFreqConverterTestResService.saveTestRes(suffix, Collections.singletonList(testRes));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Double getSqlDataValue(DevData.SqlDataDTO.ListDTO listDTO) {
|
||||||
|
if (Objects.nonNull(listDTO.getA())) {
|
||||||
|
return listDTO.getA();
|
||||||
|
}
|
||||||
|
if (Objects.nonNull(listDTO.getB())) {
|
||||||
|
return listDTO.getB();
|
||||||
|
}
|
||||||
|
if (Objects.nonNull(listDTO.getC())) {
|
||||||
|
return listDTO.getC();
|
||||||
|
}
|
||||||
|
return listDTO.getT();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void cleanup(String devTag) {
|
||||||
|
String currentUserId = this.userId;
|
||||||
|
FormalTestManager.freqConverterDevStep = null;
|
||||||
|
FormalTestManager.isRemoveSocket = true;
|
||||||
|
SocketManager.removeUser(devTag);
|
||||||
|
clearStateIfStopped(currentUserId);
|
||||||
|
this.userId = null;
|
||||||
|
this.monitorId = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 如果设备已停止,则清除共享的运行时状态
|
||||||
|
*
|
||||||
|
* @param currentUserId 当前用户ID
|
||||||
|
*/
|
||||||
|
private void clearStateIfStopped(String currentUserId) {
|
||||||
|
if (StrUtil.isBlank(currentUserId)) {
|
||||||
|
FormalTestManager.clearFreqConverterRuntimeState();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
String freqConverterTag = currentUserId + CnSocketUtil.FREQ_CONVERTER_TAG;
|
||||||
|
// 避免过早把 freqConverterTableSuffix 等全局值清掉,造成变频器无法使用全局变量
|
||||||
|
if (!SocketManager.isChannelActive(freqConverterTag)) {
|
||||||
|
FormalTestManager.freqConverterStep = null;
|
||||||
|
FormalTestManager.clearFreqConverterRuntimeState();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,434 @@
|
|||||||
|
package com.njcn.gather.detection.handler;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.IdUtil;
|
||||||
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import cn.hutool.json.JSONObject;
|
||||||
|
import cn.hutool.json.JSONUtil;
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import com.njcn.gather.detection.pojo.dto.FreqConverterRespDTO;
|
||||||
|
import com.njcn.gather.detection.pojo.enums.SourceOperateCodeEnum;
|
||||||
|
import com.njcn.gather.detection.pojo.vo.SocketDataMsg;
|
||||||
|
import com.njcn.gather.detection.pojo.vo.SocketMsg;
|
||||||
|
import com.njcn.gather.detection.util.socket.CnSocketUtil;
|
||||||
|
import com.njcn.gather.detection.util.socket.FormalTestManager;
|
||||||
|
import com.njcn.gather.detection.util.socket.SocketManager;
|
||||||
|
import com.njcn.gather.detection.util.socket.cilent.NettyClient;
|
||||||
|
import com.njcn.gather.detection.util.socket.cilent.NettyFreqConverterClientHandler;
|
||||||
|
import com.njcn.gather.detection.util.socket.config.SocketConnectionConfig;
|
||||||
|
import com.njcn.gather.detection.util.socket.websocket.WebServiceManager;
|
||||||
|
import com.njcn.gather.freqConverter.config.FreqConverterConfig;
|
||||||
|
import com.njcn.gather.freqConverter.pojo.po.FreqConverterStatus;
|
||||||
|
import com.njcn.gather.freqConverter.pojo.po.PqFreqConverterConfig;
|
||||||
|
import com.njcn.gather.freqConverter.pojo.po.PqFreqConverterTestRes;
|
||||||
|
import com.njcn.gather.freqConverter.pojo.vo.TolerantPointVO;
|
||||||
|
import com.njcn.gather.freqConverter.service.IFreqConverterService;
|
||||||
|
import com.njcn.gather.freqConverter.service.IPqFreqConverterConfigService;
|
||||||
|
import com.njcn.gather.freqConverter.service.IPqFreqConverterTestResService;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
import java.util.concurrent.Executors;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author czh
|
||||||
|
* @version 1.0
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@Service
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class SocketFreqConverterService {
|
||||||
|
private final IFreqConverterService freqConverterService;
|
||||||
|
|
||||||
|
private final SocketConnectionConfig socketConnectionConfig;
|
||||||
|
|
||||||
|
private final IPqFreqConverterConfigService pqFreqConverterConfigService;
|
||||||
|
private final IPqFreqConverterTestResService pqFreqConverterTestResService;
|
||||||
|
private String userId;
|
||||||
|
/**
|
||||||
|
* 上一个暂降点耐受检测结果
|
||||||
|
*/
|
||||||
|
private TolerantPointVO lastTolerancePoint;
|
||||||
|
private final FreqConverterConfig freqConverterConfig;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 连接变频器Socket
|
||||||
|
*
|
||||||
|
* @param converterChannelTag 变频器Channel唯一标识符
|
||||||
|
*/
|
||||||
|
public void connectSocket(String converterChannelTag) {
|
||||||
|
if (SocketManager.isChannelActive(converterChannelTag)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
String ip = socketConnectionConfig.getFreqConverter().getIp();
|
||||||
|
Integer port = socketConnectionConfig.getFreqConverter().getPort();
|
||||||
|
|
||||||
|
NettyFreqConverterClientHandler handler = new NettyFreqConverterClientHandler(converterChannelTag, this);
|
||||||
|
|
||||||
|
CompletableFuture.runAsync(() -> {
|
||||||
|
NettyClient.commonConnect(ip, port, converterChannelTag, handler);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 重连
|
||||||
|
*
|
||||||
|
* @param converterChannelTag
|
||||||
|
*/
|
||||||
|
public void reconnect(String converterChannelTag) {
|
||||||
|
SocketManager.removeUser(converterChannelTag);
|
||||||
|
|
||||||
|
String ip = socketConnectionConfig.getFreqConverter().getIp();
|
||||||
|
Integer port = socketConnectionConfig.getFreqConverter().getPort();
|
||||||
|
|
||||||
|
NettyFreqConverterClientHandler handler = new NettyFreqConverterClientHandler(converterChannelTag, this);
|
||||||
|
|
||||||
|
CompletableFuture.runAsync(() -> {
|
||||||
|
NettyClient.commonConnect(ip, port, converterChannelTag, handler);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 重试连接成功,重新开启定时任务,获取变频器状态数据
|
||||||
|
*
|
||||||
|
* @param converterChannelTag
|
||||||
|
*/
|
||||||
|
public void onReconnectSuccess(String converterChannelTag) {
|
||||||
|
log.info("变频器重连成功,恢复数据采集,converterChannelTag={}", converterChannelTag);
|
||||||
|
|
||||||
|
// FormalTestManager.stopFlag = false;
|
||||||
|
|
||||||
|
if (FormalTestManager.scheduler == null) {
|
||||||
|
FormalTestManager.scheduler = Executors.newScheduledThreadPool(1);
|
||||||
|
FormalTestManager.scheduledFuture = FormalTestManager.scheduler.scheduleAtFixedRate(() -> {
|
||||||
|
this.sendGetDeviceStatusMsg(converterChannelTag);
|
||||||
|
}, 0l, 200l, TimeUnit.MILLISECONDS);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void init(String userId, String converterId, String monitorId, Boolean reset) {
|
||||||
|
this.lastTolerancePoint = null;
|
||||||
|
this.userId = userId;
|
||||||
|
FormalTestManager.freqConverterStep = null;
|
||||||
|
FormalTestManager.currentFreqConverterId = converterId;
|
||||||
|
Integer suffix = pqFreqConverterConfigService.getSuffix(converterId);
|
||||||
|
if (reset) {
|
||||||
|
freqConverterService.clearAllData(suffix);
|
||||||
|
}
|
||||||
|
FormalTestManager.freqConverterTableSuffix = suffix;
|
||||||
|
FormalTestManager.isRemoveSocket = false;
|
||||||
|
FormalTestManager.pendingDipTaskMap.clear();
|
||||||
|
pqFreqConverterConfigService.updateTestStatus(converterId, 0);
|
||||||
|
clearScheduleTask();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 连接变频器
|
||||||
|
*/
|
||||||
|
public void connectionFreqConverter(String userId, String freqConverterTag, String converterId, String monitorId, Boolean reset) {
|
||||||
|
this.init(userId, converterId, monitorId, reset);
|
||||||
|
|
||||||
|
SocketMsg<Map<String, Object>> socketMsg = new SocketMsg<>();
|
||||||
|
socketMsg.setOperateCode(SourceOperateCodeEnum.CMD_INIT_SERIAL.getValue());
|
||||||
|
String requestId = IdUtil.fastSimpleUUID();
|
||||||
|
socketMsg.setRequestId(requestId);
|
||||||
|
|
||||||
|
PqFreqConverterConfig freqConverterConfig = pqFreqConverterConfigService.getById(converterId);
|
||||||
|
|
||||||
|
Map<String, Object> map = new HashMap<>();
|
||||||
|
map.put("portName", freqConverterConfig.getPortName());
|
||||||
|
map.put("slaveAddress", freqConverterConfig.getSlaveAddress());
|
||||||
|
map.put("baudRate", freqConverterConfig.getBaudRate());
|
||||||
|
map.put("parity", freqConverterConfig.getParity());
|
||||||
|
map.put("dataBits", freqConverterConfig.getDataBits());
|
||||||
|
map.put("stopBits", freqConverterConfig.getStopBits());
|
||||||
|
map.put("timeoutMs", freqConverterConfig.getTimeoutMs());
|
||||||
|
socketMsg.setData(map);
|
||||||
|
|
||||||
|
SocketManager.sendMsg(freqConverterTag, JSON.toJSONString(socketMsg));
|
||||||
|
FormalTestManager.freqConverterStep = SourceOperateCodeEnum.CMD_INIT_SERIAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void handleRead(String converterChannelTag, String msg) {
|
||||||
|
FreqConverterRespDTO respDTO = JSON.parseObject(msg, FreqConverterRespDTO.class);
|
||||||
|
|
||||||
|
if (respDTO.getCode() != 0) {
|
||||||
|
SocketDataMsg socketDataMsg = new SocketDataMsg();
|
||||||
|
socketDataMsg.setRequestId(FormalTestManager.freqConverterStep.getValue());
|
||||||
|
socketDataMsg.setCode(respDTO.getCode());
|
||||||
|
WebServiceManager.sendMsg(this.userId, JSON.toJSONString(socketDataMsg));
|
||||||
|
} else {
|
||||||
|
switch (FormalTestManager.freqConverterStep) {
|
||||||
|
case CMD_INIT_SERIAL:
|
||||||
|
handleInitSerial(converterChannelTag, respDTO);
|
||||||
|
break;
|
||||||
|
case CMD_GET_DEVICE_STATUS:
|
||||||
|
handleGetDeviceStatus(converterChannelTag, respDTO);
|
||||||
|
break;
|
||||||
|
case CMD_CLOSE_SERIAL:
|
||||||
|
handleCloseSerial(converterChannelTag, respDTO);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void stopTest(String converterTag, String devTag) {
|
||||||
|
FormalTestManager.freqConverterStep = SourceOperateCodeEnum.CMD_CLOSE_SERIAL;
|
||||||
|
this.sendClose(converterTag);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void cleanup(String converterChannelTag) {
|
||||||
|
String currentUserId = this.userId;
|
||||||
|
clearScheduleTask();
|
||||||
|
FormalTestManager.freqConverterStep = null;
|
||||||
|
// FormalTestManager.stopFlag = false;
|
||||||
|
FormalTestManager.isRemoveSocket = true;
|
||||||
|
SocketManager.removeUser(converterChannelTag);
|
||||||
|
updateCurrentTestStatus();
|
||||||
|
clearStateIfStopped(currentUserId);
|
||||||
|
this.userId = null;
|
||||||
|
this.lastTolerancePoint = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void handleInitSerial(String converterChannelTag, FreqConverterRespDTO respDTO) {
|
||||||
|
if (respDTO.getCode() == 0 && respDTO.getSuccess()) {
|
||||||
|
FormalTestManager.freqConverterStep = SourceOperateCodeEnum.CMD_GET_DEVICE_STATUS;
|
||||||
|
|
||||||
|
if (Objects.isNull(FormalTestManager.scheduler)) {
|
||||||
|
FormalTestManager.scheduler = Executors.newScheduledThreadPool(1);
|
||||||
|
FormalTestManager.scheduledFuture = FormalTestManager.scheduler.scheduleAtFixedRate(() -> {
|
||||||
|
this.sendGetDeviceStatusMsg(converterChannelTag);
|
||||||
|
}, 0l, freqConverterConfig.getSchedulePeriod(), TimeUnit.MILLISECONDS);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
log.warn("变频器初始化串口失败,converterChannelTag={}, converterId={}, converterTag={}, msg={}", converterChannelTag, converterChannelTag, converterChannelTag, respDTO.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void handleGetDeviceStatus(String converterChannelTag, FreqConverterRespDTO respDTO) {
|
||||||
|
JSONObject obj = JSONUtil.parseObj(respDTO.getData().toString());
|
||||||
|
String timestamp = (String) obj.get("Timestamp");
|
||||||
|
timestamp = timestamp.replace("+08:00", StrUtil.EMPTY);
|
||||||
|
obj.set("Timestamp", timestamp);
|
||||||
|
|
||||||
|
FreqConverterStatus freqConverterStatus = JSON.parseObject(obj.toString(), FreqConverterStatus.class);
|
||||||
|
// 变频器故障中,移除这段时期内的设备数据
|
||||||
|
// if (freqConverterStatus.getStatusWord1() == freqConverterConfig.getNoTolerant()) {
|
||||||
|
// FormalTestManager.stopFlag = true;
|
||||||
|
// } else {
|
||||||
|
// FormalTestManager.stopFlag = false;
|
||||||
|
// }
|
||||||
|
this.consumePendingDipTasks(freqConverterStatus);
|
||||||
|
freqConverterService.saveFreqConverterStatus(FormalTestManager.freqConverterTableSuffix, freqConverterStatus);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void handleCloseSerial(String converterChannelTag, FreqConverterRespDTO respDTO) {
|
||||||
|
if (FormalTestManager.currentFreqConverterId != null) {
|
||||||
|
pqFreqConverterConfigService.updateTestStatus(FormalTestManager.currentFreqConverterId, 1);
|
||||||
|
}
|
||||||
|
cleanup(converterChannelTag);
|
||||||
|
// if (respDTO.getCode() == 0 && respDTO.getSuccess()) {
|
||||||
|
//
|
||||||
|
// } else {
|
||||||
|
// this.sendClose(converterChannelTag);
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void sendGetDeviceStatusMsg(String converterId) {
|
||||||
|
SocketMsg<Map<String, Object>> socketMsg = new SocketMsg<>();
|
||||||
|
socketMsg.setOperateCode(SourceOperateCodeEnum.CMD_GET_DEVICE_STATUS.getValue());
|
||||||
|
String requestId = IdUtil.fastSimpleUUID();
|
||||||
|
socketMsg.setRequestId(requestId);
|
||||||
|
|
||||||
|
Map<String, Object> map = new HashMap<>();
|
||||||
|
socketMsg.setData(map);
|
||||||
|
SocketManager.sendMsg(converterId, JSON.toJSONString(socketMsg));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void sendClose(String converterTag) {
|
||||||
|
SocketMsg<Map<String, Object>> socketMsg = new SocketMsg<>();
|
||||||
|
socketMsg.setOperateCode(SourceOperateCodeEnum.CMD_CLOSE_SERIAL.getValue());
|
||||||
|
String requestId = IdUtil.fastSimpleUUID();
|
||||||
|
socketMsg.setRequestId(requestId);
|
||||||
|
|
||||||
|
Map<String, Object> map = new HashMap<>();
|
||||||
|
socketMsg.setData(map);
|
||||||
|
SocketManager.sendMsg(converterTag, JSON.toJSONString(socketMsg));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void clearScheduleTask() {
|
||||||
|
if (FormalTestManager.scheduledFuture != null) {
|
||||||
|
FormalTestManager.scheduledFuture.cancel(true);
|
||||||
|
FormalTestManager.scheduledFuture = null;
|
||||||
|
}
|
||||||
|
if (FormalTestManager.scheduler != null) {
|
||||||
|
FormalTestManager.scheduler.shutdown();
|
||||||
|
FormalTestManager.scheduler = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateCurrentTestStatus() {
|
||||||
|
if (StrUtil.isNotBlank(FormalTestManager.currentFreqConverterId)) {
|
||||||
|
pqFreqConverterConfigService.updateTestStatus(FormalTestManager.currentFreqConverterId, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 如果变频器已停止,则清除共享的运行时状态
|
||||||
|
*
|
||||||
|
* @param currentUserId 当前用户ID
|
||||||
|
*/
|
||||||
|
private void clearStateIfStopped(String currentUserId) {
|
||||||
|
if (StrUtil.isBlank(currentUserId)) {
|
||||||
|
FormalTestManager.clearFreqConverterRuntimeState();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
String devTag = currentUserId + CnSocketUtil.DEV_TAG;
|
||||||
|
// 避免过早把 freqConverterTableSuffix 等全局值清掉,造成设备无法使用全局变量
|
||||||
|
if (!SocketManager.isChannelActive(devTag)) {
|
||||||
|
FormalTestManager.freqConverterDevStep = null;
|
||||||
|
FormalTestManager.clearFreqConverterRuntimeState();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void consumePendingDipTasks(FreqConverterStatus freqConverterStatus) {
|
||||||
|
if (FormalTestManager.pendingDipTaskMap.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Integer suffix = FormalTestManager.freqConverterTableSuffix;
|
||||||
|
List<String> finishedTestResIdList = new ArrayList<>();
|
||||||
|
List<PqFreqConverterTestRes> saveTestResList = new ArrayList<>();
|
||||||
|
List<PqFreqConverterTestRes> updateTestResList = new ArrayList<>();
|
||||||
|
|
||||||
|
FormalTestManager.pendingDipTaskMap.forEach((key, task) -> {
|
||||||
|
if (freqConverterStatus.getTimestamp().isAfter(task.getTargetEndTime())) {
|
||||||
|
PqFreqConverterTestRes testRes = new PqFreqConverterTestRes();
|
||||||
|
testRes.setId(key);
|
||||||
|
testRes.setDurationMs(task.getPqDipData().getDurationMs());
|
||||||
|
testRes.setResidualVoltage(task.getPqDipData().getResidualVoltage());
|
||||||
|
testRes.setTolerant(task.getOriginalTolerant() & (freqConverterStatus.getStatusWord1() == freqConverterConfig.getTolerant() ? 1 : 0));
|
||||||
|
|
||||||
|
finishedTestResIdList.add(key);
|
||||||
|
|
||||||
|
SocketDataMsg socketDataMsg = new SocketDataMsg();
|
||||||
|
socketDataMsg.setRequestId(SourceOperateCodeEnum.FORMAL_REAL + SocketFreqConverterDevService.DIP_DATA_SUFFIX);
|
||||||
|
|
||||||
|
TolerantPointVO newTolerantPointVO = new TolerantPointVO();
|
||||||
|
newTolerantPointVO.setResidualVoltage(task.getPqDipData().getResidualVoltage());
|
||||||
|
newTolerantPointVO.setDurationMs(task.getPqDipData().getDurationMs());
|
||||||
|
newTolerantPointVO.setTolerant(testRes.getTolerant());
|
||||||
|
socketDataMsg.setData(JSON.toJSONString(newTolerantPointVO));
|
||||||
|
WebServiceManager.sendMsg(this.userId, JSON.toJSONString(socketDataMsg));
|
||||||
|
|
||||||
|
if (testRes.getTolerant() == 0) {
|
||||||
|
if (ObjectUtil.isNotNull(this.lastTolerancePoint) && this.lastTolerancePoint.getTolerant() == 1) {
|
||||||
|
TolerantPointVO featurePointVO = new TolerantPointVO();
|
||||||
|
|
||||||
|
featurePointVO.setResidualVoltage(Math.round((task.getPqDipData().getResidualVoltage() + this.lastTolerancePoint.getResidualVoltage()) / 2D * 100) / 100D);
|
||||||
|
featurePointVO.setDurationMs(Integer.valueOf((task.getPqDipData().getDurationMs().intValue() + this.lastTolerancePoint.getDurationMs().intValue()) / 2));
|
||||||
|
featurePointVO.setTolerant(2);
|
||||||
|
socketDataMsg.setData(JSON.toJSONString(featurePointVO));
|
||||||
|
WebServiceManager.sendMsg(this.userId, JSON.toJSONString(socketDataMsg));
|
||||||
|
|
||||||
|
PqFreqConverterTestRes featureTestRes = new PqFreqConverterTestRes();
|
||||||
|
featureTestRes.setId(IdUtil.fastSimpleUUID());
|
||||||
|
featureTestRes.setDurationMs(featurePointVO.getDurationMs());
|
||||||
|
featureTestRes.setResidualVoltage(featurePointVO.getResidualVoltage());
|
||||||
|
featureTestRes.setTolerant(2);
|
||||||
|
featureTestRes.setTime(LocalDateTime.now());
|
||||||
|
saveTestResList.add(featureTestRes);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 从数据库按照列查询距离该暂降点最近的一个暂降点
|
||||||
|
if (freqConverterConfig.getDirection() == 0) {
|
||||||
|
PqFreqConverterTestRes lastByDuration = pqFreqConverterTestResService.getLastByDuration(suffix, key, task.getPqDipData().getDurationMs());
|
||||||
|
if (ObjectUtil.isNotNull(lastByDuration) && lastByDuration.getTolerant() == 1) {
|
||||||
|
TolerantPointVO featurePointVO = new TolerantPointVO();
|
||||||
|
|
||||||
|
featurePointVO.setResidualVoltage(Math.round((task.getPqDipData().getResidualVoltage() + lastByDuration.getResidualVoltage()) / 2D * 100) / 100D);
|
||||||
|
featurePointVO.setDurationMs(Integer.valueOf((task.getPqDipData().getDurationMs().intValue() + lastByDuration.getDurationMs().intValue()) / 2));
|
||||||
|
featurePointVO.setTolerant(2);
|
||||||
|
socketDataMsg.setData(JSON.toJSONString(featurePointVO));
|
||||||
|
WebServiceManager.sendMsg(this.userId, JSON.toJSONString(socketDataMsg));
|
||||||
|
|
||||||
|
PqFreqConverterTestRes featureTestRes = new PqFreqConverterTestRes();
|
||||||
|
featureTestRes.setId(IdUtil.fastSimpleUUID());
|
||||||
|
featureTestRes.setDurationMs(featurePointVO.getDurationMs());
|
||||||
|
featureTestRes.setResidualVoltage(featurePointVO.getResidualVoltage());
|
||||||
|
featureTestRes.setTolerant(2);
|
||||||
|
featureTestRes.setTime(LocalDateTime.now());
|
||||||
|
saveTestResList.add(featureTestRes);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 从数据库按照行查询距离该暂降点最近的一个暂降点
|
||||||
|
if (freqConverterConfig.getDirection() == 1) {
|
||||||
|
PqFreqConverterTestRes lastByResidualVoltage = pqFreqConverterTestResService.getLastByResidualVoltage(suffix, key, task.getPqDipData().getResidualVoltage());
|
||||||
|
if (ObjectUtil.isNotNull(lastByResidualVoltage) && lastByResidualVoltage.getTolerant() == 1) {
|
||||||
|
TolerantPointVO featurePointVO = new TolerantPointVO();
|
||||||
|
|
||||||
|
featurePointVO.setResidualVoltage(Math.round((task.getPqDipData().getResidualVoltage() + lastByResidualVoltage.getResidualVoltage()) / 2D * 100) / 100D);
|
||||||
|
featurePointVO.setDurationMs(Integer.valueOf((task.getPqDipData().getDurationMs().intValue() + lastByResidualVoltage.getDurationMs().intValue()) / 2));
|
||||||
|
featurePointVO.setTolerant(2);
|
||||||
|
socketDataMsg.setData(JSON.toJSONString(featurePointVO));
|
||||||
|
WebServiceManager.sendMsg(this.userId, JSON.toJSONString(socketDataMsg));
|
||||||
|
|
||||||
|
PqFreqConverterTestRes featureTestRes = new PqFreqConverterTestRes();
|
||||||
|
featureTestRes.setId(IdUtil.fastSimpleUUID());
|
||||||
|
featureTestRes.setDurationMs(featurePointVO.getDurationMs());
|
||||||
|
featureTestRes.setResidualVoltage(featurePointVO.getResidualVoltage());
|
||||||
|
featureTestRes.setTolerant(2);
|
||||||
|
featureTestRes.setTime(LocalDateTime.now());
|
||||||
|
saveTestResList.add(featureTestRes);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.lastTolerancePoint = newTolerantPointVO;
|
||||||
|
updateTestResList.add(testRes);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!saveTestResList.isEmpty()) {
|
||||||
|
pqFreqConverterTestResService.saveTestRes(suffix, saveTestResList);
|
||||||
|
}
|
||||||
|
if (!updateTestResList.isEmpty()) {
|
||||||
|
pqFreqConverterTestResService.updateTestRes(suffix, updateTestResList);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (String dipId : finishedTestResIdList) {
|
||||||
|
FormalTestManager.pendingDipTaskMap.remove(dipId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 判断是否为新的一组测试脚本
|
||||||
|
*
|
||||||
|
* @param lastTolerancePoint 上一个暂降点
|
||||||
|
* @param newTolerantPointVO 最新的暂降点
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private boolean isNewGroup(TolerantPointVO lastTolerancePoint, TolerantPointVO newTolerantPointVO) {
|
||||||
|
// 横向分组
|
||||||
|
if (freqConverterConfig.getDirection() == 0) {
|
||||||
|
return lastTolerancePoint.getDurationMs() - newTolerantPointVO.getDurationMs() >= 10;
|
||||||
|
}
|
||||||
|
// 纵向分租
|
||||||
|
if (freqConverterConfig.getDirection() == 1) {
|
||||||
|
return lastTolerancePoint.getResidualVoltage() - newTolerantPointVO.getResidualVoltage() <= -2;
|
||||||
|
}
|
||||||
|
|
||||||
|
// if (Math.abs(lastTolerancePoint.getDurationMs() - newTolerantPointVO.getDurationMs()) >= 10 && Math.abs(lastTolerancePoint.getResidualVoltage() - newTolerantPointVO.getResidualVoltage()) >= 2) {
|
||||||
|
// return true;
|
||||||
|
// }
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -17,10 +17,11 @@ 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.report.pojo.enums.PowerIndexEnum;
|
import com.njcn.gather.result.pojo.enums.ResultUnitEnum;
|
||||||
import com.njcn.gather.script.pojo.po.SourceIssue;
|
import com.njcn.gather.script.pojo.po.SourceIssue;
|
||||||
import com.njcn.gather.source.pojo.po.SourceInitialize;
|
import com.njcn.gather.source.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;
|
||||||
@@ -120,15 +121,6 @@ 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);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 当前检测会话中的设备列表
|
* 当前检测会话中的设备列表
|
||||||
@@ -222,12 +214,12 @@ public class SocketSourceResponseService {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
sendSimulateInitFailure(param, "未知操作码");
|
// TODO: 记录未知操作码到日志,并向前端发送友好提示
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
// TODO: 向前端发送错误提示
|
||||||
log.error("程控源响应消息操作码解析失败,原始消息: {}, 解析结果: {}", msg, enumByCode);
|
log.error("程控源响应消息操作码解析失败,原始消息: {}, 解析结果: {}", msg, enumByCode);
|
||||||
sendSimulateInitFailure(param, "未知操作码");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -280,11 +272,10 @@ 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, "未知状态码");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -385,35 +376,26 @@ public class SocketSourceResponseService {
|
|||||||
|
|
||||||
//重新下发脚本
|
//重新下发脚本
|
||||||
String type = FormalTestManager.currentIssue.getType();
|
String type = FormalTestManager.currentIssue.getType();
|
||||||
if (PowerIndexEnum.P.getKey().equals(type)) {
|
if (ResultUnitEnum.P.getCode().equals(type)) {
|
||||||
FormalTestManager.currentIssue.setType(PowerIndexEnum.V.getKey());
|
FormalTestManager.currentIssue.setType(ResultUnitEnum.V_ABSOLUTELY.getCode());
|
||||||
}
|
}
|
||||||
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 {
|
} else {
|
||||||
// 推送过载测试结果
|
//todo 前端推送收到的消息暂未处理好
|
||||||
SocketDataMsg overloadSocketDataMsg = new SocketDataMsg();
|
sendWebSocketMessage(param.getUserPageId(), socketDataMsg);
|
||||||
overloadSocketDataMsg.setRequestId("overloadTest");
|
//开始设备通讯检测(发送设备初始化)
|
||||||
overloadSocketDataMsg.setCode(FormalTestManager.overload);
|
Map<String, List<PreDetection>> map = new HashMap<>(1);
|
||||||
sendWebSocketMessage(param.getUserPageId(), overloadSocketDataMsg);
|
map.put("deviceList", FormalTestManager.devList);
|
||||||
if (FormalTestManager.overload != 4) {
|
String jsonString = JSON.toJSONString(map);
|
||||||
CnSocketUtil.quitSendSource(param);
|
socketMsg.setRequestId(SourceOperateCodeEnum.YJC_SBTXJY.getValue());
|
||||||
} else {
|
socketMsg.setOperateCode(SourceOperateCodeEnum.DEV_INIT_GATHER_01.getValue());
|
||||||
//todo 前端推送收到的消息暂未处理好
|
socketMsg.setData(jsonString);
|
||||||
sendWebSocketMessage(param.getUserPageId(), socketDataMsg);
|
String json = JSON.toJSONString(socketMsg);
|
||||||
//开始设备通讯检测(发送设备初始化)
|
// 使用智能发送工具类,自动管理设备连接
|
||||||
Map<String, List<PreDetection>> map = new HashMap<>(1);
|
socketManager.smartSendToDevice(param, json);
|
||||||
map.put("deviceList", FormalTestManager.devList);
|
|
||||||
String jsonString = JSON.toJSONString(map);
|
|
||||||
socketMsg.setRequestId(SourceOperateCodeEnum.YJC_SBTXJY.getValue());
|
|
||||||
socketMsg.setOperateCode(SourceOperateCodeEnum.DEV_INIT_GATHER_01.getValue());
|
|
||||||
socketMsg.setData(jsonString);
|
|
||||||
String json = JSON.toJSONString(socketMsg);
|
|
||||||
// 使用智能发送工具类,自动管理设备连接
|
|
||||||
socketManager.smartSendToDevice(param, json);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case UNPROCESSED_BUSINESS:
|
case UNPROCESSED_BUSINESS:
|
||||||
@@ -537,14 +519,14 @@ public class SocketSourceResponseService {
|
|||||||
int ignoreCount;
|
int ignoreCount;
|
||||||
int readData;
|
int readData;
|
||||||
|
|
||||||
if (PowerIndexEnum.F.getKey().equals(sourceIssue.getType())) {
|
if (DicDataEnum.F.getCode().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 (PowerIndexEnum.VOLTAGE.getKey().equals(sourceIssue.getType())) {
|
} else if (DicDataEnum.VOLTAGE.getCode().equals(sourceIssue.getType())) {
|
||||||
// 暂态电压检测:需要更多预热时间,但只读取一次快照
|
// 暂态电压检测:需要更多预热时间,但只读取一次快照
|
||||||
// 暂态事件需要5次预热确保触发稳定
|
// 暂态事件需要5次预热确保触发稳定
|
||||||
ignoreCount = 5;
|
ignoreCount = 5;
|
||||||
@@ -574,6 +556,9 @@ 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);
|
||||||
// 设置读取次数
|
// 设置读取次数
|
||||||
|
|||||||
@@ -1,29 +0,0 @@
|
|||||||
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; }
|
|
||||||
}
|
|
||||||
@@ -1,134 +0,0 @@
|
|||||||
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; }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
package com.njcn.gather.detection.pojo.dto;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonAlias;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author caozehui
|
||||||
|
* @data 2026-04-08
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class FreqConverterRespDTO {
|
||||||
|
/**
|
||||||
|
* 请求编号
|
||||||
|
*/
|
||||||
|
@JsonAlias({"RequestId"})
|
||||||
|
private String requestId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否成功
|
||||||
|
*/
|
||||||
|
@JsonAlias({"Success"})
|
||||||
|
private Boolean success;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 状态码
|
||||||
|
*/
|
||||||
|
@JsonAlias({"Code"})
|
||||||
|
private Integer code;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 消息
|
||||||
|
*/
|
||||||
|
@JsonAlias({"Message"})
|
||||||
|
private String message;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据
|
||||||
|
*/
|
||||||
|
@JsonAlias({"Data"})
|
||||||
|
private Object data;
|
||||||
|
}
|
||||||
@@ -33,19 +33,13 @@ 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", "功率因数"),
|
||||||
TOTW("TotW", "三相总有功功率"),
|
// P_FUND("P_FUND", "基波有功功率"),
|
||||||
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", "基波电流"),
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ 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", "检测进行中");
|
SOCKET_CONNECT_TIMEOUT("A020042","socket连接超时!");
|
||||||
|
|
||||||
private final String code;
|
private final String code;
|
||||||
private final String message;
|
private final String message;
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ public enum SourceOperateCodeEnum {
|
|||||||
YJC_MXYZXJY("yjc_mxyzxjy", "模型一致性校验"),
|
YJC_MXYZXJY("yjc_mxyzxjy", "模型一致性校验"),
|
||||||
FORMAL_REAL("formal_real","正式检测"),
|
FORMAL_REAL("formal_real","正式检测"),
|
||||||
RECORD_WAVE_STEP1("record_wave_step1","启动录波_step1"),
|
RECORD_WAVE_STEP1("record_wave_step1","启动录波_step1"),
|
||||||
// RECORD_WAVE_STEP2("record_wave_step2","启动录波_step2"),
|
// RECORD_WAVE_STEP2("record_wave_step2","启动录波_step2"),
|
||||||
// SIMULATE_REAL("simulate_real","模拟检测"),
|
// SIMULATE_REAL("simulate_real","模拟检测"),
|
||||||
Coefficient_Check("Coefficient_Check","系数校验"),
|
Coefficient_Check("Coefficient_Check","系数校验"),
|
||||||
QUITE("quit","关闭设备通讯初始化"),
|
QUITE("quit","关闭设备通讯初始化"),
|
||||||
@@ -70,9 +70,6 @@ public enum SourceOperateCodeEnum {
|
|||||||
FLICKER_DATA_CHECK("flicker_data_check","闪变数据校验"),
|
FLICKER_DATA_CHECK("flicker_data_check","闪变数据校验"),
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@@ -100,12 +97,17 @@ public enum SourceOperateCodeEnum {
|
|||||||
small_comp_start("small_comp_start","小电压校准开始"),
|
small_comp_start("small_comp_start","小电压校准开始"),
|
||||||
small_comp_end("small_comp_end","小电压校准结束"),
|
small_comp_end("small_comp_end","小电压校准结束"),
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ftp文件传送指令
|
* ftp文件传送指令
|
||||||
*/
|
*/
|
||||||
FTP_SEND_01("FTP_SEND$01", "发送文件"),
|
FTP_SEND_01("FTP_SEND$01", "发送文件"),
|
||||||
RDRE$01("RDRE$01", "启动录波");
|
RDRE$01("RDRE$01", "启动录波"),
|
||||||
|
|
||||||
|
CMD_PING("ping", "检查 TCP 服务是否在线"),
|
||||||
|
CMD_INIT_SERIAL("initSerial", "初始化并打开串口连接"),
|
||||||
|
CMD_GET_SERIAL_CONFIG("getSerialConfig", "获取当前串口配置"),
|
||||||
|
CMD_GET_DEVICE_STATUS("getDeviceStatus", "读取变频器运行状态"),
|
||||||
|
CMD_CLOSE_SERIAL("closeSerial", "关闭串口"),;
|
||||||
|
|
||||||
private final String value;
|
private final String value;
|
||||||
private final String msg;
|
private final String msg;
|
||||||
|
|||||||
@@ -38,31 +38,10 @@ 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;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,25 +0,0 @@
|
|||||||
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,6 +5,7 @@ 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
|
||||||
@@ -45,11 +46,6 @@ public class PreDetectionParam {
|
|||||||
*/
|
*/
|
||||||
private String sourceId;
|
private String sourceId;
|
||||||
|
|
||||||
/**
|
|
||||||
* 源名称
|
|
||||||
*/
|
|
||||||
private String sourceName;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 所属误差体系
|
* 所属误差体系
|
||||||
*/
|
*/
|
||||||
@@ -75,36 +71,7 @@ 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));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,22 +0,0 @@
|
|||||||
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;
|
|
||||||
}
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
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<>();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
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,13 +1,8 @@
|
|||||||
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.Map;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -35,10 +30,6 @@ public interface PreDetectionService {
|
|||||||
|
|
||||||
boolean restartTemTest(PreDetectionParam param);
|
boolean restartTemTest(PreDetectionParam param);
|
||||||
|
|
||||||
void saveFormalProgress(FormalProgressParam param);
|
|
||||||
|
|
||||||
FormalProgressVO formalProgress(FormalProgressParam param);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 模拟测试-源通讯校验
|
* 模拟测试-源通讯校验
|
||||||
*
|
*
|
||||||
@@ -61,7 +52,6 @@ public interface PreDetectionService {
|
|||||||
void closeTestSimulate(SimulateDetectionParam param);
|
void closeTestSimulate(SimulateDetectionParam param);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @param param
|
* @param param
|
||||||
*/
|
*/
|
||||||
void startContrastTest(ContrastDetectionParam param);
|
void startContrastTest(ContrastDetectionParam param);
|
||||||
@@ -74,4 +64,8 @@ public interface PreDetectionService {
|
|||||||
boolean getCanCoefficient();
|
boolean getCanCoefficient();
|
||||||
|
|
||||||
void startCoefficient();
|
void startCoefficient();
|
||||||
|
|
||||||
|
void startFreqConverter(String userId, String converterId, String monitorId,Boolean reset);
|
||||||
|
|
||||||
|
void stopFreqConverter(String converterId, String monitorId);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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.script.mapper.PqScriptMapper;
|
import com.njcn.gather.result.pojo.enums.ResultUnitEnum;
|
||||||
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,7 +73,6 @@ 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";
|
||||||
@@ -81,6 +80,7 @@ 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,31 +161,30 @@ 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);
|
||||||
PowerIndexEnum powerIndexEnum = PowerIndexEnum.getByKey(sourceIssue.getType());
|
ResultUnitEnum resultUnitEnumByCode = ResultUnitEnum.getResultUnitEnumByCode(sourceIssue.getType());
|
||||||
if (StrUtil.isNotBlank(sourceIssue.getOtherType())) {
|
if (sourceIssue.getIsP()) {
|
||||||
powerIndexEnum = PowerIndexEnum.getByKey(sourceIssue.getOtherType());
|
resultUnitEnumByCode = ResultUnitEnum.P;
|
||||||
}
|
}
|
||||||
|
switch (resultUnitEnumByCode) {
|
||||||
switch (powerIndexEnum) {
|
|
||||||
/**
|
/**
|
||||||
* 频率
|
* 频率
|
||||||
*/
|
*/
|
||||||
case FREQ:
|
case FREQ:
|
||||||
return isQualified(dev, devIdMapComm, errDtlsCheckData, PowerIndexEnum.FREQ.getKey(), sourceIssue, dataRule, code, oneConfig.getScale());
|
return isQualified(dev, devIdMapComm, errDtlsCheckData, F, sourceIssue, dataRule, code, oneConfig.getScale());
|
||||||
case P:
|
case P:
|
||||||
return isQualified(dev, devIdMapComm, errDtlsCheckData, PowerIndexEnum.P.getKey(), sourceIssue, dataRule, code, oneConfig.getScale());
|
return isQualified(dev, devIdMapComm, errDtlsCheckData, P, sourceIssue, dataRule, code, oneConfig.getScale());
|
||||||
case ANGLE:
|
|
||||||
return isQualified(dev, devIdMapComm, errDtlsCheckData, PowerIndexEnum.ANGLE.getKey(), sourceIssue, dataRule, code, oneConfig.getScale());
|
|
||||||
/**
|
/**
|
||||||
* 电压
|
* 电压
|
||||||
*/
|
*/
|
||||||
case V:
|
case V_RELATIVE:
|
||||||
return isQualified(dev, devIdMapComm, errDtlsCheckData, PowerIndexEnum.V.getKey(), sourceIssue, dataRule, code, oneConfig.getScale());
|
case V_ABSOLUTELY:
|
||||||
|
return isQualified(dev, devIdMapComm, errDtlsCheckData, U, sourceIssue, dataRule, code, oneConfig.getScale());
|
||||||
/**
|
/**
|
||||||
* 电流
|
* 电流
|
||||||
*/
|
*/
|
||||||
case I:
|
case I_RELATIVE:
|
||||||
return isQualified(dev, devIdMapComm, errDtlsCheckData, PowerIndexEnum.I.getKey(), sourceIssue, dataRule, code, oneConfig.getScale());
|
case I_ABSOLUTELY:
|
||||||
|
return isQualified(dev, devIdMapComm, errDtlsCheckData, I, sourceIssue, dataRule, code, oneConfig.getScale());
|
||||||
/**
|
/**
|
||||||
* 谐波
|
* 谐波
|
||||||
*/
|
*/
|
||||||
@@ -206,12 +205,22 @@ public class DetectionServiceImpl {
|
|||||||
* 三相电压不平衡度
|
* 三相电压不平衡度
|
||||||
*/
|
*/
|
||||||
case IMBV:
|
case IMBV:
|
||||||
return isUnBalanceOrFlickerQualified(dev, devIdMapComm, errDtlsCheckData, U, sourceIssue, dataRule, code, oneConfig.getScale());
|
SimAndDigNonHarmonicResult vUnban = isUnBalanceOrFlickerQualified(dev, devIdMapComm, errDtlsCheckData, U, sourceIssue, dataRule, "V_UNBAN", oneConfig.getScale());
|
||||||
|
if (ObjectUtil.isNotNull(vUnban)) {
|
||||||
|
detectionDataDealService.acceptNonHarmonicResult(Arrays.asList(vUnban), code);
|
||||||
|
return vUnban.getResultFlag();
|
||||||
|
}
|
||||||
|
return 4;
|
||||||
/**
|
/**
|
||||||
* 三相电流不平衡度
|
* 三相电流不平衡度
|
||||||
*/
|
*/
|
||||||
case IMBA:
|
case IMBA:
|
||||||
return isUnBalanceOrFlickerQualified(dev, devIdMapComm, errDtlsCheckData, I, sourceIssue, dataRule, code, oneConfig.getScale());
|
SimAndDigNonHarmonicResult iUnban = isUnBalanceOrFlickerQualified(dev, devIdMapComm, errDtlsCheckData, I, sourceIssue, dataRule, "I_UNBAN", oneConfig.getScale());
|
||||||
|
if (ObjectUtil.isNotNull(iUnban)) {
|
||||||
|
detectionDataDealService.acceptNonHarmonicResult(Arrays.asList(iUnban), code);
|
||||||
|
return iUnban.getResultFlag();
|
||||||
|
}
|
||||||
|
return 4;
|
||||||
/**
|
/**
|
||||||
* 谐波有功功率
|
* 谐波有功功率
|
||||||
*/
|
*/
|
||||||
@@ -226,11 +235,17 @@ public class DetectionServiceImpl {
|
|||||||
* 闪变
|
* 闪变
|
||||||
*/
|
*/
|
||||||
case F:
|
case F:
|
||||||
return isUnBalanceOrFlickerQualified(dev, devIdMapComm, errDtlsCheckData, DetectionCodeEnum.PST.getCode(), sourceIssue, dataRule, code, oneConfig.getScale());
|
SimAndDigNonHarmonicResult pst = isUnBalanceOrFlickerQualified(dev, devIdMapComm, errDtlsCheckData, null, sourceIssue, dataRule, "PST", oneConfig.getScale());
|
||||||
|
if (ObjectUtil.isNotNull(pst)) {
|
||||||
|
detectionDataDealService.acceptNonHarmonicResult(Arrays.asList(pst), code);
|
||||||
|
return pst.getResultFlag();
|
||||||
|
}
|
||||||
|
return 4;
|
||||||
/**
|
/**
|
||||||
* 暂态
|
* 暂态
|
||||||
*/
|
*/
|
||||||
case VOLTAGE:
|
case VOLTAGE_MAG:
|
||||||
|
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());
|
||||||
@@ -415,36 +430,24 @@ 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) {
|
||||||
String[] splitArr = s.split("\\$");
|
if ((DetectionCodeEnum.REAL_PREFIX.getCode() + "PF").equals(s)) {
|
||||||
// 根据数据处理规则取值。key为相别,value为值列表
|
continue;
|
||||||
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());
|
|
||||||
}
|
}
|
||||||
|
// 根据数据处理规则取值。key为相别,value为值列表
|
||||||
|
Map<String, List<Double>> map = devListMap(dev, dataRule, s.split("\\$")[1]);
|
||||||
Double fData = 1.0;
|
Double fData = 1.0;
|
||||||
if (PowerIndexEnum.V.getKey().equals(type)) {
|
if (U.equals(type)) {
|
||||||
fData = sourceIssue.getFUn();
|
fData = sourceIssue.getFUn();
|
||||||
}
|
}
|
||||||
if (PowerIndexEnum.I.getKey().equals(type)) {
|
if (I.equals(type)) {
|
||||||
fData = sourceIssue.getFIn();
|
fData = sourceIssue.getFIn();
|
||||||
}
|
}
|
||||||
if (PowerIndexEnum.FREQ.getKey().equals(type)) {
|
if (F.equals(type)) {
|
||||||
fData = sourceIssue.getFFreq();
|
fData = sourceIssue.getFFreq();
|
||||||
}
|
}
|
||||||
if (PowerIndexEnum.P.getKey().equals(type)) {
|
if (P.equals(type)) {
|
||||||
if (!DetectionCodeEnum.PF.getCode().equals(splitArr[1]) && !DetectionCodeEnum.TOTPF.getCode().equals(splitArr[1])) {
|
fData = sourceIssue.getFUn() * sourceIssue.getFIn();
|
||||||
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]);
|
||||||
@@ -454,63 +457,52 @@ 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(dtlsCheckData)) {
|
if (CollUtil.isNotEmpty(errDtlsCheckData)) {
|
||||||
result.setAdType(dtlsCheckData.get(0).getValueType());
|
List<ErrDtlsCheckDataVO> dtlsCheckData = errDtlsCheckData.stream().filter(x -> x.getValueTypeCode().equals(s.split("\\$")[1])).collect(Collectors.toList());
|
||||||
isQualified = dtlsCheckData.get(0).getIsQualified();
|
if (CollUtil.isNotEmpty(dtlsCheckData)) {
|
||||||
if (CollUtil.isNotEmpty(dtlsCheckData.get(0).getErrSysDtls())) {
|
result.setAdType(dtlsCheckData.get(0).getValueType());
|
||||||
pqErrSysDtls = dtlsCheckData.get(0).getErrSysDtls();
|
isQualified = dtlsCheckData.get(0).getIsQualified();
|
||||||
}
|
if (CollUtil.isNotEmpty(dtlsCheckData.get(0).getErrSysDtls())) {
|
||||||
}
|
pqErrSysDtls = dtlsCheckData.get(0).getErrSysDtls();
|
||||||
result.setResultFlag(isQualified);
|
|
||||||
if (map.containsKey(TYPE_T)) {
|
|
||||||
List<ErrDtlsCheckDataVO> checkDataT = dtlsCheckData.stream().filter(x -> TYPE_T.equals(x.getPhase())).collect(Collectors.toList());
|
|
||||||
if (CollUtil.isNotEmpty(checkDataT)) {
|
|
||||||
DetectionData t = rangeComparisonList(map.get(TYPE_T), isQualified, pqErrSysDtls, fData, checkDataT.get(0).getValue(), dataRule, scale);
|
|
||||||
result.setTValue(JSON.toJSONString(t));
|
|
||||||
result.setResultFlag(t.getIsData());
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
List<DetectionData> resultFlag = new ArrayList<>();
|
|
||||||
Map<String, BiConsumer<SimAndDigNonHarmonicResult, DetectionData>> setters = new HashMap<>();
|
|
||||||
setters.put(TYPE_A, (r, d) -> r.setAValue(JSON.toJSONString(d)));
|
|
||||||
setters.put(TYPE_B, (r, d) -> r.setBValue(JSON.toJSONString(d)));
|
|
||||||
setters.put(TYPE_C, (r, d) -> r.setCValue(JSON.toJSONString(d)));
|
|
||||||
|
|
||||||
List<String> phases = Arrays.asList(TYPE_A, TYPE_B, TYPE_C);
|
|
||||||
for (String phase : phases) {
|
|
||||||
List<ErrDtlsCheckDataVO> checkData = dtlsCheckData.stream()
|
|
||||||
.filter(x -> phase.equals(x.getPhase()))
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
if (CollUtil.isNotEmpty(checkData)) {
|
|
||||||
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包含该键
|
|
||||||
DetectionData detectionData = rangeComparisonList(phaseValue, isQualified, pqErrSysDtls, fData, checkData.get(0).getValue(), dataRule, scale);
|
|
||||||
resultFlag.add(detectionData);
|
|
||||||
BiConsumer<SimAndDigNonHarmonicResult, DetectionData> setter = setters.get(phase);
|
|
||||||
if (setter != null) {
|
|
||||||
setter.accept(result, detectionData);
|
|
||||||
} else {
|
|
||||||
// 处理未定义的setter的情况
|
|
||||||
throw new IllegalArgumentException("Setter not defined for phase: " + phase);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
result.setResultFlag(setResultFlag(resultFlag));
|
if (map.containsKey(TYPE_T)) {
|
||||||
|
List<ErrDtlsCheckDataVO> checkDataT = dtlsCheckData.stream().filter(x -> TYPE_T.equals(x.getPhase())).collect(Collectors.toList());
|
||||||
|
if (CollUtil.isNotEmpty(checkDataT)) {
|
||||||
|
DetectionData t = rangeComparisonList(map.get(TYPE_T), isQualified, pqErrSysDtls, fData, checkDataT.get(0).getValue(), dataRule, scale);
|
||||||
|
result.setTValue(JSON.toJSONString(t));
|
||||||
|
result.setResultFlag(t.getIsData());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
List<DetectionData> resultFlag = new ArrayList<>();
|
||||||
|
Map<String, BiConsumer<SimAndDigNonHarmonicResult, DetectionData>> setters = new HashMap<>();
|
||||||
|
setters.put(TYPE_A, (r, d) -> r.setAValue(JSON.toJSONString(d)));
|
||||||
|
setters.put(TYPE_B, (r, d) -> r.setBValue(JSON.toJSONString(d)));
|
||||||
|
setters.put(TYPE_C, (r, d) -> r.setCValue(JSON.toJSONString(d)));
|
||||||
|
|
||||||
|
List<String> phases = Arrays.asList(TYPE_A, TYPE_B, TYPE_C);
|
||||||
|
for (String phase : phases) {
|
||||||
|
List<ErrDtlsCheckDataVO> checkData = dtlsCheckData.stream()
|
||||||
|
.filter(x -> phase.equals(x.getPhase()))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
if (CollUtil.isNotEmpty(checkData)) {
|
||||||
|
List<Double> phaseValue = map.get(phase);
|
||||||
|
// 注意:如果map中不存在该phase的键,phaseValue可能为null,需确保map包含该键
|
||||||
|
DetectionData detectionData = rangeComparisonList(phaseValue, isQualified, pqErrSysDtls, fData, checkData.get(0).getValue(), dataRule, scale);
|
||||||
|
resultFlag.add(detectionData);
|
||||||
|
BiConsumer<SimAndDigNonHarmonicResult, DetectionData> setter = setters.get(phase);
|
||||||
|
if (setter != null) {
|
||||||
|
setter.accept(result, detectionData);
|
||||||
|
} else {
|
||||||
|
// 处理未定义的setter的情况
|
||||||
|
throw new IllegalArgumentException("Setter not defined for phase: " + phase);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
result.setResultFlag(setResultFlag(resultFlag));
|
||||||
|
}
|
||||||
|
info.add(result);
|
||||||
}
|
}
|
||||||
info.add(result);
|
|
||||||
}
|
}
|
||||||
if (CollUtil.isNotEmpty(info)) {
|
if (CollUtil.isNotEmpty(info)) {
|
||||||
detectionDataDealService.acceptNonHarmonicResult(info, code);
|
detectionDataDealService.acceptNonHarmonicResult(info, code);
|
||||||
@@ -538,15 +530,11 @@ public class DetectionServiceImpl {
|
|||||||
SourceIssue sourceIssue,
|
SourceIssue sourceIssue,
|
||||||
DictDataEnum dataRule,
|
DictDataEnum dataRule,
|
||||||
Integer num, Integer scale) {
|
Integer num, Integer scale) {
|
||||||
Double fDataA = 1.0;
|
Double fData = 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)) {
|
||||||
fDataA = sourceIssue.getChannelList().stream().filter(x -> x.getChannelType().contains("Ua")).findFirst().get().getFAmp();
|
fData = sourceIssue.getFUn();
|
||||||
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();
|
||||||
@@ -555,9 +543,7 @@ public class DetectionServiceImpl {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (I.equals(type)) {
|
if (I.equals(type)) {
|
||||||
fDataA = sourceIssue.getChannelList().stream().filter(x -> x.getChannelType().contains("Ia")).findFirst().get().getFAmp();
|
fData = sourceIssue.getFIn();
|
||||||
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();
|
||||||
@@ -566,9 +552,7 @@ public class DetectionServiceImpl {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (HP.equals(type)) {
|
if (HP.equals(type)) {
|
||||||
fDataA = (sourceIssue.getFIn() * sourceIssue.getFUn()) * 0.01;
|
fData = (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)) {
|
||||||
@@ -594,9 +578,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), fDataA, num, scale);
|
List<DetectionData> integerBooleanA = harmRangeComparison(isQualified, pqErrSysDtls, type, TYPE_A, sourceIssue, dataRule, devMap.get(TYPE_A), fData, num, scale);
|
||||||
List<DetectionData> integerBooleanB = harmRangeComparison(isQualified, pqErrSysDtls, type, TYPE_B, sourceIssue, dataRule, devMap.get(TYPE_B), fDataB, num, scale);
|
List<DetectionData> integerBooleanB = harmRangeComparison(isQualified, pqErrSysDtls, type, TYPE_B, sourceIssue, dataRule, devMap.get(TYPE_B), fData, num, scale);
|
||||||
List<DetectionData> integerBooleanC = harmRangeComparison(isQualified, pqErrSysDtls, type, TYPE_C, sourceIssue, dataRule, devMap.get(TYPE_C), fDataC, num, scale);
|
List<DetectionData> integerBooleanC = harmRangeComparison(isQualified, pqErrSysDtls, type, TYPE_C, sourceIssue, dataRule, devMap.get(TYPE_C), fData, 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);
|
||||||
@@ -621,110 +605,74 @@ public class DetectionServiceImpl {
|
|||||||
* @param dataRule 数据处理原则
|
* @param dataRule 数据处理原则
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public Integer isUnBalanceOrFlickerQualified(List<DevData> dev,
|
public SimAndDigNonHarmonicResult 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())
|
||||||
);
|
);
|
||||||
List<String> devValueTypeList = sourceIssue.getDevValueTypeList();
|
Map<String, List<Double>> map = devListMap(dev, dataRule, code);
|
||||||
for (String s : devValueTypeList) {
|
if (CollUtil.isNotEmpty(map)) {
|
||||||
String[] splitArr = s.split("\\$");
|
Double fData = 1.0;
|
||||||
Map<String, List<Double>> map = devListMap(dev, dataRule, splitArr[1]);
|
if (U.equals(type)) {
|
||||||
if (CollUtil.isNotEmpty(map)) {
|
fData = sourceIssue.getFUn();
|
||||||
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;
|
|
||||||
if (U.equals(type)) {
|
|
||||||
fData = sourceIssue.getFUn();
|
|
||||||
}
|
|
||||||
if (I.equals(type)) {
|
|
||||||
fData = sourceIssue.getFIn();
|
|
||||||
}
|
|
||||||
SimAndDigNonHarmonicResult result = new SimAndDigNonHarmonicResult();
|
|
||||||
String[] split = dev.get(0).getId().split("_");
|
|
||||||
String devID = devIdMapComm.get(split[0]);
|
|
||||||
result.setDevMonitorId(devID + "_" + split[1]);
|
|
||||||
result.setScriptId(sourceIssue.getScriptId());
|
|
||||||
result.setSort(sourceIssue.getIndex());
|
|
||||||
result.setDataType(sourceIssue.getDataType());
|
|
||||||
List<PqErrSysDtls> pqErrSysDtls = new ArrayList<>();
|
|
||||||
Integer isQualified = 4;
|
|
||||||
if (CollUtil.isNotEmpty(dtlsCheckData)) {
|
|
||||||
result.setAdType(dtlsCheckData.get(0).getValueType());
|
|
||||||
isQualified = dtlsCheckData.get(0).getIsQualified();
|
|
||||||
if (CollUtil.isNotEmpty(dtlsCheckData.get(0).getErrSysDtls())) {
|
|
||||||
pqErrSysDtls = dtlsCheckData.get(0).getErrSysDtls();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
result.setResultFlag(isQualified);
|
|
||||||
// 闪变
|
|
||||||
if (DetectionCodeEnum.PST.getCode().equals(splitArr[1]) || DetectionCodeEnum.SeqV.getCode().equals(splitArr[1]) || DetectionCodeEnum.SeqA.getCode().equals(splitArr[1])) {
|
|
||||||
|
|
||||||
//取出源所对应的相别信息
|
|
||||||
List<PqScriptCheckData> channelTypeAList = checkData.stream()
|
|
||||||
.filter(x -> TYPE_A.equals(x.getPhase()))
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
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));
|
|
||||||
|
|
||||||
List<PqScriptCheckData> channelTypeBList = checkData.stream()
|
|
||||||
.filter(x -> TYPE_B.equals(x.getPhase()))
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
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));
|
|
||||||
|
|
||||||
List<PqScriptCheckData> channelTypeCList = checkData.stream()
|
|
||||||
.filter(x -> TYPE_C.equals(x.getPhase()))
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
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.setResultFlag(setResultFlag(Arrays.asList(a, b, c)));
|
|
||||||
} else {
|
|
||||||
// 三项不平衡
|
|
||||||
List<PqScriptCheckData> channelTypeBList = checkData.stream()
|
|
||||||
.filter(x -> TYPE_T.equals(x.getPhase()))
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
DetectionData t = rangeComparisonList(map.get(TYPE_B), isQualified, pqErrSysDtls, fData, channelTypeBList.get(0).getValue(), dataRule, scale);
|
|
||||||
result.setTValue(JSON.toJSONString(t));
|
|
||||||
result.setResultFlag(setResultFlag(Arrays.asList(t)));
|
|
||||||
}
|
|
||||||
info.add(result);
|
|
||||||
}
|
}
|
||||||
|
if (I.equals(type)) {
|
||||||
|
fData = sourceIssue.getFIn();
|
||||||
|
}
|
||||||
|
SimAndDigNonHarmonicResult result = new SimAndDigNonHarmonicResult();
|
||||||
|
String[] split = dev.get(0).getId().split("_");
|
||||||
|
String devID = devIdMapComm.get(split[0]);
|
||||||
|
result.setDevMonitorId(devID + "_" + split[1]);
|
||||||
|
result.setScriptId(sourceIssue.getScriptId());
|
||||||
|
result.setSort(sourceIssue.getIndex());
|
||||||
|
List<PqErrSysDtls> pqErrSysDtls = new ArrayList<>();
|
||||||
|
Integer isQualified = 4;
|
||||||
|
if (CollUtil.isNotEmpty(errDtlsCheckData)) {
|
||||||
|
result.setAdType(errDtlsCheckData.get(0).getValueType());
|
||||||
|
isQualified = errDtlsCheckData.get(0).getIsQualified();
|
||||||
|
if (CollUtil.isNotEmpty(errDtlsCheckData.get(0).getErrSysDtls())) {
|
||||||
|
pqErrSysDtls = errDtlsCheckData.get(0).getErrSysDtls();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
result.setDataType(sourceIssue.getDataType());
|
||||||
|
if (StrUtil.isBlank(type)) {
|
||||||
|
//取出源所对应的相别信息
|
||||||
|
List<PqScriptCheckData> channelTypeAList = checkData.stream()
|
||||||
|
.filter(x -> TYPE_A.equals(x.getPhase()))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
DetectionData a = rangeComparisonList(map.get(TYPE_A), isQualified, pqErrSysDtls, fData, channelTypeAList.get(0).getValue(), dataRule, scale);
|
||||||
|
result.setAValue(JSON.toJSONString(a));
|
||||||
|
|
||||||
|
List<PqScriptCheckData> channelTypeBList = checkData.stream()
|
||||||
|
.filter(x -> TYPE_B.equals(x.getPhase()))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
DetectionData b = rangeComparisonList(map.get(TYPE_B), isQualified, pqErrSysDtls, fData, channelTypeBList.get(0).getValue(), dataRule, scale);
|
||||||
|
result.setBValue(JSON.toJSONString(b));
|
||||||
|
|
||||||
|
List<PqScriptCheckData> channelTypeCList = checkData.stream()
|
||||||
|
.filter(x -> TYPE_C.equals(x.getPhase()))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
DetectionData c = rangeComparisonList(map.get(TYPE_C), isQualified, pqErrSysDtls, fData, channelTypeCList.get(0).getValue(), dataRule, scale);
|
||||||
|
result.setCValue(JSON.toJSONString(c));
|
||||||
|
|
||||||
|
result.setResultFlag(setResultFlag(Arrays.asList(a, b, c)));
|
||||||
|
} else {
|
||||||
|
List<PqScriptCheckData> channelTypeBList = checkData.stream()
|
||||||
|
.filter(x -> TYPE_T.equals(x.getPhase()))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
DetectionData t = rangeComparisonList(map.get(TYPE_B), isQualified, pqErrSysDtls, fData, channelTypeBList.get(0).getValue(), dataRule, scale);
|
||||||
|
result.setTValue(JSON.toJSONString(t));
|
||||||
|
result.setResultFlag(setResultFlag(Arrays.asList(t)));
|
||||||
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
if (CollUtil.isNotEmpty(info)) {
|
return null;
|
||||||
detectionDataDealService.acceptNonHarmonicResult(info, code);
|
|
||||||
List<Integer> resultFlag = info.stream().map(SimAndDigNonHarmonicResult::getResultFlag).distinct().collect(Collectors.toList());
|
|
||||||
return StorageUtil.getInteger(resultFlag);
|
|
||||||
}
|
|
||||||
return 4;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,218 +0,0 @@
|
|||||||
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,25 +3,17 @@ 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.*;
|
||||||
import com.njcn.gather.detection.handler.SocketDevResponseService;
|
|
||||||
import com.njcn.gather.detection.handler.SocketSourceResponseService;
|
|
||||||
import com.njcn.gather.detection.pojo.constant.DetectionCommunicateConstant;
|
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;
|
||||||
@@ -30,20 +22,16 @@ 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.freqConverter.service.IPqFreqConverterConfigService;
|
||||||
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.report.pojo.enums.PowerIndexEnum;
|
import com.njcn.gather.result.pojo.enums.ResultUnitEnum;
|
||||||
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;
|
||||||
@@ -51,10 +39,7 @@ import com.njcn.gather.script.service.IPqScriptCheckDataService;
|
|||||||
import com.njcn.gather.script.service.IPqScriptDtlsService;
|
import com.njcn.gather.script.service.IPqScriptDtlsService;
|
||||||
import com.njcn.gather.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;
|
||||||
@@ -62,11 +47,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;
|
||||||
@@ -90,18 +75,16 @@ public class PreDetectionServiceImpl implements PreDetectionService {
|
|||||||
private final SocketDevResponseService socketDevResponseService;
|
private final SocketDevResponseService socketDevResponseService;
|
||||||
private final SocketSourceResponseService socketSourceResponseService;
|
private final SocketSourceResponseService socketSourceResponseService;
|
||||||
private final SocketContrastResponseService socketContrastResponseService;
|
private final SocketContrastResponseService socketContrastResponseService;
|
||||||
|
private final SocketFreqConverterService socketFreqConverterService;
|
||||||
|
private final SocketFreqConverterDevService socketFreqConverterDevService;
|
||||||
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 IPqFreqConverterConfigService pqFreqConverterConfigService;
|
||||||
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
|
||||||
@@ -118,28 +101,6 @@ 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);
|
||||||
@@ -176,7 +137,6 @@ 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);
|
||||||
@@ -223,7 +183,6 @@ 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);
|
||||||
@@ -261,7 +220,6 @@ 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)) {
|
||||||
@@ -284,254 +242,31 @@ 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() + "&&" + type);
|
xuMsg.setRequestId(SourceOperateCodeEnum.FORMAL_REAL.getValue() + "&&" + sourceIssues.getType());
|
||||||
SocketManager.sendMsg(runtimeParam.getUserPageId() + DetectionCommunicateConstant.SOURCE, JSON.toJSONString(xuMsg));
|
SocketManager.sendMsg(param.getUserPageId() + DetectionCommunicateConstant.SOURCE, JSON.toJSONString(xuMsg));
|
||||||
// Resume_Success
|
// Resume_Success
|
||||||
} else {
|
} else {
|
||||||
//TODO 是否最终检测完成需要推送给用户 检测完成
|
//TODO 是否最终检测完成需要推送给用户 检测完成
|
||||||
PqScriptCheckDataParam checkDataParam = new PqScriptCheckDataParam();
|
PqScriptCheckDataParam checkDataParam = new PqScriptCheckDataParam();
|
||||||
checkDataParam.setScriptId(runtimeParam.getScriptId());
|
checkDataParam.setScriptId(param.getScriptId());
|
||||||
checkDataParam.setIsValueTypeName(false);
|
checkDataParam.setIsValueTypeName(false);
|
||||||
List<String> adType = iPqScriptCheckDataService.getValueType(checkDataParam);
|
List<String> adType = iPqScriptCheckDataService.getValueType(checkDataParam);
|
||||||
|
|
||||||
iPqDevService.updateResult(runtimeParam.getDevIds(), adType, runtimeParam.getCode(), runtimeParam.getUserId(), runtimeParam.getTemperature(), runtimeParam.getHumidity(), true);
|
iPqDevService.updateResult(param.getDevIds(), adType, param.getCode(), param.getUserId(), param.getTemperature(), param.getHumidity());
|
||||||
CnSocketUtil.quitSend(runtimeParam);
|
CnSocketUtil.quitSend(param);
|
||||||
}
|
}
|
||||||
|
|
||||||
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();
|
||||||
@@ -569,9 +304,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 (StrUtil.isNotBlank(sourceIssue.getOtherType())) {
|
if (sourceIssue.getIsP()) {
|
||||||
sourceIssue.setType(PowerIndexEnum.V.getKey());
|
sourceIssue.setType(ResultUnitEnum.V_ABSOLUTELY.getCode());
|
||||||
type = sourceIssue.getOtherType();
|
type = ResultUnitEnum.P.getCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
List<String> comm = sourceIssue.getDevValueTypeList();
|
List<String> comm = sourceIssue.getDevValueTypeList();
|
||||||
@@ -593,7 +328,6 @@ 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();
|
||||||
@@ -617,7 +351,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(pathConfig.getDataPath() + File.separator + fileName);
|
InputStream inputStream = new FileInputStream(alignDataFilePath + "\\" + 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();
|
||||||
@@ -662,6 +396,39 @@ public class PreDetectionServiceImpl implements PreDetectionService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void startFreqConverter(String userId, String converterId, String monitorId, Boolean reset) {
|
||||||
|
String freqConverterTag = userId + CnSocketUtil.FREQ_CONVERTER_TAG;
|
||||||
|
String devTag = userId + CnSocketUtil.DEV_TAG;
|
||||||
|
// socketFreqConverterService.init(userId, converterId, monitorId);
|
||||||
|
socketFreqConverterService.connectSocket(freqConverterTag);
|
||||||
|
socketFreqConverterDevService.connectSocket(devTag);
|
||||||
|
|
||||||
|
long startTime = System.currentTimeMillis();
|
||||||
|
long timeout = 3000; // 3秒超时时间
|
||||||
|
while (true) {
|
||||||
|
if (SocketManager.isChannelActive(freqConverterTag) && SocketManager.isChannelActive(devTag)) {
|
||||||
|
// if (SocketManager.isChannelActive(devTag)) {
|
||||||
|
socketFreqConverterService.connectionFreqConverter(userId, freqConverterTag, converterId, monitorId, reset);
|
||||||
|
socketFreqConverterDevService.connectionDev(userId, devTag, converterId, monitorId,reset);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 检查是否超时
|
||||||
|
if (System.currentTimeMillis() - startTime > timeout) {
|
||||||
|
throw new BusinessException(DetectionResponseEnum.SOCKET_CONNECT_TIMEOUT);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void stopFreqConverter(String converterTag, String devTag) {
|
||||||
|
pqFreqConverterConfigService.updateTestStatus(FormalTestManager.currentFreqConverterId, 1);
|
||||||
|
socketFreqConverterService.stopTest(converterTag, devTag);
|
||||||
|
socketFreqConverterDevService.stopTest(converterTag, devTag);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 比对式-与通信模块进行连接
|
* 比对式-与通信模块进行连接
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -1,20 +0,0 @@
|
|||||||
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;
|
|
||||||
}
|
|
||||||
@@ -1,110 +0,0 @@
|
|||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
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;
|
|
||||||
}
|
|
||||||
@@ -1,168 +0,0 @@
|
|||||||
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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
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;
|
|
||||||
}
|
|
||||||
@@ -14,6 +14,8 @@ import com.njcn.gather.detection.util.socket.websocket.WebServiceManager;
|
|||||||
*/
|
*/
|
||||||
public class CnSocketUtil {
|
public class CnSocketUtil {
|
||||||
|
|
||||||
|
public final static String FREQ_CONVERTER_TAG="_FreqConverter";
|
||||||
|
|
||||||
public final static String DEV_TAG = "_Dev";
|
public final static String DEV_TAG = "_Dev";
|
||||||
|
|
||||||
public final static String CONTRAST_DEV_TAG = "_Contrast_Dev";
|
public final static String CONTRAST_DEV_TAG = "_Contrast_Dev";
|
||||||
@@ -47,13 +49,9 @@ 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.getSourceName());
|
jsonObject.put("sourceId", param.getSourceId());
|
||||||
socketMsg.setData(jsonObject.toJSONString());
|
socketMsg.setData(jsonObject.toJSONString());
|
||||||
String sourceKey = param.getUserPageId() + SOURCE_TAG;
|
SocketManager.sendMsg(param.getUserPageId() + SOURCE_TAG, JSON.toJSONString(socketMsg));
|
||||||
if (SocketManager.isChannelActive(sourceKey)) {
|
|
||||||
SocketManager.markActiveClose(sourceKey);
|
|
||||||
}
|
|
||||||
SocketManager.sendMsg(sourceKey, JSON.toJSONString(socketMsg));
|
|
||||||
WebServiceManager.removePreDetectionParam(param.getUserPageId());
|
WebServiceManager.removePreDetectionParam(param.getUserPageId());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,11 +7,13 @@ import com.njcn.gather.detection.pojo.po.DevData;
|
|||||||
import com.njcn.gather.detection.pojo.vo.DevLineTestResult;
|
import com.njcn.gather.detection.pojo.vo.DevLineTestResult;
|
||||||
import com.njcn.gather.device.pojo.enums.PatternEnum;
|
import com.njcn.gather.device.pojo.enums.PatternEnum;
|
||||||
import com.njcn.gather.device.pojo.vo.PreDetection;
|
import com.njcn.gather.device.pojo.vo.PreDetection;
|
||||||
|
import com.njcn.gather.dip.pojo.po.PqDipData;
|
||||||
import com.njcn.gather.plan.pojo.enums.DataSourceEnum;
|
import com.njcn.gather.plan.pojo.enums.DataSourceEnum;
|
||||||
import com.njcn.gather.plan.pojo.po.AdPlan;
|
import com.njcn.gather.plan.pojo.po.AdPlan;
|
||||||
import com.njcn.gather.plan.pojo.po.AdPlanTestConfig;
|
import com.njcn.gather.plan.pojo.po.AdPlanTestConfig;
|
||||||
import com.njcn.gather.script.pojo.po.SourceIssue;
|
import com.njcn.gather.script.pojo.po.SourceIssue;
|
||||||
import com.njcn.gather.system.dictionary.pojo.enums.DictDataEnum;
|
import com.njcn.gather.system.dictionary.pojo.enums.DictDataEnum;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -32,6 +34,20 @@ public class FormalTestManager {
|
|||||||
// 当前步骤
|
// 当前步骤
|
||||||
public static SourceOperateCodeEnum currentStep;
|
public static SourceOperateCodeEnum currentStep;
|
||||||
|
|
||||||
|
public static SourceOperateCodeEnum freqConverterStep;
|
||||||
|
public static SourceOperateCodeEnum freqConverterDevStep;
|
||||||
|
/**
|
||||||
|
* 变频器存放数据的表后缀
|
||||||
|
*/
|
||||||
|
public static Integer freqConverterTableSuffix;
|
||||||
|
|
||||||
|
public static String currentFreqConverterId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 待采集后续变频器状态的Dip任务
|
||||||
|
*/
|
||||||
|
public static Map<String, PendingDipTask> pendingDipTaskMap = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* key:设备ip,value:当前设备下面的监测点ID(ip_通道号)
|
* key:设备ip,value:当前设备下面的监测点ID(ip_通道号)
|
||||||
*/
|
*/
|
||||||
@@ -211,38 +227,25 @@ 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 void clearFreqConverterRuntimeState() {
|
||||||
|
currentFreqConverterId = null;
|
||||||
|
freqConverterTableSuffix = null;
|
||||||
|
pendingDipTaskMap.clear();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
@Data
|
||||||
* 检测开始时间
|
public static class PendingDipTask {
|
||||||
*/
|
private PqDipData pqDipData;
|
||||||
public static LocalDateTime checkStartTime;
|
|
||||||
|
|
||||||
public static boolean resumeFormalPending;
|
private LocalDateTime targetEndTime;
|
||||||
|
private Integer originalTolerant;
|
||||||
|
|
||||||
public static Integer resumeNextSort;
|
public PendingDipTask(PqDipData pqDipData, LocalDateTime targetEndTime, Integer originalTolerant) {
|
||||||
|
this.pqDipData = pqDipData;
|
||||||
public static Integer resumeBaseFormalCheckTime;
|
this.targetEndTime = targetEndTime;
|
||||||
|
this.originalTolerant = originalTolerant;
|
||||||
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,11 +55,6 @@ 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);
|
||||||
}
|
}
|
||||||
@@ -70,31 +65,20 @@ 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();
|
||||||
}
|
}
|
||||||
System.out.println(userId + "__" + channel.id() + "关闭了客户端");
|
NioEventLoopGroup eventExecutors = socketGroup.get(userId);
|
||||||
|
if (ObjectUtil.isNotNull(eventExecutors)) {
|
||||||
|
eventExecutors.shutdownGracefully();
|
||||||
|
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);
|
||||||
NioEventLoopGroup eventExecutors = socketGroup.remove(userId);
|
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) {
|
||||||
@@ -105,20 +89,6 @@ 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)) {
|
||||||
@@ -343,11 +313,6 @@ public class SocketManager {
|
|||||||
return targetMap.get(scriptType);
|
return targetMap.get(scriptType);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void clearFormalRuntime() {
|
|
||||||
sourceIssueList.clear();
|
|
||||||
targetMap.clear();
|
|
||||||
valueTypeMap.clear();
|
|
||||||
clockMap.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ 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;
|
||||||
@@ -57,6 +56,109 @@ public class NettyClient {
|
|||||||
*/
|
*/
|
||||||
private static NettyClient instance;
|
private static NettyClient instance;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 静态方法:智能连接变频器设备(兼容性包装)
|
||||||
|
*
|
||||||
|
* @param ip IP地址
|
||||||
|
* @param port 端口号
|
||||||
|
* @param ChannelId Channel唯一标识
|
||||||
|
* @param handler 变频器处理器
|
||||||
|
*/
|
||||||
|
public static void commonConnect(String ip, Integer port, String ChannelId,
|
||||||
|
SimpleChannelInboundHandler handler) {
|
||||||
|
if (instance != null) {
|
||||||
|
instance.executeCommonConnect(ip, port, ChannelId, handler);
|
||||||
|
} else {
|
||||||
|
log.error("NettyClient未初始化,无法创建连接");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 执行变频器Socket连接建立流程
|
||||||
|
*
|
||||||
|
* @param ip 目标服务器IP地址
|
||||||
|
* @param port 目标服务器端口号
|
||||||
|
* @param ChannelId Channel唯一标识id
|
||||||
|
* @param handler 变频器业务处理器
|
||||||
|
*/
|
||||||
|
private static void executeCommonConnect(String ip, Integer port,
|
||||||
|
String ChannelId,
|
||||||
|
SimpleChannelInboundHandler handler) {
|
||||||
|
NioEventLoopGroup group = createEventLoopGroup();
|
||||||
|
|
||||||
|
try {
|
||||||
|
Bootstrap bootstrap = configureBootstrap(group);
|
||||||
|
ChannelInitializer<NioSocketChannel> initializer = createCommonChannelInitializer(ChannelId, handler);
|
||||||
|
bootstrap.handler(initializer);
|
||||||
|
ChannelFuture channelFuture = bootstrap.connect(ip, port).sync();
|
||||||
|
handleCommonConnectionResult(channelFuture, ChannelId, handler, group);
|
||||||
|
} catch (Exception e) {
|
||||||
|
handleCommonConnectionException(e, ChannelId, handler, group);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建通用通道初始化器
|
||||||
|
*
|
||||||
|
* @param channelId Channel唯一标识id
|
||||||
|
* @param handler 通用业务处理器
|
||||||
|
* @return ChannelInitializer 通道初始化器
|
||||||
|
*/
|
||||||
|
private static ChannelInitializer<NioSocketChannel> createCommonChannelInitializer(
|
||||||
|
String channelId, SimpleChannelInboundHandler handler) {
|
||||||
|
return new ChannelInitializer<NioSocketChannel>() {
|
||||||
|
@Override
|
||||||
|
protected void initChannel(NioSocketChannel ch) {
|
||||||
|
ch.pipeline()
|
||||||
|
.addLast(new LineBasedFrameDecoder(10240 * 2))
|
||||||
|
.addLast(new StringDecoder(CharsetUtil.UTF_8))
|
||||||
|
.addLast(new StringEncoder(CharsetUtil.UTF_8))
|
||||||
|
.addLast(new IdleStateHandler(60, 0, 0, TimeUnit.SECONDS))
|
||||||
|
.addLast(handler);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 处理通用连接结果
|
||||||
|
*
|
||||||
|
* @param channelFuture 连接Future对象
|
||||||
|
* @param channelId Channel唯一标识符
|
||||||
|
* @param handler 通用业务处理器
|
||||||
|
* @param group 事件循环组
|
||||||
|
*/
|
||||||
|
private static void handleCommonConnectionResult(ChannelFuture channelFuture,
|
||||||
|
String channelId,
|
||||||
|
SimpleChannelInboundHandler handler,
|
||||||
|
NioEventLoopGroup group) {
|
||||||
|
channelFuture.addListener((ChannelFutureListener) ch -> {
|
||||||
|
if (!ch.isSuccess()) {
|
||||||
|
log.error("连接Socket失败,channelId={}", channelId);
|
||||||
|
group.shutdownGracefully();
|
||||||
|
} else {
|
||||||
|
log.info("连接Socket成功,channel={}, channelId={}",
|
||||||
|
channelId, channelFuture.channel().id());
|
||||||
|
SocketManager.addGroup(channelId, group);
|
||||||
|
SocketManager.addUser(channelId, channelFuture.channel());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 处理通用连接异常
|
||||||
|
*
|
||||||
|
* @param e 异常对象
|
||||||
|
* @param channelId Channel唯一标识id
|
||||||
|
* @param handler 通用业务处理器
|
||||||
|
* @param group 事件循环组
|
||||||
|
*/
|
||||||
|
private static void handleCommonConnectionException(Exception e, String channelId,
|
||||||
|
SimpleChannelInboundHandler handler,
|
||||||
|
NioEventLoopGroup group) {
|
||||||
|
log.error("连接Socket服务端发生异常,channelId={}, error={}", channelId, e.getMessage(), e);
|
||||||
|
group.shutdownGracefully();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@PostConstruct
|
@PostConstruct
|
||||||
public void init() {
|
public void init() {
|
||||||
@@ -350,7 +452,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(param, handler, group);
|
onConnectionFailure(handler, group);
|
||||||
} else {
|
} else {
|
||||||
onConnectionSuccess(channelFuture, param, handler, group, msg);
|
onConnectionSuccess(channelFuture, param, handler, group, msg);
|
||||||
}
|
}
|
||||||
@@ -359,24 +461,15 @@ public class NettyClient {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 连接失败处理
|
* 连接失败处理
|
||||||
* 输出失败信息、优雅关闭事件循环组、通知前端、释放检测锁
|
* 输出失败信息并优雅关闭事件循环组
|
||||||
*
|
*
|
||||||
* @param param 检测参数,用于定位锁与前端通知
|
|
||||||
* @param handler 业务处理器,用于区分设备类型
|
* @param handler 业务处理器,用于区分设备类型
|
||||||
* @param group 事件循环组
|
* @param group 事件循环组
|
||||||
*/
|
*/
|
||||||
private static void onConnectionFailure(PreDetectionParam param,
|
private static void onConnectionFailure(SimpleChannelInboundHandler<String> handler, NioEventLoopGroup group) {
|
||||||
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");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -465,12 +558,6 @@ 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,7 +2,6 @@ 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;
|
||||||
@@ -69,11 +68,6 @@ 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");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -82,11 +76,6 @@ 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");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -161,18 +150,11 @@ 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("超时处理-----》" + "统计数据已超时----------------关闭");
|
||||||
@@ -182,11 +164,6 @@ 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,8 +3,6 @@ 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;
|
||||||
@@ -15,8 +13,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;
|
||||||
@@ -55,19 +53,19 @@ import java.util.stream.Collectors;
|
|||||||
public class NettyDevClientHandler extends SimpleChannelInboundHandler<String> {
|
public class NettyDevClientHandler extends SimpleChannelInboundHandler<String> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 短闪检测超时时间:20分钟+100秒(1300秒)
|
* 闪变检测超时时间:20分钟(1300秒)
|
||||||
*/
|
*/
|
||||||
private static final long SHORT_FLICKER_TIMEOUT = 1300L;
|
private static final long FLICKER_TIMEOUT = 1300L;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 统计数据检测超时时间:3分钟+100秒(190秒)
|
* 统计数据检测超时时间:3分钟(180秒)
|
||||||
*/
|
*/
|
||||||
private static final long STATISTICS_TIMEOUT = 190L;
|
private static final long STATISTICS_TIMEOUT = 180L;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 实时数据检测超时时间:1分钟*3
|
* 实时数据检测超时时间:1分钟(60秒)
|
||||||
*/
|
*/
|
||||||
private static final long REALTIME_TIMEOUT = 60 * 3L;
|
private static final long REALTIME_TIMEOUT = 60L;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 暂停操作超时时间:10分钟(600秒)
|
* 暂停操作超时时间:10分钟(600秒)
|
||||||
@@ -115,15 +113,8 @@ 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();
|
||||||
String key = param.getUserPageId() + CnSocketUtil.DEV_TAG;
|
SocketManager.removeUser(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");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -141,9 +132,6 @@ 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");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -199,9 +187,6 @@ 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");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -246,9 +231,6 @@ 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");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -262,14 +244,6 @@ 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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -305,10 +279,10 @@ public class NettyDevClientHandler extends SimpleChannelInboundHandler<String> {
|
|||||||
String type = sourceIssue.getType();
|
String type = sourceIssue.getType();
|
||||||
|
|
||||||
// 根据不同检测类型使用不同的超时阈值
|
// 根据不同检测类型使用不同的超时阈值
|
||||||
if (PowerIndexEnum.F.getKey().equals(type)) {
|
if (DicDataEnum.F.getCode().equals(type)) {
|
||||||
// 闪变检测:需要更长时间,20分钟超时
|
// 闪变检测:需要更长时间,20分钟超时
|
||||||
return currentTime >= SHORT_FLICKER_TIMEOUT;
|
return currentTime >= FLICKER_TIMEOUT;
|
||||||
} else if (PowerIndexEnum.VOLTAGE.getKey().equals(type) || PowerIndexEnum.HP.getKey().equals(type)) {
|
} else if (DicDataEnum.VOLTAGE.getCode().equals(type) || DicDataEnum.HP.getCode().equals(type)) {
|
||||||
// 统计数据类型(电压、谐波):中等时间,3分钟超时
|
// 统计数据类型(电压、谐波):中等时间,3分钟超时
|
||||||
return currentTime >= STATISTICS_TIMEOUT;
|
return currentTime >= STATISTICS_TIMEOUT;
|
||||||
} else {
|
} else {
|
||||||
@@ -328,9 +302,6 @@ 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");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -0,0 +1,147 @@
|
|||||||
|
package com.njcn.gather.detection.util.socket.cilent;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import com.njcn.gather.detection.handler.SocketFreqConverterService;
|
||||||
|
import com.njcn.gather.detection.util.socket.FormalTestManager;
|
||||||
|
import com.njcn.gather.detection.util.socket.SocketManager;
|
||||||
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
|
import io.netty.channel.SimpleChannelInboundHandler;
|
||||||
|
import io.netty.handler.timeout.IdleState;
|
||||||
|
import io.netty.handler.timeout.IdleStateEvent;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 变频器Netty客户端处理器
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
public class NettyFreqConverterClientHandler extends SimpleChannelInboundHandler<String> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 变频器Channel唯一标识符
|
||||||
|
*/
|
||||||
|
private final String converterChannelTag;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 变频器Socket响应服务
|
||||||
|
*/
|
||||||
|
private final SocketFreqConverterService socketFreqConverterService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 重连次数
|
||||||
|
*/
|
||||||
|
private int reconnectAttempts = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 最大重连次数
|
||||||
|
*/
|
||||||
|
private static final int MAX_RECONNECT_ATTEMPTS = 3;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 重连间隔(毫秒)
|
||||||
|
*/
|
||||||
|
private static final long RECONNECT_INTERVAL_MS = 5000;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否正在重连
|
||||||
|
*/
|
||||||
|
private volatile boolean isReconnecting = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 构造方法
|
||||||
|
*
|
||||||
|
* @param converterChannelTag 变频器Chanel唯一标识符
|
||||||
|
* @param socketFreqConverterService 变频器Socket响应服务
|
||||||
|
*/
|
||||||
|
public NettyFreqConverterClientHandler(String converterChannelTag, SocketFreqConverterService socketFreqConverterService) {
|
||||||
|
this.converterChannelTag = converterChannelTag;
|
||||||
|
this.socketFreqConverterService = socketFreqConverterService;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void channelActive(ChannelHandlerContext ctx) throws Exception {
|
||||||
|
log.info("变频器连接已建立,converterChannelTag={}, channelId={}", converterChannelTag, ctx.channel().id());
|
||||||
|
|
||||||
|
// 注册Channel到SocketManager
|
||||||
|
SocketManager.addUser(converterChannelTag, ctx.channel());
|
||||||
|
|
||||||
|
if (reconnectAttempts > 0) {
|
||||||
|
log.info("变频器重连成功,converterChannelTag={}, 重连次数={}", converterChannelTag, reconnectAttempts);
|
||||||
|
reconnectAttempts = 0;
|
||||||
|
isReconnecting = false;
|
||||||
|
socketFreqConverterService.onReconnectSuccess(converterChannelTag);
|
||||||
|
}
|
||||||
|
|
||||||
|
super.channelActive(ctx);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void channelRead0(ChannelHandlerContext ctx, String msg) throws Exception {
|
||||||
|
if (StrUtil.isBlank(msg)) {
|
||||||
|
log.debug("收到空消息,忽略,converterChannelTag={}", converterChannelTag);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
log.info("收到变频器消息,converterChannelTag={}, msg={}", converterChannelTag, msg);
|
||||||
|
|
||||||
|
// 处理状态数据
|
||||||
|
socketFreqConverterService.handleRead(converterChannelTag, msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
|
||||||
|
log.warn("变频器连接已断开,converterChannelTag={}", converterChannelTag);
|
||||||
|
|
||||||
|
socketFreqConverterService.cleanup(converterChannelTag);
|
||||||
|
|
||||||
|
if (!isReconnecting && reconnectAttempts < MAX_RECONNECT_ATTEMPTS && !FormalTestManager.isRemoveSocket) {
|
||||||
|
attemptReconnect(ctx);
|
||||||
|
} else if (reconnectAttempts >= MAX_RECONNECT_ATTEMPTS) {
|
||||||
|
log.error("变频器重连失败,已达到最大重连次数{}次,converterChannelTag={}", MAX_RECONNECT_ATTEMPTS, converterChannelTag);
|
||||||
|
}
|
||||||
|
|
||||||
|
super.channelInactive(ctx);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
|
||||||
|
log.error("变频器连接发生异常,converterChannelTag={}, error={}", converterChannelTag, cause.getMessage(), cause);
|
||||||
|
ctx.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
|
||||||
|
if (evt instanceof IdleStateEvent) {
|
||||||
|
IdleStateEvent event = (IdleStateEvent) evt;
|
||||||
|
if (event.state() == IdleState.READER_IDLE) {
|
||||||
|
log.warn("变频器连接读空闲,converterChannelTag={}", converterChannelTag);
|
||||||
|
// 可以选择发送心跳或关闭连接
|
||||||
|
}
|
||||||
|
}
|
||||||
|
super.userEventTriggered(ctx, evt);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void attemptReconnect(ChannelHandlerContext ctx) {
|
||||||
|
isReconnecting = true;
|
||||||
|
reconnectAttempts++;
|
||||||
|
|
||||||
|
log.info("准备重连变频器,converterChannelTag={}, 第{}/{}次重连,{}秒后开始",
|
||||||
|
converterChannelTag, reconnectAttempts, MAX_RECONNECT_ATTEMPTS, RECONNECT_INTERVAL_MS / 1000);
|
||||||
|
|
||||||
|
ctx.executor().schedule(() -> {
|
||||||
|
try {
|
||||||
|
log.info("开始执行变频器重连,converterChannelTag={}", converterChannelTag);
|
||||||
|
socketFreqConverterService.reconnect(converterChannelTag);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("变频器重连触发失败,converterChannelTag={}, error={}", converterChannelTag, e.getMessage(), e);
|
||||||
|
isReconnecting = false;
|
||||||
|
|
||||||
|
if (reconnectAttempts < MAX_RECONNECT_ATTEMPTS) {
|
||||||
|
log.warn("将在{}秒后进行下一次重试", RECONNECT_INTERVAL_MS / 1000);
|
||||||
|
ctx.executor().schedule(() -> attemptReconnect(ctx), RECONNECT_INTERVAL_MS, java.util.concurrent.TimeUnit.MILLISECONDS);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, RECONNECT_INTERVAL_MS, java.util.concurrent.TimeUnit.MILLISECONDS);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,63 @@
|
|||||||
|
package com.njcn.gather.detection.util.socket.cilent;
|
||||||
|
|
||||||
|
import com.njcn.gather.detection.handler.SocketFreqConverterDevService;
|
||||||
|
import com.njcn.gather.detection.util.socket.FormalTestManager;
|
||||||
|
import com.njcn.gather.detection.util.socket.SocketManager;
|
||||||
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
|
import io.netty.channel.SimpleChannelInboundHandler;
|
||||||
|
import io.netty.handler.timeout.IdleState;
|
||||||
|
import io.netty.handler.timeout.IdleStateEvent;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设备 Netty 客户端处理器
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
public class NettyFreqConverterDevClientHandler extends SimpleChannelInboundHandler<String> {
|
||||||
|
|
||||||
|
private final String devChannelTag;
|
||||||
|
private final SocketFreqConverterDevService socketFreqConverterDevService;
|
||||||
|
|
||||||
|
public NettyFreqConverterDevClientHandler(String devChannelTag, SocketFreqConverterDevService socketFreqConverterDevService) {
|
||||||
|
this.devChannelTag = devChannelTag;
|
||||||
|
this.socketFreqConverterDevService = socketFreqConverterDevService;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void channelActive(ChannelHandlerContext ctx) throws Exception {
|
||||||
|
log.info("设备连接已建立,devChannelTag={}, channelId={}", devChannelTag, ctx.channel().id());
|
||||||
|
SocketManager.addUser(devChannelTag, ctx.channel());
|
||||||
|
super.channelActive(ctx);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void channelRead0(ChannelHandlerContext ctx, String msg) throws Exception {
|
||||||
|
log.info("收到设备消息,devChannelTag={}, msg={}", devChannelTag, msg);
|
||||||
|
|
||||||
|
socketFreqConverterDevService.handleRead(devChannelTag, msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
|
||||||
|
log.warn("设备连接已断开,devChannelTag={}", devChannelTag);
|
||||||
|
socketFreqConverterDevService.cleanup(devChannelTag);
|
||||||
|
super.channelInactive(ctx);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
|
||||||
|
log.error("设备连接发生异常,devChannelTag={}, error={}", devChannelTag, cause.getMessage(), cause);
|
||||||
|
ctx.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
|
||||||
|
if (evt instanceof IdleStateEvent) {
|
||||||
|
IdleStateEvent event = (IdleStateEvent) evt;
|
||||||
|
if (event.state() == IdleState.READER_IDLE) {
|
||||||
|
log.warn("设备连接读空闲,devChannelTag={}", devChannelTag);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
super.userEventTriggered(ctx, evt);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,7 +1,6 @@
|
|||||||
package com.njcn.gather.detection.util.socket.cilent;
|
package com.njcn.gather.detection.util.socket.cilent;
|
||||||
|
|
||||||
import com.njcn.gather.detection.handler.SocketSourceResponseService;
|
import com.njcn.gather.detection.handler.SocketSourceResponseService;
|
||||||
import com.njcn.gather.detection.lock.DetectionLockManager;
|
|
||||||
import com.njcn.gather.detection.pojo.enums.SourceOperateCodeEnum;
|
import com.njcn.gather.detection.pojo.enums.SourceOperateCodeEnum;
|
||||||
import com.njcn.gather.detection.pojo.param.PreDetectionParam;
|
import com.njcn.gather.detection.pojo.param.PreDetectionParam;
|
||||||
import com.njcn.gather.detection.util.socket.CnSocketUtil;
|
import com.njcn.gather.detection.util.socket.CnSocketUtil;
|
||||||
@@ -70,15 +69,7 @@ public class NettySourceClientHandler extends SimpleChannelInboundHandler<String
|
|||||||
ctx.close();
|
ctx.close();
|
||||||
// 从Socket管理器中移除用户通道映射
|
// 从Socket管理器中移除用户通道映射
|
||||||
if (webUser != null && StrUtil.isNotBlank(userId)) {
|
if (webUser != null && StrUtil.isNotBlank(userId)) {
|
||||||
String key = userId + CnSocketUtil.SOURCE_TAG;
|
SocketManager.removeUser(userId + CnSocketUtil.SOURCE_TAG);
|
||||||
if (SocketManager.isActiveClosing(key)) {
|
|
||||||
SocketManager.removeMapping(key);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
SocketManager.removeUser(key);
|
|
||||||
// 源端主动断开 → 本次检测视为结束,释放检测锁
|
|
||||||
DetectionLockManager.getInstance()
|
|
||||||
.releaseIfMatchPage(userId, "SOURCE_CHANNEL_INACTIVE");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -95,7 +86,7 @@ public class NettySourceClientHandler extends SimpleChannelInboundHandler<String
|
|||||||
}
|
}
|
||||||
|
|
||||||
String userId = webUser.getUserPageId();
|
String userId = webUser.getUserPageId();
|
||||||
log.info("source接收server端数据, userId: {}, message: {}", userId, msg);
|
log.debug("源设备接收服务端数据, userId: {}, message: {}", userId, msg);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// 委托给专门的响应处理服务处理业务逻辑
|
// 委托给专门的响应处理服务处理业务逻辑
|
||||||
@@ -104,11 +95,6 @@ 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");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -125,11 +111,6 @@ 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) {
|
||||||
@@ -155,13 +136,6 @@ 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");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,29 +18,21 @@ import java.util.Set;
|
|||||||
@Component
|
@Component
|
||||||
@ConfigurationProperties(prefix = "socket")
|
@ConfigurationProperties(prefix = "socket")
|
||||||
public class SocketConnectionConfig {
|
public class SocketConnectionConfig {
|
||||||
|
/**
|
||||||
|
* 被检设备配置
|
||||||
|
*/
|
||||||
|
private DeviceConfig device = new DeviceConfig();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 程控源设备配置
|
* 程控源设备配置
|
||||||
*/
|
*/
|
||||||
private SourceConfig source = new SourceConfig();
|
private SourceConfig source = new SourceConfig();
|
||||||
|
|
||||||
/**
|
|
||||||
* 被检设备配置
|
|
||||||
*/
|
|
||||||
private DeviceConfig device = new DeviceConfig();
|
|
||||||
|
|
||||||
@Data
|
/**
|
||||||
public static class SourceConfig {
|
* 变频器配置
|
||||||
/**
|
*/
|
||||||
* 程控源IP地址
|
private DeviceConfig freqConverter = new DeviceConfig();
|
||||||
*/
|
|
||||||
private String ip;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 程控源端口号
|
|
||||||
*/
|
|
||||||
private Integer port;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
public static class DeviceConfig {
|
public static class DeviceConfig {
|
||||||
@@ -48,13 +40,33 @@ public class SocketConnectionConfig {
|
|||||||
* 被检设备IP地址
|
* 被检设备IP地址
|
||||||
*/
|
*/
|
||||||
private String ip;
|
private String ip;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 被检设备端口号
|
* 被检设备端口号
|
||||||
*/
|
*/
|
||||||
private Integer port;
|
private Integer port;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public static class SourceConfig {
|
||||||
|
/**
|
||||||
|
* 程控源IP地址
|
||||||
|
*/
|
||||||
|
private String ip;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 程控源端口号
|
||||||
|
*/
|
||||||
|
private Integer port;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取被检设备配置
|
||||||
|
*/
|
||||||
|
public DeviceConfig getDevice() {
|
||||||
|
return device;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取程控源配置
|
* 获取程控源配置
|
||||||
*/
|
*/
|
||||||
@@ -63,10 +75,10 @@ public class SocketConnectionConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取被检设备配置
|
* 获取变频器配置
|
||||||
*/
|
*/
|
||||||
public DeviceConfig getDevice() {
|
public DeviceConfig getFreqConverter() {
|
||||||
return device;
|
return freqConverter;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
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;
|
||||||
@@ -87,16 +86,6 @@ 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替代
|
||||||
@@ -153,19 +142,6 @@ 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)
|
||||||
* 支持多用户并发检测,每个用户的检测参数独立存储
|
* 支持多用户并发检测,每个用户的检测参数独立存储
|
||||||
@@ -320,8 +296,6 @@ 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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -339,25 +313,6 @@ 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,7 +1,6 @@
|
|||||||
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;
|
||||||
@@ -111,7 +110,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, ctx.channel());
|
WebServiceManager.removeByUserId(this.userId);
|
||||||
} else {
|
} else {
|
||||||
// 备用方案:如果userId为空,使用传统方法
|
// 备用方案:如果userId为空,使用传统方法
|
||||||
WebServiceManager.removeChannel(ctx.channel().id().toString());
|
WebServiceManager.removeChannel(ctx.channel().id().toString());
|
||||||
@@ -168,7 +167,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, ctx.channel());
|
WebServiceManager.removeByUserId(this.userId);
|
||||||
} else {
|
} else {
|
||||||
WebServiceManager.removeChannel(ctx.channel().id().toString());
|
WebServiceManager.removeChannel(ctx.channel().id().toString());
|
||||||
}
|
}
|
||||||
@@ -326,7 +325,7 @@ public class WebSocketHandler extends SimpleChannelInboundHandler<TextWebSocketF
|
|||||||
|
|
||||||
// 清理会话
|
// 清理会话
|
||||||
if (this.userId != null) {
|
if (this.userId != null) {
|
||||||
WebServiceManager.removeByUserId(this.userId, ctx.channel());
|
WebServiceManager.removeByUserId(this.userId);
|
||||||
log.debug("已清理WebSocket会话,userId: {}, channelId: {}", this.userId, channelId);
|
log.debug("已清理WebSocket会话,userId: {}, channelId: {}", this.userId, channelId);
|
||||||
} else {
|
} else {
|
||||||
WebServiceManager.removeChannel(channelId);
|
WebServiceManager.removeChannel(channelId);
|
||||||
@@ -415,11 +414,6 @@ 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);
|
||||||
@@ -427,4 +421,4 @@ public class WebSocketHandler extends SimpleChannelInboundHandler<TextWebSocketF
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ================================ URL解析工具已移至WebSocketPreprocessor ================================
|
// ================================ URL解析工具已移至WebSocketPreprocessor ================================
|
||||||
}
|
}
|
||||||
@@ -9,7 +9,6 @@ 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;
|
||||||
@@ -23,7 +22,6 @@ 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;
|
||||||
@@ -70,10 +68,10 @@ public class PqDevController extends BaseController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@OperateInfo(operateType = OperateType.ADD)
|
@OperateInfo(operateType = OperateType.ADD)
|
||||||
@PostMapping(value = "/add", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
@PostMapping("/add")
|
||||||
@ApiOperation("新增被检设备")
|
@ApiOperation("新增被检设备")
|
||||||
@ApiImplicitParam(name = "pqDevParam", value = "被检设备", required = true)
|
@ApiImplicitParam(name = "pqDevParam", value = "被检设备", required = true)
|
||||||
public HttpResult<Boolean> add(@ModelAttribute @Validated PqDevParam pqDevParam) {
|
public HttpResult<Boolean> add(@RequestBody @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);
|
||||||
@@ -85,10 +83,10 @@ public class PqDevController extends BaseController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@OperateInfo(operateType = OperateType.UPDATE)
|
@OperateInfo(operateType = OperateType.UPDATE)
|
||||||
@PostMapping(value = "/update", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
@PostMapping("/update")
|
||||||
@ApiOperation("修改被检设备")
|
@ApiOperation("修改被检设备")
|
||||||
@ApiImplicitParam(name = "updateParam", value = "被检设备", required = true)
|
@ApiImplicitParam(name = "updateParam", value = "被检设备", required = true)
|
||||||
public HttpResult<Boolean> update(@ModelAttribute @Validated PqDevParam.UpdateParam updateParam) {
|
public HttpResult<Boolean> update(@RequestBody @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);
|
||||||
@@ -99,14 +97,6 @@ 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("删除被检设备")
|
||||||
@@ -180,14 +170,33 @@ public class PqDevController extends BaseController {
|
|||||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
|
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
|
||||||
}
|
}
|
||||||
|
|
||||||
@OperateInfo
|
@OperateInfo(info = LogEnum.BUSINESS_COMMON, operateType = OperateType.UPLOAD)
|
||||||
@GetMapping("/getDataCheckRes")
|
@PostMapping(value = "/ttt")
|
||||||
@ApiOperation("获取接入测试-数据校验结果")
|
@ApiOperation("批量导入被检设备")
|
||||||
@ApiImplicitParam(name = "monitorId", value = "监测点id", required = true)
|
@ApiImplicitParams({
|
||||||
public HttpResult<DataCheckResDTO> getDataCheckRes(@RequestParam("monitorId") String monitorId) {
|
@ApiImplicitParam(name = "file", value = "被检设备数据文件", required = true),
|
||||||
String methodDescribe = getMethodDescribe("getDataCheckRes");
|
@ApiImplicitParam(name = "patternId", value = "模式id", required = true)
|
||||||
DataCheckResDTO dataCheckRes = pqDevService.getDataCheckRes(monitorId);
|
})
|
||||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, dataCheckRes, methodDescribe);
|
public HttpResult ttt(@RequestParam("file") MultipartFile file, @RequestParam("patternId") String patternId, @RequestParam("planId") String planId, @RequestParam(value = "cover", defaultValue = "0") Integer cover, HttpServletResponse response) {
|
||||||
|
String methodDescribe = getMethodDescribe("ttt");
|
||||||
|
LogUtil.njcnDebug(log, "{},上传文件为:{}", methodDescribe, file.getOriginalFilename());
|
||||||
|
boolean fileType = FileUtil.judgeFileIsExcel(file.getOriginalFilename());
|
||||||
|
if (!fileType) {
|
||||||
|
throw new BusinessException(CommonResponseEnum.FILE_XLSX_ERROR);
|
||||||
|
}
|
||||||
|
if ("null".equals(planId)) {
|
||||||
|
planId = null;
|
||||||
|
}
|
||||||
|
return pqDevService.importDev(file, patternId, planId, response, cover);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@OperateInfo
|
||||||
|
@GetMapping("/listAll")
|
||||||
|
@ApiOperation("查询所有未删除设备数据")
|
||||||
|
public HttpResult<List<PqDevVO>> listAll() {
|
||||||
|
String methodDescribe = getMethodDescribe("listAll");
|
||||||
|
LogUtil.njcnDebug(log, "{},查询所有设备", methodDescribe);
|
||||||
|
List<PqDevVO> result = pqDevService.listAll();
|
||||||
|
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -86,45 +86,8 @@
|
|||||||
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 <include refid="DevColumnsNoImage"/>, dev_sub.* FROM pq_dev dev
|
SELECT dev.*,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
|
||||||
@@ -161,7 +124,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 <include refid="DevColumnsNoImage"/>, dev_sub.*
|
SELECT dev.*, 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
|
||||||
|
|||||||
@@ -1,8 +0,0 @@
|
|||||||
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,7 +9,6 @@ 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.*;
|
||||||
@@ -137,9 +136,6 @@ public class PqDevParam {
|
|||||||
@ApiModelProperty("是否为导入设备")
|
@ApiModelProperty("是否为导入设备")
|
||||||
private Integer importFlag;
|
private Integer importFlag;
|
||||||
|
|
||||||
@ApiModelProperty("设备图片")
|
|
||||||
private MultipartFile image;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 更新操作实体
|
* 更新操作实体
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ 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;
|
||||||
@@ -185,9 +184,6 @@ public class PqDev extends BaseEntity implements Serializable {
|
|||||||
*/
|
*/
|
||||||
private Integer importFlag;
|
private Integer importFlag;
|
||||||
|
|
||||||
@JsonIgnore
|
|
||||||
private byte[] image;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 状态:0-删除 1-正常
|
* 状态:0-删除 1-正常
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -56,16 +56,10 @@ public class PqDevSub {
|
|||||||
private String checkBy;
|
private String checkBy;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 检测开始时间
|
* 检测时间
|
||||||
*/
|
*/
|
||||||
@TableField("Check_Start_Time")
|
@TableField("Check_Time")
|
||||||
private LocalDateTime checkStartTime;
|
private LocalDateTime checkTime;
|
||||||
|
|
||||||
/**
|
|
||||||
* 检测结束时间
|
|
||||||
*/
|
|
||||||
@TableField("Check_End_Time")
|
|
||||||
private LocalDateTime checkEndTime;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 预检测耗时
|
* 预检测耗时
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
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;
|
||||||
@@ -74,14 +73,9 @@ public class PqDevVO extends PqDev {
|
|||||||
private String checkBy;
|
private String checkBy;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 检测开始时间
|
* 检测时间
|
||||||
*/
|
*/
|
||||||
private LocalDateTime checkStartTime;
|
private LocalDateTime checkTime;
|
||||||
|
|
||||||
/**
|
|
||||||
* 检测结束时间
|
|
||||||
*/
|
|
||||||
private LocalDateTime checkEndTime;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 预检测耗时
|
* 预检测耗时
|
||||||
@@ -122,10 +116,4 @@ public class PqDevVO extends PqDev {
|
|||||||
* 检测点结果
|
* 检测点结果
|
||||||
*/
|
*/
|
||||||
private List<Integer> monitorResults;
|
private List<Integer> monitorResults;
|
||||||
|
|
||||||
private Boolean hasImage;
|
|
||||||
|
|
||||||
private String imageBase64;
|
|
||||||
|
|
||||||
private String imageContentType;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ 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;
|
||||||
@@ -96,14 +95,6 @@ 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);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取装置信息和装置下监测点信息
|
* 获取装置信息和装置下监测点信息
|
||||||
*
|
*
|
||||||
@@ -124,17 +115,9 @@ 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 updateCheckNum);
|
boolean updateResult(List<String> ids, List<String> adType, String code, String userId, Float temperature, Float humidity);
|
||||||
|
|
||||||
/**
|
|
||||||
* 新一轮正式检测真正开始前,仅清理原检测中设备的暂存耗时,并把本次设备置为检测中。
|
|
||||||
*/
|
|
||||||
void clearFormalProgressForNewRun(List<String> devIds);
|
|
||||||
|
|
||||||
Integer getMinFormalCheckTime(List<String> devIds);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 比对式-修改设备状态
|
* 比对式-修改设备状态
|
||||||
@@ -306,10 +289,5 @@ public interface IPqDevService extends IService<PqDev> {
|
|||||||
*/
|
*/
|
||||||
List<ContrastDevExcel> getExportContrastDevData(List<PqDevVO> pqDevVOList);
|
List<ContrastDevExcel> getExportContrastDevData(List<PqDevVO> pqDevVOList);
|
||||||
|
|
||||||
/**
|
List<PqDevVO> listAll();
|
||||||
* 获取接入测试-数据校验结果
|
|
||||||
* @param monitorId
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
DataCheckResDTO getDataCheckRes(String monitorId);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,14 +3,10 @@ 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,7 +5,6 @@ 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;
|
||||||
@@ -27,10 +26,7 @@ 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;
|
||||||
@@ -38,14 +34,10 @@ 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;
|
||||||
@@ -59,7 +51,6 @@ 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;
|
||||||
@@ -73,7 +64,6 @@ 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;
|
||||||
@@ -97,9 +87,6 @@ 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) {
|
||||||
@@ -141,8 +128,7 @@ 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, CopyOptions.create().setIgnoreProperties("image"));
|
BeanUtil.copyProperties(pqDevParam, pqDev);
|
||||||
fillImage(pqDev, pqDevParam);
|
|
||||||
String currrentScene = sysTestConfigService.getCurrrentScene();
|
String currrentScene = sysTestConfigService.getCurrrentScene();
|
||||||
this.checkParams(pqDev, currrentScene);
|
this.checkParams(pqDev, currrentScene);
|
||||||
|
|
||||||
@@ -173,19 +159,6 @@ 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, "图片处理失败");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 校验参数
|
* 校验参数
|
||||||
*
|
*
|
||||||
@@ -228,8 +201,7 @@ 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, CopyOptions.create().setIgnoreProperties("image"));
|
BeanUtil.copyProperties(updateParam, pqDev);
|
||||||
fillImage(pqDev, updateParam);
|
|
||||||
String currrentScene = sysTestConfigService.getCurrrentScene();
|
String currrentScene = sysTestConfigService.getCurrrentScene();
|
||||||
this.checkParams(pqDev, currrentScene);
|
this.checkParams(pqDev, currrentScene);
|
||||||
|
|
||||||
@@ -296,8 +268,6 @@ 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)
|
||||||
@@ -367,8 +337,24 @@ 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)) {
|
||||||
boolean allArchived = list.stream().allMatch(x -> x.getCheckState() != null && x.getCheckState() >= CheckStateEnum.DOCUMENTED.getValue());
|
List<String> unchecked = list.stream().filter(x -> CheckStateEnum.UNCHECKED.getValue().equals(x.getCheckState())).map(PqDevSub::getDevId).distinct().collect(Collectors.toList());
|
||||||
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();
|
||||||
@@ -396,10 +382,6 @@ 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()));
|
||||||
}
|
}
|
||||||
@@ -428,37 +410,6 @@ 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
|
||||||
@@ -468,7 +419,6 @@ 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())
|
||||||
@@ -531,48 +481,9 @@ 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 Integer getMinFormalCheckTime(List<String> devIds) {
|
public boolean updateResult(List<String> ids, List<String> adType, String code, String userId, Float temperature, Float humidity) {
|
||||||
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();
|
||||||
@@ -589,8 +500,7 @@ 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(updateCheckNum && SourceOperateCodeEnum.ALL_TEST.getValue().equals(FormalTestManager.reCheckType), PqDevSub::getCheckEndTime, LocalDateTime.now())
|
.set(PqDevSub::getCheckTime, 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)) {
|
||||||
@@ -605,33 +515,13 @@ 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 = pqDevVo.getCheckState() == CheckStateEnum.DOCUMENTED.getValue() ? CheckStateEnum.DOCUMENTED.getValue() : CheckStateEnum.CHECKED.getValue();
|
checkState = 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()));
|
||||||
@@ -646,14 +536,19 @@ public class PqDevServiceImpl extends ServiceImpl<PqDevMapper, PqDev> implements
|
|||||||
this.baseMapper.updatePlanCheckResult(pqDevVo.getPlanId(), CheckResultEnum.ACCORD.getValue());
|
this.baseMapper.updatePlanCheckResult(pqDevVo.getPlanId(), CheckResultEnum.ACCORD.getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean allUnchecked = pqDevVOList.stream().allMatch(obj -> CheckStateEnum.UNCHECKED.getValue().equals(obj.getCheckState()));
|
set = pqDevVOList.stream().map(PqDevVO::getCheckState).collect(Collectors.toSet());
|
||||||
boolean allArchived = pqDevVOList.stream().allMatch(obj -> obj.getCheckState() != null && obj.getCheckState() >= CheckStateEnum.DOCUMENTED.getValue());
|
if (set.contains(CheckStateEnum.UNCHECKED.getValue())) {
|
||||||
if (allUnchecked) {
|
|
||||||
this.baseMapper.updatePlanTestState(pqDevVo.getPlanId(), CheckStateEnum.UNCHECKED.getValue());
|
|
||||||
} else if (allArchived) {
|
|
||||||
this.baseMapper.updatePlanTestState(pqDevVo.getPlanId(), CheckStateEnum.CHECKED.getValue());
|
|
||||||
} else {
|
|
||||||
this.baseMapper.updatePlanTestState(pqDevVo.getPlanId(), CheckStateEnum.CHECKING.getValue());
|
this.baseMapper.updatePlanTestState(pqDevVo.getPlanId(), CheckStateEnum.CHECKING.getValue());
|
||||||
|
} else {
|
||||||
|
if (checkState.equals(CheckStateEnum.DOCUMENTED.getValue())) {
|
||||||
|
long count = pqDevVOList.stream().filter(obj -> !CheckStateEnum.DOCUMENTED.getValue().equals(obj.getCheckState())).count();
|
||||||
|
if (count == 0) {
|
||||||
|
// 如果非归档状态的设备数量为0,则更新计划已完成
|
||||||
|
this.baseMapper.finishPlan(pqDevVo.getPlanId());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
this.baseMapper.updatePlanTestState(pqDevVo.getPlanId(), CheckStateEnum.CHECKING.getValue());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -678,23 +573,13 @@ 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());
|
||||||
}
|
}
|
||||||
@@ -702,7 +587,6 @@ 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();
|
||||||
@@ -710,7 +594,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 -> obj.getCheckState() != null && obj.getCheckState() >= CheckStateEnum.CHECKED.getValue()).map(PqDevVO::getCheckResult).collect(Collectors.toSet());
|
Set<Integer> set = pqDevVOList.stream().filter(obj -> CheckStateEnum.CHECKED.getValue().equals(obj.getCheckState()) || CheckStateEnum.DOCUMENTED.getValue().equals(obj.getCheckState())).map(PqDevVO::getCheckResult).collect(Collectors.toSet());
|
||||||
if (checkState == CheckStateEnum.CHECKED.getValue()) {
|
if (checkState == CheckStateEnum.CHECKED.getValue()) {
|
||||||
set.add(checkResult);
|
set.add(checkResult);
|
||||||
}
|
}
|
||||||
@@ -727,51 +611,17 @@ public class PqDevServiceImpl extends ServiceImpl<PqDevMapper, PqDev> implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
boolean allUnchecked = pqDevVOList.stream().allMatch(obj -> CheckStateEnum.UNCHECKED.getValue().equals(obj.getCheckState()));
|
set = pqDevVOList.stream().map(PqDevVO::getCheckState).collect(Collectors.toSet());
|
||||||
boolean allArchived = pqDevVOList.stream().allMatch(obj -> obj.getCheckState() != null && obj.getCheckState() >= CheckStateEnum.DOCUMENTED.getValue());
|
if (set.contains(CheckStateEnum.UNCHECKED.getValue())) {
|
||||||
if (allUnchecked) {
|
|
||||||
this.baseMapper.updatePlanTestState(planId, CheckStateEnum.UNCHECKED.getValue());
|
|
||||||
} else if (allArchived) {
|
|
||||||
this.baseMapper.updatePlanTestState(planId, CheckStateEnum.CHECKED.getValue());
|
|
||||||
} else {
|
|
||||||
this.baseMapper.updatePlanTestState(planId, CheckStateEnum.CHECKING.getValue());
|
this.baseMapper.updatePlanTestState(planId, CheckStateEnum.CHECKING.getValue());
|
||||||
|
} else if (set.contains(CheckStateEnum.CHECKING.getValue())) {
|
||||||
|
this.baseMapper.updatePlanTestState(planId, CheckStateEnum.CHECKING.getValue());
|
||||||
|
} else {
|
||||||
|
this.baseMapper.updatePlanTestState(planId, CheckStateEnum.CHECKED.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<>();
|
||||||
@@ -1751,10 +1601,7 @@ 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()
|
List<PqDev> pqDevList = this.lambdaQuery().eq(PqDev::getPattern, pattern)
|
||||||
.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"};
|
||||||
@@ -1780,9 +1627,29 @@ public class PqDevServiceImpl extends ServiceImpl<PqDevMapper, PqDev> implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DataCheckResDTO getDataCheckRes(String monitorId) {
|
public List<PqDevVO> listAll() {
|
||||||
// restTemplateUtil.postJson();
|
return this.lambdaQuery()
|
||||||
DataCheckResDTO dataCheckResDTO = restTemplateUtil.postJson("http://localhost:8080/api/v1/dataCheck/getDataCheckRes", monitorId, DataCheckResDTO.class);
|
.eq(PqDev::getState, DataStateEnum.ENABLE.getCode())
|
||||||
return dataCheckResDTO;
|
.orderByDesc(PqDev::getCreateTime)
|
||||||
|
.list().stream().map(pqDev -> {
|
||||||
|
PqDevVO pqDevVO = new PqDevVO();
|
||||||
|
BeanUtil.copyProperties(pqDev, pqDevVO);
|
||||||
|
// 解密序列号和密钥
|
||||||
|
if (StrUtil.isNotBlank(pqDevVO.getSeries())) {
|
||||||
|
pqDevVO.setSeries(EncryptionUtil.decoderString(1, pqDevVO.getSeries()));
|
||||||
|
}
|
||||||
|
if (StrUtil.isNotBlank(pqDevVO.getDevKey())) {
|
||||||
|
pqDevVO.setDevKey(EncryptionUtil.decoderString(1, pqDevVO.getDevKey()));
|
||||||
|
}
|
||||||
|
// 填充设备类型信息
|
||||||
|
DevType devType = devTypeService.getById(pqDevVO.getDevType());
|
||||||
|
if (ObjectUtil.isNotNull(devType)) {
|
||||||
|
pqDevVO.setDevType(devType.getName());
|
||||||
|
pqDevVO.setDevChns(devType.getDevChns());
|
||||||
|
pqDevVO.setDevVolt(devType.getDevVolt());
|
||||||
|
pqDevVO.setDevCurr(devType.getDevCurr());
|
||||||
|
}
|
||||||
|
return pqDevVO;
|
||||||
|
}).collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,20 +1,13 @@
|
|||||||
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.mapper.PqDevSubMapper;
|
|
||||||
import com.njcn.gather.device.pojo.po.PqDevSub;
|
import com.njcn.gather.device.pojo.po.PqDevSub;
|
||||||
|
import com.njcn.gather.device.mapper.PqDevSubMapper;
|
||||||
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
|
||||||
@@ -23,19 +16,5 @@ import java.util.Objects;
|
|||||||
@Service
|
@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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,181 +0,0 @@
|
|||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
package com.njcn.gather.dip.mapper;
|
||||||
|
|
||||||
|
import com.github.yulichang.base.MPJBaseMapper;
|
||||||
|
import com.njcn.gather.dip.pojo.po.PqDipData;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author caozehui
|
||||||
|
* @date 2026-04-09
|
||||||
|
*/
|
||||||
|
public interface PqDipDataMapper extends MPJBaseMapper<PqDipData> {
|
||||||
|
}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
package com.njcn.gather.dip.pojo.po;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 电压暂降数据
|
||||||
|
*
|
||||||
|
* @author caozehui
|
||||||
|
* @date 2026-04-09
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@TableName(value = "ad_harmonic_xx")
|
||||||
|
public class PqDipData {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 主键ID
|
||||||
|
*/
|
||||||
|
private String id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 起始时间戳
|
||||||
|
*/
|
||||||
|
private LocalDateTime startTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 残余电压,单位:%Ur
|
||||||
|
*/
|
||||||
|
private Double residualVoltage;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 持续时间,单位:ms
|
||||||
|
*/
|
||||||
|
private Integer durationMs;
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
package com.njcn.gather.dip.pojo.po.vo;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author caozehui
|
||||||
|
* @data 2026-04-16
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class DipPoint {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 残余电压,单位:%Ur
|
||||||
|
*/
|
||||||
|
private Double residualVoltage;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 持续时间,单位:ms
|
||||||
|
*/
|
||||||
|
private Integer durationMs;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 0为不耐受,1为耐受
|
||||||
|
*/
|
||||||
|
private Boolean tolerant;
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
package com.njcn.gather.dip.service;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
import com.njcn.gather.dip.pojo.po.PqDipData;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author caozehui
|
||||||
|
* @date 2026-04-09
|
||||||
|
*/
|
||||||
|
public interface IPqDipDataService extends IService<PqDipData> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询指定变频器所对应的电压暂降数据
|
||||||
|
*
|
||||||
|
* @param suffix 表后缀
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
List<PqDipData> listDipData(Integer suffix);
|
||||||
|
|
||||||
|
void clearAllData(Integer suffix);
|
||||||
|
}
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
package com.njcn.gather.dip.service.impl;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.njcn.db.mybatisplus.handler.DynamicTableNameHandler;
|
||||||
|
import com.njcn.gather.dip.mapper.PqDipDataMapper;
|
||||||
|
import com.njcn.gather.dip.pojo.po.PqDipData;
|
||||||
|
import com.njcn.gather.dip.service.IPqDipDataService;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author caozehui
|
||||||
|
* @date 2026-04-09
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
public class PqDipDataServiceImpl extends ServiceImpl<PqDipDataMapper, PqDipData> implements IPqDipDataService {
|
||||||
|
@Override
|
||||||
|
public List<PqDipData> listDipData(Integer suffix) {
|
||||||
|
DynamicTableNameHandler.setTableName("pq_dip_data_" + suffix);
|
||||||
|
LambdaQueryChainWrapper<PqDipData> wrapper = this.lambdaQuery().orderByAsc(PqDipData::getStartTime);
|
||||||
|
List<PqDipData> result = wrapper.list();
|
||||||
|
DynamicTableNameHandler.remove();
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void clearAllData(Integer suffix) {
|
||||||
|
DynamicTableNameHandler.setTableName("pq_dip_data_" + suffix);
|
||||||
|
this.remove(null);
|
||||||
|
DynamicTableNameHandler.remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
package com.njcn.gather.freqConverter.config;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author caozehui
|
||||||
|
* @data 2026-04-15
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Component
|
||||||
|
@ConfigurationProperties(prefix = "freq-converter")
|
||||||
|
public class FreqConverterConfig {
|
||||||
|
private Long schedulePeriod;
|
||||||
|
private Integer tolerant;
|
||||||
|
private Integer dt;
|
||||||
|
private Integer direction;
|
||||||
|
private Integer allowErrorDuration;
|
||||||
|
private Double allowErrorResidualVoltage;
|
||||||
|
}
|
||||||
@@ -0,0 +1,116 @@
|
|||||||
|
package com.njcn.gather.freqConverter.controller;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
import com.njcn.common.pojo.annotation.OperateInfo;
|
||||||
|
import com.njcn.common.pojo.constant.OperateType;
|
||||||
|
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
|
||||||
|
import com.njcn.common.pojo.response.HttpResult;
|
||||||
|
import com.njcn.common.utils.LogUtil;
|
||||||
|
import com.njcn.gather.freqConverter.pojo.param.PqFreqConverterParam;
|
||||||
|
import com.njcn.gather.freqConverter.pojo.po.PqFreqConverterConfig;
|
||||||
|
import com.njcn.gather.freqConverter.pojo.vo.TolerantPointVO;
|
||||||
|
import com.njcn.gather.freqConverter.service.IFreqConverterService;
|
||||||
|
import com.njcn.gather.freqConverter.service.IPqFreqConverterConfigService;
|
||||||
|
import com.njcn.web.controller.BaseController;
|
||||||
|
import com.njcn.web.utils.HttpResultUtil;
|
||||||
|
import io.swagger.annotations.Api;
|
||||||
|
import io.swagger.annotations.ApiImplicitParam;
|
||||||
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author caozehui
|
||||||
|
* @data 2026-04-13
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@Api(tags = "变频器")
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/freqConverter")
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class FreqConverterController extends BaseController {
|
||||||
|
private final IFreqConverterService freqConverterService;
|
||||||
|
private final IPqFreqConverterConfigService pqFreqConverterConfigService;
|
||||||
|
|
||||||
|
|
||||||
|
@OperateInfo
|
||||||
|
@PostMapping("/list")
|
||||||
|
@ApiOperation("分页查询变频器列表")
|
||||||
|
@ApiImplicitParam(name = "queryParam", value = "查询参数", required = true)
|
||||||
|
public HttpResult<Page<PqFreqConverterConfig>> list(@RequestBody @Validated PqFreqConverterParam.QueryParam queryParam) {
|
||||||
|
String methodDescribe = getMethodDescribe("list");
|
||||||
|
LogUtil.njcnDebug(log, "{},查询数据为:{}", methodDescribe, queryParam);
|
||||||
|
Page<PqFreqConverterConfig> result = pqFreqConverterConfigService.listPqFreqConverterConfigs(queryParam);
|
||||||
|
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
|
||||||
|
}
|
||||||
|
|
||||||
|
@OperateInfo(operateType = OperateType.ADD)
|
||||||
|
@PostMapping("/add")
|
||||||
|
@ApiOperation("新增变频器")
|
||||||
|
@ApiImplicitParam(name = "pqDevParam", value = "被检设备", required = true)
|
||||||
|
public HttpResult<Boolean> add(@RequestBody @Validated PqFreqConverterParam param) {
|
||||||
|
String methodDescribe = getMethodDescribe("add");
|
||||||
|
LogUtil.njcnDebug(log, "{},新增数据为:{}", methodDescribe, param);
|
||||||
|
boolean result = pqFreqConverterConfigService.addPqFreqConverterConfig(param);
|
||||||
|
if (result) {
|
||||||
|
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, methodDescribe);
|
||||||
|
} else {
|
||||||
|
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, false, methodDescribe);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@OperateInfo(operateType = OperateType.UPDATE)
|
||||||
|
@PostMapping("/update")
|
||||||
|
@ApiOperation("修改变频器")
|
||||||
|
@ApiImplicitParam(name = "updateParam", value = "被检设备", required = true)
|
||||||
|
public HttpResult<Boolean> update(@RequestBody @Validated PqFreqConverterParam.UpdateParam param) {
|
||||||
|
String methodDescribe = getMethodDescribe("update");
|
||||||
|
LogUtil.njcnDebug(log, "{},修改数据为:{}", methodDescribe, param);
|
||||||
|
boolean result = pqFreqConverterConfigService.updatePqFreqConverterConfig(param);
|
||||||
|
if (result) {
|
||||||
|
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, methodDescribe);
|
||||||
|
} else {
|
||||||
|
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, false, methodDescribe);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@OperateInfo(operateType = OperateType.DELETE)
|
||||||
|
@PostMapping("/delete")
|
||||||
|
@ApiOperation("删除变频器")
|
||||||
|
@ApiImplicitParam(name = "param", value = "删除参数", required = true)
|
||||||
|
public HttpResult<Boolean> delete(@RequestBody @Validated List<String> ids) {
|
||||||
|
String methodDescribe = getMethodDescribe("delete");
|
||||||
|
LogUtil.njcnDebug(log, "{},删除ID数据为:{}", methodDescribe, String.join(StrUtil.COMMA, ids));
|
||||||
|
boolean result = pqFreqConverterConfigService.deletePqFreqConverterConfig(ids);
|
||||||
|
if (result) {
|
||||||
|
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, methodDescribe);
|
||||||
|
} else {
|
||||||
|
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, false, methodDescribe);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/result")
|
||||||
|
@ApiOperation("查询变频器测试结果")
|
||||||
|
@ApiImplicitParam(name = "param", value = "查询参数", required = true)
|
||||||
|
public HttpResult<List<TolerantPointVO>> result(@RequestParam("converterId") String converterId) {
|
||||||
|
String methodDescribe = getMethodDescribe("result");
|
||||||
|
LogUtil.njcnDebug(log, "{},查询ID数据为:{}", methodDescribe, converterId);
|
||||||
|
List<TolerantPointVO> tolerantPoints = freqConverterService.getDipPoints(converterId);
|
||||||
|
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, tolerantPoints, methodDescribe);
|
||||||
|
}
|
||||||
|
|
||||||
|
// @GetMapping("/scurve")
|
||||||
|
// @ApiOperation("获取绘制特性曲线的point点")
|
||||||
|
// @ApiImplicitParam(name = "converterId", value = "变频器ID", required = true)
|
||||||
|
// public HttpResult<List<TolerantPointVO>> getScurvePoints(@RequestParam("converterId") String converterId) {
|
||||||
|
// String methodDescribe = getMethodDescribe("getScurvePoints");
|
||||||
|
// LogUtil.njcnDebug(log, "{},查询ID数据为:{}", methodDescribe, converterId);
|
||||||
|
// List<TolerantPointVO> tolerantPoints = freqConverterService.getFeaturesScurvePoints(converterId);
|
||||||
|
// return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, tolerantPoints, methodDescribe);
|
||||||
|
// }
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
package com.njcn.gather.freqConverter.mapper;
|
||||||
|
|
||||||
|
import com.github.yulichang.base.MPJBaseMapper;
|
||||||
|
import com.njcn.gather.freqConverter.pojo.po.FreqConverterStatus;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author caozehui
|
||||||
|
* @data 2026-04-07
|
||||||
|
*/
|
||||||
|
public interface FreqConverterStatusMapper extends MPJBaseMapper<FreqConverterStatus> {
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
package com.njcn.gather.freqConverter.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.njcn.gather.freqConverter.pojo.po.PqFreqConverterConfig;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author caozehui
|
||||||
|
* @data 2026-04-08
|
||||||
|
*/
|
||||||
|
public interface PqFreqConverterConfigMapper extends BaseMapper<PqFreqConverterConfig> {
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
package com.njcn.gather.freqConverter.mapper;
|
||||||
|
|
||||||
|
import com.github.yulichang.base.MPJBaseMapper;
|
||||||
|
import com.njcn.gather.freqConverter.pojo.po.PqFreqConverterTestRes;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author caozehui
|
||||||
|
* @data 2026-04-14
|
||||||
|
*/
|
||||||
|
public interface PqFreqConverterTestResMapper extends MPJBaseMapper<PqFreqConverterTestRes> {
|
||||||
|
}
|
||||||
@@ -0,0 +1,66 @@
|
|||||||
|
package com.njcn.gather.freqConverter.pojo.param;
|
||||||
|
|
||||||
|
import com.njcn.common.pojo.constant.PatternRegex;
|
||||||
|
import com.njcn.gather.pojo.constant.DetectionValidMessage;
|
||||||
|
import com.njcn.web.pojo.param.BaseParam;
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
|
||||||
|
import javax.validation.constraints.NotBlank;
|
||||||
|
import javax.validation.constraints.Pattern;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author caozehui
|
||||||
|
* @data 2026-04-13
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class PqFreqConverterParam {
|
||||||
|
@ApiModelProperty(value = "名称", required = true)
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "电脑串口名", required = true)
|
||||||
|
private String portName;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "变频器设置从机地址", required = true)
|
||||||
|
private Integer slaveAddress;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "变频器设置波特率", required = true)
|
||||||
|
private Integer baudRate;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "奇偶校验类型: None, Even, Odd", required = true)
|
||||||
|
private String parity;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "变频器数据位", required = true)
|
||||||
|
private Integer dataBits;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "变频器停止位,当前只支持 1 或 2", required = true)
|
||||||
|
private Integer stopBits;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "串口读写超时,单位毫秒", required = true)
|
||||||
|
private Integer timeoutMs;
|
||||||
|
private Integer testStatus;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分页查询实体
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
public static class QueryParam extends BaseParam {
|
||||||
|
@ApiModelProperty(value = "名称", required = true)
|
||||||
|
private String name;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新操作实体
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
public static class UpdateParam extends PqFreqConverterParam {
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "id", required = true)
|
||||||
|
@NotBlank(message = DetectionValidMessage.ID_NOT_BLANK)
|
||||||
|
@Pattern(regexp = PatternRegex.SYSTEM_ID, message = DetectionValidMessage.ID_FORMAT_ERROR)
|
||||||
|
private String id;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
package com.njcn.gather.freqConverter.pojo.po;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author caozehui
|
||||||
|
* @data 2026-04-07
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@TableName(value = "ad_harmonic_xx")
|
||||||
|
public class FreqConverterStatus {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 主键ID
|
||||||
|
*/
|
||||||
|
private String id;
|
||||||
|
|
||||||
|
private Integer slaveAddress;
|
||||||
|
|
||||||
|
private Integer statusWord1;
|
||||||
|
|
||||||
|
private String statusWord1Hex;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 状态记录时刻(时间戳)
|
||||||
|
*/
|
||||||
|
private LocalDateTime timestamp;
|
||||||
|
}
|
||||||
@@ -0,0 +1,73 @@
|
|||||||
|
package com.njcn.gather.freqConverter.pojo.po;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import com.njcn.db.mybatisplus.bo.BaseEntity;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 变频器配置实体类
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@TableName("pq_freq_converter_config")
|
||||||
|
public class PqFreqConverterConfig extends BaseEntity {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 主键ID
|
||||||
|
*/
|
||||||
|
private String id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 变频器名称
|
||||||
|
*/
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 电脑串口名,如COM1
|
||||||
|
*/
|
||||||
|
private String portName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 变频器设置从机地址,范围1~127
|
||||||
|
*/
|
||||||
|
private Integer slaveAddress;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 变频器设置波特率,如19200
|
||||||
|
*/
|
||||||
|
private Integer baudRate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 奇偶校验类型: None, Even, Odd
|
||||||
|
*/
|
||||||
|
private String parity;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 变频器数据位
|
||||||
|
*/
|
||||||
|
private Integer dataBits;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 变频器停止位,当前只支持 1 或 2
|
||||||
|
*/
|
||||||
|
private Integer stopBits;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 串口读写超时,单位毫秒
|
||||||
|
*/
|
||||||
|
private Integer timeoutMs;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据表后缀
|
||||||
|
*/
|
||||||
|
private Integer suffix;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检测状态,0未检测,1检测完成
|
||||||
|
*/
|
||||||
|
private Integer testStatus;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 状态:0-删除 1-正常
|
||||||
|
*/
|
||||||
|
private Integer state;
|
||||||
|
}
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
package com.njcn.gather.freqConverter.pojo.po;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author caozehui
|
||||||
|
* @data 2026-04-14
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@TableName(value = "ad_harmonic_xx")
|
||||||
|
public class PqFreqConverterTestRes {
|
||||||
|
/**
|
||||||
|
* 主键ID
|
||||||
|
*/
|
||||||
|
private String id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 残余电压,单位:%Ur
|
||||||
|
*/
|
||||||
|
private Double residualVoltage;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 持续时间,单位:ms
|
||||||
|
*/
|
||||||
|
private Integer durationMs;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 0为不耐受,1为耐受,2为特性曲线点
|
||||||
|
*/
|
||||||
|
private Integer tolerant;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 时间
|
||||||
|
*/
|
||||||
|
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss.SSS", timezone = "GMT+8")
|
||||||
|
private LocalDateTime time;
|
||||||
|
}
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
package com.njcn.gather.freqConverter.pojo.vo;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author caozehui
|
||||||
|
* @data 2026-04-13
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class TolerantPointVO {
|
||||||
|
/**
|
||||||
|
* 持续时间,单位ms
|
||||||
|
*/
|
||||||
|
private Integer durationMs;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 残余电压,单位:%Ur
|
||||||
|
*/
|
||||||
|
private Double residualVoltage;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否耐受。0-否,1-是,2-表示特性曲线点
|
||||||
|
*/
|
||||||
|
private Integer tolerant;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 时间
|
||||||
|
*/
|
||||||
|
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss.SSS", timezone = "GMT+8")
|
||||||
|
private LocalDateTime time;
|
||||||
|
}
|
||||||
@@ -0,0 +1,62 @@
|
|||||||
|
package com.njcn.gather.freqConverter.service;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
import com.njcn.gather.freqConverter.pojo.po.FreqConverterStatus;
|
||||||
|
import com.njcn.gather.freqConverter.pojo.vo.TolerantPointVO;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author caozehui
|
||||||
|
* @data 2026-04-07
|
||||||
|
*/
|
||||||
|
public interface IFreqConverterService extends IService<FreqConverterStatus> {
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 保存变频器状态数据
|
||||||
|
*
|
||||||
|
* @param suffix 表后缀
|
||||||
|
* @param status 变频器状态数据
|
||||||
|
* @return 是否保存成功
|
||||||
|
*/
|
||||||
|
boolean saveFreqConverterStatus(Integer suffix, FreqConverterStatus status);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询指定变频器的状态历史
|
||||||
|
*
|
||||||
|
* @param converterId 变频器ID
|
||||||
|
* @return 状态数据列表
|
||||||
|
*/
|
||||||
|
List<FreqConverterStatus> listStatusData(String converterId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 清空所有数据
|
||||||
|
*
|
||||||
|
* @param converterId 变频器ID
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
void clearAllData(Integer converterId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据设备暂降数据判断变频器是否耐受
|
||||||
|
*
|
||||||
|
* @param converterId 变频器Id
|
||||||
|
* @return 是否耐受
|
||||||
|
*/
|
||||||
|
List<TolerantPointVO> getDipPoints(String converterId);
|
||||||
|
|
||||||
|
List<FreqConverterStatus> getDipDurationStatusData(Integer suffix, LocalDateTime startTime, LocalDateTime endTime);
|
||||||
|
|
||||||
|
FreqConverterStatus getLastStatusData(Integer suffix, LocalDateTime startTime);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取变频器特性曲线点
|
||||||
|
*
|
||||||
|
* @param converterId 变频器ID
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
List<TolerantPointVO> getFeaturesScurvePoints(String converterId);
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
package com.njcn.gather.freqConverter.service;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
import com.njcn.gather.freqConverter.pojo.param.PqFreqConverterParam;
|
||||||
|
import com.njcn.gather.freqConverter.pojo.po.PqFreqConverterConfig;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author caozehui
|
||||||
|
* @data 2026-04-08
|
||||||
|
*/
|
||||||
|
public interface IPqFreqConverterConfigService extends IService<PqFreqConverterConfig> {
|
||||||
|
Page<PqFreqConverterConfig> listPqFreqConverterConfigs(PqFreqConverterParam.QueryParam queryParam);
|
||||||
|
|
||||||
|
Integer getSuffix(String converterId);
|
||||||
|
|
||||||
|
boolean addPqFreqConverterConfig(PqFreqConverterParam param);
|
||||||
|
|
||||||
|
boolean updatePqFreqConverterConfig(PqFreqConverterParam.UpdateParam param);
|
||||||
|
|
||||||
|
boolean deletePqFreqConverterConfig(List<String> ids);
|
||||||
|
|
||||||
|
boolean updateTestStatus(String converterId, Integer testStatus);
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
package com.njcn.gather.freqConverter.service;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
import com.njcn.gather.freqConverter.pojo.po.PqFreqConverterTestRes;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author caozehui
|
||||||
|
* @data 2026-04-14
|
||||||
|
*/
|
||||||
|
public interface IPqFreqConverterTestResService extends IService<PqFreqConverterTestRes> {
|
||||||
|
/**
|
||||||
|
* 清空所有数据
|
||||||
|
*
|
||||||
|
* @param suffix 表后缀
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
void clearAllData(Integer suffix);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增结果记录
|
||||||
|
*
|
||||||
|
* @param suffix 表后缀
|
||||||
|
* @param testResList 结果数据
|
||||||
|
* @return 是否成功
|
||||||
|
*/
|
||||||
|
boolean saveTestRes(Integer suffix, List<PqFreqConverterTestRes> testResList);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新结果记录
|
||||||
|
*
|
||||||
|
* @param suffix 表后缀
|
||||||
|
* @param testResList 结果数据
|
||||||
|
* @return 是否成功
|
||||||
|
*/
|
||||||
|
boolean updateTestRes(Integer suffix, List<PqFreqConverterTestRes> testResList);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询结果记录
|
||||||
|
*
|
||||||
|
* @param suffix 表后缀
|
||||||
|
* @return 结果列表
|
||||||
|
*/
|
||||||
|
List<PqFreqConverterTestRes> listTestRes(Integer suffix);
|
||||||
|
|
||||||
|
PqFreqConverterTestRes getLastByDuration(Integer suffix, String id, Integer durationMs);
|
||||||
|
|
||||||
|
PqFreqConverterTestRes getLastByResidualVoltage(Integer suffix, String id, Double residualVoltage);
|
||||||
|
}
|
||||||
@@ -0,0 +1,172 @@
|
|||||||
|
package com.njcn.gather.freqConverter.service.impl;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.IdUtil;
|
||||||
|
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.njcn.db.mybatisplus.handler.DynamicTableNameHandler;
|
||||||
|
import com.njcn.gather.dip.service.IPqDipDataService;
|
||||||
|
import com.njcn.gather.freqConverter.mapper.FreqConverterStatusMapper;
|
||||||
|
import com.njcn.gather.freqConverter.pojo.po.FreqConverterStatus;
|
||||||
|
import com.njcn.gather.freqConverter.pojo.po.PqFreqConverterTestRes;
|
||||||
|
import com.njcn.gather.freqConverter.pojo.vo.TolerantPointVO;
|
||||||
|
import com.njcn.gather.freqConverter.service.IFreqConverterService;
|
||||||
|
import com.njcn.gather.freqConverter.service.IPqFreqConverterConfigService;
|
||||||
|
import com.njcn.gather.freqConverter.service.IPqFreqConverterTestResService;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 变频器状态数据Service实现类
|
||||||
|
* <p>
|
||||||
|
* 实现变频器状态数据的存储、查询和清理功能。
|
||||||
|
* 当数据量超过阈值时,自动清理无效或过期数据,避免内存和数据库资源浪费。
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @author CN_Gather Detection Team
|
||||||
|
* @version 1.0
|
||||||
|
* @since 2026
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class FreqConverterServiceImpl extends ServiceImpl<FreqConverterStatusMapper, FreqConverterStatus> implements IFreqConverterService {
|
||||||
|
private final IPqFreqConverterConfigService pqFreqConverterConfigService;
|
||||||
|
private final IPqDipDataService dipDataService;
|
||||||
|
private final IPqFreqConverterTestResService pqFreqConverterTestResService;
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public boolean saveFreqConverterStatus(Integer suffix, FreqConverterStatus status) {
|
||||||
|
if (status.getId() == null) {
|
||||||
|
status.setId(IdUtil.fastSimpleUUID());
|
||||||
|
}
|
||||||
|
DynamicTableNameHandler.setTableName(PqFreqConverterConfigServiceImpl.PQ_FREQ_CONVERTER_STATUS_TB_PREFIX + suffix);
|
||||||
|
boolean result = this.save(status);
|
||||||
|
DynamicTableNameHandler.remove();
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<FreqConverterStatus> listStatusData(String converterId) {
|
||||||
|
Integer suffix = pqFreqConverterConfigService.getSuffix(converterId);
|
||||||
|
|
||||||
|
DynamicTableNameHandler.setTableName(PqFreqConverterConfigServiceImpl.PQ_FREQ_CONVERTER_STATUS_TB_PREFIX + suffix);
|
||||||
|
LambdaQueryChainWrapper<FreqConverterStatus> wrapper = this.lambdaQuery().orderByAsc(FreqConverterStatus::getTimestamp);
|
||||||
|
List<FreqConverterStatus> result = wrapper.list();
|
||||||
|
DynamicTableNameHandler.remove();
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public void clearAllData(Integer suffix) {
|
||||||
|
DynamicTableNameHandler.setTableName(PqFreqConverterConfigServiceImpl.PQ_FREQ_CONVERTER_STATUS_TB_PREFIX + suffix);
|
||||||
|
this.remove(null);
|
||||||
|
DynamicTableNameHandler.remove();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<TolerantPointVO> getDipPoints(String converterId) {
|
||||||
|
Integer suffix = pqFreqConverterConfigService.getSuffix(converterId);
|
||||||
|
|
||||||
|
DynamicTableNameHandler.setTableName(PqFreqConverterConfigServiceImpl.PQ_FREQ_CONVERTER_TEST_RES_TB_PREFIX + suffix);
|
||||||
|
List<PqFreqConverterTestRes> pqFreqConverterTestResList = pqFreqConverterTestResService.list();
|
||||||
|
DynamicTableNameHandler.remove();
|
||||||
|
List<TolerantPointVO> result = pqFreqConverterTestResList.stream().map(item -> {
|
||||||
|
TolerantPointVO tolerantPointVO = new TolerantPointVO();
|
||||||
|
tolerantPointVO.setDurationMs(item.getDurationMs());
|
||||||
|
tolerantPointVO.setResidualVoltage(item.getResidualVoltage());
|
||||||
|
tolerantPointVO.setTolerant(item.getTolerant());
|
||||||
|
tolerantPointVO.setTime(item.getTime());
|
||||||
|
return tolerantPointVO;
|
||||||
|
})
|
||||||
|
.sorted(Comparator.comparingInt(TolerantPointVO::getDurationMs))
|
||||||
|
.sorted(Comparator.comparingDouble(TolerantPointVO::getResidualVoltage)).collect(Collectors.toList());
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<FreqConverterStatus> getDipDurationStatusData(Integer suffix, LocalDateTime startTime, LocalDateTime endTime) {
|
||||||
|
DynamicTableNameHandler.setTableName(PqFreqConverterConfigServiceImpl.PQ_FREQ_CONVERTER_STATUS_TB_PREFIX + suffix);
|
||||||
|
List<FreqConverterStatus> result = this.lambdaQuery()
|
||||||
|
.between(FreqConverterStatus::getTimestamp, startTime, endTime)
|
||||||
|
.orderByAsc(FreqConverterStatus::getTimestamp)
|
||||||
|
.list();
|
||||||
|
DynamicTableNameHandler.remove();
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FreqConverterStatus getLastStatusData(Integer suffix, LocalDateTime startTime) {
|
||||||
|
DynamicTableNameHandler.setTableName(PqFreqConverterConfigServiceImpl.PQ_FREQ_CONVERTER_STATUS_TB_PREFIX + suffix);
|
||||||
|
FreqConverterStatus one = this.lambdaQuery().le(FreqConverterStatus::getTimestamp, startTime)
|
||||||
|
.orderByDesc(FreqConverterStatus::getTimestamp)
|
||||||
|
.last("limit 1")
|
||||||
|
.one();
|
||||||
|
DynamicTableNameHandler.remove();
|
||||||
|
return one;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<TolerantPointVO> getFeaturesScurvePoints(String converterId) {
|
||||||
|
List<TolerantPointVO> dipPoints = this.getDipPoints(converterId);
|
||||||
|
if (dipPoints == null || dipPoints.isEmpty()) {
|
||||||
|
return new ArrayList<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<Integer, List<TolerantPointVO>> durationPointMap = dipPoints.stream()
|
||||||
|
.collect(Collectors.groupingBy(TolerantPointVO::getDurationMs, TreeMap::new, Collectors.toList()));
|
||||||
|
if (durationPointMap.size() < 2) {
|
||||||
|
return new ArrayList<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
List<TolerantPointVO> result = new ArrayList<>();
|
||||||
|
|
||||||
|
TolerantPointVO firstPoint = new TolerantPointVO();
|
||||||
|
|
||||||
|
List<Integer> keyList = durationPointMap.keySet().stream().collect(Collectors.toList());
|
||||||
|
Integer i1 = keyList.get(0);
|
||||||
|
List<TolerantPointVO> tolerantPointVOS1 = durationPointMap.get(i1);
|
||||||
|
Collections.sort(tolerantPointVOS1, Comparator.comparing(TolerantPointVO::getResidualVoltage));
|
||||||
|
TolerantPointVO tolerantPointVO1 = tolerantPointVOS1.get(0);
|
||||||
|
|
||||||
|
Integer i2 = keyList.get(1);
|
||||||
|
List<TolerantPointVO> tolerantPointVOS2 = durationPointMap.get(i2);
|
||||||
|
Collections.sort(tolerantPointVOS2, Comparator.comparing(TolerantPointVO::getResidualVoltage));
|
||||||
|
TolerantPointVO tolerantPointVO2 = tolerantPointVOS2.get(0);
|
||||||
|
|
||||||
|
firstPoint.setDurationMs((i1 + i2) / 2);
|
||||||
|
firstPoint.setResidualVoltage((tolerantPointVO1.getResidualVoltage() + tolerantPointVO2.getResidualVoltage()) / 2D);
|
||||||
|
firstPoint.setTolerant(2);
|
||||||
|
result.add(firstPoint);
|
||||||
|
|
||||||
|
durationPointMap.entrySet().stream()
|
||||||
|
.forEach(entry -> {
|
||||||
|
List<TolerantPointVO> sameDurationPoints = entry.getValue().stream()
|
||||||
|
.sorted(Comparator.comparing(TolerantPointVO::getResidualVoltage, Comparator.reverseOrder()))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
|
for (int index = 0; index < sameDurationPoints.size() - 1; index++) {
|
||||||
|
TolerantPointVO currentPoint = sameDurationPoints.get(index);
|
||||||
|
TolerantPointVO nextPoint = sameDurationPoints.get(index + 1);
|
||||||
|
if (!Objects.equals(currentPoint.getTolerant(), nextPoint.getTolerant())) {
|
||||||
|
TolerantPointVO featurePoint = new TolerantPointVO();
|
||||||
|
featurePoint.setDurationMs(entry.getKey());
|
||||||
|
featurePoint.setResidualVoltage((currentPoint.getResidualVoltage() + nextPoint.getResidualVoltage()) / 2D);
|
||||||
|
featurePoint.setTolerant(2);
|
||||||
|
result.add(featurePoint);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,136 @@
|
|||||||
|
package com.njcn.gather.freqConverter.service.impl;
|
||||||
|
|
||||||
|
import cn.hutool.core.bean.BeanUtil;
|
||||||
|
import cn.hutool.core.collection.CollectionUtil;
|
||||||
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.njcn.common.pojo.enums.common.DataStateEnum;
|
||||||
|
import com.njcn.gather.freqConverter.mapper.PqFreqConverterConfigMapper;
|
||||||
|
import com.njcn.gather.freqConverter.pojo.param.PqFreqConverterParam;
|
||||||
|
import com.njcn.gather.freqConverter.pojo.po.PqFreqConverterConfig;
|
||||||
|
import com.njcn.gather.freqConverter.service.IPqFreqConverterConfigService;
|
||||||
|
import com.njcn.gather.storage.mapper.TableGenMapper;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author caozehui
|
||||||
|
* @data 2026-04-08
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class PqFreqConverterConfigServiceImpl extends ServiceImpl<PqFreqConverterConfigMapper, PqFreqConverterConfig> implements IPqFreqConverterConfigService {
|
||||||
|
private final TableGenMapper tableGenMapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 表名前缀
|
||||||
|
*/
|
||||||
|
public static final String PQ_FREQ_CONVERTER_STATUS_TB_PREFIX = "pq_freq_converter_status_";
|
||||||
|
public static final String PQ_DIP_DATA_TB_PREFIX = "pq_dip_data_";
|
||||||
|
public static final String PQ_FREQ_CONVERTER_TEST_RES_TB_PREFIX = "pq_freq_converter_test_res_";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Page<PqFreqConverterConfig> listPqFreqConverterConfigs(PqFreqConverterParam.QueryParam queryParam) {
|
||||||
|
QueryWrapper wrapper = new QueryWrapper<>();
|
||||||
|
wrapper.like(StrUtil.isNotBlank(queryParam.getName()), "name", queryParam.getName());
|
||||||
|
wrapper.eq("state", 1);
|
||||||
|
return this.page(new Page<>(queryParam.getPageNum(), queryParam.getPageSize()), wrapper);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Integer getSuffix(String converterId) {
|
||||||
|
PqFreqConverterConfig freqConverterConfig = this.lambdaQuery().eq(PqFreqConverterConfig::getId, converterId).one();
|
||||||
|
return freqConverterConfig.getSuffix();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public boolean addPqFreqConverterConfig(PqFreqConverterParam param) {
|
||||||
|
// 建表
|
||||||
|
PqFreqConverterConfig freqConverterConfig = this.lambdaQuery().orderByDesc(PqFreqConverterConfig::getSuffix)
|
||||||
|
.last("limit 1").one();
|
||||||
|
Integer maxSuffix = 1;
|
||||||
|
if (ObjectUtil.isNotNull(freqConverterConfig)) {
|
||||||
|
maxSuffix = freqConverterConfig.getSuffix() + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
String tableSql = "CREATE TABLE `" + PQ_FREQ_CONVERTER_STATUS_TB_PREFIX + maxSuffix + "`(" +
|
||||||
|
" `id` char(32) NOT NULL COMMENT '主键ID'," +
|
||||||
|
" `slave_address` int(11) DEFAULT NULL COMMENT '从机地址'," +
|
||||||
|
" `status_word1` int(11) DEFAULT NULL COMMENT '状态字1'," +
|
||||||
|
" `status_word1_hex` varchar(20) DEFAULT NULL COMMENT '状态字1十六进制'," +
|
||||||
|
" `timestamp` datetime(3) NOT NULL COMMENT '状态记录时刻(时间戳)'," +
|
||||||
|
" PRIMARY KEY (`id`) USING BTREE" +
|
||||||
|
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='变频器状态表';";
|
||||||
|
tableGenMapper.genTable(tableSql);
|
||||||
|
|
||||||
|
tableSql = "CREATE TABLE `" + PQ_DIP_DATA_TB_PREFIX + maxSuffix + "` (" +
|
||||||
|
" `id` char(32) NOT NULL COMMENT '主键ID'," +
|
||||||
|
" `start_time` datetime(3) NOT NULL COMMENT '起始时间戳'," +
|
||||||
|
" `residual_voltage` decimal(6,2) NOT NULL COMMENT '残余电压(%Ur)'," +
|
||||||
|
" `duration_ms` int(11) NOT NULL COMMENT '持续时间(ms)'," +
|
||||||
|
" PRIMARY KEY (`id`)" +
|
||||||
|
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='电压暂降数据表';";
|
||||||
|
tableGenMapper.genTable(tableSql);
|
||||||
|
|
||||||
|
tableSql = "CREATE TABLE `" + PQ_FREQ_CONVERTER_TEST_RES_TB_PREFIX + maxSuffix + "` (" +
|
||||||
|
" `id` char(32) NOT NULL COMMENT '主键ID'," +
|
||||||
|
" `residual_voltage` decimal(6,2) NOT NULL COMMENT '残余电压(%Ur)'," +
|
||||||
|
" `duration_ms` int(11) NOT NULL COMMENT '持续时间(ms)'," +
|
||||||
|
" `tolerant` tinyInt(1) NOT NULL COMMENT '0为不耐受,1为耐受,2为特征点'," +
|
||||||
|
" `time` datetime(3) DEFAULT NULL COMMENT '时间',"+
|
||||||
|
" PRIMARY KEY (`id`)" +
|
||||||
|
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='变频器耐受实验结果';";
|
||||||
|
tableGenMapper.genTable(tableSql);
|
||||||
|
|
||||||
|
PqFreqConverterConfig pqFreqConverterConfig = BeanUtil.copyProperties(param, PqFreqConverterConfig.class);
|
||||||
|
pqFreqConverterConfig.setSuffix(maxSuffix);
|
||||||
|
pqFreqConverterConfig.setTestStatus(0);
|
||||||
|
pqFreqConverterConfig.setState(DataStateEnum.ENABLE.getCode());
|
||||||
|
return this.save(pqFreqConverterConfig);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public boolean updatePqFreqConverterConfig(PqFreqConverterParam.UpdateParam param) {
|
||||||
|
PqFreqConverterConfig pqFreqConverterConfig = BeanUtil.copyProperties(param, PqFreqConverterConfig.class);
|
||||||
|
return this.updateById(pqFreqConverterConfig);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public boolean deletePqFreqConverterConfig(List<String> ids) {
|
||||||
|
StringBuffer sql = new StringBuffer();
|
||||||
|
sql.append("drop table if exists ");
|
||||||
|
|
||||||
|
List<PqFreqConverterConfig> pqFreqConverterConfigs = this.listByIds(ids);
|
||||||
|
for (PqFreqConverterConfig pqFreqConverterConfig : pqFreqConverterConfigs) {
|
||||||
|
Integer suffix = pqFreqConverterConfig.getSuffix();
|
||||||
|
sql.append(PQ_FREQ_CONVERTER_STATUS_TB_PREFIX + suffix + ",")
|
||||||
|
.append(PQ_DIP_DATA_TB_PREFIX + suffix + ",")
|
||||||
|
.append(PQ_FREQ_CONVERTER_TEST_RES_TB_PREFIX + suffix + ",");
|
||||||
|
}
|
||||||
|
|
||||||
|
sql.deleteCharAt(sql.length() - 1);
|
||||||
|
// 删除表
|
||||||
|
tableGenMapper.genTable(sql.toString());
|
||||||
|
return this.lambdaUpdate()
|
||||||
|
.in(CollectionUtil.isNotEmpty(ids), PqFreqConverterConfig::getId, ids)
|
||||||
|
.set(PqFreqConverterConfig::getState, 0).update();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public boolean updateTestStatus(String converterId, Integer testStatus) {
|
||||||
|
return this.lambdaUpdate()
|
||||||
|
.eq(PqFreqConverterConfig::getId, converterId)
|
||||||
|
.set(PqFreqConverterConfig::getTestStatus, testStatus)
|
||||||
|
.update();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,81 @@
|
|||||||
|
package com.njcn.gather.freqConverter.service.impl;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.njcn.db.mybatisplus.handler.DynamicTableNameHandler;
|
||||||
|
import com.njcn.gather.freqConverter.config.FreqConverterConfig;
|
||||||
|
import com.njcn.gather.freqConverter.mapper.PqFreqConverterTestResMapper;
|
||||||
|
import com.njcn.gather.freqConverter.pojo.po.PqFreqConverterTestRes;
|
||||||
|
import com.njcn.gather.freqConverter.service.IPqFreqConverterTestResService;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author caozehui
|
||||||
|
* @data 2026-04-14
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class PqFreqConverterTestResServiceImpl extends ServiceImpl<PqFreqConverterTestResMapper, PqFreqConverterTestRes> implements IPqFreqConverterTestResService {
|
||||||
|
private final FreqConverterConfig freqConverterConfig;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void clearAllData(Integer suffix) {
|
||||||
|
DynamicTableNameHandler.setTableName(PqFreqConverterConfigServiceImpl.PQ_FREQ_CONVERTER_TEST_RES_TB_PREFIX + suffix);
|
||||||
|
this.remove(null);
|
||||||
|
DynamicTableNameHandler.remove();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean saveTestRes(Integer suffix, List<PqFreqConverterTestRes> testResList) {
|
||||||
|
DynamicTableNameHandler.setTableName(PqFreqConverterConfigServiceImpl.PQ_FREQ_CONVERTER_TEST_RES_TB_PREFIX + suffix);
|
||||||
|
this.saveBatch(testResList);
|
||||||
|
DynamicTableNameHandler.remove();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean updateTestRes(Integer suffix, List<PqFreqConverterTestRes> testResList) {
|
||||||
|
DynamicTableNameHandler.setTableName(PqFreqConverterConfigServiceImpl.PQ_FREQ_CONVERTER_TEST_RES_TB_PREFIX + suffix);
|
||||||
|
this.updateBatchById(testResList);
|
||||||
|
DynamicTableNameHandler.remove();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<PqFreqConverterTestRes> listTestRes(Integer suffix) {
|
||||||
|
DynamicTableNameHandler.setTableName(PqFreqConverterConfigServiceImpl.PQ_FREQ_CONVERTER_TEST_RES_TB_PREFIX + suffix);
|
||||||
|
List<PqFreqConverterTestRes> result = this.list();
|
||||||
|
DynamicTableNameHandler.remove();
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PqFreqConverterTestRes getLastByDuration(Integer suffix, String id, Integer durationMs) {
|
||||||
|
DynamicTableNameHandler.setTableName(PqFreqConverterConfigServiceImpl.PQ_FREQ_CONVERTER_TEST_RES_TB_PREFIX + suffix);
|
||||||
|
LambdaQueryWrapper<PqFreqConverterTestRes> queryWrapper = new LambdaQueryWrapper<>();
|
||||||
|
queryWrapper.between(PqFreqConverterTestRes::getDurationMs, durationMs - freqConverterConfig.getAllowErrorDuration(), durationMs + freqConverterConfig.getAllowErrorDuration())
|
||||||
|
.ne(PqFreqConverterTestRes::getId, id)
|
||||||
|
.orderByAsc(PqFreqConverterTestRes::getResidualVoltage)
|
||||||
|
.last("limit 1");
|
||||||
|
PqFreqConverterTestRes result = this.getOne(queryWrapper);
|
||||||
|
DynamicTableNameHandler.remove();
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PqFreqConverterTestRes getLastByResidualVoltage(Integer suffix, String id, Double residualVoltage) {
|
||||||
|
DynamicTableNameHandler.setTableName(PqFreqConverterConfigServiceImpl.PQ_FREQ_CONVERTER_TEST_RES_TB_PREFIX + suffix);
|
||||||
|
LambdaQueryWrapper<PqFreqConverterTestRes> queryWrapper = new LambdaQueryWrapper<>();
|
||||||
|
queryWrapper.between(PqFreqConverterTestRes::getResidualVoltage, residualVoltage - freqConverterConfig.getAllowErrorResidualVoltage(), residualVoltage + freqConverterConfig.getAllowErrorResidualVoltage())
|
||||||
|
.ne(PqFreqConverterTestRes::getId, id)
|
||||||
|
.orderByDesc(PqFreqConverterTestRes::getDurationMs)
|
||||||
|
.last("limit 1");
|
||||||
|
PqFreqConverterTestRes result = this.getOne(queryWrapper);
|
||||||
|
DynamicTableNameHandler.remove();
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,16 +1,13 @@
|
|||||||
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;
|
||||||
@@ -21,20 +18,12 @@ 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
|
||||||
@@ -49,7 +38,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();
|
||||||
@@ -71,7 +60,7 @@ public class PqIcdPathController extends BaseController {
|
|||||||
@PostMapping("/add")
|
@PostMapping("/add")
|
||||||
@ApiOperation("新增icd")
|
@ApiOperation("新增icd")
|
||||||
@ApiImplicitParam(name = "param", value = "icd新增参数", required = true)
|
@ApiImplicitParam(name = "param", value = "icd新增参数", required = true)
|
||||||
public HttpResult<Boolean> add(@Validated PqIcdPathParam.CreateParam param) {
|
public HttpResult<Boolean> add(PqIcdPathParam param) {
|
||||||
String methodDescribe = getMethodDescribe("add");
|
String methodDescribe = getMethodDescribe("add");
|
||||||
LogUtil.njcnDebug(log, "{},新增数据为:{}", methodDescribe, param);
|
LogUtil.njcnDebug(log, "{},新增数据为:{}", methodDescribe, param);
|
||||||
|
|
||||||
@@ -83,27 +72,11 @@ 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(@Validated PqIcdPathParam.UpdateParam param) {
|
public HttpResult<Boolean> update(PqIcdPathParam.UpdateParam param) {
|
||||||
String methodDescribe = getMethodDescribe("update");
|
String methodDescribe = getMethodDescribe("update");
|
||||||
LogUtil.njcnDebug(log, "{},修改数据为:{}", methodDescribe, param);
|
LogUtil.njcnDebug(log, "{},修改数据为:{}", methodDescribe, param);
|
||||||
|
|
||||||
@@ -115,24 +88,6 @@ 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")
|
||||||
@@ -148,70 +103,5 @@ 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,13 +1,9 @@
|
|||||||
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
|
||||||
@@ -21,21 +17,5 @@ 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,135 +4,10 @@
|
|||||||
|
|
||||||
|
|
||||||
<select id="selectIcdByDevType" resultType="com.njcn.gather.icd.pojo.po.PqIcdPath">
|
<select id="selectIcdByDevType" resultType="com.njcn.gather.icd.pojo.po.PqIcdPath">
|
||||||
select path.*
|
select *
|
||||||
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,45 +1,16 @@
|
|||||||
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 final String code;
|
private String code;
|
||||||
private final String message;
|
private String message;
|
||||||
|
|
||||||
IcdResponseEnum(String code, String message) {
|
IcdResponseEnum(String code, String message) {
|
||||||
this.code = code;
|
this.code = code;
|
||||||
|
|||||||
@@ -17,63 +17,39 @@ import javax.validation.constraints.Pattern;
|
|||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
public class PqIcdPathParam {
|
public class PqIcdPathParam {
|
||||||
@ApiModelProperty(value = "angle", required = true)
|
@ApiModelProperty(value = "名称", 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 = "usePhaseIndex", required = true)
|
@ApiModelProperty(value = "角型接线时是否使用相别的指标来进行检测,0表示否,1表示是", required = true)
|
||||||
private Integer usePhaseIndex;
|
private Integer usePhaseIndex;
|
||||||
|
|
||||||
@ApiModelProperty(value = "jsonStr")
|
@ApiModelProperty(value = "映射文件", required = true)
|
||||||
private String jsonStr;
|
private MultipartFile mappingFile;
|
||||||
|
|
||||||
@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 = "name", required = true)
|
@ApiModelProperty(value = "名称", 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 {
|
||||||
@@ -81,12 +57,5 @@ 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,6 +28,11 @@ public class PqIcdPath extends BaseEntity implements Serializable {
|
|||||||
*/
|
*/
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* icd存储地址
|
||||||
|
*/
|
||||||
|
private String path;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 状态:0-删除 1-正常
|
* 状态:0-删除 1-正常
|
||||||
*/
|
*/
|
||||||
@@ -41,55 +46,19 @@ 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 String referenceIcdName;
|
private FileVO mappingFile;
|
||||||
|
|
||||||
@TableField(exist = false)
|
@Data
|
||||||
private Boolean hasIcdFile;
|
public static class FileVO{
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
private String url;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,38 +0,0 @@
|
|||||||
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,22 +28,13 @@ 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.CreateParam param);
|
boolean addIcd(PqIcdPathParam param);
|
||||||
|
|
||||||
boolean addUpstreamIcd(List<PqIcdPathParam.ExternalCreateParam> param);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 修改Icd
|
* 修改Icd
|
||||||
@@ -61,24 +52,6 @@ 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,42 +1,34 @@
|
|||||||
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.alibaba.fastjson.JSON;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
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.icd.service.support.IcdArchiveBuilder;
|
import com.njcn.gather.pojo.enums.DetectionResponseEnum;
|
||||||
import com.njcn.gather.icd.service.support.IcdPayloadAssembler;
|
import com.njcn.gather.report.pojo.enums.ReportResponseEnum;
|
||||||
import com.njcn.web.factory.PageFactory;
|
import com.njcn.web.factory.PageFactory;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.BeanUtils;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import java.io.BufferedOutputStream;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.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
|
||||||
@@ -46,165 +38,174 @@ import java.util.stream.Collectors;
|
|||||||
@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()
|
return this.lambdaQuery().eq(PqIcdPath::getState, DataStateEnum.ENABLE.getCode()).list();
|
||||||
.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) {
|
||||||
Page<PqIcdPath> page = new Page<>(PageFactory.getPageNum(param), PageFactory.getPageSize(param));
|
LambdaQueryWrapper<PqIcdPath> wrapper = new LambdaQueryWrapper<>();
|
||||||
page.setRecords(this.baseMapper.selectPageList(page, StrUtil.trim(param.getName())));
|
wrapper.eq(PqIcdPath::getState, DataStateEnum.ENABLE.getCode())
|
||||||
|
.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.CreateParam param) {
|
public boolean addIcd(PqIcdPathParam param) {
|
||||||
validateBusinessFields(param, null);
|
param.setName(param.getName().trim());
|
||||||
PqIcdPath pqIcdPath = icdPayloadAssembler.fromCreate(param);
|
this.checkRepeat(param, false);
|
||||||
validateReferenceIcd(pqIcdPath.getType(), pqIcdPath.getReferenceIcdId(), null);
|
PqIcdPath pqIcdPath = new PqIcdPath();
|
||||||
boolean saved = this.save(pqIcdPath);
|
BeanUtils.copyProperties(param, pqIcdPath);
|
||||||
if (saved) {
|
pqIcdPath.setState(DataStateEnum.ENABLE.getCode());
|
||||||
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) {
|
||||||
|
throw new BusinessException(IcdResponseEnum.FILE_SIZE_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
// 如果文件存在,则先删除
|
||||||
|
String mappingFilePath = commInstallPath + "\\DeviceControl\\Config\\" + mappingFilename;
|
||||||
|
System.out.println("mappingFilePath = " + mappingFilePath);
|
||||||
|
Path path = Paths.get(mappingFilePath);
|
||||||
|
File file = path.toFile();
|
||||||
|
if (file.exists()) {
|
||||||
|
file.delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 保存文件
|
||||||
|
byte[] bytes = mappingFile.getBytes();
|
||||||
|
BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(new FileOutputStream(mappingFilePath));
|
||||||
|
bufferedOutputStream.write(bytes);
|
||||||
|
bufferedOutputStream.flush();
|
||||||
|
|
||||||
|
bufferedOutputStream.close();
|
||||||
|
System.out.println("File saved successfully");
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new BusinessException(ReportResponseEnum.FILE_UPLOAD_FAILED);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
System.out.println("mappingFile is null or empty");
|
||||||
|
throw new BusinessException(IcdResponseEnum.FILE_NOT_NULL);
|
||||||
}
|
}
|
||||||
return saved;
|
|
||||||
|
this.executeRestartCmd(commInstallPath);
|
||||||
|
|
||||||
|
return this.save(pqIcdPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
/**
|
||||||
@Transactional
|
* 执行重启通讯服务脚本
|
||||||
public boolean addUpstreamIcd(List<PqIcdPathParam.ExternalCreateParam> param) {
|
*
|
||||||
if (CollUtil.isEmpty(param)) {
|
* @param commInstallPath
|
||||||
return true;
|
*/
|
||||||
|
private void executeRestartCmd(String commInstallPath) {
|
||||||
|
// 以管理员身份运行bat脚本
|
||||||
|
String batFilePath = commInstallPath + "\\重启所有服务.bat";
|
||||||
|
try {
|
||||||
|
Runtime.getRuntime().exec(batFilePath);
|
||||||
|
} catch (IOException e) {
|
||||||
|
log.error("重启通讯服务失败", e);
|
||||||
}
|
}
|
||||||
validateExternalItems(param);
|
}
|
||||||
Set<String> requestStandardIds = collectRequestStandardIds(param);
|
|
||||||
Path directory = resolveIcdTxtDir();
|
private String getCommInstallPath() {
|
||||||
for (PqIcdPathParam.ExternalCreateParam item : param) {
|
String workDir = System.getProperty("user.dir");
|
||||||
validateBusinessFields(item, null);
|
// String workDir = "D:\\program\\CN_Gather";
|
||||||
PqIcdPath current = this.baseMapper.selectById(item.getId());
|
// 获取映射文件存放文件夹
|
||||||
if (current != null && !ObjectUtil.equals(current.getState(), DataStateEnum.ENABLE.getCode())) {
|
String dirPath = workDir + "\\9100";
|
||||||
throw new BusinessException(IcdResponseEnum.EXTERNAL_ICD_DELETED_NOT_ALLOW_OVERWRITE);
|
int index = workDir.indexOf("\\resources\\extraResources\\java");
|
||||||
}
|
if (index != -1) {
|
||||||
PqIcdPath pqIcdPath = icdPayloadAssembler.fromExternalCreate(item, item.getType(), item.getAngle(), item.getUsePhaseIndex());
|
dirPath = workDir.substring(0, workDir.indexOf("\\resources\\extraResources\\java")) + "\\9100";
|
||||||
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 {
|
|
||||||
syncUpdatedIcdTextFile(directory, oldName, pqIcdPath.getName(), pqIcdPath.getJsonStr());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return true;
|
return dirPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional
|
@Transactional
|
||||||
public boolean updateIcd(PqIcdPathParam.UpdateParam param) {
|
public boolean updateIcd(PqIcdPathParam.UpdateParam param) {
|
||||||
PqIcdPath current = getActiveEntity(param.getId());
|
param.setName(param.getName().trim());
|
||||||
String oldName = current.getName();
|
this.checkRepeat(param, true);
|
||||||
validateBusinessFields(param, current.getId());
|
PqIcdPath pqIcdPath = new PqIcdPath();
|
||||||
PqIcdPath pqIcdPath = icdPayloadAssembler.merge(current, param);
|
BeanUtils.copyProperties(param, pqIcdPath);
|
||||||
validateReferenceIcd(pqIcdPath.getType(), pqIcdPath.getReferenceIcdId(), current.getId());
|
|
||||||
boolean updated = this.updateById(pqIcdPath);
|
String commInstallPath = this.getCommInstallPath();
|
||||||
if (updated) {
|
long FILE_SIZE_LIMIT = 1 * 1024 * 1024;
|
||||||
syncUpdatedIcdTextFile(resolveIcdTxtDir(), oldName, pqIcdPath.getName(), pqIcdPath.getJsonStr());
|
MultipartFile mappingFile = param.getMappingFile();
|
||||||
|
if (ObjectUtil.isNotNull(mappingFile) && !mappingFile.isEmpty()) {
|
||||||
|
String mappingFilename = mappingFile.getOriginalFilename();
|
||||||
|
|
||||||
|
if (!mappingFilename.endsWith(".txt")) {
|
||||||
|
throw new BusinessException(IcdResponseEnum.FILE_TYPE_ERROR);
|
||||||
|
}
|
||||||
|
if (mappingFile.getSize() > FILE_SIZE_LIMIT) {
|
||||||
|
throw new BusinessException(IcdResponseEnum.FILE_SIZE_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
// 如果文件存在,则先删除
|
||||||
|
String mappingFilePath = commInstallPath + "\\DeviceControl\\Config\\" + mappingFilename;
|
||||||
|
Path path = Paths.get(mappingFilePath);
|
||||||
|
File file = path.toFile();
|
||||||
|
if (file.exists()) {
|
||||||
|
file.delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 保存文件
|
||||||
|
byte[] bytes = mappingFile.getBytes();
|
||||||
|
BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(new FileOutputStream(mappingFilePath));
|
||||||
|
bufferedOutputStream.write(bytes);
|
||||||
|
bufferedOutputStream.flush();
|
||||||
|
|
||||||
|
bufferedOutputStream.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new BusinessException(ReportResponseEnum.FILE_UPLOAD_FAILED);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return updated;
|
|
||||||
|
this.executeRestartCmd(commInstallPath);
|
||||||
|
|
||||||
|
return this.updateById(pqIcdPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional
|
@Transactional
|
||||||
public boolean deleteIcd(List<String> ids) {
|
public boolean deleteIcd(List<String> ids) {
|
||||||
if (CollUtil.isEmpty(ids)) {
|
List<PqIcdPath> pqIcdPaths = this.listByIds(ids);
|
||||||
return true;
|
String commInstallPath = this.getCommInstallPath();
|
||||||
}
|
pqIcdPaths.forEach(pqIcdPath -> {
|
||||||
List<PqIcdPath> pqIcdPaths = this.baseMapper.selectByIdsWithoutBlob(ids);
|
String mappingFilePath = commInstallPath + "\\DeviceControl\\Config\\" + pqIcdPath.getName() + ".txt";
|
||||||
List<String> standardIds = pqIcdPaths.stream()
|
Path path = Paths.get(mappingFilePath);
|
||||||
.filter(pqIcdPath -> ObjectUtil.equals(pqIcdPath.getType(), TYPE_STANDARD))
|
File file = path.toFile();
|
||||||
.map(PqIcdPath::getId)
|
if (file.exists()) {
|
||||||
.collect(Collectors.toList());
|
file.delete();
|
||||||
if (!standardIds.isEmpty()) {
|
|
||||||
Long count = this.baseMapper.countActiveReferencesToStandards(standardIds);
|
|
||||||
if (ObjectUtil.isNotNull(count) && count > 0) {
|
|
||||||
throw new BusinessException(IcdResponseEnum.STANDARD_ICD_IN_USE);
|
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
|
|
||||||
boolean deleted = this.lambdaUpdate().in(PqIcdPath::getId, ids).set(PqIcdPath::getState, DataStateEnum.DELETED.getCode()).update();
|
return 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
|
||||||
@@ -212,188 +213,18 @@ public class PqIcdPathServiceImpl extends ServiceImpl<PqIcdPathMapper, PqIcdPath
|
|||||||
return this.baseMapper.selectIcdByDevType(devTypeId);
|
return this.baseMapper.selectIcdByDevType(devTypeId);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void validateBusinessFields(PqIcdPathParam param, String currentId) {
|
private void checkRepeat(PqIcdPathParam param, boolean isExcludeSelf) {
|
||||||
if (ObjectUtil.isNull(param.getResult())) {
|
LambdaQueryWrapper<PqIcdPath> wrapper = new LambdaQueryWrapper<>();
|
||||||
throw new BusinessException(IcdResponseEnum.RESULT_NOT_NULL);
|
wrapper.eq(PqIcdPath::getName, param.getName())
|
||||||
}
|
.eq(PqIcdPath::getState, DataStateEnum.ENABLE.getCode());
|
||||||
if (ObjectUtil.equals(param.getResult(), RESULT_NO) && StrUtil.isBlank(param.getMsg())) {
|
if (isExcludeSelf) {
|
||||||
throw new BusinessException(IcdResponseEnum.MSG_NOT_BLANK);
|
if (param instanceof PqIcdPathParam.UpdateParam) {
|
||||||
}
|
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void validateReferenceIcd(Integer type, String referenceIcdId, String currentId) {
|
|
||||||
if (!requiresReferenceIcd(type)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (StrUtil.isNotBlank(currentId) && StrUtil.equals(currentId, referenceIcdId)) {
|
|
||||||
throw new BusinessException(IcdResponseEnum.REFERENCE_ICD_INVALID);
|
|
||||||
}
|
|
||||||
long count = this.lambdaQuery()
|
|
||||||
.eq(PqIcdPath::getId, referenceIcdId)
|
|
||||||
.in(PqIcdPath::getType, TYPE_STANDARD, TYPE_UPSTREAM_STANDARD)
|
|
||||||
.eq(PqIcdPath::getState, DataStateEnum.ENABLE.getCode())
|
|
||||||
.count();
|
|
||||||
if (count <= 0L) {
|
|
||||||
throw new BusinessException(IcdResponseEnum.REFERENCE_ICD_INVALID);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void validateExternalReferenceIcd(Integer type, String referenceIcdId, String currentId, Set<String> requestStandardIds) {
|
|
||||||
if (!requiresReferenceIcd(type)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
String trimmedReferenceId = StrUtil.trim(referenceIcdId);
|
|
||||||
if (StrUtil.isNotBlank(currentId) && StrUtil.equals(currentId, trimmedReferenceId)) {
|
|
||||||
throw new BusinessException(IcdResponseEnum.REFERENCE_ICD_INVALID);
|
|
||||||
}
|
|
||||||
if (StrUtil.isNotBlank(trimmedReferenceId) && requestStandardIds.contains(trimmedReferenceId)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
validateReferenceIcd(type, trimmedReferenceId, currentId);
|
|
||||||
}
|
|
||||||
|
|
||||||
private Set<String> collectRequestStandardIds(List<PqIcdPathParam.ExternalCreateParam> params) {
|
|
||||||
Set<String> ids = new HashSet<>();
|
|
||||||
for (PqIcdPathParam.ExternalCreateParam param : params) {
|
|
||||||
if (isStandardType(param.getType()) && StrUtil.isNotBlank(param.getId())) {
|
|
||||||
ids.add(StrUtil.trim(param.getId()));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ids;
|
int count = this.count(wrapper);
|
||||||
}
|
if (count > 0) {
|
||||||
|
throw new BusinessException(DetectionResponseEnum.ICD_PATH_NAME_REPEAT);
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,62 +0,0 @@
|
|||||||
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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,90 +0,0 @@
|
|||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,66 +0,0 @@
|
|||||||
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.UNCHECKED.getValue());
|
this.baseMapper.updateDeviceCheckState(devId, CheckStateEnum.CHECKING.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,14 +142,13 @@ 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());
|
||||||
boolean allUnchecked = devSubList.stream().allMatch(pqDevSub -> CheckStateEnum.UNCHECKED.getValue().equals(pqDevSub.getCheckState()));
|
List<PqDevSub> checkingDevSubList = devSubList.stream().filter(pqDevSub -> pqDevSub.getCheckState() == CheckStateEnum.CHECKING.getValue()).collect(Collectors.toList());
|
||||||
boolean allArchived = devSubList.stream().allMatch(pqDevSub -> pqDevSub.getCheckState() != null && pqDevSub.getCheckState() >= CheckStateEnum.DOCUMENTED.getValue());
|
if (checkedDevSubList.size() == devSubList.size() && devSubList.size() > 0) {
|
||||||
if (allArchived && CollUtil.isNotEmpty(devSubList)) {
|
|
||||||
this.baseMapper.updatePlanCheckState(plan.getId(), CheckStateEnum.CHECKED.getValue());
|
this.baseMapper.updatePlanCheckState(plan.getId(), CheckStateEnum.CHECKED.getValue());
|
||||||
} else if (allUnchecked) {
|
} else if (checkedDevSubList.size() > 0 || checkingDevSubList.size() > 0) {
|
||||||
this.baseMapper.updatePlanCheckState(plan.getId(), CheckStateEnum.UNCHECKED.getValue());
|
|
||||||
} else {
|
|
||||||
this.baseMapper.updatePlanCheckState(plan.getId(), CheckStateEnum.CHECKING.getValue());
|
this.baseMapper.updatePlanCheckState(plan.getId(), CheckStateEnum.CHECKING.getValue());
|
||||||
|
} else {
|
||||||
|
this.baseMapper.updatePlanCheckState(plan.getId(), CheckStateEnum.UNCHECKED.getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
List<PqDevSub> accordDevSubList = checkedDevSubList.stream().filter(pqDevSub -> pqDevSub.getCheckResult() == CheckResultEnum.ACCORD.getValue()).collect(Collectors.toList());
|
List<PqDevSub> accordDevSubList = checkedDevSubList.stream().filter(pqDevSub -> pqDevSub.getCheckResult() == CheckResultEnum.ACCORD.getValue()).collect(Collectors.toList());
|
||||||
@@ -373,6 +372,10 @@ 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,7 +22,6 @@ 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;
|
||||||
@@ -199,17 +198,6 @@ 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,4 +29,13 @@ public interface AdPlanMapper extends MPJBaseMapper<AdPlan> {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
PqReport getPqReportById(String id);
|
PqReport getPqReportById(String id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取所有报告模板名称
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
List<String> listAllReportTemplateName();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,15 +0,0 @@
|
|||||||
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,6 +2,7 @@
|
|||||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
<mapper namespace="com.njcn.gather.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
|
||||||
@@ -16,4 +17,10 @@
|
|||||||
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>
|
||||||
|
|
||||||
|
|||||||
@@ -1,24 +0,0 @@
|
|||||||
<?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,17 +130,4 @@ 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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,63 +0,0 @@
|
|||||||
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;
|
|
||||||
}
|
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
package com.njcn.gather.plan.pojo.vo;
|
|
||||||
|
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 检测计划单个检测大项柱状图统计结果。
|
|
||||||
*/
|
|
||||||
@Data
|
|
||||||
public class PlanStatisticsItemVO {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 检测大项ID。
|
|
||||||
*/
|
|
||||||
private String itemId;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 检测大项名称。
|
|
||||||
*/
|
|
||||||
private String itemName;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 不合格次数。
|
|
||||||
*/
|
|
||||||
private Integer unqualifiedCount;
|
|
||||||
}
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
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;
|
|
||||||
}
|
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user