瀏覽代碼

add miss key field

kerry 5 年之前
父節點
當前提交
e6a2547f30

+ 12 - 1
elastic-publish-service/index-text/unit-agency.mapping.json 查看文件

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
       "type": "text",
59
       "type": "text",
49
       "analyzer": "case_sensitive",
60
       "analyzer": "case_sensitive",
50
       "search_analyzer": "case_sensitive",
61
       "search_analyzer": "case_sensitive",

+ 7 - 2
elastic-publish-service/req/main-controller.http 查看文件

21
 
21
 
22
 {
22
 {
23
   "agencyPath": "/1",
23
   "agencyPath": "/1",
24
-  "keyword": "卡拉ok",
24
+  "keyword": "b楼",
25
   "page": 1,
25
   "page": 1,
26
   "size": 10,
26
   "size": 10,
27
   "regulatoryLevelId": "",
27
   "regulatoryLevelId": "",
31
   "unitTypeId": ""
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
 package com.vcarecity.publish.aop;
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
 import org.aspectj.lang.ProceedingJoinPoint;
6
 import org.aspectj.lang.ProceedingJoinPoint;
4
 import org.aspectj.lang.annotation.Around;
7
 import org.aspectj.lang.annotation.Around;
8
+import org.aspectj.lang.annotation.Aspect;
5
 import org.aspectj.lang.annotation.Pointcut;
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
  * @author VcKerry on 12/20/19
16
  * @author VcKerry on 12/20/19
9
  */
17
  */
10
 
18
 
11
-//@Aspect
12
-//@Component
19
+@Aspect
20
+@Component
13
 public class PrepareAopController {
21
 public class PrepareAopController {
14
 
22
 
15
 
23
 
21
 
29
 
22
     @Around("preparePointcut()")
30
     @Around("preparePointcut()")
23
     public Object check(ProceedingJoinPoint pjp) throws Throwable {
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
     public static final DateTimeFormatter ES_DT_FORMATTER = DateTimeFormatter.ofPattern(ES_DATETIME_PATTERN);
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
     public MainController(UnitService unitService,
35
     public MainController(UnitService unitService,
36
                           ElasticLoadDataService elasticLoadDataService,
36
                           ElasticLoadDataService elasticLoadDataService,
37
                           LoadDataStatusService loadDataStatusService,
37
                           LoadDataStatusService loadDataStatusService,
38
-                          @Value("${app.scheduling.enable}") Boolean schedulingEnable) {
38
+                          @Value("${app.index.reload}") Boolean reloadData) {
39
         this.unitService = unitService;
39
         this.unitService = unitService;
40
         this.elasticLoadDataService = elasticLoadDataService;
40
         this.elasticLoadDataService = elasticLoadDataService;
41
         this.loadDataStatusService = loadDataStatusService;
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
     @ResponseBody
50
     @ResponseBody
49
     @RequestMapping(value = "/load", method = {RequestMethod.GET, RequestMethod.POST})
51
     @RequestMapping(value = "/load", method = {RequestMethod.GET, RequestMethod.POST})
50
     public ApiResult loadData() {
52
     public ApiResult loadData() {
51
         synchronized (this) {
53
         synchronized (this) {
52
-            if (loadDataStatusService.getStatus() == ElasticConstant.DATA_STATUS_NOT_LOAD) {
54
+            if (loadDataStatusService.getStatus() == LoadDataStatusService.DATA_STATUS_NOT_LOAD) {
53
                 logger.info("prepare to load data into elasticsearch");
55
                 logger.info("prepare to load data into elasticsearch");
54
-                loadDataStatusService.setStatus(ElasticConstant.DATA_STATUS_LOADING);
56
+                loadDataStatusService.setStatus(LoadDataStatusService.DATA_STATUS_LOADING);
55
                 new Thread(() -> {
57
                 new Thread(() -> {
56
                     try {
58
                     try {
57
                         elasticLoadDataService.loadData();
59
                         elasticLoadDataService.loadData();
58
-                        loadDataStatusService.setStatus(ElasticConstant.DATA_STATUS_LOADED);
60
+                        loadDataStatusService.setStatus(LoadDataStatusService.DATA_STATUS_LOADED);
59
                     } catch (IOException e) {
61
                     } catch (IOException e) {
60
                         e.printStackTrace();
62
                         e.printStackTrace();
61
-                        loadDataStatusService.setStatus(ElasticConstant.DATA_STATUS_NOT_LOAD);
63
+                        loadDataStatusService.setStatus(LoadDataStatusService.DATA_STATUS_NOT_LOAD);
62
                     }
64
                     }
63
                 }).start();
65
                 }).start();
64
                 return ApiResult.builder().status(40000).message("first load data into elasticsearch").build();
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
                 return ApiResult.builder().status(40000).message("loading data into elasticsearch").build();
68
                 return ApiResult.builder().status(40000).message("loading data into elasticsearch").build();
67
             }
69
             }
68
         }
70
         }
95
 
97
 
96
     @SkipMethod
98
     @SkipMethod
97
     @Override
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
      * @return
15
      * @return
16
      */
16
      */
17
     @SkipMethod
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
 
19
 
20
     private String puserCode;
20
     private String puserCode;
21
 
21
 
22
+    private String userCode;
23
+
24
+    private String positions;
25
+
22
     @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = ElasticConstant.ES_DATETIME_PATTERN, timezone = "GMT+8")
26
     @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = ElasticConstant.ES_DATETIME_PATTERN, timezone = "GMT+8")
23
     private Date unitUpdateStamp;
27
     private Date unitUpdateStamp;
24
 
28
 

+ 2 - 0
elastic-publish-service/src/main/java/com/vcarecity/publish/pojo/dto/UnitAgencyDTO.java 查看文件

13
 @Data
13
 @Data
14
 public class UnitAgencyDTO extends UnitIdDTO {
14
 public class UnitAgencyDTO extends UnitIdDTO {
15
     private String dtuNo;
15
     private String dtuNo;
16
+    private String userCode;
16
     private String agencyName;
17
     private String agencyName;
18
+    private String positions;
17
     private String nameOfBuilding;
19
     private String nameOfBuilding;
18
     private String unitType;
20
     private String unitType;
19
     private String unitUpdateStamp;
21
     private String unitUpdateStamp;

+ 3 - 2
elastic-publish-service/src/main/java/com/vcarecity/publish/sql/service/impl/UnitServiceImpl.java 查看文件

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

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

26
 app:
26
 app:
27
   index:
27
   index:
28
     config: index-text
28
     config: index-text
29
+    reload: true
29
   scheduling:
30
   scheduling:
30
     enable: true
31
     enable: true

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

27
 app:
27
 app:
28
   index:
28
   index:
29
     config: index-text
29
     config: index-text
30
+    reload: true
30
   scheduling:
31
   scheduling:
31
     enable: false
32
     enable: false

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

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

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

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