|
@@ -12,16 +12,14 @@ import cn.com.xwy.boot.web.dto.RestResponse;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.transaction.interceptor.TransactionAspectSupport;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
+import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
@@ -30,9 +28,8 @@ import java.util.stream.Collectors;
|
|
|
* @description 菜单接口实现类
|
|
|
*/
|
|
|
@Service
|
|
|
+@Slf4j
|
|
|
public class MenuService extends ServiceImpl<MenuMapper, Menu> implements IMenuService {
|
|
|
-
|
|
|
-
|
|
|
@Resource
|
|
|
private ICompanyMenuService companyMenuService;
|
|
|
|
|
@@ -41,6 +38,8 @@ public class MenuService extends ServiceImpl<MenuMapper, Menu> implements IMenuS
|
|
|
|
|
|
@Resource
|
|
|
private IUserRoleService userRoleService;
|
|
|
+ @Resource
|
|
|
+ private IRoleService roleService;
|
|
|
|
|
|
@Override
|
|
|
public List<Menu> getByRoleId(Long roleId) {
|
|
@@ -157,19 +156,37 @@ public class MenuService extends ServiceImpl<MenuMapper, Menu> implements IMenuS
|
|
|
Long companyId = menuRequest.getCompanyId();
|
|
|
//删除企业原来关联的菜单
|
|
|
List<CompanyMenu> needDeleteCompanyMenuList = companyMenuService.list(new QueryWrapper<CompanyMenu>()
|
|
|
- .eq("company_id", companyId)
|
|
|
- );
|
|
|
- if (needDeleteCompanyMenuList != null && needDeleteCompanyMenuList.size() > 0) {
|
|
|
- List<Long> companyMenuIds = needDeleteCompanyMenuList.stream().map(CompanyMenu::getId).
|
|
|
- collect(Collectors.toList());
|
|
|
- if (companyMenuIds.size() > 0) {
|
|
|
- if (!companyMenuService.removeByIds(companyMenuIds)) {
|
|
|
- return RestResponse.fail(ApiConstants.RESULT_ERROR, "删除公司菜单关联关系失败");
|
|
|
+ .eq("company_id", companyId));
|
|
|
+ List<Long> companyMenuIds = needDeleteCompanyMenuList.stream().map(CompanyMenu::getId).
|
|
|
+ collect(Collectors.toList());
|
|
|
+ Set<Long> menuIds = needDeleteCompanyMenuList.stream().map(CompanyMenu::getMenuId).
|
|
|
+ collect(Collectors.toSet());
|
|
|
+ //获取待删除的角色权限菜单id列表
|
|
|
+ List<Long> menuIdList = ProjectUtils.getLongIdFromIds(menuRequest.getMenuIds());
|
|
|
+ if (!companyMenuIds.isEmpty()) {
|
|
|
+ log.info("公司下菜单不为空,删除公司下的菜单");
|
|
|
+ if (!companyMenuService.removeByIds(companyMenuIds)) {
|
|
|
+ log.info("删除失败,提示异常");
|
|
|
+ return RestResponse.fail(ApiConstants.RESULT_ERROR, "删除公司菜单关联关系失败");
|
|
|
+ }
|
|
|
+ log.info("删除公司下不存在,但公司下角色还拥有的菜单");
|
|
|
+ //获取公司下的所有角色id列表
|
|
|
+ Set<Long> companyRoleIds = roleService.list(Wrappers.<Role>lambdaQuery().
|
|
|
+ select(Role::getId).eq(Role::getCompanyId, companyId)).
|
|
|
+ stream().map(Role::getId).collect(Collectors.toSet());
|
|
|
+ //获取公司下不存在的菜单id,但在角色菜单(role_menu表)中拥有的菜单id
|
|
|
+ Set<Long> roleMenuIds = new HashSet<>();
|
|
|
+ for (Long menuId : menuIds) {
|
|
|
+ if (!menuIdList.contains(menuId)) {
|
|
|
+ roleMenuIds.add(menuId);
|
|
|
}
|
|
|
}
|
|
|
+ if (!companyRoleIds.isEmpty()&& !roleMenuIds.isEmpty()) {
|
|
|
+ log.debug("角色id列表和菜单id列表都不为空,删除role_menu表中的数据");
|
|
|
+ roleMenuService.remove(Wrappers.<RoleMenu>lambdaQuery().
|
|
|
+ in(RoleMenu::getRoleId, companyRoleIds).in(RoleMenu::getMenuId, roleMenuIds));
|
|
|
+ }
|
|
|
}
|
|
|
- //获取菜单id列表
|
|
|
- List<Long> menuIdList = ProjectUtils.getLongIdFromIds(menuRequest.getMenuIds());
|
|
|
List<CompanyMenu> needSaveCompanyMenuList = new ArrayList<>();
|
|
|
if (menuIdList.size() > 0) {
|
|
|
for (Long menuId : menuIdList) {
|