Browse Source

Merge branch 'dev'

dev_shibei_match
wxz 5 years ago
parent
commit
46ce72aa9d
  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

@ -337,6 +337,16 @@ public class RedisKeys {
return rootPrefix.concat("stats:calflag"); 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);
}
/** /**
* 插入大屏指标数据分布式锁 key * 插入大屏指标数据分布式锁 key
*/ */

24
epmet-module/oper-customize/oper-customize-server/src/main/java/com/epmet/controller/CustomerFootBarController.java

@ -18,6 +18,8 @@
package com.epmet.controller; package com.epmet.controller;
import com.epmet.commons.tools.page.PageData; 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.ExcelUtils;
import com.epmet.commons.tools.utils.Result; import com.epmet.commons.tools.utils.Result;
import com.epmet.commons.tools.validator.AssertUtils; 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.entity.CustomerFootBarEntity;
import com.epmet.excel.CustomerFootBarExcel; import com.epmet.excel.CustomerFootBarExcel;
import com.epmet.service.CustomerFootBarService; 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.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
@ -51,9 +57,14 @@ import java.util.Map;
@RequestMapping("customerfootbar") @RequestMapping("customerfootbar")
public class CustomerFootBarController { public class CustomerFootBarController {
private Logger logger = LogManager.getLogger(CustomerFootBarController.class);
@Autowired @Autowired
private CustomerFootBarService customerFootBarService; private CustomerFootBarService customerFootBarService;
@Autowired
private RedisUtils redisUtils;
@GetMapping("page") @GetMapping("page")
public Result<PageData<CustomerFootBarDTO>> page(@RequestParam Map<String, Object> params){ public Result<PageData<CustomerFootBarDTO>> page(@RequestParam Map<String, Object> params){
PageData<CustomerFootBarDTO> page = customerFootBarService.page(params); PageData<CustomerFootBarDTO> page = customerFootBarService.page(params);
@ -107,6 +118,13 @@ public class CustomerFootBarController {
String customerId = formDTO.getCustomerId(); String customerId = formDTO.getCustomerId();
String appType = formDTO.getAppType(); 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<CustomerFootBarEntity> footbars = customerFootBarService.listCustomerFootBars(customerId, appType);
List<CustomerFootBarDTO> barDTOS = new LinkedList<>(); List<CustomerFootBarDTO> barDTOS = new LinkedList<>();
footbars.forEach(barEntity -> { footbars.forEach(barEntity -> {
@ -117,6 +135,12 @@ public class CustomerFootBarController {
barDTO.setDefaultBarName(defaultFootBarEntity.getBarName()); barDTO.setDefaultBarName(defaultFootBarEntity.getBarName());
barDTOS.add(barDTO); 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); 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.EpmetErrorCode;
import com.epmet.commons.tools.exception.RenException; import com.epmet.commons.tools.exception.RenException;
import com.epmet.commons.tools.page.PageData; 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.utils.ConvertUtils;
import com.epmet.commons.tools.constant.FieldConstant; import com.epmet.commons.tools.constant.FieldConstant;
import com.epmet.dao.CustomerFootBarDao; 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.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Optional;
/** /**
* APP底部菜单栏信息 * APP底部菜单栏信息
@ -53,6 +57,9 @@ public class CustomerFootBarServiceImpl extends BaseServiceImpl<CustomerFootBarD
@Autowired @Autowired
private CustomerFootBarRedis customerFootBarRedis; private CustomerFootBarRedis customerFootBarRedis;
@Autowired
private RedisUtils redisUtils;
@Override @Override
public PageData<CustomerFootBarDTO> page(Map<String, Object> params) { public PageData<CustomerFootBarDTO> page(Map<String, Object> params) {
IPage<CustomerFootBarEntity> page = baseDao.selectPage( IPage<CustomerFootBarEntity> page = baseDao.selectPage(
@ -160,6 +167,7 @@ public class CustomerFootBarServiceImpl extends BaseServiceImpl<CustomerFootBarD
} }
} }
@Transactional
@Override @Override
public void updateFootBar(CustomerFootBarFormDTO form) { public void updateFootBar(CustomerFootBarFormDTO form) {
validateBeforeUpdate(form); validateBeforeUpdate(form);
@ -174,6 +182,9 @@ public class CustomerFootBarServiceImpl extends BaseServiceImpl<CustomerFootBarD
entity.setIconPath(form.getIconPath()); entity.setIconPath(form.getIconPath());
baseDao.updateById(entity); baseDao.updateById(entity);
// 删除缓存中的footbar。若缓存删除失败,则事务回滚,db中的不应该成功
redisUtils.delete(RedisKeys.getCustomerFootbarKey(entity.getCustomerId(), entity.getAppType()));
} }
@Override @Override
@ -197,6 +208,18 @@ public class CustomerFootBarServiceImpl extends BaseServiceImpl<CustomerFootBarD
for (CustomerFootBarFormDTO.OrderIndexDTO idx : orderList) { for (CustomerFootBarFormDTO.OrderIndexDTO idx : orderList) {
baseDao.updateOrder(idx.getId(), idx.getOrderIndex()); 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 @Override
@ -204,9 +227,17 @@ public class CustomerFootBarServiceImpl extends BaseServiceImpl<CustomerFootBarD
return baseDao.getByAppTypeAndBarKeyOfCustomer(customerId, appType, barKey); return baseDao.getByAppTypeAndBarKeyOfCustomer(customerId, appType, barKey);
} }
@Transactional
@Override @Override
public void updateDisplayStatus(String id, Boolean display) { public void updateDisplayStatus(String id, Boolean display) {
baseDao.updateDisplayStatus(id, 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 @Transactional
@ -230,10 +261,14 @@ public class CustomerFootBarServiceImpl extends BaseServiceImpl<CustomerFootBarD
} }
} }
@Transactional
@Override @Override
public void deleteFootBar(String id) { public void deleteFootBar(String id) {
CustomerFootBarEntity defaultFootbar = baseDao.selectById(id); CustomerFootBarEntity defaultFootbar = baseDao.selectById(id);
baseDao.physicsDeleteByAppTypeAndBarKey(defaultFootbar.getAppType(), defaultFootbar.getBarKey()); baseDao.physicsDeleteByAppTypeAndBarKey(defaultFootbar.getAppType(), defaultFootbar.getBarKey());
// 删除缓存中的footbar。若缓存删除失败,则事务回滚,db中的不应该成功
redisUtils.delete(RedisKeys.getCustomerFootbarKey(defaultFootbar.getCustomerId(), defaultFootbar.getAppType()));
} }
/** /**

Loading…
Cancel
Save