|
@@ -1,11 +1,24 @@
|
|
|
package org.springblade.system.service.impl;
|
|
|
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
+import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.fjhx.utils.TreeUtil;
|
|
|
+import org.springblade.core.log.exception.ServiceException;
|
|
|
+import org.springblade.core.secure.utils.AuthUtil;
|
|
|
+import org.springblade.core.tool.utils.ObjectUtil;
|
|
|
import org.springblade.system.entity.AppMenu;
|
|
|
+import org.springblade.system.entity.AppRoleMenu;
|
|
|
import org.springblade.system.mapper.AppMenuMapper;
|
|
|
import org.springblade.system.service.AppMenuService;
|
|
|
+import org.springblade.system.service.AppRoleMenuService;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
/**
|
|
|
* <p>
|
|
|
* app目录 服务实现类
|
|
@@ -17,4 +30,41 @@ import org.springframework.stereotype.Service;
|
|
|
@Service
|
|
|
public class AppMenuServiceImpl extends ServiceImpl<AppMenuMapper, AppMenu> implements AppMenuService {
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private AppRoleMenuService appRoleMenuService;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<Map<String, Object>> tree(Map<String, String> condition) {
|
|
|
+
|
|
|
+ // 获取目录
|
|
|
+ String status = condition.get("status");
|
|
|
+ String own = condition.get("own");
|
|
|
+
|
|
|
+ LambdaQueryChainWrapper<AppMenu> appMenuLambdaQueryChainWrapper = lambdaQuery();
|
|
|
+
|
|
|
+ // 是否之查当前用户拥有权限的菜单
|
|
|
+ if (ObjectUtil.isNotEmpty(own) && own.equals("1")) {
|
|
|
+ // 获取用户角色
|
|
|
+ String userRole = AuthUtil.getUserRole();
|
|
|
+ String[] userRoleList = userRole.split(",");
|
|
|
+ if (userRoleList.length == 0) throw new ServiceException("没有角色权限");
|
|
|
+
|
|
|
+ // 获取角色访问目录权限
|
|
|
+ List<AppRoleMenu> list = appRoleMenuService.list(
|
|
|
+ Wrappers.<AppRoleMenu>lambdaUpdate().in(AppRoleMenu::getRoleId, (Object[]) userRoleList));
|
|
|
+ if (list.size() == 0) throw new ServiceException("没有目录访问权限");
|
|
|
+ List<Long> appMenuId = list.stream().map(AppRoleMenu::getAppMenuId).collect(Collectors.toList());
|
|
|
+
|
|
|
+ appMenuLambdaQueryChainWrapper.in(AppMenu::getId, appMenuId);
|
|
|
+ } else {
|
|
|
+ appMenuLambdaQueryChainWrapper.eq(AppMenu::getTenantId, AuthUtil.getTenantId());
|
|
|
+ }
|
|
|
+
|
|
|
+ List<AppMenu> appMenuList = appMenuLambdaQueryChainWrapper
|
|
|
+ .eq(ObjectUtil.isNotEmpty(status), AppMenu::getStatus, status)
|
|
|
+ .orderByAsc(AppMenu::getSort)
|
|
|
+ .list();
|
|
|
+
|
|
|
+ return TreeUtil.buildTreeObj(appMenuList);
|
|
|
+ }
|
|
|
}
|