insert into third_join_his( JYSJ, I_DDH, I_JYJE, I_JYLX, I_JYQD, TradeTime, TranID, BizType, H_JYLX, Amount , PayType , HisOperNum, PatientID, PatientName , sort_date, trade_date, err_type, check_result, is_active) select concat(b.I_JYRQ, ' ', b.I_JYSJ) as jysj , b.I_DDH , b.I_JYJE , b.I_JYLX , b.I_FXK , b.I_JYSJ , a.PlatformTransId , a.BizType , a.TradingStatus , a.Amount , a.PayType , a.HisOperCode , a.PatientID , a.PatientName , a.TradeTime , a.trade_date , '' , '0' , '1' from (select * from hisbills_history where trade_date = #{trade_date}) a inner join (select * from bankbills_history where I_JYRQ = #{trade_date}) b on a.PlatformTransId = b.I_DDH and a.TradingStatus = b.I_JYLX and a.Amount+0 = b.I_JYJE+0 insert into third_join_his( JYSJ, I_DDH, I_JYJE, I_JYLX, I_JYQD, TradeTime, TranID, BizType, H_JYLX, Amount , PayType , HisOperNum, PatientID, PatientName , sort_date, trade_date, err_type, check_result, is_active) select a.TradeTime as jysj , b.I_DDH , b.I_JYJE , b.I_JYLX , b.I_FXK , b.I_JYSJ , a.PlatformTransId , a.BizType , a.TradingStatus , a.Amount , a.PayType , a.HisOperCode , a.PatientID , a.PatientName , a.TradeTime , a.trade_date , '1' , '1' , '1' from (select * from hisbills_history where trade_date = #{trade_date}) a left join (select * from bankbills_history where I_JYRQ = #{trade_date}) b on a.PlatformTransId = b.I_DDH and a.TradingStatus = b.I_JYLX and a.Amount+0 = b.I_JYJE+0 where b.I_DDH is null insert into third_join_his( JYSJ, I_DDH, I_JYJE, I_JYLX, I_JYQD, TradeTime, TranID, BizType, H_JYLX, Amount , PayType , HisOperNum, PatientID, PatientName , sort_date, trade_date, err_type, check_result, is_active) select concat(b.I_JYRQ, ' ', b.I_JYSJ) as jysj , b.I_DDH , b.I_JYJE , b.I_JYLX , b.I_FXK , b.I_JYSJ , a.HisTransId , a.BizType , a.TradingStatus , a.Amount , a.PayType , a.HisOperCode , a.PatientID , a.PatientName , b.I_JYSJ , b.I_JYRQ , '2' , '1' , '1' from (select * from hisbills_history where trade_date = #{trade_date}) a right join (select * from bankbills_history where I_JYRQ = #{trade_date}) b on a.PlatformTransId = b.I_DDH and a.TradingStatus = b.I_JYLX and a.Amount + 0 = b.I_JYJE + 0 where a.PlatformTransId is null insert into third_join_his(jysj, c_ysddh, c_jyje, c_zffs, c_jylx, czyh, paymethod, tradingstatus, biztype, paytype, tradetime, hisopercode, amount, platformtransid, patientid, patientname, sort_date, trade_date, err_type, check_result, is_active) select b.trade_date , '' , b.jyje , #{cash_code} , '' , b.czyh , a.PayMethod , a.TradingStatus , a.BizType , a.PayType , a.TradeTime , a.HisOperCode , a.Amount , a.PlatformTransId , a.patientid , a.patientname , b.trade_date , b.trade_date , '' , '0' , '1' from (select * from hisbill_history where trade_date = #{trade_date} and payType = #{cash_code}) a inner join (select * from cash_record where trade_date = #{trade_date}) b on a.HisOperCode = b.czyh insert into third_join_his(jysj, c_ysddh, c_jyje, c_zffs, c_jylx, czyh, paymethod, tradingstatus, biztype, paytype, tradetime, hisopercode, amount, platformtransid, patientid, patientname, sort_date, trade_date, err_type, check_result, is_active) select b.trade_date , '' , b.jyje , #{cash_code} , '' , b.czyh , a.PayMethod , a.TradingStatus , a.BizType , a.PayType , a.TradeTime , a.HisOperCode , a.Amount , a.PlatformTransId , a.patientid , a.patientname , a.trade_date , a.trade_date , '1' , '1' , '1' from (select * from hisbill_history where trade_date = #{trade_date} and payType = #{cash_code}) a left join (select * from cash_record where trade_date = #{trade_date}) b on a.HisOperCode = b.czyh where b.czyh is null insert into third_join_his(jysj, c_ysddh, c_jyje, c_zffs, c_jylx, czyh, paymethod, tradingstatus, biztype, paytype, tradetime, hisopercode, amount, platformtransid, patientid, patientname, sort_date, trade_date, err_type, check_result, is_active) select b.trade_date , '' , b.jyje , #{cash_code} , '' , b.czyh , a.PayMethod , a.TradingStatus , a.BizType , a.PayType , a.TradeTime , a.HisOperCode , a.Amount , a.PlatformTransId , a.patientid , a.patientname , b.trade_date , b.trade_date , '2' , '1' , '1' from (select * from hisbill_history where trade_date = #{trade_date} and payType = #{cash_code}) a right join (select * from cash_record where trade_date = #{trade_date}) b on a.HisOperCode = b.czyh where a.HisOperCode is null update third_join_his set err_type='3', check_result='1' where trade_date = #{trade_date} and check_result = '0' and (I_JYJE + 0) != (Amount + 0) delete from third_join_his where trade_date = #{trade_date} insert into third_join_his(jysj, c_ysddh, c_jyje, c_zffs, c_jylx, paymethod, tradingstatus, biztype, paytype, tradetime, hisopercode, amount, platformtransid, patientid, patientname, sort_date, trade_date, err_type, check_result) values (#{jysj}, #{c_ysddh}, #{c_jyje}, #{c_zffs}, #{c_jylx}, #{paymethod}, #{tradingstatus}, #{biztype}, #{paytype}, #{tradetime}, #{hisopercode}, #{amount}, #{platformtransid}, #{patientid}, #{patientname}, #{sort_date}, #{trade_date}, #{err_type}, #{check_result}) update third_join_his set check_result=#{check_result} and TranID=#{tranID} and H_JYLX=#{h_jylx} and I_DDH=#{i_ddh} and I_JYLX=#{i_jylx} update third_join_his set is_active=#{is_active} where I_DDH = #{i_ddh} and I_JYLX = #{i_jylx} update third_join_his set is_active=#{is_active} where TranID = #{tranID} and H_JYLX = #{h_jylx} update third_join_his set is_active=#{is_active} where czyh = #{hisOperCode} and trade_date = #{trade_date} and C_ZFFS = #{c_zffs} update third_join_his set is_active=#{is_active} where HisOperCode = #{hisOperCode} and trade_date = #{trade_date} and PayType = #{payType} and payMethod = #{payMethod} update third_join_his set is_active=#{is_active} where HisOperCode = #{hisOperCode} and trade_date = #{trade_date} and PayType = #{payType} and payMethod = #{payMethod} delete from third_join_his where trade_date = #{trade_date} and TranID = #{tranID} and H_JYLX = #{h_jylx} insert into third_join_his(JYSJ ,I_DDH ,I_JYJE ,I_JYLX ,I_JYQD ,TradeTime ,TranID ,BizType ,H_JYLX ,Amount ,PayType ,HisOperNum ,PatientID ,PatientName ,sort_date ,trade_date ,err_type ,check_result ,is_active ,join_id ) values ( #{itm.jysj}, #{itm.i_ddh}, #{itm.i_jyje}, #{itm.i_jylx}, #{itm.i_jyqd}, #{itm.tradeTime}, #{itm.tranID}, #{itm.BizType}, #{itm.h_jylx}, #{itm.amount}, #{itm.payType}, #{itm.hisOperNum}, #{itm.patientid}, #{itm.patientname}, #{itm.sort_date}, #{itm.trade_date}, #{itm.err_type}, #{itm.check_result}, #{itm.is_active}, #{itm.join_id} )