From 2ceb092cb757368bdab2c4cd71da4486a1d6ea2b Mon Sep 17 00:00:00 2001
From: aike <17730485278@139.com>
Date: Tue, 9 Sep 2025 09:54:45 +0800
Subject: [PATCH] =?UTF-8?q?demand:=20TMS=E7=B3=BB=E7=BB=9F=20-=20=E5=AE=A2?=
=?UTF-8?q?=E6=88=B7=E8=B4=A6=E5=8D=95=E7=AE=A1=E7=90=86=20-=20=E6=94=B6?=
=?UTF-8?q?=E6=AC=BE=E6=98=8E=E7=BB=86=E6=9F=A5=E8=AF=A2=20-=20=E6=9F=A5?=
=?UTF-8?q?=E8=AF=A2=E8=BF=94=E5=9B=9E=E5=AD=97=E6=AE=B5=E5=A2=9E=E5=8A=A0?=
=?UTF-8?q?=E8=B4=A6=E5=8D=95=E7=BC=96=E5=8F=B7=E3=80=81=E8=BF=90=E5=8D=95?=
=?UTF-8?q?=E5=8F=B7=E3=80=81=E8=B4=A6=E5=8D=95=E9=87=91=E9=A2=9D=E3=80=81?=
=?UTF-8?q?=E5=BC=80=E7=A5=A8=E9=87=91=E9=A2=9D=E3=80=81=E5=BC=80=E7=A5=A8?=
=?UTF-8?q?=E7=8A=B6=E6=80=81=E3=80=81=E5=A4=87=E6=B3=A8=E7=89=B9=E6=AE=8A?=
=?UTF-8?q?=E9=80=BB=E8=BE=91=E5=A4=84=E7=90=86?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
committer: heyu
---
.../mapper/EmisSettlePayRecordMapper.xml | 98 +++++++++----------
1 file changed, 48 insertions(+), 50 deletions(-)
diff --git a/emis-biz/src/main/resources/mapper/EmisSettlePayRecordMapper.xml b/emis-biz/src/main/resources/mapper/EmisSettlePayRecordMapper.xml
index 3ba211c5d..3510cecc0 100644
--- a/emis-biz/src/main/resources/mapper/EmisSettlePayRecordMapper.xml
+++ b/emis-biz/src/main/resources/mapper/EmisSettlePayRecordMapper.xml
@@ -654,16 +654,19 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
@@ -671,82 +674,77 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
select
pay_id,
CONCAT_WS(';',
- -- 1. 已开票记录(若存在则拼接,否则为NULL)
+ -- 1. 已开票记录(按日期+公司分组)
GROUP_CONCAT(
- CASE WHEN op_date IS NOT NULL THEN -- 只拼接明细行
+ CASE WHEN invoice_date IS NOT NULL THEN
CONCAT(
- DATE_FORMAT(op_date, '%m%d'),
+ DATE_FORMAT(invoice_date, '%m%d'),
'已开票',
CASE
- WHEN total_amount = FLOOR(total_amount) THEN CAST(FLOOR(total_amount) AS CHAR)
- ELSE TRIM(TRAILING '0' FROM TRIM(TRAILING '.' FROM CAST(total_amount AS CHAR)))
+ WHEN invoice_amount = FLOOR(invoice_amount) THEN CAST(FLOOR(invoice_amount) AS CHAR)
+ ELSE TRIM(TRAILING '0' FROM TRIM(TRAILING '.' FROM CAST(invoice_amount AS CHAR)))
END,
' ',
company_name
)
END
- ORDER BY op_date
+ ORDER BY invoice_date
SEPARATOR ';'
),
- -- 2. 剩余未开金额(从汇总行提取计算)
+ -- 2. 剩余未开金额
CASE
- WHEN (MAX(bill_amount) - MAX(invoice_amount)) > 0
+ WHEN (bill_amount - total_invoice_amount) > 0
THEN CONCAT('剩余未开',
CASE
- WHEN (MAX(bill_amount) - MAX(invoice_amount)) = FLOOR(MAX(bill_amount) - MAX(invoice_amount))
- THEN CAST(FLOOR(MAX(bill_amount) - MAX(invoice_amount)) AS CHAR)
- ELSE TRIM(TRAILING '0' FROM TRIM(TRAILING '.' FROM CAST((MAX(bill_amount) - MAX(invoice_amount)) AS CHAR)))
+ WHEN (bill_amount - total_invoice_amount) = FLOOR(bill_amount - total_invoice_amount)
+ THEN CAST(FLOOR(bill_amount - total_invoice_amount) AS CHAR)
+ ELSE TRIM(TRAILING '0' FROM TRIM(TRAILING '.' FROM CAST((bill_amount - total_invoice_amount) AS CHAR)))
END, '元')
ELSE ''
END
) as status
from (
- -- 子查询1:已开票明细行(按日期分组)
+ -- 子查询1:已开票明细行(按日期+公司分组)
select
- espr.pay_id,
- esir.op_date,
- SUM(esir.apply_money) as total_amount,
- GROUP_CONCAT(DISTINCT esir.company_name SEPARATOR ' ') as company_name,
- 0 as total_invoiced_amount, -- 明细行不参与汇总计算
- 0 as bill_amount,
- 0 as invoice_amount
- from emis_settle_pay_record espr
- left join emis_settle_pay_bill_rel espbr on espr.pay_id = espbr.pay_id
- left join emis_settle_invoice_record esir on espbr.settle_bill_no = esir.settle_bill_no
- where espr.del_flag = '0'
- and espbr.del_flag = '0'
- and esir.del_flag = '0'
- and esir.invoice_status = '2'
- and espr.pay_id in
+ espbr.pay_id,
+ DATE(esir_record.op_date) as invoice_date,
+ SUM(esir.money) as invoice_amount,
+ GROUP_CONCAT(DISTINCT esir_record.company_name SEPARATOR ' ') as company_name,
+ 0 as total_invoice_amount,
+ 0 as bill_amount
+ from emis_settle_pay_bill_rel espbr
+ left join emis_settle_sub_bill essb on espbr.settle_bill_no = essb.settle_bill_no
+ left join emis_settle_invoice_rel esir on essb.bill_code = esir.bill_no
+ left join emis_settle_invoice_record esir_record on esir.apply_seq_no = esir_record.apply_seq_no
+ where espbr.del_flag = '0' and essb.del_flag = '0' and esir.del_flag = '0' and esir_record.del_flag = '0'
+ and esir_record.invoice_status = '2'
+ and espbr.pay_id in
#{payId}
- group by espr.pay_id, esir.op_date
+ group by espbr.pay_id, DATE(esir_record.op_date), esir_record.company_name
UNION ALL
-- 子查询2:汇总行(计算总开票金额和账单金额)
select
- espr.pay_id,
- NULL as op_date, -- 汇总行无日期,用于区分
- 0 as total_amount,
+ espbr.pay_id,
+ NULL as invoice_date,
+ 0 as invoice_amount,
'' as company_name,
- SUM(CASE WHEN esir.invoice_status = '2' THEN esir.apply_money ELSE 0 END) as total_invoiced_amount,
- MAX(esb.rec_money) as bill_amount,
- SUM(CASE WHEN esir.invoice_status = '2' THEN esir.apply_money ELSE 0 END) as invoice_amount
- from emis_settle_pay_record espr
- left join emis_settle_pay_bill_rel espbr on espr.pay_id = espbr.pay_id
+ SUM(CASE WHEN esir_record.invoice_status = '2' THEN esir.money ELSE 0 END) as total_invoice_amount,
+ MAX(esb.rec_money) as bill_amount
+ from emis_settle_pay_bill_rel espbr
+ left join emis_settle_sub_bill essb on espbr.settle_bill_no = essb.settle_bill_no
left join emis_settle_bill esb on espbr.settle_bill_no = esb.settle_bill_no
- left join emis_settle_invoice_record esir on espbr.settle_bill_no = esir.settle_bill_no
- where espr.del_flag = '0'
- and espbr.del_flag = '0'
- and esb.del_flag = '0'
- and esir.del_flag = '0'
- and espr.pay_id in
+ left join emis_settle_invoice_rel esir on essb.bill_code = esir.bill_no
+ left join emis_settle_invoice_record esir_record on esir.apply_seq_no = esir_record.apply_seq_no
+ where espbr.del_flag = '0' and essb.del_flag = '0' and esb.del_flag = '0' and esir.del_flag = '0' and esir_record.del_flag = '0'
+ and espbr.pay_id in
#{payId}
- group by espr.pay_id
+ group by espbr.pay_id
) invoice_summary
group by pay_id