package report

import (
	"errors"
	"fmt"
	report_chapter_type_cache "hongze/hongze_yb/cache/report_chapter_type"
	"hongze/hongze_yb/global"
	"hongze/hongze_yb/models/response"
	"hongze/hongze_yb/models/tables/company_product"
	"hongze/hongze_yb/models/tables/rddp/chart_permission_chapter_mapping"
	"hongze/hongze_yb/models/tables/rddp/classify"
	"hongze/hongze_yb/models/tables/rddp/report"
	"hongze/hongze_yb/models/tables/rddp/report_chapter"
	"hongze/hongze_yb/models/tables/rddp/smart_report_resource"
	"hongze/hongze_yb/models/tables/report_chapter_permission_mapping"
	"hongze/hongze_yb/models/tables/report_chapter_type"
	"hongze/hongze_yb/models/tables/user_report_chapter_set"
	"hongze/hongze_yb/services"
	"hongze/hongze_yb/services/base_config"
	"hongze/hongze_yb/services/collection"
	"hongze/hongze_yb/services/company"
	"hongze/hongze_yb/services/user"
	"hongze/hongze_yb/utils"
	"html"
	"sort"
	"strings"
	"time"
)

// GetReportTypeIdsByPermissionIds 获取所有和权限绑定的报告章节ID
func GetReportTypeIdsByPermissionIds(permissionIds []int) (ids []int, err error) {
	ids, err = chart_permission_chapter_mapping.GetReportIdsByPermisssionIds(permissionIds, "week")
	return
}

// GetLatestWeek 获取有权限的最新的周报
func GetLatestWeek(permissionIds []int, typeIds []int) (reportInfo *report.Report, err error) {
	newTypeIds, err := GetWeekTypeIdsByPermissionIds(permissionIds, typeIds)
	chapters, err := report_chapter.GetLatestChaptersByTypeIdsAndClass(newTypeIds, "week")
	if err != nil {
		return
	}
	var reportIds []int
	for _, v := range chapters {
		reportIds = append(reportIds, v.ReportId)
	}
	reportInfo, err = report.GetLatestByReportIds(reportIds)
	return
}

// GetWeekTypeIdsByPermissionIds 获取有权限的章节类型ID
func GetWeekTypeIdsByPermissionIds(permissionIds []int, typeIds []int) (newTypeIds []int, err error) {
	ids, err := GetReportTypeIdsByPermissionIds(permissionIds)
	if err != nil {
		return
	}
	if len(typeIds) == 0 {
		typeIds, err = report_chapter_type_cache.GetEffectTypeID()
		if err != nil {
			return
		}
	}
	for _, v1 := range typeIds {
		for _, v2 := range ids {
			if v1 == v2 {
				newTypeIds = append(newTypeIds, v2)
			}
		}
	}
	return
}

// GetChapterListByReport 根据报告获取章节列表
func GetChapterListByReport(classifyNameFirst string, reportId int, validWeekTypeIds []int, reportCreateTime time.Time) (reportTypeList response.ReportChapterList, err error) {
	var errMsg string
	defer func() {
		if err != nil {
			global.LOG.Critical(fmt.Sprintf("GetChapterListByReport: err:%s， errMsg:%s", err.Error(), errMsg))
		}
	}()
	//查询有效的章节
	typeList, tErr := report_chapter_type.GetEffectTypes()
	if tErr != nil {
		errMsg = tErr.Error()
		err = errors.New("章节类型查询出错")
		return
	}
	if len(typeList) == 0 {
		err = errors.New("无有效的章节")
		return
	}

	typeMap := make(map[uint64]*report_chapter_type.ReportChapterType)
	var typeIds []int
	newTypeMap := make(map[int]bool)
	for _, v := range typeList {
		typeMap[v.ReportChapterTypeId] = v
		typeIds = append(typeIds, int(v.ReportChapterTypeId))
	}

	if classifyNameFirst != "晨报" {
		for _, v := range validWeekTypeIds {
			newTypeMap[v] = true
		}
	}
	//获取所有当前研报的章节
	chapterList, tErr := report_chapter.GetListByReportId(reportId, classifyNameFirst)
	if tErr != nil && tErr != utils.ErrNoRow {
		errMsg = err.Error()
		err = errors.New("章节查询出错")
		return
	}
	if len(chapterList) == 0 {
		err = errors.New("无有效章节")
		return
	}

	for _, item := range chapterList {
		if typeItem, ok := typeMap[uint64(item.TypeId)]; ok {
			// 如果是周报只展示有权限的章节
			if classifyNameFirst == "周报" {
				if _, ok1 := newTypeMap[item.TypeId]; !ok1 {
					continue
				}
			}
			temp := new(response.ReportChapterListItem)
			if reportCreateTime.Before(typeItem.PauseStartTime) || reportCreateTime.After(typeItem.PauseEndTime) {
				temp.ReportChapterId = item.ReportChapterId
				temp.TypeId = item.TypeId
				temp.TypeName = item.TypeName
				temp.Title = item.Title
				temp.Trend = item.Trend
				temp.ReportId = item.ReportId
				temp.Sort = typeItem.Sort
				temp.PublishTime = item.PublishTime
				temp.ReportChapterTypeKey = typeItem.ReportChapterTypeKey
				temp.ReportChapterTypeName = typeItem.ReportChapterTypeName
				temp.ReportChapterTypeThumb = typeItem.YbIconUrl
				temp.VideoUrl = item.VideoUrl
				temp.VideoName = item.VideoName
				temp.VideoPlaySeconds = item.VideoPlaySeconds
				temp.VideoSize = item.VideoSize
				reportTypeList = append(reportTypeList, temp)
			}
		}
	}
	if len(reportTypeList) > 0 {
		sort.Sort(reportTypeList)
	}
	return
}

