| | |
| | | validateAttachment(request.getAttachmentId(), request.getSourceSha256()); |
| | | validateRows(request); |
| | | |
| | | Long tenantId = principal.tenantId(); |
| | | Long ownerUserId = principal.userId(); |
| | | String digest = requestDigest(moduleId, request); |
| | | |
| | | // 1. 幂等命中:命令 ID 优先,其次幂等键 |
| | | AgentImportCommandDO existing = commandMapper.selectByCommandId( |
| | | tenantId, ownerUserId, moduleId, request.getCommandId()); |
| | | ownerUserId, moduleId, request.getCommandId()); |
| | | if (existing != null) { |
| | | requireSameDigest(existing, digest); |
| | | return toReceipt(existing); |
| | | } |
| | | existing = commandMapper.selectByIdempotencyKey( |
| | | tenantId, ownerUserId, moduleId, request.getIdempotencyKey()); |
| | | ownerUserId, moduleId, request.getIdempotencyKey()); |
| | | if (existing != null) { |
| | | requireSameDigest(existing, digest); |
| | | return toReceipt(existing); |
| | |
| | | .idempotencyKey(request.getIdempotencyKey()) |
| | | .requestDigest(digest) |
| | | .moduleId(moduleId) |
| | | .tenantId(tenantId) |
| | | .ownerUserId(ownerUserId) |
| | | .sessionId(request.getSessionId()) |
| | | .attachmentId(request.getAttachmentId()) |
| | |
| | | commandMapper.insert(command); |
| | | } catch (DuplicateKeyException ex) { |
| | | AgentImportCommandDO raced = commandMapper.selectByCommandId( |
| | | tenantId, ownerUserId, moduleId, request.getCommandId()); |
| | | ownerUserId, moduleId, request.getCommandId()); |
| | | if (raced == null) { |
| | | raced = commandMapper.selectByIdempotencyKey( |
| | | tenantId, ownerUserId, moduleId, request.getIdempotencyKey()); |
| | | ownerUserId, moduleId, request.getIdempotencyKey()); |
| | | } |
| | | if (raced == null) { |
| | | throw ex; |
| | |
| | | public AgentImportReceiptRespVO getCommand(String moduleId, String commandId, AgentPrincipal principal) { |
| | | requireAdapter(moduleId); |
| | | AgentImportCommandDO command = commandMapper.selectByCommandId( |
| | | principal.tenantId(), principal.userId(), moduleId, commandId); |
| | | principal.userId(), moduleId, commandId); |
| | | if (command == null) { |
| | | throw new AgentBridgeException(HttpStatus.NOT_FOUND, "COMMAND_NOT_FOUND", "导入命令不存在"); |
| | | } |
| | |
| | | } |
| | | |
| | | private void requirePermission(AgentImportModuleAdapter adapter) { |
| | | if (!securityFrameworkService.hasPermission(adapter.permission())) { |
| | | for (String permission : adapter.permissions()) { |
| | | if (!securityFrameworkService.hasPermission(permission)) { |
| | | throw new AgentBridgeException(HttpStatus.FORBIDDEN, "FORBIDDEN", |
| | | "当前用户缺少该模块的导入权限(" + adapter.permission() + ")"); |
| | | "当前用户缺少该模块的导入权限(" + permission + ")"); |
| | | } |
| | | } |
| | | } |
| | | |