report.go 15 KB

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