费用重算优化、日志记录、费用调整为逻辑删除

This commit is contained in:
liuminghui
2026-11-16 16:52:33 +08:00
parent 49f24a6b1b
commit f9038c62ac
9 changed files with 342 additions and 180 deletions
@@ -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<PayCostLine> fees;
private List<String> skipped;
/** 本次落库的应付费用,供提交成功后写日志。不返回给页面。 */
@JsonIgnore
private transient List<PrcPayBillFee> loggedFees;
/** 本次费用日志的操作类型,字典 bms_pay_fee_log_type */
@JsonIgnore
private transient String feeLogType;
}
@@ -68,12 +68,14 @@ public interface PrcPayBillFeeMapper
public int fillSourceIdByFeeIds(@Param("feeIds") List<String> feeIds);
/**
* 删除一票订单上来源为计算的费用。提单分摊和人工费用保留。
* 逻辑删除一票订单上来源为计算的费用。提单分摊和人工费用保留。
* 已进入应付账单的行不删。删除标记写成主键,避免重新生成时撞上唯一键。
*
* @param billId 计费订单ID
* @param operator 操作人
* @return 影响行数
*/
public int deleteByBillId(Long billId);
public int markCalcDeleted(@Param("billId") Long billId, @Param("operator") String operator);
/**
* 逻辑删除某一条提单费用分摊到订单上的明细。
@@ -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<PrcPayBillFeeLog> bucket, List<PrcPayBillFee> 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<PrcPayBillFeeLog> bucket)
{
write(bucket, false);
}
/**
* 把集合里剩下的日志写完,最后一批可以不足 1000 条。写入失败只打印,不向外抛。
*
* @param bucket 本次重算收集的日志
*/
@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Exception.class)
public void drain(List<PrcPayBillFeeLog> bucket)
{
write(bucket, true);
}
/**
* 读取一票订单的费用日志。表还没建或查询失败时返回空列表,并打印错误。
*
@@ -101,6 +149,29 @@ public class PayBillFeeLogService
}
}
private void write(List<PrcPayBillFeeLog> 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<PrcPayBillFeeLog> 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<PrcPayBillFeeLog> snapshots(List<PrcPayBillFee> fees, String operationType)
{
List<PrcPayBillFeeLog> rows = new ArrayList<>();
@@ -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<Long, Integer> versions = new HashMap<>();
List<String> skipped = new ArrayList<>();
List<Long> billIds = new ArrayList<>();
for (PayBillOrder order : orders)
List<PrcPayBillFeeLog> 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<PrcPayBillFee> fees = billIds.isEmpty() ? new ArrayList<>() : payBillMapper.selectFreeFees(billIds);
List<String> 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<PayBillLine> 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<String> 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<Long> 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<PrcPayBillFee> fees = billIds.isEmpty() ? new ArrayList<>() : payBillMapper.selectFreeFees(billIds);
List<String> 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<PayBillLine> 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<String> 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<Long> 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());
}
/**
@@ -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<PayCostLine> fees)
private void saveFees(Long billId, String payBillId, PayOrderCostResult result)
{
boolean recalc = hasCalcFee(billId);
payBillFeeMapper.deleteByBillId(billId);
payBillFeeMapper.markCalcDeleted(billId, operator());
List<PrcPayBillFee> rows = new java.util.ArrayList<>();
long fallback = 1L;
List<PayCostLine> 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,供结果说明使用。空日期表示不限。
*
@@ -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<String, String> 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<PayOrderRow> 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<PrcPayBillFeeLog> feeLogs = new ArrayList<>();
LinkedHashSet<String> 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
@@ -168,9 +168,15 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
and statement_line_id is not null
</select>
<delete id="deleteByBillId" parameterType="Long">
delete from prc_pay_bill_fee
<update id="markCalcDeleted">
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')
</delete>
</update>
</mapper>
@@ -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`);