Răsfoiți Sursa

英文研报定时发布

xyxie 1 an în urmă
părinte
comite
07f34e112e

+ 94 - 3
controllers/english_report/report.go

@@ -281,6 +281,7 @@ func (this *EnglishReportController) Detail() {
 // @Description 获取报告列表
 // @Param   PageSize   query   int  true       "每页数据条数"
 // @Param   CurrentIndex   query   int  true       "当前页页码,从1开始"
+// @Param   TimeType     query string true  "筛选的时间类别:publish_time(发布时间),modify_time(更新时间)"
 // @Param   StartDate   query   string  true       "开始时间"
 // @Param   EndDate   query   string  true       "结束时间"
 // @Param   Frequency   query   string  true       "频度"
@@ -309,6 +310,7 @@ func (this *EnglishReportController) ListReport() {
 	pageSize, _ := this.GetInt("PageSize")
 	currentIndex, _ := this.GetInt("CurrentIndex")
 
+	timeType := this.GetString("TimeType")
 	startDate := this.GetString("StartDate")
 	endDate := this.GetString("EndDate")
 	frequency := this.GetString("Frequency")
@@ -335,12 +337,22 @@ func (this *EnglishReportController) ListReport() {
 	if keyWord != "" {
 		condition += ` AND (title LIKE '%` + keyWord + `%' OR author LIKE '%` + keyWord + `%' ) `
 	}
+
+	if  timeType == "" {
+		timeType = "publish_time"
+	}
+	if timeType != "publish_time" && timeType != "modify_time" {
+		br.Msg = "请选择正确的时间"
+		br.ErrMsg = "请选择正确的时间"
+		return
+	}
+
 	if startDate != "" {
-		condition += ` AND create_time >= ? `
+		condition += ` AND `+timeType+` >= ? `
 		pars = append(pars, startDate)
 	}
 	if endDate != "" {
-		condition += ` AND create_time <= ? `
+		condition += ` AND `+timeType+` <= ? `
 		pars = append(pars, endDate)
 	}
 	if frequency != "" {
@@ -537,7 +549,14 @@ func (this *EnglishReportController) PublishReport() {
 			br.ErrMsg = "报告内容为空,不需要生成,report_id:" + strconv.Itoa(report.Id)
 			return
 		}
-		if tmpErr = models.PublishEnglishReportById(report.Id); tmpErr != nil {
+		var publishTime string
+		if report.PublishTime != "" {
+			// 发布时间固定为首次发布时间
+			publishTime = report.PublishTime
+		} else {
+			publishTime = time.Now().Format(utils.FormatDateTime)
+		}
+		if tmpErr = models.PublishEnglishReportById(report.Id, publishTime); tmpErr != nil {
 			br.Msg = "报告发布失败"
 			br.ErrMsg = "报告发布失败, Err:" + tmpErr.Error() + ", report_id:" + strconv.Itoa(report.Id)
 			return
@@ -552,6 +571,78 @@ func (this *EnglishReportController) PublishReport() {
 	br.Msg = "发布成功"
 }
 
+// @Title 设置定时发布接口
+// @Description 设置定时发布接口
+// @Param	request	body models.PrePublishReq true "type json string"
+// @Success 200 Ret=200 发布成功
+// @router /pre_publish [post]
+func (this *EnglishReportController) PrePublishReport() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	var req models.PrePublishReq
+	err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
+	if err != nil {
+		br.Msg = "参数解析异常!"
+		br.ErrMsg = "参数解析失败,Err:" + err.Error()
+		return
+	}
+	reportId := req.ReportId
+	if reportId == 0 {
+		br.Msg = "参数错误"
+		br.ErrMsg = "参数错误,报告id不可为空"
+		return
+	}
+	if req.PrePublishTime == "" {
+		br.Msg = "发布时间不能为空"
+		return
+	}
+	prePublishTime, err := time.ParseInLocation(utils.FormatDateTime, req.PrePublishTime, time.Local)
+	if err != nil {
+		br.Msg = "发布时间格式错误"
+		br.ErrMsg = "发布时间格式错误,Err:" + err.Error()
+		return
+	}
+	if prePublishTime.Before(time.Now()) {
+		br.Msg = "发布时间不允许选择过去时间"
+		return
+	}
+	report, err := models.GetEnglishReportById(reportId)
+	if err != nil {
+		br.Msg = "获取报告信息失败"
+		br.ErrMsg = "获取报告信息失败,Err:" + err.Error()
+		return
+	}
+	if report == nil {
+		br.Msg = "报告不存在"
+		return
+	}
+
+	if report.Content == "" {
+		br.Msg = "报告内容为空,不可发布"
+		br.ErrMsg = "报告内容为空,不需要生成,report_id:" + strconv.Itoa(report.Id)
+		return
+	}
+
+	if report.State == 2 {
+		br.Msg = "报告已发布,不可设置定时发布"
+		return
+	}
+
+	var tmpErr error
+	if tmpErr = models.SetPrePublishEnglishReportById(report.Id, req.PrePublishTime); tmpErr != nil {
+		br.Msg = "设置定时发布失败"
+		br.ErrMsg = "设置定时发布失败, Err:" + tmpErr.Error() + ", report_id:" + strconv.Itoa(report.Id)
+		return
+	}
+
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "定时发布成功"
+}
+
 // @Title 取消发布报告接口
 // @Description 取消发布报告
 // @Param	request	body models.PublishCancelReq true "type json string"

+ 1 - 0
controllers/report.go

@@ -275,6 +275,7 @@ func (this *ReportController) PublishReport() {
 		var publishTime time.Time
 		if report.MsgIsSend == 1 && report.PublishTime != "" { //如果报告曾经发布过,并且已经发送过模版消息,则章节的发布时间为报告的发布时间
 			publishTime, _ = time.ParseInLocation(utils.FormatDateTime, report.PublishTime, time.Local)
+			// todo 发布时间调整
 		} else {
 			publishTime = time.Now()
 		}

+ 14 - 4
models/english_report.go

@@ -24,6 +24,7 @@ type EnglishReport struct {
 	ModifyTime         time.Time `description:"修改时间"`
 	State              int       `description:"1:未发布,2:已发布"`
 	PublishTime        time.Time `description:"发布时间"`
+	PrePublishTime     time.Time `description:"预发布时间"`
 	Stage              int       `description:"期数"`
 	Content            string    `description:"内容"`
 	VideoUrl           string    `description:"音频文件URL"`
@@ -237,6 +238,7 @@ type EnglishReportList struct {
 	ModifyTime         time.Time `description:"修改时间"`
 	State              int       `description:"1:未发布,2:已发布"`
 	PublishTime        string    `description:"发布时间"`
+	PrePublishTime     string    `description:"预发布时间"`
 	Stage              int       `description:"期数"`
 	Content            string    `description:"内容"`
 	VideoUrl           string    `description:"音频文件URL"`
@@ -312,21 +314,29 @@ func GetEnglishReportByCondition(condition string, pars []interface{}) (items []
 }
 
 // 发布报告
-func PublishEnglishReportById(reportId int) (err error) {
+func PublishEnglishReportById(reportId int, publishTime string) (err error) {
 	o := orm.NewOrmUsingDB("rddp")
-	sql := `UPDATE english_report SET state=2,publish_time=now(),modify_time=NOW() WHERE id = ? `
-	_, err = o.Raw(sql, reportId).Exec()
+	sql := `UPDATE english_report SET state=2,publish_time=?,pre_publish_time=null,modify_time=NOW() WHERE id = ? `
+	_, err = o.Raw(sql, publishTime, reportId).Exec()
 	return
 }
 
 // 取消发布报告
 func PublishCancelEnglishReport(reportIds int) (err error) {
 	o := orm.NewOrmUsingDB("rddp")
-	sql := ` UPDATE english_report SET state=1,publish_time=null WHERE id =?  `
+	sql := ` UPDATE english_report SET state=1,pre_publish_time=null WHERE id =?  `
 	_, err = o.Raw(sql, reportIds).Exec()
 	return
 }
 
+// 设置定时发布
+func SetPrePublishEnglishReportById(reportId int, prePublishTime string) (err error) {
+	o := orm.NewOrmUsingDB("rddp")
+	sql := `UPDATE english_report SET pre_publish_time=? WHERE id = ? and state = 1 `
+	_, err = o.Raw(sql, prePublishTime, reportId).Exec()
+	return
+}
+
 // DeleteEnglishReportAndChapter 删除报告及章节
 func DeleteEnglishReportAndChapter(reportInfo *EnglishReportDetail) (err error) {
 	reportId := reportInfo.Id

+ 5 - 0
models/report.go

@@ -257,6 +257,11 @@ type AddReq struct {
 	ReportVersion      int    `description:"1:旧版,2:新版"`
 }
 
+type PrePublishReq struct {
+	ReportId       int    `description:"报告id"`
+	PrePublishTime string `description:"预发布时间"`
+}
+
 type AddResp struct {
 	ReportId   int64  `description:"报告id"`
 	ReportCode string `description:"报告code"`

+ 9 - 0
routers/commentsRouter.go

@@ -3751,6 +3751,15 @@ func init() {
             Filters: nil,
             Params: nil})
 
+    beego.GlobalControllerRouter["hongze/hz_eta_api/controllers/english_report:EnglishReportController"] = append(beego.GlobalControllerRouter["hongze/hz_eta_api/controllers/english_report:EnglishReportController"],
+        beego.ControllerComments{
+            Method: "PrePublishReport",
+            Router: `/pre_publish`,
+            AllowHTTPMethods: []string{"post"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
     beego.GlobalControllerRouter["hongze/hz_eta_api/controllers/english_report:EnglishReportController"] = append(beego.GlobalControllerRouter["hongze/hz_eta_api/controllers/english_report:EnglishReportController"],
         beego.ControllerComments{
             Method: "PublishReport",