feat(setting.warehouse): 自动出库规则改为数组结构并新增顶层开关
- 新增 auto_outbound_enabled 顶层开关,auto_outbound_rules 改为规则数组(多条为「或」,规则内条件为「与」) - 移除 auto_outbound_rules 旧的 normalize 逻辑:不再按旧对象结构补齐子项,否则数组会被改写为对象并被 schema 回退成 [],导致用户配置保存时被静默清空 - 表单字段定义同步为 array 类型,更新各项 label/描述与默认值
This commit is contained in:
parent
a344ba9544
commit
cf674d9fd0
@ -5,50 +5,48 @@ const v = '1.0'
|
||||
/** HH:mm(24 小时制、两位补零) */
|
||||
const HH_MM_PATTERN = /^([01]\d|2[0-3]):[0-5]\d$/
|
||||
|
||||
/** 自动出库规则配置(subject_config.auto_outbound_rules) */
|
||||
export type SettingWarehouseAutoOutboundRules = {
|
||||
enabled?: boolean
|
||||
require_recheck?: boolean
|
||||
/**
|
||||
* 自动出库单条规则(subject_config.auto_outbound_rules 的数组项)。
|
||||
* 规则内所有条件为「与」关系;多条规则之间为「或」关系(任一命中即自动出库)。
|
||||
* 固定前置条件(不可配置):已复核 recheck_status=fin + 已分配储位 storage_status=fin。
|
||||
*/
|
||||
export type SettingWarehouseAutoOutboundRule = {
|
||||
/** 是否要求已打包(pack_status=fin),默认 true */
|
||||
require_pack?: boolean
|
||||
/** 是否要求已称重(wms_order_express.weighing_weight>0),默认 true */
|
||||
require_weigh?: boolean
|
||||
/** 是否要求已同步(sync_status=fin),默认 true */
|
||||
require_sync?: boolean
|
||||
require_print?: boolean
|
||||
require_pick?: boolean
|
||||
/** 是否不出库当天订单(默认 true):开启后,当天放开时间前、「允许当天出库最后时间」之后复核的订单不自动出库 */
|
||||
/** 是否不出库当天复核的订单(默认 true):按订单复核时间所在日计算,需等到该日的「放行时间」才自动出库 */
|
||||
exclude_same_day_outbound?: boolean
|
||||
/** 允许当天出库最后时间,格式 HH:mm,默认 06:00;复核时间早于该时间的订单不受「不出库当天订单」的影响 */
|
||||
/** 允许当天出库最后时间,格式 HH:mm,默认 06:00(当天内 00:00~23:59),不能大于放行时间 */
|
||||
same_day_outbound_deadline_time?: string
|
||||
/** 当天放开时间,格式 HH:mm,默认 22:00;开启「不出库当天订单」时,当天到达该时间后不再限制当天复核订单的自动出库 */
|
||||
/** 放行时间,格式 HH:mm,默认 22:00;支持跨天 00:00~47:59(24:00 之后表示次日,如 27:00 = 次日 03:00) */
|
||||
same_day_outbound_release_time?: string
|
||||
}
|
||||
|
||||
/** auto_outbound_rules 中的布尔(flag)子项 */
|
||||
/** 自动出库规则(subject_config.auto_outbound_rules):数组,空数组表示不自动出库任何订单 */
|
||||
export type SettingWarehouseAutoOutboundRules = SettingWarehouseAutoOutboundRule[]
|
||||
|
||||
/** 规则中的布尔(flag)子项 */
|
||||
export const AUTO_OUTBOUND_RULE_FLAG_KEYS = [
|
||||
'enabled',
|
||||
'require_recheck',
|
||||
'require_pack',
|
||||
'require_weigh',
|
||||
'require_sync',
|
||||
'require_print',
|
||||
'require_pick',
|
||||
'exclude_same_day_outbound'
|
||||
] as const
|
||||
|
||||
/** auto_outbound_rules 中的 HH:mm 时间子项(缺省/空值回退默认,非空值原样保留交由后端校验) */
|
||||
/** 规则中的 HH:mm 时间子项(缺省/空值回退默认,非空值原样保留交由后端校验) */
|
||||
export const AUTO_OUTBOUND_RULE_TIME_KEYS = [
|
||||
'same_day_outbound_deadline_time',
|
||||
'same_day_outbound_release_time'
|
||||
] as const
|
||||
|
||||
/** 文档默认:auto_outbound_rules 各子项默认值 */
|
||||
export const DEFAULT_AUTO_OUTBOUND_RULES: Required<SettingWarehouseAutoOutboundRules> = {
|
||||
enabled: false,
|
||||
require_recheck: true,
|
||||
/** 新建规则时的默认值(与后端 normalizeAutoOutboundRule 口径一致) */
|
||||
export const DEFAULT_AUTO_OUTBOUND_RULE: Required<SettingWarehouseAutoOutboundRule> = {
|
||||
require_pack: true,
|
||||
require_weigh: true,
|
||||
require_sync: true,
|
||||
require_print: true,
|
||||
require_pick: true,
|
||||
exclude_same_day_outbound: true,
|
||||
same_day_outbound_deadline_time: '06:00',
|
||||
same_day_outbound_release_time: '22:00'
|
||||
@ -142,6 +140,9 @@ export const DEFAULT_WAREHOUSE_SENDER_FIELDS: Required<SettingWarehouseSenderCon
|
||||
/** 与 module setting.warehouse 文档 subject_config 对齐 */
|
||||
export type SettingWarehouseSubjectConfig = SettingWarehouseSenderConfig & {
|
||||
enable_external_express_code?: boolean
|
||||
/** 是否启用自动出库(flag),默认 false(关闭);开启后按 auto_outbound_rules 扫描订单并自动标记出库 */
|
||||
auto_outbound_enabled?: boolean
|
||||
/** 自动出库规则数组,空数组表示不自动出库;满足任一规则即自动出库 */
|
||||
auto_outbound_rules?: SettingWarehouseAutoOutboundRules
|
||||
/** 散单打包最大时长,单位:分钟,默认 3 */
|
||||
single_order_pack_max_minutes?: number
|
||||
@ -382,39 +383,10 @@ export function normalizeWarehouseSubjectConfig(
|
||||
base.enable_external_express_code = false
|
||||
}
|
||||
|
||||
const rulesRaw = base.auto_outbound_rules
|
||||
const rules =
|
||||
rulesRaw && typeof rulesRaw === 'object' && !Array.isArray(rulesRaw)
|
||||
? { ...(rulesRaw as Record<string, unknown>) }
|
||||
: ({} as Record<string, unknown>)
|
||||
|
||||
// 兼容历史字段名:allow_same_day_outbound(旧,「允许当天出库」)= !exclude_same_day_outbound(新,「不出库当天订单」)
|
||||
if (!('exclude_same_day_outbound' in rules) && 'allow_same_day_outbound' in rules) {
|
||||
const legacyAllow = rules.allow_same_day_outbound
|
||||
rules.exclude_same_day_outbound = !(
|
||||
legacyAllow === true || legacyAllow === 1 || legacyAllow === '1'
|
||||
)
|
||||
}
|
||||
|
||||
// 按白名单保留 flag 与 HH:mm 时间子项:不能只按「值是否为 boolean」过滤,
|
||||
// 否则 same_day_outbound_deadline_time / same_day_outbound_release_time(字符串)
|
||||
// 会在读取与保存时被静默丢弃。
|
||||
const normalizedRules: Record<string, unknown> = { ...DEFAULT_AUTO_OUTBOUND_RULES }
|
||||
for (const key of AUTO_OUTBOUND_RULE_FLAG_KEYS) {
|
||||
const value = rules[key]
|
||||
normalizedRules[key] =
|
||||
value === true || value === 1 || value === '1'
|
||||
? true
|
||||
: value === false || value === 0 || value === '0'
|
||||
? false
|
||||
: DEFAULT_AUTO_OUTBOUND_RULES[key]
|
||||
}
|
||||
for (const key of AUTO_OUTBOUND_RULE_TIME_KEYS) {
|
||||
const value = rules[key]
|
||||
const text = value === undefined || value === null ? '' : String(value).trim()
|
||||
normalizedRules[key] = text !== '' ? text : DEFAULT_AUTO_OUTBOUND_RULES[key]
|
||||
}
|
||||
base.auto_outbound_rules = normalizedRules as SettingWarehouseAutoOutboundRules
|
||||
// 自动出库:auto_outbound_enabled(flag,顶层开关)+ auto_outbound_rules(规则数组)
|
||||
// 不要再在这里按旧「对象结构」(enabled/require_recheck/require_print/require_pick)补齐子项——
|
||||
// 那会把数组改写成对象,随后 applySchemaToSubjectConfig 按 meta 的 array 类型又回退成 [],
|
||||
// 导致用户在页面上配置的规则保存时被静默清空。子项集合一律以 getFieldMeta 的 item_keys 为准。
|
||||
|
||||
for (const key of WAREHOUSE_SENDER_FIELD_KEYS) {
|
||||
if (typeof base[key] !== 'string') {
|
||||
|
||||
@ -295,22 +295,26 @@ const FALLBACK_FIELDS: NormalizedField[] = [
|
||||
{ key: 'town_name', label: '默认发件镇/街道', type: 'string', maxLength: 50 },
|
||||
{ key: 'address', label: '默认发件详细地址', type: 'string', maxLength: 200 },
|
||||
{ key: 'receiver_address', label: '仓库收货地址', type: 'string', maxLength: 500, description: '退货/退件收件地址,一行文本' },
|
||||
{
|
||||
key: 'auto_outbound_enabled',
|
||||
label: '启用自动出库',
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
description: '默认关闭;开启后按「自动出库规则」扫描订单并自动标记出库'
|
||||
},
|
||||
{
|
||||
key: 'auto_outbound_rules',
|
||||
label: '自动出库规则',
|
||||
type: 'object',
|
||||
description: '全部条件满足时自动标记待出库。',
|
||||
type: 'array',
|
||||
default: [],
|
||||
description: '多条规则之间为「或」关系,任一命中即自动出库;规则内条件为「与」关系。空数组表示不自动出库。固定前置条件:已复核 + 已分配储位。',
|
||||
itemFields: [
|
||||
{ key: 'enabled', label: '启用自动出库', type: 'boolean', description: '默认关闭' },
|
||||
{ key: 'require_recheck', label: '要求已复核', type: 'boolean', description: 'recheck_status=fin,默认开启' },
|
||||
{ key: 'require_pack', label: '要求已打包', type: 'boolean', description: 'pack_status=fin,默认开启' },
|
||||
{ key: 'require_weigh', label: '要求已称重', type: 'boolean', description: 'weighing_weight>0,默认开启' },
|
||||
{ key: 'require_sync', label: '要求已同步', type: 'boolean', description: 'sync_status=fin,默认开启' },
|
||||
{ key: 'require_print', label: '要求已打印', type: 'boolean', description: 'print_status=fin,默认开启' },
|
||||
{ key: 'require_pick', label: '要求已拣货', type: 'boolean', description: 'pick_status=fin,默认开启' },
|
||||
{ key: 'exclude_same_day_outbound', label: '不出库当天订单', type: 'boolean', defaultValue: true, description: '开启后,在当天放开时间前、「允许当天出库最后时间」之后复核的订单不自动出库,到达当天放开时间后恢复;默认开启' },
|
||||
{ key: 'same_day_outbound_deadline_time', label: '允许当天出库最后时间', type: 'string', maxLength: 5, defaultValue: '06:00', description: '格式 HH:mm,默认 06:00;复核时间早于该时间的订单不受「不出库当天订单」的影响' },
|
||||
{ key: 'same_day_outbound_release_time', label: '当天放开时间', type: 'string', maxLength: 5, defaultValue: '22:00', description: '格式 HH:mm,默认 22:00;开启「不出库当天订单」时,当天到达该时间后不再限制当天复核订单的自动出库' }
|
||||
{ key: 'require_pack', label: '要求已打包', type: 'boolean', defaultValue: true, description: 'pack_status=fin,默认开启' },
|
||||
{ key: 'require_weigh', label: '要求已称重', type: 'boolean', defaultValue: true, description: 'weighing_weight>0,默认开启' },
|
||||
{ key: 'require_sync', label: '要求已同步', type: 'boolean', defaultValue: true, description: 'sync_status=fin,默认开启' },
|
||||
{ key: 'exclude_same_day_outbound', label: '不出库当天订单', type: 'boolean', defaultValue: true, description: '开启后,按订单复核时间所在日计算:复核时间在「允许当天出库最后时间」之后的订单,需等到该日的「放行时间」才自动出库;默认开启' },
|
||||
{ key: 'same_day_outbound_deadline_time', label: '允许当天出库最后时间', type: 'string', maxLength: 5, defaultValue: '06:00', description: '格式 HH:mm,默认 06:00,范围 00:00-23:59;不能大于放行时间。当天不出库请设为 00:00' },
|
||||
{ key: 'same_day_outbound_release_time', label: '放行时间', type: 'string', maxLength: 5, defaultValue: '22:00', description: '格式 HH:mm,默认 22:00,支持跨天 00:00-47:59(24:00 之后表示次日,如 27:00 = 次日 03:00)。常用:23:59 = 当天不放、过零点出库' }
|
||||
]
|
||||
},
|
||||
{
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user