From 4ffb1400a1053f0dda23e8840fdeed1c301c1c7c Mon Sep 17 00:00:00 2001 From: dimengzhe Date: Thu, 13 Mar 2025 20:19:11 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../loanoverduebank/LoanOverdueBankMapper.xml | 97 +++++++++---------- .../loanoverduefin/LoanOverdueFinMapper.xml | 81 +++++----------- 2 files changed, 70 insertions(+), 108 deletions(-) diff --git a/anrui-riskcenter/anrui-riskcenter-biz/src/main/java/com/yxt/anrui/riskcenter/biz/loanoverduebank/LoanOverdueBankMapper.xml b/anrui-riskcenter/anrui-riskcenter-biz/src/main/java/com/yxt/anrui/riskcenter/biz/loanoverduebank/LoanOverdueBankMapper.xml index 9433de82f2..113c11381b 100644 --- a/anrui-riskcenter/anrui-riskcenter-biz/src/main/java/com/yxt/anrui/riskcenter/biz/loanoverduebank/LoanOverdueBankMapper.xml +++ b/anrui-riskcenter/anrui-riskcenter-biz/src/main/java/com/yxt/anrui/riskcenter/biz/loanoverduebank/LoanOverdueBankMapper.xml @@ -62,75 +62,68 @@ - SELECT - a1.busVinSid AS busViNSid, + SELECT a1.busVinSid AS busViNSid, RIGHT(a1.vinNo, 8) AS vinNo, - ( - a1.yq_total - + IFNULL(lbpv_total.bankBeInter, 0) - + IFNULL(fin_total.overdueMoney, 0) - ) AS overdueMoney, + (SUM(a1.yq_total) + IFNULL( + (SELECT SUM(lbpv.`bankBeInter`) + FROM loan_be_padsincere_veh lbpv + WHERE lbpv.saleVehSid = a1.busVinSid), + 0)) AS overdueMoney, a1.customer AS customerName, - a1.customerSid AS customerSid, - a1.borrowerSid AS loanSid, - a1.borrowerName AS loanName - FROM ( - -- ✅ 计算逾期金额 yq_total - SELECT - lrpd.sid, + a1.customerSid as customerSid, + a1.borrowerSid loanSid, + a1.borrowerName loanName + FROM (SELECT lrpd.sid, lrpd.busVinSid, lrpd.borrowerName, - lrpd.vinNo, + lrpd.`vinNo`, lrpd.dueMoney, - (lrpd.dueMoney - COALESCE(SUM(lrh.actualMoney), 0)) AS yq_total, + ( + lrpd.`dueMoney` - SUM(IFNULL(lrh.actualMoney, 0)) + ) AS yq_total, lrpd.borrowerSid, lrpd.customerSid, lrpd.customer - FROM loan_repayment_plan_details lrpd - LEFT JOIN loan_repayment_history lrh - ON lrh.planDetailSid = lrpd.sid - WHERE - lrpd.dueDate - < - #{stopDate} -- ✅ 直接比较日期,避免索引失效 - AND lrpd.useOrgSid = #{useOrgSid} - GROUP BY lrpd.sid, lrpd.busVinSid, lrpd.borrowerName, lrpd.vinNo, - lrpd.dueMoney, lrpd.borrowerSid, lrpd.customerSid, lrpd.customer - HAVING yq_total > 0 - ) a1 - LEFT JOIN ( - -- ✅ 计算 bankBeInter 总金额 - SELECT saleVehSid, SUM(bankBeInter) AS bankBeInter - FROM loan_be_padsincere_veh - GROUP BY saleVehSid - ) lbpv_total ON lbpv_total.saleVehSid = a1.busVinSid - LEFT JOIN ( - -- ✅ 计算 overdueMoney - SELECT - lrpd.busVinSid, - IFNULL(SUM(fjj.reveivableMoney), 0) - IFNULL(SUM(fin_sub.m), 0) AS overdueMoney - FROM anrui_fin.fin_uncollected_receivables_detailed_jr fjj - JOIN loan_repayment_plan_details lrpd - ON fjj.busSid = lrpd.sid - AND lrpd.dueDate - < - #{stopDate} -- ✅ 避免 DATE_FORMAT - LEFT JOIN ( - SELECT receivablesSid, SUM(subscriptionMoney) AS m - FROM anrui_fin.fin_selected_receivables_detailed - WHERE auditState = '3' - GROUP BY receivablesSid - ) fin_sub ON fin_sub.receivablesSid = fjj.sid - WHERE fjj.payCostTitleKey = '006' - GROUP BY lrpd.busVinSid - ) fin_total ON fin_total.busVinSid = a1.busVinSid + FROM `loan_repayment_plan_details` lrpd + LEFT JOIN `loan_repayment_history` lrh + ON lrh.planDetailSid = lrpd.`sid` + LEFT JOIN anrui_buscenter.`bus_sales_order_vehicle` bv + ON lrpd.busVinSid = bv.sid + WHERE DATE_FORMAT(lrpd.dueDate, '%Y-%m-%d') < #{stopDate} + and lrpd.useOrgSid = #{useOrgSid} + GROUP BY lrpd.`sid` + HAVING (yq_total > 0)) a1 - ${ew.sqlSegment} -- ✅ 添加动态查询条件 - ; + ${ew.sqlSegment} +