CREATE TABLE IF NOT EXISTS `la_worldcup_standing` (
  `id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
  `season_id` INT NOT NULL DEFAULT 0,
  `stage_name` VARCHAR(50) NOT NULL DEFAULT '',
  `group_name` VARCHAR(50) NOT NULL DEFAULT '',
  `team_id` BIGINT NOT NULL DEFAULT 0,
  `team_name` VARCHAR(100) NOT NULL DEFAULT '',
  `team_logo` VARCHAR(500) NOT NULL DEFAULT '',
  `rank` INT NOT NULL DEFAULT 0,
  `points` INT NOT NULL DEFAULT 0,
  `played` INT NOT NULL DEFAULT 0,
  `won` INT NOT NULL DEFAULT 0,
  `drawn` INT NOT NULL DEFAULT 0,
  `lost` INT NOT NULL DEFAULT 0,
  `goals_for` INT NOT NULL DEFAULT 0,
  `goals_against` INT NOT NULL DEFAULT 0,
  `goal_diff` INT NOT NULL DEFAULT 0,
  `row_order` INT NOT NULL DEFAULT 0,
  `create_time` INT UNSIGNED NOT NULL DEFAULT 0,
  `update_time` INT UNSIGNED NOT NULL DEFAULT 0,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uk_worldcup_group_team` (`season_id`, `stage_name`, `group_name`, `team_id`),
  KEY `idx_worldcup_group` (`season_id`, `stage_name`, `group_name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

CREATE TABLE IF NOT EXISTS `la_worldcup_person_ranking` (
  `id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
  `season_id` INT NOT NULL DEFAULT 0,
  `rank_type` VARCHAR(20) NOT NULL DEFAULT '',
  `person_id` BIGINT NOT NULL DEFAULT 0,
  `person_name` VARCHAR(100) NOT NULL DEFAULT '',
  `person_logo` VARCHAR(500) NOT NULL DEFAULT '',
  `team_id` BIGINT NOT NULL DEFAULT 0,
  `team_name` VARCHAR(100) NOT NULL DEFAULT '',
  `team_logo` VARCHAR(500) NOT NULL DEFAULT '',
  `rank` INT NOT NULL DEFAULT 0,
  `count` INT NOT NULL DEFAULT 0,
  `extra_json` JSON NULL,
  `create_time` INT UNSIGNED NOT NULL DEFAULT 0,
  `update_time` INT UNSIGNED NOT NULL DEFAULT 0,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uk_worldcup_rank_person` (`season_id`, `rank_type`, `person_id`),
  KEY `idx_worldcup_rank_type` (`season_id`, `rank_type`, `rank`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

UPDATE `la_league`
SET `label` = '世界杯',
    `type` = 'league',
    `sport_type` = 1,
    `api` = '',
    `icon` = '',
    `sort` = 285,
    `is_show` = 1,
    `league_id` = 61,
    `update_time` = UNIX_TIMESTAMP(),
    `delete_time` = NULL
WHERE (`label` = '世界杯' OR `league_id` = 61 OR `tab_id` = 26123);

INSERT INTO `la_league`
(`tab_id`, `league_id`, `label`, `type`, `sport_type`, `api`, `icon`, `sort`, `is_show`, `extra_data`, `sessionid`, `create_time`, `update_time`)
SELECT 26123, 61, '世界杯', 'league', 1, '', '', 285, 1, NULL, NULL, UNIX_TIMESTAMP(), UNIX_TIMESTAMP()
WHERE NOT EXISTS (
    SELECT 1
    FROM `la_league`
    WHERE (`label` = '世界杯' OR `league_id` = 61 OR `tab_id` = 26123)
      AND `delete_time` IS NULL
);

INSERT INTO `la_dev_crontab` (`name`, `type`, `system`, `remark`, `command`, `params`, `status`, `expression`, `create_time`, `update_time`)
SELECT '懂球帝世界杯采集', 1, 0, '拉取世界杯赛程、积分榜、射手榜和助攻榜', 'crawler', 'dqd_worldcup', 1, '*/10 * * * *', UNIX_TIMESTAMP(), UNIX_TIMESTAMP()
WHERE NOT EXISTS (
    SELECT 1 FROM `la_dev_crontab` WHERE `command` = 'crawler' AND `params` = 'dqd_worldcup' AND `delete_time` IS NULL
);
