|
@@ -1,10 +1,13 @@
|
|
|
package org.jeecg.modules.system.service.impl;
|
|
|
|
|
|
import cn.hutool.system.UserInfo;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import org.apache.shiro.SecurityUtils;
|
|
|
+import org.jeecg.common.constant.CommonConstant;
|
|
|
import org.jeecg.common.system.vo.LoginUser;
|
|
|
import org.jeecg.common.util.RedisUtil;
|
|
|
+import org.jeecg.modules.base.service.BaseCommonService;
|
|
|
import org.jeecg.modules.system.controller.SysUserController;
|
|
|
import org.jeecg.modules.system.entity.*;
|
|
|
import org.jeecg.modules.system.entity.AppmanageEntity.*;
|
|
@@ -29,6 +32,8 @@ import java.util.stream.Collectors;
|
|
|
@Service
|
|
|
public class AppmanageServiceImpl implements AppmanageService {
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private BaseCommonService baseCommonService;
|
|
|
|
|
|
// 操作用户与角色关系的(授予角色,撤销角色)
|
|
|
@Autowired
|
|
@@ -130,7 +135,6 @@ public class AppmanageServiceImpl implements AppmanageService {
|
|
|
AppUserInfo userInfo = new AppUserInfo();
|
|
|
userInfo.setAppid(appid);
|
|
|
userInfo.setUserid(userid);
|
|
|
- userInfo.setRoles(roleid);
|
|
|
useridlist.add(userid);
|
|
|
userInfoMapper.insert(userInfo);
|
|
|
});
|
|
@@ -145,8 +149,10 @@ public class AppmanageServiceImpl implements AppmanageService {
|
|
|
SysPermission sysPermission = new SysPermission();
|
|
|
// 设置菜单名称即为应用名称
|
|
|
sysPermission.setName(appBaseInfo.getName());
|
|
|
- // 设置菜单权限编码
|
|
|
- sysPermission.setPerms("sys:appmanage:enter:"+sysPermission.getName());
|
|
|
+ // 设置菜单所属应用
|
|
|
+ sysPermission.setAppId(appid);
|
|
|
+// // 设置菜单权限编码
|
|
|
+// sysPermission.setPerms("sys:appmanage:enter:"+sysPermission.getName());
|
|
|
// 设置菜单路径
|
|
|
sysPermission.setUrl(appBaseInfo.getMenuInfo());
|
|
|
// 设置组件(即 菜单路径去掉第一个 "/")
|
|
@@ -183,46 +189,52 @@ public class AppmanageServiceImpl implements AppmanageService {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 删除应用信息
|
|
|
+ * 删除应用信息 - 将会删除属于该应用的角色信息、菜单信息
|
|
|
* @param ids 应用id集合
|
|
|
* @return
|
|
|
*/
|
|
|
+ @Transactional
|
|
|
@Override
|
|
|
public Boolean deleteAppInfo(String[] ids) {
|
|
|
// 需先判断用户是否拥有所删除的应用信息的权限(平台管理员-应用管理员)
|
|
|
// 获取当前登录用户信息
|
|
|
LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
|
|
|
- QueryWrapper<AppBaseInfo> baseInfoPOQueryWrapper = new QueryWrapper<>();
|
|
|
+
|
|
|
// 查询当前应用的应用管理员信息
|
|
|
- if (ids.length == 1){ // 删除单条信息时
|
|
|
- baseInfoPOQueryWrapper.select("admin").in("id", ids[0]);
|
|
|
- AppBaseInfo appBaseInfo = baseInfoMapper.selectOne(baseInfoPOQueryWrapper);
|
|
|
- if (!appBaseInfo.getAdmin().equals(loginUser.getId())) return false;
|
|
|
- }else { // 批量删除应用信息时,如果有一个应用不是当前登录用户所创建,则返回false
|
|
|
- for (String id : ids) {
|
|
|
- AppBaseInfo appBaseInfo = baseInfoMapper.selectById(id);
|
|
|
- if (!appBaseInfo.getAdmin().equals(loginUser.getId())) return false;
|
|
|
- }
|
|
|
- }
|
|
|
for (String id : ids) {
|
|
|
// 不能删除基础平台的应用信息
|
|
|
if (id.equals("0")) return false;
|
|
|
+ AppBaseInfo appBaseInfo = baseInfoMapper.selectById(id);
|
|
|
+ if (!(appBaseInfo.getAdmin().equals(loginUser.getId()))) return false;
|
|
|
|
|
|
// 删除所属该应用的基础信息、环境信息、文档信息、用户信息
|
|
|
baseInfoMapper.deleteById(id);
|
|
|
envInfoMapper.delete(new QueryWrapper<AppEnvInfo>().eq("appid", id));
|
|
|
docInfoMapper.delete(new QueryWrapper<AppDocInfo>().eq("appid", id));
|
|
|
+ // 简易注册下的应用信息不具备用户、菜单、权限等信息,所有不需要删除
|
|
|
+ if (appBaseInfo.getAddType().equals("easy")) break;
|
|
|
userInfoMapper.delete(new QueryWrapper<AppUserInfo>().eq("appid", id));
|
|
|
|
|
|
// 删除该应用下所创建的菜单
|
|
|
-// List<SysPermission> sysPermissions = sysPermissionService(loginUser.getUsername());
|
|
|
-// String permissionsid = sysPermissions.stream().filter(permission -> permission.getAppId().equals(id)).findFirst().get().getId();
|
|
|
-// sysPermissionService.deletePermission(permissionsid);
|
|
|
+ // 查询该应用的一级菜单
|
|
|
+ LambdaQueryWrapper<SysPermission> query = new LambdaQueryWrapper<SysPermission>();
|
|
|
+ query.eq(SysPermission::getMenuType,CommonConstant.MENU_TYPE_0);
|
|
|
+ query.eq(SysPermission::getDelFlag, CommonConstant.DEL_FLAG_0);
|
|
|
+ query.eq(SysPermission::getAppId, id);
|
|
|
+ List<SysPermission> list = sysPermissionService.list(query);
|
|
|
+ for (SysPermission sysPermission : list){
|
|
|
+ sysPermissionService.deletePermission(sysPermission.getId());
|
|
|
+ }
|
|
|
|
|
|
// 删除该应用下所创建的角色信息
|
|
|
-// sysRoleService.listRoleIdsByAppId()
|
|
|
-
|
|
|
+ String[] Approleids = sysRoleService.listRoleIdsByAppId(id);
|
|
|
+ if (Approleids!=null){
|
|
|
+ boolean tag = sysRoleService.deleteBatchRole(Approleids);
|
|
|
+ if (!tag) return false;
|
|
|
+ }
|
|
|
}
|
|
|
+ // 记录日志
|
|
|
+ baseCommonService.addLog("删除应用信息:id"+Arrays.toString(ids), CommonConstant.LOG_TYPE_2, 3 );
|
|
|
return true;
|
|
|
}
|
|
|
|
|
@@ -281,20 +293,22 @@ public class AppmanageServiceImpl implements AppmanageService {
|
|
|
@Transactional
|
|
|
public Boolean editUserInfo(AppUpdataUserInfo updataUserInfo) {
|
|
|
String appid = updataUserInfo.getAppid();
|
|
|
- // 删除用户 删除应用用户默认权限
|
|
|
+ // 移除应用用户时,将去角色收回
|
|
|
if (updataUserInfo.getDelUserids()!=null&&!updataUserInfo.getDelUserids().isEmpty()){
|
|
|
updataUserInfo.getDelUserids().forEach(userid -> {
|
|
|
System.out.println("删除用户:"+userid);
|
|
|
+ // 获取要移除的用户的信息
|
|
|
QueryWrapper<AppUserInfo> userInfoPOQueryWrapper = new QueryWrapper<>();
|
|
|
userInfoPOQueryWrapper.eq("appid",appid).eq("userid",userid);
|
|
|
- AppUserInfo userInfoPO = userInfoMapper.selectOne(userInfoPOQueryWrapper);
|
|
|
- // 先去除字符串两端的空格
|
|
|
- String userDefaultRoleId = userInfoPO.getRoles().trim();
|
|
|
- // 根据逗号分割字符串
|
|
|
- String[] parts = userDefaultRoleId.split(",");
|
|
|
- QueryWrapper<SysUserRole> queryWrapper = new QueryWrapper<SysUserRole>();
|
|
|
- queryWrapper.eq("role_id", parts[0]).eq("user_id",userid);
|
|
|
- sysUserRoleService.remove(queryWrapper);
|
|
|
+ AppUserInfo userInfo = userInfoMapper.selectOne(userInfoPOQueryWrapper);
|
|
|
+ // 获取该用户在该应用下的角色信息
|
|
|
+ List<String> roleIds = sysUserRoleService.listByAppId(appid, userid);
|
|
|
+ // 删除该用户在该应用下的角色信息
|
|
|
+ roleIds.forEach(roleId -> {
|
|
|
+ QueryWrapper<SysUserRole> queryWrapper = new QueryWrapper<SysUserRole>();
|
|
|
+ queryWrapper.eq("role_id", roleId).eq("user_id",userid);
|
|
|
+ sysUserRoleService.remove(queryWrapper);
|
|
|
+ });
|
|
|
QueryWrapper<AppUserInfo> wrapper = new QueryWrapper<>();
|
|
|
wrapper.eq("appid",updataUserInfo.getAppid()).eq("userid",userid);
|
|
|
userInfoMapper.delete(wrapper);
|
|
@@ -450,25 +464,22 @@ public class AppmanageServiceImpl implements AppmanageService {
|
|
|
AppBaseInfo appBaseInfo = baseInfoMapper.selectById(queryParams.getAppid());
|
|
|
// 查询用户角色信息
|
|
|
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);
|
|
|
- // 查询应用基础信息的相关用户信息
|
|
|
String roleNameInfo = baseInfoToUserInfoRoles(appBaseInfo, (String) map.get("id"));
|
|
|
- // 使用 Stream API 将字符串转换为 List
|
|
|
- if (roleInfo!=null){
|
|
|
- // 将应用用户表中存的的角色信息字符串转换为List
|
|
|
- List<String> list = Arrays.stream(roleInfo.getRoles().split(","))
|
|
|
- .collect(Collectors.toList());
|
|
|
- QueryWrapper<SysRole> sysRoleQueryWrapper = new QueryWrapper<>();
|
|
|
- sysRoleQueryWrapper.select("role_name").in("id", list);
|
|
|
+ List<String> roleIds = sysUserRoleService.listByAppId(queryParams.getAppid(), (String) map.get("id"));
|
|
|
+
|
|
|
+ if (!roleIds.isEmpty()){
|
|
|
// 查询角色名信息
|
|
|
+ QueryWrapper<SysRole> sysRoleQueryWrapper = new QueryWrapper<>();
|
|
|
+ sysRoleQueryWrapper.select("role_name").in("id", roleIds);
|
|
|
List<SysRole> sysRoles = sysRoleMapper.selectList(sysRoleQueryWrapper);
|
|
|
if (!sysRoles.isEmpty()&&!roleNameInfo.isEmpty()){
|
|
|
roleNameInfo =roleNameInfo +", "+ sysRoles.stream()
|
|
|
.map(SysRole::getRoleName)
|
|
|
.collect(Collectors.joining(", "));
|
|
|
+ }else {
|
|
|
+ roleNameInfo = sysRoles.stream()
|
|
|
+ .map(SysRole::getRoleName)
|
|
|
+ .collect(Collectors.joining(", "));
|
|
|
}
|
|
|
}
|
|
|
map.put("roles", roleNameInfo);
|
|
@@ -599,28 +610,6 @@ public class AppmanageServiceImpl implements AppmanageService {
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 角色分配用户时添加应用用户角色信息
|
|
|
- * @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;
|
|
|
- }
|
|
|
|
|
|
private String baseInfoToUserInfoRoles(AppBaseInfo appBaseInfo, String userid){
|
|
|
String roleNameInfo = "";
|
|
@@ -657,4 +646,6 @@ public class AppmanageServiceImpl implements AppmanageService {
|
|
|
}
|
|
|
return roleNameInfo;
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
}
|