report.go 14 KB

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