report.go 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531
  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. resp.Report = reportPdf
  317. resp.Status = utils.ReportPermissionStatusHas
  318. br.Msg = "查询成功"
  319. br.Ret = 200
  320. br.Success = true
  321. br.Data = resp
  322. }
  323. // @Title 今日研报列表
  324. // @Description 今日研报列表
  325. // @Success 200 {object} models.ReportDetailResp
  326. // @router /daily/list [get]
  327. func (this *ReportController) DailyList() {
  328. br := new(models.BaseResponse).Init()
  329. defer func() {
  330. this.Data["json"] = br
  331. this.ServeJSON()
  332. }()
  333. resp, err := services.GetReportDailyList()
  334. if err != nil {
  335. br.Msg = "研报列表查询失败"
  336. br.ErrMsg = "研报列表查询失败,系统异常,Err:" + err.Error()
  337. return
  338. }
  339. if resp.Ret != 200 {
  340. br.Msg = resp.Msg
  341. br.ErrMsg = resp.ErrMsg
  342. return
  343. }
  344. reportPdfList, err := models.GetReportPdfDailyList()
  345. if err != nil {
  346. br.Msg = "研报列表查询失败"
  347. br.ErrMsg = "研报列表查询失败,系统异常,Err:" + err.Error()
  348. return
  349. }
  350. reportList := resp.Data
  351. for _, v := range reportList.List {
  352. v.ReportType = utils.ReportTypeEta
  353. }
  354. for _, v := range reportPdfList {
  355. reportList.List = append(reportList.List, &models.ReportView{
  356. Id: v.ReportPdfId,
  357. ClassifyIdFirst: v.ClassifyIdFirst,
  358. ClassifyNameFirst: v.ClassifyNameFirst,
  359. ClassifyIdSecond: v.ClassifyIdSecond,
  360. ClassifyNameSecond: v.ClassifyNameSecond,
  361. Title: v.Title,
  362. Abstract: v.Abstract,
  363. Stage: v.Stage,
  364. Author: v.Author,
  365. ReportType: utils.ReportTypePdf,
  366. })
  367. }
  368. br.Data = reportList
  369. br.Msg = "查询成功"
  370. br.Ret = 200
  371. br.Success = true
  372. }
  373. // @Title 最新研报列表
  374. // @Description 最新研报列表
  375. // @Param PageSize query int true "每页数据条数"
  376. // @Param CurrentIndex query int true "当前页页码,从1开始"
  377. // @Success 200 {object} models.ReportDetailResp
  378. // @router /recent/list [get]
  379. func (this *ReportController) RecentList() {
  380. br := new(models.BaseResponse).Init()
  381. defer func() {
  382. this.Data["json"] = br
  383. this.ServeJSON()
  384. }()
  385. pageSize, _ := this.GetInt("PageSize")
  386. currentIndex, _ := this.GetInt("CurrentIndex")
  387. if pageSize <= 0 {
  388. pageSize = 3
  389. }
  390. resp, err := services.GetReportRecentList(currentIndex, pageSize)
  391. if err != nil {
  392. br.Msg = "研报列表查询失败"
  393. br.ErrMsg = "研报列表查询失败,系统异常,Err:" + err.Error()
  394. return
  395. }
  396. reportPdfList, err := models.GetReportPdfListByCondition("", []interface{}{}, 0, 3)
  397. if err != nil {
  398. br.Msg = "研报列表查询失败"
  399. br.ErrMsg = "研报列表查询失败,系统异常,Err:" + err.Error()
  400. return
  401. }
  402. reportList := resp.Data
  403. for _, v := range reportList.List {
  404. v.ReportType = utils.ReportTypeEta
  405. }
  406. for _, v := range reportPdfList {
  407. reportList.List = append(reportList.List, &models.ReportView{
  408. Id: v.ReportPdfId,
  409. ClassifyIdFirst: v.ClassifyIdFirst,
  410. ClassifyNameFirst: v.ClassifyNameFirst,
  411. ClassifyIdSecond: v.ClassifyIdSecond,
  412. ClassifyNameSecond: v.ClassifyNameSecond,
  413. PdfUrl: v.PdfUrl,
  414. Title: v.Title,
  415. Abstract: v.Abstract,
  416. Stage: v.Stage,
  417. Author: v.Author,
  418. ReportType: utils.ReportTypePdf,
  419. PublishTime: v.PublishTime.Format(utils.FormatDate),
  420. ModifyTime: v.ModifyTime,
  421. })
  422. }
  423. sort.Sort(models.ByPublishTimeReportView(reportList.List))
  424. endIdx := len(reportList.List)
  425. if endIdx > 3 {
  426. endIdx = 3
  427. }
  428. br.Data = reportList.List[:endIdx]
  429. br.Msg = "查询成功"
  430. br.Ret = 200
  431. br.Success = true
  432. }
  433. // @Title 研报列表
  434. // @Description 研报列表
  435. // @Param ReportId query int true "报告id"
  436. // @Param chartPermissionId query int true "品种ID"
  437. // @Param PageSize query int true "每页数据条数"
  438. // @Param CurrentIndex query int true "当前页页码,从1开始"
  439. // @Success 200 {object} models.ReportDetailResp
  440. // @router /search [get]
  441. func (this *ReportController) Search() {
  442. br := new(models.BaseResponse).Init()
  443. defer func() {
  444. this.Data["json"] = br
  445. this.ServeJSON()
  446. }()
  447. keyWord := this.GetString("KeyWord")
  448. pageSize, _ := this.GetInt("PageSize")
  449. currentIndex, _ := this.GetInt("CurrentIndex")
  450. if pageSize <= 0 {
  451. pageSize = utils.PageSize30
  452. }
  453. if keyWord == "" {
  454. br.Msg = "请输入关键字"
  455. return
  456. }
  457. reports, err := services.SearchReport(keyWord, currentIndex, pageSize)
  458. if err != nil {
  459. br.Msg = "研报列表查询失败"
  460. br.ErrMsg = "研报列表查询失败,系统异常,Err:" + err.Error()
  461. return
  462. }
  463. if reports.Ret != 200 {
  464. br.Msg = reports.Msg
  465. br.ErrMsg = reports.ErrMsg
  466. return
  467. }
  468. resp := new(response.ReportSearchViewResp)
  469. list := make([]*response.ReportSearchListView, 0)
  470. for _, v := range reports.Data.List {
  471. tmpReport := &response.ReportSearchListView{
  472. ReportId: v.ReportId,
  473. ReportChapterId: v.ReportChapterId,
  474. ClassifyIdFirst: v.ClassifyIdFirst,
  475. ClassifyNameFirst: v.ClassifyNameFirst,
  476. ClassifyIdSecond: v.ClassifyIdSecond,
  477. ClassifyNameSecond: v.ClassifyNameSecond,
  478. ReportChapterTypeId: v.ReportChapterTypeId,
  479. PublishTime: v.PublishTime.Format(utils.FormatDate),
  480. Title: v.Title,
  481. ContentSub: v.ContentSub,
  482. Abstract: v.Abstract,
  483. Stage: v.Stage,
  484. Author: v.Author,
  485. }
  486. if v.PublishTime.IsZero() {
  487. tmpReport.PublishTime = ""
  488. }
  489. list = append(list, tmpReport)
  490. }
  491. resp.List = list
  492. resp.Paging = reports.Data.Paging
  493. br.Data = resp
  494. br.Msg = "查询成功"
  495. br.Ret = 200
  496. br.Success = true
  497. }