南昌市物联网技防平台-后台
Administrator
2021-03-10 5c595590ddbcbf6d121810c03f08f5c43730d645
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package org.springblade.jfpt.parcel.service.impl;
 
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.nacos.common.utils.JacksonUtils;
import org.springblade.jfpt.parcel.service.ParcelService;
import org.springblade.jfpt.parcel.util.HttpClientUtils;
import org.springblade.jfpt.parcel.util.JacksonUtil;
import org.springblade.jfpt.parcel.vo.ConditionVo;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import springfox.documentation.spring.web.json.Json;
 
import java.util.*;
 
/**
 * 包裹服务实现层
 */
@Service
public class ParcelServiceImpl implements ParcelService {
    @Value("${PARCEL_KEY}")
    private String PARCEL_KEY;
 
    @Value("${PARCEL_SECRET}")
    private String PARCEL_SECRET;
 
    @Value("${PARCEL_CONTRABAND_URL}")
    private String PARCEL_CONTRABAND_URL;
 
 
 
    /**
     * 获取查询条件
     * @param conditionVo 查询条件对象
     * @return
     */
    @Override
    public List<Map<String, Object>> parcelKindStatis(ConditionVo conditionVo) {
        //1.创建map对象,用于存储请求接口的秘钥
        Map<String, String> map = new HashMap<>();
         //2.时间不为空
        if (null!=conditionVo.getStartDate() && null!=conditionVo.getEndDate()) {
            map.put("startDate", conditionVo.getStartDate());
            map.put("endDate", conditionVo.getEndDate());
        }
        //3.调用远程接口获取数据
        String params = HttpClientUtils.httpPost(PARCEL_CONTRABAND_URL, PARCEL_KEY, PARCEL_SECRET, map);
        //4.数据转换
        Map<String,Object> data = (Map<String, Object>) JSONObject.parse(params);
        List<Object> objectList = JSON.parseArray(data.get("result").toString());
        //5.遍历,分别取出数据
        for (Object object:objectList) {
            Map <String,Object> objectMap = (Map<String, Object>) object;//取出list里面的值转为map
            System.out.println("liMap.get(\"objCode\") = " + objectMap.get("objCode"));
            System.out.println("liMap.get(\"objCode\") = " + objectMap.get("objCount"));
            System.out.println("liMap.get(\"objCode\") = " + objectMap.get("dateStr"));
            System.out.println("liMap.get(\"objCode\") = " + objectMap.get("objName"));
        }
 
        return null;
    }
}