report.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "hongze/hongze_api/cache"
  5. "hongze/hongze_api/models"
  6. "hongze/hongze_api/services"
  7. "hongze/hongze_api/utils"
  8. "html"
  9. "strconv"
  10. "strings"
  11. "time"
  12. )
  13. //报告
  14. type ReportController struct {
  15. BaseAuthController
  16. }
  17. //报告
  18. type ReportCommonController struct {
  19. BaseCommonController
  20. }
  21. // @Title 日评详情
  22. // @Description 日评详情接口
  23. // @Param ReportId query int true "报告id"
  24. // @Success 200 {object} models.ReportDetailResp
  25. // @router /detail [get]
  26. func (this *ReportController) Detail() {
  27. br := new(models.BaseResponse).Init()
  28. defer func() {
  29. this.Data["json"] = br
  30. this.ServeJSON()
  31. }()
  32. user := this.User
  33. if user == nil {
  34. br.Msg = "请登录"
  35. br.ErrMsg = "请登录,用户信息为空"
  36. br.Ret = 408
  37. return
  38. }
  39. var status int
  40. var msg string
  41. reportId, err := this.GetInt("ReportId")
  42. if err != nil {
  43. br.Msg = "参数获取失败"
  44. br.ErrMsg = "参数获取失败,Err:" + err.Error()
  45. return
  46. }
  47. if reportId <= 0 {
  48. br.Msg = "参数错误"
  49. br.ErrMsg = "参数错误,报告id小于等于0"
  50. return
  51. }
  52. report, err := models.GetReportById(reportId)
  53. if err != nil {
  54. br.Msg = "该报告已删除"
  55. br.ErrMsg = "获取报告详情失败,Err:" + err.Error()
  56. return
  57. }
  58. if report == nil {
  59. status = 1
  60. msg = "报告不存在"
  61. }
  62. report.ContentSub = html.UnescapeString(report.ContentSub)
  63. report.Content = html.UnescapeString(report.Content)
  64. productId := 0
  65. maxPermissionCount := 0
  66. if strings.Contains(report.ClassifyNameFirst, "权益研报") {
  67. productId = 2
  68. } else {
  69. productId = 1
  70. }
  71. maxPermissionCount, err = models.GetDefaultChartPermissionCountByCache(productId)
  72. if err != nil {
  73. br.Msg = "获取报告详情失败"
  74. br.ErrMsg = "获取产品默认最大权限数量失败,Err:" + err.Error()
  75. return
  76. }
  77. utils.FileLog.Info("report.detail %d,%d", user.CompanyId, productId)
  78. company, err := models.GetCompanyProductById(user.CompanyId, productId)
  79. if err != nil {
  80. if err.Error() != utils.ErrNoRow() {
  81. br.Msg = "获取报告详情失败"
  82. br.ErrMsg = "获取用户管理企业信息失败,Err:" + err.Error()
  83. return
  84. } else {
  85. status = 2
  86. msg = "您还未开通权限,如有需要请联系对口销售"
  87. }
  88. }
  89. if company == nil {
  90. status = 2
  91. msg = "您还未开通权限,如有需要请联系对口销售"
  92. } else {
  93. if company.Status == utils.COMPANY_STATUS_LOSE ||
  94. company.Status == utils.COMPANY_STATUS_FREEZE {
  95. status = 2
  96. msg = "您还未开通权限,如有需要请联系对口销售"
  97. }
  98. }
  99. if productId == 1 {
  100. reportType := "rddp"
  101. reportPermissionList, err := models.GetReportVarietyListByUserIdExt(user.UserId, reportType) //获取客户拥有权限的报告id
  102. if err != nil {
  103. if err.Error() != utils.ErrNoRow() {
  104. br.Msg = "获取报告详情失败"
  105. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  106. return
  107. } else {
  108. status = 2
  109. msg = "您还未开通权限,如有需要请联系对口销售"
  110. }
  111. }
  112. if len(reportPermissionList) == 0 {
  113. status = 2
  114. msg = "您还未开通权限,如有需要请联系对口销售"
  115. }
  116. permissionMap := make(map[int]int)
  117. for _, v := range reportPermissionList {
  118. if _, ok := permissionMap[v.ReportChapterTypeId]; !ok {
  119. permissionMap[v.ReportChapterTypeId] = v.ReportChapterTypeId
  120. }
  121. }
  122. if _, ok := permissionMap[reportId]; !ok {
  123. tips := ""
  124. status = 2
  125. classifyNameSecond := report.ClassifyNameSecond
  126. if strings.Contains(classifyNameSecond, "宏观商品复盘") ||
  127. strings.Contains(classifyNameSecond, "股债日评") ||
  128. strings.Contains(classifyNameSecond, "每日经济数据备忘录") {
  129. tips = "宏观"
  130. } else if strings.Contains(classifyNameSecond, "知白守黑日评") ||
  131. strings.Contains(classifyNameSecond, "动力煤数据点评") {
  132. tips = "黑色"
  133. } else if strings.Contains(classifyNameSecond, "化里化外日评") ||
  134. strings.Contains(classifyNameSecond, "EIA原油库存点评") ||
  135. strings.Contains(classifyNameSecond, "苯乙烯数据点评") ||
  136. strings.Contains(classifyNameSecond, "聚酯数据点评") {
  137. tips = "化工"
  138. } else if strings.Contains(classifyNameSecond, "有声有色日度闲篇") {
  139. tips = "有色"
  140. }
  141. msg = "您还未开通" + tips + "权限,如有需要请联系对口销售"
  142. }
  143. }
  144. if report.ClassifyNameFirst == "权益研报" {
  145. if report.ClassifyNameSecond == "近期路演精华" {
  146. report.TitleType = "路演精华"
  147. } else {
  148. report.TitleType = "权益"
  149. }
  150. } else {
  151. report.TitleType = "FICC"
  152. }
  153. //判断大小权限
  154. {
  155. if status == 2 {
  156. if company != nil {
  157. permissionCount, err := models.GetCompanyProductPermissionCount(company.CompanyId, productId)
  158. if err != nil {
  159. br.Msg = "获取信息失败"
  160. br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
  161. return
  162. }
  163. if permissionCount >= maxPermissionCount {
  164. status = 0
  165. msg = ""
  166. }
  167. }
  168. }
  169. }
  170. //如果客户产品被禁用了,只有在试用状态下,才不允许查看报告,那么没有权限
  171. if company != nil && company.IsSuspend > 0 && company.Status == "试用" {
  172. status = 2
  173. msg = "您还未开通权限,如有需要请联系对口销售"
  174. }
  175. if status == 2 {
  176. report.Content = report.ContentSub
  177. report.VideoUrl = ""
  178. report.VideoSize = ""
  179. report.VideoPlaySeconds = ""
  180. report.VideoName = ""
  181. }
  182. resp := new(models.ReportDetailResp)
  183. resp.Status = status
  184. resp.Msg = msg
  185. resp.Report = report
  186. //新增阅读记录
  187. if status == 0 {
  188. record := new(models.ReportViewRecord)
  189. record.UserId = user.UserId
  190. record.ReportId = reportId
  191. record.Mobile = user.Mobile
  192. record.Email = user.Email
  193. record.RealName = user.RealName
  194. record.CompanyName = company.CompanyName
  195. record.CreateTime = time.Now()
  196. err = models.AddReportViewRecord(record)
  197. if err != nil {
  198. go utils.SendEmail(utils.APPNAME+"失败提醒", "新增报告阅读记录失败:Err:"+err.Error(), utils.EmailSendToUsers)
  199. }
  200. // 添加阅读日志的数据加入到redis
  201. go cache.PushViewRecordNewRedisData(record, user.CompanyId)
  202. //修改联系人最后一次阅读报告时间
  203. go models.SetWxUserReportLastViewTime(user.UserId)
  204. }
  205. reportType := 0
  206. if report.ClassifyNameFirst == "权益研报" {
  207. reportType = 1
  208. } else {
  209. reportType = 2
  210. }
  211. recommendList, err := models.GetRecommendList(reportId, reportType)
  212. if err != nil {
  213. br.Msg = "获取报告详情失败"
  214. br.ErrMsg = "获取报告推荐列表信息失败,Err:" + err.Error()
  215. return
  216. }
  217. recommendListLen := len(recommendList)
  218. for i := 0; i < recommendListLen; i++ {
  219. item := recommendList[i]
  220. recommendList[i].Content = html.UnescapeString(item.Content)
  221. recommendList[i].ContentSub = html.UnescapeString(item.ContentSub)
  222. count, err := models.GetReportPermission(user.UserId, item.ClassifyNameSecond)
  223. if err != nil {
  224. br.Msg = "获取报告详情失败"
  225. br.ErrMsg = "判断报告权限信息失败,Err:" + err.Error()
  226. return
  227. }
  228. if count > 0 {
  229. recommendList[i].HasPermission = 1
  230. }
  231. if item.ClassifyNameFirst == "权益研报" {
  232. if recommendList[i].ClassifyNameSecond == "近期路演精华" {
  233. recommendList[i].TitleType = "路演精华"
  234. } else {
  235. recommendList[i].TitleType = "权益"
  236. }
  237. } else {
  238. recommendList[i].TitleType = "FICC"
  239. }
  240. }
  241. resp.RecommendList = recommendList
  242. item, err := models.GetClassifyDetailById(report.ClassifyIdSecond)
  243. if err != nil {
  244. br.Msg = "获取信息失败"
  245. br.ErrMsg = "获取详情专栏失败,Err:" + err.Error()
  246. return
  247. }
  248. //新增访问日志
  249. {
  250. record := new(models.UserAccessRecord)
  251. record.Uid = user.UserId
  252. record.Token = this.Token
  253. record.CreateTime = time.Now()
  254. record.Remark = strconv.Itoa(status)
  255. record.ReportId = reportId
  256. go models.AddUserAccessRecord(record)
  257. }
  258. resp.Classify = item
  259. br.Ret = 200
  260. br.Success = true
  261. br.Msg = "获取成功"
  262. br.Data = resp
  263. }
  264. // @Title 日评列表
  265. // @Description 日评列表接口
  266. // @Param PageSize query int true "每页数据条数"
  267. // @Param CurrentIndex query int true "当前页页码,从1开始"
  268. // @Param ClassifyId query int true "分类id"
  269. // @Success 200 {object} models.ReportListResp
  270. // @router /list [get]
  271. func (this *ReportController) ListReport() {
  272. br := new(models.BaseResponse).Init()
  273. defer func() {
  274. this.Data["json"] = br
  275. this.ServeJSON()
  276. }()
  277. user := this.User
  278. if user == nil {
  279. br.Msg = "请登录"
  280. br.ErrMsg = "请登录,用户信息为空"
  281. br.Ret = 408
  282. return
  283. }
  284. pageSize, _ := this.GetInt("PageSize")
  285. currentIndex, _ := this.GetInt("CurrentIndex")
  286. classifyId, _ := this.GetInt("ClassifyId")
  287. if classifyId <= 0 {
  288. br.Msg = "参数错误"
  289. br.ErrMsg = "参数错误,分类id小于等于0"
  290. return
  291. }
  292. var startSize int
  293. if pageSize <= 0 {
  294. pageSize = utils.PageSize20
  295. }
  296. if currentIndex <= 0 {
  297. currentIndex = 1
  298. }
  299. startSize = utils.StartIndex(currentIndex, pageSize)
  300. total, err := models.GetReportListCount(classifyId)
  301. if err != nil {
  302. br.Msg = "获取数据失败"
  303. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  304. return
  305. }
  306. list, err := models.GetReportList(classifyId, startSize, pageSize)
  307. if err != nil {
  308. br.Msg = "获取失败"
  309. br.ErrMsg = "获取失败,Err:" + err.Error()
  310. return
  311. }
  312. var hasPermission bool
  313. userPermission, err := services.CheckUserPermission(this.User.UserId)
  314. if err != nil {
  315. br.Msg = "绑定失败"
  316. br.ErrMsg = "绑定失败,判断权限失败:" + err.Error()
  317. return
  318. }
  319. if userPermission == 0 {
  320. hasPermission = true
  321. }
  322. reportType := "rddp"
  323. reportPermissionList, err := models.GetReportVarietyListByUserIdExt(user.UserId, reportType) //获取客户拥有权限的报告id
  324. if err != nil {
  325. if err.Error() != utils.ErrNoRow() {
  326. br.Msg = "获取报告详情失败"
  327. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  328. return
  329. } else {
  330. hasPermission = false
  331. }
  332. }
  333. if len(reportPermissionList) == 0 {
  334. hasPermission = false
  335. }
  336. permissionMap := make(map[int]int)
  337. for _, v := range reportPermissionList {
  338. if _, ok := permissionMap[v.ReportChapterTypeId]; !ok {
  339. permissionMap[v.ReportChapterTypeId] = v.ReportChapterTypeId
  340. }
  341. }
  342. listLen := len(list)
  343. for i := 0; i < listLen; i++ {
  344. item := list[i]
  345. count, err := models.GetReportPermission(user.UserId, item.ClassifyNameSecond)
  346. if err != nil {
  347. br.Msg = "获取失败"
  348. br.ErrMsg = "判断报告是否拥有权限失败,Err:" + err.Error()
  349. return
  350. }
  351. if count > 0 {
  352. list[i].HasPermission = 1
  353. }
  354. if item.ClassifyNameFirst == "权益研报" {
  355. if list[i].ClassifyNameSecond == "近期路演精华" {
  356. list[i].TitleType = "路演精华"
  357. } else {
  358. list[i].TitleType = "权益"
  359. }
  360. } else {
  361. list[i].TitleType = "FICC"
  362. }
  363. if _, ok := permissionMap[item.Id]; !ok {
  364. list[i].VideoUrl = ""
  365. list[i].VideoName = ""
  366. list[i].VideoName = ""
  367. list[i].VideoPlaySeconds = ""
  368. }
  369. if hasPermission == false {
  370. list[i].VideoUrl = ""
  371. list[i].VideoName = ""
  372. list[i].VideoName = ""
  373. list[i].VideoPlaySeconds = ""
  374. }
  375. }
  376. page := models.GetPaging(currentIndex, pageSize, total)
  377. resp := new(models.ReportListResp)
  378. resp.Paging = page
  379. resp.List = list
  380. br.Ret = 200
  381. br.Success = true
  382. br.Msg = "获取成功"
  383. br.Data = resp
  384. }
  385. // @Title 新增报告浏览记录
  386. // @Description 新增报告浏览记录接口
  387. // @Param request body models.ReportRecordReq true "type json string"
  388. // @Success 200 新增成功
  389. // @router /addUpdateLabel [post]
  390. func (this *ReportController) AddUpdateLabelReport() {
  391. br := new(models.BaseResponse).Init()
  392. defer func() {
  393. this.Data["json"] = br
  394. this.ServeJSON()
  395. }()
  396. user := this.User
  397. if user == nil {
  398. br.Msg = "请登录"
  399. br.ErrMsg = "请登录,用户信息为空"
  400. br.Ret = 408
  401. return
  402. }
  403. var req models.ReportRecordReq
  404. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  405. if err != nil {
  406. br.Msg = "参数解析异常!"
  407. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  408. return
  409. }
  410. if req.ReportId <= 0 {
  411. br.Msg = "参数错误"
  412. br.ErrMsg = "参数错误,报告id小于等于0"
  413. return
  414. }
  415. record := new(models.ReportViewLog)
  416. record.UserId = user.UserId
  417. record.ReportId = req.ReportId
  418. record.CreateTime = time.Now()
  419. err = models.AddReportViewLog(record)
  420. if err != nil {
  421. br.Msg = "获取数据失败"
  422. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  423. return
  424. }
  425. br.Ret = 200
  426. br.Success = true
  427. br.Msg = "新增成功"
  428. }
  429. // @Title 新增报告浏览记录
  430. // @Description 新增报告浏览记录接口
  431. // @Param request body models.ReportRecordReq true "type json string"
  432. // @Success 200 新增成功
  433. // @router /addViewRecord [post]
  434. func (this *ReportController) AddViewRecordReport() {
  435. br := new(models.BaseResponse).Init()
  436. defer func() {
  437. this.Data["json"] = br
  438. this.ServeJSON()
  439. }()
  440. user := this.User
  441. if user == nil {
  442. br.Msg = "请登录"
  443. br.ErrMsg = "请登录,用户信息为空"
  444. br.Ret = 408
  445. return
  446. }
  447. var req models.ReportRecordReq
  448. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  449. if err != nil {
  450. br.Msg = "参数解析异常!"
  451. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  452. return
  453. }
  454. if req.ReportId <= 0 {
  455. br.Msg = "参数错误"
  456. br.ErrMsg = "参数错误,报告id小于等于0"
  457. return
  458. }
  459. //查询企业信息
  460. company, err := models.GetCompanyInfoById(user.CompanyId)
  461. if err != nil {
  462. if err.Error() != utils.ErrNoRow() {
  463. br.Msg = "获取用户管理企业信息失败"
  464. br.ErrMsg = "获取用户管理企业信息失败,Err:" + err.Error()
  465. return
  466. } else {
  467. br.Msg = "获取用户管理企业信息失败"
  468. br.ErrMsg = "您还未开通权限,如有需要请联系对口销售"
  469. return
  470. }
  471. }
  472. record := new(models.ReportViewRecord)
  473. record.UserId = user.UserId
  474. record.ReportId = req.ReportId
  475. record.Mobile = user.Mobile
  476. record.Email = user.Email
  477. record.RealName = user.RealName
  478. record.CompanyName = company.CompanyName
  479. record.CreateTime = time.Now()
  480. err = models.AddReportViewRecord(record)
  481. if err != nil {
  482. br.Msg = "获取数据失败"
  483. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  484. return
  485. }
  486. // 添加阅读日志的数据加入到redis
  487. go cache.PushViewRecordNewRedisData(record, user.CompanyId)
  488. //修改联系人最后一次阅读报告时间
  489. go models.SetWxUserReportLastViewTime(user.UserId)
  490. br.Ret = 200
  491. br.Success = true
  492. br.Msg = "新增成功"
  493. }
  494. // @Title 新增音频阅读记录
  495. // @Description 新增音频阅读记录接口
  496. // @Param request body models.ReportRecordReq true "type json string"
  497. // @Success 200 新增成功
  498. // @router /addAudioRecord [post]
  499. func (this *ReportController) AddAudioRecord() {
  500. br := new(models.BaseResponse).Init()
  501. defer func() {
  502. this.Data["json"] = br
  503. this.ServeJSON()
  504. }()
  505. user := this.User
  506. if user == nil {
  507. br.Msg = "请登录"
  508. br.ErrMsg = "请登录,用户信息为空"
  509. br.Ret = 408
  510. return
  511. }
  512. var req models.ReportRecordReq
  513. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  514. if err != nil {
  515. br.Msg = "参数解析异常!"
  516. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  517. return
  518. }
  519. if req.ReportId <= 0 {
  520. br.Msg = "参数错误"
  521. br.ErrMsg = "参数错误,报告id小于等于0"
  522. return
  523. }
  524. record := new(models.ReportAudioRecord)
  525. record.UserId = user.UserId
  526. record.ReportId = req.ReportId
  527. record.CreateTime = time.Now()
  528. err = models.AddReportAudioRecord(record)
  529. if err != nil {
  530. br.Msg = "获取数据失败"
  531. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  532. return
  533. }
  534. br.Ret = 200
  535. br.Success = true
  536. br.Msg = "新增成功"
  537. }
  538. //func init() {
  539. // fmt.Println("start")
  540. // content:=`&lt;p&gt;&lt;strong&gt;&lt;u&gt;需要开始观察和警惕全球库存周期回摆对资产价格的压力&lt;/u&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;从经济惊喜指数上看,8月以来欧美和新兴市场的走势出现了显著的背离,美国和欧洲的经济惊喜指数都在8月见顶,9月开始回落,而新兴市场的经济惊喜指数却在一路上行。新兴市场的走强不是中国带动的,因为中国的经济惊喜指数从8月开始就基本保持稳定。新兴市场的强势更多是由于自身的原因。&lt;/p&gt;&lt;p&gt;&lt;iframe src=&#34;https://vmp.hzinsights.com/element/750/citibank_economic_surprise_index/%7C%7C%7C%7C%7C/&#34; width=&#34;100%&#34; height=&#34;350&#34; border=&#34;none&#34; style=&#34;border-width:0px; min-height:350px;&#34;&gt;&lt;/iframe&gt;&lt;/p&gt;&lt;p&gt;新兴市场经济强势的根本原因是什么?是因为疫情之后自身的经济比欧美恢复得更好么?显然不是。我们以巴西为例,看巴西的制造业PMI,已经到达突破历史的“逆天水平”。&lt;/p&gt;&lt;p&gt;&lt;iframe src=&#34;https://vmp.hzinsights.com/element/762/brazil_pmi_stock_market/%7C%7C%7C%7C%7C/&#34; width=&#34;100%&#34; height=&#34;350&#34; border=&#34;none&#34; style=&#34;border-width:0px; min-height:350px;&#34;&gt;&lt;/iframe&gt;&lt;/p&gt;`
  541. // newContent:=html.UnescapeString(content)
  542. // utils.FileLog.Info("%s",newContent)
  543. // fmt.Println("end")
  544. //}
  545. // @Title 获取报告作者详情
  546. // @Description 获取报告作者详情
  547. // @Param ReportAuthor query string true "作者名称"
  548. // @Success 200 {object} models.ReportDetailResp
  549. // @router /author/detail [get]
  550. func (this *ReportController) AuthorDetail() {
  551. br := new(models.BaseResponse).Init()
  552. defer func() {
  553. this.Data["json"] = br
  554. this.ServeJSON()
  555. }()
  556. user := this.User
  557. if user == nil {
  558. br.Msg = "请登录"
  559. br.ErrMsg = "请登录,用户信息为空"
  560. br.Ret = 408
  561. return
  562. }
  563. reportAuthor := this.GetString("ReportAuthor")
  564. if reportAuthor == "" {
  565. br.Msg = "参数错误"
  566. br.ErrMsg = "作者名称不能为空"
  567. return
  568. }
  569. author, err := models.GetReportAuthor(reportAuthor)
  570. if err != nil {
  571. br.Msg = "获取作者详情失败"
  572. br.ErrMsg = "获取作者详情失败,Err:" + err.Error()
  573. return
  574. }
  575. br.Ret = 200
  576. br.Success = true
  577. br.Msg = "获取成功"
  578. br.Data = author
  579. }