liusheng
5 天以前 fb89df539c6293a41933e445df25fa9b8047ba18
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
-- ============================================================================
-- smartor_sltd 数据库:语音问题相关表的列名对齐 / 新增列脚本
-- 生成日期: 20260928
-- 目标库  : smartor_sltd(ruoyi-admin/src/main/resources/application-druid.yml,profile=druid)
-- 目的    : 让 ivr_liba_template_script / ivr_task_template_script 的列名与
--           IvrLibaTemplateScriptMapper.xml / IvrTaskTemplateScriptMapper.xml 一致
--           (这两个 mapper 里查的是 script_assortname、script_assortid)
--
-- 【执行前实测现状(20260928,smartor_sltd)】
--   ivr_liba_script_assort   : 35 行
--       index_assort_name varchar(255) NOT NULL  注释“指标分类名称”
--       type              varchar(255) NULL      ← 该列【已存在】,35 行全为 NULL,无注释
--   ivr_liba_template_script : 121 行(del_flag=0 的 54 行)
--       categoryName varchar(50) NULL  注释“类别名”,121 行全为 NULL
--       没有 assortid 列,也没有 script_assortid 列
--   ivr_task_template_script : 1221 行
--       categoryName varchar(50) NULL  注释“类别名”,仅 26 行非空
--       没有 assortid 列,也没有 script_assortid 列
--
--   ⇒ 第 3 项(assortid → script_assortid)在这两个表里都不是“改名”,
--     两个表根本没有 assortid 列,只能“新增列 + 回填”。
--   ⇒ 回填来源用父模板的 assortid:
--        ivr_liba_template_script.templateid → ivr_liba_template.id.assortid        (121/121 行可回填)
--        ivr_task_template_script.templateID → ivr_task_template.id.assortid        (358/1221 行可回填;
--          另 825 行 templateID 在 ivr_task_template 中不存在、38 行 templateID 为 NULL,保持 NULL)
--   ⇒ 依赖检查:本库没有引用这两张表的存储过程 / 视图 / 触发器(已查
--      information_schema.ROUTINES / VIEWS / TRIGGERS,均为 0 条),改列名不影响 DB 侧对象。
--   ⇒ 代码侧影响:IvrLibaTemplateScriptMapper、IvrTaskTemplateScriptMapper 本来就在用
--      script_assortname / script_assortid,改完后这两个 mapper 才真正能查通;
--      两个 mapper 都没有引用 categoryName,所以改名不会影响现有功能。
-- ============================================================================
 
 
-- ----------------------------------------------------------------------------
-- 【0】执行前检查(确认与上面的实测一致,正常应看到 categoryName、且没有 assort 列)
-- ----------------------------------------------------------------------------
-- SHOW COLUMNS FROM ivr_liba_template_script LIKE '%assort%';
-- SHOW COLUMNS FROM ivr_liba_template_script LIKE 'categoryName';
-- SHOW COLUMNS FROM ivr_task_template_script LIKE 'categoryName';
-- SHOW COLUMNS FROM ivr_liba_script_assort LIKE 'type';
-- SELECT COUNT(*) FROM ivr_liba_template_script;      -- 121
-- SELECT COUNT(*) FROM ivr_task_template_script;      -- 1221
 
 
-- ----------------------------------------------------------------------------
-- 【1】categoryName → script_assortname(两张表,保留原类型 varchar(50) NULL 和原注释“类别名”)
--      121 / 1221 行的小表,秒级完成;CHANGE COLUMN 只改名可走 INPLACE,不阻塞读写。
-- ----------------------------------------------------------------------------
ALTER TABLE ivr_liba_template_script
    CHANGE COLUMN categoryName script_assortname varchar(50) NULL COMMENT '类别名',
    ALGORITHM = INPLACE,
    LOCK = NONE;
 
ALTER TABLE ivr_task_template_script
    CHANGE COLUMN categoryName script_assortname varchar(50) NULL COMMENT '类别名',
    ALGORITHM = INPLACE,
    LOCK = NONE;
 
 
-- ----------------------------------------------------------------------------
-- 【2】ivr_liba_script_assort.type
--      该列本来就有(varchar(255),无注释,35 行全 NULL),这里只按需求补注释并把长度改成 100。
--      注意:varchar(255) → varchar(100) 属于类型收窄,需要重建表,不能用 INPLACE/LOCK=NONE;
--      本表只有 35 行,直接执行即可(若不想动长度,只执行带 COMMENT 的 MODIFY 也一样需要重建,
--      因为改注释本身就是 COPY)。若只想加注释、不改长度,把 varchar(100) 换成 varchar(255)。
-- ----------------------------------------------------------------------------
ALTER TABLE ivr_liba_script_assort
    MODIFY COLUMN type varchar(100) NULL COMMENT '问题类型(例如,门诊满意度:mzmyd     住院满意度:zymyd  ...)';
 
 
