use of com.plumdo.common.model.ObjectMap in project plumdo-work by wengwh.
the class RoleResource method saveRoleAndMenu.
private Role saveRoleAndMenu(Role role, ObjectMap roleRequest) {
if (role == null) {
role = new Role();
}
role.setName(roleRequest.getAsString("name"));
role.setRemark(roleRequest.getAsString("remark"));
role.setTenantId(roleRequest.getAsString("tenantId"));
roleRepository.save(role);
roleMenuRepository.deleteByRoleId(role.getId());
List<ObjectMap> menus = roleRequest.getAsList("roleMenus");
for (ObjectMap menu : menus) {
RoleMenu roleMenu = new RoleMenu();
roleMenu.setMenuId(menu.getAsInteger("id"));
roleMenu.setRoleId(role.getId());
roleMenuRepository.save(roleMenu);
}
return role;
}
use of com.plumdo.common.model.ObjectMap in project plumdo-work by wengwh.
the class RoleConverter method convertDetail.
public static ObjectMap convertDetail(Role role, List<Menu> allMenus, List<Menu> roleMenus) {
ObjectMap detailMap = new ObjectMap();
detailMap.put("id", role.getId());
detailMap.put("name", role.getName());
detailMap.put("remark", role.getRemark());
detailMap.put("tenantId", role.getTenantId());
List<ObjectMap> menuList = new ArrayList<>();
for (Menu menu : allMenus) {
if (menu.getType() == TableConstant.MENU_TYPE_CHILD) {
continue;
}
menuList.add(ObjectMap.of("id", menu.getId(), "name", menu.getName(), "group", true));
for (Menu childMenu : allMenus) {
if (menu.getId().equals(childMenu.getParentId())) {
ObjectMap menuMap = ObjectMap.of("id", childMenu.getId(), "name", childMenu.getName());
if (roleMenus.contains(childMenu)) {
menuMap.put("selected", true);
} else {
menuMap.put("selected", false);
}
menuList.add(menuMap);
}
}
menuList.add(ObjectMap.of("group", false));
}
detailMap.put("menus", menuList);
return detailMap;
}
use of com.plumdo.common.model.ObjectMap in project plumdo-work by wengwh.
the class MenuConverter method convertSelectedTree.
public static List<ObjectMap> convertSelectedTree(List<Menu> menus, List<Menu> roleMenus) {
List<ObjectMap> menuList = new ArrayList<>();
for (Menu menu : menus) {
if (menu.getType() == TableConstant.MENU_TYPE_CHILD) {
continue;
}
menuList.add(ObjectMap.of("id", menu.getId(), "name", menu.getName(), "group", true));
for (Menu childMenu : menus) {
if (menu.getId().equals(childMenu.getParentId())) {
if (ObjectUtils.isNotEmpty(roleMenus) && roleMenus.contains(childMenu)) {
menuList.add(ObjectMap.of("id", childMenu.getId(), "name", childMenu.getName(), "selected", true));
} else {
menuList.add(ObjectMap.of("id", childMenu.getId(), "name", childMenu.getName(), "selected", false));
}
}
}
menuList.add(ObjectMap.of("group", false));
}
return menuList;
}