Commit 11b321ea authored by zhoushiguang's avatar zhoushiguang

路口缓行事件计算

parent f67f4c22
......@@ -18,5 +18,10 @@ import net.wanji.common.framework.mapper.BaseInterfaceMapper;
public interface EventInfoMapper extends BaseInterfaceMapper<EventInfo> {
List<Map<String,Object>> getListByStartAndEnd(Map<String, Object> map);
/**
* 路口缓行事件计算
*/
void insertCrossSlowRunEventData(@Param("startTime")String startTime,@Param("endTime")String endTime);
}
......@@ -19,4 +19,10 @@ public interface EventInfoService extends BaseDubboInterface<EventInfo> {
List<Map<String,Object>> getListByStartAndEnd(Map<String, Object> map);
/**
* 路口缓行事件计算
* @param startTime
* @param endTime
*/
void insertCrossSlowRunEventData(String startTime, String endTime);
}
......@@ -41,16 +41,27 @@ public class EventInfoServiceImpl extends BaseDubboInterfaceImpl<EventInfo> impl
return this.eventInfoMapper;
}
public List<Map<String,Object>> getListByStartAndEnd(Map<String, Object> map){
List<Map<String,Object>> list = this.eventInfoMapper.getListByStartAndEnd(map);
for (Map<String,Object> data : list) {
String dir = Tools.getMapValue("dir",data);
if (Objects.nonNull(dir) && dir.length()>2){
public List<Map<String, Object>> getListByStartAndEnd(Map<String, Object> map) {
List<Map<String, Object>> list = this.eventInfoMapper.getListByStartAndEnd(map);
for (Map<String, Object> data : list) {
String dir = Tools.getMapValue("dir", data);
if (Objects.nonNull(dir) && dir.length() > 2) {
String dirName = CommonUtils.getEventHappenDirName(dir);
data.put("dirName",dirName);
data.put("dirName", dirName);
}
}
return list;
}
@Override
public void insertCrossSlowRunEventData(String startTime, String endTime) {
long st = System.currentTimeMillis();
eventInfoMapper.insertCrossSlowRunEventData(startTime, endTime);
long et = System.currentTimeMillis();
log.info("路口缓行事件计算耗时:{}ms,时间:{} {}",et-st,startTime,endTime);
}
}
package net.wanji.opt.task;
import cn.hutool.core.date.DateField;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import lombok.extern.slf4j.Slf4j;
import net.wanji.opt.servicev2.evaluation.EventInfoService;
import net.wanji.opt.servicev2.judgeanalysis.AnalysisGreenCongestionPeriodService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Configurable;
......@@ -9,6 +13,7 @@ import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.text.ParseException;
@Component
......@@ -20,17 +25,51 @@ public class AnalysisGreenCongestionPeriodWeekTask {
@Autowired
private AnalysisGreenCongestionPeriodService analysisGreenCongestionPeriodService;
@Resource
EventInfoService eventInfoService;
@Scheduled(cron = "0 30 2 ? * 1")
public void task() throws ParseException {
analysisGreenCongestionPeriodService.selectCountByCongestionPeriod();
analysisGreenCongestionPeriodService.selectCountByLandData();
try {
analysisGreenCongestionPeriodService.selectCountByCongestionPeriod();
analysisGreenCongestionPeriodService.selectCountByLandData();
//analysisGreenCongestionPeriodService.selectCountByCrossData();
//analysisGreenCongestionPeriodService.selectCountByCrossData();
}catch (Exception e){
log.error("",e);
}
}
@Scheduled(cron = "0 0 2 ? * ? ")
public void taskDay() throws ParseException {
analysisGreenCongestionPeriodService.selectCountByCrossDataOneDay();
try {
analysisGreenCongestionPeriodService.selectCountByCrossDataOneDay();
}catch (Exception e){
log.error("",e);
}
}
@Scheduled(cron = "0 0 2 ? * ? ")
public void insertCrossSlowRunEventData() throws ParseException {
try {
DateTime endTDateTime = DateUtil.date();
//开始时间
DateTime startTDateTime = DateUtil.offsetDay(endTDateTime, -1);
startTDateTime = DateUtil.beginOfDay(startTDateTime);
String sdt = startTDateTime.toString("yyyy-MM-dd HH:00:00");
//窗口截止时间
endTDateTime = DateUtil.parseDateTime(sdt).offset(DateField.HOUR,24).offset(DateField.SECOND,-1);
String edt = endTDateTime.toString("yyyy-MM-dd HH:mm:ss");
eventInfoService.insertCrossSlowRunEventData(sdt,edt);
}catch (Exception e){
log.error("",e);
}
}
}
......@@ -2,11 +2,13 @@
*
*/
import cn.hutool.core.date.DateField;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import lombok.extern.slf4j.Slf4j;
import net.wanji.opt.SignalOptimizeApplication;
import net.wanji.opt.dao.mapper.judgeanalysis.AnalysisProblemCrossDayMapper;
import net.wanji.opt.servicev2.evaluation.EventInfoService;
import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.runner.RunWith;
......@@ -15,6 +17,8 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import javax.annotation.Resource;
import java.text.ParseException;
import java.util.Date;
/**
......@@ -29,44 +33,57 @@ public class AnalysisProblemDayTaskTest {
@Autowired
private AnalysisProblemCrossDayMapper analysisProblemCrossDayMapper;
@Resource
EventInfoService eventInfoService;
@Test
public void testProducerTrack() {
DateTime endTDateTime = DateUtil.date();
//开始时间
DateTime startTDateTime = DateUtil.offsetHour(endTDateTime, -1);
String sdt = startTDateTime.toString("yyyy-MM-dd HH:00:00");
//窗口截止时间
startTDateTime = DateUtil.offsetSecond(startTDateTime, 59);
String edt = startTDateTime.toString("yyyy-MM-dd HH:mm:ss");
System.out.println();
// long st = System.currentTimeMillis();
// DateTime startTDateTime = DateUtil.beginOfDay(new Date());
// DateTime endTDateTime = DateUtil.date(); //DateUtil.offsetHour(startTDateTime,1);
//
// while (startTDateTime.isBefore(endTDateTime)) {
//
// String sdt = startTDateTime.toString("yyyy-MM-dd HH:00:00");
//
// startTDateTime = DateUtil.offsetHour(startTDateTime, 1);
// startTDateTime = DateUtil.offsetSecond(startTDateTime,-1);
//
// String edt = startTDateTime.toString("yyyy-MM-dd HH:mm:ss");
//
// analysisProblemCrossDayMapper.insertGreenCrossHourData(sdt, edt);
//
// startTDateTime = DateUtil.offsetSecond(startTDateTime,1);
// log.info("小时粒度数据入库,小时开始时间:{},小时截止时间:{},截止时间:{}",sdt,edt,endTDateTime.toString("yyyy-MM-dd HH:mm:ss"));
//
// }
//
// long et = System.currentTimeMillis();
// System.out.println((et - st) + "ms");
long st = System.currentTimeMillis();
DateTime startTDateTime = DateUtil.beginOfDay(new Date());
DateTime endTDateTime = DateUtil.date(); //DateUtil.offsetHour(startTDateTime,1);
while (startTDateTime.isBefore(endTDateTime)) {
String sdt = startTDateTime.toString("yyyy-MM-dd HH:00:00");
startTDateTime = DateUtil.offsetHour(startTDateTime, 1);
startTDateTime = DateUtil.offsetSecond(startTDateTime, -1);
String edt = startTDateTime.toString("yyyy-MM-dd HH:mm:ss");
analysisProblemCrossDayMapper.insertGreenCrossHourData(sdt, edt);
startTDateTime = DateUtil.offsetSecond(startTDateTime, 1);
log.info("小时粒度数据入库,小时开始时间:{},小时截止时间:{},截止时间:{}", sdt, edt, endTDateTime.toString("yyyy-MM-dd HH:mm:ss"));
}
long et = System.currentTimeMillis();
System.out.println((et - st) + "ms");
}
@Test
public void insertCrossSlowRunEventData() throws ParseException {
try {
for (int i = 28; i > 0; i--) {
DateTime endTDateTime = DateUtil.date();
//开始时间
DateTime startTDateTime = DateUtil.offsetDay(endTDateTime, -i);
startTDateTime = DateUtil.beginOfDay(startTDateTime);
String sdt = startTDateTime.toString("yyyy-MM-dd HH:00:00");
//窗口截止时间
endTDateTime = DateUtil.parseDateTime(sdt).offset(DateField.HOUR, 24).offset(DateField.SECOND, -1);
String edt = endTDateTime.toString("yyyy-MM-dd HH:mm:ss");
eventInfoService.insertCrossSlowRunEventData(sdt, edt);
}
} catch (Exception e) {
log.error("", e);
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment