|
@@ -3,18 +3,21 @@ package com.zhongzheng.modules.system.service.impl;
|
|
import cn.hutool.core.lang.Validator;
|
|
import cn.hutool.core.lang.Validator;
|
|
import cn.hutool.core.util.StrUtil;
|
|
import cn.hutool.core.util.StrUtil;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.zhongzheng.common.annotation.DataScope;
|
|
import com.zhongzheng.common.annotation.DataScope;
|
|
import com.zhongzheng.common.constant.UserConstants;
|
|
import com.zhongzheng.common.constant.UserConstants;
|
|
import com.zhongzheng.common.core.domain.entity.SysRole;
|
|
import com.zhongzheng.common.core.domain.entity.SysRole;
|
|
import com.zhongzheng.common.exception.CustomException;
|
|
import com.zhongzheng.common.exception.CustomException;
|
|
import com.zhongzheng.common.utils.spring.SpringUtils;
|
|
import com.zhongzheng.common.utils.spring.SpringUtils;
|
|
|
|
+import com.zhongzheng.modules.system.domain.SysRoleBusiness;
|
|
import com.zhongzheng.modules.system.domain.SysRoleDept;
|
|
import com.zhongzheng.modules.system.domain.SysRoleDept;
|
|
import com.zhongzheng.modules.system.domain.SysRoleMenu;
|
|
import com.zhongzheng.modules.system.domain.SysRoleMenu;
|
|
import com.zhongzheng.modules.system.domain.SysUserRole;
|
|
import com.zhongzheng.modules.system.domain.SysUserRole;
|
|
import com.zhongzheng.modules.system.mapper.SysRoleDeptMapper;
|
|
import com.zhongzheng.modules.system.mapper.SysRoleDeptMapper;
|
|
import com.zhongzheng.modules.system.mapper.SysRoleMapper;
|
|
import com.zhongzheng.modules.system.mapper.SysRoleMapper;
|
|
import com.zhongzheng.modules.system.mapper.SysRoleMenuMapper;
|
|
import com.zhongzheng.modules.system.mapper.SysRoleMenuMapper;
|
|
|
|
+import com.zhongzheng.modules.system.service.ISysRoleBusinessService;
|
|
import com.zhongzheng.modules.system.service.ISysRoleService;
|
|
import com.zhongzheng.modules.system.service.ISysRoleService;
|
|
import com.zhongzheng.modules.system.mapper.SysUserRoleMapper;
|
|
import com.zhongzheng.modules.system.mapper.SysUserRoleMapper;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -40,6 +43,9 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
|
|
@Autowired
|
|
@Autowired
|
|
private SysRoleDeptMapper roleDeptMapper;
|
|
private SysRoleDeptMapper roleDeptMapper;
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ private ISysRoleBusinessService iSysRoleBusinessService;
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 根据条件分页查询角色数据
|
|
* 根据条件分页查询角色数据
|
|
*
|
|
*
|
|
@@ -184,6 +190,15 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
|
|
public int insertRole(SysRole role) {
|
|
public int insertRole(SysRole role) {
|
|
// 新增角色信息
|
|
// 新增角色信息
|
|
baseMapper.insert(role);
|
|
baseMapper.insert(role);
|
|
|
|
+ if(role.getBusinessIds()!=null&&role.getBusinessIds().size()>0){
|
|
|
|
+ boolean result = false;
|
|
|
|
+ for (Long businessId : role.getBusinessIds()) {
|
|
|
|
+ SysRoleBusiness add = new SysRoleBusiness();
|
|
|
|
+ add.setBusinessId(businessId);
|
|
|
|
+ add.setRoleId(role.getRoleId());
|
|
|
|
+ iSysRoleBusinessService.save(add);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
return insertRoleMenu(role);
|
|
return insertRoleMenu(role);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -200,6 +215,18 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
|
|
baseMapper.updateById(role);
|
|
baseMapper.updateById(role);
|
|
// 删除角色与菜单关联
|
|
// 删除角色与菜单关联
|
|
roleMenuMapper.delete(new LambdaQueryWrapper<SysRoleMenu>().eq(SysRoleMenu::getRoleId, role.getRoleId()));
|
|
roleMenuMapper.delete(new LambdaQueryWrapper<SysRoleMenu>().eq(SysRoleMenu::getRoleId, role.getRoleId()));
|
|
|
|
+ if(role.getBusinessIds()!=null&&role.getBusinessIds().size()>0){
|
|
|
|
+ LambdaQueryWrapper<SysRoleBusiness> lqw = Wrappers.lambdaQuery();
|
|
|
|
+ lqw.eq(SysRoleBusiness::getRoleId,role.getRoleId());
|
|
|
|
+ iSysRoleBusinessService.remove(lqw);
|
|
|
|
+ for (Long businessId : role.getBusinessIds()) {
|
|
|
|
+ SysRoleBusiness add = new SysRoleBusiness();
|
|
|
|
+ add.setBusinessId(businessId);
|
|
|
|
+ add.setRoleId(role.getRoleId());
|
|
|
|
+ iSysRoleBusinessService.save(add);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
return insertRoleMenu(role);
|
|
return insertRoleMenu(role);
|
|
}
|
|
}
|
|
|
|
|