fwh_shutdownList.go 1.8 KB

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