Explorar el Código

ADD req fields

kerry hace 5 años
padre
commit
698e732291
Se han modificado 26 ficheros con 398 adiciones y 49 borrados
  1. 10 2
      elastic-publish-service/req/main-controller.http
  2. 0 2
      elastic-publish-service/src/main/java/com/vcarecity/publish/ElasticPublishApplication.java
  3. 1 2
      elastic-publish-service/src/main/java/com/vcarecity/publish/config/MapperConfig.java
  4. 11 0
      elastic-publish-service/src/main/java/com/vcarecity/publish/config/SchedulingConfiguration.java
  5. 3 4
      elastic-publish-service/src/main/java/com/vcarecity/publish/controller/MainController.java
  6. 12 2
      elastic-publish-service/src/main/java/com/vcarecity/publish/elastic/service/ElasticIndexService.java
  7. 8 0
      elastic-publish-service/src/main/java/com/vcarecity/publish/elastic/service/ElasticQueryService.java
  8. 13 5
      elastic-publish-service/src/main/java/com/vcarecity/publish/elastic/service/impl/ElasticIndexServiceImpl.java
  9. 11 1
      elastic-publish-service/src/main/java/com/vcarecity/publish/elastic/service/impl/ElasticLoadDataServiceImpl.java
  10. 37 1
      elastic-publish-service/src/main/java/com/vcarecity/publish/elastic/service/impl/ElasticQueryServiceImpl.java
  11. 7 2
      elastic-publish-service/src/main/java/com/vcarecity/publish/elastic/service/impl/ElasticUpdateServiceImpl.java
  12. 8 0
      elastic-publish-service/src/main/java/com/vcarecity/publish/entity/UnitAgencyMergeEntity.java
  13. 4 0
      elastic-publish-service/src/main/java/com/vcarecity/publish/pojo/dto/UnitAgencyDTO.java
  14. 5 0
      elastic-publish-service/src/main/java/com/vcarecity/publish/pojo/query/UnitAgencyQuery.java
  15. 3 5
      elastic-publish-service/src/main/java/com/vcarecity/publish/sql/service/UnitService.java
  16. 59 13
      elastic-publish-service/src/main/java/com/vcarecity/publish/sql/service/impl/UnitServiceImpl.java
  17. 32 0
      elastic-publish-service/src/main/java/com/vcarecity/publish/util/Utils.java
  18. 5 5
      elastic-publish-service/src/main/resources/application-dev.yml
  19. 38 0
      elastic-publish-service/src/main/resources/logback-spring.xml
  20. 10 1
      elastic-publish-service/src/main/resources/mapper/AgencyMapper.xml
  21. 18 4
      elastic-publish-service/src/main/resources/mapper/UnitMapper.xml
  22. 41 0
      elastic-publish-service/src/test/java/com/vcarecity/publish/config/MapperConfigTest.java
  23. 20 0
      elastic-publish-service/src/test/java/com/vcarecity/publish/elastic/service/impl/ElasticLoadDataServiceImplTest.java
  24. 21 0
      elastic-publish-service/src/test/java/com/vcarecity/publish/elastic/service/impl/ElasticQueryServiceImplTest.java
  25. 18 0
      elastic-publish-service/src/test/java/com/vcarecity/publish/mapper/AgencyMapperTest.java
  26. 3 0
      elastic-publish-service/src/test/java/com/vcarecity/publish/service/impl/ElasticUpdateServiceImplTest.java

+ 10 - 2
elastic-publish-service/req/main-controller.http Ver fichero

@@ -5,7 +5,11 @@ Content-Type: application/json
5 5
   "agencyPath": "/1",
6 6
   "keyword": "鱼峰区",
7 7
   "page": 2,
8
-  "size": 10
8
+  "size": 10,
9
+  "regulatoryLevelId": "27,28",
10
+  "property": "",
11
+  "classify": "",
12
+  "agencyAttributeClassId": ""
9 13
 }
10 14
 
11 15
 ### unitId 信息
@@ -18,7 +22,11 @@ Content-Type: application/json
18 22
   "agencyPath": "/1",
19 23
   "keyword": "鱼峰区",
20 24
   "page": 2,
21
-  "size": 10
25
+  "size": 10,
26
+  "regulatoryLevelId": "27,28",
27
+  "property": "",
28
+  "classify": "",
29
+  "agencyAttributeClassId": ""
22 30
 }
23 31
 
24 32
 ### 详情信息

+ 0 - 2
elastic-publish-service/src/main/java/com/vcarecity/publish/ElasticPublishApplication.java Ver fichero

@@ -3,14 +3,12 @@ package com.vcarecity.publish;
3 3
 import org.mybatis.spring.annotation.MapperScan;
4 4
 import org.springframework.boot.SpringApplication;
5 5
 import org.springframework.boot.autoconfigure.SpringBootApplication;
6
-import org.springframework.scheduling.annotation.EnableScheduling;
7 6
 
8 7
 /**
9 8
  * @author Kerry on 19/12/11
10 9
  */
11 10
 
12 11
 
13
-@EnableScheduling
14 12
 @MapperScan("com.vcarecity.publish.mapper")
15 13
 @SpringBootApplication
