Просмотр исходного кода

feat(backend): 新增报告批量归档接口 POST /report/archive-batch

管理端报告列表支持多选软删除,循环归档并返回实际归档数,校验 reportIds 非空

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
liaoxg 1 месяц назад
Родитель
Сommit
c0a559ba48

+ 17 - 0
cfc-backend/src/main/java/com/etotem/cfc/controller/HealthReportController.java

@@ -1239,6 +1239,23 @@ public class HealthReportController {
         return Result.success("报告已归档");
     }
 
+    /**
+     * 批量归档报告(软删除)— 管理端选中删除
+     */
+    @Operation(summary = "批量归档健康报告(软删除)")
+    @PostMapping("/report/archive-batch")
+    public Result<String> archiveReportsBatch(
+            @RequestBody Map<String, Object> params,
+            @RequestAttribute(value = "role", required = false) String role) {
+        @SuppressWarnings("unchecked")
+        List<Long> reportIds = (List<Long>) params.get("reportIds");
+        if (reportIds == null || reportIds.isEmpty()) {
+            return Result.error("reportIds不能为空");
+        }
+        int archived = healthReportService.archiveReportsBatch(reportIds);
+        return Result.success("已归档 " + archived + " 份报告");
+    }
+
     @Operation(summary = "获取家庭成员食材推荐(含完整营养数据)")
     @PostMapping("/foods/by-family")
     public Result<Map<String, Object>> getFoodsByFamily(@RequestAttribute(value = "familyId", required = false) Long familyId) {

+ 22 - 0
cfc-backend/src/main/java/com/etotem/cfc/service/HealthReportService.java

@@ -285,6 +285,28 @@ public class HealthReportService {
         }
     }
 
+    /**
+     * 批量归档报告(软删除)— 逐个归档,返回实际归档成功的数量
+     */
+    @Transactional
+    public int archiveReportsBatch(List<Long> reportIds) {
+        if (reportIds == null || reportIds.isEmpty()) {
+            return 0;
+        }
+        int archived = 0;
+        for (Long reportId : reportIds) {
+            if (reportId == null) continue;
+            HealthReport report = healthReportMapper.selectById(reportId);
+            if (report != null && !"archived".equals(report.getStatus())) {
+                report.setStatus("archived");
+                report.setUpdatedAt(new Date());
+                healthReportMapper.updateById(report);
+                archived++;
+            }
+        }
+        return archived;
+    }
+
     // ======================== 菌群+疾病风险专数据 ========================
 
     /**