瀏覽代碼

首页报告汇总

xiexiaoyuan 3 年之前
父節點
當前提交
42e298def2

+ 37 - 0
controller/report/report.go

@@ -100,4 +100,41 @@ func List(c *gin.Context)  {
 	}
 	}
 	response.OkData("查询成功", list, c )
 	response.OkData("查询成功", list, c )
 	return
 	return
+}
+
+func CollectReportList(c *gin.Context) {
+	reqChartPermissionId := c.DefaultQuery("chart_permission_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
+	}
+
+	if reqChartPermissionId == ""{
+		response.Fail("请输入权限ID", c)
+		return
+	}
+	chartPermissionId, err := strconv.Atoi(reqChartPermissionId)
+	if err != nil {
+		response.Fail("权限ID格式错误", c)
+		return
+	}
+	userinfo := userService.GetInfoByClaims(c)
+
+	list, err := report.GetCollectReportList(userinfo, chartPermissionId, pageIndex, pageSize)
+	if err != nil {
+		response.Fail(err.Error(), c)
+		return
+	}
+	response.OkData("查询成功", list, c )
+	return
 }
 }

+ 18 - 0
models/response/report.go

@@ -98,4 +98,22 @@ type ReportListItem struct {
 type ReportList struct {
 type ReportList struct {
 	Paging     *PagingItem  		`json:"paging"`
 	Paging     *PagingItem  		`json:"paging"`
 	List        []*ReportListItem `json:"list"`
 	List        []*ReportListItem `json:"list"`
+}
+
+type ReportCollectListItem struct {
+	ReportId                 int    `description:"报告Id" json:"report_id"`
+	ReportChapterId    int    `json:"report_chapter_id"`
+	ClassifyIdFirst    int    `description:"一级分类id" json:"classify_id_first"`
+	ClassifyNameFirst  string `description:"一级分类名称" json:"classify_name_first"`
+	ClassifyIdSecond   int    `description:"二级分类id" json:"classify_id_second"`
+	ClassifyNameSecond string `description:"二级分类名称" json:"classify_name_second"`
+	ReportChapterTypeId                  int         `json:"report_chapter_type_id"`
+	PublishTime        time.Time `description:"发布时间" json:"publish_time"`
+	Title              string `description:"标题" json:"title"`
+	ContentSub         string `description:"内容前两个章节" json:"content_sub"`
+}
+
+type ReportCollectResp struct {
+	Paging     *PagingItem  		`json:"paging"`
+	List []*ReportCollectListItem `json:"list"`
 }
 }

+ 9 - 0
models/tables/chart_permission/query.go

@@ -45,3 +45,12 @@ func GetListByProductIdAndClassifyName(productId int, classifyName string) (item
 	err = global.DEFAULT_MYSQL.Model(ChartPermission{}).Where("enabled = 1 AND permission_type = 0 AND product_id = ? AND classify_name = ?", productId, classifyName).Order("sort ASC").Scan(&items).Error
 	err = global.DEFAULT_MYSQL.Model(ChartPermission{}).Where("enabled = 1 AND permission_type = 0 AND product_id = ? AND classify_name = ?", productId, classifyName).Order("sort ASC").Scan(&items).Error
 	return
 	return
 }
 }
+
+// GetByChartPermissionId 根据chartPermissionId 查找权限基本信息
+func GetByChartPermissionId(chartPermissionId int) (item *ChartPermission, err error)  {
+	err = global.DEFAULT_MYSQL.Model(ChartPermission{}).Where("chart_permission_id = ?", chartPermissionId).First(&item).Error
+	if err == utils.ErrNoRow {
+		err = nil
+	}
+	return
+}

+ 15 - 0
models/tables/chart_permission_search_key_word_mapping/query.go

@@ -29,3 +29,18 @@ func GetChartPermissionByFrom(from string) (list []*ChartPermissionSearchKeyWord
 	}
 	}
 	return
 	return
 }
 }
+
+// GetKeyWordsByChartPermissionId 根据权限ID, 查询二级分类名称
+func GetKeyWordsByChartPermissionId(charPermissionId int, from string) (keyWords []string, err error)  {
+	var list []*ChartPermissionSearchKeyWordMapping
+	err = global.DEFAULT_MYSQL.Model(ChartPermissionSearchKeyWordMapping{}).Where("chart_permission_id = ? and `from` = ? ", charPermissionId, from).Scan(&list).Error
+	if err != nil && err != utils.ErrNoRow {
+		return
+	}
+	if len(list) > 0 {
+		for _, item := range list {
+			keyWords = append(keyWords, item.KeyWord)
+		}
+	}
+	return
+}

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

@@ -19,6 +19,22 @@ func GetByClassifyName(classifyName string) (item *Classify, err error) {
 	return
 	return
 }
 }
 
 
