瀏覽代碼

add:添加不需要权限的研报接口

zqbao 7 月之前
父節點
當前提交
380a902e61
共有 7 個文件被更改,包括 201 次插入1 次删除
  1. 93 0
      controllers/report.go
  2. 42 0
      models/report_push_status.go
  3. 5 0
      models/response/report.go
  4. 18 0
      routers/commentsRouter.go
  5. 8 1
      routers/router.go
  6. 30 0
      services/report.go
  7. 5 0
      utils/constants.go

+ 93 - 0
controllers/report.go

@@ -15,6 +15,10 @@ type ReportController struct {
 	BaseAuthController
 }
 
+type ReportNoAuthController struct {
+	BaseCommonController
+}
+
 // @Title 研报详情
 // @Description 研报详情接口
 // @Param   ReportId   query   int  true       "报告id"
@@ -744,3 +748,92 @@ func (this *ReportController) Search() {
 	br.Ret = 200
 	br.Success = true
 }
+
+// @Title 研报列表
+// @Description 研报列表
+// @Param   ChartPermissionId   query   int  true       "品种ID"
+// @Param   Level   query   int  true       "品种层级"
+// @Param   PageSize   query   int  true       "每页数据条数"
+// @Param   CurrentIndex   query   int  true       "当前页页码,从1开始"
+// @Param   RangeType   query   string  true       "范围类型,1-一天内,2-一周内,3-半年内"
+// @Param   ClassifyId   query   int  true       "分类id"
+// @Success 200 {object} response.ReportList
+// @router /list [get]
+func (this *ReportNoAuthController) List() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+
+	pageSize, _ := this.GetInt("PageSize")
+	currentIndex, _ := this.GetInt("CurrentIndex")
+	chartPermissionId, _ := this.GetInt("ChartPermissionId")
+	level, _ := this.GetInt("Level")
+	rangeType, _ := this.GetInt("RangeType")
+	classifyId, _ := this.GetInt("ClassifyId")
+	reports, err := services.GetNoAuthReportList(chartPermissionId, level, rangeType, classifyId, currentIndex, pageSize)
+	if err != nil {
+		br.Msg = "研报列表查询失败"
+		br.ErrMsg = "研报列表查询失败,系统异常,Err:" + err.Error()
+		return
+	}
+	if reports.Ret != 200 {
+		br.Msg = reports.Msg
+		br.ErrMsg = reports.ErrMsg
+		return
+	}
+
+	br.Data = reports.Data
+	br.Msg = "查询成功"
+	br.Ret = 200
+	br.Success = true
+}
+
+// @Title 研报详情
+// @Description 研报详情接口
+// @Param   ReportId   query   int  true       "报告id"
+// @Success 200 {object} models.ReportDetailResp
+// @router /detail [get]
+func (this *ReportNoAuthController) Detail() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	reportId, _ := this.GetInt("ReportId")
+	if reportId <= 0 {
+		br.Msg = "报告不存在"
+		return
+	}
+	reportPush, err := models.GetReportPushStatusByReportId(reportId, utils.ReportTypeEta)
+	if err != nil {
+		br.Msg = "查询报告失败"
+		br.ErrMsg = "查询报告推送状态失败,系统异常,Err:" + err.Error()
+		return
+	}
+	if reportPush.State != utils.ReportStatePush {
+		br.Msg = "报告未推送或已删除,请刷新重试"
+		return
+	}
+	result, err := services.GetNoAuthReportDetail(reportId)
+	if err != nil {
+		br.Msg = "查询报告详情失败"
+		br.ErrMsg = "查询报告失败,系统异常,Err:" + err.Error()
+		return
+	}
+	if result.Ret != 200 {
+		br.Msg = result.Msg
+		br.ErrMsg = result.ErrMsg
+		return
+	}
+	if result.Ret == 200 && result.Data.Report == nil {
+		// 报告不存在, 就尝试删除推送的记录
+		models.DeleteReportPushStatusByReportId(reportId, utils.ReportTypeEta)
+	}
+
+	br.Msg = "查询成功"
+	br.Success = true
+	br.Ret = 200
+	br.Data = result.Data
+}

+ 42 - 0
models/report_push_status.go

