瀏覽代碼

大小写问题

kerry 5 年之前
父節點
當前提交
8f0620fbf7
共有 21 個文件被更改,包括 411 次插入55 次删除
  1. 59 0
      elastic-publish-service/config-index/unit-agency.mapping.json
  2. 11 0
      elastic-publish-service/config-index/unit-agency.setting.json
  3. 59 0
      elastic-publish-service/index-text/unit-agency.mapping.json
  4. 11 0
      elastic-publish-service/index-text/unit-agency.setting.json
  5. 59 0
      elastic-publish-service/index/unit-agency.mapping.json
  6. 11 0
      elastic-publish-service/index/unit-agency.setting.json
  7. 1 1
      elastic-publish-service/req/http-client.env.json
  8. 2 2
      elastic-publish-service/req/main-controller.http
  9. 12 13
      elastic-publish-service/src/main/java/com/vcarecity/publish/controller/MainController.java
  10. 21 27
      elastic-publish-service/src/main/java/com/vcarecity/publish/elastic/service/impl/ElasticIndexServiceImpl.java
  11. 8 3
      elastic-publish-service/src/main/java/com/vcarecity/publish/elastic/service/impl/ElasticLoadDataServiceImpl.java
  12. 1 1
      elastic-publish-service/src/main/java/com/vcarecity/publish/pojo/dto/UnitAgencyDTO.java
  13. 53 0
      elastic-publish-service/src/main/java/com/vcarecity/publish/service/LoadDataStatusService.java
  14. 30 0
      elastic-publish-service/src/main/java/com/vcarecity/publish/service/impl/LoadDataStatusServiceImpl.java
  15. 10 3
      elastic-publish-service/src/main/java/com/vcarecity/publish/sql/service/impl/UnitServiceImpl.java
  16. 9 1
      elastic-publish-service/src/main/java/com/vcarecity/publish/task/CheckUpdateTask.java
  17. 19 0
      elastic-publish-service/src/main/java/com/vcarecity/publish/util/Utils.java
  18. 2 0
      elastic-publish-service/src/main/resources/application-beta.yml
  19. 4 2
      elastic-publish-service/src/main/resources/application-dev.yml
  20. 11 2
      elastic-publish-service/src/test/java/com/vcarecity/publish/elastic/service/impl/ElasticIndexServiceImplTest.java
  21. 18 0
      elastic-publish-service/src/test/java/com/vcarecity/publish/util/UtilsTest.java

+ 59 - 0
elastic-publish-service/config-index/unit-agency.mapping.json 查看文件

@@ -0,0 +1,59 @@
1
+{
2
+  "properties": {
3
+    "agencyDetail": {
4
+      "type": "text",
5
+      "analyzer": "ik_max_word",
6
+      "search_analyzer": "ik_smart",
7
+      "fields": {
8
+        "keyword": {
9
+          "type": "keyword",
10
+          "ignore_above": 256
11
+        }
12
+      }
13
+    },
14
+    "agencyName": {
15
+      "type": "text",
16
+      "analyzer": "ik_max_word",
17
+      "search_analyzer": "ik_smart",
18
+      "fields": {
19
+        "keyword": {
20
+          "type": "keyword",
21
+          "ignore_above": 256
22
+        }
23
+      }
24
+    },
25
+    "nameOfBuilding": {
26
+      "type": "text",
27
+      "analyzer": "ik_max_word",
28
+      "search_analyzer": "ik_smart",
29
+      "fields": {
30
+        "keyword": {
31
+          "type": "keyword",
32
+          "ignore_above": 256
33
+        }
34
+      }
35
+    },
36
+    "unitType": {
37
+      "type": "text",
38
+      "analyzer": "ik_max_word",
39
+      "search_analyzer": "ik_smart",
40
+      "fields": {
41
+        "keyword": {
42
+          "type": "keyword",
43
+          "ignore_above": 256
44
+        }
45
+      }
46
+    },
47
+    "dtuNo": {
48
+      "type": "text",
49
+      "analyzer": "caseSensitive",
50
+      "search_analyzer": "caseSensitive",
51
+      "fields": {
52
+        "keyword": {
53
+          "type": "keyword",
54
+          "ignore_above": 256
55
+        }
56
+      }
57
+    }
58
+  }
59
+}

