123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290 |
- package report
- import (
- "fmt"
- "hongze/hongze_yb/models/response"
- "hongze/hongze_yb/models/response/purchase"
- "hongze/hongze_yb/models/tables/chart_permission_chapter_mapping"
- "hongze/hongze_yb/models/tables/rddp/report"
- "hongze/hongze_yb/models/tables/rddp/report_chapter"
- "hongze/hongze_yb/models/tables/report_chapter_type"
- "hongze/hongze_yb/services/company"
- "hongze/hongze_yb/services/user"
- "hongze/hongze_yb/utils"
- "log"
- )
- func GetLatestClassReport(permissionIds []int, userId uint64) (purchaseList []*purchase.PurchaseListItem, err error) {
- //获取所有和权限绑定的报告
- reportIds, err := GetReportIdsByPermissionIds(permissionIds)
- if err != nil {
- return
- }
- typeIds, tErr := report_chapter_type.GetEffectTypeID()
- if tErr != nil {
- err = tErr
- return
- }
- //获取最新的晨报
- dayReport, err := report.GetLatestDay()
- if err != nil {
- if err == utils.ErrNoRow {
- dayReport = nil
- }else{
- return
- }
- }
- //获取最新的有权限的周报
- weekReport, err := GetLatestWeek(permissionIds, typeIds)
- if err != nil {
- return
- }
- var reports []*report.Report
- if len(reportIds) > 0 {
- reports, err = report.GetLatestClassReportsByIDs(reportIds)
- if err != nil {
- return
- }
- }
- if dayReport != nil {
- reports = append(reports, dayReport)
- }
- if weekReport != nil {
- reports = append(reports, weekReport)
- }
- //获取未读数
- unReadItem, tErr := GetUnRead(reportIds, userId)
- if tErr != nil {
- err = tErr
- return
- }
- if len(reports) > 0 {
- for _, v := range reports {
- temp := new(purchase.PurchaseListItem)
- temp.ReportId = v.Id
- temp.ClassifyIdFirst = v.ClassifyIdFirst
- temp.ClassifyNameFirst = v.ClassifyNameFirst
- temp.Stage = v.Stage
- temp.Title = v.Title
- temp.ClassifyIdSecond = v.ClassifyIdSecond
- temp.ClassifyNameSecond = v.ClassifyNameSecond
- if temp.ClassifyNameFirst == "晨报" || temp.ClassifyNameFirst == "周报" { //晨报或者周报,查询最新的章节信息
- temp.Content = fmt.Sprintf("【第%d期|FICC】%s", temp.Stage, temp.Title)
- }else{
- if temp.ClassifyIdSecond > 0 { //包含二级分类
- temp.Content = fmt.Sprintf("【第%d期|FICC| %s】%s", temp.Stage, temp.ClassifyNameSecond, temp.ClassifyNameFirst)
- } else { //无二级分类
- temp.Content = fmt.Sprintf("【第%d期|FICC】%s", temp.Stage, temp.ClassifyNameFirst)
- }
- }
- temp.Time = v.PublishTime
- temp.Unread = unReadItem[temp.ClassifyNameFirst]
- purchaseList = append(purchaseList, temp)
- }
- }
- return
- }
- // GetReportIdsByPermissionIds 获取所有和权限绑定的报告
- func GetReportIdsByPermissionIds(permissionIds []int) (reportIds []int, err error) {
- reportIds, err = chart_permission_chapter_mapping.GetReportIdsByPermisssionIds(permissionIds, "rddp")
- return
- }
- // GetListByClassName 根据分类类型,分页获取报告
- func GetListByClassName(reportIds []int, className string, offset, limit int ) (list []*report.Report, err error) {
- list, err = report.GetListByIDsAndClassID(reportIds, className, offset, limit)
- return
- }
- // GetPurchaseDetail 已购详情页面
- func GetPurchaseDetail(permissionIds []int, userId uint64, classifyNameFirst string, offset, pageLimit int) (list []*purchase.Detail, err error) {
- var reports []*report.Report
- var reportIds []int
- if classifyNameFirst == "晨报" {
- //分类获取
- reports, err = report.GetListByClass(classifyNameFirst, offset, pageLimit)
- if err != nil {
- return
- }
- for _, v := range reports {
- reportIds = append(reportIds, v.Id)
- }
- }else {
- if classifyNameFirst == "周报" {
- ids, tErr := GetReportChapterIdsByPermissionIds(permissionIds)
- if tErr != nil {
- return
- }
- typeIds, tErr := report_chapter_type.GetEffectTypeID()
- if tErr != nil {
- err = tErr
- return
- }
- var newTypeIds []int
- for _, v1 := range typeIds {
- for _, v2 := range ids {
- if v1 == v2 {
- newTypeIds = append(newTypeIds, v2)
- }
- }
- }
- reportIds, err = report_chapter.GetReportIdsByIdsAndClass(newTypeIds, classifyNameFirst)
- } else {
- reportIds, err = GetReportIdsByPermissionIds(permissionIds)
- if err != nil {
- return
- }
- }
- if len(reportIds) > 0 {
- //分类获取
- reports, err = GetListByClassName(reportIds, classifyNameFirst, offset, pageLimit)
- if err != nil {
- return
- }
- }
- }
- if len(reports) > 0 {
- var viewReportIds []int
- for _, v := range reports {
- viewReportIds = append(viewReportIds, v.Id)
- temp := new(purchase.Detail)
- temp.ReportId = v.Id
- temp.ClassifyIdFirst = v.ClassifyIdFirst
- temp.ClassifyNameFirst = v.ClassifyNameFirst
- temp.Title = v.Title
- temp.ClassifyIdSecond = v.ClassifyIdSecond
- temp.ClassifyNameSecond = v.ClassifyNameSecond
- if temp.ClassifyNameFirst == "晨报" || temp.ClassifyNameFirst == "周报" { //晨报或者周报,查询最新的章节信息
- temp.Content = fmt.Sprintf("【第%d期|FICC】%s", temp.Stage, temp.Title)
- temp.TopName = temp.Title
- }else{
- if temp.ClassifyIdSecond > 0 { //包含二级分类
- temp.Content = fmt.Sprintf("【第%d期|FICC| %s】%s", temp.Stage, temp.ClassifyNameSecond, temp.ClassifyNameFirst)
- temp.TopName = temp.ClassifyNameSecond
- } else { //无二级分类
- temp.Content = fmt.Sprintf("【第%d期|FICC】%s", temp.Stage, temp.ClassifyNameFirst)
- temp.TopName = temp.ClassifyNameFirst
- }
- }
- temp.Time = v.PublishTime
- list = append(list, temp)
- }
- }
- num, tErr := BatchInsertReportView(reportIds, userId, classifyNameFirst)
- log.Printf("新增报告浏览记录:%d", num)
- if tErr != nil {
- err = tErr
- return
- }
- return
- }
- // 获取报告详情
- func GetReportDetail(userinfo user.UserInfo, reportId int) (reportDetail response.ReportDetail, err error) {
- reportInfo, err := report.GetByReportId(reportId)
- if err != nil {
- return
- }
- if reportInfo.Id == 0 {
- return
- }
- //判断权限
- permissionCheckInfo, err := CheckReportPermission(userinfo, reportId)
- if err != nil {
- return
- }
- reportItem := new(response.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 = reportInfo.ContentSub
- reportItem.Frequency = reportInfo.Frequency
- reportItem.VideoName = reportInfo.VideoName
- reportItem.VideoPlaySeconds = reportInfo.VideoPlaySeconds
- reportItem.Author = reportInfo.Author
- var reportTypeList []*response.ReportTypeListItem
- if reportInfo.ClassifyNameFirst == "晨报" || reportInfo.ClassifyNameFirst == "周报" {
- //查询有效的章节
- typeList, tErr := report_chapter_type.GetEffectTypes()
- if tErr != nil {
- err = tErr
- return
- }
- typeMap := make(map[uint64]*report_chapter_type.ReportChapterType)
- for _, v := range typeList {
- typeMap[v.ReportChapterTypeId] = v
- }
- //获取所有当前研报的章节
- chapterList, tErr := report_chapter.GetListByReportId(reportInfo.Id)
- if tErr != nil {
- err = tErr
- return
- }
- for _, item := range chapterList {
- // TODO 只展示有权限的章节
- if typeItem, ok := typeMap[uint64(item.TypeId)]; ok {
- temp := new(response.ReportTypeListItem)
- temp.TypeId = item.TypeId
- temp.Title = item.Title
- temp.ReportId = item.ReportId
- temp.Sort = item.Sort
- temp.PublishTime = item.PublishTime
- temp.BannerUrl = typeItem.BannerUrl
- temp.PauseEndTime = typeItem.PauseEndTime
- temp.PauseStartTime = typeItem.PauseStartTime
- temp.EditImgUrl = typeItem.EditImgUrl
- temp.ReportChapterTypeKey = typeItem.ReportChapterTypeKey
- temp.ReportChapterTypeName = typeItem.ReportChapterTypeName
- temp.ReportChapterTypeThumb = typeItem.ReportChapterTypeThumb
- reportTypeList = append(reportTypeList, temp)
- }
- }
- }
- //如果有权限则展示content
- if permissionCheckInfo.AuthOk == 1 {
- AddViewRecord(userinfo, reportInfo.Id)
- reportItem.Content = reportInfo.Content
- reportItem.VideoUrl = reportInfo.VideoUrl
- }
- reportDetail.ReportInfo = reportItem
- reportDetail.ReportTypeList = reportTypeList
- reportDetail.PermissionCheck = &permissionCheckInfo
- return
- }
- // CheckReportPermission 验证用户的活动参与权限
- func CheckReportPermission(userInfo user.UserInfo, reportId int) (permissionCheckInfo company.PermissionCheckInfo, err error) {
- permissionIds, err := chart_permission_chapter_mapping.GetPermissionIdsByReportId(reportId)
- if err != nil {
- return
- }
- ok, permissionCheckInfo, err := company.CheckPermissionByPermissionIdList2Ficc(userInfo.CompanyID, int(userInfo.UserID), permissionIds)
- if err != nil {
- return
- }
- if ok {
- permissionCheckInfo.AuthOk = 1
- }
- return
- }
|