business_conf_operation_record.go 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. package models
  2. import (
  3. "fmt"
  4. "github.com/beego/beego/v2/client/orm"
  5. "strings"
  6. "time"
  7. )
  8. // BusinessConfOperationRecord 商户配置操作记录表
  9. type BusinessConfOperationRecord struct {
  10. Id int `orm:"column(id);pk"`
  11. SysUserId int `description:"操作人ID"`
  12. SysRealName string `description:"操作人姓名"`
  13. Content string `description:"操作数据"`
  14. CreateTime time.Time `description:"操作时间"`
  15. }
  16. func (m *BusinessConfOperationRecord) TableName() string {
  17. return "business_conf_operation_record"
  18. }
  19. func (m *BusinessConfOperationRecord) PrimaryId() string {
  20. return "id"
  21. }
  22. func (m *BusinessConfOperationRecord) Create() (err error) {
  23. o := orm.NewOrm()
  24. id, err := o.Insert(m)
  25. if err != nil {
  26. return
  27. }
  28. m.Id = int(id)
  29. return
  30. }
  31. func (m *BusinessConfOperationRecord) CreateMulti(items []*BusinessConfOperationRecord) (err error) {
  32. if len(items) == 0 {
  33. return
  34. }
  35. o := orm.NewOrm()
  36. _, err = o.InsertMulti(len(items), items)
  37. return
  38. }
  39. func (m *BusinessConfOperationRecord) Update(cols []string) (err error) {
  40. o := orm.NewOrm()
  41. _, err = o.Update(m, cols...)
  42. return
  43. }
  44. func (m *BusinessConfOperationRecord) Del() (err error) {
  45. o := orm.NewOrm()
  46. sql := fmt.Sprintf(`DELETE FROM %s WHERE %s = ? LIMIT 1`, m.TableName(), m.PrimaryId())
  47. _, err = o.Raw(sql, m.Id).Exec()
  48. return
  49. }
  50. func (m *BusinessConfOperationRecord) GetItemById(id int) (item *BusinessConfOperationRecord, err error) {
  51. o := orm.NewOrm()
  52. sql := fmt.Sprintf(`SELECT * FROM %s WHERE %s = ? LIMIT 1`, m.TableName(), m.PrimaryId())
  53. err = o.Raw(sql, id).QueryRow(&item)
  54. return
  55. }
  56. func (m *BusinessConfOperationRecord) GetItemByCondition(condition string, pars []interface{}) (item *BusinessConfOperationRecord, err error) {
  57. o := orm.NewOrm()
  58. sql := fmt.Sprintf(`SELECT * FROM %s WHERE 1=1 %s LIMIT 1`, m.TableName(), condition)
  59. err = o.Raw(sql, pars).QueryRow(&item)
  60. return
  61. }
  62. func (m *BusinessConfOperationRecord) GetCountByCondition(condition string, pars []interface{}) (count int, err error) {
  63. o := orm.NewOrm()
  64. sql := fmt.Sprintf(`SELECT COUNT(1) FROM %s WHERE 1=1 %s`, m.TableName(), condition)
  65. err = o.Raw(sql, pars).QueryRow(&count)
  66. return
  67. }
  68. func (m *BusinessConfOperationRecord) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*BusinessConfOperationRecord, err error) {
  69. o := orm.NewOrm()
  70. fields := strings.Join(fieldArr, ",")
  71. if len(fieldArr) == 0 {
  72. fields = `*`
  73. }
  74. order := `ORDER BY create_time DESC`
  75. if orderRule != "" {
  76. order = ` ORDER BY ` + orderRule
  77. }
  78. sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s`, fields, m.TableName(), condition, order)
  79. _, err = o.Raw(sql, pars).QueryRows(&items)
  80. return
  81. }
  82. func (m *BusinessConfOperationRecord) GetPageItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string, startSize, pageSize int) (items []*BusinessConfOperationRecord, err error) {
  83. o := orm.NewOrm()
  84. fields := strings.Join(fieldArr, ",")
  85. if len(fieldArr) == 0 {
  86. fields = `*`
  87. }
  88. order := `ORDER BY create_time DESC`
  89. if orderRule != "" {
  90. order = ` ORDER BY ` + orderRule
  91. }
  92. sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s LIMIT ?,?`, fields, m.TableName(), condition, order)
  93. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  94. return
  95. }