计费重覆盖

This commit is contained in:
wuweihua
2026-11-03 18:13:52 +08:00
parent 98ae525403
commit f0012ac563
@@ -207,7 +207,11 @@ public class PrcOrderBillServiceImpl implements IPrcOrderBillService
assertOrderBillEditable(request.getOrderNo()); assertOrderBillEditable(request.getOrderNo());
PrcOrderBill existed = orderBillMapper.selectPrcOrderBillByOrderNo(request.getOrderNo()); PrcOrderBill existed = orderBillMapper.selectPrcOrderBillByOrderNo(request.getOrderNo());
BigDecimal systemWeight = request.getWeight(); BigDecimal systemWeight = request.getWeight();
BigDecimal calcWeight = resolveCalcWeight(existed, systemWeight); // Upstream Oracle sync: always use TAB_ORDER weight (same overwrite as weight/charge_weight).
// Local rebill / manual charge_weight edit: keep resolveCalcWeight preference.
BigDecimal calcWeight = isUpstreamSyncRequest(request)
? systemWeight
: resolveCalcWeight(existed, systemWeight);
// Three-side sum rule disabled: upstream already applies it. // Three-side sum rule disabled: upstream already applies it.
// Manual charge_weight wins; otherwise apply active biz rules (e.g. three-side). // Manual charge_weight wins; otherwise apply active biz rules (e.g. three-side).
// if (!isManualChargeWeight(existed)) // if (!isManualChargeWeight(existed))
@@ -1755,7 +1759,7 @@ public class PrcOrderBillServiceImpl implements IPrcOrderBillService
} }
bill.setBillKey(billKey); bill.setBillKey(billKey);
bill.setOrderNo(orderNo); bill.setOrderNo(orderNo);
// Upstream header overwrite (no validate); charge_weight kept via resolvePersistChargeWeight below. // Upstream header overwrite (no validate).
applyUpstreamBillHeaderFields(bill, request); applyUpstreamBillHeaderFields(bill, request);
Long customerId = request.getCustomerId(); Long customerId = request.getCustomerId();
if (customerId == null && result != null) if (customerId == null && result != null)
@@ -1798,7 +1802,8 @@ public class PrcOrderBillServiceImpl implements IPrcOrderBillService
{ {
bill.setCountryName(result.getCountryName()); bill.setCountryName(result.getCountryName());
} }
// weight = system/original; charge_weight = effective (may be manual override) // weight = system/original; charge_weight follows weight on upstream sync,
// otherwise may keep manual override via resolvePersistChargeWeight.
bill.setWeight(weight); bill.setWeight(weight);
bill.setBizDate(bizDate); bill.setBizDate(bizDate);
bill.setTmsId(request.getTmsId() == null ? null : Long.valueOf(request.getTmsId())); bill.setTmsId(request.getTmsId() == null ? null : Long.valueOf(request.getTmsId()));
@@ -1816,7 +1821,14 @@ public class PrcOrderBillServiceImpl implements IPrcOrderBillService
bill.setWeightMax(result.getWeightMax()); bill.setWeightMax(result.getWeightMax());
bill.setWeightLabel(result.getWeightLabel()); bill.setWeightLabel(result.getWeightLabel());
bill.setEffectiveDate(result.getEffectiveDate()); bill.setEffectiveDate(result.getEffectiveDate());
bill.setChargeWeight(resolvePersistChargeWeight(weight, result.getChargeWeight())); if (isUpstreamSyncRequest(request))
{
bill.setChargeWeight(weight);
}
else
{
bill.setChargeWeight(resolvePersistChargeWeight(weight, result.getChargeWeight()));
}
Integer billingFailStatus = result.getBillingFailStatus(); Integer billingFailStatus = result.getBillingFailStatus();
if (billingFailStatus == null) if (billingFailStatus == null)
{ {
@@ -2797,6 +2809,12 @@ public class PrcOrderBillServiceImpl implements IPrcOrderBillService
payBillFeeMapper.selectByBillId(bill.getBillId())); payBillFeeMapper.selectByBillId(bill.getBillId()));
} }
/** Upstream Oracle row present => sync/billing path that overwrites weight & charge_weight together. */
private static boolean isUpstreamSyncRequest(TmsPriceBillRequest request)
{
return request != null && request.getUpstreamRow() != null && !request.getUpstreamRow().isEmpty();
}
/** charge_weight differs from weight => treated as manual override. */ /** charge_weight differs from weight => treated as manual override. */
private static boolean isManualChargeWeight(PrcOrderBill bill) private static boolean isManualChargeWeight(PrcOrderBill bill)
{ {
@@ -3011,14 +3029,11 @@ public class PrcOrderBillServiceImpl implements IPrcOrderBillService
applyProductCodeMapping(bill, request); applyProductCodeMapping(bill, request);
Long customerId = resolveCustomerIdByCode(request.getCustomerCode(), bill.getCustomerId()); Long customerId = resolveCustomerIdByCode(request.getCustomerCode(), bill.getCustomerId());
bill.setCustomerId(customerId == null ? Long.valueOf(0L) : customerId); bill.setCustomerId(customerId == null ? Long.valueOf(0L) : customerId);
// System weight overwrite; charge_weight keeps existing manual override when present. // Order-source sync: overwrite weight and charge_weight the same way from upstream.
if (request.getWeight() != null) if (request.getWeight() != null)
{ {
bill.setWeight(request.getWeight()); bill.setWeight(request.getWeight());
if (creating || bill.getChargeWeight() == null) bill.setChargeWeight(request.getWeight());
{
bill.setChargeWeight(request.getWeight());
}
} }
if (creating) if (creating)
{ {
@@ -3131,8 +3146,12 @@ public class PrcOrderBillServiceImpl implements IPrcOrderBillService
{ {
bill.setCustomerActiveStatus(BillCustomerActiveStatus.ACTIVE.getCode()); bill.setCustomerActiveStatus(BillCustomerActiveStatus.ACTIVE.getCode());
} }
// Soft-fail snapshot: overwrite system weight; do not touch charge_weight (keep current logic). // Soft-fail snapshot: overwrite weight and charge_weight the same way from upstream.
bill.setWeight(request.getWeight()); bill.setWeight(request.getWeight());
if (request.getWeight() != null)
{
bill.setChargeWeight(request.getWeight());
}
Date bizDate = StringUtils.isEmpty(request.getBizDate()) ? new Date() : resolveBizDate(request.getBizDate()); Date bizDate = StringUtils.isEmpty(request.getBizDate()) ? new Date() : resolveBizDate(request.getBizDate());
bill.setBizDate(bizDate); bill.setBizDate(bizDate);
if (StringUtils.isEmpty(bill.getCurrency())) if (StringUtils.isEmpty(bill.getCurrency()))
@@ -3191,7 +3210,7 @@ public class PrcOrderBillServiceImpl implements IPrcOrderBillService
} }
/** /**
* Locked by AR bill: overwrite upstream header + ext; keep amounts / fees / charge_weight. * Locked by AR bill: overwrite upstream header + ext + weight/charge_weight; keep amounts / fees.
*/ */
private void persistFailedSnapshotWhenLocked(PrcOrderBill bill, TmsPriceBillRequest request, private void persistFailedSnapshotWhenLocked(PrcOrderBill bill, TmsPriceBillRequest request,
int billingFailStatus, String errorMessage) int billingFailStatus, String errorMessage)
@@ -3203,6 +3222,7 @@ public class PrcOrderBillServiceImpl implements IPrcOrderBillService
if (request.getWeight() != null) if (request.getWeight() != null)
{ {
bill.setWeight(request.getWeight()); bill.setWeight(request.getWeight());
bill.setChargeWeight(request.getWeight());
} }
} }
applyBillingFailText(bill, billingFailStatus, errorMessage); applyBillingFailText(bill, billingFailStatus, errorMessage);