diff --git a/pom.xml b/pom.xml
index 528b3bb78d225e4ba37d67b6d14a6aebae8287f7..0e1bea9b10aaa920d4750c6da677ccb4630171dd 100644
--- a/pom.xml
+++ b/pom.xml
@@ -83,6 +83,15 @@
fastjson
1.2.40
+
+
+
+ org.elasticsearch.client
+ elasticsearch-rest-high-level-client
+
diff --git a/src/main/java/com/wwb/zhunong/controller/OrderController.java b/src/main/java/com/wwb/zhunong/controller/OrderController.java
index 766f89ddccc494a84b5d0d0d7a529c46733e1249..4029c2ee800a54be4da9141b13f2f83a2103d351 100644
--- a/src/main/java/com/wwb/zhunong/controller/OrderController.java
+++ b/src/main/java/com/wwb/zhunong/controller/OrderController.java
@@ -55,6 +55,9 @@ public class OrderController {
}
order.setOrderNo("JAVA"+ DateUtil.getCurrentDateStr());
order.setCreateDate(new Date());
+ // 此处模拟支付成功修改订单表数据
+ order.setStatus(2);
+ order.setPayDate(new Date());
OrderDetail[] goods = order.getGoods();
orderService.save(order);
diff --git a/src/main/java/com/wwb/zhunong/util/EsUtils.java b/src/main/java/com/wwb/zhunong/util/EsUtils.java
new file mode 100644
index 0000000000000000000000000000000000000000..544f87c5a2023543f869486afd95e2aa7db26d96
--- /dev/null
+++ b/src/main/java/com/wwb/zhunong/util/EsUtils.java
@@ -0,0 +1,126 @@
+package com.wwb.zhunong.util;
+
+import com.alibaba.fastjson.JSON;
+import lombok.extern.slf4j.Slf4j;
+import org.elasticsearch.action.bulk.BulkRequest;
+import org.elasticsearch.action.bulk.BulkResponse;
+import org.elasticsearch.action.get.GetRequest;
+import org.elasticsearch.action.get.GetResponse;
+import org.elasticsearch.action.index.IndexRequest;
+import org.elasticsearch.action.index.IndexResponse;
+import org.elasticsearch.action.search.SearchRequest;
+import org.elasticsearch.action.search.SearchResponse;
+import org.elasticsearch.action.update.UpdateRequest;
+import org.elasticsearch.client.RequestOptions;
+import org.elasticsearch.client.RestHighLevelClient;
+import org.elasticsearch.common.Strings;
+import org.elasticsearch.common.xcontent.XContentType;
+import org.elasticsearch.index.query.IdsQueryBuilder;
+import org.elasticsearch.index.query.QueryBuilders;
+import org.elasticsearch.search.builder.SearchSourceBuilder;
+import org.elasticsearch.search.fetch.subphase.FetchSourceContext;
+import org.springframework.stereotype.Component;
+import org.springframework.util.CollectionUtils;
+
+import javax.annotation.Resource;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+/**
+ * es工具
+ */
+@Slf4j
+@Component
+public class EsUtils {
+
+ @Resource
+ private RestHighLevelClient restHighLevelClient;
+
+ /**
+ * es 查询一个对象
+ *
+ * @param indexName indexName
+ * @param indexType indexType
+ * @param id id
+ * @param clazz 需要转换的类型
+ * @param 返回的类型
+ * @return 可能返回null
+ */
+ public T getById(String indexName, String indexType, String id, Class clazz) {
+ try {
+ GetRequest getRequest = new GetRequest(indexName, indexType, id);
+ GetResponse getResponse = restHighLevelClient.get(getRequest, RequestOptions.DEFAULT);
+ return JSON.parseObject(JSON.toJSONString(getResponse.getSource()), clazz);
+ } catch (Exception e) {
+ log.error("es 查询错误 indexName :{},id :{}", indexName, id);
+ }
+ return null;
+ }
+
+
+ /**
+ * 创建或修改一个索引
+ *
+ * @param indexName indexName
+ * @param indexType indexType
+ * @param id id
+ * @param jsonString json 字符串
+ * @return true 成功 false 失败
+ * @return
+ */
+ public Boolean createOrderUpdate(String indexName, String indexType, String id, String jsonString) {
+ try {
+ IndexRequest indexRequest = new IndexRequest(indexName, indexType);
+ indexRequest.id(id);
+ indexRequest.source(jsonString, XContentType.JSON);
+ IndexResponse index = restHighLevelClient.index(indexRequest, RequestOptions.DEFAULT);
+ log.info("【添加 es数据请求】返回值 : {}", index.getId());
+ return true;
+ } catch (Exception e) {
+ log.error("【添加 es数据请求】发生异常", e);
+ return false;
+ }
+ }
+
+
+
+ /**
+ * 根据主键查询多个数据
+ *
+ * @param indexName indexName
+ * @param clazz 响应对象class
+ * @param idList 主键id
+ * @param field 需要查询的属性
+ * @param 返回数据
+ * @return
+ */
+ public List listById(String indexName, Class clazz, List idList, List field) {
+ try {
+ SearchRequest searchRequest = new SearchRequest(indexName);
+ SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
+ IdsQueryBuilder idsQueryBuilder = QueryBuilders.idsQuery();
+ idsQueryBuilder.addIds(idList.toArray(new String[idList.size()]));
+ searchSourceBuilder.query(idsQueryBuilder);
+ if (!CollectionUtils.isEmpty(field)) {
+ searchSourceBuilder
+ .fetchSource(new FetchSourceContext(true, field.toArray(new String[field.size()]), Strings.EMPTY_ARRAY));
+ }
+ searchSourceBuilder.from(0).size(idList.size());
+ searchRequest.source(searchSourceBuilder);
+
+ SearchResponse searchResponse = restHighLevelClient.search(searchRequest, RequestOptions.DEFAULT);
+
+ return Arrays.stream(searchResponse.getHits().getHits())
+ .map(item -> JSON.parseObject(item.getSourceAsString(), clazz))
+ .collect(Collectors.toList());
+ } catch (Exception e) {
+ log.error("es 查询异常", e);
+ }
+ return Collections.emptyList();
+ }
+
+
+}
diff --git a/src/main/java/com/wwb/zhunong/util/MinIOUtil.java b/src/main/java/com/wwb/zhunong/util/MinIOUtil.java
index 936726fa751fe644a6b225d4e692b641375fe5f5..4130c7a10744de02af5db88e8a8ddcdc460c95af 100644
--- a/src/main/java/com/wwb/zhunong/util/MinIOUtil.java
+++ b/src/main/java/com/wwb/zhunong/util/MinIOUtil.java
@@ -30,7 +30,7 @@ public class MinIOUtil {
/**
* Bucket所在地域对应的Endpoint
*/
- private static String endPoint="http://192.168.181.128:9000";
+ private static String endPoint="http://123.249.127.68:9000";
/**
* 存储桶名称
@@ -40,12 +40,12 @@ public class MinIOUtil {
/**
* 用户名
*/
- private static String accessKey="NqhWmuYInBXNlVOM";
+ private static String accessKey="MPV4JXXB3FO2NUCDRXHZ";
/**
* 密码
*/
- private static String secretKey="I60UzlnqEbkKAo9eyFYLY15SDj964ALM";
+ private static String secretKey="nTfQTN9vi0GZL8bzMRexP3CFQVmfTzKv829vQp0V";
/**
* 分隔符
diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml
index 8b8b6b454a2112d868827344c454c3f8fa50eee6..acdc032c3af39fc37ed08d1467f0dbe6357cd256 100644
--- a/src/main/resources/application.yml
+++ b/src/main/resources/application.yml
@@ -7,7 +7,7 @@ spring:
datasource:
type: com.alibaba.druid.pool.DruidDataSource
driver-class-name: com.mysql.cj.jdbc.Driver
- url: jdbc:mysql://192.168.181.128:3306/db_zhunong?serverTimezone=Asia/Shanghai&characterEncoding=utf8
+ url: jdbc:mysql://123.249.127.68:3306/db_zhunong?serverTimezone=Asia/Shanghai&characterEncoding=utf8
username: root
password: 123456
redis:
@@ -17,6 +17,10 @@ spring:
multipart:
max-file-size: 20MB
max-request-size: 20MB
+ elasticsearch:
+ rest:
+ uris: http://192.168.181.128:9200
+
mybatis-plus:
global-config: