Browse Source

路况信息 每小时入一次库

develop
王兴琳 5 months ago
parent
commit
6c754049b8
  1. 20
      zc-business/src/main/java/com/zc/business/controller/DcTimingOfTrafficConditionsController.java

20
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);
}
}
// 将获取到的交通指标数据封装为成功的结果并返回
}
}

Loading…
Cancel
Save