mirror of
https://gitee.com/XM-GO/PandaX.git
synced 2026-04-23 02:48:34 +08:00
[优化]base模块提出
This commit is contained in:
@@ -1,13 +1,13 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"github.com/XM-GO/PandaKit/biz"
|
||||
"github.com/XM-GO/PandaKit/restfulx"
|
||||
"github.com/XM-GO/PandaKit/utils"
|
||||
"pandax/apps/job/api/from"
|
||||
"pandax/apps/job/entity"
|
||||
"pandax/apps/job/jobs"
|
||||
"pandax/apps/job/services"
|
||||
"pandax/base/biz"
|
||||
"pandax/base/ginx"
|
||||
"pandax/base/utils"
|
||||
)
|
||||
|
||||
type JobApi struct {
|
||||
@@ -24,9 +24,9 @@ type JobApi struct {
|
||||
// @Success 200 {string} string "{"code": 400, "message": "添加失败"}"
|
||||
// @Router /job/job [post]
|
||||
// @Security X-TOKEN
|
||||
func (j *JobApi) CreateJob(rc *ginx.ReqCtx) {
|
||||
func (j *JobApi) CreateJob(rc *restfulx.ReqCtx) {
|
||||
var job entity.SysJob
|
||||
ginx.BindJsonAndValid(rc.GinCtx, &job)
|
||||
restfulx.BindJsonAndValid(rc.GinCtx, &job)
|
||||
|
||||
job.CreateBy = rc.LoginAccount.UserName
|
||||
j.JobApp.Insert(job)
|
||||
@@ -43,9 +43,9 @@ func (j *JobApi) CreateJob(rc *ginx.ReqCtx) {
|
||||
// @Success 200 {string} string "{"code": 200, "data": [...]}"
|
||||
// @Router /job/list [get]
|
||||
// @Security
|
||||
func (j *JobApi) GetJobList(rc *ginx.ReqCtx) {
|
||||
pageNum := ginx.QueryInt(rc.GinCtx, "pageNum", 1)
|
||||
pageSize := ginx.QueryInt(rc.GinCtx, "pageSize", 10)
|
||||
func (j *JobApi) GetJobList(rc *restfulx.ReqCtx) {
|
||||
pageNum := restfulx.QueryInt(rc.GinCtx, "pageNum", 1)
|
||||
pageSize := restfulx.QueryInt(rc.GinCtx, "pageSize", 10)
|
||||
jobName := rc.GinCtx.Query("jobName")
|
||||
jobGroup := rc.GinCtx.Query("jobGroup")
|
||||
status := rc.GinCtx.Query("status")
|
||||
@@ -66,8 +66,8 @@ func (j *JobApi) GetJobList(rc *ginx.ReqCtx) {
|
||||
// @Success 200 {string} string "{"code": 200, "data": [...]}"
|
||||
// @Router /job/{jobId} [get]
|
||||
// @Security
|
||||
func (j *JobApi) GetJob(rc *ginx.ReqCtx) {
|
||||
jobId := ginx.PathParamInt(rc.GinCtx, rc.GinCtx.Param("jobId"))
|
||||
func (j *JobApi) GetJob(rc *restfulx.ReqCtx) {
|
||||
jobId := restfulx.PathParamInt(rc.GinCtx, rc.GinCtx.Param("jobId"))
|
||||
rc.ResData = j.JobApp.FindOne(int64(jobId))
|
||||
}
|
||||
|
||||
@@ -81,9 +81,9 @@ func (j *JobApi) GetJob(rc *ginx.ReqCtx) {
|
||||
// @Success 200 {string} string "{"code": 400, "message": "添加失败"}"
|
||||
// @Router /job [put]
|
||||
// @Security X-TOKEN
|
||||
func (l *JobApi) UpdateJob(rc *ginx.ReqCtx) {
|
||||
func (l *JobApi) UpdateJob(rc *restfulx.ReqCtx) {
|
||||
var job entity.SysJob
|
||||
ginx.BindJsonAndValid(rc.GinCtx, &job)
|
||||
restfulx.BindJsonAndValid(rc.GinCtx, &job)
|
||||
l.JobApp.Update(job)
|
||||
}
|
||||
|
||||
@@ -94,7 +94,7 @@ func (l *JobApi) UpdateJob(rc *ginx.ReqCtx) {
|
||||
// @Success 200 {string} string "{"code": 200, "message": "删除成功"}"
|
||||
// @Success 200 {string} string "{"code": 400, "message": "删除失败"}"
|
||||
// @Router /job/{jobId} [delete]
|
||||
func (l *JobApi) DeleteJob(rc *ginx.ReqCtx) {
|
||||
func (l *JobApi) DeleteJob(rc *restfulx.ReqCtx) {
|
||||
jobIds := rc.GinCtx.Param("jobId")
|
||||
group := utils.IdsStrToIdsIntGroup(jobIds)
|
||||
l.JobApp.Delete(group)
|
||||
@@ -107,8 +107,8 @@ func (l *JobApi) DeleteJob(rc *ginx.ReqCtx) {
|
||||
// @Success 200 {string} string "{"code": 200, "message": "删除成功"}"
|
||||
// @Success 200 {string} string "{"code": 400, "message": "删除失败"}"
|
||||
// @Router /job/stop/{jobId} [get]
|
||||
func (l *JobApi) StopJobForService(rc *ginx.ReqCtx) {
|
||||
jobId := ginx.PathParamInt(rc.GinCtx, "jobId")
|
||||
func (l *JobApi) StopJobForService(rc *restfulx.ReqCtx) {
|
||||
jobId := restfulx.PathParamInt(rc.GinCtx, "jobId")
|
||||
job := l.JobApp.FindOne(int64(jobId))
|
||||
jobs.Remove(jobs.Crontab, job.EntryId)
|
||||
}
|
||||
@@ -119,8 +119,8 @@ func (l *JobApi) StopJobForService(rc *ginx.ReqCtx) {
|
||||
// @Success 200 {string} string "{"code": 200, "message": "删除成功"}"
|
||||
// @Success 200 {string} string "{"code": 400, "message": "删除失败"}"
|
||||
// @Router /job/stop/{jobId} [get]
|
||||
func (l *JobApi) StartJobForService(rc *ginx.ReqCtx) {
|
||||
jobId := ginx.PathParamInt(rc.GinCtx, "jobId")
|
||||
func (l *JobApi) StartJobForService(rc *restfulx.ReqCtx) {
|
||||
jobId := restfulx.PathParamInt(rc.GinCtx, "jobId")
|
||||
job := l.JobApp.FindOne(int64(jobId))
|
||||
|
||||
biz.IsTrue(job.Status == "0", "以关闭的任务不能开启")
|
||||
@@ -162,9 +162,9 @@ func (l *JobApi) StartJobForService(rc *ginx.ReqCtx) {
|
||||
// @Success 200 {string} string "{"code": 400, "message": "添加失败"}"
|
||||
// @Router /job/changeStatus [put]
|
||||
// @Security X-TOKEN
|
||||
func (l *JobApi) UpdateStatusJob(rc *ginx.ReqCtx) {
|
||||
func (l *JobApi) UpdateStatusJob(rc *restfulx.ReqCtx) {
|
||||
var job from.JobStatus
|
||||
ginx.BindJsonAndValid(rc.GinCtx, &job)
|
||||
restfulx.BindJsonAndValid(rc.GinCtx, &job)
|
||||
|
||||
l.JobApp.Update(entity.SysJob{JobId: job.JobId, Status: job.Status})
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package entity
|
||||
|
||||
import "pandax/base/model"
|
||||
import "github.com/XM-GO/PandaKit/model"
|
||||
|
||||
type SysJob struct {
|
||||
JobId int64 `json:"jobId" gorm:"primaryKey;autoIncrement"` // 编码
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
logEntity "pandax/apps/log/entity"
|
||||
logServices "pandax/apps/log/services"
|
||||
|
||||
"pandax/base/httpclient"
|
||||
"github.com/XM-GO/PandaKit/httpclient"
|
||||
"pandax/pkg/global"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package router
|
||||
|
||||
import (
|
||||
"github.com/XM-GO/PandaKit/restfulx"
|
||||
"github.com/gin-gonic/gin"
|
||||
"pandax/apps/job/api"
|
||||
"pandax/apps/job/services"
|
||||
"pandax/base/ginx"
|
||||
)
|
||||
|
||||
func InitJobRouter(router *gin.RouterGroup) {
|
||||
@@ -15,34 +15,34 @@ func InitJobRouter(router *gin.RouterGroup) {
|
||||
job := router.Group("")
|
||||
|
||||
job.GET("list", func(c *gin.Context) {
|
||||
ginx.NewReqCtx(c).WithLog("获取Job列表").Handle(jobApi.GetJobList)
|
||||
restfulx.NewReqCtx(c).WithLog("获取Job列表").Handle(jobApi.GetJobList)
|
||||
})
|
||||
|
||||
job.GET(":jobId", func(c *gin.Context) {
|
||||
ginx.NewReqCtx(c).WithLog("获取Job信息").Handle(jobApi.GetJob)
|
||||
restfulx.NewReqCtx(c).WithLog("获取Job信息").Handle(jobApi.GetJob)
|
||||
})
|
||||
|
||||
job.POST("", func(c *gin.Context) {
|
||||
ginx.NewReqCtx(c).WithLog("添加Job信息").Handle(jobApi.CreateJob)
|
||||
restfulx.NewReqCtx(c).WithLog("添加Job信息").Handle(jobApi.CreateJob)
|
||||
})
|
||||
|
||||
job.PUT("", func(c *gin.Context) {
|
||||
ginx.NewReqCtx(c).WithLog("修改Job信息").Handle(jobApi.UpdateJob)
|
||||
restfulx.NewReqCtx(c).WithLog("修改Job信息").Handle(jobApi.UpdateJob)
|
||||
})
|
||||
|
||||
job.DELETE(":jobId", func(c *gin.Context) {
|
||||
ginx.NewReqCtx(c).WithLog("删除Job信息").Handle(jobApi.DeleteJob)
|
||||
restfulx.NewReqCtx(c).WithLog("删除Job信息").Handle(jobApi.DeleteJob)
|
||||
})
|
||||
|
||||
job.GET("/stop/:jobId", func(c *gin.Context) {
|
||||
ginx.NewReqCtx(c).WithLog("停止一个job").Handle(jobApi.StopJobForService)
|
||||
restfulx.NewReqCtx(c).WithLog("停止一个job").Handle(jobApi.StopJobForService)
|
||||
})
|
||||
|
||||
job.GET("/start/:jobId", func(c *gin.Context) {
|
||||
ginx.NewReqCtx(c).WithLog("开启一个job").Handle(jobApi.StartJobForService)
|
||||
restfulx.NewReqCtx(c).WithLog("开启一个job").Handle(jobApi.StartJobForService)
|
||||
})
|
||||
|
||||
job.PUT("/changeStatus", func(c *gin.Context) {
|
||||
ginx.NewReqCtx(c).WithLog("修改状态").Handle(jobApi.UpdateStatusJob)
|
||||
restfulx.NewReqCtx(c).WithLog("修改状态").Handle(jobApi.UpdateStatusJob)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package services
|
||||
|
||||
import (
|
||||
"github.com/XM-GO/PandaKit/biz"
|
||||
"pandax/apps/job/entity"
|
||||
"pandax/base/biz"
|
||||
"pandax/pkg/global"
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user