From 6c754049b8dc302049e9e95e08843984c9614816 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=85=B4=E7=90=B3?= <1911390090@qq.com> Date: Wed, 3 Jul 2024 17:20: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=B0=8F=E6=97=B6=E5=85=A5=E4=B8=80=E6=AC=A1=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...DcTimingOfTrafficConditionsController.java | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 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 29c88a5a..d2b000c6 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 @@ -11,6 +11,8 @@ import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; import java.io.IOException; +import java.util.Calendar; +import java.util.Date; /** *路况信息 每小时入一次库 @@ -24,13 +26,27 @@ public class DcTimingOfTrafficConditionsController { // 调用服务层方法,获取当前交通指标数据 @Scheduled(cron = "0 0 * * * *") + //@Scheduled(cron = "0 0/1 * * * ?") public void getTheCurrentCongestedSection() throws HttpException, IOException { // 调用服务层方法,获取当前交通指标数据 JSONArray jsonArray = dcTrafficStatisticsService.getTheCurrentCongestedSection(); //插入 数据库 DcRoadConditionInformation dcRoadConditionInformation =new DcRoadConditionInformation(); dcRoadConditionInformation.setOtherConfig(jsonArray.toJSONString()); - dcRoadConditionInformationService.insertDcRoadConditionInformation(dcRoadConditionInformation); + DcRoadConditionInformation dcRoadConditionInformation1 = dcRoadConditionInformationService.selectlistTime().get(0); + Date createTime = dcRoadConditionInformation1.getCreateTime(); + Calendar createTimeCalendar = Calendar.getInstance(); + createTimeCalendar.setTime(createTime); +// 获取 createTime 的小时 + int createHour = createTimeCalendar.get(Calendar.HOUR_OF_DAY); +// 获取当前时间的小时 + Calendar currentCalendar = Calendar.getInstance(); + int currentHour = currentCalendar.get(Calendar.HOUR_OF_DAY); + if (createHour != currentHour) { + dcRoadConditionInformationService.insertDcRoadConditionInformation(dcRoadConditionInformation); + } + } + // 将获取到的交通指标数据封装为成功的结果并返回 - } + }