Browse Source

ADD req fields

kerry 5 years ago
parent
commit
f857b353f2

+ 127 - 0
elastic-publish-service/action.sh View File

1
+#!/bin/sh
2
+
3
+# PS some OS location: /usr/sbin/cronolog OR /usr/local/sbin/cronolog OR /usr/bin/cronolog(ubuntu)
4
+CRONOLOG_PATH=/usr/local/sbin/cronolog
5
+if [ ! -f "$CRONOLOG_PATH" ]; then
6
+    CRONOLOG_PATH=/usr/sbin/cronolog
7
+    if [ ! -f "$CRONOLOG_PATH" ]; then
8
+        CRONOLOG_PATH=/usr/bin/cronolog
9
+    fi;
10
+fi;
11
+
12
+# 当前脚本所在目录
13
+SERVER=$(cd `dirname $0`; pwd)
14
+cd $SERVER
15
+
16
+# 文件全路径
17
+FULL_PATH=$SERVER/elastic-publish-service-1.0.0.jar
18
+# 程序的名字,不包括版本号,一般JAR包文件名为: $APP_SIGNATURE-1.0.0.jar ,备份用.
19
+APP_SIGNATURE=elastic-publish-service
20
+# 运行参数,如: -Xmx800m
21
+RUN_PARAM=
22
+
23
+# 组合命令,如果是Java,运行其他程序,改这里,如其他运行: ./frpc -c frpc.ini
24
+RUN_COMMAND="java -jar $FULL_PATH"
25
+
26
+# 运行程序的PID文件名
27
+PID_FILE_NAME=.pid
28
+# 程序运行日志文件
29
+APP_LOG_FILE=application.log
30
+
31
+# 检查文件是否存在,
32
+if [ ! -f "$FULL_PATH" ];then
33
+    echo "file = [$FULL_PATH] not found..."
34
+    exit 0
35
+fi
36
+
37
+NOHUP_PREFIX=logs/nohup_
38
+
39
+res=""
40
+
41
+if [ $# -eq 0 ] ; then
42
+    echo "Usage: {start|stop|restart|fstop|np|nph|al|alh}"
43
+else
44
+    case "$1" in
45
+        start)
46
+                # kill 
47
+                res=`ps aux | grep "$SERVER/$APP_SIGNATURE" | grep -v "grep" | awk '{print $2}'`
48
+                if [ -n "$res" ];then
49
+                    kill -9 $(ps aux | grep "$SERVER/$APP_SIGNATURE" | grep -v "grep" | awk '{print $2}')
50
+                    sleep 1
51
+                fi
52
+                nohup $RUN_COMMAND $RUN_PARAM 2>&1 | $CRONOLOG_PATH ./$NOHUP_PREFIX%Y%m%d.log &
53
+                echo $[$!-1] > $SERVER/$PID_FILE_NAME
54
+                ;;
55
+
56
+        stop)
57
+            kill  `cat $SERVER/$PID_FILE_NAME`
58
+            rm -rf $SERVER/$PID_FILE_NAME
59
+            ;;
60
+
61
+        restart)
62
+            kill  `cat $SERVER/$PID_FILE_NAME`
63
+            rm -rf $SERVER/$PID_FILE_NAME
64
+            sleep 1
65
+            nohup $RUN_COMMAND $RUN_PARAM 2>&1 | $CRONOLOG_PATH ./$NOHUP_PREFIX%Y%m%d.log &
66
+            echo $[$!-1] > $SERVER/$PID_FILE_NAME
67
+            ;;
68
+
69
+        fstop)
70
+            kill -9 `cat $SERVER/$PID_FILE_NAME`
71
+            rm -rf $SERVER/$PID_FILE_NAME
72
+            ;;
73
+
74
+        np)
75
+            # echo $2
76
+            DATE=$(date +%Y%m%d)
77
+            tail -f  "./$NOHUP_PREFIX$DATE.log" | grep "$2"
78
+            ;;
79
+        nph)
80
+            # echo $2
81
+            DATE=$(date +%Y%m%d)
82
+            tail -f  "./$NOHUP_PREFIX$DATE.log" | perl -pe 's/('$2')/\e[1;31m$1\e[0m/g'
83
+            ;;
84
+        al)
85
+            tail -f  "./logs/$APP_LOG_FILE" | grep "$2"
86
+            ;;
87
+        alh)
88
+            tail -f  "./logs/$APP_LOG_FILE" | perl -pe 's/('$2')/\e[1;31m$1\e[0m/g'
89
+            ;;
90
+        backup)
91
+            BACKUP_DATE=$(date +%Y%m%d%H%M)
92
+            BACKUP_FOLDER=$SERVER/backup
93
+            if [ ! -d "$BACKUP_FOLDER" ];then
94
+                mkdir $BACKUP_FOLDER
95
+            fi
96
+            CU_BACK_UP=$BACKUP_FOLDER/$BACKUP_DATE
97
+            if [ ! -d "$CU_BACK_UP" ];then
98
+                mkdir $CU_BACK_UP
99
+            fi
100
+            cp $SERVER/$APP_SIGNATURE*.jar $CU_BACK_UP/
101
+            cp -R $SERVER/lib $CU_BACK_UP/
102
+            cp -R $SERVER/config $CU_BACK_UP/
103
+            ;;
104
+        rollback)
105
+            if [ $# -eq 2 ] ; then
106
+                ROLLBACK_FOLDER=$SERVER/backup/$2
107
+                echo "rollback version:"$ROLLBACK_FOLDER
108
+                if [ ! -d "$ROLLBACK_FOLDER" ];then
109
+                    echo "rollback version not found in file system. "$ROLLBACK_FOLDER
110
+                    exit 0
111
+                fi
112
+                rm -rf $SERVER/$APP_SIGNATURE*.jar
113
+                rm -rf $SERVER/lib
114
+                rm -rf $SERVER/config
115
+                cp $ROLLBACK_FOLDER/$APP_SIGNATURE*.jar $SERVER
116
+                cp -R $ROLLBACK_FOLDER/lib $SERVER/lib
117
+                cp -R $ROLLBACK_FOLDER/config $SERVER/config
118
+            else
119
+                echo "not input rollback version"
120
+            fi;
121
+            ;;
122
+        *)
123
+            echo "Usage: {start|stop|restart|fstop|np|nph}"
124
+            ;;
125
+        esac
126
+fi;
127
+exit 0