// GetChapterDetail 获取章节详情
func GetChapterDetail(user user.UserInfo, reportChapterId int) (reportChapterDetail *response.ReportChapterDetail, err error) {
	var errMsg string
	defer func() {
		if err != nil {
			global.LOG.Critical(fmt.Sprintf("GetChapterDetail: userId=%d, err:%s， errMsg:%s", user.UserID, err.Error(), errMsg))
		}
	}()

	var authOk bool
	var productAuthOk bool
	var chapterAuthOk bool
	var permissionCheckInfo response.PermissionCheckInfo
	// 判断用户状态是否是正常和永续
	companyProduct, err := company_product.GetByCompany2ProductId(user.CompanyID, 1)
	if err == utils.ErrNoRow {
		err = nil
	}
	if err != nil {
		errMsg = err.Error()
		err = errors.New("查询用户购买产品出错")
		return
	}
	if companyProduct != nil {
		// 无FICC权限的客户不可见
		if companyProduct.CompanyProductID > 0 {
			// 已购或者试用用户可见
			if strings.Contains("永续,正式", companyProduct.Status) || (companyProduct.Status == "试用" && companyProduct.IsSuspend != 1) {
				productAuthOk = true
			}
		}
	}

	typeIds, err := report_chapter_type_cache.GetEffectTypeID()
	if err != nil {
		errMsg = err.Error()
		err = errors.New("章节类型查询出错")
		return
	}
	if len(typeIds) == 0 {
		err = errors.New("无有效的章节类型")
		return
	}
	reportChapter, err := report_chapter.GetItemById(reportChapterId)
	if err != nil {
		errMsg = err.Error()
		err = errors.New("章节查询出错")
		return
	}

	if reportChapter.ReportChapterId == 0 {
		err = errors.New("章节不存在")
		return
	}

	reportInfo, tErr := report.GetByReportId(reportChapter.ReportId)
	if tErr != nil {
		errMsg = tErr.Error()
		err = errors.New("报告查询出错")
		return
	}
	if reportInfo.Id == 0 {
		err = errors.New("报告不存在")
		return
	}
	if reportChapter.Author == `` {
		reportChapter.Author = reportInfo.Author
	}
	//if reportInfo.ClassifyNameFirst == "周报" && reportChapter.IsEdit != 1 {
	//	err = errors.New("章节未编辑")
	//	return
	//}
	//判断权限
	var newTypeIds []int
	var reportChapterIdList []int
	if reportInfo.ClassifyNameFirst == "晨报" {
		authOk, permissionCheckInfo, err = CheckDayReportPermission(user, productAuthOk)
		if err != nil && err != utils.ErrNoRow {
			errMsg = err.Error()
			err = errors.New("权限查询出错")
			return
		}
	} else {
		authOk, permissionCheckInfo, newTypeIds, reportChapterIdList, err = CheckWeekReportPermission(user, reportInfo.Id, productAuthOk)
		if err != nil && err != utils.ErrNoRow {
			errMsg = err.Error()
			err = errors.New("权限查询出错")
			return
		}
		for _, v := range reportChapterIdList {
			if v == reportChapter.ReportChapterId {
				chapterAuthOk = true
			}
		}
		authOk = chapterAuthOk
	}

	var chapterMenu []*response.ReportChapterMenu
	reportChapterItem := new(response.ReportChapterItem)
	reportChapterItem.ReportChapterId = reportChapter.ReportChapterId
	reportChapterItem.ReportId = reportChapter.ReportId
	reportChapterItem.Abstract = reportChapter.Abstract
	reportChapterItem.TypeId = reportChapter.TypeId
	reportChapterItem.Title = reportChapter.Title
	reportChapterItem.ReportId = reportChapter.ReportId
	reportChapterItem.PublishTime = reportChapter.PublishTime
	reportChapterItem.VideoPlaySeconds = reportChapter.VideoPlaySeconds
	reportChapterItem.VideoName = reportChapter.VideoName
	reportChapterItem.ReportLayout = reportChapter.ReportLayout
	reportChapterItem.HeadImg = reportInfo.HeadImg
	reportChapterItem.EndImg = reportInfo.EndImg
	reportChapterItem.CanvasColor = reportInfo.CanvasColor

	// 手工上传的才返回
	if reportInfo.VoiceGenerateType == 1 {
		reportChapterItem.ReportVideoUrl = reportInfo.VideoUrl
	}

	// 版头版尾样式
	{
		if reportInfo.HeadResourceId > 0 {
			headResource, tmpErr := smart_report_resource.GetResourceItemById(reportInfo.HeadResourceId)
			if tmpErr != nil && tmpErr != utils.ErrNoRow {
				err = tmpErr
				return
			}
			if headResource != nil && headResource.ResourceID > 0 {
				reportChapterItem.HeadImg = headResource.ImgURL
				reportChapterItem.HeadStyle = headResource.Style
			}
		}

		if reportInfo.EndResourceId > 0 {
			endResource, tmpErr := smart_report_resource.GetResourceItemById(reportInfo.EndResourceId)
			if tmpErr != nil && tmpErr != utils.ErrNoRow {
				err = tmpErr
				return
			}
			if endResource != nil && endResource.ResourceID > 0 {
				reportChapterItem.EndImg = endResource.ImgURL
				reportChapterItem.EndStyle = endResource.Style
			}
		}
	}

	if reportChapter.VideoUrl != "" && reportChapter.VideoName == "" {
		reportChapterItem.VideoName = reportChapter.Title
	}
	reportChapterItem.VideoSize = reportChapter.VideoSize
	videoImgMap := map[string]string{
		"day":  "report_list_chen.png",
		"week": "report_list_zhou.png",
	}
	reportChapterItem.VideoImg = utils.ALIYUN_YBIMG_HOST + videoImgMap[reportChapter.ReportType]
	reportChapterItem.TypeName = reportChapter.TypeName
	reportChapterItem.Author = reportChapter.Author
	reportChapterItem.Stage = reportChapter.Stage
	reportChapterItem.ClassifyNameFirst = reportChapter.ClassifyNameFirst
	reportChapterItem.ClassifyIdFirst = reportChapter.ClassifyIdFirst
	// 分享背景图
	reportChapterItem.ShareBgImg = utils.DEFAULT_REPORT_SHARE_BG_IMG
	firstClassify, e := classify.GetByClassifyId(reportInfo.ClassifyIdFirst)
	if e != nil {
		err = errors.New("报告一级分类有误")
		return
	}
	if firstClassify.YbShareBgImg != "" {
		reportChapterItem.ShareBgImg = firstClassify.YbShareBgImg
	}
	var likeNum int64
	var likeEnabled int8
	if authOk {
		reportChapterItem.Content = html.UnescapeString(reportChapter.Content)
		reportChapterItem.VideoUrl = reportChapter.VideoUrl
		//底部菜单切换
		if reportInfo.ClassifyNameFirst == "周报" {
			chapterMenu, err = GetMenuChapter(reportInfo.Id, newTypeIds, reportInfo.ClassifyNameFirst, reportInfo.CreateTime)
		} else {
			chapterMenu, err = GetMenuChapter(reportInfo.Id, typeIds, reportInfo.ClassifyNameFirst, reportInfo.CreateTime)
		}
		//查询点赞数
		likeNum, likeEnabled, _ = services.GetReportLikeByReportIdOldReportId(user.UserID, reportInfo.Id, reportChapter.ReportChapterId, 0, 0)
		go AddViewRecord(user, reportInfo.Id, reportInfo.ClassifyNameFirst, reportChapterId)
	} else {
		reportChapterItem.ContentSub = html.UnescapeString(reportChapter.ContentSub)
	}

	// 图表授权token
	{
		isOpenChartExpired, e := base_config.CheckIsOpenChartExpired()
		if e != nil {
			err = errors.New("获取图表是否开启鉴权失败,err：" + e.Error())
			return
		}

		if isOpenChartExpired {
			tokenMap := make(map[string]string)
			reportChapterItem.Content = HandleReportContent(reportChapterItem.Content, "add", tokenMap)
			reportChapterItem.ContentSub = HandleReportContent(reportChapterItem.ContentSub, "add", tokenMap)
		}
	}

	go AddUserAccessRecord(user, reportInfo.Id, reportInfo.ClassifyNameFirst, reportChapterId, authOk)
	reportChapterDetail = new(response.ReportChapterDetail)
	reportChapterDetail.ReportChapterItem = reportChapterItem
	reportChapterDetail.PermissionCheck = &permissionCheckInfo
	reportChapterDetail.ReportChapterMenuList = chapterMenu
	reportChapterDetail.AuthOk = authOk
	reportChapterDetail.LikeNum = likeNum
	reportChapterDetail.LikeEnabled = likeEnabled

	// 收藏
	collectionId, e := collection.GetUserCollectByItem(int(user.UserID), collection.CollectionTypeReport, reportChapterItem.ReportId, reportChapterId)
	if e != nil {
		err = e
		return
	}
	reportChapterDetail.CollectionId = collectionId
	return
}

