From c73204a8283bbef2824af3c1e1a2427c848b6d7c Mon Sep 17 00:00:00 2001 From: misworga831 Date: Wed, 19 Jul 2023 11:10:19 +0800 Subject: [PATCH 1/5] =?UTF-8?q?fix:=20=E5=A2=9E=E5=8A=A0=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E7=B1=BB=E5=9E=8B=EF=BC=8Cvideo=E6=A0=BC?= =?UTF-8?q?=E5=BC=8F=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/cn/lili/controller/common/UploadController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common-api/src/main/java/cn/lili/controller/common/UploadController.java b/common-api/src/main/java/cn/lili/controller/common/UploadController.java index 767db2fa..027b66ae 100644 --- a/common-api/src/main/java/cn/lili/controller/common/UploadController.java +++ b/common-api/src/main/java/cn/lili/controller/common/UploadController.java @@ -75,7 +75,7 @@ public class UploadController { } - if (!CharSequenceUtil.containsAny(file.getContentType().toLowerCase(), "image")) { + if (!CharSequenceUtil.containsAny(Objects.requireNonNull(file.getContentType()).toLowerCase(), "image", "video")) { throw new ServiceException(ResultCode.FILE_TYPE_NOT_SUPPORT); } From 89f3e8f980b5a01f14abf5466d8aa1645ecf5072 Mon Sep 17 00:00:00 2001 From: chc <1501738723@qq.com> Date: Thu, 20 Jul 2023 14:23:12 +0800 Subject: [PATCH 2/5] =?UTF-8?q?fix:=20sku=E7=9A=84=E5=95=86=E5=93=81?= =?UTF-8?q?=E8=A7=86=E9=A2=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/cn/lili/modules/goods/entity/dos/GoodsSku.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/framework/src/main/java/cn/lili/modules/goods/entity/dos/GoodsSku.java b/framework/src/main/java/cn/lili/modules/goods/entity/dos/GoodsSku.java index 0c89fdc1..309fea1a 100644 --- a/framework/src/main/java/cn/lili/modules/goods/entity/dos/GoodsSku.java +++ b/framework/src/main/java/cn/lili/modules/goods/entity/dos/GoodsSku.java @@ -189,7 +189,7 @@ public class GoodsSku extends BaseEntity { this.goodsId = goods.getId(); this.goodsName = goods.getGoodsName(); this.goodsType = goods.getGoodsType(); - + this.goodsVideo = goods.getGoodsVideo(); this.selfOperated = goods.getSelfOperated(); this.sellingPoint = goods.getSellingPoint(); this.categoryPath = goods.getCategoryPath(); From 8f1541c338e38f7ab5f612e981e32722e3443d27 Mon Sep 17 00:00:00 2001 From: Chopper711 Date: Fri, 21 Jul 2023 18:29:58 +0800 Subject: [PATCH 3/5] =?UTF-8?q?fix:=E7=A7=92=E6=9D=80=E6=B4=BB=E5=8A=A8?= =?UTF-8?q?=E5=BC=82=E5=B8=B8=E6=B6=88=E6=81=AFresultcode=20=E4=BF=AE?= =?UTF-8?q?=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lili/modules/promotion/serviceimpl/SeckillServiceImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 a747c377..c9c7fba5 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 @@ -153,7 +153,7 @@ public class SeckillServiceImpl extends AbstractPromotionsServiceImpl Date: Fri, 21 Jul 2023 18:45:00 +0800 Subject: [PATCH 4/5] =?UTF-8?q?=E5=95=86=E5=93=81=E5=AF=BC=E5=85=A5?= =?UTF-8?q?=E6=B6=88=E6=81=AF=E4=B8=8D=E5=A4=9F=E6=98=8E=E7=A1=AE=E9=97=AE?= =?UTF-8?q?=E9=A2=98=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../goods/serviceimpl/GoodsImportServiceImpl.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/framework/src/main/java/cn/lili/modules/goods/serviceimpl/GoodsImportServiceImpl.java b/framework/src/main/java/cn/lili/modules/goods/serviceimpl/GoodsImportServiceImpl.java index 349ac5d9..bcf056c2 100644 --- a/framework/src/main/java/cn/lili/modules/goods/serviceimpl/GoodsImportServiceImpl.java +++ b/framework/src/main/java/cn/lili/modules/goods/serviceimpl/GoodsImportServiceImpl.java @@ -175,14 +175,24 @@ public class GoodsImportServiceImpl implements GoodsImportService { } } - String categoryId = objects.get(2).toString().substring(0, objects.get(2).toString().indexOf("-")); + String categoryId = null; + try { + categoryId = objects.get(2).toString().substring(0, objects.get(2).toString().indexOf("-")); + } catch (Exception e) { + throw new ServiceException("请选择商品分类"); + } Category category = categoryService.getCategoryById(categoryId); if (category == null) { throw new ServiceException("商品分类不存在:" + objects.get(2).toString().substring(objects.get(2).toString().indexOf("-"))); } - String templateId = objects.get(3).toString().substring(0, objects.get(3).toString().indexOf("-")); + String templateId = null; + try { + templateId = objects.get(3).toString().substring(0, objects.get(3).toString().indexOf("-")); + } catch (Exception e) { + throw new ServiceException("请选择物流模板"); + } FreightTemplateVO freightTemplateVO = freightTemplateService.getFreightTemplate(templateId); if (freightTemplateVO == null) { throw new ServiceException("配送模板不存在:" + objects.get(3).toString().substring(objects.get(3).toString().indexOf("-"))); From e8af34995b25b5bffa762129ad31a8f2bef8768a Mon Sep 17 00:00:00 2001 From: misworga831 Date: Fri, 28 Jul 2023 16:16:16 +0800 Subject: [PATCH 5/5] =?UTF-8?q?fix:=20=E4=BC=98=E5=8C=96elasticsearch=20?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=EF=BC=8C=E8=A7=A3=E5=86=B3I/O=20reactor?= =?UTF-8?q?=E9=97=AE=E9=A2=98=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BaseElasticsearchService.java | 16 ++- .../config/ElasticsearchConfig.java | 55 ++++++---- .../serviceimpl/EsGoodsIndexServiceImpl.java | 103 +++++++++++------- 3 files changed, 109 insertions(+), 65 deletions(-) diff --git a/framework/src/main/java/cn/lili/elasticsearch/BaseElasticsearchService.java b/framework/src/main/java/cn/lili/elasticsearch/BaseElasticsearchService.java index 7f08ddf7..e5976870 100644 --- a/framework/src/main/java/cn/lili/elasticsearch/BaseElasticsearchService.java +++ b/framework/src/main/java/cn/lili/elasticsearch/BaseElasticsearchService.java @@ -389,11 +389,17 @@ public abstract class BaseElasticsearchService { */ protected void deleteIndexRequest(String index) { DeleteIndexRequest deleteIndexRequest = buildDeleteIndexRequest(index); - try { - client.indices().delete(deleteIndexRequest, COMMON_OPTIONS); - } catch (IOException e) { - throw new ElasticsearchException("删除索引 {" + index + "} 失败:" + e.getMessage()); - } + client.indices().deleteAsync(deleteIndexRequest, COMMON_OPTIONS, new ActionListener() { + @Override + public void onResponse(AcknowledgedResponse acknowledgedResponse) { + log.info("删除索引 {} 成功", index); + } + + @Override + public void onFailure(Exception e) { + log.error("删除索引 {} 失败", index, e); + } + }); } /** diff --git a/framework/src/main/java/cn/lili/elasticsearch/config/ElasticsearchConfig.java b/framework/src/main/java/cn/lili/elasticsearch/config/ElasticsearchConfig.java index b80da178..6010a2a4 100644 --- a/framework/src/main/java/cn/lili/elasticsearch/config/ElasticsearchConfig.java +++ b/framework/src/main/java/cn/lili/elasticsearch/config/ElasticsearchConfig.java @@ -8,7 +8,7 @@ import org.apache.http.auth.UsernamePasswordCredentials; import org.apache.http.client.CredentialsProvider; import org.apache.http.conn.ConnectionKeepAliveStrategy; import org.apache.http.impl.client.BasicCredentialsProvider; -import org.apache.http.impl.nio.reactor.IOReactorConfig; +import org.apache.http.impl.nio.client.HttpAsyncClientBuilder; import org.elasticsearch.client.RestClient; import org.elasticsearch.client.RestClientBuilder; import org.elasticsearch.client.RestHighLevelClient; @@ -39,35 +39,46 @@ public class ElasticsearchConfig extends AbstractElasticsearchConfiguration { @Override @Bean public RestHighLevelClient elasticsearchClient() { - RestClientBuilder restBuilder = RestClient - .builder(this.getHttpHosts()); - restBuilder.setHttpClientConfigCallback(httpClientBuilder -> - httpClientBuilder - .setKeepAliveStrategy(getConnectionKeepAliveStrategy()) - .setMaxConnPerRoute(10). - setDefaultIOReactorConfig(IOReactorConfig.custom().setIoThreadCount(1).build())); String username = elasticsearchProperties.getAccount().getUsername(); String password = elasticsearchProperties.getAccount().getPassword(); - if (username != null && password != null) { - final CredentialsProvider credential = new BasicCredentialsProvider(); - credential.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(username, password)); - restBuilder.setHttpClientConfigCallback(httpClientBuilder -> - httpClientBuilder - .setDefaultCredentialsProvider(credential) - .setKeepAliveStrategy(getConnectionKeepAliveStrategy()) - .setMaxConnPerRoute(10) - .setDefaultIOReactorConfig(IOReactorConfig.custom().setIoThreadCount(Runtime.getRuntime().availableProcessors()).build())); - } + final CredentialsProvider credential = createCredentialsIfNotNull(username, password); - restBuilder.setRequestConfigCallback(requestConfigBuilder -> - requestConfigBuilder.setConnectTimeout(1000) //time until a connection with the server is established. - .setSocketTimeout(12 * 1000) //time of inactivity to wait for packets[data] to receive. - .setConnectionRequestTimeout(-1)); //time to fetch a connection from the connection pool 0 for infinite. + RestClientBuilder restBuilder = createRestClientBuilderWithConfig(credential); client = new RestHighLevelClient(restBuilder); return client; } + private CredentialsProvider createCredentialsIfNotNull(String username, String password) { + if (username == null || password == null) { + return null; + } + final CredentialsProvider credentialsProvider = new BasicCredentialsProvider(); + credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(username, password)); + return credentialsProvider; + } + + private RestClientBuilder createRestClientBuilderWithConfig(CredentialsProvider credentialsProvider) { + return RestClient + .builder(this.getHttpHosts()) + .setHttpClientConfigCallback(httpClientBuilder -> configureHttpClientBuilder(httpClientBuilder, credentialsProvider)) + .setRequestConfigCallback(requestConfigBuilder -> + requestConfigBuilder + .setConnectTimeout(1000) + .setSocketTimeout(12 * 1000)); + } + + private HttpAsyncClientBuilder configureHttpClientBuilder(HttpAsyncClientBuilder httpClientBuilder, + CredentialsProvider credentialsProvider) { + httpClientBuilder + .setKeepAliveStrategy(getConnectionKeepAliveStrategy()) + .setMaxConnPerRoute(10); + if (credentialsProvider != null) { + httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider); + } + return httpClientBuilder; + } + private HttpHost[] getHttpHosts() { List clusterNodes = elasticsearchProperties.getClusterNodes(); HttpHost[] httpHosts = new HttpHost[clusterNodes.size()]; 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 e2c34666..312f9441 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 @@ -50,6 +50,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import lombok.extern.slf4j.Slf4j; import org.apache.rocketmq.spring.core.RocketMQTemplate; +import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.bulk.BulkRequest; import org.elasticsearch.action.bulk.BulkResponse; import org.elasticsearch.action.update.UpdateRequest; @@ -71,7 +72,6 @@ import org.springframework.data.elasticsearch.core.SearchPage; import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder; import org.springframework.stereotype.Service; -import java.io.IOException; import java.lang.reflect.Field; import java.util.*; import java.util.concurrent.TimeUnit; @@ -416,14 +416,20 @@ public class EsGoodsIndexServiceImpl extends BaseElasticsearchService implements } update.setScript(new Script(script.toString())); update.setConflicts("proceed"); - try { - BulkByScrollResponse bulkByScrollResponse = client.updateByQuery(update, RequestOptions.DEFAULT); - if (bulkByScrollResponse.getVersionConflicts() > 0) { - throw new RetryException("更新商品索引失败,es内容版本冲突"); + + this.client.updateByQueryAsync(update, RequestOptions.DEFAULT, new ActionListener() { + @Override + public void onResponse(BulkByScrollResponse bulkByScrollResponse) { + if (bulkByScrollResponse.getVersionConflicts() > 0) { + throw new RetryException("更新商品索引失败,es内容版本冲突"); + } } - } catch (IOException e) { - log.error("更新商品索引异常", e); - } + + @Override + public void onFailure(Exception e) { + log.error("更新商品索引异常", e); + } + }); } /** @@ -433,24 +439,32 @@ public class EsGoodsIndexServiceImpl extends BaseElasticsearchService implements */ @Override public void updateBulkIndex(List goodsIndices) { - try { - //索引名称拼接 - String indexName = getIndexName(); + //索引名称拼接 + String indexName = getIndexName(); - BulkRequest request = new BulkRequest(); + BulkRequest request = new BulkRequest(); - for (EsGoodsIndex goodsIndex : goodsIndices) { - UpdateRequest updateRequest = new UpdateRequest(indexName, goodsIndex.getId()); + for (EsGoodsIndex goodsIndex : goodsIndices) { + UpdateRequest updateRequest = new UpdateRequest(indexName, goodsIndex.getId()); - JSONObject jsonObject = JSONUtil.parseObj(goodsIndex); - jsonObject.set("releaseTime", goodsIndex.getReleaseTime()); - updateRequest.doc(jsonObject); - request.add(updateRequest); - } - client.bulk(request, RequestOptions.DEFAULT); - } catch (IOException e) { - log.error("批量更新商品索引异常", e); + JSONObject jsonObject = JSONUtil.parseObj(goodsIndex); + jsonObject.set("releaseTime", goodsIndex.getReleaseTime()); + updateRequest.doc(jsonObject); + request.add(updateRequest); } + this.client.bulkAsync(request, RequestOptions.DEFAULT, new ActionListener() { + @Override + public void onResponse(BulkResponse bulkItemResponses) { + if (bulkItemResponses.hasFailures()) { + throw new RetryException("批量更新商品索引失败,es内容版本冲突"); + } + } + + @Override + public void onFailure(Exception e) { + log.error("批量更新商品索引异常", e); + } + }); } /** @@ -469,14 +483,21 @@ public class EsGoodsIndexServiceImpl extends BaseElasticsearchService implements deleteByQueryRequest.setQuery(boolQueryBuilder); deleteByQueryRequest.indices(getIndexName()); deleteByQueryRequest.setConflicts("proceed"); - try { - BulkByScrollResponse bulkByScrollResponse = client.deleteByQuery(deleteByQueryRequest, RequestOptions.DEFAULT); - if (bulkByScrollResponse.getVersionConflicts() > 0) { - throw new RetryException("删除索引失败,es内容版本冲突"); + this.client.deleteByQueryAsync(deleteByQueryRequest, RequestOptions.DEFAULT, new ActionListener() { + + @Override + public void onResponse(BulkByScrollResponse bulkByScrollResponse) { + if (bulkByScrollResponse.getVersionConflicts() > 0) { + throw new RetryException("删除索引失败,es内容版本冲突"); + } } - } catch (IOException e) { - log.error("删除索引异常", e); - } + + @Override + public void onFailure(Exception e) { + throw new RetryException("删除索引失败," + e.getMessage()); + } + }); + } /** @@ -883,16 +904,22 @@ public class EsGoodsIndexServiceImpl extends BaseElasticsearchService implements if (bulkRequest.requests().isEmpty()) { return; } - try { - BulkResponse responses = this.client.bulk(bulkRequest, RequestOptions.DEFAULT); - if (responses.hasFailures()) { - log.info("批量更新商品索引的促销信息中出现部分异常:{}", responses.buildFailureMessage()); - } else { - log.info("批量更新商品索引的促销信息结果:{}", responses.status()); + this.client.bulkAsync(bulkRequest, RequestOptions.DEFAULT, new ActionListener() { + @Override + public void onResponse(BulkResponse bulkItemResponses) { + if (bulkItemResponses.hasFailures()) { + log.info("批量更新商品索引的促销信息中出现部分异常:{}", bulkItemResponses.buildFailureMessage()); + } else { + log.info("批量更新商品索引的促销信息结果:{}", bulkItemResponses.status()); + } } - } catch (IOException e) { - log.error("批量更新商品索引的促销信息出现异常!", e); - } + + @Override + public void onFailure(Exception e) { + log.error("批量更新商品索引的促销信息出现异常!", e); + } + }); + } /**