-- ----------------------------------------------------------------------------
-- 【3】新增 script_assortid 列 + 用父模板的 assortid 回填
--      备注里原本写的“ivr_liba_script_ssort”应为“ivr_liba_script_assort”,下面按正确表名写。
-- ----------------------------------------------------------------------------
ALTER TABLE ivr_liba_template_script
    ADD COLUMN script_assortid int(11) NULL COMMENT '语音问题类别ID(对应的是ivr_liba_script_assort)',
    ALGORITHM = INPLACE,
    LOCK = NONE;
 
ALTER TABLE ivr_task_template_script
    ADD COLUMN script_assortid int(11) NULL COMMENT '语音问题类别ID(对应的是ivr_liba_script_assort)',
    ALGORITHM = INPLACE,
    LOCK = NONE;
 
-- 回填:121/121 行
UPDATE ivr_liba_template_script s
    JOIN ivr_liba_template t ON t.id = s.templateid
SET s.script_assortid = t.assortid;
 
-- 回填:358/1221 行(其余为孤儿数据,保持 NULL)
UPDATE ivr_task_template_script s
    JOIN ivr_task_template t ON t.id = s.templateID
SET s.script_assortid = t.assortid;
 
 
-- ----------------------------------------------------------------------------
-- 【4】可选:把 script_assortname 也补上(当前两表的 categoryName 基本全是 NULL,
--      改名后 script_assortname 仍是 NULL,而 satisfactionGraph 的语音分支是按
--      script_assortname 分组的,不补的话语音分类仍然出不来)
--      数据源:父模板 assortid → ivr_liba_script_assort.index_assort_name
--      确认要补再执行这段;不需要就跳过。
-- ----------------------------------------------------------------------------
-- UPDATE ivr_liba_template_script s
--     JOIN ivr_liba_template t ON t.id = s.templateid
--     JOIN ivr_liba_script_assort a ON a.id = t.assortid
-- SET s.script_assortname = a.index_assort_name
-- WHERE s.script_assortname IS NULL OR s.script_assortname = '';
--
-- UPDATE ivr_task_template_script s
--     JOIN ivr_task_template t ON t.id = s.templateID
--     JOIN ivr_liba_script_assort a ON a.id = t.assortid
-- SET s.script_assortname = a.index_assort_name
-- WHERE s.script_assortname IS NULL OR s.script_assortname = '';
 
 
-- ----------------------------------------------------------------------------
-- 【5】可选:给 ivr_liba_script_assort.type 填值(当前 35 行全 NULL,
--      而代码里 mydIdList 是按 type 含 "myd" 过滤的,不填值语音分支就永远是 0 个分类)
--      填值口径需要业务确认,下面只是按现有分类名给的示例,确认后再执行:
--        满意度相关(如 id=12 满意度调查、id=9 服务评价)→ mzmyd / zymyd
--        其余分类                                            → 留空或按业务自定义
--      (本库 ivr_liba_script_assort 里的分类名:未分类/患者信息/体征/疾病/症状/生活方式/
--        用药依从性/不良反应/通知提醒/服务评价/检查类/检验类/满意度调查/膳食类/运动类/睡眠类/
--        抽烟喝酒/身高/体重/视力/听力/意见建议/检验检查类/随访指标/身份确认/复诊通知/复查通知/
--        是否方便/出院宣教/修养地/语音题目/语音题目测试 …)
-- ----------------------------------------------------------------------------
-- UPDATE ivr_liba_script_assort SET type = 'zymyd' WHERE id = 12;   -- 例:满意度调查
-- UPDATE ivr_liba_script_assort SET type = 'mzmyd' WHERE id = 9;    -- 例:服务评价
 
 
-- ----------------------------------------------------------------------------
-- 【6】验证
-- ----------------------------------------------------------------------------
-- SHOW COLUMNS FROM ivr_liba_template_script LIKE '%assort%';
-- SHOW COLUMNS FROM ivr_task_template_script LIKE '%assort%';
-- SHOW COLUMNS FROM ivr_liba_script_assort LIKE 'type';
-- SELECT COUNT(*) AS liba_script_rows, SUM(script_assortid IS NULL) AS assortid_null FROM ivr_liba_template_script;      -- 期望 121 / 0
-- SELECT COUNT(*) AS task_script_rows, SUM(script_assortid IS NULL) AS assortid_null FROM ivr_task_template_script;      -- 期望 1221 / 863
 
 
-- ----------------------------------------------------------------------------
-- 【7】回滚
-- ----------------------------------------------------------------------------
-- ALTER TABLE ivr_liba_template_script CHANGE COLUMN script_assortname categoryName varchar(50) NULL COMMENT '类别名';
-- ALTER TABLE ivr_task_template_script CHANGE COLUMN script_assortname categoryName varchar(50) NULL COMMENT '类别名';
-- ALTER TABLE ivr_liba_template_script DROP COLUMN script_assortid;
-- ALTER TABLE ivr_task_template_script DROP COLUMN script_assortid;
-- ALTER TABLE ivr_liba_script_assort MODIFY COLUMN type varchar(255) NULL COMMENT '';