diff --git a/src/main/java/com/labelsys/backend/dto/request/CreateAnnotationTaskRequest.java b/src/main/java/com/labelsys/backend/dto/request/CreateAnnotationTaskRequest.java index 8acb8af..12d3e5a 100644 --- a/src/main/java/com/labelsys/backend/dto/request/CreateAnnotationTaskRequest.java +++ b/src/main/java/com/labelsys/backend/dto/request/CreateAnnotationTaskRequest.java @@ -1,6 +1,5 @@ package com.labelsys.backend.dto.request; -import com.labelsys.backend.enums.IndustryType; import com.labelsys.backend.enums.TaskType; import io.swagger.v3.oas.annotations.media.Schema; import jakarta.validation.constraints.NotBlank; @@ -12,7 +11,6 @@ import java.util.List; @Schema(description = "创建标注任务请求") public record CreateAnnotationTaskRequest( @Schema(description = "任务名称", example = "运输文档问答抽取任务") @NotBlank(message = "任务名称不能为空") String taskName, - @Schema(description = "行业类型", defaultValue = "TRANSPORT", example = "TRANSPORT") @NotNull(message = "行业类型不能为空") IndustryType industryType, @Schema(description = "任务类型", defaultValue = "EXTRACT_QA", example = "EXTRACT_QA") @NotNull(message = "任务类型不能为空") TaskType taskType, @Schema(description = "资源ID列表", example = "[191000000000000101,191000000000000102]") @NotEmpty(message = "资源列表不能为空") List resourceIds) { } \ No newline at end of file diff --git a/src/main/java/com/labelsys/backend/dto/request/UpdateAnnotationTaskRequest.java b/src/main/java/com/labelsys/backend/dto/request/UpdateAnnotationTaskRequest.java index 6c5b02a..0b5d8cf 100644 --- a/src/main/java/com/labelsys/backend/dto/request/UpdateAnnotationTaskRequest.java +++ b/src/main/java/com/labelsys/backend/dto/request/UpdateAnnotationTaskRequest.java @@ -2,14 +2,12 @@ package com.labelsys.backend.dto.request; import java.util.List; -import com.labelsys.backend.enums.IndustryType; import com.labelsys.backend.enums.TaskType; import io.swagger.v3.oas.annotations.media.Schema; @Schema(description = "更新标注任务请求") public record UpdateAnnotationTaskRequest( - @Schema(description = "行业类型", example = "TRANSPORT") IndustryType industryType, @Schema(description = "任务类型", example = "EXTRACT_QA") TaskType taskType, @Schema(description = "资源ID列表", example = "[191000000000000101,191000000000000102]") List resourceIds) { } \ No newline at end of file diff --git a/src/main/java/com/labelsys/backend/dto/response/AnnotationTaskResponse.java b/src/main/java/com/labelsys/backend/dto/response/AnnotationTaskResponse.java index 452c34c..b91aa0d 100644 --- a/src/main/java/com/labelsys/backend/dto/response/AnnotationTaskResponse.java +++ b/src/main/java/com/labelsys/backend/dto/response/AnnotationTaskResponse.java @@ -1,6 +1,5 @@ package com.labelsys.backend.dto.response; -import com.labelsys.backend.enums.IndustryType; import com.labelsys.backend.enums.TaskType; import io.swagger.v3.oas.annotations.media.Schema; @@ -11,7 +10,6 @@ import java.util.List; public record AnnotationTaskResponse( @Schema(description = "任务ID", example = "191000000000000301") Long id, @Schema(description = "任务名称", example = "运输文档问答抽取任务") String taskName, - @Schema(description = "行业类型", example = "transport") IndustryType industryType, @Schema(description = "任务类型", example = "EXTRACT_QA") TaskType taskType, @Schema(description = "任务状态", example = "PENDING") String taskStatus, @Schema(description = "资源ID列表", example = "[191000000000000101,191000000000000102]") List resourceIds, diff --git a/src/main/java/com/labelsys/backend/entity/AnnotationTask.java b/src/main/java/com/labelsys/backend/entity/AnnotationTask.java index cb343f7..a342a95 100644 --- a/src/main/java/com/labelsys/backend/entity/AnnotationTask.java +++ b/src/main/java/com/labelsys/backend/entity/AnnotationTask.java @@ -4,7 +4,6 @@ import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableLogic; import com.baomidou.mybatisplus.annotation.TableName; -import com.labelsys.backend.enums.IndustryType; import com.labelsys.backend.enums.TaskType; import com.labelsys.backend.enums.UserRole; import lombok.AllArgsConstructor; @@ -26,7 +25,6 @@ public class AnnotationTask { private Long creatorId; private UserRole creatorRole; private String taskName; - private IndustryType industryType; private TaskType taskType; private String taskStatus; @TableLogic(value = "false", delval = "true") diff --git a/src/main/java/com/labelsys/backend/mapper/AnnotationResultMapper.java b/src/main/java/com/labelsys/backend/mapper/AnnotationResultMapper.java index 448ddd4..20b04c9 100644 --- a/src/main/java/com/labelsys/backend/mapper/AnnotationResultMapper.java +++ b/src/main/java/com/labelsys/backend/mapper/AnnotationResultMapper.java @@ -12,4 +12,8 @@ public interface AnnotationResultMapper extends BaseMapper { int markArchived(@Param("id") Long id, @Param("companyId") Long companyId, @Param("reviewerId") Long reviewerId); -} \ No newline at end of file + + int markReviewedAndArchived(@Param("id") Long id, + @Param("companyId") Long companyId, + @Param("reviewerId") Long reviewerId); +} diff --git a/src/main/java/com/labelsys/backend/service/AnnotationResultArchiveService.java b/src/main/java/com/labelsys/backend/service/AnnotationResultArchiveService.java index f3ea0bd..671ee9f 100644 --- a/src/main/java/com/labelsys/backend/service/AnnotationResultArchiveService.java +++ b/src/main/java/com/labelsys/backend/service/AnnotationResultArchiveService.java @@ -211,8 +211,13 @@ public class AnnotationResultArchiveService { String archiveReason) { LocalDateTime archivedAt = LocalDateTime.now(); - // 从对象存储读取 qa.json 内容 - // String qaContentJson = loadQaContentJson(result); + int updated = annotationResultMapper.markArchived( + result.getId(), + result.getCompanyId(), + reviewerId); + if (updated == 0) { + return null; + } AnnotationResultHistory history = AnnotationResultHistory.builder() .id(IdGenerator.nextId()) @@ -229,18 +234,11 @@ public class AnnotationResultArchiveService { .archiveReason(archiveReason) .archivedBy(reviewerId) .archivedAt(archivedAt) + .createdAt(archivedAt) .reviewerId(null) .reviewerName("auto") .build(); annotationResultHistoryMapper.insert(history); - - int updated = annotationResultMapper.markArchived( - result.getId(), - result.getCompanyId(), - reviewerId); - if (updated == 0) { - return null; - } return new MergeReviewResultResponse(result.getId(), history.getId(), archiveReason, archivedAt); } @@ -368,4 +366,4 @@ public class AnnotationResultArchiveService { } } -} \ No newline at end of file +} diff --git a/src/main/java/com/labelsys/backend/service/AnnotationResultService.java b/src/main/java/com/labelsys/backend/service/AnnotationResultService.java index c125a6d..66690e4 100644 --- a/src/main/java/com/labelsys/backend/service/AnnotationResultService.java +++ b/src/main/java/com/labelsys/backend/service/AnnotationResultService.java @@ -296,8 +296,8 @@ public class AnnotationResultService { ); saveQaContent(result, updatedQaContent); - // 更新数据库记录(使用 markArchived 保证幂等性,防止并发重复归档) - int updated = annotationResultMapper.markArchived( + // 用单条 SQL 原子完成人工审核归档,避免状态部分更新后再次被自动归档扫描到。 + int updated = annotationResultMapper.markReviewedAndArchived( result.getId(), currentUser.companyId(), currentUser.userId()); @@ -307,9 +307,9 @@ public class AnnotationResultService { throw new BusinessException(ResultCode.CONFLICT, "记录已被归档"); } - // 更新 requires_manual_review 字段 result.setRequiresManualReview(false); - annotationResultMapper.updateById(result); + result.setIsDeleted(true); + result.setReviewerId(currentUser.userId()); // 归档到历史表(人工审核后归档) archiveToHistory(result, currentUser, "审核通过后归档", false); @@ -453,7 +453,7 @@ public class AnnotationResultService { } else { // 人工审核后归档:使用审核人信息 historyBuilder - .reviewerId(result.getReviewerId()) + .reviewerId(currentUser.userId()) .reviewerName(currentUser.realName()); } @@ -523,4 +523,4 @@ public class AnnotationResultService { private record Metadata(String createdAt) { } } -} \ No newline at end of file +} diff --git a/src/main/java/com/labelsys/backend/service/AnnotationTaskService.java b/src/main/java/com/labelsys/backend/service/AnnotationTaskService.java index 0f4d8d0..5c9d121 100644 --- a/src/main/java/com/labelsys/backend/service/AnnotationTaskService.java +++ b/src/main/java/com/labelsys/backend/service/AnnotationTaskService.java @@ -13,7 +13,6 @@ import com.labelsys.backend.dto.response.AnnotationTaskResponse; import com.labelsys.backend.entity.AnnotationTask; import com.labelsys.backend.entity.AnnotationTaskResource; import com.labelsys.backend.entity.SourceResource; -import com.labelsys.backend.enums.IndustryType; import com.labelsys.backend.enums.TaskStatus; import com.labelsys.backend.enums.TaskType; import com.labelsys.backend.mapper.AnnotationTaskMapper; @@ -53,7 +52,6 @@ public class AnnotationTaskService { .creatorId(currentUser.userId()) .creatorRole(currentUser.role()) .taskName(request.taskName()) - .industryType(defaultIndustryType(request.industryType())) .taskType(defaultTaskType(request.taskType())) .taskStatus(TaskStatus.PENDING.name()) .isDeleted(false) @@ -97,10 +95,6 @@ public class AnnotationTaskService { resources = loadAndValidateResources(currentUser, request.resourceIds()); } - if (request.industryType() != null) { - task.setIndustryType(request.industryType()); - } - if (request.taskType() != null) { task.setTaskType(request.taskType()); } @@ -238,7 +232,6 @@ public class AnnotationTaskService { return new AnnotationTaskResponse( task.getId(), task.getTaskName(), - task.getIndustryType(), task.getTaskType(), task.getTaskStatus(), resourceIds, @@ -264,10 +257,6 @@ public class AnnotationTaskService { } } - private IndustryType defaultIndustryType(IndustryType industryType) { - return industryType != null ? industryType : IndustryType.TRANSPORT; - } - private TaskType defaultTaskType(TaskType taskType) { return taskType != null ? taskType : TaskType.EXTRACT_QA; } diff --git a/src/main/resources/mapper/AnnotationResultMapper.xml b/src/main/resources/mapper/AnnotationResultMapper.xml index ec18f1a..b67a4a1 100644 --- a/src/main/resources/mapper/AnnotationResultMapper.xml +++ b/src/main/resources/mapper/AnnotationResultMapper.xml @@ -40,4 +40,14 @@ and company_id = #{companyId} and is_deleted = false - \ No newline at end of file + + + update annotation_result + set is_deleted = true, + requires_manual_review = false, + reviewer_id = #{reviewerId} + where id = #{id} + and company_id = #{companyId} + and is_deleted = false + + diff --git a/src/main/resources/mapper/AnnotationTaskMapper.xml b/src/main/resources/mapper/AnnotationTaskMapper.xml index a49e896..bf6614b 100644 --- a/src/main/resources/mapper/AnnotationTaskMapper.xml +++ b/src/main/resources/mapper/AnnotationTaskMapper.xml @@ -7,7 +7,6 @@ - @@ -19,7 +18,7 @@ - id, company_id, creator_id, creator_role, task_name, industry_type, task_type, + id, company_id, creator_id, creator_role, task_name, task_type, task_status, is_deleted, started_at, finished_at, error_message, created_at, updated_at diff --git a/src/main/resources/sql/data.sql b/src/main/resources/sql/data.sql index eac4ca6..19f3b89 100644 --- a/src/main/resources/sql/data.sql +++ b/src/main/resources/sql/data.sql @@ -66,12 +66,12 @@ INSERT INTO source_resource ( ON CONFLICT DO NOTHING; INSERT INTO annotation_task ( - id, company_id, creator_id, creator_role, task_name, industry_type, task_type, + id, company_id, creator_id, creator_role, task_name, task_type, task_status, is_deleted, started_at, finished_at, error_message ) VALUES - (701, 2, 4, 'EMPLOYEE', '多资源问答抽取任务', 'ELECTRICITY', 'EXTRACT_QA', + (701, 2, 4, 'EMPLOYEE', '多资源问答抽取任务', 'EXTRACT_QA', 'PENDING', FALSE, NULL, NULL, NULL), - (702, 2, 4, 'EMPLOYEE', '图片问答抽取任务', 'TRANSPORT', 'EXTRACT_QA', + (702, 2, 4, 'EMPLOYEE', '图片问答抽取任务', 'EXTRACT_QA', 'COMPLETED', FALSE, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP, NULL) ON CONFLICT DO NOTHING; diff --git a/src/main/resources/sql/schema.sql b/src/main/resources/sql/schema.sql index e33e7b2..d97638d 100644 --- a/src/main/resources/sql/schema.sql +++ b/src/main/resources/sql/schema.sql @@ -199,7 +199,6 @@ CREATE TABLE IF NOT EXISTS annotation_task creator_id BIGINT NOT NULL, creator_role VARCHAR(32) NOT NULL DEFAULT 'EMPLOYEE', task_name VARCHAR(255) NOT NULL, - industry_type VARCHAR(32) NOT NULL DEFAULT 'GENERAL', task_type VARCHAR(32) NOT NULL DEFAULT 'EXTRACT_QA', task_status VARCHAR(32) NOT NULL DEFAULT 'PENDING', is_deleted BOOLEAN NOT NULL DEFAULT FALSE, @@ -218,7 +217,6 @@ COMMENT ON COLUMN annotation_task.company_id IS '所属公司ID。'; COMMENT ON COLUMN annotation_task.creator_id IS '任务创建人用户ID。'; COMMENT ON COLUMN annotation_task.creator_role IS '任务创建人数据权限角色,默认 EMPLOYEE。'; COMMENT ON COLUMN annotation_task.task_name IS '任务名称。'; -COMMENT ON COLUMN annotation_task.industry_type IS '行业类型简写,默认 transport,可选值按业务扩展。'; COMMENT ON COLUMN annotation_task.task_type IS '任务类型,默认 EXTRACT_QA。'; COMMENT ON COLUMN annotation_task.task_status IS '任务状态,默认 PENDING,可选 RUNNING、COMPLETED、FAILED。'; COMMENT ON COLUMN annotation_task.is_deleted IS '任务软删除标记,默认 FALSE。';