Commit 9e75c489 authored by 赵啸非's avatar 赵啸非

更新用户同步通知,token不足二十分钟刷新

parent 3da50dcc
......@@ -97,11 +97,14 @@ public class AuthTokenServiceImpl implements IAuthTokenService {
String token = getToken(request);
if (StringUtils.isNotEmpty(token)) {
try {
boolean signed = Jwts.parser().isSigned(token);
if (!signed) {
log.error("token非法!=>{}", token);
return null;
}
Claims claims = parseToken(token);
String uuid = (String) claims.get(SysConstains.LOGIN_USER_KEY);
String userKey = getTokenKey(uuid);
// Rest<String> rest = userFeign.getToken(userKey);
// String userStr = rest.getData();
String userStr = "";
if (platFormType.equalsIgnoreCase(PlatformTypeEnum.CLOUD.getValue())) {
cacheService.select(portalDb);
......@@ -124,7 +127,7 @@ public class AuthTokenServiceImpl implements IAuthTokenService {
if (!ObjectUtils.isEmpty(temp)) {
userEntity.setId(temp.getId());
}
//更新menul
//更新resource 路径
String menuUrlCode = cacheService.hget(RedisKey.KEY_USER_MENU_CACHE, userEntity.getId().toString(), String.class);
if (ObjectUtils.isEmpty(menuUrlCode)) {
Set<String> urls = resourceService.findUrlSetByUserId(userEntity.getId());
......
/**
* 文件:ResourceServiceImpl.java
* 版本:1.0.0
* 日期:
* Copyright &reg;
* All right reserved.
*/
* 文件:ResourceServiceImpl.java
* 版本:1.0.0
* 日期:
* Copyright &reg;
* All right reserved.
*/
package com.mortals.xhx.base.system.resource.service.impl;
......@@ -19,10 +19,15 @@ import com.mortals.xhx.base.system.resource.model.ResourceEntity;
import com.mortals.xhx.base.system.resource.model.ResourceQuery;
import com.mortals.xhx.base.system.resource.service.ResourceService;
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.service.RoleAuthService;
import com.mortals.xhx.common.key.RedisKey;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
......@@ -34,15 +39,18 @@ import static com.mortals.xhx.common.utils.MenuEncodeUtil.generateMenuUrlCode;
* <p>Description: ResourceServiceImpl service接口 </p>
* <p>Copyright: Copyright &reg; </p>
* <p>Company: </p>
* @author
* @author
* @version 1.0.0
*/
@Service("resourceService")
public class ResourceServiceImpl extends AbstractCRUDServiceImpl<ResourceDao,ResourceEntity,Long> implements ResourceService {
public class ResourceServiceImpl extends AbstractCRUDServiceImpl<ResourceDao, ResourceEntity, Long> implements ResourceService {
@Autowired
private ICacheService cacheService;
@Autowired
private RoleAuthService roleAuthService;
@Override
public List<ResourceEntity> findAllEnable() throws AppException {
ResourceQuery params = new ResourceQuery();
......@@ -91,13 +99,27 @@ public class ResourceServiceImpl extends AbstractCRUDServiceImpl<ResourceDao,Res
updateUserMenuUrlCache();
}
@Override
protected void removeAfter(Long[] ids, Context context, int result) throws AppException {
//删除关联表中数据
if (!ObjectUtils.isEmpty(ids)) {
RoleAuthQuery query = new RoleAuthQuery();
query.setResourceIdList(Arrays.asList(ids));
List<RoleAuthEntity> roleAuthEntities = roleAuthService.find(query);
if (!ObjectUtils.isEmpty(roleAuthEntities)) {
roleAuthService.remove(roleAuthEntities.stream().map(m -> m.getId()).toArray(Long[]::new), context);
updateUserMenuUrlCache();
}
}
}
private void updateUserMenuUrlCache() {
//更新用户菜单
Set<String> hkeys = cacheService.hkeys(RedisKey.KEY_USER_MENU_CACHE);
for (String userId : hkeys) {
Set<String> urls = this.findUrlSetByUserId(DataUtil.converStr2Long(userId,0L));
Set<String> urls = this.findUrlSetByUserId(DataUtil.converStr2Long(userId, 0L));
String menuUrlCode = generateMenuUrlCode(urls);
cacheService.hset(RedisKey.KEY_USER_MENU_CACHE, userId,menuUrlCode);
cacheService.hset(RedisKey.KEY_USER_MENU_CACHE, userId, menuUrlCode);
}
}
}
\ No newline at end of file
/**
* 文件:RoleAuthServiceImpl.java
* 版本:1.0.0
* 日期:
* Copyright &reg;
* All right reserved.
*/
* 文件:RoleAuthServiceImpl.java
* 版本:1.0.0
* 日期:
* Copyright &reg;
* All right reserved.
*/
package com.mortals.xhx.base.system.role.service.impl;
import com.mortals.framework.service.ICacheService;
import com.mortals.framework.service.impl.AbstractCRUDServiceImpl;
import com.mortals.framework.util.DataUtil;
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.model.RoleAuthEntity;
import com.mortals.xhx.base.system.role.model.RoleAuthQuery;
import com.mortals.xhx.base.system.role.service.RoleAuthService;
import com.mortals.xhx.common.key.RedisKey;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
import static com.mortals.xhx.common.utils.MenuEncodeUtil.generateMenuUrlCode;
/**
* <p>Title: 角色资源权限</p>
* <p>Description: RoleAuthServiceImpl service接口 </p>
* <p>Copyright: Copyright &reg; </p>
* <p>Company: </p>
* @author
* @author
* @version 1.0.0
*/
@Service("roleAuthService")
public class RoleAuthServiceImpl extends AbstractCRUDServiceImpl<RoleAuthDao,RoleAuthEntity,Long> implements RoleAuthService {
public class RoleAuthServiceImpl extends AbstractCRUDServiceImpl<RoleAuthDao, RoleAuthEntity, Long> implements RoleAuthService {
@Autowired
private ICacheService cacheService;
@Autowired
private ResourceService resourceService;
@Override
public void doDistributionSource(RoleAuthQuery query) {
......@@ -49,6 +56,18 @@ public class RoleAuthServiceImpl extends AbstractCRUDServiceImpl<RoleAuthDao,Rol
list.add(entity);
}
this.dao.insertBatch(list);
this.updateUserMenuUrlCache();
}
private void updateUserMenuUrlCache() {
//更新用户菜单
Set<String> hkeys = cacheService.hkeys(RedisKey.KEY_USER_MENU_CACHE);
for (String userId : hkeys) {
Set<String> urls = resourceService.findUrlSetByUserId(DataUtil.converStr2Long(userId, 0L));
String menuUrlCode = generateMenuUrlCode(urls);
cacheService.hset(RedisKey.KEY_USER_MENU_CACHE, userId, menuUrlCode);
}
}
}
\ No newline at end of file
......@@ -8,6 +8,8 @@
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.service.ICacheService;
import com.mortals.framework.service.impl.AbstractCRUDServiceImpl;
import com.mortals.framework.util.DataUtil;
......@@ -81,6 +83,10 @@ public class RoleUserServiceImpl extends AbstractCRUDServiceImpl<RoleUserDao, Ro
updateUserMenuUrlCache();
}
@Override
protected void removeAfter(Long[] ids, Context context, int result) throws AppException {
updateUserMenuUrlCache();
}
private void updateUserMenuUrlCache() {
//更新用户菜单
......
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