75 lines
1.8 KiB
Dart
75 lines
1.8 KiB
Dart
|
|
/// 系统操作日志模型。
|
||
|
|
///
|
||
|
|
/// 对应后端 /sys/log/* 接口的日志实体。
|
||
|
|
class SysLog {
|
||
|
|
const SysLog({
|
||
|
|
required this.id,
|
||
|
|
required this.username,
|
||
|
|
required this.operation,
|
||
|
|
required this.method,
|
||
|
|
required this.params,
|
||
|
|
required this.time,
|
||
|
|
required this.ip,
|
||
|
|
required this.createDate,
|
||
|
|
});
|
||
|
|
|
||
|
|
/// 日志 ID。
|
||
|
|
final String id;
|
||
|
|
|
||
|
|
/// 操作用户名。
|
||
|
|
final String username;
|
||
|
|
|
||
|
|
/// 操作描述。
|
||
|
|
final String operation;
|
||
|
|
|
||
|
|
/// 请求方法(类名#方法名)。
|
||
|
|
final String method;
|
||
|
|
|
||
|
|
/// 请求参数。
|
||
|
|
final String params;
|
||
|
|
|
||
|
|
/// 执行时长(毫秒)。
|
||
|
|
final int time;
|
||
|
|
|
||
|
|
/// 操作 IP。
|
||
|
|
final String ip;
|
||
|
|
|
||
|
|
/// 创建时间。
|
||
|
|
final DateTime? createDate;
|
||
|
|
|
||
|
|
factory SysLog.fromJson(Map<String, dynamic> json) {
|
||
|
|
return SysLog(
|
||
|
|
id: json['id']?.toString() ?? '',
|
||
|
|
username: json['username']?.toString() ?? '',
|
||
|
|
operation: json['operation']?.toString() ?? '',
|
||
|
|
method: json['method']?.toString() ?? '',
|
||
|
|
params: json['params']?.toString() ?? '',
|
||
|
|
time: int.tryParse(json['time']?.toString() ?? '0') ?? 0,
|
||
|
|
ip: json['ip']?.toString() ?? '',
|
||
|
|
createDate: _parseDateTime(json['createDate']),
|
||
|
|
);
|
||
|
|
}
|
||
|
|
|
||
|
|
/// 兼容 `yyyy-MM-dd HH:mm:ss` 与 ISO 8601 两种时间格式。
|
||
|
|
static DateTime? _parseDateTime(dynamic value) {
|
||
|
|
if (value == null) return null;
|
||
|
|
final text = value.toString().trim();
|
||
|
|
if (text.isEmpty) return null;
|
||
|
|
return DateTime.tryParse(text) ??
|
||
|
|
DateTime.tryParse(text.replaceFirst(' ', 'T'));
|
||
|
|
}
|
||
|
|
|
||
|
|
Map<String, dynamic> toJson() {
|
||
|
|
return {
|
||
|
|
'id': id,
|
||
|
|
'username': username,
|
||
|
|
'operation': operation,
|
||
|
|
'method': method,
|
||
|
|
'params': params,
|
||
|
|
'time': time,
|
||
|
|
'ip': ip,
|
||
|
|
'createDate': createDate?.toIso8601String(),
|
||
|
|
};
|
||
|
|
}
|
||
|
|
}
|