12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- package edge_service
- import (
- "encoding/json"
- "fmt"
- "io/ioutil"
- "iot_manager_service/config"
- "net/http"
- url2 "net/url"
- )
- type RecordLightUp struct{}
- type RecordLightUpReq struct {
- Code int `json:"code"`
- Msg string `json:"msg"`
- Data []RecordLightUpData `json:"data"`
- }
- type RecordLightUpData struct {
- ID int `json:"id"`
- Code string `json:"code"`
- Tstart string `json:"tstart"`
- Tend string `json:"tend"`
- Brightness int `json:"brightness"`
- Duration float64 `json:"duration"`
- Updatedat string `json:"updatedat"`
- }
- // SyncRecord 同步亮灯数据
- func (r *RecordLightUp) SyncRecord(maxId int64, maxUpDateTime string) ([]RecordLightUpData, error) {
- cfg := config.Instance()
- api := cfg.Foreign.IotEdgeUrl + "/data/v1/lampevent/sync"
- url := fmt.Sprintf("%v?id=%d&&updatedat=%v", api, maxId, url2.QueryEscape(maxUpDateTime))
- method := "GET"
- client := &http.Client{}
- req, err := http.NewRequest(method, url, nil)
- 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 := RecordLightUpReq{}
- err = json.Unmarshal(body, &result)
- if err != nil {
- return nil, err
- }
- if result.Code != 0 {
- panic(result.Msg)
- }
- return result.Data, nil
- }
|