From 5bc45f4e9373aedf2cb96b1f03b41b9caf75eed1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B1=85=E5=B1=85?= Date: Wed, 30 Sep 2026 15:41:07 +0800 Subject: [PATCH] =?UTF-8?q?fix(supply-chain):=20=E5=93=81=E7=89=8C?= =?UTF-8?q?=E5=85=9C=E5=BA=95=E8=A1=8C=E7=9A=84=E9=83=A8=E9=97=A8=E8=B4=9F?= =?UTF-8?q?=E8=B4=A3=E4=BA=BA/=E6=80=BB=E8=B4=9F=E8=B4=A3=E4=BA=BA?= =?UTF-8?q?=E6=94=B9=E6=8C=89=E4=BA=BA=E5=91=98=E4=BF=A1=E6=81=AF=E9=80=BB?= =?UTF-8?q?=E8=BE=91=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../supply-chain-product-sabc.service.ts | 48 ++++++++++++++++--- 1 file changed, 42 insertions(+), 6 deletions(-) diff --git a/furniture-3d-system/src/server/services/supply-chain-product-sabc.service.ts b/furniture-3d-system/src/server/services/supply-chain-product-sabc.service.ts index e665c44b..59925037 100644 --- a/furniture-3d-system/src/server/services/supply-chain-product-sabc.service.ts +++ b/furniture-3d-system/src/server/services/supply-chain-product-sabc.service.ts @@ -128,7 +128,8 @@ type ReplacementContext = { /** * 品牌维度的运营负责人兜底:这些品牌的行没有运营负责人时,统一指派给对应的负责人 - * (运营负责人 / 运营部门负责人 / 运营总负责人 三个字段一起填)。 + * (运营负责人取兜底的人;运营部门负责人、运营总负责人按人员信息表的「部门负责人/总负责人」取, + * 与明细里原本就有负责人的行保持同一逻辑)。 * 山东专用 → 刘景刚(利润中心山东项目组);分销专用 → 宋兵乙(利润中心按人员信息走)。 */ export const BRAND_OWNER_FALLBACK: Record = { @@ -136,13 +137,44 @@ export const BRAND_OWNER_FALLBACK: Record = { '其他品牌-分销专用': '宋兵乙', } +type BrandOwnerProfile = { departmentOwner: string; generalOwner: string } +const BRAND_OWNER_PROFILE_TTL_MS = 10 * 60 * 1000 +let brandOwnerProfiles: { at: number; map: Map } | null = null + +/** + * 预加载兜底负责人在人员信息里的「部门负责人 / 总负责人」。 + * 页面/导出在构建行之前调用一次,applyBrandOwnerFallback 再同步取用。 + */ +export async function loadBrandOwnerProfiles() { + if (brandOwnerProfiles && Date.now() - brandOwnerProfiles.at < BRAND_OWNER_PROFILE_TTL_MS) return brandOwnerProfiles.map + const names = [...new Set(Object.values(BRAND_OWNER_FALLBACK))] + const map = new Map() + try { + const rows = await prisma.supplyChainManagementOwnerConfig.findMany({ + where: { operationOwner: { in: names } }, + select: { operationOwner: true, departmentOwner: true, generalOwner: true }, + }) + for (const row of rows) { + map.set(row.operationOwner.trim(), { + departmentOwner: row.departmentOwner.trim(), + generalOwner: row.generalOwner.trim(), + }) + } + } catch { + // 人员信息不可用时只兜底运营负责人,部门负责人/总负责人保持原值 + } + brandOwnerProfiles = { at: Date.now(), map } + return map +} + function applyBrandOwnerFallback(row: SabcPageRow): SabcPageRow { if (String(row.opsHead ?? '').trim()) return row const fallback = BRAND_OWNER_FALLBACK[String(row.brand ?? '').trim()] if (!fallback) return row + const profile = brandOwnerProfiles?.map.get(fallback) row.opsHead = fallback - row.opsDeptHead = fallback - row.opsDirector = fallback + row.opsDeptHead = profile?.departmentOwner || row.opsDeptHead || fallback + row.opsDirector = profile?.generalOwner || row.opsDirector return row } @@ -824,14 +856,16 @@ export function aggregateSabcDimension( export class SupplyChainProductSabcService { async calculate(input: { year: number; month: number; apply: boolean }) { const { start, end, days } = createPeriodDates(input.year, input.month) - const [targets, categoryConfigurationResult, replacementRules] = await Promise.all([ + const [, categoryConfigurationResult, replacementRules, targets] = await Promise.all([ + // 兜底负责人(山东专用/分销专用)的部门负责人、总负责人取人员信息 + loadBrandOwnerProfiles(), + loadCategoryConfigurations(), + listProductArchiveReplacementRules(), prisma.supplyChainProductArchive.findMany({ where: createSabcArchiveScope(input.year, input.month), select: archiveSelect, orderBy: [{ businessCreatedAt: 'desc' }, { barcode: 'asc' }], }), - loadCategoryConfigurations(), - listProductArchiveReplacementRules(), ]) const configurations = categoryConfigurationResult const replacementIndex = buildReplacementIndex(replacementRules) @@ -923,6 +957,8 @@ export class SupplyChainProductSabcService { const cacheKey = `periodRows:${input.year}:${input.month}` const cached = input.fresh ? null : readSabcOverviewCache(cacheKey) if (cached) return cached + // 兜底负责人(山东专用/分销专用)的部门负责人、总负责人取人员信息 + await loadBrandOwnerProfiles() const { start, end } = createPeriodDates(input.year, input.month) const result = (await this.loadFrozenPeriodRows(start, end)) ?? (await this.buildLivePeriodRows(input.year, input.month))