rdluck 4 năm trước cách đây
mục cha
commit
faf8bc1b11
2 tập tin đã thay đổi với 26 bổ sung18 xóa
  1. 22 18
      controllers/report.go
  2. 4 0
      models/report.go

+ 22 - 18
controllers/report.go

@@ -1,6 +1,7 @@
 package controllers
 
 import (
+	"encoding/json"
 	"hongze/hongze_api/models"
 	"hongze/hongze_api/utils"
 	"html"
@@ -223,7 +224,7 @@ func (this *ReportController) ListReport() {
 
 // @Title 新增报告浏览记录
 // @Description 新增报告浏览记录接口
-// @Param   ReportId   query   int  true       "报告id"
+// @Param	request	body models.ReportRecordReq true "type json string"
 // @Success 200 新增成功
 // @router /addUpdateLabel [post]
 func (this *ReportController) AddUpdateLabelReport() {
@@ -239,13 +240,14 @@ func (this *ReportController) AddUpdateLabelReport() {
 		br.Ret = 408
 		return
 	}
-	reportId, err := this.GetInt("ReportId")
+	var req models.ReportRecordReq
+	err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
 	if err != nil {
-		br.Msg = "参数获取失败"
-		br.ErrMsg = "参数获取失败,Err:" + err.Error()
+		br.Msg = "参数解析异常!"
+		br.ErrMsg = "参数解析失败,Err:" + err.Error()
 		return
 	}
-	if reportId <= 0 {
+	if req.ReportId <= 0 {
 		br.Msg = "参数错误"
 		br.ErrMsg = "参数错误,报告id小于等于0"
 		return
@@ -253,7 +255,7 @@ func (this *ReportController) AddUpdateLabelReport() {
 
 	record := new(models.ReportViewLog)
 	record.UserId = user.UserId
-	record.ReportId = reportId
+	record.ReportId = req.ReportId
 	record.CreateTime = time.Now()
 	err = models.AddReportViewLog(record)
 	if err != nil {
@@ -268,7 +270,7 @@ func (this *ReportController) AddUpdateLabelReport() {
 
 // @Title 新增报告浏览记录
 // @Description 新增报告浏览记录接口
-// @Param   ReportId   query   int  true       "报告id"
+// @Param	request	body models.ReportRecordReq true "type json string"
 // @Success 200 新增成功
 // @router /addViewRecord [post]
 func (this *ReportController) AddViewRecordReport() {
@@ -284,20 +286,21 @@ func (this *ReportController) AddViewRecordReport() {
 		br.Ret = 408
 		return
 	}
-	reportId, err := this.GetInt("ReportId")
+	var req models.ReportRecordReq
+	err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
 	if err != nil {
-		br.Msg = "参数获取失败"
-		br.ErrMsg = "参数获取失败,Err:" + err.Error()
+		br.Msg = "参数解析异常!"
+		br.ErrMsg = "参数解析失败,Err:" + err.Error()
 		return
 	}
-	if reportId <= 0 {
+	if req.ReportId <= 0 {
 		br.Msg = "参数错误"
 		br.ErrMsg = "参数错误,报告id小于等于0"
 		return
 	}
 	record := new(models.ReportViewRecord)
 	record.UserId = user.UserId
-	record.ReportId = reportId
+	record.ReportId = req.ReportId
 	record.CreateTime = time.Now()
 	err = models.AddReportViewRecord(record)
 	if err != nil {
@@ -312,7 +315,7 @@ func (this *ReportController) AddViewRecordReport() {
 
 // @Title 新增音频阅读记录
 // @Description 新增音频阅读记录接口
-// @Param   ReportId   query   int  true       "报告id"
+// @Param	request	body models.ReportRecordReq true "type json string"
 // @Success 200 新增成功
 // @router /addAudioRecord [post]
 func (this *ReportController) AddAudioRecord() {
@@ -328,20 +331,21 @@ func (this *ReportController) AddAudioRecord() {
 		br.Ret = 408
 		return
 	}
-	reportId, err := this.GetInt("ReportId")
+	var req models.ReportRecordReq
+	err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
 	if err != nil {
-		br.Msg = "参数获取失败"
-		br.ErrMsg = "参数获取失败,Err:" + err.Error()
+		br.Msg = "参数解析异常!"
+		br.ErrMsg = "参数解析失败,Err:" + err.Error()
 		return
 	}
-	if reportId <= 0 {
+	if req.ReportId <= 0 {
 		br.Msg = "参数错误"
 		br.ErrMsg = "参数错误,报告id小于等于0"
 		return
 	}
 	record := new(models.ReportAudioRecord)
 	record.UserId = user.UserId
-	record.ReportId = reportId
+	record.ReportId = req.ReportId
 	record.CreateTime = time.Now()
 	err = models.AddReportAudioRecord(record)
 	if err != nil {

+ 4 - 0
models/report.go

@@ -123,3 +123,7 @@ type ReportDetailResp struct {
 	Status int     `description:"状态:0:正常展示,1:报告不存在,2:无权限"`
 	Msg    string  `description:"提示信息"`
 }
+
+type ReportRecordReq struct {
+	ReportId int `description:"报告Id"`
+}