fix(supply-chain): 品牌兜底行的部门负责人/总负责人改按人员信息逻辑取
This commit is contained in:
parent
4c4807c72e
commit
5bc45f4e93
@ -128,7 +128,8 @@ type ReplacementContext = {
|
||||
|
||||
/**
|
||||
* 品牌维度的运营负责人兜底:这些品牌的行没有运营负责人时,统一指派给对应的负责人
|
||||
* (运营负责人 / 运营部门负责人 / 运营总负责人 三个字段一起填)。
|
||||
* (运营负责人取兜底的人;运营部门负责人、运营总负责人按人员信息表的「部门负责人/总负责人」取,
|
||||
* 与明细里原本就有负责人的行保持同一逻辑)。
|
||||
* 山东专用 → 刘景刚(利润中心山东项目组);分销专用 → 宋兵乙(利润中心按人员信息走)。
|
||||
*/
|
||||
export const BRAND_OWNER_FALLBACK: Record<string, string> = {
|
||||
@ -136,13 +137,44 @@ export const BRAND_OWNER_FALLBACK: Record<string, string> = {
|
||||
'其他品牌-分销专用': '宋兵乙',
|
||||
}
|
||||
|
||||
type BrandOwnerProfile = { departmentOwner: string; generalOwner: string }
|
||||
const BRAND_OWNER_PROFILE_TTL_MS = 10 * 60 * 1000
|
||||
let brandOwnerProfiles: { at: number; map: Map<string, BrandOwnerProfile> } | 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<string, BrandOwnerProfile>()
|
||||
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<SabcPeriodRows>(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))
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user