Bläddra i källkod

自由布局草稿保存

kobe6258 4 veckor sedan
förälder
incheckning
5419198722

+ 30 - 9
controllers/report_chapter.go

@@ -435,7 +435,7 @@ func (this *ReportController) EditDayWeekChapter() {
 	if reportInfo.ReportLayout == 3 {
 		//对自由布局的数据做一个处理
 		//自由布局更新每页的数据
-		ormList := report.ToOrmViewList(req.FreeLayoutContentPages, false, reportInfo.Id, 0)
+		ormList := report.ToOrmViewList(req.FreeLayoutContentPages, true, reportInfo.Id, reportChapterId)
 		var wg sync.WaitGroup
 		wg.Add(len(ormList))
 		for _, v := range ormList {
@@ -464,13 +464,13 @@ func (this *ReportController) EditDayWeekChapter() {
 					v.ContentStruct = html.EscapeString(v.ContentStruct)
 				}
 			}(v)
-			wg.Wait()
-			err = models.UpdateChapterFreeLayoutContentPage(reportInfo, reportChapterInfo, updateCols, tickerList, ormList)
-			if err != nil {
-				br.Msg = "保存失败"
-				br.ErrMsg = "保存失败,Err:" + err.Error()
-				return
-			}
+		}
+		wg.Wait()
+		err = models.UpdateChapterFreeLayoutContentPage(reportInfo, reportChapterInfo, updateCols, tickerList, ormList)
+		if err != nil {
+			br.Msg = "保存失败"
+			br.ErrMsg = "保存失败,Err:" + err.Error()
+			return
 		}
 	} else {
 		err = models.UpdateChapterAndTicker(reportInfo, reportChapterInfo, updateCols, tickerList)
@@ -821,7 +821,21 @@ func (this *ReportController) GetDayWeekChapter() {
 		br.ErrMsg = "无操作权限"
 		return
 	}
-
+	var pages []*report.ContentPage
+	if reportInfo.ReportLayout == 3 {
+		pages, err = report.GetSingleFreeLayoutChapterPagesByReportId(reportInfo.Id, reportChapterId)
+		if err != nil {
+			br.Msg = "获取自由布局页面列表"
+			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, chapterItem.Content)
+			page.ContentStruct = services.HandleReportContentStructTable(page.ReportId, chapterItem.ContentStruct)
+		}
+	}
 	chapterItem.Content = html.UnescapeString(chapterItem.Content)
 	chapterItem.ContentSub = html.UnescapeString(chapterItem.ContentSub)
 	chapterItem.ContentStruct = html.UnescapeString(chapterItem.ContentStruct)
@@ -839,6 +853,12 @@ func (this *ReportController) GetDayWeekChapter() {
 		tokenMap := make(map[string]string)
 		chapterItem.Content = services.HandleReportContent(chapterItem.Content, "add", tokenMap)
 		chapterItem.ContentStruct = services.HandleReportContentStruct(chapterItem.ContentStruct, "add", tokenMap)
+		if reportInfo.ReportLayout == 3 {
+			for _, page := range pages {
+				page.Content = services.HandleReportContent(page.Content, "add", tokenMap)
+				page.ContentStruct = services.HandleReportContentStruct(page.ContentStruct, "add", tokenMap)
+			}
+		}
 	}
 
 	// 授权用户列表map
@@ -876,6 +896,7 @@ func (this *ReportController) GetDayWeekChapter() {
 	}
 
 	resp := models.ReportChapterItemResp{
+		FreeLayoutPages:   pages,
 		ReportChapterItem: *chapterItem,
 		GrandAdminIdList:  chapterGrantIdList,
 		PermissionIdList:  chapterPermissionIdList,

+ 21 - 7
controllers/report_v2.go

@@ -699,6 +699,20 @@ func (this *ReportController) Detail() {
 			}
 		}
 		//item.Abstract = item.Title
+	}else{
+		if item.ReportLayout == 3 {
+			pages, err := report.GetFreeLayoutPagesByReportId(item.Id)
+			if err != nil {
+				br.Msg = "操作失败"
+				br.ErrMsg = "获取自由布局内容页失败, Err: " + err.Error()
+				return
+			}
+			for _, page := range pages {
+				page.Content = html.UnescapeString(page.Content)
+				page.ContentStruct = html.UnescapeString(page.ContentStruct)
+				pageList = append(pageList, page)
+			}
+		}
 	}
 	item.Content = html.UnescapeString(item.Content)
 	item.ContentSub = html.UnescapeString(item.ContentSub)
@@ -898,13 +912,13 @@ func (this *ReportController) SaveReportContent() {
 							v.ContentStruct = html.EscapeString(v.ContentStruct)
 						}
 					}(v)
