pcsg_index.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package index_data
  2. import (
  3. "eta_gn/eta_bridge/controller/resp"
  4. "eta_gn/eta_bridge/global"
  5. indexDataService "eta_gn/eta_bridge/services/index_data"
  6. "fmt"
  7. "github.com/gin-gonic/gin"
  8. "github.com/go-playground/validator/v10"
  9. )
  10. // PCSGIndexController 中石油新加坡指标
  11. type PCSGIndexController struct{}
  12. // GetBloombergIndexDataGeneral
  13. // @Description 获取通用格式数据
  14. // @Success 200 {string} string "获取成功"
  15. // @Router /bloomberg/index_data/general [post]
  16. func (this *PCSGIndexController) GetBloombergIndexDataGeneral(c *gin.Context) {
  17. var req struct {
  18. TaskKey string `json:"TaskKey" form:"TaskKey" description:"来源"`
  19. Frequency string `json:"Frequency" form:"Frequency" description:"频度"`
  20. }
  21. if e := c.Bind(&req); e != nil {
  22. err, ok := e.(validator.ValidationErrors)
  23. if !ok {
  24. resp.FailData("参数解析失败", "Err:"+e.Error(), c)
  25. return
  26. }
  27. resp.FailData("参数解析失败", err.Translate(global.Trans), c)
  28. return
  29. }
  30. fmt.Println(req)
  31. if req.TaskKey == "" {
  32. resp.Fail(fmt.Sprintf("参数有误, TaskKey: %s", req.TaskKey), c)
  33. return
  34. }
  35. if req.Frequency == "" {
  36. resp.Fail(fmt.Sprintf("参数有误, Frequency: %s", req.Frequency), c)
  37. return
  38. }
  39. data, e := indexDataService.GetPCSGBloombergGeneralIndex(req.TaskKey, req.Frequency)
  40. if e != nil {
  41. resp.FailMsg("获取失败", "GetPCSGBloombergGeneralIndex, err: "+e.Error(), c)
  42. return
  43. }
  44. resp.OkData("获取成功", data, c)
  45. }