123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259 |
- package controllers
- import (
- "encoding/json"
- "eta/eta_report/models"
- "fmt"
- "html"
- "strings"
- )
- // ReportShareController 报告分享
- type ReportShareController struct {
- BaseCommonController
- }
- // Detail
- // @Title 日评详情
- // @Description 日评详情接口
- // @Param ReportCode query string true "报告唯一编码"
- // @Param IsReplace query int false "是否报告转长图的场景:1-是"
- // @Success 200 {object} models.ReportShareDetailResp
- // @router /share/detail [get]
- func (this *ReportShareController) Detail() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- reportCode := this.GetString("ReportCode")
- isReplace, _ := this.GetInt("IsReplace", 0)
- if reportCode == "" {
- br.Msg = "参数错误"
- br.ErrMsg = "参数错误,reportCode 为空"
- return
- }
- report, err := models.GetReportByCode(reportCode)
- if err != nil {
- br.Msg = "该报告已删除"
- br.ErrMsg = "获取报告详情失败,Err:" + err.Error()
- return
- }
- report.ContentSub = html.UnescapeString(report.ContentSub)
- report.Content = html.UnescapeString(report.Content)
- report.ContentStruct = html.UnescapeString(report.ContentStruct)
- if report.HeadResourceId > 0 {
- headResource, err := models.GetResourceItemById(report.HeadResourceId)
- if err != nil {
- br.Msg = "操作失败"
- br.ErrMsg = "获取资源库版头失败, Err: " + err.Error()
- return
- }
- report.HeadImg = headResource.ImgUrl
- report.HeadStyle = headResource.Style
- }
- if report.EndResourceId > 0 {
- endResource, err := models.GetResourceItemById(report.EndResourceId)
- if err != nil {
- br.Msg = "操作失败"
- br.ErrMsg = "获取资源库版头失败, Err: " + err.Error()
- return
- }
- report.EndImg = endResource.ImgUrl
- report.EndStyle = endResource.Style
- }
- resp := new(models.ReportShareDetailResp)
- // 免责声明
- conf, e := models.GetBusinessConf()
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取免责声明失败, Err: " + e.Error()
- return
- }
- // (为了兼容内网客户)需要判断是否替换资源地址
- var urlReplace models.Report2ImgReplace
- if isReplace == 1 && conf[models.BusinessConfReport2ImgReplace] != "" {
- if e := json.Unmarshal([]byte(conf[models.BusinessConfReport2ImgReplace]), &urlReplace); e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = fmt.Sprintf("获取报告替换配置失败, %v", e)
- return
- }
- }
- if conf[models.BusinessConfDisclaimer] != "" {
- resp.Disclaimer = conf[models.BusinessConfDisclaimer]
- }
- // 研报分享抬头
- if v, ok := conf[models.BusinessConfH5ShareName]; ok {
- resp.H5ShareName = v
- }
- if v, ok := conf[models.BusinessConfH5ReportShareImg]; ok {
- resp.H5ReportShareImg = v
- }
- if v, ok := conf[models.BusinessConfWatermarkChart]; ok {
- resp.WatermarkChart = v
- }
- if v, ok := conf[models.BusinessConfWatermarkReport]; ok {
- resp.WatermarkReport = v
- }
- // 报告Logo
- if v, ok := conf[models.BusinessConfReportCenterLogoShow]; ok {
- if v == `true` {
- if reportLogo, ok := conf[models.BusinessConfReportLogo]; ok {
- resp.ReportLogo = reportLogo
- }
- }
- }
- // 章节类型的报告
- resp.Report = new(models.ReportItem)
- reportChapters := make([]*models.ReportChapter, 0)
- if report.HasChapter == 1 {
- // 获取章节内容
- chapters, e := models.GetPublishedChapterListByReportId(report.Id)
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取章节列表失败, Err: " + e.Error()
- return
- }
- if len(chapters) > 0 {
- for _, chapter := range chapters {
- chapter.Content = html.UnescapeString(chapter.Content)
- chapter.ContentSub = html.UnescapeString(chapter.ContentSub)
- if urlReplace.IsReplace {
- if urlReplace.OssUrlOrigin != "" {
- chapter.Content = strings.ReplaceAll(chapter.Content, urlReplace.OssUrlOrigin, urlReplace.OssUrlNew)
- chapter.ContentSub = strings.ReplaceAll(chapter.ContentSub, urlReplace.OssUrlOrigin, urlReplace.OssUrlNew)
- }
- if urlReplace.ChartUrlOrigin != "" {
- chapter.Content = strings.ReplaceAll(chapter.Content, urlReplace.ChartUrlOrigin, urlReplace.ChartUrlNew)
- chapter.ContentSub = strings.ReplaceAll(chapter.ContentSub, urlReplace.ChartUrlOrigin, urlReplace.ChartUrlNew)
- }
- }
- reportChapters = append(reportChapters, chapter)
- }
- }
- //report.Abstract = report.Title
- }
- // 替换地址
- if urlReplace.IsReplace {
- if urlReplace.OssUrlOrigin != "" {
- resp.H5ReportShareImg = strings.ReplaceAll(resp.H5ReportShareImg, urlReplace.OssUrlOrigin, urlReplace.OssUrlNew)
- resp.ReportLogo = strings.ReplaceAll(resp.ReportLogo, urlReplace.OssUrlOrigin, urlReplace.OssUrlNew)
- report.Content = strings.ReplaceAll(report.Content, urlReplace.OssUrlOrigin, urlReplace.OssUrlNew)
- report.ContentSub = strings.ReplaceAll(report.ContentSub, urlReplace.OssUrlOrigin, urlReplace.OssUrlNew)
- }
- if urlReplace.ChartUrlOrigin != "" {
- report.Content = strings.ReplaceAll(report.Content, urlReplace.ChartUrlOrigin, urlReplace.ChartUrlNew)
- report.ContentSub = strings.ReplaceAll(report.ContentSub, urlReplace.ChartUrlOrigin, urlReplace.ChartUrlNew)
- }
- }
- // 更新pv
- if e = models.UpdateReportPv(report.Id); e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "更新报告pv失败, Err: " + e.Error()
- return
- }
- resp.Report.Report = report
- resp.Report.ChapterList = reportChapters
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // OutSideReportDetail
- // @Title 日评详情
- // @Description 日评详情接口
- // @Param ReportCode query string true "报告唯一编码"
- // @Success 200 {object} models.ReportShareDetailResp
- // @router /share/outside/report/detail [get]
- func (this *ReportShareController) OutSideReportDetail() {
- 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.GetOutsideReportByReportCode(reportCode)
- if err != nil {
- br.Msg = "该报告已删除"
- br.ErrMsg = "获取报告详情失败,Err:" + err.Error()
- return
- }
- report.Content = html.UnescapeString(report.Content)
- attachmentList, err := models.GetOutsideReportAttachmentListByReportId(report.OutsideReportId)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取附件列表失败, Err: " + err.Error()
- return
- }
- outsideReportBO := models.OutsideReportBO{
- OutsideReportId: report.OutsideReportId,
- Source: report.Source,
- Title: report.Title,
- Abstract: report.Abstract,
- ClassifyId: report.ClassifyId,
- ClassifyName: report.ClassifyName,
- Content: report.Content,
- SysUserId: report.SysUserId,
- SysUserName: report.SysUserName,
- AttachmentList: attachmentList,
- }
- resp := new(models.OutsideReportResp)
- // 免责声明
- conf, e := models.GetBusinessConf()
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取免责声明失败, Err: " + e.Error()
- return
- }
- if conf[models.BusinessConfDisclaimer] != "" {
- resp.Disclaimer = conf[models.BusinessConfDisclaimer]
- }
- // 研报分享抬头
- if v, ok := conf[models.BusinessConfH5ShareName]; ok {
- resp.H5ShareName = v
- }
- if v, ok := conf[models.BusinessConfH5ReportShareImg]; ok {
- resp.H5ReportShareImg = v
- }
- if v, ok := conf[models.BusinessConfWatermarkChart]; ok {
- resp.WatermarkChart = v
- }
- if v, ok := conf[models.BusinessConfWatermarkReport]; ok {
- resp.WatermarkReport = v
- }
- // 报告Logo
- if v, ok := conf[models.BusinessConfReportCenterLogoShow]; ok {
- if v == `true` {
- if reportLogo, ok := conf[models.BusinessConfReportLogo]; ok {
- resp.ReportLogo = reportLogo
- }
- }
- }
- resp.OutsideReportBO = &outsideReportBO
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
|