Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
amos-boot-biz
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
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
项目统一框架
amos-boot-biz
Commits
49c43cd2
Commit
49c43cd2
authored
Aug 24, 2024
by
KeYong
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'origin/develop_dl_bugfix_0723' into develop_dl_bugfix_0723
parents
88e7d2da
cc9a951d
Show whitespace changes
Inline
Side-by-side
Showing
19 changed files
with
180 additions
and
1232 deletions
+180
-1232
HttpUtils.java
...ava/com/yeejoin/amos/boot/biz/common/utils/HttpUtils.java
+0
-175
OrgUsrMapper.xml
...ule-common-api/src/main/resources/mapper/OrgUsrMapper.xml
+3
-1
PluginInterceptor.java
...oin/equipmanage/common/interceptor/PluginInterceptor.java
+12
-0
HttpUtil.java
...n/java/com/yeejoin/equipmanage/common/utils/HttpUtil.java
+0
-392
HttpUtils.java
.../java/com/yeejoin/equipmanage/common/utils/HttpUtils.java
+0
-460
PoolStatisticController.java
...ejoin/equipmanage/controller/PoolStatisticController.java
+5
-1
SupervisionConfigureController.java
...quipmanage/controller/SupervisionConfigureController.java
+1
-1
WlCarMileageController.java
...eejoin/equipmanage/controller/WlCarMileageController.java
+1
-11
IotFeign.java
...src/main/java/com/yeejoin/equipmanage/fegin/IotFeign.java
+8
-0
IWlCarMileageService.java
...com/yeejoin/equipmanage/service/IWlCarMileageService.java
+0
-1
EquipmentSpecificSerivceImpl.java
...quipmanage/service/impl/EquipmentSpecificSerivceImpl.java
+0
-2
FireFightingSystemServiceImpl.java
...uipmanage/service/impl/FireFightingSystemServiceImpl.java
+0
-2
MqttReceiveServiceImpl.java
...join/equipmanage/service/impl/MqttReceiveServiceImpl.java
+139
-4
WlCarMileageServiceImpl.java
...oin/equipmanage/service/impl/WlCarMileageServiceImpl.java
+2
-146
SpeechTranscriberDemo.java
...odule/jcs/biz/audioToText/util/SpeechTranscriberDemo.java
+0
-27
EmergencyMapper.xml
...ystem-equip/src/main/resources/mapper/EmergencyMapper.xml
+2
-2
FireFightingSystemMapper.xml
...ip/src/main/resources/mapper/FireFightingSystemMapper.xml
+2
-2
application.properties
...boot-system-jcs/src/main/resources/application.properties
+3
-3
dbTemplate_plan_task.xml
...rol/src/main/resources/db/mapper/dbTemplate_plan_task.xml
+2
-2
No files found.
amos-boot-biz-common/src/main/java/com/yeejoin/amos/boot/biz/common/utils/HttpUtils.java
View file @
49c43cd2
...
...
@@ -62,182 +62,7 @@ public class HttpUtils {
requestConfig
=
configBuilder
.
build
();
}
/**
* 发送 GET 请求(HTTP),不带输入数据
*
* @param url
* @return
*/
public
static
String
doGet
(
String
url
)
{
return
doGet
(
url
,
new
HashMap
<
String
,
Object
>());
}
/**
* 发送 GET 请求(HTTP),K-V形式
*
* @param url
* @param params
* @return
*/
public
static
String
doGet
(
String
url
,
Map
<
String
,
Object
>
params
)
{
String
apiUrl
=
url
;
StringBuffer
param
=
new
StringBuffer
();
int
i
=
0
;
for
(
String
key
:
params
.
keySet
())
{
if
(
i
==
0
)
param
.
append
(
"?"
);
else
param
.
append
(
"&"
);
param
.
append
(
key
).
append
(
"="
).
append
(
params
.
get
(
key
));
i
++;
}
apiUrl
+=
param
;
String
result
=
null
;
HttpClient
httpClient
=
null
;
if
(
apiUrl
.
startsWith
(
"https"
))
{
httpClient
=
HttpClients
.
custom
().
setSSLSocketFactory
(
createSSLConnSocketFactory
())
.
setConnectionManager
(
connMgr
).
setDefaultRequestConfig
(
requestConfig
).
build
();
}
else
{
httpClient
=
HttpClients
.
createDefault
();
}
try
{
HttpGet
httpGet
=
new
HttpGet
(
apiUrl
);
HttpResponse
response
=
httpClient
.
execute
(
httpGet
);
HttpEntity
entity
=
response
.
getEntity
();
if
(
entity
!=
null
)
{
InputStream
instream
=
entity
.
getContent
();
result
=
IOUtils
.
toString
(
instream
,
"UTF-8"
);
}
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
return
result
;
}
/**
* 发送 POST 请求(HTTP),不带输入数据
*
* @param apiUrl
* @return
*/
public
static
String
doPost
(
String
apiUrl
)
{
return
doPost
(
apiUrl
,
new
HashMap
<
String
,
Object
>());
}
/**
* 发送 POST 请求,K-V形式
*
* @param apiUrl
* API接口URL
* @param params
* 参数map
* @return
*/
public
static
String
doPost
(
String
apiUrl
,
Map
<
String
,
Object
>
params
)
{
CloseableHttpClient
httpClient
=
null
;
if
(
apiUrl
.
startsWith
(
"https"
))
{
httpClient
=
HttpClients
.
custom
().
setSSLSocketFactory
(
createSSLConnSocketFactory
())
.
setConnectionManager
(
connMgr
).
setDefaultRequestConfig
(
requestConfig
).
build
();
}
else
{
httpClient
=
HttpClients
.
createDefault
();
}
String
httpStr
=
null
;
HttpPost
httpPost
=
new
HttpPost
(
apiUrl
);
CloseableHttpResponse
response
=
null
;
try
{
httpPost
.
setConfig
(
requestConfig
);
List
<
NameValuePair
>
pairList
=
new
ArrayList
<>(
params
.
size
());
for
(
Map
.
Entry
<
String
,
Object
>
entry
:
params
.
entrySet
())
{
NameValuePair
pair
=
new
BasicNameValuePair
(
entry
.
getKey
(),
entry
.
getValue
()!=
null
?
entry
.
getValue
().
toString
():
""
);
pairList
.
add
(
pair
);
}
httpPost
.
setEntity
(
new
UrlEncodedFormEntity
(
pairList
,
Charset
.
forName
(
"UTF-8"
)));
response
=
httpClient
.
execute
(
httpPost
);
HttpEntity
entity
=
response
.
getEntity
();
httpStr
=
EntityUtils
.
toString
(
entity
,
"UTF-8"
);
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
finally
{
if
(
response
!=
null
)
{
try
{
EntityUtils
.
consume
(
response
.
getEntity
());
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
}
return
httpStr
;
}
/**
* 发送 POST 请求,JSON形式,接收端需要支持json形式,否则取不到数据
*
* @param apiUrl
* @param json
* json对象
* @return
*/
public
static
String
doPost
(
String
apiUrl
,
String
json
)
{
CloseableHttpClient
httpClient
=
null
;
if
(
apiUrl
.
startsWith
(
"https"
))
{
httpClient
=
HttpClients
.
custom
().
setSSLSocketFactory
(
createSSLConnSocketFactory
()).
setConnectionManager
(
connMgr
).
setDefaultRequestConfig
(
requestConfig
).
build
();
}
else
{
httpClient
=
HttpClients
.
createDefault
();
}
String
httpStr
=
null
;
HttpPost
httpPost
=
new
HttpPost
(
apiUrl
);
CloseableHttpResponse
response
=
null
;
try
{
httpPost
.
setConfig
(
requestConfig
);
StringEntity
stringEntity
=
new
StringEntity
(
json
,
"UTF-8"
);
// 解决中文乱码问题
stringEntity
.
setContentEncoding
(
"UTF-8"
);
stringEntity
.
setContentType
(
"application/json"
);
httpPost
.
setEntity
(
stringEntity
);
response
=
httpClient
.
execute
(
httpPost
);
HttpEntity
entity
=
response
.
getEntity
();
httpStr
=
EntityUtils
.
toString
(
entity
,
"UTF-8"
);
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
finally
{
if
(
response
!=
null
)
{
try
{
EntityUtils
.
consume
(
response
.
getEntity
());
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
}
return
httpStr
;
}
/**
* 创建SSL安全连接
*
* @return
*/
private
static
SSLConnectionSocketFactory
createSSLConnSocketFactory
()
{
SSLConnectionSocketFactory
sslsf
=
null
;
try
{
SSLContext
sslContext
=
new
SSLContextBuilder
().
loadTrustMaterial
(
null
,
new
TrustStrategy
()
{
public
boolean
isTrusted
(
X509Certificate
[]
chain
,
String
authType
)
throws
CertificateException
{
return
true
;
}
}).
build
();
sslsf
=
new
SSLConnectionSocketFactory
(
sslContext
,
new
HostnameVerifier
()
{
@Override
public
boolean
verify
(
String
arg0
,
SSLSession
arg1
)
{
return
true
;
}
});
}
catch
(
GeneralSecurityException
e
)
{
e
.
printStackTrace
();
}
return
sslsf
;
}
...
...
amos-boot-module/amos-boot-module-api/amos-boot-module-common-api/src/main/resources/mapper/OrgUsrMapper.xml
View file @
49c43cd2
...
...
@@ -1664,6 +1664,7 @@
GROUP BY
a.sequenceNbr
ORDER BY a.personStatus DESC
LIMIT #{map.pageNum}, #{map.pageSize}
</select>
...
...
@@ -1718,6 +1719,7 @@
a.biz_org_name IS NOT NULL
AND a.is_delete = 0
AND a.biz_org_type = 'PERSON'
and fp.is_delete = 0
<if
test=
'bizOrgCode!=null and bizOrgCode!=""'
>
and LEFT(a.biz_org_code,18) like concat (#{bizOrgCode},'%')
</if>
<if
test=
'peopleTypeCode != null and peopleTypeCode != ""'
>
and a.peopleType like concat ('%', #{peopleTypeCode},'%')
</if>
</select>
...
...
@@ -1841,7 +1843,7 @@
AND a.is_delete = 0
AND a.biz_org_type = 'PERSON'
AND fp.is_delete = 0
AND LENGTH( a.biz_org_code )
=
18
AND LENGTH( a.biz_org_code )
>
18
<if
test=
'bizOrgCode!=null and bizOrgCode!=""'
>
and LEFT(a.biz_org_code,18) like concat (#{bizOrgCode},'%')
</if>
...
...
amos-boot-module/amos-boot-module-api/amos-boot-module-equip-api/src/main/java/com/yeejoin/equipmanage/common/interceptor/PluginInterceptor.java
View file @
49c43cd2
...
...
@@ -82,6 +82,18 @@ public class PluginInterceptor implements Interceptor {
ReflectionUtils
.
makeAccessible
(
field
);
field
.
set
(
boundSql
,
sql
);
return
executor
.
query
(
mappedStatement
,
parameter
,
rowBounds
,
resultHandler
,
cacheKey
,
boundSql
);
}
else
if
(
"com.yeejoin.equipmanage.mapper.FireFightingSystemMapper.getSystemInfoPage"
.
equals
(
id
))
{
//执行结果
String
sortField
=
""
;
if
(
parameter
instanceof
HashMap
)
{
sortField
=
((
HashMap
<?,
?>)
parameter
).
get
(
"sortField"
).
toString
();
}
sql
=
sql
.
replace
(
"_sortField"
,
sortField
);
//通过反射修改sql语句
Field
field
=
boundSql
.
getClass
().
getDeclaredField
(
"sql"
);
ReflectionUtils
.
makeAccessible
(
field
);
field
.
set
(
boundSql
,
sql
);
return
executor
.
query
(
mappedStatement
,
parameter
,
rowBounds
,
resultHandler
,
cacheKey
,
boundSql
);
}
else
{
return
invocation
.
proceed
();
}
...
...
amos-boot-module/amos-boot-module-api/amos-boot-module-equip-api/src/main/java/com/yeejoin/equipmanage/common/utils/HttpUtil.java
deleted
100644 → 0
View file @
88e7d2da
package
com
.
yeejoin
.
equipmanage
.
common
.
utils
;
import
org.apache.http.HttpEntity
;
import
org.apache.http.HttpStatus
;
import
org.apache.http.NameValuePair
;
import
org.apache.http.client.config.RequestConfig
;
import
org.apache.http.client.entity.UrlEncodedFormEntity
;
import
org.apache.http.client.methods.CloseableHttpResponse
;
import
org.apache.http.client.methods.HttpGet
;
import
org.apache.http.client.methods.HttpPost
;
import
org.apache.http.client.utils.URIBuilder
;
import
org.apache.http.config.Registry
;
import
org.apache.http.config.RegistryBuilder
;
import
org.apache.http.conn.socket.ConnectionSocketFactory
;
import
org.apache.http.conn.socket.PlainConnectionSocketFactory
;
import
org.apache.http.conn.ssl.SSLConnectionSocketFactory
;
import
org.apache.http.conn.ssl.TrustStrategy
;
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.impl.conn.PoolingHttpClientConnectionManager
;
import
org.apache.http.message.BasicNameValuePair
;
import
org.apache.http.ssl.SSLContextBuilder
;
import
org.apache.http.ssl.SSLContexts
;
import
org.apache.http.util.EntityUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.util.Assert
;
import
javax.net.ssl.HostnameVerifier
;
import
javax.net.ssl.SSLContext
;
import
java.io.BufferedReader
;
import
java.io.IOException
;
import
java.io.InputStreamReader
;
import
java.net.URISyntaxException
;
import
java.security.KeyManagementException
;
import
java.security.KeyStoreException
;
import
java.security.NoSuchAlgorithmException
;
import
java.util.ArrayList
;
import
java.util.Iterator
;
import
java.util.List
;
import
java.util.Map
;
/**
* @description: http https工具类 原生
* @author: duanwei
* @create: 2019-06-03 11:19
**/
public
class
HttpUtil
{
private
static
final
Logger
log
=
LoggerFactory
.
getLogger
(
HttpUtil
.
class
);
// 连接超时时间
public
static
final
int
CONNECTION_TIMEOUT
=
5000
;
// 请求超时时间
public
static
final
int
CONNECTION_REQUEST_TIMEOUT
=
5000
;
// 数据读取等待超时
public
static
final
int
SOCKET_TIMEOUT
=
10000
;
// http
public
static
final
String
HTTP
=
"http"
;
// https
public
static
final
String
HTTPS
=
"https"
;
// http端口
public
static
final
int
DEFAULT_HTTP_PORT
=
80
;
// https端口
public
static
final
int
DEFAULT_HTTPS_PORT
=
443
;
// 默认编码
public
static
final
String
DEFAULT_ENCODING
=
"UTF-8"
;
/**
* get请求(1.处理http请求;2.处理https请求,信任所有证书)[默认编码:UTF-8]
*
* @param url (参数直接拼接到URL后面,即http://test.com?a=1&b=2的形式)
* @return
*/
public
static
String
get
(
String
url
)
throws
IOException
,
URISyntaxException
,
NoSuchAlgorithmException
,
KeyStoreException
,
KeyManagementException
{
return
get
(
url
,
null
,
DEFAULT_ENCODING
);
}
/**
* get请求(1.处理http请求;2.处理https请求,信任所有证书)[默认编码:UTF-8]
*
* @param url (url不带参数,例:http://test.com)
* @param reqMap (参数放置到一个map中)
* @return
*/
public
static
String
get
(
String
url
,
Map
<
String
,
Object
>
reqMap
)
throws
IOException
,
URISyntaxException
,
NoSuchAlgorithmException
,
KeyStoreException
,
KeyManagementException
{
return
get
(
url
,
reqMap
,
DEFAULT_ENCODING
);
}
/**
* 根据请求头选择相应的client
* https HttpUtil.createSSLInsecureClient
* http createDefault
* @param url (url不带参数,例:http://test.com)
* @return CloseableHttpClient
*/
public
static
CloseableHttpClient
getHttpClient
(
String
url
){
CloseableHttpClient
httpClient
=
null
;
try
{
if
(
url
.
startsWith
(
HTTPS
))
{
// 创建一个SSL信任所有证书的httpClient对象
httpClient
=
HttpUtil
.
createSSLInsecureClient
();
}
else
{
httpClient
=
HttpClients
.
createDefault
();
}
}
catch
(
Exception
e
){
log
.
error
(
"请求client 初始化失败 请检查地址是否正确,url={}"
,
url
,
e
);
throw
new
RuntimeException
(
e
);
}
return
httpClient
;
}
/**
* 获取post请求头
* @param url (url不带参数,例:http://test.com)
* @return HttpPost
*/
public
static
HttpPost
getHttpPost
(
String
url
)
{
HttpPost
httpPost
=
new
HttpPost
(
url
);
RequestConfig
requestConfig
=
RequestConfig
.
custom
()
.
setConnectTimeout
(
CONNECTION_TIMEOUT
)
.
setConnectionRequestTimeout
(
CONNECTION_REQUEST_TIMEOUT
)
.
setSocketTimeout
(
SOCKET_TIMEOUT
)
.
setRedirectsEnabled
(
true
)
.
build
();
httpPost
.
setConfig
(
requestConfig
);
return
httpPost
;
}
/**
* get请求(1.处理http请求;2.处理https请求,信任所有证书)
*
* @param url (只能是http或https请求)
* @param encoding
* @return
*/
public
static
String
get
(
String
url
,
Map
<
String
,
Object
>
reqMap
,
String
encoding
)
throws
IOException
,
URISyntaxException
,
NoSuchAlgorithmException
,
KeyStoreException
,
KeyManagementException
{
Assert
.
hasText
(
url
,
"url invalid"
);
String
result
=
""
;
// 处理参数
List
<
NameValuePair
>
params
=
buildParams
(
reqMap
);
CloseableHttpResponse
response
=
null
;
HttpGet
httpGet
;
CloseableHttpClient
httpClient
=
null
;
try
{
httpClient
=
getHttpClient
(
url
);
if
(
params
!=
null
&&
params
.
size
()
>
0
)
{
URIBuilder
builder
=
new
URIBuilder
(
url
);
builder
.
setParameters
(
params
);
httpGet
=
new
HttpGet
(
builder
.
build
());
}
else
{
httpGet
=
new
HttpGet
(
url
);
}
RequestConfig
requestConfig
=
RequestConfig
.
custom
()
.
setConnectTimeout
(
CONNECTION_TIMEOUT
)
.
setConnectionRequestTimeout
(
CONNECTION_REQUEST_TIMEOUT
)
.
setSocketTimeout
(
SOCKET_TIMEOUT
)
//默认允许自动重定向
.
setRedirectsEnabled
(
true
)
.
build
();
httpGet
.
setConfig
(
requestConfig
);
// 发送请求,并接收响应
response
=
httpClient
.
execute
(
httpGet
);
result
=
handleResponse
(
url
,
encoding
,
response
);
}
finally
{
ExtendedIOUtils
.
closeQuietly
(
httpClient
);
ExtendedIOUtils
.
closeQuietly
(
response
);
}
return
result
;
}
/**
* post请求(1.处理http请求;2.处理https请求,信任所有证书)[默认编码:UTF-8]
*
* @param url
* @param reqMap
* @return
*/
public
static
String
post
(
String
url
,
Map
<
String
,
Object
>
reqMap
)
throws
IOException
,
NoSuchAlgorithmException
,
KeyStoreException
,
KeyManagementException
{
return
post
(
url
,
reqMap
,
DEFAULT_ENCODING
);
}
/**
* post请求(1.处理http请求;2.处理https请求,信任所有证书)
*
* @param url
* @param reqMap 入参是个map
* @param encoding
* @return
*/
public
static
String
post
(
String
url
,
Map
<
String
,
Object
>
reqMap
,
String
encoding
)
throws
IOException
,
NoSuchAlgorithmException
,
KeyStoreException
,
KeyManagementException
{
Assert
.
hasText
(
url
,
"url invalid"
);
String
result
=
""
;
// 添加参数
List
<
NameValuePair
>
params
=
buildParams
(
reqMap
);
CloseableHttpClient
httpClient
=
null
;
CloseableHttpResponse
response
=
null
;
try
{
httpClient
=
getHttpClient
(
url
);
HttpPost
httpPost
=
getHttpPost
(
url
);
httpPost
.
setHeader
(
"Content-type"
,
"application/x-www-form-urlencoded"
);
httpPost
.
setEntity
(
new
UrlEncodedFormEntity
(
params
,
encoding
));
// 发送请求,并接收响应
response
=
httpClient
.
execute
(
httpPost
);
result
=
handleResponse
(
url
,
encoding
,
response
);
log
.
info
(
"http调用完成,返回数据:{}"
,
result
);
}
finally
{
ExtendedIOUtils
.
closeQuietly
(
httpClient
);
ExtendedIOUtils
.
closeQuietly
(
response
);
}
return
result
;
}
/**
* post请求(1.处理http请求;2.处理https请求,信任所有证书)
*
* @param url
* @param jsonParams 入参是个json字符串
* @return
*/
public
static
String
post
(
String
url
,
String
jsonParams
)
throws
IOException
,
NoSuchAlgorithmException
,
KeyStoreException
,
KeyManagementException
{
log
.
info
(
"----->调用请求 url:{} ---->json参数:{}"
,
url
,
jsonParams
);
return
post
(
url
,
jsonParams
,
DEFAULT_ENCODING
);
}
/**
* post请求(1.处理http请求;2.处理https请求,信任所有证书)
*
* @param url
* @param jsonParams 入参是个json字符串
* @param encoding
* @return
*/
public
static
String
post
(
String
url
,
String
jsonParams
,
String
encoding
)
throws
IOException
,
NoSuchAlgorithmException
,
KeyStoreException
,
KeyManagementException
{
Assert
.
hasText
(
url
,
"url invalid"
);
String
result
;
CloseableHttpClient
httpClient
;
if
(
url
.
startsWith
(
HTTPS
))
{
// 创建一个SSL信任所有证书的httpClient对象
httpClient
=
HttpUtil
.
createSSLInsecureClient
();
}
else
{
httpClient
=
HttpClients
.
createDefault
();
}
CloseableHttpResponse
response
=
null
;
try
{
HttpPost
httpPost
=
getHttpPost
(
url
);
httpPost
.
setHeader
(
"Content-Type"
,
"application/json"
);
httpPost
.
setEntity
(
new
StringEntity
(
jsonParams
,
ContentType
.
create
(
"application/json"
,
encoding
)));
// 发送请求,并接收响应
response
=
httpClient
.
execute
(
httpPost
);
result
=
handleResponse
(
url
,
encoding
,
response
);
// result= JSONObject.parseObject(result).getString("data");
}
finally
{
ExtendedIOUtils
.
closeQuietly
(
httpClient
);
ExtendedIOUtils
.
closeQuietly
(
response
);
}
return
result
;
}
/**
* 创建一个SSL信任所有证书的httpClient对象
*
* @return
*/
public
static
CloseableHttpClient
createSSLInsecureClient
()
throws
KeyStoreException
,
NoSuchAlgorithmException
,
KeyManagementException
{
// 默认信任所有证书
HostnameVerifier
hostnameVerifier
=
(
hostname
,
session
)
->
true
;
SSLContext
sslContext
=
SSLContexts
.
custom
().
loadTrustMaterial
(
null
,
(
TrustStrategy
)
(
chain
,
authType
)
->
true
).
build
();
SSLConnectionSocketFactory
sslConnectionSocketFactory
=
new
SSLConnectionSocketFactory
(
sslContext
,
hostnameVerifier
);
return
HttpClients
.
custom
().
setSSLSocketFactory
(
sslConnectionSocketFactory
).
build
();
}
/**
* 处理响应,获取响应报文
*
* @param url
* @param encoding
* @param response
* @return
* @throws IOException
*/
private
static
String
handleResponse
(
String
url
,
String
encoding
,
CloseableHttpResponse
response
)
throws
IOException
{
StringBuilder
sb
=
new
StringBuilder
();
BufferedReader
br
=
null
;
try
{
if
(
response
!=
null
)
{
if
(
response
.
getStatusLine
().
getStatusCode
()
==
HttpStatus
.
SC_OK
)
{
// 获取响应实体
HttpEntity
entity
=
response
.
getEntity
();
if
(
entity
!=
null
)
{
br
=
new
BufferedReader
(
new
InputStreamReader
(
entity
.
getContent
(),
encoding
));
String
s
;
while
((
s
=
br
.
readLine
())
!=
null
)
{
sb
.
append
(
s
);
}
}
// 释放entity
EntityUtils
.
consume
(
entity
);
}
else
if
(
response
.
getStatusLine
().
getStatusCode
()
==
HttpStatus
.
SC_NOT_FOUND
)
{
log
.
info
(
"-----> get请求404,未找到资源. url:"
+
url
);
}
else
if
(
response
.
getStatusLine
().
getStatusCode
()
==
HttpStatus
.
SC_INTERNAL_SERVER_ERROR
)
{
log
.
info
(
"-----> get请求500,服务器端异常. url:"
+
url
);
}
}
}
finally
{
ExtendedIOUtils
.
closeQuietly
(
br
);
}
return
sb
.
toString
();
}
/**
* 采用绕过验证的方式处理https请求
*
* @param url
* @param reqMap
* @param encoding
* @return
*/
public
static
String
postSSLUrl
(
String
url
,
Map
<
String
,
Object
>
reqMap
,
String
encoding
)
throws
IOException
,
KeyManagementException
,
NoSuchAlgorithmException
,
KeyStoreException
{
String
result
;
CloseableHttpClient
httpClient
=
null
;
CloseableHttpResponse
response
=
null
;
// 添加参数
List
<
NameValuePair
>
params
=
buildParams
(
reqMap
);
try
{
//采用绕过验证的方式处理https请求
HostnameVerifier
hostnameVerifier
=
(
hostname
,
session
)
->
true
;
SSLContext
sslcontext
=
createIgnoreVerifySSL
();
//设置协议http和https对应的处理socket链接工厂的对象
Registry
<
ConnectionSocketFactory
>
socketFactoryRegistry
=
RegistryBuilder
.<
ConnectionSocketFactory
>
create
()
.
register
(
"http"
,
PlainConnectionSocketFactory
.
INSTANCE
)
.
register
(
"https"
,
new
SSLConnectionSocketFactory
(
sslcontext
,
hostnameVerifier
))
.
build
();
PoolingHttpClientConnectionManager
connManager
=
new
PoolingHttpClientConnectionManager
(
socketFactoryRegistry
);
//创建自定义的httpclient对象
httpClient
=
HttpClients
.
custom
().
setConnectionManager
(
connManager
).
build
();
//创建post方式请求对象
HttpPost
httpPost
=
new
HttpPost
(
url
);
httpPost
.
setEntity
(
new
UrlEncodedFormEntity
(
params
,
encoding
));
//指定报文头Content-type、User-Agent
httpPost
.
setHeader
(
"Content-type"
,
"application/x-www-form-urlencoded"
);
//执行请求操作,并拿到结果(同步阻塞)
response
=
httpClient
.
execute
(
httpPost
);
result
=
handleResponse
(
url
,
encoding
,
response
);
}
finally
{
ExtendedIOUtils
.
closeQuietly
(
httpClient
);
ExtendedIOUtils
.
closeQuietly
(
response
);
}
return
result
;
}
private
static
List
<
NameValuePair
>
buildParams
(
Map
<
String
,
Object
>
reqMap
)
{
List
<
NameValuePair
>
params
=
new
ArrayList
<>();
if
(
reqMap
!=
null
&&
reqMap
.
keySet
().
size
()
>
0
)
{
Iterator
<
Map
.
Entry
<
String
,
Object
>>
iter
=
reqMap
.
entrySet
().
iterator
();
while
(
iter
.
hasNext
())
{
Map
.
Entry
<
String
,
Object
>
entity
=
iter
.
next
();
params
.
add
(
new
BasicNameValuePair
(
entity
.
getKey
(),
entity
.
getValue
().
toString
()));
}
}
return
params
;
}
/**
* 绕过验证
*
* @return
* @throws NoSuchAlgorithmException
* @throws KeyManagementException
*/
public
static
SSLContext
createIgnoreVerifySSL
()
throws
NoSuchAlgorithmException
,
KeyManagementException
,
KeyStoreException
{
// 信任所有证书
return
new
SSLContextBuilder
().
loadTrustMaterial
(
null
,
(
TrustStrategy
)
(
arg0
,
arg1
)
->
true
).
build
();
}
}
amos-boot-module/amos-boot-module-api/amos-boot-module-equip-api/src/main/java/com/yeejoin/equipmanage/common/utils/HttpUtils.java
deleted
100644 → 0
View file @
88e7d2da
package
com
.
yeejoin
.
equipmanage
.
common
.
utils
;
import
com.alibaba.fastjson.JSONObject
;
import
com.yeejoin.equipmanage.common.config.GlobalCache
;
import
com.yeejoin.equipmanage.common.vo.ResponeVo
;
import
org.apache.http.NameValuePair
;
import
org.apache.http.client.config.RequestConfig
;
import
org.apache.http.client.entity.UrlEncodedFormEntity
;
import
org.apache.http.client.methods.*
;
import
org.apache.http.config.Registry
;
import
org.apache.http.config.RegistryBuilder
;
import
org.apache.http.conn.socket.ConnectionSocketFactory
;
import
org.apache.http.conn.socket.PlainConnectionSocketFactory
;
import
org.apache.http.conn.ssl.SSLConnectionSocketFactory
;
import
org.apache.http.conn.ssl.TrustStrategy
;
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.impl.conn.PoolingHttpClientConnectionManager
;
import
org.apache.http.message.BasicNameValuePair
;
import
org.apache.http.ssl.SSLContextBuilder
;
import
org.apache.http.ssl.SSLContexts
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.util.Assert
;
import
javax.net.ssl.HostnameVerifier
;
import
javax.net.ssl.SSLContext
;
import
javax.net.ssl.TrustManager
;
import
javax.net.ssl.X509TrustManager
;
import
java.io.BufferedReader
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.InputStreamReader
;
import
java.security.KeyManagementException
;
import
java.security.KeyStoreException
;
import
java.security.NoSuchAlgorithmException
;
import
java.util.ArrayList
;
import
java.util.Iterator
;
import
java.util.List
;
import
java.util.Map
;
/**
* @description: HTTP HTTPS 二次封装
* @author: duanwei
* @create: 2020-05-28 13:57
**/
public
class
HttpUtils
{
private
static
final
Logger
log
=
LoggerFactory
.
getLogger
(
HttpUtils
.
class
);
// 连接超时时间
public
static
final
int
CONNECTION_TIMEOUT
=
5000
;
// 请求超时时间
public
static
final
int
CONNECTION_REQUEST_TIMEOUT
=
5000
;
// 数据读取等待超时
public
static
final
int
SOCKET_TIMEOUT
=
10000
;
// http
public
static
final
String
HTTP
=
"http"
;
// https
public
static
final
String
HTTPS
=
"https"
;
// http端口
public
static
final
int
DEFAULT_HTTP_PORT
=
80
;
// https端口
public
static
final
int
DEFAULT_HTTPS_PORT
=
443
;
// 默认编码
public
static
final
String
DEFAULT_ENCODING
=
"UTF-8"
;
/**
* 根据请求头选择相应的client
* https HttpUtil.createSSLInsecureClient
* http createDefault
*
* @param url (url不带参数,例:http://test.com)
* @return CloseableHttpClient
*/
private
static
CloseableHttpClient
getHttpClient
(
String
url
)
{
CloseableHttpClient
httpClient
=
null
;
try
{
if
(
url
.
startsWith
(
HTTPS
))
{
// 创建一个SSL信任所有证书的httpClient对象
httpClient
=
HttpUtils
.
createSSLInsecureClient
();
}
else
{
httpClient
=
HttpClients
.
createDefault
();
}
}
catch
(
Exception
e
)
{
log
.
error
(
"请求client 初始化失败 请检查地址是否正确,url="
+
url
+
" error"
+
e
);
throw
new
RuntimeException
(
e
);
}
return
httpClient
;
}
/**
* 获取post请求头
*
* @param url (url不带参数,例:http://test.com)
* @return HttpPost
*/
public
static
HttpPost
getHttpPost
(
String
url
)
{
HttpPost
httpPost
=
new
HttpPost
(
url
);
RequestConfig
requestConfig
=
RequestConfig
.
custom
()
.
setConnectTimeout
(
CONNECTION_TIMEOUT
)
.
setConnectionRequestTimeout
(
CONNECTION_REQUEST_TIMEOUT
)
.
setSocketTimeout
(
SOCKET_TIMEOUT
)
.
setRedirectsEnabled
(
true
)
.
build
();
httpPost
.
setConfig
(
requestConfig
);
return
httpPost
;
}
/**
* get请求(1.处理http请求;2.处理https请求,信任所有证书)
*
* @param url (只能是http或https请求)
*/
public
static
ResponeVo
get
(
String
url
)
throws
IOException
{
log
.
info
(
"----->调用请求 url:"
+
url
);
String
result
=
""
;
// 处理参数
HttpGet
httpGet
;
CloseableHttpClient
httpClient
=
null
;
httpClient
=
getHttpClient
(
url
);
httpGet
=
new
HttpGet
(
url
);
//加入请求头
if
(
GlobalCache
.
header
!=
null
)
{
for
(
String
key
:
GlobalCache
.
header
.
keySet
())
{
String
value
=
GlobalCache
.
header
.
get
(
key
);
httpGet
.
setHeader
(
key
,
value
);
}
}
//加入全局请求令牌权限
httpGet
.
setHeader
(
"Http-Authorization"
,
GlobalCache
.
paramMap
.
get
(
"token"
));
RequestConfig
requestConfig
=
RequestConfig
.
custom
()
.
setConnectTimeout
(
CONNECTION_TIMEOUT
)
.
setConnectionRequestTimeout
(
CONNECTION_REQUEST_TIMEOUT
)
.
setSocketTimeout
(
SOCKET_TIMEOUT
)
//默认允许自动重定向
.
setRedirectsEnabled
(
true
)
.
build
();
httpGet
.
setConfig
(
requestConfig
);
return
baseRequest
(
httpClient
,
httpGet
);
}
/**
* post请求(1.处理http请求;2.处理https请求,信任所有证书)
*
* @param url
* @param jsonParams 入参是个json字符串
* @return
*/
public
static
ResponeVo
post
(
String
url
,
String
jsonParams
)
throws
IOException
,
NoSuchAlgorithmException
,
KeyStoreException
,
KeyManagementException
{
Assert
.
hasText
(
url
,
"url invalid"
);
String
result
;
CloseableHttpClient
httpClient
;
if
(
url
.
startsWith
(
HTTPS
))
{
// 创建一个SSL信任所有证书的httpClient对象
httpClient
=
HttpUtils
.
createSSLInsecureClient
();
}
else
{
httpClient
=
HttpClients
.
createDefault
();
}
CloseableHttpResponse
response
=
null
;
HttpPost
httpPost
=
getHttpPost
(
url
);
if
(
GlobalCache
.
header
!=
null
&&
!
GlobalCache
.
header
.
isEmpty
())
{
for
(
String
key
:
GlobalCache
.
header
.
keySet
())
{
String
value
=
GlobalCache
.
header
.
get
(
key
);
httpPost
.
setHeader
(
key
,
value
);
}
}
else
{
GlobalCache
.
header
.
put
(
"Content-Type"
,
"application/json;charset=UTF-8"
);
}
//加入全局请求令牌权限
httpPost
.
setHeader
(
"Http-Authorization"
,
GlobalCache
.
paramMap
.
get
(
"token"
));
if
(
GlobalCache
.
header
.
get
(
"Content-Type"
)
!=
null
)
{
String
contentType
=
GlobalCache
.
header
.
get
(
"Content-Type"
);
if
(
"application/x-www-form-urlencoded"
.
equals
(
contentType
))
{
JSONObject
jsonObject
=
JSONObject
.
parseObject
(
jsonParams
);
List
<
NameValuePair
>
params
=
new
ArrayList
<>();
//循环json key value 仅能解决正常对象 若Json对象中嵌套数组 则可能需要单独处理
if
(
jsonObject
!=
null
)
{
for
(
Map
.
Entry
<
String
,
Object
>
entry
:
jsonObject
.
entrySet
())
{
params
.
add
(
new
BasicNameValuePair
(
entry
.
getKey
(),
entry
.
getValue
().
toString
()));
}
httpPost
.
setEntity
(
new
UrlEncodedFormEntity
(
params
,
DEFAULT_ENCODING
));
}
}
if
(
"application/json;charset=UTF-8"
.
equals
(
contentType
))
{
httpPost
.
setEntity
(
new
StringEntity
(
jsonParams
,
ContentType
.
create
(
"application/json"
,
DEFAULT_ENCODING
)));
}
}
else
{
log
.
error
(
"请求头为空"
);
}
return
baseRequest
(
httpClient
,
httpPost
);
}
/**
* post请求(1.处理http请求;2.处理https请求,信任所有证书)
*
* @param url
* @param jsonParams 入参是个json字符串
* @return
*/
public
static
ResponeVo
post
(
String
url
,
String
jsonParams
,
Map
<
String
,
String
>
headerMap
)
throws
IOException
,
NoSuchAlgorithmException
,
KeyStoreException
,
KeyManagementException
{
Assert
.
hasText
(
url
,
"url invalid"
);
String
result
;
CloseableHttpClient
httpClient
;
if
(
url
.
startsWith
(
HTTPS
))
{
// 创建一个SSL信任所有证书的httpClient对象
httpClient
=
HttpUtils
.
createSSLInsecureClient
();
}
else
{
httpClient
=
HttpClients
.
createDefault
();
}
CloseableHttpResponse
response
=
null
;
HttpPost
httpPost
=
getHttpPost
(
url
);
if
(
GlobalCache
.
header
!=
null
&&
!
GlobalCache
.
header
.
isEmpty
())
{
for
(
String
key
:
GlobalCache
.
header
.
keySet
())
{
String
value
=
GlobalCache
.
header
.
get
(
key
);
httpPost
.
setHeader
(
key
,
value
);
}
}
else
{
GlobalCache
.
header
.
put
(
"Content-Type"
,
"application/json;charset=UTF-8"
);
}
//加入全局请求令牌权限
if
(!
headerMap
.
isEmpty
())
{
for
(
Map
.
Entry
<
String
,
String
>
entry
:
headerMap
.
entrySet
())
{
httpPost
.
setHeader
(
entry
.
getKey
(),
entry
.
getValue
());
}
}
else
{
httpPost
.
setHeader
(
"Http-Authorization"
,
GlobalCache
.
paramMap
.
get
(
"token"
));
}
if
(
GlobalCache
.
header
.
get
(
"Content-Type"
)
!=
null
)
{
String
contentType
=
GlobalCache
.
header
.
get
(
"Content-Type"
);
if
(
"application/x-www-form-urlencoded"
.
equals
(
contentType
))
{
JSONObject
jsonObject
=
JSONObject
.
parseObject
(
jsonParams
);
List
<
NameValuePair
>
params
=
new
ArrayList
<>();
//循环json key value 仅能解决正常对象 若Json对象中嵌套数组 则可能需要单独处理
if
(
jsonObject
!=
null
)
{
for
(
Map
.
Entry
<
String
,
Object
>
entry
:
jsonObject
.
entrySet
())
{
params
.
add
(
new
BasicNameValuePair
(
entry
.
getKey
(),
entry
.
getValue
().
toString
()));
}
httpPost
.
setEntity
(
new
UrlEncodedFormEntity
(
params
,
DEFAULT_ENCODING
));
}
}
if
(
"application/json;charset=UTF-8"
.
equals
(
contentType
))
{
httpPost
.
setEntity
(
new
StringEntity
(
jsonParams
,
ContentType
.
create
(
"application/json"
,
DEFAULT_ENCODING
)));
}
}
else
{
log
.
error
(
"请求头为空"
);
}
return
baseRequest
(
httpClient
,
httpPost
);
}
/**
* get请求(1.处理http请求;2.处理https请求,信任所有证书)
*
* @param url (只能是http或https请求)
* @return
*/
public
static
ResponeVo
delete
(
String
url
)
throws
IOException
,
NoSuchAlgorithmException
,
KeyStoreException
,
KeyManagementException
{
CloseableHttpClient
httpClient
=
null
;
CloseableHttpResponse
response
=
null
;
if
(
url
.
startsWith
(
HTTPS
))
{
// 创建一个SSL信任所有证书的httpClient对象
httpClient
=
HttpUtils
.
createSSLInsecureClient
();
}
else
{
httpClient
=
HttpClients
.
createDefault
();
}
HttpDelete
httpDelete
=
new
HttpDelete
(
url
);
if
(
GlobalCache
.
header
!=
null
)
{
for
(
String
key
:
GlobalCache
.
header
.
keySet
())
{
String
value
=
GlobalCache
.
header
.
get
(
key
);
httpDelete
.
setHeader
(
key
,
value
);
}
}
httpDelete
.
setHeader
(
"Http-Authorization"
,
GlobalCache
.
paramMap
.
get
(
"token"
));
return
baseRequest
(
httpClient
,
httpDelete
);
}
/**
* get请求(1.处理http请求;2.处理https请求,信任所有证书)
*
* @param url (只能是http或https请求)
* @return
*/
public
static
ResponeVo
put
(
String
url
,
String
jsonParams
)
throws
IOException
,
NoSuchAlgorithmException
,
KeyStoreException
,
KeyManagementException
{
log
.
info
(
"----->调用请求 url:"
+
url
+
" ---->json参数:"
+
jsonParams
);
CloseableHttpClient
httpClient
=
null
;
String
content
;
if
(
url
.
startsWith
(
HTTPS
))
{
// 创建一个SSL信任所有证书的httpClient对象
httpClient
=
HttpUtils
.
createSSLInsecureClient
();
}
else
{
httpClient
=
HttpClients
.
createDefault
();
}
CloseableHttpResponse
response
=
null
;
HttpPut
httpPut
=
new
HttpPut
(
url
);
if
(
GlobalCache
.
header
!=
null
)
{
for
(
String
key
:
GlobalCache
.
header
.
keySet
())
{
String
value
=
GlobalCache
.
header
.
get
(
key
);
httpPut
.
setHeader
(
key
,
value
);
}
}
//加入全局请求令牌权限
httpPut
.
setHeader
(
"Http-Authorization"
,
GlobalCache
.
paramMap
.
get
(
"token"
));
if
(
GlobalCache
.
header
.
get
(
"Content-Type"
)
!=
null
)
{
String
contentType
=
GlobalCache
.
header
.
get
(
"Content-Type"
);
if
(
"application/x-www-form-urlencoded"
.
equals
(
contentType
))
{
JSONObject
jsonObject
=
JSONObject
.
parseObject
(
jsonParams
);
List
<
NameValuePair
>
params
=
new
ArrayList
<>();
//循环json key value 仅能解决正常对象 若Json对象中嵌套数组 则可能需要单独处理
if
(
jsonObject
!=
null
)
{
for
(
Map
.
Entry
<
String
,
Object
>
entry
:
jsonObject
.
entrySet
())
{
params
.
add
(
new
BasicNameValuePair
(
entry
.
getKey
(),
entry
.
getValue
().
toString
()));
}
httpPut
.
setEntity
(
new
UrlEncodedFormEntity
(
params
,
DEFAULT_ENCODING
));
}
}
if
(
"application/json;charset=UTF-8"
.
equals
(
contentType
))
{
httpPut
.
setEntity
(
new
StringEntity
(
jsonParams
,
ContentType
.
create
(
"application/json"
,
DEFAULT_ENCODING
)));
}
}
else
{
log
.
error
(
"请求头为空"
);
}
return
baseRequest
(
httpClient
,
httpPut
);
}
/**
* 采用绕过验证的方式处理https请求
*
* @param url
* @param reqMap
* @param encoding
* @return
*/
public
static
ResponeVo
postSSLUrl
(
String
url
,
Map
<
String
,
Object
>
reqMap
,
String
encoding
)
throws
IOException
,
KeyManagementException
,
NoSuchAlgorithmException
,
KeyStoreException
{
CloseableHttpClient
httpClient
=
null
;
CloseableHttpResponse
response
=
null
;
ResponeVo
responeVo
=
null
;
// 添加参数
List
<
NameValuePair
>
params
=
buildParams
(
reqMap
);
try
{
//采用绕过验证的方式处理https请求
HostnameVerifier
hostnameVerifier
=
(
hostname
,
session
)
->
true
;
SSLContext
sslcontext
=
createIgnoreVerifySSL
();
//设置协议http和https对应的处理socket链接工厂的对象
Registry
<
ConnectionSocketFactory
>
socketFactoryRegistry
=
RegistryBuilder
.<
ConnectionSocketFactory
>
create
()
.
register
(
"http"
,
PlainConnectionSocketFactory
.
INSTANCE
)
.
register
(
"https"
,
new
SSLConnectionSocketFactory
(
sslcontext
,
hostnameVerifier
))
.
build
();
PoolingHttpClientConnectionManager
connManager
=
new
PoolingHttpClientConnectionManager
(
socketFactoryRegistry
);
//创建自定义的httpclient对象
httpClient
=
HttpClients
.
custom
().
setConnectionManager
(
connManager
).
build
();
//创建post方式请求对象
HttpPost
httpPost
=
new
HttpPost
(
url
);
httpPost
.
setEntity
(
new
UrlEncodedFormEntity
(
params
,
encoding
));
//指定报文头Content-type、User-Agent
httpPost
.
setHeader
(
"Content-type"
,
"application/x-www-form-urlencoded"
);
//执行请求操作,并拿到结果(同步阻塞)
responeVo
=
baseRequest
(
httpClient
,
httpPost
);
}
finally
{
ExtendedIOUtils
.
closeQuietly
(
httpClient
);
ExtendedIOUtils
.
closeQuietly
(
response
);
}
return
responeVo
;
}
private
static
List
<
NameValuePair
>
buildParams
(
Map
<
String
,
Object
>
reqMap
)
{
List
<
NameValuePair
>
params
=
new
ArrayList
<>();
if
(
reqMap
!=
null
&&
reqMap
.
keySet
().
size
()
>
0
)
{
Iterator
<
Map
.
Entry
<
String
,
Object
>>
iter
=
reqMap
.
entrySet
().
iterator
();
while
(
iter
.
hasNext
())
{
Map
.
Entry
<
String
,
Object
>
entity
=
iter
.
next
();
params
.
add
(
new
BasicNameValuePair
(
entity
.
getKey
(),
entity
.
getValue
().
toString
()));
}
}
return
params
;
}
/**
* 创建一个SSL信任所有证书的httpClient对象
*
* @return
*/
public
static
CloseableHttpClient
createSSLInsecureClient
()
throws
KeyStoreException
,
NoSuchAlgorithmException
,
KeyManagementException
{
// 默认信任所有证书
HostnameVerifier
hostnameVerifier
=
(
hostname
,
session
)
->
true
;
SSLContext
sslContext
=
SSLContexts
.
custom
().
loadTrustMaterial
(
null
,
(
TrustStrategy
)
(
chain
,
authType
)
->
true
).
build
();
SSLConnectionSocketFactory
sslConnectionSocketFactory
=
new
SSLConnectionSocketFactory
(
sslContext
,
hostnameVerifier
);
return
HttpClients
.
custom
().
setSSLSocketFactory
(
sslConnectionSocketFactory
).
build
();
}
/**
* 绕过验证
*
* @return
* @throws NoSuchAlgorithmException
* @throws KeyManagementException
*/
public
static
SSLContext
createIgnoreVerifySSL
()
throws
NoSuchAlgorithmException
,
KeyManagementException
,
KeyStoreException
{
// 信任所有证书
return
new
SSLContextBuilder
().
loadTrustMaterial
(
null
,
(
TrustStrategy
)
(
arg0
,
arg1
)
->
true
).
build
();
}
private
static
String
inputStreamToString
(
InputStream
is
)
{
String
line
=
""
;
StringBuilder
total
=
new
StringBuilder
();
// Wrap a BufferedReader around the InputStream
BufferedReader
rd
=
new
BufferedReader
(
new
InputStreamReader
(
is
));
try
{
// Read response until the end
while
((
line
=
rd
.
readLine
())
!=
null
)
{
total
.
append
(
line
);
}
}
catch
(
IOException
e
)
{
log
.
error
(
e
.
getLocalizedMessage
(),
e
);
}
// Return full string
return
total
.
toString
();
}
public
static
ResponeVo
baseRequest
(
CloseableHttpClient
httpClient
,
HttpUriRequest
request
)
{
ResponeVo
responeVo
=
new
ResponeVo
();
CloseableHttpResponse
response
=
null
;
try
{
String
content
;
response
=
httpClient
.
execute
(
request
);
content
=
inputStreamToString
(
response
.
getEntity
().
getContent
());
responeVo
.
setCode
(
response
.
getStatusLine
().
getStatusCode
());
responeVo
.
setContent
(
content
);
responeVo
.
setResponse
(
response
);
log
.
info
(
"http调用完成,返回数据"
+
content
);
}
catch
(
Exception
e
)
{
log
.
error
(
" http调用失败:"
+
e
);
}
ExtendedIOUtils
.
closeQuietly
(
httpClient
);
ExtendedIOUtils
.
closeQuietly
(
response
);
return
responeVo
;
}
}
amos-boot-module/amos-boot-module-biz/amos-boot-module-equip-biz/src/main/java/com/yeejoin/equipmanage/controller/PoolStatisticController.java
View file @
49c43cd2
...
...
@@ -119,7 +119,7 @@ public class PoolStatisticController {
@TycloudOperation
(
ApiLevel
=
UserType
.
AGENCY
,
needAuth
=
false
)
@RequestMapping
(
value
=
"/panel/station/statistic"
,
method
=
RequestMethod
.
GET
)
@ApiOperation
(
httpMethod
=
"GET"
,
value
=
"获取水池统计信息"
,
notes
=
"获取水池统计信息"
)
public
ResponseModel
getStationWaterPanelInfo
(
@RequestParam
(
required
=
false
)
String
bizOrgCode
)
{
public
ResponseModel
<
List
<
Map
<
String
,
Object
>>>
getStationWaterPanelInfo
(
@RequestParam
(
required
=
false
)
String
bizOrgCode
)
{
List
<
Map
<
String
,
Object
>>
infoList
=
fireFightingSystemMapper
.
getWaterInfoBySuper
(
bizOrgCode
);
List
<
Map
<
String
,
Object
>>
normalList
=
new
ArrayList
<>();
List
<
Map
<
String
,
Object
>>
abNormalList
=
new
ArrayList
<>();
...
...
@@ -140,10 +140,14 @@ public class PoolStatisticController {
BigDecimal
bigDecimal
=
new
BigDecimal
(
String
.
valueOf
(
m
.
get
(
"volume"
))).
multiply
(
new
BigDecimal
(
String
.
valueOf
(
transResult
.
get
(
"abs"
)))).
divide
(
divide
,
0
,
RoundingMode
.
HALF_UP
);
m
.
put
(
"volume"
,
bigDecimal
+
"m³"
);
m
.
put
(
"levelAbs"
,
transResult
.
get
(
"abs"
)
+
"%"
);
// 预警使用以下字段
m
.
put
(
"volumeBigDecimal"
,
bigDecimal
);
}
else
if
(
String
.
valueOf
(
transResult
.
get
(
"abs"
)).
equals
(
"100"
)
&&
String
.
valueOf
(
transResult
.
get
(
"status"
)).
equals
(
"1"
))
{
BigDecimal
bigDecimal
=
new
BigDecimal
(
String
.
valueOf
(
m
.
get
(
"volume"
)));
m
.
put
(
"volume"
,
bigDecimal
+
"m³"
);
m
.
put
(
"levelAbs"
,
transResult
.
get
(
"abs"
)
+
"%"
);
// 预警使用以下字段
m
.
put
(
"volumeBigDecimal"
,
bigDecimal
);
}
else
{
m
.
put
(
"levelAbs"
,
transResult
.
get
(
"abs"
));
}
...
...
amos-boot-module/amos-boot-module-biz/amos-boot-module-equip-biz/src/main/java/com/yeejoin/equipmanage/controller/SupervisionConfigureController.java
View file @
49c43cd2
...
...
@@ -212,7 +212,7 @@ public class SupervisionConfigureController extends AbstractBaseController {
levelAbsLiter
=
volume
.
multiply
(
new
BigDecimal
(
1000
));
}
else
{
BigDecimal
abs
=
new
BigDecimal
(
String
.
valueOf
(
transResult
.
get
(
"abs"
)));
levelAbsLiter
=
volume
.
multiply
(
abs
.
divide
(
new
BigDecimal
(
100
),
2
,
RoundingMode
.
HALF_UP
));
levelAbsLiter
=
volume
.
multiply
(
new
BigDecimal
(
1000
)).
multiply
(
abs
.
divide
(
new
BigDecimal
(
100
),
2
,
RoundingMode
.
HALF_UP
));
}
float
outputFlowRate
=
Float
.
parseFloat
(
String
.
valueOf
(
m
.
get
(
"outputFlowRate"
)));
if
(
levelAbsLiter
.
compareTo
(
new
BigDecimal
(
0
))
!=
0
&&
outputFlowRate
!=
0
)
{
...
...
amos-boot-module/amos-boot-module-biz/amos-boot-module-equip-biz/src/main/java/com/yeejoin/equipmanage/controller/WlCarMileageController.java
View file @
49c43cd2
...
...
@@ -231,17 +231,7 @@ public class WlCarMileageController {
}
/**
* 获取轨迹
*
* @return
*/
@RequestMapping
(
value
=
"/travel"
,
method
=
RequestMethod
.
GET
)
@ApiOperation
(
httpMethod
=
"GET"
,
value
=
"获取轨迹"
,
notes
=
"获取轨迹"
)
@TycloudOperation
(
ApiLevel
=
UserType
.
AGENCY
,
needAuth
=
false
)
public
List
<
Coordinate
>
travel
(
long
id
)
{
return
iWlCarMileageService
.
getCoordinateList
(
id
);
}
/**
* 获取日历
...
...
amos-boot-module/amos-boot-module-biz/amos-boot-module-equip-biz/src/main/java/com/yeejoin/equipmanage/fegin/IotFeign.java
View file @
49c43cd2
...
...
@@ -86,4 +86,12 @@ public interface IotFeign {
ResponseModel
<
Map
<
String
,
Object
>>
queryIotDataNum
(
@RequestParam
(
"timeStart"
)
String
timeStart
,
@RequestParam
(
"timeEnd"
)
String
timeEnd
);
@RequestMapping
(
value
=
"v1/livedata/queryIotDataNumByIndex"
,
method
=
RequestMethod
.
GET
,
consumes
=
"application/json"
)
ResponseModel
<
Map
<
String
,
Integer
>>
queryIotDataNumByIndex
(
@RequestParam
(
value
=
"timeStart"
)
String
timeStart
,
@RequestParam
(
value
=
"timeEnd"
)
String
timeEnd
,
@RequestParam
(
value
=
"productKey"
)
String
productKey
,
@RequestParam
(
value
=
"deviceName"
)
String
deviceName
,
@RequestParam
(
value
=
"indexKeys"
)
String
indexKeys
,
@RequestParam
(
value
=
"value"
)
String
value
);
}
amos-boot-module/amos-boot-module-biz/amos-boot-module-equip-biz/src/main/java/com/yeejoin/equipmanage/service/IWlCarMileageService.java
View file @
49c43cd2
...
...
@@ -21,7 +21,6 @@ public interface IWlCarMileageService extends IService<WlCarMileage> {
Double
totalMileage
(
String
iotCode
);
List
<
Coordinate
>
getCoordinateList
(
long
id
);
Map
<
String
,
Boolean
>
getCalender
(
long
id
,
Date
date
);
...
...
amos-boot-module/amos-boot-module-biz/amos-boot-module-equip-biz/src/main/java/com/yeejoin/equipmanage/service/impl/EquipmentSpecificSerivceImpl.java
View file @
49c43cd2
...
...
@@ -1971,8 +1971,6 @@ public class EquipmentSpecificSerivceImpl extends ServiceImpl<EquipmentSpecificM
Date
now
=
new
Date
();
String
scrapTime
=
new
SimpleDateFormat
(
DateUtils
.
DATE_TIME_PATTERN
).
format
(
calendar
.
getTime
());
int
day
=
DateUtils
.
dateBetween
(
now
,
calendar
.
getTime
());
log
.
info
(
"报废时间:{}"
,
day
);
log
.
info
(
"报废时间ID:{}"
,
e
.
get
(
"id"
).
toString
());
if
(
day
<
Integer
.
parseInt
(
equipmentScrapDay
)
&&
day
>
-
1
)
{
syncSystemctlMsg
(
e
,
scrapTime
,
day
);
}
else
if
(
day
==
-
1
)
{
...
...
amos-boot-module/amos-boot-module-biz/amos-boot-module-equip-biz/src/main/java/com/yeejoin/equipmanage/service/impl/FireFightingSystemServiceImpl.java
View file @
49c43cd2
...
...
@@ -2263,8 +2263,6 @@ public class FireFightingSystemServiceImpl extends ServiceImpl<FireFightingSyste
// 日告警设备数
listItem
.
put
(
"alarmEquipNum"
,
ObjectUtils
.
isEmpty
(
weekItem
.
get
(
"alarmEquipNum"
))
?
""
:
String
.
valueOf
(
weekItem
.
get
(
"alarmEquipNum"
)));
// 日告警条数
log
.
info
(
"==========sbco={}"
,
weekItem
.
get
(
"type_code"
).
toString
());
log
.
info
(
"==========sbCC={}"
,
weekItem
.
get
(
"code"
).
toString
());
if
(!
ObjectUtils
.
isEmpty
(
weekItem
.
get
(
"type_code"
))
&&
!
ObjectUtils
.
isEmpty
(
weekItem
.
get
(
"code"
)))
{
Integer
integer
=
fireFightingSystemMapper
.
selectAlarms
(
valueOf
(
system
.
get
(
"id"
)),
valueOf
(
weekItem
.
get
(
"type_code"
)),
valueOf
(
weekItem
.
get
(
"code"
)),
startDate
,
endDate
,
new
ArrayList
<>());
listItem
.
put
(
"trueNum"
,
String
.
valueOf
(
integer
));
...
...
amos-boot-module/amos-boot-module-biz/amos-boot-module-equip-biz/src/main/java/com/yeejoin/equipmanage/service/impl/MqttReceiveServiceImpl.java
View file @
49c43cd2
package
com
.
yeejoin
.
equipmanage
.
service
.
impl
;
import
cn.hutool.core.date.DatePattern
;
import
cn.hutool.core.date.DateUtil
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONArray
;
...
...
@@ -28,6 +29,7 @@ import com.yeejoin.equipmanage.common.utils.UUIDUtils;
import
com.yeejoin.equipmanage.common.vo.*
;
import
com.yeejoin.equipmanage.common.vo.BizMessage
;
import
com.yeejoin.equipmanage.common.vo.CustomizeItems
;
import
com.yeejoin.equipmanage.controller.PoolStatisticController
;
import
com.yeejoin.equipmanage.dto.TabContent
;
import
com.yeejoin.equipmanage.fegin.IotFeign
;
import
com.yeejoin.equipmanage.fegin.SystemctlFeign
;
...
...
@@ -104,6 +106,11 @@ public class MqttReceiveServiceImpl implements MqttReceiveService {
* 水箱液位
*/
private
final
static
String
CAFS_WaterTank_WaterTankLevel
=
"CAFS_WaterTank_WaterTankLevel"
;
private
final
static
String
FHS_PressurePump_Start
=
"FHS_PressurePump_Start"
;
private
final
static
String
FHS_PressurePump_Stop
=
"FHS_PressurePump_Stop"
;
private
static
final
String
PUMP_JOB_GROUP_NAME
=
"EQUIP_PUMP_JOB_GROUP_NAME"
;
private
static
final
String
PUMP_TRIGGER_NAME
=
"EQUIP_PUMP_TRIGGER_NAME"
;
private
static
final
String
PUMP_TRIGGER_GROUP_NAME
=
"EQUIP_PUMP_TRIGGER_GROUP_NAME"
;
...
...
@@ -180,6 +187,9 @@ public class MqttReceiveServiceImpl implements MqttReceiveService {
@Autowired
private
ManufacturerInfoMapper
manufacturerInfoMapper
;
@Autowired
private
PoolStatisticController
poolStatisticController
;
// @Autowired
// private AmosRequestContext amosAuth;
@Value
(
"${equipManage.name}"
)
...
...
@@ -389,7 +399,13 @@ public class MqttReceiveServiceImpl implements MqttReceiveService {
}
//给 iot服务 推送消息 插数据到 influxdb
if
(
isSendIot
)
{
mqttSendGateway
.
sendToMqtt
(
"influxdb/"
+
topic
.
substring
(
0
,
endIndex
),
message
);
JSONObject
messageObj
=
JSON
.
parseObject
(
message
);
if
(!
messageObj
.
containsKey
(
"traceId"
))
{
String
traceId
=
System
.
currentTimeMillis
()
+
""
;
messageObj
.
put
(
"traceId"
,
traceId
);
}
String
messageTraceId
=
JSON
.
toJSONString
(
messageObj
);
mqttSendGateway
.
sendToMqtt
(
"influxdb/"
+
topic
.
substring
(
0
,
endIndex
),
messageTraceId
);
}
EquipmentSpecificVo
vo
=
eqIotCodeList
.
get
(
0
);
topicEntity
.
setType
(
vo
.
getType
());
...
...
@@ -1119,6 +1135,13 @@ public class MqttReceiveServiceImpl implements MqttReceiveService {
iotDataVO
.
getKey
().
equalsIgnoreCase
(
FHS_WirelessliquidDetector_WaterLevel
)
||
iotDataVO
.
getKey
().
equalsIgnoreCase
(
FHS_LevelDetector_WaterLevel
))
{
alarmFlag
=
doWaterPoolLevel
(
iotDataVO
,
equipmentSpecificIndex
,
messageBodyMap
);
// 处理每站消防储水量不少于4000m³ 预警问题
doWaterStationWarning
(
equipmentSpecificIndex
.
getBizOrgCode
(),
equipmentSpecificIndex
.
getBizOrgName
());
}
//稳压泵启停次数大于15次触发预警
if
(
iotDataVO
.
getKey
().
equalsIgnoreCase
(
FHS_PressurePump_Start
)
||
iotDataVO
.
getKey
().
equalsIgnoreCase
(
FHS_PressurePump_Stop
))
{
doPressurePumInfo
(
topicEntity
,
equipmentSpecificIndex
);
}
// 遥测数据生成告警事件、日志处理
if
(
iotDataVO
.
getKey
().
equalsIgnoreCase
(
CAFS_FoamTank_FoamTankLevel
)
||
...
...
@@ -1360,7 +1383,7 @@ public class MqttReceiveServiceImpl implements MqttReceiveService {
if
(
iotDataVO
.
getKey
().
equalsIgnoreCase
(
CAFS_FoamTank_FoamTankLevel
)
||
iotDataVO
.
getKey
().
equalsIgnoreCase
(
CAFS_WaterTank_WaterTankLevel
))
{
map
=
fireFightingSystemMapper
.
getFoamTankLevel
(
equipmentSpecificIndex
.
getEquipmentSpecificId
());
indexKey
=
iotDataVO
.
getKey
().
equalsIgnoreCase
(
CAFS_FoamTank_FoamTankLevel
)
?
"CAFS_FOAM_TANK"
:
"
WATER_TANK_LEVEL
"
;
indexKey
=
iotDataVO
.
getKey
().
equalsIgnoreCase
(
CAFS_FoamTank_FoamTankLevel
)
?
"CAFS_FOAM_TANK"
:
"
CAFS_WaterTank_WaterTankLevel
"
;
}
else
{
map
=
fireFightingSystemMapper
.
getPipeNetwork
(
equipmentSpecificIndex
.
getEquipmentSpecificId
());
indexKey
=
"PIPE_PRESSURE"
;
...
...
@@ -1440,6 +1463,117 @@ public class MqttReceiveServiceImpl implements MqttReceiveService {
return
alarmFlag
;
}
private
void
doWaterStationWarning
(
String
bizOrgCode
,
String
bizOrgName
)
{
List
<
Map
<
String
,
Object
>>
result
=
poolStatisticController
.
getStationWaterPanelInfo
(
bizOrgCode
).
getResult
();
String
indexValue
=
result
.
stream
()
.
map
(
map
->
(
BigDecimal
)
map
.
get
(
"volumeBigDecimal"
))
.
reduce
(
BigDecimal
.
ZERO
,
BigDecimal:
:
add
).
toString
();
doWaterStationInfo
(
bizOrgCode
,
bizOrgName
,
indexValue
);
}
private
void
doWaterStationInfo
(
String
bizOrgCode
,
String
bizOrgName
,
String
indexValue
)
{
String
indexKey
=
"WATER_CAPACITY"
;
String
warningObjectCode
=
bizOrgCode
+
"@"
+
indexKey
;
HashMap
<
String
,
String
>
extra
=
new
HashMap
<>();
extra
.
put
(
"useSource"
,
"center"
);
extra
.
put
(
"codingSystem"
,
"center"
);
extra
.
put
(
"codingType"
,
"station"
);
extra
.
put
(
"problemReception"
,
"station"
);
extra
.
put
(
"bussId"
,
warningObjectCode
);
extra
.
put
(
"clearUniqueCode"
,
"station-WATER_CAPACITY"
);
TableContentVo
tableContentVo
=
new
TableContentVo
(
"分析结果"
,
"text"
,
"消防水池+工业水池储水量<4000m³"
,
"1"
);
TableContentVo
tableContentVo1
=
new
TableContentVo
(
"管理要求"
,
"text"
,
"每站消防储水量不少于4000m³"
,
"2"
);
TableContentVo
tableContentVo2
=
new
TableContentVo
(
"管理依据"
,
"text"
,
"换流站消防系统运行规程"
,
"3"
);
List
<
TableContentVo
>
tableContentVos
=
Arrays
.
asList
(
tableContentVo
,
tableContentVo1
,
tableContentVo2
);
// 触发预警业务
BizMessage
bizMessage
=
new
BizMessage
();
bizMessage
.
setIndexKey
(
indexKey
);
bizMessage
.
setIndexValue
(
indexValue
);
RiskBizInfoVo
riskBizInfoVo
=
new
RiskBizInfoVo
();
riskBizInfoVo
.
setWarningObjectName
(
"消防储水量"
);
riskBizInfoVo
.
setWarningObjectCode
(
warningObjectCode
);
riskBizInfoVo
.
setSourceAttribution
(
bizOrgCode
);
riskBizInfoVo
.
setSourceAttributionDesc
(
bizOrgName
);
List
<
RiskDynamicDetailsVo
>
detailsVos
=
new
ArrayList
<>();
RiskDynamicDetailsVo
dynamicDetailsVo
=
new
RiskDynamicDetailsVo
();
dynamicDetailsVo
.
setTabName
(
"预警详情"
);
detailsVos
.
add
(
dynamicDetailsVo
);
riskBizInfoVo
.
setDynamicDetails
(
detailsVos
);
CustomizeItems
customizeItems
=
new
CustomizeItems
();
customizeItems
.
setWarningContent
(
"消防水池+工业水池储水量<4000m³"
);
riskBizInfoVo
.
setCustomizeItems
(
customizeItems
);
riskBizInfoVo
.
setExtra
(
extra
);
riskBizInfoVo
.
setType
(
"waterCapacity"
);
riskBizInfoVo
.
getDynamicDetails
().
get
(
0
).
setTabContent
(
tableContentVos
);
bizMessage
.
setBizInfo
(
riskBizInfoVo
);
bizMessage
.
setTraceId
(
warningObjectCode
);
try
{
emqKeeper
.
getMqttClient
().
publish
(
"fireIot/data/analysis"
,
JSON
.
toJSONString
(
bizMessage
).
getBytes
(
StandardCharsets
.
UTF_8
),
2
,
false
);
}
catch
(
MqttException
e
)
{
e
.
printStackTrace
();
}
}
private
void
doPressurePumInfo
(
TopicEntityVo
topicEntity
,
EquipmentSpecificIndex
equipmentSpecificIndex
)
{
// 查询iot该稳压泵的启停次数 一个小时内
String
startDate
=
DateUtil
.
format
(
new
Date
(),
DatePattern
.
NORM_DATETIME_PATTERN
);
String
endDate
=
DateUtil
.
format
(
DateUtil
.
offsetHour
(
new
Date
(),
-
1
),
DatePattern
.
NORM_DATETIME_PATTERN
);
String
prefix
=
topicEntity
.
getIotCode
().
substring
(
0
,
8
);
String
suffix
=
topicEntity
.
getIotCode
().
substring
(
8
);
ResponseModel
<
Map
<
String
,
Integer
>>
mapResponseModel
=
iotFeign
.
queryIotDataNumByIndex
(
startDate
,
endDate
,
prefix
,
suffix
,
FHS_PressurePump_Start
+
","
+
FHS_PressurePump_Stop
,
"true"
);
if
(
200
==
mapResponseModel
.
getStatus
())
{
Map
<
String
,
Integer
>
result
=
mapResponseModel
.
getResult
();
Integer
totalNum
=
result
.
get
(
"num"
);
HashMap
<
String
,
String
>
extra
=
new
HashMap
<>();
extra
.
put
(
"useSource"
,
"center"
);
extra
.
put
(
"codingSystem"
,
"center"
);
extra
.
put
(
"codingType"
,
"equipment"
);
extra
.
put
(
"problemReception"
,
"station"
);
extra
.
put
(
"bussId"
,
String
.
valueOf
(
equipmentSpecificIndex
.
getEquipmentSpecificId
()));
extra
.
put
(
"clearUniqueCode"
,
"equip-pressure"
);
TableContentVo
tableContentVo
=
new
TableContentVo
(
"报警类型"
,
"text"
,
"稳压泵启停频次过高"
,
"1"
);
TableContentVo
tableContentVo1
=
new
TableContentVo
(
"报警部位"
,
"text"
,
equipmentSpecificIndex
.
getLocation
(),
"2"
);
TableContentVo
tableContentVo2
=
new
TableContentVo
(
"报警时间"
,
"text"
,
DateUtil
.
now
(),
"3"
);
TableContentVo
tableContentVo3
=
new
TableContentVo
(
"报警对象"
,
"text"
,
equipmentSpecificIndex
.
getEquipmentSpecificName
(),
"4"
);
List
<
TableContentVo
>
tableContentVos
=
Arrays
.
asList
(
tableContentVo
,
tableContentVo1
,
tableContentVo2
,
tableContentVo3
);
handlePressureWarning
(
totalNum
.
toString
(),
equipmentSpecificIndex
,
String
.
valueOf
(
equipmentSpecificIndex
.
getEquipmentSpecificId
()),
"fireIot/data/analysis"
,
"START_NUM"
,
extra
,
"equip"
,
tableContentVos
);
}
}
private
void
handlePressureWarning
(
String
indexValue
,
EquipmentSpecificIndex
equipmentSpecificIndex
,
String
businessId
,
String
topic
,
String
indexKey
,
Object
extra
,
String
source
,
List
<
TableContentVo
>
tableContentVos
)
{
// 触发预警业务
BizMessage
bizMessage
=
new
BizMessage
();
bizMessage
.
setIndexKey
(
indexKey
);
bizMessage
.
setIndexValue
(
indexValue
);
RiskBizInfoVo
riskBizInfoVo
=
fetchData
(
equipmentSpecificIndex
,
extra
,
source
);
riskBizInfoVo
.
setWarningObjectCode
(
businessId
);
riskBizInfoVo
.
getDynamicDetails
().
get
(
0
).
setTabContent
(
tableContentVos
);
bizMessage
.
setBizInfo
(
riskBizInfoVo
);
bizMessage
.
setTraceId
(
businessId
);
try
{
emqKeeper
.
getMqttClient
().
publish
(
topic
,
JSON
.
toJSONString
(
bizMessage
).
getBytes
(
StandardCharsets
.
UTF_8
),
2
,
false
);
}
catch
(
MqttException
e
)
{
e
.
printStackTrace
();
}
}
/**
* 消防水池、工业水池和消防水箱 消息发送
*
...
...
@@ -1487,7 +1621,8 @@ public class MqttReceiveServiceImpl implements MqttReceiveService {
TableContentVo
tableContentVo2
=
new
TableContentVo
(
"报警时间"
,
"text"
,
DateUtil
.
now
(),
"3"
);
TableContentVo
tableContentVo3
=
new
TableContentVo
(
"报警对象"
,
"text"
,
map
.
getOrDefault
(
"name"
,
""
).
toString
(),
"4"
);
List
<
TableContentVo
>
tableContentVos
=
Arrays
.
asList
(
tableContentVo
,
tableContentVo1
,
tableContentVo2
,
tableContentVo3
);
equipmentSpecificIndex
.
setEquipmentSpecificName
(
map
.
get
(
"name"
).
toString
());
equipmentSpecificIndex
.
setEquipmentSpecificCode
(
map
.
get
(
"id"
).
toString
());
//预警业务 消防水池和消防水箱
handleWarning
(
minValue
,
maxValue
,
...
...
@@ -1495,7 +1630,7 @@ public class MqttReceiveServiceImpl implements MqttReceiveService {
equipmentSpecificIndex
,
map
.
get
(
"id"
).
toString
(),
"fireIot/data/analysis"
,
"
WATER_POOL
_LEVEL"
,
"
pool"
.
equals
(
map
.
get
(
"resourceType"
).
toString
())
?
"WATER_POOL_LEVEL"
:
"WATER_TANK
_LEVEL"
,
extra
,
"waterLevelOver"
,
tableContentVos
);
...
...
amos-boot-module/amos-boot-module-biz/amos-boot-module-equip-biz/src/main/java/com/yeejoin/equipmanage/service/impl/WlCarMileageServiceImpl.java
View file @
49c43cd2
...
...
@@ -13,7 +13,6 @@ import com.yeejoin.equipmanage.common.entity.CarSpeedWarningRecord;
import
com.yeejoin.equipmanage.common.entity.WlCarMileage
;
import
com.yeejoin.equipmanage.common.utils.CoordinateUtil
;
import
com.yeejoin.equipmanage.common.utils.DateUtils
;
import
com.yeejoin.equipmanage.common.utils.HttpUtil
;
import
com.yeejoin.equipmanage.common.utils.RedisUtil
;
import
com.yeejoin.equipmanage.controller.Coordinate
;
import
com.yeejoin.equipmanage.fegin.IotFeign
;
...
...
@@ -69,7 +68,6 @@ import java.util.stream.Collectors;
@EnableAsync
public
class
WlCarMileageServiceImpl
extends
ServiceImpl
<
WlCarMileageMapper
,
WlCarMileage
>
implements
IWlCarMileageService
{
private
static
final
Logger
log
=
LoggerFactory
.
getLogger
(
HttpUtil
.
class
);
private
final
String
GUIDE_KEY
=
"8d2ab194d72e88d3636e9d721814333a"
;
private
final
String
GUIDE_URL
=
"https://restapi.amap.com/v4/grasproad/driving?"
;
private
final
String
GUIDE_ADDRESS_URL
=
"https://restapi.amap.com/v3/geocode/regeo?"
;
...
...
@@ -132,137 +130,6 @@ public class WlCarMileageServiceImpl extends ServiceImpl<WlCarMileageMapper, WlC
return
this
.
baseMapper
.
totalMileage
(
iotCode
);
}
@Override
public
List
<
Coordinate
>
getCoordinateList
(
long
id
)
{
double
speed
=
0
;
WlCarMileage
wlCarMileage
=
this
.
getById
(
id
);
String
iotCode
=
wlCarMileage
.
getIotCode
();
String
measurement
=
iotCode
.
substring
(
0
,
8
);
String
deviceName
=
iotCode
.
replace
(
measurement
,
""
);
// 由于iot存在毫秒故结束时间要+1秒 iot+1秒有bug还是查不到 +2秒
ResponseModel
<
List
<
Object
>>
result
=
iotFeign
.
getLiveData
(
measurement
,
deviceName
,
wlCarMileage
.
getStartTime
(),
new
Date
(
wlCarMileage
.
getEndTime
().
getTime
()));
List
<
Object
>
list
=
result
.
getResult
();
List
<
Coordinate
>
coordinateList
=
new
ArrayList
<
Coordinate
>();
if
(
list
!=
null
)
{
DateFormat
format1
=
new
SimpleDateFormat
(
"yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"
);
DateFormat
format2
=
new
SimpleDateFormat
(
"yyyy-MM-dd'T'HH:mm:ss'Z'"
);
for
(
Object
object
:
list
)
{
JSONObject
jsonObject
=
JSONObject
.
parseObject
(
JSONObject
.
toJSONString
(
object
));
if
(
jsonObject
.
get
(
"FireCar_Longitude"
)
!=
null
&&
jsonObject
.
get
(
"FireCar_Latitude"
)
!=
null
)
{
Coordinate
coordinate
=
new
Coordinate
();
List
<
Double
>
lnglat
=
new
ArrayList
<
Double
>();
lnglat
.
add
(
jsonObject
.
getDoubleValue
(
"FireCar_Longitude"
));
lnglat
.
add
(
jsonObject
.
getDoubleValue
(
"FireCar_Latitude"
));
coordinate
.
setLnglat
(
lnglat
);
coordinate
.
setSpeed
(
jsonObject
.
getDoubleValue
(
"fireCar_Speed"
));
speed
=
speed
+
jsonObject
.
getDoubleValue
(
"fireCar_Speed"
);
String
time
=
jsonObject
.
getString
(
"time"
);
if
(
time
.
length
()
>
20
)
{
try
{
coordinate
.
setTime
(
format1
.
parse
(
jsonObject
.
getString
(
"time"
)).
getTime
());
}
catch
(
ParseException
e
)
{
e
.
printStackTrace
();
}
}
else
{
try
{
coordinate
.
setTime
(
format2
.
parse
(
jsonObject
.
getString
(
"time"
)).
getTime
());
}
catch
(
ParseException
e
)
{
e
.
printStackTrace
();
}
}
double
direction
=
jsonObject
.
getDoubleValue
(
"direction"
);
if
(!
ObjectUtils
.
isEmpty
(
direction
))
{
coordinate
.
setDirection
(
jsonObject
.
getDoubleValue
(
"direction"
));
}
else
{
coordinate
.
setDirection
(
0
);
}
coordinateList
.
add
(
coordinate
);
}
}
}
// 倒序坐标变为正序
Collections
.
reverse
(
coordinateList
);
// 坐标轨迹纠偏
double
avgSpeed
=
speed
/
coordinateList
.
size
();
double
count
=
Double
.
valueOf
(
coordinateList
.
size
())
/
500
;
int
ceil
=
(
int
)
Math
.
ceil
(
count
);
ArrayList
<
Coordinate
>
resultList
=
new
ArrayList
<>();
for
(
int
i
=
1
;
i
<=
ceil
;
i
++)
{
if
(
i
==
ceil
)
{
List
<
Coordinate
>
coordinates
=
coordinateList
.
subList
(
500
*
(
i
-
1
),
coordinateList
.
size
());
List
<
Coordinate
>
check
=
check
(
coordinates
,
avgSpeed
);
resultList
.
addAll
(
check
);
}
else
{
List
<
Coordinate
>
coordinates
=
coordinateList
.
subList
(
500
*
(
i
-
1
),
500
+
(
i
-
1
)
*
500
);
List
<
Coordinate
>
check
=
check
(
coordinates
,
avgSpeed
);
resultList
.
addAll
(
check
);
}
}
return
resultList
;
}
private
List
<
Coordinate
>
check
(
List
<
Coordinate
>
list
,
double
avgSpeed
)
{
ArrayList
<
Coordinate
>
coordinates
=
new
ArrayList
<>();
JSONArray
objects
=
new
JSONArray
();
int
count
=
0
;
for
(
Coordinate
coordinate
:
list
)
{
JSONObject
jsonObject
=
new
JSONObject
();
// 经度
jsonObject
.
put
(
"x"
,
coordinate
.
getLnglat
().
get
(
0
));
// 纬度
jsonObject
.
put
(
"y"
,
coordinate
.
getLnglat
().
get
(
1
));
// 角度
jsonObject
.
put
(
"ag"
,
coordinate
.
getDirection
());
// 速度
jsonObject
.
put
(
"sp"
,
coordinate
.
getSpeed
()
>
0
?
coordinate
.
getSpeed
()
:
avgSpeed
);
// 时间
if
(
count
==
0
)
{
jsonObject
.
put
(
"tm"
,
coordinate
.
getTime
()
/
1000
);
}
else
{
jsonObject
.
put
(
"tm"
,
3
*
count
);
}
count
+=
1
;
objects
.
add
(
jsonObject
);
}
String
s
=
objects
.
toJSONString
();
StringBuilder
api
=
new
StringBuilder
(
GUIDE_URL
);
api
.
append
(
"key="
).
append
(
GUIDE_KEY
);
String
result
=
null
;
try
{
result
=
HttpUtil
.
post
(
api
.
toString
(),
s
);
}
catch
(
IOException
|
NoSuchAlgorithmException
|
KeyStoreException
|
KeyManagementException
e
)
{
e
.
printStackTrace
();
}
if
(
result
!=
null
)
{
Map
<
String
,
Object
>
jsonObject
=
(
Map
<
String
,
Object
>)
JSONObject
.
parseObject
(
result
);
//判断是否坐标不满足高德地图纠偏需求
if
(
jsonObject
.
containsKey
(
"errcode"
)
&&
jsonObject
.
get
(
"errcode"
).
toString
().
equals
(
"30001"
))
{
return
list
;
}
if
(
jsonObject
.
containsKey
(
"data"
))
{
JSONObject
data3
=
JSONObject
.
parseObject
(
jsonObject
.
get
(
"data"
).
toString
());
JSONArray
points1
=
JSONArray
.
parseArray
(
data3
.
get
(
"points"
).
toString
());
// for (int i = 0; i < points1.size(); i++) {
// JSONObject jsonObject1 = JSONObject.parseObject(points1.get(i).toString());
// List<Double> doubles = new ArrayList<>();
// Coordinate coordinate = new Coordinate();
// doubles.add(Double.valueOf(jsonObject1.get("x").toString()));
// doubles.add(Double.valueOf(jsonObject1.get("y").toString()));
// coordinate.setLnglat(doubles);
// Double speeed = getSpeedByOriginalData(objects, Double.valueOf(jsonObject1.get("x").toString()), Double.valueOf(jsonObject1.get("y").toString()));
// coordinate.setSpeed(speeed);
// coordinates.add(coordinate);
// }
coordinates
=
giveSpeedToCoordinate
(
objects
,
points1
);
}
}
return
coordinates
;
}
@Override
public
Map
<
String
,
Boolean
>
getCalender
(
long
id
,
Date
date
)
{
...
...
@@ -314,16 +181,12 @@ public class WlCarMileageServiceImpl extends ServiceImpl<WlCarMileageMapper, WlC
@Scheduled
(
cron
=
"${mileage.segmentation.cron}"
)
@Async
public
void
mileageSegmentation
()
{
log
.
info
(
"轨迹切分定时任务开始执行时间.............{}"
,
LocalDateTime
.
now
());
Calendar
cal
=
Calendar
.
getInstance
();
cal
.
setTime
(
new
Date
());
cal
.
add
(
Calendar
.
DATE
,
-
1
);
String
nowDate
=
new
SimpleDateFormat
(
"yyyy-MM-dd"
).
format
(
cal
.
getTime
());
log
.
info
(
"轨迹切分定时任务数据过滤时间.............{}"
,
nowDate
);
List
<
WlCarMileage
>
list
=
this
.
baseMapper
.
list
(
nowDate
);
log
.
info
(
"需要切分数据, {}"
,
list
);
log
.
info
(
"销毁所有坐标信息成功"
);
log
.
info
(
"------------------跨天轨迹切分任开始切分里程-------------------------------"
);
list
.
forEach
(
item
->
{
redisTemplate
.
delete
(
item
.
getIotCode
());
Calendar
calendar
=
Calendar
.
getInstance
();
...
...
@@ -393,10 +256,8 @@ public class WlCarMileageServiceImpl extends ServiceImpl<WlCarMileageMapper, WlC
item
.
setTravel
(
new
BigDecimal
(
travel
/
1000
).
setScale
(
1
,
BigDecimal
.
ROUND_HALF_UP
).
doubleValue
());
item
.
setTakeTime
(
takeTime
);
this
.
getBaseMapper
().
updateById
(
item
);
log
.
info
(
"-----------跨天轨迹切分任更新车辆坐标成功:::"
+
JSONObject
.
toJSONString
(
item
)
+
"-----------------"
);
}
});
log
.
info
(
"-------------------跨天轨迹切分任务执行完成.............."
);
//删除过期的告警数据
Date
endTime
=
DateUtil
.
offsetDay
(
new
Date
(),-
15
);
String
endTimeStr
=
DateUtil
.
format
(
endTime
,
"yyyy-MM-dd HH:mm:00"
);
...
...
@@ -474,12 +335,10 @@ public class WlCarMileageServiceImpl extends ServiceImpl<WlCarMileageMapper, WlC
}
else
{
this
.
getBaseMapper
().
deleteById
(
item
.
getId
());
}
log
.
info
(
"-----------正常结束轨迹更新车辆坐标成功:::"
+
JSONObject
.
toJSONString
(
item
)
+
"-----------------"
);
}
}
});
log
.
info
(
"轨迹切分任务执行完成.............."
);
//删除无效的告警数据
Date
endTime
=
DateUtil
.
offsetMinute
(
new
Date
(),-
10
);
String
endTimeStr
=
DateUtil
.
format
(
endTime
,
"yyyy-MM-dd HH:mm:00"
);
...
...
@@ -588,11 +447,8 @@ public class WlCarMileageServiceImpl extends ServiceImpl<WlCarMileageMapper, WlC
Double
travel1
=
CoordinateUtil
.
distance
(
startLatitude
,
startLongitude
,
jsonObject1
.
getDoubleValue
(
"x"
),
jsonObject1
.
getDoubleValue
(
"y"
));
Double
travel2
=
CoordinateUtil
.
distance
(
startLatitude
,
startLongitude
,
jsonObject2
.
getDoubleValue
(
"x"
),
jsonObject2
.
getDoubleValue
(
"y"
));
log
.
info
(
"travel1:"
+
travel1
+
"travel2:"
+
travel2
);
if
(
travel2
>
travel1
)
{
log
.
info
(
"travel1:"
+
travel1
+
"travel2:"
+
travel2
);
log
.
info
(
"lat:"
+
startLatitude
+
"long:"
+
startLongitude
);
log
.
info
(
"lat:"
+
jsonObject1
.
getDoubleValue
(
"x"
)
+
"long:"
+
jsonObject1
.
getDoubleValue
(
"y"
));
speed
=
jsonObject1
.
getDoubleValue
(
"sp"
);
break
;
}
else
{
...
...
amos-boot-module/amos-boot-module-biz/amos-boot-module-jcs-biz/src/main/java/com/yeejoin/amos/boot/module/jcs/biz/audioToText/util/SpeechTranscriberDemo.java
View file @
49c43cd2
...
...
@@ -197,30 +197,4 @@ public class SpeechTranscriberDemo {
public
void
shutdown
()
{
client
.
shutdown
();
}
public
static
void
main
(
String
[]
args
)
throws
Exception
{
String
appKey
=
"89KKwpGXXN37Pn1G"
;
String
id
=
"LTAI5t8F2oYwmfoYXjCx5vbf"
;
String
secret
=
"du6jOpdxlKNCkCo5QN6EVFiI5zSaAv"
;
String
url
=
"wss://nls-gateway.cn-shanghai.aliyuncs.com/ws/v1"
;
// 默认值:wss://nls-gateway.cn-shanghai.aliyuncs.com/ws/v1。
/* if (args.length == 3) {
appKey = args[0];
id = args[1];
secret = args[2];
} else if (args.length == 4) {
appKey = args[0];
id = args[1];
secret = args[2];
url = args[3];
} else {
System.err.println("run error, need params(url is optional): " + "<app-key> <AccessKeyId> <AccessKeySecret> [url]");
System.exit(-1);
}*/
//本案例使用本地文件模拟发送实时流数据。您在实际使用时,可以实时采集或接收语音流并发送到ASR服务端。
String
filepath
=
""
;
// * 此处写的文件路径地址不要提交到git, 国网电科院SCA扫描会报告为漏洞: 存在“便携性缺陷”
SpeechTranscriberDemo
demo
=
new
SpeechTranscriberDemo
(
appKey
,
id
,
secret
,
url
);
demo
.
process
(
filepath
);
demo
.
shutdown
();
}
}
\ No newline at end of file
amos-boot-system-equip/src/main/resources/mapper/EmergencyMapper.xml
View file @
49c43cd2
...
...
@@ -1537,10 +1537,10 @@
AND wlesal.create_date LIKE CONCAT( DATE_FORMAT( NOW( ), '%Y-%m-%d' ), '%' )
</if>
<if
test=
"startDate != null and startDate != ''"
>
AND wlesal.create_date >= DATE_FORMAT(
$
{startDate}, '%Y-%m-%d %H:%i:%s' )
AND wlesal.create_date >= DATE_FORMAT(
#
{startDate}, '%Y-%m-%d %H:%i:%s' )
</if>
<if
test=
"endDate != null and endDate != ''"
>
AND DATE_FORMAT(
$
{endDate}, '%Y-%m-%d %H:%i:%s' ) >= wlesal.create_date
AND DATE_FORMAT(
#
{endDate}, '%Y-%m-%d %H:%i:%s' ) >= wlesal.create_date
</if>
<if
test=
"systemCode != null and systemCode != ''"
>
and fs.code = #{systemCode}
...
...
amos-boot-system-equip/src/main/resources/mapper/FireFightingSystemMapper.xml
View file @
49c43cd2
...
...
@@ -7005,10 +7005,10 @@
<if
test=
"sortField != null and sortField != ''"
>
<choose>
<when
test=
"sortOrder == 'ascend'"
>
${sortField}
ASC
_sortField
ASC
</when>
<otherwise>
${sortField}
DESC
_sortField
DESC
</otherwise>
</choose>
</if>
...
...
amos-boot-system-jcs/src/main/resources/application.properties
View file @
49c43cd2
...
...
@@ -135,9 +135,9 @@ fire-rescue=1432549862557130753
management.endpoints.enabled-by-default
=
false
#阿里云实时语音识别参数
speech-config.access-key-id
=
LTAI5t62oH95jgbjRiNXPsho
speech-config.access-key-secret
=
shy9SpogYgcdDoyTB3bvP21VSRmz8n
speech-config.app-key
=
FC84bGUpbNFrexoL
speech-config.access-key-id
=
ENC(bgO92hxidPL5U5gKK94aEHvWAQ9db9wjb/7XgkCsw6J+t9gTD20xsWrxF2tPY90Kw2fM/25m4ER7K5SQLsdi9g==)
speech-config.access-key-secret
=
ENC(GZthiafYoLwmNWRgT97aiVEBM6NkBnAx9tPyLKlUo/Qoh1r6A3R1u0x4WxSMcuGPqb1OlA/4DsZWpJ5kpONuQA==)
speech-config.app-key
=
ENC(AR74B7pRjlZVPInZ9RsZroQRHjuU/6rkGamtcp2O5XMLbEgk8NMEEAksnLrNaKFmrUlkfMnNkC5bIiwjVisx3w==)
mqtt.topic.command.car.jw
=
carCoordinates
...
...
amos-boot-system-patrol/src/main/resources/db/mapper/dbTemplate_plan_task.xml
View file @
49c43cd2
...
...
@@ -1523,13 +1523,13 @@
UNION ALL
SELECT
ifnull( count( DISTINCT LEFT(p_plan_task.point_num, 18) ), 0
) AS value,
COUNT(DISTINCT LEFT(p_plan_task.org_code, 18)
) AS value,
'今日已巡查站' AS name,
'JRYXCZ' AS code
FROM
p_plan_task
<where>
finish_status = 2
(finish_status = 2 OR finish_status = 3)
AND DATE_FORMAT( check_date, '%Y-%m-%d' ) = CURRENT_DATE ()
<if
test=
"bizOrgCode != null and bizOrgCode != ''"
>
AND org_code LIKE CONCAT(#{bizOrgCode}, '%')
...
...
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