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;