+ 63 - 0
elastic-publish-service/config/logback-my.xml View File

1
+<included>
2
+
3
+    <!--默认 Appender-->
4
+    <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
5
+        <encoder>
6
+            <pattern>${CONSOLE_LOG_PATTERN}</pattern>
7
+            <charset>utf8</charset>
8
+        </encoder>
9
+    </appender>
10
+
11
+    <!-- LOG TO FILE -->
12
+    <appender name="LOGFILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
13
+        <file>logs/application.log</file>
14
+        <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
15
+            <fileNamePattern>logs/application.%d{yyyyMMdd}_%i.log</fileNamePattern>
16
+            <maxHistory>30</maxHistory>
17
+            <totalSizeCap>20GB</totalSizeCap>
18
+            <maxFileSize>50MB</maxFileSize>
19
+        </rollingPolicy>
20
+        <encoder>
21
+            <pattern>${FILE_LOG_PATTERN}</pattern>
22
+        </encoder>
23
+    </appender>
24
+
25
+    <!-- profile -->
26
+    <springProfile name="dev">
27
+        <logger name="com.vcarecity" level="DEBUG" additivity="false">
28
+            <appender-ref ref="CONSOLE"/>
29
+        </logger>
30
+
31
+        <logger name="com.vcarecity.publish.mapper.AgencyMapper" level="INFO" additivity="false">
32
+            <appender-ref ref="CONSOLE"/>
33
+        </logger>
34
+
35
+    </springProfile>
36
+
37
+    <springProfile name="beta">
38
+        <logger name="com.vcarecity" level="DEBUG" additivity="false">
39
+            <appender-ref ref="LOGFILE"/>
40
+        </logger>
41
+
42
+        <logger name="com.vcarecity.publish.mapper.AgencyMapper" level="INFO" additivity="false">
43
+            <appender-ref ref="LOGFILE"/>
44
+        </logger>
45
+
46
+    </springProfile>
47
+
48
+
49
+    <springProfile name="production">
50
+        <logger name="com.vcarecity" level="DEBUG" additivity="false">
51
+            <appender-ref ref="LOGFILE"/>
52
+        </logger>
53
+
54
+        <logger name="com.vcarecity.publish.mapper.AgencyMapper" level="INFO" additivity="false">
55
+            <appender-ref ref="LOGFILE"/>
56
+        </logger>
57
+
58
+    </springProfile>
59
+
60
+    <root level="INFO">
61
+        <appender-ref ref="CONSOLE"/>
62
+    </root>
63
+</included>

