| | |
| | | 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.DateUtils; |
| | | import org.springblade.jfpt.parcel.util.HttpClientUtils; |
| | | import org.springblade.jfpt.parcel.util.JacksonUtil; |
| | | import org.springblade.jfpt.parcel.vo.ConditionVo; |
| | |
| | | @Value("${PARCEL_CONTRABAND_URL}") |
| | | private String PARCEL_CONTRABAND_URL; |
| | | |
| | | @Value("${PARCEL_URL}") |
| | | private String PARCEL_URL; |
| | | |
| | | |
| | | |
| | | /** |
| | |
| | | */ |
| | | @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")); |
| | | //1.判空 |
| | | if (null!=conditionVo.getStatus()) { |
| | | //获取数据 |
| | | List<Object> objectList = getParcelData(conditionVo,PARCEL_CONTRABAND_URL,PARCEL_KEY,PARCEL_SECRET); |
| | | //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; |
| | | } |
| | | |
| | | /** |
| | | * 获取包裹统计数据,远程调用接口获取数据 |
| | | * @param conditionVo 查询条件对象 status 状态码 0:本天 1:本周 2:本月 |
| | | * @return |
| | | */ |
| | | @Override |
| | | public Object getParcelStatis(ConditionVo conditionVo) { |
| | | List<Object> list = new ArrayList<>();//返回 |
| | | //1.判空 |
| | | if (null!=conditionVo.getStatus()){ |
| | | //2.获取数据 |
| | | List<Object> objectList = getParcelData(conditionVo,PARCEL_URL,PARCEL_KEY,PARCEL_SECRET); |
| | | System.out.println("objectList = " + objectList); |
| | | //3.创建时间集合,包裹集合数据 |
| | | List<String> listTime = new ArrayList<>(); |
| | | List<Map<String,Object>> parcelList = new ArrayList<>(); |
| | | if (conditionVo.getStatus() == 1) { |
| | | //3.获取本周开始时间和结束时间的每一天数组 |
| | | listTime = DateUtils.pastDay(DateUtils.getWeekEnd()); |
| | | List<String> percelTimeList = new ArrayList<>(); |
| | | for (Object object:objectList) { |
| | | //4.取出list里面的值转为map |
| | | Map<String, Object> objectMap = (Map<String, Object>) object; |
| | | //5.将远程时间数据存入集合 |
| | | percelTimeList.add(objectMap.get("dateStr").toString()); |
| | | } |
| | | for (String time:listTime) { |
| | | //6.创建map,用于存储包裹数据 |
| | | HashMap<String, Object> hashMap = new HashMap<>(); |
| | | //7.如果远程数据哪天数据没有,则为0 |
| | | if (!percelTimeList.contains(time)){ |
| | | hashMap.put("dateStr",time); |
| | | hashMap.put("checkCount",0); |
| | | hashMap.put("dangerCount",0); |
| | | parcelList.add(hashMap); |
| | | }else { |
| | | //8.遍历,分别取出数据 |
| | | for (Object object : objectList) { |
| | | //9.取出list里面的值转为map |
| | | Map<String, Object> objectMap = (Map<String, Object>) object; |
| | | String dateStr = objectMap.get("dateStr").toString(); //安检时间 |
| | | Integer checkCount = Integer.parseInt(objectMap.get("checkCount").toString()); //安检包裹数量 |
| | | Integer dangerCount = Integer.parseInt(objectMap.get("dangerCount").toString()); //违禁包裹数量 |
| | | //10.判断,存入数据 |
| | | if (time.equals(dateStr)) { |
| | | Set<Map.Entry<String, Object>> entries = objectMap.entrySet(); |
| | | for (Map.Entry<String, Object> m : entries) { |
| | | if (m.getKey().equals("checkCount")) { |
| | | hashMap.put("checkCount", checkCount); |
| | | hashMap.put("dateStr", dateStr); |
| | | } |
| | | if (m.getKey().equals("dangerCount")) { |
| | | hashMap.put("dangerCount", dangerCount); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | //11.加入到集合中 |
| | | parcelList.add(hashMap); |
| | | } |
| | | } |
| | | } |
| | | //12.封装数据 |
| | | list.add(listTime); |
| | | list.add(parcelList); |
| | | //13.返回 |
| | | return list; |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 数据请求处理 |
| | | * @param conditionVo 条件 |
| | | * @param url url |
| | | * @param key 请求Key |
| | | * @param secret 请求 secret |
| | | * @return |
| | | */ |
| | | private List<Object> getParcelData(ConditionVo conditionVo, String url, String key, String secret) { |
| | | //1.创建map对象,用于存储请求接口的秘钥 |
| | | Map<String, String> map = new HashMap<>(); |
| | | String startDate = null; |
| | | String endDate = null; |
| | | //2.2查询本天的数据 |
| | | if (conditionVo.getStatus() == 0) { |
| | | //3.获取本天开始时间和结束时间 |
| | | startDate = DateUtils.getToday(); |
| | | endDate = DateUtils.getToday(); |
| | | } |
| | | //2.2查询本周内每天的数据 |
| | | if (conditionVo.getStatus() == 1) { |
| | | //3.获取本周开始时间和结束时间 |
| | | startDate = DateUtils.getWeekStart(); |
| | | endDate = DateUtils.getWeekEnd(); |
| | | } |
| | | //2.2查询本月的数据 |
| | | if (conditionVo.getStatus() == 2) { |
| | | //3.获取本月开始时间和结束时间 |
| | | startDate = DateUtils.getWeekStart(); |
| | | endDate = DateUtils.getWeekEnd(); |
| | | } |
| | | map.put("startDate", startDate); |
| | | map.put("endDate", endDate); |
| | | //4.远程调用数据 |
| | | String params = HttpClientUtils.httpPost(url, key, secret, map); |
| | | //5.数据转换 |
| | | Map<String, Object> data = (Map<String, Object>) JSONObject.parse(params); |
| | | return JSON.parseArray(data.get("result").toString()); |
| | | } |
| | | } |