Commit 3ccfbaea904de643b57cfef2faf550f2673ade75
1 parent
1618a472
Exists in
master
module heartbeat
Showing
39 changed files
with
2820 additions
and
264 deletions
Show diff stats
build.gradle
@@ -35,21 +35,15 @@ dependencies { | @@ -35,21 +35,15 @@ dependencies { | ||
35 | "org.springframework.boot:spring-boot-starter-data-jpa", | 35 | "org.springframework.boot:spring-boot-starter-data-jpa", |
36 | "org.springframework.boot:spring-boot-starter-mail", | 36 | "org.springframework.boot:spring-boot-starter-mail", |
37 | 37 | ||
38 | - "mysql:mysql-connector-java", | ||
39 | - | ||
40 | - "com.hankcs:hanlp:portable-1.7.5", | ||
41 | - | ||
42 | - "com.aliyun.oss:aliyun-sdk-oss:2.0.7", | ||
43 | "com.alibaba:fastjson:1.2.72", | 38 | "com.alibaba:fastjson:1.2.72", |
44 | - "com.alibaba:druid-spring-boot-starter:1.1.10", | 39 | + "mysql:mysql-connector-java:8.0.11", |
45 | 40 | ||
46 | - "com.xuxueli:xxl-job-core:2.1.0", | ||
47 | - "com.taover:com-taover-repository:2.1.22", | 41 | + "com.taover:com-taover-repository-starter:2.3.8", |
48 | "com.taover:com-taover-easyexcel:2.2.16", | 42 | "com.taover:com-taover-easyexcel:2.2.16", |
49 | - "com.taover:com-taover-util:1.1.112", | 43 | + "com.taover:com-taover-util:1.2.2", |
44 | + "com.taover:com-taover-codegenerate:1.2.28", | ||
50 | "cn.hutool:hutool-all:5.2.4", | 45 | "cn.hutool:hutool-all:5.2.4", |
51 | - "com.taover:com-taover-codegenerate:1.2.11", | ||
52 | "com.auth0:java-jwt:3.4.0", | 46 | "com.auth0:java-jwt:3.4.0", |
53 | - "io.jsonwebtoken:jjwt:0.6.0" | 47 | + "io.jsonwebtoken:jjwt:0.6.0" |
54 | ) | 48 | ) |
55 | } | 49 | } |
@@ -0,0 +1,91 @@ | @@ -0,0 +1,91 @@ | ||
1 | +#!/bin/bash | ||
2 | + | ||
3 | +. ~/.bash_profile | ||
4 | + | ||
5 | +#出现异常则退出 | ||
6 | +set -e | ||
7 | + | ||
8 | +#获取输入的GIT_BRANCH | ||
9 | +GIT_BRANCH="$1" | ||
10 | + | ||
11 | +#验证GIT_BRANCH | ||
12 | +if [ ! ${GIT_BRANCH} ]; then | ||
13 | + echo "fail: please input git branch name" | ||
14 | + exit 2 | ||
15 | +fi | ||
16 | + | ||
17 | +#获取输入的commit id | ||
18 | +ROLLBACK_COMMIT_ID="$2" | ||
19 | + | ||
20 | +#验证commitID | ||
21 | +if [ ! ${ROLLBACK_COMMIT_ID} ]; then | ||
22 | + echo "fail: please input commit id" | ||
23 | + exit 2 | ||
24 | +fi | ||
25 | + | ||
26 | +#定义常量 | ||
27 | +GIT_URL=git@gitlab.taover.com:taov-erp/8zyun-data-analysis.git | ||
28 | +GIT_PROJECT_NAME=8zyun-data-analysis | ||
29 | +MAIN_DIR=$(cd `dirname $0`; pwd) | ||
30 | +WEBAPP_DIR_NAME=webapp | ||
31 | +WEBAPP_BAK_DIR_NAME=webapp-bak | ||
32 | +LOG_DIR_NAME=log | ||
33 | + | ||
34 | +cd ${MAIN_DIR} | ||
35 | + | ||
36 | +#克隆项目 | ||
37 | +if [ ! -d "${MAIN_DIR}/${GIT_PROJECT_NAME}" ]; then | ||
38 | + cd ${MAIN_DIR} | ||
39 | + git clone ${GIT_URL} | ||
40 | + echo "git clone success" | ||
41 | +fi | ||
42 | + | ||
43 | +#创建基础目录 | ||
44 | +if [ ! -d "${MAIN_DIR}/${WEBAPP_DIR_NAME}" ]; then | ||
45 | + mkdir ${MAIN_DIR}/${WEBAPP_DIR_NAME} | ||
46 | + echo "mkdir webapp success" | ||
47 | +fi | ||
48 | +if [ ! -d "${MAIN_DIR}/${WEBAPP_BAK_DIR_NAME}" ]; then | ||
49 | + mkdir ${MAIN_DIR}/${WEBAPP_BAK_DIR_NAME} | ||
50 | + echo "mkdir webapp bak success" | ||
51 | +fi | ||
52 | +if [ ! -d "${MAIN_DIR}/${LOG_DIR_NAME}" ]; then | ||
53 | + mkdir ${MAIN_DIR}/${LOG_DIR_NAME} | ||
54 | + echo "mkdir log success" | ||
55 | +fi | ||
56 | + | ||
57 | +#备份上一JAR | ||
58 | +#cp -rf ${MAIN_DIR}/${WEBAPP_DIR_NAME}/ ${MAIN_DIR}/${WEBAPP_BAK_DIR_NAME}/ | ||
59 | +#echo "bak webapp dir success" | ||
60 | + | ||
61 | +#备份日志文件 | ||
62 | +bakLogFilePreffix=`date '+%Y%m%d_%H%M'` | ||
63 | +if [ -f ${MAIN_DIR}/${LOG_DIR_NAME}/log_std.out ]; then | ||
64 | + cp -f ${MAIN_DIR}/${LOG_DIR_NAME}/log_std.out ${MAIN_DIR}/${LOG_DIR_NAME}/${bakLogFilePreffix}_log_std.out | ||
65 | +fi | ||
66 | +if [ -f ${MAIN_DIR}/${LOG_DIR_NAME}/log_error.out ]; then | ||
67 | + cp -f ${MAIN_DIR}/${LOG_DIR_NAME}/log_error.out ${MAIN_DIR}/${LOG_DIR_NAME}/${bakLogFilePreffix}_log_error.out | ||
68 | +fi | ||
69 | + | ||
70 | +#拉取线上production代码并编译发布 | ||
71 | +cd ${MAIN_DIR}/${GIT_PROJECT_NAME}/ | ||
72 | +git checkout ${GIT_BRANCH} | ||
73 | +git reset --hard ${ROLLBACK_COMMIT_ID} | ||
74 | +gradle build | ||
75 | +echo "pull ${GIT_BRANCH} ${ROLLBACK_COMMIT_ID} and build success" | ||
76 | + | ||
77 | +#终止线程并移除文件 | ||
78 | +pid=`ps -ef | grep "$GIT_PROJECT_NAME".jar | grep -v grep | awk '{print $2}'` | ||
79 | +if [ -n "$pid" ] | ||
80 | +then | ||
81 | + kill $pid | ||
82 | +fi | ||
83 | +rm -rf ${MAIN_DIR}/${WEBAPP_DIR_NAME}/* | ||
84 | +echo "end process and rm success" | ||
85 | + | ||
86 | +#移动TAR文件、解压、启动 | ||
87 | +cd ${MAIN_DIR}/${WEBAPP_DIR_NAME}/ | ||
88 | +mv ${MAIN_DIR}/${GIT_PROJECT_NAME}/build/distributions/${GIT_PROJECT_NAME}-boot.tar ${MAIN_DIR}/${WEBAPP_DIR_NAME}/ | ||
89 | +tar -xvf ${GIT_PROJECT_NAME}-boot.tar | ||
90 | +nohup java -Xmx8192m -jar ${GIT_PROJECT_NAME}-boot/lib/${GIT_PROJECT_NAME}.jar --spring.profiles.active=production 2>${MAIN_DIR}/${LOG_DIR_NAME}/log_error.out 1>${MAIN_DIR}/${LOG_DIR_NAME}/log_std.out & | ||
91 | +echo "start up success" | ||
0 | \ No newline at end of file | 92 | \ No newline at end of file |
@@ -0,0 +1,86 @@ | @@ -0,0 +1,86 @@ | ||
1 | +#!/bin/bash | ||
2 | + | ||
3 | +. ~/.bash_profile | ||
4 | + | ||
5 | +#出现异常则退出 | ||
6 | +set -e | ||
7 | + | ||
8 | +#获取输入的GIT_BRANCH | ||
9 | +GIT_BRANCH="$1" | ||
10 | + | ||
11 | +#验证GIT_BRANCH | ||
12 | +if [ ! ${GIT_BRANCH} ]; then | ||
13 | + echo "fail: please input git branch name" | ||
14 | + exit 2 | ||
15 | +fi | ||
16 | + | ||
17 | +#定义常量 | ||
18 | +GIT_URL=git@gitlab.taover.com:taov-erp/8zyun-data-analysis.git | ||
19 | +GIT_PROJECT_NAME=8zyun-data-analysis | ||
20 | +MAIN_DIR=$(cd `dirname $0`; pwd) | ||
21 | +WEBAPP_DIR_NAME=webapp | ||
22 | +WEBAPP_BAK_DIR_NAME=webapp-bak | ||
23 | +LOG_DIR_NAME=log | ||
24 | + | ||
25 | +cd ${MAIN_DIR} | ||
26 | + | ||
27 | +#克隆项目 | ||
28 | +if [ ! -d "${MAIN_DIR}/${GIT_PROJECT_NAME}" ]; then | ||
29 | + cd ${MAIN_DIR} | ||
30 | + git clone ${GIT_URL} | ||
31 | + echo "git clone success" | ||
32 | +fi | ||
33 | + | ||
34 | +#创建基础目录 | ||
35 | +if [ ! -d "${MAIN_DIR}/${WEBAPP_DIR_NAME}" ]; then | ||
36 | + mkdir ${MAIN_DIR}/${WEBAPP_DIR_NAME} | ||
37 | + echo "mkdir webapp success" | ||
38 | +fi | ||
39 | +if [ ! -d "${MAIN_DIR}/${WEBAPP_BAK_DIR_NAME}" ]; then | ||
40 | + mkdir ${MAIN_DIR}/${WEBAPP_BAK_DIR_NAME} | ||
41 | + echo "mkdir webapp bak success" | ||
42 | +fi | ||
43 | +if [ ! -d "${MAIN_DIR}/${LOG_DIR_NAME}" ]; then | ||
44 | + mkdir ${MAIN_DIR}/${LOG_DIR_NAME} | ||
45 | + echo "mkdir log success" | ||
46 | +fi | ||
47 | + | ||
48 | +#备份上一JAR | ||
49 | +cp -rf ${MAIN_DIR}/${WEBAPP_DIR_NAME}/ ${MAIN_DIR}/${WEBAPP_BAK_DIR_NAME}/ | ||
50 | +echo "bak webapp dir success" | ||
51 | + | ||
52 | +#备份日志文件 | ||
53 | +bakLogFilePreffix=`date '+%Y%m%d_%H%M'` | ||
54 | +if [ -f ${MAIN_DIR}/${LOG_DIR_NAME}/log_std.out ]; then | ||
55 | + cp -f ${MAIN_DIR}/${LOG_DIR_NAME}/log_std.out ${MAIN_DIR}/${LOG_DIR_NAME}/${bakLogFilePreffix}_log_std.out | ||
56 | +fi | ||
57 | +if [ -f ${MAIN_DIR}/${LOG_DIR_NAME}/log_error.out ]; then | ||
58 | + cp -f ${MAIN_DIR}/${LOG_DIR_NAME}/log_error.out ${MAIN_DIR}/${LOG_DIR_NAME}/${bakLogFilePreffix}_log_error.out | ||
59 | +fi | ||
60 | + | ||
61 | +#拉取线上production代码并编译发布 | ||
62 | +tagNamePreffix=`date '+%Y%m%d'` | ||
63 | +cd ${MAIN_DIR}/${GIT_PROJECT_NAME}/ | ||
64 | +git checkout ${GIT_BRANCH} | ||
65 | +git pull origin ${GIT_BRANCH} | ||
66 | +headCommit=`git rev-parse HEAD` | ||
67 | +git tag -a v.${GIT_BRANCH}.${tagNamePreffix}.${headCommit} -m "COMMIT ID : ${headCommit}" || echo "git tag fail" | ||
68 | +git push origin v.${GIT_BRANCH}.${tagNamePreffix}.${headCommit} | ||
69 | +gradle build | ||
70 | +echo "pull ${GIT_BRANCH} and build success" | ||
71 | + | ||
72 | +#终止线程并移除文件 | ||
73 | +pid=`ps -ef | grep "$GIT_PROJECT_NAME".jar | grep -v grep | awk '{print $2}'` | ||
74 | +if [ -n "$pid" ] | ||
75 | +then | ||
76 | + kill $pid | ||
77 | +fi | ||
78 | +rm -rf ${MAIN_DIR}/${WEBAPP_DIR_NAME}/* | ||
79 | +echo "end process and rm success" | ||
80 | + | ||
81 | +#移动TAR文件、解压、启动 | ||
82 | +cd ${MAIN_DIR}/${WEBAPP_DIR_NAME}/ | ||
83 | +mv ${MAIN_DIR}/${GIT_PROJECT_NAME}/build/distributions/${GIT_PROJECT_NAME}-boot.tar ${MAIN_DIR}/${WEBAPP_DIR_NAME}/ | ||
84 | +tar -xvf ${GIT_PROJECT_NAME}-boot.tar | ||
85 | +nohup java -Xmx8192m -jar ${GIT_PROJECT_NAME}-boot/lib/${GIT_PROJECT_NAME}.jar --spring.profiles.active=${GIT_BRANCH} 2>${MAIN_DIR}/${LOG_DIR_NAME}/log_error.out 1>${MAIN_DIR}/${LOG_DIR_NAME}/log_std.out & | ||
86 | +echo "start up success" | ||
0 | \ No newline at end of file | 87 | \ No newline at end of file |
src/main/java/com/taover/bazhuayun/analysis/web/StartUp.java
@@ -3,9 +3,11 @@ package com.taover.bazhuayun.analysis.web; | @@ -3,9 +3,11 @@ package com.taover.bazhuayun.analysis.web; | ||
3 | import org.springframework.boot.SpringApplication; | 3 | import org.springframework.boot.SpringApplication; |
4 | import org.springframework.boot.autoconfigure.SpringBootApplication; | 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; |
5 | import org.springframework.context.annotation.EnableAspectJAutoProxy; | 5 | import org.springframework.context.annotation.EnableAspectJAutoProxy; |
6 | +import org.springframework.scheduling.annotation.EnableScheduling; | ||
6 | 7 | ||
7 | @SpringBootApplication | 8 | @SpringBootApplication |
8 | @EnableAspectJAutoProxy(exposeProxy=true, proxyTargetClass=true) | 9 | @EnableAspectJAutoProxy(exposeProxy=true, proxyTargetClass=true) |
10 | +@EnableScheduling | ||
9 | public class StartUp { | 11 | public class StartUp { |
10 | public static void main(String[] args) { | 12 | public static void main(String[] args) { |
11 | SpringApplication.run(StartUp.class, args); | 13 | SpringApplication.run(StartUp.class, args); |
src/main/java/com/taover/bazhuayun/analysis/web/controller/ExportCenterController.java
@@ -1,99 +0,0 @@ | @@ -1,99 +0,0 @@ | ||
1 | -package com.taover.bazhuayun.analysis.web.controller; | ||
2 | - | ||
3 | -import java.io.File; | ||
4 | -import java.io.FileInputStream; | ||
5 | -import java.io.IOException; | ||
6 | -import java.io.OutputStream; | ||
7 | -import java.text.ParseException; | ||
8 | -import java.text.SimpleDateFormat; | ||
9 | -import java.util.Date; | ||
10 | - | ||
11 | -import javax.annotation.Resource; | ||
12 | -import javax.servlet.http.HttpServletResponse; | ||
13 | - | ||
14 | -import org.apache.commons.lang.StringUtils; | ||
15 | -import org.springframework.web.bind.annotation.GetMapping; | ||
16 | -import org.springframework.web.bind.annotation.RequestMapping; | ||
17 | -import org.springframework.web.bind.annotation.RequestParam; | ||
18 | -import org.springframework.web.bind.annotation.RestController; | ||
19 | - | ||
20 | -import com.taover.bazhuayun.analysis.util.FileContentTypeUtils; | ||
21 | -import com.taover.bazhuayun.analysis.web.service.ExportCenterService; | ||
22 | -import com.taover.util.UtilLog; | ||
23 | - | ||
24 | -@RestController("exportcenter") | ||
25 | -@RequestMapping("/exportcenter") | ||
26 | -public class ExportCenterController { | ||
27 | - @Resource | ||
28 | - private ExportCenterService exportCenterService; | ||
29 | - | ||
30 | - @GetMapping("/wareorderfile") | ||
31 | - public void wareOrderFile(@RequestParam(name="tenantId", required=true) Integer tenantId, | ||
32 | - @RequestParam(name="startDate", defaultValue = "") String startDateStr, | ||
33 | - @RequestParam(name="endDate", defaultValue = "") String endDateStr, | ||
34 | - @RequestParam(name="wareCreateStartDate", defaultValue = "") String wareCreateStartDateStr, | ||
35 | - @RequestParam(name="wareCreateEndDate", defaultValue = "") String wareCreateEndDateStr, | ||
36 | - HttpServletResponse response) { | ||
37 | - Date startDate = new Date(); | ||
38 | - Date endDate = new Date(); | ||
39 | - Date wareCreateStartDate = null; | ||
40 | - Date wareCreateEndDate = null; | ||
41 | - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); | ||
42 | - if(StringUtils.isNotBlank(startDateStr)) { | ||
43 | - try { | ||
44 | - startDate = sdf.parse(startDateStr.substring(0, 10)); | ||
45 | - } catch (ParseException e) { | ||
46 | - e.printStackTrace(); | ||
47 | - } | ||
48 | - } | ||
49 | - if(StringUtils.isNotBlank(endDateStr)) { | ||
50 | - try { | ||
51 | - endDate = sdf.parse(endDateStr.substring(0, 10)); | ||
52 | - } catch (ParseException e) { | ||
53 | - e.printStackTrace(); | ||
54 | - } | ||
55 | - } | ||
56 | - if(StringUtils.isNotBlank(wareCreateStartDateStr)) { | ||
57 | - try { | ||
58 | - wareCreateStartDate = sdf.parse(wareCreateStartDateStr.substring(0, 10)); | ||
59 | - } catch (ParseException e) { | ||
60 | - e.printStackTrace(); | ||
61 | - } | ||
62 | - } | ||
63 | - if(StringUtils.isNotBlank(wareCreateEndDateStr)) { | ||
64 | - try { | ||
65 | - wareCreateEndDate = sdf.parse(wareCreateEndDateStr.substring(0, 10)); | ||
66 | - } catch (ParseException e) { | ||
67 | - e.printStackTrace(); | ||
68 | - } | ||
69 | - } | ||
70 | - | ||
71 | - File orderFile = null; | ||
72 | - try { | ||
73 | - orderFile = this.exportCenterService.wareOrderFile(tenantId, startDate, endDate, wareCreateStartDate, wareCreateEndDate); | ||
74 | - } catch (IOException e1) { | ||
75 | - UtilLog.errorForException(e1, this.getClass()); | ||
76 | - return; | ||
77 | - } | ||
78 | - try { | ||
79 | - this.writeFielToResponse(response, orderFile); | ||
80 | - } catch (IOException e) { | ||
81 | - UtilLog.errorForException(e, this.getClass()); | ||
82 | - } | ||
83 | - } | ||
84 | - | ||
85 | - private void writeFielToResponse(HttpServletResponse response, File file) throws IOException { | ||
86 | - OutputStream stream = response.getOutputStream(); | ||
87 | - FileInputStream reader = new FileInputStream(file); | ||
88 | - byte[] data= new byte[(int)file.length()]; | ||
89 | - reader.read(data); | ||
90 | - reader.close(); | ||
91 | - | ||
92 | - //记得设置ContentType | ||
93 | - String fileName = file.getName(); | ||
94 | - response.setContentType(FileContentTypeUtils.contentType(fileName.substring(fileName.lastIndexOf(".")))); | ||
95 | - response.setHeader("Content-Dis", "filename="+file.getName()); | ||
96 | - stream.write(data); | ||
97 | - stream.flush(); | ||
98 | - } | ||
99 | -} |
src/main/java/com/taover/bazhuayun/analysis/web/controller/api/HeartBeatController.java
0 → 100644
@@ -0,0 +1,23 @@ | @@ -0,0 +1,23 @@ | ||
1 | +package com.taover.bazhuayun.analysis.web.controller.api; | ||
2 | + | ||
3 | +import javax.annotation.Resource; | ||
4 | +import javax.servlet.http.HttpServletRequest; | ||
5 | + | ||
6 | +import org.springframework.web.bind.annotation.GetMapping; | ||
7 | +import org.springframework.web.bind.annotation.RequestMapping; | ||
8 | +import org.springframework.web.bind.annotation.RestController; | ||
9 | + | ||
10 | +import com.taover.bazhuayun.analysis.web.module.heartbeat.HeartbeatManager; | ||
11 | +import com.taover.util.bean.ResultInfo; | ||
12 | + | ||
13 | +@RestController("api.heartbeat") | ||
14 | +@RequestMapping("/api/heartbeat") | ||
15 | +public class HeartBeatController { | ||
16 | + @Resource | ||
17 | + private HeartbeatManager heartbeatManager; | ||
18 | + | ||
19 | + @GetMapping | ||
20 | + public ResultInfo get(HttpServletRequest request) { | ||
21 | + return this.heartbeatManager.dealClientRequest(request); | ||
22 | + } | ||
23 | +} |
src/main/java/com/taover/bazhuayun/analysis/web/controller/data/ExportCenterController.java
0 → 100644
@@ -0,0 +1,99 @@ | @@ -0,0 +1,99 @@ | ||
1 | +package com.taover.bazhuayun.analysis.web.controller.data; | ||
2 | + | ||
3 | +import java.io.File; | ||
4 | +import java.io.FileInputStream; | ||
5 | +import java.io.IOException; | ||
6 | +import java.io.OutputStream; | ||
7 | +import java.text.ParseException; | ||
8 | +import java.text.SimpleDateFormat; | ||
9 | +import java.util.Date; | ||
10 | + | ||
11 | +import javax.annotation.Resource; | ||
12 | +import javax.servlet.http.HttpServletResponse; | ||
13 | + | ||
14 | +import org.apache.commons.lang.StringUtils; | ||
15 | +import org.springframework.web.bind.annotation.GetMapping; | ||
16 | +import org.springframework.web.bind.annotation.RequestMapping; | ||
17 | +import org.springframework.web.bind.annotation.RequestParam; | ||
18 | +import org.springframework.web.bind.annotation.RestController; | ||
19 | + | ||
20 | +import com.taover.bazhuayun.analysis.util.FileContentTypeUtils; | ||
21 | +import com.taover.bazhuayun.analysis.web.service.ExportCenterService; | ||
22 | +import com.taover.util.UtilLog; | ||
23 | + | ||
24 | +@RestController("exportcenter") | ||
25 | +@RequestMapping("/exportcenter") | ||
26 | +public class ExportCenterController { | ||
27 | + @Resource | ||
28 | + private ExportCenterService exportCenterService; | ||
29 | + | ||
30 | + @GetMapping("/wareorderfile") | ||
31 | + public void wareOrderFile(@RequestParam(name="tenantId", required=true) Integer tenantId, | ||
32 | + @RequestParam(name="startDate", defaultValue = "") String startDateStr, | ||
33 | + @RequestParam(name="endDate", defaultValue = "") String endDateStr, | ||
34 | + @RequestParam(name="wareCreateStartDate", defaultValue = "") String wareCreateStartDateStr, | ||
35 | + @RequestParam(name="wareCreateEndDate", defaultValue = "") String wareCreateEndDateStr, | ||
36 | + HttpServletResponse response) { | ||
37 | + Date startDate = new Date(); | ||
38 | + Date endDate = new Date(); | ||
39 | + Date wareCreateStartDate = null; | ||
40 | + Date wareCreateEndDate = null; | ||
41 | + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); | ||
42 | + if(StringUtils.isNotBlank(startDateStr)) { | ||
43 | + try { | ||
44 | + startDate = sdf.parse(startDateStr.substring(0, 10)); | ||
45 | + } catch (ParseException e) { | ||
46 | + e.printStackTrace(); | ||
47 | + } | ||
48 | + } | ||
49 | + if(StringUtils.isNotBlank(endDateStr)) { | ||
50 | + try { | ||
51 | + endDate = sdf.parse(endDateStr.substring(0, 10)); | ||
52 | + } catch (ParseException e) { | ||
53 | + e.printStackTrace(); | ||
54 | + } | ||
55 | + } | ||
56 | + if(StringUtils.isNotBlank(wareCreateStartDateStr)) { | ||
57 | + try { | ||
58 | + wareCreateStartDate = sdf.parse(wareCreateStartDateStr.substring(0, 10)); | ||
59 | + } catch (ParseException e) { | ||
60 | + e.printStackTrace(); | ||
61 | + } | ||
62 | + } | ||
63 | + if(StringUtils.isNotBlank(wareCreateEndDateStr)) { | ||
64 | + try { | ||
65 | + wareCreateEndDate = sdf.parse(wareCreateEndDateStr.substring(0, 10)); | ||
66 | + } catch (ParseException e) { | ||
67 | + e.printStackTrace(); | ||
68 | + } | ||
69 | + } | ||
70 | + | ||
71 | + File orderFile = null; | ||
72 | + try { | ||
73 | + orderFile = this.exportCenterService.wareOrderFile(tenantId, startDate, endDate, wareCreateStartDate, wareCreateEndDate); | ||
74 | + } catch (IOException e1) { | ||
75 | + UtilLog.errorForException(e1, this.getClass()); | ||
76 | + return; | ||
77 | + } | ||
78 | + try { | ||
79 | + this.writeFielToResponse(response, orderFile); | ||
80 | + } catch (IOException e) { | ||
81 | + UtilLog.errorForException(e, this.getClass()); | ||
82 | + } | ||
83 | + } | ||
84 | + | ||
85 | + private void writeFielToResponse(HttpServletResponse response, File file) throws IOException { | ||
86 | + OutputStream stream = response.getOutputStream(); | ||
87 | + FileInputStream reader = new FileInputStream(file); | ||
88 | + byte[] data= new byte[(int)file.length()]; | ||
89 | + reader.read(data); | ||
90 | + reader.close(); | ||
91 | + | ||
92 | + //记得设置ContentType | ||
93 | + String fileName = file.getName(); | ||
94 | + response.setContentType(FileContentTypeUtils.contentType(fileName.substring(fileName.lastIndexOf(".")))); | ||
95 | + response.setHeader("Content-Dis", "filename="+file.getName()); | ||
96 | + stream.write(data); | ||
97 | + stream.flush(); | ||
98 | + } | ||
99 | +} |
src/main/java/com/taover/bazhuayun/analysis/web/form/BaseCreateForm.java
0 → 100644
@@ -0,0 +1,25 @@ | @@ -0,0 +1,25 @@ | ||
1 | +package com.taover.bazhuayun.analysis.web.form; | ||
2 | + | ||
3 | +import java.util.ArrayList; | ||
4 | +import java.util.List; | ||
5 | + | ||
6 | +import org.springframework.validation.BindingResult; | ||
7 | +import org.springframework.validation.ObjectError; | ||
8 | + | ||
9 | +public abstract class BaseCreateForm extends BaseForm{ | ||
10 | + /** | ||
11 | + * 获取验证异常消息列表 | ||
12 | + * @param bindingResult | ||
13 | + * @return | ||
14 | + */ | ||
15 | + public List<String> getErrorMessageList(BindingResult bindingResult){ | ||
16 | + List<String> errorMessageList = new ArrayList<String>(); | ||
17 | + if(bindingResult.hasErrors()){ | ||
18 | + List<ObjectError> errorList = bindingResult.getAllErrors(); | ||
19 | + for(int i=0; i<errorList.size(); ++i){ | ||
20 | + errorMessageList.add(errorList.get(i).getDefaultMessage()); | ||
21 | + } | ||
22 | + } | ||
23 | + return errorMessageList; | ||
24 | + } | ||
25 | +} |
src/main/java/com/taover/bazhuayun/analysis/web/form/BaseForm.java
0 → 100644
@@ -0,0 +1,64 @@ | @@ -0,0 +1,64 @@ | ||
1 | +package com.taover.bazhuayun.analysis.web.form; | ||
2 | + | ||
3 | +import java.lang.reflect.Field; | ||
4 | +import java.util.HashMap; | ||
5 | +import java.util.Map; | ||
6 | + | ||
7 | +import com.taover.util.UtilString; | ||
8 | + | ||
9 | +public abstract class BaseForm { | ||
10 | + private static Map<Class<? extends BaseForm>, Field[]> CACHE_FIELDS_BY_CLASS = new HashMap<Class<? extends BaseForm>, Field[]>(); | ||
11 | + | ||
12 | + /** | ||
13 | + * 通过正则表达式去除所有字符串左右空白字符 | ||
14 | + */ | ||
15 | + public void trimByRegexS(){ | ||
16 | + Class<? extends BaseForm> thisClass = this.getClass(); | ||
17 | + Field[] fieldArr = CACHE_FIELDS_BY_CLASS.get(thisClass); | ||
18 | + if(fieldArr == null) { | ||
19 | + fieldArr = thisClass.getDeclaredFields(); | ||
20 | + CACHE_FIELDS_BY_CLASS.put(thisClass, fieldArr); | ||
21 | + } | ||
22 | + for(int i=0; i<fieldArr.length; ++i){ | ||
23 | + Field fieldItem = fieldArr[i]; | ||
24 | + fieldItem.setAccessible(true); | ||
25 | + if(fieldItem.getType().getSimpleName().equals("String")){ | ||
26 | + try { | ||
27 | + fieldItem.set(this, UtilString.trimByRegexS((String)fieldItem.get(this))); | ||
28 | + } catch (IllegalArgumentException e) { | ||
29 | + e.printStackTrace(); | ||
30 | + } catch (IllegalAccessException e) { | ||
31 | + e.printStackTrace(); | ||
32 | + } | ||
33 | + } | ||
34 | + } | ||
35 | + } | ||
36 | + | ||
37 | + @Override | ||
38 | + public String toString() { | ||
39 | + Class<? extends BaseForm> thisClass = this.getClass(); | ||
40 | + Field[] fieldArr = CACHE_FIELDS_BY_CLASS.get(thisClass); | ||
41 | + if(fieldArr == null) { | ||
42 | + fieldArr = thisClass.getDeclaredFields(); | ||
43 | + CACHE_FIELDS_BY_CLASS.put(thisClass, fieldArr); | ||
44 | + } | ||
45 | + StringBuffer result = new StringBuffer(); | ||
46 | + for(int i=0; i<fieldArr.length; ++i){ | ||
47 | + Field fieldItem = fieldArr[i]; | ||
48 | + if(!fieldItem.isAccessible()) { | ||
49 | + fieldItem.setAccessible(true); | ||
50 | + } | ||
51 | + try { | ||
52 | + Object data = fieldItem.get(this); | ||
53 | + if(data != null) { | ||
54 | + result.append("["+fieldItem.getName()+":"+data.toString()+"]"); | ||
55 | + } | ||
56 | + } catch (IllegalArgumentException e) { | ||
57 | + e.printStackTrace(); | ||
58 | + } catch (IllegalAccessException e) { | ||
59 | + e.printStackTrace(); | ||
60 | + } | ||
61 | + } | ||
62 | + return result.toString(); | ||
63 | + } | ||
64 | +} |
src/main/java/com/taover/bazhuayun/analysis/web/form/BaseSearchForm.java
0 → 100644
@@ -0,0 +1,110 @@ | @@ -0,0 +1,110 @@ | ||
1 | +package com.taover.bazhuayun.analysis.web.form; | ||
2 | + | ||
3 | +import java.util.Date; | ||
4 | + | ||
5 | +import org.apache.commons.lang.StringUtils; | ||
6 | + | ||
7 | +import com.taover.util.UtilString; | ||
8 | + | ||
9 | +import cn.hutool.core.date.DateUtil; | ||
10 | + | ||
11 | +public abstract class BaseSearchForm extends BaseForm{ | ||
12 | + public String sortBy; | ||
13 | + public String sortOrder; | ||
14 | + public String originOrderBySql; | ||
15 | + | ||
16 | + public String getSortBy() { | ||
17 | + return sortBy; | ||
18 | + } | ||
19 | + | ||
20 | + public void setSortBy(String sortBy) { | ||
21 | + this.sortBy = sortBy; | ||
22 | + } | ||
23 | + | ||
24 | + public String getSortOrder() { | ||
25 | + return sortOrder; | ||
26 | + } | ||
27 | + | ||
28 | + public void setSortOrder(String sortOrder) { | ||
29 | + this.sortOrder = sortOrder; | ||
30 | + } | ||
31 | + | ||
32 | + public String getOriginOrderBySql() { | ||
33 | + return originOrderBySql; | ||
34 | + } | ||
35 | + | ||
36 | + public void setOriginOrderBySql(String originOrderBySql) { | ||
37 | + this.originOrderBySql = originOrderBySql; | ||
38 | + } | ||
39 | + | ||
40 | + public String createDateStartSql(Date startDate, String columnSql){ | ||
41 | + return " AND " + columnSql + ">='" + DateUtil.formatDateTime(startDate) +"' "; | ||
42 | + } | ||
43 | + | ||
44 | + public String createDateEndSql(Date endDate, String columnSql){ | ||
45 | + return " AND " + columnSql + "<='" + DateUtil.formatDateTime(endDate) + "' "; | ||
46 | + } | ||
47 | + | ||
48 | + public String createGreaterEqualSql(Object value, String columnSql){ | ||
49 | + if(value == null) { | ||
50 | + return ""; | ||
51 | + } | ||
52 | + return " AND " + columnSql + ">=" + value.toString(); | ||
53 | + } | ||
54 | + | ||
55 | + public String createLessEqualSql(Object value, String columnSql){ | ||
56 | + if(value == null) { | ||
57 | + return ""; | ||
58 | + } | ||
59 | + return " AND " + columnSql + "<=" + value.toString(); | ||
60 | + } | ||
61 | + | ||
62 | + public String createLikeSql(String likeStr, String columnSql){ | ||
63 | + if(likeStr == null) { | ||
64 | + return ""; | ||
65 | + } | ||
66 | + return " AND "+columnSql+" like '%"+this.preDealSqlKeyword(likeStr)+"%'"; | ||
67 | + } | ||
68 | + | ||
69 | + public String createRightLikeSql(String likeStr, String columnSql){ | ||
70 | + if(likeStr == null) { | ||
71 | + return ""; | ||
72 | + } | ||
73 | + return " AND "+columnSql+" like '"+this.preDealSqlKeyword(likeStr)+"%'"; | ||
74 | + } | ||
75 | + | ||
76 | + public String createEqualsSql(Object value, String columnSql){ | ||
77 | + if(value == null) { | ||
78 | + return ""; | ||
79 | + } | ||
80 | + return " AND "+columnSql+"='"+this.preDealSqlKeyword(value.toString())+"'"; | ||
81 | + } | ||
82 | + | ||
83 | + public String createInSql(String[] inArray, String columnSql){ | ||
84 | + return " AND "+columnSql+" IN('"+StringUtils.join(inArray, "','")+"')"; | ||
85 | + } | ||
86 | + | ||
87 | + public String createInSql(Integer[] inArray, String columnSql){ | ||
88 | + return " AND "+columnSql+" IN("+StringUtils.join(inArray, ",")+")"; | ||
89 | + } | ||
90 | + | ||
91 | + public String createInSql(Long[] inArray, String columnSql){ | ||
92 | + return " AND "+columnSql+" IN("+StringUtils.join(inArray, ",")+")"; | ||
93 | + } | ||
94 | + | ||
95 | + public String getOrderBySql(String defaultOrderBySql) { | ||
96 | + if(StringUtils.isNotBlank(this.getOriginOrderBySql())) { | ||
97 | + return " ORDER BY "+this.getOriginOrderBySql(); | ||
98 | + }else if(StringUtils.isNotBlank(this.getSortBy()) && StringUtils.isNotBlank(this.getSortOrder())) { | ||
99 | + return " ORDER BY "+UtilString.underscoreName(this.getSortBy()).toLowerCase()+" "+this.getSortOrder(); | ||
100 | + } | ||
101 | + return defaultOrderBySql; | ||
102 | + } | ||
103 | + | ||
104 | + public String preDealSqlKeyword(String value) { | ||
105 | + if(value == null) { | ||
106 | + return ""; | ||
107 | + } | ||
108 | + return value.replaceAll("\\\\", "\\\\\\\\\\\\\\\\").replaceAll("'", "\\\\'"); | ||
109 | + } | ||
110 | +} |
src/main/java/com/taover/bazhuayun/analysis/web/form/BaseUpdateForm.java
0 → 100644
@@ -0,0 +1,44 @@ | @@ -0,0 +1,44 @@ | ||
1 | +package com.taover.bazhuayun.analysis.web.form; | ||
2 | + | ||
3 | +import java.lang.reflect.Field; | ||
4 | +import java.util.ArrayList; | ||
5 | +import java.util.List; | ||
6 | + | ||
7 | +import javax.persistence.Column; | ||
8 | +import javax.persistence.Id; | ||
9 | + | ||
10 | +public abstract class BaseUpdateForm extends BaseForm{ | ||
11 | + | ||
12 | + /** | ||
13 | + * 转换为数据库字段更新数组 | ||
14 | + * @return | ||
15 | + */ | ||
16 | + public List<Object[]> getSQLUpdateList(){ | ||
17 | + List<Object[]> result = new ArrayList<Object[]>(); | ||
18 | + Field[] fieldArr = this.getClass().getDeclaredFields(); | ||
19 | + for(int i=0; i<fieldArr.length; ++i){ | ||
20 | + Field fieldItem = fieldArr[i]; | ||
21 | + fieldItem.setAccessible(true); | ||
22 | + Id annoId = fieldItem.getDeclaredAnnotation(Id.class); | ||
23 | + if(annoId != null){ | ||
24 | + continue; | ||
25 | + } | ||
26 | + Column annoColumn = fieldItem.getDeclaredAnnotation(Column.class); | ||
27 | + if(annoColumn == null){ | ||
28 | + continue; | ||
29 | + } | ||
30 | + try { | ||
31 | + Object value = fieldItem.get(this); | ||
32 | + if(value == null){ | ||
33 | + continue; | ||
34 | + } | ||
35 | + result.add(new Object[]{annoColumn.name(), value}); | ||
36 | + } catch (IllegalArgumentException e) { | ||
37 | + e.printStackTrace(); | ||
38 | + } catch (IllegalAccessException e) { | ||
39 | + e.printStackTrace(); | ||
40 | + } | ||
41 | + } | ||
42 | + return result; | ||
43 | + } | ||
44 | +} |
src/main/java/com/taover/bazhuayun/analysis/web/form/HeartbeatInstanceCreateForm.java
0 → 100644
@@ -0,0 +1,163 @@ | @@ -0,0 +1,163 @@ | ||
1 | +package com.taover.bazhuayun.analysis.web.form; | ||
2 | + | ||
3 | +import javax.persistence.Column; | ||
4 | +import javax.persistence.Id; | ||
5 | + | ||
6 | +public class HeartbeatInstanceCreateForm extends BaseCreateForm { | ||
7 | + | ||
8 | + /** | ||
9 | + * 实例类型:0-请求端,1-服务端 | ||
10 | + */ | ||
11 | + private java.lang.Integer roleType; | ||
12 | + | ||
13 | + public java.lang.Integer getRoleType(){ | ||
14 | + return roleType; | ||
15 | + } | ||
16 | + public void setRoleType(java.lang.Integer roleType){ | ||
17 | + this.roleType = roleType; | ||
18 | + } | ||
19 | + | ||
20 | + /** | ||
21 | + * | ||
22 | + */ | ||
23 | + private java.lang.String url; | ||
24 | + | ||
25 | + public java.lang.String getUrl(){ | ||
26 | + return url; | ||
27 | + } | ||
28 | + public void setUrl(java.lang.String url){ | ||
29 | + this.url = url; | ||
30 | + } | ||
31 | + | ||
32 | + /** | ||
33 | + * | ||
34 | + */ | ||
35 | + private java.lang.String code; | ||
36 | + | ||
37 | + public java.lang.String getCode(){ | ||
38 | + return code; | ||
39 | + } | ||
40 | + public void setCode(java.lang.String code){ | ||
41 | + this.code = code; | ||
42 | + } | ||
43 | + | ||
44 | + /** | ||
45 | + * | ||
46 | + */ | ||
47 | + private java.lang.Integer fixRateSec; | ||
48 | + | ||
49 | + public java.lang.Integer getFixRateSec(){ | ||
50 | + return fixRateSec; | ||
51 | + } | ||
52 | + public void setFixRateSec(java.lang.Integer fixRateSec){ | ||
53 | + this.fixRateSec = fixRateSec; | ||
54 | + } | ||
55 | + | ||
56 | + /** | ||
57 | + * | ||
58 | + */ | ||
59 | + private java.lang.Integer maxWaitSec; | ||
60 | + | ||
61 | + public java.lang.Integer getMaxWaitSec(){ | ||
62 | + return maxWaitSec; | ||
63 | + } | ||
64 | + public void setMaxWaitSec(java.lang.Integer maxWaitSec){ | ||
65 | + this.maxWaitSec = maxWaitSec; | ||
66 | + } | ||
67 | + | ||
68 | + /** | ||
69 | + * | ||
70 | + */ | ||
71 | + private java.lang.String token; | ||
72 | + | ||
73 | + public java.lang.String getToken(){ | ||
74 | + return token; | ||
75 | + } | ||
76 | + public void setToken(java.lang.String token){ | ||
77 | + this.token = token; | ||
78 | + } | ||
79 | + | ||
80 | + /** | ||
81 | + * | ||
82 | + */ | ||
83 | + private java.lang.String reformEmail; | ||
84 | + | ||
85 | + public java.lang.String getReformEmail(){ | ||
86 | + return reformEmail; | ||
87 | + } | ||
88 | + public void setReformEmail(java.lang.String reformEmail){ | ||
89 | + this.reformEmail = reformEmail; | ||
90 | + } | ||
91 | + | ||
92 | + /** | ||
93 | + * | ||
94 | + */ | ||
95 | + private java.lang.String reformWxid; | ||
96 | + | ||
97 | + public java.lang.String getReformWxid(){ | ||
98 | + return reformWxid; | ||
99 | + } | ||
100 | + public void setReformWxid(java.lang.String reformWxid){ | ||
101 | + this.reformWxid = reformWxid; | ||
102 | + } | ||
103 | + | ||
104 | + /** | ||
105 | + * | ||
106 | + */ | ||
107 | + private java.lang.String reformPhone; | ||
108 | + | ||
109 | + public java.lang.String getReformPhone(){ | ||
110 | + return reformPhone; | ||
111 | + } | ||
112 | + public void setReformPhone(java.lang.String reformPhone){ | ||
113 | + this.reformPhone = reformPhone; | ||
114 | + } | ||
115 | + | ||
116 | + /** | ||
117 | + * 可用状态:0-注销,1-使用中 | ||
118 | + */ | ||
119 | + private java.lang.Integer status; | ||
120 | + | ||
121 | + public java.lang.Integer getStatus(){ | ||
122 | + return status; | ||
123 | + } | ||
124 | + public void setStatus(java.lang.Integer status){ | ||
125 | + this.status = status; | ||
126 | + } | ||
127 | + | ||
128 | + /** | ||
129 | + * | ||
130 | + */ | ||
131 | + private java.lang.Integer reformMaxTime; | ||
132 | + | ||
133 | + public java.lang.Integer getReformMaxTime(){ | ||
134 | + return reformMaxTime; | ||
135 | + } | ||
136 | + public void setReformMaxTime(java.lang.Integer reformMaxTime){ | ||
137 | + this.reformMaxTime = reformMaxTime; | ||
138 | + } | ||
139 | + | ||
140 | + /** | ||
141 | + * | ||
142 | + */ | ||
143 | + private java.lang.String deployUrl; | ||
144 | + | ||
145 | + public java.lang.String getDeployUrl(){ | ||
146 | + return deployUrl; | ||
147 | + } | ||
148 | + public void setDeployUrl(java.lang.String deployUrl){ | ||
149 | + this.deployUrl = deployUrl; | ||
150 | + } | ||
151 | + | ||
152 | + /** | ||
153 | + * 丢包满足多少次,则调用发布 | ||
154 | + */ | ||
155 | + private java.lang.Integer deployAtLostNum; | ||
156 | + | ||
157 | + public java.lang.Integer getDeployAtLostNum(){ | ||
158 | + return deployAtLostNum; | ||
159 | + } | ||
160 | + public void setDeployAtLostNum(java.lang.Integer deployAtLostNum){ | ||
161 | + this.deployAtLostNum = deployAtLostNum; | ||
162 | + } | ||
163 | +} |
src/main/java/com/taover/bazhuayun/analysis/web/form/HeartbeatInstanceUpdateForm.java
0 → 100644
@@ -0,0 +1,152 @@ | @@ -0,0 +1,152 @@ | ||
1 | +package com.taover.bazhuayun.analysis.web.form; | ||
2 | + | ||
3 | +import javax.persistence.Column; | ||
4 | +import javax.persistence.Id; | ||
5 | + | ||
6 | +public class HeartbeatInstanceUpdateForm extends BaseUpdateForm { | ||
7 | + @Column(name="url") | ||
8 | + private java.lang.String url; | ||
9 | + | ||
10 | + public java.lang.String getUrl(){ | ||
11 | + return url; | ||
12 | + } | ||
13 | + public void setUrl(java.lang.String url){ | ||
14 | + this.url = url; | ||
15 | + } | ||
16 | + | ||
17 | + private java.lang.String code; | ||
18 | + | ||
19 | + public java.lang.String getCode(){ | ||
20 | + return code; | ||
21 | + } | ||
22 | + public void setCode(java.lang.String code){ | ||
23 | + this.code = code; | ||
24 | + } | ||
25 | + | ||
26 | + @Column(name="fix_rate_sec") | ||
27 | + private java.lang.Integer fixRateSec; | ||
28 | + | ||
29 | + public java.lang.Integer getFixRateSec(){ | ||
30 | + return fixRateSec; | ||
31 | + } | ||
32 | + public void setFixRateSec(java.lang.Integer fixRateSec){ | ||
33 | + this.fixRateSec = fixRateSec; | ||
34 | + } | ||
35 | + | ||
36 | + /** | ||
37 | + * | ||
38 | + */ | ||
39 | + @Column(name="max_wait_sec") | ||
40 | + private java.lang.Integer maxWaitSec; | ||
41 | + | ||
42 | + public java.lang.Integer getMaxWaitSec(){ | ||
43 | + return maxWaitSec; | ||
44 | + } | ||
45 | + public void setMaxWaitSec(java.lang.Integer maxWaitSec){ | ||
46 | + this.maxWaitSec = maxWaitSec; | ||
47 | + } | ||
48 | + | ||
49 | + /** | ||
50 | + * | ||
51 | + */ | ||
52 | + @Column(name="token") | ||
53 | + private java.lang.String token; | ||
54 | + | ||
55 | + public java.lang.String getToken(){ | ||
56 | + return token; | ||
57 | + } | ||
58 | + public void setToken(java.lang.String token){ | ||
59 | + this.token = token; | ||
60 | + } | ||
61 | + | ||
62 | + /** | ||
63 | + * | ||
64 | + */ | ||
65 | + @Column(name="reform_email") | ||
66 | + private java.lang.String reformEmail; | ||
67 | + | ||
68 | + public java.lang.String getReformEmail(){ | ||
69 | + return reformEmail; | ||
70 | + } | ||
71 | + public void setReformEmail(java.lang.String reformEmail){ | ||
72 | + this.reformEmail = reformEmail; | ||
73 | + } | ||
74 | + | ||
75 | + /** | ||
76 | + * | ||
77 | + */ | ||
78 | + @Column(name="reform_wxid") | ||
79 | + private java.lang.String reformWxid; | ||
80 | + | ||
81 | + public java.lang.String getReformWxid(){ | ||
82 | + return reformWxid; | ||
83 | + } | ||
84 | + public void setReformWxid(java.lang.String reformWxid){ | ||
85 | + this.reformWxid = reformWxid; | ||
86 | + } | ||
87 | + | ||
88 | + /** | ||
89 | + * | ||
90 | + */ | ||
91 | + @Column(name="reform_phone") | ||
92 | + private java.lang.String reformPhone; | ||
93 | + | ||
94 | + public java.lang.String getReformPhone(){ | ||
95 | + return reformPhone; | ||
96 | + } | ||
97 | + public void setReformPhone(java.lang.String reformPhone){ | ||
98 | + this.reformPhone = reformPhone; | ||
99 | + } | ||
100 | + | ||
101 | + /** | ||
102 | + * 可用状态:0-注销,1-使用中 | ||
103 | + */ | ||
104 | + @Column(name="status") | ||
105 | + private java.lang.Integer status; | ||
106 | + | ||
107 | + public java.lang.Integer getStatus(){ | ||
108 | + return status; | ||
109 | + } | ||
110 | + public void setStatus(java.lang.Integer status){ | ||
111 | + this.status = status; | ||
112 | + } | ||
113 | + | ||
114 | + /** | ||
115 | + * | ||
116 | + */ | ||
117 | + @Column(name="reform_max_time") | ||
118 | + private java.lang.Integer reformMaxTime; | ||
119 | + | ||
120 | + public java.lang.Integer getReformMaxTime(){ | ||
121 | + return reformMaxTime; | ||
122 | + } | ||
123 | + public void setReformMaxTime(java.lang.Integer reformMaxTime){ | ||
124 | + this.reformMaxTime = reformMaxTime; | ||
125 | + } | ||
126 | + | ||
127 | + /** | ||
128 | + * | ||
129 | + */ | ||
130 | + @Column(name="deploy_url") | ||
131 | + private java.lang.String deployUrl; | ||
132 | + | ||
133 | + public java.lang.String getDeployUrl(){ | ||
134 | + return deployUrl; | ||
135 | + } | ||
136 | + public void setDeployUrl(java.lang.String deployUrl){ | ||
137 | + this.deployUrl = deployUrl; | ||
138 | + } | ||
139 | + | ||
140 | + /** | ||
141 | + * 丢包满足多少次,则调用发布 | ||
142 | + */ | ||
143 | + @Column(name="deploy_at_lost_num") | ||
144 | + private java.lang.Integer deployAtLostNum; | ||
145 | + | ||
146 | + public java.lang.Integer getDeployAtLostNum(){ | ||
147 | + return deployAtLostNum; | ||
148 | + } | ||
149 | + public void setDeployAtLostNum(java.lang.Integer deployAtLostNum){ | ||
150 | + this.deployAtLostNum = deployAtLostNum; | ||
151 | + } | ||
152 | +} |
src/main/java/com/taover/bazhuayun/analysis/web/module/heartbeat/HeartbeatManager.java
0 → 100644
@@ -0,0 +1,59 @@ | @@ -0,0 +1,59 @@ | ||
1 | +package com.taover.bazhuayun.analysis.web.module.heartbeat; | ||
2 | + | ||
3 | +import java.util.List; | ||
4 | + | ||
5 | +import javax.servlet.http.HttpServletRequest; | ||
6 | + | ||
7 | +import com.taover.bazhuayun.analysis.web.form.HeartbeatInstanceCreateForm; | ||
8 | +import com.taover.bazhuayun.analysis.web.form.HeartbeatInstanceUpdateForm; | ||
9 | +import com.taover.bazhuayun.analysis.web.repository.AnalysisHeartbeatInstanceEntity; | ||
10 | +import com.taover.util.bean.ResultInfo; | ||
11 | + | ||
12 | +public interface HeartbeatManager { | ||
13 | + /** | ||
14 | + * 加载实例 | ||
15 | + * @param servers | ||
16 | + */ | ||
17 | + void loadInstance(List<AnalysisHeartbeatInstanceEntity> servers) throws Exception; | ||
18 | + | ||
19 | + /** | ||
20 | + * 创建监控实例 | ||
21 | + * @param form | ||
22 | + */ | ||
23 | + void createInstance(HeartbeatInstanceCreateForm form); | ||
24 | + | ||
25 | + /** | ||
26 | + * 修改监控实例 | ||
27 | + * @param form | ||
28 | + */ | ||
29 | + void updateInstance(HeartbeatInstanceUpdateForm form); | ||
30 | + | ||
31 | + /** | ||
32 | + * 停用监控实例 | ||
33 | + * @param code | ||
34 | + */ | ||
35 | + void disableInstanceByCode(String code); | ||
36 | + | ||
37 | + /** | ||
38 | + * 启用监控实例 | ||
39 | + * @param code | ||
40 | + */ | ||
41 | + void enableInstanceByCode(String code); | ||
42 | + | ||
43 | + /** | ||
44 | + * 处理客户端心跳请求 | ||
45 | + * @param clientRequest | ||
46 | + * @return | ||
47 | + */ | ||
48 | + ResultInfo dealClientRequest(HttpServletRequest request); | ||
49 | + | ||
50 | + /** | ||
51 | + * 刷新客户端状态 | ||
52 | + */ | ||
53 | + void flushClientStatus(); | ||
54 | + | ||
55 | + /** | ||
56 | + * 向服务器发送心跳 | ||
57 | + */ | ||
58 | + void sendServerHeartbeat(); | ||
59 | +} |
src/main/java/com/taover/bazhuayun/analysis/web/module/heartbeat/HeartbeatManagerImpl.java
0 → 100644
@@ -0,0 +1,329 @@ | @@ -0,0 +1,329 @@ | ||
1 | +package com.taover.bazhuayun.analysis.web.module.heartbeat; | ||
2 | + | ||
3 | +import java.util.ArrayList; | ||
4 | +import java.util.List; | ||
5 | +import java.util.Map; | ||
6 | + | ||
7 | +import javax.annotation.Resource; | ||
8 | +import javax.servlet.http.HttpServletRequest; | ||
9 | + | ||
10 | +import org.springframework.stereotype.Service; | ||
11 | + | ||
12 | +import com.alibaba.fastjson.JSONObject; | ||
13 | +import com.taover.bazhuayun.analysis.web.form.HeartbeatInstanceCreateForm; | ||
14 | +import com.taover.bazhuayun.analysis.web.form.HeartbeatInstanceUpdateForm; | ||
15 | +import com.taover.bazhuayun.analysis.web.module.heartbeat.bean.ClientInstance; | ||
16 | +import com.taover.bazhuayun.analysis.web.module.heartbeat.bean.ClientRequest; | ||
17 | +import com.taover.bazhuayun.analysis.web.module.heartbeat.bean.Instance; | ||
18 | +import com.taover.bazhuayun.analysis.web.module.heartbeat.bean.ServerInstance; | ||
19 | +import com.taover.bazhuayun.analysis.web.module.heartbeat.holder.ClientHolder; | ||
20 | +import com.taover.bazhuayun.analysis.web.module.heartbeat.holder.ClientHolderImpl; | ||
21 | +import com.taover.bazhuayun.analysis.web.module.heartbeat.holder.ServerHolder; | ||
22 | +import com.taover.bazhuayun.analysis.web.module.heartbeat.holder.ServerHolderImpl; | ||
23 | +import com.taover.bazhuayun.analysis.web.module.heartbeat.service.HeartbeatDeployService; | ||
24 | +import com.taover.bazhuayun.analysis.web.module.heartbeat.service.HeartbeatReformService; | ||
25 | +import com.taover.bazhuayun.analysis.web.repository.AnalysisHeartbeatInstanceEntity; | ||
26 | +import com.taover.bazhuayun.analysis.web.repository.AnalysisHeartbeatInstanceRepository; | ||
27 | +import com.taover.bazhuayun.analysis.web.repository.AnalysisHeartbeatLogEntity; | ||
28 | +import com.taover.bazhuayun.analysis.web.repository.AnalysisHeartbeatLogRepository; | ||
29 | +import com.taover.repository.exception.MultiRowException; | ||
30 | +import com.taover.repository.exception.NotFoundException; | ||
31 | +import com.taover.util.UtilLog; | ||
32 | +import com.taover.util.bean.ResultInfo; | ||
33 | +import com.taover.util.bean.UtilResultInfo; | ||
34 | + | ||
35 | +@Service | ||
36 | +public class HeartbeatManagerImpl implements HeartbeatManager { | ||
37 | + //客户端holder | ||
38 | + private static ClientHolder clientHolder = new ClientHolderImpl(); | ||
39 | + //服务端holder | ||
40 | + private static ServerHolder serverHolder = new ServerHolderImpl(); | ||
41 | + | ||
42 | + @Resource | ||
43 | + private HeartbeatReformService heartbeatReformService; | ||
44 | + @Resource | ||
45 | + private HeartbeatDeployService heartbeatDeployService; | ||
46 | + @Resource | ||
47 | + private AnalysisHeartbeatInstanceRepository analysisHeartbeatInstanceRepository; | ||
48 | + @Resource | ||
49 | + private AnalysisHeartbeatLogRepository analysisHeartbeatLogRepository; | ||
50 | + | ||
51 | + /** | ||
52 | + * 处理客户端心跳请求 | ||
53 | + * @param clientRequest | ||
54 | + * @return | ||
55 | + * @throws | ||
56 | + */ | ||
57 | + @Override | ||
58 | + public ResultInfo dealClientRequest(HttpServletRequest request) { | ||
59 | + ClientRequest cRequest = ClientRequest.createClientRequest(request); | ||
60 | + if(!clientHolder.containInstanceCode(cRequest.getCode())) { | ||
61 | + return UtilResultInfo.getFailure("code="+cRequest.getCode()+"找不到对应的监控实例"); | ||
62 | + } | ||
63 | + | ||
64 | + try { | ||
65 | + AnalysisHeartbeatInstanceEntity instance = this.analysisHeartbeatInstanceRepository.findEntityBySql("code='"+cRequest.getCode()+"' and role_type="+AnalysisHeartbeatInstanceRepository.ROLE_TYPE_CLIENT+" and status="+AnalysisHeartbeatInstanceRepository.STATUS_ENABLE, null); | ||
66 | + ResultInfo result = null; | ||
67 | + try { | ||
68 | + //刷新client信息 | ||
69 | + clientHolder.dealClientRequest(cRequest, instance); | ||
70 | + result = UtilResultInfo.getSuccess(""); | ||
71 | + }catch (Exception e) { | ||
72 | + result = UtilResultInfo.getFailure(e.getMessage()); | ||
73 | + } | ||
74 | + | ||
75 | + //记录请求日志 | ||
76 | + this.createLog(cRequest, request.getParameterMap(), result); | ||
77 | + | ||
78 | + return result; | ||
79 | + }catch (NotFoundException | MultiRowException e) { | ||
80 | + return UtilResultInfo.getFailure("查找code="+cRequest.getCode()+"对应的监控实例异常,异常信息:"+e.getMessage()); | ||
81 | + } | ||
82 | + } | ||
83 | + | ||
84 | + private void createLog(ClientRequest cRequest, Map<String, String[]> data, ResultInfo response) { | ||
85 | + try { | ||
86 | + AnalysisHeartbeatLogEntity log = new AnalysisHeartbeatLogEntity(); | ||
87 | + log.setClientIp(cRequest.getIp()); | ||
88 | + log.setInstanceCode(cRequest.getCode()); | ||
89 | + log.setResponse(JSONObject.toJSONString(response)); | ||
90 | + log.setRequest(JSONObject.toJSONString(data)); | ||
91 | + this.analysisHeartbeatLogRepository.addEntity(log, null); | ||
92 | + }catch (Exception e) { | ||
93 | + UtilLog.error("数据库异常:客户端心跳请求,日志记录出现异常", e, HeartbeatManagerImpl.class); | ||
94 | + } | ||
95 | + } | ||
96 | + | ||
97 | + /** | ||
98 | + * 刷新客户端状态 | ||
99 | + */ | ||
100 | + @Override | ||
101 | + public void flushClientStatus() { | ||
102 | + List<ClientInstance> instances = clientHolder.getClientInstanceList(); | ||
103 | + for(ClientInstance item: instances) { | ||
104 | + try { | ||
105 | + item.flush(); | ||
106 | + if(item.needReform()) { | ||
107 | + this.heartbeatReformService.sendReform(item); | ||
108 | + } | ||
109 | + if(item.needDeploy()) { | ||
110 | + this.heartbeatDeployService.sendDeploy(item); | ||
111 | + } | ||
112 | + }catch (Exception e) { | ||
113 | + UtilLog.error("刷新客户端状态出现异常,code["+item.getIdentity()+"]", e, this.getClass()); | ||
114 | + } | ||
115 | + } | ||
116 | + } | ||
117 | + | ||
118 | + /** | ||
119 | + * 向服务器发送心跳 | ||
120 | + */ | ||
121 | + @Override | ||
122 | + public void sendServerHeartbeat() { | ||
123 | + List<ServerInstance> instances = serverHolder.getServerInstanceList(); | ||
124 | + for(ServerInstance item: instances) { | ||
125 | + try { | ||
126 | + item.flush(); | ||
127 | + if(item.isSendNewHeartbeat()) { | ||
128 | + this.createLog(item); | ||
129 | + } | ||
130 | + if(item.needReform()) { | ||
131 | + this.heartbeatReformService.sendReform(item); | ||
132 | + } | ||
133 | + if(item.needDeploy()) { | ||
134 | + this.heartbeatDeployService.sendDeploy(item); | ||
135 | + } | ||
136 | + }catch (Exception e) { | ||
137 | + UtilLog.error("向服务器发送心跳出现异常,code["+item.getIdentity()+"]", e, this.getClass()); | ||
138 | + } | ||
139 | + } | ||
140 | + } | ||
141 | + | ||
142 | + private void createLog(ServerInstance item) { | ||
143 | + try { | ||
144 | + AnalysisHeartbeatLogEntity log = new AnalysisHeartbeatLogEntity(); | ||
145 | + log.setServerUrl(item.getLatestUrlWithParam()); | ||
146 | + log.setInstanceCode(item.getIdentity()); | ||
147 | + if(item.getLatestServerResponse() == null) { | ||
148 | + log.setResponse("null"); | ||
149 | + }else { | ||
150 | + log.setResponse(item.getLatestServerResponse().toString()); | ||
151 | + } | ||
152 | + this.analysisHeartbeatLogRepository.addEntity(log, null); | ||
153 | + }catch (Exception e) { | ||
154 | + UtilLog.error("数据库异常:向服务器发送心跳,日志记录出现异常", e, HeartbeatManagerImpl.class); | ||
155 | + } | ||
156 | + } | ||
157 | + | ||
158 | + @Override | ||
159 | + public void loadInstance(List<AnalysisHeartbeatInstanceEntity> instanceList) throws Exception{ | ||
160 | + if(instanceList == null || instanceList.isEmpty()) { | ||
161 | + return; | ||
162 | + } | ||
163 | + for(AnalysisHeartbeatInstanceEntity serverItem: instanceList) { | ||
164 | + if(serverItem.getCode() == null || serverItem.getCode().trim().equals("")) { | ||
165 | + continue; | ||
166 | + } | ||
167 | + if(serverItem.getFixRateSec() == null) { | ||
168 | + serverItem.setFixRateSec(Instance.DEFAULT_FIX_RATE_SEC); | ||
169 | + } | ||
170 | + if(serverItem.getMaxWaitSec() == null) { | ||
171 | + serverItem.setMaxWaitSec(Instance.DEFAULT_MAX_WAIT_SEC); | ||
172 | + } | ||
173 | + | ||
174 | + try { | ||
175 | + this.registryRuntimeInstance(serverItem); | ||
176 | + }catch (Exception e) { | ||
177 | + UtilLog.error("注册监控实例出现异常,code["+serverItem.getCode()+"]", e, this.getClass()); | ||
178 | + } | ||
179 | + } | ||
180 | + } | ||
181 | + | ||
182 | + private void registryRuntimeInstance(AnalysisHeartbeatInstanceEntity serverItem) throws Exception { | ||
183 | + if(AnalysisHeartbeatInstanceRepository.ROLE_TYPE_SERVER == serverItem.getRoleType().intValue()) { | ||
184 | + serverHolder.registryServer(serverItem); | ||
185 | + }else if(AnalysisHeartbeatInstanceRepository.ROLE_TYPE_CLIENT == serverItem.getRoleType().intValue()) { | ||
186 | + clientHolder.registryClient(serverItem); | ||
187 | + }else { | ||
188 | + throw new RuntimeException("不支持的实例角色,INSTANCE:"+JSONObject.toJSONString(serverItem)); | ||
189 | + } | ||
190 | + } | ||
191 | + | ||
192 | + private void unregistryRuntimeInstance(AnalysisHeartbeatInstanceEntity serverItem) throws Exception { | ||
193 | + if(AnalysisHeartbeatInstanceRepository.ROLE_TYPE_SERVER == serverItem.getRoleType().intValue()) { | ||
194 | + serverHolder.unregistryServer(serverItem.getCode()); | ||
195 | + }else if(AnalysisHeartbeatInstanceRepository.ROLE_TYPE_CLIENT == serverItem.getRoleType().intValue()) { | ||
196 | + clientHolder.unregistryClient(serverItem.getCode()); | ||
197 | + }else { | ||
198 | + throw new RuntimeException("不支持的实例角色,INSTANCE:"+JSONObject.toJSONString(serverItem)); | ||
199 | + } | ||
200 | + } | ||
201 | + | ||
202 | + @Override | ||
203 | + public void createInstance(HeartbeatInstanceCreateForm form) { | ||
204 | + form.trimByRegexS(); | ||
205 | + this.checkCreateForm(form); | ||
206 | + AnalysisHeartbeatInstanceEntity instance = this.constructInstance(form); | ||
207 | + Number id = this.analysisHeartbeatInstanceRepository.addEntity(instance, null); | ||
208 | + try { | ||
209 | + this.registryRuntimeInstance(this.analysisHeartbeatInstanceRepository.findEntityByID(id.longValue(), null)); | ||
210 | + }catch (Exception e) { | ||
211 | + UtilLog.error("注册监控实例出现异常,code["+instance.getCode()+"]", e, this.getClass()); | ||
212 | + } | ||
213 | + } | ||
214 | + | ||
215 | + private void checkCreateForm(HeartbeatInstanceCreateForm form) { | ||
216 | + if(form.getCode() == null) { | ||
217 | + throw new RuntimeException("未传入code"); | ||
218 | + } | ||
219 | + if(form.getFixRateSec() == null) { | ||
220 | + throw new RuntimeException("未传入检查间隔(秒)"); | ||
221 | + } | ||
222 | + if(form.getMaxWaitSec() == null) { | ||
223 | + throw new RuntimeException("未传入最大等待时间(秒)"); | ||
224 | + } | ||
225 | + if(form.getRoleType() == null) { | ||
226 | + throw new RuntimeException("未传入实例类型"); | ||
227 | + } | ||
228 | + | ||
229 | + } | ||
230 | + | ||
231 | + private AnalysisHeartbeatInstanceEntity constructInstance(HeartbeatInstanceCreateForm form) { | ||
232 | + AnalysisHeartbeatInstanceEntity instance = new AnalysisHeartbeatInstanceEntity(); | ||
233 | + instance.setCode(form.getCode()); | ||
234 | + if(form.getDeployAtLostNum() != null) { | ||
235 | + instance.setDeployAtLostNum(form.getDeployAtLostNum()); | ||
236 | + } | ||
237 | + if(form.getDeployUrl() != null) { | ||
238 | + instance.setDeployUrl(form.getDeployUrl()); | ||
239 | + } | ||
240 | + if(form.getFixRateSec() != null) { | ||
241 | + instance.setFixRateSec(form.getFixRateSec()); | ||
242 | + } | ||
243 | + if(form.getMaxWaitSec() != null) { | ||
244 | + instance.setMaxWaitSec(form.getMaxWaitSec()); | ||
245 | + } | ||
246 | + if(form.getReformEmail() != null) { | ||
247 | + instance.setReformEmail(form.getReformEmail()); | ||
248 | + } | ||
249 | + if(form.getReformMaxTime() != null) { | ||
250 | + instance.setReformMaxTime(form.getReformMaxTime()); | ||
251 | + } | ||
252 | + if(form.getReformPhone() != null) { | ||
253 | + instance.setReformPhone(form.getReformPhone()); | ||
254 | + } | ||
255 | + if(form.getReformWxid() != null) { | ||
256 | + instance.setReformWxid(form.getReformWxid()); | ||
257 | + } | ||
258 | + if(form.getRoleType() != null) { | ||
259 | + instance.setRoleType(form.getRoleType()); | ||
260 | + } | ||
261 | + if(form.getStatus() != null) { | ||
262 | + instance.setStatus(form.getStatus()); | ||
263 | + } | ||
264 | + if(form.getUrl() != null) { | ||
265 | + instance.setUrl(form.getUrl()); | ||
266 | + } | ||
267 | + if(form.getToken() != null) { | ||
268 | + instance.setToken(form.getToken()); | ||
269 | + } | ||
270 | + return instance; | ||
271 | + } | ||
272 | + | ||
273 | + @Override | ||
274 | + public void updateInstance(HeartbeatInstanceUpdateForm form) { | ||
275 | + form.trimByRegexS(); | ||
276 | + AnalysisHeartbeatInstanceEntity instance = null; | ||
277 | + try { | ||
278 | + instance = this.analysisHeartbeatInstanceRepository.findEntityBySql("code='"+form.getCode()+"'", null); | ||
279 | + } catch (NotFoundException | MultiRowException e1) { | ||
280 | + throw new RuntimeException("code="+form.getCode()+"对应的实例数据异常(未找到或存在多条重复记录),请技术人员核实"); | ||
281 | + } | ||
282 | + this.analysisHeartbeatInstanceRepository.updateEntityById(form.getSQLUpdateList(), instance.getId(), null); | ||
283 | + try { | ||
284 | + if(AnalysisHeartbeatInstanceRepository.STATUS_DISABLE == instance.getStatus().intValue()) { | ||
285 | + this.unregistryRuntimeInstance(instance); | ||
286 | + }else { | ||
287 | + this.registryRuntimeInstance(instance); | ||
288 | + } | ||
289 | + }catch (Exception e) { | ||
290 | + UtilLog.error("注销监控实例出现异常,code["+instance.getCode()+"]", e, this.getClass()); | ||
291 | + } | ||
292 | + } | ||
293 | + | ||
294 | + @Override | ||
295 | + public void disableInstanceByCode(String code) { | ||
296 | + AnalysisHeartbeatInstanceEntity instance = null; | ||
297 | + try { | ||
298 | + instance = this.analysisHeartbeatInstanceRepository.findEntityBySql("code='"+code+"'", null); | ||
299 | + } catch (NotFoundException | MultiRowException e1) { | ||
300 | + throw new RuntimeException("code="+code+"对应的实例数据异常(未找到或存在多条重复记录),请技术人员核实"); | ||
301 | + } | ||
302 | + List<Object[]> updateList = new ArrayList<Object[]>(1); | ||
303 | + updateList.add(new Object[] {"status", AnalysisHeartbeatInstanceRepository.STATUS_DISABLE}); | ||
304 | + this.analysisHeartbeatInstanceRepository.updateEntityById(updateList, instance.getId(), null); | ||
305 | + try { | ||
306 | + this.unregistryRuntimeInstance(instance); | ||
307 | + }catch (Exception e) { | ||
308 | + UtilLog.error("注销监控实例出现异常,code["+instance.getCode()+"]", e, this.getClass()); | ||
309 | + } | ||
310 | + } | ||
311 | + | ||
312 | + @Override | ||
313 | + public void enableInstanceByCode(String code) { | ||
314 | + AnalysisHeartbeatInstanceEntity instance = null; | ||
315 | + try { | ||
316 | + instance = this.analysisHeartbeatInstanceRepository.findEntityBySql("code='"+code+"'", null); | ||
317 | + } catch (NotFoundException | MultiRowException e1) { | ||
318 | + throw new RuntimeException("code="+code+"对应的实例数据异常(未找到或存在多条重复记录),请技术人员核实"); | ||
319 | + } | ||
320 | + List<Object[]> updateList = new ArrayList<Object[]>(1); | ||
321 | + updateList.add(new Object[] {"status", AnalysisHeartbeatInstanceRepository.STATUS_ENABLE}); | ||
322 | + this.analysisHeartbeatInstanceRepository.updateEntityById(updateList, instance.getId(), null); | ||
323 | + try { | ||
324 | + this.registryRuntimeInstance(instance); | ||
325 | + }catch (Exception e) { | ||
326 | + UtilLog.error("注销监控实例出现异常,code["+instance.getCode()+"]", e, this.getClass()); | ||
327 | + } | ||
328 | + } | ||
329 | +} |
src/main/java/com/taover/bazhuayun/analysis/web/module/heartbeat/bean/ClientInstance.java
0 → 100644
@@ -0,0 +1,90 @@ | @@ -0,0 +1,90 @@ | ||
1 | +package com.taover.bazhuayun.analysis.web.module.heartbeat.bean; | ||
2 | + | ||
3 | +import com.taover.bazhuayun.analysis.web.repository.AnalysisHeartbeatInstanceEntity; | ||
4 | +import com.taover.util.UtilLog; | ||
5 | + | ||
6 | +public class ClientInstance implements Instance{ | ||
7 | + private AnalysisHeartbeatInstanceEntity instance; | ||
8 | + private ClientRequest lastestClientRequest; | ||
9 | + private long lastestServerUnixtime = System.currentTimeMillis()/1000; | ||
10 | + private long currFlushServerUnixtimeBaseline = 0L; | ||
11 | + private int lostClientRequestCount = 0; | ||
12 | + private boolean detectNewLost = false; | ||
13 | + | ||
14 | + public ClientInstance(AnalysisHeartbeatInstanceEntity instance) { | ||
15 | + this.instance = instance; | ||
16 | + } | ||
17 | + | ||
18 | + @Override | ||
19 | + public void flush() { | ||
20 | + //还未收到请求,则无需刷新失败次数 | ||
21 | + if(lastestClientRequest == null) { | ||
22 | + return; | ||
23 | + } | ||
24 | + | ||
25 | + this.detectNewLost = false; | ||
26 | + this.currFlushServerUnixtimeBaseline = System.currentTimeMillis()/1000; | ||
27 | + //通过服务器时间,判断是否超时未收到客户端请求 | ||
28 | + if(isNewLoopForFixRateSec()) { | ||
29 | + ++this.lostClientRequestCount; | ||
30 | + this.detectNewLost = true; | ||
31 | + | ||
32 | + UtilLog.infoForMessage("检测到超时未收到请求,code["+this.getIdentity()+"],丢包统计["+this.lostClientRequestCount+"]", ServerInstance.class); | ||
33 | + } | ||
34 | + } | ||
35 | + | ||
36 | + private boolean isNewLoopForFixRateSec() { | ||
37 | + return ((this.currFlushServerUnixtimeBaseline-this.lastestServerUnixtime) / this.instance.getFixRateSec()) > this.lostClientRequestCount; | ||
38 | + } | ||
39 | + | ||
40 | + @Override | ||
41 | + public boolean needReform() { | ||
42 | + return this.detectNewLost && this.lostClientRequestCount>=1 && this.lostClientRequestCount<=this.instance.getReformMaxTime(); | ||
43 | + } | ||
44 | + | ||
45 | + @Override | ||
46 | + public boolean needDeploy() { | ||
47 | + return this.detectNewLost && this.lostClientRequestCount == this.instance.getDeployAtLostNum(); | ||
48 | + } | ||
49 | + | ||
50 | + public long getLastestServerUnixtime() { | ||
51 | + return lastestServerUnixtime; | ||
52 | + } | ||
53 | + | ||
54 | + public int getLostClientRequestCount() { | ||
55 | + return lostClientRequestCount; | ||
56 | + } | ||
57 | + | ||
58 | + public ClientRequest getLastestClientRequest() { | ||
59 | + return lastestClientRequest; | ||
60 | + } | ||
61 | + | ||
62 | + public AnalysisHeartbeatInstanceEntity getInstance() { | ||
63 | + return instance; | ||
64 | + } | ||
65 | + | ||
66 | + public void dealClientRequest(ClientRequest clientRequest) { | ||
67 | + if(this.instance.getFixRateSec() == null) { | ||
68 | + this.instance.setFixRateSec(Instance.DEFAULT_FIX_RATE_SEC); | ||
69 | + } | ||
70 | + if(this.instance.getMaxWaitSec() == null) { | ||
71 | + this.instance.setMaxWaitSec(Instance.DEFAULT_MAX_WAIT_SEC); | ||
72 | + } | ||
73 | + this.lastestClientRequest = clientRequest; | ||
74 | + this.lastestServerUnixtime = System.currentTimeMillis()/1000; | ||
75 | + this.lostClientRequestCount = 0; | ||
76 | + } | ||
77 | + | ||
78 | + @Override | ||
79 | + public String getIdentity() { | ||
80 | + return this.instance.getCode(); | ||
81 | + } | ||
82 | + | ||
83 | + public long getUnixtime() { | ||
84 | + if(this.lastestClientRequest == null) { | ||
85 | + return this.lastestServerUnixtime; | ||
86 | + }else { | ||
87 | + return this.lastestClientRequest.getUnixtime(); | ||
88 | + } | ||
89 | + } | ||
90 | +} |
src/main/java/com/taover/bazhuayun/analysis/web/module/heartbeat/bean/ClientRequest.java
0 → 100644
@@ -0,0 +1,63 @@ | @@ -0,0 +1,63 @@ | ||
1 | +package com.taover.bazhuayun.analysis.web.module.heartbeat.bean; | ||
2 | + | ||
3 | +import javax.servlet.http.HttpServletRequest; | ||
4 | + | ||
5 | +public class ClientRequest { | ||
6 | + private String code = ""; | ||
7 | + private String ip = ""; | ||
8 | + private long unixtime; | ||
9 | + private String seckey = ""; | ||
10 | + | ||
11 | + public String getCode() { | ||
12 | + return code; | ||
13 | + } | ||
14 | + public void setCode(String code) { | ||
15 | + this.code = code; | ||
16 | + } | ||
17 | + public String getIp() { | ||
18 | + return ip; | ||
19 | + } | ||
20 | + public void setIp(String ip) { | ||
21 | + this.ip = ip; | ||
22 | + } | ||
23 | + public long getUnixtime() { | ||
24 | + return unixtime; | ||
25 | + } | ||
26 | + public void setUnixtime(long unixtime) { | ||
27 | + this.unixtime = unixtime; | ||
28 | + } | ||
29 | + public String getSeckey() { | ||
30 | + return seckey; | ||
31 | + } | ||
32 | + public void setSeckey(String seckey) { | ||
33 | + this.seckey = seckey; | ||
34 | + } | ||
35 | + | ||
36 | + public ClientRequest(String code, String ip, long unixtime, String seckey) { | ||
37 | + this.code = code; | ||
38 | + this.ip = ip; | ||
39 | + this.unixtime = unixtime; | ||
40 | + this.seckey = seckey; | ||
41 | + } | ||
42 | + | ||
43 | + public ClientRequest(ClientRequest clientRequest) { | ||
44 | + this.code = clientRequest.getCode(); | ||
45 | + this.ip = clientRequest.getIp(); | ||
46 | + this.unixtime = clientRequest.getUnixtime(); | ||
47 | + this.seckey = clientRequest.getSeckey(); | ||
48 | + } | ||
49 | + | ||
50 | + public static ClientRequest createClientRequest(HttpServletRequest request) { | ||
51 | + String code = request.getParameter("code"); | ||
52 | + String unixtime = request.getParameter("unixtime"); | ||
53 | + String seckey = request.getParameter("seckey"); | ||
54 | + String ip = request.getRemoteHost(); | ||
55 | + return new ClientRequest(code, ip, | ||
56 | + unixtime==null?0L:Long.valueOf(unixtime), | ||
57 | + seckey); | ||
58 | + } | ||
59 | + | ||
60 | + public String getIdentity() { | ||
61 | + return this.code; | ||
62 | + } | ||
63 | +} |
src/main/java/com/taover/bazhuayun/analysis/web/module/heartbeat/bean/Instance.java
0 → 100644
@@ -0,0 +1,37 @@ | @@ -0,0 +1,37 @@ | ||
1 | +package com.taover.bazhuayun.analysis.web.module.heartbeat.bean; | ||
2 | + | ||
3 | +import com.taover.bazhuayun.analysis.web.repository.AnalysisHeartbeatInstanceEntity; | ||
4 | + | ||
5 | +public interface Instance { | ||
6 | + public static final int DEFAULT_MAX_WAIT_SEC = -1; | ||
7 | + public static final int DEFAULT_FIX_RATE_SEC = -1; | ||
8 | + | ||
9 | + /** | ||
10 | + * 实例 | ||
11 | + * @return | ||
12 | + */ | ||
13 | + AnalysisHeartbeatInstanceEntity getInstance(); | ||
14 | + | ||
15 | + /** | ||
16 | + * 获取id字符串 | ||
17 | + * @return | ||
18 | + */ | ||
19 | + String getIdentity(); | ||
20 | + | ||
21 | + /** | ||
22 | + * 是否需要发送通知 | ||
23 | + * @return | ||
24 | + */ | ||
25 | + boolean needReform(); | ||
26 | + | ||
27 | + /** | ||
28 | + * 是否需要发布 | ||
29 | + * @return | ||
30 | + */ | ||
31 | + boolean needDeploy(); | ||
32 | + | ||
33 | + /** | ||
34 | + * 刷新状态 | ||
35 | + */ | ||
36 | + void flush(); | ||
37 | +} |
src/main/java/com/taover/bazhuayun/analysis/web/module/heartbeat/bean/ServerInstance.java
0 → 100644
@@ -0,0 +1,119 @@ | @@ -0,0 +1,119 @@ | ||
1 | +package com.taover.bazhuayun.analysis.web.module.heartbeat.bean; | ||
2 | + | ||
3 | +import java.net.SocketTimeoutException; | ||
4 | + | ||
5 | +import com.taover.bazhuayun.analysis.web.repository.AnalysisHeartbeatInstanceEntity; | ||
6 | +import com.taover.util.UtilEncrypt; | ||
7 | +import com.taover.util.UtilHttpByOkHttp; | ||
8 | +import com.taover.util.UtilLog; | ||
9 | + | ||
10 | +public class ServerInstance implements Instance { | ||
11 | + private AnalysisHeartbeatInstanceEntity instance; | ||
12 | + private ServerResponse latestServerResponse; | ||
13 | + private long latestRequestUnixtime = -1; | ||
14 | + private long serverUnixtimeBaseline = 0L; | ||
15 | + private int errorServerResponseCount = 0; | ||
16 | + private boolean detectNewErrorServerResponse; | ||
17 | + private boolean isSendNewHeartbeat; | ||
18 | + private String latestUrlWithParam; | ||
19 | + | ||
20 | + public ServerInstance(AnalysisHeartbeatInstanceEntity instance) throws Exception { | ||
21 | + super(); | ||
22 | + if(!instance.getUrl().toLowerCase().startsWith("http")) { | ||
23 | + throw new Exception("目前只支持http协议的URL"); | ||
24 | + } | ||
25 | + if(instance.getFixRateSec() < 60) { | ||
26 | + throw new Exception("固定时间间隔不允许小于60s"); | ||
27 | + } | ||
28 | + this.instance = instance; | ||
29 | + } | ||
30 | + | ||
31 | + @Override | ||
32 | + public void flush() { | ||
33 | + this.serverUnixtimeBaseline = System.currentTimeMillis()/1000; | ||
34 | + this.detectNewErrorServerResponse = false; | ||
35 | + this.isSendNewHeartbeat = false; | ||
36 | + | ||
37 | + //如果小于设置的发送时间间隔,则不发送请求 | ||
38 | + if(!this.isNewLoopForFixRateSec()) { | ||
39 | + return; | ||
40 | + } | ||
41 | + | ||
42 | + this.latestRequestUnixtime = this.serverUnixtimeBaseline; | ||
43 | + try { | ||
44 | + this.isSendNewHeartbeat = true; | ||
45 | + this.latestUrlWithParam = this.instance.getUrl() + this.getUrlParams(); | ||
46 | + UtilLog.infoForMessage("向code["+this.getIdentity()+"],url["+this.latestUrlWithParam+"]发送心跳请求", ServerInstance.class); | ||
47 | + | ||
48 | + this.latestServerResponse = ServerResponse.createByJSONString(UtilHttpByOkHttp.sendGet(this.latestUrlWithParam, null, this.instance.getMaxWaitSec())); | ||
49 | + if(this.latestServerResponse.isCodeOk()) { | ||
50 | + this.errorServerResponseCount = 0; | ||
51 | + } | ||
52 | + } catch(SocketTimeoutException timeError) { | ||
53 | + this.latestServerResponse = ServerResponse.createOverdue(); | ||
54 | + } catch (Exception e) { | ||
55 | + this.latestServerResponse = ServerResponse.createException(e); | ||
56 | + } | ||
57 | + | ||
58 | + //判断响应是否正常 | ||
59 | + if(this.latestServerResponse.isOverdue() || !this.latestServerResponse.isCodeOk()) { | ||
60 | + ++this.errorServerResponseCount; | ||
61 | + this.detectNewErrorServerResponse = true; | ||
62 | + } | ||
63 | + } | ||
64 | + | ||
65 | + private String getUrlParams() { | ||
66 | + long time = this.serverUnixtimeBaseline; | ||
67 | + String seckey = UtilEncrypt.MD5Lower32(this.instance.getCode()+time+this.instance.getToken()); | ||
68 | + return "?code="+this.instance.getCode()+"&fixRateSec="+this.instance.getFixRateSec()+"&maxWaitSec="+this.instance.getMaxWaitSec()+"&unixtime="+time+"&seckey="+seckey; | ||
69 | + } | ||
70 | + | ||
71 | + private boolean isNewLoopForFixRateSec() { | ||
72 | + return ((this.serverUnixtimeBaseline-this.latestRequestUnixtime)/this.instance.getFixRateSec()) > this.errorServerResponseCount; | ||
73 | + } | ||
74 | + | ||
75 | + public AnalysisHeartbeatInstanceEntity getInstance() { | ||
76 | + return instance; | ||
77 | + } | ||
78 | + | ||
79 | + @Override | ||
80 | + public String getIdentity() { | ||
81 | + return this.instance.getCode(); | ||
82 | + } | ||
83 | + | ||
84 | + @Override | ||
85 | + public boolean needDeploy() { | ||
86 | + return this.detectNewErrorServerResponse && this.errorServerResponseCount == this.instance.getDeployAtLostNum(); | ||
87 | + } | ||
88 | + | ||
89 | + @Override | ||
90 | + public boolean needReform() { | ||
91 | + return this.detectNewErrorServerResponse | ||
92 | + && this.errorServerResponseCount>=1 | ||
93 | + && this.errorServerResponseCount<=this.instance.getReformMaxTime(); | ||
94 | + } | ||
95 | + | ||
96 | + public long getLatestRequestUnixtime() { | ||
97 | + return latestRequestUnixtime; | ||
98 | + } | ||
99 | + | ||
100 | + public ServerResponse getLatestServerResponse() { | ||
101 | + return latestServerResponse; | ||
102 | + } | ||
103 | + | ||
104 | + public int getErrorServerResponseCount() { | ||
105 | + return errorServerResponseCount; | ||
106 | + } | ||
107 | + | ||
108 | + public boolean isIncrErrorServerResponseCount() { | ||
109 | + return detectNewErrorServerResponse; | ||
110 | + } | ||
111 | + | ||
112 | + public boolean isSendNewHeartbeat() { | ||
113 | + return isSendNewHeartbeat; | ||
114 | + } | ||
115 | + | ||
116 | + public String getLatestUrlWithParam() { | ||
117 | + return latestUrlWithParam; | ||
118 | + } | ||
119 | +} |
src/main/java/com/taover/bazhuayun/analysis/web/module/heartbeat/bean/ServerResponse.java
0 → 100644
@@ -0,0 +1,79 @@ | @@ -0,0 +1,79 @@ | ||
1 | +package com.taover.bazhuayun.analysis.web.module.heartbeat.bean; | ||
2 | + | ||
3 | +import org.apache.commons.lang.StringUtils; | ||
4 | + | ||
5 | +import com.alibaba.fastjson.JSONObject; | ||
6 | + | ||
7 | +public class ServerResponse { | ||
8 | + public static String RESPONSE_CODE_OK = "ok"; | ||
9 | + | ||
10 | + private boolean isOverdue; | ||
11 | + private boolean isCodeOk; | ||
12 | + private String responseContent; | ||
13 | + private Exception exception; | ||
14 | + | ||
15 | + private ServerResponse(boolean isOverdue, boolean isCodeOk, String responseContent, Exception e) { | ||
16 | + super(); | ||
17 | + this.isOverdue = isOverdue; | ||
18 | + this.isCodeOk = isCodeOk; | ||
19 | + this.responseContent = responseContent; | ||
20 | + this.exception = e; | ||
21 | + } | ||
22 | + | ||
23 | + public boolean isOverdue() { | ||
24 | + return isOverdue; | ||
25 | + } | ||
26 | + public void setOverdue(boolean isOverdue) { | ||
27 | + this.isOverdue = isOverdue; | ||
28 | + } | ||
29 | + public boolean isCodeOk() { | ||
30 | + return isCodeOk; | ||
31 | + } | ||
32 | + public void setCodeOk(boolean isCodeOk) { | ||
33 | + this.isCodeOk = isCodeOk; | ||
34 | + } | ||
35 | + public String getResponseContent() { | ||
36 | + return responseContent; | ||
37 | + } | ||
38 | + public void setResponseContent(String responseContent) { | ||
39 | + this.responseContent = responseContent; | ||
40 | + } | ||
41 | + public Exception getException() { | ||
42 | + return exception; | ||
43 | + } | ||
44 | + public void setException(Exception exception) { | ||
45 | + this.exception = exception; | ||
46 | + } | ||
47 | + | ||
48 | + public static ServerResponse createByJSONString(String response) { | ||
49 | + if(StringUtils.isBlank(response)) { | ||
50 | + return new ServerResponse(false, false, response, null); | ||
51 | + }else { | ||
52 | + try { | ||
53 | + JSONObject data = JSONObject.parseObject(response); | ||
54 | + String code = data.getString("code"); | ||
55 | + if(RESPONSE_CODE_OK.equals(code.toLowerCase())) { | ||
56 | + return new ServerResponse(false, true, response, null); | ||
57 | + }else { | ||
58 | + return new ServerResponse(false, false, response, null); | ||
59 | + } | ||
60 | + }catch (Exception e) { | ||
61 | + return new ServerResponse(false, false, response, e); | ||
62 | + } | ||
63 | + } | ||
64 | + } | ||
65 | + | ||
66 | + public static ServerResponse createOverdue() { | ||
67 | + return new ServerResponse(false, false, "", null); | ||
68 | + } | ||
69 | + | ||
70 | + public static ServerResponse createException(Exception e) { | ||
71 | + return new ServerResponse(false, false, "", e); | ||
72 | + } | ||
73 | + | ||
74 | + @Override | ||
75 | + public String toString() { | ||
76 | + return "ServerResponse [isOverdue=" + isOverdue + ", isCodeOk=" + isCodeOk + ", responseContent=" | ||
77 | + + responseContent + ", exception=" + (exception==null?"":exception.getMessage()) + "]"; | ||
78 | + } | ||
79 | +} |
src/main/java/com/taover/bazhuayun/analysis/web/module/heartbeat/holder/ClientHolder.java
0 → 100644
@@ -0,0 +1,21 @@ | @@ -0,0 +1,21 @@ | ||
1 | +package com.taover.bazhuayun.analysis.web.module.heartbeat.holder; | ||
2 | + | ||
3 | +import java.util.List; | ||
4 | + | ||
5 | +import com.taover.bazhuayun.analysis.web.module.heartbeat.bean.ClientInstance; | ||
6 | +import com.taover.bazhuayun.analysis.web.module.heartbeat.bean.ClientRequest; | ||
7 | +import com.taover.bazhuayun.analysis.web.repository.AnalysisHeartbeatInstanceEntity; | ||
8 | + | ||
9 | +public interface ClientHolder { | ||
10 | + void dealClientRequest(ClientRequest clientRequest, AnalysisHeartbeatInstanceEntity instance); | ||
11 | + | ||
12 | + void registryClient(AnalysisHeartbeatInstanceEntity instance); | ||
13 | + | ||
14 | + List<ClientInstance> getClientInstanceList(); | ||
15 | + | ||
16 | + void flushClientStatus(ClientInstance clientInstance); | ||
17 | + | ||
18 | + void unregistryClient(String code); | ||
19 | + | ||
20 | + boolean containInstanceCode(String code); | ||
21 | +} |
src/main/java/com/taover/bazhuayun/analysis/web/module/heartbeat/holder/ClientHolderImpl.java
0 → 100644
@@ -0,0 +1,71 @@ | @@ -0,0 +1,71 @@ | ||
1 | +package com.taover.bazhuayun.analysis.web.module.heartbeat.holder; | ||
2 | + | ||
3 | +import java.util.ArrayList; | ||
4 | +import java.util.List; | ||
5 | +import java.util.Map; | ||
6 | +import java.util.concurrent.ConcurrentHashMap; | ||
7 | + | ||
8 | +import org.apache.commons.lang.StringUtils; | ||
9 | + | ||
10 | +import com.taover.bazhuayun.analysis.web.module.heartbeat.bean.ClientInstance; | ||
11 | +import com.taover.bazhuayun.analysis.web.module.heartbeat.bean.ClientRequest; | ||
12 | +import com.taover.bazhuayun.analysis.web.repository.AnalysisHeartbeatInstanceEntity; | ||
13 | +import com.taover.util.UtilEncrypt; | ||
14 | + | ||
15 | +public class ClientHolderImpl implements ClientHolder{ | ||
16 | + Map<String, ClientInstance> clientMap = new ConcurrentHashMap<String, ClientInstance>(); | ||
17 | + | ||
18 | + @Override | ||
19 | + public List<ClientInstance> getClientInstanceList() { | ||
20 | + return new ArrayList<ClientInstance>(clientMap.values()); | ||
21 | + } | ||
22 | + | ||
23 | + @Override | ||
24 | + public void flushClientStatus(ClientInstance clientInstance) { | ||
25 | + clientInstance.flush(); | ||
26 | + } | ||
27 | + | ||
28 | + @Override | ||
29 | + public void dealClientRequest(ClientRequest clientRequest, AnalysisHeartbeatInstanceEntity instance) { | ||
30 | + this.validClientRequest(clientRequest, instance.getToken()); | ||
31 | + synchronized (this.clientMap) { | ||
32 | + ClientInstance client = null; | ||
33 | + if(clientMap.containsKey(clientRequest.getIdentity())) { | ||
34 | + client = clientMap.get(clientRequest.getIdentity()); | ||
35 | + clientMap.put(client.getIdentity(), client); | ||
36 | + }else { | ||
37 | + throw new RuntimeException("找不到code="+clientRequest.getIdentity()+"的监控实例"); | ||
38 | + } | ||
39 | + client.dealClientRequest(clientRequest); | ||
40 | + } | ||
41 | + } | ||
42 | + | ||
43 | + private void validClientRequest(ClientRequest clientRequest, String token) { | ||
44 | + long time = clientRequest.getUnixtime(); | ||
45 | + String seckey = UtilEncrypt.MD5Lower32(clientRequest.getCode()+time+token); | ||
46 | + if(StringUtils.isBlank(clientRequest.getCode())) { | ||
47 | + throw new RuntimeException("未传入code信息"); | ||
48 | + } | ||
49 | + if(!seckey.equals(clientRequest.getSeckey())) { | ||
50 | + throw new RuntimeException("秘钥信息检查失败"); | ||
51 | + } | ||
52 | + } | ||
53 | + | ||
54 | + @Override | ||
55 | + public void registryClient(AnalysisHeartbeatInstanceEntity instance) { | ||
56 | + synchronized (this.clientMap) { | ||
57 | + ClientInstance client = new ClientInstance(instance); | ||
58 | + clientMap.put(client.getIdentity(), client); | ||
59 | + } | ||
60 | + } | ||
61 | + | ||
62 | + @Override | ||
63 | + public void unregistryClient(String code) { | ||
64 | + clientMap.remove(code); | ||
65 | + } | ||
66 | + | ||
67 | + @Override | ||
68 | + public boolean containInstanceCode(String code) { | ||
69 | + return clientMap.containsKey(code); | ||
70 | + } | ||
71 | +} |
src/main/java/com/taover/bazhuayun/analysis/web/module/heartbeat/holder/ServerHolder.java
0 → 100644
@@ -0,0 +1,16 @@ | @@ -0,0 +1,16 @@ | ||
1 | +package com.taover.bazhuayun.analysis.web.module.heartbeat.holder; | ||
2 | + | ||
3 | +import java.util.List; | ||
4 | + | ||
5 | +import com.taover.bazhuayun.analysis.web.module.heartbeat.bean.ServerInstance; | ||
6 | +import com.taover.bazhuayun.analysis.web.repository.AnalysisHeartbeatInstanceEntity; | ||
7 | + | ||
8 | +public interface ServerHolder { | ||
9 | + List<ServerInstance> getServerInstanceList(); | ||
10 | + | ||
11 | + void registryServer(AnalysisHeartbeatInstanceEntity instance) throws Exception; | ||
12 | + | ||
13 | + void flushServerStatus(ServerInstance serverInstance); | ||
14 | + | ||
15 | + void unregistryServer(String code); | ||
16 | +} |
src/main/java/com/taover/bazhuayun/analysis/web/module/heartbeat/holder/ServerHolderImpl.java
0 → 100644
@@ -0,0 +1,34 @@ | @@ -0,0 +1,34 @@ | ||
1 | +package com.taover.bazhuayun.analysis.web.module.heartbeat.holder; | ||
2 | + | ||
3 | +import java.util.ArrayList; | ||
4 | +import java.util.List; | ||
5 | +import java.util.Map; | ||
6 | +import java.util.concurrent.ConcurrentHashMap; | ||
7 | + | ||
8 | +import com.taover.bazhuayun.analysis.web.module.heartbeat.bean.ServerInstance; | ||
9 | +import com.taover.bazhuayun.analysis.web.repository.AnalysisHeartbeatInstanceEntity; | ||
10 | + | ||
11 | +public class ServerHolderImpl implements ServerHolder { | ||
12 | + Map<String, ServerInstance> serverMap = new ConcurrentHashMap<String, ServerInstance>(); | ||
13 | + | ||
14 | + @Override | ||
15 | + public List<ServerInstance> getServerInstanceList() { | ||
16 | + return new ArrayList<ServerInstance>(serverMap.values()); | ||
17 | + } | ||
18 | + | ||
19 | + @Override | ||
20 | + public void registryServer(AnalysisHeartbeatInstanceEntity instance) throws Exception { | ||
21 | + ServerInstance server = new ServerInstance(instance); | ||
22 | + serverMap.put(server.getIdentity(), server); | ||
23 | + } | ||
24 | + | ||
25 | + @Override | ||
26 | + public void flushServerStatus(ServerInstance serverInstance) { | ||
27 | + serverInstance.flush(); | ||
28 | + } | ||
29 | + | ||
30 | + @Override | ||
31 | + public void unregistryServer(String code) { | ||
32 | + serverMap.remove(code); | ||
33 | + } | ||
34 | +} |
src/main/java/com/taover/bazhuayun/analysis/web/module/heartbeat/service/HeartbeatDeployService.java
0 → 100644
src/main/java/com/taover/bazhuayun/analysis/web/module/heartbeat/service/HeartbeatDeployServiceImpl.java
0 → 100644
@@ -0,0 +1,46 @@ | @@ -0,0 +1,46 @@ | ||
1 | +package com.taover.bazhuayun.analysis.web.module.heartbeat.service; | ||
2 | + | ||
3 | +import javax.annotation.Resource; | ||
4 | + | ||
5 | +import org.apache.commons.lang3.StringUtils; | ||
6 | +import org.springframework.stereotype.Service; | ||
7 | + | ||
8 | +import com.taover.bazhuayun.analysis.web.module.heartbeat.bean.Instance; | ||
9 | +import com.taover.bazhuayun.analysis.web.repository.AnalysisHeartbeatReformEntity; | ||
10 | +import com.taover.bazhuayun.analysis.web.repository.AnalysisHeartbeatReformRepository; | ||
11 | +import com.taover.util.UtilHttpByOkHttp; | ||
12 | +import com.taover.util.UtilLog; | ||
13 | + | ||
14 | +@Service | ||
15 | +public class HeartbeatDeployServiceImpl implements HeartbeatDeployService { | ||
16 | + @Resource | ||
17 | + private AnalysisHeartbeatReformRepository analysisHeartbeatReformRepository; | ||
18 | + @Resource | ||
19 | + private HeartbeatReformService heartbeatReformService; | ||
20 | + | ||
21 | + private void createDeployLog(Instance instance, String response) { | ||
22 | + AnalysisHeartbeatReformEntity reform = new AnalysisHeartbeatReformEntity(); | ||
23 | + reform.setInstanceCode(instance.getIdentity()); | ||
24 | + reform.setReformContent(response); | ||
25 | + reform.setReformInfo("调用发布URL"); | ||
26 | + reform.setReformType(AnalysisHeartbeatReformRepository.REFORM_TYPE_WEIXIN); | ||
27 | + this.analysisHeartbeatReformRepository.addEntity(reform, null); | ||
28 | + } | ||
29 | + | ||
30 | + @Override | ||
31 | + public void sendDeploy(Instance item) { | ||
32 | + if(item.getInstance() == null || StringUtils.isBlank(item.getInstance().getDeployUrl())) { | ||
33 | + return; | ||
34 | + } | ||
35 | + String response = null; | ||
36 | + try { | ||
37 | + response = UtilHttpByOkHttp.sendGet(item.getInstance().getDeployUrl(), null); | ||
38 | + this.heartbeatReformService.sendReformDeploy(item); | ||
39 | + } catch (Exception e) { | ||
40 | + UtilLog.error("调用自动发布URL发生异常,发布URL["+item.getInstance().getDeployUrl()+"]", e, HeartbeatDeployServiceImpl.class); | ||
41 | + response = e.getMessage(); | ||
42 | + this.heartbeatReformService.sendErrorMsg(item, response); | ||
43 | + } | ||
44 | + this.createDeployLog(item, response); | ||
45 | + } | ||
46 | +} |
src/main/java/com/taover/bazhuayun/analysis/web/module/heartbeat/service/HeartbeatReformService.java
0 → 100644
@@ -0,0 +1,11 @@ | @@ -0,0 +1,11 @@ | ||
1 | +package com.taover.bazhuayun.analysis.web.module.heartbeat.service; | ||
2 | + | ||
3 | +import com.taover.bazhuayun.analysis.web.module.heartbeat.bean.Instance; | ||
4 | + | ||
5 | +public interface HeartbeatReformService { | ||
6 | + void sendReform(Instance item); | ||
7 | + | ||
8 | + void sendReformDeploy(Instance item); | ||
9 | + | ||
10 | + void sendErrorMsg(Instance item, String response); | ||
11 | +} |
src/main/java/com/taover/bazhuayun/analysis/web/module/heartbeat/service/HeartbeatReformServiceImpl.java
0 → 100644
@@ -0,0 +1,264 @@ | @@ -0,0 +1,264 @@ | ||
1 | +package com.taover.bazhuayun.analysis.web.module.heartbeat.service; | ||
2 | + | ||
3 | +import java.text.SimpleDateFormat; | ||
4 | +import java.util.Arrays; | ||
5 | +import java.util.Date; | ||
6 | + | ||
7 | +import javax.annotation.Resource; | ||
8 | + | ||
9 | +import org.apache.commons.lang3.StringUtils; | ||
10 | +import org.springframework.stereotype.Service; | ||
11 | + | ||
12 | +import com.alibaba.fastjson.JSON; | ||
13 | +import com.alibaba.fastjson.JSONObject; | ||
14 | +import com.taover.bazhuayun.analysis.web.module.heartbeat.bean.ClientInstance; | ||
15 | +import com.taover.bazhuayun.analysis.web.module.heartbeat.bean.Instance; | ||
16 | +import com.taover.bazhuayun.analysis.web.module.heartbeat.bean.ServerInstance; | ||
17 | +import com.taover.bazhuayun.analysis.web.repository.AnalysisHeartbeatInstanceEntity; | ||
18 | +import com.taover.bazhuayun.analysis.web.repository.AnalysisHeartbeatReformEntity; | ||
19 | +import com.taover.bazhuayun.analysis.web.repository.AnalysisHeartbeatReformRepository; | ||
20 | +import com.taover.util.UtilEmail; | ||
21 | +import com.taover.util.UtilLog; | ||
22 | +import com.taover.util.UtilWeixinMsg; | ||
23 | + | ||
24 | +@Service | ||
25 | +public class HeartbeatReformServiceImpl implements HeartbeatReformService { | ||
26 | + @Resource | ||
27 | + private AnalysisHeartbeatReformRepository analysisHeartbeatReformRepository; | ||
28 | + | ||
29 | + private void sendWarnWeixin(Instance instance, String weixinContent) { | ||
30 | + if(StringUtils.isBlank(instance.getInstance().getReformWxid())) { | ||
31 | + return; | ||
32 | + } | ||
33 | + try { | ||
34 | + String[] wxidArr = instance.getInstance().getReformWxid().split(","); | ||
35 | + for(String weixinWxid: wxidArr) { | ||
36 | + if(weixinWxid != null && !weixinWxid.trim().equals("")) { | ||
37 | + UtilWeixinMsg.sendTextMessage(weixinWxid, weixinContent); | ||
38 | + this.createWeixinReformLog(instance, weixinWxid, weixinContent); | ||
39 | + } | ||
40 | + } | ||
41 | + } catch (Exception e) { | ||
42 | + UtilLog.infoForMessage("发送微信消息失败,消息内容:"+weixinContent, this.getClass()); | ||
43 | + UtilLog.errorForException(e, this.getClass()); | ||
44 | + } | ||
45 | + } | ||
46 | + | ||
47 | + private void createWeixinReformLog(Instance instance, String weixinWxid, String weixinContent) { | ||
48 | + AnalysisHeartbeatReformEntity reform = new AnalysisHeartbeatReformEntity(); | ||
49 | + reform.setInstanceCode(instance.getIdentity()); | ||
50 | + reform.setReformContent(weixinContent); | ||
51 | + reform.setReformInfo(weixinWxid); | ||
52 | + reform.setReformType(AnalysisHeartbeatReformRepository.REFORM_TYPE_WEIXIN); | ||
53 | + this.analysisHeartbeatReformRepository.addEntity(reform, null); | ||
54 | + } | ||
55 | + | ||
56 | + private String formatWeixin(ServerInstance instance) { | ||
57 | + String htmlContent = ""; | ||
58 | + AnalysisHeartbeatInstanceEntity entity = instance.getInstance(); | ||
59 | + if(instance.getLatestServerResponse() == null) { | ||
60 | + htmlContent += " 未收到服务器响应\n"; | ||
61 | + }else { | ||
62 | + if(instance.getLatestServerResponse().isOverdue()) { | ||
63 | + htmlContent += " 向接口["+entity.getUrl()+"]发送请求,响应超时["+entity.getMaxWaitSec()+"s],请及时确认服务是否正常运行\n"; | ||
64 | + }else if(!instance.getLatestServerResponse().isCodeOk()) { | ||
65 | + htmlContent += " 向接口["+entity.getUrl()+"]发送请求,响应数据不正常(详细请查看邮件),请及时确认服务是否正常运行\n"; | ||
66 | + }else { | ||
67 | + htmlContent += " 向接口["+entity.getUrl()+"]发送请求,未知异常,请及时确认服务是否正常运行\n"; | ||
68 | + } | ||
69 | + } | ||
70 | + htmlContent += " 最后一次请求时间: "+new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date(instance.getLatestRequestUnixtime()*1000)); | ||
71 | + return htmlContent; | ||
72 | + } | ||
73 | + | ||
74 | + private String formatWeixin(ClientInstance instance) { | ||
75 | + String htmlContent = " 超过"+instance.getInstance().getFixRateSec()+"秒未收到请求,请确认CODE["+instance.getIdentity()+"]对应的服务是否运行正常\n"; | ||
76 | + htmlContent += " 客户端最后一次请求时间: "+new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date(instance.getLastestClientRequest().getUnixtime()*1000))+"\n"; | ||
77 | + htmlContent += " 累计次数("+instance.getInstance().getReformMaxTime()+"次后不再报警):"+instance.getLostClientRequestCount(); | ||
78 | + return htmlContent; | ||
79 | + } | ||
80 | + | ||
81 | + private void sendWarnEmail(Instance instance, String subject, String htmlContent) { | ||
82 | + if(StringUtils.isBlank(instance.getInstance().getReformEmail())) { | ||
83 | + return; | ||
84 | + } | ||
85 | + try { | ||
86 | + String[] emailArr = instance.getInstance().getReformEmail().split(","); | ||
87 | + if(emailArr.length == 0) { | ||
88 | + return; | ||
89 | + } | ||
90 | + UtilEmail.sendHtmlMail(Arrays.asList(emailArr), subject, htmlContent); | ||
91 | + this.createHtmlReformLog(instance, emailArr, subject, htmlContent); | ||
92 | + } catch (Exception e) { | ||
93 | + UtilLog.infoForMessage("发送邮件失败,消息内容:[标题:"+subject+"],[正文:"+htmlContent+"]", this.getClass()); | ||
94 | + UtilLog.errorForException(e, this.getClass()); | ||
95 | + } | ||
96 | + } | ||
97 | + | ||
98 | + private void createHtmlReformLog(Instance instance, String[] emailArr, String subject, String htmlContent) { | ||
99 | + AnalysisHeartbeatReformEntity reform = new AnalysisHeartbeatReformEntity(); | ||
100 | + reform.setInstanceCode(instance.getIdentity()); | ||
101 | + JSONObject data = new JSONObject(); | ||
102 | + data.put("subject", subject); | ||
103 | + data.put("content", htmlContent); | ||
104 | + reform.setReformContent(data.toJSONString()); | ||
105 | + reform.setReformInfo(StringUtils.join(emailArr, ",")); | ||
106 | + reform.setReformType(AnalysisHeartbeatReformRepository.REFORM_TYPE_EMAIL); | ||
107 | + this.analysisHeartbeatReformRepository.addEntity(reform, null); | ||
108 | + } | ||
109 | + | ||
110 | + private String formatHtml(ServerInstance instance) { | ||
111 | + String htmlContent = ""; | ||
112 | + htmlContent += "<h4 style=\"color:red;\">"; | ||
113 | + AnalysisHeartbeatInstanceEntity entity = instance.getInstance(); | ||
114 | + if(instance.getLatestServerResponse() != null) { | ||
115 | + if(instance.getLatestServerResponse().isOverdue()) { | ||
116 | + htmlContent += " 向接口["+entity.getUrl()+"]发送请求,响应超时["+entity.getMaxWaitSec()+"s],请及时确认服务是否正常运行"; | ||
117 | + }else if(!instance.getLatestServerResponse().isCodeOk()) { | ||
118 | + htmlContent += " 向接口["+entity.getUrl()+"]发送请求,响应数据不正常(详细请查看邮件),请及时确认服务是否正常运行"; | ||
119 | + }else { | ||
120 | + htmlContent += "未知异常"; | ||
121 | + } | ||
122 | + }else { | ||
123 | + htmlContent += "未记录最后一次响应记录"; | ||
124 | + } | ||
125 | + htmlContent += "</h4>"; | ||
126 | + htmlContent += "<ul>"; | ||
127 | + htmlContent += "<li>CODE: "+instance.getIdentity()+"</li>"; | ||
128 | + htmlContent += "<li>URL: "+entity.getUrl()+"</li>"; | ||
129 | + htmlContent += "<li>请求频率: "+entity.getFixRateSec()+"秒/次</li>"; | ||
130 | + htmlContent += "<li>请求最大等待时间: "+entity.getMaxWaitSec()+"秒</li>"; | ||
131 | + htmlContent += "<li>客户端请求时间戳: "+new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date(instance.getLatestRequestUnixtime()*1000))+"</li>"; | ||
132 | + htmlContent += "<li>最后一次收到的响应包: <span style=\"color:gray;\">"+JSON.toJSONString(instance.getLatestServerResponse())+"</span></li>"; | ||
133 | + htmlContent += "</ul>"; | ||
134 | + return htmlContent; | ||
135 | + } | ||
136 | + | ||
137 | + private String formatHtml(ClientInstance instance) { | ||
138 | + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); | ||
139 | + AnalysisHeartbeatInstanceEntity entity = instance.getInstance(); | ||
140 | + String htmlContent = ""; | ||
141 | + htmlContent += "<h4 style=\"color:red;\">"; | ||
142 | + htmlContent += "超过"+entity.getFixRateSec()+"秒未收到请求,请确认CODE["+instance.getIdentity()+"]对应的客户端是否运行正常<br />"; | ||
143 | + htmlContent += "客户端最后一次请求时间: "+new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date(instance.getUnixtime()*1000)); | ||
144 | + htmlContent += "</h4>"; | ||
145 | + htmlContent += "<ul>"; | ||
146 | + htmlContent += "<li>CODE: "+instance.getIdentity()+"</li>"; | ||
147 | + //htmlContent += "<li>IP: "+instance.getIp()+"</li>"; | ||
148 | + htmlContent += "<li>请求频率: "+entity.getFixRateSec()+"秒/次</li>"; | ||
149 | + htmlContent += "<li>请求最大等待时间: "+entity.getMaxWaitSec()+"秒</li>"; | ||
150 | + htmlContent += "<li>客户端请求时间戳: "+sdf.format(new Date(instance.getUnixtime()*1000))+"</li>"; | ||
151 | + htmlContent += "<li>服务器接收时间: "+sdf.format(new Date(instance.getLastestServerUnixtime()*1000))+"</li>"; | ||
152 | + htmlContent += "<li>最后一次收到的请求包: <span style=\"color:gray;\">"+JSON.toJSONString(instance.getLastestClientRequest())+"</span></li>"; | ||
153 | + htmlContent += "<li>累计次数("+entity.getReformMaxTime()+"次后不再报警):"+instance.getLostClientRequestCount()+"</li>"; | ||
154 | + htmlContent += "</ul>"; | ||
155 | + return htmlContent; | ||
156 | + } | ||
157 | + | ||
158 | + private String[] formatNormalEmailInfo(Instance instance) { | ||
159 | + String subject = "报警-项目可用性监控--监控ID["+instance.getIdentity()+"]"; | ||
160 | + String htmlContent = "<h2>监控ID:"+instance.getIdentity()+"</h2>"; | ||
161 | + if(instance instanceof ClientInstance) { | ||
162 | + htmlContent += this.formatHtml((ClientInstance)instance); | ||
163 | + }else if(instance instanceof ServerInstance) { | ||
164 | + htmlContent += this.formatHtml((ServerInstance)instance); | ||
165 | + }else { | ||
166 | + try { | ||
167 | + htmlContent += "<p>"+JSONObject.toJSONString(instance)+"</p>"; | ||
168 | + }catch (Exception e) { | ||
169 | + htmlContent += "<span style=\"color:red;\">对象无法序列化打印,instance.toString() ==>> "+instance.toString()+"</span>"; | ||
170 | + } | ||
171 | + } | ||
172 | + return new String[] {subject, htmlContent}; | ||
173 | + } | ||
174 | + | ||
175 | + @Override | ||
176 | + public void sendReform(Instance item) { | ||
177 | + String[] emailData = this.formatNormalEmailInfo(item); | ||
178 | + this.sendWarnEmail(item, emailData[0], emailData[1]); | ||
179 | + | ||
180 | + String weixinContent = this.formatNormalWeixinContent(item); | ||
181 | + this.sendWarnWeixin(item, weixinContent); | ||
182 | + } | ||
183 | + | ||
184 | + private String formatNormalWeixinContent(Instance instance) { | ||
185 | + String weixinContent = "报警-项目可用性监控\n"; | ||
186 | + if(instance instanceof ClientInstance) { | ||
187 | + weixinContent += this.formatWeixin((ClientInstance)instance); | ||
188 | + }else if(instance instanceof ServerInstance) { | ||
189 | + weixinContent += this.formatWeixin((ServerInstance)instance); | ||
190 | + }else { | ||
191 | + try { | ||
192 | + weixinContent += " JSON序列化:"+JSONObject.toJSONString(instance); | ||
193 | + }catch (Exception e) { | ||
194 | + weixinContent += " 对象无法序列化打印,instance.toString() ==>> "+instance.toString(); | ||
195 | + } | ||
196 | + } | ||
197 | + return weixinContent; | ||
198 | + } | ||
199 | + | ||
200 | + @Override | ||
201 | + public void sendReformDeploy(Instance item) { | ||
202 | + String[] emailData = this.formatDeployEmailInfo(item); | ||
203 | + this.sendWarnEmail(item, emailData[0], emailData[1]); | ||
204 | + | ||
205 | + String weixinContent = this.formatDelayWeixin(item); | ||
206 | + this.sendWarnWeixin(item, weixinContent); | ||
207 | + } | ||
208 | + | ||
209 | + private String formatDelayWeixin(Instance instance) { | ||
210 | + return "通知-项目可用性监控--自动发布任务\n" | ||
211 | + + " CODE["+instance.getIdentity()+"]对应的服务多次检查失败\n" | ||
212 | + + " 系统自动调度执行发布任务,服务怠机原因,请及时核实解决~"; | ||
213 | + } | ||
214 | + | ||
215 | + private String[] formatDeployEmailInfo(Instance instance) { | ||
216 | + String subject = "通知-项目可用性监控--执行发布任务["+instance.getIdentity()+"]"; | ||
217 | + String htmlContent = "<h2>监控ID:"+instance.getIdentity()+"</h2>"; | ||
218 | + if(instance instanceof ClientInstance) { | ||
219 | + htmlContent += this.formatHtml((ClientInstance)instance); | ||
220 | + }else if(instance instanceof ServerInstance) { | ||
221 | + htmlContent += this.formatHtml((ServerInstance)instance); | ||
222 | + }else { | ||
223 | + try { | ||
224 | + htmlContent += "<p>"+JSONObject.toJSONString(instance)+"</p>"; | ||
225 | + }catch (Exception e) { | ||
226 | + htmlContent += "<span style=\"color:red;\">对象无法序列化打印,instance.toString() ==>> "+instance.toString()+"</span>"; | ||
227 | + } | ||
228 | + } | ||
229 | + return new String[] {subject, htmlContent}; | ||
230 | + } | ||
231 | + | ||
232 | + @Override | ||
233 | + public void sendErrorMsg(Instance item, String response) { | ||
234 | + String[] emailData = this.formatErrorEmailInfo(item, response); | ||
235 | + this.sendWarnEmail(item, emailData[0], emailData[1]); | ||
236 | + | ||
237 | + String weixinContent = this.formatErrorWeixinContent(item, response); | ||
238 | + this.sendWarnWeixin(item, weixinContent); | ||
239 | + } | ||
240 | + | ||
241 | + private String[] formatErrorEmailInfo(Instance instance, String response) { | ||
242 | + String subject = "异常-项目可用监控--异常通知["+instance.getIdentity()+"]"; | ||
243 | + String htmlContent = "<h2>监控ID:"+instance.getIdentity()+"</h2>" | ||
244 | + + "<h3>异常内容:"+response+"</h3>"; | ||
245 | + if(instance instanceof ClientInstance) { | ||
246 | + htmlContent += this.formatHtml((ClientInstance)instance); | ||
247 | + }else if(instance instanceof ServerInstance) { | ||
248 | + htmlContent += this.formatHtml((ServerInstance)instance); | ||
249 | + }else { | ||
250 | + try { | ||
251 | + htmlContent += "<p>"+JSONObject.toJSONString(instance)+"</p>"; | ||
252 | + }catch (Exception e) { | ||
253 | + htmlContent += "<span style=\"color:red;\">对象无法序列化打印,instance.toString() ==>> "+instance.toString()+"</span>"; | ||
254 | + } | ||
255 | + } | ||
256 | + return new String[] {subject, htmlContent}; | ||
257 | + } | ||
258 | + | ||
259 | + private String formatErrorWeixinContent(Instance instance, String response) { | ||
260 | + return "异常-项目可用监控\n" | ||
261 | + + " CODE["+instance.getIdentity()+"]对应的服务出现异常\n" | ||
262 | + + " 异常内容:"+response; | ||
263 | + } | ||
264 | +} |
src/main/java/com/taover/bazhuayun/analysis/web/repository/AnalysisHeartbeatInstanceEntity.java
0 → 100644
@@ -0,0 +1,236 @@ | @@ -0,0 +1,236 @@ | ||
1 | +package com.taover.bazhuayun.analysis.web.repository; | ||
2 | + | ||
3 | +import java.io.Serializable; | ||
4 | +import java.math.BigDecimal; | ||
5 | +import java.sql.Timestamp; | ||
6 | +import java.util.Date; | ||
7 | + | ||
8 | +import javax.persistence.Entity; | ||
9 | +import javax.persistence.Table; | ||
10 | +import javax.persistence.Id; | ||
11 | +import javax.persistence.Column; | ||
12 | + | ||
13 | +/** | ||
14 | + * @version 1.0.0 | ||
15 | + */ | ||
16 | +@Entity | ||
17 | +@Table(name="analysis_heartbeat_instance", catalog="") | ||
18 | +public class AnalysisHeartbeatInstanceEntity implements Serializable { | ||
19 | + | ||
20 | + private static final long serialVersionUID = 1L; | ||
21 | + | ||
22 | + | ||
23 | + /** | ||
24 | + * | ||
25 | + */ | ||
26 | + @Id | ||
27 | + @Column(name="id") | ||
28 | + private java.lang.Long id; | ||
29 | + | ||
30 | + public java.lang.Long getId(){ | ||
31 | + return id; | ||
32 | + } | ||
33 | + public void setId(java.lang.Long id){ | ||
34 | + this.id = id; | ||
35 | + } | ||
36 | + | ||
37 | + /** | ||
38 | + * 实例类型:0-请求端,1-服务端 | ||
39 | + */ | ||
40 | + @Column(name="role_type") | ||
41 | + private java.lang.Integer roleType; | ||
42 | + | ||
43 | + public java.lang.Integer getRoleType(){ | ||
44 | + return roleType; | ||
45 | + } | ||
46 | + public void setRoleType(java.lang.Integer roleType){ | ||
47 | + this.roleType = roleType; | ||
48 | + } | ||
49 | + | ||
50 | + /** | ||
51 | + * | ||
52 | + */ | ||
53 | + @Column(name="url") | ||
54 | + private java.lang.String url; | ||
55 | + | ||
56 | + public java.lang.String getUrl(){ | ||
57 | + return url; | ||
58 | + } | ||
59 | + public void setUrl(java.lang.String url){ | ||
60 | + this.url = url; | ||
61 | + } | ||
62 | + | ||
63 | + /** | ||
64 | + * | ||
65 | + */ | ||
66 | + @Column(name="code") | ||
67 | + private java.lang.String code; | ||
68 | + | ||
69 | + public java.lang.String getCode(){ | ||
70 | + return code; | ||
71 | + } | ||
72 | + public void setCode(java.lang.String code){ | ||
73 | + this.code = code; | ||
74 | + } | ||
75 | + | ||
76 | + /** | ||
77 | + * | ||
78 | + */ | ||
79 | + @Column(name="fix_rate_sec") | ||
80 | + private java.lang.Integer fixRateSec; | ||
81 | + | ||
82 | + public java.lang.Integer getFixRateSec(){ | ||
83 | + return fixRateSec; | ||
84 | + } | ||
85 | + public void setFixRateSec(java.lang.Integer fixRateSec){ | ||
86 | + this.fixRateSec = fixRateSec; | ||
87 | + } | ||
88 | + | ||
89 | + /** | ||
90 | + * | ||
91 | + */ | ||
92 | + @Column(name="max_wait_sec") | ||
93 | + private java.lang.Integer maxWaitSec; | ||
94 | + | ||
95 | + public java.lang.Integer getMaxWaitSec(){ | ||
96 | + return maxWaitSec; | ||
97 | + } | ||
98 | + public void setMaxWaitSec(java.lang.Integer maxWaitSec){ | ||
99 | + this.maxWaitSec = maxWaitSec; | ||
100 | + } | ||
101 | + | ||
102 | + /** | ||
103 | + * | ||
104 | + */ | ||
105 | + @Column(name="token") | ||
106 | + private java.lang.String token; | ||
107 | + | ||
108 | + public java.lang.String getToken(){ | ||
109 | + return token; | ||
110 | + } | ||
111 | + public void setToken(java.lang.String token){ | ||
112 | + this.token = token; | ||
113 | + } | ||
114 | + | ||
115 | + /** | ||
116 | + * | ||
117 | + */ | ||
118 | + @Column(name="reform_email") | ||
119 | + private java.lang.String reformEmail; | ||
120 | + | ||
121 | + public java.lang.String getReformEmail(){ | ||
122 | + return reformEmail; | ||
123 | + } | ||
124 | + public void setReformEmail(java.lang.String reformEmail){ | ||
125 | + this.reformEmail = reformEmail; | ||
126 | + } | ||
127 | + | ||
128 | + /** | ||
129 | + * | ||
130 | + */ | ||
131 | + @Column(name="reform_wxid") | ||
132 | + private java.lang.String reformWxid; | ||
133 | + | ||
134 | + public java.lang.String getReformWxid(){ | ||
135 | + return reformWxid; | ||
136 | + } | ||
137 | + public void setReformWxid(java.lang.String reformWxid){ | ||
138 | + this.reformWxid = reformWxid; | ||
139 | + } | ||
140 | + | ||
141 | + /** | ||
142 | + * | ||
143 | + */ | ||
144 | + @Column(name="reform_phone") | ||
145 | + private java.lang.String reformPhone; | ||
146 | + | ||
147 | + public java.lang.String getReformPhone(){ | ||
148 | + return reformPhone; | ||
149 | + } | ||
150 | + public void setReformPhone(java.lang.String reformPhone){ | ||
151 | + this.reformPhone = reformPhone; | ||
152 | + } | ||
153 | + | ||
154 | + /** | ||
155 | + * 可用状态:0-注销,1-使用中 | ||
156 | + */ | ||
157 | + @Column(name="status") | ||
158 | + private java.lang.Integer status; | ||
159 | + | ||
160 | + public java.lang.Integer getStatus(){ | ||
161 | + return status; | ||
162 | + } | ||
163 | + public void setStatus(java.lang.Integer status){ | ||
164 | + this.status = status; | ||
165 | + } | ||
166 | + | ||
167 | + /** | ||
168 | + * | ||
169 | + */ | ||
170 | + @Column(name="create_time") | ||
171 | + private java.sql.Timestamp createTime; | ||
172 | + | ||
173 | + public java.sql.Timestamp getCreateTime(){ | ||
174 | + return createTime; | ||
175 | + } | ||
176 | + public void setCreateTime(java.sql.Timestamp createTime){ | ||
177 | + this.createTime = createTime; | ||
178 | + } | ||
179 | + | ||
180 | + /** | ||
181 | + * | ||
182 | + */ | ||
183 | + @Column(name="update_time") | ||
184 | + private java.sql.Timestamp updateTime; | ||
185 | + | ||
186 | + public java.sql.Timestamp getUpdateTime(){ | ||
187 | + return updateTime; | ||
188 | + } | ||
189 | + public void setUpdateTime(java.sql.Timestamp updateTime){ | ||
190 | + this.updateTime = updateTime; | ||
191 | + } | ||
192 | + | ||
193 | + /** | ||
194 | + * | ||
195 | + */ | ||
196 | + @Column(name="reform_max_time") | ||
197 | + private java.lang.Integer reformMaxTime; | ||
198 | + | ||
199 | + public java.lang.Integer getReformMaxTime(){ | ||
200 | + return reformMaxTime; | ||
201 | + } | ||
202 | + public void setReformMaxTime(java.lang.Integer reformMaxTime){ | ||
203 | + this.reformMaxTime = reformMaxTime; | ||
204 | + } | ||
205 | + | ||
206 | + /** | ||
207 | + * | ||
208 | + */ | ||
209 | + @Column(name="deploy_url") | ||
210 | + private java.lang.String deployUrl; | ||
211 | + | ||
212 | + public java.lang.String getDeployUrl(){ | ||
213 | + return deployUrl; | ||
214 | + } | ||
215 | + public void setDeployUrl(java.lang.String deployUrl){ | ||
216 | + this.deployUrl = deployUrl; | ||
217 | + } | ||
218 | + | ||
219 | + /** | ||
220 | + * 丢包满足多少次,则调用发布 | ||
221 | + */ | ||
222 | + @Column(name="deploy_at_lost_num") | ||
223 | + private java.lang.Integer deployAtLostNum; | ||
224 | + | ||
225 | + public java.lang.Integer getDeployAtLostNum(){ | ||
226 | + return deployAtLostNum; | ||
227 | + } | ||
228 | + public void setDeployAtLostNum(java.lang.Integer deployAtLostNum){ | ||
229 | + this.deployAtLostNum = deployAtLostNum; | ||
230 | + } | ||
231 | + | ||
232 | + @Override | ||
233 | + public String toString() { | ||
234 | + return "AnalysisHeartbeatInstanceEntity: [id="+id+",roleType="+roleType+",url="+url+",code="+code+",fixRateSec="+fixRateSec+",maxWaitSec="+maxWaitSec+",token="+token+",reformEmail="+reformEmail+",reformWxid="+reformWxid+",reformPhone="+reformPhone+",status="+status+",createTime="+createTime+",updateTime="+updateTime+",reformMaxTime="+reformMaxTime+",deployUrl="+deployUrl+",deployAtLostNum="+deployAtLostNum+"]"; | ||
235 | + } | ||
236 | + } |
src/main/java/com/taover/bazhuayun/analysis/web/repository/AnalysisHeartbeatInstanceRepository.java
0 → 100644
@@ -0,0 +1,25 @@ | @@ -0,0 +1,25 @@ | ||
1 | +package com.taover.bazhuayun.analysis.web.repository; | ||
2 | + | ||
3 | +import org.springframework.stereotype.Repository; | ||
4 | + | ||
5 | +import com.taover.repository.CustomJdbcTemplateWrapperTenant; | ||
6 | +import com.taover.repository.jdbctemplate.JdbcTemplateWrapperTenant; | ||
7 | + | ||
8 | +@Repository | ||
9 | +public class AnalysisHeartbeatInstanceRepository extends CustomJdbcTemplateWrapperTenant<AnalysisHeartbeatInstanceEntity, Long>{ | ||
10 | + | ||
11 | + public static final int STATUS_ENABLE = 1; | ||
12 | + public static final int STATUS_DISABLE = 0; | ||
13 | + public static final int ROLE_TYPE_CLIENT = 0; | ||
14 | + public static final int ROLE_TYPE_SERVER = 1; | ||
15 | + | ||
16 | + public AnalysisHeartbeatInstanceRepository() throws Exception { | ||
17 | + super(); | ||
18 | + } | ||
19 | + | ||
20 | + public AnalysisHeartbeatInstanceRepository(JdbcTemplateWrapperTenant jdbcTemplate) throws Exception { | ||
21 | + super(jdbcTemplate); | ||
22 | + } | ||
23 | + | ||
24 | +} | ||
25 | + |
src/main/java/com/taover/bazhuayun/analysis/web/repository/AnalysisHeartbeatLogEntity.java
0 → 100644
@@ -0,0 +1,132 @@ | @@ -0,0 +1,132 @@ | ||
1 | +package com.taover.bazhuayun.analysis.web.repository; | ||
2 | + | ||
3 | +import java.io.Serializable; | ||
4 | +import java.math.BigDecimal; | ||
5 | +import java.sql.Timestamp; | ||
6 | +import java.util.Date; | ||
7 | + | ||
8 | +import javax.persistence.Entity; | ||
9 | +import javax.persistence.Table; | ||
10 | +import javax.persistence.Id; | ||
11 | +import javax.persistence.Column; | ||
12 | + | ||
13 | +/** | ||
14 | + * @version 1.0.0 | ||
15 | + */ | ||
16 | +@Entity | ||
17 | +@Table(name="analysis_heartbeat_log", catalog="") | ||
18 | +public class AnalysisHeartbeatLogEntity implements Serializable { | ||
19 | + | ||
20 | + private static final long serialVersionUID = 1L; | ||
21 | + | ||
22 | + | ||
23 | + /** | ||
24 | + * | ||
25 | + */ | ||
26 | + @Id | ||
27 | + @Column(name="id") | ||
28 | + private java.lang.Long id; | ||
29 | + | ||
30 | + public java.lang.Long getId(){ | ||
31 | + return id; | ||
32 | + } | ||
33 | + public void setId(java.lang.Long id){ | ||
34 | + this.id = id; | ||
35 | + } | ||
36 | + | ||
37 | + /** | ||
38 | + * | ||
39 | + */ | ||
40 | + @Column(name="instance_code") | ||
41 | + private java.lang.String instanceCode; | ||
42 | + | ||
43 | + public java.lang.String getInstanceCode(){ | ||
44 | + return instanceCode; | ||
45 | + } | ||
46 | + public void setInstanceCode(java.lang.String instanceCode){ | ||
47 | + this.instanceCode = instanceCode; | ||
48 | + } | ||
49 | + | ||
50 | + /** | ||
51 | + * | ||
52 | + */ | ||
53 | + @Column(name="client_ip") | ||
54 | + private java.lang.String clientIp; | ||
55 | + | ||
56 | + public java.lang.String getClientIp(){ | ||
57 | + return clientIp; | ||
58 | + } | ||
59 | + public void setClientIp(java.lang.String clientIp){ | ||
60 | + this.clientIp = clientIp; | ||
61 | + } | ||
62 | + | ||
63 | + /** | ||
64 | + * | ||
65 | + */ | ||
66 | + @Column(name="server_url") | ||
67 | + private java.lang.String serverUrl; | ||
68 | + | ||
69 | + public java.lang.String getServerUrl(){ | ||
70 | + return serverUrl; | ||
71 | + } | ||
72 | + public void setServerUrl(java.lang.String serverUrl){ | ||
73 | + this.serverUrl = serverUrl; | ||
74 | + } | ||
75 | + | ||
76 | + /** | ||
77 | + * | ||
78 | + */ | ||
79 | + @Column(name="response") | ||
80 | + private java.lang.String response; | ||
81 | + | ||
82 | + public java.lang.String getResponse(){ | ||
83 | + return response; | ||
84 | + } | ||
85 | + public void setResponse(java.lang.String response){ | ||
86 | + this.response = response; | ||
87 | + } | ||
88 | + | ||
89 | + /** | ||
90 | + * | ||
91 | + */ | ||
92 | + @Column(name="create_time") | ||
93 | + private java.sql.Timestamp createTime; | ||
94 | + | ||
95 | + public java.sql.Timestamp getCreateTime(){ | ||
96 | + return createTime; | ||
97 | + } | ||
98 | + public void setCreateTime(java.sql.Timestamp createTime){ | ||
99 | + this.createTime = createTime; | ||
100 | + } | ||
101 | + | ||
102 | + /** | ||
103 | + * | ||
104 | + */ | ||
105 | + @Column(name="update_time") | ||
106 | + private java.sql.Timestamp updateTime; | ||
107 | + | ||
108 | + public java.sql.Timestamp getUpdateTime(){ | ||
109 | + return updateTime; | ||
110 | + } | ||
111 | + public void setUpdateTime(java.sql.Timestamp updateTime){ | ||
112 | + this.updateTime = updateTime; | ||
113 | + } | ||
114 | + | ||
115 | + /** | ||
116 | + * | ||
117 | + */ | ||
118 | + @Column(name="request") | ||
119 | + private java.lang.String request; | ||
120 | + | ||
121 | + public java.lang.String getRequest(){ | ||
122 | + return request; | ||
123 | + } | ||
124 | + public void setRequest(java.lang.String request){ | ||
125 | + this.request = request; | ||
126 | + } | ||
127 | + | ||
128 | + @Override | ||
129 | + public String toString() { | ||
130 | + return "AnalysisHeartbeatLogEntity: [id="+id+",instanceCode="+instanceCode+",clientIp="+clientIp+",serverUrl="+serverUrl+",response="+response+",createTime="+createTime+",updateTime="+updateTime+",request="+request+"]"; | ||
131 | + } | ||
132 | + } |
src/main/java/com/taover/bazhuayun/analysis/web/repository/AnalysisHeartbeatLogRepository.java
0 → 100644
@@ -0,0 +1,19 @@ | @@ -0,0 +1,19 @@ | ||
1 | +package com.taover.bazhuayun.analysis.web.repository; | ||
2 | + | ||
3 | +import org.springframework.stereotype.Repository; | ||
4 | + | ||
5 | +import com.taover.repository.CustomJdbcTemplateWrapperTenant; | ||
6 | +import com.taover.repository.jdbctemplate.JdbcTemplateWrapperTenant; | ||
7 | + | ||
8 | +@Repository | ||
9 | +public class AnalysisHeartbeatLogRepository extends CustomJdbcTemplateWrapperTenant<AnalysisHeartbeatLogEntity, Long>{ | ||
10 | + public AnalysisHeartbeatLogRepository() throws Exception { | ||
11 | + super(); | ||
12 | + } | ||
13 | + | ||
14 | + public AnalysisHeartbeatLogRepository(JdbcTemplateWrapperTenant jdbcTemplate) throws Exception { | ||
15 | + super(jdbcTemplate); | ||
16 | + } | ||
17 | + | ||
18 | +} | ||
19 | + |
src/main/java/com/taover/bazhuayun/analysis/web/repository/AnalysisHeartbeatReformEntity.java
0 → 100644
@@ -0,0 +1,119 @@ | @@ -0,0 +1,119 @@ | ||
1 | +package com.taover.bazhuayun.analysis.web.repository; | ||
2 | + | ||
3 | +import java.io.Serializable; | ||
4 | +import java.math.BigDecimal; | ||
5 | +import java.sql.Timestamp; | ||
6 | +import java.util.Date; | ||
7 | + | ||
8 | +import javax.persistence.Entity; | ||
9 | +import javax.persistence.Table; | ||
10 | +import javax.persistence.Id; | ||
11 | +import javax.persistence.Column; | ||
12 | + | ||
13 | +/** | ||
14 | + * @version 1.0.0 | ||
15 | + */ | ||
16 | +@Entity | ||
17 | +@Table(name="analysis_heartbeat_reform", catalog="") | ||
18 | +public class AnalysisHeartbeatReformEntity implements Serializable { | ||
19 | + | ||
20 | + private static final long serialVersionUID = 1L; | ||
21 | + | ||
22 | + | ||
23 | + /** | ||
24 | + * | ||
25 | + */ | ||
26 | + @Id | ||
27 | + @Column(name="id") | ||
28 | + private java.lang.Long id; | ||
29 | + | ||
30 | + public java.lang.Long getId(){ | ||
31 | + return id; | ||
32 | + } | ||
33 | + public void setId(java.lang.Long id){ | ||
34 | + this.id = id; | ||
35 | + } | ||
36 | + | ||
37 | + /** | ||
38 | + * | ||
39 | + */ | ||
40 | + @Column(name="instance_code") | ||
41 | + private java.lang.String instanceCode; | ||
42 | + | ||
43 | + public java.lang.String getInstanceCode(){ | ||
44 | + return instanceCode; | ||
45 | + } | ||
46 | + public void setInstanceCode(java.lang.String instanceCode){ | ||
47 | + this.instanceCode = instanceCode; | ||
48 | + } | ||
49 | + | ||
50 | + /** | ||
51 | + * 通知类型:0-邮件,1-微信,2-短信 | ||
52 | + */ | ||
53 | + @Column(name="reform_type") | ||
54 | + private java.lang.Integer reformType; | ||
55 | + | ||
56 | + public java.lang.Integer getReformType(){ | ||
57 | + return reformType; | ||
58 | + } | ||
59 | + public void setReformType(java.lang.Integer reformType){ | ||
60 | + this.reformType = reformType; | ||
61 | + } | ||
62 | + | ||
63 | + /** | ||
64 | + * | ||
65 | + */ | ||
66 | + @Column(name="reform_info") | ||
67 | + private java.lang.String reformInfo; | ||
68 | + | ||
69 | + public java.lang.String getReformInfo(){ | ||
70 | + return reformInfo; | ||
71 | + } | ||
72 | + public void setReformInfo(java.lang.String reformInfo){ | ||
73 | + this.reformInfo = reformInfo; | ||
74 | + } | ||
75 | + | ||
76 | + /** | ||
77 | + * | ||
78 | + */ | ||
79 | + @Column(name="reform_content") | ||
80 | + private java.lang.String reformContent; | ||
81 | + | ||
82 | + public java.lang.String getReformContent(){ | ||
83 | + return reformContent; | ||
84 | + } | ||
85 | + public void setReformContent(java.lang.String reformContent){ | ||
86 | + this.reformContent = reformContent; | ||
87 | + } | ||
88 | + | ||
89 | + /** | ||
90 | + * | ||
91 | + */ | ||
92 | + @Column(name="create_time") | ||
93 | + private java.sql.Timestamp createTime; | ||
94 | + | ||
95 | + public java.sql.Timestamp getCreateTime(){ | ||
96 | + return createTime; | ||
97 | + } | ||
98 | + public void setCreateTime(java.sql.Timestamp createTime){ | ||
99 | + this.createTime = createTime; | ||
100 | + } | ||
101 | + | ||
102 | + /** | ||
103 | + * | ||
104 | + */ | ||
105 | + @Column(name="update_time") | ||
106 | + private java.sql.Timestamp updateTime; | ||
107 | + | ||
108 | + public java.sql.Timestamp getUpdateTime(){ | ||
109 | + return updateTime; | ||
110 | + } | ||
111 | + public void setUpdateTime(java.sql.Timestamp updateTime){ | ||
112 | + this.updateTime = updateTime; | ||
113 | + } | ||
114 | + | ||
115 | + @Override | ||
116 | + public String toString() { | ||
117 | + return "AnalysisHeartbeatReformEntity: [id="+id+",instanceCode="+instanceCode+",reformType="+reformType+",reformInfo="+reformInfo+",reformContent="+reformContent+",createTime="+createTime+",updateTime="+updateTime+"]"; | ||
118 | + } | ||
119 | + } |
src/main/java/com/taover/bazhuayun/analysis/web/repository/AnalysisHeartbeatReformRepository.java
0 → 100644
@@ -0,0 +1,24 @@ | @@ -0,0 +1,24 @@ | ||
1 | +package com.taover.bazhuayun.analysis.web.repository; | ||
2 | + | ||
3 | +import org.springframework.stereotype.Repository; | ||
4 | + | ||
5 | +import com.taover.repository.CustomJdbcTemplateWrapperTenant; | ||
6 | +import com.taover.repository.jdbctemplate.JdbcTemplateWrapperTenant; | ||
7 | + | ||
8 | +@Repository | ||
9 | +public class AnalysisHeartbeatReformRepository extends CustomJdbcTemplateWrapperTenant<AnalysisHeartbeatReformEntity, Long>{ | ||
10 | + | ||
11 | + public static final int REFORM_TYPE_EMAIL = 0; | ||
12 | + public static final int REFORM_TYPE_WEIXIN = 1; | ||
13 | + public static final int REFORM_TYPE_DEPLOY = 2; | ||
14 | + | ||
15 | + public AnalysisHeartbeatReformRepository() throws Exception { | ||
16 | + super(); | ||
17 | + } | ||
18 | + | ||
19 | + public AnalysisHeartbeatReformRepository(JdbcTemplateWrapperTenant jdbcTemplate) throws Exception { | ||
20 | + super(jdbcTemplate); | ||
21 | + } | ||
22 | + | ||
23 | +} | ||
24 | + |
src/main/java/com/taover/bazhuayun/analysis/web/scafford/CodeGeneraterWB.java
0 → 100644
@@ -0,0 +1,67 @@ | @@ -0,0 +1,67 @@ | ||
1 | +package com.taover.bazhuayun.analysis.web.scafford; | ||
2 | + | ||
3 | +import com.taover.codegenerate.bazhuayun.GenerateCode; | ||
4 | + | ||
5 | +public class CodeGeneraterWB { | ||
6 | + public static void main(String args[]){ | ||
7 | + generateEntity("analysis_heartbeat_log"); | ||
8 | + //generateRepository("analysis_heartbeat_log"); | ||
9 | + } | ||
10 | + | ||
11 | + public static void generateEntity(String tableName){ | ||
12 | + try { | ||
13 | + GenerateCode.generateEntity("com.taover.bazhuayun.analysis.web", | ||
14 | + tableName, | ||
15 | + "D:\\workproject\\8zyun-data-analysis\\src\\main\\java", | ||
16 | + "rdsifmezqifmezqo.mysql.rds.aliyuncs.com", "3306", "tylife", "lexi365", "bzyun_wxorder", true); | ||
17 | + } catch (Exception e) { | ||
18 | + e.printStackTrace(); | ||
19 | + } | ||
20 | + } | ||
21 | + | ||
22 | + public static void generateRepository(String tableName){ | ||
23 | + try { | ||
24 | + GenerateCode.generateRepository("com.taover.bazhuayun.analysis.web", | ||
25 | + tableName, | ||
26 | + "D:\\workproject\\8zyun-data-analysis\\src\\main\\java", | ||
27 | + "rdsifmezqifmezqo.mysql.rds.aliyuncs.com", "3306", "tylife", "lexi365", "bzyun_wxorder", true); | ||
28 | + } catch (Exception e) { | ||
29 | + e.printStackTrace(); | ||
30 | + } | ||
31 | + } | ||
32 | + | ||
33 | + public static void generateAll(String tableName){ | ||
34 | + try { | ||
35 | + GenerateCode.generate("com.taover.bazhuayun.wxorder", | ||
36 | + tableName, | ||
37 | + "D:\\workproject\\8zyun-wxorder-api\\src\\main\\java", | ||
38 | + "121.42.142.102", "3306", "dev", "taover02", "bzyun_wxorder"); | ||
39 | + } catch (Exception e) { | ||
40 | + e.printStackTrace(); | ||
41 | + } | ||
42 | + } | ||
43 | + | ||
44 | + /** | ||
45 | + * API 调用示例 | ||
46 | + */ | ||
47 | + public static void generateCodeExample(){ | ||
48 | + try { | ||
49 | + //基础包名:"com.taover.bazhuayun.wxorder" | ||
50 | + //表名:"wxorder_agent_ssy_contact",多个表名用逗号分隔,全部表"ALL" | ||
51 | + //数据库连接信息:"127.0.0.1", "3306", "tylife", "lexi365" | ||
52 | + //数据库名称:"8zyun_wxorder" | ||
53 | + /*GenerateCode.generate("com.taover.bazhuayun.wxorder", | ||
54 | + "wxorder_goods_base_sku", | ||
55 | + "D:\\workproject\\8zyun-wxorder-api\\src\\main\\java", | ||
56 | + "127.0.0.1", "3306", "tylife", "lexi365", "8zyun_wxorder");*/ | ||
57 | + | ||
58 | + //gaoming | ||
59 | + GenerateCode.generate("com.taover.bazhuayun.wxorder", | ||
60 | + "wxorder_goods_map", | ||
61 | + "C:\\springboot\\8zyun-wxorder-api\\src\\main\\java", | ||
62 | + "192.168.3.2", "3306", "tylife", "lexi365", "8zyun_wxorder"); | ||
63 | + } catch (Exception e) { | ||
64 | + e.printStackTrace(); | ||
65 | + } | ||
66 | + } | ||
67 | +} |
src/main/java/com/taover/bazhuayun/analysis/web/schedule/HttpHeartbeat.java
0 → 100644
@@ -0,0 +1,48 @@ | @@ -0,0 +1,48 @@ | ||
1 | +package com.taover.bazhuayun.analysis.web.schedule; | ||
2 | + | ||
3 | +import java.util.List; | ||
4 | + | ||
5 | +import javax.annotation.PostConstruct; | ||
6 | +import javax.annotation.Resource; | ||
7 | + | ||
8 | +import org.springframework.scheduling.annotation.Scheduled; | ||
9 | +import org.springframework.stereotype.Component; | ||
10 | + | ||
11 | +import com.taover.bazhuayun.analysis.web.module.heartbeat.HeartbeatManager; | ||
12 | +import com.taover.bazhuayun.analysis.web.repository.AnalysisHeartbeatInstanceEntity; | ||
13 | +import com.taover.bazhuayun.analysis.web.repository.AnalysisHeartbeatInstanceRepository; | ||
14 | +import com.taover.util.UtilLog; | ||
15 | + | ||
16 | +@Component | ||
17 | +public class HttpHeartbeat { | ||
18 | + @Resource | ||
19 | + private HeartbeatManager heartbeatManager; | ||
20 | + @Resource | ||
21 | + private AnalysisHeartbeatInstanceRepository analysisHeartbeatInstanceRepository; | ||
22 | + | ||
23 | + /** | ||
24 | + * 注册心跳实例 | ||
25 | + */ | ||
26 | + @PostConstruct | ||
27 | + public void initHeartbeat() { | ||
28 | + //注册实例 | ||
29 | + List<AnalysisHeartbeatInstanceEntity> instanceList = this.analysisHeartbeatInstanceRepository.findListBySql("status="+AnalysisHeartbeatInstanceRepository.STATUS_ENABLE, null); | ||
30 | + try { | ||
31 | + this.heartbeatManager.loadInstance(instanceList); | ||
32 | + } catch (Exception e) { | ||
33 | + UtilLog.error("心跳监控--server注册失败", e, this.getClass()); | ||
34 | + } | ||
35 | + } | ||
36 | + | ||
37 | + /** | ||
38 | + * 每秒执行一次 | ||
39 | + */ | ||
40 | + @Scheduled(fixedDelay=1000) | ||
41 | + public void flushHeartbeat() { | ||
42 | + //刷新注册客户端状态 | ||
43 | + this.heartbeatManager.flushClientStatus(); | ||
44 | + | ||
45 | + //发送服务端心跳包 | ||
46 | + this.heartbeatManager.sendServerHeartbeat(); | ||
47 | + } | ||
48 | +} |
src/main/resources/application-local.properties
@@ -29,111 +29,11 @@ spring.mvc.dispatch-options-request=true | @@ -29,111 +29,11 @@ spring.mvc.dispatch-options-request=true | ||
29 | #spring.datasource.password=root | 29 | #spring.datasource.password=root |
30 | 30 | ||
31 | 31 | ||
32 | -spring.datasource.url=jdbc\:mysql\://121.42.142.102\:3306/bzyun_wxorder?useUnicode\=true&characterEncoding\=UTF-8&autoReconnect\=true&zeroDateTimeBehavior\=convertToNull&transformedBitIsBoolean\=true | ||
33 | -spring.datasource.username=dev | ||
34 | -spring.datasource.password=taover02 | ||
35 | -spring.datasource.driver-class-name=com.mysql.jdbc.Driver | 32 | +spring.datasource.url=jdbc:mysql://rdsifmezqifmezqo.mysql.rds.aliyuncs.com:3306/bzyun_wxorder?characterEncoding=UTF-8&serverTimezone=Asia/Shanghai |
33 | +spring.datasource.username=tylife | ||
34 | +spring.datasource.password=lexi365 | ||
35 | +spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver | ||
36 | spring.datasource.max-idle=10 | 36 | spring.datasource.max-idle=10 |
37 | spring.datasource.max-wait=10000 | 37 | spring.datasource.max-wait=10000 |
38 | spring.datasource.min-idle=5 | 38 | spring.datasource.min-idle=5 |
39 | spring.datasource.initial-size=5 | 39 | spring.datasource.initial-size=5 |
40 | - | ||
41 | -#zto analysis address url | ||
42 | -#zto.analysisAddress.url=https://localhost/Word_AnalysisAddress | ||
43 | -zto.analysisAddress.url=https://hdgateway.zto.com/Word_AnalysisAddress | ||
44 | -#taover analysis address url | ||
45 | -taover.analysisAddress.url=http://address.taover.com/ | ||
46 | -#kuaibao | ||
47 | -kuaibao.analysisAddress.url=https://kop.kuaidihelp.com/api | ||
48 | -kuaibao.analysisAddress.appId=105128 | ||
49 | -kuaibao.analysisAddress.appKey=3310236ba4d6296e6e2346a7d9c824662510ff87 | ||
50 | -kuaibao.analysisAddress.method=cloud.address.resolve | ||
51 | -kuaibao.analysisAddress.methodSimple=cloud.address.cleanse | ||
52 | - | ||
53 | -#aliyun oss | ||
54 | -accessKeyId=H4fIVB56iHjR6zQw | ||
55 | -accessKeySecret=7bA395UltFp16kWPJT7Pfz0XYXCk4Q | ||
56 | -endpoint=oss-cn-beijing.aliyuncs.com | ||
57 | -bucket_contact=8zyun-oss | ||
58 | -aliyun.mnsEndpoint=http://1225610490807748.mns.cn-hangzhou.aliyuncs.com | ||
59 | -#https://8zyun-oss.oss-cn-beijing.aliyuncs.com | ||
60 | -#mobile message url | ||
61 | -wwltData=sname=dlmzty00&spwd=A6cU4Tyx&scorpid=&sprdid=1012888 | ||
62 | -wwltUrl=https://seccf.51welink.com/submitdata/service.asmx/g_Submit | ||
63 | - | ||
64 | -#root ssy callcenter api config | ||
65 | -ssy.callcenter.appid=c2MkSTjT8ghM | ||
66 | -ssy.callcenter.seckey=7105ec065b8bb30fa6e3f13fccf92d0f | ||
67 | - | ||
68 | -pc.callcenter.appid=c2MkSTjT8ghZ | ||
69 | -pc.callcenter.seckey=7105ec065b8bb30fa6e3f13fccf92d0G | ||
70 | - | ||
71 | -ssy.callcenter.subscribePreffixUrl=http://localhost/api/ | ||
72 | -ssy.callcenter.subscribeSuffixUrl=/wxagentssymessagesubscribe | ||
73 | - | ||
74 | - | ||
75 | -ssy.callcenter.url.openapiSurrogacyAgent=/api/v2/openapi/surrogacy/agent | ||
76 | -ssy.callcenter.url.openapiSurrogacyQuerycontacts=/api/v2/openapi/surrogacy/querycontacts | ||
77 | -ssy.callcenter.url.openapiSurrogacySendmessage=/api/v2/openapi/surrogacy/sendmessage | ||
78 | -ssy.callcenter.url.openapiSurrogacyRegisteropenapi=/api/v2/openapi/surrogacy/registeropenapi | ||
79 | -ssy.callcenter.url.openapiSurrogacyUnregisteropenapi=/api/v2/openapi/surrogacy/unregisteropenapi | ||
80 | -ssy.callcenter.url.openapiCallcenterapibridgeService=/api/v2/openapi/callcenterapibridge/service | ||
81 | -ssy.callcenter.url.openapiCallGroupMember=/api/v2/openapi/surrogacy/querygroupmember | ||
82 | - | ||
83 | - | ||
84 | - | ||
85 | - | ||
86 | -ssy.upload.url=https://ssep.umsapi.com/api/v1/upload | ||
87 | - | ||
88 | -ssy.callcenter.sendMessage.preffixUrl=https://ssep.umsapi.com | ||
89 | - | ||
90 | -#weixin group text order confirm url | ||
91 | -wxorder.url.grouptextorder.confirm=http://localhost:8100/confirm/ | ||
92 | -wxorder.url.express.search=http://localhost:8100/confirm/query-logistics/ | ||
93 | - | ||
94 | -#ssy file server domain | ||
95 | -ssy.fileserver.urlpreffix=https://ss0.umsapi.com | ||
96 | - | ||
97 | -wxorder.front.url.host=http://localhost:8100 | ||
98 | - | ||
99 | -platform.shop.registerUrl=http://localhost/common/authorization/index | ||
100 | - | ||
101 | -wxorder.platformgoods.matchurl=http://localhost/goods/channelgoods | ||
102 | -wxorder.platformgoods.errororderurl=https://localhost/ordererror/index | ||
103 | -wxorder.url.excellist=http://localhost/groupexcel/index | ||
104 | - | ||
105 | -#pc api | ||
106 | -pc.callcenter.url.openapiSurrogacyRegisteropenapi=http://192.168.3.236:18308/v1/agent | ||
107 | -pc.callcenter.url.openapiSurrogacyQuerycontacts=http://192.168.3.236:18308/v1/contacts/ | ||
108 | -pc.callcenter.url.openapiCallGroupMember=http://192.168.3.236:18308/v1/contact/group_members/ | ||
109 | -pc.callcenter.url.openapiSurrogacyAgent=http://192.168.3.236:18308/v1/agent | ||
110 | -pc.callcenter.url.openapiSurrogacySendmessage=http://192.168.3.236:18308/v1/message_task | ||
111 | -pc.callcenter.subscribeUrl=http://192.168.3.146/api/wxagentpcmessagesubscribe | ||
112 | -pc.callcenter.url.sendMessageQueueName=oms-pc-msg | ||
113 | -pc.callcenter.url.openapiContactsFeaturesgroup=http://192.168.3.236:18308/v1/contacts/ | ||
114 | - | ||
115 | -pc.message.url.messageTaskListUrl=http://192.168.3.236:18308/v1/message_task_list | ||
116 | -pc.message.url.agentMessageTask=http://192.168.3.236:18308/v1/agent_message_task | ||
117 | - | ||
118 | -#cainiao param | ||
119 | -cainiao.link.url=http://link.cainiao.com/gateway/link.do | ||
120 | -cainiao.link.paramFormat=json | ||
121 | -cainiao.link.appKey=650167 | ||
122 | -cainiao.link.secretKey=lDO6y26nBJ6b5K96lnA1an447H1L0XK3 | ||
123 | -cainiao.link.auth.grantpage=http://lcp.cloud.cainiao.com/permission/isv/grantpage.do | ||
124 | -cainiao.link.auth.tokenUrl=http://lcp.cloud.cainiao.com/api/permission/exchangeToken.do | ||
125 | -cainiao.link.auth.callbackUrl=https://api.oms.8zyun.cn/api/expressprint/auth/cainiao | ||
126 | - | ||
127 | -#fa wang | ||
128 | -fineex.method.addOrder=fineex.wms.trades.add | ||
129 | -fineex.method.cancelOrder=fineex.wms.trade.cancel | ||
130 | -fineex.method.orderProcess=fineex.wms.trade.orderprocess.get | ||
131 | -fineex.apiAddress=http://apicloud.fineex.net/Interface/InterfaceWeb/InterfaceFwWMS.ashx | ||
132 | -fineex.method.goodsInventory=fineex.wms.product.inventory.get | ||
133 | -fineex.method.orderConfirm=fineex.wms.trade.orderdetail.confirm | ||
134 | -fineex.method.returnorderAdd=fineex.wms.trade.returnorder.add | ||
135 | - | ||
136 | - | ||
137 | -qimen.api.appKey=30303007 | ||
138 | -qimen.api.appSecret=80c63d1d8cf36a4c68b2df25fb93f703 | ||
139 | -qimen.api.url=https://qimen.api.taobao.com/router/qmtest |
src/main/resources/application-production.properties
1 | 1 | ||
2 | server.port=8200 | 2 | server.port=8200 |
3 | -server.session.timeout=10 | 3 | +server.session.timeout=3600 |
4 | server.connection-timeout=120000 | 4 | server.connection-timeout=120000 |
5 | 5 | ||
6 | -spring.servlet.multipart.max-file-size=10MB | ||
7 | -spring.servlet.multipart.max-request-size=20MB | ||
8 | - | ||
9 | spring.jackson.time-zone=GMT+8 | 6 | spring.jackson.time-zone=GMT+8 |
10 | spring.jackson.date-format=yyyy-MM-dd HH:mm:ss | 7 | spring.jackson.date-format=yyyy-MM-dd HH:mm:ss |
11 | -spring.mvc.dateFormat = yyyy-MM-dd HH:mm:ss | 8 | +spring.mvc.dateFormat=yyyy-MM-dd HH:mm:ss |
12 | spring.gson.serialize-nulls=true | 9 | spring.gson.serialize-nulls=true |
13 | 10 | ||
14 | #email config | 11 | #email config |
@@ -27,48 +24,12 @@ spring.mvc.dispatch-options-request=true | @@ -27,48 +24,12 @@ spring.mvc.dispatch-options-request=true | ||
27 | spring.mvc.async.request-timeout=200000 | 24 | spring.mvc.async.request-timeout=200000 |
28 | 25 | ||
29 | #DB info | 26 | #DB info |
30 | -spring.datasource.url=jdbc:mysql://rdsifmezqifmezqo.mysql.rds.aliyuncs.com:3306/bzyun_wxorder_prd?useUnicode=true&characterEncoding=UTF8&autoReconnect=true&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true | ||
31 | -spring.datasource.username=tylife | ||
32 | -spring.datasource.password=lexi365 | ||
33 | -spring.datasource.driver-class-name=com.mysql.jdbc.Driver | ||
34 | -spring.datasource.max-idle=10 | ||
35 | -spring.datasource.max-wait=10000 | ||
36 | -spring.datasource.min-idle=5 | ||
37 | -spring.datasource.initial-size=5 | ||
38 | - | ||
39 | -#zto analysis address url | ||
40 | -zto.analysisAddress.url=https://hdgateway.zto.com/Word_AnalysisAddress | ||
41 | -#taover analysis address url | ||
42 | -taover.analysisAddress.url=http://address.taover.com/ | ||
43 | -#kuaibao | ||
44 | -kuaibao.analysisAddress.url=https://kop.kuaidihelp.com/api | ||
45 | -kuaibao.analysisAddress.appId=105128 | ||
46 | -kuaibao.analysisAddress.appKey=3310236ba4d6296e6e2346a7d9c824662510ff87 | ||
47 | -kuaibao.analysisAddress.method=cloud.address.resolve | ||
48 | -kuaibao.analysisAddress.methodSimple=cloud.address.cleanse | ||
49 | - | ||
50 | -#aliyun oss address | ||
51 | -accessKeyId=H4fIVB56iHjR6zQw | ||
52 | -accessKeySecret=7bA395UltFp16kWPJT7Pfz0XYXCk4Q | ||
53 | -endpoint=oss-cn-beijing.aliyuncs.com | ||
54 | -bucket_contact=8zyun-oss | ||
55 | -aliyun.mnsEndpoint=http://1225610490807748.mns.cn-hangzhou.aliyuncs.com | ||
56 | -#mobile message url | ||
57 | -wwltData=sname=dlmzty00&spwd=A6cU4Tyx&scorpid=&sprdid=1012888 | ||
58 | -wwltUrl=https://seccf.51welink.com/submitdata/service.asmx/g_Submit | ||
59 | - | ||
60 | -#pc api | ||
61 | -pc.callcenter.url.openapiSurrogacyRegisteropenapi=https://ws.8zyun.cn:8080/v1/agent | ||
62 | -pc.callcenter.url.openapiSurrogacyQuerycontacts=https://ws.8zyun.cn:8080/v1/contacts/ | ||
63 | -pc.callcenter.url.openapiCallGroupMember=https://ws.8zyun.cn:8080/v1/contact/group_members/ | ||
64 | -pc.callcenter.url.openapiSurrogacyAgent=https://ws.8zyun.cn:8080/v1/agent | ||
65 | -pc.callcenter.url.openapiSurrogacySendmessage=https://ws.8zyun.cn:8080/v1/message_task | ||
66 | -pc.callcenter.url.openapiContactsFeaturesgroup=https://ws.8zyun.cn:8080/v1/contactsMessageCount | ||
67 | - | ||
68 | -pc.callcenter.appid=c2MkSTjT8ghZ | ||
69 | -pc.callcenter.seckey=7105ec065b8bb30fa6e3f13fccf92d0G | ||
70 | -pc.callcenter.subscribeUrl=https://api.oms.8zyun.cn/api/wxagentpcmessagesubscribe | ||
71 | -pc.callcenter.url.sendMessageQueueName=oms-pc-msg-production | ||
72 | - | ||
73 | -pc.message.url.messageTaskListUrl=https://ws.8zyun.cn:8080/v1/message_task_list | ||
74 | -pc.message.url.agentMessageTask=https://ws.8zyun.cn:8080/v1/agent_message_task | 27 | +spring.datasource.druid.url=jdbc:mysql://pxc-hzryz5s6f2lq4b.polarx.rds.aliyuncs.com:3306/bzyun_wxorder_prd?characterEncoding=UTF8&serverTimezone=Asia/Shanghai |
28 | +spring.datasource.druid.username=pj_analysis | ||
29 | +spring.datasource.druid.password=p67r0H@y8BLYNhCx | ||
30 | +spring.datasource.druid.driver-class-name=com.mysql.cj.jdbc.Driver | ||
31 | + | ||
32 | +spring.datasource.druid.initial-size=5 | ||
33 | +spring.datasource.druid.max-active=10 | ||
34 | +spring.datasource.druid.min-idle=5 | ||
35 | +spring.datasource.druid.max-wait=60000 |
test/main/java/com/taover/bazhuayun/analysis/test/SemilarClient.java
0 → 100644
@@ -0,0 +1,25 @@ | @@ -0,0 +1,25 @@ | ||
1 | +package com.taover.bazhuayun.analysis.test; | ||
2 | + | ||
3 | +import java.text.SimpleDateFormat; | ||
4 | +import java.util.Date; | ||
5 | + | ||
6 | +import com.taover.util.UtilEncrypt; | ||
7 | +import com.taover.util.UtilHttpByOkHttp; | ||
8 | + | ||
9 | +public class SemilarClient { | ||
10 | + public static void main(String[] args) { | ||
11 | + while(true) { | ||
12 | + String code = "xxljob"; | ||
13 | + long time = System.currentTimeMillis()/1000; | ||
14 | + String token = ""; | ||
15 | + try { | ||
16 | + System.out.println("=======send heartbeat["+new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())+"]======="); | ||
17 | + System.out.println("response:"+UtilHttpByOkHttp.sendGet("http://localhost/api/heartbeat?code="+code+"&unixtime="+time+"&seckey="+UtilEncrypt.MD5Lower32(code+time+token), null)); | ||
18 | + | ||
19 | + Thread.sleep(1000*60); | ||
20 | + } catch (Exception e) { | ||
21 | + e.printStackTrace(); | ||
22 | + } | ||
23 | + } | ||
24 | + } | ||
25 | +} |