demand: TMS系统 - 运输管理 - 查询漏组批次统计数据数量计算不准确问题优化 TMS系统 - 月结账单核销 - 撤销收款功能 撤销后 财务开票处理-已开票 收款金额 数值未实施更新

committer: heyu
This commit is contained in:
aike 2025-10-10 10:45:14 +08:00
parent f655d26ded
commit aa69391136
3 changed files with 105 additions and 27 deletions

View File

@ -613,8 +613,71 @@ public class EmisSettlePayRecordServiceImpl extends EmisBaseService implements I
// 删除收款记录
emisSettlePayRecordMapper.deleteEmisSettlePayRecordById(id);
// 重新计算账单收款
emisSettleBillService.reCalcSettleBillPayStatus(payRecordOld.getSettleBillNo());
// 重新计算账单收款(账单号可能为逗号分隔的多个)
if (StringUtils.isNotBlank(payRecordOld.getSettleBillNo())) {
List<String> settleBillNos = Arrays.stream(payRecordOld.getSettleBillNo().split(","))
.map(String::trim)
.filter(org.apache.commons.lang3.StringUtils::isNotBlank)
.distinct()
.collect(Collectors.toList());
for (String settleBillNo : settleBillNos) {
emisSettleBillService.reCalcSettleBillPayStatus(settleBillNo);
}
}
// 重新计算对应发票的已收金额与付款状态
// 规则:发票新的已收金额 = 发票历史已收金额 - 本次(payId)对应的金额汇总
// 1) 查询本次收款的运单收款明细(包含applySeqNo)
EmisSettlePayRel query = new EmisSettlePayRel();
query.setPayId(payRecordOld.getPayId());
List<EmisSettlePayRel> thisPayRelList = emisSettlePayRelMapper.selectEmisSettlePayRelList(query);
if (!CollectionUtils.isEmpty(thisPayRelList)) {
// 2) 按applySeqNo分组汇总本次金额
Map<String, BigDecimal> revokeAmountByApplySeqNo = thisPayRelList.stream()
.filter(rel -> StringUtils.isNotBlank(rel.getApplySeqNo()))
.collect(Collectors.groupingBy(EmisSettlePayRel::getApplySeqNo,
Collectors.mapping(EmisSettlePayRel::getPayMoney,
Collectors.reducing(BigDecimal.ZERO, v -> v == null ? BigDecimal.ZERO : v,
BigDecimal::add))));
// 3) 对每个发票applySeqNo执行:历史已收金额 - 本次金额,重算状态
for (Map.Entry<String, BigDecimal> entry : revokeAmountByApplySeqNo.entrySet()) {
String applySeqNo = entry.getKey();
BigDecimal revokeAmount = entry.getValue() == null ? BigDecimal.ZERO : entry.getValue();
EmisSettleInvoiceRecord invoiceRecord = emisSettleInvoiceRecordMapper
.selectInvoiceRecordByApplySeqNo(applySeqNo);
if (invoiceRecord == null) {
continue;
}
BigDecimal historyReced = invoiceRecord.getRecedMoney() == null ? BigDecimal.ZERO
: invoiceRecord.getRecedMoney();
BigDecimal applyMoney = invoiceRecord.getApplyMoney() == null ? BigDecimal.ZERO
: invoiceRecord.getApplyMoney();
// 新的已收金额 = 历史已收金额 - 本次撤销金额,且不小于0
BigDecimal newReced = historyReced.subtract(revokeAmount);
if (newReced.compareTo(BigDecimal.ZERO) < 0) {
newReced = BigDecimal.ZERO;
}
String paymentStatus;
if (newReced.compareTo(BigDecimal.ZERO) == 0) {
paymentStatus = "0"; // 未付款
} else if (newReced.compareTo(applyMoney) >= 0) {
paymentStatus = "1"; // 已付款
} else {
paymentStatus = "2"; // 部分付款
}
EmisSettleInvoiceRecord upd = new EmisSettleInvoiceRecord();
upd.setId(invoiceRecord.getId());
upd.setRecedMoney(newReced);
upd.setPaymentStatus(paymentStatus);
emisSettleInvoiceRecordMapper.updateEmisSettleInvoiceRecord(upd);
}
}
return 1;
}

View File

