Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
H
hzjtpushdateService
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
建金
hzjtpushdateService
Commits
aea918b5
Commit
aea918b5
authored
Dec 17, 2020
by
高飞
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
提升查询速度
parent
2c9a493f
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
122 additions
and
50 deletions
+122
-50
src/main/java/com/hzjt/config/ScheduleTaskConfig.java
src/main/java/com/hzjt/config/ScheduleTaskConfig.java
+14
-0
src/main/java/com/hzjt/controller/TraffController.java
src/main/java/com/hzjt/controller/TraffController.java
+0
-12
src/main/java/com/hzjt/handler/WebSocket.java
src/main/java/com/hzjt/handler/WebSocket.java
+0
-4
src/main/java/com/hzjt/listener/MyApplicationStartingEventListener.java
...com/hzjt/listener/MyApplicationStartingEventListener.java
+0
-2
src/main/java/com/hzjt/mapper/TraffFlowMapper.java
src/main/java/com/hzjt/mapper/TraffFlowMapper.java
+2
-1
src/main/java/com/hzjt/service/TraffFlowService.java
src/main/java/com/hzjt/service/TraffFlowService.java
+12
-0
src/main/java/com/hzjt/util/DateUtils.java
src/main/java/com/hzjt/util/DateUtils.java
+2
-2
src/main/resources/application.properties
src/main/resources/application.properties
+8
-8
src/main/resources/mapper/TraffFlow.xml
src/main/resources/mapper/TraffFlow.xml
+84
-21
No files found.
src/main/java/com/hzjt/config/ScheduleTaskConfig.java
View file @
aea918b5
...
...
@@ -35,6 +35,10 @@ public class ScheduleTaskConfig {
Integer
result
=
traffFlowService
.
statisVehiclesByDay
(
date
);
//抽取前一天的事件统计到新表中
Integer
resultrecord
=
traffalarmrecordService
.
statisTraffalarmrecordstatByDay
(
date
);
//删除当天的数据
traffFlowService
.
deleteVehiclesByDay
();
}
@Scheduled
(
cron
=
"0 0 23 28-31 * ?"
)
//每一个月执行一次
...
...
@@ -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
);
}
}
src/main/java/com/hzjt/controller/TraffController.java
View file @
aea918b5
...
...
@@ -64,17 +64,12 @@ public class TraffController {
@PostMapping
(
"/alarmevent"
)
public
ResultObj
rece
(
@RequestBody
Alarm
trffClientMessage
)
{
log
.
debug
(
"/event/receive接收到数据:"
+
trffClientMessage
.
toString
());
if
(!
TYPE
.
equals
(
trffClientMessage
.
getType
()))
{
log
.
info
(
"type类型不正确"
+
trffClientMessage
.
toString
());
return
ResultObj
.
error
(
ResponseEnum
.
E_1002
.
getCode
(),
"type类型不正确"
);
}
log
.
debug
(
"/event/receive data:"
+
trffClientMessage
.
toString
());
if
(
trffClientMessage
.
getImg_urls
().
isEmpty
())
{
log
.
info
(
"img_urls值不能为空"
+
trffClientMessage
.
toString
());
return
ResultObj
.
error
(
ResponseEnum
.
E_1004
.
getCode
(),
"img_urls值不能为空"
);
}
if
(
StringUtils
.
isBlank
(
trffClientMessage
.
getIncident_type
()))
{
...
...
@@ -121,7 +116,6 @@ public class TraffController {
}
catch
(
Exception
e
)
{
log
.
error
(
"MessageController receive putData error:"
+
e
.
toString
());
//return ResultObj.error(ResponseEnum.E_9999.getCode(), e.toString());
}
return
ResultObj
.
ok
(
trffClientMessage
);
}
...
...
@@ -155,13 +149,11 @@ public class TraffController {
int
tdbh
=
Integer
.
valueOf
(
sbAndTd
[
1
])
+
1
;
//重置videoid
vehicles
.
setVideo_id
(
sbbh
+
"_"
+
tdbh
);
log
.
debug
(
"/event/receive接收到数据:"
+
vehicles
.
toString
());
//直接放入表中
// traffFlowService.saveTraffFlow(vehicles);
List
<
Vehiclesdetail
>
vels
=
vehicles
.
getObjs
()
;
int
result
=
0
;
for
(
Vehiclesdetail
detail
:
vels
){
log
.
info
(
detail
.
toString
());
Vehicle
v
=
new
Vehicle
();
v
.
setId
(
UUID
.
randomUUID
().
toString
());
v
.
setCreate_time
(
new
Date
(
Long
.
valueOf
(
vehicles
.
getTs
())));
...
...
@@ -170,15 +162,12 @@ public class TraffController {
v
.
setRuleTag
(
detail
.
getRuleTag
());
v
.
setClassification_confidence
(
detail
.
getClassification_confidence
());
v
.
setVideo_id
(
vehicles
.
getVideo_id
());
log
.
info
(
v
.
toString
());
result
=
traffFlowService
.
saveTraffFlowDetail
(
v
);
log
.
info
(
"insertvel="
+
result
);
}
//查询近五分钟的车流量,当天车流量websocket 直接推送过去
log
.
info
(
"schedule >>>>>>>>>> WebSocket"
);
//根据连接的name ,群发根据videoid 查询的结果
webSocket
.
GroupSendingByVideoid
(
vehicles
.
getVideo_id
());
}
...
...
@@ -189,7 +178,6 @@ public class TraffController {
//获取自动规则
@PostMapping
(
"/autoRule"
)
public
ResultObj
autoRule
(
@RequestBody
AutoRule
rules
)
{
// log.info(rules.toString());
Map
map
=
new
HashMap
();
map
.
put
(
"type"
,
"rule"
);
map
.
put
(
"data"
,
rules
);
...
...
src/main/java/com/hzjt/handler/WebSocket.java
View file @
aea918b5
...
...
@@ -50,27 +50,23 @@ public class WebSocket {
this
.
name
=
name
;
// name是用来表示唯一客户端,如果需要指定发送,需要指定发送通过name来区分
webSocketSet
.
put
(
name
,
this
);
log
.
info
(
"[WebSocket] 连接成功,当前连接人数为:={}"
,
webSocketSet
.
size
());
}
@OnClose
public
void
OnClose
()
{
webSocketSet
.
remove
(
this
.
name
);
log
.
info
(
"[WebSocket] 退出成功,当前连接人数为:={}"
,
webSocketSet
.
size
());
}
@OnError
public
void
OnError
(
@PathParam
(
"name"
)
String
name
,
Throwable
throwable
,
Session
session
)
{
webSocketSet
.
remove
(
name
);
log
.
info
(
"[WebSocket] 退出成功,当前连接人数为:={}"
,
webSocketSet
.
size
());
}
@OnMessage
public
void
OnMessage
(
String
message
)
{
log
.
info
(
"[WebSocket] 收到消息:{}"
,
message
);
//判断是否需要指定发送,具体规则自定义
if
(
message
.
indexOf
(
"videoid"
)
>=
0
)
{
...
...
src/main/java/com/hzjt/listener/MyApplicationStartingEventListener.java
View file @
aea918b5
...
...
@@ -36,14 +36,12 @@ public class MyApplicationStartingEventListener implements ApplicationListener<S
try
{
if
(!
flag
)
{
ThreadPoolUtil
.
getSchedulePool
().
scheduleWithFixedDelay
(()
->
{
log
.
info
(
"loadFtpCache schedule----------"
);
CacheLoadService
cacheLoadService
=
applicationContext
.
getBean
(
CacheLoadService
.
class
);
cacheLoadService
.
loadFtpCache
();
},
200
,
60000
,
TimeUnit
.
MILLISECONDS
);
//判断第三方登录是否有效
ThreadPoolUtil
.
getSchedulePool
().
scheduleWithFixedDelay
(()
->
{
log
.
info
(
"QingZhiLoginCacheService schedule----------"
);
QingZhiLoginCacheService
qingZhiLoginCacheService
=
applicationContext
.
getBean
(
QingZhiLoginCacheService
.
class
);
qingZhiLoginCacheService
.
keepAlive
();
},
3
,
60
,
TimeUnit
.
SECONDS
);
...
...
src/main/java/com/hzjt/mapper/TraffFlowMapper.java
View file @
aea918b5
...
...
@@ -19,5 +19,6 @@ public interface TraffFlowMapper {
List
<
Map
>
selectFiveAndTypeDayFlow
(
String
videoid
);
Integer
statisVehiclesByDay
(
String
startime
);
Integer
deleteBeforeTwoMonthVehiclesDetails
(
String
startime
);
Integer
deleteVehiclesByDay
();
Integer
insertOrUpdatevehicleTodaystatistic
();
}
src/main/java/com/hzjt/service/TraffFlowService.java
View file @
aea918b5
...
...
@@ -39,6 +39,18 @@ public class TraffFlowService {
public
void
deleteBeforeTwoMonthVehicles
(
String
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
src/main/java/com/hzjt/util/DateUtils.java
View file @
aea918b5
...
...
@@ -39,12 +39,12 @@ public class DateUtils {
public
static
String
getYesterday
(
int
day
){
Date
date
=
addDay
(
new
Date
(),
day
);
return
new
DateTime
(
date
).
toString
(
Y
_M_D
);
return
new
DateTime
(
date
).
toString
(
Y
MD_HMS
);
}
public
static
String
getlastMonth
(
int
month
){
Date
date
=
addMonth
(
new
Date
(),
month
);
return
new
DateTime
(
date
).
toString
(
Y
_M_D
);
return
new
DateTime
(
date
).
toString
(
Y
MD_HMS
);
}
public
static
String
formatDate
(
Date
date
){
...
...
src/main/resources/application.properties
View file @
aea918b5
...
...
@@ -13,7 +13,7 @@ mybatis.configuration.map-underscore-to-camel-case=true
mybatis.configuration.default-fetch-size
=
100
mybatis.configuration.default-statement-timeout
=
3000
#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
...
...
@@ -29,13 +29,13 @@ logging.level.com.hzjt=debug
#spring.datasource.dbcp2.connection-properties=characterEncoding=utf8
# Mysql���ݿ�-����Դ����
spring.datasource.username
=
test
spring.datasource.password
=
test
spring.datasource.url
=
jdbc:oracle:thin:@192.168.168.212:1522:helowin
#
spring.datasource.username=hzjt
#
spring.datasource.password=hzjt
#
spring.datasource.url=jdbc:oracle:thin:@33.50.1.22:1521:orcl
#
spring.datasource.driverClassName=oracle.jdbc.OracleDriver
#
spring.datasource.username=test
#
spring.datasource.password=test
#
spring.datasource.url=jdbc:oracle:thin:@192.168.168.212:1522:helowin
spring.datasource.username
=
hzjt
spring.datasource.password
=
hzjt
spring.datasource.url
=
jdbc:oracle:thin:@33.50.1.22:1521:orcl
spring.datasource.driverClassName
=
oracle.jdbc.OracleDriver
# druid
spring.datasource.type
=
com.alibaba.druid.pool.DruidDataSource
# ��ʼ����С����С�����
...
...
src/main/resources/mapper/TraffFlow.xml
View file @
aea918b5
...
...
@@ -4,9 +4,9 @@
<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)
values(
#{id,jdbcType=VARCHAR},
values(
#{video_id,jdbcType=VARCHAR},
#{type,jdbcType=VARCHAR},
#{direction,jdbcType=NUMERIC},
...
...
@@ -20,13 +20,16 @@
#{video_id,jdbcType=VARCHAR},#{ts,jdbcType=VARCHAR},sysdate)
</insert>
<select
id=
"selectFiveAndDayFlow"
resultType=
"java.util.HashMap"
>
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-10/1440) and CREATE_TIME
<![CDATA[ <= ]]>
(SYSDATE-5/1440) then 1 else 0 end),0)hbfiveflow,
NVL(sum(case when CREATE_TIME>= (SYSDATE-5/1440) then 1 else 0 end),0)fiveflow,
NVL(sum(case when CREATE_TIME>=Trunc(SYSDATE) then 1 else 0 end),0)dayflow,
'all' name
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
select
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 @@
NVL( sum(case when CREATE_TIME>=Trunc(SYSDATE) then 1 else 0 end),0)dayflow,
'up' name
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
select
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 @@
NVL(sum(case when CREATE_TIME>=Trunc(SYSDATE) then 1 else 0 end),0)dayflow,
'down' name
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
id=
"selectFiveAndTypeDayFlow"
resultType=
"java.util.HashMap"
>
select 'all' name, NVL(sum(case when b.type='SEDAN' then
1
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='COACH'or b.type='MEDIUM_COACH' then
1
else 0 end),0)coach,
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
total
else 0 end),0)goodsvan,
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'
and b.type!='SEDAN'and b.type!='HEAVY_GOODS_VAN' and b.type!='LIGHT_GOODS_VAN' then 1 else 0 end),0)other
from vehicle b where video_id=#{videoid}
and CREATE_TIME>=Trunc(SYSDATE)
and b.type!='SEDAN'and b.type!='HEAVY_GOODS_VAN' and b.type!='LIGHT_GOODS_VAN' then total else 0 end),0)other
from vehicleTodaystatistic b where video_id=#{videoid}
and ts=to_char(SYSDATE,'yyyy-mm-dd')
union all
select 'up' name, NVL(sum(case when b.type='SEDAN' then
1
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,
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
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'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
from vehicle b where b.video_id=#{videoid}
and CREATE_TIME>=Trunc(SYSDATE) and ruletag ='1'
and b.type!='SEDAN'and b.type!='HEAVY_GOODS_VAN' and b.type!='LIGHT_GOODS_VAN' then total else 0 end),0)other
from vehicleTodaystatistic b where b.video_id=#{videoid}
and ts=to_char(SYSDATE,'yyyy-mm-dd') and ruletag ='1'
union all
select 'down' name, NVL(sum(case when b.type='SEDAN' then
1
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,
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
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'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
from vehicle
b where b.video_id=#{videoid}
and
CREATE_TIME>=Trunc(SYSDATE
) and ruletag ='2'
and b.type!='SEDAN'and b.type!='HEAVY_GOODS_VAN' and b.type!='LIGHT_GOODS_VAN' then
total
else 0 end),0)other
from vehicleTodaystatistic
b where b.video_id=#{videoid}
and
ts=to_char(SYSDATE,'yyyy-mm-dd'
) and ruletag ='2'
</select>
...
...
@@ -97,4 +105,59 @@
delete from vehicle WHERE create_time
<![CDATA[ <= ]]>
to_date( #{starttime}||' 23:59:59','yyyy-mm-dd hh24:mi:ss')
</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>
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment