Commit aea918b5 authored by 高飞's avatar 高飞

提升查询速度

parent 2c9a493f
...@@ -35,6 +35,10 @@ public class ScheduleTaskConfig { ...@@ -35,6 +35,10 @@ public class ScheduleTaskConfig {
Integer result = traffFlowService.statisVehiclesByDay(date); Integer result = traffFlowService.statisVehiclesByDay(date);
//抽取前一天的事件统计到新表中 //抽取前一天的事件统计到新表中
Integer resultrecord = traffalarmrecordService.statisTraffalarmrecordstatByDay(date); Integer resultrecord = traffalarmrecordService.statisTraffalarmrecordstatByDay(date);
//删除当天的数据
traffFlowService.deleteVehiclesByDay();
} }
@Scheduled(cron = "0 0 23 28-31 * ?")//每一个月执行一次 @Scheduled(cron = "0 0 23 28-31 * ?")//每一个月执行一次
...@@ -48,4 +52,14 @@ public class ScheduleTaskConfig { ...@@ -48,4 +52,14 @@ public class ScheduleTaskConfig {
} }
} }
@Scheduled(cron = "0 30/5 6-19 * * ?")//每隔5分钟统计当天目前为止的数据
private void statistoday() {
//判断是否为空表
//执行查询存在更新,不存在新增
log.info("每隔5分钟");
Integer result= traffFlowService.insertOrUpdatevehicleTodaystatistic();
log.info("today"+result);
}
} }
...@@ -64,17 +64,12 @@ public class TraffController { ...@@ -64,17 +64,12 @@ public class TraffController {
@PostMapping("/alarmevent") @PostMapping("/alarmevent")
public ResultObj rece(@RequestBody Alarm trffClientMessage) { public ResultObj rece(@RequestBody Alarm trffClientMessage) {
log.debug("/event/receive接收到数据:" + trffClientMessage.toString());
if (!TYPE.equals(trffClientMessage.getType())) { if (!TYPE.equals(trffClientMessage.getType())) {
log.info("type类型不正确" + trffClientMessage.toString());
return ResultObj.error(ResponseEnum.E_1002.getCode(), "type类型不正确"); return ResultObj.error(ResponseEnum.E_1002.getCode(), "type类型不正确");
} }
log.debug("/event/receive data:" + trffClientMessage.toString());
if (trffClientMessage.getImg_urls().isEmpty()) { if (trffClientMessage.getImg_urls().isEmpty()) {
log.info("img_urls值不能为空" + trffClientMessage.toString());
return ResultObj.error(ResponseEnum.E_1004.getCode(), "img_urls值不能为空"); return ResultObj.error(ResponseEnum.E_1004.getCode(), "img_urls值不能为空");
} }
if (StringUtils.isBlank(trffClientMessage.getIncident_type())) { if (StringUtils.isBlank(trffClientMessage.getIncident_type())) {
...@@ -121,7 +116,6 @@ public class TraffController { ...@@ -121,7 +116,6 @@ public class TraffController {
} catch (Exception e) { } catch (Exception e) {
log.error("MessageController receive putData error:" + e.toString()); log.error("MessageController receive putData error:" + e.toString());
//return ResultObj.error(ResponseEnum.E_9999.getCode(), e.toString());
} }
return ResultObj.ok(trffClientMessage); return ResultObj.ok(trffClientMessage);
} }
...@@ -155,13 +149,11 @@ public class TraffController { ...@@ -155,13 +149,11 @@ public class TraffController {
int tdbh = Integer.valueOf(sbAndTd[1]) + 1; int tdbh = Integer.valueOf(sbAndTd[1]) + 1;
//重置videoid //重置videoid
vehicles.setVideo_id(sbbh+"_"+tdbh); vehicles.setVideo_id(sbbh+"_"+tdbh);
log.debug("/event/receive接收到数据:" + vehicles.toString());
//直接放入表中 //直接放入表中
// traffFlowService.saveTraffFlow(vehicles); // traffFlowService.saveTraffFlow(vehicles);
List<Vehiclesdetail> vels=vehicles.getObjs() ; List<Vehiclesdetail> vels=vehicles.getObjs() ;
int result=0; int result=0;
for(Vehiclesdetail detail : vels){ for(Vehiclesdetail detail : vels){
log.info(detail.toString());
Vehicle v=new Vehicle(); Vehicle v=new Vehicle();
v.setId(UUID.randomUUID().toString()); v.setId(UUID.randomUUID().toString());
v.setCreate_time (new Date(Long.valueOf(vehicles.getTs()))); v.setCreate_time (new Date(Long.valueOf(vehicles.getTs())));
...@@ -170,15 +162,12 @@ public class TraffController { ...@@ -170,15 +162,12 @@ public class TraffController {
v.setRuleTag(detail.getRuleTag()); v.setRuleTag(detail.getRuleTag());
v.setClassification_confidence(detail.getClassification_confidence()); v.setClassification_confidence(detail.getClassification_confidence());
v.setVideo_id(vehicles.getVideo_id()); v.setVideo_id(vehicles.getVideo_id());
log.info(v.toString());
result=traffFlowService.saveTraffFlowDetail(v); result=traffFlowService.saveTraffFlowDetail(v);
log.info("insertvel="+result);
} }
//查询近五分钟的车流量,当天车流量websocket 直接推送过去 //查询近五分钟的车流量,当天车流量websocket 直接推送过去
log.info("schedule >>>>>>>>>> WebSocket");
//根据连接的name ,群发根据videoid 查询的结果 //根据连接的name ,群发根据videoid 查询的结果
webSocket.GroupSendingByVideoid(vehicles.getVideo_id()); webSocket.GroupSendingByVideoid(vehicles.getVideo_id());
} }
...@@ -189,7 +178,6 @@ public class TraffController { ...@@ -189,7 +178,6 @@ public class TraffController {
//获取自动规则 //获取自动规则
@PostMapping("/autoRule") @PostMapping("/autoRule")
public ResultObj autoRule(@RequestBody AutoRule rules) { public ResultObj autoRule(@RequestBody AutoRule rules) {
// log.info(rules.toString());
Map map = new HashMap(); Map map = new HashMap();
map.put("type", "rule"); map.put("type", "rule");
map.put("data", rules); map.put("data", rules);
......
...@@ -50,27 +50,23 @@ public class WebSocket { ...@@ -50,27 +50,23 @@ public class WebSocket {
this.name = name; this.name = name;
// name是用来表示唯一客户端,如果需要指定发送,需要指定发送通过name来区分 // name是用来表示唯一客户端,如果需要指定发送,需要指定发送通过name来区分
webSocketSet.put(name, this); webSocketSet.put(name, this);
log.info("[WebSocket] 连接成功,当前连接人数为:={}", webSocketSet.size());
} }
@OnClose @OnClose
public void OnClose() { public void OnClose() {
webSocketSet.remove(this.name); webSocketSet.remove(this.name);
log.info("[WebSocket] 退出成功,当前连接人数为:={}", webSocketSet.size());
} }
@OnError @OnError
public void OnError(@PathParam("name") String name, Throwable throwable, Session session) { public void OnError(@PathParam("name") String name, Throwable throwable, Session session) {
webSocketSet.remove(name); webSocketSet.remove(name);
log.info("[WebSocket] 退出成功,当前连接人数为:={}", webSocketSet.size());
} }
@OnMessage @OnMessage
public void OnMessage(String message) { public void OnMessage(String message) {
log.info("[WebSocket] 收到消息:{}", message);
//判断是否需要指定发送,具体规则自定义 //判断是否需要指定发送,具体规则自定义
if (message.indexOf("videoid") >= 0) { if (message.indexOf("videoid") >= 0) {
......
...@@ -36,14 +36,12 @@ public class MyApplicationStartingEventListener implements ApplicationListener<S ...@@ -36,14 +36,12 @@ public class MyApplicationStartingEventListener implements ApplicationListener<S
try { try {
if (!flag) { if (!flag) {
ThreadPoolUtil.getSchedulePool().scheduleWithFixedDelay(() -> { ThreadPoolUtil.getSchedulePool().scheduleWithFixedDelay(() -> {
log.info("loadFtpCache schedule----------");
CacheLoadService cacheLoadService = applicationContext.getBean(CacheLoadService.class); CacheLoadService cacheLoadService = applicationContext.getBean(CacheLoadService.class);
cacheLoadService.loadFtpCache(); cacheLoadService.loadFtpCache();
}, 200, 60000, TimeUnit.MILLISECONDS); }, 200, 60000, TimeUnit.MILLISECONDS);
//判断第三方登录是否有效 //判断第三方登录是否有效
ThreadPoolUtil.getSchedulePool().scheduleWithFixedDelay(() -> { ThreadPoolUtil.getSchedulePool().scheduleWithFixedDelay(() -> {
log.info("QingZhiLoginCacheService schedule----------");
QingZhiLoginCacheService qingZhiLoginCacheService = applicationContext.getBean(QingZhiLoginCacheService.class); QingZhiLoginCacheService qingZhiLoginCacheService = applicationContext.getBean(QingZhiLoginCacheService.class);
qingZhiLoginCacheService.keepAlive(); qingZhiLoginCacheService.keepAlive();
}, 3, 60, TimeUnit.SECONDS); }, 3, 60, TimeUnit.SECONDS);
......
...@@ -19,5 +19,6 @@ public interface TraffFlowMapper { ...@@ -19,5 +19,6 @@ public interface TraffFlowMapper {
List<Map> selectFiveAndTypeDayFlow(String videoid); List<Map> selectFiveAndTypeDayFlow(String videoid);
Integer statisVehiclesByDay(String startime); Integer statisVehiclesByDay(String startime);
Integer deleteBeforeTwoMonthVehiclesDetails(String startime); Integer deleteBeforeTwoMonthVehiclesDetails(String startime);
Integer deleteVehiclesByDay();
Integer insertOrUpdatevehicleTodaystatistic();
} }
...@@ -39,6 +39,18 @@ public class TraffFlowService { ...@@ -39,6 +39,18 @@ public class TraffFlowService {
public void deleteBeforeTwoMonthVehicles(String starttime) { public void deleteBeforeTwoMonthVehicles(String starttime) {
traffFlowMapper.deleteBeforeTwoMonthVehiclesDetails(starttime); traffFlowMapper.deleteBeforeTwoMonthVehiclesDetails(starttime);
} }
@Transactional(rollbackFor = Exception.class)
public void deleteVehiclesByDay() {
traffFlowMapper.deleteVehiclesByDay();
}
public Integer insertOrUpdatevehicleTodaystatistic() {
return traffFlowMapper.insertOrUpdatevehicleTodaystatistic();
}
} }
\ No newline at end of file
...@@ -39,12 +39,12 @@ public class DateUtils { ...@@ -39,12 +39,12 @@ public class DateUtils {
public static String getYesterday(int day){ public static String getYesterday(int day){
Date date= addDay(new Date(),day); Date date= addDay(new Date(),day);
return new DateTime(date).toString(Y_M_D); return new DateTime(date).toString(YMD_HMS);
} }
public static String getlastMonth(int month){ public static String getlastMonth(int month){
Date date= addMonth(new Date(),month); Date date= addMonth(new Date(),month);
return new DateTime(date).toString(Y_M_D); return new DateTime(date).toString(YMD_HMS);
} }
public static String formatDate(Date date){ public static String formatDate(Date date){
......
...@@ -13,7 +13,7 @@ mybatis.configuration.map-underscore-to-camel-case=true ...@@ -13,7 +13,7 @@ mybatis.configuration.map-underscore-to-camel-case=true
mybatis.configuration.default-fetch-size=100 mybatis.configuration.default-fetch-size=100
mybatis.configuration.default-statement-timeout=3000 mybatis.configuration.default-statement-timeout=3000
#mybatis.mapperLocations = classpath:xxx.xml #mybatis.mapperLocations = classpath:xxx.xml
logging.level.com.hzjt=debug #logging.level.com.hzjt=debug
## �������ݿ�-����Դ���� ## �������ݿ�-����Դ����
#spring.datasource.url=jdbc:dm://127.0.0.1:12345/auditlocal_cq #spring.datasource.url=jdbc:dm://127.0.0.1:12345/auditlocal_cq
...@@ -29,13 +29,13 @@ logging.level.com.hzjt=debug ...@@ -29,13 +29,13 @@ logging.level.com.hzjt=debug
#spring.datasource.dbcp2.connection-properties=characterEncoding=utf8 #spring.datasource.dbcp2.connection-properties=characterEncoding=utf8
# Mysql���ݿ�-����Դ���� # Mysql���ݿ�-����Դ����
spring.datasource.username=test #spring.datasource.username=test
spring.datasource.password=test #spring.datasource.password=test
spring.datasource.url=jdbc:oracle:thin:@192.168.168.212:1522:helowin #spring.datasource.url=jdbc:oracle:thin:@192.168.168.212:1522:helowin
#spring.datasource.username=hzjt spring.datasource.username=hzjt
#spring.datasource.password=hzjt spring.datasource.password=hzjt
#spring.datasource.url=jdbc:oracle:thin:@33.50.1.22:1521:orcl spring.datasource.url=jdbc:oracle:thin:@33.50.1.22:1521:orcl
#spring.datasource.driverClassName=oracle.jdbc.OracleDriver spring.datasource.driverClassName=oracle.jdbc.OracleDriver
# druid # druid
spring.datasource.type=com.alibaba.druid.pool.DruidDataSource spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
# ��ʼ����С����С����� # ��ʼ����С����С�����
......
...@@ -4,9 +4,9 @@ ...@@ -4,9 +4,9 @@
<insert id="insertlist" parameterType="com.hzjt.domain.Vehicle" > <insert id="insertlist" parameterType="com.hzjt.domain.Vehicle" >
INSERT INTO vehicle (id, video_id, type, INSERT INTO vehicle (video_id, type,
direction,classification_confidence,ruletag,create_time) direction,classification_confidence,ruletag,create_time)
values( #{id,jdbcType=VARCHAR}, values(
#{video_id,jdbcType=VARCHAR}, #{video_id,jdbcType=VARCHAR},
#{type,jdbcType=VARCHAR}, #{type,jdbcType=VARCHAR},
#{direction,jdbcType=NUMERIC}, #{direction,jdbcType=NUMERIC},
...@@ -27,6 +27,9 @@ ...@@ -27,6 +27,9 @@
NVL(sum(case when CREATE_TIME>=Trunc(SYSDATE) then 1 else 0 end),0)dayflow, NVL(sum(case when CREATE_TIME>=Trunc(SYSDATE) then 1 else 0 end),0)dayflow,
'all' name 'all' name
from vehicle b where b.video_id=#{videoid} from vehicle b where b.video_id=#{videoid}
and ( (CREATE_TIME >=(SYSDATE-1-5/1440) and CREATE_TIME<![CDATA[ <= ]]>(SYSDATE-1))
or(CREATE_TIME>= (SYSDATE-10/1440) and CREATE_TIME<![CDATA[ <= ]]> (SYSDATE-5/1440) )
or (CREATE_TIME>=Trunc(SYSDATE)))
union all union all
select select
NVL(sum(case when CREATE_TIME>=(SYSDATE-1-5/1440) and CREATE_TIME<![CDATA[ <= ]]>(SYSDATE-1) then 1 else 0 end),0)tbfiveflow, NVL(sum(case when CREATE_TIME>=(SYSDATE-1-5/1440) and CREATE_TIME<![CDATA[ <= ]]>(SYSDATE-1) then 1 else 0 end),0)tbfiveflow,
...@@ -35,6 +38,9 @@ ...@@ -35,6 +38,9 @@
NVL( sum(case when CREATE_TIME>=Trunc(SYSDATE) then 1 else 0 end),0)dayflow, NVL( sum(case when CREATE_TIME>=Trunc(SYSDATE) then 1 else 0 end),0)dayflow,
'up' name 'up' name
from vehicle b where b.video_id=#{videoid} and ruletag ='1' from vehicle b where b.video_id=#{videoid} and ruletag ='1'
and ( (CREATE_TIME >=(SYSDATE-1-5/1440) and CREATE_TIME<![CDATA[ <= ]]>(SYSDATE-1))
or(CREATE_TIME>= (SYSDATE-10/1440) and CREATE_TIME<![CDATA[ <= ]]> (SYSDATE-5/1440) )
or (CREATE_TIME>=Trunc(SYSDATE)))
union all union all
select select
NVL(sum(case when CREATE_TIME>= (SYSDATE-1-5/1440) and CREATE_TIME<![CDATA[ <= ]]>(SYSDATE-1) then 1 else 0 end),0)tbfiveflow, NVL(sum(case when CREATE_TIME>= (SYSDATE-1-5/1440) and CREATE_TIME<![CDATA[ <= ]]>(SYSDATE-1) then 1 else 0 end),0)tbfiveflow,
...@@ -43,37 +49,39 @@ ...@@ -43,37 +49,39 @@
NVL(sum(case when CREATE_TIME>=Trunc(SYSDATE) then 1 else 0 end),0)dayflow, NVL(sum(case when CREATE_TIME>=Trunc(SYSDATE) then 1 else 0 end),0)dayflow,
'down' name 'down' name
from vehicle b where b.video_id=#{videoid} and ruletag ='2' from vehicle b where b.video_id=#{videoid} and ruletag ='2'
and ( (CREATE_TIME >=(SYSDATE-1-5/1440) and CREATE_TIME<![CDATA[ <= ]]>(SYSDATE-1))
or(CREATE_TIME>= (SYSDATE-10/1440) and CREATE_TIME<![CDATA[ <= ]]> (SYSDATE-5/1440) )
or (CREATE_TIME>=Trunc(SYSDATE)))
</select> </select>
<select id="selectFiveAndTypeDayFlow" resultType="java.util.HashMap"> <select id="selectFiveAndTypeDayFlow" resultType="java.util.HashMap">
select 'all' name, NVL(sum(case when b.type='SEDAN' then 1 else 0 end),0)sedan, select 'all' name, NVL(sum(case when b.type='SEDAN' then total else 0 end),0)sedan,
NVL(sum(case when b.type='HEAVY_GOODS_VAN' or b.type= 'LIGHT_GOODS_VAN' then 1 else 0 end),0)goodsvan, NVL(sum(case when b.type='HEAVY_GOODS_VAN' or b.type= 'LIGHT_GOODS_VAN' then total else 0 end),0)goodsvan,
NVL(sum(case when b.type='COACH'or b.type='MEDIUM_COACH' then 1 else 0 end),0)coach, NVL(sum(case when b.type='COACH'or b.type='MEDIUM_COACH' then total else 0 end),0)coach,
NVL( sum(case when b.type!='COACH'and b.type!='MEDIUM_COACH' NVL( sum(case when b.type!='COACH'and b.type!='MEDIUM_COACH'
and b.type!='SEDAN'and b.type!='HEAVY_GOODS_VAN' and b.type!='LIGHT_GOODS_VAN' then 1 else 0 end),0)other and b.type!='SEDAN'and b.type!='HEAVY_GOODS_VAN' and b.type!='LIGHT_GOODS_VAN' then total else 0 end),0)other
from vehicle b where video_id=#{videoid} from vehicleTodaystatistic b where video_id=#{videoid}
and CREATE_TIME>=Trunc(SYSDATE) and ts=to_char(SYSDATE,'yyyy-mm-dd')
union all union all
select 'up' name, NVL(sum(case when b.type='SEDAN' then 1 else 0 end),0)sedan, select 'up' name, NVL(sum(case when b.type='SEDAN' then total else 0 end),0)sedan,
NVL(sum(case when b.type='HEAVY_GOODS_VAN' or b.type= 'LIGHT_GOODS_VAN' then 1 else 0 end),0)goodsvan, NVL(sum(case when b.type='HEAVY_GOODS_VAN' or b.type= 'LIGHT_GOODS_VAN' then total else 0 end),0)goodsvan,
NVL(sum(case when b.type='COACH'or b.type='MEDIUM_COACH' then 1 else 0 end),0)coach, NVL(sum(case when b.type='COACH'or b.type='MEDIUM_COACH' then 1 else 0 end),0)coach,
NVL( sum(case when b.type!='COACH'and b.type!='MEDIUM_COACH' NVL( sum(case when b.type!='COACH'and b.type!='MEDIUM_COACH'
and b.type!='SEDAN'and b.type!='HEAVY_GOODS_VAN' and b.type!='LIGHT_GOODS_VAN' then 1 else 0 end),0)other and b.type!='SEDAN'and b.type!='HEAVY_GOODS_VAN' and b.type!='LIGHT_GOODS_VAN' then total else 0 end),0)other
from vehicle b where b.video_id=#{videoid} from vehicleTodaystatistic b where b.video_id=#{videoid}
and CREATE_TIME>=Trunc(SYSDATE) and ruletag ='1' and ts=to_char(SYSDATE,'yyyy-mm-dd') and ruletag ='1'
union all union all
select 'down' name, NVL(sum(case when b.type='SEDAN' then 1 else 0 end),0)sedan, select 'down' name, NVL(sum(case when b.type='SEDAN' then total else 0 end),0)sedan,
NVL(sum(case when b.type='HEAVY_GOODS_VAN' or b.type= 'LIGHT_GOODS_VAN' then 1 else 0 end),0)goodsvan, NVL(sum(case when b.type='HEAVY_GOODS_VAN' or b.type= 'LIGHT_GOODS_VAN' then total else 0 end),0)goodsvan,
NVL(sum(case when b.type='COACH'or b.type='MEDIUM_COACH' then 1 else 0 end),0)coach, NVL(sum(case when b.type='COACH'or b.type='MEDIUM_COACH' then 1 else 0 end),0)coach,
NVL( sum(case when b.type!='COACH'and b.type!='MEDIUM_COACH' NVL( sum(case when b.type!='COACH'and b.type!='MEDIUM_COACH'
and b.type!='SEDAN'and b.type!='HEAVY_GOODS_VAN' and b.type!='LIGHT_GOODS_VAN' then 1 else 0 end),0)other and b.type!='SEDAN'and b.type!='HEAVY_GOODS_VAN' and b.type!='LIGHT_GOODS_VAN' then total else 0 end),0)other
from vehicle b where b.video_id=#{videoid} from vehicleTodaystatistic b where b.video_id=#{videoid}
and CREATE_TIME>=Trunc(SYSDATE) and ruletag ='2' and ts=to_char(SYSDATE,'yyyy-mm-dd') and ruletag ='2'
</select> </select>
...@@ -97,4 +105,59 @@ ...@@ -97,4 +105,59 @@
delete from vehicle WHERE create_time <![CDATA[ <= ]]>to_date( #{starttime}||' 23:59:59','yyyy-mm-dd hh24:mi:ss') delete from vehicle WHERE create_time <![CDATA[ <= ]]>to_date( #{starttime}||' 23:59:59','yyyy-mm-dd hh24:mi:ss')
</delete> </delete>
<delete id="deleteVehiclesByDay">
delete from vehicleTodaystatistic
</delete>
<insert id="insertOrUpdatevehicleTodaystatistic" >
MERGE INTO vehicleTodaystatistic t1 USING (
SELECT
video_id,
TO_CHAR (CREATE_TIME, 'yyyy-mm-dd') ts,
TYPE,ruletag,
COUNT (*) total,
NVL(sum(case when CREATE_TIME>= (SYSDATE-5/1440) then 1 else 0 end),0)five
FROM
vehicle
WHERE
(
create_time >= TRUNC (SYSDATE)
AND create_time <![CDATA[ <= ]]> SYSDATE
)
OR (
create_time >= TRUNC (SYSDATE - 7)
AND create_time <![CDATA[ <= ]]> SYSDATE - 7
)
OR (
create_time >= TRUNC (ADD_MONTHS(SYSDATE ,- 1))
AND create_time <![CDATA[ <= ]]> ADD_MONTHS (SYSDATE ,- 1)
)
GROUP BY
TO_CHAR (CREATE_TIME, 'yyyy-mm-dd'),
TYPE,ruletag,
video_id
) t2 ON (
t1.video_id = t2.video_id
AND t1.ts = t2.ts
AND t1. TYPE = t2. TYPE
and t1.ruletag=t2.ruletag
)
WHEN MATCHED THEN
UPDATE
SET t1.total = t2.total,
t1.five = t2.five
WHEN NOT MATCHED THEN
INSERT (video_id, ts, TYPE, ruletag,total,five)
VALUES
(
t2.video_id,
t2.ts,
t2.TYPE,
t2.ruletag,
t2.total,
t2.five
)
</insert>
</mapper> </mapper>
\ No newline at end of file
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