fix(print): 面单发件人信息接入仓库主体 subject_config 兜底(签约策略未配置时)
This commit is contained in:
parent
0717640eff
commit
5cd1479a92
@ -1145,6 +1145,46 @@ function resolveSubjectConfig(input) {
|
|||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 发件人相关字段集合,用于签约策略 → 仓库主体的按字段兜底。
|
||||||
|
*/
|
||||||
|
const SENDER_FALLBACK_FIELDS = Object.freeze([
|
||||||
|
'sender_name',
|
||||||
|
'sender_tel',
|
||||||
|
'province_name',
|
||||||
|
'city_name',
|
||||||
|
'district_name',
|
||||||
|
'town_name',
|
||||||
|
'address',
|
||||||
|
]);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 解析发件人兜底配置:签约策略 policy_config 非空值优先,空值回退仓库主体 subject_config。
|
||||||
|
*
|
||||||
|
* 注意:getContractConfig 会把策略默认值合并进 policy_config(发件人字段默认为空字符串),
|
||||||
|
* 因此不能用对象浅合并(空串会覆盖 subject_config 的有效值),必须按字段回退。
|
||||||
|
*
|
||||||
|
* @param {Object} policyConfig 签约策略配置。
|
||||||
|
* @param {Object} subjectConfig 仓库主体配置。
|
||||||
|
* @return {Object} 兜底后的策略配置对象。
|
||||||
|
*/
|
||||||
|
function resolveSenderFallbackConfig(policyConfig, subjectConfig) {
|
||||||
|
const safePolicyConfig = isPlainObject(policyConfig) ? policyConfig : {};
|
||||||
|
const safeSubjectConfig = isPlainObject(subjectConfig) ? subjectConfig : {};
|
||||||
|
const merged = { ...safePolicyConfig };
|
||||||
|
|
||||||
|
for (const key of SENDER_FALLBACK_FIELDS) {
|
||||||
|
if (!toTrimmedString(merged[key])) {
|
||||||
|
const fallbackValue = toTrimmedString(safeSubjectConfig[key]);
|
||||||
|
if (fallbackValue) {
|
||||||
|
merged[key] = fallbackValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return merged;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 构建基础数据中间态。
|
* 构建基础数据中间态。
|
||||||
* @param {Object} input 输入对象。
|
* @param {Object} input 输入对象。
|
||||||
@ -2411,6 +2451,11 @@ function buildPlatformRequestSkeleton(input = {}) {
|
|||||||
const options = isPlainObject(input.options) ? input.options : {};
|
const options = isPlainObject(input.options) ? input.options : {};
|
||||||
const extraCustomLines = Array.isArray(options.extraCustomLines) ? options.extraCustomLines : [];
|
const extraCustomLines = Array.isArray(options.extraCustomLines) ? options.extraCustomLines : [];
|
||||||
const policyConfig = resolvePolicyConfig(input);
|
const policyConfig = resolvePolicyConfig(input);
|
||||||
|
const subjectConfig = resolveSubjectConfig(input);
|
||||||
|
// 发件人兜底:签约策略 policy_config 非空值优先,空值回退仓库主体 subject_config。
|
||||||
|
// 与 buildBaseData 的三级兜底语义保持一致,避免签约策略未配发件人时
|
||||||
|
// 平台面单(快手/拼多多/抖音等)senderInfo/sender 输出为空。
|
||||||
|
const policyConfigWithSenderFallback = resolveSenderFallbackConfig(policyConfig, subjectConfig);
|
||||||
const orderExpressForCompose = isPlainObject(input.order_express)
|
const orderExpressForCompose = isPlainObject(input.order_express)
|
||||||
? { ...input.order_express }
|
? { ...input.order_express }
|
||||||
: {};
|
: {};
|
||||||
@ -2500,7 +2545,7 @@ function buildPlatformRequestSkeleton(input = {}) {
|
|||||||
skeleton,
|
skeleton,
|
||||||
orderExpressForCompose,
|
orderExpressForCompose,
|
||||||
orderDeliveryForCompose,
|
orderDeliveryForCompose,
|
||||||
policyConfig,
|
policyConfigWithSenderFallback,
|
||||||
cainiaoCustomControlTemplateURL,
|
cainiaoCustomControlTemplateURL,
|
||||||
warnings,
|
warnings,
|
||||||
extraCustomLines
|
extraCustomLines
|
||||||
@ -2512,7 +2557,7 @@ function buildPlatformRequestSkeleton(input = {}) {
|
|||||||
orderExpressForCompose,
|
orderExpressForCompose,
|
||||||
orderDeliveryForCompose,
|
orderDeliveryForCompose,
|
||||||
warnings,
|
warnings,
|
||||||
policyConfig,
|
policyConfigWithSenderFallback,
|
||||||
customDataTemplateURL,
|
customDataTemplateURL,
|
||||||
extraCustomLines
|
extraCustomLines
|
||||||
);
|
);
|
||||||
@ -2522,7 +2567,7 @@ function buildPlatformRequestSkeleton(input = {}) {
|
|||||||
skeleton,
|
skeleton,
|
||||||
orderExpressForCompose,
|
orderExpressForCompose,
|
||||||
orderDeliveryForCompose,
|
orderDeliveryForCompose,
|
||||||
policyConfig,
|
policyConfigWithSenderFallback,
|
||||||
extraCustomLines
|
extraCustomLines
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -2531,7 +2576,7 @@ function buildPlatformRequestSkeleton(input = {}) {
|
|||||||
skeleton,
|
skeleton,
|
||||||
orderExpressForCompose,
|
orderExpressForCompose,
|
||||||
orderDeliveryForCompose,
|
orderDeliveryForCompose,
|
||||||
policyConfig,
|
policyConfigWithSenderFallback,
|
||||||
extraCustomLines,
|
extraCustomLines,
|
||||||
options.customAreaBaseUrl
|
options.customAreaBaseUrl
|
||||||
);
|
);
|
||||||
@ -2541,7 +2586,7 @@ function buildPlatformRequestSkeleton(input = {}) {
|
|||||||
skeleton,
|
skeleton,
|
||||||
orderExpressForCompose,
|
orderExpressForCompose,
|
||||||
orderDeliveryForCompose,
|
orderDeliveryForCompose,
|
||||||
policyConfig,
|
policyConfigWithSenderFallback,
|
||||||
templateSample,
|
templateSample,
|
||||||
warnings,
|
warnings,
|
||||||
extraCustomLines
|
extraCustomLines
|
||||||
@ -2552,7 +2597,7 @@ function buildPlatformRequestSkeleton(input = {}) {
|
|||||||
skeleton,
|
skeleton,
|
||||||
orderExpressForCompose,
|
orderExpressForCompose,
|
||||||
orderDeliveryForCompose,
|
orderDeliveryForCompose,
|
||||||
policyConfig,
|
policyConfigWithSenderFallback,
|
||||||
warnings,
|
warnings,
|
||||||
extraCustomLines
|
extraCustomLines
|
||||||
);
|
);
|
||||||
@ -2562,7 +2607,7 @@ function buildPlatformRequestSkeleton(input = {}) {
|
|||||||
skeleton,
|
skeleton,
|
||||||
orderExpressForCompose,
|
orderExpressForCompose,
|
||||||
orderDeliveryForCompose,
|
orderDeliveryForCompose,
|
||||||
policyConfig,
|
policyConfigWithSenderFallback,
|
||||||
extraCustomLines
|
extraCustomLines
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@ -88,4 +88,126 @@ describe('test/app/lib/printer_data_builder.test.js', () => {
|
|||||||
CRLF: '\r\n',
|
CRLF: '\r\n',
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('kuaishou senderInfo fallback', () => {
|
||||||
|
const buildKuaishouInput = (policyConfig, subjectConfig) => ({
|
||||||
|
platform: 'KS',
|
||||||
|
order_express: {
|
||||||
|
waybill_code: 'WB-KS-001',
|
||||||
|
},
|
||||||
|
order_delivery: {
|
||||||
|
name: '收件人',
|
||||||
|
mobile: '13800000000',
|
||||||
|
detail_address: '收货地址',
|
||||||
|
},
|
||||||
|
policy_config: policyConfig,
|
||||||
|
subject_config: subjectConfig,
|
||||||
|
template_sample: {
|
||||||
|
cmd: 'print',
|
||||||
|
version: '1.0',
|
||||||
|
task: {
|
||||||
|
taskID: 'task-ks-001',
|
||||||
|
documents: [
|
||||||
|
{
|
||||||
|
documentID: 'doc-ks-001',
|
||||||
|
contents: [
|
||||||
|
{
|
||||||
|
addData: {},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const getSenderInfo = result => {
|
||||||
|
return result.request_skeleton.task.documents[0].contents[0].addData.senderInfo;
|
||||||
|
};
|
||||||
|
|
||||||
|
it('should fall back to subject_config when policy_config has no sender fields', () => {
|
||||||
|
const result = PrinterDataBuilder.buildPlatformRequestSkeleton(buildKuaishouInput(
|
||||||
|
{ waybill_custom_display_type: '2' },
|
||||||
|
{
|
||||||
|
sender_name: '仓库发件人',
|
||||||
|
sender_tel: '13800138000',
|
||||||
|
province_name: '广东省',
|
||||||
|
city_name: '广州市',
|
||||||
|
district_name: '白云区',
|
||||||
|
town_name: '钟落潭镇',
|
||||||
|
address: '某路1号',
|
||||||
|
}
|
||||||
|
));
|
||||||
|
const senderInfo = getSenderInfo(result);
|
||||||
|
|
||||||
|
assert.equal(senderInfo.contact.name, '仓库发件人');
|
||||||
|
assert.equal(senderInfo.contact.mobile, '13800138000');
|
||||||
|
assert.equal(senderInfo.address.provinceName, '广东省');
|
||||||
|
assert.equal(senderInfo.address.cityName, '广州市');
|
||||||
|
assert.equal(senderInfo.address.districtName, '白云区');
|
||||||
|
assert.equal(senderInfo.address.detailAddress, '某路1号');
|
||||||
|
assert.equal(senderInfo.address.countryCode, 'CHN');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should prefer policy_config sender fields over subject_config', () => {
|
||||||
|
const result = PrinterDataBuilder.buildPlatformRequestSkeleton(buildKuaishouInput(
|
||||||
|
{
|
||||||
|
sender_name: '货主发件人',
|
||||||
|
sender_tel: '13700137000',
|
||||||
|
province_name: '浙江省',
|
||||||
|
city_name: '杭州市',
|
||||||
|
district_name: '余杭区',
|
||||||
|
address: '货主地址',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
sender_name: '仓库发件人',
|
||||||
|
sender_tel: '13800138000',
|
||||||
|
province_name: '广东省',
|
||||||
|
city_name: '广州市',
|
||||||
|
district_name: '白云区',
|
||||||
|
address: '某路1号',
|
||||||
|
}
|
||||||
|
));
|
||||||
|
const senderInfo = getSenderInfo(result);
|
||||||
|
|
||||||
|
assert.equal(senderInfo.contact.name, '货主发件人');
|
||||||
|
assert.equal(senderInfo.contact.mobile, '13700137000');
|
||||||
|
assert.equal(senderInfo.address.provinceName, '浙江省');
|
||||||
|
assert.equal(senderInfo.address.cityName, '杭州市');
|
||||||
|
assert.equal(senderInfo.address.districtName, '余杭区');
|
||||||
|
assert.equal(senderInfo.address.detailAddress, '货主地址');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should fall back to subject_config when policy_config sender fields are empty strings', () => {
|
||||||
|
// 生产场景:getContractConfig 会合并策略默认值,发件人字段以空串存在
|
||||||
|
const result = PrinterDataBuilder.buildPlatformRequestSkeleton(buildKuaishouInput(
|
||||||
|
{
|
||||||
|
sender_name: '',
|
||||||
|
sender_tel: '',
|
||||||
|
province_name: '',
|
||||||
|
city_name: '',
|
||||||
|
district_name: '',
|
||||||
|
town_name: '',
|
||||||
|
address: '',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
sender_name: '仓库发件人',
|
||||||
|
sender_tel: '13800138000',
|
||||||
|
province_name: '广东省',
|
||||||
|
city_name: '广州市',
|
||||||
|
district_name: '白云区',
|
||||||
|
town_name: '钟落潭镇',
|
||||||
|
address: '某路1号',
|
||||||
|
}
|
||||||
|
));
|
||||||
|
const senderInfo = getSenderInfo(result);
|
||||||
|
|
||||||
|
assert.equal(senderInfo.contact.name, '仓库发件人');
|
||||||
|
assert.equal(senderInfo.contact.mobile, '13800138000');
|
||||||
|
assert.equal(senderInfo.address.provinceName, '广东省');
|
||||||
|
assert.equal(senderInfo.address.cityName, '广州市');
|
||||||
|
assert.equal(senderInfo.address.districtName, '白云区');
|
||||||
|
assert.equal(senderInfo.address.detailAddress, '某路1号');
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user