From eb3440d7c0c7baef5e6fc888fd0076b1787643d9 Mon Sep 17 00:00:00 2001
From: Administrator <admin>
Date: Wed, 07 Apr 2021 16:14:18 +0800
Subject: [PATCH] 预警时间分布接口新增
---
blade-service/blade-jfpts/src/main/java/org/springblade/jfpt/parcel/service/impl/ParcelServiceImpl.java | 121 ++++++++++++++++++++++++++++++++++++++++
1 files changed, 120 insertions(+), 1 deletions(-)
diff --git a/blade-service/blade-jfpts/src/main/java/org/springblade/jfpt/parcel/service/impl/ParcelServiceImpl.java b/blade-service/blade-jfpts/src/main/java/org/springblade/jfpt/parcel/service/impl/ParcelServiceImpl.java
index bca65ef..d44455b 100644
--- a/blade-service/blade-jfpts/src/main/java/org/springblade/jfpt/parcel/service/impl/ParcelServiceImpl.java
+++ b/blade-service/blade-jfpts/src/main/java/org/springblade/jfpt/parcel/service/impl/ParcelServiceImpl.java
@@ -4,6 +4,7 @@
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import io.swagger.models.auth.In;
+import org.springblade.jfpt.alarm.constant.AlarmTimeConstant;
import org.springblade.jfpt.animalheat.util.ImageUtil;
import org.springblade.jfpt.parcel.service.ParcelService;
import org.springblade.jfpt.parcel.util.DateUtils;
@@ -14,8 +15,10 @@
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
+import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
+import java.util.stream.Collectors;
import static org.springblade.core.tool.utils.DateUtil.now;
@@ -69,7 +72,6 @@
//将所有的违禁包裹编码存起来
mapCode.put(objectMap.get("objCode").toString(),objectMap.get("objCode").toString());
}
- System.out.println("mapCode = " + mapCode);
//遍历违禁编码map数据
List<Map<String,Object>> list = new ArrayList<>();
for (String value:mapCode.values()) {
@@ -434,4 +436,121 @@
public Integer selParcelTimeCount(ConditionVo conditionVo) {
return selectParcelCount(conditionVo).get(1);
}
+
+ /**
+ *查询当前时间段区间时间违禁品个数
+ * @param conditionVo
+ * @return
+ */
+ @Override
+ public List<Integer> selParcelTimeDis(ConditionVo conditionVo) {
+ ArrayList<List<Object>> objectArrayList = new ArrayList<>();
+ //设置页码数
+ conditionVo.setCurrentPage(1);
+ conditionVo.setPageSize(100);
+ //获取数据
+ Map<String,Object> result =(Map<String,Object>) getParcelDataPageList(conditionVo, PARCEL_KIND_URL, PARCEL_KEY, PARCEL_SECRET).get("result");
+ if (null!=result) {
+ List<Object> dataList = JSONArray.parseArray(result.get("data").toString());
+ objectArrayList.add(dataList);
+ //取第一次获取到的数据总数,每次取100条,多于100分批次取
+ int totalSize = Integer.parseInt(result.get("totalSize").toString());
+ int i = totalSize/100+1;
+ if (i>1){
+ for (int j=1;j<i;j++) {
+ conditionVo.setCurrentPage(j+1);
+ //获取数据
+ Map<String,Object> result0 =(Map<String,Object>) getParcelDataPageList(conditionVo, PARCEL_KIND_URL, PARCEL_KEY, PARCEL_SECRET).get("result");
+ List<Object> dataLists = JSONArray.parseArray(result0.get("data").toString());
+ objectArrayList.add(dataLists);
+ }
+ }
+ //合并集合
+ List<Object> collect = objectArrayList.stream().flatMap(List::stream).collect(Collectors.toList());
+ //筛选数据,返回数据
+ return getParcelTimeDis(collect);
+ }
+ return Arrays.asList(0,0,0,0,0,0,0,0,0,0,0,0);
+ }
+
+ /**
+ * 筛选数据,分类返回
+ * @param collect 集合数据
+ * @return
+ */
+ private List<Integer> getParcelTimeDis(List<Object> collect) {
+ List<Integer> list = new ArrayList<>();
+ int count02 = 0;
+ int count0204 = 0;
+ int count0406 = 0;
+ int count0608 = 0;
+ int count0810 = 0;
+ int count1012 = 0;
+ int count1214 = 0;
+ int count1416 = 0;
+ int count1618 = 0;
+ int count1820 = 0;
+ int count2022 = 0;
+ int count2224 = 0;
+ //遍历集合
+ for (Object data:collect) {
+ Map<String,Object> parcelData =(Map<String,Object>)data;
+ try {
+ long hours = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(parcelData.get("createTime").toString()).getHours();
+ if (hours>0 && hours< AlarmTimeConstant.TWO){
+ count02+=1;
+ }
+ if (hours>=AlarmTimeConstant.TWO && hours<AlarmTimeConstant.FOUR){
+ count0204+=1;
+ }
+ if (hours>=AlarmTimeConstant.FOUR && hours<AlarmTimeConstant.SIX){
+ count0406+=1;
+ }
+ if (hours>=AlarmTimeConstant.SIX && hours<AlarmTimeConstant.EIGHT){
+ count0608+=1;
+ }
+ if (hours>=AlarmTimeConstant.EIGHT && hours<AlarmTimeConstant.TEN){
+ count0810+=1;
+ }
+ if (hours>=AlarmTimeConstant.TEN && hours<AlarmTimeConstant.TWEKVE){
+ count1012+=1;
+ }
+ if (hours>=AlarmTimeConstant.TWEKVE && hours<AlarmTimeConstant.FOURTEEN){
+ count1214+=1;
+ }
+ if (hours>=AlarmTimeConstant.FOURTEEN && hours<AlarmTimeConstant.SIXTEEN){
+ count1416+=1;
+ }
+ if (hours>=AlarmTimeConstant.SIXTEEN && hours<AlarmTimeConstant.EIGHTEEN){
+ count1618+=1;
+ }
+ if (hours>=AlarmTimeConstant.EIGHTEEN && hours<AlarmTimeConstant.TWENTY){
+ count1820+=1;
+ }
+ if (hours>=AlarmTimeConstant.TWENTY && hours<AlarmTimeConstant.TWENTY_TWO){
+ count2022+=1;
+ }
+ if (hours>=AlarmTimeConstant.TWENTY_TWO && hours<AlarmTimeConstant.TWENTY_FOUR){
+ count2224+=1;
+ }
+ } catch (ParseException e) {
+ e.printStackTrace();
+ }
+ }
+ //封装数据
+ list.add(count02);
+ list.add(count0204);
+ list.add(count0406);
+ list.add(count0608);
+ list.add(count0810);
+ list.add(count1012);
+ list.add(count1214);
+ list.add(count1416);
+ list.add(count1618);
+ list.add(count1820);
+ list.add(count2022);
+ list.add(count2224);
+ //返回数据
+ return list;
+ }
}
--
Gitblit v1.9.3