GuDingZiChan/backend/scripts/locationNormalization.js
2026-03-23 11:54:41 +08:00

134 lines
3.5 KiB
JavaScript

const normalizeText = (value) =>
String(value == null ? '' : value)
.replace(/\r/g, ' ')
.replace(/\n/g, ' ')
.replace(/\s+/g, ' ')
.trim()
const normalizeLookupKey = (value) => normalizeText(value).toUpperCase()
const STORAGE_LOCATION_ALIASES = {
天安: '常州-天安',
天安平面: '常州-天安',
天安3D: '常州-天安',
天安二楼分销: '常州-天安',
二楼分销: '常州-天安',
天安策划: '常州-天安',
天安二楼: '常州-天安',
天安直播间: '常州-天安',
天安东直播间: '常州-天安',
天安东南直播间: '常州-天安',
天安东小直播间: '常州-天安',
'天安-大龙虾': '常州-天安',
天安库存: '常州-天安',
天安数据机: '常州-天安',
天安3楼: '常州-天安',
天安3楼机房: '常州-天安',
天安影棚: '常州-天安',
天安三楼经管胖大海: '常州-天安',
影棚: '常州-天安',
摄影棚: '常州-天安',
摄影中心: '常州-天安',
摄影中心监控: '常州-天安',
二楼外贸: '常州-天安',
横林: '常州-仓库',
横林仓: '常州-仓库',
横林二仓: '常州-仓库',
横林客退: '常州-仓库',
客退: '常州-仓库',
常州临时仓: '常州-仓库',
崔桥工厂仓: '常州-仓库',
崔桥仓: '常州-仓库',
欧伯娜崔桥工厂: '常州-仓库',
欧伯娜工厂: '常州-仓库',
崔桥工厂欧伯娜: '常州-仓库',
新苏北仓: '常州-仓库',
常州: '常州-天安',
杭州: '杭州-万通中心',
杭州宋达: '杭州-万通中心',
南京: '南京-苏宁园区',
南京运营网盘: '南京-苏宁园区',
南京机房远程数据机: '南京-苏宁园区',
'10号楼1楼机房监控': '南京-苏宁园区',
'10号楼1楼监控室': '南京-苏宁园区',
'10号楼1楼配电间监控': '南京-苏宁园区',
'10号楼3楼机房': '南京-苏宁园区',
佛山3D: '佛山',
佛山平面: '佛山',
佛山建模: '佛山',
广东佛山: '佛山',
顺德仓: '佛山'
}
const resolveStorageLocationName = (rawValue) => {
const normalized = normalizeText(rawValue)
if (!normalized) {
return {
rawValue: normalized,
normalizedValue: '',
rule: ''
}
}
const aliased = STORAGE_LOCATION_ALIASES[normalized]
if (aliased) {
return {
rawValue: normalized,
normalizedValue: aliased,
rule: 'alias'
}
}
return {
rawValue: normalized,
normalizedValue: normalized,
rule: 'direct'
}
}
const resolveStorageLocationMatch = (rawValue, locationByName) => {
const normalized = normalizeText(rawValue)
if (!normalized) {
return {
rawValue: '',
normalizedValue: '',
match: null,
rule: ''
}
}
const directMatch = locationByName.get(normalizeLookupKey(normalized)) || null
if (directMatch) {
return {
rawValue: normalized,
normalizedValue: directMatch.name,
match: directMatch,
rule: 'direct'
}
}
const resolved = resolveStorageLocationName(rawValue)
if (!resolved.normalizedValue) {
return {
rawValue: normalized,
normalizedValue: '',
match: null,
rule: ''
}
}
const aliasMatch = locationByName.get(normalizeLookupKey(resolved.normalizedValue)) || null
return {
rawValue: normalized,
normalizedValue: resolved.normalizedValue,
match: aliasMatch,
rule: resolved.rule
}
}
module.exports = {
STORAGE_LOCATION_ALIASES,
resolveStorageLocationName,
resolveStorageLocationMatch
}