func GetMenuChapter(reportId int, typeIds []int, classifyNameFirst string, reportCreateTime time.Time) (reportTypeList response.ReportChapterMenuList, err error) {
	//查询有效的章节
	typeList, tErr := report_chapter_type.GetEffectTypes()
	if tErr != nil {
		return
	}
	if len(typeList) == 0 {
		err = errors.New("无有效的章节")
		return
	}

	typeMap := make(map[uint64]*report_chapter_type.ReportChapterType)
	for _, v := range typeList {
		typeMap[v.ReportChapterTypeId] = v
	}

	//获取所有当前研报的章节
	chapterList, tErr := report_chapter.GetListByReportIdTypeIds(reportId, typeIds, classifyNameFirst)
	if tErr != nil && tErr != utils.ErrNoRow {
		return
	}
	if len(chapterList) > 0 {
		for _, item := range chapterList {
			if typeItem, ok := typeMap[uint64(item.TypeId)]; ok {
				if reportCreateTime.Before(typeItem.PauseStartTime) || reportCreateTime.After(typeItem.PauseEndTime) {
					temp := new(response.ReportChapterMenu)
					temp.ReportChapterId = item.ReportChapterId
					temp.ReportId = item.ReportId
					temp.ReportChapterTypeName = typeItem.ReportChapterTypeName
					temp.ReportChapterTypeThumb = typeItem.YbBottomIcon
					temp.Sort = typeItem.Sort
					temp.PcSelectedThumb = typeItem.PcSelectedImage
					temp.PcUnselectedThumb = typeItem.PcUnselectedImage
					reportTypeList = append(reportTypeList, temp)
				}
			}
		}
	}
	if len(reportTypeList) > 0 {
		sort.Sort(reportTypeList)
	}
	return
}

