report.go 16 KB

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