济菏高速数据中心代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

59 lines
2.7 KiB

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;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.io.IOException;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
/**
*路况信息 每小时入一次库
*/
@Component
public class DcTimingOfTrafficConditionsController {
@Autowired
private IDcTrafficStatisticsService dcTrafficStatisticsService;
@Autowired
private IDcRoadConditionInformationService dcRoadConditionInformationService;
// 调用服务层方法,获取当前交通指标数据
@Scheduled(cron = "0 0/30 * * * *")
//@Scheduled(cron = "0 0/1 * * * ?")
public void getTheCurrentCongestedSection() throws HttpException, IOException {
// 调用服务层方法,获取当前交通指标数据
JSONArray jsonArray = dcTrafficStatisticsService.getTheCurrentCongestedSection();
//插入 数据库
DcRoadConditionInformation dcRoadConditionInformation =new DcRoadConditionInformation();
dcRoadConditionInformation.setOtherConfig(jsonArray.toJSONString());
List<DcRoadConditionInformation> 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 createMinute = createTimeCalendar.get(Calendar.MINUTE);// 获取当前时间的小时
Calendar currentCalendar = Calendar.getInstance();
int currentMinute = currentCalendar.get(Calendar.MINUTE);
if (createMinute != currentMinute) {
dcRoadConditionInformationService.insertDcRoadConditionInformation(dcRoadConditionInformation);
}
}
}
// 将获取到的交通指标数据封装为成功的结果并返回
}