Commit 06160762 by 杨卫

```

feat(strategy): 添加督导带教审批数据迁移脚本

- 更新策略人员关系表中的关系类型字段
- 插入历史带教申请的指定督导数据到人员关系表
- 处理宽表扩展字段的数据迁移和去重保护
- 添加NOT EXISTS条件防止重复数据插入
- 实现字符串空串转NULL的字段处理逻辑
```
1 parent f195b4bf
......@@ -149,4 +149,79 @@ WHERE strategy_id IN (
UPDATE dj_car_life_strategy_info
SET deleted_flag = 'D', updated_date = NOW()
WHERE strategy_type = 8 AND push_flag != 6;
-- 督导带教审批数据迁移,不包含课程,课程如果有需要手动从json里面提取
-- 人员表数据处理
update dj_car_life_strategy_staff_rel t1
join dj_car_life_strategy_info t2 on t1.strategy_id =
t2.id
set t1.rel_type = 2
where t2.deleted_flag = 'N'
and t1.deleted_flag = 'N'
and t2.strategy_type = 8
and t1.rel_type is null;
-- 历史带教申请:插入指定督导 rel_type=MENTOR(1),岗位固定飞行督导(99)
insert into dj_car_life_strategy_staff_rel
(user_uuid, user_name, user_phone, strategy_id,
user_position, rel_type, created_by, created_date,
deleted_flag)
select t1.assigned_supervisor_uuid,
t1.assigned_supervisor_name,
t1.assigned_supervisor_phone,
t2.id,
99,
1,
'system',
now(),
'N'
from supervisor_special_coach_approval t1
join dj_car_life_strategy_info t2 on t1.source_id = t2.id
join task t3 on t1.task_center_id = t3.task_id
where t1.biz_type = 'MENTORING_APPLICATION'
and t1.deleted_flag = 'N'
and t1.approval_status = 1
and t2.deleted_flag = 'N'
and t2.strategy_type = 8
and not exists (
select 1 from dj_car_life_strategy_staff_rel r
where r.strategy_id = t2.id
and r.rel_type = 1
and r.deleted_flag = 'N'
);
-- 宽表数据处理
-- 历史带教申请:插入宽表扩展字段
-- 新增 NOT EXISTS 守卫,防止重跑/新流程(doSaveExtension)已建宽表时重复插入
insert into dj_car_life_strategy_extension
(mentoring_method, mentoring_scene,
mentoring_topic, mentoring_date, strategy_id,
completed_date, created_by, created_date, deleted_flag)
select
-- 字符串空串转为NULL,给int字段
NULLIF(t1.teaching_method_code, ''),
NULLIF(t1.teaching_scene_code, ''),
NULLIF(t1.teaching_topic_code, ''),
DATE_FORMAT(t1.teaching_time, '%Y-%m-%d'),
t2.id,
NULLIF(t3.complete_time, ''),
'system',
now(),
'N'
from supervisor_special_coach_approval t1
join dj_car_life_strategy_info t2 on t1.source_id = t2.id
join task t3 on t1.task_center_id = t3.task_id
where t1.biz_type = 'MENTORING_APPLICATION'
and t1.deleted_flag = 'N'
and t1.approval_status = 1
and t2.deleted_flag = 'N'
and t2.strategy_type = 8
and not exists (
select 1 from dj_car_life_strategy_extension e
where e.strategy_id = t2.id
and e.deleted_flag = 'N'
);
### 杨卫 ---------------end--------------------------------
\ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!