瀏覽代碼

add manual load data

kerryzhang 5 年之前
父節點
當前提交
0b6503ba36

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

@@ -36,4 +36,10 @@ Content-Type: application/json
36 36
 
37 37
 GET http://{{host}}/load
38 38
 
39
+### load data
40
+
41
+
42
+
43
+GET http://{{host}}/loadByAgencyIds?agencyIds=190084,196581
44
+
39 45
 ### load data

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

@@ -5,11 +5,14 @@ import com.vcarecity.publish.api.ApiResult;
5 5
 import com.vcarecity.publish.api.ApiStatus;
6 6
 import com.vcarecity.publish.constants.ElasticConstant;
7 7
 import com.vcarecity.publish.elastic.service.ElasticLoadDataService;
8
+import com.vcarecity.publish.elastic.service.ElasticUpdateService;
9
+import com.vcarecity.publish.entity.UnitAgencyMergeEntity;
8 10
 import com.vcarecity.publish.pojo.dto.TotalResultDTO;
9 11
 import com.vcarecity.publish.pojo.dto.UnitAgencyDTO;
10 12
 import com.vcarecity.publish.pojo.dto.UnitIdDTO;
11 13
 import com.vcarecity.publish.pojo.query.UnitAgencyQuery;
12 14
 import com.vcarecity.publish.service.LoadDataStatusService;
15
+import com.vcarecity.publish.sql.service.AgencyService;
13 16
 import com.vcarecity.publish.sql.service.UnitService;
14 17
 import lombok.extern.slf4j.Slf4j;
15 18
 import org.springframework.beans.factory.annotation.Value;
@@ -17,6 +20,7 @@ import org.springframework.web.bind.annotation.*;
17 20
 
18 21
 import javax.validation.Valid;
19 22
 import java.io.IOException;
23
+import java.util.ArrayList;
20 24
 import java.util.List;
21 25
 
22 26
 /**
@@ -29,16 +33,20 @@ public class MainController implements PrepareController {
29 33
 
30 34
 
31 35
     private final UnitService unitService;
36
+    private final AgencyService agencyService;
32 37
     private final ElasticLoadDataService elasticLoadDataService;
38
+    private final ElasticUpdateService elasticUpdateService;
33 39
     private final LoadDataStatusService loadDataStatusService;
34 40
 
35 41
     public MainController(UnitService unitService,
36 42
                           ElasticLoadDataService elasticLoadDataService,
37 43
                           LoadDataStatusService loadDataStatusService,
38
-                          @Value("${app.index.reload}") Boolean reloadData) {
44
+                          @Value("${app.index.reload}") Boolean reloadData, AgencyService agencyService, ElasticUpdateService elasticUpdateService) {
39 45
         this.unitService = unitService;
40 46
         this.elasticLoadDataService = elasticLoadDataService;
41 47
         this.loadDataStatusService = loadDataStatusService;
48
+        this.agencyService = agencyService;
49
+        this.elasticUpdateService = elasticUpdateService;
42 50
 
43 51
         if (!reloadData) {
44 52
             // 不重新加载
@@ -49,7 +57,7 @@ public class MainController implements PrepareController {
49 57
 
50 58
     @SkipMethod
51 59
     @ResponseBody
52
-    @RequestMapping(value = "/load", method = {RequestMethod.GET, RequestMethod.POST})
60
+    @RequestMapping(value = "/set-load", method = {RequestMethod.GET, RequestMethod.POST})
53 61
     public ApiResult setLoaded() {
54 62
         loadDataStatusService.setStatus(LoadDataStatusService.DATA_STATUS_LOADED);
55 63
         return ApiResult.builder().status(20000).message("already load data success!").build();
@@ -82,6 +90,32 @@ public class MainController implements PrepareController {
82 90
     }
83 91
 
84 92
 
93
+    @ResponseBody
94
+    @RequestMapping(value = "/loadByAgencyIds", method = {RequestMethod.POST, RequestMethod.GET})
95
+    public ApiResult loadByAgencyIds(@RequestParam("agencyIds") String agencyIds) {
96
+        String[] split = agencyIds.split(",");
97
+        List<Long> ids = new ArrayList<>(split.length);
98
+        for (String s : split) {
99
+            try {
100
+                ids.add(Long.parseLong(s));
101
+            } catch (RuntimeException e) {
102
+                e.printStackTrace();
103
+            }
104
+        }
105
+        List<UnitAgencyMergeEntity> result = agencyService.loadByAgencyIds(ids);
106
+        if (result == null) {
107
+            return ApiResult.builder().status(ApiStatus.FAILED_CODE).build();
108
+        }
109
+        try {
110
+            elasticUpdateService.handlerDataChange("unitId", result);
111
+            return ApiResult.builder().status(ApiStatus.SUCCESS_CODE).build();
112
+        } catch (IOException e) {
113
+            e.printStackTrace();
114
+            return ApiResult.builder().status(40000).message(e.getMessage()).build();
115
+        }
116
+    }
117
+
118
+
85 119
     @PostMapping("/query-unit-agency")
86 120
     public ApiResult queryUnitAgency(@RequestBody @Valid UnitAgencyQuery unitAgencyQuery) throws IOException {
87 121
 

+ 10 - 0
elastic-publish-service/src/main/java/com/vcarecity/publish/mapper/AgencyMapper.java 查看文件

@@ -36,10 +36,20 @@ public interface AgencyMapper {
36 36
 
37 37
 
38 38
     /**
39
+     * load by ids
40
+     *
41
+     * @param ids
42
+     * @return
43
+     */
44
+    List<UnitAgencyMergeEntity> loadByAgencyIds(@Param("ids") List<Long> ids);
45
+
46
+
47
+    /**
39 48
      * 获取ID对应的AgencyName
40 49
      *
41 50
      * @param agencyPathIds
42 51
      * @return
43 52
      */
