151 lines
9.7 KiB
TypeScript
151 lines
9.7 KiB
TypeScript
import { SALARY_ROLES, type SalaryRole } from './performance-salary-roles'
|
||
import type { MetricSource, SalaryPosition } from './salary-position-contract'
|
||
import { percentageBasisPoints } from './salary-position-contract'
|
||
|
||
export const SALARY_TEMPLATE_BLANK_ROWS = 5
|
||
export const SALARY_PATH = '/workspaces/organization/performance-review'
|
||
|
||
export type SalaryTemplateColumn = {
|
||
key: string
|
||
label: string
|
||
kind: 'text' | 'money' | 'number' | 'percent'
|
||
width: number
|
||
}
|
||
export type SalaryTemplateGroup = { key: string; label: string; columns: SalaryTemplateColumn[] }
|
||
export type SalaryTemplate = {
|
||
role: SalaryRole
|
||
title: string
|
||
month: string
|
||
grouped: boolean
|
||
groups: SalaryTemplateGroup[]
|
||
columns: SalaryTemplateColumn[]
|
||
}
|
||
|
||
export function currentSalaryMonth(now = new Date()): string {
|
||
const parts = new Intl.DateTimeFormat('en-US', {
|
||
timeZone: 'Asia/Shanghai', year: 'numeric', month: '2-digit',
|
||
}).formatToParts(now)
|
||
return `${parts.find(part => part.type === 'year')!.value}-${parts.find(part => part.type === 'month')!.value}`
|
||
}
|
||
|
||
export function isSalaryMonth(value: unknown): value is string {
|
||
return typeof value === 'string' && /^(?!0000)\d{4}-(0[1-9]|1[0-2])$/.test(value)
|
||
}
|
||
|
||
export function resolveSalaryMonth(value: unknown, now = new Date()): string {
|
||
return isSalaryMonth(value) ? value : currentSalaryMonth(now)
|
||
}
|
||
|
||
export function salaryMonthLabel(month: string, offset = 0): string {
|
||
const [year, number] = month.split('-').map(Number)
|
||
const index = year * 12 + number - 1 + offset
|
||
return `${Math.floor(index / 12)}年${((index % 12) + 12) % 12 + 1}月`
|
||
}
|
||
|
||
export function previousSalaryMonth(month: string): string {
|
||
const [year, number] = month.split('-').map(Number)
|
||
const index = year * 12 + number - 2
|
||
return `${String(Math.floor(index / 12)).padStart(4, '0')}-${String(((index % 12) + 12) % 12 + 1).padStart(2, '0')}`
|
||
}
|
||
|
||
export function salaryDetailsHref(role: SalaryRole, month: string): string {
|
||
return `${SALARY_PATH}?${new URLSearchParams({ role, month })}`
|
||
}
|
||
|
||
const column = (key: string, label: string, kind: SalaryTemplateColumn['kind'] = 'text', width = 144): SalaryTemplateColumn => ({ key, label, kind, width })
|
||
const group = (key: string, label: string, columns: SalaryTemplateColumn[]): SalaryTemplateGroup => ({ key, label, columns })
|
||
const identity = () => [
|
||
column('nickname', '花名', 'text', 104), column('name', '姓名', 'text', 104), column('jobGrade', '职级', 'text', 104),
|
||
column('department', '部门', 'text', 160),
|
||
]
|
||
const baseWages = () => [column('baseSalary', '基本工资', 'money'), column('gradeSalary', '职级工资', 'money'), column('performanceSalary', '绩效工资', 'money')]
|
||
const review = (key: string, label: string, overallShare: number | null, source: MetricSource['kind'] = 'survey'): SalaryTemplateColumn[] => overallShare === 0 ? [] : [
|
||
column(`${key}RawValue`, `${label} · ${source === 'market-intent-top3' ? '市场验证得分(上月)' : source === 'survey' ? '调研得分' : source === 'on-time' ? '按时交付率' : '原始得分'}`, source === 'on-time' ? 'percent' : 'number', 176),
|
||
column(`${key}Score`, `${label} · 考核得分(${source === 'market-intent-top3' ? '上月,' : ''}综合占比${overallShare === null ? '待配置' : `${overallShare}%`})`, 'number', 200),
|
||
]
|
||
const aiSharing = () => review('sharing', '知识分享/月度复盘分享', 0)
|
||
|
||
export function getSalaryTemplate(role: SalaryRole, month: string): SalaryTemplate {
|
||
const current = salaryMonthLabel(month)
|
||
const previous = salaryMonthLabel(month, -1)
|
||
const beforePrevious = salaryMonthLabel(month, -2)
|
||
const salarySummary = () => group('salary', '薪资', [
|
||
column('currentTotal', `${current}合计总薪资`, 'money', 184),
|
||
column('previousTotal', `${previous}合计总薪资`, 'money', 184),
|
||
column('salaryDifference', '环比上月薪资差值', 'money', 184),
|
||
])
|
||
const settlement = () => group('settlement', '绩效结算', [column('performanceCoefficient', '绩效系数', 'number')])
|
||
const remarks = () => group('remarks', '备注', [column('remarks', '备注', 'text', 224)])
|
||
const templates: Record<SalaryRole, SalaryTemplateGroup[]> = {
|
||
'ai-technical': [],
|
||
'ai-planning': [
|
||
group('identity', '基础信息', [...identity(), ...baseWages()]),
|
||
group('points', '积分', [column('points', `${current}积分`, 'number', 160)]),
|
||
group('qualitative', '定性 · 维度权重25%', [
|
||
...review('brandReview', '品牌调性评审', 25), ...review('collaboration', '跨部门协同', 0),
|
||
]),
|
||
group('quantitative', '定量 · 维度权重70%', [
|
||
...review('marketValidation', '创意成果市场验证', 7, 'market-intent-top3'),
|
||
...review('onTime', '项目按时交付率', 63, 'on-time'), ...aiSharing(),
|
||
]),
|
||
group('cooperation', '配合度 · 维度权重5%', review('cooperation', '工作配合度', 5)),
|
||
settlement(), salarySummary(), remarks(),
|
||
],
|
||
photography: [group('photography', '', [
|
||
column('nickname', '花名', 'text', 104), column('jobGrade', '职级', 'text', 104), column('position', '岗位', 'text', 160), column('department', '部门', 'text', 160),
|
||
column('baseSalaryBasis', '基础薪资基数', 'money', 160), column('baseSalary', '基础薪资', 'money'),
|
||
column('performanceSalaryBasis', '绩效薪资基数', 'money', 160), column('performanceCoefficient', '绩效系数', 'number'),
|
||
column('performanceSalary', '绩效薪资', 'money'), column('bonus', '奖金工资', 'money'), column('fixedPay', '固定薪酬', 'number'),
|
||
column('currentTotal', `${current}合计总薪资`, 'money', 184), column('previousTotal', `${previous}合计总薪资`, 'money', 184),
|
||
column('beforePreviousTotal', `${beforePrevious}合计薪资`, 'money', 184), column('salaryDifference', '环比上月薪资差值', 'money', 184), column('remarks', '备注', 'text', 224),
|
||
])],
|
||
'spatial-visual': [
|
||
group('identity', '基础信息', [...identity(), ...baseWages()]),
|
||
group('qualitative', '定性 · 维度权重20%', [
|
||
...review('aiTools', '协助搭建部门AI辅助工具', 3.2), ...review('collaboration', '跨部门协同', 0.8),
|
||
]),
|
||
group('quantitative', '定量', [
|
||
...review('onTime', '项目按时交付率', null, 'on-time'), ...aiSharing(),
|
||
]),
|
||
group('cooperation', '配合度 · 维度权重5%', review('cooperation', '工作配合度', 0.3)),
|
||
settlement(), salarySummary(), remarks(),
|
||
],
|
||
management: [
|
||
group('identity', '基础信息', [...identity(), ...baseWages()]),
|
||
group('qualitative', '定性 · 维度权重70%', [
|
||
...review('visualTone', '视觉调性', 56), ...review('collaboration', '跨部门协同', 14),
|
||
]),
|
||
group('quantitative', '定量 · 维度权重20%', [
|
||
...review('marketValidation', '创意成果市场验证', 8, 'unavailable'), ...review('onTime', '项目按时交付率', 8, 'on-time'),
|
||
...review('sharing', '知识分享/项目复盘', 4),
|
||
]),
|
||
group('satisfaction', '满意度 · 维度权重10%', review('cooperation', '工作配合度', 10)),
|
||
settlement(), salarySummary(), remarks(),
|
||
],
|
||
}
|
||
templates['ai-technical'] = [
|
||
group('identity', '基础信息', [...identity(), ...baseWages()]),
|
||
group('qualitative', '定性 · 维度权重30%', [...review('maintenance', '项目维护(使用方评分)', 15, 'unavailable'), ...review('projectResult', '项目成果验证', 15)]),
|
||
group('quantitative', '定量 · 维度权重60%', [...review('costReduction', 'AI功能降本成效(成本节约率)', 18, 'unavailable'), ...review('onTime', '项目按时交付率', 18, 'on-time'), ...review('sharing', '知识分享/月度复盘分享', 24)]),
|
||
group('cooperation', '配合度 · 维度权重10%', review('cooperation', '月度上级对成员工作配合满意度调研', 10)),
|
||
settlement(), salarySummary(), remarks(),
|
||
]
|
||
const groups = templates[role].filter(item => item.columns.length > 0)
|
||
return { role, title: SALARY_ROLES.find(item => item.key === role)!.title, month, grouped: role !== 'photography', groups, columns: groups.flatMap(item => item.columns) }
|
||
}
|
||
|
||
export function getPositionSalaryTemplate(position: SalaryPosition, month: string): SalaryTemplate {
|
||
const base = getSalaryTemplate(position.salaryRole, month)
|
||
const prefix: SalaryTemplateGroup[] = [group('identity', '基础信息', [...identity(), ...baseWages()])]
|
||
if (position.salaryRole === 'ai-planning') prefix.push(group('points', '积分', [column('points', `${salaryMonthLabel(month)}积分`, 'number', 160)]))
|
||
const assessment = position.dimensions.map(dimension => group(dimension.id, `${dimension.name} · 维度权重${dimension.weight}%`, dimension.metrics.flatMap(metric =>
|
||
// Integer basis points preserve tiny positive shares; only an exact zero hides the pair.
|
||
review(metric.id, metric.name, percentageBasisPoints(dimension.weight) * percentageBasisPoints(metric.weight) / 1e6, metric.source.kind))))
|
||
.filter(item => item.columns.length > 0)
|
||
const summary = position.salaryRole === 'photography'
|
||
? [group('settlement', '绩效结算', [column('performanceCoefficient', '绩效系数', 'number')]), group('salary', '薪资', base.columns.filter(item => ['bonus', 'fixedPay', 'currentTotal', 'previousTotal', 'beforePreviousTotal', 'salaryDifference'].includes(item.key))), group('remarks', '备注', [column('remarks', '备注', 'text', 224)])]
|
||
: base.groups.filter(item => ['settlement', 'salary', 'remarks'].includes(item.key)).map(item => ({ ...item, columns: item.columns.filter(item => !['baseSalary', 'gradeSalary', 'performanceSalary'].includes(item.key)) }))
|
||
const groups = [...prefix, ...assessment, ...summary]
|
||
return { ...base, title: position.name, grouped: true, groups, columns: groups.flatMap(item => item.columns) }
|
||
}
|