优化计费重量规则,新增按收货重取重逻辑

This commit is contained in:
wuweihua
2026-11-17 17:00:03 +08:00
parent 8d45439931
commit 4f2954ebce
6 changed files with 130 additions and 8 deletions
@@ -235,7 +235,9 @@ public class PrcOrderBillServiceImpl implements IPrcOrderBillService
BigDecimal calcWeight = resolveBillCalcWeight(request, existed, systemWeight);
request.setWeight(calcWeight);
TmsPriceQuoteResult result = tmsPriceQuoteService.calculate(request);
persistBill(request, systemWeight, bizDate, result);
// 规则命中时覆盖落库 weight;有 charge_weight 覆盖时保留原系统 weight
BigDecimal persistWeight = resolvePersistSystemWeight(request, existed, systemWeight, calcWeight);
persistBill(request, persistWeight, bizDate, result);
return result;
}
catch (RuntimeException e)
@@ -2065,8 +2067,8 @@ public class PrcOrderBillServiceImpl implements IPrcOrderBillService
{
bill.setCountryName(result.getCountryName());
}
// weight=上游计费重(DIMENSIONAL_WEIGHT_FACTOR);charge_weight=客户确认重/人工修改
bill.setWeight(weight);
// weight:默认上游系统重;业务规则命中时写入规则计费重;charge_weight=客户确认重/人工修改
bill.setWeight(weight);
bill.setBizDate(bizDate);
bill.setTmsId(request.getTmsId() == null ? null : Long.valueOf(request.getTmsId()));
bill.setPriceSetId(result.getPriceSetId());
@@ -3116,6 +3118,25 @@ bill.setWeight(weight);
return applyBizRuleWeight(request, systemWeight);
}
/**
* 落库 weight:无 charge_weight 覆盖时写入计费用重(含规则命中结果);
* 有客户确认重/人工改重时保留原系统 weight。
*/
private BigDecimal resolvePersistSystemWeight(TmsPriceBillRequest request, PrcOrderBill existed,
BigDecimal systemWeight, BigDecimal calcWeight)
{
BigDecimal preferred = positiveOrNull(request == null ? null : request.getChargeWeight());
if (preferred == null && !isUpstreamSyncRequest(request) && hasChargeWeightOverride(existed))
{
preferred = existed.getChargeWeight();
}
if (preferred != null)
{
return systemWeight;
}
return calcWeight != null ? calcWeight : systemWeight;
}
/**
* 上游同步/软失败:weight=上游计费重;charge_weight=客户确认重(无值则 null)。
*/
@@ -3133,7 +3154,7 @@ bill.setWeight(weight);
}
/**
* 业务规则计费重量(THREE_SIDE / VOL_8000)。
* 业务规则计费重量(THREE_SIDE / USE_RECEIVE_WEIGHT / VOL_8000)。
* 如需禁用:注释掉 resolveWeightByRule 调用,始终返回 baseWeight。
*/
private BigDecimal applyBizRuleWeight(TmsPriceBillRequest request, BigDecimal baseWeight)
@@ -21,7 +21,7 @@ public interface IBmsBizRuleService
int deleteByIds(Long[] ruleIds);
/**
* 将生效的重量规则(THREE_SIDE / VOL_8000)应用到计费请求。
* 将生效的重量规则(THREE_SIDE / USE_RECEIVE_WEIGHT / VOL_8000)应用到计费请求。
* @return 规则命中时返回覆盖后的计费重量;无规则适用时返回 null
*/
BigDecimal resolveWeightByRule(TmsPriceBillRequest request, BigDecimal systemWeight);
@@ -27,6 +27,8 @@ public class BmsBizRuleServiceImpl implements IBmsBizRuleService
public static final String RULE_TYPE_THREE_SIDE = "THREE_SIDE";
/** 计费重量 = max(L*W*H/8000, weightSource)。 */
public static final String RULE_TYPE_VOL_8000 = "VOL_8000";
/** 命中后按取值字段取重(默认实重/收货重)。 */
public static final String RULE_TYPE_USE_RECEIVE_WEIGHT = "USE_RECEIVE_WEIGHT";
public static final String WEIGHT_SOURCE_RECEIVE = "RECEIVE_WEIGHT";
public static final String WEIGHT_SOURCE_CHARGE = "CHARGE_WEIGHT";
public static final String WEIGHT_SOURCE_VOLUME = "VOLUME_WEIGHT";
@@ -137,11 +139,17 @@ public class BmsBizRuleServiceImpl implements IBmsBizRuleService
return null;
}
// 先三边之和取重,未命中再走 VOL_8000
// 优先:三边 > 取实重(收货重) > VOL_8000
BigDecimal threeSide = resolveThreeSideWeight(request, systemWeight);
if (threeSide != null)
{
return threeSide;
}
BigDecimal useReceive = resolveUseReceiveWeight(request, systemWeight);
if (useReceive != null)
{
return useReceive;
}
BigDecimal vol8000 = resolveVol8000(request, systemWeight);
if (vol8000 != null)
{
@@ -223,6 +231,34 @@ public class BmsBizRuleServiceImpl implements IBmsBizRuleService
return null;
}
/**
* 取实重(收货重):按产品/国家/客户/重量段命中后,
* 按取值字段取重(默认 RECEIVE_WEIGHT:实重优先,次收货重)。
*/
private BigDecimal resolveUseReceiveWeight(TmsPriceBillRequest request, BigDecimal systemWeight)
{
List<BmsBizRule> rules = bizRuleMapper.selectActiveByType(RULE_TYPE_USE_RECEIVE_WEIGHT);
if (rules == null || rules.isEmpty())
{
return null;
}
for (BmsBizRule rule : rules)
{
if (!matchVol8000(rule, request, systemWeight))
{
continue;
}
String source = StringUtils.isEmpty(rule.getWeightSource())
? WEIGHT_SOURCE_RECEIVE : rule.getWeightSource();
BigDecimal picked = pickWeight(source, request, systemWeight);
if (picked != null)
{
return picked.setScale(3, RoundingMode.HALF_UP);
}
}
return null;
}
private boolean matchVol8000(BmsBizRule rule, TmsPriceBillRequest request, BigDecimal systemWeight)
{
if (rule == null)
@@ -571,7 +607,9 @@ public class BmsBizRuleServiceImpl implements IBmsBizRuleService
{
throw new ServiceException("规则类型不能为空");
}
if (RULE_TYPE_VOL_8000.equalsIgnoreCase(row.getRuleType()) && StringUtils.isEmpty(row.getWeightSource()))
if ((RULE_TYPE_VOL_8000.equalsIgnoreCase(row.getRuleType())
|| RULE_TYPE_USE_RECEIVE_WEIGHT.equalsIgnoreCase(row.getRuleType()))
&& StringUtils.isEmpty(row.getWeightSource()))
{
row.setWeightSource(WEIGHT_SOURCE_RECEIVE);
}
@@ -0,0 +1,7 @@
-- USE_RECEIVE_WEIGHT: hit by product/country/customer/weight range, use receive/actual weight
SET NAMES utf8mb4;
INSERT INTO sys_dict_data (dict_sort, dict_label, dict_value, dict_type, css_class, list_class, is_default, status, create_by, create_time, remark)
SELECT 3, N'取实重(收货重)', 'USE_RECEIVE_WEIGHT', 'bms_biz_rule_type', '', 'warning', 'N', '0', 'admin', sysdate(),
N'命中后按取值字段取重;实重优先 actual_weight,次收货重 receive_weight'
FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM sys_dict_data WHERE dict_type = 'bms_biz_rule_type' AND dict_value = 'USE_RECEIVE_WEIGHT');
@@ -112,6 +112,14 @@
style="margin-bottom: 12px"
title="计费重 = max(长×宽×高(cm)/8000, 收货重);无尺寸时不覆盖"
/>
<el-alert
v-if="form.ruleType === 'USE_RECEIVE_WEIGHT'"
type="info"
:closable="false"
show-icon
style="margin-bottom: 12px"
title="命中后按取值字段取重;实重优先 actual_weight,次收货重 receive_weight"
/>
<el-form-item label="状态" prop="status">
<el-radio-group v-model="form.status">
<el-radio value="0">正常</el-radio>
@@ -33,8 +33,9 @@
<el-table-column :label="colBoundChannels" min-width="180" show-overflow-tooltip>
<template #default="{ row }">{{ boundChannelText(row) }}</template>
</el-table-column>
<el-table-column :label="colAction" width="90" align="center" fixed="right">
<el-table-column :label="colAction" width="160" align="center" fixed="right">
<template #default="{ row }">
<el-button link type="primary" @click="openDetail(row)" v-hasPermi="['price:label:query']">查看详情</el-button>
<el-button link type="primary" @click="openBindList(row)" v-hasPermi="['price:label:edit']">绑定</el-button>
</template>
</el-table-column>
@@ -112,6 +113,23 @@
<el-button type="primary" :loading="addSaving" @click="submitAddChannels">保存</el-button>
</template>
</el-dialog>
<el-drawer
v-model="detailVisible"
:title="detailTitle"
size="78%"
append-to-body
destroy-on-close
@closed="onDetailClosed"
>
<div v-loading="detailLoading">
<label-config-detail v-if="detailProduct" :product="detailProduct" :editable="false" />
<el-empty v-else-if="!detailLoading" description="暂无产品明细" />
</div>
<template #footer>
<el-button @click="detailVisible = false">关闭</el-button>
</template>
</el-drawer>
</el-drawer>
</template>
@@ -119,9 +137,11 @@
import {
listLabelProducts,
listLabelProductChannels,
replaceLabelProductChannels
replaceLabelProductChannels,
getLabelProduct
} from '@/api/price/label'
import { listChannelOptions } from '@/api/masterdata/serviceChannel'
import LabelConfigDetail from './LabelConfigDetail.vue'
const props = defineProps({
visible: { type: Boolean, default: false },
@@ -145,6 +165,14 @@ const addVisible = ref(false)
const addLoading = ref(false)
const addSaving = ref(false)
const addChannelIds = ref([])
const detailVisible = ref(false)
const detailLoading = ref(false)
const detailProduct = ref(null)
const detailTitle = computed(() => {
if (!detailProduct.value) return '产品明细'
return detailProduct.value.productName || detailProduct.value.sheetName || '产品明细'
})
const phSearch = '产品名称 / 绑定渠道'
const colId = '产品编号'
@@ -261,6 +289,26 @@ async function loadBoundChannels() {
}
}
async function openDetail(row) {
if (!row?.productId) return
detailVisible.value = true
detailLoading.value = true
detailProduct.value = null
try {
const res = await getLabelProduct(row.productId, row.versionId || row.termId)
detailProduct.value = res.data || row
} catch (e) {
detailProduct.value = row
} finally {
detailLoading.value = false
}
}
function onDetailClosed() {
detailProduct.value = null
detailLoading.value = false
}
async function openBindList(row) {
if (!row?.productId) return
bindProductId.value = row.productId