Commit 6c83ceab authored by hkl's avatar hkl

feat:1.用户管理修改

parent 16ccb5e5
...@@ -196,7 +196,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl ...@@ -196,7 +196,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
} }
@Override @Override
@CacheEvict(value={CacheConstant.SYS_USERS_CACHE}, allEntries=true) @CacheEvict(value = {CacheConstant.SYS_USERS_CACHE}, allEntries = true)
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public boolean deleteUser(String userId) { public boolean deleteUser(String userId) {
//1.删除用户 //1.删除用户
...@@ -205,7 +205,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl ...@@ -205,7 +205,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
} }
@Override @Override
@CacheEvict(value={CacheConstant.SYS_USERS_CACHE}, allEntries=true) @CacheEvict(value = {CacheConstant.SYS_USERS_CACHE}, allEntries = true)
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public boolean deleteBatchUsers(String userIds) { public boolean deleteBatchUsers(String userIds) {
//1.删除用户 //1.删除用户
...@@ -217,7 +217,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl ...@@ -217,7 +217,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
public SysUser getUserByName(String username) { public SysUser getUserByName(String username) {
SysUser sysUser = userMapper.getUserByName(username); SysUser sysUser = userMapper.getUserByName(username);
//查询用户的租户ids //查询用户的租户ids
if(sysUser!=null){ if (sysUser != null) {
List<Integer> list = userTenantMapper.getTenantIdsByUserId(sysUser.getId()); List<Integer> list = userTenantMapper.getTenantIdsByUserId(sysUser.getId());
if (oConvertUtils.isNotEmpty(list)) { if (oConvertUtils.isNotEmpty(list)) {
sysUser.setRelTenantIds(StringUtils.join(list.toArray(), SymbolConstant.COMMA)); sysUser.setRelTenantIds(StringUtils.join(list.toArray(), SymbolConstant.COMMA));
...@@ -233,7 +233,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl ...@@ -233,7 +233,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void addUserWithRole(SysUser user, String roles) { public void addUserWithRole(SysUser user, String roles) {
this.save(user); this.save(user);
if(oConvertUtils.isNotEmpty(roles)) { if (oConvertUtils.isNotEmpty(roles)) {
String[] arr = roles.split(","); String[] arr = roles.split(",");
for (String roleId : arr) { for (String roleId : arr) {
SysUserRole userRole = new SysUserRole(user.getId(), roleId); SysUserRole userRole = new SysUserRole(user.getId(), roleId);
...@@ -243,13 +243,13 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl ...@@ -243,13 +243,13 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
} }
@Override @Override
@CacheEvict(value= {CacheConstant.SYS_USERS_CACHE}, allEntries=true) @CacheEvict(value = {CacheConstant.SYS_USERS_CACHE}, allEntries = true)
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void editUserWithRole(SysUser user, String roles) { public void editUserWithRole(SysUser user, String roles) {
this.updateById(user); this.updateById(user);
//先删后加 //先删后加
sysUserRoleMapper.delete(new QueryWrapper<SysUserRole>().lambda().eq(SysUserRole::getUserId, user.getId())); sysUserRoleMapper.delete(new QueryWrapper<SysUserRole>().lambda().eq(SysUserRole::getUserId, user.getId()));
if(oConvertUtils.isNotEmpty(roles)) { if (oConvertUtils.isNotEmpty(roles)) {
String[] arr = roles.split(","); String[] arr = roles.split(",");
for (String roleId : arr) { for (String roleId : arr) {
SysUserRole userRole = new SysUserRole(user.getId(), roleId); SysUserRole userRole = new SysUserRole(user.getId(), roleId);
...@@ -266,17 +266,18 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl ...@@ -266,17 +266,18 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
/** /**
* 获取动态首页路由配置 * 获取动态首页路由配置
*
* @param username * @param username
* @param version * @param version
* @return * @return
*/ */
@Override @Override
public SysRoleIndex getDynamicIndexByUserRole(String username,String version) { public SysRoleIndex getDynamicIndexByUserRole(String username, String version) {
List<String> roles = sysUserRoleMapper.getRoleByUserName(username); List<String> roles = sysUserRoleMapper.getRoleByUserName(username);
String componentUrl = RoleIndexConfigEnum.getIndexByRoles(roles); String componentUrl = RoleIndexConfigEnum.getIndexByRoles(roles);
SysRoleIndex roleIndex = new SysRoleIndex(componentUrl); SysRoleIndex roleIndex = new SysRoleIndex(componentUrl);
//只有 X-Version=v3 的时候,才读取sys_role_index表获取角色首页配置 //只有 X-Version=v3 的时候,才读取sys_role_index表获取角色首页配置
if (oConvertUtils.isNotEmpty(version) && roles!=null && roles.size()>0) { if (oConvertUtils.isNotEmpty(version) && roles != null && roles.size() > 0) {
LambdaQueryWrapper<SysRoleIndex> routeIndexQuery = new LambdaQueryWrapper(); LambdaQueryWrapper<SysRoleIndex> routeIndexQuery = new LambdaQueryWrapper();
//用户所有角色 //用户所有角色
routeIndexQuery.in(SysRoleIndex::getRoleCode, roles); routeIndexQuery.in(SysRoleIndex::getRoleCode, roles);
...@@ -291,7 +292,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl ...@@ -291,7 +292,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
} }
//如果componentUrl为空,则返回空 //如果componentUrl为空,则返回空
if(oConvertUtils.isEmpty(roleIndex.getComponent())){ if (oConvertUtils.isEmpty(roleIndex.getComponent())) {
return null; return null;
} }
return roleIndex; return roleIndex;
...@@ -299,6 +300,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl ...@@ -299,6 +300,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
/** /**
* 通过用户名获取用户角色集合 * 通过用户名获取用户角色集合
*
* @param username 用户名 * @param username 用户名
* @return 角色集合 * @return 角色集合
*/ */
...@@ -329,28 +331,29 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl ...@@ -329,28 +331,29 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
permissionSet.add(po.getPerms()); permissionSet.add(po.getPerms());
} }
} }
log.info("-------通过数据库读取用户拥有的权限Perms------username: "+ username+",Perms size: "+ (permissionSet==null?0:permissionSet.size()) ); log.info("-------通过数据库读取用户拥有的权限Perms------username: " + username + ",Perms size: " + (permissionSet == null ? 0 : permissionSet.size()));
return permissionSet; return permissionSet;
} }
/** /**
* 升级SpringBoot2.6.6,不允许循环依赖 * 升级SpringBoot2.6.6,不允许循环依赖
* @author:qinfeng *
* @update: 2022-04-07
* @param username * @param username
* @return * @return
* @author:qinfeng
* @update: 2022-04-07
*/ */
@Override @Override
public SysUserCacheInfo getCacheUser(String username) { public SysUserCacheInfo getCacheUser(String username) {
SysUserCacheInfo info = new SysUserCacheInfo(); SysUserCacheInfo info = new SysUserCacheInfo();
info.setOneDepart(true); info.setOneDepart(true);
if(oConvertUtils.isEmpty(username)) { if (oConvertUtils.isEmpty(username)) {
return null; return null;
} }
//查询用户信息 //查询用户信息
SysUser sysUser = userMapper.getUserByName(username); SysUser sysUser = userMapper.getUserByName(username);
if(sysUser!=null) { if (sysUser != null) {
info.setSysUserCode(sysUser.getUsername()); info.setSysUserCode(sysUser.getUsername());
info.setSysUserName(sysUser.getRealname()); info.setSysUserName(sysUser.getRealname());
info.setSysOrgCode(sysUser.getOrgCode()); info.setSysOrgCode(sysUser.getOrgCode());
...@@ -359,12 +362,12 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl ...@@ -359,12 +362,12 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
//多部门支持in查询 //多部门支持in查询
List<SysDepart> list = sysDepartMapper.queryUserDeparts(sysUser.getId()); List<SysDepart> list = sysDepartMapper.queryUserDeparts(sysUser.getId());
List<String> sysMultiOrgCode = new ArrayList<String>(); List<String> sysMultiOrgCode = new ArrayList<String>();
if(list==null || list.size()==0) { if (list == null || list.size() == 0) {
//当前用户无部门 //当前用户无部门
//sysMultiOrgCode.add("0"); //sysMultiOrgCode.add("0");
}else if(list.size()==1) { } else if (list.size() == 1) {
sysMultiOrgCode.add(list.get(0).getOrgCode()); sysMultiOrgCode.add(list.get(0).getOrgCode());
}else { } else {
info.setOneDepart(false); info.setOneDepart(false);
for (SysDepart dpt : list) { for (SysDepart dpt : list) {
sysMultiOrgCode.add(dpt.getOrgCode()); sysMultiOrgCode.add(dpt.getOrgCode());
...@@ -377,19 +380,20 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl ...@@ -377,19 +380,20 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
/** /**
* 根据部门Id查询 * 根据部门Id查询
*
* @param page * @param page
* @param departId 部门id * @param departId 部门id
* @param username 用户账户名称 * @param username 用户账户名称
* @return * @return
*/ */
@Override @Override
public IPage<SysUser> getUserByDepId(Page<SysUser> page, String departId,String username) { public IPage<SysUser> getUserByDepId(Page<SysUser> page, String departId, String username) {
return userMapper.getUserByDepId(page, departId,username); return userMapper.getUserByDepId(page, departId, username);
} }
@Override @Override
public IPage<SysUser> getUserByDepIds(Page<SysUser> page, List<String> departIds, String username) { public IPage<SysUser> getUserByDepIds(Page<SysUser> page, List<String> departIds, String username) {
return userMapper.getUserByDepIds(page, departIds,username); return userMapper.getUserByDepIds(page, departIds, username);
} }
@Override @Override
...@@ -433,6 +437,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl ...@@ -433,6 +437,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
/** /**
* 根据角色Id查询 * 根据角色Id查询
*
* @param page * @param page
* @param roleId 角色id * @param roleId 角色id
* @param username 用户账户名称 * @param username 用户账户名称
...@@ -440,14 +445,14 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl ...@@ -440,14 +445,14 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
*/ */
@Override @Override
public IPage<SysUser> getUserByRoleId(Page<SysUser> page, String roleId, String username) { public IPage<SysUser> getUserByRoleId(Page<SysUser> page, String roleId, String username) {
return userMapper.getUserByRoleId(page,roleId,username); return userMapper.getUserByRoleId(page, roleId, username);
} }
@Override @Override
@CacheEvict(value= {CacheConstant.SYS_USERS_CACHE}, key="#username") @CacheEvict(value = {CacheConstant.SYS_USERS_CACHE}, key = "#username")
public void updateUserDepart(String username,String orgCode,Integer loginTenantId) { public void updateUserDepart(String username, String orgCode, Integer loginTenantId) {
baseMapper.updateUserDepart(username, orgCode,loginTenantId); baseMapper.updateUserDepart(username, orgCode, loginTenantId);
} }
...@@ -466,7 +471,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl ...@@ -466,7 +471,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void addUserWithDepart(SysUser user, String selectedParts) { public void addUserWithDepart(SysUser user, String selectedParts) {
// this.save(user); //保存角色的时候已经添加过一次了 // this.save(user); //保存角色的时候已经添加过一次了
if(oConvertUtils.isNotEmpty(selectedParts)) { if (oConvertUtils.isNotEmpty(selectedParts)) {
String[] arr = selectedParts.split(","); String[] arr = selectedParts.split(",");
for (String deaprtId : arr) { for (String deaprtId : arr) {
SysUserDepart userDeaprt = new SysUserDepart(user.getId(), deaprtId); SysUserDepart userDeaprt = new SysUserDepart(user.getId(), deaprtId);
...@@ -478,33 +483,33 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl ...@@ -478,33 +483,33 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
@CacheEvict(value={CacheConstant.SYS_USERS_CACHE}, allEntries=true) @CacheEvict(value = {CacheConstant.SYS_USERS_CACHE}, allEntries = true)
public void editUserWithDepart(SysUser user, String departs) { public void editUserWithDepart(SysUser user, String departs) {
//更新角色的时候已经更新了一次了,可以再跟新一次 //更新角色的时候已经更新了一次了,可以再跟新一次
this.updateById(user); this.updateById(user);
String[] arr = {}; String[] arr = {};
if(oConvertUtils.isNotEmpty(departs)){ if (oConvertUtils.isNotEmpty(departs)) {
arr = departs.split(","); arr = departs.split(",");
} }
//查询已关联部门 //查询已关联部门
List<SysUserDepart> userDepartList = sysUserDepartMapper.selectList(new QueryWrapper<SysUserDepart>().lambda().eq(SysUserDepart::getUserId, user.getId())); List<SysUserDepart> userDepartList = sysUserDepartMapper.selectList(new QueryWrapper<SysUserDepart>().lambda().eq(SysUserDepart::getUserId, user.getId()));
if(userDepartList != null && userDepartList.size()>0){ if (userDepartList != null && userDepartList.size() > 0) {
for(SysUserDepart depart : userDepartList ){ for (SysUserDepart depart : userDepartList) {
//修改已关联部门删除部门用户角色关系 //修改已关联部门删除部门用户角色关系
if(!Arrays.asList(arr).contains(depart.getDepId())){ if (!Arrays.asList(arr).contains(depart.getDepId())) {
List<SysDepartRole> sysDepartRoleList = sysDepartRoleMapper.selectList( List<SysDepartRole> sysDepartRoleList = sysDepartRoleMapper.selectList(
new QueryWrapper<SysDepartRole>().lambda().eq(SysDepartRole::getDepartId,depart.getDepId())); new QueryWrapper<SysDepartRole>().lambda().eq(SysDepartRole::getDepartId, depart.getDepId()));
List<String> roleIds = sysDepartRoleList.stream().map(SysDepartRole::getId).collect(Collectors.toList()); List<String> roleIds = sysDepartRoleList.stream().map(SysDepartRole::getId).collect(Collectors.toList());
if(roleIds != null && roleIds.size()>0){ if (roleIds != null && roleIds.size() > 0) {
departRoleUserMapper.delete(new QueryWrapper<SysDepartRoleUser>().lambda().eq(SysDepartRoleUser::getUserId, user.getId()) departRoleUserMapper.delete(new QueryWrapper<SysDepartRoleUser>().lambda().eq(SysDepartRoleUser::getUserId, user.getId())
.in(SysDepartRoleUser::getDroleId,roleIds)); .in(SysDepartRoleUser::getDroleId, roleIds));
} }
} }
} }
} }
//先删后加 //先删后加
sysUserDepartMapper.delete(new QueryWrapper<SysUserDepart>().lambda().eq(SysUserDepart::getUserId, user.getId())); sysUserDepartMapper.delete(new QueryWrapper<SysUserDepart>().lambda().eq(SysUserDepart::getUserId, user.getId()));
if(oConvertUtils.isNotEmpty(departs)) { if (oConvertUtils.isNotEmpty(departs)) {
for (String departId : arr) { for (String departId : arr) {
SysUserDepart userDepart = new SysUserDepart(user.getId(), departId); SysUserDepart userDepart = new SysUserDepart(user.getId(), departId);
sysUserDepartMapper.insert(userDepart); sysUserDepartMapper.insert(userDepart);
...@@ -515,6 +520,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl ...@@ -515,6 +520,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
/** /**
* 校验用户是否有效 * 校验用户是否有效
*
* @param sysUser * @param sysUser
* @return * @return
*/ */
...@@ -523,7 +529,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl ...@@ -523,7 +529,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
Result<?> result = new Result<Object>(); Result<?> result = new Result<Object>();
//情况1:根据用户信息查询,该用户不存在 //情况1:根据用户信息查询,该用户不存在
if (sysUser == null) { if (sysUser == null) {
result.error500("该用户不存在,请注册"); result.error500("该用户不存在");
baseCommonService.addLog("用户登录失败,用户不存在!", CommonConstant.LOG_TYPE_1, null); baseCommonService.addLog("用户登录失败,用户不存在!", CommonConstant.LOG_TYPE_1, null);
return result; return result;
} }
...@@ -563,7 +569,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl ...@@ -563,7 +569,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
} }
@Override @Override
@CacheEvict(value={CacheConstant.SYS_USERS_CACHE}, allEntries=true) @CacheEvict(value = {CacheConstant.SYS_USERS_CACHE}, allEntries = true)
public boolean revertLogicDeleted(List<String> userIds, SysUser updateEntity) { public boolean revertLogicDeleted(List<String> userIds, SysUser updateEntity) {
return userMapper.revertLogicDeleted(userIds, updateEntity) > 0; return userMapper.revertLogicDeleted(userIds, updateEntity) > 0;
} }
...@@ -588,7 +594,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl ...@@ -588,7 +594,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
line += sysThirdAccountMapper.delete(new LambdaQueryWrapper<SysThirdAccount>().in(SysThirdAccount::getSysUserId, userIds)); line += sysThirdAccountMapper.delete(new LambdaQueryWrapper<SysThirdAccount>().in(SysThirdAccount::getSysUserId, userIds));
//6. 删除租户用户中间表的数据 //6. 删除租户用户中间表的数据
line += userTenantMapper.delete(new LambdaQueryWrapper<SysUserTenant>().in(SysUserTenant::getUserId,userIds)); line += userTenantMapper.delete(new LambdaQueryWrapper<SysUserTenant>().in(SysUserTenant::getUserId, userIds));
return line != 0; return line != 0;
} }
...@@ -618,7 +624,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl ...@@ -618,7 +624,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
@Override @Override
public List<SysUser> queryByDepIds(List<String> departIds, String username) { public List<SysUser> queryByDepIds(List<String> departIds, String username) {
return userMapper.queryByDepIds(departIds,username); return userMapper.queryByDepIds(departIds, username);
} }
@Override @Override
...@@ -627,9 +633,9 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl ...@@ -627,9 +633,9 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
//step.1 保存用户 //step.1 保存用户
this.save(user); this.save(user);
//获取用户保存前台传过来的租户id并添加到租户 //获取用户保存前台传过来的租户id并添加到租户
this.saveUserTenant(user.getId(),relTenantIds); this.saveUserTenant(user.getId(), relTenantIds);
//step.2 保存角色 //step.2 保存角色
if(oConvertUtils.isNotEmpty(selectedRoles)) { if (oConvertUtils.isNotEmpty(selectedRoles)) {
String[] arr = selectedRoles.split(","); String[] arr = selectedRoles.split(",");
for (String roleId : arr) { for (String roleId : arr) {
SysUserRole userRole = new SysUserRole(user.getId(), roleId); SysUserRole userRole = new SysUserRole(user.getId(), roleId);
...@@ -638,7 +644,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl ...@@ -638,7 +644,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
} }
//step.3 保存所属部门 //step.3 保存所属部门
if(oConvertUtils.isNotEmpty(selectedDeparts)) { if (oConvertUtils.isNotEmpty(selectedDeparts)) {
String[] arr = selectedDeparts.split(","); String[] arr = selectedDeparts.split(",");
for (String deaprtId : arr) { for (String deaprtId : arr) {
SysUserDepart userDeaprt = new SysUserDepart(user.getId(), deaprtId); SysUserDepart userDeaprt = new SysUserDepart(user.getId(), deaprtId);
...@@ -647,23 +653,23 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl ...@@ -647,23 +653,23 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
} }
//触发入职流程 //触发入职流程
LoginUser userInfo=new LoginUser(); LoginUser userInfo = new LoginUser();
BeanUtils.copyProperties(user,userInfo); BeanUtils.copyProperties(user, userInfo);
LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal(); LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
} }
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
@CacheEvict(value={CacheConstant.SYS_USERS_CACHE}, allEntries=true) @CacheEvict(value = {CacheConstant.SYS_USERS_CACHE}, allEntries = true)
public void editUser(SysUser user, String roles, String departs, String relTenantIds) { public void editUser(SysUser user, String roles, String departs, String relTenantIds) {
//获取用户编辑前台传过来的租户id //获取用户编辑前台传过来的租户id
this.editUserTenants(user.getId(),relTenantIds); this.editUserTenants(user.getId(), relTenantIds);
//step.1 修改用户基础信息 //step.1 修改用户基础信息
this.updateById(user); this.updateById(user);
//step.2 修改角色 //step.2 修改角色
//处理用户角色 先删后加 //处理用户角色 先删后加
sysUserRoleMapper.delete(new QueryWrapper<SysUserRole>().lambda().eq(SysUserRole::getUserId, user.getId())); sysUserRoleMapper.delete(new QueryWrapper<SysUserRole>().lambda().eq(SysUserRole::getUserId, user.getId()));
if(oConvertUtils.isNotEmpty(roles)) { if (oConvertUtils.isNotEmpty(roles)) {
String[] arr = roles.split(","); String[] arr = roles.split(",");
for (String roleId : arr) { for (String roleId : arr) {
SysUserRole userRole = new SysUserRole(user.getId(), roleId); SysUserRole userRole = new SysUserRole(user.getId(), roleId);
...@@ -673,28 +679,28 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl ...@@ -673,28 +679,28 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
//step.3 修改部门 //step.3 修改部门
String[] arr = {}; String[] arr = {};
if(oConvertUtils.isNotEmpty(departs)){ if (oConvertUtils.isNotEmpty(departs)) {
arr = departs.split(","); arr = departs.split(",");
} }
//查询已关联部门 //查询已关联部门
List<SysUserDepart> userDepartList = sysUserDepartMapper.selectList(new QueryWrapper<SysUserDepart>().lambda().eq(SysUserDepart::getUserId, user.getId())); List<SysUserDepart> userDepartList = sysUserDepartMapper.selectList(new QueryWrapper<SysUserDepart>().lambda().eq(SysUserDepart::getUserId, user.getId()));
if(userDepartList != null && userDepartList.size()>0){ if (userDepartList != null && userDepartList.size() > 0) {
for(SysUserDepart depart : userDepartList ){ for (SysUserDepart depart : userDepartList) {
//修改已关联部门删除部门用户角色关系 //修改已关联部门删除部门用户角色关系
if(!Arrays.asList(arr).contains(depart.getDepId())){ if (!Arrays.asList(arr).contains(depart.getDepId())) {
List<SysDepartRole> sysDepartRoleList = sysDepartRoleMapper.selectList( List<SysDepartRole> sysDepartRoleList = sysDepartRoleMapper.selectList(
new QueryWrapper<SysDepartRole>().lambda().eq(SysDepartRole::getDepartId,depart.getDepId())); new QueryWrapper<SysDepartRole>().lambda().eq(SysDepartRole::getDepartId, depart.getDepId()));
List<String> roleIds = sysDepartRoleList.stream().map(SysDepartRole::getId).collect(Collectors.toList()); List<String> roleIds = sysDepartRoleList.stream().map(SysDepartRole::getId).collect(Collectors.toList());
if(roleIds != null && roleIds.size()>0){ if (roleIds != null && roleIds.size() > 0) {
departRoleUserMapper.delete(new QueryWrapper<SysDepartRoleUser>().lambda().eq(SysDepartRoleUser::getUserId, user.getId()) departRoleUserMapper.delete(new QueryWrapper<SysDepartRoleUser>().lambda().eq(SysDepartRoleUser::getUserId, user.getId())
.in(SysDepartRoleUser::getDroleId,roleIds)); .in(SysDepartRoleUser::getDroleId, roleIds));
} }
} }
} }
} }
//先删后加 //先删后加
sysUserDepartMapper.delete(new QueryWrapper<SysUserDepart>().lambda().eq(SysUserDepart::getUserId, user.getId())); sysUserDepartMapper.delete(new QueryWrapper<SysUserDepart>().lambda().eq(SysUserDepart::getUserId, user.getId()));
if(oConvertUtils.isNotEmpty(departs)) { if (oConvertUtils.isNotEmpty(departs)) {
for (String departId : arr) { for (String departId : arr) {
SysUserDepart userDepart = new SysUserDepart(user.getId(), departId); SysUserDepart userDepart = new SysUserDepart(user.getId(), departId);
sysUserDepartMapper.insert(userDepart); sysUserDepartMapper.insert(userDepart);
...@@ -716,17 +722,17 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl ...@@ -716,17 +722,17 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
} }
@Override @Override
@Cacheable(cacheNames=CacheConstant.SYS_USERS_CACHE, key="#username") @Cacheable(cacheNames = CacheConstant.SYS_USERS_CACHE, key = "#username")
@SensitiveEncode @SensitiveEncode
public LoginUser getEncodeUserInfo(String username){ public LoginUser getEncodeUserInfo(String username) {
if(oConvertUtils.isEmpty(username)) { if (oConvertUtils.isEmpty(username)) {
return null; return null;
} }
LoginUser loginUser = new LoginUser(); LoginUser loginUser = new LoginUser();
SysUser sysUser = userMapper.getUserByName(username); SysUser sysUser = userMapper.getUserByName(username);
//查询用户的租户ids //查询用户的租户ids
this.setUserTenantIds(sysUser); this.setUserTenantIds(sysUser);
if(sysUser==null) { if (sysUser == null) {
return null; return null;
} }
BeanUtils.copyProperties(sysUser, loginUser); BeanUtils.copyProperties(sysUser, loginUser);
...@@ -734,29 +740,29 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl ...@@ -734,29 +740,29 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
} }
@Override @Override
@CacheEvict(value={CacheConstant.SYS_USERS_CACHE}, allEntries=true) @CacheEvict(value = {CacheConstant.SYS_USERS_CACHE}, allEntries = true)
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void userQuit(String username) { public void userQuit(String username) {
SysUser sysUser = userMapper.getUserByName(username); SysUser sysUser = userMapper.getUserByName(username);
if(null == sysUser){ if (null == sysUser) {
throw new JeecgBootException("离职失败,该用户已不存在"); throw new JeecgBootException("离职失败,该用户已不存在");
} }
//update-begin---author:wangshuai ---date:20230111 for:[QQYUN-3951]租户用户离职重构------------ //update-begin---author:wangshuai ---date:20230111 for:[QQYUN-3951]租户用户离职重构------------
int tenantId = oConvertUtils.getInt(TenantContext.getTenant(), 0); int tenantId = oConvertUtils.getInt(TenantContext.getTenant(), 0);
//更新用户租户表的状态为离职状态 //更新用户租户表的状态为离职状态
if(tenantId==0){ if (tenantId == 0) {
throw new JeecgBootException("离职失败,租户不存在"); throw new JeecgBootException("离职失败,租户不存在");
} }
LambdaQueryWrapper<SysUserTenant> query = new LambdaQueryWrapper<>(); LambdaQueryWrapper<SysUserTenant> query = new LambdaQueryWrapper<>();
query.eq(SysUserTenant::getUserId,sysUser.getId()); query.eq(SysUserTenant::getUserId, sysUser.getId());
query.eq(SysUserTenant::getTenantId,tenantId); query.eq(SysUserTenant::getTenantId, tenantId);
SysUserTenant userTenant = new SysUserTenant(); SysUserTenant userTenant = new SysUserTenant();
userTenant.setStatus(CommonConstant.USER_TENANT_QUIT); userTenant.setStatus(CommonConstant.USER_TENANT_QUIT);
userTenantMapper.update(userTenant,query); userTenantMapper.update(userTenant, query);
//update-end---author:wangshuai ---date:20230111 for:[QQYUN-3951]租户用户离职重构------------ //update-end---author:wangshuai ---date:20230111 for:[QQYUN-3951]租户用户离职重构------------
//触发离职流程 //触发离职流程
LoginUser userInfo=new LoginUser(); LoginUser userInfo = new LoginUser();
BeanUtils.copyProperties(sysUser,userInfo); BeanUtils.copyProperties(sysUser, userInfo);
LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal(); LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
} }
...@@ -767,22 +773,23 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl ...@@ -767,22 +773,23 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
@Override @Override
public void updateStatusAndFlag(List<String> userIds, SysUser sysUser) { public void updateStatusAndFlag(List<String> userIds, SysUser sysUser) {
userMapper.updateStatusAndFlag(userIds,sysUser); userMapper.updateStatusAndFlag(userIds, sysUser);
} }
/** /**
* 设置登录租户 * 设置登录租户
*
* @param sysUser * @param sysUser
* @return * @return
*/ */
@Override @Override
public Result<JSONObject> setLoginTenant(SysUser sysUser, JSONObject obj, String username, Result<JSONObject> result){ public Result<JSONObject> setLoginTenant(SysUser sysUser, JSONObject obj, String username, Result<JSONObject> result) {
// update-begin--Author:sunjianlei Date:20210802 for:获取用户租户信息 // update-begin--Author:sunjianlei Date:20210802 for:获取用户租户信息
//用户有哪些租户 //用户有哪些租户
List<SysTenant> tenantList = null; List<SysTenant> tenantList = null;
//update-begin---author:wangshuai ---date:20221223 for:[QQYUN-3371]租户逻辑改造,改成关系表------------ //update-begin---author:wangshuai ---date:20221223 for:[QQYUN-3371]租户逻辑改造,改成关系表------------
List<Integer> tenantIdList = relationMapper.getTenantIdsNoStatus(sysUser.getId()); List<Integer> tenantIdList = relationMapper.getTenantIdsNoStatus(sysUser.getId());
if (null!=tenantIdList && tenantIdList.size()>0) { if (null != tenantIdList && tenantIdList.size() > 0) {
//update-end---author:wangshuai ---date:20221223 for:[QQYUN-3371]租户逻辑改造,改成关系表-------------- //update-end---author:wangshuai ---date:20221223 for:[QQYUN-3371]租户逻辑改造,改成关系表--------------
//------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------
//查询有效的租户集合 //查询有效的租户集合
...@@ -817,11 +824,11 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl ...@@ -817,11 +824,11 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
sysUser.setLoginTenantId(0); sysUser.setLoginTenantId(0);
} }
//设置用户登录缓存租户 //设置用户登录缓存租户
this.updateUserDepart(username, null,sysUser.getLoginTenantId()); this.updateUserDepart(username, null, sysUser.getLoginTenantId());
log.info(" 登录接口用户的租户ID = {}", sysUser.getLoginTenantId()); log.info(" 登录接口用户的租户ID = {}", sysUser.getLoginTenantId());
if(sysUser.getLoginTenantId()!=null){ if (sysUser.getLoginTenantId() != null) {
//登录的时候需要手工设置下会话中的租户ID,不然登录接口无法通过租户隔离查询到数据 //登录的时候需要手工设置下会话中的租户ID,不然登录接口无法通过租户隔离查询到数据
TenantContext.setTenant(sysUser.getLoginTenantId()+""); TenantContext.setTenant(sysUser.getLoginTenantId() + "");
} }
return null; return null;
} }
...@@ -829,14 +836,15 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl ...@@ -829,14 +836,15 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
/** /**
* 获取租户id * 获取租户id
*
* @param sysUser * @param sysUser
*/ */
private void setUserTenantIds(SysUser sysUser) { private void setUserTenantIds(SysUser sysUser) {
if(ObjectUtils.isNotEmpty(sysUser)) { if (ObjectUtils.isNotEmpty(sysUser)) {
List<Integer> list = relationMapper.getTenantIdsNoStatus(sysUser.getId()); List<Integer> list = relationMapper.getTenantIdsNoStatus(sysUser.getId());
if(null!=list && list.size()>0){ if (null != list && list.size() > 0) {
sysUser.setRelTenantIds(StringUtils.join(list.toArray(), ",")); sysUser.setRelTenantIds(StringUtils.join(list.toArray(), ","));
}else{ } else {
sysUser.setRelTenantIds(""); sysUser.setRelTenantIds("");
} }
} }
...@@ -844,6 +852,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl ...@@ -844,6 +852,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
/** /**
* 保存租户 * 保存租户
*
* @param userId * @param userId
* @param relTenantIds * @param relTenantIds
*/ */
...@@ -857,14 +866,14 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl ...@@ -857,14 +866,14 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
relation.setStatus(CommonConstant.STATUS_1); relation.setStatus(CommonConstant.STATUS_1);
relationMapper.insert(relation); relationMapper.insert(relation);
} }
}else{ } else {
//是否开启系统管理模块的多租户数据隔离【SAAS多租户模式】 //是否开启系统管理模块的多租户数据隔离【SAAS多租户模式】
if (MybatisPlusSaasConfig.OPEN_SYSTEM_TENANT_CONTROL) { if (MybatisPlusSaasConfig.OPEN_SYSTEM_TENANT_CONTROL) {
//update-begin---author:wangshuai ---date:20230220 for:判断当前用户是否在当前租户里面,如果不存在在新增------------ //update-begin---author:wangshuai ---date:20230220 for:判断当前用户是否在当前租户里面,如果不存在在新增------------
String tenantId = TenantContext.getTenant(); String tenantId = TenantContext.getTenant();
if(oConvertUtils.isNotEmpty(tenantId)){ if (oConvertUtils.isNotEmpty(tenantId)) {
Integer count = relationMapper.userTenantIzExist(userId, Integer.parseInt(tenantId)); Integer count = relationMapper.userTenantIzExist(userId, Integer.parseInt(tenantId));
if(count == 0){ if (count == 0) {
SysUserTenant relation = new SysUserTenant(); SysUserTenant relation = new SysUserTenant();
relation.setUserId(userId); relation.setUserId(userId);
relation.setTenantId(Integer.parseInt(tenantId)); relation.setTenantId(Integer.parseInt(tenantId));
...@@ -879,6 +888,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl ...@@ -879,6 +888,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
/** /**
* 编辑租户 * 编辑租户
*
* @param userId * @param userId
* @param relTenantIds * @param relTenantIds
*/ */
...@@ -895,7 +905,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl ...@@ -895,7 +905,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
this.saveUserTenant(userId, relTenantIds); this.saveUserTenant(userId, relTenantIds);
} else { } else {
//都不为空,需要比较,进行添加或删除 //都不为空,需要比较,进行添加或删除
if(oConvertUtils.isNotEmpty(relTenantIds) && CollectionUtils.isNotEmpty(oldTenantIds)){ if (oConvertUtils.isNotEmpty(relTenantIds) && CollectionUtils.isNotEmpty(oldTenantIds)) {
//找到新的租户id与原来的租户id不同之处,进行删除 //找到新的租户id与原来的租户id不同之处,进行删除
String[] relTenantIdArray = relTenantIds.split(SymbolConstant.COMMA); String[] relTenantIdArray = relTenantIds.split(SymbolConstant.COMMA);
List<String> relTenantIdList = Arrays.asList(relTenantIdArray); List<String> relTenantIdList = Arrays.asList(relTenantIdArray);
...@@ -913,20 +923,20 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl ...@@ -913,20 +923,20 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
/** /**
* 删除租户通过用户id * 删除租户通过用户id
*
* @param tenantId * @param tenantId
* @param userId * @param userId
*/ */
private void deleteTenantByUserId(String userId,Integer tenantId){ private void deleteTenantByUserId(String userId, Integer tenantId) {
LambdaQueryWrapper<SysUserTenant> query = new LambdaQueryWrapper<>(); LambdaQueryWrapper<SysUserTenant> query = new LambdaQueryWrapper<>();
query.eq(SysUserTenant::getUserId, userId); query.eq(SysUserTenant::getUserId, userId);
if(oConvertUtils.isNotEmpty(tenantId)){ if (oConvertUtils.isNotEmpty(tenantId)) {
query.eq(SysUserTenant::getTenantId, tenantId); query.eq(SysUserTenant::getTenantId, tenantId);
} }
relationMapper.delete(query); relationMapper.delete(query);
} }
@Override @Override
public void batchEditUsers(JSONObject json) { public void batchEditUsers(JSONObject json) {
String userIds = json.getString("userIds"); String userIds = json.getString("userIds");
...@@ -937,27 +947,27 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl ...@@ -937,27 +947,27 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
String post = json.getString("post"); String post = json.getString("post");
//工作地点? 没有这个字段 //工作地点? 没有这个字段
String workAddress = json.getString("workAddress"); String workAddress = json.getString("workAddress");
if(oConvertUtils.isNotEmpty(post)) { if (oConvertUtils.isNotEmpty(post)) {
LambdaUpdateWrapper<SysUser> updateWrapper = new UpdateWrapper<SysUser>().lambda() LambdaUpdateWrapper<SysUser> updateWrapper = new UpdateWrapper<SysUser>().lambda()
.in(SysUser::getId, idList) .in(SysUser::getId, idList)
.set(SysUser::getPost, post); .set(SysUser::getPost, post);
this.update(updateWrapper); this.update(updateWrapper);
} }
if(oConvertUtils.isNotEmpty(selecteddeparts)) { if (oConvertUtils.isNotEmpty(selecteddeparts)) {
//查询当前租户的部门列表 //查询当前租户的部门列表
Integer currentTenantId = oConvertUtils.getInt(TenantContext.getTenant(), 0); Integer currentTenantId = oConvertUtils.getInt(TenantContext.getTenant(), 0);
LambdaQueryWrapper<SysDepart> departQuery = new LambdaQueryWrapper<SysDepart>() LambdaQueryWrapper<SysDepart> departQuery = new LambdaQueryWrapper<SysDepart>()
.eq(SysDepart::getTenantId, currentTenantId); .eq(SysDepart::getTenantId, currentTenantId);
List<SysDepart> departList = sysDepartMapper.selectList(departQuery); List<SysDepart> departList = sysDepartMapper.selectList(departQuery);
if(departList==null || departList.size()==0){ if (departList == null || departList.size() == 0) {
log.error("batchEditUsers 根据租户ID没有找到部门>"+currentTenantId); log.error("batchEditUsers 根据租户ID没有找到部门>" + currentTenantId);
return; return;
} }
List<String> departIdList = new ArrayList<String>(); List<String> departIdList = new ArrayList<String>();
for(SysDepart depart: departList){ for (SysDepart depart : departList) {
if(depart!=null){ if (depart != null) {
String id = depart.getId(); String id = depart.getId();
if(oConvertUtils.isNotEmpty(id)){ if (oConvertUtils.isNotEmpty(id)) {
departIdList.add(id); departIdList.add(id);
} }
} }
...@@ -972,7 +982,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl ...@@ -972,7 +982,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
//再新增 //再新增
for (String deaprtId : arr) { for (String deaprtId : arr) {
for(String userId: idList){ for (String userId : idList) {
SysUserDepart userDepart = new SysUserDepart(userId, deaprtId); SysUserDepart userDepart = new SysUserDepart(userId, deaprtId);
sysUserDepartMapper.insert(userDepart); sysUserDepartMapper.insert(userDepart);
} }
...@@ -983,34 +993,34 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl ...@@ -983,34 +993,34 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
@Override @Override
public DepartAndUserInfo searchByKeyword(String keyword) { public DepartAndUserInfo searchByKeyword(String keyword) {
DepartAndUserInfo departAndUserInfo = new DepartAndUserInfo(); DepartAndUserInfo departAndUserInfo = new DepartAndUserInfo();
if(oConvertUtils.isNotEmpty(keyword)){ if (oConvertUtils.isNotEmpty(keyword)) {
LambdaQueryWrapper<SysUser> query1 = new LambdaQueryWrapper<SysUser>() LambdaQueryWrapper<SysUser> query1 = new LambdaQueryWrapper<SysUser>()
.like(SysUser::getRealname, keyword); .like(SysUser::getRealname, keyword);
String str = oConvertUtils.getString(TenantContext.getTenant(), "0"); String str = oConvertUtils.getString(TenantContext.getTenant(), "0");
Integer tenantId = Integer.valueOf(str); Integer tenantId = Integer.valueOf(str);
if(MybatisPlusSaasConfig.OPEN_SYSTEM_TENANT_CONTROL){ if (MybatisPlusSaasConfig.OPEN_SYSTEM_TENANT_CONTROL) {
List<String> userIds = userTenantMapper.getUserIdsByTenantId(tenantId); List<String> userIds = userTenantMapper.getUserIdsByTenantId(tenantId);
if (oConvertUtils.listIsNotEmpty(userIds)) { if (oConvertUtils.listIsNotEmpty(userIds)) {
query1.in(SysUser::getId, userIds); query1.in(SysUser::getId, userIds);
}else{ } else {
query1.eq(SysUser::getId, ""); query1.eq(SysUser::getId, "");
} }
} }
List<SysUser> list1 = this.baseMapper.selectList(query1); List<SysUser> list1 = this.baseMapper.selectList(query1);
if(list1!=null && list1.size()>0){ if (list1 != null && list1.size() > 0) {
List<UserAvatar> userList = list1.stream().map(v -> new UserAvatar(v)).collect(Collectors.toList()); List<UserAvatar> userList = list1.stream().map(v -> new UserAvatar(v)).collect(Collectors.toList());
departAndUserInfo.setUserList(userList); departAndUserInfo.setUserList(userList);
} }
LambdaQueryWrapper<SysDepart> query2 = new LambdaQueryWrapper<SysDepart>() LambdaQueryWrapper<SysDepart> query2 = new LambdaQueryWrapper<SysDepart>()
.like(SysDepart::getDepartName, keyword); .like(SysDepart::getDepartName, keyword);
if(MybatisPlusSaasConfig.OPEN_SYSTEM_TENANT_CONTROL){ if (MybatisPlusSaasConfig.OPEN_SYSTEM_TENANT_CONTROL) {
query2.eq(SysDepart::getTenantId, tenantId); query2.eq(SysDepart::getTenantId, tenantId);
} }
List<SysDepart> list2 = sysDepartMapper.selectList(query2); List<SysDepart> list2 = sysDepartMapper.selectList(query2);
if(list2!=null && list2.size()>0){ if (list2 != null && list2.size() > 0) {
List<DepartInfo> departList = new ArrayList<>(); List<DepartInfo> departList = new ArrayList<>();
for(SysDepart depart: list2){ for (SysDepart depart : list2) {
List<String> orgName = new ArrayList<>(); List<String> orgName = new ArrayList<>();
List<String> orgId = new ArrayList<>(); List<String> orgId = new ArrayList<>();
getParentDepart(depart, orgName, orgId); getParentDepart(depart, orgName, orgId);
...@@ -1029,10 +1039,10 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl ...@@ -1029,10 +1039,10 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
@Override @Override
public UpdateDepartInfo getUpdateDepartInfo(String departId) { public UpdateDepartInfo getUpdateDepartInfo(String departId) {
SysDepart depart = sysDepartMapper.selectById(departId); SysDepart depart = sysDepartMapper.selectById(departId);
if(depart!=null){ if (depart != null) {
UpdateDepartInfo info = new UpdateDepartInfo(depart); UpdateDepartInfo info = new UpdateDepartInfo(depart);
List<SysDepart> subList = sysDepartMapper.queryDeptByPid(departId); List<SysDepart> subList = sysDepartMapper.queryDeptByPid(departId);
if(subList!=null && subList.size()>0){ if (subList != null && subList.size() > 0) {
info.setHasSub(true); info.setHasSub(true);
} }
//获取部门负责人信息 //获取部门负责人信息
...@@ -1040,7 +1050,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl ...@@ -1040,7 +1050,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
.eq(SysUser::getUserIdentity, 2) .eq(SysUser::getUserIdentity, 2)
.like(SysUser::getDepartIds, depart.getId()); .like(SysUser::getDepartIds, depart.getId());
List<SysUser> userList = this.baseMapper.selectList(query); List<SysUser> userList = this.baseMapper.selectList(query);
if(userList!=null && userList.size()>0){ if (userList != null && userList.size() > 0) {
List<String> idList = userList.stream().map(i -> i.getId()).collect(Collectors.toList()); List<String> idList = userList.stream().map(i -> i.getId()).collect(Collectors.toList());
info.setChargePersonList(idList); info.setChargePersonList(idList);
} }
...@@ -1053,12 +1063,12 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl ...@@ -1053,12 +1063,12 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
public void doUpdateDepartInfo(UpdateDepartInfo info) { public void doUpdateDepartInfo(UpdateDepartInfo info) {
String departId = info.getDepartId(); String departId = info.getDepartId();
SysDepart depart = sysDepartMapper.selectById(departId); SysDepart depart = sysDepartMapper.selectById(departId);
if(depart!=null){ if (depart != null) {
//修改部门信息-上级和部门名称 //修改部门信息-上级和部门名称
if(!depart.getParentId().equals(info.getParentId())){ if (!depart.getParentId().equals(info.getParentId())) {
String pid = info.getParentId(); String pid = info.getParentId();
SysDepart parentDepart = sysDepartMapper.selectById(pid); SysDepart parentDepart = sysDepartMapper.selectById(pid);
if(parentDepart!=null){ if (parentDepart != null) {
String orgCode = getNextOrgCode(pid); String orgCode = getNextOrgCode(pid);
depart.setOrgCode(orgCode); depart.setOrgCode(orgCode);
depart.setParentId(pid); depart.setParentId(pid);
...@@ -1071,20 +1081,20 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl ...@@ -1071,20 +1081,20 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
List<String> departChargeUserIdList = departChargeUsers.stream().map(i -> i.getId()).collect(Collectors.toList()); List<String> departChargeUserIdList = departChargeUsers.stream().map(i -> i.getId()).collect(Collectors.toList());
//修改部门负责人 //修改部门负责人
List<String> userIdList = info.getChargePersonList(); List<String> userIdList = info.getChargePersonList();
if(userIdList!=null && userIdList.size()>0){ if (userIdList != null && userIdList.size() > 0) {
for(String userId: userIdList){ for (String userId : userIdList) {
SysUser user = this.baseMapper.selectById(userId); SysUser user = this.baseMapper.selectById(userId);
if(user!=null){ if (user != null) {
departChargeUserIdList.remove(user.getId()); departChargeUserIdList.remove(user.getId());
user.setUserIdentity(2); user.setUserIdentity(2);
String departIds = user.getDepartIds(); String departIds = user.getDepartIds();
if(oConvertUtils.isEmpty(departIds)){ if (oConvertUtils.isEmpty(departIds)) {
user.setDepartIds(departId); user.setDepartIds(departId);
}else{ } else {
List<String> list = new ArrayList<String>(Arrays.asList(departIds.split(","))); List<String> list = new ArrayList<String>(Arrays.asList(departIds.split(",")));
if(list.indexOf(departId)>=0){ if (list.indexOf(departId) >= 0) {
continue; continue;
}else{ } else {
list.add(departId); list.add(departId);
String newDepartIds = String.join(",", list); String newDepartIds = String.join(",", list);
user.setDepartIds(newDepartIds); user.setDepartIds(newDepartIds);
...@@ -1094,9 +1104,9 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl ...@@ -1094,9 +1104,9 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
} }
} }
//删除 //删除
for(String chargeUserId: departChargeUserIdList){ for (String chargeUserId : departChargeUserIdList) {
for(SysUser chargeUser: departChargeUsers){ for (SysUser chargeUser : departChargeUsers) {
if(chargeUser.getId().equals(chargeUserId)){ if (chargeUser.getId().equals(chargeUserId)) {
String departIds = chargeUser.getDepartIds(); String departIds = chargeUser.getDepartIds();
List<String> list = new ArrayList<String>(Arrays.asList(departIds.split(","))); List<String> list = new ArrayList<String>(Arrays.asList(departIds.split(",")));
list.remove(departId); list.remove(departId);
...@@ -1112,23 +1122,23 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl ...@@ -1112,23 +1122,23 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
} }
} }
private List<SysUser> queryDepartChargePersons(String departId){ private List<SysUser> queryDepartChargePersons(String departId) {
List<SysUser> result = new ArrayList<>(); List<SysUser> result = new ArrayList<>();
LambdaQueryWrapper<SysUserDepart> query1 = new LambdaQueryWrapper<SysUserDepart>() LambdaQueryWrapper<SysUserDepart> query1 = new LambdaQueryWrapper<SysUserDepart>()
.eq(SysUserDepart::getDepId, departId); .eq(SysUserDepart::getDepId, departId);
List<SysUserDepart> list1 = sysUserDepartMapper.selectList(query1); List<SysUserDepart> list1 = sysUserDepartMapper.selectList(query1);
if(list1!=null && list1.size()>0){ if (list1 != null && list1.size() > 0) {
List<String> userIdList = list1.stream().map(item -> item.getUserId()).collect(Collectors.toList()); List<String> userIdList = list1.stream().map(item -> item.getUserId()).collect(Collectors.toList());
LambdaQueryWrapper<SysUser> query2 = new LambdaQueryWrapper<SysUser>() LambdaQueryWrapper<SysUser> query2 = new LambdaQueryWrapper<SysUser>()
.in(SysUser::getId, userIdList); .in(SysUser::getId, userIdList);
List<SysUser> userList = this.baseMapper.selectList(query2); List<SysUser> userList = this.baseMapper.selectList(query2);
if(userList!=null && userList.size()>0){ if (userList != null && userList.size() > 0) {
for(SysUser user: userList){ for (SysUser user : userList) {
Integer identity = user.getUserIdentity(); Integer identity = user.getUserIdentity();
String deps = user.getDepartIds(); String deps = user.getDepartIds();
if(identity!=null && identity==2){ if (identity != null && identity == 2) {
if(oConvertUtils.isNotEmpty(deps)){ if (oConvertUtils.isNotEmpty(deps)) {
if(deps.indexOf(departId)>=0){ if (deps.indexOf(departId) >= 0) {
result.add(user); result.add(user);
} }
} }
...@@ -1141,12 +1151,13 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl ...@@ -1141,12 +1151,13 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
/** /**
* 变更父级部门 修改编码 * 变更父级部门 修改编码
*
* @param parentId * @param parentId
* @return * @return
*/ */
private String getNextOrgCode(String parentId){ private String getNextOrgCode(String parentId) {
JSONObject formData = new JSONObject(); JSONObject formData = new JSONObject();
formData.put("parentId",parentId); formData.put("parentId", parentId);
String[] codeArray = (String[]) FillRuleUtil.executeRule(FillRuleConstant.DEPART, formData); String[] codeArray = (String[]) FillRuleUtil.executeRule(FillRuleConstant.DEPART, formData);
return codeArray[0]; return codeArray[0];
} }
...@@ -1157,36 +1168,36 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl ...@@ -1157,36 +1168,36 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
String departId = json.getString("departId"); String departId = json.getString("departId");
boolean status = json.getBoolean("status"); boolean status = json.getBoolean("status");
SysUser user = this.getById(userId); SysUser user = this.getById(userId);
if(user!=null){ if (user != null) {
String ids = user.getDepartIds(); String ids = user.getDepartIds();
if(status==true){ if (status == true) {
//设置部门负责人 //设置部门负责人
if(oConvertUtils.isEmpty(ids)){ if (oConvertUtils.isEmpty(ids)) {
user.setDepartIds(departId); user.setDepartIds(departId);
}else{ } else {
List<String> list = new ArrayList<String>(Arrays.asList(ids.split(","))); List<String> list = new ArrayList<String>(Arrays.asList(ids.split(",")));
if(list.indexOf(departId)>=0){ if (list.indexOf(departId) >= 0) {
//啥也不干 //啥也不干
}else{ } else {
list.add(departId); list.add(departId);
String newIds = String.join(",", list); String newIds = String.join(",", list);
user.setDepartIds(newIds); user.setDepartIds(newIds);
} }
} }
}else{ } else {
// 取消负责人 // 取消负责人
if(oConvertUtils.isNotEmpty(ids)){ if (oConvertUtils.isNotEmpty(ids)) {
List<String> list = new ArrayList<String>(); List<String> list = new ArrayList<String>();
for(String temp: ids.split(",")){ for (String temp : ids.split(",")) {
if(oConvertUtils.isEmpty(temp)){ if (oConvertUtils.isEmpty(temp)) {
continue; continue;
} }
if(!temp.equals(departId)){ if (!temp.equals(departId)) {
list.add(temp); list.add(temp);
} }
} }
String newIds = ""; String newIds = "";
if(list.size()>0){ if (list.size() > 0) {
newIds = String.join(",", list); newIds = String.join(",", list);
} }
user.setDepartIds(newIds); user.setDepartIds(newIds);
...@@ -1198,15 +1209,16 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl ...@@ -1198,15 +1209,16 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
/** /**
* 找上级部门 * 找上级部门
*
* @param depart * @param depart
* @param orgName * @param orgName
* @param orgId * @param orgId
*/ */
private void getParentDepart(SysDepart depart,List<String> orgName,List<String> orgId){ private void getParentDepart(SysDepart depart, List<String> orgName, List<String> orgId) {
String pid = depart.getParentId(); String pid = depart.getParentId();
orgName.add(0, depart.getDepartName()); orgName.add(0, depart.getDepartName());
orgId.add(0, depart.getId()); orgId.add(0, depart.getId());
if(oConvertUtils.isNotEmpty(pid)){ if (oConvertUtils.isNotEmpty(pid)) {
SysDepart temp = sysDepartMapper.selectById(pid); SysDepart temp = sysDepartMapper.selectById(pid);
getParentDepart(temp, orgName, orgId); getParentDepart(temp, orgName, orgId);
} }
...@@ -1214,7 +1226,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl ...@@ -1214,7 +1226,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
@CacheEvict(value={CacheConstant.SYS_USERS_CACHE}, allEntries=true) @CacheEvict(value = {CacheConstant.SYS_USERS_CACHE}, allEntries = true)
public void editTenantUser(SysUser sysUser, String tenantId, String departs, String roles) { public void editTenantUser(SysUser sysUser, String tenantId, String departs, String roles) {
SysUser user = new SysUser(); SysUser user = new SysUser();
user.setWorkNo(sysUser.getWorkNo()); user.setWorkNo(sysUser.getWorkNo());
...@@ -1227,6 +1239,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl ...@@ -1227,6 +1239,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
/** /**
* 修改租户下的部门 * 修改租户下的部门
*
* @param departs * @param departs
*/ */
public void updateTenantDepart(SysUser user, String tenantId, String departs) { public void updateTenantDepart(SysUser user, String tenantId, String departs) {
......
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