From 58720493916a5b0c72edfcb135ff04d773a71191 Mon Sep 17 00:00:00 2001 From: hhf <614792109@qq.com> Date: Tue, 26 Oct 2021 18:01:45 +0800 Subject: [PATCH 01/18] =?UTF-8?q?=E5=8F=8C=E9=87=8D=E6=A0=A1=E9=AA=8C?= =?UTF-8?q?=E9=94=81bug=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cn/lili/common/utils/ThreadPoolUtil.java | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/framework/src/main/java/cn/lili/common/utils/ThreadPoolUtil.java b/framework/src/main/java/cn/lili/common/utils/ThreadPoolUtil.java index 17f87182..5a62281a 100644 --- a/framework/src/main/java/cn/lili/common/utils/ThreadPoolUtil.java +++ b/framework/src/main/java/cn/lili/common/utils/ThreadPoolUtil.java @@ -24,7 +24,10 @@ public class ThreadPoolUtil { */ private static final BlockingQueue BQUEUE = new ArrayBlockingQueue(100); private static final ThreadPoolExecutor POOL = new ThreadPoolExecutor(SIZE_CORE_POOL, SIZE_MAX_POOL, ALIVE_TIME, TimeUnit.MILLISECONDS, BQUEUE, new ThreadPoolExecutor.CallerRunsPolicy()); - public static ThreadPoolExecutor threadPool; + /** + * volatile禁止指令重排 + */ + public static volatile ThreadPoolExecutor threadPool; static { POOL.prestartAllCoreThreads(); @@ -49,22 +52,20 @@ public class ThreadPoolUtil { } /** - * dcs获取线程池 + * DCL获取线程池 * * @return 线程池对象 */ public static ThreadPoolExecutor getThreadPool() { if (threadPool != null) { return threadPool; - } else { - synchronized (ThreadPoolUtil.class) { - if (threadPool == null) { - threadPool = (ThreadPoolExecutor) Executors.newCachedThreadPool(); - return threadPool; - } - return threadPool; + } + synchronized (ThreadPoolUtil.class) { + if (threadPool == null) { + threadPool = (ThreadPoolExecutor) Executors.newCachedThreadPool(); } } + return threadPool; } public static ThreadPoolExecutor getPool() { From dd1bf2eec0447d74d8dfc717a2284c41166a72e8 Mon Sep 17 00:00:00 2001 From: Chopper Date: Wed, 27 Oct 2021 12:16:40 +0800 Subject: [PATCH 02/18] =?UTF-8?q?=E6=8B=BC=E5=9B=A2=E6=B4=BB=E5=8A=A8?= =?UTF-8?q?=E8=A2=AB=E5=BC=82=E5=B8=B8=E6=93=8D=E4=BD=9C=E5=90=8E=EF=BC=8C?= =?UTF-8?q?=E5=95=86=E5=93=81=E7=B4=A2=E5=BC=95=E6=B2=A1=E6=9C=89=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E9=97=AE=E9=A2=98=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/cn/lili/common/enums/ResultCode.java | 6 ++---- .../cn/lili/modules/goods/service/GoodsSkuService.java | 7 +++++++ .../modules/goods/serviceimpl/GoodsSkuServiceImpl.java | 2 +- .../lili/modules/order/cart/service/CartServiceImpl.java | 9 +++++++++ 4 files changed, 19 insertions(+), 5 deletions(-) diff --git a/framework/src/main/java/cn/lili/common/enums/ResultCode.java b/framework/src/main/java/cn/lili/common/enums/ResultCode.java index 90b3703b..655e4cb9 100644 --- a/framework/src/main/java/cn/lili/common/enums/ResultCode.java +++ b/framework/src/main/java/cn/lili/common/enums/ResultCode.java @@ -154,7 +154,7 @@ public enum ResultCode { * 购物车 */ CART_ERROR(30001, "读取结算页的购物车异常"), - CART_PINTUAN_NOT_EXIST_ERROR(30002, "拼团活动不存在错误"), + CART_PINTUAN_NOT_EXIST_ERROR(30002, "拼团活动已关闭,请稍后重试"), CART_PINTUAN_LIMIT_ERROR(30003, "购买数量超过拼团活动限制数量"), SHIPPING_NOT_APPLY(30005, "购物商品不支持当前收货地址配送"), @@ -449,9 +449,7 @@ public enum ResultCode { CUSTOM_WORDS_SECRET_KEY_ERROR(90002, "秘钥验证失败!"), CONNECT_NOT_EXIST(90000, "登录方式不存在!"), ELASTICSEARCH_INDEX_INIT_ERROR(90003, "索引初始化失败!"), - PURCHASE_ORDER_DEADLINE_ERROR(90004,"供求单,已超过报名截止时间") - - ; + PURCHASE_ORDER_DEADLINE_ERROR(90004, "供求单,已超过报名截止时间"); private final Integer code; private final String message; diff --git a/framework/src/main/java/cn/lili/modules/goods/service/GoodsSkuService.java b/framework/src/main/java/cn/lili/modules/goods/service/GoodsSkuService.java index a79e547c..022e7917 100644 --- a/framework/src/main/java/cn/lili/modules/goods/service/GoodsSkuService.java +++ b/framework/src/main/java/cn/lili/modules/goods/service/GoodsSkuService.java @@ -143,6 +143,13 @@ public interface GoodsSkuService extends IService { */ void updateGoodsSkuStatus(Goods goods); + /** + * 发送生成ES商品索引 + * + * @param goods 商品信息 + */ + void generateEs(Goods goods); + /** * 更新SKU库存 * diff --git a/framework/src/main/java/cn/lili/modules/goods/serviceimpl/GoodsSkuServiceImpl.java b/framework/src/main/java/cn/lili/modules/goods/serviceimpl/GoodsSkuServiceImpl.java index 72fd03a7..ad617615 100644 --- a/framework/src/main/java/cn/lili/modules/goods/serviceimpl/GoodsSkuServiceImpl.java +++ b/framework/src/main/java/cn/lili/modules/goods/serviceimpl/GoodsSkuServiceImpl.java @@ -497,7 +497,7 @@ public class GoodsSkuServiceImpl extends ServiceImpl i * * @param goods 商品信息 */ - private void generateEs(Goods goods) { + public void generateEs(Goods goods) { String destination = rocketmqCustomProperties.getGoodsTopic() + ":" + GoodsTagsEnum.GENERATOR_GOODS_INDEX.name(); //发送mq消息 rocketMQTemplate.asyncSend(destination, JSONUtil.toJsonStr(goods), RocketmqSendCallbackBuilder.commonCallback()); diff --git a/framework/src/main/java/cn/lili/modules/order/cart/service/CartServiceImpl.java b/framework/src/main/java/cn/lili/modules/order/cart/service/CartServiceImpl.java index 35960d7a..52ef8c00 100644 --- a/framework/src/main/java/cn/lili/modules/order/cart/service/CartServiceImpl.java +++ b/framework/src/main/java/cn/lili/modules/order/cart/service/CartServiceImpl.java @@ -11,6 +11,7 @@ import cn.lili.common.utils.CurrencyUtil; import cn.lili.modules.goods.entity.dos.GoodsSku; import cn.lili.modules.goods.entity.enums.GoodsAuthEnum; import cn.lili.modules.goods.entity.enums.GoodsStatusEnum; +import cn.lili.modules.goods.service.GoodsService; import cn.lili.modules.goods.service.GoodsSkuService; import cn.lili.modules.member.entity.dos.MemberAddress; import cn.lili.modules.order.cart.entity.dto.MemberCouponDTO; @@ -36,6 +37,7 @@ import cn.lili.modules.promotion.entity.vos.PointsGoodsVO; import cn.lili.modules.promotion.entity.vos.kanjia.KanjiaActivitySearchParams; import cn.lili.modules.promotion.service.*; import cn.lili.modules.search.entity.dos.EsGoodsIndex; +import cn.lili.modules.search.service.EsGoodsIndexService; import cn.lili.modules.search.service.EsGoodsSearchService; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import lombok.extern.slf4j.Slf4j; @@ -92,6 +94,11 @@ public class CartServiceImpl implements CartService { */ @Autowired private EsGoodsSearchService esGoodsSearchService; + /** + * ES商品 + */ + @Autowired + private GoodsService goodsService; /** * 拼团 */ @@ -689,6 +696,8 @@ public class CartServiceImpl implements CartService { cartSkuVO.setUtilPrice(promotionGoods.getPrice()); cartSkuVO.setPurchasePrice(promotionGoods.getPrice()); } else { + //如果拼团活动被异常处理,则在这里安排mq重新写入商品索引 + goodsSkuService.generateEs(goodsService.getById(cartSkuVO.getGoodsSku().getGoodsId())); throw new ServiceException(ResultCode.CART_PINTUAN_NOT_EXIST_ERROR); } //检测拼团限购数量 From bc8885c5b8389df7dc5e13d4fce5a0e2e46b9110 Mon Sep 17 00:00:00 2001 From: Chopper Date: Thu, 28 Oct 2021 11:43:22 +0800 Subject: [PATCH 03/18] =?UTF-8?q?=E4=B8=80=E4=B8=AA=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E6=8F=8F=E8=BF=B0=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/cn/lili/modules/goods/entity/dos/Goods.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/framework/src/main/java/cn/lili/modules/goods/entity/dos/Goods.java b/framework/src/main/java/cn/lili/modules/goods/entity/dos/Goods.java index e890b200..b4939407 100644 --- a/framework/src/main/java/cn/lili/modules/goods/entity/dos/Goods.java +++ b/framework/src/main/java/cn/lili/modules/goods/entity/dos/Goods.java @@ -41,7 +41,7 @@ public class Goods extends BaseEntity { @ApiModelProperty(value = "商品名称") @NotEmpty(message = "商品名称不能为空") - @Length(max = 100, message = "商品名称提案仓,不能超过100个字符") + @Length(max = 100, message = "商品名称太长,不能超过100个字符") private String goodsName; @ApiModelProperty(value = "商品价格", required = true) From 036ad56093a37c4b5f608524f50d950b65d5b892 Mon Sep 17 00:00:00 2001 From: Chopper Date: Thu, 28 Oct 2021 14:40:38 +0800 Subject: [PATCH 04/18] =?UTF-8?q?=E5=95=86=E5=93=81=E7=B4=A2=E5=BC=95?= =?UTF-8?q?=E7=94=9F=E6=88=90=E4=BB=A3=E7=A0=81=E8=BF=81=E7=A7=BB=EF=BC=8C?= =?UTF-8?q?=E7=BB=93=E6=9E=84=E7=A8=8D=E5=BE=AE=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/cn/lili/common/enums/ResultCode.java | 3 +- .../search/service/EsGoodsIndexService.java | 10 ++ .../serviceimpl/EsGoodsIndexServiceImpl.java | 116 +++++++++++++++++- .../other/ElasticsearchController.java | 89 +------------- 4 files changed, 128 insertions(+), 90 deletions(-) diff --git a/framework/src/main/java/cn/lili/common/enums/ResultCode.java b/framework/src/main/java/cn/lili/common/enums/ResultCode.java index 655e4cb9..87e9f0ae 100644 --- a/framework/src/main/java/cn/lili/common/enums/ResultCode.java +++ b/framework/src/main/java/cn/lili/common/enums/ResultCode.java @@ -449,7 +449,8 @@ public enum ResultCode { CUSTOM_WORDS_SECRET_KEY_ERROR(90002, "秘钥验证失败!"), CONNECT_NOT_EXIST(90000, "登录方式不存在!"), ELASTICSEARCH_INDEX_INIT_ERROR(90003, "索引初始化失败!"), - PURCHASE_ORDER_DEADLINE_ERROR(90004, "供求单,已超过报名截止时间"); + PURCHASE_ORDER_DEADLINE_ERROR(90004, "供求单,已超过报名截止时间"), + INDEX_BUILDING(90005, "索引正在生成"); private final Integer code; private final String message; diff --git a/framework/src/main/java/cn/lili/modules/search/service/EsGoodsIndexService.java b/framework/src/main/java/cn/lili/modules/search/service/EsGoodsIndexService.java index a33c8928..f7edeb7e 100644 --- a/framework/src/main/java/cn/lili/modules/search/service/EsGoodsIndexService.java +++ b/framework/src/main/java/cn/lili/modules/search/service/EsGoodsIndexService.java @@ -18,6 +18,16 @@ import java.util.Map; **/ public interface EsGoodsIndexService { + /** + * 全局索引初始化 + */ + void init(); + + /** + * 获取es生成索引进度 + * @return + */ + Map getProgress(); /** * 添加商品索引 * diff --git a/framework/src/main/java/cn/lili/modules/search/serviceimpl/EsGoodsIndexServiceImpl.java b/framework/src/main/java/cn/lili/modules/search/serviceimpl/EsGoodsIndexServiceImpl.java index 65b3254a..ed5a1ce9 100644 --- a/framework/src/main/java/cn/lili/modules/search/serviceimpl/EsGoodsIndexServiceImpl.java +++ b/framework/src/main/java/cn/lili/modules/search/serviceimpl/EsGoodsIndexServiceImpl.java @@ -2,6 +2,8 @@ package cn.lili.modules.search.serviceimpl; import cn.hutool.core.date.DateUtil; import cn.hutool.core.text.CharSequenceUtil; +import cn.hutool.core.thread.ThreadUtil; +import cn.hutool.core.util.ArrayUtil; import cn.hutool.core.util.ReflectUtil; import cn.hutool.extra.pinyin.PinyinUtil; import cn.hutool.json.JSONObject; @@ -9,14 +11,18 @@ import cn.hutool.json.JSONUtil; import cn.lili.cache.Cache; import cn.lili.cache.CachePrefix; import cn.lili.common.enums.PromotionTypeEnum; +import cn.lili.common.enums.ResultCode; +import cn.lili.common.enums.ResultUtil; +import cn.lili.common.exception.ServiceException; import cn.lili.elasticsearch.BaseElasticsearchService; import cn.lili.elasticsearch.EsSuffix; import cn.lili.elasticsearch.config.ElasticsearchProperties; -import cn.lili.modules.goods.entity.dos.GoodsSku; -import cn.lili.modules.goods.entity.dos.GoodsWords; +import cn.lili.modules.goods.entity.dos.*; import cn.lili.modules.goods.entity.dto.GoodsParamsDTO; +import cn.lili.modules.goods.entity.enums.GoodsAuthEnum; +import cn.lili.modules.goods.entity.enums.GoodsStatusEnum; import cn.lili.modules.goods.entity.enums.GoodsWordsTypeEnum; -import cn.lili.modules.goods.service.GoodsWordsService; +import cn.lili.modules.goods.service.*; import cn.lili.modules.promotion.entity.dos.PromotionGoods; import cn.lili.modules.promotion.entity.dto.BasePromotion; import cn.lili.modules.promotion.entity.enums.PromotionStatusEnum; @@ -27,6 +33,8 @@ import cn.lili.modules.search.entity.dto.EsGoodsSearchDTO; import cn.lili.modules.search.repository.EsGoodsIndexRepository; import cn.lili.modules.search.service.EsGoodsIndexService; import cn.lili.modules.search.service.EsGoodsSearchService; +import cn.lili.modules.store.entity.dos.StoreGoodsLabel; +import cn.lili.modules.store.service.StoreGoodsLabelService; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import lombok.extern.slf4j.Slf4j; import org.assertj.core.util.IterableUtil; @@ -78,9 +86,111 @@ public class EsGoodsIndexServiceImpl extends BaseElasticsearchService implements private GoodsWordsService goodsWordsService; @Autowired private PromotionService promotionService; + + + @Autowired + private GoodsSkuService goodsSkuService; + @Autowired + private GoodsService goodsService; + @Autowired + private BrandService brandService; + + @Autowired + private CategoryService categoryService; + + @Autowired + private StoreGoodsLabelService storeGoodsLabelService; @Autowired private Cache cache; + @Override + public void init() { + //获取索引任务标识 + Boolean flag = (Boolean) cache.get(CachePrefix.INIT_INDEX_FLAG.getPrefix()); + //为空则默认写入没有任务 + if (flag == null) { + cache.put(CachePrefix.INIT_INDEX_FLAG.getPrefix(), false); + } + //有正在初始化的任务,则提示异常 + if (Boolean.TRUE.equals(flag)) { + throw new ServiceException(ResultCode.INDEX_BUILDING); + } + + //初始化标识 + cache.put(CachePrefix.INIT_INDEX_PROCESS.getPrefix(), null); + cache.put(CachePrefix.INIT_INDEX_FLAG.getPrefix(), true); + + ThreadUtil.execAsync(() -> { + try { + //查询商品信息 + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); + queryWrapper.eq(GoodsSku::getIsAuth, GoodsAuthEnum.PASS.name()); + queryWrapper.eq(GoodsSku::getMarketEnable, GoodsStatusEnum.UPPER.name()); + + List list = goodsSkuService.list(queryWrapper); + List esGoodsIndices = new ArrayList<>(); + //库存锁是在redis做的,所以生成索引,同时更新一下redis中的库存数量 + for (GoodsSku goodsSku : list) { + Goods goods = goodsService.getById(goodsSku.getGoodsId()); + //如果出现极端情况,有sku,没有与之匹配的商品,则跳过 + if (goods == null) { + continue; + } + EsGoodsIndex index = new EsGoodsIndex(goodsSku); + + //商品参数索引 + if (goods.getParams() != null && !goods.getParams().isEmpty()) { + List goodsParamDTOS = JSONUtil.toList(goods.getParams(), GoodsParamsDTO.class); + index = new EsGoodsIndex(goodsSku, goodsParamDTOS); + } + //商品分类索引 + if (goods.getCategoryPath() != null) { + List categories = categoryService.listByIdsOrderByLevel(Arrays.asList(goods.getCategoryPath().split(","))); + if (!categories.isEmpty()) { + index.setCategoryNamePath(ArrayUtil.join(categories.stream().map(Category::getName).toArray(), ",")); + } + } + //商品品牌索引 + Brand brand = brandService.getById(goods.getBrandId()); + if (brand != null) { + index.setBrandName(brand.getName()); + index.setBrandUrl(brand.getLogo()); + } + //店铺分类索引 + if (goods.getStoreCategoryPath() != null && CharSequenceUtil.isNotEmpty(goods.getStoreCategoryPath())) { + List storeGoodsLabels = storeGoodsLabelService.listByStoreIds(Arrays.asList(goods.getStoreCategoryPath().split(","))); + if (!storeGoodsLabels.isEmpty()) { + index.setStoreCategoryNamePath(ArrayUtil.join(storeGoodsLabels.stream().map(StoreGoodsLabel::getLabelName).toArray(), ",")); + } + } + //促销索引 + Map goodsCurrentPromotionMap = promotionService.getGoodsCurrentPromotionMap(index); + index.setPromotionMap(goodsCurrentPromotionMap); + esGoodsIndices.add(index); + cache.put(GoodsSkuService.getStockCacheKey(goodsSku.getId()), goodsSku.getQuantity().toString()); + } + //初始化商品索引 + this.initIndex(esGoodsIndices); + } catch (Exception e) { + log.error("商品索引生成异常:", e); + //如果出现异常,则将进行中的任务标识取消掉,打印日志 + cache.put(CachePrefix.INIT_INDEX_PROCESS.getPrefix(), null); + cache.put(CachePrefix.INIT_INDEX_FLAG.getPrefix(), false); + } + }); + } + + @Override + public Map getProgress() { + Map map = (Map) cache.get(CachePrefix.INIT_INDEX_PROCESS.getPrefix()); + if (map == null) { + return null; + } + Boolean flag = (Boolean) cache.get(CachePrefix.INIT_INDEX_FLAG.getPrefix()); + map.put("flag", Boolean.TRUE.equals(flag) ? 1 : 0); + return map; + } + @Override public void addIndex(EsGoodsIndex goods) { try { diff --git a/manager-api/src/main/java/cn/lili/controller/other/ElasticsearchController.java b/manager-api/src/main/java/cn/lili/controller/other/ElasticsearchController.java index 4770c933..45d45638 100644 --- a/manager-api/src/main/java/cn/lili/controller/other/ElasticsearchController.java +++ b/manager-api/src/main/java/cn/lili/controller/other/ElasticsearchController.java @@ -6,6 +6,7 @@ import cn.hutool.core.util.ArrayUtil; import cn.hutool.json.JSONUtil; import cn.lili.cache.Cache; import cn.lili.cache.CachePrefix; +import cn.lili.common.enums.ResultCode; import cn.lili.common.enums.ResultUtil; import cn.lili.common.vo.ResultMessage; import cn.lili.modules.goods.entity.dos.Brand; @@ -52,101 +53,17 @@ public class ElasticsearchController { @Autowired private EsGoodsIndexService esGoodsIndexService; - @Autowired - private GoodsSkuService goodsSkuService; - - @Autowired - private GoodsService goodsService; - - @Autowired - private StringRedisTemplate stringRedisTemplate; - - @Autowired - private PromotionService promotionService; - - @Autowired - private CategoryService categoryService; - - @Autowired - private BrandService brandService; - - @Autowired - private StoreGoodsLabelService storeGoodsLabelService; - @Autowired private Cache cache; @GetMapping public ResultMessage init() { - - Boolean flag = (Boolean) cache.get(CachePrefix.INIT_INDEX_FLAG.getPrefix()); - if (flag == null) { - cache.put(CachePrefix.INIT_INDEX_FLAG.getPrefix(), false); - } - if (Boolean.TRUE.equals(flag)) { - return ResultUtil.error(100000, "当前有任务在执行"); - } - - cache.put(CachePrefix.INIT_INDEX_PROCESS.getPrefix(), null); - cache.put(CachePrefix.INIT_INDEX_FLAG.getPrefix(), true); - ThreadUtil.execAsync(() -> { - try { - //查询商品信息 - LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); - queryWrapper.eq(GoodsSku::getIsAuth, GoodsAuthEnum.PASS.name()); - queryWrapper.eq(GoodsSku::getMarketEnable, GoodsStatusEnum.UPPER.name()); - - List list = goodsSkuService.list(queryWrapper); - List esGoodsIndices = new ArrayList<>(); - //库存锁是在redis做的,所以生成索引,同时更新一下redis中的库存数量 - for (GoodsSku goodsSku : list) { - Goods goods = goodsService.getById(goodsSku.getGoodsId()); - EsGoodsIndex index = new EsGoodsIndex(goodsSku); - if (goods.getParams() != null && !goods.getParams().isEmpty()) { - List goodsParamDTOS = JSONUtil.toList(goods.getParams(), GoodsParamsDTO.class); - index = new EsGoodsIndex(goodsSku, goodsParamDTOS); - } - if (goods.getCategoryPath() != null) { - List categories = categoryService.listByIdsOrderByLevel(Arrays.asList(goods.getCategoryPath().split(","))); - if (!categories.isEmpty()) { - index.setCategoryNamePath(ArrayUtil.join(categories.stream().map(Category::getName).toArray(), ",")); - } - } - Brand brand = brandService.getById(goods.getBrandId()); - if (brand != null) { - index.setBrandName(brand.getName()); - index.setBrandUrl(brand.getLogo()); - } - if (goods.getStoreCategoryPath() != null && CharSequenceUtil.isNotEmpty(goods.getStoreCategoryPath())) { - List storeGoodsLabels = storeGoodsLabelService.listByStoreIds(Arrays.asList(goods.getStoreCategoryPath().split(","))); - if (!storeGoodsLabels.isEmpty()) { - index.setStoreCategoryNamePath(ArrayUtil.join(storeGoodsLabels.stream().map(StoreGoodsLabel::getLabelName).toArray(), ",")); - } - } - Map goodsCurrentPromotionMap = promotionService.getGoodsCurrentPromotionMap(index); - index.setPromotionMap(goodsCurrentPromotionMap); - esGoodsIndices.add(index); - stringRedisTemplate.opsForValue().set(GoodsSkuService.getStockCacheKey(goodsSku.getId()), goodsSku.getQuantity().toString()); - } - //初始化商品索引 - esGoodsIndexService.initIndex(esGoodsIndices); - } catch (Exception e) { - cache.put(CachePrefix.INIT_INDEX_PROCESS.getPrefix(), null); - cache.put(CachePrefix.INIT_INDEX_FLAG.getPrefix(), false); - } - }); + esGoodsIndexService.init(); return ResultUtil.success(); } @GetMapping("/progress") public ResultMessage> getProgress() { - try { - Map map = (Map) cache.get(CachePrefix.INIT_INDEX_PROCESS.getPrefix()); - Boolean flag = (Boolean) cache.get(CachePrefix.INIT_INDEX_FLAG.getPrefix()); - map.put("flag", Boolean.TRUE.equals(flag) ? 1 : 0); - return ResultUtil.data(map); - } catch (Exception e) { - return ResultUtil.data(null); - } + return ResultUtil.data(esGoodsIndexService.getProgress()); } } From 57594f3f073f13fbb46b66b99ae35b65968660ee Mon Sep 17 00:00:00 2001 From: Chopper Date: Thu, 28 Oct 2021 17:09:51 +0800 Subject: [PATCH 05/18] =?UTF-8?q?=E6=9C=89=E4=B8=80=E4=B8=AA=E7=A9=BA?= =?UTF-8?q?=E5=93=81=E7=89=8C=E9=97=AE=E9=A2=98=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../search/serviceimpl/EsGoodsSearchServiceImpl.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/framework/src/main/java/cn/lili/modules/search/serviceimpl/EsGoodsSearchServiceImpl.java b/framework/src/main/java/cn/lili/modules/search/serviceimpl/EsGoodsSearchServiceImpl.java index 73792f46..efd86c71 100644 --- a/framework/src/main/java/cn/lili/modules/search/serviceimpl/EsGoodsSearchServiceImpl.java +++ b/framework/src/main/java/cn/lili/modules/search/serviceimpl/EsGoodsSearchServiceImpl.java @@ -159,7 +159,7 @@ public class EsGoodsSearchServiceImpl implements EsGoodsSearchService { String categoryNamePath = categoryPath; - if (!categoryBuckets.isEmpty()) { + if (!categoryNameBuckets.isEmpty()) { categoryNamePath = categoryNameBuckets.get(0).getKey().toString(); } String[] split = ArrayUtil.distinct(categoryPath.split(",")); @@ -187,6 +187,10 @@ public class EsGoodsSearchServiceImpl implements EsGoodsSearchService { if (brandBuckets != null && !brandBuckets.isEmpty()) { for (int i = 0; i < brandBuckets.size(); i++) { String brandId = brandBuckets.get(i).getKey().toString(); + //当商品品牌id为0时,代表商品没有选择品牌,所以过滤掉品牌选择器 + if (brandId.equals("0")) { + continue; + } if (CharSequenceUtil.isNotEmpty(goodsSearch.getBrandId())) { List brandList = Arrays.asList(goodsSearch.getBrandId().split("@")); if (brandList.contains(brandId)) { From adf353790b3ae12607439ac80135df7ee3e66e0a Mon Sep 17 00:00:00 2001 From: Chopper Date: Thu, 28 Oct 2021 17:28:36 +0800 Subject: [PATCH 06/18] =?UTF-8?q?=E8=B0=83=E6=95=B4=E4=B8=8B=E9=94=99?= =?UTF-8?q?=E8=AF=AF=E6=8F=90=E7=A4=BA=E8=AF=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- framework/src/main/java/cn/lili/common/enums/ResultCode.java | 2 +- .../lili/modules/promotion/serviceimpl/SeckillServiceImpl.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/framework/src/main/java/cn/lili/common/enums/ResultCode.java b/framework/src/main/java/cn/lili/common/enums/ResultCode.java index 87e9f0ae..56c2ac34 100644 --- a/framework/src/main/java/cn/lili/common/enums/ResultCode.java +++ b/framework/src/main/java/cn/lili/common/enums/ResultCode.java @@ -240,7 +240,7 @@ public enum ResultCode { * 活动 */ PROMOTION_GOODS_NOT_EXIT(40000, "当前促销商品不存在!"), - PROMOTION_SAME_ACTIVE_EXIST(40001, "当前时间内已存在同类活动"), + PROMOTION_SAME_ACTIVE_EXIST(40001, "活动时间内已存在同类活动,请选择关闭、删除当前时段的活动"), PROMOTION_START_TIME_ERROR(40002, "活动起始时间不能小于当前时间"), PROMOTION_END_TIME_ERROR(40003, "活动结束时间不能小于当前时间"), PROMOTION_TIME_ERROR(40004, "活动起始时间必须大于结束时间"), diff --git a/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/SeckillServiceImpl.java b/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/SeckillServiceImpl.java index c98962ae..c059874a 100644 --- a/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/SeckillServiceImpl.java +++ b/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/SeckillServiceImpl.java @@ -339,7 +339,7 @@ public class SeckillServiceImpl extends ServiceImpl impl int sameNum = this.count(queryWrapper); //当前时间段是否存在同类活动 if (sameNum > 0) { - throw new ServiceException("当前时间内已存在同类活动:" + seckill.getStartTime()); + throw new ServiceException(ResultCode.PROMOTION_SAME_ACTIVE_EXIST); } } } \ No newline at end of file From a535b5c54c6fb97285ffaa9b07d612c645cc5cbc Mon Sep 17 00:00:00 2001 From: Chopper Date: Thu, 28 Oct 2021 17:28:59 +0800 Subject: [PATCH 07/18] =?UTF-8?q?=E9=85=8D=E7=BD=AE=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E4=B8=AD=E7=9A=84sql=E6=98=BE=E7=A4=BA=E9=BB=98=E8=AE=A4?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E5=BC=80=E5=90=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- buyer-api/src/main/resources/application.yml | 2 +- common-api/src/main/resources/application.yml | 2 +- consumer/src/main/resources/application.yml | 2 +- manager-api/src/main/resources/application.yml | 2 +- seller-api/src/main/resources/application.yml | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/buyer-api/src/main/resources/application.yml b/buyer-api/src/main/resources/application.yml index b33e38c7..9ed3cc2a 100644 --- a/buyer-api/src/main/resources/application.yml +++ b/buyer-api/src/main/resources/application.yml @@ -121,7 +121,7 @@ spring: props: #是否打印逻辑SQL语句和实际SQL语句,建议调试时打印,在生产环境关闭 sql: - show: false + show: true # 忽略TOKEN 鉴权 的url ignored: diff --git a/common-api/src/main/resources/application.yml b/common-api/src/main/resources/application.yml index 1157b9bf..fb53aa1c 100644 --- a/common-api/src/main/resources/application.yml +++ b/common-api/src/main/resources/application.yml @@ -118,7 +118,7 @@ spring: props: #是否打印逻辑SQL语句和实际SQL语句,建议调试时打印,在生产环境关闭 sql: - show: false + show: true # 忽略鉴权url ignored: diff --git a/consumer/src/main/resources/application.yml b/consumer/src/main/resources/application.yml index 1ec5a786..65dffa3c 100644 --- a/consumer/src/main/resources/application.yml +++ b/consumer/src/main/resources/application.yml @@ -121,7 +121,7 @@ spring: props: #是否打印逻辑SQL语句和实际SQL语句,建议调试时打印,在生产环境关闭 sql: - show: false + show: true # 忽略鉴权url ignored: diff --git a/manager-api/src/main/resources/application.yml b/manager-api/src/main/resources/application.yml index 8db62326..08e14ecd 100644 --- a/manager-api/src/main/resources/application.yml +++ b/manager-api/src/main/resources/application.yml @@ -118,7 +118,7 @@ spring: props: #是否打印逻辑SQL语句和实际SQL语句,建议调试时打印,在生产环境关闭 sql: - show: false + show: true # 忽略鉴权url ignored: diff --git a/seller-api/src/main/resources/application.yml b/seller-api/src/main/resources/application.yml index 2eb3eebe..95886ca4 100644 --- a/seller-api/src/main/resources/application.yml +++ b/seller-api/src/main/resources/application.yml @@ -118,7 +118,7 @@ spring: props: #是否打印逻辑SQL语句和实际SQL语句,建议调试时打印,在生产环境关闭 sql: - show: false + show: true # 忽略鉴权url ignored: From 44e36f0bcdb9b2c7fa6b90074ec49d1dd1c6bb6a Mon Sep 17 00:00:00 2001 From: Chopper Date: Thu, 28 Oct 2021 18:35:23 +0800 Subject: [PATCH 08/18] =?UTF-8?q?=E6=90=9C=E7=B4=A2=E5=8F=82=E6=95=B0?= =?UTF-8?q?=E9=97=AE=E9=A2=98=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lili/modules/order/order/entity/dto/OrderSearchParams.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/framework/src/main/java/cn/lili/modules/order/order/entity/dto/OrderSearchParams.java b/framework/src/main/java/cn/lili/modules/order/order/entity/dto/OrderSearchParams.java index f32eaf3e..a8add156 100644 --- a/framework/src/main/java/cn/lili/modules/order/order/entity/dto/OrderSearchParams.java +++ b/framework/src/main/java/cn/lili/modules/order/order/entity/dto/OrderSearchParams.java @@ -99,8 +99,7 @@ public class OrderSearchParams extends PageVO { //关键字查询 if (StrUtil.isNotEmpty(keywords)) { - wrapper.like("o.sn", keywords); - wrapper.like("oi.goods_name", keywords); + wrapper.like("o.sn", keywords).or().like("oi.goods_name", keywords); } //按卖家查询 wrapper.eq(StrUtil.equals(UserContext.getCurrentUser().getRole().name(), UserEnums.STORE.name()), "o.store_id", UserContext.getCurrentUser().getStoreId()); From 585e2c4ccc940f8a9054e5facb529f49eca0d0a2 Mon Sep 17 00:00:00 2001 From: Chopper Date: Thu, 28 Oct 2021 19:24:28 +0800 Subject: [PATCH 09/18] =?UTF-8?q?=E5=93=81=E7=89=8C=E5=88=A0=E9=99=A4?= =?UTF-8?q?=E5=AF=BC=E8=87=B4=E5=95=86=E5=93=81=E6=B2=A1=E6=9C=89=E5=93=81?= =?UTF-8?q?=E7=89=8C=EF=BC=8C=E5=89=8D=E7=AB=AFes=E6=9C=89=E7=A9=BA?= =?UTF-8?q?=E5=93=81=E7=89=8C=E9=97=AE=E9=A2=98=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/cn/lili/common/enums/ResultCode.java | 3 +- .../goods/service/CategoryBrandService.java | 2 +- .../modules/goods/service/GoodsService.java | 7 ++++ .../goods/serviceimpl/BrandServiceImpl.java | 38 +++++++++++++++---- .../serviceimpl/CategoryBrandServiceImpl.java | 4 +- .../goods/serviceimpl/GoodsServiceImpl.java | 7 ++++ 6 files changed, 50 insertions(+), 11 deletions(-) diff --git a/framework/src/main/java/cn/lili/common/enums/ResultCode.java b/framework/src/main/java/cn/lili/common/enums/ResultCode.java index 56c2ac34..d93ebb7f 100644 --- a/framework/src/main/java/cn/lili/common/enums/ResultCode.java +++ b/framework/src/main/java/cn/lili/common/enums/ResultCode.java @@ -99,7 +99,8 @@ public enum ResultCode { BRAND_DISABLE_ERROR(14003, "品牌禁用失败"), BRAND_DELETE_ERROR(14004, "品牌删除失败"), BRAND_NAME_EXIST_ERROR(20002, "品牌名称重复!"), - BRAND_USE_DISABLE_ERROR(20003, "分类已经绑定此品牌,请先解除关联"), + BRAND_USE_DISABLE_ERROR(20003, "分类已经绑定品牌,请先解除关联"), + BRAND_BIND_GOODS_ERROR(20005, "品牌已经绑定商品,请先解除关联"), BRAND_NOT_EXIST(20004, "品牌不存在"), /** diff --git a/framework/src/main/java/cn/lili/modules/goods/service/CategoryBrandService.java b/framework/src/main/java/cn/lili/modules/goods/service/CategoryBrandService.java index 57a776bc..32f84616 100644 --- a/framework/src/main/java/cn/lili/modules/goods/service/CategoryBrandService.java +++ b/framework/src/main/java/cn/lili/modules/goods/service/CategoryBrandService.java @@ -35,7 +35,7 @@ public interface CategoryBrandService extends IService { * @param brandId 品牌ID * @return 分类品牌关联信息 */ - List getCategoryBrandListByBrandId(String brandId); + List getCategoryBrandListByBrandId(List brandId); /** * 保存分类品牌关系 diff --git a/framework/src/main/java/cn/lili/modules/goods/service/GoodsService.java b/framework/src/main/java/cn/lili/modules/goods/service/GoodsService.java index 2c6e03fb..dbf17a60 100644 --- a/framework/src/main/java/cn/lili/modules/goods/service/GoodsService.java +++ b/framework/src/main/java/cn/lili/modules/goods/service/GoodsService.java @@ -20,6 +20,13 @@ import java.util.List; public interface GoodsService extends IService { + /** + * 根据品牌获取商品 + * + * @param brandIds 品牌ids + */ + List getByBrandIds(List brandIds); + /** * 下架所有商家商品 * diff --git a/framework/src/main/java/cn/lili/modules/goods/serviceimpl/BrandServiceImpl.java b/framework/src/main/java/cn/lili/modules/goods/serviceimpl/BrandServiceImpl.java index 05612b92..2b66bb3b 100644 --- a/framework/src/main/java/cn/lili/modules/goods/serviceimpl/BrandServiceImpl.java +++ b/framework/src/main/java/cn/lili/modules/goods/serviceimpl/BrandServiceImpl.java @@ -5,12 +5,14 @@ import cn.lili.common.enums.ResultCode; import cn.lili.common.exception.ServiceException; import cn.lili.modules.goods.entity.dos.Brand; import cn.lili.modules.goods.entity.dos.CategoryBrand; +import cn.lili.modules.goods.entity.dos.Goods; import cn.lili.modules.goods.entity.dto.BrandPageDTO; import cn.lili.modules.goods.entity.vos.BrandVO; import cn.lili.modules.goods.mapper.BrandMapper; import cn.lili.modules.goods.service.BrandService; import cn.lili.modules.goods.service.CategoryBrandService; import cn.lili.modules.goods.service.CategoryService; +import cn.lili.modules.goods.service.GoodsService; import cn.lili.mybatis.util.PageUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; @@ -21,6 +23,7 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.util.ArrayList; +import java.util.LinkedList; import java.util.List; import java.util.stream.Collectors; @@ -44,6 +47,9 @@ public class BrandServiceImpl extends ServiceImpl implements @Autowired private CategoryService categoryService; + @Autowired + private GoodsService goodsService; + @Override public IPage getBrandsByPage(BrandPageDTO page) { LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); @@ -88,7 +94,9 @@ public class BrandServiceImpl extends ServiceImpl implements Brand brand = this.checkExist(brandId); //如果是要禁用,则需要先判定绑定关系 if (Boolean.TRUE.equals(disable)) { - checkoutCategory(brandId); + List ids = new ArrayList<>(); + ids.add(brandId); + checkBind(ids); } brand.setDeleteFlag(disable); return updateById(brand); @@ -96,7 +104,7 @@ public class BrandServiceImpl extends ServiceImpl implements @Override public void deleteBrands(List ids) { - ids.forEach(this::checkoutCategory); + checkBind(ids); this.removeByIds(ids); } @@ -104,16 +112,32 @@ public class BrandServiceImpl extends ServiceImpl implements /** * 校验绑定关系 * - * @param brandId + * @param brandIds */ - private void checkoutCategory(String brandId) { + private void checkBind(List brandIds) { //分了绑定关系查询 - List categoryBrands = categoryBrandService.getCategoryBrandListByBrandId(brandId); + List categoryBrands = categoryBrandService.getCategoryBrandListByBrandId(brandIds); if (!categoryBrands.isEmpty()) { - List brandIds = categoryBrands.stream().map(CategoryBrand::getCategoryId).collect(Collectors.toList()); + List categoryIds = categoryBrands.stream().map(CategoryBrand::getCategoryId).collect(Collectors.toList()); throw new ServiceException(ResultCode.BRAND_USE_DISABLE_ERROR, - JSONUtil.toJsonStr(categoryService.getCategoryNameByIds(brandIds))); + JSONUtil.toJsonStr(categoryService.getCategoryNameByIds(categoryIds))); } + + //分了商品绑定关系查询 + List goods = goodsService.getByBrandIds(brandIds); + if (!goods.isEmpty()) { + List goodsNames = goods.stream().map(Goods::getGoodsName).collect(Collectors.toList()); + throw new ServiceException(ResultCode.BRAND_BIND_GOODS_ERROR, + JSONUtil.toJsonStr(goodsNames)); + } + } + + /** + * 校验绑定关系 + * + * @param brandIds + */ + private void checkoutGoods(List brandIds) { } /** diff --git a/framework/src/main/java/cn/lili/modules/goods/serviceimpl/CategoryBrandServiceImpl.java b/framework/src/main/java/cn/lili/modules/goods/serviceimpl/CategoryBrandServiceImpl.java index 4d0929f3..bd88e375 100644 --- a/framework/src/main/java/cn/lili/modules/goods/serviceimpl/CategoryBrandServiceImpl.java +++ b/framework/src/main/java/cn/lili/modules/goods/serviceimpl/CategoryBrandServiceImpl.java @@ -36,8 +36,8 @@ public class CategoryBrandServiceImpl extends ServiceImpl getCategoryBrandListByBrandId(String brandId) { - return this.list(new LambdaQueryWrapper().eq(CategoryBrand::getBrandId, brandId)); + public List getCategoryBrandListByBrandId(List brandId) { + return this.list(new LambdaQueryWrapper().in(CategoryBrand::getBrandId, brandId)); } @Override diff --git a/framework/src/main/java/cn/lili/modules/goods/serviceimpl/GoodsServiceImpl.java b/framework/src/main/java/cn/lili/modules/goods/serviceimpl/GoodsServiceImpl.java index af7d8365..08cb2a2d 100644 --- a/framework/src/main/java/cn/lili/modules/goods/serviceimpl/GoodsServiceImpl.java +++ b/framework/src/main/java/cn/lili/modules/goods/serviceimpl/GoodsServiceImpl.java @@ -119,6 +119,13 @@ public class GoodsServiceImpl extends ServiceImpl implements @Autowired private Cache cache; + @Override + public List getByBrandIds(List brandIds) { + LambdaQueryWrapper lambdaQueryWrapper = new LambdaQueryWrapper (); + lambdaQueryWrapper.in(Goods::getBrandId,brandIds); + return list(lambdaQueryWrapper); + } + @Override public void underStoreGoods(String storeId) { //获取商品ID列表 From afd5eba986dc95c346b08a48182c92da83541758 Mon Sep 17 00:00:00 2001 From: Chopper Date: Fri, 29 Oct 2021 10:18:15 +0800 Subject: [PATCH 10/18] =?UTF-8?q?i18n=E6=95=B0=E6=8D=AE=E5=BA=93=E9=85=8D?= =?UTF-8?q?=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/application.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/application.yml b/config/application.yml index e3e81029..cef22e8d 100644 --- a/config/application.yml +++ b/config/application.yml @@ -70,7 +70,7 @@ spring: default-datasource: type: com.alibaba.druid.pool.DruidDataSource driverClassName: com.mysql.cj.jdbc.Driver - url: jdbc:mysql://192.168.0.116:3306/lilishop?useUnicode=true&characterEncoding=utf-8&useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai + url: jdbc:mysql://192.168.0.116:3306/i18n?useUnicode=true&characterEncoding=utf-8&useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai username: root password: lilishop maxActive: 20 From a2fd6dd8d1eb76a98c4a0f881e208d18b4a163df Mon Sep 17 00:00:00 2001 From: Chopper Date: Mon, 1 Nov 2021 09:04:50 +0800 Subject: [PATCH 11/18] =?UTF-8?q?=E8=BF=98=E5=8E=9F=E9=BB=98=E8=AE=A4?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=BA=93=E5=90=8D=E7=A7=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/application.yml | 2 +- .../main/java/cn/lili/modules/page/service/PageDataService.java | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/config/application.yml b/config/application.yml index cef22e8d..e3e81029 100644 --- a/config/application.yml +++ b/config/application.yml @@ -70,7 +70,7 @@ spring: default-datasource: type: com.alibaba.druid.pool.DruidDataSource driverClassName: com.mysql.cj.jdbc.Driver - url: jdbc:mysql://192.168.0.116:3306/i18n?useUnicode=true&characterEncoding=utf-8&useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai + url: jdbc:mysql://192.168.0.116:3306/lilishop?useUnicode=true&characterEncoding=utf-8&useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai username: root password: lilishop maxActive: 20 diff --git a/framework/src/main/java/cn/lili/modules/page/service/PageDataService.java b/framework/src/main/java/cn/lili/modules/page/service/PageDataService.java index 09432b50..b7cda265 100644 --- a/framework/src/main/java/cn/lili/modules/page/service/PageDataService.java +++ b/framework/src/main/java/cn/lili/modules/page/service/PageDataService.java @@ -7,6 +7,7 @@ import cn.lili.modules.page.entity.vos.PageDataListVO; import cn.lili.modules.page.entity.vos.PageDataVO; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.service.IService; +import org.springframework.cache.annotation.CacheConfig; /** * 页面业务层 From 7e58b98e74c01afee468bb223d146036cc253096 Mon Sep 17 00:00:00 2001 From: Chopper Date: Tue, 2 Nov 2021 10:31:54 +0800 Subject: [PATCH 12/18] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E4=B8=80=E4=B8=AA?= =?UTF-8?q?=E5=8F=AF=E8=83=BD=E5=AF=BC=E8=87=B4=E4=BC=98=E6=83=A0=E5=88=B8?= =?UTF-8?q?=E5=9C=A8=E8=B4=AD=E7=89=A9=E8=BD=A6=E6=9D=A1=E4=BB=B6=E4=B8=8D?= =?UTF-8?q?=E6=BB=A1=E8=B6=B3=E5=B0=B1=E5=8F=AF=E4=BB=A5=E9=80=89=E6=8B=A9?= =?UTF-8?q?=E4=BC=98=E6=83=A0=E5=88=B8=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../modules/order/cart/entity/dto/TradeDTO.java | 13 +++++++++++++ .../order/cart/render/impl/CouponRender.java | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/framework/src/main/java/cn/lili/modules/order/cart/entity/dto/TradeDTO.java b/framework/src/main/java/cn/lili/modules/order/cart/entity/dto/TradeDTO.java index b6286359..cc072b28 100644 --- a/framework/src/main/java/cn/lili/modules/order/cart/entity/dto/TradeDTO.java +++ b/framework/src/main/java/cn/lili/modules/order/cart/entity/dto/TradeDTO.java @@ -19,6 +19,7 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.stream.Collectors; /** * 购物车视图 @@ -147,4 +148,16 @@ public class TradeDTO implements Serializable { public TradeDTO() { this(CartTypeEnum.CART); } + + /** + * 过滤购物车中已选择的sku + * + * @return + */ + public List getCheckedSkuList() { + if (skuList != null && !skuList.isEmpty()) { + return skuList.stream().filter(CartSkuVO::getChecked).collect(Collectors.toList()); + } + return skuList; + } } diff --git a/framework/src/main/java/cn/lili/modules/order/cart/render/impl/CouponRender.java b/framework/src/main/java/cn/lili/modules/order/cart/render/impl/CouponRender.java index cbb9f9f6..ad833422 100644 --- a/framework/src/main/java/cn/lili/modules/order/cart/render/impl/CouponRender.java +++ b/framework/src/main/java/cn/lili/modules/order/cart/render/impl/CouponRender.java @@ -103,7 +103,7 @@ public class CouponRender implements CartRenderStep { if (memberCoupon == null) { return; } - List filterSku = filterSkuVo(tradeDTO.getSkuList(), memberCoupon); + List filterSku = filterSkuVo(tradeDTO.getCheckedSkuList(), memberCoupon); if (filterSku == null || filterSku.isEmpty()) { tradeDTO.getCantUseCoupons().add(new MemberCouponVO(memberCoupon, "购物车中没有满足优惠券使用范围的优惠券")); From 394ee27525fa327b4ecdcf0b638a8b3b43cb20db Mon Sep 17 00:00:00 2001 From: Chopper Date: Tue, 2 Nov 2021 12:45:52 +0800 Subject: [PATCH 13/18] =?UTF-8?q?=E5=BA=93=E5=AD=98=E5=AD=97=E6=AE=B5?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B=E4=B8=8D=E4=B8=80=E8=87=B4=E9=97=AE=E9=A2=98?= =?UTF-8?q?=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../serviceimpl/GoodsSkuServiceImpl.java | 29 ++++++++----------- .../serviceimpl/EsGoodsIndexServiceImpl.java | 2 +- .../cn/lili/test/elasticsearch/EsTest.java | 5 ++-- 3 files changed, 16 insertions(+), 20 deletions(-) diff --git a/framework/src/main/java/cn/lili/modules/goods/serviceimpl/GoodsSkuServiceImpl.java b/framework/src/main/java/cn/lili/modules/goods/serviceimpl/GoodsSkuServiceImpl.java index ad617615..6fa288a2 100644 --- a/framework/src/main/java/cn/lili/modules/goods/serviceimpl/GoodsSkuServiceImpl.java +++ b/framework/src/main/java/cn/lili/modules/goods/serviceimpl/GoodsSkuServiceImpl.java @@ -64,7 +64,7 @@ public class GoodsSkuServiceImpl extends ServiceImpl i * 缓存 */ @Autowired - private Cache cache; + private Cache cache; /** * 分类 */ @@ -75,11 +75,6 @@ public class GoodsSkuServiceImpl extends ServiceImpl i */ @Autowired private GoodsGalleryService goodsGalleryService; - /** - * 缓存 - */ - @Autowired - private StringRedisTemplate stringRedisTemplate; /** * rocketMq */ @@ -195,7 +190,7 @@ public class GoodsSkuServiceImpl extends ServiceImpl i @Override public GoodsSku getGoodsSkuByIdFromCache(String id) { //获取缓存中的sku - GoodsSku goodsSku = cache.get(GoodsSkuService.getCacheKeys(id)); + GoodsSku goodsSku = (GoodsSku) cache.get(GoodsSkuService.getCacheKeys(id)); //如果缓存中没有信息,则查询数据库,然后写入缓存 if (goodsSku == null) { goodsSku = this.getById(id); @@ -206,14 +201,14 @@ public class GoodsSkuServiceImpl extends ServiceImpl i } //获取商品库存 - String quantity = stringRedisTemplate.opsForValue().get(GoodsSkuService.getStockCacheKey(id)); + Integer integer = (Integer) cache.get(GoodsSkuService.getStockCacheKey(id)); //库存不为空 - if (StrUtil.isNotEmpty(quantity)) { + if (integer == null) { //库存与缓存中不一致, - if (!goodsSku.getQuantity().equals(Convert.toInt(quantity))) { + if (!goodsSku.getQuantity().equals(integer)) { //写入最新的库存信息 - goodsSku.setQuantity(Convert.toInt(quantity)); + goodsSku.setQuantity(integer); cache.put(GoodsSkuService.getCacheKeys(goodsSku.getId()), goodsSku); } } @@ -408,7 +403,7 @@ public class GoodsSkuServiceImpl extends ServiceImpl i goodsSku.setQuantity(quantity); this.update(new LambdaUpdateWrapper().eq(GoodsSku::getId, skuId).set(GoodsSku::getQuantity, quantity)); cache.put(GoodsSkuService.getCacheKeys(skuId), goodsSku); - stringRedisTemplate.opsForValue().set(GoodsSkuService.getStockCacheKey(skuId), quantity.toString()); + cache.put(GoodsSkuService.getStockCacheKey(skuId), quantity); //更新商品库存 List goodsSkus = new ArrayList<>(); @@ -420,12 +415,12 @@ public class GoodsSkuServiceImpl extends ServiceImpl i @Override public Integer getStock(String skuId) { String cacheKeys = GoodsSkuService.getStockCacheKey(skuId); - String stockStr = stringRedisTemplate.opsForValue().get(cacheKeys); - if (stockStr != null) { - return Convert.toInt(stockStr); + Integer stock = (Integer) cache.get(cacheKeys); + if (stock != null) { + return stock; } else { GoodsSku goodsSku = getGoodsSkuByIdFromCache(skuId); - stringRedisTemplate.opsForValue().set(cacheKeys, goodsSku.getQuantity().toString()); + cache.put(cacheKeys, goodsSku.getQuantity()); return goodsSku.getQuantity(); } } @@ -536,7 +531,7 @@ public class GoodsSkuServiceImpl extends ServiceImpl i } goodsSku.setGoodsType(goods.getGoodsType()); skus.add(goodsSku); - stringRedisTemplate.opsForValue().set(GoodsSkuService.getStockCacheKey(goodsSku.getId()), goodsSku.getQuantity().toString()); + cache.put(GoodsSkuService.getStockCacheKey(goodsSku.getId()), goodsSku.getQuantity()); } this.saveBatch(skus); return skus; diff --git a/framework/src/main/java/cn/lili/modules/search/serviceimpl/EsGoodsIndexServiceImpl.java b/framework/src/main/java/cn/lili/modules/search/serviceimpl/EsGoodsIndexServiceImpl.java index ed5a1ce9..c2cd102c 100644 --- a/framework/src/main/java/cn/lili/modules/search/serviceimpl/EsGoodsIndexServiceImpl.java +++ b/framework/src/main/java/cn/lili/modules/search/serviceimpl/EsGoodsIndexServiceImpl.java @@ -167,7 +167,7 @@ public class EsGoodsIndexServiceImpl extends BaseElasticsearchService implements Map goodsCurrentPromotionMap = promotionService.getGoodsCurrentPromotionMap(index); index.setPromotionMap(goodsCurrentPromotionMap); esGoodsIndices.add(index); - cache.put(GoodsSkuService.getStockCacheKey(goodsSku.getId()), goodsSku.getQuantity().toString()); + cache.put(GoodsSkuService.getStockCacheKey(goodsSku.getId()), goodsSku.getQuantity()); } //初始化商品索引 this.initIndex(esGoodsIndices); diff --git a/manager-api/src/test/java/cn/lili/test/elasticsearch/EsTest.java b/manager-api/src/test/java/cn/lili/test/elasticsearch/EsTest.java index 566a5772..e31c9903 100644 --- a/manager-api/src/test/java/cn/lili/test/elasticsearch/EsTest.java +++ b/manager-api/src/test/java/cn/lili/test/elasticsearch/EsTest.java @@ -2,6 +2,7 @@ package cn.lili.test.elasticsearch; import cn.hutool.core.util.ReflectUtil; import cn.hutool.json.JSONUtil; +import cn.lili.cache.Cache; import cn.lili.common.vo.PageVO; import cn.lili.modules.goods.entity.dos.GoodsSku; import cn.lili.modules.goods.entity.enums.GoodsAuthEnum; @@ -52,7 +53,7 @@ class EsTest { private GoodsSkuService goodsSkuService; @Autowired - private StringRedisTemplate stringRedisTemplate; + private Cache cache; @Autowired private PromotionService promotionService; @@ -161,7 +162,7 @@ class EsTest { Map goodsCurrentPromotionMap = promotionService.getGoodsCurrentPromotionMap(index); index.setPromotionMap(goodsCurrentPromotionMap); esGoodsIndices.add(index); - stringRedisTemplate.opsForValue().set(GoodsSkuService.getStockCacheKey(goodsSku.getId()), goodsSku.getQuantity().toString()); + cache.put(GoodsSkuService.getStockCacheKey(goodsSku.getId()), goodsSku.getQuantity()); } esGoodsIndexService.initIndex(esGoodsIndices); Assertions.assertTrue(true); From 9baafd55beea1a75051ac7c81f070e04bcd10590 Mon Sep 17 00:00:00 2001 From: Chopper Date: Tue, 2 Nov 2021 12:59:58 +0800 Subject: [PATCH 14/18] =?UTF-8?q?=E5=BA=93=E5=AD=98=E5=88=A4=E5=AE=9A?= =?UTF-8?q?=E9=97=AE=E9=A2=98=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cn/lili/modules/goods/serviceimpl/GoodsSkuServiceImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/framework/src/main/java/cn/lili/modules/goods/serviceimpl/GoodsSkuServiceImpl.java b/framework/src/main/java/cn/lili/modules/goods/serviceimpl/GoodsSkuServiceImpl.java index 6fa288a2..37eb9159 100644 --- a/framework/src/main/java/cn/lili/modules/goods/serviceimpl/GoodsSkuServiceImpl.java +++ b/framework/src/main/java/cn/lili/modules/goods/serviceimpl/GoodsSkuServiceImpl.java @@ -204,7 +204,7 @@ public class GoodsSkuServiceImpl extends ServiceImpl i Integer integer = (Integer) cache.get(GoodsSkuService.getStockCacheKey(id)); //库存不为空 - if (integer == null) { + if (integer != null) { //库存与缓存中不一致, if (!goodsSku.getQuantity().equals(integer)) { //写入最新的库存信息 From af37386821442069a3581802a5d3d8c3bd6e36a4 Mon Sep 17 00:00:00 2001 From: Chopper Date: Tue, 2 Nov 2021 16:03:07 +0800 Subject: [PATCH 15/18] =?UTF-8?q?=E5=91=BD=E5=90=8D=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 02c67ae5..6e5ea9db 100644 --- a/README.md +++ b/README.md @@ -43,21 +43,21 @@ https://docs.pickmall.cn ### 💧 开源商城项目地址(gitee) -**Java后台(商城所有API)**:https://gitee.com/beijing_hongye_huicheng/lilishop.git +**API(商城所有API)**:https://gitee.com/beijing_hongye_huicheng/lilishop.git **UI(商城管理端/商家端/买家PC端)**: https://gitee.com/beijing_hongye_huicheng/lilishop-ui.git -**Uni-app(商城移动端,支持小程序/APP/H5)**:https://gitee.com/beijing_hongye_huicheng/lilishop-uniapp.git +**uniapp(商城移动端,支持小程序/APP/H5)**:https://gitee.com/beijing_hongye_huicheng/lilishop-uniapp.git **docker一键部署(商城部署脚本)**:https://gitee.com/beijing_hongye_huicheng/docker.git ### 💧 开源商城项目地址(github) -**Java后台(商城所有API)**:https://github.com/hongyehuicheng/lilishop.git +**API(商城所有API)**:https://github.com/hongyehuicheng/lilishop.git **UI(商城管理端/商家端/买家PC端)**: https://github.com/hongyehuicheng/lilishop-ui.git -**Uni-app(商城移动端,支持小程序/APP/H5)**:https://github.com/hongyehuicheng/lilishop-uniapp.git +**uniapp(商城移动端,支持小程序/APP/H5)**:https://github.com/hongyehuicheng/lilishop-uniapp.git **docker一键部署(商城部署脚本)**:https://github.com/hongyehuicheng/docker.git From 956a6e465af4fea6d8f76a53d433a19e1889618a Mon Sep 17 00:00:00 2001 From: Chopper Date: Wed, 3 Nov 2021 09:14:05 +0800 Subject: [PATCH 16/18] =?UTF-8?q?=E4=BC=98=E5=8C=96=E9=AA=8C=E8=AF=81?= =?UTF-8?q?=E7=A0=81=E6=A8=A1=E5=9D=97=E7=9B=B8=E5=85=B3=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=EF=BC=8C=E8=A7=A3=E5=86=B3=E4=B8=80=E4=B8=AA=E5=8F=AF=E8=83=BD?= =?UTF-8?q?=E7=94=B1=E4=BA=8E=E5=B9=B6=E5=8F=91=E5=AF=BC=E8=87=B4=E5=A4=9A?= =?UTF-8?q?=E5=8F=91=E7=9F=AD=E4=BF=A1=EF=BC=8C=E6=88=96=E8=80=85=E5=A4=9A?= =?UTF-8?q?=E7=94=9F=E6=88=90=E9=AA=8C=E8=AF=81=E7=BB=93=E6=9E=9C=E7=9A=84?= =?UTF-8?q?=E6=83=85=E6=99=AF=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/SliderImageController.java | 10 ++------- .../lili/controller/common/SmsController.java | 9 +++----- .../src/main/java/cn/lili/cache/Cache.java | 2 +- .../java/cn/lili/cache/impl/RedisCache.java | 4 ++-- .../java/cn/lili/common/enums/ResultCode.java | 4 ++-- .../service/VerificationService.java | 2 +- .../service/impl/VerificationServiceImpl.java | 21 ++++++++----------- 7 files changed, 20 insertions(+), 32 deletions(-) diff --git a/common-api/src/main/java/cn/lili/controller/common/SliderImageController.java b/common-api/src/main/java/cn/lili/controller/common/SliderImageController.java index 640ffec9..865c1780 100644 --- a/common-api/src/main/java/cn/lili/controller/common/SliderImageController.java +++ b/common-api/src/main/java/cn/lili/controller/common/SliderImageController.java @@ -32,14 +32,8 @@ public class SliderImageController { @GetMapping("/{verificationEnums}") @ApiOperation(value = "获取校验接口,一分钟同一个ip请求10次") public ResultMessage getSliderImage(@RequestHeader String uuid, @PathVariable VerificationEnums verificationEnums) { - try { - return ResultUtil.data(verificationService.createVerification(verificationEnums, uuid)); - } catch (ServiceException e) { - throw e; - } catch (Exception e) { - log.error("获取校验接口错误", e); - throw new ServiceException(ResultCode.VERIFICATION_EXIST); - } + return ResultUtil.data(verificationService.createVerification(verificationEnums, uuid)); + } @LimitPoint(name = "slider_image", key = "verification_pre_check", limit = 600) diff --git a/common-api/src/main/java/cn/lili/controller/common/SmsController.java b/common-api/src/main/java/cn/lili/controller/common/SmsController.java index 70f5bfab..04fe50f9 100644 --- a/common-api/src/main/java/cn/lili/controller/common/SmsController.java +++ b/common-api/src/main/java/cn/lili/controller/common/SmsController.java @@ -42,11 +42,8 @@ public class SmsController { @RequestHeader String uuid, @PathVariable String mobile, @PathVariable VerificationEnums verificationEnums) { - if (verificationService.check(uuid, verificationEnums)) { - smsUtil.sendSmsCode(mobile, verificationEnums, uuid); - return ResultUtil.success(ResultCode.VERIFICATION_SEND_SUCCESS); - } else { - throw new ServiceException(ResultCode.VERIFICATION_SMS_EXPIRED_ERROR); - } + verificationService.check(uuid, verificationEnums); + smsUtil.sendSmsCode(mobile, verificationEnums, uuid); + return ResultUtil.success(ResultCode.VERIFICATION_SEND_SUCCESS); } } diff --git a/framework/src/main/java/cn/lili/cache/Cache.java b/framework/src/main/java/cn/lili/cache/Cache.java index d71bc646..7bd4d481 100644 --- a/framework/src/main/java/cn/lili/cache/Cache.java +++ b/framework/src/main/java/cn/lili/cache/Cache.java @@ -89,7 +89,7 @@ public interface Cache { * * @param key 缓存key */ - void remove(Object key); + Boolean remove(Object key); /** * 删除 diff --git a/framework/src/main/java/cn/lili/cache/impl/RedisCache.java b/framework/src/main/java/cn/lili/cache/impl/RedisCache.java index b16d0405..ade80a68 100644 --- a/framework/src/main/java/cn/lili/cache/impl/RedisCache.java +++ b/framework/src/main/java/cn/lili/cache/impl/RedisCache.java @@ -78,9 +78,9 @@ public class RedisCache implements Cache { } @Override - public void remove(Object key) { + public Boolean remove(Object key) { - redisTemplate.delete(key); + return redisTemplate.delete(key); } /** diff --git a/framework/src/main/java/cn/lili/common/enums/ResultCode.java b/framework/src/main/java/cn/lili/common/enums/ResultCode.java index d93ebb7f..accc1077 100644 --- a/framework/src/main/java/cn/lili/common/enums/ResultCode.java +++ b/framework/src/main/java/cn/lili/common/enums/ResultCode.java @@ -426,8 +426,8 @@ public enum ResultCode { */ VERIFICATION_SEND_SUCCESS(80201, "短信验证码,发送成功"), VERIFICATION_ERROR(80202, "验证失败"), - VERIFICATION_SMS_ERROR(80203, "短信验证码错误,请重新校验"), - VERIFICATION_SMS_EXPIRED_ERROR(80204, "验证码已失效,请重新校验"), + VERIFICATION_CODE_INVALID(80204, "验证码已失效,请重新校验"), + VERIFICATION_SMS_CHECKED_ERROR(80210, "短信验证码错误,请重新校验"), /** * 微信相关异常 diff --git a/framework/src/main/java/cn/lili/modules/verification/service/VerificationService.java b/framework/src/main/java/cn/lili/modules/verification/service/VerificationService.java index 9bd4109d..44c3f836 100644 --- a/framework/src/main/java/cn/lili/modules/verification/service/VerificationService.java +++ b/framework/src/main/java/cn/lili/modules/verification/service/VerificationService.java @@ -20,7 +20,7 @@ public interface VerificationService { * @return 校验对象 * @throws IOException 校验错误 */ - Map createVerification(VerificationEnums verificationEnums, String uuid) throws IOException; + Map createVerification(VerificationEnums verificationEnums, String uuid); /** * 预校验 diff --git a/framework/src/main/java/cn/lili/modules/verification/service/impl/VerificationServiceImpl.java b/framework/src/main/java/cn/lili/modules/verification/service/impl/VerificationServiceImpl.java index 9f35be8c..be0bbf6a 100644 --- a/framework/src/main/java/cn/lili/modules/verification/service/impl/VerificationServiceImpl.java +++ b/framework/src/main/java/cn/lili/modules/verification/service/impl/VerificationServiceImpl.java @@ -51,7 +51,7 @@ public class VerificationServiceImpl implements VerificationService { * @return 验证码参数 */ @Override - public Map createVerification(VerificationEnums verificationEnums, String uuid) throws IOException { + public Map createVerification(VerificationEnums verificationEnums, String uuid) { if (uuid == null) { throw new ServiceException(ResultCode.ILLEGAL_REQUEST_ERROR); @@ -97,8 +97,7 @@ public class VerificationServiceImpl implements VerificationService { } catch (ServiceException e) { throw e; } catch (Exception e) { - log.error("创建校验错误", e); - return null; + throw new ServiceException(ResultCode.ERROR); } } @@ -136,16 +135,16 @@ public class VerificationServiceImpl implements VerificationService { public boolean preCheck(Integer xPos, String uuid, VerificationEnums verificationEnums) { Integer randomX = (Integer) cache.get(cacheKey(verificationEnums, uuid)); if (randomX == null) { - return false; + throw new ServiceException(ResultCode.VERIFICATION_CODE_INVALID); } log.debug("{}{}", randomX, xPos); - //验证结果 - if (Math.abs(randomX - xPos) < verificationCodeProperties.getFaultTolerant()) { + //验证结果正确 && 删除标记成功 + if (Math.abs(randomX - xPos) < verificationCodeProperties.getFaultTolerant() && cache.remove(cacheResult(verificationEnums, uuid))) { //验证成功,则记录验证结果 验证有效时间与验证码创建有效时间一致 cache.put(cacheResult(verificationEnums, uuid), true, verificationCodeProperties.getEffectiveTime()); return true; } - return false; + throw new ServiceException(ResultCode.VERIFICATION_ERROR); } /** @@ -157,13 +156,11 @@ public class VerificationServiceImpl implements VerificationService { */ @Override public boolean check(String uuid, VerificationEnums verificationEnums) { - Object object = cache.get(cacheResult(verificationEnums, uuid)); - if (object == null) { - return false; - } else { - cache.remove(cacheResult(verificationEnums, uuid)); + //如果有校验标记,则返回校验结果 + if (cache.remove(cacheResult(verificationEnums, uuid))) { return true; } + throw new ServiceException(ResultCode.VERIFICATION_CODE_INVALID); } /** From af9ffd1cbfd6cc1a52880e0c5777aa4ffc802543 Mon Sep 17 00:00:00 2001 From: Chopper Date: Wed, 3 Nov 2021 09:36:25 +0800 Subject: [PATCH 17/18] =?UTF-8?q?=E8=A7=A3=E5=86=B3admin=E9=A1=B9=E7=9B=AE?= =?UTF-8?q?=E6=97=A0=E6=B3=95=E5=90=AF=E5=8A=A8=E9=97=AE=E9=A2=98=E3=80=82?= =?UTF-8?q?=20=E5=AE=8C=E5=96=84=E9=AA=8C=E8=AF=81=E7=A0=81=E6=A8=A1?= =?UTF-8?q?=E5=9D=97=E4=BC=98=E5=8C=96=E9=9C=80=E8=A6=81=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E7=9A=84=E9=A1=B9=E7=9B=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- admin/src/main/resources/logback-spring.xml | 41 +++++++++++++++++++ .../passport/MemberBuyerController.java | 35 ++++++---------- config/application.yml | 11 +++-- .../service/impl/VerificationServiceImpl.java | 2 +- 4 files changed, 59 insertions(+), 30 deletions(-) create mode 100644 admin/src/main/resources/logback-spring.xml diff --git a/admin/src/main/resources/logback-spring.xml b/admin/src/main/resources/logback-spring.xml new file mode 100644 index 00000000..8e2f8cac --- /dev/null +++ b/admin/src/main/resources/logback-spring.xml @@ -0,0 +1,41 @@ + + + + + + + + + + ${APP_NAME} + + + + ${LOG_FILE_PATH}/${APP_NAME}-%d{yyyy-MM-dd}.log + 30 + + + ${FILE_LOG_PATTERN} + + + + + + + 127.0.0.1:4560 + + + + UTC + + + + {"appName":"${APP_NAME}"} + + + + + + + + \ No newline at end of file diff --git a/buyer-api/src/main/java/cn/lili/controller/passport/MemberBuyerController.java b/buyer-api/src/main/java/cn/lili/controller/passport/MemberBuyerController.java index d81bc53e..affadd30 100644 --- a/buyer-api/src/main/java/cn/lili/controller/passport/MemberBuyerController.java +++ b/buyer-api/src/main/java/cn/lili/controller/passport/MemberBuyerController.java @@ -47,11 +47,8 @@ public class MemberBuyerController { public ResultMessage userLogin(@NotNull(message = "用户名不能为空") @RequestParam String username, @NotNull(message = "密码不能为空") @RequestParam String password, @RequestHeader String uuid) { - if (verificationService.check(uuid, VerificationEnums.LOGIN)) { - return ResultUtil.data(this.memberService.usernameLogin(username, password)); - } else { - throw new ServiceException(ResultCode.VERIFICATION_ERROR); - } + verificationService.check(uuid, VerificationEnums.LOGIN); + return ResultUtil.data(this.memberService.usernameLogin(username, password)); } @ApiOperation(value = "短信登录接口") @@ -63,11 +60,8 @@ public class MemberBuyerController { public ResultMessage smsLogin(@NotNull(message = "手机号为空") @RequestParam String mobile, @NotNull(message = "验证码为空") @RequestParam String code, @RequestHeader String uuid) { - if (smsUtil.verifyCode(mobile, VerificationEnums.LOGIN, uuid, code)) { - return ResultUtil.data(memberService.mobilePhoneLogin(mobile)); - } else { - throw new ServiceException(ResultCode.VERIFICATION_SMS_ERROR); - } + smsUtil.verifyCode(mobile, VerificationEnums.LOGIN, uuid, code); + return ResultUtil.data(memberService.mobilePhoneLogin(mobile)); } @ApiOperation(value = "注册用户") @@ -84,12 +78,9 @@ public class MemberBuyerController { @RequestHeader String uuid, @NotNull(message = "验证码不能为空") @RequestParam String code) { - boolean result = smsUtil.verifyCode(mobilePhone, VerificationEnums.REGISTER, uuid, code); - if (result) { - return ResultUtil.data(memberService.register(username, password, mobilePhone)); - } else { - throw new ServiceException(ResultCode.VERIFICATION_SMS_ERROR); - } + smsUtil.verifyCode(mobilePhone, VerificationEnums.REGISTER, uuid, code); + return ResultUtil.data(memberService.register(username, password, mobilePhone)); + } @ApiOperation(value = "获取当前登录用户接口") @@ -109,13 +100,11 @@ public class MemberBuyerController { @NotNull(message = "验证码为空") @RequestParam String code, @RequestHeader String uuid) { //校验短信验证码是否正确 - if (smsUtil.verifyCode(mobile, VerificationEnums.FIND_USER, uuid, code)) { - //校验是否通过手机号可获取会员,存在则将会员信息存入缓存,有效时间3分钟 - if (memberService.findByMobile(uuid, mobile)) { - return ResultUtil.success(); - } - } - throw new ServiceException(ResultCode.VERIFICATION_ERROR); + smsUtil.verifyCode(mobile, VerificationEnums.FIND_USER, uuid, code); + //校验是否通过手机号可获取会员,存在则将会员信息存入缓存,有效时间3分钟 + memberService.findByMobile(uuid, mobile); + + return ResultUtil.success(); } @ApiOperation(value = "修改密码") diff --git a/config/application.yml b/config/application.yml index e3e81029..c729b183 100644 --- a/config/application.yml +++ b/config/application.yml @@ -182,7 +182,6 @@ mybatis-plus: # 日志 logging: - config: classpath:logback-spring.xml # 输出级别 level: cn.lili: info @@ -230,11 +229,11 @@ lili: system: isDemoSite: false isTestModel: true -# 脱敏级别: -# 0:不做脱敏处理 -# 1:管理端用户手机号等信息脱敏 -# 2:商家端信息脱敏(为2时,表示管理端,商家端同时脱敏) -# sensitiveLevel: 2 + # 脱敏级别: + # 0:不做脱敏处理 + # 1:管理端用户手机号等信息脱敏 + # 2:商家端信息脱敏(为2时,表示管理端,商家端同时脱敏) + # sensitiveLevel: 2 statistics: # 在线人数统计 X 小时。这里设置48,即统计过去48小时每小时在线人数 diff --git a/framework/src/main/java/cn/lili/modules/verification/service/impl/VerificationServiceImpl.java b/framework/src/main/java/cn/lili/modules/verification/service/impl/VerificationServiceImpl.java index be0bbf6a..7694f0f2 100644 --- a/framework/src/main/java/cn/lili/modules/verification/service/impl/VerificationServiceImpl.java +++ b/framework/src/main/java/cn/lili/modules/verification/service/impl/VerificationServiceImpl.java @@ -139,7 +139,7 @@ public class VerificationServiceImpl implements VerificationService { } log.debug("{}{}", randomX, xPos); //验证结果正确 && 删除标记成功 - if (Math.abs(randomX - xPos) < verificationCodeProperties.getFaultTolerant() && cache.remove(cacheResult(verificationEnums, uuid))) { + if (Math.abs(randomX - xPos) < verificationCodeProperties.getFaultTolerant() && cache.remove(cacheKey(verificationEnums, uuid))) { //验证成功,则记录验证结果 验证有效时间与验证码创建有效时间一致 cache.put(cacheResult(verificationEnums, uuid), true, verificationCodeProperties.getEffectiveTime()); return true; From ec020535e2ace50ecafb19720175f5dbd3da6e44 Mon Sep 17 00:00:00 2001 From: Chopper Date: Wed, 3 Nov 2021 15:06:02 +0800 Subject: [PATCH 18/18] =?UTF-8?q?=E6=9C=AA=E7=9F=A5=E8=B4=AD=E7=89=A9?= =?UTF-8?q?=E8=BD=A6=E7=9A=84=E6=83=85=E6=99=AF=E4=B8=8B=EF=BC=8C=E8=B4=AD?= =?UTF-8?q?=E7=89=A9=E8=BD=A6=E5=86=85=E5=AE=B9=E4=BA=92=E9=80=9A=E9=97=AE?= =?UTF-8?q?=E9=A2=98=E5=A4=84=E7=90=86=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../order/cart/entity/enums/CartTypeEnum.java | 4 +++ .../cart/entity/enums/TradeCacheEnum.java | 30 ------------------- .../order/cart/service/CartServiceImpl.java | 17 ++++------- 3 files changed, 9 insertions(+), 42 deletions(-) delete mode 100644 framework/src/main/java/cn/lili/modules/order/cart/entity/enums/TradeCacheEnum.java diff --git a/framework/src/main/java/cn/lili/modules/order/cart/entity/enums/CartTypeEnum.java b/framework/src/main/java/cn/lili/modules/order/cart/entity/enums/CartTypeEnum.java index 1f273a53..2a6073b7 100644 --- a/framework/src/main/java/cn/lili/modules/order/cart/entity/enums/CartTypeEnum.java +++ b/framework/src/main/java/cn/lili/modules/order/cart/entity/enums/CartTypeEnum.java @@ -33,4 +33,8 @@ public enum CartTypeEnum { */ KANJIA; + public String getPrefix() { + return "{" + this.name() + "}_"; + } + } diff --git a/framework/src/main/java/cn/lili/modules/order/cart/entity/enums/TradeCacheEnum.java b/framework/src/main/java/cn/lili/modules/order/cart/entity/enums/TradeCacheEnum.java deleted file mode 100644 index 3e26d466..00000000 --- a/framework/src/main/java/cn/lili/modules/order/cart/entity/enums/TradeCacheEnum.java +++ /dev/null @@ -1,30 +0,0 @@ -package cn.lili.modules.order.cart.entity.enums; - -/** - * 交易缓存枚举 - * - * @author Chopper - * @since 2020-03-25 2:30 下午 - */ -public enum TradeCacheEnum { - - //================交易================= - - /** - * 拼团 - */ - PINTUAN, - /** - * 购物车原始数据 - */ - CART_DATA, - /** - * 立即购买购物车原始数据 - */ - BUY_NOW_CART_DATA; - - - public String getPrefix() { - return "{" + this.name() + "}_"; - } -} diff --git a/framework/src/main/java/cn/lili/modules/order/cart/service/CartServiceImpl.java b/framework/src/main/java/cn/lili/modules/order/cart/service/CartServiceImpl.java index 52ef8c00..68a94a20 100644 --- a/framework/src/main/java/cn/lili/modules/order/cart/service/CartServiceImpl.java +++ b/framework/src/main/java/cn/lili/modules/order/cart/service/CartServiceImpl.java @@ -18,7 +18,6 @@ import cn.lili.modules.order.cart.entity.dto.MemberCouponDTO; import cn.lili.modules.order.cart.entity.dto.TradeDTO; import cn.lili.modules.order.cart.entity.enums.CartTypeEnum; import cn.lili.modules.order.cart.entity.enums.DeliveryMethodEnum; -import cn.lili.modules.order.cart.entity.enums.TradeCacheEnum; import cn.lili.modules.order.cart.entity.vo.CartSkuVO; import cn.lili.modules.order.cart.entity.vo.CartVO; import cn.lili.modules.order.cart.entity.vo.TradeParams; @@ -37,7 +36,6 @@ import cn.lili.modules.promotion.entity.vos.PointsGoodsVO; import cn.lili.modules.promotion.entity.vos.kanjia.KanjiaActivitySearchParams; import cn.lili.modules.promotion.service.*; import cn.lili.modules.search.entity.dos.EsGoodsIndex; -import cn.lili.modules.search.service.EsGoodsIndexService; import cn.lili.modules.search.service.EsGoodsSearchService; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import lombok.extern.slf4j.Slf4j; @@ -204,17 +202,12 @@ public class CartServiceImpl implements CartService { */ private String getOriginKey(CartTypeEnum cartTypeEnum) { - String cacheKey = ""; - //如果会员登录了,则要以会员id为key - AuthUser currentUser = UserContext.getCurrentUser(); - if (cartTypeEnum.equals(CartTypeEnum.CART)) { - cacheKey = TradeCacheEnum.CART_DATA.getPrefix() + currentUser.getId(); - } else if (cartTypeEnum.equals(CartTypeEnum.BUY_NOW)) { - cacheKey = TradeCacheEnum.BUY_NOW_CART_DATA.getPrefix() + currentUser.getId(); - } else if (cartTypeEnum.equals(CartTypeEnum.PINTUAN)) { - cacheKey = TradeCacheEnum.PINTUAN.getPrefix() + currentUser.getId(); + //缓存key,默认使用购物车 + if (cartTypeEnum != null) { + AuthUser currentUser = UserContext.getCurrentUser(); + return cartTypeEnum.getPrefix() + currentUser.getId(); } - return cacheKey; + throw new ServiceException(ResultCode.ERROR); } @Override