Browse Source

大小写问题

kerry 5 years ago
parent
commit
8f0620fbf7
21 changed files with 411 additions and 55 deletions
  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 View File

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 View File

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 View File

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 View File

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 View File

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 View File

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 View File

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

+ 2 - 2
elastic-publish-service/req/main-controller.http View File

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

+ 12 - 13
elastic-publish-service/src/main/java/com/vcarecity/publish/controller/MainController.java View File

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

1
 package com.vcarecity.publish.elastic.service.impl;
1
 package com.vcarecity.publish.elastic.service.impl;
2
 
2
 
3
 import com.vcarecity.publish.elastic.service.ElasticIndexService;
3
 import com.vcarecity.publish.elastic.service.ElasticIndexService;
4
+import com.vcarecity.publish.util.Utils;
4
 import lombok.extern.slf4j.Slf4j;
5
 import lombok.extern.slf4j.Slf4j;
5
 import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest;
6
 import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest;
6
 import org.elasticsearch.client.RequestOptions;
7
 import org.elasticsearch.client.RequestOptions;
9
 import org.elasticsearch.client.indices.CreateIndexResponse;
10
 import org.elasticsearch.client.indices.CreateIndexResponse;
10
 import org.elasticsearch.client.indices.GetIndexRequest;
11
 import org.elasticsearch.client.indices.GetIndexRequest;
11
 import org.elasticsearch.common.xcontent.XContentType;
12
 import org.elasticsearch.common.xcontent.XContentType;
13
+import org.springframework.beans.factory.annotation.Value;
12
 import org.springframework.stereotype.Service;
14
 import org.springframework.stereotype.Service;
13
 
15
 
16
+import java.io.File;
14
 import java.io.IOException;
17
 import java.io.IOException;
15
 import java.util.List;
18
 import java.util.List;
16
 
19
 
22
 @Service
25
 @Service
23
 public class ElasticIndexServiceImpl implements ElasticIndexService {
26
 public class ElasticIndexServiceImpl implements ElasticIndexService {
24
 
27
 
28
+    @Value("${app.index.config}")
29
+    private String indexConfig;
30
+
25
     private final RestHighLevelClient restHighLevelClient;
31
     private final RestHighLevelClient restHighLevelClient;
26
 
32
 
27
     public ElasticIndexServiceImpl(RestHighLevelClient restHighLevelClient) {
33
     public ElasticIndexServiceImpl(RestHighLevelClient restHighLevelClient) {
36
 
42
 
37
     @Override
43
     @Override
38
     public boolean createIndex(String index) throws IOException {
44
     public boolean createIndex(String index) throws IOException {
39
-
40
         CreateIndexRequest request = new CreateIndexRequest(index);
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
         CreateIndexResponse createIndexResponse = restHighLevelClient.indices().create(request, RequestOptions.DEFAULT);
62
         CreateIndexResponse createIndexResponse = restHighLevelClient.indices().create(request, RequestOptions.DEFAULT);
68
-
69
         return createIndexResponse.isAcknowledged();
63
         return createIndexResponse.isAcknowledged();
70
 
64
 
71
     }
65
     }

+ 8 - 3
elastic-publish-service/src/main/java/com/vcarecity/publish/elastic/service/impl/ElasticLoadDataServiceImpl.java View File

25
     private final ElasticUpdateService elasticUpdateService;
25
     private final ElasticUpdateService elasticUpdateService;
26
     private final ElasticIndexService elasticIndexService;
26
     private final ElasticIndexService elasticIndexService;
27
     private final int pageCount;
27
     private final int pageCount;
28
+    private final String index;
28
 
29
 
29
     public ElasticLoadDataServiceImpl(UnitMapper unitMapper,
30
     public ElasticLoadDataServiceImpl(UnitMapper unitMapper,
30
                                       ElasticUpdateService elasticUpdateService,
31
                                       ElasticUpdateService elasticUpdateService,
33
         this.elasticUpdateService = elasticUpdateService;
34
         this.elasticUpdateService = elasticUpdateService;
34
         this.elasticIndexService = elasticIndexService;
35
         this.elasticIndexService = elasticIndexService;
35
         this.pageCount = ElasticConstant.QUERY_PAGE_COUNT;
36
         this.pageCount = ElasticConstant.QUERY_PAGE_COUNT;
37
+        this.index = ElasticConstant.UNIT_AGENCY_INDEX;
36
     }
38
     }
37
 
39
 
38
 
40
 
39
     @Override
41
     @Override
40
     public void loadData() throws IOException {
42
     public void loadData() throws IOException {
41
 
43
 
42
-        boolean exist = elasticIndexService.indexExist(ElasticConstant.UNIT_AGENCY_INDEX);
44
+        boolean exist = elasticIndexService.indexExist(index);
43
         if (exist) {
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
         long allTime = System.currentTimeMillis();
53
         long allTime = System.currentTimeMillis();
49
 
54
 
50
         // calc handler count
55
         // calc handler count

+ 1 - 1
elastic-publish-service/src/main/java/com/vcarecity/publish/pojo/dto/UnitAgencyDTO.java View File

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

+ 53 - 0
elastic-publish-service/src/main/java/com/vcarecity/publish/service/LoadDataStatusService.java View File

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 View File

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 View File

38
     private final RestHighLevelClient restHighLevelClient;
38
     private final RestHighLevelClient restHighLevelClient;
39
     private final ObjectMapper objectMapper;
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
             "dtuNo.keyword",
42
             "dtuNo.keyword",
43
             "agencyName.keyword",
43
             "agencyName.keyword",
44
-            //"agencyDetail.keyword",
45
             "unitType.keyword",
44
             "unitType.keyword",
46
             "nameOfBuilding.keyword",
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
     static final String[] MATCH_KEY_NAMES = new String[]{
56
     static final String[] MATCH_KEY_NAMES = new String[]{
330
 
337
 
331
         for (String kn : SEARCH_KEY_NAMES) {
338
         for (String kn : SEARCH_KEY_NAMES) {
332
             QueryBuilder queryBuilder = QueryBuilders.wildcardQuery(kn, "*" + keyword + "*");
339
             QueryBuilder queryBuilder = QueryBuilders.wildcardQuery(kn, "*" + keyword + "*");
333
-            // QueryBuilder queryBuilder = QueryBuilders.matchQuery(kn, keyword);
340
+            // QueryBuilder queryBuilder = QueryBuilders.(kn, keyword);
334
             boolQueryBuilder.should(queryBuilder);
341
             boolQueryBuilder.should(queryBuilder);
335
         }
342
         }
336
         return boolQueryBuilder;
343
         return boolQueryBuilder;

+ 9 - 1
elastic-publish-service/src/main/java/com/vcarecity/publish/task/CheckUpdateTask.java View File

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

1
 package com.vcarecity.publish.util;
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
  * @author VcKerry on 12/19/19
10
  * @author VcKerry on 12/19/19
5
  */
11
  */
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 View File

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

+ 4 - 2
elastic-publish-service/src/main/resources/application-dev.yml View File

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

+ 11 - 2
elastic-publish-service/src/test/java/com/vcarecity/publish/elastic/service/impl/ElasticIndexServiceImplTest.java View File

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

+ 18 - 0
elastic-publish-service/src/test/java/com/vcarecity/publish/util/UtilsTest.java View File

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
+}