@@ -21,6 +21,7 @@ import cc.smtweb.system.bpm.web.sys.user.menuPlan.MenuPlan; | |||
import cc.smtweb.system.bpm.web.sys.user.menuPlan.MenuPlanCache; | |||
import cc.smtweb.system.bpm.web.sys.user.menuPlan.MenuPlanContent; | |||
import cc.smtweb.system.bpm.web.sys.user.menuPlan.MenuPlanItem; | |||
import cc.smtweb.system.bpm.web.sys.user.role.RoleHelper; | |||
import org.apache.commons.lang3.StringUtils; | |||
import java.util.*; | |||
@@ -36,6 +37,8 @@ public class PreviewMenuTreeService { | |||
List<MenuVO> menuVOList = buildMenu(prj_id, module, us); | |||
if (!CommUtil.isEmpty(menuVOList)) { | |||
return R.success(menuVOList); | |||
}else { | |||
return R.success(new ArrayList<>()); | |||
} | |||
} | |||
List<ModelForm> listForm; | |||
@@ -78,15 +81,16 @@ public class PreviewMenuTreeService { | |||
} | |||
public List<MenuVO> buildMenu(String prj_id, String module, UserSession us) { | |||
Set<MenuPlan> set = MenuPlanCache.getInstance().getByP(prj_id); | |||
Set<MenuPlan> set = RoleHelper.getMenuPlans(us.getUserId(),us.getPartyId()); | |||
if (CommUtil.isEmpty(set)) { | |||
return new ArrayList<>(); | |||
} | |||
MenuPlan menuPlan = set.iterator().next(); | |||
MenuPlanContent mpc = new MenuPlanContent(menuPlan.getContent()); | |||
List<MenuVO> list = new ArrayList<>(); | |||
Set<Long> rightMenuIds = RoleHelper.getRoleMenuIds(us.getUserId() , us.getPartyId(),menuPlan.getId(), true); | |||
for (MenuPlanItem mp : mpc.getChildren(0)) { | |||
List<MenuVO> menuVOList = buildMenu(-1, mp); | |||
List<MenuVO> menuVOList = buildMenuWithRight(-1, mp,rightMenuIds); | |||
if (menuVOList == null) continue; | |||
list.addAll(menuVOList); | |||
} | |||
@@ -118,7 +122,27 @@ public class PreviewMenuTreeService { | |||
list.add(menu); | |||
return list; | |||
} | |||
private List<MenuVO> buildMenuWithRight(long parent_id, MenuPlanItem mp,Set<Long> rightMenuIds) { | |||
if (mp == null || !rightMenuIds.contains(mp.getId())) return null; | |||
List<MenuVO> list = new ArrayList<>(); | |||
MenuVO menu = new MenuVO(); | |||
menu.setId(mp.getId()); | |||
menu.setName(mp.getLabel()); | |||
menu.setIcon(mp.getIcon()); | |||
menu.setPath(MenuCache.getInstance().getPath(mp.getMenu())); | |||
menu.setParentId(parent_id); | |||
List<MenuVO> child = new ArrayList<>(); | |||
if (!CommUtil.isEmpty(mp.getChildren())) { | |||
for (MenuPlanItem cmp : mp.getChildren()) { | |||
List<MenuVO> m = buildMenuWithRight(menu.getId(), cmp,rightMenuIds); | |||
if (m == null) continue; | |||
child.addAll(m); | |||
} | |||
} | |||
menu.setChildren(child); | |||
list.add(menu); | |||
return list; | |||
} | |||
private MenuVO setMenuParent(Long parent_id, Map<Long, MenuVO> map, List<MenuVO> list) { | |||
MenuVO parent = map.get(parent_id); | |||
if (parent != null) return parent; | |||
@@ -55,7 +55,7 @@ public class AuthService { | |||
// return new UserSession(1); | |||
} else { | |||
user = LoginHelper.login(loginPO); | |||
userSession = new UserSession(user.getId()); | |||
userSession = LoginHelper.createUserSession(user); | |||
} | |||
} catch (BizException e) { | |||
data.put("isOk", false); | |||
@@ -8,10 +8,13 @@ import cc.smtweb.framework.core.exception.BizException; | |||
import cc.smtweb.framework.core.session.UserSession; | |||
import cc.smtweb.system.bpm.web.sys.user.user.User; | |||
import cc.smtweb.system.bpm.web.sys.user.user.UserCache; | |||
import cc.smtweb.system.bpm.web.sys.user.user.UserParty; | |||
import cc.smtweb.system.bpm.web.sys.user.user.UserPartyCache; | |||
import org.apache.commons.codec.digest.DigestUtils; | |||
import org.apache.commons.lang3.StringUtils; | |||
import java.util.List; | |||
import java.util.Set; | |||
/** | |||
* Created with IntelliJ IDEA. | |||
@@ -73,7 +76,17 @@ public class LoginHelper { | |||
if (user == null) { | |||
throw new BizException("账号或者密码出错"); | |||
} | |||
return new UserSession(user.getId()); | |||
return createUserSession(user); | |||
} | |||
public static UserSession createUserSession(User user){ | |||
UserSession us = new UserSession(user.getId()); | |||
Set<UserParty> ups = UserPartyCache.getInstance().getByUser(String.valueOf(us.getUserId())); | |||
if(ups!=null&&ups.size()>0){ | |||
UserParty up = ups.iterator().next(); | |||
us.setPartyId(up.getPartyId()); | |||
us.setDeptId(up.getDeptId()); | |||
} | |||
return us; | |||
} | |||
// public static UserSession login(LoginVO loginPO) { | |||
@@ -4,6 +4,7 @@ import cc.smtweb.framework.core.annotation.SwCache; | |||
import cc.smtweb.framework.core.cache.AbstractEntityCache; | |||
import cc.smtweb.framework.core.cache.CacheManager; | |||
import cc.smtweb.framework.core.util.CommUtil; | |||
import cc.smtweb.framework.core.util.StringUtil; | |||
import java.util.HashSet; | |||
import java.util.Set; | |||
@@ -36,6 +37,6 @@ public class RoleCache extends AbstractEntityCache<Role> { | |||
key.forEach(k -> { | |||
names.add(get(k).getName()); | |||
}); | |||
return CommUtil.getSqlInStr(names); | |||
return StringUtil.join(names,","); | |||
} | |||
} |
@@ -0,0 +1,120 @@ | |||
package cc.smtweb.system.bpm.web.sys.user.role; | |||
import cc.smtweb.system.bpm.web.sys.user.menuPlan.MenuPlan; | |||
import cc.smtweb.system.bpm.web.sys.user.menuPlan.MenuPlanCache; | |||
import cc.smtweb.system.bpm.web.sys.user.menuPlan.MenuPlanContent; | |||
import cc.smtweb.system.bpm.web.sys.user.menuPlan.MenuPlanItem; | |||
import cc.smtweb.system.bpm.web.sys.user.user.UserRoleCache; | |||
import java.util.HashSet; | |||
import java.util.List; | |||
import java.util.Set; | |||
/** | |||
* @Author: tanghp | |||
* @Date: 2022-09-06 18:35 | |||
* @Desc: 角色辅助类 | |||
*/ | |||
public final class RoleHelper { | |||
/** | |||
* 获取角色权限 | |||
* @param userId 用户ID | |||
* @param menuPlanId 菜单方案ID | |||
* @return | |||
*/ | |||
public static List<RoleRight> getRoleRightList(long userId, long menuPlanId){ | |||
return null; | |||
} | |||
/** | |||
* 获取用户的菜单权限 | |||
* @param userId 用户ID | |||
* @param partyId 机构ID | |||
* @param incParent 是否包含父节点,(子节点配置了,把父节点也查出来) | |||
* @return | |||
*/ | |||
public static Set<Long> getRoleMenuIds(long userId,long partyId,boolean incParent){ | |||
Set<Long> mpIds = getMenuPlanIds(userId,partyId); | |||
if(mpIds.size()==0){ | |||
return new HashSet<>(); | |||
} | |||
return getRoleMenuIds(userId,partyId,mpIds.iterator().next(),incParent); | |||
} | |||
/** | |||
* 获取用户的菜单权限 | |||
* @param userId 用户ID | |||
* @param partyId 机构ID | |||
* @param menuPlanId 菜单方案ID | |||
* @param incParent 是否包含父节点,(子节点配置了,把父节点也查出来) | |||
* @return | |||
*/ | |||
public static Set<Long> getRoleMenuIds(long userId,long partyId, long menuPlanId,boolean incParent){ | |||
Set<Long> menuIds = new HashSet<>(); | |||
MenuPlan menuPlan = MenuPlanCache.getInstance().get(menuPlanId); | |||
if(menuPlan==null)return menuIds; | |||
Set<Long> roleIds = UserRoleCache.getInstance().getRoleIdByUP(userId,partyId); | |||
RoleCache roleCache = RoleCache.getInstance(); | |||
roleIds.forEach((roleId)-> { | |||
Role role = roleCache.get(roleId); | |||
if(role==null || role.getSmpId()!=menuPlanId){ | |||
return; | |||
} | |||
RoleRightContent roleRightContent = new RoleRightContent(role.getPrivilege()); | |||
menuIds.addAll(roleRightContent.getMenuRightIds()); | |||
}); | |||
MenuPlanContent menuPlanContent = new MenuPlanContent(menuPlan.getContent()); | |||
if(incParent){ | |||
Set<Long> tempIds = new HashSet<>(menuIds); | |||
tempIds.forEach(id->{ | |||
fillMenuId(id,menuPlanContent,menuIds); | |||
}); | |||
} | |||
return menuIds; | |||
} | |||
private static void fillMenuId(Long id,MenuPlanContent menuPlanContent, Set<Long> menuIds){ | |||
menuIds.add(id); | |||
MenuPlanItem parent = menuPlanContent.findParentById(id); | |||
if(parent!=null){ | |||
if(!menuIds.contains(parent.getId())){ | |||
fillMenuId(parent.getId(),menuPlanContent,menuIds); | |||
} | |||
} | |||
} | |||
/** | |||
* 获取用户的菜单方案 | |||
* @param userId 用户ID | |||
* @param partyId 机构ID | |||
* @return 菜单方案ID | |||
*/ | |||
public static Set<Long> getMenuPlanIds(long userId,long partyId){ | |||
Set<Long> mpList = new HashSet<>(); | |||
Set<Long> roleIds = UserRoleCache.getInstance().getRoleIdByUP(userId,partyId); | |||
RoleCache roleCache = RoleCache.getInstance(); | |||
roleIds.forEach((roleId)-> { | |||
Role role = roleCache.get(roleId); | |||
if(role!=null&&role.getSmpId()>0L){ | |||
mpList.add(role.getSmpId()); | |||
} | |||
}); | |||
return mpList; | |||
} | |||
/** | |||
* 获取用户的菜单方案 | |||
* @param userId 用户ID | |||
* @param partyId 机构ID | |||
* @return 菜单方案 | |||
*/ | |||
public static Set<MenuPlan> getMenuPlans(long userId,long partyId){ | |||
Set<MenuPlan> mpList = new HashSet<>(); | |||
Set<Long> roleIds = UserRoleCache.getInstance().getRoleIdByUP(userId,partyId); | |||
roleIds.forEach((roleId)-> { | |||
Role role = RoleCache.getInstance().get(roleId); | |||
if(role!=null&&role.getSmpId()>0L){ | |||
MenuPlan mp = MenuPlanCache.getInstance().get(role.getSmpId()); | |||
if(mp!=null){ | |||
mpList.add(mp); | |||
} | |||
} | |||
}); | |||
return mpList; | |||
} | |||
} |
@@ -72,7 +72,14 @@ public class RoleRightContent { | |||
}); | |||
return CommUtil.getSqlInStr(menus); | |||
} | |||
public Set<Long> getMenuRightIds() { | |||
Set<Long> ids = new HashSet<>(); | |||
if (map.size() == 0) return ids; | |||
map.values().forEach(roleRight -> { | |||
if (roleRight.getMenu() == 1) ids.add(roleRight.getId()); | |||
}); | |||
return ids; | |||
} | |||
public String getFieldRight(long key, int type) { | |||
RoleRight right = getRoleRight(key); | |||
if (right == null) return ""; | |||
@@ -240,7 +240,7 @@ public class StringUtil { | |||
* @param delim the delimiter character(s) to use. (null value will join with no delimiter) | |||
* @return a String of all values in the list seperated by the delimiter | |||
*/ | |||
public static String join(List<String> list, String delim) { | |||
public static String join(Collection<String> list, String delim) { | |||
if (list == null || list.size() < 1) | |||
return null; | |||
StringBuffer buf = new StringBuffer(); | |||