Java、SpringBoot请求第三方分页接口,获取全部数据。

  /**
     * 车辆抵扣明细报表查询
     */
    @Override
    public void getCouponInfoList() {
        String url = parkingConfig.getUrl() + "/api/wec/GetCouponInfoList";
        ParkingDefaultRequestParameters parkingDefaultRequestParameters = setDefaultParams();
        parkingDefaultRequestParameters.setServiceCode("getCouponInfoList");
        Date endTime = MzDateUtil.beforeMinute(MzDateUtil.nowHour(), 1);
        Date startTime = MzDateUtil.beforeMinute(endTime, 58);
        parkingDefaultRequestParameters.setStartTime(startTime);
        parkingDefaultRequestParameters.setEndTime(endTime);
        int pageIndex = 1;
        int pageSize = 1000;
        ParkCouponInfoListSo so = new ParkCouponInfoListSo();
        while (true) {
            setPageParams(parkingDefaultRequestParameters, pageIndex, pageSize);
            JSONObject jsonObject = JSONObject.parseObject(JSONObject.toJSONString(parkingDefaultRequestParameters));
            jsonObject.put("key", SignUtils.paramsSign(jsonObject, parkingConfig.getSecret()));
            JSONObject post = parkingRestServerUtils.post(url, jsonObject);
            if (ObjectUtil.isNull(post)) {
                break;
            }
            ParkCouponInfoListSo tempParkCouponInfoListSo = post.toJavaObject(ParkCouponInfoListSo.class);
            Date nowDate = MzDateUtil.getNowDate();
            Map<String, Integer> dateYYMMDDHH = getDateYYMMDDHH(startTime);
            for (ParkCouponInfoList item : tempParkCouponInfoListSo.getCouponList()) {
                item.setCreateTime(nowDate);
                item.setReportTime(startTime);
                item.setReportYear(dateYYMMDDHH.get(MY_YEAR));
                item.setReportMonth(dateYYMMDDHH.get(MY_MONTH));
                item.setReportDay(dateYYMMDDHH.get(MY_DAY));
                item.setReportHour(dateYYMMDDHH.get(MY_HOUR));
            }
            so.getCouponList().addAll(tempParkCouponInfoListSo.getCouponList());
            //请求完全部数据
            if (tempParkCouponInfoListSo.getCouponList().size() < pageSize) {
                break;
            } else {
                //请求下一页
                pageIndex++;
            }
        }
        if (CollectionUtil.isNotEmpty(so.getCouponList())) {
            ParkCouponInfoList db = parkCouponInfoListMapper.selectParkCouponInfoListByTime(so.getCouponList().get(0));
            if (ObjectUtil.isNull(db)) {
                parkCouponInfoListMapper.batchInsertParkCouponInfoList(so);
            }
        }
    }

你可能感兴趣的:(Java,java,spring,boot,开发语言)