Roc 8 months ago
parent
commit
96335a436b
3 changed files with 79 additions and 129 deletions
  1. 45 84
      controllers/report_chapter.go
  2. 4 44
      controllers/report_v2.go
  3. 30 1
      services/report_v2.go

+ 45 - 84
controllers/report_chapter.go

@@ -626,96 +626,57 @@ func (this *ReportController) GetReportChapterList() {
 			}
 		}
 
-		// TODO 获取更新规则
-		researchType := chapterList[0].ReportType
-		chapterTypeList, tmpErr := models.GetAllReportChapterTypeListByResearchType(researchType)
-		if tmpErr != nil {
-			br.Msg = "获取更新规则失败"
-			br.ErrMsg = "获取更新规则失败, Err: " + tmpErr.Error()
-			return
-		}
-		// 调整章节更新
-		nowTime := time.Now().Local()
+		// 章节类型的字段
 		for _, item := range chapterList {
-			stop := false
-			for _, rule := range chapterTypeList {
-				if rule.ReportChapterTypeId == item.TypeId {
-					//fmt.Println("rule.Enabled :", rule.Enabled, ";name=", rule.ReportChapterTypeName, "item.IsEdit:", item.IsEdit, "rule.IsSet:", rule.IsSet)
-					// 如果被永久暂停更新了
-					if rule.Enabled == 0 && item.IsEdit == 0 { //该章节已被永久禁用,同时未被操作过
-						stop = true
-					} else if rule.PauseStartTime != "" && rule.PauseEndTime != "" && rule.PauseStartTime != utils.EmptyDateStr && rule.PauseEndTime != utils.EmptyDateStr {
-						startTime, timeErr := time.ParseInLocation(utils.FormatDate, rule.PauseStartTime, time.Local)
-						if timeErr != nil {
-							br.Msg = "获取更新规则失败"
-							br.ErrMsg = "更新规则时间转换失败4001, Err: " + timeErr.Error()
-							return
-						}
-						endTime, timeErr := time.ParseInLocation(utils.FormatDate, rule.PauseEndTime, time.Local)
-						if timeErr != nil {
-							br.Msg = "获取更新规则失败"
-							br.ErrMsg = "更新规则时间转换失败4002, Err: " + timeErr.Error()
-							return
-						}
-						// 暂停更新
-						if nowTime.After(startTime) && nowTime.Before(endTime.AddDate(0, 0, 1)) {
-							stop = true
-						}
-						break
-					}
-				}
+			// 授权的用户列表
+			tmpChapterIdGrandList, ok := chapterIdGrandListMap[item.ReportChapterId]
+			if !ok {
+				tmpChapterIdGrandList = make([]int, 0)
+			}
+			// 关联的品种列表
+			tmpChapterIdPermissionList, ok := chapterIdPermissionListMap[item.ReportChapterId]
+			if !ok {
+				tmpChapterIdPermissionList = make([]int, 0)
 			}
-			if !stop {
-				// 授权的用户列表
-				tmpChapterIdGrandList, ok := chapterIdGrandListMap[item.ReportChapterId]
-				if !ok {
-					tmpChapterIdGrandList = make([]int, 0)
-				}
-				// 关联的品种列表
-				tmpChapterIdPermissionList, ok := chapterIdPermissionListMap[item.ReportChapterId]
-				if !ok {
-					tmpChapterIdPermissionList = make([]int, 0)
-				}
 
-				tmpChapterItem := models.ReportChapterResp{
-					ReportChapterId:  item.ReportChapterId,
-					ReportId:         item.ReportId,
-					ReportType:       item.ReportType,
-					TypeId:           item.TypeId,
-					TypeName:         item.TypeName,
-					TypeEditImg:      typeIdImg[item.TypeId],
-					Title:            item.Title,
-					IsEdit:           item.IsEdit,
-					Trend:            item.Trend,
-					Sort:             item.Sort,
-					PublishState:     item.PublishState,
-					VideoUrl:         item.VideoUrl,
-					VideoName:        item.VideoName,
-					VideoPlaySeconds: item.VideoPlaySeconds,
-					VideoSize:        item.VideoSize,
-					VideoKind:        item.VideoKind,
-					ModifyTime:       item.ModifyTime.Format(utils.FormatDate),
-					GrandAdminIdList: tmpChapterIdGrandList,
-					PermissionIdList: tmpChapterIdPermissionList,
-				}
-				markStatus, err := services.UpdateReportEditMark(item.ReportId, item.ReportChapterId, this.SysUser.AdminId, 2, this.SysUser.RealName, this.Lang)
-				if err != nil {
-					br.Msg = "查询标记状态失败"
-					br.ErrMsg = "查询标记状态失败,Err:" + err.Error()
-					return
-				}
+			tmpChapterItem := models.ReportChapterResp{
+				ReportChapterId:  item.ReportChapterId,
+				ReportId:         item.ReportId,
+				ReportType:       item.ReportType,
+				TypeId:           item.TypeId,
+				TypeName:         item.TypeName,
+				TypeEditImg:      typeIdImg[item.TypeId],
+				Title:            item.Title,
+				IsEdit:           item.IsEdit,
+				Trend:            item.Trend,
+				Sort:             item.Sort,
+				PublishState:     item.PublishState,
+				VideoUrl:         item.VideoUrl,
+				VideoName:        item.VideoName,
+				VideoPlaySeconds: item.VideoPlaySeconds,
+				VideoSize:        item.VideoSize,
+				VideoKind:        item.VideoKind,
+				ModifyTime:       item.ModifyTime.Format(utils.FormatDate),
+				GrandAdminIdList: tmpChapterIdGrandList,
+				PermissionIdList: tmpChapterIdPermissionList,
+			}
+			markStatus, err := services.UpdateReportEditMark(item.ReportId, item.ReportChapterId, this.SysUser.AdminId, 2, this.SysUser.RealName, this.Lang)
+			if err != nil {
+				br.Msg = "查询标记状态失败"
+				br.ErrMsg = "查询标记状态失败,Err:" + err.Error()
+				return
+			}
 
-				if markStatus.Status == 0 {
-					tmpChapterItem.CanEdit = true
-				} else {
-					tmpChapterItem.Editor = markStatus.Editor
-				}
+			if markStatus.Status == 0 {
+				tmpChapterItem.CanEdit = true
+			} else {
+				tmpChapterItem.Editor = markStatus.Editor
+			}
 
-				// 报告章节的操作权限
-				tmpChapterItem.IsAuth = services.CheckChapterAuthByAdminIdList(sysUser.AdminId, reportInfo.AdminId, tmpChapterIdGrandList)
+			// 报告章节的操作权限
+			tmpChapterItem.IsAuth = services.CheckChapterAuthByAdminIdList(sysUser.AdminId, reportInfo.AdminId, tmpChapterIdGrandList)
 
-				resp = append(resp, tmpChapterItem)
-			}
+			resp = append(resp, tmpChapterItem)
 		}
 	}
 

