浏览代码

增加版头版尾资源

kobe6258 1 天之前
父节点
当前提交
f9a0edcfd5
共有 4 个文件被更改,包括 61 次插入20 次删除
  1. 18 6
      controllers/report_chapter.go
  2. 22 2
      models/report/report_free_layout.go
  3. 11 10
      models/report_chapter.go
  4. 10 2
      services/report_v2.go

+ 18 - 6
controllers/report_chapter.go

@@ -160,7 +160,6 @@ func (this *ReportController) AddChapter() {
 	//reportChapterInfo.CanvasColor = req.CanvasColor
 	//reportChapterInfo.HeadResourceId = req.HeadResourceId
 	//reportChapterInfo.EndResourceId = req.EndResourceId
-
 	err, errMsg := services.AddChapterBaseInfoAndPermission(reportInfo, reportChapterInfo, req.PermissionIdList, req.AdminIdList)
 	if err != nil {
 		br.Msg = "保存失败"
@@ -829,6 +828,7 @@ func (this *ReportController) GetDayWeekChapter() {
 		br.ErrMsg = "无操作权限"
 		return
 	}
+	var pageNum int
 	var pages []*report.ContentPage
 	if reportInfo.ReportLayout == 3 {
 		pages, err = report.GetSingleFreeLayoutChapterPagesByReportId(reportInfo.Id, reportChapterId)
@@ -837,11 +837,22 @@ func (this *ReportController) GetDayWeekChapter() {
 			br.ErrMsg = "获取自由布局页面列表,Err:" + err.Error()
 			return
 		}
-		for _, page := range pages {
-			page.Content = html.UnescapeString(page.Content)
-			page.ContentStruct = html.UnescapeString(page.ContentStruct)
-			page.Content = services.HandleReportContentTable(page.ReportId, page.Content)
-			page.ContentStruct = services.HandleReportContentStructTable(page.ReportId, page.ContentStruct)
+		if len(pages) == 0 {
+			//获取当前章节前置章节总页数
+			pageNum, err = report.GetPrevFreeLayoutChaptersPagesByChapterId(reportInfo.Id, reportChapterId)
+			if err != nil {
+				br.Msg = "获取自由布局前置章节总页数"
+				br.ErrMsg = "获取自由布局前置章节总页数,Err:" + err.Error()
+				return
+			}
+
+		} else {
+			for _, page := range pages {
+				page.Content = html.UnescapeString(page.Content)
+				page.ContentStruct = html.UnescapeString(page.ContentStruct)
+				page.Content = services.HandleReportContentTable(page.ReportId, page.Content)
+				page.ContentStruct = services.HandleReportContentStructTable(page.ReportId, page.ContentStruct)
+			}
 		}
 	}
 	chapterItem.Content = html.UnescapeString(chapterItem.Content)
@@ -905,6 +916,7 @@ func (this *ReportController) GetDayWeekChapter() {
 	resp := models.ReportChapterItemResp{
 		FreeLayoutContentPages: pages,
 		FreeLayoutConfig:       reportInfo.FreeLayoutConfig,
+		PreviousPagesNum:       pageNum,
 		ReportChapterItem:      *chapterItem,
 		GrandAdminIdList:       chapterGrantIdList,
 		PermissionIdList:       chapterPermissionIdList,

+ 22 - 2
models/report/report_free_layout.go

@@ -1,6 +1,7 @@
 package report
 
 import (
+	sql2 "database/sql"
 	"eta/eta_api/global"
 	"eta/eta_api/utils"
 	"gorm.io/gorm"
@@ -181,10 +182,29 @@ func BatchInsertOrUpdatePages(tx *gorm.DB, list []*ReportFreeLayout, isChapter b
 	}
 	return
 }
-
+func GetPrevFreeLayoutChaptersPagesByChapterId(reportId int, chapterId int) (pageNum int, err error) {
+	var pageNumNullable sql2.NullInt64
+	sql := `SELECT count(*) 
+FROM report_free_layout rfl
+JOIN report_chapter rc ON rc.report_id = rfl.report_id and rc.report_chapter_id=rfl.report_chapter_id
+WHERE rfl.report_id = ?
+  AND rc.sort < (
+    SELECT sort
+    FROM report_chapter
+    WHERE report_id = ? and report_chapter_id=?
+  )`
+	err = global.DbMap[utils.DbNameReport].Raw(sql, reportId, reportId, chapterId).Scan(&pageNumNullable).Error
+	if err != nil {
+		return
+	}
+	if pageNumNullable.Valid {
+		pageNum = int(pageNumNullable.Int64)
+	}
+	return
+}
 func GetFreeLayoutChapterPagesByReportId(reportId int) (list []*ContentPage, err error) {
 	var ormList []*ReportFreeLayout
-	sql := `select rfl.*,rc.sort from report_free_layout rfl LEFT JOIN report_chapter rc on rc.report_id=rfl.report_id  where rfl.report_id =? order by rc.sort,rfl.page asc`
+	sql := `select rfl.*,rc.sort from report_free_layout rfl LEFT JOIN report_chapter rc on rc.report_id=rfl.report_id and rc.report_chapter_id=rfl.report_chapter_id where rfl.report_id =? order by rc.sort,rfl.page asc`
 	err = global.DbMap[utils.DbNameReport].Raw(sql, reportId).Find(&ormList).Error
 	if err != nil {
 		return nil, err

+ 11 - 10
models/report_chapter.go

@@ -134,16 +134,17 @@ func (m *ReportChapterItem) ConvDateTimeStr() {
 // @Description: 章节详情(带有一些额外的数据)
 type ReportChapterItemResp struct {
 	ReportChapterItem
-	FreeLayoutContentPages  []*report.ContentPage
-	FreeLayoutConfig  string
-	GrandAdminIdList []int  `description:"授权的用户id列表"`
-	PermissionIdList []int  `description:"关联的品种id列表"`
-	CanEdit          bool   `description:"是否可编辑"`
-	Editor           string `description:"编辑人"`
-	HeadImg          string `description:"报告头图地址"`
-	EndImg           string `description:"报告尾图地址"`
-	HeadStyle        string `description:"版头样式"`
-	EndStyle         string `description:"版尾样式"`
+	FreeLayoutContentPages []*report.ContentPage
+	FreeLayoutConfig       string
+	PreviousPagesNum       int
+	GrandAdminIdList       []int  `description:"授权的用户id列表"`
+	PermissionIdList       []int  `description:"关联的品种id列表"`
+	CanEdit                bool   `description:"是否可编辑"`
+	Editor                 string `description:"编辑人"`
+	HeadImg                string `description:"报告头图地址"`
+	EndImg                 string `description:"报告尾图地址"`
+	HeadStyle              string `description:"版头样式"`
+	EndStyle               string `description:"版尾样式"`
 }
 
 type ReportChapterResp struct {

+ 10 - 2
services/report_v2.go

@@ -744,7 +744,15 @@ func AddChapterBaseInfoAndPermission(reportInfo *models.Report, reportChapterInf
 			CreateTime:        time.Now(),
 		})
 	}
-
+	if reportInfo.ReportLayout == 3 {
+		//增加默认排序
+		maxSort, sortErr := reportChapterInfo.GetMaxSortByReportId(reportInfo.Id)
+		if sortErr != nil {
+			err = fmt.Errorf("获取报告章节最大排序失败, ReportId: %d, Err: %v", reportInfo.Id, sortErr)
+			return
+		}
+		reportChapterInfo.Sort = maxSort + 1
+	}
 	err = models.AddChapterBaseInfoAndPermission(reportChapterInfo, addChapterAdminList, addChapterPermissionList)
 
 	return
@@ -1190,7 +1198,7 @@ func PublishReport(reportId int, reportUrl string, sysUser *system.Admin) (tips
 			content += page.Content
 		}
 		if content == "" {
-			errMsg= "自由布局报告内容为空,不可设置定时发布"
+			errMsg = "自由布局报告内容为空,不可设置定时发布"
 			err = errors.New("自由布局报告内容为空,不可设置定时发布,report_id:" + strconv.Itoa(reportInfo.Id))
 			return
 		}