From 016ded5bc0571842d27823f6037794ea6f4c02ab Mon Sep 17 00:00:00 2001 From: wxz Date: Mon, 21 Sep 2020 14:08:46 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0footbar=E7=BC=93=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../epmet/commons/tools/redis/RedisKeys.java | 10 ++++++ .../controller/CustomerFootBarController.java | 24 +++++++++++++ .../impl/CustomerFootBarServiceImpl.java | 35 +++++++++++++++++++ 3 files changed, 69 insertions(+) diff --git a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/redis/RedisKeys.java b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/redis/RedisKeys.java index ea8f100f6c..e88a2d92af 100644 --- a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/redis/RedisKeys.java +++ b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/redis/RedisKeys.java @@ -335,4 +335,14 @@ public class RedisKeys { public static String getCustomerStatsCalKeyPrefix() { return rootPrefix.concat("stats:calflag"); } + + /** + * footbar缓存key + * @param customerId + * @param appType + * @return + */ + public static String getCustomerFootbarKey(String customerId, String appType) { + return rootPrefix.concat("footbar").concat(":").concat(customerId).concat(":").concat(appType); + } } diff --git a/epmet-module/oper-customize/oper-customize-server/src/main/java/com/epmet/controller/CustomerFootBarController.java b/epmet-module/oper-customize/oper-customize-server/src/main/java/com/epmet/controller/CustomerFootBarController.java index 5b9c7a0da8..924dbc5b4b 100644 --- a/epmet-module/oper-customize/oper-customize-server/src/main/java/com/epmet/controller/CustomerFootBarController.java +++ b/epmet-module/oper-customize/oper-customize-server/src/main/java/com/epmet/controller/CustomerFootBarController.java @@ -18,6 +18,8 @@ package com.epmet.controller; import com.epmet.commons.tools.page.PageData; +import com.epmet.commons.tools.redis.RedisKeys; +import com.epmet.commons.tools.redis.RedisUtils; import com.epmet.commons.tools.utils.ExcelUtils; import com.epmet.commons.tools.utils.Result; import com.epmet.commons.tools.validator.AssertUtils; @@ -31,8 +33,12 @@ import com.epmet.dto.result.CustomerFootBarResultDTO; import com.epmet.entity.CustomerFootBarEntity; import com.epmet.excel.CustomerFootBarExcel; import com.epmet.service.CustomerFootBarService; +import com.epmet.service.impl.CustomerFunctionDetailServiceImpl; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.util.CollectionUtils; import org.springframework.web.bind.annotation.*; import javax.servlet.http.HttpServletResponse; @@ -51,9 +57,14 @@ import java.util.Map; @RequestMapping("customerfootbar") public class CustomerFootBarController { + private Logger logger = LogManager.getLogger(CustomerFootBarController.class); + @Autowired private CustomerFootBarService customerFootBarService; + @Autowired + private RedisUtils redisUtils; + @GetMapping("page") public Result> page(@RequestParam Map params){ PageData page = customerFootBarService.page(params); @@ -107,6 +118,13 @@ public class CustomerFootBarController { String customerId = formDTO.getCustomerId(); String appType = formDTO.getAppType(); + // 优先查询缓存 + List bars = (List)redisUtils.get(RedisKeys.getCustomerFootbarKey(customerId, appType)); + if (bars != null) { + new Result>().ok(bars); + } + + // 查询db List footbars = customerFootBarService.listCustomerFootBars(customerId, appType); List barDTOS = new LinkedList<>(); footbars.forEach(barEntity -> { @@ -117,6 +135,12 @@ public class CustomerFootBarController { barDTO.setDefaultBarName(defaultFootBarEntity.getBarName()); barDTOS.add(barDTO); }); + + try { + redisUtils.set(RedisKeys.getCustomerFootbarKey(customerId, appType), barDTOS); + } catch (Exception e) { + logger.error("将客户footbar放入缓存失败,customerId:{}, appType:{}", customerId, appType); + } return new Result>().ok(barDTOS); } diff --git a/epmet-module/oper-customize/oper-customize-server/src/main/java/com/epmet/service/impl/CustomerFootBarServiceImpl.java b/epmet-module/oper-customize/oper-customize-server/src/main/java/com/epmet/service/impl/CustomerFootBarServiceImpl.java index 594674b283..5205059bc0 100644 --- a/epmet-module/oper-customize/oper-customize-server/src/main/java/com/epmet/service/impl/CustomerFootBarServiceImpl.java +++ b/epmet-module/oper-customize/oper-customize-server/src/main/java/com/epmet/service/impl/CustomerFootBarServiceImpl.java @@ -23,6 +23,8 @@ import com.epmet.commons.mybatis.service.impl.BaseServiceImpl; import com.epmet.commons.tools.exception.EpmetErrorCode; import com.epmet.commons.tools.exception.RenException; import com.epmet.commons.tools.page.PageData; +import com.epmet.commons.tools.redis.RedisKeys; +import com.epmet.commons.tools.redis.RedisUtils; import com.epmet.commons.tools.utils.ConvertUtils; import com.epmet.commons.tools.constant.FieldConstant; import com.epmet.dao.CustomerFootBarDao; @@ -36,10 +38,12 @@ import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import org.springframework.util.CollectionUtils; import java.util.Arrays; import java.util.List; import java.util.Map; +import java.util.Optional; /** * APP底部菜单栏信息 @@ -53,6 +57,9 @@ public class CustomerFootBarServiceImpl extends BaseServiceImpl page(Map params) { IPage page = baseDao.selectPage( @@ -160,6 +167,7 @@ public class CustomerFootBarServiceImpl extends BaseServiceImpl { + // 删除缓存中的footbar。若缓存删除失败,则事务回滚,db中的不应该成功 + redisUtils.delete(RedisKeys.getCustomerFootbarKey(c.getCustomerId(), c.getAppType())); + }); + } + } @Override @@ -204,9 +227,17 @@ public class CustomerFootBarServiceImpl extends BaseServiceImpl { + // 删除缓存中的footbar。若缓存删除失败,则事务回滚,db中的不应该成功 + redisUtils.delete(RedisKeys.getCustomerFootbarKey(c.getCustomerId(), c.getAppType())); + }); } @Transactional @@ -230,10 +261,14 @@ public class CustomerFootBarServiceImpl extends BaseServiceImpl