44 53
     List<AgencyEntity> findAgencyNameByAgencyIdList(@Param("agencyPathIds") List<Integer> agencyPathIds);
54
+
45 55
 }

+ 10 - 0
elastic-publish-service/src/main/java/com/vcarecity/publish/sql/service/AgencyService.java 查看文件

@@ -1,5 +1,7 @@
1 1
 package com.vcarecity.publish.sql.service;
2 2
 
3
+import com.vcarecity.publish.entity.UnitAgencyMergeEntity;
4
+
3 5
 import java.util.List;
4 6
 
5 7
 /**
@@ -15,4 +17,12 @@ public interface AgencyService {
15 17
      * @return
16 18
      */
17 19
     List<String> getAgencyPathDetail(List<Integer> agencyPath);
20
+
21
+    /**
22
+     * load by id
23
+     *
24
+     * @param ids
25
+     * @return
26
+     */
27
+    List<UnitAgencyMergeEntity> loadByAgencyIds(List<Long> ids);
18 28
 }

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

@@ -1,6 +1,7 @@
1 1
 package com.vcarecity.publish.sql.service.impl;
2 2
 
3 3
 import com.vcarecity.publish.entity.AgencyEntity;
4
+import com.vcarecity.publish.entity.UnitAgencyMergeEntity;
4 5
 import com.vcarecity.publish.mapper.AgencyMapper;
5 6
 import com.vcarecity.publish.sql.service.AgencyService;
6 7
 import org.springframework.stereotype.Service;
@@ -28,4 +29,13 @@ public class AgencyServiceImpl implements AgencyService {
28 29
         List<AgencyEntity> agencyNameByAgencyIdList = agencyMapper.findAgencyNameByAgencyIdList(agencyPath);
29 30
         return agencyNameByAgencyIdList.stream().map(AgencyEntity::getAgencyName).collect(Collectors.toList());
30 31
     }
32
+
33
+    @Override
34
+    public List<UnitAgencyMergeEntity> loadByAgencyIds(List<Long> ids) {
35
+        if (ids == null || ids.isEmpty()) {
36
+            return null;
37
+        }
38
+        return agencyMapper.loadByAgencyIds(ids);
39
+
40
+    }
31 41
 }

+ 5 - 3
elastic-publish-service/src/main/resources/application-production.yml 查看文件

@@ -2,9 +2,11 @@ server:
2 2
   port: 8092
3 3
 spring:
4 4
   datasource:
5
-    url: jdbc:mysql:replication://192.168.10.210:6446,192.168.10.210:6447/fmmp?serverTimezone=Asia/Shanghai
5
+    url: jdbc:mysql:replication://192.168.10.31:6446,192.168.10.31:6447/fmmp?serverTimezone=Asia/Shanghai
6 6
     username: root
7 7
     password: R00T@mysql
