Forráskód Böngészése

feat: 增加FindEventList 查询事件列表

gaoyagang 11 hónapja
szülő
commit
b012bae188

+ 34 - 0
datacenter_client/types.go

@@ -196,6 +196,20 @@ type (
 		COM2_D2_Tag2 float64 `json:"COM2_D2_Tag2"`
 		CTime        string  `json:"c_time"`
 	}
+
+	EventInfo struct {
+		Id         int64  `json:"id"`
+		ProjectId  int64  `json:"project_id"`
+		DeviceCode string `json:"device_code"`
+		Name       string `json:"name"`
+		Item       string `json:"item"`
+		Val        string `json:"val"`
+		OldVal     string `json:"old_val"`
+		Time       string `json:"time"`    // 事件触发时间
+		Title      string `json:"title"`   // 事件标题
+		Context    string `json:"context"` // 事件内容
+		CTime      string `json:"c_time"`
+	}
 )
 
 type (
@@ -350,6 +364,15 @@ type (
 		Order     string
 		OnlyEven  int
 	}
+
+	FindEventListReq struct {
+		ProjectId  int64
+		Name       string
+		DeviceCode string
+		Item       string
+		Stime      string
+		Etime      string
+	}
 )
 
 type (
@@ -543,6 +566,14 @@ type (
 			List map[string]*DataDescribeMinAndMaxInfo `json:"list"`
 		} `json:"data"`
 	}
+
+	FindEventListResp struct {
+		Code int    `json:"code"`
+		Msg  string `json:"msg"`
+		Data struct {
+			List []*EventInfo `json:"list"`
+		} `json:"data"`
+	}
 )
 
 type (
@@ -591,5 +622,8 @@ type (
 
 		// FindKyLink 泛联数据接口
 		FindKyLink(FindKyLinkDataReq) (*FindKyLinkDataResp, error)
+
+		// FindEventList 泛联数据接口
+		FindEventList(FindEventListReq) (*FindEventListResp, error)
 	}
 )

+ 33 - 0
datacenter_client/v1/FindEventList.go

@@ -0,0 +1,33 @@
+package v1
+
+import (
+	"errors"
+	"metawant.greentech.com.cn/gaoyagang/gt-common/datacenter_client"
+	"metawant.greentech.com.cn/gaoyagang/gt-common/httplib"
+	"strconv"
+)
+
+func (d *DcApi) FindEventList(params datacenter_client.FindEventListReq) (*datacenter_client.FindEventListResp, error) {
+	serviceName := "/events"
+	h := httplib.Get(d.serviceUrl(serviceName))
+
+	h.Param("project_id", strconv.FormatInt(params.ProjectId, 10))
+	h.Param("name", params.Name)
+	h.Param("stime", params.Stime)
+	h.Param("etime", params.Etime)
+	h.Param("device_code", params.DeviceCode)
+	h.Param("item", params.Item)
+
+	resp := &datacenter_client.FindEventListResp{}
+
+	err := d.call(h, resp)
+	if err != nil {
+		return nil, err
+	}
+
+	if resp.Code != 200 {
+		return nil, errors.New(resp.Msg)
+	}
+
+	return resp, err
+}

+ 27 - 0
datacenter_client/v1/FindEventList_test.go

@@ -0,0 +1,27 @@
+package v1
+
+import (
+	"metawant.greentech.com.cn/gaoyagang/gt-common/datacenter_client"
+	"metawant.greentech.com.cn/gaoyagang/gt-common/httplib"
+	"testing"
+)
+
+func TestDcApi_FindEventList(t *testing.T) {
+	var c = NewDcApi(ClientOptions{
+		HTTPSettings: httplib.HTTPSettings{},
+		ServerIp:     "127.0.0.1:8080",
+		AppName:      "simulations",
+		AppSecret:    "e3fc084fda3d2a6628b9ce28abf21243",
+	})
+
+	data, err := c.FindEventList(datacenter_client.FindEventListReq{
+		ProjectId:  92,
+		Name:       "FLUID_LEVEL_CHANGE",
+		DeviceCode: "LIT-54061A",
+		Item:       "asdfasdf",
+		Stime:      "2024-06-29 00:00:00",
+		Etime:      "2024-06-29 14:00:00",
+	})
+	t.Log(data)
+	t.Log(err)
+}