report.go 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602
  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.Mobile = user.Mobile
  182. record.Email = user.Email
  183. record.RealName = user.RealName
  184. record.CompanyName = company.CompanyName
  185. record.CreateTime = time.Now()
  186. err = models.AddReportViewRecord(record)
  187. if err != nil {
  188. go utils.SendEmail(utils.APPNAME+"失败提醒", "新增报告阅读记录失败:Err:"+err.Error(), utils.EmailSendToUsers)
  189. }
  190. //修改联系人最后一次阅读报告时间
  191. go models.SetWxUserReportLastViewTime(user.UserId)
  192. }
  193. reportType := 0
  194. if report.ClassifyNameFirst == "权益研报" {
  195. reportType = 1
  196. } else {
  197. reportType = 2
  198. }
  199. recommendList, err := models.GetRecommendList(reportId, reportType)
  200. if err != nil {
  201. br.Msg = "获取报告详情失败"
  202. br.ErrMsg = "获取报告推荐列表信息失败,Err:" + err.Error()
  203. return
  204. }
  205. recommendListLen := len(recommendList)
  206. for i := 0; i < recommendListLen; i++ {
  207. item := recommendList[i]
  208. recommendList[i].Content = html.UnescapeString(item.Content)
  209. recommendList[i].ContentSub = html.UnescapeString(item.ContentSub)
  210. count, err := models.GetReportPermission(user.UserId, item.ClassifyNameSecond)
  211. if err != nil {
  212. br.Msg = "获取报告详情失败"
  213. br.ErrMsg = "判断报告权限信息失败,Err:" + err.Error()
  214. return
  215. }
  216. if count > 0 {
  217. recommendList[i].HasPermission = 1
  218. }
  219. if item.ClassifyNameFirst == "权益研报" {
  220. if recommendList[i].ClassifyNameSecond == "近期路演精华" {
  221. recommendList[i].TitleType = "图说逻辑"
  222. } else {
  223. recommendList[i].TitleType = "权益"
  224. }
  225. } else {
  226. recommendList[i].TitleType = "FICC"
  227. }
  228. }
  229. resp.RecommendList = recommendList
  230. item, err := models.GetClassifyDetailById(report.ClassifyIdSecond)
  231. if err != nil {
  232. br.Msg = "获取信息失败"
  233. br.ErrMsg = "获取详情专栏失败,Err:" + err.Error()
  234. return
  235. }
  236. //新增访问日志
  237. {
  238. record := new(models.UserAccessRecord)
  239. record.Uid = user.UserId
  240. record.Token = this.Token
  241. record.CreateTime = time.Now()
  242. record.Remark = strconv.Itoa(status)
  243. record.ReportId = reportId
  244. go models.AddUserAccessRecord(record)
  245. }
  246. resp.Classify = item
  247. br.Ret = 200
  248. br.Success = true
  249. br.Msg = "获取成功"
  250. br.Data = resp
  251. }
  252. // @Title 日评列表
  253. // @Description 日评列表接口
  254. // @Param PageSize query int true "每页数据条数"
  255. // @Param CurrentIndex query int true "当前页页码,从1开始"
  256. // @Param ClassifyId query int true "分类id"
  257. // @Success 200 {object} models.ReportListResp
  258. // @router /list [get]
  259. func (this *ReportController) ListReport() {
  260. br := new(models.BaseResponse).Init()
  261. defer func() {
  262. this.Data["json"] = br
  263. this.ServeJSON()
  264. }()
  265. user := this.User
  266. if user == nil {
  267. br.Msg = "请登录"
  268. br.ErrMsg = "请登录,用户信息为空"
  269. br.Ret = 408
  270. return
  271. }
  272. pageSize, _ := this.GetInt("PageSize")
  273. currentIndex, _ := this.GetInt("CurrentIndex")
  274. classifyId, _ := this.GetInt("ClassifyId")
  275. if classifyId <= 0 {
  276. br.Msg = "参数错误"
  277. br.ErrMsg = "参数错误,分类id小于等于0"
  278. return
  279. }
  280. var startSize int
  281. if pageSize <= 0 {
  282. pageSize = utils.PageSize20
  283. }
  284. if currentIndex <= 0 {
  285. currentIndex = 1
  286. }
  287. startSize = utils.StartIndex(currentIndex, pageSize)
  288. total, err := models.GetReportListCount(classifyId)
  289. if err != nil {
  290. br.Msg = "获取数据失败"
  291. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  292. return
  293. }
  294. list, err := models.GetReportList(classifyId, startSize, pageSize)
  295. if err != nil {
  296. br.Msg = "获取失败"
  297. br.ErrMsg = "获取失败,Err:" + err.Error()
  298. return
  299. }
  300. var hasPermission bool
  301. userPermission, err := services.CheckUserPermission(this.User.UserId)
  302. if err != nil {
  303. br.Msg = "绑定失败"
  304. br.ErrMsg = "绑定失败,判断权限失败:" + err.Error()
  305. return
  306. }
  307. if userPermission == 0 {
  308. hasPermission = true
  309. }
  310. reportType := "rddp"
  311. reportPermissionList, err := models.GetReportVarietyListByUserIdExt(user.UserId, reportType) //获取客户拥有权限的报告id
  312. if err != nil {
  313. if err.Error() != utils.ErrNoRow() {
  314. br.Msg = "获取报告详情失败"
  315. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  316. return
  317. } else {
  318. hasPermission = false
  319. }
  320. }
  321. if len(reportPermissionList) == 0 {
  322. hasPermission = false
  323. }
  324. permissionMap := make(map[int]int)
  325. for _, v := range reportPermissionList {
  326. if _, ok := permissionMap[v.ReportChapterTypeId]; !ok {
  327. permissionMap[v.ReportChapterTypeId] = v.ReportChapterTypeId
  328. }
  329. }
  330. listLen := len(list)
  331. for i := 0; i < listLen; i++ {
  332. item := list[i]
  333. count, err := models.GetReportPermission(user.UserId, item.ClassifyNameSecond)
  334. if err != nil {
  335. br.Msg = "获取失败"
  336. br.ErrMsg = "判断报告是否拥有权限失败,Err:" + err.Error()
  337. return
  338. }
  339. if count > 0 {
  340. list[i].HasPermission = 1
  341. }
  342. if item.ClassifyNameFirst == "权益研报" {
  343. if list[i].ClassifyNameSecond == "近期路演精华" {
  344. list[i].TitleType = "图说逻辑"
  345. } else {
  346. list[i].TitleType = "权益"
  347. }
  348. } else {
  349. list[i].TitleType = "FICC"
  350. }
  351. if _, ok := permissionMap[item.Id]; !ok {
  352. list[i].VideoUrl = ""
  353. list[i].VideoName = ""
  354. list[i].VideoName = ""
  355. list[i].VideoPlaySeconds = ""
  356. }
  357. if hasPermission == false {
  358. list[i].VideoUrl = ""
  359. list[i].VideoName = ""
  360. list[i].VideoName = ""
  361. list[i].VideoPlaySeconds = ""
  362. }
  363. }
  364. page := models.GetPaging(currentIndex, pageSize, total)
  365. resp := new(models.ReportListResp)
  366. resp.Paging = page
  367. resp.List = list
  368. br.Ret = 200
  369. br.Success = true
  370. br.Msg = "获取成功"
  371. br.Data = resp
  372. }
  373. // @Title 新增报告浏览记录
  374. // @Description 新增报告浏览记录接口
  375. // @Param request body models.ReportRecordReq true "type json string"
  376. // @Success 200 新增成功
  377. // @router /addUpdateLabel [post]
  378. func (this *ReportController) AddUpdateLabelReport() {
  379. br := new(models.BaseResponse).Init()
  380. defer func() {
  381. this.Data["json"] = br
  382. this.ServeJSON()
  383. }()
  384. user := this.User
  385. if user == nil {
  386. br.Msg = "请登录"
  387. br.ErrMsg = "请登录,用户信息为空"
  388. br.Ret = 408
  389. return
  390. }
  391. var req models.ReportRecordReq
  392. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  393. if err != nil {
  394. br.Msg = "参数解析异常!"
  395. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  396. return
  397. }
  398. if req.ReportId <= 0 {
  399. br.Msg = "参数错误"
  400. br.ErrMsg = "参数错误,报告id小于等于0"
  401. return
  402. }
  403. record := new(models.ReportViewLog)
  404. record.UserId = user.UserId
  405. record.ReportId = req.ReportId
  406. record.CreateTime = time.Now()
  407. err = models.AddReportViewLog(record)
  408. if err != nil {
  409. br.Msg = "获取数据失败"
  410. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  411. return
  412. }
  413. br.Ret = 200
  414. br.Success = true
  415. br.Msg = "新增成功"
  416. }
  417. // @Title 新增报告浏览记录
  418. // @Description 新增报告浏览记录接口
  419. // @Param request body models.ReportRecordReq true "type json string"
  420. // @Success 200 新增成功
  421. // @router /addViewRecord [post]
  422. func (this *ReportController) AddViewRecordReport() {
  423. br := new(models.BaseResponse).Init()
  424. defer func() {
  425. this.Data["json"] = br
  426. this.ServeJSON()
  427. }()
  428. user := this.User
  429. if user == nil {
  430. br.Msg = "请登录"
  431. br.ErrMsg = "请登录,用户信息为空"
  432. br.Ret = 408
  433. return
  434. }
  435. var req models.ReportRecordReq
  436. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  437. if err != nil {
  438. br.Msg = "参数解析异常!"
  439. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  440. return
  441. }
  442. if req.ReportId <= 0 {
  443. br.Msg = "参数错误"
  444. br.ErrMsg = "参数错误,报告id小于等于0"
  445. return
  446. }
  447. //查询企业信息
  448. company, err := models.GetCompanyInfoById(user.CompanyId)
  449. if err != nil {
  450. if err.Error() != utils.ErrNoRow() {
  451. br.Msg = "获取用户管理企业信息失败"
  452. br.ErrMsg = "获取用户管理企业信息失败,Err:" + err.Error()
  453. return
  454. } else {
  455. br.Msg = "获取用户管理企业信息失败"
  456. br.ErrMsg = "您还未开通权限,如有需要请联系对口销售"
  457. return
  458. }
  459. }
  460. record := new(models.ReportViewRecord)
  461. record.UserId = user.UserId
  462. record.ReportId = req.ReportId
  463. record.Mobile = user.Mobile
  464. record.Email = user.Email
  465. record.RealName = user.RealName
  466. record.CompanyName = company.CompanyName
  467. record.CreateTime = time.Now()
  468. err = models.AddReportViewRecord(record)
  469. if err != nil {
  470. br.Msg = "获取数据失败"
  471. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  472. return
  473. }
  474. br.Ret = 200
  475. br.Success = true
  476. br.Msg = "新增成功"
  477. }
  478. // @Title 新增音频阅读记录
  479. // @Description 新增音频阅读记录接口
  480. // @Param request body models.ReportRecordReq true "type json string"
  481. // @Success 200 新增成功
  482. // @router /addAudioRecord [post]
  483. func (this *ReportController) AddAudioRecord() {
  484. br := new(models.BaseResponse).Init()
  485. defer func() {
  486. this.Data["json"] = br
  487. this.ServeJSON()
  488. }()
  489. user := this.User
  490. if user == nil {
  491. br.Msg = "请登录"
  492. br.ErrMsg = "请登录,用户信息为空"
  493. br.Ret = 408
  494. return
  495. }
  496. var req models.ReportRecordReq
  497. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  498. if err != nil {
  499. br.Msg = "参数解析异常!"
  500. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  501. return
  502. }
  503. if req.ReportId <= 0 {
  504. br.Msg = "参数错误"
  505. br.ErrMsg = "参数错误,报告id小于等于0"
  506. return
  507. }
  508. record := new(models.ReportAudioRecord)
  509. record.UserId = user.UserId
  510. record.ReportId = req.ReportId
  511. record.CreateTime = time.Now()
  512. err = models.AddReportAudioRecord(record)
  513. if err != nil {
  514. br.Msg = "获取数据失败"
  515. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  516. return
  517. }
  518. br.Ret = 200
  519. br.Success = true
  520. br.Msg = "新增成功"
  521. }
  522. //func init() {
  523. // fmt.Println("start")
  524. // 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;`
  525. // newContent:=html.UnescapeString(content)
  526. // utils.FileLog.Info("%s",newContent)
  527. // fmt.Println("end")
  528. //}
  529. // @Title 获取报告作者详情
  530. // @Description 获取报告作者详情
  531. // @Param ReportAuthor query string true "作者名称"
  532. // @Success 200 {object} models.ReportDetailResp
  533. // @router /author/detail [get]
  534. func (this *ReportController) AuthorDetail() {
  535. br := new(models.BaseResponse).Init()
  536. defer func() {
  537. this.Data["json"] = br
  538. this.ServeJSON()
  539. }()
  540. user := this.User
  541. if user == nil {
  542. br.Msg = "请登录"
  543. br.ErrMsg = "请登录,用户信息为空"
  544. br.Ret = 408
  545. return
  546. }
  547. reportAuthor := this.GetString("ReportAuthor")
  548. if reportAuthor == "" {
  549. br.Msg = "参数错误"
  550. br.ErrMsg = "作者名称不能为空"
  551. return
  552. }
  553. author, err := models.GetReportAuthor(reportAuthor)
  554. if err != nil {
  555. br.Msg = "获取作者详情失败"
  556. br.ErrMsg = "获取作者详情失败,Err:" + err.Error()
  557. return
  558. }
  559. br.Ret = 200
  560. br.Success = true
  561. br.Msg = "获取成功"
  562. br.Data = author
  563. }