瀏覽代碼

feat: 增加FindKyLink 查询泛联数据

gaoyagang 11 月之前
父節點
當前提交
44034ecb19
共有 4 個文件被更改,包括 112 次插入1 次删除
  1. 37 0
      datacenter_client/types.go
  2. 44 0
      datacenter_client/v1/FindKyLink.go
  3. 29 0
      datacenter_client/v1/FindKyLink_test.go
  4. 2 1
      httplib/httplib.go

+ 37 - 0
datacenter_client/types.go

@@ -181,6 +181,21 @@ type (
 		Min float64 `json:"min"`
 		Max float64 `json:"max"`
 	}
+
+	KyLinkInfo struct {
+		Id           int64   `json:"id"`
+		ProjectId    int64   `json:"project_id"`
+		Customer     int64   `json:"customer"`
+		Name         string  `json:"name"`
+		COM1_D1_PH   float64 `json:"COM1_D1_PH"`
+		COM1_D2_Tag1 float64 `json:"COM1_D2_Tag1"`
+		COM1_D2_Tag2 float64 `json:"COM1_D2_Tag2"`
+		COM2_D1_Tag1 float64 `json:"COM2_D1_Tag1"`
+		COM2_D1_Tag2 float64 `json:"COM2_D1_Tag2"`
+		COM2_D2_Tag1 float64 `json:"COM2_D2_Tag1"`
+		COM2_D2_Tag2 float64 `json:"COM2_D2_Tag2"`
+		CTime        string  `json:"c_time"`
+	}
 )
 
 type (
@@ -324,6 +339,17 @@ type (
 		Stime     string
 		Etime     string
 	}
+
+	FindKyLinkDataReq struct {
+		ProjectId int64
+		Customer  string
+		Stime     string
+		Etime     string
+		Page      int64
+		PageSize  int64
+		Order     string
+		OnlyEven  int
+	}
 )
 
 type (
@@ -501,6 +527,14 @@ type (
 		} `json:"data"`
 	}
 
+	FindKyLinkDataResp struct {
+		Code int    `json:"code"`
+		Msg  string `json:"msg"`
+		Data struct {
+			List []*KyLinkInfo `json:"list"`
+		} `json:"data"`
+	}
+
 	FindDataMinAndMaxResp struct {
 		Code int    `json:"code"`
 		Msg  string `json:"msg"`
@@ -554,5 +588,8 @@ type (
 		FindDataCorrelation(FindDataCorrelationReq) (*FindDataCorrelationResp, error)
 		// FindDataMinAndMax 拉取数据分析结果, 时间段内的最小与最大值
 		FindDataMinAndMax(FindDataMinAndMaxReq) (*FindDataMinAndMaxResp, error)
+
+		// FindKyLink 泛联数据接口
+		FindKyLink(FindKyLinkDataReq) (*FindKyLinkDataResp, error)
 	}
 )

+ 44 - 0
datacenter_client/v1/FindKyLink.go

@@ -0,0 +1,44 @@
+package v1
+
+import (
+	"errors"
+	"fmt"
+	"metawant.greentech.com.cn/gaoyagang/gt-common/datacenter_client"
+	"metawant.greentech.com.cn/gaoyagang/gt-common/httplib"
+	"strconv"
+)
+
+func (d *DcApi) FindKyLink(params datacenter_client.FindKyLinkDataReq) (*datacenter_client.FindKyLinkDataResp, error) {
+	serviceName := "/data/Kylink"
+	h := httplib.Get(d.serviceUrl(serviceName))
+
+	if params.PageSize <= 0 {
+		params.PageSize = 50
+	}
+
+	if params.Page <= 1 {
+		params.Page = 1
+	}
+
+	h.Param("project_id", strconv.FormatInt(params.ProjectId, 10))
+	h.Param("customers", params.Customer)
+	h.Param("stime", params.Stime)
+	h.Param("etime", params.Etime)
+	h.Param("only_even", fmt.Sprintf("%d", params.OnlyEven))
+	h.Param("page", strconv.FormatInt(params.Page, 10))
+	h.Param("page_size", strconv.FormatInt(params.PageSize, 10))
+	h.Param("order", params.Order)
+
+	resp := &datacenter_client.FindKyLinkDataResp{}
+
+	err := d.call(h, resp)
+	if err != nil {
+		return nil, err
+	}
+
+	if resp.Code != 200 {
+		return nil, errors.New(resp.Msg)
+	}
+
+	return resp, err
+}

+ 29 - 0
datacenter_client/v1/FindKyLink_test.go

@@ -0,0 +1,29 @@
+package v1
+
+import (
+	"metawant.greentech.com.cn/gaoyagang/gt-common/datacenter_client"
+	"metawant.greentech.com.cn/gaoyagang/gt-common/httplib"
+	"testing"
+)
+
+func TestDcApi_FindKyLink(t *testing.T) {
+	var c = NewDcApi(ClientOptions{
+		HTTPSettings: httplib.HTTPSettings{},
+		ServerIp:     "127.0.0.1:8080",
+		AppName:      "simulations",
+		AppSecret:    "e3fc084fda3d2a6628b9ce28abf21243",
+	})
+
+	data, err := c.FindKyLink(datacenter_client.FindKyLinkDataReq{
+		ProjectId: 92,
+		Customer:  "93,117",
+		Stime:     "2024-06-24 00:00:00",
+		Etime:     "2024-06-29 14:00:00",
+		//Page:      1,
+		//PageSize:  50,
+		//Order:     "id asc",
+		//OnlyEven:  1,
+	})
+	t.Log(data)
+	t.Log(err)
+}

+ 2 - 1
httplib/httplib.go

@@ -334,7 +334,7 @@ func (b *HTTPRequest) JSONBody(obj interface{}) (*HTTPRequest, error) {
 func (b *HTTPRequest) buildURL(paramBody string) {
 	// build GET url with query string
 	if len(paramBody) > 0 {
-	//if b.req.Method == "GET" && len(paramBody) > 0 {
+		//if b.req.Method == "GET" && len(paramBody) > 0 {
 		if strings.Contains(b.url, "?") {
 			b.url += "&" + paramBody
 		} else {
@@ -558,6 +558,7 @@ func (b *HTTPRequest) ToFile(filename string) error {
 // it calls Response inner.
 func (b *HTTPRequest) ToJSON(v interface{}) error {
 	data, err := b.Bytes()
+	println(string(data))
 	if err != nil {
 		return err
 	}