Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
Y
yifu-mvp
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
fangxinjiang
yifu-mvp
Commits
dba2e82e
Commit
dba2e82e
authored
May 06, 2024
by
hongguangwu
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'origin/MVP1.6.3' into MVP1.6.3
parents
b66d84f4
f9f79002
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
263 additions
and
3 deletions
+263
-3
PersonVo.java
.../yifu/cloud/plus/v1/yifu/common/ldap/entity/PersonVo.java
+6
-0
UserController.java
...u/cloud/plus/v1/yifu/admin/controller/UserController.java
+14
-0
SysUserService.java
...yifu/cloud/plus/v1/yifu/admin/service/SysUserService.java
+7
-0
SysUserServiceImpl.java
...d/plus/v1/yifu/admin/service/impl/SysUserServiceImpl.java
+214
-1
application.yml
yifu-upms/yifu-upms-biz/src/main/resources/application.yml
+4
-0
SysUserMapper.xml
...yifu-upms-biz/src/main/resources/mapper/SysUserMapper.xml
+18
-2
No files found.
yifu-common/yifu-common-ldap/src/main/java/com/yifu/cloud/plus/v1/yifu/common/ldap/entity/PersonVo.java
View file @
dba2e82e
...
...
@@ -85,6 +85,12 @@ public class PersonVo {
@Attribute
protected
Date
updateTime
;
/**
* 部门id
*/
@Attribute
protected
Long
deptId
;
/**
* 状态
*/
...
...
yifu-upms/yifu-upms-biz/src/main/java/com/yifu/cloud/plus/v1/yifu/admin/controller/UserController.java
View file @
dba2e82e
...
...
@@ -16,6 +16,7 @@
package
com
.
yifu
.
cloud
.
plus
.
v1
.
yifu
.
admin
.
controller
;
import
com.alibaba.fastjson.JSONObject
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
import
com.baomidou.mybatisplus.core.metadata.IPage
;
import
com.baomidou.mybatisplus.core.toolkit.Wrappers
;
...
...
@@ -45,6 +46,7 @@ import org.springframework.security.access.prepost.PreAuthorize;
import
org.springframework.validation.BindingResult
;
import
org.springframework.web.bind.annotation.*
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.validation.Valid
;
import
java.security.NoSuchAlgorithmException
;
import
java.util.ArrayList
;
...
...
@@ -493,4 +495,16 @@ public class UserController {
UserInfo
info
=
userService
.
getUserInfo
(
user
);
return
info
;
}
/**
* 从ldap实时更新用户和部门
*
* @return R
*/
@SysLog
(
"从ldap实时更新用户和部门"
)
@PostMapping
(
"/updateUserAndDept"
)
public
R
updateUserAndDept
(
HttpServletRequest
request
,
@RequestBody
JSONObject
json
)
{
return
R
.
ok
(
userService
.
updateUserAndDept
(
request
,
json
));
}
}
yifu-upms/yifu-upms-biz/src/main/java/com/yifu/cloud/plus/v1/yifu/admin/service/SysUserService.java
View file @
dba2e82e
...
...
@@ -16,6 +16,7 @@
package
com
.
yifu
.
cloud
.
plus
.
v1
.
yifu
.
admin
.
service
;
import
com.alibaba.fastjson.JSONObject
;
import
com.baomidou.mybatisplus.core.metadata.IPage
;
import
com.baomidou.mybatisplus.extension.plugins.pagination.Page
;
import
com.baomidou.mybatisplus.extension.service.IService
;
...
...
@@ -29,6 +30,7 @@ import com.yifu.cloud.plus.v1.yifu.admin.api.vo.UserVO;
import
com.yifu.cloud.plus.v1.yifu.common.core.util.R
;
import
org.springframework.validation.BindingResult
;
import
javax.servlet.http.HttpServletRequest
;
import
java.security.NoSuchAlgorithmException
;
import
java.util.List
;
import
java.util.Set
;
...
...
@@ -178,4 +180,9 @@ public interface SysUserService extends IService<SysUser> {
**/
void
ldapLogin
(
String
username
,
String
password
,
SysUser
user
);
/**
* 从ldap实时更新用户和部门
* @return R
*/
R
updateUserAndDept
(
HttpServletRequest
request
,
JSONObject
json
);
}
yifu-upms/yifu-upms-biz/src/main/java/com/yifu/cloud/plus/v1/yifu/admin/service/impl/SysUserServiceImpl.java
View file @
dba2e82e
...
...
@@ -19,7 +19,9 @@ package com.yifu.cloud.plus.v1.yifu.admin.service.impl;
import
cn.hutool.core.collection.CollUtil
;
import
cn.hutool.core.util.ArrayUtil
;
import
cn.hutool.core.util.StrUtil
;
import
com.alibaba.fastjson.JSONArray
;
import
com.alibaba.fastjson.JSONObject
;
import
com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper
;
import
com.baomidou.mybatisplus.core.metadata.IPage
;
import
com.baomidou.mybatisplus.core.toolkit.StringUtils
;
import
com.baomidou.mybatisplus.core.toolkit.Wrappers
;
...
...
@@ -51,6 +53,7 @@ import com.yifu.cloud.plus.v1.yifu.common.ldap.util.LdapUtil;
import
lombok.RequiredArgsConstructor
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.BeanUtils
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.cache.annotation.CacheEvict
;
import
org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder
;
import
org.springframework.security.crypto.password.PasswordEncoder
;
...
...
@@ -59,6 +62,7 @@ import org.springframework.transaction.annotation.Transactional;
import
org.springframework.util.Assert
;
import
org.springframework.validation.BindingResult
;
import
javax.servlet.http.HttpServletRequest
;
import
java.security.NoSuchAlgorithmException
;
import
java.time.LocalDateTime
;
import
java.util.*
;
...
...
@@ -96,6 +100,12 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
private
final
PermissionDaprUtil
permissionDaprUtil
;
@Value
(
"${hrms.id}"
)
private
String
hcmId
;
@Value
(
"${hrms.secret}"
)
private
String
hcmSecret
;
/**
* 保存用户信息
* @param userDto DTO 对象
...
...
@@ -490,8 +500,20 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
try
{
List
<
PersonVo
>
list
=
ldapUtil
.
getAllPersons
();
if
(
null
!=
list
)
{
List
<
SysUser
>
listUser
=
this
.
list
(
Wrappers
.<
SysUser
>
query
().
lambda
().
eq
(
SysUser:
:
getDelFlag
,
CommonConstants
.
STATUS_NORMAL
));
List
<
SysUser
>
listUser
=
this
.
list
(
Wrappers
.<
SysUser
>
query
().
lambda
()
.
eq
(
SysUser:
:
getType
,
CommonConstants
.
STATUS_NORMAL
)
.
eq
(
SysUser:
:
getDelFlag
,
CommonConstants
.
STATUS_NORMAL
));
List
<
String
>
list1
=
listUser
.
stream
().
map
(
SysUser:
:
getUsername
).
collect
(
Collectors
.
toList
());
//筛选出不存在的用户重置为不可用
List
<
String
>
list2
=
list
.
stream
().
map
(
PersonVo:
:
getUid
).
collect
(
Collectors
.
toList
());
List
<
String
>
collect
=
list1
.
stream
().
filter
(
s
->
!
list2
.
contains
(
s
)
).
collect
(
Collectors
.
toList
());
log
.
info
(
"要重置为不可用的用户列表:"
+
collect
);
LambdaUpdateWrapper
<
SysUser
>
settleUpdate
=
new
LambdaUpdateWrapper
<>();
settleUpdate
.
set
(
SysUser:
:
getDelFlag
,
CommonConstants
.
ONE_STRING
);
settleUpdate
.
in
(
SysUser:
:
getUsername
,
collect
);
this
.
update
(
settleUpdate
);
List
<
PersonVo
>
updateList
=
new
ArrayList
<>();
List
<
PersonVo
>
insertList
=
new
ArrayList
<>();
for
(
PersonVo
personVo
:
list
)
{
...
...
@@ -709,6 +731,197 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
return
this
.
updateById
(
sysUser
);
}
/**
* 从ldap实时更新用户和部门
* @return R
*/
@Override
public
R
updateUserAndDept
(
HttpServletRequest
request
,
JSONObject
json
)
{
//权限验证
String
appId
=
request
.
getHeader
(
"HRBS-APP-ID"
);
String
appSecret
=
request
.
getHeader
(
"HRBS-APP-SECRET"
);
if
(
Common
.
isEmpty
(
appId
)
||
Common
.
isEmpty
(
appSecret
)){
return
R
.
failed
(
"操作失败,权限标识错误!"
);
}
if
(!
hcmId
.
equals
(
appId
)
||
!
hcmSecret
.
equals
(
appSecret
)
){
return
R
.
failed
(
"操作失败,无权限!"
);
}
if
(
Common
.
isEmpty
(
json
))
{
return
R
.
failed
(
"传参不能为空"
);
}
boolean
isAll
=
(
boolean
)
json
.
get
(
"isAll"
);
String
dataType
=
json
.
get
(
"isAll"
).
toString
();
//获取人员和部门信息
JSONArray
updateParamsArr
=
json
.
getJSONArray
(
"data"
);
if
(
Common
.
isEmpty
(
updateParamsArr
))
{
return
R
.
failed
(
"传参不能为空"
);
}
//全量更新直接调用定时任务接口
if
(
isAll
)
{
this
.
updateByLdap
();
//用户同步操作
}
else
if
(
"user"
.
equals
(
dataType
))
{
//更新或者新增用户信息
updateOrSaveUser
(
updateParamsArr
);
}
else
{
//更新或者新增部门信息
updateOrSaveDept
(
updateParamsArr
);
}
return
R
.
ok
();
}
/**
* 更新或者新增用户信息
* @return
*/
private
void
updateOrSaveUser
(
JSONArray
updateParamsArr
)
{
List
<
SysUser
>
listUser
=
this
.
list
(
Wrappers
.<
SysUser
>
query
().
lambda
().
eq
(
SysUser:
:
getDelFlag
,
CommonConstants
.
STATUS_NORMAL
));
List
<
String
>
list1
=
listUser
.
stream
().
map
(
SysUser:
:
getUsername
).
collect
(
Collectors
.
toList
());
List
<
PersonVo
>
updateList
=
new
ArrayList
<>();
List
<
PersonVo
>
insertList
=
new
ArrayList
<>();
SysDept
sysDeptCount
;
List
<
String
>
saveDnList
;
JSONObject
updateJson
;
for
(
int
i
=
0
;
i
<
updateParamsArr
.
size
();
i
++)
{
updateJson
=
updateParamsArr
.
getJSONObject
(
i
);
PersonVo
personVo
=
new
PersonVo
();
personVo
.
setUid
(
updateJson
.
get
(
"uid"
)==
null
?
""
:
updateJson
.
getString
(
"uid"
));
personVo
.
setPersonName
(
updateJson
.
get
(
"cn"
)==
null
?
""
:
updateJson
.
getString
(
"cn"
));
personVo
.
setTelephoneNumber
(
updateJson
.
get
(
"telephoneNumber"
)==
null
?
""
:
updateJson
.
getString
(
"telephoneNumber"
));
personVo
.
setEmail
(
updateJson
.
get
(
"mail"
)==
null
?
""
:
updateJson
.
getString
(
"mail"
));
String
dn
=
updateJson
.
get
(
"dn"
)==
null
?
""
:
updateJson
.
getString
(
"dn"
);
log
.
info
(
"更新人员信息:"
+
dn
+
"_"
+
personVo
.
getUid
());
if
(
dn
.
contains
(
"uid"
))
{
dn
=
dn
.
substring
(
dn
.
indexOf
(
","
,
1
)
+
1
);
}
saveDnList
=
Arrays
.
stream
(
dn
.
split
(
","
)).
filter
(
e
->
(
e
.
contains
(
"ou="
)
&&
!
e
.
equals
(
"ou=wanxin"
))).
collect
(
Collectors
.
toList
());
String
deptName
=
saveDnList
.
get
(
0
).
replace
(
"ou="
,
""
);
personVo
.
setDeptName
(
deptName
);
sysDeptCount
=
sysDeptMapper
.
selectDeptDn
(
dn
);
if
(
Common
.
isEmpty
(
sysDeptCount
))
{
continue
;
}
else
{
personVo
.
setDeptName
(
deptName
);
personVo
.
setDeptId
(
sysDeptCount
.
getDeptId
());
}
if
(
list1
.
stream
().
anyMatch
(
e
->
e
.
equals
(
personVo
.
getUid
())))
{
updateList
.
add
(
personVo
);
}
else
{
//新增用户赋初始密码
personVo
.
setPassword
(
ENCODER
.
encode
(
CommonConstants
.
DEFAULT_PASSWORD
));
insertList
.
add
(
personVo
);
}
}
if
(!
updateList
.
isEmpty
())
{
baseMapper
.
batchUpdateUser
(
updateList
);
}
if
(!
insertList
.
isEmpty
())
{
baseMapper
.
batchInsertUser
(
insertList
);
//新增用户的初始化角色
JSONObject
jsonObject
;
for
(
PersonVo
personVo
:
insertList
)
{
if
(
Common
.
isNotNull
(
personVo
.
getRoleIds
()))
{
SysUser
user
=
this
.
getOne
(
Wrappers
.<
SysUser
>
query
().
lambda
().
eq
(
SysUser:
:
getUsername
,
personVo
.
getUid
()).
last
(
CommonConstants
.
LAST_ONE_SQL
));
jsonObject
=
JSONObject
.
parseObject
(
personVo
.
getRoleIds
());
//获取mvp用户的角色
String
userRole
=
jsonObject
.
get
(
"hro"
)==
null
?
""
:
jsonObject
.
getString
(
"hro"
);
if
(!
userRole
.
isEmpty
())
{
Common
.
getList
(
userRole
).
stream
().
map
(
roleId
->
{
SysUserRole
role
=
new
SysUserRole
();
role
.
setUserId
(
user
.
getUserId
());
role
.
setRoleId
(
Long
.
valueOf
(
roleId
));
return
role
;
}).
forEach
(
sysUserRoleMapper:
:
insert
);
}
//获取ekp用户的角色
String
ekpUserRole
=
jsonObject
.
get
(
"ekp"
)==
null
?
""
:
jsonObject
.
getString
(
"ekp"
);
if
(!
ekpUserRole
.
isEmpty
())
{
for
(
String
roleId
:
Common
.
getList
(
ekpUserRole
))
{
HcmInitRoleInfoVo
vo
=
new
HcmInitRoleInfoVo
();
vo
.
setLoginName
(
user
.
getUsername
());
vo
.
setRoleId
(
roleId
);
permissionDaprUtil
.
saveSysUserRole
(
vo
);
}
}
}
}
}
}
/**
* 更新或者新增部门信息
* @return
*/
private
void
updateOrSaveDept
(
JSONArray
updateParamsArr
)
{
SysDept
sysDeptCount
;
List
<
String
>
saveDnList
;
JSONObject
updateJson
;
for
(
int
i
=
0
;
i
<
updateParamsArr
.
size
();
i
++)
{
updateJson
=
updateParamsArr
.
getJSONObject
(
i
);
String
dn
=
updateJson
.
get
(
"dn"
)==
null
?
""
:
updateJson
.
getString
(
"dn"
);
String
deptId
=
updateJson
.
get
(
"x-ouid"
)==
null
?
""
:
updateJson
.
getString
(
"x-ouid"
);
String
deptName
=
updateJson
.
get
(
"ou"
)==
null
?
""
:
updateJson
.
getString
(
"ou"
);
log
.
info
(
"更新部门信息:"
+
dn
);
saveDnList
=
Arrays
.
stream
(
dn
.
split
(
","
)).
filter
(
e
->
(
e
.
contains
(
"ou="
)
&&
!
e
.
equals
(
"ou=wanxin"
))).
collect
(
Collectors
.
toList
());
int
size
=
saveDnList
.
size
();
if
(
size
==
1
)
{
SysDept
sysDept
=
sysDeptMapper
.
selectDeptDn
(
dn
);
if
(
null
==
sysDept
)
{
SysDept
ins
=
sysDeptMapper
.
selectCountId
(
Long
.
valueOf
(
deptId
));
if
(
Common
.
isNotNull
(
ins
))
{
ins
.
setName
(
deptName
);
ins
.
setDeptDn
(
dn
);
sysDeptMapper
.
updateDeptById
(
ins
);
}
else
{
SysDept
insertSysDept
=
new
SysDept
();
insertSysDept
.
setName
(
deptName
);
insertSysDept
.
setParentId
(
0L
);
insertSysDept
.
setDeptDn
(
dn
);
if
(
Common
.
isNotNull
(
deptId
))
{
insertSysDept
.
setDeptId
(
Long
.
valueOf
(
deptId
));
}
insertSysDept
.
setDelFlag
(
CommonConstants
.
ZERO_STRING
);
sysDeptMapper
.
insert
(
insertSysDept
);
}
}
else
{
sysDept
.
setName
(
deptName
);
sysDeptMapper
.
updateDeptById
(
sysDept
);
}
}
else
{
SysDept
sysDept
=
sysDeptMapper
.
selectDeptDn
(
dn
.
substring
(
dn
.
indexOf
(
"ou="
,
2
),
dn
.
length
()));
if
(
null
!=
sysDept
)
{
sysDeptCount
=
sysDeptMapper
.
selectDeptDn
(
dn
);
if
(
null
==
sysDeptCount
)
{
SysDept
ins
=
sysDeptMapper
.
selectCountId
(
Long
.
valueOf
(
deptId
));
if
(
Common
.
isNotNull
(
ins
))
{
ins
.
setName
(
deptName
);
ins
.
setDeptDn
(
dn
);
ins
.
setParentId
(
sysDept
.
getDeptId
());
sysDeptMapper
.
updateDeptById
(
ins
);
}
else
{
SysDept
insertSysDept
=
new
SysDept
();
insertSysDept
.
setName
(
deptName
);
insertSysDept
.
setParentId
(
sysDept
.
getDeptId
());
insertSysDept
.
setDeptDn
(
dn
);
if
(
Common
.
isNotNull
(
deptId
))
{
insertSysDept
.
setDeptId
(
Long
.
valueOf
(
deptId
));
}
insertSysDept
.
setDelFlag
(
CommonConstants
.
ZERO_STRING
);
sysDeptMapper
.
insert
(
insertSysDept
);
}
}
else
{
sysDeptCount
.
setName
(
deptName
);
sysDeptCount
.
setDeptDn
(
dn
);
sysDeptCount
.
setParentId
(
sysDept
.
getDeptId
());
sysDeptMapper
.
updateDeptById
(
sysDeptCount
);
}
}
}
}
}
private
void
clenrUserCache
(
String
username
,
String
wxUserId
,
String
phone
){
//用户名登录用户缓存清除
if
(
Common
.
isNotNull
(
username
)){
...
...
yifu-upms/yifu-upms-biz/src/main/resources/application.yml
View file @
dba2e82e
...
...
@@ -97,3 +97,7 @@ springdoc:
-
group
:
upms
#按包路径匹配
packagesToScan
:
com.yifu.cloud.plus.v1.yifu.admin.controller
hrms
:
id
:
HRBS
secret
:
d8a3649587afe0fc2045741f84cd15221b8404f1ae5c3e9c8c301a4caba07d54
yifu-upms/yifu-upms-biz/src/main/resources/mapper/SysUserMapper.xml
View file @
dba2e82e
...
...
@@ -214,7 +214,7 @@
<insert
id=
"batchInsertUser"
parameterType=
"java.util.List"
>
insert into sys_user
(user_id,username,password,phone,email,nickname,create_time)
(user_id,username,password,phone,email,nickname,create_time
,dept_id,dept_name
)
VALUES
<foreach
collection=
"list"
item=
"item"
index=
"index"
separator=
","
>
(
...
...
@@ -224,7 +224,9 @@
#{item.telephoneNumber},
#{item.email},
#{item.personName},
now()
now(),
#{item.deptId},
#{item.deptName}
)
</foreach>
</insert>
...
...
@@ -265,6 +267,20 @@
when username=#{i.uid} then now()
</foreach>
</trim>
<trim
prefix=
"dept_id =case"
suffix=
"end,"
>
<foreach
collection=
"list"
item=
"i"
index=
"index"
>
<if
test=
"i.deptId!=null"
>
when username=#{i.userId} then #{i.deptId}
</if>
</foreach>
</trim>
<trim
prefix=
"dept_name =case"
suffix=
"end,"
>
<foreach
collection=
"list"
item=
"i"
index=
"index"
>
<if
test=
"i.deptName!=null"
>
when username=#{i.userId} then #{i.deptName}
</if>
</foreach>
</trim>
</trim>
where
<foreach
collection=
"list"
separator=
"or"
item=
"i"
index=
"index"
>
...
...
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