// CheckWeekReportPermission
// @Description: 验证周报的权限（并获取拥有权限的章节id列表）
// @author: Roc
// @datetime 2024-06-24 11:06:52
// @param userInfo user.UserInfo
// @param reportId int
// @param productAuthOk bool
// @return authOk bool
// @return permissionCheckInfo response.PermissionCheckInfo
// @return validTypeIds []int 分类关联的章节类型ID列表
// @return reportChapterIdList []int 并获取拥有权限的章节id列表
// @return err error
func CheckWeekReportPermission(userInfo user.UserInfo, reportId int, productAuthOk bool) (authOk bool, permissionCheckInfo response.PermissionCheckInfo, validTypeIds, reportChapterIdList []int, err error) {
	var permissionIds []int
	var validPermissionIds []int //最后允许显示的章节

	// 当前报告的品种与章节列表的map
	permissionChapterList := make(map[int][]int)
	permissionIdMap := make(map[int]bool)
	typeIdMap := make(map[int]bool)
	if productAuthOk {
		reportChapterMappingList, tmpErr := report_chapter_permission_mapping.GetReportChapterPermissionMappingItemListByReportId(reportId)
		if tmpErr != nil && errors.Is(tmpErr, utils.ErrNoRow) {
			return
		}
		for _, v := range reportChapterMappingList {
			if _, ok := permissionIdMap[v.ChartPermissionID]; !ok {
				permissionIdMap[v.ChartPermissionID] = true
				permissionIds = append(permissionIds, v.ChartPermissionID)
			}
			if _, ok := typeIdMap[v.TypeId]; !ok {
				typeIdMap[v.TypeId] = true
				validTypeIds = append(validTypeIds, v.TypeId)
			}

			tmpList, ok := permissionChapterList[v.ChartPermissionID]
			if !ok {
				tmpList = make([]int, 0)
			}
			permissionChapterList[v.ChartPermissionID] = append(tmpList, v.ReportChapterID)
		}

	}

	authOk, permissionCheckInfo, validPermissionIds, err = company.GetCheckPermission(userInfo.CompanyID, int(userInfo.UserID), permissionIds)
	if err != nil {
		return
	}
	//返回可用的章节列表
	if len(validPermissionIds) > 0 {
		reportChapterIdMap := make(map[int]bool)
		for _, v := range validPermissionIds {

			chapterIdList, ok := permissionChapterList[v]
			if !ok {
				continue
			}
			for _, chapterId := range chapterIdList {
				if _, ok := reportChapterIdMap[chapterId]; !ok {
					reportChapterIdMap[chapterId] = true
					reportChapterIdList = append(reportChapterIdList, chapterId)
				}
			}
		}
	}

	return
}

