Răsfoiți Sursa

研报定时发布

xyxie 1 an în urmă
părinte
comite
3ad869f56c

+ 5 - 3
controllers/english_report/report.go

@@ -277,6 +277,7 @@ func (this *EnglishReportController) Detail() {
 	br.Data = item
 }
 
+// ListReport
 // @Title 获取报告列表接口
 // @Description 获取报告列表
 // @Param   PageSize   query   int  true       "每页数据条数"
@@ -338,7 +339,7 @@ func (this *EnglishReportController) ListReport() {
 		condition += ` AND (title LIKE '%` + keyWord + `%' OR author LIKE '%` + keyWord + `%' ) `
 	}
 
-	if  timeType == "" {
+	if timeType == "" {
 		timeType = "publish_time"
 	}
 	if timeType != "publish_time" && timeType != "modify_time" {
@@ -348,11 +349,11 @@ func (this *EnglishReportController) ListReport() {
 	}
 
 	if startDate != "" {
-		condition += ` AND `+timeType+` >= ? `
+		condition += ` AND ` + timeType + ` >= ? `
 		pars = append(pars, startDate)
 	}
 	if endDate != "" {
-		condition += ` AND `+timeType+` <= ? `
+		condition += ` AND ` + timeType + ` <= ? `
 		pars = append(pars, endDate)
 	}
 	if frequency != "" {
@@ -571,6 +572,7 @@ func (this *EnglishReportController) PublishReport() {
 	br.Msg = "发布成功"
 }
 
+// PrePublishReport
 // @Title 设置定时发布接口
 // @Description 设置定时发布接口
 // @Param	request	body models.PrePublishReq true "type json string"

+ 89 - 2
controllers/report.go

@@ -39,6 +39,7 @@ type ReportUploadCommonController struct {
 // @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       "频度"
@@ -59,6 +60,7 @@ func (this *ReportController) 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")
@@ -78,6 +80,15 @@ func (this *ReportController) ListReport() {
 	}
 	startSize = utils.StartIndex(currentIndex, pageSize)
 
+	if timeType == "" {
+		timeType = "publish_time"
+	}
+	if timeType != "publish_time" && timeType != "modify_time" {
+		br.Msg = "请选择正确的时间"
+		br.ErrMsg = "请选择正确的时间"
+		return
+	}
+
 	var condition string
 	var pars []interface{}
 
@@ -85,11 +96,11 @@ func (this *ReportController) ListReport() {
 		condition += ` AND (title LIKE '%` + keyWord + `%' OR author LIKE '%` + keyWord + `%' ) `
 	}
 	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 != "" {
@@ -3054,3 +3065,79 @@ func (this *ReportController) CheckDayWeekReportChapterVideo() {
 	br.Msg = "保存成功"
 	br.Data = typeNameArr
 }
+
+// PrePublishReport
+// @Title 设置定时发布接口
+// @Description 设置定时发布接口
+// @Param	request	body models.PrePublishReq true "type json string"
+// @Success 200 Ret=200 发布成功
+// @router /pre_publish [post]
+func (this *ReportController) 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.GetReportById(reportId)
+	if err != nil {
+		br.Msg = "获取报告信息失败"
+		br.ErrMsg = "获取报告信息失败,Err:" + err.Error()
+		return
+	}
+	if report == nil {
+		br.Msg = "报告不存在"
+		return
+	}
+	if report.ClassifyNameFirst == "晨报" || report.ClassifyNameFirst == "周报" {
+		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.SetPrePublishReportById(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 = "定时发布成功"
+}

+ 1 - 1
models/english_report.go

@@ -329,7 +329,7 @@ func PublishCancelEnglishReport(reportIds int) (err error) {
 	return
 }
 
-// 设置定时发布
+// SetPrePublishEnglishReportById 设置定时发布
 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 `

+ 9 - 0
models/report.go

@@ -56,6 +56,7 @@ type ReportList struct {
 	ModifyTime         time.Time                 `description:"修改时间"`
 	State              int                       `description:"1:未发布,2:已发布"`
 	PublishTime        string                    `description:"发布时间"`
+	PrePublishTime     string                    `description:"预发布时间"`
 	Stage              int                       `description:"期数"`
 	MsgIsSend          int                       `description:"模板消息是否已发送,0:否,1:是"`
 	Content            string                    `description:"内容"`
@@ -1011,3 +1012,11 @@ func ModifyReportMsgIsSendV2(reportId int) (err error) {
 	_, err = o.Raw(sql, reportId).Exec()
 	return
 }
+
+// SetPrePublishReportById 设置定时发布
+func SetPrePublishReportById(reportId int, prePublishTime string) (err error) {
+	o := orm.NewOrmUsingDB("rddp")
+	sql := `UPDATE report SET pre_publish_time=? WHERE id = ? and state = 1 `
+	_, err = o.Raw(sql, prePublishTime, reportId).Exec()
+	return
+}

+ 9 - 0
routers/commentsRouter.go

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