sa_compare_classify.go 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. package semantic_analysis
  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. type SaCompareClassify struct {
  10. SaCompareClassifyId int `orm:"column(sa_compare_classify_id);pk" description:"分类ID"`
  11. ClassifyName string `description:"分类名称"`
  12. SysAdminId int `description:"创建人ID"`
  13. SysAdminName string `description:"创建人姓名"`
  14. CreateTime time.Time `description:"创建时间"`
  15. ModifyTime time.Time `description:"修改时间"`
  16. }
  17. var SaCompareClassifyColumns = struct {
  18. SaCompareClassifyId string
  19. ClassifyName string
  20. SysAdminId string
  21. SysAdminName string
  22. CreateTime string
  23. ModifyTime string
  24. }{
  25. SaCompareClassifyId: "sa_compare_classify_id",
  26. ClassifyName: "classify_name",
  27. SysAdminId: "sys_admin_id",
  28. SysAdminName: "sys_admin_name",
  29. CreateTime: "create_time",
  30. ModifyTime: "modify_time",
  31. }
  32. func (m *SaCompareClassify) TableName() string {
  33. return "sa_compare_classify"
  34. }
  35. func (m *SaCompareClassify) Create() (err error) {
  36. o := orm.NewOrm()
  37. id, err := o.Insert(m)
  38. if err != nil {
  39. return
  40. }
  41. m.SaCompareClassifyId = int(id)
  42. return
  43. }
  44. func (m *SaCompareClassify) Update(cols []string) (err error) {
  45. o := orm.NewOrm()
  46. _, err = o.Update(m, cols...)
  47. return
  48. }
  49. func (m *SaCompareClassify) Del() (err error) {
  50. o := orm.NewOrm()
  51. sql := `DELETE FROM sa_compare_classify WHERE sa_compare_classify_id = ? LIMIT 1`
  52. _, err = o.Raw(sql, m.SaCompareClassifyId).Exec()
  53. return
  54. }
  55. func (m *SaCompareClassify) GetItemById(id int) (err error) {
  56. o := orm.NewOrm()
  57. sql := `SELECT * FROM sa_compare_classify WHERE sa_compare_classify_id = ? LIMIT 1`
  58. err = o.Raw(sql, id).QueryRow(&m)
  59. return
  60. }
  61. func (m *SaCompareClassify) GetItemByCondition(condition string, pars []interface{}) (err error) {
  62. o := orm.NewOrm()
  63. sql := `SELECT * FROM sa_compare_classify WHERE 1=1 `
  64. sql += condition
  65. sql += ` LIMIT 1`
  66. err = o.Raw(sql, pars).QueryRow(&m)
  67. return
  68. }
  69. func (m *SaCompareClassify) GetCountByCondition(condition string, pars []interface{}) (count int, err error) {
  70. o := orm.NewOrm()
  71. sql := fmt.Sprintf(`SELECT COUNT(1) FROM %s WHERE 1=1 %s`, m.TableName(), condition)
  72. err = o.Raw(sql, pars).QueryRow(&count)
  73. return
  74. }
  75. func (m *SaCompareClassify) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*SaCompareClassify, err error) {
  76. o := orm.NewOrm()
  77. fields := strings.Join(fieldArr, ",")
  78. if len(fieldArr) == 0 {
  79. fields = `*`
  80. }
  81. order := `ORDER BY create_time DESC`
  82. if orderRule != "" {
  83. order = ` ORDER BY ` + orderRule
  84. }
  85. sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s`, fields, m.TableName(), condition, order)
  86. _, err = o.Raw(sql, pars).QueryRows(&items)
  87. return
  88. }
  89. func (m *SaCompareClassify) GetPageItemsByCondition(startSize, pageSize int, condition string, pars []interface{}, fieldArr []string, orderRule string) (total int, items []*SaCompareClassify, err error) {
  90. o := orm.NewOrm()
  91. fields := strings.Join(fieldArr, ",")
  92. if len(fieldArr) == 0 {
  93. fields = `*`
  94. }
  95. order := `ORDER BY create_time DESC`
  96. if orderRule != "" {
  97. order = ` ORDER BY ` + orderRule
  98. }
  99. sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s`, fields, m.TableName(), condition, order)
  100. totalSql := `SELECT COUNT(1) total FROM (` + sql + `) z`
  101. if err = o.Raw(totalSql, pars).QueryRow(&total); err != nil {
  102. return
  103. }
  104. sql += ` LIMIT ?,?`
  105. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  106. return
  107. }
  108. type SaCompareClassifyAddReq struct {
  109. ClassifyName string `description:"分类名称"`
  110. }
  111. type SaCompareClassifyEditReq struct {
  112. SaCompareClassifyId int `description:"分类ID"`
  113. SaCompareClassifyAddReq
  114. }
  115. type SaCompareClassifyDelReq struct {
  116. SaCompareClassifyId int `description:"分类ID"`
  117. }
  118. type SaCompareClassifyPageListResp struct {
  119. List []*SaCompareClassifyItem
  120. Paging *paging.PagingItem `description:"分页数据"`
  121. }
  122. type SaCompareClassifyItem struct {
  123. SaCompareClassifyId int `description:"分类ID"`
  124. ClassifyName string `description:"分类名称"`
  125. SysAdminId int `description:"创建人ID"`
  126. SysAdminName string `description:"创建人姓名"`
  127. CreateTime string `description:"创建时间"`
  128. Children []*SaCompareItem `description:"分类下的比对"`
  129. }