report.go 13 KB

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