|
@@ -1,27 +1,37 @@
|
|
|
package edu.travel.tenant.service.impl;
|
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
+import cn.hutool.core.lang.Assert;
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
-import edu.travel.tenant.entity.EduTenant;
|
|
|
+import edu.travel.tenant.dto.AssignRolesOrMenus;
|
|
|
+import edu.travel.tenant.entity.*;
|
|
|
import edu.travel.tenant.enums.UserStatus;
|
|
|
-import edu.travel.tenant.service.ITenantService;
|
|
|
+import edu.travel.tenant.service.*;
|
|
|
import edu.travel.service.SysServiceImpl;
|
|
|
import edu.travel.tenant.mapper.EduTenantMapper;
|
|
|
import edu.travel.tenant.vo.EduTenantVo;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Objects;
|
|
|
-import java.util.Set;
|
|
|
+import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@Service
|
|
|
public class ITenantServiceImpl extends SysServiceImpl<EduTenantMapper, EduTenant> implements ITenantService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ISysUserRoleService sysUserRoleService;
|
|
|
+ @Autowired
|
|
|
+ private ISysRoleMenuService sysRoleMenuService;
|
|
|
+ @Autowired
|
|
|
+ private ISysMenuService sysMenuService;
|
|
|
+ @Autowired
|
|
|
+ private ISysRoleService sysRoleService;
|
|
|
@Override
|
|
|
- public EduTenant getTenantByID(String tenantID) {
|
|
|
+ public EduTenant getTenantByPhoneNumber(String tenantID) {
|
|
|
return super.getOneLink(new QueryWrapper<EduTenant>().eq("tenant_phone",tenantID));
|
|
|
}
|
|
|
|
|
@@ -48,11 +58,12 @@ public class ITenantServiceImpl extends SysServiceImpl<EduTenantMapper, EduTenan
|
|
|
|
|
|
@Override
|
|
|
@Transactional
|
|
|
- public void deleteByIds(Set<Long> ids) {
|
|
|
- if (ids==null || ids.isEmpty()) {
|
|
|
+ public void deleteByIds(List<Long> ids) {
|
|
|
+ HashSet<Long> set = new HashSet<>(ids);
|
|
|
+ if (set==null || set.isEmpty()) {
|
|
|
throw new RuntimeException("参数为空");
|
|
|
}
|
|
|
- List<EduTenant> tenants = this.listByIds(ids);
|
|
|
+ List<EduTenant> tenants = this.listByIds(set);
|
|
|
if (tenants == null || tenants.isEmpty()) {
|
|
|
throw new RuntimeException("用户不存在或已注销");
|
|
|
}
|
|
@@ -93,6 +104,70 @@ public class ITenantServiceImpl extends SysServiceImpl<EduTenantMapper, EduTenan
|
|
|
.eq(EduTenant::getUserStatus,1));
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public List<SysMenu> getMenuList(EduTenant principal) {
|
|
|
+
|
|
|
+ if (principal ==null) throw new RuntimeException("用户未登录");
|
|
|
+ EduTenant tenant = this.getTenantById(principal.getId());
|
|
|
+ if (tenant == null) throw new RuntimeException("用户不存在");
|
|
|
+ if (tenant.getUserStatus() == 0) throw new RuntimeException("用户已禁用");
|
|
|
+ if (tenant.getDeleteFlag() == 1) throw new RuntimeException("用户已注销");
|
|
|
+ if (tenant.getId() != null) {
|
|
|
+
|
|
|
+ List<Long> roleIdList = sysUserRoleService.getBaseMapper().selectList(new LambdaQueryWrapper<SysUserRole>()
|
|
|
+ .eq(SysUserRole::getId, tenant.getId())).stream()
|
|
|
+ .map(SysUserRole::getRoleId)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ if (roleIdList.isEmpty()) return null;
|
|
|
+
|
|
|
+ Set<Long> menuIdList = sysRoleMenuService.getBaseMapper().selectList(new LambdaQueryWrapper<SysRoleMenu>()
|
|
|
+ .in(SysRoleMenu::getRoleId, roleIdList)).stream()
|
|
|
+ .map(SysRoleMenu::getMenuId)
|
|
|
+ .collect(Collectors.toSet());
|
|
|
+
|
|
|
+ List<SysMenu> list = sysMenuService.list(new LambdaQueryWrapper<SysMenu>()
|
|
|
+ .eq(SysMenu::getDeleteFlag, 0)
|
|
|
+ .eq(SysMenu::getStatus, 1)
|
|
|
+ .in(SysMenu::getId, menuIdList));
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<SysRole> getRoleListByUserId(EduTenant principal) {
|
|
|
+ if (principal ==null) throw new RuntimeException("用户未登录");
|
|
|
+ if (principal.getId() == null) throw new RuntimeException("用户不存在");
|
|
|
+
|
|
|
+ List<Long> roleIdList = sysUserRoleService.getBaseMapper().selectList(new LambdaQueryWrapper<SysUserRole>()
|
|
|
+ .eq(SysUserRole::getId, principal.getId())).stream()
|
|
|
+ .map(SysUserRole::getRoleId)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ if (roleIdList.isEmpty()) return null;
|
|
|
+
|
|
|
+ List<SysRole> list = sysRoleService.list(new LambdaQueryWrapper<SysRole>()
|
|
|
+ .in(SysRole::getId, roleIdList)
|
|
|
+ .eq(SysRole::getDeleteFlag, 0));
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void assignRolesToUser(AssignRolesOrMenus assignRolesOrMenus) {
|
|
|
+ Assert.isTrue(ObjectUtil.isNotEmpty(assignRolesOrMenus),"请登录");
|
|
|
+ Assert.isTrue(ObjectUtil.isNotEmpty(assignRolesOrMenus.getId()),"请选择需分配角色的用户");
|
|
|
+ Assert.isTrue(ObjectUtil.isNotEmpty(assignRolesOrMenus.getIds()),"请选择角色");
|
|
|
+ List<SysRole> roleList = sysRoleService.listByIds(assignRolesOrMenus.getIds());
|
|
|
+ Assert.isTrue(ObjectUtil.isNotEmpty(roleList),"选择的角色不存在");
|
|
|
+ Assert.isTrue(roleList.size() == assignRolesOrMenus.getIds().size(),"包含重复的角色或不存在的角色");
|
|
|
+
|
|
|
+ sysUserRoleService.saveOrUpdateBatch(assignRolesOrMenus.getIds().stream().map(roleId -> {
|
|
|
+ SysUserRole sysUserRole = new SysUserRole();
|
|
|
+ sysUserRole.setUserId(assignRolesOrMenus.getId());
|
|
|
+ sysUserRole.setRoleId(roleId);
|
|
|
+ return sysUserRole;
|
|
|
+ }).collect(Collectors.toList()));
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
*
|
|
|
* 填充用户状态
|