Browse Source

add Scheduled

kerry 5 years ago
parent
commit
a2ba2b1f62
23 changed files with 247 additions and 49 deletions
  1. 3 0
      common/src/main/java/com/vcarecity/elastic/constants/ElasticConstant.java
  2. 4 3
      elastic-load-data/src/main/java/com/vcarecity/test/service/elastic/ElasticSaveServiceImpl.java
  3. 5 1
      elastic-load-data/src/main/java/com/vcarecity/test/service/elastic/QueryDataServiceImpl.java
  4. 2 2
      elastic-load-data/src/main/java/com/vcarecity/test/service/mysql/MySQLObtainDataServiceImpl.java
  5. 3 0
      elastic-publish-service/src/main/java/com/vcarecity/publish/ElasticPublishApplication.java
  6. 15 0
      elastic-publish-service/src/main/java/com/vcarecity/publish/api/ApiResult.java
  7. 10 0
      elastic-publish-service/src/main/java/com/vcarecity/publish/api/ApiStatus.java
  8. 0 9
      elastic-publish-service/src/main/java/com/vcarecity/publish/constants/CheckConstant.java
  9. 14 0
      elastic-publish-service/src/main/java/com/vcarecity/publish/constants/ElasticConstant.java
  10. 11 6
      elastic-publish-service/src/main/java/com/vcarecity/publish/controller/MainController.java
  11. 28 1
      elastic-publish-service/src/main/java/com/vcarecity/publish/elastic/service/ElasticIndexService.java
  12. 8 0
      elastic-publish-service/src/main/java/com/vcarecity/publish/elastic/service/ElasticLoadDataService.java
  13. 19 0
      elastic-publish-service/src/main/java/com/vcarecity/publish/elastic/service/impl/ElasticIndexServiceImpl.java
  14. 56 0
      elastic-publish-service/src/main/java/com/vcarecity/publish/elastic/service/impl/ElasticLoadDataServiceImpl.java
  15. 12 6
      elastic-publish-service/src/main/java/com/vcarecity/publish/elastic/service/impl/ElasticUpdateServiceImpl.java
  16. 1 1
      elastic-publish-service/src/main/java/com/vcarecity/publish/mapper/AgencyMapper.java
  17. 10 0
      elastic-publish-service/src/main/java/com/vcarecity/publish/mapper/UnitMapper.java
  18. 2 2
      elastic-publish-service/src/main/java/com/vcarecity/publish/service/impl/CheckTimeServiceImpl.java
  19. 4 1
      elastic-publish-service/src/main/java/com/vcarecity/publish/sql/service/impl/AgencyServiceImpl.java
  20. 9 6
      elastic-publish-service/src/main/java/com/vcarecity/publish/sql/service/impl/UnitServiceImpl.java
  21. 5 1
      elastic-publish-service/src/main/java/com/vcarecity/publish/task/CheckUpdateTask.java
  22. 2 2
      elastic-publish-service/src/main/resources/mapper/AgencyMapper.xml
  23. 24 8
      elastic-publish-service/src/main/resources/mapper/UnitMapper.xml

+ 3 - 0
common/src/main/java/com/vcarecity/elastic/constants/ElasticConstant.java View File

@@ -15,4 +15,7 @@ public class ElasticConstant {
15 15
     public static final DateTimeFormatter ES_DATE_FORMATTER = DateTimeFormatter.ofPattern(ES_DATE);
16 16
 
17 17
     public static final String ES_AGENCY_ID_PREFIX = "aId";
18
+
19
+
20
+    public static final String UNIT_AGENCY_INDEX = "unit-agency";
18 21
 }

+ 4 - 3
elastic-load-data/src/main/java/com/vcarecity/test/service/elastic/ElasticSaveServiceImpl.java View File

