|
@@ -0,0 +1,78 @@
|
|
|
+package edge_service
|
|
|
+
|
|
|
+import (
|
|
|
+ "encoding/json"
|
|
|
+ "io/ioutil"
|
|
|
+ "iot_manager_service/config"
|
|
|
+ "net/http"
|
|
|
+ "strings"
|
|
|
+)
|
|
|
+
|
|
|
+// CaptureIts 获取设备能耗数据
|
|
|
+type ForCaptureIts struct{}
|
|
|
+
|
|
|
+// CaptureItsReq 请求参数
|
|
|
+type ForCaptureItsReq struct {
|
|
|
+ Codes []string `json:"codes"` //抓拍单元 capture_sn列表
|
|
|
+ Start string `json:"start"`
|
|
|
+ End string `json:"end"`
|
|
|
+ Flag int `json:"flag"` //0按日 1按月
|
|
|
+}
|
|
|
+
|
|
|
+// ForCaptureItsRes 返回数据
|
|
|
+type ForCaptureItsRes struct {
|
|
|
+ Code int `json:"code"`
|
|
|
+ Msg string `json:"msg"`
|
|
|
+ Data []ForCaptureItsData `json:"data"`
|
|
|
+}
|
|
|
+type ForCaptureItsData struct {
|
|
|
+ Code string `json:"code"` //抓拍单元 capture_sn
|
|
|
+ Time string `json:"time"` //时间 2022-05-01 ||2022-05
|
|
|
+ Flag int `json:"flag"` //0:日数据,1:月数据,2:小时数据
|
|
|
+ Sflag int `json:"sflag"` //车速区间时:
|
|
|
+ Total int `json:"total"` //数量
|
|
|
+}
|
|
|
+
|
|
|
+// VehicleTotal 统计日 月 车流量 数据
|
|
|
+func (f ForCaptureIts) VehicleTotal(reqPostData ForCaptureItsReq) ([]ForCaptureItsData, error) {
|
|
|
+ api := "/data/v1/its/vehicletotal"
|
|
|
+ return f.pubPost(reqPostData, api)
|
|
|
+}
|
|
|
+
|
|
|
+//公用 post请求
|
|
|
+func (f ForCaptureIts) pubPost(reqPostData ForCaptureItsReq, api string) ([]ForCaptureItsData, error) {
|
|
|
+ cfg := config.Instance()
|
|
|
+ api = cfg.Foreign.IotEdgeUrl + api
|
|
|
+ //fmt.Printf("api = %v \n", api)
|
|
|
+ reqPostData.Start = reqPostData.Start + " 00:00:00"
|
|
|
+ reqPostData.End = reqPostData.End + " 23:59:59"
|
|
|
+ //fmt.Printf("reqPostData = %v \n", reqPostData)
|
|
|
+ method := "POST"
|
|
|
+ client := &http.Client{}
|
|
|
+ marshal, _ := json.Marshal(reqPostData)
|
|
|
+ req, err := http.NewRequest(method, api, strings.NewReader(string(marshal)))
|
|
|
+
|
|
|
+ if err != nil {
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+ res, err := client.Do(req)
|
|
|
+ if err != nil {
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+ defer res.Body.Close()
|
|
|
+ body, err := ioutil.ReadAll(res.Body)
|
|
|
+ if err != nil {
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+ //fmt.Printf("body = %v", string(body))
|
|
|
+ result := ForCaptureItsRes{}
|
|
|
+ err = json.Unmarshal(body, &result)
|
|
|
+ if err != nil {
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+ if result.Code != 0 {
|
|
|
+ panic(result.Msg)
|
|
|
+ }
|
|
|
+ //fmt.Printf("result.Data = %v", result.Data)
|
|
|
+ return result.Data, nil
|
|
|
+}
|