eta_business_menu_icon.go 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. package eta_business
  2. import (
  3. "fmt"
  4. "github.com/beego/beego/v2/client/orm"
  5. "strings"
  6. "time"
  7. )
  8. // EtaBusinessMenuIcon 菜单icon表
  9. type EtaBusinessMenuIcon struct {
  10. IconId int `orm:"column(icon_id);pk"`
  11. IconPath string `description:"icon地址"`
  12. CreateTime time.Time `description:"创建时间"`
  13. }
  14. func (m *EtaBusinessMenuIcon) TableName() string {
  15. return "eta_business_menu_icon"
  16. }
  17. func (m *EtaBusinessMenuIcon) PrimaryId() string {
  18. return "icon_id"
  19. }
  20. func (m *EtaBusinessMenuIcon) Create() (err error) {
  21. o := orm.NewOrm()
  22. id, err := o.Insert(m)
  23. if err != nil {
  24. return
  25. }
  26. m.IconId = int(id)
  27. return
  28. }
  29. func (m *EtaBusinessMenuIcon) CreateMulti(items []*EtaBusinessMenuIcon) (err error) {
  30. if len(items) == 0 {
  31. return
  32. }
  33. o := orm.NewOrm()
  34. _, err = o.InsertMulti(len(items), items)
  35. return
  36. }
  37. func (m *EtaBusinessMenuIcon) Update(cols []string) (err error) {
  38. o := orm.NewOrm()
  39. _, err = o.Update(m, cols...)
  40. return
  41. }
  42. func (m *EtaBusinessMenuIcon) Del() (err error) {
  43. o := orm.NewOrm()
  44. sql := fmt.Sprintf(`DELETE FROM %s WHERE %s = ? LIMIT 1`, m.TableName(), m.PrimaryId())
  45. _, err = o.Raw(sql, m.IconId).Exec()
  46. return
  47. }
  48. func (m *EtaBusinessMenuIcon) GetItemById(id int) (item *EtaBusinessMenuIcon, err error) {
  49. o := orm.NewOrm()
  50. sql := fmt.Sprintf(`SELECT * FROM %s WHERE %s = ? LIMIT 1`, m.TableName(), m.PrimaryId())
  51. err = o.Raw(sql, id).QueryRow(&item)
  52. return
  53. }
  54. func (m *EtaBusinessMenuIcon) GetItemByCondition(condition string, pars []interface{}) (item *EtaBusinessMenuIcon, err error) {
  55. o := orm.NewOrm()
  56. sql := fmt.Sprintf(`SELECT * FROM %s WHERE 1=1 %s LIMIT 1`, m.TableName(), condition)
  57. err = o.Raw(sql, pars).QueryRow(&item)
  58. return
  59. }
  60. func (m *EtaBusinessMenuIcon) GetCountByCondition(condition string, pars []interface{}) (count int, err error) {
  61. o := orm.NewOrm()
  62. sql := fmt.Sprintf(`SELECT COUNT(1) FROM %s WHERE 1=1 %s`, m.TableName(), condition)
  63. err = o.Raw(sql, pars).QueryRow(&count)
  64. return
  65. }
  66. func (m *EtaBusinessMenuIcon) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*EtaBusinessMenuIcon, err error) {
  67. o := orm.NewOrm()
  68. fields := strings.Join(fieldArr, ",")
  69. if len(fieldArr) == 0 {
  70. fields = `*`
  71. }
  72. order := `ORDER BY create_time DESC, icon_id ASC`
  73. if orderRule != "" {
  74. order = ` ORDER BY ` + orderRule
  75. }
  76. sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s`, fields, m.TableName(), condition, order)
  77. _, err = o.Raw(sql, pars).QueryRows(&items)
  78. return
  79. }
  80. func (m *EtaBusinessMenuIcon) GetPageItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string, startSize, pageSize int) (items []*EtaBusinessMenuIcon, err error) {
  81. o := orm.NewOrm()
  82. fields := strings.Join(fieldArr, ",")
  83. if len(fieldArr) == 0 {
  84. fields = `*`
  85. }
  86. order := `ORDER BY create_time DESC`
  87. if orderRule != "" {
  88. order = ` ORDER BY ` + orderRule
  89. }
  90. sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s LIMIT ?,?`, fields, m.TableName(), condition, order)
  91. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  92. return
  93. }
  94. // EtaBusinessMenuIconItem 菜单icon
  95. type EtaBusinessMenuIconItem struct {
  96. IconId int
  97. IconPath string `description:"icon地址"`
  98. }
  99. // EtaBusinessMenuIconAddReq 新增icon请求体
  100. type EtaBusinessMenuIconAddReq struct {
  101. IconPath string `description:"icon地址"`
  102. }