Commit fcfc3bb6 authored by duanruiming's avatar duanruiming

代码逻辑优化

parent eab31446
......@@ -203,6 +203,10 @@
<version>4.13.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.cvicse.embedded</groupId>
<artifactId>spring-boot-starter-inforsuite</artifactId>
</dependency>
</dependencies>
<build>
......
package net.wanji.opt.common.exception;
import com.cvicse.bixi.connector.ClientAbortException;
import lombok.extern.slf4j.Slf4j;
import net.wanji.common.framework.exceptionhandler.GlobalExceptionHandler;
import net.wanji.common.framework.rest.JsonViewObject;
import org.apache.catalina.connector.ClientAbortException;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
......
/**
*
*/
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;
import org.junit.runners.MethodSorters;
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;
/**
* @author fengyi
* @date
*/
@RunWith(SpringRunner.class)
@SpringBootTest(classes = SignalOptimizeApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
@Slf4j
public class AnalysisProblemDayTaskTest {
@Autowired
private AnalysisProblemCrossDayMapper analysisProblemCrossDayMapper;
@Resource
EventInfoService eventInfoService;
@Test
public void testProducerTrack() {
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);
}
}
@Test
public void insertCrossSlowRunDayData() throws ParseException {
try {
//路口缓行事件数据单独计算
DateTime yesterday = DateUtil.yesterday();
String dt = yesterday.toString("yyyyMMdd");
for (int i = 20250401; i < 20250428; i++) {
long st = System.currentTimeMillis();
analysisProblemCrossDayMapper.insertAnalysisCrossSlowRunDay(i);
long et = System.currentTimeMillis();
log.info("路口缓行按天统计:耗时{}ms,dt={}", et-st,i);
}
} catch (Exception e) {
log.error("", e);
}
}
}
/**
*
*/
package zsg;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import net.wanji.opt.SignalOptimizeApplication;
import net.wanji.opt.common.EsDateIndexUtil;
import net.wanji.opt.servicev2.judgeanalysis.AnalysisProblemCrossDayService;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.LineIterator;
import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.MethodSorters;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import javax.annotation.Resource;
import java.io.File;
import java.util.Date;
import java.util.List;
import java.util.concurrent.TimeUnit;
/**
* @author fengyi
* @date
*/
@RunWith(SpringRunner.class)
@SpringBootTest(classes = SignalOptimizeApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class AreaCrossTest {
@Resource
AnalysisProblemCrossDayService analysisProblemCrossDayService;
@Test
public void testProducerTrack() {
analysisProblemCrossDayService.updateCrossAreaIdByCondition();
}
}
/**
*
*/
import cn.hutool.core.date.DateUtil;
import net.wanji.opt.SignalOptimizeApplication;
import net.wanji.opt.dao.mapper.judgeanalysis.AnalysisProblemCrossDayMapper;
import net.wanji.opt.servicev2.judgeanalysis.AnalysisProblemAndStrategyDayService;
import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.MethodSorters;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.test.context.junit4.SpringRunner;
import java.util.Date;
/**
* @author fengyi
* @date
*/
@RunWith(SpringRunner.class)
@SpringBootTest(classes = SignalOptimizeApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class EventOptimizeTaskTest {
@Autowired
private AnalysisProblemAndStrategyDayService analysisProblemAndStrategyDayService;
@Test
public void taskGreen() {
try {
//analysisProblemAndStrategyDayService.selectCountByTypeOfCross();
Integer dtStart = 20250423;// Integer.valueOf(DateUtil.beginOfMonth(new Date()).toString("yyyyMMdd"));
Integer dtEnd = 20250423;// Integer.valueOf(DateUtil.format(new Date(),"yyyyMMdd"));
analysisProblemAndStrategyDayService.selectCountByTypeOfGreen(dtStart,dtEnd);
} catch (Exception e) {
e.printStackTrace();
}
}
@Test
public void taskCross() {
try {
Integer dtStart = 20250423;// Integer.valueOf(DateUtil.beginOfMonth(new Date()).toString("yyyyMMdd"));
Integer dtEnd = 20250423; //Integer.valueOf(DateUtil.format(new Date(),"yyyyMMdd"));
analysisProblemAndStrategyDayService.selectCountByTypeOfCross(dtStart,dtEnd);
} catch (Exception e) {
e.printStackTrace();
}
}
}
/**
*
*/
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import net.wanji.opt.SignalOptimizeApplication;
import net.wanji.opt.task.ReportGreenAndCrossOptimizeStatisticTask;
import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.MethodSorters;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import javax.annotation.Resource;
/**
* @author fengyi
* @date
*/
@RunWith(SpringRunner.class)
@SpringBootTest(classes = SignalOptimizeApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class OptimizeStatisticTaskTest {
@Resource
ReportGreenAndCrossOptimizeStatisticTask optimizeStatisticTask;
@Test
public void testProducerTrack() {
DateTime dateTime = DateUtil.lastWeek();
dateTime = DateUtil.beginOfWeek(dateTime.toJdkDate());
String start = dateTime.toString("yyyy-MM-dd HH:mm:ss");
String end = DateUtil.now();
//测试运行上周一到现在的数据
optimizeStatisticTask.optimizeDurationCal();
}
}
spring:
cloud:
nacos:
config:
server-addr: 37.12.182.29:8848
file-extension: yaml
group: signal
namespace: signal
username: nacos
password: nacos
application:
# dubbo启动需要程序名称
name: signal-optimize-data-compute
main:
allow-circular-references: true
spring:
profiles:
active: test
logging:
level:
org.apache.ibatis: DEBUG
\ No newline at end of file
......@@ -21,8 +21,8 @@
select
id,event_id,event_desc,type,start_time,end_time,source,wkt,image_url,gmt_create,gmt_modified
from t_event_data
where to_days(#{todayTime}) = to_days(start_time)
order by start_time desc;
where to_char(#{todayTime}::timestamp, 'YYYY-MM-DD HH24:MI:SS') = to_char(start_time, 'YYYY-MM-DD HH24:MI:SS')
order by start_time desc
</select>
......
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