55 lines
1.5 KiB
Go
55 lines
1.5 KiB
Go
package db_service
|
|
|
|
import (
|
|
"cron_admin/app/constants/common"
|
|
"cron_admin/app/http/entities/backend"
|
|
"cron_admin/app/models/crondbmodel"
|
|
"cron_admin/app/utils/mapstructure"
|
|
"xorm.io/builder"
|
|
)
|
|
|
|
func DbList(request *backend.DbListRequest, page int, limit int) (count int64, DbListInfo []crondbmodel.CronDb, err error) {
|
|
conn := builder.NewCond()
|
|
if request.DbName != "" {
|
|
conn = conn.And(builder.Like{"DbName", request.DbName})
|
|
}
|
|
if request.DbType != "" {
|
|
conn = conn.And(builder.Like{"DbType", request.DbType})
|
|
}
|
|
if request.Status != 0 {
|
|
conn = conn.And(builder.Eq{"Status": request.Status})
|
|
}
|
|
session := crondbmodel.GetInstance().GetDb().Where(conn)
|
|
if page != 0 && limit != 0 {
|
|
session = session.Limit(limit, (page-1)*limit)
|
|
}
|
|
if request.DbPermission != 0 {
|
|
session = session.And(builder.Eq{"DbPermission": request.DbPermission})
|
|
}
|
|
count, err = session.Omit("source", "UpdateTime").FindAndCount(&DbListInfo)
|
|
if err != nil {
|
|
return
|
|
}
|
|
return
|
|
}
|
|
|
|
func DbAdd(request *backend.DbAddRequest) (err error) {
|
|
var db crondbmodel.CronDb
|
|
_ = mapstructure.Decode(request, &db)
|
|
db.Status = common.STATUS_DISABLE
|
|
_, 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
|
|
}
|