|
@@ -14,10 +14,9 @@ import org.jeecg.modules.system.vo.SysUserRoleVO;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.util.*;
|
|
|
import java.util.concurrent.locks.ReentrantLock;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
@@ -30,8 +29,6 @@ import java.util.stream.Collectors;
|
|
|
@Service
|
|
|
public class AppmanageServiceImpl implements AppmanageService {
|
|
|
|
|
|
- @Autowired
|
|
|
- private ISysDepartService sysDepartService;
|
|
|
|
|
|
// 操作用户与角色关系的(授予角色,撤销角色)
|
|
|
@Autowired
|
|
@@ -52,6 +49,9 @@ public class AppmanageServiceImpl implements AppmanageService {
|
|
|
@Autowired
|
|
|
private ISysRoleService sysRoleService;
|
|
|
|
|
|
+ @Resource
|
|
|
+ private SysRoleMapper sysRoleMapper;
|
|
|
+
|
|
|
@Autowired
|
|
|
private AppCustomMapper customMapper;
|
|
|
|
|
@@ -392,24 +392,27 @@ public class AppmanageServiceImpl implements AppmanageService {
|
|
|
|
|
|
@Override
|
|
|
public AppEditUserInfoEntity queryAppUser(AppUserInfoQueryParams queryParams) {
|
|
|
+ List<Map<String, Object>> appUserInfos = new ArrayList<>();
|
|
|
AppEditUserInfoEntity editUserInfoEntity = new AppEditUserInfoEntity();
|
|
|
- // 作为编辑表单时的查询
|
|
|
- if (queryParams.getAppid()!=null){
|
|
|
+ if (queryParams.getAppid()!=null){ // 作为编辑表单时的查询
|
|
|
editUserInfoEntity.setIsEdit(hasEditCurrentInfoPermission(queryParams.getAppid()));
|
|
|
QueryWrapper<AppUserInfo> queryWrapper = new QueryWrapper<>();
|
|
|
queryWrapper.select("userid");
|
|
|
queryWrapper.eq("appid",queryParams.getAppid());
|
|
|
- List<AppUserInfo> userInfoPOS = userInfoMapper.selectList(queryWrapper);
|
|
|
- if (!userInfoPOS.isEmpty()){
|
|
|
- List<String> ids = userInfoPOS.stream()
|
|
|
+ List<AppUserInfo> userInfos = userInfoMapper.selectList(queryWrapper);
|
|
|
+ if (!userInfos.isEmpty()&&!queryParams.getAppid().equals("0")){
|
|
|
+ List<String> ids = userInfos.stream()
|
|
|
.map(AppUserInfo::getUserid)
|
|
|
.collect(Collectors.toList());
|
|
|
- List<Map<String, Object>> appUserInfos = sysUserService.userComplexCondition(ids, null, queryParams.getRealname(),
|
|
|
+
|
|
|
+ appUserInfos = sysUserService.userComplexCondition(ids,
|
|
|
+ null,
|
|
|
+ queryParams.getRealname(),
|
|
|
queryParams.getDept(),
|
|
|
queryParams.getFilteruserids(),
|
|
|
queryParams.getPageNo());
|
|
|
|
|
|
- // 判断是否可进行编辑操作
|
|
|
+ // 判断当前用户是否可进行编辑操作
|
|
|
LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
|
|
|
String managerId = "";
|
|
|
Map<String, String> appManagerInfo = new HashMap<>();
|
|
@@ -422,25 +425,43 @@ public class AppmanageServiceImpl implements AppmanageService {
|
|
|
managerId = appManagerInfo.get(queryParams.getAppid());
|
|
|
}
|
|
|
editUserInfoEntity.setIsEdit(loginUser.getId().equals(managerId));
|
|
|
- editUserInfoEntity.setUserinfos(appUserInfos);
|
|
|
-
|
|
|
- // 查询应用用户角色信息
|
|
|
|
|
|
+ // 查询用户角色信息
|
|
|
+ appUserInfos.forEach(map -> {
|
|
|
+ QueryWrapper<AppUserInfo> appUserInfoQueryWrapper = new QueryWrapper<>();
|
|
|
+ appUserInfoQueryWrapper.select("roles")
|
|
|
+ .eq("userid", map.get("id")).eq("appid", queryParams.getAppid());
|
|
|
+ AppUserInfo roleInfo = userInfoMapper.selectOne(appUserInfoQueryWrapper);
|
|
|
+ // 使用 Stream API 将字符串转换为 List
|
|
|
+ if (roleInfo!=null){
|
|
|
+ List<String> list = Arrays.stream(roleInfo.getRoles().split(","))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ QueryWrapper<SysRole> sysRoleQueryWrapper = new QueryWrapper<>();
|
|
|
+ sysRoleQueryWrapper.select("role_name").in("id", list);
|
|
|
+ List<SysRole> sysRoles = sysRoleMapper.selectList(sysRoleQueryWrapper);
|
|
|
+ String roleNameInfo = sysRoles.stream()
|
|
|
+ .map(SysRole::getRoleName)
|
|
|
+ .collect(Collectors.joining(","));
|
|
|
+ map.put("roles", roleNameInfo);
|
|
|
+ }else {
|
|
|
+ map.put("roles", "");
|
|
|
+ }
|
|
|
+ });
|
|
|
}
|
|
|
- }else { // 作为添加表单时的查询
|
|
|
- List<Map<String, Object>> maps = sysUserService.userComplexCondition(queryParams.getUserids(), null,
|
|
|
+ }else { // 作为添加表单时的查询(查询全部用户), 角色分配用户时亦使用
|
|
|
+ appUserInfos = sysUserService.userComplexCondition(queryParams.getUserids(),
|
|
|
+ queryParams.getUsername(),
|
|
|
queryParams.getRealname(),
|
|
|
queryParams.getDept(),
|
|
|
queryParams.getFilteruserids(),
|
|
|
queryParams.getPageNo());
|
|
|
- editUserInfoEntity.setUserinfos(maps);
|
|
|
}
|
|
|
- List<Map<String, Object>> userinfos = editUserInfoEntity.getUserinfos();
|
|
|
// 如果查询到的用户不为空,则取appUserInfos最后一个值为total值,并将appUserInfos最后一个值删除
|
|
|
- if (!userinfos.isEmpty()){
|
|
|
- editUserInfoEntity.setTotal((Integer) userinfos.get(userinfos.size()-1).get("total"));
|
|
|
- userinfos.remove(userinfos.size()-1);
|
|
|
+ if (!appUserInfos.isEmpty()){
|
|
|
+ editUserInfoEntity.setTotal((Integer) appUserInfos.get(appUserInfos.size()-1).get("total"));
|
|
|
+ appUserInfos.remove(appUserInfos.size()-1);
|
|
|
}
|
|
|
+ editUserInfoEntity.setUserinfos(appUserInfos);
|
|
|
return editUserInfoEntity;
|
|
|
}
|
|
|
/**
|
|
@@ -550,8 +571,26 @@ public class AppmanageServiceImpl implements AppmanageService {
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- public void addAppUserRoleInfos(SysUserRole sysUserRole){
|
|
|
-
|
|
|
+ /**
|
|
|
+ * 角色分配用户时添加应用用户角色信息
|
|
|
+ * @param sysUserRole
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public boolean addAppUserRoleInfos(SysUserRole sysUserRole){
|
|
|
+ // 根据角色id查询所属的应用id
|
|
|
+ SysRole sysRole = sysRoleMapper.selectById(sysUserRole.getRoleId());
|
|
|
+ String appid = sysRole.getAppId();
|
|
|
+ QueryWrapper<AppUserInfo> appUserInfoQueryWrapper = new QueryWrapper<>();
|
|
|
+ // 先查询应用用户原来的角色信息,若为空,则直接更新,若不为空,将原角色信息与新的角色信息进行拼接后再更新,新旧角色id信息通过逗号分隔的字符串
|
|
|
+ appUserInfoQueryWrapper.eq("appid",appid).eq("userid",sysUserRole.getUserId());
|
|
|
+ AppUserInfo appUserInfo = userInfoMapper.selectOne(appUserInfoQueryWrapper);
|
|
|
+ String appUserRolesInfo = appUserInfo.getRoles();
|
|
|
+ if (appUserRolesInfo!=null){
|
|
|
+ appUserInfo.setRoles(appUserRolesInfo+","+sysUserRole.getRoleId());
|
|
|
+ }else {
|
|
|
+ appUserInfo.setRoles(sysUserRole.getRoleId());
|
|
|
+ }
|
|
|
+ int i = userInfoMapper.updateById(appUserInfo);
|
|
|
+ return i>0;
|
|
|
}
|
|
|
}
|