Commit c5a16c5f authored by 赵啸非's avatar 赵啸非

添加菜单资源配置

parent 93d7bcc5
...@@ -41,6 +41,21 @@ public class MenuTreeSelect implements Serializable { ...@@ -41,6 +41,21 @@ public class MenuTreeSelect implements Serializable {
*/ */
private String label; private String label;
/**
* 菜单类型 (0.目录,1.菜单,2.按钮)
*/
private Integer menuType;
/**
* 菜单显示状态 (0.显示,1.隐藏)
*/
private Integer visible;
/**
* 权限标识,多个逗号分割
*/
private String perms;
/** /**
* 子节点 * 子节点
*/ */
...@@ -53,6 +68,9 @@ public class MenuTreeSelect implements Serializable { ...@@ -53,6 +68,9 @@ public class MenuTreeSelect implements Serializable {
this.id = entity.getId(); this.id = entity.getId();
this.parentId = entity.getParentId(); this.parentId = entity.getParentId();
this.label = entity.getName(); this.label = entity.getName();
this.menuType = entity.getMenuType();
this.visible = entity.getVisible();
this.perms = entity.getPerms();
if(!ObjectUtils.isEmpty(entity.getChildren())){ if(!ObjectUtils.isEmpty(entity.getChildren())){
this.children = entity.getChildren().stream().map(MenuTreeSelect::new).collect(Collectors.toList()); this.children = entity.getChildren().stream().map(MenuTreeSelect::new).collect(Collectors.toList());
} }
...@@ -66,6 +84,9 @@ public class MenuTreeSelect implements Serializable { ...@@ -66,6 +84,9 @@ public class MenuTreeSelect implements Serializable {
JSONObject jsonObject = parser.parseObject(); JSONObject jsonObject = parser.parseObject();
node.setId(jsonObject.getLong("id")); node.setId(jsonObject.getLong("id"));
node.setLabel(jsonObject.getString("label")); node.setLabel(jsonObject.getString("label"));
node.setMenuType(jsonObject.getInteger("menuType"));
node.setVisible(jsonObject.getInteger("visible"));
node.setPerms(jsonObject.getString("perms"));
JSONArray jsonArray = jsonObject.getJSONArray("children"); JSONArray jsonArray = jsonObject.getJSONArray("children");
List<MenuTreeSelect> children = new ArrayList<>(); List<MenuTreeSelect> children = new ArrayList<>();
if(!ObjectUtils.isEmpty(jsonArray)){ if(!ObjectUtils.isEmpty(jsonArray)){
......
...@@ -25,4 +25,8 @@ public class MenuVo extends BaseEntityLong { ...@@ -25,4 +25,8 @@ public class MenuVo extends BaseEntityLong {
private Integer type; private Integer type;
/**
* 是否选中,0为选中,1选中。默认0
*/
private Integer checked=0;
} }
\ No newline at end of file
...@@ -75,6 +75,16 @@ public interface MenuService extends ICRUDService<MenuEntity,Long> { ...@@ -75,6 +75,16 @@ public interface MenuService extends ICRUDService<MenuEntity,Long> {
*/ */
List<MenuTreeSelect> buildMenuTreeSelect(List<MenuEntity> menuList); List<MenuTreeSelect> buildMenuTreeSelect(List<MenuEntity> menuList);
/**
* 构建树,包含是否选中
* @param allMenuList
* @param menuIdsChecked
* @return
*/
List<MenuTreeSelect> buildMenuTreeChecked(List<MenuEntity> allMenuList, Set<Long> menuIdsChecked);
/** /**
* 根据父id查询子节点 * 根据父id查询子节点
* @param parentId * @param parentId
......
...@@ -158,7 +158,7 @@ public class MenuServiceImpl extends AbstractCRUDServiceImpl<MenuDao, MenuEntity ...@@ -158,7 +158,7 @@ public class MenuServiceImpl extends AbstractCRUDServiceImpl<MenuDao, MenuEntity
for (Iterator<MenuEntity> iterator = list.iterator(); iterator.hasNext(); ) { for (Iterator<MenuEntity> iterator = list.iterator(); iterator.hasNext(); ) {
MenuEntity menuEntity = iterator.next(); MenuEntity menuEntity = iterator.next();
if (!tempList.contains(menuEntity.getParentId())) { if (!tempList.contains(menuEntity.getParentId())) {
recursionFn(list, menuEntity); recursionFn(list, menuEntity, new HashSet<>());
returnList.add(menuEntity); returnList.add(menuEntity);
} }
} }
...@@ -176,7 +176,7 @@ public class MenuServiceImpl extends AbstractCRUDServiceImpl<MenuDao, MenuEntity ...@@ -176,7 +176,7 @@ public class MenuServiceImpl extends AbstractCRUDServiceImpl<MenuDao, MenuEntity
for (Iterator<MenuEntity> iterator = list.iterator(); iterator.hasNext(); ) { for (Iterator<MenuEntity> iterator = list.iterator(); iterator.hasNext(); ) {
MenuEntity menuEntity = iterator.next(); MenuEntity menuEntity = iterator.next();
if (!tempList.contains(menuEntity.getParentId())) { if (!tempList.contains(menuEntity.getParentId())) {
recursionFn(list, menuEntity); recursionFn(list, menuEntity, new HashSet<>());
returnList.add(menuEntity); returnList.add(menuEntity);
} }
} }
...@@ -186,16 +186,39 @@ public class MenuServiceImpl extends AbstractCRUDServiceImpl<MenuDao, MenuEntity ...@@ -186,16 +186,39 @@ public class MenuServiceImpl extends AbstractCRUDServiceImpl<MenuDao, MenuEntity
return returnList.stream().map(MenuTreeSelect::new).collect(Collectors.toList()); return returnList.stream().map(MenuTreeSelect::new).collect(Collectors.toList());
} }
@Override
public List<MenuTreeSelect> buildMenuTreeChecked(List<MenuEntity> allMenuList, Set<Long> menuIdsChecked) {
List<MenuEntity> returnList = new ArrayList<>();
List<Long> tempList = allMenuList.stream().map(MenuEntity::getId).collect(Collectors.toList());
for (Iterator<MenuEntity> iterator = allMenuList.iterator(); iterator.hasNext(); ) {
MenuEntity menuEntity = iterator.next();
if (!tempList.contains(menuEntity.getParentId())) {
recursionFn(allMenuList, menuEntity, menuIdsChecked);
returnList.add(menuEntity);
}
}
if (returnList.isEmpty()) {
returnList = allMenuList;
}
return returnList.stream().map(MenuTreeSelect::new).collect(Collectors.toList());
}
/** /**
* 递归列表 * 递归列表
*/ */
private void recursionFn(List<MenuEntity> list, MenuEntity t) { private void recursionFn(List<MenuEntity> list, MenuEntity t, Set<Long> menuIdsChecked) {
// 得到子节点列表 // 得到子节点列表
List<MenuEntity> childList = getChildList(list, t); List<MenuEntity> childList = getChildList(list, t);
t.setChildren(childList); t.setChildren(childList);
for (MenuEntity tChild : childList) { for (MenuEntity tChild : childList) {
if (menuIdsChecked.contains(tChild.getId())) {
tChild.setChecked(YesNoEnum.YES.getValue());
}
if (hasChild(list, tChild)) { if (hasChild(list, tChild)) {
recursionFn(list, tChild); recursionFn(list, tChild, menuIdsChecked);
} }
} }
} }
......
...@@ -11,9 +11,12 @@ package com.mortals.xhx.base.system.role.service; ...@@ -11,9 +11,12 @@ package com.mortals.xhx.base.system.role.service;
import com.mortals.framework.model.Context; import com.mortals.framework.model.Context;
import com.mortals.framework.service.ICRUDService; import com.mortals.framework.service.ICRUDService;
import com.mortals.xhx.base.system.menu.model.MenuTreeSelect;
import com.mortals.xhx.base.system.role.model.RoleAuthEntity; import com.mortals.xhx.base.system.role.model.RoleAuthEntity;
import com.mortals.xhx.base.system.role.model.RoleAuthQuery; import com.mortals.xhx.base.system.role.model.RoleAuthQuery;
import java.util.List;
/** /**
* <p>Title: 角色资源权限</p> * <p>Title: 角色资源权限</p>
...@@ -31,4 +34,8 @@ public interface RoleAuthService extends ICRUDService<RoleAuthEntity,Long> { ...@@ -31,4 +34,8 @@ public interface RoleAuthService extends ICRUDService<RoleAuthEntity,Long> {
/** 角色分配菜单 */ /** 角色分配菜单 */
void doDistributionMenu(RoleAuthQuery query, Context context); void doDistributionMenu(RoleAuthQuery query, Context context);
/** 角色编辑菜单 */
List<MenuTreeSelect> editMenu(RoleAuthQuery query, Context context);
} }
\ No newline at end of file
...@@ -8,10 +8,15 @@ ...@@ -8,10 +8,15 @@
package com.mortals.xhx.base.system.role.service.impl; package com.mortals.xhx.base.system.role.service.impl;
import com.mortals.framework.exception.AppException;
import com.mortals.framework.model.Context; import com.mortals.framework.model.Context;
import com.mortals.framework.service.ICacheService; import com.mortals.framework.service.ICacheService;
import com.mortals.framework.service.impl.AbstractCRUDServiceImpl; import com.mortals.framework.service.impl.AbstractCRUDServiceImpl;
import com.mortals.framework.util.DataUtil; import com.mortals.framework.util.DataUtil;
import com.mortals.xhx.base.system.menu.model.MenuEntity;
import com.mortals.xhx.base.system.menu.model.MenuQuery;
import com.mortals.xhx.base.system.menu.model.MenuTreeSelect;
import com.mortals.xhx.base.system.menu.service.MenuService;
import com.mortals.xhx.base.system.resource.service.ResourceService; import com.mortals.xhx.base.system.resource.service.ResourceService;
import com.mortals.xhx.base.system.role.dao.RoleAuthDao; import com.mortals.xhx.base.system.role.dao.RoleAuthDao;
import com.mortals.xhx.base.system.role.model.RoleAuthEntity; import com.mortals.xhx.base.system.role.model.RoleAuthEntity;
...@@ -24,6 +29,7 @@ import org.springframework.stereotype.Service; ...@@ -24,6 +29,7 @@ import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils; import org.springframework.util.ObjectUtils;
import java.util.*; import java.util.*;
import java.util.stream.Collectors;
import static com.mortals.xhx.common.utils.MenuEncodeUtil.generateMenuUrlCode; import static com.mortals.xhx.common.utils.MenuEncodeUtil.generateMenuUrlCode;
...@@ -32,6 +38,7 @@ import static com.mortals.xhx.common.utils.MenuEncodeUtil.generateMenuUrlCode; ...@@ -32,6 +38,7 @@ import static com.mortals.xhx.common.utils.MenuEncodeUtil.generateMenuUrlCode;
* <p>Description: RoleAuthServiceImpl service接口 </p> * <p>Description: RoleAuthServiceImpl service接口 </p>
* <p>Copyright: Copyright &reg; </p> * <p>Copyright: Copyright &reg; </p>
* <p>Company: </p> * <p>Company: </p>
*
* @author * @author
* @version 1.0.0 * @version 1.0.0
*/ */
...@@ -40,6 +47,9 @@ public class RoleAuthServiceImpl extends AbstractCRUDServiceImpl<RoleAuthDao, Ro ...@@ -40,6 +47,9 @@ public class RoleAuthServiceImpl extends AbstractCRUDServiceImpl<RoleAuthDao, Ro
@Autowired @Autowired
private ICacheService cacheService; private ICacheService cacheService;
@Autowired
private MenuService menuService;
@Autowired @Autowired
@Lazy @Lazy
private ResourceService resourceService; private ResourceService resourceService;
...@@ -57,8 +67,8 @@ public class RoleAuthServiceImpl extends AbstractCRUDServiceImpl<RoleAuthDao, Ro ...@@ -57,8 +67,8 @@ public class RoleAuthServiceImpl extends AbstractCRUDServiceImpl<RoleAuthDao, Ro
Long[] delIds = this.find(roleAuthQuery).stream() Long[] delIds = this.find(roleAuthQuery).stream()
.filter(f -> f.getMenuId() == null) .filter(f -> f.getMenuId() == null)
.map(f -> f.getId()).toArray(Long[]::new); .map(f -> f.getId()).toArray(Long[]::new);
if(!ObjectUtils.isEmpty(delIds)){ if (!ObjectUtils.isEmpty(delIds)) {
this.remove(delIds,context); this.remove(delIds, context);
} }
List<RoleAuthEntity> list = new ArrayList<>(); List<RoleAuthEntity> list = new ArrayList<>();
...@@ -86,8 +96,8 @@ public class RoleAuthServiceImpl extends AbstractCRUDServiceImpl<RoleAuthDao, Ro ...@@ -86,8 +96,8 @@ public class RoleAuthServiceImpl extends AbstractCRUDServiceImpl<RoleAuthDao, Ro
Long[] delIds = this.find(roleAuthQuery).stream() Long[] delIds = this.find(roleAuthQuery).stream()
.filter(f -> f.getMenuId() != null) .filter(f -> f.getMenuId() != null)
.map(f -> f.getId()).toArray(Long[]::new); .map(f -> f.getId()).toArray(Long[]::new);
if(!ObjectUtils.isEmpty(delIds)){ if (!ObjectUtils.isEmpty(delIds)) {
this.remove(delIds,context); this.remove(delIds, context);
} }
List<RoleAuthEntity> list = new ArrayList<>(); List<RoleAuthEntity> list = new ArrayList<>();
...@@ -102,6 +112,25 @@ public class RoleAuthServiceImpl extends AbstractCRUDServiceImpl<RoleAuthDao, Ro ...@@ -102,6 +112,25 @@ public class RoleAuthServiceImpl extends AbstractCRUDServiceImpl<RoleAuthDao, Ro
this.updateUserMenuUrlCache(); this.updateUserMenuUrlCache();
} }
@Override
public List<MenuTreeSelect> editMenu(RoleAuthQuery query, Context context) {
if (ObjectUtils.isEmpty(query.getRoleId())) throw new AppException("角色不能为空");
RoleAuthQuery roleAuthQuery = new RoleAuthQuery();
roleAuthQuery.setRoleId(query.getRoleId());
Set<Long> menuIdList = this.find(roleAuthQuery).stream()
.map(f -> f.getMenuId())
.filter(f -> f != null)
.collect(Collectors.toSet());
if (!ObjectUtils.isEmpty(menuIdList)) {
List<MenuEntity> allMenuList = menuService.find(new MenuQuery());
List<MenuTreeSelect> menuTreeSelects = menuService.buildMenuTreeChecked(allMenuList, menuIdList);
return menuTreeSelects;
}
return Collections.emptyList();
}
private void updateUserMenuUrlCache() { private void updateUserMenuUrlCache() {
//更新用户菜单 //更新用户菜单
Set<String> hkeys = cacheService.hkeys(RedisKey.KEY_USER_MENU_CACHE); Set<String> hkeys = cacheService.hkeys(RedisKey.KEY_USER_MENU_CACHE);
......
...@@ -31,7 +31,7 @@ public class RoleAuthController extends BaseCRUDJsonBodyMappingController<RoleAu ...@@ -31,7 +31,7 @@ public class RoleAuthController extends BaseCRUDJsonBodyMappingController<RoleAu
* 分配资源 * 分配资源
*/ */
@PostMapping(value = "distributionSource") @PostMapping(value = "distributionSource")
public String distributionUser(@RequestBody RoleAuthQuery query) { public String distributionSource(@RequestBody RoleAuthQuery query) {
try { try {
service.doDistributionSource(query,this.getContext()); service.doDistributionSource(query,this.getContext());
JSONObject ret = new JSONObject(); JSONObject ret = new JSONObject();
...@@ -46,4 +46,43 @@ public class RoleAuthController extends BaseCRUDJsonBodyMappingController<RoleAu ...@@ -46,4 +46,43 @@ public class RoleAuthController extends BaseCRUDJsonBodyMappingController<RoleAu
} }
} }
/**
* 分配菜单
*/
@PostMapping(value = "distributionMenu")
public String distributionMenu(@RequestBody RoleAuthQuery query) {
try {
service.doDistributionMenu(query,this.getContext());
JSONObject ret = new JSONObject();
ret.put(KEY_RESULT_CODE, VALUE_RESULT_SUCCESS);
return ret.toJSONString();
} catch (Exception e) {
log.error("分配角色资源错误", e);
JSONObject ret = new JSONObject();
ret.put(KEY_RESULT_CODE, VALUE_RESULT_FAILURE);
ret.put(KEY_RESULT_MSG, super.convertException(e));
return ret.toJSONString();
}
}
/**
* 根据橘色编辑菜单
*/
@PostMapping(value = "editMenu")
public String editMenu(@RequestBody RoleAuthQuery query) {
try {
service.editMenu(query,this.getContext());
JSONObject ret = new JSONObject();
ret.put(KEY_RESULT_CODE, VALUE_RESULT_SUCCESS);
return ret.toJSONString();
} catch (Exception e) {
log.error("分配角色资源错误", e);
JSONObject ret = new JSONObject();
ret.put(KEY_RESULT_CODE, VALUE_RESULT_FAILURE);
ret.put(KEY_RESULT_MSG, super.convertException(e));
return ret.toJSONString();
}
}
} }
\ No newline at end of file
...@@ -45,4 +45,6 @@ application: ...@@ -45,4 +45,6 @@ application:
auth: auth:
unloginUrl: /refresh,/error,/login/login,/login/index,/login/logout,/securitycode/createCode,/file/common/*,/test*,/resource/list,/api/asset/*,/api/*,/uploads/*,/project/file/*,/file/* unloginUrl: /refresh,/error,/login/login,/login/index,/login/logout,/securitycode/createCode,/file/common/*,/test*,/resource/list,/api/asset/*,/api/*,/uploads/*,/project/file/*,/file/*
uncheckUrl: /refresh,/error,/login/login,/login/index,/login/logout,/securitycode/createCode,/file/common/*,/test*,/resource/list,/api/asset/*,/api/*,/uploads/*,/project/file/*,/file/* uncheckUrl: /refresh,/error,/login/login,/login/index,/login/logout,/securitycode/createCode,/file/common/*,/test*,/resource/list,/api/asset/*,/api/*,/uploads/*,/project/file/*,/file/*
dm:
enable: false
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment