Browse Source

优化修复

jiapu 2 months ago
parent
commit
427ce4b53a

+ 62 - 0
cfc-backend/src/main/java/com/etotem/cfc/controller/admin/AdminHealthPlanController.java

@@ -0,0 +1,62 @@
+package com.etotem.cfc.controller.admin;
+
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.etotem.cfc.common.Result;
+import com.etotem.cfc.entity.HealthPlan;
+import com.etotem.cfc.entity.Task;
+import com.etotem.cfc.service.HealthPlanService;
+import com.etotem.cfc.util.ParamUtils;
+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/admin/health-plan")
+public class AdminHealthPlanController {
+
+    @Resource
+    private HealthPlanService healthPlanService;
+
+    @Operation(summary = "健康方案分页列表(按成员展示)")
+    @PostMapping("/list")
+    public Result<Page<HealthPlan>> list(@RequestBody Map<String, Object> params,
+                                         @RequestAttribute("role") String role) {
+        if (!"admin".equals(role) && !"teacher".equals(role) && !"butler".equals(role)
+                && !"nutritionist".equals(role) && !"operator".equals(role)) {
+            return Result.error("无权限");
+        }
+        int page = params.get("page") != null ? ((Number) params.get("page")).intValue() : 1;
+        int size = params.get("size") != null ? ((Number) params.get("size")).intValue() : 20;
+        Long familyId = ParamUtils.getLong(params.get("familyId"));
+        String status = params.get("status") != null ? params.get("status").toString() : null;
+        String keyword = params.get("keyword") != null ? params.get("keyword").toString() : null;
+        Page<HealthPlan> result = healthPlanService.adminListPlans(familyId, status, keyword, page, size);
+        return Result.success(result);
+    }
+
+    @Operation(summary = "健康方案详情(含分解任务)")
+    @PostMapping("/detail")
+    public Result<HealthPlan> detail(@RequestBody Map<String, Object> params,
+                                     @RequestAttribute("role") String role) {
+        if (!"admin".equals(role) && !"teacher".equals(role) && !"butler".equals(role)
+                && !"nutritionist".equals(role) && !"operator".equals(role)) {
+            return Result.error("无权限");
+        }
+        Long planId = ParamUtils.getLong(params.get("planId"));
+        if (planId == null) {
+            return Result.error("planId不能为空");
+        }
+        HealthPlan plan = healthPlanService.getPlanDetail(planId);
+        if (plan == null) {
+            return Result.error("方案不存在");
+        }
+        List<Task> tasks = healthPlanService.getPlanTasks(planId);
+        plan.setTasks(tasks);
+        return Result.success(plan);
+    }
+}

+ 57 - 0
cfc-backend/src/main/java/com/etotem/cfc/service/TaskPlanInstanceService.java

@@ -0,0 +1,57 @@
+package com.etotem.cfc.service;
+
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.etotem.cfc.entity.TaskPlanInstance;
+import com.etotem.cfc.mapper.TaskPlanInstanceMapper;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+
+/**
+ * 任务方案实例服务
+ */
+@Service
+public class TaskPlanInstanceService {
+
+    @Autowired
+    private TaskPlanInstanceMapper mapper;
+
+    /**
+     * 根据家庭 ID 获取方案列表(包含所有孩子)
+     */
+    public List<TaskPlanInstance> getListByFamily(Long familyId) {
+        LambdaQueryWrapper<TaskPlanInstance> wrapper = new LambdaQueryWrapper<>();
+        wrapper.eq(TaskPlanInstance::getFamilyId, familyId)
+               .orderByDesc(TaskPlanInstance::getCreatedAt);
+        return mapper.selectList(wrapper);
+    }
+
+    /**
+     * 根据家庭 ID 和孩子 ID 获取方案列表
+     */
+    public List<TaskPlanInstance> getListByChildAndFamily(Long childId, Long familyId) {
+        LambdaQueryWrapper<TaskPlanInstance> wrapper = new LambdaQueryWrapper<>();
+        wrapper.eq(TaskPlanInstance::getChildId, childId)
+               .eq(TaskPlanInstance::getFamilyId, familyId)
+               .orderByDesc(TaskPlanInstance::getCreatedAt);
+        return mapper.selectList(wrapper);
+    }
+
+    /**
+     * 根据孩子 ID 获取方案列表
+     */
+    public List<TaskPlanInstance> getListByChild(Long childId) {
+        LambdaQueryWrapper<TaskPlanInstance> wrapper = new LambdaQueryWrapper<>();
+        wrapper.eq(TaskPlanInstance::getChildId, childId)
+               .orderByDesc(TaskPlanInstance::getCreatedAt);
+        return mapper.selectList(wrapper);
+    }
+
+    /**
+     * 根据方案 ID 获取单个方案
+     */
+    public TaskPlanInstance getById(Long id) {
+        return mapper.selectById(id);
+    }
+}