Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
eshiled-new
/
ne-shield-trialdrive-admin
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 40d52e26
authored
Jun 30, 2021
by
黄小葱
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
新增和修改车辆中 增加设备时从旧e盾获取设备信息
1 parent
9894ca35
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
520 additions
and
40 deletions
src/main/java/cn/com/glsx/admin/modules/service/DeviceService.java
src/main/java/cn/com/glsx/admin/modules/service/RemoteDeviceService.java
src/main/java/cn/com/glsx/admin/modules/service/VehicleService.java
src/main/java/cn/com/glsx/admin/modules/utils/Coder.java
src/main/java/cn/com/glsx/admin/modules/utils/GopUtil.java
src/main/java/cn/com/glsx/admin/modules/utils/MD5Util.java
src/test/java/cn/com/glsx/admin/modules/service/DeviceServiceTest.java
src/test/java/cn/com/glsx/admin/modules/service/VehicleServiceTest.java
src/main/java/cn/com/glsx/admin/modules/service/DeviceService.java
View file @
40d52e2
...
@@ -2,9 +2,13 @@ package cn.com.glsx.admin.modules.service;
...
@@ -2,9 +2,13 @@ package cn.com.glsx.admin.modules.service;
import
cn.com.glsx.admin.modules.entity.Device
;
import
cn.com.glsx.admin.modules.entity.Device
;
import
cn.com.glsx.admin.modules.mapper.DeviceMapper
;
import
cn.com.glsx.admin.modules.mapper.DeviceMapper
;
import
cn.com.glsx.admin.modules.model.param.TrackInfoBo
;
import
org.springframework.beans.BeanUtils
;
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
java.util.Date
;
/**
/**
* @Desc:设备service
* @Desc:设备service
* @Author huangxc
* @Author huangxc
...
@@ -15,6 +19,9 @@ public class DeviceService {
...
@@ -15,6 +19,9 @@ public class DeviceService {
@Autowired
@Autowired
private
DeviceMapper
deviceMapper
;
private
DeviceMapper
deviceMapper
;
@Autowired
private
RemoteDeviceService
remoteDeviceService
;
public
int
insertDevice
(
Device
device
)
{
public
int
insertDevice
(
Device
device
)
{
return
deviceMapper
.
insert
(
device
);
return
deviceMapper
.
insert
(
device
);
}
}
...
@@ -35,5 +42,32 @@ public class DeviceService {
...
@@ -35,5 +42,32 @@ public class DeviceService {
return
true
;
return
true
;
}
}
/**
* 远程调用获取设备信息
* @param sn
*/
public
TrackInfoBo
remoteGetDeviceBySn
(
String
sn
)
{
return
remoteDeviceService
.
getDeviceBySn
(
sn
);
}
/**
* 保存设备
* @param trackInfo
* @param createId
*/
public
int
saveTrackInfoBo
(
TrackInfoBo
trackInfo
,
Long
createId
)
{
Device
device
=
new
Device
();
BeanUtils
.
copyProperties
(
trackInfo
,
device
);
// device.setName("");
device
.
setSim
(
trackInfo
.
getSimPhone
());
device
.
setManufacturer
(
trackInfo
.
getPartner
());
device
.
setActivateStatus
(
trackInfo
.
getIsActive
());
device
.
setActivateTime
(
trackInfo
.
getActiveDate
());
device
.
setCreatedBy
(
createId
);
device
.
setCreatedDate
(
new
Date
());
return
insertDevice
(
device
);
}
}
}
src/main/java/cn/com/glsx/admin/modules/service/RemoteDeviceService.java
0 → 100644
View file @
40d52e2
package
cn
.
com
.
glsx
.
admin
.
modules
.
service
;
import
cn.com.glsx.admin.modules.model.param.TrackInfoBo
;
import
cn.com.glsx.admin.modules.utils.GopUtil
;
import
com.alibaba.fastjson.JSONObject
;
import
com.glsx.plat.common.utils.HttpUtils
;
import
com.glsx.plat.context.utils.PropertiesUtils
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang.StringUtils
;
import
org.apache.logging.log4j.util.PropertiesUtil
;
import
org.springframework.stereotype.Service
;
import
java.util.TreeMap
;
@Slf4j
@Service
public
class
RemoteDeviceService
{
/**
* 调用e盾标准接口获取设备信息
* @param sn
*/
public
TrackInfoBo
getDeviceBySn
(
String
sn
)
{
String
url
=
PropertiesUtils
.
getProperty
(
"edun.otsi.url"
)
+
"/api/device/getInfoBySn"
;
String
appKet
=
PropertiesUtils
.
getProperty
(
"edun.otsi.appKet"
);
String
appSecret
=
PropertiesUtils
.
getProperty
(
"edun.otsi.appSecret"
);
TreeMap
<
String
,
Object
>
tparams
=
new
TreeMap
<>();
tparams
.
put
(
"appKey"
,
appKet
);
tparams
.
put
(
"sn"
,
sn
);
//加密得到sign
String
sign
=
GopUtil
.
sign
(
tparams
,
appSecret
);
tparams
.
put
(
"sign"
,
sign
);
String
result
=
HttpUtils
.
get
(
url
,
tparams
);
JSONObject
resultObj
=
JSONObject
.
parseObject
(
result
);
if
(
resultObj
==
null
)
{
log
.
info
(
"remote getInfoBysn result is null"
);
return
null
;
}
String
returnCode
=
resultObj
.
getString
(
"returnCode"
);
String
message
=
resultObj
.
getString
(
"message"
);
if
(
StringUtils
.
isBlank
(
returnCode
)
||
!
"0"
.
equals
(
returnCode
))
{
log
.
info
(
"remote getInfoBysn fail! returnCode:"
+
returnCode
+
"; message:"
+
message
);
return
null
;
}
String
data
=
resultObj
.
getString
(
"data"
);
if
(
StringUtils
.
isBlank
(
data
))
{
return
null
;
}
TrackInfoBo
trackInfoBo
=
JSONObject
.
parseObject
(
data
,
TrackInfoBo
.
class
);
return
trackInfoBo
;
}
}
src/main/java/cn/com/glsx/admin/modules/service/VehicleService.java
View file @
40d52e2
...
@@ -19,20 +19,13 @@ import cn.com.glsx.admin.modules.model.param.*;
...
@@ -19,20 +19,13 @@ import cn.com.glsx.admin.modules.model.param.*;
import
cn.com.glsx.admin.modules.utils.DateUtil
;
import
cn.com.glsx.admin.modules.utils.DateUtil
;
import
cn.com.glsx.admin.modules.utils.FileIOUtil
;
import
cn.com.glsx.admin.modules.utils.FileIOUtil
;
import
cn.com.glsx.auth.utils.ShieldContextHolder
;
import
cn.com.glsx.auth.utils.ShieldContextHolder
;
import
cn.com.glsx.publiccenter.api.dto.request.FindDictDataRequest
;
import
cn.com.glsx.publiccenter.api.dto.response.SysDictDataResponse
;
import
cn.com.glsx.publiccenter.api.dto.response.SysDictDataResponse
;
import
cn.com.glsx.publiccenter.api.feign.SysDictDataService
;
import
cn.com.glsx.usercenter.api.dto.request.FindUserRequest
;
import
cn.com.glsx.usercenter.api.dto.request.FindUserRequest
;
import
cn.com.glsx.usercenter.api.dto.response.User
;
import
cn.com.glsx.usercenter.api.dto.response.User
;
import
cn.com.glsx.usercenter.api.feign.ApiUserService
;
import
cn.com.glsx.usercenter.api.feign.UserService
;
import
com.github.pagehelper.PageHelper
;
import
com.github.pagehelper.PageHelper
;
import
com.github.pagehelper.PageInfo
;
import
com.github.pagehelper.PageInfo
;
import
com.glsx.plat.common.utils.StringUtils
;
import
com.glsx.plat.common.utils.StringUtils
;
import
com.glsx.plat.context.utils.PropertiesUtils
;
import
com.glsx.plat.context.utils.PropertiesUtils
;
import
com.glsx.plat.core.web.R
;
import
com.google.errorprone.annotations.FormatString
;
import
com.google.gson.reflect.TypeToken
;
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.collections.map.HashedMap
;
import
org.apache.commons.collections.map.HashedMap
;
...
@@ -40,7 +33,6 @@ import org.springframework.beans.BeanUtils;
...
@@ -40,7 +33,6 @@ import org.springframework.beans.BeanUtils;
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
;
import
scala.runtime.StringFormat
;
import
java.io.FileNotFoundException
;
import
java.io.FileNotFoundException
;
import
java.io.InputStream
;
import
java.io.InputStream
;
...
@@ -142,10 +134,17 @@ public class VehicleService {
...
@@ -142,10 +134,17 @@ public class VehicleService {
if
(
StringUtils
.
isBlank
(
sn
))
{
if
(
StringUtils
.
isBlank
(
sn
))
{
return
;
return
;
}
}
//查询该设备是否存在
//查询该设备是否存在
不存在 则从旧e盾查询
if
(!
deviceService
.
checkSnExist
(
sn
))
{
if
(!
deviceService
.
checkSnExist
(
sn
))
{
throw
new
AdminException
(
ResultEnum
.
DEVICE_NOT_EXIST
.
getCode
(),
// 旧e盾不存在 抛出异常 存在则保存数据
String
.
format
(
ResultEnum
.
DEVICE_NOT_EXIST
.
getMessage
(),
sn
));
TrackInfoBo
trackInfoBo
=
deviceService
.
remoteGetDeviceBySn
(
sn
);
if
(
trackInfoBo
==
null
)
{
throw
new
AdminException
(
ResultEnum
.
DEVICE_NOT_EXIST
.
getCode
(),
String
.
format
(
ResultEnum
.
DEVICE_NOT_EXIST
.
getMessage
(),
sn
));
}
else
{
deviceService
.
saveTrackInfoBo
(
trackInfoBo
,
driveVehicleBo
.
getShopNameId
());
}
}
}
//查询设备是否绑定过 绑定过 抛出异常
//查询设备是否绑定过 绑定过 抛出异常
VehicleDevice
vdBind
=
vehicleDeviceService
.
getVehicleDeviceBySnBind
(
sn
);
VehicleDevice
vdBind
=
vehicleDeviceService
.
getVehicleDeviceBySnBind
(
sn
);
...
@@ -196,15 +195,25 @@ public class VehicleService {
...
@@ -196,15 +195,25 @@ public class VehicleService {
updateVehicle
(
driveVehicleoBo
);
updateVehicle
(
driveVehicleoBo
);
List
<
VehicleDevice
>
bindVehicleDevice
=
vehicleDeviceService
.
listVehicleDeviceByVehicleIdBind
(
Long
.
valueOf
(
driveVehicleoBo
.
getTempId
()));
List
<
VehicleDevice
>
bindVehicleDevice
=
vehicleDeviceService
.
listVehicleDeviceByVehicleIdBind
(
Long
.
valueOf
(
driveVehicleoBo
.
getTempId
()));
String
sn
=
driveVehicleoBo
.
getSn
();
String
sn
=
driveVehicleoBo
.
getSn
();
//1.现在不绑定 以前也未绑定
if
(
StringUtils
.
isBlank
(
sn
)
&&
CollectionUtils
.
isEmpty
(
bindVehicleDevice
))
{
if
(
StringUtils
.
isBlank
(
sn
)
&&
CollectionUtils
.
isEmpty
(
bindVehicleDevice
))
{
return
;
return
;
//2. 现在不绑定 以前绑定了 提示
}
else
if
(
StringUtils
.
isBlank
(
sn
)
&&
CollectionUtils
.
isNotEmpty
(
bindVehicleDevice
))
{
}
else
if
(
StringUtils
.
isBlank
(
sn
)
&&
CollectionUtils
.
isNotEmpty
(
bindVehicleDevice
))
{
throw
new
AdminException
(
ResultEnum
.
UN_BIND_DEVICE
);
throw
new
AdminException
(
ResultEnum
.
UN_BIND_DEVICE
);
}
}
// 现在绑定了 判断设备是否存在 不存在 则从旧e盾查询
if
(
StringUtils
.
isNotBlank
(
sn
)
&&
!
deviceService
.
checkSnExist
(
sn
))
{
if
(
StringUtils
.
isNotBlank
(
sn
)
&&
!
deviceService
.
checkSnExist
(
sn
))
{
throw
new
AdminException
(
ResultEnum
.
DEVICE_NOT_EXIST
.
getCode
(),
// 旧e盾不存在 抛出异常 存在则保存数据
String
.
format
(
ResultEnum
.
DEVICE_NOT_EXIST
.
getMessage
(),
sn
));
TrackInfoBo
trackInfoBo
=
deviceService
.
remoteGetDeviceBySn
(
sn
);
if
(
trackInfoBo
==
null
)
{
throw
new
AdminException
(
ResultEnum
.
DEVICE_NOT_EXIST
.
getCode
(),
String
.
format
(
ResultEnum
.
DEVICE_NOT_EXIST
.
getMessage
(),
sn
));
}
else
{
deviceService
.
saveTrackInfoBo
(
trackInfoBo
,
driveVehicleoBo
.
getShopNameId
());
}
}
}
// 3. 现在绑定了 以前也绑定了
if
(
StringUtils
.
isNotBlank
(
sn
)
&&
CollectionUtils
.
isNotEmpty
(
bindVehicleDevice
))
{
if
(
StringUtils
.
isNotBlank
(
sn
)
&&
CollectionUtils
.
isNotEmpty
(
bindVehicleDevice
))
{
//绑定的设备和已存在的是否相同 全部不相同 提示先解绑 再重新绑定
//绑定的设备和已存在的是否相同 全部不相同 提示先解绑 再重新绑定
boolean
bindFlag
=
false
;
boolean
bindFlag
=
false
;
...
@@ -218,6 +227,7 @@ public class VehicleService {
...
@@ -218,6 +227,7 @@ public class VehicleService {
if
(!
bindFlag
)
{
if
(!
bindFlag
)
{
throw
new
AdminException
(
ResultEnum
.
UN_BIND_DEVICE
);
throw
new
AdminException
(
ResultEnum
.
UN_BIND_DEVICE
);
}
}
// 4. 现在绑定了 以前未绑定
}
else
if
(
StringUtils
.
isNotBlank
(
sn
)
&&
CollectionUtils
.
isEmpty
(
bindVehicleDevice
))
{
}
else
if
(
StringUtils
.
isNotBlank
(
sn
)
&&
CollectionUtils
.
isEmpty
(
bindVehicleDevice
))
{
//绑定
//绑定
vehicleDeviceService
.
saveSnToVehicleId
(
sn
,
Long
.
valueOf
(
driveVehicleoBo
.
getTempId
()));
vehicleDeviceService
.
saveSnToVehicleId
(
sn
,
Long
.
valueOf
(
driveVehicleoBo
.
getTempId
()));
...
@@ -359,7 +369,7 @@ public class VehicleService {
...
@@ -359,7 +369,7 @@ public class VehicleService {
String
sn
=
trackInfo
.
getSn
();
String
sn
=
trackInfo
.
getSn
();
// 查询设备是否存在
// 查询设备是否存在
if
(!
deviceService
.
checkSnExist
(
sn
))
{
if
(!
deviceService
.
checkSnExist
(
sn
))
{
count
+=
saveDevice
(
trackInfo
,
createId
);
count
+=
deviceService
.
saveTrackInfoBo
(
trackInfo
,
createId
);
}
else
{
}
else
{
log
.
info
(
"同步设备已存在,不保存。sn:"
+
sn
);
log
.
info
(
"同步设备已存在,不保存。sn:"
+
sn
);
}
}
...
@@ -457,24 +467,7 @@ public class VehicleService {
...
@@ -457,24 +467,7 @@ public class VehicleService {
return
vehicle
;
return
vehicle
;
}
}
/**
* 保存设备
* @param trackInfo
* @param createId
*/
public
int
saveDevice
(
TrackInfoBo
trackInfo
,
Long
createId
)
{
Device
device
=
new
Device
();
BeanUtils
.
copyProperties
(
trackInfo
,
device
);
// device.setName("");
device
.
setSim
(
trackInfo
.
getSimPhone
());
device
.
setManufacturer
(
trackInfo
.
getPartner
());
device
.
setActivateStatus
(
trackInfo
.
getIsActive
());
device
.
setActivateTime
(
trackInfo
.
getActiveDate
());
device
.
setCreatedBy
(
createId
);
device
.
setCreatedDate
(
new
Date
());
return
deviceService
.
insertDevice
(
device
);
}
/**
/**
* 检查该设备是否绑定 如果绑定 则解除绑定 重新绑定新车辆
* 检查该设备是否绑定 如果绑定 则解除绑定 重新绑定新车辆
...
...
src/main/java/cn/com/glsx/admin/modules/utils/Coder.java
0 → 100644
View file @
40d52e2
package
cn
.
com
.
glsx
.
admin
.
modules
.
utils
;
import
sun.misc.BASE64Decoder
;
import
sun.misc.BASE64Encoder
;
import
javax.crypto.KeyGenerator
;
import
javax.crypto.Mac
;
import
javax.crypto.SecretKey
;
import
javax.crypto.spec.SecretKeySpec
;
import
java.security.MessageDigest
;
public
class
Coder
{
public
static
final
String
KEY_SHA
=
"SHA"
;
public
static
final
String
KEY_MD5
=
"MD5"
;
/**
* MAC算法可选以下多种算法
*
* <pre>
* HmacMD5
* HmacSHA1
* HmacSHA256
* HmacSHA384
* HmacSHA512
* </pre>
*/
public
static
final
String
KEY_MAC
=
"HmacMD5"
;
/**
* BASE64解密
*
* @param key
* @return
* @throws Exception
*/
public
static
byte
[]
decryptBASE64
(
String
key
)
throws
Exception
{
return
(
new
BASE64Decoder
()).
decodeBuffer
(
key
);
}
/**
* BASE64加密
*
* @param key
* @return
* @throws Exception
*/
public
static
String
encryptBASE64
(
byte
[]
key
)
throws
Exception
{
return
(
new
BASE64Encoder
()).
encodeBuffer
(
key
);
}
/**
* MD5加密
*
* @param data
* @return
* @throws Exception
*/
public
static
byte
[]
encryptMD5
(
byte
[]
data
)
throws
Exception
{
MessageDigest
md5
=
MessageDigest
.
getInstance
(
KEY_MD5
);
md5
.
update
(
data
);
return
md5
.
digest
();
}
/**
* SHA加密
*
* @param data
* @return
* @throws Exception
*/
public
static
byte
[]
encryptSHA
(
byte
[]
data
)
throws
Exception
{
MessageDigest
sha
=
MessageDigest
.
getInstance
(
KEY_SHA
);
sha
.
update
(
data
);
return
sha
.
digest
();
}
/**
* 初始化HMAC密钥
*
* @return
* @throws Exception
*/
public
static
String
initMacKey
()
throws
Exception
{
KeyGenerator
keyGenerator
=
KeyGenerator
.
getInstance
(
KEY_MAC
);
SecretKey
secretKey
=
keyGenerator
.
generateKey
();
return
encryptBASE64
(
secretKey
.
getEncoded
());
}
/**
* HMAC加密
*
* @param data
* @param key
* @return
* @throws Exception
*/
public
static
byte
[]
encryptHMAC
(
byte
[]
data
,
String
key
)
throws
Exception
{
SecretKey
secretKey
=
new
SecretKeySpec
(
decryptBASE64
(
key
),
KEY_MAC
);
Mac
mac
=
Mac
.
getInstance
(
secretKey
.
getAlgorithm
());
mac
.
init
(
secretKey
);
return
mac
.
doFinal
(
data
);
}
}
src/main/java/cn/com/glsx/admin/modules/utils/GopUtil.java
0 → 100644
View file @
40d52e2
/**
* 版权声明:深圳市广联赛讯有限公司 版权所有 违者必究 2012
* 日 期:12-6-2
*/
package
cn
.
com
.
glsx
.
admin
.
modules
.
utils
;
import
java.io.UnsupportedEncodingException
;
import
java.nio.charset.StandardCharsets
;
import
java.util.*
;
/**
* <pre>
* 功能说明:
* </pre>
*
* @author 徐少敏
* @version 1.0
*/
public
class
GopUtil
{
/**
* 使用<code>secret</code>对paramValues按以下算法进行签名: <br/>
* uppercase(hex(sha1(secretkey1value1key2value2...secret))
*
* @param paramValues 参数列表
* @param secret
* @return
*/
public
static
String
sign
(
Map
<
String
,
Object
>
paramValues
,
String
secret
)
{
return
sign
(
paramValues
,
null
,
secret
);
}
/**
* 对paramValues进行签名,其中ignoreParamNames这些参数不参与签名
*
* @param paramValues
* @param ignoreParamNames
* @param secret
* @return
*/
public
static
String
sign
(
Map
<
String
,
Object
>
paramValues
,
List
<
String
>
ignoreParamNames
,
String
secret
)
{
StringBuilder
sb
=
new
StringBuilder
();
List
<
String
>
paramNames
=
new
ArrayList
<>(
paramValues
.
size
());
paramNames
.
addAll
(
paramValues
.
keySet
());
if
(
ignoreParamNames
!=
null
&&
ignoreParamNames
.
size
()
>
0
)
{
for
(
String
ignoreParamName
:
ignoreParamNames
)
{
paramNames
.
remove
(
ignoreParamName
);
}
}
Collections
.
sort
(
paramNames
);
sb
.
append
(
secret
);
for
(
String
paramName
:
paramNames
)
{
sb
.
append
(
paramName
).
append
(
paramValues
.
get
(
paramName
));
}
sb
.
append
(
secret
);
return
MD5Util
.
convert32
(
sb
.
toString
());
}
/**
* 参数md5加密
*
* @param params
* @return
*/
public
static
String
getParamsMD5Sign
(
Map
<
String
,
Object
>
params
)
{
StringBuffer
paramsStr
=
new
StringBuffer
();
for
(
Map
.
Entry
<
String
,
Object
>
param
:
params
.
entrySet
())
{
paramsStr
.
append
(
param
.
getKey
()).
append
(
param
.
getValue
());
}
return
MD5Util
.
encrypt
(
paramsStr
.
toString
()).
toUpperCase
();
}
public
static
String
utf8Encoding
(
String
value
,
String
sourceCharsetName
)
{
try
{
return
new
String
(
value
.
getBytes
(
sourceCharsetName
),
StandardCharsets
.
UTF_8
);
}
catch
(
UnsupportedEncodingException
e
)
{
throw
new
IllegalArgumentException
(
e
);
}
}
public
static
String
getUUID
()
{
UUID
uuid
=
UUID
.
randomUUID
();
return
uuid
.
toString
().
toUpperCase
();
}
public
static
void
main
(
String
[]
args
)
{
String
uuid
=
getUUID
();
System
.
out
.
println
(
uuid
.
replaceAll
(
"-"
,
""
));
}
}
src/main/java/cn/com/glsx/admin/modules/utils/MD5Util.java
0 → 100644
View file @
40d52e2
package
cn
.
com
.
glsx
.
admin
.
modules
.
utils
;
import
java.io.UnsupportedEncodingException
;
import
java.security.MessageDigest
;
import
java.security.NoSuchAlgorithmException
;
import
java.util.Map
;
public
class
MD5Util
{
private
static
final
String
hexDigits
[]
=
{
"0"
,
"1"
,
"2"
,
"3"
,
"4"
,
"5"
,
"6"
,
"7"
,
"8"
,
"9"
,
"a"
,
"b"
,
"c"
,
"d"
,
"e"
,
"f"
};
private
static
String
byteArrayToHexString
(
byte
b
[])
{
StringBuffer
resultSb
=
new
StringBuffer
();
for
(
int
i
=
0
;
i
<
b
.
length
;
i
++)
{
resultSb
.
append
(
byteToHexString
(
b
[
i
]));
}
return
resultSb
.
toString
();
}
private
static
String
byteToHexString
(
byte
b
)
{
int
n
=
b
;
if
(
n
<
0
)
n
+=
256
;
int
d1
=
n
/
16
;
int
d2
=
n
%
16
;
return
hexDigits
[
d1
]
+
hexDigits
[
d2
];
}
public
static
String
encode
(
String
origin
)
{
return
encode
(
origin
,
"UTF-8"
);
}
public
static
String
encode
(
String
origin
,
String
charsetname
)
{
String
resultString
=
null
;
try
{
resultString
=
new
String
(
origin
);
MessageDigest
md
=
MessageDigest
.
getInstance
(
"MD5"
);
if
(
charsetname
==
null
||
""
.
equals
(
charsetname
))
resultString
=
byteArrayToHexString
(
md
.
digest
(
resultString
.
getBytes
()));
else
resultString
=
byteArrayToHexString
(
md
.
digest
(
resultString
.
getBytes
(
charsetname
)));
}
catch
(
Exception
exception
)
{
}
return
resultString
;
}
/**
* md5加密方法
* @param str
* @return
*/
public
static
String
encrypt
(
String
str
)
{
try
{
byte
b
[]
=
Coder
.
encryptMD5
(
str
.
getBytes
(
"utf-8"
));
StringBuffer
buf
=
new
StringBuffer
();
String
stmp
=
""
;
for
(
int
n
=
0
;
n
<
b
.
length
;
n
++)
{
stmp
=
Integer
.
toHexString
(
b
[
n
]
&
0XFF
);
if
(
stmp
.
length
()
==
1
)
buf
.
append
(
"0"
).
append
(
stmp
);
else
buf
.
append
(
stmp
);
}
return
buf
.
toString
();
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
return
""
;
}
public
static
String
MD516
(
String
sourceStr
)
{
String
result
=
""
;
try
{
MessageDigest
md
=
MessageDigest
.
getInstance
(
"MD5"
);
try
{
md
.
update
(
sourceStr
.
getBytes
(
"GBK"
));
}
catch
(
UnsupportedEncodingException
e
)
{
// TODO Auto-generated catch block
e
.
printStackTrace
();
}
byte
b
[]
=
md
.
digest
();
int
i
;
StringBuffer
buf
=
new
StringBuffer
(
""
);
for
(
int
offset
=
0
;
offset
<
b
.
length
;
offset
++)
{
i
=
b
[
offset
];
if
(
i
<
0
)
i
+=
256
;
if
(
i
<
16
)
buf
.
append
(
"0"
);
buf
.
append
(
Integer
.
toHexString
(
i
));
}
result
=
buf
.
toString
();
result
=
result
.
toString
().
substring
(
8
,
24
);
}
catch
(
NoSuchAlgorithmException
e
)
{
System
.
out
.
println
(
e
);
}
return
result
;
}
/**
* 获取MD5加密的sign
*
* @param params
* @return
*/
public
static
String
getParamsMD5Sign
(
Map
<
Object
,
Object
>
params
)
{
StringBuffer
paramsStr
=
new
StringBuffer
();
for
(
Map
.
Entry
<
Object
,
Object
>
param
:
params
.
entrySet
())
{
paramsStr
.
append
(
param
.
getKey
()).
append
(
param
.
getValue
());
}
return
MD5Util
.
encrypt
(
paramsStr
.
toString
()).
toUpperCase
();
}
/**
* 32位MD5加密算法
* @param s
* @return
*/
public
static
String
convert32
(
String
s
){
char
hexChars
[]
=
{
'0'
,
'1'
,
'2'
,
'3'
,
'4'
,
'5'
,
'6'
,
'7'
,
'8'
,
'9'
,
'a'
,
'b'
,
'c'
,
'd'
,
'e'
,
'f'
};
try
{
byte
[]
bytes
=
s
.
getBytes
(
"UTF-8"
);
MessageDigest
md
=
MessageDigest
.
getInstance
(
"MD5"
);
md
.
update
(
bytes
);
bytes
=
md
.
digest
();
int
j
=
bytes
.
length
;
char
[]
chars
=
new
char
[
j
*
2
];
int
k
=
0
;
for
(
int
i
=
0
;
i
<
bytes
.
length
;
i
++)
{
byte
b
=
bytes
[
i
];
chars
[
k
++]
=
hexChars
[
b
>>>
4
&
0xf
];
chars
[
k
++]
=
hexChars
[
b
&
0xf
];
}
return
new
String
(
chars
);
}
catch
(
Exception
e
){
return
null
;
}
}
/**
* 16位MD5加密算法
* @param s
* @return
*/
public
static
String
convert16
(
String
s
){
char
hexChars
[]
=
{
'0'
,
'1'
,
'2'
,
'3'
,
'4'
,
'5'
,
'6'
,
'7'
,
'8'
,
'9'
,
'a'
,
'b'
,
'c'
,
'd'
,
'e'
,
'f'
};
try
{
byte
[]
bytes
=
s
.
getBytes
();
MessageDigest
md
=
MessageDigest
.
getInstance
(
"MD5"
);
md
.
update
(
bytes
);
bytes
=
md
.
digest
();
int
j
=
bytes
.
length
;
char
[]
chars
=
new
char
[
j
*
2
];
int
k
=
0
;
for
(
int
i
=
0
;
i
<
bytes
.
length
;
i
++)
{
byte
b
=
bytes
[
i
];
chars
[
k
++]
=
hexChars
[
b
>>>
4
&
0xf
];
chars
[
k
++]
=
hexChars
[
b
&
0xf
];
}
return
new
String
(
chars
).
substring
(
8
,
24
);
}
catch
(
Exception
e
){
return
null
;
}
}
}
src/test/java/cn/com/glsx/admin/modules/service/DeviceServiceTest.java
0 → 100644
View file @
40d52e2
package
cn
.
com
.
glsx
.
admin
.
modules
.
service
;
import
cn.com.glsx.Application
;
import
cn.com.glsx.admin.modules.model.param.TrackInfoBo
;
import
lombok.extern.slf4j.Slf4j
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.test.context.SpringBootTest
;
import
org.springframework.test.context.junit4.SpringRunner
;
@Slf4j
@RunWith
(
SpringRunner
.
class
)
@SpringBootTest
(
classes
=
Application
.
class
,
webEnvironment
=
SpringBootTest
.
WebEnvironment
.
RANDOM_PORT
)
public
class
DeviceServiceTest
{
@Autowired
private
DeviceService
deviceService
;
@Test
public
void
testRemoteGetDeviceBySnAndSave
()
{
TrackInfoBo
trackInfoBo
=
deviceService
.
remoteGetDeviceBySn
(
"8130902002"
);
log
.
info
(
trackInfoBo
.
toString
());
deviceService
.
saveTrackInfoBo
(
trackInfoBo
,
10001L
);
}
}
src/test/java/cn/com/glsx/admin/modules/service/VehicleServiceTest.java
View file @
40d52e2
...
@@ -194,19 +194,16 @@ public class VehicleServiceTest {
...
@@ -194,19 +194,16 @@ public class VehicleServiceTest {
bo
.
setClassId
(
7394
);
bo
.
setClassId
(
7394
);
bo
.
setActiveTime
(
"2021-06-01"
);
bo
.
setActiveTime
(
"2021-06-01"
);
bo
.
setChanle
(
"edun_timed_task"
);
bo
.
setChanle
(
"edun_timed_task"
);
bo
.
setVin
(
"wavxc12345678abc
d
"
);
bo
.
setVin
(
"wavxc12345678abc
e
"
);
List
<
TrackInfoBo
>
trackInfoList
=
new
ArrayList
<>();
List
<
TrackInfoBo
>
trackInfoList
=
new
ArrayList
<>();
TrackInfoBo
trackInfoBo
=
new
TrackInfoBo
();
TrackInfoBo
trackInfoBo
=
new
TrackInfoBo
();
trackInfoBo
.
setSn
(
"2223333
4
"
);
trackInfoBo
.
setSn
(
"2223333
5
"
);
trackInfoBo
.
setCheckCode
(
"666666
4
"
);
trackInfoBo
.
setCheckCode
(
"666666
5
"
);
trackInfoBo
.
setIccid
(
"111109876
4
"
);
trackInfoBo
.
setIccid
(
"111109876
5
"
);
trackInfoBo
.
setImsi
(
"2190833
4
"
);
trackInfoBo
.
setImsi
(
"2190833
5
"
);
trackInfoList
.
add
(
trackInfoBo
);
trackInfoList
.
add
(
trackInfoBo
);
bo
.
setTrackInfoList
(
trackInfoList
);
bo
.
setTrackInfoList
(
trackInfoList
);
vehicleService
.
syncVehicleDeviceLinkFence
(
bo
);
vehicleService
.
syncVehicleDeviceLinkFence
(
bo
);
}
}
}
}
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