refactor: 重构更新多个文件中的相关调用
This commit is contained in:
@@ -6,7 +6,8 @@ import (
|
||||
|
||||
"be.ems/lib/log"
|
||||
"be.ems/lib/services"
|
||||
tokenConst "be.ems/src/framework/constants/token"
|
||||
"be.ems/src/framework/constants"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
)
|
||||
|
||||
@@ -23,7 +24,7 @@ func LoggerTrace(next http.Handler) http.Handler {
|
||||
log.Trace(" User-Agent:", r.Header.Get("User-Agent"))
|
||||
log.Trace(" Content-Type:", r.Header.Get("Content-Type"))
|
||||
log.Trace(" AccessToken:", r.Header.Get("AccessToken"))
|
||||
log.Trace(" Authorization:", r.Header.Get(tokenConst.HEADER_KEY))
|
||||
log.Trace(" Authorization:", r.Header.Get(constants.HEADER_KEY))
|
||||
log.Trace("Trace End=====")
|
||||
//body, _ := io.ReadAll(io.LimitReader(r.Body, global.RequestBodyMaxLen))
|
||||
// nop-close to ready r.Body !!!
|
||||
|
||||
@@ -11,7 +11,7 @@ import (
|
||||
|
||||
"be.ems/lib/core/ctx"
|
||||
"be.ems/lib/log"
|
||||
"be.ems/src/framework/datasource"
|
||||
"be.ems/src/framework/database/db"
|
||||
"be.ems/src/framework/utils/date"
|
||||
)
|
||||
|
||||
@@ -52,7 +52,7 @@ func LogMML(next http.Handler) http.Handler {
|
||||
username := ctx.LoginUserToUserName(r)
|
||||
// 执行插入
|
||||
sql := "insert into mml_log (user,ip,ne_type,ne_id,mml,result,log_time)values(?,?,?,?,?,?,?)"
|
||||
_, sqlerr := datasource.ExecDB("", sql, []any{username, ipAddr, neType, neId, mmlCmd, resultStr, timeStr})
|
||||
_, sqlerr := db.ExecDB("", sql, []any{username, ipAddr, neType, neId, mmlCmd, resultStr, timeStr})
|
||||
if sqlerr != nil {
|
||||
log.Errorf("insert row : %v", sqlerr.Error())
|
||||
}
|
||||
|
||||
@@ -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