修改计费重

This commit is contained in:
wuweihua
2026-10-13 17:12:32 +08:00
parent 5c48717da2
commit d6a6ec4d53
17 changed files with 294 additions and 14 deletions
@@ -112,6 +112,8 @@ public class PrcOrderBill extends BaseEntity
private String customerActiveStatus;
/** NORMAL / ARREARS */
private String creditArrearsStatus;
/** NONE / REFUNDED */
private String refundStatus;
private String roundMode;
private List<PrcIncomeBillFee> incomeFees;
@@ -101,6 +101,8 @@ public class TmsPriceQuoteResult implements Serializable
private String customerActiveStatus;
/** NORMAL / ARREARS */
private String creditArrearsStatus;
/** NONE / REFUNDED */
private String refundStatus;
private Integer pieces;
private BigDecimal actualWeight;
private BigDecimal volume;
@@ -0,0 +1,39 @@
package com.bms.price.enums;
/**
* Refund status snapshot on prc_order_bill.
* NONE = not refunded; REFUNDED = has fee_type=REFUND line.
*/
public enum BillRefundStatus
{
NONE("NONE"),
REFUNDED("REFUNDED");
private final String code;
BillRefundStatus(String code)
{
this.code = code;
}
public String getCode()
{
return code;
}
public static BillRefundStatus of(String code)
{
if (code == null)
{
return null;
}
for (BillRefundStatus status : values())
{
if (status.code.equalsIgnoreCase(code.trim()))
{
return status;
}
}
return null;
}
}
@@ -46,12 +46,8 @@ public class OracleOrderBillMapper
String countryName = firstStr(row, "COUNTRY_NAME", "COUNTRY_EINGTH_NAME", "COUNTRY");
req.setCountryName(countryName);
req.setDestPostcode(firstStr(row, "CONSIGNEE_POSTCODE"));
// TAB_ORDER.DIMENSIONAL_WEIGHT_FACTOR = billing weight (计费重) -> quote weight / prc_order_bill.charge_weight
BigDecimal chargeWeight = firstPositiveDecimal(row, "DIMENSIONAL_WEIGHT_FACTOR");
BigDecimal weight = chargeWeight != null
? chargeWeight
: firstPositiveDecimal(row, "ACTUAL_WEIGHT", "PUSH_WEIGHT", "WEIGHT", "VOLUME_WEIGHT");
req.setWeight(weight);
// Quote / prc_order_bill.weight: use upstream TAB_ORDER.WEIGHT directly.
req.setWeight(firstPositiveDecimal(row, "WEIGHT"));
req.setActualWeight(firstPositiveDecimal(row, "ACTUAL_WEIGHT", "PUSH_WEIGHT", "WEIGHT"));
req.setPieces(firstInt(row, "ORDER_PIECE", "PACKAGE_NUM", "PRODUCT_SUM"));
req.setVolume(toVolumeM3(firstDecimal(row, "VOLUME")));
@@ -54,6 +54,7 @@ import com.bms.price.domain.vo.TmsPriceQuoteFeeLine;
import com.bms.price.domain.vo.TmsPriceQuoteResult;
import com.bms.price.enums.BillCreditArrearsStatus;
import com.bms.price.enums.BillCustomerActiveStatus;
import com.bms.price.enums.BillRefundStatus;
import com.bms.price.enums.TmsOrderBillMatchType;
import com.bms.price.mapper.PrcIncomeBillFeeMapper;
import com.bms.price.mapper.PrcIncomeBillMapper;
@@ -184,6 +185,10 @@ public class PrcOrderBillServiceImpl implements IPrcOrderBillService
}
failReq.setTransferNo(bill.getTransferNo());
assertOrderBillEditable(bill);
if (BillRefundStatus.REFUNDED.getCode().equalsIgnoreCase(bill.getRefundStatus()))
{
throw new ServiceException("\u8ba2\u5355\u5df2\u9000\u8d39\uff0c\u4e0d\u53ef\u91cd\u590d\u9000\u8d39");
}
List<PrcIncomeBillFee> fees = incomeBillFeeMapper.selectByBillId(bill.getBillId());
if (fees == null)
@@ -194,7 +199,7 @@ public class PrcOrderBillServiceImpl implements IPrcOrderBillService
{
if (row != null && FEE_TYPE_REFUND.equalsIgnoreCase(row.getFeeType()))
{
throw new ServiceException("订单已退费,不可重复退费");
throw new ServiceException("\u8ba2\u5355\u5df2\u9000\u8d39\uff0c\u4e0d\u53ef\u91cd\u590d\u9000\u8d39");
}
}
@@ -234,6 +239,7 @@ public class PrcOrderBillServiceImpl implements IPrcOrderBillService
refundFee.setArBillStatus(ArIncomeBillFeeStatus.UNBILLED.getCode());
refundFee.setManualFlag("0");
incomeBillFeeMapper.insertPrcIncomeBillFee(refundFee);
bill.setRefundStatus(BillRefundStatus.REFUNDED.getCode());
TmsPriceQuoteResult result = refreshBillIncomeTotals(bill);
JSONObject req = new JSONObject();
@@ -243,6 +249,7 @@ public class PrcOrderBillServiceImpl implements IPrcOrderBillService
req.put("billId", bill.getBillId());
req.put("refundAmount", feeSum.negate());
req.put("feeId", refundFee.getFeeId());
req.put("refundStatus", bill.getRefundStatus());
if (billSearchStore != null)
{
billSearchStore.save(EsLogType.BILL,
@@ -718,11 +725,27 @@ public class PrcOrderBillServiceImpl implements IPrcOrderBillService
StringUtils.isEmpty(bill.getCustomerActiveStatus())
? BillCustomerActiveStatus.ACTIVE.getCode() : bill.getCustomerActiveStatus());
bill.setCreditArrearsStatus(creditArrearsStatus);
bill.setRefundStatus(resolveRefundStatus(fees));
orderBillMapper.updatePrcOrderBill(bill);
orderBillMapper.refreshArBillStatusByBillIds(Arrays.asList(bill.getBillId()));
return toResult(bill, fees, payBillFeeMapper.selectByBillId(bill.getBillId()));
}
private static String resolveRefundStatus(List<PrcIncomeBillFee> fees)
{
if (fees != null)
{
for (PrcIncomeBillFee row : fees)
{
if (row != null && FEE_TYPE_REFUND.equalsIgnoreCase(row.getFeeType()))
{
return BillRefundStatus.REFUNDED.getCode();
}
}
}
return BillRefundStatus.NONE.getCode();
}
private BigDecimal calcManualSurchargeAmount(PrcSurcharge surcharge, BigDecimal weight, BigDecimal freightAmount)
{
if (surcharge == null || surcharge.getChargeValue() == null)
@@ -1106,6 +1129,10 @@ public class PrcOrderBillServiceImpl implements IPrcOrderBillService
// Credit soft-fail before persist so insert/update stores arrears flag in one write.
String creditArrearsStatus = syncOrderCredit(bill, previousIncome, customerActiveStatus);
bill.setCreditArrearsStatus(creditArrearsStatus);
if (existed == null || StringUtils.isEmpty(bill.getRefundStatus()))
{
bill.setRefundStatus(BillRefundStatus.NONE.getCode());
}
result.setBillId(bill.getBillId());
result.setOrderNo(orderNo);
result.setTransferNo(bill.getTransferNo());
@@ -1113,6 +1140,7 @@ public class PrcOrderBillServiceImpl implements IPrcOrderBillService
result.setCustomerCode(bill.getCustomerCode());
result.setCustomerActiveStatus(customerActiveStatus);
result.setCreditArrearsStatus(creditArrearsStatus);
result.setRefundStatus(bill.getRefundStatus());
result.setIncomeTotal(bill.getIncomeTotal());
result.setPayTotal(bill.getPayTotal());
result.setPayableTotal(bill.getIncomeTotal());
@@ -1121,6 +1149,7 @@ public class PrcOrderBillServiceImpl implements IPrcOrderBillService
if (existed == null)
{
bill.setArBillStatus(ArOrderBillStatus.UNBILLED.getCode());
bill.setRefundStatus(BillRefundStatus.NONE.getCode());
orderBillMapper.insertPrcOrderBill(bill);
}
else
@@ -1152,11 +1181,14 @@ public class PrcOrderBillServiceImpl implements IPrcOrderBillService
result.setIncomeTotal(refreshed.getIncomeTotal());
result.setPayableTotal(refreshed.getPayableTotal());
result.setCreditArrearsStatus(refreshed.getCreditArrearsStatus());
result.setRefundStatus(refreshed.getRefundStatus());
result.setFeeDetails(refreshed.getFeeDetails());
}
}
else
{
bill.setRefundStatus(BillRefundStatus.NONE.getCode());
result.setRefundStatus(bill.getRefundStatus());
orderBillMapper.refreshArBillStatusByBillIds(Arrays.asList(bill.getBillId()));
}
// Payable not in scope yet: do not write prc_pay_bill / prc_pay_bill_fee.
@@ -1570,6 +1602,9 @@ public class PrcOrderBillServiceImpl implements IPrcOrderBillService
r.setCurrency(bill.getCurrency());
r.setRoundMode(bill.getRoundMode());
r.setBizDate(bill.getBizDate());
r.setCustomerActiveStatus(bill.getCustomerActiveStatus());
r.setCreditArrearsStatus(bill.getCreditArrearsStatus());
r.setRefundStatus(bill.getRefundStatus());
r.setFeeDetails(toIncomeFeeLines(incomeFees));
r.setPayFeeDetails(toPayFeeLines(payFees));
PrcIncomeBill incomeBill = incomeBillMapper.selectByBillId(bill.getBillId());
@@ -1661,6 +1696,7 @@ public class PrcOrderBillServiceImpl implements IPrcOrderBillService
r.setCustomerName(bill.getCustomerName());
r.setCustomerActiveStatus(bill.getCustomerActiveStatus());
r.setCreditArrearsStatus(bill.getCreditArrearsStatus());
r.setRefundStatus(bill.getRefundStatus());
r.setPieces(bill.getPieces());
r.setActualWeight(bill.getActualWeight());
r.setVolume(bill.getVolume());
@@ -160,6 +160,15 @@ public class TabOrderSyncAsyncRunner
/** Sync selected rows with a short-lived worker pool (for HTTP syncSelected). */
public Map<String, Object> syncRowsParallel(List<TabOrderMonitorVo> rows)
{
return syncRowsParallel(rows, null);
}
/**
* Sync or refund selected rows.
* @param billType optional PENDING/REBILL/REFUND; null = auto PENDING/REBILL
*/
public Map<String, Object> syncRowsParallel(List<TabOrderMonitorVo> rows, String billType)
{
Map<String, Object> data = new HashMap<String, Object>();
List<Map<String, Object>> details = new ArrayList<Map<String, Object>>();
@@ -170,6 +179,7 @@ public class TabOrderSyncAsyncRunner
data.put("details", details);
return data;
}
final String fixedBillType = StringUtils.isEmpty(billType) ? null : billType.trim();
int threads = Math.min(clampThreads(billingProperties == null ? null : billingProperties.getOrderSourceSyncThreads()),
Math.max(1, rows.size()));
ExecutorService pool = newWorkerPool(threads, "order-source-sel");
@@ -187,9 +197,10 @@ public class TabOrderSyncAsyncRunner
item.put("transferOrderId", one == null ? null : one.getTransferOrderId());
try
{
PrcBillingTask task = billingTaskService.submitAndProcess(toSubmit(one));
PrcBillingTask task = billingTaskService.submitAndProcess(toSubmit(one, fixedBillType));
item.put("successStatus", task == null ? null : task.getSuccessStatus());
item.put("errorMessage", task == null ? null : task.getErrorMessage());
item.put("billType", task == null ? fixedBillType : task.getBillType());
if (task != null && BillTaskSuccessStatus.SUCCESS.getCode().equals(task.getSuccessStatus()))
{
ok.incrementAndGet();
@@ -204,6 +215,7 @@ public class TabOrderSyncAsyncRunner
fail.incrementAndGet();
item.put("successStatus", "ERROR");
item.put("errorMessage", e.getMessage());
item.put("billType", fixedBillType);
}
return item;
});
@@ -357,6 +369,11 @@ public class TabOrderSyncAsyncRunner
}
public static BillingTaskSubmitRequest toSubmit(TabOrderMonitorVo row)
{
return toSubmit(row, null);
}
public static BillingTaskSubmitRequest toSubmit(TabOrderMonitorVo row, String billType)
{
if (row == null)
{
@@ -368,6 +385,10 @@ public class TabOrderSyncAsyncRunner
req.setOrderNo(row.getOrderId());
req.setCustomerCode(row.getCustomerCode());
req.setBillTime(row.getPickupDate());
if (StringUtils.isNotEmpty(billType))
{
req.setBillType(billType.trim());
}
return req;
}
}