任务模块
This commit is contained in:
parent
ef73d1ac2b
commit
ed3e3291ee
|
@ -0,0 +1,44 @@
|
|||
package backend
|
||||
|
||||
import (
|
||||
"cron_admin/app/constants/errorcode"
|
||||
"cron_admin/app/http/controllers"
|
||||
"cron_admin/app/http/entities/backend"
|
||||
"cron_admin/app/models/cronusermodel"
|
||||
cmd_services "cron_admin/app/services/cmd_service"
|
||||
"github.com/ahmetb/go-linq/v3"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func CmdList(c *gin.Context) {
|
||||
request := controllers.GetRequest(c).(*backend.CmdListRequest)
|
||||
count, list, err := cmd_services.GetListByWhere(request, request.Page, request.Limit)
|
||||
if err != nil {
|
||||
controllers.HandRes(c, nil, errorcode.NotFound)
|
||||
} else {
|
||||
ulist := make([]backend.UserListResponse, 0)
|
||||
linq.From(list).SelectT(func(in cronusermodel.CronUser) (d backend.UserListResponse) {
|
||||
d.ResponseFromDb(in)
|
||||
return d
|
||||
}).ToSlice(&ulist)
|
||||
controllers.HandRes(c, gin.H{"data": ulist, "count": count}, err)
|
||||
}
|
||||
}
|
||||
|
||||
func CmdAdd(c *gin.Context) {
|
||||
request := controllers.GetRequest(c).(*backend.CmdAddRequest)
|
||||
err := cmd_services.UserAdd(request)
|
||||
controllers.HandRes(c, nil, err)
|
||||
}
|
||||
|
||||
func CmdEdit(c *gin.Context) {
|
||||
request := controllers.GetRequest(c).(*backend.CmdEditRequest)
|
||||
err := cmd_services.UserEdit(request)
|
||||
controllers.HandRes(c, nil, err)
|
||||
}
|
||||
|
||||
func CmdDel(c *gin.Context) {
|
||||
request := controllers.GetRequest(c).(*backend.CmdDeleteRequest)
|
||||
err := cmd_services.UserDel(request)
|
||||
controllers.HandRes(c, nil, err)
|
||||
}
|
|
@ -5,14 +5,14 @@ import (
|
|||
"cron_admin/app/http/controllers"
|
||||
"cron_admin/app/http/entities/backend"
|
||||
"cron_admin/app/models/cronusermodel"
|
||||
"cron_admin/app/services"
|
||||
user_services "cron_admin/app/services/user_service"
|
||||
"github.com/ahmetb/go-linq/v3"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func UserList(c *gin.Context) {
|
||||
request := controllers.GetRequest(c).(*backend.UserListRequest)
|
||||
count, list, err := services.GetListByWhere(request, request.Page, request.Limit)
|
||||
count, list, err := user_services.GetListByWhere(request, request.Page, request.Limit)
|
||||
if err != nil {
|
||||
controllers.HandRes(c, nil, errorcode.NotFound)
|
||||
} else {
|
||||
|
@ -27,18 +27,18 @@ func UserList(c *gin.Context) {
|
|||
|
||||
func UserAdd(c *gin.Context) {
|
||||
request := controllers.GetRequest(c).(*backend.UserAddRequest)
|
||||
err := services.UserAdd(request)
|
||||
err := user_services.UserAdd(request)
|
||||
controllers.HandRes(c, nil, err)
|
||||
}
|
||||
|
||||
func UserEdit(c *gin.Context) {
|
||||
request := controllers.GetRequest(c).(*backend.UserEditRequest)
|
||||
err := services.UserEdit(request)
|
||||
err := user_services.UserEdit(request)
|
||||
controllers.HandRes(c, nil, err)
|
||||
}
|
||||
|
||||
func UserDel(c *gin.Context) {
|
||||
request := controllers.GetRequest(c).(*backend.UserDeleteRequest)
|
||||
err := services.UserDel(request)
|
||||
err := user_services.UserDel(request)
|
||||
controllers.HandRes(c, nil, err)
|
||||
}
|
||||
|
|
|
@ -0,0 +1,103 @@
|
|||
package backend
|
||||
|
||||
import (
|
||||
"cron_admin/app/models/croncmdmodel"
|
||||
"time"
|
||||
)
|
||||
|
||||
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"`
|
||||
}
|
||||
|
||||
type CmdInfoRequest struct {
|
||||
CmdId int `json:"cmd_id" form:"cmd_id" validate:"required" example:"1"`
|
||||
}
|
||||
|
||||
type CmdListResponse struct {
|
||||
CmdId string `json:"cmd_id"`
|
||||
CmdName string `json:"cmd_name"`
|
||||
UserIds string `json:"user_ids"`
|
||||
EntryId int `json:"entry_id"`
|
||||
ReadDbId int `json:"read_db_id"`
|
||||
WriteDbId int `json:"write_db_id"`
|
||||
ExecuteType int `json:"execute_type"`
|
||||
ExecuteRead string `json:"execute_read"`
|
||||
ExecuteWrite string `json:"execute_write"`
|
||||
Cron string `json:"cron"`
|
||||
MatchJson string `json:"match_json"`
|
||||
SendTimeType int `json:"send_time_type"`
|
||||
SendLimit int `json:"send_limit"`
|
||||
ReportChannelId int `json:"report_channel_id"`
|
||||
CreateTime string `json:"create_time"`
|
||||
UpdateTime string `json:"update_time"`
|
||||
Status int `json:"status"`
|
||||
FailReason string `json:"fail_reason"`
|
||||
Users []*UserListResponse `json:"users"`
|
||||
ReadDb DbListResponse `json:"read_db"`
|
||||
WriteDb DbListResponse `json:"write_db"`
|
||||
ReportChannel ReportChannelListResponse `json:"report_channel"`
|
||||
}
|
||||
|
||||
type CmdAddRequest struct {
|
||||
CmdName string `json:"cmd_name"`
|
||||
UserIds string `json:"user_ids"`
|
||||
ReadDbId int `json:"read_db_id"`
|
||||
WriteDbId int `json:"write_db_id"`
|
||||
ExecuteType int `json:"execute_type"`
|
||||
ExecuteRead string `json:"execute_read"`
|
||||
ExecuteWrite string `json:"execute_write"`
|
||||
Cron string `json:"cron"`
|
||||
MatchJson string `json:"match_json"`
|
||||
SendTimeType int `json:"send_time_type"`
|
||||
SendLimit int `json:"send_limit"`
|
||||
ReportChannelId int `json:"report_channel_id"`
|
||||
}
|
||||
|
||||
type CmdEditRequest struct {
|
||||
CmdId int `json:"cmd_id" validate:"required" form:"cmd_id" example:""`
|
||||
CmdName string `json:"cmd_name"`
|
||||
UserIds string `json:"user_ids"`
|
||||
ReadDbId int `json:"read_db_id"`
|
||||
WriteDbId int `json:"write_db_id"`
|
||||
ExecuteType int `json:"execute_type"`
|
||||
ExecuteRead string `json:"execute_read"`
|
||||
ExecuteWrite string `json:"execute_write"`
|
||||
Cron string `json:"cron"`
|
||||
MatchJson string `json:"match_json"`
|
||||
SendTimeType int `json:"send_time_type"`
|
||||
SendLimit int `json:"send_limit"`
|
||||
ReportChannelId int `json:"report_channel_id"`
|
||||
}
|
||||
|
||||
type CmdDeleteRequest struct {
|
||||
CmdId int `json:"user_id" validate:"required" form:"user_id" example:""`
|
||||
}
|
||||
|
||||
func (response *CmdListResponse) ResponseFromDb(l croncmdmodel.CronCmd) {
|
||||
response.CmdId = l.CmdId
|
||||
response.CmdName = l.CmdName
|
||||
response.UserIds = l.UserIds
|
||||
response.Status = l.Status
|
||||
response.ReadDbId = l.ReadDbId
|
||||
response.WriteDbId = l.WriteDbId
|
||||
response.ExecuteType = l.ExecuteType
|
||||
response.ExecuteRead = l.ExecuteRead
|
||||
response.ExecuteWrite = l.ExecuteWrite
|
||||
response.Cron = l.Cron
|
||||
response.MatchJson = l.MatchJson
|
||||
response.SendTimeType = l.SendTimeType
|
||||
response.SendLimit = l.SendLimit
|
||||
response.ReportChannelId = l.ReportChannelId
|
||||
response.CreateTime = l.CreateTime.Format(time.DateTime)
|
||||
response.UpdateTime = l.UpdateTime.Format(time.DateTime)
|
||||
response.FailReason = l.FailReason
|
||||
|
||||
//cronusermodel.GetInstance().GetDb().Where("user_id IN (?)", strings.Join(strings.Split(l.UserIds, ","), ",")).Find(&response.Users)
|
||||
//crond.GetInstance().GetDb().Where("user_id = ?", strings.Join(strings.Split(l.UserIds, ","), ",")).Find(&response.Users)
|
||||
return
|
||||
|
||||
}
|
|
@ -13,25 +13,25 @@ var (
|
|||
|
||||
// 实体
|
||||
type CronCmd struct {
|
||||
CmdId string `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)"`
|
||||
ReadDbId int `xorm:"'read_db_id' int(10)"`
|
||||
WriteDbId int `xorm:"'write_db_id' int(11)"`
|
||||
ExecuteType int `xorm:"'execute_type' TINYINT"`
|
||||
ExecuteRead string `xorm:"'execute_read' TEXT"`
|
||||
ExecuteWrite string `xorm:"'execute_write' TEXT"`
|
||||
Cron string `xorm:"'cron' varchar(64)"`
|
||||
MatchJson string `xorm:"'match_json' JSON"`
|
||||
SendTimeType int `xorm:"'send_time_type' TINYINT"`
|
||||
SendLimit int `xorm:"'send_limit' SMALLINT"`
|
||||
ReportChannelId int `xorm:"'report_channel_id' int(11)"`
|
||||
CreateTime time.Time `xorm:"'create_time' datetime"`
|
||||
UpdateTime time.Time `xorm:"'update_time' timestamp"`
|
||||
Status int `xorm:"'status' TINYINT"`
|
||||
FailReason string `xorm:"'fail_reason' varchar(200)"`
|
||||
DeletedTime time.Time `xorm:"'deleted_time' datetime"`
|
||||
CmdId string `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)"`
|
||||
ReadDbId int `xorm:"'read_db_id' int(10)"`
|
||||
WriteDbId int `xorm:"'write_db_id' int(11)"`
|
||||
ExecuteType int `xorm:"'execute_type' TINYINT"`
|
||||
ExecuteRead string `xorm:"'execute_read' TEXT"`
|
||||
ExecuteWrite string `xorm:"'execute_write' TEXT"`
|
||||
Cron string `xorm:"'cron' varchar(64)"`
|
||||
MatchJson string `xorm:"'match_json' JSON"`
|
||||
SendTimeType int `xorm:"'send_time_type' TINYINT"`
|
||||
SendLimit int `xorm:"'send_limit' SMALLINT"`
|
||||
ReportChannelId int `xorm:"'report_channel_id' int(11)"`
|
||||
CreateTime *time.Time `xorm:"'create_time' datetime"`
|
||||
UpdateTime time.Time `xorm:"'update_time' timestamp"`
|
||||
Status int `xorm:"'status' TINYINT"`
|
||||
FailReason string `xorm:"'fail_reason' varchar(200)"`
|
||||
DeletedTime time.Time `xorm:"'deleted_time' datetime"`
|
||||
}
|
||||
|
||||
// 表名
|
||||
|
|
|
@ -0,0 +1,56 @@
|
|||
package cmd_services
|
||||
|
||||
import (
|
||||
"cron_admin/app/constants/common"
|
||||
"cron_admin/app/http/entities/backend"
|
||||
"cron_admin/app/models/croncmdmodel"
|
||||
|
||||
"cron_admin/app/utils/mapstructure"
|
||||
"xorm.io/builder"
|
||||
)
|
||||
|
||||
func GetListByWhere(request *backend.CmdListRequest, page int, limit int) (count int64, cmdListInfo []croncmdmodel.CronCmd, err error) {
|
||||
cond := builder.NewCond()
|
||||
|
||||
if request.CmdName != "" {
|
||||
cond = cond.And(builder.Like{"cmd_name", request.CmdName})
|
||||
}
|
||||
if request.Status != 0 {
|
||||
cond = cond.And(builder.Eq{"status": request.Status})
|
||||
}
|
||||
if request.ExecuteType != 0 {
|
||||
cond = cond.And(builder.Eq{"status": request.Status})
|
||||
}
|
||||
|
||||
session := croncmdmodel.GetInstance().GetDb().Where(cond)
|
||||
|
||||
if page != 0 && limit != 0 {
|
||||
session = session.Limit(page, (page-1)*limit)
|
||||
}
|
||||
count, err = session.FindAndCount(&cmdListInfo)
|
||||
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func UserAdd(request *backend.CmdAddRequest) (err error) {
|
||||
var db croncmdmodel.CronCmd
|
||||
_ = mapstructure.Decode(request, &db)
|
||||
db.Status = common.STATUS_ENABLE
|
||||
_, err = croncmdmodel.GetInstance().GetDb().InsertOne(db)
|
||||
return
|
||||
}
|
||||
|
||||
func UserEdit(request *backend.CmdEditRequest) (err error) {
|
||||
var db croncmdmodel.CronCmd
|
||||
_ = mapstructure.Decode(request, &db)
|
||||
_, err = croncmdmodel.GetInstance().GetDb().ID(request.CmdId).Update(&db)
|
||||
return
|
||||
}
|
||||
|
||||
func UserDel(request *backend.CmdDeleteRequest) (err error) {
|
||||
_, err = croncmdmodel.GetInstance().GetDb().ID(request.CmdId).Delete(&croncmdmodel.CronCmd{})
|
||||
return
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package services
|
||||
package user_services
|
||||
|
||||
import (
|
||||
"cron_admin/app/constants/common"
|
Loading…
Reference in New Issue