@@ -49,13 +49,13 @@ public class ElasticSaveServiceImpl implements ElasticSaveService {
49 49
 
50 50
         List<Map> saveResult = new ArrayList<>(result.size());
51 51
 
52
-        for (UnitAgencyEntity uae : result) {
52
+
53
+            for (UnitAgencyEntity uae : result) {
53 54
             final List<Integer> agencyIdList = AgencyPathUtil.splitAgencyId(uae.getAgencyPath());
54 55
             List<String> agencyPathDetail = agencyService.getAgencyPathDetail(agencyIdList);
55 56
 
56 57
             UnitAgencyDetailEntity unitAgencyDetailEntity = new UnitAgencyDetailEntity();
57 58
 
58
-
59 59
             beanCopier.copy(uae, unitAgencyDetailEntity, null);
60 60
 
61 61
             unitAgencyDetailEntity.setAgencyDetail(String.join("", agencyPathDetail));
@@ -85,8 +85,9 @@ public class ElasticSaveServiceImpl implements ElasticSaveService {
85 85
                 bulkRequest.add(indexRequest);
86 86
             }
87 87
             if (hasData) {
88
+                long time = System.currentTimeMillis();
88 89
                 BulkResponse bulkResponse = restHighLevelClient.bulk(bulkRequest, RequestOptions.DEFAULT);
89
-                logger.info("bulk insert status {}", bulkResponse.status());
90
+                logger.info("bulk insert status {}. usage: {} /ms", bulkResponse.status(), (System.currentTimeMillis() - time));
90 91
             }
91 92
         } catch (IOException e) {
92 93
             e.printStackTrace();

+ 5 - 1
elastic-load-data/src/main/java/com/vcarecity/test/service/elastic/QueryDataServiceImpl.java View File

@@ -1,6 +1,7 @@
1 1
 package com.vcarecity.test.service.elastic;
2 2
 
3 3
 import com.google.inject.Inject;
4
+import com.vcarecity.elastic.constants.ElasticConstant;
4 5
 import com.vcarecity.elastic.util.AgencyPathUtil;
5 6
 import com.vcarecity.test.service.QueryDataService;
6 7
 import org.elasticsearch.action.search.SearchRequest;
@@ -27,9 +28,12 @@ public class QueryDataServiceImpl implements QueryDataService {
27 28
 
28 29
     private final RestHighLevelClient restHighLevelClient;
29 30
 
31
+    private final String index;
32
+
30 33
     @Inject
31 34
     public QueryDataServiceImpl(RestHighLevelClient restHighLevelClient) {
32 35
         this.restHighLevelClient = restHighLevelClient;
36
+        this.index = ElasticConstant.UNIT_AGENCY_INDEX;
33 37
     }
34 38
 
35 39
 
@@ -38,7 +42,7 @@ public class QueryDataServiceImpl implements QueryDataService {
38 42
         List<Integer> agencyIds = AgencyPathUtil.splitAgencyId(agencyPath);
39 43
         BoolQueryBuilder boolQueryBuilder = agencyCondition(agencyIds);
40 44
 
41
-        String index = "unit-agency";
45
+
42 46
 
43 47
 
44 48
         SearchRequest searchRequest = new SearchRequest();

+ 2 - 2
elastic-load-data/src/main/java/com/vcarecity/test/service/mysql/MySQLObtainDataServiceImpl.java View File

@@ -20,7 +20,7 @@ import java.util.List;
20 20
 @Slf4j
21 21
 public class MySQLObtainDataServiceImpl implements ObtainDataService {
22 22
 
23
-    //language=mysql
23
+    //language=sql
24 24
     private static final String OB_SQL = "SELECT TU.UNIT_ID,\n" +
25 25
             "       TU.DTU_NO,\n" +
26 26
             "       TU.PUSER_CODE,\n" +
@@ -34,7 +34,7 @@ public class MySQLObtainDataServiceImpl implements ObtainDataService {
34 34
             "FROM T_UNIT TU\n" +
35 35
             "         INNER JOIN T_AGENCY TAG ON TU.AGENCY_ID = TAG.AGENCY_ID AND TU.ISDELETED = 0\n" +
36 36
             "         INNER JOIN T_BUILDING TB ON TB.BUILDING_ID = TU.BUILDING_ID\n" +
37
-            "         INNER JOIN T_UNIT_TYPE TUT ON TUT.UNIT_TYPE_ID = TU.UNIT_TYPE_ID  limit ?,?";
37
+            "         INNER JOIN T_UNIT_TYPE TUT ON TUT.UNIT_TYPE_ID = TU.UNIT_TYPE_ID limit ?,?";
38 38
 
39 39
     private final DataSource dataSource;
40 40
     private final TypeHandler typeHandler;

+ 3 - 0
elastic-publish-service/src/main/java/com/vcarecity/publish/ElasticPublishApplication.java View File

@@ -3,11 +3,14 @@ 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;
6 7
 
7 8
 /**
8 9
  * @author Kerry on 19/12/11
9 10
  */
10 11
 
12
+
13
+@EnableScheduling
11 14
 @MapperScan("com.vcarecity.publish.mapper")
12 15
 @SpringBootApplication
13 16
 public class ElasticPublishApplication {

+ 15 - 0
elastic-publish-service/src/main/java/com/vcarecity/publish/api/ApiResult.java View File

@@ -0,0 +1,15 @@
1
+package com.vcarecity.publish.api;
2
+
3
+import lombok.Builder;
4
+
5
+/**
6
+ * @author VcKerry on 12/18/19
7
+ */
8
+
9
+@Builder
10
+public class ApiResult {
11
+    private int status;
12
+    private String message;
13
+    private int errorCode;
14
+    private Object data;
15
+}

+ 10 - 0
elastic-publish-service/src/main/java/com/vcarecity/publish/api/ApiStatus.java View File

@@ -0,0 +1,10 @@
1
+package com.vcarecity.publish.api;
2
+
3
+/**
4
+ * @author VcKerry on 12/18/19
5
+ */
6
+
7
+public class ApiStatus {
8
+    public static final int SUCCESS_CODE = 20000;
9
+    public static final int FAILED_CODE = 40000;
10
+}

+ 0 - 9
elastic-publish-service/src/main/java/com/vcarecity/publish/constants/CheckConstant.java View File

@@ -1,9 +0,0 @@
1
-package com.vcarecity.publish.constants;
2
-
3
-/**
4
- * @author VcKerry on 12/18/19
5
- */
6
-
7
-public class CheckConstant {
8
-    public static final long CHECK_TIME_INTERVAL = 1000 * 3 * 60;
9
-}

+ 14 - 0
elastic-publish-service/src/main/java/com/vcarecity/publish/constants/ElasticConstant.java View File

@@ -0,0 +1,14 @@
1
+package com.vcarecity.publish.constants;
2
+
3
+/**
4
+ * @author VcKerry on 12/18/19
5
+ */
6
+
7
+public class ElasticConstant {
8
+    public static final long CHECK_TIME_INTERVAL = 1000 * 3 * 60;
9
+
10
+    public static final String UNIT_AGENCY_INDEX = "unit-agency";
11
+
12
+
13
+    public static final int QUERY_PAGE_COUNT = 2000;
14
+}

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

@@ -1,5 +1,8 @@
1 1
 package com.vcarecity.publish.controller;
2 2
 
3
+import com.vcarecity.publish.api.ApiResult;
4
+import com.vcarecity.publish.api.ApiStatus;
5
+import com.vcarecity.publish.constants.ElasticConstant;
3 6
 import com.vcarecity.publish.pojo.dto.UnitAgencyDTO;
4 7
 import com.vcarecity.publish.pojo.query.UnitAgencyQuery;
5 8
 import com.vcarecity.publish.sql.service.UnitService;
@@ -26,16 +29,18 @@ public class MainController {
26 29
     }
27 30
 
28 31
     @PostMapping("/query-unit-agency")
29
-    public Object queryUnitAgency(@RequestBody @Valid UnitAgencyQuery unitAgencyQuery) throws IOException {
32
+    public ApiResult queryUnitAgency(@RequestBody @Valid UnitAgencyQuery unitAgencyQuery) throws IOException {
30 33
         final List<UnitAgencyDTO> unitAgencyByQuery = unitService.getUnitAgencyByQuery(unitAgencyQuery.getAgencyPath(), unitAgencyQuery.getKeyword(),
31
-                unitAgencyQuery.getPage(), unitAgencyQuery.getSize(), "unit-agency");
32
-        return unitAgencyByQuery.stream().map(UnitAgencyDTO::getUnitId).collect(Collectors.toList());
34
+                unitAgencyQuery.getPage(), unitAgencyQuery.getSize(), ElasticConstant.UNIT_AGENCY_INDEX);
35
+        List<Long> data = unitAgencyByQuery.stream().map(UnitAgencyDTO::getUnitId).collect(Collectors.toList());
36
+        return ApiResult.builder().status(ApiStatus.SUCCESS_CODE).data(data).build();
33 37
     }
34 38
 
35 39
     @PostMapping("/test/query-unit-agency")
36
-    public Object testQueryUnitAgency(@RequestBody @Valid UnitAgencyQuery unitAgencyQuery) throws IOException {
37
-        return unitService.getUnitAgencyByQuery(unitAgencyQuery.getAgencyPath(), unitAgencyQuery.getKeyword(),
38
-                unitAgencyQuery.getPage(), unitAgencyQuery.getSize(), "unit-agency");
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);
43
+        return ApiResult.builder().status(ApiStatus.SUCCESS_CODE).data(data).build();
39 44
     }
40 45
 
41 46
 

+ 28 - 1
elastic-publish-service/src/main/java/com/vcarecity/publish/elastic/service/ElasticIndexService.java View File

@@ -1,14 +1,41 @@
1 1
 package com.vcarecity.publish.elastic.service;
2 2
 
3
+import java.util.List;
4
+
3 5
 /**
4 6
  * @author kerryzhang on 2019/12/17
5 7
  */
6 8
 
7 9
 public interface ElasticIndexService {
8 10
 
9
-    void createIndex(String ...indices);
11
+    /**
12
+     * index 是否存在
13
+     *
14
+     * @param index
15
+     * @return
16
+     */
17
+    boolean indexExist(String index);
18
+
19
+    /**
20
+     * create index
21
+     *
22
+     * @param indices
23
+     */
24
+    void createIndex(String... indices);
10 25
 
26
+    /**
27
+     * delete index
28
+     *
29
+     * @param indices
30
+     */
11 31
     void deleteIndex(String... indices);
12 32
 
13 33
 
34
+    /**
35
+     * list index
36
+     *
37
+     * @return
38
+     */
39
+    List<String> indices();
40
+
14 41
 }

+ 8 - 0
elastic-publish-service/src/main/java/com/vcarecity/publish/elastic/service/ElasticLoadDataService.java View File

@@ -1,8 +1,16 @@
1 1
 package com.vcarecity.publish.elastic.service;
2 2
 
3
+import java.io.IOException;
4
+
3 5
 /**
4 6
  * @author kerryzhang on 2019/12/17
5 7
  */
6 8
 
7 9
 public interface ElasticLoadDataService {
10
+    /**
11
+     * load data
12
+     *
13
+     * @throws IOException
14
+     */
15
+    void loadData() throws IOException;
8 16
 }

+ 19 - 0
elastic-publish-service/src/main/java/com/vcarecity/publish/elastic/service/impl/ElasticIndexServiceImpl.java View File

@@ -1,8 +1,11 @@
1 1
 package com.vcarecity.publish.elastic.service.impl;
2 2
 
3 3
 import com.vcarecity.publish.elastic.service.ElasticIndexService;
4
+import org.elasticsearch.client.RestHighLevelClient;
4 5
 import org.springframework.stereotype.Service;
5 6
 
7
+import java.util.List;
8
+
6 9
 /**
7 10
  * @author kerryzhang on 2019/12/17
8 11
  */
@@ -10,6 +13,17 @@ import org.springframework.stereotype.Service;
10 13
 @Service
11 14
 public class ElasticIndexServiceImpl implements ElasticIndexService {
12 15
 
16
+    private final RestHighLevelClient restHighLevelClient;
17
+
18
+    public ElasticIndexServiceImpl(RestHighLevelClient restHighLevelClient) {
19
+        this.restHighLevelClient = restHighLevelClient;
20
+    }
21
+
22
+    @Override
23
+    public boolean indexExist(String index) {
24
+
25
+        return false;
26
+    }
13 27
 
14 28
     @Override
15 29
     public void createIndex(String... indices) {
@@ -20,4 +34,9 @@ public class ElasticIndexServiceImpl implements ElasticIndexService {
20 34
     public void deleteIndex(String... indices) {
21 35
 
22 36
     }
37
+
38
+    @Override
39
+    public List<String> indices() {
40
+        return null;
41
+    }
23 42
 }

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

@@ -1,12 +1,68 @@
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.ElasticLoadDataService;
5
+import com.vcarecity.publish.elastic.service.ElasticUpdateService;
6
+import com.vcarecity.publish.entity.UnitAgencyMergeEntity;
7
+import com.vcarecity.publish.mapper.UnitMapper;
8
+import lombok.extern.slf4j.Slf4j;
4 9
 import org.springframework.stereotype.Service;
5 10
 
11
+import java.io.IOException;
12
+import java.util.List;
13
+
6 14
 /**
7 15
  * @author kerryzhang on 2019/12/17
8 16
  */
9 17
 
18
+@Slf4j
10 19
 @Service
11 20
 public class ElasticLoadDataServiceImpl implements ElasticLoadDataService {
21
+
22
+
23
+    private final UnitMapper unitMapper;
24
+    private final ElasticUpdateService elasticUpdateService;
25
+    private final int pageCount;
26
+
27
+    public ElasticLoadDataServiceImpl(UnitMapper unitMapper,
28
+                                      ElasticUpdateService elasticUpdateService) {
29
+        this.unitMapper = unitMapper;
30
+        this.elasticUpdateService = elasticUpdateService;
31
+        this.pageCount = ElasticConstant.QUERY_PAGE_COUNT;
32
+    }
33
+
34
+
35
+    @Override
36
+    public void loadData() throws IOException {
37
+
38
+        long allTime = System.currentTimeMillis();
39
+
40
+        // calc handler count
41
+        int count = 0;
42
+        // page
43
+        int start = 0;
44
+
45
+        List<UnitAgencyMergeEntity> result;
46
+        do {
47
+
48
+            long startTime = System.currentTimeMillis();
49
+
50
+            result = unitMapper.findAllWithPage(start * pageCount, pageCount);
51
+            start++;
52
+            count += result.size();
53
+
54
+            logger.debug("query database usageTime: {} ms. count = {}", (System.currentTimeMillis() - startTime), count);
55
+
56
+            startTime = System.currentTimeMillis();
57
+
58
+            elasticUpdateService.addElasticData(result);
59
+
60
+            logger.debug("write to Elasticsearch usageTime: {} ms.", (System.currentTimeMillis() - startTime));
61
+
62
+        } while (result.size() == pageCount);
63
+
64
+        logger.info("loadData ok. All usageTime = {} ms.", (System.currentTimeMillis() - allTime));
65
+
66
+    }
67
+
12 68
 }

+ 12 - 6
elastic-publish-service/src/main/java/com/vcarecity/publish/elastic/service/impl/ElasticUpdateServiceImpl.java View File

@@ -4,6 +4,7 @@ import com.fasterxml.jackson.core.type.TypeReference;
4 4
 import com.fasterxml.jackson.databind.ObjectMapper;
5 5
 import com.vcarecity.elastic.util.AgencyPathUtil;
6 6
 import com.vcarecity.elastic.util.SnowFlake;
7
+import com.vcarecity.publish.constants.ElasticConstant;
7 8
 import com.vcarecity.publish.elastic.entity.UnitAgencyDetailEntity;
8 9
 import com.vcarecity.publish.elastic.service.ElasticUpdateService;
9 10
 import com.vcarecity.publish.entity.UnitAgencyMergeEntity;
@@ -39,7 +40,7 @@ import java.util.Map;
39 40
 @Service
40 41
 public class ElasticUpdateServiceImpl implements ElasticUpdateService {
41 42
 
42
-    public static final String INDEX = "unit-agency";
43
+    public final String index;
43 44
 
44 45
     private final RestHighLevelClient restHighLevelClient;
45 46
     private final ObjectMapper objectMapper;
@@ -52,6 +53,7 @@ public class ElasticUpdateServiceImpl implements ElasticUpdateService {
52 53
         this.objectMapper = objectMapper;
53 54
         this.agencyService = agencyService;
54 55
 
56
+        this.index = ElasticConstant.UNIT_AGENCY_INDEX;
55 57
     }
56 58
 
57 59
 
@@ -102,6 +104,8 @@ public class ElasticUpdateServiceImpl implements ElasticUpdateService {
102 104
         // 更新数据
103 105
         List<UnitAgencyMergeEntity> addData = updateDataByQuery(key, updateList);
104 106
 
107
+        logger.info("add data size = {}", addData.size());
108
+
105 109
         // 添加数据
106 110
         this.addElasticData(addData);
107 111
     }
@@ -113,7 +117,7 @@ public class ElasticUpdateServiceImpl implements ElasticUpdateService {
113 117
             return;
114 118
         }
115 119
         for (Long id : ids) {
116
-            DeleteByQueryRequest request = new DeleteByQueryRequest(INDEX);
120
+            DeleteByQueryRequest request = new DeleteByQueryRequest(index);
117 121
             request.setQuery(QueryBuilders.termQuery(key, id));
118 122
             restHighLevelClient.deleteByQuery(request, RequestOptions.DEFAULT);
119 123
         }
@@ -129,7 +133,7 @@ public class ElasticUpdateServiceImpl implements ElasticUpdateService {
129 133
             Object value = params.get(key);
130 134
             params.remove(key);
131 135
 
132
-            UpdateByQueryRequest request = new UpdateByQueryRequest(INDEX);
136
+            UpdateByQueryRequest request = new UpdateByQueryRequest(index);
133 137
             request.setQuery(QueryBuilders.termQuery(key, value));
134 138
             request.setScript(new Script(ScriptType.INLINE, "painless", getPainlessCode(params), params));
135 139
 
@@ -137,7 +141,7 @@ public class ElasticUpdateServiceImpl implements ElasticUpdateService {
137 141
 
138 142
             logger.info("response:{}", response);
139 143
 
140
-            if (response.getUpdated() != 0L) {
144
+            if (response.getUpdated() == 0L) {
141 145
                 addList.add(item);
142 146
             }
143 147
         }
@@ -164,11 +168,13 @@ public class ElasticUpdateServiceImpl implements ElasticUpdateService {
164 168
         try {
165 169
             BulkRequest bulkRequest = new BulkRequest();
166 170
             for (Map<String, Object> val : saveResult) {
167
-                IndexRequest indexRequest = createIndexRequest(INDEX, val);
171
+                IndexRequest indexRequest = createIndexRequest(index, val);
168 172
                 bulkRequest.add(indexRequest);
169 173
             }
170 174
             BulkResponse bulkResponse = restHighLevelClient.bulk(bulkRequest, RequestOptions.DEFAULT);
171
-            logger.info("bulk insert status {}", bulkResponse.status());
175
+
176
+            logger.debug("bulk addElasticData status {}, size = {}", bulkResponse.status(), saveResult.size());
177
+
172 178
         } catch (IOException e) {
173 179
             e.printStackTrace();
174 180
         }

+ 1 - 1
elastic-publish-service/src/main/java/com/vcarecity/publish/mapper/AgencyMapper.java View File

@@ -41,5 +41,5 @@ public interface AgencyMapper {
41 41
      * @param agencyPathIds
42 42
      * @return
43 43
      */
44
-    List<String> findAgencyNameByAgencyIdList(@Param("agencyPathIds") List<Integer> agencyPathIds);
44
+    List<AgencyEntity> findAgencyNameByAgencyIdList(@Param("agencyPathIds") List<Integer> agencyPathIds);
45 45
 }

+ 10 - 0
elastic-publish-service/src/main/java/com/vcarecity/publish/mapper/UnitMapper.java View File

@@ -35,4 +35,14 @@ public interface UnitMapper {
35 35
     List<UnitAgencyMergeEntity> findUpdateUaList(@Param("fromDate") String fromDate, @Param("toDate") String toDate);
36 36
 
37 37
 
38
+    /**
39
+     * find all by page
40
+     *
41
+     * @param page
42
+     * @param size
43
+     * @return
44
+     */
45
+    List<UnitAgencyMergeEntity> findAllWithPage(@Param("page") int page, @Param("size") int size);
46
+
47
+
38 48
 }

+ 2 - 2
elastic-publish-service/src/main/java/com/vcarecity/publish/service/impl/CheckTimeServiceImpl.java View File

@@ -1,6 +1,6 @@
1 1
 package com.vcarecity.publish.service.impl;
2 2
 
3
-import com.vcarecity.publish.constants.CheckConstant;
3
+import com.vcarecity.publish.constants.ElasticConstant;
4 4
 import com.vcarecity.publish.service.CheckTimeService;
5 5
 import com.vcarecity.publish.util.DateUtil;
6 6
 import org.springframework.data.redis.core.RedisTemplate;
@@ -37,7 +37,7 @@ public class CheckTimeServiceImpl implements CheckTimeService {
37 37
             LocalDateTime.ofInstant(new Date(Long.parseLong(value.toString())).toInstant(), ZoneId.systemDefault()).format(DateUtil.DATE_TIME_FORMATTER);
38 38
         }
39 39
 
40
-        long last = System.currentTimeMillis() - CheckConstant.CHECK_TIME_INTERVAL;
40
+        long last = System.currentTimeMillis() - ElasticConstant.CHECK_TIME_INTERVAL;
41 41
         redisTemplate.opsForValue().set(redisKey, last);
42 42
 
43 43
         return LocalDateTime.ofInstant(new Date(last).toInstant(), ZoneId.systemDefault()).format(DateUtil.DATE_TIME_FORMATTER);

+ 4 - 1
elastic-publish-service/src/main/java/com/vcarecity/publish/sql/service/impl/AgencyServiceImpl.java View File

@@ -1,10 +1,12 @@
1 1
 package com.vcarecity.publish.sql.service.impl;
2 2
 
3
+import com.vcarecity.publish.entity.AgencyEntity;
3 4
 import com.vcarecity.publish.mapper.AgencyMapper;
4 5
 import com.vcarecity.publish.sql.service.AgencyService;
5 6
 import org.springframework.stereotype.Service;
6 7
 
7 8
 import java.util.List;
9
+import java.util.stream.Collectors;
8 10
 
9 11
 /**
10 12
  * @author kerryzhang on 2019/12/17
@@ -23,6 +25,7 @@ public class AgencyServiceImpl implements AgencyService {
23 25
     public List<String> getAgencyPathDetail(List<Integer> agencyPath) {
24 26
 
25 27
         //TODO 可以优化的空间
26
-        return agencyMapper.findAgencyNameByAgencyIdList(agencyPath);
28
+        List<AgencyEntity> agencyNameByAgencyIdList = agencyMapper.findAgencyNameByAgencyIdList(agencyPath);
29
+        return agencyNameByAgencyIdList.stream().map(AgencyEntity::getAgencyName).collect(Collectors.toList());
27 30
     }
28 31
 }

+ 9 - 6
elastic-publish-service/src/main/java/com/vcarecity/publish/sql/service/impl/UnitServiceImpl.java View File

@@ -35,6 +35,15 @@ 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[]{
39
+            "agencyName.keyword",
40
+            "agencyDetail.keyword",
41
+            "unitType.keyword",
42
+            "nameOfBuilding.keyword",
43
+    };
44
+
45
+    static String[] queryColumns = new String[]{"unitId", "nameOfBuilding", "agencyDetail", "agencyName"};
46
+
38 47
     public UnitServiceImpl(RestHighLevelClient restHighLevelClient,
39 48
                            ObjectMapper objectMapper) {
40 49
         this.restHighLevelClient = restHighLevelClient;
@@ -56,7 +65,6 @@ public class UnitServiceImpl implements UnitService {
56 65
             queryBuilder.must(keywordBoolQuery);
57 66
         }
58 67
 
59
-        String[] queryColumns = new String[]{"unitId", "nameOfBuilding", "agencyDetail", "agencyName"};
60 68
 
61 69
         SearchRequest searchRequest = new SearchRequest();
62 70
         SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
@@ -285,11 +293,6 @@ public class UnitServiceImpl implements UnitService {
285 293
             return null;
286 294
         }
287 295
 
288
-        final String[] keyNames = new String[]{
289
-                "agencyName.keyword",
290
-                "agencyDetail.keyword",
291
-                "nameOfBuilding.keyword",
292
-        };
293 296
 
294 297
         final BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
295 298
 

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

@@ -1,12 +1,14 @@
1 1
 package com.vcarecity.publish.task;
2 2
 
3
+import com.vcarecity.publish.constants.ElasticConstant;
4
+import com.vcarecity.publish.elastic.service.ElasticUpdateService;
3 5
 import com.vcarecity.publish.entity.UnitAgencyMergeEntity;
4 6
 import com.vcarecity.publish.mapper.AgencyMapper;
5 7
 import com.vcarecity.publish.mapper.UnitMapper;
6 8
 import com.vcarecity.publish.service.CheckTimeService;
7
-import com.vcarecity.publish.elastic.service.ElasticUpdateService;
8 9
 import com.vcarecity.publish.util.DateUtil;
9 10
 import lombok.extern.slf4j.Slf4j;
11
+import org.springframework.scheduling.annotation.Scheduled;
10 12
 import org.springframework.stereotype.Component;
11 13
 
12 14
 import java.time.LocalDateTime;
@@ -38,6 +40,8 @@ public class CheckUpdateTask {
38 40
         this.unitMapper = unitMapper;
39 41
     }
40 42
 
43
+
44
+    @Scheduled(initialDelay = 1000L, fixedDelay = ElasticConstant.CHECK_TIME_INTERVAL)
41 45
     public void checkUpdateTask() {
42 46
 
43 47
         // 当前更新时间

+ 2 - 2
elastic-publish-service/src/main/resources/mapper/AgencyMapper.xml View File

@@ -47,8 +47,8 @@
47 47
                  INNER JOIN T_UNIT_TYPE TUT ON TUT.UNIT_TYPE_ID = TU.UNIT_TYPE_ID
48 48
     </select>
49 49
 
50
-    <select id="findAgencyNameByAgencyIdList" resultType="string" parameterType="list">
51
-        select AGENCY_NAME from T_AGENCY
50
+    <select id="findAgencyNameByAgencyIdList" resultType="agencyEntity" parameterType="list">
51
+        select AGENCY_NAME,AGENCY_ID from T_AGENCY
52 52
         <where>
53 53
             AGENCY_ID in
54 54
             <foreach item="item" collection="agencyPathIds" separator="," open="(" close=")" index="">

+ 24 - 8
elastic-publish-service/src/main/resources/mapper/UnitMapper.xml View File

@@ -1,14 +1,6 @@
1 1
 <?xml version="1.0" encoding="UTF-8" ?>
2 2
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
3 3
 <mapper namespace="com.vcarecity.publish.mapper.UnitMapper">
4
-
5
-    <select id="findUpdateList" resultType="unitEntity">
6
-        select UNIT_ID, DTU_NO, PUSER_CODE, ISDELETED
7
-        from T_UNIT
8
-        where UPDATESTAMP between to_date('${fromDate}', 'YYYY-MM-DD HH24:MI:SS')
9
-                  and to_date('${toDate}', 'YYYY-MM-DD HH24:MI:SS')
10
-    </select>
11
-
12 4
     <resultMap id="unitAgencyMergeEntityMap" type="unitAgencyMergeEntity">
13 5
         <result column="UNIT_ID" property="unitId"/>
14 6
         <result column="DTU_NO" property="dtuNo"/>
@@ -23,6 +15,12 @@
23 15
         <result column="UNIT_TYPE" property="unitType"/>
24 16
     </resultMap>
25 17
 
18
+    <select id="findUpdateList" resultType="unitEntity">
19
+        select UNIT_ID, DTU_NO, PUSER_CODE, ISDELETED
20
+        from T_UNIT
21
+        where UPDATESTAMP between '${fromDate}' and '${toDate}'
22
+    </select>
23
+
26 24
 
27 25
     <select id="findUpdateUaList" resultMap="unitAgencyMergeEntityMap">
28 26
         SELECT TU.UNIT_ID,
@@ -44,4 +42,22 @@
44 42
                  INNER JOIN T_BUILDING TB ON TB.BUILDING_ID = TU.BUILDING_ID
45 43
                  INNER JOIN T_UNIT_TYPE TUT ON TUT.UNIT_TYPE_ID = TU.UNIT_TYPE_ID
46 44
     </select>
45
+
46
+    <select id="findAllWithPage" resultType="unitAgencyMergeEntity">
47
+        SELECT TU.UNIT_ID,
48
+               TU.DTU_NO,
49
+               TU.PUSER_CODE,
50
+               TAG.AGENCY_ID,
51
+               TAG.AGENCY_PATH,
52
+               TAG.AGENCY_NAME,
53
+               TB.BUILDING_ID,
54
+               TB.NAME_OF_BUILDING,
55
+               TUT.UNIT_TYPE_ID,
56
+               TUT.UNIT_TYPE
57
+        FROM T_UNIT TU
58
+                 INNER JOIN T_AGENCY TAG ON TU.AGENCY_ID = TAG.AGENCY_ID AND TU.ISDELETED = 0
59
+                 INNER JOIN T_BUILDING TB ON TB.BUILDING_ID = TU.BUILDING_ID
60
+                 INNER JOIN T_UNIT_TYPE TUT ON TUT.UNIT_TYPE_ID = TU.UNIT_TYPE_ID
61
+        limit ?,?
62
+    </select>
47 63
 </mapper>