report.go 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. package models
  2. import (
  3. "rdluck_tools/orm"
  4. "time"
  5. )
  6. type Report struct {
  7. Id int `orm:"column(id)" description:"报告Id"`
  8. AddType int `description:"新增方式:1:新增报告,2:继承报告"`
  9. ClassifyIdFirst int `description:"一级分类id"`
  10. ClassifyNameFirst string `description:"一级分类名称"`
  11. ClassifyIdSecond int `description:"二级分类id"`
  12. ClassifyNameSecond string `description:"二级分类名称"`
  13. Title string `description:"标题"`
  14. Abstract string `description:"摘要"`
  15. Author string `description:"作者"`
  16. Frequency string `description:"频度"`
  17. CreateTime string `description:"创建时间"`
  18. ModifyTime time.Time `description:"修改时间"`
  19. State int `description:"1:未发布,2:已发布"`
  20. PublishTime time.Time `description:"发布时间"`
  21. Stage int `description:"期数"`
  22. MsgIsSend int `description:"消息是否已发送,0:否,1:是"`
  23. Content string `description:"内容"`
  24. VideoUrl string `description:"音频文件URL"`
  25. VideoName string `description:"音频文件名称"`
  26. VideoPlaySeconds string `description:"音频播放时长"`
  27. ContentSub string `description:"内容前两个章节"`
  28. }
  29. type ReportList struct {
  30. Id int `description:"报告Id"`
  31. AddType int `description:"新增方式:1:新增报告,2:继承报告"`
  32. ClassifyIdFirst int `description:"一级分类id"`
  33. ClassifyNameFirst string `description:"一级分类名称"`
  34. ClassifyIdSecond int `description:"二级分类id"`
  35. ClassifyNameSecond string `description:"二级分类名称"`
  36. Title string `description:"标题"`
  37. Abstract string `description:"摘要"`
  38. Author string `description:"作者"`
  39. Frequency string `description:"频度"`
  40. CreateTime string `description:"创建时间"`
  41. ModifyTime time.Time `description:"修改时间"`
  42. State int `description:"1:未发布,2:已发布"`
  43. PublishTime time.Time `description:"发布时间"`
  44. Stage int `description:"期数"`
  45. MsgIsSend int `description:"消息是否已发送,0:否,1:是"`
  46. Content string `description:"内容"`
  47. VideoUrl string `description:"音频文件URL"`
  48. VideoName string `description:"音频文件名称"`
  49. VideoPlaySeconds string `description:"音频播放时长"`
  50. ContentSub string `description:"内容前两个章节"`
  51. Pv int `description:"Pv"`
  52. Uv int `description:"Uv"`
  53. }
  54. type ReportListResp struct {
  55. List []*ReportList
  56. Paging *PagingItem `description:"分页数据"`
  57. }
  58. func GetReportListCount(condition string, pars []interface{}) (count int, err error) {
  59. o := orm.NewOrm()
  60. o.Using("rddp")
  61. sql := `SELECT COUNT(1) AS count FROM report WHERE 1=1 `
  62. if condition != "" {
  63. sql += condition
  64. }
  65. err = o.Raw(sql, pars).QueryRow(&count)
  66. return
  67. }
  68. func GetReportList(condition string, pars []interface{}, startSize, pageSize int) (items []*ReportList, err error) {
  69. o := orm.NewOrm()
  70. o.Using("rddp")
  71. sql := `SELECT *,
  72. (SELECT COUNT(1) FROM report_view_record AS rvr WHERE rvr.report_id=report.id) AS pv,
  73. (SELECT COUNT(DISTINCT user_id) FROM report_view_record AS rvr WHERE rvr.report_id=report.id) AS uv
  74. FROM report WHERE 1=1 `
  75. if condition != "" {
  76. sql += condition
  77. }
  78. sql += `ORDER BY modify_time DESC LIMIT ?,?`
  79. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  80. return
  81. }
  82. //发布报告
  83. func PublishReport(reportIds string) (err error) {
  84. o := orm.NewOrm()
  85. o.Using("rddp")
  86. sql := `UPDATE report SET state=2,publish_time=now(),modify_time=NOW() WHERE id IN (` + reportIds + `)`
  87. _, err = o.Raw(sql).Exec()
  88. return
  89. }
  90. //取消发布报告
  91. func PublishCancleReport(reportIds string) (err error) {
  92. o := orm.NewOrm()
  93. o.Using("rddp")
  94. sql := ` UPDATE report SET state=1,publish_time=null WHERE id IN (` + reportIds + `) `
  95. _, err = o.Raw(sql).Exec()
  96. return
  97. }
  98. //删除报告
  99. func DeleteReport(reportIds string) (err error) {
  100. o := orm.NewOrm()
  101. o.Using("rddp")
  102. sql := ` DELETE FROM report WHERE id IN (` + reportIds + `) `
  103. _, err = o.Raw(sql).Exec()
  104. return
  105. }
  106. func GetReportById(reportId int) (item *Report, err error) {
  107. o := orm.NewOrm()
  108. o.Using("rddp")
  109. sql := `SELECT * FROM report WHERE id=?`
  110. err = o.Raw(sql, reportId).QueryRow(&item)
  111. return
  112. }
  113. func GetReportStage(classifyIdFirst, classifyIdSecond int) (count int, err error) {
  114. o := orm.NewOrm()
  115. o.Using("rddp")
  116. sql := ``
  117. if classifyIdSecond > 0 {
  118. sql = "SELECT MAX(stage) AS max_stage FROM report WHERE classify_id_second=? "
  119. o.Raw(sql, classifyIdSecond).QueryRow(&count)
  120. } else {
  121. sql = "SELECT MAX(stage) AS max_stage FROM report WHERE classify_id_first=? "
  122. o.Raw(sql, classifyIdFirst).QueryRow(&count)
  123. }
  124. return
  125. }
  126. type PublishReq struct {
  127. ReportIds string `description:"报告id,多个用英文逗号隔开"`
  128. }
  129. type DeleteReq struct {
  130. ReportIds string `description:"报告id,多个用英文逗号隔开"`
  131. }
  132. type AddReq struct {
  133. AddType int `description:"新增方式:1:新增报告,2:继承报告"`
  134. ClassifyIdFirst int `description:"一级分类id"`
  135. ClassifyNameFirst string `description:"一级分类名称"`
  136. ClassifyIdSecond int `description:"二级分类id"`
  137. ClassifyNameSecond string `description:"二级分类名称"`
  138. Title string `description:"标题"`
  139. Abstract string `description:"摘要"`
  140. Author string `description:"作者"`
  141. Frequency string `description:"频度"`
  142. State int `description:"状态:1:未发布,2:已发布"`
  143. Content string `description:"内容"`
  144. CreateTime string `description:"创建时间"`
  145. }
  146. type AddResp struct {
  147. ReportId int64 `description:"报告id"`
  148. }
  149. func AddReport(item *Report) (lastId int64, err error) {
  150. o := orm.NewOrm()
  151. o.Using("rddp")
  152. lastId, err = o.Insert(item)
  153. return
  154. }
  155. type EditReq struct {
  156. ReportId int64 `description:"报告id"`
  157. ClassifyIdFirst int `description:"一级分类id"`
  158. ClassifyNameFirst string `description:"一级分类名称"`
  159. ClassifyIdSecond int `description:"二级分类id"`
  160. ClassifyNameSecond string `description:"二级分类名称"`
  161. Title string `description:"标题"`
  162. Abstract string `description:"摘要"`
  163. Author string `description:"作者"`
  164. Frequency string `description:"频度"`
  165. State int `description:"状态:1:未发布,2:已发布"`
  166. Content string `description:"内容"`
  167. CreateTime string `description:"创建时间"`
  168. }
  169. type EditResp struct {
  170. ReportId int64 `description:"报告id"`
  171. }
  172. func EditReport(item *Report, reportId int64) (err error) {
  173. o := orm.NewOrm()
  174. o.Using("rddp")
  175. sql := `UPDATE report
  176. SET
  177. classify_id_first =?,
  178. classify_name_first = ?,
  179. classify_id_second = ?,
  180. classify_name_second = ?,
  181. title = ?,
  182. abstract = = ?,
  183. author = = ?,
  184. frequency = = ?,
  185. state = = ?,
  186. content = = ?,
  187. content_sub = = ?,
  188. create_time=?,
  189. modify_time = = ?
  190. WHERE id = ? `
  191. _, err = o.Raw(sql, item.ClassifyIdFirst, item.ClassifyNameFirst, item.ClassifyIdSecond, item.ClassifyNameSecond, item.Title,
  192. item.Abstract, item.Frequency, item.State, item.Content, item.ContentSub, item.CreateTime, time.Now(), item.Id).Exec()
  193. return
  194. }
  195. type ReportDetailReq struct {
  196. ReportId int `description:"报告id"`
  197. }
  198. type ClassifyIdDetailReq struct {
  199. ClassifyIdFirst int `description:"报告一级分类id"`
  200. ClassifyIdSecond int `description:"报告二级分类id"`
  201. }
  202. func GetReportDetailByClassifyId(classifyIdFirst, classifyIdSecond int) (item *Report, err error) {
  203. o := orm.NewOrm()
  204. o.Using("rddp")
  205. sql := ` SELECT * FROM report WHERE 1=1 `
  206. if classifyIdSecond > 0 {
  207. sql = sql + ` AND classify_id_second=? ORDER BY stage DESC LIMIT 1`
  208. err = o.Raw(sql, classifyIdSecond).QueryRow(&item)
  209. } else {
  210. sql = sql + ` AND classify_id_first=? ORDER BY stage DESC LIMIT 1`
  211. err = o.Raw(sql, classifyIdFirst).QueryRow(&item)
  212. }
  213. return
  214. }
  215. type SendTemplateMsgReq struct {
  216. ReportId int `description:"报告id"`
  217. }
  218. func ModifyReportMsgIsSend(reportId int) (err error) {
  219. o := orm.NewOrm()
  220. o.Using("rddp")
  221. report, err := GetReportById(reportId)
  222. if err != nil {
  223. return
  224. }
  225. if report.MsgIsSend == 0 {
  226. sql := `UPDATE report SET msg_is_send = 1 WHERE id = ? `
  227. _, err = o.Raw(sql, reportId).Exec()
  228. }
  229. return
  230. }
  231. func ModifyReportVideo(reportId int, videoUrl, videoName string, playSeconds float64) (err error) {
  232. o := orm.NewOrm()
  233. o.Using("rddp")
  234. sql := `UPDATE report SET video_url=?,video_name=?,video_play_seconds=? WHERE id=? `
  235. _, err = o.Raw(sql, videoUrl, videoName, playSeconds, reportId).Exec()
  236. return
  237. }
  238. type ReportItem struct {
  239. Id int `orm:"column(id)" description:"报告Id"`
  240. AddType int `description:"新增方式:1:新增报告,2:继承报告"`
  241. ClassifyIdFirst int `description:"一级分类id"`
  242. ClassifyNameFirst string `description:"一级分类名称"`
  243. ClassifyIdSecond int `description:"二级分类id"`
  244. ClassifyNameSecond string `description:"二级分类名称"`
  245. Title string `description:"标题"`
  246. Abstract string `description:"摘要"`
  247. Author string `description:"作者"`
  248. Frequency string `description:"频度"`
  249. CreateTime time.Time `description:"创建时间"`
  250. ModifyTime time.Time `description:"修改时间"`
  251. State int `description:"1:未发布,2:已发布"`
  252. PublishTime time.Time `description:"发布时间"`
  253. Stage int `description:"期数"`
  254. MsgIsSend int `description:"消息是否已发送,0:否,1:是"`
  255. Content string `description:"内容"`
  256. VideoUrl string `description:"音频文件URL"`
  257. VideoName string `description:"音频文件名称"`
  258. VideoPlaySeconds string `description:"音频播放时长"`
  259. ContentSub string `description:"内容前两个章节"`
  260. }
  261. func GetReportItemById(reportId int) (item *ReportItem, err error) {
  262. o := orm.NewOrm()
  263. o.Using("rddp")
  264. sql := `SELECT * FROM report WHERE id=?`
  265. err = o.Raw(sql, reportId).QueryRow(&item)
  266. return
  267. }