feat: 优化退休提醒功能 - 个性化退休年龄计算
- 添加 FemaleWorkerType enum (CADRE/WORKER) 和 Employee.femaleWorkerType 字段 - 新增 calcIndividualRetireAge: 按个人出生日期逐人计算退休年龄 - 重写 calcRetirementDaysLeft: 基于个人出生日期+性别+岗位类型 - updateEmployeesRetirementDays 使用 femaleWorkerType 区分女干部/女工人 - 前端新增/编辑员工表单添加女性岗位类型选择器 - 前端政策展示改为改革规则卡片(基准→目标年龄) - 前端距退休天数改为退休日期显示(XXXX年XX月XX日) - 移除AI退休政策计算相关代码和手动刷新路由 - 导入支持女性岗位类型列
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { useState, useEffect } from 'react'
|
||||
import { toast } from 'sonner'
|
||||
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query'
|
||||
import { Building2, Users, CreditCard, Plus, Bell, Download, Upload, FileSpreadsheet, Clock, CheckCircle, AlertCircle, RefreshCw } from 'lucide-react'
|
||||
import { Building2, Users, CreditCard, Plus, Bell, Download, Upload, FileSpreadsheet, Clock, CheckCircle, AlertCircle } from 'lucide-react'
|
||||
import api from '../lib/api'
|
||||
import { useAuthStore } from '../store/authStore'
|
||||
import Card from '../components/ui/Card'
|
||||
@@ -148,8 +148,6 @@ function OrgSettings({ orgData, onSave, saving }: { orgData: any; onSave: (data:
|
||||
function RetirementSection({ enabled, onToggle }: { enabled: boolean; onToggle: (v: boolean) => void }) {
|
||||
const queryClient = useQueryClient()
|
||||
const [confirming, setConfirming] = useState(false)
|
||||
const [refreshing, setRefreshing] = useState(false)
|
||||
const [streamContent, setStreamContent] = useState('')
|
||||
|
||||
const { data: policyData, isLoading } = useQuery<any>({
|
||||
queryKey: ['retirement-policy'],
|
||||
@@ -170,55 +168,33 @@ function RetirementSection({ enabled, onToggle }: { enabled: boolean; onToggle:
|
||||
onError: () => toast.error('确认失败'),
|
||||
})
|
||||
|
||||
const handleRefresh = async () => {
|
||||
setRefreshing(true)
|
||||
setStreamContent('')
|
||||
try {
|
||||
const token = useAuthStore.getState().accessToken
|
||||
const baseUrl = import.meta.env.DEV ? 'http://localhost:3000/api/v1' : '/api/v1'
|
||||
const res = await fetch(`${baseUrl}/settings/retirement-policy/refresh`, {
|
||||
method: 'POST',
|
||||
headers: { 'Authorization': `Bearer ${token}`, 'Content-Type': 'application/json' },
|
||||
})
|
||||
const reader = res.body?.getReader()
|
||||
const decoder = new TextDecoder()
|
||||
let buf = ''
|
||||
while (reader) {
|
||||
const { done, value } = await reader.read()
|
||||
if (done) break
|
||||
buf += decoder.decode(value, { stream: true })
|
||||
const lines = buf.split('\n')
|
||||
buf = lines.pop() || ''
|
||||
for (const line of lines) {
|
||||
if (line.startsWith('data: ')) {
|
||||
try {
|
||||
const msg = JSON.parse(line.slice(6))
|
||||
if (msg.type === 'chunk') {
|
||||
setStreamContent(prev => prev + msg.content)
|
||||
} else if (msg.type === 'done') {
|
||||
toast.success(msg.message || '已获取最新政策')
|
||||
setRefreshing(false)
|
||||
setStreamContent('')
|
||||
queryClient.invalidateQueries({ queryKey: ['retirement-policy'] })
|
||||
} else if (msg.type === 'error') {
|
||||
toast.error(msg.message || '获取失败')
|
||||
setRefreshing(false)
|
||||
setStreamContent('')
|
||||
}
|
||||
} catch {}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
toast.error('获取失败')
|
||||
setRefreshing(false)
|
||||
setStreamContent('')
|
||||
}
|
||||
}
|
||||
|
||||
const confirmed = policyData?.confirmed
|
||||
const pending = policyData?.pending
|
||||
|
||||
const renderPolicyRules = () => (
|
||||
<div className="space-y-2">
|
||||
<div className="text-xs font-medium text-gray-600">改革规则(基准退休年龄 → 目标退休年龄)</div>
|
||||
<div className="grid grid-cols-3 gap-2">
|
||||
<div className="bg-white rounded-md p-2 text-center border border-gray-200">
|
||||
<div className="text-xs text-gray-500">男性职工</div>
|
||||
<div className="text-sm font-semibold text-gray-700">60岁 → 63岁</div>
|
||||
<div className="text-xs text-gray-400">每4个月延1个月</div>
|
||||
</div>
|
||||
<div className="bg-white rounded-md p-2 text-center border border-gray-200">
|
||||
<div className="text-xs text-gray-500">女性干部</div>
|
||||
<div className="text-sm font-semibold text-gray-700">55岁 → 58岁</div>
|
||||
<div className="text-xs text-gray-400">每4个月延1个月</div>
|
||||
</div>
|
||||
<div className="bg-white rounded-md p-2 text-center border border-gray-200">
|
||||
<div className="text-xs text-gray-500">女性工人</div>
|
||||
<div className="text-sm font-semibold text-gray-700">50岁 → 55岁</div>
|
||||
<div className="text-xs text-gray-400">每2个月延1个月</div>
|
||||
</div>
|
||||
</div>
|
||||
<p className="text-xs text-gray-400">个人退休年龄根据出生年月逐人计算,达到基准退休年龄的时间点不同,延迟月数也不同。</p>
|
||||
</div>
|
||||
)
|
||||
|
||||
return (
|
||||
<div className="mt-6 pt-6 border-t">
|
||||
<div className="flex items-center justify-between mb-4">
|
||||
@@ -232,9 +208,6 @@ function RetirementSection({ enabled, onToggle }: { enabled: boolean; onToggle:
|
||||
{confirming ? '确认中...' : '确认生效'}
|
||||
</Button>
|
||||
)}
|
||||
<Button size="sm" variant="secondary" onClick={handleRefresh} disabled={refreshing}>
|
||||
<RefreshCw className="w-3 h-3 mr-1" />{refreshing ? '获取中...' : '重新获取'}
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
@@ -262,13 +235,7 @@ function RetirementSection({ enabled, onToggle }: { enabled: boolean; onToggle:
|
||||
确认于 {new Date(confirmed.confirmedAt).toLocaleDateString('zh-CN')}
|
||||
</span>
|
||||
</div>
|
||||
<div className="text-xs text-gray-600 space-y-1">
|
||||
<div>男性退休年龄:<b>{confirmed.maleRetireAge}岁</b> 女性干部:<b>{confirmed.femaleRetireAge}岁</b> 女性工人:<b>{confirmed.femaleWorkerAge}岁</b></div>
|
||||
<details className="mt-1">
|
||||
<summary className="cursor-pointer text-gray-500 hover:text-gray-700">查看完整政策内容</summary>
|
||||
<div className="mt-2 whitespace-pre-wrap text-xs max-h-48 overflow-y-auto bg-white rounded p-2 border">{confirmed.content}</div>
|
||||
</details>
|
||||
</div>
|
||||
{renderPolicyRules()}
|
||||
</div>
|
||||
)}
|
||||
|
||||
@@ -279,35 +246,18 @@ function RetirementSection({ enabled, onToggle }: { enabled: boolean; onToggle:
|
||||
<AlertCircle className="w-4 h-4 text-orange-600" />
|
||||
<span className="text-sm font-medium text-orange-800">检测到新政策版本(v{pending.version}),请确认后生效</span>
|
||||
</div>
|
||||
<div className="text-xs text-gray-600 space-y-1">
|
||||
<div>男性退休年龄:<b>{pending.maleRetireAge}岁</b> 女性干部:<b>{pending.femaleRetireAge}岁</b> 女性工人:<b>{pending.femaleWorkerAge}岁</b></div>
|
||||
<details className="mt-1">
|
||||
<summary className="cursor-pointer text-gray-500 hover:text-gray-700">查看完整政策内容</summary>
|
||||
<div className="mt-2 whitespace-pre-wrap text-xs max-h-48 overflow-y-auto bg-white rounded p-2 border">{pending.content}</div>
|
||||
</details>
|
||||
</div>
|
||||
{renderPolicyRules()}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* 无政策 */}
|
||||
{!confirmed && !pending && !isLoading && (
|
||||
<div className="rounded-lg border border-gray-200 bg-gray-50 p-3 text-center">
|
||||
<p className="text-sm text-gray-500">暂无退休政策数据,点击上方"重新获取"按钮获取最新政策</p>
|
||||
<p className="text-sm text-gray-500">暂无退休政策数据,系统将自动获取最新政策</p>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{isLoading && <p className="text-sm text-gray-400 text-center">加载中...</p>}
|
||||
|
||||
{/* 流式输出 */}
|
||||
{streamContent && (
|
||||
<div className="rounded-lg border border-blue-200 bg-blue-50 p-3">
|
||||
<div className="flex items-center gap-2 mb-2">
|
||||
<RefreshCw className="w-4 h-4 text-blue-600 animate-spin" />
|
||||
<span className="text-sm font-medium text-blue-800">AI 正在获取最新政策...</span>
|
||||
</div>
|
||||
<div className="whitespace-pre-wrap text-xs max-h-64 overflow-y-auto bg-white rounded p-2 border">{streamContent}</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user