-- 升级协作任务编排字段，所有的历史数据默认 hpdi_taskrule
UPDATE T_HPDI_SALARYVERBILL SET FTASKARRANGECLASS = 'hpdi_taskrule', FTASKARRANGEID = FTASKRULEID,FTASKARRANGEVID = FTASKRULEVID WHERE (FTASKARRANGECLASS = ' ' OR FTASKARRANGECLASS IS NULL) AND FTASKRULEID != 0;

UPDATE T_HPDI_SINSURVERBILL SET FTASKARRANGECLASS = 'hpdi_taskrule', FTASKARRANGEID = FTASKRULEID,FTASKARRANGEVID = FTASKRULEVID WHERE (FTASKARRANGECLASS = ' ' OR FTASKARRANGECLASS IS NULL) AND FTASKRULEID != 0;

UPDATE T_HPDI_SUMMARYVBILL SET FTASKARRANGECLASS = 'hpdi_taskrule', FTASKARRANGEID = FTASKRULEID,FTASKARRANGEVID = FTASKRULEVID WHERE (FTASKARRANGECLASS = ' ' OR FTASKARRANGECLASS IS NULL) AND FTASKRULEID != 0;

UPDATE T_HPDI_TAXVERBILL SET FTASKARRANGECLASS = 'hpdi_taskrule', FTASKARRANGEID = FTASKRULEID,FTASKARRANGEVID = FTASKRULEVID WHERE (FTASKARRANGECLASS = ' ' OR FTASKARRANGECLASS IS NULL) AND FTASKRULEID != 0;

-- 升级关联协作任务中心字段数据
UPDATE T_HPDI_SALARYVERBILL SET FCOLLATASKCLASS = 'hpdi_taskcenter',FCOLLATASKID = FTASKCENTERID WHERE (FCOLLATASKCLASS = ' ' OR FCOLLATASKCLASS IS NULL) AND FTASKCENTERID != 0;

UPDATE T_HPDI_SINSURVERBILL SET FCOLLATASKCLASS = 'hpdi_taskcenter',FCOLLATASKID = FTASKCENTERID WHERE (FCOLLATASKCLASS = ' ' OR FCOLLATASKCLASS IS NULL) AND FTASKCENTERID != 0;

UPDATE T_HPDI_SUMMARYVBILL SET FCOLLATASKCLASS = 'hpdi_taskcenter',FCOLLATASKID = FTASKCENTERID WHERE (FCOLLATASKCLASS = ' ' OR FCOLLATASKCLASS IS NULL) AND FTASKCENTERID != 0;

UPDATE T_HPDI_TAXVERBILL SET FCOLLATASKCLASS = 'hpdi_taskcenter',FCOLLATASKID = FTASKCENTERID WHERE (FCOLLATASKCLASS = ' ' OR FCOLLATASKCLASS IS NULL) AND FTASKCENTERID != 0;

-- 升级薪酬核定单的关联协作规则历史版本分录表
INSERT INTO T_HPDI_SUMVBCRENT(FENTRYID,FID,FCOLLARULEVID,FSEQ,FCOLLARULEVCLASS)
SELECT FPKID AS FENTRYID,FID,FBASEDATAID AS FCOLLARULEVID, 0 AS FSEQ, 'hpdi_collarulesal' AS FCOLLARULEVCLASS  FROM T_HPDI_SUMVERPRACTG
WHERE FPKID NOT IN (
	SELECT FENTRYID FROM T_HPDI_SUMVBCRENT
);

-- 更新关联的协作规则和历史版本
UPDATE T_HPDI_TASKCENTERENT SET FCOLLARULECLASS = 'hpdi_collarulesal', FCOLLARULEID = FPAYROLLACTGID, FCOLLARULEVID = FPAYROLLACTGVID WHERE (FCOLLARULECLASS = ' ' OR FCOLLARULECLASS IS NULL) AND FPAYROLLACTGID != 0;

-- 汇总核定单 ftaskrulenid 字段和 ftaskcenternid 字段升级
update t_hpdi_summaryvbill set ftaskrulenid = ftaskarrangeid where ftaskarrangeclass = 'hpdi_taskarrange' and ftaskrulenid = 0 and ftaskarrangeid != 0;
update t_hpdi_summaryvbill set ftaskcenternid = fcollataskid where  ftaskarrangeclass = 'hpdi_taskarrange' and ftaskcenternid = 0 and fcollataskid != 0;
update t_hpdi_summaryvbill set ftaskruleid = ftaskarrangeid where ftaskarrangeclass = 'hpdi_taskrule' and ftaskruleid = 0 and ftaskarrangeid != 0;
update t_hpdi_summaryvbill set ftaskcenterid = fcollataskid where ftaskarrangeclass = 'hpdi_taskrule' and ftaskcenterid = 0 and fcollataskid != 0;
