kerryzhang 5 лет назад
Родитель
Сommit
eb0c3d1622
40 измененных файлов: 292 добавлений и 146 удалений
  1. 0 65
      elastic-publish-service/src/main/java/com/vcarecity/elastic/publish/task/CheckUpdateTask.java
  2. 2 2
      elastic-publish-service/src/main/java/com/vcarecity/publish/ElasticPublishApplication.java
  3. 1 1
      elastic-publish-service/src/main/java/com/vcarecity/publish/config/ElasticConfig.java
  4. 1 1
      elastic-publish-service/src/main/java/com/vcarecity/publish/config/MapperConfig.java
  5. 4 4
      elastic-publish-service/src/main/java/com/vcarecity/publish/controller/MainController.java
  6. 1 1
      elastic-publish-service/src/main/java/com/vcarecity/publish/controller/TestController.java
  7. 17 0
      elastic-publish-service/src/main/java/com/vcarecity/publish/elastic/entity/UnitAgencyDetailEntity.java
  8. 8 0
      elastic-publish-service/src/main/java/com/vcarecity/publish/elastic/service/ElasticLoadDataService.java
  9. 3 2
      elastic-publish-service/src/main/java/com/vcarecity/publish/elastic/service/ElasticQueryService.java
  10. 3 3
      elastic-publish-service/src/main/java/com/vcarecity/publish/elastic/service/ElasticUpdateService.java
  11. 12 0
      elastic-publish-service/src/main/java/com/vcarecity/publish/elastic/service/impl/ElasticLoadDataServiceImpl.java
  12. 3 3
      elastic-publish-service/src/main/java/com/vcarecity/publish/elastic/service/impl/ElasticQueryServiceImpl.java
  13. 40 8
      elastic-publish-service/src/main/java/com/vcarecity/publish/elastic/service/impl/ElasticUpdateServiceImpl.java
  14. 1 1
      elastic-publish-service/src/main/java/com/vcarecity/publish/entity/AgencyEntity.java
  15. 1 1
      elastic-publish-service/src/main/java/com/vcarecity/publish/entity/BuildingEntity.java
  16. 1 1
      elastic-publish-service/src/main/java/com/vcarecity/publish/entity/UnitAgencyMergeEntity.java
  17. 1 1
      elastic-publish-service/src/main/java/com/vcarecity/publish/entity/UnitEntity.java
  18. 10 3
      elastic-publish-service/src/main/java/com/vcarecity/publish/mapper/AgencyMapper.java
  19. 2 2
      elastic-publish-service/src/main/java/com/vcarecity/publish/mapper/BuildingMapper.java
  20. 3 3
      elastic-publish-service/src/main/java/com/vcarecity/publish/mapper/UnitMapper.java
  21. 1 1
      elastic-publish-service/src/main/java/com/vcarecity/publish/pojo/dto/UnitAgencyDTO.java
  22. 1 1
      elastic-publish-service/src/main/java/com/vcarecity/publish/pojo/query/UnitAgencyQuery.java
  23. 1 1
      elastic-publish-service/src/main/java/com/vcarecity/publish/service/CheckTimeService.java
  24. 3 3
      elastic-publish-service/src/main/java/com/vcarecity/publish/service/impl/CheckTimeServiceImpl.java
  25. 18 0
      elastic-publish-service/src/main/java/com/vcarecity/publish/sql/service/AgencyService.java
  26. 2 2
      elastic-publish-service/src/main/java/com/vcarecity/publish/sql/service/UnitService.java
  27. 28 0
      elastic-publish-service/src/main/java/com/vcarecity/publish/sql/service/impl/AgencyServiceImpl.java
  28. 3 3
      elastic-publish-service/src/main/java/com/vcarecity/publish/sql/service/impl/UnitServiceImpl.java
  29. 76 0
      elastic-publish-service/src/main/java/com/vcarecity/publish/task/CheckUpdateTask.java
  30. 1 1
      elastic-publish-service/src/main/java/com/vcarecity/publish/util/DateUtil.java
  31. 1 1
      elastic-publish-service/src/main/resources/application-dev.yml
  32. 15 3
      elastic-publish-service/src/main/resources/mapper/AgencyMapper.xml
  33. 1 1
      elastic-publish-service/src/main/resources/mapper/BuildingMapper.xml
  34. 1 1
      elastic-publish-service/src/main/resources/mapper/UnitMapper.xml
  35. 0 21
      elastic-publish-service/src/test/java/com/vcarecity/elastic/publish/service/impl/UpdateElasticServiceImplTest.java
  36. 1 1
      elastic-publish-service/src/test/java/com/vcarecity/publish/mapper/AgencyMapperTest.java
  37. 1 1
      elastic-publish-service/src/test/java/com/vcarecity/publish/mapper/BuildingMapperTest.java
  38. 2 2
      elastic-publish-service/src/test/java/com/vcarecity/publish/mapper/UnitMapperTest.java
  39. 21 0
      elastic-publish-service/src/test/java/com/vcarecity/publish/service/impl/ElasticUpdateServiceImplTest.java
  40. 1 1
      elastic-publish-service/src/test/java/com/vcarecity/publish/service/impl/UnitServiceImplTest.java

