1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- package settings
- import (
- "github.com/astaxie/beego/logs"
- "github.com/astaxie/beego/orm"
- "nginx-ui/server/models"
- )
- type SettingService struct {
- }
- // Save 保存或者修改
- func (c *SettingService) Save(body *models.Setting) (*models.Setting, error) {
- o := orm.NewOrm()
- _, err := models.InsertOrUpdate[models.Setting](o, body)
- return body, err
- }
- // GetList 获取全部组织
- func (c *SettingService) GetList(vo ListVo) ([]models.Setting, error) {
- o := orm.NewOrm()
- qs := o.QueryTable(&models.Setting{})
- if vo.Prefix != "" {
- qs.FilterRaw("config_key LIKE '?%'", vo.Prefix)
- }
- if vo.Enable > -1 {
- qs.Filter("Enable", vo.Enable)
- }
- qs.OrderBy("-Id")
- var list []models.Setting
- _, err := qs.All(&list)
- if err != nil {
- return nil, err
- }
- return list, nil
- }
- // Delete 获取全部组织
- func (c *SettingService) Delete(id int) error {
- o := orm.NewOrm()
- _, err := o.Delete(&models.Setting{Id: id})
- return err
- }
- var SettingSrv = new(SettingService)
- // GetSettings 根据前缀获取设置
- func GetSettings(prefix string) []models.Setting {
- list, err := SettingSrv.GetList(ListVo{Prefix: prefix, Enable: 1})
- if err != nil {
- logs.Error("get setting list error:", err)
- return make([]models.Setting, 0)
- }
- return list
- }
|