| | |
| | | throw new AgentBridgeException(HttpStatus.SERVICE_UNAVAILABLE, "WRITE_DISABLED", |
| | | "智能体写入开关未打开,提交已拒绝"); |
| | | } |
| | | if (Boolean.TRUE.equals(reqVO.getSyncMes()) && !policy.isAllowMesSync()) { |
| | | throw new AgentBridgeException(HttpStatus.UNPROCESSABLE_ENTITY, "MES_SYNC_DISABLED", |
| | | "服务未开放同步 MES,请关闭 syncMes 后重试"); |
| | | } |
| | | String requestDigest = buildRequestDigest(reqVO); |
| | | Long tenantId = principal.tenantId(); |
| | | Long ownerUserId = principal.userId(); |
| | | |
| | | // 1. 幂等命中:命令 ID 优先,其次幂等键 |
| | | MdmAgentImportCommandDO existing = commandMapper.selectByCommandId(tenantId, ownerUserId, reqVO.getCommandId()); |
| | | MdmAgentImportCommandDO existing = commandMapper.selectByCommandId(ownerUserId, reqVO.getCommandId()); |
| | | if (existing != null) { |
| | | if (!existing.getRequestDigest().equals(requestDigest)) { |
| | | throw new AgentBridgeException(HttpStatus.CONFLICT, "COMMAND_ID_CONFLICT", |
| | |
| | | } |
| | | return toReceipt(existing); |
| | | } |
| | | existing = commandMapper.selectByIdempotencyKey(tenantId, ownerUserId, reqVO.getIdempotencyKey()); |
| | | existing = commandMapper.selectByIdempotencyKey(ownerUserId, reqVO.getIdempotencyKey()); |
| | | if (existing != null) { |
| | | if (!existing.getRequestDigest().equals(requestDigest)) { |
| | | throw new AgentBridgeException(HttpStatus.CONFLICT, "IDEMPOTENCY_CONFLICT", |
| | |
| | | .commandId(reqVO.getCommandId()) |
| | | .idempotencyKey(reqVO.getIdempotencyKey()) |
| | | .requestDigest(requestDigest) |
| | | .tenantId(tenantId) |
| | | .ownerUserId(ownerUserId) |
| | | .sessionId(reqVO.getSessionId()) |
| | | .attachmentId(reqVO.getAttachmentId()) |
| | |
| | | try { |
| | | commandMapper.insert(command); |
| | | } catch (DuplicateKeyException ex) { |
| | | MdmAgentImportCommandDO raced = commandMapper.selectByCommandId(tenantId, ownerUserId, reqVO.getCommandId()); |
| | | MdmAgentImportCommandDO raced = commandMapper.selectByCommandId(ownerUserId, reqVO.getCommandId()); |
| | | if (raced == null) { |
| | | raced = commandMapper.selectByIdempotencyKey(tenantId, ownerUserId, reqVO.getIdempotencyKey()); |
| | | raced = commandMapper.selectByIdempotencyKey(ownerUserId, reqVO.getIdempotencyKey()); |
| | | } |
| | | if (raced == null) { |
| | | throw ex; |
| | |
| | | return; |
| | | } |
| | | MdmItemSaveReqVO saveReqVO = resolution.saveReqVO(); |
| | | saveReqVO.setSyncMes(false); // 本阶段固定不同步 MES |
| | | saveReqVO.setSyncMes(Boolean.TRUE.equals(reqVO.getSyncMes())); |
| | | Long itemId = itemService.createItem(saveReqVO); |
| | | commandRowMapper.insert(baseRow(command.getCommandId(), row) |
| | | .action("CREATE").status("SUCCESS").targetItemId(itemId) |
| | |
| | | |
| | | public MdmAgentImportReceiptRespVO getCommand(String commandId, AgentPrincipal principal) { |
| | | MdmAgentImportCommandDO command = commandMapper.selectByCommandId( |
| | | principal.tenantId(), principal.userId(), commandId); |
| | | principal.userId(), commandId); |
| | | if (command == null) { |
| | | throw new AgentBridgeException(HttpStatus.NOT_FOUND, "COMMAND_NOT_FOUND", "导入命令不存在"); |
| | | } |