多租户实现逻辑功能不完善问题 #4676

pull/4819/head
zhangdaiscott 2023-03-13 16:12:18 +08:00
parent b75cbcc911
commit 5417f1285a
8 changed files with 113 additions and 24 deletions

View File

@ -218,8 +218,10 @@ public class SysTenantController {
result.error500("参数为空!"); result.error500("参数为空!");
} }
//------------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------------
//是否开启系统管理模块的多租户数据隔离【SAAS多租户模式】 //获取登录用户信息
if(MybatisPlusSaasConfig.OPEN_SYSTEM_TENANT_CONTROL){ LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
//是否开启系统管理模块的多租户数据隔离【SAAS多租户模式】, admin给特权可以管理所有租户
if(MybatisPlusSaasConfig.OPEN_SYSTEM_TENANT_CONTROL && !"admin".equals(sysUser.getUsername())){
Integer loginSessionTenant = oConvertUtils.getInt(TenantContext.getTenant()); Integer loginSessionTenant = oConvertUtils.getInt(TenantContext.getTenant());
if(loginSessionTenant!=null && !loginSessionTenant.equals(Integer.valueOf(id))){ if(loginSessionTenant!=null && !loginSessionTenant.equals(Integer.valueOf(id))){
result.error500("无权限访问他人租户!"); result.error500("无权限访问他人租户!");
@ -797,4 +799,24 @@ public class SysTenantController {
TenantDepartAuthInfo info = sysTenantService.getTenantDepartAuthInfo(Integer.parseInt(id)); TenantDepartAuthInfo info = sysTenantService.getTenantDepartAuthInfo(Integer.parseInt(id));
return Result.ok(info); return Result.ok(info);
} }
/**
* ()
* @param tenantId
* @param packId
* @param status
* @param pageNo
* @param pageSize
* @return
*/
@GetMapping("/queryTenantPackUserList")
public Result<IPage<TenantPackUser>> queryTenantPackUserList(@RequestParam("tenantId") String tenantId,
@RequestParam("packId") String packId,
@RequestParam("status") Integer status,
@RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
@RequestParam(name="pageSize", defaultValue="10") Integer pageSize){
Page<TenantPackUser> page = new Page<>(pageNo,pageSize);
IPage<TenantPackUser> pageList = sysTenantService.queryTenantPackUserList(tenantId,packId,status,page);
return Result.ok(pageList);
}
} }

View File

@ -91,4 +91,14 @@ public interface SysTenantMapper extends BaseMapper<SysTenant> {
* @return * @return
*/ */
List<UserPosition> queryUserPositionList(@Param("userIdList") List<String> userIdList); List<UserPosition> queryUserPositionList(@Param("userIdList") List<String> userIdList);
/**
*
* @param page
* @param tenantId
* @param packId
* @param status
* @return
*/
List<TenantPackUser> queryTenantPackUserList(@Param("page") Page<TenantPackUser> page, @Param("tenantId") String tenantId, @Param("packId") String packId, @Param("status") Integer status);
} }

View File

@ -1,10 +1,7 @@
package org.jeecg.modules.system.mapper; package org.jeecg.modules.system.mapper;
import java.util.List;
import org.apache.ibatis.annotations.Param;
import org.jeecg.modules.system.entity.SysTenantPack;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.jeecg.modules.system.entity.SysTenantPack;
/** /**
* @Description: * @Description:

View File

@ -100,7 +100,7 @@
<select id="queryUserPositionList" resultType="org.jeecg.modules.system.vo.tenant.UserPosition"> <select id="queryUserPositionList" resultType="org.jeecg.modules.system.vo.tenant.UserPosition">
SELECT c.id as user_id, name as position_name FROM sys_user c SELECT c.id as user_id, name as position_name FROM sys_user c
join sys_user_position b on c.id = b.user_id join sys_user_position b on c.id = b.user_id
join sys_position a on a.code = b.position_code join sys_position a on a.id = b.position_id
where c.status = 1 and c.del_flag = 0 where c.status = 1 and c.del_flag = 0
and c.id in and c.id in
<foreach collection="userIdList" index="index" item="id" open="(" separator="," close=")"> <foreach collection="userIdList" index="index" item="id" open="(" separator="," close=")">
@ -108,5 +108,18 @@
</foreach> </foreach>
</select> </select>
<!--获取租户产品包用户列表-->
<select id="queryTenantPackUserList" resultType="org.jeecg.modules.system.vo.tenant.TenantPackUser">
SELECT c.id, c.username, c.realname, c.phone, c.avatar, a.pack_name, a.id as pack_id FROM sys_user c
join sys_tenant_pack_user b on c.id = b.user_id
join sys_tenant_pack a on a.id = b.pack_id
where c.status = 1
and c.del_flag = 0
and b.status = #{status}
and a.tenant_id = #{tenantId}
<if test="packId!='' and packId!=null">
and a.id = #{packId}
</if>
</select>
</mapper> </mapper>

View File

@ -1,7 +1,7 @@
package org.jeecg.modules.system.service; package org.jeecg.modules.system.service;
import org.jeecg.modules.system.entity.SysTenantPack;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import org.jeecg.modules.system.entity.SysTenantPack;
import org.jeecg.modules.system.entity.SysTenantPackUser; import org.jeecg.modules.system.entity.SysTenantPackUser;
import java.util.List; import java.util.List;

View File

@ -190,4 +190,14 @@ public interface ISysTenantService extends IService<SysTenant> {
* @param sysTenantPackUser * @param sysTenantPackUser
*/ */
void deleteApply(SysTenantPackUser sysTenantPackUser); void deleteApply(SysTenantPackUser sysTenantPackUser);
/**
*
* @param tenantId
* @param packId
* @param status
* @param page
* @return
*/
IPage<TenantPackUser> queryTenantPackUserList(String tenantId, String packId, Integer status, Page<TenantPackUser> page);
} }

