feat: migrate cross checking ui to v3 flow
This commit is contained in:
@@ -2,6 +2,19 @@ import { postgrestGet, postgrestPut } from "../postgrest-client";
|
||||
import axios from 'axios';
|
||||
import { API_BASE_URL } from '../../config/api-config';
|
||||
|
||||
interface ResultEnvelope<T> {
|
||||
code?: number;
|
||||
msg?: string;
|
||||
data?: T;
|
||||
}
|
||||
|
||||
function unwrapResultEnvelope<T>(payload: unknown): T {
|
||||
if (payload && typeof payload === 'object' && 'data' in (payload as ResultEnvelope<T>)) {
|
||||
return ((payload as ResultEnvelope<T>).data ?? null) as T;
|
||||
}
|
||||
return payload as T;
|
||||
}
|
||||
|
||||
/**
|
||||
* 从不同格式的 API 响应中提取数据
|
||||
* @param responseData API 响应数据
|
||||
@@ -86,8 +99,7 @@ async function safeGetJWT(jwtToken?: string): Promise<string> {
|
||||
/**
|
||||
* 检查用户是否有权确认完成文档评查
|
||||
*
|
||||
* 🔥 接口文档: auth_doc/交叉评查接口文档.md 接口11
|
||||
* 📍 API地址: GET /api/v2/cross_review/tasks/{task_id}/can-confirm
|
||||
* 📍 API地址: GET /api/v3/cross-review/tasks/{task_id}/can-confirm
|
||||
*
|
||||
* @param taskId 任务ID
|
||||
* @param frontendJWT JWT token
|
||||
@@ -100,10 +112,8 @@ export async function findIsProposer(taskId: string | number, userId: number | u
|
||||
return false;
|
||||
}
|
||||
|
||||
// 调用新的接口检查用户是否有权确认完成
|
||||
// GET /api/v2/cross_review/tasks/{task_id}/can-confirm
|
||||
const response = await axios.get(
|
||||
`${API_BASE_URL}/api/v2/cross_review/tasks/${taskId}/can-confirm`,
|
||||
const response = await axios.get<ResultEnvelope<{ canConfirm?: boolean; can_confirm?: boolean }>>(
|
||||
`${API_BASE_URL}/api/v3/cross-review/tasks/${taskId}/can-confirm`,
|
||||
{
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
@@ -112,12 +122,8 @@ export async function findIsProposer(taskId: string | number, userId: number | u
|
||||
}
|
||||
);
|
||||
|
||||
const data = response.data;
|
||||
// console.log('[findIsProposer] 检查权限响应:', data);
|
||||
|
||||
// 返回 can_confirm 字段,表示是否有权确认完成
|
||||
// 有权限的用户:任务创建者(assigner_id) 或 主要负责人(principal_user_ids)
|
||||
return data?.can_confirm === true;
|
||||
const data = response.data?.data || response.data;
|
||||
return data?.canConfirm === true || data?.can_confirm === true;
|
||||
} catch (error) {
|
||||
console.error('[findIsProposer] 检查权限失败:', error);
|
||||
|
||||
@@ -147,26 +153,29 @@ export async function submitCrossCheckingOpinion(
|
||||
const token = await safeGetJWT(jwtToken);
|
||||
|
||||
const requestData = {
|
||||
document_id: opinionData.documentId,
|
||||
evaluation_point_id: Number(opinionData.evaluationPointId), // 强制转数字
|
||||
proposed_score: opinionData.deductionScore,
|
||||
reason: opinionData.auditOpinion,
|
||||
proposer_id: userInfo?.user_id,
|
||||
evaluation_result_id: opinionData.reviewPointResultId
|
||||
documentId: Number(opinionData.documentId),
|
||||
evaluationPointId: Number(opinionData.evaluationPointId),
|
||||
deductionScore: opinionData.deductionScore,
|
||||
auditOpinion: opinionData.auditOpinion,
|
||||
reviewPointResultId: Number(opinionData.reviewPointResultId)
|
||||
};
|
||||
|
||||
const response = await axios.post(`${API_BASE_URL}/api/v2/cross_review/proposals`, requestData, {
|
||||
const response = await axios.post<ResultEnvelope<{ proposalId?: number; createdAt?: string }>>(`${API_BASE_URL}/api/v3/cross-review/proposals`, requestData, {
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': `Bearer ${token}`
|
||||
}
|
||||
});
|
||||
const data = unwrapResultEnvelope<{ proposalId?: number; createdAt?: string }>(response.data);
|
||||
|
||||
return {
|
||||
data: {
|
||||
success: true,
|
||||
message: '意见提交成功',
|
||||
data: response.data
|
||||
data: {
|
||||
id: data?.proposalId,
|
||||
created_at: data?.createdAt || new Date().toISOString()
|
||||
}
|
||||
}
|
||||
};
|
||||
} catch (error) {
|
||||
@@ -213,64 +222,80 @@ export async function getCrossCheckingOpinions(
|
||||
// 如果没传userId,默认用1
|
||||
const realUserId = userId ?? 1;
|
||||
// 实际后端API调用,拼接API_BASE_URL
|
||||
const response = await axios.post(`${API_BASE_URL}/api/v2/cross_review/proposals/document`, {
|
||||
// user_id: realUserId,
|
||||
document_id: documentId, // 如果后端需要document_id可以加上
|
||||
page,
|
||||
page_size: pageSize
|
||||
}, {
|
||||
const response = await axios.get<ResultEnvelope<{
|
||||
total: number;
|
||||
page: number;
|
||||
pageSize: number;
|
||||
items: Array<{
|
||||
proposalId: string | number;
|
||||
evaluationPointName: string;
|
||||
proposedScore: number;
|
||||
reason: string;
|
||||
proposer: string;
|
||||
votes?: Array<{ voter: string; voteType: string }>;
|
||||
agreeVoters?: string[];
|
||||
disagreeVoters?: string[];
|
||||
pendingVoters?: string[];
|
||||
canVote?: boolean;
|
||||
problemMessage?: string;
|
||||
proposerId: number;
|
||||
createdAt: string;
|
||||
status: string;
|
||||
}>;
|
||||
}>>(`${API_BASE_URL}/api/v3/cross-review/documents/${documentId}/proposals`, {
|
||||
params: {
|
||||
page,
|
||||
pageSize
|
||||
},
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': `Bearer ${token}`
|
||||
}
|
||||
});
|
||||
|
||||
const data = response.data;
|
||||
// console.log('最原始的返回data', data);
|
||||
// 处理新的数据结构,支持分页
|
||||
const responseData = data.data || data;
|
||||
const pagination = data.pagination;
|
||||
const pageData = unwrapResultEnvelope<{
|
||||
total: number;
|
||||
page: number;
|
||||
pageSize: number;
|
||||
items: Array<{
|
||||
proposalId: string | number;
|
||||
evaluationPointName: string;
|
||||
proposedScore: number;
|
||||
reason: string;
|
||||
proposer: string;
|
||||
votes?: Array<{ voter: string; voteType: string }>;
|
||||
agreeVoters?: string[];
|
||||
disagreeVoters?: string[];
|
||||
pendingVoters?: string[];
|
||||
canVote?: boolean;
|
||||
problemMessage?: string;
|
||||
proposerId: number;
|
||||
createdAt: string;
|
||||
status: string;
|
||||
}>;
|
||||
}>(response.data);
|
||||
|
||||
// 定义后端返回的数据项类型
|
||||
interface ProposalItem {
|
||||
proposal_id: string | number;
|
||||
evaluation_point_name: string;
|
||||
proposed_score: number;
|
||||
reason: string;
|
||||
proposer: string;
|
||||
votes?: Array<{ voter: string; vote_type: string }>;
|
||||
agree_voters?: string[];
|
||||
disagree_voters?: string[];
|
||||
pending_voters?: string[];
|
||||
can_vote?: boolean;
|
||||
problem_message?: string;
|
||||
proposer_id: number;
|
||||
created_at: string;
|
||||
status: string;
|
||||
}
|
||||
|
||||
// 适配后端返回结构,使用新字段
|
||||
const opinions: CrossCheckingOpinion[] = Array.isArray(responseData) ? responseData.map((item: ProposalItem) => ({
|
||||
proposal_id: item.proposal_id,
|
||||
evaluation_point_name: item.evaluation_point_name,
|
||||
proposed_score: item.proposed_score,
|
||||
const opinions: CrossCheckingOpinion[] = Array.isArray(pageData?.items) ? pageData.items.map((item) => ({
|
||||
proposal_id: item.proposalId,
|
||||
evaluation_point_name: item.evaluationPointName,
|
||||
proposed_score: item.proposedScore,
|
||||
reason: item.reason,
|
||||
proposer: item.proposer,
|
||||
votes: item.votes || [],
|
||||
agree_voters: item.agree_voters || [],
|
||||
disagree_voters: item.disagree_voters || [],
|
||||
pending_voters: item.pending_voters || [],
|
||||
can_vote: item.can_vote ?? false,
|
||||
problem_message: item.problem_message || '',
|
||||
proposer_id: item.proposer_id,
|
||||
created_at: item.created_at,
|
||||
votes: (item.votes || []).map((vote) => ({ voter: vote.voter, vote_type: vote.voteType })),
|
||||
agree_voters: item.agreeVoters || [],
|
||||
disagree_voters: item.disagreeVoters || [],
|
||||
pending_voters: item.pendingVoters || [],
|
||||
can_vote: item.canVote ?? false,
|
||||
problem_message: item.problemMessage || '',
|
||||
proposer_id: item.proposerId,
|
||||
created_at: item.createdAt,
|
||||
status: item.status
|
||||
})) : [];
|
||||
|
||||
return {
|
||||
data: {
|
||||
opinions,
|
||||
total: pagination?.total || opinions.length
|
||||
total: pageData?.total || opinions.length
|
||||
}
|
||||
};
|
||||
} catch (error) {
|
||||
@@ -335,31 +360,29 @@ export async function performOpinionAction(
|
||||
switch (actionData.action) {
|
||||
case 'agree':
|
||||
message = '已赞同该意见';
|
||||
endpoint = `${API_BASE_URL}/api/v2/cross_review/proposals/${actionData.opinionId}/votes`;
|
||||
requestBody = { vote_type: 'agree', voter_id: userInfo?.user_id };
|
||||
endpoint = `${API_BASE_URL}/api/v3/cross-review/proposals/${actionData.opinionId}/votes`;
|
||||
requestBody = { voteType: 'agree' };
|
||||
break;
|
||||
case 'disagree':
|
||||
message = '已反对该意见';
|
||||
endpoint = `${API_BASE_URL}/api/v2/cross_review/proposals/${actionData.opinionId}/votes`;
|
||||
requestBody = { vote_type: 'disagree', voter_id: userInfo?.user_id };
|
||||
endpoint = `${API_BASE_URL}/api/v3/cross-review/proposals/${actionData.opinionId}/votes`;
|
||||
requestBody = { voteType: 'disagree' };
|
||||
break;
|
||||
case 'withdraw_vote':
|
||||
message = '已撤销投票';
|
||||
// 撤销投票的接口,根据实际API调整
|
||||
endpoint = `${API_BASE_URL}/api/v2/cross_review/proposals/${actionData.opinionId}/votes`;
|
||||
requestBody = { vote_type: 'cancel', voter_id: userInfo?.user_id };
|
||||
endpoint = `${API_BASE_URL}/api/v3/cross-review/proposals/${actionData.opinionId}/votes`;
|
||||
requestBody = { voteType: 'cancel' };
|
||||
break;
|
||||
case 'withdraw_opinion':
|
||||
message = '已撤销意见';
|
||||
// 撤销意见的接口,根据实际API调整
|
||||
endpoint = `${API_BASE_URL}/api/v2/cross_review/proposals/${actionData.opinionId}`;
|
||||
endpoint = `${API_BASE_URL}/api/v3/cross-review/proposals/${actionData.opinionId}`;
|
||||
requestBody = {};
|
||||
break;
|
||||
default:
|
||||
throw new Error('无效的操作类型');
|
||||
}
|
||||
|
||||
const response = actionData.action === 'withdraw_opinion'
|
||||
await (actionData.action === 'withdraw_opinion'
|
||||
? await axios.delete(endpoint, {
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
@@ -371,11 +394,7 @@ export async function performOpinionAction(
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': `Bearer ${token}`
|
||||
}
|
||||
});
|
||||
|
||||
const data = response.data;
|
||||
|
||||
console.log('返回的意见列表数据',data);
|
||||
}));
|
||||
|
||||
return {
|
||||
data: {
|
||||
@@ -412,8 +431,7 @@ export async function performOpinionAction(
|
||||
* @param frontendJWT JWT token
|
||||
* @returns 完成评查结果
|
||||
*
|
||||
* 🔥 接口文档: auth_doc/交叉评查接口文档(1).md 接口10
|
||||
* 📍 API地址: POST /admin/v2/cross_review/tasks/{task_id}/documents/{document_id}/complete
|
||||
* 📍 API地址: POST /api/v3/cross-review/tasks/{task_id}/documents/{document_id}/complete
|
||||
*/
|
||||
export async function confirmReviewResults(
|
||||
taskId: string | number,
|
||||
@@ -428,10 +446,13 @@ export async function confirmReviewResults(
|
||||
return { error: '文档ID不能为空', status: 400 };
|
||||
}
|
||||
|
||||
// 调用后端API确认文档审核完成
|
||||
// 接口: POST /admin/v2/cross_review/tasks/{task_id}/documents/{document_id}/complete
|
||||
const response = await axios.post(
|
||||
`${API_BASE_URL}/admin/v2/cross_review/tasks/${taskId}/documents/${documentId}/complete`,
|
||||
const response = await axios.post<ResultEnvelope<{
|
||||
taskId?: number;
|
||||
documentId?: number;
|
||||
taskStatus?: string;
|
||||
auditStatus?: number;
|
||||
}>>(
|
||||
`${API_BASE_URL}/api/v3/cross-review/tasks/${taskId}/documents/${documentId}/complete`,
|
||||
{}, // 无需请求体
|
||||
{
|
||||
headers: {
|
||||
@@ -441,15 +462,16 @@ export async function confirmReviewResults(
|
||||
}
|
||||
);
|
||||
|
||||
const data = response.data;
|
||||
const data = response.data?.data || response.data;
|
||||
|
||||
// 检查响应是否成功
|
||||
if (data?.success || data?.code === 0) {
|
||||
if (data) {
|
||||
return {
|
||||
data: {
|
||||
task_id: data.task_id || taskId,
|
||||
document_id: data.document_id || documentId,
|
||||
message: data.message || '文档评查已完成'
|
||||
task_id: data.taskId || taskId,
|
||||
document_id: data.documentId || documentId,
|
||||
task_status: data.taskStatus,
|
||||
audit_status: data.auditStatus,
|
||||
message: '文档评查已完成'
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -457,7 +479,7 @@ export async function confirmReviewResults(
|
||||
// 数据为空或格式不正确
|
||||
console.error('❌ [confirmReviewResults] API响应数据异常:', data);
|
||||
return {
|
||||
error: data?.message || '确认文档审核失败',
|
||||
error: '确认文档审核失败',
|
||||
status: 500
|
||||
};
|
||||
|
||||
@@ -491,26 +513,30 @@ export async function checkProposalVotes(
|
||||
// 获取JWT token
|
||||
const token = await safeGetJWT(jwtToken);
|
||||
|
||||
const requestData = {
|
||||
document_id: documentId
|
||||
};
|
||||
|
||||
const response = await axios.post(`${API_BASE_URL}/api/v2/cross_review/proposals/document/check_pending_votes`, requestData, {
|
||||
const response = await axios.get<ResultEnvelope<{
|
||||
hasPendingVotes?: boolean;
|
||||
pendingProposals?: Array<{ evaluationPointName: string; pendingVotersNum: number }>;
|
||||
}>>(`${API_BASE_URL}/api/v3/cross-review/documents/${documentId}/pending-votes`, {
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': `Bearer ${token}`
|
||||
}
|
||||
});
|
||||
|
||||
const data = response.data;
|
||||
|
||||
console.log("检查投票数据",data);
|
||||
const data = unwrapResultEnvelope<{
|
||||
hasPendingVotes?: boolean;
|
||||
pendingProposals?: Array<{ evaluationPointName: string; pendingVotersNum: number }>;
|
||||
}>(response.data);
|
||||
|
||||
return {
|
||||
data: {
|
||||
success: true,
|
||||
message: '检查成功',
|
||||
data: data
|
||||
data: {
|
||||
pending_proposals: (data?.pendingProposals || []).map((item) => ({
|
||||
evaluation_point_name: item.evaluationPointName,
|
||||
pending_voters_num: item.pendingVotersNum
|
||||
}))
|
||||
}
|
||||
}
|
||||
};
|
||||
} catch (error) {
|
||||
@@ -533,4 +559,3 @@ export async function checkProposalVotes(
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -199,19 +199,13 @@ export async function uploadCrossCheckingDocument(
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量上传并自动分配交叉评查任务(新接口适配)
|
||||
* @param files 文件列表
|
||||
* @param typeId 文档类型ID
|
||||
* @param priority 优先级
|
||||
* @param documentNumber 文档编号
|
||||
* @param remark 备注
|
||||
* @param isTestDocument 是否为测试文档
|
||||
* @param assignUserIds 需要分配的用户ID数组
|
||||
* @param taskName 任务名称
|
||||
* @param docType 文档类型(如 XZCF、XZXK)
|
||||
* @param taskType 任务类型(如 市局间交叉评查、区局间交叉评查)
|
||||
* @param token JWT Token
|
||||
* @param principalUserIds 负责人ID数组(包含主要负责人和额外负责人)
|
||||
* 旧的一体化“上传并分配任务”接口适配。
|
||||
*
|
||||
* 现在创建交叉评查任务已改为:
|
||||
* 1. 先上传文档
|
||||
* 2. 再调用 `createCrossReviewTask()` 创建 v3 任务
|
||||
*
|
||||
* 这里先保留兼容实现,避免影响可能的旧调用方。
|
||||
*/
|
||||
export async function batchUploadAndAssignCrossCheckingFiles(
|
||||
files: CrossCheckingUploadedFile[],
|
||||
@@ -286,16 +280,15 @@ export async function batchUploadAndAssignCrossCheckingFiles(
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建交叉评查任务
|
||||
* @param taskData 任务数据
|
||||
* @param token JWT Token
|
||||
* @returns 创建结果
|
||||
* 创建交叉评查任务(v3)。
|
||||
* 先由前端完成文档上传,再将上传成功后的 documentIds 挂到任务上。
|
||||
*/
|
||||
export async function createCrossReviewTask(taskData: {
|
||||
documentIds: number[];
|
||||
userIds: number[];
|
||||
assignerId: number;
|
||||
principalUserIds?: number[];
|
||||
taskName: string;
|
||||
docTypeId?: number;
|
||||
docType: string;
|
||||
taskType?: string;
|
||||
}, token: string | null = null): Promise<{
|
||||
@@ -305,12 +298,13 @@ export async function createCrossReviewTask(taskData: {
|
||||
}> {
|
||||
try {
|
||||
const requestBody = {
|
||||
document_ids: taskData.documentIds,
|
||||
user_ids: taskData.userIds,
|
||||
assigner_id: taskData.assignerId,
|
||||
task_name: taskData.taskName,
|
||||
doc_type: taskData.docType,
|
||||
task_type: taskData.taskType || '市局间交叉评查'
|
||||
documentIds: taskData.documentIds,
|
||||
memberUserIds: taskData.userIds,
|
||||
principalUserIds: taskData.principalUserIds || [],
|
||||
taskName: taskData.taskName,
|
||||
docTypeId: taskData.docTypeId,
|
||||
docTypeCode: taskData.docType,
|
||||
taskType: taskData.taskType || 'CITY'
|
||||
};
|
||||
|
||||
// console.log('[创建任务] 请求数据:', requestBody);
|
||||
@@ -323,7 +317,7 @@ export async function createCrossReviewTask(taskData: {
|
||||
}
|
||||
|
||||
const response = await axios.post(
|
||||
`${API_BASE_URL}/admin/cross_review/tasks/assign`,
|
||||
`${API_BASE_URL}/api/v3/cross-review/tasks`,
|
||||
requestBody,
|
||||
{ headers }
|
||||
);
|
||||
@@ -376,7 +370,7 @@ export function formatFileSize(bytes: number): string {
|
||||
/**
|
||||
* 向已有任务上传新文档
|
||||
*
|
||||
* POST /api/v2/cross_review/tasks/{task_id}/upload_documents
|
||||
* POST /api/v3/cross-review/tasks/{task_id}/documents/upload
|
||||
*
|
||||
* @param params 上传参数
|
||||
* @returns 上传结果
|
||||
@@ -396,10 +390,9 @@ export async function uploadDocumentToTask(params: {
|
||||
console.log('[上传文档到任务] 开始上传:', { taskId, fileName: file.name });
|
||||
|
||||
const formData = new FormData();
|
||||
// 添加文件(使用 files 字段名)
|
||||
formData.append('files', file, file.name);
|
||||
formData.append('file', file, file.name);
|
||||
|
||||
const uploadEndpoint = `/api/v2/cross_review/tasks/${taskId}/upload_documents`;
|
||||
const uploadEndpoint = `/api/v3/cross-review/tasks/${taskId}/documents/upload`;
|
||||
const uploadUrl = API_BASE_URL + uploadEndpoint;
|
||||
|
||||
const headers: Record<string, string> = {};
|
||||
@@ -410,10 +403,9 @@ export async function uploadDocumentToTask(params: {
|
||||
const response = await axios.post(uploadUrl, formData, { headers });
|
||||
const result = response.data;
|
||||
|
||||
// 新接口响应格式: { code: 0, success: true, message: "...", data: {...} }
|
||||
if (result && (result.success || result.code === 0)) {
|
||||
console.log('[上传文档到任务] 上传成功:', result.message);
|
||||
return { success: true, data: result.data };
|
||||
return { success: true, data: result.data || result };
|
||||
} else {
|
||||
console.error('[上传文档到任务] 上传失败:', result.detail || result.message);
|
||||
return { success: false, error: result.detail || result.message || '上传失败' };
|
||||
|
||||
@@ -76,7 +76,7 @@ export interface UserTaskApiResponse {
|
||||
items: UserTaskInfo[];
|
||||
}
|
||||
|
||||
// 任务文档接口类型定义(旧版,保留兼容)
|
||||
// 任务文档接口类型定义(任务详情页兼容结构)
|
||||
export interface TaskDocument {
|
||||
document_id: number;
|
||||
file_name: string;
|
||||
@@ -289,6 +289,156 @@ export interface ApiResponse<T> {
|
||||
status?: number;
|
||||
}
|
||||
|
||||
interface ResultEnvelope<T> {
|
||||
code?: number;
|
||||
msg?: string;
|
||||
data?: T;
|
||||
}
|
||||
|
||||
interface V3UserTaskItem {
|
||||
taskId: number;
|
||||
taskName: string;
|
||||
taskType: string;
|
||||
docTypeId?: number | null;
|
||||
docTypeCode?: string | null;
|
||||
status: string;
|
||||
progress?: number;
|
||||
totalDocuments?: number;
|
||||
completedDocuments?: number;
|
||||
createdAt?: string;
|
||||
}
|
||||
|
||||
interface V3UserTaskPage {
|
||||
total: number;
|
||||
page: number;
|
||||
pageSize: number;
|
||||
items: V3UserTaskItem[];
|
||||
}
|
||||
|
||||
interface V3TaskDocumentItem {
|
||||
documentId: number;
|
||||
name: string;
|
||||
documentNumber?: string | null;
|
||||
typeId?: number | null;
|
||||
processingStatus?: string | null;
|
||||
versionNo?: number;
|
||||
isLatestVersion?: boolean;
|
||||
auditStatus?: number;
|
||||
createdAt?: string;
|
||||
}
|
||||
|
||||
interface V3TaskDocumentPage {
|
||||
taskId: number;
|
||||
total: number;
|
||||
page: number;
|
||||
pageSize: number;
|
||||
items: V3TaskDocumentItem[];
|
||||
}
|
||||
|
||||
function unwrapResultEnvelope<T>(payload: unknown): T {
|
||||
if (payload && typeof payload === 'object' && 'data' in (payload as ResultEnvelope<T>)) {
|
||||
return ((payload as ResultEnvelope<T>).data ?? null) as T;
|
||||
}
|
||||
return payload as T;
|
||||
}
|
||||
|
||||
function mapProcessingStatus(status?: string | null): CrossReviewDocumentWithVersion['status'] {
|
||||
switch (status) {
|
||||
case 'processed':
|
||||
case 'Processed':
|
||||
return 'Processed';
|
||||
case 'failed':
|
||||
case 'Failed':
|
||||
return 'Failed';
|
||||
case 'cutting':
|
||||
case 'Cutting':
|
||||
return 'Cutting';
|
||||
case 'extracting':
|
||||
case 'Extractioning':
|
||||
return 'Extractioning';
|
||||
case 'evaluating':
|
||||
case 'Evaluationing':
|
||||
return 'Evaluationing';
|
||||
case 'waiting':
|
||||
case 'Waiting':
|
||||
default:
|
||||
return 'Waiting';
|
||||
}
|
||||
}
|
||||
|
||||
function mapV3TaskToUserTaskInfo(item: V3UserTaskItem): UserTaskInfo {
|
||||
return {
|
||||
task_id: item.taskId,
|
||||
task_name: item.taskName,
|
||||
task_status: item.status,
|
||||
doc_type: item.docTypeCode || undefined,
|
||||
task_created_at: item.createdAt,
|
||||
task_type: item.taskType,
|
||||
progress: item.progress,
|
||||
total_documents: item.totalDocuments
|
||||
};
|
||||
}
|
||||
|
||||
function mapV3DocumentToTaskDocument(item: V3TaskDocumentItem): TaskDocument {
|
||||
return {
|
||||
document_id: item.documentId,
|
||||
file_name: item.name || '',
|
||||
status: mapProcessingStatus(item.processingStatus),
|
||||
path: '',
|
||||
file_code: item.documentNumber || '',
|
||||
file_type_name: item.typeId ? `类型${item.typeId}` : '',
|
||||
file_type_id: item.typeId || 0,
|
||||
file_size: 0,
|
||||
upload_time: item.createdAt || '',
|
||||
created_at: item.createdAt || '',
|
||||
evaluations_status: 0,
|
||||
audit_status: item.auditStatus || 0,
|
||||
created_by_user_id: 0,
|
||||
issues: [],
|
||||
final_score: 0,
|
||||
score_summary: '',
|
||||
score_percent: null,
|
||||
pass_count: 0,
|
||||
warning_count: 0,
|
||||
fail_count: 0,
|
||||
manual_count: 0
|
||||
};
|
||||
}
|
||||
|
||||
function mapV3DocumentToVersionedDocument(item: V3TaskDocumentItem): CrossReviewDocumentWithVersion {
|
||||
const typeName = item.typeId ? `类型${item.typeId}` : '未知类型';
|
||||
return {
|
||||
id: item.documentId,
|
||||
name: item.name || '',
|
||||
path: '',
|
||||
version_number: item.versionNo || 1,
|
||||
created_at: item.createdAt || '',
|
||||
status: mapProcessingStatus(item.processingStatus),
|
||||
file_size: 0,
|
||||
document_number: item.documentNumber || null,
|
||||
type_id: item.typeId || 0,
|
||||
type_name: typeName,
|
||||
upload_time: item.createdAt || '',
|
||||
audit_status: (item.auditStatus || 0) as 0 | 1,
|
||||
total_evaluation_points: 0,
|
||||
pass_count: 0,
|
||||
warning_count: 0,
|
||||
error_count: 0,
|
||||
manual_count: 0,
|
||||
issue_count: 0,
|
||||
warning_messages: [],
|
||||
error_messages: [],
|
||||
issue_messages: [],
|
||||
manual_messages: [],
|
||||
final_score: 0,
|
||||
full_score: 100,
|
||||
score_summary: '',
|
||||
score_percent: 0,
|
||||
total_versions: 1,
|
||||
history_versions: []
|
||||
};
|
||||
}
|
||||
|
||||
// 任务列表查询参数
|
||||
export interface TaskListParams {
|
||||
page?: number;
|
||||
@@ -321,10 +471,7 @@ export interface TaskListResponse {
|
||||
*/
|
||||
export async function getCrossCheckingTasks(params: TaskListParams = {}, userInfo?: { user_id?: number; [key: string]: unknown }, jwtToken?: string): Promise<ApiResponse<TaskListResponse>> {
|
||||
try {
|
||||
// console.log('开始调用getCrossCheckingTasks,参数:', params);
|
||||
|
||||
// 调用用户任务API,获取当前用户参与的任务
|
||||
const userTasksResponse = await getUserTaskDocuments(params.page || 1, params.pageSize || 10, jwtToken);
|
||||
const userTasksResponse = await getUserTaskDocuments(params, jwtToken);
|
||||
|
||||
// console.log('getUserTaskDocuments响应:', JSON.stringify(userTasksResponse,null,2));
|
||||
|
||||
@@ -347,7 +494,7 @@ export async function getCrossCheckingTasks(params: TaskListParams = {}, userInf
|
||||
startDate: userTask.task_created_at ? new Date(userTask.task_created_at).toISOString().split('T')[0] : new Date().toISOString().split('T')[0],
|
||||
taskType: userTask.task_type, // 保持默认任务类型
|
||||
docType: userTask.doc_type || '未知类型', // 使用API返回的文档类型
|
||||
evaluationRegion: userTask.evaluation_region || [], // 保持默认评查地区
|
||||
evaluationRegion: userTask.evaluation_region || [],
|
||||
progress: userTask.progress || 0, // 使用API返回的进度
|
||||
status: userTask.task_status || 'pending', // 使用API返回的任务状态
|
||||
score: userTask.task_status === 'completed' ? 85 : 0, // 默认分数
|
||||
@@ -391,7 +538,7 @@ export async function getCrossCheckingTasks(params: TaskListParams = {}, userInf
|
||||
const lowerKeyword = keyword.toLowerCase();
|
||||
filteredTasks = filteredTasks.filter(task =>
|
||||
task.taskName.toLowerCase().includes(lowerKeyword) ||
|
||||
task.evaluationRegion.toLowerCase().includes(lowerKeyword)
|
||||
task.evaluationRegion.join(',').toLowerCase().includes(lowerKeyword)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -525,7 +672,7 @@ export async function getCrossCheckingStats(userInfo?: { user_id?: number; [key:
|
||||
console.log('开始调用getCrossCheckingStats');
|
||||
|
||||
// 获取用户任务数据来计算统计(默认获取第一页数据进行统计)
|
||||
const userTasksResponse = await getUserTaskDocuments(1, 100, jwtToken); // 获取前100个任务用于统计
|
||||
const userTasksResponse = await getUserTaskDocuments({ page: 1, pageSize: 100 }, jwtToken);
|
||||
|
||||
if (!userTasksResponse.success || !userTasksResponse.data) {
|
||||
console.error('获取用户任务失败:', userTasksResponse.error);
|
||||
@@ -568,25 +715,49 @@ export async function getCrossCheckingStats(userInfo?: { user_id?: number; [key:
|
||||
* @param jwtToken JWT token
|
||||
* @returns 用户任务列表
|
||||
*/
|
||||
export async function getUserTaskDocuments(page: number = 1, pageSize: number = 10, jwtToken?: string): Promise<ApiResponse<UserTaskApiResponse>> {
|
||||
export async function getUserTaskDocuments(params: TaskListParams = {}, jwtToken?: string): Promise<ApiResponse<UserTaskApiResponse>> {
|
||||
try {
|
||||
// 拼接绝对路径,去除多余斜杠
|
||||
const base = API_BASE_URL.endsWith('/') ? API_BASE_URL.slice(0, -1) : API_BASE_URL;
|
||||
const url = `${base}/admin/v2/cross_review/tasks/user_tasks`;
|
||||
const url = `${base}/api/v3/cross-review/tasks/query`;
|
||||
|
||||
const response = await axios.post(url, {
|
||||
page: page,
|
||||
page_size: pageSize
|
||||
}, {
|
||||
const page = params.page || 1;
|
||||
const pageSize = params.pageSize || 10;
|
||||
const requestBody: Record<string, unknown> = {
|
||||
page,
|
||||
pageSize
|
||||
};
|
||||
|
||||
if (params.keyword?.trim()) {
|
||||
requestBody.keyword = params.keyword.trim();
|
||||
}
|
||||
if (params.status && params.status !== 'all') {
|
||||
requestBody.status = params.status;
|
||||
}
|
||||
if (params.taskType && params.taskType !== 'all') {
|
||||
requestBody.taskType = params.taskType;
|
||||
}
|
||||
if (params.docType && params.docType !== 'all') {
|
||||
requestBody.docTypeCode = params.docType;
|
||||
}
|
||||
|
||||
const response = await axios.post<ResultEnvelope<V3UserTaskPage>>(url, requestBody, {
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': `Bearer ${jwtToken || ''}`
|
||||
}
|
||||
});
|
||||
|
||||
const pageData = unwrapResultEnvelope<V3UserTaskPage>(response.data);
|
||||
const items = Array.isArray(pageData?.items) ? pageData.items.map(mapV3TaskToUserTaskInfo) : [];
|
||||
|
||||
return {
|
||||
success: true,
|
||||
data: response.data
|
||||
data: {
|
||||
total: pageData?.total || 0,
|
||||
page: pageData?.page || page,
|
||||
page_size: pageData?.pageSize || pageSize,
|
||||
items
|
||||
}
|
||||
};
|
||||
} catch (error) {
|
||||
if (axios.isAxiosError(error)) {
|
||||
@@ -603,7 +774,7 @@ export async function getUserTaskDocuments(page: number = 1, pageSize: number =
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定任务的文档列表(旧版接口,保留兼容)
|
||||
* 获取指定任务的文档列表(兼容任务详情使用)
|
||||
* @param taskId 任务ID
|
||||
* @param page 页码
|
||||
* @param pageSize 每页大小
|
||||
@@ -612,24 +783,30 @@ export async function getUserTaskDocuments(page: number = 1, pageSize: number =
|
||||
*/
|
||||
export async function getTaskDocuments(taskId: number, page: number = 1, pageSize: number = 10, jwtToken?: string): Promise<ApiResponse<TaskDocumentApiResponse>> {
|
||||
try {
|
||||
// 拼接绝对路径,去除多余斜杠
|
||||
const base = API_BASE_URL.endsWith('/') ? API_BASE_URL.slice(0, -1) : API_BASE_URL;
|
||||
const url = `${base}/admin/v2/cross_review/tasks/${taskId}/documents`;
|
||||
// console.log('最终请求URL:', url);
|
||||
const url = `${base}/api/v3/cross-review/tasks/${taskId}/documents`;
|
||||
|
||||
const response = await axios.post(url, {
|
||||
page: page,
|
||||
page_size: pageSize
|
||||
}, {
|
||||
const response = await axios.get<ResultEnvelope<V3TaskDocumentPage>>(url, {
|
||||
params: {
|
||||
page,
|
||||
pageSize
|
||||
},
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': `Bearer ${jwtToken || ''}`
|
||||
}
|
||||
});
|
||||
|
||||
const pageData = unwrapResultEnvelope<V3TaskDocumentPage>(response.data);
|
||||
const items = Array.isArray(pageData?.items) ? pageData.items.map(mapV3DocumentToTaskDocument) : [];
|
||||
|
||||
return {
|
||||
success: true,
|
||||
data: response.data
|
||||
data: {
|
||||
total: pageData?.total || 0,
|
||||
page: pageData?.page || page,
|
||||
page_size: pageData?.pageSize || pageSize,
|
||||
items
|
||||
}
|
||||
};
|
||||
} catch (error) {
|
||||
if (axios.isAxiosError(error)) {
|
||||
@@ -646,9 +823,9 @@ export async function getTaskDocuments(taskId: number, page: number = 1, pageSiz
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取任务下文档列表(支持版本归纳)- 新版接口
|
||||
* 获取任务下文档列表(支持版本归纳)
|
||||
*
|
||||
* POST /api/v2/cross_review/tasks/{task_id}/documents
|
||||
* GET /api/v3/cross-review/tasks/{task_id}/documents
|
||||
*
|
||||
* 同一任务内同名且同类型的文档会被归纳为版本组,最新上传的为当前版本,其余为历史版本。
|
||||
*
|
||||
@@ -661,18 +838,16 @@ export async function getTaskDocumentsWithVersions(
|
||||
const { taskId, page = 1, pageSize = 10, keyword, jwtToken } = params;
|
||||
|
||||
try {
|
||||
// 拼接绝对路径,去除多余斜杠
|
||||
const base = API_BASE_URL.endsWith('/') ? API_BASE_URL.slice(0, -1) : API_BASE_URL;
|
||||
const url = `${base}/api/v2/cross_review/tasks/${taskId}/documents`;
|
||||
const url = `${base}/api/v3/cross-review/tasks/${taskId}/documents`;
|
||||
|
||||
// 构建请求体
|
||||
const queryParams: {
|
||||
page: number;
|
||||
page_size: number;
|
||||
pageSize: number;
|
||||
keyword?: string;
|
||||
} = {
|
||||
page,
|
||||
page_size: pageSize
|
||||
pageSize
|
||||
};
|
||||
|
||||
// 只有当 keyword 有值时才添加
|
||||
@@ -680,16 +855,25 @@ export async function getTaskDocumentsWithVersions(
|
||||
queryParams.keyword = keyword.trim();
|
||||
}
|
||||
|
||||
const response = await axios.get<CrossReviewDocumentListResponse>(url, {
|
||||
const response = await axios.get<ResultEnvelope<V3TaskDocumentPage>>(url, {
|
||||
params: queryParams,
|
||||
headers: {
|
||||
'Authorization': `Bearer ${jwtToken || ''}`
|
||||
}
|
||||
});
|
||||
|
||||
const pageData = unwrapResultEnvelope<V3TaskDocumentPage>(response.data);
|
||||
const documents = Array.isArray(pageData?.items) ? pageData.items.map(mapV3DocumentToVersionedDocument) : [];
|
||||
|
||||
return {
|
||||
success: true,
|
||||
data: response.data
|
||||
data: {
|
||||
total: pageData?.total || 0,
|
||||
page: pageData?.page || page,
|
||||
page_size: pageData?.pageSize || pageSize,
|
||||
total_pages: Math.ceil((pageData?.total || 0) / (pageData?.pageSize || pageSize || 1)),
|
||||
documents
|
||||
}
|
||||
};
|
||||
} catch (error) {
|
||||
if (axios.isAxiosError(error)) {
|
||||
@@ -1030,4 +1214,4 @@ export async function uploadCrossReviewDocumentTemplate(
|
||||
error: error instanceof Error ? error.message : '上传模板失败'
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user