-					wg.Wait()
-					err = models.InsertOrUpdateReportFreeLayoutContentPage(reportInfo, ormList)
-					if err != nil {
-						br.Msg = "保存失败"
-						br.ErrMsg = "保存失败,Err:" + err.Error()
-						return
-					}
+				}
+				wg.Wait()
+				err = models.InsertOrUpdateReportFreeLayoutContentPage(reportInfo, ormList)
+				if err != nil {
+					br.Msg = "保存失败"
+					br.ErrMsg = "保存失败,Err:" + err.Error()
+					return
 				}
 			} else {
 				updateCols := []string{"Content", "ContentSub", "ContentStruct", "HeadImg", "EndImg", "CanvasColor", "HeadResourceId", "EndResourceId", "ModifyTime", "ContentModifyTime"}

+ 29 - 9
models/report/report_free_layout.go

@@ -88,17 +88,14 @@ func (*ReportFreeLayout) TableName() string {
 }
 
 func BatchInsertOrUpdatePages(tx *gorm.DB, list []*ReportFreeLayout, isChapter bool, reportId, chapterId int) (err error) {
-	tx.Clauses(clause.OnConflict{
-		Columns:   []clause.Column{{Name: "report_id"}, {Name: "report_chapter_id"}, {Name: "page"}},
-		DoUpdates: clause.AssignmentColumns([]string{"content", "content_struct", "modify_time", "is_deleted"}),
-	})
+
 	if isChapter {
-		err = tx.Where("report_id = ? and report_chapter_id=? and is_chapter=1", reportId, chapterId).Update("is_deleted", 1).Error
+		err = tx.Model(&ReportFreeLayout{}).Where("report_id = ? and report_chapter_id=? and is_chapter=1", reportId, chapterId).Update("is_deleted", 1).Error
 		if err != nil {
 			return
 		}
 	} else {
-		err = tx.Where("report_id = ? and report_chapter_id=? and is_chapter=0", reportId, chapterId).Update("is_deleted", 1).Error
+		err = tx.Model(&ReportFreeLayout{}).Where("report_id = ? and report_chapter_id=? and is_chapter=0", reportId, chapterId).Update("is_deleted", 1).Error
 		if err != nil {
 			return
 		}
@@ -106,13 +103,36 @@ func BatchInsertOrUpdatePages(tx *gorm.DB, list []*ReportFreeLayout, isChapter b
 	if err != nil {
 		return
 	}
-	err = tx.CreateInBatches(list, len(list)).Error
+	err = tx.Model(&ReportFreeLayout{}).Clauses(clause.OnConflict{
+		Columns:   []clause.Column{{Name: "report_id"}, {Name: "report_chapter_id"}, {Name: "page"}},
+		DoUpdates: clause.AssignmentColumns([]string{"content", "content_struct", "modify_time", "is_deleted"}),
+	}).CreateInBatches(list, len(list)).Error
 	return
 }
 
-func GetFreeLayoutChapterPagesByReportId(id int) (list []*ContentPage, err error) {
+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 =? and  is_deleted=0 order by rc.sort,rfl.page asc`
+	err = global.DbMap[utils.DbNameReport].Raw(sql, reportId).Find(&ormList).Error
+	if err != nil {
+		return nil, err
+	}
+	list = ToPageViewList(ormList)
+	return
+}
+func GetSingleFreeLayoutChapterPagesByReportId(reportId, chapterId int) (list []*ContentPage, err error) {
+	var ormList []*ReportFreeLayout
+	sql := `select * from report_free_layout where report_id =? and report_chapter_id=? and  is_deleted=0 order by page asc`
+	err = global.DbMap[utils.DbNameReport].Raw(sql, reportId,chapterId).Find(&ormList).Error
+	if err != nil {
+		return nil, err
+	}
+	list = ToPageViewList(ormList)
+	return
+}
+func GetFreeLayoutPagesByReportId(id 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 is_deleted=0 order by rc.sort,rfl.page asc`
+	sql := `select * from report_free_layout   where report_id =? and is_deleted=0 and is_chapter=0 order by page asc`
 	err = global.DbMap[utils.DbNameReport].Raw(sql, id).Find(&ormList).Error
 	if err != nil {
 		return nil, err

+ 1 - 0
models/report_chapter.go

@@ -134,6 +134,7 @@ func (m *ReportChapterItem) ConvDateTimeStr() {
 // @Description: 章节详情(带有一些额外的数据)
 type ReportChapterItemResp struct {
 	ReportChapterItem
+	FreeLayoutPages  []*report.ContentPage
 	GrandAdminIdList []int  `description:"授权的用户id列表"`
 	PermissionIdList []int  `description:"关联的品种id列表"`
 	CanEdit          bool   `description:"是否可编辑"`