+ 0 - 65
elastic-publish-service/src/main/java/com/vcarecity/elastic/publish/task/CheckUpdateTask.java Просмотреть файл

@@ -1,65 +0,0 @@
1
-package com.vcarecity.elastic.publish.task;
2
-
3
-import com.vcarecity.elastic.publish.entity.UnitAgencyMergeEntity;
4
-import com.vcarecity.elastic.publish.mapper.AgencyMapper;
5
-import com.vcarecity.elastic.publish.mapper.BuildingMapper;
6
-import com.vcarecity.elastic.publish.mapper.UnitMapper;
7
-import com.vcarecity.elastic.publish.service.CheckTimeService;
8
-import com.vcarecity.elastic.publish.util.DateUtil;
9
-
10
-import java.time.LocalDateTime;
11
-import java.time.ZoneId;
12
-import java.util.Date;
13
-import java.util.List;
14
-
15
-/**
16
- * @author Kerry on 19/12/11
17
- */
18
-
19
-//@Component
20
-public class CheckUpdateTask {
21
-
22
-    private final CheckTimeService checkTimeService;
23
-    private final AgencyMapper agencyMapper;
24
-    private final UnitMapper unitMapper;
25
-    private final BuildingMapper buildingMapper;
26
-
27
-    public CheckUpdateTask(CheckTimeService checkTimeService, AgencyMapper agencyMapper,
28
-                           UnitMapper unitMapper,
29
-                           BuildingMapper buildingMapper) {
30
-        this.checkTimeService = checkTimeService;
31
-        this.agencyMapper = agencyMapper;
32
-        this.unitMapper = unitMapper;
33
-        this.buildingMapper = buildingMapper;
34
-    }
35
-
36
-
37
-    public void checkTask() {
38
-
39
-        long curCheckTime = System.currentTimeMillis();
40
-        String toDateTime = LocalDateTime.ofInstant(new Date(curCheckTime).toInstant(), ZoneId.systemDefault()).format(DateUtil.DATE_TIME_FORMATTER);
41
-
42
-        List<UnitAgencyMergeEntity> updateUaList;
43
-        String fromDateTime;
44
-
45
-        fromDateTime = checkTimeService.getLastDateTime("T_UNIT");
46
-        updateUaList = unitMapper.findUpdateUaList(fromDateTime, toDateTime);
47
-        if (!updateUaList.isEmpty()) {
48
-
49
-        }
50
-        checkTimeService.setLastDateTime("T_UNIT", curCheckTime);
51
-        updateUaList.clear();
52
-
53
-        fromDateTime = checkTimeService.getLastDateTime("T_AGENCY");
54
-        updateUaList = agencyMapper.findUpdateUaList(fromDateTime, toDateTime);
55
-
56
-        if (!updateUaList.isEmpty()) {
57
-
58
-        }
59
-        checkTimeService.setLastDateTime("T_AGENCY", curCheckTime);
60
-        updateUaList.clear();
61
-
62
-
63
-    }
64
-
65
-}

elastic-publish-service/src/main/java/com/vcarecity/elastic/publish/ElasticPublishApplication.java → elastic-publish-service/src/main/java/com/vcarecity/publish/ElasticPublishApplication.java Просмотреть файл

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

elastic-publish-service/src/main/java/com/vcarecity/elastic/publish/config/ElasticConfig.java → elastic-publish-service/src/main/java/com/vcarecity/publish/config/ElasticConfig.java Просмотреть файл

@@ -1,4 +1,4 @@
1
-package com.vcarecity.elastic.publish.config;
1
+package com.vcarecity.publish.config;
2 2
 
3 3
 import org.apache.http.HttpHost;
4 4
 import org.apache.http.auth.AuthScope;

elastic-publish-service/src/main/java/com/vcarecity/elastic/publish/config/MapperConfig.java → elastic-publish-service/src/main/java/com/vcarecity/publish/config/MapperConfig.java Просмотреть файл

@@ -1,4 +1,4 @@
1
-package com.vcarecity.elastic.publish.config;
1
+package com.vcarecity.publish.config;
2 2
 
3 3
 import com.fasterxml.jackson.annotation.JsonInclude;
4 4
 import com.fasterxml.jackson.databind.DeserializationFeature;

elastic-publish-service/src/main/java/com/vcarecity/elastic/publish/controller/MainController.java → elastic-publish-service/src/main/java/com/vcarecity/publish/controller/MainController.java Просмотреть файл

@@ -1,8 +1,8 @@
1
-package com.vcarecity.elastic.publish.controller;
1
+package com.vcarecity.publish.controller;
2 2
 
3
-import com.vcarecity.elastic.publish.pojo.dto.UnitAgencyDTO;
4
-import com.vcarecity.elastic.publish.pojo.query.UnitAgencyQuery;
5
-import com.vcarecity.elastic.publish.service.UnitService;
3
+import com.vcarecity.publish.pojo.dto.UnitAgencyDTO;
4
+import com.vcarecity.publish.pojo.query.UnitAgencyQuery;
5
+import com.vcarecity.publish.sql.service.UnitService;
6 6
 import org.springframework.web.bind.annotation.PostMapping;
7 7
 import org.springframework.web.bind.annotation.RequestBody;
8 8
 import org.springframework.web.bind.annotation.RestController;

