修改系统概览中统计信息的显示逻辑

This commit is contained in:
PingChuan
2025-05-30 16:14:28 +08:00
parent 01cea56a6a
commit 202d64efd6
+22 -10
View File
@@ -1,3 +1,4 @@
import { log } from "node:console";
import { postgrestGet, type PostgrestParams } from "../postgrest-client"; import { postgrestGet, type PostgrestParams } from "../postgrest-client";
import dayjs from 'dayjs'; import dayjs from 'dayjs';
@@ -127,7 +128,7 @@ export async function getHomeData(): Promise<HomeStatistics> {
is_test_document: `eq.false` is_test_document: `eq.false`
} }
}; };
const todayPendingCount = await handleApiResponse<{count: number}[]>( const todayPendingCount = await handleApiResponse<{ count: number }[]>(
postgrestGet('documents', todayPendingParams), postgrestGet('documents', todayPendingParams),
'获取今日待审核文件数量失败', '获取今日待审核文件数量失败',
[] []
@@ -143,7 +144,7 @@ export async function getHomeData(): Promise<HomeStatistics> {
is_test_document: `eq.false` is_test_document: `eq.false`
} }
}; };
const thisMonthReviewedCount = await handleApiResponse<{count: number}[]>( const thisMonthReviewedCount = await handleApiResponse<{ count: number }[]>(
postgrestGet('documents', thisMonthReviewedParams), postgrestGet('documents', thisMonthReviewedParams),
'获取本月已审核文件数量失败', '获取本月已审核文件数量失败',
[] []
@@ -160,7 +161,7 @@ export async function getHomeData(): Promise<HomeStatistics> {
is_test_document: `eq.false` is_test_document: `eq.false`
} }
}; };
const lastMonthReviewedCount = await handleApiResponse<{count: number}[]>( const lastMonthReviewedCount = await handleApiResponse<{ count: number }[]>(
postgrestGet('documents', lastMonthReviewedParams), postgrestGet('documents', lastMonthReviewedParams),
'获取上月已审核文件数量失败', '获取上月已审核文件数量失败',
[] []
@@ -171,12 +172,13 @@ export async function getHomeData(): Promise<HomeStatistics> {
// 计算同比增长 // 计算同比增长
let reviewGrowthValue = 0; let reviewGrowthValue = 0;
let reviewGrowthIsUp = true; let reviewGrowthIsUp = true;
// console.log('lastMonthReviewed-------', lastMonthReviewed);
// console.log('monthlyReviewedFiles-------', monthlyReviewedFiles);
if (lastMonthReviewed > 0) { if (lastMonthReviewed > 0) {
const growthRate = ((monthlyReviewedFiles - lastMonthReviewed) / lastMonthReviewed) * 100; const growthRate = ((monthlyReviewedFiles - lastMonthReviewed) / lastMonthReviewed) * 100;
reviewGrowthValue = Math.abs(parseFloat(growthRate.toFixed(1))); reviewGrowthValue = Math.abs(parseFloat(growthRate.toFixed(1)));
reviewGrowthIsUp = growthRate >= 0; reviewGrowthIsUp = growthRate >= 0;
} else if (lastMonthReviewed == 0 && monthlyReviewedFiles > 0) {
reviewGrowthValue = 100;
reviewGrowthIsUp = true;
} }
// 3. 审核通过率 - 本月审核通过率 // 3. 审核通过率 - 本月审核通过率
@@ -188,7 +190,7 @@ export async function getHomeData(): Promise<HomeStatistics> {
is_test_document: `eq.false` is_test_document: `eq.false`
} }
}; };
const thisMonthTotalCount = await handleApiResponse<{count: number}[]>( const thisMonthTotalCount = await handleApiResponse<{ count: number }[]>(
postgrestGet('documents', thisMonthTotalParams), postgrestGet('documents', thisMonthTotalParams),
'获取本月审核通过数量失败', '获取本月审核通过数量失败',
[] []
@@ -210,7 +212,7 @@ export async function getHomeData(): Promise<HomeStatistics> {
is_test_document: `eq.false` is_test_document: `eq.false`
} }
}; };
const lastMonthTotalCount = await handleApiResponse<{count: number}[]>( const lastMonthTotalCount = await handleApiResponse<{ count: number }[]>(
postgrestGet('documents', lastMonthTotalParams), postgrestGet('documents', lastMonthTotalParams),
'获取上月审核通过数量失败', '获取上月审核通过数量失败',
[] []
@@ -223,16 +225,26 @@ export async function getHomeData(): Promise<HomeStatistics> {
? parseFloat(((lastMonthTotal / lastMonthReviewed) * 100).toFixed(1)) ? parseFloat(((lastMonthTotal / lastMonthReviewed) * 100).toFixed(1))
: 0; : 0;
console.log('上个月-------', lastMonthPassRate);
// 计算通过率同比增长 // 计算通过率同比增长
let passRateGrowthValue = 0; let passRateGrowthValue = 0;
let passRateGrowthIsUp = true; let passRateGrowthIsUp = true;
if (lastMonthPassRate > 0) { if (lastMonthPassRate > 0) {
const passRateGrowth = ((monthlyPassRate - lastMonthPassRate) / lastMonthPassRate) * 100; const passRateGrowth = ((monthlyPassRate - lastMonthPassRate) / lastMonthPassRate) * 100;
passRateGrowthValue = Math.abs(parseFloat(passRateGrowth.toFixed(1))); passRateGrowthValue = Math.abs(parseFloat(passRateGrowth.toFixed(1)));
passRateGrowthIsUp = passRateGrowth >= 0; passRateGrowthIsUp = passRateGrowth >= 0;
} else if (lastMonthPassRate == 0 && monthlyPassRate > 0) {
passRateGrowthValue = 100;
passRateGrowthIsUp = true;
} }
console.log('上月通过率-------', lastMonthPassRate);
console.log('本月通过率-------', monthlyPassRate);
// 4. 检查出的问题总数(从评估结果表中统计) // 4. 检查出的问题总数(从评估结果表中统计)
const thisMonthIssuesParams: PostgrestParams = { const thisMonthIssuesParams: PostgrestParams = {
select: 'count', select: 'count',
@@ -241,7 +253,7 @@ export async function getHomeData(): Promise<HomeStatistics> {
'evaluated_results->result': 'eq.false' // 使用->操作符访问JSONB字段 'evaluated_results->result': 'eq.false' // 使用->操作符访问JSONB字段
} }
}; };
const thisMonthIssuesResponse = await handleApiResponse<{count: number}[]>( const thisMonthIssuesResponse = await handleApiResponse<{ count: number }[]>(
postgrestGet('evaluation_results', thisMonthIssuesParams), postgrestGet('evaluation_results', thisMonthIssuesParams),
'获取本月问题数据失败', '获取本月问题数据失败',
[] []
@@ -257,7 +269,7 @@ export async function getHomeData(): Promise<HomeStatistics> {
'evaluated_results->result': 'eq.false' // 使用->操作符访问JSONB字段 'evaluated_results->result': 'eq.false' // 使用->操作符访问JSONB字段
} }
}; };
const lastMonthIssuesResponse = await handleApiResponse<{count: number}[]>( const lastMonthIssuesResponse = await handleApiResponse<{ count: number }[]>(
postgrestGet('evaluation_results', lastMonthIssuesParams), postgrestGet('evaluation_results', lastMonthIssuesParams),
'获取上月问题数据失败', '获取上月问题数据失败',
[] []
@@ -269,12 +281,12 @@ export async function getHomeData(): Promise<HomeStatistics> {
let issuesGrowthValue = 0; let issuesGrowthValue = 0;
let issuesGrowthIsUp = true; let issuesGrowthIsUp = true;
if (lastMonthIssuesCount > 0) { if (lastMonthIssuesCount > 0) {
const issuesGrowth = ((thisMonthIssuesCount - lastMonthIssuesCount) / lastMonthIssuesCount) * 100; const issuesGrowth = ((thisMonthIssuesCount - lastMonthIssuesCount) / lastMonthIssuesCount) * 100;
issuesGrowthValue = Math.abs(parseFloat(issuesGrowth.toFixed(1))); issuesGrowthValue = Math.abs(parseFloat(issuesGrowth.toFixed(1)));
issuesGrowthIsUp = issuesGrowth >= 0; issuesGrowthIsUp = issuesGrowth >= 0;
} }
// 返回统计结果 // 返回统计结果
return { return {
todayPendingFiles, todayPendingFiles,