Browse Source

添加图表详情功能

zqbao 10 months ago
parent
commit
10c2bc356f
3 changed files with 48 additions and 0 deletions
  1. 32 0
      controllers/chart.go
  2. 7 0
      models/chart.go
  3. 9 0
      routers/commentsRouter.go

+ 32 - 0
controllers/chart.go

@@ -60,3 +60,35 @@ func (this *ChartController) List() {
 	br.Data = resp
 
 }
+
+// @Title Detail
+// @Description 获得图表详情
+// @Param   ChartInfoId   query   int  true       "图表详情id"
+// @Success 200 {object} models.BaseResponse
+// @Failure 403 {object} models.BaseResponse
+// @router /detail [get]
+func (this *ChartController) Detail() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+
+	chartInfoId, _ := this.GetInt("ChartInfoId")
+	if chartInfoId <= 0 {
+		br.Msg = "图表id错误"
+		return
+	}
+
+	chart, err := models.GetChartById(chartInfoId)
+	if err != nil {
+		br.Msg = "获取图表列表失败"
+		br.ErrMsg = "获取图表列表失败,系统错误,Err:" + err.Error()
+		return
+	}
+
+	br.Ret = 200
+	br.Msg = "获取图表列表成功"
+	br.Success = true
+	br.Data = chart
+}

+ 7 - 0
models/chart.go

@@ -95,3 +95,10 @@ func GetChartList(startSize, pageSize int) (item []*ChartInfoView, err error) {
 	_, err = o.Raw(sql, startSize, pageSize).QueryRows(&item)
 	return
 }
+
+func GetChartById(chartInfoId int) (item *ChartInfoView, err error) {
+	o := orm.NewOrmUsingDB("data")
+	sql := ` SELECT * FROM chart_info WHERE chart_info_id=?`
+	err = o.Raw(sql, chartInfoId).QueryRow(&item)
+	return
+}

+ 9 - 0
routers/commentsRouter.go

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