elastic-publish-service/src/main/java/com/vcarecity/elastic/publish/controller/TestController.java → elastic-publish-service/src/main/java/com/vcarecity/publish/controller/TestController.java Просмотреть файл

@@ -1,4 +1,4 @@
1
-package com.vcarecity.elastic.publish.controller;
1
+package com.vcarecity.publish.controller;
2 2
 
3 3
 import org.springframework.web.bind.annotation.GetMapping;
4 4
 import org.springframework.web.bind.annotation.RestController;

+ 17 - 0
elastic-publish-service/src/main/java/com/vcarecity/publish/elastic/entity/UnitAgencyDetailEntity.java Просмотреть файл

@@ -0,0 +1,17 @@
1
+package com.vcarecity.publish.elastic.entity;
2
+
3
+import com.vcarecity.publish.entity.UnitAgencyMergeEntity;
4
+import lombok.Data;
5
+import lombok.EqualsAndHashCode;
6
+import lombok.ToString;
7
+
8
+/**
9
+ * @author kerryzhang on 2019/12/17
10
+ */
11
+
12
+@ToString(callSuper = true)
13
+@EqualsAndHashCode(callSuper = true)
14
+@Data
15
+public class UnitAgencyDetailEntity extends UnitAgencyMergeEntity {
16
+    private String agencyDetail;
17
+}

+ 8 - 0
elastic-publish-service/src/main/java/com/vcarecity/publish/elastic/service/ElasticLoadDataService.java Просмотреть файл

@@ -0,0 +1,8 @@
1
+package com.vcarecity.publish.elastic.service;
2
+
3
+/**
4
+ * @author kerryzhang on 2019/12/17
5
+ */
6
+
7
+public interface ElasticLoadDataService {
8
+}

elastic-publish-service/src/main/java/com/vcarecity/elastic/publish/service/QueryElasticService.java → elastic-publish-service/src/main/java/com/vcarecity/publish/elastic/service/ElasticQueryService.java Просмотреть файл

@@ -1,4 +1,4 @@
1
-package com.vcarecity.elastic.publish.service;
1
+package com.vcarecity.publish.elastic.service;
2 2
 
3 3
 import java.util.List;
4 4
 
@@ -6,7 +6,8 @@ import java.util.List;
6 6
  * @author VcKerry on 12/17/19
7 7
  */
8 8
 
