fix(category-config): 规模行导入同步一级类目与分类到类目配置(留空保留原值)

This commit is contained in:
WuYongJie 2026-09-24 15:46:30 +08:00
parent ebf9e6a6c4
commit d52fd19c49

View File

@ -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,