feat: 退休提醒功能 - 身份证提取出生日期、渐进式退休年龄计算、AI流式获取政策、用户确认生效

This commit is contained in:
freedakgmail
2026-07-25 01:21:07 +08:00
parent 169a0e1117
commit b892df1d52
10 changed files with 659 additions and 5 deletions
+38
View File
@@ -0,0 +1,38 @@
import prisma from '../src/lib/prisma'
import { decrypt } from '../src/lib/crypto'
function extractBirthDate(idCard: string): Date | null {
if (idCard.length === 18) {
const y = parseInt(idCard.substring(6, 10))
const m = parseInt(idCard.substring(10, 12))
const d = parseInt(idCard.substring(12, 14))
if (y && m && d) return new Date(y, m - 1, d)
}
if (idCard.length === 15) {
const y = parseInt('19' + idCard.substring(6, 8))
const m = parseInt(idCard.substring(8, 10))
const d = parseInt(idCard.substring(10, 12))
if (y && m && d) return new Date(y, m - 1, d)
}
return null
}
async function main() {
const employees = await prisma.employee.findMany({ select: { id: true, idCardNumber: true, birthDate: true } })
let updated = 0
for (const emp of employees) {
if (emp.birthDate) continue
if (!emp.idCardNumber) continue
let idCard: string
try { idCard = decrypt(emp.idCardNumber).toString() } catch { continue }
const birthDate = extractBirthDate(idCard)
if (birthDate) {
await prisma.employee.update({ where: { id: emp.id }, data: { birthDate } })
updated++
}
}
console.log(`Updated ${updated} employees with birthDate`)
await prisma.$disconnect()
}
main()