diff --git a/zc-business/src/main/java/com/zc/business/controller/DcTimingOfTrafficConditionsController.java b/zc-business/src/main/java/com/zc/business/controller/DcTimingOfTrafficConditionsController.java index d2b000c6..6655e47c 100644 --- a/zc-business/src/main/java/com/zc/business/controller/DcTimingOfTrafficConditionsController.java +++ b/zc-business/src/main/java/com/zc/business/controller/DcTimingOfTrafficConditionsController.java @@ -3,6 +3,7 @@ package com.zc.business.controller; import com.alibaba.fastjson.JSONArray; import com.ruoyi.common.core.domain.AjaxResult; import com.zc.business.domain.DcRoadConditionInformation; +import com.zc.business.enums.UniversalEnum; import com.zc.business.service.IDcRoadConditionInformationService; import com.zc.business.service.IDcTrafficStatisticsService; import com.zc.common.core.httpclient.exception.HttpException; @@ -13,6 +14,7 @@ import org.springframework.stereotype.Component; import java.io.IOException; import java.util.Calendar; import java.util.Date; +import java.util.List; /** *路况信息 每小时入一次库 @@ -25,7 +27,7 @@ public class DcTimingOfTrafficConditionsController { private IDcRoadConditionInformationService dcRoadConditionInformationService; // 调用服务层方法,获取当前交通指标数据 - @Scheduled(cron = "0 0 * * * *") + @Scheduled(cron = "0 0/30 * * * *") //@Scheduled(cron = "0 0/1 * * * ?") public void getTheCurrentCongestedSection() throws HttpException, IOException { // 调用服务层方法,获取当前交通指标数据 @@ -33,20 +35,25 @@ public class DcTimingOfTrafficConditionsController { //插入 数据库 DcRoadConditionInformation dcRoadConditionInformation =new DcRoadConditionInformation(); dcRoadConditionInformation.setOtherConfig(jsonArray.toJSONString()); - DcRoadConditionInformation dcRoadConditionInformation1 = dcRoadConditionInformationService.selectlistTime().get(0); - Date createTime = dcRoadConditionInformation1.getCreateTime(); + List dcRoadConditionInformations = dcRoadConditionInformationService.selectlistTime(); + if (dcRoadConditionInformations.size()==UniversalEnum.ZERO.getNumber()){ + dcRoadConditionInformationService.insertDcRoadConditionInformation(dcRoadConditionInformation); + }else { + DcRoadConditionInformation dcRoadConditionInformation1 = dcRoadConditionInformations.get(UniversalEnum.ZERO.getNumber()); + Date createTime = dcRoadConditionInformation1.getCreateTime(); Calendar createTimeCalendar = Calendar.getInstance(); createTimeCalendar.setTime(createTime); -// 获取 createTime 的小时 - int createHour = createTimeCalendar.get(Calendar.HOUR_OF_DAY); -// 获取当前时间的小时 + // 获取 createTime 的分钟 + int createMinute = createTimeCalendar.get(Calendar.MINUTE);// 获取当前时间的小时 Calendar currentCalendar = Calendar.getInstance(); - int currentHour = currentCalendar.get(Calendar.HOUR_OF_DAY); - if (createHour != currentHour) { + int currentMinute = currentCalendar.get(Calendar.MINUTE); + if (createMinute != currentMinute) { dcRoadConditionInformationService.insertDcRoadConditionInformation(dcRoadConditionInformation); } } + } + // 将获取到的交通指标数据封装为成功的结果并返回 }