添加nginx相关配置,首页系统概览添加用户id查询
This commit is contained in:
+112
-113
@@ -1,4 +1,4 @@
|
||||
import { postgrestGet, type PostgrestParams } from "../postgrest-client";
|
||||
import { postgrestGet, postgrestPost, type PostgrestParams } from "../postgrest-client";
|
||||
import dayjs from 'dayjs';
|
||||
|
||||
/**
|
||||
@@ -96,7 +96,7 @@ function buildTypeFilter(reviewType: string | null): string {
|
||||
* @param reviewType 从客户端传入的 reviewType 值
|
||||
* @returns 主页数据
|
||||
*/
|
||||
export async function getHomeData(reviewType?: string | null): Promise<HomeStatistics> {
|
||||
export async function getHomeData(reviewType?: string | null,userId?: string | number): Promise<HomeStatistics> {
|
||||
try {
|
||||
// 获取当前日期和时间相关值
|
||||
const startOfToday = dayjs().startOf('day').format('YYYY-MM-DD HH:mm:ss');
|
||||
@@ -105,7 +105,8 @@ export async function getHomeData(reviewType?: string | null): Promise<HomeStati
|
||||
const startOfLastMonth = dayjs().subtract(1, 'month').startOf('month').format('YYYY-MM-DD HH:mm:ss');
|
||||
const endOfLastMonth = dayjs().subtract(1, 'month').endOf('month').format('YYYY-MM-DD HH:mm:ss');
|
||||
|
||||
// console.log('传入的 reviewType', reviewType);
|
||||
console.log('传入的 reviewType', reviewType);
|
||||
console.log('传入的 userId', userId);
|
||||
|
||||
// 基于 reviewType 构建类型过滤条件
|
||||
const typeFilter = buildTypeFilter(reviewType || null);
|
||||
@@ -146,7 +147,8 @@ export async function getHomeData(reviewType?: string | null): Promise<HomeStati
|
||||
filter: {
|
||||
or: `(audit_status.eq.0,audit_status.eq.2,audit_status.is.null)`,
|
||||
created_at: `gte.${startOfToday}`,
|
||||
is_test_document: `eq.false`
|
||||
is_test_document: `eq.false`,
|
||||
user_id: `eq.${userId}`
|
||||
}
|
||||
};
|
||||
|
||||
@@ -180,7 +182,8 @@ export async function getHomeData(reviewType?: string | null): Promise<HomeStati
|
||||
filter: {
|
||||
and: `(audit_status.neq.0,audit_status.neq.2)`,
|
||||
updated_at: `gte.${startOfThisMonth}`,
|
||||
is_test_document: `eq.false`
|
||||
is_test_document: `eq.false`,
|
||||
user_id: `eq.${userId}`
|
||||
}
|
||||
};
|
||||
|
||||
@@ -211,7 +214,8 @@ export async function getHomeData(reviewType?: string | null): Promise<HomeStati
|
||||
filter: {
|
||||
or: `(audit_status.eq.1,audit_status.eq.-1)`,
|
||||
and: `(updated_at.gte.${startOfLastMonth},updated_at.lte.${endOfLastMonth})`,
|
||||
is_test_document: `eq.false`
|
||||
is_test_document: `eq.false`,
|
||||
user_id: `eq.${userId}`
|
||||
}
|
||||
};
|
||||
|
||||
@@ -258,7 +262,8 @@ export async function getHomeData(reviewType?: string | null): Promise<HomeStati
|
||||
filter: {
|
||||
audit_status: `eq.1`,
|
||||
created_at: `gte.${startOfThisMonth}`,
|
||||
is_test_document: `eq.false`
|
||||
is_test_document: `eq.false`,
|
||||
user_id: `eq.${userId}`
|
||||
}
|
||||
};
|
||||
|
||||
@@ -294,7 +299,8 @@ export async function getHomeData(reviewType?: string | null): Promise<HomeStati
|
||||
filter: {
|
||||
audit_status: `eq.1`,
|
||||
and: `(updated_at.gte.${startOfLastMonth},updated_at.lte.${endOfLastMonth})`,
|
||||
is_test_document: `eq.false`
|
||||
is_test_document: `eq.false`,
|
||||
user_id: `eq.${userId}`
|
||||
}
|
||||
};
|
||||
|
||||
@@ -352,15 +358,18 @@ export async function getHomeData(reviewType?: string | null): Promise<HomeStati
|
||||
// 根据 reviewType 设置要查询的文档类型
|
||||
if (reviewType === 'contract') {
|
||||
// 合同类型 - 直接查询类型 1
|
||||
const typeToQuery = 1;
|
||||
const typeToQuery = [1];
|
||||
|
||||
// 调用数据库函数获取本月指定类型的问题数量
|
||||
|
||||
const thisMonthIssuesResponse = await handleApiResponse<{ count: number }[]>(
|
||||
postgrestGet(`rpc/count_evaluation_results_by_type?type_val=${typeToQuery}&start_time=${startOfThisMonth}&end_time=${endOfThisMonth}`, {
|
||||
select: '*',
|
||||
filter: {}
|
||||
postgrestPost('rpc/count_evaluation_results_by_type', {
|
||||
start_time: startOfThisMonth,
|
||||
end_time: endOfThisMonth,
|
||||
type_val: typeToQuery,
|
||||
userid: parseInt(userId as string)
|
||||
}),
|
||||
'获取本月问题数据失败',
|
||||
'获取合同本月问题数据失败',
|
||||
[]
|
||||
);
|
||||
|
||||
@@ -369,9 +378,11 @@ export async function getHomeData(reviewType?: string | null): Promise<HomeStati
|
||||
|
||||
// 调用数据库函数获取上月指定类型的问题数量
|
||||
const lastMonthIssuesResponse = await handleApiResponse<{ count: number }[]>(
|
||||
postgrestGet(`rpc/count_evaluation_results_by_type?type_val=${typeToQuery}&start_time=${startOfLastMonth}&end_time=${endOfLastMonth}`, {
|
||||
select: '*',
|
||||
filter: {}
|
||||
postgrestPost('rpc/count_evaluation_results_by_type', {
|
||||
start_time: startOfLastMonth,
|
||||
end_time: endOfLastMonth,
|
||||
type_val: typeToQuery,
|
||||
userid: parseInt(userId as string)
|
||||
}),
|
||||
'获取上月问题数据失败',
|
||||
[]
|
||||
@@ -382,120 +393,108 @@ export async function getHomeData(reviewType?: string | null): Promise<HomeStati
|
||||
|
||||
} else if (reviewType === 'record') {
|
||||
// 记录类型 - 需要查询类型 2 和类型 3,并合并结果
|
||||
const typeToQuery = [2,3];
|
||||
|
||||
// 查询类型 2 的本月问题数量
|
||||
const thisMonthType2Response = await handleApiResponse<{ count: number }[]>(
|
||||
postgrestGet(`rpc/count_evaluation_results_by_type?type_val=2&start_time=${startOfThisMonth}&end_time=${endOfThisMonth}`, {
|
||||
select: '*',
|
||||
filter: {}
|
||||
postgrestPost('rpc/count_evaluation_results_by_type', {
|
||||
start_time: startOfThisMonth,
|
||||
end_time: endOfThisMonth,
|
||||
type_val: typeToQuery,
|
||||
userid: parseInt(userId as string)
|
||||
}),
|
||||
'获取本月类型2问题数据失败',
|
||||
'获取本月许可卷宗类型2问题数据失败',
|
||||
[]
|
||||
);
|
||||
|
||||
// 查询类型 3 的本月问题数量
|
||||
const thisMonthType3Response = await handleApiResponse<{ count: number }[]>(
|
||||
postgrestGet(`rpc/count_evaluation_results_by_type?type_val=3&start_time=${startOfThisMonth}&end_time=${endOfThisMonth}`, {
|
||||
select: '*',
|
||||
filter: {}
|
||||
}),
|
||||
'获取本月类型3问题数据失败',
|
||||
[]
|
||||
);
|
||||
|
||||
// 合并本月两种类型的问题数量
|
||||
// 本月两种类型的问题数量
|
||||
const thisMonthType2Count = thisMonthType2Response[0]?.count || 0;
|
||||
const thisMonthType3Count = thisMonthType3Response[0]?.count || 0;
|
||||
thisMonthIssuesCount = thisMonthType2Count + thisMonthType3Count;
|
||||
thisMonthIssuesCount = thisMonthType2Count
|
||||
|
||||
// 查询类型 2 的上月问题数量
|
||||
// 上月两种类型的问题数量
|
||||
const lastMonthType2Response = await handleApiResponse<{ count: number }[]>(
|
||||
postgrestGet(`rpc/count_evaluation_results_by_type?type_val=2&start_time=${startOfLastMonth}&end_time=${endOfLastMonth}`, {
|
||||
select: '*',
|
||||
filter: {}
|
||||
postgrestPost('rpc/count_evaluation_results_by_type', {
|
||||
start_time: startOfLastMonth,
|
||||
end_time: endOfLastMonth,
|
||||
type_val: typeToQuery,
|
||||
userid: parseInt(userId as string)
|
||||
}),
|
||||
'获取上月类型2问题数据失败',
|
||||
'获取上月许可卷宗类型2问题数据失败',
|
||||
[]
|
||||
);
|
||||
|
||||
// 查询类型 3 的上月问题数量
|
||||
const lastMonthType3Response = await handleApiResponse<{ count: number }[]>(
|
||||
postgrestGet(`rpc/count_evaluation_results_by_type?type_val=3&start_time=${startOfLastMonth}&end_time=${endOfLastMonth}`, {
|
||||
select: '*',
|
||||
filter: {}
|
||||
}),
|
||||
'获取上月类型3问题数据失败',
|
||||
[]
|
||||
);
|
||||
|
||||
|
||||
// 合并上月两种类型的问题数量
|
||||
// 上月两种类型的问题数量
|
||||
const lastMonthType2Count = lastMonthType2Response[0]?.count || 0;
|
||||
const lastMonthType3Count = lastMonthType3Response[0]?.count || 0;
|
||||
lastMonthIssuesCount = lastMonthType2Count + lastMonthType3Count;
|
||||
lastMonthIssuesCount = lastMonthType2Count
|
||||
|
||||
} else {
|
||||
// 如果没有指定类型,则使用原来的查询方式获取所有类型的问题数量
|
||||
const thisMonthIssuesParams: PostgrestParams = {
|
||||
select: 'count',
|
||||
filter: {
|
||||
and: `(created_at.gte.${startOfThisMonth},created_at.lte.${endOfThisMonth})`,
|
||||
'evaluated_results->result': 'eq.false' // 使用->操作符访问JSONB字段
|
||||
}
|
||||
};
|
||||
|
||||
// 添加类型过滤条件
|
||||
if (typeFilter) {
|
||||
if (typeFilter.startsWith('(')) {
|
||||
thisMonthIssuesParams.or = typeFilter;
|
||||
} else {
|
||||
const [field, op, value] = typeFilter.split('.');
|
||||
if (!thisMonthIssuesParams.filter) {
|
||||
thisMonthIssuesParams.filter = {};
|
||||
}
|
||||
thisMonthIssuesParams.filter[field] = `${op}.${value}`;
|
||||
}
|
||||
}
|
||||
|
||||
const thisMonthIssuesResponse = await handleApiResponse<{ count: number }[]>(
|
||||
postgrestGet('evaluation_results', thisMonthIssuesParams),
|
||||
'获取本月问题数据失败',
|
||||
[]
|
||||
);
|
||||
|
||||
// 本月问题数量
|
||||
thisMonthIssuesCount = thisMonthIssuesResponse[0]?.count || 0;
|
||||
|
||||
// 上月问题数量
|
||||
const lastMonthIssuesParams: PostgrestParams = {
|
||||
select: 'count',
|
||||
filter: {
|
||||
and: `(created_at.gte.${startOfLastMonth},created_at.lte.${endOfLastMonth})`,
|
||||
'evaluated_results->result': 'eq.false' // 使用->操作符访问JSONB字段
|
||||
}
|
||||
};
|
||||
|
||||
// 添加类型过滤条件
|
||||
if (typeFilter) {
|
||||
if (typeFilter.startsWith('(')) {
|
||||
lastMonthIssuesParams.or = typeFilter;
|
||||
} else {
|
||||
const [field, op, value] = typeFilter.split('.');
|
||||
if (!lastMonthIssuesParams.filter) {
|
||||
lastMonthIssuesParams.filter = {};
|
||||
}
|
||||
lastMonthIssuesParams.filter[field] = `${op}.${value}`;
|
||||
}
|
||||
}
|
||||
|
||||
const lastMonthIssuesResponse = await handleApiResponse<{ count: number }[]>(
|
||||
postgrestGet('evaluation_results', lastMonthIssuesParams),
|
||||
'获取上月问题数据失败',
|
||||
[]
|
||||
);
|
||||
|
||||
// 上月问题数量
|
||||
lastMonthIssuesCount = lastMonthIssuesResponse[0]?.count || 0;
|
||||
}
|
||||
// 暂时不会存在没有指定类型得情况,暂不实现。
|
||||
// else {
|
||||
// // 如果没有指定类型,则使用原来的查询方式获取所有类型的问题数量
|
||||
// const thisMonthIssuesParams: PostgrestParams = {
|
||||
// select: 'count',
|
||||
// filter: {
|
||||
// and: `(created_at.gte.${startOfThisMonth},created_at.lte.${endOfThisMonth})`,
|
||||
// 'evaluated_results->result': 'eq.false',
|
||||
// user_id: `eq.${userId}`
|
||||
// }
|
||||
// };
|
||||
|
||||
// // 添加类型过滤条件
|
||||
// if (typeFilter) {
|
||||
// if (typeFilter.startsWith('(')) {
|
||||
// thisMonthIssuesParams.or = typeFilter;
|
||||
// } else {
|
||||
// const [field, op, value] = typeFilter.split('.');
|
||||
// if (!thisMonthIssuesParams.filter) {
|
||||
// thisMonthIssuesParams.filter = {};
|
||||
// }
|
||||
// thisMonthIssuesParams.filter[field] = `${op}.${value}`;
|
||||
// }
|
||||
// }
|
||||
|
||||
// const thisMonthIssuesResponse = await handleApiResponse<{ count: number }[]>(
|
||||
// postgrestGet('evaluation_results', thisMonthIssuesParams),
|
||||
// '获取本月问题数据失败',
|
||||
// []
|
||||
// );
|
||||
|
||||
// // 本月问题数量
|
||||
// thisMonthIssuesCount = thisMonthIssuesResponse[0]?.count || 0;
|
||||
|
||||
// // 上月问题数量
|
||||
// const lastMonthIssuesParams: PostgrestParams = {
|
||||
// select: 'count',
|
||||
// filter: {
|
||||
// and: `(created_at.gte.${startOfLastMonth},created_at.lte.${endOfLastMonth})`,
|
||||
// 'evaluated_results->result': 'eq.false',
|
||||
// user_id: `eq.${userId}`
|
||||
// }
|
||||
// };
|
||||
|
||||
// // 添加类型过滤条件
|
||||
// if (typeFilter) {
|
||||
// if (typeFilter.startsWith('(')) {
|
||||
// lastMonthIssuesParams.or = typeFilter;
|
||||
// } else {
|
||||
// const [field, op, value] = typeFilter.split('.');
|
||||
// if (!lastMonthIssuesParams.filter) {
|
||||
// lastMonthIssuesParams.filter = {};
|
||||
// }
|
||||
// lastMonthIssuesParams.filter[field] = `${op}.${value}`;
|
||||
// }
|
||||
// }
|
||||
|
||||
// const lastMonthIssuesResponse = await handleApiResponse<{ count: number }[]>(
|
||||
// postgrestGet('evaluation_results', lastMonthIssuesParams),
|
||||
// '获取上月问题数据失败',
|
||||
// []
|
||||
// );
|
||||
|
||||
// // 上月问题数量
|
||||
// lastMonthIssuesCount = lastMonthIssuesResponse[0]?.count || 0;
|
||||
// }
|
||||
|
||||
// 计算问题数量同比增长
|
||||
let issuesGrowthValue = 0;
|
||||
|
||||
Reference in New Issue
Block a user