CREATE DATABASE IF NOT EXISTS jayu_cloud DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; USE jayu_cloud; DROP TEMPORARY TABLE IF EXISTS tmp_jy_artist_shop; CREATE TEMPORARY TABLE tmp_jy_artist_shop ( artist_id bigint unsigned NOT NULL, shop_id bigint unsigned NOT NULL, PRIMARY KEY (artist_id, shop_id) ) ENGINE=Memory; INSERT INTO tmp_jy_artist_shop (artist_id, shop_id) SELECT artist_id, shop_id FROM ( SELECT u.id AS artist_id, b.shop_id AS shop_id FROM t_user u JOIN t_user_shop_binding b ON b.user_id = u.id WHERE u.type = 3 AND IFNULL(u.is_delete, 0) = 0 AND b.status = 1 AND IFNULL(b.is_delete, 0) = 0 AND b.shop_id > 0 UNION SELECT u.id AS artist_id, u.shop_id AS shop_id FROM t_user u WHERE u.type = 3 AND IFNULL(u.is_delete, 0) = 0 AND u.shop_id IS NOT NULL AND u.shop_id > 0 ) artist_shop; UPDATE t_artist_schedule_rule r JOIN tmp_jy_artist_shop a ON a.artist_id = r.artist_id AND a.shop_id = r.shop_id SET r.preset_type = 'EVERYDAY', r.work_days = '1,2,3,4,5,6,7', r.start_time = '00:00:00', r.end_time = '23:59:59', r.slot_minutes = 60, r.capacity = 1, r.status = 1, r.remark = '员工默认全周全天排班', r.update_time = NOW() WHERE IFNULL(r.is_delete, 0) = 0; INSERT INTO t_artist_schedule_rule ( id, shop_id, artist_id, preset_type, work_days, start_time, end_time, slot_minutes, capacity, status, remark, create_time, update_time, is_delete ) SELECT UUID_SHORT() AS id, a.shop_id, a.artist_id, 'EVERYDAY', '1,2,3,4,5,6,7', '00:00:00', '23:59:59', 60, 1, 1, '员工默认全周全天排班', NOW(), NOW(), 0 FROM tmp_jy_artist_shop a LEFT JOIN t_artist_schedule_rule r ON r.shop_id = a.shop_id AND r.artist_id = a.artist_id AND IFNULL(r.is_delete, 0) = 0 WHERE r.id IS NULL; DROP TEMPORARY TABLE IF EXISTS tmp_jy_artist_shop;