// CheckDayReportPermission 验证晨报的权限
func CheckDayReportPermission(userInfo user.UserInfo, productAuthOk bool) (authOk bool, permissionCheckInfo response.PermissionCheckInfo, err error) {
	if productAuthOk {
		authOk = true
		return
	}
	authOk, permissionCheckInfo, _, err = company.GetCheckPermission(userInfo.CompanyID, int(userInfo.UserID), []int{})

	return
}

// GetReportChapterVideoList 根据报告获取章节的音频列表
func GetReportChapterVideoList(permissionIds []int, classifyName string, list []*report.Report, userId uint64) (videoMap map[int][]*response.VideoListItem, weekAuthMap map[int]bool, errMsg string, err error) {
	videoMap = make(map[int][]*response.VideoListItem)
	weekAuthMap = make(map[int]bool)
	var reportIds []int
	reportMap := make(map[int]*report.Report)
	for _, reportInfo := range list {
		reportMap[reportInfo.Id] = reportInfo
		reportIds = append(reportIds, reportInfo.Id)
	}
	// 查询有效的章节
	//查询有效的章节
	typeList, tErr := report_chapter_type.GetEffectTypes()
	if tErr != nil {
		errMsg = tErr.Error()
		err = errors.New("章节类型查询出错")
		return
	}
	if len(typeList) == 0 {
		err = errors.New("无有效的章节")
		return
	}

	typeMap := make(map[int]*report_chapter_type.ReportChapterType)
	var typeIds []int
	typeIds = append(typeIds, 0)
	for _, v := range typeList {
		typeMap[int(v.ReportChapterTypeId)] = v
		typeIds = append(typeIds, int(v.ReportChapterTypeId))
	}

	var chapters []*report_chapter.ReportChapter
	setMap := make(map[int]int)
	if classifyName != "晨报" {
		// 查询用户有权限的章节列表
		chapters, err = report_chapter.GetByPermissionIdListAndReportList(permissionIds, reportIds)
		//获取音频设置章节
		setList, _ := user_report_chapter_set.GetUserReportChapterSet(userId)
		for _, v := range setList {
			if v.IsClose == 0 {
				setMap[v.TypeId] = v.TypeId
			}
		}
	} else {
		// 查询章节列表
		chapters, err = report_chapter.GetByTypeIdsAndReportIds(typeIds, reportIds, classifyName)
	}
	if err != nil {
		errMsg = err.Error()
		err = errors.New("查询章节出错")
		return
	}
	for _, v := range chapters {
		if classifyName != "晨报" {
			weekAuthMap[v.ReportId] = true
		}

		// 各种过滤条件
		{
			if v.VideoUrl == `` {
				continue
			}
			// 报告校验
			reportDetail, ok := reportMap[v.ReportId]
			if !ok { // 不是当前报告，那么过滤不处理
				continue
			}
			reportDate := reportDetail.CreateTime

			// 如果是系统配置的章节类型，那么需要额外校验时间
			if v.TypeId > 0 {
				// 如果不存在该类型的章节类型，那么就过滤，直接下一个循环
				temp, ok := typeMap[v.TypeId]
				if !ok {
					continue
				}

				// 如果晚于开始日期同时早于结束日期；或者等于开始日期；或者等于结束日期，那么就过滤，直接下一个循环
				if (reportDate.After(temp.PauseStartTime) && reportDate.Before(temp.PauseEndTime)) || reportDate.Equal(temp.PauseStartTime) || reportDate.Equal(temp.PauseEndTime) {
					continue
				}
			}

			if classifyName != "晨报" {
				if _, sok := setMap[v.TypeId]; !sok {
					continue
				}
			}
		}

		videoItem := new(response.VideoListItem)
		videoItem.VideoPlaySeconds = v.VideoPlaySeconds
		videoItem.VideoName = v.VideoName
		if v.VideoName == "" {
			videoItem.VideoName = v.Title
		}
		videoItem.VideoUrl = v.VideoUrl
		videoItem.Sort = v.Sort
		videoMap[v.ReportId] = append(videoMap[v.ReportId], videoItem)
	}

	return
}

