config.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package v2
  2. import (
  3. "database/sql"
  4. "go-common/app/infra/config/model"
  5. "go-common/library/ecode"
  6. "go-common/library/log"
  7. )
  8. // UpdateConfValue update config state/
  9. func (d *Dao) UpdateConfValue(ID int64, value string) (err error) {
  10. err = d.DB.Model(&model.Config{ID: ID}).Where("state=?", model.ConfigIng).Update("comment", value).Error
  11. return
  12. }
  13. // UpdateConfState update config state/
  14. func (d *Dao) UpdateConfState(ID int64, state int8) (err error) {
  15. err = d.DB.Model(&model.Config{ID: ID}).Update("state", state).Error
  16. return
  17. }
  18. // ConfigsByIDs get Config by IDs.
  19. func (d *Dao) ConfigsByIDs(ids []int64) (confs []*model.Value, err error) {
  20. var rows *sql.Rows
  21. if rows, err = d.DB.Where(ids).Select("id,name,comment").Where("state = ?", model.ConfigEnd).Model(&model.Config{}).Rows(); err != nil {
  22. log.Error("ConfigsByIDs(%v) error(%v)", ids, err)
  23. return
  24. }
  25. defer rows.Close()
  26. for rows.Next() {
  27. v := new(model.Value)
  28. if err = rows.Scan(&v.ConfigID, &v.Name, &v.Config); err != nil {
  29. log.Error("ConfigsByIDs(%v) error(%v)", ids, err)
  30. return
  31. }
  32. confs = append(confs, v)
  33. }
  34. if len(confs) == 0 {
  35. err = ecode.NothingFound
  36. }
  37. return
  38. }