fwh_shutdownList.go 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. package fwh_test
  2. import (
  3. "fwh-toolbox-server/domain"
  4. "net/url"
  5. "strconv"
  6. )
  7. type ShutdownListData struct {
  8. Current int `json:"current"` // 当前页
  9. Pages int `json:"pages"` // 总页数
  10. Size int `json:"size"` // 每页最大条数
  11. Total int64 `json:"total"` // 总条数
  12. Records []domain.ShutdownRecord `json:"records"` // 记录列表
  13. }
  14. // 查询Shutdown站点列表 one page
  15. func querySiteShutdownListOnePage(date string, country int, page int) (*domain.FwhResponseB[ShutdownListData], error) {
  16. // 构造 query 参数
  17. params := url.Values{}
  18. if country <= 0 {
  19. params.Add("countryId", "") // 0-ALL
  20. } else {
  21. params.Add("countryId", strconv.Itoa(country)) // 2-美国 3-澳大利亚 5-加拿大 6-新西兰 51-巴巴多斯
  22. }
  23. params.Add("date", date)
  24. params.Add("timeType", strconv.Itoa(1)) // 0-通讯时间;1-设备时间
  25. params.Add("pageSize", strconv.FormatUint(REQ_PAGE_SIZE, 10))
  26. params.Add("pageNum", strconv.Itoa(page))
  27. params.Add("land", "ZH_CN")
  28. response, err := FwhHttpGetUnmarshalB[ShutdownListData](getFullEnergyUrl("/api-inspect/fault/listShutdownGateway"), params)
  29. if err != nil {
  30. return nil, err
  31. }
  32. return response, nil
  33. }
  34. // 查询Shutdown站点列表
  35. func QuerySiteShutdownList(date string, country int) ([]domain.ShutdownRecord, error) {
  36. var total int64 = 0
  37. var page int = 0
  38. var records []domain.ShutdownRecord = []domain.ShutdownRecord{}
  39. for total == 0 || REQ_PAGE_SIZE*uint64(page) < uint64(total) {
  40. page++
  41. shutdownListRes, err := querySiteShutdownListOnePage(date, country, page)
  42. if err != nil {
  43. return nil, err
  44. }
  45. total = int64(shutdownListRes.Data.Total)
  46. records = append(records, shutdownListRes.Data.Records...)
  47. }
  48. return records, nil
  49. }