调整收付款问题

This commit is contained in:
2026-09-01 11:52:15 +08:00
parent a4599c48c5
commit 1363a526ff
5 changed files with 75 additions and 49 deletions
@@ -40,6 +40,16 @@ import java.util.List;
*/
public interface AirportMasterMapper extends BaseMapper<AirportMaster> {
/**
* 按编码查询空港机场(包含逻辑删除记录,用于唯一性校验)。
*/
AirportMaster selectByCodeIncludingDeleted(@Param("code") String code);
/**
* 恢复逻辑删除空港机场。
*/
int restoreById(@Param("id") Long id);
/**
* 自定义分页
*
@@ -32,6 +32,20 @@
<result column="remark" property="remark"/>
</resultMap>
<select id="selectByCodeIncludingDeleted" resultMap="airportMasterResultMap">
SELECT
am.*
FROM blade_airport_master am
WHERE am.code = #{code}
</select>
<update id="restoreById">
UPDATE blade_airport_master
SET is_deleted = 0
WHERE id = #{id}
AND is_deleted = 1
</update>
<select id="selectAirportMasterPage" resultMap="airportMasterResultMap">
SELECT
am.id,
@@ -98,6 +98,7 @@ public class AirportMasterServiceImpl extends BaseServiceImpl<AirportMasterMappe
public boolean submit(AirportMaster airportMaster) {
prepare(airportMaster, SOURCE_MANUAL);
validate(airportMaster);
prepareSubmitTarget(airportMaster);
return saveOrUpdate(airportMaster);
}
@@ -479,6 +480,22 @@ public class AirportMasterServiceImpl extends BaseServiceImpl<AirportMasterMappe
}
}
private void prepareSubmitTarget(AirportMaster airportMaster) {
if (Func.isNotEmpty(airportMaster.getId())) {
return;
}
AirportMaster existingAirportMaster = baseMapper.selectByCodeIncludingDeleted(airportMaster.getCode());
if (existingAirportMaster == null) {
return;
}
if (!Objects.equals(existingAirportMaster.getIsDeleted(), 1)) {
throw new ServiceException("该编码已存在");
}
baseMapper.restoreById(existingAirportMaster.getId());
airportMaster.setId(existingAirportMaster.getId());
airportMaster.setIsDeleted(0);
}
private void validateUnique(AirportMaster airportMaster, com.baomidou.mybatisplus.core.toolkit.support.SFunction<AirportMaster, ?> column, String value, String message) {
if (Func.isEmpty(value)) {
return;
@@ -210,14 +210,22 @@ public class FormalSettlementServiceImpl extends BaseServiceImpl<FormalSettlemen
vo.setPayments(paymentMapper.selectList(Wrappers.<FormalSettlementPayment>lambdaQuery()
.eq(FormalSettlementPayment::getFormalSettlementId, id).orderByDesc(FormalSettlementPayment::getCreateTime)));
vo.setInvoices(listInvoices(settlement));
List<Long> preSettlementIds = sources.stream().map(FormalSettlementSource::getPreSettlementId).toList();
Set<Long> relationApplicationIds = paymentApplicationSettlementMapper.selectList(
Wrappers.<PaymentApplicationSettlement>lambdaQuery()
.select(PaymentApplicationSettlement::getPaymentApplicationId)
.eq(PaymentApplicationSettlement::getFormalSettlementId, id)
.eq(PaymentApplicationSettlement::getIsDeleted, 0)).stream()
.map(PaymentApplicationSettlement::getPaymentApplicationId).filter(Objects::nonNull)
.collect(Collectors.toSet());
LambdaQueryWrapper<PaymentApplication> paymentApplicationQuery = Wrappers.<PaymentApplication>lambdaQuery();
if (preSettlementIds.isEmpty()) {
paymentApplicationQuery.eq(PaymentApplication::getSettlementId, id);
} else {
paymentApplicationQuery.and(query -> query.eq(PaymentApplication::getSettlementId, id)
.or().in(PaymentApplication::getPreSettlementId, preSettlementIds));
}
paymentApplicationQuery.and(query -> {
query.eq(PaymentApplication::getSettlementId, id);
if (!relationApplicationIds.isEmpty()) {
query.or(wrapper -> wrapper.in(PaymentApplication::getId, relationApplicationIds));
}
})
.eq(PaymentApplication::getPaymentType, "settlement_payment")
.eq(PaymentApplication::getIsDeleted, 0);
vo.setPaymentApplications(paymentApplicationMapper.selectList(paymentApplicationQuery
.orderByDesc(PaymentApplication::getCreateTime)).stream()
.map(item -> PaymentApplicationWrapper.build().entityVO(item)).toList());
@@ -350,8 +358,10 @@ public class FormalSettlementServiceImpl extends BaseServiceImpl<FormalSettlemen
applySummaryRequest(settlement.getId(), request.getSummaryFees());
refreshSettlementAmount(settlement);
rebuildInvoices(settlement, request.getInvoices());
saveChange(settlement.getId(), "结算单基本信息", null, creating ? "新增" : "调整",
(creating ? "创建" : "保存") + "正式结算单" + settlement.getFormalSettlementNo(), request.getRemark());
if (!creating) {
saveChange(settlement.getId(), "结算单基本信息", null, "调整",
"保存正式结算单" + settlement.getFormalSettlementNo(), request.getRemark());
}
return settlement.getId();
}
@@ -1016,18 +1026,10 @@ public class FormalSettlementServiceImpl extends BaseServiceImpl<FormalSettlemen
}
private PaymentSummary calculatePaymentSummary(FormalSettlement settlement) {
List<Long> preSettlementIds = sourceMapper.selectList(Wrappers.<FormalSettlementSource>lambdaQuery()
.eq(FormalSettlementSource::getFormalSettlementId, settlement.getId())
.eq(FormalSettlementSource::getIsDeleted, 0)).stream()
.map(FormalSettlementSource::getPreSettlementId).filter(Objects::nonNull).toList();
LambdaQueryWrapper<PaymentApplication> query = Wrappers.<PaymentApplication>lambdaQuery()
.eq(PaymentApplication::getSettlementId, settlement.getId())
.eq(PaymentApplication::getPaymentType, "settlement_payment")
.eq(PaymentApplication::getIsDeleted, 0);
if (preSettlementIds.isEmpty()) {
query.eq(PaymentApplication::getSettlementId, settlement.getId());
} else {
query.and(wrapper -> wrapper.eq(PaymentApplication::getSettlementId, settlement.getId())
.or().in(PaymentApplication::getPreSettlementId, preSettlementIds));
}
List<PaymentApplicationSettlement> relations = paymentApplicationSettlementMapper.selectList(
Wrappers.<PaymentApplicationSettlement>lambdaQuery()
.eq(PaymentApplicationSettlement::getFormalSettlementId, settlement.getId())
@@ -1045,7 +1047,8 @@ public class FormalSettlementServiceImpl extends BaseServiceImpl<FormalSettlemen
.map(PaymentApplication::getPaidAmount).map(this::money)
.reduce(BigDecimal.ZERO, BigDecimal::add);
Map<Long, String> relationStatuses = relationApplicationIds.isEmpty() ? Map.of() : paymentApplicationMapper.selectList(
Wrappers.<PaymentApplication>lambdaQuery().in(PaymentApplication::getId, relationApplicationIds))
Wrappers.<PaymentApplication>lambdaQuery().select(PaymentApplication::getId, PaymentApplication::getApprovalStatus)
.in(PaymentApplication::getId, relationApplicationIds).eq(PaymentApplication::getIsDeleted, 0))
.stream().collect(Collectors.toMap(PaymentApplication::getId, PaymentApplication::getApprovalStatus));
appliedAmount = appliedAmount.add(relations.stream()
.filter(item -> REVIEWING.equals(relationStatuses.get(item.getPaymentApplicationId())))
@@ -1055,30 +1058,13 @@ public class FormalSettlementServiceImpl extends BaseServiceImpl<FormalSettlemen
.filter(item -> APPROVED.equals(relationStatuses.get(item.getPaymentApplicationId())))
.map(PaymentApplicationSettlement::getPaidAmount).map(this::money)
.reduce(BigDecimal.ZERO, BigDecimal::add));
List<FormalSettlementPayment> legacyPayments = paymentMapper.selectList(
Wrappers.<FormalSettlementPayment>lambdaQuery()
.eq(FormalSettlementPayment::getFormalSettlementId, settlement.getId())
.eq(FormalSettlementPayment::getIsDeleted, 0));
appliedAmount = appliedAmount.add(legacyPayments.stream()
.filter(item -> REVIEWING.equals(item.getBillStatus()))
.map(FormalSettlementPayment::getAppliedAmount).map(this::money)
.reduce(BigDecimal.ZERO, BigDecimal::add));
paidAmount = paidAmount.add(legacyPayments.stream()
.filter(item -> APPROVED.equals(item.getBillStatus()))
.map(FormalSettlementPayment::getPaidAmount).map(this::money)
.reduce(BigDecimal.ZERO, BigDecimal::add));
paidAmount = paidAmount.add(sourceMapper.selectList(Wrappers.<FormalSettlementSource>lambdaQuery()
.eq(FormalSettlementSource::getFormalSettlementId, settlement.getId())
.eq(FormalSettlementSource::getIsDeleted, 0)).stream()
.map(FormalSettlementSource::getAdvancePaidAmount).map(this::money)
.reduce(BigDecimal.ZERO, BigDecimal::add));
if ("receivable".equals(settlement.getSettlementType())) {
paidAmount = paidAmount.add(receiptClaimSettlementMapper.selectList(
paidAmount = receiptClaimSettlementMapper.selectList(
Wrappers.<ReceiptClaimSettlement>lambdaQuery()
.eq(ReceiptClaimSettlement::getFormalSettlementId, settlement.getId())
.eq(ReceiptClaimSettlement::getStatus, 1))
.stream().map(ReceiptClaimSettlement::getAllocatedReceiptAmount).map(this::money)
.reduce(BigDecimal.ZERO, BigDecimal::add));
.reduce(BigDecimal.ZERO, BigDecimal::add);
}
return new PaymentSummary(money(appliedAmount), money(paidAmount));
}
@@ -140,22 +140,21 @@ public class PreSettlementServiceImpl extends BaseServiceImpl<PreSettlementMappe
List<PaymentApplication> applications = paymentApplicationMapper.selectList(
Wrappers.<PaymentApplication>lambdaQuery()
.select(PaymentApplication::getPreSettlementId, PaymentApplication::getAppliedAmount,
PaymentApplication::getPaidAmount, PaymentApplication::getApprovalStatus)
PaymentApplication::getPaidAmount)
.eq(PaymentApplication::getPaymentType, "progress_advance")
.in(PaymentApplication::getPreSettlementId, preSettlementIds)
.in(PaymentApplication::getApprovalStatus, STATUS_REVIEWING, STATUS_APPROVED)
.eq(PaymentApplication::getApprovalStatus, STATUS_APPROVED)
.eq(PaymentApplication::getIsDeleted, 0));
Map<Long, BigDecimal> reviewingAmounts = new HashMap<>();
Map<Long, BigDecimal> approvedAmounts = new HashMap<>();
Map<Long, BigDecimal> appliedAmounts = new HashMap<>();
Map<Long, BigDecimal> paidAmounts = new HashMap<>();
applications.forEach(application -> {
boolean reviewing = STATUS_REVIEWING.equals(application.getApprovalStatus());
Map<Long, BigDecimal> amounts = reviewing ? reviewingAmounts : approvedAmounts;
BigDecimal amount = reviewing ? application.getAppliedAmount() : application.getPaidAmount();
amounts.merge(application.getPreSettlementId(), money(amount), BigDecimal::add);
Long preSettlementId = application.getPreSettlementId();
appliedAmounts.merge(preSettlementId, money(application.getAppliedAmount()), BigDecimal::add);
paidAmounts.merge(preSettlementId, money(application.getPaidAmount()), BigDecimal::add);
});
records.forEach(record -> {
record.setAdvanceAppliedAmount(money(reviewingAmounts.get(record.getId())));
record.setAdvancePaidAmount(money(approvedAmounts.get(record.getId())));
record.setAdvanceAppliedAmount(money(appliedAmounts.get(record.getId())));
record.setAdvancePaidAmount(money(paidAmounts.get(record.getId())));
});
}