report.go 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. package report
  2. import (
  3. "github.com/gin-gonic/gin"
  4. "hongze/hongze_yb/controller/response"
  5. "hongze/hongze_yb/models/request"
  6. "hongze/hongze_yb/models/tables/user_report_chapter_set"
  7. "hongze/hongze_yb/services"
  8. "hongze/hongze_yb/services/report"
  9. userService "hongze/hongze_yb/services/user"
  10. "hongze/hongze_yb/utils"
  11. "strconv"
  12. )
  13. // Detail 报告详情
  14. func Detail(c *gin.Context) {
  15. reqReportId := c.DefaultQuery("report_id", "")
  16. if reqReportId == "" {
  17. response.Fail("请输入报告ID", c)
  18. return
  19. }
  20. reportId, err := strconv.Atoi(reqReportId)
  21. if err != nil {
  22. response.Fail("报告ID格式有误", c)
  23. return
  24. }
  25. userinfo := userService.GetInfoByClaims(c)
  26. reportDetail, err := report.GetReportDetail(userinfo, reportId)
  27. if err != nil {
  28. if err.Error() == "报告未发布" {
  29. response.NotReleaseMsg("您查看的报告不存在,请试试其他报告吧", err.Error(), c)
  30. return
  31. } else {
  32. response.FailMsg(err.Error(), err.Error(), c)
  33. return
  34. }
  35. }
  36. response.OkData("查询成功", reportDetail, c)
  37. return
  38. }
  39. // ChapterDetail 章节详情
  40. func ChapterDetail(c *gin.Context) {
  41. reqReportChapterId := c.DefaultQuery("report_chapter_id", "")
  42. if reqReportChapterId == "" {
  43. response.Fail("请输入章节ID", c)
  44. return
  45. }
  46. reportChapterId, err := strconv.Atoi(reqReportChapterId)
  47. if err != nil {
  48. response.Fail("章节ID格式有误", c)
  49. return
  50. }
  51. userinfo := userService.GetInfoByClaims(c)
  52. chapterDetail, err := report.GetChapterDetail(userinfo, reportChapterId)
  53. if err != nil {
  54. response.FailMsg("查看章节详情出错", err.Error(), c)
  55. return
  56. }
  57. response.OkData("查询成功", chapterDetail, c)
  58. return
  59. }
  60. // List 研报列表
  61. func List(c *gin.Context) {
  62. var req request.ReportListReq
  63. if err := c.Bind(&req); err != nil {
  64. response.Fail("参数有误", c)
  65. return
  66. }
  67. if req.ClassifyIdFirst <= 0 {
  68. response.Fail("分类ID有误", c)
  69. return
  70. }
  71. if req.CurrentIndex == 0 {
  72. req.CurrentIndex = 1
  73. }
  74. if req.PageSize == 0 {
  75. req.PageSize = utils.PageSize20
  76. }
  77. userInfo := userService.GetInfoByClaims(c)
  78. list, err := report.GetReportList(userInfo, req.KeyWord, req.ClassifyIdFirst, req.ClassifyIdSecond, req.CurrentIndex, req.PageSize, req.ClassifyMenuId)
  79. if err != nil {
  80. response.FailMsg("查看研报列表出错", err.Error(), c)
  81. return
  82. }
  83. response.OkData("查询成功", list, c)
  84. return
  85. }
  86. // CollectReportList 首页研报汇总
  87. func CollectReportList(c *gin.Context) {
  88. reqChartPermissionId := c.DefaultQuery("chart_permission_id", "")
  89. reqPageIndex := c.DefaultQuery("current_index", "1")
  90. reqPageSize := c.DefaultQuery("page_size", strconv.Itoa(utils.PageSize20))
  91. pageIndex, err := strconv.Atoi(reqPageIndex)
  92. if err != nil {
  93. response.Fail("请输入正确的条数限制", c)
  94. return
  95. }
  96. pageSize, err := strconv.Atoi(reqPageSize)
  97. if err != nil {
  98. response.Fail("请输入正确的页码", c)
  99. return
  100. }
  101. if reqChartPermissionId == "" {
  102. response.Fail("请输入权限ID", c)
  103. return
  104. }
  105. chartPermissionId, err := strconv.Atoi(reqChartPermissionId)
  106. if err != nil {
  107. response.Fail("权限ID格式错误", c)
  108. return
  109. }
  110. userinfo := userService.GetInfoByClaims(c)
  111. list, err := report.GetCollectReportList(userinfo, chartPermissionId, pageIndex, pageSize)
  112. if err != nil {
  113. response.FailMsg("汇总报告查询出错", err.Error(), c)
  114. return
  115. }
  116. response.OkData("查询成功", list, c)
  117. return
  118. }
  119. // Search 首页研报搜索
  120. func Search(c *gin.Context) {
  121. keyWord := c.DefaultQuery("key_word", "")
  122. reqPageIndex := c.DefaultQuery("current_index", "1")
  123. reqPageSize := c.DefaultQuery("page_size", strconv.Itoa(utils.PageSize20))
  124. pageIndex, err := strconv.Atoi(reqPageIndex)
  125. if err != nil {
  126. response.Fail("请输入正确的条数限制", c)
  127. return
  128. }
  129. pageSize, err := strconv.Atoi(reqPageSize)
  130. if err != nil {
  131. response.Fail("请输入正确的页码", c)
  132. return
  133. }
  134. if keyWord == "" {
  135. response.Fail("请输入搜索词", c)
  136. return
  137. }
  138. userinfo := userService.GetInfoByClaims(c)
  139. data, err := report.SearchReport(userinfo, keyWord, pageIndex, pageSize)
  140. if err != nil {
  141. response.FailMsg("搜索报告出错", err.Error(), c)
  142. return
  143. }
  144. response.OkData("查询成功", data, c)
  145. return
  146. }
  147. // TickerData 报告详情获取指标数据
  148. func TickerData(c *gin.Context) {
  149. reqReportChapterId := c.DefaultQuery("report_chapter_id", "")
  150. if reqReportChapterId == "" {
  151. response.Fail("请输入章节ID", c)
  152. return
  153. }
  154. reportChapterId, err := strconv.Atoi(reqReportChapterId)
  155. if err != nil {
  156. response.Fail("章节ID格式有误", c)
  157. return
  158. }
  159. userinfo := userService.GetInfoByClaims(c)
  160. chapterDetail, err := report.GetTickerData(userinfo, reportChapterId)
  161. if err != nil {
  162. response.Fail(err.Error(), c)
  163. return
  164. }
  165. response.OkData("查询成功", chapterDetail, c)
  166. return
  167. }
  168. // RddpShareImg 获取报告分享图
  169. func RddpShareImg(c *gin.Context) {
  170. var req request.RddpReportShareImgReq
  171. if c.ShouldBind(&req) != nil {
  172. response.Fail("参数异常", c)
  173. return
  174. }
  175. defaultImg := utils.DEFAULT_REPORT_SHARE_BG_IMG
  176. if req.Source == "" {
  177. response.OkData("获取成功", defaultImg, c)
  178. return
  179. }
  180. imgUrl, err := services.GetDynamicShareImg(req.Source, req.Pars)
  181. if err != nil {
  182. response.FailData("获取分享海报失败", "获取分享海报失败, Err: "+err.Error(), c)
  183. return
  184. }
  185. if imgUrl == "" {
  186. imgUrl = defaultImg
  187. }
  188. response.OkData("获取成功", imgUrl, c)
  189. }
  190. // ReportPptImgList 报告中的ppt图片列表
  191. func ReportPptImgList(c *gin.Context) {
  192. reqReportId := c.DefaultQuery("report_id", "")
  193. if reqReportId == "" {
  194. response.Fail("请输入报告ID", c)
  195. return
  196. }
  197. reportId, err := strconv.Atoi(reqReportId)
  198. if err != nil {
  199. response.Fail("报告ID格式有误", c)
  200. return
  201. }
  202. reqReportChapterId := c.DefaultQuery("report_chapter_id", "0")
  203. reportChapterId, err := strconv.Atoi(reqReportChapterId)
  204. if err != nil {
  205. response.Fail("章节ID格式有误", c)
  206. return
  207. }
  208. pptImgList, err := report.GetReportPptImgListByReportIdAndReportChapterId(reportId, reportChapterId)
  209. if err != nil {
  210. response.FailMsg("获取ppt图片成功", err.Error(), c)
  211. return
  212. }
  213. response.OkData("获取成功", pptImgList, c)
  214. return
  215. }
  216. // VarietyReportList 品种类型研报列表
  217. func VarietyReportList(c *gin.Context) {
  218. reqClassifyId := c.DefaultQuery("classify_id", "")
  219. reqChartPermissionId := c.DefaultQuery("chart_permission_id", "")
  220. reqPageIndex := c.DefaultQuery("current_index", "1")
  221. reqPageSize := c.DefaultQuery("page_size", strconv.Itoa(utils.PageSize20))
  222. pageIndex, err := strconv.Atoi(reqPageIndex)
  223. if err != nil {
  224. response.Fail("请输入正确的条数限制", c)
  225. return
  226. }
  227. pageSize, err := strconv.Atoi(reqPageSize)
  228. if err != nil {
  229. response.Fail("请输入正确的页码", c)
  230. return
  231. }
  232. if reqChartPermissionId == "" {
  233. response.Fail("请输入权限ID", c)
  234. return
  235. }
  236. chartPermissionId, err := strconv.Atoi(reqChartPermissionId)
  237. if err != nil {
  238. response.Fail("权限ID格式错误", c)
  239. return
  240. }
  241. classifyId, err := strconv.Atoi(reqClassifyId)
  242. if err != nil {
  243. response.Fail("种类ID格式错误", c)
  244. return
  245. }
  246. userinfo := userService.GetInfoByClaims(c)
  247. list, err := report.GetVarietyReportList(userinfo, classifyId, chartPermissionId, pageIndex, pageSize)
  248. if err != nil {
  249. response.FailMsg("查看研报列表出错", err.Error(), c)
  250. return
  251. }
  252. response.OkData("查询成功", list, c)
  253. return
  254. }
  255. // RddpShareImg 获取报告分享图
  256. func ReportChapterSet(c *gin.Context) {
  257. var req request.ReportChapterSetReq
  258. if c.ShouldBind(&req) != nil {
  259. response.Fail("参数异常", c)
  260. return
  261. }
  262. userinfo := userService.GetInfoByClaims(c)
  263. err := user_report_chapter_set.ModifyReportChapterSet(req.IsClose, userinfo.UserID, req.TypeId)
  264. if err != nil {
  265. response.Fail("保存失败,err:"+err.Error(), c)
  266. return
  267. }
  268. response.Ok("保存成功", c)
  269. }