Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
eshiled-new
/
ne-shield-usercenter
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 4693a5d0
authored
Apr 12, 2022
by
王欣伟
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
修改API创建和更新帐号信息
1 parent
49ccf291
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
42 additions
and
12 deletions
src/main/java/cn/com/glsx/shield/modules/entity/UserRoleRelation.java
src/main/java/cn/com/glsx/shield/modules/service/UserService.java
src/test/java/cn/com/glsx/usercenter/modul/ApiUserControllerTest.java
src/main/java/cn/com/glsx/shield/modules/entity/UserRoleRelation.java
View file @
4693a5d
...
@@ -29,6 +29,13 @@ public class UserRoleRelation extends BaseEntity {
...
@@ -29,6 +29,13 @@ public class UserRoleRelation extends BaseEntity {
}
}
}
}
public
UserRoleRelation
(
Long
createBy
)
{
if
(
createBy
!=
null
)
{
this
.
setCreatedBy
(
createBy
);
this
.
setCreatedDate
(
new
Date
());
}
}
/**
/**
* 用户id
* 用户id
*/
*/
...
...
src/main/java/cn/com/glsx/shield/modules/service/UserService.java
View file @
4693a5d
...
@@ -367,7 +367,17 @@ public class UserService {
...
@@ -367,7 +367,17 @@ public class UserService {
//校验角色
//校验角色
checkUserRole
(
userBO
);
checkUserRole
(
userBO
);
User
user
=
new
User
(
true
);
// 添加帐号设置创建人
SyntheticUser
user
=
ShieldContextHolder
.
getUser
();
addCommonUser
(
userBO
,
user
.
getUserId
());
}
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
void
addCommonUser
(
UserBO
userBO
,
Long
createBy
)
{
User
user
=
new
User
();
user
.
setCreatedBy
(
createBy
);
user
.
setCreatedDate
(
new
Date
());
BeanUtils
.
copyProperties
(
userBO
,
user
);
BeanUtils
.
copyProperties
(
userBO
,
user
);
generateAndSetPassword
(
user
,
userBO
.
getPassword
());
generateAndSetPassword
(
user
,
userBO
.
getPassword
());
...
@@ -376,14 +386,18 @@ public class UserService {
...
@@ -376,14 +386,18 @@ public class UserService {
Long
userId
=
user
.
getId
();
Long
userId
=
user
.
getId
();
if
(
userBO
.
getSuperiorId
()
==
null
)
{
if
(
userBO
.
getSuperiorId
()
==
null
)
{
UserPath
userPath
=
new
UserPath
(
true
);
UserPath
userPath
=
new
UserPath
();
userPath
.
setCreatedBy
(
createBy
);
userPath
.
setCreatedDate
(
new
Date
());
userPath
.
setSuperiorId
(
userId
);
userPath
.
setSuperiorId
(
userId
);
userPath
.
setSubId
(
userId
);
userPath
.
setSubId
(
userId
);
userPath
.
setTenantId
(
user
.
getTenantId
());
userPath
.
setTenantId
(
user
.
getTenantId
());
userPathMapper
.
insertRootPath
(
userPath
);
userPathMapper
.
insertRootPath
(
userPath
);
log
.
info
(
"新增用户根关系{}"
,
userPath
);
log
.
info
(
"新增用户根关系{}"
,
userPath
);
}
else
{
}
else
{
UserPath
userPath
=
new
UserPath
(
true
);
UserPath
userPath
=
new
UserPath
();
userPath
.
setCreatedBy
(
createBy
);
userPath
.
setCreatedDate
(
new
Date
());
userPath
.
setSuperiorId
(
userBO
.
getSuperiorId
());
userPath
.
setSuperiorId
(
userBO
.
getSuperiorId
());
userPath
.
setSubId
(
userId
);
userPath
.
setSubId
(
userId
);
userPath
.
setTenantId
(
user
.
getTenantId
());
userPath
.
setTenantId
(
user
.
getTenantId
());
...
@@ -391,7 +405,7 @@ public class UserService {
...
@@ -391,7 +405,7 @@ public class UserService {
log
.
info
(
"新增用户{}关系{}条"
,
userId
,
insertCnt
);
log
.
info
(
"新增用户{}关系{}条"
,
userId
,
insertCnt
);
}
}
userRoleRelationMapper
.
insert
(
new
UserRoleRelation
(
true
).
setUserId
(
userId
).
setRoleId
(
userBO
.
getRoleId
()));
userRoleRelationMapper
.
insert
(
new
UserRoleRelation
(
createBy
).
setUserId
(
userId
).
setRoleId
(
userBO
.
getRoleId
()));
}
}
@Transactional
(
rollbackFor
=
Exception
.
class
)
@Transactional
(
rollbackFor
=
Exception
.
class
)
...
@@ -408,6 +422,12 @@ public class UserService {
...
@@ -408,6 +422,12 @@ public class UserService {
//校验角色
//校验角色
checkUserRole
(
userBO
);
checkUserRole
(
userBO
);
editCommonUser
(
userBO
,
ShieldContextHolder
.
getUserId
());
}
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
void
editCommonUser
(
UserBO
userBO
,
Long
updateBy
)
{
User
user
=
userMapper
.
selectById
(
userBO
.
getId
());
User
user
=
userMapper
.
selectById
(
userBO
.
getId
());
Long
superiorId
=
user
.
getSuperiorId
();
Long
superiorId
=
user
.
getSuperiorId
();
...
@@ -434,7 +454,7 @@ public class UserService {
...
@@ -434,7 +454,7 @@ public class UserService {
UserRoleRelation
relation
=
relationList
.
get
(
0
);
UserRoleRelation
relation
=
relationList
.
get
(
0
);
if
(!
relation
.
getRoleId
().
equals
(
userBO
.
getRoleId
()))
{
if
(!
relation
.
getRoleId
().
equals
(
userBO
.
getRoleId
()))
{
relation
.
setRoleId
(
userBO
.
getRoleId
());
relation
.
setRoleId
(
userBO
.
getRoleId
());
relation
.
setUpdatedBy
(
ShieldContextHolder
.
getUserId
()
);
relation
.
setUpdatedBy
(
updateBy
);
relation
.
setUpdatedDate
(
new
Date
());
relation
.
setUpdatedDate
(
new
Date
());
userRoleRelationMapper
.
updateByPrimaryKeySelective
(
relation
);
userRoleRelationMapper
.
updateByPrimaryKeySelective
(
relation
);
}
}
...
@@ -1040,12 +1060,14 @@ public class UserService {
...
@@ -1040,12 +1060,14 @@ public class UserService {
.
setRoleId
(
simpleAddUser
.
getRoleId
())
.
setRoleId
(
simpleAddUser
.
getRoleId
())
.
setPassword
(
simpleAddUser
.
getPassword
())
.
setPassword
(
simpleAddUser
.
getPassword
())
.
setPhoneNumber
(
simpleAddUser
.
getPhoneNum
())
.
setPhoneNumber
(
simpleAddUser
.
getPhoneNum
())
.
setEnableStatus
(
SysConstants
.
EnableStatus
.
enable
.
getCode
());
.
setEnableStatus
(
SysConstants
.
EnableStatus
.
enable
.
getCode
())
.
setTenantId
(
simpleAddUser
.
getTenantId
());
log
.
info
(
"账号:{}"
,
JSONUtil
.
toJsonStr
(
userBO
));
log
.
info
(
"账号:{}"
,
JSONUtil
.
toJsonStr
(
userBO
));
if
(
user
!=
null
)
{
if
(
user
!=
null
)
{
editUser
(
userBO
);
userBO
.
setId
(
user
.
getId
());
editCommonUser
(
userBO
,
simpleAddUser
.
getCreateId
());
}
else
{
}
else
{
add
User
(
userBO
);
add
CommonUser
(
userBO
,
simpleAddUser
.
getCreateId
()
);
}
}
cn
.
com
.
glsx
.
usercenter
.
api
.
dto
.
response
.
User
userDto
=
null
;
cn
.
com
.
glsx
.
usercenter
.
api
.
dto
.
response
.
User
userDto
=
null
;
...
...
src/test/java/cn/com/glsx/usercenter/modul/ApiUserControllerTest.java
View file @
4693a5d
...
@@ -29,7 +29,7 @@ public class ApiUserControllerTest {
...
@@ -29,7 +29,7 @@ public class ApiUserControllerTest {
@Before
@Before
public
void
runBeforeTestMethod
()
{
public
void
runBeforeTestMethod
()
{
SyntheticUser
user
=
new
SyntheticUser
();
/*
SyntheticUser user = new SyntheticUser();
user.setUserId(8160L);
user.setUserId(8160L);
user.setUsername("仲利国际租赁有限公司");
user.setUsername("仲利国际租赁有限公司");
user.setIsSupperAdmin(false);
user.setIsSupperAdmin(false);
...
@@ -51,19 +51,20 @@ public class ApiUserControllerTest {
...
@@ -51,19 +51,20 @@ public class ApiUserControllerTest {
role.setRoleName("仲利国际租赁有限公司");
role.setRoleName("仲利国际租赁有限公司");
roleList.add(role);
roleList.add(role);
user.setRoles(roleList);
user.setRoles(roleList);
ShieldContextHolder
.
setUser
(
user
);
ShieldContextHolder.setUser(user);
*/
}
}
@Test
@Test
public
void
test
()
{
public
void
test
()
{
SimpleAddUser
simpleAddUser
=
new
SimpleAddUser
();
SimpleAddUser
simpleAddUser
=
new
SimpleAddUser
();
simpleAddUser
.
setAccount
(
"wangxw1000000
1
"
);
simpleAddUser
.
setAccount
(
"wangxw1000000
3
"
);
simpleAddUser
.
setUserName
(
"xinwei1000
1
"
);
simpleAddUser
.
setUserName
(
"xinwei1000
3
"
);
simpleAddUser
.
setDepartmentId
(
4808L
);
simpleAddUser
.
setDepartmentId
(
4808L
);
simpleAddUser
.
setRoleId
(
81L
);
simpleAddUser
.
setRoleId
(
81L
);
simpleAddUser
.
setPassword
(
"ABC123"
);
simpleAddUser
.
setPassword
(
"ABC123"
);
simpleAddUser
.
setPhoneNum
(
"13800001001"
);
simpleAddUser
.
setPhoneNum
(
"13800001001"
);
simpleAddUser
.
setTenantId
(
86L
);
simpleAddUser
.
setTenantId
(
86L
);
simpleAddUser
.
setCreateId
(
8160L
);
apiUserController
.
addSimpleUser
(
simpleAddUser
);
apiUserController
.
addSimpleUser
(
simpleAddUser
);
}
}
...
...
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