fix: 退休检测改为按最新合同类型判断,排除劳务协议员工
detectRetirementRisks、updateEmployeesRetirementDays、日历退休日期查询 均改为 include 最新合同并在代码中判断 contractType,而非用 some 查询 (some 会匹配到历史 FIXED 合同导致劳务人员仍被检测)
This commit is contained in:
@@ -488,13 +488,16 @@ export async function detectMonthlyTasks(orgId: string) {
|
||||
*/
|
||||
export async function detectRetirementRisks(orgId: string) {
|
||||
const employees = await prisma.employee.findMany({
|
||||
where: { orgId, status: 'ACTIVE', birthDate: { not: null }, contracts: { some: { contractType: { in: ['FIXED', 'UNFIXED'] } } } },
|
||||
select: { id: true, name: true, gender: true, birthDate: true, femaleWorkerType: true },
|
||||
where: { orgId, status: 'ACTIVE', birthDate: { not: null } },
|
||||
include: { contracts: { orderBy: { createdAt: 'desc' }, take: 1 } },
|
||||
})
|
||||
|
||||
const risks: { employeeId: string; type: RiskType; level: RiskLevel; title: string; description: string; actionUrl: string }[] = []
|
||||
|
||||
for (const emp of employees) {
|
||||
// 只对最新合同为正式劳动合同的员工进行退休检测
|
||||
const latestContractType = emp.contracts[0]?.contractType
|
||||
if (!latestContractType || !['FIXED', 'UNFIXED'].includes(latestContractType)) continue
|
||||
if (!emp.birthDate) continue
|
||||
const gender = emp.gender || '男'
|
||||
const fwt = emp.femaleWorkerType
|
||||
@@ -1204,16 +1207,19 @@ export async function getMonthlyCalendar(orgId: string, month: string) {
|
||||
})
|
||||
}
|
||||
|
||||
// 6. 退休日期(仅正式劳动合同员工)
|
||||
// 6. 退休日期(仅最新合同为正式劳动合同的员工)
|
||||
const retiringEmployees = await prisma.employee.findMany({
|
||||
where: {
|
||||
orgId,
|
||||
status: 'ACTIVE',
|
||||
retirementDaysLeft: { gte: 0, lte: 365 },
|
||||
contracts: { some: { contractType: { in: ['FIXED', 'UNFIXED'] } } },
|
||||
},
|
||||
include: { contracts: { orderBy: { createdAt: 'desc' }, take: 1 } },
|
||||
})
|
||||
for (const emp of retiringEmployees) {
|
||||
// 只对最新合同为正式劳动合同的员工显示退休日期
|
||||
const latestContractType = emp.contracts[0]?.contractType
|
||||
if (!latestContractType || !['FIXED', 'UNFIXED'].includes(latestContractType)) continue
|
||||
if (emp.retirementDaysLeft !== null) {
|
||||
const retireDate = new Date()
|
||||
retireDate.setDate(retireDate.getDate() + emp.retirementDaysLeft)
|
||||
|
||||
Reference in New Issue
Block a user