db数据管理
This commit is contained in:
parent
afcd977b0c
commit
22dc1bbcc6
|
@ -27,3 +27,15 @@ func DbAdd(c *gin.Context) {
|
|||
err := db_service.DbAdd(request)
|
||||
controllers.HandRes(c, nil, err)
|
||||
}
|
||||
|
||||
func DbEdit(c *gin.Context) {
|
||||
request := controllers.GetRequest(c).(*backend.DbEditRequest)
|
||||
err := db_service.DbEdit(request)
|
||||
controllers.HandRes(c, nil, err)
|
||||
}
|
||||
|
||||
func DbDel(c *gin.Context) {
|
||||
request := controllers.GetRequest(c).(*backend.DbDeleteRequest)
|
||||
err := db_service.DbDel(request)
|
||||
controllers.HandRes(c, nil, err)
|
||||
}
|
||||
|
|
|
@ -4,18 +4,18 @@ import "cron_admin/app/http/entities"
|
|||
|
||||
type DbListRequest struct {
|
||||
entities.PageRequest
|
||||
DbName string `json:"db_name" form:"db_name" example:""`
|
||||
Status int `json:"status" form:"status" example:"1"`
|
||||
DbType string `json:"db_type" form:"db_type" example:"mysql"`
|
||||
DbName string `json:"db_name" form:"db_name" example:""`
|
||||
Status int `json:"status" form:"status" example:"1"`
|
||||
DbType string `json:"db_type" form:"db_type" example:"mysql"`
|
||||
DbPermission int `json:"db_permission" form:"db_permission" example:"1"`
|
||||
}
|
||||
|
||||
type DbListResponse struct {
|
||||
DbId string `json:"db_id"`
|
||||
DbId int `json:"db_id"`
|
||||
DbName string `json:"db_name"`
|
||||
DbType string `json:"db_type"`
|
||||
Status int `json:"status"`
|
||||
DbPermission int `json:"db_permission"`
|
||||
Source string `json:"source"`
|
||||
Desc string `json:"desc"`
|
||||
CreateTime string `json:"create_time"`
|
||||
}
|
||||
|
@ -28,3 +28,17 @@ type DbAddRequest struct {
|
|||
Desc string `json:"desc" form:"desc" example:""`
|
||||
Status int `json:"status" form:"status" example:"1"`
|
||||
}
|
||||
|
||||
type DbEditRequest struct {
|
||||
DbId int `json:"db_id" validate:"required" form:"db_id" example:""`
|
||||
DbName string `json:"db_name" validate:"required" form:"db_name" example:""`
|
||||
DbType string `json:"db_type" validate:"required" form:"db_type" example:"mysql"`
|
||||
DbPermission int `json:"db_permission" validate:"required" form:"db_permission" example:"1"`
|
||||
Source string `json:"source" validate:"required" form:"source" example:""`
|
||||
Desc string `json:"desc" form:"desc" example:""`
|
||||
Status int `json:"status" form:"status" example:"1"`
|
||||
}
|
||||
|
||||
type DbDeleteRequest struct {
|
||||
DbId int `json:"db_id" validate:"required" form:"db_id" example:""`
|
||||
}
|
||||
|
|
|
@ -9,4 +9,6 @@ var BackendRequestMap = map[string]func() interface{}{
|
|||
|
||||
common.ADMIN_OAUTH_V1 + "/sql/list": func() interface{} { return new(backend.DbListRequest) },
|
||||
common.ADMIN_OAUTH_V1 + "/sql/add": func() interface{} { return new(backend.DbAddRequest) },
|
||||
common.ADMIN_OAUTH_V1 + "/sql/edit": func() interface{} { return new(backend.DbEditRequest) },
|
||||
common.ADMIN_OAUTH_V1 + "/sql/del": func() interface{} { return new(backend.DbDeleteRequest) },
|
||||
}
|
||||
|
|
|
@ -40,6 +40,8 @@ func RegisterAdminRoute(router *gin.Engine) {
|
|||
{
|
||||
sql.POST("/list", backend.DbList)
|
||||
sql.POST("/add", backend.DbAdd)
|
||||
sql.POST("/edit", backend.DbEdit)
|
||||
sql.DELETE("/del", backend.DbDel)
|
||||
}
|
||||
//任务
|
||||
cmd := v1.Group("/cmd")
|
||||
|
|
|
@ -13,15 +13,16 @@ var (
|
|||
|
||||
// 实体
|
||||
type CronDb struct {
|
||||
DbId string `xorm:"'db_id' UNSIGNED INT"`
|
||||
DbName string `xorm:"'db_name' varchar(20)"`
|
||||
DbType string `xorm:"'db_type' varchar(10)"`
|
||||
DbPermission int `xorm:"'db_permission' TINYINT"`
|
||||
Source string `xorm:"'source' varchar(150)"`
|
||||
Desc string `xorm:"'desc' varchar(200)"`
|
||||
CreateTime time.Time `xorm:"'create_time' datetime"`
|
||||
UpdateTime time.Time `xorm:"'update_time' timestamp"`
|
||||
Status int `xorm:"'status' TINYINT"`
|
||||
DbId int `xorm:"'db_id' UNSIGNED INT pk autoincr"`
|
||||
DbName string `xorm:"'db_name' varchar(20)"`
|
||||
DbType string `xorm:"'db_type' varchar(10)"`
|
||||
DbPermission int `xorm:"'db_permission' TINYINT"`
|
||||
Source string `xorm:"'source' varchar(150)"`
|
||||
Desc string `xorm:"'desc' varchar(200)"`
|
||||
CreateTime *time.Time `xorm:"'create_time' created datetime"`
|
||||
UpdateTime time.Time `xorm:"'update_time' updated timestamp"`
|
||||
DeletedTime time.Time `xorm:"'deleted_time' deleted datetime"`
|
||||
Status int `xorm:"'status' TINYINT"`
|
||||
}
|
||||
|
||||
// 表名
|
||||
|
|
|
@ -23,7 +23,10 @@ func DbList(request *backend.DbListRequest, page int, limit int) (count int64, D
|
|||
if page != 0 && limit != 0 {
|
||||
session = session.Limit(limit, (page-1)*limit)
|
||||
}
|
||||
count, err = session.FindAndCount(&DbListInfo)
|
||||
if request.DbPermission != 0 {
|
||||
session = session.And(builder.Eq{"DbPermission": request.DbPermission})
|
||||
}
|
||||
count, err = session.Omit("source", "UpdateTime").FindAndCount(&DbListInfo)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
@ -37,3 +40,15 @@ func DbAdd(request *backend.DbAddRequest) (err error) {
|
|||
_, err = crondbmodel.GetInstance().GetDb().InsertOne(db)
|
||||
return
|
||||
}
|
||||
|
||||
func DbEdit(request *backend.DbEditRequest) (err error) {
|
||||
var db crondbmodel.CronDb
|
||||
_ = mapstructure.Decode(request, &db)
|
||||
_, err = crondbmodel.GetInstance().GetDb().ID(request.DbId).Update(&db)
|
||||
return
|
||||
}
|
||||
|
||||
func DbDel(request *backend.DbDeleteRequest) (err error) {
|
||||
_, err = crondbmodel.GetInstance().GetDb().ID(request.DbId).Delete(&crondbmodel.CronDb{})
|
||||
return
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue