Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
sample-form-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
赵啸非
sample-form-platform
Commits
c2a132e8
Commit
c2a132e8
authored
Nov 15, 2023
by
赵啸非
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
更新用户同步逻辑
parent
a0640cae
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
87 additions
and
300 deletions
+87
-300
sample-form-manager/src/main/java/com/mortals/xhx/base/system/user/model/UserEntity.java
...va/com/mortals/xhx/base/system/user/model/UserEntity.java
+9
-2
sample-form-manager/src/main/java/com/mortals/xhx/base/system/user/model/UserEntityExt.java
...com/mortals/xhx/base/system/user/model/UserEntityExt.java
+0
-1
sample-form-manager/src/main/java/com/mortals/xhx/base/system/user/model/vo/UserVo.java
...ava/com/mortals/xhx/base/system/user/model/vo/UserVo.java
+44
-0
sample-form-manager/src/main/java/com/mortals/xhx/base/system/user/service/UserService.java
...com/mortals/xhx/base/system/user/service/UserService.java
+2
-70
sample-form-manager/src/main/java/com/mortals/xhx/base/system/user/service/impl/UserServiceImpl.java
...ls/xhx/base/system/user/service/impl/UserServiceImpl.java
+26
-199
sample-form-manager/src/main/java/com/mortals/xhx/base/system/user/web/UserController.java
.../com/mortals/xhx/base/system/user/web/UserController.java
+6
-28
No files found.
sample-form-manager/src/main/java/com/mortals/xhx/base/system/user/model/UserEntity.java
View file @
c2a132e8
...
...
@@ -6,13 +6,14 @@ import java.util.Objects;
import
com.mortals.framework.ap.SysConstains
;
import
com.mortals.framework.model.BaseEntityLong
;
import
com.mortals.framework.service.IUser
;
import
com.mortals.xhx.base.system.user.model.vo.UserVo
;
/**
*
* Description:User
* date: 2021-9-26 16:11:48
*/
public
class
UserEntity
extends
User
EntityExt
implements
IUser
{
public
class
UserEntity
extends
User
Vo
implements
IUser
{
private
static
final
long
serialVersionUID
=
1632643908537L
;
...
...
@@ -126,6 +127,8 @@ public class UserEntity extends UserEntityExt implements IUser {
*/
private
String
lastModPwdAddr
;
private
String
siteIds
;
public
UserEntity
(){
}
...
...
@@ -330,7 +333,7 @@ public class UserEntity extends UserEntityExt implements IUser {
@Override
public
String
getSiteIds
()
{
return
super
.
getSiteIds
()
;
return
this
.
siteIds
;
}
@Override
...
...
@@ -338,6 +341,10 @@ public class UserEntity extends UserEntityExt implements IUser {
return
null
;
}
public
void
setSiteIds
(
String
siteIds
)
{
this
.
siteIds
=
siteIds
;
}
/**
* 设置 站点id
* @param siteId
...
...
sample-form-manager/src/main/java/com/mortals/xhx/base/system/user/model/UserEntityExt.java
View file @
c2a132e8
...
...
@@ -30,7 +30,6 @@ public class UserEntityExt extends BaseEntityLong {
private
Long
expireTime
;
private
String
siteName
;
private
List
<
Long
>
roleIds
;
private
String
siteCode
;
private
String
oldPassword
;
...
...
sample-form-manager/src/main/java/com/mortals/xhx/base/system/user/model/vo/UserVo.java
0 → 100644
View file @
c2a132e8
package
com.mortals.xhx.base.system.user.model.vo
;
import
com.mortals.framework.model.BaseEntityLong
;
import
lombok.Data
;
/**
* 用户信息业务视图对象
*
* @author zxfei
* @date 2022-07-05
*/
@Data
public
class
UserVo
extends
BaseEntityLong
{
/**
* 站点名称
*/
private
String
siteName
;
private
String
roleIds
;
/**
* 唯一标识
*/
private
String
token
;
/**
* 菜单栏
*/
private
String
menuUrl
;
/**
* 登录时间
*/
private
Long
loginTime
;
/**
* 过期时间
*/
private
Long
expireTime
;
private
String
oldPassword
;
private
String
newPassword
;
private
String
siteIds
;
}
\ No newline at end of file
sample-form-manager/src/main/java/com/mortals/xhx/base/system/user/service/UserService.java
View file @
c2a132e8
...
...
@@ -31,35 +31,7 @@ import java.util.Set;
*/
public
interface
UserService
extends
ICRUDCacheService
<
UserEntity
,
Long
>
{
/**
* 用户登录
*
* @param loginName 登录用户名
* @param password 登录密码
* @param loginIp 登录IP
* @return
* @throws AppException
*/
public
UserEntity
doLogin
(
String
loginName
,
String
password
,
String
loginIp
)
throws
AppException
;
/**
* 校验用户名与密码是否正确
*
* @param loginName
* @param password
* @return
* @throws AppException
*/
public
UserEntity
doCheckUser
(
String
loginName
,
String
password
)
throws
AppException
;
/**
* 检查用户是否存在
*
* @param loginName 登录用户名
* @param userId 密码
* @return
*/
public
boolean
existUser
(
String
loginName
,
Long
userId
)
throws
AppException
;
/**
* 通过登录用户获取菜单功能权限
...
...
@@ -67,7 +39,7 @@ public interface UserService extends ICRUDCacheService<UserEntity,Long> {
* @param user
* @return
*/
public
List
<
MenuEntity
>
findOutlookBarList
(
IUser
user
);
List
<
MenuEntity
>
findOutlookBarList
(
IUser
user
);
/**
* 查询用户所有有权限的菜单ID
...
...
@@ -75,47 +47,7 @@ public interface UserService extends ICRUDCacheService<UserEntity,Long> {
* @param userEntity
* @return
*/
public
Set
<
Long
>
findAllAuthIds
(
UserEntity
userEntity
)
throws
AppException
;
/**
* 查询用户记录
*
* @param platformId
* @param params
* @param currPage
* @param prePageResult
* @return
* @throws AppException
*/
public
Result
<
UserEntity
>
find
(
Long
platformId
,
UserEntity
params
,
int
currPage
,
int
prePageResult
)
throws
AppException
;
/**
* 为客户创建用户
*
* @param currUser 当前用户
* @param customerId 客户ID
* @param customerName 客户名称
* @param loginName
* @param password
* @param userName
* @param mobile
* @return
* @throws AppException
*/
public
UserEntity
createUser
(
IUser
currUser
,
Long
customerId
,
String
customerName
,
String
loginName
,
String
password
,
String
userName
,
String
mobile
)
throws
AppException
;
/**
* 用户修改密码
*
* @param loginName
* @param oldPwd
* @param newPwd
* @return
* @throws AppException
*/
public
boolean
updateUserPwd
(
String
loginName
,
String
oldPwd
,
String
newPwd
)
throws
AppException
;
Set
<
Long
>
findAllAuthIds
(
UserEntity
userEntity
)
throws
AppException
;
Rest
<
Void
>
refreshUser
();
...
...
sample-form-manager/src/main/java/com/mortals/xhx/base/system/user/service/impl/UserServiceImpl.java
View file @
c2a132e8
...
...
@@ -26,6 +26,7 @@ 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
;
...
...
@@ -79,146 +80,36 @@ public class UserServiceImpl extends AbstractCRUDCacheServiceImpl<UserDao, UserE
}
private
void
doHandlerUser
(
UserEntity
entity
)
throws
AppException
{
if
(
StringUtils
.
isNotEmpty
(
entity
.
getLoginPwd
()))
{
try
{
entity
.
setLoginPwd
(
SecurityUtil
.
md5DoubleEncoding
(
entity
.
getLoginPwd
()));
}
catch
(
Exception
e
)
{
throw
new
AppException
(
"密码转换异常"
);
}
}
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
{
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
(
"你没有权限执行该操作"
);
}
this
.
doHandlerUser
(
entity
);
updateUserRole
(
entity
);
}
@Override
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
);
}
updateUserRole
(
entity
);
}
@Override
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
);
}
@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
);
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
void
findAfter
(
UserEntity
params
,
PageInfo
pageInfo
,
Context
context
,
List
<
UserEntity
>
list
)
throws
AppException
{
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
);
});
//List<RoleUserEntity> roleUserEntityList =
}
}
public
UserEntity
findByLoginName
(
String
loginName
)
{
UserQuery
params
=
new
UserQuery
();
params
.
setLoginName
(
loginName
);
List
<
UserEntity
>
userList
=
super
.
dao
.
getList
(
params
);
if
(
userList
!=
null
&&
userList
.
size
()
>
0
)
{
return
userList
.
get
(
0
);
}
return
null
;
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
();
}
@Override
public
UserEntity
doLogin
(
String
loginName
,
String
password
,
String
loginIp
)
throws
AppException
{
UserEntity
sysUser
=
this
.
findByLoginName
(
loginName
);
if
(
sysUser
==
null
||
!
sysUser
.
getLoginName
().
equals
(
loginName
))
{
throw
new
AppException
(
"用户名不存在!"
);
}
try
{
if
(!
sysUser
.
getLoginPwd
().
equals
(
SecurityUtil
.
md5DoubleEncoding
(
password
)))
{
throw
new
AppException
(
"登录密码错误!"
);
}
}
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
;
}
@Override
public
UserEntity
doCheckUser
(
String
loginName
,
String
password
)
throws
AppException
{
UserEntity
sysUser
=
this
.
findByLoginName
(
loginName
);
if
(
sysUser
==
null
||
!
sysUser
.
getLoginName
().
equals
(
loginName
))
{
return
null
;
}
try
{
if
(!
sysUser
.
getLoginPwd
().
equals
(
SecurityUtil
.
md5DoubleEncoding
(
password
)))
{
return
null
;
}
}
catch
(
Exception
e
)
{
return
null
;
}
return
sysUser
;
}
@Override
public
Set
<
Long
>
findAllAuthIds
(
UserEntity
userEntity
)
throws
AppException
{
...
...
@@ -285,79 +176,6 @@ public class UserServiceImpl extends AbstractCRUDCacheServiceImpl<UserDao, UserE
return
outlookBar
;
}
@Override
public
Result
<
UserEntity
>
find
(
Long
platformId
,
UserEntity
params
,
int
currPage
,
int
prePageResult
)
throws
AppException
{
PageInfo
pageInfo
=
new
PageInfo
(
prePageResult
);
pageInfo
.
setCurrPage
(
currPage
);
return
super
.
find
(
params
,
pageInfo
,
null
);
}
@Override
public
UserEntity
createUser
(
IUser
currUser
,
Long
customerId
,
String
customerName
,
String
loginName
,
String
password
,
String
userName
,
String
mobile
)
throws
AppException
{
try
{
UserEntity
entity
=
new
UserEntity
();
entity
.
initAttrValue
();
entity
.
setLoginName
(
loginName
);
entity
.
setRealName
(
userName
);
entity
.
setCustomerId
(
customerId
);
entity
.
setLoginPwd
(
password
);
entity
.
setMobile
(
mobile
);
entity
.
setUserType
(
UserType
.
CUSTOMER
.
getValue
());
entity
.
setCreateTime
(
new
Date
());
if
(
currUser
!=
null
)
{
entity
.
setCreateUser
(
currUser
.
getLoginName
());
entity
.
setCreateUserName
(
currUser
.
getRealName
());
}
this
.
doHandlerUser
(
entity
);
dao
.
insert
(
entity
);
return
entity
;
}
catch
(
Exception
e
)
{
log
.
error
(
"给客户创建用户异常-->customerId:"
+
customerId
+
",customerName:"
+
customerName
+
",loginName:"
+
loginName
+
"-->原因:"
+
e
.
getMessage
());
return
null
;
}
}
@Override
public
boolean
existUser
(
String
loginName
,
Long
userId
)
throws
AppException
{
UserEntity
sysUser
=
this
.
findByLoginName
(
loginName
);
boolean
bRet
=
false
;
if
(
sysUser
!=
null
)
{
if
(
userId
==
null
||
userId
==
0
||
userId
.
longValue
()
!=
sysUser
.
getId
().
longValue
())
{
bRet
=
true
;
}
}
return
bRet
;
}
@Override
public
boolean
updateUserPwd
(
String
loginName
,
String
oldPwd
,
String
newPwd
)
throws
AppException
{
UserEntity
sysUser
=
this
.
findByLoginName
(
loginName
);
if
(
sysUser
==
null
||
!
sysUser
.
getLoginName
().
equals
(
loginName
))
{
throw
new
AppException
(
"帐号错误!"
);
}
try
{
if
(!
sysUser
.
getLoginPwd
().
equals
(
SecurityUtil
.
md5DoubleEncoding
(
oldPwd
)))
{
throw
new
AppException
(
"原始密码错误!"
);
}
}
catch
(
Exception
e
)
{
throw
new
AppException
(
"密码验认出错!"
,
e
);
}
try
{
sysUser
.
setLoginPwd
(
SecurityUtil
.
md5DoubleEncoding
(
newPwd
));
sysUser
.
setLoginPwd3
(
sysUser
.
getLoginPwd2
());
sysUser
.
setLoginPwd2
(
sysUser
.
getLoginPwd1
());
sysUser
.
setLoginPwd1
(
sysUser
.
getLoginPwd
());
sysUser
.
setLastModPwdTime
(
new
Date
());
}
catch
(
Exception
e
)
{
throw
new
AppException
(
"密码转换异常!"
,
e
);
}
dao
.
update
(
sysUser
);
return
true
;
}
@Override
public
Rest
<
Void
>
refreshUser
()
{
UserPdu
userPdu
=
new
UserPdu
();
...
...
@@ -420,6 +238,15 @@ public class UserServiceImpl extends AbstractCRUDCacheServiceImpl<UserDao, UserE
return
Rest
.
ok
();
}
@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
);
}
@Override
public
UserDao
getUserDao
()
{
...
...
sample-form-manager/src/main/java/com/mortals/xhx/base/system/user/web/UserController.java
View file @
c2a132e8
...
...
@@ -21,7 +21,10 @@ import com.mortals.framework.common.Rest;
import
com.mortals.framework.service.IUser
;
import
com.mortals.framework.web.BaseCRUDJsonBodyMappingController
;
import
com.mortals.xhx.base.system.role.model.RoleEntity
;
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.RoleService
;
import
com.mortals.xhx.base.system.role.service.RoleUserService
;
import
com.mortals.xhx.common.code.UserStatus
;
import
com.mortals.framework.common.IBaseEnum
;
import
com.mortals.framework.common.code.UserType
;
...
...
@@ -55,6 +58,9 @@ public class UserController extends BaseCRUDJsonBodyMappingController<UserServic
@Autowired
private
RoleService
roleService
;
@Autowired
private
RoleUserService
roleUserService
;
public
UserController
()
{
super
.
setModuleDesc
(
"用户信息"
);
}
...
...
@@ -69,34 +75,6 @@ public class UserController extends BaseCRUDJsonBodyMappingController<UserServic
super
.
init
(
model
,
context
);
}
@Override
protected
int
editAfter
(
Long
id
,
Map
<
String
,
Object
>
model
,
UserEntity
entity
,
Context
context
)
throws
AppException
{
entity
.
setLoginPwd
(
null
);
entity
.
setLoginPwd1
(
null
);
entity
.
setLoginPwd2
(
null
);
entity
.
setLoginPwd3
(
null
);
return
1
;
}
@RequestMapping
(
value
=
"change/password"
,
method
=
RequestMethod
.
POST
)
public
String
changePassword
(
@RequestBody
UserEntity
entity
)
{
IUser
user
=
this
.
getCurUser
();
if
(
user
==
null
){
return
this
.
createFailJsonResp
(
"请先登录"
);
}
JSONObject
ret
=
new
JSONObject
();
try
{
service
.
updateUserPwd
(
super
.
getCurUser
().
getLoginName
(),
entity
.
getOldPassword
(),
entity
.
getNewPassword
());
ret
.
put
(
KEY_RESULT_CODE
,
VALUE_RESULT_SUCCESS
);
ret
.
put
(
KEY_RESULT_MSG
,
"密码修改成功!"
);
}
catch
(
Exception
e
)
{
ret
.
put
(
KEY_RESULT_CODE
,
VALUE_RESULT_FAILURE
);
ret
.
put
(
KEY_RESULT_MSG
,
super
.
convertException
(
e
));
}
return
ret
.
toJSONString
();
}
@PostMapping
({
"refreshUser"
})
@UnAuth
...
...
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