sa_doc_classify.go 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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 SaDocClassify struct {
  10. SaDocClassifyId int `gorm:"primaryKey;column:sa_doc_classify_id;type:int(10) unsigned;not null"` // 语义分析-文档分类Id
  11. ClassifyName string `gorm:"column:classify_name;type:varchar(128);not null;default:''"` // 分类名称
  12. CoverImg string `gorm:"column:cover_img;type:varchar(255);not null;default:''"` // 封面图
  13. SysAdminId int `gorm:"column:sys_admin_id;type:int(10) unsigned;not null;default:0"` // 创建人Id
  14. SysAdminName string `gorm:"column:sys_admin_name;type:varchar(128);not null;default:''"` // 创建人姓名
  15. CreateTime time.Time `gorm:"column:create_time;type:datetime"` // 创建时间
  16. ModifyTime time.Time `gorm:"column:modify_time;type:datetime"` // 更新时间
  17. }
  18. var SaDocClassifyColumns = struct {
  19. SaDocClassifyId string
  20. ClassifyName string
  21. CoverImg string
  22. SysAdminId string
  23. SysAdminName string
  24. CreateTime string
  25. ModifyTime string
  26. }{
  27. SaDocClassifyId: "sa_doc_classify_id",
  28. ClassifyName: "classify_name",
  29. CoverImg: "cover_img",
  30. SysAdminId: "sys_admin_id",
  31. SysAdminName: "sys_admin_name",
  32. CreateTime: "create_time",
  33. ModifyTime: "modify_time",
  34. }
  35. func (m *SaDocClassify) TableName() string {
  36. return "sa_doc_classify"
  37. }
  38. func (m *SaDocClassify) Create() (err error) {
  39. err = global.DEFAULT_DmSQL.Create(m).Error
  40. return
  41. }
  42. func (m *SaDocClassify) Update(cols []string) (err error) {
  43. err = global.DEFAULT_DmSQL.Select(cols).Updates(m).Error
  44. return
  45. }
  46. func (m *SaDocClassify) Del() (err error) {
  47. sql := `DELETE FROM sa_doc_classify WHERE sa_doc_classify_id = ? LIMIT 1`
  48. err = global.DEFAULT_DmSQL.Exec(sql, m.SaDocClassifyId).Error
  49. return
  50. }
  51. func (m *SaDocClassify) GetItemById(id int) (err error) {
  52. sql := `SELECT * FROM sa_doc_classify WHERE sa_doc_classify_id = ? LIMIT 1`
  53. err = global.DEFAULT_DmSQL.Raw(sql, id).First(&m).Error
  54. return
  55. }
  56. func (m *SaDocClassify) GetItemByCondition(condition string, pars []interface{}) (err error) {
  57. sql := `SELECT * FROM sa_doc_classify WHERE 1=1 `
  58. sql += condition
  59. sql += ` LIMIT 1`
  60. err = global.DEFAULT_DmSQL.Raw(sql, pars...).First(&m).Error
  61. return
  62. }
  63. func (m *SaDocClassify) GetCountByCondition(condition string, pars []interface{}) (count int, err error) {
  64. sql := fmt.Sprintf(`SELECT COUNT(1) FROM %s WHERE 1=1 %s`, m.TableName(), condition)
  65. err = global.DEFAULT_DmSQL.Raw(sql, pars...).Scan(&count).Error
  66. return
  67. }
  68. func (m *SaDocClassify) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*SaDocClassify, err error) {
  69. fields := strings.Join(fieldArr, ",")
  70. if len(fieldArr) == 0 {
  71. fields = `*`
  72. }
  73. order := `ORDER BY create_time DESC`
  74. if orderRule != "" {
  75. order = ` ORDER BY ` + orderRule
  76. }
  77. sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s`, fields, m.TableName(), condition, order)
  78. err = global.DEFAULT_DmSQL.Raw(sql, pars...).Find(&items).Error
  79. return
  80. }
  81. func (m *SaDocClassify) GetPageItemsByCondition(startSize, pageSize int, condition string, pars []interface{}, fieldArr []string, orderRule string) (total int, items []*SaDocClassify, err error) {
  82. fields := strings.Join(fieldArr, ",")
  83. if len(fieldArr) == 0 {
  84. fields = `*`
  85. }
  86. order := `ORDER BY create_time DESC`
  87. if orderRule != "" {
  88. order = ` ORDER BY ` + orderRule
  89. }
  90. sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s`, fields, m.TableName(), condition, order)
  91. totalSql := `SELECT COUNT(1) total FROM (` + sql + `) z`
  92. err = global.DEFAULT_DmSQL.Raw(totalSql, pars...).Scan(&total).Error
  93. if err != nil {
  94. return
  95. }
  96. sql += ` LIMIT ?,?`
  97. err = global.DEFAULT_DmSQL.Raw(sql, pars...).Find(&items).Error
  98. return
  99. }
  100. type SaDocClassifyAddReq struct {
  101. ClassifyName string `description:"分类名称"`
  102. CoverImg string `description:"封面图"`
  103. }
  104. type SaDocClassifyEditReq struct {
  105. SaDocClassifyId int `description:"分类ID"`
  106. SaDocClassifyAddReq
  107. }
  108. type SaDocClassifyDelReq struct {
  109. SaDocClassifyId int `description:"分类ID"`
  110. }
  111. type SaDocClassifyPageListResp struct {
  112. List []*SaDocClassifyItem
  113. Paging *paging.PagingItem `description:"分页数据"`
  114. }
  115. type SaDocClassifyItem struct {
  116. SaDocClassifyId int `description:"分类ID"`
  117. ClassifyName string `description:"分类名称"`
  118. CoverImg string `description:"封面图"`
  119. SysAdminId int `description:"创建人ID"`
  120. SysAdminName string `description:"创建人名称"`
  121. CreateTime string `description:"创建时间"`
  122. Children []*SaDocClassifyChildrenItem `gorm:"-" description:"分类下的文档"`
  123. }
  124. type SaDocClassifyChildrenItem struct {
  125. SaDocId int `description:"文档ID"`
  126. Title string `description:"文档标题"`
  127. Theme string `description:"文档主题"`
  128. CreateTime string `description:"创建时间"`
  129. UseNum int `description:"引用数"`
  130. }