+ 11 - 0
elastic-publish-service/config-index/unit-agency.setting.json 查看文件

@@ -0,0 +1,11 @@
1
+{
2
+  "analysis": {
3
+    "analyzer": {
4
+      "caseSensitive": {
5
+        "filter": "lowercase",
6
+        "type": "custom",
7
+        "tokenizer": "keyword"
8
+      }
9
+    }
10
+  }
11
+}

+ 59 - 0
elastic-publish-service/index-text/unit-agency.mapping.json 查看文件

@@ -0,0 +1,59 @@
1
+{
2
+  "properties": {
3
+    "agencyDetail": {
4
+      "type": "text",
5
+      "analyzer": "case_sensitive",
6
+      "search_analyzer": "case_sensitive",
7
+      "fields": {
8
+        "keyword": {
9
+          "type": "keyword",
10
+          "ignore_above": 256
11
+        }
12
+      }
13
+    },
14
+    "agencyName": {
15
+      "type": "text",
16
+      "analyzer": "case_sensitive",
17
+      "search_analyzer": "case_sensitive",
18
+      "fields": {
19
+        "keyword": {
20
+          "type": "keyword",
21
+          "ignore_above": 256
22
+        }
23
+      }
24
+    },
25
+    "nameOfBuilding": {
26
+      "type": "text",
27
+      "analyzer": "case_sensitive",
28
+      "search_analyzer": "case_sensitive",
29
+      "fields": {
30
+        "keyword": {
31
+          "type": "keyword",
32
+          "ignore_above": 256
33
+        }
34
+      }
35
+    },
36
+    "unitType": {
37
+      "type": "text",
38
+      "analyzer": "case_sensitive",
39
+      "search_analyzer": "case_sensitive",
40
+      "fields": {
41
+        "keyword": {
42
+          "type": "keyword",
43
+          "ignore_above": 256
44
+        }
45
+      }
46
+    },
47
+    "dtuNo": {
48
+      "type": "text",
49
+      "analyzer": "case_sensitive",
50
+      "search_analyzer": "case_sensitive",
51
+      "fields": {
52
+        "keyword": {
53
+          "type": "keyword",
54
+          "ignore_above": 256
55
+        }
56
+      }
57
+    }
58
+  }
59
+}

+ 11 - 0
elastic-publish-service/index-text/unit-agency.setting.json 查看文件

@@ -0,0 +1,11 @@
1
+{
2
+  "analysis": {
3
+    "analyzer": {
4
+      "case_sensitive": {
5
+        "filter": "lowercase",
6
+        "type": "custom",
7
+        "tokenizer": "keyword"
8
+      }
9
+    }
10
+  }
11
+}

+ 59 - 0
elastic-publish-service/index/unit-agency.mapping.json 查看文件

@@ -0,0 +1,59 @@
1
+{
2
+  "properties": {
3
+    "agencyDetail": {
4
+      "type": "text",
5
+      "analyzer": "ik_max_word",
6
+      "search_analyzer": "ik_smart",
7
+      "fields": {
8
+        "keyword": {
9
+          "type": "keyword",
10
+          "ignore_above": 256
11
+        }
12
+      }
13
+    },
14
+    "agencyName": {
15
+      "type": "text",
16
+      "analyzer": "ik_max_word",
17
+      "search_analyzer": "ik_smart",
18
+      "fields": {
19
+        "keyword": {
20
+          "type": "keyword",
21
+          "ignore_above": 256
22
+        }
23
+      }
24
+    },
25
+    "nameOfBuilding": {
26
+      "type": "text",
27
+      "analyzer": "ik_max_word",
28
+      "search_analyzer": "ik_smart",
29
+      "fields": {
30
+        "keyword": {
31
+          "type": "keyword",
32
+          "ignore_above": 256
33
+        }
34
+      }
35
+    },
36
+    "unitType": {
37
+      "type": "text",
38
+      "analyzer": "ik_max_word",
39
+      "search_analyzer": "ik_smart",
40
+      "fields": {
41
+        "keyword": {
42
+          "type": "keyword",
43
+          "ignore_above": 256
44
+        }
45
+      }
46
+    },
47
+    "dtuNo": {
48
+      "type": "text",
49
+      "analyzer": "caseSensitive",
50
+      "search_analyzer": "caseSensitive",
51
+      "fields": {
52
+        "keyword": {
53
+          "type": "keyword",
54
+          "ignore_above": 256
55
+        }
56
+      }
57
+    }
58
+  }
59
+}

