diff --git a/mall-dependencies/pom.xml b/mall-dependencies/pom.xml index a2ff54112..2148f9bd1 100644 --- a/mall-dependencies/pom.xml +++ b/mall-dependencies/pom.xml @@ -208,6 +208,7 @@ org.apache.dubbo dubbo ${dubbo.version} + org.apache.dubbo @@ -247,6 +248,13 @@ ${xxl-job.version} + + + + + + + io.seata diff --git a/management-web-app/pom.xml b/management-web-app/pom.xml index 2a1025e36..3649c3014 100644 --- a/management-web-app/pom.xml +++ b/management-web-app/pom.xml @@ -71,8 +71,21 @@ com.alibaba.cloud spring-cloud-starter-alibaba-nacos-discovery + + + + + + + + + + + + + org.projectlombok diff --git a/management-web-app/src/main/resources/application-dev.yml b/management-web-app/src/main/resources/application-dev.yml index 4cfe1567c..2e26cd388 100644 --- a/management-web-app/src/main/resources/application-dev.yml +++ b/management-web-app/src/main/resources/application-dev.yml @@ -11,4 +11,5 @@ spring: dubbo: # Dubbo 注册中心 registry: - address: spring-cloud://400-infra.server.iocoder.cn:8848 # 指定 Dubbo 服务注册中心的地址 + # address: spring-cloud://400-infra.server.iocoder.cn:8848 # 指定 Dubbo 服务注册中心的地址 + address: nacos://400-infra.server.iocoder.cn:8848?namespace=dev # 指定 Dubbo 服务注册中心的地址 diff --git a/management-web-app/src/main/resources/application-local.yml b/management-web-app/src/main/resources/application-local.yml index 4a84b973e..2e26cd388 100644 --- a/management-web-app/src/main/resources/application-local.yml +++ b/management-web-app/src/main/resources/application-local.yml @@ -11,6 +11,5 @@ spring: dubbo: # Dubbo 注册中心 registry: -# address: spring-cloud://400-infra.server.iocoder.cn:8848 # 指定 Dubbo 服务注册中心的地址 + # address: spring-cloud://400-infra.server.iocoder.cn:8848 # 指定 Dubbo 服务注册中心的地址 address: nacos://400-infra.server.iocoder.cn:8848?namespace=dev # 指定 Dubbo 服务注册中心的地址 - diff --git a/product-service-project/product-service-api/src/main/java/cn/iocoder/mall/productservice/rpc/spu/ProductSpuRpc.java b/product-service-project/product-service-api/src/main/java/cn/iocoder/mall/productservice/rpc/spu/ProductSpuRpc.java index 4f797572c..df7cca42f 100644 --- a/product-service-project/product-service-api/src/main/java/cn/iocoder/mall/productservice/rpc/spu/ProductSpuRpc.java +++ b/product-service-project/product-service-api/src/main/java/cn/iocoder/mall/productservice/rpc/spu/ProductSpuRpc.java @@ -56,10 +56,10 @@ public interface ProductSpuRpc { /** * 顺序获得商品 SPU 编号数组 * - * @param limit 数量 * @param lastSpuId 最后一个商品 SPU 编号 + * @param limit 数量 * @return 商品 SPU 编号数组 */ - CommonResult> listProductSpuIds(Integer limit, Integer lastSpuId); + CommonResult> listProductSpuIds(Integer lastSpuId, Integer limit); } diff --git a/product-service-project/product-service-app/src/main/java/cn/iocoder/mall/productservice/dal/mysql/mapper/spu/ProductSpuMapper.java b/product-service-project/product-service-app/src/main/java/cn/iocoder/mall/productservice/dal/mysql/mapper/spu/ProductSpuMapper.java index 86e08cd4b..c2b9a84d9 100644 --- a/product-service-project/product-service-app/src/main/java/cn/iocoder/mall/productservice/dal/mysql/mapper/spu/ProductSpuMapper.java +++ b/product-service-project/product-service-app/src/main/java/cn/iocoder/mall/productservice/dal/mysql/mapper/spu/ProductSpuMapper.java @@ -8,6 +8,8 @@ import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import org.springframework.stereotype.Repository; +import java.util.List; + @Repository public interface ProductSpuMapper extends BaseMapper { @@ -25,4 +27,9 @@ public interface ProductSpuMapper extends BaseMapper { return selectPage(new Page<>(pageBO.getPageNo(), pageBO.getPageSize()), query); } + default List selectListByIdGt(Integer id, Integer limit) { + return selectList(new QueryWrapperX().gtIfPresent("id", id) + .orderByAsc("id").last("LIMIT " + limit)); + } + } diff --git a/product-service-project/product-service-app/src/main/java/cn/iocoder/mall/productservice/manager/spu/ProductSpuManager.java b/product-service-project/product-service-app/src/main/java/cn/iocoder/mall/productservice/manager/spu/ProductSpuManager.java index 34fc1d6a2..967ce2cd4 100644 --- a/product-service-project/product-service-app/src/main/java/cn/iocoder/mall/productservice/manager/spu/ProductSpuManager.java +++ b/product-service-project/product-service-app/src/main/java/cn/iocoder/mall/productservice/manager/spu/ProductSpuManager.java @@ -165,12 +165,12 @@ public class ProductSpuManager { /** * 顺序获得商品 SPU 编号数组 * - * @param limit 数量 * @param lastSpuId 最后一个商品 SPU 编号 + * @param limit 数量 * @return 商品 SPU 编号数组 */ - public List listProductSpuIds(Integer limit, Integer lastSpuId) { - return productAttrService.listProductSpuIds(limit, lastSpuId); + public List listProductSpuIds(Integer lastSpuId, Integer limit) { + return productSpuService.listProductSpuIds(lastSpuId, limit); } private List checkProductAttr(List skuBOs) { diff --git a/product-service-project/product-service-app/src/main/java/cn/iocoder/mall/productservice/rpc/spu/ProductSpuRpcImpl.java b/product-service-project/product-service-app/src/main/java/cn/iocoder/mall/productservice/rpc/spu/ProductSpuRpcImpl.java index 71e09ec56..8ff164979 100644 --- a/product-service-project/product-service-app/src/main/java/cn/iocoder/mall/productservice/rpc/spu/ProductSpuRpcImpl.java +++ b/product-service-project/product-service-app/src/main/java/cn/iocoder/mall/productservice/rpc/spu/ProductSpuRpcImpl.java @@ -50,8 +50,8 @@ public class ProductSpuRpcImpl implements ProductSpuRpc { } @Override - public CommonResult> listProductSpuIds(Integer limit, Integer lastSpuId) { - return success(productSpuManager.listProductSpuIds(limit, lastSpuId)); + public CommonResult> listProductSpuIds(Integer lastSpuId, Integer limit) { + return success(productSpuManager.listProductSpuIds(lastSpuId, limit)); } } diff --git a/product-service-project/product-service-app/src/main/java/cn/iocoder/mall/productservice/service/attr/ProductAttrService.java b/product-service-project/product-service-app/src/main/java/cn/iocoder/mall/productservice/service/attr/ProductAttrService.java index ccb3345bd..517fa257c 100644 --- a/product-service-project/product-service-app/src/main/java/cn/iocoder/mall/productservice/service/attr/ProductAttrService.java +++ b/product-service-project/product-service-app/src/main/java/cn/iocoder/mall/productservice/service/attr/ProductAttrService.java @@ -208,18 +208,4 @@ public class ProductAttrService { return ProductAttrConvert.INSTANCE.convertList03(productAttrValueDOs); } - /** - * 顺序获得商品 SPU 编号数组 - * - * 一般情况下,该接口我们用于提供顺序的 SPU 编号数组,以便调用方进一步根据自己需要获取商品信息 - * 例如说,搜索服务会不断获取商品编号,重建该商品编号的索引 - * - * @param limit 数量 - * @param lastSpuId 最后一个商品 SPU 编号 - * @return 商品 SPU 编号数组 - */ - public List listProductSpuIds(Integer limit, Integer lastSpuId) { - return null; - } - } diff --git a/product-service-project/product-service-app/src/main/java/cn/iocoder/mall/productservice/service/spu/ProductSpuService.java b/product-service-project/product-service-app/src/main/java/cn/iocoder/mall/productservice/service/spu/ProductSpuService.java index 773e5a9d3..bcd10b75d 100644 --- a/product-service-project/product-service-app/src/main/java/cn/iocoder/mall/productservice/service/spu/ProductSpuService.java +++ b/product-service-project/product-service-app/src/main/java/cn/iocoder/mall/productservice/service/spu/ProductSpuService.java @@ -1,6 +1,7 @@ package cn.iocoder.mall.productservice.service.spu; import cn.iocoder.common.framework.exception.util.ServiceExceptionUtil; +import cn.iocoder.common.framework.util.CollectionUtils; import cn.iocoder.common.framework.vo.PageResult; import cn.iocoder.mall.productservice.convert.spu.ProductSpuConvert; import cn.iocoder.mall.productservice.dal.mysql.dataobject.spu.ProductSpuDO; @@ -91,4 +92,18 @@ public class ProductSpuService { return ProductSpuConvert.INSTANCE.convertPage(productSpuDOPage); } + /** + * 顺序获得商品 SPU 编号数组 + * + * 一般情况下,该接口我们用于提供顺序的 SPU 编号数组,以便调用方进一步根据自己需要获取商品信息 + * 例如说,搜索服务会不断获取商品编号,重建该商品编号的索引 + * + * @param lastSpuId 最后一个商品 SPU 编号 + * @param limit 数量 + * @return 商品 SPU 编号数组 + */ + public List listProductSpuIds(Integer lastSpuId, Integer limit) { + return CollectionUtils.convertList(productSpuMapper.selectListByIdGt(lastSpuId, limit), ProductSpuDO::getId); + } + } diff --git a/product/product-service-impl/src/main/java/cn/iocoder/mall/product/dao/ProductSpuMapper.java b/product/product-service-impl/src/main/java/cn/iocoder/mall/product/dao/ProductSpuMapper.java deleted file mode 100644 index 9341be8a3..000000000 --- a/product/product-service-impl/src/main/java/cn/iocoder/mall/product/dao/ProductSpuMapper.java +++ /dev/null @@ -1,23 +0,0 @@ -package cn.iocoder.mall.product.dao; - -import cn.iocoder.mall.product.dataobject.ProductSpuDO; -import org.apache.ibatis.annotations.Param; -import org.springframework.stereotype.Repository; - -import java.util.Collection; -import java.util.List; - -@Repository -public interface ProductSpuMapper { - - /** - * 获得大于 id 的商品编号数组 - * - * @param id 商品编号 - * @param limit 数量 - * @return 商品编号数组 - */ - List selectIdListByIdGt(@Param("id") Integer id, - @Param("limit") Integer limit); - -} diff --git a/product/product-service-impl/src/main/resources/mapper/ProductSpuMapper.xml b/product/product-service-impl/src/main/resources/mapper/ProductSpuMapper.xml deleted file mode 100644 index 16ea54419..000000000 --- a/product/product-service-impl/src/main/resources/mapper/ProductSpuMapper.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - id, name, sell_point, description, cid, - pic_urls, visible, sort, price, quantity, - create_time - - - - - diff --git a/search-service-project/search-service-api/src/main/java/cn/iocoder/mall/searchservice/enums/package-info.java b/search-service-project/search-service-api/src/main/java/cn/iocoder/mall/searchservice/enums/package-info.java index d32f814d0..8651e340d 100644 --- a/search-service-project/search-service-api/src/main/java/cn/iocoder/mall/searchservice/enums/package-info.java +++ b/search-service-project/search-service-api/src/main/java/cn/iocoder/mall/searchservice/enums/package-info.java @@ -1 +1,4 @@ +/** + * 占位,避免包折叠 + */ package cn.iocoder.mall.searchservice.enums; diff --git a/search-service-project/search-service-api/src/main/java/cn/iocoder/mall/searchservice/enums/product/SearchProductConditionFieldEnum.java b/search-service-project/search-service-api/src/main/java/cn/iocoder/mall/searchservice/enums/product/SearchProductConditionFieldEnum.java new file mode 100644 index 000000000..eaed8cb6a --- /dev/null +++ b/search-service-project/search-service-api/src/main/java/cn/iocoder/mall/searchservice/enums/product/SearchProductConditionFieldEnum.java @@ -0,0 +1,19 @@ +package cn.iocoder.mall.searchservice.enums.product; + +/** + * 搜索商品条件的字段枚举 + */ +public enum SearchProductConditionFieldEnum { + + CATEGORY("category"); + + /** + * 字段 + */ + private final String field; + + SearchProductConditionFieldEnum(String field) { + this.field = field; + } + +} diff --git a/search-service-project/search-service-api/src/main/java/cn/iocoder/mall/searchservice/rpc/package-info.java b/search-service-project/search-service-api/src/main/java/cn/iocoder/mall/searchservice/rpc/package-info.java index 1daa4587e..193599110 100644 --- a/search-service-project/search-service-api/src/main/java/cn/iocoder/mall/searchservice/rpc/package-info.java +++ b/search-service-project/search-service-api/src/main/java/cn/iocoder/mall/searchservice/rpc/package-info.java @@ -1 +1,4 @@ +/** + * 占位,避免包折叠 + */ package cn.iocoder.mall.searchservice.rpc; diff --git a/search-service-project/search-service-app/pom.xml b/search-service-project/search-service-app/pom.xml index c9ffabefb..547724843 100644 --- a/search-service-project/search-service-app/pom.xml +++ b/search-service-project/search-service-app/pom.xml @@ -57,6 +57,13 @@ spring-boot-starter-data-elasticsearch + + + org.springframework.boot + spring-boot-starter-test + test + + org.springframework.boot diff --git a/search-service-project/search-service-app/src/main/java/cn/iocoder/mall/searchservice/convert/product/SearchProductConvert.java b/search-service-project/search-service-app/src/main/java/cn/iocoder/mall/searchservice/convert/product/SearchProductConvert.java index d0336c9f7..52a9461ca 100644 --- a/search-service-project/search-service-app/src/main/java/cn/iocoder/mall/searchservice/convert/product/SearchProductConvert.java +++ b/search-service-project/search-service-app/src/main/java/cn/iocoder/mall/searchservice/convert/product/SearchProductConvert.java @@ -11,6 +11,8 @@ import org.mapstruct.Mapping; import org.mapstruct.factory.Mappers; import org.springframework.data.domain.Page; +import java.util.List; + @Mapper public interface SearchProductConvert { @@ -30,8 +32,11 @@ public interface SearchProductConvert { ESProductDO convert(SearchProductSaveBO bean); - @Mapping(source = "content", target = "list") - @Mapping(source = "getTotalElements", target = "total") - PageResult convert(Page searchPage); + List convertList(List list); + + default PageResult convertPage(Page searchPage) { + return new PageResult().setList(convertList(searchPage.getContent())) + .setTotal(searchPage.getTotalElements()); + } } diff --git a/search-service-project/search-service-app/src/main/java/cn/iocoder/mall/searchservice/manager/product/SearchProductManager.java b/search-service-project/search-service-app/src/main/java/cn/iocoder/mall/searchservice/manager/product/SearchProductManager.java index a20d4f33b..7ef0f62e4 100644 --- a/search-service-project/search-service-app/src/main/java/cn/iocoder/mall/searchservice/manager/product/SearchProductManager.java +++ b/search-service-project/search-service-app/src/main/java/cn/iocoder/mall/searchservice/manager/product/SearchProductManager.java @@ -24,6 +24,8 @@ import java.util.List; @Slf4j public class SearchProductManager { + private static final Integer REBUILD_FETCH_PER_SIZE = 100; + @DubboReference(version = "${dubbo.consumer.ProductSpuRpc.version}") private ProductSpuRpc productSpuRpc; @DubboReference(version = "${dubbo.consumer.ProductSkuRpc.version}") @@ -37,6 +39,40 @@ public class SearchProductManager { @Autowired private SearchProductService searchProductService; + /** + * 重建所有商品的 ES 索引 + * + * @return 重建数量 + */ + public Integer rebuild() { + // TODO 芋艿,因为目前商品比较少,所以写的很粗暴。等未来重构 + Integer lastId = null; + int rebuildCounts = 0; + while (true) { + // 从商品服务,增量获取商品列表编号 + CommonResult> listProductSpuIdsResult = productSpuRpc.listProductSpuIds(lastId, REBUILD_FETCH_PER_SIZE); + listProductSpuIdsResult.checkError(); + List spuIds = listProductSpuIdsResult.getData(); + // 逐个重建索引到 ES 中 + spuIds.forEach(this::saveProduct); + // 设置新的 lastId ,或者结束 + rebuildCounts += listProductSpuIdsResult.getData().size(); + if (spuIds.size() < REBUILD_FETCH_PER_SIZE) { + break; + } else { + lastId = spuIds.get(spuIds.size() - 1); + } + } + // 返回成功 + return rebuildCounts; + } + + /** + * 重建指定商品的 ES 索引 + * + * @param id 商品 SPU 编号 + * @return 是否重建成功 + */ public Boolean saveProduct(Integer id) { // 获得商品 SPU CommonResult productSpuResult = productSpuRpc.getProductSpu(id); diff --git a/search-service-project/search-service-app/src/main/java/cn/iocoder/mall/searchservice/mq/consumer/PayTransactionPaySuccessConsumer.java b/search-service-project/search-service-app/src/main/java/cn/iocoder/mall/searchservice/mq/consumer/ProductUpdateConsumer.java similarity index 86% rename from search-service-project/search-service-app/src/main/java/cn/iocoder/mall/searchservice/mq/consumer/PayTransactionPaySuccessConsumer.java rename to search-service-project/search-service-app/src/main/java/cn/iocoder/mall/searchservice/mq/consumer/ProductUpdateConsumer.java index 0ec04e640..03391fca4 100644 --- a/search-service-project/search-service-app/src/main/java/cn/iocoder/mall/searchservice/mq/consumer/PayTransactionPaySuccessConsumer.java +++ b/search-service-project/search-service-app/src/main/java/cn/iocoder/mall/searchservice/mq/consumer/ProductUpdateConsumer.java @@ -8,12 +8,15 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.util.Assert; +/** + * 商品更新 Topic 的消费者,重建对应的商品的 ES 索引 + */ @Service @RocketMQMessageListener( topic = ProductUpdateMessage.TOPIC, consumerGroup = "${spring.application.name}-consumer-group-" + ProductUpdateMessage.TOPIC ) -public class PayTransactionPaySuccessConsumer implements RocketMQListener { +public class ProductUpdateConsumer implements RocketMQListener { @Autowired private SearchProductManager productSearchManager; diff --git a/search-service-project/search-service-app/src/main/java/cn/iocoder/mall/searchservice/service/package-info.java b/search-service-project/search-service-app/src/main/java/cn/iocoder/mall/searchservice/service/package-info.java index edcc8abe4..66a4e86ab 100644 --- a/search-service-project/search-service-app/src/main/java/cn/iocoder/mall/searchservice/service/package-info.java +++ b/search-service-project/search-service-app/src/main/java/cn/iocoder/mall/searchservice/service/package-info.java @@ -1,4 +1,4 @@ /** - * 占位 + * 占位,避免包折叠 */ package cn.iocoder.mall.searchservice.service; diff --git a/search-service-project/search-service-app/src/main/java/cn/iocoder/mall/searchservice/service/product/SearchProductService.java b/search-service-project/search-service-app/src/main/java/cn/iocoder/mall/searchservice/service/product/SearchProductService.java index e859d16c2..8c9f71968 100644 --- a/search-service-project/search-service-app/src/main/java/cn/iocoder/mall/searchservice/service/product/SearchProductService.java +++ b/search-service-project/search-service-app/src/main/java/cn/iocoder/mall/searchservice/service/product/SearchProductService.java @@ -7,6 +7,7 @@ import cn.iocoder.common.framework.vo.SortingField; import cn.iocoder.mall.searchservice.convert.product.SearchProductConvert; import cn.iocoder.mall.searchservice.dal.es.dataobject.ESProductDO; import cn.iocoder.mall.searchservice.dal.es.repository.ESProductRepository; +import cn.iocoder.mall.searchservice.enums.product.SearchProductConditionFieldEnum; import cn.iocoder.mall.searchservice.enums.product.SearchProductPageQuerySortFieldEnum; import cn.iocoder.mall.searchservice.service.product.bo.SearchProductBO; import cn.iocoder.mall.searchservice.service.product.bo.SearchProductConditionBO; @@ -47,7 +48,7 @@ public class SearchProductService { Page searchPage = productRepository.search(pageQueryBO.getCid(), pageQueryBO.getKeyword(), pageQueryBO.getPageNo(), pageQueryBO.getPageSize(), pageQueryBO.getSorts()); // 转换结果 - return SearchProductConvert.INSTANCE.convert(searchPage); + return SearchProductConvert.INSTANCE.convertPage(searchPage); } private void checkSortFieldInvalid(List sorts) { @@ -74,11 +75,11 @@ public class SearchProductService { * 在我们搜索商品时,需要获得关键字可选择的分类、品牌等等搜索条件,方便用户进一步检索 * * @param keyword 关键字 - * @param fields 需要返回的搜索条件。目前可传入的参数为 + * @param fields 需要返回的搜索条件{@link SearchProductConditionFieldEnum}。目前可传入的参数为 * 1. category :商品分类,会返回商品分类编号 * @return 搜索条件 */ - public SearchProductConditionBO getSearchCondition(String keyword, Collection fields) { + public SearchProductConditionBO getSearchProductCondition(String keyword, Collection fields) { // 创建 ES 搜索条件 NativeSearchQueryBuilder nativeSearchQueryBuilder = new NativeSearchQueryBuilder(); // 筛选 diff --git a/search-service-project/search-service-app/src/main/resources/application-local.yaml b/search-service-project/search-service-app/src/main/resources/application-local.yaml index 9671ef1d8..9c125c50b 100644 --- a/search-service-project/search-service-app/src/main/resources/application-local.yaml +++ b/search-service-project/search-service-app/src/main/resources/application-local.yaml @@ -16,3 +16,6 @@ dubbo: # Dubbo 服务提供者的配置 provider: tag: ${DUBBO_TAG} # Dubbo 路由分组 + # Dubbo 服务消费者的配置 + consumer: + tag: ${DUBBO_TAG} # Dubbo 路由分组 diff --git a/search-service-project/search-service-app/src/test/java/cn/iocoder/mall/searchservice/manager/package-info.java b/search-service-project/search-service-app/src/test/java/cn/iocoder/mall/searchservice/manager/package-info.java new file mode 100644 index 000000000..ff9569ee8 --- /dev/null +++ b/search-service-project/search-service-app/src/test/java/cn/iocoder/mall/searchservice/manager/package-info.java @@ -0,0 +1,4 @@ +/** + * 占位 + */ +package cn.iocoder.mall.searchservice.manager; diff --git a/search/search-service-impl/src/test/java/cn/iocoder/mall/search/biz/service/ProductSearchServiceImplTest.java b/search-service-project/search-service-app/src/test/java/cn/iocoder/mall/searchservice/manager/product/SearchProductManagerTest.java similarity index 56% rename from search/search-service-impl/src/test/java/cn/iocoder/mall/search/biz/service/ProductSearchServiceImplTest.java rename to search-service-project/search-service-app/src/test/java/cn/iocoder/mall/searchservice/manager/product/SearchProductManagerTest.java index 06ffc3b2f..287548d56 100644 --- a/search/search-service-impl/src/test/java/cn/iocoder/mall/search/biz/service/ProductSearchServiceImplTest.java +++ b/search-service-project/search-service-app/src/test/java/cn/iocoder/mall/searchservice/manager/product/SearchProductManagerTest.java @@ -1,31 +1,35 @@ -package cn.iocoder.mall.search.biz.api; +package cn.iocoder.mall.searchservice.manager.product; -import cn.iocoder.mall.search.biz.dao.ProductRepository; +import cn.iocoder.mall.searchservice.dal.es.repository.ESProductRepository; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +/** + * {@link SearchProductManager} 的测试类,目前是集成测试类 + */ @RunWith(SpringJUnit4ClassRunner.class) @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE) -public class ProductSearchServiceImplTest { - - @Autowired - private ProductSearchServiceImpl productSearchService; - @Autowired - private ProductRepository productRepository; +public class SearchProductManagerTest { static { System.setProperty("es.set.netty.runtime.available.processors", "false"); } + @Autowired + private SearchProductManager searchProductManager; + + @Autowired + private ESProductRepository esProductRepository; + @Test public void testRebuild() { - int counts = productSearchService.rebuild(); + int counts = searchProductManager.rebuild(); System.out.println("重建数量:" + counts); - System.out.println(productRepository.count()); + System.out.println(esProductRepository.count()); } } diff --git a/search-service-project/search-service-app/src/test/java/cn/iocoder/mall/searchservice/service/package-info.java b/search-service-project/search-service-app/src/test/java/cn/iocoder/mall/searchservice/service/package-info.java new file mode 100644 index 000000000..edcc8abe4 --- /dev/null +++ b/search-service-project/search-service-app/src/test/java/cn/iocoder/mall/searchservice/service/package-info.java @@ -0,0 +1,4 @@ +/** + * 占位 + */ +package cn.iocoder.mall.searchservice.service; diff --git a/search-service-project/search-service-app/src/test/java/cn/iocoder/mall/searchservice/service/product/SearchProductServiceTest.java b/search-service-project/search-service-app/src/test/java/cn/iocoder/mall/searchservice/service/product/SearchProductServiceTest.java new file mode 100644 index 000000000..98d9597d4 --- /dev/null +++ b/search-service-project/search-service-app/src/test/java/cn/iocoder/mall/searchservice/service/product/SearchProductServiceTest.java @@ -0,0 +1,32 @@ +package cn.iocoder.mall.searchservice.service.product; + +import cn.iocoder.mall.searchservice.service.product.bo.SearchProductConditionBO; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +import java.util.Collections; + +/** + * {@link SearchProductService} 的测试类,目前是集成测试类 + */ +@RunWith(SpringJUnit4ClassRunner.class) +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE) +public class SearchProductServiceTest { + + static { + System.setProperty("es.set.netty.runtime.available.processors", "false"); + } + + @Autowired + private SearchProductService searchProductService; + + @Test + public void testGetSearchCondition() { + SearchProductConditionBO conditionBO = searchProductService.getSearchProductCondition("商品", Collections.singletonList("category")); + System.out.println(conditionBO); + } + +} diff --git a/search/search-biz-api/pom.xml b/search/search-biz-api/pom.xml deleted file mode 100644 index b8d93c0db..000000000 --- a/search/search-biz-api/pom.xml +++ /dev/null @@ -1,23 +0,0 @@ - - - - search - cn.iocoder.mall - 1.0-SNAPSHOT - - 4.0.0 - - search-biz-api - - - - - cn.iocoder.mall - common-framework - 1.0-SNAPSHOT - - - - diff --git a/search/search-biz/pom.xml b/search/search-biz/pom.xml deleted file mode 100644 index 7a6c27c57..000000000 --- a/search/search-biz/pom.xml +++ /dev/null @@ -1,110 +0,0 @@ - - - - search - cn.iocoder.mall - 1.0-SNAPSHOT - - 4.0.0 - - search-biz - - - - - cn.iocoder.mall - mall-spring-boot - 1.0-SNAPSHOT - - - - search-biz-api - cn.iocoder.mall - 1.0-SNAPSHOT - - - - cn.iocoder.mall - product-rpc-api - 1.0-SNAPSHOT - - - - org.springframework.boot - spring-boot-starter-data-elasticsearch - - - - - com.alibaba.cloud - spring-cloud-starter-dubbo - - - - - com.alibaba.cloud - spring-cloud-starter-alibaba-nacos-discovery - - - - - com.alibaba.cloud - spring-cloud-starter-stream-rocketmq - - - - - com.google.guava - guava - - - - org.mapstruct - mapstruct - - - org.mapstruct - mapstruct-jdk8 - - - org.projectlombok - lombok - - - - com.alibaba - fastjson - - - - - org.springframework.boot - spring-boot-starter-test - test - - - org.springframework.boot - spring-boot-starter-web - - - - - com.github.vanroy - spring-boot-starter-data-jest - - - - - - - - - org.apache.maven.plugins - maven-compiler-plugin - - - - - diff --git a/search/search-biz/src/main/java/cn/iocoder/mall/search/biz/service/ProductSearchService.java b/search/search-biz/src/main/java/cn/iocoder/mall/search/biz/service/ProductSearchService.java deleted file mode 100644 index 50101d746..000000000 --- a/search/search-biz/src/main/java/cn/iocoder/mall/search/biz/service/ProductSearchService.java +++ /dev/null @@ -1,20 +0,0 @@ -package cn.iocoder.mall.search.biz.service; - - -public interface ProductSearchService { - - Integer rebuild(); - - /** - * 构建商品的搜索索引 - * - * @param id 商品编号 - * @return 构建结果 - */ - Boolean save(Integer id); -// -// ProductPageBO getSearchPage(ProductSearchPageDTO searchPageDTO); -// -// ProductConditionBO getSearchCondition(ProductConditionDTO conditionDTO); - -} diff --git a/search/search-biz/src/main/java/cn/iocoder/mall/search/biz/service/ProductSearchServiceImpl.java b/search/search-biz/src/main/java/cn/iocoder/mall/search/biz/service/ProductSearchServiceImpl.java deleted file mode 100644 index 88c938eaa..000000000 --- a/search/search-biz/src/main/java/cn/iocoder/mall/search/biz/service/ProductSearchServiceImpl.java +++ /dev/null @@ -1,54 +0,0 @@ -package cn.iocoder.mall.search.biz.service; - -import cn.iocoder.common.framework.util.CollectionUtil; -import cn.iocoder.common.framework.vo.SortingField; -import cn.iocoder.mall.search.biz.dao.ProductRepository; -import cn.iocoder.mall.search.biz.dto.ProductSearchPageDTO; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.elasticsearch.core.ElasticsearchTemplate; -import org.springframework.stereotype.Service; -import org.springframework.util.Assert; - -import java.util.List; - -@Service -@org.apache.dubbo.config.annotation.Service(validation = "true", version = "${dubbo.provider.ProductSearchService.version}") -public class ProductSearchServiceImpl implements ProductSearchService { - - private static final Integer REBUILD_FETCH_PER_SIZE = 100; - - @Autowired - private ProductRepository productRepository; - - -// @Reference(validation = "true", version = "${dubbo.consumer.ProductSpuService.version}") -// private ProductSpuService productSpuService; -// @Reference(validation = "true", version = "${dubbo.consumer.ProductCategoryService.version}") -// private ProductCategoryService productCategoryService; -// @Reference(validation = "true", version = "${dubbo.consumer.CartService.version}") -// private CartService cartService; - -// @Override -// public Integer rebuild() { -// // TODO 芋艿,因为目前商品比较少,所以写的很粗暴。等未来重构 -// Integer lastId = null; -// int rebuildCounts = 0; -// while (true) { -// List spus = productSpuService.getProductSpuDetailListForSync(lastId, REBUILD_FETCH_PER_SIZE); -// rebuildCounts += spus.size(); -// // 存储到 ES 中 -// List products = spus.stream().map(this::convert).collect(Collectors.toList()); -// productRepository.saveAll(products); -// // 设置新的 lastId ,或者结束 -// if (spus.size() < REBUILD_FETCH_PER_SIZE) { -// break; -// } else { -// lastId = spus.get(spus.size() - 1).getId(); -// } -// } -// // 返回成功 -// return rebuildCounts; -// } -// - -} diff --git a/search/search-biz/src/main/resources/biz.properties b/search/search-biz/src/main/resources/biz.properties deleted file mode 100644 index 197907aff..000000000 --- a/search/search-biz/src/main/resources/biz.properties +++ /dev/null @@ -1,8 +0,0 @@ -##################### 业务模块 ##################### -## OAuth2CodeService -modules.oauth2-code-service.access-token-expire-time-millis = 2880000 -modules.oauth2-code-service.refresh-token-expire-time-millis = 43200000 -## OAuth2MobileCodeService -modules.oauth2-mobile-code-service.code-expire-time-millis = 600000 -modules.oauth2-mobile-code-service.send-maximum-quantity-per-day = 10 -modules.oauth2-mobile-code-service.send-frequency = 60000 diff --git a/search/search-biz/src/main/resources/biz.yaml b/search/search-biz/src/main/resources/biz.yaml deleted file mode 100644 index fc41b8a93..000000000 --- a/search/search-biz/src/main/resources/biz.yaml +++ /dev/null @@ -1,7 +0,0 @@ -spring: - data: - # Jest 配置项 - jest: - uri: http://127.0.0.1:9200 - - diff --git a/search/search-rest/src/main/resources/rest.yaml b/search/search-rest/src/main/resources/rest.yaml deleted file mode 100644 index 778308fcf..000000000 --- a/search/search-rest/src/main/resources/rest.yaml +++ /dev/null @@ -1,12 +0,0 @@ -# 服务器的配置项 -server: - port: 18099 - servlet: - context-path: /search-api/ - -# Swagger 配置项 -swagger: - title: 商品查询子系统 - description: 商品查询子系统 - version: 1.0.0 - base-package: cn.iocoder.mall.search.rest.controller diff --git a/search/search-rpc/pom.xml b/search/search-rpc/pom.xml deleted file mode 100644 index d46e9e2f4..000000000 --- a/search/search-rpc/pom.xml +++ /dev/null @@ -1,48 +0,0 @@ - - - - search - cn.iocoder.mall - 1.0-SNAPSHOT - - 4.0.0 - - search-rpc - - - - - - cn.iocoder.mall - search-rpc-api - 1.0-SNAPSHOT - - - - cn.iocoder.mall - search-biz - 1.0-SNAPSHOT - - - - - com.alibaba.cloud - spring-cloud-starter-dubbo - - - - - com.alibaba.cloud - spring-cloud-starter-alibaba-nacos-discovery - - - - - com.github.vanroy - spring-boot-starter-data-jest - - - - \ No newline at end of file diff --git a/search/search-rpc/src/main/java/cn/iocoder/mall/search/biz/convert/ProductSearchConvert.java b/search/search-rpc/src/main/java/cn/iocoder/mall/search/biz/convert/ProductSearchConvert.java deleted file mode 100644 index b83142908..000000000 --- a/search/search-rpc/src/main/java/cn/iocoder/mall/search/biz/convert/ProductSearchConvert.java +++ /dev/null @@ -1,35 +0,0 @@ -package cn.iocoder.mall.search.biz.convert; - -import cn.iocoder.mall.search.biz.bo.ProductBO; -import cn.iocoder.mall.search.biz.dataobject.ESProductDO; -import org.mapstruct.Mapper; -import org.mapstruct.factory.Mappers; - -import java.util.List; - -@Mapper -public interface ProductSearchConvert { - - ProductSearchConvert INSTANCE = Mappers.getMapper(ProductSearchConvert.class); - -// @Mappings({}) -// ESProductDO convert(ProductSpuDetailBO spu); - -// @Mappings({}) -// default ESProductDO convert(ProductSpuDetailBO spu, CalcSkuPriceBO calcSkuPrice) { -// // Spu 的基础数据 -// ESProductDO product = this.convert(spu); -// product.setOriginalPrice(calcSkuPrice.getOriginalPrice()).setBuyPrice(calcSkuPrice.getBuyPrice()); -// // 设置促销活动相关字段 -// if (calcSkuPrice.getTimeLimitedDiscount() != null) { -// PromotionActivityBO activity = calcSkuPrice.getTimeLimitedDiscount(); -// product.setPromotionActivityId(activity.getId()).setPromotionActivityTitle(activity.getTitle()) -// .setPromotionActivityType(activity.getActivityType()); -// } -// // 返回 -// return product; -// } - - List convert(List list); - -} diff --git a/search/search-rpc/src/main/java/cn/iocoder/mall/search/biz/rpc/user/ProductSearchRPCImpl.java b/search/search-rpc/src/main/java/cn/iocoder/mall/search/biz/rpc/user/ProductSearchRPCImpl.java deleted file mode 100644 index 129068bdf..000000000 --- a/search/search-rpc/src/main/java/cn/iocoder/mall/search/biz/rpc/user/ProductSearchRPCImpl.java +++ /dev/null @@ -1,29 +0,0 @@ -package cn.iocoder.mall.search.biz.rpc.user; - -import cn.iocoder.common.framework.vo.CommonResult; -import cn.iocoder.mall.search.biz.api.user.ProductSearchRPC; -import cn.iocoder.mall.search.biz.service.ProductSearchService; -import org.apache.dubbo.config.annotation.Service; -import org.springframework.beans.factory.annotation.Autowired; - - -@Service(validation = "true", version = "${dubbo.provider.ProductSearchRpc.version}") -public class ProductSearchRPCImpl implements ProductSearchRPC { - - @Autowired - private ProductSearchService productSearchService; - - @Override - public CommonResult rebuild() { - return null; - } - - @Override - public CommonResult save(Integer id){ -// ProductSpuDetailBO productSpuDetail = productSpuService.getProductSpuDetail(spuId); -// return ProductSpuConvert.INSTANCE.convertDetail(productSpuDetail); - return CommonResult.success(true); - } - - -} diff --git a/search/search-rpc/src/main/resources/rpc-local.yaml b/search/search-rpc/src/main/resources/rpc-local.yaml deleted file mode 100644 index e056170af..000000000 --- a/search/search-rpc/src/main/resources/rpc-local.yaml +++ /dev/null @@ -1,14 +0,0 @@ -spring: - # Spring Cloud 配置项 - cloud: - nacos: - # Spring Cloud Nacos Discovery 配置项 - discovery: - server-addr: s1.iocoder.cn:8848 # Nacos 服务器地址 - namespace: local # Nacos 命名空间 - -# Dubbo 配置项 -dubbo: - # Dubbo 注册中心 - registry: - address: spring-cloud://s1.iocoder.cn:8848 # 指定 Dubbo 服务注册中心的地址 diff --git a/search/search-rpc/src/main/resources/rpc-test.yaml b/search/search-rpc/src/main/resources/rpc-test.yaml deleted file mode 100644 index d3d0e9e69..000000000 --- a/search/search-rpc/src/main/resources/rpc-test.yaml +++ /dev/null @@ -1,14 +0,0 @@ -spring: - # Spring Cloud 配置项 - cloud: - nacos: - # Spring Cloud Nacos Discovery 配置项 - discovery: - server-addr: s1.iocoder.cn:8848 # Nacos 服务器地址 - namespace: test # Nacos 命名空间 - -# Dubbo 配置项 -dubbo: - # Dubbo 注册中心 - registry: - address: spring-cloud://s1.iocoder.cn:8848 # 指定 Dubbo 服务注册中心的地址 diff --git a/search/search-rpc/src/main/resources/rpc.yaml b/search/search-rpc/src/main/resources/rpc.yaml deleted file mode 100644 index 398fbf430..000000000 --- a/search/search-rpc/src/main/resources/rpc.yaml +++ /dev/null @@ -1,22 +0,0 @@ -# Dubbo 配置项 -dubbo: - # Spring Cloud Alibaba Dubbo 专属配置 - cloud: - subscribed-services: 'search-application' # 设置订阅的应用列表,默认为 * 订阅所有应用 - # Dubbo 提供者的协议 - protocol: - name: dubbo - port: -1 - # Dubbo 提供服务的扫描基础包 - scan: - base-packages: cn.iocoder.mall.search.rpc.rpc - # Dubbo 服务提供者的配置 - provider: -# filter: -exception -# ProductSpuService: -# version: 1.0.0 - - # Dubbo 服务消费者的配置 - consumer: -# ProductSpuService: -# version: 1.0.0 diff --git a/search/search-service-api/src/main/java/cn/iocoder/mall/search/api/ProductSearchService.java b/search/search-service-api/src/main/java/cn/iocoder/mall/search/api/ProductSearchService.java deleted file mode 100644 index 441235779..000000000 --- a/search/search-service-api/src/main/java/cn/iocoder/mall/search/api/ProductSearchService.java +++ /dev/null @@ -1,16 +0,0 @@ -package cn.iocoder.mall.search.biz; - -import cn.iocoder.mall.search.biz.bo.ProductConditionBO; -import cn.iocoder.mall.search.biz.bo.ProductPageBO; -import cn.iocoder.mall.search.biz.dto.ProductConditionDTO; -import cn.iocoder.mall.search.biz.dto.ProductSearchPageDTO; - -public interface ProductSearchService { - - Integer rebuild(); - - ProductPageBO getSearchPage(ProductSearchPageDTO searchPageDTO); - - ProductConditionBO getSearchCondition(ProductConditionDTO conditionDTO); - -} diff --git a/search/search-service-impl/pom.xml b/search/search-service-impl/pom.xml deleted file mode 100644 index 2cf391aed..000000000 --- a/search/search-service-impl/pom.xml +++ /dev/null @@ -1,89 +0,0 @@ - - - - search - cn.iocoder.mall - 1.0-SNAPSHOT - - 4.0.0 - - search-service-impl - - - - - cn.iocoder.mall - mall-spring-boot - 1.0-SNAPSHOT - - - cn.iocoder.mall - search-service-api - 1.0-SNAPSHOT - - - cn.iocoder.mall - product-service-api - 1.0-SNAPSHOT - - - cn.iocoder.mall - order-service-api - 1.0-SNAPSHOT - - - - - org.springframework.boot - spring-boot-starter-data-elasticsearch - - - - - com.alibaba.cloud - spring-cloud-starter-dubbo - - - - - com.alibaba.cloud - spring-cloud-starter-alibaba-nacos-discovery - - - - - com.alibaba.cloud - spring-cloud-starter-stream-rocketmq - - - - - com.google.guava - guava - - - - - org.springframework.boot - spring-boot-starter-test - test - - - org.springframework.boot - spring-boot-starter-web - - - - - - - - org.apache.maven.plugins - maven-compiler-plugin - - - - - diff --git a/search/search-service-impl/src/main/java/cn/iocoder/mall/search/biz/convert/ProductSearchConvert.java b/search/search-service-impl/src/main/java/cn/iocoder/mall/search/biz/convert/ProductSearchConvert.java deleted file mode 100644 index 6a42e33ca..000000000 --- a/search/search-service-impl/src/main/java/cn/iocoder/mall/search/biz/convert/ProductSearchConvert.java +++ /dev/null @@ -1,39 +0,0 @@ -package cn.iocoder.mall.search.biz.convert; - -import cn.iocoder.mall.order.api.bo.CalcSkuPriceBO; -import cn.iocoder.mall.product.api.bo.ProductSpuDetailBO; -import cn.iocoder.mall.promotion.api.bo.PromotionActivityBO; -import cn.iocoder.mall.search.biz.bo.ProductBO; -import cn.iocoder.mall.search.biz.dataobject.ESProductDO; -import org.mapstruct.Mapper; -import org.mapstruct.Mappings; -import org.mapstruct.factory.Mappers; - -import java.util.List; - -@Mapper -public interface ProductSearchConvert { - - ProductSearchConvert INSTANCE = Mappers.getMapper(ProductSearchConvert.class); - - @Mappings({}) - ESProductDO convert(ProductSpuDetailBO spu); - - @Mappings({}) - default ESProductDO convert(ProductSpuDetailBO spu, CalcSkuPriceBO calcSkuPrice) { - // Spu 的基础数据 - ESProductDO product = this.convert(spu); - product.setOriginalPrice(calcSkuPrice.getOriginalPrice()).setBuyPrice(calcSkuPrice.getBuyPrice()); - // 设置促销活动相关字段 - if (calcSkuPrice.getTimeLimitedDiscount() != null) { - PromotionActivityBO activity = calcSkuPrice.getTimeLimitedDiscount(); - product.setPromotionActivityId(activity.getId()).setPromotionActivityTitle(activity.getTitle()) - .setPromotionActivityType(activity.getActivityType()); - } - // 返回 - return product; - } - - List convert(List list); - -} diff --git a/search/search-service-impl/src/main/java/cn/iocoder/mall/search/biz/service/ProductSearchServiceImpl.java b/search/search-service-impl/src/main/java/cn/iocoder/mall/search/biz/service/ProductSearchServiceImpl.java deleted file mode 100644 index 05fabd1cb..000000000 --- a/search/search-service-impl/src/main/java/cn/iocoder/mall/search/biz/service/ProductSearchServiceImpl.java +++ /dev/null @@ -1,113 +0,0 @@ -package cn.iocoder.mall.search.biz.api; - -import cn.iocoder.common.framework.util.CollectionUtil; -import cn.iocoder.common.framework.util.StringUtil; -import cn.iocoder.common.framework.vo.SortingField; -import cn.iocoder.mall.order.api.CartService; -import cn.iocoder.mall.order.api.bo.CalcSkuPriceBO; -import cn.iocoder.mall.product.api.ProductCategoryService; -import cn.iocoder.mall.product.api.ProductSpuService; -import cn.iocoder.mall.product.api.bo.ProductCategoryBO; -import cn.iocoder.mall.product.api.bo.ProductSpuDetailBO; -import cn.iocoder.mall.search.biz.ProductSearchService; -import cn.iocoder.mall.search.biz.bo.ProductConditionBO; -import cn.iocoder.mall.search.biz.bo.ProductPageBO; -import cn.iocoder.mall.search.biz.dto.ProductConditionDTO; -import cn.iocoder.mall.search.biz.dto.ProductSearchPageDTO; -import cn.iocoder.mall.search.biz.convert.ProductSearchConvert; -import cn.iocoder.mall.search.biz.dao.ProductRepository; -import cn.iocoder.mall.search.biz.dataobject.ESProductDO; -import org.apache.dubbo.config.annotation.Reference; -import org.elasticsearch.index.query.QueryBuilders; -import org.elasticsearch.search.aggregations.Aggregation; -import org.elasticsearch.search.aggregations.AggregationBuilders; -import org.elasticsearch.search.aggregations.bucket.terms.LongTerms; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.domain.Page; -import org.springframework.data.elasticsearch.core.ElasticsearchTemplate; -import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder; -import org.springframework.stereotype.Service; -import org.springframework.util.Assert; - -import java.util.ArrayList; -import java.util.Comparator; -import java.util.List; -import java.util.Map; -import java.util.stream.Collectors; - -@Service -@org.apache.dubbo.config.annotation.Service(validation = "true", version = "${dubbo.provider.ProductSearchService.version}") -public class ProductSearchServiceImpl implements ProductSearchService { - - private static final Integer REBUILD_FETCH_PER_SIZE = 100; - - @Autowired - private ProductRepository productRepository; - @Autowired - private ElasticsearchTemplate elasticsearchTemplate; // 因为需要使用到聚合操作,只好引入 ElasticsearchTemplate 。 - - @Override - public Integer rebuild() { - // TODO 芋艿,因为目前商品比较少,所以写的很粗暴。等未来重构 - Integer lastId = null; - int rebuildCounts = 0; - while (true) { - List spus = productSpuService.getProductSpuDetailListForSync(lastId, REBUILD_FETCH_PER_SIZE); - rebuildCounts += spus.size(); - // 存储到 ES 中 - List products = spus.stream().map(this::convert).collect(Collectors.toList()); - productRepository.saveAll(products); - // 设置新的 lastId ,或者结束 - if (spus.size() < REBUILD_FETCH_PER_SIZE) { - break; - } else { - lastId = spus.get(spus.size() - 1).getId(); - } - } - // 返回成功 - return rebuildCounts; - } - - @Override - public ProductConditionBO getSearchCondition(ProductConditionDTO conditionDTO) { - // 创建 ES 搜索条件 - NativeSearchQueryBuilder nativeSearchQueryBuilder = new NativeSearchQueryBuilder(); - // 筛选 - if (StringUtil.hasText(conditionDTO.getKeyword())) { // 如果有 keyword ,就去匹配 - nativeSearchQueryBuilder.withQuery(QueryBuilders.multiMatchQuery(conditionDTO.getKeyword(), - "name", "sellPoint", "categoryName")); - } else { - nativeSearchQueryBuilder.withQuery(QueryBuilders.matchAllQuery()); - } - // 聚合 - if (conditionDTO.getFields().contains(ProductConditionDTO.FIELD_CATEGORY)) { // 商品分类 - nativeSearchQueryBuilder.addAggregation(AggregationBuilders.terms("cids").field("cid")); - } - // 执行查询 - ProductConditionBO condition = elasticsearchTemplate.query(nativeSearchQueryBuilder.build(), response -> { - ProductConditionBO result = new ProductConditionBO(); - // categoryIds 聚合 - Aggregation categoryIdsAggregation = response.getAggregations().get("cids"); - if (categoryIdsAggregation != null) { - result.setCategories(new ArrayList<>()); - for (LongTerms.Bucket bucket : (((LongTerms) categoryIdsAggregation).getBuckets())) { - result.getCategories().add(new ProductConditionBO.Category().setId(bucket.getKeyAsNumber().intValue())); - } - } - // 返回结果 - return result; - }); - // 聚合其它数据源 - if (!CollectionUtil.isEmpty(condition.getCategories())) { - // 查询指定的 ProductCategoryBO 数组,并转换成 ProductCategoryBO Map - Map categoryMap = productCategoryService.getListByIds( - condition.getCategories().stream().map(ProductConditionBO.Category::getId).collect(Collectors.toList())) - .stream().collect(Collectors.toMap(ProductCategoryBO::getId, category -> category)); - // 设置分类名 - condition.getCategories().forEach(category -> category.setName(categoryMap.get(category.getId()).getName())); - } - // 返回结果 - return condition; - } - -} diff --git a/search/search-service-impl/src/main/resources/config/application-test.yaml b/search/search-service-impl/src/main/resources/config/application-test.yaml deleted file mode 100644 index 5e48f70bf..000000000 --- a/search/search-service-impl/src/main/resources/config/application-test.yaml +++ /dev/null @@ -1,14 +0,0 @@ -# es -spring: - data: - elasticsearch: - cluster-name: elasticsearch - cluster-nodes: 192.168.88.14:9300 - repositories: - enable: true - -# rocketmq -rocketmq: - name-server: 192.168.88.14:9876 - producer: - group: search-producer-group diff --git a/search/search-service-impl/src/main/resources/config/application.yaml b/search/search-service-impl/src/main/resources/config/application.yaml deleted file mode 100644 index 236fd500c..000000000 --- a/search/search-service-impl/src/main/resources/config/application.yaml +++ /dev/null @@ -1,54 +0,0 @@ -# es -spring: - application: - name: search-application - data: - elasticsearch: - cluster-name: elasticsearch - cluster-nodes: s1.iocoder.cn:9300 - repositories: - enable: true - elasticsearch: - rest: - uris: s1.iocoder.cn:9200 - - # Spring Cloud 配置项 - cloud: - nacos: - # Spring Cloud Nacos Discovery 配置项 - discovery: - server-addr: s1.iocoder.cn:8848 # Nacos 服务器地址 - -# Dubbo 配置项 -dubbo: - # Dubbo 注册中心 - registry: - address: spring-cloud://s1.iocoder.cn:8848 # 指定 Dubbo 服务注册中心的地址 - # Spring Cloud Alibaba Dubbo 专属配置 - cloud: - subscribed-services: admin-application, order-application, product-application # 设置订阅的应用列表,默认为 * 订阅所有应用 - # Dubbo 提供者的协议 - protocol: - name: dubbo - port: -1 - # Dubbo 提供服务的扫描基础包 - scan: - base-packages: cn.iocoder.mall.search.biz.service - # Dubbo 服务提供者的配置 - provider: - filter: -exception - ProductSearchService: - version: 1.0.0 - consumer: - ProductSpuService: - version: 1.0.0 - ProductCategoryService: - version: 1.0.0 - CartService: - version: 1.0.0 - -# rocketmq -rocketmq: - name-server: s1.iocoder.cn:9876 - producer: - group: search-producer-group diff --git a/search/search-service-impl/src/test/java/cn/iocoder/mall/search/biz/Application.java b/search/search-service-impl/src/test/java/cn/iocoder/mall/search/biz/Application.java deleted file mode 100644 index fe2e3da2a..000000000 --- a/search/search-service-impl/src/test/java/cn/iocoder/mall/search/biz/Application.java +++ /dev/null @@ -1,7 +0,0 @@ -package cn.iocoder.mall.search.biz; - -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication(scanBasePackages = {"cn.iocoder.mall.search"}) -public class Application { -} diff --git a/search/search-service-impl/src/test/java/cn/iocoder/mall/search/biz/dao/ProductRepositoryTest.java b/search/search-service-impl/src/test/java/cn/iocoder/mall/search/biz/dao/ProductRepositoryTest.java deleted file mode 100644 index 2d7f669d0..000000000 --- a/search/search-service-impl/src/test/java/cn/iocoder/mall/search/biz/dao/ProductRepositoryTest.java +++ /dev/null @@ -1,50 +0,0 @@ -package cn.iocoder.mall.search.biz.dao; - -import cn.iocoder.mall.search.biz.dataobject.ESProductDO; -import org.junit.Ignore; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - -import java.util.List; - -@RunWith(SpringJUnit4ClassRunner.class) -@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE) -public class ProductRepositoryTest { - - @Autowired - private ProductRepository productRepository; - - @Test - @Ignore - public void testSave() { -// productRepository.deleteById(1); - ESProductDO product = new ESProductDO() - .setId(1) - .setName("你猜"); - productRepository.save(product); - } - - @Test - @Ignore - public void testFindByName() { - ESProductDO product = productRepository.findByName("锤子"); - System.out.println(product); - } - - @Test - public void testSearch() { -// Page page = productRepository.search(639, null, 1, 10); -// console(page.getContent()); - -// Page page = productRepository.search(null, "数据库Oracle", 1, 10); -// console(page.getContent()); - } - - private void console(List list) { - list.forEach(System.out::println); - } - -} diff --git a/shop-web-app/pom.xml b/shop-web-app/pom.xml index 0ee3de356..455d22fe6 100644 --- a/shop-web-app/pom.xml +++ b/shop-web-app/pom.xml @@ -12,4 +12,82 @@ shop-web-app 商城,用于用户购物 + + + + + cn.iocoder.mall + mall-dependencies + 1.0-SNAPSHOT + pom + import + + + + + + + + cn.iocoder.mall + mall-spring-boot-starter-web + + + + cn.iocoder.mall + mall-spring-boot-starter-swagger + + + + cn.iocoder.mall + mall-spring-boot-starter-security-user + + + + + cn.iocoder.mall + mall-spring-boot-starter-dubbo + + + + + cn.iocoder.mall + user-service-api + 1.0-SNAPSHOT + + + + cn.iocoder.mall + product-service-api + 1.0-SNAPSHOT + + + + cn.iocoder.mall + system-service-api + 1.0-SNAPSHOT + + + + + com.alibaba.cloud + spring-cloud-starter-alibaba-nacos-discovery + + + + + org.projectlombok + lombok + + + + org.mapstruct + mapstruct + + + org.mapstruct + mapstruct-jdk8 + + + + diff --git a/shop-web-app/src/main/java/cn/iocoder/mall/shopweb/ShopWebApplication.java b/shop-web-app/src/main/java/cn/iocoder/mall/shopweb/ShopWebApplication.java new file mode 100644 index 000000000..8b0f5a02a --- /dev/null +++ b/shop-web-app/src/main/java/cn/iocoder/mall/shopweb/ShopWebApplication.java @@ -0,0 +1,13 @@ +package cn.iocoder.mall.shopweb; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class ShopWebApplication { + + public static void main(String[] args) { + SpringApplication.run(ShopWebApplication.class, args); + } + +} diff --git a/user-web-app/src/main/java/cn/iocoder/mall/userweb/controller/product/ProductCategoryController.http b/shop-web-app/src/main/java/cn/iocoder/mall/shopweb/controller/product/ProductCategoryController.http similarity index 100% rename from user-web-app/src/main/java/cn/iocoder/mall/userweb/controller/product/ProductCategoryController.http rename to shop-web-app/src/main/java/cn/iocoder/mall/shopweb/controller/product/ProductCategoryController.http diff --git a/user-web-app/src/main/java/cn/iocoder/mall/userweb/controller/product/ProductCategoryController.java b/shop-web-app/src/main/java/cn/iocoder/mall/shopweb/controller/product/ProductCategoryController.java similarity index 96% rename from user-web-app/src/main/java/cn/iocoder/mall/userweb/controller/product/ProductCategoryController.java rename to shop-web-app/src/main/java/cn/iocoder/mall/shopweb/controller/product/ProductCategoryController.java index 25e79d7ec..14941c444 100644 --- a/user-web-app/src/main/java/cn/iocoder/mall/userweb/controller/product/ProductCategoryController.java +++ b/shop-web-app/src/main/java/cn/iocoder/mall/shopweb/controller/product/ProductCategoryController.java @@ -1,4 +1,4 @@ -package cn.iocoder.mall.userweb.controller.product; +package cn.iocoder.mall.shopweb.controller.product; import cn.iocoder.common.framework.vo.CommonResult; import cn.iocoder.mall.userweb.controller.product.vo.category.ProductCategoryRespVO; diff --git a/user-web-app/src/main/java/cn/iocoder/mall/userweb/controller/product/vo/category/ProductCategoryRespVO.java b/shop-web-app/src/main/java/cn/iocoder/mall/shopweb/controller/product/vo/category/ProductCategoryRespVO.java similarity index 90% rename from user-web-app/src/main/java/cn/iocoder/mall/userweb/controller/product/vo/category/ProductCategoryRespVO.java rename to shop-web-app/src/main/java/cn/iocoder/mall/shopweb/controller/product/vo/category/ProductCategoryRespVO.java index b059eb773..89d78b20b 100644 --- a/user-web-app/src/main/java/cn/iocoder/mall/userweb/controller/product/vo/category/ProductCategoryRespVO.java +++ b/shop-web-app/src/main/java/cn/iocoder/mall/shopweb/controller/product/vo/category/ProductCategoryRespVO.java @@ -1,4 +1,4 @@ -package cn.iocoder.mall.userweb.controller.product.vo.category; +package cn.iocoder.mall.shopweb.controller.product.vo.category; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; diff --git a/shop-web-app/src/main/java/cn/iocoder/mall/shopweb/controller/product/vo/package-info.java b/shop-web-app/src/main/java/cn/iocoder/mall/shopweb/controller/product/vo/package-info.java new file mode 100644 index 000000000..47e88023c --- /dev/null +++ b/shop-web-app/src/main/java/cn/iocoder/mall/shopweb/controller/product/vo/package-info.java @@ -0,0 +1 @@ +package cn.iocoder.mall.shopweb.controller.product.vo; diff --git a/shop-web-app/src/main/resources/application-dev.yml b/shop-web-app/src/main/resources/application-dev.yml new file mode 100644 index 000000000..4cfe1567c --- /dev/null +++ b/shop-web-app/src/main/resources/application-dev.yml @@ -0,0 +1,14 @@ +spring: + # Spring Cloud 配置项 + cloud: + nacos: + # Spring Cloud Nacos Discovery 配置项 + discovery: + server-addr: 400-infra.server.iocoder.cn:8848 # Nacos 服务器地址 + namespace: dev # Nacos 命名空间 + +# Dubbo 配置项 +dubbo: + # Dubbo 注册中心 + registry: + address: spring-cloud://400-infra.server.iocoder.cn:8848 # 指定 Dubbo 服务注册中心的地址 diff --git a/shop-web-app/src/main/resources/application-local.yml b/shop-web-app/src/main/resources/application-local.yml new file mode 100644 index 000000000..2e26cd388 --- /dev/null +++ b/shop-web-app/src/main/resources/application-local.yml @@ -0,0 +1,15 @@ +spring: + # Spring Cloud 配置项 + cloud: + nacos: + # Spring Cloud Nacos Discovery 配置项 + discovery: + server-addr: 400-infra.server.iocoder.cn:8848 # Nacos 服务器地址 + namespace: dev # Nacos 命名空间 + +# Dubbo 配置项 +dubbo: + # Dubbo 注册中心 + registry: + # address: spring-cloud://400-infra.server.iocoder.cn:8848 # 指定 Dubbo 服务注册中心的地址 + address: nacos://400-infra.server.iocoder.cn:8848?namespace=dev # 指定 Dubbo 服务注册中心的地址 diff --git a/shop-web-app/src/main/resources/application.yml b/shop-web-app/src/main/resources/application.yml new file mode 100644 index 000000000..e521912ed --- /dev/null +++ b/shop-web-app/src/main/resources/application.yml @@ -0,0 +1,48 @@ +# 服务器的配置项 +server: + port: 18083 + servlet: + context-path: /user-api/ + +spring: + # Application 的配置项 + application: + name: shop-web + # Profile 的配置项 + profiles: + active: local + # SpringMVC 配置项 + mvc: + throw-exception-if-no-handler-found: true # 匹配不到路径时,抛出 NoHandlerFoundException 异常 + static-path-pattern: /doc.html # 静态资源的路径 + +# Dubbo 配置项 +dubbo: + # Spring Cloud Alibaba Dubbo 专属配置 + cloud: + subscribed-services: 'user-service,system-service' # 设置订阅的应用列表,默认为 * 订阅所有应用 + # Dubbo 服务消费者的配置 + consumer: + timeout: 10000 + validation: true # 开启 Consumer 的参数校验 + UserSmsCodeRpc: + version: 1.0.0 + UserRpc: + version: 1.0.0 + OAuth2Rpc: + version: 1.0.0 + SystemAccessLogRpc: + version: 1.0.0 + SystemExceptionLogRpc: + version: 1.0.0 + UserAddressRpc: + version: 1.0.0 + ProductCategoryRpc: + version: 1.0.0 + +# Swagger 配置项 +swagger: + title: 商城中心 + description: 提供用户商城购物流程中的 API + version: 1.0.0 + base-package: cn.iocoder.mall.shopweb.controller diff --git a/user-web-app/src/main/java/cn/iocoder/mall/userweb/controller/product/vo/package-info.java b/user-web-app/src/main/java/cn/iocoder/mall/userweb/controller/product/vo/package-info.java deleted file mode 100644 index f2877ca69..000000000 --- a/user-web-app/src/main/java/cn/iocoder/mall/userweb/controller/product/vo/package-info.java +++ /dev/null @@ -1 +0,0 @@ -package cn.iocoder.mall.userweb.controller.product.vo;