From f60de37e3bec3d7dcd37d58894b607a53ce4bf9a Mon Sep 17 00:00:00 2001 From: lau572 <1010031226@qq.com> Date: Fri, 27 Dec 2024 18:48:10 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=80=E7=B1=BB=E4=BA=A4=E8=B0=83=E5=B0=8F?= =?UTF-8?q?=E6=97=B6=E6=95=B0=E6=8D=AE=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DcTrafficSurveyDataController.java | 43 +++++++++++++++---- 1 file changed, 35 insertions(+), 8 deletions(-) diff --git a/zc-business/src/main/java/com/zc/business/controller/DcTrafficSurveyDataController.java b/zc-business/src/main/java/com/zc/business/controller/DcTrafficSurveyDataController.java index f2137da0..fbdec4a8 100644 --- a/zc-business/src/main/java/com/zc/business/controller/DcTrafficSurveyDataController.java +++ b/zc-business/src/main/java/com/zc/business/controller/DcTrafficSurveyDataController.java @@ -103,9 +103,22 @@ public class DcTrafficSurveyDataController extends BaseController Object data = null; AjaxResult ajaxResult = dcDeviceController.queryDeviceProperties(dcDevice.getIotDeviceId(), propertyId, props); - if (ajaxResult.get("code").equals(UniversalEnum.TWO_HUNDRED.getNumber()) && ajaxResult.containsKey("data") && ajaxResult.get("data") != null) { - data = JSON.parseObject(ajaxResult.get("data").toString()).get("data"); - } else { + try { + if (ajaxResult.get("code").equals(UniversalEnum.TWO_HUNDRED.getNumber()) && ajaxResult.containsKey("data") && ajaxResult.get("data") != null) { + data = JSON.parseObject(ajaxResult.get("data").toString()).get("data"); + } else { + //超时、错误等异常状态,放入缓存下次定时执行时再次请求一遍 + Map cacheMap = new HashMap<>(); + cacheMap.put("iotDeviceId",dcDevice.getIotDeviceId()); + cacheMap.put("stakeMark",dcDevice.getStakeMark()); + cacheMap.put("startTime",startTime); + cacheMap.put("endTime",endTime); + cacheMap.put("count",3); //剩余请求次数 + redisCache.setCacheMapValue(RedisKeyConstants.TRAFFIC_SURVEY_HOURS_DATA,dcDevice.getIotDeviceId()+startTime,cacheMap); + break; + } + } catch (Exception e){ + e.printStackTrace(); //超时、错误等异常状态,放入缓存下次定时执行时再次请求一遍 Map cacheMap = new HashMap<>(); cacheMap.put("iotDeviceId",dcDevice.getIotDeviceId()); @@ -116,6 +129,7 @@ public class DcTrafficSurveyDataController extends BaseController redisCache.setCacheMapValue(RedisKeyConstants.TRAFFIC_SURVEY_HOURS_DATA,dcDevice.getIotDeviceId()+startTime,cacheMap); break; } + JSONArray dataArray = JSON.parseArray(data.toString()); if (dataArray == null || dataArray.size() < 1){ break; @@ -220,11 +234,23 @@ public class DcTrafficSurveyDataController extends BaseController props.put("sorts[0].name", "timestamp"); Object data = null; - AjaxResult ajaxResult = dcDeviceController.queryDeviceProperties(iotDeviceId, "01", props); - if (ajaxResult.get("code").equals(UniversalEnum.TWO_HUNDRED.getNumber()) && ajaxResult.containsKey("data") && ajaxResult.get("data") != null) { - data = JSON.parseObject(ajaxResult.get("data").toString()).get("data"); - redisCache.delCacheMapValue(RedisKeyConstants.TRAFFIC_SURVEY_HOURS_DATA,iotDeviceId+startTime); - } else { + try { + AjaxResult ajaxResult = dcDeviceController.queryDeviceProperties(iotDeviceId, "01", props); + if (ajaxResult.get("code").equals(UniversalEnum.TWO_HUNDRED.getNumber()) && ajaxResult.containsKey("data") && ajaxResult.get("data") != null) { + data = JSON.parseObject(ajaxResult.get("data").toString()).get("data"); + redisCache.delCacheMapValue(RedisKeyConstants.TRAFFIC_SURVEY_HOURS_DATA,iotDeviceId+startTime); + } else { + count--; + if (count < 1){ + redisCache.delCacheMapValue(RedisKeyConstants.TRAFFIC_SURVEY_HOURS_DATA,iotDeviceId+startTime); + } else { + value.put("count",count); + redisCache.setCacheMapValue(RedisKeyConstants.TRAFFIC_SURVEY_HOURS_DATA,iotDeviceId+startTime,value); + } + break; + } + } catch (Exception e){ + e.printStackTrace(); count--; if (count < 1){ redisCache.delCacheMapValue(RedisKeyConstants.TRAFFIC_SURVEY_HOURS_DATA,iotDeviceId+startTime); @@ -234,6 +260,7 @@ public class DcTrafficSurveyDataController extends BaseController } break; } + JSONArray dataArray = JSON.parseArray(data.toString()); if (dataArray == null || dataArray.size() < 1){ break;