ziwen hace 2 años
padre
commit
f0484ce8ca
Se han modificado 5 ficheros con 193 adiciones y 6 borrados
  1. 13 0
      controller/pc/pc.go
  2. 32 6
      models/response/pc/classify.go
  3. 16 0
      models/response/pc/report.go
  4. 1 0
      routers/pc.go
  5. 131 0
      services/pc/classify.go

+ 13 - 0
controller/pc/pc.go

@@ -160,3 +160,16 @@ func Recommend(c *gin.Context)  {
 	response.OkData("查询成功", recommendList, c )
 	return
 }
+
+// ClassifyFirstList Ficc 菜单
+func ClassifyFirstList(c *gin.Context)  {
+	userinfo := userService.GetInfoByClaims(c)
+
+	classList, err := pc.GetClassifyFirstList(userinfo)
+	if err != nil {
+		response.Fail(err.Error(), c)
+		return
+	}
+	response.OkData("查询成功", classList, c )
+	return
+}

+ 32 - 6
models/response/pc/classify.go

@@ -18,11 +18,37 @@ type ClassifyListItem struct {
 
 type ClassifyDetail struct {
 	ClassifyListItem
-	Comments []*customer_comment.CustomerComment
-	AvatarImgUrl    string               `json:"avatar_img_url"`
-	Abstract        string               `json:"abstract"`
-	Descript        string               `json:"descript"`
+	Comments        []*customer_comment.CustomerComment
+	AvatarImgUrl    string                        `json:"avatar_img_url"`
+	Abstract        string                        `json:"abstract"`
+	Descript        string                        `json:"descript"`
 	PermissionCheck *response.PermissionCheckInfo `json:"permission_check"`
-	AuthOk          bool                 `json:"auth_ok"`
-	VipTitle        string               `json:"vip_title"'`
+	AuthOk          bool                          `json:"auth_ok"`
+	VipTitle        string                        `json:"vip_title"'`
 }
+
+type ClassifyFirstListItem struct {
+	ClassifyIdFirst    int    `description:"一级分类id" json:"classify_id_first"`
+	Latest             int    `description:"最新更新" json:"latest"`
+	ClassifyIdSecond   int    `json:"classify_id_second"`
+	ClassifyNameFirst  string `description:"一级分类名称" json:"classify_name_first"`
+	ClassifyNameSecond string `json:"classify_name_second"`
+	BackImgUrl         string `json:"back_img_url"`
+	Sort               int    `json:"sort"`
+	RedirectType       int    `description:"跳转页面类型:1,专栏列表,2报告列表,3专栏详情" json:"redirect_type"`
+}
+
+type ClassifyFirstList []*ClassifyFirstListItem
+
+func (c ClassifyFirstList) Len() int {
+	return len(c)
+}
+
+func (c ClassifyFirstList) Less(i, j int) bool {
+	return c[i].Sort < c[j].Sort
+}
+
+func (c ClassifyFirstList) Swap(i, j int) {
+	c[i], c[j] = c[j], c[i]
+}
+

+ 16 - 0
models/response/pc/report.go

@@ -45,4 +45,20 @@ func GetRecommendList(reportId, reportType int) (items []*RecommendReport, err e
 	sql += ` ORDER BY publish_time DESC LIMIT 3`
 	err = global.MYSQL["rddp"].Raw(sql).Scan(&items).Error
 	return
+}
+
+type LatestReport struct {
+	Id                 int    `orm:"column(id)" description:"报告Id" json:"_"`
+	ClassifyNameFirst  string `description:"一级分类名称" json:"classify_name_first"`
+	Title              string `description:"标题" json:"title"`
+	State              int    `description:"1:未发布,2:已发布" json:"state"`
+	PublishTime        time.Time `description:"发布时间" json:"publish_time"`
+	Stage              int    `description:"期数" json:"stage"`
+}
+
+func GetLatestStage(classifyNames []string) (items []*LatestReport, err error){
+	sql := `SELECT id,classify_name_first,title,state,publish_time,stage FROM report WHERE classify_name_first IN (?) GROUP BY classify_name_first ORDER BY publish_time DESC`
+	fmt.Println(sql)
+	err = global.MYSQL["rddp"].Raw(sql,classifyNames).Scan(&items).Error
+	return
 }

+ 1 - 0
routers/pc.go

@@ -14,4 +14,5 @@ func InitPc(r *gin.Engine)  {
 	rGroup.GET("/detail", pc.ClassifyDetail)
 	rGroup.GET("/detail_banner", pc.ClassifyDetailBanner)
 	rGroup.GET("/recommend", pc.Recommend)
+	rGroup.GET("/classify", pc.ClassifyFirstList)
 }

+ 131 - 0
services/pc/classify.go

@@ -0,0 +1,131 @@
+package pc
+
+import (
+	"errors"
+	"fmt"
+	"hongze/hongze_yb/global"
+	"hongze/hongze_yb/models/response/pc"
+	"hongze/hongze_yb/models/tables/rddp/classify"
+	"hongze/hongze_yb/services/user"
+	"hongze/hongze_yb/utils"
+	"sort"
+)
+
+// GetClassifyFirstList 获取一级分类列表
+func GetClassifyFirstList(user user.UserInfo) (list pc.ClassifyFirstList, err error) {
+	var errMsg string
+	defer func() {
+		if err != nil {
+			global.LOG.Critical(fmt.Sprintf("GetClassifyFirstList: userId=%d, err:%s, errMsg:%s", user.UserID, err.Error(), errMsg))
+		}
+	}()
+
+	classifyParents, err := classify.GetParentList()
+	if err != nil {
+		errMsg = err.Error()
+		err = errors.New("分类查询出错")
+		return
+	}
+	if len(classifyParents) == 0 {
+		err = errors.New("分类不存在")
+		return
+	}
+
+	// 当前版本一级分类固定
+	classifyIconMap := map[string]string{
+		"晨报": utils.ALIYUN_YBIMG_HOST + "ficc_icon_day_128.png",
+		"周报": utils.ALIYUN_YBIMG_HOST + "ficc_icon_week_128.png",
+		"双周报": utils.ALIYUN_YBIMG_HOST + "ficc_icon_two_week_128.png",
+		"月报": utils.ALIYUN_YBIMG_HOST + "ficc_icon_month_128.png",
+		"草根调研": utils.ALIYUN_YBIMG_HOST + "ficc_icon_grassroots_128.png",
+		"需求报告": utils.ALIYUN_YBIMG_HOST + "ficc_icon_need_report_128.png",
+		"宏观报告": utils.ALIYUN_YBIMG_HOST + "ficc_icon_hongguan_128.png",
+		"日度点评": utils.ALIYUN_YBIMG_HOST + "ficc_icon_daily_comment_128.png",
+		"数据点评": utils.ALIYUN_YBIMG_HOST + "ficc_icon_data_128.png",
+		"碳市场价格周报": utils.ALIYUN_YBIMG_HOST + "ficc_icon_rcarbon_128.png",
+		"行业调研": utils.ALIYUN_YBIMG_HOST + "ficc_icon_research_128.png",
+		"海外视角": utils.ALIYUN_YBIMG_HOST + "ficc_icon_overseas_128.png",
+		"百家谈": utils.ALIYUN_YBIMG_HOST + "ficc_icon_family_128.png",
+		"会议纪要": utils.ALIYUN_YBIMG_HOST + "ficc_icon_meeting_128.png",
+		"大事点评":  utils.ALIYUN_YBIMG_HOST + "ficc_icon_big_thing_128.png",
+		"年报合集": utils.ALIYUN_YBIMG_HOST + "ficc_icon_year_collect_128.png",
+	}
+
+	classifySortMap := map[string]int{
+		"晨报": 1,
+		"周报": 2,
+		"双周报": 3,
+		"月报": 4,
+		"草根调研": 5,
+		"需求报告": 6,
+		"宏观报告": 7,
+		"日度点评": 8,
+		"数据点评": 9,
+		"碳市场价格周报": 10,
+		"行业调研": 11,
+		"海外视角": 12,
+		"百家谈": 13,
+		"会议纪要": 14,
+		"大事点评":  15,
+		"年报合集": 16,
+	}
+	names := []string{
+		"晨报",
+		"周报",
+		"双周报",
+		"月报",
+		"草根调研",
+		"需求报告",
+		"宏观报告",
+		"日度点评",
+		"数据点评",
+		"碳市场价格周报",
+		"行业调研",
+		"海外视角",
+		"百家谈",
+		"会议纪要",
+		"大事点评",
+		"年报合集",
+	}
+	reportList,err := pc.GetLatestStage(names)
+	if err != nil {
+		errMsg = err.Error()
+		err = errors.New("报告查询出错")
+		return
+	}
+	for _, item := range classifyParents {
+		temp := new(pc.ClassifyFirstListItem)
+		temp.ClassifyIdFirst = item.Id
+		temp.ClassifyNameFirst = item.ClassifyName
+		temp.BackImgUrl = classifyIconMap[item.ClassifyName]
+		temp.Sort = classifySortMap[item.ClassifyName]
+		if temp.Sort == 0 {
+			continue
+		}
+		// ShowType展示类型:1-列表 2-专栏; RedirectType跳转类型:1-专栏列表 2-报告列表 3-专栏详情
+		temp.RedirectType = 2
+		if item.ShowType == 2 {
+			temp.RedirectType = 1
+			classifyChild, _ := classify.GetChildByPid(item.Id)
+			if classifyChild != nil && len(classifyChild) == 1 {
+				// 存在二级分类且仅有一个时直接跳转专栏详情
+				temp.ClassifyIdSecond = classifyChild[0].Id
+				temp.ClassifyNameSecond = classifyChild[0].ClassifyName
+				temp.RedirectType = 3
+			}
+		}
+		list = append(list, temp)
+	}
+	for _, item := range list {
+		for _, report := range reportList {
+			if report.ClassifyNameFirst == item.ClassifyNameFirst {
+				item.Latest = report.Stage
+			}
+		}
+	}
+	if len(list) > 0 {
+		sort.Sort(list)
+	}
+
+	return
+}