admin/sql/seed_doc_number_rule_20261114.sql
zzh 13997ae5d0
All checks were successful
Build and Deploy / deploy (push) Successful in 1m17s
feat: 单号规则支持截取模式,扫描条码按规则解析后再查单
新增 Generate/Extract 模式、匹配预览与运营扫描链路接入,并补充迁移种子与解析单测。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-14 19:28:10 +08:00

128 lines
4.4 KiB
SQL
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

-- =============================================================================
-- seed_doc_number_rule_20261114.sql
-- 单号规则种子:五类单据各一条「全通配」规则,公式对齐代码内置默认。
-- 可重复执行(按 DocType + RuleName 判重)。
-- 前置:已执行 migrate_doc_number_rule_20261114.sql(表存在)。
-- 说明:
-- - ProductCode / ChannelCode / CountryCode 为空 = 通配
-- - Priority 900:低于业务自定义规则(数值越小越优先),便于后续覆盖
-- - Status=2 启用
-- =============================================================================
-- 运单号(对齐内置:BCD + yyMMddHHmmss + 4 位随机)
INSERT INTO `t_doc_number_rule` (
`DocType`, `RuleName`, `Formula`, `ProductCode`, `ChannelCode`, `CountryCode`,
`Priority`, `Status`, `Remark`, `IsDeleted`, `CreateUserId`
)
SELECT
'ServiceNo',
'默认-运单号',
'BCD{yyMMddHHmmss}{RAND:4}',
NULL, NULL, NULL,
900, 2,
'全通配;未配置更具体规则时使用。等价于系统内置运单号。',
0, 0
FROM DUAL
WHERE NOT EXISTS (
SELECT 1 FROM `t_doc_number_rule`
WHERE `IsDeleted` = 0 AND `DocType` = 'ServiceNo' AND `RuleName` = '默认-运单号'
);
-- 客户单号(对齐内置:C + yyyyMMdd + 6 位随机;仅 ClientNo 为空时生成)
INSERT INTO `t_doc_number_rule` (
`DocType`, `RuleName`, `Formula`, `ProductCode`, `ChannelCode`, `CountryCode`,
`Priority`, `Status`, `Remark`, `IsDeleted`, `CreateUserId`
)
SELECT
'ClientNo',
'默认-客户单号',
'C{yyyyMMdd}{RAND:6}',
NULL, NULL, NULL,
900, 2,
'全通配;下单未填客户单号时使用。等价于系统内置客户单号。',
0, 0
FROM DUAL
WHERE NOT EXISTS (
SELECT 1 FROM `t_doc_number_rule`
WHERE `IsDeleted` = 0 AND `DocType` = 'ClientNo' AND `RuleName` = '默认-客户单号'
);
-- 揽收单号(对齐内置:PK + yyyyMMddHHmmss + 4 位随机)
INSERT INTO `t_doc_number_rule` (
`DocType`, `RuleName`, `Formula`, `ProductCode`, `ChannelCode`, `CountryCode`,
`Priority`, `Status`, `Remark`, `IsDeleted`, `CreateUserId`
)
SELECT
'PickupNo',
'默认-揽收单号',
'PK{yyyyMMddHHmmss}{RAND:4}',
NULL, NULL, NULL,
900, 2,
'全通配;等价于系统内置揽收单号。',
0, 0
FROM DUAL
WHERE NOT EXISTS (
SELECT 1 FROM `t_doc_number_rule`
WHERE `IsDeleted` = 0 AND `DocType` = 'PickupNo' AND `RuleName` = '默认-揽收单号'
);
-- 大包号(对齐内置:BAG + yyMMddHHmmss + 4 位随机)
INSERT INTO `t_doc_number_rule` (
`DocType`, `RuleName`, `Formula`, `ProductCode`, `ChannelCode`, `CountryCode`,
`Priority`, `Status`, `Remark`, `IsDeleted`, `CreateUserId`
)
SELECT
'BagNo',
'默认-大包号',
'BAG{yyMMddHHmmss}{RAND:4}',
NULL, NULL, NULL,
900, 2,
'全通配;等价于系统内置大包号。',
0, 0
FROM DUAL
WHERE NOT EXISTS (
SELECT 1 FROM `t_doc_number_rule`
WHERE `IsDeleted` = 0 AND `DocType` = 'BagNo' AND `RuleName` = '默认-大包号'
);
-- 主单号(对齐内置:MBL + yyMMddHHmmss + 4 位随机)
INSERT INTO `t_doc_number_rule` (
`DocType`, `RuleName`, `Formula`, `ProductCode`, `ChannelCode`, `CountryCode`,
`Priority`, `Status`, `Remark`, `IsDeleted`, `CreateUserId`
)
SELECT
'MasterNo',
'默认-主单号',
'MBL{yyMMddHHmmss}{RAND:4}',
NULL, NULL, NULL,
900, 2,
'全通配;等价于系统内置主单号。',
0, 0
FROM DUAL
WHERE NOT EXISTS (
SELECT 1 FROM `t_doc_number_rule`
WHERE `IsDeleted` = 0 AND `DocType` = 'MasterNo' AND `RuleName` = '默认-主单号'
);
-- ---------------------------------------------------------------------------
-- 示例:按国家细分的运单号(可按需改产品/渠道;不需要可删)
-- 公式示例:BCD + 国家 + 日期 + 日序号 6 位 → BCDUS261114000001
-- ---------------------------------------------------------------------------
INSERT INTO `t_doc_number_rule` (
`DocType`, `RuleName`, `Formula`, `ProductCode`, `ChannelCode`, `CountryCode`,
`Priority`, `Status`, `Remark`, `IsDeleted`, `CreateUserId`
)
SELECT
'ServiceNo',
'示例-美国运单号',
'BCD{COUNTRY}{yyMMdd}{SEQ:6}',
NULL, NULL, 'US',
100, 1,
'示例规则(默认禁用)。启用后仅目的国=US 时命中;可改 CountryCode / 公式。',
0, 0
FROM DUAL
WHERE NOT EXISTS (
SELECT 1 FROM `t_doc_number_rule`
WHERE `IsDeleted` = 0 AND `DocType` = 'ServiceNo' AND `RuleName` = '示例-美国运单号'
);