Quellcode durchsuchen

三级校审ai助手

Alex vor 1 Tag
Ursprung
Commit
a7b14e24cc

+ 3 - 1
jeeplus-modules/jeeplus-assess/src/main/java/com/jeeplus/assess/program/configuration/projectList/service/ProjectListService.java

@@ -471,6 +471,8 @@ public class ProjectListService {
             Map<String,String> map = new HashMap<>();
             String fileList = JSON.toJSONString((programAuditDto.getWorkAttachmentDtoList()));
             String attachmentId = programAudit.getId();
+            // 校审文件:同一张 work_attachment 表,attachmentId 为校审记录ID,flag 为 program;
+            // 项目登记附件则是 attachmentId=项目ID、flag=workcontract,两者互不影响。
             String attachmentFlag = "program";
             map.put("fileList",fileList);
             map.put("attachmentId",attachmentId);
@@ -776,7 +778,7 @@ public class ProjectListService {
 
     public ProgramAuditDto findByIdAudit(String id){
         ProgramAuditDto byIdAudit = programAuditMapper.findByIdAudit(id);
-        // 查询附件信息
+        // 查询本级校审文件:attachment_id 为当前校审记录ID,与项目登记附件分开
         List<WorkAttachmentInfo> files = workContractInfoMapper.findDtos(id);
         if (CollectionUtils.isNotEmpty(files)) {
             for (WorkAttachmentInfo i : files) {

+ 2 - 2
jeeplus-modules/jeeplus-assess/src/main/java/com/jeeplus/assess/programAuditAi/service/ProgramAuditAiService.java

@@ -112,7 +112,7 @@ public class ProgramAuditAiService {
 
         List<AiAttachmentDTO> attachments = req.getWorkAttachmentDtoList();
         if (attachments == null || attachments.isEmpty()) {
-            throw new ProgramAuditAiException("NO_ATTACHMENT", "该项目登记时未上传附件,请先上传附件再生成校审意见。");
+            throw new ProgramAuditAiException("NO_ATTACHMENT", "请先上传项目附件或校审文件后再生成校审意见。");
         }
         if (attachments.size() > maxFiles()) {
             throw new ProgramAuditAiException("TOO_MANY_FILES", "本次附件超过 " + maxFiles() + " 个,请保留核心资料后再生成");
@@ -167,7 +167,7 @@ public class ProgramAuditAiService {
                 throw new ProgramAuditAiException("NO_SUPPORTED_ATTACHMENT",
                         "所有附件均为不支持的文件类型(" + typeText(unsupportedTypes) + "),无法生成校审意见。");
             }
-            throw new ProgramAuditAiException("NO_ATTACHMENT", "该项目登记时未上传附件,请先上传附件再生成校审意见。");
+            throw new ProgramAuditAiException("NO_ATTACHMENT", "请先上传项目附件或校审文件后再生成校审意见。");
         }
         String unsupportedWarning = unsupportedWarning(unsupportedTypes);
 

+ 69 - 0
jeeplus-modules/jeeplus-assess/src/main/java/com/jeeplus/assess/programAuditAi/service/ProgramAuditAiStartupRecovery.java

@@ -0,0 +1,69 @@
+package com.jeeplus.assess.programAuditAi.service;
+
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.jeeplus.assess.programAuditAi.domain.ProgramAuditAiGeneration;
+import com.jeeplus.assess.programAuditAi.mapper.ProgramAuditAiGenerationMapper;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.boot.ApplicationArguments;
+import org.springframework.boot.ApplicationRunner;
+import org.springframework.stereotype.Component;
+
+import javax.annotation.Resource;
+import java.util.Date;
+import java.util.List;
+
+/**
+ * 校审 AI 生成任务启动恢复。
+ *
+ */
+@Slf4j
+@Component
+public class ProgramAuditAiStartupRecovery implements ApplicationRunner {
+
+    private static final String STATUS_RUNNING = "running";
+    private static final String STATUS_FAILED = "failed";
+    private static final String ERROR_CODE_INTERRUPTED = "AI_INTERRUPTED";
+    private static final String ERROR_MESSAGE_INTERRUPTED = "服务重启导致生成中断,请重新生成";
+
+    @Resource
+    private ProgramAuditAiGenerationMapper generationMapper;
+
+    @Override
+    public void run(ApplicationArguments args) {
+        recoverInterruptedTasks();
+    }
+
+    /**
+     * 将启动前遗留的 running 任务全部置为 failed。
+     */
+    public int recoverInterruptedTasks() {
+        QueryWrapper<ProgramAuditAiGeneration> query = new QueryWrapper<>();
+        query.eq("status", STATUS_RUNNING)
+            .isNull("finished_at");
+        List<ProgramAuditAiGeneration> runningTasks = generationMapper.selectList(query);
+        if (runningTasks == null || runningTasks.isEmpty()) {
+            return 0;
+        }
+
+        Date finishedAt = new Date();
+        int recovered = 0;
+        for (ProgramAuditAiGeneration task : runningTasks) {
+            task.setStatus(STATUS_FAILED);
+            task.setDetailStatus(STATUS_FAILED);
+            task.setReportStatus(STATUS_FAILED);
+            task.setRemarksStatus(STATUS_FAILED);
+            task.setWorkStatus(STATUS_FAILED);
+            task.setErrorCode(ERROR_CODE_INTERRUPTED);
+            task.setErrorMessage(ERROR_MESSAGE_INTERRUPTED);
+            task.setFinishedAt(finishedAt);
+            if (task.getStartedAt() != null) {
+                task.setDurationMs(Math.max(0L, finishedAt.getTime() - task.getStartedAt().getTime()));
+            }
+            generationMapper.updateById(task);
+            recovered++;
+        }
+
+        log.warn("校审AI启动恢复:已将 {} 条遗留 running 任务置为 failed", recovered);
+        return recovered;
+    }
+}