package acceleronix import ( "bytes" "encoding/json" "errors" "fwh-toolbox-server/domain" "go.uber.org/zap" ) // 查询SIM卡列表 func QuerySimCardList(page uint, size uint) (*domain.AcceleronixSimCardListResponse, error) { res, err := acceleronixHttpPost("/sim/page", domain.AcceleronixSimCardListRequestBody{ PageNum: page, PageSize: size, }) if err != nil { zap.L().Error("QuerySimCardList failed.", zap.String("err", err.Error())) return nil, err } var resList domain.AcceleronixSimCardListResponse if err := json.Unmarshal(res.Body, &resList); err != nil { zap.L().Error("QuerySimCardList Unmarshal failed.", zap.String("err", err.Error()), zap.String("body", string(res.Body))) return nil, err } zap.L().Debug("QuerySimCardList", zap.Int("DataNum", len(resList.Data.List)), zap.Int64("Page", resList.Data.Current), zap.Int64("Size", resList.Data.Size), zap.Int64("Total", resList.Data.Total)) return &resList, nil } // 查询SIM卡详情 func QuerySimCardInfo(iccid string) (*domain.AcceleronixSimCardInfoResponse, error) { res, err := acceleronixHttpPost("/sim/detail", map[string]interface{}{ "iccid": iccid, }) if err != nil { zap.L().Error("QuerySimCardInfo failed.", zap.String("err", err.Error())) return nil, err } var resInfo domain.AcceleronixSimCardInfoResponse if err := json.Unmarshal(res.Body, &resInfo); err != nil { zap.L().Error("QuerySimCardInfo Unmarshal failed.", zap.String("err", err.Error()), zap.String("body", string(res.Body))) return nil, err } zap.L().Debug("QuerySimCardInfo", zap.String("GICCID", iccid)) return &resInfo, nil } // 批量获取SIM卡数据用量信息 // month 格式YYYYMM exp.202301 func QueryBatchSimCardDataInfo(iccidList []string, month string) ([]domain.AcceleronixSimCardDataUsageInfoResponse, error) { res, err := acceleronixHttpPost("/sim/batchQueryMonthData", domain.AcceleronixBatchDataUsageRequestBody{ Iccids: iccidList, Month: month, }) if err != nil { zap.L().Error("QueryBatchSimCardDataInfo failed.", zap.String("err", err.Error())) return nil, err } // 处理多种格式Body(成功:数组,失败:Struct) bodyBytes := bytes.TrimSpace(res.Body) if len(bodyBytes) == 0 { zap.L().Error("QueryBatchSimCardDataInfo Body is empty.", zap.String("body", string(res.Body))) return nil, errors.New("QueryBatchSimCardDataInfo empty response body") } switch bodyBytes[0] { case '[': var result []domain.AcceleronixSimCardDataUsageInfoResponse if err := json.Unmarshal(bodyBytes, &result); err != nil { zap.L().Error("QueryBatchSimCardDataInfo Unmarshal failed.", zap.String("err", err.Error()), zap.String("body", string(res.Body))) return nil, err } zap.L().Debug("QueryBatchSimCardDataInfo", zap.Strings("GICCIDs", iccidList), zap.String("month", month)) return result, nil case '{': var apiErr domain.AcceleronixResponseError if err := json.Unmarshal(bodyBytes, &apiErr); err == nil { zap.L().Error("QueryBatchSimCardDataInfo Error struct unmarshal failed.", zap.String("body", string(res.Body))) return nil, err } zap.L().Error("QueryBatchSimCardDataInfo AcceleronixResponseError", zap.Int("Code", apiErr.Code), zap.String("Msg", apiErr.Msg)) return nil, errors.New("QueryBatchSimCardDataInfo AcceleronixResponseError") default: return nil, errors.New("QueryBatchSimCardDataInfo invalid body") } } // 查询流量池列表 func QueryDataPoolList(page uint, size uint) (*domain.AcceleronixDataPoolListResponse, error) { res, err := acceleronixHttpPost("/dataPool/page", domain.AcceleronixDataPoolListRequestBody{ PageNum: page, PageSize: size, }) if err != nil { zap.L().Error("QueryDataPoolList failed.", zap.String("err", err.Error())) return nil, err } var resList domain.AcceleronixDataPoolListResponse if err := json.Unmarshal(res.Body, &resList); err != nil { zap.L().Error("QueryDataPoolList Unmarshal failed.", zap.String("err", err.Error()), zap.String("body", string(res.Body))) return nil, err } zap.L().Debug("QueryDataPoolList", zap.Int("DataNum", len(resList.Data.List)), zap.Int64("Page", resList.Data.Current), zap.Int64("Size", resList.Data.Size), zap.Int64("Total", resList.Data.Total)) return &resList, nil } // 查询流量池SIM详情 func QueryDataPoolSimInfo(dataPoolId string, page uint, size uint) (*domain.AcceleronixDataPoolSimInfoResponse, error) { res, err := acceleronixHttpPost("/dataPool/detail", map[string]interface{}{ "dataPoolId": dataPoolId, "pageNum": page, "pageSize": size, }) if err != nil { zap.L().Error("QueryDataPoolSimInfo failed.", zap.String("err", err.Error())) return nil, err } var resInfo domain.AcceleronixDataPoolSimInfoResponse if err := json.Unmarshal(res.Body, &resInfo); err != nil { zap.L().Error("QueryDataPoolSimInfo Unmarshal failed.", zap.String("err", err.Error()), zap.String("body", string(res.Body))) return nil, err } zap.L().Debug("QueryDataPoolSimInfo", zap.String("PoolId", dataPoolId), zap.Int("DataNum", len(resInfo.Data.List)), zap.Int64("Page", resInfo.Data.Current), zap.Int64("Size", resInfo.Data.Size), zap.Int64("Total", resInfo.Data.Total)) return &resInfo, nil }