Browse Source

Merge branch 'bzq/dev' of eta_mini/eta_mini_api into master

鲍自强 7 months ago
parent
commit
2b4130852f

+ 89 - 0
controllers/chart_permission.go

@@ -10,6 +10,10 @@ type ChartPermissionController struct {
 	BaseAuthController
 }
 
+type ChartPermissionNoAuthController struct {
+	BaseCommonController
+}
+
 // List
 // @Title 系统品种列表
 // @Description 系统品种列表
@@ -105,3 +109,88 @@ func (this *ChartPermissionController) ClassifyTree() {
 	br.Success = true
 	br.Ret = 200
 }
+
+// ClassifyTree
+// @Title 获取品种下的分类权限列表
+// @Description 获取研报的品种权限列表
+// @Param   ChartPermissionId   query   int  true       "品种权限id"
+// @Success 200 {object} []models.ChartPermission
+// @router /classify/tree [get]
+func (this *ChartPermissionNoAuthController) ClassifyTree() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	chartPermissionId, _ := this.GetInt("ChartPermissionId")
+	if chartPermissionId < 0 {
+		br.Msg = "品种权限异常"
+		return
+	}
+	resp, err := services.GetClassifyTreeByChartPermission(chartPermissionId)
+	if err != nil {
+		br.Msg = "获取分类失败"
+		br.ErrMsg = "品种权限获取失败,系统错误,Err:" + err.Error()
+		return
+	}
+	if resp.Ret != 200 {
+		br.Msg = resp.Msg
+		br.ErrMsg = resp.ErrMsg
+		return
+	}
+	classifyList := resp.Data
+
+	br.Data = classifyList
+	br.Msg = "获取成功"
+	br.Success = true
+	br.Ret = 200
+}
+
+// List
+// @Title 系统品种列表
+// @Description 系统品种列表
+// @Param   chartPermissonId   query   int  true       "品种权限id"
+// @Success 200 {object} models.LoginResp
+// @router /list [get]
+func (this *ChartPermissionNoAuthController) List() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	id, _ := this.GetInt("chartPermissonId", 0)
+
+	var resp *models.ChartPermissionResp[[]*models.ChartPermission]
+	var err error
+	if id == 0 {
+		resp, err = services.GetChartPermissionList()
+	} else if id > 0 {
+		resp, err = services.GetChartPermissionSecondList(id)
+	}
+	if err != nil {
+		br.Msg = "权限列表获取失败"
+		br.ErrMsg = "权限列表获取失败,系统错误,Err:" + err.Error()
+		return
+	}
+	if resp.Ret != 200 {
+		br.Msg = resp.Msg
+		br.ErrMsg = resp.ErrMsg
+		return
+	}
+	chartPermissionList := make([]*models.ChartPermissionView, 0)
+	for _, item := range resp.Data {
+		chartPermissionList = append(chartPermissionList, &models.ChartPermissionView{
+			ChartPermissionId:   item.ChartPermissionId,
+			PermissionName:      item.PermissionName,
+			Remark:              item.Remark,
+			ImageUrl:            item.ImageUrl,
+			ChartPermissionType: utils.PermissionTypeEta,
+		})
+
+	}
+
+	br.Ret = 200
+	br.Data = chartPermissionList
+	br.Msg = "列表获取成功"
+	br.Success = true
+}

+ 162 - 0
controllers/report.go

@@ -6,6 +6,7 @@ import (
 	"eta/eta_mini_api/services"
 	"eta/eta_mini_api/utils"
 	"sort"
+	"strconv"
 	"time"
 
 	"github.com/rdlucklib/rdluck_tools/paging"
@@ -15,6 +16,10 @@ type ReportController struct {
 	BaseAuthController
 }
 
+type ReportNoAuthController struct {
+	BaseCommonController
+}
+
 // @Title 研报详情
 // @Description 研报详情接口
 // @Param   ReportId   query   int  true       "报告id"
@@ -744,3 +749,160 @@ 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 = "报告已删除或未发布,请刷新重试"
+		return
+	}
+
+	br.Msg = "查询成功"
+	br.Success = true
+	br.Ret = 200
+	br.Data = result.Data
+}
+
+// @Title 研报搜索
+// @Description 研报搜索
+// @Param   KeyWord   query   string  true       "每页数据条数"
+// @Param   PageSize   query   int  true       "每页数据条数"
+// @Param   CurrentIndex   query   int  true       "当前页页码,从1开始"
+// @Success 200 {object} models.ReportDetailResp
+// @router /search [get]
+func (this *ReportNoAuthController) Search() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+
+	keyWord := this.GetString("KeyWord")
+	pageSize, _ := this.GetInt("PageSize")
+	currentIndex, _ := this.GetInt("CurrentIndex")
+	if pageSize <= 0 {
+		pageSize = utils.PageSize30
+	}
+
+	if keyWord == "" {
+		br.Msg = "请输入关键字"
+		return
+	}
+
+	reports, total, err := services.SearchReportPush(keyWord, currentIndex, pageSize)
+	if err != nil {
+		br.Msg = "研报列表查询失败"
+		br.ErrMsg = "研报列表查询失败,系统异常,Err:" + err.Error()
+		return
+	}
+	resp := new(response.ReportSearchViewResp)
+	list := make([]*response.ReportSearchListView, 0)
+	for _, v := range reports {
+		tmpReport := &response.ReportSearchListView{
+			ReportId:           v.ReportId,
+			ClassifyIdFirst:    v.ClassifyIdFirst,
+			ClassifyNameFirst:  v.ClassifyNameFirst,
+			ClassifyIdSecond:   v.ClassifyIdSecond,
+			ClassifyNameSecond: v.ClassifyNameSecond,
+			ClassifyIdThird:    v.ClassifyIdThird,
+			ClassifyNameThird:  v.ClassifyNameThird,
+			PublishTime:        v.PublishTime.Format(utils.FormatDate),
+			Title:              v.Title,
+			Abstract:           v.Abstract,
+			Stage:              strconv.Itoa(v.Stage),
+			Author:             v.Author,
+			ReportType:         v.ReportType,
+		}
+		if v.PublishTime.IsZero() {
+			tmpReport.PublishTime = ""
+		}
+		list = append(list, tmpReport)
+	}
+
+	page := paging.GetPaging(currentIndex, pageSize, total)
+	resp.List = list
+	resp.Paging = page
+
+	br.Data = resp
+	br.Msg = "查询成功"
+	br.Ret = 200
+	br.Success = true
+}

