Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
device-new-platform
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
赵啸非
device-new-platform
Commits
3da50dcc
Commit
3da50dcc
authored
Nov 13, 2023
by
赵啸非
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
更新用户同步通知,token不足二十分钟刷新
parent
fd70f380
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
94 additions
and
30 deletions
+94
-30
device-manager/src/main/java/com/mortals/xhx/base/framework/interceptor/AuthTokenServiceImpl.java
.../xhx/base/framework/interceptor/AuthTokenServiceImpl.java
+6
-2
device-manager/src/main/java/com/mortals/xhx/base/system/user/service/UserService.java
...com/mortals/xhx/base/system/user/service/UserService.java
+5
-0
device-manager/src/main/java/com/mortals/xhx/base/system/user/service/impl/UserServiceImpl.java
...ls/xhx/base/system/user/service/impl/UserServiceImpl.java
+62
-0
device-manager/src/main/java/com/mortals/xhx/base/system/user/web/UserController.java
.../com/mortals/xhx/base/system/user/web/UserController.java
+14
-11
device-manager/src/main/java/com/mortals/xhx/daemon/task/SyncUserTaskImpl.java
...in/java/com/mortals/xhx/daemon/task/SyncUserTaskImpl.java
+7
-17
No files found.
device-manager/src/main/java/com/mortals/xhx/base/framework/interceptor/AuthTokenServiceImpl.java
View file @
3da50dcc
...
...
@@ -80,7 +80,7 @@ public class AuthTokenServiceImpl implements IAuthTokenService {
protected
static
final
Long
SECOND_WEEK
=
7
*
SECOND_DAY
;
private
static
final
Long
SECOND_MINUTE_TEN
=
1
*
SECOND_MINUTE
;
private
static
final
Long
SECOND_MINUTE_TEN
=
20
*
SECOND_MINUTE
;
@Autowired
private
ICacheService
cacheService
;
...
...
@@ -106,6 +106,11 @@ public class AuthTokenServiceImpl implements IAuthTokenService {
if
(
platFormType
.
equalsIgnoreCase
(
PlatformTypeEnum
.
CLOUD
.
getValue
()))
{
cacheService
.
select
(
portalDb
);
userStr
=
cacheService
.
get
(
userKey
);
//刷新token时间
UserEntity
userEntity
=
JSONObject
.
parseObject
(
userStr
,
UserEntity
.
class
);
if
(!
ObjectUtils
.
isEmpty
(
userEntity
))
{
verifyToken
(
userEntity
);
}
cacheService
.
select
(
db
);
}
else
{
userStr
=
cacheService
.
get
(
userKey
);
...
...
@@ -116,7 +121,6 @@ public class AuthTokenServiceImpl implements IAuthTokenService {
//更新portal 中的id 为 device中的id
// UserEntity temp = userService.selectOne(new UserQuery().loginName(userEntity.getLoginName()));
UserEntity
temp
=
userService
.
getExtCache
(
userEntity
.
getLoginName
());
if
(!
ObjectUtils
.
isEmpty
(
temp
))
{
userEntity
.
setId
(
temp
.
getId
());
}
...
...
device-manager/src/main/java/com/mortals/xhx/base/system/user/service/UserService.java
View file @
3da50dcc
...
...
@@ -8,6 +8,7 @@
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
;
...
...
@@ -116,6 +117,10 @@ public interface UserService extends ICRUDCacheService<UserEntity,Long> {
Rest
<
Void
>
refreshUser
();
UserDao
getUserDao
();
}
\ No newline at end of file
device-manager/src/main/java/com/mortals/xhx/base/system/user/service/impl/UserServiceImpl.java
View file @
3da50dcc
...
...
@@ -9,6 +9,7 @@
package
com.mortals.xhx.base.system.user.service.impl
;
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
;
...
...
@@ -30,6 +31,12 @@ 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.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.util.ObjectUtils
;
...
...
@@ -47,6 +54,7 @@ import java.util.stream.Collectors;
* @version 1.0.0
*/
@Service
(
"userService"
)
@Slf4j
public
class
UserServiceImpl
extends
AbstractCRUDCacheServiceImpl
<
UserDao
,
UserEntity
,
Long
>
implements
UserService
{
...
...
@@ -59,6 +67,9 @@ public class UserServiceImpl extends AbstractCRUDCacheServiceImpl<UserDao, UserE
@Autowired
private
RoleUserService
roleUserService
;
@Autowired
private
IUserFeign
userFeign
;
@Override
protected
String
getExtKey
(
UserEntity
data
)
{
return
data
.
getLoginName
();
...
...
@@ -319,6 +330,57 @@ public class UserServiceImpl extends AbstractCRUDCacheServiceImpl<UserDao, UserE
return
true
;
}
@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
>
oldUserList
=
this
.
find
(
new
UserQuery
());
log
.
info
(
" oldUserList size:{}"
,
oldUserList
.
size
());
Map
<
String
,
UserEntity
>
oldUserMap
=
oldUserList
.
stream
().
collect
(
Collectors
.
toMap
(
x
->
x
.
getLoginName
(),
y
->
y
,
(
o
,
n
)
->
n
));
Map
<
String
,
UserEntity
>
newUserMap
=
newUserList
.
stream
().
collect
(
Collectors
.
toMap
(
x
->
x
.
getLoginName
(),
y
->
y
,
(
o
,
n
)
->
n
));
List
<
UserEntity
>
saveUserList
=
newUserList
.
stream
().
map
(
item
->
{
if
(!
oldUserMap
.
containsKey
(
item
.
getLoginName
()))
{
item
.
setCreateUserId
(
1L
);
item
.
setCreateUserName
(
"系统管理员"
);
item
.
setCreateTime
(
new
Date
());
return
item
;
}
return
null
;
}).
filter
(
f
->
f
!=
null
).
collect
(
Collectors
.
toList
());
if
(!
ObjectUtils
.
isEmpty
(
saveUserList
))
{
saveUserList
.
stream
().
forEach
(
item
->{
this
.
getUserDao
().
insert
(
item
);
});
//userService.save(saveUserList);
}
}
//查找新增 与更新
}
return
Rest
.
ok
();
}
@Override
public
UserDao
getUserDao
()
{
return
getDao
();
...
...
device-manager/src/main/java/com/mortals/xhx/base/system/user/web/UserController.java
View file @
3da50dcc
...
...
@@ -2,12 +2,13 @@ package com.mortals.xhx.base.system.user.web;
import
com.alibaba.fastjson.JSONObject
;
import
com.mortals.framework.annotation.UnAuth
;
import
com.mortals.framework.common.IBaseEnum
;
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
;
import
com.mortals.framework.web.BaseCRUDJsonBodyMappingController
;
import
com.mortals.framework.web.BaseCRUDJsonMappingController
;
import
com.mortals.xhx.base.framework.annotation.Operlog
;
import
com.mortals.xhx.base.system.role.model.RoleQuery
;
import
com.mortals.xhx.base.system.role.model.RoleUserEntity
;
...
...
@@ -20,17 +21,10 @@ import com.mortals.xhx.common.code.UserStatus;
import
io.jsonwebtoken.Claims
;
import
io.jsonwebtoken.Jwts
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.util.ObjectUtils
;
import
org.springframework.util.StringUtils
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMethod
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.bind.annotation.*
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
java.util.Base64
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.stream.Collectors
;
...
...
@@ -56,8 +50,8 @@ public class UserController extends BaseCRUDJsonBodyMappingController<UserServic
@Override
protected
void
init
(
Map
<
String
,
Object
>
model
,
Context
context
)
{
this
.
addDict
(
model
,
"userType"
,
IBaseEnum
.
getEnumMap
(
UserType
.
class
));
this
.
addDict
(
model
,
"status"
,
UserStatus
.
getEnumMap
());
this
.
addDict
(
model
,
"userType"
,
IBaseEnum
.
getEnumMap
(
UserType
.
class
));
this
.
addDict
(
model
,
"status"
,
UserStatus
.
getEnumMap
());
this
.
addDict
(
model
,
"roleIds"
,
roleService
.
find
(
new
RoleQuery
()).
stream
().
collect
(
Collectors
.
toMap
(
x
->
x
.
getId
().
toString
(),
y
->
y
.
getName
())));
}
...
...
@@ -117,6 +111,15 @@ public class UserController extends BaseCRUDJsonBodyMappingController<UserServic
}
@PostMapping
({
"refreshUser"
})
@UnAuth
public
Rest
<
Object
>
refreshUser
()
{
log
.
info
(
"刷新用户"
);
this
.
service
.
refreshUser
();
return
Rest
.
ok
(
"用户同步刷新操作成功"
);
}
public
static
void
main
(
String
[]
args
)
{
String
token
=
"eyJhbGciOiJIUzI1NiJ9.eyJsb2dpbl91c2VyX2tleSI6IjIzNGE5NDA5ZDVhOTQ3MWNhMzdkYjZkYmMwY2JjZTc5In0.MWyQW40HYDxyUz7PJRf_nRsFPWx3Hr811Ime984nixs"
;
...
...
device-manager/src/main/java/com/mortals/xhx/daemon/task/SyncUserTaskImpl.java
View file @
3da50dcc
package
com.mortals.xhx.daemon.task
;
import
com.mortals.framework.common.Rest
;
import
com.mortals.framework.exception.AppException
;
import
com.mortals.framework.service.ITask
;
import
com.mortals.framework.service.ITaskExcuteService
;
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.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnExpression
;
import
org.springframework.stereotype.Service
;
import
org.springframework.util.ObjectUtils
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.stream.Collectors
;
/**
* 同步用户,唯一标识为用户名。
...
...
@@ -39,7 +26,10 @@ public class SyncUserTaskImpl implements ITaskExcuteService {
@Override
public
void
excuteTask
(
ITask
task
)
throws
AppException
{
log
.
info
(
"同步用户任务"
);
UserPdu
userPdu
=
new
UserPdu
();
userService
.
refreshUser
();
/* UserPdu userPdu = new UserPdu();
userPdu.setPage(1);
userPdu.setSize(-1);
Rest<RespData<List<UserPdu>>> resp = userFeign.list(userPdu);
...
...
@@ -86,7 +76,7 @@ public class SyncUserTaskImpl implements ITaskExcuteService {
//同步更新用户,以loginname为唯一标识,密码默认与用户相同
/* resp.getData().getData().forEach(user -> {
*/
/* resp.getData().getData().forEach(user -> {
log.info("loginName:{}", user.getLoginName());
UserEntity tempEntity = userService.selectOne(new UserQuery().loginName(user.getLoginName()));
if (ObjectUtils.isEmpty(tempEntity)) {
...
...
@@ -101,8 +91,8 @@ public class SyncUserTaskImpl implements ITaskExcuteService {
log.info("更新:{}", JSON.toJSONString(userEntity));
userService.getUserDao().update(userEntity);
}
});*/
}
});*/
/*
}
*/
// log.info("syncUserResp:{}", JSON.toJSONString(resp));
}
...
...
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