| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187 |
- package com.etotem.cfc.controller;
- import com.etotem.cfc.common.Result;
- import com.etotem.cfc.entity.HealthIndicator;
- import com.etotem.cfc.entity.HealthReport;
- import com.etotem.cfc.service.HealthReportService;
- import io.swagger.v3.oas.annotations.Operation;
- import io.swagger.v3.oas.annotations.tags.Tag;
- import org.springframework.web.bind.annotation.*;
- import javax.annotation.Resource;
- import java.util.List;
- import java.util.Map;
- /**
- * 健康检测报告接口 — 体检报告/菌群检测报告的录入与查询
- */
- @Tag(name = "健康检测报告", description = "健康报告上传、查询、指标明细")
- @RestController
- @RequestMapping("/api/health")
- public class HealthReportController {
- @Resource
- private HealthReportService healthReportService;
- /**
- * 创建健康报告(含指标明细)
- */
- @Operation(summary = "创建健康报告")
- @PostMapping("/report/create")
- public Result<HealthReport> createReport(
- @RequestBody Map<String, Object> params,
- @RequestAttribute("userId") Long userId) {
- Long childId = params.get("childId") != null
- ? Long.valueOf(params.get("childId").toString()) : null;
- if (childId == null) {
- return Result.error("childId不能为空");
- }
- String reportType = (String) params.get("reportType");
- if (reportType == null) {
- return Result.error("reportType不能为空: physical_exam / gut_flora");
- }
- // 构建报告主体
- HealthReport report = new HealthReport();
- report.setUserId(childId);
- report.setReportType(reportType);
- report.setOverallScore(params.get("overallScore") != null
- ? Integer.valueOf(params.get("overallScore").toString()) : null);
- report.setGutHealthScore(params.get("gutHealthScore") != null
- ? Integer.valueOf(params.get("gutHealthScore").toString()) : null);
- report.setChronicDiseaseScore(params.get("chronicDiseaseScore") != null
- ? Integer.valueOf(params.get("chronicDiseaseScore").toString()) : null);
- report.setNutritionScore(params.get("nutritionScore") != null
- ? Integer.valueOf(params.get("nutritionScore").toString()) : null);
- report.setGutAge((String) params.get("gutAge"));
- report.setGutType((String) params.get("gutType"));
- report.setFileUrl((String) params.get("fileUrl"));
- report.setRemark((String) params.get("remark"));
- // 报告日期(默认当天)
- report.setReportDate(new java.util.Date());
- // 指标明细(可选)
- @SuppressWarnings("unchecked")
- List<Map<String, Object>> indicatorList =
- (List<Map<String, Object>>) params.get("indicators");
- List<HealthIndicator> indicators = null;
- if (indicatorList != null) {
- indicators = new java.util.ArrayList<>();
- for (int i = 0; i < indicatorList.size(); i++) {
- Map<String, Object> item = indicatorList.get(i);
- HealthIndicator ind = new HealthIndicator();
- ind.setCategory((String) item.get("category"));
- ind.setIndicatorName((String) item.get("indicatorName"));
- ind.setIndicatorValue(item.get("indicatorValue") != null
- ? item.get("indicatorValue").toString() : null);
- ind.setUnit((String) item.get("unit"));
- ind.setRefRange((String) item.get("refRange"));
- ind.setStatus((String) item.get("status"));
- ind.setSortOrder(i);
- indicators.add(ind);
- }
- }
- HealthReport created = healthReportService.createReport(report, indicators);
- return Result.success(created);
- }
- /**
- * 获取孩子的最新健康报告
- */
- @Operation(summary = "获取最新健康报告")
- @PostMapping("/report/latest")
- public Result<HealthReport> getLatestReport(
- @RequestBody Map<String, Object> params) {
- Long childId = params.get("childId") != null
- ? Long.valueOf(params.get("childId").toString()) : null;
- if (childId == null) {
- return Result.error("childId不能为空");
- }
- HealthReport report = healthReportService.getLatestReport(childId);
- return Result.success(report);
- }
- /**
- * 获取孩子的所有健康报告列表
- */
- @Operation(summary = "获取健康报告列表")
- @PostMapping("/report/list")
- public Result<List<HealthReport>> listReports(
- @RequestBody Map<String, Object> params) {
- Long childId = params.get("childId") != null
- ? Long.valueOf(params.get("childId").toString()) : null;
- if (childId == null) {
- return Result.error("childId不能为空");
- }
- List<HealthReport> reports = healthReportService.getUserReports(childId);
- return Result.success(reports);
- }
- /**
- * 获取某份报告的所有指标明细
- */
- @Operation(summary = "获取报告指标明细")
- @PostMapping("/indicator/list")
- public Result<List<HealthIndicator>> listIndicators(
- @RequestBody Map<String, Object> params) {
- Long reportId = params.get("reportId") != null
- ? Long.valueOf(params.get("reportId").toString()) : null;
- if (reportId == null) {
- return Result.error("reportId不能为空");
- }
- List<HealthIndicator> indicators = healthReportService.getReportIndicators(reportId);
- return Result.success(indicators);
- }
- /**
- * 获取孩子身体维度数据详情(健康指标解读)
- */
- @Operation(summary = "获取身体维度数据详情")
- @PostMapping("/body/detail")
- public Result<List<HealthIndicator>> getBodyDetail(
- @RequestBody Map<String, Object> params) {
- Long childId = params.get("childId") != null
- ? Long.valueOf(params.get("childId").toString()) : null;
- if (childId == null) {
- return Result.error("childId不能为空");
- }
- List<HealthIndicator> detail = healthReportService.getBodyDetail(childId);
- return Result.success(detail);
- }
- /**
- * 获取报告完整详情(含指标明细 + 菌群数据 + 疾病风险评估)
- */
- @Operation(summary = "获取报告完整详情")
- @PostMapping("/report/detail")
- public Result<Map<String, Object>> getReportDetail(
- @RequestBody Map<String, Object> params) {
- Long reportId = params.get("reportId") != null
- ? Long.valueOf(params.get("reportId").toString()) : null;
- if (reportId == null) {
- return Result.error("reportId不能为空");
- }
- Map<String, Object> detail = healthReportService.getReportDetail(reportId);
- return Result.success(detail);
- }
- /**
- * 归档报告
- */
- @Operation(summary = "归档健康报告")
- @PostMapping("/report/archive")
- public Result<String> archiveReport(
- @RequestBody Map<String, Object> params) {
- Long reportId = params.get("reportId") != null
- ? Long.valueOf(params.get("reportId").toString()) : null;
- if (reportId == null) {
- return Result.error("reportId不能为空");
- }
- healthReportService.archiveReport(reportId);
- return Result.success("报告已归档");
- }
- }
|