Browse Source

修改

master
dimengzhe 3 months ago
parent
commit
4ffb1400a1
  1. 97
      anrui-riskcenter/anrui-riskcenter-biz/src/main/java/com/yxt/anrui/riskcenter/biz/loanoverduebank/LoanOverdueBankMapper.xml
  2. 81
      anrui-riskcenter/anrui-riskcenter-biz/src/main/java/com/yxt/anrui/riskcenter/biz/loanoverduefin/LoanOverdueFinMapper.xml

97
anrui-riskcenter/anrui-riskcenter-biz/src/main/java/com/yxt/anrui/riskcenter/biz/loanoverduebank/LoanOverdueBankMapper.xml

@ -62,75 +62,68 @@
<select id="detailsList" resultType="com.yxt.anrui.riskcenter.api.loanoverduebankdetails.LoanOverdueBankDetailsDto">
SELECT
a1.loanContractNo,
a1.borrowerName AS loanName,
a1.borrowerSid AS loanSid,
a1.bankName,
a1.bankContractNo,
COUNT(a1.sid) AS period, -- 逾期期数
<!--贷款合同编号-->
a1.`loanContractNo`,
<!--贷款人-->
a1.borrowerName loanName,
a1.borrowerSid loanSid,
<!--资方-->
a1.`bankName`,
<!--资方合同编号-->
a1.`bankContractNo`,
<!--逾期期数-->
COUNT(a1.sid) AS period,
<!--逾期金额-->
(
a1.yq_total
+ IFNULL(lbpv_total.bankBeInter, 0)
+ IFNULL(fin_total.overdueMoney, 0)
SUM(a1.yq_total) + IFNULL(
(SELECT SUM(lbpv.`bankBeInter`)
FROM loan_be_padsincere_veh lbpv
WHERE lbpv.saleVehSid = a1.busVinSid),
0
) + IFNULL(cte.reveivableMoneySum, 0)
) AS overdueMoney,
a1.customerSid,
a1.customer AS customerName
FROM (
-- ✅ 计算逾期金额 yq_total
SELECT
lrpd.sid,
lrpd.loanContractNo,
a1.customer customerName
FROM (SELECT lrpd.sid,
lrpd.`loanContractNo`,
lrpd.borrowerName,
lrpd.bankName,
lrpd.bankContractNo,
lrpd.`bankName`,
lrpd.`bankContractNo`,
lrpd.dueMoney,
(lrpd.dueMoney - COALESCE(SUM(lrh.actualMoney), 0)) AS yq_total,
(
lrpd.`dueMoney` - SUM(IFNULL(lrh.actualMoney, 0))
) AS yq_total,
lrpd.customer,
lrpd.customerSid,
lrpd.borrowerSid,
lrpd.busVinSid
FROM loan_repayment_plan_details lrpd
LEFT JOIN loan_repayment_history lrh
ON lrh.planDetailSid = lrpd.sid
WHERE
lrpd.dueDate
&lt;
#{stopDate} -- ✅ 避免 DATE_FORMAT 影响索引
AND lrpd.useOrgSid = #{useOrgSid}
GROUP BY lrpd.sid, lrpd.loanContractNo, lrpd.borrowerName, lrpd.bankName,
lrpd.bankContractNo, lrpd.dueMoney, lrpd.customer,
lrpd.customerSid, lrpd.borrowerSid, lrpd.busVinSid
HAVING yq_total > 0
) a1
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') &lt; #{stopDate}
and lrpd.useOrgSid = #{useOrgSid}
GROUP BY lrpd.`sid`
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
IFNULL(SUM(fjj.reveivableMoney), 0) - IFNULL(SUM(s.subscriptionMoney), 0) AS reveivableMoneySum
FROM anrui_fin.fin_uncollected_receivables_detailed_jr fjj
LEFT JOIN anrui_fin.fin_selected_receivables_detailed s
ON s.receivablesSid = fjj.sid AND s.auditState = '3'
JOIN loan_repayment_plan_details lrpd
ON fjj.busSid = lrpd.sid
AND lrpd.dueDate
&lt;
#{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'
WHERE DATE_FORMAT(lrpd.dueDate, '%Y-%m-%d') &lt; #{stopDate}
AND fjj.payCostTitleKey = '006'
GROUP BY lrpd.busVinSid
) fin_total ON fin_total.busVinSid = a1.busVinSid
) cte ON cte.busVinSid = a1.busVinSid
<where>
${ew.sqlSegment} -- ✅ 保留动态查询条件
</where>;
${ew.sqlSegment}
</where>
</select>
<select id="getAppDetails" resultType="com.yxt.anrui.riskcenter.api.loanoverduebank.LoanOverdueBankAppDetailsVo">

81
anrui-riskcenter/anrui-riskcenter-biz/src/main/java/com/yxt/anrui/riskcenter/biz/loanoverduefin/LoanOverdueFinMapper.xml

@ -61,71 +61,40 @@
</update>
<select id="detailsList" resultType="com.yxt.anrui.riskcenter.api.loanoverduefindetails.LoanOverdueFinDetailsDto">
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
&lt;
#{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
&lt;
#{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') &lt; #{stopDate}
and lrpd.useOrgSid = #{useOrgSid}
GROUP BY lrpd.`sid`
HAVING (yq_total > 0)) a1
<where>
${ew.sqlSegment} -- ✅ 添加动态查询条件
</where>;
${ew.sqlSegment}
</where>
</select>
<select id="getAppDetails" resultType="com.yxt.anrui.riskcenter.api.loanoverduefin.LoanOverdueFinAppVo">

Loading…
Cancel
Save