Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
my-kafka-project
Project
Project
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
AI算法平台
my-kafka-project
Commits
d8d9e368
Commit
d8d9e368
authored
Nov 21, 2023
by
yf
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改iot推送问题
parent
3864c971
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
143 additions
and
22 deletions
+143
-22
pom.xml
pom.xml
+22
-0
src/main/java/com/example/mykafkaproject/bean/IotWarnPushDto.java
.../java/com/example/mykafkaproject/bean/IotWarnPushDto.java
+9
-0
src/main/java/com/example/mykafkaproject/bean/WarnPushBase.java
...in/java/com/example/mykafkaproject/bean/WarnPushBase.java
+10
-0
src/main/java/com/example/mykafkaproject/server/WarnPushBaseServer.java
...com/example/mykafkaproject/server/WarnPushBaseServer.java
+31
-22
src/main/java/com/example/mykafkaproject/utils/HttpUtils.java
...main/java/com/example/mykafkaproject/utils/HttpUtils.java
+55
-0
src/main/java/com/example/mykafkaproject/utils/JsonUtil.java
src/main/java/com/example/mykafkaproject/utils/JsonUtil.java
+16
-0
No files found.
pom.xml
View file @
d8d9e368
...
@@ -69,6 +69,27 @@
...
@@ -69,6 +69,27 @@
</exclusions>
</exclusions>
</dependency>
</dependency>
<!--http 基础包-->
<dependency>
<groupId>
org.apache.httpcomponents
</groupId>
<artifactId>
httpclient
</artifactId>
<version>
4.5.5
</version>
</dependency>
<dependency>
<groupId>
org.apache.httpcomponents
</groupId>
<artifactId>
httpmime
</artifactId>
<version>
4.5.5
</version>
</dependency>
<dependency>
<groupId>
org.apache.httpcomponents
</groupId>
<artifactId>
httpcore
</artifactId>
<version>
4.4.9
</version>
</dependency>
<dependency>
<groupId>
com.alibaba
</groupId>
<artifactId>
fastjson
</artifactId>
<version>
1.2.47
</version>
</dependency>
<dependency>
<dependency>
<groupId>
com.dahuatech.icc
</groupId>
<groupId>
com.dahuatech.icc
</groupId>
<artifactId>
java-sdk-core
</artifactId>
<artifactId>
java-sdk-core
</artifactId>
...
@@ -114,6 +135,7 @@
...
@@ -114,6 +135,7 @@
<plugin>
<plugin>
<groupId>
org.springframework.boot
</groupId>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-maven-plugin
</artifactId>
<artifactId>
spring-boot-maven-plugin
</artifactId>
<version>
2.1.1.RELEASE
</version>
<!--<configuration>
<!--<configuration>
<mainClass>com.example.mykafkaproject.MyKafkaProjectApplication</mainClass>
<mainClass>com.example.mykafkaproject.MyKafkaProjectApplication</mainClass>
<skip>true</skip>
<skip>true</skip>
...
...
src/main/java/com/example/mykafkaproject/bean/IotWarnPushDto.java
View file @
d8d9e368
...
@@ -13,6 +13,7 @@ public class IotWarnPushDto {
...
@@ -13,6 +13,7 @@ public class IotWarnPushDto {
private
String
grade_type_code
;
private
String
grade_type_code
;
private
String
alarm_time
;
private
String
alarm_time
;
private
String
picture
;
private
String
picture
;
private
String
video
;
private
String
belong
;
private
String
belong
;
private
String
create_time
;
private
String
create_time
;
...
@@ -87,4 +88,12 @@ public class IotWarnPushDto {
...
@@ -87,4 +88,12 @@ public class IotWarnPushDto {
public
void
setGrade_type_code
(
String
grade_type_code
)
{
public
void
setGrade_type_code
(
String
grade_type_code
)
{
this
.
grade_type_code
=
grade_type_code
;
this
.
grade_type_code
=
grade_type_code
;
}
}
public
String
getVideo
()
{
return
video
;
}
public
void
setVideo
(
String
video
)
{
this
.
video
=
video
;
}
}
}
src/main/java/com/example/mykafkaproject/bean/WarnPushBase.java
View file @
d8d9e368
...
@@ -52,6 +52,8 @@ public class WarnPushBase{
...
@@ -52,6 +52,8 @@ public class WarnPushBase{
/** 摄像头Id */
/** 摄像头Id */
private
String
channelId
;
private
String
channelId
;
private
String
alarmMsg
;
public
Long
getId
()
{
public
Long
getId
()
{
return
id
;
return
id
;
...
@@ -164,4 +166,12 @@ public class WarnPushBase{
...
@@ -164,4 +166,12 @@ public class WarnPushBase{
public
void
setChannelId
(
String
channelId
)
{
public
void
setChannelId
(
String
channelId
)
{
this
.
channelId
=
channelId
;
this
.
channelId
=
channelId
;
}
}
public
String
getAlarmMsg
()
{
return
alarmMsg
;
}
public
void
setAlarmMsg
(
String
alarmMsg
)
{
this
.
alarmMsg
=
alarmMsg
;
}
}
}
src/main/java/com/example/mykafkaproject/server/WarnPushBaseServer.java
View file @
d8d9e368
...
@@ -10,9 +10,10 @@ import com.dahuatech.icc.oauth.http.DefaultClient;
...
@@ -10,9 +10,10 @@ import com.dahuatech.icc.oauth.http.DefaultClient;
import
com.dahuatech.icc.oauth.http.IClient
;
import
com.dahuatech.icc.oauth.http.IClient
;
import
com.dahuatech.icc.oauth.model.v202010.GeneralRequest
;
import
com.dahuatech.icc.oauth.model.v202010.GeneralRequest
;
import
com.dahuatech.icc.oauth.model.v202010.GeneralResponse
;
import
com.dahuatech.icc.oauth.model.v202010.GeneralResponse
;
import
com.example.mykafkaproject.bean.IotWarnPushDto
;
import
com.example.mykafkaproject.bean.WarnPushBase
;
import
com.example.mykafkaproject.bean.WarnPushBase
;
import
com.example.mykafkaproject.mapper.WarnPushBaseMapper
;
import
com.example.mykafkaproject.mapper.WarnPushBaseMapper
;
import
com.example.mykafkaproject.utils.HttpUtils
;
import
com.example.mykafkaproject.utils.JsonUtil
;
import
com.example.mykafkaproject.utils.PinYinUtil
;
import
com.example.mykafkaproject.utils.PinYinUtil
;
import
com.example.mykafkaproject.utils.RtspToMP4
;
import
com.example.mykafkaproject.utils.RtspToMP4
;
import
org.slf4j.Logger
;
import
org.slf4j.Logger
;
...
@@ -22,6 +23,8 @@ import org.springframework.stereotype.Service;
...
@@ -22,6 +23,8 @@ import org.springframework.stereotype.Service;
import
java.text.SimpleDateFormat
;
import
java.text.SimpleDateFormat
;
import
java.util.Date
;
import
java.util.Date
;
import
java.util.HashMap
;
import
java.util.Map
;
@Service
(
"WarnPushBaseServer"
)
@Service
(
"WarnPushBaseServer"
)
public
class
WarnPushBaseServer
{
public
class
WarnPushBaseServer
{
...
@@ -36,14 +39,15 @@ public class WarnPushBaseServer {
...
@@ -36,14 +39,15 @@ public class WarnPushBaseServer {
public
void
addMessage
(
String
message
)
{
public
void
addMessage
(
String
message
)
{
LOGGER
.
info
(
"预警信息:"
+
message
);
LOGGER
.
info
(
"预警信息:"
+
message
);
WarnPushBase
warnPushBase
=
JSON
.
parseObject
(
message
,
WarnPushBase
.
class
);
WarnPushBase
warnPushBase
=
JSON
.
parseObject
(
message
,
WarnPushBase
.
class
);
//获取视频地址
//获取视频地址
//获取前后五秒时间戳
//获取前后五秒时间戳
Date
alarmTime
=
warnPushBase
.
getAlarmTime
();
Date
alarmTime
=
warnPushBase
.
getAlarmTime
();
String
video
=
getVideo
(
warnPushBase
.
getChannelId
(),
alarmTime
.
getTime
()
/
1000
-
5
,
alarmTime
.
getTime
()
/
1000
+
5
);
String
video
=
getVideo
(
warnPushBase
.
getChannelId
(),
alarmTime
.
getTime
()
/
1000
-
5
,
alarmTime
.
getTime
()
/
1000
+
5
);
warnPushBase
.
setAlarmMsg
(
warnPushBase
.
getGradeType
());
warnPushBase
.
setGradeType
(
"摄像头预警"
);
warnPushBase
.
setVideo
(
video
);
warnPushBase
.
setVideo
(
video
);
warnPushBaseMapper
.
add
(
warnPushBase
);
warnPushBaseMapper
.
add
(
warnPushBase
);
...
@@ -73,7 +77,7 @@ public class WarnPushBaseServer {
...
@@ -73,7 +77,7 @@ public class WarnPushBaseServer {
rtspToMP4
.
stopRecord
(
process
[
0
]);
rtspToMP4
.
stopRecord
(
process
[
0
]);
return
"http://172.16.20.211:8080/profile/MP4/"
+
fileName
;
return
"http://172.16.20.211:8080/profile/MP4/"
+
fileName
;
}
catch
(
ClientException
e
)
{
}
catch
(
ClientException
e
)
{
e
.
printStackTrace
();
e
.
printStackTrace
();
}
catch
(
InterruptedException
e
)
{
}
catch
(
InterruptedException
e
)
{
...
@@ -105,30 +109,35 @@ public class WarnPushBaseServer {
...
@@ -105,30 +109,35 @@ public class WarnPushBaseServer {
String
url
=
obj
.
getJSONObject
(
"data"
).
getStr
(
"url"
);
String
url
=
obj
.
getJSONObject
(
"data"
).
getStr
(
"url"
);
String
token
=
obj
.
getJSONObject
(
"data"
).
getStr
(
"token"
);
String
token
=
obj
.
getJSONObject
(
"data"
).
getStr
(
"token"
);
String
[]
parts
=
url
.
split
(
"\\|"
);
String
[]
parts
=
url
.
split
(
"\\|"
);
return
parts
[
0
]
+
"?token="
+
token
+
"&trackID=0"
;
return
parts
[
0
]
+
"?token="
+
token
+
"&trackID=0"
;
}
}
public
void
iotPush
(
WarnPushBase
warnPushBase
){
public
void
iotPush
(
WarnPushBase
warnPushBase
)
{
SimpleDateFormat
simpleDateFormat
=
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss"
);
SimpleDateFormat
simpleDateFormat
=
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss"
);
String
url
=
"http://172.16.20.170:8089/api/v1/aqgl/warn"
;
String
url
=
"http://172.16.20.170:8089/api/v1"
;
IotWarnPushDto
iotWarnPushDto
=
new
IotWarnPushDto
();
String
result_info
=
null
;
iotWarnPushDto
.
setOrder_name
(
"智能安全系纺"
);
try
{
iotWarnPushDto
.
setAlarm_device_name
(
warnPushBase
.
getAlarmDeviceName
());
//同步IOT
iotWarnPushDto
.
setGrade_name
(
warnPushBase
.
getGradeName
());
Map
<
String
,
String
>
bodys
=
new
HashMap
<>();
iotWarnPushDto
.
setGrade_type
(
"摄像头预警"
);
bodys
.
put
(
"order_name"
,
"AI预警平台"
);
iotWarnPushDto
.
setGrade_type_code
(
PinYinUtil
.
getPinYinHeadChar
(
iotWarnPushDto
.
getGrade_type
()));
bodys
.
put
(
"alarm_device_name"
,
warnPushBase
.
getAlarmDeviceName
());
iotWarnPushDto
.
setAlarm_time
(
simpleDateFormat
.
format
(
warnPushBase
.
getAlarmTime
()));
bodys
.
put
(
"grade_name"
,
warnPushBase
.
getGradeName
());
iotWarnPushDto
.
setPicture
(
warnPushBase
.
getPicture
());
bodys
.
put
(
"grade_type"
,
"摄像头预警"
);
iotWarnPushDto
.
setBelong
(
warnPushBase
.
getBelong
());
bodys
.
put
(
"grade_type_code"
,
PinYinUtil
.
getPinYinHeadChar
(
warnPushBase
.
getGradeType
()));
iotWarnPushDto
.
setCreate_time
(
simpleDateFormat
.
format
(
new
Date
()));
bodys
.
put
(
"alarm_time"
,
simpleDateFormat
.
format
(
warnPushBase
.
getAlarmTime
()));
String
json
=
JSON
.
toJSONString
(
iotWarnPushDto
);
bodys
.
put
(
"alarm_msg"
,
warnPushBase
.
getAlarmMsg
());
String
result
=
HttpRequest
.
post
(
url
)
bodys
.
put
(
"picture"
,
warnPushBase
.
getPicture
());
.
body
(
json
)
bodys
.
put
(
"mine"
,
warnPushBase
.
getBelong
());
.
execute
().
body
();
bodys
.
put
(
"create_time"
,
simpleDateFormat
.
format
(
new
Date
()));
System
.
out
.
println
(
"IOT返回结果:"
+
result
);
result_info
=
HttpUtils
.
doPostJson
(
url
,
null
,
JsonUtil
.
getObjectToString
(
bodys
));
}
catch
(
Exception
e
)
{
System
.
out
.
println
(
"同步IOT出错!!!"
);
}
System
.
out
.
println
(
"IOT返回结果:"
+
result_info
);
}
}
}
}
src/main/java/com/example/mykafkaproject/utils/HttpUtils.java
0 → 100644
View file @
d8d9e368
package
com
.
example
.
mykafkaproject
.
utils
;
import
org.apache.http.client.methods.CloseableHttpResponse
;
import
org.apache.http.client.methods.HttpPost
;
import
org.apache.http.entity.ContentType
;
import
org.apache.http.entity.StringEntity
;
import
org.apache.http.impl.client.CloseableHttpClient
;
import
org.apache.http.impl.client.HttpClients
;
import
org.apache.http.util.EntityUtils
;
import
java.io.IOException
;
import
java.util.Iterator
;
import
java.util.Map
;
public
class
HttpUtils
{
/**
* Post请求传参
* @param url
* @param headerMap
* @param json
* @return
*/
public
static
String
doPostJson
(
String
url
,
Map
<
String
,
String
>
headerMap
,
String
json
)
{
// 创建Httpclient对象
CloseableHttpClient
httpClient
=
HttpClients
.
createDefault
();
CloseableHttpResponse
response
=
null
;
String
resultString
=
""
;
try
{
// 创建Http Post请求
HttpPost
httpPost
=
new
HttpPost
(
url
);
if
(
headerMap
!=
null
)
{
Iterator
headerIterator
=
headerMap
.
entrySet
().
iterator
();
//循环增加header
while
(
headerIterator
.
hasNext
()){
Map
.
Entry
<
String
,
String
>
elem
=
(
Map
.
Entry
<
String
,
String
>)
headerIterator
.
next
();
httpPost
.
addHeader
(
elem
.
getKey
(),
elem
.
getValue
());
}
}
// 创建请求内容
StringEntity
entity
=
new
StringEntity
(
json
,
ContentType
.
APPLICATION_JSON
);
httpPost
.
setEntity
(
entity
);
// 执行http请求
response
=
httpClient
.
execute
(
httpPost
);
resultString
=
EntityUtils
.
toString
(
response
.
getEntity
(),
"UTF8"
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
finally
{
try
{
response
.
close
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
return
resultString
;
}
}
src/main/java/com/example/mykafkaproject/utils/JsonUtil.java
0 → 100644
View file @
d8d9e368
package
com
.
example
.
mykafkaproject
.
utils
;
import
com.alibaba.fastjson.serializer.SerializerFeature
;
import
com.alibaba.fastjson.JSON
;
public
class
JsonUtil
{
/**
* 功能描述:把java对象转换成JSON数据
* @param object java对象
* @return JSON数据
*/
public
static
String
getObjectToString
(
Object
object
)
{
return
JSON
.
toJSONString
(
object
,
SerializerFeature
.
WriteMapNullValue
);
}
}
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