Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
O
one-certificate-system
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
赵啸非
one-certificate-system
Commits
e96120ec
Commit
e96120ec
authored
Jul 28, 2024
by
赵啸非
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加目录字段
parent
cfb0ba91
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
193 additions
and
128 deletions
+193
-128
one-certificate-manager/src/main/java/com/mortals/xhx/base/system/user/service/UserService.java
...com/mortals/xhx/base/system/user/service/UserService.java
+31
-11
one-certificate-manager/src/main/java/com/mortals/xhx/base/system/user/service/impl/UserServiceImpl.java
...ls/xhx/base/system/user/service/impl/UserServiceImpl.java
+162
-117
No files found.
one-certificate-manager/src/main/java/com/mortals/xhx/base/system/user/service/UserService.java
View file @
e96120ec
...
...
@@ -8,7 +8,6 @@
package
com.mortals.xhx.base.system.user.service
;
import
com.mortals.framework.common.Rest
;
import
com.mortals.framework.exception.AppException
;
import
com.mortals.framework.model.Result
;
import
com.mortals.framework.service.ICRUDCacheService
;
...
...
@@ -39,7 +38,7 @@ public interface UserService extends ICRUDCacheService<UserEntity,Long> {
* @return
* @throws AppException
*/
UserEntity
doLogin
(
String
loginName
,
String
password
,
String
loginIp
)
throws
AppException
;
public
UserEntity
doLogin
(
String
loginName
,
String
password
,
String
loginIp
)
throws
AppException
;
/**
* 校验用户名与密码是否正确
...
...
@@ -49,7 +48,7 @@ public interface UserService extends ICRUDCacheService<UserEntity,Long> {
* @return
* @throws AppException
*/
UserEntity
doCheckUser
(
String
loginName
,
String
password
)
throws
AppException
;
public
UserEntity
doCheckUser
(
String
loginName
,
String
password
)
throws
AppException
;
/**
* 检查用户是否存在
...
...
@@ -58,7 +57,7 @@ public interface UserService extends ICRUDCacheService<UserEntity,Long> {
* @param userId 密码
* @return
*/
boolean
existUser
(
String
loginName
,
Long
userId
)
throws
AppException
;
public
boolean
existUser
(
String
loginName
,
Long
userId
)
throws
AppException
;
/**
* 通过登录用户获取菜单功能权限
...
...
@@ -66,7 +65,7 @@ public interface UserService extends ICRUDCacheService<UserEntity,Long> {
* @param user
* @return
*/
List
<
MenuEntity
>
findOutlookBarList
(
IUser
user
);
public
List
<
MenuEntity
>
findOutlookBarList
(
IUser
user
);
/**
* 查询用户所有有权限的菜单ID
...
...
@@ -74,7 +73,7 @@ public interface UserService extends ICRUDCacheService<UserEntity,Long> {
* @param userEntity
* @return
*/
Set
<
Long
>
findAllAuthIds
(
UserEntity
userEntity
)
throws
AppException
;
public
Set
<
Long
>
findAllAuthIds
(
UserEntity
userEntity
)
throws
AppException
;
/**
* 查询用户记录
...
...
@@ -86,7 +85,7 @@ public interface UserService extends ICRUDCacheService<UserEntity,Long> {
* @return
* @throws AppException
*/
Result
<
UserEntity
>
find
(
Long
platformId
,
UserEntity
params
,
int
currPage
,
int
prePageResult
)
throws
AppException
;
public
Result
<
UserEntity
>
find
(
Long
platformId
,
UserEntity
params
,
int
currPage
,
int
prePageResult
)
throws
AppException
;
/**
* 为客户创建用户
...
...
@@ -101,7 +100,7 @@ public interface UserService extends ICRUDCacheService<UserEntity,Long> {
* @return
* @throws AppException
*/
UserEntity
createUser
(
IUser
currUser
,
Long
customerId
,
String
customerName
,
String
loginName
,
String
password
,
public
UserEntity
createUser
(
IUser
currUser
,
Long
customerId
,
String
customerName
,
String
loginName
,
String
password
,
String
userName
,
String
mobile
)
throws
AppException
;
/**
...
...
@@ -113,11 +112,32 @@ public interface UserService extends ICRUDCacheService<UserEntity,Long> {
* @return
* @throws AppException
*/
boolean
updateUserPwd
(
String
loginName
,
String
oldPwd
,
String
newPwd
)
throws
AppException
;
public
boolean
updateUserPwd
(
String
loginName
,
String
oldPwd
,
String
newPwd
)
throws
AppException
;
/**
*
* @param entity
*/
void
doHandlerUser
(
UserEntity
entity
);
Rest
<
Void
>
refreshUser
();
UserDao
getUserDao
();
UserDao
getUserDao
();
/**
* 发送手机验证码
* @param mobileNumber
* @throws AppException
*/
void
sendSmsVerifyCode
(
String
mobileNumber
)
throws
AppException
;
/**
* 手机验证码登录
* @param mobileNumber
* @param verifyCode
* @param loginIp
* @return
* @throws AppException
*/
UserEntity
doSmsLogin
(
String
mobileNumber
,
String
verifyCode
,
String
loginIp
)
throws
AppException
;
}
\ No newline at end of file
one-certificate-manager/src/main/java/com/mortals/xhx/base/system/user/service/impl/UserServiceImpl.java
View file @
e96120ec
...
...
@@ -8,8 +8,10 @@
package
com.mortals.xhx.base.system.user.service.impl
;
import
cn.hutool.core.util.PhoneUtil
;
import
cn.hutool.core.util.RandomUtil
;
import
com.alibaba.fastjson.JSONObject
;
import
com.mortals.framework.ap.SysConstains
;
import
com.mortals.framework.common.Rest
;
import
com.mortals.framework.common.code.UserType
;
import
com.mortals.framework.exception.AppException
;
import
com.mortals.framework.model.Context
;
...
...
@@ -17,32 +19,26 @@ import com.mortals.framework.model.PageInfo;
import
com.mortals.framework.model.Result
;
import
com.mortals.framework.service.IUser
;
import
com.mortals.framework.service.impl.AbstractCRUDCacheServiceImpl
;
import
com.mortals.framework.util.HttpUtil
;
import
com.mortals.framework.util.SecurityUtil
;
import
com.mortals.framework.util.StringUtils
;
import
com.mortals.xhx.base.system.menu.model.MenuEntity
;
import
com.mortals.xhx.base.system.menu.service.MenuService
;
import
com.mortals.xhx.base.system.resource.model.ResourceEntity
;
import
com.mortals.xhx.base.system.resource.service.ResourceService
;
import
com.mortals.xhx.base.system.role.dao.RoleUserDao
;
import
com.mortals.xhx.base.system.role.model.RoleUserEntity
;
import
com.mortals.xhx.base.system.role.model.RoleUserQuery
;
import
com.mortals.xhx.base.system.role.service.RoleUserService
;
import
com.mortals.xhx.base.system.user.dao.UserDao
;
import
com.mortals.xhx.base.system.user.model.UserEntity
;
import
com.mortals.xhx.base.system.user.model.UserQuery
;
import
com.mortals.xhx.base.system.user.service.UserService
;
import
com.mortals.xhx.common.code.YesNoEnum
;
import
com.mortals.xhx.common.pdu.RespData
;
import
com.mortals.xhx.common.pdu.user.UserPdu
;
import
com.mortals.xhx.feign.user.IUserFeign
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.BeanUtils
;
import
org.apache.commons.collections4.CollectionUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.
context.annotation.Lazy
;
import
org.springframework.
beans.factory.annotation.Value
;
import
org.springframework.stereotype.Service
;
import
org.springframework.util.ObjectUtils
;
import
java.util.*
;
import
java.util.stream.Collectors
;
/**
* <p>Title: 用户信息</p>
...
...
@@ -54,7 +50,6 @@ import java.util.stream.Collectors;
* @version 1.0.0
*/
@Service
(
"userService"
)
@Slf4j
public
class
UserServiceImpl
extends
AbstractCRUDCacheServiceImpl
<
UserDao
,
UserEntity
,
Long
>
implements
UserService
{
...
...
@@ -63,18 +58,27 @@ public class UserServiceImpl extends AbstractCRUDCacheServiceImpl<UserDao, UserE
@Autowired
private
ResourceService
resourceService
;
@Autowired
private
RoleUser
Service
roleUserService
;
private
RoleUser
Dao
roleUserDao
;
@Lazy
@Autowired
private
IUserFeign
userFeign
;
@Value
(
"${sms.smsSendUrl:http://sms.wx3.com.cn/api/index/index}"
)
private
String
smsApiUrl
;
@Value
(
"${sms.apiId:ADsUXLrS81vZDU95}"
)
private
String
appid
;
/**
* 短信模板ID
**/
private
static
String
SMS_TPYE
=
"30"
;
private
static
String
SMS_VERIFY_CODE_KEY
=
"login:sms:verify:"
;
@Override
protected
String
getExtKey
(
UserEntity
data
)
{
return
data
.
getLoginName
();
}
private
void
doHandlerUser
(
UserEntity
entity
)
throws
AppException
{
public
void
doHandlerUser
(
UserEntity
entity
)
throws
AppException
{
if
(
StringUtils
.
isNotEmpty
(
entity
.
getLoginPwd
()))
{
try
{
entity
.
setLoginPwd
(
SecurityUtil
.
md5DoubleEncoding
(
entity
.
getLoginPwd
()));
...
...
@@ -84,63 +88,98 @@ public class UserServiceImpl extends AbstractCRUDCacheServiceImpl<UserDao, UserE
}
else
{
entity
.
setLoginPwd
(
null
);
}
// if (entity.isSystemUser()) {
// entity.setUserType(UserType.SYSTEM.getValue());
// } else {
// entity.setUserType(UserType.CUSTOMER.getValue());
// }
}
@Override
protected
void
saveBefore
(
UserEntity
entity
,
Context
context
)
throws
AppException
{
if
(!
ObjectUtils
.
isEmpty
(
entity
.
getLoginName
())
&&
existUser
(
entity
.
getLoginName
(),
entity
.
getId
()))
{
throw
new
AppException
(
"登录名已存在!"
);
}
this
.
doHandlerUser
(
entity
);
}
@Override
protected
void
saveAfter
(
UserEntity
entity
,
Context
context
)
throws
AppException
{
if
(
CollectionUtils
.
isNotEmpty
(
entity
.
getRoleIds
()))
{
List
<
RoleUserEntity
>
roleUserEntityList
=
new
ArrayList
<>();
entity
.
getRoleIds
().
stream
().
forEach
(
item
->
{
RoleUserEntity
roleUserEntity
=
new
RoleUserEntity
();
roleUserEntity
.
setUserId
(
entity
.
getId
());
roleUserEntity
.
setRoleId
(
item
);
roleUserEntityList
.
add
(
roleUserEntity
);
});
roleUserDao
.
insertBatch
(
roleUserEntityList
);
}
}
@Override
protected
void
updateBefore
(
UserEntity
entity
,
Context
context
)
throws
AppException
{
/
/
if (entity.getId().longValue() == SysConstains.ADMIN_ID && !context.getUser().isAdmin()) {
//
throw new AppException("你没有权限执行该操作");
// }
//更新不更新密码字段
entity
.
setLoginPwd
(
null
);
/
*
if (entity.getId().longValue() == SysConstains.ADMIN_ID && !context.getUser().isAdmin()) {
throw new AppException("你没有权限执行该操作");
}*/
if
(
entity
.
getId
().
longValue
()
==
SysConstains
.
ADMIN_ID
)
{
throw
new
AppException
(
"你没有权限执行该操作"
);
}
this
.
doHandlerUser
(
entity
);
}
@Override
protected
void
saveAfter
(
UserEntity
entity
,
Context
context
)
throws
AppException
{
//新增角色
updateUserRole
(
entity
);
super
.
saveAfter
(
entity
,
context
);
protected
void
updateAfter
(
UserEntity
entity
,
Context
context
)
throws
AppException
{
if
(
CollectionUtils
.
isNotEmpty
(
entity
.
getRoleIds
()))
{
List
<
RoleUserEntity
>
roleUserEntityList
=
new
ArrayList
<>();
entity
.
getRoleIds
().
stream
().
forEach
(
item
->
{
RoleUserEntity
roleUserEntity
=
new
RoleUserEntity
();
roleUserEntity
.
setUserId
(
entity
.
getId
());
roleUserEntity
.
setRoleId
(
item
);
roleUserEntityList
.
add
(
roleUserEntity
);
});
RoleUserEntity
condition
=
new
RoleUserEntity
();
condition
.
setUserId
(
entity
.
getId
());
roleUserDao
.
delete
(
condition
);
roleUserDao
.
insertBatch
(
roleUserEntityList
);
}
}
@Override
protected
void
updateAfter
(
UserEntity
entity
,
Context
context
)
throws
AppException
{
updateUserRole
(
entity
);
super
.
updateAfter
(
entity
,
context
);
protected
UserEntity
findBefore
(
UserEntity
params
,
Context
context
)
throws
AppException
{
// if (StringUtils.isNotEmpty(params.getDeptIds())) {
// params.setDeptIds(StringUtils.fillWithMark(params.getDeptIds(), ","));
// }
return
super
.
findBefore
(
params
,
context
);
}
private
void
updateUserRole
(
UserEntity
entity
)
{
if
(!
ObjectUtils
.
isEmpty
(
entity
.
getId
())
&&
entity
.
getId
().
longValue
()
!=
SysConstains
.
ADMIN_ID
&&
!
ObjectUtils
.
isEmpty
(
entity
.
getRoleIds
()))
{
RoleUserQuery
roleUserQuery
=
new
RoleUserQuery
();
roleUserQuery
.
setUserId
(
entity
.
getId
());
List
<
Long
>
idList
=
Arrays
.
asList
(
entity
.
getRoleIds
().
split
(
","
)).
stream
().
map
(
Long:
:
parseLong
).
collect
(
Collectors
.
toList
());
roleUserQuery
.
setRoleIdList
(
idList
);
roleUserService
.
doDistributionRole
(
roleUserQuery
);
}
@Override
protected
UserEntity
findBefore
(
UserEntity
params
,
PageInfo
pageInfo
,
Context
context
)
throws
AppException
{
// if (StringUtils.isNotEmpty(params.getDeptIds())) {
// params.setDeptIds(StringUtils.fillWithMark(params.getDeptIds(), ","));
// }
return
super
.
findBefore
(
params
,
pageInfo
,
context
);
}
@Override
protected
void
findAfter
(
UserEntity
params
,
PageInfo
pageInfo
,
Context
context
,
List
<
UserEntity
>
list
)
throws
AppException
{
list
.
stream
().
peek
(
item
->
{
RoleUserQuery
roleUserQuery
=
new
RoleUserQuery
();
roleUserQuery
.
setUserId
(
item
.
getId
());
String
roleIds
=
roleUserService
.
find
(
roleUserQuery
).
stream
().
map
(
RoleUserEntity:
:
getRoleId
).
map
(
String:
:
valueOf
).
collect
(
Collectors
.
joining
(
","
));
item
.
setRoleIds
(
roleIds
);
}).
count
();
super
.
findAfter
(
params
,
pageInfo
,
context
,
list
);
if
(
CollectionUtils
.
isNotEmpty
(
list
))
{
list
.
stream
().
forEach
(
item
->
{
RoleUserEntity
query
=
new
RoleUserEntity
();
query
.
setUserId
(
item
.
getId
());
List
<
RoleUserEntity
>
roleUserEntityList
=
roleUserDao
.
getList
(
query
);
List
<
Long
>
roleIds
=
new
ArrayList
<>();
roleUserEntityList
.
stream
().
forEach
(
role
->
{
roleIds
.
add
(
role
.
getRoleId
());
});
item
.
setRoleIds
(
roleIds
);
String
roleIdStrs
=
StringUtils
.
join
(
roleIds
,
","
);
item
.
setRoleIdStrs
(
roleIdStrs
);
RoleUserQuery
roleUserQuery
=
new
RoleUserQuery
();
roleUserQuery
.
setUserId
(
item
.
getId
());
});
}
}
public
UserEntity
findByLoginName
(
String
loginName
)
{
UserQuery
params
=
new
UserQuery
();
params
.
setLoginName
(
loginName
);
...
...
@@ -164,6 +203,11 @@ public class UserServiceImpl extends AbstractCRUDCacheServiceImpl<UserDao, UserE
}
catch
(
Exception
e
)
{
throw
new
AppException
(
"密码验认出错!"
,
e
);
}
UserEntity
update
=
new
UserEntity
();
update
.
setId
(
sysUser
.
getId
());
update
.
setLastLoginAddress
(
loginIp
);
update
.
setLastLoginTime
(
new
Date
());
this
.
dao
.
update
(
update
);
return
sysUser
;
}
...
...
@@ -207,7 +251,7 @@ public class UserServiceImpl extends AbstractCRUDCacheServiceImpl<UserDao, UserE
urls
.
addAll
(
StringUtils
.
converStr2Set
(
url
));
}
}
Set
<
Long
>
authIds
=
new
HashSet
<>();
Set
<
Long
>
authIds
=
new
HashSet
<
Long
>();
Map
<
Long
,
MenuEntity
>
menuMap
=
new
HashMap
<
Long
,
MenuEntity
>();
List
<
MenuEntity
>
userModuleList
=
this
.
menuService
.
findAllEnable
();
for
(
MenuEntity
sysModule
:
userModuleList
)
{
...
...
@@ -215,7 +259,6 @@ public class UserServiceImpl extends AbstractCRUDCacheServiceImpl<UserDao, UserE
continue
;
}
menuMap
.
put
(
sysModule
.
getId
(),
sysModule
);
if
(!
user
.
isAdmin
()
&&
urls
.
contains
(
StringUtils
.
trim
(
sysModule
.
getUrl
())))
{
authIds
.
add
(
sysModule
.
getId
());
}
...
...
@@ -264,6 +307,7 @@ public class UserServiceImpl extends AbstractCRUDCacheServiceImpl<UserDao, UserE
entity
.
initAttrValue
();
entity
.
setLoginName
(
loginName
);
entity
.
setRealName
(
userName
);
entity
.
setCustomerId
(
customerId
);
entity
.
setLoginPwd
(
password
);
entity
.
setMobile
(
mobile
);
entity
.
setUserType
(
UserType
.
CUSTOMER
.
getValue
());
...
...
@@ -309,6 +353,7 @@ public class UserServiceImpl extends AbstractCRUDCacheServiceImpl<UserDao, UserE
}
try
{
sysUser
.
setLoginPwd
(
SecurityUtil
.
md5DoubleEncoding
(
newPwd
));
}
catch
(
Exception
e
)
{
throw
new
AppException
(
"密码转换异常!"
,
e
);
}
...
...
@@ -317,78 +362,78 @@ public class UserServiceImpl extends AbstractCRUDCacheServiceImpl<UserDao, UserE
}
@Override
public
Rest
<
Void
>
refreshUser
()
{
UserPdu
userPdu
=
new
UserPdu
();
userPdu
.
setPage
(
1
);
userPdu
.
setSize
(-
1
);
Rest
<
RespData
<
List
<
UserPdu
>>>
resp
=
userFeign
.
list
(
userPdu
);
if
(
resp
.
getCode
()
==
YesNoEnum
.
YES
.
getValue
())
{
List
<
UserPdu
>
userPduList
=
resp
.
getData
().
getData
();
log
.
info
(
"用户总数量:{}"
,
userPduList
.
size
());
if
(!
ObjectUtils
.
isEmpty
(
userPduList
))
{
List
<
UserEntity
>
newUserList
=
userPduList
.
stream
().
map
(
newUser
->
{
UserEntity
userEntity
=
new
UserEntity
();
userEntity
.
initAttrValue
();
BeanUtils
.
copyProperties
(
newUser
,
userEntity
,
new
String
[]{
"id"
,
"lastLoginTime"
,
"lastLoginAddress"
});
return
userEntity
;
}).
collect
(
Collectors
.
toList
());
List
<
UserEntity
>
saveUpdateUserList
=
newUserList
.
parallelStream
().
map
(
item
->
{
UserEntity
extCache
=
this
.
getExtCache
(
item
.
getLoginName
());
if
(
ObjectUtils
.
isEmpty
(
extCache
))
{
item
.
setCreateUserId
(
1L
);
item
.
setCreateUserName
(
"系统管理员"
);
item
.
setCreateTime
(
new
Date
());
return
item
;
}
else
{
//更新用户列表
item
.
setId
(
extCache
.
getId
());
item
.
setUpdateUserId
(
1L
);
item
.
setUpdateUserName
(
"系统管理员"
);
item
.
setUpdateTime
(
new
Date
());
return
item
;
}
}).
collect
(
Collectors
.
toList
());
Map
<
Boolean
,
List
<
UserEntity
>>
saveUpdateCollect
=
saveUpdateUserList
.
stream
().
collect
(
Collectors
.
partitioningBy
(
x
->
x
.
getId
()
==
null
));
if
(!
ObjectUtils
.
isEmpty
(
saveUpdateCollect
.
get
(
true
)))
{
//需要新增的用户
log
.
info
(
"需要新增用户数量:{}"
,
saveUpdateCollect
.
get
(
true
).
size
());
saveUpdateCollect
.
get
(
true
).
stream
().
forEach
(
item
->
{
this
.
getUserDao
().
insert
(
item
);
this
.
putCache
(
item
.
getId
()
==
null
?
""
:
item
.
getId
().
toString
(),
item
);
//更新默认用户角色
RoleUserQuery
roleUserQuery
=
new
RoleUserQuery
();
roleUserQuery
.
setUserId
(
item
.
getId
());
roleUserQuery
.
setRoleIdList
(
Arrays
.
asList
(
1L
));
roleUserService
.
doDistributionRole
(
roleUserQuery
);
});
}
public
UserDao
getUserDao
()
{
return
this
.
getDao
();
}
if
(!
ObjectUtils
.
isEmpty
(
saveUpdateCollect
.
get
(
false
)))
{
//需要新增的用户
log
.
info
(
"需要更新用户数量:{}"
,
saveUpdateCollect
.
get
(
false
).
size
());
saveUpdateCollect
.
get
(
false
).
stream
().
forEach
(
item
->
{
this
.
getUserDao
().
update
(
item
);
this
.
putCache
(
item
.
getId
()
==
null
?
""
:
item
.
getId
().
toString
(),
item
);
});
}
@Override
public
void
sendSmsVerifyCode
(
String
mobileNumber
)
throws
AppException
{
if
(
StringUtils
.
isEmpty
(
mobileNumber
))
{
throw
new
AppException
(
"手机号不能为空"
);
}
if
(!
PhoneUtil
.
isPhone
(
mobileNumber
))
{
throw
new
AppException
(
"手机号码格式不正确"
);
}
UserEntity
user
=
this
.
selectOne
(
new
UserQuery
().
mobile
(
mobileNumber
));
if
(
user
==
null
)
{
throw
new
AppException
(
"手机号码:"
+
mobileNumber
+
"没有注册用户"
);
}
String
verifyCode
=
cacheService
.
get
(
SMS_VERIFY_CODE_KEY
+
mobileNumber
);
if
(
StringUtils
.
isNotEmpty
(
verifyCode
))
{
throw
new
AppException
(
"当前手机号码已发送验证码,请稍后重试"
);
}
try
{
Map
<
String
,
String
>
params
=
new
HashMap
<>();
params
.
put
(
"appid"
,
appid
);
params
.
put
(
"phone"
,
mobileNumber
);
params
.
put
(
"type"
,
SMS_TPYE
);
String
[]
json
=
new
String
[
2
];
String
vCode
=
RandomUtil
.
randomNumbers
(
6
);
json
[
0
]
=
vCode
;
json
[
1
]
=
"1"
;
params
.
put
(
"json"
,
JSONObject
.
toJSON
(
json
).
toString
());
String
resp
=
HttpUtil
.
doPost
(
smsApiUrl
,
params
);
JSONObject
respJson
=
JSONObject
.
parseObject
(
resp
);
if
(
respJson
.
getIntValue
(
"code"
)
==
0
)
{
throw
new
AppException
(
"短信发送失败:"
+
respJson
.
getString
(
"message"
));
}
//查找新增 与更新
//有效期60秒
cacheService
.
setnx
(
SMS_VERIFY_CODE_KEY
+
mobileNumber
,
vCode
,
60
);
}
catch
(
Exception
e
)
{
log
.
error
(
"短信发送异常"
,
e
);
throw
new
AppException
(
"短信发送异常"
);
}
return
Rest
.
ok
();
}
@Override
public
UserDao
getUserDao
()
{
return
getDao
();
public
UserEntity
doSmsLogin
(
String
mobileNumber
,
String
verifyCode
,
String
loginIp
)
throws
AppException
{
if
(
StringUtils
.
isEmpty
(
mobileNumber
))
{
throw
new
AppException
(
"手机号不能为空"
);
}
if
(
StringUtils
.
isEmpty
(
verifyCode
))
{
throw
new
AppException
(
"验证码不能为空"
);
}
if
(!
PhoneUtil
.
isPhone
(
mobileNumber
))
{
throw
new
AppException
(
"手机号码格式不正确"
);
}
UserEntity
customer
=
this
.
selectOne
(
new
UserQuery
().
mobile
(
mobileNumber
));
if
(
customer
==
null
)
{
throw
new
AppException
(
"手机号码:"
+
mobileNumber
+
"没有注册用户"
);
}
String
vCode
=
cacheService
.
get
(
SMS_VERIFY_CODE_KEY
+
mobileNumber
);
if
(
StringUtils
.
isEmpty
(
vCode
))
{
throw
new
AppException
(
"验证码已失效"
);
}
if
(!
verifyCode
.
equals
(
vCode
))
{
throw
new
AppException
(
"验证码不正确"
);
}
UserEntity
update
=
new
UserEntity
();
update
.
setId
(
customer
.
getId
());
update
.
setLastLoginAddress
(
loginIp
);
update
.
setLastLoginTime
(
new
Date
());
this
.
update
(
update
);
return
customer
;
}
@Override
protected
void
removeAfter
(
Long
[]
ids
,
Context
context
,
int
result
)
throws
AppException
{
super
.
removeAfter
(
ids
,
context
,
result
);
RoleUserQuery
roleUserQuery
=
new
RoleUserQuery
();
roleUserQuery
.
setUserIdList
(
Arrays
.
asList
(
ids
));
Long
[]
userIds
=
roleUserService
.
find
(
roleUserQuery
).
stream
().
map
(
RoleUserEntity:
:
getId
).
toArray
(
Long
[]::
new
);
roleUserService
.
remove
(
userIds
,
context
);
}
}
\ 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