测通完成评查,投票,意见列表,任务列表,任务关联文档列表的内容。剩余创建任务,提出意见的完善
This commit is contained in:
@@ -1,4 +1,24 @@
|
||||
// import { postgrestPost } from "../postgrest-client";
|
||||
import { postgrestGet, postgrestPut } from "../postgrest-client";
|
||||
|
||||
/**
|
||||
* 从不同格式的 API 响应中提取数据
|
||||
* @param responseData API 响应数据
|
||||
* @returns 提取后的数据或 null
|
||||
*/
|
||||
function extractApiData<T>(responseData: unknown): T | null {
|
||||
if (!responseData) return null;
|
||||
|
||||
// 格式1: { code: number, msg: string, data: T }
|
||||
if (typeof responseData === 'object' && responseData !== null &&
|
||||
'code' in responseData &&
|
||||
'data' in responseData &&
|
||||
(responseData as { data: unknown }).data) {
|
||||
return (responseData as { data: T }).data;
|
||||
}
|
||||
|
||||
// 格式2: 直接是数据对象
|
||||
return responseData as T;
|
||||
}
|
||||
|
||||
/**
|
||||
* 提出意见的请求参数接口
|
||||
@@ -39,21 +59,8 @@ export interface CrossCheckingOpinion {
|
||||
pending_voters: string[];
|
||||
can_vote: boolean;
|
||||
problem_message: string;
|
||||
// 兼容旧字段
|
||||
id?: string | number;
|
||||
evaluation_point_id?: string | number;
|
||||
document_id?: string | number;
|
||||
audit_point?: string;
|
||||
found_issue?: string;
|
||||
audit_opinion?: string;
|
||||
deduction_score?: number;
|
||||
status?: string;
|
||||
created_at?: string;
|
||||
updated_at?: string;
|
||||
is_vote?: boolean;
|
||||
voter_count?: number;
|
||||
proposer_name?: string;
|
||||
current_user_is_proposer?: boolean;
|
||||
proposer_id: number;
|
||||
created_at: string;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -74,6 +81,34 @@ async function safeGetJWT(jwtToken?: string): Promise<string> {
|
||||
return jwtToken || '';
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前登录用户是否是发起人
|
||||
* @param taskId 任务ID
|
||||
* @param userId 用户ID
|
||||
* @returns 是否是发起人
|
||||
*/
|
||||
export async function findIsProposer(taskId: string | number, userId: number | undefined): Promise<boolean> {
|
||||
// 通过postgrest的get请求去cross_examination_tasks表中进行查找assignee_id是否等于userId
|
||||
const response = await postgrestGet(`cross_examination_tasks`, {
|
||||
select: 'assigner_id',
|
||||
filter: {
|
||||
id: `eq.${taskId}`
|
||||
}
|
||||
});
|
||||
if (response.error) {
|
||||
console.error('获取任务数据失败:', response.error);
|
||||
return false;
|
||||
}
|
||||
const data = extractApiData<{assigner_id: number}[]>(response.data);
|
||||
// console.log('data', data);
|
||||
|
||||
if (data && data.length > 0) {
|
||||
return data[0].assigner_id === userId;
|
||||
}
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 提交交叉评查意见
|
||||
* @param opinionData 意见数据
|
||||
@@ -154,7 +189,7 @@ export async function getCrossCheckingOpinions(
|
||||
// 如果没传userId,默认用1
|
||||
const realUserId = userId ?? 1;
|
||||
// 实际后端API调用,拼接API_BASE_URL
|
||||
const response = await fetch(`${API_BASE_URL}/admin/cross_review/proposals/details`, {
|
||||
const response = await fetch(`${API_BASE_URL}/admin/cross_review/proposals/document`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
@@ -171,7 +206,7 @@ export async function getCrossCheckingOpinions(
|
||||
throw new Error('获取意见列表失败');
|
||||
}
|
||||
const data = await response.json();
|
||||
|
||||
console.log('最原始的返回data', data);
|
||||
// 处理新的数据结构,支持分页
|
||||
const responseData = data.data || data;
|
||||
const pagination = data.pagination;
|
||||
@@ -189,13 +224,8 @@ export async function getCrossCheckingOpinions(
|
||||
pending_voters?: string[];
|
||||
can_vote?: boolean;
|
||||
problem_message?: string;
|
||||
evaluation_point_id?: string | number;
|
||||
document_id?: string | number;
|
||||
status?: string;
|
||||
created_at?: string;
|
||||
updated_at?: string;
|
||||
is_vote?: boolean;
|
||||
current_user_is_proposer?: boolean;
|
||||
proposer_id: number;
|
||||
created_at: string;
|
||||
}
|
||||
|
||||
// 适配后端返回结构,使用新字段
|
||||
@@ -211,21 +241,8 @@ export async function getCrossCheckingOpinions(
|
||||
pending_voters: item.pending_voters || [],
|
||||
can_vote: item.can_vote ?? false,
|
||||
problem_message: item.problem_message || '',
|
||||
// 兼容旧字段
|
||||
id: item.proposal_id,
|
||||
evaluation_point_id: item.evaluation_point_id,
|
||||
document_id: item.document_id || documentId,
|
||||
audit_point: item.evaluation_point_name,
|
||||
found_issue: item.problem_message || '',
|
||||
audit_opinion: item.reason || '',
|
||||
deduction_score: item.proposed_score,
|
||||
status: item.status || 'pending',
|
||||
created_at: item.created_at || '',
|
||||
updated_at: item.updated_at || '',
|
||||
is_vote: item.is_vote || false,
|
||||
voter_count: (item.agree_voters?.length || 0) + (item.disagree_voters?.length || 0),
|
||||
proposer_name: item.proposer,
|
||||
current_user_is_proposer: item.current_user_is_proposer || false
|
||||
proposer_id: item.proposer_id,
|
||||
created_at: item.created_at
|
||||
})) : [];
|
||||
|
||||
return {
|
||||
@@ -271,7 +288,8 @@ export interface OpinionActionRequest {
|
||||
*/
|
||||
export async function performOpinionAction(
|
||||
actionData: OpinionActionRequest,
|
||||
jwtToken?: string
|
||||
jwtToken?: string,
|
||||
userInfo?: { user_id: number }
|
||||
): Promise<ApiResponse<{ success: boolean; message: string }>> {
|
||||
try {
|
||||
const token = await safeGetJWT(jwtToken);
|
||||
@@ -284,23 +302,23 @@ export async function performOpinionAction(
|
||||
case 'agree':
|
||||
message = '已赞同该意见';
|
||||
endpoint = `${API_BASE_URL}/admin/cross_review/proposals/${actionData.opinionId}/votes`;
|
||||
requestBody = { vote_type: 'agree' };
|
||||
requestBody = { vote_type: 'agree', voter_id: userInfo?.user_id };
|
||||
break;
|
||||
case 'disagree':
|
||||
message = '已反对该意见';
|
||||
endpoint = `${API_BASE_URL}/admin/cross_review/proposals/${actionData.opinionId}/votes`;
|
||||
requestBody = { vote_type: 'disagree' };
|
||||
requestBody = { vote_type: 'disagree', voter_id: userInfo?.user_id };
|
||||
break;
|
||||
case 'withdraw_vote':
|
||||
message = '已撤销投票';
|
||||
// 撤销投票的接口,根据实际API调整
|
||||
endpoint = `${API_BASE_URL}/admin/cross_review/proposals/${actionData.opinionId}/votes/withdraw`;
|
||||
requestBody = {};
|
||||
endpoint = `${API_BASE_URL}/admin/cross_review/proposals/${actionData.opinionId}/votes`;
|
||||
requestBody = { vote_type: 'cancel', voter_id: userInfo?.user_id };
|
||||
break;
|
||||
case 'withdraw_opinion':
|
||||
message = '已撤销意见';
|
||||
// 撤销意见的接口,根据实际API调整
|
||||
endpoint = `${API_BASE_URL}/admin/cross_review/proposals/${actionData.opinionId}/withdraw`;
|
||||
endpoint = `${API_BASE_URL}/admin/cross_review/proposals/${actionData.opinionId}`;
|
||||
requestBody = {};
|
||||
break;
|
||||
default:
|
||||
@@ -308,7 +326,7 @@ export async function performOpinionAction(
|
||||
}
|
||||
|
||||
const response = await fetch(endpoint, {
|
||||
method: 'POST',
|
||||
method: actionData.action === 'withdraw_opinion' ? 'DELETE' : 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': `Bearer ${token}`
|
||||
@@ -318,6 +336,8 @@ export async function performOpinionAction(
|
||||
|
||||
const data = await response.json();
|
||||
|
||||
console.log('返回的意见列表数据',data);
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(data.message || data.error || '操作失败');
|
||||
}
|
||||
@@ -336,3 +356,92 @@ export async function performOpinionAction(
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 完成评查
|
||||
* @param documentId 文档ID
|
||||
* @returns 完成评查结果
|
||||
*/
|
||||
export async function confirmReviewResults(
|
||||
documentId: string | number
|
||||
): Promise<{data?: unknown, error?: string, status?: number}> {
|
||||
try {
|
||||
// 通过postgrest的post请求去documents表中进行查找id等于documentId的数据,更新documents表的audit_status为1
|
||||
const response = await postgrestPut(`documents`, {
|
||||
audit_status: 1
|
||||
}, {
|
||||
id: documentId
|
||||
});
|
||||
if(response.error) {
|
||||
return {
|
||||
error: response.error,
|
||||
status: response.status
|
||||
};
|
||||
}
|
||||
const extractedData = extractApiData<unknown>(response.data);
|
||||
if(!extractedData) {
|
||||
return {
|
||||
error: '更新文档状态失败',
|
||||
status: 500
|
||||
};
|
||||
}
|
||||
return {
|
||||
data: extractedData
|
||||
};
|
||||
|
||||
} catch (error) {
|
||||
console.error('完成评查失败:', error);
|
||||
return {
|
||||
error: error instanceof Error ? error.message : '完成评查失败',
|
||||
status: 500
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 点击完成评查按钮后,调用接口,检查文档下提案是否存在未投票用户
|
||||
export async function checkProposalVotes(
|
||||
documentId: string | number,
|
||||
jwtToken?: string
|
||||
): Promise<{data?: unknown, error?: string, status?: number}> {
|
||||
try {
|
||||
// 获取JWT token
|
||||
const token = await safeGetJWT(jwtToken);
|
||||
|
||||
const requestData = {
|
||||
document_id: documentId
|
||||
};
|
||||
|
||||
const response = await fetch(`${API_BASE_URL}/admin/cross_review/proposals/document/check_pending_votes`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': `Bearer ${token}`
|
||||
},
|
||||
body: JSON.stringify(requestData)
|
||||
});
|
||||
|
||||
const data = await response.json();
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(data.message || '检查失败');
|
||||
}
|
||||
console.log("检查投票数据",data);
|
||||
|
||||
return {
|
||||
data: {
|
||||
success: true,
|
||||
message: '检查成功',
|
||||
data: data
|
||||
}
|
||||
};
|
||||
} catch (error) {
|
||||
console.error('检查失败:', error);
|
||||
return {
|
||||
error: error instanceof Error ? error.message : '检查失败',
|
||||
status: 500
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -104,7 +104,8 @@ export async function uploadCrossCheckingDocument(
|
||||
remark: string = '',
|
||||
isTestDocument: boolean = false,
|
||||
documentId: number | null = null,
|
||||
isReupload: boolean = false
|
||||
isReupload: boolean = false,
|
||||
token: string | null = null
|
||||
): Promise<{data: CrossCheckingFileUploadResponse; error?: never} | {data?: never; error: string; status?: number}> {
|
||||
try {
|
||||
console.log('【交叉评查上传】开始上传文档:', { fileName, fileSize: binaryData.byteLength, typeId });
|
||||
@@ -140,11 +141,17 @@ export async function uploadCrossCheckingDocument(
|
||||
// 发送请求
|
||||
try {
|
||||
console.log('【交叉评查上传】开始fetch请求...');
|
||||
const headers: HeadersInit = {
|
||||
'X-File-Name': encodeURIComponent(fileName),
|
||||
};
|
||||
|
||||
if (token) {
|
||||
headers['Authorization'] = `Bearer ${token}`;
|
||||
}
|
||||
|
||||
const response = await fetch(uploadUrl, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'X-File-Name': encodeURIComponent(fileName)
|
||||
},
|
||||
headers,
|
||||
body: formData
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user