Browse Source

Merge branch 'dev_footbar_cache' into dev_temp

dev_shibei_match
wxz 5 years ago
parent
commit
d8f32156b3
  1. 10
      epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/redis/RedisKeys.java
  2. 24
      epmet-module/oper-customize/oper-customize-server/src/main/java/com/epmet/controller/CustomerFootBarController.java
  3. 35
      epmet-module/oper-customize/oper-customize-server/src/main/java/com/epmet/service/impl/CustomerFootBarServiceImpl.java

10
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);
}
}

24
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<PageData<CustomerFootBarDTO>> page(@RequestParam Map<String, Object> params){
PageData<CustomerFootBarDTO> page = customerFootBarService.page(params);
@ -107,6 +118,13 @@ public class CustomerFootBarController {
String customerId = formDTO.getCustomerId();
String appType = formDTO.getAppType();
// 优先查询缓存
List<CustomerFootBarDTO> bars = (List<CustomerFootBarDTO>)redisUtils.get(RedisKeys.getCustomerFootbarKey(customerId, appType));
if (bars != null) {
new Result<List<CustomerFootBarDTO>>().ok(bars);
}
// 查询db
List<CustomerFootBarEntity> footbars = customerFootBarService.listCustomerFootBars(customerId, appType);
List<CustomerFootBarDTO> 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<List<CustomerFootBarDTO>>().ok(barDTOS);
}

35
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<CustomerFootBarD
@Autowired
private CustomerFootBarRedis customerFootBarRedis;
@Autowired
private RedisUtils redisUtils;
@Override
public PageData<CustomerFootBarDTO> page(Map<String, Object> params) {
IPage<CustomerFootBarEntity> page = baseDao.selectPage(
@ -160,6 +167,7 @@ public class CustomerFootBarServiceImpl extends BaseServiceImpl<CustomerFootBarD
}
}
@Transactional
@Override
public void updateFootBar(CustomerFootBarFormDTO form) {
validateBeforeUpdate(form);
@ -174,6 +182,9 @@ public class CustomerFootBarServiceImpl extends BaseServiceImpl<CustomerFootBarD
entity.setIconPath(form.getIconPath());
baseDao.updateById(entity);
// 删除缓存中的footbar。若缓存删除失败,则事务回滚,db中的不应该成功
redisUtils.delete(RedisKeys.getCustomerFootbarKey(entity.getCustomerId(), entity.getAppType()));
}
@Override
@ -197,6 +208,18 @@ public class CustomerFootBarServiceImpl extends BaseServiceImpl<CustomerFootBarD
for (CustomerFootBarFormDTO.OrderIndexDTO idx : orderList) {
baseDao.updateOrder(idx.getId(), idx.getOrderIndex());
}
if (!CollectionUtils.isEmpty(orderList)) {
String footbarId = orderList.get(0).getId();
CustomerFootBarEntity footBarEntity = baseDao.selectById(footbarId);
Optional.of(footBarEntity).ifPresent(c -> {
// 删除缓存中的footbar。若缓存删除失败,则事务回滚,db中的不应该成功
redisUtils.delete(RedisKeys.getCustomerFootbarKey(c.getCustomerId(), c.getAppType()));
});
}
}
@Override
@ -204,9 +227,17 @@ public class CustomerFootBarServiceImpl extends BaseServiceImpl<CustomerFootBarD
return baseDao.getByAppTypeAndBarKeyOfCustomer(customerId, appType, barKey);
}
@Transactional
@Override
public void updateDisplayStatus(String id, Boolean display) {
baseDao.updateDisplayStatus(id, display);
CustomerFootBarEntity footBarEntity = baseDao.selectById(id);
Optional.of(footBarEntity).ifPresent(c -> {
// 删除缓存中的footbar。若缓存删除失败,则事务回滚,db中的不应该成功
redisUtils.delete(RedisKeys.getCustomerFootbarKey(c.getCustomerId(), c.getAppType()));
});
}
@Transactional
@ -230,10 +261,14 @@ public class CustomerFootBarServiceImpl extends BaseServiceImpl<CustomerFootBarD
}
}
@Transactional
@Override
public void deleteFootBar(String id) {
CustomerFootBarEntity defaultFootbar = baseDao.selectById(id);
baseDao.physicsDeleteByAppTypeAndBarKey(defaultFootbar.getAppType(), defaultFootbar.getBarKey());
// 删除缓存中的footbar。若缓存删除失败,则事务回滚,db中的不应该成功
redisUtils.delete(RedisKeys.getCustomerFootbarKey(defaultFootbar.getCustomerId(), defaultFootbar.getAppType()));
}
/**

Loading…
Cancel
Save