|
@@ -0,0 +1,379 @@
|
|
|
+package services
|
|
|
+
|
|
|
+//FICC研报
|
|
|
+import (
|
|
|
+ "errors"
|
|
|
+ "fmt"
|
|
|
+ "hongze/hongze_cygx/models"
|
|
|
+ "hongze/hongze_cygx/models/ficc_report"
|
|
|
+ "hongze/hongze_cygx/utils"
|
|
|
+ "html"
|
|
|
+)
|
|
|
+
|
|
|
+// GetMinClassify
|
|
|
+// @Description: 获取最小分类ID
|
|
|
+// @author: Roc
|
|
|
+// @datetime 2024-06-20 09:23:19
|
|
|
+// @param reportInfo *models.Report
|
|
|
+// @return minClassifyId int
|
|
|
+// @return minClassifyName string
|
|
|
+// @return err error
|
|
|
+func GetMinClassify(reportInfo *ficc_report.Report) (minClassifyId int, minClassifyName string, err error) {
|
|
|
+ defer func() {
|
|
|
+ if err != nil {
|
|
|
+ go utils.SendAlarmMsg(fmt.Sprint("获取最小分类ID失败,报告ID:%d,Err:%s", reportInfo.Id, err.Error()), 2)
|
|
|
+ }
|
|
|
+
|
|
|
+ }()
|
|
|
+ minClassifyId = reportInfo.ClassifyIdThird
|
|
|
+ minClassifyName = reportInfo.ClassifyNameThird
|
|
|
+ if minClassifyId <= 0 {
|
|
|
+ minClassifyId = reportInfo.ClassifyIdSecond
|
|
|
+ minClassifyName = reportInfo.ClassifyNameSecond
|
|
|
+ }
|
|
|
+ if minClassifyId <= 0 {
|
|
|
+ minClassifyId = reportInfo.ClassifyIdFirst
|
|
|
+ minClassifyName = reportInfo.ClassifyNameFirst
|
|
|
+ }
|
|
|
+ if minClassifyId <= 0 {
|
|
|
+ err = errors.New("分类异常")
|
|
|
+ }
|
|
|
+
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+// 获取报告详情
|
|
|
+func GetReportDetail(userinfo *models.WxUserItem, reportId int) (reportDetail ficc_report.ReportDetail, err error) {
|
|
|
+ //var errMsg string
|
|
|
+ defer func() {
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println(err)
|
|
|
+ go utils.SendAlarmMsg(fmt.Sprint("获取研报详情失败 GetFiccYbDetailByApi ,err:", err.Error(), "ReportId:", reportId), 2)
|
|
|
+ }
|
|
|
+ }()
|
|
|
+
|
|
|
+ reportInfo, err := ficc_report.GetByReportId(reportId)
|
|
|
+ if err != nil {
|
|
|
+ //errMsg = err.Error()
|
|
|
+ err = errors.New("报告查询出错")
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if reportInfo.Id == 0 {
|
|
|
+ err = errors.New("报告不存在")
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if reportInfo.State != 2 && reportInfo.State != 6 {
|
|
|
+ err = errors.New("报告未发布")
|
|
|
+ return
|
|
|
+ }
|
|
|
+ // 获取最小分类
|
|
|
+ minClassifyId, _, err := GetMinClassify(reportInfo)
|
|
|
+
|
|
|
+ // 判断报告是否属于专栏报告
|
|
|
+ firstClassify, e := ficc_report.GetByClassifyId(reportInfo.ClassifyIdFirst)
|
|
|
+ if e != nil {
|
|
|
+ err = errors.New("报告一级分类有误")
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ // 最小分类
|
|
|
+ var minClassify *ficc_report.Classify
|
|
|
+ if reportInfo.ClassifyIdFirst == minClassifyId {
|
|
|
+ minClassify = firstClassify
|
|
|
+ } else {
|
|
|
+ minClassify, e = ficc_report.GetByClassifyId(minClassifyId)
|
|
|
+ if e != nil {
|
|
|
+ err = errors.New("报告最小层级分类有误")
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //判断权限
|
|
|
+
|
|
|
+ var authOk bool
|
|
|
+ var reportChapterIdList []int
|
|
|
+ if reportInfo.HasChapter == 1 {
|
|
|
+ if reportInfo.ClassifyNameFirst == "晨报" {
|
|
|
+ //authOk, permissionCheckInfo, err = CheckDayReportPermission(userinfo, productAuthOk)
|
|
|
+ } else {
|
|
|
+ authOk, _, _, reportChapterIdList, err = CheckWeekReportPermission(userinfo, reportId, true)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ authOk = true
|
|
|
+ fmt.Println("reportChapterIdList", reportChapterIdList)
|
|
|
+
|
|
|
+ reportItem := new(ficc_report.ReportItem)
|
|
|
+ reportItem.ReportId = reportInfo.Id
|
|
|
+ reportItem.Title = reportInfo.Title
|
|
|
+ reportItem.PublishTime = reportInfo.PublishTime
|
|
|
+ reportItem.ClassifyNameFirst = reportInfo.ClassifyNameFirst
|
|
|
+ reportItem.ClassifyNameSecond = reportInfo.ClassifyNameSecond
|
|
|
+ reportItem.Stage = reportInfo.Stage
|
|
|
+ reportItem.Abstract = reportInfo.Abstract
|
|
|
+ reportItem.ContentSub = html.UnescapeString(reportInfo.ContentSub)
|
|
|
+ reportItem.Frequency = reportInfo.Frequency
|
|
|
+ reportItem.VideoName = reportInfo.VideoName
|
|
|
+ reportItem.HasChapter = reportInfo.HasChapter
|
|
|
+ reportItem.ReportLayout = reportInfo.ReportLayout
|
|
|
+ reportItem.HeadImg = reportInfo.HeadImg
|
|
|
+ reportItem.EndImg = reportInfo.EndImg
|
|
|
+ reportItem.CanvasColor = reportInfo.CanvasColor
|
|
|
+
|
|
|
+ //版头版尾样式
|
|
|
+ {
|
|
|
+ if reportInfo.HeadResourceId > 0 {
|
|
|
+ headResource, tmpErr := ficc_report.GetResourceItemById(reportInfo.HeadResourceId)
|
|
|
+ if tmpErr != nil {
|
|
|
+ err = tmpErr
|
|
|
+ return
|
|
|
+ }
|
|
|
+ reportItem.HeadImg = headResource.ImgURL
|
|
|
+ reportItem.HeadStyle = headResource.Style
|
|
|
+ }
|
|
|
+
|
|
|
+ if reportInfo.EndResourceId > 0 {
|
|
|
+ endResource, tmpErr := ficc_report.GetResourceItemById(reportInfo.EndResourceId)
|
|
|
+ if tmpErr != nil {
|
|
|
+ err = tmpErr
|
|
|
+ return
|
|
|
+ }
|
|
|
+ reportItem.EndImg = endResource.ImgURL
|
|
|
+ reportItem.EndStyle = endResource.Style
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if reportInfo.VideoName == "" && reportInfo.VideoUrl != "" {
|
|
|
+ reportItem.VideoName = reportInfo.Title
|
|
|
+ }
|
|
|
+ reportItem.VideoSize = reportInfo.VideoSize
|
|
|
+ reportItem.VideoPlaySeconds = reportInfo.VideoPlaySeconds
|
|
|
+ reportItem.Author = reportInfo.Author
|
|
|
+ // 分享背景图取二级分类配图, 二级没有配图时使用一级配图, 一级也没有使用默认图
|
|
|
+ reportItem.ShareBgImg = utils.DEFAULT_REPORT_SHARE_BG_IMG
|
|
|
+ secondClassify, e := ficc_report.GetByClassifyId(reportInfo.ClassifyIdSecond)
|
|
|
+ if e != nil {
|
|
|
+ err = errors.New("报告二级分类有误")
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if secondClassify.YbShareBgImg != "" {
|
|
|
+ reportItem.ShareBgImg = secondClassify.YbShareBgImg
|
|
|
+ } else {
|
|
|
+ if firstClassify.YbShareBgImg != "" {
|
|
|
+ reportItem.ShareBgImg = firstClassify.YbShareBgImg
|
|
|
+ }
|
|
|
+ }
|
|
|
+ var reportTypeList []*ficc_report.ReportChapterListItem
|
|
|
+
|
|
|
+ if reportInfo.HasChapter == 1 {
|
|
|
+ //(晨报和周报的banner图)
|
|
|
+ if reportInfo.ClassifyNameFirst == "晨报" {
|
|
|
+ reportItem.BannerUrl = utils.ALIYUN_YBIMG_HOST + "report_banner_day.jpg"
|
|
|
+ } else {
|
|
|
+ reportItem.BannerUrl = utils.ALIYUN_YBIMG_HOST + "report_banner_week.jpg"
|
|
|
+ }
|
|
|
+
|
|
|
+ // 如果还没有配置banner图,则取晨报的
|
|
|
+ if reportItem.BannerUrl == `` {
|
|
|
+ reportItem.BannerUrl = utils.ALIYUN_YBIMG_HOST + "report_banner_day.jpg"
|
|
|
+ }
|
|
|
+
|
|
|
+ if authOk {
|
|
|
+ reportTypeList, err = GetChapterListByReportChapterIdList(reportInfo.ClassifyNameFirst, reportInfo.Id, reportChapterIdList)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // 音频播放条图片用分类图片
|
|
|
+ //reportItem.VideoImg = utils.HZ_DEFAULT_AVATAR
|
|
|
+ //permissionIds, tmpErr := chart_permission_search_key_word_mapping.GetChartPermissionIdsByKeyWord(reportInfo.ClassifyIdSecond)
|
|
|
+ //if tmpErr != nil {
|
|
|
+ // errMsg = tmpErr.Error()
|
|
|
+ // err = errors.New("查询报告权限失败")
|
|
|
+ // return
|
|
|
+ //}
|
|
|
+ //if len(permissionIds) > 0 {
|
|
|
+ // chartPermission, tmpErr := chart_permission.GetListByIds(permissionIds)
|
|
|
+ // if tmpErr != nil {
|
|
|
+ // errMsg = tmpErr.Error()
|
|
|
+ // err = errors.New("查询品种信息失败")
|
|
|
+ // return
|
|
|
+ // }
|
|
|
+ // lenChart := len(chartPermission)
|
|
|
+ // for i := 0; i < lenChart; i++ {
|
|
|
+ // if chartPermission[i].YbImgUrl != "" {
|
|
|
+ // reportItem.VideoImg = utils.ALIYUN_YBIMG_HOST + chartPermission[i].YbImgUrl
|
|
|
+ // break
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ //}
|
|
|
+ }
|
|
|
+ //如果有权限则展示content
|
|
|
+ if authOk {
|
|
|
+ reportItem.Content = html.UnescapeString(reportInfo.Content)
|
|
|
+ reportItem.VideoUrl = reportInfo.VideoUrl
|
|
|
+ }
|
|
|
+
|
|
|
+ reportDetail.ReportInfo = reportItem
|
|
|
+ reportDetail.ReportChapterList = reportTypeList
|
|
|
+ //reportDetail.PermissionCheck = &permissionCheckInfo
|
|
|
+ reportDetail.AuthOk = authOk
|
|
|
+ //reportDetail.LikeNum = likeNum
|
|
|
+ //reportDetail.LikeEnabled = likeEnabled
|
|
|
+ reportDetail.ReportShowType = int(firstClassify.ShowType)
|
|
|
+ reportDetail.ReportDetailShowType = int(minClassify.ReportDetailShowType)
|
|
|
+
|
|
|
+ // 如果分类配置是列表展示,那么就移除content内容
|
|
|
+ if minClassify.ReportDetailShowType == 2 {
|
|
|
+ for _, v := range reportTypeList {
|
|
|
+ v.Content = ``
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ for _, v := range reportTypeList {
|
|
|
+ v.Content = html.UnescapeString(v.Content)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ 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 *models.WxUserItem, reportId int, productAuthOk bool) (authOk bool, permissionCheckInfo ficc_report.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)
|
|
|
+ reportChapterIdMap := make(map[int]bool)
|
|
|
+ if productAuthOk {
|
|
|
+ reportChapterMappingList, e := ficc_report.GetReportChapterPermissionMappingItemListByReportId(reportId)
|
|
|
+ if e != nil && e.Error() != utils.ErrNoRow() {
|
|
|
+ err = errors.New(e.Error())
|
|
|
+ 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)
|
|
|
+ if _, ok := reportChapterIdMap[v.ReportChapterId]; !ok {
|
|
|
+ reportChapterIdMap[v.ReportChapterId] = true
|
|
|
+ reportChapterIdList = append(reportChapterIdList, v.ReportChapterId) //走权益的校验权限,到这里的权限都可以用
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ 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 ficc_report.ReportChapterList, err error) {
|
|
|
+ var errMsg string
|
|
|
+ defer func() {
|
|
|
+ if err != nil {
|
|
|
+ go utils.SendAlarmMsg(fmt.Sprintf("GetChapterListByReport: err:%s, errMsg:%s", err.Error(), errMsg), 2)
|
|
|
+ }
|
|
|
+ }()
|
|
|
+ //查询有效的章节
|
|
|
+ typeList, e := ficc_report.GetEffectTypes()
|
|
|
+ if e != nil {
|
|
|
+
|
|
|
+ err = errors.New("章节类型查询出错" + e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if len(typeList) == 0 {
|
|
|
+ err = errors.New("无有效的章节")
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ typeMap := make(map[uint64]*ficc_report.ReportChapterType)
|
|
|
+ for _, v := range typeList {
|
|
|
+ typeMap[v.ReportChapterTypeId] = v
|
|
|
+ }
|
|
|
+
|
|
|
+ var chapterList []*ficc_report.ReportChapter
|
|
|
+ if len(reportChapterIdList) > 0 {
|
|
|
+ //获取所有当前研报有权限的章节
|
|
|
+ chapterList, e = ficc_report.GetListByChapterIds(reportChapterIdList)
|
|
|
+ } else {
|
|
|
+ // 获取所有报告章节
|
|
|
+ chapterList, e = ficc_report.GetListByReportId(reportId, classifyNameFirst)
|
|
|
+ }
|
|
|
+ if e != nil && e.Error() != utils.ErrNoRow() {
|
|
|
+ err = errors.New("章节查询出错" + e.Error())
|
|
|
+ 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(ficc_report.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
|
|
|
+}
|