sa_doc_classify.go 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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 SaDocClassify struct {
  10. SaDocClassifyId int `orm:"column(sa_doc_classify_id);pk" description:"分类ID"`
  11. ClassifyName string `description:"分类名称"`
  12. CoverImg string `description:"封面图"`
  13. SysAdminId int `description:"创建人ID"`
  14. SysAdminName string `description:"创建人名称"`
  15. CreateTime time.Time `description:"创建时间"`
  16. ModifyTime time.Time `description:"修改时间"`
  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. o := orm.NewOrm()
  40. id, err := o.Insert(m)
  41. if err != nil {
  42. return
  43. }
  44. m.SaDocClassifyId = int(id)
  45. return
  46. }
  47. func (m *SaDocClassify) Update(cols []string) (err error) {
  48. o := orm.NewOrm()
  49. _, err = o.Update(m, cols...)
  50. return
  51. }
  52. func (m *SaDocClassify) Del() (err error) {
  53. o := orm.NewOrm()
  54. sql := `DELETE FROM sa_doc_classify WHERE sa_doc_classify_id = ? LIMIT 1`
  55. _, err = o.Raw(sql, m.SaDocClassifyId).Exec()
  56. return
  57. }
  58. func (m *SaDocClassify) GetItemById(id int) (err error) {
  59. o := orm.NewOrm()
  60. sql := `SELECT * FROM sa_doc_classify WHERE sa_doc_classify_id = ? LIMIT 1`
  61. err = o.Raw(sql, id).QueryRow(&m)
  62. return
  63. }
  64. func (m *SaDocClassify) GetItemByCondition(condition string, pars []interface{}) (err error) {
  65. o := orm.NewOrm()
  66. sql := `SELECT * FROM sa_doc_classify WHERE 1=1 `
  67. sql += condition
  68. sql += ` LIMIT 1`
  69. err = o.Raw(sql, pars).QueryRow(&m)
  70. return
  71. }
  72. func (m *SaDocClassify) GetCountByCondition(condition string, pars []interface{}) (count int, err error) {
  73. o := orm.NewOrm()
  74. sql := fmt.Sprintf(`SELECT COUNT(1) FROM %s WHERE 1=1 %s`, m.TableName(), condition)
  75. err = o.Raw(sql, pars).QueryRow(&count)
  76. return
  77. }
  78. func (m *SaDocClassify) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*SaDocClassify, err error) {
  79. o := orm.NewOrm()
  80. fields := strings.Join(fieldArr, ",")
  81. if len(fieldArr) == 0 {
  82. fields = `*`
  83. }
  84. order := `ORDER BY create_time DESC`
  85. if orderRule != "" {
  86. order = ` ORDER BY ` + orderRule
  87. }
  88. sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s`, fields, m.TableName(), condition, order)
  89. _, err = o.Raw(sql, pars).QueryRows(&items)
  90. return
  91. }
  92. func (m *SaDocClassify) GetPageItemsByCondition(startSize, pageSize int, condition string, pars []interface{}, fieldArr []string, orderRule string) (total int, items []*SaDocClassify, err error) {
  93. o := orm.NewOrm()
  94. fields := strings.Join(fieldArr, ",")
  95. if len(fieldArr) == 0 {
  96. fields = `*`
  97. }
  98. order := `ORDER BY create_time DESC`
  99. if orderRule != "" {
  100. order = ` ORDER BY ` + orderRule
  101. }
  102. sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s`, fields, m.TableName(), condition, order)
  103. totalSql := `SELECT COUNT(1) total FROM (` + sql + `) z`
  104. if err = o.Raw(totalSql, pars).QueryRow(&total); err != nil {
  105. return
  106. }
  107. sql += ` LIMIT ?,?`
  108. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  109. return
  110. }
  111. type SaDocClassifyAddReq struct {
  112. ClassifyName string `description:"分类名称"`
  113. CoverImg string `description:"封面图"`
  114. }
  115. type SaDocClassifyEditReq struct {
  116. SaDocClassifyId int `description:"分类ID"`
  117. SaDocClassifyAddReq
  118. }
  119. type SaDocClassifyDelReq struct {
  120. SaDocClassifyId int `description:"分类ID"`
  121. }
  122. type SaDocClassifyPageListResp struct {
  123. List []*SaDocClassifyItem
  124. Paging *paging.PagingItem `description:"分页数据"`
  125. }
  126. type SaDocClassifyItem struct {
  127. SaDocClassifyId int `description:"分类ID"`
  128. ClassifyName string `description:"分类名称"`
  129. CoverImg string `description:"封面图"`
  130. SysAdminId int `description:"创建人ID"`
  131. SysAdminName string `description:"创建人名称"`
  132. CreateTime string `description:"创建时间"`
  133. Children []*SaDocClassifyChildrenItem `description:"分类下的文档"`
  134. }
  135. type SaDocClassifyChildrenItem struct {
  136. SaDocId int `description:"文档ID"`
  137. Title string `description:"文档标题"`
  138. Theme string `description:"文档主题"`
  139. CreateTime string `description:"创建时间"`
  140. UseNum int `description:"引用数"`
  141. }