eta_version_update_log.go 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. package models
  2. import (
  3. "fmt"
  4. "github.com/beego/beego/v2/client/orm"
  5. "github.com/rdlucklib/rdluck_tools/paging"
  6. "strings"
  7. "time"
  8. )
  9. // EtaVersionUpdateLog ETA版本更新日志表
  10. type EtaVersionUpdateLog struct {
  11. Id int `orm:"column(id);pk"`
  12. Version string `description:"版本号"`
  13. Content string `description:"更新内容"`
  14. UpdateDate time.Time `description:"更新日期"`
  15. CreateTime time.Time
  16. ModifyTime time.Time
  17. }
  18. func (m *EtaVersionUpdateLog) TableName() string {
  19. return "eta_version_update_log"
  20. }
  21. func (m *EtaVersionUpdateLog) PrimaryId() string {
  22. return "id"
  23. }
  24. func (m *EtaVersionUpdateLog) Create() (err error) {
  25. o := orm.NewOrm()
  26. id, err := o.Insert(m)
  27. if err != nil {
  28. return
  29. }
  30. m.Id = int(id)
  31. return
  32. }
  33. func (m *EtaVersionUpdateLog) CreateMulti(items []*EtaVersionUpdateLog) (err error) {
  34. if len(items) == 0 {
  35. return
  36. }
  37. o := orm.NewOrm()
  38. _, err = o.InsertMulti(len(items), items)
  39. return
  40. }
  41. func (m *EtaVersionUpdateLog) Update(cols []string) (err error) {
  42. o := orm.NewOrm()
  43. _, err = o.Update(m, cols...)
  44. return
  45. }
  46. func (m *EtaVersionUpdateLog) Del() (err error) {
  47. o := orm.NewOrm()
  48. sql := fmt.Sprintf(`DELETE FROM %s WHERE %s = ? LIMIT 1`, m.TableName(), m.PrimaryId())
  49. _, err = o.Raw(sql, m.Id).Exec()
  50. return
  51. }
  52. func (m *EtaVersionUpdateLog) GetItemById(id int) (item *EtaVersionUpdateLog, err error) {
  53. o := orm.NewOrm()
  54. sql := fmt.Sprintf(`SELECT * FROM %s WHERE %s = ? LIMIT 1`, m.TableName(), m.PrimaryId())
  55. err = o.Raw(sql, id).QueryRow(&item)
  56. return
  57. }
  58. func (m *EtaVersionUpdateLog) GetItemByCondition(condition string, pars []interface{}) (item *EtaVersionUpdateLog, err error) {
  59. o := orm.NewOrm()
  60. sql := fmt.Sprintf(`SELECT * FROM %s WHERE 1=1 %s LIMIT 1`, m.TableName(), condition)
  61. err = o.Raw(sql, pars).QueryRow(&item)
  62. return
  63. }
  64. func (m *EtaVersionUpdateLog) GetCountByCondition(condition string, pars []interface{}) (count int, err error) {
  65. o := orm.NewOrm()
  66. sql := fmt.Sprintf(`SELECT COUNT(1) FROM %s WHERE 1=1 %s`, m.TableName(), condition)
  67. err = o.Raw(sql, pars).QueryRow(&count)
  68. return
  69. }
  70. func (m *EtaVersionUpdateLog) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*EtaVersionUpdateLog, err error) {
  71. o := orm.NewOrm()
  72. fields := strings.Join(fieldArr, ",")
  73. if len(fieldArr) == 0 {
  74. fields = `*`
  75. }
  76. order := `ORDER BY create_time DESC`
  77. if orderRule != "" {
  78. order = ` ORDER BY ` + orderRule
  79. }
  80. sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s`, fields, m.TableName(), condition, order)
  81. _, err = o.Raw(sql, pars).QueryRows(&items)
  82. return
  83. }
  84. func (m *EtaVersionUpdateLog) GetPageItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string, startSize, pageSize int) (items []*EtaVersionUpdateLog, err error) {
  85. o := orm.NewOrm()
  86. fields := strings.Join(fieldArr, ",")
  87. if len(fieldArr) == 0 {
  88. fields = `*`
  89. }
  90. order := `ORDER BY create_time DESC`
  91. if orderRule != "" {
  92. order = ` ORDER BY ` + orderRule
  93. }
  94. sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s LIMIT ?,?`, fields, m.TableName(), condition, order)
  95. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  96. return
  97. }
  98. // EtaVersionUpdateLogItem 更新日志信息
  99. type EtaVersionUpdateLogItem struct {
  100. Id int
  101. Version string `description:"版本号"`
  102. Content string `description:"更新内容"`
  103. UpdateDate string `description:"更新日期"`
  104. CreateTime string
  105. ModifyTime string
  106. }
  107. // EtaVersionUpdateLogListResp 更新日志列表响应体
  108. type EtaVersionUpdateLogListResp struct {
  109. List []*EtaVersionUpdateLogItem
  110. Paging *paging.PagingItem
  111. }
  112. // EtaVersionUpdateLogAddReq 新增更新日志请求体
  113. type EtaVersionUpdateLogAddReq struct {
  114. Version string `description:"版本号"`
  115. Content string `description:"更新内容"`
  116. UpdateDate string `description:"更新日期"`
  117. }
  118. // EtaVersionUpdateLogEditReq 编辑更新日志请求体
  119. type EtaVersionUpdateLogEditReq struct {
  120. Id int
  121. EtaVersionUpdateLogAddReq
  122. }
  123. // EtaVersionUpdateLogDelReq 删除更新日志请求体
  124. type EtaVersionUpdateLogDelReq struct {
  125. Id int
  126. }