From 3d8a61d24872f303a230d19420e12d550f1a923c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=85=B4=E7=90=B3?= <1911390090@qq.com> Date: Thu, 4 Jul 2024 18:44:23 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B7=AF=E5=86=B5=E4=BF=A1=E6=81=AF=20?= =?UTF-8?q?=E6=AF=8F=E5=8D=8A=E4=B8=AA=E5=B0=8F=E6=97=B6=E5=85=A5=E4=B8=80?= =?UTF-8?q?=E6=AC=A1=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...DcTimingOfTrafficConditionsController.java | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) 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); } } + } + // 将获取到的交通指标数据封装为成功的结果并返回 }