9
-public interface QueryElasticService {
9
+public interface ElasticQueryService {
10
+
10 11
 
11 12
     List<Long> queryById();
12 13
 }

elastic-publish-service/src/main/java/com/vcarecity/elastic/publish/service/UpdateElasticService.java → elastic-publish-service/src/main/java/com/vcarecity/publish/elastic/service/ElasticUpdateService.java Просмотреть файл

@@ -1,6 +1,6 @@
1
-package com.vcarecity.elastic.publish.service;
1
+package com.vcarecity.publish.elastic.service;
2 2
 
3
-import com.vcarecity.elastic.publish.entity.UnitAgencyMergeEntity;
3
+import com.vcarecity.publish.entity.UnitAgencyMergeEntity;
4 4
 
5 5
 import java.io.IOException;
6 6
 import java.util.List;
@@ -9,7 +9,7 @@ import java.util.List;
9 9
  * @author Kerry on 12/17/19
10 10
  */
11 11
 
12
-public interface UpdateElasticService {
12
+public interface ElasticUpdateService {
13 13
 
14 14
     void updateTest() throws IOException;
15 15
 

+ 12 - 0
elastic-publish-service/src/main/java/com/vcarecity/publish/elastic/service/impl/ElasticLoadDataServiceImpl.java Просмотреть файл

@@ -0,0 +1,12 @@
1
+package com.vcarecity.publish.elastic.service.impl;
2
+
3
+import com.vcarecity.publish.elastic.service.ElasticLoadDataService;
4
+import org.springframework.stereotype.Service;
5
+
6
+/**
7
+ * @author kerryzhang on 2019/12/17
8
+ */
9
+
10
+@Service
11
+public class ElasticLoadDataServiceImpl implements ElasticLoadDataService {
12
+}

elastic-publish-service/src/main/java/com/vcarecity/elastic/publish/service/impl/QueryElasticServiceImpl.java → elastic-publish-service/src/main/java/com/vcarecity/publish/elastic/service/impl/ElasticQueryServiceImpl.java Просмотреть файл

@@ -1,6 +1,6 @@
1
-package com.vcarecity.elastic.publish.service.impl;
1
+package com.vcarecity.publish.elastic.service.impl;
2 2
 
3
-import com.vcarecity.elastic.publish.service.QueryElasticService;
3
+import com.vcarecity.publish.elastic.service.ElasticQueryService;
4 4
 import org.springframework.stereotype.Service;
5 5
 
6 6
 import java.util.List;
@@ -10,7 +10,7 @@ import java.util.List;
10 10
  */
11 11
 
12 12
 @Service
13
-public class QueryElasticServiceImpl implements QueryElasticService {
13
+public class ElasticQueryServiceImpl implements ElasticQueryService {
14 14
     @Override
15 15
     public List<Long> queryById() {
16 16
         return null;

elastic-publish-service/src/main/java/com/vcarecity/elastic/publish/service/impl/UpdateElasticServiceImpl.java → elastic-publish-service/src/main/java/com/vcarecity/publish/elastic/service/impl/ElasticUpdateServiceImpl.java Просмотреть файл

@@ -1,7 +1,9 @@
1
-package com.vcarecity.elastic.publish.service.impl;
1
+package com.vcarecity.publish.elastic.service.impl;
2 2
 
3
-import com.vcarecity.elastic.publish.entity.UnitAgencyMergeEntity;
4
-import com.vcarecity.elastic.publish.service.UpdateElasticService;
3
+import com.fasterxml.jackson.core.type.TypeReference;
4
+import com.fasterxml.jackson.databind.ObjectMapper;
5
+import com.vcarecity.publish.entity.UnitAgencyMergeEntity;
6
+import com.vcarecity.publish.elastic.service.ElasticUpdateService;
5 7
 import org.elasticsearch.client.RequestOptions;
6 8
 import org.elasticsearch.client.RestHighLevelClient;
7 9
 import org.elasticsearch.index.query.QueryBuilders;
@@ -13,6 +15,7 @@ import org.elasticsearch.script.ScriptType;
13 15
 import org.springframework.stereotype.Service;
14 16
 
15 17
 import java.io.IOException;
18
+import java.lang.reflect.Type;
16 19
 import java.util.ArrayList;
17 20
 import java.util.HashMap;
18 21
 import java.util.List;
@@ -23,14 +26,17 @@ import java.util.Map;
23 26
  */
24 27
 
25 28
 @Service
26
-public class UpdateElasticServiceImpl implements UpdateElasticService {
29
+public class ElasticUpdateServiceImpl implements ElasticUpdateService {
27 30
 
28 31
     public static final String INDEX = "unit-agency";
29 32
 
30 33
     private final RestHighLevelClient restHighLevelClient;
34
+    private final ObjectMapper objectMapper;
31 35
 
32
-    public UpdateElasticServiceImpl(RestHighLevelClient restHighLevelClient) {
36
+    public ElasticUpdateServiceImpl(RestHighLevelClient restHighLevelClient,
37
+                                    ObjectMapper objectMapper) {
33 38
         this.restHighLevelClient = restHighLevelClient;
39
+        this.objectMapper = objectMapper;
34 40
     }
35 41
 
36 42
 
@@ -69,14 +75,34 @@ public class UpdateElasticServiceImpl implements UpdateElasticService {
69 75
 
70 76
     @Override
71 77
     public void updateUnit(List<UnitAgencyMergeEntity> list) throws IOException {
78
+        List<UnitAgencyMergeEntity> updateList = new ArrayList<>();
72 79
         List<Long> deleteId = new ArrayList<>();
73 80
         for (UnitAgencyMergeEntity uae : list) {
74 81
             if (uae.getIsDeleted() == 1) {
75 82
                 deleteId.add(uae.getUnitId());
83
+            } else if (uae.getIsDeleted() == 0) {
84
+                updateList.add(uae);
76 85
             }
77 86
         }
78 87
         deleteById("unitId", deleteId);
88
+        if (updateList.isEmpty()) {
89
+            return;
90
+        }
91
+        for (UnitAgencyMergeEntity entity : updateList) {
92
+
93
+            Map<String, Object> map = objectMapper.convertValue(entity, new TypeReference<Map<String, Object>>() {
94
+                @Override
95
+                public Type getType() {
96
+                    return super.getType();
97
+                }
98
+            });
99
+
100
+            map.remove("unitId");
79 101
 
102
+            UpdateByQueryRequest request = new UpdateByQueryRequest(INDEX);
103
+            request.setQuery(QueryBuilders.termQuery("unitId", entity.getUnitId()));
104
+
105
+        }
80 106
     }
81 107
 
82 108
     @Override
@@ -92,12 +118,18 @@ public class UpdateElasticServiceImpl implements UpdateElasticService {
92 118
         }
93 119
         deleteById("agencyId", deleteId);
94 120
         list.clear();
95
-
121
+        updateElasticData("agencyId", updateList);
96 122
     }
97 123
 
98 124
 
99
-    private void insertData(List<UnitAgencyMergeEntity> list) {
100
-
125
+    private void updateElasticData(String key, List<UnitAgencyMergeEntity> list) throws IOException {
126
+        if (list == null || list.isEmpty()) {
127
+            return;
128
+        }
129
+        for (UnitAgencyMergeEntity item : list) {
130
+            UpdateByQueryRequest request = new UpdateByQueryRequest(INDEX);
131
+            request.setQuery(QueryBuilders.termQuery(key, item.getAgencyId()));
132
+        }
101 133
     }
102 134
 
103 135
     private void deleteById(String key, List<Long> deleteId) throws IOException {

elastic-publish-service/src/main/java/com/vcarecity/elastic/publish/entity/AgencyEntity.java → elastic-publish-service/src/main/java/com/vcarecity/publish/entity/AgencyEntity.java Просмотреть файл

@@ -1,4 +1,4 @@
1
-package com.vcarecity.elastic.publish.entity;
1
+package com.vcarecity.publish.entity;
2 2
 
3 3
 import lombok.Data;
4 4
 

elastic-publish-service/src/main/java/com/vcarecity/elastic/publish/entity/BuildingEntity.java → elastic-publish-service/src/main/java/com/vcarecity/publish/entity/BuildingEntity.java Просмотреть файл

@@ -1,4 +1,4 @@
1
-package com.vcarecity.elastic.publish.entity;
1
+package com.vcarecity.publish.entity;
2 2
 
3 3
 import lombok.Data;
4 4
 

elastic-publish-service/src/main/java/com/vcarecity/elastic/publish/entity/UnitAgencyMergeEntity.java → elastic-publish-service/src/main/java/com/vcarecity/publish/entity/UnitAgencyMergeEntity.java Просмотреть файл

@@ -1,4 +1,4 @@
1
-package com.vcarecity.elastic.publish.entity;
1
+package com.vcarecity.publish.entity;
2 2
 
3 3
 import lombok.Data;
4 4
 

elastic-publish-service/src/main/java/com/vcarecity/elastic/publish/entity/UnitEntity.java → elastic-publish-service/src/main/java/com/vcarecity/publish/entity/UnitEntity.java Просмотреть файл

@@ -1,4 +1,4 @@
1
-package com.vcarecity.elastic.publish.entity;
1
+package com.vcarecity.publish.entity;
2 2
 
3 3
 import lombok.Data;
4 4
 

elastic-publish-service/src/main/java/com/vcarecity/elastic/publish/mapper/AgencyMapper.java → elastic-publish-service/src/main/java/com/vcarecity/publish/mapper/AgencyMapper.java Просмотреть файл

@@ -1,7 +1,7 @@
1
-package com.vcarecity.elastic.publish.mapper;
1
+package com.vcarecity.publish.mapper;
2 2
 
3
-import com.vcarecity.elastic.publish.entity.AgencyEntity;
4
-import com.vcarecity.elastic.publish.entity.UnitAgencyMergeEntity;
3
+import com.vcarecity.publish.entity.AgencyEntity;
4
+import com.vcarecity.publish.entity.UnitAgencyMergeEntity;
5 5
 import org.apache.ibatis.annotations.Mapper;
6 6
 import org.apache.ibatis.annotations.Param;
7 7
 
@@ -35,4 +35,11 @@ public interface AgencyMapper {
35 35
     List<UnitAgencyMergeEntity> findUpdateUaList(@Param("fromDate") String fromDate, @Param("toDate") String toDate);
36 36
 
37 37
 
38
+    /**
39
+     * 获取ID对应的AgencyName
40
+     *
41
+     * @param agencyPathIds
42
+     * @return
43
+     */
44
+    List<String> findAgencyNameByAgencyIdList(@Param("agencyPathIds") List<Integer> agencyPathIds);
38 45
 }

elastic-publish-service/src/main/java/com/vcarecity/elastic/publish/mapper/BuildingMapper.java → elastic-publish-service/src/main/java/com/vcarecity/publish/mapper/BuildingMapper.java Просмотреть файл

@@ -1,6 +1,6 @@
1
-package com.vcarecity.elastic.publish.mapper;
1
+package com.vcarecity.publish.mapper;
2 2
 
3
-import com.vcarecity.elastic.publish.entity.BuildingEntity;
3
+import com.vcarecity.publish.entity.BuildingEntity;
4 4
 import org.apache.ibatis.annotations.Mapper;
5 5
 import org.apache.ibatis.annotations.Param;
6 6
 

elastic-publish-service/src/main/java/com/vcarecity/elastic/publish/mapper/UnitMapper.java → elastic-publish-service/src/main/java/com/vcarecity/publish/mapper/UnitMapper.java Просмотреть файл

@@ -1,7 +1,7 @@
1
-package com.vcarecity.elastic.publish.mapper;
1
+package com.vcarecity.publish.mapper;
2 2
 
3
-import com.vcarecity.elastic.publish.entity.UnitAgencyMergeEntity;
4
-import com.vcarecity.elastic.publish.entity.UnitEntity;
3
+import com.vcarecity.publish.entity.UnitAgencyMergeEntity;
4
+import com.vcarecity.publish.entity.UnitEntity;
5 5
 import org.apache.ibatis.annotations.Mapper;
6 6
 import org.apache.ibatis.annotations.Param;
7 7
 

elastic-publish-service/src/main/java/com/vcarecity/elastic/publish/pojo/dto/UnitAgencyDTO.java → elastic-publish-service/src/main/java/com/vcarecity/publish/pojo/dto/UnitAgencyDTO.java Просмотреть файл

@@ -1,4 +1,4 @@
1
-package com.vcarecity.elastic.publish.pojo.dto;
1
+package com.vcarecity.publish.pojo.dto;
2 2
 
3 3
 import lombok.Data;
4 4
 

elastic-publish-service/src/main/java/com/vcarecity/elastic/publish/pojo/query/UnitAgencyQuery.java → elastic-publish-service/src/main/java/com/vcarecity/publish/pojo/query/UnitAgencyQuery.java Просмотреть файл

@@ -1,4 +1,4 @@
1
-package com.vcarecity.elastic.publish.pojo.query;
1
+package com.vcarecity.publish.pojo.query;
2 2
 
3 3
 import lombok.Data;
4 4
 

elastic-publish-service/src/main/java/com/vcarecity/elastic/publish/service/CheckTimeService.java → elastic-publish-service/src/main/java/com/vcarecity/publish/service/CheckTimeService.java Просмотреть файл

@@ -1,4 +1,4 @@
1
-package com.vcarecity.elastic.publish.service;
1
+package com.vcarecity.publish.service;
2 2
 
3 3
 /**
4 4
  * @author VcKerry on 12/17/19

elastic-publish-service/src/main/java/com/vcarecity/elastic/publish/service/impl/CheckTimeServiceImpl.java → elastic-publish-service/src/main/java/com/vcarecity/publish/service/impl/CheckTimeServiceImpl.java Просмотреть файл

@@ -1,7 +1,7 @@
1
-package com.vcarecity.elastic.publish.service.impl;
1
+package com.vcarecity.publish.service.impl;
2 2
 
3
-import com.vcarecity.elastic.publish.service.CheckTimeService;
4
-import com.vcarecity.elastic.publish.util.DateUtil;
3
+import com.vcarecity.publish.service.CheckTimeService;
4
+import com.vcarecity.publish.util.DateUtil;
5 5
 import org.springframework.stereotype.Service;
6 6
 
7 7
 import java.time.LocalDateTime;

+ 18 - 0
elastic-publish-service/src/main/java/com/vcarecity/publish/sql/service/AgencyService.java Просмотреть файл

@@ -0,0 +1,18 @@
1
+package com.vcarecity.publish.sql.service;
2
+
3
+import java.util.List;
4
+
5
+/**
6
+ * @author kerryzhang on 2019/12/17
7
+ */
8
+
9
+public interface AgencyService {
10
+
11
+    /**
12
+     * 获取
13
+     *
14
+     * @param agencyPath
15
+     * @return
16
+     */
17
+    List<String> getAgencyPathDetail(List<Integer> agencyPath);
18
+}

elastic-publish-service/src/main/java/com/vcarecity/elastic/publish/service/UnitService.java → elastic-publish-service/src/main/java/com/vcarecity/publish/sql/service/UnitService.java Просмотреть файл

@@ -1,6 +1,6 @@
1
-package com.vcarecity.elastic.publish.service;
1
+package com.vcarecity.publish.sql.service;
2 2
 
3
-import com.vcarecity.elastic.publish.pojo.dto.UnitAgencyDTO;
3
+import com.vcarecity.publish.pojo.dto.UnitAgencyDTO;
4 4
 
5 5
 import java.io.IOException;
6 6
 import java.util.List;

+ 28 - 0
elastic-publish-service/src/main/java/com/vcarecity/publish/sql/service/impl/AgencyServiceImpl.java Просмотреть файл

@@ -0,0 +1,28 @@
1
+package com.vcarecity.publish.sql.service.impl;
2
+
3
+import com.vcarecity.publish.mapper.AgencyMapper;
4
+import com.vcarecity.publish.sql.service.AgencyService;
5
+import org.springframework.stereotype.Service;
6
+
7
+import java.util.List;
8
+
9
+/**
10
+ * @author kerryzhang on 2019/12/17
11
+ */
12
+
13
+@Service
14
+public class AgencyServiceImpl implements AgencyService {
15
+
16
+    private final AgencyMapper agencyMapper;
17
+
18
+    public AgencyServiceImpl(AgencyMapper agencyMapper) {
19
+        this.agencyMapper = agencyMapper;
20
+    }
21
+
22
+    @Override
23
+    public List<String> getAgencyPathDetail(List<Integer> agencyPath) {
24
+
25
+        //TODO 可以优化的空间
26
+        return agencyMapper.findAgencyNameByAgencyIdList(agencyPath);
27
+    }
28
+}

elastic-publish-service/src/main/java/com/vcarecity/elastic/publish/service/impl/UnitServiceImpl.java → elastic-publish-service/src/main/java/com/vcarecity/publish/sql/service/impl/UnitServiceImpl.java Просмотреть файл

@@ -1,8 +1,8 @@
1
-package com.vcarecity.elastic.publish.service.impl;
1
+package com.vcarecity.publish.sql.service.impl;
2 2
 
3 3
 import com.fasterxml.jackson.databind.ObjectMapper;
4
-import com.vcarecity.elastic.publish.pojo.dto.UnitAgencyDTO;
5
-import com.vcarecity.elastic.publish.service.UnitService;
4
+import com.vcarecity.publish.pojo.dto.UnitAgencyDTO;
5
+import com.vcarecity.publish.sql.service.UnitService;
6 6
 import com.vcarecity.elastic.util.AgencyPathUtil;
7 7
 import lombok.extern.slf4j.Slf4j;
8 8
 import org.elasticsearch.action.search.SearchRequest;

+ 76 - 0
elastic-publish-service/src/main/java/com/vcarecity/publish/task/CheckUpdateTask.java Просмотреть файл

@@ -0,0 +1,76 @@
1
+package com.vcarecity.publish.task;
2
+
3
+import com.vcarecity.publish.entity.UnitAgencyMergeEntity;
4
+import com.vcarecity.publish.mapper.AgencyMapper;
5
+import com.vcarecity.publish.mapper.UnitMapper;
6
+import com.vcarecity.publish.service.CheckTimeService;
7
+import com.vcarecity.publish.elastic.service.ElasticUpdateService;
8
+import com.vcarecity.publish.util.DateUtil;
9
+import org.springframework.stereotype.Component;
10
+
11
+import java.time.LocalDateTime;
12
+import java.time.ZoneId;
13
+import java.util.Date;
14
+import java.util.List;
15
+
16
+/**
17
+ * @author Kerry on 19/12/11
18
+ */
19
+
20
+@Component
21
+public class CheckUpdateTask {
22
+
23
+    private final CheckTimeService checkTimeService;
24
+    private final ElasticUpdateService elasticUpdateService;
25
+    private final AgencyMapper agencyMapper;
26
+    private final UnitMapper unitMapper;
27
+
28
+
29
+    public CheckUpdateTask(CheckTimeService checkTimeService,
30
+                           ElasticUpdateService elasticUpdateService,
31
+                           AgencyMapper agencyMapper,
32
+                           UnitMapper unitMapper) {
33
+        this.checkTimeService = checkTimeService;
34
+        this.elasticUpdateService = elasticUpdateService;
35
+        this.agencyMapper = agencyMapper;
36
+        this.unitMapper = unitMapper;
37
+    }
38
+
39
+
40
+    public void checkTask() {
41
+
42
+        // 当前更新时间
43
+        long curCheckTime = System.currentTimeMillis();
44
+        String toDateTime = LocalDateTime.ofInstant(new Date(curCheckTime).toInstant(), ZoneId.systemDefault()).format(DateUtil.DATE_TIME_FORMATTER);
45
+
46
+        List<UnitAgencyMergeEntity> updateUaList;
47
+        String fromDateTime;
48
+
49
+        // 获取上一次的时间
50
+        fromDateTime = checkTimeService.getLastDateTime("T_UNIT");
51
+        try {
52
+            updateUaList = unitMapper.findUpdateUaList(fromDateTime, toDateTime);
53
+            if (!updateUaList.isEmpty()) {
54
+                elasticUpdateService.updateUnit(updateUaList);
55
+            }
56
+            checkTimeService.setLastDateTime("T_UNIT", curCheckTime);
57
+            updateUaList.clear();
58
+        } catch (Exception e) {
59
+            e.printStackTrace();
60
+        }
61
+
62
+
63
+        fromDateTime = checkTimeService.getLastDateTime("T_AGENCY");
64
+        try {
65
+            updateUaList = agencyMapper.findUpdateUaList(fromDateTime, toDateTime);
66
+            if (!updateUaList.isEmpty()) {
67
+                elasticUpdateService.updateAgency(updateUaList);
68
+            }
69
+            checkTimeService.setLastDateTime("T_AGENCY", curCheckTime);
70
+            updateUaList.clear();
71
+        } catch (Exception e) {
72
+            e.printStackTrace();
73
+        }
74
+    }
75
+
76
+}

elastic-publish-service/src/main/java/com/vcarecity/elastic/publish/util/DateUtil.java → elastic-publish-service/src/main/java/com/vcarecity/publish/util/DateUtil.java Просмотреть файл

@@ -1,4 +1,4 @@
1
-package com.vcarecity.elastic.publish.util;
1
+package com.vcarecity.publish.util;
2 2
 
3 3
 import java.time.format.DateTimeFormatter;
4 4
 

+ 1 - 1
elastic-publish-service/src/main/resources/application-dev.yml Просмотреть файл

@@ -20,5 +20,5 @@ logging:
20 20
     com:
21 21
       vcarecity: debug
22 22
 mybatis:
23
-  type-aliases-package: com.vcarecity.elastic.publish.entity
23
+  type-aliases-package: com.vcarecity.publish.entity
24 24
   mapper-locations: classpath:mapper/*.xml

+ 15 - 3
elastic-publish-service/src/main/resources/mapper/AgencyMapper.xml Просмотреть файл

@@ -1,12 +1,14 @@
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
 
4
-<mapper namespace="com.vcarecity.elastic.publish.mapper.AgencyMapper">
4
+<mapper namespace="com.vcarecity.publish.mapper.AgencyMapper">
5 5
 
6 6
 
7 7
     <select id="findUpdateList" resultType="agencyEntity">
8
-        select AGENCY_ID,AGENCY_PATH,AGENCY_NAME,ISDELETED from T_AGENCY where UPDATESTAMP between to_date('${fromDate}','YYYY-MM-DD HH24:MI:SS')
9
-        and to_date('${toDate}','YYYY-MM-DD HH24:MI:SS')
8
+        select AGENCY_ID, AGENCY_PATH, AGENCY_NAME, ISDELETED
9
+        from T_AGENCY
10
+        where UPDATESTAMP between to_date('${fromDate}', 'YYYY-MM-DD HH24:MI:SS')
11
+                  and to_date('${toDate}', 'YYYY-MM-DD HH24:MI:SS')
10 12
     </select>
11 13
 
12 14
     <resultMap id="unitAgencyMergeEntityMap" type="unitAgencyMergeEntity">
@@ -47,5 +49,15 @@
47 49
                  INNER JOIN T_UNIT_TYPE TUT ON TUT.UNIT_TYPE_ID = TU.UNIT_TYPE_ID
48 50
     </select>
49 51
 
52
+    <select id="findAgencyNameByAgencyIdList" resultType="string" parameterType="list">
53
+        select AGENCY_NAME from T_AGENCY
54
+        <where>
55
+            AGENCY_ID in
56
+            <foreach item="item" collection="agencyPathIds" separator="," open="(" close=")" index="">
57
+                ${item}
58
+            </foreach>
59
+        </where>
60
+    </select>
61
+
50 62
 
51 63
 </mapper>

+ 1 - 1
elastic-publish-service/src/main/resources/mapper/BuildingMapper.xml Просмотреть файл

@@ -1,6 +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
-<mapper namespace="com.vcarecity.elastic.publish.mapper.BuildingMapper">
3
+<mapper namespace="com.vcarecity.publish.mapper.BuildingMapper">
4 4
 
5 5
     <select id="findUpdateList" resultType="buildingEntity">
6 6
         select BUILDING_ID, NAME_OF_BUILDING, ISDELETED

+ 1 - 1
elastic-publish-service/src/main/resources/mapper/UnitMapper.xml Просмотреть файл

@@ -1,6 +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
-<mapper namespace="com.vcarecity.elastic.publish.mapper.UnitMapper">
3
+<mapper namespace="com.vcarecity.publish.mapper.UnitMapper">
4 4
 
5 5
     <select id="findUpdateList" resultType="unitEntity">
6 6
         select UNIT_ID, DTU_NO, PUSER_CODE, ISDELETED

+ 0 - 21
elastic-publish-service/src/test/java/com/vcarecity/elastic/publish/service/impl/UpdateElasticServiceImplTest.java Просмотреть файл

@@ -1,21 +0,0 @@
1
-package com.vcarecity.elastic.publish.service.impl;
2
-
3
-import com.vcarecity.elastic.publish.service.UpdateElasticService;
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
-
9
-@SpringBootTest
10
-public class UpdateElasticServiceImplTest {
11
-
12
-    @Autowired
13
-    private UpdateElasticService updateElasticService;
14
-
15
-    @Test
16
-    void updateTest() throws Exception {
17
-        updateElasticService.updateTest();
18
-    }
19
-
20
-
21
-}

elastic-publish-service/src/test/java/com/vcarecity/elastic/publish/mapper/AgencyMapperTest.java → elastic-publish-service/src/test/java/com/vcarecity/publish/mapper/AgencyMapperTest.java Просмотреть файл

@@ -1,4 +1,4 @@
1
-package com.vcarecity.elastic.publish.mapper;
1
+package com.vcarecity.publish.mapper;
2 2
 
3 3
 import org.junit.jupiter.api.Test;
4 4
 import org.springframework.beans.factory.annotation.Autowired;

elastic-publish-service/src/test/java/com/vcarecity/elastic/publish/mapper/BuildingMapperTest.java → elastic-publish-service/src/test/java/com/vcarecity/publish/mapper/BuildingMapperTest.java Просмотреть файл

@@ -1,4 +1,4 @@
1
-package com.vcarecity.elastic.publish.mapper;
1
+package com.vcarecity.publish.mapper;
2 2
 
3 3
 import org.junit.jupiter.api.Test;
4 4
 import org.springframework.beans.factory.annotation.Autowired;

elastic-publish-service/src/test/java/com/vcarecity/elastic/publish/mapper/UnitMapperTest.java → elastic-publish-service/src/test/java/com/vcarecity/publish/mapper/UnitMapperTest.java Просмотреть файл

@@ -1,6 +1,6 @@
1
-package com.vcarecity.elastic.publish.mapper;
1
+package com.vcarecity.publish.mapper;
2 2
 
3
-import com.vcarecity.elastic.publish.entity.UnitAgencyMergeEntity;
3
+import com.vcarecity.publish.entity.UnitAgencyMergeEntity;
4 4
 import org.junit.jupiter.api.Test;
5 5
 import org.springframework.beans.factory.annotation.Autowired;
6 6
 import org.springframework.boot.test.context.SpringBootTest;

+ 21 - 0
elastic-publish-service/src/test/java/com/vcarecity/publish/service/impl/ElasticUpdateServiceImplTest.java Просмотреть файл

@@ -0,0 +1,21 @@
1
+package com.vcarecity.publish.service.impl;
2
+
3
+import com.vcarecity.publish.elastic.service.ElasticUpdateService;
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
+
9
+@SpringBootTest
10
+public class ElasticUpdateServiceImplTest {
11
+
12
+    @Autowired
13
+    private ElasticUpdateService elasticUpdateService;
14
+
15
+    @Test
16
+    void updateTest() throws Exception {
17
+        elasticUpdateService.updateTest();
18
+    }
19
+
20
+
21
+}

elastic-publish-service/src/test/java/com/vcarecity/elastic/publish/service/impl/UnitServiceImplTest.java → elastic-publish-service/src/test/java/com/vcarecity/publish/service/impl/UnitServiceImplTest.java Просмотреть файл

@@ -1,4 +1,4 @@
1
-package com.vcarecity.elastic.publish.service.impl;
1
+package com.vcarecity.publish.service.impl;
2 2
 
3 3
 import org.elasticsearch.action.update.UpdateRequest;
4 4
 import org.elasticsearch.client.RestHighLevelClient;