fix: 全面优化安全、性能和代码质量
P0: 环境变量校验/事务保护/RBAC权限 P1: 花名册分页/密码重置验证码/ErrorBoundary/N+1查询优化 P2: 导出限制/自定义错误类/body大小限制/代码去重 P3: 自定义确认弹窗替换window.confirm
This commit is contained in:
@@ -111,22 +111,30 @@ router.post('/contracts/preview-renew', authMiddleware, async (req: AuthRequest,
|
||||
}
|
||||
|
||||
// 合规检查:按员工分组,检查历史固定期合同次数
|
||||
const employeeIds = contracts.map((c) => c.employeeId)
|
||||
const allFixedContracts = await prisma.laborContract.findMany({
|
||||
where: {
|
||||
employeeId: { in: employeeIds },
|
||||
orgId: req.user!.orgId,
|
||||
contractType: 'FIXED',
|
||||
},
|
||||
orderBy: { startDate: 'asc' },
|
||||
})
|
||||
const fixedContractsByEmp = new Map<string, typeof allFixedContracts>()
|
||||
for (const c of allFixedContracts) {
|
||||
if (!fixedContractsByEmp.has(c.employeeId)) {
|
||||
fixedContractsByEmp.set(c.employeeId, [])
|
||||
}
|
||||
fixedContractsByEmp.get(c.employeeId)!.push(c)
|
||||
}
|
||||
|
||||
const results = []
|
||||
for (const contract of contracts) {
|
||||
const employee = contract.employee
|
||||
|
||||
// 查找该员工所有历史固定期合同(按时间正序,用于判断续签次数)
|
||||
const allFixedContracts = await prisma.laborContract.findMany({
|
||||
where: {
|
||||
employeeId: contract.employeeId,
|
||||
orgId: req.user!.orgId,
|
||||
contractType: 'FIXED',
|
||||
},
|
||||
orderBy: { startDate: 'asc' },
|
||||
})
|
||||
const empFixedContracts = fixedContractsByEmp.get(contract.employeeId) || []
|
||||
|
||||
// 当前合同是第几次固定期(从1开始计数)
|
||||
const currentIndex = allFixedContracts.findIndex((c) => c.id === contract.id)
|
||||
const currentIndex = empFixedContracts.findIndex((c) => c.id === contract.id)
|
||||
const renewalCount = currentIndex + 1
|
||||
|
||||
// 判断是否应签无固定期限:
|
||||
|
||||
Reference in New Issue
Block a user