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.C_JYRQ, ' ', b.C_JYSJ) as jysj
, b.C_YSDDH
, b.C_JYJE
, b.C_JYLX
, b.C_ZFFS
, b.C_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 hisbill_history where trade_date = #{trade_date} and payType!=#{cash_code}) a
inner join
(select * from bankbill_history where C_JYRQ = #{trade_date}) b
on a.PlatformTransId = b.C_YSDDH and a.TradingStatus = b.C_JYLX and a.Amount+0 = b.C_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.C_YSDDH
, b.C_JYJE
, b.C_JYLX
, b.C_ZFFS
, b.C_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 hisbill_history where trade_date = #{trade_date} and payType!=#{cash_code}) a
left join
(select * from bankbill_history where C_JYRQ = #{trade_date}) b
on a.PlatformTransId = b.C_YSDDH and a.TradingStatus = b.C_JYLX and a.Amount+0 = b.C_JYJE+0
where b.C_YSDDH 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.C_JYRQ, ' ', b.C_JYSJ) as jysj
, b.C_YSDDH
, b.C_JYJE
, b.C_JYLX
, b.C_ZFFS
, b.C_JYSJ
, a.HisTransId
, a.BizType
, a.TradingStatus
, a.Amount
, a.PayType
, a.HisOperCode
, a.PatientId
, a.PatientName
, b.C_JYSJ
, b.C_JYRQ
, '2'
, '1'
, '1'
from (select * from hisbill_history where trade_date = #{trade_date} and payType!=#{cash_code}) a
right join
(select * from bankbill_history where C_JYRQ = #{trade_date}) b
on a.PlatformTransId = b.C_YSDDH and a.TradingStatus = b.C_JYLX and a.Amount + 0 = b.C_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}
)