Browse Source

feat:新增接口获取报告中未发布的章节数

Roc 9 months ago
parent
commit
4dd042dda0
3 changed files with 84 additions and 7 deletions
  1. 60 7
      controllers/report_chapter.go
  2. 15 0
      models/report_chapter.go
  3. 9 0
      routers/commentsRouter.go

+ 60 - 7
controllers/report_chapter.go

@@ -1343,15 +1343,68 @@ func (this *ReportController) PublishDayWeekReportChapter() {
 	}
 
 	// 同时发布报告
-	if req.PublishReport == 1 {
-		if _, e := services.PublishDayWeekReport(chapterInfo.ReportId); e != nil {
-			br.Msg = "章节发布成功,报告发布失败,请手动发布报告"
-			br.ErrMsg = "发布晨/周报失败, Err: " + e.Error()
-			return
-		}
-	}
+	//if req.PublishReport == 1 {
+	//	if _, e := services.PublishDayWeekReport(chapterInfo.ReportId); e != nil {
+	//		br.Msg = "章节发布成功,报告发布失败,请手动发布报告"
+	//		br.ErrMsg = "发布晨/周报失败, Err: " + e.Error()
+	//		return
+	//	}
+	//}
 
 	br.Ret = 200
 	br.Success = true
 	br.Msg = "操作成功"
 }
+
+// GetUnPublishReportChapterCount
+// @Title 获取报告中未发布的章节数
+// @Description 获取报告中未发布的章节数
+// @Param	ReportId  query  int  true  "报告ID"
+// @Success 200 Ret=200 获取成功
+// @router /chapter/un_publish/count [get]
+func (this *ReportController) GetUnPublishReportChapterCount() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	sysUser := this.SysUser
+	if sysUser == nil {
+		br.Msg = "请登录"
+		br.ErrMsg = "请登录,SysUser Is Empty"
+		br.Ret = 408
+		return
+	}
+
+	reportId, _ := this.GetInt("ReportId")
+	if reportId <= 0 {
+		br.Msg = "参数有误"
+		br.IsSendEmail = false
+		return
+	}
+	reportInfo, err := models.GetReportById(reportId)
+	if err != nil {
+		br.Msg = "报告有误"
+		br.ErrMsg = "报告有误, Err: " + err.Error()
+		return
+	}
+
+	if reportInfo.HasChapter == 0 {
+		br.Msg = "报告未包含章节"
+		br.IsSendEmail = false
+		return
+	}
+
+	// 获取未发布的章节数
+	unPublishedNum, err := models.CountUnPublishedChapterNum(reportInfo.Id)
+	if err != nil {
+		br.Msg = "获取未发布的章节数失败"
+		br.ErrMsg = "获取未发布的章节数失败, Err: " + err.Error()
+		return
+	}
+
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "获取成功"
+	br.Data = unPublishedNum
+}

+ 15 - 0
models/report_chapter.go

@@ -311,6 +311,21 @@ func CountPublishedChapterNum(reportId int) (count int, err error) {
 	return
 }
 
+// CountUnPublishedChapterNum
+// @Description: 获取报告未发布的章节数
+// @author: Roc
+// @datetime 2024-06-14 15:59:23
+// @param reportId int
+// @return count int
+// @return err error
+func CountUnPublishedChapterNum(reportId int) (count int, err error) {
+	o := orm.NewOrmUsingDB("rddp")
+	sql := ` SELECT COUNT(1) AS ct FROM report_chapter WHERE report_id = ? AND publish_state = 1 `
+	err = o.Raw(sql, reportId).QueryRow(&count)
+
+	return
+}
+
 // GetChapterListByChapterIds 根据ReportId获取章节列表
 func GetChapterListByChapterIds(chapterIds []int) (list []*ReportChapter, err error) {
 	if len(chapterIds) == 0 {

+ 9 - 0
routers/commentsRouter.go

@@ -7846,6 +7846,15 @@ func init() {
             Filters: nil,
             Params: nil})
 
+    beego.GlobalControllerRouter["eta/eta_api/controllers:ReportController"] = append(beego.GlobalControllerRouter["eta/eta_api/controllers:ReportController"],
+        beego.ControllerComments{
+            Method: "GetUnPublishReportChapterCount",
+            Router: `/chapter/un_publish/count`,
+            AllowHTTPMethods: []string{"get"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
     beego.GlobalControllerRouter["eta/eta_api/controllers:ReportController"] = append(beego.GlobalControllerRouter["eta/eta_api/controllers:ReportController"],
         beego.ControllerComments{
             Method: "VoiceUpload",