| | |
| | | import { message } from 'antd'; |
| | | import ProcessAPIService from '../services/ProcessAPIService'; |
| | | import OutboundBotAPIService from '../services/OutboundBotAPIService'; |
| | | import EvidenceAPIService from '../services/EvidenceAPIService'; |
| | | import MediationAgreementAPIService from '../services/MediationAgreementAPIService'; |
| | | import { getMergedParams } from '../utils/urlParams'; |
| | | import { mockTimelineData } from '../mocks/timeline'; |
| | | import { getFallbackStartTime, parseTimeString } from '../utils/timeFormatter'; |
| | |
| | | const [taskStartTime, setTaskStartTime] = useState(null); // 任务开始时间 |
| | | const [isTaskTimeFallback, setIsTaskTimeFallback] = useState(false); // 是否降级模式 |
| | | const [hasLoaded, setHasLoaded] = useState(false); // 防止重复加载 |
| | | |
| | | // 证据材料数据 |
| | | const [evidenceData, setEvidenceData] = useState({ |
| | | applicantMaterials: [], |
| | | respondentMaterials: [], |
| | | loading: false, |
| | | error: null |
| | | }); |
| | | |
| | | // 调解协议数据 |
| | | const [agreementData, setAgreementData] = useState({ |
| | | content: '', |
| | | loading: false, |
| | | error: null |
| | | }); |
| | | |
| | | /** |
| | | * 保存数据到localStorage |
| | |
| | | personId: item.personId, |
| | | mediationId: item.mediationId, |
| | | caseId: String(caseId), // 添加 caseId 字段用于轮询 |
| | | perTypeName: item.perTypeName || '', // 当事人类型名称(申请方当事人/被申请方当事人) |
| | | perClassName: item.perClassName || '', // 添加人员类型名称 |
| | | trueName: item.trueName || '', // 添加真实姓名 |
| | | startTime: item.createdTime || item.start_time, |
| | | startTime: item.createTime || item.createdTime || item.start_time, // 兼容 createTime 和 createdTime |
| | | pollStartTime: Date.now(), |
| | | retryCount: 0 |
| | | }); |
| | |
| | | failedJobs.push({ |
| | | personId: item.personId, |
| | | message: item.message || '未知错误', |
| | | perTypeName: item.perTypeName || '', // 当事人类型名称(申请方当事人/被申请方当事人) |
| | | perClassName: item.perClassName || '', // 添加人员类型名称 |
| | | trueName: item.trueName || '', // 添加真实姓名 |
| | | errorCode: item.errorCode, // 添加错误码 |
| | |
| | | localStorage.setItem(`${OUTBOUND_JOBS_KEY}_failed`, JSON.stringify(remainingFailedJobs)); |
| | | console.log('外呼成功后清除失败记录,清除数量:', storedFailedJobs.length - remainingFailedJobs.length); |
| | | } |
| | | |
| | | // 触发自定义事件,通知 OutboundCallWidget 组件立即刷新 |
| | | setTimeout(() => { |
| | | window.dispatchEvent(new CustomEvent('outbound-jobs-updated')); |
| | | }, 300); |
| | | } |
| | | |
| | | // 存储失败的任务到 localStorage(用于气泡显示) |
| | |
| | | console.log('Using fallback start time:', new Date(fallbackTime).toLocaleString()); |
| | | } |
| | | }; |
| | | |
| | | /** |
| | | * 加载证据材料数据 |
| | | * @param {Object} params - 参数对象 |
| | | * @param {string} params.caseId - 案件ID |
| | | * @param {string} params.caseType - 案件类型 |
| | | * @param {string} params.platformCode - 平台编码 |
| | | */ |
| | | const loadEvidenceData = async (params) => { |
| | | setEvidenceData(prev => ({ ...prev, loading: true, error: null })); |
| | | |
| | | try { |
| | | const response = await EvidenceAPIService.getEvidenceList({ |
| | | case_id: params.caseId, |
| | | case_type: params.caseType || params.caseTypeFirst, |
| | | platform_code: params.platformCode |
| | | }); |
| | | |
| | | console.log('Evidence API response:', response); |
| | | |
| | | const responseData = response.data || []; |
| | | |
| | | // 分离申请人和被申请人材料 |
| | | const applicantData = responseData.find(item => item.per_type === '15_020008-1'); |
| | | const respondentData = responseData.find(item => item.per_type === '15_020008-2'); |
| | | |
| | | const applicantList = applicantData?.file_list?.slice(0, applicantData.file_count) || []; |
| | | const respondentList = respondentData?.file_list?.slice(0, respondentData.file_count) || []; |
| | | |
| | | setEvidenceData({ |
| | | applicantMaterials: applicantList, |
| | | respondentMaterials: respondentList, |
| | | loading: false, |
| | | error: null |
| | | }); |
| | | |
| | | console.log('Evidence data loaded:', { applicantList, respondentList }); |
| | | } catch (err) { |
| | | console.error('加载证据材料失败:', err); |
| | | setEvidenceData(prev => ({ |
| | | ...prev, |
| | | loading: false, |
| | | error: err.message || '加载证据材料失败' |
| | | })); |
| | | } |
| | | }; |
| | | |
| | | /** |
| | | * 加载调解协议数据 |
| | | * @param {string} caseId - 案件ID |
| | | */ |
| | | const loadAgreementData = async (caseId) => { |
| | | setAgreementData(prev => ({ ...prev, loading: true, error: null })); |
| | | |
| | | try { |
| | | const response = await MediationAgreementAPIService.generateAgreement(caseId); |
| | | |
| | | if (response?.data?.agreeContent) { |
| | | setAgreementData({ |
| | | content: response.data.agreeContent, |
| | | loading: false, |
| | | error: null |
| | | }); |
| | | console.log('Agreement data loaded'); |
| | | } else { |
| | | setAgreementData({ |
| | | content: '', |
| | | loading: false, |
| | | error: '协议内容为空' |
| | | }); |
| | | } |
| | | } catch (err) { |
| | | console.error('加载调解协议失败:', err); |
| | | setAgreementData({ |
| | | content: '', |
| | | loading: false, |
| | | error: err.message || '加载调解协议失败' |
| | | }); |
| | | } |
| | | }; |
| | | |
| | | /** |
| | | * 加载案件数据 |
| | | */ |
| | |
| | | return; |
| | | } |
| | | |
| | | EvidenceAPIService.processCaseFilesOcr(params.caseId).catch((ocrError) => { |
| | | console.error('触发案件文件OCR失败:', ocrError); |
| | | }); |
| | | |
| | | try { |
| | | await OutboundBotAPIService.syncStatusByCase({ caseId: params.caseId }); |
| | | } catch (syncError) { |
| | |
| | | } |
| | | |
| | | // 调用API获取数据 |
| | | // 将URL中的auth_token转换为authorization传入API |
| | | const response = await ProcessAPIService.getCaseProcessInfo( |
| | | params.caseId, |
| | | { |
| | | caseTypeFirst: params.caseTypeFirst, |
| | | platform_code: params.platform_code |
| | | platform_code: params.platform_code, |
| | | authorization: params.auth_token || params.authorization || '' |
| | | } |
| | | ); |
| | | |
| | |
| | | setCaseData(timelineData); |
| | | setProcessNodes(Array.isArray(nodesData) ? nodesData : []); // 确保为数组 |
| | | setHasLoaded(true); // 标记已加载 |
| | | |
| | | // 并行加载证据材料和调解协议数据(在终态检查之前,确保数据完整性) |
| | | await Promise.all([ |
| | | loadEvidenceData({ |
| | | caseId: params.caseId, |
| | | caseType: params.caseType || params.caseTypeFirst, |
| | | caseTypeFirst: params.caseTypeFirst, |
| | | platformCode: params.platform_code |
| | | }), |
| | | loadAgreementData(params.caseId) |
| | | ]); |
| | | |
| | | // 检查终态状态(调解成功/失败/人工接管),终态不执行外呼和存储 |
| | | const mediationState = timelineData.mediation?.state; |
| | |
| | | refreshData, |
| | | loadCaseData, |
| | | taskStartTime, // 任务开始时间 |
| | | isTaskTimeFallback // 是否降级模式 |
| | | isTaskTimeFallback, // 是否降级模式 |
| | | // 证据材料数据 |
| | | evidenceData, |
| | | loadEvidenceData, |
| | | // 调解协议数据 |
| | | agreementData, |
| | | loadAgreementData |
| | | }; |
| | | |
| | | return ( |