Files
TurboHR/backend/src/routes/audit.routes.ts
T
freedakgmail fb36b10402 feat: 工作日历/考勤管理重构/AI人力报告/工作台员工分布/筛选优化/导入导出增强
- 新增工作日历页面(月历视图、事件管理、自定义事件)
- 考勤管理重构为6 Tab模块(班次/排班/每日出勤/月度报表/休假记录)
- AI顾问新增人力报告Tab,支持流式生成+Word导出
- 工作台总览新增员工分布统计(性别/年龄/学历/司龄饼图)+部门成本拆分
- 花名册/合同/解聘补偿新增部门和状态筛选
- 薪税管理新增工资表导入模板下载、银行代发CSV导出
- 社保公积金支持多公积金账户类型显示
- 数据导出新增花名册/解聘记录导出,中文文件名编码修复
- 数据导入新增模板下载(员工/增减员/工资表)+错误日志导出
- 移除工作台日历卡片(已迁移至独立工作日历页面)
- 新增20260728/20260729更新测试指导文档
2026-07-29 08:35:29 +08:00

81 lines
2.4 KiB
TypeScript

import { Router, Response, NextFunction } from 'express'
import prisma from '../lib/prisma'
import { authMiddleware, AuthRequest } from '../middleware/auth'
const router = Router()
router.use(authMiddleware)
/**
* 查询审计日志
* 支持按操作类型、实体类型、时间范围筛选
*/
router.get('/', async (req: AuthRequest, res: Response, next: NextFunction) => {
try {
const page = parseInt(req.query.page as string) || 1
const pageSize = Math.min(parseInt(req.query.pageSize as string) || 20, 200)
const action = req.query.action as string | undefined
const entity = req.query.entity as string | undefined
const userId = req.query.userId as string | undefined
const dateFrom = req.query.dateFrom as string | undefined
const dateTo = req.query.dateTo as string | undefined
const where: any = { orgId: req.user!.orgId }
if (action) where.action = { contains: action, mode: 'insensitive' }
if (entity) where.entity = entity
if (userId) where.userId = userId
if (dateFrom || dateTo) {
where.createdAt = {}
if (dateFrom) where.createdAt.gte = new Date(dateFrom)
if (dateTo) where.createdAt.lte = new Date(`${dateTo}T23:59:59`)
}
const [logs, total] = await Promise.all([
prisma.auditLog.findMany({
where,
orderBy: { createdAt: 'desc' },
skip: (page - 1) * pageSize,
take: pageSize,
}),
prisma.auditLog.count({ where }),
])
res.json({
success: true,
data: { items: logs, total, page, pageSize, totalPages: Math.ceil(total / pageSize) },
})
} catch (err) {
next(err)
}
})
/**
* 获取审计日志统计(按操作类型分组)
*/
router.get('/stats', async (req: AuthRequest, res: Response, next: NextFunction) => {
try {
const dateFrom = req.query.dateFrom as string | undefined
const dateTo = req.query.dateTo as string | undefined
const where: any = { orgId: req.user!.orgId }
if (dateFrom || dateTo) {
where.createdAt = {}
if (dateFrom) where.createdAt.gte = new Date(dateFrom)
if (dateTo) where.createdAt.lte = new Date(`${dateTo}T23:59:59`)
}
const stats = await prisma.auditLog.groupBy({
by: ['action'],
where,
_count: { action: true },
orderBy: { _count: { action: 'desc' } },
take: 20,
})
res.json({ success: true, data: stats })
} catch (err) {
next(err)
}
})
export default router