+ 6 - 0
elastic-publish-service/req/http-client.env.json View File

1
 {
1
 {
2
   "dev": {
2
   "dev": {
3
     "host": "http://192.168.10.179:7080"
3
     "host": "http://192.168.10.179:7080"
4
+  },
5
+  "beta": {
6
+    "host": "http://192.168.10.100:8092"
7
+  },
8
+  "beta-out": {
9
+    "host": "http://103.239.204.35:8092"
4
   }
10
   }
5
 }
11
 }

+ 3 - 0
elastic-publish-service/req/load.http View File

1
+GET http://{{host}}/load
2
+
3
+### load data

+ 4 - 2
elastic-publish-service/req/main-controller.http View File

9
   "regulatoryLevelId": "",
9
   "regulatoryLevelId": "",
10
   "property": "",
10
   "property": "",
11
   "classify": "",
11
   "classify": "",
12
-  "agencyAttributeClassId": ""
12
+  "agencyAttributeClassId": "",
13
+  "unitTypeId": ""
13
 }
14
 }
14
 
15
 
15
 ### unitId 信息
16
 ### unitId 信息
26
   "regulatoryLevelId": "",
27
   "regulatoryLevelId": "",
27
   "property": "",
28
   "property": "",
28
   "classify": "",
29
   "classify": "",
29
-  "agencyAttributeClassId": ""
30
+  "agencyAttributeClassId": "",
31
+  "unitTypeId": ""
30
 }
32
 }
31
 
33
 
32
 ### 详情信息
34
 ### 详情信息

+ 3 - 18
elastic-publish-service/src/main/java/com/vcarecity/publish/aop/PrepareAopController.java View File

1
 package com.vcarecity.publish.aop;
1
 package com.vcarecity.publish.aop;
2
 
2
 
3
-import com.vcarecity.publish.api.ApiResult;
4
-import com.vcarecity.publish.controller.PrepareController;
5
 import org.aspectj.lang.ProceedingJoinPoint;
3
 import org.aspectj.lang.ProceedingJoinPoint;
6
 import org.aspectj.lang.annotation.Around;
4
 import org.aspectj.lang.annotation.Around;
7
-import org.aspectj.lang.annotation.Aspect;
8
 import org.aspectj.lang.annotation.Pointcut;
5
 import org.aspectj.lang.annotation.Pointcut;
9
-import org.springframework.stereotype.Component;
10
 
6
 
11
 /**
7
 /**
12
  * @author VcKerry on 12/20/19
8
  * @author VcKerry on 12/20/19
13
  */
9
  */
14
 
10
 
15
-@Aspect
16
-@Component
11
+//@Aspect
12
+//@Component
17
 public class PrepareAopController {
13
 public class PrepareAopController {
18
 
14
 
19
 
15
 
25
 
21
 
26
     @Around("preparePointcut()")
22
     @Around("preparePointcut()")
27
     public Object check(ProceedingJoinPoint pjp) throws Throwable {
23
     public Object check(ProceedingJoinPoint pjp) throws Throwable {
28
-        Object target = pjp.getTarget();
29
-
30
-        if (target instanceof PrepareController) {
31
-
32
-            if (((PrepareController) target).isPrepare()) {
33
-                return pjp.proceed();
34
-            }
35
-            // 数据没有准备好...
36
-            return ApiResult.builder().status(40000).message("data loading ").build();
37
-        }
38
-
39
-        return pjp.proceed();
24
+        return pjp.getTarget();
40
     }
25
     }
41
 
26
 
42
 }
27
 }

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

1
 package com.vcarecity.publish.constants;
1
 package com.vcarecity.publish.constants;
2
 
2
 
3
-import java.time.ZoneId;
4
 import java.time.format.DateTimeFormatter;
3
 import java.time.format.DateTimeFormatter;
5
 
4
 
