Sprint 4-5: 员工自助+考勤+合规+AI+搜索
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
/**
|
||||
* 全局搜索路由 — 员工、页面、功能搜索
|
||||
*/
|
||||
import { Router } from 'express'
|
||||
import prisma from '../lib/prisma'
|
||||
import { authMiddleware, AuthRequest } from '../middleware/auth'
|
||||
|
||||
const router = Router()
|
||||
|
||||
/**
|
||||
* GET /search?q=keyword
|
||||
* 全局搜索:员工、部门等
|
||||
*/
|
||||
router.get('/', authMiddleware, async (req: AuthRequest, res, next) => {
|
||||
try {
|
||||
const q = (req.query.q as string || '').trim()
|
||||
if (!q || q.length < 1) {
|
||||
return res.json({ success: true, data: { employees: [] } })
|
||||
}
|
||||
|
||||
if (!req.user) {
|
||||
return res.status(401).json({ success: false, message: '未授权' })
|
||||
}
|
||||
const orgId = req.user.orgId
|
||||
|
||||
// 搜索员工(按姓名、工号、手机号)
|
||||
const employees = await prisma.employee.findMany({
|
||||
where: {
|
||||
orgId,
|
||||
OR: [
|
||||
{ name: { contains: q } },
|
||||
{ employeeNo: { contains: q } },
|
||||
{ phone: { contains: q } },
|
||||
],
|
||||
status: { notIn: ['TERMINATED'] },
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
name: true,
|
||||
department: true,
|
||||
position: true,
|
||||
employeeNo: true,
|
||||
},
|
||||
take: 10,
|
||||
})
|
||||
|
||||
res.json({ success: true, data: { employees } })
|
||||
} catch (err) { next(err) }
|
||||
})
|
||||
|
||||
export default router
|
||||
Reference in New Issue
Block a user