+ 11 - 0
elastic-publish-service/index/unit-agency.setting.json 查看文件

@@ -0,0 +1,11 @@
1
+{
2
+  "analysis": {
3
+    "analyzer": {
4
+      "caseSensitive": {
5
+        "filter": "lowercase",
6
+        "type": "custom",
7
+        "tokenizer": "keyword"
8
+      }
9
+    }
10
+  }
11
+}

+ 1 - 1
elastic-publish-service/req/http-client.env.json 查看文件

@@ -1,6 +1,6 @@
1 1
 {
2 2
   "dev": {
3
-    "host": "http://192.168.10.179:7080"
3
+    "host": "http://192.168.10.179:8092"
4 4
   },
5 5
   "beta": {
6 6
     "host": "http://192.168.10.100:8092"

+ 2 - 2
elastic-publish-service/req/main-controller.http 查看文件

@@ -3,7 +3,7 @@ Content-Type: application/json
3 3
 
4 4
 {
5 5
   "agencyPath": "/1",
6
-  "keyword": "SV190102725618",
6
+  "keyword": "重庆电子工程职业学院GLTL重庆高校",
7 7
   "page": 1,
8 8
   "size": 10,
9 9
   "regulatoryLevelId": "",
@@ -21,7 +21,7 @@ Content-Type: application/json
21 21
 
22 22
 {
23 23
   "agencyPath": "/1",
24
-  "keyword": "RSV1901027256184",
24
+  "keyword": "卡拉ok",
25 25
   "page": 1,
26 26
   "size": 10,
27 27
   "regulatoryLevelId": "",

+ 12 - 13
elastic-publish-service/src/main/java/com/vcarecity/publish/controller/MainController.java 查看文件

@@ -9,6 +9,7 @@ import com.vcarecity.publish.pojo.dto.TotalResultDTO;
9 9
 import com.vcarecity.publish.pojo.dto.UnitAgencyDTO;
10 10
 import com.vcarecity.publish.pojo.dto.UnitIdDTO;
11 11
 import com.vcarecity.publish.pojo.query.UnitAgencyQuery;
12
+import com.vcarecity.publish.service.LoadDataStatusService;
12 13
 import com.vcarecity.publish.sql.service.UnitService;
13 14
 import lombok.extern.slf4j.Slf4j;
14 15
 import org.springframework.beans.factory.annotation.Value;
@@ -17,7 +18,6 @@ import org.springframework.web.bind.annotation.*;
17 18
 import javax.validation.Valid;
18 19
 import java.io.IOException;
19 20
 import java.util.List;
20
-import java.util.concurrent.atomic.AtomicInteger;
21 21
 
22 22
 /**
23 23
  * @author Kerry on 19/12/11
@@ -27,21 +27,20 @@ import java.util.concurrent.atomic.AtomicInteger;
27 27
 @RestController
28 28
 public class MainController implements PrepareController {
29 29
 
30
-    private AtomicInteger dataStatus;
31 30
 
32 31
     private final UnitService unitService;
33 32
     private final ElasticLoadDataService elasticLoadDataService;
33
+    private final LoadDataStatusService loadDataStatusService;
34 34
 
35 35
     public MainController(UnitService unitService,
36 36
                           ElasticLoadDataService elasticLoadDataService,
37
+                          LoadDataStatusService loadDataStatusService,
37 38
                           @Value("${app.scheduling.enable}") Boolean schedulingEnable) {
38 39
         this.unitService = unitService;
39 40
         this.elasticLoadDataService = elasticLoadDataService;
40
-
41
-        if (schedulingEnable) {
42
-            dataStatus = new AtomicInteger(ElasticConstant.DATA_STATUS_LOADED);
43
-        } else {
44
-            dataStatus = new AtomicInteger(ElasticConstant.DATA_STATUS_NOT_LOAD);
41
+        this.loadDataStatusService = loadDataStatusService;
42
+        if (!schedulingEnable) {
43
+            loadDataStatusService.setStatus(ElasticConstant.DATA_STATUS_LOADED);
45 44
         }
46 45
     }
47 46
 
@@ -50,20 +49,20 @@ public class MainController implements PrepareController {
50 49
     @RequestMapping(value = "/load", method = {RequestMethod.GET, RequestMethod.POST})
51 50
     public ApiResult loadData() {
52 51
         synchronized (this) {
53
-            if (dataStatus.get() == ElasticConstant.DATA_STATUS_NOT_LOAD) {
52
+            if (loadDataStatusService.getStatus() == ElasticConstant.DATA_STATUS_NOT_LOAD) {
54 53
                 logger.info("prepare to load data into elasticsearch");
55
-                dataStatus.set(ElasticConstant.DATA_STATUS_LOADING);
54
+                loadDataStatusService.setStatus(ElasticConstant.DATA_STATUS_LOADING);
56 55
                 new Thread(() -> {
57 56
                     try {
58 57
                         elasticLoadDataService.loadData();
59
-                        dataStatus.set(ElasticConstant.DATA_STATUS_LOADED);
58
+                        loadDataStatusService.setStatus(ElasticConstant.DATA_STATUS_LOADED);
60 59
                     } catch (IOException e) {
61 60
                         e.printStackTrace();
62
-                        dataStatus.set(ElasticConstant.DATA_STATUS_NOT_LOAD);
61
+                        loadDataStatusService.setStatus(ElasticConstant.DATA_STATUS_NOT_LOAD);
63 62
                     }
64 63
                 }).start();
65 64
                 return ApiResult.builder().status(40000).message("first load data into elasticsearch").build();
66
-            } else if (dataStatus.get() == ElasticConstant.DATA_STATUS_LOADING) {
65
+            } else if (loadDataStatusService.getStatus() == ElasticConstant.DATA_STATUS_LOADING) {
67 66
                 return ApiResult.builder().status(40000).message("loading data into elasticsearch").build();
68 67
             }
69 68
         }
@@ -97,6 +96,6 @@ public class MainController implements PrepareController {
97 96
     @SkipMethod
98 97
     @Override
99 98
     public int getDataStatus() {
100
-        return dataStatus.get();
99
+        return loadDataStatusService.getStatus();
101 100
     }
102 101
 }

+ 21 - 27
elastic-publish-service/src/main/java/com/vcarecity/publish/elastic/service/impl/ElasticIndexServiceImpl.java 查看文件

@@ -1,6 +1,7 @@
1 1
 package com.vcarecity.publish.elastic.service.impl;
2 2
 
3 3
 import com.vcarecity.publish.elastic.service.ElasticIndexService;
4
+import com.vcarecity.publish.util.Utils;
4 5
 import lombok.extern.slf4j.Slf4j;
5 6
 import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest;
6 7
 import org.elasticsearch.client.RequestOptions;
@@ -9,8 +10,10 @@ import org.elasticsearch.client.indices.CreateIndexRequest;
9 10
 import org.elasticsearch.client.indices.CreateIndexResponse;
10 11
 import org.elasticsearch.client.indices.GetIndexRequest;
11 12
 import org.elasticsearch.common.xcontent.XContentType;
13
+import org.springframework.beans.factory.annotation.Value;
12 14
 import org.springframework.stereotype.Service;
13 15
 
16
+import java.io.File;
14 17
 import java.io.IOException;
15 18
 import java.util.List;
16 19
 
@@ -22,6 +25,9 @@ import java.util.List;
22 25
 @Service
23 26
 public class ElasticIndexServiceImpl implements ElasticIndexService {
24 27
 
28
+    @Value("${app.index.config}")
29
+    private String indexConfig;
30
+
25 31
     private final RestHighLevelClient restHighLevelClient;
26 32
 
27 33
     public ElasticIndexServiceImpl(RestHighLevelClient restHighLevelClient) {
@@ -36,36 +42,24 @@ public class ElasticIndexServiceImpl implements ElasticIndexService {
36 42
 
37 43
     @Override
38 44
     public boolean createIndex(String index) throws IOException {
39
-
40 45
         CreateIndexRequest request = new CreateIndexRequest(index);
41
-
42
-        // mapping
43
-        //language=JSON
44
-        String mapping = "{\n" +
45
-                "  \"properties\": {\n" +
46
-                "    \"agencyName\": {\n" +
47
-                "      \"type\": \"text\",\n" +
48
-                "      \"analyzer\": \"ik_max_word\",\n" +
49
-                "      \"search_analyzer\": \"ik_smart\"\n" +
50
-                "    },\n" +
51
-                "    \"agencyDetail\": {\n" +
52
-                "      \"type\": \"text\",\n" +
53
-                "      \"analyzer\": \"ik_max_word\",\n" +
54
-                "      \"search_analyzer\": \"ik_smart\"\n" +
55
-                "    },\n" +
56
-                "    \"nameOfBuilding\": {\n" +
57
-                "      \"type\": \"text\",\n" +
58
-                "      \"analyzer\": \"ik_max_word\",\n" +
59
-                "      \"search_analyzer\": \"ik_smart\"\n" +
60
-                "    }\n" +
61
-                "  " +
62
-                "}\n" +
63
-                "}";
64
-
65
-        request.mapping(mapping, XContentType.JSON);
46
+        try {
47
+            File file = new File(indexConfig + "/" + index + ".setting.json");
48
+            String setting = Utils.readFile(file);
49
+            request.settings(setting, XContentType.JSON);
50
+        } catch (IOException e) {
51
+            logger.warn("setting file not found. usage default setting config");
52
+        }
53
+
54
+        try {
55
+            File file = new File(indexConfig + "/" + index + ".mapping.json");
56
+            String mapping = Utils.readFile(file);
57
+            request.mapping(mapping, XContentType.JSON);
58
+        } catch (IOException e) {
59
+            logger.warn("mapping file not found. usage default mapping config");
60
+        }
66 61
 
67 62
         CreateIndexResponse createIndexResponse = restHighLevelClient.indices().create(request, RequestOptions.DEFAULT);
68
-
69 63
         return createIndexResponse.isAcknowledged();
70 64
 
71 65
     }

+ 8 - 3
elastic-publish-service/src/main/java/com/vcarecity/publish/elastic/service/impl/ElasticLoadDataServiceImpl.java 查看文件

@@ -25,6 +25,7 @@ public class ElasticLoadDataServiceImpl implements ElasticLoadDataService {
25 25
     private final ElasticUpdateService elasticUpdateService;
26 26
     private final ElasticIndexService elasticIndexService;
27 27
     private final int pageCount;
28
+    private final String index;
28 29
 
29 30
     public ElasticLoadDataServiceImpl(UnitMapper unitMapper,
30 31
                                       ElasticUpdateService elasticUpdateService,
@@ -33,18 +34,22 @@ public class ElasticLoadDataServiceImpl implements ElasticLoadDataService {
33 34
         this.elasticUpdateService = elasticUpdateService;
34 35
         this.elasticIndexService = elasticIndexService;
35 36
         this.pageCount = ElasticConstant.QUERY_PAGE_COUNT;
37
+        this.index = ElasticConstant.UNIT_AGENCY_INDEX;
36 38
     }
37 39
 
38 40
 
39 41
     @Override
40 42
     public void loadData() throws IOException {
41 43
 
42
-        boolean exist = elasticIndexService.indexExist(ElasticConstant.UNIT_AGENCY_INDEX);
44
+        boolean exist = elasticIndexService.indexExist(index);
43 45
         if (exist) {
44
-            logger.warn("elastic index = [{}] already exits", ElasticConstant.UNIT_AGENCY_INDEX);
45
-            elasticIndexService.deleteIndex(ElasticConstant.UNIT_AGENCY_INDEX);
46
+            logger.warn("elastic index = [{}] already exits", index);
47
+            elasticIndexService.deleteIndex(index);
46 48
         }
47 49
 
50
+        boolean createResult = elasticIndexService.createIndex(this.index);
51
+        logger.info("create elastic index = [{}], create result = {}", index, createResult);
52
+
48 53
         long allTime = System.currentTimeMillis();
49 54
 
50 55
         // calc handler count

+ 1 - 1
elastic-publish-service/src/main/java/com/vcarecity/publish/pojo/dto/UnitAgencyDTO.java 查看文件

@@ -12,8 +12,8 @@ import lombok.ToString;
12 12
 @EqualsAndHashCode(callSuper = true)
13 13
 @Data
14 14
 public class UnitAgencyDTO extends UnitIdDTO {
15
+    private String dtuNo;
15 16
     private String agencyName;
16
-    private String agencyDetail;
17 17
     private String nameOfBuilding;
18 18
     private String unitType;
19 19
     private String unitUpdateStamp;

+ 53 - 0
elastic-publish-service/src/main/java/com/vcarecity/publish/service/LoadDataStatusService.java 查看文件

@@ -0,0 +1,53 @@
1
+package com.vcarecity.publish.service;
2
+
3
+/**
4
+ * @author VcKerry on 12/26/19
5
+ */
6
+
7
+public interface LoadDataStatusService {
8
+
9
+    /**
10
+     * 数据未加载
11
+     */
12
+    int DATA_STATUS_NOT_LOAD = -1;
13
+    /**
14
+     * 数据加载中
15
+     */
16
+    int DATA_STATUS_LOADING = 0;
17
+    /**
18
+     * 数据加载完成
19
+     */
20
+    int DATA_STATUS_LOADED = 1;
21
+
22
+
23
+    /**
24
+     * 获取当前状态
25
+     *
26
+     * @return
27
+     */
28
+    int getStatus();
29
+
30
+    /**
31
+     * 已经加载过了?
32
+     *
33
+     * @return
34
+     */
35
+    default boolean isLoaded() {
36
+        return getStatus() == DATA_STATUS_LOADED;
37
+    }
38
+
39
+    /**
40
+     * set status
41
+     *
42
+     * @param newStatus
43
+     */
44
+    void setStatus(int newStatus);
45
+
46
+    /**
47
+     * set loaded
48
+     */
49
+    default void setLoaded() {
50
+        setStatus(DATA_STATUS_LOADED);
51
+    }
52
+
53
+}

+ 30 - 0
elastic-publish-service/src/main/java/com/vcarecity/publish/service/impl/LoadDataStatusServiceImpl.java 查看文件

@@ -0,0 +1,30 @@
1
+package com.vcarecity.publish.service.impl;
2
+
3
+import com.vcarecity.publish.service.LoadDataStatusService;
4
+import org.springframework.stereotype.Service;
5
+
6
+import java.util.concurrent.atomic.AtomicInteger;
7
+
8
+/**
9
+ * @author VcKerry on 12/26/19
10
+ */
11
+
12
+@Service
13
+public class LoadDataStatusServiceImpl implements LoadDataStatusService {
14
+
15
+    private AtomicInteger dataStatus;
16
+
17
+    public LoadDataStatusServiceImpl() {
18
+        this.dataStatus = new AtomicInteger(DATA_STATUS_NOT_LOAD);
19
+    }
20
+
21
+    @Override
22
+    public int getStatus() {
23
+        return dataStatus.get();
24
+    }
25
+
26
+    @Override
27
+    public void setStatus(int newStatus) {
28
+        dataStatus.set(newStatus);
29
+    }
30
+}

+ 10 - 3
elastic-publish-service/src/main/java/com/vcarecity/publish/sql/service/impl/UnitServiceImpl.java 查看文件

@@ -38,12 +38,19 @@ public class UnitServiceImpl implements UnitService {
38 38
     private final RestHighLevelClient restHighLevelClient;
39 39
     private final ObjectMapper objectMapper;
40 40
 
41
-    static final String[] SEARCH_KEY_NAMES = new String[]{
41
+    /*static final String[] SEARCH_KEY_NAMES = new String[]{
42 42
             "dtuNo.keyword",
43 43
             "agencyName.keyword",
44
-            //"agencyDetail.keyword",
45 44
             "unitType.keyword",
46 45
             "nameOfBuilding.keyword",
46
+    };*/
47
+
48
+
49
+    static final String[] SEARCH_KEY_NAMES = new String[]{
50
+            "dtuNo",
51
+            "agencyName",
52
+            "unitType",
53
+            "nameOfBuilding",
47 54
     };
48 55
 
49 56
     static final String[] MATCH_KEY_NAMES = new String[]{
@@ -330,7 +337,7 @@ public class UnitServiceImpl implements UnitService {
330 337
 
331 338
         for (String kn : SEARCH_KEY_NAMES) {
332 339
             QueryBuilder queryBuilder = QueryBuilders.wildcardQuery(kn, "*" + keyword + "*");
333
-            // QueryBuilder queryBuilder = QueryBuilders.matchQuery(kn, keyword);
340
+            // QueryBuilder queryBuilder = QueryBuilders.(kn, keyword);
334 341
             boolQueryBuilder.should(queryBuilder);
335 342
         }
336 343
         return boolQueryBuilder;

+ 9 - 1
elastic-publish-service/src/main/java/com/vcarecity/publish/task/CheckUpdateTask.java 查看文件

@@ -6,6 +6,7 @@ import com.vcarecity.publish.entity.UnitAgencyMergeEntity;
6 6
 import com.vcarecity.publish.mapper.AgencyMapper;
7 7
 import com.vcarecity.publish.mapper.UnitMapper;
8 8
 import com.vcarecity.publish.service.CheckTimeService;
9
+import com.vcarecity.publish.service.LoadDataStatusService;
9 10
 import com.vcarecity.publish.util.DateUtil;
10 11
 import lombok.extern.slf4j.Slf4j;
11 12
 import org.springframework.scheduling.annotation.Scheduled;
@@ -26,16 +27,18 @@ public class CheckUpdateTask {
26 27
 
27 28
     private final CheckTimeService checkTimeService;
28 29
     private final ElasticUpdateService elasticUpdateService;
30
+    private final LoadDataStatusService loadDataStatusService;
29 31
     private final AgencyMapper agencyMapper;
30 32
     private final UnitMapper unitMapper;
31 33
 
32 34
 
33 35
     public CheckUpdateTask(CheckTimeService checkTimeService,
34 36
                            ElasticUpdateService elasticUpdateService,
35
-                           AgencyMapper agencyMapper,
37
+                           LoadDataStatusService loadDataStatusService, AgencyMapper agencyMapper,
36 38
                            UnitMapper unitMapper) {
37 39
         this.checkTimeService = checkTimeService;
38 40
         this.elasticUpdateService = elasticUpdateService;
41
+        this.loadDataStatusService = loadDataStatusService;
39 42
         this.agencyMapper = agencyMapper;
40 43
         this.unitMapper = unitMapper;
41 44
     }
@@ -44,6 +47,11 @@ public class CheckUpdateTask {
44 47
     @Scheduled(initialDelay = 3 * 1000L, fixedDelay = ElasticConstant.CHECK_TIME_INTERVAL)
45 48
     public void checkUpdateTask() {
46 49
 
50
+        if (!loadDataStatusService.isLoaded()) {
51
+            return;
52
+        }
53
+
54
+
47 55
         // 当前更新时间
48 56
         long curCheckTime = System.currentTimeMillis();
49 57
         String toDateTime = LocalDateTime.ofInstant(new Date(curCheckTime).toInstant(), ZoneId.systemDefault()).format(DateUtil.DATE_TIME_FORMATTER);

+ 19 - 0
elastic-publish-service/src/main/java/com/vcarecity/publish/util/Utils.java 查看文件

@@ -1,5 +1,11 @@
1 1
 package com.vcarecity.publish.util;
2 2
 
3
+import java.io.File;
4
+import java.io.IOException;
5
+import java.nio.file.FileSystemNotFoundException;
6
+import java.nio.file.Files;
7
+import java.util.List;
8
+
3 9
 /**
4 10
  * @author VcKerry on 12/19/19
5 11
  */
@@ -29,4 +35,17 @@ public class Utils {
29 35
     }
30 36
 
31 37
 
38
+    public static String readFile(String filePath) throws IOException {
39
+        return readFile(new File(filePath));
40
+    }
41
+
42
+    public static String readFile(File file) throws IOException {
43
+        if (!file.exists()) {
44
+            throw new FileSystemNotFoundException(file.getAbsolutePath());
45
+        }
46
+        List<String> strings = Files.readAllLines(file.toPath());
47
+        return String.join("\n", strings);
48
+    }
49
+
50
+
32 51
 }

+ 2 - 0
elastic-publish-service/src/main/resources/application-beta.yml 查看文件

@@ -24,5 +24,7 @@ mybatis:
24 24
     map-underscore-to-camel-case: true
25 25
 debug: true
26 26
 app:
27
+  index:
28
+    config: index-text
27 29
   scheduling:
28 30
     enable: true

+ 4 - 2
elastic-publish-service/src/main/resources/application-dev.yml 查看文件

@@ -1,5 +1,5 @@
1 1
 server:
2
-  port: 7080
2
+  port: 8092
3 3
 spring:
4 4
   datasource:
5 5
     url: jdbc:mysql:replication://192.168.10.210:6446,192.168.10.210:6447/fmmp?serverTimezone=Asia/Shanghai
@@ -11,7 +11,7 @@ spring:
11 11
         - http://192.168.10.241:9200
12 12
         - http://192.168.10.242:9200
13 13
         - http://192.168.10.243:9200
14
-      username: elastic
14
+      username: kerry
15 15
       password: abcd!234
16 16
   redis:
17 17
     database: 2
@@ -25,5 +25,7 @@ mybatis:
25 25
     map-underscore-to-camel-case: true
26 26
 debug: true
27 27
 app:
28
+  index:
29
+    config: index-text
28 30
   scheduling:
29 31
     enable: false

+ 11 - 2
elastic-publish-service/src/test/java/com/vcarecity/publish/elastic/service/impl/ElasticIndexServiceImplTest.java 查看文件

@@ -1,26 +1,35 @@
1 1
 package com.vcarecity.publish.elastic.service.impl;
2 2
 
3
+import com.vcarecity.publish.constants.ElasticConstant;
3 4
 import com.vcarecity.publish.elastic.service.ElasticIndexService;
4 5
 import org.junit.jupiter.api.Test;
5 6
 import org.springframework.beans.factory.annotation.Autowired;
6 7
 import org.springframework.boot.test.context.SpringBootTest;
8
+import org.springframework.test.context.TestPropertySource;
7 9
 
8 10
 import java.io.IOException;
9 11
 
12
+@TestPropertySource(properties = "app.scheduling.enable=false")
10 13
 @SpringBootTest
11 14
 class ElasticIndexServiceImplTest {
12 15
 
13 16
     @Autowired
14 17
     private ElasticIndexService elasticIndexService;
15 18
 
19
+    public static final String INDEX = ElasticConstant.UNIT_AGENCY_INDEX;
16 20
 
17 21
     @Test
18
-    void indexExist() {
22
+    void indexExist() throws Exception {
23
+        boolean exist = elasticIndexService.indexExist(INDEX);
24
+        if (exist) {
25
+            elasticIndexService.deleteIndex(INDEX);
26
+        }
27
+        elasticIndexService.createIndex(INDEX);
19 28
     }
20 29
 
21 30
     @Test
22 31
     void createIndex() throws IOException {
23
-        elasticIndexService.createIndex("test");
32
+
24 33
     }
25 34
 
26 35
     @Test

+ 18 - 0
elastic-publish-service/src/test/java/com/vcarecity/publish/util/UtilsTest.java 查看文件

@@ -0,0 +1,18 @@
1
+package com.vcarecity.publish.util;
2
+
3
+import org.junit.jupiter.api.Test;
4
+
5
+import java.io.IOException;
6
+
7
+import static org.junit.jupiter.api.Assertions.*;
8
+
9
+class UtilsTest {
10
+
11
+    @Test
12
+    void readFile() throws IOException {
13
+        String s = Utils.readFile("mapping/unit-agency.mapping.json");
14
+        System.out.println("-----");
15
+        System.out.println(s);
16
+        System.out.println("-----");
17
+    }
18
+}