6
 /**
5
 /**
23
     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);
24
 
23
 
25
 
24
 
26
-    public static final String SYSTEM_TIMEZONE = ZoneId.systemDefault().getId();
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
+
27
 }
39
 }

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

9
 import com.vcarecity.publish.pojo.dto.UnitIdDTO;
9
 import com.vcarecity.publish.pojo.dto.UnitIdDTO;
10
 import com.vcarecity.publish.pojo.query.UnitAgencyQuery;
10
 import com.vcarecity.publish.pojo.query.UnitAgencyQuery;
11
 import com.vcarecity.publish.sql.service.UnitService;
11
 import com.vcarecity.publish.sql.service.UnitService;
12
+import lombok.extern.slf4j.Slf4j;
13
+import org.springframework.beans.factory.annotation.Value;
12
 import org.springframework.web.bind.annotation.*;
14
 import org.springframework.web.bind.annotation.*;
13
 
15
 
14
 import javax.validation.Valid;
16
 import javax.validation.Valid;
15
 import java.io.IOException;
17
 import java.io.IOException;
16
 import java.util.List;
18
 import java.util.List;
19
+import java.util.concurrent.atomic.AtomicInteger;
17
 
20
 
18
 /**
21
 /**
19
  * @author Kerry on 19/12/11
22
  * @author Kerry on 19/12/11
20
  */
23
  */
21
 
24
 
25
+@Slf4j
22
 @RestController
26
 @RestController
23
 public class MainController implements PrepareController {
27
 public class MainController implements PrepareController {
24
 
28
 
25
-    private int status = -1;
29
+    private AtomicInteger dataStatus;
26
 
30
 
27
     private final UnitService unitService;
31
     private final UnitService unitService;
28
     private final ElasticLoadDataService elasticLoadDataService;
32
     private final ElasticLoadDataService elasticLoadDataService;
29
 
33
 
30
-    public MainController(UnitService unitService, ElasticLoadDataService elasticLoadDataService) {
34
+    public MainController(UnitService unitService,
35
+                          ElasticLoadDataService elasticLoadDataService,
36
+                          @Value("${app.scheduling.enable}") Boolean schedulingEnable) {
31
         this.unitService = unitService;
37
         this.unitService = unitService;
32
         this.elasticLoadDataService = elasticLoadDataService;
38
         this.elasticLoadDataService = elasticLoadDataService;
39
+
40
+        if (schedulingEnable) {
41
+            dataStatus = new AtomicInteger(ElasticConstant.DATA_STATUS_LOADED);
42
+        } else {
43
+            dataStatus = new AtomicInteger(ElasticConstant.DATA_STATUS_NOT_LOAD);
44
+        }
33
     }
45
     }
34
 
46
 
35
 
47
 
48
+    @ResponseBody
36
     @RequestMapping(value = "/load", method = {RequestMethod.GET, RequestMethod.POST})
49
     @RequestMapping(value = "/load", method = {RequestMethod.GET, RequestMethod.POST})
37
     public ApiResult loadData() {
50
     public ApiResult loadData() {
38
-        if (status == -1) {
39
-            status = 0;
40
-            synchronized (this) {
51
+        synchronized (this) {
52
+            if (dataStatus.get() == ElasticConstant.DATA_STATUS_NOT_LOAD) {
53
+                logger.info("prepare to load data into elasticsearch");
54
+                dataStatus.set(ElasticConstant.DATA_STATUS_LOADING);
41
                 new Thread(() -> {
55
                 new Thread(() -> {
42
                     try {
56
                     try {
43
                         elasticLoadDataService.loadData();
57
                         elasticLoadDataService.loadData();
44
-                        status = 1;
58
+                        dataStatus.set(ElasticConstant.DATA_STATUS_LOADED);
45
                     } catch (IOException e) {
59
                     } catch (IOException e) {
46
                         e.printStackTrace();
60
                         e.printStackTrace();
47
-                        status = -1;
61
+                        dataStatus.set(ElasticConstant.DATA_STATUS_NOT_LOAD);
48
                     }
62
                     }
49
                 }).start();
63
                 }).start();
64
+                return ApiResult.builder().status(40000).message("first load data into elasticsearch").build();
65
+            } else if (dataStatus.get() == ElasticConstant.DATA_STATUS_LOADING) {
66
+                return ApiResult.builder().status(40000).message("loading data into elasticsearch").build();
50
             }
67
             }
51
         }
68
         }
52
-        return ApiResult.builder().status(40000).message("loading data").build();
69
+        return ApiResult.builder().status(40000).message("already load data success!").build();
53
     }
70
     }
54
 
71
 
55
 
72
 
67
         return ApiResult.builder().status(ApiStatus.SUCCESS_CODE).data(data).build();
84
         return ApiResult.builder().status(ApiStatus.SUCCESS_CODE).data(data).build();
68
     }
85
     }
