-- step1 将单据上的 billstatus 值 值修改为 auditstatus(避免憨憨删除执行记录重复冲了数据 , 这里where billStatus= ' ')
UPDATE t_hdm_regbasebill
SET fbillstatus = fauditstatus
WHERE fbillstatus = ' ';

-- step2 如果billStatus为暂存 auditStatus 一定为暂存
UPDATE t_hdm_regbasebill
SET fauditstatus = 'A'
WHERE fbillstatus = 'A';

-- step3 如果billStatus为已提交 auditStatus 一定为已提交
-- billStatus 为审批中或者审批不通过 则 auditStatus 也为已提交
UPDATE t_hdm_regbasebill
SET fauditstatus = 'B'
WHERE fbillstatus = 'B'
   OR fbillstatus = 'D'
   OR fbillstatus = 'E';

-- step5 如果billStatus为审批通过 AND 有终止信息 auditStatus 一定为 已废弃
UPDATE t_hdm_regbasebill
SET fauditstatus = 'F'
WHERE fbillstatus = 'C';
-- AND fid in (SELECT t_hdm_regbasebill_a.fid FROM t_hdm_regbasebill_a WHERE ftermuserid != 0);
   
-- step4 如果billStatus为审批通过 AND 无终止信息 auditStatus 一定为 已审核
UPDATE t_hdm_regbasebill
SET fauditstatus = 'C'
WHERE fbillstatus = 'C'
  AND fid in (SELECT t_hdm_regbasebill_a.fid FROM t_hdm_regbasebill_a WHERE ftermuserid = 0);


-- step6 已废弃对应已废弃
UPDATE t_hdm_regbasebill
SET fauditstatus = 'F'
WHERE fbillstatus = 'F';