Browse Source

查询eta社区中的图表数据

xyxie 3 months ago
parent
commit
1b4b95319c
3 changed files with 98 additions and 0 deletions
  1. 84 0
      controllers/eta_forum_chart.go
  2. 9 0
      routers/commentsRouter.go
  3. 5 0
      routers/router.go

+ 84 - 0
controllers/eta_forum_chart.go

@@ -0,0 +1,84 @@
+package controllers
+
+import (
+	"encoding/json"
+	"eta/eta_report/models"
+	"eta/eta_report/services"
+	"eta/eta_report/utils"
+	"fmt"
+	"io/ioutil"
+	"net/http"
+)
+
+// EtaForumChartController 图表详情
+type EtaForumChartController struct {
+	BaseAuthController
+}
+
+// ChartDetail
+// @Title 表格详情
+// @Description 表格详情
+// @Success 200 {object} models.EnglishReportShareDetailResp
+// @router /chart/detail [post]
+func (this *EtaForumChartController) ChartDetail() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		if br.ErrMsg == "" {
+			br.IsSendEmail = false
+		}
+		this.Data["json"] = br
+		this.ServeJSONNoEncryption()
+	}()
+
+	var req services.ChartDetailReq
+	err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
+	if err != nil {
+		br.Msg = "参数解析异常!"
+		br.ErrMsg = "参数解析失败,Err:" + err.Error()
+		return
+	}
+	if req.UniqueCode == "" {
+		br.Msg = "参数不能为空!"
+		br.ErrMsg = "参数不能为空!"
+		return
+	}
+	url := utils.ChartLibUrl + `/eta_forum/chart/common/detail?UniqueCode=%s`
+	url = fmt.Sprintf(url, req.UniqueCode)
+
+	resp, e := http.Get(url)
+	if e != nil {
+		err = fmt.Errorf("http Get err: %s", e.Error())
+		br.ErrMsg = err.Error()
+		return
+	}
+	defer resp.Body.Close()
+
+	b, e := ioutil.ReadAll(resp.Body)
+	if e != nil {
+		err = fmt.Errorf("resp body read err: %s", e.Error())
+		br.ErrMsg = err.Error()
+		return
+	}
+	if len(b) == 0 {
+		err = fmt.Errorf("resp body is empty")
+		br.ErrMsg = err.Error()
+		return
+	}
+
+	result := new(models.BaseResponse)
+	if e = json.Unmarshal(b, &result); e != nil {
+		err = fmt.Errorf("result unmarshal err: %s\nresult: %s", e.Error(), string(b))
+		br.ErrMsg = err.Error()
+		return
+	}
+	if result.Ret != 200 {
+		err = fmt.Errorf("result: %s", string(b))
+		br.ErrMsg = err.Error()
+		return
+	}
+
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "获取成功"
+	br.Data = result.Data
+}

+ 9 - 0
routers/commentsRouter.go

@@ -34,6 +34,15 @@ func init() {
             Filters: nil,
             Params: nil})
 
+    beego.GlobalControllerRouter["eta/eta_report/controllers:EtaForumChartController"] = append(beego.GlobalControllerRouter["eta/eta_report/controllers:EtaForumChartController"],
+        beego.ControllerComments{
+            Method: "ChartDetail",
+            Router: `/chart/detail`,
+            AllowHTTPMethods: []string{"post"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
     beego.GlobalControllerRouter["eta/eta_report/controllers:ExcelController"] = append(beego.GlobalControllerRouter["eta/eta_report/controllers:ExcelController"],
         beego.ControllerComments{
             Method: "ExcelDetail",

+ 5 - 0
routers/router.go

@@ -44,6 +44,11 @@ func init() {
 				&controllers.ChartController{},
 			),
 		),
+		web.NSNamespace("/eta_forum",
+			web.NSInclude(
+				&controllers.EtaForumChartController{},
+			),
+		),
 	)
 	web.AddNamespace(ns)
 }