Browse Source

fix:添加最新研报接口

zqbao 9 months ago
parent
commit
0aed0b9390
4 changed files with 135 additions and 12 deletions
  1. 0 2
      controllers/chart.go
  2. 109 10
      controllers/report.go
  3. 17 0
      models/report.go
  4. 9 0
      routers/commentsRouter.go

+ 0 - 2
controllers/chart.go

@@ -17,7 +17,6 @@ type ChartController struct {
 // @Param   PageSize   query   int  true       "每页数据条数"
 // @Param   CurrentIndex   query   int  true       "当前页页码,从1开始"
 // @Success 200 {object} models.BaseResponse
-// @Failure 403 {object} models.BaseResponse
 // @router /list [get]
 func (this *ChartController) List() {
 	br := new(models.BaseResponse).Init()
@@ -66,7 +65,6 @@ func (this *ChartController) List() {
 // @Param   ChartInfoId   query   int  true       "图表详情id"
 // @Param    UniqueCode  query   string  true       "图表唯一id"
 // @Success 200 {object} models.BaseResponse
-// @Failure 403 {object} models.BaseResponse
 // @router /detail [get]
 func (this *ChartController) Detail() {
 	br := new(models.BaseResponse).Init()

+ 109 - 10
controllers/report.go

@@ -23,8 +23,7 @@ type ReportController struct {
 // @Param   PageSize   query   int  true       "每页数据条数"
 // @Param   CurrentIndex   query   int  true       "当前页页码,从1开始"
 // @Param   RangeType   query   string  true       "范围类型,1-一天内,2-一周内,3-半年内"
-// @Success 200 {int} models.User.Id
-// @Failure 403 body is empty
+// @Success 200 {object} response.ReportListResp
 // @router /list [get]
 func (this *ReportController) List() {
 	br := new(models.BaseResponse).Init()
@@ -147,7 +146,7 @@ func (this *ReportController) List() {
 // @Description 研报详情接口
 // @Param   ReportId   query   int  true       "报告id"
 // @Param   UserId   query   int  true       "用户id"
-// @Success 200 {object} models.ReportDetailResp
+// @Success 200 {object} response.ReportDetailResp
 // @router /detail [get]
 func (this *ReportController) Detail() {
 	br := new(models.BaseResponse).Init()
@@ -311,7 +310,7 @@ func (this *ReportController) Detail() {
 // @Title 研报详情
 // @Description 研报详情接口
 // @Param   ReportId   query   int  true       "报告id"
-// @Success 200 {object} models.ReportDetailResp
+// @Success 200 {object} response.ReportDetailResp
 // @router /detail/noUser [get]
 func (this *ReportController) DetailNoUser() {
 	br := new(models.BaseResponse).Init()
@@ -360,11 +359,11 @@ func (this *ReportController) DetailNoUser() {
 	br.Msg = "获取成功"
 }
 
-// @Title List
-// @Description create users
-// @Param	body		body 	models.User	true		"body for user content"
-// @Success 200 {int} models.User.Id
-// @Failure 403 body is empty
+// @Title 今日研报列表
+// @Description 今日研报列表
+// @Param   PageSize   query   int  true       "每页数据条数"
+// @Param   CurrentIndex   query   int  true       "当前页页码,从1开始"
+// @Success 200 {object} response.ReportListResp
 // @router /daily/list [get]
 func (this *ReportController) Today() {
 	br := new(models.BaseResponse).Init()
@@ -460,12 +459,112 @@ func (this *ReportController) Today() {
 	br.Data = resp
 }
 
+// @Title 最新研报列表
+// @Description 最新研报列表
+// @Param   PageSize   query   int  true       "每页数据条数"
+// @Param   CurrentIndex   query   int  true       "当前页页码,从1开始"
+// @Success 200 {object} response.ReportListResp
+// @router /recent/list [get]
+func (this *ReportController) RecentList() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+
+	pageSize, _ := this.GetInt("PageSize")
+	currentIndex, _ := this.GetInt("CurrentIndex")
+
+	var startSize int
+	if pageSize <= 0 {
+		pageSize = utils.PageSize30
+	}
+	if currentIndex <= 0 {
+		currentIndex = 1
+	}
+	startSize = utils.StartIndex(currentIndex, pageSize)
+
+	total, err := models.GetReportDailyListCount()
+	if err != nil {
+		br.Msg = "获取数据失败"
+		br.ErrMsg = "获取数据失败,Err:" + err.Error()
+		return
+	}
+
+	list, err := models.GetReportRecentList(startSize, pageSize)
+	if err != nil {
+		br.Msg = "获取失败"
+		br.ErrMsg = "获取失败,Err:" + err.Error()
+		return
+	}
+	classifyIds := make([]string, 0)
+	for _, v := range list {
+		classifyIds = append(classifyIds, strconv.Itoa(v.ClassifyIdSecond))
+	}
+	classifyIds = utils.Unique(classifyIds)
+	// 获取二级分类和二级品种权限的映射
+	chartPermissionMapping, err := models.GetChartPermissionIdsListByClassifyIds(classifyIds)
+	if err != nil {
+		br.Msg = "获取研报权限失败"
+		br.ErrMsg = "获取研报权限失败,Err:" + err.Error()
+		return
+	}
+	classifyToPermissionMap2 := make(map[int][]int)
+	chartPermissionIds := make([]string, 0)
+	for _, v := range chartPermissionMapping {
+		classifyToPermissionMap2[v.ClassifyId] = append(classifyToPermissionMap2[v.ClassifyId], v.ChartPermissionId)
+		chartPermissionIds = append(chartPermissionIds, strconv.Itoa(v.ChartPermissionId))
+	}
+	// 获取二级品种的权限,并建立映射
+	chartPermissionList2, err := models.GetParentChartPermissionListByIds(chartPermissionIds)
+	if err != nil {
+		br.Msg = "获取研报二级品种权限失败"
+		br.ErrMsg = "获取研报二级品种权限失败,Err:" + err.Error()
+		return
+	}
+	chartPermissionViewMap2 := make(map[int]*models.ChartPermission)
+	for _, v := range chartPermissionList2 {
+		chartPermissionViewMap2[v.ChartPermissionId] = v
+	}
+	// 获取一级品种的权限,并建立映射
+	chartPermissionList1, err := models.GetChildChartPermissionListById(0)
+	if err != nil {
+		br.Msg = "获取研报一级品种权限失败"
+		br.ErrMsg = "获取研报一级品种权限失败,Err:" + err.Error()
+		return
+	}
+	chartPermissionMap1 := make(map[int]*models.ChartPermission)
+	for _, v := range chartPermissionList1 {
+		chartPermissionMap1[v.ChartPermissionId] = v
+	}
+	// 组合数据
+	for _, v := range list {
+		var permissionNames []string
+		for _, vv := range classifyToPermissionMap2[v.ClassifyIdSecond] {
+			parent2 := chartPermissionViewMap2[vv].ParentId
+			permissionNames = append(permissionNames, chartPermissionMap1[parent2].PermissionName)
+		}
+		v.PermissionNames = utils.Unique(permissionNames)
+	}
+
+	page := paging.GetPaging(currentIndex, pageSize, total)
+
+	resp := new(response.ReportListResp)
+	resp.Paging = page
+	resp.List = list
+
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "获取成功"
+	br.Data = resp
+}
+
 // @Title 研报搜索
 // @Description 研报搜索
 // @Param   PageSize   query   int  true       "每页数据条数"
 // @Param   CurrentIndex   query   int  true       "当前页页码,从1开始"
 // @Param   KeyWord   query   string  true       "关键字"
-// @Success 200 {object} models.ReportDetailResp
+// @Success 200 {object} response.ReportSearchResp
 // @router /search [get]
 func (this *ReportController) Search() {
 	br := new(models.BaseResponse).Init()

+ 17 - 0
models/report.go

@@ -62,6 +62,23 @@ func GetReportDailyList(startSize, pageSize int) (items []*ReportList, err error
 	return
 }
 
+func GetReportRecentList(startSize, pageSize int) (items []*ReportList, err error) {
+	o := orm.NewOrmUsingDB("rddp")
+	sql := ` SELECT a.id,a.add_type,a.classify_id_first,a.classify_name_first,a.classify_id_second,a.classify_name_second,a.title,a.abstract,a.author,a.frequency,
+			a.create_time,a.modify_time,a.state,a.publish_time,a.stage,a.msg_is_send,b.id AS classify_id,b.classify_name,b.descript,b.report_author,b.author_descript,
+            b.report_img_url,b.head_img_url,b.avatar_img_url,b.column_img_url,a.video_url,a.video_name,a.video_play_seconds,a.video_size,
+            CASE WHEN DATE(a.modify_time)=DATE(NOW()) THEN 1 ELSE 0 END AS is_current_date
+            FROM report AS a
+			INNER JOIN  classify AS b ON a.classify_id_second=b.id
+			WHERE (a.state=2 OR a.state=6) AND a.classify_id_second IN (
+				SELECT DISTINCT classify_id
+				FROM chart_permission_search_key_word_mapping
+			)
+			ORDER BY  a.publish_time DESC LIMIT ?,?  `
+	_, err = o.Raw(sql, startSize, pageSize).QueryRows(&items)
+	return
+}
+
 func GetReportCountByClassifyIds(classifyIds []string, condition string) (count int, err error) {
 	o := orm.NewOrmUsingDB("rddp")
 	sql := `SELECT  COUNT(*) AS count  FROM report AS a

+ 9 - 0
routers/commentsRouter.go

@@ -115,6 +115,15 @@ func init() {
             Filters: nil,
             Params: nil})
 
+    beego.GlobalControllerRouter["eta/eta_mini_bridge/controllers:ReportController"] = append(beego.GlobalControllerRouter["eta/eta_mini_bridge/controllers:ReportController"],
+        beego.ControllerComments{
+            Method: "RecentList",
+            Router: `/recent/list`,
+            AllowHTTPMethods: []string{"get"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
     beego.GlobalControllerRouter["eta/eta_mini_bridge/controllers:ReportController"] = append(beego.GlobalControllerRouter["eta/eta_mini_bridge/controllers:ReportController"],
         beego.ControllerComments{
             Method: "Search",