From f8a8e2fc681910e24246f5f872f3013bf46e27b4 Mon Sep 17 00:00:00 2001 From: hequan_waynaqua <1669738430@qq.com> Date: Mon, 26 Oct 2020 17:22:25 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E5=95=86=E5=9F=8E):=20=E6=B7=BB=E5=8A=A0e?= =?UTF-8?q?lasticsearch?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/api/controller/shop/GoodsController.java | 10 +++++----- .../java/com/wayn/common/constant/SysConstants.java | 4 ++-- .../core/service/shop/impl/GoodsServiceImpl.java | 6 +++--- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/waynboot-admin-api/src/main/java/com/wayn/admin/api/controller/shop/GoodsController.java b/waynboot-admin-api/src/main/java/com/wayn/admin/api/controller/shop/GoodsController.java index 7cd3686..5c71b70 100644 --- a/waynboot-admin-api/src/main/java/com/wayn/admin/api/controller/shop/GoodsController.java +++ b/waynboot-admin-api/src/main/java/com/wayn/admin/api/controller/shop/GoodsController.java @@ -70,14 +70,14 @@ public class GoodsController extends BaseController { @PostMapping("syncEs") public R syncEs() { - if (redisCache.getCacheObject(SysConstants.REDIS_GOODS_INDEX) != null) { + if (redisCache.getCacheObject(SysConstants.REDIS_ES_GOODS_INDEX) != null) { return R.error("正在同步,请稍等"); } boolean flag = false; - redisCache.setCacheObject(SysConstants.REDIS_GOODS_INDEX, true, 3, TimeUnit.MINUTES); - baseElasticService.deleteIndex(SysConstants.GOODS_INDEX); + redisCache.setCacheObject(SysConstants.REDIS_ES_GOODS_INDEX, true, 3, TimeUnit.MINUTES); + baseElasticService.deleteIndex(SysConstants.ES_GOODS_INDEX); InputStream inputStream = this.getClass().getResourceAsStream(SysConstants.ES_INDEX_GOODS_FILENAME); - if (baseElasticService.createIndex(SysConstants.GOODS_INDEX, FileUtils.getContent(inputStream))) { + if (baseElasticService.createIndex(SysConstants.ES_GOODS_INDEX, FileUtils.getContent(inputStream))) { List list = iGoodsService.list(); List entities = new ArrayList<>(); for (Goods goods : list) { @@ -94,7 +94,7 @@ public class GoodsController extends BaseController { entities.add(elasticEntity); } flag = baseElasticService.insertBatch("goods", entities); - redisCache.deleteObject(SysConstants.REDIS_GOODS_INDEX); + redisCache.deleteObject(SysConstants.REDIS_ES_GOODS_INDEX); } return R.result(flag); } diff --git a/waynboot-common/src/main/java/com/wayn/common/constant/SysConstants.java b/waynboot-common/src/main/java/com/wayn/common/constant/SysConstants.java index e044df5..62dcf47 100644 --- a/waynboot-common/src/main/java/com/wayn/common/constant/SysConstants.java +++ b/waynboot-common/src/main/java/com/wayn/common/constant/SysConstants.java @@ -78,7 +78,7 @@ public class SysConstants { */ public static String ES_INDEX_GOODS_FILENAME = "/es/index/goods"; - public static final String GOODS_INDEX = "goods"; - public static final String REDIS_GOODS_INDEX = "es_goods"; + public static final String ES_GOODS_INDEX = "goods"; + public static final String REDIS_ES_GOODS_INDEX = "es_goods"; } diff --git a/waynboot-common/src/main/java/com/wayn/common/core/service/shop/impl/GoodsServiceImpl.java b/waynboot-common/src/main/java/com/wayn/common/core/service/shop/impl/GoodsServiceImpl.java index 84c19df..db3fe69 100644 --- a/waynboot-common/src/main/java/com/wayn/common/core/service/shop/impl/GoodsServiceImpl.java +++ b/waynboot-common/src/main/java/com/wayn/common/core/service/shop/impl/GoodsServiceImpl.java @@ -142,7 +142,7 @@ public class GoodsServiceImpl extends ServiceImpl implements map.put("keyword", goods.getKeywords().split(",")); map.put("isOnSale", goods.getIsOnSale()); elasticEntity.setData(map); - boolean one = baseElasticService.insertOrUpdateOne(SysConstants.GOODS_INDEX, elasticEntity); + boolean one = baseElasticService.insertOrUpdateOne(SysConstants.ES_GOODS_INDEX, elasticEntity); if (!one) { throw new BusinessException("创建商品,同步es失败"); } @@ -167,7 +167,7 @@ public class GoodsServiceImpl extends ServiceImpl implements iGoodsAttributeService.remove(new QueryWrapper().eq("goods_id", goodsId)); iGoodsProductService.remove(new QueryWrapper().eq("goods_id", goodsId)); // 同步es - boolean one = baseElasticService.delete(SysConstants.GOODS_INDEX, goodsId.toString()); + boolean one = baseElasticService.delete(SysConstants.ES_GOODS_INDEX, goodsId.toString()); if (!one) { throw new BusinessException("删除商品,同步es失败"); } @@ -238,7 +238,7 @@ public class GoodsServiceImpl extends ServiceImpl implements map.put("keyword", goods.getKeywords().split(",")); map.put("isOnSale", goods.getIsOnSale()); elasticEntity.setData(map); - boolean one = baseElasticService.insertOrUpdateOne(SysConstants.GOODS_INDEX, elasticEntity); + boolean one = baseElasticService.insertOrUpdateOne(SysConstants.ES_GOODS_INDEX, elasticEntity); if (!one) { throw new BusinessException("创建商品,同步es失败"); }