|
|
@@ -1,8 +1,6 @@
|
|
|
package com.sqx.modules.goods.service.impl;
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
-import cn.hutool.core.convert.Convert;
|
|
|
-import cn.hutool.core.io.IoUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
@@ -11,8 +9,10 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.sqx.common.constant.RedisKey;
|
|
|
import com.sqx.common.exception.SqxException;
|
|
|
import com.sqx.common.utils.PageUtils;
|
|
|
+import com.sqx.common.utils.RedisUtils;
|
|
|
import com.sqx.common.utils.Result;
|
|
|
import com.sqx.modules.activity.service.ActivityShopService;
|
|
|
import com.sqx.modules.activity.vo.ShopActivityVO;
|
|
|
@@ -20,11 +20,9 @@ import com.sqx.modules.common.entity.CommonInfo;
|
|
|
import com.sqx.modules.common.service.CommonInfoService;
|
|
|
import com.sqx.modules.coupon.dao.TbCouponDao;
|
|
|
import com.sqx.modules.coupon.entity.TbCoupon;
|
|
|
-import com.sqx.modules.errand.service.TbIndentService;
|
|
|
import com.sqx.modules.goods.dao.GoodsDao;
|
|
|
import com.sqx.modules.goods.dao.GoodsShopDao;
|
|
|
import com.sqx.modules.goods.dao.GoodsShopRelevancyDao;
|
|
|
-import com.sqx.modules.goods.dao.GoodsSkuDao;
|
|
|
import com.sqx.modules.goods.dto.ShopQueryDTO;
|
|
|
import com.sqx.modules.goods.entity.Goods;
|
|
|
import com.sqx.modules.goods.entity.GoodsAttr;
|
|
|
@@ -38,8 +36,6 @@ import com.sqx.modules.goods.service.GoodsAttrValueService;
|
|
|
import com.sqx.modules.goods.service.GoodsService;
|
|
|
import com.sqx.modules.goods.service.GoodsSkuService;
|
|
|
import com.sqx.modules.goods.utils.SkuUtil;
|
|
|
-import com.sqx.modules.goods.vo.GoodsListVo;
|
|
|
-import com.sqx.modules.goods.vo.GoodsVo;
|
|
|
import com.sqx.modules.order.entity.Evaluate;
|
|
|
import com.sqx.modules.shop.dao.ShopMessageDao;
|
|
|
import com.sqx.modules.sys.dao.SysUserRoleDao;
|
|
|
@@ -49,20 +45,14 @@ import org.apache.commons.lang.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
-import org.springframework.web.bind.annotation.RequestParam;
|
|
|
-import sun.net.www.protocol.http.HttpURLConnection;
|
|
|
-
|
|
|
-import javax.imageio.ImageIO;
|
|
|
-import javax.swing.*;
|
|
|
-import java.awt.*;
|
|
|
-import java.awt.geom.AffineTransform;
|
|
|
-import java.awt.image.BufferedImage;
|
|
|
-import java.io.InputStream;
|
|
|
+
|
|
|
import java.math.BigDecimal;
|
|
|
-import java.net.URL;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
-import java.util.*;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@Service
|
|
|
@@ -71,8 +61,6 @@ public class GoodsServiceImpl extends ServiceImpl<GoodsDao, Goods> implements Go
|
|
|
@Autowired
|
|
|
private GoodsDao goodsDao;
|
|
|
@Autowired
|
|
|
- private GoodsSkuDao goodsSkuDao;
|
|
|
- @Autowired
|
|
|
private GoodsAttrService goodsAttrService;
|
|
|
@Autowired
|
|
|
private GoodsSkuService goodsSkuService;
|
|
|
@@ -87,14 +75,15 @@ public class GoodsServiceImpl extends ServiceImpl<GoodsDao, Goods> implements Go
|
|
|
@Autowired
|
|
|
private ShopMessageDao shopMessageDao;
|
|
|
@Autowired
|
|
|
- private TbIndentService tbIndentService;
|
|
|
- @Autowired
|
|
|
private GoodsShopRelevancyDao goodsShopRelevancyDao;
|
|
|
@Autowired
|
|
|
private TbCouponDao tbCouponDao;
|
|
|
@Autowired
|
|
|
private ActivityShopService activityShopService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private RedisUtils redisUtils;
|
|
|
+
|
|
|
@Transactional
|
|
|
@Override
|
|
|
public Result insertGoods(Goods goods) {
|
|
|
@@ -523,6 +512,16 @@ public class GoodsServiceImpl extends ServiceImpl<GoodsDao, Goods> implements Go
|
|
|
lng = 121.47;
|
|
|
lat = 31.23;
|
|
|
}
|
|
|
+
|
|
|
+ // 构建缓存键
|
|
|
+ String cacheKey = buildShopCacheKey(queryDTO, lat, lng);
|
|
|
+
|
|
|
+ // 尝试从缓存获取数据
|
|
|
+ PageUtils cachedResult = (PageUtils) redisUtils.get(cacheKey);
|
|
|
+ if (cachedResult != null) {
|
|
|
+ return Result.success().put("data", cachedResult);
|
|
|
+ }
|
|
|
+
|
|
|
Page<GoodsShop> pages = new Page<>(queryDTO.getPage(), queryDTO.getLimit());
|
|
|
|
|
|
String city = queryDTO.getCity();
|
|
|
@@ -570,10 +569,48 @@ public class GoodsServiceImpl extends ServiceImpl<GoodsDao, Goods> implements Go
|
|
|
}
|
|
|
|
|
|
PageUtils pageUtils = new PageUtils(goodsShopIPage);
|
|
|
+
|
|
|
+ // 存入缓存,过期时间为1分钟(60秒)
|
|
|
+ redisUtils.set(cacheKey, pageUtils, 60);
|
|
|
+
|
|
|
return Result.success().put("data", pageUtils);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * 构建店铺查询的缓存键
|
|
|
+ */
|
|
|
+ private String buildShopCacheKey(ShopQueryDTO queryDTO, Double lat, Double lng) {
|
|
|
+ // 对经纬度进行精度处理,避免微小差异导致不同的缓存键
|
|
|
+ String latStr = String.format("%.4f", lat);
|
|
|
+ String lngStr = String.format("%.4f", lng);
|
|
|
+
|
|
|
+ StringBuilder keyBuilder = new StringBuilder(RedisKey.INDEX_SHOP_LIST_CACHE_KEY);
|
|
|
+ keyBuilder.append("lat_").append(latStr)
|
|
|
+ .append("_lng_").append(lngStr)
|
|
|
+ .append("_page_").append(queryDTO.getPage())
|
|
|
+ .append("_limit_").append(queryDTO.getLimit());
|
|
|
+
|
|
|
+ // 添加筛选条件
|
|
|
+ if (queryDTO.getScreen() != null) {
|
|
|
+ keyBuilder.append("_screen_").append(queryDTO.getScreen());
|
|
|
+ }
|
|
|
+ if (queryDTO.getShopTypeId() != null) {
|
|
|
+ keyBuilder.append("_type_").append(queryDTO.getShopTypeId());
|
|
|
+ }
|
|
|
+ if (StrUtil.isNotBlank(queryDTO.getImpotr())) {
|
|
|
+ keyBuilder.append("_keyword_").append(queryDTO.getImpotr().hashCode()); // 使用哈希值避免key过长
|
|
|
+ }
|
|
|
+ if (queryDTO.getActivityId() != null) {
|
|
|
+ keyBuilder.append("_activity_").append(queryDTO.getActivityId());
|
|
|
+ }
|
|
|
+ if (StrUtil.isNotBlank(queryDTO.getCity())) {
|
|
|
+ keyBuilder.append("_city_").append(queryDTO.getCity());
|
|
|
+ }
|
|
|
+
|
|
|
+ return keyBuilder.toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* 根据经纬度查询城市
|
|
|
*
|
|
|
* @param lat lat
|