english_report.go 15 KB

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