report.go 14 KB

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