+ 4 - 44
controllers/report_v2.go

@@ -590,52 +590,12 @@ func (this *ReportController) Detail() {
 			return
 		}
 
-		// TODO 更新规则
 		if len(tmpChapterList) > 0 {
-			// 获取更新规则
-			researchType := tmpChapterList[0].ReportType
-			chapterTypeList, tmpErr := models.GetAllReportChapterTypeListByResearchType(researchType)
-			if tmpErr != nil {
-				br.Msg = "获取更新规则失败"
-				br.ErrMsg = "获取更新规则失败, Err: " + tmpErr.Error()
-				return
-			}
-			// 调整章节更新
-			nowTime := time.Now().Local()
+			// 章节类型的字段赋值
 			for _, item := range tmpChapterList {
-				stop := false
-				for _, rule := range chapterTypeList {
-					if rule.ReportChapterTypeId == item.TypeId {
-						//fmt.Println("rule.Enabled :", rule.Enabled, ";name=", rule.ReportChapterTypeName, "item.IsEdit:", item.IsEdit, "rule.IsSet:", rule.IsSet)
-						// 如果被永久暂停更新了
-						if rule.Enabled == 0 && item.IsEdit == 0 { //该章节已被永久禁用,同时未被操作过
-							stop = true
-						} else if rule.PauseStartTime != "" && rule.PauseEndTime != "" && rule.PauseStartTime != utils.EmptyDateStr && rule.PauseEndTime != utils.EmptyDateStr {
-							startTime, timeErr := time.ParseInLocation(utils.FormatDate, rule.PauseStartTime, time.Local)
-							if timeErr != nil {
-								br.Msg = "获取更新规则失败"
-								br.ErrMsg = "更新规则时间转换失败4001, Err: " + timeErr.Error()
-								return
-							}
-							endTime, timeErr := time.ParseInLocation(utils.FormatDate, rule.PauseEndTime, time.Local)
-							if timeErr != nil {
-								br.Msg = "获取更新规则失败"
-								br.ErrMsg = "更新规则时间转换失败4002, Err: " + timeErr.Error()
-								return
-							}
-							// 暂停更新
-							if nowTime.After(startTime) && nowTime.Before(endTime.AddDate(0, 0, 1)) {
-								stop = true
-							}
-							break
-						}
-					}
-				}
-				if !stop {
-					item.Content = html.UnescapeString(item.Content)
-					item.ContentSub = html.UnescapeString(item.ContentSub)
-					chapterList = append(chapterList, item)
-				}
+				item.Content = html.UnescapeString(item.Content)
+				item.ContentSub = html.UnescapeString(item.ContentSub)
+				chapterList = append(chapterList, item)
 			}
 		}
 

