add
This commit is contained in:
parent
9a1485661d
commit
0efb7787a7
|
@ -5,8 +5,11 @@ 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) {
|
||||||
|
@ -31,20 +34,19 @@ 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.delegate.findMany({
|
this.prismaClient.systemLog.findMany({
|
||||||
where,
|
where,
|
||||||
skip,
|
skip,
|
||||||
take: pageSize,
|
take: pageSize,
|
||||||
orderBy: { timestamp: 'desc' },
|
orderBy: { timestamp: 'desc' },
|
||||||
...rest
|
...rest
|
||||||
}),
|
}),
|
||||||
this.delegate.count({ where })
|
this.prismaClient.systemLog.count({ where })
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
@ -119,7 +121,6 @@ export class SystemLogService extends BaseService<Prisma.SystemLogDelegate> {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return { changes };
|
return { changes };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,10 @@ 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();
|
||||||
|
@ -29,6 +32,9 @@ 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>
|
||||||
|
@ -47,3 +53,7 @@ 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