xyxie 1 天之前
父节点
当前提交
031a5db4e3
共有 3 个文件被更改,包括 317 次插入0 次删除
  1. 134 0
      controllers/kpler.go
  2. 109 0
      models/base_from_kpler.go
  3. 74 0
      models/kpler_request.go

+ 134 - 0
controllers/kpler.go

@@ -0,0 +1,134 @@
+package controllers
+
+import (
+	"encoding/json"
+	"eta/eta_data_analysis/models"
+	"eta/eta_data_analysis/services/kpler"
+	"fmt"
+
+	"github.com/beego/beego/v2/server/web"
+)
+
+type KplerController struct {
+	web.Controller
+}
+
+// 获取开普勒数据
+// @Title GetKplerData
+// @Description 获取开普勒数据
+// @Param body body models.KplerFlowDataLibReq true "请求参数"
+// @Success 200 {object} models.BaseResponse
+// @router /getFlowData [post]
+func (this *KplerController) GetFlowData() {
+    //获取入参
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		if br.ErrMsg == "" {
+			br.IsSendEmail = false
+		}
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	var params models.KplerFlowDataLibReq
+	if e := json.Unmarshal(this.Ctx.Input.RequestBody, &params); e != nil {
+		br.Msg = "参数解析异常"
+		br.ErrMsg = fmt.Sprintf("参数解析失败, %v", e)
+		return
+	}
+	
+	if params.Granularity == "" {
+		br.Msg = "请选择频度"
+		return
+	}
+	if params.Split == "" {
+		br.Msg = "请选择拆分类型"
+		return
+	}
+	if params.Unit == "" {
+		br.Msg = "请选择单位"
+		return
+	}
+	if params.FlowDirection == "" {
+		br.Msg = "请选择流向"
+		return
+	}
+	
+	data, err := kpler.GetKplerData(params)
+	if err != nil {
+		br.Msg = "获取数据失败"
+		br.ErrMsg = fmt.Sprintf("获取数据失败, %v", err)
+		return
+	}
+	br.Data = data
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "获取成功"
+}
+
+// 获取产品数据
+// @Title GetProductData
+// @Description 获取产品数据
+// @Param body body models.KplerProductDataLibReq true "请求参数"
+// @Success 200 {object} models.BaseResponse
+// @router /getProductData [post]
+func (this *KplerController) GetProductData() {
+	 //获取入参
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		if br.ErrMsg == "" {
+			br.IsSendEmail = false
+		}
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	data, err := kpler.GetProducts()
+	if err != nil {
+		br.Msg = "获取数据失败"
+		br.ErrMsg = fmt.Sprintf("获取数据失败, %v", err)
+		return
+	}
+	br.Data = data
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "获取成功"
+}
+
+// 获取区域数据
+// @Title GetZoneData
+// @Description 获取区域数据
+// @Param body body models.KplerZoneDataLibReq true "请求参数"
+// @Success 200 {object} models.BaseResponse
+// @router /getZoneData [post]
+func (this *KplerController) GetZoneData() {
+	//获取入参
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		if br.ErrMsg == "" {
+			br.IsSendEmail = false
+		}
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	var params models.KplerZoneDataLibReq
+	if e := json.Unmarshal(this.Ctx.Input.RequestBody, &params); e != nil {
+		//br.Msg = "参数解析异常"
+		// br.ErrMsg = fmt.Sprintf("参数解析失败, %v", e)
+		// return
+	}
+	token, err := kpler.GetKplerAccessToken()
+	if err != nil {
+		br.Msg = "获取token失败"
+		br.ErrMsg = fmt.Sprintf("获取token失败, %v", err)
+		return
+	}
+	data, err := kpler.GetZonesByApi(token, params.AncestorName, params.DescendantType)
+	if err != nil {
+		br.Msg = "获取数据失败"
+		br.ErrMsg = fmt.Sprintf("获取数据失败, %v", err)
+		return
+	}
+	br.Data = data
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "获取成功"
+}

+ 109 - 0
models/base_from_kpler.go

