包装接口,处理数据

    @RequestMapping(
            value = {"/rest/asset/getWaybillList/{orderCode}"},
            method = {RequestMethod.GET}
    )
    public Map<String,Object> getWaybillList(@PathVariable final String orderCode,Page page) {
        String url = "https://api.shciip.com/dw/lgs/waybill_detail?appCode=ed57b1dd35a74e99b2ea7cbd0fb55d26";
        HashMap<String, Object> paramMap = new HashMap<>();
        paramMap.put("pageNum",page.getPage());
        paramMap.put("pageSize",page.getPageSize());
        paramMap.put("order_code",orderCode);
        String result = HttpUtil.get(url,paramMap);

        Map<String, Object> resultMap = JSON.parseObject(result, new TypeReference<Map<String, Object>>() {});
        String dataString =  resultMap.get("data").toString();
        Map<String, Object> dataMap = JSON.parseObject(dataString, new TypeReference<Map<String, Object>>() {});
        Integer totalNum = (Integer) dataMap.get("totalNum");

        HashMap<String, Object> paramMap2 = new HashMap<>();
        paramMap2.put("pageNum",1);
        paramMap2.put("pageSize",totalNum);
        paramMap2.put("order_code",orderCode);
        String result2 = HttpUtil.get(url,paramMap);
        Map<String, Object> resultMap2 = JSON.parseObject(result2, new TypeReference<Map<String, Object>>() {});
        String dataString2 =  resultMap2.get("data").toString();
        Map<String, Object> dataMap2 = JSON.parseObject(dataString2, new TypeReference<Map<String, Object>>() {});
        String tempString = (String) dataMap2.get("rows").toString();
        List<Map<String, Object>> list = JSON.parseObject(tempString, new TypeReference<List<Map<String, Object>>>() {});
        Double totalAmount = 0.0;
        for (Map o : list){
            String str = o.get("delivery_amount").toString();
            Double temp = Double.valueOf(str);
            totalAmount += temp;
        }
        resultMap.put("totalAmount",totalAmount);

        return resultMap;
    }
		List<Map<String,Object>> list = JSON.parseObject(str, new TypeReference<List<Map<String, Object>>>() {});

你可能感兴趣的:(实战经验,java)