云
7 小时以前 95ae0c83d2aa58d86b4039e3f7f16ee93afb8f00
yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/service/agent/imports/SystemAgentGenericImportService.java
@@ -93,19 +93,18 @@
        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);
@@ -129,7 +128,6 @@
                .idempotencyKey(request.getIdempotencyKey())
                .requestDigest(digest)
                .moduleId(moduleId)
                .tenantId(tenantId)
                .ownerUserId(ownerUserId)
                .sessionId(request.getSessionId())
                .attachmentId(request.getAttachmentId())
@@ -145,10 +143,10 @@
            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;
@@ -226,7 +224,7 @@
    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", "导入命令不存在");
        }
@@ -297,9 +295,11 @@
    }
    private void requirePermission(AgentImportModuleAdapter adapter) {
        if (!securityFrameworkService.hasPermission(adapter.permission())) {
            throw new AgentBridgeException(HttpStatus.FORBIDDEN, "FORBIDDEN",
                    "当前用户缺少该模块的导入权限(" + adapter.permission() + ")");
        for (String permission : adapter.permissions()) {
            if (!securityFrameworkService.hasPermission(permission)) {
                throw new AgentBridgeException(HttpStatus.FORBIDDEN, "FORBIDDEN",
                        "当前用户缺少该模块的导入权限(" + permission + ")");
            }
        }
    }