refactor: 删除冗余常量文件并整合常量定义

This commit is contained in:
TsMask
2025-02-20 09:50:29 +08:00
parent 1b435074cb
commit a1296b6fe6
63 changed files with 1823 additions and 1748 deletions

View File

@@ -7,12 +7,11 @@ import (
"strings"
"time"
"be.ems/src/framework/constants/common"
tokenConstants "be.ems/src/framework/constants/token"
"be.ems/src/framework/constants"
"be.ems/src/framework/i18n"
"be.ems/src/framework/utils/ctx"
"be.ems/src/framework/reqctx"
"be.ems/src/framework/resp"
"be.ems/src/framework/utils/parse"
"be.ems/src/framework/vo/result"
"be.ems/src/modules/system/model"
"be.ems/src/modules/system/service"
@@ -91,7 +90,7 @@ func OptionNew(title, businessType string) Options {
func OperateLog(options Options) gin.HandlerFunc {
return func(c *gin.Context) {
c.Set("startTime", time.Now())
language := ctx.AcceptLanguage(c)
language := reqctx.AcceptLanguage(c)
// 函数名
funcName := c.HandlerName()
@@ -99,37 +98,31 @@ func OperateLog(options Options) gin.HandlerFunc {
funcName = funcName[lastDotIndex+1:]
// 解析ip地址
ipaddr, location := ctx.IPAddrLocation(c)
ipaddr, location := reqctx.IPAddrLocation(c)
// 获取登录用户信息
loginUser, err := ctx.LoginUser(c)
loginUser, err := reqctx.LoginUser(c)
if err != nil {
c.JSON(401, result.CodeMsg(401, i18n.TKey(language, err.Error())))
c.JSON(401, resp.CodeMsg(401, i18n.TKey(language, err.Error())))
c.Abort() // 停止执行后续的处理函数
return
}
// 操作日志记录
operLog := model.SysLogOperate{
Title: options.Title,
BusinessType: options.BusinessType,
OperatorType: options.OperatorType,
Method: funcName,
OperURL: c.Request.URL.Path,
RequestMethod: c.Request.Method,
OperIP: ipaddr,
OperLocation: location,
OperName: loginUser.User.UserName,
DeptName: loginUser.User.Dept.DeptName,
}
if loginUser.User.UserType == "sys" {
operLog.OperatorType = OPERATOR_TYPE_MANAGE
Title: options.Title,
BusinessType: options.BusinessType,
OperaMethod: funcName,
OperaUrl: c.Request.URL.Path,
OperaUrlMethod: c.Request.Method,
OperaIp: ipaddr,
OperaLocation: location,
OperaBy: loginUser.User.UserName,
}
// 是否需要保存request参数和值
if options.IsSaveRequestData {
params := ctx.RequestParamsMap(c)
params := reqctx.RequestParamsMap(c)
// 敏感属性字段进行掩码
processSensitiveFields(params)
jsonStr, _ := json.Marshal(params)
@@ -137,7 +130,7 @@ func OperateLog(options Options) gin.HandlerFunc {
if len(paramsStr) > 2000 {
paramsStr = paramsStr[:2000]
}
operLog.OperParam = paramsStr
operLog.OperaParam = paramsStr
}
// 调用下一个处理程序
@@ -146,9 +139,9 @@ func OperateLog(options Options) gin.HandlerFunc {
// 响应状态
status := c.Writer.Status()
if status == 200 {
operLog.Status = common.STATUS_YES
operLog.StatusFlag = constants.STATUS_YES
} else {
operLog.Status = common.STATUS_NO
operLog.StatusFlag = constants.STATUS_NO
}
// 是否需要保存response参数和值
@@ -157,16 +150,16 @@ func OperateLog(options Options) gin.HandlerFunc {
contentType := c.Writer.Header().Get("Content-Type")
content := contentType + contentDisposition
msg := fmt.Sprintf(`{"status":"%d","size":"%d","content-type":"%s"}`, status, c.Writer.Size(), content)
operLog.OperMsg = msg
operLog.OperaMsg = msg
}
// 日志记录时间
duration := time.Since(c.GetTime("startTime"))
operLog.CostTime = duration.Milliseconds()
operLog.OperTime = time.Now().UnixMilli()
operLog.OperaTime = time.Now().UnixMilli()
// 保存操作记录到数据库
service.NewSysLogOperateImpl.InsertSysLogOperate(operLog)
service.NewSysLogOperate.Insert(operLog)
}
}
@@ -179,8 +172,8 @@ var maskProperties []string = []string{
"oldPassword",
"newPassword",
"confirmPassword",
tokenConstants.RESPONSE_FIELD,
tokenConstants.ACCESS_TOKEN,
constants.ACCESS_TOKEN,
constants.ACCESS_TOKEN_QUERY,
}
// processSensitiveFields 处理敏感属性字段