+ 84 - 0
models/report_push_status.go

@@ -0,0 +1,84 @@
+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:"推送时间"`
+}
+
+type ReportPushView struct {
+	ReportPushStatusId int    `orm:"pk"`
+	ReportId           int    `description:"报告id"`
+	Title              string `description:"报告标题"`
+	Abstract           string `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:"报告作者"`
+	Stage              int    `description:"期数"`
+	State              int    `description:"报告状态:0-未推送,1-已推送"`
+	PushTime           string `description:"推送时间"`
+	PublishTime        string `description:"报告发布时间"`
+	ReportType         int    `description:"报告类型:1-eta报告"`
+	CreateTime         string `description:"创建时间"`
+	ModifyTime         string `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 GetReportPushStatusCountByCondition(condition string, pars []interface{}) (count int, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT COUNT(*) AS count FROM report_push_status WHERE 1=1 AND state=1 `
+	if condition != "" {
+		sql += condition
+	}
+	err = o.Raw(sql, pars...).QueryRow(&count)
+	return
+}
+
+func GetReportPushStatusByCondition(condition string, pars []interface{}, startSize int, pageSize int) (items []*ReportPushStatus, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT * FROM report_push_status WHERE 1=1 AND state=1 `
+	if condition != "" {
+		sql += condition
+	}
+	sql += ` ORDER BY publish_time DESC LIMIT ?,?`
+	_, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
+	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.ReportPushView
+	Paging *paging.PagingItem
+}
+
 type ReportResp[T any] struct {
 	Ret    int
 	Data   T

+ 45 - 0
routers/commentsRouter.go

@@ -61,6 +61,24 @@ func init() {
             Filters: nil,
             Params: nil})
 
+    beego.GlobalControllerRouter["eta/eta_mini_api/controllers:ChartPermissionNoAuthController"] = append(beego.GlobalControllerRouter["eta/eta_mini_api/controllers:ChartPermissionNoAuthController"],
+        beego.ControllerComments{
+            Method: "ClassifyTree",
+            Router: `/classify/tree`,
+            AllowHTTPMethods: []string{"get"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
+    beego.GlobalControllerRouter["eta/eta_mini_api/controllers:ChartPermissionNoAuthController"] = append(beego.GlobalControllerRouter["eta/eta_mini_api/controllers:ChartPermissionNoAuthController"],
+        beego.ControllerComments{
+            Method: "List",
+            Router: `/list`,
+            AllowHTTPMethods: []string{"get"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
     beego.GlobalControllerRouter["eta/eta_mini_api/controllers:MiniConfigController"] = append(beego.GlobalControllerRouter["eta/eta_mini_api/controllers:MiniConfigController"],
         beego.ControllerComments{
             Method: "MiniConfig",
@@ -250,6 +268,33 @@ 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:ReportNoAuthController"] = append(beego.GlobalControllerRouter["eta/eta_mini_api/controllers:ReportNoAuthController"],
+        beego.ControllerComments{
+            Method: "Search",
+            Router: `/search`,
+            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",

+ 13 - 1
routers/router.go

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

+ 50 - 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)
@@ -114,3 +144,23 @@ func SearchReport(keyWord string, currentIndex, pageSize int) (resp *resp2.Repor
 	return
 
 }
+
+func SearchReportPush(keyWord string, startSize, pageSize int) (items []*models.ReportPushStatus, total int, err error) {
+	if keyWord == "" {
+		return
+	}
+
+	var pars []interface{}
+	condition := `AND title LIKE ?`
+	pars = append(pars, utils.GetLikeKeywordPars(pars, keyWord, 1))
+	total, err = models.GetReportPushStatusCountByCondition(condition, pars)
+	if err != nil {
+		return
+	}
+
+	items, err = models.GetReportPushStatusByCondition(condition, pars, startSize, pageSize)
+	if err != nil {
+		return
+	}
+	return
+}

+ 5 - 0
utils/constants.go

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