美文网首页
定时同步调用分页数据到本地批量入库

定时同步调用分页数据到本地批量入库

作者: IT男的假智慧 | 来源:发表于2021-03-22 09:17 被阅读0次

public ResultaddPlatformProject(String areaId) {

    List<PlatformProject> arrayList =new ArrayList<>();

    int received=0;

    Integer page=0;

    Integer size=100;

    Integer total=0;

    try {

        do {

            JSONObject requestJson =new JSONObject();

            requestJson.put("pageNo", page);

            requestJson.put("pageSize", size);

            requestJson.put("StartTime", "2000-01-01 00:00:00");

            String requestStr = requestJson.toJSONString();

            JSONObject resultJson = requestDeviceData(true, "url", requestStr);

            JSONObject data = resultJson.getJSONObject("data");

            JSONArray jsonArray = data.getJSONArray("list");

            total = data.getInteger("totalSize");

            received+=jsonArray.size();

            if (jsonArray.size()==0){

                break;

            }

            JSONArray jsonArray1 = data.getJSONArray("list");

            for (int j =0; j < jsonArray1.size(); j++) {

                JSONObject itemJson = jsonArray.getJSONObject(j);

                PlatformProject platformDate =new PlatformProject();

                platformDate.setProjectId(itemJson.getString("id"));

                platformDate.setName(itemJson.getString("name"));

                platformDate.setAreaId(itemJson.getString("areaId"));

                platformDate.setCode(itemJson.getString("code"));

                platformDate.setLocationStr(itemJson.getString("locationStr"));

                arrayList.add(platformDate);

            }

            page++;

        }while (received<=total);

        //去重

        List<PlatformProject> unique = arrayList.stream().collect(collectingAndThen(toCollection(() ->new TreeSet<>(Comparator.comparing(PlatformProject::getCode))), ArrayList::new));

        platformProjectMapper.delPlatformProjectByAll();

        insertBatch(unique);

        return Response.response(unique);

    } catch (Exception e) {

        log.error("工程设备大屏-获取集成平台区域数据失败", e);

        return Response.response(arrayList);

    }

}

相关文章

网友评论

      本文标题:定时同步调用分页数据到本地批量入库

      本文链接:https://www.haomeiwen.com/subject/afrbcltx.html