From e02812df9217d3e50a368a8234c07c60c64c0ff4 Mon Sep 17 00:00:00 2001
From: shiyunteng <shiyunteng@example.com>
Date: 星期三, 05 八月 2026 08:34:26 +0800
Subject: [PATCH] feat:新增石煤机 机械厂模版合同/客户数据主数据同步接口/合同履约进度新增质保结束操作/合同开票状态 修改为待开 可开 已开/出库逻辑完善

---
 platformx-business-finance-biz/src/main/resources/mapper/ContractPaymentScheduleMapper.xml |   70 +++++++++++++++++++++++++++++++++--
 1 files changed, 66 insertions(+), 4 deletions(-)

diff --git a/platformx-business-finance-biz/src/main/resources/mapper/ContractPaymentScheduleMapper.xml b/platformx-business-finance-biz/src/main/resources/mapper/ContractPaymentScheduleMapper.xml
index 94fd082..8f0d3dc 100644
--- a/platformx-business-finance-biz/src/main/resources/mapper/ContractPaymentScheduleMapper.xml
+++ b/platformx-business-finance-biz/src/main/resources/mapper/ContractPaymentScheduleMapper.xml
@@ -87,7 +87,10 @@
 			and bc.area_id = #{queryDTO.areaId}
 		</if>
 		<if test="queryDTO.industryId !=null">
-			and bc.industry_id = #{queryDTO.industryId}
+			and c.industry_code = #{queryDTO.industryId}
+		</if>
+		<if test="queryDTO.classId !=null">
+			and bc.class_id = #{queryDTO.classId}
 		</if>
 		GROUP BY
 		ranges.overdue_range,
@@ -166,7 +169,7 @@
 			c.del_flag = '0'
 		  AND c.amount > c.paid_amount
 		<if test="queryDTO.companyId !=null">
-			and c.party_a_id = #{queryDTO.companyId}
+			and c.party_b_id = #{queryDTO.companyId}
 		</if>
 		  AND EXISTS ( SELECT 1 FROM contract_out_bound cob WHERE cob.del_flag = '0' AND cob.contract_id = c.id )
 		GROUP BY
@@ -212,13 +215,13 @@
 				LEFT JOIN contract c ON c.del_flag = '0'
 				AND DATEDIFF(
 														CURRENT_DATE,
-														( SELECT max( out_bound_time ) FROM contract_out_bound cob WHERE cob.del_flag = '0' AND cob.contract_id = c.id ORDER BY out_bound_time ASC )) BETWEEN ranges.min_days
+														( SELECT max( invoice_time ) FROM contract_invoice ci WHERE ci.del_flag = '0' AND ci.contract_id = c.id ORDER BY invoice_time ASC )) BETWEEN ranges.min_days
 											AND ranges.max_days
 		WHERE
 			c.del_flag = '0'
 		  AND c.amount > c.paid_amount
 		<if test="queryDTO.companyId !=null">
-			and c.party_a_id = #{queryDTO.companyId}
+			and c.party_b_id = #{queryDTO.companyId}
 		</if>
 		  AND EXISTS ( SELECT 1 FROM contract_invoice ci WHERE ci.del_flag = '0' AND ci.contract_id = c.id)
 		GROUP BY
@@ -227,4 +230,63 @@
 		ORDER BY
 			ranges.min_days;
 	</select>
+	<select id="selectAgingTotalScale" resultType="com.by4cloud.platformx.business.vo.AgingVo">
+		SELECT
+		ranges.overdue_range,
+		COALESCE (
+		SUM(
+		CASE
+
+		WHEN cps.payment_status = '0' THEN
+		cps.planned_amount
+		WHEN cps.payment_status = '1' THEN
+		cps.planned_amount - cps.actual_amount ELSE 0
+		END
+		),
+		0
+		) AS total_amount
+		FROM
+		(
+		SELECT
+		'0-30澶�' AS overdue_range,
+		0 AS min_days,
+		30 AS max_days UNION ALL
+		SELECT
+		'31-60澶�',
+		31,
+		60 UNION ALL
+		SELECT
+		'61-90澶�',
+		61,
+		90 UNION ALL
+		SELECT
+		'91-180澶�',
+		91,
+		180 UNION ALL
+		SELECT
+		'181-365澶�',
+		181,
+		365 UNION ALL
+		SELECT
+		'1骞翠互涓�',
+		366,
+		999999
+		) AS ranges
+		LEFT JOIN contract_payment_schedule cps ON cps.del_flag = '0'
+		AND cps.payment_status NOT IN ( '2', '3' )
+		AND cps.effective_end_date &lt; CURRENT_DATE
+	 	AND DATEDIFF( CURRENT_DATE, cps.effective_end_date ) BETWEEN ranges.min_days
+		AND ranges.max_days
+		LEFT JOIN contract c ON cps.contract_id = c.id
+		WHERE
+		c.del_flag = '0'
+		<if test="queryDTO.companyId !=null">
+			and c.party_b_id = #{queryDTO.companyId}
+		</if>
+		GROUP BY
+		ranges.overdue_range,
+		ranges.min_days
+		ORDER BY
+		ranges.min_days;
+	</select>
 </mapper>
\ No newline at end of file

--
Gitblit v1.9.1