-
-
Notifications
You must be signed in to change notification settings - Fork 274
/
Copy pathoperation_log_logic.go
87 lines (76 loc) · 2.13 KB
/
operation_log_logic.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package logic
import (
"fmt"
"github.com/eryajf/go-ldap-admin/model"
"github.com/eryajf/go-ldap-admin/model/request"
"github.com/eryajf/go-ldap-admin/model/response"
"github.com/eryajf/go-ldap-admin/public/tools"
"github.com/eryajf/go-ldap-admin/service/isql"
"github.com/gin-gonic/gin"
)
type OperationLogLogic struct{}
// List 数据列表
func (l OperationLogLogic) List(c *gin.Context, req interface{}) (data interface{}, rspError interface{}) {
r, ok := req.(*request.OperationLogListReq)
if !ok {
return nil, ReqAssertErr
}
_ = c
fmt.Println(r)
// 获取数据列表
logs, err := isql.OperationLog.List(r)
if err != nil {
return nil, tools.NewMySqlError(fmt.Errorf("获取接口列表失败: %s", err.Error()))
}
rets := make([]model.OperationLog, 0)
for _, log := range logs {
rets = append(rets, *log)
}
count, err := isql.OperationLog.Count()
if err != nil {
return nil, tools.NewMySqlError(fmt.Errorf("获取接口总数失败"))
}
return response.LogListRsp{
Total: count,
Logs: rets,
}, nil
// 获取
// logs, err := isql.OperationLog.List(&r)
// if err != nil {
// response.Fail(c, nil, "获取操作日志列表失败: "+err.Error())
// return
// }
// return nil, nil
}
// Delete 删除数据
func (l OperationLogLogic) Delete(c *gin.Context, req interface{}) (data interface{}, rspError interface{}) {
r, ok := req.(*request.OperationLogDeleteReq)
if !ok {
return nil, ReqAssertErr
}
_ = c
for _, id := range r.OperationLogIds {
filter := tools.H{"id": int(id)}
if !isql.OperationLog.Exist(filter) {
return nil, tools.NewMySqlError(fmt.Errorf("该条记录不存在"))
}
}
// 删除接口
err := isql.OperationLog.Delete(r.OperationLogIds)
if err != nil {
return nil, tools.NewMySqlError(fmt.Errorf("删除该改条记录失败: %s", err.Error()))
}
return nil, nil
}
func (l OperationLogLogic) Clean(c *gin.Context, req interface{}) (data interface{}, rspError interface{}) {
_, ok := req.(*request.OperationLogListReq)
if !ok {
return nil, ReqAssertErr
}
_ = c
err := isql.OperationLog.Clean()
if err != nil {
return err, nil
}
return "操作日志清空完成", nil
}