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
818d5f4b
Commit
818d5f4b
authored
Jun 15, 2022
by
huyuchen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
huyc ldap相关代码提交
parent
b92e4d48
Hide whitespace changes
Inline
Side-by-side
Showing
16 changed files
with
378 additions
and
1 deletion
+378
-1
pom.xml
yifu-common/pom.xml
+1
-0
CommonConstants.java
...ud.plus.v1/yifu/common/core/constant/CommonConstants.java
+3
-0
pom.xml
yifu-common/yifu-common-ldap/pom.xml
+25
-0
LdapAutoConfigue.java
...oud/plus/v1/yifu/common/ldap/config/LdapAutoConfigue.java
+15
-0
PersonVo.java
.../yifu/cloud/plus/v1/yifu/common/ldap/entity/PersonVo.java
+89
-0
PersonAttributesMapper.java
...us/v1/yifu/common/ldap/mapper/PersonAttributesMapper.java
+34
-0
LdapUtil.java
...om/yifu/cloud/plus/v1/yifu/common/ldap/util/LdapUtil.java
+50
-0
spring.factories
...-common-ldap/src/main/resources/META-INF/spring.factories
+2
-0
application.properties
...ifu-common-ldap/src/main/resources/application.properties
+4
-0
pom.xml
yifu-upms/yifu-upms-biz/pom.xml
+5
-0
DeptController.java
...u.cloud.plus.v1/yifu/admin/controller/DeptController.java
+9
-0
UserController.java
...u.cloud.plus.v1/yifu/admin/controller/UserController.java
+9
-0
SysDeptService.java
...yifu.cloud.plus.v1/yifu/admin/service/SysDeptService.java
+7
-0
SysUserService.java
...yifu.cloud.plus.v1/yifu/admin/service/SysUserService.java
+6
-0
SysDeptServiceImpl.java
...d.plus.v1/yifu/admin/service/impl/SysDeptServiceImpl.java
+79
-1
SysUserServiceImpl.java
...d.plus.v1/yifu/admin/service/impl/SysUserServiceImpl.java
+40
-0
No files found.
yifu-common/pom.xml
View file @
818d5f4b
...
@@ -41,5 +41,6 @@
...
@@ -41,5 +41,6 @@
<module>
yifu-common-test
</module>
<module>
yifu-common-test
</module>
<module>
yifu-common-dapr
</module>
<module>
yifu-common-dapr
</module>
<module>
yifu-common-swagger
</module>
<module>
yifu-common-swagger
</module>
<module>
yifu-common-ldap
</module>
</modules>
</modules>
</project>
</project>
yifu-common/yifu-common-core/src/main/java/com/yifu.cloud.plus.v1/yifu/common/core/constant/CommonConstants.java
View file @
818d5f4b
...
@@ -128,4 +128,7 @@ public interface CommonConstants {
...
@@ -128,4 +128,7 @@ public interface CommonConstants {
* hgw 2022-6-9 17:36:35
* hgw 2022-6-9 17:36:35
*/
*/
String
DOWN_LINE
=
"_"
;
String
DOWN_LINE
=
"_"
;
//空字符串
String
EMPTY_STRING
=
""
;
}
}
yifu-common/yifu-common-ldap/pom.xml
0 → 100644
View file @
818d5f4b
<?xml version="1.0" encoding="UTF-8"?>
<project
xmlns=
"http://maven.apache.org/POM/4.0.0"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<parent>
<artifactId>
yifu-common
</artifactId>
<groupId>
com.yifu.cloud.plus.v1
</groupId>
<version>
1.0.0
</version>
</parent>
<modelVersion>
4.0.0
</modelVersion>
<description>
ldap引入
</description>
<artifactId>
yifu-common-ldap
</artifactId>
<packaging>
jar
</packaging>
<dependencies>
<dependency>
<groupId>
org.springframework.ldap
</groupId>
<artifactId>
spring-ldap-core
</artifactId>
</dependency>
<dependency>
<groupId>
com.unboundid
</groupId>
<artifactId>
unboundid-ldapsdk
</artifactId>
<version>
3.2.0
</version>
</dependency>
</dependencies>
</project>
yifu-common/yifu-common-ldap/src/main/java/com/yifu/cloud/plus/v1/yifu/common/ldap/config/LdapAutoConfigue.java
0 → 100644
View file @
818d5f4b
package
com
.
yifu
.
cloud
.
plus
.
v1
.
yifu
.
common
.
ldap
.
config
;
import
com.yifu.cloud.plus.v1.yifu.common.ldap.util.LdapUtil
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
@Configuration
public
class
LdapAutoConfigue
{
@Bean
public
LdapUtil
getLdapUtils
()
{
return
new
LdapUtil
();
}
}
yifu-common/yifu-common-ldap/src/main/java/com/yifu/cloud/plus/v1/yifu/common/ldap/entity/PersonVo.java
0 → 100644
View file @
818d5f4b
package
com
.
yifu
.
cloud
.
plus
.
v1
.
yifu
.
common
.
ldap
.
entity
;
import
lombok.Data
;
import
lombok.ToString
;
import
org.springframework.ldap.odm.annotations.Attribute
;
import
org.springframework.ldap.odm.annotations.Entry
;
import
java.util.Date
;
@Data
@ToString
@Entry
(
objectClasses
=
{
"posixAccount"
,
"top"
,
"inetOrgPerson"
},
base
=
"ou=安徽皖信人力资源管理有限公司,ou=wanxin"
)
public
class
PersonVo
{
/**
* 主键
*/
@Attribute
(
name
=
"uid"
)
private
String
uid
;
/**
* 常用姓名
*/
@Attribute
(
name
=
"cn"
)
private
String
personName
;
/**
* 电话
*/
@Attribute
(
name
=
"telephoneNumber"
)
private
String
telephoneNumber
;
/**
* 邮箱
*/
@Attribute
(
name
=
"email"
)
private
String
email
;
/**
* 展示姓名
*/
@Attribute
(
name
=
"displayName"
)
private
String
displayName
;
/**
* 真实姓名
*/
@Attribute
(
name
=
"sn"
)
private
String
sn
;
/**
* 用户url
*/
@Attribute
(
name
=
"homeDirectory"
)
private
String
homeDirectory
;
/**
* 主键
*/
@Attribute
(
name
=
"ou"
)
private
String
deptName
;
/**
* 主键
*/
@Attribute
(
name
=
"userPassword"
)
private
String
password
;
/**
* 创建时间
*/
@Attribute
protected
Date
createTime
;
/**
* 更新时间
*/
@Attribute
protected
Date
updateTime
;
/**
* 状态
*/
@Attribute
protected
Integer
status
;
}
yifu-common/yifu-common-ldap/src/main/java/com/yifu/cloud/plus/v1/yifu/common/ldap/mapper/PersonAttributesMapper.java
0 → 100644
View file @
818d5f4b
package
com
.
yifu
.
cloud
.
plus
.
v1
.
yifu
.
common
.
ldap
.
mapper
;
import
com.yifu.cloud.plus.v1.yifu.common.ldap.entity.PersonVo
;
import
org.springframework.ldap.core.AttributesMapper
;
import
javax.naming.NamingException
;
import
javax.naming.directory.Attributes
;
public
class
PersonAttributesMapper
implements
AttributesMapper
<
PersonVo
>
{
@Override
public
PersonVo
mapFromAttributes
(
Attributes
attributes
)
throws
NamingException
{
PersonVo
personVo
=
new
PersonVo
();
if
(
null
!=
attributes
.
get
(
"cn"
))
{
personVo
.
setPersonName
((
String
)
attributes
.
get
(
"cn"
).
get
());
}
if
(
null
!=
attributes
.
get
(
"uid"
))
{
personVo
.
setUid
((
String
)
attributes
.
get
(
"uid"
).
get
());
}
if
(
null
!=
attributes
.
get
(
"telephoneNumber"
))
{
personVo
.
setTelephoneNumber
((
String
)
attributes
.
get
(
"telephoneNumber"
).
get
());
}
if
(
null
!=
attributes
.
get
(
"mail"
))
{
personVo
.
setEmail
((
String
)
attributes
.
get
(
"mail"
).
get
());
}
else
{
personVo
.
setEmail
(
""
);
}
if
(
null
!=
attributes
.
get
(
"ou"
))
{
personVo
.
setDeptName
((
String
)
attributes
.
get
(
"ou"
).
get
());
}
personVo
.
setPassword
((
String
)
attributes
.
get
(
"uid"
).
get
());
return
personVo
;
}
}
yifu-common/yifu-common-ldap/src/main/java/com/yifu/cloud/plus/v1/yifu/common/ldap/util/LdapUtil.java
0 → 100644
View file @
818d5f4b
package
com
.
yifu
.
cloud
.
plus
.
v1
.
yifu
.
common
.
ldap
.
util
;
import
com.unboundid.ldap.sdk.*
;
import
com.unboundid.ldap.sdk.controls.SubentriesRequestControl
;
import
com.yifu.cloud.plus.v1.yifu.common.ldap.entity.PersonVo
;
import
com.yifu.cloud.plus.v1.yifu.common.ldap.mapper.PersonAttributesMapper
;
import
lombok.extern.log4j.Log4j2
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.ldap.core.LdapTemplate
;
import
java.util.ArrayList
;
import
java.util.List
;
import
static
org
.
springframework
.
ldap
.
query
.
LdapQueryBuilder
.
query
;
@Log4j2
public
class
LdapUtil
{
@Autowired
private
LdapTemplate
ldapTemplate
;
/**
* @return List<SearchResultEntry>
* @author huyc
* @date 2022-06-14 17:56
* @description get请求获取指定对象信息
**/
public
List
<
SearchResultEntry
>
getAllPersonNamesWithTraditionalWay
()
{
List
<
SearchResultEntry
>
result
=
new
ArrayList
<
SearchResultEntry
>();
try
{
LDAPConnection
connection
=
new
LDAPConnection
(
"192.168.1.65"
,
389
,
"cn=admin,dc=worfu,dc=com"
,
"yifu123456!"
);
SearchRequest
searchRequest
=
new
SearchRequest
(
"ou=安徽皖信人力资源管理有限公司,ou=wanxin,dc=worfu,dc=com"
,
SearchScope
.
SUB
,
"(objectclass=*)"
);
searchRequest
.
addControl
(
new
SubentriesRequestControl
());
SearchResult
searchResult
=
connection
.
search
(
searchRequest
);
for
(
SearchResultEntry
entry
:
searchResult
.
getSearchEntries
())
{
result
.
add
(
entry
);
}
}
catch
(
LDAPException
e
)
{
e
.
printStackTrace
();
}
return
result
;
}
public
List
<
PersonVo
>
getAllPersons
()
{
List
<
PersonVo
>
list
=
ldapTemplate
.
search
(
query
()
.
where
(
"objectclass"
).
is
(
"posixAccount"
),
new
PersonAttributesMapper
());
return
list
;
}
}
yifu-common/yifu-common-ldap/src/main/resources/META-INF/spring.factories
0 → 100644
View file @
818d5f4b
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
com.yifu.cloud.plus.v1.yifu.common.ldap.config.LdapAutoConfigue\
yifu-common/yifu-common-ldap/src/main/resources/application.properties
0 → 100644
View file @
818d5f4b
spring.ldap.urls
=
ldap://192.168.1.65:389
spring.ldap.username
=
cn=admin,dc=worfu,dc=com
spring.ldap.password
=
yifu123456!
spring.ldap.base
=
dc=worfu,dc=com
\ No newline at end of file
yifu-upms/yifu-upms-biz/pom.xml
View file @
818d5f4b
...
@@ -65,6 +65,11 @@
...
@@ -65,6 +65,11 @@
<groupId>
com.yifu.cloud.plus.v1
</groupId>
<groupId>
com.yifu.cloud.plus.v1
</groupId>
<artifactId>
yifu-common-swagger
</artifactId>
<artifactId>
yifu-common-swagger
</artifactId>
</dependency>
</dependency>
<dependency>
<groupId>
com.yifu.cloud.plus.v1
</groupId>
<artifactId>
yifu-common-ldap
</artifactId>
<version>
1.0.0
</version>
</dependency>
<!--<dependency>
<!--<dependency>
<groupId>com.yifu.cloud.plus.v1</groupId>
<groupId>com.yifu.cloud.plus.v1</groupId>
<artifactId>yifu-common-swagger</artifactId>
<artifactId>yifu-common-swagger</artifactId>
...
...
yifu-upms/yifu-upms-biz/src/main/java/com/yifu.cloud.plus.v1/yifu/admin/controller/DeptController.java
View file @
818d5f4b
...
@@ -134,4 +134,13 @@ public class DeptController {
...
@@ -134,4 +134,13 @@ public class DeptController {
return
R
.
ok
(
sysDeptService
.
listChildDeptId
(
deptId
));
return
R
.
ok
(
sysDeptService
.
listChildDeptId
(
deptId
));
}
}
/**
* 从ldap中获取部门
* @return R
*/
@SysLog
(
"从ldap中获取部门"
)
@PostMapping
(
"/updateDept"
)
public
R
updateDeptByLdap
()
{
return
R
.
ok
(
sysDeptService
.
updateDeptByLdap
());
}
}
}
yifu-upms/yifu-upms-biz/src/main/java/com/yifu.cloud.plus.v1/yifu/admin/controller/UserController.java
View file @
818d5f4b
...
@@ -226,4 +226,13 @@ public class UserController {
...
@@ -226,4 +226,13 @@ public class UserController {
return
userService
.
importUser
(
excelVOList
,
bindingResult
);
return
userService
.
importUser
(
excelVOList
,
bindingResult
);
}
}
/**
* 从ldap中获取用户
* @return R
*/
@SysLog
(
"从ldap中获取用户"
)
@PostMapping
(
"/updateUser"
)
public
R
updateByLdap
()
{
return
R
.
ok
(
userService
.
updateByLdap
());
}
}
}
yifu-upms/yifu-upms-biz/src/main/java/com/yifu.cloud.plus.v1/yifu/admin/service/SysDeptService.java
View file @
818d5f4b
...
@@ -19,6 +19,7 @@ package com.yifu.cloud.plus.v1.yifu.admin.service;
...
@@ -19,6 +19,7 @@ package com.yifu.cloud.plus.v1.yifu.admin.service;
import
cn.hutool.core.lang.tree.Tree
;
import
cn.hutool.core.lang.tree.Tree
;
import
com.baomidou.mybatisplus.extension.service.IService
;
import
com.baomidou.mybatisplus.extension.service.IService
;
import
com.yifu.cloud.plus.v1.yifu.admin.api.entity.SysDept
;
import
com.yifu.cloud.plus.v1.yifu.admin.api.entity.SysDept
;
import
com.yifu.cloud.plus.v1.yifu.common.core.util.R
;
import
java.util.List
;
import
java.util.List
;
...
@@ -72,4 +73,10 @@ public interface SysDeptService extends IService<SysDept> {
...
@@ -72,4 +73,10 @@ public interface SysDeptService extends IService<SysDept> {
*/
*/
List
<
Long
>
listChildDeptId
(
Long
deptId
);
List
<
Long
>
listChildDeptId
(
Long
deptId
);
/**
* 从ldap中获取部门
* @return R
*/
R
updateDeptByLdap
();
}
}
yifu-upms/yifu-upms-biz/src/main/java/com/yifu.cloud.plus.v1/yifu/admin/service/SysUserService.java
View file @
818d5f4b
...
@@ -122,4 +122,10 @@ public interface SysUserService extends IService<SysUser> {
...
@@ -122,4 +122,10 @@ public interface SysUserService extends IService<SysUser> {
*/
*/
R
<
Boolean
>
registerUser
(
UserDTO
userDto
);
R
<
Boolean
>
registerUser
(
UserDTO
userDto
);
/**
* 从ldap中获取用户
* @return R
*/
R
updateByLdap
();
}
}
yifu-upms/yifu-upms-biz/src/main/java/com/yifu.cloud.plus.v1/yifu/admin/service/impl/SysDeptServiceImpl.java
View file @
818d5f4b
...
@@ -20,15 +20,23 @@ import cn.hutool.core.collection.CollUtil;
...
@@ -20,15 +20,23 @@ import cn.hutool.core.collection.CollUtil;
import
cn.hutool.core.lang.tree.Tree
;
import
cn.hutool.core.lang.tree.Tree
;
import
cn.hutool.core.lang.tree.TreeNode
;
import
cn.hutool.core.lang.tree.TreeNode
;
import
cn.hutool.core.lang.tree.TreeUtil
;
import
cn.hutool.core.lang.tree.TreeUtil
;
import
com.baomidou.mybatisplus.core.toolkit.StringUtils
;
import
com.baomidou.mybatisplus.core.toolkit.Wrappers
;
import
com.baomidou.mybatisplus.core.toolkit.Wrappers
;
import
com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
;
import
com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
;
import
com.unboundid.ldap.sdk.SearchResultEntry
;
import
com.yifu.cloud.plus.v1.yifu.admin.api.entity.SysDept
;
import
com.yifu.cloud.plus.v1.yifu.admin.api.entity.SysDept
;
import
com.yifu.cloud.plus.v1.yifu.admin.api.entity.SysDeptRelation
;
import
com.yifu.cloud.plus.v1.yifu.admin.api.entity.SysDeptRelation
;
import
com.yifu.cloud.plus.v1.yifu.admin.api.entity.SysUser
;
import
com.yifu.cloud.plus.v1.yifu.admin.mapper.SysDeptMapper
;
import
com.yifu.cloud.plus.v1.yifu.admin.mapper.SysDeptMapper
;
import
com.yifu.cloud.plus.v1.yifu.admin.service.SysDeptRelationService
;
import
com.yifu.cloud.plus.v1.yifu.admin.service.SysDeptRelationService
;
import
com.yifu.cloud.plus.v1.yifu.admin.service.SysDeptService
;
import
com.yifu.cloud.plus.v1.yifu.admin.service.SysDeptService
;
import
com.yifu.cloud.plus.v1.yifu.admin.service.SysUserService
;
import
com.yifu.cloud.plus.v1.yifu.common.core.constant.CommonConstants
;
import
com.yifu.cloud.plus.v1.yifu.common.core.util.R
;
import
com.yifu.cloud.plus.v1.yifu.common.ldap.util.LdapUtil
;
import
com.yifu.cloud.plus.v1.yifu.common.security.util.SecurityUtils
;
import
com.yifu.cloud.plus.v1.yifu.common.security.util.SecurityUtils
;
import
lombok.RequiredArgsConstructor
;
import
lombok.RequiredArgsConstructor
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.BeanUtils
;
import
org.springframework.beans.BeanUtils
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.transaction.annotation.Transactional
;
...
@@ -46,10 +54,15 @@ import java.util.stream.Collectors;
...
@@ -46,10 +54,15 @@ import java.util.stream.Collectors;
*/
*/
@Service
@Service
@RequiredArgsConstructor
@RequiredArgsConstructor
@Slf4j
public
class
SysDeptServiceImpl
extends
ServiceImpl
<
SysDeptMapper
,
SysDept
>
implements
SysDeptService
{
public
class
SysDeptServiceImpl
extends
ServiceImpl
<
SysDeptMapper
,
SysDept
>
implements
SysDeptService
{
private
final
SysDeptRelationService
sysDeptRelationService
;
private
final
SysDeptRelationService
sysDeptRelationService
;
private
final
SysUserService
sysUserService
;
private
final
LdapUtil
ldapUtil
;
/**
/**
* 添加信息部门
* 添加信息部门
* @param dept 部门
* @param dept 部门
...
@@ -164,4 +177,69 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impl
...
@@ -164,4 +177,69 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impl
return
TreeUtil
.
build
(
collect
,
parentId
);
return
TreeUtil
.
build
(
collect
,
parentId
);
}
}
}
/**
* 从ldap中获取用户
* @return R
*/
@Override
public
R
<
Boolean
>
updateDeptByLdap
()
{
List
<
SearchResultEntry
>
entryList
=
ldapUtil
.
getAllPersonNamesWithTraditionalWay
();
for
(
SearchResultEntry
entry
:
entryList
)
{
String
dn
=
entry
.
getDN
();
String
userId
=
""
;
if
(
dn
.
contains
(
"uid"
))
{
userId
=
dn
.
substring
(
4
,
dn
.
indexOf
(
","
,
1
));
}
List
<
String
>
list
=
Arrays
.
asList
(
dn
.
split
(
","
)).
stream
().
filter
(
e
->
(
e
.
contains
(
"ou="
)
&&
!
e
.
equals
(
"ou=wanxin"
))).
collect
(
Collectors
.
toList
());
String
deptName
=
list
.
get
(
0
).
replace
(
"ou="
,
""
);
int
size
=
list
.
size
();
if
(
size
==
1
)
{
SysDept
sysDept
=
this
.
getOne
(
Wrappers
.<
SysDept
>
query
().
lambda
().
eq
(
SysDept:
:
getName
,
deptName
));
if
(
null
==
sysDept
)
{
SysDept
insertSysDept
=
new
SysDept
();
insertSysDept
.
setName
(
deptName
);
insertSysDept
.
setParentId
(
CommonConstants
.
MENU_TREE_ROOT_ID
);
this
.
save
(
insertSysDept
);
}
else
{
sysDept
.
setName
(
deptName
);
this
.
updateDeptById
(
sysDept
);
}
}
else
if
(
size
>=
2
)
{
SysDept
sysDept
=
new
SysDept
();
if
(
size
>
2
)
{
SysDept
sysDeptThree
=
this
.
getOne
(
Wrappers
.<
SysDept
>
query
().
lambda
().
eq
(
SysDept:
:
getName
,
list
.
get
(
2
).
replace
(
"ou="
,
""
)));
sysDept
=
this
.
getOne
(
Wrappers
.<
SysDept
>
query
().
lambda
().
eq
(
SysDept:
:
getName
,
list
.
get
(
1
).
replace
(
"ou="
,
""
))
.
eq
(
SysDept:
:
getParentId
,
sysDeptThree
.
getDeptId
()));
}
else
{
sysDept
=
this
.
getOne
(
Wrappers
.<
SysDept
>
query
().
lambda
().
eq
(
SysDept:
:
getName
,
list
.
get
(
1
).
replace
(
"ou="
,
""
)));
}
if
(
null
!=
sysDept
)
{
SysDept
sysDeptCount
=
this
.
getOne
(
Wrappers
.<
SysDept
>
query
().
lambda
().
eq
(
SysDept:
:
getName
,
deptName
).
eq
(
SysDept:
:
getParentId
,
sysDept
.
getDeptId
()));
if
(
null
==
sysDeptCount
)
{
SysDept
insertSysDept
=
new
SysDept
();
insertSysDept
.
setName
(
deptName
);
insertSysDept
.
setParentId
(
sysDept
.
getDeptId
());
this
.
save
(
insertSysDept
);
}
else
{
if
(
StringUtils
.
isNotBlank
(
userId
))
{
try
{
SysUser
user
=
sysUserService
.
getOne
(
Wrappers
.<
SysUser
>
query
().
lambda
().
eq
(
SysUser:
:
getUsername
,
userId
));
if
(
null
!=
user
)
{
user
.
setDeptId
(
sysDeptCount
.
getDeptId
());
sysUserService
.
updateById
(
user
);
}
sysDeptCount
.
setName
(
deptName
);
sysDeptCount
.
setParentId
(
sysDept
.
getDeptId
());
this
.
updateDeptById
(
sysDeptCount
);
}
catch
(
Exception
e
)
{
log
.
info
(
"更新异常:"
+
e
.
getMessage
());
return
R
.
failed
(
"同步信息失败!"
);
}
}
}
}
}
}
return
R
.
ok
();
}
}
yifu-upms/yifu-upms-biz/src/main/java/com/yifu.cloud.plus.v1/yifu/admin/service/impl/SysUserServiceImpl.java
View file @
818d5f4b
...
@@ -24,6 +24,7 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
...
@@ -24,6 +24,7 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import
com.baomidou.mybatisplus.extension.plugins.pagination.Page
;
import
com.baomidou.mybatisplus.extension.plugins.pagination.Page
;
import
com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
;
import
com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
;
import
com.pig4cloud.plugin.excel.vo.ErrorMessage
;
import
com.pig4cloud.plugin.excel.vo.ErrorMessage
;
import
com.unboundid.ldap.sdk.SearchResultEntry
;
import
com.yifu.cloud.plus.v1.yifu.admin.api.dto.UserDTO
;
import
com.yifu.cloud.plus.v1.yifu.admin.api.dto.UserDTO
;
import
com.yifu.cloud.plus.v1.yifu.admin.api.dto.UserInfo
;
import
com.yifu.cloud.plus.v1.yifu.admin.api.dto.UserInfo
;
import
com.yifu.cloud.plus.v1.yifu.admin.api.entity.*
;
import
com.yifu.cloud.plus.v1.yifu.admin.api.entity.*
;
...
@@ -39,6 +40,8 @@ import com.yifu.cloud.plus.v1.yifu.common.core.constant.enums.MenuTypeEnum;
...
@@ -39,6 +40,8 @@ import com.yifu.cloud.plus.v1.yifu.common.core.constant.enums.MenuTypeEnum;
import
com.yifu.cloud.plus.v1.yifu.common.core.exception.ErrorCodes
;
import
com.yifu.cloud.plus.v1.yifu.common.core.exception.ErrorCodes
;
import
com.yifu.cloud.plus.v1.yifu.common.core.util.MsgUtils
;
import
com.yifu.cloud.plus.v1.yifu.common.core.util.MsgUtils
;
import
com.yifu.cloud.plus.v1.yifu.common.core.util.R
;
import
com.yifu.cloud.plus.v1.yifu.common.core.util.R
;
import
com.yifu.cloud.plus.v1.yifu.common.ldap.entity.PersonVo
;
import
com.yifu.cloud.plus.v1.yifu.common.ldap.util.LdapUtil
;
import
lombok.RequiredArgsConstructor
;
import
lombok.RequiredArgsConstructor
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.BeanUtils
;
import
org.springframework.beans.BeanUtils
;
...
@@ -77,6 +80,8 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
...
@@ -77,6 +80,8 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
private
final
SysUserPostMapper
sysUserPostMapper
;
private
final
SysUserPostMapper
sysUserPostMapper
;
private
final
LdapUtil
ldapUtil
;
/**
/**
* 保存用户信息
* 保存用户信息
* @param userDto DTO 对象
* @param userDto DTO 对象
...
@@ -393,4 +398,39 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
...
@@ -393,4 +398,39 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
return
R
.
ok
(
saveUser
(
userDto
));
return
R
.
ok
(
saveUser
(
userDto
));
}
}
/**
* 从ldap中获取用户
* @return R
*/
@Override
public
R
<
Boolean
>
updateByLdap
()
{
List
<
PersonVo
>
list
=
ldapUtil
.
getAllPersons
();
if
(
null
!=
list
)
{
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
());
Map
<
String
,
String
>
map
=
listUser
.
stream
().
collect
(
HashMap:
:
new
,
(
m
,
v
)
->
m
.
put
(
v
.
getUsername
(),
v
.
getUserId
()),
HashMap:
:
putAll
);
for
(
PersonVo
personVo
:
list
)
{
if
(
list1
.
stream
().
anyMatch
(
e
->
e
.
equals
(
personVo
.
getUid
())))
{
SysUser
sysUser
=
this
.
getById
(
map
.
get
(
personVo
.
getUid
()));
sysUser
.
setUsername
(
personVo
.
getUid
());
sysUser
.
setPhone
(
personVo
.
getTelephoneNumber
());
sysUser
.
setEmail
(
personVo
.
getEmail
());
sysUser
.
setNickname
(
personVo
.
getPersonName
());
sysUser
.
setPassword
(
personVo
.
getPassword
());
this
.
updateById
(
sysUser
);
}
else
{
SysUser
sysUser
=
new
SysUser
();
sysUser
.
setUsername
(
personVo
.
getUid
());
sysUser
.
setPhone
(
personVo
.
getTelephoneNumber
());
sysUser
.
setEmail
(
personVo
.
getEmail
());
sysUser
.
setNickname
(
personVo
.
getPersonName
());
sysUser
.
setDelFlag
(
CommonConstants
.
STATUS_NORMAL
);
sysUser
.
setPassword
(
personVo
.
getPassword
());
sysUser
.
setUserGroup
(
CommonConstants
.
EMPTY_STRING
);
this
.
save
(
sysUser
);
}
}
}
return
R
.
ok
();
}
}
}
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