report.go 14 KB

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