日志管理列表
This commit is contained in:
parent
1b1f5b9a19
commit
b8d601d3cb
|
@ -0,0 +1,23 @@
|
|||
package backend
|
||||
|
||||
import (
|
||||
"cron_admin/app/constants/errorcode"
|
||||
"cron_admin/app/http/controllers"
|
||||
"cron_admin/app/http/entities/backend"
|
||||
"cron_admin/app/services"
|
||||
"cron_admin/app/utils/helper"
|
||||
"cron_admin/app/utils/mapstructure"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func CronFuncLogsList(c *gin.Context) {
|
||||
request := controllers.GetRequest(c).(*backend.CronFuncLogsListRequest)
|
||||
count, DbListInfo, err := services.CronFuncLogsList(request, request.Page, request.Limit)
|
||||
if err != nil {
|
||||
controllers.HandRes(c, nil, errorcode.ParamError)
|
||||
} else {
|
||||
var DbListResponse []backend.CronFuncLogsListResponse
|
||||
_ = mapstructure.DecodeWithTime(DbListInfo, &DbListResponse, helper.DefaultFormatLayout)
|
||||
controllers.HandRes(c, gin.H{"data": DbListResponse, "count": count}, err)
|
||||
}
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
package backend
|
||||
|
||||
import "cron_admin/app/http/entities"
|
||||
|
||||
type CronFuncLogsListRequest struct {
|
||||
entities.PageRequest
|
||||
CmdId int64 `json:"cmd_id"`
|
||||
Status int `json:"status"`
|
||||
}
|
||||
|
||||
type CronFuncLogsListResponse struct {
|
||||
LogId int64 `json:"log_id"`
|
||||
CmdId int64 `json:"cmd_id"`
|
||||
CmdName string `json:"cmd_name"`
|
||||
ReadExecute string `json:"read_execute"`
|
||||
WriteExecute string `json:"write_execute"`
|
||||
FailReason string `json:"fail_reason"`
|
||||
CreateTime string `json:"create_time"`
|
||||
UpdateTime string `json:"update_time"`
|
||||
Status int `json:"status"`
|
||||
}
|
|
@ -21,4 +21,7 @@ var BackendRequestMap = map[string]func() interface{}{
|
|||
common.ADMIN_OAUTH_V1 + "/channel/list": func() interface{} { return new(backend.ReportChannelListRequest) },
|
||||
common.ADMIN_OAUTH_V1 + "/channel/update": func() interface{} { return new(backend.ReportChannelUpdateRequest) },
|
||||
common.ADMIN_OAUTH_V1 + "/channel/delete": func() interface{} { return new(entities.IdRequest) },
|
||||
|
||||
// 日志
|
||||
common.ADMIN_OAUTH_V1 + "/log/cmd/list": func() interface{} { return new(backend.CronFuncLogsListRequest) },
|
||||
}
|
||||
|
|
|
@ -67,7 +67,7 @@ func RegisterAdminRoute(router *gin.Engine) {
|
|||
//任务日志
|
||||
cmdLog := log.Group("/cmd")
|
||||
{
|
||||
cmdLog.GET("/list", backend.Empty)
|
||||
cmdLog.POST("/list", backend.CronFuncLogsList)
|
||||
}
|
||||
//消息日志
|
||||
mesLog := log.Group("/mes")
|
||||
|
|
|
@ -0,0 +1,43 @@
|
|||
package cronfunclogsmodel
|
||||
|
||||
import (
|
||||
"github.com/qit-team/snow-core/db"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
var (
|
||||
once sync.Once
|
||||
m *CronFuncLogsModel
|
||||
)
|
||||
|
||||
// 实体
|
||||
type CronFuncLogs struct {
|
||||
LogId int64 `xorm:"'log_id' UNSIGNED INT"`
|
||||
CmdId int64 `xorm:"'cmd_id' INT"`
|
||||
ReadExecute string `xorm:"'read_execute' json"`
|
||||
WriteExecute string `xorm:"'write_execute' text"`
|
||||
FailReason string `xorm:"'fail_reason' text"`
|
||||
CreateTime time.Time `xorm:"'create_time' datetime"`
|
||||
UpdateTime time.Time `xorm:"'update_time' timestamp"`
|
||||
Status int `xorm:"'status' tinyint"`
|
||||
}
|
||||
|
||||
// 表名
|
||||
func (m *CronFuncLogs) TableName() string {
|
||||
return "cron_func_logs"
|
||||
}
|
||||
|
||||
// 私有化,防止被外部new
|
||||
type CronFuncLogsModel struct {
|
||||
db.Model //组合基础Model,集成基础Model的属性和方法
|
||||
}
|
||||
|
||||
// 单例模式
|
||||
func GetInstance() *CronFuncLogsModel {
|
||||
once.Do(func() {
|
||||
m = new(CronFuncLogsModel)
|
||||
//m.DiName = "" //设置数据库实例连接,默认db.SingletonMain
|
||||
})
|
||||
return m
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
package crondbmodel
|
||||
|
||||
import (
|
||||
"github.com/qit-team/snow-core/db"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
var (
|
||||
once sync.Once
|
||||
m *CronReportLogsModel
|
||||
)
|
||||
|
||||
// 实体
|
||||
type CronReportLogs struct {
|
||||
ReportId int64 `xorm:"'report_id' UNSIGNED INT"`
|
||||
FuncLogId int64 `xorm:"'func_log_id' INT"`
|
||||
CmdId int64 `xorm:"'cmd_id' INT"`
|
||||
UserId string `xorm:"'user_id' varchar(100)"`
|
||||
Data string `xorm:"'data' json"`
|
||||
FailReason string `xorm:"'fail_reason' varchar(200)"`
|
||||
CreateTime time.Time `xorm:"'create_time' datetime"`
|
||||
UpdateTime time.Time `xorm:"'update_time' timestamp"`
|
||||
Status int `xorm:"'status' tinyint"`
|
||||
}
|
||||
|
||||
// 表名
|
||||
func (m *CronReportLogs) TableName() string {
|
||||
return "cron_report_logs"
|
||||
}
|
||||
|
||||
// 私有化,防止被外部new
|
||||
type CronReportLogsModel struct {
|
||||
db.Model //组合基础Model,集成基础Model的属性和方法
|
||||
}
|
||||
|
||||
// 单例模式
|
||||
func GetInstance() *CronReportLogsModel {
|
||||
once.Do(func() {
|
||||
m = new(CronReportLogsModel)
|
||||
//m.DiName = "" //设置数据库实例连接,默认db.SingletonMain
|
||||
})
|
||||
return m
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
package services
|
||||
|
||||
import (
|
||||
"cron_admin/app/http/entities/backend"
|
||||
"cron_admin/app/models/cronfunclogsmodel"
|
||||
"xorm.io/builder"
|
||||
)
|
||||
|
||||
func CronFuncLogsList(request *backend.CronFuncLogsListRequest, page int, limit int) (count int64, listInfo []cronfunclogsmodel.CronFuncLogs, err error) {
|
||||
conn := builder.NewCond()
|
||||
if request.CmdId != 0 {
|
||||
conn = conn.And(builder.Eq{"CmdId": request.CmdId})
|
||||
}
|
||||
if request.Status != 0 {
|
||||
conn = conn.And(builder.Eq{"Status": request.Status})
|
||||
}
|
||||
session := cronfunclogsmodel.GetInstance().GetDb().Where(conn)
|
||||
if page != 0 && limit != 0 {
|
||||
session = session.Limit(limit, (page-1)*limit)
|
||||
}
|
||||
count, err = session.FindAndCount(&listInfo)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
Loading…
Reference in New Issue