mirror of https://github.com/jeecgboot/jeecg-boot
多租户实现逻辑功能不完善问题 #4676
parent
b75cbcc911
commit
5417f1285a
|
@ -67,8 +67,8 @@ public class SysTenantController {
|
|||
//@RequiresPermissions("system:tenant:list")
|
||||
@PermissionData(pageComponent = "system/TenantList")
|
||||
@RequestMapping(value = "/list", method = RequestMethod.GET)
|
||||
public Result<IPage<SysTenant>> queryPageList(SysTenant sysTenant,@RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
|
||||
@RequestParam(name="pageSize", defaultValue="10") Integer pageSize,HttpServletRequest req) {
|
||||
public Result<IPage<SysTenant>> queryPageList(SysTenant sysTenant, @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
|
||||
@RequestParam(name="pageSize", defaultValue="10") Integer pageSize, HttpServletRequest req) {
|
||||
Result<IPage<SysTenant>> result = new Result<IPage<SysTenant>>();
|
||||
//---author:zhangyafei---date:20210916-----for: 租户管理添加日期范围查询---
|
||||
Date beginDate=null;
|
||||
|
@ -104,8 +104,8 @@ public class SysTenantController {
|
|||
*/
|
||||
@GetMapping("/recycleBinPageList")
|
||||
//@RequiresPermissions("system:tenant:recycleBinPageList")
|
||||
public Result<IPage<SysTenant>> recycleBinPageList(SysTenant sysTenant,@RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
|
||||
@RequestParam(name="pageSize", defaultValue="10") Integer pageSize,HttpServletRequest req){
|
||||
public Result<IPage<SysTenant>> recycleBinPageList(SysTenant sysTenant, @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
|
||||
@RequestParam(name="pageSize", defaultValue="10") Integer pageSize, HttpServletRequest req){
|
||||
Result<IPage<SysTenant>> result = new Result<IPage<SysTenant>>();
|
||||
Page<SysTenant> page = new Page<SysTenant>(pageNo, pageSize);
|
||||
IPage<SysTenant> pageList = sysTenantService.getRecycleBinPageList(page, sysTenant);
|
||||
|
@ -218,8 +218,10 @@ public class SysTenantController {
|
|||
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());
|
||||
if(loginSessionTenant!=null && !loginSessionTenant.equals(Integer.valueOf(id))){
|
||||
result.error500("无权限访问他人租户!");
|
||||
|
@ -360,7 +362,7 @@ public class SysTenantController {
|
|||
*/
|
||||
@PutMapping("/invitationUserJoin")
|
||||
//@RequiresPermissions("system:tenant:invitation:user")
|
||||
public Result<String> invitationUserJoin(@RequestParam("ids") String ids,@RequestParam("userIds") String userIds){
|
||||
public Result<String> invitationUserJoin(@RequestParam("ids") String ids, @RequestParam("userIds") String userIds){
|
||||
sysTenantService.invitationUserJoin(ids,userIds);
|
||||
return Result.ok("邀请用户成功");
|
||||
}
|
||||
|
@ -417,7 +419,7 @@ public class SysTenantController {
|
|||
* @return
|
||||
*/
|
||||
@RequestMapping(value = "/editOwnTenant", method ={RequestMethod.PUT, RequestMethod.POST})
|
||||
public Result<SysTenant> editOwnTenant(@RequestBody SysTenant tenant,HttpServletRequest req) {
|
||||
public Result<SysTenant> editOwnTenant(@RequestBody SysTenant tenant, HttpServletRequest req) {
|
||||
Result<SysTenant> result = new Result();
|
||||
String tenantId = TokenUtils.getTenantIdByRequest(req);
|
||||
if(!tenantId.equals(tenant.getId().toString())){
|
||||
|
@ -556,7 +558,7 @@ public class SysTenantController {
|
|||
*/
|
||||
@PutMapping("/cancelTenant")
|
||||
//@RequiresPermissions("system:tenant:cancelTenant")
|
||||
public Result<String> cancelTenant(@RequestBody SysTenant sysTenant,HttpServletRequest request) {
|
||||
public Result<String> cancelTenant(@RequestBody SysTenant sysTenant, HttpServletRequest request) {
|
||||
LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
|
||||
SysTenant tenant = sysTenantService.getById(sysTenant.getId());
|
||||
if (null == tenant) {
|
||||
|
@ -638,7 +640,7 @@ public class SysTenantController {
|
|||
* @return
|
||||
*/
|
||||
@DeleteMapping("/exitUserTenant")
|
||||
public Result<String> exitUserTenant(@RequestBody SysTenant sysTenant,HttpServletRequest request){
|
||||
public Result<String> exitUserTenant(@RequestBody SysTenant sysTenant, HttpServletRequest request){
|
||||
LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
|
||||
//验证用户是否已存在
|
||||
Integer count = relationService.userTenantIzExist(sysUser.getId(),sysTenant.getId());
|
||||
|
@ -797,4 +799,24 @@ public class SysTenantController {
|
|||
TenantDepartAuthInfo info = sysTenantService.getTenantDepartAuthInfo(Integer.parseInt(id));
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -91,4 +91,14 @@ public interface SysTenantMapper extends BaseMapper<SysTenant> {
|
|||
* @return
|
||||
*/
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -1,10 +1,7 @@
|
|||
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 org.jeecg.modules.system.entity.SysTenantPack;
|
||||
|
||||
/**
|
||||
* @Description: 租户产品包
|
||||
|
|
|
@ -100,7 +100,7 @@
|
|||
<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
|
||||
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
|
||||
and c.id in
|
||||
<foreach collection="userIdList" index="index" item="id" open="(" separator="," close=")">
|
||||
|
@ -108,5 +108,18 @@
|
|||
</foreach>
|
||||
</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>
|
|
@ -1,7 +1,7 @@
|
|||
package org.jeecg.modules.system.service;
|
||||
|
||||
import org.jeecg.modules.system.entity.SysTenantPack;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import org.jeecg.modules.system.entity.SysTenantPack;
|
||||
import org.jeecg.modules.system.entity.SysTenantPackUser;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -71,5 +71,5 @@ public interface ISysTenantPackService extends IService<SysTenantPack> {
|
|||
* @param packCode
|
||||
* @return
|
||||
*/
|
||||
SysTenantPack getSysTenantPack(Integer tenantId ,String packCode);
|
||||
SysTenantPack getSysTenantPack(Integer tenantId , String packCode);
|
||||
}
|
||||
|
|
|
@ -190,4 +190,14 @@ public interface ISysTenantService extends IService<SysTenant> {
|
|||
* @param 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);
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package org.jeecg.modules.system.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.apache.shiro.SecurityUtils;
|
||||
import org.jeecg.common.constant.SymbolConstant;
|
||||
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.modules.aop.TenantLog;
|
||||
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.SysTenantPackUser;
|
||||
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.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
|
|
@ -74,7 +74,7 @@ public class SysTenantServiceImpl extends ServiceImpl<SysTenantMapper, SysTenant
|
|||
public Long countUserLinkTenant(String id) {
|
||||
LambdaQueryWrapper<SysUserTenant> query = new LambdaQueryWrapper<>();
|
||||
query.eq(SysUserTenant::getTenantId,id);
|
||||
query.eq(SysUserTenant::getStatus,CommonConstant.STATUS_1);
|
||||
query.eq(SysUserTenant::getStatus, CommonConstant.STATUS_1);
|
||||
// 查找出已被关联的用户数量
|
||||
return userTenantMapper.selectCount(query);
|
||||
}
|
||||
|
@ -107,7 +107,7 @@ public class SysTenantServiceImpl extends ServiceImpl<SysTenantMapper, SysTenant
|
|||
SysUserTenant relation = new SysUserTenant();
|
||||
relation.setUserId(userId);
|
||||
relation.setTenantId(Integer.valueOf(id));
|
||||
relation.setStatus(CommonConstant.USER_TENANT_UNDER_REVIEW);
|
||||
relation.setStatus(CommonConstant.USER_TENANT_NORMAL);
|
||||
userTenantMapper.insert(relation);
|
||||
}
|
||||
//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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 触发入职流程
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue