|
@@ -0,0 +1,449 @@
|
|
|
|
|
+package com.etotem.cfc.unit;
|
|
|
|
|
+
|
|
|
|
|
+import com.etotem.cfc.common.Result;
|
|
|
|
|
+import com.etotem.cfc.controller.assessment.AssessmentComparisonController;
|
|
|
|
|
+import com.etotem.cfc.controller.growth.GrowthPlanController;
|
|
|
|
|
+import com.etotem.cfc.controller.guide.GuideFamilyTaskController;
|
|
|
|
|
+import com.etotem.cfc.controller.tianpan.TianpanController;
|
|
|
|
|
+import com.etotem.cfc.dto.TianpanDashboardVO;
|
|
|
|
|
+import com.etotem.cfc.service.TianpanService;
|
|
|
|
|
+import com.etotem.cfc.service.UserService;
|
|
|
|
|
+import org.junit.jupiter.api.DisplayName;
|
|
|
|
|
+import org.junit.jupiter.api.Test;
|
|
|
|
|
+import org.springframework.web.bind.annotation.PostMapping;
|
|
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
|
+
|
|
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
|
|
+import java.lang.reflect.Field;
|
|
|
|
|
+import java.lang.reflect.Method;
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
|
+import java.util.Arrays;
|
|
|
|
|
+import java.util.Collections;
|
|
|
|
|
+import java.util.HashSet;
|
|
|
|
|
+import java.util.LinkedHashMap;
|
|
|
|
|
+import java.util.LinkedHashSet;
|
|
|
|
|
+import java.util.List;
|
|
|
|
|
+import java.util.Map;
|
|
|
|
|
+import java.util.Set;
|
|
|
|
|
+
|
|
|
|
|
+import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
|
|
|
+import static org.junit.jupiter.api.Assertions.assertNotNull;
|
|
|
|
|
+import static org.junit.jupiter.api.Assertions.assertTrue;
|
|
|
|
|
+import static org.junit.jupiter.api.Assertions.fail;
|
|
|
|
|
+import static org.mockito.ArgumentMatchers.any;
|
|
|
|
|
+import static org.mockito.Mockito.mock;
|
|
|
|
|
+import static org.mockito.Mockito.never;
|
|
|
|
|
+import static org.mockito.Mockito.verify;
|
|
|
|
|
+import static org.mockito.Mockito.when;
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ * 契约级单测(TDD-RED):能力键 {@code ai.coach.familyBoard} / 任务号 S-cfc-249 ——
|
|
|
|
|
+ * 「家庭成长看板(教练聚合视图)」<b>同源聚合 / 下钻路由 / 角色门禁 / 安全默认值</b>契约缺口。
|
|
|
|
|
+ *
|
|
|
|
|
+ * <p><b>契约溯源</b></p>
|
|
|
|
|
+ * <ul>
|
|
|
|
|
+ * <li>需求:{@code tests/user-scenarios/应用场景总览.md} SC-B-10(家庭成长看板·教练聚合视图)——
|
|
|
|
|
+ * 目标「一屏聚合全家五维/任务/报告/方案」,流程「打开 → 聚合展示 → 下钻」,边界「仅本家庭;缺失降级」。</li>
|
|
|
|
|
+ * <li>AC:{@code tests/test-cases/butler.md} TC-B-10(四类齐全、数值与各模块详情一致、每张卡片下钻)、
|
|
|
|
|
+ * TC-B-10-E(单卡降级/整页空态)、TC-B-10-P(家长越权 F9、孩子 token、非绑定规划师均 403)。</li>
|
|
|
|
|
+ * <li>设计:{@code docs/superpowers/api/API_REFERENCE.md} §4.10(测评)/§4.14(先天画像,心维度来源);
|
|
|
|
|
+ * 派单指定载体 = 家庭天盘 {@code TianpanController /api/tianpan/*}
|
|
|
|
|
+ * (dashboard / member/{memberId} / related-items,全家五维/任务/报告/方案聚合下钻),
|
|
|
|
|
+ * 且与 {@code teacher.family.overview} 同源——
|
|
|
|
|
+ * {@code GuideFamilyTaskController}(任务总览/进行中任务)、{@code GrowthPlanController}(进行中方案)、
|
|
|
|
|
+ * {@code AssessmentComparisonController}(报告对比)、{@code TianpanController}(天盘聚合)。</li>
|
|
|
|
|
+ * </ul>
|
|
|
|
|
+ *
|
|
|
|
|
+ * <p><b>与已合入主链的同键 RED 测试互补</b>:{@code CoachFamilyBoardContractTest}(13 红)锚定「新建宿主服务 +
|
|
|
|
|
+ * 新 Controller」,{@code AiCoachFamilyBoardSurfaceContractTest}(5 红)锚定「既有天盘面载体字段 + POST 端点 /
|
|
|
|
|
+ * familyId 隔离」。本类补齐三者均未覆盖的四个契约面:</p>
|
|
|
|
|
+ * <ol>
|
|
|
|
|
+ * <li><b>同源依赖</b>:看板宿主必须复用 {@code TianpanService}/{@code TaskService}/{@code GrowthPlanService}/
|
|
|
|
|
+ * {@code AssessmentComparisonService}/{@code GuideFamilyAccessGuard},而非另起炉灶重复聚合;</li>
|
|
|
|
|
+ * <li><b>下钻路由映射</b>:每张卡片的 {@code drillDownRoute} 必须落到同源详情端点(不是任意非空字符串);</li>
|
|
|
|
|
+ * <li><b>角色门禁</b>:既有天盘聚合端点 {@code TianpanController#dashboard} 必须拒绝孩子 token 请求全家看板
|
|
|
|
|
+ * (TC-B-10-P 第 2 步 403,孩子端仅 SC-C-06 自身只读);当前 checkAccess 仅看 familyId 归属,未看 role;</li>
|
|
|
|
|
+ * <li><b>五维数据源 + 安全默认值</b>:五维载体须含根码 body/mind/wisdom/action/wealth 与 sources(§4.10/§4.14),
|
|
|
|
|
+ * 看板 VO 须对空态字段给出非 null / false 默认值,避免整页白屏。</li>
|
|
|
|
|
+ * </ol>
|
|
|
|
|
+ *
|
|
|
|
|
+ * <p><b>实现现状(RED 依据)</b>:{@link TianpanController} 无看板聚合端点,{@link TianpanDashboardVO} 仅含
|
|
|
|
|
+ * familyName/members/relationships/familyWuxing/relatedItems/dailyFortune/annualEnergies;全库无
|
|
|
|
|
+ * {@code CoachFamilyBoardService} / {@code FamilyBoardVO}。故除「同源端点存在性」对照用例外,其余用例全部失败(红),
|
|
|
|
|
+ * 失败原文以 {@code [S-cfc-249/ai.coach.familyBoard]} 开头。</p>
|
|
|
|
|
+ *
|
|
|
|
|
+ * <p><b>GREEN 指引</b>:按上述四面落地宿主/载体/端点并复用同源服务后自动转绿。纯 JUnit 反射,
|
|
|
|
|
+ * 无 Spring 上下文 / 无 DB / 无外部服务,与同批 RED 契约测试
|
|
|
|
|
+ * ({@code TeamProfitHookContractTest}、{@code FamilyJoinValidationRulesContractTest})风格一致。</p>
|
|
|
|
|
+ */
|
|
|
|
|
+class AiCoachFamilyBoardSameSourceContractTest {
|
|
|
|
|
+
|
|
|
|
|
+ /** 规格设计宿主(本分支未落地,反射锚定避免编译期依赖)。 */
|
|
|
|
|
+ private static final String BOARD_SERVICE = "com.etotem.cfc.service.CoachFamilyBoardService";
|
|
|
|
|
+
|
|
|
|
|
+ /** 看板响应载体候选(按优先级)。 */
|
|
|
|
|
+ private static final String[] BOARD_VO_CANDIDATES = {
|
|
|
|
|
+ "com.etotem.cfc.dto.FamilyBoardVO",
|
|
|
|
|
+ "com.etotem.cfc.dto.CoachFamilyBoardVO",
|
|
|
|
|
+ "com.etotem.cfc.dto.FamilyBoardAggregateVO"
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ /** 看板 Controller 候选(既有天盘面 / 新契约面)。 */
|
|
|
|
|
+ private static final String[] BOARD_CONTROLLERS = {
|
|
|
|
|
+ "com.etotem.cfc.controller.ai.CoachFamilyBoardController"
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ /** 与 teacher.family.overview 同源的宿主依赖(同源聚合,禁止另起炉灶)。 */
|
|
|
|
|
+ private static final Set<String> SAME_SOURCE_DEPS = new HashSet<>(Arrays.asList(
|
|
|
|
|
+ "com.etotem.cfc.service.TianpanService",
|
|
|
|
|
+ "com.etotem.cfc.service.TaskService",
|
|
|
|
|
+ "com.etotem.cfc.service.GrowthPlanService",
|
|
|
|
|
+ "com.etotem.cfc.service.AssessmentComparisonService",
|
|
|
|
|
+ "com.etotem.cfc.service.GuideFamilyAccessGuard"));
|
|
|
|
|
+
|
|
|
|
|
+ /** 五维根码(DimensionCodeConstants:身/心/智/行/富)。 */
|
|
|
|
|
+ private static final Set<String> ROOT_DIMS = new HashSet<>(
|
|
|
|
|
+ Arrays.asList("body", "mind", "wisdom", "action", "wealth"));
|
|
|
|
|
+
|
|
|
|
|
+ /** TC-B-10 五类卡片。 */
|
|
|
|
|
+ private static final Set<String> CARDS = new LinkedHashSet<>(Arrays.asList(
|
|
|
|
|
+ "fiveDimension", "reports", "tasks", "plans", "warnings"));
|
|
|
|
|
+
|
|
|
|
|
+ /** 每张卡片下钻必须命中的同源端点片段(路由映射,非任意字符串)。 */
|
|
|
|
|
+ private static final Map<String, String> EXPECTED_DRILL_DOWN_ROUTES = expectedRoutes();
|
|
|
|
|
+
|
|
|
|
|
+ // ==================== 对照(应绿):同源端点确实存在 ====================
|
|
|
|
|
+
|
|
|
|
|
+ @Test
|
|
|
|
|
+ @DisplayName("对照-1:teacher.family.overview 同源端点应已存在(天盘/任务/方案/报告)")
|
|
|
|
|
+ void sameSourceEndpoints_shouldExist() {
|
|
|
|
|
+ assertEquals("/api/tianpan", classPath(TianpanController.class),
|
|
|
|
|
+ "[S-cfc-249/ai.coach.familyBoard] 同源锚点缺失:TianpanController 类路径");
|
|
|
|
|
+ assertEquals("/dashboard", postPath(TianpanController.class, "dashboard"));
|
|
|
|
|
+ assertEquals("/member/{memberId}", postPath(TianpanController.class, "memberDetail"));
|
|
|
|
|
+
|
|
|
|
|
+ assertEquals("/api/guide/families", classPath(GuideFamilyTaskController.class));
|
|
|
|
|
+ assertEquals("/{familyId}/overview", postPath(GuideFamilyTaskController.class, "getFamilyTaskOverview"));
|
|
|
|
|
+ assertEquals("/dashboard-stats", postPath(GuideFamilyTaskController.class, "getDashboardStats"));
|
|
|
|
|
+ assertEquals("/{familyId}/children/{memberId}/tasks",
|
|
|
|
|
+ postPath(GuideFamilyTaskController.class, "getFamilyMemberTasks"));
|
|
|
|
|
+
|
|
|
|
|
+ assertEquals("/api/growth/plan", classPath(GrowthPlanController.class));
|
|
|
|
|
+ assertEquals("/child/{memberId}/active", postPath(GrowthPlanController.class, "getActivePlan"));
|
|
|
|
|
+
|
|
|
|
|
+ assertEquals("/api/assessment/compare", classPath(AssessmentComparisonController.class));
|
|
|
|
|
+ assertEquals("/by-family", postPath(AssessmentComparisonController.class, "compareByFamily"));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // ==================== 正常流(RED):同源依赖 / 下钻路由 / 五维数据源 ====================
|
|
|
|
|
+
|
|
|
|
|
+ @Test
|
|
|
|
|
+ @DisplayName("正常流-2:看板宿主应复用同源服务(天盘/任务/方案/报告/规划师绑定守卫)")
|
|
|
|
|
+ void boardHost_shouldDependOnSameSourceServices() {
|
|
|
|
|
+ Class<?> host = boardHost();
|
|
|
|
|
+ Set<String> fieldTypes = declaredFieldTypeNames(host);
|
|
|
|
|
+ for (String dep : SAME_SOURCE_DEPS) {
|
|
|
|
|
+ assertTrue(fieldTypes.contains(dep),
|
|
|
|
|
+ "[S-cfc-249/ai.coach.familyBoard] 看板宿主 " + host.getName() + " 未复用同源服务 " + dep
|
|
|
|
|
+ + ":SC-B-10 要求与 teacher.family.overview 同源(任务总览/进行中方案/报告对比/天盘聚合),"
|
|
|
|
|
+ + "当前实现未落地或另起炉灶,无法保证聚合数值与各模块详情一致。");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Test
|
|
|
|
|
+ @DisplayName("正常流-3:每张卡片下钻路由应映射到同源详情端点")
|
|
|
|
|
+ void boardDrillDown_shouldRouteToSameSourceEndpoints() {
|
|
|
|
|
+ Object host = boardHostInstance();
|
|
|
|
|
+ for (Map.Entry<String, String> entry : EXPECTED_DRILL_DOWN_ROUTES.entrySet()) {
|
|
|
|
|
+ String route = invokeString(host, "drillDownRoute", entry.getKey());
|
|
|
|
|
+ assertNotNull(route,
|
|
|
|
|
+ "[S-cfc-249/ai.coach.familyBoard] 卡片 " + entry.getKey()
|
|
|
|
|
+ + " 缺少 drillDownRoute(String card) 下钻路由契约(实现未落地):"
|
|
|
|
|
+ + "TC-B-10 第 3 步要求每张卡片正确下钻到对应详情页。");
|
|
|
|
|
+ assertTrue(route.contains(entry.getValue()),
|
|
|
|
|
+ "[S-cfc-249/ai.coach.familyBoard] 卡片 " + entry.getKey() + " 下钻路由 " + route
|
|
|
|
|
+ + " 未命中同源端点片段 " + entry.getValue()
|
|
|
|
|
+ + ":下钻必须落到 teacher.family.overview 同源详情面,不得指向任意页面。");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Test
|
|
|
|
|
+ @DisplayName("正常流-4:五维载体应含身/心/智/行/富根码与 sources(§4.10 测评 + §4.14 先天画像)")
|
|
|
|
|
+ void fiveDimensionCarrier_shouldCarryRootDimsAndSources() {
|
|
|
|
|
+ for (Class<?> carrier : boardCarriers()) {
|
|
|
|
|
+ Field fiveDim = findField(carrier, "fiveDimension");
|
|
|
|
|
+ if (fiveDim == null) {
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ Set<String> fields = declaredFieldNames(fiveDim.getType());
|
|
|
|
|
+ if (fields.containsAll(ROOT_DIMS) && fields.contains("sources")) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ fail("[S-cfc-249/ai.coach.familyBoard] 看板载体缺少含 " + ROOT_DIMS + " 与 sources 的五维聚合结构:"
|
|
|
|
|
+ + "API_REFERENCE §4.10(测评五维来源)/§4.14(先天画像心维度来源,"
|
|
|
|
|
+ + "/api/mind/innate/portrait)要求五维卡片声明数据来源,当前载体仅含天盘五行/运势,"
|
|
|
|
|
+ + "五维数据源契约未落地。");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // ==================== 异常流(RED):安全默认值 ====================
|
|
|
|
|
+
|
|
|
|
|
+ @Test
|
|
|
|
|
+ @DisplayName("异常流-5:看板 VO 应给出安全默认值(空集合 + degraded=false + emptyState=false)")
|
|
|
|
|
+ void boardCarrier_shouldInitializeSafeDefaults() {
|
|
|
|
|
+ Class<?> carrier = firstLoadableBoardVo();
|
|
|
|
|
+ assertNotNull(carrier,
|
|
|
|
|
+ "[S-cfc-249/ai.coach.familyBoard] 看板响应载体 " + Arrays.toString(BOARD_VO_CANDIDATES)
|
|
|
|
|
+ + " 均未落地:TC-B-10-E 要求缺失降级不白屏,载体必须先有安全默认值(实现未落地)。");
|
|
|
|
|
+ Object vo = instantiate(carrier);
|
|
|
|
|
+ for (String card : CARDS) {
|
|
|
|
|
+ assertNotNull(invokeGetter(vo, card),
|
|
|
|
|
+ "[S-cfc-249/ai.coach.familyBoard] 看板载体 " + carrier.getSimpleName() + " 字段 " + card
|
|
|
|
|
+ + " 默认值为 null:空数据时应返回空结构而非 null,否则前端整页白屏(TC-B-10-E)。");
|
|
|
|
|
+ }
|
|
|
|
|
+ assertEquals(Boolean.FALSE, invokeGetter(vo, "degraded"),
|
|
|
|
|
+ "[S-cfc-249/ai.coach.familyBoard] degraded 默认值应为 false(仅局部降级时置 true)。");
|
|
|
|
|
+ assertEquals(Boolean.FALSE, invokeGetter(vo, "emptyState"),
|
|
|
|
|
+ "[S-cfc-249/ai.coach.familyBoard] emptyState 默认值应为 false(全家无数据时才置 true)。");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // ==================== 权限流(RED):角色门禁 / 规划师绑定守卫 ====================
|
|
|
|
|
+
|
|
|
|
|
+ @Test
|
|
|
|
|
+ @DisplayName("权限流-6:孩子 token 请求全家天盘看板应 403(TC-B-10-P,不进入聚合)")
|
|
|
|
|
+ void boardAggregate_childRole_shouldBeDenied() {
|
|
|
|
|
+ Method endpoint = findBoardEndpoint();
|
|
|
|
|
+ assertNotNull(endpoint,
|
|
|
|
|
+ "[S-cfc-249/ai.coach.familyBoard] 看板聚合 POST 端点未落地:应在 TianpanController /api/tianpan/*"
|
|
|
|
|
+ + "(或 /api/ai/coach/family-board)提供「打开→聚合展示」入口。");
|
|
|
|
|
+
|
|
|
|
|
+ // 纯 Mockito:孩子 token 属于本家庭(familyId 归属校验会通过),但角色不得查看全家看板
|
|
|
|
|
+ Long familyId = 100L;
|
|
|
|
|
+ Long childUserId = 3L;
|
|
|
|
|
+ TianpanService tianpanService = mock(TianpanService.class);
|
|
|
|
|
+ UserService userService = mock(UserService.class);
|
|
|
|
|
+ when(userService.getEffectiveFamilyIds(childUserId)).thenReturn(setOf(familyId));
|
|
|
|
|
+ when(tianpanService.buildDashboard(any(Long.class), any(), any(), any()))
|
|
|
|
|
+ .thenReturn(new TianpanDashboardVO());
|
|
|
|
|
+
|
|
|
|
|
+ TianpanController controller = new TianpanController();
|
|
|
|
|
+ injectField(controller, "tianpanService", tianpanService);
|
|
|
|
|
+ injectField(controller, "userService", userService);
|
|
|
|
|
+
|
|
|
|
|
+ HttpServletRequest request = mock(HttpServletRequest.class);
|
|
|
|
|
+ when(request.getAttribute("role")).thenReturn("child");
|
|
|
|
|
+ when(request.getAttribute("userId")).thenReturn(childUserId);
|
|
|
|
|
+
|
|
|
|
|
+ Result<TianpanDashboardVO> result = controller.dashboard(request, new LinkedHashMap<String, Object>(), familyId);
|
|
|
|
|
+
|
|
|
|
|
+ assertEquals(403, result.getCode(),
|
|
|
|
|
+ "[S-cfc-249/ai.coach.familyBoard] 孩子 token 请求全家天盘看板应 403(TC-B-10-P 第 2 步:"
|
|
|
|
|
+ + "孩子端仅自身只读视图 SC-C-06):当前 checkAccess 仅校验 familyId 归属、忽略 role,"
|
|
|
|
|
+ + "返回 " + result.getCode() + ",角色门禁契约未落地。");
|
|
|
|
|
+ verify(tianpanService, never()).buildDashboard(any(Long.class), any(), any(), any());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Test
|
|
|
|
|
+ @DisplayName("权限流-7:看板应复用规划师家庭绑定守卫(同源 teacher.family.overview)")
|
|
|
|
|
+ void boardHost_shouldReuseGuideFamilyAccessGuard() {
|
|
|
|
|
+ Set<String> fieldTypes = declaredFieldTypeNames(boardHost());
|
|
|
|
|
+ assertTrue(fieldTypes.contains("com.etotem.cfc.service.GuideFamilyAccessGuard"),
|
|
|
|
|
+ "[S-cfc-249/ai.coach.familyBoard] 看板宿主未注入 GuideFamilyAccessGuard:"
|
|
|
|
|
+ + "TC-B-10-P 第 3 步「规划师请求非绑定家庭看板 403」须复用规划师绑定守卫,"
|
|
|
|
|
+ + "与 teacher.family.overview 同源,不得自行判定绑定关系。");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // ==================== 反射辅助 ====================
|
|
|
|
|
+
|
|
|
|
|
+ private static Map<String, String> expectedRoutes() {
|
|
|
|
|
+ Map<String, String> routes = new LinkedHashMap<>();
|
|
|
|
|
+ routes.put("fiveDimension", "tianpan/dashboard");
|
|
|
|
|
+ routes.put("reports", "assessment/compare/by-family");
|
|
|
|
|
+ routes.put("tasks", "guide/families");
|
|
|
|
|
+ routes.put("plans", "growth/plan/child/");
|
|
|
|
|
+ routes.put("warnings", "tianpan/related-items");
|
|
|
|
|
+ return routes;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private Class<?> boardHost() {
|
|
|
|
|
+ Class<?> clazz = loadClass(BOARD_SERVICE);
|
|
|
|
|
+ if (clazz == null) {
|
|
|
|
|
+ fail("[S-cfc-249/ai.coach.familyBoard] 契约宿主 " + BOARD_SERVICE
|
|
|
|
|
+ + " 未实现(实现未落地):SC-B-10 一屏聚合→下钻服务缺失。");
|
|
|
|
|
+ }
|
|
|
|
|
+ return clazz;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private Object boardHostInstance() {
|
|
|
|
|
+ try {
|
|
|
|
|
+ return boardHost().getDeclaredConstructor().newInstance();
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ fail("[S-cfc-249/ai.coach.familyBoard] 契约宿主 " + BOARD_SERVICE + " 实例化失败:" + e.getMessage());
|
|
|
|
|
+ throw new IllegalStateException("unreachable");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private List<Class<?>> boardCarriers() {
|
|
|
|
|
+ List<Class<?>> carriers = new ArrayList<>();
|
|
|
|
|
+ carriers.add(TianpanDashboardVO.class);
|
|
|
|
|
+ for (String name : BOARD_VO_CANDIDATES) {
|
|
|
|
|
+ Class<?> clazz = loadClass(name);
|
|
|
|
|
+ if (clazz != null && !carriers.contains(clazz)) {
|
|
|
|
|
+ carriers.add(clazz);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return carriers;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private Class<?> firstLoadableBoardVo() {
|
|
|
|
|
+ for (String name : BOARD_VO_CANDIDATES) {
|
|
|
|
|
+ Class<?> clazz = loadClass(name);
|
|
|
|
|
+ if (clazz != null) {
|
|
|
|
|
+ return clazz;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /** 在既有天盘面 / 新契约面按方法名或路径查找 POST 聚合端点。 */
|
|
|
|
|
+ private Method findBoardEndpoint() {
|
|
|
|
|
+ List<Class<?>> controllers = new ArrayList<>();
|
|
|
|
|
+ controllers.add(TianpanController.class);
|
|
|
|
|
+ for (String name : BOARD_CONTROLLERS) {
|
|
|
|
|
+ Class<?> clazz = loadClass(name);
|
|
|
|
|
+ if (clazz != null) {
|
|
|
|
|
+ controllers.add(clazz);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ for (Class<?> controller : controllers) {
|
|
|
|
|
+ for (Method m : controller.getDeclaredMethods()) {
|
|
|
|
|
+ PostMapping pm = m.getAnnotation(PostMapping.class);
|
|
|
|
|
+ if (pm == null) {
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ String name = m.getName().toLowerCase();
|
|
|
|
|
+ if (name.contains("board") || name.contains("aggregate")
|
|
|
|
|
+ || hasAnyPath(pm.value(), "/family-board", "/board", "/aggregate")) {
|
|
|
|
|
+ return m;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private boolean hasAnyPath(String[] paths, String... expected) {
|
|
|
|
|
+ if (paths == null) {
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+ for (String path : paths) {
|
|
|
|
|
+ for (String e : expected) {
|
|
|
|
|
+ if (path.contains(e)) {
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private static Set<Long> setOf(Long... ids) {
|
|
|
|
|
+ Set<Long> set = new HashSet<>();
|
|
|
|
|
+ Collections.addAll(set, ids);
|
|
|
|
|
+ return set;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private static void injectField(Object target, String name, Object value) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ Field f = target.getClass().getDeclaredField(name);
|
|
|
|
|
+ f.setAccessible(true);
|
|
|
|
|
+ f.set(target, value);
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ fail("[S-cfc-249/ai.coach.familyBoard] 注入契约依赖 " + name + " 失败:" + e.getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private String invokeString(Object target, String methodName, String arg) {
|
|
|
|
|
+ for (Method m : target.getClass().getMethods()) {
|
|
|
|
|
+ if (m.getName().equals(methodName) && m.getParameterCount() == 1
|
|
|
|
|
+ && String.class.equals(m.getReturnType())) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ return (String) m.invoke(target, arg);
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private Object invokeGetter(Object target, String property) {
|
|
|
|
|
+ String suffix = Character.toUpperCase(property.charAt(0)) + property.substring(1);
|
|
|
|
|
+ for (Method m : target.getClass().getMethods()) {
|
|
|
|
|
+ if (m.getParameterCount() == 0
|
|
|
|
|
+ && (m.getName().equals("get" + suffix) || m.getName().equals("is" + suffix))) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ return m.invoke(target);
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private Object instantiate(Class<?> clazz) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ return clazz.getDeclaredConstructor().newInstance();
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ fail("[S-cfc-249/ai.coach.familyBoard] 看板载体 " + clazz.getName() + " 实例化失败:" + e.getMessage());
|
|
|
|
|
+ throw new IllegalStateException("unreachable");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private Field findField(Class<?> clazz, String name) {
|
|
|
|
|
+ for (Field f : clazz.getDeclaredFields()) {
|
|
|
|
|
+ if (f.getName().equals(name)) {
|
|
|
|
|
+ return f;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private Set<String> declaredFieldNames(Class<?> clazz) {
|
|
|
|
|
+ Set<String> names = new HashSet<>();
|
|
|
|
|
+ for (Field f : clazz.getDeclaredFields()) {
|
|
|
|
|
+ names.add(f.getName());
|
|
|
|
|
+ }
|
|
|
|
|
+ return names;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private Set<String> declaredFieldTypeNames(Class<?> clazz) {
|
|
|
|
|
+ Set<String> types = new HashSet<>();
|
|
|
|
|
+ for (Field f : clazz.getDeclaredFields()) {
|
|
|
|
|
+ types.add(f.getType().getName());
|
|
|
|
|
+ }
|
|
|
|
|
+ return types;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private String classPath(Class<?> clazz) {
|
|
|
|
|
+ RequestMapping rm = clazz.getAnnotation(RequestMapping.class);
|
|
|
|
|
+ return rm != null && rm.value().length > 0 ? rm.value()[0] : null;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private String postPath(Class<?> clazz, String methodName) {
|
|
|
|
|
+ for (Method m : clazz.getDeclaredMethods()) {
|
|
|
|
|
+ if (m.getName().equals(methodName)) {
|
|
|
|
|
+ PostMapping pm = m.getAnnotation(PostMapping.class);
|
|
|
|
|
+ return pm != null && pm.value().length > 0 ? pm.value()[0] : null;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private Class<?> loadClass(String name) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ return Class.forName(name, false, Thread.currentThread().getContextClassLoader());
|
|
|
|
|
+ } catch (ClassNotFoundException e) {
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+}
|