소스 검색

add miss key field

kerry 5 년 전
부모
커밋
e6a2547f30

+ 12 - 1
elastic-publish-service/index-text/unit-agency.mapping.json 파일 보기

@@ -44,7 +44,18 @@
44 44
         }
45 45
       }
46 46
     },
47
-    "dtuNo": {
47
+    "userCode": {
48
+      "type": "text",
49
+      "analyzer": "case_sensitive",
50
+      "search_analyzer": "case_sensitive",
51
+      "fields": {
52
+        "keyword": {
53
+          "type": "keyword",
54
+          "ignore_above": 256
55
+        }
56
+      }
57
+    },
58
+    "positions": {
48 59
       "type": "text",
49 60
       "analyzer": "case_sensitive",
50 61
       "search_analyzer": "case_sensitive",

+ 7 - 2
elastic-publish-service/req/main-controller.http 파일 보기

@@ -21,7 +21,7 @@ Content-Type: application/json
21 21
 
22 22
 {
23 23
   "agencyPath": "/1",
24
-  "keyword": "卡拉ok",
24
+  "keyword": "b楼",
25 25
   "page": 1,
26 26
   "size": 10,
27 27
   "regulatoryLevelId": "",
@@ -31,4 +31,9 @@ Content-Type: application/json
31 31
   "unitTypeId": ""
32 32
 }
33 33
 
34
-### 详情信息
34
+### 详情信息
35
+
36
+
37
+GET http://{{host}}/load
38
+
39
+### load data

+ 27 - 4
elastic-publish-service/src/main/java/com/vcarecity/publish/aop/PrepareAopController.java 파일 보기

@@ -1,15 +1,23 @@
1 1
 package com.vcarecity.publish.aop;
2 2
 
3
+import com.vcarecity.publish.annotation.SkipMethod;
4
+import com.vcarecity.publish.api.ApiResult;
5
+import com.vcarecity.publish.controller.PrepareController;
3 6
 import org.aspectj.lang.ProceedingJoinPoint;
4 7
 import org.aspectj.lang.annotation.Around;
8
+import org.aspectj.lang.annotation.Aspect;
5 9
 import org.aspectj.lang.annotation.Pointcut;
10
+import org.aspectj.lang.reflect.MethodSignature;
11
+import org.springframework.stereotype.Component;
12
+
13
+import java.lang.reflect.Method;
6 14
 
7 15
 /**
8 16
  * @author VcKerry on 12/20/19
9 17
  */
10 18
 
11
-//@Aspect
12
-//@Component
19
+@Aspect
20
+@Component
13 21
 public class PrepareAopController {
14 22
 
15 23
 
@@ -21,7 +29,22 @@ public class PrepareAopController {
21 29
 
22 30
     @Around("preparePointcut()")
23 31
     public Object check(ProceedingJoinPoint pjp) throws Throwable {
24
-        return pjp.getTarget();
25
-    }
26 32
 
33
+        Object target = pjp.getTarget();
34
+        if (target instanceof PrepareController) {
35
+            MethodSignature signature = (MethodSignature) pjp.getSignature();
36
+            Method method = signature.getMethod();
37
+            if (method.getAnnotation(SkipMethod.class) != null) {
38
+                return pjp.proceed();
39
+            }
40
+
41
+            PrepareController o = (PrepareController) target;
42
+            if (o.isLoadData()) {
43
+                return pjp.proceed();
44
+            } else {
45
+                return ApiResult.builder().status(40000).message("data not loaded").build();
46
+            }
47
+        }
48
+        return pjp.proceed();
49
+    }
27 50
 }

+ 0 - 13
elastic-publish-service/src/main/java/com/vcarecity/publish/constants/ElasticConstant.java 파일 보기

@@ -22,18 +22,5 @@ public class ElasticConstant {
22 22
     public static final DateTimeFormatter ES_DT_FORMATTER = DateTimeFormatter.ofPattern(ES_DATETIME_PATTERN);
23 23
 
24 24
 
25
-    /**
26
-     * 数据未加载
27
-     */
28
-    public static final int DATA_STATUS_NOT_LOAD = -1;
29
-    /**
30
-     * 数据加载中
31
-     */
32
-    public static final int DATA_STATUS_LOADING = 0;
33
-    /**
34
-     * 数据加载完成
35
-     */
36
-    public static final int DATA_STATUS_LOADED = 1;
37
-
38 25
 
39 26
 }

+ 13 - 11
elastic-publish-service/src/main/java/com/vcarecity/publish/controller/MainController.java 파일 보기

@@ -35,34 +35,36 @@ public class MainController implements PrepareController {
35 35
     public MainController(UnitService unitService,
36 36
                           ElasticLoadDataService elasticLoadDataService,
37 37
                           LoadDataStatusService loadDataStatusService,
38
-                          @Value("${app.scheduling.enable}") Boolean schedulingEnable) {
38
+                          @Value("${app.index.reload}") Boolean reloadData) {
39 39
         this.unitService = unitService;
40 40
         this.elasticLoadDataService = elasticLoadDataService;
41 41
         this.loadDataStatusService = loadDataStatusService;
42
-        if (!schedulingEnable) {
43
-            loadDataStatusService.setStatus(ElasticConstant.DATA_STATUS_LOADED);
42
+
43
+        if (!reloadData) {
44
+            // 不重新加载
45
+            loadDataStatusService.setStatus(LoadDataStatusService.DATA_STATUS_LOADED);
44 46
         }
45 47
     }
46 48
 
47
-
49
+    @SkipMethod
48 50
     @ResponseBody
49 51
     @RequestMapping(value = "/load", method = {RequestMethod.GET, RequestMethod.POST})
50 52
     public ApiResult loadData() {
51 53
         synchronized (this) {
52
-            if (loadDataStatusService.getStatus() == ElasticConstant.DATA_STATUS_NOT_LOAD) {
54
+            if (loadDataStatusService.getStatus() == LoadDataStatusService.DATA_STATUS_NOT_LOAD) {
53 55
                 logger.info("prepare to load data into elasticsearch");
54
-                loadDataStatusService.setStatus(ElasticConstant.DATA_STATUS_LOADING);
56
+                loadDataStatusService.setStatus(LoadDataStatusService.DATA_STATUS_LOADING);
55 57
                 new Thread(() -> {
56 58
                     try {
57 59
                         elasticLoadDataService.loadData();
58
-                        loadDataStatusService.setStatus(ElasticConstant.DATA_STATUS_LOADED);
60
+                        loadDataStatusService.setStatus(LoadDataStatusService.DATA_STATUS_LOADED);
59 61
                     } catch (IOException e) {
60 62
                         e.printStackTrace();
61
-                        loadDataStatusService.setStatus(ElasticConstant.DATA_STATUS_NOT_LOAD);
63
+                        loadDataStatusService.setStatus(LoadDataStatusService.DATA_STATUS_NOT_LOAD);
62 64
                     }
63 65
                 }).start();
64 66
                 return ApiResult.builder().status(40000).message("first load data into elasticsearch").build();
65
-            } else if (loadDataStatusService.getStatus() == ElasticConstant.DATA_STATUS_LOADING) {
67
+            } else if (loadDataStatusService.getStatus() == LoadDataStatusService.DATA_STATUS_LOADING) {
66 68
                 return ApiResult.builder().status(40000).message("loading data into elasticsearch").build();
67 69
             }
68 70
         }
@@ -95,7 +97,7 @@ public class MainController implements PrepareController {
95 97
 
96 98
     @SkipMethod
97 99
     @Override
98
-    public int getDataStatus() {
99
-        return loadDataStatusService.getStatus();
100
+    public boolean isLoadData() {
101
+        return loadDataStatusService.isLoaded();
100 102
     }
101 103
 }

+ 1 - 1
elastic-publish-service/src/main/java/com/vcarecity/publish/controller/PrepareController.java 파일 보기

@@ -15,6 +15,6 @@ public interface PrepareController {
15 15
      * @return
16 16
      */
17 17
     @SkipMethod
18
-    int getDataStatus();
18
+    boolean isLoadData();
19 19
 
20 20
 }

+ 4 - 0
elastic-publish-service/src/main/java/com/vcarecity/publish/entity/UnitAgencyMergeEntity.java 파일 보기

@@ -19,6 +19,10 @@ public class UnitAgencyMergeEntity {
19 19
 
20 20
     private String puserCode;
21 21
 
22
+    private String userCode;
23
+
24
+    private String positions;
25
+
22 26
     @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = ElasticConstant.ES_DATETIME_PATTERN, timezone = "GMT+8")
23 27
     private Date unitUpdateStamp;
24 28
 

+ 2 - 0
elastic-publish-service/src/main/java/com/vcarecity/publish/pojo/dto/UnitAgencyDTO.java 파일 보기

@@ -13,7 +13,9 @@ import lombok.ToString;
13 13
 @Data
14 14
 public class UnitAgencyDTO extends UnitIdDTO {
15 15
     private String dtuNo;
16
+    private String userCode;
16 17
     private String agencyName;
18
+    private String positions;
17 19
     private String nameOfBuilding;
18 20
     private String unitType;
19 21
     private String unitUpdateStamp;

+ 3 - 2
elastic-publish-service/src/main/java/com/vcarecity/publish/sql/service/impl/UnitServiceImpl.java 파일 보기

@@ -47,10 +47,11 @@ public class UnitServiceImpl implements UnitService {
47 47
 
48 48
 
49 49
     static final String[] SEARCH_KEY_NAMES = new String[]{
50
-            "dtuNo",
51 50
             "agencyName",
52 51
             "unitType",
53 52
             "nameOfBuilding",
53
+            "userCode",
54
+            "positions"
54 55
     };
55 56
 
56 57
     static final String[] MATCH_KEY_NAMES = new String[]{
@@ -331,7 +332,7 @@ public class UnitServiceImpl implements UnitService {
331 332
         if (keyword == null || keyword.trim().length() == 0) {
332 333
             return null;
333 334
         }
334
-
335
+        keyword = keyword.toLowerCase();
335 336
 
336 337
         final BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
337 338
 

+ 1 - 0
elastic-publish-service/src/main/resources/application-beta.yml 파일 보기

@@ -26,5 +26,6 @@ debug: true
26 26
 app:
27 27
   index:
28 28
     config: index-text
29
+    reload: true
29 30
   scheduling:
30 31
     enable: true

+ 1 - 0
elastic-publish-service/src/main/resources/application-dev.yml 파일 보기

@@ -27,5 +27,6 @@ debug: true
27 27
 app:
28 28
   index:
29 29
     config: index-text
30
+    reload: true
30 31
   scheduling:
31 32
     enable: false

+ 4 - 0
elastic-publish-service/src/main/resources/mapper/AgencyMapper.xml 파일 보기

@@ -15,6 +15,8 @@
15 15
         <result column="UNIT_ID" property="unitId"/>
16 16
         <result column="DTU_NO" property="dtuNo"/>
17 17
         <result column="PUSER_CODE" property="puserCode"/>
18
+        <result column="USER_CODE" property="userCode"/>
19
+        <result column="POSITIONS" property="positions"/>
18 20
         <result column="UNIT_UPDATE_STAMP" property="unitUpdateStamp" javaType="java.util.Date"/>
19 21
         <result column="ISDELETED" property="isDeleted"/>
20 22
         <result column="AGENCY_ID" property="agencyId"/>
@@ -35,6 +37,8 @@
35 37
         SELECT TU.UNIT_ID,
36 38
                TU.DTU_NO,
37 39
                TU.PUSER_CODE,
40
+               TU.USER_CODE,
41
+               TU.POSITIONS,
38 42
                TU.UPDATESTAMP UNIT_UPDATE_STAMP,
39 43
                TAG.AGENCY_ID,
40 44
                TAG.AGENCY_PATH,

+ 6 - 0
elastic-publish-service/src/main/resources/mapper/UnitMapper.xml 파일 보기

@@ -6,6 +6,8 @@
6 6
         <result column="UNIT_ID" property="unitId"/>
7 7
         <result column="DTU_NO" property="dtuNo"/>
8 8
         <result column="PUSER_CODE" property="puserCode"/>
9
+        <result column="USER_CODE" property="userCode"/>
10
+        <result column="POSITIONS" property="positions"/>
9 11
         <result column="UNIT_UPDATE_STAMP" property="unitUpdateStamp" javaType="java.util.Date"/>
10 12
         <result column="ISDELETED" property="isDeleted"/>
11 13
         <result column="AGENCY_ID" property="agencyId"/>
@@ -32,6 +34,8 @@
32 34
         SELECT TU.UNIT_ID,
33 35
                TU.DTU_NO,
34 36
                TU.PUSER_CODE,
37
+               TU.USER_CODE,
38
+               TU.POSITIONS,
35 39
                TU.UPDATESTAMP UNIT_UPDATE_STAMP,
36 40
                TU.ISDELETED,
37 41
                TAG.AGENCY_ID,
@@ -59,6 +63,8 @@
59 63
         SELECT TU.UNIT_ID,
60 64
                TU.DTU_NO,
61 65
                TU.PUSER_CODE,
66
+               TU.USER_CODE,
67
+               TU.POSITIONS,
62 68
                TU.UPDATESTAMP UNIT_UPDATE_STAMP,
63 69
                TAG.AGENCY_ID,
64 70
                TAG.AGENCY_PATH,