69
 
86
 
87
+
70
     @SkipMethod
88
     @SkipMethod
71
     @Override
89
     @Override
72
-    public boolean isPrepare() {
73
-        return false;
90
+    public int getDataStatus() {
91
+        return dataStatus.get();
74
     }
92
     }
75
 }
93
 }

+ 1 - 1
elastic-publish-service/src/main/java/com/vcarecity/publish/controller/PrepareController.java View File

15
      * @return
15
      * @return
16
      */
16
      */
17
     @SkipMethod
17
     @SkipMethod
18
-    boolean isPrepare();
18
+    int getDataStatus();
19
 
19
 
20
 }
20
 }

+ 1 - 0
elastic-publish-service/src/main/java/com/vcarecity/publish/pojo/query/UnitAgencyQuery.java View File

27
     private String classify;
27
     private String classify;
28
     private String regulatoryLevelId;
28
     private String regulatoryLevelId;
29
     private String agencyAttributeClassId;
29
     private String agencyAttributeClassId;
30
+    private String unitTypeId;
30
 
31
 
31
 }
32
 }

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

47
     static final String[] MATCH_KEY_NAMES = new String[]{
47
     static final String[] MATCH_KEY_NAMES = new String[]{
48
             "agencyAttributeClassId",
48
             "agencyAttributeClassId",
49
             "regulatoryLevelId",
49
             "regulatoryLevelId",
50
+            "unitTypeId",
50
             "property",
51
             "property",
51
             "classify"
52
             "classify"
52
     };
53
     };

+ 3 - 3
elastic-publish-service/src/main/resources/application-beta.yml View File

1
 server:
1
 server:
2
-  port: 7080
2
+  port: 8092
3
 spring:
3
 spring:
4
   datasource:
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
     username: root
6
     username: root
7
     password: R00T@mysql
7
     password: R00T@mysql
8
   elasticsearch:
8
   elasticsearch:
14
       password: abcd!234
14
       password: abcd!234
15
   redis:
15
   redis:
16
     database: 2
16
     database: 2
17
-    host: 192.168.10.112
17
+    host: 192.168.10.240
18
     port: 6379
18
     port: 6379
19
     password: admin~1(^-^)
19
     password: admin~1(^-^)
20
 mybatis:
20
 mybatis:

+ 1 - 1
elastic-publish-service/src/main/resources/application-dev.yml View File

26
 debug: true
26
 debug: true
27
 app:
27
 app:
28
   scheduling:
28
   scheduling:
29
-    enable: true
29
+    enable: false

+ 1 - 27
elastic-publish-service/src/main/resources/logback-spring.xml View File

3
 
3
 
4
     <!--spring-boot-2.0.3.RELEASE.jar!/org/springframework/boot/logging/logback/defaults.xml-->
4
     <!--spring-boot-2.0.3.RELEASE.jar!/org/springframework/boot/logging/logback/defaults.xml-->
5
     <include resource="org/springframework/boot/logging/logback/defaults.xml"/>
5
     <include resource="org/springframework/boot/logging/logback/defaults.xml"/>
6
+    <include file="config/logback-my.xml"/>
6
 
7
 
7
 
8
 
8
-    <!--默认 Appender-->
9
-    <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
10
-        <encoder>
11
-            <pattern>${CONSOLE_LOG_PATTERN}</pattern>
12
-            <charset>utf8</charset>
13
-        </encoder>
14
-    </appender>
15
-
16
-
17
-    <root level="INFO">
18
-        <appender-ref ref="CONSOLE"/>
19
-    </root>
20
-
21
-
22
-    <springProfile name="dev">
23
-
24
-        <logger name="com.vcarecity" level="DEBUG" additivity="false">
25
-            <appender-ref ref="CONSOLE"/>
26
-        </logger>
27
-
28
-        <logger name="com.vcarecity.publish.mapper.AgencyMapper" level="INFO" additivity="false">
29
-            <appender-ref ref="CONSOLE"/>
30
-        </logger>
31
-
32
-
33
-    </springProfile>
34
-
35
 
9
 
36
     <springProfile name="beta">
10
     <springProfile name="beta">
37
 
11