补齐迁移补录闭环与离线验证
This commit is contained in:
parent
ceacc2f98d
commit
247c3107b5
1
.gitignore
vendored
1
.gitignore
vendored
@ -17,6 +17,7 @@ error.log
|
||||
temp_migration_output/
|
||||
8.xlsx
|
||||
~$*.xlsx
|
||||
migration_manual_overrides.json
|
||||
行政手动补录清单*.xlsx
|
||||
地址标准化候选.csv
|
||||
01-login-page.png
|
||||
|
||||
389
backend/scripts/buildMigrationManualOverridesFromWorkbook.js
Normal file
389
backend/scripts/buildMigrationManualOverridesFromWorkbook.js
Normal file
@ -0,0 +1,389 @@
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
|
||||
const XLSX = require(path.resolve(__dirname, '../../frontend/node_modules/xlsx'))
|
||||
|
||||
const PROJECT_ROOT = path.resolve(__dirname, '../..')
|
||||
const DEFAULT_OUTPUT = path.join(PROJECT_ROOT, 'migration_manual_overrides.json')
|
||||
const WORKBOOK_PREFIX = '行政手动补录清单'
|
||||
|
||||
const normalizeText = (value) =>
|
||||
String(value == null ? '' : value)
|
||||
.replace(/\r/g, ' ')
|
||||
.replace(/\n/g, ' ')
|
||||
.replace(/\s+/g, ' ')
|
||||
.trim()
|
||||
|
||||
const normalizeAssetCode = (value) => normalizeText(value).toUpperCase()
|
||||
|
||||
const parseArgs = () => {
|
||||
const args = process.argv.slice(2)
|
||||
const options = {
|
||||
workbookPath: '',
|
||||
outputPath: DEFAULT_OUTPUT
|
||||
}
|
||||
|
||||
for (let index = 0; index < args.length; index += 1) {
|
||||
const arg = args[index]
|
||||
if (arg === '--workbook') {
|
||||
options.workbookPath = args[index + 1] || ''
|
||||
index += 1
|
||||
} else if (arg === '--output') {
|
||||
options.outputPath = args[index + 1] || DEFAULT_OUTPUT
|
||||
index += 1
|
||||
}
|
||||
}
|
||||
|
||||
return options
|
||||
}
|
||||
|
||||
const resolvePathArg = (value) => {
|
||||
const target = normalizeText(value)
|
||||
if (!target) {
|
||||
return ''
|
||||
}
|
||||
|
||||
return path.isAbsolute(target) ? target : path.resolve(process.cwd(), target)
|
||||
}
|
||||
|
||||
const resolveLatestWorkbookPath = () => {
|
||||
const matches = fs
|
||||
.readdirSync(PROJECT_ROOT, { withFileTypes: true })
|
||||
.filter(
|
||||
(entry) =>
|
||||
entry.isFile() &&
|
||||
entry.name.startsWith(WORKBOOK_PREFIX) &&
|
||||
entry.name.endsWith('.xlsx') &&
|
||||
!entry.name.startsWith('~$')
|
||||
)
|
||||
.map((entry) => ({
|
||||
path: path.join(PROJECT_ROOT, entry.name),
|
||||
mtimeMs: fs.statSync(path.join(PROJECT_ROOT, entry.name)).mtimeMs
|
||||
}))
|
||||
.sort((left, right) => left.mtimeMs - right.mtimeMs)
|
||||
|
||||
if (!matches.length) {
|
||||
throw new Error(`未找到 ${WORKBOOK_PREFIX}*.xlsx`)
|
||||
}
|
||||
|
||||
return matches[matches.length - 1].path
|
||||
}
|
||||
|
||||
const resolveWorkbookPath = (value) => {
|
||||
const resolved = resolvePathArg(value)
|
||||
const workbookPath = resolved || resolveLatestWorkbookPath()
|
||||
if (!fs.existsSync(workbookPath)) {
|
||||
throw new Error(`工作簿不存在: ${workbookPath}`)
|
||||
}
|
||||
return workbookPath
|
||||
}
|
||||
|
||||
const resolveOutputPath = (value) => {
|
||||
const resolved = resolvePathArg(value || DEFAULT_OUTPUT)
|
||||
if (!resolved) {
|
||||
return DEFAULT_OUTPUT
|
||||
}
|
||||
return resolved
|
||||
}
|
||||
|
||||
const normalizeOverrideMap = (value) => {
|
||||
if (!value || typeof value !== 'object' || Array.isArray(value)) {
|
||||
return {}
|
||||
}
|
||||
|
||||
const result = {}
|
||||
for (const [key, rawValue] of Object.entries(value)) {
|
||||
const normalizedKey = normalizeText(key)
|
||||
const normalizedValue = normalizeText(rawValue)
|
||||
if (!normalizedKey || !normalizedValue) {
|
||||
continue
|
||||
}
|
||||
result[normalizedKey] = normalizedValue
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
const normalizeAssetOverrideMap = (value) => {
|
||||
if (!value || typeof value !== 'object' || Array.isArray(value)) {
|
||||
return {}
|
||||
}
|
||||
|
||||
const result = {}
|
||||
for (const [key, rawOverride] of Object.entries(value)) {
|
||||
const assetCode = normalizeAssetCode(key)
|
||||
if (!assetCode || !rawOverride || typeof rawOverride !== 'object' || Array.isArray(rawOverride)) {
|
||||
continue
|
||||
}
|
||||
|
||||
const normalizedOverride = {}
|
||||
for (const [fieldKey, fieldValue] of Object.entries(rawOverride)) {
|
||||
const normalizedValue = normalizeText(fieldValue)
|
||||
if (!normalizedValue) {
|
||||
continue
|
||||
}
|
||||
normalizedOverride[fieldKey] = normalizedValue
|
||||
}
|
||||
|
||||
if (Object.keys(normalizedOverride).length > 0) {
|
||||
result[assetCode] = normalizedOverride
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
const loadExistingOverrides = (filePath) => {
|
||||
if (!fs.existsSync(filePath)) {
|
||||
return {
|
||||
departmentAliases: {},
|
||||
locationAliases: {},
|
||||
ownerAliases: {},
|
||||
assetOverrides: {}
|
||||
}
|
||||
}
|
||||
|
||||
const parsed = JSON.parse(fs.readFileSync(filePath, 'utf8'))
|
||||
return {
|
||||
departmentAliases: normalizeOverrideMap(parsed.departmentAliases),
|
||||
locationAliases: normalizeOverrideMap(parsed.locationAliases),
|
||||
ownerAliases: normalizeOverrideMap(parsed.ownerAliases),
|
||||
assetOverrides: normalizeAssetOverrideMap(parsed.assetOverrides)
|
||||
}
|
||||
}
|
||||
|
||||
const readSheetRows = (workbook, sheetName) => {
|
||||
const sheet = workbook.Sheets[sheetName]
|
||||
if (!sheet) {
|
||||
return []
|
||||
}
|
||||
|
||||
return XLSX.utils.sheet_to_json(sheet, { defval: '' })
|
||||
}
|
||||
|
||||
const createWorkbookState = (existing) => ({
|
||||
output: {
|
||||
departmentAliases: { ...existing.departmentAliases },
|
||||
locationAliases: { ...existing.locationAliases },
|
||||
ownerAliases: { ...existing.ownerAliases },
|
||||
assetOverrides: Object.fromEntries(
|
||||
Object.entries(existing.assetOverrides).map(([assetCode, fields]) => [assetCode, { ...fields }])
|
||||
)
|
||||
},
|
||||
provenance: {
|
||||
ownerAliases: Object.fromEntries(
|
||||
Object.keys(existing.ownerAliases).map((key) => [key, 'existing output'])
|
||||
),
|
||||
assetOverrides: Object.fromEntries(
|
||||
Object.entries(existing.assetOverrides).map(([assetCode, fields]) => [
|
||||
assetCode,
|
||||
Object.fromEntries(Object.keys(fields).map((fieldKey) => [fieldKey, 'existing output']))
|
||||
])
|
||||
)
|
||||
},
|
||||
stats: {
|
||||
ownerAliasRowsApplied: 0,
|
||||
assetOverrideFieldsApplied: 0,
|
||||
assetOverrideRowsTouched: 0,
|
||||
blankEditableRows: 0,
|
||||
skippedRowsWithoutAssetCode: 0
|
||||
}
|
||||
})
|
||||
|
||||
const setOwnerAlias = (state, ownerName, targetEmployee, context) => {
|
||||
const normalizedOwnerName = normalizeText(ownerName)
|
||||
const normalizedTarget = normalizeText(targetEmployee)
|
||||
if (!normalizedOwnerName || !normalizedTarget) {
|
||||
return
|
||||
}
|
||||
|
||||
const currentValue = state.output.ownerAliases[normalizedOwnerName]
|
||||
const currentSource = state.provenance.ownerAliases[normalizedOwnerName] || ''
|
||||
if (currentValue && currentValue !== normalizedTarget && currentSource !== 'existing output') {
|
||||
throw new Error(
|
||||
`花名映射冲突: ${normalizedOwnerName} 在 ${currentSource} 和 ${context} 填了不同目标员工`
|
||||
)
|
||||
}
|
||||
|
||||
if (currentValue !== normalizedTarget) {
|
||||
state.stats.ownerAliasRowsApplied += 1
|
||||
}
|
||||
|
||||
state.output.ownerAliases[normalizedOwnerName] = normalizedTarget
|
||||
state.provenance.ownerAliases[normalizedOwnerName] = context
|
||||
}
|
||||
|
||||
const setAssetOverrideField = (state, assetCode, fieldKey, fieldValue, context) => {
|
||||
const normalizedAssetCode = normalizeAssetCode(assetCode)
|
||||
const normalizedValue = normalizeText(fieldValue)
|
||||
if (!normalizedValue) {
|
||||
return false
|
||||
}
|
||||
|
||||
if (!normalizedAssetCode) {
|
||||
state.stats.skippedRowsWithoutAssetCode += 1
|
||||
return false
|
||||
}
|
||||
|
||||
if (!state.output.assetOverrides[normalizedAssetCode]) {
|
||||
state.output.assetOverrides[normalizedAssetCode] = {}
|
||||
}
|
||||
if (!state.provenance.assetOverrides[normalizedAssetCode]) {
|
||||
state.provenance.assetOverrides[normalizedAssetCode] = {}
|
||||
}
|
||||
|
||||
const currentValue = state.output.assetOverrides[normalizedAssetCode][fieldKey]
|
||||
const currentSource = state.provenance.assetOverrides[normalizedAssetCode][fieldKey] || ''
|
||||
if (currentValue && currentValue !== normalizedValue && currentSource !== 'existing output') {
|
||||
throw new Error(
|
||||
`资产覆盖冲突: ${normalizedAssetCode} 的 ${fieldKey} 在 ${currentSource} 和 ${context} 填了不同值`
|
||||
)
|
||||
}
|
||||
|
||||
if (currentValue !== normalizedValue) {
|
||||
if (Object.keys(state.output.assetOverrides[normalizedAssetCode]).length === 0) {
|
||||
state.stats.assetOverrideRowsTouched += 1
|
||||
}
|
||||
state.stats.assetOverrideFieldsApplied += 1
|
||||
}
|
||||
|
||||
state.output.assetOverrides[normalizedAssetCode][fieldKey] = normalizedValue
|
||||
state.provenance.assetOverrides[normalizedAssetCode][fieldKey] = context
|
||||
return true
|
||||
}
|
||||
|
||||
const processPendingSheet = (state, rows) => {
|
||||
for (let index = 0; index < rows.length; index += 1) {
|
||||
const row = rows[index]
|
||||
const context = `待确认部门 第${index + 2}行`
|
||||
const assetCode = row.legacy_asset_code
|
||||
const targets = [
|
||||
['department', row.行政填写_目标部门],
|
||||
['owner', row.行政填写_目标员工],
|
||||
['location', row.行政填写_标准地址],
|
||||
['currentStatus', row.行政填写_资产状态]
|
||||
]
|
||||
|
||||
let applied = false
|
||||
for (const [fieldKey, fieldValue] of targets) {
|
||||
applied = setAssetOverrideField(state, assetCode, fieldKey, fieldValue, context) || applied
|
||||
}
|
||||
|
||||
if (!applied) {
|
||||
state.stats.blankEditableRows += 1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const processOwnerManualSheet = (state, rows) => {
|
||||
for (let index = 0; index < rows.length; index += 1) {
|
||||
const row = rows[index]
|
||||
const context = `待补使用人 第${index + 2}行`
|
||||
const applied = setAssetOverrideField(state, row.legacy_asset_code, 'owner', row.行政填写_目标员工, context)
|
||||
if (!applied) {
|
||||
state.stats.blankEditableRows += 1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const processOwnerAliasSheet = (state, rows) => {
|
||||
for (let index = 0; index < rows.length; index += 1) {
|
||||
const row = rows[index]
|
||||
const ownerName = normalizeText(row.owner_name)
|
||||
const targetEmployee = normalizeText(row.行政填写_目标员工)
|
||||
if (!ownerName || !targetEmployee) {
|
||||
state.stats.blankEditableRows += 1
|
||||
continue
|
||||
}
|
||||
|
||||
setOwnerAlias(state, ownerName, targetEmployee, `花名核对 第${index + 2}行`)
|
||||
}
|
||||
}
|
||||
|
||||
const processLocationSheet = (state, rows) => {
|
||||
for (let index = 0; index < rows.length; index += 1) {
|
||||
const row = rows[index]
|
||||
const context = `待补地址 第${index + 2}行`
|
||||
const applied = setAssetOverrideField(
|
||||
state,
|
||||
row.legacy_asset_code,
|
||||
'location',
|
||||
row.行政填写_标准地址,
|
||||
context
|
||||
)
|
||||
if (!applied) {
|
||||
state.stats.blankEditableRows += 1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const sortObjectByKey = (value) =>
|
||||
Object.fromEntries(
|
||||
Object.entries(value).sort(([leftKey], [rightKey]) => leftKey.localeCompare(rightKey, 'zh-CN'))
|
||||
)
|
||||
|
||||
const sortNestedAssetOverrides = (assetOverrides) =>
|
||||
Object.fromEntries(
|
||||
Object.entries(assetOverrides)
|
||||
.sort(([leftKey], [rightKey]) => leftKey.localeCompare(rightKey, 'zh-CN'))
|
||||
.map(([assetCode, fields]) => [assetCode, sortObjectByKey(fields)])
|
||||
)
|
||||
|
||||
const buildSummary = (state) => ({
|
||||
ownerAliases: Object.keys(state.output.ownerAliases).length,
|
||||
departmentAliases: Object.keys(state.output.departmentAliases).length,
|
||||
locationAliases: Object.keys(state.output.locationAliases).length,
|
||||
assetOverrides: Object.keys(state.output.assetOverrides).length,
|
||||
assetOverrideFields: Object.values(state.output.assetOverrides).reduce(
|
||||
(total, fields) => total + Object.keys(fields).length,
|
||||
0
|
||||
),
|
||||
ownerAliasRowsApplied: state.stats.ownerAliasRowsApplied,
|
||||
assetOverrideFieldsApplied: state.stats.assetOverrideFieldsApplied,
|
||||
assetOverrideRowsTouched: state.stats.assetOverrideRowsTouched,
|
||||
blankEditableRows: state.stats.blankEditableRows,
|
||||
skippedRowsWithoutAssetCode: state.stats.skippedRowsWithoutAssetCode
|
||||
})
|
||||
|
||||
const run = () => {
|
||||
const options = parseArgs()
|
||||
const workbookPath = resolveWorkbookPath(options.workbookPath)
|
||||
const outputPath = resolveOutputPath(options.outputPath)
|
||||
const existing = loadExistingOverrides(outputPath)
|
||||
const state = createWorkbookState(existing)
|
||||
const workbook = XLSX.readFile(workbookPath, { raw: false })
|
||||
|
||||
processPendingSheet(state, readSheetRows(workbook, '待确认部门'))
|
||||
processOwnerManualSheet(state, readSheetRows(workbook, '待补使用人'))
|
||||
processOwnerAliasSheet(state, readSheetRows(workbook, '花名核对'))
|
||||
processLocationSheet(state, readSheetRows(workbook, '待补地址'))
|
||||
|
||||
const finalOutput = {
|
||||
departmentAliases: sortObjectByKey(state.output.departmentAliases),
|
||||
locationAliases: sortObjectByKey(state.output.locationAliases),
|
||||
ownerAliases: sortObjectByKey(state.output.ownerAliases),
|
||||
assetOverrides: sortNestedAssetOverrides(state.output.assetOverrides)
|
||||
}
|
||||
|
||||
fs.mkdirSync(path.dirname(outputPath), { recursive: true })
|
||||
fs.writeFileSync(outputPath, `${JSON.stringify(finalOutput, null, 2)}\n`)
|
||||
|
||||
console.log(
|
||||
JSON.stringify(
|
||||
{
|
||||
workbookPath,
|
||||
outputPath,
|
||||
summary: buildSummary(state)
|
||||
},
|
||||
null,
|
||||
2
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
try {
|
||||
run()
|
||||
} catch (error) {
|
||||
console.error(error && error.stack ? error.stack : String(error))
|
||||
process.exit(1)
|
||||
}
|
||||
@ -25,7 +25,8 @@ const parseArgs = () => {
|
||||
const options = {
|
||||
inputDir: '',
|
||||
importBackupDir: '',
|
||||
output: DEFAULT_OUTPUT
|
||||
output: DEFAULT_OUTPUT,
|
||||
nullLocationJson: ''
|
||||
}
|
||||
|
||||
for (let index = 0; index < args.length; index += 1) {
|
||||
@ -39,6 +40,9 @@ const parseArgs = () => {
|
||||
} else if (arg === '--output') {
|
||||
options.output = args[index + 1] || DEFAULT_OUTPUT
|
||||
index += 1
|
||||
} else if (arg === '--null-location-json') {
|
||||
options.nullLocationJson = args[index + 1] || ''
|
||||
index += 1
|
||||
}
|
||||
}
|
||||
|
||||
@ -197,6 +201,24 @@ const runRemoteNodeScript = (script) => {
|
||||
return JSON.parse(stdout)
|
||||
}
|
||||
|
||||
const readNullLocationRows = (nullLocationJsonArg) => {
|
||||
const resolvedPath = nullLocationJsonArg
|
||||
? path.isAbsolute(nullLocationJsonArg)
|
||||
? nullLocationJsonArg
|
||||
: path.resolve(process.cwd(), nullLocationJsonArg)
|
||||
: ''
|
||||
|
||||
if (resolvedPath) {
|
||||
if (!fs.existsSync(resolvedPath)) {
|
||||
throw new Error(`待补地址 JSON 不存在: ${resolvedPath}`)
|
||||
}
|
||||
|
||||
return readJson(resolvedPath)
|
||||
}
|
||||
|
||||
return runRemoteNodeScript(buildRemoteNullLocationScript())
|
||||
}
|
||||
|
||||
const buildRemoteNullLocationScript = () => `
|
||||
let PrismaClient
|
||||
try { ({ PrismaClient } = require('@prisma/client')) } catch { ({ PrismaClient } = require('/app/node_modules/@prisma/client')) }
|
||||
@ -372,7 +394,7 @@ const run = () => {
|
||||
const missingCode = readJson(path.join(importBackupDir, 'excluded_missing_code_rows.json'))
|
||||
const duplicateCodes = readJson(path.join(importBackupDir, 'excluded_duplicate_codes.json'))
|
||||
const plannedSummary = readJson(path.join(importBackupDir, 'planned_import_summary.json'))
|
||||
const liveNullLocationRows = runRemoteNodeScript(buildRemoteNullLocationScript())
|
||||
const liveNullLocationRows = readNullLocationRows(options.nullLocationJson)
|
||||
|
||||
const duplicateCodeSet = new Set(duplicateCodes.duplicateDetails.map((item) => item.legacyCode))
|
||||
const pendingRows = buildPendingRows(normalizedRecords)
|
||||
|
||||
@ -119,7 +119,8 @@ const parseArgs = () => {
|
||||
const args = process.argv.slice(2)
|
||||
const options = {
|
||||
workbookPath: WORKBOOK_PATH,
|
||||
overridesPath: ''
|
||||
overridesPath: '',
|
||||
liveSnapshotPath: ''
|
||||
}
|
||||
|
||||
for (let index = 0; index < args.length; index += 1) {
|
||||
@ -130,6 +131,9 @@ const parseArgs = () => {
|
||||
} else if (arg === '--overrides') {
|
||||
options.overridesPath = args[index + 1] || ''
|
||||
index += 1
|
||||
} else if (arg === '--live-snapshot') {
|
||||
options.liveSnapshotPath = args[index + 1] || ''
|
||||
index += 1
|
||||
}
|
||||
}
|
||||
|
||||
@ -582,7 +586,20 @@ const prisma = new PrismaClient()
|
||||
})
|
||||
`
|
||||
|
||||
const readLiveSnapshot = () => {
|
||||
const readLiveSnapshot = (snapshotPathArg = '') => {
|
||||
const snapshotPath = resolvePathArg(snapshotPathArg)
|
||||
if (snapshotPath) {
|
||||
if (!fs.existsSync(snapshotPath)) {
|
||||
throw new Error(`live 快照文件不存在: ${snapshotPath}`)
|
||||
}
|
||||
|
||||
return {
|
||||
source: 'file',
|
||||
path: snapshotPath,
|
||||
data: JSON.parse(fs.readFileSync(snapshotPath, 'utf8'))
|
||||
}
|
||||
}
|
||||
|
||||
if (!fs.existsSync(PLINK_PATH)) {
|
||||
throw new Error(`未找到 plink.exe: ${PLINK_PATH}`)
|
||||
}
|
||||
@ -616,7 +633,11 @@ const readLiveSnapshot = () => {
|
||||
throw new Error('live 快照返回为空')
|
||||
}
|
||||
|
||||
return JSON.parse(stdout)
|
||||
return {
|
||||
source: 'remote',
|
||||
path: '',
|
||||
data: JSON.parse(stdout)
|
||||
}
|
||||
}
|
||||
|
||||
const buildLookupMap = (items, keyGetter) => {
|
||||
@ -1073,7 +1094,8 @@ const run = () => {
|
||||
}
|
||||
|
||||
const workbook = loadWorkbookRows(workbookPath, manualOverrides.data)
|
||||
const liveSnapshot = readLiveSnapshot()
|
||||
const liveSnapshotResult = readLiveSnapshot(options.liveSnapshotPath)
|
||||
const liveSnapshot = liveSnapshotResult.data
|
||||
const refs = buildReferenceMaps(liveSnapshot)
|
||||
const personIndexes = buildPersonIndexes(liveSnapshot.persons)
|
||||
|
||||
@ -1106,6 +1128,8 @@ const run = () => {
|
||||
generatedAt: new Date().toISOString(),
|
||||
outputDir,
|
||||
sourceRowCount: workbook.rows.length,
|
||||
liveSnapshotSource: liveSnapshotResult.source,
|
||||
liveSnapshotPath: liveSnapshotResult.path || null,
|
||||
summary,
|
||||
referenceCounts: {
|
||||
assetTypes: liveSnapshot.assetTypes.length,
|
||||
|
||||
@ -348,13 +348,44 @@
|
||||
|
||||
如果输出文件被 Excel 占用,会自动换一个时间戳文件名。
|
||||
|
||||
另外这支脚本现在还支持:
|
||||
|
||||
- `--null-location-json`
|
||||
- 在当前会话没有远程密码时,改用本地 JSON 做离线结构验证
|
||||
|
||||
### 7.7 行政工作簿转 overrides 脚本
|
||||
|
||||
当前已经新增:
|
||||
|
||||
- `backend/scripts/buildMigrationManualOverridesFromWorkbook.js`
|
||||
|
||||
用途是:
|
||||
|
||||
- 行政填写工作簿
|
||||
- 脚本生成 `migration_manual_overrides.json`
|
||||
- `prepareEquipmentMigrationDryRun.js` 读取 overrides
|
||||
- 再次分桶
|
||||
|
||||
当前脚本已支持:
|
||||
|
||||
- 自动读取最新 `行政手动补录清单*.xlsx`
|
||||
- 也可手动指定 `--workbook`
|
||||
- 默认输出到 `migration_manual_overrides.json`
|
||||
- 同一资产字段或同一花名若存在冲突填写,直接报错拦截
|
||||
|
||||
---
|
||||
|
||||
## 8. 当前剩余问题到底是什么
|
||||
|
||||
### 8.1 还没导入的真正 pending 资产
|
||||
|
||||
当前真正还没有解决的 pending-review 只有 `23` 条。
|
||||
当前真正还没有解决的 pending-review,按“最新已验证 live 口径”仍是 `23` 条。
|
||||
|
||||
但要注意:
|
||||
|
||||
- 本地已做过一轮离线重跑验证
|
||||
- 因为加上了 `品牌营销策划中心 -> 品牌策划中心`
|
||||
- 离线 dry-run 已经把 pending 压到 `22`
|
||||
|
||||
按原始部门分布是:
|
||||
|
||||
@ -480,32 +511,45 @@
|
||||
- 剩下的主要靠行政确认
|
||||
- 如果没有一个“行政填完就能继续喂回系统”的闭环,后面又会变回人工重复劳动
|
||||
|
||||
### 10.2 我刚刚已经动手但还没验证的本地改动
|
||||
### 10.2 刚刚已经验证通过的本地改动
|
||||
|
||||
这一轮我已经开始改了两处脚本,但**用户在中途打断要求先写交接文档,所以这两处改动还没有重新跑 dry-run 验证,也没有部署,也没有导出新工作簿验证**。
|
||||
前一版交接里提到的两处“已改但未验证”脚本,当前已经完成本地离线验证。
|
||||
|
||||
本地已改但未验证的文件:
|
||||
已验证的文件:
|
||||
|
||||
- `backend/scripts/prepareEquipmentMigrationDryRun.js`
|
||||
- `backend/scripts/exportAdminManualReviewWorkbook.js`
|
||||
|
||||
本地已改的方向是:
|
||||
验证结论:
|
||||
|
||||
#### A. `prepareEquipmentMigrationDryRun.js`
|
||||
|
||||
已经开始补这些能力:
|
||||
当前已确认可用:
|
||||
|
||||
- 支持读取手工 overrides 文件
|
||||
- 支持对单条资产做字段覆盖
|
||||
- 支持对历史 owner / 历史部门 / 历史地址做人工映射覆盖
|
||||
- 支持 `--live-snapshot`
|
||||
- 已额外补了一条高置信度部门映射:
|
||||
- `品牌营销策划中心 -> 品牌策划中心`
|
||||
|
||||
但当前状态只是“文件已改”,**没有重新执行脚本验证结果**。
|
||||
本地离线验证结果:
|
||||
|
||||
- 使用已验证 live 快照重跑后
|
||||
- `pendingReview: 23 -> 22`
|
||||
- `importWithoutOwner: 401 -> 402`
|
||||
|
||||
确认被吃掉的是:
|
||||
|
||||
- `JS-PC-1719`
|
||||
- 原因从:
|
||||
- `unmapped_department|owner_not_in_active_synced_roster`
|
||||
- 变成:
|
||||
- `owner_not_in_active_synced_roster`
|
||||
|
||||
#### B. `exportAdminManualReviewWorkbook.js`
|
||||
|
||||
已经开始把行政工作簿改成可填写格式,方向是:
|
||||
当前已确认可用:
|
||||
|
||||
- 给 `待确认部门` 增加:
|
||||
- `行政填写_目标部门`
|
||||
@ -523,16 +567,24 @@
|
||||
- `行政填写_标准地址`
|
||||
- `行政填写_备注`
|
||||
- 增加 `填写说明` 工作表
|
||||
- 支持 `--null-location-json`
|
||||
|
||||
但当前同样只是“本地已改”,**还没有重新导出工作簿验证结构**。
|
||||
本地离线验证结果:
|
||||
|
||||
### 10.3 当前原计划但还没开始写的脚本
|
||||
- 已成功导出新版工作簿
|
||||
- `待确认部门`:`22`
|
||||
- `待补使用人`:`197`
|
||||
- `花名核对`:`106`
|
||||
- `待补地址`:`59`
|
||||
- 新增可填写列与 `填写说明` 工作表结构都已验证通过
|
||||
|
||||
我本来下一步要继续补一支新脚本,方向已经明确,但还没开始落文件:
|
||||
### 10.3 刚刚已经补完的新脚本
|
||||
|
||||
- 计划新增一个“行政工作簿 -> overrides JSON”的生成脚本
|
||||
当前已经新增:
|
||||
|
||||
预期用途是:
|
||||
- `backend/scripts/buildMigrationManualOverridesFromWorkbook.js`
|
||||
|
||||
当前用途是:
|
||||
|
||||
- 行政把工作簿填完
|
||||
- 脚本把填写结果转成 `migration_manual_overrides.json`
|
||||
@ -540,7 +592,20 @@
|
||||
- 重新分桶
|
||||
- 再用现有导入脚本继续导入 / 补挂 / 回填
|
||||
|
||||
这支脚本**目前还没开始创建文件**。
|
||||
当前已完成的本地验证:
|
||||
|
||||
- 空白行政列工作簿 -> 生成空 overrides JSON,结果正常
|
||||
- 样例填写工作簿 -> 成功生成:
|
||||
- `ownerAliases`
|
||||
- `assetOverrides`
|
||||
- 再把这份样例 overrides 喂回 dry-run
|
||||
- `pendingReview: 22 -> 21`
|
||||
- `importWithoutOwner: 402 -> 403`
|
||||
|
||||
注意:
|
||||
|
||||
- 这一步仍然只是本地离线验证
|
||||
- 还没有拿行政真实填写结果跑正式 overrides
|
||||
|
||||
---
|
||||
|
||||
@ -548,29 +613,29 @@
|
||||
|
||||
### 11.1 第一优先级
|
||||
|
||||
先不要继续改业务逻辑,先把“刚刚本地已改但未验证”的两处脚本跑通。
|
||||
先不要急着再猜部门或猜花名,优先用行政真实填写结果跑一次完整闭环。
|
||||
|
||||
也就是先做:
|
||||
|
||||
1. 检查 `backend/scripts/prepareEquipmentMigrationDryRun.js` 是否有语法错误
|
||||
2. 用当前 Excel 和当前 live 快照重新跑一轮 dry-run
|
||||
3. 看新 dry-run 是否正常输出
|
||||
4. 看 `品牌营销策划中心 -> 品牌策划中心` 这条高置信度映射是否让 pending 再减少
|
||||
5. 重新跑 `exportAdminManualReviewWorkbook.js`
|
||||
6. 看新工作簿列是否正确、是否真的可供行政填写
|
||||
1. 让行政基于新版工作簿填写 `目标员工 / 目标部门 / 标准地址 / 资产状态`
|
||||
2. 跑 `backend/scripts/buildMigrationManualOverridesFromWorkbook.js`
|
||||
3. 生成正式 `migration_manual_overrides.json`
|
||||
4. 再用当前 Excel + live 快照重跑 dry-run
|
||||
5. 看还能继续吃掉多少 `pending / ownerless / null-location`
|
||||
6. 再决定是否执行下一轮增量 live 导入
|
||||
|
||||
### 11.2 第二优先级
|
||||
|
||||
如果上面两步都正常,再继续补“工作簿 -> overrides JSON”的脚本。
|
||||
如果行政还没来得及填表,再补两件事中的一件:
|
||||
|
||||
这件事比继续硬猜部门更重要,因为:
|
||||
1. 继续整理 `59` 条待补地址,判断哪些应新增标准地址
|
||||
2. 继续整理 `196/197` 条历史花名,优先合并出稳定 owner alias
|
||||
|
||||
- 剩下的大头已经不是代码自己能完全猜出来的
|
||||
- 没有闭环,行政补完还得人工二次处理
|
||||
但不要在没有证据的情况下硬猜。
|
||||
|
||||
### 11.3 第三优先级
|
||||
|
||||
如果 overrides 流程做完,再继续:
|
||||
如果 overrides 流程已经拿到行政真实结果,再继续:
|
||||
|
||||
- 用行政填写后的结果生成 overrides
|
||||
- 重新跑 dry-run
|
||||
@ -610,6 +675,7 @@
|
||||
- `backend/scripts/importConfirmedEquipmentToLive.js`
|
||||
- `backend/scripts/backfillImportedEquipmentLocations.js`
|
||||
- `backend/scripts/exportAdminManualReviewWorkbook.js`
|
||||
- `backend/scripts/buildMigrationManualOverridesFromWorkbook.js`
|
||||
- `backend/scripts/locationNormalization.js`
|
||||
|
||||
### 12.3 关键输出目录和文件
|
||||
|
||||
@ -29,11 +29,57 @@
|
||||
- 已扩展 `backend/scripts/backfillImportedEquipmentLocations.js`
|
||||
- 不再只处理 `import-ready`
|
||||
- 也能处理 `import-without-owner`
|
||||
- 已扩展 `backend/scripts/prepareEquipmentMigrationDryRun.js`
|
||||
- 支持 `--live-snapshot`
|
||||
- 支持读取 `migration_manual_overrides.json`
|
||||
- 已加入高置信度部门映射:
|
||||
- `品牌营销策划中心 -> 品牌策划中心`
|
||||
- 已扩展 `backend/scripts/exportAdminManualReviewWorkbook.js`
|
||||
- 支持 `--null-location-json`
|
||||
- 可在没有远程密码的情况下做离线结构验证
|
||||
- 已新增 `backend/scripts/buildMigrationManualOverridesFromWorkbook.js`
|
||||
- 可把行政填写后的工作簿生成 `migration_manual_overrides.json`
|
||||
- 同一资产字段或同一花名如果填写冲突,会直接报错拦截
|
||||
- 今天地址回填结果:
|
||||
- 第一轮回填:32 条
|
||||
- 第二轮回填:5 条
|
||||
- 无标准地址从 96 压到 59
|
||||
|
||||
## 今天新增的本地离线验证结果
|
||||
|
||||
- 使用已验证 live 快照
|
||||
- `temp_migration_output/migration_dry_run_2026-03-23_03-01-06/live_reference_snapshot.json`
|
||||
- 重新跑 dry-run 后结果变为:
|
||||
- `importReady = 1255`
|
||||
- `importWithoutOwner = 402`
|
||||
- `pendingReview = 22`
|
||||
- `discardNoImport = 34`
|
||||
- 已确认新增映射确实生效:
|
||||
- `JS-PC-1719`
|
||||
- 原部门:`品牌营销策划中心`
|
||||
- 从 `pending-review`
|
||||
- 变成 `import-without-owner`
|
||||
- 使用离线 `null-location` JSON 重跑行政工作簿导出后,结构验证通过
|
||||
- `待确认部门`:22
|
||||
- `待补使用人`:197
|
||||
- `花名核对`:106
|
||||
- `待补地址`:59
|
||||
- 新增可填写列与 `填写说明` 工作表均已生成
|
||||
- 已做样例闭环验证:
|
||||
- 样例工作簿 -> `migration_manual_overrides.json`
|
||||
- 再喂给 dry-run
|
||||
- 结果可继续把 `pendingReview` 从 22 压到 21
|
||||
|
||||
## 当前说明
|
||||
|
||||
- 上面这轮新增验证是“本地离线验证”
|
||||
- 没有新的 live 写入
|
||||
- 原因是当前会话没有注入 `FIXED_ASSET_SSH_PASSWORD`
|
||||
- 但脚本链路本身已经打通到:
|
||||
- 行政工作簿可填写
|
||||
- 工作簿可生成 overrides
|
||||
- dry-run 可读取 overrides 重新分桶
|
||||
|
||||
## 关键输出文件
|
||||
|
||||
- 最新 dry-run:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user