report.go 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468
  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. go models.SetWxUserReportLastViewTime(user.UserId)
  156. }
  157. reportType := 0
  158. if report.ClassifyNameFirst == "权益研报" {
  159. reportType = 1
  160. } else {
  161. reportType = 2
  162. }
  163. recommendList, err := models.GetRecommendList(reportId, reportType)
  164. if err != nil {
  165. br.Msg = "获取报告详情失败"
  166. br.ErrMsg = "获取报告推荐列表信息失败,Err:" + err.Error()
  167. return
  168. }
  169. recommendListLen := len(recommendList)
  170. for i := 0; i < recommendListLen; i++ {
  171. item := recommendList[i]
  172. recommendList[i].Content = html.UnescapeString(item.Content)
  173. recommendList[i].ContentSub = html.UnescapeString(item.ContentSub)
  174. count, err := models.GetReportPermission(user.UserId, item.ClassifyNameSecond)
  175. if err != nil {
  176. br.Msg = "获取报告详情失败"
  177. br.ErrMsg = "判断报告权限信息失败,Err:" + err.Error()
  178. return
  179. }
  180. if count > 0 {
  181. recommendList[i].HasPermission = 1
  182. }
  183. if item.ClassifyNameFirst == "权益研报" {
  184. recommendList[i].TitleType = "图说逻辑"
  185. } else {
  186. recommendList[i].TitleType = "FICC"
  187. }
  188. }
  189. resp.RecommendList = recommendList
  190. br.Ret = 200
  191. br.Success = true
  192. br.Msg = "获取成功"
  193. br.Data = resp
  194. }
  195. // @Title 日评列表
  196. // @Description 日评列表接口
  197. // @Param PageSize query int true "每页数据条数"
  198. // @Param CurrentIndex query int true "当前页页码,从1开始"
  199. // @Param ClassifyId query int true "分类id"
  200. // @Success 200 {object} models.ReportListResp
  201. // @router /list [get]
  202. func (this *ReportController) ListReport() {
  203. br := new(models.BaseResponse).Init()
  204. defer func() {
  205. this.Data["json"] = br
  206. this.ServeJSON()
  207. }()
  208. user := this.User
  209. if user == nil {
  210. br.Msg = "请登录"
  211. br.ErrMsg = "请登录,用户信息为空"
  212. br.Ret = 408
  213. return
  214. }
  215. pageSize, _ := this.GetInt("PageSize")
  216. currentIndex, _ := this.GetInt("CurrentIndex")
  217. classifyId, _ := this.GetInt("ClassifyId")
  218. if classifyId <= 0 {
  219. br.Msg = "参数错误"
  220. br.ErrMsg = "参数错误,分类id小于等于0"
  221. return
  222. }
  223. var startSize int
  224. if pageSize <= 0 {
  225. pageSize = utils.PageSize20
  226. }
  227. if currentIndex <= 0 {
  228. currentIndex = 1
  229. }
  230. startSize = utils.StartIndex(currentIndex, pageSize)
  231. total, err := models.GetReportListCount(classifyId)
  232. if err != nil {
  233. br.Msg = "获取数据失败"
  234. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  235. return
  236. }
  237. list, err := models.GetReportList(classifyId, startSize, pageSize)
  238. if err != nil {
  239. br.Msg = "获取失败"
  240. br.ErrMsg = "获取失败,Err:" + err.Error()
  241. return
  242. }
  243. listLen := len(list)
  244. for i := 0; i < listLen; i++ {
  245. item := list[i]
  246. list[i].Content = html.UnescapeString(item.Content)
  247. list[i].ContentSub = html.UnescapeString(item.ContentSub)
  248. count, err := models.GetReportPermission(user.UserId, item.ClassifyNameSecond)
  249. if err != nil {
  250. br.Msg = "获取失败"
  251. br.ErrMsg = "判断报告是否拥有权限失败,Err:" + err.Error()
  252. return
  253. }
  254. if count > 0 {
  255. list[i].HasPermission = 1
  256. }
  257. if item.ClassifyNameFirst == "权益研报" {
  258. list[i].TitleType = "图说逻辑"
  259. } else {
  260. list[i].TitleType = "FICC"
  261. }
  262. }
  263. page := models.GetPaging(currentIndex, pageSize, total)
  264. resp := new(models.ReportListResp)
  265. resp.Paging = page
  266. resp.List = list
  267. br.Ret = 200
  268. br.Success = true
  269. br.Msg = "获取成功"
  270. br.Data = resp
  271. }
  272. // @Title 新增报告浏览记录
  273. // @Description 新增报告浏览记录接口
  274. // @Param request body models.ReportRecordReq true "type json string"
  275. // @Success 200 新增成功
  276. // @router /addUpdateLabel [post]
  277. func (this *ReportController) AddUpdateLabelReport() {
  278. br := new(models.BaseResponse).Init()
  279. defer func() {
  280. this.Data["json"] = br
  281. this.ServeJSON()
  282. }()
  283. user := this.User
  284. if user == nil {
  285. br.Msg = "请登录"
  286. br.ErrMsg = "请登录,用户信息为空"
  287. br.Ret = 408
  288. return
  289. }
  290. var req models.ReportRecordReq
  291. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  292. if err != nil {
  293. br.Msg = "参数解析异常!"
  294. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  295. return
  296. }
  297. if req.ReportId <= 0 {
  298. br.Msg = "参数错误"
  299. br.ErrMsg = "参数错误,报告id小于等于0"
  300. return
  301. }
  302. record := new(models.ReportViewLog)
  303. record.UserId = user.UserId
  304. record.ReportId = req.ReportId
  305. record.CreateTime = time.Now()
  306. err = models.AddReportViewLog(record)
  307. if err != nil {
  308. br.Msg = "获取数据失败"
  309. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  310. return
  311. }
  312. br.Ret = 200
  313. br.Success = true
  314. br.Msg = "新增成功"
  315. }
  316. // @Title 新增报告浏览记录
  317. // @Description 新增报告浏览记录接口
  318. // @Param request body models.ReportRecordReq true "type json string"
  319. // @Success 200 新增成功
  320. // @router /addViewRecord [post]
  321. func (this *ReportController) AddViewRecordReport() {
  322. br := new(models.BaseResponse).Init()
  323. defer func() {
  324. this.Data["json"] = br
  325. this.ServeJSON()
  326. }()
  327. user := this.User
  328. if user == nil {
  329. br.Msg = "请登录"
  330. br.ErrMsg = "请登录,用户信息为空"
  331. br.Ret = 408
  332. return
  333. }
  334. var req models.ReportRecordReq
  335. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  336. if err != nil {
  337. br.Msg = "参数解析异常!"
  338. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  339. return
  340. }
  341. if req.ReportId <= 0 {
  342. br.Msg = "参数错误"
  343. br.ErrMsg = "参数错误,报告id小于等于0"
  344. return
  345. }
  346. record := new(models.ReportViewRecord)
  347. record.UserId = user.UserId
  348. record.ReportId = req.ReportId
  349. record.CreateTime = time.Now()
  350. err = models.AddReportViewRecord(record)
  351. if err != nil {
  352. br.Msg = "获取数据失败"
  353. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  354. return
  355. }
  356. br.Ret = 200
  357. br.Success = true
  358. br.Msg = "新增成功"
  359. }
  360. // @Title 新增音频阅读记录
  361. // @Description 新增音频阅读记录接口
  362. // @Param request body models.ReportRecordReq true "type json string"
  363. // @Success 200 新增成功
  364. // @router /addAudioRecord [post]
  365. func (this *ReportController) AddAudioRecord() {
  366. br := new(models.BaseResponse).Init()
  367. defer func() {
  368. this.Data["json"] = br
  369. this.ServeJSON()
  370. }()
  371. user := this.User
  372. if user == nil {
  373. br.Msg = "请登录"
  374. br.ErrMsg = "请登录,用户信息为空"
  375. br.Ret = 408
  376. return
  377. }
  378. var req models.ReportRecordReq
  379. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  380. if err != nil {
  381. br.Msg = "参数解析异常!"
  382. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  383. return
  384. }
  385. if req.ReportId <= 0 {
  386. br.Msg = "参数错误"
  387. br.ErrMsg = "参数错误,报告id小于等于0"
  388. return
  389. }
  390. record := new(models.ReportAudioRecord)
  391. record.UserId = user.UserId
  392. record.ReportId = req.ReportId
  393. record.CreateTime = time.Now()
  394. err = models.AddReportAudioRecord(record)
  395. if err != nil {
  396. br.Msg = "获取数据失败"
  397. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  398. return
  399. }
  400. br.Ret = 200
  401. br.Success = true
  402. br.Msg = "新增成功"
  403. }
  404. //func init() {
  405. // fmt.Println("start")
  406. // 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;`
  407. // newContent:=html.UnescapeString(content)
  408. // utils.FileLog.Info("%s",newContent)
  409. // fmt.Println("end")
  410. //}
  411. // @Title 获取报告作者详情
  412. // @Description 获取报告作者详情
  413. // @Param ReportAuthor query string true "作者名称"
  414. // @Success 200 {object} models.ReportDetailResp
  415. // @router /author/detail [get]
  416. func (this *ReportController) AuthorDetail() {
  417. br := new(models.BaseResponse).Init()
  418. defer func() {
  419. this.Data["json"] = br
  420. this.ServeJSON()
  421. }()
  422. user := this.User
  423. if user == nil {
  424. br.Msg = "请登录"
  425. br.ErrMsg = "请登录,用户信息为空"
  426. br.Ret = 408
  427. return
  428. }
  429. reportAuthor := this.GetString("ReportAuthor")
  430. if reportAuthor == "" {
  431. br.Msg = "参数错误"
  432. br.ErrMsg = "作者名称不能为空"
  433. return
  434. }
  435. author, err := models.GetReportAuthor(reportAuthor)
  436. if err != nil {
  437. br.Msg = "获取作者详情失败"
  438. br.ErrMsg = "获取作者详情失败,Err:" + err.Error()
  439. return
  440. }
  441. br.Ret = 200
  442. br.Success = true
  443. br.Msg = "获取成功"
  444. br.Data = author
  445. }