Browse Source

Merge branch 'bzq/dev' of eta_mini/eta_mini_bridge into debug

鲍自强 7 months ago
parent
commit
4649338041
5 changed files with 403 additions and 3 deletions
  1. 300 0
      controllers/report.go
  2. 72 2
      models/report.go
  3. 5 0
      models/response/report.go
  4. 18 0
      routers/commentsRouter.go
  5. 8 1
      routers/router.go

+ 300 - 0
controllers/report.go

@@ -16,6 +16,10 @@ type ReportController struct {
 	BaseAuthController
 }
 
+type ReportNoAuthController struct {
+	BaseCommonController
+}
+
 // @Title List
 // @Description create users
 // @Param   ChartPermissionId   query   int  true       "品种ID"
@@ -731,3 +735,299 @@ func (this *ReportController) Search() {
 	br.Ret = 200
 	br.Success = true
 }
+
+// @Title List
+// @Description create users
+// @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.ReportListResp
+// @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")
+
+	if chartPermissionId <= 0 {
+		br.Msg = "品种参数错误"
+		return
+	}
+	var condition string
+	switch rangeType {
+	case 1:
+		condition += ` AND DATE(modify_time)=DATE(NOW()) `
+	case 2:
+		condition += ` AND DATE(modify_time) BETWEEN DATE_SUB(NOW(),INTERVAL 1 WEEK) AND NOW() `
+	case 3:
+		condition += ` AND DATE(modify_time) BETWEEN DATE_SUB(NOW(),INTERVAL 6 MONTH) AND NOW() `
+	}
+
+	var startSize int
+	if pageSize <= 0 {
+		pageSize = utils.PageSize20
+	}
+	if currentIndex <= 0 {
+		currentIndex = 1
+	}
+	startSize = utils.StartIndex(currentIndex, pageSize)
+	classifyList, err := models.GetClassifyList()
+	if err != nil {
+		br.Msg = "获取数据失败"
+		br.ErrMsg = "获取数据失败,Err:" + err.Error()
+		return
+	}
+	classifyMap := make(map[int]*models.ClassifyView)
+	isHas := false
+	for _, v := range classifyList {
+		if v.Id == classifyId && classifyId != 0 {
+			isHas = true
+		}
+		classifyMap[v.Id] = v
+	}
+	if !isHas && classifyId != 0 {
+		br.Msg = "分类不存在"
+		return
+	}
+	classifyIdMap := make(map[int]struct{})
+	if classifyId > 0 {
+		leafClassifyIds := getLeafClassifyIds(classifyMap, classifyId)
+		for _, v := range leafClassifyIds {
+			classifyIdMap[v] = struct{}{}
+		}
+	}
+	var total int
+	var reportList []*models.ReportPushStatus
+	classifyFirstIds := make([]int, 0)
+	classifySecondIds := make([]int, 0)
+	classifyThirdIds := make([]int, 0)
+	switch level {
+	case 2:
+		classifyIds, err := models.GetClassifyIdsListById(chartPermissionId)
+		if err != nil {
+			br.Msg = "获取报告列表失败"
+			br.ErrMsg = "获取数据失败,Err:" + err.Error()
+			return
+		}
+		if len(classifyIds) == 0 {
+			br.Msg = "该品种下没有绑定分类"
+			br.ErrMsg = "获取数据失败,品种id:" + strconv.Itoa(chartPermissionId)
+			return
+		}
+
+		classifyIds = utils.Unique(classifyIds)
+		// 根据分类筛选报告
+		var selectedClassifyId []int
+		if classifyId > 0 {
+			for _, v := range classifyIds {
+				if _, ok := classifyIdMap[v]; ok {
+					selectedClassifyId = append(selectedClassifyId, v)
+				}
+			}
+		} else {
+			selectedClassifyId = classifyIds
+		}
+
+		classifyList, err := models.GetClassifyListByIds(selectedClassifyId)
+		if err != nil {
+			br.Msg = "获取报告列表失败"
+			br.ErrMsg = "获取数据失败,Err:" + err.Error()
+			return
+		}
+		for _, v := range classifyList {
+			switch v.Level {
+			case 1:
+				classifyFirstIds = append(classifyFirstIds, v.Id)
+			case 2:
+				classifySecondIds = append(classifySecondIds, v.Id)
+			case 3:
+				classifyThirdIds = append(classifyThirdIds, v.Id)
+			}
+		}
+		tmptotal, err := models.GetPushReportCountByClassifyIds(classifyFirstIds, classifySecondIds, classifyThirdIds, condition)
+		if err != nil {
+			br.Msg = "获取数据失败"
+			br.ErrMsg = "获取数据失败,Err:" + err.Error()
+			return
+		}
+		total = tmptotal
+		tmpReportList, err := models.GetPushReportListByClassifyIds(classifyFirstIds, classifySecondIds, classifyThirdIds, condition, startSize, pageSize)
+		if err != nil {
+			br.Msg = "获取报告列表失败"
+			br.ErrMsg = "获取数据失败,Err:" + err.Error()
+			return
+		}
+		reportList = tmpReportList
+	case 1:
+		chartPermissionIds, err := models.GetChildChartPermissionIdsById(chartPermissionId)
+		if err != nil {
+			br.Msg = "获取报告列表失败"
+			br.ErrMsg = "获取数据失败,Err:" + err.Error()
+			return
+		}
+		if len(chartPermissionIds) == 0 {
+			br.Msg = "该品种下没有绑定分类"
+			br.ErrMsg = "获取数据失败,品种id:" + strconv.Itoa(chartPermissionId)
+			return
+		}
+		classifyIds, err := models.GetClassifyIdsListByIds(chartPermissionIds)
+		if err != nil {
+			br.Msg = "获取报告列表失败"
+			br.ErrMsg = "获取报告列表失败,Err:" + err.Error()
+			return
+		}
+		if len(classifyIds) == 0 {
+			br.Msg = "该品种下没有绑定分类"
+			return
+		}
+		classifyIds = utils.Unique(classifyIds)
+		// 根据分类筛选报告
+		var selectedClassifyId []int
+		if classifyId > 0 {
+			for _, v := range classifyIds {
+				if _, ok := classifyIdMap[v]; ok {
+					selectedClassifyId = append(selectedClassifyId, v)
+				}
+			}
+		} else {
+			selectedClassifyId = classifyIds
+		}
+
+		classifyList, err := models.GetClassifyListByIds(selectedClassifyId)
+		if err != nil {
+			br.Msg = "获取报告列表失败"
+			br.ErrMsg = "获取数据失败,Err:" + err.Error()
+			return
+		}
+		for _, v := range classifyList {
+			switch v.Level {
+			case 1:
+				classifyFirstIds = append(classifyFirstIds, v.Id)
+			case 2:
+				classifySecondIds = append(classifySecondIds, v.Id)
+			case 3:
+				classifyThirdIds = append(classifyThirdIds, v.Id)
+			}
+		}
+		tmptotal, err := models.GetPushReportCountByClassifyIds(classifyFirstIds, classifySecondIds, classifyThirdIds, condition)
+		if err != nil {
+			br.Msg = "获取数据失败"
+			br.ErrMsg = "获取数据失败,Err:" + err.Error()
+			return
+		}
+		total = tmptotal
+		tmpReportList, err := models.GetPushReportListByClassifyIds(classifyFirstIds, classifySecondIds, classifyThirdIds, condition, startSize, pageSize)
+		if err != nil {
+			br.Msg = "获取报告列表失败"
+			br.ErrMsg = "获取报告列表失败,Err:" + err.Error()
+			return
+		}
+		reportList = tmpReportList
+	default:
+		br.Msg = "层级参数错误"
+		return
+	}
+
+	page := paging.GetPaging(currentIndex, pageSize, total)
+	resp := new(response.ReportPushListResp)
+	resp.Paging = page
+	resp.List = reportList
+
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "获取成功"
+	br.Data = resp
+}
+
+// @Title 研报详情
+// @Description 研报详情接口
+// @Param   ReportId   query   int  true       "报告id"
+// @Param   UserId   query   int  true       "用户id"
+// @Success 200 {object} response.ReportDetailResp
+// @router /detail [get]
+func (this *ReportNoAuthController) Detail() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	reportId, err := this.GetInt("ReportId")
+	if err != nil {
+		br.Msg = "参数获取失败"
+		br.ErrMsg = "参数获取失败,Err:" + err.Error()
+		return
+	}
+	if reportId <= 0 {
+		br.Msg = "参数错误"
+		br.ErrMsg = "参数错误,报告id小于等于0"
+		return
+	}
+
+	report, err := models.GetReportById(reportId)
+	if err != nil {
+		if err.Error() == utils.ErrNoRow() {
+			br.Ret = 200
+			br.Data = new(response.ReportDetailResp)
+			br.Success = true
+			br.Msg = "该报告已删除或不存在"
+			return
+		}
+		br.Msg = "该报告已删除"
+		br.ErrMsg = "获取报告详情失败,Err:" + err.Error()
+		return
+	}
+	if report.HeadResourceId > 0 || report.EndResourceId > 0 {
+		headImg, err := models.GetSmartReportResourceById(report.HeadResourceId)
+		if err != nil && err.Error() != utils.ErrNoRow() {
+			utils.FileLog.Warn("版头数据获取失败,Err:" + err.Error())
+		}
+		endImg, err := models.GetSmartReportResourceById(report.EndResourceId)
+		if err != nil && err.Error() != utils.ErrNoRow() {
+			utils.FileLog.Warn("版尾数据获取失败,Err:" + err.Error())
+		}
+		if headImg != nil {
+			report.HeadResource = headImg
+		}
+		if endImg != nil {
+			report.EndResource = endImg
+		}
+	}
+
+	if report.HasChapter == 1 {
+		chapterList, err := models.GetReportChapterList(report.Id)
+		if err != nil {
+			br.Msg = "该报告已删除"
+			br.ErrMsg = "获取章节列表失败,Err:" + err.Error()
+			return
+		}
+		for _, v := range chapterList {
+			v.Content = html.UnescapeString(v.Content)
+		}
+		report.ChapterContent = chapterList
+	}
+	report.ContentSub = html.UnescapeString(report.ContentSub)
+	report.Content = html.UnescapeString(report.Content)
+	if report == nil {
+		br.Msg = "报告不存在"
+		return
+	}
+
+	resp := new(response.ReportDetailResp)
+	resp.Report = report
+
+	br.Data = resp
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "获取成功"
+}

