Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
V
VieoAITaskProducerService
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
VideoAIService
VieoAITaskProducerService
Commits
6287b042
Commit
6287b042
authored
May 06, 2021
by
wangjinjing
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
websocket 版本
parent
f6be2967
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
120 additions
and
13 deletions
+120
-13
src/main/java/com/cx/cn/cxquartz/controller/ExtController.java
...ain/java/com/cx/cn/cxquartz/controller/ExtController.java
+7
-3
src/main/java/com/cx/cn/cxquartz/job/WebSocket.java
src/main/java/com/cx/cn/cxquartz/job/WebSocket.java
+103
-0
src/main/resources/mapper/TrafficMapper.xml
src/main/resources/mapper/TrafficMapper.xml
+10
-10
No files found.
src/main/java/com/cx/cn/cxquartz/controller/ExtController.java
View file @
6287b042
...
...
@@ -7,6 +7,7 @@ import com.alibaba.fastjson.JSONObject;
import
com.cx.cn.cxquartz.bean.PatrolCtrlAlarm
;
import
com.cx.cn.cxquartz.bean.PatrolCtrlRecord
;
import
com.cx.cn.cxquartz.bean.PictureTime
;
import
com.cx.cn.cxquartz.job.WebSocket
;
import
com.cx.cn.cxquartz.service.quartz.*
;
import
com.cx.cn.cxquartz.util.*
;
import
com.cx.cn.cxquartz.vo.*
;
...
...
@@ -94,6 +95,8 @@ public class ExtController {
@Autowired
PeopleridebicycService
peopleridebicycService
;
@Autowired
WebSocket
webSocket
;
private
static
CompletionService
<
PictureResult
>
threadService
=
new
ExecutorCompletionService
<
PictureResult
>(
ThreadPoolUtil
.
getPool
());
...
...
@@ -297,7 +300,6 @@ public class ExtController {
//更新 recordalarm 为一分析
traffAlarmRecordService
.
updateTraffAlarmRecordProcess
(
transferRecord
);
for
(
TraffpictureParam
traffpictureParam
:
objectList
)
{
//根据imageid 获得 base64图片
JSONObject
metadata
=
JSONObject
.
parseObject
(
String
.
valueOf
(
traffpictureParam
.
getMetadata
()));
traffpictureParam
.
setAreaid
(
transferRecord
.
getAreaid
());
...
...
@@ -337,6 +339,7 @@ public class ExtController {
meta
.
setId
(
traffpictureParam
.
getId
());
//新增到车辆详情表
trafficService
.
insertTraffic
(
meta
);
if
(
null
!=
meta
.
getObjectBoundingBox
())
traffpictureParam
.
setObjx
(
meta
.
getObjectBoundingBox
().
getX
());
traffpictureParam
.
setObjy
(
meta
.
getObjectBoundingBox
().
getY
());
traffpictureParam
.
setObjw
(
meta
.
getObjectBoundingBox
().
getW
());
...
...
@@ -368,7 +371,7 @@ public class ExtController {
ByteArrayInputStream
bais
=
new
ByteArrayInputStream
(
base64Decoder
.
decodeBuffer
(
traffpictureParam
.
getImagedata
()));
BufferedImage
image
=
ImageIO
.
read
(
bais
);
Graphics
g
=
image
.
getGraphics
();
g
.
setColor
(
Color
.
RED
);
//画笔颜色
g
.
setColor
(
Color
.
GREEN
);
//画笔颜色
g
.
drawRect
(
traffpictureParam
.
getObjx
(),
traffpictureParam
.
getObjy
(),
traffpictureParam
.
getObjw
(),
traffpictureParam
.
getObjh
());
ByteArrayOutputStream
stream
=
new
ByteArrayOutputStream
();
ImageIO
.
write
(
image
,
"png"
,
stream
);
...
...
@@ -379,8 +382,9 @@ public class ExtController {
logger
.
info
(
"base64画框异常:"
+
ex
.
toString
());
}
traffPictureService
.
updateTraffpicture
(
traffpictureParam
);
WebSocket
.
GroupSending
(
JSONObject
.
toJSONString
(
traffpictureParam
));
}
}
...
...
src/main/java/com/cx/cn/cxquartz/job/WebSocket.java
0 → 100644
View file @
6287b042
package
com
.
cx
.
cn
.
cxquartz
.
job
;
import
com.alibaba.fastjson.JSONObject
;
import
org.springframework.stereotype.Component
;
import
javax.websocket.*
;
import
javax.websocket.server.PathParam
;
import
javax.websocket.server.ServerEndpoint
;
import
java.util.*
;
import
java.util.concurrent.ConcurrentHashMap
;
@Component
@ServerEndpoint
(
"/websocket/{name}"
)
public
class
WebSocket
{
/**
* 与某个客户端的连接对话,需要通过它来给客户端发送消息
*/
private
Session
session
;
/**
* 标识当前连接客户端的用户名
*/
private
String
name
;
/**
* 用于存所有的连接服务的客户端,这个对象存储是安全的
*/
private
static
ConcurrentHashMap
<
String
,
WebSocket
>
webSocketSet
=
new
ConcurrentHashMap
<>();
@OnOpen
public
void
OnOpen
(
Session
session
,
@PathParam
(
value
=
"name"
)
String
name
)
{
this
.
session
=
session
;
this
.
name
=
name
;
// name是用来表示唯一客户端,如果需要指定发送,需要指定发送通过name来区分
webSocketSet
.
put
(
name
,
this
);
}
@OnClose
public
void
OnClose
()
{
webSocketSet
.
remove
(
this
.
name
);
}
@OnError
public
void
OnError
(
@PathParam
(
"name"
)
String
name
,
Throwable
throwable
,
Session
session
)
{
webSocketSet
.
remove
(
name
);
}
@OnMessage
public
void
OnMessage
(
String
message
)
{
//判断是否需要指定发送,具体规则自定义
if
(
message
.
indexOf
(
"HEARTBEAT"
)>=
0
){
Map
map
=
new
HashMap
();
map
.
put
(
"type"
,
"HEARTBEAT"
);
map
.
put
(
"ts"
,
new
Date
().
getTime
());
AppointSending
(
name
,
JSONObject
.
toJSONString
(
map
));
}
}
/**
* 群发
*
* @param message
*/
public
static
void
GroupSending
(
String
message
)
{
for
(
String
name
:
webSocketSet
.
keySet
())
{
try
{
if
(
null
!=
webSocketSet
.
get
(
name
)
&&
null
!=
webSocketSet
.
get
(
name
).
session
&&
null
!=
webSocketSet
.
get
(
name
).
session
.
getBasicRemote
())
webSocketSet
.
get
(
name
).
session
.
getBasicRemote
().
sendText
(
message
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
}
/**
* 指定发送
*
* @param name
* @param message
*/
public
void
AppointSending
(
String
name
,
String
message
)
{
if
(
null
!=
webSocketSet
.
get
(
name
)
&&
null
!=
webSocketSet
.
get
(
name
).
session
&&
null
!=
webSocketSet
.
get
(
name
).
session
.
getBasicRemote
())
{
synchronized
(
webSocketSet
.
get
(
name
).
session
)
{
try
{
webSocketSet
.
get
(
name
).
session
.
getBasicRemote
().
sendText
(
message
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
}
}
}
src/main/resources/mapper/TrafficMapper.xml
View file @
6287b042
...
...
@@ -42,10 +42,10 @@
<trim
prefix=
"("
suffix=
")"
suffixOverrides=
","
>
<if
test=
"id !=null"
>
id,
</if>
<if
test=
"Type !=null"
>
type ,
</if>
<if
test=
"ObjectBoundingBox.x !=null"
>
objectx ,
</if>
<if
test=
"ObjectBoundingBox.y !=null"
>
objecty ,
</if>
<if
test=
"ObjectBoundingBox.w !=null"
>
objectw ,
</if>
<if
test=
"ObjectBoundingBox.h !=null"
>
objecth ,
</if>
<if
test=
"ObjectBoundingBox
!=null and ObjectBoundingBox
.x !=null"
>
objectx ,
</if>
<if
test=
"ObjectBoundingBox
!=null and ObjectBoundingBox
.y !=null"
>
objecty ,
</if>
<if
test=
"ObjectBoundingBox
!=null and ObjectBoundingBox
.w !=null"
>
objectw ,
</if>
<if
test=
"ObjectBoundingBox
!=null and ObjectBoundingBox
.h !=null"
>
objecth ,
</if>
<if
test=
"VehicleClass !=null"
>
vehicleclass ,
</if>
<if
test=
"VehicleColorNums !=null"
>
vehiclecolornums ,
</if>
<if
test=
"VehicleColor !=null"
>
vehiclecolor ,
</if>
...
...
@@ -76,10 +76,10 @@
<trim
prefix=
"values ("
suffix=
")"
suffixOverrides=
","
>
<if
test=
"id !=null"
>
#{id} ,
</if>
<if
test=
"Type !=null"
>
#{Type} ,
</if>
<if
test=
"ObjectBoundingBox.x !=null"
>
#{ObjectBoundingBox.x } ,
</if>
<if
test=
"ObjectBoundingBox.y !=null"
>
#{ObjectBoundingBox.y} ,
</if>
<if
test=
"ObjectBoundingBox.w !=null"
>
#{ObjectBoundingBox.w} ,
</if>
<if
test=
"ObjectBoundingBox.h !=null"
>
#{ObjectBoundingBox.h} ,
</if>
<if
test=
"ObjectBoundingBox
!=null and ObjectBoundingBox
.x !=null"
>
#{ObjectBoundingBox.x } ,
</if>
<if
test=
"ObjectBoundingBox
!=null and ObjectBoundingBox
.y !=null"
>
#{ObjectBoundingBox.y} ,
</if>
<if
test=
"ObjectBoundingBox
!=null and ObjectBoundingBox
.w !=null"
>
#{ObjectBoundingBox.w} ,
</if>
<if
test=
"ObjectBoundingBox
!=null and ObjectBoundingBox
.h !=null"
>
#{ObjectBoundingBox.h} ,
</if>
<if
test=
"VehicleClass !=null"
>
#{VehicleClass} ,
</if>
<if
test=
"VehicleColorNums !=null"
>
#{VehicleColorNums} ,
</if>
<if
test=
"VehicleColor !=null"
>
#{VehicleColor} ,
</if>
...
...
@@ -98,8 +98,8 @@
<if
test=
"Decoration !=null"
>
#{Decoration} ,
</if>
<if
test=
"Drop !=null"
>
#{Drop},
</if>
<if
test=
"Tag !=null"
>
#{Tag},
</if>
<if
test=
"SafetyBelt.MainDriver !=null"
>
#{SafetyBelt.MainDriver} ,
</if>
<if
test=
"SafetyBelt.CoDriver !=null"
>
#{SafetyBelt.CoDriver},
</if>
<if
test=
"SafetyBelt
!=null and SafetyBelt
.MainDriver !=null"
>
#{SafetyBelt.MainDriver} ,
</if>
<if
test=
"SafetyBelt
!=null and SafetyBelt
.CoDriver !=null"
>
#{SafetyBelt.CoDriver},
</if>
<if
test=
"HasCall !=null"
>
#{HasCall} ,
</if>
<if
test=
"HasCrash !=null"
>
#{HasCrash} ,
</if>
<if
test=
"HasDanger !=null"
>
#{HasDanger} ,
</if>
...
...
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