Browse Source

feat(ai.aiyunyi.mapping): S-cfc-468 TDD-GREEN 爱云医检测映射表实体/Mapper/建表迁移

红测 AiYunyiMappingContractTest 14/14 转绿(基线 13 红 1 绿)。新增 AiYunyiMapping 实体(@TableName/@TableId AUTO)、AiYunyiMappingMapper(BaseMapper),迁移500 幂等 CREATE TABLE IF NOT EXISTS aiyunyi_mapping 并同步 schema.sql。
E2E Test Bot 3 hours ago
parent
commit
d2c97e37ae

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

@@ -3666,6 +3666,38 @@ insertSysConfigSeed("gift_membership_pay_price", "198000", "送会员商品达
         // 迁移499: 还原水机 K8 终身会员权益(3 名 LIFETIME 补录交易 + 设备维护提醒表)
         // 幂等:order_no 唯一 + 提醒唯一键 uk_reminder,重复执行不产生重复数据
         migrateK8LifetimeBenefits();
+
+        // 迁移500: 爱云医 AI 检测本地映射表 aiyunyi_mapping(能力键 ai.aiyunyi.mapping,§4.3)
+        // 承载家庭/成员 ↔ 爱云医检测用户/套餐/套餐项/报告的关联与状态(0进行中/1完成/2失败)
+        createAiYunyiMappingTable();
+    }
+
+    /**
+     * 迁移500: 爱云医 AI 检测本地映射表(能力键 ai.aiyunyi.mapping,§4.3)。
+     * 幂等:CREATE TABLE IF NOT EXISTS + try/catch 忽略「表已存在」异常,可重复执行。
+     */
+    void createAiYunyiMappingTable() {
+        try {
+            jdbcTemplate.execute("CREATE TABLE IF NOT EXISTS aiyunyi_mapping ("
+                    + "id BIGINT AUTO_INCREMENT PRIMARY KEY, "
+                    + "member_id BIGINT NOT NULL COMMENT '家庭成员ID(family_members.id)', "
+                    + "family_id BIGINT NOT NULL COMMENT '家庭ID', "
+                    + "aiyunyi_detection_user_id BIGINT NULL COMMENT '爱云医检测用户ID', "
+                    + "aiyunyi_package_id BIGINT NULL COMMENT '爱云医套餐ID', "
+                    + "aiyunyi_package_item_id BIGINT NULL COMMENT '爱云医套餐项ID', "
+                    + "aiyunyi_report_id BIGINT NULL COMMENT '爱云医报告ID', "
+                    + "aiyunyi_inspection_type INT NOT NULL DEFAULT 0 COMMENT '检测类型: 0普通照片/1/2/3', "
+                    + "status INT NOT NULL DEFAULT 0 COMMENT '状态: 0进行中/1完成/2失败', "
+                    + "created_at DATETIME DEFAULT CURRENT_TIMESTAMP, "
+                    + "updated_at DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, "
+                    + "INDEX idx_member (member_id), "
+                    + "INDEX idx_family (family_id), "
+                    + "INDEX idx_report (aiyunyi_report_id) "
+                    + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='爱云医AI检测本地映射表'");
+            log.info("迁移500: 已创建 aiyunyi_mapping 表");
+        } catch (Exception e) {
+            log.warn("迁移500: 创建 aiyunyi_mapping 表失败(可能已存在): {}", e.getMessage());
+        }
     }
 
     /**

+ 53 - 0
cfc-backend/src/main/java/com/etotem/cfc/entity/AiYunyiMapping.java

@@ -0,0 +1,53 @@
+package com.etotem.cfc.entity;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import lombok.Data;
+
+import java.io.Serializable;
+import java.util.Date;
+
+/**
+ * 爱云医 AI 检测本地映射表(能力键 ai.aiyunyi.mapping,§4.3 aiyunyi_mapping)。
+ *
+ * <p>单租户账户模型下记录「家庭/成员 ↔ 爱云医检测用户/套餐/套餐项/报告」的关联与处理状态。
+ * 状态:0 进行中 / 1 完成 / 2 失败。</p>
+ */
+@Data
+@TableName("aiyunyi_mapping")
+public class AiYunyiMapping implements Serializable {
+
+    private static final long serialVersionUID = 1L;
+
+    @TableId(type = IdType.AUTO)
+    private long id;
+
+    /** 家庭成员ID(family_members.id) */
+    private long memberId;
+
+    /** 家庭ID */
+    private long familyId;
+
+    /** 爱云医检测用户ID */
+    private long aiyunyiDetectionUserId;
+
+    /** 爱云医套餐ID */
+    private long aiyunyiPackageId;
+
+    /** 爱云医套餐项ID */
+    private long aiyunyiPackageItemId;
+
+    /** 爱云医报告ID */
+    private long aiyunyiReportId;
+
+    /** 检测类型:0 普通照片 / 1 / 2 / 3 */
+    private int aiyunyiInspectionType;
+
+    /** 状态:0 进行中 / 1 完成 / 2 失败 */
+    private int status;
+
+    private Date createdAt;
+
+    private Date updatedAt;
+}

+ 13 - 0
cfc-backend/src/main/java/com/etotem/cfc/mapper/AiYunyiMappingMapper.java

@@ -0,0 +1,13 @@
+package com.etotem.cfc.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.etotem.cfc.entity.AiYunyiMapping;
+import org.apache.ibatis.annotations.Mapper;
+
+/**
+ * 爱云医 AI 检测本地映射表 Mapper(能力键 ai.aiyunyi.mapping)。
+ * 继承 MyBatis-Plus BaseMapper,提供 insert/selectById/updateById/deleteById CRUD。
+ */
+@Mapper
+public interface AiYunyiMappingMapper extends BaseMapper<AiYunyiMapping> {
+}

+ 18 - 0
cfc-backend/src/main/resources/schema.sql

@@ -24,6 +24,24 @@ CREATE INDEX idx_rules_enabled ON recommendation_rules(enabled);
 CREATE INDEX idx_rules_scene ON recommendation_rules(scene_codes);
 CREATE INDEX idx_rules_priority ON recommendation_rules(priority);
 
+-- 爱云医 AI 检测本地映射表(能力键 ai.aiyunyi.mapping,§4.3;迁移500)
+CREATE TABLE IF NOT EXISTS aiyunyi_mapping (
+    id BIGINT AUTO_INCREMENT PRIMARY KEY,
+    member_id BIGINT NOT NULL COMMENT '家庭成员ID(family_members.id)',
+    family_id BIGINT NOT NULL COMMENT '家庭ID',
+    aiyunyi_detection_user_id BIGINT NULL COMMENT '爱云医检测用户ID',
+    aiyunyi_package_id BIGINT NULL COMMENT '爱云医套餐ID',
+    aiyunyi_package_item_id BIGINT NULL COMMENT '爱云医套餐项ID',
+    aiyunyi_report_id BIGINT NULL COMMENT '爱云医报告ID',
+    aiyunyi_inspection_type INT NOT NULL DEFAULT 0 COMMENT '检测类型: 0普通照片/1/2/3',
+    status INT NOT NULL DEFAULT 0 COMMENT '状态: 0进行中/1完成/2失败',
+    created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
+    updated_at DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
+    INDEX idx_member (member_id),
+    INDEX idx_family (family_id),
+    INDEX idx_report (aiyunyi_report_id)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='爱云医AI检测本地映射表';
+
 -- 浠艾福数据库初始化脚本
 -- 自动创建表