|
@@ -5,14 +5,17 @@ import cn.com.ty.lift.common.utils.ProjectUtils;
|
|
|
import cn.com.ty.lift.common.utils.TreeUtil;
|
|
|
import cn.com.ty.lift.system.user.dao.entity.CompanyMenu;
|
|
|
import cn.com.ty.lift.system.user.dao.entity.Menu;
|
|
|
+import cn.com.ty.lift.system.user.dao.entity.Role;
|
|
|
import cn.com.ty.lift.system.user.dao.entity.RoleMenu;
|
|
|
import cn.com.ty.lift.system.user.dao.entity.model.MenuRequest;
|
|
|
+import cn.com.ty.lift.system.user.dao.entity.model.MenuResponse;
|
|
|
import cn.com.ty.lift.system.user.dao.mapper.MenuMapper;
|
|
|
import cn.com.ty.lift.system.user.service.ICompanyMenuService;
|
|
|
import cn.com.ty.lift.system.user.service.IMenuService;
|
|
|
import cn.com.ty.lift.system.user.service.IRoleMenuService;
|
|
|
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 org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
@@ -21,7 +24,10 @@ 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.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* @author huangyuan
|
|
@@ -44,7 +50,7 @@ public class MenuService extends ServiceImpl<MenuMapper, Menu> implements IMenuS
|
|
|
.eq("role_id", roleId)
|
|
|
);
|
|
|
List<Long> menuIdList = ProjectUtils.getAttrList(roleMenuList, "menuId", null);
|
|
|
- if(menuIdList != null && menuIdList.size() > 0){
|
|
|
+ if (menuIdList != null && menuIdList.size() > 0) {
|
|
|
return (List<Menu>) this.listByIds(menuIdList);
|
|
|
}
|
|
|
return null;
|
|
@@ -56,8 +62,8 @@ public class MenuService extends ServiceImpl<MenuMapper, Menu> implements IMenuS
|
|
|
List<Menu> menuTree = TreeUtil.listToTree(menuList, ApiConstants.MENU_PARENT_ATTR, ApiConstants.ROOT_MENU_PARENT_ID, "id");
|
|
|
//递归组合菜单路径
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
- menuTreeToUrl(menuTree, sb);
|
|
|
- return sb.toString().replace("\n","");
|
|
|
+ menuTreeToUrl(menuTree, sb);
|
|
|
+ return sb.toString().replace("\n", "");
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -90,13 +96,54 @@ public class MenuService extends ServiceImpl<MenuMapper, Menu> implements IMenuS
|
|
|
List<CompanyMenu> companyMenuList = companyMenuService.list(new QueryWrapper<CompanyMenu>()
|
|
|
.eq("company_id", companyId)
|
|
|
);
|
|
|
- List<Long> menuIdList = ProjectUtils.getAttrList(companyMenuList, "menuId", null);
|
|
|
- if(menuIdList != null && menuIdList.size() > 0){
|
|
|
- return (List<Menu>) this.listByIds(menuIdList);
|
|
|
+ if (companyMenuList != null && companyMenuList.size() > 0) {
|
|
|
+ List<Long> menuIdList = companyMenuList.stream().map(CompanyMenu::getMenuId).collect(Collectors.toList());
|
|
|
+ if (menuIdList.size() > 0) {
|
|
|
+ return (List<Menu>) this.listByIds(menuIdList);
|
|
|
+ }
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public RestResponse getButton(MenuRequest menuRequest) {
|
|
|
+ List<MenuResponse> menuResponseList = new ArrayList<>();
|
|
|
+ List<Menu> buttonList = list(Wrappers.<Menu>query().
|
|
|
+ eq("parent_id", menuRequest.getMenuId()).
|
|
|
+ eq("type", "button")
|
|
|
+ );
|
|
|
+ if (buttonList != null && buttonList.size() > 0) {
|
|
|
+ List<Long> buttonIdList = buttonList.stream().map(menu -> Long.parseLong(menu.getId().toString())).
|
|
|
+ collect(Collectors.toList());
|
|
|
+ //获取当前角色关联的菜单信息
|
|
|
+ List<RoleMenu> roleMenuList = roleMenuService.list(Wrappers.<RoleMenu>query().
|
|
|
+ eq("role_id", menuRequest.getCurrentRoleId()).
|
|
|
+ in(buttonIdList.size() > 0, "menu_id", buttonIdList)
|
|
|
+ );
|
|
|
+ //设置菜单id -> 菜单角色关联关系
|
|
|
+ Map<Long, List<RoleMenu>> menuIdToRoleMenu = new HashMap<>();
|
|
|
+ if (roleMenuList != null && roleMenuList.size() > 0) {
|
|
|
+ menuIdToRoleMenu.putAll(roleMenuList.stream().collect(Collectors.groupingBy(RoleMenu::getMenuId)));
|
|
|
+ }
|
|
|
+ //封装菜单信息
|
|
|
+ buttonList.forEach(button -> {
|
|
|
+ MenuResponse menuResponse = new MenuResponse();
|
|
|
+ menuResponse.setId(Long.parseLong(button.getId().toString()));
|
|
|
+ menuResponse.setName(button.getName());
|
|
|
+ menuResponse.setCode(button.getCode());
|
|
|
+ //设置菜单是否显示
|
|
|
+ if (menuIdToRoleMenu.size() > 0) {
|
|
|
+ List<RoleMenu> roleMenus = menuIdToRoleMenu.get(Long.parseLong(button.getId().toString()));
|
|
|
+ if (roleMenus != null && roleMenus.size() > 0) {
|
|
|
+ menuResponse.setChecked(true);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ menuResponseList.add(menuResponse);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ return RestResponse.success(menuResponseList);
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
@Transactional
|
|
|
public RestResponse companyMenu(MenuRequest menuRequest) {
|
|
@@ -107,8 +154,8 @@ public class MenuService extends ServiceImpl<MenuMapper, Menu> implements IMenuS
|
|
|
);
|
|
|
List<Long> companyMenuIds = ProjectUtils.getAttrList(needDeleteCompanyMenuList, "id", null);
|
|
|
if (companyMenuIds.size() > 0) {
|
|
|
- if(!companyMenuService.removeByIds(companyMenuIds)){
|
|
|
- return RestResponse.fail(ApiConstants.RESULT_ERROR, "删除公司菜单关联关系失败");
|
|
|
+ if (!companyMenuService.removeByIds(companyMenuIds)) {
|
|
|
+ return RestResponse.fail(ApiConstants.RESULT_ERROR, "删除公司菜单关联关系失败");
|
|
|
}
|
|
|
}
|
|
|
//获取菜单id列表
|
|
@@ -124,7 +171,7 @@ public class MenuService extends ServiceImpl<MenuMapper, Menu> implements IMenuS
|
|
|
}
|
|
|
//保存公司菜单关联关系
|
|
|
if (needSaveCompanyMenuList.size() > 0) {
|
|
|
- if(!companyMenuService.saveBatch(needSaveCompanyMenuList)){
|
|
|
+ if (!companyMenuService.saveBatch(needSaveCompanyMenuList)) {
|
|
|
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
|
return RestResponse.fail(ApiConstants.RESULT_ERROR, "保存公司菜单关系失败");
|
|
|
}
|