|
@@ -1,10 +1,13 @@
|
|
package org.jeecg.modules.system.service.impl;
|
|
package org.jeecg.modules.system.service.impl;
|
|
|
|
|
|
import cn.hutool.system.UserInfo;
|
|
import cn.hutool.system.UserInfo;
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import org.apache.shiro.SecurityUtils;
|
|
import org.apache.shiro.SecurityUtils;
|
|
|
|
+import org.jeecg.common.constant.CommonConstant;
|
|
import org.jeecg.common.system.vo.LoginUser;
|
|
import org.jeecg.common.system.vo.LoginUser;
|
|
import org.jeecg.common.util.RedisUtil;
|
|
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.controller.SysUserController;
|
|
import org.jeecg.modules.system.entity.*;
|
|
import org.jeecg.modules.system.entity.*;
|
|
import org.jeecg.modules.system.entity.AppmanageEntity.*;
|
|
import org.jeecg.modules.system.entity.AppmanageEntity.*;
|
|
@@ -29,6 +32,8 @@ import java.util.stream.Collectors;
|
|
@Service
|
|
@Service
|
|
public class AppmanageServiceImpl implements AppmanageService {
|
|
public class AppmanageServiceImpl implements AppmanageService {
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ private BaseCommonService baseCommonService;
|
|
|
|
|
|
// 操作用户与角色关系的(授予角色,撤销角色)
|
|
// 操作用户与角色关系的(授予角色,撤销角色)
|
|
@Autowired
|
|
@Autowired
|
|
@@ -130,7 +135,6 @@ public class AppmanageServiceImpl implements AppmanageService {
|
|
AppUserInfo userInfo = new AppUserInfo();
|
|
AppUserInfo userInfo = new AppUserInfo();
|
|
userInfo.setAppid(appid);
|
|
userInfo.setAppid(appid);
|
|
userInfo.setUserid(userid);
|
|
userInfo.setUserid(userid);
|
|
- userInfo.setRoles(roleid);
|
|
|
|
useridlist.add(userid);
|
|
useridlist.add(userid);
|
|
userInfoMapper.insert(userInfo);
|
|
userInfoMapper.insert(userInfo);
|
|
});
|
|
});
|
|
@@ -145,8 +149,10 @@ public class AppmanageServiceImpl implements AppmanageService {
|
|
SysPermission sysPermission = new SysPermission();
|
|
SysPermission sysPermission = new SysPermission();
|
|
// 设置菜单名称即为应用名称
|
|
// 设置菜单名称即为应用名称
|
|
sysPermission.setName(appBaseInfo.getName());
|
|
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());
|
|
sysPermission.setUrl(appBaseInfo.getMenuInfo());
|
|
// 设置组件(即 菜单路径去掉第一个 "/")
|
|
// 设置组件(即 菜单路径去掉第一个 "/")
|
|
@@ -171,7 +177,7 @@ public class AppmanageServiceImpl implements AppmanageService {
|
|
if (!appInfo.getAppEnvInfoDTO().isEmpty()){
|
|
if (!appInfo.getAppEnvInfoDTO().isEmpty()){
|
|
System.out.println("环境信息不为空");
|
|
System.out.println("环境信息不为空");
|
|
for (AppEnvInfo appEnvInfo : appInfo.getAppEnvInfoDTO()){
|
|
for (AppEnvInfo appEnvInfo : appInfo.getAppEnvInfoDTO()){
|
|
- appEnvInfo.setAppId(appid);
|
|
|
|
|
|
+ appEnvInfo.setAppid(appid);
|
|
envInfoMapper.insert(appEnvInfo);
|
|
envInfoMapper.insert(appEnvInfo);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -183,46 +189,52 @@ public class AppmanageServiceImpl implements AppmanageService {
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * 删除应用信息
|
|
|
|
|
|
+ * 删除应用信息 - 将会删除属于该应用的角色信息、菜单信息
|
|
* @param ids 应用id集合
|
|
* @param ids 应用id集合
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|
|
|
|
+ @Transactional
|
|
@Override
|
|
@Override
|
|
public Boolean deleteAppInfo(String[] ids) {
|
|
public Boolean deleteAppInfo(String[] ids) {
|
|
// 需先判断用户是否拥有所删除的应用信息的权限(平台管理员-应用管理员)
|
|
// 需先判断用户是否拥有所删除的应用信息的权限(平台管理员-应用管理员)
|
|
// 获取当前登录用户信息
|
|
// 获取当前登录用户信息
|
|
LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
|
|
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) {
|
|
for (String id : ids) {
|
|
// 不能删除基础平台的应用信息
|
|
// 不能删除基础平台的应用信息
|
|
if (id.equals("0")) return false;
|
|
if (id.equals("0")) return false;
|
|
|
|
+ AppBaseInfo appBaseInfo = baseInfoMapper.selectById(id);
|
|
|
|
+ if (!(appBaseInfo.getAdmin().equals(loginUser.getId()))) return false;
|
|
|
|
|
|
// 删除所属该应用的基础信息、环境信息、文档信息、用户信息
|
|
// 删除所属该应用的基础信息、环境信息、文档信息、用户信息
|
|
baseInfoMapper.deleteById(id);
|
|
baseInfoMapper.deleteById(id);
|
|
envInfoMapper.delete(new QueryWrapper<AppEnvInfo>().eq("appid", id));
|
|
envInfoMapper.delete(new QueryWrapper<AppEnvInfo>().eq("appid", id));
|
|
docInfoMapper.delete(new QueryWrapper<AppDocInfo>().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));
|
|
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;
|
|
return true;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -252,7 +264,7 @@ public class AppmanageServiceImpl implements AppmanageService {
|
|
for (AppEnvInfo appEnvInfo : envInfo) {
|
|
for (AppEnvInfo appEnvInfo : envInfo) {
|
|
// 如果没有id信息,则为新增的数据
|
|
// 如果没有id信息,则为新增的数据
|
|
if (appEnvInfo.getId()==null){
|
|
if (appEnvInfo.getId()==null){
|
|
- appEnvInfo.setAppId(appid);
|
|
|
|
|
|
+ appEnvInfo.setAppid(appid);
|
|
envInfoMapper.insert(appEnvInfo);
|
|
envInfoMapper.insert(appEnvInfo);
|
|
}else { // 有id信息则为在原有数据基础上需修改的数据
|
|
}else { // 有id信息则为在原有数据基础上需修改的数据
|
|
envInfoMapper.updateById(appEnvInfo);
|
|
envInfoMapper.updateById(appEnvInfo);
|
|
@@ -281,20 +293,22 @@ public class AppmanageServiceImpl implements AppmanageService {
|
|
@Transactional
|
|
@Transactional
|
|
public Boolean editUserInfo(AppUpdataUserInfo updataUserInfo) {
|
|
public Boolean editUserInfo(AppUpdataUserInfo updataUserInfo) {
|
|
String appid = updataUserInfo.getAppid();
|
|
String appid = updataUserInfo.getAppid();
|
|
- // 删除用户 删除应用用户默认权限
|
|
|
|
|
|
+ // 移除应用用户时,将去角色收回
|
|
if (updataUserInfo.getDelUserids()!=null&&!updataUserInfo.getDelUserids().isEmpty()){
|
|
if (updataUserInfo.getDelUserids()!=null&&!updataUserInfo.getDelUserids().isEmpty()){
|
|
updataUserInfo.getDelUserids().forEach(userid -> {
|
|
updataUserInfo.getDelUserids().forEach(userid -> {
|
|
System.out.println("删除用户:"+userid);
|
|
System.out.println("删除用户:"+userid);
|
|
|
|
+ // 获取要移除的用户的信息
|
|
QueryWrapper<AppUserInfo> userInfoPOQueryWrapper = new QueryWrapper<>();
|
|
QueryWrapper<AppUserInfo> userInfoPOQueryWrapper = new QueryWrapper<>();
|
|
userInfoPOQueryWrapper.eq("appid",appid).eq("userid",userid);
|
|
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<>();
|
|
QueryWrapper<AppUserInfo> wrapper = new QueryWrapper<>();
|
|
wrapper.eq("appid",updataUserInfo.getAppid()).eq("userid",userid);
|
|
wrapper.eq("appid",updataUserInfo.getAppid()).eq("userid",userid);
|
|
userInfoMapper.delete(wrapper);
|
|
userInfoMapper.delete(wrapper);
|
|
@@ -392,7 +406,7 @@ public class AppmanageServiceImpl implements AppmanageService {
|
|
@Override
|
|
@Override
|
|
public List<AppEnvInfo> queryEnvInfoByAppId(String appid) {
|
|
public List<AppEnvInfo> queryEnvInfoByAppId(String appid) {
|
|
List<AppEnvInfo> envInfos = envInfoMapper.
|
|
List<AppEnvInfo> envInfos = envInfoMapper.
|
|
- selectList(new QueryWrapper<AppEnvInfo>().eq("app_id", appid));
|
|
|
|
|
|
+ selectList(new QueryWrapper<AppEnvInfo>().eq("appid", appid));
|
|
return envInfos;
|
|
return envInfos;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -450,25 +464,22 @@ public class AppmanageServiceImpl implements AppmanageService {
|
|
AppBaseInfo appBaseInfo = baseInfoMapper.selectById(queryParams.getAppid());
|
|
AppBaseInfo appBaseInfo = baseInfoMapper.selectById(queryParams.getAppid());
|
|
// 查询用户角色信息
|
|
// 查询用户角色信息
|
|
appUserInfos.forEach(map -> {
|
|
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"));
|
|
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);
|
|
List<SysRole> sysRoles = sysRoleMapper.selectList(sysRoleQueryWrapper);
|
|
if (!sysRoles.isEmpty()&&!roleNameInfo.isEmpty()){
|
|
if (!sysRoles.isEmpty()&&!roleNameInfo.isEmpty()){
|
|
roleNameInfo =roleNameInfo +", "+ sysRoles.stream()
|
|
roleNameInfo =roleNameInfo +", "+ sysRoles.stream()
|
|
.map(SysRole::getRoleName)
|
|
.map(SysRole::getRoleName)
|
|
.collect(Collectors.joining(", "));
|
|
.collect(Collectors.joining(", "));
|
|
|
|
+ }else {
|
|
|
|
+ roleNameInfo = sysRoles.stream()
|
|
|
|
+ .map(SysRole::getRoleName)
|
|
|
|
+ .collect(Collectors.joining(", "));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
map.put("roles", roleNameInfo);
|
|
map.put("roles", roleNameInfo);
|
|
@@ -599,28 +610,6 @@ public class AppmanageServiceImpl implements AppmanageService {
|
|
return false;
|
|
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){
|
|
private String baseInfoToUserInfoRoles(AppBaseInfo appBaseInfo, String userid){
|
|
String roleNameInfo = "";
|
|
String roleNameInfo = "";
|
|
@@ -657,4 +646,6 @@ public class AppmanageServiceImpl implements AppmanageService {
|
|
}
|
|
}
|
|
return roleNameInfo;
|
|
return roleNameInfo;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+
|
|
}
|
|
}
|