json格式分页处理

发布时间 2023-04-25 14:50:46作者: 我的心儿
点击查看代码
public static JSONArray sendByQCCGetListArrayString(JSONArray jsonArrayResult, BaseHttpService<String,String> baseHttpService, Map<String, String> map, OperatorBO operatorBO){
        try {
            map.put("pageIndex",1+"");
            if(map.get("PageSize")==null)
            map.put("PageSize","20");//分页数目,默认10条,最大不超过20条
            RestResult<String> json = baseHttpService.getChannelData("", HttpMethod.GET, operatorBO, map);
            JSONObject jsonObject = JSON.parseObject(json.getData());
            if("200".equals(json.getCode())){
                jsonArrayResult = new JSONArray();
                jsonArrayResult.add(0,jsonObject.getJSONObject("Paging"));
                jsonArrayResult.add(1,jsonObject.getJSONArray("Result"));
                if(jsonObject.getJSONObject("Paging")!=null&&jsonObject.getJSONObject("Paging").containsKey("TotalRecords")) {
                    int totalPages = jsonObject.getJSONObject("Paging").getIntValue("TotalRecords") % Integer.parseInt(map.get("PageSize")) == 0
                            ? jsonObject.getJSONObject("Paging").getIntValue("TotalRecords") / Integer.parseInt(map.get("PageSize"))
                            : jsonObject.getJSONObject("Paging").getIntValue("TotalRecords") / Integer.parseInt(map.get("PageSize")) + 1;
                    for (int i = 2; i <= totalPages; i++) {
                        map.put("pageIndex", i + "");
                        RestResult<String> jsons = baseHttpService.getChannelData("", HttpMethod.GET, operatorBO, map);
                        JSONObject jsonObjects = JSON.parseObject(jsons.getData());
                        if ("200".equals(json.getCode())) {
                            jsonArrayResult.add(i, jsonObjects.getJSONArray("Result"));
                        } else {
                            //结果如果失败,则置空结果集
                            jsonArrayResult = null;
                        }
                    }
                }
            }
        }catch (Exception e){
            log.info("get接口调用{}异常",map.toString(),e);
            e.printStackTrace();
            //结果如果失败,则置空结果集
            jsonArrayResult = null;
        }
        return jsonArrayResult;
    }

点击查看代码
 public TableDataInfo queryStrategyTaskList(@RequestBody PersonalGrantTaskDTO grantTaskDTO, HttpServletRequest request) {
        PageDomain pageDomain = TableSupport.buildPageRequest();
        Integer pageNum = pageDomain.getPageNum();
        Integer pageSize = pageDomain.getPageSize();
        List<PersonalGrantRecordVO> list = personalGrantRecordService.getTaskList(request, grantTaskDTO);
        int num = list.size();
        if (num > 0) {
            list = list.stream()
                    .skip((pageNum - 1) * pageSize)
                    .limit(pageSize)
                    .collect(Collectors.toList());
        }
        TableDataInfo rspData = new TableDataInfo();
        rspData.setCode(HttpStatus.SUCCESS);
        rspData.setRows(list);
        rspData.setTotal(num);
        return rspData;
    }