diff --git a/backend/prisma/schema.prisma b/backend/prisma/schema.prisma index 9ee57fe..d80b5ff 100644 --- a/backend/prisma/schema.prisma +++ b/backend/prisma/schema.prisma @@ -132,6 +132,9 @@ model Organization { contactPhone String? payrollFrequency Int @default(1) // 每月发薪次数(1=一次一批) retirementReminderEnabled Boolean @default(false) // 退休提醒开关 + esignPolicyEnabled Boolean @default(false) // 规章制度电子签 + esignPayslipEnabled Boolean @default(false) // 工资条电子签 + esignOnboardingEnabled Boolean @default(false) // 入职文件电子签 createdAt DateTime @default(now()) updatedAt DateTime @updatedAt @@ -1465,6 +1468,7 @@ model ESignRecord { contractId String? // 关联 LaborContract employeeId String employee Employee @relation(fields: [employeeId], references: [id], onDelete: Cascade) + scene String @default("CONTRACT") // CONTRACT | RESIGNATION | POLICY | PAYSLIP | ONBOARDING flowId String? // 易签宝流程ID documentTitle String // 文件标题 documentContent String? // 文件内容(HTML/PDF base64) diff --git a/backend/src/routes/esign.routes.ts b/backend/src/routes/esign.routes.ts index 75b071c..3814cfa 100644 --- a/backend/src/routes/esign.routes.ts +++ b/backend/src/routes/esign.routes.ts @@ -12,16 +12,19 @@ const createSignSchema = z.object({ documentTitle: z.string().min(1), documentContent: z.string().optional(), remark: z.string().optional(), + scene: z.string().optional(), }) // 签署记录列表 router.get('/', async (req: AuthRequest, res: Response, next: NextFunction) => { try { const status = req.query.status as string | undefined + const scene = req.query.scene as string | undefined const records = await prisma.eSignRecord.findMany({ where: { orgId: req.user!.orgId, ...(status && { status }), + ...(scene && { scene }), }, include: { employee: { select: { id: true, name: true, department: true, phone: true } }, @@ -56,6 +59,7 @@ router.post('/create', async (req: AuthRequest, res: Response, next: NextFunctio orgId: req.user!.orgId, contractId: data.contractId || null, employeeId: data.employeeId, + scene: data.scene || 'CONTRACT', documentTitle: data.documentTitle, documentContent: data.documentContent || null, // flowId: esignResult.flowId, // TODO: 易签宝对接后启用 diff --git a/backend/src/routes/portal.routes.ts b/backend/src/routes/portal.routes.ts index df6f298..fa6db6e 100644 --- a/backend/src/routes/portal.routes.ts +++ b/backend/src/routes/portal.routes.ts @@ -171,6 +171,25 @@ router.post('/payslip/:id/confirm', portalAuth, async (req: any, res, next) => { events: [{ action: '工资条确认', timestamp: new Date().toISOString(), ip: req.ip, userAgent: req.headers['user-agent'] }], createdBy: req.employee.id, }).catch(() => {}) + + // 如果开启了工资条电子签,创建电子签记录 + const org = await prisma.organization.findUnique({ where: { id: req.employee.orgId }, select: { esignPayslipEnabled: true } }) + if (org?.esignPayslipEnabled) { + await prisma.eSignRecord.create({ + data: { + orgId: req.employee.orgId, + employeeId: req.employee.id, + scene: 'PAYSLIP', + documentTitle: `工资条确认:${payslip.month}`, + status: 'PENDING', + initiatedBy: req.employee.id, + createdBy: req.employee.id, + remark: '工资条确认时自动发起', + expiredAt: new Date(Date.now() + 30 * 24 * 60 * 60 * 1000), + }, + }) + } + res.json({ success: true }) } catch (err) { next(err) @@ -544,6 +563,27 @@ router.post('/policies/:id/read', portalAuth, async (req: Request, res: Response userAgent: req.headers['user-agent'] || null, }, }) + + // 如果开启了制度电子签,创建电子签记录 + const org = await prisma.organization.findUnique({ where: { id: orgId }, select: { esignPolicyEnabled: true } }) + if (org?.esignPolicyEnabled) { + const policyDoc = await prisma.policyDocument.findUnique({ where: { id: req.params.id }, select: { title: true, content: true } }) + await prisma.eSignRecord.create({ + data: { + orgId, + employeeId, + scene: 'POLICY', + documentTitle: `制度签收:${policyDoc?.title || '未知'}`, + documentContent: policyDoc?.content || null, + status: 'PENDING', + initiatedBy: employeeId, + createdBy: employeeId, + remark: '制度阅读确认后自动发起', + expiredAt: new Date(Date.now() + 30 * 24 * 60 * 60 * 1000), + }, + }) + } + res.json({ success: true, data: { readAt: record.readAt.toISOString() } }) } catch (err) { next(err) diff --git a/backend/src/routes/settings.routes.ts b/backend/src/routes/settings.routes.ts index 03d1d5b..9b70861 100644 --- a/backend/src/routes/settings.routes.ts +++ b/backend/src/routes/settings.routes.ts @@ -28,7 +28,7 @@ router.get('/org', async (req: AuthRequest, res, next) => { try { const org = await prisma.organization.findUnique({ where: { id: req.user!.orgId }, - select: { id: true, name: true, plan: true, maxEmployees: true, city: true, contactName: true, contactPhone: true, payrollFrequency: true, retirementReminderEnabled: true, createdAt: true }, + select: { id: true, name: true, plan: true, maxEmployees: true, city: true, contactName: true, contactPhone: true, payrollFrequency: true, retirementReminderEnabled: true, esignPolicyEnabled: true, esignPayslipEnabled: true, esignOnboardingEnabled: true, createdAt: true }, }) res.json({ success: true, data: org }) } catch (err) { @@ -39,7 +39,7 @@ router.get('/org', async (req: AuthRequest, res, next) => { // 更新企业信息 router.put('/org', requireAdmin, async (req: AuthRequest, res, next) => { try { - const { name, payrollFrequency, city, contactName, contactPhone, retirementReminderEnabled } = req.body as { name?: string; payrollFrequency?: number; city?: string; contactName?: string; contactPhone?: string; retirementReminderEnabled?: boolean } + const { name, payrollFrequency, city, contactName, contactPhone, retirementReminderEnabled, esignPolicyEnabled, esignPayslipEnabled, esignOnboardingEnabled } = req.body as { name?: string; payrollFrequency?: number; city?: string; contactName?: string; contactPhone?: string; retirementReminderEnabled?: boolean; esignPolicyEnabled?: boolean; esignPayslipEnabled?: boolean; esignOnboardingEnabled?: boolean } const updateData: any = {} if (name) updateData.name = name if (payrollFrequency !== undefined) updateData.payrollFrequency = payrollFrequency @@ -47,10 +47,13 @@ router.put('/org', requireAdmin, async (req: AuthRequest, res, next) => { if (contactName !== undefined) updateData.contactName = contactName if (contactPhone !== undefined) updateData.contactPhone = contactPhone if (retirementReminderEnabled !== undefined) updateData.retirementReminderEnabled = retirementReminderEnabled + if (esignPolicyEnabled !== undefined) updateData.esignPolicyEnabled = esignPolicyEnabled + if (esignPayslipEnabled !== undefined) updateData.esignPayslipEnabled = esignPayslipEnabled + if (esignOnboardingEnabled !== undefined) updateData.esignOnboardingEnabled = esignOnboardingEnabled const org = await prisma.organization.update({ where: { id: req.user!.orgId }, data: updateData, - select: { id: true, name: true, plan: true, maxEmployees: true, city: true, contactName: true, contactPhone: true, payrollFrequency: true, retirementReminderEnabled: true }, + select: { id: true, name: true, plan: true, maxEmployees: true, city: true, contactName: true, contactPhone: true, payrollFrequency: true, retirementReminderEnabled: true, esignPolicyEnabled: true, esignPayslipEnabled: true, esignOnboardingEnabled: true }, }) res.json({ success: true, data: org }) } catch (err) { diff --git a/backend/src/routes/work-process.routes.ts b/backend/src/routes/work-process.routes.ts index c5ea1be..7f65cc7 100644 --- a/backend/src/routes/work-process.routes.ts +++ b/backend/src/routes/work-process.routes.ts @@ -164,6 +164,27 @@ router.post('/:id/approve', authMiddleware, async (req: AuthRequest, res: Respon ...(execResult.employeeId && !process.employeeId && { employeeId: execResult.employeeId }), }, }) + + // 入职审批通过且开启了入职文件电子签,创建电子签记录 + if (execResult.employeeId && process.type === 'ONBOARDING') { + const orgSettings = await prisma.organization.findUnique({ where: { id: req.user!.orgId }, select: { esignOnboardingEnabled: true } }) + if (orgSettings?.esignOnboardingEnabled) { + await prisma.eSignRecord.create({ + data: { + orgId: req.user!.orgId, + employeeId: execResult.employeeId, + scene: 'ONBOARDING', + documentTitle: '入职文件签署', + status: 'PENDING', + initiatedBy: req.user!.id, + createdBy: req.user!.id, + remark: '入职审批通过后自动发起', + expiredAt: new Date(Date.now() + 30 * 24 * 60 * 60 * 1000), + }, + }) + } + } + res.json({ success: true, data: updated }) } catch (err) { next(err) diff --git a/frontend/src/lib/api-services.ts b/frontend/src/lib/api-services.ts index 1740517..cb02e4a 100644 --- a/frontend/src/lib/api-services.ts +++ b/frontend/src/lib/api-services.ts @@ -603,9 +603,9 @@ export const benefitApi = { // ========== 电子签署(易签宝) ========== export const esignApi = { - list: (status?: string) => - get('/esign', { params: status ? { status } : {} }).then(unwrap()), - create: (data: { contractId?: string; employeeId: string; documentTitle: string; documentContent?: string; remark?: string }) => + list: (params?: { status?: string; scene?: string }) => + get('/esign', { params: params || {} }).then(unwrap()), + create: (data: { contractId?: string; employeeId: string; documentTitle: string; documentContent?: string; remark?: string; scene?: string }) => post('/esign/create', data), status: (id: string) => get(`/esign/${id}/status`).then(unwrap()), diff --git a/frontend/src/pages/ESign.tsx b/frontend/src/pages/ESign.tsx index db60a81..403fa62 100644 --- a/frontend/src/pages/ESign.tsx +++ b/frontend/src/pages/ESign.tsx @@ -19,9 +19,18 @@ const STATUS_CONFIG: Record = { CANCELLED: { label: '已取消', color: 'bg-gray-100 text-gray-500' }, } +const SCENE_CONFIG: Record = { + CONTRACT: { label: '劳动合同', color: 'bg-blue-50 text-blue-600 border border-blue-200' }, + RESIGNATION: { label: '离职协议', color: 'bg-orange-50 text-orange-600 border border-orange-200' }, + POLICY: { label: '规章制度', color: 'bg-amber-50 text-amber-600 border border-amber-200' }, + PAYSLIP: { label: '工资条', color: 'bg-emerald-50 text-emerald-600 border border-emerald-200' }, + ONBOARDING: { label: '入职文件', color: 'bg-purple-50 text-purple-600 border border-purple-200' }, +} + export default function ESign() { const queryClient = useQueryClient() const [filterStatus, setFilterStatus] = useState('') + const [filterScene, setFilterScene] = useState('') const [showCreate, setShowCreate] = useState(false) const [formData, setFormData] = useState({ employeeId: '', @@ -30,9 +39,9 @@ export default function ESign() { }) const { data: records = [], isLoading } = useQuery({ - queryKey: ['esign-records', filterStatus], + queryKey: ['esign-records', filterStatus, filterScene], queryFn: async () => { - return await esignApi.list(filterStatus || undefined) + return await esignApi.list({ status: filterStatus || undefined, scene: filterScene || undefined }) }, }) @@ -114,6 +123,14 @@ export default function ESign() { {Object.entries(STATUS_CONFIG).map(([k, v]) => )} + + + ))} + + ) } diff --git a/frontend/src/pages/Termination.tsx b/frontend/src/pages/Termination.tsx index d3f2731..135ea7c 100644 --- a/frontend/src/pages/Termination.tsx +++ b/frontend/src/pages/Termination.tsx @@ -1559,6 +1559,7 @@ export default function Termination() { employeeId, documentTitle: '离职协议', remark: '离职流程中发起', + scene: 'RESIGNATION', }) queryClient.invalidateQueries({ queryKey: ['esign-records'] }) toast.success('离职协议电子签署已发起') diff --git a/frontend/src/pages/portal/MyEsign.tsx b/frontend/src/pages/portal/MyEsign.tsx index 7c0f94c..9df5fff 100644 --- a/frontend/src/pages/portal/MyEsign.tsx +++ b/frontend/src/pages/portal/MyEsign.tsx @@ -18,6 +18,14 @@ const STATUS_MAP: Record }, } +const SCENE_LABELS: Record = { + CONTRACT: { label: '劳动合同', color: 'bg-blue-50 text-blue-600 border border-blue-200' }, + RESIGNATION: { label: '离职协议', color: 'bg-orange-50 text-orange-600 border border-orange-200' }, + POLICY: { label: '规章制度', color: 'bg-amber-50 text-amber-600 border border-amber-200' }, + PAYSLIP: { label: '工资条', color: 'bg-emerald-50 text-emerald-600 border border-emerald-200' }, + ONBOARDING: { label: '入职文件', color: 'bg-purple-50 text-purple-600 border border-purple-200' }, +} + export default function MyEsign() { const queryClient = useQueryClient() const [selectedId, setSelectedId] = useState(null) @@ -101,6 +109,11 @@ export default function MyEsign() { 关联合同 )} + {detail.scene && SCENE_LABELS[detail.scene] && ( +
+ {SCENE_LABELS[detail.scene].label} +
+ )} {/* 签署操作 */}
@@ -169,8 +182,8 @@ export default function MyEsign() {
{r.documentTitle} - {r.contractId && ( - 劳动合同 + {r.scene && SCENE_LABELS[r.scene] && ( + {SCENE_LABELS[r.scene].label} )}
diff --git a/frontend/src/pages/roster/ContractInfo.tsx b/frontend/src/pages/roster/ContractInfo.tsx index 035c326..6e8a438 100644 --- a/frontend/src/pages/roster/ContractInfo.tsx +++ b/frontend/src/pages/roster/ContractInfo.tsx @@ -27,6 +27,7 @@ export default function ContractInfo({ employeeId, contracts, hireDate }: { empl employeeId, documentTitle: `${data.contractType === 'UNFIXED' ? '无固定期限' : '固定期限'}劳动合同`, remark: '合同创建时自动发起', + scene: 'CONTRACT', }) toast.success('合同已保存,电子签署记录已创建') } catch {