-- 创建唯一索引
create unique index uk_proc_task on EXT_AX_HI_TASKINST (proc_inst_id, task_id);

-- 清洗历史版本的审批日志数据
insert into ext_ax_hi_taskinst (proc_inst_id, task_id, task_definition_key, status, assignee)
select PROC_INST_ID_, ID_, TASK_DEF_KEY_, 'PROCESSING', ifnull(ASSIGNEE_, '') as ASSIGNEE_
from act_hi_taskinst
where END_TIME_ is null
  and ID_ not in (select distinct task_id from ext_ax_hi_taskinst);


-- 清洗发起人数据
insert into ext_ax_hi_taskinst (proc_inst_id, task_id, task_definition_key, status, assignee)
select PROC_INST_ID_, ID_, TASK_DEF_KEY_, 'APPROVED', ifnull(ASSIGNEE_, '') as ASSIGNEE_
from act_hi_taskinst
where PROC_INST_ID_ in (select PROC_INST_ID_ from act_hi_taskinst)
  and TASK_DEF_KEY_ = 'NODE_STARTER'
  and ID_ not in (select task_id from ext_ax_hi_taskinst where task_definition_key = 'NODE_STARTER');

