package fwh_pro import ( "encoding/json" "fwh-toolbox-server/domain" "net/url" "strconv" ) type ShutdownListResponse struct { Code int `json:"code"` Msg string `json:"msg"` Data ShutdownListData `json:"data"` } type ShutdownListData struct { Current int `json:"current"` // 当前页 Pages int `json:"pages"` // 总页数 Size int `json:"size"` // 每页最大条数 Total int64 `json:"total"` // 总条数 Records []domain.ShutdownRecord `json:"records"` // 记录列表 } // 查询Shutdown站点列表 one page func querySiteShutdownListOnePage(date string, country int, page int) ([]byte, error) { // 构造 query 参数 var params url.Values if country <= 0 { params.Add("countryId", "") // 0-ALL } else { params.Add("countryId", strconv.Itoa(country)) // 2-美国 3-澳大利亚 5-加拿大 6-新西兰 51-巴巴多斯 } params.Add("date", date) params.Add("timeType", strconv.Itoa(1)) // 0-通讯时间;1-设备时间 params.Add("pageSize", strconv.FormatUint(REQ_PAGE_SIZE, 10)) params.Add("pageNum", strconv.Itoa(page)) params.Add("land", "ZH_CN") return FwhHttpGet("https://energy.franklinwh.com/api-inspect/fault/listShutdownGateway", params) } // 查询Shutdown站点列表 func QuerySiteShutdownList(date string, country int) ([]domain.ShutdownRecord, error) { var total int64 = 0 var page int = 0 var records []domain.ShutdownRecord = []domain.ShutdownRecord{} for total == 0 || REQ_PAGE_SIZE*uint64(page) < uint64(total) { page++ resByte, err := querySiteShutdownListOnePage(date, country, page) if err != nil { return nil, err } var shutdownListRes ShutdownListResponse // 反序列化(unmarshal) jsonErr := json.Unmarshal(resByte, &shutdownListRes) if jsonErr != nil { return nil, jsonErr } total = int64(shutdownListRes.Data.Total) records = append(records, shutdownListRes.Data.Records...) } return records, nil }