Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
polysoft-nafmii
/
polysoft-parent
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 69a0a101
authored
Apr 27, 2021
by
ypenglv
Browse Files
Options
Browse Files
Tag
Download
Plain Diff
冲入解决
2 parents
31b96803
1d435427
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
165 additions
and
21 deletions
nafmii-app/src/main/java/org/nafmii/app/user/service/impl/UserServiceImpl.java
nafmii-app/src/main/java/org/nafmii/app/user/vo/UserVO.java
nafmii-app/src/main/resources/application.yml
nafmii-common/src/main/java/org/nafmii/common/utils/JwtUtils.java
nafmii-common/src/main/java/org/nafmii/common/vo/AppUser.java
nafmii-common/src/main/java/org/nafmii/common/vo/UserJwtVO.java
nafmii-common/src/main/java/org/nafmii/enums/RedisEnum.java
nafmii-app/src/main/java/org/nafmii/app/user/service/impl/UserServiceImpl.java
View file @
69a0a10
...
@@ -15,12 +15,17 @@ import org.nafmii.common.utils.GuavaUtil;
...
@@ -15,12 +15,17 @@ import org.nafmii.common.utils.GuavaUtil;
import
org.nafmii.common.utils.JwtUtils
;
import
org.nafmii.common.utils.JwtUtils
;
import
org.nafmii.common.utils.SnowFlakeUtil
;
import
org.nafmii.common.utils.SnowFlakeUtil
;
import
org.nafmii.common.constant.UserEnum
;
import
org.nafmii.common.constant.UserEnum
;
import
org.nafmii.common.vo.UserJwtVO
;
import
org.nafmii.enums.RedisEnum
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.data.redis.core.StringRedisTemplate
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
javax.annotation.Resource
;
import
javax.annotation.Resource
;
import
java.time.LocalDateTime
;
import
java.time.LocalDateTime
;
import
java.time.format.DateTimeFormatter
;
import
java.time.format.DateTimeFormatter
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.List
;
import
java.util.concurrent.TimeUnit
;
/**
/**
* @author:zhoujh
* @author:zhoujh
...
@@ -36,6 +41,12 @@ public class UserServiceImpl implements UserService {
...
@@ -36,6 +41,12 @@ public class UserServiceImpl implements UserService {
@Resource
@Resource
private
AppUserMapper
appUserMapper
;
private
AppUserMapper
appUserMapper
;
//redis缓存快递集合-key
public
static
final
String
USER_CODE_KEY
=
"user:code"
;
@Autowired
StringRedisTemplate
stringRedisTemplate
;
/**
/**
* 模拟用户登陆
* 模拟用户登陆
* @return
* @return
...
@@ -99,8 +110,9 @@ public class UserServiceImpl implements UserService {
...
@@ -99,8 +110,9 @@ public class UserServiceImpl implements UserService {
log
.
info
(
"用户注册参数==============>"
+
registerDto
);
log
.
info
(
"用户注册参数==============>"
+
registerDto
);
//将验证码放入到缓存当中(过期时间60s)test
//将验证码放入到缓存当中(过期时间60s)test
// GuavaUtil.putTrackGuava(registerDto.getPhone(),registerDto.getCode());
// GuavaUtil.putTrackGuava(registerDto.getPhone(),registerDto.getCode());
stringRedisTemplate
.
opsForValue
().
set
(
new
StringBuilder
().
append
(
USER_CODE_KEY
).
append
(
registerDto
.
getPhone
()).
toString
(),
registerDto
.
getCode
(),
RedisEnum
.
PHONECODE
.
getCode
(),
TimeUnit
.
SECONDS
);
//重缓存中获取(通过手机号获取)
//重缓存中获取(通过手机号获取)
String
code
=
(
String
)
GuavaUtil
.
getTrackGuava
(
registerDto
.
getPhone
());
String
code
=
stringRedisTemplate
.
opsForValue
().
get
(
USER_CODE_KEY
+
registerDto
.
getPhone
());
log
.
info
(
"冲缓存中获取的验证码===============》{}"
,
code
);
log
.
info
(
"冲缓存中获取的验证码===============》{}"
,
code
);
if
(
null
==
code
){
if
(
null
==
code
){
throw
new
BusinessException
(
"验证码已过期"
);
throw
new
BusinessException
(
"验证码已过期"
);
...
@@ -108,7 +120,6 @@ public class UserServiceImpl implements UserService {
...
@@ -108,7 +120,6 @@ public class UserServiceImpl implements UserService {
if
(!
code
.
equals
(
registerDto
.
getCode
())){
if
(!
code
.
equals
(
registerDto
.
getCode
())){
throw
new
BusinessException
(
"验证码错误请重新输入"
);
throw
new
BusinessException
(
"验证码错误请重新输入"
);
}
}
int
i
=
appUserMapper
.
insert
(
appUser
);
int
i
=
appUserMapper
.
insert
(
appUser
);
if
(
i
<
0
){
if
(
i
<
0
){
return
new
ApiResponse
().
fail
(
"新增失败"
);
return
new
ApiResponse
().
fail
(
"新增失败"
);
...
@@ -133,7 +144,8 @@ public class UserServiceImpl implements UserService {
...
@@ -133,7 +144,8 @@ public class UserServiceImpl implements UserService {
}
}
}
else
{
}
else
{
//验证码登陆
//验证码登陆
String
code
=
(
String
)
GuavaUtil
.
getTrackGuava
(
loginDto
.
getPhone
());
String
code
=
stringRedisTemplate
.
opsForValue
().
get
(
USER_CODE_KEY
+
loginDto
.
getPhone
());
log
.
info
(
"冲redis中获取的验证码===============》{}"
,
code
);
log
.
info
(
"冲缓存中获取的验证码===============》{}"
,
code
);
log
.
info
(
"冲缓存中获取的验证码===============》{}"
,
code
);
if
(
null
==
code
){
if
(
null
==
code
){
throw
new
BusinessException
(
"验证码已过期"
);
throw
new
BusinessException
(
"验证码已过期"
);
...
@@ -146,6 +158,11 @@ public class UserServiceImpl implements UserService {
...
@@ -146,6 +158,11 @@ public class UserServiceImpl implements UserService {
throw
new
BusinessException
(
"请先注册"
);
throw
new
BusinessException
(
"请先注册"
);
}
}
}
}
UserJwtVO
vo
=
new
UserJwtVO
();
vo
.
setId
(
userVo
.
getId
());
vo
.
setPhone
(
userVo
.
getPhone
());
String
token
=
JwtUtils
.
generateJsonWebToken
(
vo
);
userVo
.
setAuthorization
(
token
);
ApiResponse
apiResponse
=
new
ApiResponse
();
ApiResponse
apiResponse
=
new
ApiResponse
();
apiResponse
.
setData
(
userVo
);
apiResponse
.
setData
(
userVo
);
return
apiResponse
;
return
apiResponse
;
...
...
nafmii-app/src/main/java/org/nafmii/app/user/vo/UserVO.java
View file @
69a0a10
...
@@ -64,4 +64,6 @@ public class UserVO {
...
@@ -64,4 +64,6 @@ public class UserVO {
@ApiModelProperty
(
value
=
"是否有效标识 0 有效用户 1无效用户"
)
@ApiModelProperty
(
value
=
"是否有效标识 0 有效用户 1无效用户"
)
private
String
isEnable
;
private
String
isEnable
;
@ApiModelProperty
(
value
=
"token"
)
private
String
authorization
;
}
}
nafmii-app/src/main/resources/application.yml
View file @
69a0a10
...
@@ -36,3 +36,19 @@ spring:
...
@@ -36,3 +36,19 @@ spring:
connection-timeout
:
3000
connection-timeout
:
3000
pool-name
:
NFMII_HikariCP
pool-name
:
NFMII_HikariCP
connection-test-query
:
SELECT 1
connection-test-query
:
SELECT 1
redis
:
# Redis数据库索引(默认为0)
database
:
0
# Redis服务器地址
host
:
127.0.0.1
port
:
6379
# Redis服务器连接密码(默认为空)
password
:
jedis
:
pool
:
# 连接池最大连接数(使用负值表示没有限制)
max-active
:
20
max-wait
:
-1ms
max-idle
:
10
min-idle
:
0
timeout
:
1000ms
nafmii-common/src/main/java/org/nafmii/common/utils/JwtUtils.java
View file @
69a0a10
...
@@ -3,6 +3,7 @@ package org.nafmii.common.utils;
...
@@ -3,6 +3,7 @@ package org.nafmii.common.utils;
import
io.jsonwebtoken.Claims
;
import
io.jsonwebtoken.Claims
;
import
io.jsonwebtoken.Jwts
;
import
io.jsonwebtoken.Jwts
;
import
io.jsonwebtoken.SignatureAlgorithm
;
import
io.jsonwebtoken.SignatureAlgorithm
;
import
org.nafmii.common.vo.UserJwtVO
;
import
java.util.Date
;
import
java.util.Date
;
import
java.util.HashMap
;
import
java.util.HashMap
;
...
@@ -19,24 +20,24 @@ public class JwtUtils {
...
@@ -19,24 +20,24 @@ public class JwtUtils {
private
static
final
String
ROLE_CLAIMS
=
"rol"
;
private
static
final
String
ROLE_CLAIMS
=
"rol"
;
// public static String generateJsonWebToken(AppUser
user) {
public
static
String
generateJsonWebToken
(
UserJwtVO
user
)
{
//
if (user.getId() == null || user.getUserName() == null ) {
if
(
user
.
getId
()
==
null
||
user
.
getUserName
()
==
null
)
{
//
return null;
return
null
;
//
}
}
//
//
Map<String,Object> map = new HashMap<>();
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
//
map.put(ROLE_CLAIMS, "rol");
map
.
put
(
ROLE_CLAIMS
,
"rol"
);
//
String token = Jwts
String
token
=
Jwts
//
.builder()
.
builder
()
//
.setSubject(SUBJECT)
.
setSubject
(
SUBJECT
)
//
.setClaims(map)
.
setClaims
(
map
)
//
.claim("id", user.getId())
.
claim
(
"id"
,
user
.
getId
())
//
.claim("name", user.getUserName())
.
claim
(
"name"
,
user
.
getUserName
())
//
.setIssuedAt(new Date())
.
setIssuedAt
(
new
Date
())
//
.setExpiration(new Date(System.currentTimeMillis() + EXPIRITION))
.
setExpiration
(
new
Date
(
System
.
currentTimeMillis
()
+
EXPIRITION
))
//
.signWith(SignatureAlgorithm.HS256, APPSECRET_KEY).compact();
.
signWith
(
SignatureAlgorithm
.
HS256
,
APPSECRET_KEY
).
compact
();
//
return token;
return
token
;
//
}
}
/**
/**
* 生成token
* 生成token
...
...
nafmii-common/src/main/java/org/nafmii/common/vo/AppUser.java
deleted
100644 → 0
View file @
31b9680
File mode changed
nafmii-common/src/main/java/org/nafmii/common/vo/UserJwtVO.java
0 → 100644
View file @
69a0a10
package
org
.
nafmii
.
common
.
vo
;
import
io.swagger.annotations.ApiModel
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.Data
;
import
java.util.Date
;
/**
* @author:zhoujh
* @Function:TODO
* @date 2021/4/25 10:22
* @ClassName:
* @version:
* @remark:
*/
@Data
@ApiModel
(
"用户返回报文"
)
public
class
UserJwtVO
{
private
Long
id
;
@ApiModelProperty
(
value
=
"昵称"
)
private
String
userName
;
@ApiModelProperty
(
value
=
"登录密码"
)
private
String
loginPwd
;
@ApiModelProperty
(
value
=
"中文姓名"
)
private
String
realName
;
@ApiModelProperty
(
value
=
"手机号/登录账号"
)
private
String
phone
;
@ApiModelProperty
(
value
=
"出生日期"
)
private
String
birthday
;
@ApiModelProperty
(
value
=
"邮箱"
)
private
String
email
;
@ApiModelProperty
(
value
=
"头像图片地址"
)
private
String
headPicture
;
@ApiModelProperty
(
value
=
"国籍"
)
private
String
nationality
;
@ApiModelProperty
(
value
=
"单位全称"
)
private
String
unitName
;
@ApiModelProperty
(
value
=
"微信OPENT_ID"
)
private
String
openId
;
@ApiModelProperty
(
value
=
"是否开启指纹登录 0 未开启 1 已开启"
)
private
String
figerprintFalg
;
@ApiModelProperty
(
value
=
"是否开启人脸识别登录 0 未开启 1 已开启"
)
private
String
faceidFalg
;
@ApiModelProperty
(
value
=
"创建时间"
)
private
Date
createTime
;
@ApiModelProperty
(
value
=
"更新时间"
)
private
Date
updateTime
;
@ApiModelProperty
(
value
=
"是否有效标识 0 有效用户 1无效用户"
)
private
String
isEnable
;
}
nafmii-common/src/main/java/org/nafmii/enums/RedisEnum.java
0 → 100644
View file @
69a0a10
package
org
.
nafmii
.
enums
;
/**
* @author:zhoujh
* @Function:TODO
* @date 2021/4/27 13:48
* @ClassName:
* @version:
* @remark:
*/
public
enum
RedisEnum
{
/**
* 验证码失效时间60s
*/
PHONECODE
(
60
,
"60秒后失效"
)
;
RedisEnum
(
Integer
code
,
String
name
){
this
.
code
=
code
;
this
.
name
=
name
;
}
private
String
name
;
private
Integer
code
;
public
String
getName
()
{
return
name
;
}
public
void
setName
(
String
name
)
{
this
.
name
=
name
;
}
public
Integer
getCode
()
{
return
code
;
}
public
void
setCode
(
Integer
code
)
{
this
.
code
=
code
;
}
}
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment