|
@@ -5,6 +5,7 @@ import cn.hutool.core.util.ObjectUtil;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.fjhx.tenant.entity.tenant.dto.BindingMenuDto;
|
|
|
import com.fjhx.tenant.entity.tenant.dto.TenantInfoDto;
|
|
|
import com.fjhx.tenant.entity.tenant.dto.TenantInfoSelectDto;
|
|
|
import com.fjhx.tenant.entity.tenant.po.TenantInfo;
|
|
@@ -18,6 +19,8 @@ import com.ruoyi.common.exception.ServiceException;
|
|
|
import com.ruoyi.common.utils.SecurityUtils;
|
|
|
import com.ruoyi.common.utils.wrapper.IWrapper;
|
|
|
import com.ruoyi.common.utils.wrapper.SqlField;
|
|
|
+import com.ruoyi.system.domain.SysRoleMenu;
|
|
|
+import com.ruoyi.system.mapper.SysRoleMenuMapper;
|
|
|
import com.ruoyi.system.service.ISysDeptService;
|
|
|
import com.ruoyi.system.service.ISysRoleService;
|
|
|
import com.ruoyi.system.service.ISysUserService;
|
|
@@ -51,6 +54,26 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoMapper, TenantI
|
|
|
@Autowired
|
|
|
private ISysRoleService sysRoleService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private SysRoleMenuMapper sysRoleMenuMapper;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<TenantInfo> getList(TenantInfoSelectDto dto) {
|
|
|
+ IWrapper<TenantInfo> wrapper = getWrapper();
|
|
|
+ wrapper.orderByDesc(TenantInfo::getId)
|
|
|
+ .eq(TenantInfo::getStatus, dto.getStatus())
|
|
|
+ .eq(TenantInfo::getFlowStatus, dto.getFlowStatus())
|
|
|
+ .like(TenantInfo::getTenantId, dto.getTenantId())
|
|
|
+ .like(TenantInfo::getEnterpriseName, dto.getEnterpriseName())
|
|
|
+ .keyword(dto,
|
|
|
+ new SqlField(TenantInfo::getEnterpriseName),
|
|
|
+ new SqlField(TenantInfo::getTenantId)
|
|
|
+ );
|
|
|
+
|
|
|
+ return list(wrapper);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
public Page<TenantInfoVo> getPage(TenantInfoSelectDto dto) {
|
|
|
IWrapper<TenantInfo> wrapper = getWrapper();
|
|
|
wrapper.orderByDesc("ti", TenantInfo::getId)
|
|
@@ -154,4 +177,55 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoMapper, TenantI
|
|
|
this.removeById(id);
|
|
|
}
|
|
|
|
|
|
+ @Transactional
|
|
|
+ @Override
|
|
|
+ public void bindingMenu(BindingMenuDto dto) {
|
|
|
+ String tenantId = dto.getTenantId();
|
|
|
+ TenantInfo tenantInfo = this.getOne(q -> q.eq(TenantInfo::getTenantId, tenantId));
|
|
|
+ if (tenantInfo == null) {
|
|
|
+ throw new ServiceException("未找到租户");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 查询租户下的所有角色
|
|
|
+ List<SysRole> sysRoleList = sysRoleService.list(Wrappers.<SysRole>lambdaQuery().eq(SysRole::getTenantId, tenantId));
|
|
|
+ if (sysRoleList.size() == 0) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ List<Long> roleIdList = sysRoleList.stream().map(SysRole::getRoleId).collect(Collectors.toList());
|
|
|
+
|
|
|
+ // 删除租户所有角色除此之外的菜单
|
|
|
+ sysRoleMenuMapper.removeOtherMenu(roleIdList, dto.getMenuIdList());
|
|
|
+
|
|
|
+ // 添加租户管理员对应权限
|
|
|
+ Long adminRoleId = null;
|
|
|
+ for (SysRole sysRole : sysRoleList) {
|
|
|
+ String roleKey = sysRole.getRoleKey();
|
|
|
+ if ("admin".equals(roleKey)) {
|
|
|
+ adminRoleId = sysRole.getRoleId();
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (adminRoleId == null) {
|
|
|
+ throw new ServiceException("没有找到租户管理员角色");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 找出原有菜单
|
|
|
+ List<Long> adminMenuIdList = sysRoleMenuMapper.getMenuIdByRoleId(adminRoleId);
|
|
|
+
|
|
|
+ // 新增菜单
|
|
|
+ final Long role = adminRoleId;
|
|
|
+ List<SysRoleMenu> sysRoleMenuList = dto.getMenuIdList().stream()
|
|
|
+ .filter(item -> !adminMenuIdList.contains(item))
|
|
|
+ .map(item -> {
|
|
|
+ SysRoleMenu sysRoleMenu = new SysRoleMenu();
|
|
|
+ sysRoleMenu.setMenuId(item);
|
|
|
+ sysRoleMenu.setRoleId(role);
|
|
|
+ return sysRoleMenu;
|
|
|
+ })
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ sysRoleMenuMapper.batchRoleMenu(sysRoleMenuList);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
}
|