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) } count, err = session.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 }