补充历史预约作品商品ID迁移
This commit is contained in:
@@ -0,0 +1,104 @@
|
||||
CREATE DATABASE IF NOT EXISTS jayu_cloud DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||
USE jayu_cloud;
|
||||
|
||||
START TRANSACTION;
|
||||
|
||||
DROP TEMPORARY TABLE IF EXISTS tmp_jy_appointment_product_backfill;
|
||||
|
||||
CREATE TEMPORARY TABLE tmp_jy_appointment_product_backfill
|
||||
(
|
||||
order_item_id bigint unsigned NOT NULL,
|
||||
product_id bigint unsigned NOT NULL,
|
||||
PRIMARY KEY (order_item_id),
|
||||
UNIQUE KEY uk_tmp_jy_appointment_product_backfill_product (product_id)
|
||||
) ENGINE = InnoDB;
|
||||
|
||||
INSERT INTO tmp_jy_appointment_product_backfill (order_item_id, product_id)
|
||||
SELECT oi.id,
|
||||
UUID_SHORT()
|
||||
FROM t_order_item oi
|
||||
JOIN t_order o
|
||||
ON o.id = oi.order_id
|
||||
LEFT JOIN t_appointment_reservation r
|
||||
ON r.order_item_id = oi.id
|
||||
AND IFNULL(r.is_delete, 0) = 0
|
||||
WHERE oi.product_id IS NULL
|
||||
AND IFNULL(oi.is_delete, 0) = 0
|
||||
AND IFNULL(o.is_delete, 0) = 0
|
||||
AND COALESCE(o.shop_id, r.shop_id) IS NOT NULL
|
||||
AND NULLIF(TRIM(oi.appointment_product_title), '') IS NOT NULL;
|
||||
|
||||
INSERT INTO t_product
|
||||
(
|
||||
id,
|
||||
shop_id,
|
||||
title,
|
||||
description,
|
||||
precautions,
|
||||
image_file_ids,
|
||||
price,
|
||||
tags,
|
||||
like_count,
|
||||
collect_count,
|
||||
approximate_duration,
|
||||
bookable_artists,
|
||||
available_coupons,
|
||||
front_visible,
|
||||
source_type,
|
||||
create_time,
|
||||
update_time,
|
||||
is_delete
|
||||
)
|
||||
SELECT mapping.product_id,
|
||||
COALESCE(o.shop_id, r.shop_id),
|
||||
NULLIF(TRIM(oi.appointment_product_title), ''),
|
||||
NULLIF(TRIM(oi.appointment_product_description), ''),
|
||||
NULLIF(TRIM(oi.appointment_product_precautions), ''),
|
||||
NULLIF(TRIM(oi.appointment_product_image_file_ids), ''),
|
||||
COALESCE(oi.price, 0),
|
||||
COALESCE(NULLIF(TRIM(oi.appointment_product_tags), ''), ''),
|
||||
0,
|
||||
0,
|
||||
CASE
|
||||
WHEN r.appointment_start_time IS NOT NULL
|
||||
AND r.appointment_end_time IS NOT NULL
|
||||
THEN CAST(GREATEST(
|
||||
1,
|
||||
CEIL(TIMESTAMPDIFF(SECOND, r.appointment_start_time, r.appointment_end_time) / 60)
|
||||
) AS CHAR)
|
||||
ELSE ''
|
||||
END,
|
||||
CASE
|
||||
WHEN oi.artist_id IS NULL THEN ''
|
||||
ELSE CAST(oi.artist_id AS CHAR)
|
||||
END,
|
||||
NULL,
|
||||
0,
|
||||
'MANAGER_APPOINTMENT',
|
||||
COALESCE(oi.create_time, NOW()),
|
||||
COALESCE(oi.update_time, NOW()),
|
||||
0
|
||||
FROM tmp_jy_appointment_product_backfill mapping
|
||||
JOIN t_order_item oi
|
||||
ON oi.id = mapping.order_item_id
|
||||
JOIN t_order o
|
||||
ON o.id = oi.order_id
|
||||
LEFT JOIN t_appointment_reservation r
|
||||
ON r.order_item_id = oi.id
|
||||
AND IFNULL(r.is_delete, 0) = 0;
|
||||
|
||||
UPDATE t_order_item oi
|
||||
JOIN tmp_jy_appointment_product_backfill mapping
|
||||
ON mapping.order_item_id = oi.id
|
||||
SET oi.product_id = mapping.product_id
|
||||
WHERE oi.product_id IS NULL;
|
||||
|
||||
SELECT COUNT(*) AS backfilled_order_item_count
|
||||
FROM tmp_jy_appointment_product_backfill mapping
|
||||
JOIN t_order_item oi
|
||||
ON oi.id = mapping.order_item_id
|
||||
WHERE oi.product_id = mapping.product_id;
|
||||
|
||||
COMMIT;
|
||||
|
||||
DROP TEMPORARY TABLE IF EXISTS tmp_jy_appointment_product_backfill;
|
||||
Reference in New Issue
Block a user