Commit b517383e authored by hongguangwu's avatar hongguangwu

Merge remote-tracking branch 'origin/develop' into develop

parents b6510714 abc6d0c5
...@@ -66,6 +66,12 @@ public class SysDept extends BaseEntity { ...@@ -66,6 +66,12 @@ public class SysDept extends BaseEntity {
@Schema(description = "父级部门id") @Schema(description = "父级部门id")
private Long parentId; private Long parentId;
/**
* dn
*/
@Schema(description = "部门dn")
private String deptDn;
/** /**
* 是否删除 -1:已删除 0:正常 * 是否删除 -1:已删除 0:正常
*/ */
......
...@@ -201,7 +201,7 @@ public class DictController { ...@@ -201,7 +201,7 @@ public class DictController {
public R updateById(@RequestBody SysDictItem sysDictItem) { public R updateById(@RequestBody SysDictItem sysDictItem) {
SysDictItem item = sysDictItemService.getOne(Wrappers.<SysDictItem>query().lambda() SysDictItem item = sysDictItemService.getOne(Wrappers.<SysDictItem>query().lambda()
.eq(SysDictItem::getType,sysDictItem.getType()) .eq(SysDictItem::getType,sysDictItem.getType())
.ne(SysDictItem::getId,sysDictItem.getDictId()) .ne(SysDictItem::getId,sysDictItem.getId())
.eq(SysDictItem::getValue,sysDictItem.getValue()) .eq(SysDictItem::getValue,sysDictItem.getValue())
.eq(SysDictItem::getDelFlag,CommonConstants.ZERO_STRING) .eq(SysDictItem::getDelFlag,CommonConstants.ZERO_STRING)
.last(CommonConstants.LAST_ONE_SQL)); .last(CommonConstants.LAST_ONE_SQL));
......
...@@ -39,4 +39,6 @@ public interface SysDeptMapper extends BaseMapper<SysDept> { ...@@ -39,4 +39,6 @@ public interface SysDeptMapper extends BaseMapper<SysDept> {
*/ */
List<SysDept> listDepts(); List<SysDept> listDepts();
List<String> selectDnList();
} }
...@@ -22,10 +22,12 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page; ...@@ -22,10 +22,12 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
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.entity.SysUser; import com.yifu.cloud.plus.v1.yifu.admin.api.entity.SysUser;
import com.yifu.cloud.plus.v1.yifu.admin.api.vo.UserVO; import com.yifu.cloud.plus.v1.yifu.admin.api.vo.UserVO;
import com.yifu.cloud.plus.v1.yifu.common.ldap.entity.PersonVo;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**
* <p> * <p>
...@@ -67,4 +69,10 @@ public interface SysUserMapper extends BaseMapper<SysUser> { ...@@ -67,4 +69,10 @@ public interface SysUserMapper extends BaseMapper<SysUser> {
*/ */
List<UserVO> selectVoList(@Param("query") UserDTO userDTO); List<UserVO> selectVoList(@Param("query") UserDTO userDTO);
void batchInsertUser(@Param("list") List<PersonVo> list);
void batchUpdateUser(@Param("list") List<PersonVo> list);
void updateUser(@Param("list") List<Map<String,Object>> list);
} }
...@@ -28,6 +28,7 @@ import com.yifu.cloud.plus.v1.yifu.admin.api.entity.SysDept; ...@@ -28,6 +28,7 @@ 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.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.mapper.SysUserMapper;
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.admin.service.SysUserService;
...@@ -43,6 +44,7 @@ import org.springframework.transaction.annotation.Transactional; ...@@ -43,6 +44,7 @@ import org.springframework.transaction.annotation.Transactional;
import java.util.*; import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.Stream;
/** /**
* <p> * <p>
...@@ -63,6 +65,10 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impl ...@@ -63,6 +65,10 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impl
private final LdapUtil ldapUtil; private final LdapUtil ldapUtil;
private final SysDeptMapper sysDeptMapper;
private final SysUserMapper sysUserMapper;
/** /**
* 添加信息部门 * 添加信息部门
* @param dept 部门 * @param dept 部门
...@@ -178,12 +184,22 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impl ...@@ -178,12 +184,22 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impl
} }
/** /**
* 从ldap中获取用户 * 从ldap中获取部门
* @return R * @return R
*/ */
@Override @Override
public R<Boolean> updateDeptByLdap() { public R<Boolean> updateDeptByLdap() {
List<SearchResultEntry> entryList = ldapUtil.getAllPersonNamesWithTraditionalWay(); List<SearchResultEntry> entryList = ldapUtil.getAllPersonNamesWithTraditionalWay();
//获取ldap所有的dn
List<String> entryDnList = entryList.stream().map(SearchResultEntry::getDN).collect(Collectors.toList());
//获取本地dept表中所有的dn
List<String> dnList = sysDeptMapper.selectDnList();
List<String> delList = dnList.stream().filter(p-> !entryDnList.contains(p)).collect(Collectors.toList());
//删除ldap中不存在的dn的数据
if (delList.size() >0) {
sysDeptMapper.delete(Wrappers.<SysDept>query().lambda().in(SysDept::getDeptDn, delList));
}
List<Map<String,Object>> updUserList = new ArrayList<>();
for (SearchResultEntry entry : entryList) { for (SearchResultEntry entry : entryList) {
String dn = entry.getDN(); String dn = entry.getDN();
String userId = ""; String userId = "";
...@@ -194,52 +210,48 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impl ...@@ -194,52 +210,48 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impl
String deptName = list.get(0).replace("ou=", ""); String deptName = list.get(0).replace("ou=", "");
int size = list.size(); int size = list.size();
if (size == 1) { if (size == 1) {
SysDept sysDept = this.getOne(Wrappers.<SysDept>query().lambda().eq(SysDept::getName, deptName)); SysDept sysDept = this.getOne(Wrappers.<SysDept>query().lambda().eq(SysDept::getDeptDn, dn));
if (null == sysDept) { if (null == sysDept) {
SysDept insertSysDept = new SysDept(); SysDept insertSysDept = new SysDept();
insertSysDept.setName(deptName); insertSysDept.setName(deptName);
insertSysDept.setParentId(CommonConstants.MENU_TREE_ROOT_ID); insertSysDept.setParentId(CommonConstants.MENU_TREE_ROOT_ID);
insertSysDept.setDeptDn(dn);
this.save(insertSysDept); this.save(insertSysDept);
} else { } else {
sysDept.setName(deptName); sysDept.setName(deptName);
this.updateDeptById(sysDept); this.updateDeptById(sysDept);
} }
} else if (size >= 2) { } else if (size >= 2) {
SysDept sysDept = new SysDept(); try {
if (size > 2) { SysDept sysDept = this.getOne(Wrappers.<SysDept>query().lambda().eq(SysDept::getDeptDn, dn.substring(dn.indexOf("ou=", 2), dn.length())));
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) { if (null != sysDept) {
SysDept sysDeptCount = this.getOne(Wrappers.<SysDept>query().lambda().eq(SysDept::getName, deptName).eq(SysDept::getParentId,sysDept.getDeptId())); SysDept sysDeptCount = this.getOne(Wrappers.<SysDept>query().lambda().eq(SysDept::getDeptDn, dn));
if (null == sysDeptCount) { if (null == sysDeptCount) {
SysDept insertSysDept = new SysDept(); SysDept insertSysDept = new SysDept();
insertSysDept.setName(deptName); insertSysDept.setName(deptName);
insertSysDept.setParentId(sysDept.getDeptId()); insertSysDept.setParentId(sysDept.getDeptId());
insertSysDept.setDeptDn(dn);
this.save(insertSysDept); this.save(insertSysDept);
} else { } else {
if (StringUtils.isNotBlank(userId)) { if (StringUtils.isNotBlank(userId)) {
try { Map<String,Object> map = new HashMap<>();
SysUser user = sysUserService.getOne(Wrappers.<SysUser>query().lambda().eq(SysUser::getUsername, userId)); map.put("userId",userId);
if (null != user) { map.put("deptId",sysDeptCount.getDeptId());
user.setDeptId(sysDeptCount.getDeptId()); updUserList.add(map);
sysUserService.updateById(user);
} }
sysDeptCount.setName(deptName); sysDeptCount.setName(deptName);
sysDeptCount.setParentId(sysDept.getDeptId()); sysDeptCount.setParentId(sysDept.getDeptId());
this.updateDeptById(sysDeptCount); this.updateDeptById(sysDeptCount);
} catch (Exception e) {
log.info("更新异常:"+e.getMessage());
return R.failed("同步信息失败!");
}
} }
} }
} catch (Exception e) {
log.info("更新异常:" + e.getMessage());
return R.failed("同步信息失败!");
} }
} }
} }
//更新用户信息
sysUserMapper.updateUser(updUserList);
return R.ok(); return R.ok();
} }
} }
...@@ -82,6 +82,8 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl ...@@ -82,6 +82,8 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
private final LdapUtil ldapUtil; private final LdapUtil ldapUtil;
private final SysUserMapper sysUserMapper;
/** /**
* 保存用户信息 * 保存用户信息
* @param userDto DTO 对象 * @param userDto DTO 对象
...@@ -409,26 +411,20 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl ...@@ -409,26 +411,20 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
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::getDelFlag, CommonConstants.STATUS_NORMAL));
List<String> list1 = listUser.stream().map(SysUser::getUsername).collect(Collectors.toList()); 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); Map<String, String> map = listUser.stream().collect(HashMap::new, (m, v) -> m.put(v.getUsername(), v.getUserId()), HashMap::putAll);
List<PersonVo> updateList = new ArrayList<>();
List<PersonVo> insertList = new ArrayList<>();
for (PersonVo personVo : list) { for (PersonVo personVo : list) {
if (list1.stream().anyMatch(e -> e.equals(personVo.getUid()))) { if (list1.stream().anyMatch(e -> e.equals(personVo.getUid()))) {
SysUser sysUser = this.getById(map.get(personVo.getUid())); updateList.add(personVo);
sysUser.setUsername(personVo.getUid());
sysUser.setPhone(personVo.getTelephoneNumber());
sysUser.setEmail(personVo.getEmail());
sysUser.setNickname(personVo.getPersonName());
sysUser.setPassword(personVo.getPassword());
this.updateById(sysUser);
} else { } else {
SysUser sysUser = new SysUser(); insertList.add(personVo);
sysUser.setUsername(personVo.getUid()); }
sysUser.setPhone(personVo.getTelephoneNumber()); }
sysUser.setEmail(personVo.getEmail()); if (updateList.size()>0) {
sysUser.setNickname(personVo.getPersonName()); sysUserMapper.batchUpdateUser(updateList);
sysUser.setDelFlag(CommonConstants.STATUS_NORMAL);
sysUser.setPassword(personVo.getPassword());
sysUser.setUserGroup(CommonConstants.EMPTY_STRING);
this.save(sysUser);
} }
if (insertList.size()>0) {
sysUserMapper.batchInsertUser(insertList);
} }
} }
return R.ok(); return R.ok();
......
...@@ -207,4 +207,75 @@ ...@@ -207,4 +207,75 @@
</where> </where>
ORDER BY u.create_time DESC ORDER BY u.create_time DESC
</select> </select>
<insert id="batchInsertUser" parameterType="java.util.List">
insert into sys_user
(user_id,username,phone,email,password,nickname)
VALUES
<foreach collection="list" item="item" index="index" separator=",">
(
REPLACE(UUID(),"-",""),
#{item.uid,jdbcType=VARCHAR},
#{item.telephoneNumber,jdbcType=VARCHAR},
#{item.email,jdbcType=VARCHAR},
#{item.password,jdbcType=VARCHAR},
#{item.personName,jdbcType=VARCHAR}
)
</foreach>
</insert>
<update id="batchUpdateUser" parameterType="java.util.List">
update sys_user
<trim prefix="set" suffixOverrides=",">
<trim prefix="phone =case" suffix="end,">
<foreach collection="list" item="i" index="index">
<if test="i.telephoneNumber!=null">
when username=#{i.uid} then #{i.telephoneNumber}
</if>
</foreach>
</trim>
<trim prefix="email =case" suffix="end,">
<foreach collection="list" item="i" index="index">
<if test="i.email!=null">
when username=#{i.uid} then #{i.email}
</if>
</foreach>
</trim>
<trim prefix="nickname =case" suffix="end," >
<foreach collection="list" item="i" index="index">
<if test="i.personName!=null">
when username=#{i.uid} then #{i.personName}
</if>
</foreach>
</trim>
<trim prefix="password =case" suffix="end," >
<foreach collection="list" item="i" index="index">
<if test="i.password!=null">
when username=#{i.uid} then #{i.password}
</if>
</foreach>
</trim>
</trim>
where
<foreach collection="list" separator="or" item="i" index="index" >
username=#{i.uid}
</foreach>
</update>
<update id="updateUser" parameterType="java.util.List">
update sys_user
<trim prefix="set" suffixOverrides=",">
<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>
where
<foreach collection="list" separator="or" item="i" index="index" >
username=#{i.userId}
</foreach>
</update>
</mapper> </mapper>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment