ソースを参照

调整已购页面的分页和权限

xiexiaoyuan 3 年 前
コミット
181326bcce

+ 24 - 10
controller/purchase/purchase.go

@@ -7,6 +7,7 @@ import (
 	"hongze/hongze_yb/global"
 	"hongze/hongze_yb/services/purchase"
 	userService "hongze/hongze_yb/services/user"
+	"hongze/hongze_yb/utils"
 	"strconv"
 )
 
@@ -28,19 +29,26 @@ func List(c *gin.Context) {
 }
 
 func Detail(c *gin.Context)  {
-    classifyNameFirst := c.DefaultQuery("classify_name_first", "")
-	reqPageSize := c.DefaultQuery("page", "1")
-	reqPageLimit := c.DefaultQuery("limit", "10")
+    reqClassifyIdFirst := c.DefaultQuery("classify_id_first", "")
 	reqActivityId := c.DefaultQuery("activity_id", "")
 
+	reqPageIndex := c.DefaultQuery("current_index", "1")
+	reqPageSize := c.DefaultQuery("page_size", strconv.Itoa(utils.PageSize20))
+
+	pageIndex, err := strconv.Atoi(reqPageIndex)
+	if err != nil {
+		response.Fail("请输入正确的条数限制", c)
+		return
+	}
+
 	pageSize, err := strconv.Atoi(reqPageSize)
 	if err != nil {
 		response.Fail("请输入正确的页码", c)
 		return
 	}
-	pageLimit, err := strconv.Atoi(reqPageLimit)
-	if err != nil {
-		response.Fail("请输入正确的条数限制", c)
+
+	if reqClassifyIdFirst == "" && reqActivityId == "" {
+		response.Fail("请输入分类序号或者活动序号", c)
 		return
 	}
 
@@ -53,10 +61,16 @@ func Detail(c *gin.Context)  {
 		}
 	}
 
-	if classifyNameFirst == "" && activityId == 0 {
-		response.Fail("请输入分类类型或者活动序号", c)
-		return
+	var classifyIdFirst int
+	if reqClassifyIdFirst != ""{
+		classifyIdFirst, err = strconv.Atoi(reqClassifyIdFirst)
+		if err != nil {
+			response.Fail("分类ID格式错误", c)
+			return
+		}
 	}
+
+
 	// 判断用户是否有已购权限
 	userinfo := userService.GetInfoByClaims(c)
 	if userinfo.CompanyID == 0 {
@@ -64,7 +78,7 @@ func Detail(c *gin.Context)  {
 		return
 	}
 
-	list, err := purchase.GetDetail(userinfo, classifyNameFirst, activityId, pageSize, pageLimit)
+	list, err := purchase.GetDetail(userinfo, classifyIdFirst, activityId, pageIndex, pageSize)
 	if err != nil {
 		response.Fail(err.Error(), c)
 		global.LOG.Critical(fmt.Sprintf("userId=%d, errMsg:%s", userinfo.UserID, err.Error()))

+ 7 - 2
models/response/purchase/purchase.go

@@ -2,6 +2,7 @@ package purchase
 
 import (
 	"golang.org/x/sys/unix"
+	"hongze/hongze_yb/models/response"
 	"time"
 )
 
@@ -10,15 +11,19 @@ type PurchaseListItem struct {
 	Unread             int    `description:"未读数" json:"unread"`
 }
 
+type DetailResp struct {
+	List []*Detail  `json:"list"`
+	Paging  *response.PagingItem `json:"paging"`
+}
+
 type Detail struct {
 	item
-//	ImgUrl    string   `description:"背景图地址" json:"img_url"`
+	ImgUrl    string   `description:"背景图地址" json:"img_url"`
 	TopName         string   `description:"主标题" json:"top_name"`
 }
 
 type item struct {
 	ReportId           int    `description:"报告Id" json:"report_id"`
-	ReportChapterId    int    `description:"报告章节Id" json:"report_chapter_id"`
 	ActivityId		   int 	  `description:"活动ID" json:"activity_id"`
 	ClassifyIdFirst    int    `description:"一级分类id" json:"classify_id_first"`
 	ClassifyNameFirst  string `description:"一级分类名称" json:"classify_name_first"`

+ 33 - 0
models/tables/rddp/classify/query.go

@@ -35,4 +35,37 @@ func GetListByPid(pid int) (list []*Classify, err error) {
 		err = nil
 	}
 	return
+}
+
+
+// GetIdsByClassifyName 根据分类名称查找id
+func GetIdsByClassifyName(names []string) (ids []int, err error) {
+	var list []*Classify
+	err = global.MYSQL["rddp"].Model(Classify{}).Select("id").Where("classify_name in (?) ", names).Scan(&list).Error
+	if err == utils.ErrNoRow {
+		err = nil
+	}
+	if err != nil {
+		return
+	}
+	for _, v := range list {
+		ids = append(ids, v.Id)
+	}
+	return
+}
+
+// GetIdsByClassifyNameAndParentId 查询
+func GetIdsByClassifyNameAndParentId(names []string, parentId int) (ids []int, err error) {
+	var list []*Classify
+	err = global.MYSQL["rddp"].Model(Classify{}).Select("id").Where("classify_name in (?) and parent_id = ?", names, parentId).Scan(&list).Error
+	if err == utils.ErrNoRow {
+		err = nil
+	}
+	if err != nil {
+		return
+	}
+	for _, v := range list {
+		ids = append(ids, v.Id)
+	}
+	return
 }

+ 56 - 16
models/tables/rddp/report/query.go

@@ -5,7 +5,8 @@ import (
 	"hongze/hongze_yb/utils"
 )
 
-func GetLatestClassReportsByIDs(reportIDs []int) (reportList []*Report, err error) {
+// GetLatestClassReportsByClassifyIdSeconds 根据用户已购买的分类权限查询个分类最新的报告
+func GetLatestClassReportsByClassifyIdSeconds(classifyIdSeconds []int) (reportList []*Report, err error) {
 	sql := `SELECT
 	max( publish_time ) as publish_time,
 	classify_id_first,
@@ -19,34 +20,47 @@ FROM
 	report 
 WHERE
 	state = 2 
-	AND id IN ?
+	AND classify_id_second IN ?
 GROUP BY
 	classify_id_first`
-	err = global.MYSQL["rddp"].Raw(sql, reportIDs).Scan(&reportList).Error
+	err = global.MYSQL["rddp"].Raw(sql, classifyIdSeconds).Scan(&reportList).Error
 	return
 }
 
-// GetReportsByIDsAndDate 根据时间和报告ID筛选出合适的记录
-func GetReportsByIDsAndDate( ids []int, publishTime string) (reportList []*Report, err error) {
+// GetReportsByClassifyIdSecondsAndDate 根据时间和报告分类筛选出合适的记录
+func GetReportsByClassifyIdSecondsAndDate( classifyIdSeconds []int, publishTime string) (reportList []*Report, err error) {
 	err = global.MYSQL["rddp"].Model(Report{}).
 		Select("id, classify_name_first").
-		Where("id in (?) and state = 2 and publish_time > ? ", ids, publishTime).Scan(&reportList).Error
+		Where("classify_id_second in (?) and state = 2 and publish_time > ? ", classifyIdSeconds, publishTime).Scan(&reportList).Error
 	return
 }
 
-// GetReportsByIDsAndDateAndClass 根据时间和报告ID筛选出合适的记录
-func GetReportsByIDsAndDateAndClass( ids []int, classifyNameFirst string, publishTime string) (reportList []*Report, err error) {
+// GetListByIDsAndClassifyIdFirst 分页查询
+func GetListByIDsAndClassifyIdFirst( ids []int, classifyIdFirst int,  offset , limit int) (reportList []*Report, err error) {
 	err = global.MYSQL["rddp"].Model(Report{}).
-		Select("id, classify_name_first").
-		Where("id in (?) and state = 2 and classify_name_first = ? and publish_time > ? ", ids, classifyNameFirst, publishTime).Scan(&reportList).Error
+		Select("id, classify_id_first, classify_name_first, classify_id_second, classify_name_second, title, stage, publish_time").
+		Where("id in (?) and classify_id_first=? and state = 2 ", ids, classifyIdFirst).
+		Order("publish_time desc, id desc").
+		Offset(offset).
+		Limit(limit).
+		Scan(&reportList).Error
 	return
 }
 
-// GetListByIDsAndClassID 分页查询
-func GetListByIDsAndClassID( ids []int, classifyNameFirst string,  offset , limit int) (reportList []*Report, err error) {
+// GetListCountByIDsAndClassifyIdFirst 分页查询
+func GetListCountByIDsAndClassifyIdFirst( ids []int, classifyIdFirst int) (total int64, err error) {
 	err = global.MYSQL["rddp"].Model(Report{}).
 		Select("id, classify_id_first, classify_name_first, classify_id_second, classify_name_second, title, stage, publish_time").
-		Where("id in (?) and classify_name_first=? and state = 2 ", ids, classifyNameFirst).
+		Where("id in (?) and classify_id_first=? and state = 2 ", ids, classifyIdFirst).
+		Count(&total).Error
+	return
+}
+
+// GetListByClassifyIdSecondsAndClassifyIdFirst 分页查询
+func GetListByClassifyIdSecondsAndClassifyIdFirst( classifyIdSeconds []int, classifyIdFirst int,  offset , limit int) (reportList []*Report, err error) {
+	err = global.MYSQL["rddp"].Model(Report{}).
+		Select("id, classify_id_first, classify_name_first, classify_id_second, classify_name_second, title, stage, publish_time").
+		Where("classify_id_second in (?) and classify_id_first=? and state = 2 ", classifyIdSeconds, classifyIdFirst).
 		Order("publish_time desc, id desc").
 		Offset(offset).
 		Limit(limit).
@@ -54,11 +68,20 @@ func GetListByIDsAndClassID( ids []int, classifyNameFirst string,  offset , limi
 	return
 }
 
-// GetListByClass 按照类型分页查询
-func GetListByClass(classifyNameFirst string,  offset , limit int) (reportList []*Report, err error) {
+// GetListCountByClassifyIdSecondsAndClassifyIdFirst
+func GetListCountByClassifyIdSecondsAndClassifyIdFirst( classifyIdSeconds []int, classifyIdFirst int) (total int64, err error) {
 	err = global.MYSQL["rddp"].Model(Report{}).
 		Select("id, classify_id_first, classify_name_first, classify_id_second, classify_name_second, title, stage, publish_time").
-		Where("classify_name_first=? and state = 2 ", classifyNameFirst).
+		Where("classify_id_second in (?) and classify_id_first=? and state = 2 ", classifyIdSeconds, classifyIdFirst).
+		Count(&total).Error
+	return
+}
+
+// GetListByClassifyIdFirst 按照类型分页查询
+func GetListByClassifyIdFirst(classifyIdFirst int,  offset , limit int) (reportList []*Report, err error) {
+	err = global.MYSQL["rddp"].Model(Report{}).
+		Select("id, classify_id_first, classify_name_first, classify_id_second, classify_name_second, title, stage, publish_time").
+		Where("classify_id_first=? and state = 2 ", classifyIdFirst).
 		Order("publish_time desc, id desc").
 		Offset(offset).
 		Limit(limit).
@@ -66,6 +89,15 @@ func GetListByClass(classifyNameFirst string,  offset , limit int) (reportList [
 	return
 }
 
+// GetListCountByClassifyIdFirst 按照类型查询报告总数
+func GetListCountByClassifyIdFirst(classifyIdFirst int) (total int64, err error) {
+	err = global.MYSQL["rddp"].Model(Report{}).
+		Select("id, classify_id_first, classify_name_first, classify_id_second, classify_name_second, title, stage, publish_time").
+		Where("classify_id_first=? and state = 2 ", classifyIdFirst).
+		Count(&total).Error
+	return
+}
+
 // GetByReportId 根据id获取报告
 func GetByReportId(id int) (item *Report, err error) {
 	err = global.MYSQL["rddp"].Where("id = ? and state = 2", id).First(&item).Error
@@ -117,6 +149,7 @@ func GetListByClassifyIdSecond(classifyIdSecond int,  offset , limit int) (repor
 }
 
 
+
 // GetListCountByClassifyIdSecond 按照二级分类总条数
 func GetListCountByClassifyIdSecond(classifyIdSecond int) (total int64, err error) {
 	err = global.MYSQL["rddp"].Model(Report{}).
@@ -128,6 +161,13 @@ func GetListCountByClassifyIdSecond(classifyIdSecond int) (total int64, err erro
 	return
 }
 
+// GetReportListByCondition 获取报告列表
+func GetReportListByCondition(condition string, pars []interface{}) (list []*Report, err error) {
+	err = global.MYSQL["rddp"].Select("id").Model(Report{}).Where(condition, pars...).
+		Scan(&list).Error
+	return
+}
+
 
 // GetReportList 获取报告列表
 func GetReportList(condition string, pars []interface{}, offset , limit int) (list []*Report, err error) {

+ 3 - 3
models/tables/rddp/report_chapter/query.go

@@ -23,7 +23,7 @@ WHERE
 	AND classify_name_first = ?
 ORDER BY
 	publish_time desc`
-	err = global.MYSQL["rddp"].Raw(sql, typeIds, classifyNameFirst).First(&reportChapter).Error
+	err = global.MYSQL["rddp"].Model(ReportChapter{}).Raw(sql, typeIds, classifyNameFirst).First(&reportChapter).Error
 	return
 }
 
@@ -63,7 +63,7 @@ func GetListByReportIdTypeIds(reportId int, typeIds []int, classifyNameFirst str
 
 // GetContentById 根据ID获取章节详情
 func GetContentById(id int, typeIds []int) (info *ReportChapter, err error)  {
-	err = global.MYSQL["rddp"].Select("report_chapter_id, report_id,  is_edit, content, trend, type_id, type_name, abstract, title, author, publish_time, content, content_sub, video_url, video_name, video_play_seconds, video_size").
+	err = global.MYSQL["rddp"].Model(ReportChapter{}).Select("report_chapter_id, report_id,  is_edit, content, trend, type_id, type_name, abstract, title, author, publish_time, content, content_sub, video_url, video_name, video_play_seconds, video_size").
 		Where("report_chapter_id = ? and type_id in (?) AND publish_state = 2 ", id, typeIds).
 		First(&info).Error
 	if err == utils.ErrNoRow {
@@ -75,7 +75,7 @@ func GetContentById(id int, typeIds []int) (info *ReportChapter, err error)  {
 // GetReportIdsByTypeIdsAndClass 根据章节ID获取报告ID
 func GetReportIdsByTypeIdsAndClass(typeIds []int, classifyNameFirst string) (reportIds []int, err error) {
 	var list []*ReportChapter
-	err = global.MYSQL["rddp"].Select("DISTINCT report_id").Where("type_id = (?) and publish_state = 2 AND is_edit = 1 AND classify_name_first= ? ", typeIds, classifyNameFirst).Scan(&list).Error
+	err = global.MYSQL["rddp"].Model(ReportChapter{}).Select("DISTINCT report_id").Where("type_id in (?) and publish_state = 2 AND is_edit = 1 AND classify_name_first= ? ", typeIds, classifyNameFirst).Scan(&list).Error
 	if err != nil {
 		return
 	}

+ 8 - 0
models/tables/yb_activity/query.go

@@ -96,4 +96,12 @@ func GetListByIds(activityids []int, offset , limit int) (activitys []*YbActivit
 		Limit(limit).
 		Scan(&activitys).Error
 	return
+}
+
+// GetListCountByIds 查询活动列表总数
+func GetListCountByIds(activityIds []int) (total int64, err error)  {
+	err = global.DEFAULT_MYSQL.Model(YbActivity{}).
+		Where("activity_id in (?) and is_delete = 0 and publish_status = 1", activityIds).
+		Count(&total).Error
+	return
 }

+ 12 - 57
services/activity/activity.go

@@ -3,10 +3,9 @@ package activity
 import (
 	"fmt"
 	"gorm.io/gorm"
+	"hongze/hongze_yb/models/response"
 	"hongze/hongze_yb/models/response/purchase"
 	"hongze/hongze_yb/models/tables/company_product"
-	"hongze/hongze_yb/models/tables/rddp/report"
-	"hongze/hongze_yb/models/tables/rddp/report_view_log"
 	"hongze/hongze_yb/models/tables/yb_activity"
 	"hongze/hongze_yb/models/tables/yb_activity_permission"
 	"hongze/hongze_yb/models/tables/yb_activity_register"
@@ -236,7 +235,7 @@ func GetLatestActivity(permissionIds []int, userId uint64) (purchaseItem *purcha
 
 
 // GetList 从用户有权限参与的活动中,筛选出最新的活动
-func GetPurchaseDetail(permissionIds []int, userId uint64,  offset, pageLimit int) (list []*purchase.Detail, err error)  {
+func GetPurchaseDetail(permissionIds []int, userId uint64,  pageIndex, pageSize int) (ret *purchase.DetailResp, err error)  {
 	// 获取用户权限可参与的活动ID
 	var activityIds []int
 	permissions, err := yb_activity_permission.GetPermissionsByPermissionIds(permissionIds)
@@ -246,13 +245,16 @@ func GetPurchaseDetail(permissionIds []int, userId uint64,  offset, pageLimit in
 	for _, v := range permissions {
 		activityIds = append(activityIds, int(v.ActivityID))
 	}
-
-	activityList, err := yb_activity.GetListByIds(activityIds, offset, pageLimit)
+	offset := (pageIndex - 1) * pageSize
+	activityList, err := yb_activity.GetListByIds(activityIds, offset, pageSize)
 	if err != nil {
 		return
 	}
 
-
+	total, err := yb_activity.GetListCountByIds(activityIds)
+	if err != nil {
+		return
+	}
 	var WeekDayMap = map[string]string{
 		"Monday":    "周一",
 		"Tuesday":   "周二",
@@ -263,7 +265,8 @@ func GetPurchaseDetail(permissionIds []int, userId uint64,  offset, pageLimit in
 		"Sunday":    "周日",
 	}
 
-
+	ret = new(purchase.DetailResp)
+	var list []*purchase.Detail
 	for _, item := range activityList {
 		temp := new(purchase.Detail)
 		temp.ActivityId = item.ActivityID
@@ -280,7 +283,8 @@ func GetPurchaseDetail(permissionIds []int, userId uint64,  offset, pageLimit in
 		temp.TopName = item.ActivityName
 		list = append(list, temp)
 	}
-
+	ret.List = list
+	ret.Paging = response.GetPaging(pageIndex, pageSize, int(total))
 	num, tErr := BatchInsertActivityView(activityIds, userId)
 	log.Printf("新增活动浏览记录:%d", num)
 	if tErr != nil {
@@ -288,53 +292,4 @@ func GetPurchaseDetail(permissionIds []int, userId uint64,  offset, pageLimit in
 		return
 	}
 	return
-}
-
-
-// BatchInsertReportView 批量新增活动已读记录
-func BatchInsertReportView(reportIds []int, userId uint64, classifyNameFirst string) (num int, err error)  {
-	firstDay := "2022-01-01"
-	newReports, err := report.GetReportsByIDsAndDateAndClass(reportIds, classifyNameFirst, firstDay)
-	if err != nil {
-		return
-	}
-	var newIds []int
-	reportMap := make(map[int]int)
-	if len(newReports) > 0 {
-		for _, v := range newReports {
-			newIds = append(newIds, v.Id)
-			reportMap[v.Id] = v.Id
-		}
-		//获取用户的浏览记录
-		viewReportIds, tErr := report_view_log.GetByReportIdsAndUserIdAndTime(newIds, userId, firstDay)
-		if tErr != nil {
-			err = tErr
-			return
-		}
-
-		//过滤已经浏览过的报告ID
-		if len(viewReportIds) > 0 {
-			for _, item := range viewReportIds {
-				if _, ok := reportMap[item]; ok {
-					delete(reportMap, item)
-				}
-			}
-		}
-
-		var reportLogs []*report_view_log.ReportViewLog
-		for _, v := range reportMap{
-			temp := new(report_view_log.ReportViewLog)
-			temp.ReportId = v
-			temp.UserId = userId
-			temp.CreateTime = time.Now()
-			reportLogs = append(reportLogs, temp)
-		}
-		tErr = report_view_log.CreateInBatches(reportLogs)
-		if tErr != nil {
-			err = tErr
-			return
-		}
-		num = len(reportLogs)
-	}
-	return
 }

+ 6 - 6
services/purchase/purchase.go

@@ -38,20 +38,20 @@ func GetLatestReportAndActivity(user user.UserInfo) (list purchase.PurchaseList,
 }
 
 // GetDetail 已购详情页面
-func GetDetail(user user.UserInfo, classifyNameFirst string, activityId, pageSize, pageLimit int) (list []*purchase.Detail, err error)  {
+func GetDetail(user user.UserInfo, classifyIdFirst int, activityId, pageIndex, pageSize int) (ret *purchase.DetailResp, err error)  {
 	permissionIds, err := company.GetPurchasePermissionIdsByCompany2ProductId(user.CompanyID, 1)
 	if err != nil {
 		return
 	}
-	if len(permissionIds) <= 0 && classifyNameFirst != "晨报" {
+	if len(permissionIds) <= 0 {
 		err = errors.New("用户无权限")
 		return
 	}
-	offset := (pageSize - 1) * pageLimit
-	if classifyNameFirst != "" {
-		list, err = report.GetPurchaseDetail(permissionIds, user.UserID, classifyNameFirst, offset, pageLimit)
+
+	if classifyIdFirst != 0 {
+		ret, err = report.GetPurchaseDetail(permissionIds, user.UserID, classifyIdFirst, pageIndex, pageSize)
 	}else if activityId > 0 {
-		list, err = activity2.GetPurchaseDetail(permissionIds, user.UserID, offset, pageLimit)
+		ret, err = activity2.GetPurchaseDetail(permissionIds, user.UserID, pageIndex, pageSize)
 	}
 	return
 }

+ 125 - 36
services/report/report.go

@@ -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

+ 5 - 3
services/report/report_chapter.go

@@ -27,9 +27,11 @@ func GetLatestWeek(permissionIds []int, typeIds []int) (reportInfo *report.Repor
 	if err != nil {
 		return
 	}
-	reportInfo, err = report.GetByReportId(chapter.ReportId)
-	if err == utils.ErrNoRow {
-		return nil, nil
+	if chapter.ReportId > 0 {
+		reportInfo, err = report.GetByReportId(chapter.ReportId)
+		if err == utils.ErrNoRow {
+			return nil, nil
+		}
 	}
 	return
 }

+ 17 - 4
services/report/report_view_log.go

@@ -8,9 +8,9 @@ import (
 
 
 // GetUnRead 获取未读数
-func GetUnRead(reportIds []int, userId uint64) (unReadItem map[string]int, err error) {
+func GetUnRead(classifyIdSeconds []int, userId uint64) (unReadItem map[string]int, err error) {
 	firstDay := "2022-01-01"
-	newReports, err := report.GetReportsByIDsAndDate(reportIds, firstDay)
+	newReports, err := report.GetReportsByClassifyIdSecondsAndDate(classifyIdSeconds, firstDay)
 	if err != nil {
 		return
 	}
@@ -50,9 +50,22 @@ func GetUnRead(reportIds []int, userId uint64) (unReadItem map[string]int, err e
 }
 
 // BatchInsertReportView 批量新增报告已读记录
-func BatchInsertReportView(reportIds []int, userId uint64, classifyNameFirst string) (num int, err error)  {
+func BatchInsertReportView(weekReportIds []int, userId uint64, classifyNameFirst string, classifyIdSeconds []int) (num int, err error)  {
 	firstDay := "2022-01-01"
-	newReports, err := report.GetReportsByIDsAndDateAndClass(reportIds, classifyNameFirst, firstDay)
+	var newReports []*report.Report
+	pars := make([]interface{}, 0)
+
+	condition := "state = 2 and classify_name_first = ? and publish_time > ? "
+	pars = append(pars, classifyNameFirst, firstDay)
+	if classifyNameFirst == "晨报" {
+	} else if classifyNameFirst == "周报" {
+		condition += " and id in (?)"
+		pars = append(pars, weekReportIds)
+	} else {
+		condition += " and classify_id_second in (?)"
+		pars = append(pars, classifyIdSeconds)
+	}
+	newReports, err = report.GetReportListByCondition(condition, pars)
 	if err != nil {
 		return
 	}