|
|
@@ -3651,6 +3651,10 @@ insertSysConfigSeed("gift_membership_pay_price", "198000", "送会员商品达
|
|
|
// 写入 product_order_auto_complete 27 字符 > 原列宽 20,触发 Data truncation,
|
|
|
// 操作日志缺失)。幂等:MODIFY 可重复执行(已是 64 时语义等价 no-op)。
|
|
|
widenUserOperationLogType();
|
|
|
+
|
|
|
+ // 迁移499: 还原水机 K8 终身会员权益(3 名 LIFETIME 补录交易 + 设备维护提醒表)
|
|
|
+ // 幂等:order_no 唯一 + 提醒唯一键 uk_reminder,重复执行不产生重复数据
|
|
|
+ migrateK8LifetimeBenefits();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -3668,6 +3672,81 @@ insertSysConfigSeed("gift_membership_pay_price", "198000", "送会员商品达
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 迁移499: 还原水机 K8 终身会员权益(spec 2026-11-19)。
|
|
|
+ * <p>① 创建设备维护提醒表 device_maintenance_reminders(唯一键 uk_reminder 幂等);
|
|
|
+ * ② 为 3 名 LIFETIME 会员补录 K8 交易订单(order_no 唯一守卫,INSERT IGNORE);
|
|
|
+ * ③ 按购买日推算洗机/滤芯到期,生成 6 条维护提醒(INSERT IGNORE)。</p>
|
|
|
+ * <p>整体 try-catch 吞异常,避免历史库缺列导致启动失败;幂等可重复执行。</p>
|
|
|
+ */
|
|
|
+ private void migrateK8LifetimeBenefits() {
|
|
|
+ try {
|
|
|
+ // ① 设备维护提醒表
|
|
|
+ jdbcTemplate.execute("CREATE TABLE IF NOT EXISTS device_maintenance_reminders (" +
|
|
|
+ "id BIGINT AUTO_INCREMENT PRIMARY KEY, " +
|
|
|
+ "buyer_id BIGINT NOT NULL COMMENT '购买人user_id', " +
|
|
|
+ "family_id BIGINT COMMENT '家庭ID', " +
|
|
|
+ "product_id BIGINT NOT NULL COMMENT '来源设备product_id(9=还原水机)', " +
|
|
|
+ "service_type VARCHAR(20) NOT NULL COMMENT 'wash_machine=洗机/replace_filter=换滤芯', " +
|
|
|
+ "purchased_at DATETIME NOT NULL, " +
|
|
|
+ "due_date DATE NOT NULL, " +
|
|
|
+ "window_start_date DATE NOT NULL, " +
|
|
|
+ "status VARCHAR(20) NOT NULL DEFAULT 'pending' COMMENT 'pending/done/dismissed', " +
|
|
|
+ "created_at DATETIME DEFAULT CURRENT_TIMESTAMP, " +
|
|
|
+ "updated_at DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, " +
|
|
|
+ "UNIQUE KEY uk_reminder (buyer_id, product_id, service_type, due_date), " +
|
|
|
+ "INDEX idx_family_status (family_id, status)" +
|
|
|
+ ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='设备维护提醒'");
|
|
|
+
|
|
|
+ // ② 补录 3 名终身会员的 K8 交易记录(order_no 唯一守卫)
|
|
|
+ Object[][] members = {
|
|
|
+ {53L, 71L, "2026-06-26"},
|
|
|
+ {54L, 57L, "2026-09-27"},
|
|
|
+ {55L, 59L, "2026-09-27"}
|
|
|
+ };
|
|
|
+ for (Object[] m : members) {
|
|
|
+ Long buyerId = (Long) m[0];
|
|
|
+ Long familyId = (Long) m[1];
|
|
|
+ String paidDate = (String) m[2];
|
|
|
+ String orderNo = "K8-LIFETIME-" + buyerId + "-" + paidDate.replace("-", "");
|
|
|
+ jdbcTemplate.update(
|
|
|
+ "INSERT IGNORE INTO product_orders (order_no, product_id, product_name, buyer_id, family_id, "
|
|
|
+ + "quantity, unit_price, total_amount, status, paid_at, created_at, updated_at) "
|
|
|
+ + "VALUES (?, 9, '还原水机', ?, ?, 1, 4080000, 4080000, 'paid', ?, NOW(), NOW())",
|
|
|
+ orderNo, buyerId, familyId, paidDate + " 00:00:00");
|
|
|
+ }
|
|
|
+
|
|
|
+ // ③ 生成设备维护提醒(复用 K8MaintenanceCalculator,插入幂等)
|
|
|
+ for (Object[] m : members) {
|
|
|
+ Long buyerId = (Long) m[0];
|
|
|
+ Long familyId = (Long) m[1];
|
|
|
+ java.time.LocalDateTime paidAt = java.time.LocalDateTime.of(
|
|
|
+ Integer.parseInt(((String) m[2]).substring(0, 4)),
|
|
|
+ Integer.parseInt(((String) m[2]).substring(5, 7)),
|
|
|
+ Integer.parseInt(((String) m[2]).substring(8, 10)), 0, 0);
|
|
|
+ com.etotem.cfc.service.K8MaintenanceCalculator.MaintenanceDates d =
|
|
|
+ com.etotem.cfc.service.K8MaintenanceCalculator.deriveMaintenance(paidAt);
|
|
|
+ insertMaintenanceReminder(buyerId, familyId, "wash_machine", paidAt, d.washDueDate, d.washWindowStart);
|
|
|
+ insertMaintenanceReminder(buyerId, familyId, "replace_filter", paidAt, d.filterDueDate, d.filterWindowStart);
|
|
|
+ }
|
|
|
+ log.info("迁移499: K8终身会员权益补录完成(3订单+6提醒)");
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.warn("迁移499: K8终身会员权益补录失败(忽略): {}", e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /** 幂等插入单条设备维护提醒(唯一键 uk_reminder 去重)。 */
|
|
|
+ private void insertMaintenanceReminder(Long buyerId, Long familyId, String serviceType,
|
|
|
+ java.time.LocalDateTime purchasedAt,
|
|
|
+ java.time.LocalDate dueDate, java.time.LocalDate windowStart) {
|
|
|
+ jdbcTemplate.update(
|
|
|
+ "INSERT IGNORE INTO device_maintenance_reminders "
|
|
|
+ + "(buyer_id, family_id, product_id, service_type, purchased_at, due_date, window_start_date, status) "
|
|
|
+ + "VALUES (?, ?, 9, ?, ?, ?, ?, 'pending')",
|
|
|
+ buyerId, familyId, serviceType, purchasedAt,
|
|
|
+ java.sql.Date.valueOf(dueDate), java.sql.Date.valueOf(windowStart));
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* 迁移475: 创建资源匹配结果表(SC-H-05,能力键 butler.resource.match)。
|