|
@@ -1,25 +1,51 @@
|
|
|
package report
|
|
|
|
|
|
import (
|
|
|
+ "errors"
|
|
|
+ "fmt"
|
|
|
+ "hongze/hongze_yb/global"
|
|
|
+ "hongze/hongze_yb/models/response"
|
|
|
"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"
|
|
|
)
|
|
|
|
|
|
-// GetReportChapterIdsByPermissionIds 获取所有和权限绑定的报告章节ID
|
|
|
-func GetReportChapterIdsByPermissionIds(permissionIds []int) (ids []int, err error) {
|
|
|
+// 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) {
|
|
|
- ids, err := GetReportChapterIdsByPermissionIds(permissionIds)
|
|
|
+ newTypeIds, err := GetWeekTypeIdsByPermissionIds(permissionIds, typeIds)
|
|
|
+ chapter, err := report_chapter.GetLatestChapterByTypeIdsAndClass(newTypeIds,"week")
|
|
|
if err != nil {
|
|
|
return
|
|
|
}
|
|
|
- var newTypeIds []int
|
|
|
+ reportInfo, err = report.GetByReportId(chapter.ReportId)
|
|
|
+ if err == utils.ErrNoRow {
|
|
|
+ return nil, nil
|
|
|
+ }
|
|
|
+ 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.GetEffectTypeID()
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
for _, v1 := range typeIds {
|
|
|
for _, v2 := range ids {
|
|
|
if v1 == v2 {
|
|
@@ -27,14 +53,188 @@ func GetLatestWeek(permissionIds []int, typeIds []int) (reportInfo *report.Repor
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+// GetChapterListByReport 根据报告获取章节列表
|
|
|
+func GetChapterListByReport(classifyNameFirst string, reportId int, companyId int64) (reportTypeList[]*response.ReportTypeListItem, 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 == "周报" {
|
|
|
+ permissionIds, tErr := company.GetValidPermissionIdListByCompany2ProductId(companyId, 1)
|
|
|
+ if tErr != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ newTypeIds, tErr := GetWeekTypeIdsByPermissionIds(permissionIds, typeIds)
|
|
|
+ if tErr != nil {
|
|
|
+ err = tErr
|
|
|
+ return
|
|
|
+ }
|
|
|
+ for _, v := range newTypeIds {
|
|
|
+ newTypeMap[v] = true
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //获取所有当前研报的章节
|
|
|
+ chapterList, tErr := report_chapter.GetListByReportId(reportId)
|
|
|
+ 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 {
|
|
|
+ // TODO 如果是周报只展示有权限的章节
|
|
|
+ if classifyNameFirst == "周报" {
|
|
|
+ if _, ok1 := newTypeMap[item.TypeId]; !ok1 {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ }
|
|
|
+ temp := new(response.ReportTypeListItem)
|
|
|
+ temp.ReportChapterId = item.ReportChapterId
|
|
|
+ temp.ReportId = item.ReportId
|
|
|
+ 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)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ 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))
|
|
|
+ }
|
|
|
+ }()
|
|
|
|
|
|
- chapter, err := report_chapter.GetLatestChapterByIdsAndClass(newTypeIds,"week")
|
|
|
+ typeIds, err := report_chapter_type.GetEffectTypeID()
|
|
|
if err != nil {
|
|
|
+ errMsg = err.Error()
|
|
|
+ err = errors.New("章节类型查询出错")
|
|
|
return
|
|
|
}
|
|
|
- reportInfo, err = report.GetByReportId(chapter.ReportId)
|
|
|
- if err == utils.ErrNoRow {
|
|
|
- return nil, nil
|
|
|
+ if len(typeIds) == 0 {
|
|
|
+ err = errors.New("无有效的章节类型")
|
|
|
+ return
|
|
|
+ }
|
|
|
+ reportChapter, err := report_chapter.GetContentById(reportChapterId, typeIds)
|
|
|
+ if err != nil {
|
|
|
+ errMsg = err.Error()
|
|
|
+ err = errors.New("章节查询出错")
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ if reportChapter.ReportChapterId == 0 {
|
|
|
+ err = errors.New("章节不存在")
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ var authOk bool
|
|
|
+ var chapterAuthOk bool
|
|
|
+ var permissionCheckInfo company.PermissionCheckInfo
|
|
|
+
|
|
|
+ reportInfo, tErr := report.GetByReportId(reportChapter.ReportId)
|
|
|
+ if tErr != nil {
|
|
|
+ errMsg = err.Error()
|
|
|
+ err = errors.New("报告查询出错")
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if reportInfo.Id == 0 {
|
|
|
+ err = errors.New("报告不存在")
|
|
|
+ return
|
|
|
+ }
|
|
|
+ //判断权限
|
|
|
+ permissionIds, tErr := company.GetValidPermissionIdListByCompany2ProductId(user.CompanyID, 1)
|
|
|
+ if tErr != nil && tErr != utils.ErrNoRow {
|
|
|
+ errMsg = tErr.Error()
|
|
|
+ err = errors.New("权限查询出错")
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ //TODO 修改权限校验接口,如果用户没有权限也要允许用户查看部分内容
|
|
|
+ authOk, permissionCheckInfo, tErr = company.CheckPermissionByPermissionIdList2Ficc(user.CompanyID, int(user.UserID), permissionIds)
|
|
|
+ if tErr != nil && tErr != utils.ErrNoRow{
|
|
|
+ errMsg = tErr.Error()
|
|
|
+ err = errors.New("权限查询出错")
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if reportInfo.ClassifyNameFirst == "周报" {
|
|
|
+ var newTypeIds []int
|
|
|
+ newTypeIds, err = GetWeekTypeIdsByPermissionIds(permissionIds, typeIds)
|
|
|
+ if err != nil && err != utils.ErrNoRow{
|
|
|
+ errMsg = tErr.Error()
|
|
|
+ err = errors.New("周报章节权限查询出错")
|
|
|
+ return
|
|
|
+ }
|
|
|
+ for _, v := range newTypeIds {
|
|
|
+ if v == reportChapter.TypeId {
|
|
|
+ chapterAuthOk = true
|
|
|
+ }
|
|
|
+ }
|
|
|
+ authOk = chapterAuthOk
|
|
|
+ }
|
|
|
+ reportChapterItem := new(response.ReportChapterItem)
|
|
|
+ reportChapterItem.ReportChapterId = reportChapter.ReportChapterId
|
|
|
+ reportChapterItem.ReportId = reportChapter.ReportId
|
|
|
+ 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.VideoSize = reportChapter.VideoSize
|
|
|
+ if authOk {
|
|
|
+ reportChapterItem.Content = reportChapter.Content
|
|
|
+ reportChapterItem.VideoUrl = reportChapter.VideoUrl
|
|
|
+ }else{
|
|
|
+ reportChapterItem.ContentSub = reportChapter.ContentSub
|
|
|
}
|
|
|
+ reportChapterDetail = new(response.ReportChapterDetail)
|
|
|
+ reportChapterDetail.ReportChapterItem = reportChapterItem
|
|
|
+ reportChapterDetail.PermissionCheck = &permissionCheckInfo
|
|
|
+ reportChapterDetail.AuthOk = authOk
|
|
|
return
|
|
|
}
|