:fix: 修复付款申请草稿重存时结算关联唯一索引冲突(逻辑删除残留旧行,改物理删除)

This commit is contained in:
刘泉佳
2026-10-13 20:05:16 +08:00
parent 08e07841b5
commit d99488b999
2 changed files with 20 additions and 3 deletions
@@ -1,10 +1,21 @@
package org.springblade.transport.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.springblade.transport.pojo.entity.PaymentApplicationSettlement;
/** 付款申请关联正式结算单 Mapper。 */
@Mapper
public interface PaymentApplicationSettlementMapper extends BaseMapper<PaymentApplicationSettlement> {
/**
* 按付款申请主键物理删除关联记录(表存在不含逻辑删除字段的关系唯一索引,重存前必须物理清理)
*
* @param paymentApplicationId 付款申请主键
* @return 删除行数
*/
@Delete("DELETE FROM blade_payment_application_settlement WHERE payment_application_id = #{paymentApplicationId}")
int deleteByPaymentApplicationId(@Param("paymentApplicationId") Long paymentApplicationId);
}
@@ -325,7 +325,7 @@ private final CustomerReceiptAccountMapper receiptAccountMapper;
validateProjectAdvanceContract(entity);
validateSelectedBill(entity, false);
validateQuota(entity);
// HCS 提交同步校验(事务内查询类同步,D15/R2-Q3):C101-1 风险(黑名单阻断)+ C106-1 额度(超额转特批)
// HCS 提交同步校验(事务内查询类同步,D15/R2-Q3):C101-1 风险(收款方外部客商高风险/黑名单须特批附件并标记待特批)+ C106-1 额度(超额转特批)
hcsCreditCheckSupport.checkOnSubmit(entity);
entity.setApprovalStatus(TransportBusiConstant.REVIEWING);
entity.setCurrentNode("财务审核");
@@ -388,6 +388,12 @@ private final CustomerReceiptAccountMapper receiptAccountMapper;
public String doSyncKingdee(Long id, KingdeeSyncContext context) {
PaymentApplication entity = lockedPayment(id);
if (!TransportBusiConstant.APPROVED.equals(entity.getApprovalStatus())) throw new ServiceException("仅审批通过的付款申请允许生成金蝶单据");
// 高风险/黑名单客商付款特批门禁:待特批/特批审核中(挂起"特批审核")禁止推送金蝶,
// 特批通过(合规 paymentLegal/result 回调恢复"审批通过")后放行
if (entity.getHcsSpecStatus() != null && List.of(HcsSyncConstant.SPEC_STATUS_NEED, HcsSyncConstant.SPEC_STATUS_PUSHING,
HcsSyncConstant.SPEC_STATUS_PROCESSING).contains(entity.getHcsSpecStatus())) {
throw new ServiceException("收款方客商为高风险/黑名单,付款特批审核中(" + entity.getCurrentNode() + "),特批完成后方可推送金蝶");
}
if (KingdeeBfiConstant.KINGDEE_STATUS_SYNCED.equals(entity.getKingdeeStatus())
|| KingdeeBfiConstant.KINGDEE_STATUS_PAYING.equals(entity.getKingdeeStatus())
|| KingdeeBfiConstant.KINGDEE_STATUS_PAID.equals(entity.getKingdeeStatus())
@@ -1505,8 +1511,8 @@ private final CustomerReceiptAccountMapper receiptAccountMapper;
private void saveSettlementRelations(PaymentApplication entity, List<FormalSettlement> settlements) {
if (settlements.isEmpty()) return;
settlementRelationMapper.delete(Wrappers.<PaymentApplicationSettlement>lambdaQuery()
.eq(PaymentApplicationSettlement::getPaymentApplicationId, entity.getId()));
// 关系唯一索引不含 is_deleted,逻辑删除会残留旧行导致重存冲突,此处必须物理删除
settlementRelationMapper.deleteByPaymentApplicationId(entity.getId());
BigDecimal totalBase = settlements.stream().map(item -> money(item.getSettlementAmount()).subtract(
cumulativeFormalSettlementApplied(item.getId(), entity.getId())).max(BigDecimal.ZERO))
.reduce(BigDecimal.ZERO, BigDecimal::add);