INSERT INTO `la_community_tag` (`name`, `icon`, `sort`, `post_count`, `is_hot`, `status`, `create_time`)
SELECT '世界杯', '', 90, 0, 1, 1, UNIX_TIMESTAMP()
WHERE NOT EXISTS (
    SELECT 1 FROM `la_community_tag` WHERE `name` = '世界杯'
);

INSERT INTO `la_community_post` (`user_id`, `content`, `images`, `post_type`, `match_id`, `is_paid`, `price_points`, `free_content_len`, `status`, `create_time`, `update_time`)
SELECT 1, '世界杯开赛氛围越来越浓了，大家觉得本届最大的黑马会是谁？', '[]', 0, 0, 0, 0, 100, 1, UNIX_TIMESTAMP(), UNIX_TIMESTAMP()
WHERE NOT EXISTS (
    SELECT 1 FROM `la_community_post` WHERE `content` = '世界杯开赛氛围越来越浓了，大家觉得本届最大的黑马会是谁？'
);

INSERT INTO `la_community_post` (`user_id`, `content`, `images`, `post_type`, `match_id`, `is_paid`, `price_points`, `free_content_len`, `status`, `create_time`, `update_time`)
SELECT 1, '我更看好防守稳一点的球队，世界杯这种大赛还是先稳住再说。', '[]', 0, 0, 0, 0, 100, 1, UNIX_TIMESTAMP(), UNIX_TIMESTAMP()
WHERE NOT EXISTS (
    SELECT 1 FROM `la_community_post` WHERE `content` = '我更看好防守稳一点的球队，世界杯这种大赛还是先稳住再说。'
);

INSERT INTO `la_community_post` (`user_id`, `content`, `images`, `post_type`, `match_id`, `is_paid`, `price_points`, `free_content_len`, `status`, `create_time`, `update_time`)
SELECT 1, '这届世界杯的球员状态起伏很大，关键还是看临场调整和替补深度。', '[]', 0, 0, 0, 0, 100, 1, UNIX_TIMESTAMP(), UNIX_TIMESTAMP()
WHERE NOT EXISTS (
    SELECT 1 FROM `la_community_post` WHERE `content` = '这届世界杯的球员状态起伏很大，关键还是看临场调整和替补深度。'
);

INSERT INTO `la_community_post_tag` (`post_id`, `tag_id`)
SELECT p.id, t.id
FROM `la_community_post` p
JOIN `la_community_tag` t ON t.`name` = '世界杯'
WHERE p.`content` IN (
    '世界杯开赛氛围越来越浓了，大家觉得本届最大的黑马会是谁？',
    '我更看好防守稳一点的球队，世界杯这种大赛还是先稳住再说。',
    '这届世界杯的球员状态起伏很大，关键还是看临场调整和替补深度。'
)
ON DUPLICATE KEY UPDATE `post_id` = `post_id`;

UPDATE `la_community_tag` t
SET `post_count` = (
    SELECT COUNT(*)
    FROM `la_community_post_tag` pt
    JOIN `la_community_post` p ON p.id = pt.post_id AND p.delete_time IS NULL
    WHERE pt.tag_id = t.id
)
WHERE t.`name` = '世界杯';
