123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669 |
- 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/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 {
- err = tmpErr
- return
- }
- reportChapterItem.HeadImg = headResource.ImgURL
- reportChapterItem.HeadStyle = headResource.Style
- }
- if reportInfo.EndResourceId > 0 {
- endResource, tmpErr := smart_report_resource.GetResourceItemById(reportInfo.EndResourceId)
- if tmpErr != nil {
- err = tmpErr
- return
- }
- 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)
- }
- 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
- }
|