Browse Source

配置pc客户菜单时 删除缓存

release
jianjun 4 years ago
parent
commit
5d9828085c
  1. 2
      epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/redis/RedisKeys.java
  2. 55
      epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/redis/GovCustomerMenuRedis.java
  3. 10
      epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/redis/GovMenuRedis.java
  4. 6
      epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/service/impl/GovCustomerMenuServiceImpl.java
  5. 8
      epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/service/impl/GovMenuServiceImpl.java

2
epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/redis/RedisKeys.java

@ -734,6 +734,6 @@ public class RedisKeys {
}
public static String getCustomerMenuList(String customerId, Integer type) {
return rootPrefix.concat("oper:access:nav:customerId:").concat(customerId)+type;
return rootPrefix.concat("oper:access:nav:customerId:").concat(customerId).concat(":type:")+type;
}
}

55
epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/redis/GovCustomerMenuRedis.java

@ -17,31 +17,72 @@
package com.epmet.redis;
import com.epmet.commons.tools.redis.RedisKeys;
import com.epmet.commons.tools.redis.RedisUtils;
import com.epmet.dto.GovMenuDTO;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.List;
/**
* 客户菜单配置表
*
* @author generator generator@elink-cn.com
* @since v1.0.0 2021-03-16
*/
@Slf4j
@Component
public class GovCustomerMenuRedis {
@Autowired
private RedisUtils redisUtils;
public void delete(Object[] ids) {
/**
* desc:保存客户菜单缓存
* @param customerId
* @param type
* @see com.epmet.enums.MenuTypeEnum
*/
public void setCustomerMenuList(String customerId, Integer type, List<GovMenuDTO> govMenuDTOS) {
if (checkParam(customerId, type)) {
String key = RedisKeys.getCustomerMenuList(customerId, type);
redisUtils.set(key, govMenuDTOS, RedisUtils.DEFAULT_EXPIRE);
}
}
/**
* desc:获取客户菜单缓存
* @param customerId
* @param type
* @see com.epmet.enums.MenuTypeEnum
*/
public List<GovMenuDTO> getCustomerMenuList(String customerId, Integer type) {
if (checkParam(customerId, type)) {
String key = RedisKeys.getCustomerMenuList(customerId, type);
return (List<GovMenuDTO>) redisUtils.get(key);
}
return null;
}
public void set(){
/**
* desc:删除客户菜单缓存
* @param customerId
* @param type
* @see com.epmet.enums.MenuTypeEnum
*/
public void delCustomerMenu(String customerId, Integer type) {
if (checkParam(customerId, type)) {
String key = RedisKeys.getCustomerMenuList(customerId, type);
redisUtils.delete(key);
}
}
public String get(String id){
return null;
private boolean checkParam(String customerId, Integer type) {
if (StringUtils.isBlank(customerId) || type == null){
log.warn("checkParam fail, param is null");
return false;
}
return true;
}
}

10
epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/redis/GovMenuRedis.java

@ -70,14 +70,4 @@ public class GovMenuRedis {
String key = RedisKeys.getUserPermissionsKey(userId, app, client);
return (Set<String>)redisUtils.get(key);
}
public void setCustomerMenuList(String customerId, Integer type, List<GovMenuDTO> govMenuDTOS) {
String key = RedisKeys.getCustomerMenuList(customerId, type);
redisUtils.set(key,govMenuDTOS,RedisUtils.DEFAULT_EXPIRE);
}
public List<GovMenuDTO> getCustomerMenuList(String customerId, Integer type) {
String key = RedisKeys.getCustomerMenuList(customerId, type);
return (List<GovMenuDTO>)redisUtils.get(key);
}
}

6
epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/service/impl/GovCustomerMenuServiceImpl.java

@ -20,14 +20,15 @@ package com.epmet.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.epmet.commons.mybatis.service.impl.BaseServiceImpl;
import com.epmet.commons.tools.constant.FieldConstant;
import com.epmet.commons.tools.constant.NumConstant;
import com.epmet.commons.tools.page.PageData;
import com.epmet.commons.tools.utils.ConvertUtils;
import com.epmet.commons.tools.constant.FieldConstant;
import com.epmet.dao.GovCustomerMenuDao;
import com.epmet.dto.GovCustomerMenuDTO;
import com.epmet.dto.form.MenuConfigFormDTO;
import com.epmet.entity.GovCustomerMenuEntity;
import com.epmet.enums.MenuTypeEnum;
import com.epmet.redis.GovCustomerMenuRedis;
import com.epmet.service.GovCustomerMenuService;
import org.apache.commons.lang3.StringUtils;
@ -105,6 +106,7 @@ public class GovCustomerMenuServiceImpl extends BaseServiceImpl<GovCustomerMenuD
}
@Override
@Transactional(rollbackFor = Exception.class)
public void saveCustomerMenu(MenuConfigFormDTO formDTO) {
baseDao.deleteBatchTableIds(formDTO.getTableId());
if (NumConstant.ZERO < formDTO.getCustomerIds().size()) {
@ -117,6 +119,8 @@ public class GovCustomerMenuServiceImpl extends BaseServiceImpl<GovCustomerMenuD
}
insertBatch(entities);
}
//删除缓存
formDTO.getCustomerIds().forEach(customerId-> govCustomerMenuRedis.delCustomerMenu(customerId, MenuTypeEnum.MENU.value()));
}
@Override

8
epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/service/impl/GovMenuServiceImpl.java

@ -33,7 +33,7 @@ import com.epmet.dao.GovMenuDao;
import com.epmet.dto.GovMenuDTO;
import com.epmet.entity.GovMenuEntity;
import com.epmet.enums.MenuTypeEnum;
import com.epmet.feign.EpmetUserFeignClient;
import com.epmet.redis.GovCustomerMenuRedis;
import com.epmet.redis.GovMenuRedis;
import com.epmet.service.*;
import org.apache.commons.lang3.StringUtils;
@ -58,7 +58,7 @@ public class GovMenuServiceImpl extends BaseServiceImpl<GovMenuDao, GovMenuEntit
@Autowired
private GovMenuRedis govMenuRedis;
@Autowired
private EpmetUserFeignClient epmetUserFeignClient;
private GovCustomerMenuRedis govCustomerMenuRedis;
@Autowired
private GovRoleMenuService govRoleMenuService;
@Autowired
@ -209,14 +209,14 @@ public class GovMenuServiceImpl extends BaseServiceImpl<GovMenuDao, GovMenuEntit
* @Date 15:51 2021-03-16
**/
private List<GovMenuDTO> getCustomerMenuList(String customerId, Integer type) {
List<GovMenuDTO> govMenuDTOS = govMenuRedis.getCustomerMenuList(customerId,type);
List<GovMenuDTO> govMenuDTOS = govCustomerMenuRedis.getCustomerMenuList(customerId,type);
if (!CollectionUtils.isEmpty(govMenuDTOS)){
return govMenuDTOS;
}
List<GovMenuEntity> menuList = baseDao.getCustomerMenuList(customerId, type, HttpContextUtils.getLanguage());
List<GovMenuDTO> dtoList = ConvertUtils.sourceToTarget(menuList, GovMenuDTO.class);
govMenuDTOS = TreeUtils.buildTree(dtoList);
govMenuRedis.setCustomerMenuList(customerId,type,govMenuDTOS);
govCustomerMenuRedis.setCustomerMenuList(customerId,type,govMenuDTOS);
return govMenuDTOS;
}

Loading…
Cancel
Save