--整体报送状态
 insert into ur_task_dw_total (
 TASK_ID, PERD_CODE, DW_ID, 
 TRUNC_ID , PROJ_ID, RPT_STATUS , 
 CUR_DW_ID, CUR_MAN_DW_ID, L_DO_USER_ID , 
 L_DO_DATE, RPT_USER_ID, RPT_DATE , 
 RPT_DW_ID, L_ADT_USER_ID, L_ADT_DATE ,
 L_ADT_NODE , CUR_ADT_NODE , LOG_NO , 
 TRANS_DW_LOG_NO, IS_RETURN, IS_REGAIN, 
 IS_A_RETURN, A_RETURN_DW_ID , A_RETURN_USER_ID , 
 A_RETURN_REASON, A_RETURN_TIME) 
 select 
 TASK_ID, PERD_CODE, DW_ID, 
 TRUNC_ID , '*' as PROJ_ID, min(RPT_STATUS) as  RPT_STATUS, 
 min(CUR_MAN_DW_ID) as CUR_DW_ID, min(CUR_MAN_DW_ID) as CUR_MAN_DW_ID, min(L_DO_USER_ID) as  L_DO_USER_ID, 
 min(L_DO_DATE) as L_DO_DATE, min(RPT_USER_ID) as RPT_USER_ID, min(RPT_DATE) as RPT_DATE, 
 min(RPT_DW_ID) as RPT_DW_ID, min(L_ADT_USER_ID) as L_ADT_USER_ID, min(L_ADT_DATE) as L_ADT_DATE,
 min(L_ADT_NODE) as L_ADT_NODE, min(CUR_ADT_NODE) as CUR_ADT_NODE, max(LOG_NO) as LOG_NO, 
 min(TRANS_DW_LOG_NO) as TRANS_DW_LOG_NO, max(IS_RETURN) as IS_RETURN, max(IS_REGAIN) as IS_REGAIN, 
 max(IS_A_RETURN) as IS_A_RETURN, min(A_RETURN_DW_ID) as A_RETURN_DW_ID , min(A_RETURN_USER_ID) as A_RETURN_USER_ID , 
 min(A_RETURN_REASON) as A_RETURN_REASON, min(A_RETURN_TIME) as A_RETURN_TIME 
 from ur_task_dw td 
 where ((exists (select task_id from ur_task_rpt tr,ur_rpt r
    where tr.rpt_id=r.rpt_id and tr.task_id=td.task_id and r.RPT_TYPE<>'C' and r.IS_DETAIL='0')
 and td.proj_id='*') or exists (select task_id from ur_task_rpt tr,ur_rpt r
    where tr.rpt_id=r.rpt_id and tr.task_id=td.task_id and r.RPT_TYPE='C' and r.IS_ONE_ROW='0')) 
 and not exists (select * from ur_task_dw_total tdt 
    where tdt.TASK_ID=td.TASK_ID and tdt.PERD_CODE=td.PERD_CODE and tdt.DW_ID=td.DW_ID and tdt.TRUNC_ID=td.TRUNC_ID)
 group by TASK_ID, PERD_CODE, DW_ID, TRUNC_ID;
 
 
--自动调度
alter table UR_SYS_SCHEDULE add LAST_REF_RESULT varchar2(3700);