bugfix:对账完成

This commit is contained in:
Yuan
2025-12-07 11:46:49 +08:00
parent 3f931c2e29
commit 66620d51ae
23 changed files with 664 additions and 124 deletions

View File

@@ -75,6 +75,23 @@
<if test="likeFiled!=null and likeFiled!=''">
and C_YSDDH like concat('%',concat(#{likeFiled},'%'))
</if>
and C_SHDDH in (
select C_SHDDH
from bankbill_history
<where>
<if test="startTime!=null and startTime!=''">
and C_JYRQ &gt;= #{startTime}
</if>
<if test="endTime!=null and endTime!=''">
and C_JYRQ &lt;= #{endTime}
</if>
<if test="c_zffs!=null and c_zffs!=''">
and C_ZFFS = #{c_zffs}
</if>
</where>
group by C_SHDDH
having ROUND(SUM(CAST(C_JYJE AS DECIMAL(18,2))), 2) != 0
)
</where>
order by C_JYRQ,C_JYSJ
</select>
@@ -267,4 +284,4 @@
</if>
</where>
</select>
</mapper>
</mapper>

View File

@@ -14,6 +14,10 @@
PayType as dimension_value,
'按支付方式' as dimension_name
</when>
<when test="dimension == 'bizType'">
BizType as dimension_value,
'按业务类型' as dimension_name
</when>
<when test="dimension == 'refundType'">
TradingStatus as dimension_value,
'按退款类型' as dimension_name
@@ -41,6 +45,9 @@
<if test="payType != null and payType != ''">
AND PayType = #{payType}
</if>
<if test="bizType != null and bizType != ''">
AND BizType = #{bizType}
</if>
<choose>
<when test="dimension == 'time'">
GROUP BY DATE_FORMAT(trade_date, '%Y-%m-%d')
@@ -50,6 +57,10 @@
GROUP BY PayType
ORDER BY total_refund_amount DESC
</when>
<when test="dimension == 'bizType'">
GROUP BY BizType
ORDER BY total_refund_amount DESC
</when>
<when test="dimension == 'refundType'">
GROUP BY TradingStatus
ORDER BY total_refund_amount DESC
@@ -80,6 +91,9 @@
<if test="payType != null and payType != ''">
AND PayType = #{payType}
</if>
<if test="bizType != null and bizType != ''">
AND BizType = #{bizType}
</if>
</select>
<!-- 获取退款趋势数据 -->
@@ -100,6 +114,9 @@
<if test="payType != null and payType != ''">
AND PayType = #{payType}
</if>
<if test="bizType != null and bizType != ''">
AND BizType = #{bizType}
</if>
GROUP BY DATE_FORMAT(trade_date, '%Y-%m-%d')
ORDER BY DATE_FORMAT(trade_date, '%Y-%m-%d') ASC
</select>

View File

@@ -0,0 +1,115 @@
<?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.FinancialReconciliation.TenpaySummaryMapper">
<select id="findTenpayBankSummary" parameterType="HashMap" resultType="HashMap">
SELECT '微信支付' AS PAY_NAME,
COUNT(1) AS CNT,
CAST(IFNULL(SUM(CAST(C_JYJE AS DECIMAL(19,2))),0) AS DECIMAL(19,2)) AS AMT
FROM bankbill_history
<where>
<if test="startTime != null and startTime != ''">
AND C_JYRQ &gt;= #{startTime}
</if>
<if test="endTime != null and endTime != ''">
AND C_JYRQ &lt;= #{endTime}
</if>
AND bill_table_name = '微信支付账单'
AND C_JYLX = '1'
</where>
UNION ALL
SELECT '支付宝支付' AS PAY_NAME,
0 AS CNT,
CAST(0 AS DECIMAL(19,2)) AS AMT
UNION ALL
SELECT '刷卡支付' AS PAY_NAME,
0 AS CNT,
CAST(0 AS DECIMAL(19,2)) AS AMT
UNION ALL
SELECT '退款' AS PAY_NAME,
COUNT(1) AS CNT,
CAST(IFNULL(SUM(CAST(C_JYJE AS DECIMAL(19,2))),0) AS DECIMAL(19,2)) AS AMT
FROM bankbill_history
<where>
<if test="startTime != null and startTime != ''">
AND C_JYRQ &gt;= #{startTime}
</if>
<if test="endTime != null and endTime != ''">
AND C_JYRQ &lt;= #{endTime}
</if>
AND bill_table_name = '微信支付账单'
AND C_JYLX = '2'
</where>
UNION ALL
SELECT '合计' AS PAY_NAME,
COUNT(1) AS CNT,
CAST(IFNULL(SUM(CAST(C_JYJE AS DECIMAL(19,2))),0) AS DECIMAL(19,2)) AS AMT
FROM bankbill_history
<where>
<if test="startTime != null and startTime != ''">
AND C_JYRQ &gt;= #{startTime}
</if>
<if test="endTime != null and endTime != ''">
AND C_JYRQ &lt;= #{endTime}
</if>
AND bill_table_name = '微信支付账单'
AND C_JYLX IN ('1','2')
</where>
</select>
<select id="findTenpayHisSummary" parameterType="HashMap" resultType="HashMap">
SELECT '微信支付' AS PAY_NAME,
COUNT(1) AS CNT,
CAST(IFNULL(SUM(CAST(Amount AS DECIMAL(19,2))),0) AS DECIMAL(19,2)) AS AMT
FROM hisbill_history
<where>
<if test="startTime != null and startTime != ''">
AND trade_date &gt;= #{startTime}
</if>
<if test="endTime != null and endTime != ''">
AND trade_date &lt;= #{endTime}
</if>
AND LOWER(HisOperCode) = 'wx'
AND TradingStatus = '1'
</where>
UNION ALL
SELECT '支付宝支付' AS PAY_NAME,
0 AS CNT,
CAST(0 AS DECIMAL(19,2)) AS AMT
UNION ALL
SELECT '刷卡支付' AS PAY_NAME,
0 AS CNT,
CAST(0 AS DECIMAL(19,2)) AS AMT
UNION ALL
SELECT '退款' AS PAY_NAME,
COUNT(1) AS CNT,
CAST(IFNULL(SUM(CAST(Amount AS DECIMAL(19,2))),0) AS DECIMAL(19,2)) AS AMT
FROM hisbill_history
<where>
<if test="startTime != null and startTime != ''">
AND trade_date &gt;= #{startTime}
</if>
<if test="endTime != null and endTime != ''">
AND trade_date &lt;= #{endTime}
</if>
AND LOWER(HisOperCode) = 'wx'
AND TradingStatus = '2'
</where>
UNION ALL
SELECT '合计' AS PAY_NAME,
COUNT(1) AS CNT,
CAST(IFNULL(SUM(CAST(Amount AS DECIMAL(19,2))),0) AS DECIMAL(19,2)) AS AMT
FROM hisbill_history
<where>
<if test="startTime != null and startTime != ''">
AND trade_date &gt;= #{startTime}
</if>
<if test="endTime != null and endTime != ''">
AND trade_date &lt;= #{endTime}
</if>
AND LOWER(HisOperCode) = 'wx'
AND TradingStatus IN ('1','2')
</where>
</select>
</mapper>

View File

@@ -26,6 +26,9 @@
<if test="payType!=null and payType!=''">
and PayType = #{payType}
</if>
<if test="bizType!=null and bizType!=''">
and BizType = #{bizType}
</if>
<if test="startTime!=null and startTime!=''">
and trade_date &gt;= #{startTime}
</if>
@@ -47,6 +50,9 @@
<if test="payType!=null and payType!=''">
and PayType = #{payType}
</if>
<if test="bizType!=null and bizType!=''">
and BizType = #{bizType}
</if>
<if test="startTime!=null and startTime!=''">
and trade_date &gt;= #{startTime}
</if>
@@ -247,16 +253,20 @@
</where>
</select>
<!-- 医保对账:按险种和清算类别分组统计(按ReceiptNO去重即HisTransId
1. 医疗总金额MEDFEE_SUMAMT统计同一收据号HisTransId下的自费总额取该收据号的ZFAmount并按组求和
2. 统筹金额FUND_PAY_SUMAMT和账户金额ACCT_PAY只统计PayType为9和10的记录按收据号合并
3. 按HisTransId去重合并统计金额 -->
<!-- 医保对账:按险种和清算类别分组统计(去重规则HisTransId + ZFAmount 都相同才视为同一记录
1. 医疗总金额MEDFEE_SUMAMT统计同一收据号HisTransId且同一自费金额ZFAmount下的金额累计统筹 + 非退款账户 + 自费
2. 统筹金额FUND_PAY_SUMAMT:累计统筹金额(不受退款影响)
3. 账户金额ACCT_PAY累计账户金额包含退款 -->
<select id="findMedicalInsuranceGroupData" parameterType="HashMap" resultType="HashMap">
select
t.insutype as INSUTYPE,
t.clr_type as CLR_TYPE,
count(distinct t.HisTransId) as FIXMEDINS_SETL_CNT,
cast(IFNULL(sum(t.ybtc),0) + IFNULL(sum(t.ybzh),0) + IFNULL(sum(t.zf),0) as decimal(19,2)) as MEDFEE_SUMAMT,
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,
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 (
@@ -266,7 +276,9 @@
HisTransId,
max(cast(IFNULL(ybtcAmount,0) as decimal(19,2))) as ybtc,
max(cast(IFNULL(ybzhAmount,0) as decimal(19,2))) as ybzh,
max(cast(IFNULL(zfAmount,0) as decimal(19,2))) as zf
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
from hisbill_history
where trade_date = #{trade_date}
and insutype is not null
@@ -275,7 +287,7 @@
and clr_type != ''
and HisTransId is not null
and HisTransId != ''
group by insutype, clr_type, HisTransId
group by insutype, clr_type, HisTransId, cast(IFNULL(zfAmount,0) as decimal(19,2))
) as t
group by t.insutype, t.clr_type
order by t.insutype, t.clr_type

View File

@@ -111,17 +111,7 @@
0 as BANK_AMOUNT
from hisbill_history
where PayMethod = '2'
and PayType != '5' <!-- 排除现金支付 -->
and PayType != '3' <!-- 排除军保支付(医院垫支) -->
and PayType != '7' <!-- 排除预交金 -->
and PayType != '9' <!-- 排除统筹支付 -->
and PayType != '10' <!-- 排除账户支付 -->
<if test="military_payment_code != null and military_payment_code != ''">
and PayType != #{military_payment_code}
</if>
<if test="check_payment_code != null and check_payment_code != ''">
and PayType != #{check_payment_code}
</if>
and PayType = '2'
<if test="startTime != null and startTime != ''">
and trade_date &gt;= #{startTime}
</if>

View File

@@ -14,6 +14,12 @@
<result column="fixmedins_setl_cnt" property="fixmedins_setl_cnt" jdbcType="INTEGER"/>
<result column="stmt_rslt" property="stmt_rslt" jdbcType="VARCHAR"/>
<result column="stmt_rslt_dscr" property="stmt_rslt_dscr" jdbcType="VARCHAR"/>
<result column="execute_type" property="execute_type" jdbcType="VARCHAR"/>
<result column="check_round" property="check_round" jdbcType="INTEGER"/>
<result column="recheck_flag" property="recheck_flag" jdbcType="VARCHAR"/>
<result column="prev_stmt_rslt" property="prev_stmt_rslt" jdbcType="VARCHAR"/>
<result column="recheck_time" property="recheck_time" jdbcType="VARCHAR"/>
<result column="recheck_user" property="recheck_user" jdbcType="VARCHAR"/>
<result column="api_result" property="api_result" jdbcType="VARCHAR"/>
<result column="create_time" property="create_time" jdbcType="VARCHAR"/>
<result column="modify_time" property="modify_time" jdbcType="VARCHAR"/>
@@ -24,13 +30,15 @@
insert into medical_insurance_reconciliation_result (
id, trade_date, insutype, clr_type,
medfee_sumamt, fund_pay_sumamt, acct_pay, fixmedins_setl_cnt,
stmt_rslt, stmt_rslt_dscr, api_result,
create_time, modify_time
stmt_rslt, stmt_rslt_dscr,
execute_type, check_round, recheck_flag, prev_stmt_rslt, recheck_time, recheck_user,
api_result, create_time, modify_time
) values (
#{id}, #{trade_date}, #{insutype}, #{clr_type},
#{medfee_sumamt}, #{fund_pay_sumamt}, #{acct_pay}, #{fixmedins_setl_cnt},
#{stmt_rslt}, #{stmt_rslt_dscr}, #{api_result},
#{create_time}, #{modify_time}
#{stmt_rslt}, #{stmt_rslt_dscr},
#{execute_type}, #{check_round}, #{recheck_flag}, #{prev_stmt_rslt}, nullif(#{recheck_time}, ''), #{recheck_user},
#{api_result}, #{create_time}, #{modify_time}
)
</insert>
@@ -39,15 +47,17 @@
insert into medical_insurance_reconciliation_result (
id, trade_date, insutype, clr_type,
medfee_sumamt, fund_pay_sumamt, acct_pay, fixmedins_setl_cnt,
stmt_rslt, stmt_rslt_dscr, api_result,
create_time, modify_time
stmt_rslt, stmt_rslt_dscr,
execute_type, check_round, recheck_flag, prev_stmt_rslt, recheck_time, recheck_user,
api_result, create_time, modify_time
) values
<foreach collection="list" index="index" item="itm" separator=",">
(
#{itm.id}, #{itm.trade_date}, #{itm.insutype}, #{itm.clr_type},
#{itm.medfee_sumamt}, #{itm.fund_pay_sumamt}, #{itm.acct_pay}, #{itm.fixmedins_setl_cnt},
#{itm.stmt_rslt}, #{itm.stmt_rslt_dscr}, #{itm.api_result},
#{itm.create_time}, #{itm.modify_time}
#{itm.stmt_rslt}, #{itm.stmt_rslt_dscr},
#{itm.execute_type}, #{itm.check_round}, #{itm.recheck_flag}, #{itm.prev_stmt_rslt}, nullif(#{itm.recheck_time}, ''), #{itm.recheck_user},
#{itm.api_result}, #{itm.create_time}, #{itm.modify_time}
)
</foreach>
</insert>
@@ -65,6 +75,12 @@
fixmedins_setl_cnt,
stmt_rslt,
stmt_rslt_dscr,
execute_type,
check_round,
recheck_flag,
prev_stmt_rslt,
DATE_FORMAT(recheck_time, '%Y-%m-%d %H:%i:%s') as recheck_time,
recheck_user,
api_result,
DATE_FORMAT(create_time, '%Y-%m-%d %H:%i:%s') as create_time,
DATE_FORMAT(modify_time, '%Y-%m-%d %H:%i:%s') as modify_time
@@ -105,5 +121,3 @@
</delete>
</mapper>

View File

@@ -232,7 +232,19 @@
</if>
) a
right join
(select * from bankbill_history where C_JYRQ = #{trade_date} and (is_inpatient is null or is_inpatient = '0')) b -- 排除住院订单
(
select * from bankbill_history
where C_JYRQ = #{trade_date}
and (is_inpatient is null or is_inpatient = '0')
and C_SHDDH in (
select C_SHDDH
from bankbill_history
where C_JYRQ = #{trade_date}
and (is_inpatient is null or is_inpatient = '0')
group by C_SHDDH
having ROUND(SUM(CAST(C_JYJE AS DECIMAL(18,2))), 2) != 0
)
) b -- 排除住院订单且排除同订单号正负抵消为0的记录
on a.PlatformTransId = b.C_SHDDH and a.TradingStatus = b.C_JYLX and ROUND(CAST(a.Amount AS DECIMAL(18,2)), 2) = ROUND(CAST(b.C_JYJE AS DECIMAL(18,2)), 2)
where a.PlatformTransId is null
</insert>
@@ -651,8 +663,10 @@
PatientID = #{patientid},
PatientName = #{patientname},
sort_date = #{sort_date},
err_type = #{err_type},
check_result = #{check_result}
err_type = case when ROUND(CAST(#{amount} AS DECIMAL(18,2)), 2) = ROUND(CAST(I_JYJE AS DECIMAL(18,2)), 2)
and #{h_jylx} = I_JYLX then '' else '3' end,
check_result = case when ROUND(CAST(#{amount} AS DECIMAL(18,2)), 2) = ROUND(CAST(I_JYJE AS DECIMAL(18,2)), 2)
and #{h_jylx} = I_JYLX then '0' else '1' end
where trade_date = #{trade_date}
and I_DDH = #{i_ddh}
</update>
@@ -693,4 +707,4 @@
</insert>
</mapper>
</mapper>

View File

@@ -3,47 +3,65 @@
<mapper namespace="com.saye.hospitalgd.mapper.UnilateralMapper">
<select id="findAllUnilateral" parameterType="HashMap" resultType="HashMap">
select id
,PayType
,TranID
,H_JYLX
,trade_date
,HisOperNum
,Amount
,I_JYJE
,I_JYLX
,I_DDH
,I_JYQD
,TradeTime
,is_manager
,manager_time
,err_type
,remark
,create_time
,modify_time
,managerType
from unmanger_unilateral
<where>
<if test="startTime!=null and startTime!=''">
and trade_date &gt;=#{startTime}
</if>
<if test="startTime!=null and startTime!=''">
and trade_date &lt;=#{endTime}
</if>
<if test="payType!=null and payType!=''">
and payType =#{payType}
</if>
<if test="thirdPay!=null and thirdPay!=''">
and I_JYQD =#{thirdPay}
</if>
<if test="err_type!=null and err_type!=''">
and err_type =#{err_type}
</if>
<if test="is_manager!=null and is_manager!=''">
and is_manager=#{is_manager}
</if>
</where>
order by trade_date
select u.id
,u.PayType
,u.TranID
,u.H_JYLX
,u.trade_date
,u.HisOperNum
,u.Amount
,u.I_JYJE
,u.I_JYLX
,u.I_DDH
,u.I_JYQD
,u.TradeTime
,u.is_manager
,u.manager_time
,u.err_type
,u.remark
,u.create_time
,u.modify_time
,u.managerType
from unmanger_unilateral u
inner join (
select COALESCE(TranID,'') as TranID,
COALESCE(H_JYLX,'') as H_JYLX,
COALESCE(I_DDH,'') as I_DDH,
COALESCE(I_JYLX,'') as I_JYLX,
COALESCE(is_manager,'') as is_manager,
trade_date,
max(modify_time) as modify_time
from unmanger_unilateral
<where>
<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="payType!=null and payType!=''">
and payType =#{payType}
</if>
<if test="thirdPay!=null and thirdPay!=''">
and I_JYQD =#{thirdPay}
</if>
<if test="err_type!=null and err_type!=''">
and err_type =#{err_type}
</if>
<if test="is_manager!=null and is_manager!=''">
and is_manager=#{is_manager}
</if>
</where>
group by COALESCE(TranID,''), COALESCE(H_JYLX,''), COALESCE(I_DDH,''), COALESCE(I_JYLX,''), COALESCE(is_manager,''), trade_date
) g
on u.TranID = g.TranID
and u.H_JYLX = g.H_JYLX
and COALESCE(u.I_DDH,'') = g.I_DDH
and COALESCE(u.I_JYLX,'') = g.I_JYLX
and COALESCE(u.is_manager,'') = g.is_manager
and u.trade_date = g.trade_date
and u.modify_time = g.modify_time
order by u.trade_date
</select>
<insert id="insertUnilateral" parameterType="HashMap">
@@ -100,6 +118,9 @@
<if test="h_jylx!=null and h_jylx!=''">
and H_JYLX=#{h_jylx}
</if>
<if test="trade_date!=null and trade_date!=''">
and trade_date=#{trade_date}
</if>
<if test="i_jylx!=null and i_jylx!=''">
and I_JYLX=#{i_jylx}
</if>
@@ -252,4 +273,4 @@
and I_DDH = #{i_ddh}
and err_type = '2'
</delete>
</mapper>
</mapper>