english_report.go 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "errors"
  5. "github.com/rdlucklib/rdluck_tools/paging"
  6. "hongze/hongze_api/models"
  7. "hongze/hongze_api/services/alarm_msg"
  8. services "hongze/hongze_api/services/elastic"
  9. "hongze/hongze_api/utils"
  10. "html"
  11. "strings"
  12. "time"
  13. )
  14. // EnglishReportShareController 报告分享
  15. type EnglishReportShareController struct {
  16. BaseCommonController
  17. }
  18. type EnglishReportController struct {
  19. BaseCommonController
  20. }
  21. // EnglishReportDetail
  22. // @Title 英文研报-分享详情
  23. // @Description 英文研报-分享详情
  24. // @Param ReportCode query string true "报告唯一编码"
  25. // @Param ShareEmail query int false "推送的邮箱ID"
  26. // @Success 200 {object} models.ReportShareDetailResp
  27. // @router /share/detail [get]
  28. func (this *EnglishReportShareController) EnglishReportDetail() {
  29. br := new(models.BaseResponse).Init()
  30. defer func() {
  31. this.Data["json"] = br
  32. this.ServeJSON()
  33. }()
  34. reportCode := this.GetString("ReportCode")
  35. if reportCode == "" {
  36. br.Msg = "参数错误"
  37. br.ErrMsg = "参数错误,reportCode 为空"
  38. return
  39. }
  40. report, err := models.GetEnglishReportByCode(reportCode)
  41. if err != nil {
  42. br.Msg = "该报告已删除"
  43. br.ErrMsg = "获取报告详情失败,Err:" + err.Error()
  44. return
  45. }
  46. err = models.UpdateEnglishReportCounts(reportCode)
  47. if err != nil {
  48. br.Msg = "更新失败"
  49. br.ErrMsg = "更新失败,Err:" + err.Error()
  50. return
  51. }
  52. report.ContentSub = html.UnescapeString(report.ContentSub)
  53. report.Content = html.UnescapeString(report.Content)
  54. // 记录邮箱
  55. shareEmail, _ := this.GetInt("ShareEmail", 0)
  56. if shareEmail != 0 {
  57. go func() {
  58. var errMsg error
  59. defer func() {
  60. if errMsg != nil {
  61. alarm_msg.SendAlarmMsg(utils.APPNAME+"更新英文报告邮箱PV失败, Err: "+errMsg.Error(), 2)
  62. }
  63. }()
  64. userEmail, e := models.GetEnglishReportEmailById(shareEmail)
  65. if e != nil && e.Error() != utils.ErrNoRow() {
  66. errMsg = errors.New("获取客户邮箱信息失败, Err:" + e.Error())
  67. return
  68. }
  69. if userEmail == nil {
  70. return
  71. }
  72. // 更新报告邮箱pv(冗余)
  73. if e = models.UpdateEnglishReportEmailCounts(reportCode); e != nil {
  74. errMsg = errors.New("更新报告邮箱PV失败, Err:" + e.Error())
  75. return
  76. }
  77. // 记录邮箱PV
  78. pv := &models.EnglishReportEmailPV{
  79. ReportId: report.Id,
  80. EmailId: userEmail.Id,
  81. CreateTime: time.Now().Local(),
  82. }
  83. if e = pv.Create(); e != nil {
  84. errMsg = errors.New("新增邮箱PV失败, Err: " + e.Error())
  85. return
  86. }
  87. // 更新阅读量
  88. if e = models.UpdateEnglishReportEmailViewTotal(userEmail.Id); e != nil {
  89. errMsg = errors.New("更新英文联系人阅读量失败, Err: " + e.Error())
  90. return
  91. }
  92. if userEmail.CompanyId > 0 {
  93. if e = models.UpdateEnglishCompanyViewTotal(userEmail.CompanyId); e != nil {
  94. errMsg = errors.New("更新英文客户阅读量, Err: " + e.Error())
  95. return
  96. }
  97. }
  98. }()
  99. }
  100. resp := new(models.EnglishReportShareDetailResp)
  101. resp.Report = report
  102. br.Ret = 200
  103. br.Success = true
  104. br.Msg = "获取成功"
  105. br.Data = resp
  106. }
  107. // @Title 获取分类列表
  108. // @Description 获取分类列表
  109. // @Param PageSize query int true "每页数据条数"
  110. // @Param CurrentIndex query int true "当前页页码,从1开始"
  111. // @Param KeyWord query string true "检索关键词"
  112. // @Param CompanyType query string false "产品类型,枚举值:'ficc','权益';不传默认返回全部"
  113. // @Success 200 {object} models.EnglishClassifyListResp
  114. // @router /classify [get]
  115. func (this *EnglishReportController) Classify() {
  116. br := new(models.BaseResponse).Init()
  117. defer func() {
  118. this.Data["json"] = br
  119. this.ServeJSON()
  120. }()
  121. parentList, err := models.GetParentEnglishClassify()
  122. if err != nil {
  123. br.Msg = "获取一级分类失败"
  124. br.ErrMsg = "获取一级分类失败,Err:" + err.Error()
  125. return
  126. }
  127. childList, err := models.GetChildEnglishClassify()
  128. if err != nil {
  129. br.Msg = "获取二级分类失败"
  130. br.ErrMsg = "获取二级分类失败,Err:" + err.Error()
  131. return
  132. }
  133. parentMap := make(map[int][]*models.EnglishClassify, 0)
  134. for _, v := range childList {
  135. parentMap[v.ParentId] = append(parentMap[v.ParentId], v)
  136. }
  137. list := make([]*models.EnglishClassifyList, 0)
  138. for _, v := range parentList {
  139. tmp := &models.EnglishClassifyList{
  140. Id: v.Id,
  141. ClassifyName: v.ClassifyName,
  142. Sort: v.Sort,
  143. ParentId: v.ParentId,
  144. CreateTime: v.CreateTime.Format(utils.FormatDateTime),
  145. ModifyTime: v.ModifyTime.Format(utils.FormatDateTime),
  146. ClassifyLabel: v.ClassifyLabel,
  147. ShowType: v.ShowType,
  148. IsShow: v.IsShow,
  149. }
  150. if child, ok := parentMap[v.Id]; ok {
  151. tmp.Child = child
  152. }
  153. list = append(list, tmp)
  154. }
  155. resp := new(models.EnglishClassifyListResp)
  156. resp.List = list
  157. br.Data = resp
  158. br.Ret = 200
  159. br.Success = true
  160. br.Msg = "获取成功"
  161. }
  162. // @Title 获取报告列表接口
  163. // @Description 获取报告列表
  164. // @Param PageSize query int true "每页数据条数"
  165. // @Param CurrentIndex query int true "当前页页码,从1开始"
  166. // @Param StartDate query string true "开始时间"
  167. // @Param EndDate query string true "结束时间"
  168. // @Param Frequency query string true "频度"
  169. // @Param ClassifyNameFirst query string true "一级分类名称"
  170. // @Param ClassifyNameSecond query string true "二级分类名称"
  171. // @Param State query int true "状态"
  172. // @Param KeyWord query string true "搜索关键词"
  173. // @Param PublishSort query string true "desc:降序,asc 升序(预留)"
  174. // @Param CompanyType query string false "产品类型,枚举值:'ficc','权益';不传默认返回全部"
  175. // @Success 200 {object} models.ReportListResp
  176. // @router /list [get]
  177. func (this *EnglishReportController) ListReport() {
  178. br := new(models.BaseResponse).Init()
  179. defer func() {
  180. this.Data["json"] = br
  181. this.ServeJSON()
  182. }()
  183. pageSize, _ := this.GetInt("PageSize")
  184. currentIndex, _ := this.GetInt("CurrentIndex")
  185. classifyIdFirst, _ := this.GetInt("ClassifyIdFirst")
  186. classifyIdSecond, _ := this.GetInt("ClassifyIdSecond")
  187. var startSize int
  188. if pageSize <= 0 {
  189. pageSize = utils.PageSize20
  190. }
  191. if currentIndex <= 0 {
  192. currentIndex = 1
  193. }
  194. startSize = utils.StartIndex(currentIndex, pageSize)
  195. var condition string
  196. var pars []interface{}
  197. if classifyIdFirst > 0 {
  198. condition += ` AND classify_id_first = ? `
  199. pars = append(pars, classifyIdFirst)
  200. }
  201. if classifyIdSecond > 0 {
  202. condition += ` AND classify_id_second = ? `
  203. pars = append(pars, classifyIdSecond)
  204. }
  205. total, err := models.GetEnglishReportListCount(condition, pars)
  206. if err != nil {
  207. br.Msg = "获取失败"
  208. br.ErrMsg = "获取失败,Err:" + err.Error()
  209. return
  210. }
  211. detailList, err := models.GetEnglishReportList(condition, pars, startSize, pageSize)
  212. if err != nil {
  213. br.Msg = "获取失败"
  214. br.ErrMsg = "获取失败,Err:" + err.Error()
  215. return
  216. }
  217. list := make([]*models.EnglishReportList, 0)
  218. for _, v := range detailList {
  219. tmp := &models.EnglishReportList{
  220. Id: v.Id,
  221. AddType: v.AddType,
  222. ClassifyIdFirst: v.ClassifyIdFirst,
  223. ClassifyNameFirst: v.ClassifyNameFirst,
  224. ClassifyIdSecond: v.ClassifyIdSecond,
  225. ClassifyNameSecond: v.ClassifyNameSecond,
  226. Title: v.Title,
  227. Abstract: v.Abstract,
  228. Author: v.Author,
  229. Frequency: v.Frequency,
  230. CreateTime: v.CreateTime,
  231. ModifyTime: v.ModifyTime,
  232. PublishTime: v.PublishTime,
  233. Stage: v.Stage,
  234. VideoUrl: v.VideoUrl,
  235. VideoName: v.VideoName,
  236. VideoPlaySeconds: v.VideoPlaySeconds,
  237. ReportCode: v.ReportCode,
  238. }
  239. if v.State == 2 {
  240. tmp.ShareUrl = "https://share.hzinsights.com/reportEn?code=" + v.ReportCode
  241. }
  242. list = append(list, tmp)
  243. }
  244. page := paging.GetPaging(currentIndex, pageSize, total)
  245. resp := new(models.EnglishReportListResp)
  246. resp.Paging = page
  247. resp.List = list
  248. br.Ret = 200
  249. br.Success = true
  250. br.Msg = "获取成功"
  251. br.Data = resp
  252. }
  253. // FilterByEs
  254. // @Title 英文报告筛选接口
  255. // @Description 英文报告筛选接口
  256. // @Param KeyWord query string false "搜索关键词:指标ID/指标名称"
  257. // @Param PageSize query int true "每页数据条数"
  258. // @Param CurrentIndex query int true "当前页页码,从1开始"
  259. // @Success 200 {object} data_manage.EdbInfoList
  260. // @router /filter_by_es [get]
  261. func (this *EnglishReportController) FilterByEs() {
  262. br := new(models.BaseResponse).Init()
  263. defer func() {
  264. this.Data["json"] = br
  265. this.ServeJSON()
  266. }()
  267. pageSize, _ := this.GetInt("PageSize")
  268. currentIndex, _ := this.GetInt("CurrentIndex")
  269. var total int64
  270. var startSize int
  271. if pageSize <= 0 {
  272. pageSize = utils.PageSize20
  273. }
  274. if currentIndex <= 0 {
  275. currentIndex = 1
  276. }
  277. startSize = paging.StartIndex(currentIndex, pageSize)
  278. keyWord := this.GetString("KeyWord")
  279. keyWord = strings.TrimSpace(keyWord) //移除字符串首尾空格
  280. if keyWord == "" {
  281. br.Msg = "请输入关键词"
  282. return
  283. }
  284. reportList := make([]*models.SearchEnglishReportItem, 0)
  285. var err error
  286. searchResp, total, err := services.SearchESEnglishReport(keyWord, startSize, pageSize)
  287. if err != nil {
  288. br.Msg = "报告搜索失败"
  289. br.ErrMsg = "报告搜索失败,Err:" + err.Error()
  290. return
  291. }
  292. if searchResp.Hits != nil {
  293. for _, v := range searchResp.Hits.Hits {
  294. temp := new(models.SearchEnglishReportItem)
  295. itemJson, tmpErr := v.Source.MarshalJSON()
  296. if tmpErr != nil {
  297. br.Msg = "报告搜索失败 解析出错"
  298. br.ErrMsg = "报告搜索失败,Err:" + tmpErr.Error()
  299. return
  300. }
  301. reportItem := new(models.ElasticEnglishReportDetail)
  302. tmpErr = json.Unmarshal(itemJson, &reportItem)
  303. if tmpErr != nil {
  304. br.Msg = "报告搜索失败 解析json出错"
  305. br.ErrMsg = "报告搜索失败, 解析json出错,Err:" + tmpErr.Error()
  306. return
  307. }
  308. temp.Id = reportItem.ReportId
  309. temp.ClassifyIdFirst = reportItem.ClassifyIdFirst
  310. temp.ClassifyNameFirst = reportItem.ClassifyNameFirst
  311. temp.ClassifyIdSecond = reportItem.ClassifyIdSecond
  312. temp.ClassifyNameSecond = reportItem.ClassifyNameSecond
  313. temp.Title = reportItem.Title
  314. temp.Author = reportItem.Author
  315. temp.CreateTime = reportItem.CreateTime
  316. // 默认应该从数据库中查询
  317. temp.ContentSub = reportItem.ContentSub
  318. temp.PublishTime = reportItem.PublishTime
  319. temp.ReportCode = reportItem.ReportCode
  320. if len(v.Highlight["Title"]) > 0 {
  321. temp.Title = v.Highlight["Title"][0]
  322. }
  323. if len(v.Highlight["BodyContent"]) > 0 {
  324. temp.ContentSub = v.Highlight["BodyContent"][0]
  325. }
  326. temp.ContentSub = "<div style=\"-webkit-line-clamp: 3;-webkit-box-orient: vertical;display: -webkit-box;overflow: hidden;text-overflow: ellipsis;\">" + temp.ContentSub + "</div>"
  327. reportList = append(reportList, temp)
  328. }
  329. }
  330. page := paging.GetPaging(currentIndex, pageSize, int(total))
  331. //新增搜索词记录
  332. /*{
  333. searchKeyword := new(data_manage.SearchKeyword)
  334. searchKeyword.KeyWord = keyWord
  335. searchKeyword.CreateTime = time.Now()
  336. go data_manage.AddSearchKeyword(searchKeyword)
  337. }*/
  338. resp := models.SearchEnglishReportResp{
  339. Paging: page,
  340. List: reportList,
  341. }
  342. br.Ret = 200
  343. br.Success = true
  344. br.Msg = "搜索成功"
  345. br.Data = resp
  346. }
  347. // TrialEnglishReportDetail
  348. // @Title 英文研报-分享详情-ETA试用平台
  349. // @Description 英文研报-分享详情
  350. // @Param ReportCode query string true "报告唯一编码"
  351. // @Param ShareEmail query int false "推送的邮箱ID"
  352. // @Success 200 {object} models.ReportShareDetailResp
  353. // @router /trial/share/detail [get]
  354. func (this *EnglishReportShareController) TrialEnglishReportDetail() {
  355. br := new(models.BaseResponse).Init()
  356. defer func() {
  357. this.Data["json"] = br
  358. this.ServeJSON()
  359. }()
  360. reportCode := this.GetString("ReportCode")
  361. if reportCode == "" {
  362. br.Msg = "参数错误"
  363. br.ErrMsg = "参数错误,reportCode 为空"
  364. return
  365. }
  366. report, err := models.GetTrialEnglishReportByCode(reportCode)
  367. if err != nil {
  368. br.Msg = "该报告已删除"
  369. br.ErrMsg = "获取报告详情失败,Err:" + err.Error()
  370. return
  371. }
  372. err = models.UpdateTrialEnglishReportCounts(reportCode)
  373. if err != nil {
  374. br.Msg = "更新失败"
  375. br.ErrMsg = "更新失败,Err:" + err.Error()
  376. return
  377. }
  378. report.ContentSub = html.UnescapeString(report.ContentSub)
  379. report.Content = html.UnescapeString(report.Content)
  380. // 记录邮箱
  381. shareEmail, _ := this.GetInt("ShareEmail", 0)
  382. if shareEmail != 0 {
  383. go func() {
  384. var errMsg error
  385. defer func() {
  386. if errMsg != nil {
  387. alarm_msg.SendAlarmMsg(utils.APPNAME+"更新英文报告邮箱PV失败, Err: "+errMsg.Error(), 2)
  388. }
  389. }()
  390. userEmail, e := models.GetTrialEnglishReportEmailById(shareEmail)
  391. if e != nil && e.Error() != utils.ErrNoRow() {
  392. errMsg = errors.New("获取客户邮箱信息失败, Err:" + e.Error())
  393. return
  394. }
  395. if userEmail == nil {
  396. return
  397. }
  398. // 更新报告邮箱pv(冗余)
  399. if e = models.UpdateTrialEnglishReportEmailCounts(reportCode); e != nil {
  400. errMsg = errors.New("更新报告邮箱PV失败, Err:" + e.Error())
  401. return
  402. }
  403. // 记录邮箱PV
  404. pv := &models.EnglishReportEmailPV{
  405. ReportId: report.Id,
  406. EmailId: userEmail.Id,
  407. CreateTime: time.Now().Local(),
  408. }
  409. if e = models.InsertTrialEnglishReportEmailPV(pv); e != nil {
  410. errMsg = errors.New("新增邮箱PV失败, Err: " + e.Error())
  411. return
  412. }
  413. // 更新阅读量
  414. if e = models.UpdateTrialEnglishReportEmailViewTotal(userEmail.Id); e != nil {
  415. errMsg = errors.New("更新英文联系人阅读量失败, Err: " + e.Error())
  416. return
  417. }
  418. if userEmail.CompanyId > 0 {
  419. if e = models.UpdateTrialEnglishCompanyViewTotal(userEmail.CompanyId); e != nil {
  420. errMsg = errors.New("更新英文客户阅读量, Err: " + e.Error())
  421. return
  422. }
  423. }
  424. }()
  425. }
  426. resp := new(models.EnglishReportShareDetailResp)
  427. resp.Report = report
  428. br.Ret = 200
  429. br.Success = true
  430. br.Msg = "获取成功"
  431. br.Data = resp
  432. }