8
+    hikari:
9
+      connection-test-query: select 1
8 10
   elasticsearch:
9 11
     rest:
10 12
       uris:
@@ -26,6 +28,6 @@ mybatis:
26 28
 app:
27 29
   index:
28 30
     config: index-text
29
-    reload: true
31
+    reload: false
30 32
   scheduling:
31
-    enable: false
33
+    enable: true

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

@@ -1,5 +1,5 @@
1 1
 spring:
2 2
   profiles:
3
-    active: dev
3
+    #active: dev
4 4
     #active: beta
5
-    #active: production
5
+    active: production

+ 35 - 0
elastic-publish-service/src/main/resources/mapper/AgencyMapper.xml 查看文件

@@ -62,6 +62,41 @@
62 62
                  INNER JOIN T_AGENCY_EXTEND TAE ON TAE.AGENCY_ID = TU.AGENCY_ID
63 63
     </select>
64 64
 
65
+    <select id="loadByAgencyIds" resultMap="unitAgencyMergeEntityMap">
66
+        SELECT TU.UNIT_ID,
67
+        TU.DTU_NO,
68
+        TU.PUSER_CODE,
69
+        TU.USER_CODE,
70
+        TU.POSITIONS,
71
+        TU.UPDATESTAMP UNIT_UPDATE_STAMP,
72
+        TAG.AGENCY_ID,
73
+        TAG.AGENCY_PATH,
74
+        TAG.AGENCY_NAME,
75
+        TAG.ISDELETED,
76
+        TB.BUILDING_ID,
77
+        TB.NAME_OF_BUILDING,
78
+        TUT.UNIT_TYPE_ID,
79
+        TUT.UNIT_TYPE,
80
+        TUT.PROPERTY,
81
+        TUT.CLASSIFY,
82
+        TAE.REGULATORY_LEVEL_ID,
83
+        TAE.AGENCY_ATTRIBUTE_CLASS_ID
84
+        FROM (select *
85
+        from T_AGENCY I_TAG
86
+        <where>
87
+            where I_TAG.AGENCY_ID in
88
+            <foreach item="item" index="index" collection="ids" open="(" separator="," close=")">
89
+                    ${item}
90
+            </foreach>
91
+        </where>
92
+        ) TAG
93
+        INNER JOIN T_UNIT TU ON TU.AGENCY_ID = TAG.AGENCY_ID
94
+        INNER JOIN T_BUILDING TB ON TB.BUILDING_ID = TU.BUILDING_ID
95
+        INNER JOIN T_UNIT_TYPE TUT ON TUT.UNIT_TYPE_ID = TU.UNIT_TYPE_ID
96
+        INNER JOIN T_AGENCY_EXTEND TAE ON TAE.AGENCY_ID = TU.AGENCY_ID
97
+    </select>
98
+
99
+
65 100
     <select id="findAgencyNameByAgencyIdList" resultType="agencyEntity" parameterType="list">
66 101
         select AGENCY_NAME,AGENCY_ID from T_AGENCY
67 102
         <where>

+ 12 - 0
elastic-publish-service/src/test/java/com/vcarecity/publish/mapper/AgencyMapperTest.java 查看文件

@@ -1,6 +1,7 @@
1 1
 package com.vcarecity.publish.mapper;
2 2
 
3 3
 import com.vcarecity.publish.entity.AgencyEntity;
4
+import com.vcarecity.publish.entity.UnitAgencyMergeEntity;
4 5
 import org.junit.jupiter.api.Test;
5 6
 import org.springframework.beans.factory.annotation.Autowired;
6 7
 import org.springframework.boot.test.context.SpringBootTest;
@@ -44,4 +45,15 @@ public class AgencyMapperTest {
44 45
             System.out.println(agencyEntity);
45 46
         }
46 47
     }
48
+
49
+    @Test
50
+    public void loadByAgencyIds() {
51
+        List<Long> ids = new ArrayList<>();
52
+        ids.add(80424L);
53
+
54
+        List<UnitAgencyMergeEntity> unitAgencyMergeEntities = agencyMapper.loadByAgencyIds(ids);
55
+        for (UnitAgencyMergeEntity unitAgencyMergeEntity : unitAgencyMergeEntities) {
56
+            System.out.println(unitAgencyMergeEntity);
57
+        }
58
+    }
47 59
 }