Pārlūkot izejas kodu

弘则-晨周报详情章节

hsun 1 gadu atpakaļ
vecāks
revīzija
ac6cafab1e

+ 1 - 0
.gitignore

@@ -4,3 +4,4 @@
 /binlog
 /*.exe
 /conf
+*.tar.gz

+ 2 - 2
controllers/english_report.go

@@ -20,7 +20,7 @@ type EnglishReportShareController struct {
 // @Description 英文研报-分享详情
 // @Param   ReportCode   query   string  true	"报告唯一编码"
 // @Param   ShareEmail   query   int  false	"推送的邮箱ID"
-// @Success 200 {object} models.ReportShareDetailResp
+// @Success 200 {object} models.EnglishReportShareDetailResp
 // @router /share/detail [get]
 func (this *EnglishReportShareController) EnglishReportDetail() {
 	br := new(models.BaseResponse).Init()
@@ -133,7 +133,7 @@ func (this *EnglishReportShareController) EnglishReportDetail() {
 // @Description 英文研报-分享详情
 // @Param   ReportCode   query   string  true	"报告唯一编码"
 // @Param   ShareEmail   query   int  false	"推送的邮箱ID"
-// @Success 200 {object} models.ReportShareDetailResp
+// @Success 200 {object} models.EnglishReportShareDetailResp
 // @router /trial/share/detail [get]
 func (this *EnglishReportShareController) TrialEnglishReportDetail() {
 	br := new(models.BaseResponse).Init()

+ 67 - 1
controllers/report_share.go

@@ -2,7 +2,9 @@ package controllers
 
 import (
 	"eta/eta_report/models"
+	"eta/eta_report/utils"
 	"html"
+	"time"
 )
 
 // ReportShareController 报告分享
@@ -63,7 +65,71 @@ func (this *ReportShareController) Detail() {
 		resp.WatermarkReport = v
 	}
 
-	resp.Report = report
+	// 晨周报
+	resp.Report = new(models.ReportItem)
+	reportChapters := make([]*models.ReportChapter, 0)
+	if utils.BusinessCode == utils.BusinessCodeRelease && report.HasChapter == 1 {
+		// 获取章节内容
+		chapters, e := models.GetPublishedChapterListByReportId(report.Id)
+		if e != nil {
+			br.Msg = "获取失败"
+			br.ErrMsg = "获取章节列表失败, Err: " + e.Error()
+			return
+		}
+
+		if len(chapters) > 0 {
+			// 获取更新规则
+			researchType := chapters[0].ReportType
+			types, e := models.GetAllReportChapterTypeListByResearchType(researchType)
+			if e != nil {
+				br.Msg = "获取更新规则失败"
+				br.ErrMsg = "获取更新规则失败, Err: " + e.Error()
+				return
+			}
+
+			// 调整章节更新
+			nowTime := time.Now().Local()
+			for _, chapter := range chapters {
+				stop := false
+				for _, rule := range types {
+					if rule.ReportChapterTypeId != chapter.TypeId {
+						continue
+					}
+					// 如果被永久暂停更新了
+					if rule.Enabled == 0 && chapter.IsEdit == 0 { //该章节已被永久禁用,同时未被操作过
+						stop = true
+					} else if rule.PauseStartTime != "" && rule.PauseEndTime != "" && rule.PauseStartTime != utils.EmptyDateStr && rule.PauseEndTime != utils.EmptyDateStr {
+						startTime, e := time.ParseInLocation(utils.FormatDate, rule.PauseStartTime, time.Local)
+						if e != nil {
+							br.Msg = "获取更新规则失败"
+							br.ErrMsg = "更新规则开始时间转换失败, Err: " + e.Error()
+							return
+						}
+						endTime, e := time.ParseInLocation(utils.FormatDate, rule.PauseEndTime, time.Local)
+						if e != nil {
+							br.Msg = "获取更新规则失败"
+							br.ErrMsg = "更新规则结束时间转换失败, Err: " + e.Error()
+							return
+						}
+						// 暂停更新
+						if nowTime.After(startTime) && nowTime.Before(endTime.AddDate(0, 0, 1)) {
+							stop = true
+						}
+						break
+					}
+				}
+				if !stop {
+					chapter.Content = html.UnescapeString(chapter.Content)
+					chapter.ContentSub = html.UnescapeString(chapter.ContentSub)
+					reportChapters = append(reportChapters, chapter)
+				}
+			}
+		}
+		report.Abstract = report.Title
+	}
+	resp.Report.Report = report
+	resp.Report.ChapterList = reportChapters
+
 	br.Ret = 200
 	br.Success = true
 	br.Msg = "获取成功"

+ 11 - 3
models/db.go

@@ -9,21 +9,29 @@ import (
 )
 
 func init() {
-
+	// eta_report
 	_ = orm.RegisterDataBase("default", "mysql", utils.MYSQL_URL)
 	orm.SetMaxIdleConns("default", 50)
 	orm.SetMaxOpenConns("default", 100)
 	db, _ := orm.GetDB("default")
 	db.SetConnMaxLifetime(10 * time.Minute)
 
-	// ETA默认库
+	// eta_master
 	_ = orm.RegisterDataBase("eta", "mysql", utils.MYSQL_URL_ETA)
 	orm.SetMaxIdleConns("eta", 50)
 	orm.SetMaxOpenConns("eta", 100)
-
 	etaDb, _ := orm.GetDB("eta")
 	etaDb.SetConnMaxLifetime(10 * time.Minute)
 
+	// crm_master
+	if utils.MYSQL_WEEKLY_URL != `` && utils.BusinessCode == utils.BusinessCodeRelease {
+		_ = orm.RegisterDataBase("weekly", "mysql", utils.MYSQL_WEEKLY_URL)
+		orm.SetMaxIdleConns("weekly", 50)
+		orm.SetMaxOpenConns("weekly", 100)
+		weeklyDb, _ := orm.GetDB("weekly")
+		weeklyDb.SetConnMaxLifetime(10 * time.Minute)
+	}
+
 	//注册对象
 	orm.RegisterModel(
 		new(Report),

+ 12 - 6
models/report.go

@@ -30,6 +30,7 @@ type Report struct {
 	IsShowNewLabel     int    `description:"是否显示新标签"`
 	IsCurrentDate      int    `description:"是否当前日期"`
 	ClassifyName       string `description:"分类名称"`
+	HasChapter         int    `description:"是否有章节"`
 }
 
 func GetReportByCode(reportCode string) (item *Report, err error) {
@@ -40,11 +41,16 @@ func GetReportByCode(reportCode string) (item *Report, err error) {
 }
 
 type ReportShareDetailResp struct {
-	Report           *Report `description:"报告"`
-	Disclaimer       string  `description:"免责声明"`
-	H5ShareName      string  `description:"研报分享抬头"`
-	H5ReportShareImg string  `description:"研报分享图片"`
-	WatermarkChart   string  `description:"图表是否需要水印"`
-	WatermarkReport  string  `description:"报告是否需要水印"`
+	Report           *ReportItem `description:"报告"`
+	Disclaimer       string      `description:"免责声明"`
+	H5ShareName      string      `description:"研报分享抬头"`
+	H5ReportShareImg string      `description:"研报分享图片"`
+	WatermarkChart   string      `description:"图表是否需要水印"`
+	WatermarkReport  string      `description:"报告是否需要水印"`
 	Hz               int
 }
+
+type ReportItem struct {
+	*Report
+	ChapterList []*ReportChapter
+}

+ 45 - 0
models/report_chapter.go

@@ -0,0 +1,45 @@
+package models
+
+import (
+	"github.com/beego/beego/v2/client/orm"
+	"time"
+)
+
+// ReportChapter 报告章节
+type ReportChapter struct {
+	ReportChapterId   int       `orm:"column(report_chapter_id);pk" description:"报告章节ID"`
+	ReportId          int       `description:"报告ID"`
+	ReportType        string    `description:"报告类型 day-晨报 week-周报"`
+	ClassifyIdFirst   int       `description:"一级分类id"`
+	ClassifyNameFirst string    `description:"一级分类名称"`
+	TypeId            int       `description:"品种ID"`
+	TypeName          string    `description:"品种名称"`
+	Title             string    `description:"标题"`
+	Abstract          string    `description:"摘要"`
+	AddType           int       `description:"新增方式:1:新增报告,2:继承报告"`
+	Author            string    `description:"作者"`
+	Content           string    `description:"内容"`
+	ContentSub        string    `description:"内容前两个章节"`
+	Stage             int       `description:"期数"`
+	Trend             string    `description:"趋势观点"`
+	Sort              int       `description:"排序: 数值越小越靠前"`
+	IsEdit            int       `description:"是否已编辑 0-待编辑 1-已编辑"`
+	PublishState      int       `description:"发布状态 1-待发布,2-已发布"`
+	PublishTime       time.Time `description:"发布时间"`
+	VideoUrl          string    `description:"音频文件URL"`
+	VideoName         string    `description:"音频文件名称"`
+	VideoPlaySeconds  string    `description:"音频播放时长"`
+	VideoSize         string    `description:"音频文件大小,单位M"`
+	VideoKind         int       `description:"音频生成方式:1,手动上传,2:自动生成"`
+	CreateTime        string    `description:"创建时间"`
+	ModifyTime        time.Time `description:"修改时间"`
+	OriginalVideoUrl  string    `description:"原始音频文件URL"`
+}
+
+// GetPublishedChapterListByReportId 根据ReportId获取已发布章节列表
+func GetPublishedChapterListByReportId(reportId int) (list []*ReportChapter, err error) {
+	o := orm.NewOrm()
+	sql := ` SELECT * FROM report_chapter WHERE report_id = ? AND publish_state = 2 ORDER BY sort ASC`
+	_, err = o.Raw(sql, reportId).QueryRows(&list)
+	return
+}

+ 43 - 0
models/report_chapter_type.go

@@ -0,0 +1,43 @@
+package models
+
+import (
+	"eta/eta_report/utils"
+	"github.com/beego/beego/v2/client/orm"
+	"time"
+)
+
+type ReportChapterType struct {
+	ReportChapterTypeId    int       `orm:"column(report_chapter_type_id);pk" description:"报告章节类型id"`
+	ReportChapterTypeKey   string    `description:"章节key"`
+	ReportChapterTypeThumb string    `description:"H5展示的图片"`
+	BannerUrl              string    `description:"banner显示图片"`
+	ReportChapterTypeName  string    `description:"报告章节类型名称"`
+	Sort                   int       `description:"排序字段"`
+	Enabled                int       `description:"启禁用状态"`
+	CreatedTime            time.Time `description:"创建时间"`
+	LastUpdatedTime        time.Time `description:"更新时间"`
+	ResearchType           string    `description:"研报类型"`
+	SelectedImage          string    `description:"选中时的图片"`
+	UnselectedImage        string    `description:"没选中时的图片"`
+	PcSelectedImage        string    `description:"PC-选中的图片"`
+	PcUnselectedImage      string    `description:"PC-未选中的图片"`
+	EditImgUrl             string    `description:"管理后台编辑时选用的图"`
+	TickerTitle            string    `description:"指标列的标题"`
+	IsShow                 int       `description:"是否显示(研报小程序端根据此字段判断)"`
+	PauseStartTime         string    `description:"暂停开始日期"`
+	PauseEndTime           string    `description:"暂停结束日期"`
+	IsSet                  int       `description:"是否设置:0为设置,1已设置"`
+	YbIconUrl              string    `description:"研报小程序icon"`
+	YbBottomIcon           string    `description:"研报小程序详情底部icon"`
+}
+
+// GetAllReportChapterTypeListByResearchType 通过报告类型获取章节类型列表
+func GetAllReportChapterTypeListByResearchType(researchType string) (list []*ReportChapterType, err error) {
+	if utils.BusinessCode != utils.BusinessCodeRelease {
+		return
+	}
+	o := orm.NewOrmUsingDB("weekly")
+	sql := ` SELECT * FROM report_chapter_type WHERE research_type = ?`
+	_, err = o.Raw(sql, researchType).QueryRows(&list)
+	return
+}

+ 5 - 3
utils/config.go

@@ -8,9 +8,10 @@ import (
 )
 
 var (
-	RunMode       string //运行模式
-	MYSQL_URL     string //数据库连接
-	MYSQL_URL_ETA string
+	RunMode          string //运行模式
+	MYSQL_URL        string //数据库连接
+	MYSQL_URL_ETA    string
+	MYSQL_WEEKLY_URL string //CRM主库
 
 	REDIS_CACHE string       //缓存地址
 	Rc          *cache.Cache //redis缓存
@@ -109,6 +110,7 @@ func init() {
 	fmt.Println(RunMode + " 模式")
 	MYSQL_URL = config["mysql_url"]
 	MYSQL_URL_ETA = config["mysql_url_eta"]
+	MYSQL_WEEKLY_URL = config["mysql_url_weekly"]
 
 	REDIS_CACHE = config["beego_cache"]
 	if len(REDIS_CACHE) <= 0 {

+ 8 - 0
utils/constants.go

@@ -12,6 +12,8 @@ const (
 	FormatDateTime        = "2006-01-02 15:04:05"     //完整时间格式
 	HlbFormatDateTime     = "2006-01-02_15:04:05.999" //完整时间格式
 	FormatDateTimeUnSpace = "20060102150405"          //完整时间格式
+	EmptyDateTimeStr      = "0000-00-00 00:00:00"     //DateTime零值字符串
+	EmptyDateStr          = "0000-00-00"              //Date零值字符串
 	PageSize15            = 15                        //列表页每页数据量
 	PageSize5             = 5
 	PageSize10            = 10
@@ -79,3 +81,9 @@ const (
 const (
 	CACHE_CREATE_REPORT_IMGPDF_QUEUE = "eta_report:report_img_pdf_queue" // 生成报告长图PDF队列
 )
+
+// 商户号
+const (
+	BusinessCodeSandbox = "E2023080700" // 试用平台
+	BusinessCodeRelease = "E2023080900" // 生产环境
+)