日志管理列表

This commit is contained in:
陈俊宏 2024-11-28 11:38:13 +08:00
parent 640b1ed361
commit f788fa580c
7 changed files with 70 additions and 11 deletions

View File

@ -4,10 +4,13 @@ import (
"cron_admin/app/constants/errorcode"
"cron_admin/app/http/controllers"
"cron_admin/app/http/entities/backend"
"cron_admin/app/models/croncmdmodel"
"cron_admin/app/services"
cmd_services "cron_admin/app/services/cmd_service"
"cron_admin/app/utils/helper"
"cron_admin/app/utils/mapstructure"
"github.com/gin-gonic/gin"
"strconv"
)
func CronFuncLogsList(c *gin.Context) {
@ -18,7 +21,33 @@ func CronFuncLogsList(c *gin.Context) {
} else {
var funcLogsListResponse []backend.CronFuncLogsListResponse
_ = mapstructure.DecodeWithTime(funcLogsList, &funcLogsListResponse, helper.DefaultFormatLayout)
// todo 获取当前列表下的CmdName
// 获取当前列表下的CmdName
// 获取所有的cmd_id
var cmdIds []string
cmdIdsMap := make(map[int64]bool)
for _, v := range funcLogsListResponse {
if _, ok := cmdIdsMap[v.CmdId]; ok {
continue
}
cmdIdsMap[v.CmdId] = true
// v.cmdId 转成string
cmdIdStr := strconv.FormatInt(v.CmdId, 10)
cmdIds = append(cmdIds, cmdIdStr)
}
// 获取所有的cmd_id对应的CmdName
_, cmdList, err := cmd_services.GetListByWhere(&backend.CmdListRequest{CmdIds: cmdIds}, 1, 100)
if err != nil {
return
}
cmdListMap := make(map[int64]croncmdmodel.CronCmd)
for _, v := range cmdList {
cmdListMap[int64(v.CmdId)] = v
}
for k, v := range funcLogsListResponse {
if cmdListMap != nil && cmdListMap[v.CmdId].CmdName != "" {
funcLogsListResponse[k].CmdName = cmdListMap[v.CmdId].CmdName
}
}
controllers.HandRes(c, gin.H{"data": funcLogsListResponse, "count": count}, err)
}
}

View File

