report.go 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589
  1. package controllers
  2. import (
  3. "eta/eta_mini_api/models"
  4. "eta/eta_mini_api/models/response"
  5. "eta/eta_mini_api/services"
  6. "eta/eta_mini_api/utils"
  7. "sort"
  8. "time"
  9. "github.com/rdlucklib/rdluck_tools/paging"
  10. )
  11. type ReportController struct {
  12. BaseAuthController
  13. }
  14. // @Title 研报详情
  15. // @Description 研报详情接口
  16. // @Param ReportId query int true "报告id"
  17. // @Success 200 {object} models.ReportDetailResp
  18. // @router /detail [get]
  19. func (this *ReportController) Detail() {
  20. br := new(models.BaseResponse).Init()
  21. defer func() {
  22. this.Data["json"] = br
  23. this.ServeJSON()
  24. }()
  25. reportId, _ := this.GetInt("ReportId")
  26. if reportId <= 0 {
  27. br.Msg = "报告不存在"
  28. return
  29. }
  30. user := this.User
  31. if user == nil {
  32. // 如果没有用户没有绑定信息,单独处理
  33. resp, er := services.GetReportDetailNoUser(reportId)
  34. if er != nil {
  35. br.Msg = "查询报告详情失败"
  36. br.ErrMsg = "查询报告失败,系统异常,Err:" + er.Error()
  37. return
  38. }
  39. if resp.Ret != 200 {
  40. br.Msg = resp.Msg
  41. br.ErrMsg = resp.ErrMsg
  42. return
  43. }
  44. br.Msg = "查询成功"
  45. br.Data = resp.Data
  46. br.Success = true
  47. br.Ret = 200
  48. return
  49. }
  50. result, err := services.GetReportDetail(reportId, user.UserId)
  51. if err != nil {
  52. br.Msg = "查询报告详情失败"
  53. br.ErrMsg = "查询报告失败,系统异常,Err:" + err.Error()
  54. return
  55. }
  56. if result.Ret == 403 {
  57. br.Msg = result.Msg
  58. br.ErrMsg = result.ErrMsg
  59. return
  60. }
  61. if result.Ret == 200 && result.Data.Report == nil {
  62. // 后台没有这个报告,那么尝试删除我的收藏
  63. models.DeleteMyReportByUserIdAndReportId(user.UserId, reportId, utils.ReportTypeEta)
  64. br.Msg = "该报告已删除或不存在,请刷新页面"
  65. return
  66. }
  67. count, err := models.GetMyReportCountByUserIdAndReportId(user.UserId, reportId, utils.ReportTypeEta)
  68. if err != nil {
  69. br.Msg = "查询收藏数量失败"
  70. br.ErrMsg = "查询收藏数量失败,Err:" + err.Error()
  71. return
  72. }
  73. if count > 0 {
  74. result.Data.IsCollect = true
  75. } else {
  76. result.Data.IsCollect = false
  77. }
  78. if user.UserId != 0 {
  79. result.Data.IsSignIn = true
  80. }
  81. br.Msg = "查询成功"
  82. br.Success = true
  83. br.Ret = 200
  84. br.Data = result.Data
  85. }
  86. // @Title 研报列表
  87. // @Description 研报列表
  88. // @Param ChartPermissionId query int true "品种ID"
  89. // @Param Level query int true "品种层级"
  90. // @Param PageSize query int true "每页数据条数"
  91. // @Param CurrentIndex query int true "当前页页码,从1开始"
  92. // @Param RangeType query string true "范围类型,1-一天内,2-一周内,3-半年内"
  93. // @Param ClassifyId query int true "分类id"
  94. // @Success 200 {object} response.ReportList
  95. // @router /list [get]
  96. func (this *ReportController) List() {
  97. br := new(models.BaseResponse).Init()
  98. defer func() {
  99. this.Data["json"] = br
  100. this.ServeJSON()
  101. }()
  102. pageSize, _ := this.GetInt("PageSize")
  103. currentIndex, _ := this.GetInt("CurrentIndex")
  104. chartPermissionId, _ := this.GetInt("ChartPermissionId")
  105. level, _ := this.GetInt("Level")
  106. rangeType, _ := this.GetInt("RangeType")
  107. classifyId, _ := this.GetInt("ClassifyId")
  108. reports, err := services.GetReportList(chartPermissionId, level, rangeType, classifyId, currentIndex, pageSize)
  109. if err != nil {
  110. br.Msg = "研报列表查询失败"
  111. br.ErrMsg = "研报列表查询失败,系统异常,Err:" + err.Error()
  112. return
  113. }
  114. if reports.Ret != 200 {
  115. br.Msg = reports.Msg
  116. br.ErrMsg = reports.ErrMsg
  117. return
  118. }
  119. br.Data = reports.Data
  120. br.Msg = "查询成功"
  121. br.Ret = 200
  122. br.Success = true
  123. }
  124. // @Title pdf研报列表
  125. // @Description pdf研报列表
  126. // @Param ChartPermissionId query int true "品种ID"
  127. // @Param PageSize query int true "每页数据条数"
  128. // @Param CurrentIndex query int true "当前页页码,从1开始"
  129. // @Param RangeType query int true "范围类型,1-一天内,2-一周内,3-半年内"
  130. // @Param ClassifyId query int true "二级分类id"
  131. // @Success 200 {object} response.ReportList
  132. // @router /pdf/list [get]
  133. func (this *ReportController) PdfList() {
  134. br := new(models.BaseResponse).Init()
  135. defer func() {
  136. this.Data["json"] = br
  137. this.ServeJSON()
  138. }()
  139. pageSize, _ := this.GetInt("PageSize")
  140. currentIndex, _ := this.GetInt("CurrentIndex")
  141. chartPermissionId, _ := this.GetInt("ChartPermissionId")
  142. classifyId, _ := this.GetInt("ClassifyId")
  143. rangeType, _ := this.GetInt("RangeType")
  144. if pageSize <= 0 {
  145. pageSize = utils.PageSize20
  146. }
  147. if currentIndex <= 0 {
  148. currentIndex = 1
  149. }
  150. if chartPermissionId <= 0 {
  151. br.Msg = "请输入品种ID"
  152. return
  153. }
  154. var condition string
  155. var pars []interface{}
  156. switch rangeType {
  157. case 1:
  158. condition += ` AND DATE(publish_time)=DATE(NOW()) `
  159. case 2:
  160. condition += ` AND DATE(publish_time) BETWEEN DATE_SUB(NOW(),INTERVAL 1 WEEK) AND NOW() `
  161. case 3:
  162. condition += ` AND DATE(publish_time) BETWEEN DATE_SUB(NOW(),INTERVAL 6 MONTH) AND NOW() `
  163. }
  164. startSize := utils.StartIndex(currentIndex, pageSize)
  165. if classifyId != 0 {
  166. condition += ` AND classify_id_second=?`
  167. pars = append(pars, classifyId)
  168. } else if chartPermissionId != 0 {
  169. resp, err := services.GetClassifyListByChartPermission(chartPermissionId)
  170. if err != nil {
  171. br.Msg = "获取分类失败"
  172. br.ErrMsg = "获取分类失败,系统异常,Err:" + err.Error()
  173. return
  174. }
  175. if resp.Ret != 200 {
  176. br.Msg = resp.Msg
  177. br.ErrMsg = resp.ErrMsg
  178. return
  179. }
  180. classifyList := resp.Data
  181. condition += ` AND classify_id_second IN (` + utils.GetOrmReplaceHolder(len(classifyList)) + `)`
  182. for _, item := range classifyList {
  183. pars = append(pars, item.Id)
  184. }
  185. }
  186. total, err := models.GetReportPdfCountByCondition(condition, pars)
  187. if err != nil {
  188. br.Msg = "研报列表查询失败"
  189. br.ErrMsg = "研报列表统计查询失败,系统异常,Err:" + err.Error()
  190. return
  191. }
  192. reportPdfList, err := models.GetReportPdfListByCondition(condition, pars, startSize, pageSize)
  193. if err != nil {
  194. br.Msg = "研报列表查询失败"
  195. br.ErrMsg = "研报列表查询失败,系统异常,Err:" + err.Error()
  196. return
  197. }
  198. page := paging.GetPaging(currentIndex, pageSize, total)
  199. resp := new(response.ReportPdfResp)
  200. resp.List = reportPdfList
  201. resp.Paging = page
  202. br.Msg = "查询成功"
  203. br.Ret = 200
  204. br.Success = true
  205. br.Data = resp
  206. }
  207. // @Title pdf研报详情
  208. // @Description pdf研报详情
  209. // @Param ReportPdfId query int true "品种ID"
  210. // @Success 200 {object} response.ReportList
  211. // @router /pdf/detail [get]
  212. func (this *ReportController) PdfDetail() {
  213. br := new(models.BaseResponse).Init()
  214. defer func() {
  215. this.Data["json"] = br
  216. this.ServeJSON()
  217. }()
  218. user := this.User
  219. // 有效期是否到期
  220. var vailStatus int
  221. if user.Status == utils.UserStatusFormal || user.Status == utils.UserStatusNo {
  222. if user.ValidEndTime.After(time.Now()) && user.ValidStartTime.Before(time.Now()) {
  223. vailStatus = 2
  224. } else {
  225. // 不在有效期时间则设置为过期, 将用户状态禁用
  226. vailStatus = 1
  227. user.Status = utils.UserStatusNo
  228. }
  229. }
  230. reportPdfId, _ := this.GetInt("ReportPdfId")
  231. if reportPdfId <= 0 {
  232. br.Msg = "研报不存在或已删除"
  233. return
  234. }
  235. reportPdf, err := models.GetReportPdfById(reportPdfId)
  236. if err != nil {
  237. if err.Error() == utils.ErrNoRow() {
  238. br.Msg = "研报不存在或已删除"
  239. return
  240. }
  241. br.Msg = "研报不存在或已删除"
  242. br.ErrMsg = "研报不存在或已删除,系统异常,Err:" + err.Error()
  243. return
  244. }
  245. permissionResp, err := services.GetChartPermissionListByClassifyId(reportPdf.ClassifyIdSecond, 0)
  246. if err != nil {
  247. br.Msg = "研报不存在或已删除"
  248. br.ErrMsg = "获取权限失败,系统异常,Err:" + err.Error()
  249. return
  250. }
  251. if permissionResp.Ret != 200 {
  252. br.Msg = permissionResp.Msg
  253. br.ErrMsg = permissionResp.ErrMsg
  254. return
  255. }
  256. var IsHas bool
  257. var IsPublic bool
  258. permissionMap := make(map[int]struct{})
  259. for _, v := range permissionResp.Data {
  260. if v.ChartPermissionId == 1 {
  261. IsPublic = true
  262. }
  263. permissionMap[v.ChartPermissionId] = struct{}{}
  264. }
  265. resp := new(response.ReportPdfDetailResp)
  266. if !IsPublic {
  267. // 如果是私有报告,用户权限过期直接返回有效期已过
  268. if vailStatus == 1 {
  269. resp.Report = reportPdf
  270. resp.Status = utils.ReportPermissionStatusExpired
  271. br.Ret = 200
  272. br.Data = resp
  273. br.Msg = "用户权限不足"
  274. return
  275. }
  276. // 如果被禁用或是潜在用户,直接返回无阅读报告权限
  277. if user.Status == utils.UserStatusNo || user.Status == utils.UserStatusPotential {
  278. resp.Report = reportPdf
  279. resp.Status = utils.ReportPermissionStatusNo
  280. br.Ret = 200
  281. br.Data = resp
  282. br.Msg = "用户权限不足"
  283. return
  284. }
  285. userChartPermissionIds, err := models.GetUserChartPermissionIdByUserId(user.UserId)
  286. if err != nil {
  287. br.Msg = "获取用户权限失败"
  288. br.ErrMsg = "获取用户权限失败,Err:" + err.Error()
  289. return
  290. }
  291. if len(userChartPermissionIds) == 0 {
  292. resp.Report = reportPdf
  293. resp.Status = utils.ReportPermissionStatusNo
  294. br.Ret = 200
  295. br.Data = resp
  296. br.Msg = "用户权限不足"
  297. return
  298. }
  299. for _, v := range userChartPermissionIds {
  300. if _, ok := permissionMap[v]; ok {
  301. IsHas = true
  302. break
  303. }
  304. }
  305. if !IsHas {
  306. resp.Report = reportPdf
  307. resp.Status = utils.ReportPermissionStatusNoPermission
  308. br.Ret = 200
  309. br.Data = resp
  310. br.Msg = "用户权限不足"
  311. return
  312. }
  313. } else {
  314. reportPdf.IsPublic = IsPublic
  315. }
  316. count, err := models.GetMyReportCountByUserIdAndReportId(user.UserId, reportPdf.ReportPdfId, utils.ReportTypePdf)
  317. if err != nil {
  318. br.Msg = "获取研报详情失败"
  319. br.ErrMsg = "获取用户收藏记录失败,Err:" + err.Error()
  320. return
  321. }
  322. if count > 0 {
  323. reportPdf.IsCollect = true
  324. } else {
  325. reportPdf.IsCollect = false
  326. }
  327. resp.Report = reportPdf
  328. resp.Status = utils.ReportPermissionStatusHas
  329. br.Msg = "查询成功"
  330. br.Ret = 200
  331. br.Success = true
  332. br.Data = resp
  333. }
  334. // @Title 今日研报列表
  335. // @Description 今日研报列表
  336. // @Success 200 {object} models.ReportDetailResp
  337. // @router /daily/list [get]
  338. func (this *ReportController) DailyList() {
  339. br := new(models.BaseResponse).Init()
  340. defer func() {
  341. this.Data["json"] = br
  342. this.ServeJSON()
  343. }()
  344. resp, err := services.GetReportDailyList()
  345. if err != nil {
  346. br.Msg = "研报列表查询失败"
  347. br.ErrMsg = "研报列表查询失败,系统异常,Err:" + err.Error()
  348. return
  349. }
  350. if resp.Ret != 200 {
  351. br.Msg = resp.Msg
  352. br.ErrMsg = resp.ErrMsg
  353. return
  354. }
  355. reportPdfList, err := models.GetReportPdfDailyList()
  356. if err != nil {
  357. br.Msg = "研报列表查询失败"
  358. br.ErrMsg = "研报列表查询失败,系统异常,Err:" + err.Error()
  359. return
  360. }
  361. reportList := resp.Data
  362. for _, v := range reportList.List {
  363. v.ReportType = utils.ReportTypeEta
  364. }
  365. var classifyIds []int
  366. for _, v := range reportPdfList {
  367. classifyIds = append(classifyIds, v.ClassifyIdSecond)
  368. }
  369. classifyResp, err := services.GetFirstChartPermission(classifyIds)
  370. if err != nil {
  371. br.Msg = "研报列表查询失败"
  372. br.ErrMsg = "研报列表查询失败,系统异常,Err:" + err.Error()
  373. return
  374. }
  375. if classifyResp.Ret != 200 {
  376. br.Msg = classifyResp.Msg
  377. br.ErrMsg = classifyResp.ErrMsg
  378. return
  379. }
  380. classifyPermissionMap := make(map[int][]string)
  381. for _, v := range classifyResp.Data {
  382. classifyPermissionMap[v.ClassifyId] = v.PermissionNames
  383. }
  384. for _, v := range reportPdfList {
  385. reportList.List = append(reportList.List, &models.ReportView{
  386. Id: v.ReportPdfId,
  387. ClassifyIdFirst: v.ClassifyIdFirst,
  388. ClassifyNameFirst: v.ClassifyNameFirst,
  389. ClassifyIdSecond: v.ClassifyIdSecond,
  390. ClassifyNameSecond: v.ClassifyNameSecond,
  391. PermissionNames: classifyPermissionMap[v.ClassifyIdSecond],
  392. PdfUrl: v.PdfUrl,
  393. Title: v.Title,
  394. Abstract: v.Abstract,
  395. Stage: v.Stage,
  396. Author: v.Author,
  397. ReportType: utils.ReportTypePdf,
  398. PublishTime: v.PublishTime.Format(utils.FormatDate),
  399. ModifyTime: v.ModifyTime,
  400. })
  401. }
  402. br.Data = reportList
  403. br.Msg = "查询成功"
  404. br.Ret = 200
  405. br.Success = true
  406. }
  407. // @Title 最新研报列表
  408. // @Description 最新研报列表
  409. // @Param PageSize query int true "每页数据条数"
  410. // @Param CurrentIndex query int true "当前页页码,从1开始"
  411. // @Success 200 {object} models.ReportDetailResp
  412. // @router /recent/list [get]
  413. func (this *ReportController) RecentList() {
  414. br := new(models.BaseResponse).Init()
  415. defer func() {
  416. this.Data["json"] = br
  417. this.ServeJSON()
  418. }()
  419. pageSize, _ := this.GetInt("PageSize")
  420. currentIndex, _ := this.GetInt("CurrentIndex")
  421. if pageSize <= 0 {
  422. pageSize = 3
  423. }
  424. resp, err := services.GetReportRecentList(currentIndex, pageSize)
  425. if err != nil {
  426. br.Msg = "研报列表查询失败"
  427. br.ErrMsg = "研报列表查询失败,系统异常,Err:" + err.Error()
  428. return
  429. }
  430. // 查询已发布的pdf
  431. condition := ` AND state=1 `
  432. reportPdfList, err := models.GetReportPdfListByCondition(condition, []interface{}{}, 0, 3)
  433. if err != nil {
  434. br.Msg = "研报列表查询失败"
  435. br.ErrMsg = "研报列表查询失败,系统异常,Err:" + err.Error()
  436. return
  437. }
  438. reportList := resp.Data
  439. for _, v := range reportList.List {
  440. v.ReportType = utils.ReportTypeEta
  441. }
  442. var classifyIds []int
  443. for _, v := range reportPdfList {
  444. classifyIds = append(classifyIds, v.ClassifyIdSecond)
  445. }
  446. classifyResp, err := services.GetFirstChartPermission(classifyIds)
  447. if err != nil {
  448. br.Msg = "研报列表查询失败"
  449. br.ErrMsg = "研报列表查询失败,系统异常,Err:" + err.Error()
  450. return
  451. }
  452. if classifyResp.Ret != 200 {
  453. br.Msg = classifyResp.Msg
  454. br.ErrMsg = classifyResp.ErrMsg
  455. return
  456. }
  457. classifyPermissionMap := make(map[int][]string)
  458. for _, v := range classifyResp.Data {
  459. classifyPermissionMap[v.ClassifyId] = v.PermissionNames
  460. }
  461. for _, v := range reportPdfList {
  462. reportList.List = append(reportList.List, &models.ReportView{
  463. Id: v.ReportPdfId,
  464. ClassifyIdFirst: v.ClassifyIdFirst,
  465. ClassifyNameFirst: v.ClassifyNameFirst,
  466. ClassifyIdSecond: v.ClassifyIdSecond,
  467. ClassifyNameSecond: v.ClassifyNameSecond,
  468. PermissionNames: classifyPermissionMap[v.ClassifyIdSecond],
  469. PdfUrl: v.PdfUrl,
  470. Title: v.Title,
  471. Abstract: v.Abstract,
  472. Stage: v.Stage,
  473. Author: v.Author,
  474. ReportType: utils.ReportTypePdf,
  475. PublishTime: v.PublishTime.Format(utils.FormatDateTime),
  476. ModifyTime: v.ModifyTime,
  477. })
  478. }
  479. sort.Sort(models.ByPublishTimeReportView(reportList.List))
  480. endIdx := len(reportList.List)
  481. if endIdx > 3 {
  482. endIdx = 3
  483. }
  484. br.Data = reportList.List[:endIdx]
  485. br.Msg = "查询成功"
  486. br.Ret = 200
  487. br.Success = true
  488. }
  489. // @Title 研报列表
  490. // @Description 研报列表
  491. // @Param ReportId query int true "报告id"
  492. // @Param chartPermissionId query int true "品种ID"
  493. // @Param PageSize query int true "每页数据条数"
  494. // @Param CurrentIndex query int true "当前页页码,从1开始"
  495. // @Success 200 {object} models.ReportDetailResp
  496. // @router /search [get]
  497. func (this *ReportController) Search() {
  498. br := new(models.BaseResponse).Init()
  499. defer func() {
  500. this.Data["json"] = br
  501. this.ServeJSON()
  502. }()
  503. keyWord := this.GetString("KeyWord")
  504. pageSize, _ := this.GetInt("PageSize")
  505. currentIndex, _ := this.GetInt("CurrentIndex")
  506. if pageSize <= 0 {
  507. pageSize = utils.PageSize30
  508. }
  509. if keyWord == "" {
  510. br.Msg = "请输入关键字"
  511. return
  512. }
  513. reports, err := services.SearchReport(keyWord, currentIndex, pageSize)
  514. if err != nil {
  515. br.Msg = "研报列表查询失败"
  516. br.ErrMsg = "研报列表查询失败,系统异常,Err:" + err.Error()
  517. return
  518. }
  519. if reports.Ret != 200 {
  520. br.Msg = reports.Msg
  521. br.ErrMsg = reports.ErrMsg
  522. return
  523. }
  524. resp := new(response.ReportSearchViewResp)
  525. list := make([]*response.ReportSearchListView, 0)
  526. for _, v := range reports.Data.List {
  527. tmpReport := &response.ReportSearchListView{
  528. ReportId: v.ReportId,
  529. ReportChapterId: v.ReportChapterId,
  530. ClassifyIdFirst: v.ClassifyIdFirst,
  531. ClassifyNameFirst: v.ClassifyNameFirst,
  532. ClassifyIdSecond: v.ClassifyIdSecond,
  533. ClassifyNameSecond: v.ClassifyNameSecond,
  534. ReportChapterTypeId: v.ReportChapterTypeId,
  535. PublishTime: v.PublishTime.Format(utils.FormatDate),
  536. Title: v.Title,
  537. ContentSub: v.ContentSub,
  538. Abstract: v.Abstract,
  539. Stage: v.Stage,
  540. Author: v.Author,
  541. }
  542. if v.PublishTime.IsZero() {
  543. tmpReport.PublishTime = ""
  544. }
  545. list = append(list, tmpReport)
  546. }
  547. resp.List = list
  548. resp.Paging = reports.Data.Paging
  549. br.Data = resp
  550. br.Msg = "查询成功"
  551. br.Ret = 200
  552. br.Success = true
  553. }