/*社保代办理 1.派单审核通过 2.派增(type=0):待办理(social_handle_status='0') or 派减(type=1):已办理完成或部分办理失败 且已派减*/
AND a.social_id is not null
AND a.STATUS = "2"
and (( a.type = '0' AND (s.HANDLE_STATUS = "0" or s.HANDLE_STATUS = "4") ) or ( a.type ='1' AND (if(ifnull(h.id,0) != '0',h.HANDLE_STATUS,s.HANDLE_STATUS) in ('1','5','6','3','7') or (s.HANDLE_STATUS in ('1','5','6','3','7') and s.REDUCE_CAN = '1')) ))
case a.SOCIAL_HANDLE_STATUS when '0' then '未办理' when '1' then '全部办理成功' when '2' then '全部办理失败' when '3' then '部分办理成功' when '4' then '办理中' else '-' end socialHandleStatus,
case s.ygs_Handle_Status when '0' then '无' when '1' then '待办理' when '2' then '自动办理中' when '3' then '继续办理' when '4' then '中止办理' when '5' then '人工处理' when '6' then '成功' else '-' end ygsHandleStatus,
case s.ysd_Handle_Status when '0' then '无' when '1' then '待办理' when '2' then '自动办理中' when '3' then '继续办理' when '4' then '中止办理' when '5' then '人工处理' when '6' then '成功' else '-' end ysdHandleStatus,
/*社保代办理 1.派单审核通过 2.派增(type=0):待办理(social_handle_status='0') or 派减(type=1):已办理完成或部分办理失败 且已派减*/
AND a.social_id is not null
AND a.STATUS = "2"
and (( a.type = '0' AND (s.HANDLE_STATUS = "0" or s.HANDLE_STATUS = "4") ) or ( a.type ='1' AND (if(ifnull(h.id,0) != '0',h.HANDLE_STATUS,s.HANDLE_STATUS) in ('1','5','6','3','7') or (s.HANDLE_STATUS in ('1','5','6','3','7') and s.REDUCE_CAN = '1')) ))