Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
app-service
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Container Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
SuperHive
back-end
app-service
Commits
b9743359
Commit
b9743359
authored
Apr 18, 2020
by
zhangzc
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
提交APP-service代码
parents
Changes
69
Show whitespace changes
Inline
Side-by-side
Showing
69 changed files
with
5284 additions
and
0 deletions
+5284
-0
.gitignore
.gitignore
+9
-0
pom.xml
pom.xml
+208
-0
AppApplication.java
src/main/java/com/esv/freight/app/AppApplication.java
+30
-0
RedisComponent.java
.../com/esv/freight/app/common/component/RedisComponent.java
+518
-0
DbDeletedEnum.java
...a/com/esv/freight/app/common/constants/DbDeletedEnum.java
+40
-0
EException.java
...java/com/esv/freight/app/common/exception/EException.java
+58
-0
LogbackFilter.java
...java/com/esv/freight/app/common/filter/LogbackFilter.java
+56
-0
RestLogFilter.java
...java/com/esv/freight/app/common/filter/RestLogFilter.java
+166
-0
RestExceptionHandler.java
.../esv/freight/app/common/handler/RestExceptionHandler.java
+52
-0
ECode.java
src/main/java/com/esv/freight/app/common/response/ECode.java
+38
-0
EResponse.java
...n/java/com/esv/freight/app/common/response/EResponse.java
+141
-0
AESSecretUtils.java
.../java/com/esv/freight/app/common/util/AESSecretUtils.java
+174
-0
DateUtils.java
src/main/java/com/esv/freight/app/common/util/DateUtils.java
+324
-0
ReqUtils.java
src/main/java/com/esv/freight/app/common/util/ReqUtils.java
+42
-0
ValidatorDelete.java
.../freight/app/common/validator/groups/ValidatorDelete.java
+15
-0
ValidatorDetail.java
.../freight/app/common/validator/groups/ValidatorDetail.java
+15
-0
ValidatorInsert.java
.../freight/app/common/validator/groups/ValidatorInsert.java
+15
-0
ValidatorList.java
...sv/freight/app/common/validator/groups/ValidatorList.java
+15
-0
ValidatorUpdate.java
.../freight/app/common/validator/groups/ValidatorUpdate.java
+15
-0
PageResultVO.java
...main/java/com/esv/freight/app/common/vo/PageResultVO.java
+52
-0
RestRequestWrapper.java
...om/esv/freight/app/common/wrapper/RestRequestWrapper.java
+83
-0
RestResponseWrapper.java
...m/esv/freight/app/common/wrapper/RestResponseWrapper.java
+79
-0
CacheConfig.java
src/main/java/com/esv/freight/app/config/CacheConfig.java
+154
-0
FeignConfigure.java
src/main/java/com/esv/freight/app/config/FeignConfigure.java
+40
-0
FeignInterceptorConfig.java
...va/com/esv/freight/app/config/FeignInterceptorConfig.java
+35
-0
JacksonConfig.java
src/main/java/com/esv/freight/app/config/JacksonConfig.java
+28
-0
LogFilterConfig.java
...main/java/com/esv/freight/app/config/LogFilterConfig.java
+40
-0
MybatisPlusConfig.java
...in/java/com/esv/freight/app/config/MybatisPlusConfig.java
+28
-0
DictInterface.java
src/main/java/com/esv/freight/app/feign/DictInterface.java
+22
-0
NoticeInterface.java
src/main/java/com/esv/freight/app/feign/NoticeInterface.java
+23
-0
DriverAccountController.java
...pp/module/account/controller/DriverAccountController.java
+144
-0
DriverPasswordController.java
...p/module/account/controller/DriverPasswordController.java
+96
-0
OwnerAccountController.java
...app/module/account/controller/OwnerAccountController.java
+182
-0
OwnerPasswordController.java
...pp/module/account/controller/OwnerPasswordController.java
+97
-0
AppLoginDao.java
...a/com/esv/freight/app/module/account/dao/AppLoginDao.java
+18
-0
AppLoginEntity.java
...esv/freight/app/module/account/entity/AppLoginEntity.java
+67
-0
LoginByPwdForm.java
...m/esv/freight/app/module/account/form/LoginByPwdForm.java
+43
-0
LoginBySmsForm.java
...m/esv/freight/app/module/account/form/LoginBySmsForm.java
+42
-0
ModifyPasswordForm.java
...v/freight/app/module/account/form/ModifyPasswordForm.java
+42
-0
RealNameAuthForm.java
...esv/freight/app/module/account/form/RealNameAuthForm.java
+92
-0
RefreshTokenForm.java
...esv/freight/app/module/account/form/RefreshTokenForm.java
+24
-0
ResetPasswordForm.java
...sv/freight/app/module/account/form/ResetPasswordForm.java
+52
-0
AppLoginService.java
...v/freight/app/module/account/service/AppLoginService.java
+34
-0
AppLoginImpl.java
...freight/app/module/account/service/impl/AppLoginImpl.java
+222
-0
AccountDetailVO.java
...om/esv/freight/app/module/account/vo/AccountDetailVO.java
+43
-0
LoginVO.java
...n/java/com/esv/freight/app/module/account/vo/LoginVO.java
+33
-0
DeliveryAddressController.java
.../module/address/controller/DeliveryAddressController.java
+199
-0
ReceiveAddressController.java
...p/module/address/controller/ReceiveAddressController.java
+198
-0
CreateDeliveryAddressForm.java
...ht/app/module/address/form/CreateDeliveryAddressForm.java
+81
-0
CreateReceiveAddressForm.java
...ght/app/module/address/form/CreateReceiveAddressForm.java
+81
-0
DeleteAddressForm.java
...sv/freight/app/module/address/form/DeleteAddressForm.java
+24
-0
EditDeliveryAddressForm.java
...ight/app/module/address/form/EditDeliveryAddressForm.java
+87
-0
EditReceiveAddressForm.java
...eight/app/module/address/form/EditReceiveAddressForm.java
+87
-0
AddressAccountService.java
...ght/app/module/address/service/AddressAccountService.java
+17
-0
AddressAccountServiceImpl.java
...odule/address/service/impl/AddressAccountServiceImpl.java
+31
-0
DeliveryAddressItemVO.java
.../freight/app/module/address/vo/DeliveryAddressItemVO.java
+49
-0
DeliveryAddressListVO.java
.../freight/app/module/address/vo/DeliveryAddressListVO.java
+30
-0
ReceiveAddressItemVO.java
...v/freight/app/module/address/vo/ReceiveAddressItemVO.java
+49
-0
ReceiveAddressListVO.java
...v/freight/app/module/address/vo/ReceiveAddressListVO.java
+30
-0
OrderController.java
.../freight/app/module/order/controller/OrderController.java
+96
-0
AddOrderForm.java
...a/com/esv/freight/app/module/order/form/AddOrderForm.java
+111
-0
OrderListForm.java
.../com/esv/freight/app/module/order/form/OrderListForm.java
+46
-0
OrderListItemVO.java
.../com/esv/freight/app/module/order/vo/OrderListItemVO.java
+65
-0
OrderListVO.java
...java/com/esv/freight/app/module/order/vo/OrderListVO.java
+50
-0
OrderStatisticsVO.java
...om/esv/freight/app/module/order/vo/OrderStatisticsVO.java
+48
-0
application-dev.yml
src/main/resources/application-dev.yml
+56
-0
bootstrap.yml
src/main/resources/bootstrap.yml
+23
-0
logback-spring.xml
src/main/resources/logback-spring.xml
+58
-0
AppLoginDao.xml
src/main/resources/mapper/account/AppLoginDao.xml
+22
-0
No files found.
.gitignore
0 → 100644
View file @
b9743359
*.class
*.iml
*.log
/*.iml
/.idea/
/log/
/logs/
*/target/
/target/
pom.xml
0 → 100644
View file @
b9743359
<?xml version="1.0" encoding="UTF-8"?>
<project
xmlns=
"http://maven.apache.org/POM/4.0.0"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<modelVersion>
4.0.0
</modelVersion>
<parent>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-parent
</artifactId>
<version>
2.1.1.RELEASE
</version>
</parent>
<groupId>
com.esv.freight
</groupId>
<artifactId>
app-service
</artifactId>
<version>
1.0.0-SNAPSHOT
</version>
<name>
freight-app-service
</name>
<description>
freight-app
</description>
<properties>
<project.build.sourceEncoding>
UTF-8
</project.build.sourceEncoding>
<java.version>
1.8
</java.version>
<spring-cloud.version>
Greenwich.SR1
</spring-cloud.version>
<alibaba-nacos-discovery.version>
2.1.1.RELEASE
</alibaba-nacos-discovery.version>
<alibaba-nacos-config.version>
2.1.1.RELEASE
</alibaba-nacos-config.version>
<alibaba-fastjson.version>
1.2.62
</alibaba-fastjson.version>
<alibaba-druid.version>
1.1.21
</alibaba-druid.version>
<apache-commons-lang3.version>
3.7
</apache-commons-lang3.version>
<mybatisplus.version>
3.3.1
</mybatisplus.version>
</properties>
<dependencies>
<dependency>
<groupId>
com.esv.platform
</groupId>
<artifactId>
gateway-common
</artifactId>
<version>
1.0.0-SNAPSHOT
</version>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-web
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-test
</artifactId>
<scope>
test
</scope>
</dependency>
<dependency>
<groupId>
junit
</groupId>
<artifactId>
junit
</artifactId>
<scope>
test
</scope>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-configuration-processor
</artifactId>
<optional>
true
</optional>
</dependency>
<dependency>
<groupId>
com.alibaba.cloud
</groupId>
<artifactId>
spring-cloud-starter-alibaba-nacos-discovery
</artifactId>
<version>
${alibaba-nacos-discovery.version}
</version>
</dependency>
<dependency>
<groupId>
com.alibaba.cloud
</groupId>
<artifactId>
spring-cloud-starter-alibaba-nacos-config
</artifactId>
<version>
${alibaba-nacos-config.version}
</version>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-cache
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-data-redis
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.cloud
</groupId>
<artifactId>
spring-cloud-starter-openfeign
</artifactId>
</dependency>
<dependency>
<groupId>
com.alibaba
</groupId>
<artifactId>
fastjson
</artifactId>
<version>
${alibaba-fastjson.version}
</version>
</dependency>
<dependency>
<groupId>
org.apache.commons
</groupId>
<artifactId>
commons-lang3
</artifactId>
<version>
${apache-commons-lang3.version}
</version>
</dependency>
<dependency>
<groupId>
org.projectlombok
</groupId>
<artifactId>
lombok
</artifactId>
<optional>
true
</optional>
</dependency>
<dependency>
<groupId>
com.fasterxml.jackson.core
</groupId>
<artifactId>
jackson-annotations
</artifactId>
</dependency>
<dependency>
<groupId>
joda-time
</groupId>
<artifactId>
joda-time
</artifactId>
</dependency>
<dependency>
<groupId>
mysql
</groupId>
<artifactId>
mysql-connector-java
</artifactId>
</dependency>
<dependency>
<groupId>
com.baomidou
</groupId>
<artifactId>
mybatis-plus-boot-starter
</artifactId>
<version>
${mybatisplus.version}
</version>
</dependency>
<dependency>
<groupId>
com.alibaba
</groupId>
<artifactId>
druid-spring-boot-starter
</artifactId>
<version>
${alibaba-druid.version}
</version>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>
org.springframework.cloud
</groupId>
<artifactId>
spring-cloud-dependencies
</artifactId>
<version>
${spring-cloud.version}
</version>
<type>
pom
</type>
<scope>
import
</scope>
</dependency>
</dependencies>
</dependencyManagement>
<repositories>
<repository>
<id>
esv-repository
</id>
<url>
http://192.168.31.249:18084/repository/maven-public/
</url>
<!-- 外网环境使用 -->
<!-- <url>http://esvsy.wicp.vip:18084/repository/maven-public/</url>-->
</repository>
</repositories>
<profiles>
<profile>
<id>
develop
</id>
<build>
<plugins>
<plugin>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-surefire-plugin
</artifactId>
<configuration>
<skipTests>
false
</skipTests>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>
release
</id>
<build>
<resources>
<resource>
<directory>
src/main/resources
</directory>
<excludes>
<exclude>
*.yml
</exclude>
<exclude>
application*.properties
</exclude>
<exclude>
bootstrap.properties
</exclude>
<exclude>
logback-spring.xml
</exclude>
</excludes>
<filtering>
true
</filtering>
</resource>
</resources>
</build>
</profile>
</profiles>
<build>
<plugins>
<plugin>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-maven-plugin
</artifactId>
<configuration>
<includeSystemScope>
true
</includeSystemScope>
</configuration>
</plugin>
<plugin>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-resources-plugin
</artifactId>
<configuration>
<nonFilteredFileExtensions>
<nonFilteredFileExtension>
woff
</nonFilteredFileExtension>
<nonFilteredFileExtension>
woff2
</nonFilteredFileExtension>
<nonFilteredFileExtension>
eot
</nonFilteredFileExtension>
<nonFilteredFileExtension>
ttf
</nonFilteredFileExtension>
<nonFilteredFileExtension>
svg
</nonFilteredFileExtension>
</nonFilteredFileExtensions>
</configuration>
</plugin>
</plugins>
<resources>
<resource>
<directory>
src/main/resources
</directory>
<includes>
<include>
**/*.*
</include>
</includes>
<excludes>
</excludes>
<filtering>
true
</filtering>
</resource>
</resources>
</build>
</project>
src/main/java/com/esv/freight/app/AppApplication.java
0 → 100644
View file @
b9743359
package
com
.
esv
.
freight
.
app
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
import
org.springframework.cloud.client.discovery.EnableDiscoveryClient
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.web.context.request.RequestContextListener
;
/**
* @description: 启动类
* @project: Spring-Cloud-Single-Template
* @name: com.esv.freight.TemplateApplication
* @author: 黄朝斌
* @email: huangchaobin@esvtek.com
* @createTime: 2020/04/07 15:17
* @version:1.0
*/
@SpringBootApplication
@EnableDiscoveryClient
public
class
AppApplication
{
public
static
void
main
(
String
[]
args
)
{
SpringApplication
.
run
(
AppApplication
.
class
,
args
);
}
@Bean
public
RequestContextListener
requestContextListener
(){
return
new
RequestContextListener
();
}
}
src/main/java/com/esv/freight/app/common/component/RedisComponent.java
0 → 100644
View file @
b9743359
package
com
.
esv
.
freight
.
app
.
common
.
component
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.data.redis.core.RedisTemplate
;
import
org.springframework.stereotype.Component
;
import
org.springframework.util.CollectionUtils
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Set
;
import
java.util.concurrent.TimeUnit
;
/**
* @description: RedisTemplate封装组件
* @project: Spring-Cloud-Single-Template
* @name: com.esv.freight.common.component.RedisComponent
* @author: 黄朝斌
* @email: huangchaobin@esvtek.com
* @createTime: 2020/04/09 10:02
* @version:1.0
*/
@Component
@Slf4j
public
class
RedisComponent
{
private
RedisTemplate
<
String
,
Object
>
redisTemplate
;
@Autowired
public
RedisComponent
(
RedisTemplate
<
String
,
Object
>
redisTemplate
)
{
this
.
redisTemplate
=
redisTemplate
;
}
/**
* 指定缓存失效时间
*
* @param key 键
* @param time 时间(秒)
* @return
*/
public
boolean
expire
(
String
key
,
long
time
)
{
if
(
0L
>=
time
)
{
return
false
;
}
try
{
redisTemplate
.
expire
(
key
,
time
,
TimeUnit
.
SECONDS
);
return
true
;
}
catch
(
Exception
e
)
{
log
.
error
(
e
.
getMessage
(),
e
);
return
false
;
}
}
/**
* 根据key 获取过期时间
*
* @param key 键 不能为null
* @return 时间(秒) 返回0代表为永久有效
*/
public
long
getExpire
(
String
key
)
{
return
redisTemplate
.
getExpire
(
key
,
TimeUnit
.
SECONDS
);
}
/**
* 判断key是否存在
*
* @param key 键
* @return true 存在 false不存在
*/
public
boolean
hasKey
(
String
key
)
{
try
{
return
redisTemplate
.
hasKey
(
key
);
}
catch
(
Exception
e
)
{
log
.
error
(
e
.
getMessage
(),
e
);
return
false
;
}
}
/**
* 删除缓存
*
* @param key 可以传一个值 或多个
*/
@SuppressWarnings
(
"unchecked"
)
public
void
del
(
String
...
key
)
{
if
(
key
!=
null
&&
key
.
length
>
0
)
{
if
(
key
.
length
==
1
)
{
redisTemplate
.
delete
(
key
[
0
]);
}
else
{
redisTemplate
.
delete
(
CollectionUtils
.
arrayToList
(
key
));
}
}
}
//================================String=================================
/**
* 普通缓存获取
*
* @param key 键
* @return 值
*/
public
Object
get
(
String
key
)
{
return
key
==
null
?
null
:
redisTemplate
.
opsForValue
().
get
(
key
);
}
/**
* 普通缓存放入并设置时间
*
* @param key 键
* @param value 值
* @param time 时间(秒) time要大于0
* @return true成功 false 失败
*/
public
boolean
set
(
String
key
,
Object
value
,
long
time
)
{
try
{
if
(
time
>
0
)
{
redisTemplate
.
opsForValue
().
set
(
key
,
value
,
time
,
TimeUnit
.
SECONDS
);
return
true
;
}
else
{
return
false
;
}
}
catch
(
Exception
e
)
{
log
.
error
(
e
.
getMessage
(),
e
);
return
false
;
}
}
/**
* 递增
*
* @param key 键
* @param delta 要增加几(大于0)
* @return
*/
public
long
incr
(
String
key
,
long
delta
)
{
if
(
delta
<
0
)
{
throw
new
RuntimeException
(
"递增因子必须大于0"
);
}
return
redisTemplate
.
opsForValue
().
increment
(
key
,
delta
);
}
/**
* 递减
*
* @param key 键
* @param delta 要减少几(小于0)
* @return
*/
public
long
decr
(
String
key
,
long
delta
)
{
if
(
delta
<
0
)
{
throw
new
RuntimeException
(
"递减因子必须大于0"
);
}
return
redisTemplate
.
opsForValue
().
increment
(
key
,
-
delta
);
}
//================================Map=================================
/**
* HashGet
*
* @param key 键 不能为null
* @param item 项 不能为null
* @return 值
*/
public
Object
hget
(
String
key
,
String
item
)
{
return
redisTemplate
.
opsForHash
().
get
(
key
,
item
);
}
/**
* 获取hashKey对应的所有键值
*
* @param key 键
* @return 对应的多个键值
*/
public
Map
<
Object
,
Object
>
hmget
(
String
key
)
{
return
redisTemplate
.
opsForHash
().
entries
(
key
);
}
/**
* HashSet 并设置时间
*
* @param key 键
* @param map 对应多个键值
* @param time 时间(秒)
* @return true成功 false失败
*/
public
boolean
hmset
(
String
key
,
Map
<
String
,
Object
>
map
,
long
time
)
{
if
(
0L
>=
time
)
{
return
false
;
}
try
{
redisTemplate
.
opsForHash
().
putAll
(
key
,
map
);
expire
(
key
,
time
);
return
true
;
}
catch
(
Exception
e
)
{
log
.
error
(
e
.
getMessage
(),
e
);
return
false
;
}
}
/**
* 向一张hash表中放入数据,如果不存在将创建
*
* @param key 键
* @param item 项
* @param value 值
* @param time 时间(秒) 注意:如果已存在的hash表有时间,这里将会替换原有的时间
* @return true 成功 false失败
*/
public
boolean
hset
(
String
key
,
String
item
,
Object
value
,
long
time
)
{
if
(
0L
>=
time
)
{
return
false
;
}
try
{
redisTemplate
.
opsForHash
().
put
(
key
,
item
,
value
);
expire
(
key
,
time
);
return
true
;
}
catch
(
Exception
e
)
{
log
.
error
(
e
.
getMessage
(),
e
);
return
false
;
}
}
/**
* 删除hash表中的值
*
* @param key 键 不能为null
* @param item 项 可以使多个 不能为null
*/
public
void
hdel
(
String
key
,
Object
...
item
)
{
redisTemplate
.
opsForHash
().
delete
(
key
,
item
);
}
/**
* 判断hash表中是否有该项的值
*
* @param key 键 不能为null
* @param item 项 不能为null
* @return true 存在 false不存在
*/
public
boolean
hHasKey
(
String
key
,
String
item
)
{
return
redisTemplate
.
opsForHash
().
hasKey
(
key
,
item
);
}
/**
* hash递增 如果不存在,就会创建一个 并把新增后的值返回
*
* @param key 键
* @param item 项
* @param by 要增加几(大于0)
* @return
*/
public
double
hincr
(
String
key
,
String
item
,
double
by
)
{
return
redisTemplate
.
opsForHash
().
increment
(
key
,
item
,
by
);
}
/**
* hash递减
*
* @param key 键
* @param item 项
* @param by 要减少记(小于0)
* @return
*/
public
double
hdecr
(
String
key
,
String
item
,
double
by
)
{
return
redisTemplate
.
opsForHash
().
increment
(
key
,
item
,
-
by
);
}
//============================set=============================
/**
* 根据key获取Set中的所有值
*
* @param key 键
* @return
*/
public
Set
<
Object
>
sGet
(
String
key
)
{
try
{
return
redisTemplate
.
opsForSet
().
members
(
key
);
}
catch
(
Exception
e
)
{
log
.
error
(
e
.
getMessage
(),
e
);
return
null
;
}
}
/**
* 根据value从一个set中查询,是否存在
*
* @param key 键
* @param value 值
* @return true 存在 false不存在
*/
public
boolean
sHasKey
(
String
key
,
Object
value
)
{
try
{
return
redisTemplate
.
opsForSet
().
isMember
(
key
,
value
);
}
catch
(
Exception
e
)
{
log
.
error
(
e
.
getMessage
(),
e
);
return
false
;
}
}
/**
* 将数据放入set缓存
*
* @param key 键
* @param values 值 可以是多个
* @return 成功个数
*/
public
long
sSet
(
String
key
,
Object
...
values
)
{
try
{
return
redisTemplate
.
opsForSet
().
add
(
key
,
values
);
}
catch
(
Exception
e
)
{
log
.
error
(
e
.
getMessage
(),
e
);
return
0
;
}
}
/**
* 将set数据放入缓存
*
* @param key 键
* @param time 时间(秒)
* @param values 值 可以是多个
* @return 成功个数
*/
public
long
sSetAndTime
(
String
key
,
long
time
,
Object
...
values
)
{
if
(
0L
>=
time
)
{
return
0L
;
}
try
{
Long
count
=
redisTemplate
.
opsForSet
().
add
(
key
,
values
);
expire
(
key
,
time
);
return
count
;
}
catch
(
Exception
e
)
{
log
.
error
(
e
.
getMessage
(),
e
);
return
0
;
}
}
/**
* 获取set缓存的长度
*
* @param key 键
* @return
*/
public
long
sGetSetSize
(
String
key
)
{
try
{
return
redisTemplate
.
opsForSet
().
size
(
key
);
}
catch
(
Exception
e
)
{
log
.
error
(
e
.
getMessage
(),
e
);
return
0
;
}
}
/**
* 移除值为value的
*
* @param key 键
* @param values 值 可以是多个
* @return 移除的个数
*/
public
long
setRemove
(
String
key
,
Object
...
values
)
{
try
{
Long
count
=
redisTemplate
.
opsForSet
().
remove
(
key
,
values
);
return
count
;
}
catch
(
Exception
e
)
{
log
.
error
(
e
.
getMessage
(),
e
);
return
0
;
}
}
//===============================list=================================
/**
* 获取list缓存的内容
*
* @param key 键
* @param start 开始
* @param end 结束 0 到 -1代表所有值
* @return
*/
public
List
<
Object
>
lGet
(
String
key
,
long
start
,
long
end
)
{
try
{
return
redisTemplate
.
opsForList
().
range
(
key
,
start
,
end
);
}
catch
(
Exception
e
)
{
log
.
error
(
e
.
getMessage
(),
e
);
return
null
;
}
}
/**
* 获取list缓存的长度
*
* @param key 键
* @return
*/
public
long
lGetListSize
(
String
key
)
{
try
{
return
redisTemplate
.
opsForList
().
size
(
key
);
}
catch
(
Exception
e
)
{
log
.
error
(
e
.
getMessage
(),
e
);
return
0
;
}
}
/**
* 通过索引 获取list中的值
*
* @param key 键
* @param index 索引 index>=0时, 0 表头,1 第二个元素,依次类推;index<0时,-1,表尾,-2倒数第二个元素,依次类推
* @return
*/
public
Object
lGetIndex
(
String
key
,
long
index
)
{
try
{
return
redisTemplate
.
opsForList
().
index
(
key
,
index
);
}
catch
(
Exception
e
)
{
log
.
error
(
e
.
getMessage
(),
e
);
return
null
;
}
}
/**
* 将list放入缓存
*
* @param key 键
* @param value 值
* @param time 时间(秒)
* @return
*/
public
boolean
lSet
(
String
key
,
Object
value
,
long
time
)
{
if
(
0L
>=
time
)
{
return
false
;
}
try
{
redisTemplate
.
opsForList
().
rightPush
(
key
,
value
);
expire
(
key
,
time
);
return
true
;
}
catch
(
Exception
e
)
{
log
.
error
(
e
.
getMessage
(),
e
);
return
false
;
}
}
/**
* 将list放入缓存
*
* @param key 键
* @param value 值
* @return
*/
public
boolean
lSet
(
String
key
,
List
<
Object
>
value
)
{
try
{
redisTemplate
.
opsForList
().
rightPushAll
(
key
,
value
);
return
true
;
}
catch
(
Exception
e
)
{
log
.
error
(
e
.
getMessage
(),
e
);
return
false
;
}
}
/**
* 将list放入缓存
*
* @param key 键
* @param value 值
* @param time 时间(秒)
* @return
*/
public
boolean
lSet
(
String
key
,
List
<
Object
>
value
,
long
time
)
{
if
(
0L
>=
time
)
{
return
false
;
}
try
{
redisTemplate
.
opsForList
().
rightPushAll
(
key
,
value
);
expire
(
key
,
time
);
return
true
;
}
catch
(
Exception
e
)
{
log
.
error
(
e
.
getMessage
(),
e
);
return
false
;
}
}
/**
* 根据索引修改list中的某条数据
*
* @param key 键
* @param index 索引
* @param value 值
* @return
*/
public
boolean
lUpdateIndex
(
String
key
,
long
index
,
Object
value
)
{
try
{
redisTemplate
.
opsForList
().
set
(
key
,
index
,
value
);
return
true
;
}
catch
(
Exception
e
)
{
log
.
error
(
e
.
getMessage
(),
e
);
return
false
;
}
}
/**
* 移除N个值为value
*
* @param key 键
* @param count 移除多少个
* @param value 值
* @return 移除的个数
*/
public
long
lRemove
(
String
key
,
long
count
,
Object
value
)
{
try
{
Long
remove
=
redisTemplate
.
opsForList
().
remove
(
key
,
count
,
value
);
return
remove
;
}
catch
(
Exception
e
)
{
log
.
error
(
e
.
getMessage
(),
e
);
return
0
;
}
}
}
src/main/java/com/esv/freight/app/common/constants/DbDeletedEnum.java
0 → 100644
View file @
b9743359
package
com
.
esv
.
freight
.
app
.
common
.
constants
;
/**
* @description: DB记录是否删除标识
* @project: SpringCloudTemplate
* @name: com.esv.springcloud.template.common.constants.DbDeletedEnum
* @author: 黄朝斌
* @email: huangchaobin@esvtek.com
* @createTime: 2020/03/13 15:08
* @version:1.0
*/
public
enum
DbDeletedEnum
{
NO
(
false
,
"未删除"
),
YES
(
true
,
"已删除"
);
private
Boolean
code
;
private
String
message
;
DbDeletedEnum
(
Boolean
code
,
String
message
)
{
this
.
code
=
code
;
this
.
message
=
message
;
}
public
Boolean
getCode
()
{
return
code
;
}
public
void
setCode
(
Boolean
code
)
{
this
.
code
=
code
;
}
public
String
getMessage
()
{
return
message
;
}
public
void
setMessage
(
String
message
)
{
this
.
message
=
message
;
}
}
src/main/java/com/esv/freight/app/common/exception/EException.java
0 → 100644
View file @
b9743359
package
com
.
esv
.
freight
.
app
.
common
.
exception
;
/**
* @description: 自定义业务异常
* @project: SpringCloudTemplate
* @name: com.esv.springcloud.template.common.exception.EException
* @author: 黄朝斌
* @email: huangchaobin@esvtek.com
* @createTime: 2020/03/12 17:21
* @version:1.0
*/
public
class
EException
extends
RuntimeException
{
private
static
final
long
serialVersionUID
=
1L
;
private
int
code
=
500
;
private
String
message
;
public
EException
(
String
message
)
{
super
(
message
);
this
.
message
=
message
;
}
public
EException
(
String
message
,
Throwable
e
)
{
super
(
message
,
e
);
this
.
message
=
message
;
}
public
EException
(
int
code
,
String
message
)
{
super
(
message
);
this
.
code
=
code
;
this
.
message
=
message
;
}
public
EException
(
int
code
,
String
message
,
Throwable
e
)
{
super
(
message
,
e
);
this
.
code
=
code
;
this
.
message
=
message
;
}
public
int
getCode
()
{
return
code
;
}
public
void
setCode
(
int
code
)
{
this
.
code
=
code
;
}
@Override
public
String
getMessage
()
{
return
message
;
}
public
void
setMessage
(
String
message
)
{
this
.
message
=
message
;
}
}
src/main/java/com/esv/freight/app/common/filter/LogbackFilter.java
0 → 100644
View file @
b9743359
package
com
.
esv
.
freight
.
app
.
common
.
filter
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang3.StringUtils
;
import
org.slf4j.MDC
;
import
javax.servlet.*
;
import
javax.servlet.http.HttpServletRequest
;
import
java.io.IOException
;
import
java.util.UUID
;
/**
* @description: 处理Logback traceId过滤器
* @project: SpringCloudTemplate
* @name: com.esv.springcloud.template.common.filter.LogbackFilter
* @author: 黄朝斌
* @email: huangchaobin@esvtek.com
* @createTime: 2020/03/13 11:35
* @version:1.0
*/
@Slf4j
public
class
LogbackFilter
implements
Filter
{
@Override
public
void
init
(
FilterConfig
filterConfig
)
throws
ServletException
{
}
@Override
public
void
doFilter
(
ServletRequest
servletRequest
,
ServletResponse
servletResponse
,
FilterChain
filterChain
)
throws
IOException
,
ServletException
{
// 获取来自上游服务的传参traceId
HttpServletRequest
httpServletRequest
=
(
HttpServletRequest
)
servletRequest
;
String
traceId
=
httpServletRequest
.
getHeader
(
"trace_id"
);
boolean
bInsertMDC
=
setMDC
(
traceId
);
try
{
filterChain
.
doFilter
(
servletRequest
,
servletResponse
);
}
finally
{
if
(
bInsertMDC
)
{
MDC
.
remove
(
"traceId"
);
}
}
}
@Override
public
void
destroy
()
{
}
private
boolean
setMDC
(
String
traceId
)
{
if
(
StringUtils
.
isEmpty
(
traceId
)
||
"null"
.
equalsIgnoreCase
(
traceId
))
{
traceId
=
UUID
.
randomUUID
().
toString
().
replace
(
"-"
,
""
);
}
MDC
.
put
(
"traceId"
,
traceId
);
return
true
;
}
}
src/main/java/com/esv/freight/app/common/filter/RestLogFilter.java
0 → 100644
View file @
b9743359
package
com
.
esv
.
freight
.
app
.
common
.
filter
;
import
com.esv.freight.app.common.wrapper.RestRequestWrapper
;
import
com.esv.freight.app.common.wrapper.RestResponseWrapper
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang3.StringUtils
;
import
javax.servlet.*
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.BufferedReader
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.InputStreamReader
;
import
java.nio.charset.Charset
;
import
java.util.Enumeration
;
import
java.util.HashMap
;
import
java.util.Map
;
/**
* @description: Rest请求日志Filter
* @project: SpringCloudTemplate
* @name: com.esv.springcloud.template.web.filter.RestLogFilter
* @author: 黄朝斌
* @email: huangchaobin@esvtek.com
* @createTime: 2020/03/09 17:44
* @version:1.0
*/
@Slf4j
public
class
RestLogFilter
implements
Filter
{
@Override
public
void
init
(
FilterConfig
filterConfig
)
{
}
@Override
public
void
doFilter
(
ServletRequest
servletRequest
,
ServletResponse
servletResponse
,
FilterChain
filterChain
)
throws
IOException
,
ServletException
{
RestRequestWrapper
requestWrapper
=
new
RestRequestWrapper
((
HttpServletRequest
)
servletRequest
);
RestResponseWrapper
responseWrapper
=
new
RestResponseWrapper
((
HttpServletResponse
)
servletResponse
);
String
reqContentType
=
StringUtils
.
trimToEmpty
(
requestWrapper
.
getContentType
()).
toLowerCase
();
if
(
reqContentType
.
contains
(
"multipart/form-data"
))
{
log
.
info
(
"multipart/form-data request"
);
}
else
{
// 日志输出请求
logReq
(
requestWrapper
);
}
filterChain
.
doFilter
(
requestWrapper
,
responseWrapper
);
String
resContentType
=
StringUtils
.
trimToEmpty
(
responseWrapper
.
getContentType
());
if
(
resContentType
.
contains
(
"text"
)
||
resContentType
.
contains
(
"xml"
)
||
resContentType
.
contains
(
"json"
))
{
// 日志输出返回
try
{
logRes
(
requestWrapper
,
responseWrapper
);
}
catch
(
Exception
e
)
{
log
.
error
(
e
.
getMessage
(),
e
);
}
}
else
{
log
.
info
(
"Response ContentType: {}"
,
resContentType
);
}
}
@Override
public
void
destroy
()
{
}
private
String
getPostBodyStr
(
HttpServletRequest
request
)
{
String
bodyStr
=
null
;
StringBuilder
sb
=
new
StringBuilder
();
InputStream
inputStream
=
null
;
BufferedReader
reader
=
null
;
try
{
inputStream
=
request
.
getInputStream
();
reader
=
new
BufferedReader
(
new
InputStreamReader
(
inputStream
,
Charset
.
forName
(
"UTF-8"
)));
String
line
=
""
;
while
((
line
=
reader
.
readLine
())
!=
null
)
{
sb
.
append
(
line
);
}
if
(
0
==
sb
.
length
())
{
Map
<
String
,
String
>
bodyMap
=
new
HashMap
<>();
Map
<
String
,
String
[]>
parameterMap
=
request
.
getParameterMap
();
for
(
Map
.
Entry
<
String
,
String
[]>
entry
:
parameterMap
.
entrySet
())
{
for
(
String
value
:
entry
.
getValue
())
{
bodyMap
.
put
(
entry
.
getKey
(),
value
);
}
}
bodyStr
=
bodyMap
.
toString
();
}
else
{
bodyStr
=
sb
.
toString
();
}
}
catch
(
IOException
e
)
{
log
.
error
(
"解析post参数时发生错误:{}"
,
e
.
getMessage
());
}
finally
{
if
(
inputStream
!=
null
)
{
try
{
inputStream
.
close
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
if
(
reader
!=
null
)
{
try
{
reader
.
close
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
}
return
bodyStr
;
}
private
void
logReq
(
RestRequestWrapper
requestWrapper
)
{
String
url
=
requestWrapper
.
getRequestURI
();
String
method
=
requestWrapper
.
getMethod
();
if
(
"GET"
.
equalsIgnoreCase
(
method
))
{
Enumeration
em
=
requestWrapper
.
getParameterNames
();
String
reqParams
=
""
;
while
(
em
.
hasMoreElements
())
{
String
k
=
em
.
nextElement
().
toString
();
String
v
=
requestWrapper
.
getParameter
(
k
);
reqParams
+=
"&"
+
k
+
"="
+
v
;
}
reqParams
=
reqParams
.
replaceFirst
(
"&"
,
""
);
if
(
url
.
startsWith
(
"/actuator"
))
{
log
.
debug
(
"[IP={}]收到{}请求,url:{},params:{}"
,
getHttpClientIp
(
requestWrapper
),
method
,
url
,
reqParams
);
}
else
{
log
.
info
(
"[IP={}]收到{}请求,url:{},params:{}"
,
getHttpClientIp
(
requestWrapper
),
method
,
url
,
reqParams
);
}
}
else
if
(
"POST"
.
equalsIgnoreCase
(
method
))
{
log
.
info
(
"[IP={}]收到{}请求,url:{},body:{}"
,
getHttpClientIp
(
requestWrapper
),
method
,
url
,
getPostBodyStr
(
requestWrapper
));
}
else
{
}
}
private
void
logRes
(
RestRequestWrapper
requestWrapper
,
RestResponseWrapper
responseWrapper
)
throws
Exception
{
byte
[]
bytes
=
responseWrapper
.
getBody
();
String
resStr
=
new
String
(
bytes
,
"utf-8"
);
String
url
=
requestWrapper
.
getRequestURI
();
if
(
url
.
startsWith
(
"/actuator"
))
{
log
.
debug
(
"请求响应:{}"
,
resStr
);
}
else
{
log
.
info
(
"请求响应:{}"
,
resStr
);
}
}
private
String
getHttpClientIp
(
HttpServletRequest
req
){
String
ip
=
req
.
getHeader
(
"x-forwarded-for"
);
if
(
ip
==
null
||
ip
.
length
()
==
0
||
"unknown"
.
equalsIgnoreCase
(
ip
))
{
ip
=
req
.
getHeader
(
"Proxy-Client-IP"
);
}
if
(
ip
==
null
||
ip
.
length
()
==
0
||
"unknown"
.
equalsIgnoreCase
(
ip
))
{
ip
=
req
.
getHeader
(
"WL-Proxy-Client-IP"
);
}
if
(
ip
==
null
||
ip
.
length
()
==
0
||
"unknown"
.
equalsIgnoreCase
(
ip
))
{
ip
=
req
.
getRemoteAddr
();
}
return
ip
;
}
}
\ No newline at end of file
src/main/java/com/esv/freight/app/common/handler/RestExceptionHandler.java
0 → 100644
View file @
b9743359
package
com
.
esv
.
freight
.
app
.
common
.
handler
;
import
com.esv.freight.app.common.exception.EException
;
import
com.esv.freight.app.common.response.EResponse
;
import
com.esv.freight.app.common.response.ECode
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.context.support.DefaultMessageSourceResolvable
;
import
org.springframework.web.bind.MethodArgumentNotValidException
;
import
org.springframework.web.bind.MissingServletRequestParameterException
;
import
org.springframework.web.bind.annotation.ExceptionHandler
;
import
org.springframework.web.bind.annotation.RestControllerAdvice
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.validation.ConstraintViolationException
;
import
java.util.stream.Collectors
;
/**
* @description:
* @project: SpringCloudTemplate
* @name: com.esv.springcloud.template.common.handler.RestExceptionHandler
* @author: 黄朝斌
* @email: huangchaobin@esvtek.com
* @createTime: 2020/03/12 17:41
* @version:1.0
*/
@Slf4j
@RestControllerAdvice
public
class
RestExceptionHandler
{
@ExceptionHandler
(
value
=
Exception
.
class
)
public
EResponse
defaultErrorHandler
(
HttpServletRequest
req
,
Exception
e
)
{
EResponse
r
;
if
(
e
instanceof
EException
)
{
r
=
EResponse
.
error
(((
EException
)
e
).
getCode
(),
e
.
getMessage
());
}
else
if
(
e
instanceof
MethodArgumentNotValidException
)
{
String
message
=
((
MethodArgumentNotValidException
)
e
).
getBindingResult
().
getAllErrors
().
stream
().
map
(
DefaultMessageSourceResolvable:
:
getDefaultMessage
).
collect
(
Collectors
.
joining
(
"|"
));
r
=
EResponse
.
error
(
ECode
.
PARAM_ERROR
.
code
(),
ECode
.
PARAM_ERROR
.
message
()
+
"["
+
message
+
"]"
);
}
else
if
(
e
instanceof
ConstraintViolationException
)
{
String
message
=
e
.
getMessage
();
if
(
message
.
contains
(
":"
))
{
message
=
message
.
split
(
":"
)[
1
];
}
r
=
EResponse
.
error
(
ECode
.
PARAM_ERROR
.
code
(),
ECode
.
PARAM_ERROR
.
message
()
+
"["
+
message
+
"]"
);
}
else
if
(
e
instanceof
MissingServletRequestParameterException
)
{
r
=
EResponse
.
error
(
ECode
.
PARAM_ERROR
.
code
(),
ECode
.
PARAM_ERROR
.
message
()
+
"["
+
e
.
getMessage
()
+
"]"
);
}
else
{
r
=
EResponse
.
error
(
ECode
.
SERVER_ERROR
);
log
.
error
(
e
.
getMessage
(),
e
);
}
return
r
;
}
}
src/main/java/com/esv/freight/app/common/response/ECode.java
0 → 100644
View file @
b9743359
package
com
.
esv
.
freight
.
app
.
common
.
response
;
/**
* @description: 系统响应码
* @project: SpringCloudTemplate
* @name: com.esv.springcloud.template.common.response.ECode
* @author: 黄朝斌
* @email: huangchaobin@esvtek.com
* @createTime: 2020/03/12 17:34
* @version:1.0
*/
public
class
ECode
{
public
static
final
ECode
SUCCESS
=
new
ECode
(
200
,
"success"
);
public
static
final
ECode
ACCESS_DENIED
=
new
ECode
(
401
,
"没有访问权限"
);
public
static
final
ECode
SERVER_ERROR
=
new
ECode
(
500
,
"服务内部错误"
);
public
static
final
ECode
SERVICE_UNAVAILABLE
=
new
ECode
(
503
,
"服务限流,暂不可用"
);
public
static
final
ECode
PARAM_ERROR
=
new
ECode
(
600
,
"参数不合法"
);
public
static
final
ECode
TOKEN_INVALID
=
new
ECode
(
601
,
"无效的Token"
);
public
static
final
ECode
TOKEN_EXPIRED
=
new
ECode
(
602
,
"Token已过期"
);
public
ECode
(
int
code
,
String
message
)
{
this
.
code
=
code
;
this
.
message
=
message
;
}
private
int
code
;
private
String
message
;
public
int
code
()
{
return
code
;
}
public
String
message
()
{
return
message
;
}
}
src/main/java/com/esv/freight/app/common/response/EResponse.java
0 → 100644
View file @
b9743359
package
com
.
esv
.
freight
.
app
.
common
.
response
;
import
java.io.Serializable
;
/**
* @description: Rest请求统一返回对象
* @project: SpringCloudTemplate
* @name: com.esv.springcloud.template.common.response.EResponse
* @author: 黄朝斌
* @email: huangchaobin@esvtek.com
* @createTime: 2020/03/12 17:23
* @version:1.0
*/
public
class
EResponse
<
T
>
implements
Serializable
{
private
static
final
long
serialVersionUID
=
6472520481853704969L
;
private
int
code
;
private
String
message
;
private
long
responseTime
;
private
T
data
;
private
EResponse
()
{
this
.
responseTime
=
System
.
currentTimeMillis
();
}
private
EResponse
(
int
code
,
String
message
)
{
this
();
this
.
code
=
code
;
this
.
message
=
message
;
}
private
EResponse
(
ECode
eCode
)
{
this
(
eCode
.
code
(),
eCode
.
message
());
}
private
EResponse
(
T
data
)
{
this
(
ECode
.
SUCCESS
);
this
.
data
=
data
;
}
/**
* description 成功返回
* param []
* return com.esv.common.response.EResponse
* author chenfm
* createTime 2020/3/6 14:50
**/
public
static
EResponse
ok
()
{
return
new
EResponse
(
ECode
.
SUCCESS
);
}
/**
* description 成功返回(带数据)
* param [data] 返回数据
* return com.esv.common.response.EResponse<T>
* author chenfm
* createTime 2020/3/6 14:50
**/
public
static
<
T
>
EResponse
<
T
>
ok
(
T
data
)
{
return
new
EResponse
<
T
>(
data
);
}
/**
* description 返回默认系统异常
* param []
* return com.esv.springcloud.template.common.response.EResponse
* author Administrator
* createTime 2020/03/13 15:36
**/
public
static
EResponse
error
()
{
return
error
(
ECode
.
SERVER_ERROR
);
}
/**
* description 返回自定义code、message异常
* param []
* return com.esv.common.response.EResponse
* author chenfm
* createTime 2020/3/9 13:32
*
* @param code
* @param message*/
public
static
EResponse
error
(
int
code
,
String
message
)
{
return
new
EResponse
(
code
,
message
);
}
/**
* description 异常返回
* param [rCode] 异常码
* return com.esv.common.response.EResponse
* author chenfm
* createTime 2020/3/6 14:50
**/
public
static
EResponse
error
(
ECode
eCode
)
{
return
new
EResponse
(
eCode
);
}
/**
* description 判断返回是否成功
* param []
* return boolean
* author chenfm
* createTime 2020/3/6 14:51
**/
public
boolean
success
()
{
return
this
.
code
==
ECode
.
SUCCESS
.
code
();
}
/**
* description 修改提示信息
* param [message] 提示信息
* return void
* author chenfm
* createTime 2020/3/6 17:44
**/
public
EResponse
message
(
String
message
)
{
this
.
message
=
message
;
return
this
;
}
public
int
getCode
()
{
return
this
.
code
;
}
public
String
getMessage
()
{
return
message
;
}
public
long
getTime
()
{
return
responseTime
;
}
public
T
getData
()
{
return
data
;
}
}
\ No newline at end of file
src/main/java/com/esv/freight/app/common/util/AESSecretUtils.java
0 → 100644
View file @
b9743359
package
com
.
esv
.
freight
.
app
.
common
.
util
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang3.ArrayUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
javax.crypto.Cipher
;
import
javax.crypto.KeyGenerator
;
import
javax.crypto.SecretKey
;
import
javax.crypto.spec.SecretKeySpec
;
import
java.security.SecureRandom
;
/**
* @description: 对称加密AES工具类
* @project: SpringCloudTemplate
* @name: com.esv.springcloud.template.common.util.AESSecretUtils
* @author: 黄朝斌
* @email: huangchaobin@esvtek.com
* @createTime: 2020/03/13 14:29
* @version:1.0
*/
@Slf4j
public
class
AESSecretUtils
{
/**秘钥的大小*/
private
static
final
int
KEYSIZE
=
128
;
/**
* @Author: Helon
* @Description: AES加密
* @param data - 待加密内容
* @param key - 加密秘钥
* @Data: 2018/7/28 18:42
* @Modified By:
*/
public
static
byte
[]
encrypt
(
String
data
,
String
key
)
{
if
(
StringUtils
.
isNotBlank
(
data
))
{
try
{
KeyGenerator
keyGenerator
=
KeyGenerator
.
getInstance
(
"AES"
);
//选择一种固定算法,为了避免不同java实现的不同算法,生成不同的密钥,而导致解密失败
SecureRandom
random
=
SecureRandom
.
getInstance
(
"SHA1PRNG"
);
random
.
setSeed
(
key
.
getBytes
());
keyGenerator
.
init
(
KEYSIZE
,
random
);
SecretKey
secretKey
=
keyGenerator
.
generateKey
();
byte
[]
enCodeFormat
=
secretKey
.
getEncoded
();
SecretKeySpec
secretKeySpec
=
new
SecretKeySpec
(
enCodeFormat
,
"AES"
);
// 创建密码器
Cipher
cipher
=
Cipher
.
getInstance
(
"AES"
);
byte
[]
byteContent
=
data
.
getBytes
(
"utf-8"
);
// 初始化
cipher
.
init
(
Cipher
.
ENCRYPT_MODE
,
secretKeySpec
);
// 加密
byte
[]
result
=
cipher
.
doFinal
(
byteContent
);
return
result
;
}
catch
(
Exception
e
)
{
log
.
error
(
"AES加密字符串失败"
,
e
.
getMessage
());
}
}
return
null
;
}
/**
* @Author: Helon
* @Description: AES加密,返回String
* @param data - 待加密内容
* @param key - 加密秘钥
* @Data: 2018/7/28 18:59
* @Modified By:
*/
public
static
String
encryptToStr
(
String
data
,
String
key
)
{
if
(
StringUtils
.
isBlank
(
data
)
||
StringUtils
.
isBlank
(
key
))
{
return
null
;
}
else
{
byte
[]
bytes
=
encrypt
(
data
,
key
);
if
(
null
==
bytes
||
0
==
bytes
.
length
)
{
return
null
;
}
else
{
return
parseByte2HexStr
(
bytes
);
}
}
}
/**
* @Author: Helon
* @Description: AES解密
* @param data - 待解密字节数组
* @param key - 秘钥
* @Data: 2018/7/28 19:01
* @Modified By:
*/
public
static
byte
[]
decrypt
(
byte
[]
data
,
String
key
)
{
if
(
ArrayUtils
.
isNotEmpty
(
data
))
{
try
{
KeyGenerator
keyGenerator
=
KeyGenerator
.
getInstance
(
"AES"
);
//选择一种固定算法,为了避免不同java实现的不同算法,生成不同的密钥,而导致解密失败
SecureRandom
random
=
SecureRandom
.
getInstance
(
"SHA1PRNG"
);
random
.
setSeed
(
key
.
getBytes
());
keyGenerator
.
init
(
KEYSIZE
,
random
);
SecretKey
secretKey
=
keyGenerator
.
generateKey
();
byte
[]
enCodeFormat
=
secretKey
.
getEncoded
();
SecretKeySpec
secretKeySpec
=
new
SecretKeySpec
(
enCodeFormat
,
"AES"
);
// 创建密码器
Cipher
cipher
=
Cipher
.
getInstance
(
"AES"
);
// 初始化
cipher
.
init
(
Cipher
.
DECRYPT_MODE
,
secretKeySpec
);
byte
[]
result
=
cipher
.
doFinal
(
data
);
// 加密
return
result
;
}
catch
(
Exception
e
)
{
log
.
error
(
"AES解密字符串失败"
,
e
.
getMessage
());
}
}
return
null
;
}
/**
* @Author: Helon
* @Description: AES解密,返回String
* @param enCryptdata - 待解密字节数组
* @param key - 秘钥
* @Data: 2018/7/28 19:01
* @Modified By:
*/
public
static
String
decryptToStr
(
String
enCryptdata
,
String
key
)
{
if
(
StringUtils
.
isEmpty
(
enCryptdata
))
{
return
null
;
}
byte
[]
decryptBytes
=
decrypt
(
parseHexStr2Byte
(
enCryptdata
),
key
);
if
(
null
==
decryptBytes
)
{
return
null
;
}
return
new
String
(
decryptBytes
);
}
/**
* @Author: Helon
* @Description: 将二进制转换成16进制
* @param buf - 二进制数组
* @Data: 2018/7/28 19:12
* @Modified By:
*/
public
static
String
parseByte2HexStr
(
byte
buf
[])
{
StringBuffer
sb
=
new
StringBuffer
();
for
(
int
i
=
0
;
i
<
buf
.
length
;
i
++)
{
String
hex
=
Integer
.
toHexString
(
buf
[
i
]
&
0xFF
);
if
(
hex
.
length
()
==
1
)
{
hex
=
'0'
+
hex
;
}
sb
.
append
(
hex
.
toUpperCase
());
}
return
sb
.
toString
();
}
/**
* @Author: Helon
* @Description: 将16进制转换为二进制
* @param hexStr - 16进制字符串
* @Data: 2018/7/28 19:13
* @Modified By:
*/
public
static
byte
[]
parseHexStr2Byte
(
String
hexStr
)
{
if
(
hexStr
.
length
()
<
1
)
{
return
null
;
}
byte
[]
result
=
new
byte
[
hexStr
.
length
()
/
2
];
for
(
int
i
=
0
;
i
<
hexStr
.
length
()
/
2
;
i
++)
{
int
high
=
Integer
.
parseInt
(
hexStr
.
substring
(
i
*
2
,
i
*
2
+
1
),
16
);
int
low
=
Integer
.
parseInt
(
hexStr
.
substring
(
i
*
2
+
1
,
i
*
2
+
2
),
16
);
result
[
i
]
=
(
byte
)
(
high
*
16
+
low
);
}
return
result
;
}
}
src/main/java/com/esv/freight/app/common/util/DateUtils.java
0 → 100644
View file @
b9743359
package
com
.
esv
.
freight
.
app
.
common
.
util
;
import
org.apache.commons.lang3.StringUtils
;
import
org.joda.time.DateTime
;
import
org.joda.time.format.DateTimeFormat
;
import
org.joda.time.format.DateTimeFormatter
;
import
java.util.Date
;
/**
* @description: 日期工具类
* @project: SpringCloudTemplate
* @name: com.esv.springcloud.template.common.util.DateUtils
* @author: 黄朝斌
* @email: huangchaobin@esvtek.com
* @createTime: 2020/03/12 18:02
* @version:1.0
*/
public
class
DateUtils
{
public
static
final
String
DATE_FORMAT0
=
"yyyy-MM-dd HH:mm:ss:SSS"
;
public
static
final
String
DATE_FORMAT1
=
"yyyy-MM-dd HH:mm:ss"
;
public
static
final
String
DATE_FORMAT2
=
"yyyyMMdd"
;
public
static
final
String
DATE_FORMAT3
=
"yyyy-MM-dd"
;
public
static
final
String
DATE_FORMAT4
=
"yyyyMMddHHmmss"
;
public
static
final
String
DATE_FORMAT5
=
"yyyy-MM"
;
public
static
final
String
DATE_FORMAT6
=
"yyyyMMddHHmmssSSS"
;
public
static
final
String
DATE_FORMAT7
=
"MMdd"
;
public
static
final
String
DATE_FORMAT8
=
"mm HH"
;
public
static
final
String
DATE_FORMAT9
=
"HH:mm:ss"
;
/**
* 一个月的时间换算成秒:30 * 24 * 60 * 60
*/
public
static
final
long
MONTH_TO_SECONDS
=
2592000L
;
/**
* 一天的时间换算成秒:24 * 60 * 60
*/
public
static
final
long
DAY_TO_SECONDS
=
86400L
;
/**
* 获取当前Date类型时间
* @return
*/
public
static
Date
getSysdate
()
{
return
new
Date
();
}
/**
* 获取当前String(yyyy-MM-dd HH:mm:ss)类型时间
* @return
*/
public
static
String
getSysdateStr
()
{
Date
date
=
new
Date
();
return
format
(
date
,
DATE_FORMAT1
);
}
/**
* 获取当前String(yyyyMMddHHmmssSSS)类型时间
* @return
*/
public
static
String
getSysdateStr19
()
{
Date
date
=
new
Date
();
return
format
(
date
,
DATE_FORMAT6
);
}
/**
* 获取指定字符串格式的当前时间
* @param format
* @return
*/
public
static
String
getSysdateStr
(
String
format
)
{
Date
date
=
new
Date
();
return
format
(
date
,
format
);
}
/**
* 格式化日期,格式为“yyyy-MM-dd HH:mm:ss”
* @param date
* @return
*/
public
static
String
format
(
Date
date
)
{
return
format
(
date
,
DateUtils
.
DATE_FORMAT1
);
}
/**
* 格式化日期,格式自定义
* @param date
* @param format
* @return
*/
public
static
String
format
(
Date
date
,
String
format
)
{
if
(
date
==
null
)
{
return
null
;
}
DateTime
dateTime
=
new
DateTime
(
date
);
return
dateTime
.
toString
(
format
);
}
/**
* 字符串转换成日期,字符串格式同date类型
* @param dateStr
* @param format
* @return
*/
public
static
Date
parse
(
String
dateStr
,
String
format
)
{
if
(
null
==
dateStr
)
{
return
null
;
}
DateTimeFormatter
dateTimeFormatter
=
DateTimeFormat
.
forPattern
(
format
);
DateTime
dateTime
=
dateTimeFormatter
.
parseDateTime
(
dateStr
);
return
dateTime
.
toDate
();
}
/**
* 字符串转换成日期
* @param dateStr
* @return
*/
public
static
Date
parse
(
String
dateStr
)
{
if
(-
1
<
dateStr
.
indexOf
(
"-"
))
{
return
parse
(
dateStr
,
"yyyy-MM-dd"
);
}
else
if
(-
1
<
dateStr
.
indexOf
(
"/"
))
{
return
parse
(
dateStr
,
"yyyy/MM/dd"
);
}
else
{
return
parse
(
dateStr
,
"yyyyMMdd"
);
}
}
/**
* 判断date日期是否过期(与当前时刻比较)
*
* @param date
* @return
*/
public
static
boolean
isTimeExpired
(
Date
date
)
{
if
(
null
==
date
)
{
return
true
;
}
String
timeStr
=
format
(
date
);
return
isBeforeNow
(
timeStr
);
}
/**
* 判断date日期是否过期(与当前时刻比较)
*
* @param timeStr
* @return
*/
public
static
boolean
isTimeExpired
(
String
timeStr
)
{
if
(
StringUtils
.
isBlank
(
timeStr
))
{
return
true
;
}
return
isBeforeNow
(
timeStr
);
}
/**
* 判断timeStr是否在当前时刻之前
*
* @param timeStr
* @return
*/
private
static
boolean
isBeforeNow
(
String
timeStr
)
{
DateTimeFormatter
format
=
DateTimeFormat
.
forPattern
(
DATE_FORMAT1
);
DateTime
dateTime
=
DateTime
.
parse
(
timeStr
,
format
);
return
dateTime
.
isBeforeNow
();
}
/**
* 日期加天数
*
* @param date
* @param days
* @return
*/
public
static
Date
plusDays
(
Date
date
,
Integer
days
)
{
return
plusOrMinusDays
(
date
,
days
,
0
);
}
/**
* 日期减天数
*
* @param date
* @param days
* @return
*/
public
static
Date
minusDays
(
Date
date
,
Integer
days
)
{
return
plusOrMinusDays
(
date
,
days
,
1
);
}
/**
* 加减天数
*
* @param date
* @param days
* @param type 0:加天数 1:减天数
* @return
*/
private
static
Date
plusOrMinusDays
(
Date
date
,
Integer
days
,
Integer
type
)
{
if
(
null
==
date
)
{
return
null
;
}
days
=
null
==
days
?
0
:
days
;
DateTime
dateTime
=
new
DateTime
(
date
);
if
(
type
==
0
)
{
dateTime
=
dateTime
.
plusDays
(
days
);
}
else
{
dateTime
=
dateTime
.
minusDays
(
days
);
}
return
dateTime
.
toDate
();
}
/**
* 日期加分钟
*
* @param date
* @param minutes
* @return
*/
public
static
Date
plusMinutes
(
Date
date
,
Integer
minutes
)
{
return
plusOrMinusMinutes
(
date
,
minutes
,
0
);
}
/**
* 日期减分钟
*
* @param date
* @param minutes
* @return
*/
public
static
Date
minusMinutes
(
Date
date
,
Integer
minutes
)
{
return
plusOrMinusMinutes
(
date
,
minutes
,
1
);
}
/**
* 加减分钟
*
* @param date
* @param minutes
* @param type 0:加分钟 1:减分钟
* @return
*/
private
static
Date
plusOrMinusMinutes
(
Date
date
,
Integer
minutes
,
Integer
type
)
{
if
(
null
==
date
)
{
return
null
;
}
minutes
=
null
==
minutes
?
0
:
minutes
;
DateTime
dateTime
=
new
DateTime
(
date
);
if
(
type
==
0
)
{
dateTime
=
dateTime
.
plusMinutes
(
minutes
);
}
else
{
dateTime
=
dateTime
.
minusMinutes
(
minutes
);
}
return
dateTime
.
toDate
();
}
/**
* 日期加月份
*
* @param date
* @param months
* @return
*/
public
static
Date
plusMonths
(
Date
date
,
Integer
months
)
{
return
plusOrMinusMonths
(
date
,
months
,
0
);
}
/**
* 日期减月份
*
* @param date
* @param months
* @return
*/
public
static
Date
minusMonths
(
Date
date
,
Integer
months
)
{
return
plusOrMinusMonths
(
date
,
months
,
1
);
}
/**
* 加减月份
*
* @param date
* @param months
* @param type 0:加月份 1:减月份
* @return
*/
private
static
Date
plusOrMinusMonths
(
Date
date
,
Integer
months
,
Integer
type
)
{
if
(
null
==
date
)
{
return
null
;
}
months
=
null
==
months
?
0
:
months
;
DateTime
dateTime
=
new
DateTime
(
date
);
if
(
type
==
0
)
{
dateTime
=
dateTime
.
plusMonths
(
months
);
}
else
{
dateTime
=
dateTime
.
minusMonths
(
months
);
}
return
dateTime
.
toDate
();
}
/**
* 判断target是否在开始和结束时间之间
*
* @param target
* @param startTime
* @param endTime
* @return
*/
public
static
boolean
isBetweenStartAndEndTime
(
Date
target
,
Date
startTime
,
Date
endTime
)
{
if
(
null
==
target
||
null
==
startTime
||
null
==
endTime
)
{
return
false
;
}
DateTime
dateTime
=
new
DateTime
(
target
);
return
dateTime
.
isAfter
(
startTime
.
getTime
())
&&
dateTime
.
isBefore
(
endTime
.
getTime
());
}
}
src/main/java/com/esv/freight/app/common/util/ReqUtils.java
0 → 100644
View file @
b9743359
package
com
.
esv
.
freight
.
app
.
common
.
util
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.web.context.request.RequestContextHolder
;
import
org.springframework.web.context.request.ServletRequestAttributes
;
import
javax.servlet.http.HttpServletRequest
;
/**
* @description:Http请求工具类
* @author:hcbmailbox@163.com
* @date:2019/12/25
*/
@Slf4j
public
class
ReqUtils
{
public
static
String
getRequestHeader
(
String
headerKey
)
{
ServletRequestAttributes
servletRequestAttributes
=
(
ServletRequestAttributes
)
RequestContextHolder
.
getRequestAttributes
();
HttpServletRequest
request
=
servletRequestAttributes
.
getRequest
();
return
request
.
getHeader
(
headerKey
);
}
/**
* 获得Http客户端的ip
* @param req
* @return
*/
public
static
String
getHttpClientIp
(
HttpServletRequest
req
){
String
ip
=
req
.
getHeader
(
"x-forwarded-for"
);
if
(
ip
==
null
||
ip
.
length
()
==
0
||
"unknown"
.
equalsIgnoreCase
(
ip
))
{
ip
=
req
.
getHeader
(
"Proxy-Client-IP"
);
}
if
(
ip
==
null
||
ip
.
length
()
==
0
||
"unknown"
.
equalsIgnoreCase
(
ip
))
{
ip
=
req
.
getHeader
(
"WL-Proxy-Client-IP"
);
}
if
(
ip
==
null
||
ip
.
length
()
==
0
||
"unknown"
.
equalsIgnoreCase
(
ip
))
{
ip
=
req
.
getRemoteAddr
();
}
return
ip
;
}
}
src/main/java/com/esv/freight/app/common/validator/groups/ValidatorDelete.java
0 → 100644
View file @
b9743359
package
com
.
esv
.
freight
.
app
.
common
.
validator
.
groups
;
import
javax.validation.groups.Default
;
/**
* @description: 参数校验分组:删除记录
* @project: SpringCloudTemplate
* @name: com.esv.springcloud.template.common.validator.groups.ValidatorDelete
* @author: 黄朝斌
* @email: huangchaobin@esvtek.com
* @createTime: 2020/03/12 17:58
* @version:1.0
*/
public
interface
ValidatorDelete
extends
Default
{
}
src/main/java/com/esv/freight/app/common/validator/groups/ValidatorDetail.java
0 → 100644
View file @
b9743359
package
com
.
esv
.
freight
.
app
.
common
.
validator
.
groups
;
import
javax.validation.groups.Default
;
/**
* @description: 数校验分组:记录详情
* @project: SpringCloudTemplate
* @name: com.esv.springcloud.template.common.validator.groups.ValidatorDetail
* @author: 黄朝斌
* @email: huangchaobin@esvtek.com
* @createTime: 2020/03/12 17:57
* @version:1.0
*/
public
interface
ValidatorDetail
extends
Default
{
}
src/main/java/com/esv/freight/app/common/validator/groups/ValidatorInsert.java
0 → 100644
View file @
b9743359
package
com
.
esv
.
freight
.
app
.
common
.
validator
.
groups
;
import
javax.validation.groups.Default
;
/**
* @description: 参数校验分组:新增记录
* @project: SpringCloudTemplate
* @name: com.esv.springcloud.template.common.validator.groups.ValidatorInsert
* @author: 黄朝斌
* @email: huangchaobin@esvtek.com
* @createTime: 2020/03/12 17:57
* @version:1.0
*/
public
interface
ValidatorInsert
extends
Default
{
}
src/main/java/com/esv/freight/app/common/validator/groups/ValidatorList.java
0 → 100644
View file @
b9743359
package
com
.
esv
.
freight
.
app
.
common
.
validator
.
groups
;
import
javax.validation.groups.Default
;
/**
* @description: 参数校验分组:查询列表
* @project: SpringCloudTemplate
* @name: com.esv.springcloud.template.common.validator.groups.ValidatorList
* @author: 黄朝斌
* @email: huangchaobin@esvtek.com
* @createTime: 2020/03/12 17:58
* @version:1.0
*/
public
interface
ValidatorList
extends
Default
{
}
src/main/java/com/esv/freight/app/common/validator/groups/ValidatorUpdate.java
0 → 100644
View file @
b9743359
package
com
.
esv
.
freight
.
app
.
common
.
validator
.
groups
;
import
javax.validation.groups.Default
;
/**
* @description: 参数校验分组:更新记录
* @project: SpringCloudTemplate
* @name: com.esv.springcloud.template.common.validator.groups.ValidatorUpdate
* @author: 黄朝斌
* @email: huangchaobin@esvtek.com
* @createTime: 2020/03/12 17:58
* @version:1.0
*/
public
interface
ValidatorUpdate
extends
Default
{
}
src/main/java/com/esv/freight/app/common/vo/PageResultVO.java
0 → 100644
View file @
b9743359
package
com
.
esv
.
freight
.
app
.
common
.
vo
;
import
com.baomidou.mybatisplus.core.metadata.IPage
;
import
lombok.Data
;
import
java.util.List
;
/**
* @description: 分页查询返回结果VO
* @project: Spring-Cloud-Single-Template
* @name: com.esv.freight.common.vo.PageResultVO
* @author: 黄朝斌
* @email: huangchaobin@esvtek.com
* @createTime: 2020/04/09 10:01
* @version:1.0
*/
@Data
public
class
PageResultVO
{
/**
* 每页记录条数
**/
private
Long
pageSize
;
/**
* 当前页码
**/
private
Long
pageNum
;
/**
* 总记录条数
**/
private
Long
total
;
/**
* 当前页的记录条数
**/
private
Long
recordSize
;
/**
* 数据
**/
private
List
<?>
record
;
public
PageResultVO
(
IPage
page
,
List
<?>
record
)
{
this
.
pageSize
=
page
.
getSize
();
this
.
pageNum
=
page
.
getCurrent
();
this
.
total
=
page
.
getTotal
();
this
.
recordSize
=
Long
.
parseLong
(
String
.
valueOf
(
page
.
getRecords
().
size
()));
this
.
record
=
record
;
}
}
src/main/java/com/esv/freight/app/common/wrapper/RestRequestWrapper.java
0 → 100644
View file @
b9743359
package
com
.
esv
.
freight
.
app
.
common
.
wrapper
;
import
javax.servlet.ReadListener
;
import
javax.servlet.ServletInputStream
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletRequestWrapper
;
import
java.io.*
;
import
java.nio.charset.Charset
;
/**
* @description: HttpServletRequest包装类
* @project: SpringCloudTemplate
* @name: com.esv.springcloud.template.common.wrapper.RestRequestWrapper
* @author: 黄朝斌
* @email: huangchaobin@esvtek.com
* @createTime: 2020/03/12 17:59
* @version:1.0
*/
public
class
RestRequestWrapper
extends
HttpServletRequestWrapper
{
private
byte
[]
body
;
public
RestRequestWrapper
(
HttpServletRequest
request
)
throws
IOException
{
super
(
request
);
ServletInputStream
inputStream
=
request
.
getInputStream
();
if
(
null
!=
inputStream
)
{
body
=
readBytes
(
inputStream
);
}
}
@Override
public
BufferedReader
getReader
()
{
return
new
BufferedReader
(
new
InputStreamReader
(
getInputStream
()));
}
@Override
public
ServletInputStream
getInputStream
()
{
final
ByteArrayInputStream
bais
=
new
ByteArrayInputStream
(
body
);
return
new
ServletInputStream
()
{
@Override
public
boolean
isFinished
()
{
return
false
;
}
@Override
public
boolean
isReady
()
{
return
false
;
}
@Override
public
void
setReadListener
(
ReadListener
readListener
)
{
}
@Override
public
int
read
()
{
return
bais
.
read
();
}
};
}
private
String
streamToString
(
InputStream
inputStream
)
{
try
(
BufferedReader
br
=
new
BufferedReader
(
new
InputStreamReader
(
inputStream
,
"UTF-8"
)))
{
StringBuilder
builder
=
new
StringBuilder
();
String
output
;
while
((
output
=
br
.
readLine
())
!=
null
)
{
builder
.
append
(
output
);
}
return
builder
.
toString
();
}
catch
(
IOException
e
)
{
throw
new
RuntimeException
(
"Http 服务调用失败"
,
e
);
}
}
private
byte
[]
readBytes
(
ServletInputStream
inputStream
)
{
return
streamToString
(
inputStream
).
getBytes
(
Charset
.
forName
(
"UTF-8"
));
}
public
void
setBody
(
String
data
)
{
this
.
body
=
data
.
getBytes
(
Charset
.
forName
(
"UTF-8"
));
}
}
src/main/java/com/esv/freight/app/common/wrapper/RestResponseWrapper.java
0 → 100644
View file @
b9743359
package
com
.
esv
.
freight
.
app
.
common
.
wrapper
;
import
lombok.AllArgsConstructor
;
import
lombok.Data
;
import
javax.servlet.ServletOutputStream
;
import
javax.servlet.WriteListener
;
import
javax.servlet.http.HttpServletResponse
;
import
javax.servlet.http.HttpServletResponseWrapper
;
import
java.io.ByteArrayOutputStream
;
import
java.io.IOException
;
import
java.io.OutputStreamWriter
;
import
java.io.PrintWriter
;
/**
* @description: HttpServletResponse包装类
* @project: SpringCloudTemplate
* @name: com.esv.springcloud.template.common.wrapper.RestResponseWrapper
* @author: 黄朝斌
* @email: huangchaobin@esvtek.com
* @createTime: 2020/03/12 18:00
* @version:1.0
*/
public
class
RestResponseWrapper
extends
HttpServletResponseWrapper
{
private
ByteArrayOutputStream
byteArrayOutputStream
=
new
ByteArrayOutputStream
();
private
HttpServletResponse
response
;
public
RestResponseWrapper
(
HttpServletResponse
response
)
{
super
(
response
);
this
.
response
=
response
;
}
public
byte
[]
getBody
()
{
return
byteArrayOutputStream
.
toByteArray
();
}
@Override
public
ServletOutputStream
getOutputStream
()
{
return
new
ServletOutputStreamWrapper
(
this
.
byteArrayOutputStream
,
this
.
response
);
}
@Override
public
PrintWriter
getWriter
()
throws
IOException
{
return
new
PrintWriter
(
new
OutputStreamWriter
(
this
.
byteArrayOutputStream
,
this
.
response
.
getCharacterEncoding
()));
}
@Data
@AllArgsConstructor
private
static
class
ServletOutputStreamWrapper
extends
ServletOutputStream
{
private
ByteArrayOutputStream
outputStream
;
private
HttpServletResponse
response
;
@Override
public
boolean
isReady
()
{
return
true
;
}
@Override
public
void
setWriteListener
(
WriteListener
listener
)
{
}
@Override
public
void
write
(
int
b
)
throws
IOException
{
this
.
outputStream
.
write
(
b
);
}
@Override
public
void
flush
()
throws
IOException
{
if
(!
this
.
response
.
isCommitted
())
{
byte
[]
body
=
this
.
outputStream
.
toByteArray
();
ServletOutputStream
outputStream
=
this
.
response
.
getOutputStream
();
outputStream
.
write
(
body
);
outputStream
.
flush
();
}
}
}
}
src/main/java/com/esv/freight/app/config/CacheConfig.java
0 → 100644
View file @
b9743359
package
com
.
esv
.
freight
.
app
.
config
;
import
com.fasterxml.jackson.annotation.JsonAutoDetect
;
import
com.fasterxml.jackson.annotation.PropertyAccessor
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
org.springframework.cache.CacheManager
;
import
org.springframework.cache.annotation.EnableCaching
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.data.redis.cache.RedisCacheConfiguration
;
import
org.springframework.data.redis.cache.RedisCacheManager
;
import
org.springframework.data.redis.connection.RedisConnectionFactory
;
import
org.springframework.data.redis.core.*
;
import
org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer
;
import
org.springframework.data.redis.serializer.RedisSerializationContext
;
import
org.springframework.data.redis.serializer.RedisSerializer
;
import
org.springframework.data.redis.serializer.StringRedisSerializer
;
import
java.time.Duration
;
/**
* @description: Cache配置类
* @project: Spring-Cloud-Single-Template
* @name: com.esv.freight.config.CacheConfig
* @author: 黄朝斌
* @email: huangchaobin@esvtek.com
* @createTime: 2020/04/09 9:57
* @version:1.0
*/
@Configuration
@EnableCaching
public
class
CacheConfig
{
/**
* description 为SpringCache注册缓存管理器
* param [redisConnectionFactory]
* return org.springframework.cache.CacheManager
* author Administrator
* createTime 2020/03/19 14:26
**/
@Bean
public
CacheManager
cacheManager
(
RedisConnectionFactory
redisConnectionFactory
)
{
long
timeToLive
=
60L
;
RedisSerializer
<
String
>
redisSerializer
=
new
StringRedisSerializer
();
Jackson2JsonRedisSerializer
jackson2JsonRedisSerializer
=
new
Jackson2JsonRedisSerializer
(
Object
.
class
);
// 解决查询缓存转换异常的问题
ObjectMapper
om
=
new
ObjectMapper
();
om
.
setVisibility
(
PropertyAccessor
.
ALL
,
JsonAutoDetect
.
Visibility
.
ANY
);
om
.
enableDefaultTyping
(
ObjectMapper
.
DefaultTyping
.
NON_FINAL
);
jackson2JsonRedisSerializer
.
setObjectMapper
(
om
);
// 配置序列化(解决乱码的问题)
RedisCacheConfiguration
config
=
RedisCacheConfiguration
.
defaultCacheConfig
()
.
entryTtl
(
Duration
.
ofMinutes
(
timeToLive
))
.
serializeKeysWith
(
RedisSerializationContext
.
SerializationPair
.
fromSerializer
(
redisSerializer
))
.
serializeValuesWith
(
RedisSerializationContext
.
SerializationPair
.
fromSerializer
(
jackson2JsonRedisSerializer
));
RedisCacheManager
cacheManager
=
RedisCacheManager
.
builder
(
redisConnectionFactory
)
.
cacheDefaults
(
config
)
.
build
();
return
cacheManager
;
}
/**
* RedisTemplate相关配置
* @param factory
* @return
*/
@Bean
public
RedisTemplate
<
String
,
Object
>
redisTemplate
(
RedisConnectionFactory
factory
)
{
RedisTemplate
<
String
,
Object
>
template
=
new
RedisTemplate
<>();
// 配置连接工厂
template
.
setConnectionFactory
(
factory
);
//使用Jackson2JsonRedisSerializer来序列化和反序列化redis的value值(默认使用JDK的序列化方式)
Jackson2JsonRedisSerializer
jacksonSeial
=
new
Jackson2JsonRedisSerializer
(
Object
.
class
);
ObjectMapper
om
=
new
ObjectMapper
();
// 指定要序列化的域,field,get和set,以及修饰符范围,ANY是都有包括private和public
om
.
setVisibility
(
PropertyAccessor
.
ALL
,
JsonAutoDetect
.
Visibility
.
ANY
);
// 指定序列化输入的类型,类必须是非final修饰的,final修饰的类,比如String,Integer等会跑出异常
om
.
enableDefaultTyping
(
ObjectMapper
.
DefaultTyping
.
NON_FINAL
);
jacksonSeial
.
setObjectMapper
(
om
);
// 值采用json序列化
template
.
setValueSerializer
(
jacksonSeial
);
//使用StringRedisSerializer来序列化和反序列化redis的key值
template
.
setKeySerializer
(
new
StringRedisSerializer
());
// 设置hash key 和value序列化模式
template
.
setHashKeySerializer
(
new
StringRedisSerializer
());
template
.
setHashValueSerializer
(
jacksonSeial
);
template
.
afterPropertiesSet
();
return
template
;
}
/**
* 对hash类型的数据操作
*
* @param redisTemplate
* @return
*/
@Bean
public
HashOperations
<
String
,
String
,
Object
>
hashOperations
(
RedisTemplate
<
String
,
Object
>
redisTemplate
)
{
return
redisTemplate
.
opsForHash
();
}
/**
* 对redis字符串类型数据操作
*
* @param redisTemplate
* @return
*/
@Bean
public
ValueOperations
<
String
,
Object
>
valueOperations
(
RedisTemplate
<
String
,
Object
>
redisTemplate
)
{
return
redisTemplate
.
opsForValue
();
}
/**
* 对链表类型的数据操作
*
* @param redisTemplate
* @return
*/
@Bean
public
ListOperations
<
String
,
Object
>
listOperations
(
RedisTemplate
<
String
,
Object
>
redisTemplate
)
{
return
redisTemplate
.
opsForList
();
}
/**
* 对无序集合类型的数据操作
*
* @param redisTemplate
* @return
*/
@Bean
public
SetOperations
<
String
,
Object
>
setOperations
(
RedisTemplate
<
String
,
Object
>
redisTemplate
)
{
return
redisTemplate
.
opsForSet
();
}
/**
* 对有序集合类型的数据操作
*
* @param redisTemplate
* @return
*/
@Bean
public
ZSetOperations
<
String
,
Object
>
zSetOperations
(
RedisTemplate
<
String
,
Object
>
redisTemplate
)
{
return
redisTemplate
.
opsForZSet
();
}
}
src/main/java/com/esv/freight/app/config/FeignConfigure.java
0 → 100644
View file @
b9743359
package
com
.
esv
.
freight
.
app
.
config
;
import
feign.RequestInterceptor
;
import
org.slf4j.MDC
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.cloud.openfeign.EnableFeignClients
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.web.client.RestTemplate
;
/**
* @description: Feign接口配置
* @project: Spring-Cloud-Single-Template
* @name: com.esv.freight.config.FeignConfigure
* @author: 黄朝斌
* @email: huangchaobin@esvtek.com
* @createTime: 2020/04/09 9:57
* @version:1.0
*/
@EnableFeignClients
(
basePackages
=
"com.esv.freight.app.feign"
)
@Configuration
public
class
FeignConfigure
{
@Value
(
"${spring.application.name}"
)
private
String
applicationName
;
@Bean
public
RestTemplate
restTemplate
()
{
return
new
RestTemplate
();
}
@Bean
public
RequestInterceptor
requestInterceptor
()
{
RequestInterceptor
requestInterceptor
=
((
requestTemplate
->
{
requestTemplate
.
header
(
"trace_id"
,
MDC
.
get
(
"traceId"
));
requestTemplate
.
header
(
"application_name"
,
applicationName
);
}));
return
requestInterceptor
;
}
}
src/main/java/com/esv/freight/app/config/FeignInterceptorConfig.java
0 → 100644
View file @
b9743359
package
com
.
esv
.
freight
.
app
.
config
;
import
feign.RequestInterceptor
;
import
feign.RequestTemplate
;
import
org.slf4j.MDC
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.context.annotation.Bean
;
/**
* @description: 注册Feign请求拦截器
* @project: Spring-Cloud-Single-Template
* @name: com.esv.freight.config.FeignInterceptorConfig
* @author: 黄朝斌
* @email: huangchaobin@esvtek.com
* @createTime: 2020/04/09 9:58
* @version:1.0
*/
public
class
FeignInterceptorConfig
{
@Value
(
"${spring.application.name}"
)
private
String
applicationName
;
@Bean
public
RequestInterceptor
requestInterceptor
(){
return
new
FeignRequestInterceptor
();
}
class
FeignRequestInterceptor
implements
RequestInterceptor
{
@Override
public
void
apply
(
RequestTemplate
requestTemplate
)
{
requestTemplate
.
header
(
"trace_id"
,
MDC
.
get
(
"traceId"
));
requestTemplate
.
header
(
"application_name"
,
applicationName
);
}
}
}
src/main/java/com/esv/freight/app/config/JacksonConfig.java
0 → 100644
View file @
b9743359
package
com
.
esv
.
freight
.
app
.
config
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
com.fasterxml.jackson.databind.SerializationFeature
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Primary
;
/**
* @description: ResponseBody允许序列化结果值为 null 的数据
* @project: Spring-Cloud-Single-Template
* @name: com.esv.freight.config.JacksonConfig
* @author: 黄朝斌
* @email: huangchaobin@esvtek.com
* @createTime: 2020/04/09 9:43
* @version:1.0
*/
@Configuration
public
class
JacksonConfig
{
@Bean
@Primary
@ConditionalOnMissingBean
(
ObjectMapper
.
class
)
public
ObjectMapper
jacksonObjectMapper
()
{
return
new
ObjectMapper
().
disable
(
SerializationFeature
.
FAIL_ON_EMPTY_BEANS
);
}
}
src/main/java/com/esv/freight/app/config/LogFilterConfig.java
0 → 100644
View file @
b9743359
package
com
.
esv
.
freight
.
app
.
config
;
import
com.esv.freight.app.common.filter.LogbackFilter
;
import
com.esv.freight.app.common.filter.RestLogFilter
;
import
org.springframework.boot.web.servlet.FilterRegistrationBean
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
/**
* @description: 注册请求Filter
* @project: SpringCloudTemplate
* @name: com.esv.springcloud.template.web.config.FilterConfig
* @author: 黄朝斌
* @email: huangchaobin@esvtek.com
* @createTime: 2020/03/09 17:47
* @version:1.0
*/
@Configuration
public
class
LogFilterConfig
{
private
static
final
String
URL
=
"/*"
;
@Bean
public
FilterRegistrationBean
<
LogbackFilter
>
logbackFilterRegister
()
{
FilterRegistrationBean
<
LogbackFilter
>
registration
=
new
FilterRegistrationBean
<>();
registration
.
setFilter
(
new
LogbackFilter
());
registration
.
addUrlPatterns
(
URL
);
registration
.
setOrder
(
Integer
.
MIN_VALUE
);
return
registration
;
}
@Bean
public
FilterRegistrationBean
<
RestLogFilter
>
restLogFilterRegister
()
{
FilterRegistrationBean
<
RestLogFilter
>
filterRegistrationBean
=
new
FilterRegistrationBean
<>();
filterRegistrationBean
.
setFilter
(
new
RestLogFilter
());
filterRegistrationBean
.
addUrlPatterns
(
URL
);
filterRegistrationBean
.
setOrder
(
Integer
.
MIN_VALUE
+
1
);
return
filterRegistrationBean
;
}
}
src/main/java/com/esv/freight/app/config/MybatisPlusConfig.java
0 → 100644
View file @
b9743359
package
com
.
esv
.
freight
.
app
.
config
;
import
com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor
;
import
org.mybatis.spring.annotation.MapperScan
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
/**
* @description:
* @project: Spring-Cloud-Single-Template
* @name: com.esv.freight.config.mybatis.MybatisPlusConfig
* @author: 黄朝斌
* @email: huangchaobin@esvtek.com
* @createTime: 2020/04/09 9:58
* @version:1.0
*/
@Configuration
@MapperScan
({
"com.esv.freight.app.module.*.dao"
})
public
class
MybatisPlusConfig
{
/**
* 分页插件
*/
@Bean
public
PaginationInterceptor
paginationInterceptor
()
{
return
new
PaginationInterceptor
();
}
}
src/main/java/com/esv/freight/app/feign/DictInterface.java
0 → 100644
View file @
b9743359
package
com
.
esv
.
freight
.
app
.
feign
;
import
com.alibaba.fastjson.JSONObject
;
import
org.springframework.cloud.openfeign.FeignClient
;
import
org.springframework.web.bind.annotation.PostMapping
;
/**
* @description:
* @project: Freight
* @name: com.esv.freight.app.feign.NoticeInterface
* @author: 黄朝斌
* @email: huangchaobin@esvtek.com
* @createTime: 2020/04/13 13:48
* @version:1.0
*/
@FeignClient
(
value
=
"freight-base-service"
)
public
interface
DictInterface
{
@PostMapping
(
value
=
"/base/dict/get"
)
JSONObject
getDictByTypes
(
JSONObject
bodyJson
);
}
src/main/java/com/esv/freight/app/feign/NoticeInterface.java
0 → 100644
View file @
b9743359
package
com
.
esv
.
freight
.
app
.
feign
;
import
com.alibaba.fastjson.JSONObject
;
import
org.springframework.cloud.openfeign.FeignClient
;
import
org.springframework.web.bind.annotation.PostMapping
;
/**
* @description:
* @project: Freight
* @name: com.esv.freight.app.feign.NoticeInterface
* @author: 张志臣
* @email: zhangzhichen@esvtek.com
* @createTime: 2020/04/17 17:48
* @version:1.0
*/
@FeignClient
(
value
=
"freight-notice-service"
)
public
interface
NoticeInterface
{
@PostMapping
(
value
=
"/notice/sms/captcha/check"
)
JSONObject
checkSmsCaptcha
(
JSONObject
bodyJson
);
}
src/main/java/com/esv/freight/app/module/account/controller/DriverAccountController.java
0 → 100644
View file @
b9743359
package
com
.
esv
.
freight
.
app
.
module
.
account
.
controller
;
import
com.alibaba.fastjson.JSONObject
;
import
com.esv.freight.app.common.response.ECode
;
import
com.esv.freight.app.common.response.EResponse
;
import
com.esv.freight.app.common.validator.groups.ValidatorInsert
;
import
com.esv.freight.app.feign.DictInterface
;
import
com.esv.freight.app.feign.NoticeInterface
;
import
com.esv.freight.app.module.account.form.LoginByPwdForm
;
import
com.esv.freight.app.module.account.form.LoginBySmsForm
;
import
com.esv.freight.app.module.account.form.RefreshTokenForm
;
import
com.esv.freight.app.module.account.service.AppLoginService
;
import
com.esv.freight.app.module.account.vo.AccountDetailVO
;
import
com.esv.freight.app.module.account.vo.LoginVO
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.validation.annotation.Validated
;
import
org.springframework.web.bind.annotation.*
;
/**
* @description: 账号Controller
* @project: Freight
* @name: com.esv.freight.module.ownerBackend.account.controller.DriverAccountController
* @author: 张志臣
* @email: zhangzhichen@esvtek.com
* @createTime: 2020/04/14 14:00
* @version:1.0
*/
@RestController
@RequestMapping
(
"/driverBackend/account"
)
@Slf4j
@Validated
public
class
DriverAccountController
{
private
DictInterface
dictInterface
;
private
NoticeInterface
noticeInterface
;
private
AppLoginService
appLoginService
;
@Autowired
public
DriverAccountController
(
DictInterface
dictInterface
,
NoticeInterface
noticeInterface
,
AppLoginService
appLoginService
)
{
this
.
dictInterface
=
dictInterface
;
this
.
noticeInterface
=
noticeInterface
;
this
.
appLoginService
=
appLoginService
;
}
/**
* description 短信验证码登录
* param [LoginBySmsForm]
* return com.esv.freight.common.response.EResponse
* author 张志臣
* createTime 2020/04/14 14:00
**/
@PostMapping
(
"/login/loginBySms"
)
public
EResponse
loginBySms
(
@RequestBody
(
required
=
false
)
@Validated
(
ValidatorInsert
.
class
)
LoginBySmsForm
loginBySmsForm
)
{
if
(
loginBySmsForm
==
null
)
{
return
EResponse
.
error
(
ECode
.
PARAM_ERROR
);
}
// 调用通知服务验证短信接口
JSONObject
reqJson
=
new
JSONObject
();
reqJson
.
put
(
"phone"
,
loginBySmsForm
.
getPhone
());
reqJson
.
put
(
"type"
,
"login"
);
reqJson
.
put
(
"captcha"
,
loginBySmsForm
.
getSmsCode
());
log
.
info
(
reqJson
.
toJSONString
());
JSONObject
result
=
noticeInterface
.
checkSmsCaptcha
(
reqJson
);
log
.
info
(
result
.
toJSONString
());
if
(
result
.
getInteger
(
"code"
)
==
200
)
{
LoginVO
loginByPwdVO
=
appLoginService
.
loginBySms
(
loginBySmsForm
.
getPhone
());
return
EResponse
.
ok
(
loginByPwdVO
);
}
return
EResponse
.
error
(
result
.
getInteger
(
"code"
),
result
.
getString
(
"message"
));
}
/**
* description 帐号密码登录RequestHeader
* param [LoginByPwdForm]
* return com.esv.freight.common.response.EResponse
* author 张志臣
* createTime 2020/04/14 14:00
**/
@PostMapping
(
"/login/loginByPwd"
)
public
EResponse
loginByPwd
(
@RequestBody
(
required
=
false
)
@Validated
(
ValidatorInsert
.
class
)
LoginByPwdForm
loginByPwdForm
)
{
if
(
loginByPwdForm
==
null
)
{
return
EResponse
.
error
(
ECode
.
PARAM_ERROR
);
}
if
(!
appLoginService
.
isExistAccount
(
loginByPwdForm
.
getPhone
()))
{
return
EResponse
.
error
(
1001
,
"账号不存在"
);
}
// TODO,Feign调用货主账号密码,目前暂时先假定密码为1234qwer(MD5加密)
if
(!
"62c8ad0a15d9d1ca38d5dee762a16e01"
.
equals
(
loginByPwdForm
.
getPwd
()))
{
return
EResponse
.
error
(
1003
,
"密码错误"
);
}
LoginVO
loginByPwdVO
=
appLoginService
.
loginByPwd
(
loginByPwdForm
.
getPhone
());
return
EResponse
.
ok
(
loginByPwdVO
);
}
/**
* description 帐号登出
* param
* return com.esv.freight.common.response.EResponse
* author 张志臣
* createTime 2020/04/14 14:00
**/
@PostMapping
(
"/logout"
)
public
EResponse
logout
(
@RequestHeader
(
"Union-Authorization"
)
String
accessToken
)
{
appLoginService
.
logout
(
accessToken
);
return
EResponse
.
ok
();
}
/**
* description 刷新Token
* param [refreshToken] 刷新Token
* return com.esv.freight.common.response.EResponse
* author 张志臣
* createTime 2020/04/13 09:00
**/
@PostMapping
(
"/token/refresh"
)
public
EResponse
refresh
(
@RequestHeader
(
"Union-Authorization"
)
String
accessToken
,
@RequestBody
(
required
=
false
)
@Validated
(
ValidatorInsert
.
class
)
RefreshTokenForm
refreshTokenForm
)
{
LoginVO
loginByPwdVO
=
appLoginService
.
refreshToken
(
accessToken
,
refreshTokenForm
);
return
EResponse
.
ok
(
loginByPwdVO
);
}
/**
* description 获取帐号详情
* param []
* return com.esv.freight.common.response.EResponse
* author 张志臣
* createTime 2020/04/14 15:00
**/
@PostMapping
(
"/detail"
)
public
EResponse
detail
(
@RequestHeader
(
"Union-Authorization"
)
String
accessToken
)
{
AccountDetailVO
accountDetailVO
=
appLoginService
.
getAccountDetailInfo
(
accessToken
);
return
EResponse
.
ok
(
accountDetailVO
);
}
}
src/main/java/com/esv/freight/app/module/account/controller/DriverPasswordController.java
0 → 100644
View file @
b9743359
package
com
.
esv
.
freight
.
app
.
module
.
account
.
controller
;
import
com.alibaba.fastjson.JSONObject
;
import
com.esv.freight.app.common.response.ECode
;
import
com.esv.freight.app.common.response.EResponse
;
import
com.esv.freight.app.common.validator.groups.ValidatorInsert
;
import
com.esv.freight.app.feign.NoticeInterface
;
import
com.esv.freight.app.module.account.form.ResetPasswordForm
;
import
com.esv.freight.app.module.account.form.ModifyPasswordForm
;
import
com.esv.freight.app.module.account.service.AppLoginService
;
import
com.esv.freight.app.module.account.vo.LoginVO
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.validation.annotation.Validated
;
import
org.springframework.web.bind.annotation.*
;
/**
* @description: 密码Controller
* @project: Freight
* @name: com.esv.freight.module.ownerBackend.account.controller.DriverPasswordController
* @author: 张志臣
* @email: zhangzhichen@esvtek.com
* @createTime: 2020/04/14 16:00
* @version:1.0
*/
@RestController
@RequestMapping
(
"/driverBackend/password"
)
@Slf4j
@Validated
public
class
DriverPasswordController
{
private
NoticeInterface
noticeInterface
;
private
AppLoginService
appLoginService
;
@Autowired
public
DriverPasswordController
(
NoticeInterface
noticeInterface
,
AppLoginService
appLoginService
)
{
this
.
noticeInterface
=
noticeInterface
;
this
.
appLoginService
=
appLoginService
;
}
/**
* description 重置密码
* param [AccountRegisterForm]
* return com.esv.freight.common.response.EResponse
* author 张志臣
* createTime 2020/04/14 16:00
**/
@PostMapping
(
"/reset"
)
public
EResponse
reset
(
@RequestBody
(
required
=
false
)
@Validated
(
ValidatorInsert
.
class
)
ResetPasswordForm
resetPasswordForm
)
{
if
(
resetPasswordForm
==
null
)
{
return
EResponse
.
error
(
ECode
.
PARAM_ERROR
);
}
if
(!
appLoginService
.
isExistAccount
(
resetPasswordForm
.
getPhone
()))
{
return
EResponse
.
error
(
1002
,
"手机号未注册"
);
}
// 调用通知服务验证短信接口
JSONObject
reqJson
=
new
JSONObject
();
reqJson
.
put
(
"phone"
,
resetPasswordForm
.
getPhone
());
reqJson
.
put
(
"type"
,
"reset_pwd"
);
reqJson
.
put
(
"captcha"
,
resetPasswordForm
.
getSmsCode
());
log
.
info
(
reqJson
.
toJSONString
());
JSONObject
result
=
noticeInterface
.
checkSmsCaptcha
(
reqJson
);
log
.
info
(
result
.
toJSONString
());
if
(
result
.
getInteger
(
"code"
)
==
200
)
{
LoginVO
loginByPwdVO
=
appLoginService
.
loginBySms
(
resetPasswordForm
.
getPhone
());
return
EResponse
.
ok
(
loginByPwdVO
);
}
return
EResponse
.
error
(
1001
,
"短信验证码错误或已失效"
);
}
/**
* description 修改密码
* param [AccountRegisterForm]
* return com.esv.freight.common.response.EResponse
* author 张志臣
* createTime 2020/04/14 16:00
**/
@PostMapping
(
"/edit"
)
public
EResponse
edit
(
@RequestHeader
(
"Union-Authorization"
)
String
accessToken
,
@RequestBody
(
required
=
false
)
@Validated
(
ValidatorInsert
.
class
)
ModifyPasswordForm
modifyPasswordFrom
)
{
if
(
modifyPasswordFrom
==
null
)
{
return
EResponse
.
error
(
ECode
.
PARAM_ERROR
);
}
if
(
"1234qwer"
.
equals
(
modifyPasswordFrom
.
getOldPwd
()))
{
return
EResponse
.
error
(
1001
,
"原密码错误"
);
}
return
EResponse
.
ok
();
}
}
src/main/java/com/esv/freight/app/module/account/controller/OwnerAccountController.java
0 → 100644
View file @
b9743359
package
com
.
esv
.
freight
.
app
.
module
.
account
.
controller
;
import
com.alibaba.fastjson.JSONObject
;
import
com.esv.freight.app.feign.DictInterface
;
import
com.esv.freight.app.feign.NoticeInterface
;
import
com.esv.freight.app.module.account.form.*
;
import
com.esv.freight.app.module.account.service.AppLoginService
;
import
com.esv.freight.app.module.account.vo.AccountDetailVO
;
import
com.esv.freight.app.common.response.ECode
;
import
com.esv.freight.app.common.response.EResponse
;
import
com.esv.freight.app.common.validator.groups.ValidatorInsert
;
import
com.esv.freight.app.module.account.vo.LoginVO
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.validation.annotation.Validated
;
import
org.springframework.web.bind.annotation.*
;
import
javax.validation.constraints.NotBlank
;
import
java.util.UUID
;
/**
* @description: 账号Controller
* @project: Freight
* @name: com.esv.freight.module.ownerBackend.account.controller.OwnerAccountController
* @author: 张志臣
* @email: zhangzhichen@esvtek.com
* @createTime: 2020/04/09 17:00
* @version:1.0
*/
@RestController
@RequestMapping
(
"/ownerBackend/account"
)
@Slf4j
@Validated
public
class
OwnerAccountController
{
private
DictInterface
dictInterface
;
private
NoticeInterface
noticeInterface
;
private
AppLoginService
appLoginService
;
@Autowired
public
OwnerAccountController
(
DictInterface
dictInterface
,
NoticeInterface
noticeInterface
,
AppLoginService
appLoginService
)
{
this
.
dictInterface
=
dictInterface
;
this
.
noticeInterface
=
noticeInterface
;
this
.
appLoginService
=
appLoginService
;
}
/**
* description 短信验证码登录
* param [LoginBySmsForm]
* return com.esv.freight.common.response.EResponse
* author 张志臣
* createTime 2020/04/10 16:00
**/
@PostMapping
(
"/login/loginBySms"
)
public
EResponse
loginBySms
(
@RequestBody
(
required
=
false
)
@Validated
(
ValidatorInsert
.
class
)
LoginBySmsForm
loginBySmsForm
)
{
if
(
loginBySmsForm
==
null
)
{
return
EResponse
.
error
(
ECode
.
PARAM_ERROR
);
}
// 调用通知服务验证短信接口
JSONObject
reqJson
=
new
JSONObject
();
reqJson
.
put
(
"phone"
,
loginBySmsForm
.
getPhone
());
reqJson
.
put
(
"type"
,
"login"
);
reqJson
.
put
(
"captcha"
,
loginBySmsForm
.
getSmsCode
());
log
.
info
(
reqJson
.
toJSONString
());
JSONObject
result
=
noticeInterface
.
checkSmsCaptcha
(
reqJson
);
log
.
info
(
result
.
toJSONString
());
/*
JSONObject reqJson1 = new JSONObject();
reqJson1.put("type", "conse");
log.info(reqJson1.toJSONString());
JSONObject result1 = dictInterface.getDictByTypes(reqJson1);
log.info(result1.toJSONString());
*/
if
(
result
.
getInteger
(
"code"
)
==
200
)
{
LoginVO
loginByPwdVO
=
appLoginService
.
loginBySms
(
loginBySmsForm
.
getPhone
());
return
EResponse
.
ok
(
loginByPwdVO
);
}
return
EResponse
.
error
(
result
.
getInteger
(
"code"
),
result
.
getString
(
"message"
));
}
/**
* description 帐号密码登录RequestHeader
* param [LoginByPwdForm]
* return com.esv.freight.common.response.EResponse
* author 张志臣
* createTime 2020/04/10 16:00
**/
@PostMapping
(
"/login/loginByPwd"
)
public
EResponse
loginByPwd
(
@RequestBody
(
required
=
false
)
@Validated
(
ValidatorInsert
.
class
)
LoginByPwdForm
loginByPwdForm
)
{
if
(
loginByPwdForm
==
null
)
{
return
EResponse
.
error
(
ECode
.
PARAM_ERROR
);
}
if
(!
appLoginService
.
isExistAccount
(
loginByPwdForm
.
getPhone
()))
{
return
EResponse
.
error
(
1001
,
"账号不存在"
);
}
// TODO,Feign调用货主账号密码,目前暂时先假定密码为1234qwer(MD5加密)
if
(!
"62c8ad0a15d9d1ca38d5dee762a16e01"
.
equals
(
loginByPwdForm
.
getPwd
()))
{
return
EResponse
.
error
(
1003
,
"密码错误"
);
}
LoginVO
loginByPwdVO
=
appLoginService
.
loginByPwd
(
loginByPwdForm
.
getPhone
());
return
EResponse
.
ok
(
loginByPwdVO
);
}
/**
* description 帐号登出
* param
* return com.esv.freight.common.response.EResponse
* author 张志臣
* createTime 2020/04/11 11:00
**/
@PostMapping
(
"/logout"
)
public
EResponse
logout
(
@RequestHeader
(
"Union-Authorization"
)
String
accessToken
)
{
appLoginService
.
logout
(
accessToken
);
return
EResponse
.
ok
();
}
/**
* description 刷新Token
* param [refreshToken] 刷新Token
* return com.esv.freight.common.response.EResponse
* author 张志臣
* createTime 2020/04/13 09:00
**/
@PostMapping
(
"/token/refresh"
)
public
EResponse
refresh
(
@RequestHeader
(
"Union-Authorization"
)
String
accessToken
,
@RequestBody
(
required
=
false
)
@Validated
(
ValidatorInsert
.
class
)
RefreshTokenForm
refreshTokenForm
)
{
LoginVO
loginByPwdVO
=
appLoginService
.
refreshToken
(
accessToken
,
refreshTokenForm
);
return
EResponse
.
ok
(
loginByPwdVO
);
}
/**
* description 获取帐号详情
* param []
* return com.esv.freight.common.response.EResponse
* author 张志臣
* createTime 2020/04/13 10:00
**/
@PostMapping
(
"/detail"
)
public
EResponse
detail
(
@RequestHeader
(
"Union-Authorization"
)
String
accessToken
)
{
if
(
appLoginService
.
isInvalidAccessToken
(
accessToken
))
{
return
EResponse
.
error
(
ECode
.
TOKEN_EXPIRED
);
}
AccountDetailVO
accountDetailVO
=
appLoginService
.
getAccountDetailInfo
(
accessToken
);
return
EResponse
.
ok
(
accountDetailVO
);
}
/**
* description 帐号实名认证
* param [RealNameAuthForm]
* return com.esv.freight.common.response.EResponse
* author 张志臣
* createTime 2020/04/13 10:00
**/
@PostMapping
(
"/realNameAuth"
)
public
EResponse
realNameAuth
(
@RequestHeader
(
"Union-Authorization"
)
String
accessToken
,
@RequestBody
(
required
=
false
)
@Validated
(
ValidatorInsert
.
class
)
RealNameAuthForm
realNameAuthForm
)
{
if
(
realNameAuthForm
==
null
)
{
return
EResponse
.
error
(
ECode
.
PARAM_ERROR
);
}
if
(
appLoginService
.
isInvalidAccessToken
(
accessToken
))
{
return
EResponse
.
error
(
ECode
.
TOKEN_EXPIRED
);
}
// TODO,Feign调用货主账号密码,目前暂时设定成功
if
(
"1234qwer"
.
equals
(
realNameAuthForm
.
getIdCard
()))
{
return
EResponse
.
error
(
1001
,
"身份证信息与照片不一致"
);
}
return
EResponse
.
ok
();
}
}
\ No newline at end of file
src/main/java/com/esv/freight/app/module/account/controller/OwnerPasswordController.java
0 → 100644
View file @
b9743359
package
com
.
esv
.
freight
.
app
.
module
.
account
.
controller
;
import
com.alibaba.fastjson.JSONObject
;
import
com.esv.freight.app.feign.DictInterface
;
import
com.esv.freight.app.feign.NoticeInterface
;
import
com.esv.freight.app.module.account.form.ResetPasswordForm
;
import
com.esv.freight.app.module.account.form.ModifyPasswordForm
;
import
com.esv.freight.app.module.account.service.AppLoginService
;
import
com.esv.freight.app.module.account.vo.LoginVO
;
import
com.esv.freight.app.common.response.ECode
;
import
com.esv.freight.app.common.response.EResponse
;
import
com.esv.freight.app.common.validator.groups.ValidatorInsert
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.validation.annotation.Validated
;
import
org.springframework.web.bind.annotation.*
;
/**
* @description: 密码Controller
* @project: Freight
* @name: com.esv.freight.module.ownerBackend.account.controller.OwnerPasswordController
* @author: 张志臣
* @email: zhangzhichen@esvtek.com
* @createTime: 2020/04/13 10:00
* @version:1.0
*/
@RestController
@RequestMapping
(
"/ownerBackend/password"
)
@Slf4j
@Validated
public
class
OwnerPasswordController
{
private
NoticeInterface
noticeInterface
;
private
AppLoginService
appLoginService
;
@Autowired
public
OwnerPasswordController
(
NoticeInterface
noticeInterface
,
AppLoginService
appLoginService
)
{
this
.
noticeInterface
=
noticeInterface
;
this
.
appLoginService
=
appLoginService
;
}
/**
* description 重置密码
* param [AccountRegisterForm]
* return com.esv.freight.common.response.EResponse
* author 张志臣
* createTime 2020/04/13 10:00
**/
@PostMapping
(
"/reset"
)
public
EResponse
reset
(
@RequestBody
(
required
=
false
)
@Validated
(
ValidatorInsert
.
class
)
ResetPasswordForm
resetPasswordForm
)
{
if
(
resetPasswordForm
==
null
)
{
return
EResponse
.
error
(
ECode
.
PARAM_ERROR
);
}
if
(!
appLoginService
.
isExistAccount
(
resetPasswordForm
.
getPhone
()))
{
return
EResponse
.
error
(
1002
,
"手机号未注册"
);
}
// 调用通知服务验证短信接口
JSONObject
reqJson
=
new
JSONObject
();
reqJson
.
put
(
"phone"
,
resetPasswordForm
.
getPhone
());
reqJson
.
put
(
"type"
,
"reset_pwd"
);
reqJson
.
put
(
"captcha"
,
resetPasswordForm
.
getSmsCode
());
log
.
info
(
reqJson
.
toJSONString
());
JSONObject
result
=
noticeInterface
.
checkSmsCaptcha
(
reqJson
);
log
.
info
(
result
.
toJSONString
());
if
(
result
.
getInteger
(
"code"
)
==
200
)
{
LoginVO
loginByPwdVO
=
appLoginService
.
loginBySms
(
resetPasswordForm
.
getPhone
());
return
EResponse
.
ok
(
loginByPwdVO
);
}
return
EResponse
.
error
(
1001
,
"短信验证码错误或已失效"
);
}
/**
* description 修改密码
* param [AccountRegisterForm]
* return com.esv.freight.common.response.EResponse
* author 张志臣
* createTime 2020/04/13 10:00
**/
@PostMapping
(
"/edit"
)
public
EResponse
edit
(
@RequestHeader
(
"Union-Authorization"
)
String
accessToken
,
@RequestBody
(
required
=
false
)
@Validated
(
ValidatorInsert
.
class
)
ModifyPasswordForm
modifyPasswordFrom
)
{
if
(
modifyPasswordFrom
==
null
)
{
return
EResponse
.
error
(
ECode
.
PARAM_ERROR
);
}
if
(
"1234qwer"
.
equals
(
modifyPasswordFrom
.
getOldPwd
()))
{
return
EResponse
.
error
(
1001
,
"原密码错误"
);
}
return
EResponse
.
ok
();
}
}
src/main/java/com/esv/freight/app/module/account/dao/AppLoginDao.java
0 → 100644
View file @
b9743359
package
com
.
esv
.
freight
.
app
.
module
.
account
.
dao
;
import
com.baomidou.mybatisplus.core.mapper.BaseMapper
;
import
com.esv.freight.app.module.account.entity.AppLoginEntity
;
import
org.apache.ibatis.annotations.Mapper
;
/**
* APP用户登录信息表
*
* @author 张志臣
* @email zhangzhichen@esvtek.com
* @date 2020-04-13 16:00
*/
@Mapper
public
interface
AppLoginDao
extends
BaseMapper
<
AppLoginEntity
>
{
AppLoginEntity
selectLogin
(
AppLoginEntity
queryEntity
);
}
src/main/java/com/esv/freight/app/module/account/entity/AppLoginEntity.java
0 → 100644
View file @
b9743359
package
com
.
esv
.
freight
.
app
.
module
.
account
.
entity
;
import
com.baomidou.mybatisplus.annotation.TableId
;
import
com.baomidou.mybatisplus.annotation.TableName
;
import
lombok.Data
;
import
java.io.Serializable
;
import
java.util.Date
;
/**
* APP用户登录信息表
*
* @author 张志臣
* @email zhangzhichen@esvtek.com
* @date 2020-04-13 16:00
*/
@Data
@TableName
(
"app_login_info"
)
public
class
AppLoginEntity
implements
Serializable
{
private
static
final
long
serialVersionUID
=
1L
;
/**
* 主键
*/
@TableId
private
Long
id
;
/**
* 手机号码
*/
private
String
phone
;
/**
* 访问token
*/
private
String
accessToken
;
/**
* 刷新token
*/
private
String
refreshToken
;
/**
* 设备序列号
*/
private
String
sn
;
/**
* 登录状态:1-登录中、2-已登出
*/
private
String
loginStatus
;
/**
* 登录时间
*/
private
Date
loginTime
;
/**
* 登出时间
*/
private
Date
logoutTime
;
/**
* token刷新时间
*/
private
Date
refreshTime
;
/**
* 访问token有效期
*/
private
Date
accessTokenValidTime
;
/**
* 刷新token有效期
*/
private
Date
refreshTokenValidTime
;
}
src/main/java/com/esv/freight/app/module/account/form/LoginByPwdForm.java
0 → 100644
View file @
b9743359
package
com
.
esv
.
freight
.
app
.
module
.
account
.
form
;
import
com.esv.freight.app.common.validator.groups.ValidatorDelete
;
import
com.esv.freight.app.common.validator.groups.ValidatorInsert
;
import
com.esv.freight.app.common.validator.groups.ValidatorUpdate
;
import
lombok.Data
;
import
org.apache.commons.lang3.builder.ToStringBuilder
;
import
org.apache.commons.lang3.builder.ToStringStyle
;
import
org.hibernate.validator.constraints.Length
;
import
javax.validation.constraints.NotBlank
;
/**
* @description: 账号密码登录验证类
* @project: Freight
* @name: com.esv.freight.module.ownerBackend.account.form.LoginByPwdForm
* @author: 张志臣
* @email: zhangzhichen@esvtek.com
* @createTime: 2020/04/10 16:00
* @version:1.0
*/
@Data
public
class
LoginByPwdForm
{
/**
* 手机号
*/
@Length
(
min
=
11
,
max
=
11
,
message
=
"参数phone长度不合法"
,
groups
=
{
ValidatorInsert
.
class
,
ValidatorUpdate
.
class
,
ValidatorDelete
.
class
})
@NotBlank
(
message
=
"参数phone不能为空"
,
groups
=
{
ValidatorInsert
.
class
,
ValidatorUpdate
.
class
,
ValidatorDelete
.
class
})
private
String
phone
;
/**
* 密码
*/
@Length
(
min
=
32
,
max
=
32
,
message
=
"参数pwd长度不合法"
,
groups
=
{
ValidatorInsert
.
class
,
ValidatorUpdate
.
class
,
ValidatorDelete
.
class
})
@NotBlank
(
message
=
"参数pwd不能为空"
,
groups
=
{
ValidatorInsert
.
class
,
ValidatorUpdate
.
class
,
ValidatorDelete
.
class
})
private
String
pwd
;
@Override
public
String
toString
()
{
return
ToStringBuilder
.
reflectionToString
(
this
,
ToStringStyle
.
JSON_STYLE
);
}
}
src/main/java/com/esv/freight/app/module/account/form/LoginBySmsForm.java
0 → 100644
View file @
b9743359
package
com
.
esv
.
freight
.
app
.
module
.
account
.
form
;
import
com.esv.freight.app.common.validator.groups.ValidatorDelete
;
import
com.esv.freight.app.common.validator.groups.ValidatorInsert
;
import
com.esv.freight.app.common.validator.groups.ValidatorUpdate
;
import
lombok.Data
;
import
org.apache.commons.lang3.builder.ToStringBuilder
;
import
org.apache.commons.lang3.builder.ToStringStyle
;
import
org.hibernate.validator.constraints.Length
;
import
javax.validation.constraints.NotBlank
;
/**
* @description: 短信验证码登录验证类
* @project: Freight
* @name: com.esv.freight.module.ownerBackend.account.form.LoginBySmsForm
* @author: 张志臣
* @email: zhangzhichen@esvtek.com
* @createTime: 2020/04/11 10:00
* @version:1.0
*/
@Data
public
class
LoginBySmsForm
{
/**
* 手机号
*/
@Length
(
min
=
11
,
max
=
11
,
message
=
"参数phone长度不合法"
,
groups
=
{
ValidatorInsert
.
class
,
ValidatorUpdate
.
class
,
ValidatorDelete
.
class
})
@NotBlank
(
message
=
"参数phone不能为空"
,
groups
=
{
ValidatorInsert
.
class
,
ValidatorUpdate
.
class
,
ValidatorDelete
.
class
})
private
String
phone
;
/**
* 短信验证码
*/
@Length
(
min
=
6
,
max
=
6
,
message
=
"参数pwd长度不合法"
,
groups
=
{
ValidatorInsert
.
class
,
ValidatorUpdate
.
class
,
ValidatorDelete
.
class
})
@NotBlank
(
message
=
"参数smsCode不能为空"
,
groups
=
{
ValidatorInsert
.
class
,
ValidatorUpdate
.
class
,
ValidatorDelete
.
class
})
private
String
smsCode
;
@Override
public
String
toString
()
{
return
ToStringBuilder
.
reflectionToString
(
this
,
ToStringStyle
.
JSON_STYLE
);
}
}
src/main/java/com/esv/freight/app/module/account/form/ModifyPasswordForm.java
0 → 100644
View file @
b9743359
package
com
.
esv
.
freight
.
app
.
module
.
account
.
form
;
import
com.esv.freight.app.common.validator.groups.ValidatorDelete
;
import
com.esv.freight.app.common.validator.groups.ValidatorInsert
;
import
com.esv.freight.app.common.validator.groups.ValidatorUpdate
;
import
lombok.Data
;
import
org.apache.commons.lang3.builder.ToStringBuilder
;
import
org.apache.commons.lang3.builder.ToStringStyle
;
import
org.hibernate.validator.constraints.Length
;
import
javax.validation.constraints.NotBlank
;
/**
* @description: 重置密码验证类
* @project: Freight
* @name: com.esv.freight.module.ownerBackend.account.form.ModifyPasswordFrom
* @author: 张志臣
* @email: zhangzhichen@esvtek.com
* @createTime: 2020/04/13 10:00
* @version:1.0
*/
@Data
public
class
ModifyPasswordForm
{
/**
* 原密码
*/
@Length
(
min
=
32
,
max
=
32
,
message
=
"参数oldPwdd长度不合法"
,
groups
=
{
ValidatorInsert
.
class
,
ValidatorUpdate
.
class
,
ValidatorDelete
.
class
})
@NotBlank
(
message
=
"参数pwd不能为空"
,
groups
=
{
ValidatorInsert
.
class
,
ValidatorUpdate
.
class
,
ValidatorDelete
.
class
})
private
String
oldPwd
;
/**
* 新密码
*/
@Length
(
min
=
32
,
max
=
32
,
message
=
"参数newPwd长度不合法"
,
groups
=
{
ValidatorInsert
.
class
,
ValidatorUpdate
.
class
,
ValidatorDelete
.
class
})
@NotBlank
(
message
=
"参数pwd不能为空"
,
groups
=
{
ValidatorInsert
.
class
,
ValidatorUpdate
.
class
,
ValidatorDelete
.
class
})
private
String
newPwd
;
@Override
public
String
toString
()
{
return
ToStringBuilder
.
reflectionToString
(
this
,
ToStringStyle
.
JSON_STYLE
);
}
}
src/main/java/com/esv/freight/app/module/account/form/RealNameAuthForm.java
0 → 100644
View file @
b9743359
package
com
.
esv
.
freight
.
app
.
module
.
account
.
form
;
import
com.esv.freight.app.common.validator.groups.ValidatorInsert
;
import
com.esv.freight.app.common.validator.groups.ValidatorList
;
import
com.esv.freight.app.common.validator.groups.ValidatorUpdate
;
import
lombok.Data
;
import
org.apache.commons.lang3.builder.ToStringBuilder
;
import
org.apache.commons.lang3.builder.ToStringStyle
;
import
org.hibernate.validator.constraints.Length
;
import
javax.validation.constraints.NotNull
;
/**
* @description: 账号实名认证验证类
* @project: Freight
* @name: com.esv.freight.module.ownerBackend.account.form.RealNameAuthForm
* @author: 张志臣
* @email: zhangzhichen@esvtek.com
* @createTime: 2020/04/13 10:00
* @version:1.0
*/
@Data
public
class
RealNameAuthForm
{
/**
* 身份证正面图片数据
*/
@NotNull
(
message
=
"参数idCardFileFront不能为空"
)
private
String
idCardFileFront
;
/**
* 身份证背面图片数据
*/
@NotNull
(
message
=
"参数idCardFileBack不能为空"
)
private
String
idCardFileBack
;
/**
* 姓名
*/
@NotNull
(
message
=
"参数name不能为空"
)
@Length
(
max
=
50
,
message
=
"姓名长度不合法"
)
private
String
name
;
/**
* 身份证号码
*/
@Length
(
max
=
18
,
message
=
"参数idCard长度不合法"
,
groups
=
{
ValidatorList
.
class
})
@Length
(
min
=
18
,
max
=
18
,
message
=
"参数idCard长度不合法"
,
groups
=
{
ValidatorInsert
.
class
,
ValidatorUpdate
.
class
})
@NotNull
(
message
=
"参数idCard不能为空"
)
private
String
idCard
;
/**
* 身份证有效期,格式yyyy.MM.dd,或长期
*/
private
String
idCardExpireDate
;
/**
* 省份代码
*/
@Length
(
max
=
6
,
message
=
"参数provinceCode长度不合法"
,
groups
=
{
ValidatorList
.
class
})
@Length
(
min
=
6
,
max
=
6
,
message
=
"参数provinceCode长度不合法"
,
groups
=
{
ValidatorInsert
.
class
,
ValidatorUpdate
.
class
})
@NotNull
(
message
=
"参数provinceCode不能为空"
)
private
String
provinceCode
;
/**
* 市代码
*/
@Length
(
max
=
6
,
message
=
"参数cityCode长度不合法"
,
groups
=
{
ValidatorList
.
class
})
@Length
(
min
=
6
,
max
=
6
,
message
=
"参数cityCode长度不合法"
,
groups
=
{
ValidatorInsert
.
class
,
ValidatorUpdate
.
class
})
@NotNull
(
message
=
"参数cityCode不能为空"
)
private
String
cityCode
;
/**
* 区县代码
*/
@Length
(
max
=
6
,
message
=
"参数districtCode长度不合法"
,
groups
=
{
ValidatorList
.
class
})
@Length
(
min
=
6
,
max
=
6
,
message
=
"参数districtCode长度不合法"
,
groups
=
{
ValidatorInsert
.
class
,
ValidatorUpdate
.
class
})
@NotNull
(
message
=
"参数districtCode不能为空"
)
private
String
districtCode
;
/**
* 详细地址
*/
@NotNull
(
message
=
"参数detailAddress不能为空"
)
@Length
(
max
=
50
,
message
=
"详细地址长度不合法"
)
private
String
detailAddress
;
@Override
public
String
toString
()
{
return
ToStringBuilder
.
reflectionToString
(
this
,
ToStringStyle
.
JSON_STYLE
);
}
}
src/main/java/com/esv/freight/app/module/account/form/RefreshTokenForm.java
0 → 100644
View file @
b9743359
package
com
.
esv
.
freight
.
app
.
module
.
account
.
form
;
import
lombok.Data
;
import
javax.validation.constraints.NotNull
;
/**
* @description: 刷新token验证类
* @project: Freight
* @name: com.esv.freight.module.ownerBackend.account.form.RefreshTokenForm
* @author: 张志臣
* @email: zhangzhichen@esvtek.com
* @createTime: 2020/04/18 09:00
* @version:1.0
*/
@Data
public
class
RefreshTokenForm
{
/**
* 刷新token
*/
@NotNull
(
message
=
"参数refreshToken不能为空"
)
private
String
refreshToken
;
}
src/main/java/com/esv/freight/app/module/account/form/ResetPasswordForm.java
0 → 100644
View file @
b9743359
package
com
.
esv
.
freight
.
app
.
module
.
account
.
form
;
import
com.esv.freight.app.common.validator.groups.ValidatorDelete
;
import
com.esv.freight.app.common.validator.groups.ValidatorInsert
;
import
com.esv.freight.app.common.validator.groups.ValidatorList
;
import
com.esv.freight.app.common.validator.groups.ValidatorUpdate
;
import
lombok.Data
;
import
org.apache.commons.lang3.builder.ToStringBuilder
;
import
org.apache.commons.lang3.builder.ToStringStyle
;
import
org.hibernate.validator.constraints.Length
;
import
javax.validation.constraints.NotBlank
;
/**
* @description: 账号注册验证类
* @project: Freight
* @name: com.esv.freight.module.ownerBackend.account.form.AccountRegisterForm
* @author: 张志臣
* @email: zhangzhichen@esvtek.com
* @createTime: 2020/04/13 09:00
* @version:1.0
*/
@Data
public
class
ResetPasswordForm
{
/**
* 手机号
*/
@Length
(
max
=
17
,
message
=
"参数phone长度不合法"
,
groups
=
{
ValidatorList
.
class
})
@Length
(
min
=
11
,
max
=
11
,
message
=
"参数phone长度不合法"
,
groups
=
{
ValidatorInsert
.
class
,
ValidatorUpdate
.
class
,
ValidatorDelete
.
class
})
@NotBlank
(
message
=
"参数phone不能为空"
,
groups
=
{
ValidatorInsert
.
class
,
ValidatorUpdate
.
class
,
ValidatorDelete
.
class
})
private
String
phone
;
/**
* 短信验证码
*/
@Length
(
min
=
6
,
max
=
6
,
message
=
"参数pwd长度不合法"
,
groups
=
{
ValidatorInsert
.
class
,
ValidatorUpdate
.
class
,
ValidatorDelete
.
class
})
@NotBlank
(
message
=
"参数smsCode不能为空"
,
groups
=
{
ValidatorInsert
.
class
,
ValidatorUpdate
.
class
,
ValidatorDelete
.
class
})
private
String
smsCode
;
/**
* 密码
*/
@Length
(
min
=
32
,
max
=
32
,
message
=
"参数pwd长度不合法"
,
groups
=
{
ValidatorInsert
.
class
,
ValidatorUpdate
.
class
,
ValidatorDelete
.
class
})
@NotBlank
(
message
=
"参数pwd不能为空"
,
groups
=
{
ValidatorInsert
.
class
,
ValidatorUpdate
.
class
,
ValidatorDelete
.
class
})
private
String
pwd
;
@Override
public
String
toString
()
{
return
ToStringBuilder
.
reflectionToString
(
this
,
ToStringStyle
.
JSON_STYLE
);
}
}
src/main/java/com/esv/freight/app/module/account/service/AppLoginService.java
0 → 100644
View file @
b9743359
package
com
.
esv
.
freight
.
app
.
module
.
account
.
service
;
import
com.baomidou.mybatisplus.extension.service.IService
;
import
com.esv.freight.app.module.account.entity.AppLoginEntity
;
import
com.esv.freight.app.module.account.form.RefreshTokenForm
;
import
com.esv.freight.app.module.account.vo.AccountDetailVO
;
import
com.esv.freight.app.module.account.vo.LoginVO
;
/**
* APP用户登录信息表
*
* @author 张志臣
* @email zhangzhichen@esvtek.com
* @date 2020-04-15 10:00
*/
public
interface
AppLoginService
extends
IService
<
AppLoginEntity
>
{
LoginVO
loginByPwd
(
String
phone
);
LoginVO
loginBySms
(
String
phone
);
void
logout
(
String
accessToken
);
LoginVO
refreshToken
(
String
accessToken
,
RefreshTokenForm
refreshTokenForm
);
boolean
isExistAccount
(
String
phone
);
boolean
isInvalidAccessToken
(
String
accessToken
);
boolean
isInvalidRefreshToken
(
String
refreshToken
);
AccountDetailVO
getAccountDetailInfo
(
String
accessToken
);
}
\ No newline at end of file
src/main/java/com/esv/freight/app/module/account/service/impl/AppLoginImpl.java
0 → 100644
View file @
b9743359
package
com
.
esv
.
freight
.
app
.
module
.
account
.
service
.
impl
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
import
com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
;
import
com.esv.freight.app.common.exception.EException
;
import
com.esv.freight.app.module.account.dao.AppLoginDao
;
import
com.esv.freight.app.module.account.entity.AppLoginEntity
;
import
com.esv.freight.app.module.account.form.RefreshTokenForm
;
import
com.esv.freight.app.module.account.service.AppLoginService
;
import
com.esv.freight.app.module.account.vo.AccountDetailVO
;
import
com.esv.freight.app.module.account.vo.LoginVO
;
import
org.springframework.stereotype.Service
;
import
java.text.DateFormat
;
import
java.text.SimpleDateFormat
;
import
java.util.Calendar
;
import
java.util.Date
;
import
java.util.UUID
;
@Service
(
"appLoginService"
)
public
class
AppLoginImpl
extends
ServiceImpl
<
AppLoginDao
,
AppLoginEntity
>
implements
AppLoginService
{
private
void
createToken
(
AppLoginEntity
entity
)
{
if
(
entity
==
null
)
{
return
;
}
entity
.
setAccessToken
(
UUID
.
randomUUID
().
toString
().
replaceAll
(
"-"
,
""
));
entity
.
setRefreshToken
(
UUID
.
randomUUID
().
toString
().
replaceAll
(
"-"
,
""
));
}
@Override
public
LoginVO
loginBySms
(
String
phone
)
{
AppLoginEntity
appLoginEntity
=
this
.
getAccountByPhone
(
phone
);
if
(
null
==
appLoginEntity
)
{
return
addLogin
(
phone
);
}
createToken
(
appLoginEntity
);
appLoginEntity
.
setLoginStatus
(
"1"
);
appLoginEntity
.
setLoginTime
(
new
Date
());
appLoginEntity
.
setRefreshTime
(
new
Date
());
appLoginEntity
.
setAccessTokenValidTime
(
getFuture
(
1
));
appLoginEntity
.
setRefreshTokenValidTime
(
getFuture
(
30
));
this
.
baseMapper
.
updateById
(
appLoginEntity
);
//数据转换
LoginVO
loginByPwdVO
=
new
LoginVO
();
loginByPwdVO
.
setAccessToken
(
appLoginEntity
.
getAccessToken
());
loginByPwdVO
.
setRefreshToken
(
appLoginEntity
.
getRefreshToken
());
return
loginByPwdVO
;
}
private
LoginVO
addLogin
(
String
phone
)
{
AppLoginEntity
appLoginEntity
=
new
AppLoginEntity
();
appLoginEntity
.
setPhone
(
phone
);
createToken
(
appLoginEntity
);
appLoginEntity
.
setLoginStatus
(
"1"
);
appLoginEntity
.
setLoginTime
(
new
Date
());
appLoginEntity
.
setRefreshTime
(
new
Date
());
appLoginEntity
.
setAccessTokenValidTime
(
getFuture
(
1
));
appLoginEntity
.
setRefreshTokenValidTime
(
getFuture
(
30
));
this
.
baseMapper
.
insert
(
appLoginEntity
);
//数据转换
LoginVO
loginByPwdVO
=
new
LoginVO
();
loginByPwdVO
.
setAccessToken
(
appLoginEntity
.
getAccessToken
());
loginByPwdVO
.
setRefreshToken
(
appLoginEntity
.
getRefreshToken
());
return
loginByPwdVO
;
}
@Override
public
LoginVO
loginByPwd
(
String
phone
)
{
AppLoginEntity
appLoginEntity
=
this
.
getAccountByPhone
(
phone
);
createToken
(
appLoginEntity
);
appLoginEntity
.
setLoginStatus
(
"1"
);
appLoginEntity
.
setLoginTime
(
new
Date
());
appLoginEntity
.
setRefreshTime
(
new
Date
());
appLoginEntity
.
setAccessTokenValidTime
(
getFuture
(
1
));
appLoginEntity
.
setRefreshTokenValidTime
(
getFuture
(
30
));
this
.
baseMapper
.
updateById
(
appLoginEntity
);
//数据转换
LoginVO
loginByPwdVO
=
new
LoginVO
();
loginByPwdVO
.
setAccessToken
(
appLoginEntity
.
getAccessToken
());
loginByPwdVO
.
setRefreshToken
(
appLoginEntity
.
getRefreshToken
());
return
loginByPwdVO
;
}
@Override
public
void
logout
(
String
accessToken
)
{
AppLoginEntity
entity
=
this
.
getAccountByAccessToken
(
accessToken
);
if
(
entity
==
null
)
{
throw
new
EException
(
602
,
"Token已过期,请重新登录"
);
}
entity
.
setAccessToken
(
""
);
entity
.
setRefreshToken
(
""
);
entity
.
setLoginStatus
(
"2"
);
entity
.
setLogoutTime
(
new
Date
());
this
.
baseMapper
.
updateById
(
entity
);
}
@Override
public
LoginVO
refreshToken
(
String
accessToken
,
RefreshTokenForm
refreshTokenForm
)
{
AppLoginEntity
entity
=
this
.
getAccountByAccessToken
(
accessToken
);
if
(
entity
==
null
)
{
throw
new
EException
(
602
,
"Token已过期,请重新登录"
);
}
if
(
isInvalidRefreshToken
(
refreshTokenForm
.
getRefreshToken
()))
{
throw
new
EException
(
602
,
"Token已过期,请重新登录"
);
}
createToken
(
entity
);
entity
.
setRefreshTime
(
new
Date
());
entity
.
setLoginStatus
(
"1"
);
entity
.
setAccessTokenValidTime
(
getFuture
(
1
));
entity
.
setRefreshTokenValidTime
(
getFuture
(
30
));
this
.
baseMapper
.
updateById
(
entity
);
//数据转换
LoginVO
loginByPwdVO
=
new
LoginVO
();
loginByPwdVO
.
setAccessToken
(
entity
.
getAccessToken
());
loginByPwdVO
.
setRefreshToken
(
entity
.
getRefreshToken
());
return
loginByPwdVO
;
}
@Override
public
boolean
isExistAccount
(
String
phone
)
{
AppLoginEntity
entity
=
this
.
getAccountByPhone
(
phone
);
if
(
null
==
entity
)
{
return
false
;
}
return
true
;
}
@Override
public
AccountDetailVO
getAccountDetailInfo
(
String
accessToken
)
{
AppLoginEntity
entity
=
this
.
getAccountByAccessToken
(
accessToken
);
if
(
entity
==
null
)
{
throw
new
EException
(
602
,
"Token已过期,请重新登录"
);
}
AccountDetailVO
accountDetailVO
=
new
AccountDetailVO
();
accountDetailVO
.
setAccount
(
entity
.
getPhone
());
accountDetailVO
.
setContactor
(
"赵龙"
);
accountDetailVO
.
setId
(
"testownerid123"
);
accountDetailVO
.
setAuthenticateStatus
(
1
);
accountDetailVO
.
setOwnerType
(
1
);
return
accountDetailVO
;
}
@Override
public
boolean
isInvalidAccessToken
(
String
accessToken
)
{
AppLoginEntity
entity
=
this
.
getAccountByAccessToken
(
accessToken
);
if
(
entity
==
null
)
{
throw
new
EException
(
602
,
"Token已过期,请重新登录"
);
}
Date
current
=
new
Date
();
Date
accessDate
=
entity
.
getAccessTokenValidTime
();
if
(
current
.
after
(
accessDate
))
{
return
true
;
}
return
false
;
}
@Override
public
boolean
isInvalidRefreshToken
(
String
refreshToken
)
{
AppLoginEntity
entity
=
this
.
getAccountByRefreshToken
(
refreshToken
);
if
(
entity
==
null
)
{
throw
new
EException
(
602
,
"Token已过期,请重新登录"
);
}
Date
current
=
new
Date
();
Date
refreshDate
=
entity
.
getRefreshTokenValidTime
();
if
(
current
.
after
(
refreshDate
))
{
return
true
;
}
return
false
;
}
private
AppLoginEntity
getAccountByPhone
(
String
phone
)
{
QueryWrapper
<
AppLoginEntity
>
queryWrapper
=
new
QueryWrapper
<>();
queryWrapper
.
eq
(
"phone"
,
phone
);
return
this
.
baseMapper
.
selectOne
(
queryWrapper
);
}
private
AppLoginEntity
getAccountByAccessToken
(
String
accessToken
)
{
QueryWrapper
<
AppLoginEntity
>
queryWrapper
=
new
QueryWrapper
<>();
queryWrapper
.
eq
(
"access_token"
,
accessToken
);
return
this
.
baseMapper
.
selectOne
(
queryWrapper
);
}
private
AppLoginEntity
getAccountByRefreshToken
(
String
refreshToken
)
{
QueryWrapper
<
AppLoginEntity
>
queryWrapper
=
new
QueryWrapper
<>();
queryWrapper
.
select
().
eq
(
"refresh_token"
,
refreshToken
);
return
this
.
baseMapper
.
selectOne
(
queryWrapper
);
}
/**
* 返回未来天数
* @param days
* @return
*/
public
Date
getFuture
(
int
days
)
{
Calendar
calendar
=
Calendar
.
getInstance
();
calendar
.
setTime
(
new
Date
());
calendar
.
set
(
Calendar
.
DATE
,
calendar
.
get
(
Calendar
.
DATE
)
+
days
);
return
calendar
.
getTime
();
}
}
src/main/java/com/esv/freight/app/module/account/vo/AccountDetailVO.java
0 → 100644
View file @
b9743359
package
com
.
esv
.
freight
.
app
.
module
.
account
.
vo
;
import
lombok.Data
;
/**
* @description: 账号详情VO
* @project: Freight
* @name: com.esv.freight.module.ownerBackend.account.login.vo.AccountDetailVO
* @author: 张志臣
* @email: zhangzhichen@esvtek.com
* @createTime: 2020/04/13 17:00
* @version:1.0
*/
@Data
public
class
AccountDetailVO
{
// 账号ID
private
String
id
;
// 认证状态:1-未认证、2-已认证
private
Integer
authenticateStatus
;
// 货主类型:1-个人、2-企业
private
Integer
ownerType
;
// 帐号
private
String
account
;
// 姓名
private
String
contactor
;
// 身份证号码
private
String
idCard
;
// 身份证有效期 格式yyyy.MM.dd,或长期
private
String
idCardExpireDate
;
// 身份证正面图片URL
private
String
idCardFileFrontURL
;
// 身份证反面图片URL
private
String
idCardFileBackURL
;
}
src/main/java/com/esv/freight/app/module/account/vo/LoginVO.java
0 → 100644
View file @
b9743359
package
com
.
esv
.
freight
.
app
.
module
.
account
.
vo
;
import
lombok.Data
;
import
org.apache.commons.lang3.builder.ToStringBuilder
;
import
org.apache.commons.lang3.builder.ToStringStyle
;
/**
* @description: 账号密码登录VO
* @project: Freight
* @name: com.esv.freight.module.ownerBackend.account.login.vo.LoginByPwdVO
* @author: 张志臣
* @email: zhangzhichen@esvtek.com
* @createTime: 2020/04/10 16:00
* @version:1.0
*/
@Data
public
class
LoginVO
{
/**
* 访问Token
*/
private
String
accessToken
;
/**
* 刷新Token
*/
private
String
refreshToken
;
@Override
public
String
toString
()
{
return
ToStringBuilder
.
reflectionToString
(
this
,
ToStringStyle
.
JSON_STYLE
);
}
}
src/main/java/com/esv/freight/app/module/address/controller/DeliveryAddressController.java
0 → 100644
View file @
b9743359
package
com
.
esv
.
freight
.
app
.
module
.
address
.
controller
;
import
com.esv.freight.app.common.response.ECode
;
import
com.esv.freight.app.common.response.EResponse
;
import
com.esv.freight.app.common.validator.groups.ValidatorInsert
;
import
com.esv.freight.app.module.address.form.CreateDeliveryAddressForm
;
import
com.esv.freight.app.module.address.form.DeleteAddressForm
;
import
com.esv.freight.app.module.address.form.EditDeliveryAddressForm
;
import
com.esv.freight.app.module.address.service.AddressAccountService
;
import
com.esv.freight.app.module.address.vo.DeliveryAddressListVO
;
import
com.esv.freight.app.module.address.vo.DeliveryAddressItemVO
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.validation.annotation.Validated
;
import
org.springframework.web.bind.annotation.*
;
import
javax.validation.constraints.NotBlank
;
import
java.util.ArrayList
;
import
java.util.List
;
/**
* @description: 发货地址Controller
* @project: Freight
* @name: com.esv.freight.module.ownerBackend.address.controller.DeliveryAddressController
* @author: 张志臣
* @email: zhangzhichen@esvtek.com
* @createTime: 2020/04/13 10:00
* @version:1.0
*/
@RestController
@RequestMapping
(
"/ownerBackend/address/delivery"
)
@Slf4j
@Validated
public
class
DeliveryAddressController
{
private
AddressAccountService
addressAccountService
;
private
DeliveryAddressListVO
deliveryAddressListVO
;
private
List
<
DeliveryAddressItemVO
>
listDeliveryAddressVO
;
private
Integer
mIndex
=
100
;
@Autowired
public
DeliveryAddressController
(
AddressAccountService
addressAccountService
)
{
this
.
addressAccountService
=
addressAccountService
;
deliveryAddressListVO
=
new
DeliveryAddressListVO
();
listDeliveryAddressVO
=
new
ArrayList
<>();
deliveryAddressListVO
.
setRecords
(
listDeliveryAddressVO
);
}
/**
* description 发货地址列表
* param [accessToken]
* return com.esv.freight.common.response.EResponse
* author 张志臣
* createTime 2020/04/17 13:00
**/
@PostMapping
(
"/list"
)
public
EResponse
list
(
@RequestHeader
(
"Union-Authorization"
)
String
accessToken
)
{
String
phone
=
addressAccountService
.
getPhoneByAccessToken
(
accessToken
);
if
(
phone
==
null
||
""
.
equals
(
phone
))
{
return
EResponse
.
error
(
1001
,
"未找到此用户"
);
}
// TODO,Feign调用货主发货地址列表接口,目前暂时返回假数据
return
EResponse
.
ok
(
deliveryAddressListVO
);
}
/**
* description 新增发货地址
* param [CreateAddressForm]
* return com.esv.freight.common.response.EResponse
* author 张志臣
* createTime 2020/04/13 11:00
**/
@PostMapping
(
"/add"
)
public
EResponse
add
(
@RequestHeader
(
"Union-Authorization"
)
String
accessToken
,
@RequestBody
(
required
=
false
)
@Validated
(
ValidatorInsert
.
class
)
CreateDeliveryAddressForm
createAddressForm
)
{
if
(
createAddressForm
==
null
)
{
return
EResponse
.
error
(
ECode
.
PARAM_ERROR
);
}
String
phone
=
addressAccountService
.
getPhoneByAccessToken
(
accessToken
);
if
(
phone
==
null
||
""
.
equals
(
phone
))
{
return
EResponse
.
error
(
1001
,
"未找到此用户"
);
}
// TODO,Feign调用货主发货地址列表接口,目前暂时返回假数据
for
(
int
i
=
0
;
i
<
listDeliveryAddressVO
.
size
();
++
i
)
{
DeliveryAddressItemVO
vo
=
listDeliveryAddressVO
.
get
(
i
);
if
(
createAddressForm
.
getAddressName
().
equals
(
vo
.
getAddressName
()))
{
return
EResponse
.
error
(
1002
,
"重复的地址名称"
);
}
}
DeliveryAddressItemVO
deliveryAddressVO
=
new
DeliveryAddressItemVO
();
deliveryAddressVO
.
setAddressName
(
createAddressForm
.
getAddressName
());
deliveryAddressVO
.
setId
(++
mIndex
);
deliveryAddressVO
.
setProvinceCode
(
createAddressForm
.
getProvinceCode
());
deliveryAddressVO
.
setCityCode
(
createAddressForm
.
getCityCode
());
deliveryAddressVO
.
setDistrictCode
(
createAddressForm
.
getDistrictCode
());
deliveryAddressVO
.
setDetailAddress
(
createAddressForm
.
getDetailAddress
());
deliveryAddressVO
.
setDeliverer
(
createAddressForm
.
getDeliverer
());
deliveryAddressVO
.
setDelivererPhone
(
createAddressForm
.
getDelivererPhone
());
listDeliveryAddressVO
.
add
(
deliveryAddressVO
);
return
EResponse
.
ok
();
}
/**
* description 编辑发货地址
* param [EditAddressForm]
* return com.esv.freight.common.response.EResponse
* author 张志臣
* createTime 2020/04/13 11:00
**/
@PostMapping
(
"/edit"
)
public
EResponse
edit
(
@RequestHeader
(
"Union-Authorization"
)
String
accessToken
,
@RequestBody
(
required
=
false
)
@Validated
(
ValidatorInsert
.
class
)
EditDeliveryAddressForm
editAddressForm
)
{
if
(
editAddressForm
==
null
)
{
return
EResponse
.
error
(
ECode
.
PARAM_ERROR
);
}
String
phone
=
addressAccountService
.
getPhoneByAccessToken
(
accessToken
);
if
(
phone
==
null
||
""
.
equals
(
phone
))
{
return
EResponse
.
error
(
1003
,
"未找到此用户"
);
}
// TODO,Feign调用货主发货地址列表接口,目前暂时返回假数据
DeliveryAddressItemVO
deliveryAddressVO
=
null
;
for
(
int
i
=
0
;
i
<
listDeliveryAddressVO
.
size
();
++
i
)
{
DeliveryAddressItemVO
addressVO
=
listDeliveryAddressVO
.
get
(
i
);
if
(
addressVO
.
getId
()
==
editAddressForm
.
getId
())
{
deliveryAddressVO
=
addressVO
;
break
;
}
}
if
(
deliveryAddressVO
==
null
)
{
return
EResponse
.
error
(
1001
,
"无效的地址ID"
);
}
deliveryAddressVO
.
setAddressName
(
editAddressForm
.
getAddressName
());
deliveryAddressVO
.
setProvinceCode
(
editAddressForm
.
getProvinceCode
());
deliveryAddressVO
.
setCityCode
(
editAddressForm
.
getCityCode
());
deliveryAddressVO
.
setDistrictCode
(
editAddressForm
.
getDistrictCode
());
deliveryAddressVO
.
setDetailAddress
(
editAddressForm
.
getDetailAddress
());
deliveryAddressVO
.
setDeliverer
(
editAddressForm
.
getDeliverer
());
deliveryAddressVO
.
setDelivererPhone
(
editAddressForm
.
getDelivererPhone
());
return
EResponse
.
ok
();
}
/**
* description 删除发货地址
* param [EditAddressForm]
* return com.esv.freight.common.response.EResponse
* author 张志臣
* createTime 2020/04/13 11:00
**/
@PostMapping
(
"/delete"
)
public
EResponse
delete
(
@RequestHeader
(
"Union-Authorization"
)
String
accessToken
,
@RequestBody
(
required
=
false
)
@Validated
(
ValidatorInsert
.
class
)
DeleteAddressForm
deleteAddressForm
)
{
String
phone
=
addressAccountService
.
getPhoneByAccessToken
(
accessToken
);
if
(
phone
==
null
||
""
.
equals
(
phone
))
{
return
EResponse
.
error
(
1003
,
"未找到此用户"
);
}
// TODO,Feign调用货主发货地址列表接口,目前暂时返回假数据
DeliveryAddressItemVO
deliveryAddressVO
=
null
;
int
index
=
0
;
for
(
index
=
0
;
index
<
listDeliveryAddressVO
.
size
();
++
index
)
{
DeliveryAddressItemVO
addressVO
=
listDeliveryAddressVO
.
get
(
index
);
if
(
addressVO
.
getId
()
==
deleteAddressForm
.
getId
())
{
deliveryAddressVO
=
addressVO
;
break
;
}
}
if
(
deliveryAddressVO
==
null
)
{
return
EResponse
.
error
(
1001
,
"无效的地址ID"
);
}
listDeliveryAddressVO
.
remove
(
index
);
return
EResponse
.
ok
();
}
/**
* description 默认发货地址
* param [EditAddressForm]
* return com.esv.freight.common.response.EResponse
* author 张志臣
* createTime 2020/04/13 11:00
**/
@PostMapping
(
"/default"
)
public
EResponse
defaultAddress
(
@NotBlank
(
message
=
"ID不能为空"
)
@RequestParam
String
id
)
{
return
EResponse
.
ok
();
}
}
src/main/java/com/esv/freight/app/module/address/controller/ReceiveAddressController.java
0 → 100644
View file @
b9743359
package
com
.
esv
.
freight
.
app
.
module
.
address
.
controller
;
import
com.esv.freight.app.common.response.ECode
;
import
com.esv.freight.app.common.response.EResponse
;
import
com.esv.freight.app.common.validator.groups.ValidatorInsert
;
import
com.esv.freight.app.module.address.form.CreateReceiveAddressForm
;
import
com.esv.freight.app.module.address.form.DeleteAddressForm
;
import
com.esv.freight.app.module.address.form.EditReceiveAddressForm
;
import
com.esv.freight.app.module.address.service.AddressAccountService
;
import
com.esv.freight.app.module.address.vo.ReceiveAddressListVO
;
import
com.esv.freight.app.module.address.vo.ReceiveAddressItemVO
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.validation.annotation.Validated
;
import
org.springframework.web.bind.annotation.*
;
import
javax.validation.constraints.NotBlank
;
import
java.util.ArrayList
;
import
java.util.List
;
/**
* @description: 收货地址Controller
* @project: Freight
* @name: com.esv.freight.module.ownerBackend.address.controller.ReceiveAddressController
* @author: 张志臣
* @email: zhangzhichen@esvtek.com
* @createTime: 2020/04/13 10:00
* @version:1.0
*/
@RestController
@RequestMapping
(
"/ownerBackend/address/receive"
)
@Slf4j
@Validated
public
class
ReceiveAddressController
{
private
AddressAccountService
addressAccountService
;
private
ReceiveAddressListVO
receiveAddressListVO
;
private
List
<
ReceiveAddressItemVO
>
listReceiveAddressVO
;
private
Integer
mIndex
=
100
;
@Autowired
public
ReceiveAddressController
(
AddressAccountService
addressAccountService
)
{
this
.
addressAccountService
=
addressAccountService
;
receiveAddressListVO
=
new
ReceiveAddressListVO
();
listReceiveAddressVO
=
new
ArrayList
<>();
receiveAddressListVO
.
setRecords
(
listReceiveAddressVO
);
}
/**
* description 收货地址列表
* param [accessToken]
* return com.esv.freight.common.response.EResponse
* author 张志臣
* createTime 2020/04/17 13:00
**/
@PostMapping
(
"/list"
)
public
EResponse
list
(
@RequestHeader
(
"Union-Authorization"
)
String
accessToken
)
{
String
phone
=
addressAccountService
.
getPhoneByAccessToken
(
accessToken
);
if
(
phone
==
null
||
""
.
equals
(
phone
))
{
return
EResponse
.
error
(
1001
,
"未找到此用户"
);
}
// TODO,Feign调用货主发货地址列表接口,目前暂时返回假数据
return
EResponse
.
ok
(
receiveAddressListVO
);
}
/**
* description 新增收货地址
* param [CreateAddressForm]
* return com.esv.freight.common.response.EResponse
* author 张志臣
* createTime 2020/04/13 11:00
**/
@PostMapping
(
"/add"
)
public
EResponse
add
(
@RequestHeader
(
"Union-Authorization"
)
String
accessToken
,
@RequestBody
(
required
=
false
)
@Validated
(
ValidatorInsert
.
class
)
CreateReceiveAddressForm
createAddressForm
)
{
if
(
createAddressForm
==
null
)
{
return
EResponse
.
error
(
ECode
.
PARAM_ERROR
);
}
String
phone
=
addressAccountService
.
getPhoneByAccessToken
(
accessToken
);
if
(
phone
==
null
||
""
.
equals
(
phone
))
{
return
EResponse
.
error
(
1001
,
"未找到此用户"
);
}
// TODO,Feign调用货主发货地址列表接口,目前暂时返回假数据
for
(
int
i
=
0
;
i
<
listReceiveAddressVO
.
size
();
++
i
)
{
ReceiveAddressItemVO
vo
=
listReceiveAddressVO
.
get
(
i
);
if
(
createAddressForm
.
getAddressName
().
equals
(
vo
.
getAddressName
()))
{
return
EResponse
.
error
(
1002
,
"重复的地址名称"
);
}
}
ReceiveAddressItemVO
receiveAddressVO
=
new
ReceiveAddressItemVO
();
receiveAddressVO
.
setAddressName
(
createAddressForm
.
getAddressName
());
receiveAddressVO
.
setId
(++
mIndex
);
receiveAddressVO
.
setProvinceCode
(
createAddressForm
.
getProvinceCode
());
receiveAddressVO
.
setCityCode
(
createAddressForm
.
getCityCode
());
receiveAddressVO
.
setDistrictCode
(
createAddressForm
.
getDistrictCode
());
receiveAddressVO
.
setDetailAddress
(
createAddressForm
.
getDetailAddress
());
receiveAddressVO
.
setReceiver
(
createAddressForm
.
getReceiver
());
receiveAddressVO
.
setReceiverPhone
(
createAddressForm
.
getReceiverPhone
());
listReceiveAddressVO
.
add
(
receiveAddressVO
);
return
EResponse
.
ok
();
}
/**
* description 编辑收货地址
* param [EditAddressForm]
* return com.esv.freight.common.response.EResponse
* author 张志臣
* createTime 2020/04/13 11:00
**/
@PostMapping
(
"/edit"
)
public
EResponse
edit
(
@RequestHeader
(
"Union-Authorization"
)
String
accessToken
,
@RequestBody
(
required
=
false
)
@Validated
(
ValidatorInsert
.
class
)
EditReceiveAddressForm
editAddressForm
)
{
if
(
editAddressForm
==
null
)
{
return
EResponse
.
error
(
ECode
.
PARAM_ERROR
);
}
String
phone
=
addressAccountService
.
getPhoneByAccessToken
(
accessToken
);
if
(
phone
==
null
||
""
.
equals
(
phone
))
{
return
EResponse
.
error
(
1003
,
"未找到此用户"
);
}
// TODO,Feign调用货主发货地址列表接口,目前暂时返回假数据
ReceiveAddressItemVO
receiveAddressVO
=
null
;
for
(
int
i
=
0
;
i
<
listReceiveAddressVO
.
size
();
++
i
)
{
ReceiveAddressItemVO
addressVO
=
listReceiveAddressVO
.
get
(
i
);
if
(
addressVO
.
getId
()
==
editAddressForm
.
getId
())
{
receiveAddressVO
=
addressVO
;
break
;
}
}
if
(
receiveAddressVO
==
null
)
{
return
EResponse
.
error
(
1001
,
"无效的地址ID"
);
}
receiveAddressVO
.
setAddressName
(
editAddressForm
.
getAddressName
());
receiveAddressVO
.
setProvinceCode
(
editAddressForm
.
getProvinceCode
());
receiveAddressVO
.
setCityCode
(
editAddressForm
.
getCityCode
());
receiveAddressVO
.
setDistrictCode
(
editAddressForm
.
getDistrictCode
());
receiveAddressVO
.
setDetailAddress
(
editAddressForm
.
getDetailAddress
());
receiveAddressVO
.
setReceiver
(
editAddressForm
.
getReceiver
());
receiveAddressVO
.
setReceiverPhone
(
editAddressForm
.
getReceiverPhone
());
return
EResponse
.
ok
();
}
/**
* description 删除收货地址
* param [EditAddressForm]
* return com.esv.freight.common.response.EResponse
* author 张志臣
* createTime 2020/04/13 11:00
**/
@PostMapping
(
"/delete"
)
public
EResponse
delete
(
@RequestHeader
(
"Union-Authorization"
)
String
accessToken
,
@RequestBody
(
required
=
false
)
@Validated
(
ValidatorInsert
.
class
)
DeleteAddressForm
deleteAddressForm
)
{
String
phone
=
addressAccountService
.
getPhoneByAccessToken
(
accessToken
);
if
(
phone
==
null
||
""
.
equals
(
phone
))
{
return
EResponse
.
error
(
1003
,
"未找到此用户"
);
}
// TODO,Feign调用货主发货地址列表接口,目前暂时返回假数据
ReceiveAddressItemVO
receiveAddressVO
=
null
;
int
index
=
0
;
for
(
index
=
0
;
index
<
listReceiveAddressVO
.
size
();
++
index
)
{
ReceiveAddressItemVO
addressVO
=
listReceiveAddressVO
.
get
(
index
);
if
(
addressVO
.
getId
()
==
deleteAddressForm
.
getId
())
{
receiveAddressVO
=
addressVO
;
break
;
}
}
if
(
receiveAddressVO
==
null
)
{
return
EResponse
.
error
(
1001
,
"无效的地址ID"
);
}
listReceiveAddressVO
.
remove
(
index
);
return
EResponse
.
ok
();
}
/**
* description 默认收货地址
* param [EditAddressForm]
* return com.esv.freight.common.response.EResponse
* author 张志臣
* createTime 2020/04/13 11:00
**/
@PostMapping
(
"/default"
)
public
EResponse
defaultAddress
(
@NotBlank
(
message
=
"ID不能为空"
)
@RequestParam
String
id
)
{
return
EResponse
.
ok
();
}
}
src/main/java/com/esv/freight/app/module/address/form/CreateDeliveryAddressForm.java
0 → 100644
View file @
b9743359
package
com
.
esv
.
freight
.
app
.
module
.
address
.
form
;
import
com.esv.freight.app.common.validator.groups.ValidatorInsert
;
import
com.esv.freight.app.common.validator.groups.ValidatorList
;
import
com.esv.freight.app.common.validator.groups.ValidatorUpdate
;
import
lombok.Data
;
import
org.apache.commons.lang3.builder.ToStringBuilder
;
import
org.apache.commons.lang3.builder.ToStringStyle
;
import
org.hibernate.validator.constraints.Length
;
import
javax.validation.constraints.NotNull
;
/**
* @description: 新增发货地址验证类
* @project: Freight
* @name: com.esv.freight.module.ownerBackend.address.form.CreateDeliveryAddressForm
* @author: 张志臣
* @email: zhangzhichen@esvtek.com
* @createTime: 2020/04/13 11:00
* @version:1.0
*/
@Data
public
class
CreateDeliveryAddressForm
{
/**
* 地址名称
*/
@NotNull
(
message
=
"参数addressName不能为空"
)
@Length
(
max
=
50
,
message
=
"地址名称长度不合法"
)
private
String
addressName
;
/**
* 省份代码
*/
@Length
(
max
=
6
,
message
=
"参数provinceCode长度不合法"
,
groups
=
{
ValidatorList
.
class
})
@Length
(
min
=
6
,
max
=
6
,
message
=
"参数provinceCode长度不合法"
,
groups
=
{
ValidatorInsert
.
class
,
ValidatorUpdate
.
class
})
@NotNull
(
message
=
"参数provinceCode不能为空"
)
private
String
provinceCode
;
/**
* 市代码
*/
@Length
(
max
=
6
,
message
=
"参数cityCode长度不合法"
,
groups
=
{
ValidatorList
.
class
})
@Length
(
min
=
6
,
max
=
6
,
message
=
"参数cityCode长度不合法"
,
groups
=
{
ValidatorInsert
.
class
,
ValidatorUpdate
.
class
})
@NotNull
(
message
=
"参数cityCode不能为空"
)
private
String
cityCode
;
/**
* 区县代码
*/
@Length
(
max
=
6
,
message
=
"参数districtCode长度不合法"
,
groups
=
{
ValidatorList
.
class
})
@Length
(
min
=
6
,
max
=
6
,
message
=
"参数districtCode长度不合法"
,
groups
=
{
ValidatorInsert
.
class
,
ValidatorUpdate
.
class
})
@NotNull
(
message
=
"参数districtCode不能为空"
)
private
String
districtCode
;
/**
* 详细地址
*/
@NotNull
(
message
=
"参数detailAddress不能为空"
)
@Length
(
max
=
50
,
message
=
"详细地址长度不合法"
)
private
String
detailAddress
;
/**
* 发货人
*/
@NotNull
(
message
=
"参数deliverer不能为空"
)
@Length
(
max
=
20
,
message
=
"发货人长度不合法"
)
private
String
deliverer
;
/**
* 发货人电话
*/
@NotNull
(
message
=
"参数receiverPhone不能为空"
)
@Length
(
max
=
30
,
message
=
"发货人电话长度不合法"
)
private
String
delivererPhone
;
@Override
public
String
toString
()
{
return
ToStringBuilder
.
reflectionToString
(
this
,
ToStringStyle
.
JSON_STYLE
);
}
}
src/main/java/com/esv/freight/app/module/address/form/CreateReceiveAddressForm.java
0 → 100644
View file @
b9743359
package
com
.
esv
.
freight
.
app
.
module
.
address
.
form
;
import
com.esv.freight.app.common.validator.groups.ValidatorInsert
;
import
com.esv.freight.app.common.validator.groups.ValidatorList
;
import
com.esv.freight.app.common.validator.groups.ValidatorUpdate
;
import
lombok.Data
;
import
org.apache.commons.lang3.builder.ToStringBuilder
;
import
org.apache.commons.lang3.builder.ToStringStyle
;
import
org.hibernate.validator.constraints.Length
;
import
javax.validation.constraints.NotNull
;
/**
* @description: 新增收货地址验证类
* @project: Freight
* @name: com.esv.freight.module.ownerBackend.address.form.CreateReceiveAddressForm
* @author: 张志臣
* @email: zhangzhichen@esvtek.com
* @createTime: 2020/04/17 10:00
* @version:1.0
*/
@Data
public
class
CreateReceiveAddressForm
{
/**
* 地址名称
*/
@NotNull
(
message
=
"参数addressName不能为空"
)
@Length
(
max
=
50
,
message
=
"地址名称长度不合法"
)
private
String
addressName
;
/**
* 省份代码
*/
@Length
(
max
=
6
,
message
=
"参数provinceCode长度不合法"
,
groups
=
{
ValidatorList
.
class
})
@Length
(
min
=
6
,
max
=
6
,
message
=
"参数provinceCode长度不合法"
,
groups
=
{
ValidatorInsert
.
class
,
ValidatorUpdate
.
class
})
@NotNull
(
message
=
"参数provinceCode不能为空"
)
private
String
provinceCode
;
/**
* 市代码
*/
@Length
(
max
=
6
,
message
=
"参数cityCode长度不合法"
,
groups
=
{
ValidatorList
.
class
})
@Length
(
min
=
6
,
max
=
6
,
message
=
"参数cityCode长度不合法"
,
groups
=
{
ValidatorInsert
.
class
,
ValidatorUpdate
.
class
})
@NotNull
(
message
=
"参数cityCode不能为空"
)
private
String
cityCode
;
/**
* 区县代码
*/
@Length
(
max
=
6
,
message
=
"参数districtCode长度不合法"
,
groups
=
{
ValidatorList
.
class
})
@Length
(
min
=
6
,
max
=
6
,
message
=
"参数districtCode长度不合法"
,
groups
=
{
ValidatorInsert
.
class
,
ValidatorUpdate
.
class
})
@NotNull
(
message
=
"参数districtCode不能为空"
)
private
String
districtCode
;
/**
* 详细地址
*/
@NotNull
(
message
=
"参数detailAddress不能为空"
)
@Length
(
max
=
50
,
message
=
"详细地址长度不合法"
)
private
String
detailAddress
;
/**
* 收货人
*/
@NotNull
(
message
=
"参数receiver不能为空"
)
@Length
(
max
=
20
,
message
=
"收货人长度不合法"
)
private
String
receiver
;
/**
* 收货人电话
*/
@NotNull
(
message
=
"参数receiverPhone不能为空"
)
@Length
(
max
=
30
,
message
=
"收货人电话长度不合法"
)
private
String
receiverPhone
;
@Override
public
String
toString
()
{
return
ToStringBuilder
.
reflectionToString
(
this
,
ToStringStyle
.
JSON_STYLE
);
}
}
src/main/java/com/esv/freight/app/module/address/form/DeleteAddressForm.java
0 → 100644
View file @
b9743359
package
com
.
esv
.
freight
.
app
.
module
.
address
.
form
;
import
lombok.Data
;
import
javax.validation.constraints.NotNull
;
/**
* @description: 删除地址验证类
* @project: Freight
* @name: com.esv.freight.module.ownerBackend.address.form.DeleteAddressForm
* @author: 张志臣
* @email: zhangzhichen@esvtek.com
* @createTime: 2020/04/17 15:00
* @version:1.0
*/
@Data
public
class
DeleteAddressForm
{
/**
* 收货地址ID
*/
@NotNull
(
message
=
"参数id不能为空"
)
private
Integer
id
;
}
src/main/java/com/esv/freight/app/module/address/form/EditDeliveryAddressForm.java
0 → 100644
View file @
b9743359
package
com
.
esv
.
freight
.
app
.
module
.
address
.
form
;
import
com.esv.freight.app.common.validator.groups.ValidatorInsert
;
import
com.esv.freight.app.common.validator.groups.ValidatorList
;
import
com.esv.freight.app.common.validator.groups.ValidatorUpdate
;
import
lombok.Data
;
import
org.apache.commons.lang3.builder.ToStringBuilder
;
import
org.apache.commons.lang3.builder.ToStringStyle
;
import
org.hibernate.validator.constraints.Length
;
import
javax.validation.constraints.NotNull
;
/**
* @description: 编辑发货地址验证类
* @project: Freight
* @name: com.esv.freight.module.ownerBackend.address.form.EditDeliveryAddressForm
* @author: 张志臣
* @email: zhangzhichen@esvtek.com
* @createTime: 2020/04/13 11:00
* @version:1.0
*/
@Data
public
class
EditDeliveryAddressForm
{
/**
* 收货地址ID
*/
@NotNull
(
message
=
"参数id不能为空"
)
private
Integer
id
;
/**
* 地址名称
*/
@NotNull
(
message
=
"参数addressName不能为空"
)
@Length
(
max
=
50
,
message
=
"地址名称长度不合法"
)
private
String
addressName
;
/**
* 省份代码
*/
@Length
(
max
=
6
,
message
=
"参数provinceCode长度不合法"
,
groups
=
{
ValidatorList
.
class
})
@Length
(
min
=
6
,
max
=
6
,
message
=
"参数provinceCode长度不合法"
,
groups
=
{
ValidatorInsert
.
class
,
ValidatorUpdate
.
class
})
@NotNull
(
message
=
"参数provinceCode不能为空"
)
private
String
provinceCode
;
/**
* 市代码
*/
@Length
(
max
=
6
,
message
=
"参数cityCode长度不合法"
,
groups
=
{
ValidatorList
.
class
})
@Length
(
min
=
6
,
max
=
6
,
message
=
"参数cityCode长度不合法"
,
groups
=
{
ValidatorInsert
.
class
,
ValidatorUpdate
.
class
})
@NotNull
(
message
=
"参数cityCode不能为空"
)
private
String
cityCode
;
/**
* 区县代码
*/
@Length
(
max
=
6
,
message
=
"参数districtCode长度不合法"
,
groups
=
{
ValidatorList
.
class
})
@Length
(
min
=
6
,
max
=
6
,
message
=
"参数districtCode长度不合法"
,
groups
=
{
ValidatorInsert
.
class
,
ValidatorUpdate
.
class
})
@NotNull
(
message
=
"参数districtCode不能为空"
)
private
String
districtCode
;
/**
* 详细地址
*/
@NotNull
(
message
=
"参数detailAddress不能为空"
)
@Length
(
max
=
50
,
message
=
"详细地址长度不合法"
)
private
String
detailAddress
;
/**
* 发货人
*/
@NotNull
(
message
=
"参数deliverer不能为空"
)
@Length
(
max
=
20
,
message
=
"发货人长度不合法"
)
private
String
deliverer
;
/**
* 发货人电话
*/
@NotNull
(
message
=
"参数receiverPhone不能为空"
)
@Length
(
max
=
30
,
message
=
"发货人电话长度不合法"
)
private
String
delivererPhone
;
@Override
public
String
toString
()
{
return
ToStringBuilder
.
reflectionToString
(
this
,
ToStringStyle
.
JSON_STYLE
);
}
}
src/main/java/com/esv/freight/app/module/address/form/EditReceiveAddressForm.java
0 → 100644
View file @
b9743359
package
com
.
esv
.
freight
.
app
.
module
.
address
.
form
;
import
com.esv.freight.app.common.validator.groups.ValidatorInsert
;
import
com.esv.freight.app.common.validator.groups.ValidatorList
;
import
com.esv.freight.app.common.validator.groups.ValidatorUpdate
;
import
lombok.Data
;
import
org.apache.commons.lang3.builder.ToStringBuilder
;
import
org.apache.commons.lang3.builder.ToStringStyle
;
import
org.hibernate.validator.constraints.Length
;
import
javax.validation.constraints.NotNull
;
/**
* @description: 编辑收货地址验证类
* @project: Freight
* @name: com.esv.freight.module.ownerBackend.address.form.EditReceiveAddressForm
* @author: 张志臣
* @email: zhangzhichen@esvtek.com
* @createTime: 2020/04/13 11:00
* @version:1.0
*/
@Data
public
class
EditReceiveAddressForm
{
/**
* 收货地址ID
*/
@NotNull
(
message
=
"参数id不能为空"
)
private
Integer
id
;
/**
* 地址名称
*/
@NotNull
(
message
=
"参数addressName不能为空"
)
@Length
(
max
=
50
,
message
=
"地址名称长度不合法"
)
private
String
addressName
;
/**
* 省份代码
*/
@Length
(
max
=
6
,
message
=
"参数provinceCode长度不合法"
,
groups
=
{
ValidatorList
.
class
})
@Length
(
min
=
6
,
max
=
6
,
message
=
"参数provinceCode长度不合法"
,
groups
=
{
ValidatorInsert
.
class
,
ValidatorUpdate
.
class
})
@NotNull
(
message
=
"参数provinceCode不能为空"
)
private
String
provinceCode
;
/**
* 市代码
*/
@Length
(
max
=
6
,
message
=
"参数cityCode长度不合法"
,
groups
=
{
ValidatorList
.
class
})
@Length
(
min
=
6
,
max
=
6
,
message
=
"参数cityCode长度不合法"
,
groups
=
{
ValidatorInsert
.
class
,
ValidatorUpdate
.
class
})
@NotNull
(
message
=
"参数cityCode不能为空"
)
private
String
cityCode
;
/**
* 区县代码
*/
@Length
(
max
=
6
,
message
=
"参数districtCode长度不合法"
,
groups
=
{
ValidatorList
.
class
})
@Length
(
min
=
6
,
max
=
6
,
message
=
"参数districtCode长度不合法"
,
groups
=
{
ValidatorInsert
.
class
,
ValidatorUpdate
.
class
})
@NotNull
(
message
=
"参数districtCode不能为空"
)
private
String
districtCode
;
/**
* 详细地址
*/
@NotNull
(
message
=
"参数detailAddress不能为空"
)
@Length
(
max
=
50
,
message
=
"详细地址长度不合法"
)
private
String
detailAddress
;
/**
* 收货人
*/
@NotNull
(
message
=
"参数receiver不能为空"
)
@Length
(
max
=
20
,
message
=
"收货人长度不合法"
)
private
String
receiver
;
/**
* 收货人电话
*/
@NotNull
(
message
=
"参数receiverPhone不能为空"
)
@Length
(
max
=
30
,
message
=
"收货人电话长度不合法"
)
private
String
receiverPhone
;
@Override
public
String
toString
()
{
return
ToStringBuilder
.
reflectionToString
(
this
,
ToStringStyle
.
JSON_STYLE
);
}
}
src/main/java/com/esv/freight/app/module/address/service/AddressAccountService.java
0 → 100644
View file @
b9743359
package
com
.
esv
.
freight
.
app
.
module
.
address
.
service
;
import
com.baomidou.mybatisplus.extension.service.IService
;
import
com.esv.freight.app.module.account.entity.AppLoginEntity
;
import
com.esv.freight.app.module.address.vo.DeliveryAddressListVO
;
/**
* APP用户登录信息表
*
* @author 张志臣
* @email zhangzhichen@esvtek.com
* @date 2020-04-15 10:00
*/
public
interface
AddressAccountService
extends
IService
<
AppLoginEntity
>
{
String
getPhoneByAccessToken
(
String
accessToken
);
}
src/main/java/com/esv/freight/app/module/address/service/impl/AddressAccountServiceImpl.java
0 → 100644
View file @
b9743359
package
com
.
esv
.
freight
.
app
.
module
.
address
.
service
.
impl
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
import
com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
;
import
com.esv.freight.app.common.exception.EException
;
import
com.esv.freight.app.module.account.dao.AppLoginDao
;
import
com.esv.freight.app.module.account.entity.AppLoginEntity
;
import
com.esv.freight.app.module.account.service.AppLoginService
;
import
com.esv.freight.app.module.address.service.AddressAccountService
;
import
com.esv.freight.app.module.address.vo.DeliveryAddressListVO
;
import
org.springframework.stereotype.Service
;
@Service
(
"addressAccountService"
)
public
class
AddressAccountServiceImpl
extends
ServiceImpl
<
AppLoginDao
,
AppLoginEntity
>
implements
AddressAccountService
{
@Override
public
String
getPhoneByAccessToken
(
String
accessToken
)
{
AppLoginEntity
entity
=
this
.
getAccountByAccessToken
(
accessToken
);
if
(
entity
==
null
)
{
throw
new
EException
(
1
,
"未找到accessToken"
);
}
return
entity
.
getPhone
();
}
private
AppLoginEntity
getAccountByAccessToken
(
String
accessToken
)
{
QueryWrapper
<
AppLoginEntity
>
queryWrapper
=
new
QueryWrapper
<>();
queryWrapper
.
eq
(
"access_token"
,
accessToken
);
return
this
.
baseMapper
.
selectOne
(
queryWrapper
);
}
}
src/main/java/com/esv/freight/app/module/address/vo/DeliveryAddressItemVO.java
0 → 100644
View file @
b9743359
package
com
.
esv
.
freight
.
app
.
module
.
address
.
vo
;
import
lombok.Data
;
/**
* @description: 发货地址VO
* @project: Freight
* @name: com.esv.freight.module.ownerBackend.account.address.vo.DeliveryAddressVO
* @author: 张志臣
* @email: zhangzhichen@esvtek.com
* @createTime: 2020/04/17 10:00
* @version:1.0
*/
@Data
public
class
DeliveryAddressItemVO
{
/**
* 发货地址ID
*/
private
Integer
id
;
/**
* 地址名称
*/
private
String
addressName
;
/**
* 省份代码
*/
private
String
provinceCode
;
/**
* 市代码
*/
private
String
cityCode
;
/**
* 区县代码
*/
private
String
districtCode
;
/**
* 详细地址
*/
private
String
detailAddress
;
/**
* 发货人
*/
private
String
deliverer
;
/**
* 发货人电话
*/
private
String
delivererPhone
;
}
src/main/java/com/esv/freight/app/module/address/vo/DeliveryAddressListVO.java
0 → 100644
View file @
b9743359
package
com
.
esv
.
freight
.
app
.
module
.
address
.
vo
;
import
lombok.Data
;
import
org.apache.commons.lang3.builder.ToStringBuilder
;
import
org.apache.commons.lang3.builder.ToStringStyle
;
import
java.util.List
;
/**
* @description: 发货地址VO
* @project: Freight
* @name: com.esv.freight.module.ownerBackend.account.address.vo.DeliveryAddressListVO
* @author: 张志臣
* @email: zhangzhichen@esvtek.com
* @createTime: 2020/04/17 10:00
* @version:1.0
*/
@Data
public
class
DeliveryAddressListVO
{
/**
* 数据
**/
private
List
<
DeliveryAddressItemVO
>
records
;
@Override
public
String
toString
()
{
return
ToStringBuilder
.
reflectionToString
(
this
,
ToStringStyle
.
JSON_STYLE
);
}
}
src/main/java/com/esv/freight/app/module/address/vo/ReceiveAddressItemVO.java
0 → 100644
View file @
b9743359
package
com
.
esv
.
freight
.
app
.
module
.
address
.
vo
;
import
lombok.Data
;
/**
* @description: 收货地址VO
* @project: Freight
* @name: com.esv.freight.module.ownerBackend.account.address.vo.ReceiveAddressVO
* @author: 张志臣
* @email: zhangzhichen@esvtek.com
* @createTime: 2020/04/17 10:00
* @version:1.0
*/
@Data
public
class
ReceiveAddressItemVO
{
/**
* 收货地址ID
*/
private
Integer
id
;
/**
* 地址名称
*/
private
String
addressName
;
/**
* 省份代码
*/
private
String
provinceCode
;
/**
* 市代码
*/
private
String
cityCode
;
/**
* 区县代码
*/
private
String
districtCode
;
/**
* 详细地址
*/
private
String
detailAddress
;
/**
* 收货人
*/
private
String
receiver
;
/**
* 收货人电话
*/
private
String
receiverPhone
;
}
src/main/java/com/esv/freight/app/module/address/vo/ReceiveAddressListVO.java
0 → 100644
View file @
b9743359
package
com
.
esv
.
freight
.
app
.
module
.
address
.
vo
;
import
lombok.Data
;
import
org.apache.commons.lang3.builder.ToStringBuilder
;
import
org.apache.commons.lang3.builder.ToStringStyle
;
import
java.util.List
;
/**
* @description: 收货地址VO
* @project: Freight
* @name: com.esv.freight.module.ownerBackend.account.address.vo.ReceiveAddressListVO
* @author: 张志臣
* @email: zhangzhichen@esvtek.com
* @createTime: 2020/04/17 10:00
* @version:1.0
*/
@Data
public
class
ReceiveAddressListVO
{
/**
* 数据
**/
private
List
<
ReceiveAddressItemVO
>
records
;
@Override
public
String
toString
()
{
return
ToStringBuilder
.
reflectionToString
(
this
,
ToStringStyle
.
JSON_STYLE
);
}
}
src/main/java/com/esv/freight/app/module/order/controller/OrderController.java
0 → 100644
View file @
b9743359
package
com
.
esv
.
freight
.
app
.
module
.
order
.
controller
;
import
com.esv.freight.app.common.response.ECode
;
import
com.esv.freight.app.common.response.EResponse
;
import
com.esv.freight.app.common.validator.groups.ValidatorInsert
;
import
com.esv.freight.app.feign.DictInterface
;
import
com.esv.freight.app.feign.NoticeInterface
;
import
com.esv.freight.app.module.account.service.AppLoginService
;
import
com.esv.freight.app.module.order.form.OrderListForm
;
import
com.esv.freight.app.module.order.vo.OrderStatisticsVO
;
import
com.esv.freight.app.module.order.form.AddOrderForm
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.validation.annotation.Validated
;
import
org.springframework.web.bind.annotation.*
;
/**
* @description: 订单Controller
* @project: Freight
* @name: com.esv.freight.module.ownerBackend.order.controller.OrderController
* @author: 张志臣
* @email: zhangzhichen@esvtek.com
* @createTime: 2020/04/13 13:00
* @version:1.0
*/
@RestController
@RequestMapping
(
"/ownerBackend/order"
)
@Slf4j
@Validated
public
class
OrderController
{
private
AppLoginService
appLoginService
;
@Autowired
public
OrderController
(
AppLoginService
appLoginService
)
{
this
.
appLoginService
=
appLoginService
;
}
/**
* description 获取订单分类统计信息
* param
* return com.esv.freight.common.response.EResponse
* author 张志臣
* createTime 2020/04/11 11:00
**/
@PostMapping
(
"/statistics/getCountByType"
)
public
EResponse
getCountByType
(
@RequestHeader
(
"Union-Authorization"
)
String
accessToken
)
{
if
(
appLoginService
.
isInvalidAccessToken
(
accessToken
))
{
return
EResponse
.
error
(
ECode
.
TOKEN_EXPIRED
);
}
OrderStatisticsVO
orderStatisticsVO
=
new
OrderStatisticsVO
();
orderStatisticsVO
.
setCancelled
(
6
);
orderStatisticsVO
.
setComplete
(
5
);
orderStatisticsVO
.
setExecuting
(
3
);
orderStatisticsVO
.
setPending
(
6
);
orderStatisticsVO
.
setPublished
(
10
);
return
EResponse
.
ok
(
orderStatisticsVO
);
}
/**
* description 获取订单列表
* param [accessToken, addOrderForm]
* return com.esv.freight.common.response.EResponse
* author 张志臣
* createTime 2020/04/18 11:00
**/
@PostMapping
(
"/list"
)
public
EResponse
list
(
@RequestHeader
(
"Union-Authorization"
)
String
accessToken
,
@RequestBody
(
required
=
false
)
@Validated
(
ValidatorInsert
.
class
)
OrderListForm
orderListForm
)
{
if
(
appLoginService
.
isInvalidAccessToken
(
accessToken
))
{
return
EResponse
.
error
(
ECode
.
TOKEN_EXPIRED
);
}
return
EResponse
.
ok
();
}
/**
* description 发布订单
* param [AddOrderForm]
* return com.esv.freight.common.response.EResponse
* author 张志臣
* createTime 2020/04/13 14:00
**/
@PostMapping
(
"/platform/add"
)
public
EResponse
add
(
@RequestHeader
(
"Union-Authorization"
)
String
accessToken
,
@RequestBody
(
required
=
false
)
@Validated
(
ValidatorInsert
.
class
)
AddOrderForm
addOrderForm
)
{
if
(
appLoginService
.
isInvalidAccessToken
(
accessToken
))
{
return
EResponse
.
error
(
ECode
.
TOKEN_EXPIRED
);
}
return
EResponse
.
ok
();
}
}
src/main/java/com/esv/freight/app/module/order/form/AddOrderForm.java
0 → 100644
View file @
b9743359
package
com
.
esv
.
freight
.
app
.
module
.
order
.
form
;
import
com.esv.freight.app.common.validator.groups.ValidatorDelete
;
import
com.esv.freight.app.common.validator.groups.ValidatorInsert
;
import
com.esv.freight.app.common.validator.groups.ValidatorUpdate
;
import
lombok.Data
;
import
org.apache.commons.lang3.builder.ToStringBuilder
;
import
org.apache.commons.lang3.builder.ToStringStyle
;
import
org.hibernate.validator.constraints.Length
;
import
javax.validation.constraints.NotBlank
;
/**
* @description: 发布订单验证类
* @project: Freight
* @name: com.esv.freight.module.ownerBackend.order.form.AddOrderForm
* @author: 张志臣
* @email: zhangzhichen@esvtek.com
* @createTime: 2020/04/13 13:00
* @version:1.0
*/
@Data
public
class
AddOrderForm
{
/**
* 发货地址ID
*/
@NotBlank
(
message
=
"参数deliveryAddressId不能为空"
,
groups
=
{
ValidatorInsert
.
class
,
ValidatorUpdate
.
class
,
ValidatorDelete
.
class
})
private
Integer
deliveryAddressId
;
/**
* 收货地址ID
*/
@NotBlank
(
message
=
"参数receiveAddressId不能为空"
,
groups
=
{
ValidatorInsert
.
class
,
ValidatorUpdate
.
class
,
ValidatorDelete
.
class
})
private
Integer
receiveAddressId
;
/**
* 货物类型
*/
@NotBlank
(
message
=
"参数goodsType不能为空"
,
groups
=
{
ValidatorInsert
.
class
,
ValidatorUpdate
.
class
,
ValidatorDelete
.
class
})
private
Integer
goodsType
;
/**
* 货物名称编码
*/
@NotBlank
(
message
=
"参数goodsNameCode不能为空"
,
groups
=
{
ValidatorInsert
.
class
,
ValidatorUpdate
.
class
,
ValidatorDelete
.
class
})
private
Integer
goodsNameCode
;
/**
* 货物名称内容
*/
@NotBlank
(
message
=
"参数goodsName不能为空"
,
groups
=
{
ValidatorInsert
.
class
,
ValidatorUpdate
.
class
,
ValidatorDelete
.
class
})
private
String
goodsName
;
/**
* 货物明细
*/
@NotBlank
(
message
=
"参数goodsDetail不能为空"
,
groups
=
{
ValidatorInsert
.
class
,
ValidatorUpdate
.
class
,
ValidatorDelete
.
class
})
@Length
(
max
=
200
,
message
=
"货物明细长度不合法"
)
private
String
goodsDetail
;
/**
* 货物单位
*/
@NotBlank
(
message
=
"参数goodsUnit不能为空"
,
groups
=
{
ValidatorInsert
.
class
,
ValidatorUpdate
.
class
,
ValidatorDelete
.
class
})
private
Integer
goodsUnit
;
/**
* 货物单价
*/
@NotBlank
(
message
=
"参数goodsUnitPrice不能为空"
,
groups
=
{
ValidatorInsert
.
class
,
ValidatorUpdate
.
class
,
ValidatorDelete
.
class
})
private
Number
goodsUnitPrice
;
/**
* 要求发货时间
*/
@NotBlank
(
message
=
"参数requiredDeliveryTime不能为空"
,
groups
=
{
ValidatorInsert
.
class
,
ValidatorUpdate
.
class
,
ValidatorDelete
.
class
})
private
String
requiredDeliveryTime
;
/**
* 要求交货时间
*/
@NotBlank
(
message
=
"参数requiredReceiveTime不能为空"
,
groups
=
{
ValidatorInsert
.
class
,
ValidatorUpdate
.
class
,
ValidatorDelete
.
class
})
private
String
requiredReceiveTime
;
/**
* 车辆类型,主类型
*/
private
String
vehicleTypeMain
;
/**
* 车辆类型,子类型
*/
private
String
vehicleTypeSub
;
/**
* 车长
*/
private
String
vehicleLength
;
/**
* 备注
*/
@Length
(
max
=
200
,
message
=
"备注长度不合法"
)
private
String
remark
;
@Override
public
String
toString
()
{
return
ToStringBuilder
.
reflectionToString
(
this
,
ToStringStyle
.
JSON_STYLE
);
}
}
src/main/java/com/esv/freight/app/module/order/form/OrderListForm.java
0 → 100644
View file @
b9743359
package
com
.
esv
.
freight
.
app
.
module
.
order
.
form
;
import
com.esv.freight.app.common.validator.groups.ValidatorDelete
;
import
com.esv.freight.app.common.validator.groups.ValidatorInsert
;
import
com.esv.freight.app.common.validator.groups.ValidatorUpdate
;
import
lombok.Data
;
import
org.apache.commons.lang3.builder.ToStringStyle
;
import
org.apache.commons.lang3.builder.ToStringBuilder
;
import
org.apache.commons.lang3.builder.ToStringStyle
;
import
javax.validation.constraints.NotBlank
;
/**
* @description: 订单列表验证类
* @project: Freight
* @name: com.esv.freight.module.ownerBackend.order.form.OrderListForm
* @author: 张志臣
* @email: zhangzhichen@esvtek.com
* @createTime: 2020/04/18 11:00
* @version:1.0
*/
@Data
public
class
OrderListForm
{
/**
* 订单类型:1-待审核、2-新增、3-执行中
*/
@NotBlank
(
message
=
"参数type不能为空"
,
groups
=
{
ValidatorInsert
.
class
,
ValidatorUpdate
.
class
,
ValidatorDelete
.
class
})
private
Integer
type
;
/**
* 当前页数
*/
@NotBlank
(
message
=
"参数pageNum不能为空"
,
groups
=
{
ValidatorInsert
.
class
,
ValidatorUpdate
.
class
,
ValidatorDelete
.
class
})
private
Integer
pageNum
;
/**
* 每页显示记录数
*/
@NotBlank
(
message
=
"参数pageSize不能为空"
,
groups
=
{
ValidatorInsert
.
class
,
ValidatorUpdate
.
class
,
ValidatorDelete
.
class
})
private
Integer
pageSize
;
@Override
public
String
toString
()
{
return
ToStringBuilder
.
reflectionToString
(
this
,
ToStringStyle
.
JSON_STYLE
);
}
}
src/main/java/com/esv/freight/app/module/order/vo/OrderListItemVO.java
0 → 100644
View file @
b9743359
package
com
.
esv
.
freight
.
app
.
module
.
order
.
vo
;
import
lombok.Data
;
/**
* @description: 订单列表VO
* @project: Freight
* @name: com.esv.freight.app.module.order.vo.OrderListItemVO
* @author: 张志臣
* @email: zhangzhichen@esvtek.com
* @createTime: 2020/04/18 11:00
* @version:1.0
*/
@Data
public
class
OrderListItemVO
{
/**
* 订单ID
*/
private
Integer
id
;
/**
* 订单号
*/
private
String
orderNO
;
/**
* 发货地址省份
*/
private
String
deliveryProviceCode
;
/**
* 发货地址城市
*/
private
String
deliveryCityCode
;
/**
* 收货地址省份
*/
private
String
receiveProviceCode
;
/**
* 收货地址城市
*/
private
String
receiveCityCode
;
/**
* 货物类型,字典表
*/
private
Integer
goodType
;
/**
* 货物订单量
*/
private
String
goodsTotalAmount
;
/**
* 货物单位,字典表
*/
private
Integer
goodsUnit
;
/**
* 发布时间
*/
private
Integer
publishTime
;
/**
* 发货时间
*/
private
Integer
deliveryTime
;
/**
* 订单来源,字典表
*/
private
String
orderSource
;
}
src/main/java/com/esv/freight/app/module/order/vo/OrderListVO.java
0 → 100644
View file @
b9743359
package
com
.
esv
.
freight
.
app
.
module
.
order
.
vo
;
import
lombok.Data
;
import
org.apache.commons.lang3.builder.ToStringBuilder
;
import
org.apache.commons.lang3.builder.ToStringStyle
;
import
java.util.List
;
/**
* @description: 订单列表VO
* @project: Freight
* @name: com.esv.freight.module.ownerBackend.order.vo.OrderListVO
* @author: 张志臣
* @email: zhangzhichen@esvtek.com
* @createTime: 2020/04/18 11:00
* @version:1.0
*/
@Data
public
class
OrderListVO
{
/**
* 当前页数
*/
private
Integer
pageNum
;
/**
* 每页显示记录数
*/
private
Integer
pageSize
;
/**
* 总记录数
*/
private
Integer
totalSize
;
/**
* 当前页的记录数
*/
private
Integer
recordSize
;
/**
* 记录列表
**/
private
List
<
OrderListItemVO
>
records
;
@Override
public
String
toString
()
{
return
ToStringBuilder
.
reflectionToString
(
this
,
ToStringStyle
.
JSON_STYLE
);
}
}
src/main/java/com/esv/freight/app/module/order/vo/OrderStatisticsVO.java
0 → 100644
View file @
b9743359
package
com
.
esv
.
freight
.
app
.
module
.
order
.
vo
;
import
lombok.Data
;
import
org.apache.commons.lang3.builder.ToStringBuilder
;
import
org.apache.commons.lang3.builder.ToStringStyle
;
/**
* @description: 获取订单分类统计信息VO
* @project: Freight
* @name: com.esv.freight.module.ownerBackend.order.vo.OrderStatisticsVO
* @author: 张志臣
* @email: zhangzhichen@esvtek.com
* @createTime: 2020/04/13 13:00
* @version:1.0
*/
@Data
public
class
OrderStatisticsVO
{
/**
* 已发布订单数量
*/
private
Integer
published
;
/**
* 执行中订单数量
*/
private
Integer
executing
;
/**
* 待审核订单数量
*/
private
Integer
pending
;
/**
* 已完结订单数量
*/
private
Integer
complete
;
/**
* 已取消订单数量
*/
private
Integer
cancelled
;
@Override
public
String
toString
()
{
return
ToStringBuilder
.
reflectionToString
(
this
,
ToStringStyle
.
JSON_STYLE
);
}
}
src/main/resources/application-dev.yml
0 → 100644
View file @
b9743359
spring
:
datasource
:
type
:
com.alibaba.druid.pool.DruidDataSource
druid
:
driver-class-name
:
com.mysql.cj.jdbc.Driver
url
:
jdbc:mysql://192.168.31.248:3306/freight?useUnicode=true&characterEncoding=utf8&autoReconnect=true&useSSL=false
username
:
freight
password
:
freight
initial-size
:
5
min-idle
:
5
max-active
:
20
max-wait
:
60000
time-between-eviction-runs-millis
:
60000
min-evictable-idle-time-millis
:
300000
validation-query
:
SELECT 1 FROM DUAL
test-while-idle
:
true
test-on-borrow
:
false
test-on-return
:
false
filter
:
stat
:
log-slow-sql
:
true
slow-sql-millis
:
1000
merge-sql
:
false
redis
:
database
:
0
host
:
192.168.31.248
port
:
6379
password
:
timeout
:
1000
jedis
:
pool
:
max-active
:
8
max-wait
:
-1
max-idle
:
8
min-idle
:
0
#mybatis
mybatis-plus
:
mapper-locations
:
classpath*:/mapper/**/*Dao.xml
#实体扫描,多个package用逗号或者分号分隔
typeAliasesPackage
:
com.esv.freight.*.*.entity,com.esv.freight.*.*.dto
check-config-location
:
true
#原生配置
configuration
:
map-underscore-to-camel-case
:
true
cache-enabled
:
false
call-setters-on-nulls
:
true
jdbc-type-for-null
:
'
null'
global-config
:
banner
:
true
#数据库相关配置
db-config
:
#主键类型 AUTO:"数据库ID自增", INPUT:"用户输入ID", ID_WORKER:"全局唯一ID (数字类型唯一ID)", UUID:"全局唯一ID UUID";
id-type
:
AUTO
logic-delete-value
:
1
logic-not-delete-value
:
0
\ No newline at end of file
src/main/resources/bootstrap.yml
0 → 100644
View file @
b9743359
server
:
port
:
1004
nacos
:
url
:
192.168.31.248:8848
namespace
:
aad5aa26-5351-4e7a-a65e-ecb332f3c52c
group
:
FREIGHT_GROUP
spring
:
application
:
name
:
freight-app-service
profiles
:
active
:
dev
cloud
:
nacos
:
discovery
:
server-addr
:
${nacos.url}
namespace
:
${nacos.namespace}
group
:
${nacos.group}
config
:
server-addr
:
${nacos.url}
namespace
:
${nacos.namespace}
file-extension
:
yml
group
:
${nacos.group}
\ No newline at end of file
src/main/resources/logback-spring.xml
0 → 100644
View file @
b9743359
<?xml version="1.0" encoding="UTF-8"?>
<configuration
scan=
"true"
scanPeriod=
"60 seconds"
>
<include
resource=
"org/springframework/boot/logging/logback/base.xml"
/>
<springProperty
scope=
"context"
name=
"LOG_FILE_NAME"
source=
"spring.application.name"
/>
<!-- 日志存储目录 -->
<property
name=
"LOG_FILE_PATH"
value=
"./logs/"
/>
<!-- 日志文件大小 -->
<property
name=
"MAX_FILE_SIZE"
value=
"100MB"
/>
<!-- 日志最大的历史(单位:天) -->
<property
name=
"MAX_HISTORY"
value=
"90"
/>
<!-- 格式化输出:%d表示日期,%thread表示线程名,%-5level:级别从左显示5个字符宽度,%msg:日志消息,%n:换行符-->
<property
name=
"LOG_PATTERN"
value=
"%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread-%X{traceId}] %-5level %logger{50}.%M[%line]:%msg%n"
/>
<!-- 控制台输出 -->
<appender
name=
"CONSOLE_APPENDER"
class=
"ch.qos.logback.core.ConsoleAppender"
>
<filter
class=
"ch.qos.logback.classic.filter.ThresholdFilter"
>
<level>
debug
</level>
</filter>
<encoder>
<Pattern>
${LOG_PATTERN}
</Pattern>
<charset>
UTF-8
</charset>
</encoder>
</appender>
<!-- 滚动记录文件,先将日志记录到指定文件,当符合某个条件时,将日志记录到其他文件 -->
<appender
name=
"FILE_APPENDER"
class=
"ch.qos.logback.core.rolling.RollingFileAppender"
>
<file>
${LOG_FILE_PATH}${LOG_FILE_NAME}.log
</file>
<rollingPolicy
class=
"ch.qos.logback.core.rolling.TimeBasedRollingPolicy"
>
<fileNamePattern>
${LOG_FILE_PATH}${LOG_FILE_NAME}-%d{yyyy-MM-dd}-%i.log
</fileNamePattern>
<maxHistory>
${MAX_HISTORY}
</maxHistory>
<timeBasedFileNamingAndTriggeringPolicy
class=
"ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP"
>
<maxFileSize>
${MAX_FILE_SIZE}
</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
</rollingPolicy>
<encoder
class=
"ch.qos.logback.classic.encoder.PatternLayoutEncoder"
>
<pattern>
${LOG_PATTERN}
</pattern>
<charset>
UTF-8
</charset>
</encoder>
</appender>
<!-- mybatis sql日志 日志的级别需要是DEBUG -->
<!-- 日志打印的包的范围,及分类日志文件存储 -->
<logger
name=
"com.esv"
level=
"DEBUG"
additivity=
"false"
>
<appender-ref
ref=
"CONSOLE_APPENDER"
/>
<appender-ref
ref=
"FILE_APPENDER"
/>
</logger>
<!--控制台和日志文件输出级别-->
<root
level=
"INFO"
additivity=
"false"
>
<appender-ref
ref=
"CONSOLE_APPENDER"
/>
<appender-ref
ref=
"FILE_APPENDER"
/>
</root>
</configuration>
\ No newline at end of file
src/main/resources/mapper/account/AppLoginDao.xml
0 → 100644
View file @
b9743359
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper
namespace=
"com.esv.freight.app.module.account.dao.AppLoginDao"
>
<!-- 可根据自己的需求,是否要使用 -->
<resultMap
type=
"com.esv.freight.app.module.account.entity.AppLoginEntity"
id=
"appLoginMap"
>
<result
property=
"id"
column=
"id"
/>
<result
property=
"phone"
column=
"phone"
/>
<result
property=
"accessToken"
column=
"access_token"
/>
<result
property=
"refreshToken"
column=
"refresh_token"
/>
<result
property=
"sn"
column=
"sn"
/>
<result
property=
"loginStatus"
column=
"login_status"
/>
<result
property=
"loginTime"
column=
"login_time"
/>
<result
property=
"logoutTime"
column=
"logout_time"
/>
<result
property=
"refreshTime"
column=
"refresh_time"
/>
<result
property=
"accessTokenValidTime"
column=
"access_token_valid_time"
/>
<result
property=
"refreshTokenValidTime"
column=
"refresh_token_valid_time"
/>
</resultMap>
</mapper>
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment