| | |
| | | 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; |
| | | import org.springblade.jfpt.parcel.util.HttpClientUtils; |
| | |
| | | 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; |
| | | |
| | |
| | | @Value("${PARCEL_DETAIL_RUL}") |
| | | private String PARCEL_DETAIL_RUL; |
| | | |
| | | @Value("${PARCEL_KIND_URL}") |
| | | private String PARCEL_KIND_URL; |
| | | |
| | | @Value("${PARCEL_PRE_URL}") |
| | | private String PARCEL_PRE_URL; |
| | | |
| | | |
| | | |
| | | /** |
| | |
| | | //将所有的违禁包裹编码存起来 |
| | | 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()) { |
| | |
| | | //12.封装数据 |
| | | list.add(listTime); |
| | | list.add(parcelList); |
| | | list.add(getKindServenDataList()); |
| | | list.add(getKindServenDataList(conditionVo)); |
| | | //13.返回 |
| | | return list; |
| | | } |
| | |
| | | String startDate = null; |
| | | String endDate = null; |
| | | //2.2查询本天的数据 |
| | | if (conditionVo.getStatus() == 0) { |
| | | //3.获取本天开始时间和结束时间 |
| | | startDate = DateUtils.getToday(); |
| | | endDate = DateUtils.getToday(); |
| | | if (null!=conditionVo.getStatus()) { |
| | | if (conditionVo.getStatus() == 0) { |
| | | //3.获取本天开始时间和结束时间 |
| | | startDate = DateUtils.getToday(); |
| | | endDate = DateUtils.getToday(); |
| | | } |
| | | //2.2查询过去6天及当天的的数据 |
| | | if (conditionVo.getStatus() == 1) { |
| | | //3.获取过去6天及当天开始时间和结束时间 |
| | | startDate = DateUtils.getPastDate(6, now()); |
| | | endDate = DateUtils.getToday(); |
| | | } |
| | | //2.4查询本周的数据 |
| | | if (conditionVo.getStatus() == 3) { |
| | | //3.获取过去6天及当天开始时间和结束时间 |
| | | startDate = DateUtils.getWeekStart(); |
| | | endDate = DateUtils.getWeekEnd(); |
| | | } |
| | | //2.2查询本月的数据 |
| | | if (conditionVo.getStatus() == 2) { |
| | | //3.获取本月开始时间和结束时间 |
| | | startDate = DateUtils.getMonthStart(); |
| | | endDate = DateUtils.getMonthEnd(); |
| | | } |
| | | } |
| | | //2.2查询过去6天及当天的的数据 |
| | | if (conditionVo.getStatus() == 1) { |
| | | //3.获取过去6天及当天开始时间和结束时间 |
| | | startDate = DateUtils.getPastDate(6,now()); |
| | | endDate = DateUtils.getToday(); |
| | | } |
| | | //2.4查询本周的数据 |
| | | if (conditionVo.getStatus() == 3) { |
| | | //3.获取过去6天及当天开始时间和结束时间 |
| | | startDate = DateUtils.getWeekStart(); |
| | | endDate = DateUtils.getWeekEnd(); |
| | | } |
| | | //2.2查询本月的数据 |
| | | if (conditionVo.getStatus() == 2) { |
| | | //3.获取本月开始时间和结束时间 |
| | | startDate = DateUtils.getMonthStart(); |
| | | endDate = DateUtils.getMonthEnd(); |
| | | //2.5 按时间条件查询 |
| | | if (null!=conditionVo.getStartTime() && conditionVo.getStartTime()!="" |
| | | && null != conditionVo.getEndTime() && conditionVo.getEndTime()!=""){ |
| | | startDate = conditionVo.getStartTime().substring(0,10); |
| | | System.out.println("startDate = " + startDate); |
| | | endDate = conditionVo.getEndTime().substring(0,10); |
| | | System.out.println("endDate = " + endDate); |
| | | } |
| | | map.put("startDate", startDate); |
| | | map.put("endDate", endDate); |
| | |
| | | |
| | | /** |
| | | * 查询包裹,违禁品总数 |
| | | * @param status 状态码 0:本天 1:本周 2:本月 |
| | | * @param conditionVo status 状态码 0:本天 1:本周 2:本月 |
| | | * @return |
| | | */ |
| | | @Override |
| | | public List<Integer> selectParcelCount(Integer status) { |
| | | public List<Integer> selectParcelCount(ConditionVo conditionVo) { |
| | | List<Integer> list = new ArrayList<>(); |
| | | ConditionVo conditionVo = new ConditionVo(); |
| | | conditionVo.setStatus(status); |
| | | //获取包裹数据 |
| | | List<Object> parcelData = getParcelData(conditionVo, PARCEL_URL, PARCEL_KEY, PARCEL_SECRET); |
| | | if (null!=parcelData) { |
| | | //查询当天的包裹总数 |
| | | Integer dangerCount = null; |
| | | Integer contrabandCount = null; |
| | | if (status == 0) { |
| | | conditionVo.setStatus(0); |
| | | if (conditionVo.getStatus() == 0) { |
| | | for (Object object : parcelData) { |
| | | //取出list里面的值转为map |
| | | Map<String, Object> objectMap = (Map<String, Object>) object; |
| | |
| | | * @return |
| | | */ |
| | | @Override |
| | | public Map<String, Object> selectParcelData() { |
| | | public Map<String, Object> selectParcelData(ConditionVo conditionVo) { |
| | | HashMap<String, Object> map = new HashMap<>(); |
| | | map.put("parcelData",getKindServenDataList()); |
| | | map.put("parcelData",getKindServenDataList(conditionVo)); |
| | | return map; |
| | | } |
| | | |
| | |
| | | * 获取危险违禁品7天内每天的数量集合 |
| | | * @return |
| | | */ |
| | | public List<Integer> getKindServenDataList(){ |
| | | ConditionVo conditionVo = new ConditionVo(); |
| | | conditionVo.setStatus(1);//近7天status 为 1 |
| | | public List<Integer> getKindServenDataList(ConditionVo conditionVo){ |
| | | if (null==conditionVo){ |
| | | conditionVo.setStatus(1);//近7天status 为 1 |
| | | } |
| | | //获取数据 |
| | | List<Object> objectList = getParcelData(conditionVo,PARCEL_CONTRABAND_URL,PARCEL_KEY,PARCEL_SECRET); |
| | | if (null!=objectList) { |
| | |
| | | * @return |
| | | */ |
| | | @Override |
| | | public Map<String, String> getParcelPic(String imgUrl) { |
| | | public Map<String, Object> getParcelPic(String imgUrl) { |
| | | //截取图片imgKey信息 |
| | | String[] imgKeys = imgUrl.split("=", imgUrl.length()); |
| | | String imgKey = imgKeys[1]; |
| | |
| | | map.put("imgKey",imgKey); |
| | | //执行http远程调用 |
| | | String s = HttpClientUtils.doGetHeaderPictureBase64(PARCEL_PICTURE_URL, PARCEL_KEY, PARCEL_SECRET, map); |
| | | map.put("imgBase64",s); |
| | | return map; |
| | | //获取图片的长宽 |
| | | Map<String, Object> imageMap = ImageUtil.getBase64ImageWidthAndHeight(s); |
| | | //封装数据 |
| | | imageMap.put("imgBase64",s); |
| | | //返回 |
| | | return imageMap; |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | @Override |
| | | public Object getParcelDetailPage(ConditionVo conditionVo) { |
| | | String result = getParcelDataPageList(conditionVo, PARCEL_DETAIL_RUL, PARCEL_KEY, PARCEL_SECRET).get("result").toString(); |
| | | Map<String,Object> result =(Map<String,Object>) getParcelDataPageList(conditionVo, PARCEL_DETAIL_RUL, PARCEL_KEY, PARCEL_SECRET).get("result"); |
| | | if (null!=result) { |
| | | return JSONObject.parse(result); |
| | | // List<Object> dataList = JSONArray.parseArray(result.get("data").toString()); |
| | | // System.out.println("dataList = " + dataList); |
| | | // //遍历集合 |
| | | // for (Object data:dataList) { |
| | | // Map<String,Object> parcelData =(Map<String,Object>)data; |
| | | // String imgUrl = parcelData.get("imgUrl").toString(); |
| | | // //查询图片 PARCEL_PRE_URL |
| | | // //截取图片imgKey信息 |
| | | // String[] imgKeys = imgUrl.split("=", imgUrl.length()); |
| | | // String imgKey = imgKeys[1]; |
| | | // //封装成map对象 |
| | | // HashMap<String, String> map = new HashMap<>(); |
| | | // map.put("imgKey",imgKey); |
| | | // //执行http远程调用 |
| | | // String s = HttpClientUtils.doGetHeaderPictureBase64(PARCEL_PICTURE_URL, PARCEL_KEY, PARCEL_SECRET, map); |
| | | // //封装数据 |
| | | // if (null!=s && s!="") { |
| | | // parcelData.put("imgUrl", s); |
| | | // } |
| | | // } |
| | | return JSONObject.parse(result.toString()); |
| | | |
| | | } |
| | | return null; |
| | | } |
| | |
| | | */ |
| | | @Override |
| | | public Object getParcelkindDetailPage(ConditionVo conditionVo) { |
| | | conditionVo.setDecisioDiagramResult("contraband"); |
| | | Map<Object, Object> map = new HashMap<>(); |
| | | List<Object> list = new ArrayList<>(); |
| | | //获取违禁包裹数据 |
| | | Map<String,Object> result = (Map<String,Object>)getParcelDataPageList(conditionVo, PARCEL_DETAIL_RUL, PARCEL_KEY, PARCEL_SECRET).get("result"); |
| | | //获取违禁品数据 |
| | | String result = getParcelDataPageList(conditionVo, PARCEL_KIND_URL, PARCEL_KEY, PARCEL_SECRET).get("result").toString(); |
| | | if (null!=result) { |
| | | //获取总违禁包裹数量 |
| | | Integer totalSize = Integer.parseInt(result.get("totalSize").toString()); |
| | | int total = totalSize/conditionVo.getCurrentPage() +1 ; |
| | | for (int i = 0;i<total;i++){ |
| | | conditionVo.setCurrentPage(i+1); |
| | | //获取违禁包裹数据 |
| | | Map<String,Object> resultData = (Map<String,Object>)getParcelDataPageList(conditionVo, PARCEL_DETAIL_RUL, PARCEL_KEY, PARCEL_SECRET).get("result"); |
| | | //提取违禁品数据 |
| | | List<Object> dataList = JSON.parseArray(resultData.get("data").toString()); |
| | | for (Object data : dataList) { |
| | | //取出list里面的值转为map |
| | | Map<String, Object> objectMap = (Map<String, Object>) data; |
| | | //获取违禁包裹名称,包裹Id,包裹图片,过机时间 |
| | | String checkMachineName = objectMap.get("checkMachineName").toString(); |
| | | String packageId = objectMap.get("packageId").toString(); |
| | | String imgUrl = objectMap.get("imgUrl").toString(); |
| | | String samplingTime = objectMap.get("samplingTime").toString(); |
| | | //获取违禁品集合数据 |
| | | List<Object> detailVoList = JSON.parseArray(objectMap.get("coordsDetailVoList").toString()); |
| | | //遍历违禁品集合数据 |
| | | for (Object detailVo : detailVoList) { |
| | | //封装违禁包裹信息 |
| | | Map<String, Object> detailVoMap = (Map<String, Object>) detailVo; |
| | | detailVoMap.put("checkMachineName", checkMachineName); |
| | | detailVoMap.put("packageId", packageId); |
| | | detailVoMap.put("imgUrl", imgUrl); |
| | | detailVoMap.put("samplingTime", samplingTime); |
| | | list.add(detailVoMap); |
| | | } |
| | | } |
| | | } |
| | | //对组装好的违禁品集合数据排序,按时间 |
| | | //分页 |
| | | List<Object> listPaging = PageList.getListPaging(list, conditionVo.getCurrentPage(), conditionVo.getPageSize()); |
| | | //封装数据 |
| | | map.put("totalSize", list.size()); |
| | | map.put("data", listPaging); |
| | | map.put("currentPage", conditionVo.getCurrentPage()); |
| | | map.put("pageSize", conditionVo.getPageSize()); |
| | | //返回数据 |
| | | return map; |
| | | return JSONObject.parse(result); |
| | | } |
| | | return null; |
| | | } |
| | |
| | | map.put("pageSize", conditionVo.getPageSize()); |
| | | } |
| | | //3.远程调用api 获取数据 |
| | | String params = HttpClientUtils.httpPost(PARCEL_DETAIL_RUL, PARCEL_KEY, PARCEL_SECRET, map); |
| | | String params = HttpClientUtils.httpPost(url, key, secret, map); |
| | | Map<String,Object> paramsMap = (Map<String, Object>) JSONObject.parse(params); |
| | | if (paramsMap.get("succ").toString().equals("ok")){ |
| | | //4返回数据 |
| | |
| | | return null; |
| | | } |
| | | |
| | | /** |
| | | * 查询当前时间段违禁品总个数 |
| | | * @param conditionVo |
| | | * @return |
| | | */ |
| | | @Override |
| | | 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; |
| | | } |
| | | } |