#
Junjie
14 小时以前 656429e94f5989911bdf07848ef44b1cc71dfaf1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
SET @current_db := DATABASE();
 
SET @column_exists := (
  SELECT COUNT(1)
  FROM information_schema.COLUMNS
  WHERE TABLE_SCHEMA = @current_db
    AND TABLE_NAME = 'asr_bas_station_path_profile'
    AND COLUMN_NAME = 'is_default'
);
 
SET @add_column_sql := IF(
  @column_exists = 0,
  'ALTER TABLE asr_bas_station_path_profile ADD COLUMN is_default TINYINT NOT NULL DEFAULT 0 COMMENT ''默认模板 1是 0否'' AFTER status',
  'SELECT ''column is_default already exists'' '
);
PREPARE stmt_add_column FROM @add_column_sql;
EXECUTE stmt_add_column;
DEALLOCATE PREPARE stmt_add_column;
 
SET @default_profile_code := (
  SELECT COALESCE(MAX(TRIM(`value`)), 'default')
  FROM `sys_config`
  WHERE `code` = 'stationPathDefaultProfileCode'
);
 
UPDATE `asr_bas_station_path_profile`
SET `is_default` = 0;
 
UPDATE `asr_bas_station_path_profile`
SET `is_default` = 1
WHERE `profile_code` = @default_profile_code
  AND `status` = 1;
 
UPDATE `asr_bas_station_path_profile`
SET `is_default` = 1
WHERE `profile_code` = 'default'
  AND `status` = 1
  AND NOT EXISTS (
    SELECT 1
    FROM (
      SELECT `id`
      FROM `asr_bas_station_path_profile`
      WHERE `is_default` = 1
    ) t
  );
 
UPDATE `asr_bas_station_path_profile`
SET `is_default` = 1
WHERE `id` = (
  SELECT `id`
  FROM (
    SELECT `id`
    FROM `asr_bas_station_path_profile`
    WHERE `status` = 1
    ORDER BY `priority` ASC, `id` ASC
    LIMIT 1
  ) t
)
AND NOT EXISTS (
  SELECT 1
  FROM (
    SELECT `id`
    FROM `asr_bas_station_path_profile`
    WHERE `is_default` = 1
  ) t
);
 
DELETE FROM `sys_config`
WHERE `code` = 'stationPathDefaultProfileCode';