refactor: 重构更新多个文件中的相关调用
This commit is contained in:
@@ -12,9 +12,9 @@ import (
|
||||
"time"
|
||||
|
||||
"be.ems/lib/core/ctx"
|
||||
"be.ems/src/framework/constants/common"
|
||||
"be.ems/src/framework/constants"
|
||||
"be.ems/src/framework/ip2region"
|
||||
"be.ems/src/framework/middleware/collectlogs"
|
||||
"be.ems/src/framework/utils/ip2region"
|
||||
"be.ems/src/framework/utils/parse"
|
||||
"be.ems/src/modules/system/model"
|
||||
"be.ems/src/modules/system/service"
|
||||
@@ -52,19 +52,17 @@ func LogOperate(options collectlogs.Options) func(http.Handler) http.Handler {
|
||||
// 解析ip地址
|
||||
ip := strings.Split(r.RemoteAddr, ":")[0]
|
||||
ipaddr := ip2region.ClientIP(ip)
|
||||
location := ip2region.RealAddressByIp(ipaddr)
|
||||
location := "-" //ip2region.RealAddressByIp(ipaddr)
|
||||
// 操作日志记录
|
||||
operLog := model.SysLogOperate{
|
||||
Title: options.Title,
|
||||
BusinessType: options.BusinessType,
|
||||
OperatorType: collectlogs.OPERATOR_TYPE_MANAGE,
|
||||
Method: funcName,
|
||||
OperURL: r.RequestURI,
|
||||
RequestMethod: r.Method,
|
||||
OperIP: ipaddr,
|
||||
OperLocation: location,
|
||||
OperName: username,
|
||||
DeptName: "",
|
||||
Title: options.Title,
|
||||
BusinessType: options.BusinessType,
|
||||
OperaMethod: funcName,
|
||||
OperaUrl: r.RequestURI,
|
||||
OperaUrlMethod: r.Method,
|
||||
OperaIp: ipaddr,
|
||||
OperaLocation: location,
|
||||
OperaBy: username,
|
||||
}
|
||||
|
||||
// 是否需要保存request,参数和值
|
||||
@@ -97,7 +95,7 @@ func LogOperate(options collectlogs.Options) func(http.Handler) http.Handler {
|
||||
if len(paramsStr) > 2000 {
|
||||
paramsStr = paramsStr[:2000]
|
||||
}
|
||||
operLog.OperParam = paramsStr
|
||||
operLog.OperaParam = paramsStr
|
||||
}
|
||||
|
||||
next.ServeHTTP(w, r)
|
||||
@@ -110,9 +108,9 @@ func LogOperate(options collectlogs.Options) func(http.Handler) http.Handler {
|
||||
|
||||
// 响应状态
|
||||
if status == "200" || status == "204" {
|
||||
operLog.Status = common.STATUS_YES
|
||||
operLog.StatusFlag = constants.STATUS_YES
|
||||
} else {
|
||||
operLog.Status = common.STATUS_NO
|
||||
operLog.StatusFlag = constants.STATUS_NO
|
||||
}
|
||||
|
||||
// 是否需要保存response,参数和值
|
||||
@@ -121,16 +119,16 @@ func LogOperate(options collectlogs.Options) func(http.Handler) http.Handler {
|
||||
contentType := w.Header().Get("Content-Type")
|
||||
content := contentType + contentDisposition
|
||||
msg := fmt.Sprintf(`{"status":"%s","size":"%s","content-type":"%s"}`, status, size, content)
|
||||
operLog.OperMsg = msg
|
||||
operLog.OperaMsg = msg
|
||||
}
|
||||
|
||||
// 日志记录时间
|
||||
duration := time.Since(startTime)
|
||||
operLog.CostTime = duration.Milliseconds()
|
||||
operLog.OperTime = time.Now().UnixMilli()
|
||||
operLog.OperaTime = time.Now().UnixMilli()
|
||||
|
||||
// 保存操作记录到数据库
|
||||
service.NewSysLogOperateImpl.InsertSysLogOperate(operLog)
|
||||
service.NewSysLogOperate.Insert(operLog)
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user