1. 修复日志创建时间筛选报错的bug.
2. 修复日志里操作人,修改人,userAgent为空的bug. 3. 迁移表时,日志表添加字段注释. 4. sys_opera_log表oper_param字段类型改为text,解决字段长度报错的问题
This commit is contained in:
1 parent
dc625997c4
commit
0f742900f5
5 files changed
+24
-13
No files matched your search
@@ -3,6 +3,7 @@
|
|||||||
*/.DS_Store
|
*/.DS_Store
|
||||||
static/uploadfile
|
static/uploadfile
|
||||||
main.exe
|
main.exe
|
||||||
|
*.exe
|
||||||
go-admin
|
go-admin
|
||||||
temp/
|
temp/
|
||||||
!temp
|
!temp
|
||||||
|
|||||||
@@ -18,15 +18,15 @@ type SysOperaLog struct {
|
|||||||
BusinessType string `json:"businessType" gorm:"size:128;comment:操作类型"`
|
BusinessType string `json:"businessType" gorm:"size:128;comment:操作类型"`
|
||||||
BusinessTypes string `json:"businessTypes" gorm:"size:128;comment:BusinessTypes"`
|
BusinessTypes string `json:"businessTypes" gorm:"size:128;comment:BusinessTypes"`
|
||||||
Method string `json:"method" gorm:"size:128;comment:函数"`
|
Method string `json:"method" gorm:"size:128;comment:函数"`
|
||||||
RequestMethod string `json:"requestMethod" gorm:"size:128;comment:请求方式"`
|
RequestMethod string `json:"requestMethod" gorm:"size:128;comment:请求方式 GET POST PUT DELETE"`
|
||||||
OperatorType string `json:"operatorType" gorm:"size:128;comment:操作类型"`
|
OperatorType string `json:"operatorType" gorm:"size:128;comment:操作类型"`
|
||||||
OperName string `json:"operName" gorm:"size:128;comment:操作者"`
|
OperName string `json:"operName" gorm:"size:128;comment:操作者"`
|
||||||
DeptName string `json:"deptName" gorm:"size:128;comment:部门名称"`
|
DeptName string `json:"deptName" gorm:"size:128;comment:部门名称"`
|
||||||
OperUrl string `json:"operUrl" gorm:"size:255;comment:访问地址"`
|
OperUrl string `json:"operUrl" gorm:"size:255;comment:访问地址"`
|
||||||
OperIp string `json:"operIp" gorm:"size:128;comment:客户端ip"`
|
OperIp string `json:"operIp" gorm:"size:128;comment:客户端ip"`
|
||||||
OperLocation string `json:"operLocation" gorm:"size:128;comment:访问位置"`
|
OperLocation string `json:"operLocation" gorm:"size:128;comment:访问位置"`
|
||||||
OperParam string `json:"operParam" gorm:"size:255;comment:请求参数"`
|
OperParam string `json:"operParam" gorm:"text;comment:请求参数"`
|
||||||
Status string `json:"status" gorm:"size:4;comment:操作状态"`
|
Status string `json:"status" gorm:"size:4;comment:操作状态 1:正常 2:关闭"`
|
||||||
OperTime time.Time `json:"operTime" gorm:"comment:操作时间"`
|
OperTime time.Time `json:"operTime" gorm:"comment:操作时间"`
|
||||||
JsonResult string `json:"jsonResult" gorm:"size:255;comment:返回数据"`
|
JsonResult string `json:"jsonResult" gorm:"size:255;comment:返回数据"`
|
||||||
Remark string `json:"remark" gorm:"size:255;comment:备注"`
|
Remark string `json:"remark" gorm:"size:255;comment:备注"`
|
||||||
|
|||||||
@@ -8,16 +8,21 @@ import (
|
|||||||
common "go-admin/common/models"
|
common "go-admin/common/models"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
OperaStatusEnabel = "1" // 状态-正常
|
||||||
|
OperaStatusDisable = "2" // 状态-关闭
|
||||||
|
)
|
||||||
|
|
||||||
type SysOperaLogGetPageReq struct {
|
type SysOperaLogGetPageReq struct {
|
||||||
dto.Pagination `search:"-"`
|
dto.Pagination `search:"-"`
|
||||||
Title string `form:"title" search:"type:contains;column:title;table:sys_opera_log" comment:"操作模块"`
|
Title string `form:"title" search:"type:contains;column:title;table:sys_opera_log" comment:"操作模块"`
|
||||||
Method string `form:"method" search:"type:contains;column:method;table:sys_opera_log" comment:"函数"`
|
Method string `form:"method" search:"type:contains;column:method;table:sys_opera_log" comment:"函数"`
|
||||||
RequestMethod string `form:"requestMethod" search:"type:contains;column:request_method;table:sys_opera_log" comment:"请求方式"`
|
RequestMethod string `form:"requestMethod" search:"type:contains;column:request_method;table:sys_opera_log" comment:"请求方式: GET POST PUT DELETE"`
|
||||||
OperUrl string `form:"operUrl" search:"type:contains;column:oper_url;table:sys_opera_log" comment:"访问地址"`
|
OperUrl string `form:"operUrl" search:"type:contains;column:oper_url;table:sys_opera_log" comment:"访问地址"`
|
||||||
OperIp string `form:"operIp" search:"type:exact;column:oper_ip;table:sys_opera_log" comment:"客户端ip"`
|
OperIp string `form:"operIp" search:"type:exact;column:oper_ip;table:sys_opera_log" comment:"客户端ip"`
|
||||||
Status int `form:"status" search:"type:exact;column:status;table:sys_opera_log" comment:"状态"`
|
Status int `form:"status" search:"type:exact;column:status;table:sys_opera_log" comment:"状态 1:正常 2:关闭"`
|
||||||
BeginTime string `form:"beginTime" search:"type:gte;column:ctime;table:sys_opera_log" comment:"创建时间"`
|
BeginTime string `form:"beginTime" search:"type:gte;column:created_at;table:sys_opera_log" comment:"创建时间"`
|
||||||
EndTime string `form:"endTime" search:"type:lte;column:ctime;table:sys_opera_log" comment:"创建时间"`
|
EndTime string `form:"endTime" search:"type:lte;column:created_at;table:sys_opera_log" comment:"更新时间"`
|
||||||
SysOperaLogOrder
|
SysOperaLogOrder
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,15 +10,15 @@ type SysOperaLog struct {
|
|||||||
BusinessType string `json:"businessType" gorm:"type:varchar(128);comment:操作类型"`
|
BusinessType string `json:"businessType" gorm:"type:varchar(128);comment:操作类型"`
|
||||||
BusinessTypes string `json:"businessTypes" gorm:"type:varchar(128);comment:BusinessTypes"`
|
BusinessTypes string `json:"businessTypes" gorm:"type:varchar(128);comment:BusinessTypes"`
|
||||||
Method string `json:"method" gorm:"type:varchar(128);comment:函数"`
|
Method string `json:"method" gorm:"type:varchar(128);comment:函数"`
|
||||||
RequestMethod string `json:"requestMethod" gorm:"type:varchar(128);comment:请求方式"`
|
RequestMethod string `json:"requestMethod" gorm:"type:varchar(128);comment:请求方式: GET POST PUT DELETE"`
|
||||||
OperatorType string `json:"operatorType" gorm:"type:varchar(128);comment:操作类型"`
|
OperatorType string `json:"operatorType" gorm:"type:varchar(128);comment:操作类型"`
|
||||||
OperName string `json:"operName" gorm:"type:varchar(128);comment:操作者"`
|
OperName string `json:"operName" gorm:"type:varchar(128);comment:操作者"`
|
||||||
DeptName string `json:"deptName" gorm:"type:varchar(128);comment:部门名称"`
|
DeptName string `json:"deptName" gorm:"type:varchar(128);comment:部门名称"`
|
||||||
OperUrl string `json:"operUrl" gorm:"type:varchar(255);comment:访问地址"`
|
OperUrl string `json:"operUrl" gorm:"type:varchar(255);comment:访问地址"`
|
||||||
OperIp string `json:"operIp" gorm:"type:varchar(128);comment:客户端ip"`
|
OperIp string `json:"operIp" gorm:"type:varchar(128);comment:客户端ip"`
|
||||||
OperLocation string `json:"operLocation" gorm:"type:varchar(128);comment:访问位置"`
|
OperLocation string `json:"operLocation" gorm:"type:varchar(128);comment:访问位置"`
|
||||||
OperParam string `json:"operParam" gorm:"type:varchar(255);comment:请求参数"`
|
OperParam string `json:"operParam" gorm:"type:text;comment:请求参数"`
|
||||||
Status string `json:"status" gorm:"type:varchar(4);comment:操作状态"`
|
Status string `json:"status" gorm:"type:varchar(4);comment:操作状态 1:正常 2:关闭"`
|
||||||
OperTime time.Time `json:"operTime" gorm:"type:timestamp;comment:操作时间"`
|
OperTime time.Time `json:"operTime" gorm:"type:timestamp;comment:操作时间"`
|
||||||
JsonResult string `json:"jsonResult" gorm:"type:varchar(255);comment:返回数据"`
|
JsonResult string `json:"jsonResult" gorm:"type:varchar(255);comment:返回数据"`
|
||||||
Remark string `json:"remark" gorm:"type:varchar(255);comment:备注"`
|
Remark string `json:"remark" gorm:"type:varchar(255);comment:备注"`
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"go-admin/app/admin/service/dto"
|
||||||
"go-admin/common"
|
"go-admin/common"
|
||||||
gaConfig "go-admin/config"
|
gaConfig "go-admin/config"
|
||||||
"io"
|
"io"
|
||||||
@@ -102,6 +103,7 @@ func LoggerToFile() gin.HandlerFunc {
|
|||||||
|
|
||||||
// SetDBOperLog 写入操作日志表 fixme 该方法后续即将弃用
|
// SetDBOperLog 写入操作日志表 fixme 该方法后续即将弃用
|
||||||
func SetDBOperLog(c *gin.Context, clientIP string, statusCode int, reqUri string, reqMethod string, latencyTime time.Duration, body string, result string, status int) {
|
func SetDBOperLog(c *gin.Context, clientIP string, statusCode int, reqUri string, reqMethod string, latencyTime time.Duration, body string, result string, status int) {
|
||||||
|
|
||||||
log := api.GetRequestLogger(c)
|
log := api.GetRequestLogger(c)
|
||||||
l := make(map[string]interface{})
|
l := make(map[string]interface{})
|
||||||
l["_fullPath"] = c.FullPath()
|
l["_fullPath"] = c.FullPath()
|
||||||
@@ -110,16 +112,19 @@ func SetDBOperLog(c *gin.Context, clientIP string, statusCode int, reqUri string
|
|||||||
fmt.Println("gaConfig.ExtConfig.AMap.Key", gaConfig.ExtConfig.AMap.Key)
|
fmt.Println("gaConfig.ExtConfig.AMap.Key", gaConfig.ExtConfig.AMap.Key)
|
||||||
l["operLocation"] = pkg.GetLocation(clientIP, gaConfig.ExtConfig.AMap.Key)
|
l["operLocation"] = pkg.GetLocation(clientIP, gaConfig.ExtConfig.AMap.Key)
|
||||||
l["operName"] = user.GetUserName(c)
|
l["operName"] = user.GetUserName(c)
|
||||||
l["requestMethod"] = c.Request.Method
|
l["requestMethod"] = reqMethod
|
||||||
l["operParam"] = body
|
l["operParam"] = body
|
||||||
l["operTime"] = time.Now()
|
l["operTime"] = time.Now()
|
||||||
l["jsonResult"] = result
|
l["jsonResult"] = result
|
||||||
l["latencyTime"] = latencyTime.String()
|
l["latencyTime"] = latencyTime.String()
|
||||||
l["statusCode"] = statusCode
|
l["statusCode"] = statusCode
|
||||||
|
l["userAgent"] = c.Request.UserAgent()
|
||||||
|
l["createBy"] = user.GetUserId(c)
|
||||||
|
l["updateBy"] = user.GetUserId(c)
|
||||||
if status == http.StatusOK {
|
if status == http.StatusOK {
|
||||||
l["status"] = "2"
|
l["status"] = dto.OperaStatusEnabel
|
||||||
} else {
|
} else {
|
||||||
l["status"] = "1"
|
l["status"] = dto.OperaStatusDisable
|
||||||
}
|
}
|
||||||
q := sdk.Runtime.GetMemoryQueue(c.Request.Host)
|
q := sdk.Runtime.GetMemoryQueue(c.Request.Host)
|
||||||
message, err := sdk.Runtime.GetStreamMessage("", global.OperateLog, l)
|
message, err := sdk.Runtime.GetStreamMessage("", global.OperateLog, l)
|
||||||
|
|||||||
Reference in new issue
Block a user