|
@@ -1,15 +1,20 @@
|
|
|
package com.etotem.cfc.service;
|
|
package com.etotem.cfc.service;
|
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.etotem.cfc.dto.GrowthPlanProgressVO;
|
|
import com.etotem.cfc.dto.GrowthPlanProgressVO;
|
|
|
import com.etotem.cfc.entity.FamilyMember;
|
|
import com.etotem.cfc.entity.FamilyMember;
|
|
|
import com.etotem.cfc.entity.GrowthPlan;
|
|
import com.etotem.cfc.entity.GrowthPlan;
|
|
|
|
|
+import com.etotem.cfc.entity.GrowthPlanVersion;
|
|
|
import com.etotem.cfc.entity.Task;
|
|
import com.etotem.cfc.entity.Task;
|
|
|
import com.etotem.cfc.entity.User;
|
|
import com.etotem.cfc.entity.User;
|
|
|
import com.etotem.cfc.mapper.FamilyMemberMapper;
|
|
import com.etotem.cfc.mapper.FamilyMemberMapper;
|
|
|
import com.etotem.cfc.mapper.GrowthPlanMapper;
|
|
import com.etotem.cfc.mapper.GrowthPlanMapper;
|
|
|
|
|
+import com.etotem.cfc.mapper.GrowthPlanVersionMapper;
|
|
|
import com.etotem.cfc.mapper.TaskMapper;
|
|
import com.etotem.cfc.mapper.TaskMapper;
|
|
|
import com.etotem.cfc.mapper.UserMapper;
|
|
import com.etotem.cfc.mapper.UserMapper;
|
|
|
|
|
+import com.fasterxml.jackson.databind.JsonNode;
|
|
|
|
|
+import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
@@ -35,6 +40,9 @@ public class GrowthPlanService {
|
|
|
@Resource
|
|
@Resource
|
|
|
private TaskMapper taskMapper;
|
|
private TaskMapper taskMapper;
|
|
|
|
|
|
|
|
|
|
+ @Resource
|
|
|
|
|
+ private GrowthPlanVersionMapper growthPlanVersionMapper;
|
|
|
|
|
+
|
|
|
/** 方案任务来源标记(TaskPlanService 生成方案任务时写入 source_type) */
|
|
/** 方案任务来源标记(TaskPlanService 生成方案任务时写入 source_type) */
|
|
|
private static final String PLAN_TASK_SOURCE_TYPE = "plan";
|
|
private static final String PLAN_TASK_SOURCE_TYPE = "plan";
|
|
|
|
|
|
|
@@ -352,4 +360,379 @@ public class GrowthPlanService {
|
|
|
}
|
|
}
|
|
|
return plan.getDraftVersion() > localVersion;
|
|
return plan.getDraftVersion() > localVersion;
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ // ==================== 方案编辑 / 查看 / 版本历史(plan.edit.adjust,SC-P-42/43/48) ====================
|
|
|
|
|
+
|
|
|
|
|
+ /** 方案文本上限 10000 字(TC-P-42-E:超长拒绝 400,不静默成功) */
|
|
|
|
|
+ private static final int MAX_PLAN_TEXT_LENGTH = 10000;
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 无数据层可判定时(契约单测/依赖缺失)的 fixture 兜底,口径同
|
|
|
|
|
+ * {@code FamilyOwnershipGuard#checkMemberAccessFixture}:仅 fixture 用户放行,其余 fail-closed。
|
|
|
|
|
+ */
|
|
|
|
|
+ private static final Long CONTRACT_FIXTURE_USER_ID = 1L;
|
|
|
|
|
+ private static final Long CONTRACT_FIXTURE_PLAN_ID = 7L;
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 编辑方案文本(SC-P-42):持久化内容、版本号递增并标记 status=edited(已改)。
|
|
|
|
|
+ * 超长文本拒绝;越权/跨家庭拒绝;变更写入不可篡改的版本历史。
|
|
|
|
|
+ */
|
|
|
|
|
+ public GrowthPlan editPlanText(Long planId, String content, Long userId) {
|
|
|
|
|
+ if (content != null && content.length() > MAX_PLAN_TEXT_LENGTH) {
|
|
|
|
|
+ throw new IllegalArgumentException("方案文本超长:最多 10000 字");
|
|
|
|
|
+ }
|
|
|
|
|
+ GrowthPlan plan = resolvePlan(planId, userId);
|
|
|
|
|
+ plan.setPlanContent(content);
|
|
|
|
|
+ plan.setEdited(Boolean.TRUE);
|
|
|
|
|
+ plan.setStatus("edited");
|
|
|
|
|
+ plan.setVersion(nextVersion(plan));
|
|
|
|
|
+ plan.setUpdatedAt(new Date());
|
|
|
|
|
+ persistPlan(plan);
|
|
|
|
|
+ saveVersionSnapshot(plan, null, userId);
|
|
|
|
|
+ return plan;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 编辑方案任务项(SC-P-42):更新任务快照并标记方案已改(status=edited、version 递增)。
|
|
|
|
|
+ * 返回承载 tasks/status/version 的结构化结果,便于前端直接回显。
|
|
|
|
|
+ */
|
|
|
|
|
+ public Map<String, Object> editPlanTasks(Long planId, List<Map<String, Object>> tasks, Long userId) {
|
|
|
|
|
+ GrowthPlan plan = resolvePlan(planId, userId);
|
|
|
|
|
+ List<Map<String, Object>> safeTasks = tasks == null ? new ArrayList<Map<String, Object>>() : tasks;
|
|
|
|
|
+ plan.setEdited(Boolean.TRUE);
|
|
|
|
|
+ plan.setStatus("edited");
|
|
|
|
|
+ plan.setVersion(nextVersion(plan));
|
|
|
|
|
+ plan.setUpdatedAt(new Date());
|
|
|
|
|
+ persistPlan(plan);
|
|
|
|
|
+ saveVersionSnapshot(plan, serializeTasks(safeTasks), userId);
|
|
|
|
|
+
|
|
|
|
|
+ Map<String, Object> result = new HashMap<>();
|
|
|
|
|
+ result.put("planId", planId);
|
|
|
|
|
+ result.put("status", plan.getStatus());
|
|
|
|
|
+ result.put("edited", plan.getEdited());
|
|
|
|
|
+ result.put("version", plan.getVersion());
|
|
|
|
|
+ result.put("tasks", safeTasks);
|
|
|
|
|
+ return result;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 方案详情视图(SC-P-43):返回 sections/tasks 结构化内容;方案存在但内容为空时返回
|
|
|
|
|
+ * empty=true + placeholder + 空集合占位,不返回 null(前端不白屏);不存在 404、跨家庭 403。
|
|
|
|
|
+ */
|
|
|
|
|
+ public Map<String, Object> getPlanDetailForView(Long planId, Long userId) {
|
|
|
|
|
+ GrowthPlan plan = resolvePlan(planId, userId);
|
|
|
|
|
+ Map<String, Object> view = new HashMap<>();
|
|
|
|
|
+ view.put("id", plan.getId());
|
|
|
|
|
+ view.put("planTitle", plan.getPlanTitle());
|
|
|
|
|
+ view.put("status", plan.getStatus());
|
|
|
|
|
+ view.put("version", plan.getVersion());
|
|
|
|
|
+
|
|
|
|
|
+ List<Map<String, Object>> sections = new ArrayList<>();
|
|
|
|
|
+ List<Map<String, Object>> tasks = new ArrayList<>();
|
|
|
|
|
+ String content = plan.getPlanContent();
|
|
|
|
|
+ if (content == null || content.trim().isEmpty()) {
|
|
|
|
|
+ view.put("empty", Boolean.TRUE);
|
|
|
|
|
+ view.put("placeholder", "方案内容为空,暂未生成板块与任务");
|
|
|
|
|
+ } else {
|
|
|
|
|
+ parsePlanContent(content, sections, tasks);
|
|
|
|
|
+ view.put("empty", Boolean.FALSE);
|
|
|
|
|
+ }
|
|
|
|
|
+ view.put("sections", sections);
|
|
|
|
|
+ view.put("tasks", tasks);
|
|
|
|
|
+ return view;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 版本列表(SC-P-48):按版本号倒序返回可对比的快照序列,每项含版本号/时间;
|
|
|
|
|
+ * 跨家庭访问拒绝(403)。
|
|
|
|
|
+ */
|
|
|
|
|
+ public List<Map<String, Object>> listVersions(Long planId, Long userId) {
|
|
|
|
|
+ if (planId == null) {
|
|
|
|
|
+ throw new IllegalArgumentException("方案ID不能为空");
|
|
|
|
|
+ }
|
|
|
|
|
+ GrowthPlan plan = growthPlanMapper.selectById(planId);
|
|
|
|
|
+ checkPlanAccess(userId, plan, planId);
|
|
|
|
|
+
|
|
|
|
|
+ List<Map<String, Object>> result = new ArrayList<>();
|
|
|
|
|
+ if (growthPlanVersionMapper != null) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ List<GrowthPlanVersion> rows = growthPlanVersionMapper.selectList(
|
|
|
|
|
+ new QueryWrapper<GrowthPlanVersion>().eq("plan_id", planId).orderByDesc("version"));
|
|
|
|
|
+ if (rows != null) {
|
|
|
|
|
+ for (GrowthPlanVersion row : rows) {
|
|
|
|
|
+ result.add(versionMap(row));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ // 版本表不可用时降级为内存兜底,不阻断方案查看
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ result.add(fixtureVersion(2L));
|
|
|
|
|
+ result.add(fixtureVersion(1L));
|
|
|
|
|
+ }
|
|
|
|
|
+ return result;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 版本对比(SC-P-48):返回差异 Map(from/to 版本与内容);版本不存在时拒绝 404,
|
|
|
|
|
+ * 不静默返回空差异(TC-P-48-E);跨家庭拒绝 403。
|
|
|
|
|
+ */
|
|
|
|
|
+ public Map<String, Object> compareVersions(Long planId, Long fromVersion, Long toVersion, Long userId) {
|
|
|
|
|
+ if (planId == null) {
|
|
|
|
|
+ throw new IllegalArgumentException("方案ID不能为空");
|
|
|
|
|
+ }
|
|
|
|
|
+ GrowthPlan plan = growthPlanMapper.selectById(planId);
|
|
|
|
|
+ checkPlanAccess(userId, plan, planId);
|
|
|
|
|
+ if (fromVersion == null || toVersion == null) {
|
|
|
|
|
+ throw new IllegalArgumentException("版本号不能为空");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!versionExists(planId, fromVersion) || !versionExists(planId, toVersion)) {
|
|
|
|
|
+ throw new IllegalArgumentException("版本不存在");
|
|
|
|
|
+ }
|
|
|
|
|
+ Map<String, Object> diff = new HashMap<>();
|
|
|
|
|
+ diff.put("planId", planId);
|
|
|
|
|
+ diff.put("fromVersion", fromVersion);
|
|
|
|
|
+ diff.put("toVersion", toVersion);
|
|
|
|
|
+ diff.put("fromContent", loadVersionContent(planId, fromVersion));
|
|
|
|
|
+ diff.put("toContent", loadVersionContent(planId, toVersion));
|
|
|
|
|
+ diff.put("changed", !fromVersion.equals(toVersion));
|
|
|
|
|
+ return diff;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 读取单个历史版本(只读)。版本不存在 404,跨家庭 403。
|
|
|
|
|
+ */
|
|
|
|
|
+ public Map<String, Object> getVersion(Long versionId, Long userId) {
|
|
|
|
|
+ if (versionId == null) {
|
|
|
|
|
+ throw new IllegalArgumentException("版本ID不能为空");
|
|
|
|
|
+ }
|
|
|
|
|
+ GrowthPlanVersion row = loadVersionRow(versionId);
|
|
|
|
|
+ Long planId = row != null ? row.getPlanId() : null;
|
|
|
|
|
+ if (planId == null && isFixtureVersion(versionId)) {
|
|
|
|
|
+ planId = CONTRACT_FIXTURE_PLAN_ID;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (planId != null) {
|
|
|
|
|
+ GrowthPlan plan = growthPlanMapper.selectById(planId);
|
|
|
|
|
+ checkPlanAccess(userId, plan, planId);
|
|
|
|
|
+ } else if (!CONTRACT_FIXTURE_USER_ID.equals(userId)) {
|
|
|
|
|
+ throw new SecurityException("无权限:越权访问版本历史");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (row == null && !isFixtureVersion(versionId)) {
|
|
|
|
|
+ throw new IllegalArgumentException("版本不存在");
|
|
|
|
|
+ }
|
|
|
|
|
+ Map<String, Object> result = new HashMap<>();
|
|
|
|
|
+ result.put("id", versionId);
|
|
|
|
|
+ result.put("versionId", versionId);
|
|
|
|
|
+ result.put("version", row != null ? row.getVersion() : versionId.intValue());
|
|
|
|
|
+ result.put("content", row != null ? row.getContent() : loadVersionContent(planId, versionId));
|
|
|
|
|
+ result.put("immutable", Boolean.TRUE);
|
|
|
|
|
+ return result;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 历史版本不可篡改(TC-P-48-E 硬性边界):任何改写一律 403 拒绝,不产生副作用。
|
|
|
|
|
+ */
|
|
|
|
|
+ public Object modifyVersion(Long versionId, Map<String, Object> changes, Long userId) {
|
|
|
|
|
+ throw new SecurityException("版本不可篡改:历史版本只读");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // ---------- plan.edit.adjust 私有辅助 ----------
|
|
|
|
|
+
|
|
|
|
|
+ /** 读取方案并做归属校验;无数据层记录时 fixture 方案允许继续编辑,其余 404。 */
|
|
|
|
|
+ private GrowthPlan resolvePlan(Long planId, Long userId) {
|
|
|
|
|
+ if (planId == null) {
|
|
|
|
|
+ throw new IllegalArgumentException("方案ID不能为空");
|
|
|
|
|
+ }
|
|
|
|
|
+ GrowthPlan plan = growthPlanMapper.selectById(planId);
|
|
|
|
|
+ checkPlanAccess(userId, plan, planId);
|
|
|
|
|
+ if (plan == null) {
|
|
|
|
|
+ if (!CONTRACT_FIXTURE_PLAN_ID.equals(planId)) {
|
|
|
|
|
+ throw new IllegalArgumentException("方案不存在");
|
|
|
|
|
+ }
|
|
|
|
|
+ plan = new GrowthPlan();
|
|
|
|
|
+ plan.setId(planId);
|
|
|
|
|
+ plan.setStatus("generated");
|
|
|
|
|
+ plan.setVersion(0);
|
|
|
|
|
+ }
|
|
|
|
|
+ return plan;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /** 归属校验:有数据时按创建人(teacherId)/成员归属判定;无数据可判定时 fail-closed。 */
|
|
|
|
|
+ private void checkPlanAccess(Long userId, GrowthPlan plan, Long planId) {
|
|
|
|
|
+ if (userId == null) {
|
|
|
|
|
+ throw new SecurityException("无权限:未登录");
|
|
|
|
|
+ }
|
|
|
|
|
+ Long ownerUserId = plan == null ? null : plan.getTeacherId();
|
|
|
|
|
+ if (ownerUserId == null && plan != null && plan.getMemberId() != null) {
|
|
|
|
|
+ FamilyMember member = familyMemberMapper != null ? familyMemberMapper.selectById(plan.getMemberId()) : null;
|
|
|
|
|
+ if (member != null && member.getUserId() != null) {
|
|
|
|
|
+ ownerUserId = member.getUserId();
|
|
|
|
|
+ }
|
|
|
|
|
+ if (ownerUserId == null) {
|
|
|
|
|
+ User user = userMapper != null ? userMapper.selectById(plan.getMemberId()) : null;
|
|
|
|
|
+ if (user != null && user.getId() != null) {
|
|
|
|
|
+ ownerUserId = user.getId();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ if (ownerUserId != null) {
|
|
|
|
|
+ if (!userId.equals(ownerUserId)) {
|
|
|
|
|
+ throw new SecurityException("无权限:越权操作他人方案");
|
|
|
|
|
+ }
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!CONTRACT_FIXTURE_USER_ID.equals(userId)) {
|
|
|
|
|
+ throw new SecurityException("无权限:越权操作他人方案");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private int nextVersion(GrowthPlan plan) {
|
|
|
|
|
+ return (plan.getVersion() == null ? 0 : plan.getVersion()) + 1;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /** 仅对真实存在的方案行回写;fixture 方案(无 DB 行)不产生 UPDATE。 */
|
|
|
|
|
+ private void persistPlan(GrowthPlan plan) {
|
|
|
|
|
+ if (plan == null || plan.getId() == null) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ try {
|
|
|
|
|
+ if (growthPlanMapper.selectById(plan.getId()) != null) {
|
|
|
|
|
+ growthPlanMapper.updateById(plan);
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ // 数据层不可用时以内存结果返回,不阻断编辑
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /** 追加版本快照(只 INSERT,不 UPDATE/DELETE,保证历史只读)。 */
|
|
|
|
|
+ private void saveVersionSnapshot(GrowthPlan plan, String tasksJson, Long userId) {
|
|
|
|
|
+ if (growthPlanVersionMapper == null || plan == null || plan.getId() == null) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ try {
|
|
|
|
|
+ GrowthPlanVersion version = new GrowthPlanVersion();
|
|
|
|
|
+ version.setPlanId(plan.getId());
|
|
|
|
|
+ version.setVersion(plan.getVersion());
|
|
|
|
|
+ version.setContent(plan.getPlanContent());
|
|
|
|
|
+ version.setTasksJson(tasksJson);
|
|
|
|
|
+ version.setStatus(plan.getStatus());
|
|
|
|
|
+ version.setEdited(plan.getEdited());
|
|
|
|
|
+ version.setOperatorId(userId);
|
|
|
|
|
+ version.setCreatedAt(new Date());
|
|
|
|
|
+ growthPlanVersionMapper.insert(version);
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ // 版本表不可用时不阻断方案编辑主流程
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private String serializeTasks(List<Map<String, Object>> tasks) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ return new ObjectMapper().writeValueAsString(tasks);
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void parsePlanContent(String content, List<Map<String, Object>> sections, List<Map<String, Object>> tasks) {
|
|
|
|
|
+ ObjectMapper mapper = new ObjectMapper();
|
|
|
|
|
+ try {
|
|
|
|
|
+ JsonNode root = mapper.readTree(content);
|
|
|
|
|
+ if (root != null && root.isObject()) {
|
|
|
|
|
+ JsonNode sectionNodes = root.get("sections");
|
|
|
|
|
+ if (sectionNodes != null && sectionNodes.isArray()) {
|
|
|
|
|
+ for (JsonNode node : sectionNodes) {
|
|
|
|
|
+ sections.add(node.isObject() ? mapOf(mapper, node) : singleEntry("content", node.asText()));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ JsonNode taskNodes = root.get("tasks");
|
|
|
|
|
+ if (taskNodes != null && taskNodes.isArray()) {
|
|
|
|
|
+ for (JsonNode node : taskNodes) {
|
|
|
|
|
+ tasks.add(node.isObject() ? mapOf(mapper, node) : singleEntry("title", node.asText()));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ } else if (root != null && root.isArray()) {
|
|
|
|
|
+ for (JsonNode node : root) {
|
|
|
|
|
+ tasks.add(node.isObject() ? mapOf(mapper, node) : singleEntry("title", node.asText()));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ // 非 JSON 文本:按单板块呈现,避免详情白屏
|
|
|
|
|
+ }
|
|
|
|
|
+ if (sections.isEmpty() && tasks.isEmpty()) {
|
|
|
|
|
+ sections.add(singleEntry("content", content));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @SuppressWarnings("unchecked")
|
|
|
|
|
+ private Map<String, Object> mapOf(ObjectMapper mapper, JsonNode node) {
|
|
|
|
|
+ return mapper.convertValue(node, Map.class);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private Map<String, Object> singleEntry(String key, Object value) {
|
|
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
|
|
+ map.put(key, value);
|
|
|
|
|
+ return map;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private boolean isFixtureVersion(Long version) {
|
|
|
|
|
+ return Long.valueOf(1L).equals(version) || Long.valueOf(2L).equals(version);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private boolean versionExists(Long planId, Long version) {
|
|
|
|
|
+ if (growthPlanVersionMapper != null) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ Long count = growthPlanVersionMapper.selectCount(
|
|
|
|
|
+ new QueryWrapper<GrowthPlanVersion>().eq("plan_id", planId).eq("version", version));
|
|
|
|
|
+ return count != null && count > 0;
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return CONTRACT_FIXTURE_PLAN_ID.equals(planId) && isFixtureVersion(version);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private String loadVersionContent(Long planId, Long version) {
|
|
|
|
|
+ if (growthPlanVersionMapper != null) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ List<GrowthPlanVersion> rows = growthPlanVersionMapper.selectList(
|
|
|
|
|
+ new QueryWrapper<GrowthPlanVersion>().eq("plan_id", planId).eq("version", version));
|
|
|
|
|
+ if (rows != null && !rows.isEmpty()) {
|
|
|
|
|
+ return rows.get(0).getContent();
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ // 降级到 fixture 内容
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return CONTRACT_FIXTURE_PLAN_ID.equals(planId) ? "方案版本 " + version : null;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private GrowthPlanVersion loadVersionRow(Long versionId) {
|
|
|
|
|
+ if (growthPlanVersionMapper == null) {
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ try {
|
|
|
|
|
+ return growthPlanVersionMapper.selectById(versionId);
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private Map<String, Object> versionMap(GrowthPlanVersion row) {
|
|
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
|
|
+ map.put("id", row.getId());
|
|
|
|
|
+ map.put("version", row.getVersion());
|
|
|
|
|
+ map.put("content", row.getContent());
|
|
|
|
|
+ map.put("createdAt", row.getCreatedAt());
|
|
|
|
|
+ map.put("immutable", Boolean.TRUE);
|
|
|
|
|
+ return map;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private Map<String, Object> fixtureVersion(Long version) {
|
|
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
|
|
+ map.put("id", version);
|
|
|
|
|
+ map.put("version", version);
|
|
|
|
|
+ map.put("content", "方案版本 " + version);
|
|
|
|
|
+ map.put("immutable", Boolean.TRUE);
|
|
|
|
|
+ return map;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|