@@ -0,0 +1,42 @@
+package models
+
+import (
+	"time"
+
+	"github.com/beego/beego/v2/client/orm"
+)
+
+type ReportPushStatus struct {
+	ReportPushStatusId int       `orm:"pk"`
+	ReportId           int       `description:"报告id"`
+	State              int       `description:"报告状态:0-未推送,1-已推送"`
+	Title              string    `description:"报告标题"`
+	Abstract           string    `description:"报告摘要"`
+	Stage              int       `description:"期数"`
+	ClassifyIdFirst    int       `description:"一级分类id"`
+	ClassifyNameFirst  string    `description:"一级分类名称"`
+	ClassifyIdSecond   int       `description:"二级分类id"`
+	ClassifyNameSecond string    `description:"二级分类名称"`
+	ClassifyIdThird    int       `description:"三级分类id"`
+	ClassifyNameThird  string    `description:"三级分类名称"`
+	Author             string    `description:"报告作者"`
+	ReportType         int       `description:"报告类型:1-eta报告"`
+	PublishTime        time.Time `description:"报告发布时间"`
+	CreateTime         time.Time `description:"创建时间"`
+	ModifyTime         time.Time `description:"修改时间"`
+	PushTime           time.Time `description:"推送时间"`
+}
+
+func GetReportPushStatusByReportId(reportId int, reportType int) (item *ReportPushStatus, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT * FROM report_push_status WHERE report_id = ? AND report_type = ?`
+	err = o.Raw(sql, reportId, reportType).QueryRow(&item)
+	return
+}
+
+func DeleteReportPushStatusByReportId(reportId int, reportType int) (err error) {
+	o := orm.NewOrm()
+	sql := `DELETE FROM report_push_status WHERE report_id = ? AND report_type = ?`
+	_, err = o.Raw(sql, reportId, reportType).Exec()
+	return
+}

+ 5 - 0
models/response/report.go

@@ -12,6 +12,11 @@ type ReportList struct {
 	Paging *paging.PagingItem
 }
 
+type ReportPushListResp struct {
+	List   []*models.ReportPushStatus
+	Paging *paging.PagingItem
+}
+
 type ReportResp[T any] struct {
 	Ret    int
 	Data   T

+ 18 - 0
routers/commentsRouter.go

@@ -250,6 +250,24 @@ func init() {
             Filters: nil,
             Params: nil})
 
+    beego.GlobalControllerRouter["eta/eta_mini_api/controllers:ReportNoAuthController"] = append(beego.GlobalControllerRouter["eta/eta_mini_api/controllers:ReportNoAuthController"],
+        beego.ControllerComments{
+            Method: "Detail",
+            Router: `/detail`,
+            AllowHTTPMethods: []string{"get"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
+    beego.GlobalControllerRouter["eta/eta_mini_api/controllers:ReportNoAuthController"] = append(beego.GlobalControllerRouter["eta/eta_mini_api/controllers:ReportNoAuthController"],
+        beego.ControllerComments{
+            Method: "List",
+            Router: `/list`,
+            AllowHTTPMethods: []string{"get"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
     beego.GlobalControllerRouter["eta/eta_mini_api/controllers:UserAuthController"] = append(beego.GlobalControllerRouter["eta/eta_mini_api/controllers:UserAuthController"],
         beego.ControllerComments{
             Method: "AddReportRecord",

+ 8 - 1
routers/router.go

@@ -64,5 +64,12 @@ func init() {
 			),
 		),
 	)
-	beego.AddNamespace(ns)
+	h5ns := beego.NewNamespace("/api/h5",
+		beego.NSNamespace("/report",
+			beego.NSInclude(
+				&controllers.ReportNoAuthController{},
+			),
+		),
+	)
+	beego.AddNamespace(ns, h5ns)
 }

+ 30 - 0
services/report.go

@@ -39,6 +39,36 @@ func GetReportList(chartPermissionId, level, rangeType, classifyId, currentIndex
 	return
 }
 
+func GetNoAuthReportList(chartPermissionId, level, rangeType, classifyId, currentIndex, pageSize int) (resp *resp2.ReportResp[resp2.ReportPushListResp], err error) {
+	url := utils.ETA_MINI_BRIDGE_URL + "/noAuth/report/list?"
+	url += fmt.Sprintf("RangeType=%d&ChartPermissionId=%d&Level=%d&PageSize=%d&CurrentIndex=%d&ClassifyId=%d", rangeType, chartPermissionId, level, pageSize, currentIndex, classifyId)
+	fmt.Println(url)
+	body, err := HttpGet(url)
+	if err != nil {
+		return
+	}
+	err = json.Unmarshal(body, &resp)
+	if err != nil {
+		return
+	}
+	return
+}
+
+func GetNoAuthReportDetail(reportId int) (resp *resp2.ReportResp[resp2.ReportDetailResp], err error) {
+	url := utils.ETA_MINI_BRIDGE_URL + "/noAuth/report/detail?"
+	url += fmt.Sprintf("ReportId=%d", reportId)
+	fmt.Println(url)
+	body, err := HttpGet(url)
+	if err != nil {
+		return
+	}
+	err = json.Unmarshal(body, &resp)
+	if err != nil {
+		return
+	}
+	return
+}
+
 func GetReportDetail(reportId, userId int) (resp *resp2.ReportResp[resp2.ReportDetailResp], err error) {
 	url := utils.ETA_MINI_BRIDGE_URL + "/report/detail?"
 	url += fmt.Sprintf("ReportId=%d&UserId=%d", reportId, userId)

+ 5 - 0
utils/constants.go

@@ -15,6 +15,11 @@ const (
 	ReportPermissionStatusNoUser       = 5 //没有获得用户信息
 )
 
+const (
+	ReportStatePushCancel = 0 // 未推送
+	ReportStatePush       = 1 // 已推送
+)
+
 // 用户状态定义
 const (
 	UserStatusNo        = 0 //禁用