Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
open-source
/
chejia-smart-service
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 fc1a08ef
authored
May 08, 2021
by
fz
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
代码规范整理
1.代码警告处理 2.整理车钥匙加密工具类,添加单元测试
1 parent
4903a55a
Hide whitespace changes
Inline
Side-by-side
Showing
18 changed files
with
235 additions
and
320 deletions
src/main/java/cn/com/glsx/SmartServiceApplication.java
src/main/java/cn/com/glsx/smart/common/exception/ChejiaBusinessException.java
src/main/java/cn/com/glsx/smart/common/utils/AesEncryptUtils.java
src/main/java/cn/com/glsx/smart/common/utils/JwtUtil.java
src/main/java/cn/com/glsx/smart/common/utils/SnowflakeWorker.java
src/main/java/cn/com/glsx/smart/config/KafkaProducerConfig.java
src/main/java/cn/com/glsx/smart/config/SnowFlakeWorkerConfig.java
src/main/java/cn/com/glsx/smart/modules/controller/AiLockingkeyController.java
src/main/java/cn/com/glsx/smart/modules/controller/AiLockingkeyShareController.java
src/main/java/cn/com/glsx/smart/modules/controller/ConditionController.java
src/main/java/cn/com/glsx/smart/modules/controller/ContentController.java
src/main/java/cn/com/glsx/smart/modules/controller/ProductController.java
src/main/java/cn/com/glsx/smart/modules/controller/ProductTypeController.java
src/main/java/cn/com/glsx/smart/modules/controller/SysCodeController.java
src/main/java/cn/com/glsx/smart/modules/controller/SysFileController.java
src/main/java/cn/com/glsx/smart/modules/controller/UserDeviceController.java
src/main/java/cn/com/glsx/smart/modules/service/impl/AiLockingKeyServiceImpl.java
src/test/java/com/glsx/smart/service/TestAesEncryptUtils.java
src/main/java/cn/com/glsx/SmartServiceApplication.java
View file @
fc1a08e
...
...
@@ -26,7 +26,6 @@ import tk.mybatis.spring.annotation.MapperScan;
@EnableDiscoveryClient
@EnableTransactionManagement
@ServletComponentScan
// 使用通用 Mapper 的注解
@MapperScan
(
basePackages
={
"cn.com.glsx.smart.modules.mapper"
})
public
class
SmartServiceApplication
extends
SpringBootServletInitializer
{
/**
...
...
src/main/java/cn/com/glsx/smart/common/exception/ChejiaBusinessException.java
View file @
fc1a08e
...
...
@@ -7,7 +7,7 @@ import com.glsx.plat.exception.BusinessException;
* <p>Project: chejia-smart
*
* @author wbh
* @
d
ate 2021-03-16
* @
D
ate 2021-03-16
*/
public
class
ChejiaBusinessException
extends
BusinessException
{
private
ChejiaBusinessException
(
int
code
,
String
message
)
{
...
...
src/main/java/cn/com/glsx/smart/common/utils/AesEncryptUtils.java
View file @
fc1a08e
...
...
@@ -7,41 +7,46 @@ import org.springframework.stereotype.Component;
import
javax.crypto.Cipher
;
import
javax.crypto.KeyGenerator
;
import
javax.crypto.spec.SecretKeySpec
;
import
java.io.UnsupportedEncodingException
;
import
java.math.BigInteger
;
import
java.security.SecureRandom
;
import
java.text.SimpleDateFormat
;
import
java.util.Date
;
import
java.util.Random
;
import
java.nio.charset.StandardCharsets
;
/**
* @author fengzhi
* @version V1.0
* @Description: AES加密工具类
*/
@Component
public
class
AesEncryptUtils
{
//可配置到Constant中,并读取配置文件注入,16位,自己定义
/**
* crep的解密key
* 可配置到Constant中,并读取配置文件注入,16位
*/
@Value
(
"${aesencrypt.key}"
)
private
String
KEY
;
//参数分别代表 算法名称/加密模式/数据填充方式
/**
* 参数分别代表
* 算法名称/加密模式/数据填充方式
*/
@Value
(
"${aesencrypt.algorithmstr}"
)
private
String
ALGORITHMSTR
;
//参数分别代表 算法名称/加密模式/数据填充方式
/**
* secretKey的解密key
*/
@Value
(
"${aesencrypt.secret.key}"
)
private
String
secretKey
;
private
String
SECRET_KEY
;
/**
* 加密
*
* @param content 加密的字符串
* @param encryptKey key值
* @return
* @throws Exception
* @param encryptKey 加密的key值
*/
public
String
encrypt
(
String
content
,
String
encryptKey
)
throws
Exception
{
KeyGenerator
kgen
=
KeyGenerator
.
getInstance
(
"AES"
);
kgen
.
init
(
128
);
Cipher
cipher
=
Cipher
.
getInstance
(
ALGORITHMSTR
);
cipher
.
init
(
Cipher
.
ENCRYPT_MODE
,
new
SecretKeySpec
(
encryptKey
.
getBytes
(),
"AES"
));
byte
[]
b
=
cipher
.
doFinal
(
content
.
getBytes
(
"utf-8"
));
byte
[]
b
=
cipher
.
doFinal
(
content
.
getBytes
(
StandardCharsets
.
UTF_8
));
// 采用base64算法进行转码,避免出现中文乱码
return
Base64
.
encodeBase64String
(
b
);
...
...
@@ -52,8 +57,6 @@ public class AesEncryptUtils {
*
* @param encryptStr 解密的字符串
* @param decryptKey 解密的key值
* @return
* @throws Exception
*/
public
String
decrypt
(
String
encryptStr
,
String
decryptKey
)
throws
Exception
{
KeyGenerator
kgen
=
KeyGenerator
.
getInstance
(
"AES"
);
...
...
@@ -66,184 +69,35 @@ public class AesEncryptUtils {
return
new
String
(
decryptBytes
);
}
/**
* 加密crep
* @param content 明文
*/
public
String
encrypt
(
String
content
)
throws
Exception
{
return
encrypt
(
content
,
KEY
);
}
/**
* 解密crep
* @param encryptStr 密文
*/
public
String
decrypt
(
String
encryptStr
)
throws
Exception
{
return
decrypt
(
encryptStr
,
KEY
);
}
public
String
encryptSecret
(
String
content
)
throws
Exception
{
return
encrypt
(
content
,
secretKey
);
}
public
String
decryptSecret
(
String
encryptStr
)
throws
Exception
{
return
decrypt
(
encryptStr
,
secretKey
);
}
public
static
void
main
(
String
[]
args
)
throws
Exception
{
//Map map = new HashMap<String, String>();
//map.put("key", "value");
//map.put("中文", "汉字");
//String content = JSONObject.toJSONString(map);
//System.out.println("加密前:" + content);
//
String
encrypt
=
encrypt1
(
"370342948446986240110"
,
"0BDsQu0naQF9BYGr"
);
System
.
out
.
println
(
"加密后1:"
+
encrypt
);
//
String
decrypt
=
decrypt1
(
"tZvuOJsVI6B8x5Yx3CBOH2MZn/3YhKbUtiVlkP9c+iU="
,
"0BDsQu0naQF9BYGr"
);
System
.
out
.
println
(
"解密后1:"
+
decrypt
);
String
encrypt2
=
encrypt1
(
"37061517396835532890027292"
,
"tHS9rKB161Oh9Idj"
);
System
.
out
.
println
(
"加密后:"
+
encrypt
);
////
String
decrypt2
=
decrypt1
(
"pZz3WfhsWOJSxpky6q8r84EHTSL/rmlkHhcNeWR9bys="
,
"tHS9rKB161Oh9Idj"
);
System
.
out
.
println
(
"解密后2:"
+
decrypt
);
//
//获取16位随机密钥
String
secret
=
getGUID
();
System
.
out
.
println
(
"生成key:"
+
secret
);
String
beginTime
=
new
String
(
"10:22"
);
String
endTime
=
new
String
(
"10:22"
);
//1 直接用Date自带方法before()和after()比较
SimpleDateFormat
df
=
new
SimpleDateFormat
(
"HH:mm"
);
Date
sd1
=
df
.
parse
(
beginTime
);
Date
sd2
=
df
.
parse
(
endTime
);
System
.
out
.
println
(
sd1
.
before
(
sd2
));
System
.
out
.
println
(
sd1
.
after
(
sd2
));
// 2 用String的compareTo()方法:
Integer
i
=
beginTime
.
compareTo
(
endTime
);
System
.
out
.
println
(
i
);
//返回正值是代表左侧日期大于参数日期,反之亦然,日期格式必须一致
// 3 转成date格式换成秒数比较秒数大小,getTime()方法
Date
sd3
=
df
.
parse
(
beginTime
);
Date
sd4
=
df
.
parse
(
endTime
);
long
long1
=
sd1
.
getTime
();
long
long2
=
sd2
.
getTime
();
System
.
out
.
println
(
long1
);
System
.
out
.
println
(
long2
);
SnowflakeWorker
worker
=
new
SnowflakeWorker
(
1
,
1
);
String
id
=
worker
.
nextId
()+
""
;
String
result
=
id
.
substring
(
id
.
length
()-
16
,
id
.
length
());
System
.
out
.
println
(
"nextid:"
+
id
+
"===res:"
+
result
);
}
public
static
String
decrypt1
(
String
encryptStr
,
String
decryptKey
)
throws
Exception
{
KeyGenerator
kgen
=
KeyGenerator
.
getInstance
(
"AES"
);
kgen
.
init
(
128
);
Cipher
cipher
=
Cipher
.
getInstance
(
"AES/ECB/PKCS5Padding"
);
cipher
.
init
(
Cipher
.
DECRYPT_MODE
,
new
SecretKeySpec
(
decryptKey
.
getBytes
(),
"AES"
));
// 采用base64算法进行转码,避免出现中文乱码
byte
[]
encryptBytes
=
Base64
.
decodeBase64
(
encryptStr
);
byte
[]
decryptBytes
=
cipher
.
doFinal
(
encryptBytes
);
return
new
String
(
decryptBytes
);
}
/**
*
生成16位不重复的随机数,含数字+大小写
* @
return
*
加密secretKey
* @
param content 明文
*/
public
static
String
getGUID
()
{
StringBuilder
uid
=
new
StringBuilder
();
//产生16位的强随机数
Random
rd
=
new
SecureRandom
();
for
(
int
i
=
0
;
i
<
16
;
i
++)
{
//产生0-2的3位随机数
int
type
=
rd
.
nextInt
(
3
);
switch
(
type
){
case
0
:
//0-9的随机数
uid
.
append
(
rd
.
nextInt
(
10
));
/*int random = ThreadLocalRandom.current().ints(0, 10)
.distinct().limit(1).findFirst().getAsInt();*/
break
;
case
1
:
//ASCII在65-90之间为大写,获取大写随机
uid
.
append
((
char
)(
rd
.
nextInt
(
25
)+
65
));
break
;
case
2
:
//ASCII在97-122之间为小写,获取小写随机
uid
.
append
((
char
)(
rd
.
nextInt
(
25
)+
97
));
break
;
default
:
break
;
}
}
return
uid
.
toString
();
}
public
static
String
encrypt1
(
String
content
,
String
encryptKey
)
throws
Exception
{
KeyGenerator
kgen
=
KeyGenerator
.
getInstance
(
"AES"
);
kgen
.
init
(
128
);
Cipher
cipher
=
Cipher
.
getInstance
(
"AES/ECB/PKCS5Padding"
);
cipher
.
init
(
Cipher
.
ENCRYPT_MODE
,
new
SecretKeySpec
(
encryptKey
.
getBytes
(),
"AES"
));
byte
[]
b
=
cipher
.
doFinal
(
content
.
getBytes
(
"utf-8"
));
// 采用base64算法进行转码,避免出现中文乱码
return
Base64
.
encodeBase64String
(
b
);
public
String
encryptSecret
(
String
content
)
throws
Exception
{
return
encrypt
(
content
,
SECRET_KEY
);
}
/**
* 计算中英文字符串的字节长度 <br/>
* 一个中文占3个字节
*
* @param str
* @return int 字符串的字节长度
* 解密secretKey
* @param encryptStr 密文
*/
public
static
int
getLength
(
String
str
)
{
if
(
str
==
null
||
str
.
length
()
==
0
)
{
return
0
;
}
try
{
return
str
.
getBytes
(
"UTF-8"
).
length
;
}
catch
(
UnsupportedEncodingException
e
)
{
//logger.error("计算中英文字符串的字节长度失败,", e);
}
return
0
;
}
//將10進制轉換為16進制
public
static
String
encodeHEX
(
Integer
numb
){
String
hex
=
Integer
.
toHexString
(
numb
);
return
hex
;
}
//將16進制字符串轉換為10進制數字
public
static
int
decodeHEX
(
String
hexs
){
BigInteger
bigint
=
new
BigInteger
(
hexs
,
16
);
int
numb
=
bigint
.
intValue
();
return
numb
;
public
String
decryptSecret
(
String
encryptStr
)
throws
Exception
{
return
decrypt
(
encryptStr
,
SECRET_KEY
);
}
}
src/main/java/cn/com/glsx/smart/common/utils/JwtUtil.java
View file @
fc1a08e
...
...
@@ -7,91 +7,40 @@ import lombok.extern.slf4j.Slf4j;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Component
;
import
java.util.Date
;
import
java.util.Map
;
/**
* @Description: Jwt工具类
* @author fengzhi
* @version V1.0
* @Description: Jwt令牌工具类
*/
@Slf4j
@Component
public
class
JwtUtil
{
//令牌加密key
/**
* 令牌加密key
*/
@Value
(
"${jwt.secret}"
)
private
String
KEY
=
"123456"
;
//令牌默认超时时间
@Value
(
"${jwt.expiration}"
)
private
String
EXPIRATION
;
private
String
KEY
;
/**
*
根据负责生成JWT的token
*
生成JWT令牌
*/
public
String
generateToken
(
Map
<
String
,
Object
>
claims
)
{
return
Jwts
.
builder
()
.
setClaims
(
claims
)
.
signWith
(
SignatureAlgorithm
.
HS256
,
KEY
)
.
compact
();
}
public
String
generateToken
(
Map
<
String
,
Object
>
claims
,
long
expireTime
)
{
return
Jwts
.
builder
()
.
setClaims
(
claims
)
.
setExpiration
(
generateExpirationDate
(
expireTime
))
.
signWith
(
SignatureAlgorithm
.
HS256
,
KEY
)
.
signWith
(
SignatureAlgorithm
.
HS256
,
KEY
)
.
compact
();
}
/**
*
从token中获取JWT中的负载
*
解析JWT令牌
*/
public
Claims
getClaimsFromToken
(
String
token
)
{
Claims
claims
=
null
;
claims
=
Jwts
.
parser
()
return
Jwts
.
parser
()
.
setSigningKey
(
KEY
)
.
parseClaimsJws
(
token
)
.
getBody
();
return
claims
;
}
/**
* 生成token的过期时间
*/
public
Date
generateExpirationDate
(
long
expireTime
)
{
return
new
Date
(
System
.
currentTimeMillis
()
+
expireTime
*
1000
);
}
/**
* 判断token是否已经失效
*/
public
boolean
isTokenExpired
(
String
token
)
{
Date
expiredDate
=
getExpiredDateFromToken
(
token
);
return
expiredDate
.
before
(
new
Date
());
}
/**
* 从token中获取过期时间
*/
public
Date
getExpiredDateFromToken
(
String
token
)
{
Claims
claims
=
getClaimsFromToken
(
token
);
return
claims
.
getExpiration
();
}
/**
* 判断token是否可以被刷新
*/
//public boolean canRefresh(String token) {
// return !isTokenExpired(token);
//}
/**
* 刷新token
*/
//public String refreshToken(String token) {
// Claims claims = getClaimsFromToken(token);
// claims.put("created", new Date());
// return generateToken(claims);
//}
}
src/main/java/cn/com/glsx/smart/common/utils/SnowflakeWorker.java
View file @
fc1a08e
...
...
@@ -8,26 +8,10 @@ package cn.com.glsx.smart.common.utils;
* @Version V1.0
*/
public
class
SnowflakeWorker
{
/** 时间节点,算法从2018/5/21 11:26:52这个时间点开始,可以保证69年不重复。*/
private
final
long
epoch
=
1526873212000L
;
/** 机器id所占的位数 */
private
final
long
workerIdBits
=
5L
;
/** 支持的最大机器id,结果是31 (这个移位算法可以很快的计算出几位二进制数所能表示的最大十进制数) */
private
long
maxWorkerId
=
-
1L
^
(-
1L
<<
workerIdBits
);
/** 数据中心标识id所占的位数 */
private
final
long
dataCenterIdBits
=
5L
;
/** 支持的最大数据中心标识id,结果是31 */
private
final
long
maxDataCenterId
=
-
1L
^
(-
1L
<<
dataCenterIdBits
);
/** 序列在id中占的位数 */
private
final
long
sequenceBits
=
12L
;
/** 机器ID向左移12位 */
private
final
long
workerIdShift
=
sequenceBits
;
/** 数据标识中心id向左移17位(12+5) */
private
final
long
dataCenterIdShift
=
sequenceBits
+
workerIdBits
;
/** 时间截向左移22位(5+5+12) */
private
final
long
timestampLeftShift
=
sequenceBits
+
workerIdBits
+
dataCenterIdBits
;
/** 生成序列的掩码,这里为4095 (0b111111111111=0xfff=4095) */
private
final
long
sequenceMask
=
-
1L
^
(-
1L
<<
sequenceBits
);
/** 工作机器ID(0~31)*/
private
long
workerId
;
/** 数据中心ID(0~31) */
...
...
@@ -42,9 +26,13 @@ public class SnowflakeWorker {
* @param dataCenterId 数据中心ID (0~31)
*/
public
SnowflakeWorker
(
long
workerId
,
long
dataCenterId
)
{
//支持的最大机器id,结果是31 (这个移位算法可以很快的计算出几位二进制数所能表示的最大十进制数)
long
maxWorkerId
=
~(-
1L
<<
workerIdBits
);
if
(
workerId
>
maxWorkerId
||
workerId
<
0
)
{
throw
new
IllegalArgumentException
(
String
.
format
(
"worker Id can't be greater than %d or less than 0"
,
maxWorkerId
));
}
//支持的最大数据中心标识id,结果是31
long
maxDataCenterId
=
~(-
1L
<<
dataCenterIdBits
);
if
(
dataCenterId
>
maxDataCenterId
||
dataCenterId
<
0
)
{
throw
new
IllegalArgumentException
(
String
.
format
(
"dataCenter Id can't be greater than %d or less than 0"
,
maxDataCenterId
));
}
...
...
@@ -64,7 +52,11 @@ public class SnowflakeWorker {
String
.
format
(
"Clock moved backwards. Refusing to generate id for %d milliseconds"
,
lastTimestamp
-
timestamp
));
}
//如果是同一时间生成的,则进行毫秒内序列
//序列在id中占的位数
long
sequenceBits
=
12L
;
if
(
lastTimestamp
==
timestamp
)
{
// 生成序列的掩码,这里为4095 (0b111111111111=0xfff=4095)
long
sequenceMask
=
~(-
1L
<<
sequenceBits
);
sequence
=
(
sequence
+
1
)
&
sequenceMask
;
//毫秒内序列溢出
if
(
sequence
==
0
)
{
...
...
@@ -77,9 +69,16 @@ public class SnowflakeWorker {
//上次生成ID的时间截
lastTimestamp
=
timestamp
;
//移位并通过或运算拼到一起组成64位的ID
// 时间节点,算法从2018/5/21 11:26:52这个时间点开始,可以保证69年不重复。
long
epoch
=
1526873212000L
;
// 时间截向左移22位(5+5+12)
long
timestampLeftShift
=
sequenceBits
+
workerIdBits
+
dataCenterIdBits
;
// 数据标识中心id向左移17位(12+5)
long
dataCenterIdShift
=
sequenceBits
+
workerIdBits
;
// 机器ID向左移12位
return
((
timestamp
-
epoch
)
<<
timestampLeftShift
)
|
(
dataCenterId
<<
dataCenterIdShift
)
|
(
workerId
<<
workerIdShift
)
|
(
workerId
<<
sequenceBits
)
|
sequence
;
}
...
...
@@ -113,7 +112,7 @@ public class SnowflakeWorker {
System.out.println(id);
}*/
long
x
=
-
1L
^
(-
1L
<<
63
);
long
x
=
~
(-
1L
<<
63
);
System
.
out
.
println
(
x
);
System
.
out
.
println
(
Long
.
MAX_VALUE
);
}
...
...
src/main/java/cn/com/glsx/smart/config/KafkaProducerConfig.java
View file @
fc1a08e
...
...
@@ -19,7 +19,6 @@ import java.util.Properties;
@Slf4j
@Configuration
public
class
KafkaProducerConfig
{
@Autowired
private
KafkaProperties
kafkaConfig
;
...
...
src/main/java/cn/com/glsx/smart/config/SnowFlakeWorkerConfig.java
View file @
fc1a08e
...
...
@@ -24,8 +24,6 @@ public class SnowFlakeWorkerConfig {
public
SnowflakeWorker
getSnowFlakeWorker
()
{
String
workerId
=
snowFlakeConfig
.
getWorkerId
();
String
datacenterId
=
snowFlakeConfig
.
getDatacenterId
();
log
.
info
(
"SnowWorkerConfig====workerId:"
+
workerId
+
"====datacenterId:"
+
datacenterId
);
SnowflakeWorker
worker
=
new
SnowflakeWorker
(
Long
.
valueOf
(
workerId
),
Long
.
valueOf
(
datacenterId
));
return
worker
;
return
new
SnowflakeWorker
(
Long
.
parseLong
(
workerId
),
Long
.
parseLong
(
datacenterId
));
}
}
src/main/java/cn/com/glsx/smart/modules/controller/AiLockingkeyController.java
View file @
fc1a08e
...
...
@@ -9,11 +9,11 @@ import org.springframework.beans.factory.annotation.Autowired;
import
org.springframework.web.bind.annotation.*
;
/**
* @Title: ConditionController.java
* @Description: 提供给gop-accounts(车钥匙app)使用的接口
* @author fengzhi
* @version V1.0
*/
//TODO 处理service层不要返回R
@Slf4j
@RestController
@RequestMapping
(
"/lockingKey"
)
...
...
@@ -24,28 +24,35 @@ public class AiLockingkeyController {
@Autowired
private
AiLockingKeyShareService
aiLockingKeyShareService
;
/************************分享车钥匙相关接口************************/
//主车钥匙修改分享状态
/**
* 主车钥匙修改分享状态
*/
@PostMapping
(
value
=
"/setPrimaryShareStatus"
)
public
R
setPrimaryLockingKeyShareStatus
(
@RequestBody
SmartKeyPrimaryShareEditReq
request
)
{
return
aiLockingKeyService
.
setPrimaryLockingKeyShareStatus
(
request
);
}
//车钥匙分享令牌获取
/**
* 车钥匙分享令牌获取
*/
@GetMapping
(
value
=
"/getShareToken"
)
public
R
getShareToken
(
SmartCarKeyTokenRequest
request
)
{
return
aiLockingKeyService
.
getShareToken
(
request
);
}
//智能车钥匙共享列表获取
/**
* 智能车钥匙共享列表获取
*/
@GetMapping
(
value
=
"/getShareKeyList"
)
public
R
getShareKeyList
(
SmartShareCarKeyPageRequest
request
)
{
return
aiLockingKeyService
.
getShareKeyList
(
request
);
}
//分享车钥匙设置修改分享状态
/**
* 分享车钥匙设置修改分享状态
*/
@PostMapping
(
value
=
"/setShareStatus"
)
public
R
setShareLockingKeyShareStatus
(
@RequestBody
SmartShareKeyEditReq
request
)
{
return
aiLockingKeyShareService
.
removeShareKey
(
request
);
...
...
@@ -53,61 +60,81 @@ public class AiLockingkeyController {
/************************车钥匙相关接口************************/
//sn查询/新增车钥匙
/**
* sn查询/新增车钥匙
*/
@GetMapping
(
value
=
"/get"
)
public
R
getLockingKey
(
SmartCarKeyRequest
request
)
{
return
aiLockingKeyService
.
getLockingKey
(
request
);
}
//sn查询车钥匙蓝牙地址
/**
* sn查询车钥匙蓝牙地址
*/
@GetMapping
(
value
=
"/bluemac/get"
)
public
R
getMobileBlueMac
(
SmartCarKeyRequest
request
)
{
return
aiLockingKeyService
.
getMobileBlueMac
(
request
);
}
//userId查询车钥匙
/**
* userId查询车钥匙
*/
@GetMapping
(
value
=
"/user/getAll"
)
public
R
getAllKeyByUser
(
SmartCarKeyUserRequest
request
)
{
return
aiLockingKeyService
.
getAllKeyByUser
(
request
);
}
//智能车钥匙解绑
/**
* 智能车钥匙解绑
*/
@PostMapping
(
value
=
"/remove"
)
public
R
removeLockingKey
(
@RequestBody
SmartCarKeyRequest
request
)
{
return
aiLockingKeyService
.
removeLockingKey
(
request
);
}
//智能车钥匙注册成功后的数据保存
/**
* 智能车钥匙注册成功后的数据保存
*/
@PostMapping
(
value
=
"/saveRegisterInfo"
)
public
R
saveLockingKeyRegisterInfo
(
@RequestBody
SmartCarKeyRegisterRequest
request
)
{
return
aiLockingKeyService
.
saveLockingKeyRegisterInfo
(
request
);
}
//根据userid注销钥匙
/**
* 根据userid注销钥匙
*/
@PostMapping
(
value
=
"/removeKeysByUser"
)
public
R
removeKeysByUser
(
@RequestBody
SmartCarKeyUserRequest
request
)
{
return
aiLockingKeyService
.
removeKeysByUser
(
request
);
}
//车钥匙操作指令上报
/**
* 车钥匙操作指令上报
*/
@PostMapping
(
value
=
"/logCommand"
)
public
R
LogLockingKeyCommand
(
@RequestBody
SmartCarKeyCommandRequest
request
)
{
return
aiLockingKeyService
.
LogLockingKeyCommand
(
request
);
}
//车钥匙操作指令批量上报
/**
* 车钥匙操作指令批量上报
*/
@PostMapping
(
value
=
"/batchLogCommand"
)
public
R
batchLogCommand
(
@RequestBody
SmartCarKeyActionLogBatchRequest
request
)
{
return
aiLockingKeyService
.
batchLogCommand
(
request
);
}
//车钥匙修改昵称
/**
* 车钥匙修改昵称
*/
@PostMapping
(
value
=
"/setName"
)
public
R
setLockingKeyName
(
@RequestBody
SmartCarKeyNameRequest
request
)
{
return
aiLockingKeyService
.
setLockingKeyName
(
request
);
}
//车钥匙修改自动感应
/**
* 车钥匙修改自动感应
*/
@PostMapping
(
value
=
"/setAutoSense"
)
public
R
setLockingKeyAutoSense
(
@RequestBody
SmartCarKeyAutoSenseRequest
request
)
{
return
aiLockingKeyService
.
setLockingKeyAutoSense
(
request
);
...
...
src/main/java/cn/com/glsx/smart/modules/controller/AiLockingkeyShareController.java
View file @
fc1a08e
...
...
@@ -10,6 +10,13 @@ import lombok.extern.slf4j.Slf4j;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.*
;
/**
* @Description: 提供给rop-accounts(车钥匙小程序)使用的接口
* @author fengzhi
* @version V1.0
*/
//TODO 处理service层不要返回R
@Slf4j
@RestController
@RequestMapping
(
"/share/lockingKey"
)
...
...
src/main/java/cn/com/glsx/smart/modules/controller/ConditionController.java
View file @
fc1a08e
...
...
@@ -11,7 +11,7 @@ import java.util.List;
/**
* @Title: ConditionController.java
* @Description:获取场景指令触发条件
* @Description:
获取场景指令触发条件
* @author think.wang
* @version V1.0
* @Company: Didihu.com.cn
...
...
src/main/java/cn/com/glsx/smart/modules/controller/ContentController.java
View file @
fc1a08e
...
...
@@ -11,7 +11,7 @@ import java.util.List;
/**
* @Title: ContentController.java
* @Description:获取场景指令执行内容
* @Description:
获取场景指令执行内容
* @author think.wang
* @version V1.0
* @Company: Didihu.com.cn
...
...
src/main/java/cn/com/glsx/smart/modules/controller/ProductController.java
View file @
fc1a08e
package
cn
.
com
.
glsx
.
smart
.
modules
.
controller
;
import
java.util.List
;
import
cn.com.glsx.smart.modules.entity.SmartDeviceOrder
;
import
cn.com.glsx.smart.modules.entity.SmartProduct
;
import
cn.com.glsx.smart.modules.service.SmartProductService
;
...
...
@@ -10,11 +9,9 @@ import com.github.pagehelper.PageInfo;
import
com.glsx.plat.core.web.R
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.bind.annotation.*
;
import
java.util.List
;
/**
* <p>Description: 产品列表业务
...
...
src/main/java/cn/com/glsx/smart/modules/controller/ProductTypeController.java
View file @
fc1a08e
package
cn
.
com
.
glsx
.
smart
.
modules
.
controller
;
import
java.util.List
;
import
cn.com.glsx.smart.modules.entity.SmartProductType
;
import
cn.com.glsx.smart.modules.service.SmartProductTypeService
;
import
com.alibaba.fastjson.JSON
;
...
...
@@ -8,11 +7,9 @@ import com.github.pagehelper.PageInfo;
import
com.glsx.plat.core.web.R
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.bind.annotation.*
;
import
java.util.List
;
/**
* <p>Description: 产品类型业务
...
...
src/main/java/cn/com/glsx/smart/modules/controller/SysCodeController.java
View file @
fc1a08e
package
cn
.
com
.
glsx
.
smart
.
modules
.
controller
;
import
java.util.List
;
import
cn.com.glsx.smart.common.exception.ChejiaBusinessException
;
import
cn.com.glsx.smart.common.exception.ResultEnum
;
import
cn.com.glsx.smart.modules.entity.SmartSysCode
;
...
...
@@ -10,11 +9,7 @@ import com.glsx.plat.common.utils.StringUtils;
import
com.glsx.plat.core.web.R
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.bind.annotation.*
;
import
java.util.List
;
...
...
src/main/java/cn/com/glsx/smart/modules/controller/SysFileController.java
View file @
fc1a08e
package
cn
.
com
.
glsx
.
smart
.
modules
.
controller
;
import
java.util.List
;
import
java.util.Map
;
import
cn.com.glsx.smart.modules.model.FileDTO
;
import
cn.com.glsx.smart.modules.service.SmartSysFileService
;
import
com.glsx.plat.core.web.R
;
...
...
@@ -9,12 +7,10 @@ import io.swagger.annotations.Api;
import
io.swagger.annotations.ApiOperation
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.bind.annotation.*
;
import
java.util.List
;
import
java.util.Map
;
/**
* <p>Description:
...
...
src/main/java/cn/com/glsx/smart/modules/controller/UserDeviceController.java
View file @
fc1a08e
...
...
@@ -10,12 +10,7 @@ import com.glsx.plat.common.utils.StringUtils;
import
com.glsx.plat.core.web.R
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.bind.annotation.*
;
import
java.util.List
;
...
...
src/main/java/cn/com/glsx/smart/modules/service/impl/AiLockingKeyServiceImpl.java
View file @
fc1a08e
...
...
@@ -16,7 +16,6 @@ import com.alibaba.nacos.common.utils.StringUtils;
import
com.github.pagehelper.PageHelper
;
import
com.github.pagehelper.PageInfo
;
import
com.glsx.plat.core.web.R
;
import
com.glsx.plat.exception.BusinessException
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang.text.StrBuilder
;
import
org.springframework.beans.BeanUtils
;
...
...
@@ -131,7 +130,9 @@ public class AiLockingKeyServiceImpl implements AiLockingKeyService {
//根据userid注销
@Override
public
R
removeKeysByUser
(
SmartCarKeyUserRequest
request
)
{
int
count
=
0
;
try
{
long
userId
=
Long
.
valueOf
(
request
.
getUserId
());
//逻辑删除蓝牙车钥匙设备
...
...
@@ -153,13 +154,13 @@ public class AiLockingKeyServiceImpl implements AiLockingKeyService {
//主钥匙的分享钥匙关闭分享
smartVehicleBlueShareKeyService
.
closeShareKeyByMainKeyIds
(
KeyIds
);
//逻辑删除主钥匙
smartVehicleBlueKeyService
.
removeKeyByIds
(
KeyIds
);
count
=
smartVehicleBlueKeyService
.
removeKeyByIds
(
KeyIds
);
}
}
catch
(
Exception
e
)
{
return
R
.
error
(
e
.
getMessage
());
}
return
R
.
ok
();
return
R
.
ok
()
.
data
(
count
)
;
}
...
...
src/test/java/com/glsx/smart/service/TestAesEncryptUtils.java
0 → 100644
View file @
fc1a08e
package
com
.
glsx
.
smart
.
service
;
import
cn.com.glsx.SmartServiceApplication
;
import
cn.com.glsx.smart.common.utils.AesEncryptUtils
;
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
;
import
java.security.SecureRandom
;
import
java.util.Random
;
/**
* @author fengzhi
* @version 1.0.0
* @description: 车钥匙AES加密解密测试
* @createTime 2021年05月08日 15:58:00
*/
@RunWith
(
SpringRunner
.
class
)
@SpringBootTest
(
classes
=
SmartServiceApplication
.
class
)
@Slf4j
public
class
TestAesEncryptUtils
{
@Autowired
private
AesEncryptUtils
aesEncryptUtils
;
@Test
public
void
testEncryptCrep
()
{
String
encrypt
=
null
;
try
{
encrypt
=
aesEncryptUtils
.
encrypt
(
"370342948446986240110"
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
log
.
info
(
"crep加密后:{}"
,
encrypt
);
}
@Test
public
void
testDecryptCrep
()
{
String
decrypt
=
null
;
try
{
decrypt
=
aesEncryptUtils
.
decrypt
(
"tZvuOJsVI6B8x5Yx3CBOH2MZn/3YhKbUtiVlkP9c+iU="
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
log
.
info
(
"crep解密后:{}"
,
decrypt
);
}
@Test
public
void
testEncryptSecretKey
()
{
String
encrypt
=
null
;
try
{
encrypt
=
aesEncryptUtils
.
encryptSecret
(
"37061517396835532890027292"
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
log
.
info
(
"SecretKey加密后:{}"
,
encrypt
);
}
@Test
public
void
testDecryptSecretKey
()
{
String
decrypt
=
null
;
try
{
decrypt
=
aesEncryptUtils
.
decryptSecret
(
"pZz3WfhsWOJSxpky6q8r84EHTSL/rmlkHhcNeWR9bys="
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
log
.
info
(
"SecretKey解密后:{}"
,
decrypt
);
}
@Test
public
void
testUUID
()
{
StringBuilder
uid
=
new
StringBuilder
();
//产生16位的强随机数
Random
rd
=
new
SecureRandom
();
for
(
int
i
=
0
;
i
<
16
;
i
++)
{
//产生0-2的3位随机数
int
type
=
rd
.
nextInt
(
3
);
switch
(
type
)
{
case
0
:
//0-9的随机数
uid
.
append
(
rd
.
nextInt
(
10
));
/*int random = ThreadLocalRandom.current().ints(0, 10)
.distinct().limit(1).findFirst().getAsInt();*/
break
;
case
1
:
//ASCII在65-90之间为大写,获取大写随机
uid
.
append
((
char
)
(
rd
.
nextInt
(
25
)
+
65
));
break
;
case
2
:
//ASCII在97-122之间为小写,获取小写随机
uid
.
append
((
char
)
(
rd
.
nextInt
(
25
)
+
97
));
break
;
default
:
break
;
}
}
String
uuid
=
uid
.
toString
();
log
.
info
(
"UUID:{}"
,
uuid
);
}
}
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