Compare commits
No commits in common. "dd513444c55a4a0c18a38e35dd2e801dd4c016f4" and "12dbc9183022bfcff9d028cd4d33038bd64ef557" have entirely different histories.
dd513444c5
...
12dbc91830
|
@ -5,11 +5,8 @@ import EventBus, { CrudOperation } from "@server/utils/event-bus";
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class SystemLogService extends BaseService<Prisma.SystemLogDelegate> {
|
export class SystemLogService extends BaseService<Prisma.SystemLogDelegate> {
|
||||||
protected readonly prismaClient: any;
|
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
super(db, ObjectType.SYSTEM_LOG, false);
|
super(db, ObjectType.SYSTEM_LOG, false); // 不自动处理更新时间和删除时间
|
||||||
this.prismaClient = db;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async create(args: Prisma.SystemLogCreateArgs) {
|
async create(args: Prisma.SystemLogCreateArgs) {
|
||||||
|
@ -34,19 +31,20 @@ export class SystemLogService extends BaseService<Prisma.SystemLogDelegate> {
|
||||||
return super.findMany(args); // 放弃分页结构
|
return super.findMany(args); // 放弃分页结构
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 添加分页查询方法
|
||||||
async findManyWithPagination({ page = 1, pageSize = 20, where = {}, ...rest }: any) {
|
async findManyWithPagination({ page = 1, pageSize = 20, where = {}, ...rest }: any) {
|
||||||
const skip = (page - 1) * pageSize;
|
const skip = (page - 1) * pageSize;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const [items, total] = await Promise.all([
|
const [items, total] = await Promise.all([
|
||||||
this.prismaClient.systemLog.findMany({
|
this.delegate.findMany({
|
||||||
where,
|
where,
|
||||||
skip,
|
skip,
|
||||||
take: pageSize,
|
take: pageSize,
|
||||||
orderBy: { timestamp: 'desc' },
|
orderBy: { timestamp: 'desc' },
|
||||||
...rest
|
...rest
|
||||||
}),
|
}),
|
||||||
this.prismaClient.systemLog.count({ where })
|
this.delegate.count({ where })
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
@ -121,6 +119,7 @@ export class SystemLogService extends BaseService<Prisma.SystemLogDelegate> {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return { changes };
|
return { changes };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,10 +4,7 @@ import React, { useState, useEffect } from 'react';
|
||||||
|
|
||||||
// 创建一个全局变量来存储日志
|
// 创建一个全局变量来存储日志
|
||||||
let globalLogs: string[] = [];
|
let globalLogs: string[] = [];
|
||||||
const clearLogs = () => {
|
|
||||||
localStorage.removeItem('systemLogs');
|
|
||||||
setLogs([]);
|
|
||||||
};
|
|
||||||
// 添加日志的函数
|
// 添加日志的函数
|
||||||
export const addLog = (log: string) => {
|
export const addLog = (log: string) => {
|
||||||
const timestamp = new Date().toLocaleString();
|
const timestamp = new Date().toLocaleString();
|
||||||
|
@ -32,9 +29,6 @@ const SystemLogPage = () => {
|
||||||
return (
|
return (
|
||||||
<div className="max-w-4xl mx-auto p-6">
|
<div className="max-w-4xl mx-auto p-6">
|
||||||
<h1 className="text-2xl font-bold mb-6">系统日志</h1>
|
<h1 className="text-2xl font-bold mb-6">系统日志</h1>
|
||||||
<button onClick={clearLogs} className="mb-4 bg-red-500 text-white p-2 rounded">
|
|
||||||
清除日志
|
|
||||||
</button>
|
|
||||||
<div className="bg-white p-6 rounded-lg shadow">
|
<div className="bg-white p-6 rounded-lg shadow">
|
||||||
{logs.length === 0 ? (
|
{logs.length === 0 ? (
|
||||||
<p className="text-gray-500">暂无系统日志</p>
|
<p className="text-gray-500">暂无系统日志</p>
|
||||||
|
@ -53,7 +47,3 @@ const SystemLogPage = () => {
|
||||||
};
|
};
|
||||||
|
|
||||||
export default SystemLogPage;
|
export default SystemLogPage;
|
||||||
function setLogs(arg0: undefined[]) {
|
|
||||||
throw new Error('Function not implemented.');
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
|
@ -567,7 +567,7 @@ model SystemLog {
|
||||||
// 关联部门
|
// 关联部门
|
||||||
departmentId String? @map("department_id")
|
departmentId String? @map("department_id")
|
||||||
department Department? @relation(fields: [departmentId], references: [id])
|
department Department? @relation(fields: [departmentId], references: [id])
|
||||||
message String? @map("message") // 完整的日志文本内容
|
message String @map("message") // 完整的日志文本内容
|
||||||
// 优化索引
|
// 优化索引
|
||||||
@@index([timestamp])
|
@@index([timestamp])
|
||||||
@@index([level])
|
@@index([level])
|
||||||
|
|
Loading…
Reference in New Issue