Browse Source

新增分享接口

rdluck 4 years ago
parent
commit
c76ff15e4f
2 changed files with 21 additions and 33 deletions
  1. 9 33
      controllers/report_share.go
  2. 12 0
      models/report.go

+ 9 - 33
controllers/report_share.go

@@ -13,8 +13,8 @@ type ReportShareController struct {
 
 // @Title 日评详情
 // @Description 日评详情接口
-// @Param   ReportId   query   int  true       "报告id"
-// @Success 200 {object} models.ReportDetailResp
+// @Param   ReportCode   query   string  true       "报告唯一编码"
+// @Success 200 {object} models.ReportShareDetailResp
 // @router /share/detail [get]
 func (this *ReportShareController) Detail() {
 	br := new(models.BaseResponse).Init()
@@ -23,49 +23,25 @@ func (this *ReportShareController) Detail() {
 		this.ServeJSON()
 	}()
 
-	var status int
-	var msg string
-	reportId, err := this.GetInt("ReportId")
-	if err != nil {
-		br.Msg = "参数获取失败"
-		br.ErrMsg = "参数获取失败,Err:" + err.Error()
-		return
-	}
-	if reportId <= 0 {
+	reportCode:= this.GetString("ReportCode")
+
+	if reportCode =="" {
 		br.Msg = "参数错误"
-		br.ErrMsg = "参数错误,报告id小于等于0"
+		br.ErrMsg = "参数错误,reportCode 为空"
 		return
 	}
-	report, err := models.GetReportById(reportId)
+	report, err := models.GetReportByCode(reportCode)
 	if err != nil {
 		br.Msg = "获取报告详情失败"
 		br.ErrMsg = "获取报告详情失败,Err:" + err.Error()
 		return
 	}
-	if report == nil {
-		status = 1
-		msg = "报告不存在"
-	}
+
 	report.ContentSub = html.UnescapeString(report.ContentSub)
 	report.Content = html.UnescapeString(report.Content)
 
-	resp := new(models.ReportDetailResp)
-	resp.Status = status
-	resp.Msg = msg
+	resp := new(models.ReportShareDetailResp)
 	resp.Report = report
-	recommendList, err := models.GetRecommendList(reportId)
-	if err != nil {
-		br.Msg = "获取报告详情失败"
-		br.ErrMsg = "获取报告推荐列表信息失败,Err:" + err.Error()
-		return
-	}
-	recommendListLen := len(recommendList)
-	for i := 0; i < recommendListLen; i++ {
-		item := recommendList[i]
-		recommendList[i].Content = html.UnescapeString(item.Content)
-		recommendList[i].ContentSub = html.UnescapeString(item.ContentSub)
-	}
-	resp.RecommendList = recommendList
 	br.Ret = 200
 	br.Success = true
 	br.Msg = "获取成功"

+ 12 - 0
models/report.go

@@ -162,3 +162,15 @@ func GetRecommendList(reportId int) (items []*RecommendReport, err error) {
 	_, err = o.Raw(sql, reportId).QueryRows(&items)
 	return
 }
+
+func GetReportByCode(reportCode string) (item *Report, err error) {
+	o := orm.NewOrm()
+	o.Using("rddp")
+	sql := `SELECT * FROM report WHERE report_code=?`
+	err = o.Raw(sql, reportCode).QueryRow(&item)
+	return
+}
+
+type ReportShareDetailResp struct {
+	Report        *Report            `description:"报告"`
+}