@ -4,12 +4,15 @@ import (
"cron_admin/app/constants/errorcode"
"cron_admin/app/http/controllers"
"cron_admin/app/http/entities/backend"
"cron_admin/app/models/croncmdmodel"
"cron_admin/app/models/cronusermodel"
"cron_admin/app/services"
cmd_services "cron_admin/app/services/cmd_service"
userServices "cron_admin/app/services/user_service"
"cron_admin/app/utils/helper"
"cron_admin/app/utils/mapstructure"
"github.com/gin-gonic/gin"
"strconv"
"strings"
)
@ -24,6 +27,8 @@ func CronReportLogsList(c *gin.Context) {
// 合并reportLogsListResponse下的所有user_id 并去重
var userIds []string
userIdsMap := make(map[int64]bool)
var cmdIds []string
cmdIdsMap := make(map[int64]bool)
for _, v := range reportLogsListResponse {
userIdsStr := strings.Split(v.UserId, ",")
for _, userId := range userIdsStr {
@ -35,6 +40,13 @@ func CronReportLogsList(c *gin.Context) {
userIds = append(userIds, userId)
}
}
if _, ok := cmdIdsMap[v.CmdId]; ok {
continue
}
cmdIdsMap[v.CmdId] = true
// v.cmdId 转成string
cmdIdStr := strconv.FormatInt(v.CmdId, 10)
cmdIds = append(cmdIds, cmdIdStr)
}
_, userList, err := userServices.GetListByWhere(&backend.UserListRequest{UserIds: userIds}, 1, 100)
if err != nil {
@ -44,6 +56,15 @@ func CronReportLogsList(c *gin.Context) {
for _, v := range userList {
userListMap[int64(v.UserId)] = v
}
// 获取所有的cmd_id对应的CmdName
_, cmdList, err := cmd_services.GetListByWhere(&backend.CmdListRequest{CmdIds: cmdIds}, 1, 100)
if err != nil {
return
}
cmdListMap := make(map[int64]croncmdmodel.CronCmd)
for _, v := range cmdList {
cmdListMap[int64(v.CmdId)] = v
}
for k, v := range reportLogsListResponse {
userIdsStr := strings.Split(v.UserId, ",")
var userNames []string
@ -54,6 +75,9 @@ func CronReportLogsList(c *gin.Context) {
}
userNamesStr := strings.Join(userNames, ",")
reportLogsListResponse[k].UserName = userNamesStr
if cmdListMap != nil && cmdListMap[v.CmdId].CmdName != "" {
reportLogsListResponse[k].CmdName = cmdListMap[v.CmdId].CmdName
}
}
controllers.HandRes(c, gin.H{"data": reportLogsListResponse, "count": count}, err)

View File

@ -6,11 +6,12 @@ import (
)
type CmdListRequest struct {
Page int `json:"page" validate:"required" form:"page" example:"1"`
Limit int `json:"limit" validate:"required" form:"limit" example:"10"`
CmdName string `json:"cmd_name" form:"cmd_name" example:"155555555"`
Status int `json:"status" form:"status" example:"1"`
ExecuteType int `json:"execute_type" form:"execute_type" example:"46516"`
Page int `json:"page" validate:"required" form:"page" example:"1"`
Limit int `json:"limit" validate:"required" form:"limit" example:"10"`
CmdName string `json:"cmd_name" form:"cmd_name" example:"155555555"`
Status int `json:"status" form:"status" example:"1"`
ExecuteType int `json:"execute_type" form:"execute_type" example:"46516"`
CmdIds []string `json:"cmd_id"`
}
type CmdInfoRequest struct {
@ -18,7 +19,7 @@ type CmdInfoRequest struct {
}
type CmdListResponse struct {
CmdId string `json:"cmd_id"`
CmdId int `json:"cmd_id"`
CmdName string `json:"cmd_name"`
UserIds string `json:"user_ids"`
EntryId int `json:"entry_id"`

View File

@ -16,6 +16,7 @@ type CronReportLogsListResponse struct {
ReportId int64 `json:"report_id"`
FuncLogId int64 `json:"func_log_id"`
CmdId int64 `json:"cmd_id"`
CmdName string `json:"cmd_name"`
UserId string `json:"user_id"`
UserName string `json:"user_name"`
Data string `json:"data"`

View File

@ -13,7 +13,7 @@ var (
// 实体
type CronCmd struct {
CmdId string `xorm:"'cmd_id' UNSIGNED INT"`
CmdId int `xorm:"'cmd_id' UNSIGNED INT"`
CmdName string `xorm:"'cmd_name' varchar(20)"`
UserIds string `xorm:"'user_ids' varchar(50)"`
EntryId int `xorm:"'entry_id' int(10)"`

View File

@ -21,6 +21,10 @@ func GetListByWhere(request *backend.CmdListRequest, page int, limit int) (count
if request.ExecuteType != 0 {
cond = cond.And(builder.Eq{"status": request.Status})
}
if len(request.CmdIds) > 0 {
// 使用IN查询
cond = cond.And(builder.In("cmd_id", request.CmdIds))
}
session := croncmdmodel.GetInstance().GetDb().Where(cond)

View File

@ -9,13 +9,13 @@ import (
func CronReportLogsList(request *backend.CronReportLogsListRequest, page int, limit int) (count int64, listInfo []cronreportlogsmodel.CronReportLogs, err error) {
conn := builder.NewCond()
if request.FuncLogId != 0 {
conn = conn.And(builder.Eq{"FuncLogId": request.FuncLogId})
conn = conn.And(builder.Eq{"func_log_id": request.FuncLogId})
}
if request.CmdId != 0 {
conn = conn.And(builder.Eq{"CmdId": request.CmdId})
conn = conn.And(builder.Eq{"cmd_id": request.CmdId})
}
if request.Status != 0 {
conn = conn.And(builder.Eq{"Status": request.Status})
conn = conn.And(builder.Eq{"status": request.Status})
}
// 使用FIND_IN_SET 函数
if request.UserId != 0 {