report.go 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599
  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. // @Param PageSize query int true "每页数据条数"
  337. // @Param CurrentIndex query int true "当前页页码,从1开始"
  338. // @Success 200 {object} models.ReportDetailResp
  339. // @router /daily/list [get]
  340. func (this *ReportController) DailyList() {
  341. br := new(models.BaseResponse).Init()
  342. defer func() {
  343. this.Data["json"] = br
  344. this.ServeJSON()
  345. }()
  346. // 暂不使用分页
  347. pageSize, _ := this.GetInt("PageSize")
  348. currentIndex, _ := this.GetInt("CurrentIndex")
  349. if pageSize <= 0 {
  350. pageSize = utils.PageSize20
  351. }
  352. if currentIndex <= 0 {
  353. currentIndex = 1
  354. }
  355. resp, err := services.GetReportDailyList()
  356. if err != nil {
  357. br.Msg = "研报列表查询失败"
  358. br.ErrMsg = "研报列表查询失败,系统异常,Err:" + err.Error()
  359. return
  360. }
  361. if resp.Ret != 200 {
  362. br.Msg = resp.Msg
  363. br.ErrMsg = resp.ErrMsg
  364. return
  365. }
  366. reportPdfList, err := models.GetReportPdfDailyList()
  367. if err != nil {
  368. br.Msg = "研报列表查询失败"
  369. br.ErrMsg = "研报列表查询失败,系统异常,Err:" + err.Error()
  370. return
  371. }
  372. reportList := resp.Data
  373. for _, v := range reportList.List {
  374. v.ReportType = utils.ReportTypeEta
  375. }
  376. var classifyIds []int
  377. for _, v := range reportPdfList {
  378. classifyIds = append(classifyIds, v.ClassifyIdSecond)
  379. }
  380. classifyResp, err := services.GetFirstChartPermission(classifyIds)
  381. if err != nil {
  382. br.Msg = "研报列表查询失败"
  383. br.ErrMsg = "研报列表查询失败,系统异常,Err:" + err.Error()
  384. return
  385. }
  386. if classifyResp.Ret != 200 {
  387. br.Msg = classifyResp.Msg
  388. br.ErrMsg = classifyResp.ErrMsg
  389. return
  390. }
  391. classifyPermissionMap := make(map[int][]string)
  392. for _, v := range classifyResp.Data {
  393. classifyPermissionMap[v.ClassifyId] = v.PermissionNames
  394. }
  395. for _, v := range reportPdfList {
  396. reportList.List = append(reportList.List, &models.ReportView{
  397. Id: v.ReportPdfId,
  398. ClassifyIdFirst: v.ClassifyIdFirst,
  399. ClassifyNameFirst: v.ClassifyNameFirst,
  400. ClassifyIdSecond: v.ClassifyIdSecond,
  401. ClassifyNameSecond: v.ClassifyNameSecond,
  402. PermissionNames: classifyPermissionMap[v.ClassifyIdSecond],
  403. PdfUrl: v.PdfUrl,
  404. Title: v.Title,
  405. Abstract: v.Abstract,
  406. Stage: v.Stage,
  407. Author: v.Author,
  408. ReportType: utils.ReportTypePdf,
  409. PublishTime: v.PublishTime.Format(utils.FormatDate),
  410. ModifyTime: v.ModifyTime,
  411. })
  412. }
  413. br.Data = reportList
  414. br.Msg = "查询成功"
  415. br.Ret = 200
  416. br.Success = true
  417. }
  418. // @Title 最新研报列表
  419. // @Description 最新研报列表
  420. // @Param PageSize query int true "每页数据条数"
  421. // @Param CurrentIndex query int true "当前页页码,从1开始"
  422. // @Success 200 {object} models.ReportDetailResp
  423. // @router /recent/list [get]
  424. func (this *ReportController) RecentList() {
  425. br := new(models.BaseResponse).Init()
  426. defer func() {
  427. this.Data["json"] = br
  428. this.ServeJSON()
  429. }()
  430. pageSize, _ := this.GetInt("PageSize")
  431. currentIndex, _ := this.GetInt("CurrentIndex")
  432. if pageSize <= 0 {
  433. pageSize = 3
  434. }
  435. resp, err := services.GetReportRecentList(currentIndex, pageSize)
  436. if err != nil {
  437. br.Msg = "研报列表查询失败"
  438. br.ErrMsg = "研报列表查询失败,系统异常,Err:" + err.Error()
  439. return
  440. }
  441. // 查询已发布的pdf
  442. condition := ` AND state=1 `
  443. reportPdfList, err := models.GetReportPdfListByCondition(condition, []interface{}{}, 0, 3)
  444. if err != nil {
  445. br.Msg = "研报列表查询失败"
  446. br.ErrMsg = "研报列表查询失败,系统异常,Err:" + err.Error()
  447. return
  448. }
  449. reportList := resp.Data
  450. for _, v := range reportList.List {
  451. v.ReportType = utils.ReportTypeEta
  452. }
  453. var classifyIds []int
  454. for _, v := range reportPdfList {
  455. classifyIds = append(classifyIds, v.ClassifyIdSecond)
  456. }
  457. classifyResp, err := services.GetFirstChartPermission(classifyIds)
  458. if err != nil {
  459. br.Msg = "研报列表查询失败"
  460. br.ErrMsg = "研报列表查询失败,系统异常,Err:" + err.Error()
  461. return
  462. }
  463. if classifyResp.Ret != 200 {
  464. br.Msg = classifyResp.Msg
  465. br.ErrMsg = classifyResp.ErrMsg
  466. return
  467. }
  468. classifyPermissionMap := make(map[int][]string)
  469. for _, v := range classifyResp.Data {
  470. classifyPermissionMap[v.ClassifyId] = v.PermissionNames
  471. }
  472. for _, v := range reportPdfList {
  473. reportList.List = append(reportList.List, &models.ReportView{
  474. Id: v.ReportPdfId,
  475. ClassifyIdFirst: v.ClassifyIdFirst,
  476. ClassifyNameFirst: v.ClassifyNameFirst,
  477. ClassifyIdSecond: v.ClassifyIdSecond,
  478. ClassifyNameSecond: v.ClassifyNameSecond,
  479. PermissionNames: classifyPermissionMap[v.ClassifyIdSecond],
  480. PdfUrl: v.PdfUrl,
  481. Title: v.Title,
  482. Abstract: v.Abstract,
  483. Stage: v.Stage,
  484. Author: v.Author,
  485. ReportType: utils.ReportTypePdf,
  486. PublishTime: v.PublishTime.Format(utils.FormatDateTime),
  487. ModifyTime: v.ModifyTime,
  488. })
  489. }
  490. sort.Sort(models.ByPublishTimeReportView(reportList.List))
  491. endIdx := len(reportList.List)
  492. if endIdx > 3 {
  493. endIdx = 3
  494. }
  495. br.Data = reportList.List[:endIdx]
  496. br.Msg = "查询成功"
  497. br.Ret = 200
  498. br.Success = true
  499. }
  500. // @Title 研报列表
  501. // @Description 研报列表
  502. // @Param ReportId query int true "报告id"
  503. // @Param chartPermissionId query int true "品种ID"
  504. // @Param PageSize query int true "每页数据条数"
  505. // @Param CurrentIndex query int true "当前页页码,从1开始"
  506. // @Success 200 {object} models.ReportDetailResp
  507. // @router /search [get]
  508. func (this *ReportController) Search() {
  509. br := new(models.BaseResponse).Init()
  510. defer func() {
  511. this.Data["json"] = br
  512. this.ServeJSON()
  513. }()
  514. keyWord := this.GetString("KeyWord")
  515. pageSize, _ := this.GetInt("PageSize")
  516. currentIndex, _ := this.GetInt("CurrentIndex")
  517. if pageSize <= 0 {
  518. pageSize = utils.PageSize30
  519. }
  520. if keyWord == "" {
  521. br.Msg = "请输入关键字"
  522. return
  523. }
  524. reports, err := services.SearchReport(keyWord, currentIndex, pageSize)
  525. if err != nil {
  526. br.Msg = "研报列表查询失败"
  527. br.ErrMsg = "研报列表查询失败,系统异常,Err:" + err.Error()
  528. return
  529. }
  530. if reports.Ret != 200 {
  531. br.Msg = reports.Msg
  532. br.ErrMsg = reports.ErrMsg
  533. return
  534. }
  535. resp := new(response.ReportSearchViewResp)
  536. list := make([]*response.ReportSearchListView, 0)
  537. for _, v := range reports.Data.List {
  538. tmpReport := &response.ReportSearchListView{
  539. ReportId: v.ReportId,
  540. ReportChapterId: v.ReportChapterId,
  541. ClassifyIdFirst: v.ClassifyIdFirst,
  542. ClassifyNameFirst: v.ClassifyNameFirst,
  543. ClassifyIdSecond: v.ClassifyIdSecond,
  544. ClassifyNameSecond: v.ClassifyNameSecond,
  545. ReportChapterTypeId: v.ReportChapterTypeId,
  546. PublishTime: v.PublishTime.Format(utils.FormatDate),
  547. Title: v.Title,
  548. ContentSub: v.ContentSub,
  549. Abstract: v.Abstract,
  550. Stage: v.Stage,
  551. Author: v.Author,
  552. }
  553. if v.PublishTime.IsZero() {
  554. tmpReport.PublishTime = ""
  555. }
  556. list = append(list, tmpReport)
  557. }
  558. resp.List = list
  559. resp.Paging = reports.Data.Paging
  560. br.Data = resp
  561. br.Msg = "查询成功"
  562. br.Ret = 200
  563. br.Success = true
  564. }