This commit is contained in:
wuweihua
2026-11-18 09:41:23 +08:00
13 changed files with 84 additions and 50 deletions
@@ -44,7 +44,7 @@ public enum PaymentMesEnum
BMS_PAY_PICK_CH("BMS_PAY_PICK_CH", "渠道绑定产品", "请先勾选渠道"),
BMS_PAY_PICK_SIDE("BMS_PAY_PICK_SIDE", "渠道绑定产品", "请至少选择应付或应收产品"),
BMS_PAY_BIND_NONE("BMS_PAY_BIND_NONE", "渠道绑定产品", "没有可绑定的渠道"),
BMS_PAY_CH_PROD("BMS_PAY_CH_PROD", "渠道应付产品", "渠道还没有选择应付产品"),
BMS_PAY_CH_PROD("BMS_PAY_CH_PROD", "渠道应付价卡", "渠道还没有选择应付价卡"),
BMS_PAY_OUT_TERM("BMS_PAY_OUT_TERM", "应付价格有效期", "订单时间没有落在价格有效期内"),
BMS_PAY_TWO_VER("BMS_PAY_TWO_VER", "应付价格对比", "请选择两个价格版本"),
BMS_PAY_AR_AP("BMS_PAY_AR_AP", "收付类型", "收付类型只能是应收AR或应付AP"),
@@ -63,6 +63,10 @@ public class PrcPayBillFee implements Serializable
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date updateTime;
/** 订单计费日,只在折算汇率时使用,不入库 */
@JsonIgnore
private Date bizDate;
/** 写日志时带上的变更前费用项,不入库 */
@JsonIgnore
private String logBeforeName;
@@ -94,6 +94,9 @@ public interface PrcPayBillFeeMapper
/** 明细还没挂上应付主表时,按订单补上主表 ID。单次不超过 1000 个订单。 */
public int bindPayBillId(@Param("billIds") List<Long> billIds);
/** 这些订单上未删除的应付明细。带上订单计费日,汇总时用来取汇率。 */
public List<PrcPayBillFee> selectOpenFees(@Param("billIds") List<Long> billIds);
/**
* 这条提单费用分摊到的订单里,取一个已经生成应付账单的订单号。
* 是否出账看 prc_order_bill_ext.is_meet:1 已生成。
@@ -1,5 +1,6 @@
package com.bms.price.mapper;
import java.math.BigDecimal;
import java.util.List;
import org.apache.ibatis.annotations.Param;
import com.bms.price.domain.PrcPayBill;
@@ -63,6 +64,9 @@ public interface PrcPayBillMapper
*/
int refreshPayTotal(@Param("billIds") List<Long> billIds);
/** 把折成人民币后的应付汇总写到主表,明细金额和币种不动。 */
int updateCnyPayTotal(@Param("billId") Long billId, @Param("payTotal") BigDecimal payTotal);
/** 订单还没有应付主表时补一行,总额随后按明细重算。单次不超过 1000 个订单。 */
int insertMissingPayBills(@Param("billIds") List<Long> billIds, @Param("operator") String operator);
@@ -10,7 +10,7 @@ public interface IPrcPayBillFeeService
{
/**
* 分批写入应付明细,并回写这些订单的应付总额。
* 明细每批最多 1000 条。总额是该订单未删除明细的金额之和,同时写入 prc_pay_bill.pay_total 和订单应付总额。
* 明细每批最多 1000 条,金额和币种按原样写入 prc_pay_bill_fee。汇总时外币按汇率折成人民币,只回写 prc_pay_bill.pay_total。
*
* @param fees 本次新增的应付明细
*/
@@ -75,9 +75,6 @@ public class PayOrderCostServiceImpl implements IPayOrderCostService
@Autowired
private PayPostcodeMapper payPostcodeMapper;
@Autowired
private PayFeeMoney payFeeMoney;
/**
* 重算一票订单的尾程应付并落库。
* 先找渠道和计费日对应的价卡版本,再用重量、尺寸、邮编算出费用,写回订单应付。
@@ -152,7 +149,6 @@ public class PayOrderCostServiceImpl implements IPayOrderCostService
{
throw new ServiceException(result.getMessage() == null ? PaymentMesEnum.BMS_PAY_NO_COST.getCnMes() : result.getMessage());
}
applyCny(result, bizDate);
String operator = SecurityUtils.getUsername();
PrcPayBill payBill = saveBill(bill, result, operator);
saveFees(bill.getBillId(), payBill.getPayBillId(), result);
@@ -645,7 +641,7 @@ public class PayOrderCostServiceImpl implements IPayOrderCostService
row.setScId(scId);
String userId = PayFeeMoney.userId();
row.setAmount(fee.getAmount());
row.setCurrency(PayFeeMoney.CNY);
row.setCurrency(fee.getCurrency());
row.setFeeSource("CALC");
row.setCreateBy(userId);
row.setUpdateBy(userId);
@@ -688,25 +684,6 @@ public class PayOrderCostServiceImpl implements IPayOrderCostService
result.setFeeLogType(recalc ? PayBillFeeLogService.RECALC : PayBillFeeLogService.ADD);
}
/** 按计费日汇率把本次尾程费用折成人民币,明细三位,合计两位。 */
private void applyCny(PayOrderCostResult result, Date bizDate)
{
BigDecimal sum = BigDecimal.ZERO;
List<PayCostLine> fees = result.getFees() == null ? List.of() : result.getFees();
for (PayCostLine fee : fees)
{
BigDecimal cny = payFeeMoney.toCny(fee.getAmount(), fee.getCurrency(), bizDate);
fee.setAmount(cny);
fee.setCurrency(PayFeeMoney.CNY);
if (cny != null)
{
sum = sum.add(cny);
}
}
result.setCurrency(PayFeeMoney.CNY);
result.setPayTotal(PayFeeMoney.total(sum));
}
/** 计算费用,空来源按计算费用处理。 */
private static boolean calcFee(PrcPayBillFee fee)
{
@@ -1,6 +1,7 @@
package com.bms.price.service.impl;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
@@ -73,9 +74,6 @@ public class PayOrderListServiceImpl implements IPayOrderListService
@Autowired
private PayBillFeeLogService payBillFeeLogService;
@Autowired
private PayFeeMoney payFeeMoney;
@Autowired
@Lazy
private PayOrderRecalcAsyncRunner payOrderRecalcAsyncRunner;
@@ -336,8 +334,8 @@ public class PayOrderListServiceImpl implements IPayOrderListService
{
throw new ServiceException("币种过长");
}
BigDecimal amount = payFeeMoney.toCny(line.getAmount(), currency, order.getBizDate());
if (amount.abs().compareTo(new BigDecimal("9999999999.999")) > 0)
BigDecimal amount = line.getAmount().setScale(2, RoundingMode.HALF_UP);
if (amount.abs().compareTo(new BigDecimal("9999999999.99")) > 0)
{
throw new ServiceException("金额超出范围");
}
@@ -360,7 +358,7 @@ public class PayOrderListServiceImpl implements IPayOrderListService
fee.setScId(manualScId());
fee.setFeeLevel(level);
fee.setAmount(amount);
fee.setCurrency(PayFeeMoney.CNY);
fee.setCurrency(currency);
fee.setRemark(remark == null || remark.isEmpty() ? null : remark);
fee.setFeeSource("MANUAL");
fee.setCreateBy(userId);
@@ -1,16 +1,19 @@
package com.bms.price.service.impl;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.bms.common.utils.SecurityUtils;
import com.bms.price.domain.PrcPayBillFee;
import com.bms.price.mapper.PrcOrderBillMapper;
import com.bms.price.mapper.PrcPayBillFeeMapper;
import com.bms.price.mapper.PrcPayBillMapper;
import com.bms.price.pay.PayFeeMoney;
import com.bms.price.service.IPrcPayBillFeeService;
/**
@@ -28,7 +31,7 @@ public class PrcPayBillFeeServiceImpl implements IPrcPayBillFeeService
private PrcPayBillMapper payBillMapper;
@Autowired
private PrcOrderBillMapper orderBillMapper;
private PayFeeMoney payFeeMoney;
@Override
@Transactional(rollbackFor = Exception.class)
@@ -76,8 +79,38 @@ public class PrcPayBillFeeServiceImpl implements IPrcPayBillFeeService
List<Long> chunk = ids.subList(from, Math.min(from + BATCH_SIZE, ids.size()));
payBillMapper.insertMissingPayBills(chunk, operator);
payBillFeeMapper.bindPayBillId(chunk);
payBillMapper.refreshPayTotal(chunk);
orderBillMapper.refreshPayTotalFromFees(chunk);
writeCnyTotals(chunk);
}
}
/** 不改 prc_pay_bill_fee。按计费日汇率把明细折成人民币后相加,四舍五入到两位,只写入 prc_pay_bill.pay_total。 */
private void writeCnyTotals(List<Long> billIds)
{
Map<Long, BigDecimal> sums = new LinkedHashMap<>();
for (Long billId : billIds)
{
sums.put(billId, BigDecimal.ZERO);
}
List<PrcPayBillFee> fees = payBillFeeMapper.selectOpenFees(billIds);
if (fees != null)
{
for (PrcPayBillFee fee : fees)
{
if (fee == null || fee.getBillId() == null || fee.getAmount() == null)
{
continue;
}
BigDecimal cny = payFeeMoney.toCny(fee.getAmount(), fee.getCurrency(), fee.getBizDate());
if (cny == null)
{
continue;
}
sums.merge(fee.getBillId(), cny, BigDecimal::add);
}
}
for (Map.Entry<Long, BigDecimal> entry : sums.entrySet())
{
payBillMapper.updateCnyPayTotal(entry.getKey(), PayFeeMoney.total(entry.getValue()));
}
}
@@ -64,9 +64,6 @@ public class SrvBillAirAllocServiceImpl implements ISrvBillAirAllocService
@Autowired
private PayBillFeeLogService payBillFeeLogService;
@Autowired
private PayFeeMoney payFeeMoney;
@Override
public List<SrvBillAirAllocFee> preview(List<String> billCodes)
{
@@ -110,8 +107,7 @@ public class SrvBillAirAllocServiceImpl implements ISrvBillAirAllocService
{
List<SrvBillAirAllocOrder> rows = orders.get(fee.getBillCode());
fee.setOrderCount(rows.size());
BigDecimal cnyPrice = payFeeMoney.toCny(fee.getPrice(), fee.getCurrency(), fee.getCreateTime());
List<BigDecimal> shares = split(cnyPrice, rows, true);
List<BigDecimal> shares = split(fee.getPrice(), rows, true);
for (int i = 0; i < rows.size(); i++)
{
batch.add(toOrderFee(fee, rows.get(i), shares.get(i), payBillIds));
@@ -252,7 +248,7 @@ public class SrvBillAirAllocServiceImpl implements ISrvBillAirAllocService
row.setFeeLevel(fee.getFeeLevel());
String userId = PayFeeMoney.userId();
row.setAmount(amount);
row.setCurrency(PayFeeMoney.CNY);
row.setCurrency(fee.getCurrency().trim());
row.setRoundMode("HALF_UP");
row.setRemark(remark(fee));
row.setFeeSource(FEE_SOURCE);
@@ -297,7 +293,7 @@ public class SrvBillAirAllocServiceImpl implements ISrvBillAirAllocService
}
/**
* 把已经折成人民币的费用价格拆到每一票订单,结果保留三位,合计等于费用价格。
* 把费用价格拆到每一票订单,结果保留两位,合计等于费用价格。
* 按订单数量:每一票先向下取整,差额补在最后一票。
* 按重量:按订单重量占这些订单总重量的比例分摊。前面的订单向下取整,差额补在最后一票有重量的订单上。
* 订单重量优先取计费重,没有计费重时取实际重量,再没有取收货重量。
@@ -309,12 +305,12 @@ public class SrvBillAirAllocServiceImpl implements ISrvBillAirAllocService
*/
private static List<BigDecimal> split(BigDecimal price, List<SrvBillAirAllocOrder> orders, boolean byWeight)
{
BigDecimal total = price.setScale(PayFeeMoney.LINE_SCALE, RoundingMode.HALF_UP);
BigDecimal total = price.setScale(2, RoundingMode.HALF_UP);
int count = orders.size();
List<BigDecimal> shares = new ArrayList<>(count);
if (!byWeight)
{
BigDecimal each = total.divide(BigDecimal.valueOf(count), PayFeeMoney.LINE_SCALE, RoundingMode.DOWN);
BigDecimal each = total.divide(BigDecimal.valueOf(count), 2, RoundingMode.DOWN);
BigDecimal used = ZERO;
for (int i = 0; i < count - 1; i++)
{
@@ -342,7 +338,7 @@ public class SrvBillAirAllocServiceImpl implements ISrvBillAirAllocService
shares.add(null);
continue;
}
BigDecimal share = total.multiply(weight(orders.get(i))).divide(sum, PayFeeMoney.LINE_SCALE, RoundingMode.DOWN);
BigDecimal share = total.multiply(weight(orders.get(i))).divide(sum, 2, RoundingMode.DOWN);
shares.add(share);
used = used.add(share);
}
@@ -24,6 +24,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="createTime" column="create_time" />
<result property="updateBy" column="update_by" />
<result property="updateTime" column="update_time" />
<result property="bizDate" column="biz_date" />
</resultMap>
<sql id="feeItemName">
@@ -192,6 +193,15 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
and statement_line_id is not null
</select>
<select id="selectOpenFees" resultMap="PrcPayBillFeeResult">
select f.fee_id, f.bill_id, f.amount, f.currency, b.biz_date
from prc_pay_bill_fee f
left join prc_order_bill b on b.bill_id = f.bill_id
where ifnull(f.is_deleted, '0') = '0'
and f.bill_id in
<foreach collection="billIds" item="billId" open="(" separator="," close=")">#{billId}</foreach>
</select>
<update id="markCalcDeleted">
update prc_pay_bill_fee
set is_deleted = '1',
@@ -138,6 +138,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<foreach collection="billIds" item="billId" open="(" separator="," close=")">#{billId}</foreach>
</update>
<update id="updateCnyPayTotal">
update prc_pay_bill
set pay_total = #{payTotal},
currency = 'CNY',
update_time = sysdate()
where bill_id = #{billId}
</update>
<update id="markCalcStatus">
update prc_pay_bill
set pay_calc_status = #{status},