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;
|
}
|
}
|