mirror of
https://gitee.com/XM-GO/PandaX.git
synced 2026-04-23 02:48:34 +08:00
优化功能,通知功能,任务功能
This commit is contained in:
63
apps/log/api/log_job.go
Normal file
63
apps/log/api/log_job.go
Normal file
@@ -0,0 +1,63 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"pandax/apps/log/entity"
|
||||
"pandax/apps/log/services"
|
||||
"pandax/base/ctx"
|
||||
"pandax/base/ginx"
|
||||
"pandax/base/utils"
|
||||
)
|
||||
|
||||
type LogJobApi struct {
|
||||
LogJobApp services.LogJobModel
|
||||
}
|
||||
|
||||
// @Summary Job日志列表
|
||||
// @Description 获取JSON
|
||||
// @Tags 任务日志
|
||||
// @Param status query string false "status"
|
||||
// @Param jobGroup query string false "jobGroup"
|
||||
// @Param name query string false "name"
|
||||
// @Param pageSize query int false "页条数"
|
||||
// @Param pageNum query int false "页码"
|
||||
// @Success 200 {string} string "{"code": 200, "data": [...]}"
|
||||
// @Router /log/logJob/list [get]
|
||||
// @Security
|
||||
func (l *LogJobApi) GetJobLogList(rc *ctx.ReqCtx) {
|
||||
pageNum := ginx.QueryInt(rc.GinCtx, "pageNum", 1)
|
||||
pageSize := ginx.QueryInt(rc.GinCtx, "pageSize", 10)
|
||||
name := rc.GinCtx.Query("name")
|
||||
jobGroup := rc.GinCtx.Query("jobGroup")
|
||||
status := rc.GinCtx.Query("status")
|
||||
|
||||
list, total := l.LogJobApp.FindListPage(pageNum, pageSize, entity.LogJob{Name: name, JobGroup: jobGroup, Status: status})
|
||||
rc.ResData = map[string]interface{}{
|
||||
"data": list,
|
||||
"total": total,
|
||||
"pageNum": pageNum,
|
||||
"pageSize": pageSize,
|
||||
}
|
||||
}
|
||||
|
||||
// @Summary 批量删除登录日志
|
||||
// @Description 删除数据
|
||||
// @Tags 任务日志
|
||||
// @Param logId path string true "以逗号(,)分割的logId"
|
||||
// @Success 200 {string} string "{"code": 200, "message": "删除成功"}"
|
||||
// @Success 200 {string} string "{"code": 400, "message": "删除失败"}"
|
||||
// @Router /log/logJob/{logId} [delete]
|
||||
func (l *LogJobApi) DeleteJobLog(rc *ctx.ReqCtx) {
|
||||
logIds := rc.GinCtx.Param("logId")
|
||||
group := utils.IdsStrToIdsIntGroup(logIds)
|
||||
l.LogJobApp.Delete(group)
|
||||
}
|
||||
|
||||
// @Summary 清空登录日志
|
||||
// @Description 删除数据
|
||||
// @Tags 任务日志
|
||||
// @Success 200 {string} string "{"code": 200, "message": "删除成功"}"
|
||||
// @Success 200 {string} string "{"code": 400, "message": "删除失败"}"
|
||||
// @Router /log/logJob/all [delete]
|
||||
func (l *LogJobApi) DeleteAll(rc *ctx.ReqCtx) {
|
||||
l.LogJobApp.DeleteAll()
|
||||
}
|
||||
@@ -20,7 +20,7 @@ type LogLoginApi struct {
|
||||
// @Param pageSize query int false "页条数"
|
||||
// @Param pageNum query int false "页码"
|
||||
// @Success 200 {string} string "{"code": 200, "data": [...]}"
|
||||
// @Router /system/log/list [get]
|
||||
// @Router /log/logLogin/list [get]
|
||||
// @Security
|
||||
func (l *LogLoginApi) GetLoginLogList(rc *ctx.ReqCtx) {
|
||||
pageNum := ginx.QueryInt(rc.GinCtx, "pageNum", 1)
|
||||
@@ -42,7 +42,7 @@ func (l *LogLoginApi) GetLoginLogList(rc *ctx.ReqCtx) {
|
||||
// @Tags 登录日志
|
||||
// @Param infoId path int true "infoId"
|
||||
// @Success 200 {string} string "{"code": 200, "data": [...]}"
|
||||
// @Router /system/log/logLogin/{infoId} [get]
|
||||
// @Router /log/logLogin/{infoId} [get]
|
||||
// @Security
|
||||
func (l *LogLoginApi) GetLoginLog(rc *ctx.ReqCtx) {
|
||||
infoId := ginx.PathParamInt(rc.GinCtx, rc.GinCtx.Param("infoId"))
|
||||
@@ -57,7 +57,7 @@ func (l *LogLoginApi) GetLoginLog(rc *ctx.ReqCtx) {
|
||||
// @Param data body entity.LogLogin true "body"
|
||||
// @Success 200 {string} string "{"code": 200, "message": "添加成功"}"
|
||||
// @Success 200 {string} string "{"code": 400, "message": "添加失败"}"
|
||||
// @Router /system/log/logLogin [put]
|
||||
// @Router /log/logLogin [put]
|
||||
// @Security X-TOKEN
|
||||
func (l *LogLoginApi) UpdateLoginLog(rc *ctx.ReqCtx) {
|
||||
var log entity.LogLogin
|
||||
@@ -71,7 +71,7 @@ func (l *LogLoginApi) UpdateLoginLog(rc *ctx.ReqCtx) {
|
||||
// @Param infoId path string true "以逗号(,)分割的infoId"
|
||||
// @Success 200 {string} string "{"code": 200, "message": "删除成功"}"
|
||||
// @Success 200 {string} string "{"code": 400, "message": "删除失败"}"
|
||||
// @Router /system/log/logLogin/{infoId} [delete]
|
||||
// @Router /log/logLogin/{infoId} [delete]
|
||||
func (l *LogLoginApi) DeleteLoginLog(rc *ctx.ReqCtx) {
|
||||
infoIds := rc.GinCtx.Param("infoId")
|
||||
group := utils.IdsStrToIdsIntGroup(infoIds)
|
||||
@@ -83,7 +83,7 @@ func (l *LogLoginApi) DeleteLoginLog(rc *ctx.ReqCtx) {
|
||||
// @Tags 登录日志
|
||||
// @Success 200 {string} string "{"code": 200, "message": "删除成功"}"
|
||||
// @Success 200 {string} string "{"code": 400, "message": "删除失败"}"
|
||||
// @Router /system/log/logLogin/all [delete]
|
||||
// @Router /log/logLogin/all [delete]
|
||||
func (l *LogLoginApi) DeleteAll(rc *ctx.ReqCtx) {
|
||||
l.LogLoginApp.DeleteAll()
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ type LogOperApi struct {
|
||||
// @Param pageSize query int false "页条数"
|
||||
// @Param pageNum query int false "页码"
|
||||
// @Success 200 {string} string "{"code": 200, "data": [...]}"
|
||||
// @Router /system/log/list [get]
|
||||
// @Router /log/logOper/list [get]
|
||||
// @Security
|
||||
func (l *LogOperApi) GetOperLogList(rc *ctx.ReqCtx) {
|
||||
pageNum := ginx.QueryInt(rc.GinCtx, "pageNum", 1)
|
||||
@@ -44,7 +44,7 @@ func (l *LogOperApi) GetOperLogList(rc *ctx.ReqCtx) {
|
||||
// @Tags 操作日志
|
||||
// @Param operId path int true "operId"
|
||||
// @Success 200 {string} string "{"code": 200, "data": [...]}"
|
||||
// @Router /system/log/logOper/{operId} [get]
|
||||
// @Router /log/logOper/{operId} [get]
|
||||
// @Security
|
||||
func (l *LogOperApi) GetOperLog(rc *ctx.ReqCtx) {
|
||||
operId := ginx.PathParamInt(rc.GinCtx, rc.GinCtx.Param("operId"))
|
||||
@@ -57,7 +57,7 @@ func (l *LogOperApi) GetOperLog(rc *ctx.ReqCtx) {
|
||||
// @Param operId path string true "以逗号(,)分割的operId"
|
||||
// @Success 200 {string} string "{"code": 200, "message": "删除成功"}"
|
||||
// @Success 200 {string} string "{"code": 400, "message": "删除失败"}"
|
||||
// @Router /system/log/logOper/{operId} [delete]
|
||||
// @Router /log/logOper/{operId} [delete]
|
||||
func (l *LogOperApi) DeleteOperLog(rc *ctx.ReqCtx) {
|
||||
operIds := rc.GinCtx.Param("operId")
|
||||
group := utils.IdsStrToIdsIntGroup(operIds)
|
||||
@@ -70,7 +70,7 @@ func (l *LogOperApi) DeleteOperLog(rc *ctx.ReqCtx) {
|
||||
// @Tags 操作日志
|
||||
// @Success 200 {string} string "{"code": 200, "message": "删除成功"}"
|
||||
// @Success 200 {string} string "{"code": 400, "message": "删除失败"}"
|
||||
// @Router /system/log/logOper/all [delete]
|
||||
// @Router /log/logOper/all [delete]
|
||||
func (l *LogOperApi) DeleteAll(rc *ctx.ReqCtx) {
|
||||
l.LogOperApp.DeleteAll()
|
||||
}
|
||||
|
||||
16
apps/log/entity/log_job.go
Normal file
16
apps/log/entity/log_job.go
Normal file
@@ -0,0 +1,16 @@
|
||||
package entity
|
||||
|
||||
import (
|
||||
"pandax/base/model"
|
||||
)
|
||||
|
||||
type LogJob struct {
|
||||
LogId int64 `json:"logId" gorm:"primary_key;AUTO_INCREMENT"` //主键
|
||||
Name string `json:"name" gorm:"type:varchar(128);comment:任务名称"`
|
||||
JobGroup string `json:"jobGroup" gorm:"type:varchar(128);comment:分组"`
|
||||
EntryId int `json:"entryId" gorm:"type:int(11);comment:任务id"`
|
||||
InvokeTarget string `json:"invokeTarget" gorm:"type:varchar(128);comment:调用方法"`
|
||||
LogInfo string `json:"logInfo" gorm:"type:varchar(255);comment:日志信息"`
|
||||
Status string `json:"status" gorm:"type:varchar(1);comment:状态"`
|
||||
model.BaseModel
|
||||
}
|
||||
@@ -29,7 +29,7 @@ func InitLogRouter(router *gin.RouterGroup) {
|
||||
ctx.NewReqCtxWithGin(c).WithLog(updateLogLoginLog).Handle(login.UpdateLoginLog)
|
||||
})
|
||||
|
||||
deleteLogLoginAllLog := ctx.NewLogInfo("删除登录日志信息")
|
||||
deleteLogLoginAllLog := ctx.NewLogInfo("清空登录日志信息")
|
||||
logLogin.DELETE("all", func(c *gin.Context) {
|
||||
ctx.NewReqCtxWithGin(c).WithLog(deleteLogLoginAllLog).Handle(login.DeleteAll)
|
||||
})
|
||||
@@ -55,7 +55,7 @@ func InitLogRouter(router *gin.RouterGroup) {
|
||||
ctx.NewReqCtxWithGin(c).WithLog(getLogOperLog).Handle(oper.GetOperLog)
|
||||
})
|
||||
|
||||
deleteLogOperAllLog := ctx.NewLogInfo("删除操作日志信息")
|
||||
deleteLogOperAllLog := ctx.NewLogInfo("清空操作日志信息")
|
||||
logOper.DELETE("all", func(c *gin.Context) {
|
||||
ctx.NewReqCtxWithGin(c).WithLog(deleteLogOperAllLog).Handle(oper.DeleteAll)
|
||||
})
|
||||
@@ -64,4 +64,25 @@ func InitLogRouter(router *gin.RouterGroup) {
|
||||
logOper.DELETE(":operId", func(c *gin.Context) {
|
||||
ctx.NewReqCtxWithGin(c).WithLog(deleteLogOperLog).Handle(oper.DeleteOperLog)
|
||||
})
|
||||
|
||||
// Job日志
|
||||
job := &api.LogJobApi{
|
||||
LogJobApp: services.LogJobModelDao,
|
||||
}
|
||||
logJob := router.Group("logJob")
|
||||
|
||||
logJobListLog := ctx.NewLogInfo("获取操作日志列表")
|
||||
logJob.GET("list", func(c *gin.Context) {
|
||||
ctx.NewReqCtxWithGin(c).WithLog(logJobListLog).Handle(job.GetJobLogList)
|
||||
})
|
||||
|
||||
deleteLogJobAllLog := ctx.NewLogInfo("清空操作日志信息")
|
||||
logJob.DELETE("all", func(c *gin.Context) {
|
||||
ctx.NewReqCtxWithGin(c).WithLog(deleteLogJobAllLog).Handle(job.DeleteAll)
|
||||
})
|
||||
|
||||
deleteLogJobLog := ctx.NewLogInfo("删除操作日志信息")
|
||||
logJob.DELETE(":logId", func(c *gin.Context) {
|
||||
ctx.NewReqCtxWithGin(c).WithLog(deleteLogJobLog).Handle(job.DeleteJobLog)
|
||||
})
|
||||
}
|
||||
|
||||
61
apps/log/services/log_job.go
Normal file
61
apps/log/services/log_job.go
Normal file
@@ -0,0 +1,61 @@
|
||||
package services
|
||||
|
||||
import (
|
||||
"pandax/apps/log/entity"
|
||||
"pandax/base/biz"
|
||||
"pandax/base/global"
|
||||
)
|
||||
|
||||
type (
|
||||
LogJobModel interface {
|
||||
Insert(data entity.LogJob) *entity.LogJob
|
||||
FindListPage(page, pageSize int, data entity.LogJob) (*[]entity.LogJob, int64)
|
||||
Delete(infoId []int64)
|
||||
DeleteAll()
|
||||
}
|
||||
|
||||
logJobModelImpl struct {
|
||||
table string
|
||||
}
|
||||
)
|
||||
|
||||
var LogJobModelDao LogJobModel = &logJobModelImpl{
|
||||
table: `log_jobs`,
|
||||
}
|
||||
|
||||
func (m *logJobModelImpl) Insert(data entity.LogJob) *entity.LogJob {
|
||||
global.Db.Table(m.table).Create(&data)
|
||||
return &data
|
||||
}
|
||||
|
||||
func (m *logJobModelImpl) FindListPage(page, pageSize int, data entity.LogJob) (*[]entity.LogJob, int64) {
|
||||
list := make([]entity.LogJob, 0)
|
||||
var total int64 = 0
|
||||
offset := pageSize * (page - 1)
|
||||
db := global.Db.Table(m.table)
|
||||
// 此处填写 where参数判断
|
||||
if data.Status != "" {
|
||||
db = db.Where("status = ?", data.Status)
|
||||
}
|
||||
if data.JobGroup != "" {
|
||||
db = db.Where("job_group = ?", data.JobGroup)
|
||||
}
|
||||
if data.Name != "" {
|
||||
db = db.Where("name like ?", "%"+data.Name+"%")
|
||||
}
|
||||
err := db.Where("`delete_time` IS NULL").Count(&total).Error
|
||||
err = db.Order("log_id desc").Limit(pageSize).Offset(offset).Find(&list).Error
|
||||
|
||||
biz.ErrIsNil(err, "查询登录分页日志信息失败")
|
||||
return &list, total
|
||||
}
|
||||
|
||||
func (m *logJobModelImpl) Delete(logIds []int64) {
|
||||
err := global.Db.Table(m.table).Delete(&entity.LogJob{}, "`log_id` in (?)", logIds).Error
|
||||
biz.ErrIsNil(err, "删除登录日志信息失败")
|
||||
return
|
||||
}
|
||||
|
||||
func (m *logJobModelImpl) DeleteAll() {
|
||||
global.Db.Exec("DELETE FROM log_jobs")
|
||||
}
|
||||
Reference in New Issue
Block a user