// GetChapterListByReportChapterIdList
// @Description: 根据报告获取章节列表
// @author: Roc
// @datetime 2024-06-24 11:23:36
// @param classifyNameFirst string
// @param reportId int
// @param reportChapterIdList []int
// @param reportCreateTime time.Time
// @return reportTypeList response.ReportChapterList
// @return err error
func GetChapterListByReportChapterIdList(classifyNameFirst string, reportId int, reportChapterIdList []int) (reportTypeList response.ReportChapterList, err error) {
	var errMsg string
	defer func() {
		if err != nil {
			global.LOG.Critical(fmt.Sprintf("GetChapterListByReport: err:%s， errMsg:%s", err.Error(), errMsg))
		}
	}()
	//查询有效的章节
	typeList, tErr := report_chapter_type.GetEffectTypes()
	if tErr != nil {
		errMsg = tErr.Error()
		err = errors.New("章节类型查询出错")
		return
	}
	if len(typeList) == 0 {
		err = errors.New("无有效的章节")
		return
	}

	typeMap := make(map[uint64]*report_chapter_type.ReportChapterType)
	for _, v := range typeList {
		typeMap[v.ReportChapterTypeId] = v
	}

	var chapterList []*report_chapter.ReportChapter
	if len(reportChapterIdList) > 0 {
		//获取所有当前研报有权限的章节
		chapterList, tErr = report_chapter.GetListByChapterIds(reportChapterIdList)
	} else {
		// 获取所有报告章节
		chapterList, tErr = report_chapter.GetListByReportId(reportId, classifyNameFirst)
	}
	if tErr != nil && tErr != utils.ErrNoRow {
		errMsg = err.Error()
		err = errors.New("章节查询出错")
		return
	}
	if len(chapterList) == 0 {
		err = errors.New("无有效章节")
		return
	}

	for _, item := range chapterList {
		typeItem, ok1 := typeMap[uint64(item.TypeId)]
		// 如果是配置的章节，那么就需要判断是否禁用，如果禁用，则不展示
		if item.TypeId > 0 && !ok1 {
			continue
		}

		temp := new(response.ReportChapterListItem)
		temp.ReportChapterId = item.ReportChapterId
		temp.TypeId = item.TypeId
		temp.TypeName = item.TypeName
		temp.Title = item.Title
		temp.Trend = item.Trend
		temp.ReportId = item.ReportId
		temp.Sort = item.Sort
		temp.PublishTime = item.PublishTime
		temp.VideoUrl = item.VideoUrl
		temp.VideoName = item.VideoName
		temp.VideoPlaySeconds = item.VideoPlaySeconds
		temp.VideoSize = item.VideoSize
		temp.Content = item.Content

		// 系统配置的参数，只有配置的章节类型，才能赋值
		if typeItem != nil {
			temp.ReportChapterTypeKey = typeItem.ReportChapterTypeKey
			temp.ReportChapterTypeName = typeItem.ReportChapterTypeName
			temp.ReportChapterTypeThumb = typeItem.YbIconUrl
		}

		reportTypeList = append(reportTypeList, temp)
	}
	if len(reportTypeList) > 0 {
		sort.Sort(reportTypeList)
	}
	return
}
