sa_compare_classify.go 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. package semantic_analysis
  2. import (
  3. "eta_gn/eta_api/global"
  4. "fmt"
  5. "github.com/rdlucklib/rdluck_tools/paging"
  6. "strings"
  7. "time"
  8. )
  9. type SaCompareClassify struct {
  10. SaCompareClassifyId int `gorm:"primaryKey;column:sa_compare_classify_id;type:int(10) unsigned;not null"` // 语义分析-文档分类Id
  11. ClassifyName string `gorm:"column:classify_name;type:varchar(128);not null;default:''"` // 分类名称
  12. SysAdminId int `gorm:"column:sys_admin_id;type:int(10) unsigned;not null;default:0"` // 创建人Id
  13. SysAdminName string `gorm:"column:sys_admin_name;type:varchar(128);not null;default:''"` // 创建人姓名
  14. CreateTime time.Time `gorm:"column:create_time;type:datetime"` // 创建时间
  15. ModifyTime time.Time `gorm:"column:modify_time;type:datetime"` // 更新时间
  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. err = global.DEFAULT_DmSQL.Create(m).Error
  37. return
  38. }
  39. func (m *SaCompareClassify) Update(cols []string) (err error) {
  40. err = global.DEFAULT_DmSQL.Select(cols).Updates(m).Error
  41. return
  42. }
  43. func (m *SaCompareClassify) Del() (err error) {
  44. sql := `DELETE FROM sa_compare_classify WHERE sa_compare_classify_id = ? LIMIT 1`
  45. err = global.DEFAULT_DmSQL.Exec(sql, m.SaCompareClassifyId).Error
  46. return
  47. }
  48. func (m *SaCompareClassify) GetItemById(id int) (err error) {
  49. sql := `SELECT * FROM sa_compare_classify WHERE sa_compare_classify_id = ? LIMIT 1`
  50. err = global.DEFAULT_DmSQL.Raw(sql, id).First(&m).Error
  51. return
  52. }
  53. func (m *SaCompareClassify) GetItemByCondition(condition string, pars []interface{}) (err error) {
  54. sql := `SELECT * FROM sa_compare_classify WHERE 1=1 `
  55. sql += condition
  56. sql += ` LIMIT 1`
  57. err = global.DEFAULT_DmSQL.Raw(sql, pars...).First(&m).Error
  58. return
  59. }
  60. func (m *SaCompareClassify) GetCountByCondition(condition string, pars []interface{}) (count int, err error) {
  61. sql := fmt.Sprintf(`SELECT COUNT(1) FROM %s WHERE 1=1 %s`, m.TableName(), condition)
  62. err = global.DEFAULT_DmSQL.Raw(sql, pars...).Scan(&count).Error
  63. return
  64. }
  65. func (m *SaCompareClassify) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*SaCompareClassify, err error) {
  66. fields := strings.Join(fieldArr, ",")
  67. if len(fieldArr) == 0 {
  68. fields = `*`
  69. }
  70. order := `ORDER BY create_time DESC`
  71. if orderRule != "" {
  72. order = ` ORDER BY ` + orderRule
  73. }
  74. sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s`, fields, m.TableName(), condition, order)
  75. err = global.DEFAULT_DmSQL.Raw(sql, pars...).Find(&items).Error
  76. return
  77. }
  78. func (m *SaCompareClassify) GetPageItemsByCondition(startSize, pageSize int, condition string, pars []interface{}, fieldArr []string, orderRule string) (total int, items []*SaCompareClassify, err error) {
  79. fields := strings.Join(fieldArr, ",")
  80. if len(fieldArr) == 0 {
  81. fields = `*`
  82. }
  83. order := `ORDER BY create_time DESC`
  84. if orderRule != "" {
  85. order = ` ORDER BY ` + orderRule
  86. }
  87. sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s`, fields, m.TableName(), condition, order)
  88. totalSql := `SELECT COUNT(1) total FROM (` + sql + `) z`
  89. err = global.DEFAULT_DmSQL.Raw(totalSql, pars...).Scan(&total).Error
  90. if err != nil {
  91. return
  92. }
  93. sql += ` LIMIT ?,?`
  94. err = global.DEFAULT_DmSQL.Raw(sql, pars...).Find(&items).Error
  95. return
  96. }
  97. type SaCompareClassifyAddReq struct {
  98. ClassifyName string `description:"分类名称"`
  99. }
  100. type SaCompareClassifyEditReq struct {
  101. SaCompareClassifyId int `description:"分类ID"`
  102. SaCompareClassifyAddReq
  103. }
  104. type SaCompareClassifyDelReq struct {
  105. SaCompareClassifyId int `description:"分类ID"`
  106. }
  107. type SaCompareClassifyPageListResp struct {
  108. List []*SaCompareClassifyItem
  109. Paging *paging.PagingItem `description:"分页数据"`
  110. }
  111. type SaCompareClassifyItem struct {
  112. SaCompareClassifyId int `description:"分类ID"`
  113. ClassifyName string `description:"分类名称"`
  114. SysAdminId int `description:"创建人ID"`
  115. SysAdminName string `description:"创建人姓名"`
  116. CreateTime string `description:"创建时间"`
  117. Children []*SaCompareItem `gorm:"-" description:"分类下的比对"`
  118. }