english_report.go 11 KB

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