|
|
@@ -48,13 +48,20 @@ public class HealthPlanServiceImpl implements HealthPlanService {
|
|
|
@Override
|
|
|
public Long savePlan(HealthPlan plan) {
|
|
|
plan.setCreatedAt(new Date());
|
|
|
+ // 新方案默认为 pending_review 状态,待规划师审核后发布
|
|
|
+ if (plan.getStatus() == null || plan.getStatus().isEmpty()) {
|
|
|
+ plan.setStatus("pending_review");
|
|
|
+ }
|
|
|
healthPlanMapper.insert(plan);
|
|
|
- try {
|
|
|
- generateDailyTasksFromPlan(plan);
|
|
|
- log.info("方案{}自动生成任务完成,familyId={}, memberIds={}",
|
|
|
- plan.getId(), plan.getFamilyId(), plan.getMemberIds());
|
|
|
- } catch (Exception e) {
|
|
|
- log.warn("方案{}自动生成任务失败,不影响方案保存: {}", plan.getId(), e.getMessage());
|
|
|
+ // 仅在已发布状态才自动生成任务
|
|
|
+ if ("published".equals(plan.getStatus())) {
|
|
|
+ try {
|
|
|
+ generateDailyTasksFromPlan(plan);
|
|
|
+ log.info("方案{}发布时生成任务完成,familyId={}, memberIds={}",
|
|
|
+ plan.getId(), plan.getFamilyId(), plan.getMemberIds());
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.warn("方案{}发布时生成任务失败,不影响方案保存: {}", plan.getId(), e.getMessage());
|
|
|
+ }
|
|
|
}
|
|
|
return plan.getId();
|
|
|
}
|
|
|
@@ -77,7 +84,8 @@ public class HealthPlanServiceImpl implements HealthPlanService {
|
|
|
public Long confirmPlan(Long planId) {
|
|
|
HealthPlan plan = healthPlanMapper.selectById(planId);
|
|
|
if (plan == null) throw new RuntimeException("方案不存在");
|
|
|
- plan.setStatus("confirmed");
|
|
|
+ plan.setStatus("published");
|
|
|
+ plan.setUpdatedAt(new Date());
|
|
|
healthPlanMapper.updateById(plan);
|
|
|
try {
|
|
|
generateDailyTasksFromPlan(plan);
|
|
|
@@ -264,4 +272,60 @@ public class HealthPlanServiceImpl implements HealthPlanService {
|
|
|
}
|
|
|
return tasks;
|
|
|
}
|
|
|
-}
|
|
|
+@Override
|
|
|
+ public List<HealthPlan> listPendingReviewPlans(Long familyId) {
|
|
|
+ com.baomidou.mybatisplus.core.conditions.query.QueryWrapper<HealthPlan> w = new com.baomidou.mybatisplus.core.conditions.query.QueryWrapper<>();
|
|
|
+ w.eq("family_id", familyId);
|
|
|
+ w.in("status", "draft", "pending_review");
|
|
|
+ w.orderByDesc("created_at");
|
|
|
+ return healthPlanMapper.selectList(w);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public HealthPlan updatePlanContent(Long planId, String planContent, String planJson) {
|
|
|
+ HealthPlan plan = healthPlanMapper.selectById(planId);
|
|
|
+ if (plan == null) throw new RuntimeException("方案不存在");
|
|
|
+ if (!"pending_review".equals(plan.getStatus()) && !"draft".equals(plan.getStatus())) {
|
|
|
+ throw new RuntimeException("方案状态不允许编辑");
|
|
|
+ }
|
|
|
+ if (planContent != null) plan.setPlanContent(planContent);
|
|
|
+ if (planJson != null) plan.setPlanJson(planJson);
|
|
|
+ plan.setUpdatedAt(new Date());
|
|
|
+ healthPlanMapper.updateById(plan);
|
|
|
+ return plan;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public HealthPlan approveAndPublish(Long planId, Long reviewedBy, String comment) {
|
|
|
+ HealthPlan plan = healthPlanMapper.selectById(planId);
|
|
|
+ if (plan == null) throw new RuntimeException("方案不存在");
|
|
|
+ if (!"pending_review".equals(plan.getStatus()) && !"draft".equals(plan.getStatus())) {
|
|
|
+ throw new RuntimeException("方案状态不允许审核");
|
|
|
+ }
|
|
|
+ plan.setStatus("published");
|
|
|
+ plan.setReviewedBy(reviewedBy);
|
|
|
+ plan.setReviewedAt(new Date());
|
|
|
+ plan.setReviewComment(comment);
|
|
|
+ plan.setUpdatedAt(new Date());
|
|
|
+ healthPlanMapper.updateById(plan);
|
|
|
+ try {
|
|
|
+ generateDailyTasksFromPlan(plan);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.warn("方案{}发布时生成任务失败: {}", planId, e.getMessage());
|
|
|
+ }
|
|
|
+ return plan;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public HealthPlan rejectPlan(Long planId, Long reviewedBy, String comment) {
|
|
|
+ HealthPlan plan = healthPlanMapper.selectById(planId);
|
|
|
+ if (plan == null) throw new RuntimeException("方案不存在");
|
|
|
+ plan.setStatus("rejected");
|
|
|
+ plan.setReviewedBy(reviewedBy);
|
|
|
+ plan.setReviewedAt(new Date());
|
|
|
+ plan.setReviewComment(comment);
|
|
|
+ plan.setUpdatedAt(new Date());
|
|
|
+ healthPlanMapper.updateById(plan);
|
|
|
+ return plan;
|
|
|
+ }
|
|
|
+}
|