fix: 修复当天入职员工被误判为预入职的时区问题;数据导出独立为设置Tab

This commit is contained in:
freedakgmail
2026-07-24 23:37:11 +08:00
parent 5c12f28ac7
commit bb25e1731c
3 changed files with 997 additions and 8 deletions
+8 -3
View File
@@ -28,8 +28,13 @@ router.get('/', authMiddleware, async (req: AuthRequest, res, next) => {
const contractStatus = req.query.contractStatus as string // active | expiring | expired | unsigned | etc.
const skip = (page - 1) * pageSize
// 使用本地日期午夜,避免时区问题导致当天入职被误判为预入职
const today = new Date()
today.setHours(0, 0, 0, 0)
// hireDate 可能以 UTC 午夜存储(如 new Date('2026-07-24')),在 UTC+8 下为 08:00
// 将 today 前移一天作为比较基准,确保当天入职的员工不被误判为预入职
const todayEnd = new Date(today)
todayEnd.setDate(todayEnd.getDate() + 1)
// 先查询满足 orgId 和搜索条件的员工
const whereBase: any = { orgId: req.user!.orgId }
@@ -45,10 +50,10 @@ router.get('/', authMiddleware, async (req: AuthRequest, res, next) => {
whereBase.status = 'RESIGNED'
} else if (status === 'PRE_HIRE') {
whereBase.status = 'ACTIVE'
whereBase.hireDate = { gt: today }
whereBase.hireDate = { gt: todayEnd }
} else if (status === 'ACTIVE') {
whereBase.status = 'ACTIVE'
whereBase.hireDate = { lte: today }
whereBase.hireDate = { lte: todayEnd }
}
// unsigned 合同状态可以在 DB 层过滤
@@ -101,7 +106,7 @@ router.get('/', authMiddleware, async (req: AuthRequest, res, next) => {
hireDate: e.hireDate,
})
const isResigned = e.terminations.some((t) => t.terminationDate <= today)
const isPreHire = !isResigned && e.hireDate > today
const isPreHire = !isResigned && e.hireDate > todayEnd
const dynamicStatus = isResigned ? 'RESIGNED' : (isPreHire ? 'PRE_HIRE' : 'ACTIVE')
return {
id: e.id,