help_doc.go 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. package help_doc
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "github.com/rdlucklib/rdluck_tools/paging"
  5. "time"
  6. )
  7. type HelpDoc struct {
  8. Id int `orm:"column(id);pk"`
  9. ClassifyId int // 分类id
  10. Title string // 标题
  11. Author string // 作者
  12. CreateTime time.Time // 创建时间
  13. ModifyTime time.Time // 修改时间
  14. Status int // 1:未发布,2:已发布
  15. PublishTime time.Time // 发布时间
  16. Content string // 内容
  17. AdminId int // 创建人
  18. AdminRealName string // 创建人姓名
  19. Anchor string // 锚点
  20. Recommend string // 推荐
  21. }
  22. type HelpDocItem struct {
  23. Id int `orm:"column(id);pk"`
  24. ClassifyId int // 分类id
  25. Title string // 标题
  26. Author string // 作者
  27. CreateTime string // 创建时间
  28. ModifyTime string // 修改时间
  29. Status int // 1:未发布,2:已发布
  30. PublishTime string // 发布时间
  31. Content string // 内容
  32. AdminId int // 创建人
  33. AdminRealName string // 创建人姓名
  34. Anchor string // 锚点
  35. Recommend string // 推荐
  36. }
  37. func EditHelpDocClassifyId(classifyId int, classifyName string) (err error) {
  38. o := orm.NewOrm()
  39. sql := `UPDATE help_doc SET classify_name=?,modify_time=NOW() WHERE classify_id=? `
  40. _, err = o.Raw(sql, classifyId, classifyName).Exec()
  41. return
  42. }
  43. type AddHelpDocReq struct {
  44. Id int64 `description:"文章id"`
  45. ClassifyId int `description:"分类id"`
  46. Title string `description:"标题"`
  47. Author string `description:"作者"`
  48. Status int `description:"状态:1:未发布,2:已发布"`
  49. Content string `description:"内容"`
  50. IsChange bool `description:"内容是否改变"`
  51. AnchorData []AnchorList
  52. RecommendData []RecommendList
  53. }
  54. type AnchorList struct {
  55. AnchorId string
  56. Anchor string
  57. AnchorName string
  58. Child []AnchorList
  59. }
  60. type RecommendList struct {
  61. Name string
  62. Url string
  63. }
  64. func AddHelpDoc(item *HelpDoc) (lastId int64, err error) {
  65. o := orm.NewOrm()
  66. lastId, err = o.Insert(item)
  67. return
  68. }
  69. type EditHelpDocReq struct {
  70. Id int64 `description:"文章id"`
  71. ClassifyId int `description:"分类id"`
  72. Title string `description:"标题"`
  73. Author string `description:"作者"`
  74. Status int `description:"状态:1:未发布,2:已发布"`
  75. Content string `description:"内容"`
  76. AnchorData []AnchorList
  77. RecommendData []RecommendList
  78. }
  79. func EditHelpDoc(item *HelpDoc, reportId int64) (err error) {
  80. o := orm.NewOrm()
  81. sql := `UPDATE help_doc
  82. SET
  83. classify_id =?,
  84. title = ?,
  85. author = ?,
  86. content = ?,
  87. modify_time = ?,
  88. status = ?,
  89. publish_time = ?,
  90. anchor = ?,
  91. recommend = ?
  92. WHERE id = ? `
  93. _, err = o.Raw(sql, item.ClassifyId, item.Title, item.Author, item.Content, item.ModifyTime,
  94. item.Status, item.PublishTime, item.Anchor, item.Recommend, reportId).Exec()
  95. return
  96. }
  97. func GetHelpDocById(docId int) (item *HelpDocItem, err error) {
  98. o := orm.NewOrm()
  99. sql := `SELECT * FROM help_doc WHERE id=?`
  100. err = o.Raw(sql, docId).QueryRow(&item)
  101. return
  102. }
  103. type HelpDocResp struct {
  104. Id int `orm:"column(id);pk"`
  105. ClassifyId int // 分类id
  106. ClassifyName string // 分类路径
  107. Title string // 标题
  108. Author string // 作者
  109. CreateTime string // 创建时间
  110. ModifyTime string // 修改时间
  111. Status int // 1:未发布,2:已发布
  112. PublishTime string // 发布时间
  113. Content string // 内容
  114. AdminId int // 创建人
  115. AdminRealName string // 创建人姓名
  116. Anchor []AnchorList // 锚点
  117. Recommend []RecommendList // 推荐
  118. }
  119. func GetHelpDocListCount(condition string, pars []interface{}) (count int, err error) {
  120. o := orm.NewOrm()
  121. sql := `SELECT COUNT(1) AS count FROM help_doc WHERE 1=1 `
  122. if condition != "" {
  123. sql += condition
  124. }
  125. err = o.Raw(sql, pars).QueryRow(&count)
  126. return
  127. }
  128. func GetHelpDocList(condition string, pars []interface{}, startSize, pageSize int) (items []*HelpDocItem, err error) {
  129. o := orm.NewOrm()
  130. sql := `SELECT * FROM help_doc WHERE 1=1 `
  131. if condition != "" {
  132. sql += condition
  133. }
  134. sql += `ORDER BY create_time DESC LIMIT ?,?`
  135. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  136. return
  137. }
  138. type HelpDocListResp struct {
  139. List []*HelpDocResp
  140. ClassifyName string
  141. Paging *paging.PagingItem `description:"分页数据"`
  142. }
  143. type PublishReq struct {
  144. DocId int
  145. Status int `description:"状态:1:未发布,2:已发布"`
  146. }
  147. // 发布报告
  148. func PublishHelpDocById(reportId, status int) (err error) {
  149. o := orm.NewOrm()
  150. sql := ``
  151. if status == 1 {
  152. sql = `UPDATE help_doc SET status=1,publish_time=NULL,modify_time=NOW() WHERE id = ? `
  153. } else {
  154. sql = `UPDATE help_doc SET status=2,publish_time=now(),modify_time=NOW() WHERE id = ? `
  155. }
  156. _, err = o.Raw(sql, reportId).Exec()
  157. return
  158. }
  159. type DeleteReq struct {
  160. DocId int `description:"id"`
  161. }
  162. func DeleteHelpDoc(reportIds int) (err error) {
  163. o := orm.NewOrm()
  164. sql := ` DELETE FROM help_doc WHERE id =? `
  165. _, err = o.Raw(sql, reportIds).Exec()
  166. return
  167. }
  168. func GetAllHelpDoc() (items []*HelpDocItem, err error) {
  169. o := orm.NewOrm()
  170. sql := `SELECT * FROM help_doc `
  171. _, err = o.Raw(sql).QueryRows(&items)
  172. return
  173. }
  174. type HelpDocSaveResp struct {
  175. HelpDocId int64 `description:"智能研报ID"`
  176. ModifyTime string `description:"修改时间"`
  177. }