From f9038c62acb9826ca9d2e7e691171b8e401bc408 Mon Sep 17 00:00:00 2001 From: liuminghui <468701464@qq.com> Date: Mon, 16 Nov 2026 16:52:33 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B4=B9=E7=94=A8=E9=87=8D=E7=AE=97=E4=BC=98?= =?UTF-8?q?=E5=8C=96=E3=80=81=E6=97=A5=E5=BF=97=E8=AE=B0=E5=BD=95=E3=80=81?= =?UTF-8?q?=E8=B4=B9=E7=94=A8=E8=B0=83=E6=95=B4=E4=B8=BA=E9=80=BB=E8=BE=91?= =?UTF-8?q?=E5=88=A0=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bms/price/domain/PayOrderCostResult.java | 9 + .../bms/price/mapper/PrcPayBillFeeMapper.java | 6 +- .../price/service/PayBillFeeLogService.java | 73 +++++- .../service/impl/PayBillServiceImpl.java | 243 ++++++++++-------- .../service/impl/PayOrderCostServiceImpl.java | 36 ++- .../service/impl/PayOrderListServiceImpl.java | 133 ++++++---- .../mapper/price/PrcPayBillFeeMapper.xml | 12 +- .../sql/price/pay_fee_calc_soft_delete.sql | 5 + .../views/price/billing/payOrder/index.vue | 5 +- 9 files changed, 342 insertions(+), 180 deletions(-) create mode 100644 bms-back/sql/price/pay_fee_calc_soft_delete.sql diff --git a/bms-back/bms-system/src/main/java/com/bms/price/domain/PayOrderCostResult.java b/bms-back/bms-system/src/main/java/com/bms/price/domain/PayOrderCostResult.java index 2b6c8548..6b39e730 100644 --- a/bms-back/bms-system/src/main/java/com/bms/price/domain/PayOrderCostResult.java +++ b/bms-back/bms-system/src/main/java/com/bms/price/domain/PayOrderCostResult.java @@ -2,6 +2,7 @@ package com.bms.price.domain; import java.math.BigDecimal; import java.util.List; +import com.fasterxml.jackson.annotation.JsonIgnore; import lombok.Data; /** 按订单生成应付的结果。skipped 是价卡里有、但这票算不了的附加费。 */ @@ -29,4 +30,12 @@ public class PayOrderCostResult private List fees; private List skipped; + + /** 本次落库的应付费用,供提交成功后写日志。不返回给页面。 */ + @JsonIgnore + private transient List loggedFees; + + /** 本次费用日志的操作类型,字典 bms_pay_fee_log_type */ + @JsonIgnore + private transient String feeLogType; } diff --git a/bms-back/bms-system/src/main/java/com/bms/price/mapper/PrcPayBillFeeMapper.java b/bms-back/bms-system/src/main/java/com/bms/price/mapper/PrcPayBillFeeMapper.java index 13277ac6..043cd4e9 100644 --- a/bms-back/bms-system/src/main/java/com/bms/price/mapper/PrcPayBillFeeMapper.java +++ b/bms-back/bms-system/src/main/java/com/bms/price/mapper/PrcPayBillFeeMapper.java @@ -68,12 +68,14 @@ public interface PrcPayBillFeeMapper public int fillSourceIdByFeeIds(@Param("feeIds") List feeIds); /** - * 删除一票订单上来源为计算的费用。提单分摊和人工费用保留。 + * 逻辑删除一票订单上来源为计算的费用。提单分摊和人工费用保留。 + * 已进入应付账单的行不删。删除标记写成主键,避免重新生成时撞上唯一键。 * * @param billId 计费订单ID + * @param operator 操作人 * @return 影响行数 */ - public int deleteByBillId(Long billId); + public int markCalcDeleted(@Param("billId") Long billId, @Param("operator") String operator); /** * 逻辑删除某一条提单费用分摊到订单上的明细。 diff --git a/bms-back/bms-system/src/main/java/com/bms/price/service/PayBillFeeLogService.java b/bms-back/bms-system/src/main/java/com/bms/price/service/PayBillFeeLogService.java index 70e616f6..a04a34b9 100644 --- a/bms-back/bms-system/src/main/java/com/bms/price/service/PayBillFeeLogService.java +++ b/bms-back/bms-system/src/main/java/com/bms/price/service/PayBillFeeLogService.java @@ -7,6 +7,8 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Propagation; +import org.springframework.transaction.annotation.Transactional; import com.bms.common.utils.SecurityUtils; import com.bms.price.domain.PrcPayBillFee; import com.bms.price.domain.PrcPayBillFeeLog; @@ -35,7 +37,8 @@ public class PayBillFeeLogService /** 废弃 */ public static final String VOID = "5"; - private static final int BATCH_SIZE = 200; + /** 费用日志批量插入条数 */ + public static final int BATCH_SIZE = 1000; @Autowired private PrcPayBillFeeLogMapper payBillFeeLogMapper; @@ -77,6 +80,51 @@ public class PayBillFeeLogService } } + /** + * 把费用快照放进集合,不写库。调用方凑满 {@link #BATCH_SIZE} 再 {@link #flush}。 + * + * @param bucket 本次重算收集的日志 + * @param fees 已经提交成功的费用 + * @param operationType 字典值,见本类常量 + */ + public void collect(List bucket, List fees, String operationType) + { + if (bucket == null) + { + return; + } + try + { + bucket.addAll(snapshots(fees, operationType)); + } + catch (Exception ex) + { + log.error("收集应付费用日志失败 operationType={}", operationType, ex); + } + } + + /** + * 把集合里凑满的日志按 1000 条写入。不足 1000 的留给 {@link #drain}。写入失败只打印,不向外抛。 + * + * @param bucket 本次重算收集的日志 + */ + @Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Exception.class) + public void flush(List bucket) + { + write(bucket, false); + } + + /** + * 把集合里剩下的日志写完,最后一批可以不足 1000 条。写入失败只打印,不向外抛。 + * + * @param bucket 本次重算收集的日志 + */ + @Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Exception.class) + public void drain(List bucket) + { + write(bucket, true); + } + /** * 读取一票订单的费用日志。表还没建或查询失败时返回空列表,并打印错误。 * @@ -101,6 +149,29 @@ public class PayBillFeeLogService } } + private void write(List bucket, boolean drain) + { + if (bucket == null || bucket.isEmpty()) + { + return; + } + while (bucket.size() >= BATCH_SIZE || (drain && !bucket.isEmpty())) + { + int size = Math.min(BATCH_SIZE, bucket.size()); + List chunk = new ArrayList<>(bucket.subList(0, size)); + try + { + payBillFeeLogMapper.insertBatch(chunk); + bucket.subList(0, size).clear(); + } + catch (Exception ex) + { + log.error("写入应付费用日志失败 size={}", size, ex); + break; + } + } + } + private List snapshots(List fees, String operationType) { List rows = new ArrayList<>(); diff --git a/bms-back/bms-system/src/main/java/com/bms/price/service/impl/PayBillServiceImpl.java b/bms-back/bms-system/src/main/java/com/bms/price/service/impl/PayBillServiceImpl.java index d0c9a7ff..3b671a87 100644 --- a/bms-back/bms-system/src/main/java/com/bms/price/service/impl/PayBillServiceImpl.java +++ b/bms-back/bms-system/src/main/java/com/bms/price/service/impl/PayBillServiceImpl.java @@ -42,6 +42,7 @@ import com.bms.price.domain.PayBillOrder; import com.bms.price.domain.PayBillPreview; import com.bms.price.domain.PayOrderCostResult; import com.bms.price.domain.PrcPayBillFee; +import com.bms.price.domain.PrcPayBillFeeLog; import com.bms.price.mapper.PayBillMapper; import com.bms.price.mapper.PayFinanceMapper; import com.bms.price.mapper.PrcPayBillFeeMapper; @@ -159,127 +160,143 @@ public class PayBillServiceImpl implements IPayBillService Map versions = new HashMap<>(); List skipped = new ArrayList<>(); List billIds = new ArrayList<>(); - for (PayBillOrder order : orders) + List feeLogs = new ArrayList<>(); + try { - billIds.add(order.getBillId()); - if (payBillMapper.countCalcFees(order.getBillId()) > 0) + for (PayBillOrder order : orders) { - continue; - } - try - { - PayOrderCostResult cost = payOrderCostService.generateIsolated(order.getBillId()); - if (cost != null) + billIds.add(order.getBillId()); + if (payBillMapper.countCalcFees(order.getBillId()) > 0) { - versions.put(order.getBillId(), cost.getVersionNo()); + continue; + } + try + { + PayOrderCostResult cost = payOrderCostService.generateIsolated(order.getBillId()); + if (cost != null) + { + versions.put(order.getBillId(), cost.getVersionNo()); + payBillFeeLogService.collect(feeLogs, cost.getLoggedFees(), cost.getFeeLogType()); + if (feeLogs.size() >= PayBillFeeLogService.BATCH_SIZE) + { + payBillFeeLogService.flush(feeLogs); + } + } + } + catch (ServiceException ex) + { + skipped.add(order.getOrderNo() + ":" + ex.getMessage()); } } - catch (ServiceException ex) + List fees = billIds.isEmpty() ? new ArrayList<>() : payBillMapper.selectFreeFees(billIds); + List skippedParty = new ArrayList<>(); + fees = keepSupplierFees(fees, orders, supplier, skippedParty); + if (!fees.isEmpty() && fees.get(0).getCurrency() != null && !fees.get(0).getCurrency().isBlank()) { - skipped.add(order.getOrderNo() + ":" + ex.getMessage()); + currency = fees.get(0).getCurrency(); + } + List lines = new ArrayList<>(); + for (PrcPayBillFee fee : fees) + { + PayBillOrder order = findOrder(orders, fee.getBillId()); + PayBillLine line = new PayBillLine(); + line.setOrderBillId(fee.getBillId()); + line.setOrderNo(order == null ? "" : order.getOrderNo()); + line.setLadingNo(order == null ? "" : order.getLadingNo()); + line.setFeeId(fee.getFeeId()); + line.setFeeName(fee.getFeeName() == null || fee.getFeeName().isBlank() ? fee.getFeeType() : fee.getFeeName()); + line.setFeeSource(fee.getFeeSource()); + line.setFeeLevel(fee.getFeeLevel()); + line.setAmount(fee.getAmount()); + line.setDiffStatus("NONE"); + line.setCurrency(fee.getCurrency()); + line.setPriceDate(order == null || order.getBizDate() == null ? null : order.getBizDate()); + line.setVersionNo(versions.get(fee.getBillId())); + line.setLineSource("LADING".equals(fee.getFeeSource()) ? "LADING" : "ORDER"); + lines.add(line); + } + if (lines.isEmpty()) + { + List notes = new ArrayList<>(); + notes.addAll(skipped); + notes.addAll(skippedParty); + throw new ServiceException(notes.isEmpty() ? PaymentMesEnum.BMS_PAY_BILL_FEE.getCnMes() : String.join(";", notes)); + } + BigDecimal total = BigDecimal.ZERO; + for (PayBillLine line : lines) + { + String lineCurrency = line.getCurrency() == null ? "" : line.getCurrency(); + if (!currency.equals(lineCurrency)) + { + throw PaymentMesEnum.BMS_PAY_CURRENCY.exception(); + } + total = total.add(line.getAmount() == null ? BigDecimal.ZERO : line.getAmount()); + } + String operator = SecurityUtils.getUsername(); + PayBill bill = new PayBill(); + bill.setBillNo(nextNo()); + bill.setSupplierId(supplier.getSupplierId()); + bill.setSupplierName(supplier.getSupplierName()); + bill.setCurrency(currency); + bill.setSourceType(mode(command)); + bill.setPeriodStart(parseDay(command.getBeginDate())); + bill.setPeriodEnd(parseDay(command.getEndDate())); + Set orderIds = new HashSet<>(); + for (PayBillLine line : lines) + { + if (line.getOrderBillId() != null) + { + orderIds.add(line.getOrderBillId()); + } + } + BigDecimal scaled = total.setScale(2, RoundingMode.HALF_UP); + bill.setOrderCount(orderIds.size()); + bill.setTotalAmount(scaled); + bill.setSupplierAmount(scaled); + bill.setDiffAmount(BigDecimal.ZERO.setScale(2, RoundingMode.HALF_UP)); + bill.setPaidAmount(BigDecimal.ZERO.setScale(2, RoundingMode.HALF_UP)); + bill.setBillKind("BLUE"); + int termDays = supplier.getZq() == null || supplier.getZq() < 0 ? 30 : supplier.getZq().intValue(); + bill.setTermDays(termDays); + Date due = parseDay(command.getDueDate()); + bill.setDueDate(due == null ? java.sql.Date.valueOf(LocalDate.now().plusDays(termDays)) : due); + bill.setTaxRate(BigDecimal.ZERO.setScale(4, RoundingMode.HALF_UP)); + bill.setExchangeRate(BigDecimal.ONE); + bill.setAmountNet(scaled); + bill.setTaxAmount(BigDecimal.ZERO.setScale(2, RoundingMode.HALF_UP)); + bill.setBaseAmount(scaled); + bill.setRateDate(java.sql.Date.valueOf(LocalDate.now())); + bill.setCreateBy(operator); + bill.setRemark(command.getRemark()); + payBillMapper.insertPayBill(bill); + for (PayBillLine line : lines) + { + line.setBillId(bill.getBillId()); + payBillMapper.insertLine(line); + if (line.getFeeId() != null && !line.getFeeId().isBlank() && payBillMapper.bindFeeLine(line.getFeeId(), line.getLineId()) != 1) + { + throw PaymentMesEnum.BMS_PAY_FEE_TAKEN.exception(); + } + } + String desc = "生成应付账单,订单 " + orderIds.size() + " 票,费用 " + lines.size() + " 行"; + if (!skipped.isEmpty()) + { + desc = desc + ";未补尾程:" + String.join(";", skipped); + } + if (!skippedParty.isEmpty()) + { + desc = desc + ";未并入:" + String.join(";", skippedParty); + } + writeLog(bill.getBillId(), "CREATE", null, "DRAFT", desc.length() > 500 ? desc.substring(0, 500) : desc, operator); + return selectPayBillDetail(bill.getBillId()); + } + finally + { + if (!feeLogs.isEmpty()) + { + payBillFeeLogService.drain(feeLogs); } } - List fees = billIds.isEmpty() ? new ArrayList<>() : payBillMapper.selectFreeFees(billIds); - List skippedParty = new ArrayList<>(); - fees = keepSupplierFees(fees, orders, supplier, skippedParty); - if (!fees.isEmpty() && fees.get(0).getCurrency() != null && !fees.get(0).getCurrency().isBlank()) - { - currency = fees.get(0).getCurrency(); - } - List lines = new ArrayList<>(); - for (PrcPayBillFee fee : fees) - { - PayBillOrder order = findOrder(orders, fee.getBillId()); - PayBillLine line = new PayBillLine(); - line.setOrderBillId(fee.getBillId()); - line.setOrderNo(order == null ? "" : order.getOrderNo()); - line.setLadingNo(order == null ? "" : order.getLadingNo()); - line.setFeeId(fee.getFeeId()); - line.setFeeName(fee.getFeeName() == null || fee.getFeeName().isBlank() ? fee.getFeeType() : fee.getFeeName()); - line.setFeeSource(fee.getFeeSource()); - line.setFeeLevel(fee.getFeeLevel()); - line.setAmount(fee.getAmount()); - line.setDiffStatus("NONE"); - line.setCurrency(fee.getCurrency()); - line.setPriceDate(order == null || order.getBizDate() == null ? null : order.getBizDate()); - line.setVersionNo(versions.get(fee.getBillId())); - line.setLineSource("LADING".equals(fee.getFeeSource()) ? "LADING" : "ORDER"); - lines.add(line); - } - if (lines.isEmpty()) - { - List notes = new ArrayList<>(); - notes.addAll(skipped); - notes.addAll(skippedParty); - throw new ServiceException(notes.isEmpty() ? PaymentMesEnum.BMS_PAY_BILL_FEE.getCnMes() : String.join(";", notes)); - } - BigDecimal total = BigDecimal.ZERO; - for (PayBillLine line : lines) - { - String lineCurrency = line.getCurrency() == null ? "" : line.getCurrency(); - if (!currency.equals(lineCurrency)) - { - throw PaymentMesEnum.BMS_PAY_CURRENCY.exception(); - } - total = total.add(line.getAmount() == null ? BigDecimal.ZERO : line.getAmount()); - } - String operator = SecurityUtils.getUsername(); - PayBill bill = new PayBill(); - bill.setBillNo(nextNo()); - bill.setSupplierId(supplier.getSupplierId()); - bill.setSupplierName(supplier.getSupplierName()); - bill.setCurrency(currency); - bill.setSourceType(mode(command)); - bill.setPeriodStart(parseDay(command.getBeginDate())); - bill.setPeriodEnd(parseDay(command.getEndDate())); - Set orderIds = new HashSet<>(); - for (PayBillLine line : lines) - { - if (line.getOrderBillId() != null) - { - orderIds.add(line.getOrderBillId()); - } - } - BigDecimal scaled = total.setScale(2, RoundingMode.HALF_UP); - bill.setOrderCount(orderIds.size()); - bill.setTotalAmount(scaled); - bill.setSupplierAmount(scaled); - bill.setDiffAmount(BigDecimal.ZERO.setScale(2, RoundingMode.HALF_UP)); - bill.setPaidAmount(BigDecimal.ZERO.setScale(2, RoundingMode.HALF_UP)); - bill.setBillKind("BLUE"); - int termDays = supplier.getZq() == null || supplier.getZq() < 0 ? 30 : supplier.getZq().intValue(); - bill.setTermDays(termDays); - Date due = parseDay(command.getDueDate()); - bill.setDueDate(due == null ? java.sql.Date.valueOf(LocalDate.now().plusDays(termDays)) : due); - bill.setTaxRate(BigDecimal.ZERO.setScale(4, RoundingMode.HALF_UP)); - bill.setExchangeRate(BigDecimal.ONE); - bill.setAmountNet(scaled); - bill.setTaxAmount(BigDecimal.ZERO.setScale(2, RoundingMode.HALF_UP)); - bill.setBaseAmount(scaled); - bill.setRateDate(java.sql.Date.valueOf(LocalDate.now())); - bill.setCreateBy(operator); - bill.setRemark(command.getRemark()); - payBillMapper.insertPayBill(bill); - for (PayBillLine line : lines) - { - line.setBillId(bill.getBillId()); - payBillMapper.insertLine(line); - if (line.getFeeId() != null && !line.getFeeId().isBlank() && payBillMapper.bindFeeLine(line.getFeeId(), line.getLineId()) != 1) - { - throw PaymentMesEnum.BMS_PAY_FEE_TAKEN.exception(); - } - } - String desc = "生成应付账单,订单 " + orderIds.size() + " 票,费用 " + lines.size() + " 行"; - if (!skipped.isEmpty()) - { - desc = desc + ";未补尾程:" + String.join(";", skipped); - } - if (!skippedParty.isEmpty()) - { - desc = desc + ";未并入:" + String.join(";", skippedParty); - } - writeLog(bill.getBillId(), "CREATE", null, "DRAFT", desc.length() > 500 ? desc.substring(0, 500) : desc, operator); - return selectPayBillDetail(bill.getBillId()); } /** diff --git a/bms-back/bms-system/src/main/java/com/bms/price/service/impl/PayOrderCostServiceImpl.java b/bms-back/bms-system/src/main/java/com/bms/price/service/impl/PayOrderCostServiceImpl.java index c5d2db1b..0fd44914 100644 --- a/bms-back/bms-system/src/main/java/com/bms/price/service/impl/PayOrderCostServiceImpl.java +++ b/bms-back/bms-system/src/main/java/com/bms/price/service/impl/PayOrderCostServiceImpl.java @@ -111,7 +111,12 @@ public class PayOrderCostServiceImpl implements IPayOrderCostService { return null; } - return generate(billId); + PayOrderCostResult result = generate(billId); + if (result != null) + { + payBillFeeLogService.record(result.getLoggedFees(), result.getFeeLogType()); + } + return result; } @Override @@ -157,7 +162,7 @@ public class PayOrderCostServiceImpl implements IPayOrderCostService } String operator = SecurityUtils.getUsername(); PrcPayBill payBill = saveBill(bill, result, operator); - saveFees(bill.getBillId(), payBill.getPayBillId(), result.getFees()); + saveFees(bill.getBillId(), payBill.getPayBillId(), result); String channelName = channel.getChannelName() == null ? channel.getChannelCode() : channel.getChannelName(); String end = product.getTermEnd() == null ? "不限" : day(product.getTermEnd()); result.setMessage("渠道「" + channelName + "」" + product.getProductName() + " 第 " + product.getVersionNo() @@ -640,18 +645,20 @@ public class PayOrderCostServiceImpl implements IPayOrderCostService } /** - * 用本次算出的尾程费用替换订单上的计算费用。来源不是计算的费用行会保留。 + * 用本次算出的尾程费用替换订单上的计算费用。原来的计算费用改为逻辑删除,提单分摊和人工费用保留。 + * 新费用只挂到结果上,等事务提交后再写日志。 * * @param billId 计费订单ID * @param payBillId 订单应付主表ID - * @param fees 本次算出的费用 + * @param result 本次计费结果,算出的费用在其中 */ - private void saveFees(Long billId, String payBillId, List fees) + private void saveFees(Long billId, String payBillId, PayOrderCostResult result) { boolean recalc = hasCalcFee(billId); - payBillFeeMapper.deleteByBillId(billId); + payBillFeeMapper.markCalcDeleted(billId, operator()); List rows = new java.util.ArrayList<>(); long fallback = 1L; + List fees = result.getFees() == null ? java.util.List.of() : result.getFees(); for (PayCostLine fee : fees) { PrcPayBillFee row = new PrcPayBillFee(); @@ -680,7 +687,8 @@ public class PayOrderCostServiceImpl implements IPayOrderCostService { payBillFeeService.refreshTotals(java.util.List.of(billId)); } - payBillFeeLogService.record(rows, recalc ? PayBillFeeLogService.RECALC : PayBillFeeLogService.ADD); + result.setLoggedFees(rows); + result.setFeeLogType(recalc ? PayBillFeeLogService.RECALC : PayBillFeeLogService.ADD); } /** 这票订单上还有没删除的计算费用。有则本次落库是重算,没有则是首次生成。 */ @@ -706,6 +714,20 @@ public class PayOrderCostServiceImpl implements IPayOrderCostService return false; } + /** 当前登录人。没有登录信息时记 system。 */ + private static String operator() + { + try + { + String name = SecurityUtils.getUsername(); + return name == null || name.isBlank() ? "system" : name; + } + catch (Exception ignored) + { + return "system"; + } + } + /** * 把日期格式化成 yyyy-MM-dd,供结果说明使用。空日期表示不限。 * diff --git a/bms-back/bms-system/src/main/java/com/bms/price/service/impl/PayOrderListServiceImpl.java b/bms-back/bms-system/src/main/java/com/bms/price/service/impl/PayOrderListServiceImpl.java index a2dad76a..0f13c57d 100644 --- a/bms-back/bms-system/src/main/java/com/bms/price/service/impl/PayOrderListServiceImpl.java +++ b/bms-back/bms-system/src/main/java/com/bms/price/service/impl/PayOrderListServiceImpl.java @@ -14,6 +14,7 @@ import org.springframework.transaction.annotation.Transactional; import com.bms.common.enums.PaymentMesEnum; import com.bms.common.exception.ServiceException; import com.bms.common.utils.SecurityUtils; +import com.bms.price.domain.PayOrderCostResult; import com.bms.price.domain.PayOrderFeeBoard; import com.bms.price.domain.PrcPayBill; import com.bms.price.domain.PayOrderFeeLine; @@ -24,6 +25,7 @@ import com.bms.price.domain.PayOrderRecalcLine; import com.bms.price.domain.PayOrderRecalcResult; import com.bms.price.domain.PayOrderRow; import com.bms.price.domain.PrcPayBillFee; +import com.bms.price.domain.PrcPayBillFeeLog; import com.bms.price.mapper.PayOrderListMapper; import com.bms.price.mapper.PrcPayBillFeeMapper; import com.bms.price.mapper.PrcPayBillMapper; @@ -37,6 +39,8 @@ public class PayOrderListServiceImpl implements IPayOrderListService { private static final int MAX_ORDER_NOS = 500; + private static final int MAX_LADING_NOS = 10; + private static final Map TITLES = new LinkedHashMap<>(); static @@ -106,90 +110,113 @@ public class PayOrderListServiceImpl implements IPayOrderListService { throw new ServiceException("请填写单号"); } - if (nos.size() > MAX_ORDER_NOS) - { - throw new ServiceException("一次最多重算" + MAX_ORDER_NOS + "个单号"); - } boolean byOrder = "ORDER".equalsIgnoreCase(source); boolean byLading = "LADING".equalsIgnoreCase(source); if (!byOrder && !byLading) { throw new ServiceException("请选择按订单号或按提单号重算"); } + if (byLading && nos.size() > MAX_LADING_NOS) + { + throw new ServiceException("一次最多重算" + MAX_LADING_NOS + "个提单号"); + } + if (byOrder && nos.size() > MAX_ORDER_NOS) + { + throw new ServiceException("一次最多重算" + MAX_ORDER_NOS + "个订单号"); + } List found = byOrder ? payOrderListMapper.selectByOrderNos(nos) : payOrderListMapper.selectByLadingNos(nos); if (found == null) { found = new ArrayList<>(); } - if (found.size() > MAX_ORDER_NOS) + if (byOrder && found.size() > MAX_ORDER_NOS) { throw new ServiceException("一次最多重算" + MAX_ORDER_NOS + "票订单"); } PayOrderRecalcResult result = new PayOrderRecalcResult(); + List feeLogs = new ArrayList<>(); LinkedHashSet hit = new LinkedHashSet<>(); - for (PayOrderRow order : found) + try { - if (order == null || order.getBillId() == null || order.getBillId().isBlank()) + for (PayOrderRow order : found) { - continue; - } - hit.add(byOrder ? order.getOrderNo() : order.getLadingNo()); - PayOrderRecalcLine line = new PayOrderRecalcLine(); - line.setOrderNo(order.getOrderNo()); - line.setLadingNo(order.getLadingNo()); - if (payBillFeeMapper.countSettledCalc(Long.valueOf(order.getBillId().trim())) > 0) - { - line.setSuccess(false); - line.setMessage("费用已进入应付账单,未重算"); - result.getLines().add(line); - result.setFailCount(result.getFailCount() + 1); - continue; - } - try - { - payOrderCostService.generateIsolated(Long.valueOf(order.getBillId().trim())); - line.setSuccess(true); - result.setSuccessCount(result.getSuccessCount() + 1); - } - catch (Exception ex) - { - String message = ex.getMessage() == null ? "应付费用生成失败" : ex.getMessage(); + if (order == null || order.getBillId() == null || order.getBillId().isBlank()) + { + continue; + } + hit.add(byOrder ? order.getOrderNo() : order.getLadingNo()); + PayOrderRecalcLine line = new PayOrderRecalcLine(); + line.setOrderNo(order.getOrderNo()); + line.setLadingNo(order.getLadingNo()); + if (payBillFeeMapper.countSettledCalc(Long.valueOf(order.getBillId().trim())) > 0) + { + line.setSuccess(false); + line.setMessage("费用已进入应付账单,未重算"); + result.getLines().add(line); + result.setFailCount(result.getFailCount() + 1); + continue; + } try { - payOrderCostService.markCalcFail(Long.valueOf(order.getBillId().trim()), message); + PayOrderCostResult cost = payOrderCostService.generateIsolated(Long.valueOf(order.getBillId().trim())); + line.setSuccess(true); + result.setSuccessCount(result.getSuccessCount() + 1); + if (cost != null) + { + payBillFeeLogService.collect(feeLogs, cost.getLoggedFees(), cost.getFeeLogType()); + if (feeLogs.size() >= PayBillFeeLogService.BATCH_SIZE) + { + payBillFeeLogService.flush(feeLogs); + } + } } - catch (Exception markEx) + catch (Exception ex) { - message = message + ";计费状态未写入"; + String message = ex.getMessage() == null ? "应付费用生成失败" : ex.getMessage(); + try + { + payOrderCostService.markCalcFail(Long.valueOf(order.getBillId().trim()), message); + } + catch (Exception markEx) + { + message = message + ";计费状态未写入"; + } + line.setSuccess(false); + line.setMessage(message); + result.setFailCount(result.getFailCount() + 1); + } + result.getLines().add(line); + } + for (String no : nos) + { + if (hit.contains(no)) + { + continue; + } + PayOrderRecalcLine line = new PayOrderRecalcLine(); + if (byOrder) + { + line.setOrderNo(no); + line.setMessage("没有找到这个订单"); + } + else + { + line.setLadingNo(no); + line.setMessage("这个提单下没有订单"); } line.setSuccess(false); - line.setMessage(message); + result.getLines().add(line); result.setFailCount(result.getFailCount() + 1); } - result.getLines().add(line); + return result; } - for (String no : nos) + finally { - if (hit.contains(no)) + if (!feeLogs.isEmpty()) { - continue; + payBillFeeLogService.drain(feeLogs); } - PayOrderRecalcLine line = new PayOrderRecalcLine(); - if (byOrder) - { - line.setOrderNo(no); - line.setMessage("没有找到这个订单"); - } - else - { - line.setLadingNo(no); - line.setMessage("这个提单下没有订单"); - } - line.setSuccess(false); - result.getLines().add(line); - result.setFailCount(result.getFailCount() + 1); } - return result; } @Override diff --git a/bms-back/bms-system/src/main/resources/mapper/price/PrcPayBillFeeMapper.xml b/bms-back/bms-system/src/main/resources/mapper/price/PrcPayBillFeeMapper.xml index 8a8d4027..586192ab 100644 --- a/bms-back/bms-system/src/main/resources/mapper/price/PrcPayBillFeeMapper.xml +++ b/bms-back/bms-system/src/main/resources/mapper/price/PrcPayBillFeeMapper.xml @@ -168,9 +168,15 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" and statement_line_id is not null - - delete from prc_pay_bill_fee + + update prc_pay_bill_fee + set is_deleted = '1', + deleted_mark = id, + update_by = #{operator}, + update_time = sysdate() where bill_id = #{billId} + and ifnull(is_deleted, '0') = '0' + and statement_line_id is null and (fee_source is null or fee_source = '' or fee_source = 'CALC') - + diff --git a/bms-back/sql/price/pay_fee_calc_soft_delete.sql b/bms-back/sql/price/pay_fee_calc_soft_delete.sql new file mode 100644 index 00000000..ca51521d --- /dev/null +++ b/bms-back/sql/price/pay_fee_calc_soft_delete.sql @@ -0,0 +1,5 @@ +-- `prc_pay_bill_fee` 增加逻辑删除标记 +ALTER TABLE `bms`.`prc_pay_bill_fee` ADD COLUMN `deleted_mark` bigint(20) NOT NULL DEFAULT 0 COMMENT '未删除为0,逻辑删除时写入本行主键,避免重新生成时撞上唯一键' AFTER `is_deleted`; + +-- `prc_pay_bill_fee` 唯一键带上逻辑删除标记 +ALTER TABLE `bms`.`prc_pay_bill_fee` DROP INDEX `uk_pay_bill_fee_item`, ADD UNIQUE KEY `uk_pay_bill_fee_item` (`bill_id`, `fee_type`, `sc_id`, `deleted_mark`); diff --git a/bms-front/src/views/price/billing/payOrder/index.vue b/bms-front/src/views/price/billing/payOrder/index.vue index c860f515..ddea23c2 100644 --- a/bms-front/src/views/price/billing/payOrder/index.vue +++ b/bms-front/src/views/price/billing/payOrder/index.vue @@ -133,7 +133,7 @@ - +
@@ -178,6 +178,9 @@ const feeLogs = ref([]) const recalcOpen = ref(false) const recalcSaving = ref(false) const recalcForm = reactive({ sourceType: 'ORDER', text: '' }) +const recalcPlaceholder = computed(() => recalcForm.sourceType === 'LADING' + ? '多个提单号可用逗号、空格或换行分隔,一次最多10个' + : '多个订单号可用逗号、空格或换行分隔,一次最多500个') const recalcResult = ref(null) const recalcFails = computed(() => (recalcResult.value?.lines || []).filter(line => !line.success))