签入脚本
This commit is contained in:
@@ -0,0 +1,109 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/gogf/gf/v2/database/gdb"
|
||||
|
||||
"easygoadmin/api/v1"
|
||||
"easygoadmin/internal/dao"
|
||||
"easygoadmin/internal/service"
|
||||
)
|
||||
|
||||
// ============================== 登录日志业务实现 ==============================
|
||||
|
||||
// sLoginLog 登录日志业务实现
|
||||
// 实现 service.ILoginLog 接口,承载登录日志模块的业务逻辑
|
||||
type sLoginLog struct{}
|
||||
|
||||
// loginLogSerializeMaps 枚举字段到字典编码的映射
|
||||
// {field}Text 由 dict_item 解析,字典管理页可修改文案
|
||||
var loginLogSerializeMaps = map[string]string{
|
||||
"log_type": "login_log_log_type",
|
||||
"source": "login_log_source",
|
||||
"status": "login_log_status",
|
||||
}
|
||||
|
||||
// loginLogSpec 登录日志模块声明
|
||||
var loginLogSpec = ModuleSpec[v1.LoginLogItem, v1.LoginLogItem, v1.LoginLogDetailRes]{
|
||||
Model: dao.LoginLog.Ctx,
|
||||
LikeFields: []string{"username"},
|
||||
EqFields: []string{"log_type", "status"},
|
||||
OrderBy: "id DESC",
|
||||
SerializeMaps: loginLogSerializeMaps,
|
||||
}
|
||||
|
||||
func init() {
|
||||
service.RegisterLoginLog(&sLoginLog{})
|
||||
}
|
||||
|
||||
// Page 登录日志分页
|
||||
// 按查询条件分页返回登录日志列表
|
||||
func (s *sLoginLog) Page(ctx context.Context, req *v1.LoginLogPageReq) (res *v1.LoginLogPageRes, err error) {
|
||||
list, total, err := loginLogSpec.Page(ctx, req, req.GetPageNo(), req.GetPageSize())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return v1.NewPageData(req.GetPageNo(), req.GetPageSize(), total, derefSlice(list)), nil
|
||||
}
|
||||
|
||||
// List 登录日志全量列表
|
||||
// 按关键词、类型、状态等条件返回登录日志列表
|
||||
func (s *sLoginLog) List(ctx context.Context, req *v1.LoginLogListReq) (res v1.LoginLogListRes, err error) {
|
||||
list, err := loginLogSpec.List(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return derefSlice(list), nil
|
||||
}
|
||||
|
||||
// Detail 登录日志详情
|
||||
// 按日志ID查询详情
|
||||
func (s *sLoginLog) Detail(ctx context.Context, req *v1.LoginLogDetailReq) (res *v1.LoginLogDetailRes, err error) {
|
||||
return loginLogSpec.Detail(ctx, req.Id, req)
|
||||
}
|
||||
|
||||
// Delete 删除登录日志
|
||||
// 按日志ID删除单条记录
|
||||
func (s *sLoginLog) Delete(ctx context.Context, req *v1.LoginLogDeleteReq) (res *v1.LoginLogDeleteRes, err error) {
|
||||
if err = loginLogSpec.Delete(ctx, req.Id); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &v1.LoginLogDeleteRes{}, nil
|
||||
}
|
||||
|
||||
// BatchDelete 批量删除登录日志
|
||||
// 按日志ID列表批量删除记录
|
||||
func (s *sLoginLog) BatchDelete(ctx context.Context, req *v1.LoginLogBatchDeleteReq) (res *v1.LoginLogBatchDeleteRes, err error) {
|
||||
if err = loginLogSpec.BatchDelete(ctx, req.Ids); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &v1.LoginLogBatchDeleteRes{}, nil
|
||||
}
|
||||
|
||||
// toItem 数据库记录转换为登录日志行数据
|
||||
// 枚举字段同步补全对应文本
|
||||
func (s *sLoginLog) toItem(ctx context.Context, r gdb.Record) v1.LoginLogItem {
|
||||
return v1.LoginLogItem{
|
||||
Id: r["id"].Int64(),
|
||||
Username: r["username"].String(),
|
||||
LogType: r["log_type"].Int(),
|
||||
LogTypeText: DictGetText(ctx, loginLogSerializeMaps["log_type"], r["log_type"].Int()),
|
||||
Source: r["source"].Int(),
|
||||
SourceText: DictGetText(ctx, loginLogSerializeMaps["source"], r["source"].Int()),
|
||||
Method: r["method"].String(),
|
||||
RequestMethod: r["request_method"].String(),
|
||||
Url: r["url"].String(),
|
||||
Param: r["param"].String(),
|
||||
Result: r["result"].String(),
|
||||
Ip: r["ip"].String(),
|
||||
Location: r["location"].String(),
|
||||
Os: r["os"].String(),
|
||||
Browser: r["browser"].String(),
|
||||
ConsumeTime: r["consume_time"].Int64(),
|
||||
Status: r["status"].Int(),
|
||||
StatusText: DictGetText(ctx, loginLogSerializeMaps["status"], r["status"].Int()),
|
||||
Error: r["error"].String(),
|
||||
CreateTime: r["create_time"].GTime(),
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user