|
@@ -33,49 +33,81 @@ func GetLatestClassReport(permissionIds []int, userId uint64) (purchaseList []*p
|
|
|
global.LOG.Critical(fmt.Sprintf("GetLatestClassReport: userId=%d, err:%s, errMsg:%s", userId, err.Error(), errMsg))
|
|
|
}
|
|
|
}()
|
|
|
- //获取所有和权限绑定的报告
|
|
|
- reportIds, err := GetReportIdsByPermissionIds(permissionIds)
|
|
|
+
|
|
|
+ //获取所有分类信息
|
|
|
+ classifys, err := classify.GetSimpleAll()
|
|
|
if err != nil {
|
|
|
+ errMsg = err.Error()
|
|
|
+ err = errors.New("分类查询出错")
|
|
|
return
|
|
|
}
|
|
|
+ classifyFirstIconMap := make(map[int]string)
|
|
|
+ classifySecondNameMap := make(map[string]int)
|
|
|
+ for _, v := range classifys{
|
|
|
+ if v.ParentId == 0 {
|
|
|
+ classifyFirstIconMap[v.Id] = v.YbIconUrl
|
|
|
+ }else{
|
|
|
+ classifySecondNameMap[v.ClassifyName] = v.Id
|
|
|
+ }
|
|
|
+ }
|
|
|
//获取最新的晨报
|
|
|
dayReport, err := report.GetLatestDay()
|
|
|
if err != nil {
|
|
|
- if err == utils.ErrNoRow {
|
|
|
- dayReport = nil
|
|
|
- }else{
|
|
|
- return
|
|
|
- }
|
|
|
+ errMsg = err.Error()
|
|
|
+ err = errors.New("晨报查询出错")
|
|
|
+ return
|
|
|
}
|
|
|
//获取最新的有权限的周报
|
|
|
- typeIds, tErr := report_chapter_type.GetEffectTypeID()
|
|
|
- if tErr != nil {
|
|
|
- err = tErr
|
|
|
+ typeIds, err := report_chapter_type.GetEffectTypeID()
|
|
|
+ if err != nil {
|
|
|
+ errMsg = err.Error()
|
|
|
+ err = errors.New("晨报查询出错")
|
|
|
return
|
|
|
}
|
|
|
weekReport, err := GetLatestWeek(permissionIds, typeIds)
|
|
|
if err != nil {
|
|
|
+ errMsg = err.Error()
|
|
|
+ err = errors.New("周报查询出错")
|
|
|
return
|
|
|
}
|
|
|
-
|
|
|
+ // 有权限的二级分类
|
|
|
var reports []*report.Report
|
|
|
+ var classifyIdSeconds []int
|
|
|
// 获取晨报和周报以外的其他报告
|
|
|
- reports, err = report.GetLatestClassReportsByIDs(reportIds)
|
|
|
+ // 获取有权限的二级分类
|
|
|
+
|
|
|
+ chartPermissions, err := chart_permission_search_key_word_mapping.GetChartPermissionByFrom("rddp")
|
|
|
if err != nil {
|
|
|
+ errMsg = err.Error()
|
|
|
+ err = errors.New("分类权限查询出错")
|
|
|
return
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
- if dayReport != nil {
|
|
|
+ if len(chartPermissions) > 0 {
|
|
|
+ for _, v := range chartPermissions {
|
|
|
+ for _, myPerId := range permissionIds {
|
|
|
+ if v.ChartPermissionId == myPerId {
|
|
|
+ if classifyNameSecond, ok := classifySecondNameMap[v.KeyWord]; ok{
|
|
|
+ classifyIdSeconds = append(classifyIdSeconds, classifyNameSecond)
|
|
|
+ }
|
|
|
+ break
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ reports, err = report.GetLatestClassReportsByClassifyIdSeconds(classifyIdSeconds)
|
|
|
+ if err != nil {
|
|
|
+ errMsg = err.Error()
|
|
|
+ err = errors.New("二级分类最新报告查询出错")
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if dayReport.Id > 0 {
|
|
|
reports = append(reports, dayReport)
|
|
|
-
|
|
|
}
|
|
|
if weekReport != nil {
|
|
|
reports = append(reports, weekReport)
|
|
|
}
|
|
|
-
|
|
|
//获取未读数
|
|
|
- unReadItem, tErr := GetUnRead(reportIds, userId)
|
|
|
+ unReadItem, tErr := GetUnRead(classifyIdSeconds, userId)
|
|
|
if tErr != nil {
|
|
|
err = tErr
|
|
|
return
|
|
@@ -90,6 +122,9 @@ func GetLatestClassReport(permissionIds []int, userId uint64) (purchaseList []*p
|
|
|
temp.Title = v.Title
|
|
|
temp.ClassifyIdSecond = v.ClassifyIdSecond
|
|
|
temp.ClassifyNameSecond = v.ClassifyNameSecond
|
|
|
+ if imgUrl, ok := classifyFirstIconMap[temp.ClassifyIdFirst]; ok {
|
|
|
+ temp.ImgUrl = imgUrl
|
|
|
+ }
|
|
|
if temp.ClassifyNameFirst == "晨报" || temp.ClassifyNameFirst == "周报" { //晨报或者周报,查询最新的章节信息
|
|
|
temp.Content = fmt.Sprintf("【第%d期|FICC】%s", temp.Stage, temp.Title)
|
|
|
}else{
|
|
@@ -108,13 +143,6 @@ func GetLatestClassReport(permissionIds []int, userId uint64) (purchaseList []*p
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-// GetReportIdsByPermissionIds 获取所有和权限绑定的报告
|
|
|
-func GetReportIdsByPermissionIds(permissionIds []int) (reportIds []int, err error) {
|
|
|
- reportIds, err = chart_permission_chapter_mapping.GetReportIdsByPermisssionIds(permissionIds, "rddp")
|
|
|
- return
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
// GetPurchaseDetail 已购详情页面
|
|
|
func GetPurchaseDetail(permissionIds []int, userId uint64, classifyIdFirst int, pageIndex, pageSize int) (ret *purchase.DetailResp, err error) {
|
|
|
var errMsg string
|
|
@@ -124,7 +152,7 @@ func GetPurchaseDetail(permissionIds []int, userId uint64, classifyIdFirst int,
|
|
|
}
|
|
|
}()
|
|
|
var reports []*report.Report
|
|
|
- var reportIds []int
|
|
|
+ var weekReportIds []int
|
|
|
|
|
|
classifyInfo, err := classify.GetByClassifyId(classifyIdFirst)
|
|
|
if err != nil {
|
|
@@ -140,15 +168,16 @@ func GetPurchaseDetail(permissionIds []int, userId uint64, classifyIdFirst int,
|
|
|
classifyNameFirst := classifyInfo.ClassifyName
|
|
|
offset := (pageIndex - 1) * pageSize
|
|
|
var total int64
|
|
|
+ var classifyIdSeconds []int
|
|
|
+
|
|
|
if classifyNameFirst == "晨报" {
|
|
|
//分类获取
|
|
|
reports, err = report.GetListByClassifyIdFirst(classifyIdFirst, offset, pageSize)
|
|
|
if err != nil {
|
|
|
+ errMsg = err.Error()
|
|
|
+ err = errors.New("晨报查询出错")
|
|
|
return
|
|
|
}
|
|
|
- for _, v := range reports {
|
|
|
- reportIds = append(reportIds, v.Id)
|
|
|
- }
|
|
|
total, err = report.GetListCountByClassifyIdFirst(classifyIdFirst)
|
|
|
if err != nil {
|
|
|
errMsg = err.Error()
|
|
@@ -161,26 +190,57 @@ func GetPurchaseDetail(permissionIds []int, userId uint64, classifyIdFirst int,
|
|
|
if tErr != nil {
|
|
|
return
|
|
|
}
|
|
|
- reportIds, err = report_chapter.GetReportIdsByTypeIdsAndClass(newTypeIds, classifyNameFirst)
|
|
|
- } else {
|
|
|
- reportIds, err = GetReportIdsByPermissionIds(permissionIds)
|
|
|
- if err != nil {
|
|
|
- return
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if len(reportIds) > 0 {
|
|
|
+ weekReportIds, err = report_chapter.GetReportIdsByTypeIdsAndClass(newTypeIds, classifyNameFirst)
|
|
|
//分类获取
|
|
|
- reports, err = report.GetListByIDsAndClassifyIdFirst(reportIds, classifyIdFirst, offset, pageSize)
|
|
|
+ reports, err = report.GetListByIDsAndClassifyIdFirst(weekReportIds, classifyIdFirst, offset, pageSize)
|
|
|
if err != nil {
|
|
|
return
|
|
|
}
|
|
|
- total, err = report.GetListCountByIDsAndClassifyIdFirst(reportIds, classifyIdFirst)
|
|
|
+ total, err = report.GetListCountByIDsAndClassifyIdFirst(weekReportIds, classifyIdFirst)
|
|
|
if err != nil {
|
|
|
errMsg = err.Error()
|
|
|
err = errors.New("查询报告总数出错")
|
|
|
return
|
|
|
}
|
|
|
+ }else{
|
|
|
+ //获取有权限的二级分类
|
|
|
+ var classifyNameSeconds []string
|
|
|
+ chartPermissions, tErr := chart_permission_search_key_word_mapping.GetChartPermissionByFrom("rddp")
|
|
|
+ if tErr != nil {
|
|
|
+ errMsg = tErr.Error()
|
|
|
+ err = errors.New("分类权限查询出错")
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if len(chartPermissions) > 0 {
|
|
|
+ for _, v := range chartPermissions {
|
|
|
+ for _, myPerId := range permissionIds {
|
|
|
+ if v.ChartPermissionId == myPerId {
|
|
|
+ classifyNameSeconds = append(classifyNameSeconds, v.KeyWord)
|
|
|
+ break
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //获取所有二级分类的id
|
|
|
+ classifyIdSeconds, tErr = classify.GetIdsByClassifyNameAndParentId(classifyNameSeconds, classifyIdFirst)
|
|
|
+ if tErr != nil {
|
|
|
+ errMsg = tErr.Error()
|
|
|
+ err = errors.New("二级分类查询出错")
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if len(classifyIdSeconds) > 0 {
|
|
|
+ //分类获取
|
|
|
+ reports, err = report.GetListByClassifyIdSecondsAndClassifyIdFirst(classifyIdSeconds, classifyIdFirst, offset, pageSize)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ total, err = report.GetListCountByClassifyIdSecondsAndClassifyIdFirst(classifyIdSeconds, classifyIdFirst)
|
|
|
+ if err != nil {
|
|
|
+ errMsg = err.Error()
|
|
|
+ err = errors.New("查询报告总数出错")
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
var list []*purchase.Detail
|
|
@@ -197,6 +257,7 @@ func GetPurchaseDetail(permissionIds []int, userId uint64, classifyIdFirst int,
|
|
|
temp.ClassifyIdSecond = v.ClassifyIdSecond
|
|
|
temp.ClassifyNameSecond = v.ClassifyNameSecond
|
|
|
temp.Stage = v.Stage
|
|
|
+ temp.ImgUrl = classifyInfo.YbBgUrl
|
|
|
if temp.ClassifyNameFirst == "晨报" || temp.ClassifyNameFirst == "周报" { //晨报或者周报,查询最新的章节信息
|
|
|
temp.Content = fmt.Sprintf("【第%d期|FICC】%s", temp.Stage, temp.Title)
|
|
|
temp.TopName = temp.Title
|
|
@@ -215,7 +276,8 @@ func GetPurchaseDetail(permissionIds []int, userId uint64, classifyIdFirst int,
|
|
|
}
|
|
|
ret.List = list
|
|
|
ret.Paging = response.GetPaging(pageIndex, pageSize, int(total))
|
|
|
- _, tErr := BatchInsertReportView(reportIds, userId, classifyNameFirst)
|
|
|
+ _, tErr := BatchInsertReportView(weekReportIds, userId, classifyNameFirst, classifyIdSeconds)
|
|
|
+
|
|
|
if tErr != nil {
|
|
|
err = tErr
|
|
|
return
|