+// GetSecondIdsByClassifyNames 根据权限相关的二级分类名称获取名称ID
+func GetSecondIdsByClassifyNames(names []string) (ids []int, err error) {
+	var list []*Classify
+	err = global.MYSQL["rddp"].Model(Classify{}).Select("id").Where("classify_name in (?) and parent_id >0 ", names).Scan(&list).Error
+	if err != nil {
+		if err == utils.ErrNoRow {
+			err = nil
+		}
+		return
+	}
+	for _, v := range list {
+		ids = append(ids, v.Id)
+	}
+	return
+}
+
 // GetParentList 查询所有一级分类
 // GetParentList 查询所有一级分类
 func GetParentList() (list []*Classify, err error) {
 func GetParentList() (list []*Classify, err error) {
 	err = global.MYSQL["rddp"].Model(Classify{}).Where("parent_id = 0").Order("sort asc, id asc").Scan(&list).Error
 	err = global.MYSQL["rddp"].Model(Classify{}).Where("parent_id = 0").Order("sort asc, id asc").Scan(&list).Error

+ 76 - 0
models/tables/rddp/report/query.go

@@ -2,6 +2,7 @@ package report
 
 
 import (
 import (
 	"hongze/hongze_yb/global"
 	"hongze/hongze_yb/global"
+	"hongze/hongze_yb/models/response"
 	"hongze/hongze_yb/utils"
 	"hongze/hongze_yb/utils"
 )
 )
 
 
@@ -162,4 +163,79 @@ func GetReportListCount(condition string, pars []interface{}) (total int64, err
 	err = global.MYSQL["rddp"].Model(Report{}).Where(condition, pars...).
 	err = global.MYSQL["rddp"].Model(Report{}).Where(condition, pars...).
 		Count(&total).Error
 		Count(&total).Error
 	return
 	return
+}
+
+// GetReportCollectListByPermission 根据权限相关的分类查询报告和章节
+func GetReportCollectListByPermission(classifyIdSeconds []int, typeIds []int, offset , limit int) (list []*response.ReportCollectListItem, err error)  {
+	sql := `( SELECT
+id AS report_id,
+0 AS report_chapter_id,
+classify_id_first,
+classify_id_second,
+classify_name_first,
+classify_name_second,
+0 as report_chapter_type_id,
+title,
+content_sub,
+publish_time 
+FROM
+	report
+WHERE
+	classify_name_first != "晨报" 
+	AND classify_name_first != "周报" 
+	AND classify_id_second in (?)
+	AND state = 2
+	)
+UNION
+	
+( SELECT
+report_id,
+report_chapter_id,
+classify_id_first,
+0 as classify_id_second,
+classify_name_first,
+null as classify_name_second,
+type_id as report_chapter_type_id,
+title,
+content_sub,
+publish_time 
+FROM
+	report_chapter
+WHERE
+	publish_state = 2
+	AND type_id in (?)
+	)
+	ORDER BY publish_time DESC, report_id desc LIMIT ? OFFSET ?
+	`
+	err = global.MYSQL["rddp"].Raw(sql, classifyIdSeconds, typeIds, limit, offset).Scan(&list).Error
+	return
+}
+// GetReportCollectCountByPermission 查询汇总报告总页数
+func GetReportCollectCountByPermission(classifyIdSeconds []int, typeIds []int) (total int64, err error)  {
+	sql := `select count(*) from ( ( SELECT
+id AS report_id,
+0 AS report_chapter_id
+FROM
+        report
+WHERE
+        classify_name_first != "晨报" 
+        AND classify_name_first != "周报" 
+        AND classify_id_second in (55,35,58,65,61,47)
+        AND state = 2
+        )
+UNION
+        
+( SELECT
+report_id,
+report_chapter_id
+FROM
+        report_chapter
+WHERE
+        publish_state = 2
+        AND type_id in (9,28)
+        )
+) as ru
+	`
+	err = global.MYSQL["rddp"].Raw(sql, classifyIdSeconds, typeIds).Count(&total).Error
+	return
 }
 }

+ 18 - 0
models/tables/report_chapter_type/query.go

@@ -28,3 +28,21 @@ func GetEffectTypes() (list []*ReportChapterType, err error ) {
 	return
 	return
 }
 }
 
 
+// GetTypeIDByReportChapterTypeName 根据章节类型查找章节ID
+func GetTypeIDByReportChapterTypeName(name string) (chapterIds []int, err error ) {
+	var chapterList []*ReportChapterType
+	err = global.DEFAULT_MYSQL.Model(ReportChapterType{}).Select("report_chapter_type_id ").Where("is_show=1 and report_chapter_type_name =?", name).Scan(&chapterList).Error
+	if err != nil {
+		if err == utils.ErrNoRow {
+			err = nil
+		}
+		return
+	}
+	if len(chapterList) > 0 {
+		for _, v := range chapterList {
+			chapterIds = append(chapterIds, int(v.ReportChapterTypeId))
+		}
+	}
+	return
+}
+

+ 2 - 0
routers/report.go

