Files
dzpt/src/main/resources/mapper/HisDetailMapper.xml

320 lines
13 KiB
XML
Raw Normal View History

2025-07-23 09:55:50 +08:00
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.saye.hospitalgd.mapper.HisDetailMapper">
<select id="findHisDetail" parameterType="HashMap" resultType="HashMap">
2025-08-21 10:00:57 +08:00
select PayMethod
2025-07-23 09:55:50 +08:00
,TradingStatus
,BizType
,PayType
,TradeTime
2025-08-21 10:00:57 +08:00
,HisOperCode
2025-07-23 09:55:50 +08:00
,Amount
2025-08-21 10:00:57 +08:00
,remarks
2025-07-23 09:55:50 +08:00
,PlatformTransId
2025-08-21 10:00:57 +08:00
,PatientId
2025-07-23 09:55:50 +08:00
,PatientName
,trade_date
2025-08-21 10:00:57 +08:00
,his_wsdl_id
,HisTransId
2025-10-27 08:49:28 +08:00
,clr_type
,insutype
,ybzhAmount
,ybtcAmount
2025-08-21 10:00:57 +08:00
from hisbill_history
2025-07-23 09:55:50 +08:00
<where>
<if test="payTypeList != null and payTypeList.size() > 0">
and PayType in
<foreach collection="payTypeList" item="pt" open="(" separator="," close=")">
#{pt}
</foreach>
</if>
<if test="(payTypeList == null or payTypeList.size() == 0) and payType!=null and payType!=''">
2025-07-23 09:55:50 +08:00
and PayType = #{payType}
</if>
2025-12-07 11:46:49 +08:00
<if test="bizType!=null and bizType!=''">
and BizType = #{bizType}
</if>
2025-07-23 09:55:50 +08:00
<if test="startTime!=null and startTime!=''">
and trade_date &gt;= #{startTime}
</if>
<if test="endTime!=null and endTime!=''">
and trade_date &lt;= #{endTime}
</if>
<if test="likeFiled!=null and likeFiled!=''">
and PlatformTransId like concat('%',concat(#{likeFiled},'%'))
</if>
</where>
order by trade_date,TradeTime
</select>
2025-08-21 10:00:57 +08:00
<!-- 添加一个明确的count查询避免分页插件的自动生成问题 -->
<select id="findHisDetailCount" parameterType="HashMap" resultType="long">
select count(1)
from hisbill_history
<where>
<if test="payTypeList != null and payTypeList.size() > 0">
and PayType in
<foreach collection="payTypeList" item="pt" open="(" separator="," close=")">
#{pt}
</foreach>
</if>
<if test="(payTypeList == null or payTypeList.size() == 0) and payType!=null and payType!=''">
2025-08-21 10:00:57 +08:00
and PayType = #{payType}
</if>
2025-12-07 11:46:49 +08:00
<if test="bizType!=null and bizType!=''">
and BizType = #{bizType}
</if>
2025-08-21 10:00:57 +08:00
<if test="startTime!=null and startTime!=''">
and trade_date &gt;= #{startTime}
</if>
<if test="endTime!=null and endTime!=''">
and trade_date &lt;= #{endTime}
</if>
<if test="likeFiled!=null and likeFiled!=''">
and PlatformTransId like concat('%',concat(#{likeFiled},'%'))
</if>
</where>
</select>
2025-10-30 17:21:43 +08:00
<!-- 查询有自费金额的HIS账单记录 -->
<select id="findHisDetailWithZfAmount" parameterType="HashMap" resultType="HashMap">
select
PayMethod,
TradingStatus,
BizType,
PayType,
TradeTime,
HisOperCode,
Amount,
zfAmount,
PlatformTransId,
PatientId,
PatientName,
trade_date,
his_wsdl_id,
HisTransId,
clr_type,
insutype,
ybzhAmount,
ybtcAmount
from hisbill_history
<where>
<if test="trade_date!=null and trade_date!=''">
and trade_date = #{trade_date}
</if>
<if test="has_zf_amount!=null and has_zf_amount!=''">
and zfAmount is not null
and zfAmount != ''
and zfAmount != '0'
and zfAmount != '0.00'
and ABS(CAST(zfAmount AS DECIMAL(18,2))) > 0
</if>
</where>
order by TradeTime, PlatformTransId
</select>
2025-07-23 09:55:50 +08:00
<delete id="deleteHisBillOriginalByParam" parameterType="HashMap">
delete from hisbill_original where trade_date=#{trade_date}
</delete>
<delete id="deleteHisBillOriginalWNByParam" parameterType="HashMap">
delete from hisbill_original_wn where trade_date=#{trade_date}
</delete>
<delete id="deleteHisBillOriginalHYByParam" parameterType="HashMap">
delete from hisbill_original_hy where trade_date=#{trade_date}
</delete>
<delete id="deleteHisBillByParam" parameterType="HashMap">
delete from hisbill_history where trade_date=#{trade_date}
</delete>
<insert id="insertAllHisBillOriginal" parameterType="java.util.List">
insert into
hisbill_original(PayMethod,TradingStatus,BizType,PayType,TradeTime,HisOperCode,Amount,remarks,PlatformTransId,PatientId,PatientName,trade_date,his_wsdl_id)
values
<foreach collection="list" index="index" item="itm" separator=",">
(
#{itm.payMethod},#{itm.tradingStatus},#{itm.bizType},#{itm.payType},#{itm.tradeTime},#{itm.hisOperCode},#{itm.amount},
#{itm.remarks},#{itm.platformTransId},#{itm.patientId},#{itm.patientName},#{itm.trade_date},#{itm.his_wsdl_id}
)
</foreach>
</insert>
<insert id="insertAllHisBillOriginalWN" parameterType="java.util.List">
insert into hisbill_original_wn(sjlx, hzxm, patid, jyje, tyje, zflsh, jyrq, sftkjl, zffs, jylx, czyh,
trade_date, his_wsdl_id)
values
<foreach collection="list" index="index" item="itm" separator=",">
(
#{itm.sjlx},#{itm.hzxm},#{itm.patid},#{itm.jyje},#{itm.tyje},#{itm.zflsh},#{itm.jyrq},
#{itm.sftkjl},#{itm.zffs},#{itm.jylx},#{itm.czyh},#{itm.trade_date},#{itm.his_wsdl_id}
)
</foreach>
</insert>
<insert id="insertAllHisBillOriginalHY" parameterType="java.util.List">
insert into
2025-10-27 08:49:28 +08:00
hisbill_original_hy(VisitzOrg,BizType,PayType,Amount,ZFAmount,YBZHAmount,YBTCAmount,Receipt_no,PatientID,PatientName,TradeTime,HisTime,HisOperNum,PowerTranID,trade_date,clr_type,insutype)
2025-07-23 09:55:50 +08:00
values
<foreach collection="list" index="index" item="itm" separator=",">
(
#{itm.visitzOrg},#{itm.bizType},#{itm.payType},#{itm.amount},#{itm.zfAmount},#{itm.ybzhAmount},#{itm.ybtcAmount},
2025-10-27 08:49:28 +08:00
#{itm.receiptNO},#{itm.patientID},#{itm.patientName},#{itm.tradeTime},#{itm.hisTime},#{itm.hisOperNum},#{itm.powerTranID},#{itm.trade_date},
#{itm.clrType},#{itm.insutype}
2025-07-23 09:55:50 +08:00
)
</foreach>
</insert>
2025-08-21 10:00:57 +08:00
2025-07-23 09:55:50 +08:00
<insert id="insertAllHisBillHistory" parameterType="java.util.List">
insert into
2025-10-30 17:21:43 +08:00
hisbill_history(PayMethod,TradingStatus,BizType,PayType,TradeTime,HisOperCode,Amount,remarks,PlatformTransId,PatientId,PatientName,trade_date,his_wsdl_id,HisTransId,clr_type,insutype,ybzhAmount,ybtcAmount,zfAmount)
2025-07-23 09:55:50 +08:00
values
<foreach collection="list" index="index" item="itm" separator=",">
(
#{itm.payMethod},#{itm.tradingStatus},#{itm.bizType},#{itm.payType},#{itm.tradeTime},#{itm.hisOperCode},#{itm.amount},#{itm.remarks},#{itm.platformTransId},#{itm.patientId}
2025-10-30 17:21:43 +08:00
,#{itm.patientName},#{itm.trade_date},#{itm.his_wsdl_id},#{itm.hisTransId},#{itm.clrType},#{itm.insutype},#{itm.ybzhAmount},#{itm.ybtcAmount},#{itm.zfAmount}
2025-07-23 09:55:50 +08:00
)
</foreach>
</insert>
<delete id="deleteTempTable">
delete from temp_hisbill_history
</delete>
<insert id="findHisDetailToTemp" parameterType="HashMap">
insert into temp_hisbill_history
select a.PayMethod,a.TradingStatus,a.BizType,a.PayType,a.TradeTime,a.HisOperCode,a.Amount,a.remarks,a.PlatformTransId,a.PatientId,a.PatientName,a.trade_date,a.his_wsdl_id
from hisbill_history a
left join (select PlatformTransId from hisbill_history where TradingStatus='2' and trade_date=#{trade_date}) b
on a.PlatformTransId=b.PlatformTransId
where a.trade_date=#{trade_date} and b.PlatformTransId is null and a.PayType!='5'
</insert>
<select id="findHisDetailByParam" parameterType="HashMap" resultType="HashMap">
2025-08-21 10:00:57 +08:00
select PayMethod
,TradingStatus
,BizType
,PayType
,TradeTime
,HisOperCode
,Amount
,remarks
,PlatformTransId
,PatientId
,PatientName
,trade_date
,his_wsdl_id
,HisTransId
2025-10-27 08:49:28 +08:00
,clr_type
,insutype
,ybzhAmount
,ybtcAmount
2025-08-21 10:00:57 +08:00
from hisbill_history
2025-07-23 09:55:50 +08:00
where trade_date=#{trade_date}
<if test="payTypeList != null and payTypeList.size() > 0">
and PayType in
<foreach collection="payTypeList" item="pt" open="(" separator="," close=")">
#{pt}
</foreach>
</if>
<if test="(payTypeList == null or payTypeList.size() == 0) and payType!=null and payType!=''">
2025-08-21 10:00:57 +08:00
and PayType = #{payType}
2025-07-23 09:55:50 +08:00
</if>
2025-08-21 10:00:57 +08:00
<if test="tradingStatus!=null and tradingStatus!=''">
and TradingStatus = #{tradingStatus}
2025-07-23 09:55:50 +08:00
</if>
2025-08-21 10:00:57 +08:00
<if test="orderby_amount!=null and orderby_amount!=''">
order by Amount desc
2025-07-23 09:55:50 +08:00
</if>
</select>
<select id="findHisDetailByTimeAndYSDDH" parameterType="HashMap" resultType="HashMap">
select PayMethod,TradingStatus,BizType,PayType,TradeTime,HisOperCode,Amount,remarks,PlatformTransId,
2025-10-27 08:49:28 +08:00
PatientId,PatientName,HisTransId,clr_type,insutype,ybzhAmount,ybtcAmount
2025-07-23 09:55:50 +08:00
from hisbill_history
where trade_date=#{searchTime}
and PlatformTransId = #{c_ysddh}
</select>
<select id="findHisDetailFirmNumByTime" parameterType="HashMap" resultType="HashMap">
select his_wsdl_id,count(1) as firmNum
from hisbill_history
where TradeTime &gt;= #{startTime}
and TradeTime &lt;= #{endTime}
group by his_wsdl_id
</select>
<select id="findHisCashDetail" parameterType="HashMap" resultType="HashMap">
2025-10-27 08:49:28 +08:00
select PayMethod, TradingStatus, BizType, PayType, TradeTime, HisOperCode, Amount, remarks, PlatformTransId, PatientId, PatientName, trade_date, his_wsdl_id, HisTransId, clr_type, insutype, ybzhAmount, ybtcAmount
2025-07-23 09:55:50 +08:00
from hisbill_history
where trade_date=#{trade_date} and PayType='5'
</select>
<select id="findHisDetailCountData" parameterType="HashMap" resultType="HashMap">
select count(1) as num,cast(IFNULL(sum(Amount),0) as decimal(19,2)) as money
from hisbill_history
<where>
<if test="payTypeList != null and payTypeList.size() > 0">
and PayType in
<foreach collection="payTypeList" item="pt" open="(" separator="," close=")">
#{pt}
</foreach>
</if>
<if test="(payTypeList == null or payTypeList.size() == 0) and payType!=null and payType!=''">
2025-10-23 15:11:04 +08:00
and (PayType = #{payType} or PayType = CAST(#{payType} AS UNSIGNED))
2025-07-23 09:55:50 +08:00
</if>
<if test="startTime!=null and startTime!=''">
2025-10-23 15:11:04 +08:00
and trade_date &gt;= #{startTime}
2025-07-23 09:55:50 +08:00
</if>
<if test="endTime!=null and endTime!=''">
2025-10-23 15:11:04 +08:00
and trade_date &lt;= #{endTime}
2025-07-23 09:55:50 +08:00
</if>
<if test="likeFiled!=null and likeFiled!=''">
and PlatformTransId like concat('%',concat(#{likeFiled},'%'))
</if>
</where>
</select>
2025-10-27 08:49:28 +08:00
2025-12-07 11:46:49 +08:00
<!-- 医保对账按险种和清算类别分组统计去重规则HisTransId + ZFAmount 都相同才视为同一记录)
1. 医疗总金额MEDFEE_SUMAMT统计同一收据号HisTransId且同一自费金额ZFAmount下的金额累计统筹 + 非退款账户 + 自费
2. 统筹金额FUND_PAY_SUMAMT累计统筹金额不受退款影响
3. 账户金额ACCT_PAY累计账户金额包含退款 -->
2025-10-27 08:49:28 +08:00
<select id="findMedicalInsuranceGroupData" parameterType="HashMap" resultType="HashMap">
2025-11-27 20:48:57 +08:00
select
t.insutype as INSUTYPE,
t.clr_type as CLR_TYPE,
count(distinct t.HisTransId) as FIXMEDINS_SETL_CNT,
2025-12-07 11:46:49 +08:00
cast(
IFNULL(sum(t.ybtc),0)
+ IFNULL(sum(case when t.is_inpatient = 1 then 0 else t.ybzh_non_refund end),0)
+ IFNULL(sum(t.zf),0)
as decimal(19,2)) as MEDFEE_SUMAMT,
2025-11-27 20:48:57 +08:00
cast(IFNULL(sum(t.ybtc),0) as decimal(19,2)) as FUND_PAY_SUMAMT,
cast(IFNULL(sum(t.ybzh),0) as decimal(19,2)) as ACCT_PAY
from (
select
insutype,
clr_type,
HisTransId,
max(cast(IFNULL(ybtcAmount,0) as decimal(19,2))) as ybtc,
max(cast(IFNULL(ybzhAmount,0) as decimal(19,2))) as ybzh,
2025-12-07 11:46:49 +08:00
max(case when TradingStatus != '2' then cast(IFNULL(ybzhAmount,0) as decimal(19,2)) else 0 end) as ybzh_non_refund,
max(cast(IFNULL(zfAmount,0) as decimal(19,2))) as zf,
max(case when PayMethod = '2' then 1 else 0 end) as is_inpatient
2025-11-27 20:48:57 +08:00
from hisbill_history
where trade_date = #{trade_date}
and insutype is not null
and insutype != ''
and clr_type is not null
and clr_type != ''
and HisTransId is not null
and HisTransId != ''
2025-12-07 11:46:49 +08:00
group by insutype, clr_type, HisTransId, cast(IFNULL(zfAmount,0) as decimal(19,2))
2025-11-27 20:48:57 +08:00
) as t
group by t.insutype, t.clr_type
order by t.insutype, t.clr_type
2025-10-27 08:49:28 +08:00
</select>
2025-11-27 20:48:57 +08:00
</mapper>