Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
eshiled-new
/
ne-shield-standard-interfaces
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
1
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit b70a980e
authored
Mar 30, 2026
by
范富荣
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
添加对接思享驾接口逻辑
1 parent
80565b29
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
325 additions
and
14 deletions
pom.xml
src/main/java/cn/com/glsx/stdinterface/modules/model/sxj/DeviceSeparationAlarmItem.java
src/main/java/cn/com/glsx/stdinterface/modules/model/sxj/FenceAlarmItem.java
src/main/java/cn/com/glsx/stdinterface/modules/model/sxj/OfflineAlarmInfo.java
src/main/java/cn/com/glsx/stdinterface/modules/service/AlarmElectricFenceService.java
src/main/java/cn/com/glsx/stdinterface/modules/service/AlarmWarnAnalyseService.java
src/main/java/cn/com/glsx/stdinterface/modules/service/QyproAdminApiFacade.java
src/main/java/cn/com/glsx/stdinterface/modules/service/VehicleDeviceService.java
src/main/java/cn/com/glsx/stdinterface/modules/util/ApiClient.java
src/main/java/cn/com/glsx/stdinterface/modules/util/ECDSAUtil.java
src/main/resources/mapper/AlarmElectricFenceMapper.xml
pom.xml
View file @
b70a980
...
@@ -44,7 +44,7 @@
...
@@ -44,7 +44,7 @@
<dependency>
<dependency>
<groupId>
com.glsx
</groupId>
<groupId>
com.glsx
</groupId>
<artifactId>
ne-shield-standard-interfaces-api
</artifactId>
<artifactId>
ne-shield-standard-interfaces-api
</artifactId>
<version>
1.
2
.0-SNAPSHOT
</version>
<version>
1.
3
.0-SNAPSHOT
</version>
<scope>
compile
</scope>
<scope>
compile
</scope>
</dependency>
</dependency>
...
...
src/main/java/cn/com/glsx/stdinterface/modules/model/sxj/DeviceSeparationAlarmItem.java
View file @
b70a980
package
cn
.
com
.
glsx
.
stdinterface
.
modules
.
model
.
sxj
;
package
cn
.
com
.
glsx
.
stdinterface
.
modules
.
model
.
sxj
;
import
com.alibaba.fastjson.annotation.JSONField
;
import
lombok.Data
;
import
lombok.Data
;
import
lombok.ToString
;
import
lombok.ToString
;
...
@@ -17,36 +18,43 @@ public class DeviceSeparationAlarmItem implements Serializable {
...
@@ -17,36 +18,43 @@ public class DeviceSeparationAlarmItem implements Serializable {
/**
/**
* 事件Id
* 事件Id
*/
*/
@JSONField
(
name
=
"Id"
)
private
String
Id
;
private
String
Id
;
/**
/**
* 设备号
* 设备号
*/
*/
@JSONField
(
name
=
"Imei"
)
private
String
Imei
;
private
String
Imei
;
/**
/**
* 多个设备号
* 多个设备号
(仅库表映射;同步第三方单设备 JSON 不包含该字段)
*/
*/
@JSONField
(
serialize
=
false
)
private
String
deviceInfo
;
private
String
deviceInfo
;
/**
/**
* 预警类型:固定值43
* 预警类型:固定值43
*/
*/
@JSONField
(
name
=
"MessDataType"
)
private
String
MessDataType
;
private
String
MessDataType
;
/**
/**
* 事件时间
* 事件时间
*/
*/
@JSONField
(
name
=
"Time"
,
format
=
"yyyy-MM-dd HH:mm:ss"
)
private
Date
Time
;
private
Date
Time
;
/**
/**
* 车架号
* 车架号
*/
*/
@JSONField
(
name
=
"VinNumber"
)
private
String
VinNumber
;
private
String
VinNumber
;
/**
/**
* 有线无线属性:1-无线 2-有线
* 有线无线属性:1-无线 2-有线
*/
*/
@JSONField
(
name
=
"DeviceType"
)
private
String
DeviceType
;
private
String
DeviceType
;
// 无参构造(JSON反序列化必备)
// 无参构造(JSON反序列化必备)
...
...
src/main/java/cn/com/glsx/stdinterface/modules/model/sxj/FenceAlarmItem.java
View file @
b70a980
...
@@ -67,7 +67,7 @@ public class FenceAlarmItem implements Serializable {
...
@@ -67,7 +67,7 @@ public class FenceAlarmItem implements Serializable {
private
String
MsgAddress
;
// 严格匹配文档字段名:MsgAddress(大小写完全一致)
private
String
MsgAddress
;
// 严格匹配文档字段名:MsgAddress(大小写完全一致)
/**
/**
* 预警
状态
* 预警
类型
* 类型:int
* 类型:int
* 说明:1-预警,0-解除
* 说明:1-预警,0-解除
*/
*/
...
...
src/main/java/cn/com/glsx/stdinterface/modules/model/sxj/OfflineAlarmInfo.java
View file @
b70a980
package
cn
.
com
.
glsx
.
stdinterface
.
modules
.
model
.
sxj
;
package
cn
.
com
.
glsx
.
stdinterface
.
modules
.
model
.
sxj
;
import
com.alibaba.fastjson.annotation.JSONField
;
import
lombok.Data
;
import
lombok.Data
;
import
lombok.ToString
;
import
lombok.ToString
;
...
@@ -14,50 +15,61 @@ public class OfflineAlarmInfo implements Serializable {
...
@@ -14,50 +15,61 @@ public class OfflineAlarmInfo implements Serializable {
/**
/**
* 事件Id
* 事件Id
*/
*/
@JSONField
(
name
=
"Id"
)
private
String
Id
;
private
String
Id
;
/**
/**
* 设备号
* 设备号
*/
*/
@JSONField
(
name
=
"Imei"
)
private
String
Imei
;
private
String
Imei
;
/**
/**
* 预警类型:固定值46(离线超时)
* 预警类型:固定值46(离线超时)
*/
*/
@JSONField
(
name
=
"MessDataType"
)
private
String
MessDataType
;
private
String
MessDataType
;
/**
/**
* 事件时间
* 事件时间
*/
*/
@JSONField
(
name
=
"Time"
,
format
=
"yyyy-MM-dd HH:mm:ss"
)
private
Date
Time
;
private
Date
Time
;
/**
/**
* 车架号
* 车架号
*/
*/
@JSONField
(
name
=
"VinNumber"
)
private
String
VinNumber
;
private
String
VinNumber
;
/**
/**
* 有线无线属性:1-无线 2-有线
* 有线无线属性:1-无线 2-有线
*/
*/
@JSONField
(
name
=
"DeviceType"
)
private
String
DeviceType
;
private
String
DeviceType
;
/**
/**
* 事件纬度
* 事件纬度
*/
*/
@JSONField
(
name
=
"lat"
)
private
String
lat
;
private
String
lat
;
/**
/**
* 事件经度
* 事件经度
*/
*/
@JSONField
(
name
=
"lng"
)
private
String
lng
;
private
String
lng
;
/**
/**
* 离线时长(天)
* 离线时长(天)
*/
*/
@JSONField
(
name
=
"AlarmDay"
)
private
String
AlarmDay
;
private
String
AlarmDay
;
@JSONField
(
serialize
=
false
)
private
Date
lastGpsTime
;
private
Date
lastGpsTime
;
@JSONField
(
serialize
=
false
)
private
Date
lastBsTime
;
private
Date
lastBsTime
;
...
...
src/main/java/cn/com/glsx/stdinterface/modules/service/AlarmElectricFenceService.java
View file @
b70a980
...
@@ -13,13 +13,13 @@ import cn.com.glsx.stdinterface.modules.mapper.ElectricFenceMapper;
...
@@ -13,13 +13,13 @@ import cn.com.glsx.stdinterface.modules.mapper.ElectricFenceMapper;
import
cn.com.glsx.stdinterface.modules.mapper.VehicleDeviceMapper
;
import
cn.com.glsx.stdinterface.modules.mapper.VehicleDeviceMapper
;
import
cn.com.glsx.stdinterface.modules.mapper.VehicleMapper
;
import
cn.com.glsx.stdinterface.modules.mapper.VehicleMapper
;
import
cn.com.glsx.stdinterface.modules.model.sxj.FenceAlarmItem
;
import
cn.com.glsx.stdinterface.modules.model.sxj.FenceAlarmItem
;
import
cn.com.glsx.stdinterface.modules.model.sxj.FenceAlarmRequest
;
import
cn.com.glsx.stdinterface.modules.remote.NotifyCenterService
;
import
cn.com.glsx.stdinterface.modules.remote.NotifyCenterService
;
import
cn.com.glsx.stdinterface.modules.remote.RemoteGpsBsService
;
import
cn.com.glsx.stdinterface.modules.remote.RemoteGpsBsService
;
import
cn.com.glsx.stdinterface.modules.util.DateUtils
;
import
cn.com.glsx.stdinterface.modules.util.DateUtils
;
import
cn.hutool.core.date.DateUtil
;
import
cn.hutool.core.date.DateUtil
;
import
cn.hutool.core.util.ObjectUtil
;
import
cn.hutool.core.util.ObjectUtil
;
import
cn.hutool.json.JSONUtil
;
import
cn.hutool.json.JSONUtil
;
import
com.alibaba.fastjson.JSON
;
import
com.github.pagehelper.Page
;
import
com.github.pagehelper.Page
;
import
com.github.pagehelper.PageHelper
;
import
com.github.pagehelper.PageHelper
;
import
com.glsx.plat.common.utils.StringUtils
;
import
com.glsx.plat.common.utils.StringUtils
;
...
@@ -61,6 +61,9 @@ public class AlarmElectricFenceService {
...
@@ -61,6 +61,9 @@ public class AlarmElectricFenceService {
@Autowired
@Autowired
private
NotifyCenterService
notifyCenterService
;
private
NotifyCenterService
notifyCenterService
;
@Autowired
private
QyproAdminApiFacade
qyproAdminApiFacade
;
/**
/**
* 围栏围栏报警数据
* 围栏围栏报警数据
*
*
...
@@ -234,7 +237,14 @@ public class AlarmElectricFenceService {
...
@@ -234,7 +237,14 @@ public class AlarmElectricFenceService {
if
(
x
.
getAlarmTime
()
!=
null
)
{
if
(
x
.
getAlarmTime
()
!=
null
)
{
x
.
setTime
((
int
)
x
.
getAlarmTime
().
getTime
());
x
.
setTime
((
int
)
x
.
getAlarmTime
().
getTime
());
}
}
// 预警类型:默认预警1
x
.
setIsAlarm
(
1
);
//发送请求
//发送请求
try
{
qyproAdminApiFacade
.
syncDeviceWarningContent
(
JSON
.
toJSONString
(
x
));
}
catch
(
Exception
e
)
{
log
.
error
(
"围栏报警第三方同步失败, item={}"
,
x
,
e
);
}
});
});
int
pages
=
page
.
getPages
();
int
pages
=
page
.
getPages
();
...
...
src/main/java/cn/com/glsx/stdinterface/modules/service/AlarmWarnAnalyseService.java
View file @
b70a980
...
@@ -13,13 +13,14 @@ import cn.com.glsx.stdinterface.modules.mapper.AlarmWarnAnalyseMapper;
...
@@ -13,13 +13,14 @@ import cn.com.glsx.stdinterface.modules.mapper.AlarmWarnAnalyseMapper;
import
cn.com.glsx.stdinterface.modules.mapper.AlarmWarnAnalyseProcessMapper
;
import
cn.com.glsx.stdinterface.modules.mapper.AlarmWarnAnalyseProcessMapper
;
import
cn.com.glsx.stdinterface.modules.mapper.DeviceMapper
;
import
cn.com.glsx.stdinterface.modules.mapper.DeviceMapper
;
import
cn.com.glsx.stdinterface.modules.model.sxj.DeviceSeparationAlarmItem
;
import
cn.com.glsx.stdinterface.modules.model.sxj.DeviceSeparationAlarmItem
;
import
c
n.com.glsx.stdinterface.modules.model.sxj.DeviceSeparationAlarmRequest
;
import
c
om.alibaba.fastjson.JSON
;
import
com.github.pagehelper.Page
;
import
com.github.pagehelper.Page
;
import
com.github.pagehelper.PageHelper
;
import
com.github.pagehelper.PageHelper
;
import
com.glsx.plat.context.utils.PropertiesUtils
;
import
com.glsx.plat.context.utils.PropertiesUtils
;
import
com.glsx.plat.core.enums.SysConstants
;
import
com.glsx.plat.core.enums.SysConstants
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.collections.CollectionUtils
;
import
org.apache.commons.collections.CollectionUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.transaction.annotation.Transactional
;
...
@@ -53,6 +54,9 @@ public class AlarmWarnAnalyseService {
...
@@ -53,6 +54,9 @@ public class AlarmWarnAnalyseService {
@Autowired
@Autowired
private
DeviceMapper
deviceMapper
;
private
DeviceMapper
deviceMapper
;
@Autowired
private
QyproAdminApiFacade
qyproAdminApiFacade
;
/**
/**
* 保存警情中心数据
* 保存警情中心数据
*
*
...
@@ -168,9 +172,11 @@ public class AlarmWarnAnalyseService {
...
@@ -168,9 +172,11 @@ public class AlarmWarnAnalyseService {
Map
<
String
,
Device
>
finalDeviceMap
=
deviceMap
;
Map
<
String
,
Device
>
finalDeviceMap
=
deviceMap
;
deviceSeparationAlarmList
.
forEach
(
x
->
{
deviceSeparationAlarmList
.
forEach
(
x
->
{
String
[]
split
=
x
.
getDeviceInfo
().
split
(
";"
);
String
[]
split
=
x
.
getDeviceInfo
().
split
(
";"
);
//遍历数组
for
(
String
rawSn
:
split
)
{
List
<
String
>
snSplit
=
Arrays
.
asList
(
split
);
String
sn
=
StringUtils
.
trimToEmpty
(
rawSn
);
snSplit
.
forEach
(
sn
->
{
if
(
StringUtils
.
isBlank
(
sn
))
{
continue
;
}
DeviceSeparationAlarmItem
item
=
new
DeviceSeparationAlarmItem
();
DeviceSeparationAlarmItem
item
=
new
DeviceSeparationAlarmItem
();
item
.
setId
(
x
.
getId
());
item
.
setId
(
x
.
getId
());
item
.
setImei
(
sn
);
item
.
setImei
(
sn
);
...
@@ -178,16 +184,19 @@ public class AlarmWarnAnalyseService {
...
@@ -178,16 +184,19 @@ public class AlarmWarnAnalyseService {
item
.
setVinNumber
(
x
.
getVinNumber
());
item
.
setVinNumber
(
x
.
getVinNumber
());
item
.
setMessDataType
(
"43"
);
item
.
setMessDataType
(
"43"
);
Device
device
=
finalDeviceMap
.
get
(
sn
);
Device
device
=
finalDeviceMap
.
get
(
sn
);
if
(
device
!=
null
)
{
//设置有线/无线属性
if
(
device
!=
null
)
{
if
(
Objects
.
equals
(
1
,
device
.
getSource
()))
{
if
(
Objects
.
equals
(
1
,
device
.
getSource
()))
{
item
.
setDeviceType
(
"2"
);
item
.
setDeviceType
(
"2"
);
}
else
{
}
else
{
item
.
setDeviceType
(
"1"
);
item
.
setDeviceType
(
"1"
);
}
}
}
}
//发送请求
try
{
});
qyproAdminApiFacade
.
syncDeviceWarningContent
(
JSON
.
toJSONString
(
item
));
}
catch
(
Exception
e
)
{
log
.
error
(
"设备分离预警同步第三方失败, item:{}"
,
item
,
e
);
}
}
});
});
int
pages
=
page
.
getPages
();
int
pages
=
page
.
getPages
();
if
(
pageNum
>=
pages
)
{
if
(
pageNum
>=
pages
)
{
...
...
src/main/java/cn/com/glsx/stdinterface/modules/service/QyproAdminApiFacade.java
0 → 100644
View file @
b70a980
package
cn
.
com
.
glsx
.
stdinterface
.
modules
.
service
;
import
cn.com.glsx.stdinterface.modules.util.ApiClient
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONObject
;
import
com.glsx.plat.context.utils.PropertiesUtils
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.beans.factory.DisposableBean
;
import
org.springframework.stereotype.Component
;
import
java.util.concurrent.TimeUnit
;
import
java.util.concurrent.atomic.AtomicBoolean
;
/**
* 祺鲲 / qypro-admin 第三方接口门面:复用单一 {@link ApiClient},避免重复创建连接与 Token 状态分裂。
* <p>
* 配置项(建议由 Nacos 下发):{@code qypro.admin.systemKey}、{@code qypro.admin.privateKey}、{@code qypro.admin.baseUrl}
*/
@Slf4j
@Component
public
class
QyproAdminApiFacade
implements
DisposableBean
{
public
static
final
String
PROP_SYSTEM_KEY
=
"sxj.admin.systemKey"
;
public
static
final
String
PROP_PRIVATE_KEY
=
"sxj.admin.privateKey"
;
public
static
final
String
PROP_BASE_URL
=
"sxj.admin.baseUrl"
;
private
static
final
String
API_DEVICE_WARNING_CONTENT
=
"/v1/auth/device/warning-content"
;
/** 含首次调用至多 3 次 HTTP 调用(重试 < 3 次) */
private
static
final
int
WARNING_CONTENT_MAX_ATTEMPTS
=
3
;
private
static
final
long
RATE_LIMIT_BACKOFF_BASE_MS
=
1000L
;
private
final
Object
clientLock
=
new
Object
();
private
ApiClient
apiClient
;
private
volatile
boolean
destroyed
;
private
final
AtomicBoolean
missingConfigWarned
=
new
AtomicBoolean
(
false
);
/**
* 预警信息内容格式同步:POST {@value #API_DEVICE_WARNING_CONTENT},Token 模式(与 {@link ApiClient#main} 示例一致)。
*
* @param jsonBody application/json 请求体
* @throws ApiClient.ApiException 业务 code 非 200 或解析失败
*/
public
void
syncDeviceWarningContent
(
String
jsonBody
)
{
ApiClient
client
=
getOrCreateClient
();
if
(
client
==
null
)
{
return
;
}
for
(
int
attempt
=
1
;
attempt
<=
WARNING_CONTENT_MAX_ATTEMPTS
;
attempt
++)
{
log
.
info
(
"Qypro warning-content 请求 attempt={}/{} api={} body={}"
,
attempt
,
WARNING_CONTENT_MAX_ATTEMPTS
,
API_DEVICE_WARNING_CONTENT
,
jsonBody
);
String
response
=
client
.
post
(
API_DEVICE_WARNING_CONTENT
,
jsonBody
);
log
.
info
(
"Qypro warning-content 响应 attempt={} body={}"
,
attempt
,
response
);
JSONObject
o
=
JSON
.
parseObject
(
response
);
Integer
code
=
o
.
getInteger
(
"code"
);
if
(
code
!=
null
&&
code
==
200
)
{
return
;
}
if
(
Integer
.
valueOf
(
429
).
equals
(
code
)
&&
attempt
<
WARNING_CONTENT_MAX_ATTEMPTS
)
{
long
waitMs
=
RATE_LIMIT_BACKOFF_BASE_MS
*
(
1L
<<
(
attempt
-
1
));
log
.
warn
(
"Qypro warning-content 限流 code=429,{}ms 后进行第 {} 次重试, msg={}"
,
waitMs
,
attempt
+
1
,
o
.
getString
(
"msg"
));
sleepQuietly
(
waitMs
);
continue
;
}
throw
new
ApiClient
.
ApiException
(
"预警内容同步失败: code="
+
code
+
", msg="
+
o
.
getString
(
"msg"
));
}
}
private
static
void
sleepQuietly
(
long
waitMs
)
{
try
{
TimeUnit
.
MILLISECONDS
.
sleep
(
waitMs
);
}
catch
(
InterruptedException
e
)
{
Thread
.
currentThread
().
interrupt
();
throw
new
ApiClient
.
ApiException
(
"预警内容同步等待重试被中断"
,
e
);
}
}
private
ApiClient
getOrCreateClient
()
{
if
(
destroyed
)
{
return
null
;
}
synchronized
(
clientLock
)
{
if
(
apiClient
!=
null
)
{
return
apiClient
;
}
String
systemKey
=
PropertiesUtils
.
getProperty
(
PROP_SYSTEM_KEY
,
""
);
String
privateKey
=
PropertiesUtils
.
getProperty
(
PROP_PRIVATE_KEY
,
""
);
String
baseUrl
=
PropertiesUtils
.
getProperty
(
PROP_BASE_URL
,
""
);
if
(
StringUtils
.
isAnyBlank
(
systemKey
,
privateKey
,
baseUrl
))
{
if
(
missingConfigWarned
.
compareAndSet
(
false
,
true
))
{
log
.
warn
(
"Qypro 管理端未配置完整({}、{}、{}),跳过第三方预警同步"
,
PROP_SYSTEM_KEY
,
PROP_PRIVATE_KEY
,
PROP_BASE_URL
);
}
return
null
;
}
apiClient
=
new
ApiClient
(
systemKey
,
privateKey
,
baseUrl
);
return
apiClient
;
}
}
@Override
public
void
destroy
()
{
synchronized
(
clientLock
)
{
destroyed
=
true
;
if
(
apiClient
!=
null
)
{
try
{
apiClient
.
close
();
}
catch
(
Exception
e
)
{
log
.
warn
(
"关闭 Qypro ApiClient 异常"
,
e
);
}
apiClient
=
null
;
}
}
}
}
src/main/java/cn/com/glsx/stdinterface/modules/service/VehicleDeviceService.java
View file @
b70a980
...
@@ -17,6 +17,7 @@ import cn.hutool.core.date.DateUtil;
...
@@ -17,6 +17,7 @@ import cn.hutool.core.date.DateUtil;
import
com.github.pagehelper.Page
;
import
com.github.pagehelper.Page
;
import
com.github.pagehelper.PageHelper
;
import
com.github.pagehelper.PageHelper
;
import
com.github.pagehelper.PageInfo
;
import
com.github.pagehelper.PageInfo
;
import
com.alibaba.fastjson.JSON
;
import
com.glsx.plat.common.multithread.ListSplitIterator
;
import
com.glsx.plat.common.multithread.ListSplitIterator
;
import
com.glsx.plat.context.utils.PropertiesUtils
;
import
com.glsx.plat.context.utils.PropertiesUtils
;
import
com.glsx.plat.core.web.R
;
import
com.glsx.plat.core.web.R
;
...
@@ -54,6 +55,9 @@ public class VehicleDeviceService {
...
@@ -54,6 +55,9 @@ public class VehicleDeviceService {
@Autowired
@Autowired
private
AlarmWarnAnalyseService
alarmWarnAnalyseService
;
private
AlarmWarnAnalyseService
alarmWarnAnalyseService
;
@Autowired
private
QyproAdminApiFacade
qyproAdminApiFacade
;
/**
/**
* 通过设备号获取设备关系实体类
* 通过设备号获取设备关系实体类
*
*
...
@@ -123,7 +127,7 @@ public class VehicleDeviceService {
...
@@ -123,7 +127,7 @@ public class VehicleDeviceService {
}
}
//1. 统计设备分离报警
//1. 统计设备分离报警
alarmWarnAnalyseService
.
pushSXJDeviceSeparationAlarmData
(
date
,
createdIds
);
alarmWarnAnalyseService
.
pushSXJDeviceSeparationAlarmData
(
date
,
createdIds
);
return
fals
e
;
return
tru
e
;
}
}
...
@@ -237,6 +241,11 @@ public class VehicleDeviceService {
...
@@ -237,6 +241,11 @@ public class VehicleDeviceService {
offlineAlarmInfo
.
setAlarmDay
(
calculateOfflineDays
(
now
,
lastTime
).
toString
());
offlineAlarmInfo
.
setAlarmDay
(
calculateOfflineDays
(
now
,
lastTime
).
toString
());
}
}
//发送请求
//发送请求
try
{
qyproAdminApiFacade
.
syncDeviceWarningContent
(
JSON
.
toJSONString
(
offlineAlarmInfo
));
}
catch
(
Exception
e
)
{
log
.
error
(
"离线报警第三方同步失败, item:{}"
,
offlineAlarmInfo
,
e
);
}
}
}
int
pages
=
page
.
getPages
();
int
pages
=
page
.
getPages
();
...
...
src/main/java/cn/com/glsx/stdinterface/modules/util/ApiClient.java
0 → 100644
View file @
b70a980
This diff is collapsed.
Click to expand it.
src/main/java/cn/com/glsx/stdinterface/modules/util/ECDSAUtil.java
0 → 100644
View file @
b70a980
package
cn
.
com
.
glsx
.
stdinterface
.
modules
.
util
;
import
org.apache.commons.codec.binary.Base64
;
import
java.security.*
;
import
java.security.spec.ECGenParameterSpec
;
import
java.security.spec.PKCS8EncodedKeySpec
;
import
java.security.spec.X509EncodedKeySpec
;
import
java.util.concurrent.ConcurrentHashMap
;
public
class
ECDSAUtil
{
/**
* 椭圆曲线算法
*/
private
static
final
String
EC_ALGORITHM
=
"EC"
;
/**
* 签名算法 (P-256曲线 + SHA256)
*/
private
static
final
String
SIGNATURE_ALGORITHM
=
"SHA256withECDSA"
;
/**
* 标准曲线名称
*/
private
static
final
String
EC_CURVE
=
"secp256r1"
;
// P-256
// 缓存KeyFactory提升性能
private
static
final
ConcurrentHashMap
<
String
,
KeyFactory
>
KEY_FACTORY_CACHE
=
new
ConcurrentHashMap
<>();
/**
* 生成密钥对 (P-256,签名长度约64-72字节,Base64后约88字符)
*/
public
static
KeyPair
getKeyPair
()
throws
Exception
{
KeyPairGenerator
keyPairGenerator
=
KeyPairGenerator
.
getInstance
(
EC_ALGORITHM
);
keyPairGenerator
.
initialize
(
new
ECGenParameterSpec
(
EC_CURVE
),
new
SecureRandom
());
return
keyPairGenerator
.
generateKeyPair
();
}
/**
* 获取公钥(Base64编码)
*/
public
static
String
getPublicKey
(
KeyPair
keyPair
)
{
return
Base64
.
encodeBase64String
(
keyPair
.
getPublic
().
getEncoded
());
}
/**
* 获取私钥(Base64编码)
*/
public
static
String
getPrivateKey
(
KeyPair
keyPair
)
{
return
Base64
.
encodeBase64String
(
keyPair
.
getPrivate
().
getEncoded
());
}
/**
* ECDSA签名
* @param data 原文
* @param privateKeyBase64 私钥Base64
* @return Base64签名结果(
*/
public
static
String
sign
(
String
data
,
String
privateKeyBase64
)
throws
Exception
{
PrivateKey
privateKey
=
loadPrivateKey
(
privateKeyBase64
);
Signature
signature
=
Signature
.
getInstance
(
SIGNATURE_ALGORITHM
);
signature
.
initSign
(
privateKey
);
signature
.
update
(
data
.
getBytes
(
"UTF-8"
));
return
Base64
.
encodeBase64String
(
signature
.
sign
());
}
/**
* ECDSA验签(替代原RSA verify)
* @param data 原文
* @param signBase64 签名Base64
* @param publicKeyBase64 公钥Base64
*/
public
static
boolean
verify
(
String
data
,
String
signBase64
,
String
publicKeyBase64
)
throws
Exception
{
PublicKey
publicKey
=
loadPublicKey
(
publicKeyBase64
);
Signature
signature
=
Signature
.
getInstance
(
SIGNATURE_ALGORITHM
);
signature
.
initVerify
(
publicKey
);
signature
.
update
(
data
.
getBytes
(
"UTF-8"
));
return
signature
.
verify
(
Base64
.
decodeBase64
(
signBase64
));
}
/**
* JWT专用:获取ECPrivateKey对象
*/
public
static
PrivateKey
getPrivateKey
(
String
privateKeyBase64
)
throws
Exception
{
return
loadPrivateKey
(
privateKeyBase64
);
}
/**
* JWT专用:获取ECPublicKey对象
*/
public
static
PublicKey
getPublicKey
(
String
publicKeyBase64
)
throws
Exception
{
return
loadPublicKey
(
publicKeyBase64
);
}
/**
* 加载私钥(支持PKCS#8格式)
*/
private
static
PrivateKey
loadPrivateKey
(
String
privateKeyBase64
)
throws
Exception
{
String
cleaned
=
cleanKey
(
privateKeyBase64
);
byte
[]
keyBytes
=
Base64
.
decodeBase64
(
cleaned
);
PKCS8EncodedKeySpec
spec
=
new
PKCS8EncodedKeySpec
(
keyBytes
);
KeyFactory
keyFactory
=
getKeyFactory
();
return
keyFactory
.
generatePrivate
(
spec
);
}
/**
* 加载公钥(支持X.509格式)
*/
private
static
PublicKey
loadPublicKey
(
String
publicKeyBase64
)
throws
Exception
{
String
cleaned
=
cleanKey
(
publicKeyBase64
);
byte
[]
keyBytes
=
Base64
.
decodeBase64
(
cleaned
);
X509EncodedKeySpec
spec
=
new
X509EncodedKeySpec
(
keyBytes
);
KeyFactory
keyFactory
=
getKeyFactory
();
return
keyFactory
.
generatePublic
(
spec
);
}
/**
* 清理密钥字符串(去除头尾标记和换行)
*/
private
static
String
cleanKey
(
String
key
)
{
if
(
key
==
null
||
key
.
trim
().
isEmpty
())
{
throw
new
IllegalArgumentException
(
"密钥不能为空"
);
}
return
key
.
replace
(
"-----BEGIN PRIVATE KEY-----"
,
""
)
.
replace
(
"-----END PRIVATE KEY-----"
,
""
)
.
replace
(
"-----BEGIN PUBLIC KEY-----"
,
""
)
.
replace
(
"-----END PUBLIC KEY-----"
,
""
)
.
replace
(
"-----BEGIN EC PRIVATE KEY-----"
,
""
)
// 兼容SEC1格式
.
replace
(
"-----END EC PRIVATE KEY-----"
,
""
)
.
replaceAll
(
"\\s+"
,
""
);
}
private
static
KeyFactory
getKeyFactory
()
throws
NoSuchAlgorithmException
{
return
KEY_FACTORY_CACHE
.
computeIfAbsent
(
EC_ALGORITHM
,
k
->
{
try
{
return
KeyFactory
.
getInstance
(
k
);
}
catch
(
NoSuchAlgorithmException
e
)
{
throw
new
RuntimeException
(
e
);
}
});
}
}
\ No newline at end of file
\ No newline at end of file
src/main/resources/mapper/AlarmElectricFenceMapper.xml
View file @
b70a980
...
@@ -89,7 +89,7 @@
...
@@ -89,7 +89,7 @@
</select>
</select>
<select
id=
"listAlarmElectricFence"
resultType=
"cn.com.glsx.stdinterface.modules.model.sxj.FenceAlarmItem"
>
<select
id=
"listAlarmElectricFence"
resultType=
"cn.com.glsx.stdinterface.modules.model.sxj.FenceAlarmItem"
>
select taef.id as Id, taef.sn as Imei , taef.alarm_time as alarmTime, tv.vin as VinNumber,
taef.alarm_time as alarmTime,
select taef.id as Id, taef.sn as Imei , taef.alarm_time as alarmTime, tv.vin as VinNumber,
taef.address as MsgAddress
taef.address as MsgAddress
from t_vehicle tv
from t_vehicle tv
inner join t_vehicle_device tvd on tvd.vehicle_id = tv.id
inner join t_vehicle_device tvd on tvd.vehicle_id = tv.id
...
...
Write
Preview
Markdown
is supported
Attach a file
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 post a comment