@@ -11,6 +11,7 @@ func InitReport(r *gin.Engine)  {
 	rGroup.GET("/detail", report.Detail)
 	rGroup.GET("/detail", report.Detail)
 	rGroup.GET("/chapter/detail", report.ChapterDetail)
 	rGroup.GET("/chapter/detail", report.ChapterDetail)
 	rGroup.GET("/list", report.List)
 	rGroup.GET("/list", report.List)
+	rGroup.GET("/collect", report.CollectReportList)
 
 
 	rGroup2 := r.Group("api/classify").Use(middleware.Token())
 	rGroup2 := r.Group("api/classify").Use(middleware.Token())
 	rGroup2.GET("/", report.ClassifyFirstList)
 	rGroup2.GET("/", report.ClassifyFirstList)
@@ -18,4 +19,5 @@ func InitReport(r *gin.Engine)  {
 	rGroup2.GET("/simple/list", report.ClassifySimpleList)
 	rGroup2.GET("/simple/list", report.ClassifySimpleList)
 	rGroup2.GET("/detail", report.ClassifyDetail)
 	rGroup2.GET("/detail", report.ClassifyDetail)
 	rGroup2.GET("/detail/reports", report.ClassifyDetailReports)
 	rGroup2.GET("/detail/reports", report.ClassifyDetailReports)
+
 }
 }

+ 71 - 0
services/report/report.go

@@ -6,6 +6,7 @@ import (
 	"hongze/hongze_yb/global"
 	"hongze/hongze_yb/global"
 	"hongze/hongze_yb/models/response"
 	"hongze/hongze_yb/models/response"
 	"hongze/hongze_yb/models/response/purchase"
 	"hongze/hongze_yb/models/response/purchase"
+	"hongze/hongze_yb/models/tables/chart_permission"
 	"hongze/hongze_yb/models/tables/chart_permission_chapter_mapping"
 	"hongze/hongze_yb/models/tables/chart_permission_chapter_mapping"
 	"hongze/hongze_yb/models/tables/chart_permission_search_key_word_mapping"
 	"hongze/hongze_yb/models/tables/chart_permission_search_key_word_mapping"
 	"hongze/hongze_yb/models/tables/rddp/classify"
 	"hongze/hongze_yb/models/tables/rddp/classify"
@@ -439,4 +440,74 @@ func GetReportList(user user.UserInfo, keyWord string, classifyIdFirst, classify
 	ret.List = reportList
 	ret.List = reportList
 	ret.Paging = response.GetPaging(pageIndex, pageSize, int(total))
 	ret.Paging = response.GetPaging(pageIndex, pageSize, int(total))
 	return
 	return
+}
+
+// GetCollectReportList 首页展示报告汇总列表
+func GetCollectReportList(user user.UserInfo, chartPermissionId, pageIndex, pageSize int) (ret *response.ReportCollectResp, err error)  {
+	var errMsg string
+	defer func() {
+		if err != nil {
+			global.LOG.Critical(fmt.Sprintf("GetCollectReportList: userId=%d, err:%s, errMsg:%s", user.UserID, err.Error(), errMsg))
+		}
+	}()
+
+	// 查询权限的基本信息
+	permissionInfo, err := chart_permission.GetByChartPermissionId(chartPermissionId)
+	if err != nil {
+		errMsg = err.Error()
+		err = errors.New("查询权限出错")
+		return
+	}
+
+	if permissionInfo.ChartPermissionID == 0 {
+		err = errors.New("权限不存在")
+		return
+	}
+	// 除了晨报和周报以外的其他报告
+	classifyNames, err := chart_permission_search_key_word_mapping.GetKeyWordsByChartPermissionId(chartPermissionId, "rddp")
+	if err != nil {
+		errMsg = err.Error()
+		err = errors.New("查询权限对应的分类出错")
+		return
+	}
+
+	var classifySecondIds []int
+	if len(classifyNames) > 0 {
+		classifySecondIds, err = classify.GetSecondIdsByClassifyNames(classifyNames)
+		if err != nil {
+			errMsg = err.Error()
+			err = errors.New("查询分类出错")
+			return
+		}
+	}
+
+	// 查询晨报和周报相对应的章节ID
+	reportChapterTypeIds, err := report_chapter_type.GetTypeIDByReportChapterTypeName(permissionInfo.PermissionName)
+	if err != nil {
+		errMsg = err.Error()
+		err = errors.New("查询权限对应的章节出错")
+		return
+	}
+
+	var reportList []*response.ReportCollectListItem
+	var total int64
+	if len(reportChapterTypeIds) > 0 || len(classifySecondIds) > 0 {
+		offset := (pageIndex - 1) * pageSize
+		reportList, err = report.GetReportCollectListByPermission(classifySecondIds, reportChapterTypeIds, offset, pageSize)
+		if err != nil {
+			errMsg = err.Error()
+			err = errors.New("查询报告信息出错")
+			return
+		}
+		total, err = report.GetReportCollectCountByPermission(classifySecondIds, reportChapterTypeIds)
+		if err != nil {
+			errMsg = err.Error()
+			err = errors.New("查询报告总数出错")
+			return
+		}
+	}
+	ret = new(response.ReportCollectResp)
+	ret.List = reportList
+	ret.Paging = response.GetPaging(pageIndex, pageSize, int(total))
+	return
 }
 }