report.go 17 KB

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