16 14
 public class ElasticPublishApplication {

+ 1 - 2
elastic-publish-service/src/main/java/com/vcarecity/publish/config/MapperConfig.java Ver fichero

@@ -1,6 +1,5 @@
1 1
 package com.vcarecity.publish.config;
2 2
 
3
-import com.fasterxml.jackson.annotation.JsonInclude;
4 3
 import com.fasterxml.jackson.databind.DeserializationFeature;
5 4
 import com.fasterxml.jackson.databind.ObjectMapper;
6 5
 import org.springframework.context.annotation.Bean;
@@ -16,7 +15,7 @@ public class MapperConfig {
16 15
     @Bean
17 16
     public ObjectMapper objectMapper() {
18 17
         ObjectMapper objectMapper = new ObjectMapper();
19
-        objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
18
+        // objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
20 19
         objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
21 20
         return objectMapper;
22 21
     }

+ 11 - 0
elastic-publish-service/src/main/java/com/vcarecity/publish/config/SchedulingConfiguration.java Ver fichero

@@ -0,0 +1,11 @@
1
+package com.vcarecity.publish.config;
2
+
3
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
4
+import org.springframework.context.annotation.Configuration;
5
+import org.springframework.scheduling.annotation.EnableScheduling;
6
+
7
+@ConditionalOnProperty(value = "app.scheduling.enable", havingValue = "true", matchIfMissing = true)
8
+@Configuration
9
+@EnableScheduling
10
+public class SchedulingConfiguration {
11
+}

+ 3 - 4
elastic-publish-service/src/main/java/com/vcarecity/publish/controller/MainController.java Ver fichero

@@ -30,16 +30,15 @@ public class MainController {
30 30
 
31 31
     @PostMapping("/query-unit-agency")
32 32
     public ApiResult queryUnitAgency(@RequestBody @Valid UnitAgencyQuery unitAgencyQuery) throws IOException {
33
-        final List<UnitAgencyDTO> unitAgencyByQuery = unitService.getUnitAgencyByQuery(unitAgencyQuery.getAgencyPath(), unitAgencyQuery.getKeyword(),
34
-                unitAgencyQuery.getPage(), unitAgencyQuery.getSize(), ElasticConstant.UNIT_AGENCY_INDEX);
33
+        final List<UnitAgencyDTO> unitAgencyByQuery = unitService.getUnitAgencyByQuery(unitAgencyQuery, ElasticConstant.UNIT_AGENCY_INDEX);
34
+
35 35
         List<Long> data = unitAgencyByQuery.stream().map(UnitAgencyDTO::getUnitId).collect(Collectors.toList());
36 36
         return ApiResult.builder().status(ApiStatus.SUCCESS_CODE).data(data).build();
37 37
     }
38 38
 
39 39
     @PostMapping("/test/query-unit-agency")
40 40
     public ApiResult testQueryUnitAgency(@RequestBody @Valid UnitAgencyQuery unitAgencyQuery) throws IOException {
41
-        List<UnitAgencyDTO> data = unitService.getUnitAgencyByQuery(unitAgencyQuery.getAgencyPath(), unitAgencyQuery.getKeyword(),
42
-                unitAgencyQuery.getPage(), unitAgencyQuery.getSize(), ElasticConstant.UNIT_AGENCY_INDEX);
41
+        List<UnitAgencyDTO> data = unitService.getUnitAgencyByQuery(unitAgencyQuery, ElasticConstant.UNIT_AGENCY_INDEX);
43 42
         return ApiResult.builder().status(ApiStatus.SUCCESS_CODE).data(data).build();
44 43
     }
45 44
 

+ 12 - 2
elastic-publish-service/src/main/java/com/vcarecity/publish/elastic/service/ElasticIndexService.java Ver fichero

@@ -1,5 +1,6 @@
1 1
 package com.vcarecity.publish.elastic.service;
2 2
 
3
+import java.io.IOException;
3 4
 import java.util.List;
4 5
 
5 6
 /**
@@ -10,11 +11,15 @@ public interface ElasticIndexService {
10 11
 
11 12
     /**
12 13
      * index 是否存在
14
+     * <a href="https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/java-rest-high-indices-exists.html">
15
+     * API
16
+     * </a>
13 17
      *
14 18
      * @param index
15 19
      * @return
20
+     * @throws IOException
16 21
      */
17
-    boolean indexExist(String index);
22
+    boolean indexExist(String index) throws IOException;
18 23
 
19 24
     /**
20 25
      * create index
@@ -26,9 +31,14 @@ public interface ElasticIndexService {
26 31
     /**
27 32
      * delete index
28 33
      *
34
+     * <a href="https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/java-rest-high-delete-index.html">
35
+     * API
36
+     * </a>
37
+     *
29 38
      * @param indices
39
+     * @throws IOException
30 40
      */
31
-    void deleteIndex(String... indices);
41
+    void deleteIndex(String... indices) throws IOException;
32 42
 
33 43
 
34 44
     /**

+ 8 - 0
elastic-publish-service/src/main/java/com/vcarecity/publish/elastic/service/ElasticQueryService.java Ver fichero

@@ -1,10 +1,18 @@
1 1
 package com.vcarecity.publish.elastic.service;
2 2
 
3
+import java.io.IOException;
4
+
3 5
 /**
4 6
  * @author VcKerry on 12/17/19
5 7
  */
6 8
 
7 9
 public interface ElasticQueryService {
8 10
 
11
+    /**
12
+     * for test
13
+     *
14
+     * @throws IOException
15
+     */
16
+    void testQuery() throws IOException;
9 17
 
10 18
 }

+ 13 - 5
elastic-publish-service/src/main/java/com/vcarecity/publish/elastic/service/impl/ElasticIndexServiceImpl.java Ver fichero

@@ -1,15 +1,21 @@
1 1
 package com.vcarecity.publish.elastic.service.impl;
2 2
 
3 3
 import com.vcarecity.publish.elastic.service.ElasticIndexService;
4
+import lombok.extern.slf4j.Slf4j;
5
+import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest;
6
+import org.elasticsearch.client.RequestOptions;
4 7
 import org.elasticsearch.client.RestHighLevelClient;
8
+import org.elasticsearch.client.indices.GetIndexRequest;
5 9
 import org.springframework.stereotype.Service;
6 10
 
11
+import java.io.IOException;
7 12
 import java.util.List;
8 13
 
9 14
 /**
10 15
  * @author kerryzhang on 2019/12/17
11 16
  */
12 17
 
18
+@Slf4j
13 19
 @Service
14 20
 public class ElasticIndexServiceImpl implements ElasticIndexService {
15 21
 
@@ -20,9 +26,9 @@ public class ElasticIndexServiceImpl implements ElasticIndexService {
20 26
     }
21 27
 
22 28
     @Override
23
-    public boolean indexExist(String index) {
24
-
25
-        return false;
29
+    public boolean indexExist(String index) throws IOException {
30
+        GetIndexRequest request = new GetIndexRequest(index);
31
+        return restHighLevelClient.indices().exists(request, RequestOptions.DEFAULT);
26 32
     }
27 33
 
28 34
     @Override
@@ -31,8 +37,10 @@ public class ElasticIndexServiceImpl implements ElasticIndexService {
31 37
     }
32 38
 
33 39
     @Override
34
-    public void deleteIndex(String... indices) {
35
-
40
+    public void deleteIndex(String... indices) throws IOException {
41
+        logger.warn("delete elastic index = {}", indices);
42
+        DeleteIndexRequest request = new DeleteIndexRequest(indices);
43
+        restHighLevelClient.indices().delete(request, RequestOptions.DEFAULT);
36 44
     }
37 45
 
38 46
     @Override

+ 11 - 1
elastic-publish-service/src/main/java/com/vcarecity/publish/elastic/service/impl/ElasticLoadDataServiceImpl.java Ver fichero

@@ -1,6 +1,7 @@
1 1
 package com.vcarecity.publish.elastic.service.impl;
2 2
 
3 3
 import com.vcarecity.publish.constants.ElasticConstant;
4
+import com.vcarecity.publish.elastic.service.ElasticIndexService;
4 5
 import com.vcarecity.publish.elastic.service.ElasticLoadDataService;
5 6
 import com.vcarecity.publish.elastic.service.ElasticUpdateService;
6 7
 import com.vcarecity.publish.entity.UnitAgencyMergeEntity;
@@ -22,12 +23,15 @@ public class ElasticLoadDataServiceImpl implements ElasticLoadDataService {
22 23
 
23 24
     private final UnitMapper unitMapper;
24 25
     private final ElasticUpdateService elasticUpdateService;
26
+    private final ElasticIndexService elasticIndexService;
25 27
     private final int pageCount;
26 28
 
27 29
     public ElasticLoadDataServiceImpl(UnitMapper unitMapper,
28
-                                      ElasticUpdateService elasticUpdateService) {
30
+                                      ElasticUpdateService elasticUpdateService,
31
+                                      ElasticIndexService elasticIndexService) {
29 32
         this.unitMapper = unitMapper;
30 33
         this.elasticUpdateService = elasticUpdateService;
34
+        this.elasticIndexService = elasticIndexService;
31 35
         this.pageCount = ElasticConstant.QUERY_PAGE_COUNT;
32 36
     }
33 37
 
@@ -35,6 +39,12 @@ public class ElasticLoadDataServiceImpl implements ElasticLoadDataService {
35 39
     @Override
36 40
     public void loadData() throws IOException {
37 41
 
42
+        boolean exist = elasticIndexService.indexExist(ElasticConstant.UNIT_AGENCY_INDEX);
43
+        if (exist) {
44
+            logger.warn("elastic index = [{}] already exits", ElasticConstant.UNIT_AGENCY_INDEX);
45
+            elasticIndexService.deleteIndex(ElasticConstant.UNIT_AGENCY_INDEX);
46
+        }
47
+
38 48
         long allTime = System.currentTimeMillis();
39 49
 
40 50
         // calc handler count

+ 37 - 1
elastic-publish-service/src/main/java/com/vcarecity/publish/elastic/service/impl/ElasticQueryServiceImpl.java Ver fichero

@@ -1,15 +1,51 @@
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.ElasticQueryService;
5
+import lombok.extern.slf4j.Slf4j;
6
+import org.elasticsearch.action.search.SearchRequest;
7
+import org.elasticsearch.action.search.SearchResponse;
8
+import org.elasticsearch.client.RequestOptions;
9
+import org.elasticsearch.client.RestHighLevelClient;
10
+import org.elasticsearch.index.query.QueryBuilders;
11
+import org.elasticsearch.index.query.TermQueryBuilder;
12
+import org.elasticsearch.search.SearchHit;
13
+import org.elasticsearch.search.builder.SearchSourceBuilder;
4 14
 import org.springframework.stereotype.Service;
5 15
 
6
-import java.util.List;
16
+import java.io.IOException;
7 17
 
8 18
 /**
9 19
  * @author VcKerry on 12/17/19
10 20
  */
11 21
 
22
+@Slf4j
12 23
 @Service
13 24
 public class ElasticQueryServiceImpl implements ElasticQueryService {
14 25
 
26
+    private final RestHighLevelClient restHighLevelClient;
27
+
28
+    public ElasticQueryServiceImpl(RestHighLevelClient restHighLevelClient) {
29
+        this.restHighLevelClient = restHighLevelClient;
30
+    }
31
+
32
+    @Override
33
+    public void testQuery() throws IOException {
34
+
35
+        TermQueryBuilder unitId = QueryBuilders.termQuery("unitId", 39746);
36
+
37
+
38
+        SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
39
+        searchSourceBuilder.query(unitId);
40
+
41
+
42
+        SearchRequest request = new SearchRequest(ElasticConstant.UNIT_AGENCY_INDEX);
43
+        request.source(searchSourceBuilder);
44
+
45
+        SearchResponse response = restHighLevelClient.search(request, RequestOptions.DEFAULT);
46
+        for (SearchHit hit : response.getHits()) {
47
+            logger.debug("{}", hit.getSourceAsString());
48
+        }
49
+
50
+    }
15 51
 }

+ 7 - 2
elastic-publish-service/src/main/java/com/vcarecity/publish/elastic/service/impl/ElasticUpdateServiceImpl.java Ver fichero

@@ -1,6 +1,8 @@
1 1
 package com.vcarecity.publish.elastic.service.impl;
2 2
 
3
+import com.fasterxml.jackson.annotation.JsonInclude;
3 4
 import com.fasterxml.jackson.core.type.TypeReference;
5
+import com.fasterxml.jackson.databind.DeserializationFeature;
4 6
 import com.fasterxml.jackson.databind.ObjectMapper;
5 7
 import com.vcarecity.elastic.util.AgencyPathUtil;
6 8
 import com.vcarecity.elastic.util.SnowFlake;
@@ -47,12 +49,15 @@ public class ElasticUpdateServiceImpl implements ElasticUpdateService {
47 49
     private final AgencyService agencyService;
48 50
 
49 51
     public ElasticUpdateServiceImpl(RestHighLevelClient restHighLevelClient,
50
-                                    ObjectMapper objectMapper,
51 52
                                     AgencyService agencyService) {
52 53
         this.restHighLevelClient = restHighLevelClient;
53
-        this.objectMapper = objectMapper;
54 54
         this.agencyService = agencyService;
55 55
 
56
+        ObjectMapper objectMapper = new ObjectMapper();
57
+        objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
58
+        objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
59
+
60
+        this.objectMapper = objectMapper;
56 61
         this.index = ElasticConstant.UNIT_AGENCY_INDEX;
57 62
     }
58 63
 

+ 8 - 0
elastic-publish-service/src/main/java/com/vcarecity/publish/entity/UnitAgencyMergeEntity.java Ver fichero

@@ -30,4 +30,12 @@ public class UnitAgencyMergeEntity {
30 30
     private String unitType;
31 31
 
32 32
     private Integer isDeleted;
33
+
34
+    private Integer property;
35
+
36
+    private Integer classify;
37
+
38
+    private Integer regulatoryLevelId;
39
+
40
+    private Integer agencyAttributeClassId;
33 41
 }

+ 4 - 0
elastic-publish-service/src/main/java/com/vcarecity/publish/pojo/dto/UnitAgencyDTO.java Ver fichero

@@ -12,4 +12,8 @@ public class UnitAgencyDTO {
12 12
     private String agencyName;
13 13
     private String agencyDetail;
14 14
     private String nameOfBuilding;
15
+    private Long classify;
16
+    private Long property;
17
+    private Long regulatoryLevelId;
18
+    private Long agencyAttributeClassId;
15 19
 }

+ 5 - 0
elastic-publish-service/src/main/java/com/vcarecity/publish/pojo/query/UnitAgencyQuery.java Ver fichero

@@ -23,4 +23,9 @@ public class UnitAgencyQuery {
23 23
     @Min(1)
24 24
     private int size = 100;
25 25
 
26
+    private String property;
27
+    private String classify;
28
+    private String regulatoryLevelId;
29
+    private String agencyAttributeClassId;
30
+
26 31
 }

+ 3 - 5
elastic-publish-service/src/main/java/com/vcarecity/publish/sql/service/UnitService.java Ver fichero

@@ -1,6 +1,7 @@
1 1
 package com.vcarecity.publish.sql.service;
2 2
 
3 3
 import com.vcarecity.publish.pojo.dto.UnitAgencyDTO;
4
+import com.vcarecity.publish.pojo.query.UnitAgencyQuery;
4 5
 
5 6
 import java.io.IOException;
6 7
 import java.util.List;
@@ -14,14 +15,11 @@ public interface UnitService {
14 15
     /**
15 16
      * test
16 17
      *
17
-     * @param agencyPath
18
-     * @param inputKeyword
19
-     * @param page
20
-     * @param size
18
+     * @param queryParam
21 19
      * @param indices
22 20
      * @return
23 21
      * @throws IOException
24 22
      */
25
-    List<UnitAgencyDTO> getUnitAgencyByQuery(String agencyPath, String inputKeyword, int page, int size, String... indices) throws IOException;
23
+    List<UnitAgencyDTO> getUnitAgencyByQuery(UnitAgencyQuery queryParam, String... indices) throws IOException;
26 24
 
27 25
 }

+ 59 - 13
elastic-publish-service/src/main/java/com/vcarecity/publish/sql/service/impl/UnitServiceImpl.java Ver fichero

@@ -1,24 +1,24 @@
1 1
 package com.vcarecity.publish.sql.service.impl;
2 2
 
3 3
 import com.fasterxml.jackson.databind.ObjectMapper;
4
+import com.vcarecity.elastic.util.AgencyPathUtil;
4 5
 import com.vcarecity.publish.pojo.dto.UnitAgencyDTO;
6
+import com.vcarecity.publish.pojo.query.UnitAgencyQuery;
5 7
 import com.vcarecity.publish.sql.service.UnitService;
6
-import com.vcarecity.elastic.util.AgencyPathUtil;
8
+import com.vcarecity.publish.util.Utils;
7 9
 import lombok.extern.slf4j.Slf4j;
8 10
 import org.elasticsearch.action.search.SearchRequest;
9 11
 import org.elasticsearch.action.search.SearchResponse;
10 12
 import org.elasticsearch.client.RequestOptions;
11 13
 import org.elasticsearch.client.RestHighLevelClient;
12
-import org.elasticsearch.index.query.BoolQueryBuilder;
13
-import org.elasticsearch.index.query.QueryBuilder;
14
-import org.elasticsearch.index.query.QueryBuilders;
15
-import org.elasticsearch.index.query.TermQueryBuilder;
14
+import org.elasticsearch.index.query.*;
16 15
 import org.elasticsearch.search.SearchHit;
17 16
 import org.elasticsearch.search.SearchHits;
18 17
 import org.elasticsearch.search.builder.SearchSourceBuilder;
19 18
 import org.springframework.stereotype.Service;
20 19
 
21 20
 import java.io.IOException;
21
+import java.lang.reflect.Field;
22 22
 import java.util.ArrayList;
23 23
 import java.util.Collections;
24 24
 import java.util.List;
@@ -35,14 +35,21 @@ public class UnitServiceImpl implements UnitService {
35 35
     private final RestHighLevelClient restHighLevelClient;
36 36
     private final ObjectMapper objectMapper;
37 37
 
38
-    static final String[] keyNames = new String[]{
38
+    static final String[] SEARCH_KEY_NAMES = new String[]{
39 39
             "agencyName.keyword",
40 40
             "agencyDetail.keyword",
41 41
             "unitType.keyword",
42 42
             "nameOfBuilding.keyword",
43 43
     };
44 44
 
45
-    static String[] queryColumns = new String[]{"unitId", "nameOfBuilding", "agencyDetail", "agencyName"};
45
+    static final String[] MATCH_KEY_NAMES = new String[]{
46
+            "agencyAttributeClassId",
47
+            "regulatoryLevelId",
48
+            "property",
49
+            "classify"
50
+    };
51
+
52
+    static String[] queryColumns = new String[]{"unitId", "nameOfBuilding", "agencyDetail", "agencyName", "agencyAttributeClassId", "regulatoryLevelId", "property", "classify"};
46 53
 
47 54
     public UnitServiceImpl(RestHighLevelClient restHighLevelClient,
48 55
                            ObjectMapper objectMapper) {
@@ -51,13 +58,13 @@ public class UnitServiceImpl implements UnitService {
51 58
     }
52 59
 
53 60
     @Override
54
-    public List<UnitAgencyDTO> getUnitAgencyByQuery(String agencyPath, String inputKeyword, int page, int size, String... indices) throws IOException {
55
-        List<Integer> agencyIdList = AgencyPathUtil.splitAgencyId(agencyPath);
61
+    public List<UnitAgencyDTO> getUnitAgencyByQuery(UnitAgencyQuery queryParam, String... indices) throws IOException {
62
+        List<Integer> agencyIdList = AgencyPathUtil.splitAgencyId(queryParam.getAgencyPath());
56 63
         if (agencyIdList.isEmpty()) {
57 64
             return Collections.emptyList();
58 65
         }
59 66
         QueryBuilder agencyIdBoolQuery = agencyIdListCondition(agencyIdList);
60
-        QueryBuilder keywordBoolQuery = multiInputParamKeywordBool(inputKeyword);
67
+        QueryBuilder keywordBoolQuery = multiInputParamKeywordBool(queryParam.getKeyword());
61 68
 
62 69
         BoolQueryBuilder queryBuilder = QueryBuilders.boolQuery().must(agencyIdBoolQuery);
63 70
 
@@ -65,13 +72,19 @@ public class UnitServiceImpl implements UnitService {
65 72
             queryBuilder.must(keywordBoolQuery);
66 73
         }
67 74
 
75
+        List<QueryBuilder> queryBuilders = arrayParamQuery(queryParam);
76
+        for (QueryBuilder builder : queryBuilders) {
77
+            queryBuilder.must(builder);
78
+        }
79
+
80
+        int from = (queryParam.getPage() - 1) * queryParam.getSize();
68 81
 
69 82
         SearchRequest searchRequest = new SearchRequest();
70 83
         SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
71 84
         searchSourceBuilder.query(queryBuilder);
72 85
         searchSourceBuilder.fetchSource(queryColumns, new String[]{});
73
-        searchSourceBuilder.from((page - 1) * size);
74
-        searchSourceBuilder.size(size);
86
+        searchSourceBuilder.from(from);
87
+        searchSourceBuilder.size(queryParam.getSize());
75 88
         searchRequest.source(searchSourceBuilder);
76 89
         searchRequest.indices(indices);
77 90
 
@@ -296,7 +309,7 @@ public class UnitServiceImpl implements UnitService {
296 309
 
297 310
         final BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
298 311
 
299
-        for (String kn : keyNames) {
312
+        for (String kn : SEARCH_KEY_NAMES) {
300 313
             QueryBuilder queryBuilder = QueryBuilders.wildcardQuery(kn, "*" + keyword + "*");
301 314
             // QueryBuilder queryBuilder = QueryBuilders.matchQuery(kn, keyword);
302 315
             boolQueryBuilder.should(queryBuilder);
@@ -304,4 +317,37 @@ public class UnitServiceImpl implements UnitService {
304 317
         return boolQueryBuilder;
305 318
     }
306 319
 
320
+
321
+    private List<QueryBuilder> arrayParamQuery(UnitAgencyQuery queryParam) {
322
+        List<QueryBuilder> queryArray = new ArrayList<>(MATCH_KEY_NAMES.length);
323
+
324
+        for (String matchKeyName : MATCH_KEY_NAMES) {
325
+
326
+            Object value = null;
327
+            try {
328
+                Field declaredField = UnitAgencyQuery.class.getDeclaredField(matchKeyName);
329
+                declaredField.setAccessible(true);
330
+                value = declaredField.get(queryParam);
331
+
332
+            } catch (NoSuchFieldException | IllegalAccessException e) {
333
+                e.printStackTrace();
334
+            }
335
+            if (value == null) {
336
+                continue;
337
+            }
338
+            String listString = value.toString();
339
+            int[] ints = Utils.paramToArray(listString);
340
+            if (ints.length == 1) {
341
+                TermQueryBuilder termQueryBuilder = QueryBuilders.termQuery(matchKeyName, ints[0]);
342
+                queryArray.add(termQueryBuilder);
343
+            } else if (ints.length > 1) {
344
+                TermsQueryBuilder termsQueryBuilder = QueryBuilders.termsQuery(matchKeyName, ints);
345
+                queryArray.add(termsQueryBuilder);
346
+            }
347
+
348
+        }
349
+
350
+        return queryArray;
351
+    }
352
+
307 353
 }

+ 32 - 0
elastic-publish-service/src/main/java/com/vcarecity/publish/util/Utils.java Ver fichero

@@ -0,0 +1,32 @@
1
+package com.vcarecity.publish.util;
2
+
3
+/**
4
+ * @author VcKerry on 12/19/19
5
+ */
6
+
7
+public class Utils {
8
+
9
+    public static final int[] EMPTY_PARAM = new int[0];
10
+
11
+    public static int[] paramToArray(String input) {
12
+        if (input == null) {
13
+            return EMPTY_PARAM;
14
+        }
15
+        input = input.trim();
16
+        if (input.length() == 0) {
17
+            return EMPTY_PARAM;
18
+        }
19
+
20
+        String[] split = input.split(",");
21
+        if (split.length == 0) {
22
+            return EMPTY_PARAM;
23
+        }
24
+        int[] res = new int[split.length];
25
+        for (int i = 0; i < split.length; i++) {
26
+            res[i] = Integer.parseInt(split[i]);
27
+        }
28
+        return res;
29
+    }
30
+
31
+
32
+}

+ 5 - 5
elastic-publish-service/src/main/resources/application-dev.yml Ver fichero

@@ -18,12 +18,12 @@ spring:
18 18
     host: 192.168.10.112
19 19
     port: 6379
20 20
     password: admin~1(^-^)
21
-logging:
22
-  level:
23
-    com:
24
-      vcarecity: debug
25 21
 mybatis:
26 22
   type-aliases-package: com.vcarecity.publish.entity
27 23
   mapper-locations: classpath:mapper/*.xml
28
-
24
+  configuration:
25
+    map-underscore-to-camel-case: true
29 26
 debug: true
27
+app:
28
+  scheduling:
29
+    enable: false

+ 38 - 0
elastic-publish-service/src/main/resources/logback-spring.xml Ver fichero

@@ -0,0 +1,38 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<configuration scan="true" scanPeriod="120 seconds">
3
+
4
+    <!--spring-boot-2.0.3.RELEASE.jar!/org/springframework/boot/logging/logback/defaults.xml-->
5
+    <include resource="org/springframework/boot/logging/logback/defaults.xml"/>
6
+
7
+
8
+    <!--默认 Appender-->
9
+    <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
10
+        <encoder>
11
+            <pattern>${CONSOLE_LOG_PATTERN}</pattern>
12
+            <charset>utf8</charset>
13
+        </encoder>
14
+    </appender>
15
+
16
+
17
+    <root level="INFO">
18
+        <appender-ref ref="CONSOLE"/>
19
+    </root>
20
+
21
+
22
+    <springProfile name="dev">
23
+
24
+
25
+        <logger name="com.vcarecity" level="DEBUG" additivity="false">
26
+            <appender-ref ref="CONSOLE"/>
27
+        </logger>
28
+
29
+
30
+        <logger name="com.vcarecity.publish.mapper.AgencyMapper" level="INFO" additivity="false">
31
+            <appender-ref ref="CONSOLE"/>
32
+        </logger>
33
+
34
+
35
+    </springProfile>
36
+
37
+
38
+</configuration>

+ 10 - 1
elastic-publish-service/src/main/resources/mapper/AgencyMapper.xml Ver fichero

@@ -23,6 +23,10 @@
23 23
         <result column="NAME_OF_BUILDING" property="nameOfBuilding"/>
24 24
         <result column="UNIT_TYPE_ID" property="unitTypeId"/>
25 25
         <result column="UNIT_TYPE" property="unitType"/>
26
+        <result column="PROPERTY" property="property"/>
27
+        <result column="CLASSIFY" property="classify"/>
28
+        <result column="REGULATORY_LEVEL_ID" property="regulatoryLevelId"/>
29
+        <result column="AGENCY_ATTRIBUTE_CLASS_ID" property="agencyAttributeClassId"/>
26 30
     </resultMap>
27 31
 
28 32
 
@@ -37,7 +41,11 @@
37 41
                TB.BUILDING_ID,
38 42
                TB.NAME_OF_BUILDING,
39 43
                TUT.UNIT_TYPE_ID,
40
-               TUT.UNIT_TYPE
44
+               TUT.UNIT_TYPE,
45
+               TUT.PROPERTY,
46
+               TUT.CLASSIFY,
47
+               TAE.REGULATORY_LEVEL_ID,
48
+               TAE.AGENCY_ATTRIBUTE_CLASS_ID
41 49
         FROM (select *
42 50
               from T_AGENCY I_TAG
43 51
               where UPDATESTAMP between '${fromDate}' and '${toDate}'
@@ -45,6 +53,7 @@
45 53
                  INNER JOIN T_UNIT TU ON TU.AGENCY_ID = TAG.AGENCY_ID
46 54
                  INNER JOIN T_BUILDING TB ON TB.BUILDING_ID = TU.BUILDING_ID
47 55
                  INNER JOIN T_UNIT_TYPE TUT ON TUT.UNIT_TYPE_ID = TU.UNIT_TYPE_ID
56
+                 INNER JOIN T_AGENCY_EXTEND TAE ON TAE.AGENCY_ID = TU.AGENCY_ID
48 57
     </select>
49 58
 
50 59
     <select id="findAgencyNameByAgencyIdList" resultType="agencyEntity" parameterType="list">

+ 18 - 4
elastic-publish-service/src/main/resources/mapper/UnitMapper.xml Ver fichero

@@ -13,6 +13,10 @@
13 13
         <result column="NAME_OF_BUILDING" property="nameOfBuilding"/>
14 14
         <result column="UNIT_TYPE_ID" property="unitTypeId"/>
15 15
         <result column="UNIT_TYPE" property="unitType"/>
16
+        <result column="PROPERTY" property="property"/>
17
+        <result column="CLASSIFY" property="classify"/>
18
+        <result column="REGULATORY_LEVEL_ID" property="regulatoryLevelId"/>
19
+        <result column="AGENCY_ATTRIBUTE_CLASS_ID" property="agencyAttributeClassId"/>
16 20
     </resultMap>
17 21
 
18 22
     <select id="findUpdateList" resultType="unitEntity">
@@ -33,7 +37,11 @@
33 37
                TB.BUILDING_ID,
34 38
                TB.NAME_OF_BUILDING,
35 39
                TUT.UNIT_TYPE_ID,
36
-               TUT.UNIT_TYPE
40
+               TUT.UNIT_TYPE,
41
+               TUT.PROPERTY,
42
+               TUT.CLASSIFY,
43
+               TAE.REGULATORY_LEVEL_ID,
44
+               TAE.AGENCY_ATTRIBUTE_CLASS_ID
37 45
         FROM (select *
38 46
               from T_UNIT I_TU
39 47
               where UPDATESTAMP between '${fromDate}' and '${toDate}'
@@ -41,9 +49,10 @@
41 49
                  INNER JOIN T_AGENCY TAG ON TU.AGENCY_ID = TAG.AGENCY_ID
42 50
                  INNER JOIN T_BUILDING TB ON TB.BUILDING_ID = TU.BUILDING_ID
43 51
                  INNER JOIN T_UNIT_TYPE TUT ON TUT.UNIT_TYPE_ID = TU.UNIT_TYPE_ID
52
+                 INNER JOIN T_AGENCY_EXTEND TAE ON TAE.AGENCY_ID = TU.AGENCY_ID
44 53
     </select>
45 54
 
46
-    <select id="findAllWithPage" resultType="unitAgencyMergeEntity">
55
+    <select id="findAllWithPage" resultMap="unitAgencyMergeEntityMap">
47 56
         SELECT TU.UNIT_ID,
48 57
                TU.DTU_NO,
49 58
                TU.PUSER_CODE,
@@ -53,11 +62,16 @@
53 62
                TB.BUILDING_ID,
54 63
                TB.NAME_OF_BUILDING,
55 64
                TUT.UNIT_TYPE_ID,
56
-               TUT.UNIT_TYPE
65
+               TUT.UNIT_TYPE,
66
+               TUT.PROPERTY,
67
+               TUT.CLASSIFY,
68
+               TAE.REGULATORY_LEVEL_ID,
69
+               TAE.AGENCY_ATTRIBUTE_CLASS_ID
57 70
         FROM T_UNIT TU
58 71
                  INNER JOIN T_AGENCY TAG ON TU.AGENCY_ID = TAG.AGENCY_ID AND TU.ISDELETED = 0
59 72
                  INNER JOIN T_BUILDING TB ON TB.BUILDING_ID = TU.BUILDING_ID
60 73
                  INNER JOIN T_UNIT_TYPE TUT ON TUT.UNIT_TYPE_ID = TU.UNIT_TYPE_ID
61
-        limit ?,?
74
+                 INNER JOIN T_AGENCY_EXTEND TAE ON TAE.AGENCY_ID = TU.AGENCY_ID
75
+        limit ${page},${size}
62 76
     </select>
63 77
 </mapper>

+ 41 - 0
elastic-publish-service/src/test/java/com/vcarecity/publish/config/MapperConfigTest.java Ver fichero

@@ -0,0 +1,41 @@
1
+package com.vcarecity.publish.config;
2
+
3
+import com.fasterxml.jackson.core.type.TypeReference;
4
+import com.fasterxml.jackson.databind.DeserializationFeature;
5
+import com.fasterxml.jackson.databind.ObjectMapper;
6
+import com.vcarecity.publish.entity.AgencyEntity;
7
+import org.junit.jupiter.api.Test;
8
+
9
+import java.lang.reflect.Type;
10
+import java.util.Map;
11
+
12
+class MapperConfigTest {
13
+    @Test
14
+    public void objectMapper() throws Exception {
15
+        ObjectMapper objectMapper = new ObjectMapper();
16
+        // objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
17
+        objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
18
+
19
+
20
+        AgencyEntity ae = new AgencyEntity();
21
+        ae.setAgencyId(11L);
22
+        ae.setIsDeleted(0);
23
+
24
+        String s = objectMapper.writeValueAsString(ae);
25
+        System.out.println(s);
26
+
27
+        Map<String, Object> map = objectMapper.convertValue(ae, new TypeReference<Map<String, Object>>() {
28
+            @Override
29
+            public Type getType() {
30
+                return super.getType();
31
+            }
32
+        });
33
+        System.out.println(map);
34
+
35
+        String value = "{\"agencyId\":11,\"agencyPath\":null,\"agencyName\":null,\"isDeleted\":0}";
36
+
37
+        AgencyEntity agencyEntity = objectMapper.readValue(value, AgencyEntity.class);
38
+        System.out.println(agencyEntity);
39
+
40
+    }
41
+}

+ 20 - 0
elastic-publish-service/src/test/java/com/vcarecity/publish/elastic/service/impl/ElasticLoadDataServiceImplTest.java Ver fichero

@@ -0,0 +1,20 @@
1
+package com.vcarecity.publish.elastic.service.impl;
2
+
3
+import com.vcarecity.publish.elastic.service.ElasticLoadDataService;
4
+import org.junit.jupiter.api.Test;
5
+import org.springframework.beans.factory.annotation.Autowired;
6
+import org.springframework.boot.test.context.SpringBootTest;
7
+
8
+import java.io.IOException;
9
+
10
+@SpringBootTest
11
+class ElasticLoadDataServiceImplTest {
12
+
13
+    @Autowired
14
+    private ElasticLoadDataService elasticLoadDataService;
15
+
16
+    @Test
17
+    void loadData() throws IOException {
18
+        elasticLoadDataService.loadData();
19
+    }
20
+}

+ 21 - 0
elastic-publish-service/src/test/java/com/vcarecity/publish/elastic/service/impl/ElasticQueryServiceImplTest.java Ver fichero

@@ -0,0 +1,21 @@
1
+package com.vcarecity.publish.elastic.service.impl;
2
+
3
+import com.vcarecity.publish.elastic.service.ElasticQueryService;
4
+import org.junit.jupiter.api.Test;
5
+import org.springframework.beans.factory.annotation.Autowired;
6
+import org.springframework.boot.test.context.SpringBootTest;
7
+
8
+import java.io.IOException;
9
+
10
+
11
+@SpringBootTest
12
+class ElasticQueryServiceImplTest {
13
+
14
+    @Autowired
15
+    private ElasticQueryService elasticQueryService;
16
+
17
+    @Test
18
+    void testQuery() throws IOException {
19
+        elasticQueryService.testQuery();
20
+    }
21
+}

+ 18 - 0
elastic-publish-service/src/test/java/com/vcarecity/publish/mapper/AgencyMapperTest.java Ver fichero

@@ -1,9 +1,15 @@
1 1
 package com.vcarecity.publish.mapper;
2 2
 
3
+import com.vcarecity.publish.entity.AgencyEntity;
3 4
 import org.junit.jupiter.api.Test;
4 5
 import org.springframework.beans.factory.annotation.Autowired;
5 6
 import org.springframework.boot.test.context.SpringBootTest;
7
+import org.springframework.test.context.TestPropertySource;
6 8
 
9
+import java.util.ArrayList;
10
+import java.util.List;
11
+
12
+@TestPropertySource(properties = "app.scheduling.enable=false")
7 13
 @SpringBootTest
8 14
 public class AgencyMapperTest {
9 15
 
@@ -26,4 +32,16 @@ public class AgencyMapperTest {
26 32
 
27 33
         agencyMapper.findUpdateUaList(from, to);
28 34
     }
35
+
36
+    @Test
37
+    public void findAgencyNameByAgencyIdList() {
38
+        List<Integer> id = new ArrayList<>();
39
+        id.add(1);
40
+        id.add(297);
41
+        id.add(80424);
42
+        List<AgencyEntity> agencyNameByAgencyIdList = agencyMapper.findAgencyNameByAgencyIdList(id);
43
+        for (AgencyEntity agencyEntity : agencyNameByAgencyIdList) {
44
+            System.out.println(agencyEntity);
45
+        }
46
+    }
29 47
 }

+ 3 - 0
elastic-publish-service/src/test/java/com/vcarecity/publish/service/impl/ElasticUpdateServiceImplTest.java Ver fichero

@@ -12,9 +12,12 @@ public class ElasticUpdateServiceImplTest {
12 12
     @Autowired
13 13
     private ElasticUpdateService elasticUpdateService;
14 14
 
15
+
15 16
     @Test
16 17
     void updateTest() throws Exception {
18
+
17 19
         elasticUpdateService.updateTest();
20
+
18 21
     }
19 22
 
20 23