Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
cloud-fb
Overview
Overview
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
王衍超
cloud-fb
Commits
1d2b70d7
Commit
1d2b70d7
authored
Apr 26, 2022
by
yanHeng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[初始化] wuLink对接
parent
e30dac8c
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
85 additions
and
13 deletions
+85
-13
IotPlatformUtils.java
...in/java/com/beecode/inz/common/util/IotPlatformUtils.java
+62
-8
ShipInfoServiceImpl.java
.../xyst/dinas/biz/internal/service/ShipInfoServiceImpl.java
+23
-5
No files found.
backend/inz.common/src/main/java/com/beecode/inz/common/util/IotPlatformUtils.java
View file @
1d2b70d7
...
...
@@ -8,6 +8,7 @@ import org.slf4j.LoggerFactory;
import
org.springframework.stereotype.Component
;
import
org.springframework.web.client.RestTemplate
;
import
java.net.URLEncoder
;
import
java.nio.charset.StandardCharsets
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
...
...
@@ -59,11 +60,14 @@ public class IotPlatformUtils {
/**
* 历史轨迹URL
*/
private
static
final
String
HISTORY_URL
=
GPS_WU_LING_DOMAIN
+
"devices/history
"
;
private
static
final
String
HISTORY_URL
=
GPS_WU_LING_DOMAIN
_API
+
"/api/v1/gateways/%1$s/metrics
"
;
//跟踪url
private
static
final
String
TRACKING_URL
=
GPS_WU_LING_DOMAIN_API
+
"api/v1/gateways/【%1$s】/metrics/last"
;
private
static
final
String
TRACKING_URL
=
GPS_WU_LING_DOMAIN_API
+
"api/v1/gateways/%1$s/metrics/last"
;
//网关指标
private
static
final
String
METRICS_PARAM
=
"[\"高程\",\"状态\",\"模拟量\",\"里程\",\"GNSS 定位卫星数\",\"方向\",\"纬度\",\"消息ID\",\"速度\",\"经度\",\"无线通信网络信号强度\",\"__internal_online_status__\",\"IO 状态位\",\"报警标志\"]"
;
/**
* 获取单个设备最新数据
...
...
@@ -94,9 +98,13 @@ public class IotPlatformUtils {
List
<
String
>
imeisInfoKey
=
new
ArrayList
<>();
String
[]
split
=
imeis
.
split
(
","
);
for
(
String
s
:
split
)
{
String
s1
=
RedisUtils
.
getInstance
().
get
(
getGpsWuLingImeisTrackingRedisKey
(
imei
s
));
String
s1
=
RedisUtils
.
getInstance
().
get
(
getGpsWuLingImeisTrackingRedisKey
(
s
));
if
(
StringUtils
.
isNotEmpty
(
s1
)){
imeisInfos
.
add
(
new
JSONObject
(
s1
).
toMap
());
JSONArray
objects
=
new
JSONArray
(
s1
);
for
(
int
i
=
0
;
i
<
objects
.
length
();
i
++)
{
Map
<
String
,
Object
>
imeisInfo
=
objects
.
getJSONObject
(
i
).
toMap
();
imeisInfos
.
add
(
imeisInfo
);
}
}
else
{
imeisInfoKey
.
add
(
s
);
}
...
...
@@ -120,14 +128,13 @@ public class IotPlatformUtils {
JSONObject
getStr
=
new
JSONObject
(
sendGet
);
int
code
=
getStr
.
getInt
(
"code"
);
if
(
20000
==(
code
))
{
JSONArray
data
=
getStr
.
getJSON
Array
(
"data
"
);
JSONArray
data
=
getStr
.
getJSON
Object
(
"data"
).
getJSONArray
(
"metrics
"
);
for
(
int
i
=
0
;
i
<
data
.
length
();
i
++)
{
//每分钟限制了600次请求 8秒缓存,可能不大够..
JSONObject
jsonObject
=
data
.
getJSONObject
(
i
);
Map
<
String
,
Object
>
imeisInfo
=
jsonObject
.
toMap
();
RedisUtils
.
getInstance
().
set
(
getGpsWuLingImeisTrackingRedisKey
(
imeis
),
jsonObject
.
toString
(),
8
);
Map
<
String
,
Object
>
imeisInfo
=
data
.
getJSONObject
(
i
).
toMap
();
imeisInfos
.
add
(
imeisInfo
);
}
RedisUtils
.
getInstance
().
set
(
getGpsWuLingImeisTrackingRedisKey
(
imeis
),
data
.
toString
(),
8
);
}
else
{
logger
.
error
(
"请求GPSWuLink平台获取tracking出错,错误信息"
+
getStr
.
get
(
"msg"
)+
",设备号列表"
+
imeis
);
}
...
...
@@ -183,4 +190,51 @@ public class IotPlatformUtils {
}
public
static
List
<
Object
>
history
(
String
imei
,
Long
startTime
,
Long
endTime
)
throws
Exception
{
List
<
Object
>
datas
=
null
;
if
(
StringUtils
.
isEmpty
(
imei
)){
return
null
;
}
String
token
=
null
;
try
{
token
=
RedisUtils
.
getInstance
().
get
(
getGpsWuLingTokenRedisKey
(
CLIET_ID
,
CLIENT_SECRET
));
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
if
(
token
==
null
||
""
.
equals
(
token
)){
HashMap
<
String
,
Object
>
tokenMap
=
getAuthToken
(
CLIET_ID
,
CLIENT_SECRET
);
if
((
int
)
tokenMap
.
get
(
"status"
)
==
0
)
{
token
=
tokenMap
.
get
(
"data"
).
toString
();
}
}
String
param
=
"serialNumber="
+
imei
;
//根据设备序号 查询网关id
String
findGatewayId
=
HttpSendUtil
.
sendGet
(
FIND_GATEWAY_ID_URL
,
param
,
token
);
JSONObject
findStr
=
new
JSONObject
(
findGatewayId
);
int
findCode
=
findStr
.
getInt
(
"code"
);
String
id
=
""
;
if
(
20000
==(
findCode
))
{
id
=
findStr
.
get
(
"data"
).
toString
();
}
if
(
""
.
equals
(
id
)){
return
null
;
}
//根据网关id 查询网关最新数据
String
metricsParam
=
URLEncoder
.
encode
(
METRICS_PARAM
,
"UTF-8"
);
String
sendParam
=
"startTime="
+
startTime
+
"&stopTime="
+
endTime
+
"&metrics="
+
metricsParam
;
String
sendGet
=
HttpSendUtil
.
sendGet
(
String
.
format
(
HISTORY_URL
,
id
),
sendParam
,
token
);
JSONObject
getStr
=
new
JSONObject
(
sendGet
);
int
code
=
getStr
.
getInt
(
"code"
);
if
(
20000
==(
code
))
{
JSONArray
data
=
getStr
.
getJSONObject
(
"data"
).
getJSONArray
(
"metrics"
);
datas
=
data
.
toList
();
}
else
{
logger
.
error
(
"请求GPSWuLink平台获取tracking出错,错误信息"
+
getStr
.
get
(
"msg"
)+
",设备号列表"
+
imei
);
}
return
datas
;
}
}
backend/xyst.dinas.biz/src/main/java/com/xyst/dinas/biz/internal/service/ShipInfoServiceImpl.java
View file @
1d2b70d7
...
...
@@ -3,7 +3,6 @@ package com.xyst.dinas.biz.internal.service;
import
com.beecode.bap.attachment.common.Page
;
import
com.beecode.bcp.type.KObject
;
import
com.beecode.inz.common.BaseConstants
;
import
com.beecode.inz.common.util.GpsOOUtil
;
import
com.beecode.inz.common.util.IotPlatformUtils
;
import
com.xyst.dinas.biz.dao.ShipInfoDao
;
import
com.xyst.dinas.biz.service.ShipInfoService
;
...
...
@@ -125,17 +124,36 @@ public class ShipInfoServiceImpl implements ShipInfoService {
return
list
;
}
/**
* @Author yanHeng
* @Date 2022/4/25 18:07
* @Param [uuid, startTime, endTime]
* @return java.util.List<java.lang.Object>
* 旧版本 获取谷米历史数据轨迹
**/
// @Override
// public List<Object> getShipHistoryById(UUID uuid, Long startTime, Long endTime) throws Exception {
// KObject load = shipInfoDao.load(uuid);
// String account = load.getString("account");
// String accountPassword = load.getString("accountPassword");
// String imei = load.getString("deviceNumber");
//
// if(StringUtils.isEmpty(account)||StringUtils.isEmpty(accountPassword)||StringUtils.isEmpty(imei)){
// return null;
// }
// return GpsOOUtil.history(account, accountPassword, imei, null, startTime, endTime, null);
// }
@Override
public
List
<
Object
>
getShipHistoryById
(
UUID
uuid
,
Long
startTime
,
Long
endTime
)
throws
Exception
{
KObject
load
=
shipInfoDao
.
load
(
uuid
);
String
account
=
load
.
getString
(
"account"
);
String
accountPassword
=
load
.
getString
(
"accountPassword"
);
String
imei
=
load
.
getString
(
"deviceNumber"
);
if
(
StringUtils
.
isEmpty
(
account
)||
StringUtils
.
isEmpty
(
accountPassword
)||
StringUtils
.
isEmpty
(
imei
)){
if
(
StringUtils
.
isEmpty
(
imei
)){
return
null
;
}
return
GpsOOUtil
.
history
(
account
,
accountPassword
,
imei
,
null
,
startTime
,
endTime
,
null
);
return
IotPlatformUtils
.
history
(
imei
,
startTime
,
endTime
);
}
@Override
...
...
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