fix: 退休检测改为按最新合同类型判断,排除劳务协议员工

detectRetirementRisks、updateEmployeesRetirementDays、日历退休日期查询
均改为 include 最新合同并在代码中判断 contractType,而非用 some 查询
(some 会匹配到历史 FIXED 合同导致劳务人员仍被检测)
This commit is contained in:
freedakgmail
2026-08-17 21:04:00 +08:00
parent 0ea069cd57
commit f2cb5e66b2
2 changed files with 23 additions and 12 deletions
+13 -8
View File
@@ -236,19 +236,24 @@ export async function confirmRetirementPolicy(orgId: string, policyId: string):
// 批量更新员工距退休天数(基于个人出生日期 individually 计算)
export async function updateEmployeesRetirementDays(orgId: string): Promise<void> {
// 查询有正式劳动合同的员工
// 查询所有在职员工(含合同信息),在代码中按最新合同判断
const employees = await prisma.employee.findMany({
where: {
orgId,
contracts: { some: { contractType: { in: ['FIXED', 'UNFIXED'] } } },
},
select: { id: true, birthDate: true, gender: true, femaleWorkerType: true },
where: { orgId, status: 'ACTIVE', birthDate: { not: null } },
include: { contracts: { orderBy: { createdAt: 'desc' }, take: 1 } },
})
for (const emp of employees) {
if (!emp.birthDate) continue
const latestContractType = emp.contracts[0]?.contractType
if (!latestContractType || !['FIXED', 'UNFIXED'].includes(latestContractType)) {
// 非正式劳动合同:清除退休天数
await prisma.employee.update({
where: { id: emp.id },
data: { retirementDaysLeft: null },
})
continue
}
const gender = emp.gender || '男'
const daysLeft = calcRetirementDaysLeft(emp.birthDate, gender, emp.femaleWorkerType)
const daysLeft = calcRetirementDaysLeft(emp.birthDate!, gender, emp.femaleWorkerType)
if (daysLeft !== null) {
await prisma.employee.update({
where: { id: emp.id },