@@ -0,0 +1,109 @@
+package models
+
+type BaseFromKpler struct {
+	Date          string
+	Value         float64
+	PeriodEndDate string
+}
+
+  // withIntraCountry := false
+  // withIntraRegion := true
+  // withForecast := true
+  // withFreightView := false
+  // withProductEstimation := false
+  type KplerFlowDataLibReq struct {
+	Products string `description:"产品名称"`
+	FromZones string `description:"来源区域ID,对应Location" ` 
+	ToZones string `description:"流向区域ID"`
+	Split string `description:"拆分类型"`
+	FlowDirection string `description:"流向,对应periodicity:export/import"`
+	Granularity string `description:"粒度: daily/weekly/monthly/yearly"`
+	Unit string `description:"单位"`
+	FromCountries string `description:"来源国家"`
+	ToCountries string `description:"流向国家"`
+	FromInstallations string `description:"来源安装"`
+	ToInstallations string `description:"流向安装"`
+	OnlyRealized string `description:"是否只查询已实现数据"`
+	VesselTypes string `description:"船型"`
+	VesselTypesAlt string `description:"船型"`
+    WithIntraCountry string `description:"是否查询同国数据"`
+    WithIntraRegion string `description:"是否查询同区域数据"`
+    WithForecast string `description:"是否查询预测数据"`
+    WithFreightView string `description:"是否查询运费数据"`
+    WithProductEstimation string `description:"是否查询产品估算数据"`
+    StartDate string `description:"开始日期"`
+    EndDate string `description:"结束日期"`
+}
+
+type KplerFlowData struct {
+	SplitItem string 
+	ApiQueryUrl string
+	IndexData []KplerBaseExcelData 
+}
+
+type KplerBaseExcelData struct {
+	DataTime string
+	Value    string
+}
+
+//bodystr := "Id (Product);Name;Type (Product);Family;Family Id;Group;Group Id;Product;Product Id;Grade;Grade Id;Density (Product);Density Unit;Energy Density;Energy Density Unit;Expansion Ratio
+type KplerProduct struct {
+	Id string
+	Name string
+	Type string
+	Family string
+	FamilyId string
+	Group string
+	GroupId string
+	Product string
+	ProductId string
+	Grade string
+	GradeId string
+	Density string
+	DensityUnit string
+	EnergyDensity string
+	EnergyDensityUnit string
+	ExpansionRatio string
+}
+
+// Ancestor Id;Ancestor Name;Ancestor Type;Descendant Id;Descendant Name;Descendant Type
+type KplerZone struct {
+	AncestorId string
+	AncestorName string
+	AncestorType string
+	DescendantId string
+	DescendantName string
+	DescendantType string
+}
+
+type KplerZoneDataLibReq struct {
+	Token string `description:"token"`
+	AncestorName string `description:"祖先名称"`
+	DescendantType string `description:"子类型"`
+}
+
+// HandleKplerExcelData Kpler的excel数据
+type HandleKplerExcelData struct {
+	ClassifyName       string `description:"指标目录"`
+	ParentClassifyName string `description:"父级指标目录"`
+	ClassifySort       int    `description:"指标目录排序号"`
+	IndexName          string `description:"指标名称"`
+	IndexCode          string `description:"指标编码"`
+	Unit               string `description:"单位"`
+	Sort               int    `description:"排序号"`
+	Frequency          string `description:"频度"`
+	ProductNames       string `description:"产品名称"`
+	FromZoneNames      string `description:"区域名称"`
+	ToZoneNames        string `description:"区域名称"`
+	FlowDirection      string `description:"流向"`
+	Granularity        string `description:"粒度"`
+	Split              string `description:"拆分类型"`
+	SplitName          string `description:"拆分类型名称"`
+	ExcelQueryUrl      string `description:"Excel查询URL"`
+	ExcelDataMap       map[string]string
+}
+
+type HandleKplerExcelDataReq struct {
+	List         []*HandleKplerExcelData
+	TerminalCode string `description:"编码"`
+}

+ 74 - 0
models/kpler_request.go

@@ -0,0 +1,74 @@
+package models
+
+// KplerLocation represents a location with ID and name
+type KplerExcelLocation struct {
+	ID   string `json:"id"`
+	Name string `json:"name"`
+}
+
+// KplerProduct represents a product with ID and name
+type KplerExcelProduct struct {
+	ID   string `json:"id"`
+	Name string `json:"name"`
+}
+
+// KplerFlowsRequest represents the request structure for Kpler flows API
+type KplerFlowsRequest struct {
+	Platform            string          `json:"platform"`
+	Origins            []KplerExcelLocation `json:"origins"`
+	Destinations       []KplerExcelLocation `json:"destinations"`
+	FromInstallations  []KplerExcelLocation `json:"fromInstallations"`
+	ToInstallations    []KplerExcelLocation `json:"toInstallations"`
+	FlowDirection      string          `json:"flowDirection"`
+	Products           []KplerExcelProduct  `json:"products"`
+	Unit               string          `json:"unit"`
+	IsProductEstimation bool           `json:"isProductEstimation"`
+	IsIntracountry     bool           `json:"isIntracountry"`
+	IsIntraRegion      bool           `json:"isIntraRegion"`
+	IsWithForecast     bool           `json:"isWithForecast"`
+	Granularity        string         `json:"granularity"`
+	VesselClassification string       `json:"vesselClassification"`
+	VesselsTypes        []string      `json:"vesselsTypes"`
+	Split               string        `json:"split"`
+	IsFreightView       bool          `json:"isFreightView"`
+	IsWithPeriodEndTime bool          `json:"isWithPeriodEndTime"`
+	Projection          string        `json:"projection"`
+	SelectedPreset      string        `json:"selectedPreset"`
+	StartDate           *string       `json:"startDate"`
+	EndDate             *string       `json:"endDate"`
+}
+
+// ZoneInfo represents a geographical zone in Kpler API
+type ZoneInfo struct {
+	ID   string `json:"id"`
+	Name string `json:"name"`
+}
+
+// ProductInfo represents a product in Kpler API
+type ProductInfo struct {
+	ID   string `json:"id"`
+	Name string `json:"name"`
+}
+
+// KplerDataPoint represents a single data point with end date and value
+type KplerDataPoint struct {
+	EndDate string  `json:"end_date"`
+	Value   string `json:"val"`
+}
+
+// KplerExcelIndexData represents a single index data from Excel
+type KplerExcelIndexData struct {
+	Title      string            
+	Name       string            
+	DataPoints []KplerDataPoint  
+	Request    string        
+}
+
+// KplerFlowsExcelRequest is an alias for KplerFlowsRequest
+type KplerFlowsExcelRequest = KplerFlowsRequest
+
+// Process data rows
+type DataPoint struct {
+	Value string
+	Row   int
+}