Commit 0a3a3e78 authored by 赵啸非's avatar 赵啸非

添加菜单资源配置

parent 26c85420
...@@ -123,11 +123,11 @@ public class AuthTokenServiceImpl implements IAuthTokenService { ...@@ -123,11 +123,11 @@ public class AuthTokenServiceImpl implements IAuthTokenService {
} }
//更新resource 路径 //更新resource 路径
String menuUrlCode = cacheService.hget(RedisKey.KEY_USER_MENU_CACHE, userEntity.getId().toString(), String.class); String menuUrlCode = cacheService.hget(RedisKey.KEY_USER_MENU_CACHE, userEntity.getId().toString(), String.class);
if (ObjectUtils.isEmpty(menuUrlCode)) { // if (ObjectUtils.isEmpty(menuUrlCode)) {
Set<String> urls = resourceService.findUrlSetByUserId(userEntity.getId()); // Set<String> urls = resourceService.findUrlSetByUserId(userEntity.getId());
menuUrlCode = MenuEncodeUtil.generateMenuUrlCode(urls); // menuUrlCode = MenuEncodeUtil.generateMenuUrlCode(urls);
cacheService.hset(RedisKey.KEY_USER_MENU_CACHE, userEntity.getId().toString(), menuUrlCode); // cacheService.hset(RedisKey.KEY_USER_MENU_CACHE, userEntity.getId().toString(), menuUrlCode);
} // }
userEntity.setMenuUrl(menuUrlCode); userEntity.setMenuUrl(menuUrlCode);
return userEntity; return userEntity;
} }
......
...@@ -69,7 +69,6 @@ public class ResourceServiceImpl extends AbstractCRUDServiceImpl<ResourceDao, Re ...@@ -69,7 +69,6 @@ public class ResourceServiceImpl extends AbstractCRUDServiceImpl<ResourceDao, Re
continue; continue;
} }
urls.add(url); urls.add(url);
// url = url.replaceAll(",", ",");
} }
return urls; return urls;
} }
......
...@@ -21,7 +21,9 @@ import com.mortals.xhx.base.system.resource.service.ResourceService; ...@@ -21,7 +21,9 @@ 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;
import com.mortals.xhx.base.system.role.model.RoleAuthQuery; import com.mortals.xhx.base.system.role.model.RoleAuthQuery;
import com.mortals.xhx.base.system.role.model.RoleUserQuery;
import com.mortals.xhx.base.system.role.service.RoleAuthService; import com.mortals.xhx.base.system.role.service.RoleAuthService;
import com.mortals.xhx.base.system.role.service.RoleUserService;
import com.mortals.xhx.common.key.RedisKey; import com.mortals.xhx.common.key.RedisKey;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy; import org.springframework.context.annotation.Lazy;
...@@ -49,6 +51,8 @@ public class RoleAuthServiceImpl extends AbstractCRUDServiceImpl<RoleAuthDao, Ro ...@@ -49,6 +51,8 @@ public class RoleAuthServiceImpl extends AbstractCRUDServiceImpl<RoleAuthDao, Ro
private ICacheService cacheService; private ICacheService cacheService;
@Autowired @Autowired
private MenuService menuService; private MenuService menuService;
@Autowired
private RoleUserService roleUserService;
@Autowired @Autowired
@Lazy @Lazy
...@@ -56,12 +60,9 @@ public class RoleAuthServiceImpl extends AbstractCRUDServiceImpl<RoleAuthDao, Ro ...@@ -56,12 +60,9 @@ public class RoleAuthServiceImpl extends AbstractCRUDServiceImpl<RoleAuthDao, Ro
@Override @Override
public void doDistributionSource(RoleAuthQuery query, Context context) { public void doDistributionSource(RoleAuthQuery query, Context context) {
if (ObjectUtils.isEmpty(query.getRoleId())) throw new AppException("角色不能为空!");
// 删除角色资源老数据 // 删除角色资源老数据
Long roleId = query.getRoleId(); Long roleId = query.getRoleId();
/* Map<String, Object> condition = new HashMap<>();
condition.put("roleId", roleId);
this.dao.delete(condition);*/
//todo
RoleAuthQuery roleAuthQuery = new RoleAuthQuery(); RoleAuthQuery roleAuthQuery = new RoleAuthQuery();
roleAuthQuery.setRoleId(roleId); roleAuthQuery.setRoleId(roleId);
Long[] delIds = this.find(roleAuthQuery).stream() Long[] delIds = this.find(roleAuthQuery).stream()
...@@ -80,17 +81,23 @@ public class RoleAuthServiceImpl extends AbstractCRUDServiceImpl<RoleAuthDao, Ro ...@@ -80,17 +81,23 @@ public class RoleAuthServiceImpl extends AbstractCRUDServiceImpl<RoleAuthDao, Ro
} }
this.dao.insertBatch(list); this.dao.insertBatch(list);
this.updateUserMenuUrlCache();
//查询所有有这个用户角色的用户
// this.find(new RoleAuthQuery().roleId(roleId)).stream().filter(f->f.get)
List<Long> userIdList = roleUserService.find(new RoleUserQuery().roleId(query.getRoleId())).stream()
.map(m -> m.getUserId())
.filter(f -> f != null)
.distinct().collect(Collectors.toList());
this.updateUserMenuUrlCache(userIdList);
} }
@Override @Override
public void doDistributionMenu(RoleAuthQuery query, Context context) { public void doDistributionMenu(RoleAuthQuery query, Context context) {
if (ObjectUtils.isEmpty(query.getRoleId())) throw new AppException("角色不能为空!");
// 删除角色资源老数据 // 删除角色资源老数据
Long roleId = query.getRoleId(); Long roleId = query.getRoleId();
/* Map<String, Object> condition = new HashMap<>();
condition.put("roleId", roleId);
this.dao.delete(condition);*/
//todo
RoleAuthQuery roleAuthQuery = new RoleAuthQuery(); RoleAuthQuery roleAuthQuery = new RoleAuthQuery();
roleAuthQuery.setRoleId(roleId); roleAuthQuery.setRoleId(roleId);
Long[] delIds = this.find(roleAuthQuery).stream() Long[] delIds = this.find(roleAuthQuery).stream()
...@@ -108,13 +115,16 @@ public class RoleAuthServiceImpl extends AbstractCRUDServiceImpl<RoleAuthDao, Ro ...@@ -108,13 +115,16 @@ public class RoleAuthServiceImpl extends AbstractCRUDServiceImpl<RoleAuthDao, Ro
list.add(entity); list.add(entity);
} }
this.dao.insertBatch(list); this.dao.insertBatch(list);
List<Long> userIdList = roleUserService.find(new RoleUserQuery().roleId(query.getRoleId())).stream()
this.updateUserMenuUrlCache(); .map(m -> m.getUserId())
.filter(f -> f != null)
.distinct().collect(Collectors.toList());
this.updateUserMenuUrlCache(userIdList);
} }
@Override @Override
public List<MenuTreeSelect> editMenu(RoleAuthQuery query, Context context) { public List<MenuTreeSelect> editMenu(RoleAuthQuery query, Context context) {
if (ObjectUtils.isEmpty(query.getRoleId())) throw new AppException("角色不能为空"); if (ObjectUtils.isEmpty(query.getRoleId())) throw new AppException("角色不能为空!");
RoleAuthQuery roleAuthQuery = new RoleAuthQuery(); RoleAuthQuery roleAuthQuery = new RoleAuthQuery();
roleAuthQuery.setRoleId(query.getRoleId()); roleAuthQuery.setRoleId(query.getRoleId());
...@@ -131,13 +141,11 @@ public class RoleAuthServiceImpl extends AbstractCRUDServiceImpl<RoleAuthDao, Ro ...@@ -131,13 +141,11 @@ public class RoleAuthServiceImpl extends AbstractCRUDServiceImpl<RoleAuthDao, Ro
} }
private void updateUserMenuUrlCache() { private void updateUserMenuUrlCache(List<Long> userIdList) {
//更新用户菜单 for (Long userId : userIdList) {
Set<String> hkeys = cacheService.hkeys(RedisKey.KEY_USER_MENU_CACHE); Set<String> urls = resourceService.findUrlSetByUserId(userId);
for (String userId : hkeys) {
Set<String> urls = resourceService.findUrlSetByUserId(DataUtil.converStr2Long(userId, 0L));
String menuUrlCode = generateMenuUrlCode(urls); String menuUrlCode = generateMenuUrlCode(urls);
cacheService.hset(RedisKey.KEY_USER_MENU_CACHE, userId, menuUrlCode); cacheService.hset(RedisKey.KEY_USER_MENU_CACHE, userId.toString(), menuUrlCode);
} }
} }
......
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