View File

@ -1,6 +1,7 @@
package org.jeecg.modules.system.service.impl; package org.jeecg.modules.system.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.shiro.SecurityUtils; import org.apache.shiro.SecurityUtils;
import org.jeecg.common.constant.SymbolConstant; import org.jeecg.common.constant.SymbolConstant;
import org.jeecg.common.constant.TenantConstant; import org.jeecg.common.constant.TenantConstant;
@ -9,7 +10,6 @@ import org.jeecg.common.util.SpringContextUtils;
import org.jeecg.common.util.oConvertUtils; import org.jeecg.common.util.oConvertUtils;
import org.jeecg.modules.aop.TenantLog; import org.jeecg.modules.aop.TenantLog;
import org.jeecg.modules.system.entity.SysPackPermission; import org.jeecg.modules.system.entity.SysPackPermission;
import org.jeecg.modules.system.entity.SysTenant;
import org.jeecg.modules.system.entity.SysTenantPack; import org.jeecg.modules.system.entity.SysTenantPack;
import org.jeecg.modules.system.entity.SysTenantPackUser; import org.jeecg.modules.system.entity.SysTenantPackUser;
import org.jeecg.modules.system.mapper.SysPackPermissionMapper; import org.jeecg.modules.system.mapper.SysPackPermissionMapper;
@ -18,11 +18,8 @@ import org.jeecg.modules.system.mapper.SysTenantPackUserMapper;
import org.jeecg.modules.system.service.ISysTenantPackService; import org.jeecg.modules.system.service.ISysTenantPackService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import javax.sql.DataSource;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;

View File

@ -107,7 +107,7 @@ public class SysTenantServiceImpl extends ServiceImpl<SysTenantMapper, SysTenant
SysUserTenant relation = new SysUserTenant(); SysUserTenant relation = new SysUserTenant();
relation.setUserId(userId); relation.setUserId(userId);
relation.setTenantId(Integer.valueOf(id)); relation.setTenantId(Integer.valueOf(id));
relation.setStatus(CommonConstant.USER_TENANT_UNDER_REVIEW); relation.setStatus(CommonConstant.USER_TENANT_NORMAL);
userTenantMapper.insert(relation); userTenantMapper.insert(relation);
} }
//update-end---author:wangshuai ---date:20221223 for[QQYUN-3371]租户逻辑改造,改成关系表------------ //update-end---author:wangshuai ---date:20221223 for[QQYUN-3371]租户逻辑改造,改成关系表------------
@ -559,6 +559,46 @@ public class SysTenantServiceImpl extends ServiceImpl<SysTenantMapper, SysTenant
} }
} }
@Override
public IPage<TenantPackUser> queryTenantPackUserList(String tenantId, String packId, Integer status, Page<TenantPackUser> page) {
// 查询用户
List<TenantPackUser> userList = baseMapper.queryTenantPackUserList(page,tenantId, packId,status);
// 获取产品包下用户部门和职位
userList = getPackUserPositionAndDepart(userList);
return page.setRecords(userList);
}
/**
*
* @param userList
* @return
*/
private List<TenantPackUser> getPackUserPositionAndDepart(List<TenantPackUser> userList) {
if(userList!=null && userList.size()>0){
List<String> userIdList = userList.stream().map(i->i.getId()).collect(Collectors.toList());
// 部门
List<UserDepart> depList = baseMapper.queryUserDepartList(userIdList);
// 职位
//List<UserPosition> userPositions = baseMapper.queryUserPositionList(userIdList);
// 遍历用户 往用户中添加 部门信息和职位信息
for (TenantPackUser user : userList) {
//添加部门
for (UserDepart dep : depList) {
if (user.getId().equals(dep.getUserId())) {
user.addDepart(dep.getDepartName());
}
}
// //添加职位
// for (UserPosition userPosition : userPositions) {
// if (user.getId().equals(userPosition.getUserId())) {
// user.addPosition(userPosition.getPositionName());
// }
// }
}
}
return userList;
}
/** /**
* *
* *