123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494 |
- package controllers
- import (
- "encoding/json"
- "errors"
- "github.com/rdlucklib/rdluck_tools/paging"
- "hongze/hongze_api/models"
- "hongze/hongze_api/services/alarm_msg"
- services "hongze/hongze_api/services/elastic"
- "hongze/hongze_api/utils"
- "html"
- "strings"
- "time"
- )
- // EnglishReportShareController 报告分享
- type EnglishReportShareController struct {
- BaseCommonController
- }
- type EnglishReportController struct {
- BaseCommonController
- }
- // EnglishReportDetail
- // @Title 英文研报-分享详情
- // @Description 英文研报-分享详情
- // @Param ReportCode query string true "报告唯一编码"
- // @Param ShareEmail query int false "推送的邮箱ID"
- // @Success 200 {object} models.ReportShareDetailResp
- // @router /share/detail [get]
- func (this *EnglishReportShareController) EnglishReportDetail() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- reportCode := this.GetString("ReportCode")
- if reportCode == "" {
- br.Msg = "参数错误"
- br.ErrMsg = "参数错误,reportCode 为空"
- return
- }
- report, err := models.GetEnglishReportByCode(reportCode)
- if err != nil {
- br.Msg = "该报告已删除"
- br.ErrMsg = "获取报告详情失败,Err:" + err.Error()
- return
- }
- err = models.UpdateEnglishReportCounts(reportCode)
- if err != nil {
- br.Msg = "更新失败"
- br.ErrMsg = "更新失败,Err:" + err.Error()
- return
- }
- report.ContentSub = html.UnescapeString(report.ContentSub)
- report.Content = html.UnescapeString(report.Content)
- // 记录邮箱
- shareEmail, _ := this.GetInt("ShareEmail", 0)
- if shareEmail != 0 {
- go func() {
- var errMsg error
- defer func() {
- if errMsg != nil {
- alarm_msg.SendAlarmMsg(utils.APPNAME+"更新英文报告邮箱PV失败, Err: "+errMsg.Error(), 2)
- }
- }()
- userEmail, e := models.GetEnglishReportEmailById(shareEmail)
- if e != nil && e.Error() != utils.ErrNoRow() {
- errMsg = errors.New("获取客户邮箱信息失败, Err:" + e.Error())
- return
- }
- if userEmail == nil {
- return
- }
- // 更新报告邮箱pv(冗余)
- if e = models.UpdateEnglishReportEmailCounts(reportCode); e != nil {
- errMsg = errors.New("更新报告邮箱PV失败, Err:" + e.Error())
- return
- }
- // 记录邮箱PV
- pv := &models.EnglishReportEmailPV{
- ReportId: report.Id,
- EmailId: userEmail.Id,
- CreateTime: time.Now().Local(),
- }
- if e = pv.Create(); e != nil {
- errMsg = errors.New("新增邮箱PV失败, Err: " + e.Error())
- return
- }
- // 更新阅读量
- if e = models.UpdateEnglishReportEmailViewTotal(userEmail.Id); e != nil {
- errMsg = errors.New("更新英文联系人阅读量失败, Err: " + e.Error())
- return
- }
- if userEmail.CompanyId > 0 {
- if e = models.UpdateEnglishCompanyViewTotal(userEmail.CompanyId); e != nil {
- errMsg = errors.New("更新英文客户阅读量, Err: " + e.Error())
- return
- }
- }
- }()
- }
- // 免责声明
- conf, e := models.GetBusinessConf()
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取免责声明失败, Err: " + e.Error()
- return
- }
- resp := new(models.EnglishReportShareDetailResp)
- // 研报分享抬头
- if v, ok := conf[models.BusinessConfH5ShareEnName]; ok {
- resp.H5ShareEnName = v
- }
- if v, ok := conf[models.BusinessConfH5ReportShareImg]; ok {
- resp.H5ReportShareImg = v
- }
- resp.Hz = 1
- resp.Report = report
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // @Title 获取分类列表
- // @Description 获取分类列表
- // @Param PageSize query int true "每页数据条数"
- // @Param CurrentIndex query int true "当前页页码,从1开始"
- // @Param KeyWord query string true "检索关键词"
- // @Param CompanyType query string false "产品类型,枚举值:'ficc','权益';不传默认返回全部"
- // @Success 200 {object} models.EnglishClassifyListResp
- // @router /classify [get]
- func (this *EnglishReportController) Classify() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- parentList, err := models.GetParentEnglishClassify()
- if err != nil {
- br.Msg = "获取一级分类失败"
- br.ErrMsg = "获取一级分类失败,Err:" + err.Error()
- return
- }
- childList, err := models.GetChildEnglishClassify()
- if err != nil {
- br.Msg = "获取二级分类失败"
- br.ErrMsg = "获取二级分类失败,Err:" + err.Error()
- return
- }
- parentMap := make(map[int][]*models.EnglishClassify, 0)
- for _, v := range childList {
- parentMap[v.ParentId] = append(parentMap[v.ParentId], v)
- }
- list := make([]*models.EnglishClassifyList, 0)
- for _, v := range parentList {
- tmp := &models.EnglishClassifyList{
- Id: v.Id,
- ClassifyName: v.ClassifyName,
- Sort: v.Sort,
- ParentId: v.ParentId,
- CreateTime: v.CreateTime.Format(utils.FormatDateTime),
- ModifyTime: v.ModifyTime.Format(utils.FormatDateTime),
- ClassifyLabel: v.ClassifyLabel,
- ShowType: v.ShowType,
- IsShow: v.IsShow,
- }
- if child, ok := parentMap[v.Id]; ok {
- tmp.Child = child
- }
- list = append(list, tmp)
- }
- resp := new(models.EnglishClassifyListResp)
- resp.List = list
- br.Data = resp
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- }
- // @Title 获取报告列表接口
- // @Description 获取报告列表
- // @Param PageSize query int true "每页数据条数"
- // @Param CurrentIndex query int true "当前页页码,从1开始"
- // @Param StartDate query string true "开始时间"
- // @Param EndDate query string true "结束时间"
- // @Param Frequency query string true "频度"
- // @Param ClassifyNameFirst query string true "一级分类名称"
- // @Param ClassifyNameSecond query string true "二级分类名称"
- // @Param State query int true "状态"
- // @Param KeyWord query string true "搜索关键词"
- // @Param PublishSort query string true "desc:降序,asc 升序(预留)"
- // @Param CompanyType query string false "产品类型,枚举值:'ficc','权益';不传默认返回全部"
- // @Success 200 {object} models.ReportListResp
- // @router /list [get]
- func (this *EnglishReportController) ListReport() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- pageSize, _ := this.GetInt("PageSize")
- currentIndex, _ := this.GetInt("CurrentIndex")
- classifyIdFirst, _ := this.GetInt("ClassifyIdFirst")
- classifyIdSecond, _ := this.GetInt("ClassifyIdSecond")
- var startSize int
- if pageSize <= 0 {
- pageSize = utils.PageSize20
- }
- if currentIndex <= 0 {
- currentIndex = 1
- }
- startSize = utils.StartIndex(currentIndex, pageSize)
- var condition string
- var pars []interface{}
- if classifyIdFirst > 0 {
- condition += ` AND classify_id_first = ? `
- pars = append(pars, classifyIdFirst)
- }
- if classifyIdSecond > 0 {
- condition += ` AND classify_id_second = ? `
- pars = append(pars, classifyIdSecond)
- }
- total, err := models.GetEnglishReportListCount(condition, pars)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- detailList, err := models.GetEnglishReportList(condition, pars, startSize, pageSize)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- list := make([]*models.EnglishReportList, 0)
- for _, v := range detailList {
- tmp := &models.EnglishReportList{
- Id: v.Id,
- AddType: v.AddType,
- ClassifyIdFirst: v.ClassifyIdFirst,
- ClassifyNameFirst: v.ClassifyNameFirst,
- ClassifyIdSecond: v.ClassifyIdSecond,
- ClassifyNameSecond: v.ClassifyNameSecond,
- Title: v.Title,
- Abstract: v.Abstract,
- Author: v.Author,
- Frequency: v.Frequency,
- CreateTime: v.CreateTime,
- ModifyTime: v.ModifyTime,
- PublishTime: v.PublishTime,
- Stage: v.Stage,
- VideoUrl: v.VideoUrl,
- VideoName: v.VideoName,
- VideoPlaySeconds: v.VideoPlaySeconds,
- ReportCode: v.ReportCode,
- }
- if v.State == 2 {
- tmp.ShareUrl = "https://share.hzinsights.com/reportEn?code=" + v.ReportCode
- }
- list = append(list, tmp)
- }
- page := paging.GetPaging(currentIndex, pageSize, total)
- resp := new(models.EnglishReportListResp)
- resp.Paging = page
- resp.List = list
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // FilterByEs
- // @Title 英文报告筛选接口
- // @Description 英文报告筛选接口
- // @Param KeyWord query string false "搜索关键词:指标ID/指标名称"
- // @Param PageSize query int true "每页数据条数"
- // @Param CurrentIndex query int true "当前页页码,从1开始"
- // @Success 200 {object} data_manage.EdbInfoList
- // @router /filter_by_es [get]
- func (this *EnglishReportController) FilterByEs() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- pageSize, _ := this.GetInt("PageSize")
- currentIndex, _ := this.GetInt("CurrentIndex")
- var total int64
- var startSize int
- if pageSize <= 0 {
- pageSize = utils.PageSize20
- }
- if currentIndex <= 0 {
- currentIndex = 1
- }
- startSize = paging.StartIndex(currentIndex, pageSize)
- keyWord := this.GetString("KeyWord")
- keyWord = strings.TrimSpace(keyWord) //移除字符串首尾空格
- if keyWord == "" {
- br.Msg = "请输入关键词"
- return
- }
- reportList := make([]*models.SearchEnglishReportItem, 0)
- var err error
- searchResp, total, err := services.SearchESEnglishReport(keyWord, startSize, pageSize)
- if err != nil {
- br.Msg = "报告搜索失败"
- br.ErrMsg = "报告搜索失败,Err:" + err.Error()
- return
- }
- if searchResp.Hits != nil {
- for _, v := range searchResp.Hits.Hits {
- temp := new(models.SearchEnglishReportItem)
- itemJson, tmpErr := v.Source.MarshalJSON()
- if tmpErr != nil {
- br.Msg = "报告搜索失败 解析出错"
- br.ErrMsg = "报告搜索失败,Err:" + tmpErr.Error()
- return
- }
- reportItem := new(models.ElasticEnglishReportDetail)
- tmpErr = json.Unmarshal(itemJson, &reportItem)
- if tmpErr != nil {
- br.Msg = "报告搜索失败 解析json出错"
- br.ErrMsg = "报告搜索失败, 解析json出错,Err:" + tmpErr.Error()
- return
- }
- temp.Id = reportItem.ReportId
- temp.ClassifyIdFirst = reportItem.ClassifyIdFirst
- temp.ClassifyNameFirst = reportItem.ClassifyNameFirst
- temp.ClassifyIdSecond = reportItem.ClassifyIdSecond
- temp.ClassifyNameSecond = reportItem.ClassifyNameSecond
- temp.Title = reportItem.Title
- temp.Author = reportItem.Author
- temp.CreateTime = reportItem.CreateTime
- // 默认应该从数据库中查询
- temp.ContentSub = reportItem.ContentSub
- temp.PublishTime = reportItem.PublishTime
- temp.ReportCode = reportItem.ReportCode
- if len(v.Highlight["Title"]) > 0 {
- temp.Title = v.Highlight["Title"][0]
- }
- if len(v.Highlight["BodyContent"]) > 0 {
- temp.ContentSub = v.Highlight["BodyContent"][0]
- }
- temp.ContentSub = "<div style=\"-webkit-line-clamp: 3;-webkit-box-orient: vertical;display: -webkit-box;overflow: hidden;text-overflow: ellipsis;\">" + temp.ContentSub + "</div>"
- reportList = append(reportList, temp)
- }
- }
- page := paging.GetPaging(currentIndex, pageSize, int(total))
- //新增搜索词记录
- /*{
- searchKeyword := new(data_manage.SearchKeyword)
- searchKeyword.KeyWord = keyWord
- searchKeyword.CreateTime = time.Now()
- go data_manage.AddSearchKeyword(searchKeyword)
- }*/
- resp := models.SearchEnglishReportResp{
- Paging: page,
- List: reportList,
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "搜索成功"
- br.Data = resp
- }
- // TrialEnglishReportDetail
- // @Title 英文研报-分享详情-ETA试用平台
- // @Description 英文研报-分享详情
- // @Param ReportCode query string true "报告唯一编码"
- // @Param ShareEmail query int false "推送的邮箱ID"
- // @Success 200 {object} models.ReportShareDetailResp
- // @router /trial/share/detail [get]
- func (this *EnglishReportShareController) TrialEnglishReportDetail() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- reportCode := this.GetString("ReportCode")
- if reportCode == "" {
- br.Msg = "参数错误"
- br.ErrMsg = "参数错误,reportCode 为空"
- return
- }
- report, err := models.GetTrialEnglishReportByCode(reportCode)
- if err != nil {
- br.Msg = "该报告已删除"
- br.ErrMsg = "获取报告详情失败,Err:" + err.Error()
- return
- }
- err = models.UpdateTrialEnglishReportCounts(reportCode)
- if err != nil {
- br.Msg = "更新失败"
- br.ErrMsg = "更新失败,Err:" + err.Error()
- return
- }
- report.ContentSub = html.UnescapeString(report.ContentSub)
- report.Content = html.UnescapeString(report.Content)
- // 记录邮箱
- shareEmail, _ := this.GetInt("ShareEmail", 0)
- if shareEmail != 0 {
- go func() {
- var errMsg error
- defer func() {
- if errMsg != nil {
- alarm_msg.SendAlarmMsg(utils.APPNAME+"更新英文报告邮箱PV失败, Err: "+errMsg.Error(), 2)
- }
- }()
- userEmail, e := models.GetTrialEnglishReportEmailById(shareEmail)
- if e != nil && e.Error() != utils.ErrNoRow() {
- errMsg = errors.New("获取客户邮箱信息失败, Err:" + e.Error())
- return
- }
- if userEmail == nil {
- return
- }
- // 更新报告邮箱pv(冗余)
- if e = models.UpdateTrialEnglishReportEmailCounts(reportCode); e != nil {
- errMsg = errors.New("更新报告邮箱PV失败, Err:" + e.Error())
- return
- }
- // 记录邮箱PV
- pv := &models.EnglishReportEmailPV{
- ReportId: report.Id,
- EmailId: userEmail.Id,
- CreateTime: time.Now().Local(),
- }
- if e = models.InsertTrialEnglishReportEmailPV(pv); e != nil {
- errMsg = errors.New("新增邮箱PV失败, Err: " + e.Error())
- return
- }
- // 更新阅读量
- if e = models.UpdateTrialEnglishReportEmailViewTotal(userEmail.Id); e != nil {
- errMsg = errors.New("更新英文联系人阅读量失败, Err: " + e.Error())
- return
- }
- if userEmail.CompanyId > 0 {
- if e = models.UpdateTrialEnglishCompanyViewTotal(userEmail.CompanyId); e != nil {
- errMsg = errors.New("更新英文客户阅读量, Err: " + e.Error())
- return
- }
- }
- }()
- }
- resp := new(models.EnglishReportShareDetailResp)
- // 免责声明
- conf, e := models.GetBusinessConf()
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取免责声明失败, Err: " + e.Error()
- return
- }
- // 研报分享抬头
- if v, ok := conf[models.BusinessConfH5ShareEnName]; ok {
- resp.H5ShareEnName = v
- }
- if v, ok := conf[models.BusinessConfH5ReportShareImg]; ok {
- resp.H5ReportShareImg = v
- }
- resp.Hz = 1
- resp.Report = report
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
|