+ 30 - 1
services/report_v2.go

@@ -316,12 +316,41 @@ func getAddChapter(reportInfo *models.Report, minClassifyId, inheritReportId int
 
 	errMsg = "生成报告章节失败"
 	// 章节类型列表
-	typeList, err := models.GetReportChapterTypeListByClassifyId(minClassifyId)
+	allTypeList, err := models.GetReportChapterTypeListByClassifyId(minClassifyId)
 	if err != nil {
 		err = errors.New(errMsg)
 		return
 	}
 
+	// 待添加的章节
+	typeList := make([]*models.ReportChapterType, 0)
+
+	nowTime := time.Now().Local()
+	for _, chapterType := range allTypeList {
+		// 如果被永久暂停更新了
+		if chapterType.Enabled == 0 { //该章节已被永久禁用,那么就不允许继承或者新增该章节
+			continue
+		}
+
+		if chapterType.PauseStartTime != "" && chapterType.PauseEndTime != "" && chapterType.PauseStartTime != utils.EmptyDateStr && chapterType.PauseEndTime != utils.EmptyDateStr {
+			startTime, timeErr := time.ParseInLocation(utils.FormatDate, chapterType.PauseStartTime, time.Local)
+			if timeErr != nil {
+				utils.FileLog.Error("更新规则时间转换失败4001, Err: " + timeErr.Error())
+				continue
+			}
+			endTime, timeErr := time.ParseInLocation(utils.FormatDate, chapterType.PauseEndTime, time.Local)
+			if timeErr != nil {
+				utils.FileLog.Error("更新规则时间转换失败4002, Err: " + timeErr.Error())
+				continue
+			}
+			// 暂停更新
+			if nowTime.After(startTime) && nowTime.Before(endTime.AddDate(0, 0, 1)) {
+				continue
+			}
+			typeList = append(typeList, chapterType)
+		}
+	}
+
 	// 分类章节的授权用户
 	typeGrantListMap := make(map[int][]*report.ReportChapterGrant)
 	// 自定义章节列表