cms 内容实用缓存提高查询速度

dev
袁野 1 month ago
parent e8d7ae5536
commit a55ec4a33e
  1. 4
      bweb/src/main/java/com/bweb/controller/TestController.java
  2. 1
      bweb/src/main/java/com/bweb/controller/cms/CmsContentController.java
  3. 95
      cweb/src/main/java/com/cweb/controller/cms/CmsContentController.java
  4. 3
      schedule/src/main/java/com/hfkj/schedule/JdGoodsSchedule.java
  5. 18
      service/src/main/java/com/hfkj/service/cms/CmsContentService.java
  6. 25
      service/src/main/java/com/hfkj/service/cms/impl/CmsContentServiceImpl.java
  7. 6
      service/src/main/java/com/hfkj/service/order/impl/BsOrderRefundServiceImpl.java
  8. 1
      service/src/main/java/com/hfkj/sysenum/UserLoginPlatform.java

@ -348,7 +348,7 @@ public class TestController {
mapGoods.put("automatic", 1);
mapGoods.put("status", 1);
mapGoods.put("rand", 1);
map.put("type", 1);
mapGoods.put("type", 1);
mapGoods.put("salePriceS", 10);
mapGoods.put("salePriceE", 50);
mapGoods.put("limit", 25);
@ -384,7 +384,7 @@ public class TestController {
}
}
cmsContentService.cacheDelete("HOME_DATAWXAPPLETS");
return ResponseMsgUtil.success("成功");
} catch (Exception e) {

@ -83,6 +83,7 @@ public class CmsContentController {
cmsContentService.create(cmsContent);
}
cmsContentService.cacheDelete(body.getCode()+body.getPlatformCode());
return ResponseMsgUtil.success("操作成功");
} catch (Exception e) {

@ -1,9 +1,11 @@
package com.cweb.controller.cms;
import com.hfkj.common.utils.RedisUtil;
import com.hfkj.common.utils.ResponseMsgUtil;
import com.hfkj.entity.CmsContent;
import com.hfkj.entity.GoodsMsg;
import com.hfkj.entity.GoodsSpecs;
import com.hfkj.model.BsMerModel;
import com.hfkj.model.CmsContentModel;
import com.hfkj.model.ResponseData;
import com.hfkj.model.goods.GoodsModel;
@ -16,6 +18,7 @@ import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@ -37,35 +40,43 @@ public class CmsContentController {
Logger log = LoggerFactory.getLogger(CmsContentController.class);
// 缓存前缀KEY
public final static String CACHE_KEY = "CMS:";
@Autowired
private RedisUtil redisUtil;
@Resource
private CmsContentService cmsContentService;
@Resource
private GoodsMsgService goodsMsgService;
@Resource
private GoodsSpecsService goodsSpecsService;
@RequestMapping(value="/getCms",method = RequestMethod.GET)
@ResponseBody
@ApiOperation(value = "查询列表")
public ResponseData getCms(@RequestParam(value = "code" , required = false) String code,
@RequestParam(value = "platformCode" , required = false) String platformCode) {
try {
List<CmsContentModel> cmsContents = new ArrayList<>();
Object cacheObj = redisUtil.get(CACHE_KEY+code+platformCode);
if (cacheObj != null) {
cmsContents = (List<CmsContentModel>) cacheObj;
} else {
Map<String , Object> map = new HashMap<>();
map.put("code", code);
if (platformCode == null) {
platformCode = "WXAPPLETS";
}
map.put("status", 1);
map.put("platformCode", platformCode);
List<CmsContent> list = cmsContentService.getList(map);
Map<String , Object> map = new HashMap<>();
map.put("code", code);
if (platformCode == null) {
platformCode = "WXAPPLETS";
}
map.put("status", 1);
map.put("platformCode", platformCode);
List<CmsContent> list = cmsContentService.getList(map);
List<CmsContentModel> cmsContents = new ArrayList<>();
for (CmsContent cmsContent : list) {
List<JdGoodsModel> goodsModels = new ArrayList<>();
for (CmsContent cmsContent : list) {
List<JdGoodsModel> goodsModels = new ArrayList<>();
Map<String , Object> goodsMap = new HashMap<>();
@ -74,43 +85,47 @@ public class CmsContentController {
List<JdGoodsModel> goodsMsgs = new ArrayList<>();
if (cmsContent.getAutomatic() == 1) {
goodsMap.put("goodsType", cmsContent.getShowDataId());
if (cmsContent.getShowDataId() != null) {
cmsContent.setJumpUrl(cmsContent.getJumpUrl() + "&goodsType=" + cmsContent.getShowDataId());
if (cmsContent.getAutomatic() == 1) {
goodsMap.put("goodsType", cmsContent.getShowDataId());
if (cmsContent.getShowDataId() != null) {
cmsContent.setJumpUrl(cmsContent.getJumpUrl() + "&goodsType=" + cmsContent.getShowDataId());
}
} else {
cmsContent.setJumpUrl(cmsContent.getJumpUrl() + "&automaticCode=" + cmsContent.getId());
goodsMap.put("automaticCode" , cmsContent.getId());
}
} else {
cmsContent.setJumpUrl(cmsContent.getJumpUrl() + "&automaticCode=" + cmsContent.getId());
goodsMap.put("automaticCode" , cmsContent.getId());
}
if ( cmsContent.getShowType() != null && cmsContent.getShowType() == 1) {
if ( cmsContent.getShowType() != null && cmsContent.getShowType() == 1) {
goodsMap.put("limit" , 2);
goodsMsgs = goodsMsgService.getListCrest(goodsMap);
}
if (cmsContent.getShowType() != null && cmsContent.getShowType() == 2) {
goodsMap.put("limit" , 2);
goodsMsgs = goodsMsgService.getListCrest(goodsMap);
}
if (cmsContent.getShowType() != null && cmsContent.getShowType() == 2) {
goodsMap.put("limit" , 4);
goodsMap.put("saleNum" , 2);
goodsMap.put("limit" , 4);
goodsMap.put("saleNum" , 2);
goodsMsgs = goodsMsgService.getListCrest(goodsMap);
}
if (cmsContent.getShowType() != null && cmsContent.getShowType() == 3) {
goodsMsgs = goodsMsgService.getListCrest(goodsMap);
}
if (cmsContent.getShowType() != null && cmsContent.getShowType() == 3) {
goodsMap.put("limit" , 10);
goodsMap.put("type" , 1);
goodsMsgs = goodsMsgService.getListCrest(goodsMap);
}
goodsMap.put("limit" , 10);
goodsMap.put("type" , 1);
goodsMsgs = goodsMsgService.getListCrest(goodsMap);
}
goodsModels.addAll(goodsMsgs);
CmsContentModel cmsContentModel = new CmsContentModel();
CmsContentModel cmsContentModel = new CmsContentModel();
BeanUtils.copyProperties(cmsContent, cmsContentModel);
cmsContentModel.setGoodsMsgList(goodsModels);
cmsContents.add(cmsContentModel);
}
BeanUtils.copyProperties(cmsContent, cmsContentModel);
cmsContentModel.setGoodsMsgList(goodsModels);
cmsContents.add(cmsContentModel);
// 更新缓存
cmsContentService.cache(cmsContents , code+platformCode);
}
return ResponseMsgUtil.success(cmsContents);

@ -74,7 +74,7 @@ public class JdGoodsSchedule {
mapGoods.put("automatic", 1);
mapGoods.put("status", 1);
mapGoods.put("rand", 1);
map.put("type", 1);
mapGoods.put("type", 1);
mapGoods.put("salePriceS", 10);
mapGoods.put("salePriceE", 50);
mapGoods.put("limit", 25);
@ -110,6 +110,7 @@ public class JdGoodsSchedule {
}
}
cmsContentService.cacheDelete("HOME_DATAWXAPPLETS");
}
}

@ -2,6 +2,8 @@ package com.hfkj.service.cms;
import com.hfkj.entity.CmsContent;
import com.hfkj.entity.GoodsMsg;
import com.hfkj.model.CmsContentModel;
import com.hfkj.model.order.OrderModel;
import java.util.List;
import java.util.Map;
@ -68,4 +70,20 @@ public interface CmsContentService {
*/
List<CmsContent> getList(Map<String , Object> map);
/**
* 更新缓存
* @param cmsContentList
* @return
*/
List<CmsContentModel> cache(List<CmsContentModel> cmsContentList , String code);
/**
* 删除缓存
* @param code
* @return
*/
void cacheDelete(String code);
}

@ -1,20 +1,32 @@
package com.hfkj.service.cms.impl;
import com.hfkj.common.utils.RedisUtil;
import com.hfkj.dao.CmsContentMapper;
import com.hfkj.entity.CmsContent;
import com.hfkj.entity.CmsContentExample;
import com.hfkj.model.CmsContentModel;
import com.hfkj.service.cms.CmsContentService;
import org.apache.commons.collections4.MapUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.Collections;
import java.util.List;
import java.util.Map;
@Service("cmsContentService")
public class CmsContentServiceImpl implements CmsContentService {
// 缓存前缀KEY
public final static String CACHE_KEY = "CMS:";
// 订单缓存时间 24小时
public final static Integer CACHE_TIME = 60*60*24;
@Autowired
private RedisUtil redisUtil;
@Resource
private CmsContentMapper cmsContentMapper;
@ -69,4 +81,17 @@ public class CmsContentServiceImpl implements CmsContentService {
example.setOrderByClause("create_time desc");
return cmsContentMapper.selectByExample(example);
}
@Override
public List<CmsContentModel> cache(List<CmsContentModel> cmsContentList , String code) {
// 缓存
redisUtil.set(CACHE_KEY + code, cmsContentList, CACHE_TIME);
return cmsContentList;
}
@Override
public void cacheDelete(String code) {
// 缓存
redisUtil.del(CACHE_KEY + code);
}
}

@ -501,8 +501,14 @@ public class BsOrderRefundServiceImpl implements BsOrderRefundService {
private Boolean goodsVpdSource(OrderChildModel orderChild) {
// 查询卡券订单
BsOrderCoupon orderCoupon = orderCouponService.getDetailByChildOrderNo(orderChild.getChildOrderNo());
if (orderCoupon == null) {
return false;
}
// 查询卡券订单的卡密
List<BsOrderCouponNo> couponNoList = orderCouponNoService.getListByCouponOrderId(orderCoupon.getId());
if (couponNoList.isEmpty()) {
return false;
}
return couponNoList.get(0).getGoodsVpdSource().equals(GoodsVpdSourceEnum.type1.getCode()) || couponNoList.get(0).getGoodsVpdSource().equals(GoodsVpdSourceEnum.type3.getCode());
}

@ -14,6 +14,7 @@ public enum UserLoginPlatform {
VFAMILY("VFAMILY", "V家园"),
GZGOV("GZGOV", "省自机关"),
HIGH("HIGH", "嗨加油"),
ZXJZ("ZXJZ", "智行九州"),
;
private String code;

Loading…
Cancel
Save