|
|
|
@ -4,7 +4,10 @@ import apelet.common.core.annotation.MyDataSource; |
|
|
|
import apelet.common.core.base.dao.BaseDaoMapper; |
|
|
|
import apelet.common.core.base.dao.BaseDaoMapper; |
|
|
|
import apelet.common.core.base.service.BaseService; |
|
|
|
import apelet.common.core.base.service.BaseService; |
|
|
|
import apelet.common.core.constant.GlobalDeletedFlag; |
|
|
|
import apelet.common.core.constant.GlobalDeletedFlag; |
|
|
|
import apelet.common.core.object.*; |
|
|
|
import apelet.common.core.object.CallResult; |
|
|
|
|
|
|
|
import apelet.common.core.object.MyOrderParam; |
|
|
|
|
|
|
|
import apelet.common.core.object.MyPageData; |
|
|
|
|
|
|
|
import apelet.common.core.object.MyPageParam; |
|
|
|
import apelet.common.core.util.MyModelUtil; |
|
|
|
import apelet.common.core.util.MyModelUtil; |
|
|
|
import apelet.common.core.util.MyPageUtil; |
|
|
|
import apelet.common.core.util.MyPageUtil; |
|
|
|
import apelet.common.ext.base.BizWidgetDatasource; |
|
|
|
import apelet.common.ext.base.BizWidgetDatasource; |
|
|
|
@ -12,18 +15,20 @@ import apelet.common.ext.constant.BizWidgetDatasourceType; |
|
|
|
import apelet.common.ext.util.BizWidgetDatasourceExtHelper; |
|
|
|
import apelet.common.ext.util.BizWidgetDatasourceExtHelper; |
|
|
|
import apelet.common.sequence.wrapper.IdGeneratorWrapper; |
|
|
|
import apelet.common.sequence.wrapper.IdGeneratorWrapper; |
|
|
|
import apelet.tenantadmin.config.DataSourceType; |
|
|
|
import apelet.tenantadmin.config.DataSourceType; |
|
|
|
import apelet.tenantadmin.upms.dao.SysRoleMapper; |
|
|
|
import apelet.tenantadmin.upms.dao.*; |
|
|
|
import apelet.tenantadmin.upms.dao.SysRoleMenuMapper; |
|
|
|
import apelet.tenantadmin.upms.model.*; |
|
|
|
import apelet.tenantadmin.upms.dao.SysUserRoleMapper; |
|
|
|
import apelet.tenantadmin.upms.service.SysDeptService; |
|
|
|
import apelet.tenantadmin.upms.model.SysRole; |
|
|
|
|
|
|
|
import apelet.tenantadmin.upms.model.SysRoleMenu; |
|
|
|
|
|
|
|
import apelet.tenantadmin.upms.model.SysUserRole; |
|
|
|
|
|
|
|
import apelet.tenantadmin.upms.service.SysMenuService; |
|
|
|
import apelet.tenantadmin.upms.service.SysMenuService; |
|
|
|
import apelet.tenantadmin.upms.service.SysRoleService; |
|
|
|
import apelet.tenantadmin.upms.service.SysRoleService; |
|
|
|
|
|
|
|
import apelet.tenantadmin.upms.vo.SysDeptVo; |
|
|
|
|
|
|
|
import apelet.tenantadmin.upms.vo.SysRoleVo; |
|
|
|
import cn.hutool.core.bean.BeanUtil; |
|
|
|
import cn.hutool.core.bean.BeanUtil; |
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil; |
|
|
|
import cn.hutool.core.util.StrUtil; |
|
|
|
import cn.hutool.core.util.StrUtil; |
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
|
|
|
|
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 com.github.pagehelper.Page; |
|
|
|
import com.github.pagehelper.page.PageMethod; |
|
|
|
import com.github.pagehelper.page.PageMethod; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
@ -55,6 +60,12 @@ public class SysRoleServiceImpl extends BaseService<SysRole, Long> implements Sy |
|
|
|
@Autowired |
|
|
|
@Autowired |
|
|
|
private SysMenuService sysMenuService; |
|
|
|
private SysMenuService sysMenuService; |
|
|
|
@Autowired |
|
|
|
@Autowired |
|
|
|
|
|
|
|
private SysRoleDeptMapper sysRoleDeptMapper; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
|
|
|
private SysDeptService sysDeptService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
|
|
|
private SysDeptMapper sysDeptMapper; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private IdGeneratorWrapper idGenerator; |
|
|
|
private IdGeneratorWrapper idGenerator; |
|
|
|
@Autowired |
|
|
|
@Autowired |
|
|
|
private BizWidgetDatasourceExtHelper bizWidgetDatasourceExtHelper; |
|
|
|
private BizWidgetDatasourceExtHelper bizWidgetDatasourceExtHelper; |
|
|
|
@ -106,7 +117,7 @@ public class SysRoleServiceImpl extends BaseService<SysRole, Long> implements Sy |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public SysRole saveNew(SysRole role, Set<Long> menuIdSet) { |
|
|
|
public SysRole saveNew(SysRole role, Set<Long> menuIdSet, Long deptId) { |
|
|
|
role.setRoleId(idGenerator.nextLongId()); |
|
|
|
role.setRoleId(idGenerator.nextLongId()); |
|
|
|
MyModelUtil.fillCommonsForInsert(role); |
|
|
|
MyModelUtil.fillCommonsForInsert(role); |
|
|
|
role.setDeletedFlag(GlobalDeletedFlag.NORMAL); |
|
|
|
role.setDeletedFlag(GlobalDeletedFlag.NORMAL); |
|
|
|
@ -119,6 +130,13 @@ public class SysRoleServiceImpl extends BaseService<SysRole, Long> implements Sy |
|
|
|
sysRoleMenuMapper.insert(roleMenu); |
|
|
|
sysRoleMenuMapper.insert(roleMenu); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// 写入角色-组织关联
|
|
|
|
|
|
|
|
if (deptId != null) { |
|
|
|
|
|
|
|
SysRoleDept roleDept = new SysRoleDept(); |
|
|
|
|
|
|
|
roleDept.setRoleId(role.getRoleId()); |
|
|
|
|
|
|
|
roleDept.setDeptId(deptId); |
|
|
|
|
|
|
|
sysRoleDeptMapper.insert(roleDept); |
|
|
|
|
|
|
|
} |
|
|
|
return role; |
|
|
|
return role; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -132,7 +150,7 @@ public class SysRoleServiceImpl extends BaseService<SysRole, Long> implements Sy |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public boolean update(SysRole role, SysRole originalRole, Set<Long> menuIdSet) { |
|
|
|
public boolean update(SysRole role, SysRole originalRole, Set<Long> menuIdSet, Long deptId) { |
|
|
|
MyModelUtil.fillCommonsForUpdate(role, originalRole); |
|
|
|
MyModelUtil.fillCommonsForUpdate(role, originalRole); |
|
|
|
if (sysRoleMapper.updateById(role) != 1) { |
|
|
|
if (sysRoleMapper.updateById(role) != 1) { |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
@ -148,6 +166,16 @@ public class SysRoleServiceImpl extends BaseService<SysRole, Long> implements Sy |
|
|
|
sysRoleMenuMapper.insert(roleMenu); |
|
|
|
sysRoleMenuMapper.insert(roleMenu); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// 先删后插角色-组织关联
|
|
|
|
|
|
|
|
SysRoleDept deleteFilter = new SysRoleDept(); |
|
|
|
|
|
|
|
deleteFilter.setRoleId(role.getRoleId()); |
|
|
|
|
|
|
|
sysRoleDeptMapper.delete(new QueryWrapper<>(deleteFilter)); |
|
|
|
|
|
|
|
if (deptId != null) { |
|
|
|
|
|
|
|
SysRoleDept roleDept = new SysRoleDept(); |
|
|
|
|
|
|
|
roleDept.setRoleId(role.getRoleId()); |
|
|
|
|
|
|
|
roleDept.setDeptId(deptId); |
|
|
|
|
|
|
|
sysRoleDeptMapper.insert(roleDept); |
|
|
|
|
|
|
|
} |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -169,6 +197,9 @@ public class SysRoleServiceImpl extends BaseService<SysRole, Long> implements Sy |
|
|
|
SysUserRole userRole = new SysUserRole(); |
|
|
|
SysUserRole userRole = new SysUserRole(); |
|
|
|
userRole.setRoleId(roleId); |
|
|
|
userRole.setRoleId(roleId); |
|
|
|
sysUserRoleMapper.delete(new QueryWrapper<>(userRole)); |
|
|
|
sysUserRoleMapper.delete(new QueryWrapper<>(userRole)); |
|
|
|
|
|
|
|
SysRoleDept roleDept = new SysRoleDept(); |
|
|
|
|
|
|
|
roleDept.setRoleId(roleId); |
|
|
|
|
|
|
|
sysRoleDeptMapper.delete(new QueryWrapper<>(roleDept)); |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -229,7 +260,7 @@ public class SysRoleServiceImpl extends BaseService<SysRole, Long> implements Sy |
|
|
|
* @return 验证结果。 |
|
|
|
* @return 验证结果。 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public CallResult verifyRelatedData(SysRole sysRole, SysRole originalSysRole, String menuIdListString) { |
|
|
|
public CallResult verifyRelatedData(SysRole sysRole, SysRole originalSysRole, String menuIdListString, Long deptId) { |
|
|
|
JSONObject jsonObject = null; |
|
|
|
JSONObject jsonObject = null; |
|
|
|
if (StringUtils.isNotBlank(menuIdListString)) { |
|
|
|
if (StringUtils.isNotBlank(menuIdListString)) { |
|
|
|
Set<Long> menuIdSet = Arrays.stream( |
|
|
|
Set<Long> menuIdSet = Arrays.stream( |
|
|
|
@ -240,6 +271,16 @@ public class SysRoleServiceImpl extends BaseService<SysRole, Long> implements Sy |
|
|
|
jsonObject = new JSONObject(); |
|
|
|
jsonObject = new JSONObject(); |
|
|
|
jsonObject.put("menuIdSet", menuIdSet); |
|
|
|
jsonObject.put("menuIdSet", menuIdSet); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// 校验组织ID(可选)
|
|
|
|
|
|
|
|
if (deptId != null) { |
|
|
|
|
|
|
|
if (!sysDeptService.existId(deptId)) { |
|
|
|
|
|
|
|
return CallResult.error("数据验证失败,关联的组织并不存在,请刷新后重试!"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (jsonObject == null) { |
|
|
|
|
|
|
|
jsonObject = new JSONObject(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
jsonObject.put("deptId", deptId); |
|
|
|
|
|
|
|
} |
|
|
|
return CallResult.ok(jsonObject); |
|
|
|
return CallResult.ok(jsonObject); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -266,4 +307,49 @@ public class SysRoleServiceImpl extends BaseService<SysRole, Long> implements Sy |
|
|
|
public List<Map<String, Object>> getSysPermCodeListWithDetail(Long roleId, String permCode) { |
|
|
|
public List<Map<String, Object>> getSysPermCodeListWithDetail(Long roleId, String permCode) { |
|
|
|
return sysRoleMapper.getSysPermCodeListWithDetail(roleId, permCode); |
|
|
|
return sysRoleMapper.getSysPermCodeListWithDetail(roleId, permCode); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public SysDeptVo getRoleDept(Long roleId) { |
|
|
|
|
|
|
|
SysRoleDept filter = new SysRoleDept(); |
|
|
|
|
|
|
|
filter.setRoleId(roleId); |
|
|
|
|
|
|
|
SysRoleDept roleDept = sysRoleDeptMapper.selectOne(new QueryWrapper<>(filter)); |
|
|
|
|
|
|
|
if (roleDept == null) { |
|
|
|
|
|
|
|
return null; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
SysDept dept = sysDeptMapper.selectById(roleDept.getDeptId()); |
|
|
|
|
|
|
|
if (dept == null) { |
|
|
|
|
|
|
|
return null; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return MyModelUtil.copyTo(dept, SysDeptVo.class); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public MyPageData<SysRoleVo> listRoleByDeptId(Long deptId, MyOrderParam orderParam, MyPageParam pageParam) { |
|
|
|
|
|
|
|
// 查询xy_sys_role_dept获取roleId集合
|
|
|
|
|
|
|
|
SysRoleDept filter = new SysRoleDept(); |
|
|
|
|
|
|
|
filter.setDeptId(deptId); |
|
|
|
|
|
|
|
List<SysRoleDept> roleDeptList = sysRoleDeptMapper.selectList(new QueryWrapper<>(filter)); |
|
|
|
|
|
|
|
if (CollUtil.isEmpty(roleDeptList)) { |
|
|
|
|
|
|
|
return new MyPageData<>(Collections.emptyList(), 0L); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
List<Long> roleIdList = roleDeptList.stream() |
|
|
|
|
|
|
|
.map(SysRoleDept::getRoleId).collect(Collectors.toList()); |
|
|
|
|
|
|
|
// 分页查询角色,使用IN条件
|
|
|
|
|
|
|
|
if (pageParam != null) { |
|
|
|
|
|
|
|
PageMethod.startPage(pageParam.getPageNum(), pageParam.getPageSize()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
String orderBy = MyOrderParam.buildOrderBy(orderParam, SysRole.class); |
|
|
|
|
|
|
|
LambdaQueryWrapper<SysRole> queryWrapper = new LambdaQueryWrapper<>(); |
|
|
|
|
|
|
|
queryWrapper.in(SysRole::getRoleId, roleIdList); |
|
|
|
|
|
|
|
if (StrUtil.isNotBlank(orderBy)) { |
|
|
|
|
|
|
|
queryWrapper.last("ORDER BY " + orderBy); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
List<SysRole> roleList = sysRoleMapper.selectList(queryWrapper); |
|
|
|
|
|
|
|
List<SysRoleVo> roleVoList = MyModelUtil.copyCollectionTo(roleList, SysRoleVo.class); |
|
|
|
|
|
|
|
long totalCount = 0L; |
|
|
|
|
|
|
|
if (roleList instanceof Page) { |
|
|
|
|
|
|
|
totalCount = ((Page<SysRole>) roleList).getTotal(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return MyPageUtil.makeResponseData(roleVoList, totalCount); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|