forked from all_user/stat_center
Initial commit
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
package opLogSer
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"github.com/gin-gonic/gin"
|
||||
"stat/api/proto"
|
||||
"stat/common"
|
||||
"stat/common/stdLog"
|
||||
"stat/common/utils"
|
||||
"stat/models/opLogMod"
|
||||
"time"
|
||||
)
|
||||
|
||||
// 添加操作日志
|
||||
func AddOpLog(ctx *gin.Context, account string, isAdmin bool, opData interface{}) {
|
||||
common.Go(func() {
|
||||
now := time.Now()
|
||||
opDataStr, _ := json.Marshal(opData)
|
||||
|
||||
doc := opLogMod.OpLog{
|
||||
Operator: account,
|
||||
Router: ctx.Request.RequestURI,
|
||||
Data: string(opDataStr),
|
||||
IsAdmin: isAdmin,
|
||||
CreatedAt: now,
|
||||
}
|
||||
|
||||
_ = opLogMod.AddOpLog(ctx, &doc)
|
||||
})
|
||||
}
|
||||
|
||||
func GetOpLogList(ctx context.Context, param proto.ListOpLogReq) (code stdLog.CodeType, data interface{}, err error) {
|
||||
resp := proto.ListOpLogRes{
|
||||
Total: 0,
|
||||
List: make([]proto.OpLogInfo, 0),
|
||||
}
|
||||
|
||||
skip, limit := utils.ToDBPage(param.PageNum, param.PageSize)
|
||||
total, opList, err := opLogMod.GetOpLogList(ctx, param.Operator, param.Router, param.IsAdmin, skip, limit)
|
||||
if err != nil {
|
||||
code = stdLog.Failure
|
||||
return
|
||||
}
|
||||
|
||||
for _, v := range opList {
|
||||
tmp := proto.OpLogInfo{
|
||||
Operator: v.Operator,
|
||||
Router: v.Router,
|
||||
Data: v.Data,
|
||||
IsAdmin: v.IsAdmin,
|
||||
CreatedAt: v.CreatedAt,
|
||||
}
|
||||
|
||||
resp.List = append(resp.List, tmp)
|
||||
}
|
||||
|
||||
resp.Total = total
|
||||
|
||||
data = resp
|
||||
code = stdLog.Success
|
||||
return
|
||||
}
|
||||
Reference in New Issue
Block a user