Răsfoiți Sursa

fix: 后台活动权重维度code与标准五维体系不一致导致新活动小程序端不显示

DimensionWeightPicker: mind(智)→wisdom、heart(心)→mind,与小程序/后端标准体系对齐
DatabaseInitializer 迁移141: 修正历史 dimension_weights 表 + 主表 JSON 列旧 code
ActivityController: 补 java.util.List 导入(遗留编译错误)
Sisyphus 3 luni în urmă
părinte
comite
cd191521b4

+ 39 - 0
cfc-backend/src/main/java/com/etotem/cfc/config/DatabaseInitializer.java

@@ -6148,6 +6148,45 @@ try {
 
     // 迁移140: activities表添加family_scope列(推荐系统-家庭参与去重,原migration102内从未被调用)
     ensureColumn("activities", "family_scope", "TINYINT DEFAULT 1 COMMENT '是否面向家庭: 1=家庭成员参与过即排除, 0=仅按个人参与排除'");
+
+    // 迁移141: 修正五维权重维度code体系(后台DimensionWeightPicker曾用mind=智/heart=心,标准体系为wisdom=智/mind=心)
+    // 旧体系写入的数据导致小程序端按wisdom/mind查询JSON_EXTRACT匹配不到,新活动显示不出来
+    try {
+        // 1. dimension_weights 表:仅处理含 heart 的目标(旧体系写入的),mind(智)→wisdom,heart(心)→mind
+        int dwHeartCount = jdbcTemplate.queryForObject(
+            "SELECT COUNT(*) FROM dimension_weights WHERE dimension = 'heart'", Integer.class);
+        if (dwHeartCount > 0) {
+            jdbcTemplate.update("UPDATE dimension_weights dw " +
+                "JOIN (SELECT DISTINCT target_type, target_id FROM dimension_weights WHERE dimension = 'heart') h " +
+                "ON dw.target_type = h.target_type AND dw.target_id = h.target_id " +
+                "SET dw.dimension = 'wisdom' WHERE dw.dimension = 'mind'");
+            jdbcTemplate.update("UPDATE dimension_weights SET dimension = 'mind' WHERE dimension = 'heart'");
+            log.info("已修正dimension_weights表维度code: {}条heart记录", dwHeartCount);
+        }
+    } catch (Exception e) {
+        log.warn("修正dimension_weights表维度code失败: {}", e.getMessage());
+    }
+
+    try {
+        // 2. 主表 dimension_weights JSON 列:含 heart 键的记录,mind键→wisdom键,heart键→mind键
+        String[] jsonTables = {"activities", "products", "articles"};
+        for (String table : jsonTables) {
+            int jsonCount = jdbcTemplate.queryForObject(
+                "SELECT COUNT(*) FROM " + table + " WHERE dimension_weights IS NOT NULL " +
+                "AND JSON_CONTAINS_PATH(dimension_weights, 'one', '$.heart')", Integer.class);
+            if (jsonCount > 0) {
+                jdbcTemplate.update("UPDATE " + table + " SET dimension_weights = JSON_SET(" +
+                    "JSON_REMOVE(JSON_REMOVE(dimension_weights, '$.mind'), '$.heart'), " +
+                    "'$.wisdom', JSON_EXTRACT(dimension_weights, '$.mind'), " +
+                    "'$.mind', JSON_EXTRACT(dimension_weights, '$.heart')) " +
+                    "WHERE dimension_weights IS NOT NULL " +
+                    "AND JSON_CONTAINS_PATH(dimension_weights, 'one', '$.heart')");
+                log.info("已修正{}表dimension_weights JSON: {}条", table, jsonCount);
+            }
+        }
+    } catch (Exception e) {
+        log.warn("修正主表dimension_weights JSON失败: {}", e.getMessage());
+    }
     }
 
     private void runMigration82() {

+ 8 - 8
cfc-web/src/components/DimensionWeightPicker.vue

@@ -54,18 +54,18 @@ export default {
     return {
       dimensions: [
         { code: 'body', name: '身·土', color: '#FF8C42', currentValue: 20 },
-        { code: 'mind', name: '智·金', color: '#6366F1', currentValue: 20 },
+        { code: 'wisdom', name: '智·金', color: '#6366F1', currentValue: 20 },
         { code: 'action', name: '行·木', color: '#10B981', currentValue: 20 },
         { code: 'wealth', name: '富·水', color: '#F59E0B', currentValue: 20 },
-        { code: 'heart', name: '心·火', color: '#FF6B9D', currentValue: 20 }
+        { code: 'mind', name: '心·火', color: '#FF6B9D', currentValue: 20 }
       ],
       presets: [
-        { label: '均衡', weights: { body: 20, mind: 20, action: 20, wealth: 20, heart: 20 } },
-        { label: '偏身', weights: { body: 40, mind: 15, action: 15, wealth: 15, heart: 15 } },
-        { label: '偏智', weights: { body: 15, mind: 40, action: 15, wealth: 15, heart: 15 } },
-        { label: '偏行', weights: { body: 15, mind: 15, action: 40, wealth: 15, heart: 15 } },
-        { label: '偏富', weights: { body: 15, mind: 15, action: 15, wealth: 40, heart: 15 } },
-        { label: '偏心', weights: { body: 15, mind: 15, action: 15, wealth: 15, heart: 40 } }
+        { label: '均衡', weights: { body: 20, wisdom: 20, action: 20, wealth: 20, mind: 20 } },
+        { label: '偏身', weights: { body: 40, wisdom: 15, action: 15, wealth: 15, mind: 15 } },
+        { label: '偏智', weights: { body: 15, wisdom: 40, action: 15, wealth: 15, mind: 15 } },
+        { label: '偏行', weights: { body: 15, wisdom: 15, action: 40, wealth: 15, mind: 15 } },
+        { label: '偏富', weights: { body: 15, wisdom: 15, action: 15, wealth: 40, mind: 15 } },
+        { label: '偏心', weights: { body: 15, wisdom: 15, action: 15, wealth: 15, mind: 40 } }
       ]
     }
   },