|
|
@@ -101,7 +101,9 @@ public class GrowthPlanService {
|
|
|
|
|
|
public GrowthPlan createPlan(GrowthPlan plan) {
|
|
|
if (plan.getStatus() == null) {
|
|
|
- plan.setStatus("active");
|
|
|
+ // SC-P-44/45「未确认不可激活」:新建方案默认处于待确认态(generated),
|
|
|
+ // 家长确认/审核通过后才流转为 reviewed → active(能力键 plan.confirm.submit)
|
|
|
+ plan.setStatus("generated");
|
|
|
}
|
|
|
plan.setReviewCount(plan.getReviewCount() != null ? plan.getReviewCount() : 0);
|
|
|
plan.setCreatedAt(new Date());
|
|
|
@@ -184,11 +186,72 @@ public class GrowthPlanService {
|
|
|
return user != null ? user.getNickname() : null;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 复盘成长方案(SC-P-44 审核,能力键 plan.confirm.submit)。
|
|
|
+ *
|
|
|
+ * <p>状态机:generated→reviewed(审核通过后进入待激活态,参照 PlanReviewController
|
|
|
+ * TaskPlanInstance 的 generated→reviewed→active 状态机);越状态守卫——
|
|
|
+ * 非 generated 状态(如 active)调审核抛 {@link IllegalStateException}「方案状态异常」。</p>
|
|
|
+ */
|
|
|
public boolean reviewPlan(Long id) {
|
|
|
GrowthPlan plan = growthPlanMapper.selectById(id);
|
|
|
if (plan == null) return false;
|
|
|
+ if (!"generated".equals(plan.getStatus())) {
|
|
|
+ throw new IllegalStateException("方案状态异常");
|
|
|
+ }
|
|
|
+ plan.setStatus("reviewed");
|
|
|
plan.setReviewCount(plan.getReviewCount() != null ? plan.getReviewCount() + 1 : 1);
|
|
|
plan.setUpdatedAt(new Date());
|
|
|
return growthPlanMapper.updateById(plan) > 0;
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 确认成长方案(SC-P-44 家长确认/送审,能力键 plan.confirm.submit)。
|
|
|
+ *
|
|
|
+ * <p>状态机:generated→reviewed(家长确认/送审后进入待激活态);确认幂等——
|
|
|
+ * 已 reviewed/active 的方案再次确认视为已确认(返回 true,无副作用);
|
|
|
+ * 其他非法状态(draft/completed/expired)抛 {@link IllegalStateException}「方案状态异常」。</p>
|
|
|
+ *
|
|
|
+ * @param id 成长方案ID
|
|
|
+ * @return 方案不存在返回 false;已确认/确认成功返回 true
|
|
|
+ */
|
|
|
+ public boolean confirmPlan(Long id) {
|
|
|
+ GrowthPlan plan = growthPlanMapper.selectById(id);
|
|
|
+ if (plan == null) return false;
|
|
|
+ String status = plan.getStatus();
|
|
|
+ if ("reviewed".equals(status) || "active".equals(status)) {
|
|
|
+ return true; // 确认幂等:已确认/已激活
|
|
|
+ }
|
|
|
+ if (!"generated".equals(status)) {
|
|
|
+ throw new IllegalStateException("方案状态异常");
|
|
|
+ }
|
|
|
+ plan.setStatus("reviewed");
|
|
|
+ plan.setUpdatedAt(new Date());
|
|
|
+ return growthPlanMapper.updateById(plan) > 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 发布成长方案(SC-P-45 方案直接发布,能力键 plan.confirm.submit)。
|
|
|
+ *
|
|
|
+ * <p>配置允许直发时:generated/reviewed→active(直接生效);发布幂等——
|
|
|
+ * 已 active 的方案再次发布返回 true,无副作用;非法状态
|
|
|
+ * (draft/completed/expired)抛 {@link IllegalStateException}「方案状态异常」。</p>
|
|
|
+ *
|
|
|
+ * @param id 成长方案ID
|
|
|
+ * @return 方案不存在返回 false;已发布/发布成功返回 true
|
|
|
+ */
|
|
|
+ public boolean submitPlan(Long id) {
|
|
|
+ GrowthPlan plan = growthPlanMapper.selectById(id);
|
|
|
+ if (plan == null) return false;
|
|
|
+ String status = plan.getStatus();
|
|
|
+ if ("active".equals(status)) {
|
|
|
+ return true; // 发布幂等:已激活
|
|
|
+ }
|
|
|
+ if (!"generated".equals(status) && !"reviewed".equals(status)) {
|
|
|
+ throw new IllegalStateException("方案状态异常");
|
|
|
+ }
|
|
|
+ plan.setStatus("active");
|
|
|
+ plan.setUpdatedAt(new Date());
|
|
|
+ return growthPlanMapper.updateById(plan) > 0;
|
|
|
+ }
|
|
|
}
|