feat: 20260805 系统优化 - 身份证复制fallback/薪税日期筛选/社保版本修复/证据链导出/违纪证明/医疗期政策/绩效类型评级/合同作废/帮助更新
This commit is contained in:
@@ -245,3 +245,101 @@ router.post('/retirement-policy/:id/confirm', requireAdmin, async (req: AuthRequ
|
||||
}
|
||||
})
|
||||
|
||||
// ========== 医疗期政策配置 ==========
|
||||
|
||||
const DEFAULT_POLICIES = [
|
||||
{
|
||||
region: '全国',
|
||||
legalBasis: '《企业职工患病或非因工负伤医疗期规定》第三条(劳部发[1994]479号)',
|
||||
rules: [
|
||||
{ maxYears: 5, months: 3, cycleMonths: 6 },
|
||||
{ maxYears: 10, months: 6, cycleMonths: 12 },
|
||||
{ maxYears: 15, months: 9, cycleMonths: 15 },
|
||||
{ maxYears: 20, months: 12, cycleMonths: 18 },
|
||||
{ maxYears: 999, months: 24, cycleMonths: 30 },
|
||||
],
|
||||
isDefault: true,
|
||||
},
|
||||
{
|
||||
region: '上海',
|
||||
legalBasis: '《上海市关于本市劳动者在履行劳动合同期间患病或者非因工负伤的医疗期标准的规定》',
|
||||
rules: [
|
||||
{ maxYears: 1, months: 3, cycleMonths: 6 },
|
||||
{ maxYears: 4, months: 3, cycleMonths: 6 },
|
||||
{ maxYears: 10, months: 6, cycleMonths: 12 },
|
||||
{ maxYears: 999, months: 9, cycleMonths: 18 },
|
||||
],
|
||||
isDefault: false,
|
||||
},
|
||||
]
|
||||
|
||||
// 获取医疗期政策列表
|
||||
router.get('/medical-period/policies', async (req: AuthRequest, res, next) => {
|
||||
try {
|
||||
let policies = await prisma.medicalPeriodPolicy.findMany({
|
||||
where: { orgId: req.user!.orgId },
|
||||
orderBy: [{ isDefault: 'desc' }, { region: 'asc' }],
|
||||
})
|
||||
if (policies.length === 0) {
|
||||
policies = await prisma.$transaction(
|
||||
DEFAULT_POLICIES.map(p =>
|
||||
prisma.medicalPeriodPolicy.create({
|
||||
data: { orgId: req.user!.orgId, ...p },
|
||||
})
|
||||
)
|
||||
)
|
||||
}
|
||||
res.json({ success: true, data: policies })
|
||||
} catch (err) {
|
||||
next(err)
|
||||
}
|
||||
})
|
||||
|
||||
// 新增/编辑医疗期政策
|
||||
const medicalPolicySchema = z.object({
|
||||
region: z.string().min(1, '地区名称不能为空'),
|
||||
legalBasis: z.string().min(1, '法律依据不能为空'),
|
||||
rules: z.array(z.object({
|
||||
maxYears: z.number().min(0),
|
||||
months: z.number().min(1),
|
||||
cycleMonths: z.number().min(1),
|
||||
})).min(1, '至少需要一条分档规则'),
|
||||
isDefault: z.boolean().default(false),
|
||||
})
|
||||
|
||||
router.post('/medical-period/policies', requireAdmin, async (req: AuthRequest, res, next) => {
|
||||
try {
|
||||
const data = medicalPolicySchema.parse(req.body)
|
||||
if (data.isDefault) {
|
||||
await prisma.medicalPeriodPolicy.updateMany({
|
||||
where: { orgId: req.user!.orgId },
|
||||
data: { isDefault: false },
|
||||
})
|
||||
}
|
||||
const policy = await prisma.medicalPeriodPolicy.upsert({
|
||||
where: { orgId_region: { orgId: req.user!.orgId, region: data.region } },
|
||||
update: { legalBasis: data.legalBasis, rules: data.rules, isDefault: data.isDefault },
|
||||
create: { orgId: req.user!.orgId, ...data },
|
||||
})
|
||||
res.json({ success: true, data: policy })
|
||||
} catch (err: any) {
|
||||
if (err.issues) return res.status(400).json({ success: false, error: { code: 'VALIDATION_ERROR', message: err.issues[0]?.message } })
|
||||
next(err)
|
||||
}
|
||||
})
|
||||
|
||||
// 删除医疗期政策
|
||||
router.delete('/medical-period/policies/:id', requireAdmin, async (req: AuthRequest, res, next) => {
|
||||
try {
|
||||
const policy = await prisma.medicalPeriodPolicy.findFirst({
|
||||
where: { id: req.params.id, orgId: req.user!.orgId },
|
||||
})
|
||||
if (!policy) return res.status(404).json({ success: false, error: { code: 'NOT_FOUND', message: '政策不存在' } })
|
||||
if (policy.isDefault) return res.status(400).json({ success: false, error: { code: 'BAD_REQUEST', message: '不能删除默认政策' } })
|
||||
await prisma.medicalPeriodPolicy.delete({ where: { id: req.params.id } })
|
||||
res.json({ success: true })
|
||||
} catch (err) {
|
||||
next(err)
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user