+ 72 - 2
models/report.go

@@ -39,6 +39,27 @@ type ReportList struct {
 	ClassifyDetail
 }
 
+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:"推送时间"`
+}
+
 // GetReportDailyListCount 获得今日报告数量
 func GetReportDailyListCount() (count int, err error) {
 	o := orm.NewOrmUsingDB("rddp")
@@ -110,6 +131,55 @@ func GetReportCountByClassifyIds(classifyFirstIds, classifySecondIds, classifyTh
 	return
 }
 
+func GetPushReportCountByClassifyIds(classifyFirstIds, classifySecondIds, classifyThirdIds []int, condition string) (count int, err error) {
+	if len(classifyFirstIds) == 0 && len(classifySecondIds) == 0 && len(classifyThirdIds) == 0 {
+		return
+	}
+	o := orm.NewOrm()
+	sql := `SELECT COUNT(*) AS count FROM report_push_status WHERE state=1 AND report_type=1 AND (1=2 `
+
+	if len(classifyFirstIds) > 0 {
+		sql += fmt.Sprintf(" OR classify_id_first IN (%s) ", utils.GetOrmReplaceHolder(len(classifyFirstIds)))
+	}
+	if len(classifySecondIds) > 0 {
+		sql += fmt.Sprintf(" OR classify_id_second IN (%s) ", utils.GetOrmReplaceHolder(len(classifySecondIds)))
+	}
+	if len(classifyThirdIds) > 0 {
+		sql += fmt.Sprintf(" OR classify_id_third IN (%s) ", utils.GetOrmReplaceHolder(len(classifyThirdIds)))
+	}
+	sql += ` ) `
+	if condition != "" {
+		sql += condition
+	}
+	err = o.Raw(sql, classifyFirstIds, classifySecondIds, classifyThirdIds).QueryRow(&count)
+	return
+}
+
+func GetPushReportListByClassifyIds(classifyFirstIds, classifySecondIds, classifyThirdIds []int, condition string, startSize, pageSize int) (items []*ReportPushStatus, err error) {
+	if len(classifyFirstIds) == 0 && len(classifySecondIds) == 0 && len(classifyThirdIds) == 0 {
+		return
+	}
+	o := orm.NewOrm()
+	sql := `SELECT * FROM report_push_status WHERE state=1 AND report_type=1 AND (1=2 `
+	// AND (a.classify_id_first IN (%s) OR a.classify_id_second IN (%s) OR a.classify_id_third IN (%s)) `
+	if len(classifyFirstIds) > 0 {
+		sql += fmt.Sprintf(" OR classify_id_first IN (%s) ", utils.GetOrmReplaceHolder(len(classifyFirstIds)))
+	}
+	if len(classifySecondIds) > 0 {
+		sql += fmt.Sprintf(" OR classify_id_second IN (%s) ", utils.GetOrmReplaceHolder(len(classifySecondIds)))
+	}
+	if len(classifyThirdIds) > 0 {
+		sql += fmt.Sprintf(" OR classify_id_third IN (%s) ", utils.GetOrmReplaceHolder(len(classifyThirdIds)))
+	}
+	sql += `) `
+	if condition != "" {
+		sql += condition
+	}
+	sql += ` ORDER BY publish_time DESC LIMIT ?,? `
+	_, err = o.Raw(sql, classifyFirstIds, classifySecondIds, classifyThirdIds, startSize, pageSize).QueryRows(&items)
+	return
+}
+
 func GetReportByClassifyIds(classifyIds []int, condition string) (count int, err error) {
 	if len(classifyIds) == 0 {
 		return
@@ -203,14 +273,14 @@ type ReportChapter struct {
 
 func GetReportChapterList(reportId int) (items []*ReportChapter, err error) {
 	o := orm.NewOrmUsingDB("rddp")
-	sql := `SELECT * FROM report_chapter WHERE report_id=?`
+	sql := `SELECT * FROM report_chapter WHERE report_id=? ORDER BY sort ASC`
 	_, err = o.Raw(sql, reportId).QueryRows(&items)
 	return
 }
 
 func GetReportById(reportId int) (item *ReportDetail, err error) {
 	o := orm.NewOrmUsingDB("rddp")
-	sql := `SELECT * FROM report WHERE id=?`
+	sql := `SELECT * FROM report WHERE (state=2 OR state=6) AND id=?`
 	err = o.Raw(sql, reportId).QueryRow(&item)
 	return
 }

+ 5 - 0
models/response/report.go

@@ -11,6 +11,11 @@ type ReportListResp struct {
 	Paging *paging.PagingItem
 }
 
+type ReportPushListResp struct {
+	List   []*models.ReportPushStatus
+	Paging *paging.PagingItem
+}
+
 //	type ReportDetailResp struct {
 //		Report   *models.ReportDetail   `description:"报告"`
 //		Classify *models.ClassifyDetail `description:"对应专栏"`

+ 18 - 0
routers/commentsRouter.go

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

+ 8 - 1
routers/router.go

@@ -49,5 +49,12 @@ func init() {
 			),
 		),
 	)
-	web.AddNamespace(ns)
+	nsNoAuth := web.NewNamespace("/v1/noAuth",
+		web.NSNamespace("/report",
+			web.NSInclude(
+				&controllers.ReportNoAuthController{},
+			),
+		),
+	)
+	web.AddNamespace(ns, nsNoAuth)
 }