diff --git a/detection/src/main/java/com/njcn/gather/detection/controller/PreDetectionController.java b/detection/src/main/java/com/njcn/gather/detection/controller/PreDetectionController.java index 49f0433f..984f52e1 100644 --- a/detection/src/main/java/com/njcn/gather/detection/controller/PreDetectionController.java +++ b/detection/src/main/java/com/njcn/gather/detection/controller/PreDetectionController.java @@ -106,12 +106,24 @@ public class PreDetectionController extends BaseController { @ApiImplicitParam(name = "param", value = "查询参数", required = true) public HttpResult startTestSimulate(@RequestBody @Validated SimulateDetectionParam param) { String methodDescribe = getMethodDescribe("startTestSimulate"); - HttpResult busy = requireHolderSelf(); + // ContrastDetectionParam 无 userPageId 字段,用 loginName 作为会话标识(与 WS 会话 key 一致) + HttpResult busy = tryAcquireLock(param.getUserPageId()); if (busy != null) { return busy; } - preDetectionService.sendScript(param); - return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe); + // 同步阶段抛异常时回滚锁,理由同 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_CONTRAST_SYNC_FAILED"); + } + } } /** diff --git a/detection/src/main/java/com/njcn/gather/detection/handler/SocketSourceResponseService.java b/detection/src/main/java/com/njcn/gather/detection/handler/SocketSourceResponseService.java index 5ad50968..14560d7b 100644 --- a/detection/src/main/java/com/njcn/gather/detection/handler/SocketSourceResponseService.java +++ b/detection/src/main/java/com/njcn/gather/detection/handler/SocketSourceResponseService.java @@ -121,6 +121,15 @@ public class SocketSourceResponseService { sendErrorAndQuit(param, socketDataMsg, errorCode.getMessage()); } + private void sendSimulateInitFailure(PreDetectionParam param, String errorMessage) { + SocketDataMsg socketDataMsg = new SocketDataMsg(); + socketDataMsg.setRequestId(SourceOperateCodeEnum.YJC_YTXJY.getValue()); + socketDataMsg.setOperateCode(SourceOperateCodeEnum.INIT_GATHER.getValue()); + socketDataMsg.setCode(SourceResponseCodeEnum.UNKNOWN_ERROR.getCode()); + socketDataMsg.setData(errorMessage); + sendWebSocketMessage(param.getUserPageId(), socketDataMsg); + } + /** * 当前检测会话中的设备列表 @@ -214,12 +223,12 @@ public class SocketSourceResponseService { break; default: - // TODO: 记录未知操作码到日志,并向前端发送友好提示 + sendSimulateInitFailure(param, "未知操作码"); break; } } else { - // TODO: 向前端发送错误提示 log.error("程控源响应消息操作码解析失败,原始消息: {}, 解析结果: {}", msg, enumByCode); + sendSimulateInitFailure(param, "未知操作码"); } } @@ -272,10 +281,11 @@ public class SocketSourceResponseService { sendWebSocketMessage(param.getUserPageId(), socketDataMsg); break; default: - // 未识别的响应码:发送通用错误消息 - WebServiceManager.sendUnknownErrorMessage(param.getUserPageId()); + sendSimulateInitFailure(param, "未知状态码"); break; } + } else { + sendSimulateInitFailure(param, "未知状态码"); } } diff --git a/detection/src/main/java/com/njcn/gather/detection/service/impl/PreDetectionServiceImpl.java b/detection/src/main/java/com/njcn/gather/detection/service/impl/PreDetectionServiceImpl.java index a48a0681..62455757 100644 --- a/detection/src/main/java/com/njcn/gather/detection/service/impl/PreDetectionServiceImpl.java +++ b/detection/src/main/java/com/njcn/gather/detection/service/impl/PreDetectionServiceImpl.java @@ -223,6 +223,7 @@ public class PreDetectionServiceImpl implements PreDetectionService { private void sendYtxSocketSimulate(PreDetectionParam param) { SourceInitialize sourceParam = pqSourceService.getSourceInitializeParam(param.getSourceId()); param.setSourceId(sourceParam.getSourceId()); + param.setSourceName(sourceParam.getSourceId()); String loginName = RequestUtil.getLoginNameByToken(); WebServiceManager.addPreDetectionParam(loginName, param); if (ObjectUtil.isNotNull(sourceParam)) { diff --git a/detection/src/main/java/com/njcn/gather/detection/util/socket/cilent/NettySourceClientHandler.java b/detection/src/main/java/com/njcn/gather/detection/util/socket/cilent/NettySourceClientHandler.java index 66479aea..27601d50 100644 --- a/detection/src/main/java/com/njcn/gather/detection/util/socket/cilent/NettySourceClientHandler.java +++ b/detection/src/main/java/com/njcn/gather/detection/util/socket/cilent/NettySourceClientHandler.java @@ -90,7 +90,7 @@ public class NettySourceClientHandler extends SimpleChannelInboundHandler