gongxiangp2/lib/performance-salary-details-contract.ts
2026-12-01 11:46:25 +08:00

60 lines
3.0 KiB
TypeScript

import type { SalaryRole } from './performance-salary-roles'
import type { SalaryPosition } from './salary-position-contract'
import type { SalaryTemplate } from './performance-salary-templates'
import type { MarketIntentEvidence } from './salary-market-intent-contract'
import type { DepartmentDeliveryEvidence } from './salary-department-contract'
import { salaryMonthLabel } from './performance-salary-templates'
import type { SurveyMatchReason } from './salary-survey-scores'
export type SalaryCell = string | number | null
export type SalaryPhase = 'base' | 'partial' | 'full'
export type SalaryDataSource = 'survey' | 'on-time' | 'market-intent-top3' | 'points'
export type SalarySourceStatus = {
source: SalaryDataSource
salaryMonth: string
sourceMonth: string
} & ({ status: 'pending' } | { status: 'ready' } | { status: 'failed'; code: string; message: string })
export type SalaryDetailRow = {
employeeProfileId: string
employeeLabel: string
hasSalaryBase: boolean
positionGroupCode: string
values: Record<string, SalaryCell>
metrics: Record<string, number | null>
metricEvidence?: Record<string, MarketIntentEvidence | DepartmentDeliveryEvidence>
totalScore: number | null
positionId?: string
jobGrade?: string
performancePositionId?: string | null
performanceMatch?: 'matched' | 'unmatched'
}
export type SalaryDetails = {
scope?: { role: SalaryRole | 'all'; phase: SalaryPhase; sources: SalarySourceStatus[] }
displayMonth: string
sourceMonth: string
marketSourceMonth: string
isFallback: boolean
roles: Record<SalaryRole, SalaryDetailRow[]>
positionGroups: Array<{ position: SalaryPosition; template: SalaryTemplate; rows: SalaryDetailRow[] }>
surveyMatchIssues?: Array<{ employeeProfileId: string; employeeLabel: string; salaryRole: SalaryRole; reason: SurveyMatchReason; message: string }>
departmentMatchIssues?: Array<{ employeeProfileId: string; employeeLabel: string; message: string }>
pointsMatchIssues?: Array<{ employeeProfileId: string; employeeLabel: string; message: string }>
}
export const SALARY_STREAM_TYPE = 'application/x-ndjson'
export type SalaryStreamEvent = { data: SalaryDetails } | { error: string; status: number }
export const SALARY_XLSX_MIME = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
export const salaryDetailsExportFileName = (month: string) => `绩效薪资明细_${month}.xlsx`
export const salarySourceNames: Record<SalaryDataSource, string> = {
survey: '绩效调研', 'on-time': '按时交付率', 'market-intent-top3': '市场验证', points: '积分',
}
export function salarySourceLabel(data: Pick<SalaryDetails, 'displayMonth' | 'sourceMonth' | 'marketSourceMonth' | 'isFallback'>) {
const source = data.isFallback
? `${Number(data.displayMonth.slice(5))}月暂无调研数据,当前使用${salaryMonthLabel(data.sourceMonth)}数据测试`
: `数据月份:${salaryMonthLabel(data.sourceMonth)}`
return `${source};市场验证考核月份:${salaryMonthLabel(data.marketSourceMonth)}`
}