|
@@ -15,20 +15,16 @@ import (
|
|
|
"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
|
|
|
- }
|
|
|
+ var errMsg string
|
|
|
+ defer func() {
|
|
|
+ if err != nil {
|
|
|
+ global.LOG.Critical(fmt.Sprintf("GetLatestClassReport: userId=%d, err:%s, errMsg:%s", userId, err.Error(), errMsg))
|
|
|
+ }
|
|
|
+ }()
|
|
|
+
|
|
|
//获取最新的晨报
|
|
|
dayReport, err := report.GetLatestDay()
|
|
|
if err != nil {
|
|
@@ -39,18 +35,52 @@ func GetLatestClassReport(permissionIds []int, userId uint64) (purchaseList []*p
|
|
|
}
|
|
|
}
|
|
|
//获取最新的有权限的周报
|
|
|
+ typeIds, tErr := report_chapter_type.GetEffectTypeID()
|
|
|
+ if tErr != nil {
|
|
|
+ err = tErr
|
|
|
+ return
|
|
|
+ }
|
|
|
weekReport, err := GetLatestWeek(permissionIds, typeIds)
|
|
|
if err != nil {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
var reports []*report.Report
|
|
|
- if len(reportIds) > 0 {
|
|
|
- reports, err = report.GetLatestClassReportsByIDs(reportIds)
|
|
|
+ // 有权限的二级分类
|
|
|
+ var classifyIdSeconds []int
|
|
|
+ // 获取晨报和周报以外的其他报告
|
|
|
+ {
|
|
|
+ //获取有权限的二级分类
|
|
|
+ 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.GetIdsByClassifyName(classifyNameSeconds)
|
|
|
+ if tErr != nil {
|
|
|
+ errMsg = tErr.Error()
|
|
|
+ err = errors.New("二级分类查询出错")
|
|
|
+ return
|
|
|
+ }
|
|
|
+ reports, err = report.GetLatestClassReportsByClassifyIdSeconds(classifyIdSeconds)
|
|
|
if err != nil {
|
|
|
return
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
if dayReport != nil {
|
|
|
reports = append(reports, dayReport)
|
|
|
|
|
@@ -60,7 +90,7 @@ func GetLatestClassReport(permissionIds []int, userId uint64) (purchaseList []*p
|
|
|
}
|
|
|
|
|
|
//获取未读数
|
|
|
- unReadItem, tErr := GetUnRead(reportIds, userId)
|
|
|
+ unReadItem, tErr := GetUnRead(classifyIdSeconds, userId)
|
|
|
if tErr != nil {
|
|
|
err = tErr
|
|
|
return
|
|
@@ -99,25 +129,44 @@ func GetReportIdsByPermissionIds(permissionIds []int) (reportIds []int, err erro
|
|
|
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) {
|
|
|
+func GetPurchaseDetail(permissionIds []int, userId uint64, classifyIdFirst int, pageIndex, pageSize int) (ret *purchase.DetailResp, err error) {
|
|
|
+ var errMsg string
|
|
|
+ defer func() {
|
|
|
+ if err != nil {
|
|
|
+ global.LOG.Critical(fmt.Sprintf("GetPurchaseDetail: userId=%d, err:%s, errMsg:%s", userId, err.Error(), errMsg))
|
|
|
+ }
|
|
|
+ }()
|
|
|
var reports []*report.Report
|
|
|
- var reportIds []int
|
|
|
+ var weekReportIds []int
|
|
|
+
|
|
|
+ classifyInfo, err := classify.GetByClassifyId(classifyIdFirst)
|
|
|
+ if err != nil {
|
|
|
+ errMsg = err.Error()
|
|
|
+ err = errors.New("分类查询出错")
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ if classifyInfo.Id == 0 {
|
|
|
+ err = errors.New("分类不存在")
|
|
|
+ return
|
|
|
+ }
|
|
|
+ classifyNameFirst := classifyInfo.ClassifyName
|
|
|
+ offset := (pageIndex - 1) * pageSize
|
|
|
+ var total int64
|
|
|
+ var classifyIdSeconds []int
|
|
|
if classifyNameFirst == "晨报" {
|
|
|
//分类获取
|
|
|
- reports, err = report.GetListByClass(classifyNameFirst, offset, pageLimit)
|
|
|
+ reports, err = report.GetListByClassifyIdFirst(classifyIdFirst, offset, pageSize)
|
|
|
if err != nil {
|
|
|
return
|
|
|
}
|
|
|
- for _, v := range reports {
|
|
|
- reportIds = append(reportIds, v.Id)
|
|
|
+ total, err = report.GetListCountByClassifyIdFirst(classifyIdFirst)
|
|
|
+ if err != nil {
|
|
|
+ errMsg = err.Error()
|
|
|
+ err = errors.New("查询报告总数出错")
|
|
|
+ return
|
|
|
}
|
|
|
}else {
|
|
|
if classifyNameFirst == "周报" {
|
|
@@ -125,22 +174,61 @@ func GetPurchaseDetail(permissionIds []int, userId uint64, classifyNameFirst str
|
|
|
if tErr != nil {
|
|
|
return
|
|
|
}
|
|
|
- reportIds, err = report_chapter.GetReportIdsByTypeIdsAndClass(newTypeIds, classifyNameFirst)
|
|
|
- } else {
|
|
|
- reportIds, err = GetReportIdsByPermissionIds(permissionIds)
|
|
|
+ weekReportIds, err = report_chapter.GetReportIdsByTypeIdsAndClass(newTypeIds, classifyNameFirst)
|
|
|
+ //分类获取
|
|
|
+ reports, err = report.GetListByIDsAndClassifyIdFirst(weekReportIds, classifyIdFirst, offset, pageSize)
|
|
|
if err != nil {
|
|
|
return
|
|
|
}
|
|
|
- }
|
|
|
-
|
|
|
- if len(reportIds) > 0 {
|
|
|
- //分类获取
|
|
|
- reports, err = GetListByClassName(reportIds, classifyNameFirst, offset, pageLimit)
|
|
|
+ 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
|
|
|
+ ret = new(purchase.DetailResp)
|
|
|
if len(reports) > 0 {
|
|
|
var viewReportIds []int
|
|
|
for _, v := range reports {
|
|
@@ -152,6 +240,7 @@ func GetPurchaseDetail(permissionIds []int, userId uint64, classifyNameFirst str
|
|
|
temp.Title = v.Title
|
|
|
temp.ClassifyIdSecond = v.ClassifyIdSecond
|
|
|
temp.ClassifyNameSecond = v.ClassifyNameSecond
|
|
|
+ temp.Stage = v.Stage
|
|
|
if temp.ClassifyNameFirst == "晨报" || temp.ClassifyNameFirst == "周报" { //晨报或者周报,查询最新的章节信息
|
|
|
temp.Content = fmt.Sprintf("【第%d期|FICC】%s", temp.Stage, temp.Title)
|
|
|
temp.TopName = temp.Title
|
|
@@ -168,9 +257,9 @@ func GetPurchaseDetail(permissionIds []int, userId uint64, classifyNameFirst str
|
|
|
list = append(list, temp)
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- num, tErr := BatchInsertReportView(reportIds, userId, classifyNameFirst)
|
|
|
- log.Printf("新增报告浏览记录:%d", num)
|
|
|
+ ret.List = list
|
|
|
+ ret.Paging = response.GetPaging(pageIndex, pageSize, int(total))
|
|
|
+ _, tErr := BatchInsertReportView(weekReportIds, userId, classifyNameFirst, classifyIdSeconds)
|
|
|
if tErr != nil {
|
|
|
err = tErr
|
|
|
return
|