Commit 8371a0d0 authored by hongguangwu's avatar hongguangwu

MVP1.7.14-优化采用用户组控制数据权限的菜单,账号若无用户组,不允许看数据。

parent 65707b1d
...@@ -36,96 +36,113 @@ public class MenuUtil { ...@@ -36,96 +36,113 @@ public class MenuUtil {
private static final String START_STR = "start"; private static final String START_STR = "start";
public void setAuthSql(YifuUser user, BaseEntity entity) { public void setAuthSql(YifuUser user, BaseEntity entity) {
// 是否无权限,默认否
boolean noAuth = false;
// 普通用户: // 普通用户:
if (user != null && Common.isNotNull(user.getId()) && CommonConstants.ONE_STRING.equals(user.getSystemFlag())) { if (user != null && Common.isNotNull(user.getId())) {
// 菜单id if (CommonConstants.ONE_STRING.equals(user.getSystemFlag())) {
String menuId = entity.getMId(); // 菜单id
if (Common.isEmpty(menuId)) { String menuId = entity.getMId();
menuId = entity.getMenuInfo(); if (Common.isEmpty(menuId)) {
} menuId = entity.getMenuInfo();
if (Common.isNotNull(menuId)) { }
String linkId = user.getId(); if (Common.isNotNull(menuId)) {
int linkType = 1; // 用户 String linkId = user.getId();
SysDataAuth sysDataAuth = new SysDataAuth(); int linkType = 1; // 用户
sysDataAuth.setLinkId(linkId); SysDataAuth sysDataAuth = new SysDataAuth();
sysDataAuth.setLinkType(linkType); sysDataAuth.setLinkId(linkId);
// 获取缓存菜单权限的步骤: sysDataAuth.setLinkType(linkType);
Cache cache = cacheManager.getCache(CacheConstants.DATA_AUTH_DETAILS + linkType); // 获取缓存菜单权限的步骤:
Object obj = null; Cache cache = cacheManager.getCache(CacheConstants.DATA_AUTH_DETAILS + linkType);
if (cache != null) { Object obj = null;
obj = cache.get(linkId + CommonConstants.DOWN_LINE_STRING + menuId); if (cache != null) {
if (Common.isEmpty(obj)) {
HttpDaprUtil.invokeMethodPost(daprUpmsProperties.getAppUrl(), daprUpmsProperties.getAppId()
, "/dataAuth/refreshAuth", sysDataAuth, SysDataAuth.class, SecurityConstants.FROM_IN);
obj = cache.get(linkId + CommonConstants.DOWN_LINE_STRING + menuId); obj = cache.get(linkId + CommonConstants.DOWN_LINE_STRING + menuId);
if (Common.isEmpty(obj)) { if (Common.isEmpty(obj)) {
linkId = user.getUserGroup(); HttpDaprUtil.invokeMethodPost(daprUpmsProperties.getAppUrl(), daprUpmsProperties.getAppId()
linkType = 0; // 用户组 , "/dataAuth/refreshAuth", sysDataAuth, SysDataAuth.class, SecurityConstants.FROM_IN);
cache = cacheManager.getCache(CacheConstants.DATA_AUTH_DETAILS + linkType); obj = cache.get(linkId + CommonConstants.DOWN_LINE_STRING + menuId);
if (cache != null) { if (Common.isEmpty(obj)) {
obj = cache.get(linkId + CommonConstants.DOWN_LINE_STRING + menuId); linkId = user.getUserGroup();
if (Common.isEmpty(obj)) { // 无用户组,直接返回阻断sql
sysDataAuth.setLinkId(linkId); if (Common.isEmpty(linkId)) {
sysDataAuth.setLinkType(linkType); entity.setAuthSql( " and 1=2 ");
HttpDaprUtil.invokeMethodPost(daprUpmsProperties.getAppUrl(), daprUpmsProperties.getAppId() return;
, "/dataAuth/refreshAuth", sysDataAuth, SysDataAuth.class, SecurityConstants.FROM_IN); }
linkType = 0; // 用户组
cache = cacheManager.getCache(CacheConstants.DATA_AUTH_DETAILS + linkType);
if (cache != null) {
obj = cache.get(linkId + CommonConstants.DOWN_LINE_STRING + menuId); obj = cache.get(linkId + CommonConstants.DOWN_LINE_STRING + menuId);
if (Common.isEmpty(obj)) {
sysDataAuth.setLinkId(linkId);
sysDataAuth.setLinkType(linkType);
HttpDaprUtil.invokeMethodPost(daprUpmsProperties.getAppUrl(), daprUpmsProperties.getAppId()
, "/dataAuth/refreshAuth", sysDataAuth, SysDataAuth.class, SecurityConstants.FROM_IN);
obj = cache.get(linkId + CommonConstants.DOWN_LINE_STRING + menuId);
}
} }
} }
} }
} }
} if (Common.isNotNull(obj)) {
if (Common.isNotNull(obj)) { SimpleValueWrapper objs = (SimpleValueWrapper) obj;
SimpleValueWrapper objs = (SimpleValueWrapper) obj; if (Common.isNotNull(objs)) {
if (Common.isNotNull(objs)) { String sql = String.valueOf(objs.get());
String sql = String.valueOf(objs.get()); if (sql.contains("#create_by")) {
if (sql.contains("#create_by")) { sql = sql.replace("#create_by", user.getId());
sql = sql.replace("#create_by", user.getId()); }
} if (sql.contains("#settleDomainId")) {
if (sql.contains("#settleDomainId")) { // 获取人员项目权限
// 获取人员项目权限 R<TSettleDomainListVo> res = HttpDaprUtil.invokeMethodPost(daprArchivesProperties.getAppUrl()
R<TSettleDomainListVo> res = HttpDaprUtil.invokeMethodPost(daprArchivesProperties.getAppUrl() , daprArchivesProperties.getAppId(), "/tsettledomain/getSettleDomainIdsByUserId"
, daprArchivesProperties.getAppId(),"/tsettledomain/getSettleDomainIdsByUserId" , user.getId(), TSettleDomainListVo.class, SecurityConstants.FROM_IN);
, user.getId(), TSettleDomainListVo.class, SecurityConstants.FROM_IN); StringBuilder deptStr = new StringBuilder();
StringBuilder deptStr = new StringBuilder(); if (res != null && CommonConstants.SUCCESS == res.getCode()
if (res != null && CommonConstants.SUCCESS == res.getCode() && res.getData() != null && res.getData().getDeptIds() != null
&& res.getData() != null && res.getData().getDeptIds() != null && !res.getData().getDeptIds().isEmpty()) {
&& !res.getData().getDeptIds().isEmpty()) { for (String deptId : res.getData().getDeptIds()) {
for (String deptId : res.getData().getDeptIds()) { deptStr.append(",'").append(deptId).append("'");
deptStr.append(",'").append(deptId).append("'"); }
} }
//sql = sql.replace("or a.settle_domain_id in ('0'#settleDomainId) ", "")
sql = sql.replace("#settleDomainId", deptStr.toString());
} }
//sql = sql.replace("or a.settle_domain_id in ('0'#settleDomainId) ", "") String userIds = "0";
sql = sql.replace("#settleDomainId", deptStr.toString()); if (sql.contains(START_STR)) {
} String deptIds = StringUtils.substringBetween(sql, START_STR, "end");
String userIds = "0"; R<String> userIdR = HttpDaprUtil.invokeMethodPost(daprUpmsProperties.getAppUrl()
if (sql.contains(START_STR)) { , daprUpmsProperties.getAppId(), "/user/inner/getUserIdByDeptIds", deptIds
String deptIds = StringUtils.substringBetween(sql,START_STR, "end"); , String.class, SecurityConstants.FROM_IN);
R<String> userIdR = HttpDaprUtil.invokeMethodPost(daprUpmsProperties.getAppUrl() if (userIdR != null && CommonConstants.SUCCESS == userIdR.getCode()) {
,daprUpmsProperties.getAppId(),"/user/inner/getUserIdByDeptIds",deptIds userIds = userIdR.getData();
, String.class, SecurityConstants.FROM_IN); }
if (userIdR != null && CommonConstants.SUCCESS == userIdR.getCode()) { sql = sql.replace(START_STR, "").replace("end", "")
userIds = userIdR.getData(); .replace(deptIds, userIds);
} }
sql = sql.replace(START_STR, "").replace("end", "") if (sql.contains("#deptId")) {
.replace(deptIds, userIds); R<String> userIdR = HttpDaprUtil.invokeMethodPost(daprUpmsProperties.getAppUrl()
} , daprUpmsProperties.getAppId(), "/user/inner/getUserIdByDeptIds"
if (sql.contains("#deptId")) { , String.valueOf(user.getDeptId()), String.class, SecurityConstants.FROM_IN);
R<String> userIdR = HttpDaprUtil.invokeMethodPost(daprUpmsProperties.getAppUrl() if (userIdR != null && CommonConstants.SUCCESS == userIdR.getCode()) {
,daprUpmsProperties.getAppId(),"/user/inner/getUserIdByDeptIds" userIds = userIdR.getData();
,String.valueOf(user.getDeptId()), String.class, SecurityConstants.FROM_IN); }
if (userIdR != null && CommonConstants.SUCCESS == userIdR.getCode()) { sql = sql.replace("#deptId", userIds);
userIds = userIdR.getData(); //sql = sql.replace(" or dept.dept_id = #deptId ", "")
}
if (Common.isNotNull(sql)) {
entity.setAuthSql(sql);
} }
sql = sql.replace("#deptId", userIds);
//sql = sql.replace(" or dept.dept_id = #deptId ", "")
}
if (Common.isNotNull(sql)) {
entity.setAuthSql(sql);
} }
} }
} else {
noAuth = true;
} }
} }
} else {
noAuth = true;
}
// 无权限的,默认无数据
if (noAuth) {
entity.setAuthSql( " and 1=2 ");
} }
} }
} }
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