sys_config.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. package models
  2. import (
  3. "fmt"
  4. "github.com/beego/beego/v2/client/orm"
  5. "time"
  6. )
  7. // SysConfig 系统配置表
  8. type SysConfig struct {
  9. ConfigId int `orm:"column(config_id);pk"`
  10. ConfigCode string `description:"配置编码"`
  11. ConfigValue string `description:"配置值"`
  12. Remark string `description:"备注信息"`
  13. CreateTime time.Time `description:"创建时间"`
  14. ModifyTime time.Time `description:"更新时间"`
  15. }
  16. func (m *SysConfig) TableName() string {
  17. return "sys_config"
  18. }
  19. type SysConfigCols struct {
  20. PrimaryId string
  21. ConfigCode string
  22. ConfigValue string
  23. Remark string
  24. CreateTime string
  25. ModifyTime string
  26. }
  27. func (m *SysConfig) Cols() SysConfigCols {
  28. return SysConfigCols{
  29. PrimaryId: "config_id",
  30. ConfigCode: "config_code",
  31. ConfigValue: "config_value",
  32. Remark: "remark",
  33. CreateTime: "create_time",
  34. ModifyTime: "modify_time",
  35. }
  36. }
  37. func (m *SysConfig) GetConfigByCode(code string) (item *SysConfig, err error) {
  38. o := orm.NewOrm()
  39. sql := fmt.Sprintf(`SELECT * FROM %s WHERE %s = ? LIMIT 1`, m.TableName(), m.Cols().ConfigCode)
  40. err = o.Raw(sql, code).QueryRow(&item)
  41. return
  42. }