sa_compare.go 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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 SaCompare struct {
  10. SaCompareId int `orm:"column(sa_compare_id);pk" description:"比对ID"`
  11. ClassifyId int `description:"比对分类ID"`
  12. ClassifyName string `description:"比对分类名称"`
  13. Title string `description:"标题"`
  14. ResultImg string `description:"比对结果图片"`
  15. SysAdminId int `description:"创建人ID"`
  16. SysAdminName string `description:"创建人姓名"`
  17. Sort int `description:"排序"`
  18. CreateTime time.Time `description:"创建时间"`
  19. ModifyTime time.Time `description:"修改时间"`
  20. }
  21. var SaCompareColumns = struct {
  22. SaCompareId string
  23. ClassifyId string
  24. ClassifyName string
  25. Title string
  26. ResultImg string
  27. SysAdminId string
  28. SysAdminName string
  29. Sort string
  30. CreateTime string
  31. ModifyTime string
  32. }{
  33. SaCompareId: "sa_compare_id",
  34. ClassifyId: "classify_id",
  35. ClassifyName: "classify_name",
  36. Title: "title",
  37. ResultImg: "result_img",
  38. SysAdminId: "sys_admin_id",
  39. SysAdminName: "sys_admin_name",
  40. Sort: "sort",
  41. CreateTime: "create_time",
  42. ModifyTime: "modify_time",
  43. }
  44. func (m *SaCompare) TableName() string {
  45. return "sa_compare"
  46. }
  47. func (m *SaCompare) Create() (err error) {
  48. o := orm.NewOrm()
  49. id, err := o.Insert(m)
  50. if err != nil {
  51. return
  52. }
  53. m.SaCompareId = int(id)
  54. return
  55. }
  56. func (m *SaCompare) Update(cols []string) (err error) {
  57. o := orm.NewOrm()
  58. _, err = o.Update(m, cols...)
  59. return
  60. }
  61. func (m *SaCompare) Del() (err error) {
  62. o := orm.NewOrm()
  63. sql := `DELETE FROM sa_compare WHERE sa_compare_id = ? LIMIT 1`
  64. _, err = o.Raw(sql, m.SaCompareId).Exec()
  65. return
  66. }
  67. func (m *SaCompare) GetItemById(id int) (err error) {
  68. o := orm.NewOrm()
  69. sql := `SELECT * FROM sa_compare WHERE sa_compare_id = ? LIMIT 1`
  70. err = o.Raw(sql, id).QueryRow(&m)
  71. return
  72. }
  73. func (m *SaCompare) GetItemByCondition(condition string, pars []interface{}) (err error) {
  74. o := orm.NewOrm()
  75. sql := `SELECT * FROM sa_compare WHERE 1=1 `
  76. sql += condition
  77. sql += ` LIMIT 1`
  78. err = o.Raw(sql, pars).QueryRow(&m)
  79. return
  80. }
  81. func (m *SaCompare) GetCountByCondition(condition string, pars []interface{}) (count int, err error) {
  82. o := orm.NewOrm()
  83. sql := fmt.Sprintf(`SELECT COUNT(1) FROM %s WHERE 1=1 %s`, m.TableName(), condition)
  84. err = o.Raw(sql, pars).QueryRow(&count)
  85. return
  86. }
  87. func (m *SaCompare) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*SaCompare, err error) {
  88. o := orm.NewOrm()
  89. fields := strings.Join(fieldArr, ",")
  90. if len(fieldArr) == 0 {
  91. fields = `*`
  92. }
  93. order := `ORDER BY create_time DESC`
  94. if orderRule != "" {
  95. order = ` ORDER BY ` + orderRule
  96. }
  97. sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s`, fields, m.TableName(), condition, order)
  98. _, err = o.Raw(sql, pars).QueryRows(&items)
  99. return
  100. }
  101. func (m *SaCompare) GetPageItemsByCondition(startSize, pageSize int, condition string, pars []interface{}, fieldArr []string, orderRule string) (total int, items []*SaCompare, err error) {
  102. o := orm.NewOrm()
  103. fields := strings.Join(fieldArr, ",")
  104. if len(fieldArr) == 0 {
  105. fields = `*`
  106. }
  107. order := `ORDER BY create_time DESC`
  108. if orderRule != "" {
  109. order = ` ORDER BY ` + orderRule
  110. }
  111. sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s`, fields, m.TableName(), condition, order)
  112. totalSql := `SELECT COUNT(1) total FROM (` + sql + `) z`
  113. if err = o.Raw(totalSql, pars).QueryRow(&total); err != nil {
  114. return
  115. }
  116. sql += ` LIMIT ?,?`
  117. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  118. return
  119. }
  120. type SaCompareItem struct {
  121. SaCompareId int `description:"比对ID"`
  122. ClassifyId int `description:"比对分类ID"`
  123. ClassifyName string `description:"比对分类名称"`
  124. Title string `description:"标题"`
  125. ResultImg string `description:"比对结果图片"`
  126. SysAdminId int `description:"创建人ID"`
  127. SysAdminName string `description:"创建人姓名"`
  128. CreateTime string `description:"创建时间"`
  129. }
  130. type SaCompareElastic struct {
  131. SaCompareId int `description:"比对ID"`
  132. ClassifyId int `description:"比对分类ID"`
  133. ClassifyName string `description:"比对分类名称"`
  134. Title string `description:"标题"`
  135. ResultImg string `description:"比对结果图片"`
  136. SysAdminId int `description:"创建人ID"`
  137. SysAdminName string `description:"创建人姓名"`
  138. CreateTime string `description:"创建时间"`
  139. ModifyTime string `description:"修改时间"`
  140. }
  141. // CompareListByEsResp 文档对比Es搜索返回
  142. type CompareListByEsResp struct {
  143. Paging *paging.PagingItem
  144. List []*SaCompareElastic
  145. }