feat: 电子签全场景集成+场景筛选+设置开关
- ESignRecord 模型新增 scene 字段(CONTRACT/RESIGNATION/POLICY/PAYSLIP/ONBOARDING) - Organization 模型新增3个电子签开关:esignPolicyEnabled/esignPayslipEnabled/esignOnboardingEnabled - 设置页面企业信息新增电子签署设置区域,3个开关各自独立,缺省关闭 - 规章制度签收:开启电子签后,员工阅读确认时自动创建POLICY场景签署记录 - 工资条确认:开启电子签后,员工确认工资条时自动创建PAYSLIP场景签署记录 - 入职文件签署:开启电子签后,HR审批通过入职流程时自动创建ONBOARDING场景签署记录 - 电子签署列表增加场景筛选下拉(全部场景/劳动合同/离职协议/规章制度/工资条/入职文件) - 管理端和员工端列表均展示场景标签(基于scene字段,替代硬编码判断) - 合同和离职流程的esign调用已加scene参数
This commit is contained in:
@@ -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: 易签宝对接后启用
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user