hsun преди 1 година
родител
ревизия
7d975fb249
променени са 2 файла, в които са добавени 25 реда и са изтрити 12 реда
  1. 17 12
      controller/index_data/jiayue_index.go
  2. 8 0
      models/request/index_data/jiayue_index.go

+ 17 - 12
controller/index_data/jiayue_index.go

@@ -18,23 +18,28 @@ type JiaYueIndexController struct{}
 // GetData
 // @Description 获取嘉悦指标数据
 // @Success 200 {string} string "操作成功"
-// @Router /jiayue/index [get]
+// @Router /jiayue/index [post]
 func (j *JiaYueIndexController) GetData(c *gin.Context) {
-	indexCode := c.DefaultQuery("index_code", "")
-	source := c.DefaultQuery("source", "")
-	startDate := c.DefaultQuery("start_date", "")
-	endDate := c.DefaultQuery("end_date", "")
-
-	if indexCode == "" {
+	var req indexDataReq.JiaYueIndexReq
+	if e := c.Bind(&req); e != nil {
+		err, ok := e.(validator.ValidationErrors)
+		if !ok {
+			resp.FailData("参数解析失败", "Err:"+e.Error(), c)
+			return
+		}
+		resp.FailData("参数解析失败", err.Translate(global.Trans), c)
+		return
+	}
+	if req.IndexCode == "" {
 		resp.FailMsg("请输入指标code码", "请输入指标code码", c)
 		return
 	}
-	if source == "" {
+	if req.Source == "" {
 		resp.FailMsg("请输入指标来源", "请输入指标来源", c)
 		return
 	}
 
-	data, err, errMsg := indexDataService.GetIndexFromJiaYue(indexCode, source, startDate, endDate)
+	data, err, errMsg := indexDataService.GetIndexFromJiaYue(req.IndexCode, req.Source, req.StartDate, req.EndDate)
 	if err != nil {
 		resp.FailMsg("查询失败", err.Error()+errMsg, c)
 		return
@@ -46,10 +51,10 @@ func (j *JiaYueIndexController) GetData(c *gin.Context) {
 // GetPageIndex
 // @Description 获取嘉悦指标列表-分页
 // @Success 200 {string} string "获取成功"
-// @Router /jiayue/page_index [get]
+// @Router /jiayue/page_index [post]
 func (j *JiaYueIndexController) GetPageIndex(c *gin.Context) {
 	var req indexDataReq.JiaYuePageIndexReq
-	if e := c.BindQuery(&req); e != nil {
+	if e := c.Bind(&req); e != nil {
 		err, ok := e.(validator.ValidationErrors)
 		if !ok {
 			resp.FailData("参数解析失败", "Err:"+e.Error(), c)
@@ -83,7 +88,7 @@ func (j *JiaYueIndexController) GetPageIndex(c *gin.Context) {
 // GetIndexFrequency
 // @Description 获取指标频度列表
 // @Success 200 {string} string "获取成功"
-// @Router /jiayue/frequency_list [get]
+// @Router /jiayue/frequency_list [post]
 func (j *JiaYueIndexController) GetIndexFrequency(c *gin.Context) {
 	list, err := jiayue.GetDictFrequency()
 	if err != nil {

+ 8 - 0
models/request/index_data/jiayue_index.go

@@ -1,5 +1,13 @@
 package index_data
 
+// JiaYueIndexReq 指标请求体
+type JiaYueIndexReq struct {
+	IndexCode string `json:"index_code" form:"index_code" description:"指标编码"`
+	Source    string `json:"source" form:"source" description:"来源"`
+	StartDate string `json:"start_date" form:"start_date" description:"开始日期"`
+	EndDate   string `json:"end_date" form:"end_date" description:"结束日期"`
+}
+
 // JiaYuePageIndexReq 指标列表请求体-分页
 type JiaYuePageIndexReq struct {
 	SourceExtend string `json:"source_extend" form:"source_extend" description:"来源"`