@ -9,6 +9,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="payId" column="pay_id" />
<result property="billNo" column="bill_no" />
<result property="payMoney" column="pay_money" />
<result property="applySeqNo" column="apply_seq_no" />
</resultMap>
<resultMap id="EmisSettlePayRelWithSubBillResult" type="EmisSettlePayRel" extends="EmisSettlePayRelResult" >
@ -20,26 +21,40 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</resultMap>
<sql id="selectEmisSettlePayRelVo">
select id, pay_id, bill_no, pay_money, del_flag, create_by, create_time, update_by, update_time, create_site, update_site from emis_settle_pay_rel
select a.id,
a.pay_id,
a.bill_no,
a.pay_money,
a.del_flag,
a.create_by,
a.create_time,
a.update_by,
a.update_time,
a.create_site,
a.update_site,
r.apply_seq_no
from emis_settle_pay_rel a
left join emis_settle_pay_invoice_rel r
on r.pay_id = a.pay_id and r.del_flag = '0'
</sql>
<select id="selectEmisSettlePayRelList" parameterType="EmisSettlePayRel" resultMap="EmisSettlePayRelWithSubBillResult">
<include refid="selectEmisSettlePayRelVo"/>
<where>
del_flag='0'
<if test="id != null "> and id = #{id}</if>
<if test="payId != null and payId != ''"> and pay_id = #{payId}</if>
<if test="billNo != null and billNo != ''"> and bill_no = #{billNo}</if>
<if test="payMoney != null "> and pay_money = #{payMoney}</if>
<if test="delFlag != null and delFlag != ''"> and del_flag like concat('%', #{delFlag}, '%')</if>
<if test="createBy != null and createBy != ''"> and create_by like concat('%', #{createBy}, '%')</if>
<if test="createTime != null "> and create_time = #{createTime}</if>
<if test="updateBy != null and updateBy != ''"> and update_by like concat('%', #{updateBy}, '%')</if>
<if test="updateTime != null "> and update_time = #{updateTime}</if>
<if test="createSite != null and createSite != ''"> and create_site like concat('%', #{createSite}, '%')</if>
<if test="updateSite != null and updateSite != ''"> and update_site like concat('%', #{updateSite}, '%')</if>
a.del_flag='0'
<if test="id != null "> and a.id = #{id}</if>
<if test="payId != null and payId != ''"> and a.pay_id = #{payId}</if>
<if test="billNo != null and billNo != ''"> and a.bill_no = #{billNo}</if>
<if test="payMoney != null "> and a.pay_money = #{payMoney}</if>
<if test="delFlag != null and delFlag != ''"> and a.del_flag like concat('%', #{delFlag}, '%')</if>
<if test="createBy != null and createBy != ''"> and a.create_by like concat('%', #{createBy}, '%')</if>
<if test="createTime != null "> and a.create_time = #{createTime}</if>
<if test="updateBy != null and updateBy != ''"> and a.update_by like concat('%', #{updateBy}, '%')</if>
<if test="updateTime != null "> and a.update_time = #{updateTime}</if>
<if test="createSite != null and createSite != ''"> and a.create_site like concat('%', #{createSite}, '%')</if>
<if test="updateSite != null and updateSite != ''"> and a.update_site like concat('%', #{updateSite}, '%')</if>
</where>
order by create_time desc
order by a.create_time desc
</select>
<select id="selectHasPayListBySettleBillNo" parameterType="String" resultMap="EmisSettlePayRelWithSubBillResult">

View File

@ -18,9 +18,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
STR_TO_DATE(CONCAT(DATE_FORMAT(w.send_date, '%Y-%m'), '-01'), '%Y-%m-%d') as bill_month,
COUNT(*) as ticket_count
FROM emis_tms_site_batch_miss bm
LEFT JOIN emis_waybill w ON bm.bill_code = w.bill_code
LEFT JOIN emis_site s ON bm.start_site_code = s.site_code
WHERE 1=1
LEFT JOIN emis_waybill w ON bm.bill_code = w.bill_code AND w.del_flag = '0'
LEFT JOIN emis_site s ON bm.start_site_code = s.site_code AND s.del_flag = '0'
WHERE bm.del_flag = '0'
<if test="startSiteCode != null and startSiteCode != ''">
AND bm.start_site_code = #{startSiteCode}
</if>
@ -62,12 +62,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
LIMIT 1) as product_type_name
from emis_tms_site_batch_miss m
left join emis_waybill w on m.bill_code = w.bill_code and w.del_flag='0'
left join emis_site s1 on w.send_site_code=s1.site_code and s1.del_flag=0
left join emis_site s2 on m.start_site_code=s2.site_code and s2.del_flag=0
left join emis_site s3 on m.next_site_code=s3.site_code and s3.del_flag=0
left join emis_site s1 on w.send_site_code=s1.site_code and s1.del_flag='0'
left join emis_site s2 on m.start_site_code=s2.site_code and s2.del_flag='0'
left join emis_site s3 on m.next_site_code=s3.site_code and s3.del_flag='0'
left join emis_country c1 on w.send_country=c1.code and c1.del_flag='0'
left join emis_country c2 on w.receive_country=c2.code and c2.del_flag='0'
left join emis_site s4 on w.dispatch_underling_site_code=s4.site_code and s4.del_flag=0
left join emis_site s4 on w.dispatch_underling_site_code=s4.site_code and s4.del_flag='0'
left join emis_trans_line k on w.trans_line_type=k.line_code and k.del_flag='0'
left join emis_trans_plan_rule r on m.trans_plan_rule_id=r.id and r.del_flag='0'
left join emis_trans_line l on m.line_code=l.line_code and l.del_flag='0'
@ -114,12 +114,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
LIMIT 1) as product_type_name
from emis_tms_site_batch_miss m
left join emis_waybill w on m.bill_code = w.bill_code and w.del_flag='0'
left join emis_site s1 on w.send_site_code=s1.site_code and s1.del_flag=0
left join emis_site s2 on m.start_site_code=s2.site_code and s2.del_flag=0
left join emis_site s3 on m.next_site_code=s3.site_code and s3.del_flag=0
left join emis_site s1 on w.send_site_code=s1.site_code and s1.del_flag='0'
left join emis_site s2 on m.start_site_code=s2.site_code and s2.del_flag='0'
left join emis_site s3 on m.next_site_code=s3.site_code and s3.del_flag='0'
left join emis_country c1 on w.send_country=c1.code and c1.del_flag='0'
left join emis_country c2 on w.receive_country=c2.code and c2.del_flag='0'
left join emis_site s4 on w.dispatch_underling_site_code=s4.site_code and s4.del_flag=0
left join emis_site s4 on w.dispatch_underling_site_code=s4.site_code and s4.del_flag='0'
left join emis_trans_line k on w.trans_line_type=k.line_code and k.del_flag='0'
left join emis_trans_plan_rule r on m.trans_plan_rule_id=r.id and r.del_flag='0'
left join emis_trans_line l on m.line_code=l.line_code and l.del_flag='0'