db数据管理
This commit is contained in:
parent
afcd977b0c
commit
22dc1bbcc6
|
@ -27,3 +27,15 @@ func DbAdd(c *gin.Context) {
|
||||||
err := db_service.DbAdd(request)
|
err := db_service.DbAdd(request)
|
||||||
controllers.HandRes(c, nil, err)
|
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 {
|
type DbListRequest struct {
|
||||||
entities.PageRequest
|
entities.PageRequest
|
||||||
DbName string `json:"db_name" form:"db_name" example:""`
|
DbName string `json:"db_name" form:"db_name" example:""`
|
||||||
Status int `json:"status" form:"status" example:"1"`
|
Status int `json:"status" form:"status" example:"1"`
|
||||||
DbType string `json:"db_type" form:"db_type" example:"mysql"`
|
DbType string `json:"db_type" form:"db_type" example:"mysql"`
|
||||||
|
DbPermission int `json:"db_permission" form:"db_permission" example:"1"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type DbListResponse struct {
|
type DbListResponse struct {
|
||||||
DbId string `json:"db_id"`
|
DbId int `json:"db_id"`
|
||||||
DbName string `json:"db_name"`
|
DbName string `json:"db_name"`
|
||||||
DbType string `json:"db_type"`
|
DbType string `json:"db_type"`
|
||||||
Status int `json:"status"`
|
Status int `json:"status"`
|
||||||
DbPermission int `json:"db_permission"`
|
DbPermission int `json:"db_permission"`
|
||||||
Source string `json:"source"`
|
|
||||||
Desc string `json:"desc"`
|
Desc string `json:"desc"`
|
||||||
CreateTime string `json:"create_time"`
|
CreateTime string `json:"create_time"`
|
||||||
}
|
}
|
||||||
|
@ -28,3 +28,17 @@ type DbAddRequest struct {
|
||||||
Desc string `json:"desc" form:"desc" example:""`
|
Desc string `json:"desc" form:"desc" example:""`
|
||||||
Status int `json:"status" form:"status" example:"1"`
|
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/list": func() interface{} { return new(backend.DbListRequest) },
|
||||||
common.ADMIN_OAUTH_V1 + "/sql/add": func() interface{} { return new(backend.DbAddRequest) },
|
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("/list", backend.DbList)
|
||||||
sql.POST("/add", backend.DbAdd)
|
sql.POST("/add", backend.DbAdd)
|
||||||
|
sql.POST("/edit", backend.DbEdit)
|
||||||
|
sql.DELETE("/del", backend.DbDel)
|
||||||
}
|
}
|
||||||
//任务
|
//任务
|
||||||
cmd := v1.Group("/cmd")
|
cmd := v1.Group("/cmd")
|
||||||
|
|
|
@ -13,15 +13,16 @@ var (
|
||||||
|
|
||||||
// 实体
|
// 实体
|
||||||
type CronDb struct {
|
type CronDb struct {
|
||||||
DbId string `xorm:"'db_id' UNSIGNED INT"`
|
DbId int `xorm:"'db_id' UNSIGNED INT pk autoincr"`
|
||||||
DbName string `xorm:"'db_name' varchar(20)"`
|
DbName string `xorm:"'db_name' varchar(20)"`
|
||||||
DbType string `xorm:"'db_type' varchar(10)"`
|
DbType string `xorm:"'db_type' varchar(10)"`
|
||||||
DbPermission int `xorm:"'db_permission' TINYINT"`
|
DbPermission int `xorm:"'db_permission' TINYINT"`
|
||||||
Source string `xorm:"'source' varchar(150)"`
|
Source string `xorm:"'source' varchar(150)"`
|
||||||
Desc string `xorm:"'desc' varchar(200)"`
|
Desc string `xorm:"'desc' varchar(200)"`
|
||||||
CreateTime time.Time `xorm:"'create_time' datetime"`
|
CreateTime *time.Time `xorm:"'create_time' created datetime"`
|
||||||
UpdateTime time.Time `xorm:"'update_time' timestamp"`
|
UpdateTime time.Time `xorm:"'update_time' updated timestamp"`
|
||||||
Status int `xorm:"'status' TINYINT"`
|
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 {
|
if page != 0 && limit != 0 {
|
||||||
session = session.Limit(limit, (page-1)*limit)
|
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 {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -37,3 +40,15 @@ func DbAdd(request *backend.DbAddRequest) (err error) {
|
||||||
_, err = crondbmodel.GetInstance().GetDb().InsertOne(db)
|
_, err = crondbmodel.GetInstance().GetDb().InsertOne(db)
|
||||||
return
|
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