diff --git a/furniture-3d-system/src/server/services/supply-chain-product-archive-category-scale-row.service.ts b/furniture-3d-system/src/server/services/supply-chain-product-archive-category-scale-row.service.ts index 2d4f8075..95ab634c 100644 --- a/furniture-3d-system/src/server/services/supply-chain-product-archive-category-scale-row.service.ts +++ b/furniture-3d-system/src/server/services/supply-chain-product-archive-category-scale-row.service.ts @@ -5,6 +5,7 @@ import { type CategoryConfigImportFailure, type CategoryConfigImportProgress, type CategoryConfigImportResult, + type ProductArchiveCategoryConfigStatus, type ProductArchiveCategoryScaleRow, } from '@/lib/supply-chain-product-archive-category-config' import { @@ -303,9 +304,30 @@ export class SupplyChainProductArchiveCategoryScaleRowService { try { const categoryL2 = String(row.categoryL2 ?? '').trim() if (!categoryL2) throw new AppError(ErrorCode.VALIDATION_REQUIRED_FIELD, '二级类目不能为空') - if (!configByL2.has(categoryL2)) { + const config = configByL2.get(categoryL2) + if (!config) { throw new AppError(ErrorCode.SUPPLY_CHAIN_CATEGORY_CONFIG_NOT_FOUND, '二级类目不存在,请先在类目配置中新增') } + + // 同步类目信息:文件里带一级类目/分类时更新类目配置(留空保留原值) + const fileL1 = String(row.categoryL1 ?? '').trim() + const fileGroup = String(row.categoryGroup ?? '').trim() + if (fileL1 || fileGroup) { + const updatedConfig = await this.categoryRepository.update({ + id: config.id, + categoryL2: config.categoryL2, + categoryL1: fileL1 || config.categoryL1, + categoryGroup: fileGroup || config.categoryGroup, + scaleLabel: config.scaleLabel, + performanceStart: config.performanceStart === null ? null : Number(config.performanceStart), + performanceEnd: config.performanceEnd === null ? null : Number(config.performanceEnd), + dailySalesStart: config.dailySalesStart === null ? null : Number(config.dailySalesStart), + dailySalesEnd: config.dailySalesEnd === null ? null : Number(config.dailySalesEnd), + status: config.status as ProductArchiveCategoryConfigStatus, + }) + configByL2.set(categoryL2, updatedConfig) + } + const data = buildRowInput({ scaleLabel: String(row.scaleLabel ?? '').trim(), performanceStart: row.performanceStart,