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
You need to sign in or sign up before continuing.
Commit 729d2c76
authored
Apr 21, 2021
by
fz
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
1.整理代码
2.设置车钥匙昵称判断重复 3.控制截取雪花算法后16位id作为crep
1 parent
88d9aa2d
Hide whitespace changes
Inline
Side-by-side
Showing
38 changed files
with
393 additions
and
128 deletions
src/main/java/com/glsx/smart/config/KafkaProducerConfig.java
src/main/java/com/glsx/smart/config/SnowFlakeConfig.java
src/main/java/com/glsx/smart/config/SnowWorkerConfig.java
src/main/java/com/glsx/smart/controller/ProductController.java
src/main/java/com/glsx/smart/controller/ProductTypeController.java
src/main/java/com/glsx/smart/controller/SysCodeController.java
src/main/java/com/glsx/smart/controller/SysFileController.java
src/main/java/com/glsx/smart/dao/entity/SmartDeviceOrdervalue.java
src/main/java/com/glsx/smart/dao/entity/SmartDeviceStatus.java
src/main/java/com/glsx/smart/dao/entity/SmartKeyCommandLog.java
src/main/java/com/glsx/smart/dao/entity/SmartProduct.java
src/main/java/com/glsx/smart/dao/entity/SmartSceneLog.java
src/main/java/com/glsx/smart/dao/entity/SmartSysCode.java
src/main/java/com/glsx/smart/dao/entity/SmartSysFile.java
src/main/java/com/glsx/smart/dao/entity/SmartTemplateParam.java
src/main/java/com/glsx/smart/dao/entity/SmartVehicleBlueKey.java
src/main/java/com/glsx/smart/dao/mapper/SmartDeviceStatusMapper.java
src/main/java/com/glsx/smart/dao/mapper/SmartKeyCommandLogMapper.java
src/main/java/com/glsx/smart/dao/mapper/SmartSysCodeMapper.java
src/main/java/com/glsx/smart/dao/mapper/SmartVehicleBlueKeyMapper.java
src/main/java/com/glsx/smart/filter/CorsFilter.java
src/main/java/com/glsx/smart/pojo/BaseDTO.java
src/main/java/com/glsx/smart/pojo/response/SmartCarKeyResponse.java
src/main/java/com/glsx/smart/service/SmartDeviceStatusService.java
src/main/java/com/glsx/smart/service/SmartKeyCommandLogService.java
src/main/java/com/glsx/smart/service/SmartSceneService.java
src/main/java/com/glsx/smart/service/SmartVehicleBlueKeyService.java
src/main/java/com/glsx/smart/service/impl/AiLockingKeyServiceImpl.java
src/main/java/com/glsx/smart/service/impl/SmartDeviceStatusServiceImpl.java
src/main/java/com/glsx/smart/service/impl/SmartKeyCommandLogServiceImpl.java
src/main/java/com/glsx/smart/service/impl/SmartSceneServiceImpl.java
src/main/java/com/glsx/smart/service/impl/SmartSysFileServiceImpl.java
src/main/java/com/glsx/smart/service/impl/SmartVehicleBlueKeyServiceImpl.java
src/main/java/com/glsx/smart/utils/AesEncryptUtils.java
src/main/java/com/glsx/smart/utils/DjApiInvoker.java
src/main/java/com/glsx/smart/utils/HttpUtil.java
src/main/java/com/glsx/smart/utils/SignUtil.java
src/main/java/com/glsx/smart/utils/SnowflakeWorker.java
src/main/java/com/glsx/smart/config/KafkaProducerConfig.java
View file @
729d2c7
package
com
.
glsx
.
smart
.
config
;
import
kafka.javaapi.producer.Producer
;
import
kafka.producer.ProducerConfig
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
kafka.producer.ProducerConfig
;
import
java.util.Properties
;
/**
...
...
src/main/java/com/glsx/smart/config/SnowFlakeConfig.java
0 → 100644
View file @
729d2c7
package
com
.
glsx
.
smart
.
config
;
import
lombok.Data
;
import
org.springframework.boot.context.properties.ConfigurationProperties
;
import
org.springframework.context.annotation.Configuration
;
/**
* @author fengzhi
* @version 1.0.0
* @ClassName KafkaProductorConfig.java
* @description: kafka生产消息
* @createTime 2021年03月12日 16:21:00
*/
@Data
@Configuration
@ConfigurationProperties
(
"snow.flake"
)
public
class
SnowFlakeConfig
{
private
String
workerId
;
private
String
datacenterId
;
}
src/main/java/com/glsx/smart/config/SnowWorkerConfig.java
0 → 100644
View file @
729d2c7
package
com
.
glsx
.
smart
.
config
;
import
com.glsx.smart.utils.SnowflakeWorker
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
/**
* @author fengzhi
* @version 1.0.0
* @ClassName KafkaProductorConfig.java
* @description: kafka生产消息
* @createTime 2021年03月12日 16:21:00
*/
@Slf4j
@Configuration
public
class
SnowWorkerConfig
{
@Autowired
private
SnowFlakeConfig
snowFlakeConfig
;
@Bean
(
"snowflakeWorker"
)
public
SnowflakeWorker
getSnowFlakeWorker
()
{
SnowflakeWorker
worker
=
new
SnowflakeWorker
(
Long
.
valueOf
(
snowFlakeConfig
.
getWorkerId
()),
Long
.
valueOf
(
snowFlakeConfig
.
getDatacenterId
()));
return
worker
;
}
}
src/main/java/com/glsx/smart/controller/ProductController.java
View file @
729d2c7
package
com
.
glsx
.
smart
.
controller
;
import
java.util.List
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONArray
;
import
com.github.pagehelper.PageInfo
;
...
...
@@ -14,6 +13,8 @@ import org.springframework.web.bind.annotation.RequestMapping;
import
org.springframework.web.bind.annotation.RequestMethod
;
import
org.springframework.web.bind.annotation.RestController
;
import
java.util.List
;
/**
* <p>Description: 产品列表业务
* <p>Project: chejia-smart
...
...
src/main/java/com/glsx/smart/controller/ProductTypeController.java
View file @
729d2c7
package
com
.
glsx
.
smart
.
controller
;
import
java.util.List
;
import
com.alibaba.fastjson.JSON
;
import
com.github.pagehelper.PageInfo
;
import
com.glsx.smart.dao.entity.SmartProductType
;
...
...
@@ -12,6 +11,8 @@ import org.springframework.web.bind.annotation.RequestMapping;
import
org.springframework.web.bind.annotation.RequestMethod
;
import
org.springframework.web.bind.annotation.RestController
;
import
java.util.List
;
/**
* <p>Description: 产品类型业务
* <p>Project: chejia-smart
...
...
src/main/java/com/glsx/smart/controller/SysCodeController.java
View file @
729d2c7
package
com
.
glsx
.
smart
.
controller
;
import
java.util.List
;
import
com.alibaba.fastjson.JSON
;
import
com.glsx.plat.common.utils.StringUtils
;
import
com.glsx.plat.core.web.R
;
...
...
@@ -14,6 +13,8 @@ import org.springframework.web.bind.annotation.RequestMapping;
import
org.springframework.web.bind.annotation.RequestMethod
;
import
org.springframework.web.bind.annotation.RestController
;
import
java.util.List
;
/**
* <p>Description:
* <p>Project: chejia-smart
...
...
src/main/java/com/glsx/smart/controller/SysFileController.java
View file @
729d2c7
package
com
.
glsx
.
smart
.
controller
;
import
java.util.List
;
import
java.util.Map
;
import
com.glsx.plat.core.web.R
;
import
com.glsx.smart.pojo.FileDTO
;
import
com.glsx.smart.service.SmartSysFileService
;
...
...
@@ -9,11 +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.RequestBody
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMethod
;
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/com/glsx/smart/dao/entity/SmartDeviceOrdervalue.java
View file @
729d2c7
package
com
.
glsx
.
smart
.
dao
.
entity
;
import
lombok.Data
;
import
javax.persistence.Column
;
import
javax.persistence.Id
;
import
javax.persistence.Table
;
import
lombok.Data
;
/**
* <p>Description:
...
...
src/main/java/com/glsx/smart/dao/entity/SmartDeviceStatus.java
View file @
729d2c7
package
com
.
glsx
.
smart
.
dao
.
entity
;
import
lombok.Data
;
import
javax.persistence.GeneratedValue
;
import
javax.persistence.GenerationType
;
import
javax.persistence.Id
;
import
javax.persistence.Table
;
import
java.util.Date
;
import
lombok.Data
;
/**
* <p>Description:
...
...
src/main/java/com/glsx/smart/dao/entity/SmartKeyCommandLog.java
View file @
729d2c7
package
com
.
glsx
.
smart
.
dao
.
entity
;
import
java.io.Serializable
;
import
java.util.Date
;
import
com.fasterxml.jackson.annotation.JsonFormat
;
import
lombok.Data
;
import
org.springframework.format.annotation.DateTimeFormat
;
...
...
@@ -11,6 +8,8 @@ import javax.persistence.GeneratedValue;
import
javax.persistence.GenerationType
;
import
javax.persistence.Id
;
import
javax.persistence.Table
;
import
java.io.Serializable
;
import
java.util.Date
;
/**
* 智能蓝牙车钥匙指令操作日志表
...
...
src/main/java/com/glsx/smart/dao/entity/SmartProduct.java
View file @
729d2c7
package
com
.
glsx
.
smart
.
dao
.
entity
;
import
javax.persistence.GeneratedValue
;
import
javax.persistence.GenerationType
;
import
javax.persistence.Id
;
import
javax.persistence.Table
;
import
javax.persistence.Transient
;
import
java.util.Date
;
import
com.glsx.smart.pojo.BaseDTO
;
import
lombok.Data
;
import
javax.persistence.*
;
import
java.util.Date
;
/**
* <p>Description:
* <p>Project: chejia-smart
...
...
src/main/java/com/glsx/smart/dao/entity/SmartSceneLog.java
View file @
729d2c7
package
com
.
glsx
.
smart
.
dao
.
entity
;
import
lombok.Data
;
import
javax.persistence.Column
;
import
javax.persistence.GeneratedValue
;
import
javax.persistence.Id
;
import
javax.persistence.Table
;
import
java.util.Date
;
import
lombok.Data
;
/**
* <p>Description:
...
...
src/main/java/com/glsx/smart/dao/entity/SmartSysCode.java
View file @
729d2c7
package
com
.
glsx
.
smart
.
dao
.
entity
;
import
javax.persistence.GeneratedValue
;
import
javax.persistence.GenerationType
;
import
javax.persistence.Id
;
import
javax.persistence.Table
;
import
javax.persistence.Transient
;
import
java.util.Date
;
import
java.util.List
;
import
com.glsx.smart.pojo.BaseDTO
;
import
lombok.Data
;
import
javax.persistence.*
;
import
java.util.Date
;
import
java.util.List
;
/**
* <p>Description:
* <p>Project: chejia-smart
...
...
src/main/java/com/glsx/smart/dao/entity/SmartSysFile.java
View file @
729d2c7
package
com
.
glsx
.
smart
.
dao
.
entity
;
import
lombok.Data
;
import
javax.persistence.GeneratedValue
;
import
javax.persistence.GenerationType
;
import
javax.persistence.Id
;
import
javax.persistence.Table
;
import
java.util.Date
;
import
lombok.Data
;
/**
* <p>Description:
...
...
src/main/java/com/glsx/smart/dao/entity/SmartTemplateParam.java
View file @
729d2c7
...
...
@@ -9,11 +9,12 @@ package com.glsx.smart.dao.entity;
*/
import
lombok.Data
;
import
javax.persistence.GeneratedValue
;
import
javax.persistence.GenerationType
;
import
javax.persistence.Id
;
import
javax.persistence.Table
;
import
lombok.Data
;
/**
* 车家智能场景模板参数表
...
...
src/main/java/com/glsx/smart/dao/entity/SmartVehicleBlueKey.java
View file @
729d2c7
package
com
.
glsx
.
smart
.
dao
.
entity
;
import
java.io.Serializable
;
import
java.util.Date
;
import
com.fasterxml.jackson.annotation.JsonFormat
;
import
lombok.Data
;
import
org.springframework.format.annotation.DateTimeFormat
;
...
...
@@ -11,6 +8,8 @@ import javax.persistence.GeneratedValue;
import
javax.persistence.GenerationType
;
import
javax.persistence.Id
;
import
javax.persistence.Table
;
import
java.io.Serializable
;
import
java.util.Date
;
/**
* 智能蓝牙车钥匙表
...
...
src/main/java/com/glsx/smart/dao/mapper/SmartDeviceStatusMapper.java
View file @
729d2c7
package
com
.
glsx
.
smart
.
dao
.
mapper
;
import
java.util.List
;
import
com.glsx.smart.dao.entity.SmartDeviceStatus
;
import
org.apache.ibatis.annotations.Mapper
;
import
org.apache.ibatis.annotations.Param
;
import
java.util.List
;
/**
* <p>Description:
...
...
src/main/java/com/glsx/smart/dao/mapper/SmartKeyCommandLogMapper.java
View file @
729d2c7
...
...
@@ -2,10 +2,11 @@ package com.glsx.smart.dao.mapper;
import
com.glsx.smart.dao.entity.SmartKeyCommandLog
;
import
com.glsx.smart.dao.entity.SmartKeyCommandLogExample
;
import
java.util.List
;
import
org.apache.ibatis.annotations.Mapper
;
import
org.apache.ibatis.annotations.Param
;
import
java.util.List
;
@Mapper
public
interface
SmartKeyCommandLogMapper
{
long
countByExample
(
SmartKeyCommandLogExample
example
);
...
...
src/main/java/com/glsx/smart/dao/mapper/SmartSysCodeMapper.java
View file @
729d2c7
package
com
.
glsx
.
smart
.
dao
.
mapper
;
import
java.util.List
;
import
com.glsx.smart.dao.entity.SmartSysCode
;
import
org.apache.ibatis.annotations.Mapper
;
import
org.apache.ibatis.annotations.Param
;
import
java.util.List
;
/**
* <p>Description:
* <p>Project: chejia-smart
...
...
src/main/java/com/glsx/smart/dao/mapper/SmartVehicleBlueKeyMapper.java
View file @
729d2c7
...
...
@@ -2,10 +2,11 @@ package com.glsx.smart.dao.mapper;
import
com.glsx.smart.dao.entity.SmartVehicleBlueKey
;
import
com.glsx.smart.dao.entity.SmartVehicleBlueKeyExample
;
import
java.util.List
;
import
org.apache.ibatis.annotations.Mapper
;
import
org.apache.ibatis.annotations.Param
;
import
java.util.List
;
@Mapper
public
interface
SmartVehicleBlueKeyMapper
{
long
countByExample
(
SmartVehicleBlueKeyExample
example
);
...
...
src/main/java/com/glsx/smart/filter/CorsFilter.java
View file @
729d2c7
package
com
.
glsx
.
smart
.
filter
;
import
javax.servlet.Filter
;
import
javax.servlet.FilterChain
;
import
javax.servlet.ServletException
;
import
javax.servlet.ServletRequest
;
import
javax.servlet.ServletResponse
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.IOException
;
import
java.util.Enumeration
;
import
com.glsx.plat.common.utils.StringUtils
;
import
org.springframework.http.HttpHeaders
;
import
org.springframework.http.HttpMethod
;
import
org.springframework.stereotype.Component
;
import
javax.servlet.*
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.IOException
;
import
java.util.Enumeration
;
/**
* <p>Description: 跨域配置
* <p>Project: chejia-smart
...
...
src/main/java/com/glsx/smart/pojo/BaseDTO.java
View file @
729d2c7
package
com
.
glsx
.
smart
.
pojo
;
import
javax.persistence.Transient
;
import
lombok.Data
;
import
javax.persistence.Transient
;
/**
* @author think.wang
* @version 1.0.0
...
...
src/main/java/com/glsx/smart/pojo/response/SmartCarKeyResponse.java
View file @
729d2c7
...
...
@@ -3,6 +3,7 @@ package com.glsx.smart.pojo.response;
import
com.fasterxml.jackson.annotation.JsonFormat
;
import
lombok.Data
;
import
org.springframework.format.annotation.DateTimeFormat
;
import
java.io.Serializable
;
import
java.util.Date
;
...
...
src/main/java/com/glsx/smart/service/SmartDeviceStatusService.java
View file @
729d2c7
package
com
.
glsx
.
smart
.
service
;
import
java.util.List
;
import
com.glsx.smart.dao.entity.SmartDeviceStatus
;
import
java.util.List
;
/**
* <p>Description:
* <p>Project: chejia-smart
...
...
src/main/java/com/glsx/smart/service/SmartKeyCommandLogService.java
View file @
729d2c7
package
com
.
glsx
.
smart
.
service
;
import
com.glsx.smart.dao.entity.SmartKeyCommandLog
;
import
java.util.List
;
import
com.glsx.smart.dao.entity.SmartKeyCommandLogExample
;
import
java.util.List
;
public
interface
SmartKeyCommandLogService
{
...
...
src/main/java/com/glsx/smart/service/SmartSceneService.java
View file @
729d2c7
...
...
@@ -3,7 +3,6 @@ package com.glsx.smart.service;
import
com.glsx.smart.dao.entity.SmartScene
;
import
com.glsx.smart.pojo.OrderResponse
;
import
java.io.IOException
;
import
java.util.List
;
/**
...
...
src/main/java/com/glsx/smart/service/SmartVehicleBlueKeyService.java
View file @
729d2c7
...
...
@@ -2,6 +2,7 @@ package com.glsx.smart.service;
import
com.glsx.smart.dao.entity.SmartVehicleBlueKey
;
import
com.glsx.smart.dao.entity.SmartVehicleBlueKeyExample
;
import
java.util.List
;
public
interface
SmartVehicleBlueKeyService
{
...
...
src/main/java/com/glsx/smart/service/impl/AiLockingKeyServiceImpl.java
View file @
729d2c7
...
...
@@ -2,7 +2,6 @@ package com.glsx.smart.service.impl;
import
com.alibaba.nacos.common.utils.CollectionUtils
;
import
com.alibaba.nacos.common.utils.StringUtils
;
import
com.glsx.plat.common.utils.SnowFlake
;
import
com.glsx.plat.core.web.R
;
import
com.glsx.smart.dao.entity.SmartKeyCommandLog
;
import
com.glsx.smart.dao.entity.SmartVehicleBlueKey
;
...
...
@@ -15,10 +14,12 @@ import com.glsx.smart.service.AiLockingKeyService;
import
com.glsx.smart.service.SmartKeyCommandLogService
;
import
com.glsx.smart.service.SmartVehicleBlueKeyService
;
import
com.glsx.smart.utils.AesEncryptUtils
;
import
com.glsx.smart.utils.SnowflakeWorker
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.BeanUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
java.util.Date
;
import
java.util.List
;
...
...
@@ -42,22 +43,25 @@ public class AiLockingKeyServiceImpl implements AiLockingKeyService {
@Autowired
private
AesEncryptUtils
aesEncryptUtils
;
@Autowired
private
SnowflakeWorker
snowflakeWorker
;
//sn查询/新增车钥匙
@Override
public
R
getLockingKey
(
SmartCarKeyRequest
request
)
{
SmartCarKeyResponse
response
=
new
SmartCarKeyResponse
();
SmartVehicleBlueKeyExample
example
=
getExampleBysn
(
Long
.
valueOf
(
request
.
getUserId
()),
request
.
getSn
());
SmartVehicleBlueKeyExample
example
=
getExampleBysn
(
Long
.
valueOf
(
request
.
getUserId
()),
request
.
getSn
());
List
<
SmartVehicleBlueKey
>
smartVehicleBlueKeys
=
smartVehicleBlueKeyService
.
selectByExample
(
example
);
if
(
CollectionUtils
.
isEmpty
(
smartVehicleBlueKeys
))
{
if
(
CollectionUtils
.
isEmpty
(
smartVehicleBlueKeys
))
{
//如果sn,userid没有数据,生成只含有crep钥匙信息返回
SmartVehicleBlueKey
newKey
=
new
SmartVehicleBlueKey
();
//雪花算法生成crep,对称加密
String
crep
=
getCrepCode
(
request
);
String
crep
=
getCrepCode
();
String
crep_encrypt
=
""
;
//加密
try
{
crep_encrypt
=
aesEncryptUtils
.
encrypt
(
crep
);
crep_encrypt
=
aesEncryptUtils
.
encrypt
(
crep
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
throw
new
BusinessException
(
ResultEnum
.
ENCRYPT_EXCEP_1
);
...
...
@@ -74,22 +78,22 @@ public class AiLockingKeyServiceImpl implements AiLockingKeyService {
smartVehicleBlueKeyService
.
insert
(
newKey
);
//返回,crep用密文传输
BeanUtils
.
copyProperties
(
newKey
,
response
);
BeanUtils
.
copyProperties
(
newKey
,
response
);
response
.
setCrepCode
(
crep_encrypt
);
return
R
.
ok
().
data
(
response
);
}
else
{
}
else
{
SmartVehicleBlueKey
carkey
=
smartVehicleBlueKeys
.
get
(
0
);
String
crepCode
=
carkey
.
getCrepCode
();
if
(
StringUtils
.
isNotEmpty
(
crepCode
))
{
if
(
StringUtils
.
isNotEmpty
(
crepCode
))
{
//如果sn,userid有对应的crep,返回钥匙信息
BeanUtils
.
copyProperties
(
carkey
,
response
);
BeanUtils
.
copyProperties
(
carkey
,
response
);
//将数据库密钥解密成明文
String
secretKey
=
""
;
String
secretKey_db
=
carkey
.
getSecretKey
();
if
(
StringUtils
.
isNotEmpty
(
secretKey
))
{
if
(
StringUtils
.
isNotEmpty
(
secretKey
))
{
try
{
secretKey
=
aesEncryptUtils
.
decryptSecret
(
secretKey_db
);
secretKey
=
aesEncryptUtils
.
decryptSecret
(
secretKey_db
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
throw
new
BusinessException
(
ResultEnum
.
ENCRYPT_EXCEP_6
);
...
...
@@ -101,9 +105,9 @@ public class AiLockingKeyServiceImpl implements AiLockingKeyService {
String
crep_encrypt
=
""
;
String
secret_key_encrypt
=
""
;
try
{
crep_encrypt
=
aesEncryptUtils
.
encrypt
(
crepCode
);
if
(
StringUtils
.
isNotEmpty
(
secretKey
))
secret_key_encrypt
=
aesEncryptUtils
.
encrypt
(
secretKey
);
crep_encrypt
=
aesEncryptUtils
.
encrypt
(
crepCode
);
if
(
StringUtils
.
isNotEmpty
(
secretKey
))
secret_key_encrypt
=
aesEncryptUtils
.
encrypt
(
secretKey
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
throw
new
BusinessException
(
ResultEnum
.
ENCRYPT_EXCEP_2
);
...
...
@@ -112,14 +116,14 @@ public class AiLockingKeyServiceImpl implements AiLockingKeyService {
response
.
setCrepCode
(
crep_encrypt
);
response
.
setSecretKey
(
secret_key_encrypt
);
return
R
.
ok
().
data
(
response
);
}
else
{
}
else
{
//如果sn,userid没有对应的crep。生成只含有crep钥匙信息返回
//雪花算法生成crep,对称加密
String
crep
=
getCrepCode
(
request
);
String
crep
=
getCrepCode
();
String
crep_encrypt
=
""
;
//加密
try
{
crep_encrypt
=
aesEncryptUtils
.
encrypt
(
crep
);
crep_encrypt
=
aesEncryptUtils
.
encrypt
(
crep
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
throw
new
BusinessException
(
ResultEnum
.
ENCRYPT_EXCEP_3
);
...
...
@@ -135,7 +139,7 @@ public class AiLockingKeyServiceImpl implements AiLockingKeyService {
smartVehicleBlueKeyService
.
updateByPrimaryKey
(
carkey
);
//返回,crep用密文传输
BeanUtils
.
copyProperties
(
carkey
,
response
);
BeanUtils
.
copyProperties
(
carkey
,
response
);
response
.
setCrepCode
(
crep_encrypt
);
return
R
.
ok
().
data
(
response
);
}
...
...
@@ -143,7 +147,6 @@ public class AiLockingKeyServiceImpl implements AiLockingKeyService {
}
//智能车钥匙解绑
@Override
public
R
removeLockingKey
(
SmartCarKeyRmRequest
request
)
{
...
...
@@ -161,7 +164,7 @@ public class AiLockingKeyServiceImpl implements AiLockingKeyService {
logData
.
setUserId
(
Long
.
valueOf
(
carKeyCommandRequest
.
getUserId
()));
String
crep
=
""
;
try
{
crep
=
aesEncryptUtils
.
decrypt
(
carKeyCommandRequest
.
getCrepCode
());
crep
=
aesEncryptUtils
.
decrypt
(
carKeyCommandRequest
.
getCrepCode
());
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
throw
new
BusinessException
(
ResultEnum
.
ENCRYPT_EXCEP_4
);
...
...
@@ -177,9 +180,28 @@ public class AiLockingKeyServiceImpl implements AiLockingKeyService {
//车钥匙修改昵称
@Override
public
R
setLockingKeyName
(
SmartCarKeyNameRequest
request
)
{
SmartVehicleBlueKey
smartVehicleBlueKey
=
new
SmartVehicleBlueKey
();
smartVehicleBlueKey
.
setKeyName
(
request
.
getKeyName
());
smartVehicleBlueKeyService
.
updateByExampleSelective
(
smartVehicleBlueKey
,
getExampleBysn
(
Long
.
valueOf
(
request
.
getUserId
()),
request
.
getSn
()));
String
keyName
=
request
.
getKeyName
();
if
(
StringUtils
.
isBlank
(
keyName
))
{
return
R
.
error
(
"keyName不能为空字符串"
);
}
//查询车钥匙
SmartVehicleBlueKeyExample
example
=
new
SmartVehicleBlueKeyExample
();
example
.
createCriteria
().
andIsDeleteEqualTo
(
0
)
.
andSnEqualTo
(
request
.
getSn
())
.
andUserIdEqualTo
(
Long
.
valueOf
(
request
.
getUserId
()))
;
List
<
SmartVehicleBlueKey
>
keyList
=
smartVehicleBlueKeyService
.
selectByExample
(
example
);
if
(
CollectionUtils
.
isNotEmpty
(
keyList
))
{
SmartVehicleBlueKey
smartVehicleBlueKey
=
keyList
.
get
(
0
);
//如果库中存在相同的昵称
String
keyName_db
=
smartVehicleBlueKey
.
getKeyName
();
if
(
StringUtils
.
isNotBlank
(
keyName_db
)
&&
keyName_db
.
equals
(
keyName
))
{
return
R
.
error
(
"keyName重复,已存在"
);
}
smartVehicleBlueKey
.
setKeyName
(
keyName
);
smartVehicleBlueKeyService
.
updateByPrimaryKeySelective
(
smartVehicleBlueKey
);
}
return
R
.
ok
();
}
...
...
@@ -209,8 +231,8 @@ public class AiLockingKeyServiceImpl implements AiLockingKeyService {
String
crep
=
""
;
String
keySecret
=
""
;
try
{
crep
=
aesEncryptUtils
.
decrypt
(
request
.
getCrepCode
());
keySecret
=
aesEncryptUtils
.
decrypt
(
request
.
getSecretKey
());
crep
=
aesEncryptUtils
.
decrypt
(
request
.
getCrepCode
());
keySecret
=
aesEncryptUtils
.
decrypt
(
request
.
getSecretKey
());
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
throw
new
BusinessException
(
ResultEnum
.
ENCRYPT_EXCEP_5
);
...
...
@@ -219,9 +241,9 @@ public class AiLockingKeyServiceImpl implements AiLockingKeyService {
//将密钥明文加密后存入数据库
String
secretKey_db
=
""
;
if
(
StringUtils
.
isNotEmpty
(
keySecret
))
{
if
(
StringUtils
.
isNotEmpty
(
keySecret
))
{
try
{
secretKey_db
=
aesEncryptUtils
.
encryptSecret
(
keySecret
);
secretKey_db
=
aesEncryptUtils
.
encryptSecret
(
keySecret
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
throw
new
BusinessException
(
ResultEnum
.
ENCRYPT_EXCEP_7
);
...
...
@@ -237,7 +259,7 @@ public class AiLockingKeyServiceImpl implements AiLockingKeyService {
SmartVehicleBlueKeyExample
example
=
new
SmartVehicleBlueKeyExample
();
example
.
createCriteria
().
andUserIdEqualTo
(
Long
.
valueOf
(
request
.
getUserId
())).
andCrepCodeEqualTo
(
crep
).
andIsDeleteEqualTo
(
0
);
smartVehicleBlueKeyService
.
updateByExampleSelective
(
smartVehicleBlueKey
,
example
);
smartVehicleBlueKeyService
.
updateByExampleSelective
(
smartVehicleBlueKey
,
example
);
return
R
.
ok
();
}
...
...
@@ -249,10 +271,9 @@ public class AiLockingKeyServiceImpl implements AiLockingKeyService {
}
//获取crep(雪花算法+userid)
private
String
getCrepCode
(
SmartCarKeyRequest
request
)
{
long
snowId
=
SnowFlake
.
nextId
();
long
userId
=
Long
.
parseLong
(
request
.
getUserId
());
StringBuilder
sb
=
new
StringBuilder
();
return
sb
.
append
(
snowId
).
append
(
userId
).
toString
();
private
String
getCrepCode
()
{
String
snowId
=
snowflakeWorker
.
nextId
()+
""
;
int
len
=
snowId
.
length
();
return
snowId
.
substring
(
len
-
16
,
len
);
}
}
src/main/java/com/glsx/smart/service/impl/SmartDeviceStatusServiceImpl.java
View file @
729d2c7
package
com
.
glsx
.
smart
.
service
.
impl
;
import
javax.annotation.Resource
;
import
java.util.List
;
import
com.glsx.smart.dao.entity.SmartDeviceStatus
;
import
com.glsx.smart.dao.mapper.SmartDeviceStatusMapper
;
import
com.glsx.smart.service.SmartDeviceStatusService
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.stereotype.Service
;
import
javax.annotation.Resource
;
import
java.util.List
;
/**
* <p>Description:
* <p>Project: chejia-smart
...
...
src/main/java/com/glsx/smart/service/impl/SmartKeyCommandLogServiceImpl.java
View file @
729d2c7
package
com
.
glsx
.
smart
.
service
.
impl
;
import
org.springframework.stereotype.Service
;
import
javax.annotation.Resource
;
import
com.glsx.smart.dao.entity.SmartKeyCommandLog
;
import
java.util.List
;
import
com.glsx.smart.dao.entity.SmartKeyCommandLogExample
;
import
com.glsx.smart.dao.mapper.SmartKeyCommandLogMapper
;
import
com.glsx.smart.service.SmartKeyCommandLogService
;
import
org.springframework.stereotype.Service
;
import
javax.annotation.Resource
;
import
java.util.List
;
@Service
public
class
SmartKeyCommandLogServiceImpl
implements
SmartKeyCommandLogService
{
...
...
src/main/java/com/glsx/smart/service/impl/SmartSceneServiceImpl.java
View file @
729d2c7
...
...
@@ -32,11 +32,7 @@ import org.springframework.transaction.annotation.Transactional;
import
javax.annotation.Resource
;
import
java.io.IOException
;
import
java.text.MessageFormat
;
import
java.util.ArrayList
;
import
java.util.Date
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.*
;
import
java.util.concurrent.TimeUnit
;
import
java.util.stream.Collectors
;
...
...
src/main/java/com/glsx/smart/service/impl/SmartSysFileServiceImpl.java
View file @
729d2c7
...
...
@@ -11,11 +11,7 @@ import org.springframework.beans.BeanUtils;
import
org.springframework.stereotype.Service
;
import
javax.annotation.Resource
;
import
java.util.ArrayList
;
import
java.util.Date
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.*
;
import
java.util.stream.Collectors
;
/**
...
...
src/main/java/com/glsx/smart/service/impl/SmartVehicleBlueKeyServiceImpl.java
View file @
729d2c7
package
com
.
glsx
.
smart
.
service
.
impl
;
import
org.springframework.stereotype.Service
;
import
javax.annotation.Resource
;
import
com.glsx.smart.dao.entity.SmartVehicleBlueKey
;
import
com.glsx.smart.dao.entity.SmartVehicleBlueKeyExample
;
import
java.util.List
;
import
com.glsx.smart.dao.mapper.SmartVehicleBlueKeyMapper
;
import
com.glsx.smart.service.SmartVehicleBlueKeyService
;
import
org.springframework.stereotype.Service
;
import
javax.annotation.Resource
;
import
java.util.List
;
@Service
public
class
SmartVehicleBlueKeyServiceImpl
implements
SmartVehicleBlueKeyService
{
...
...
src/main/java/com/glsx/smart/utils/AesEncryptUtils.java
View file @
729d2c7
...
...
@@ -3,10 +3,15 @@ package com.glsx.smart.utils;
import
org.apache.commons.codec.binary.Base64
;
import
org.springframework.beans.factory.annotation.Value
;
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
;
@Component
...
...
@@ -86,20 +91,69 @@ public class AesEncryptUtils {
//System.out.println("加密前:" + content);
//
String
encrypt
=
encrypt1
(
"370342948446986240110"
,
"0BDsQu0naQF9BYGr"
);
System
.
out
.
println
(
"加密后:"
+
encrypt
);
System
.
out
.
println
(
"加密后
1
:"
+
encrypt
);
//
String
decrypt
=
decrypt1
(
"
6GRXvnluinolZWMqxHYFgG7+x8XoVSYlsYRRP/Zla5Y
="
,
"0BDsQu0naQF9BYGr"
);
System
.
out
.
println
(
"解密后:"
+
decrypt
);
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
);
//tHS9rKB161Oh9Idj
//
//获取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
{
...
...
@@ -157,4 +211,39 @@ public class AesEncryptUtils {
return
Base64
.
encodeBase64String
(
b
);
}
/**
* 计算中英文字符串的字节长度 <br/>
* 一个中文占3个字节
*
* @param str
* @return int 字符串的字节长度
*/
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
;
}
}
src/main/java/com/glsx/smart/utils/DjApiInvoker.java
View file @
729d2c7
package
com
.
glsx
.
smart
.
utils
;
import
java.util.Date
;
import
java.util.Map
;
import
cn.hutool.core.date.DateUtil
;
import
com.alibaba.fastjson.JSON
;
import
com.glsx.plat.common.utils.HttpUtils
;
...
...
@@ -15,6 +13,9 @@ import org.springframework.context.ApplicationContext;
import
org.springframework.context.ApplicationContextAware
;
import
org.springframework.core.env.Environment
;
import
java.util.Date
;
import
java.util.Map
;
/**
* <p>Description: 嘀加商城 API 调用工具类
* <p>Project: chejia-smart
...
...
src/main/java/com/glsx/smart/utils/HttpUtil.java
View file @
729d2c7
...
...
@@ -6,15 +6,7 @@ import org.apache.commons.lang.StringUtils;
import
org.apache.commons.lang.time.DateFormatUtils
;
import
org.apache.commons.logging.Log
;
import
org.apache.commons.logging.LogFactory
;
import
org.apache.http.Consts
;
import
org.apache.http.HttpEntity
;
import
org.apache.http.HttpEntityEnclosingRequest
;
import
org.apache.http.HttpRequest
;
import
org.apache.http.HttpResponse
;
import
org.apache.http.NameValuePair
;
import
org.apache.http.NoHttpResponseException
;
import
org.apache.http.ParseException
;
import
org.apache.http.StatusLine
;
import
org.apache.http.*
;
import
org.apache.http.client.ClientProtocolException
;
import
org.apache.http.client.HttpClient
;
import
org.apache.http.client.HttpRequestRetryHandler
;
...
...
@@ -52,12 +44,7 @@ import java.io.InterruptedIOException;
import
java.net.UnknownHostException
;
import
java.nio.charset.Charset
;
import
java.security.NoSuchAlgorithmException
;
import
java.util.ArrayList
;
import
java.util.Date
;
import
java.util.Iterator
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Set
;
import
java.util.*
;
public
class
HttpUtil
{
...
...
src/main/java/com/glsx/smart/utils/SignUtil.java
View file @
729d2c7
package
com
.
glsx
.
smart
.
utils
;
import
cn.hutool.core.collection.CollectionUtil
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.codec.digest.DigestUtils
;
import
java.util.ArrayList
;
import
java.util.Collections
;
import
java.util.List
;
import
java.util.Map
;
import
cn.hutool.core.collection.CollectionUtil
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.codec.digest.DigestUtils
;
/**
* <p>Description: 签名工具类,支持 MD5 签名和 SHA1 签名,也可以实现 {@link DigestTool} 来自定义加密方式。
...
...
src/main/java/com/glsx/smart/utils/SnowflakeWorker.java
0 → 100644
View file @
729d2c7
package
com
.
glsx
.
smart
.
utils
;
/**
* @Title: SnowflakeWorker.java
* @Description: 雪花算法-生成自增长的ID,无须查库,分布式的订单编号生成算法。
* @Author saruman
* @Date 2018/5/21 16:11
* @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) */
private
long
dataCenterId
;
/** 毫秒内序列(0~4095) */
private
long
sequence
=
0L
;
/** 上次生成ID的时间截 */
private
long
lastTimestamp
=
-
1L
;
/**
* @param workerId 工作机器ID (0~31)
* @param dataCenterId 数据中心ID (0~31)
*/
public
SnowflakeWorker
(
long
workerId
,
long
dataCenterId
)
{
if
(
workerId
>
maxWorkerId
||
workerId
<
0
)
{
throw
new
IllegalArgumentException
(
String
.
format
(
"worker Id can't be greater than %d or less than 0"
,
maxWorkerId
));
}
if
(
dataCenterId
>
maxDataCenterId
||
dataCenterId
<
0
)
{
throw
new
IllegalArgumentException
(
String
.
format
(
"dataCenter Id can't be greater than %d or less than 0"
,
maxDataCenterId
));
}
this
.
workerId
=
workerId
;
this
.
dataCenterId
=
dataCenterId
;
}
/**
* 获得下一个ID (该方法是线程安全的)
* @return SnowflakeId
*/
public
synchronized
long
nextId
()
{
long
timestamp
=
timeGen
();
//如果当前时间小于上一次ID生成的时间戳,说明系统时钟回退过这个时候应当抛出异常
if
(
timestamp
<
lastTimestamp
)
{
throw
new
RuntimeException
(
String
.
format
(
"Clock moved backwards. Refusing to generate id for %d milliseconds"
,
lastTimestamp
-
timestamp
));
}
//如果是同一时间生成的,则进行毫秒内序列
if
(
lastTimestamp
==
timestamp
)
{
sequence
=
(
sequence
+
1
)
&
sequenceMask
;
//毫秒内序列溢出
if
(
sequence
==
0
)
{
//阻塞到下一个毫秒,获得新的时间戳
timestamp
=
tilNextMillis
(
lastTimestamp
);
}
}
else
{
//时间戳改变,毫秒内序列重置
sequence
=
0L
;
}
//上次生成ID的时间截
lastTimestamp
=
timestamp
;
//移位并通过或运算拼到一起组成64位的ID
return
((
timestamp
-
epoch
)
<<
timestampLeftShift
)
|
(
dataCenterId
<<
dataCenterIdShift
)
|
(
workerId
<<
workerIdShift
)
|
sequence
;
}
/**
* 阻塞到下一个毫秒,直到获得新的时间戳
* @param lastTimestamp 上次生成ID的时间截
* @return 当前时间戳
*/
private
long
tilNextMillis
(
long
lastTimestamp
)
{
long
timestamp
=
timeGen
();
while
(
timestamp
<=
lastTimestamp
)
{
timestamp
=
timeGen
();
}
return
timestamp
;
}
/**
* 返回以毫秒为单位的当前时间
* @return 当前时间(毫秒)
*/
private
long
timeGen
()
{
return
System
.
currentTimeMillis
();
}
//==============================Test=============================================
/** 测试 */
public
static
void
main
(
String
[]
args
)
{
/*SnowflakeWorker idWorker = new SnowflakeWorker(0, 0);
for (int i = 0; i < 1000; i++) {
long id = idWorker.nextId();
System.out.println(id);
}*/
long
x
=
-
1L
^
(-
1L
<<
63
);
System
.
out
.
println
(
x
);
System
.
out
.
println
(
Long
.
MAX_VALUE
);
}
}
\ No newline at end of file
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