|
|
@@ -1,17 +1,29 @@
|
|
|
package com.etotem.cfc.controller;
|
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.etotem.cfc.common.Result;
|
|
|
+import com.etotem.cfc.dto.ApplyPackageDTO;
|
|
|
+import com.etotem.cfc.entity.ProblemDomain;
|
|
|
+import com.etotem.cfc.entity.TaskPlanInstance;
|
|
|
import com.etotem.cfc.entity.TaskTemplateItem;
|
|
|
import com.etotem.cfc.entity.TaskTemplatePackage;
|
|
|
+import com.etotem.cfc.entity.UserIntent;
|
|
|
+import com.etotem.cfc.mapper.ProblemDomainMapper;
|
|
|
+import com.etotem.cfc.mapper.TaskPlanInstanceMapper;
|
|
|
+import com.etotem.cfc.mapper.UserIntentMapper;
|
|
|
+import com.etotem.cfc.service.MembershipService;
|
|
|
+import com.etotem.cfc.service.TaskPlanService;
|
|
|
import com.etotem.cfc.service.TaskTemplatePackageService;
|
|
|
import io.swagger.v3.oas.annotations.Operation;
|
|
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
|
|
import javax.annotation.Resource;
|
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestAttribute;
|
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
+import java.util.Date;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
@@ -20,7 +32,7 @@ import com.etotem.cfc.util.ParamUtils;
|
|
|
/**
|
|
|
* 问题域套餐 — 改版v1(套餐详情:介绍/使用方式/包含检测/任务模板/奖励说明)
|
|
|
*/
|
|
|
-@Tag(name = "问题域套餐", description = "套餐详情查询")
|
|
|
+@Tag(name = "问题域套餐", description = "套餐详情查询与方案确认")
|
|
|
@RestController
|
|
|
@RequestMapping("/api/problem-package")
|
|
|
public class ProblemPackageController {
|
|
|
@@ -28,6 +40,21 @@ public class ProblemPackageController {
|
|
|
@Resource
|
|
|
private TaskTemplatePackageService taskTemplatePackageService;
|
|
|
|
|
|
+ @Resource
|
|
|
+ private TaskPlanService taskPlanService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private TaskPlanInstanceMapper planInstanceMapper;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private UserIntentMapper userIntentMapper;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private ProblemDomainMapper problemDomainMapper;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private MembershipService membershipService;
|
|
|
+
|
|
|
@Operation(summary = "套餐详情(名称/介绍/周期/包含任务模板/奖励说明)")
|
|
|
@PostMapping("/detail")
|
|
|
public Result<Map<String, Object>> detail(@RequestBody Map<String, Object> params) {
|
|
|
@@ -55,4 +82,82 @@ public class ProblemPackageController {
|
|
|
data.put("items", items);
|
|
|
return Result.success(data);
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 方案确认(B17/B20 补全):用户确认方案后生成可执行任务并推进旅程 stage=6。
|
|
|
+ * <p>
|
|
|
+ * 幂等:同一家庭同一套餐已存在激活中的方案实例则复用,不重复生成任务。
|
|
|
+ * 参数 packageId 可省略:缺省取用户意图(问题域)绑定的第一个套餐。
|
|
|
+ */
|
|
|
+ @Operation(summary = "方案确认:生成方案任务(memberOnly=1)并推进旅程 stage=6")
|
|
|
+ @PostMapping("/confirm")
|
|
|
+ public Result<Map<String, Object>> confirm(@RequestAttribute("userId") Long userId,
|
|
|
+ @RequestBody Map<String, Object> params) {
|
|
|
+ Long familyId = membershipService.getUserFamilyId(userId);
|
|
|
+ if (familyId == null) {
|
|
|
+ return Result.noFamily("请先创建或加入家庭");
|
|
|
+ }
|
|
|
+ Long packageId = ParamUtils.getLong(params.get("packageId"));
|
|
|
+
|
|
|
+ // 缺省套餐:从用户意图(问题域)取绑定的第一个套餐
|
|
|
+ if (packageId == null) {
|
|
|
+ UserIntent intent = findIntent(userId);
|
|
|
+ if (intent == null || intent.getProblemDomainCode() == null
|
|
|
+ || intent.getProblemDomainCode().isEmpty()) {
|
|
|
+ return Result.error("未找到问题域,请先选择问题域");
|
|
|
+ }
|
|
|
+ ProblemDomain domain = problemDomainMapper.selectOne(
|
|
|
+ new LambdaQueryWrapper<ProblemDomain>()
|
|
|
+ .eq(ProblemDomain::getCode, intent.getProblemDomainCode())
|
|
|
+ .last("LIMIT 1"));
|
|
|
+ if (domain == null || domain.getTaskTemplatePackageIds() == null
|
|
|
+ || domain.getTaskTemplatePackageIds().trim().isEmpty()) {
|
|
|
+ return Result.error("该问题域未绑定套餐,请先在管理端配置");
|
|
|
+ }
|
|
|
+ packageId = Long.parseLong(domain.getTaskTemplatePackageIds().trim().split(",")[0]);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 幂等:同一家庭同一套餐已有激活中的方案实例则复用
|
|
|
+ TaskPlanInstance plan = planInstanceMapper.selectOne(
|
|
|
+ new LambdaQueryWrapper<TaskPlanInstance>()
|
|
|
+ .eq(TaskPlanInstance::getFamilyId, familyId)
|
|
|
+ .eq(TaskPlanInstance::getPackageId, packageId)
|
|
|
+ .eq(TaskPlanInstance::getStatus, "active")
|
|
|
+ .last("LIMIT 1"));
|
|
|
+ Long planId;
|
|
|
+ if (plan == null) {
|
|
|
+ ApplyPackageDTO dto = new ApplyPackageDTO();
|
|
|
+ dto.setPackageId(packageId);
|
|
|
+ TaskPlanInstance created = taskPlanService.applyPackage(dto, familyId);
|
|
|
+ planId = created.getId();
|
|
|
+ } else {
|
|
|
+ planId = plan.getId();
|
|
|
+ }
|
|
|
+
|
|
|
+ // 生成方案任务(memberOnly=1,幂等)
|
|
|
+ int taskCount = taskPlanService.generatePlanTasks(planId, familyId, userId);
|
|
|
+
|
|
|
+ // 推进旅程 stage=6(方案已确认,任务已生成)
|
|
|
+ UserIntent intent = findIntent(userId);
|
|
|
+ if (intent != null && (intent.getJourneyStage() == null || intent.getJourneyStage() < 6)) {
|
|
|
+ Date now = new Date();
|
|
|
+ intent.setJourneyStage(6);
|
|
|
+ intent.setStageUpdatedAt(now);
|
|
|
+ intent.setUpdatedAt(now);
|
|
|
+ userIntentMapper.updateById(intent);
|
|
|
+ }
|
|
|
+
|
|
|
+ Map<String, Object> data = new HashMap<>();
|
|
|
+ data.put("planId", planId);
|
|
|
+ data.put("taskCount", taskCount);
|
|
|
+ data.put("journeyStage", 6);
|
|
|
+ return Result.success(data);
|
|
|
+ }
|
|
|
+
|
|
|
+ private UserIntent findIntent(Long userId) {
|
|
|
+ return userIntentMapper.selectOne(
|
|
|
+ new LambdaQueryWrapper<UserIntent>()
|
|
|
+ .eq(UserIntent::getUserId, userId)
|
|
|
+ .last("LIMIT 1"));
|
|
|
+ }
|
|
|
}
|