From 14190ef94c4eb13041556fb3c9ce04906e83cd71 Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Tue, 12 Jan 2021 09:19:14 +0800 Subject: [PATCH 001/172] =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E5=87=BA=E4=BA=8B?= =?UTF-8?q?=E5=8C=96=E4=BB=A3=E7=A0=81=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 31 +++ Dockerfile | 10 + pom.xml | 127 +++++++++++ rzl_adapter_run.sh | 30 +++ setup_dev.sh | 27 +++ setup_production.sh | 20 ++ setup_test.sh | 27 +++ .../DipperPositionApplication.java | 24 +++ .../controller/DipperPositionController.java | 30 +++ src/main/resources/bootstrap-dev.yaml | 10 + src/main/resources/bootstrap-pro.yaml | 10 + src/main/resources/bootstrap-test.yaml | 10 + src/main/resources/bootstrap.yaml | 10 + src/main/resources/log/logback-spring.xml | 197 ++++++++++++++++++ 14 files changed, 563 insertions(+) create mode 100644 .gitignore create mode 100644 Dockerfile create mode 100644 pom.xml create mode 100644 rzl_adapter_run.sh create mode 100644 setup_dev.sh create mode 100644 setup_production.sh create mode 100644 setup_test.sh create mode 100644 src/main/java/com/telpo/dipperposition/DipperPositionApplication.java create mode 100644 src/main/java/com/telpo/dipperposition/controller/DipperPositionController.java create mode 100644 src/main/resources/bootstrap-dev.yaml create mode 100644 src/main/resources/bootstrap-pro.yaml create mode 100644 src/main/resources/bootstrap-test.yaml create mode 100644 src/main/resources/bootstrap.yaml create mode 100644 src/main/resources/log/logback-spring.xml diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d4dfde6 --- /dev/null +++ b/.gitignore @@ -0,0 +1,31 @@ +HELP.md +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/** +!**/src/test/** + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ + +### VS Code ### +.vscode/ \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..839622d --- /dev/null +++ b/Dockerfile @@ -0,0 +1,10 @@ +FROM java:8 +MAINTAINER king <1609724385@qq.com> +VOLUME /tmp +COPY target/dipperposition.jar dipperposition.jar +COPY --from=hengyunabc/arthas:latest /opt/arthas /opt/arthas +ENV TimeZone=Asia/Shanghai +ENV active=dev +ENV JAVA_OPTS="-Xmx256M -Xms256M" +RUN ln -snf /usr/share/zoneinfo/$TimeZone /etc/localtime && echo $TimeZone > /etc/timezone +ENTRYPOINT java $JAVA_OPTS -Djava.security.egd=file:/dev/./urandom -jar /dipperposition.jar --spring.profiles.active=$active \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..3a9aa0a --- /dev/null +++ b/pom.xml @@ -0,0 +1,127 @@ + + + 4.0.0 + com.telpo + dipperposition + 1.0-SNAPSHOT + dipperposition + 北斗定位服务 + jar + + + org.springframework.boot + spring-boot-starter-parent + 2.2.5.RELEASE + + + + UTF-8 + UTF-8 + 1.8 + UTF-8 + 2.2.0.RELEASE + Hoxton.RELEASE + true + + + + + org.springframework.boot + spring-boot-devtools + runtime + true + + + + org.projectlombok + lombok + true + + + + + com.alibaba.cloud + spring-cloud-starter-alibaba-nacos-discovery + + + + com.alibaba.cloud + spring-cloud-starter-alibaba-nacos-config + + + + org.springframework.boot + spring-boot-starter-webflux + + + + org.springframework.boot + spring-boot-configuration-processor + true + + + + + org.apache.commons + commons-lang3 + 3.10 + + + + + de.codecentric + spring-boot-admin-starter-client + 2.2.4 + + + + com.alibaba + fastjson + 1.2.28 + + + + + + + + org.springframework.cloud + spring-cloud-dependencies + ${spring-cloud.version} + pom + import + + + + com.alibaba.cloud + spring-cloud-alibaba-dependencies + ${spring-cloud-alibaba.version} + pom + import + + + + + + ${project.artifactId} + + + org.springframework.boot + spring-boot-maven-plugin + + + true + + + + + repackage + + + + + + + \ No newline at end of file diff --git a/rzl_adapter_run.sh b/rzl_adapter_run.sh new file mode 100644 index 0000000..a50a29f --- /dev/null +++ b/rzl_adapter_run.sh @@ -0,0 +1,30 @@ +#!/bin/bash +environment=$1 +version=$2 +echo "环境变量为${environment},版本为$version!" +if [[ ${environment} == 'production' ]]; then + echo "开始远程构建容器" + docker stop dipperposition_service || true + docker rm dipperposition_service || true + docker rmi -f $(docker images | grep registry.cn-shanghai.aliyuncs.com/telpo_platform/rzl_adapter | awk '{print $3}') + docker login --username=rzl_wangjx@1111649216405698 --password=telpo.123 registry.cn-shanghai.aliyuncs.com + docker pull registry.cn-shanghai.aliyuncs.com/telpo_platform/dipperposition_service:$version + docker run -e active=pro -v /home/data/dipperposition/log:/var/log/dipperposition --restart=always -p 8092:8092 -d --name dipperposition_service registry.cn-shanghai.aliyuncs.com/telpo_platform/dipperposition_service:$version + #删除产生的None镜像 + docker rmi -f $(docker images | grep none | awk '{print $3}') + docker ps -a +else +if [[ ${environment} == 'test' ]]; then + #echo "开始远程构建容器" + docker stop dipperposition_service || true + docker rm dipperposition_service || true + + docker rmi -f $(docker images | grep 139.224.254.18:5000/dipperposition_service | awk '{print $3}') + docker pull 139.224.254.18:5000/rzl_adapter:$version + docker run -v /home/data/dipperposition/log:/var/log/dipperposition -e active=test --restart=always -d --network host --name dipperposition_service 139.224.254.18:5000/dipperposition_service:$version + + #删除产生的None镜像 + docker rmi -f $(docker images | grep none | awk '{print $3}') + docker ps -a +fi +fi diff --git a/setup_dev.sh b/setup_dev.sh new file mode 100644 index 0000000..9c709f8 --- /dev/null +++ b/setup_dev.sh @@ -0,0 +1,27 @@ +#!/bin/bash +mvn clean +mvn package -Dmaven.test.skip=true +#image_version=$(date +%Y%m%d%H%M) +image_version=$version +docker stop dipperposition_service || true +docker rm dipperposition_service || true + +# 删除镜像 +docker rmi -f $(docker images | grep telpo/dipperposition_service | awk '{print $3}') + +docker build . -t telpo/rzl_adapter:$image_version + +#TODO:推送镜像到私有仓库 +echo '=================开始推送镜像=======================' +docker tag telpo/dipperposition_service:$image_version 139.224.254.18:5000/dipperposition_service:$image_version +docker push 139.224.254.18:5000/dipperposition_service:$image_version +echo '=================推送镜像完成=======================' + +#删除产生的None镜像 +docker rmi -f $(docker images | grep none | awk '{print $3}') +# 查看镜像列表 +docker images +# 启动容器 +docker run -v /home/data/dipperposition/log:/var/log/dipperposition -d -e active=dev --network host --restart=always --name dipperposition_service 139.224.254.18:5000/dipperposition_service:$image_version +# 查看日志 +# docker logs dipperposition_service diff --git a/setup_production.sh b/setup_production.sh new file mode 100644 index 0000000..7de562d --- /dev/null +++ b/setup_production.sh @@ -0,0 +1,20 @@ +#!/usr/bin/env bash +mvn clean +mvn package -Dmaven.test.skip=true +image_version=$version +# 删除镜像 +docker rmi -f $( + docker images | grep registry.cn-shanghai.aliyuncs.com/telpo_platform/dipperposition_service | awk '{print $3}' +) +# 构建telpo/mrp:$image_version镜像 +docker build . -t telpo/dipperposition_service:$image_version +#TODO:推送镜像到阿里仓库 +echo '=================开始推送镜像=======================' +docker login --username=rzl_wangjx@1111649216405698 --password=telpo.123 registry.cn-shanghai.aliyuncs.com +docker tag telpo/dipperposition_service:$image_version registry.cn-shanghai.aliyuncs.com/telpo_platform/dipperposition_service:$image_version +docker push registry.cn-shanghai.aliyuncs.com/telpo_platform/dipperposition_service:$image_version +echo '=================推送镜像完成=======================' +#删除产生的None镜像 +docker rmi -f $(docker images | grep none | awk '{print $3}') +# 查看镜像列表 +docker images diff --git a/setup_test.sh b/setup_test.sh new file mode 100644 index 0000000..19c0b24 --- /dev/null +++ b/setup_test.sh @@ -0,0 +1,27 @@ +#!/bin/bash +mvn clean +mvn package -Dmaven.test.skip=true +#image_version=$(date +%Y%m%d%H%M) +image_version=$version +docker stop dipperposition_service || true +docker rm dipperposition_service || true + +# 删除镜像 +docker rmi -f $(docker images | grep telpo/dipperposition_service | awk '{print $3}') + +docker build . -t telpo/dipperposition_service:$image_version + +#TODO:推送镜像到私有仓库 +echo '=================开始推送镜像=======================' +docker tag telpo/dipperposition_service:$image_version 139.224.254.18:5000/dipperposition_service:$image_version +docker push 139.224.254.18:5000/dipperposition_service:$image_version +echo '=================推送镜像完成=======================' + +#删除产生的None镜像 +docker rmi -f $(docker images | grep none | awk '{print $3}') +# 查看镜像列表 +docker images +# 启动容器 +docker run -v /home/data/dipperposition/log:/var/log/dipperposition -d -e active=test --network host --restart=always --name dipperposition_service 139.224.254.18:5000/dipperposition_service:$image_version +# 查看日志 +# docker logs dipperposition_service diff --git a/src/main/java/com/telpo/dipperposition/DipperPositionApplication.java b/src/main/java/com/telpo/dipperposition/DipperPositionApplication.java new file mode 100644 index 0000000..be9dc30 --- /dev/null +++ b/src/main/java/com/telpo/dipperposition/DipperPositionApplication.java @@ -0,0 +1,24 @@ +package com.telpo.dipperposition; + +import lombok.extern.slf4j.Slf4j; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.client.discovery.EnableDiscoveryClient; +import org.springframework.cloud.openfeign.EnableFeignClients; + +/** + * @program: gateway + * @description: 网关启动类 + * @author: linwl + * @create: 2020-06-18 16:39 + */ +@SpringBootApplication +@EnableDiscoveryClient +@Slf4j +public class DipperPositionApplication { + + public static void main(String[] args) { + SpringApplication.run(DipperPositionApplication.class, args); + log.info("北斗定位服务启动!"); + } +} diff --git a/src/main/java/com/telpo/dipperposition/controller/DipperPositionController.java b/src/main/java/com/telpo/dipperposition/controller/DipperPositionController.java new file mode 100644 index 0000000..dd96b62 --- /dev/null +++ b/src/main/java/com/telpo/dipperposition/controller/DipperPositionController.java @@ -0,0 +1,30 @@ +package com.telpo.dipperposition.controller; + +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.client.RestTemplate; + +import java.time.Duration; +import java.time.LocalDateTime; +import java.util.ArrayList; +import java.util.List; + +/** + * @program: DipperPositionController + * @description: 北斗定位 + * @author: linwl + * @create: 2020-07-10 14:01 + */ +@RestController +@Slf4j +public class DipperPositionController { + + @RequestMapping("/getPos") + public String getCampusListJson() { + return "Helle world!"; + } +} diff --git a/src/main/resources/bootstrap-dev.yaml b/src/main/resources/bootstrap-dev.yaml new file mode 100644 index 0000000..6f36d67 --- /dev/null +++ b/src/main/resources/bootstrap-dev.yaml @@ -0,0 +1,10 @@ +spring: + main: + allow-bean-definition-overriding: true + application: + name: dipperposition-service + cloud: + nacos: + config: + server-addr: 172.16.192.26:8848 + file-extension: yml \ No newline at end of file diff --git a/src/main/resources/bootstrap-pro.yaml b/src/main/resources/bootstrap-pro.yaml new file mode 100644 index 0000000..721abc4 --- /dev/null +++ b/src/main/resources/bootstrap-pro.yaml @@ -0,0 +1,10 @@ +spring: + main: + allow-bean-definition-overriding: true + application: + name: dipperposition-service + cloud: + nacos: + config: + server-addr: 172.19.42.38:8848 + file-extension: yml \ No newline at end of file diff --git a/src/main/resources/bootstrap-test.yaml b/src/main/resources/bootstrap-test.yaml new file mode 100644 index 0000000..e8e687a --- /dev/null +++ b/src/main/resources/bootstrap-test.yaml @@ -0,0 +1,10 @@ +spring: + main: + allow-bean-definition-overriding: true + application: + name: dipperposition-service + cloud: + nacos: + config: + server-addr: 172.19.42.44:8848 + file-extension: yml \ No newline at end of file diff --git a/src/main/resources/bootstrap.yaml b/src/main/resources/bootstrap.yaml new file mode 100644 index 0000000..6f36d67 --- /dev/null +++ b/src/main/resources/bootstrap.yaml @@ -0,0 +1,10 @@ +spring: + main: + allow-bean-definition-overriding: true + application: + name: dipperposition-service + cloud: + nacos: + config: + server-addr: 172.16.192.26:8848 + file-extension: yml \ No newline at end of file diff --git a/src/main/resources/log/logback-spring.xml b/src/main/resources/log/logback-spring.xml new file mode 100644 index 0000000..e461b86 --- /dev/null +++ b/src/main/resources/log/logback-spring.xml @@ -0,0 +1,197 @@ + + + + + + + + + + + + + + + + + + + + + + + + + debug + + + ${CONSOLE_LOG_PATTERN} + + UTF-8 + + + + + + + + + + ${log.path}/log_debug.log + + + %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n + UTF-8 + + + + + ${log.path}/debug/log-debug-%d{yyyy-MM-dd}.%i.log + + 100MB + + + 15 + + + + debug + ACCEPT + DENY + + + + + + + ${log.path}/log_info.log + + + %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n + UTF-8 + + + + + ${log.path}/info/log-info-%d{yyyy-MM-dd}.%i.log + + 100MB + + + 15 + + + + info + ACCEPT + DENY + + + + + + + ${log.path}/log_warn.log + + + %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n + UTF-8 + + + + ${log.path}/warn/log-warn-%d{yyyy-MM-dd}.%i.log + + 100MB + + + 15 + + + + warn + ACCEPT + DENY + + + + + + + + ${log.path}/log_error.log + + + %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n + UTF-8 + + + + ${log.path}/error/log-error-%d{yyyy-MM-dd}.%i.log + + 100MB + + + 15 + + + + ERROR + ACCEPT + DENY + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file From 9cc4e1e36b5244595fc97de224f6863e5f9f95b7 Mon Sep 17 00:00:00 2001 From: wangjx <1609724385@qq.com> Date: Tue, 12 Jan 2021 09:20:34 +0800 Subject: [PATCH 002/172] =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E5=87=BA=E4=BA=8B?= =?UTF-8?q?=E5=8C=96=E4=BB=A3=E7=A0=81=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/telpo/dipperposition/DipperPositionApplication.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/com/telpo/dipperposition/DipperPositionApplication.java b/src/main/java/com/telpo/dipperposition/DipperPositionApplication.java index be9dc30..0fc217b 100644 --- a/src/main/java/com/telpo/dipperposition/DipperPositionApplication.java +++ b/src/main/java/com/telpo/dipperposition/DipperPositionApplication.java @@ -18,6 +18,7 @@ import org.springframework.cloud.openfeign.EnableFeignClients; public class DipperPositionApplication { public static void main(String[] args) { + log.info("北斗定位服务开始!"); SpringApplication.run(DipperPositionApplication.class, args); log.info("北斗定位服务启动!"); } From 8d1994adcff1db78c1164278c677fb2ea78be7f2 Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Tue, 12 Jan 2021 09:28:36 +0800 Subject: [PATCH 003/172] =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E5=87=BA=E4=BA=8B?= =?UTF-8?q?=E5=8C=96=E4=BB=A3=E7=A0=81=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- rzl_adapter_run.sh => dipper_position_run.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename rzl_adapter_run.sh => dipper_position_run.sh (100%) diff --git a/rzl_adapter_run.sh b/dipper_position_run.sh similarity index 100% rename from rzl_adapter_run.sh rename to dipper_position_run.sh From 7363bae6f51a8202369fab46d1af0185ccf3a360 Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Tue, 12 Jan 2021 09:43:26 +0800 Subject: [PATCH 004/172] =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E5=87=BA=E4=BA=8B?= =?UTF-8?q?=E5=8C=96=E4=BB=A3=E7=A0=81=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/telpo/dipperposition/DipperPositionApplication.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/com/telpo/dipperposition/DipperPositionApplication.java b/src/main/java/com/telpo/dipperposition/DipperPositionApplication.java index 0fc217b..97c9f71 100644 --- a/src/main/java/com/telpo/dipperposition/DipperPositionApplication.java +++ b/src/main/java/com/telpo/dipperposition/DipperPositionApplication.java @@ -4,7 +4,6 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.client.discovery.EnableDiscoveryClient; -import org.springframework.cloud.openfeign.EnableFeignClients; /** * @program: gateway From d9ef5220e40de582a50ca0064dab4eca2af4fb0e Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Tue, 12 Jan 2021 09:49:13 +0800 Subject: [PATCH 005/172] =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E5=87=BA=E4=BA=8B?= =?UTF-8?q?=E5=8C=96=E4=BB=A3=E7=A0=81=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- setup_dev.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup_dev.sh b/setup_dev.sh index 9c709f8..2ae931a 100644 --- a/setup_dev.sh +++ b/setup_dev.sh @@ -9,7 +9,7 @@ docker rm dipperposition_service || true # 删除镜像 docker rmi -f $(docker images | grep telpo/dipperposition_service | awk '{print $3}') -docker build . -t telpo/rzl_adapter:$image_version +docker build . -t telpo/dipperposition_service:$image_version #TODO:推送镜像到私有仓库 echo '=================开始推送镜像=======================' From d0b5bd068605ff74563e06a483f4030f2768d448 Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Tue, 12 Jan 2021 10:03:23 +0800 Subject: [PATCH 006/172] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E8=AF=BB=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DipperPositionApplication.java | 2 ++ .../dipperposition/config/PositionConfig.java | 26 +++++++++++++++++++ src/main/resources/log/logback-spring.xml | 4 +-- 3 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 src/main/java/com/telpo/dipperposition/config/PositionConfig.java diff --git a/src/main/java/com/telpo/dipperposition/DipperPositionApplication.java b/src/main/java/com/telpo/dipperposition/DipperPositionApplication.java index 97c9f71..5bafebb 100644 --- a/src/main/java/com/telpo/dipperposition/DipperPositionApplication.java +++ b/src/main/java/com/telpo/dipperposition/DipperPositionApplication.java @@ -3,6 +3,7 @@ package com.telpo.dipperposition; import lombok.extern.slf4j.Slf4j; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.cloud.client.discovery.EnableDiscoveryClient; /** @@ -12,6 +13,7 @@ import org.springframework.cloud.client.discovery.EnableDiscoveryClient; * @create: 2020-06-18 16:39 */ @SpringBootApplication +@EnableConfigurationProperties @EnableDiscoveryClient @Slf4j public class DipperPositionApplication { diff --git a/src/main/java/com/telpo/dipperposition/config/PositionConfig.java b/src/main/java/com/telpo/dipperposition/config/PositionConfig.java new file mode 100644 index 0000000..d1ebbb0 --- /dev/null +++ b/src/main/java/com/telpo/dipperposition/config/PositionConfig.java @@ -0,0 +1,26 @@ +package com.telpo.dipperposition.config; + +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.annotation.Configuration; + +/** + * @program: gateway + * @description: jwt设置 + * @author: linwl + * @create: 2020-06-18 17:45 + */ +@Getter +@Setter +@ToString +@ConfigurationProperties("position") +@Configuration +public class PositionConfig { + + @Value("${hello}") + private String hello; + +} diff --git a/src/main/resources/log/logback-spring.xml b/src/main/resources/log/logback-spring.xml index e461b86..f4101af 100644 --- a/src/main/resources/log/logback-spring.xml +++ b/src/main/resources/log/logback-spring.xml @@ -7,7 +7,7 @@ - + @@ -172,7 +172,7 @@ - + From 12a8143c29e77245c76844dbb3255414b92f5b6f Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Tue, 12 Jan 2021 10:25:09 +0800 Subject: [PATCH 007/172] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E8=AF=BB=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dipperposition/controller/DipperPositionController.java | 2 +- src/main/resources/bootstrap-dev.yaml | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/telpo/dipperposition/controller/DipperPositionController.java b/src/main/java/com/telpo/dipperposition/controller/DipperPositionController.java index dd96b62..9840242 100644 --- a/src/main/java/com/telpo/dipperposition/controller/DipperPositionController.java +++ b/src/main/java/com/telpo/dipperposition/controller/DipperPositionController.java @@ -24,7 +24,7 @@ import java.util.List; public class DipperPositionController { @RequestMapping("/getPos") - public String getCampusListJson() { + public String getPos() { return "Helle world!"; } } diff --git a/src/main/resources/bootstrap-dev.yaml b/src/main/resources/bootstrap-dev.yaml index 6f36d67..9522e9b 100644 --- a/src/main/resources/bootstrap-dev.yaml +++ b/src/main/resources/bootstrap-dev.yaml @@ -1,4 +1,6 @@ spring: + profiles: + active: dev main: allow-bean-definition-overriding: true application: From 205257eb1e800d3aabb40ad46794c7c9e5c0c3f0 Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Tue, 12 Jan 2021 10:52:55 +0800 Subject: [PATCH 008/172] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E8=AF=BB=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/telpo/dipperposition/config/PositionConfig.java | 4 ++-- .../dipperposition/controller/DipperPositionController.java | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/telpo/dipperposition/config/PositionConfig.java b/src/main/java/com/telpo/dipperposition/config/PositionConfig.java index d1ebbb0..fab2dfe 100644 --- a/src/main/java/com/telpo/dipperposition/config/PositionConfig.java +++ b/src/main/java/com/telpo/dipperposition/config/PositionConfig.java @@ -16,11 +16,11 @@ import org.springframework.context.annotation.Configuration; @Getter @Setter @ToString -@ConfigurationProperties("position") @Configuration +@ConfigurationProperties(prefix = "position") public class PositionConfig { - @Value("${hello}") + //@Value("${hello}") private String hello; } diff --git a/src/main/java/com/telpo/dipperposition/controller/DipperPositionController.java b/src/main/java/com/telpo/dipperposition/controller/DipperPositionController.java index 9840242..e3d6fb4 100644 --- a/src/main/java/com/telpo/dipperposition/controller/DipperPositionController.java +++ b/src/main/java/com/telpo/dipperposition/controller/DipperPositionController.java @@ -7,6 +7,7 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.client.RestTemplate; +import org.springframework.web.context.ContextLoader; import java.time.Duration; import java.time.LocalDateTime; @@ -25,6 +26,6 @@ public class DipperPositionController { @RequestMapping("/getPos") public String getPos() { - return "Helle world!"; + return "Helle world!" + ContextLoader.getCurrentWebApplicationContext().toString(); } } From cc5e05c695d7d2ad8ef9dd1afa1baeb6ad1ca4ec Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Tue, 12 Jan 2021 11:02:32 +0800 Subject: [PATCH 009/172] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E8=AF=BB=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/bootstrap-dev.yaml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/resources/bootstrap-dev.yaml b/src/main/resources/bootstrap-dev.yaml index 9522e9b..28b91ca 100644 --- a/src/main/resources/bootstrap-dev.yaml +++ b/src/main/resources/bootstrap-dev.yaml @@ -1,12 +1,12 @@ spring: - profiles: - active: dev + main: allow-bean-definition-overriding: true application: - name: dipperposition-service + name: dipperposition-service.yaml cloud: nacos: config: + service=${spring:application:name}: server-addr: 172.16.192.26:8848 - file-extension: yml \ No newline at end of file + file-extension: yaml \ No newline at end of file From 2bb4a8b56fdbc819cef745691263ffd674d2d74c Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Tue, 12 Jan 2021 11:02:53 +0800 Subject: [PATCH 010/172] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E8=AF=BB=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/bootstrap-dev.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/bootstrap-dev.yaml b/src/main/resources/bootstrap-dev.yaml index 28b91ca..4df2e42 100644 --- a/src/main/resources/bootstrap-dev.yaml +++ b/src/main/resources/bootstrap-dev.yaml @@ -3,7 +3,7 @@ spring: main: allow-bean-definition-overriding: true application: - name: dipperposition-service.yaml + name: dipperposition-service-dev.yaml cloud: nacos: config: From ea89686011aa5babab29431ac762eb28c53daf2b Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Tue, 12 Jan 2021 11:04:23 +0800 Subject: [PATCH 011/172] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E8=AF=BB=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/bootstrap-dev.yaml | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/resources/bootstrap-dev.yaml b/src/main/resources/bootstrap-dev.yaml index 4df2e42..44b75f8 100644 --- a/src/main/resources/bootstrap-dev.yaml +++ b/src/main/resources/bootstrap-dev.yaml @@ -1,5 +1,4 @@ spring: - main: allow-bean-definition-overriding: true application: @@ -7,6 +6,5 @@ spring: cloud: nacos: config: - service=${spring:application:name}: server-addr: 172.16.192.26:8848 file-extension: yaml \ No newline at end of file From b1bcdc40275456d9aea1776cf80c48bc7b7c9b8f Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Tue, 12 Jan 2021 11:08:26 +0800 Subject: [PATCH 012/172] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E8=AF=BB=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dipperposition/controller/DipperPositionController.java | 2 +- src/main/resources/bootstrap-dev.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/telpo/dipperposition/controller/DipperPositionController.java b/src/main/java/com/telpo/dipperposition/controller/DipperPositionController.java index e3d6fb4..6a9b7bc 100644 --- a/src/main/java/com/telpo/dipperposition/controller/DipperPositionController.java +++ b/src/main/java/com/telpo/dipperposition/controller/DipperPositionController.java @@ -26,6 +26,6 @@ public class DipperPositionController { @RequestMapping("/getPos") public String getPos() { - return "Helle world!" + ContextLoader.getCurrentWebApplicationContext().toString(); + return "Helle world!"; //ContextLoader.getCurrentWebApplicationContext().toString(); } } diff --git a/src/main/resources/bootstrap-dev.yaml b/src/main/resources/bootstrap-dev.yaml index 44b75f8..1656353 100644 --- a/src/main/resources/bootstrap-dev.yaml +++ b/src/main/resources/bootstrap-dev.yaml @@ -2,7 +2,7 @@ spring: main: allow-bean-definition-overriding: true application: - name: dipperposition-service-dev.yaml + name: dipperposition-service-dev cloud: nacos: config: From b51c9e1ff1092e47e0b096e4de30141e2c16629c Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Tue, 12 Jan 2021 11:26:41 +0800 Subject: [PATCH 013/172] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E8=AF=BB=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 5 ++ .../controller/DipperPositionController.java | 58 +++++++++++++++---- 2 files changed, 53 insertions(+), 10 deletions(-) diff --git a/pom.xml b/pom.xml index 3a9aa0a..382d7f3 100644 --- a/pom.xml +++ b/pom.xml @@ -51,6 +51,11 @@ spring-cloud-starter-alibaba-nacos-config + + com.alibaba.nacos + nacos-client + + org.springframework.boot spring-boot-starter-webflux diff --git a/src/main/java/com/telpo/dipperposition/controller/DipperPositionController.java b/src/main/java/com/telpo/dipperposition/controller/DipperPositionController.java index 6a9b7bc..bb3f9d2 100644 --- a/src/main/java/com/telpo/dipperposition/controller/DipperPositionController.java +++ b/src/main/java/com/telpo/dipperposition/controller/DipperPositionController.java @@ -1,18 +1,16 @@ package com.telpo.dipperposition.controller; +import com.alibaba.nacos.api.PropertyKeyConst; +import com.alibaba.nacos.api.exception.NacosException; import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; -import org.springframework.web.client.RestTemplate; -import org.springframework.web.context.ContextLoader; -import java.time.Duration; -import java.time.LocalDateTime; -import java.util.ArrayList; -import java.util.List; +import java.util.Properties; +import java.util.concurrent.Executor; +import com.alibaba.nacos.api.NacosFactory; +import com.alibaba.nacos.api.config.ConfigService; +import com.alibaba.nacos.api.config.listener.Listener; /** * @program: DipperPositionController @@ -25,7 +23,47 @@ import java.util.List; public class DipperPositionController { @RequestMapping("/getPos") - public String getPos() { + public String getPos() throws NacosException, InterruptedException { + String serverAddr = "localhost"; + String dataId = "dipperposition-service-dev"; + String group = "DEFAULT_GROUP"; + + String positionId = "String.hello"; + Properties properties = new Properties(); + properties.put(PropertyKeyConst.SERVER_ADDR, serverAddr); + ConfigService configService = NacosFactory.createConfigService(properties); + String content = configService.getConfig(dataId, group, 5000); + System.out.println(content); + configService.addListener(dataId, group, new Listener() { + @Override + public void receiveConfigInfo(String configInfo) { + log.info("recieve:" + configInfo); + } + + @Override + public Executor getExecutor() { + return null; + } + }); + + boolean isPublishOk = configService.publishConfig(dataId, group, "content"); + log.info(String.valueOf(isPublishOk)); + Thread.sleep(3000); + + content = configService.getConfig(dataId, group, 5000); + log.info(content); + + content = configService.getConfig(dataId, group, 5000); + log.info(content); + + boolean isRemoveOk = configService.removeConfig(dataId, group); + log.info(String.valueOf(isRemoveOk)); + Thread.sleep(3000); + + content = configService.getConfig(dataId, group, 5000); + log.info(content); + Thread.sleep(30000); + return "Helle world!"; //ContextLoader.getCurrentWebApplicationContext().toString(); } } From 9f4859b0c30a210e356631fad0673ce1630fd6d7 Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Tue, 12 Jan 2021 11:36:03 +0800 Subject: [PATCH 014/172] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E8=AF=BB=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dipperposition/controller/DipperPositionController.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/telpo/dipperposition/controller/DipperPositionController.java b/src/main/java/com/telpo/dipperposition/controller/DipperPositionController.java index bb3f9d2..7556c5c 100644 --- a/src/main/java/com/telpo/dipperposition/controller/DipperPositionController.java +++ b/src/main/java/com/telpo/dipperposition/controller/DipperPositionController.java @@ -53,7 +53,7 @@ public class DipperPositionController { content = configService.getConfig(dataId, group, 5000); log.info(content); - content = configService.getConfig(dataId, group, 5000); + content = configService.getConfig(positionId, group, 5000); log.info(content); boolean isRemoveOk = configService.removeConfig(dataId, group); @@ -64,6 +64,8 @@ public class DipperPositionController { log.info(content); Thread.sleep(30000); + System.out.println(content); + return "Helle world!"; //ContextLoader.getCurrentWebApplicationContext().toString(); } } From f4273be9904f60ff4a13d6af1a73a6080926197d Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Tue, 12 Jan 2021 11:49:24 +0800 Subject: [PATCH 015/172] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E8=AF=BB=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dipperposition/config/PositionConfig.java | 2 +- .../controller/DipperPositionController.java | 21 ++++++++++--------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/telpo/dipperposition/config/PositionConfig.java b/src/main/java/com/telpo/dipperposition/config/PositionConfig.java index fab2dfe..78fefbd 100644 --- a/src/main/java/com/telpo/dipperposition/config/PositionConfig.java +++ b/src/main/java/com/telpo/dipperposition/config/PositionConfig.java @@ -20,7 +20,7 @@ import org.springframework.context.annotation.Configuration; @ConfigurationProperties(prefix = "position") public class PositionConfig { - //@Value("${hello}") + @Value("${hello}") private String hello; } diff --git a/src/main/java/com/telpo/dipperposition/controller/DipperPositionController.java b/src/main/java/com/telpo/dipperposition/controller/DipperPositionController.java index 7556c5c..74d6b59 100644 --- a/src/main/java/com/telpo/dipperposition/controller/DipperPositionController.java +++ b/src/main/java/com/telpo/dipperposition/controller/DipperPositionController.java @@ -32,7 +32,7 @@ public class DipperPositionController { Properties properties = new Properties(); properties.put(PropertyKeyConst.SERVER_ADDR, serverAddr); ConfigService configService = NacosFactory.createConfigService(properties); - String content = configService.getConfig(dataId, group, 5000); + String content = configService.getConfig(dataId, group, 10000); System.out.println(content); configService.addListener(dataId, group, new Listener() { @Override @@ -50,21 +50,22 @@ public class DipperPositionController { log.info(String.valueOf(isPublishOk)); Thread.sleep(3000); - content = configService.getConfig(dataId, group, 5000); + configService = NacosFactory.createConfigService(properties); + content = configService.getConfig(dataId, group, 10000); log.info(content); - content = configService.getConfig(positionId, group, 5000); + content = configService.getConfig(positionId, group, 10000); log.info(content); - boolean isRemoveOk = configService.removeConfig(dataId, group); - log.info(String.valueOf(isRemoveOk)); - Thread.sleep(3000); + //boolean isRemoveOk = configService.removeConfig(dataId, group); + //log.info(String.valueOf(isRemoveOk)); + //Thread.sleep(3000); - content = configService.getConfig(dataId, group, 5000); - log.info(content); - Thread.sleep(30000); + //content = configService.getConfig(dataId, group, 10000); + //log.info(content); + //Thread.sleep(30000); - System.out.println(content); + //System.out.println(content); return "Helle world!"; //ContextLoader.getCurrentWebApplicationContext().toString(); } From 0f95841bde845f609706509c81c9819a211b293a Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Tue, 12 Jan 2021 11:55:30 +0800 Subject: [PATCH 016/172] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E8=AF=BB=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dipperposition/config/PositionConfig.java | 7 +++- .../controller/DipperPositionController.java | 40 ++----------------- 2 files changed, 9 insertions(+), 38 deletions(-) diff --git a/src/main/java/com/telpo/dipperposition/config/PositionConfig.java b/src/main/java/com/telpo/dipperposition/config/PositionConfig.java index 78fefbd..ed1f84e 100644 --- a/src/main/java/com/telpo/dipperposition/config/PositionConfig.java +++ b/src/main/java/com/telpo/dipperposition/config/PositionConfig.java @@ -1,5 +1,8 @@ package com.telpo.dipperposition.config; +import com.alibaba.nacos.api.NacosFactory; +import com.alibaba.nacos.api.PropertyKeyConst; +import com.alibaba.nacos.api.config.ConfigService; import lombok.Getter; import lombok.Setter; import lombok.ToString; @@ -7,6 +10,8 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.context.annotation.Configuration; +import java.util.Properties; + /** * @program: gateway * @description: jwt设置 @@ -20,7 +25,7 @@ import org.springframework.context.annotation.Configuration; @ConfigurationProperties(prefix = "position") public class PositionConfig { - @Value("${hello}") + //@Value("${hello}") private String hello; } diff --git a/src/main/java/com/telpo/dipperposition/controller/DipperPositionController.java b/src/main/java/com/telpo/dipperposition/controller/DipperPositionController.java index 74d6b59..308655c 100644 --- a/src/main/java/com/telpo/dipperposition/controller/DipperPositionController.java +++ b/src/main/java/com/telpo/dipperposition/controller/DipperPositionController.java @@ -24,48 +24,14 @@ public class DipperPositionController { @RequestMapping("/getPos") public String getPos() throws NacosException, InterruptedException { - String serverAddr = "localhost"; - String dataId = "dipperposition-service-dev"; String group = "DEFAULT_GROUP"; - - String positionId = "String.hello"; + String positionId = "position.hello"; Properties properties = new Properties(); + String serverAddr = "172.16.192.26"; properties.put(PropertyKeyConst.SERVER_ADDR, serverAddr); ConfigService configService = NacosFactory.createConfigService(properties); - String content = configService.getConfig(dataId, group, 10000); + String content = configService.getConfig(positionId, group, 10000); System.out.println(content); - configService.addListener(dataId, group, new Listener() { - @Override - public void receiveConfigInfo(String configInfo) { - log.info("recieve:" + configInfo); - } - - @Override - public Executor getExecutor() { - return null; - } - }); - - boolean isPublishOk = configService.publishConfig(dataId, group, "content"); - log.info(String.valueOf(isPublishOk)); - Thread.sleep(3000); - - configService = NacosFactory.createConfigService(properties); - content = configService.getConfig(dataId, group, 10000); - log.info(content); - - content = configService.getConfig(positionId, group, 10000); - log.info(content); - - //boolean isRemoveOk = configService.removeConfig(dataId, group); - //log.info(String.valueOf(isRemoveOk)); - //Thread.sleep(3000); - - //content = configService.getConfig(dataId, group, 10000); - //log.info(content); - //Thread.sleep(30000); - - //System.out.println(content); return "Helle world!"; //ContextLoader.getCurrentWebApplicationContext().toString(); } From 638a9703b0f285483a29f746e5213ca0a7e867ec Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Tue, 12 Jan 2021 12:00:03 +0800 Subject: [PATCH 017/172] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E8=AF=BB=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/bootstrap-dev.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/bootstrap-dev.yaml b/src/main/resources/bootstrap-dev.yaml index 1656353..8f21889 100644 --- a/src/main/resources/bootstrap-dev.yaml +++ b/src/main/resources/bootstrap-dev.yaml @@ -2,7 +2,7 @@ spring: main: allow-bean-definition-overriding: true application: - name: dipperposition-service-dev + name: dipperposition-service cloud: nacos: config: From 8ff69ce56f389348dee33d350c14f8119b72bd49 Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Tue, 12 Jan 2021 12:24:29 +0800 Subject: [PATCH 018/172] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E8=AF=BB=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/DipperPositionController.java | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/telpo/dipperposition/controller/DipperPositionController.java b/src/main/java/com/telpo/dipperposition/controller/DipperPositionController.java index 308655c..1202dc6 100644 --- a/src/main/java/com/telpo/dipperposition/controller/DipperPositionController.java +++ b/src/main/java/com/telpo/dipperposition/controller/DipperPositionController.java @@ -1,11 +1,14 @@ package com.telpo.dipperposition.controller; +import com.alibaba.cloud.nacos.parser.NacosDataParserHandler; import com.alibaba.nacos.api.PropertyKeyConst; import com.alibaba.nacos.api.exception.NacosException; import lombok.extern.slf4j.Slf4j; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import java.io.IOException; +import java.util.Map; import java.util.Properties; import java.util.concurrent.Executor; import com.alibaba.nacos.api.NacosFactory; @@ -23,16 +26,19 @@ import com.alibaba.nacos.api.config.listener.Listener; public class DipperPositionController { @RequestMapping("/getPos") - public String getPos() throws NacosException, InterruptedException { + public String getPos() throws NacosException, InterruptedException, IOException { String group = "DEFAULT_GROUP"; + String dataId = "dipperposition-service"; String positionId = "position.hello"; Properties properties = new Properties(); String serverAddr = "172.16.192.26"; properties.put(PropertyKeyConst.SERVER_ADDR, serverAddr); ConfigService configService = NacosFactory.createConfigService(properties); - String content = configService.getConfig(positionId, group, 10000); + String content = configService.getConfig(dataId, group, 10000); System.out.println(content); - - return "Helle world!"; //ContextLoader.getCurrentWebApplicationContext().toString(); + //log.info(positionId + ":" + content.positionId) + Map dataMap = NacosDataParserHandler.getInstance().parseNacosData(content,"yaml"); + return dataMap == null ? "" : (String)dataMap.get(positionId); + //return "Helle world!"; //ContextLoader.getCurrentWebApplicationContext().toString(); } } From f5c44b2d3f60c86ab0d1c8accc945653fb7abde5 Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Tue, 12 Jan 2021 12:27:25 +0800 Subject: [PATCH 019/172] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E8=AF=BB=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/telpo/dipperposition/config/PositionConfig.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/telpo/dipperposition/config/PositionConfig.java b/src/main/java/com/telpo/dipperposition/config/PositionConfig.java index ed1f84e..b9cec6a 100644 --- a/src/main/java/com/telpo/dipperposition/config/PositionConfig.java +++ b/src/main/java/com/telpo/dipperposition/config/PositionConfig.java @@ -25,7 +25,7 @@ import java.util.Properties; @ConfigurationProperties(prefix = "position") public class PositionConfig { - //@Value("${hello}") + @Value("${hello}") private String hello; } From 4e7b6e5f34498719a4a7fc6ad16afaefc874aaba Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Tue, 12 Jan 2021 14:06:21 +0800 Subject: [PATCH 020/172] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E8=AF=BB=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../telpo/dipperposition/co/RzlAccount.java | 19 +++++++++++++++++++ .../dipperposition/config/PositionConfig.java | 10 ++++++++++ 2 files changed, 29 insertions(+) create mode 100644 src/main/java/com/telpo/dipperposition/co/RzlAccount.java diff --git a/src/main/java/com/telpo/dipperposition/co/RzlAccount.java b/src/main/java/com/telpo/dipperposition/co/RzlAccount.java new file mode 100644 index 0000000..d332dd6 --- /dev/null +++ b/src/main/java/com/telpo/dipperposition/co/RzlAccount.java @@ -0,0 +1,19 @@ +package com.telpo.dipperposition.co; + +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; + +/** + * @program: RzlAccount + * @description: 融智联账号配置 + * @author: king + * @create: 2021-01-12 14:02 + **/ +@Getter +@Setter +@ToString +public class RzlAccount { + + private String hello; +} diff --git a/src/main/java/com/telpo/dipperposition/config/PositionConfig.java b/src/main/java/com/telpo/dipperposition/config/PositionConfig.java index b9cec6a..e64e98d 100644 --- a/src/main/java/com/telpo/dipperposition/config/PositionConfig.java +++ b/src/main/java/com/telpo/dipperposition/config/PositionConfig.java @@ -3,12 +3,14 @@ package com.telpo.dipperposition.config; import com.alibaba.nacos.api.NacosFactory; import com.alibaba.nacos.api.PropertyKeyConst; import com.alibaba.nacos.api.config.ConfigService; +import com.telpo.dipperposition.co.RzlAccount; import lombok.Getter; import lombok.Setter; import lombok.ToString; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Scope; import java.util.Properties; @@ -28,4 +30,12 @@ public class PositionConfig { @Value("${hello}") private String hello; + @Scope("prototype") + public RzlAccount getRzlAccount() { + + RzlAccount rzlAccount = new RzlAccount(); + rzlAccount.setHello(hello); + return rzlAccount; + } + } From 9a70fc4aee30d1a08afdff13768d71d0de5f73d5 Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Tue, 12 Jan 2021 14:08:53 +0800 Subject: [PATCH 021/172] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E8=AF=BB=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/telpo/dipperposition/config/PositionConfig.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/telpo/dipperposition/config/PositionConfig.java b/src/main/java/com/telpo/dipperposition/config/PositionConfig.java index e64e98d..3bf2a0c 100644 --- a/src/main/java/com/telpo/dipperposition/config/PositionConfig.java +++ b/src/main/java/com/telpo/dipperposition/config/PositionConfig.java @@ -8,8 +8,10 @@ import lombok.Getter; import lombok.Setter; import lombok.ToString; import org.springframework.beans.factory.annotation.Value; +import org.springframework.beans.factory.config.ConfigurableBeanFactory; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Lazy; import org.springframework.context.annotation.Scope; import java.util.Properties; @@ -30,7 +32,8 @@ public class PositionConfig { @Value("${hello}") private String hello; - @Scope("prototype") + @Lazy + @Scope(value = ConfigurableBeanFactory.SCOPE_SINGLETON) public RzlAccount getRzlAccount() { RzlAccount rzlAccount = new RzlAccount(); From 31ec06a41dcd53797aa5f0413fafbb994b387c91 Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Tue, 12 Jan 2021 14:10:35 +0800 Subject: [PATCH 022/172] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E8=AF=BB=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/telpo/dipperposition/config/PositionConfig.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/telpo/dipperposition/config/PositionConfig.java b/src/main/java/com/telpo/dipperposition/config/PositionConfig.java index 3bf2a0c..6a81b21 100644 --- a/src/main/java/com/telpo/dipperposition/config/PositionConfig.java +++ b/src/main/java/com/telpo/dipperposition/config/PositionConfig.java @@ -22,6 +22,7 @@ import java.util.Properties; * @author: linwl * @create: 2020-06-18 17:45 */ +@Lazy @Getter @Setter @ToString @@ -32,7 +33,6 @@ public class PositionConfig { @Value("${hello}") private String hello; - @Lazy @Scope(value = ConfigurableBeanFactory.SCOPE_SINGLETON) public RzlAccount getRzlAccount() { From 558005fd9aace61def5c80bff197d0c459994651 Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Tue, 12 Jan 2021 14:14:46 +0800 Subject: [PATCH 023/172] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E8=AF=BB=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../telpo/dipperposition/co/RzlAccount.java | 2 ++ .../controller/DipperPositionController.java | 30 +++++++++++-------- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/telpo/dipperposition/co/RzlAccount.java b/src/main/java/com/telpo/dipperposition/co/RzlAccount.java index d332dd6..709f4da 100644 --- a/src/main/java/com/telpo/dipperposition/co/RzlAccount.java +++ b/src/main/java/com/telpo/dipperposition/co/RzlAccount.java @@ -3,6 +3,7 @@ package com.telpo.dipperposition.co; import lombok.Getter; import lombok.Setter; import lombok.ToString; +import org.springframework.stereotype.Component; /** * @program: RzlAccount @@ -13,6 +14,7 @@ import lombok.ToString; @Getter @Setter @ToString +@Component public class RzlAccount { private String hello; diff --git a/src/main/java/com/telpo/dipperposition/controller/DipperPositionController.java b/src/main/java/com/telpo/dipperposition/controller/DipperPositionController.java index 1202dc6..157fc25 100644 --- a/src/main/java/com/telpo/dipperposition/controller/DipperPositionController.java +++ b/src/main/java/com/telpo/dipperposition/controller/DipperPositionController.java @@ -3,7 +3,9 @@ package com.telpo.dipperposition.controller; import com.alibaba.cloud.nacos.parser.NacosDataParserHandler; import com.alibaba.nacos.api.PropertyKeyConst; import com.alibaba.nacos.api.exception.NacosException; +import com.telpo.dipperposition.co.RzlAccount; import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @@ -25,20 +27,24 @@ import com.alibaba.nacos.api.config.listener.Listener; @Slf4j public class DipperPositionController { + @Autowired RzlAccount rzlAccount; + @RequestMapping("/getPos") public String getPos() throws NacosException, InterruptedException, IOException { - String group = "DEFAULT_GROUP"; - String dataId = "dipperposition-service"; - String positionId = "position.hello"; - Properties properties = new Properties(); - String serverAddr = "172.16.192.26"; - properties.put(PropertyKeyConst.SERVER_ADDR, serverAddr); - ConfigService configService = NacosFactory.createConfigService(properties); - String content = configService.getConfig(dataId, group, 10000); - System.out.println(content); - //log.info(positionId + ":" + content.positionId) - Map dataMap = NacosDataParserHandler.getInstance().parseNacosData(content,"yaml"); - return dataMap == null ? "" : (String)dataMap.get(positionId); +// String group = "DEFAULT_GROUP"; +// String dataId = "dipperposition-service"; +// String positionId = "position.hello"; +// Properties properties = new Properties(); +// String serverAddr = "172.16.192.26"; +// properties.put(PropertyKeyConst.SERVER_ADDR, serverAddr); +// ConfigService configService = NacosFactory.createConfigService(properties); +// String content = configService.getConfig(dataId, group, 10000); +// System.out.println(content); +// //log.info(positionId + ":" + content.positionId) +// Map dataMap = NacosDataParserHandler.getInstance().parseNacosData(content,"yaml"); +// return dataMap == null ? "" : (String)dataMap.get(positionId); + + return rzlAccount.getHello(); //return "Helle world!"; //ContextLoader.getCurrentWebApplicationContext().toString(); } } From d2cb1faa307d2036364a4a2d0bee64b863e0942d Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Tue, 12 Jan 2021 14:17:13 +0800 Subject: [PATCH 024/172] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E8=AF=BB=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dipperposition/controller/DipperPositionController.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/telpo/dipperposition/controller/DipperPositionController.java b/src/main/java/com/telpo/dipperposition/controller/DipperPositionController.java index 157fc25..f69f1ec 100644 --- a/src/main/java/com/telpo/dipperposition/controller/DipperPositionController.java +++ b/src/main/java/com/telpo/dipperposition/controller/DipperPositionController.java @@ -4,6 +4,7 @@ import com.alibaba.cloud.nacos.parser.NacosDataParserHandler; import com.alibaba.nacos.api.PropertyKeyConst; import com.alibaba.nacos.api.exception.NacosException; import com.telpo.dipperposition.co.RzlAccount; +import com.telpo.dipperposition.config.PositionConfig; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.RequestMapping; @@ -27,7 +28,8 @@ import com.alibaba.nacos.api.config.listener.Listener; @Slf4j public class DipperPositionController { - @Autowired RzlAccount rzlAccount; + @Autowired + PositionConfig positionConfig; @RequestMapping("/getPos") public String getPos() throws NacosException, InterruptedException, IOException { @@ -44,7 +46,7 @@ public class DipperPositionController { // Map dataMap = NacosDataParserHandler.getInstance().parseNacosData(content,"yaml"); // return dataMap == null ? "" : (String)dataMap.get(positionId); - return rzlAccount.getHello(); + return positionConfig.getHello(); //return "Helle world!"; //ContextLoader.getCurrentWebApplicationContext().toString(); } } From 0e73159f60a4c261d247ff3e55ed5e776aa336ea Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Tue, 12 Jan 2021 14:29:08 +0800 Subject: [PATCH 025/172] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E8=AF=BB=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../telpo/dipperposition/co/RzlAccount.java | 21 +++++++++++++++++++ .../controller/DipperPositionController.java | 6 ++---- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/telpo/dipperposition/co/RzlAccount.java b/src/main/java/com/telpo/dipperposition/co/RzlAccount.java index 709f4da..df5d1bc 100644 --- a/src/main/java/com/telpo/dipperposition/co/RzlAccount.java +++ b/src/main/java/com/telpo/dipperposition/co/RzlAccount.java @@ -3,6 +3,8 @@ package com.telpo.dipperposition.co; import lombok.Getter; import lombok.Setter; import lombok.ToString; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Component; /** @@ -11,11 +13,30 @@ import org.springframework.stereotype.Component; * @author: king * @create: 2021-01-12 14:02 **/ +@Lazy @Getter @Setter @ToString @Component public class RzlAccount { + @Value("${hello}") private String hello; + + RzlAccount() + { + } + + private static RzlAccount instance; + public static RzlAccount getInstance(){ + if (instance==null){ + try { + Thread.sleep(100); + } catch (InterruptedException e) { + e.printStackTrace(); + } + instance = new RzlAccount(); + } + return instance; + } } diff --git a/src/main/java/com/telpo/dipperposition/controller/DipperPositionController.java b/src/main/java/com/telpo/dipperposition/controller/DipperPositionController.java index f69f1ec..d31777a 100644 --- a/src/main/java/com/telpo/dipperposition/controller/DipperPositionController.java +++ b/src/main/java/com/telpo/dipperposition/controller/DipperPositionController.java @@ -28,8 +28,7 @@ import com.alibaba.nacos.api.config.listener.Listener; @Slf4j public class DipperPositionController { - @Autowired - PositionConfig positionConfig; + RzlAccount rzlAccount; @RequestMapping("/getPos") public String getPos() throws NacosException, InterruptedException, IOException { @@ -45,8 +44,7 @@ public class DipperPositionController { // //log.info(positionId + ":" + content.positionId) // Map dataMap = NacosDataParserHandler.getInstance().parseNacosData(content,"yaml"); // return dataMap == null ? "" : (String)dataMap.get(positionId); - - return positionConfig.getHello(); + return RzlAccount.getInstance().getHello(); //return "Helle world!"; //ContextLoader.getCurrentWebApplicationContext().toString(); } } From 5c13b0c2544210aad701b164a6dff7c2bbd86cdd Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Tue, 12 Jan 2021 14:30:02 +0800 Subject: [PATCH 026/172] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E8=AF=BB=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/telpo/dipperposition/co/RzlAccount.java | 2 +- .../telpo/dipperposition/config/PositionConfig.java | 11 ----------- 2 files changed, 1 insertion(+), 12 deletions(-) diff --git a/src/main/java/com/telpo/dipperposition/co/RzlAccount.java b/src/main/java/com/telpo/dipperposition/co/RzlAccount.java index df5d1bc..5b589b4 100644 --- a/src/main/java/com/telpo/dipperposition/co/RzlAccount.java +++ b/src/main/java/com/telpo/dipperposition/co/RzlAccount.java @@ -20,7 +20,7 @@ import org.springframework.stereotype.Component; @Component public class RzlAccount { - @Value("${hello}") + @Value("${position.hello}") private String hello; RzlAccount() diff --git a/src/main/java/com/telpo/dipperposition/config/PositionConfig.java b/src/main/java/com/telpo/dipperposition/config/PositionConfig.java index 6a81b21..7e0b866 100644 --- a/src/main/java/com/telpo/dipperposition/config/PositionConfig.java +++ b/src/main/java/com/telpo/dipperposition/config/PositionConfig.java @@ -30,15 +30,4 @@ import java.util.Properties; @ConfigurationProperties(prefix = "position") public class PositionConfig { - @Value("${hello}") - private String hello; - - @Scope(value = ConfigurableBeanFactory.SCOPE_SINGLETON) - public RzlAccount getRzlAccount() { - - RzlAccount rzlAccount = new RzlAccount(); - rzlAccount.setHello(hello); - return rzlAccount; - } - } From c3d71e8da5e71952679bcb2361371070829d7504 Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Tue, 12 Jan 2021 14:33:58 +0800 Subject: [PATCH 027/172] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E8=AF=BB=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dipperposition/config/PositionConfig.java | 18 ++++++++++++++++++ .../controller/DipperPositionController.java | 2 +- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/telpo/dipperposition/config/PositionConfig.java b/src/main/java/com/telpo/dipperposition/config/PositionConfig.java index 7e0b866..0826f8d 100644 --- a/src/main/java/com/telpo/dipperposition/config/PositionConfig.java +++ b/src/main/java/com/telpo/dipperposition/config/PositionConfig.java @@ -29,5 +29,23 @@ import java.util.Properties; @Configuration @ConfigurationProperties(prefix = "position") public class PositionConfig { + @Value("${position.hello}") + private String hello; + PositionConfig() + { + } + + private static PositionConfig instance; + public static PositionConfig getInstance(){ + if (instance==null){ + try { + Thread.sleep(100); + } catch (InterruptedException e) { + e.printStackTrace(); + } + instance = new PositionConfig(); + } + return instance; + } } diff --git a/src/main/java/com/telpo/dipperposition/controller/DipperPositionController.java b/src/main/java/com/telpo/dipperposition/controller/DipperPositionController.java index d31777a..619e305 100644 --- a/src/main/java/com/telpo/dipperposition/controller/DipperPositionController.java +++ b/src/main/java/com/telpo/dipperposition/controller/DipperPositionController.java @@ -44,7 +44,7 @@ public class DipperPositionController { // //log.info(positionId + ":" + content.positionId) // Map dataMap = NacosDataParserHandler.getInstance().parseNacosData(content,"yaml"); // return dataMap == null ? "" : (String)dataMap.get(positionId); - return RzlAccount.getInstance().getHello(); + return PositionConfig.getInstance().getHello(); //return "Helle world!"; //ContextLoader.getCurrentWebApplicationContext().toString(); } } From 6f91bc025aa0df70272138313bc86f9242819b46 Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Tue, 12 Jan 2021 14:39:26 +0800 Subject: [PATCH 028/172] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E8=AF=BB=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/telpo/dipperposition/config/PositionConfig.java | 6 ++++-- .../dipperposition/controller/DipperPositionController.java | 4 +++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/telpo/dipperposition/config/PositionConfig.java b/src/main/java/com/telpo/dipperposition/config/PositionConfig.java index 0826f8d..4285ce0 100644 --- a/src/main/java/com/telpo/dipperposition/config/PositionConfig.java +++ b/src/main/java/com/telpo/dipperposition/config/PositionConfig.java @@ -27,11 +27,13 @@ import java.util.Properties; @Setter @ToString @Configuration -@ConfigurationProperties(prefix = "position") public class PositionConfig { - @Value("${position.hello}") + @Value(value = "${position.hello}") private String hello; + @Value(value = "${spring.application.name}") + private String name; + PositionConfig() { } diff --git a/src/main/java/com/telpo/dipperposition/controller/DipperPositionController.java b/src/main/java/com/telpo/dipperposition/controller/DipperPositionController.java index 619e305..24b744a 100644 --- a/src/main/java/com/telpo/dipperposition/controller/DipperPositionController.java +++ b/src/main/java/com/telpo/dipperposition/controller/DipperPositionController.java @@ -44,7 +44,9 @@ public class DipperPositionController { // //log.info(positionId + ":" + content.positionId) // Map dataMap = NacosDataParserHandler.getInstance().parseNacosData(content,"yaml"); // return dataMap == null ? "" : (String)dataMap.get(positionId); - return PositionConfig.getInstance().getHello(); + String returnStr= + "return position = " + PositionConfig.getInstance().getHello() + "return name = " + PositionConfig.getInstance().getName(); + return returnStr; //return "Helle world!"; //ContextLoader.getCurrentWebApplicationContext().toString(); } } From f2088a1404167bfab7659f848a5a605d28adf926 Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Tue, 12 Jan 2021 14:49:27 +0800 Subject: [PATCH 029/172] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E8=AF=BB=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../telpo/dipperposition/config/PositionConfig.java | 11 +++++++++-- .../controller/DipperPositionController.java | 1 + 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/telpo/dipperposition/config/PositionConfig.java b/src/main/java/com/telpo/dipperposition/config/PositionConfig.java index 4285ce0..223c64e 100644 --- a/src/main/java/com/telpo/dipperposition/config/PositionConfig.java +++ b/src/main/java/com/telpo/dipperposition/config/PositionConfig.java @@ -7,9 +7,11 @@ import com.telpo.dipperposition.co.RzlAccount; import lombok.Getter; import lombok.Setter; import lombok.ToString; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.config.ConfigurableBeanFactory; import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Lazy; import org.springframework.context.annotation.Scope; @@ -28,14 +30,19 @@ import java.util.Properties; @ToString @Configuration public class PositionConfig { - @Value(value = "${position.hello}") + + @Autowired + private ConfigurableApplicationContext configurableApplicationContext; + //@Value(value = "${position.hello}") private String hello; - @Value(value = "${spring.application.name}") + //@Value(value = "${spring.application.name}") private String name; PositionConfig() { + hello = configurableApplicationContext.getEnvironment().getProperty("position.hello"); + name = configurableApplicationContext.getEnvironment().getProperty("spring.application.name"); } private static PositionConfig instance; diff --git a/src/main/java/com/telpo/dipperposition/controller/DipperPositionController.java b/src/main/java/com/telpo/dipperposition/controller/DipperPositionController.java index 24b744a..22cba9b 100644 --- a/src/main/java/com/telpo/dipperposition/controller/DipperPositionController.java +++ b/src/main/java/com/telpo/dipperposition/controller/DipperPositionController.java @@ -46,6 +46,7 @@ public class DipperPositionController { // return dataMap == null ? "" : (String)dataMap.get(positionId); String returnStr= "return position = " + PositionConfig.getInstance().getHello() + "return name = " + PositionConfig.getInstance().getName(); + return returnStr; //return "Helle world!"; //ContextLoader.getCurrentWebApplicationContext().toString(); } From 507f5e1cc3d94d765b5be273cae898d619713e19 Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Tue, 12 Jan 2021 14:53:03 +0800 Subject: [PATCH 030/172] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E8=AF=BB=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/telpo/dipperposition/config/PositionConfig.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/com/telpo/dipperposition/config/PositionConfig.java b/src/main/java/com/telpo/dipperposition/config/PositionConfig.java index 223c64e..7153f46 100644 --- a/src/main/java/com/telpo/dipperposition/config/PositionConfig.java +++ b/src/main/java/com/telpo/dipperposition/config/PositionConfig.java @@ -24,7 +24,6 @@ import java.util.Properties; * @author: linwl * @create: 2020-06-18 17:45 */ -@Lazy @Getter @Setter @ToString From 3c2cfdc8c0b35cb64e80f4661cbeb5a1982b348c Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Tue, 12 Jan 2021 14:56:16 +0800 Subject: [PATCH 031/172] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E8=AF=BB=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/telpo/dipperposition/config/PositionConfig.java | 4 ++-- .../controller/DipperPositionController.java | 9 +++++---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/telpo/dipperposition/config/PositionConfig.java b/src/main/java/com/telpo/dipperposition/config/PositionConfig.java index 7153f46..34b9059 100644 --- a/src/main/java/com/telpo/dipperposition/config/PositionConfig.java +++ b/src/main/java/com/telpo/dipperposition/config/PositionConfig.java @@ -40,8 +40,8 @@ public class PositionConfig { PositionConfig() { - hello = configurableApplicationContext.getEnvironment().getProperty("position.hello"); - name = configurableApplicationContext.getEnvironment().getProperty("spring.application.name"); + //hello = configurableApplicationContext.getEnvironment().getProperty("position.hello"); + //name = configurableApplicationContext.getEnvironment().getProperty("spring.application.name"); } private static PositionConfig instance; diff --git a/src/main/java/com/telpo/dipperposition/controller/DipperPositionController.java b/src/main/java/com/telpo/dipperposition/controller/DipperPositionController.java index 22cba9b..4783081 100644 --- a/src/main/java/com/telpo/dipperposition/controller/DipperPositionController.java +++ b/src/main/java/com/telpo/dipperposition/controller/DipperPositionController.java @@ -7,6 +7,7 @@ import com.telpo.dipperposition.co.RzlAccount; import com.telpo.dipperposition.config.PositionConfig; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @@ -27,8 +28,9 @@ import com.alibaba.nacos.api.config.listener.Listener; @RestController @Slf4j public class DipperPositionController { - - RzlAccount rzlAccount; + @Value(value = "${position.hello}") + private String hello; + //RzlAccount rzlAccount; @RequestMapping("/getPos") public String getPos() throws NacosException, InterruptedException, IOException { @@ -44,8 +46,7 @@ public class DipperPositionController { // //log.info(positionId + ":" + content.positionId) // Map dataMap = NacosDataParserHandler.getInstance().parseNacosData(content,"yaml"); // return dataMap == null ? "" : (String)dataMap.get(positionId); - String returnStr= - "return position = " + PositionConfig.getInstance().getHello() + "return name = " + PositionConfig.getInstance().getName(); + String returnStr= "return position = " + hello; return returnStr; //return "Helle world!"; //ContextLoader.getCurrentWebApplicationContext().toString(); From 0d6b255922a4cfc4801a917ac06440da37cd7b67 Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Fri, 15 Jan 2021 12:27:42 +0800 Subject: [PATCH 032/172] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E8=AF=BB=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 45 ++ .../DipperPositionApplication.java | 10 + .../telpo/dipperposition/common/CSVUtil.java | 87 +++ .../dipperposition/common/HexConvert.java | 140 ++++ .../dipperposition/common/OkHttpUtil.java | 155 ++++ .../dipperposition/common/RedisUtil.java | 665 ++++++++++++++++++ .../dipperposition/common/SocketClient.java | 85 +++ .../dipperposition/common/TimeTools.java | 39 + .../dipperposition/config/PositionConfig.java | 11 - .../config/db/MongoDbContext.java | 66 ++ .../config/db/MongoListProperties.java | 30 + .../config/db/MultiMongoTemplate.java | 26 + .../controller/DipperPositionController.java | 32 +- .../entity/mongo/IPProvinceEntity.java | 24 + .../enums/DipperReturnValue.java | 53 ++ .../handler/NettyServerHandler.java | 145 ++++ .../handler/ServerChannelInitializer.java | 24 + .../mapper/IPProvinceMapper.java | 52 ++ .../server/DipperPositionServer.java | 153 ++++ .../IDipperAstPosAsyncTaskService.java | 23 + .../IDipperAstTimeAsyncTaskService.java | 17 + .../service/IDipperDataAsyncTaskService.java | 26 + .../service/IPProvinceService.java | 45 ++ .../DipperAstPosAsyncTaskServiceImpl.java | 251 +++++++ .../DipperAstTimeAsyncTaskServiceImpl.java | 104 +++ .../impl/DipperDataAsyncTaskServiceImpl.java | 73 ++ .../service/impl/IPProvinceServiceImpl.java | 62 ++ .../dipperposition/task/ScheduleService.java | 39 + .../telpo/dipperposition/vo/IPProvinceVo.java | 20 + src/main/resources/bootstrap.yaml | 26 +- 30 files changed, 2486 insertions(+), 42 deletions(-) create mode 100644 src/main/java/com/telpo/dipperposition/common/CSVUtil.java create mode 100644 src/main/java/com/telpo/dipperposition/common/HexConvert.java create mode 100644 src/main/java/com/telpo/dipperposition/common/OkHttpUtil.java create mode 100644 src/main/java/com/telpo/dipperposition/common/RedisUtil.java create mode 100644 src/main/java/com/telpo/dipperposition/common/SocketClient.java create mode 100644 src/main/java/com/telpo/dipperposition/common/TimeTools.java create mode 100644 src/main/java/com/telpo/dipperposition/config/db/MongoDbContext.java create mode 100644 src/main/java/com/telpo/dipperposition/config/db/MongoListProperties.java create mode 100644 src/main/java/com/telpo/dipperposition/config/db/MultiMongoTemplate.java create mode 100644 src/main/java/com/telpo/dipperposition/entity/mongo/IPProvinceEntity.java create mode 100644 src/main/java/com/telpo/dipperposition/enums/DipperReturnValue.java create mode 100644 src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java create mode 100644 src/main/java/com/telpo/dipperposition/handler/ServerChannelInitializer.java create mode 100644 src/main/java/com/telpo/dipperposition/mapper/IPProvinceMapper.java create mode 100644 src/main/java/com/telpo/dipperposition/server/DipperPositionServer.java create mode 100644 src/main/java/com/telpo/dipperposition/service/IDipperAstPosAsyncTaskService.java create mode 100644 src/main/java/com/telpo/dipperposition/service/IDipperAstTimeAsyncTaskService.java create mode 100644 src/main/java/com/telpo/dipperposition/service/IDipperDataAsyncTaskService.java create mode 100644 src/main/java/com/telpo/dipperposition/service/IPProvinceService.java create mode 100644 src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java create mode 100644 src/main/java/com/telpo/dipperposition/service/impl/DipperAstTimeAsyncTaskServiceImpl.java create mode 100644 src/main/java/com/telpo/dipperposition/service/impl/DipperDataAsyncTaskServiceImpl.java create mode 100644 src/main/java/com/telpo/dipperposition/service/impl/IPProvinceServiceImpl.java create mode 100644 src/main/java/com/telpo/dipperposition/task/ScheduleService.java create mode 100644 src/main/java/com/telpo/dipperposition/vo/IPProvinceVo.java diff --git a/pom.xml b/pom.xml index 382d7f3..20c8038 100644 --- a/pom.xml +++ b/pom.xml @@ -87,6 +87,51 @@ 1.2.28 + + io.netty + netty-all + 4.1.13.Final + + + + com.telpo + common + 1.1.19 + + + + + org.springframework.boot + spring-boot-starter-data-redis + + + + + org.apache.commons + commons-pool2 + + + + + com.squareup.okhttp3 + okhttp + 4.8.0 + + + + + de.codecentric + spring-boot-admin-starter-client + 2.2.4 + + + + + net.sourceforge.javacsv + javacsv + 2.0 + + diff --git a/src/main/java/com/telpo/dipperposition/DipperPositionApplication.java b/src/main/java/com/telpo/dipperposition/DipperPositionApplication.java index 5bafebb..865170a 100644 --- a/src/main/java/com/telpo/dipperposition/DipperPositionApplication.java +++ b/src/main/java/com/telpo/dipperposition/DipperPositionApplication.java @@ -1,11 +1,15 @@ package com.telpo.dipperposition; +import com.telpo.dipperposition.server.DipperPositionServer; import lombok.extern.slf4j.Slf4j; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.context.properties.ConfigurationPropertiesScan; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.cloud.client.discovery.EnableDiscoveryClient; +import java.net.InetSocketAddress; + /** * @program: gateway * @description: 网关启动类 @@ -16,11 +20,17 @@ import org.springframework.cloud.client.discovery.EnableDiscoveryClient; @EnableConfigurationProperties @EnableDiscoveryClient @Slf4j +@ConfigurationPropertiesScan public class DipperPositionApplication { public static void main(String[] args) { log.info("北斗定位服务开始!"); SpringApplication.run(DipperPositionApplication.class, args); log.info("北斗定位服务启动!"); + //启动服务端 + DipperPositionServer nettyServer = new DipperPositionServer(); + nettyServer.startTimeAsnc(); + nettyServer.startPosAsnc(); + nettyServer.startStarsAsnc(); } } diff --git a/src/main/java/com/telpo/dipperposition/common/CSVUtil.java b/src/main/java/com/telpo/dipperposition/common/CSVUtil.java new file mode 100644 index 0000000..e6d1ab0 --- /dev/null +++ b/src/main/java/com/telpo/dipperposition/common/CSVUtil.java @@ -0,0 +1,87 @@ +package com.telpo.dipperposition.common; + +import com.csvreader.CsvReader; +import com.csvreader.CsvWriter; + +import java.io.FileNotFoundException; +import java.io.FileWriter; +import java.io.IOException; +import java.nio.charset.Charset; +import java.util.ArrayList; +import java.util.List; +/** + * @program: dipperposition + * @description: CSV文件读取单元 + * @author: linwl + * @create: 2021-01-14 11:19 + **/ +public class CSVUtil { + /** + * 读取每行的数据 + * + * @param readPath + * @return + */ + public static List readCSV(String readPath) { + String filePath = readPath; + List listData = new ArrayList<>(); + try { + filePath = readPath; + CsvReader csvReader = new CsvReader(filePath); + // 读表头 + boolean re = csvReader.readHeaders(); + while (csvReader.readRecord()) { + String rawRecord = csvReader.getRawRecord(); + listData.add(rawRecord); + } + return listData; + } catch (FileNotFoundException e) { + throw new RuntimeException("文件未找到"); + } catch (IOException e) { + throw new RuntimeException(e.getMessage()); + } + + } + + /** + * 写入文件头 + * @param writePath + * @param header + */ + public static void writeCSV(String writePath, String[] header) { + String filePath = writePath; + try { + CsvWriter csvWriter = new CsvWriter(writePath, ',', Charset.forName("UTF-8")); + //String [] header = {"SkuId","SsuId","图片地址","大小(bit)","高度","宽度"}; + csvWriter.writeRecord(header); + csvWriter.close(); + } catch (Exception e) { + e.printStackTrace(); + } + + } + + /** + * 利用输入输出流持续写 + * @param fileName + * @param content + */ + public static void writeContent(String fileName, String content) { + FileWriter writer = null; + try { + // 打开一个写文件器,构造函数中的第二个参数true表示以追加形式写文件 + writer = new FileWriter(fileName, true); + writer.write(content + "\r\n"); + } catch (IOException e) { + e.printStackTrace(); + } finally { + try { + if (writer != null) { + writer.close(); + } + } catch (IOException e) { + e.printStackTrace(); + } + } + } +} diff --git a/src/main/java/com/telpo/dipperposition/common/HexConvert.java b/src/main/java/com/telpo/dipperposition/common/HexConvert.java new file mode 100644 index 0000000..8f79122 --- /dev/null +++ b/src/main/java/com/telpo/dipperposition/common/HexConvert.java @@ -0,0 +1,140 @@ +package com.telpo.dipperposition.common; + +/** + * @program: dipperposition + * @description: 16进制处理 + * @author: linwl + * @create: 2021-01-14 22:05 + **/ +public class HexConvert { + public static String convertStringToHex(String str){ + + char[] chars = str.toCharArray(); + + StringBuffer hex = new StringBuffer(); + for(int i = 0; i < chars.length; i++){ + hex.append(Integer.toHexString((int)chars[i])); + } + + return hex.toString(); + } + + public static String convertHexToString(String hex){ + + StringBuilder sb = new StringBuilder(); + StringBuilder sb2 = new StringBuilder(); + + for( int i=0; i> 4)); + hex += String.valueOf(hexStr.charAt(b & 0x0F)); + result += hex + " "; + } + return result; + } + + //將10進制轉換為16進制 + public static String encodeHEX(long numb){ + + String hex= Long.toHexString(numb); + return hex; + + } + + + //將16進制字符串轉換為10進制數字 + public static long decodeHEX(String hexs){ + long longValue= Long.parseLong("123ABC", 16); + return longValue; + } + + + /** + * 生成校验码的int值 + * */ + public static String makeChecksum(String data) { + if (data == null || data.equals("")) { + return ""; + } + int total = 0; + int len = data.length(); + int num = 0; + while (num < len) { + String s = data.substring(num, num + 2); + //System.out.println(s); + total += Integer.parseInt(s, 16); + num = num + 2; + } + /** + * 用256求余最大是255,即16进制的FF + */ + int mod = total % 256; + String hex = Integer.toHexString(mod); + len = hex.length(); + // 如果不够校验位的长度,补0,这里用的是两位校验 + if (len < 2) { + hex = "0" + hex; + } + return hex; + } +// +// public static void main(String[] args) { +// +// +// System.out.println("======ASCII码转换为16进制======"); +// String str = "*00007VERSION\\n1$"; +// System.out.println("字符串: " + str); +// String hex = HexConvert.convertStringToHex(str); +// System.out.println("====转换为16进制=====" + hex); +// +// System.out.println("======16进制转换为ASCII======"); +// System.out.println("Hex : " + hex); +// System.out.println("ASCII : " + HexConvert.convertHexToString(hex)); +// +// byte[] bytes = HexConvert.hexStringToBytes( hex ); +// +// System.out.println(HexConvert.BinaryToHexString( bytes )); +// } + +} diff --git a/src/main/java/com/telpo/dipperposition/common/OkHttpUtil.java b/src/main/java/com/telpo/dipperposition/common/OkHttpUtil.java new file mode 100644 index 0000000..a31eb99 --- /dev/null +++ b/src/main/java/com/telpo/dipperposition/common/OkHttpUtil.java @@ -0,0 +1,155 @@ +package com.telpo.dipperposition.common; + +import com.alibaba.fastjson.JSONObject; +import lombok.extern.slf4j.Slf4j; +import okhttp3.*; +import org.apache.commons.lang3.ObjectUtils; +import org.apache.commons.lang3.exception.ExceptionUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import java.text.MessageFormat; +import java.util.Iterator; +import java.util.Map; +import java.util.Objects; + +/** + * @program: DataPushServer + * @description: okhttp工具类 + * @author: linwl + * @create: 2020-07-17 15:43 + */ +@Slf4j +@Component +public class OkHttpUtil { + + @Autowired + private OkHttpClient okHttpClient; + + /** + * 根据map获取get请求参数 + * + * @param queries + * @return + */ + public StringBuffer getQueryString(String url, Map queries) { + StringBuffer sb = new StringBuffer(url); + if (queries != null && queries.keySet().size() > 0) { + boolean firstFlag = true; + Iterator iterator = queries.entrySet().iterator(); + while (iterator.hasNext()) { + Map.Entry entry = (Map.Entry) iterator.next(); + if (firstFlag) { + sb.append("?" + entry.getKey() + "=" + entry.getValue()); + firstFlag = false; + } else { + sb.append("&" + entry.getKey() + "=" + entry.getValue()); + } + } + } + return sb; + } + + /** + * get + * + * @param url 请求的url + * @param queries 请求的参数,在浏览器?后面的数据,没有可以传null + * @return + */ + public String get(String url, Map queries) { + StringBuffer sb = getQueryString(url, queries); + Request request = new Request.Builder().url(sb.toString()).build(); + log.debug(MessageFormat.format("发送Get to url<{0}>,参数为:{1}", url, queries)); + return execNewCall(request); + } + + /** + * post + * + * @param url 请求的url + * @param params post form 提交的参数 + * @return + */ + public String postFormParams(String url, Map params) { + FormBody.Builder builder = new FormBody.Builder(); + // 添加参数 + if (params != null && params.keySet().size() > 0) { + for (String key : params.keySet()) { + builder.add(key, params.get(key)); + } + } + log.debug(MessageFormat.format("发送post from to url<{0}>,参数为:{1}", url, params)); + Request request = new Request.Builder().url(url).post(builder.build()).build(); + return execNewCall(request); + } + + /** Post请求发送JSON数据....{"name":"zhangsan","pwd":"123456"} 参数一:请求Url 参数二:请求的JSON 参数三:请求回调 */ + public String postJsonParams(String url, String jsonParams) { + RequestBody requestBody = RequestBody.create(jsonParams, MediaType.parse("application/json; charset=utf-8")); + Request request = new Request.Builder().url(url).post(requestBody).build(); + log.debug(MessageFormat.format("发送post json to url<{0}>,参数为:{1}", url, jsonParams)); + return execNewCall(request); + } + + /** Post请求发送xml数据.... 参数一:请求Url 参数二:请求的xmlString 参数三:请求回调 */ + public String postXmlParams(String url, String xml) { + RequestBody requestBody = + RequestBody.create(xml, MediaType.parse("application/xml; charset=utf-8")); + Request request = new Request.Builder().url(url).post(requestBody).build(); + log.debug(MessageFormat.format("发送post xml to url<{0}>,参数为:{1}", url, xml)); + return execNewCall(request); + } + + /** + * 调用okhttp的newCall方法 + * + * @param request + * @return + */ + private String execNewCall(Request request) { + try (Response response = okHttpClient.newCall(request).execute()) { + if (response.isSuccessful()) { + return Objects.requireNonNull(response.body()).string(); + } + } catch (Exception e) { + log.error("okhttp3 put error >> ex = {}", ExceptionUtils.getStackTrace(e)); + } + return "FAIL"; + } + + /** + * Post请求发送JSON数据....{"name":"zhangsan","pwd":"123456"} 参数一:请求Url 参数二:请求的JSON 参数三:请求回调 + */ + public String postJsonParamsWithToken(String url, String token, String jsonParams) { + RequestBody requestBody = + RequestBody.create(jsonParams, MediaType.parse("application/json; charset=utf-8")); + Request request = new Request.Builder().url(url). + addHeader("Authorization", token).post(requestBody).build(); + log.debug(MessageFormat.format("发送post json to url<{0}>,参数为:{1}", url, jsonParams)); + return execNewCall(request); + } + + public JSONObject postRequestWithJson(String url, String accessToken, JSONObject postData) { + String postResult; + if (ObjectUtils.isNotEmpty(accessToken)) { + postResult = postJsonParamsWithToken(url, accessToken, JSONObject.toJSONString(postData)); + } else { + postResult = postJsonParams(url, JSONObject.toJSONString(postData)); + } + + if (postResult == null) { + log.error("访问错误"); + return null; + } else { + log.debug(postResult); + if(("FAIL").equals(postResult.toString())) { + JSONObject object = new JSONObject(); + object.put("result", "FAIL"); + return object; + } else { + return JSONObject.parseObject(postResult); + } + } + } +} diff --git a/src/main/java/com/telpo/dipperposition/common/RedisUtil.java b/src/main/java/com/telpo/dipperposition/common/RedisUtil.java new file mode 100644 index 0000000..97933f0 --- /dev/null +++ b/src/main/java/com/telpo/dipperposition/common/RedisUtil.java @@ -0,0 +1,665 @@ +package com.telpo.dipperposition.common; + +import lombok.extern.slf4j.Slf4j; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.stereotype.Component; +import org.springframework.util.CollectionUtils; + +import javax.annotation.Resource; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.TimeUnit; + +/** + * @program: DataPushServer + * @description: redis工具类 + * @author: linwl + * @create: 2020-07-11 10:26 + */ +@Component +@Slf4j +public class RedisUtil { + + @Resource private RedisTemplate redisTemplate; + + // =============================common============================ + /** + * 指定缓存失效时间 + * + * @param key 键 + * @param time 时间(秒) + * @return + */ + public boolean expire(String key, long time) { + try { + if (time > 0) { + redisTemplate.expire(key, time, TimeUnit.SECONDS); + } + return true; + } catch (Exception e) { + log.error(key, e); + return false; + } + } + + /** + * 根据key 获取过期时间 + * + * @param key 键 不能为null + * @return 时间(秒) 返回0代表为永久有效 + */ + public long getExpire(String key) { + return redisTemplate.getExpire(key, TimeUnit.SECONDS); + } + + /** + * 判断key是否存在 + * + * @param key 键 + * @return true 存在 false不存在 + */ + public boolean hasKey(String key) { + try { + return redisTemplate.hasKey(key); + } catch (Exception e) { + log.error(key, e); + return false; + } + } + + /** + * 删除缓存 + * + * @param key 可以传一个值 或多个 + */ + @SuppressWarnings("unchecked") + public void del(String... key) { + if (key != null && key.length > 0) { + if (key.length == 1) { + redisTemplate.delete(key[0]); + } else { + redisTemplate.delete(CollectionUtils.arrayToList(key)); + } + } + } + + // ============================String============================= + /** + * 普通缓存获取 + * + * @param key 键 + * @return 值 + */ + public Object get(String key) { + return key == null ? null : redisTemplate.opsForValue().get(key); + } + + /** + * 普通缓存放入 + * + * @param key 键 + * @param value 值 + * @return true成功 false失败 + */ + public boolean set(String key, Object value) { + try { + redisTemplate.opsForValue().set(key, value); + return true; + } catch (Exception e) { + log.error(key, e); + return false; + } + } + + /** + * 普通缓存放入并设置时间 + * + * @param key 键 + * @param value 值 + * @param time 时间(秒) time要大于0 如果time小于等于0 将设置无限期 + * @return true成功 false 失败 + */ + public boolean set(String key, Object value, long time) { + try { + if (time > 0) { + redisTemplate.opsForValue().set(key, value, time, TimeUnit.SECONDS); + } else { + set(key, value); + } + return true; + } catch (Exception e) { + log.error(key, e); + return false; + } + } + + /** + * 递增 适用场景: https://blog.csdn.net/y_y_y_k_k_k_k/article/details/79218254 高并发生成订单号,秒杀类的业务逻辑等。。 + * + * @param key 键 + * @param delta 要增加几(大于0) + * @return + */ + public long incr(String key, long delta) { + if (delta < 0) { + throw new RuntimeException("递增因子必须大于0"); + } + return redisTemplate.opsForValue().increment(key, delta); + } + + /** + * 递减 + * + * @param key 键 + * @param delta 要减少几(小于0) + * @return + */ + public long decr(String key, long delta) { + if (delta < 0) { + throw new RuntimeException("递减因子必须大于0"); + } + return redisTemplate.opsForValue().increment(key, -delta); + } + + // ================================Map================================= + /** + * HashGet + * + * @param key 键 不能为null + * @param item 项 不能为null + * @return 值 + */ + public Object hget(String key, String item) { + return redisTemplate.opsForHash().get(key, item); + } + + /** + * 获取hashKey对应的所有键值 + * + * @param key 键 + * @return 对应的多个键值 + */ + public Map hmget(String key) { + return redisTemplate.opsForHash().entries(key); + } + + /** + * HashSet + * + * @param key 键 + * @param map 对应多个键值 + * @return true 成功 false 失败 + */ + public boolean hmset(String key, Map map) { + try { + redisTemplate.opsForHash().putAll(key, map); + return true; + } catch (Exception e) { + log.error(key, e); + return false; + } + } + + /** + * HashSet 并设置时间 + * + * @param key 键 + * @param map 对应多个键值 + * @param time 时间(秒) + * @return true成功 false失败 + */ + public boolean hmset(String key, Map map, long time) { + try { + redisTemplate.opsForHash().putAll(key, map); + if (time > 0) { + expire(key, time); + } + return true; + } catch (Exception e) { + log.error(key, e); + return false; + } + } + + /** + * 向一张hash表中放入数据,如果不存在将创建 + * + * @param key 键 + * @param item 项 + * @param value 值 + * @return true 成功 false失败 + */ + public boolean hset(String key, String item, Object value) { + try { + redisTemplate.opsForHash().put(key, item, value); + return true; + } catch (Exception e) { + log.error(key, e); + return false; + } + } + + /** + * 向一张hash表中放入数据,如果不存在将创建 + * + * @param key 键 + * @param item 项 + * @param value 值 + * @param time 时间(秒) 注意:如果已存在的hash表有时间,这里将会替换原有的时间 + * @return true 成功 false失败 + */ + public boolean hset(String key, String item, Object value, long time) { + try { + redisTemplate.opsForHash().put(key, item, value); + if (time > 0) { + expire(key, time); + } + return true; + } catch (Exception e) { + log.error(key, e); + return false; + } + } + + /** + * 删除hash表中的值 + * + * @param key 键 不能为null + * @param item 项 可以使多个 不能为null + */ + public void hdel(String key, Object... item) { + redisTemplate.opsForHash().delete(key, item); + } + + /** + * 判断hash表中是否有该项的值 + * + * @param key 键 不能为null + * @param item 项 不能为null + * @return true 存在 false不存在 + */ + public boolean hHasKey(String key, String item) { + return redisTemplate.opsForHash().hasKey(key, item); + } + + /** + * hash递增 如果不存在,就会创建一个 并把新增后的值返回 + * + * @param key 键 + * @param item 项 + * @param by 要增加几(大于0) + * @return + */ + public double hincr(String key, String item, double by) { + return redisTemplate.opsForHash().increment(key, item, by); + } + + /** + * hash递减 + * + * @param key 键 + * @param item 项 + * @param by 要减少记(小于0) + * @return + */ + public double hdecr(String key, String item, double by) { + return redisTemplate.opsForHash().increment(key, item, -by); + } + + // ============================set============================= + /** + * 根据key获取Set中的所有值 + * + * @param key 键 + * @return + */ + public Set sGet(String key) { + try { + return redisTemplate.opsForSet().members(key); + } catch (Exception e) { + log.error(key, e); + return null; + } + } + + /** + * 根据value从一个set中查询,是否存在 + * + * @param key 键 + * @param value 值 + * @return true 存在 false不存在 + */ + public boolean sHasKey(String key, Object value) { + try { + return redisTemplate.opsForSet().isMember(key, value); + } catch (Exception e) { + log.error(key, e); + return false; + } + } + + /** + * 将数据放入set缓存 + * + * @param key 键 + * @param values 值 可以是多个 + * @return 成功个数 + */ + public long sSet(String key, Object... values) { + try { + return redisTemplate.opsForSet().add(key, values); + } catch (Exception e) { + log.error(key, e); + return 0; + } + } + + /** + * 将set数据放入缓存 + * + * @param key 键 + * @param time 时间(秒) + * @param values 值 可以是多个 + * @return 成功个数 + */ + public long sSetAndTime(String key, long time, Object... values) { + try { + Long count = redisTemplate.opsForSet().add(key, values); + if (time > 0) { + expire(key, time); + } + return count; + } catch (Exception e) { + log.error(key, e); + return 0; + } + } + + /** + * 获取set缓存的长度 + * + * @param key 键 + * @return + */ + public long sGetSetSize(String key) { + try { + return redisTemplate.opsForSet().size(key); + } catch (Exception e) { + log.error(key, e); + return 0; + } + } + + /** + * 移除值为value的 + * + * @param key 键 + * @param values 值 可以是多个 + * @return 移除的个数 + */ + public long setRemove(String key, Object... values) { + try { + Long count = redisTemplate.opsForSet().remove(key, values); + return count; + } catch (Exception e) { + log.error(key, e); + return 0; + } + } + + // ============================zset============================= + /** + * 根据key获取Set中的所有值 + * + * @param key 键 + * @return + */ + public Set zSGet(String key) { + try { + return redisTemplate.opsForSet().members(key); + } catch (Exception e) { + log.error(key, e); + return null; + } + } + + /** + * 根据value从一个set中查询,是否存在 + * + * @param key 键 + * @param value 值 + * @return true 存在 false不存在 + */ + public boolean zSHasKey(String key, Object value) { + try { + return redisTemplate.opsForSet().isMember(key, value); + } catch (Exception e) { + log.error(key, e); + return false; + } + } + + public Boolean zSSet(String key, Object value, double score) { + try { + return redisTemplate.opsForZSet().add(key, value, 2); + } catch (Exception e) { + log.error(key, e); + return false; + } + } + + /** + * 将set数据放入缓存 + * + * @param key 键 + * @param time 时间(秒) + * @param values 值 可以是多个 + * @return 成功个数 + */ + public long zSSetAndTime(String key, long time, Object... values) { + try { + Long count = redisTemplate.opsForSet().add(key, values); + if (time > 0) { + expire(key, time); + } + return count; + } catch (Exception e) { + log.error(key, e); + return 0; + } + } + + /** + * 获取set缓存的长度 + * + * @param key 键 + * @return + */ + public long zSGetSetSize(String key) { + try { + return redisTemplate.opsForSet().size(key); + } catch (Exception e) { + log.error(key, e); + return 0; + } + } + + /** + * 移除值为value的 + * + * @param key 键 + * @param values 值 可以是多个 + * @return 移除的个数 + */ + public long zSetRemove(String key, Object... values) { + try { + Long count = redisTemplate.opsForSet().remove(key, values); + return count; + } catch (Exception e) { + log.error(key, e); + return 0; + } + } + // ===============================list================================= + + /** + * 获取list缓存的内容 取出来的元素 总数 end-start+1 + * + * @param key 键 + * @param start 开始 0 是第一个元素 + * @param end 结束 -1代表所有值 + * @return + */ + public List lGet(String key, long start, long end) { + try { + return redisTemplate.opsForList().range(key, start, end); + } catch (Exception e) { + log.error(key, e); + return null; + } + } + + /** + * 获取list缓存的长度 + * + * @param key 键 + * @return + */ + public long lGetListSize(String key) { + try { + return redisTemplate.opsForList().size(key); + } catch (Exception e) { + log.error(key, e); + return 0; + } + } + + /** + * 通过索引 获取list中的值 + * + * @param key 键 + * @param index 索引 index>=0时, 0 表头,1 第二个元素,依次类推;index<0时,-1,表尾,-2倒数第二个元素,依次类推 + * @return + */ + public Object lGetIndex(String key, long index) { + try { + return redisTemplate.opsForList().index(key, index); + } catch (Exception e) { + log.error(key, e); + return null; + } + } + + /** + * 将list放入缓存 + * + * @param key 键 + * @param value 值 + * @return + */ + public boolean lSet(String key, Object value) { + try { + redisTemplate.opsForList().rightPush(key, value); + return true; + } catch (Exception e) { + log.error(key, e); + return false; + } + } + + /** + * 将list放入缓存 + * + * @param key 键 + * @param value 值 + * @param time 时间(秒) + * @return + */ + public boolean lSet(String key, Object value, long time) { + try { + redisTemplate.opsForList().rightPush(key, value); + if (time > 0) { + expire(key, time); + } + return true; + } catch (Exception e) { + log.error(key, e); + return false; + } + } + + /** + * 将list放入缓存 + * + * @param key 键 + * @param value 值 + * @return + */ + public boolean lSet(String key, List value) { + try { + redisTemplate.opsForList().rightPushAll(key, value); + return true; + } catch (Exception e) { + log.error(key, e); + return false; + } + } + + /** + * 将list放入缓存 + * + * @param key 键 + * @param value 值 + * @param time 时间(秒) + * @return + */ + public boolean lSet(String key, List value, long time) { + try { + redisTemplate.opsForList().rightPushAll(key, value); + if (time > 0) { + expire(key, time); + } + return true; + } catch (Exception e) { + log.error(key, e); + return false; + } + } + + /** + * 根据索引修改list中的某条数据 + * + * @param key 键 + * @param index 索引 + * @param value 值 + * @return + */ + public boolean lUpdateIndex(String key, long index, Object value) { + try { + redisTemplate.opsForList().set(key, index, value); + return true; + } catch (Exception e) { + log.error(key, e); + return false; + } + } + + /** + * 移除N个值为value + * + * @param key 键 + * @param count 移除多少个 + * @param value 值 + * @return 移除的个数 + */ + public long lRemove(String key, long count, Object value) { + try { + Long remove = redisTemplate.opsForList().remove(key, count, value); + return remove; + } catch (Exception e) { + log.error(key, e); + return 0; + } + } +} diff --git a/src/main/java/com/telpo/dipperposition/common/SocketClient.java b/src/main/java/com/telpo/dipperposition/common/SocketClient.java new file mode 100644 index 0000000..79e8e94 --- /dev/null +++ b/src/main/java/com/telpo/dipperposition/common/SocketClient.java @@ -0,0 +1,85 @@ +package com.telpo.dipperposition.common; + +import lombok.extern.slf4j.Slf4j; + +import java.io.*; +import java.net.Socket; +/** + * @program: dipperposition + * @description: socket连接单元 + * @author: king + * @create: 2021-01-14 13:52 + **/ +@Slf4j +public class SocketClient { + //定义一个Socket对象 + Socket socket = null; + + public SocketClient(String host, int port, int timeout) { + try { + //需要服务器的IP地址和端口号,才能获得正确的Socket对象 + socket = new Socket(host, port); + socket.setSoTimeout(timeout); + } catch (IOException e) { + log.error("Socket Connect Error:" + e.getMessage()); + } + } + + public String getOutput() { + try { + OutputStream os = socket.getOutputStream(); + return os.toString(); + } catch (IOException e) { + log.error("Socket getOutputStream Error:" + e.getMessage()); + return null; + } + } + + + public String sendCmd(String astCmd, String ackAckCheckRef) { + try { + OutputStream os=socket.getOutputStream(); + PrintWriter pw=new PrintWriter(os); + // TODO 发生命令 + String info="用户名:Tom,用户密码:123456"; + pw.write(astCmd); + pw.flush(); + socket.shutdownOutput(); + + //接收服务器的相应 + String reply=null; + //输入流 + InputStream is=socket.getInputStream(); + BufferedReader br=new BufferedReader(new InputStreamReader(is)); + + String ackResult=""; + String ackHexOut = HexConvert.convertStringToHex(ackAckCheckRef); + while(!((reply=br.readLine())==null)){ + log.debug("接收服务器的信息:"+reply); + if (ackHexOut.equals(reply)) { + reply=br.readLine(); + ackResult = HexConvert.convertHexToString(reply); + break; + } + } + //4.关闭资源 + br.close(); + is.close(); + pw.close(); + os.close(); + return ackResult; + } catch (IOException e) { + log.error("Socket sendCmd Error:" + e.getMessage()); + return null; + } + } + + public void closeConnection() { + try { + socket.close(); + //socket.shutdownOutput(); + } catch (IOException e) { + log.error("Socket getOutputStream Error:" + e.getMessage()); + } + } +} diff --git a/src/main/java/com/telpo/dipperposition/common/TimeTools.java b/src/main/java/com/telpo/dipperposition/common/TimeTools.java new file mode 100644 index 0000000..f23879c --- /dev/null +++ b/src/main/java/com/telpo/dipperposition/common/TimeTools.java @@ -0,0 +1,39 @@ +package com.telpo.dipperposition.common; + +import tools.CommonTools; + +import java.time.LocalTime; +import java.time.format.DateTimeFormatter; + +/** + * @program: DataPushServer + * @description: 时间工具类 + * @author: linwl + * @create: 2020-08-05 11:16 + */ +public class TimeTools { + + private TimeTools() {} + + /** + * 校验时间段 + * + * @param startTime 起始时间 HH:mm + * @param endTime 结束时间 HH:mm + * @return + */ + public static boolean checkTime(String startTime, String endTime) { + boolean result = false; + DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("HH:mm"); + LocalTime pushStartTime = LocalTime.parse(startTime, dateTimeFormatter); + LocalTime pushEndTime = LocalTime.parse(endTime, dateTimeFormatter); + LocalTime zeroTime = LocalTime.parse("00:00"); + if (zeroTime.equals(pushEndTime)) { + pushEndTime = pushEndTime.plusNanos(-10); + } + if (CommonTools.checkInTime(pushStartTime, pushEndTime)) { + result = true; + } + return result; + } +} diff --git a/src/main/java/com/telpo/dipperposition/config/PositionConfig.java b/src/main/java/com/telpo/dipperposition/config/PositionConfig.java index 34b9059..d9faef3 100644 --- a/src/main/java/com/telpo/dipperposition/config/PositionConfig.java +++ b/src/main/java/com/telpo/dipperposition/config/PositionConfig.java @@ -1,22 +1,11 @@ package com.telpo.dipperposition.config; -import com.alibaba.nacos.api.NacosFactory; -import com.alibaba.nacos.api.PropertyKeyConst; -import com.alibaba.nacos.api.config.ConfigService; -import com.telpo.dipperposition.co.RzlAccount; import lombok.Getter; import lombok.Setter; import lombok.ToString; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.beans.factory.config.ConfigurableBeanFactory; -import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Lazy; -import org.springframework.context.annotation.Scope; - -import java.util.Properties; /** * @program: gateway diff --git a/src/main/java/com/telpo/dipperposition/config/db/MongoDbContext.java b/src/main/java/com/telpo/dipperposition/config/db/MongoDbContext.java new file mode 100644 index 0000000..f27c529 --- /dev/null +++ b/src/main/java/com/telpo/dipperposition/config/db/MongoDbContext.java @@ -0,0 +1,66 @@ +package com.telpo.dipperposition.config.db; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Bean; +import org.springframework.data.mongodb.MongoDbFactory; +import org.springframework.data.mongodb.core.SimpleMongoClientDbFactory; +import org.springframework.stereotype.Component; +import org.springframework.util.CollectionUtils; + +import javax.annotation.PostConstruct; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; + +/** + * @program: DataPushServer + * @description: mongdb数据库连接上下文 + * @author: linwl + * @create: 2020-07-11 14:31 + */ +@Component +public class MongoDbContext { + + private static final Map MONGO_CLIENT_DB_FACTORY_MAP = new HashMap<>(); + private static final ThreadLocal MONGO_DB_FACTORY_THREAD_LOCAL = + new ThreadLocal<>(); + @Autowired + MongoListProperties mongoListProperties; + + public static MongoDbFactory getMongoDbFactory() { + return MONGO_DB_FACTORY_THREAD_LOCAL.get(); + } + + public static void setMongoDbFactory(String name) { + MONGO_DB_FACTORY_THREAD_LOCAL.set(MONGO_CLIENT_DB_FACTORY_MAP.get(name)); + } + + public static void removeMongoDbFactory() { + MONGO_DB_FACTORY_THREAD_LOCAL.remove(); + } + + @PostConstruct + public void afterPropertiesSet() { + if (!CollectionUtils.isEmpty(mongoListProperties.getDblist())) { + mongoListProperties + .getDblist() + .forEach( + info -> { + MONGO_CLIENT_DB_FACTORY_MAP.put( + info.getDatabase(), new SimpleMongoClientDbFactory(info.getUri())); + }); + } + } + + @Bean(name = "mongoTemplate") + public MultiMongoTemplate dynamicMongoTemplate() { + Iterator iterator = MONGO_CLIENT_DB_FACTORY_MAP.values().iterator(); + return new MultiMongoTemplate(iterator.next()); + } + + @Bean(name = "mongoDbFactory") + public MongoDbFactory mongoDbFactory() { + Iterator iterator = MONGO_CLIENT_DB_FACTORY_MAP.values().iterator(); + return iterator.next(); + } +} diff --git a/src/main/java/com/telpo/dipperposition/config/db/MongoListProperties.java b/src/main/java/com/telpo/dipperposition/config/db/MongoListProperties.java new file mode 100644 index 0000000..804eff3 --- /dev/null +++ b/src/main/java/com/telpo/dipperposition/config/db/MongoListProperties.java @@ -0,0 +1,30 @@ +package com.telpo.dipperposition.config.db; + +import lombok.Data; +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; +import org.springframework.boot.context.properties.ConfigurationProperties; + +import java.util.List; + +/** + * @program: DataPushServer + * @description: mongo连接配置类 + * @author: linwl + * @create: 2020-07-11 14:41 + */ +@Getter +@Setter +@ToString +@ConfigurationProperties(prefix = "mongo.datasource") +public class MongoListProperties { + + private List dblist; + + @Data + public static class MongoList { + private String uri; + private String database; + } +} diff --git a/src/main/java/com/telpo/dipperposition/config/db/MultiMongoTemplate.java b/src/main/java/com/telpo/dipperposition/config/db/MultiMongoTemplate.java new file mode 100644 index 0000000..df79df4 --- /dev/null +++ b/src/main/java/com/telpo/dipperposition/config/db/MultiMongoTemplate.java @@ -0,0 +1,26 @@ +package com.telpo.dipperposition.config.db; + +import com.mongodb.client.MongoDatabase; +import lombok.extern.slf4j.Slf4j; +import org.springframework.data.mongodb.MongoDbFactory; +import org.springframework.data.mongodb.core.MongoTemplate; + +/** + * @program: DataPushServer + * @description: 多mongo数据源配置 + * @author: linwl + * @create: 2020-07-11 14:21 + */ +@Slf4j +public class MultiMongoTemplate extends MongoTemplate { + + public MultiMongoTemplate(MongoDbFactory mongoDbFactory) { + super(mongoDbFactory); + } + + @Override + protected MongoDatabase doGetDatabase() { + MongoDbFactory mongoDbFactory = MongoDbContext.getMongoDbFactory(); + return mongoDbFactory == null ? super.doGetDatabase() : mongoDbFactory.getDb(); + } +} diff --git a/src/main/java/com/telpo/dipperposition/controller/DipperPositionController.java b/src/main/java/com/telpo/dipperposition/controller/DipperPositionController.java index 4783081..df2e40f 100644 --- a/src/main/java/com/telpo/dipperposition/controller/DipperPositionController.java +++ b/src/main/java/com/telpo/dipperposition/controller/DipperPositionController.java @@ -1,23 +1,10 @@ package com.telpo.dipperposition.controller; -import com.alibaba.cloud.nacos.parser.NacosDataParserHandler; -import com.alibaba.nacos.api.PropertyKeyConst; -import com.alibaba.nacos.api.exception.NacosException; -import com.telpo.dipperposition.co.RzlAccount; -import com.telpo.dipperposition.config.PositionConfig; import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; -import java.io.IOException; -import java.util.Map; -import java.util.Properties; -import java.util.concurrent.Executor; -import com.alibaba.nacos.api.NacosFactory; -import com.alibaba.nacos.api.config.ConfigService; -import com.alibaba.nacos.api.config.listener.Listener; /** * @program: DipperPositionController @@ -33,22 +20,7 @@ public class DipperPositionController { //RzlAccount rzlAccount; @RequestMapping("/getPos") - public String getPos() throws NacosException, InterruptedException, IOException { -// String group = "DEFAULT_GROUP"; -// String dataId = "dipperposition-service"; -// String positionId = "position.hello"; -// Properties properties = new Properties(); -// String serverAddr = "172.16.192.26"; -// properties.put(PropertyKeyConst.SERVER_ADDR, serverAddr); -// ConfigService configService = NacosFactory.createConfigService(properties); -// String content = configService.getConfig(dataId, group, 10000); -// System.out.println(content); -// //log.info(positionId + ":" + content.positionId) -// Map dataMap = NacosDataParserHandler.getInstance().parseNacosData(content,"yaml"); -// return dataMap == null ? "" : (String)dataMap.get(positionId); - String returnStr= "return position = " + hello; - - return returnStr; - //return "Helle world!"; //ContextLoader.getCurrentWebApplicationContext().toString(); + public String getPos() { + return "return position = " + hello; } } diff --git a/src/main/java/com/telpo/dipperposition/entity/mongo/IPProvinceEntity.java b/src/main/java/com/telpo/dipperposition/entity/mongo/IPProvinceEntity.java new file mode 100644 index 0000000..d9f27df --- /dev/null +++ b/src/main/java/com/telpo/dipperposition/entity/mongo/IPProvinceEntity.java @@ -0,0 +1,24 @@ +package com.telpo.dipperposition.entity.mongo; + +import com.telpo.dipperposition.vo.IPProvinceVo; +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; +import models.BaseMongoDbEntity; + +/** + * @program: IPProvinceEntity + * @description: 位置实体类 + * @author: linwl + * @create: 2020-07-11 15:33 + */ +@ToString +@Getter +@Setter +public class IPProvinceEntity extends BaseMongoDbEntity { + + /** Ip */ + private String ip; + /** Ip所在省份 */ + private String province; +} diff --git a/src/main/java/com/telpo/dipperposition/enums/DipperReturnValue.java b/src/main/java/com/telpo/dipperposition/enums/DipperReturnValue.java new file mode 100644 index 0000000..68fa68f --- /dev/null +++ b/src/main/java/com/telpo/dipperposition/enums/DipperReturnValue.java @@ -0,0 +1,53 @@ +package com.telpo.dipperposition.enums; + +/** + * @program: DipperReturnValue + * @description: 推送类型枚举 + * @author: king + * @create: 2021-01-24 11:44 + */ +public enum DipperReturnValue { + ACK(0, "SDBP-PUB–ACK"), + NACK(1, "SDBP-PUB–NACK"); + + /** 状态值 */ + private int value; + /** 描述 */ + private String describe; + + private DipperReturnValue(int value, String describe) { + this.value = value; + this.describe = describe; + } + + /** + * 获取推送类型 + * + * @param value + * @return + */ + public static DipperReturnValue getByValue(int value) { + for (DipperReturnValue enums : DipperReturnValue.values()) { + if (enums.getValue() == value) { + return enums; + } + } + return null; + } + + public int getValue() { + return value; + } + + public void setValue(int value) { + this.value = value; + } + + public String getDescribe() { + return describe; + } + + public void setDescribe(String describe) { + this.describe = describe; + } +} diff --git a/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java b/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java new file mode 100644 index 0000000..2549967 --- /dev/null +++ b/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java @@ -0,0 +1,145 @@ +package com.telpo.dipperposition.handler; + +import com.telpo.dipperposition.enums.DipperReturnValue; +import com.telpo.dipperposition.service.IDipperAstPosAsyncTaskService; +import com.telpo.dipperposition.service.IDipperAstTimeAsyncTaskService; +import com.telpo.dipperposition.service.IDipperDataAsyncTaskService; +import io.netty.buffer.ByteBuf; +import io.netty.buffer.Unpooled; +import io.netty.channel.socket.SocketChannel; +import io.netty.channel.ChannelHandlerContext; +import io.netty.channel.ChannelInboundHandlerAdapter; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; + +import java.time.LocalDateTime; + +/** + * @program: dipperposition + * @description: Netty服务器处理句柄 + * @author: linwl + * @create: 2021-01-13 13:56 + **/ +@Slf4j +public class NettyServerHandler extends ChannelInboundHandlerAdapter { + + + @Autowired + private IDipperAstTimeAsyncTaskService dipperTimeAsyncTaskService; + @Autowired + private IDipperAstPosAsyncTaskService dipperAstPosAsyncTaskService; + @Autowired + private IDipperDataAsyncTaskService dipperDataAsyncTaskService; + + @Value(value = "${position.server.timeAsycPort}") + private String timeAsycServerPort; + + @Value(value = "${position.server.posAsycPort}") + private String posAsycServerPort; + + @Value(value = "${position.server.starsAsycPort}") + private String starsAsycServerPort; + /** + * 客户端连接会触发 + */ + @Override + public void channelActive(ChannelHandlerContext ctx) throws Exception { + log.info("Channel active......"); + + SocketChannel channel = (SocketChannel) ctx.channel(); + log.info("链接报告开始"); + log.info("链接报告信息:有一客户端链接到本服务端"); + log.info("链接报告IP:" + channel.localAddress().getHostString()); + log.info("链接报告Port:" + channel.localAddress().getPort()); + log.info("链接报告完毕"); + //通知客户端链接建立成功 + // 默认返回取得时间成功 + String ackAckCheckRef = "233E0101020004020A1D"; + if (Integer.parseInt(posAsycServerPort) == channel.localAddress().getPort()) { + ackAckCheckRef = "233E010102000401091C"; + } + if (Integer.parseInt(starsAsycServerPort) == channel.localAddress().getPort()) { + ackAckCheckRef = "233E010102000421293C"; + } + //String str = "通知客户端链接建立成功" + " " + LocalDateTime.now() + " " + channel.localAddress().getHostString() + + // "\r\n"; + ByteBuf buf = Unpooled.buffer(ackAckCheckRef.getBytes().length); + buf.writeBytes(ackAckCheckRef.getBytes("GBK")); + ctx.writeAndFlush(buf); + } + + + /** + * 当客户端主动断开服务端的链接后,这个通道就是不活跃的。也就是说客户端与服务端的关闭了通信通道并且不可以传输数据 + */ + @Override + public void channelInactive(ChannelHandlerContext ctx) throws Exception { + log.info("客户端断开链接,IP:{}", ctx.channel().localAddress().toString()); + } + + /** + * 客户端发消息会触发 + */ + @Override + public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { + //接收msg消息{与上一章节相比,此处已经不需要自己进行解码} + SocketChannel channel = (SocketChannel) ctx.channel(); + String ipAddress = channel.remoteAddress().toString(); + String message = " 接收到消息:{0}, 客户端IP:{1}"; + log.info(message ,msg, ipAddress); + + String channelAns = ""; + // 返回时间指令 + if (Integer.parseInt(timeAsycServerPort) == channel.localAddress().getPort()) { + // 初始时间辅助输入; + channelAns = dipperTimeAsyncTaskService.pushAstTime(); + } + + // 发送SDBP-AST-POS获取辅助位置信息 + if (Integer.parseInt(posAsycServerPort) == channel.localAddress().getPort()) { + channelAns = dipperAstPosAsyncTaskService.pushAstPos(ipAddress); + } + + // 从缓存获取SDBP-AST-EPH星历数 + if (Integer.parseInt(starsAsycServerPort) == channel.localAddress().getPort()) { + channelAns = dipperDataAsyncTaskService.getAstEPH(); + } + + + // 最后把SDBP-AST-TIME、SDBP-AST-POS、SDBP-AST-EPH并包一起发给设备。 + // 设备采用16进制获取数据,则代理服务器也是采用16进制返回数据。 + // 通知客户端链消息发送成功 + // String str = "服务端收到:" + LocalDateTime.now() + " " + msg + "\r\n"; + ByteBuf buf = Unpooled.buffer(channelAns.getBytes().length); + buf.writeBytes(channelAns.getBytes("GBK")); + ctx.writeAndFlush(buf); + //ctx.write("你也好哦"); + //ctx.flush(); + } + +// @Override +// public void channelRead0(ChannelHandlerContext ctx, HttpObject msg) +// throws Exception { +// if (msg instanceof HttpRequest) { +// HttpRequest mReq = (HttpRequest) msg; +// String clientIP = mReq.headers().get("X-Forwarded-For"); +// if (clientIP == null) { +// InetSocketAddress insocket = (InetSocketAddress) ctx.channel() +// .remoteAddress(); +// clientIP = insocket.getAddress().getHostAddress(); +// } +// } +// } + + /** + * 发生异常触发 + */ + @Override + public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { + cause.printStackTrace(); + ctx.close(); + } + + +} diff --git a/src/main/java/com/telpo/dipperposition/handler/ServerChannelInitializer.java b/src/main/java/com/telpo/dipperposition/handler/ServerChannelInitializer.java new file mode 100644 index 0000000..95d98dd --- /dev/null +++ b/src/main/java/com/telpo/dipperposition/handler/ServerChannelInitializer.java @@ -0,0 +1,24 @@ +package com.telpo.dipperposition.handler; + +import io.netty.channel.ChannelInitializer; +import io.netty.channel.ChannelPipeline; +import io.netty.channel.socket.SocketChannel; +import io.netty.handler.codec.string.StringDecoder; +import io.netty.handler.codec.string.StringEncoder; +import io.netty.util.CharsetUtil; +/** + * @program: dipperposition + * @description: 服务器通道初始化 + * @author: king + * @create: 2021-01-13 13:54 + **/ +public class ServerChannelInitializer extends ChannelInitializer { + @Override + protected void initChannel(SocketChannel socketChannel) throws Exception { + //添加编解码 + socketChannel.pipeline().addLast("decoder", new StringDecoder(CharsetUtil.UTF_8)); + socketChannel.pipeline().addLast("encoder", new StringEncoder(CharsetUtil.UTF_8)); + socketChannel.pipeline().addLast(new NettyServerHandler()); + } + +} diff --git a/src/main/java/com/telpo/dipperposition/mapper/IPProvinceMapper.java b/src/main/java/com/telpo/dipperposition/mapper/IPProvinceMapper.java new file mode 100644 index 0000000..b42acc0 --- /dev/null +++ b/src/main/java/com/telpo/dipperposition/mapper/IPProvinceMapper.java @@ -0,0 +1,52 @@ +package com.telpo.dipperposition.mapper; + +import com.telpo.dipperposition.entity.mongo.IPProvinceEntity; +import db.BaseMongoDbDao; +import org.springframework.stereotype.Repository; + +import java.util.List; + +/** + * @program: DataPushServer + * @description: 推送记录mapper + * @author: linwl + * @create: 2020-07-20 11:12 + */ +@Repository +public class IPProvinceMapper extends BaseMongoDbDao { + + @Override + protected Class getEntityClass() { + return IPProvinceEntity.class; + } + + @Override + public void save(IPProvinceEntity entity, String collectionName) { + super.save(entity, collectionName); + } + + @Override + public void updateFirst(IPProvinceEntity srcObj, IPProvinceEntity targetObj) { + super.updateFirst(srcObj, targetObj); + } + + @Override + public List getPage(IPProvinceEntity object, int start, int size) { + return super.getPage(object, start, size); + } + + @Override + public List queryList(IPProvinceEntity object) { + return super.queryList(object); + } + + @Override + public List queryList(IPProvinceEntity object, String collectionName) { + return super.queryList(object, collectionName); + } + + @Override + public void deleteById(String id) { + super.deleteById(id); + } +} diff --git a/src/main/java/com/telpo/dipperposition/server/DipperPositionServer.java b/src/main/java/com/telpo/dipperposition/server/DipperPositionServer.java new file mode 100644 index 0000000..6afdc44 --- /dev/null +++ b/src/main/java/com/telpo/dipperposition/server/DipperPositionServer.java @@ -0,0 +1,153 @@ +package com.telpo.dipperposition.server; + +import com.telpo.dipperposition.handler.ServerChannelInitializer; +import com.telpo.dipperposition.service.IDipperDataAsyncTaskService; +import io.netty.bootstrap.ServerBootstrap; +import io.netty.channel.ChannelFuture; +import io.netty.channel.ChannelOption; +import io.netty.channel.EventLoopGroup; +import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.socket.nio.NioServerSocketChannel; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; + +import java.net.InetSocketAddress; + + +/** + * @program: DipperPositionServer + * @description: 北斗定位 + * @author: king + * @create: 2021-01-13 14:01 + */ +@Slf4j +public class DipperPositionServer { + + @Value(value = "${position.serverAddr}") + private String serverAddr; + + @Value(value = "${position.server.timeAsycPort}") + private String timeAsycServerPort; + + @Value(value = "${position.server.posAsycPort}") + private String posAsycServerPort; + + @Value(value = "${position.server.starsAsycPort}") + private String starsAsycServerPort; + + /* + * 时间同步进程线程 + */ + public void startTimeAsnc() { + + //new 一个主线程组 + EventLoopGroup mainThreadGroup = new NioEventLoopGroup(1); + //new 一个工作线程组 + EventLoopGroup workThreadGroup = new NioEventLoopGroup(200); + InetSocketAddress socketAddress = new InetSocketAddress(serverAddr, Integer.parseInt(timeAsycServerPort)); + ServerBootstrap bootstrap = new ServerBootstrap() + .group(mainThreadGroup, workThreadGroup) + .channel(NioServerSocketChannel.class) + .childHandler(new ServerChannelInitializer()) + .localAddress(socketAddress) + //设置队列大小 + .option(ChannelOption.SO_BACKLOG, 1024) + // 两小时内没有数据的通信时,TCP会自动发送一个活动探测数据报文 + .childOption(ChannelOption.SO_KEEPALIVE, true); + + + //绑定端口,开始接收进来的连接 + try { + ChannelFuture future = bootstrap.bind(socketAddress).sync(); + log.info("服务器启动开始监听端口: {}", socketAddress.getPort()); + + + future.channel().closeFuture().sync(); + } catch (InterruptedException e) { + e.printStackTrace(); + } finally { + //关闭主线程组 + mainThreadGroup.shutdownGracefully(); + //关闭工作线程组 + workThreadGroup.shutdownGracefully(); + } + } + + /* + * 时间同步进程线程 + */ + public void startPosAsnc() { + + //new 一个主线程组 + EventLoopGroup mainThreadGroup = new NioEventLoopGroup(1); + //new 一个工作线程组 + EventLoopGroup workThreadGroup = new NioEventLoopGroup(200); + InetSocketAddress socketAddress = new InetSocketAddress(serverAddr, Integer.parseInt(posAsycServerPort)); + ServerBootstrap bootstrap = new ServerBootstrap() + .group(mainThreadGroup, workThreadGroup) + .channel(NioServerSocketChannel.class) + .childHandler(new ServerChannelInitializer()) + .localAddress(socketAddress) + //设置队列大小 + .option(ChannelOption.SO_BACKLOG, 1024) + // 两小时内没有数据的通信时,TCP会自动发送一个活动探测数据报文 + .childOption(ChannelOption.SO_KEEPALIVE, true); + + + //绑定端口,开始接收进来的连接 + try { + ChannelFuture future = bootstrap.bind(socketAddress).sync(); + log.info("服务器启动开始监听端口: {}", socketAddress.getPort()); + + + future.channel().closeFuture().sync(); + } catch (InterruptedException e) { + e.printStackTrace(); + } finally { + //关闭主线程组 + mainThreadGroup.shutdownGracefully(); + //关闭工作线程组 + workThreadGroup.shutdownGracefully(); + } + } + + + /* + * 星历同步进程线程 + */ + public void startStarsAsnc() { + + //new 一个主线程组 + EventLoopGroup mainThreadGroup = new NioEventLoopGroup(1); + //new 一个工作线程组 + EventLoopGroup workThreadGroup = new NioEventLoopGroup(200); + InetSocketAddress socketAddress = new InetSocketAddress(serverAddr, Integer.parseInt(starsAsycServerPort)); + ServerBootstrap bootstrap = new ServerBootstrap() + .group(mainThreadGroup, workThreadGroup) + .channel(NioServerSocketChannel.class) + .childHandler(new ServerChannelInitializer()) + .localAddress(socketAddress) + //设置队列大小 + .option(ChannelOption.SO_BACKLOG, 1024) + // 两小时内没有数据的通信时,TCP会自动发送一个活动探测数据报文 + .childOption(ChannelOption.SO_KEEPALIVE, true); + + + //绑定端口,开始接收进来的连接 + try { + ChannelFuture future = bootstrap.bind(socketAddress).sync(); + log.info("服务器启动开始监听端口: {}", socketAddress.getPort()); + + + future.channel().closeFuture().sync(); + } catch (InterruptedException e) { + e.printStackTrace(); + } finally { + //关闭主线程组 + mainThreadGroup.shutdownGracefully(); + //关闭工作线程组 + workThreadGroup.shutdownGracefully(); + } + } +} diff --git a/src/main/java/com/telpo/dipperposition/service/IDipperAstPosAsyncTaskService.java b/src/main/java/com/telpo/dipperposition/service/IDipperAstPosAsyncTaskService.java new file mode 100644 index 0000000..c5e2006 --- /dev/null +++ b/src/main/java/com/telpo/dipperposition/service/IDipperAstPosAsyncTaskService.java @@ -0,0 +1,23 @@ +package com.telpo.dipperposition.service; + +import java.io.UnsupportedEncodingException; + +/** + * @program: IDipperAstPosAsyncTaskService + * @description: 系统预先基于省份的省会城市的经纬度作为辅助信息, + * 根据设备请求的IP地址,从高德IP定位服务获取相关的省份,再匹配相应的位置信息作为辅助位置信息。 + * 如果匹配不到省份,则以武汉中心作为辅助为位置信息。 + * 关于IP与省份的关系保存到缓存中,用于下次使用时,先在缓存中获取匹配信息,匹配不到,再请求高德IP定位服务。 + * 高德IP定位服务:https://lbs.amap.com/api/webservice/guide/api/ipconfig。 + * @author: king + * @create: 2021-01-17 16:24 + */ +public interface IDipperAstPosAsyncTaskService { + + /** + * 同步任务 + * + */ + String pushAstPos(String ipAddress) throws UnsupportedEncodingException; + +} diff --git a/src/main/java/com/telpo/dipperposition/service/IDipperAstTimeAsyncTaskService.java b/src/main/java/com/telpo/dipperposition/service/IDipperAstTimeAsyncTaskService.java new file mode 100644 index 0000000..5dfeb0e --- /dev/null +++ b/src/main/java/com/telpo/dipperposition/service/IDipperAstTimeAsyncTaskService.java @@ -0,0 +1,17 @@ +package com.telpo.dipperposition.service; + +/** + * @program: IDipperDataAsyncTaskService + * @description: 发送SDBP-AST-TIME获取时间信息 + * @author: king + * @create: 2021-01-17 16:24 + */ +public interface IDipperAstTimeAsyncTaskService { + + /** + * 同步任务 + * + */ + String pushAstTime(); + +} diff --git a/src/main/java/com/telpo/dipperposition/service/IDipperDataAsyncTaskService.java b/src/main/java/com/telpo/dipperposition/service/IDipperDataAsyncTaskService.java new file mode 100644 index 0000000..f050b9c --- /dev/null +++ b/src/main/java/com/telpo/dipperposition/service/IDipperDataAsyncTaskService.java @@ -0,0 +1,26 @@ +package com.telpo.dipperposition.service; + +/** + * @program: IDipperDataAsyncTaskService + * @description: 发送bds获取星历数据。 + * * 每30分钟获取1次,30秒超时, + * * 如果失败,则可以等待10秒再获取1次 + * @author: king + * @create: 2021-01-17 16:24 + */ +public interface IDipperDataAsyncTaskService { + + /** + * 同步任务 + * + */ + void pullAstEPH(); + + + /** + * 根据IP获取EPH + * + */ + String getAstEPH(); + +} diff --git a/src/main/java/com/telpo/dipperposition/service/IPProvinceService.java b/src/main/java/com/telpo/dipperposition/service/IPProvinceService.java new file mode 100644 index 0000000..f8e3c66 --- /dev/null +++ b/src/main/java/com/telpo/dipperposition/service/IPProvinceService.java @@ -0,0 +1,45 @@ +package com.telpo.dipperposition.service; + +import com.telpo.dipperposition.entity.mongo.IPProvinceEntity; +import com.telpo.dipperposition.vo.IPProvinceVo; + +/** + * @program: IPProvinceService + * @description: IP省份服务接口 + * @author: king + * @create: 2020-07-20 11:09 + */ +public interface IPProvinceService { + + /** + * 保存IP省份 + * + * @param entity + * @return + */ + boolean saveIPProvince(IPProvinceEntity entity); + + /** + * 更新IP省份 + * + * @param query + * @param update + * @return + */ + boolean updateIPProvince( + IPProvinceEntity query, IPProvinceEntity update); + + /** + * 根据ID移除IP省份记录 + * + * @param id + * @return + */ + boolean romveById(String id); + + /* + * @param ipAddress + * 获取IP省份 + */ + IPProvinceEntity getIPProvince(String ipAddress); +} diff --git a/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java b/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java new file mode 100644 index 0000000..fc1831e --- /dev/null +++ b/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java @@ -0,0 +1,251 @@ +package com.telpo.dipperposition.service.impl; + +import com.alibaba.fastjson.JSONObject; +import com.google.common.base.Joiner; +import com.telpo.dipperposition.common.*; +import com.telpo.dipperposition.entity.mongo.IPProvinceEntity; +import com.telpo.dipperposition.mapper.IPProvinceMapper; +import com.telpo.dipperposition.service.IDipperAstPosAsyncTaskService; +import com.telpo.dipperposition.service.IPProvinceService; +import com.telpo.dipperposition.vo.IPProvinceVo; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.ObjectUtils; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.scheduling.annotation.Async; +import org.springframework.stereotype.Service; + +import java.io.UnsupportedEncodingException; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; +import java.util.List; + +/** + * @program: DipperAstPosAsyncTaskServiceImpl + * @description: 系统预先基于省份的省会城市的经纬度作为辅助信息, + * * 根据设备请求的IP地址,从高德IP定位服务获取相关的省份,再匹配相应的位置信息作为辅助位置信息。 + * * 如果匹配不到省份,则以武汉中心作为辅助为位置信息。 + * * 关于IP与省份的关系保存到缓存中,用于下次使用时,先在缓存中获取匹配信息,匹配不到,再请求高德IP定位服务。 + * * 高德IP定位服务:https://lbs.amap.com/api/webservice/guide/api/ipconfig。 + * @author: king + * @create: 2021-01-10 14:01 + */ +@Service +@Slf4j +public class DipperAstPosAsyncTaskServiceImpl implements IDipperAstPosAsyncTaskService { + + @Autowired + private RedisUtil redisUtil; + @Autowired + private OkHttpUtil okHttpUtil; + @Autowired + private IPProvinceService iPProvinceService; + + @Value("${pos.centerProvinceFilePath}") + String centerProvinceFilePath; + + @Value("${pos.ipPositionRequestPath}") + String ipPositionRequestPath; + @Value("${pos.ipPositionRequestKey}") + String ipPositionRequestKey; + @Value("${pos.centerProvince}") + String centerProvince; + + + @Value("${pos.ast.server}") + String astServer; + @Value("${pos.ast.posAstPort}") + int posAstPort; + @Value("${pos.ast.timeout}") + int astTimeout; + +// private String getAstPos(String ipAddress) throws UnsupportedEncodingException { +// +// String centerAddress = getIpPositionProvince(ipAddress); +// if (ObjectUtils.isEmpty(centerAddress) || centerAddress.equals("0")) { +// log.warn("IP地址非法,无法获取辅助位置信息!"); +// // 返回武汉的定位数据 +// centerAddress = centerProvince; +// } else { +// // 保存到mongoDB +// createIPProvince(ipAddress, centerAddress); +// } +// +// String lonAndAlt; +// if (redisUtil.hasKey(centerAddress)) { +// // 获取省会城市定位信息 +// lonAndAlt= (String) redisUtil.get(centerAddress); +// } else { +// // 请求高德IP定位服务 +// this.getPosFromFile(centerAddress); +// lonAndAlt = (String) redisUtil.get(centerAddress); +// } +// +// return lonAndAlt; +// } + + // 从CSV文件读取省会城市中心点位置信息 + private void getPosFromFile(String centerAddress) { + // 不存在说明token是已过期了 + String centerProvinceName = ""; + String centerProvinceLonAndAlt = ""; + List centerAddressSets = CSVUtil.readCSV(centerProvinceFilePath); + for (String centerAddressSet:centerAddressSets) { + String[] centerAddressSetArray = centerAddressSet.split(","); + if (centerAddressSetArray.length < 3) { + log.warn("CSV数据格式错误"); + } else { + centerProvinceName = centerAddressSetArray[3]; + centerProvinceLonAndAlt = centerAddressSetArray[1]+","+centerAddressSetArray[2]; + redisUtil.set(centerProvinceName, centerProvinceLonAndAlt, 0); + } + } + } + + // 根据IP获取省会信息 + private String getIpPositionProvince(String ipAddress) { + + // 关于IP与省份的关系保存到缓存中 + // 使用时,先在缓存中获取匹配信息 + // 用mongodb实现 + IPProvinceEntity ipProvinceEntity = iPProvinceService.getIPProvince(ipAddress); + if (ipProvinceEntity == null) { + // 匹配不到,再请求高德IP定位服务。 + JSONObject userObj = new JSONObject(); + userObj.put("ip", ipAddress); + userObj.put("key", ipPositionRequestKey); + + JSONObject json = okHttpUtil.postRequestWithJson(ipPositionRequestPath, null, userObj); + if (ObjectUtils.isNotEmpty(json)) { + String province = (String) json.get("province"); + if (ObjectUtils.isEmpty(province)) { + log.debug("json is :" + json.toString()); + return null; + } + return province; + } else { + // 意外错误 + log.debug("ip address is null"); + return null; + } + } else { + return ipProvinceEntity.getProvince(); + } + } + + // 将IP对应的省会保存到mongoDB + private void createIPProvince(String ipAddress, String province) { + log.debug("异步创建推送失败任务记录!"); + try { + IPProvinceEntity ipProvinceEntity = iPProvinceService.getIPProvince(ipAddress); + if (ipProvinceEntity == null) { + //DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); + ipProvinceEntity.setIp(ipAddress); + ipProvinceEntity.setProvince(province); + iPProvinceService.saveIPProvince(ipProvinceEntity); + } else { + + ipProvinceEntity.setProvince(province); + iPProvinceService.updateIPProvince(ipProvinceEntity, ipProvinceEntity); + } + } catch (Exception e) { + log.error("创建推送失败记录异常:", e); + } + } + + /* + * 获取定位辅助信息 + * @param ipAddress + */ + @Override + public String pushAstPos(String ipAddress) throws UnsupportedEncodingException { + // (1) 获取省会城市信息 + String centerAddress = getIpPositionProvince(ipAddress); + if (ObjectUtils.isEmpty(centerAddress) || centerAddress.equals("0")) { + log.warn("IP地址非法,无法获取辅助位置信息!"); + // 返回武汉的定位数据 + centerAddress = centerProvince; + } else { + // 保存到mongoDB + createIPProvince(ipAddress, centerAddress); + } + + String lonAndAlt; + if (redisUtil.hasKey(centerAddress)) { + // 获取省会城市定位信息 + lonAndAlt= (String) redisUtil.get(centerAddress); + } else { + // 请求高德IP定位服务 + this.getPosFromFile(centerAddress); + lonAndAlt = (String) redisUtil.get(centerAddress); + } + + // (2) 处理返回结果 + if (lonAndAlt == null) { + // null处理 + log.error("系统错误,请联系系统管理员。"); + return null; + //return; + } + + // push to GNNS Server + String pushResult = getCmdOfPos(lonAndAlt); + return pushResult; + } + + // 组装命令发送给设备 + private String getCmdOfPos(String astPos) { + + // 创建Socket客户端实例; + // SocketClient client = new SocketClient(astServer, posAstPort, astTimeout); + + // 时间和位置不是从服务器获取,而是本地生成 + String[] astPosArray = astPos.split(","); + String lan = astPosArray[0].trim(); + String alt = astPosArray[1].trim(); + double lanValue = Double.parseDouble(lan) * 10000000; + long lanLongValue = Double.doubleToLongBits(lanValue); + if (lanLongValue < 0) { + lanLongValue = lanLongValue + 4294967295L + 1; + } + double altValue = Double.parseDouble(alt) * 10000000; + long altLongValue = Double.doubleToLongBits(altValue); + if (altLongValue < 0) { + altLongValue = altLongValue + 4294967295L + 1; + } + // 数值换算举例(以经度举例。纬度、高度、位置精度换算方法一致): + // (1)经度数值为 113.431,则换算方法如下: + // 113.431/比例因子 = 1134310000(十进制) + //  439C3270(十六进制) + //  经度数据填入 70 32 9C 43(小端模式) + // (2)经度数值为-113.431,则换算方法如下: + // 113.431/比例因子 = 1134310000(十进制) + //  439C3270(十六进制) + //  FFFFFFFF - 439C3270 + 1= BC63CD90(补码) + // 经度数据填入 90 CD 63 BC(小端模式) + // 指令(十六进制) + // 举例: 23 3E 04 01 10 00 70 32 9C 43 D0 B2 CE 0D 70 17 00 00 40 0D 03 00 CA 95 + // 其中 + // 23 3E 为同步头 + // 04 01 为识别码 + // 10 00 表示长度为 16 + // 70 32 9C 43 表示注入的辅助经度为 113.431 度 + // D0 B2 CE 0D 表示注入的辅助纬度为 23.165 度 + // 00 2F 为校验和 + + // astTimeCmd 组装 + String astTimeCmd = "233E0401"; + astTimeCmd += "1000"; + astTimeCmd += HexConvert.encodeHEX(lanLongValue); + astTimeCmd += HexConvert.encodeHEX(altLongValue); + + String hexIn = HexConvert.convertStringToHex(astTimeCmd) + HexConvert.makeChecksum(astTimeCmd); + + //String sendResult = client.sendCmd(hexIn, ackAckCheckRef); + //client.closeConnection(); + + //return sendResult; + return hexIn; + } +} diff --git a/src/main/java/com/telpo/dipperposition/service/impl/DipperAstTimeAsyncTaskServiceImpl.java b/src/main/java/com/telpo/dipperposition/service/impl/DipperAstTimeAsyncTaskServiceImpl.java new file mode 100644 index 0000000..488936d --- /dev/null +++ b/src/main/java/com/telpo/dipperposition/service/impl/DipperAstTimeAsyncTaskServiceImpl.java @@ -0,0 +1,104 @@ +package com.telpo.dipperposition.service.impl; + +import com.telpo.dipperposition.common.HexConvert; +import com.telpo.dipperposition.common.SocketClient; +import com.telpo.dipperposition.service.IDipperAstTimeAsyncTaskService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Service; + +import java.time.LocalDateTime; + +/** + * @program: DipperDataAsyncTaskServiceImpl + * @description: 发送SDBP-AST-TIME获取时间信息 + * @author: king + * @create: 2021-01-10 14:01 + */ +@Service +@Slf4j +public class DipperAstTimeAsyncTaskServiceImpl implements IDipperAstTimeAsyncTaskService { + + @Override + public String pushAstTime() { + + // (1) 发送SDBP-AST-TIME + // String sendResult = pushTimeToDipper(); + //if (sendResult == null) { + // log.error("取不到时间。"); + // return null; + //} + + // (2) 获取时间信息 + return pushTimeToDipper(); + //return sendResult; + } + + private String pushTimeToDipper() { + + // 创建Socket客户端实例; + // SocketClient client = new SocketClient(astServer, timeAstPort, astTimeout); + + // 时间和位置不是从服务器获取,而是本地生成(其中时间误差不超过3s) + // 23 3E 04 02 10 00 20 E1 07 09 14 0C 22 38 00 00 00 00 00 28 6B EE 22 98 + // 23 3E 为同步头 + // 04 02 为识别码 + // 10 00 表示长度为 16 + // --日期-- + // 20 E1 表示闰秒改正数为 + // E1 07 表示年为 2017 年(十六进制 07E1 转为十进制) + // 09 表示 9 月 + // 14 表示 20 日 + // 0C 22 38 00 00 00 00 00 表示 UTC时间,为12时34分56.0秒(小数秒建议固定为 0) + // 00 28 6B EE 表示 4 秒的时间精度(十六进制 EE6B2800 转为十进制为 4000000000,乘以比 例因子 10-9就是 4 秒) + // 00 2F 为校验和 + // TODO astTimeCmd 组装 + String astTimeCmd = "233E0402"; + astTimeCmd += "1000"; + astTimeCmd += "20E1"; + LocalDateTime now = LocalDateTime.now(); + int year = now.getYear(); + int month = now.getMonthValue(); + int day = now.getDayOfMonth(); + String hexYearString = Integer.toHexString(year); + hexYearString = "0" + hexYearString; + astTimeCmd += hexYearString.substring(2,2) + hexYearString.substring(0,2); + String hexMonthString = Integer.toHexString(month); + hexMonthString = "0" + hexMonthString; + astTimeCmd += hexMonthString; + String hexDayString = Integer.toHexString(day); + if (day < 16) { + hexDayString = "0" + hexDayString; + } + astTimeCmd += hexDayString; + + int hour = now.getHour(); + int minitor = now.getMinute(); + int second = now.getSecond(); + String hexHourString = Integer.toHexString(hour); + if (hour < 16) { + hexHourString = "0" + hexHourString; + } + astTimeCmd += hexHourString; + String hexMinitorString = Integer.toHexString(minitor); + if (minitor < 16) { + hexMinitorString = "0" + hexMinitorString; + } + astTimeCmd += hexMinitorString; + String hexSecondString = Integer.toHexString(second); + if (second < 16) { + hexSecondString = "0" + hexSecondString; + } + astTimeCmd += hexSecondString; + astTimeCmd += "0000000000"; + astTimeCmd += "00286BEE"; + + String hexIn = HexConvert.convertStringToHex(astTimeCmd) + HexConvert.makeChecksum(astTimeCmd); + + //String ackAckCheckRef = "233E0101020004020A1D"; + //String sendResult = client.sendCmd(hexIn, ackAckCheckRef); + //client.closeConnection(); + + return hexIn; + } +} diff --git a/src/main/java/com/telpo/dipperposition/service/impl/DipperDataAsyncTaskServiceImpl.java b/src/main/java/com/telpo/dipperposition/service/impl/DipperDataAsyncTaskServiceImpl.java new file mode 100644 index 0000000..92870c5 --- /dev/null +++ b/src/main/java/com/telpo/dipperposition/service/impl/DipperDataAsyncTaskServiceImpl.java @@ -0,0 +1,73 @@ +package com.telpo.dipperposition.service.impl; + +import com.telpo.dipperposition.common.HexConvert; +import com.telpo.dipperposition.common.RedisUtil; +import com.telpo.dipperposition.common.SocketClient; +import com.telpo.dipperposition.service.IDipperDataAsyncTaskService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Service; + +/** + * @program: DipperDataAsyncTaskServiceImpl + * @description: 获取星历数据。 + * @author: king + * @create: 2021-01-10 14:01 + */ +@Service +@Slf4j +public class DipperDataAsyncTaskServiceImpl implements IDipperDataAsyncTaskService { + + @Autowired + private RedisUtil redisUtil; + + @Value("${pos.ast.server}") + String astServer; + @Value("${pos.ast.ephAstPort}") + int ephAstPort; + @Value("${pos.ast.ephAstHexPort}") + int ephAstHexPort; + @Value("${pos.ast.timeout}") + int astTimeout; + + + private static String DIPPER_DATA_KEY = "TaidouDipperData"; + + @Override + public void pullAstEPH() { + + // (1) 发送bds获取星历数据 + String dipperData = pullEPHFromDipper(); + + // (2) 获取星历数据 + if (dipperData == null) { + log.error("获取星历数据错误,取不到星历数据。"); + } else { + // 保存到DB或者缓存 + redisUtil.set(DIPPER_DATA_KEY,dipperData); + } + } + + + private String pullEPHFromDipper() { + + // 创建Socket客户端实例; + SocketClient client = new SocketClient(astServer, ephAstPort, astTimeout); + + // astTimeCmd 组装 + String astTimeCmd = "all"; + String hexIn = HexConvert.convertStringToHex(astTimeCmd) + HexConvert.makeChecksum(astTimeCmd); + + String ackAckCheckRef = "233E010102000421293C"; + String sendResult = client.sendCmd(hexIn, ackAckCheckRef); + client.closeConnection(); + + return sendResult; + } + + @Override + public String getAstEPH(){ + return (String)redisUtil.get(DIPPER_DATA_KEY); + } +} diff --git a/src/main/java/com/telpo/dipperposition/service/impl/IPProvinceServiceImpl.java b/src/main/java/com/telpo/dipperposition/service/impl/IPProvinceServiceImpl.java new file mode 100644 index 0000000..ca2de93 --- /dev/null +++ b/src/main/java/com/telpo/dipperposition/service/impl/IPProvinceServiceImpl.java @@ -0,0 +1,62 @@ +package com.telpo.dipperposition.service.impl; + +import com.telpo.dipperposition.entity.mongo.IPProvinceEntity; +import com.telpo.dipperposition.mapper.IPProvinceMapper; +import com.telpo.dipperposition.service.IPProvinceService; +import com.telpo.dipperposition.vo.IPProvinceVo; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.ObjectUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.List; + +/** + * @program: DataPushServer + * @description: 推送记录服务接口实现类 + * @author: linwl + * @create: 2020-07-20 11:09 + */ +@Slf4j +@Service +public class IPProvinceServiceImpl implements IPProvinceService { + + @Autowired + private IPProvinceMapper iPProvinceMapper; + + @Override + public boolean saveIPProvince(IPProvinceEntity entity) { + iPProvinceMapper.save(entity); + return true; + } + + @Override + public boolean updateIPProvince( + IPProvinceEntity query, IPProvinceEntity update) { + iPProvinceMapper.updateFirst(query, update); + return true; + } + + @Override + public boolean romveById(String id) { + iPProvinceMapper.deleteById(id); + return false; + } + + @Override + public IPProvinceEntity getIPProvince(String ipAddress) { + try { + IPProvinceEntity query = new IPProvinceEntity(); + query.setIp(ipAddress); + List pushRecords = iPProvinceMapper.queryList(query); + if (ObjectUtils.isNotEmpty(pushRecords)) { + return pushRecords.get(0); + } else { + return null; + } + } catch (Exception e) { + log.error("获取IP省份异常:", e); + return null; + } + } +} diff --git a/src/main/java/com/telpo/dipperposition/task/ScheduleService.java b/src/main/java/com/telpo/dipperposition/task/ScheduleService.java new file mode 100644 index 0000000..70d31f1 --- /dev/null +++ b/src/main/java/com/telpo/dipperposition/task/ScheduleService.java @@ -0,0 +1,39 @@ +package com.telpo.dipperposition.task; + +import com.telpo.dipperposition.service.IDipperDataAsyncTaskService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.stereotype.Component; + + +/** + * @program: DataPushServer + * @description: 定时执行任务服务 + * @author: king + * @create: 2021-01-17 16:24 + */ +@Component +@Slf4j +public class ScheduleService { + + @Autowired + private IDipperDataAsyncTaskService dipperDataAsyncTaskService; + + /* + * 调用9012端口的接口获取星历数据。 + * 通过TCP连接服务器agnss.techtotop.com:9012,发送bds获取星历数据。 + * 每30分钟获取1次,30秒超时, + * 如果失败,则可以等待10秒再获取1次。 * + */ + @Scheduled(cron = "${scheduler.task.cron}") + public void pullData() { + log.info("开始星历数据同步!"); + // 获取推送失败的记录 + try { + dipperDataAsyncTaskService.pullAstEPH(); + } catch (Exception e) { + log.error("执行定时获取星历数据发生异常:", e); + } + } +} diff --git a/src/main/java/com/telpo/dipperposition/vo/IPProvinceVo.java b/src/main/java/com/telpo/dipperposition/vo/IPProvinceVo.java new file mode 100644 index 0000000..df9abeb --- /dev/null +++ b/src/main/java/com/telpo/dipperposition/vo/IPProvinceVo.java @@ -0,0 +1,20 @@ +package com.telpo.dipperposition.vo; + +import lombok.Getter; +import lombok.Setter; + +/** + * @program: DataPushServer + * @description: 基础类 + * @author: linwl + * @create: 2020-07-17 16:41 + */ +@Setter +@Getter +public class IPProvinceVo { + + /** Ip */ + private String ip; + /** Ip所在省份 */ + private String province; +} diff --git a/src/main/resources/bootstrap.yaml b/src/main/resources/bootstrap.yaml index 6f36d67..707693d 100644 --- a/src/main/resources/bootstrap.yaml +++ b/src/main/resources/bootstrap.yaml @@ -7,4 +7,28 @@ spring: nacos: config: server-addr: 172.16.192.26:8848 - file-extension: yml \ No newline at end of file + file-extension: yaml +scheduler: + task: + pool: + size: 2 + #等待任务完成退出最大秒数 + await-seconds: 600 + cron: "0 */30 * * * *" + +pos: + centerProvinceFilePath: /csv/provinceLonAlt.csv + ipPositionRequestPath: https://restapi.amap.com/v3/ip + ipPositionRequestKey: 65e794b0a1a4b87eeec86f93fea05411 + centerProvince: 湖北省 + ast: + server: agnss.techtotop.com + ephAstPort: 8012 + ephAstHexPort: 9012 + timeout: 30000 + +position: + server: + timeAsycPort: + posAsycPort: + starsAsycPort: \ No newline at end of file From 333ea44cb08387b0ceb9cb5e09ae827eb5a21e77 Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Fri, 15 Jan 2021 12:29:57 +0800 Subject: [PATCH 033/172] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E8=AF=BB=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/csv/provinceLonAlt.csv | 35 +++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 src/main/resources/csv/provinceLonAlt.csv diff --git a/src/main/resources/csv/provinceLonAlt.csv b/src/main/resources/csv/provinceLonAlt.csv new file mode 100644 index 0000000..9904ec8 --- /dev/null +++ b/src/main/resources/csv/provinceLonAlt.csv @@ -0,0 +1,35 @@ +城市,经度,纬度,省份 +沈阳市,123.429092,41.796768,辽宁省 +长春市,125.324501,43.886841,吉林省 +哈尔滨市,126.642464,45.756966,黑龙江省 +北京市,116.405289,39.904987,北京市 +天津市,117.190186,39.125595,天津市 +呼和浩特市,111.75199,40.84149,内蒙古自治区 +银川市,106.23248,38.48644,宁夏回族自治区 +太原市,112.549248,37.857014,山西省 +石家庄市,114.502464,38.045475,河北省 +济南市,117.000923,36.675808,山东省 +郑州市,113.665413,34.757977,河南省 +西安市,108.948021,34.263161,陕西省 +武汉市,114.298569,30.584354,湖北省 +南京市,118.76741,32.041546,江苏省 +合肥市,117.283043,31.861191,安徽省 +上海市,121.472641,31.231707,上海市 +长沙市,112.982277,28.19409,湖南省 +南昌市,115.892151,28.676493,江西省 +杭州市,120.15358,30.287458,浙江省 +福州市,119.306236,26.075302,福建省 +广州市,113.28064,23.125177,广东省 +台北市,121.520076,25.030724,台湾省 +海口市,110.19989,20.04422,海南省 +南宁市,108.320007,22.82402,广西壮族自治区 +重庆市,106.504959,29.533155,重庆市 +昆明市,102.71225,25.040609,云南省 +贵阳市,106.713478,26.578342,贵州省 +成都市,104.065735,30.659462,四川省 +兰州市,103.83417,36.06138,甘肃省 +西宁市,101.77782,36.61729,青海省 +拉萨市,91.1145,29.64415,西藏自治区 +乌鲁木齐市,87.61688,43.82663,新疆维吾尔自治区 +香港,114.16546,22.27534,香港特别行政区 +澳门,113.54913,22.19875,澳门特别行政区 From 777127d16819505c809368d40805d1d7d5622460 Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Fri, 15 Jan 2021 13:49:15 +0800 Subject: [PATCH 034/172] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E8=AF=BB=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../annotation/MongoSwitch.java | 22 +++++++++++++++++++ .../config/db/MongoDbContext.java | 3 +-- .../mapper/IPProvinceMapper.java | 6 +++++ .../server/DipperPositionServer.java | 2 +- src/main/resources/bootstrap.yaml | 7 +++--- 5 files changed, 34 insertions(+), 6 deletions(-) create mode 100644 src/main/java/com/telpo/dipperposition/annotation/MongoSwitch.java diff --git a/src/main/java/com/telpo/dipperposition/annotation/MongoSwitch.java b/src/main/java/com/telpo/dipperposition/annotation/MongoSwitch.java new file mode 100644 index 0000000..6153006 --- /dev/null +++ b/src/main/java/com/telpo/dipperposition/annotation/MongoSwitch.java @@ -0,0 +1,22 @@ +package com.telpo.dipperposition.annotation; + +import java.lang.annotation.*; + +/** + * @program: DataPushServer + * @description: mongo数据源切换注解 + * @author: linwl + * @create: 2020-07-11 15:06 + */ +@Target({ElementType.METHOD}) +@Retention(RetentionPolicy.RUNTIME) +@Documented +public @interface MongoSwitch { + + /** + * mongo数据库名称 + * + * @return + */ + String value() default ""; +} diff --git a/src/main/java/com/telpo/dipperposition/config/db/MongoDbContext.java b/src/main/java/com/telpo/dipperposition/config/db/MongoDbContext.java index f27c529..14fbcd8 100644 --- a/src/main/java/com/telpo/dipperposition/config/db/MongoDbContext.java +++ b/src/main/java/com/telpo/dipperposition/config/db/MongoDbContext.java @@ -22,8 +22,7 @@ import java.util.Map; public class MongoDbContext { private static final Map MONGO_CLIENT_DB_FACTORY_MAP = new HashMap<>(); - private static final ThreadLocal MONGO_DB_FACTORY_THREAD_LOCAL = - new ThreadLocal<>(); + private static final ThreadLocal MONGO_DB_FACTORY_THREAD_LOCAL = new ThreadLocal<>(); @Autowired MongoListProperties mongoListProperties; diff --git a/src/main/java/com/telpo/dipperposition/mapper/IPProvinceMapper.java b/src/main/java/com/telpo/dipperposition/mapper/IPProvinceMapper.java index b42acc0..b050e1d 100644 --- a/src/main/java/com/telpo/dipperposition/mapper/IPProvinceMapper.java +++ b/src/main/java/com/telpo/dipperposition/mapper/IPProvinceMapper.java @@ -1,5 +1,6 @@ package com.telpo.dipperposition.mapper; +import com.telpo.dipperposition.annotation.MongoSwitch; import com.telpo.dipperposition.entity.mongo.IPProvinceEntity; import db.BaseMongoDbDao; import org.springframework.stereotype.Repository; @@ -21,11 +22,13 @@ public class IPProvinceMapper extends BaseMongoDbDao { } @Override + @MongoSwitch("common") public void save(IPProvinceEntity entity, String collectionName) { super.save(entity, collectionName); } @Override + @MongoSwitch("common") public void updateFirst(IPProvinceEntity srcObj, IPProvinceEntity targetObj) { super.updateFirst(srcObj, targetObj); } @@ -36,16 +39,19 @@ public class IPProvinceMapper extends BaseMongoDbDao { } @Override + @MongoSwitch("common") public List queryList(IPProvinceEntity object) { return super.queryList(object); } @Override + @MongoSwitch("common") public List queryList(IPProvinceEntity object, String collectionName) { return super.queryList(object, collectionName); } @Override + @MongoSwitch("common") public void deleteById(String id) { super.deleteById(id); } diff --git a/src/main/java/com/telpo/dipperposition/server/DipperPositionServer.java b/src/main/java/com/telpo/dipperposition/server/DipperPositionServer.java index 6afdc44..9b4066d 100644 --- a/src/main/java/com/telpo/dipperposition/server/DipperPositionServer.java +++ b/src/main/java/com/telpo/dipperposition/server/DipperPositionServer.java @@ -24,7 +24,7 @@ import java.net.InetSocketAddress; @Slf4j public class DipperPositionServer { - @Value(value = "${position.serverAddr}") + @Value(value = "${position.server.serverAddr}") private String serverAddr; @Value(value = "${position.server.timeAsycPort}") diff --git a/src/main/resources/bootstrap.yaml b/src/main/resources/bootstrap.yaml index 707693d..57e192e 100644 --- a/src/main/resources/bootstrap.yaml +++ b/src/main/resources/bootstrap.yaml @@ -29,6 +29,7 @@ pos: position: server: - timeAsycPort: - posAsycPort: - starsAsycPort: \ No newline at end of file + serverAddr: 172.16.192.26 + timeAsycPort: 9011 + posAsycPort: 9013 + starsAsycPort: 9012 \ No newline at end of file From 3343cf9669ce44d868c54a73611b8454057fccb6 Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Fri, 15 Jan 2021 13:59:15 +0800 Subject: [PATCH 035/172] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E8=AF=BB=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/telpo/dipperposition/common/SocketClient.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/telpo/dipperposition/common/SocketClient.java b/src/main/java/com/telpo/dipperposition/common/SocketClient.java index 79e8e94..e07cb28 100644 --- a/src/main/java/com/telpo/dipperposition/common/SocketClient.java +++ b/src/main/java/com/telpo/dipperposition/common/SocketClient.java @@ -41,7 +41,7 @@ public class SocketClient { OutputStream os=socket.getOutputStream(); PrintWriter pw=new PrintWriter(os); // TODO 发生命令 - String info="用户名:Tom,用户密码:123456"; + //String info="用户名:Tom,用户密码:123456"; pw.write(astCmd); pw.flush(); socket.shutdownOutput(); @@ -67,6 +67,7 @@ public class SocketClient { is.close(); pw.close(); os.close(); + log.debug(ackResult); return ackResult; } catch (IOException e) { log.error("Socket sendCmd Error:" + e.getMessage()); From 0d988208b22a292597ebfbbb680c0e807ff14ad2 Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Fri, 15 Jan 2021 14:44:09 +0800 Subject: [PATCH 036/172] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E8=AF=BB=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/telpo/dipperposition/common/OkHttpUtil.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/com/telpo/dipperposition/common/OkHttpUtil.java b/src/main/java/com/telpo/dipperposition/common/OkHttpUtil.java index a31eb99..44b01cc 100644 --- a/src/main/java/com/telpo/dipperposition/common/OkHttpUtil.java +++ b/src/main/java/com/telpo/dipperposition/common/OkHttpUtil.java @@ -23,8 +23,7 @@ import java.util.Objects; @Component public class OkHttpUtil { - @Autowired - private OkHttpClient okHttpClient; + @Autowired private OkHttpClient okHttpClient; /** * 根据map获取get请求参数 From 042cbc5814bd92a1c2c796773332e277ef9de920 Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Fri, 15 Jan 2021 15:17:36 +0800 Subject: [PATCH 037/172] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E8=AF=BB=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/telpo/dipperposition/common/OkHttpUtil.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/telpo/dipperposition/common/OkHttpUtil.java b/src/main/java/com/telpo/dipperposition/common/OkHttpUtil.java index 44b01cc..45c27dd 100644 --- a/src/main/java/com/telpo/dipperposition/common/OkHttpUtil.java +++ b/src/main/java/com/telpo/dipperposition/common/OkHttpUtil.java @@ -23,7 +23,7 @@ import java.util.Objects; @Component public class OkHttpUtil { - @Autowired private OkHttpClient okHttpClient; + private OkHttpClient okHttpClient = new OkHttpClient(); /** * 根据map获取get请求参数 From db517c26318f232c5834aa8b9d8947097af7c6b7 Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Fri, 15 Jan 2021 15:38:29 +0800 Subject: [PATCH 038/172] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E8=AF=BB=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../handler/NettyServerHandler.java | 25 ++++++++++++- .../IDipperAstPosAsyncTaskService.java | 6 +++- .../service/IDipperDataAsyncTaskService.java | 9 ++++- .../DipperAstPosAsyncTaskServiceImpl.java | 36 ++++++++----------- .../impl/DipperDataAsyncTaskServiceImpl.java | 23 ++++++------ .../dipperposition/task/ScheduleService.java | 12 ++++++- 6 files changed, 73 insertions(+), 38 deletions(-) diff --git a/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java b/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java index 2549967..4802fe9 100644 --- a/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java +++ b/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java @@ -40,6 +40,25 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter { @Value(value = "${position.server.starsAsycPort}") private String starsAsycServerPort; + + + @Value("${pos.centerProvinceFilePath}") + String centerProvinceFilePath; + + @Value("${pos.ipPositionRequestPath}") + String ipPositionRequestPath; + @Value("${pos.ipPositionRequestKey}") + String ipPositionRequestKey; + @Value("${pos.centerProvince}") + String centerProvince; + + + @Value("${pos.ast.server}") + String astServer; + @Value("${pos.ast.posAstPort}") + int posAstPort; + @Value("${pos.ast.timeout}") + int astTimeout; /** * 客户端连接会触发 */ @@ -98,7 +117,11 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter { // 发送SDBP-AST-POS获取辅助位置信息 if (Integer.parseInt(posAsycServerPort) == channel.localAddress().getPort()) { - channelAns = dipperAstPosAsyncTaskService.pushAstPos(ipAddress); + channelAns = dipperAstPosAsyncTaskService.pushAstPos(ipAddress, + centerProvinceFilePath, + centerProvince, + ipPositionRequestPath, + ipPositionRequestKey); } // 从缓存获取SDBP-AST-EPH星历数 diff --git a/src/main/java/com/telpo/dipperposition/service/IDipperAstPosAsyncTaskService.java b/src/main/java/com/telpo/dipperposition/service/IDipperAstPosAsyncTaskService.java index c5e2006..dcc0cb8 100644 --- a/src/main/java/com/telpo/dipperposition/service/IDipperAstPosAsyncTaskService.java +++ b/src/main/java/com/telpo/dipperposition/service/IDipperAstPosAsyncTaskService.java @@ -18,6 +18,10 @@ public interface IDipperAstPosAsyncTaskService { * 同步任务 * */ - String pushAstPos(String ipAddress) throws UnsupportedEncodingException; + String pushAstPos(String ipAddress, + String centerProvinceFilePath, + String centerProvince, + String ipPositionRequestPath, + String ipPositionRequestKey) throws UnsupportedEncodingException; } diff --git a/src/main/java/com/telpo/dipperposition/service/IDipperDataAsyncTaskService.java b/src/main/java/com/telpo/dipperposition/service/IDipperDataAsyncTaskService.java index f050b9c..2b4d8ee 100644 --- a/src/main/java/com/telpo/dipperposition/service/IDipperDataAsyncTaskService.java +++ b/src/main/java/com/telpo/dipperposition/service/IDipperDataAsyncTaskService.java @@ -1,5 +1,7 @@ package com.telpo.dipperposition.service; +import org.springframework.beans.factory.annotation.Value; + /** * @program: IDipperDataAsyncTaskService * @description: 发送bds获取星历数据。 @@ -12,9 +14,14 @@ public interface IDipperDataAsyncTaskService { /** * 同步任务 + * @param astServer + * @param ephAstHexPort + * @param astTimeout * */ - void pullAstEPH(); + void pullAstEPH(String astServer, + int ephAstHexPort, + int astTimeout); /** diff --git a/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java b/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java index fc1831e..c51c6e5 100644 --- a/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java +++ b/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java @@ -42,24 +42,10 @@ public class DipperAstPosAsyncTaskServiceImpl implements IDipperAstPosAsyncTaskS @Autowired private IPProvinceService iPProvinceService; - @Value("${pos.centerProvinceFilePath}") - String centerProvinceFilePath; - - @Value("${pos.ipPositionRequestPath}") - String ipPositionRequestPath; - @Value("${pos.ipPositionRequestKey}") - String ipPositionRequestKey; - @Value("${pos.centerProvince}") - String centerProvince; - - - @Value("${pos.ast.server}") - String astServer; - @Value("${pos.ast.posAstPort}") - int posAstPort; - @Value("${pos.ast.timeout}") - int astTimeout; - + private String centerProvince; + private String centerProvinceFilePath; + private String ipPositionRequestPath; + private String ipPositionRequestKey; // private String getAstPos(String ipAddress) throws UnsupportedEncodingException { // // String centerAddress = getIpPositionProvince(ipAddress); @@ -90,7 +76,7 @@ public class DipperAstPosAsyncTaskServiceImpl implements IDipperAstPosAsyncTaskS // 不存在说明token是已过期了 String centerProvinceName = ""; String centerProvinceLonAndAlt = ""; - List centerAddressSets = CSVUtil.readCSV(centerProvinceFilePath); + List centerAddressSets = CSVUtil.readCSV(this.centerProvinceFilePath); for (String centerAddressSet:centerAddressSets) { String[] centerAddressSetArray = centerAddressSet.split(","); if (centerAddressSetArray.length < 3) { @@ -159,13 +145,21 @@ public class DipperAstPosAsyncTaskServiceImpl implements IDipperAstPosAsyncTaskS * @param ipAddress */ @Override - public String pushAstPos(String ipAddress) throws UnsupportedEncodingException { + public String pushAstPos(String ipAddress, + String centerProvinceFilePath, + String centerProvince, + String ipPositionRequestPath, + String ipPositionRequestKey) throws UnsupportedEncodingException { + this.ipPositionRequestKey = ipPositionRequestKey; + this.ipPositionRequestPath = ipPositionRequestPath; + this.centerProvince = centerProvince; + this.centerProvinceFilePath = centerProvinceFilePath; // (1) 获取省会城市信息 String centerAddress = getIpPositionProvince(ipAddress); if (ObjectUtils.isEmpty(centerAddress) || centerAddress.equals("0")) { log.warn("IP地址非法,无法获取辅助位置信息!"); // 返回武汉的定位数据 - centerAddress = centerProvince; + centerAddress = this.centerProvince; } else { // 保存到mongoDB createIPProvince(ipAddress, centerAddress); diff --git a/src/main/java/com/telpo/dipperposition/service/impl/DipperDataAsyncTaskServiceImpl.java b/src/main/java/com/telpo/dipperposition/service/impl/DipperDataAsyncTaskServiceImpl.java index 92870c5..be34849 100644 --- a/src/main/java/com/telpo/dipperposition/service/impl/DipperDataAsyncTaskServiceImpl.java +++ b/src/main/java/com/telpo/dipperposition/service/impl/DipperDataAsyncTaskServiceImpl.java @@ -22,21 +22,18 @@ public class DipperDataAsyncTaskServiceImpl implements IDipperDataAsyncTaskServi @Autowired private RedisUtil redisUtil; - @Value("${pos.ast.server}") - String astServer; - @Value("${pos.ast.ephAstPort}") - int ephAstPort; - @Value("${pos.ast.ephAstHexPort}") - int ephAstHexPort; - @Value("${pos.ast.timeout}") - int astTimeout; - - private static String DIPPER_DATA_KEY = "TaidouDipperData"; + private String astServer; + private int ephAstHexPort; + private int astTimeout; @Override - public void pullAstEPH() { - + public void pullAstEPH(String astServer, + int ephAstHexPort, + int astTimeout) { + this.astServer = astServer; + this.ephAstHexPort = ephAstHexPort; + this.astTimeout = astTimeout; // (1) 发送bds获取星历数据 String dipperData = pullEPHFromDipper(); @@ -53,7 +50,7 @@ public class DipperDataAsyncTaskServiceImpl implements IDipperDataAsyncTaskServi private String pullEPHFromDipper() { // 创建Socket客户端实例; - SocketClient client = new SocketClient(astServer, ephAstPort, astTimeout); + SocketClient client = new SocketClient(astServer, ephAstHexPort, astTimeout); // astTimeCmd 组装 String astTimeCmd = "all"; diff --git a/src/main/java/com/telpo/dipperposition/task/ScheduleService.java b/src/main/java/com/telpo/dipperposition/task/ScheduleService.java index 70d31f1..587addc 100644 --- a/src/main/java/com/telpo/dipperposition/task/ScheduleService.java +++ b/src/main/java/com/telpo/dipperposition/task/ScheduleService.java @@ -3,6 +3,7 @@ package com.telpo.dipperposition.task; import com.telpo.dipperposition.service.IDipperDataAsyncTaskService; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; @@ -17,6 +18,15 @@ import org.springframework.stereotype.Component; @Slf4j public class ScheduleService { + @Value("${pos.ast.server}") + String astServer; + @Value("${pos.ast.ephAstPort}") + int ephAstPort; + @Value("${pos.ast.ephAstHexPort}") + int ephAstHexPort; + @Value("${pos.ast.timeout}") + int astTimeout; + @Autowired private IDipperDataAsyncTaskService dipperDataAsyncTaskService; @@ -31,7 +41,7 @@ public class ScheduleService { log.info("开始星历数据同步!"); // 获取推送失败的记录 try { - dipperDataAsyncTaskService.pullAstEPH(); + dipperDataAsyncTaskService.pullAstEPH(astServer,ephAstHexPort,astTimeout); } catch (Exception e) { log.error("执行定时获取星历数据发生异常:", e); } From a3b512535d595363370d9e01b4e68ae82653142c Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Fri, 15 Jan 2021 15:57:46 +0800 Subject: [PATCH 039/172] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E8=AF=BB=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DipperPositionApplication.java | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/telpo/dipperposition/DipperPositionApplication.java b/src/main/java/com/telpo/dipperposition/DipperPositionApplication.java index 865170a..dc7aae0 100644 --- a/src/main/java/com/telpo/dipperposition/DipperPositionApplication.java +++ b/src/main/java/com/telpo/dipperposition/DipperPositionApplication.java @@ -1,5 +1,10 @@ package com.telpo.dipperposition; +import com.alibaba.nacos.api.NacosFactory; +import com.alibaba.nacos.api.config.ConfigService; +import com.alibaba.nacos.api.config.listener.Listener; +import com.alibaba.nacos.api.PropertyKeyConst; +import com.alibaba.nacos.api.exception.NacosException; import com.telpo.dipperposition.server.DipperPositionServer; import lombok.extern.slf4j.Slf4j; import org.springframework.boot.SpringApplication; @@ -8,7 +13,8 @@ import org.springframework.boot.context.properties.ConfigurationPropertiesScan; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.cloud.client.discovery.EnableDiscoveryClient; -import java.net.InetSocketAddress; +import java.util.Properties; +import java.util.concurrent.Executor; /** * @program: gateway @@ -27,10 +33,26 @@ public class DipperPositionApplication { log.info("北斗定位服务开始!"); SpringApplication.run(DipperPositionApplication.class, args); log.info("北斗定位服务启动!"); + try { + test(); + } catch (Exception e) { + log.error(e.getMessage()); + } //启动服务端 DipperPositionServer nettyServer = new DipperPositionServer(); nettyServer.startTimeAsnc(); nettyServer.startPosAsnc(); nettyServer.startStarsAsnc(); } + + private static void test() throws NacosException { + String serverAddr = "172.16.192.26"; + String dataId = "dipperposition-service"; + String group = "DEFAULT_GROUP"; + Properties properties = new Properties(); + properties.put(PropertyKeyConst.SERVER_ADDR, serverAddr); + ConfigService configService = NacosFactory.createConfigService(properties); + String content = configService.getConfig(dataId, group, 5000); + System.out.println(content); + } } From a89f386841f11594c6da3970291aa01e38ac5a58 Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Fri, 15 Jan 2021 16:02:37 +0800 Subject: [PATCH 040/172] =?UTF-8?q?=E5=A2=9E=E5=8A=A0OkHttp=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E6=96=87=E4=BB=B6=E8=AF=BB=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dipperposition/common/OkHttpUtil.java | 2 +- .../dipperposition/config/OkHttpConfig.java | 99 +++++++++++++++++++ 2 files changed, 100 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/telpo/dipperposition/config/OkHttpConfig.java diff --git a/src/main/java/com/telpo/dipperposition/common/OkHttpUtil.java b/src/main/java/com/telpo/dipperposition/common/OkHttpUtil.java index 45c27dd..44b01cc 100644 --- a/src/main/java/com/telpo/dipperposition/common/OkHttpUtil.java +++ b/src/main/java/com/telpo/dipperposition/common/OkHttpUtil.java @@ -23,7 +23,7 @@ import java.util.Objects; @Component public class OkHttpUtil { - private OkHttpClient okHttpClient = new OkHttpClient(); + @Autowired private OkHttpClient okHttpClient; /** * 根据map获取get请求参数 diff --git a/src/main/java/com/telpo/dipperposition/config/OkHttpConfig.java b/src/main/java/com/telpo/dipperposition/config/OkHttpConfig.java new file mode 100644 index 0000000..6fd53c8 --- /dev/null +++ b/src/main/java/com/telpo/dipperposition/config/OkHttpConfig.java @@ -0,0 +1,99 @@ +package com.telpo.dipperposition.config; + +import lombok.extern.slf4j.Slf4j; +import okhttp3.ConnectionPool; +import okhttp3.OkHttpClient; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import javax.net.ssl.SSLContext; +import javax.net.ssl.SSLSocketFactory; +import javax.net.ssl.TrustManager; +import javax.net.ssl.X509TrustManager; +import java.security.KeyManagementException; +import java.security.NoSuchAlgorithmException; +import java.security.SecureRandom; +import java.security.cert.CertificateException; +import java.security.cert.X509Certificate; +import java.util.concurrent.TimeUnit; + +/** + * @program: DataPushServer + * @description: http设置 + * @author: linwl + * @create: 2020-07-17 15:29 + */ +@Configuration +@Slf4j +public class OkHttpConfig { + + @Value("${OkHttp-config.pool.max-conn}") + private Integer maxConn; + + @Value("${OkHttp-config.pool.keep-alive}") + private Integer keepAlive; + + @Value("${OkHttp-config.read-timeout}") + private long readTimeout; + + @Value("${OkHttp-config.conn-timeout}") + private long connTimeout; + + @Value("${OkHttp-config.write-timeout}") + private long writeTimeout; + + @Bean + public X509TrustManager x509TrustManager() { + return new X509TrustManager() { + @Override + public void checkClientTrusted(X509Certificate[] x509Certificates, String s) + throws CertificateException {} + + @Override + public void checkServerTrusted(X509Certificate[] x509Certificates, String s) + throws CertificateException {} + + @Override + public X509Certificate[] getAcceptedIssuers() { + return new X509Certificate[0]; + } + }; + } + + @Bean + public SSLSocketFactory sslSocketFactory() { + try { + // 信任任何链接 + SSLContext sslContext = SSLContext.getInstance("TLS"); + sslContext.init(null, new TrustManager[] {x509TrustManager()}, new SecureRandom()); + return sslContext.getSocketFactory(); + } catch (NoSuchAlgorithmException | KeyManagementException e) { + log.error("okhttp3 send https error:", e); + } + return null; + } + + /** + * Create a new connection pool with tuning parameters appropriate for a single-user application. + * The tuning parameters in this pool are subject to change in future OkHttp releases. Currently + */ + @Bean + public ConnectionPool pool() { + return new ConnectionPool(maxConn, keepAlive, TimeUnit.MINUTES); + } + + @Bean + public OkHttpClient okHttpClient() { + OkHttpClient.Builder builder = new OkHttpClient.Builder(); + builder + .connectTimeout(connTimeout, TimeUnit.SECONDS) + .readTimeout(readTimeout, TimeUnit.SECONDS) + .writeTimeout(writeTimeout, TimeUnit.SECONDS) + .connectionPool(pool()) // 连接池 + .retryOnConnectionFailure(true) + .hostnameVerifier((s, sslSession) -> true) + .sslSocketFactory(sslSocketFactory(), x509TrustManager()); + return builder.build(); + } +} From 94dd661281b935173cc2950c2e858e039afbd7d3 Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Fri, 15 Jan 2021 16:04:50 +0800 Subject: [PATCH 041/172] =?UTF-8?q?=E5=A2=9E=E5=8A=A0OkHttp=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E6=96=87=E4=BB=B6=E8=AF=BB=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/SchedulingExecutorConfig.java | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 src/main/java/com/telpo/dipperposition/controller/SchedulingExecutorConfig.java diff --git a/src/main/java/com/telpo/dipperposition/controller/SchedulingExecutorConfig.java b/src/main/java/com/telpo/dipperposition/controller/SchedulingExecutorConfig.java new file mode 100644 index 0000000..e2b3072 --- /dev/null +++ b/src/main/java/com/telpo/dipperposition/controller/SchedulingExecutorConfig.java @@ -0,0 +1,40 @@ +package com.telpo.dipperposition.controller; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.scheduling.annotation.SchedulingConfigurer; +import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; +import org.springframework.scheduling.config.ScheduledTaskRegistrar; + +/** + * @program: DataPushServer + * @description: 定时任务线程配置 + * @author: linwl + * @create: 2020-07-24 10:53 + */ +@Configuration +public class SchedulingExecutorConfig implements SchedulingConfigurer { + + @Value("${scheduler.pool.size}") + private int pollSize; + + @Value("${scheduler.pool.await-seconds}") + private int awaitSeconds; + + @Override + public void configureTasks(ScheduledTaskRegistrar taskRegistrar) { + ThreadPoolTaskScheduler taskScheduler = taskScheduler(); + taskRegistrar.setTaskScheduler(taskScheduler); + } + + @Bean(destroyMethod = "shutdown", name = "taskScheduler") + public ThreadPoolTaskScheduler taskScheduler() { + ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler(); + scheduler.setPoolSize(pollSize); + scheduler.setThreadNamePrefix("task-"); + scheduler.setAwaitTerminationSeconds(awaitSeconds); + scheduler.setWaitForTasksToCompleteOnShutdown(true); + return scheduler; + } +} From 7380704f220af40bb722c858992ed1722bfb2db9 Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Fri, 15 Jan 2021 16:05:39 +0800 Subject: [PATCH 042/172] =?UTF-8?q?=E5=A2=9E=E5=8A=A0OkHttp=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E6=96=87=E4=BB=B6=E8=AF=BB=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../telpo/dipperposition/DipperPositionApplication.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/telpo/dipperposition/DipperPositionApplication.java b/src/main/java/com/telpo/dipperposition/DipperPositionApplication.java index dc7aae0..8d3349e 100644 --- a/src/main/java/com/telpo/dipperposition/DipperPositionApplication.java +++ b/src/main/java/com/telpo/dipperposition/DipperPositionApplication.java @@ -12,6 +12,8 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.context.properties.ConfigurationPropertiesScan; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.cloud.client.discovery.EnableDiscoveryClient; +import org.springframework.scheduling.annotation.EnableAsync; +import org.springframework.scheduling.annotation.EnableScheduling; import java.util.Properties; import java.util.concurrent.Executor; @@ -23,10 +25,11 @@ import java.util.concurrent.Executor; * @create: 2020-06-18 16:39 */ @SpringBootApplication -@EnableConfigurationProperties @EnableDiscoveryClient -@Slf4j @ConfigurationPropertiesScan +@EnableAsync +@EnableScheduling +@Slf4j public class DipperPositionApplication { public static void main(String[] args) { From 8bc4836f4e70878347ae8f02aa692bd47c14f173 Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Fri, 15 Jan 2021 16:12:55 +0800 Subject: [PATCH 043/172] =?UTF-8?q?=E5=A2=9E=E5=8A=A0OkHttp=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E6=96=87=E4=BB=B6=E8=AF=BB=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../{controller => config}/SchedulingExecutorConfig.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename src/main/java/com/telpo/dipperposition/{controller => config}/SchedulingExecutorConfig.java (96%) diff --git a/src/main/java/com/telpo/dipperposition/controller/SchedulingExecutorConfig.java b/src/main/java/com/telpo/dipperposition/config/SchedulingExecutorConfig.java similarity index 96% rename from src/main/java/com/telpo/dipperposition/controller/SchedulingExecutorConfig.java rename to src/main/java/com/telpo/dipperposition/config/SchedulingExecutorConfig.java index e2b3072..653b662 100644 --- a/src/main/java/com/telpo/dipperposition/controller/SchedulingExecutorConfig.java +++ b/src/main/java/com/telpo/dipperposition/config/SchedulingExecutorConfig.java @@ -1,4 +1,4 @@ -package com.telpo.dipperposition.controller; +package com.telpo.dipperposition.config; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; From c54ba7bb5708ef295d396cab0537978bf20c118a Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Fri, 15 Jan 2021 16:20:24 +0800 Subject: [PATCH 044/172] =?UTF-8?q?=E5=A2=9E=E5=8A=A0OkHttp=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E6=96=87=E4=BB=B6=E8=AF=BB=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../config/SchedulingExecutorConfig.java | 13 ++++++++++++ .../service/IDipperDataAsyncTaskService.java | 7 +------ .../impl/DipperDataAsyncTaskServiceImpl.java | 20 ++++++++----------- .../dipperposition/task/ScheduleService.java | 11 +--------- 4 files changed, 23 insertions(+), 28 deletions(-) diff --git a/src/main/java/com/telpo/dipperposition/config/SchedulingExecutorConfig.java b/src/main/java/com/telpo/dipperposition/config/SchedulingExecutorConfig.java index 653b662..2bfd302 100644 --- a/src/main/java/com/telpo/dipperposition/config/SchedulingExecutorConfig.java +++ b/src/main/java/com/telpo/dipperposition/config/SchedulingExecutorConfig.java @@ -1,5 +1,7 @@ package com.telpo.dipperposition.config; +import lombok.Getter; +import lombok.Setter; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -13,6 +15,8 @@ import org.springframework.scheduling.config.ScheduledTaskRegistrar; * @author: linwl * @create: 2020-07-24 10:53 */ +@Getter +@Setter @Configuration public class SchedulingExecutorConfig implements SchedulingConfigurer { @@ -22,6 +26,15 @@ public class SchedulingExecutorConfig implements SchedulingConfigurer { @Value("${scheduler.pool.await-seconds}") private int awaitSeconds; + @Value("${pos.ast.server}") + private String astServer; + @Value("${pos.ast.ephAstPort}") + private int ephAstPort; + @Value("${pos.ast.ephAstHexPort}") + private int ephAstHexPort; + @Value("${pos.ast.timeout}") + private int astTimeout; + @Override public void configureTasks(ScheduledTaskRegistrar taskRegistrar) { ThreadPoolTaskScheduler taskScheduler = taskScheduler(); diff --git a/src/main/java/com/telpo/dipperposition/service/IDipperDataAsyncTaskService.java b/src/main/java/com/telpo/dipperposition/service/IDipperDataAsyncTaskService.java index 2b4d8ee..708e6df 100644 --- a/src/main/java/com/telpo/dipperposition/service/IDipperDataAsyncTaskService.java +++ b/src/main/java/com/telpo/dipperposition/service/IDipperDataAsyncTaskService.java @@ -14,14 +14,9 @@ public interface IDipperDataAsyncTaskService { /** * 同步任务 - * @param astServer - * @param ephAstHexPort - * @param astTimeout * */ - void pullAstEPH(String astServer, - int ephAstHexPort, - int astTimeout); + void pullAstEPH(); /** diff --git a/src/main/java/com/telpo/dipperposition/service/impl/DipperDataAsyncTaskServiceImpl.java b/src/main/java/com/telpo/dipperposition/service/impl/DipperDataAsyncTaskServiceImpl.java index be34849..3315aeb 100644 --- a/src/main/java/com/telpo/dipperposition/service/impl/DipperDataAsyncTaskServiceImpl.java +++ b/src/main/java/com/telpo/dipperposition/service/impl/DipperDataAsyncTaskServiceImpl.java @@ -3,6 +3,7 @@ package com.telpo.dipperposition.service.impl; import com.telpo.dipperposition.common.HexConvert; import com.telpo.dipperposition.common.RedisUtil; import com.telpo.dipperposition.common.SocketClient; +import com.telpo.dipperposition.config.SchedulingExecutorConfig; import com.telpo.dipperposition.service.IDipperDataAsyncTaskService; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; @@ -19,21 +20,16 @@ import org.springframework.stereotype.Service; @Slf4j public class DipperDataAsyncTaskServiceImpl implements IDipperDataAsyncTaskService { - @Autowired - private RedisUtil redisUtil; private static String DIPPER_DATA_KEY = "TaidouDipperData"; - private String astServer; - private int ephAstHexPort; - private int astTimeout; + + @Autowired + private RedisUtil redisUtil; + @Autowired + private SchedulingExecutorConfig schedulingExecutorConfig; @Override - public void pullAstEPH(String astServer, - int ephAstHexPort, - int astTimeout) { - this.astServer = astServer; - this.ephAstHexPort = ephAstHexPort; - this.astTimeout = astTimeout; + public void pullAstEPH() { // (1) 发送bds获取星历数据 String dipperData = pullEPHFromDipper(); @@ -50,7 +46,7 @@ public class DipperDataAsyncTaskServiceImpl implements IDipperDataAsyncTaskServi private String pullEPHFromDipper() { // 创建Socket客户端实例; - SocketClient client = new SocketClient(astServer, ephAstHexPort, astTimeout); + SocketClient client = new SocketClient(schedulingExecutorConfig.getAstServer(), schedulingExecutorConfig.getEphAstHexPort(),schedulingExecutorConfig.getAstTimeout()); // astTimeCmd 组装 String astTimeCmd = "all"; diff --git a/src/main/java/com/telpo/dipperposition/task/ScheduleService.java b/src/main/java/com/telpo/dipperposition/task/ScheduleService.java index 587addc..885a633 100644 --- a/src/main/java/com/telpo/dipperposition/task/ScheduleService.java +++ b/src/main/java/com/telpo/dipperposition/task/ScheduleService.java @@ -18,15 +18,6 @@ import org.springframework.stereotype.Component; @Slf4j public class ScheduleService { - @Value("${pos.ast.server}") - String astServer; - @Value("${pos.ast.ephAstPort}") - int ephAstPort; - @Value("${pos.ast.ephAstHexPort}") - int ephAstHexPort; - @Value("${pos.ast.timeout}") - int astTimeout; - @Autowired private IDipperDataAsyncTaskService dipperDataAsyncTaskService; @@ -41,7 +32,7 @@ public class ScheduleService { log.info("开始星历数据同步!"); // 获取推送失败的记录 try { - dipperDataAsyncTaskService.pullAstEPH(astServer,ephAstHexPort,astTimeout); + dipperDataAsyncTaskService.pullAstEPH(); } catch (Exception e) { log.error("执行定时获取星历数据发生异常:", e); } From 5d067eacf9f6ae377c03886d3224bc18da8d0b48 Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Fri, 15 Jan 2021 16:34:37 +0800 Subject: [PATCH 045/172] =?UTF-8?q?=E5=A2=9E=E5=8A=A0OkHttp=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E6=96=87=E4=BB=B6=E8=AF=BB=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../config/AsyncExecutorConfig.java | 67 +++++++++++++++++++ .../DipperAstPosAsyncTaskServiceImpl.java | 12 ++-- .../DipperAstTimeAsyncTaskServiceImpl.java | 2 + .../impl/DipperDataAsyncTaskServiceImpl.java | 2 + 4 files changed, 78 insertions(+), 5 deletions(-) create mode 100644 src/main/java/com/telpo/dipperposition/config/AsyncExecutorConfig.java diff --git a/src/main/java/com/telpo/dipperposition/config/AsyncExecutorConfig.java b/src/main/java/com/telpo/dipperposition/config/AsyncExecutorConfig.java new file mode 100644 index 0000000..9806f31 --- /dev/null +++ b/src/main/java/com/telpo/dipperposition/config/AsyncExecutorConfig.java @@ -0,0 +1,67 @@ +package com.telpo.dipperposition.config; + +import lombok.extern.slf4j.Slf4j; +import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.scheduling.annotation.AsyncConfigurer; +import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; + +import java.util.concurrent.Executor; +import java.util.concurrent.ThreadPoolExecutor; + +/** + * @program: DataPushServer + * @description: + * @author: linwl + * @create: 2020-07-11 09:17 + */ +@Configuration +@Slf4j +public class AsyncExecutorConfig implements AsyncConfigurer { + + @Value("${async.pool.corePoolSize}") + private int corePoolSize; + + @Value("${async.pool.maxPoolSize}") + private int maxPoolSize; + + @Value("${async.pool.queueCapacity}") + private int queueCapacity; + + @Bean(name = "asyncServiceExecutor") + public Executor asyncServiceExecutor() { + log.info("start asyncServiceExecutor"); + ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); + // 配置核心线程数 + executor.setCorePoolSize(corePoolSize); + // 配置最大线程数 + executor.setMaxPoolSize(maxPoolSize); + // 配置队列大小 + executor.setQueueCapacity(queueCapacity); + // 配置线程池中的线程的名称前缀 + String threadNamePrefix = "async-pool-"; + executor.setThreadNamePrefix(threadNamePrefix); + + // 设置拒绝策略:当pool已经达到max size的时候,如何处理新任务 + // CALLER_RUNS:不在新线程中执行任务,而是有调用者所在的线程来执行 + executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy()); + // 执行初始化 + executor.initialize(); + return executor; + } + + /** + * 异步任务中异常处理 + * + * @return + */ + @Override + public AsyncUncaughtExceptionHandler getAsyncUncaughtExceptionHandler() { + return (arg0, arg1, arg2) -> { + log.error("==========================" + arg0.getMessage() + "=======================", arg0); + log.error("com.telpo.auth.exception method:" + arg1.getName()); + }; + } +} diff --git a/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java b/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java index c51c6e5..4b100eb 100644 --- a/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java +++ b/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java @@ -121,7 +121,8 @@ public class DipperAstPosAsyncTaskServiceImpl implements IDipperAstPosAsyncTaskS } // 将IP对应的省会保存到mongoDB - private void createIPProvince(String ipAddress, String province) { + @Async("asyncServiceExecutor") + public void createIPProvince(String ipAddress, String province) { log.debug("异步创建推送失败任务记录!"); try { IPProvinceEntity ipProvinceEntity = iPProvinceService.getIPProvince(ipAddress); @@ -130,10 +131,10 @@ public class DipperAstPosAsyncTaskServiceImpl implements IDipperAstPosAsyncTaskS ipProvinceEntity.setIp(ipAddress); ipProvinceEntity.setProvince(province); iPProvinceService.saveIPProvince(ipProvinceEntity); - } else { - - ipProvinceEntity.setProvince(province); - iPProvinceService.updateIPProvince(ipProvinceEntity, ipProvinceEntity); +// } else { +// +// ipProvinceEntity.setProvince(province); +// iPProvinceService.updateIPProvince(ipProvinceEntity, ipProvinceEntity); } } catch (Exception e) { log.error("创建推送失败记录异常:", e); @@ -145,6 +146,7 @@ public class DipperAstPosAsyncTaskServiceImpl implements IDipperAstPosAsyncTaskS * @param ipAddress */ @Override + @Async("asyncServiceExecutor") public String pushAstPos(String ipAddress, String centerProvinceFilePath, String centerProvince, diff --git a/src/main/java/com/telpo/dipperposition/service/impl/DipperAstTimeAsyncTaskServiceImpl.java b/src/main/java/com/telpo/dipperposition/service/impl/DipperAstTimeAsyncTaskServiceImpl.java index 488936d..1ae8c2d 100644 --- a/src/main/java/com/telpo/dipperposition/service/impl/DipperAstTimeAsyncTaskServiceImpl.java +++ b/src/main/java/com/telpo/dipperposition/service/impl/DipperAstTimeAsyncTaskServiceImpl.java @@ -5,6 +5,7 @@ import com.telpo.dipperposition.common.SocketClient; import com.telpo.dipperposition.service.IDipperAstTimeAsyncTaskService; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Value; +import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Service; import java.time.LocalDateTime; @@ -20,6 +21,7 @@ import java.time.LocalDateTime; public class DipperAstTimeAsyncTaskServiceImpl implements IDipperAstTimeAsyncTaskService { @Override + @Async("asyncServiceExecutor") public String pushAstTime() { // (1) 发送SDBP-AST-TIME diff --git a/src/main/java/com/telpo/dipperposition/service/impl/DipperDataAsyncTaskServiceImpl.java b/src/main/java/com/telpo/dipperposition/service/impl/DipperDataAsyncTaskServiceImpl.java index 3315aeb..0928dc5 100644 --- a/src/main/java/com/telpo/dipperposition/service/impl/DipperDataAsyncTaskServiceImpl.java +++ b/src/main/java/com/telpo/dipperposition/service/impl/DipperDataAsyncTaskServiceImpl.java @@ -8,6 +8,7 @@ import com.telpo.dipperposition.service.IDipperDataAsyncTaskService; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; +import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Service; /** @@ -60,6 +61,7 @@ public class DipperDataAsyncTaskServiceImpl implements IDipperDataAsyncTaskServi } @Override + @Async("asyncServiceExecutor") public String getAstEPH(){ return (String)redisUtil.get(DIPPER_DATA_KEY); } From 807ce4deba07cdba98f8b2837d58659d09647c7d Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Fri, 15 Jan 2021 17:02:37 +0800 Subject: [PATCH 046/172] =?UTF-8?q?=E5=A2=9E=E5=8A=A0OkHttp=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E6=96=87=E4=BB=B6=E8=AF=BB=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dipperposition/co/PositionConfigInfo.java | 33 ++++++++++++++ .../telpo/dipperposition/co/RzlAccount.java | 42 ----------------- .../dipperposition/config/PositionConfig.java | 45 ++++++++++++------- .../server/DipperPositionServer.java | 24 ++++------ .../impl/DipperDataAsyncTaskServiceImpl.java | 1 - 5 files changed, 71 insertions(+), 74 deletions(-) create mode 100644 src/main/java/com/telpo/dipperposition/co/PositionConfigInfo.java delete mode 100644 src/main/java/com/telpo/dipperposition/co/RzlAccount.java diff --git a/src/main/java/com/telpo/dipperposition/co/PositionConfigInfo.java b/src/main/java/com/telpo/dipperposition/co/PositionConfigInfo.java new file mode 100644 index 0000000..f4f3de0 --- /dev/null +++ b/src/main/java/com/telpo/dipperposition/co/PositionConfigInfo.java @@ -0,0 +1,33 @@ +package com.telpo.dipperposition.co; + +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; +import okhttp3.*; +import okhttp3.internal.ws.RealWebSocket; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Lazy; +import org.springframework.stereotype.Component; + +import javax.net.SocketFactory; + +/** + * @program: RzlAccount + * @description: 融智联账号配置 + * @author: king + * @create: 2021-01-12 14:02 + **/ +@Getter +@Setter +@Component +public class PositionConfigInfo { + + private String serverAddr; + + private String timeAsycServerPort; + + private String posAsycServerPort; + + private String starsAsycServerPort; + +} diff --git a/src/main/java/com/telpo/dipperposition/co/RzlAccount.java b/src/main/java/com/telpo/dipperposition/co/RzlAccount.java deleted file mode 100644 index 5b589b4..0000000 --- a/src/main/java/com/telpo/dipperposition/co/RzlAccount.java +++ /dev/null @@ -1,42 +0,0 @@ -package com.telpo.dipperposition.co; - -import lombok.Getter; -import lombok.Setter; -import lombok.ToString; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.context.annotation.Lazy; -import org.springframework.stereotype.Component; - -/** - * @program: RzlAccount - * @description: 融智联账号配置 - * @author: king - * @create: 2021-01-12 14:02 - **/ -@Lazy -@Getter -@Setter -@ToString -@Component -public class RzlAccount { - - @Value("${position.hello}") - private String hello; - - RzlAccount() - { - } - - private static RzlAccount instance; - public static RzlAccount getInstance(){ - if (instance==null){ - try { - Thread.sleep(100); - } catch (InterruptedException e) { - e.printStackTrace(); - } - instance = new RzlAccount(); - } - return instance; - } -} diff --git a/src/main/java/com/telpo/dipperposition/config/PositionConfig.java b/src/main/java/com/telpo/dipperposition/config/PositionConfig.java index d9faef3..aae0be6 100644 --- a/src/main/java/com/telpo/dipperposition/config/PositionConfig.java +++ b/src/main/java/com/telpo/dipperposition/config/PositionConfig.java @@ -1,10 +1,14 @@ package com.telpo.dipperposition.config; +import com.telpo.dipperposition.co.PositionConfigInfo; import lombok.Getter; import lombok.Setter; import lombok.ToString; +import okhttp3.OkHttpClient; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; /** @@ -15,17 +19,28 @@ import org.springframework.context.annotation.Configuration; */ @Getter @Setter -@ToString @Configuration public class PositionConfig { - @Autowired - private ConfigurableApplicationContext configurableApplicationContext; + //@Autowired + //private ConfigurableApplicationContext configurableApplicationContext; //@Value(value = "${position.hello}") - private String hello; + //private String hello; //@Value(value = "${spring.application.name}") - private String name; + //private String name; + + @Value(value = "${position.server.serverAddr}") + private String serverAddr; + + @Value(value = "${position.server.timeAsycPort}") + private String timeAsycServerPort; + + @Value(value = "${position.server.posAsycPort}") + private String posAsycServerPort; + + @Value(value = "${position.server.starsAsycPort}") + private String starsAsycServerPort; PositionConfig() { @@ -33,16 +48,14 @@ public class PositionConfig { //name = configurableApplicationContext.getEnvironment().getProperty("spring.application.name"); } - private static PositionConfig instance; - public static PositionConfig getInstance(){ - if (instance==null){ - try { - Thread.sleep(100); - } catch (InterruptedException e) { - e.printStackTrace(); - } - instance = new PositionConfig(); - } - return instance; + @Bean (name = "positionConfigInfo") + public PositionConfigInfo positionConfigInfo(){ + PositionConfigInfo configInfo = new PositionConfigInfo(); + configInfo.setServerAddr(this.serverAddr); + configInfo.setTimeAsycServerPort(this.timeAsycServerPort); + configInfo.setPosAsycServerPort(this.posAsycServerPort); + configInfo.setStarsAsycServerPort(this.starsAsycServerPort); + System.out.print(configInfo.toString()); + return configInfo; } } diff --git a/src/main/java/com/telpo/dipperposition/server/DipperPositionServer.java b/src/main/java/com/telpo/dipperposition/server/DipperPositionServer.java index 9b4066d..48b475f 100644 --- a/src/main/java/com/telpo/dipperposition/server/DipperPositionServer.java +++ b/src/main/java/com/telpo/dipperposition/server/DipperPositionServer.java @@ -1,5 +1,6 @@ package com.telpo.dipperposition.server; +import com.telpo.dipperposition.config.PositionConfig; import com.telpo.dipperposition.handler.ServerChannelInitializer; import com.telpo.dipperposition.service.IDipperDataAsyncTaskService; import io.netty.bootstrap.ServerBootstrap; @@ -24,18 +25,8 @@ import java.net.InetSocketAddress; @Slf4j public class DipperPositionServer { - @Value(value = "${position.server.serverAddr}") - private String serverAddr; - - @Value(value = "${position.server.timeAsycPort}") - private String timeAsycServerPort; - - @Value(value = "${position.server.posAsycPort}") - private String posAsycServerPort; - - @Value(value = "${position.server.starsAsycPort}") - private String starsAsycServerPort; - + @Autowired + PositionConfig positionConfig; /* * 时间同步进程线程 */ @@ -45,7 +36,8 @@ public class DipperPositionServer { EventLoopGroup mainThreadGroup = new NioEventLoopGroup(1); //new 一个工作线程组 EventLoopGroup workThreadGroup = new NioEventLoopGroup(200); - InetSocketAddress socketAddress = new InetSocketAddress(serverAddr, Integer.parseInt(timeAsycServerPort)); + InetSocketAddress socketAddress = new InetSocketAddress(positionConfig.getServerAddr(), + Integer.parseInt(positionConfig.getTimeAsycServerPort())); ServerBootstrap bootstrap = new ServerBootstrap() .group(mainThreadGroup, workThreadGroup) .channel(NioServerSocketChannel.class) @@ -83,7 +75,8 @@ public class DipperPositionServer { EventLoopGroup mainThreadGroup = new NioEventLoopGroup(1); //new 一个工作线程组 EventLoopGroup workThreadGroup = new NioEventLoopGroup(200); - InetSocketAddress socketAddress = new InetSocketAddress(serverAddr, Integer.parseInt(posAsycServerPort)); + InetSocketAddress socketAddress = new InetSocketAddress(positionConfig.getServerAddr(), + Integer.parseInt(positionConfig.getPosAsycServerPort())); ServerBootstrap bootstrap = new ServerBootstrap() .group(mainThreadGroup, workThreadGroup) .channel(NioServerSocketChannel.class) @@ -122,7 +115,8 @@ public class DipperPositionServer { EventLoopGroup mainThreadGroup = new NioEventLoopGroup(1); //new 一个工作线程组 EventLoopGroup workThreadGroup = new NioEventLoopGroup(200); - InetSocketAddress socketAddress = new InetSocketAddress(serverAddr, Integer.parseInt(starsAsycServerPort)); + InetSocketAddress socketAddress = new InetSocketAddress(positionConfig.getServerAddr(), + Integer.parseInt(positionConfig.getStarsAsycServerPort())); ServerBootstrap bootstrap = new ServerBootstrap() .group(mainThreadGroup, workThreadGroup) .channel(NioServerSocketChannel.class) diff --git a/src/main/java/com/telpo/dipperposition/service/impl/DipperDataAsyncTaskServiceImpl.java b/src/main/java/com/telpo/dipperposition/service/impl/DipperDataAsyncTaskServiceImpl.java index 0928dc5..8eb9e01 100644 --- a/src/main/java/com/telpo/dipperposition/service/impl/DipperDataAsyncTaskServiceImpl.java +++ b/src/main/java/com/telpo/dipperposition/service/impl/DipperDataAsyncTaskServiceImpl.java @@ -7,7 +7,6 @@ import com.telpo.dipperposition.config.SchedulingExecutorConfig; import com.telpo.dipperposition.service.IDipperDataAsyncTaskService; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Service; From 4a28c2bbeece945fcb5d69f94ca926ec2e2552fa Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Fri, 15 Jan 2021 17:12:09 +0800 Subject: [PATCH 047/172] =?UTF-8?q?=E5=A2=9E=E5=8A=A0OkHttp=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E6=96=87=E4=BB=B6=E8=AF=BB=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/telpo/dipperposition/server/DipperPositionServer.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/telpo/dipperposition/server/DipperPositionServer.java b/src/main/java/com/telpo/dipperposition/server/DipperPositionServer.java index 48b475f..72b81e9 100644 --- a/src/main/java/com/telpo/dipperposition/server/DipperPositionServer.java +++ b/src/main/java/com/telpo/dipperposition/server/DipperPositionServer.java @@ -32,12 +32,14 @@ public class DipperPositionServer { */ public void startTimeAsnc() { + log.debug("Server is :", positionConfig.getServerAddr()); + log.debug("Port is :", positionConfig.getTimeAsycServerPort()); //new 一个主线程组 EventLoopGroup mainThreadGroup = new NioEventLoopGroup(1); //new 一个工作线程组 EventLoopGroup workThreadGroup = new NioEventLoopGroup(200); InetSocketAddress socketAddress = new InetSocketAddress(positionConfig.getServerAddr(), - Integer.parseInt(positionConfig.getTimeAsycServerPort())); + Integer.parseInt("9101")); ServerBootstrap bootstrap = new ServerBootstrap() .group(mainThreadGroup, workThreadGroup) .channel(NioServerSocketChannel.class) From d1927de28586a22e8009887604d8e17f60f34d27 Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Fri, 15 Jan 2021 17:16:39 +0800 Subject: [PATCH 048/172] =?UTF-8?q?=E5=A2=9E=E5=8A=A0OkHttp=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E6=96=87=E4=BB=B6=E8=AF=BB=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/telpo/dipperposition/server/DipperPositionServer.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/telpo/dipperposition/server/DipperPositionServer.java b/src/main/java/com/telpo/dipperposition/server/DipperPositionServer.java index 72b81e9..a0fa877 100644 --- a/src/main/java/com/telpo/dipperposition/server/DipperPositionServer.java +++ b/src/main/java/com/telpo/dipperposition/server/DipperPositionServer.java @@ -1,5 +1,6 @@ package com.telpo.dipperposition.server; +import com.telpo.dipperposition.co.PositionConfigInfo; import com.telpo.dipperposition.config.PositionConfig; import com.telpo.dipperposition.handler.ServerChannelInitializer; import com.telpo.dipperposition.service.IDipperDataAsyncTaskService; @@ -26,7 +27,7 @@ import java.net.InetSocketAddress; public class DipperPositionServer { @Autowired - PositionConfig positionConfig; + PositionConfigInfo positionConfig; /* * 时间同步进程线程 */ From 61e158e0db26809a2a9369b851a584f9c465bd2f Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Fri, 15 Jan 2021 17:20:10 +0800 Subject: [PATCH 049/172] =?UTF-8?q?=E5=A2=9E=E5=8A=A0OkHttp=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E6=96=87=E4=BB=B6=E8=AF=BB=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../config/AsyncExecutorConfig.java | 17 +++++++++++++++++ .../server/DipperPositionServer.java | 3 ++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/telpo/dipperposition/config/AsyncExecutorConfig.java b/src/main/java/com/telpo/dipperposition/config/AsyncExecutorConfig.java index 9806f31..e3d8c6b 100644 --- a/src/main/java/com/telpo/dipperposition/config/AsyncExecutorConfig.java +++ b/src/main/java/com/telpo/dipperposition/config/AsyncExecutorConfig.java @@ -1,5 +1,7 @@ package com.telpo.dipperposition.config; +import lombok.Getter; +import lombok.Setter; import lombok.extern.slf4j.Slf4j; import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler; import org.springframework.beans.factory.annotation.Value; @@ -17,6 +19,8 @@ import java.util.concurrent.ThreadPoolExecutor; * @author: linwl * @create: 2020-07-11 09:17 */ +@Getter +@Setter @Configuration @Slf4j public class AsyncExecutorConfig implements AsyncConfigurer { @@ -30,6 +34,19 @@ public class AsyncExecutorConfig implements AsyncConfigurer { @Value("${async.pool.queueCapacity}") private int queueCapacity; + + @Value(value = "${position.server.serverAddr}") + private String serverAddr; + + @Value(value = "${position.server.timeAsycPort}") + private String timeAsycServerPort; + + @Value(value = "${position.server.posAsycPort}") + private String posAsycServerPort; + + @Value(value = "${position.server.starsAsycPort}") + private String starsAsycServerPort; + @Bean(name = "asyncServiceExecutor") public Executor asyncServiceExecutor() { log.info("start asyncServiceExecutor"); diff --git a/src/main/java/com/telpo/dipperposition/server/DipperPositionServer.java b/src/main/java/com/telpo/dipperposition/server/DipperPositionServer.java index a0fa877..82f5759 100644 --- a/src/main/java/com/telpo/dipperposition/server/DipperPositionServer.java +++ b/src/main/java/com/telpo/dipperposition/server/DipperPositionServer.java @@ -1,6 +1,7 @@ package com.telpo.dipperposition.server; import com.telpo.dipperposition.co.PositionConfigInfo; +import com.telpo.dipperposition.config.AsyncExecutorConfig; import com.telpo.dipperposition.config.PositionConfig; import com.telpo.dipperposition.handler.ServerChannelInitializer; import com.telpo.dipperposition.service.IDipperDataAsyncTaskService; @@ -27,7 +28,7 @@ import java.net.InetSocketAddress; public class DipperPositionServer { @Autowired - PositionConfigInfo positionConfig; + AsyncExecutorConfig positionConfig; /* * 时间同步进程线程 */ From 62bff69c3fe1cc30c19ee9f1e637c8a6d7e8e6c6 Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Fri, 15 Jan 2021 17:26:39 +0800 Subject: [PATCH 050/172] =?UTF-8?q?=E5=A2=9E=E5=8A=A0OkHttp=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E6=96=87=E4=BB=B6=E8=AF=BB=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../config/AsyncExecutorConfig.java | 15 --------------- .../server/DipperPositionServer.java | 19 +++++++++++-------- 2 files changed, 11 insertions(+), 23 deletions(-) diff --git a/src/main/java/com/telpo/dipperposition/config/AsyncExecutorConfig.java b/src/main/java/com/telpo/dipperposition/config/AsyncExecutorConfig.java index e3d8c6b..a339326 100644 --- a/src/main/java/com/telpo/dipperposition/config/AsyncExecutorConfig.java +++ b/src/main/java/com/telpo/dipperposition/config/AsyncExecutorConfig.java @@ -19,8 +19,6 @@ import java.util.concurrent.ThreadPoolExecutor; * @author: linwl * @create: 2020-07-11 09:17 */ -@Getter -@Setter @Configuration @Slf4j public class AsyncExecutorConfig implements AsyncConfigurer { @@ -34,19 +32,6 @@ public class AsyncExecutorConfig implements AsyncConfigurer { @Value("${async.pool.queueCapacity}") private int queueCapacity; - - @Value(value = "${position.server.serverAddr}") - private String serverAddr; - - @Value(value = "${position.server.timeAsycPort}") - private String timeAsycServerPort; - - @Value(value = "${position.server.posAsycPort}") - private String posAsycServerPort; - - @Value(value = "${position.server.starsAsycPort}") - private String starsAsycServerPort; - @Bean(name = "asyncServiceExecutor") public Executor asyncServiceExecutor() { log.info("start asyncServiceExecutor"); diff --git a/src/main/java/com/telpo/dipperposition/server/DipperPositionServer.java b/src/main/java/com/telpo/dipperposition/server/DipperPositionServer.java index 82f5759..c9c0fe6 100644 --- a/src/main/java/com/telpo/dipperposition/server/DipperPositionServer.java +++ b/src/main/java/com/telpo/dipperposition/server/DipperPositionServer.java @@ -27,6 +27,11 @@ import java.net.InetSocketAddress; @Slf4j public class DipperPositionServer { + private String serverAddr="172.16.192.26"; + private String timeAsycServerPort="9011"; + private String posAsycServerPort="9013"; + private String starsAsycServerPort="9012"; + @Autowired AsyncExecutorConfig positionConfig; /* @@ -34,14 +39,12 @@ public class DipperPositionServer { */ public void startTimeAsnc() { - log.debug("Server is :", positionConfig.getServerAddr()); - log.debug("Port is :", positionConfig.getTimeAsycServerPort()); //new 一个主线程组 EventLoopGroup mainThreadGroup = new NioEventLoopGroup(1); //new 一个工作线程组 EventLoopGroup workThreadGroup = new NioEventLoopGroup(200); - InetSocketAddress socketAddress = new InetSocketAddress(positionConfig.getServerAddr(), - Integer.parseInt("9101")); + InetSocketAddress socketAddress = new InetSocketAddress(serverAddr, + Integer.parseInt(timeAsycServerPort)); ServerBootstrap bootstrap = new ServerBootstrap() .group(mainThreadGroup, workThreadGroup) .channel(NioServerSocketChannel.class) @@ -79,8 +82,8 @@ public class DipperPositionServer { EventLoopGroup mainThreadGroup = new NioEventLoopGroup(1); //new 一个工作线程组 EventLoopGroup workThreadGroup = new NioEventLoopGroup(200); - InetSocketAddress socketAddress = new InetSocketAddress(positionConfig.getServerAddr(), - Integer.parseInt(positionConfig.getPosAsycServerPort())); + InetSocketAddress socketAddress = new InetSocketAddress(serverAddr, + Integer.parseInt(posAsycServerPort)); ServerBootstrap bootstrap = new ServerBootstrap() .group(mainThreadGroup, workThreadGroup) .channel(NioServerSocketChannel.class) @@ -119,8 +122,8 @@ public class DipperPositionServer { EventLoopGroup mainThreadGroup = new NioEventLoopGroup(1); //new 一个工作线程组 EventLoopGroup workThreadGroup = new NioEventLoopGroup(200); - InetSocketAddress socketAddress = new InetSocketAddress(positionConfig.getServerAddr(), - Integer.parseInt(positionConfig.getStarsAsycServerPort())); + InetSocketAddress socketAddress = new InetSocketAddress(serverAddr, + Integer.parseInt(starsAsycServerPort)); ServerBootstrap bootstrap = new ServerBootstrap() .group(mainThreadGroup, workThreadGroup) .channel(NioServerSocketChannel.class) From 5fc68fa22a96dd277d14f5462e8d98c3de3bebb0 Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Fri, 15 Jan 2021 17:48:53 +0800 Subject: [PATCH 051/172] =?UTF-8?q?=E5=A2=9E=E5=8A=A0OkHttp=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E6=96=87=E4=BB=B6=E8=AF=BB=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dipperposition/co/PositionConfigInfo.java | 8 ++-- .../dipperposition/config/PositionConfig.java | 44 +++++++++---------- .../server/DipperPositionServer.java | 14 +++++- .../impl/DipperDataAsyncTaskServiceImpl.java | 5 ++- 4 files changed, 42 insertions(+), 29 deletions(-) diff --git a/src/main/java/com/telpo/dipperposition/co/PositionConfigInfo.java b/src/main/java/com/telpo/dipperposition/co/PositionConfigInfo.java index f4f3de0..47c2d16 100644 --- a/src/main/java/com/telpo/dipperposition/co/PositionConfigInfo.java +++ b/src/main/java/com/telpo/dipperposition/co/PositionConfigInfo.java @@ -6,6 +6,7 @@ import lombok.ToString; import okhttp3.*; import okhttp3.internal.ws.RealWebSocket; import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Component; @@ -20,14 +21,15 @@ import javax.net.SocketFactory; @Getter @Setter @Component +@ConfigurationProperties(prefix = "position-server") public class PositionConfigInfo { private String serverAddr; - private String timeAsycServerPort; + private String timeAsycPort; - private String posAsycServerPort; + private String posAsycPort; - private String starsAsycServerPort; + private String starsAsycPort; } diff --git a/src/main/java/com/telpo/dipperposition/config/PositionConfig.java b/src/main/java/com/telpo/dipperposition/config/PositionConfig.java index aae0be6..6e7d36e 100644 --- a/src/main/java/com/telpo/dipperposition/config/PositionConfig.java +++ b/src/main/java/com/telpo/dipperposition/config/PositionConfig.java @@ -30,32 +30,32 @@ public class PositionConfig { //@Value(value = "${spring.application.name}") //private String name; - @Value(value = "${position.server.serverAddr}") - private String serverAddr; - - @Value(value = "${position.server.timeAsycPort}") - private String timeAsycServerPort; - - @Value(value = "${position.server.posAsycPort}") - private String posAsycServerPort; - - @Value(value = "${position.server.starsAsycPort}") - private String starsAsycServerPort; +// @Value(value = "${position.server.serverAddr}") +// private String serverAddr; +// +// @Value(value = "${position.server.timeAsycPort}") +// private String timeAsycServerPort; +// +// @Value(value = "${position.server.posAsycPort}") +// private String posAsycServerPort; +// +// @Value(value = "${position.server.starsAsycPort}") +// private String starsAsycServerPort; PositionConfig() { //hello = configurableApplicationContext.getEnvironment().getProperty("position.hello"); //name = configurableApplicationContext.getEnvironment().getProperty("spring.application.name"); } - - @Bean (name = "positionConfigInfo") - public PositionConfigInfo positionConfigInfo(){ - PositionConfigInfo configInfo = new PositionConfigInfo(); - configInfo.setServerAddr(this.serverAddr); - configInfo.setTimeAsycServerPort(this.timeAsycServerPort); - configInfo.setPosAsycServerPort(this.posAsycServerPort); - configInfo.setStarsAsycServerPort(this.starsAsycServerPort); - System.out.print(configInfo.toString()); - return configInfo; - } +// +// @Bean (name = "positionConfigInfo") +// public PositionConfigInfo positionConfigInfo(){ +// PositionConfigInfo configInfo = new PositionConfigInfo(); +// configInfo.setServerAddr(this.serverAddr); +// configInfo.setTimeAsycServerPort(this.timeAsycServerPort); +// configInfo.setPosAsycServerPort(this.posAsycServerPort); +// configInfo.setStarsAsycServerPort(this.starsAsycServerPort); +// System.out.print(configInfo.toString()); +// return configInfo; +// } } diff --git a/src/main/java/com/telpo/dipperposition/server/DipperPositionServer.java b/src/main/java/com/telpo/dipperposition/server/DipperPositionServer.java index c9c0fe6..6df87f5 100644 --- a/src/main/java/com/telpo/dipperposition/server/DipperPositionServer.java +++ b/src/main/java/com/telpo/dipperposition/server/DipperPositionServer.java @@ -1,5 +1,9 @@ package com.telpo.dipperposition.server; +import com.alibaba.nacos.api.NacosFactory; +import com.alibaba.nacos.api.PropertyKeyConst; +import com.alibaba.nacos.api.config.ConfigService; +import com.alibaba.nacos.api.exception.NacosException; import com.telpo.dipperposition.co.PositionConfigInfo; import com.telpo.dipperposition.config.AsyncExecutorConfig; import com.telpo.dipperposition.config.PositionConfig; @@ -14,8 +18,11 @@ import io.netty.channel.socket.nio.NioServerSocketChannel; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; +import org.springframework.beans.factory.config.YamlMapFactoryBean; +import java.io.InputStream; import java.net.InetSocketAddress; +import java.util.Properties; /** @@ -27,13 +34,16 @@ import java.net.InetSocketAddress; @Slf4j public class DipperPositionServer { + @Autowired PositionConfigInfo positionConfigInfo; private String serverAddr="172.16.192.26"; private String timeAsycServerPort="9011"; private String posAsycServerPort="9013"; private String starsAsycServerPort="9012"; - @Autowired - AsyncExecutorConfig positionConfig; + public DipperPositionServer() throws NacosException { + String serverAddr = positionConfigInfo.getServerAddr(); + log.info("Config serverAddr is " + serverAddr); + } /* * 时间同步进程线程 */ diff --git a/src/main/java/com/telpo/dipperposition/service/impl/DipperDataAsyncTaskServiceImpl.java b/src/main/java/com/telpo/dipperposition/service/impl/DipperDataAsyncTaskServiceImpl.java index 8eb9e01..aec944e 100644 --- a/src/main/java/com/telpo/dipperposition/service/impl/DipperDataAsyncTaskServiceImpl.java +++ b/src/main/java/com/telpo/dipperposition/service/impl/DipperDataAsyncTaskServiceImpl.java @@ -22,6 +22,7 @@ public class DipperDataAsyncTaskServiceImpl implements IDipperDataAsyncTaskServi private static String DIPPER_DATA_KEY = "TaidouDipperData"; + private static String DIPPER_ALL_DATA_REQ = "616C6C"; @Autowired private RedisUtil redisUtil; @@ -49,8 +50,8 @@ public class DipperDataAsyncTaskServiceImpl implements IDipperDataAsyncTaskServi SocketClient client = new SocketClient(schedulingExecutorConfig.getAstServer(), schedulingExecutorConfig.getEphAstHexPort(),schedulingExecutorConfig.getAstTimeout()); // astTimeCmd 组装 - String astTimeCmd = "all"; - String hexIn = HexConvert.convertStringToHex(astTimeCmd) + HexConvert.makeChecksum(astTimeCmd); + String astTimeCmd = DIPPER_ALL_DATA_REQ; + String hexIn = astTimeCmd + HexConvert.makeChecksum(astTimeCmd); String ackAckCheckRef = "233E010102000421293C"; String sendResult = client.sendCmd(hexIn, ackAckCheckRef); From b4671ae5414533bb159247485b33b1181a2ee6f5 Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Fri, 15 Jan 2021 17:49:46 +0800 Subject: [PATCH 052/172] =?UTF-8?q?=E5=A2=9E=E5=8A=A0OkHttp=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E6=96=87=E4=BB=B6=E8=AF=BB=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dipperposition/DipperPositionApplication.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/telpo/dipperposition/DipperPositionApplication.java b/src/main/java/com/telpo/dipperposition/DipperPositionApplication.java index 8d3349e..02bb839 100644 --- a/src/main/java/com/telpo/dipperposition/DipperPositionApplication.java +++ b/src/main/java/com/telpo/dipperposition/DipperPositionApplication.java @@ -38,14 +38,14 @@ public class DipperPositionApplication { log.info("北斗定位服务启动!"); try { test(); + //启动服务端 + DipperPositionServer nettyServer = new DipperPositionServer(); + nettyServer.startTimeAsnc(); + nettyServer.startPosAsnc(); + nettyServer.startStarsAsnc(); } catch (Exception e) { log.error(e.getMessage()); } - //启动服务端 - DipperPositionServer nettyServer = new DipperPositionServer(); - nettyServer.startTimeAsnc(); - nettyServer.startPosAsnc(); - nettyServer.startStarsAsnc(); } private static void test() throws NacosException { From 4a17769b98d563e81c61968013235e6e81334c81 Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Fri, 15 Jan 2021 17:54:27 +0800 Subject: [PATCH 053/172] =?UTF-8?q?=E5=A2=9E=E5=8A=A0OkHttp=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E6=96=87=E4=BB=B6=E8=AF=BB=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/telpo/dipperposition/server/DipperPositionServer.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/telpo/dipperposition/server/DipperPositionServer.java b/src/main/java/com/telpo/dipperposition/server/DipperPositionServer.java index 6df87f5..ee2b6ed 100644 --- a/src/main/java/com/telpo/dipperposition/server/DipperPositionServer.java +++ b/src/main/java/com/telpo/dipperposition/server/DipperPositionServer.java @@ -41,7 +41,7 @@ public class DipperPositionServer { private String starsAsycServerPort="9012"; public DipperPositionServer() throws NacosException { - String serverAddr = positionConfigInfo.getServerAddr(); + //String serverAddr = positionConfigInfo.getServerAddr(); log.info("Config serverAddr is " + serverAddr); } /* From 928efde49305f76aee35566f6fd0b894675931d6 Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Fri, 15 Jan 2021 18:04:21 +0800 Subject: [PATCH 054/172] =?UTF-8?q?=E5=A2=9E=E5=8A=A0OkHttp=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E6=96=87=E4=BB=B6=E8=AF=BB=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/DipperPositionController.java | 4 ++-- .../server/DipperPositionServer.java | 23 ++++++++++++++++++- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/telpo/dipperposition/controller/DipperPositionController.java b/src/main/java/com/telpo/dipperposition/controller/DipperPositionController.java index df2e40f..524256a 100644 --- a/src/main/java/com/telpo/dipperposition/controller/DipperPositionController.java +++ b/src/main/java/com/telpo/dipperposition/controller/DipperPositionController.java @@ -15,12 +15,12 @@ import org.springframework.web.bind.annotation.RestController; @RestController @Slf4j public class DipperPositionController { - @Value(value = "${position.hello}") + @Value(value = "${position-server.serverAddr}") private String hello; //RzlAccount rzlAccount; @RequestMapping("/getPos") public String getPos() { - return "return position = " + hello; + return "return serverAddr = " + hello; } } diff --git a/src/main/java/com/telpo/dipperposition/server/DipperPositionServer.java b/src/main/java/com/telpo/dipperposition/server/DipperPositionServer.java index ee2b6ed..a2bba72 100644 --- a/src/main/java/com/telpo/dipperposition/server/DipperPositionServer.java +++ b/src/main/java/com/telpo/dipperposition/server/DipperPositionServer.java @@ -19,9 +19,13 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.config.YamlMapFactoryBean; +import org.yaml.snakeyaml.Yaml; +import java.io.ByteArrayInputStream; +import java.io.FileInputStream; import java.io.InputStream; import java.net.InetSocketAddress; +import java.util.Map; import java.util.Properties; @@ -34,7 +38,7 @@ import java.util.Properties; @Slf4j public class DipperPositionServer { - @Autowired PositionConfigInfo positionConfigInfo; + // @Autowired PositionConfigInfo positionConfigInfo; private String serverAddr="172.16.192.26"; private String timeAsycServerPort="9011"; private String posAsycServerPort="9013"; @@ -42,6 +46,23 @@ public class DipperPositionServer { public DipperPositionServer() throws NacosException { //String serverAddr = positionConfigInfo.getServerAddr(); + try { + String serverAddr = "172.16.192.26"; + String dataId = "dipperposition-service"; + String group = "DEFAULT_GROUP"; + Properties properties = new Properties(); + properties.put(PropertyKeyConst.SERVER_ADDR, serverAddr); + ConfigService configService = NacosFactory.createConfigService(properties); + String content = configService.getConfig(dataId, group, 5000); + + ByteArrayInputStream tInputStringStream = new ByteArrayInputStream(content.getBytes()); + Yaml yaml = new Yaml(); + Map m1 = (Map) yaml.load(tInputStringStream); + Map m2 = (Map) m1.get("position-server"); + log.info("Map server is:" + m2.get("serverAddr")); + } catch (Exception ex) { + ex.printStackTrace(); + } log.info("Config serverAddr is " + serverAddr); } /* From 05bb34c2d27a30731bcd6be3254b54a4865cf073 Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Fri, 15 Jan 2021 18:12:32 +0800 Subject: [PATCH 055/172] =?UTF-8?q?=E5=A2=9E=E5=8A=A0OkHttp=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E6=96=87=E4=BB=B6=E8=AF=BB=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../telpo/dipperposition/handler/NettyServerHandler.java | 6 +++--- .../telpo/dipperposition/server/DipperPositionServer.java | 5 ----- src/main/resources/bootstrap.yaml | 3 +-- 3 files changed, 4 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java b/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java index 4802fe9..5776681 100644 --- a/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java +++ b/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java @@ -32,13 +32,13 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter { @Autowired private IDipperDataAsyncTaskService dipperDataAsyncTaskService; - @Value(value = "${position.server.timeAsycPort}") + @Value(value = "${position-server.timeAsycPort}") private String timeAsycServerPort; - @Value(value = "${position.server.posAsycPort}") + @Value(value = "${position-server.posAsycPort}") private String posAsycServerPort; - @Value(value = "${position.server.starsAsycPort}") + @Value(value = "${position-server.starsAsycPort}") private String starsAsycServerPort; diff --git a/src/main/java/com/telpo/dipperposition/server/DipperPositionServer.java b/src/main/java/com/telpo/dipperposition/server/DipperPositionServer.java index a2bba72..ab95c72 100644 --- a/src/main/java/com/telpo/dipperposition/server/DipperPositionServer.java +++ b/src/main/java/com/telpo/dipperposition/server/DipperPositionServer.java @@ -16,14 +16,9 @@ import io.netty.channel.EventLoopGroup; import io.netty.channel.nio.NioEventLoopGroup; import io.netty.channel.socket.nio.NioServerSocketChannel; import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.beans.factory.config.YamlMapFactoryBean; import org.yaml.snakeyaml.Yaml; import java.io.ByteArrayInputStream; -import java.io.FileInputStream; -import java.io.InputStream; import java.net.InetSocketAddress; import java.util.Map; import java.util.Properties; diff --git a/src/main/resources/bootstrap.yaml b/src/main/resources/bootstrap.yaml index 57e192e..66034b2 100644 --- a/src/main/resources/bootstrap.yaml +++ b/src/main/resources/bootstrap.yaml @@ -27,8 +27,7 @@ pos: ephAstHexPort: 9012 timeout: 30000 -position: - server: +position-server: serverAddr: 172.16.192.26 timeAsycPort: 9011 posAsycPort: 9013 From 087c01389ad7a28c67d7dedd366d7c167ea0a511 Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Fri, 15 Jan 2021 18:16:26 +0800 Subject: [PATCH 056/172] =?UTF-8?q?=E5=A2=9E=E5=8A=A0OkHttp=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E6=96=87=E4=BB=B6=E8=AF=BB=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pom.xml b/pom.xml index 20c8038..9ae26f0 100644 --- a/pom.xml +++ b/pom.xml @@ -74,11 +74,11 @@ 3.10 - + - de.codecentric - spring-boot-admin-starter-client - 2.2.4 + org.yaml + snakeyaml + 1.25 From 6961b3299357cfbd9e510ef606b50c1a67b2e65d Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Fri, 15 Jan 2021 18:24:29 +0800 Subject: [PATCH 057/172] =?UTF-8?q?=E5=A2=9E=E5=8A=A0OkHttp=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E6=96=87=E4=BB=B6=E8=AF=BB=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DipperPositionApplication.java | 6 ++-- .../server/DipperPositionServer.java | 34 ++++++++++--------- 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/src/main/java/com/telpo/dipperposition/DipperPositionApplication.java b/src/main/java/com/telpo/dipperposition/DipperPositionApplication.java index 02bb839..b7fe236 100644 --- a/src/main/java/com/telpo/dipperposition/DipperPositionApplication.java +++ b/src/main/java/com/telpo/dipperposition/DipperPositionApplication.java @@ -41,8 +41,10 @@ public class DipperPositionApplication { //启动服务端 DipperPositionServer nettyServer = new DipperPositionServer(); nettyServer.startTimeAsnc(); - nettyServer.startPosAsnc(); - nettyServer.startStarsAsnc(); + DipperPositionServer nettyServer2 = new DipperPositionServer(); + nettyServer2.startPosAsnc(); + DipperPositionServer nettyServer3 = new DipperPositionServer(); + nettyServer3.startStarsAsnc(); } catch (Exception e) { log.error(e.getMessage()); } diff --git a/src/main/java/com/telpo/dipperposition/server/DipperPositionServer.java b/src/main/java/com/telpo/dipperposition/server/DipperPositionServer.java index ab95c72..5d56980 100644 --- a/src/main/java/com/telpo/dipperposition/server/DipperPositionServer.java +++ b/src/main/java/com/telpo/dipperposition/server/DipperPositionServer.java @@ -4,11 +4,7 @@ import com.alibaba.nacos.api.NacosFactory; import com.alibaba.nacos.api.PropertyKeyConst; import com.alibaba.nacos.api.config.ConfigService; import com.alibaba.nacos.api.exception.NacosException; -import com.telpo.dipperposition.co.PositionConfigInfo; -import com.telpo.dipperposition.config.AsyncExecutorConfig; -import com.telpo.dipperposition.config.PositionConfig; import com.telpo.dipperposition.handler.ServerChannelInitializer; -import com.telpo.dipperposition.service.IDipperDataAsyncTaskService; import io.netty.bootstrap.ServerBootstrap; import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelOption; @@ -19,6 +15,8 @@ import lombok.extern.slf4j.Slf4j; import org.yaml.snakeyaml.Yaml; import java.io.ByteArrayInputStream; +import java.net.Inet4Address; +import java.net.InetAddress; import java.net.InetSocketAddress; import java.util.Map; import java.util.Properties; @@ -34,31 +32,35 @@ import java.util.Properties; public class DipperPositionServer { // @Autowired PositionConfigInfo positionConfigInfo; - private String serverAddr="172.16.192.26"; - private String timeAsycServerPort="9011"; - private String posAsycServerPort="9013"; - private String starsAsycServerPort="9012"; + private String serverAddr; + private String timeAsycPort; + private String posAsycPort; + private String starsAsycPort; public DipperPositionServer() throws NacosException { //String serverAddr = positionConfigInfo.getServerAddr(); try { - String serverAddr = "172.16.192.26"; + InetAddress ip4 = Inet4Address.getLocalHost(); String dataId = "dipperposition-service"; String group = "DEFAULT_GROUP"; Properties properties = new Properties(); - properties.put(PropertyKeyConst.SERVER_ADDR, serverAddr); + properties.put(PropertyKeyConst.SERVER_ADDR, ip4); ConfigService configService = NacosFactory.createConfigService(properties); String content = configService.getConfig(dataId, group, 5000); ByteArrayInputStream tInputStringStream = new ByteArrayInputStream(content.getBytes()); Yaml yaml = new Yaml(); - Map m1 = (Map) yaml.load(tInputStringStream); + Map m1 = yaml.load(tInputStringStream); Map m2 = (Map) m1.get("position-server"); - log.info("Map server is:" + m2.get("serverAddr")); + this.serverAddr = (String)m2.get("serverAddr"); + this.timeAsycPort = (String)m2.get("timeAsycPort"); + this.posAsycPort = (String)m2.get("posAsycPort"); + this.starsAsycPort = (String)m2.get("starsAsycPort"); + //log.info("Map server is:" + m2.get("serverAddr")); } catch (Exception ex) { ex.printStackTrace(); } - log.info("Config serverAddr is " + serverAddr); + //log.info("Config serverAddr is " + serverAddr); } /* * 时间同步进程线程 @@ -70,7 +72,7 @@ public class DipperPositionServer { //new 一个工作线程组 EventLoopGroup workThreadGroup = new NioEventLoopGroup(200); InetSocketAddress socketAddress = new InetSocketAddress(serverAddr, - Integer.parseInt(timeAsycServerPort)); + Integer.parseInt(timeAsycPort)); ServerBootstrap bootstrap = new ServerBootstrap() .group(mainThreadGroup, workThreadGroup) .channel(NioServerSocketChannel.class) @@ -109,7 +111,7 @@ public class DipperPositionServer { //new 一个工作线程组 EventLoopGroup workThreadGroup = new NioEventLoopGroup(200); InetSocketAddress socketAddress = new InetSocketAddress(serverAddr, - Integer.parseInt(posAsycServerPort)); + Integer.parseInt(posAsycPort)); ServerBootstrap bootstrap = new ServerBootstrap() .group(mainThreadGroup, workThreadGroup) .channel(NioServerSocketChannel.class) @@ -149,7 +151,7 @@ public class DipperPositionServer { //new 一个工作线程组 EventLoopGroup workThreadGroup = new NioEventLoopGroup(200); InetSocketAddress socketAddress = new InetSocketAddress(serverAddr, - Integer.parseInt(starsAsycServerPort)); + Integer.parseInt(starsAsycPort)); ServerBootstrap bootstrap = new ServerBootstrap() .group(mainThreadGroup, workThreadGroup) .channel(NioServerSocketChannel.class) From cb19e1409fb32a17758db718f771c8f5336fc37f Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Fri, 15 Jan 2021 18:28:26 +0800 Subject: [PATCH 058/172] =?UTF-8?q?=E5=A2=9E=E5=8A=A0OkHttp=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E6=96=87=E4=BB=B6=E8=AF=BB=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/telpo/dipperposition/server/DipperPositionServer.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/telpo/dipperposition/server/DipperPositionServer.java b/src/main/java/com/telpo/dipperposition/server/DipperPositionServer.java index 5d56980..157aea2 100644 --- a/src/main/java/com/telpo/dipperposition/server/DipperPositionServer.java +++ b/src/main/java/com/telpo/dipperposition/server/DipperPositionServer.java @@ -44,7 +44,7 @@ public class DipperPositionServer { String dataId = "dipperposition-service"; String group = "DEFAULT_GROUP"; Properties properties = new Properties(); - properties.put(PropertyKeyConst.SERVER_ADDR, ip4); + properties.put(PropertyKeyConst.SERVER_ADDR, ip4.getHostAddress()); ConfigService configService = NacosFactory.createConfigService(properties); String content = configService.getConfig(dataId, group, 5000); From b26b4a11e8f7c34654d8d1cec15cede552cbc888 Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Fri, 15 Jan 2021 18:35:40 +0800 Subject: [PATCH 059/172] =?UTF-8?q?=E5=A2=9E=E5=8A=A0OkHttp=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E6=96=87=E4=BB=B6=E8=AF=BB=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dipperposition/server/DipperPositionServer.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/telpo/dipperposition/server/DipperPositionServer.java b/src/main/java/com/telpo/dipperposition/server/DipperPositionServer.java index 157aea2..bbe51d2 100644 --- a/src/main/java/com/telpo/dipperposition/server/DipperPositionServer.java +++ b/src/main/java/com/telpo/dipperposition/server/DipperPositionServer.java @@ -40,11 +40,17 @@ public class DipperPositionServer { public DipperPositionServer() throws NacosException { //String serverAddr = positionConfigInfo.getServerAddr(); try { - InetAddress ip4 = Inet4Address.getLocalHost(); + try { + InetAddress ip4 = Inet4Address.getLocalHost(); + serverAddr = ip4.getHostAddress(); + } catch (Exception ex) { + serverAddr = "172.16.192.26"; + ex.printStackTrace(); + } String dataId = "dipperposition-service"; String group = "DEFAULT_GROUP"; Properties properties = new Properties(); - properties.put(PropertyKeyConst.SERVER_ADDR, ip4.getHostAddress()); + properties.put(PropertyKeyConst.SERVER_ADDR, serverAddr); ConfigService configService = NacosFactory.createConfigService(properties); String content = configService.getConfig(dataId, group, 5000); From d057f2a3edc859150cea2f7eecb655111ef6653c Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Fri, 15 Jan 2021 18:39:34 +0800 Subject: [PATCH 060/172] =?UTF-8?q?=E5=A2=9E=E5=8A=A0OkHttp=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E6=96=87=E4=BB=B6=E8=AF=BB=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/DipperPositionServer.java | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/telpo/dipperposition/server/DipperPositionServer.java b/src/main/java/com/telpo/dipperposition/server/DipperPositionServer.java index bbe51d2..e338727 100644 --- a/src/main/java/com/telpo/dipperposition/server/DipperPositionServer.java +++ b/src/main/java/com/telpo/dipperposition/server/DipperPositionServer.java @@ -33,9 +33,9 @@ public class DipperPositionServer { // @Autowired PositionConfigInfo positionConfigInfo; private String serverAddr; - private String timeAsycPort; - private String posAsycPort; - private String starsAsycPort; + private Integer timeAsycPort; + private Integer posAsycPort; + private Integer starsAsycPort; public DipperPositionServer() throws NacosException { //String serverAddr = positionConfigInfo.getServerAddr(); @@ -59,9 +59,9 @@ public class DipperPositionServer { Map m1 = yaml.load(tInputStringStream); Map m2 = (Map) m1.get("position-server"); this.serverAddr = (String)m2.get("serverAddr"); - this.timeAsycPort = (String)m2.get("timeAsycPort"); - this.posAsycPort = (String)m2.get("posAsycPort"); - this.starsAsycPort = (String)m2.get("starsAsycPort"); + this.timeAsycPort = (Integer)m2.get("timeAsycPort"); + this.posAsycPort = (Integer)m2.get("posAsycPort"); + this.starsAsycPort = (Integer)m2.get("starsAsycPort"); //log.info("Map server is:" + m2.get("serverAddr")); } catch (Exception ex) { ex.printStackTrace(); @@ -78,7 +78,7 @@ public class DipperPositionServer { //new 一个工作线程组 EventLoopGroup workThreadGroup = new NioEventLoopGroup(200); InetSocketAddress socketAddress = new InetSocketAddress(serverAddr, - Integer.parseInt(timeAsycPort)); + timeAsycPort); ServerBootstrap bootstrap = new ServerBootstrap() .group(mainThreadGroup, workThreadGroup) .channel(NioServerSocketChannel.class) @@ -117,7 +117,7 @@ public class DipperPositionServer { //new 一个工作线程组 EventLoopGroup workThreadGroup = new NioEventLoopGroup(200); InetSocketAddress socketAddress = new InetSocketAddress(serverAddr, - Integer.parseInt(posAsycPort)); + posAsycPort); ServerBootstrap bootstrap = new ServerBootstrap() .group(mainThreadGroup, workThreadGroup) .channel(NioServerSocketChannel.class) @@ -157,7 +157,7 @@ public class DipperPositionServer { //new 一个工作线程组 EventLoopGroup workThreadGroup = new NioEventLoopGroup(200); InetSocketAddress socketAddress = new InetSocketAddress(serverAddr, - Integer.parseInt(starsAsycPort)); + starsAsycPort); ServerBootstrap bootstrap = new ServerBootstrap() .group(mainThreadGroup, workThreadGroup) .channel(NioServerSocketChannel.class) From 2df02f0cd003797d46b3e91cc47a0b635b53b29f Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Fri, 15 Jan 2021 18:46:07 +0800 Subject: [PATCH 061/172] =?UTF-8?q?=E5=A2=9E=E5=8A=A0OkHttp=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E6=96=87=E4=BB=B6=E8=AF=BB=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DipperPositionApplication.java | 8 +- .../dipperposition/server/EphAsyncServer.java | 106 ++++++++++++++++++ .../server/TimeAsyncServer.java | 106 ++++++++++++++++++ 3 files changed, 217 insertions(+), 3 deletions(-) create mode 100644 src/main/java/com/telpo/dipperposition/server/EphAsyncServer.java create mode 100644 src/main/java/com/telpo/dipperposition/server/TimeAsyncServer.java diff --git a/src/main/java/com/telpo/dipperposition/DipperPositionApplication.java b/src/main/java/com/telpo/dipperposition/DipperPositionApplication.java index b7fe236..b76b1e2 100644 --- a/src/main/java/com/telpo/dipperposition/DipperPositionApplication.java +++ b/src/main/java/com/telpo/dipperposition/DipperPositionApplication.java @@ -6,6 +6,8 @@ import com.alibaba.nacos.api.config.listener.Listener; import com.alibaba.nacos.api.PropertyKeyConst; import com.alibaba.nacos.api.exception.NacosException; import com.telpo.dipperposition.server.DipperPositionServer; +import com.telpo.dipperposition.server.EphAsyncServer; +import com.telpo.dipperposition.server.TimeAsyncServer; import lombok.extern.slf4j.Slf4j; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @@ -39,11 +41,11 @@ public class DipperPositionApplication { try { test(); //启动服务端 - DipperPositionServer nettyServer = new DipperPositionServer(); - nettyServer.startTimeAsnc(); + TimeAsyncServer nettyServer1 = new TimeAsyncServer(); + nettyServer1.startTimeAsnc(); DipperPositionServer nettyServer2 = new DipperPositionServer(); nettyServer2.startPosAsnc(); - DipperPositionServer nettyServer3 = new DipperPositionServer(); + EphAsyncServer nettyServer3 = new EphAsyncServer(); nettyServer3.startStarsAsnc(); } catch (Exception e) { log.error(e.getMessage()); diff --git a/src/main/java/com/telpo/dipperposition/server/EphAsyncServer.java b/src/main/java/com/telpo/dipperposition/server/EphAsyncServer.java new file mode 100644 index 0000000..28eca89 --- /dev/null +++ b/src/main/java/com/telpo/dipperposition/server/EphAsyncServer.java @@ -0,0 +1,106 @@ +package com.telpo.dipperposition.server; + +import com.alibaba.nacos.api.NacosFactory; +import com.alibaba.nacos.api.PropertyKeyConst; +import com.alibaba.nacos.api.config.ConfigService; +import com.alibaba.nacos.api.exception.NacosException; +import com.telpo.dipperposition.handler.ServerChannelInitializer; +import io.netty.bootstrap.ServerBootstrap; +import io.netty.channel.ChannelFuture; +import io.netty.channel.ChannelOption; +import io.netty.channel.EventLoopGroup; +import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.socket.nio.NioServerSocketChannel; +import lombok.extern.slf4j.Slf4j; +import org.yaml.snakeyaml.Yaml; + +import java.io.ByteArrayInputStream; +import java.net.Inet4Address; +import java.net.InetAddress; +import java.net.InetSocketAddress; +import java.util.Map; +import java.util.Properties; + + +/** + * @program: DipperPositionServer + * @description: 北斗定位 + * @author: king + * @create: 2021-01-13 14:01 + */ +@Slf4j +public class EphAsyncServer { + + // @Autowired PositionConfigInfo positionConfigInfo; + private String serverAddr; + private Integer starsAsycPort; + + public EphAsyncServer() throws NacosException { + //String serverAddr = positionConfigInfo.getServerAddr(); + try { + try { + InetAddress ip4 = Inet4Address.getLocalHost(); + serverAddr = ip4.getHostAddress(); + } catch (Exception ex) { + serverAddr = "172.16.192.26"; + ex.printStackTrace(); + } + String dataId = "dipperposition-service"; + String group = "DEFAULT_GROUP"; + Properties properties = new Properties(); + properties.put(PropertyKeyConst.SERVER_ADDR, serverAddr); + ConfigService configService = NacosFactory.createConfigService(properties); + String content = configService.getConfig(dataId, group, 5000); + + ByteArrayInputStream tInputStringStream = new ByteArrayInputStream(content.getBytes()); + Yaml yaml = new Yaml(); + Map m1 = yaml.load(tInputStringStream); + Map m2 = (Map) m1.get("position-server"); + this.serverAddr = (String)m2.get("serverAddr"); + this.starsAsycPort = (Integer)m2.get("starsAsycPort"); + //log.info("Map server is:" + m2.get("serverAddr")); + } catch (Exception ex) { + ex.printStackTrace(); + } + //log.info("Config serverAddr is " + serverAddr); + } + + /* + * 星历同步进程线程 + */ + public void startStarsAsnc() { + + //new 一个主线程组 + EventLoopGroup mainThreadGroup = new NioEventLoopGroup(1); + //new 一个工作线程组 + EventLoopGroup workThreadGroup = new NioEventLoopGroup(200); + InetSocketAddress socketAddress = new InetSocketAddress(serverAddr, + starsAsycPort); + ServerBootstrap bootstrap = new ServerBootstrap() + .group(mainThreadGroup, workThreadGroup) + .channel(NioServerSocketChannel.class) + .childHandler(new ServerChannelInitializer()) + .localAddress(socketAddress) + //设置队列大小 + .option(ChannelOption.SO_BACKLOG, 1024) + // 两小时内没有数据的通信时,TCP会自动发送一个活动探测数据报文 + .childOption(ChannelOption.SO_KEEPALIVE, true); + + + //绑定端口,开始接收进来的连接 + try { + ChannelFuture future = bootstrap.bind(socketAddress).sync(); + log.info("服务器启动开始监听端口: {}", socketAddress.getPort()); + + + future.channel().closeFuture().sync(); + } catch (InterruptedException e) { + e.printStackTrace(); + } finally { + //关闭主线程组 + mainThreadGroup.shutdownGracefully(); + //关闭工作线程组 + workThreadGroup.shutdownGracefully(); + } + } +} diff --git a/src/main/java/com/telpo/dipperposition/server/TimeAsyncServer.java b/src/main/java/com/telpo/dipperposition/server/TimeAsyncServer.java new file mode 100644 index 0000000..110e470 --- /dev/null +++ b/src/main/java/com/telpo/dipperposition/server/TimeAsyncServer.java @@ -0,0 +1,106 @@ +package com.telpo.dipperposition.server; + +import com.alibaba.nacos.api.NacosFactory; +import com.alibaba.nacos.api.PropertyKeyConst; +import com.alibaba.nacos.api.config.ConfigService; +import com.alibaba.nacos.api.exception.NacosException; +import com.telpo.dipperposition.handler.ServerChannelInitializer; +import io.netty.bootstrap.ServerBootstrap; +import io.netty.channel.ChannelFuture; +import io.netty.channel.ChannelOption; +import io.netty.channel.EventLoopGroup; +import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.socket.nio.NioServerSocketChannel; +import lombok.extern.slf4j.Slf4j; +import org.yaml.snakeyaml.Yaml; + +import java.io.ByteArrayInputStream; +import java.net.Inet4Address; +import java.net.InetAddress; +import java.net.InetSocketAddress; +import java.util.Map; +import java.util.Properties; + + +/** + * @program: DipperPositionServer + * @description: 北斗定位 + * @author: king + * @create: 2021-01-13 14:01 + */ +@Slf4j +public class TimeAsyncServer { + + // @Autowired PositionConfigInfo positionConfigInfo; + private String serverAddr; + private Integer timeAsycPort; + + public TimeAsyncServer() throws NacosException { + //String serverAddr = positionConfigInfo.getServerAddr(); + try { + try { + InetAddress ip4 = Inet4Address.getLocalHost(); + serverAddr = ip4.getHostAddress(); + } catch (Exception ex) { + serverAddr = "172.16.192.26"; + ex.printStackTrace(); + } + String dataId = "dipperposition-service"; + String group = "DEFAULT_GROUP"; + Properties properties = new Properties(); + properties.put(PropertyKeyConst.SERVER_ADDR, serverAddr); + ConfigService configService = NacosFactory.createConfigService(properties); + String content = configService.getConfig(dataId, group, 5000); + + ByteArrayInputStream tInputStringStream = new ByteArrayInputStream(content.getBytes()); + Yaml yaml = new Yaml(); + Map m1 = yaml.load(tInputStringStream); + Map m2 = (Map) m1.get("position-server"); + this.serverAddr = (String)m2.get("serverAddr"); + this.timeAsycPort = (Integer)m2.get("timeAsycPort"); + //log.info("Map server is:" + m2.get("serverAddr")); + } catch (Exception ex) { + ex.printStackTrace(); + } + //log.info("Config serverAddr is " + serverAddr); + } + /* + * 时间同步进程线程 + */ + public void startTimeAsnc() { + + //new 一个主线程组 + EventLoopGroup mainThreadGroup = new NioEventLoopGroup(1); + //new 一个工作线程组 + EventLoopGroup workThreadGroup = new NioEventLoopGroup(200); + InetSocketAddress socketAddress = new InetSocketAddress(serverAddr, + timeAsycPort); + ServerBootstrap bootstrap = new ServerBootstrap() + .group(mainThreadGroup, workThreadGroup) + .channel(NioServerSocketChannel.class) + .childHandler(new ServerChannelInitializer()) + .localAddress(socketAddress) + //设置队列大小 + .option(ChannelOption.SO_BACKLOG, 1024) + // 两小时内没有数据的通信时,TCP会自动发送一个活动探测数据报文 + .childOption(ChannelOption.SO_KEEPALIVE, true); + + + //绑定端口,开始接收进来的连接 + try { + ChannelFuture future = bootstrap.bind(socketAddress).sync(); + log.info("服务器启动开始监听端口: {}", socketAddress.getPort()); + + + future.channel().closeFuture().sync(); + } catch (InterruptedException e) { + e.printStackTrace(); + } finally { + //关闭主线程组 + mainThreadGroup.shutdownGracefully(); + //关闭工作线程组 + workThreadGroup.shutdownGracefully(); + } + } + +} From baf415e73b0046bc3e59123123c6a703c1c5fd8b Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Fri, 15 Jan 2021 22:31:56 +0800 Subject: [PATCH 062/172] =?UTF-8?q?=E5=A2=9E=E5=8A=A0OkHttp=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E6=96=87=E4=BB=B6=E8=AF=BB=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dipper_position_run.sh | 4 +- setup_dev.sh | 2 +- setup_test.sh | 2 +- .../DipperPositionApplication.java | 20 +- .../server/DipperPositionServer.java | 272 ++++++++++-------- 5 files changed, 162 insertions(+), 138 deletions(-) diff --git a/dipper_position_run.sh b/dipper_position_run.sh index a50a29f..5b6a93c 100644 --- a/dipper_position_run.sh +++ b/dipper_position_run.sh @@ -9,7 +9,7 @@ if [[ ${environment} == 'production' ]]; then docker rmi -f $(docker images | grep registry.cn-shanghai.aliyuncs.com/telpo_platform/rzl_adapter | awk '{print $3}') docker login --username=rzl_wangjx@1111649216405698 --password=telpo.123 registry.cn-shanghai.aliyuncs.com docker pull registry.cn-shanghai.aliyuncs.com/telpo_platform/dipperposition_service:$version - docker run -e active=pro -v /home/data/dipperposition/log:/var/log/dipperposition --restart=always -p 8092:8092 -d --name dipperposition_service registry.cn-shanghai.aliyuncs.com/telpo_platform/dipperposition_service:$version + docker run -e active=pro -v /home/data/dipperposition/log:/var/log/dipperposition --restart=always -p 8092:8092 -p 9101:9101 -p 9102:9102 -p 9103:9103 -d --name dipperposition_service registry.cn-shanghai.aliyuncs.com/telpo_platform/dipperposition_service:$version #删除产生的None镜像 docker rmi -f $(docker images | grep none | awk '{print $3}') docker ps -a @@ -21,7 +21,7 @@ if [[ ${environment} == 'test' ]]; then docker rmi -f $(docker images | grep 139.224.254.18:5000/dipperposition_service | awk '{print $3}') docker pull 139.224.254.18:5000/rzl_adapter:$version - docker run -v /home/data/dipperposition/log:/var/log/dipperposition -e active=test --restart=always -d --network host --name dipperposition_service 139.224.254.18:5000/dipperposition_service:$version + docker run -v /home/data/dipperposition/log:/var/log/dipperposition -e active=test --restart=always -d --network host -p 9101:9101 -p 9102:9102 -p 9103:9103 --name dipperposition_service 139.224.254.18:5000/dipperposition_service:$version #删除产生的None镜像 docker rmi -f $(docker images | grep none | awk '{print $3}') diff --git a/setup_dev.sh b/setup_dev.sh index 2ae931a..0992b6b 100644 --- a/setup_dev.sh +++ b/setup_dev.sh @@ -22,6 +22,6 @@ docker rmi -f $(docker images | grep none | awk '{print $3}') # 查看镜像列表 docker images # 启动容器 -docker run -v /home/data/dipperposition/log:/var/log/dipperposition -d -e active=dev --network host --restart=always --name dipperposition_service 139.224.254.18:5000/dipperposition_service:$image_version +docker run -v /home/data/dipperposition/log:/var/log/dipperposition -d -e active=dev --network host --restart=always -p 9101:9101 -p 9102:9102 -p 9103:9103 --name dipperposition_service 139.224.254.18:5000/dipperposition_service:$image_version # 查看日志 # docker logs dipperposition_service diff --git a/setup_test.sh b/setup_test.sh index 19c0b24..b27a499 100644 --- a/setup_test.sh +++ b/setup_test.sh @@ -22,6 +22,6 @@ docker rmi -f $(docker images | grep none | awk '{print $3}') # 查看镜像列表 docker images # 启动容器 -docker run -v /home/data/dipperposition/log:/var/log/dipperposition -d -e active=test --network host --restart=always --name dipperposition_service 139.224.254.18:5000/dipperposition_service:$image_version +docker run -v /home/data/dipperposition/log:/var/log/dipperposition -d -e active=test --network host --restart=always -p 9101:9101 -p 9102:9102 -p 9103:9103 --name dipperposition_service 139.224.254.18:5000/dipperposition_service:$image_version # 查看日志 # docker logs dipperposition_service diff --git a/src/main/java/com/telpo/dipperposition/DipperPositionApplication.java b/src/main/java/com/telpo/dipperposition/DipperPositionApplication.java index b76b1e2..822bcb4 100644 --- a/src/main/java/com/telpo/dipperposition/DipperPositionApplication.java +++ b/src/main/java/com/telpo/dipperposition/DipperPositionApplication.java @@ -5,6 +5,7 @@ import com.alibaba.nacos.api.config.ConfigService; import com.alibaba.nacos.api.config.listener.Listener; import com.alibaba.nacos.api.PropertyKeyConst; import com.alibaba.nacos.api.exception.NacosException; +import com.telpo.dipperposition.co.PositionConfigInfo; import com.telpo.dipperposition.server.DipperPositionServer; import com.telpo.dipperposition.server.EphAsyncServer; import com.telpo.dipperposition.server.TimeAsyncServer; @@ -14,6 +15,8 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.context.properties.ConfigurationPropertiesScan; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.cloud.client.discovery.EnableDiscoveryClient; +import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.core.env.ConfigurableEnvironment; import org.springframework.scheduling.annotation.EnableAsync; import org.springframework.scheduling.annotation.EnableScheduling; @@ -35,18 +38,15 @@ import java.util.concurrent.Executor; public class DipperPositionApplication { public static void main(String[] args) { - log.info("北斗定位服务开始!"); - SpringApplication.run(DipperPositionApplication.class, args); - log.info("北斗定位服务启动!"); try { - test(); + log.info("北斗定位服务开始!"); + ConfigurableApplicationContext applicationContext = SpringApplication.run(DipperPositionApplication.class, args); + log.info("北斗定位服务启动!"); //启动服务端 - TimeAsyncServer nettyServer1 = new TimeAsyncServer(); - nettyServer1.startTimeAsnc(); - DipperPositionServer nettyServer2 = new DipperPositionServer(); - nettyServer2.startPosAsnc(); - EphAsyncServer nettyServer3 = new EphAsyncServer(); - nettyServer3.startStarsAsnc(); + ConfigurableEnvironment environment = applicationContext.getEnvironment(); + PositionConfigInfo pci; + pci = (PositionConfigInfo)environment.getSystemProperties().get("position-server"); + DipperPositionServer nettyServer2 = new DipperPositionServer(pci); } catch (Exception e) { log.error(e.getMessage()); } diff --git a/src/main/java/com/telpo/dipperposition/server/DipperPositionServer.java b/src/main/java/com/telpo/dipperposition/server/DipperPositionServer.java index e338727..554163d 100644 --- a/src/main/java/com/telpo/dipperposition/server/DipperPositionServer.java +++ b/src/main/java/com/telpo/dipperposition/server/DipperPositionServer.java @@ -4,6 +4,7 @@ import com.alibaba.nacos.api.NacosFactory; import com.alibaba.nacos.api.PropertyKeyConst; import com.alibaba.nacos.api.config.ConfigService; import com.alibaba.nacos.api.exception.NacosException; +import com.telpo.dipperposition.co.PositionConfigInfo; import com.telpo.dipperposition.handler.ServerChannelInitializer; import io.netty.bootstrap.ServerBootstrap; import io.netty.channel.ChannelFuture; @@ -12,15 +13,6 @@ import io.netty.channel.EventLoopGroup; import io.netty.channel.nio.NioEventLoopGroup; import io.netty.channel.socket.nio.NioServerSocketChannel; import lombok.extern.slf4j.Slf4j; -import org.yaml.snakeyaml.Yaml; - -import java.io.ByteArrayInputStream; -import java.net.Inet4Address; -import java.net.InetAddress; -import java.net.InetSocketAddress; -import java.util.Map; -import java.util.Properties; - /** * @program: DipperPositionServer @@ -37,132 +29,137 @@ public class DipperPositionServer { private Integer posAsycPort; private Integer starsAsycPort; - public DipperPositionServer() throws NacosException { - //String serverAddr = positionConfigInfo.getServerAddr(); - try { - try { - InetAddress ip4 = Inet4Address.getLocalHost(); - serverAddr = ip4.getHostAddress(); - } catch (Exception ex) { - serverAddr = "172.16.192.26"; - ex.printStackTrace(); - } - String dataId = "dipperposition-service"; - String group = "DEFAULT_GROUP"; - Properties properties = new Properties(); - properties.put(PropertyKeyConst.SERVER_ADDR, serverAddr); - ConfigService configService = NacosFactory.createConfigService(properties); - String content = configService.getConfig(dataId, group, 5000); - - ByteArrayInputStream tInputStringStream = new ByteArrayInputStream(content.getBytes()); - Yaml yaml = new Yaml(); - Map m1 = yaml.load(tInputStringStream); - Map m2 = (Map) m1.get("position-server"); - this.serverAddr = (String)m2.get("serverAddr"); - this.timeAsycPort = (Integer)m2.get("timeAsycPort"); - this.posAsycPort = (Integer)m2.get("posAsycPort"); - this.starsAsycPort = (Integer)m2.get("starsAsycPort"); - //log.info("Map server is:" + m2.get("serverAddr")); - } catch (Exception ex) { - ex.printStackTrace(); - } - //log.info("Config serverAddr is " + serverAddr); - } - /* - * 时间同步进程线程 - */ - public void startTimeAsnc() { + public DipperPositionServer(PositionConfigInfo pci) throws NacosException { - //new 一个主线程组 - EventLoopGroup mainThreadGroup = new NioEventLoopGroup(1); - //new 一个工作线程组 - EventLoopGroup workThreadGroup = new NioEventLoopGroup(200); - InetSocketAddress socketAddress = new InetSocketAddress(serverAddr, - timeAsycPort); - ServerBootstrap bootstrap = new ServerBootstrap() - .group(mainThreadGroup, workThreadGroup) - .channel(NioServerSocketChannel.class) - .childHandler(new ServerChannelInitializer()) - .localAddress(socketAddress) - //设置队列大小 - .option(ChannelOption.SO_BACKLOG, 1024) - // 两小时内没有数据的通信时,TCP会自动发送一个活动探测数据报文 - .childOption(ChannelOption.SO_KEEPALIVE, true); - - - //绑定端口,开始接收进来的连接 - try { - ChannelFuture future = bootstrap.bind(socketAddress).sync(); - log.info("服务器启动开始监听端口: {}", socketAddress.getPort()); - - - future.channel().closeFuture().sync(); - } catch (InterruptedException e) { - e.printStackTrace(); - } finally { - //关闭主线程组 - mainThreadGroup.shutdownGracefully(); - //关闭工作线程组 - workThreadGroup.shutdownGracefully(); - } - } - - /* - * 时间同步进程线程 - */ - public void startPosAsnc() { - - //new 一个主线程组 - EventLoopGroup mainThreadGroup = new NioEventLoopGroup(1); - //new 一个工作线程组 - EventLoopGroup workThreadGroup = new NioEventLoopGroup(200); - InetSocketAddress socketAddress = new InetSocketAddress(serverAddr, - posAsycPort); - ServerBootstrap bootstrap = new ServerBootstrap() - .group(mainThreadGroup, workThreadGroup) - .channel(NioServerSocketChannel.class) - .childHandler(new ServerChannelInitializer()) - .localAddress(socketAddress) - //设置队列大小 - .option(ChannelOption.SO_BACKLOG, 1024) - // 两小时内没有数据的通信时,TCP会自动发送一个活动探测数据报文 - .childOption(ChannelOption.SO_KEEPALIVE, true); - - - //绑定端口,开始接收进来的连接 - try { - ChannelFuture future = bootstrap.bind(socketAddress).sync(); - log.info("服务器启动开始监听端口: {}", socketAddress.getPort()); - - - future.channel().closeFuture().sync(); - } catch (InterruptedException e) { - e.printStackTrace(); - } finally { - //关闭主线程组 - mainThreadGroup.shutdownGracefully(); - //关闭工作线程组 - workThreadGroup.shutdownGracefully(); - } + this.serverAddr = pci.getServerAddr(); + this.timeAsycPort = Integer.parseInt(pci.getTimeAsycPort()); + this.posAsycPort = Integer.parseInt(pci.getPosAsycPort()); + this.starsAsycPort = Integer.parseInt(pci.getStarsAsycPort()); + //String serverAddr = positionConfigInfo.getServerAddr(); +// try { +// try { +// InetAddress ip4 = Inet4Address.getLocalHost(); +// serverAddr = ip4.getHostAddress(); +// } catch (Exception ex) { +// serverAddr = "172.16.192.26"; +// ex.printStackTrace(); +// } +// String dataId = "dipperposition-service"; +// String group = "DEFAULT_GROUP"; +// Properties properties = new Properties(); +// properties.put(PropertyKeyConst.SERVER_ADDR, serverAddr); +// ConfigService configService = NacosFactory.createConfigService(properties); +// String content = configService.getConfig(dataId, group, 5000); +// +// ByteArrayInputStream tInputStringStream = new ByteArrayInputStream(content.getBytes()); +// Yaml yaml = new Yaml(); +// Map m1 = yaml.load(tInputStringStream); +// Map m2 = (Map) m1.get("position-server"); +// this.serverAddr = (String)m2.get("serverAddr"); +// this.timeAsycPort = (Integer)m2.get("timeAsycPort"); +// this.posAsycPort = (Integer)m2.get("posAsycPort"); +// this.starsAsycPort = (Integer)m2.get("starsAsycPort"); +// log.info("Map server is:" + m2.get("serverAddr")); +// } catch (Exception ex) { +// ex.printStackTrace(); +// } } +// /* +// * 时间同步进程线程 +// */ +// public void startTimeAsnc() { +// +// //new 一个主线程组 +// EventLoopGroup mainThreadGroup = new NioEventLoopGroup(1); +// //new 一个工作线程组 +// EventLoopGroup workThreadGroup = new NioEventLoopGroup(200); +// InetSocketAddress socketAddress = new InetSocketAddress(serverAddr, +// timeAsycPort); +// ServerBootstrap bootstrap = new ServerBootstrap() +// .group(mainThreadGroup, workThreadGroup) +// .channel(NioServerSocketChannel.class) +// .childHandler(new ServerChannelInitializer()) +// .localAddress(socketAddress) +// //设置队列大小 +// .option(ChannelOption.SO_BACKLOG, 1024) +// // 两小时内没有数据的通信时,TCP会自动发送一个活动探测数据报文 +// .childOption(ChannelOption.SO_KEEPALIVE, true); +// +// +// //绑定端口,开始接收进来的连接 +// try { +// ChannelFuture future = bootstrap.bind(socketAddress).sync(); +// log.info("服务器启动开始监听端口: {}", socketAddress.getPort()); +// +// +// future.channel().closeFuture().sync(); +// } catch (InterruptedException e) { +// e.printStackTrace(); +// } finally { +// //关闭主线程组 +// mainThreadGroup.shutdownGracefully(); +// //关闭工作线程组 +// workThreadGroup.shutdownGracefully(); +// } +// } + +// /* +// * 时间同步进程线程 +// */ +// public void startPosAsnc() { +// +// //new 一个主线程组 +// EventLoopGroup mainThreadGroup = new NioEventLoopGroup(1); +// //new 一个工作线程组 +// EventLoopGroup workThreadGroup = new NioEventLoopGroup(200); +// InetSocketAddress socketAddress = new InetSocketAddress(serverAddr, +// posAsycPort); +// ServerBootstrap bootstrap = new ServerBootstrap() +// .group(mainThreadGroup, workThreadGroup) +// .channel(NioServerSocketChannel.class) +// .childHandler(new ServerChannelInitializer()) +// .localAddress(socketAddress) +// //设置队列大小 +// .option(ChannelOption.SO_BACKLOG, 1024) +// // 两小时内没有数据的通信时,TCP会自动发送一个活动探测数据报文 +// .childOption(ChannelOption.SO_KEEPALIVE, true); +// +// +// //绑定端口,开始接收进来的连接 +// try { +// ChannelFuture future = bootstrap.bind(socketAddress).sync(); +// log.info("服务器启动开始监听端口: {}", socketAddress.getPort()); +// +// +// future.channel().closeFuture().sync(); +// } catch (InterruptedException e) { +// e.printStackTrace(); +// } finally { +// //关闭主线程组 +// mainThreadGroup.shutdownGracefully(); +// //关闭工作线程组 +// workThreadGroup.shutdownGracefully(); +// } +// } /* * 星历同步进程线程 */ - public void startStarsAsnc() { + //public void startStarsAsnc() { + public void start() { //new 一个主线程组 EventLoopGroup mainThreadGroup = new NioEventLoopGroup(1); //new 一个工作线程组 EventLoopGroup workThreadGroup = new NioEventLoopGroup(200); - InetSocketAddress socketAddress = new InetSocketAddress(serverAddr, - starsAsycPort); + //InetSocketAddress socketAddress = new InetSocketAddress(serverAddr, + // starsAsycPort); ServerBootstrap bootstrap = new ServerBootstrap() .group(mainThreadGroup, workThreadGroup) .channel(NioServerSocketChannel.class) .childHandler(new ServerChannelInitializer()) - .localAddress(socketAddress) + //.localAddress(socketAddress) //设置队列大小 .option(ChannelOption.SO_BACKLOG, 1024) // 两小时内没有数据的通信时,TCP会自动发送一个活动探测数据报文 @@ -171,11 +168,38 @@ public class DipperPositionServer { //绑定端口,开始接收进来的连接 try { - ChannelFuture future = bootstrap.bind(socketAddress).sync(); - log.info("服务器启动开始监听端口: {}", socketAddress.getPort()); - - - future.channel().closeFuture().sync(); + ChannelFuture channelFuture = bootstrap.bind(timeAsycPort).sync(); + log.info("时间辅助服务器启动开始监听端口: {}", timeAsycPort); + channelFuture.addListener(future -> { + if (future.isSuccess()){ + System.out.println("start success"); + }else{ + System.out.println("start failed"); + } + }); + + ChannelFuture channelFuture2 = bootstrap.bind(posAsycPort).sync(); + log.info("位置服务器启动开始监听端口: {}", posAsycPort); + channelFuture2.addListener(future -> { + if (future.isSuccess()){ + System.out.println("start success"); + }else{ + System.out.println("start failed"); + } + }); + + + ChannelFuture channelFuture3 = bootstrap.bind(starsAsycPort).sync(); + log.info("星历服务器启动开始监听端口: {}", starsAsycPort); + channelFuture3.addListener(future -> { + if (future.isSuccess()){ + System.out.println("start success"); + }else{ + System.out.println("start failed"); + } + }); + + //channelFuture.channel().closeFuture().sync(); } catch (InterruptedException e) { e.printStackTrace(); } finally { From 9998786591c02fe6dbad58e0c6b6d3fee3e97f56 Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Fri, 15 Jan 2021 22:45:35 +0800 Subject: [PATCH 063/172] =?UTF-8?q?=E5=A2=9E=E5=8A=A0OkHttp=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E6=96=87=E4=BB=B6=E8=AF=BB=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dipper_position_run.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dipper_position_run.sh b/dipper_position_run.sh index 5b6a93c..214ca0e 100644 --- a/dipper_position_run.sh +++ b/dipper_position_run.sh @@ -20,7 +20,7 @@ if [[ ${environment} == 'test' ]]; then docker rm dipperposition_service || true docker rmi -f $(docker images | grep 139.224.254.18:5000/dipperposition_service | awk '{print $3}') - docker pull 139.224.254.18:5000/rzl_adapter:$version + docker pull 139.224.254.18:5000/dipperposition_service:$version docker run -v /home/data/dipperposition/log:/var/log/dipperposition -e active=test --restart=always -d --network host -p 9101:9101 -p 9102:9102 -p 9103:9103 --name dipperposition_service 139.224.254.18:5000/dipperposition_service:$version #删除产生的None镜像 From 009d2f0967f59eaf428d3405652402368a99ab7d Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Fri, 15 Jan 2021 22:51:37 +0800 Subject: [PATCH 064/172] =?UTF-8?q?=E5=A2=9E=E5=8A=A0OkHttp=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E6=96=87=E4=BB=B6=E8=AF=BB=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dipperposition/DipperPositionApplication.java | 12 +----------- .../dipperposition/server/DipperPositionServer.java | 5 +++-- 2 files changed, 4 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/telpo/dipperposition/DipperPositionApplication.java b/src/main/java/com/telpo/dipperposition/DipperPositionApplication.java index 822bcb4..5f66554 100644 --- a/src/main/java/com/telpo/dipperposition/DipperPositionApplication.java +++ b/src/main/java/com/telpo/dipperposition/DipperPositionApplication.java @@ -47,19 +47,9 @@ public class DipperPositionApplication { PositionConfigInfo pci; pci = (PositionConfigInfo)environment.getSystemProperties().get("position-server"); DipperPositionServer nettyServer2 = new DipperPositionServer(pci); + nettyServer2.start(); } catch (Exception e) { log.error(e.getMessage()); } } - - private static void test() throws NacosException { - String serverAddr = "172.16.192.26"; - String dataId = "dipperposition-service"; - String group = "DEFAULT_GROUP"; - Properties properties = new Properties(); - properties.put(PropertyKeyConst.SERVER_ADDR, serverAddr); - ConfigService configService = NacosFactory.createConfigService(properties); - String content = configService.getConfig(dataId, group, 5000); - System.out.println(content); - } } diff --git a/src/main/java/com/telpo/dipperposition/server/DipperPositionServer.java b/src/main/java/com/telpo/dipperposition/server/DipperPositionServer.java index 554163d..435a798 100644 --- a/src/main/java/com/telpo/dipperposition/server/DipperPositionServer.java +++ b/src/main/java/com/telpo/dipperposition/server/DipperPositionServer.java @@ -14,6 +14,8 @@ import io.netty.channel.nio.NioEventLoopGroup; import io.netty.channel.socket.nio.NioServerSocketChannel; import lombok.extern.slf4j.Slf4j; +import java.net.InetSocketAddress; + /** * @program: DipperPositionServer * @description: 北斗定位 @@ -153,8 +155,7 @@ public class DipperPositionServer { EventLoopGroup mainThreadGroup = new NioEventLoopGroup(1); //new 一个工作线程组 EventLoopGroup workThreadGroup = new NioEventLoopGroup(200); - //InetSocketAddress socketAddress = new InetSocketAddress(serverAddr, - // starsAsycPort); + //InetSocketAddress socketAddress = new InetSocketAddress(serverAddr,null); ServerBootstrap bootstrap = new ServerBootstrap() .group(mainThreadGroup, workThreadGroup) .channel(NioServerSocketChannel.class) From 2e7c33a4280f5bc6c3ec0afb6c7010a3598f43ba Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Fri, 15 Jan 2021 23:04:04 +0800 Subject: [PATCH 065/172] =?UTF-8?q?=E5=A2=9E=E5=8A=A0OkHttp=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E6=96=87=E4=BB=B6=E8=AF=BB=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dipperposition/DipperPositionApplication.java | 9 ++++++--- .../dipperposition/server/DipperPositionServer.java | 11 ++++++----- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/telpo/dipperposition/DipperPositionApplication.java b/src/main/java/com/telpo/dipperposition/DipperPositionApplication.java index 5f66554..126a78b 100644 --- a/src/main/java/com/telpo/dipperposition/DipperPositionApplication.java +++ b/src/main/java/com/telpo/dipperposition/DipperPositionApplication.java @@ -44,9 +44,12 @@ public class DipperPositionApplication { log.info("北斗定位服务启动!"); //启动服务端 ConfigurableEnvironment environment = applicationContext.getEnvironment(); - PositionConfigInfo pci; - pci = (PositionConfigInfo)environment.getSystemProperties().get("position-server"); - DipperPositionServer nettyServer2 = new DipperPositionServer(pci); + log.info(environment.toString()); + log.info(environment.getProperty("position-server")); + //PositionConfigInfo pci; + //pci = (PositionConfigInfo)environment.getProperty("position-server"); + DipperPositionServer nettyServer2 = new DipperPositionServer(environment); + log.info(environment.getSystemProperties().toString()); nettyServer2.start(); } catch (Exception e) { log.error(e.getMessage()); diff --git a/src/main/java/com/telpo/dipperposition/server/DipperPositionServer.java b/src/main/java/com/telpo/dipperposition/server/DipperPositionServer.java index 435a798..5a1828b 100644 --- a/src/main/java/com/telpo/dipperposition/server/DipperPositionServer.java +++ b/src/main/java/com/telpo/dipperposition/server/DipperPositionServer.java @@ -13,6 +13,7 @@ import io.netty.channel.EventLoopGroup; import io.netty.channel.nio.NioEventLoopGroup; import io.netty.channel.socket.nio.NioServerSocketChannel; import lombok.extern.slf4j.Slf4j; +import org.springframework.core.env.ConfigurableEnvironment; import java.net.InetSocketAddress; @@ -31,12 +32,12 @@ public class DipperPositionServer { private Integer posAsycPort; private Integer starsAsycPort; - public DipperPositionServer(PositionConfigInfo pci) throws NacosException { + public DipperPositionServer(ConfigurableEnvironment environment) throws NacosException { - this.serverAddr = pci.getServerAddr(); - this.timeAsycPort = Integer.parseInt(pci.getTimeAsycPort()); - this.posAsycPort = Integer.parseInt(pci.getPosAsycPort()); - this.starsAsycPort = Integer.parseInt(pci.getStarsAsycPort()); + this.serverAddr = environment.getProperty("position-server.serverAddr"); + this.timeAsycPort = Integer.parseInt(environment.getProperty("position-server.timeAsycPort")); + this.posAsycPort = Integer.parseInt(environment.getProperty("position-server.posAsycPort")); + this.starsAsycPort = Integer.parseInt(environment.getProperty("position-server.starsAsycPort")); //String serverAddr = positionConfigInfo.getServerAddr(); // try { // try { From 48f4b5e38c088f779887f272f64481d942f7a232 Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Fri, 15 Jan 2021 23:45:16 +0800 Subject: [PATCH 066/172] =?UTF-8?q?=E5=A2=9E=E5=8A=A0OkHttp=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E6=96=87=E4=BB=B6=E8=AF=BB=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DipperPositionApplication.java | 6 +-- .../handler/NettyServerHandler.java | 16 +++++-- .../server/DipperPositionServer.java | 43 +++++++++++++++++++ 3 files changed, 59 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/telpo/dipperposition/DipperPositionApplication.java b/src/main/java/com/telpo/dipperposition/DipperPositionApplication.java index 126a78b..fde8bd5 100644 --- a/src/main/java/com/telpo/dipperposition/DipperPositionApplication.java +++ b/src/main/java/com/telpo/dipperposition/DipperPositionApplication.java @@ -44,12 +44,12 @@ public class DipperPositionApplication { log.info("北斗定位服务启动!"); //启动服务端 ConfigurableEnvironment environment = applicationContext.getEnvironment(); - log.info(environment.toString()); - log.info(environment.getProperty("position-server")); + //log.info(environment.toString()); + //log.info(environment.getProperty("position-server")); //PositionConfigInfo pci; //pci = (PositionConfigInfo)environment.getProperty("position-server"); DipperPositionServer nettyServer2 = new DipperPositionServer(environment); - log.info(environment.getSystemProperties().toString()); + //log.info(environment.getSystemProperties().toString()); nettyServer2.start(); } catch (Exception e) { log.error(e.getMessage()); diff --git a/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java b/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java index 5776681..8c38627 100644 --- a/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java +++ b/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java @@ -13,6 +13,7 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; +import java.io.InputStream; import java.time.LocalDateTime; /** @@ -24,6 +25,9 @@ import java.time.LocalDateTime; @Slf4j public class NettyServerHandler extends ChannelInboundHandlerAdapter { + private static String AST_TIME_CMD = "54494d45"; + private static String AST_POS_CMD = "504f53"; + private static String AST_EPH_CMD = "455048"; @Autowired private IDipperAstTimeAsyncTaskService dipperTimeAsyncTaskService; @@ -110,13 +114,18 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter { String channelAns = ""; // 返回时间指令 - if (Integer.parseInt(timeAsycServerPort) == channel.localAddress().getPort()) { + //if (Integer.parseInt(timeAsycServerPort) == channel.localAddress().getPort()) { + ByteBuf recvmg = (ByteBuf) msg; + String recvmgStr = recvmg.toString(); + if (AST_TIME_CMD.equals(recvmg)) { // 初始时间辅助输入; channelAns = dipperTimeAsyncTaskService.pushAstTime(); } // 发送SDBP-AST-POS获取辅助位置信息 - if (Integer.parseInt(posAsycServerPort) == channel.localAddress().getPort()) { + // if (Integer.parseInt(posAsycServerPort) == channel.localAddress().getPort()) { + + if (AST_POS_CMD.equals(recvmg)) { channelAns = dipperAstPosAsyncTaskService.pushAstPos(ipAddress, centerProvinceFilePath, centerProvince, @@ -125,7 +134,8 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter { } // 从缓存获取SDBP-AST-EPH星历数 - if (Integer.parseInt(starsAsycServerPort) == channel.localAddress().getPort()) { + //if (Integer.parseInt(starsAsycServerPort) == channel.localAddress().getPort()) { + if (AST_POS_CMD.equals(recvmg)) { channelAns = dipperDataAsyncTaskService.getAstEPH(); } diff --git a/src/main/java/com/telpo/dipperposition/server/DipperPositionServer.java b/src/main/java/com/telpo/dipperposition/server/DipperPositionServer.java index 5a1828b..9d51b0a 100644 --- a/src/main/java/com/telpo/dipperposition/server/DipperPositionServer.java +++ b/src/main/java/com/telpo/dipperposition/server/DipperPositionServer.java @@ -28,6 +28,7 @@ public class DipperPositionServer { // @Autowired PositionConfigInfo positionConfigInfo; private String serverAddr; + private Integer serverPort; private Integer timeAsycPort; private Integer posAsycPort; private Integer starsAsycPort; @@ -35,6 +36,7 @@ public class DipperPositionServer { public DipperPositionServer(ConfigurableEnvironment environment) throws NacosException { this.serverAddr = environment.getProperty("position-server.serverAddr"); + this.serverPort = Integer.parseInt(environment.getProperty("server.port")); this.timeAsycPort = Integer.parseInt(environment.getProperty("position-server.timeAsycPort")); this.posAsycPort = Integer.parseInt(environment.getProperty("position-server.posAsycPort")); this.starsAsycPort = Integer.parseInt(environment.getProperty("position-server.starsAsycPort")); @@ -211,4 +213,45 @@ public class DipperPositionServer { workThreadGroup.shutdownGracefully(); } } + + public void start2() { + + //new 一个主线程组 + EventLoopGroup mainThreadGroup = new NioEventLoopGroup(1); + //new 一个工作线程组 + EventLoopGroup workThreadGroup = new NioEventLoopGroup(200); + //InetSocketAddress socketAddress = new InetSocketAddress(serverAddr,null); + ServerBootstrap bootstrap = new ServerBootstrap() + .group(mainThreadGroup, workThreadGroup) + .channel(NioServerSocketChannel.class) + .childHandler(new ServerChannelInitializer()) + //.localAddress(socketAddress) + //设置队列大小 + .option(ChannelOption.SO_BACKLOG, 1024) + // 两小时内没有数据的通信时,TCP会自动发送一个活动探测数据报文 + .childOption(ChannelOption.SO_KEEPALIVE, true); + + + //绑定端口,开始接收进来的连接 + try { + ChannelFuture channelFuture = bootstrap.bind(serverPort).sync(); + log.info("时间辅助服务器启动开始监听端口: {}", serverPort); + channelFuture.addListener(future -> { + if (future.isSuccess()){ + System.out.println("start success"); + }else{ + System.out.println("start failed"); + } + }); + + //channelFuture.channel().closeFuture().sync(); + } catch (InterruptedException e) { + e.printStackTrace(); + } finally { + //关闭主线程组 + mainThreadGroup.shutdownGracefully(); + //关闭工作线程组 + workThreadGroup.shutdownGracefully(); + } + } } From a129cd64dbb85fa1c436407e98b0591b9e6d94ae Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Fri, 15 Jan 2021 23:48:56 +0800 Subject: [PATCH 067/172] =?UTF-8?q?=E5=A2=9E=E5=8A=A0OkHttp=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E6=96=87=E4=BB=B6=E8=AF=BB=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/telpo/dipperposition/DipperPositionApplication.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/telpo/dipperposition/DipperPositionApplication.java b/src/main/java/com/telpo/dipperposition/DipperPositionApplication.java index fde8bd5..bc64010 100644 --- a/src/main/java/com/telpo/dipperposition/DipperPositionApplication.java +++ b/src/main/java/com/telpo/dipperposition/DipperPositionApplication.java @@ -48,9 +48,9 @@ public class DipperPositionApplication { //log.info(environment.getProperty("position-server")); //PositionConfigInfo pci; //pci = (PositionConfigInfo)environment.getProperty("position-server"); - DipperPositionServer nettyServer2 = new DipperPositionServer(environment); + DipperPositionServer nettyServer = new DipperPositionServer(environment); //log.info(environment.getSystemProperties().toString()); - nettyServer2.start(); + nettyServer.start2(); } catch (Exception e) { log.error(e.getMessage()); } From db82f068b46f0282e26e317b0ba464be5f135d47 Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Sat, 16 Jan 2021 08:21:50 +0800 Subject: [PATCH 068/172] =?UTF-8?q?=E7=BA=A0=E6=AD=A3=E4=B9=B1=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/telpo/dipperposition/common/SocketClient.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/telpo/dipperposition/common/SocketClient.java b/src/main/java/com/telpo/dipperposition/common/SocketClient.java index e07cb28..2021dcc 100644 --- a/src/main/java/com/telpo/dipperposition/common/SocketClient.java +++ b/src/main/java/com/telpo/dipperposition/common/SocketClient.java @@ -4,6 +4,8 @@ import lombok.extern.slf4j.Slf4j; import java.io.*; import java.net.Socket; +import java.nio.charset.StandardCharsets; + /** * @program: dipperposition * @description: socket连接单元 @@ -50,7 +52,7 @@ public class SocketClient { String reply=null; //输入流 InputStream is=socket.getInputStream(); - BufferedReader br=new BufferedReader(new InputStreamReader(is)); + BufferedReader br=new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8)); String ackResult=""; String ackHexOut = HexConvert.convertStringToHex(ackAckCheckRef); From 7caf0beeb76cfb58a6b6dfce8cb98d7b7c23b137 Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Sat, 16 Jan 2021 08:53:12 +0800 Subject: [PATCH 069/172] =?UTF-8?q?=E7=BA=A0=E6=AD=A3=E4=B9=B1=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dipper_position_run.sh | 4 ++-- setup_dev.sh | 2 +- setup_test.sh | 3 ++- .../com/telpo/dipperposition/server/DipperPositionServer.java | 4 ++-- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/dipper_position_run.sh b/dipper_position_run.sh index 214ca0e..defa30d 100644 --- a/dipper_position_run.sh +++ b/dipper_position_run.sh @@ -9,7 +9,7 @@ if [[ ${environment} == 'production' ]]; then docker rmi -f $(docker images | grep registry.cn-shanghai.aliyuncs.com/telpo_platform/rzl_adapter | awk '{print $3}') docker login --username=rzl_wangjx@1111649216405698 --password=telpo.123 registry.cn-shanghai.aliyuncs.com docker pull registry.cn-shanghai.aliyuncs.com/telpo_platform/dipperposition_service:$version - docker run -e active=pro -v /home/data/dipperposition/log:/var/log/dipperposition --restart=always -p 8092:8092 -p 9101:9101 -p 9102:9102 -p 9103:9103 -d --name dipperposition_service registry.cn-shanghai.aliyuncs.com/telpo_platform/dipperposition_service:$version + docker run -e active=pro -v /home/data/dipperposition/log:/var/log/dipperposition --restart=always -p 8105:8105 -p 9011:9011 -p 9012:9012 -p 9013:9013 -d --name dipperposition_service registry.cn-shanghai.aliyuncs.com/telpo_platform/dipperposition_service:$version #删除产生的None镜像 docker rmi -f $(docker images | grep none | awk '{print $3}') docker ps -a @@ -21,7 +21,7 @@ if [[ ${environment} == 'test' ]]; then docker rmi -f $(docker images | grep 139.224.254.18:5000/dipperposition_service | awk '{print $3}') docker pull 139.224.254.18:5000/dipperposition_service:$version - docker run -v /home/data/dipperposition/log:/var/log/dipperposition -e active=test --restart=always -d --network host -p 9101:9101 -p 9102:9102 -p 9103:9103 --name dipperposition_service 139.224.254.18:5000/dipperposition_service:$version + docker run -v /home/data/dipperposition/log:/var/log/dipperposition -e active=test --restart=always -d --network host -p 8105:8105 -p 9011:9011 -p 9012:9012 -p 9013:9013 --name dipperposition_service 139.224.254.18:5000/dipperposition_service:$version #删除产生的None镜像 docker rmi -f $(docker images | grep none | awk '{print $3}') diff --git a/setup_dev.sh b/setup_dev.sh index 0992b6b..3dfc300 100644 --- a/setup_dev.sh +++ b/setup_dev.sh @@ -22,6 +22,6 @@ docker rmi -f $(docker images | grep none | awk '{print $3}') # 查看镜像列表 docker images # 启动容器 -docker run -v /home/data/dipperposition/log:/var/log/dipperposition -d -e active=dev --network host --restart=always -p 9101:9101 -p 9102:9102 -p 9103:9103 --name dipperposition_service 139.224.254.18:5000/dipperposition_service:$image_version +docker run -v /home/data/dipperposition/log:/var/log/dipperposition -d -e active=dev --network host --restart=always -p 9011:9011 -p 9012:9012 -p 9013:9013 --name dipperposition_service 139.224.254.18:5000/dipperposition_service:$image_version # 查看日志 # docker logs dipperposition_service diff --git a/setup_test.sh b/setup_test.sh index b27a499..7f18d30 100644 --- a/setup_test.sh +++ b/setup_test.sh @@ -22,6 +22,7 @@ docker rmi -f $(docker images | grep none | awk '{print $3}') # 查看镜像列表 docker images # 启动容器 -docker run -v /home/data/dipperposition/log:/var/log/dipperposition -d -e active=test --network host --restart=always -p 9101:9101 -p 9102:9102 -p 9103:9103 --name dipperposition_service 139.224.254.18:5000/dipperposition_service:$image_version +docker run -v /home/data/dipperposition/log:/var/log/dipperposition -d -e active=test --network host --restart=always -p 9011:9011 -p 9012:9012 -p 9013:9013 --name dipperposition_service 139.224.254 + .18:5000/dipperposition_service:$image_version # 查看日志 # docker logs dipperposition_service diff --git a/src/main/java/com/telpo/dipperposition/server/DipperPositionServer.java b/src/main/java/com/telpo/dipperposition/server/DipperPositionServer.java index 9d51b0a..f81ddfc 100644 --- a/src/main/java/com/telpo/dipperposition/server/DipperPositionServer.java +++ b/src/main/java/com/telpo/dipperposition/server/DipperPositionServer.java @@ -234,8 +234,8 @@ public class DipperPositionServer { //绑定端口,开始接收进来的连接 try { - ChannelFuture channelFuture = bootstrap.bind(serverPort).sync(); - log.info("时间辅助服务器启动开始监听端口: {}", serverPort); + ChannelFuture channelFuture = bootstrap.bind(timeAsycPort).sync(); + log.info("时间辅助服务器启动开始监听端口: {}", timeAsycPort); channelFuture.addListener(future -> { if (future.isSuccess()){ System.out.println("start success"); From 678cfbd35d919e9dc147d98b1dbb41d976ac0db7 Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Sat, 16 Jan 2021 09:02:25 +0800 Subject: [PATCH 070/172] =?UTF-8?q?=E5=A4=9A=E7=AB=AF=E5=8F=A3=E5=BC=80?= =?UTF-8?q?=E6=94=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dipper_position_run.sh | 2 +- setup_test.sh | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/dipper_position_run.sh b/dipper_position_run.sh index defa30d..79b07f2 100644 --- a/dipper_position_run.sh +++ b/dipper_position_run.sh @@ -21,7 +21,7 @@ if [[ ${environment} == 'test' ]]; then docker rmi -f $(docker images | grep 139.224.254.18:5000/dipperposition_service | awk '{print $3}') docker pull 139.224.254.18:5000/dipperposition_service:$version - docker run -v /home/data/dipperposition/log:/var/log/dipperposition -e active=test --restart=always -d --network host -p 8105:8105 -p 9011:9011 -p 9012:9012 -p 9013:9013 --name dipperposition_service 139.224.254.18:5000/dipperposition_service:$version + docker run -v /home/data/dipperposition/log:/var/log/dipperposition -e active=test --restart=always -d --network host -p 9011:9011 --name dipperposition_service 139.224.254.18:5000/dipperposition_service:$version #删除产生的None镜像 docker rmi -f $(docker images | grep none | awk '{print $3}') diff --git a/setup_test.sh b/setup_test.sh index 7f18d30..c88ef12 100644 --- a/setup_test.sh +++ b/setup_test.sh @@ -22,7 +22,6 @@ docker rmi -f $(docker images | grep none | awk '{print $3}') # 查看镜像列表 docker images # 启动容器 -docker run -v /home/data/dipperposition/log:/var/log/dipperposition -d -e active=test --network host --restart=always -p 9011:9011 -p 9012:9012 -p 9013:9013 --name dipperposition_service 139.224.254 - .18:5000/dipperposition_service:$image_version +docker run -v /home/data/dipperposition/log:/var/log/dipperposition -d -e active=test --network host --restart=always -p 9011:9011 --name dipperposition_service 139.224.254.18:5000/dipperposition_service:$image_version # 查看日志 # docker logs dipperposition_service From 6b6f2b23bae66cac92f9133dc4a9bc5dd79a90c8 Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Sat, 16 Jan 2021 09:51:39 +0800 Subject: [PATCH 071/172] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=AF=BB=E5=8F=96?= =?UTF-8?q?=E7=9A=84=E7=BB=93=E6=9E=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dipperposition/common/SocketClient.java | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/telpo/dipperposition/common/SocketClient.java b/src/main/java/com/telpo/dipperposition/common/SocketClient.java index 2021dcc..d34fe80 100644 --- a/src/main/java/com/telpo/dipperposition/common/SocketClient.java +++ b/src/main/java/com/telpo/dipperposition/common/SocketClient.java @@ -54,22 +54,25 @@ public class SocketClient { InputStream is=socket.getInputStream(); BufferedReader br=new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8)); - String ackResult=""; - String ackHexOut = HexConvert.convertStringToHex(ackAckCheckRef); - while(!((reply=br.readLine())==null)){ - log.debug("接收服务器的信息:"+reply); - if (ackHexOut.equals(reply)) { - reply=br.readLine(); - ackResult = HexConvert.convertHexToString(reply); - break; - } + StringBuffer ackResultBuf= new StringBuffer(); + //String ackHexOut = HexConvert.convertStringToHex(ackAckCheckRef); + reply=br.readLine(); + while(reply!=null){ + //log.debug("接收服务器的信息:"+reply); + //if (ackHexOut.equals(reply)) { + ackResultBuf.append(reply); + reply=br.readLine(); + // break; + //} } + String ackResult = HexConvert.convertHexToString(ackResultBuf.toString()); //4.关闭资源 br.close(); is.close(); pw.close(); os.close(); log.debug(ackResult); + log.debug("接收服务器的信息:"+ackResult); return ackResult; } catch (IOException e) { log.error("Socket sendCmd Error:" + e.getMessage()); From 9215f3851deb5cfdc5f04748167b3e5b1a025d9a Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Sat, 16 Jan 2021 10:03:18 +0800 Subject: [PATCH 072/172] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=AF=BB=E5=8F=96?= =?UTF-8?q?=E7=9A=84=E7=BB=93=E6=9E=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/telpo/dipperposition/common/SocketClient.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/telpo/dipperposition/common/SocketClient.java b/src/main/java/com/telpo/dipperposition/common/SocketClient.java index d34fe80..b8d4c4b 100644 --- a/src/main/java/com/telpo/dipperposition/common/SocketClient.java +++ b/src/main/java/com/telpo/dipperposition/common/SocketClient.java @@ -65,15 +65,15 @@ public class SocketClient { // break; //} } - String ackResult = HexConvert.convertHexToString(ackResultBuf.toString()); + //String ackResult = HexConvert.convertHexToString(ackResultBuf.toString()); //4.关闭资源 br.close(); is.close(); pw.close(); os.close(); log.debug(ackResult); - log.debug("接收服务器的信息:"+ackResult); - return ackResult; + log.debug("接收服务器的信息:"+ackResultBuf.toString()); + return ackResultBuf.toString(); } catch (IOException e) { log.error("Socket sendCmd Error:" + e.getMessage()); return null; From 59b09efd76cdeedaf59dd22f3ae5aadb1658e83c Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Sat, 16 Jan 2021 10:03:45 +0800 Subject: [PATCH 073/172] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=AF=BB=E5=8F=96?= =?UTF-8?q?=E7=9A=84=E7=BB=93=E6=9E=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/telpo/dipperposition/common/SocketClient.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/telpo/dipperposition/common/SocketClient.java b/src/main/java/com/telpo/dipperposition/common/SocketClient.java index b8d4c4b..5217a14 100644 --- a/src/main/java/com/telpo/dipperposition/common/SocketClient.java +++ b/src/main/java/com/telpo/dipperposition/common/SocketClient.java @@ -71,7 +71,7 @@ public class SocketClient { is.close(); pw.close(); os.close(); - log.debug(ackResult); + //log.debug(ackResult); log.debug("接收服务器的信息:"+ackResultBuf.toString()); return ackResultBuf.toString(); } catch (IOException e) { From 7854e0b23289dded84351df97e89f0bc5bbedced Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Sat, 16 Jan 2021 10:41:49 +0800 Subject: [PATCH 074/172] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=AF=BB=E5=8F=96?= =?UTF-8?q?=E7=9A=84=E7=BB=93=E6=9E=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dipperposition/common/SocketClient.java | 33 +++++++++++-------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/telpo/dipperposition/common/SocketClient.java b/src/main/java/com/telpo/dipperposition/common/SocketClient.java index 5217a14..ebc3e5e 100644 --- a/src/main/java/com/telpo/dipperposition/common/SocketClient.java +++ b/src/main/java/com/telpo/dipperposition/common/SocketClient.java @@ -52,28 +52,35 @@ public class SocketClient { String reply=null; //输入流 InputStream is=socket.getInputStream(); - BufferedReader br=new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8)); + //BufferedReader br=new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8)); + ByteArrayOutputStream swapStream = new ByteArrayOutputStream(); + byte[] buff = new byte[100]; - StringBuffer ackResultBuf= new StringBuffer(); + //StringBuffer ackResultBuf= new StringBuffer(); //String ackHexOut = HexConvert.convertStringToHex(ackAckCheckRef); - reply=br.readLine(); - while(reply!=null){ - //log.debug("接收服务器的信息:"+reply); - //if (ackHexOut.equals(reply)) { - ackResultBuf.append(reply); - reply=br.readLine(); - // break; - //} +// reply=br.readLine(); +// while(reply!=null){ +// //log.debug("接收服务器的信息:"+reply); +// //if (ackHexOut.equals(reply)) { +// ackResultBuf.append(reply); +// reply=br.readLine(); +// // break; +// //} +// } + int rc = 0; + while ((rc = is.read(buff, 0, 100)) > 0) { + swapStream.write(buff, 0, rc); } + byte[] in2b = swapStream.toByteArray(); //String ackResult = HexConvert.convertHexToString(ackResultBuf.toString()); //4.关闭资源 - br.close(); + swapStream.close(); is.close(); pw.close(); os.close(); //log.debug(ackResult); - log.debug("接收服务器的信息:"+ackResultBuf.toString()); - return ackResultBuf.toString(); + log.debug("接收服务器的信息:"+in2b.toString()); + return in2b.toString(); } catch (IOException e) { log.error("Socket sendCmd Error:" + e.getMessage()); return null; From 2641bebed8ebada5f1d1764579d035e9edc22a66 Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Sat, 16 Jan 2021 10:47:02 +0800 Subject: [PATCH 075/172] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=AF=BB=E5=8F=96?= =?UTF-8?q?=E7=9A=84=E7=BB=93=E6=9E=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/telpo/dipperposition/common/SocketClient.java | 4 ++-- .../dipperposition/handler/NettyServerHandler.java | 7 +++++-- .../service/IDipperDataAsyncTaskService.java | 2 +- .../service/impl/DipperDataAsyncTaskServiceImpl.java | 10 +++++----- 4 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/telpo/dipperposition/common/SocketClient.java b/src/main/java/com/telpo/dipperposition/common/SocketClient.java index ebc3e5e..3dc7473 100644 --- a/src/main/java/com/telpo/dipperposition/common/SocketClient.java +++ b/src/main/java/com/telpo/dipperposition/common/SocketClient.java @@ -38,7 +38,7 @@ public class SocketClient { } - public String sendCmd(String astCmd, String ackAckCheckRef) { + public byte[] sendCmd(String astCmd, String ackAckCheckRef) { try { OutputStream os=socket.getOutputStream(); PrintWriter pw=new PrintWriter(os); @@ -80,7 +80,7 @@ public class SocketClient { os.close(); //log.debug(ackResult); log.debug("接收服务器的信息:"+in2b.toString()); - return in2b.toString(); + return in2b; } catch (IOException e) { log.error("Socket sendCmd Error:" + e.getMessage()); return null; diff --git a/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java b/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java index 8c38627..193a9ca 100644 --- a/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java +++ b/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java @@ -116,10 +116,12 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter { // 返回时间指令 //if (Integer.parseInt(timeAsycServerPort) == channel.localAddress().getPort()) { ByteBuf recvmg = (ByteBuf) msg; + ByteBuf buf = null; String recvmgStr = recvmg.toString(); if (AST_TIME_CMD.equals(recvmg)) { // 初始时间辅助输入; channelAns = dipperTimeAsyncTaskService.pushAstTime(); + buf = Unpooled.buffer(channelAns.getBytes().length); } // 发送SDBP-AST-POS获取辅助位置信息 @@ -131,12 +133,14 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter { centerProvince, ipPositionRequestPath, ipPositionRequestKey); + buf = Unpooled.buffer(channelAns.getBytes().length); } // 从缓存获取SDBP-AST-EPH星历数 //if (Integer.parseInt(starsAsycServerPort) == channel.localAddress().getPort()) { if (AST_POS_CMD.equals(recvmg)) { - channelAns = dipperDataAsyncTaskService.getAstEPH(); + byte[] astEPHBytes = dipperDataAsyncTaskService.getAstEPH(); + buf = Unpooled.buffer(astEPHBytes.length); } @@ -144,7 +148,6 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter { // 设备采用16进制获取数据,则代理服务器也是采用16进制返回数据。 // 通知客户端链消息发送成功 // String str = "服务端收到:" + LocalDateTime.now() + " " + msg + "\r\n"; - ByteBuf buf = Unpooled.buffer(channelAns.getBytes().length); buf.writeBytes(channelAns.getBytes("GBK")); ctx.writeAndFlush(buf); //ctx.write("你也好哦"); diff --git a/src/main/java/com/telpo/dipperposition/service/IDipperDataAsyncTaskService.java b/src/main/java/com/telpo/dipperposition/service/IDipperDataAsyncTaskService.java index 708e6df..ec70f9e 100644 --- a/src/main/java/com/telpo/dipperposition/service/IDipperDataAsyncTaskService.java +++ b/src/main/java/com/telpo/dipperposition/service/IDipperDataAsyncTaskService.java @@ -23,6 +23,6 @@ public interface IDipperDataAsyncTaskService { * 根据IP获取EPH * */ - String getAstEPH(); + byte[] getAstEPH(); } diff --git a/src/main/java/com/telpo/dipperposition/service/impl/DipperDataAsyncTaskServiceImpl.java b/src/main/java/com/telpo/dipperposition/service/impl/DipperDataAsyncTaskServiceImpl.java index aec944e..72b3a0a 100644 --- a/src/main/java/com/telpo/dipperposition/service/impl/DipperDataAsyncTaskServiceImpl.java +++ b/src/main/java/com/telpo/dipperposition/service/impl/DipperDataAsyncTaskServiceImpl.java @@ -32,7 +32,7 @@ public class DipperDataAsyncTaskServiceImpl implements IDipperDataAsyncTaskServi @Override public void pullAstEPH() { // (1) 发送bds获取星历数据 - String dipperData = pullEPHFromDipper(); + byte[] dipperData = pullEPHFromDipper(); // (2) 获取星历数据 if (dipperData == null) { @@ -44,7 +44,7 @@ public class DipperDataAsyncTaskServiceImpl implements IDipperDataAsyncTaskServi } - private String pullEPHFromDipper() { + private byte[] pullEPHFromDipper() { // 创建Socket客户端实例; SocketClient client = new SocketClient(schedulingExecutorConfig.getAstServer(), schedulingExecutorConfig.getEphAstHexPort(),schedulingExecutorConfig.getAstTimeout()); @@ -54,7 +54,7 @@ public class DipperDataAsyncTaskServiceImpl implements IDipperDataAsyncTaskServi String hexIn = astTimeCmd + HexConvert.makeChecksum(astTimeCmd); String ackAckCheckRef = "233E010102000421293C"; - String sendResult = client.sendCmd(hexIn, ackAckCheckRef); + byte[] sendResult = client.sendCmd(hexIn, ackAckCheckRef); client.closeConnection(); return sendResult; @@ -62,7 +62,7 @@ public class DipperDataAsyncTaskServiceImpl implements IDipperDataAsyncTaskServi @Override @Async("asyncServiceExecutor") - public String getAstEPH(){ - return (String)redisUtil.get(DIPPER_DATA_KEY); + public byte[] getAstEPH(){ + return (byte[])redisUtil.get(DIPPER_DATA_KEY); } } From 53f20e3317fecae46f87cc71b462e00e04ec7fa2 Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Sat, 16 Jan 2021 11:12:36 +0800 Subject: [PATCH 076/172] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=AF=BB=E5=8F=96?= =?UTF-8?q?=E7=9A=84=E7=BB=93=E6=9E=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/telpo/dipperposition/common/SocketClient.java | 6 +++--- .../dipperposition/handler/NettyServerHandler.java | 4 ++-- .../service/IDipperDataAsyncTaskService.java | 2 +- .../service/impl/DipperDataAsyncTaskServiceImpl.java | 10 +++++----- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/telpo/dipperposition/common/SocketClient.java b/src/main/java/com/telpo/dipperposition/common/SocketClient.java index 3dc7473..b017c6a 100644 --- a/src/main/java/com/telpo/dipperposition/common/SocketClient.java +++ b/src/main/java/com/telpo/dipperposition/common/SocketClient.java @@ -38,7 +38,7 @@ public class SocketClient { } - public byte[] sendCmd(String astCmd, String ackAckCheckRef) { + public String sendCmd(String astCmd, String ackAckCheckRef) { try { OutputStream os=socket.getOutputStream(); PrintWriter pw=new PrintWriter(os); @@ -79,8 +79,8 @@ public class SocketClient { pw.close(); os.close(); //log.debug(ackResult); - log.debug("接收服务器的信息:"+in2b.toString()); - return in2b; + log.debug("接收服务器的信息:"+HexConvert.BinaryToHexString(in2b)); + return HexConvert.BinaryToHexString(in2b); } catch (IOException e) { log.error("Socket sendCmd Error:" + e.getMessage()); return null; diff --git a/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java b/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java index 193a9ca..c552c23 100644 --- a/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java +++ b/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java @@ -139,8 +139,8 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter { // 从缓存获取SDBP-AST-EPH星历数 //if (Integer.parseInt(starsAsycServerPort) == channel.localAddress().getPort()) { if (AST_POS_CMD.equals(recvmg)) { - byte[] astEPHBytes = dipperDataAsyncTaskService.getAstEPH(); - buf = Unpooled.buffer(astEPHBytes.length); + String astEPHBytes = dipperDataAsyncTaskService.getAstEPH(); + buf = Unpooled.buffer(astEPHBytes.getBytes().length); } diff --git a/src/main/java/com/telpo/dipperposition/service/IDipperDataAsyncTaskService.java b/src/main/java/com/telpo/dipperposition/service/IDipperDataAsyncTaskService.java index ec70f9e..708e6df 100644 --- a/src/main/java/com/telpo/dipperposition/service/IDipperDataAsyncTaskService.java +++ b/src/main/java/com/telpo/dipperposition/service/IDipperDataAsyncTaskService.java @@ -23,6 +23,6 @@ public interface IDipperDataAsyncTaskService { * 根据IP获取EPH * */ - byte[] getAstEPH(); + String getAstEPH(); } diff --git a/src/main/java/com/telpo/dipperposition/service/impl/DipperDataAsyncTaskServiceImpl.java b/src/main/java/com/telpo/dipperposition/service/impl/DipperDataAsyncTaskServiceImpl.java index 72b3a0a..aec944e 100644 --- a/src/main/java/com/telpo/dipperposition/service/impl/DipperDataAsyncTaskServiceImpl.java +++ b/src/main/java/com/telpo/dipperposition/service/impl/DipperDataAsyncTaskServiceImpl.java @@ -32,7 +32,7 @@ public class DipperDataAsyncTaskServiceImpl implements IDipperDataAsyncTaskServi @Override public void pullAstEPH() { // (1) 发送bds获取星历数据 - byte[] dipperData = pullEPHFromDipper(); + String dipperData = pullEPHFromDipper(); // (2) 获取星历数据 if (dipperData == null) { @@ -44,7 +44,7 @@ public class DipperDataAsyncTaskServiceImpl implements IDipperDataAsyncTaskServi } - private byte[] pullEPHFromDipper() { + private String pullEPHFromDipper() { // 创建Socket客户端实例; SocketClient client = new SocketClient(schedulingExecutorConfig.getAstServer(), schedulingExecutorConfig.getEphAstHexPort(),schedulingExecutorConfig.getAstTimeout()); @@ -54,7 +54,7 @@ public class DipperDataAsyncTaskServiceImpl implements IDipperDataAsyncTaskServi String hexIn = astTimeCmd + HexConvert.makeChecksum(astTimeCmd); String ackAckCheckRef = "233E010102000421293C"; - byte[] sendResult = client.sendCmd(hexIn, ackAckCheckRef); + String sendResult = client.sendCmd(hexIn, ackAckCheckRef); client.closeConnection(); return sendResult; @@ -62,7 +62,7 @@ public class DipperDataAsyncTaskServiceImpl implements IDipperDataAsyncTaskServi @Override @Async("asyncServiceExecutor") - public byte[] getAstEPH(){ - return (byte[])redisUtil.get(DIPPER_DATA_KEY); + public String getAstEPH(){ + return (String)redisUtil.get(DIPPER_DATA_KEY); } } From 6224e5e04d6142e2a9e56e44e7d3f65f14c30b22 Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Mon, 18 Jan 2021 10:05:07 +0800 Subject: [PATCH 077/172] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=88=B0docker?= =?UTF-8?q?=E5=A4=96=E8=BF=90=E8=A1=8C=E7=8E=AF=E5=A2=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 18 +++-- setup_dev.sh | 58 ++++++++++++--- .../DipperPositionApplication.java | 5 -- .../dipperposition/common/TimeTools.java | 39 ---------- src/main/resources/bootstrap.yaml | 71 ++++++++++++++----- src/main/resources/log/logback-spring.xml | 3 +- 6 files changed, 116 insertions(+), 78 deletions(-) delete mode 100644 src/main/java/com/telpo/dipperposition/common/TimeTools.java diff --git a/pom.xml b/pom.xml index 9ae26f0..a56dba9 100644 --- a/pom.xml +++ b/pom.xml @@ -40,6 +40,12 @@ true + + + com.telpo + common + 1.1.19 + com.alibaba.cloud @@ -93,12 +99,6 @@ 4.1.13.Final - - com.telpo - common - 1.1.19 - - org.springframework.boot @@ -132,6 +132,12 @@ 2.0 + + com.mongodb + mongo + 1.0 + + diff --git a/setup_dev.sh b/setup_dev.sh index 3dfc300..ccac94b 100644 --- a/setup_dev.sh +++ b/setup_dev.sh @@ -3,25 +3,61 @@ mvn clean mvn package -Dmaven.test.skip=true #image_version=$(date +%Y%m%d%H%M) image_version=$version -docker stop dipperposition_service || true -docker rm dipperposition_service || true + +docker cp docker-jenkin:/var/jenkins_home/workspace/dipperpos_service/target/dipperposition.jar /home/data/dipperposition/dipperposition.jar +#docker stop dipperposition_service || true +#docker rm dipperposition_service || true # 删除镜像 -docker rmi -f $(docker images | grep telpo/dipperposition_service | awk '{print $3}') +#docker rmi -f $(docker images | grep telpo/dipperposition_service | awk '{print $3}') -docker build . -t telpo/dipperposition_service:$image_version +#docker build . -t telpo/dipperposition_service:$image_version #TODO:推送镜像到私有仓库 -echo '=================开始推送镜像=======================' -docker tag telpo/dipperposition_service:$image_version 139.224.254.18:5000/dipperposition_service:$image_version -docker push 139.224.254.18:5000/dipperposition_service:$image_version -echo '=================推送镜像完成=======================' +#echo '=================开始推送镜像=======================' +#docker tag telpo/dipperposition_service:$image_version 139.224.254.18:5000/dipperposition_service:$image_version +#docker push 139.224.254.18:5000/dipperposition_service:$image_version +#echo '=================推送镜像完成=======================' #删除产生的None镜像 -docker rmi -f $(docker images | grep none | awk '{print $3}') +#docker rmi -f $(docker images | grep none | awk '{print $3}') # 查看镜像列表 -docker images +#docker images # 启动容器 -docker run -v /home/data/dipperposition/log:/var/log/dipperposition -d -e active=dev --network host --restart=always -p 9011:9011 -p 9012:9012 -p 9013:9013 --name dipperposition_service 139.224.254.18:5000/dipperposition_service:$image_version +#docker run -v /home/data/dipperposition/log:/var/log/dipperposition -d -e active=dev --network host --restart=always +# -p 9011:9011 -p 9012:9012 -p 9013:9013 --name dipperposition_service 139.224.254.18:5000/dipperposition_service:$image_version + +#echo "scp ${WORKSPACE} files......begin" +#set passwd "telpo#1234" +#scp /var/jenkins_home/workspace/dipperpos_service/target/dipperposition.jar root@47.116.142.20:/home/data/dipperposition/dipperposition.jar +#expect { +# "密码:" +# { +# send "$passwd\n" +# } +# "pass" +# { +# send "$passwd\n" +# } +# +# "yes/no" +# { +# sleep 5 +# send_user "send yes" +# send "yes\n" +# } +# eof +# { +# sleep 5 +# send_user "eof\n" +# } +#} +#send "exit\r" +#expect eof +#echo "scp ${WORKSPACE} files......end" # 查看日志 # docker logs dipperposition_service + +echo '=================启动NettyAPP=======================' +java -jar -Xms256m -Xmx256m -Xss256k -XX:MetaspaceSize=256m -XX:MaxMetaspaceSize=512m /home/data/dipperposition/dipperposition.jar +echo '=================完成NettyAPP启动=======================' diff --git a/src/main/java/com/telpo/dipperposition/DipperPositionApplication.java b/src/main/java/com/telpo/dipperposition/DipperPositionApplication.java index bc64010..38c509d 100644 --- a/src/main/java/com/telpo/dipperposition/DipperPositionApplication.java +++ b/src/main/java/com/telpo/dipperposition/DipperPositionApplication.java @@ -44,12 +44,7 @@ public class DipperPositionApplication { log.info("北斗定位服务启动!"); //启动服务端 ConfigurableEnvironment environment = applicationContext.getEnvironment(); - //log.info(environment.toString()); - //log.info(environment.getProperty("position-server")); - //PositionConfigInfo pci; - //pci = (PositionConfigInfo)environment.getProperty("position-server"); DipperPositionServer nettyServer = new DipperPositionServer(environment); - //log.info(environment.getSystemProperties().toString()); nettyServer.start2(); } catch (Exception e) { log.error(e.getMessage()); diff --git a/src/main/java/com/telpo/dipperposition/common/TimeTools.java b/src/main/java/com/telpo/dipperposition/common/TimeTools.java deleted file mode 100644 index f23879c..0000000 --- a/src/main/java/com/telpo/dipperposition/common/TimeTools.java +++ /dev/null @@ -1,39 +0,0 @@ -package com.telpo.dipperposition.common; - -import tools.CommonTools; - -import java.time.LocalTime; -import java.time.format.DateTimeFormatter; - -/** - * @program: DataPushServer - * @description: 时间工具类 - * @author: linwl - * @create: 2020-08-05 11:16 - */ -public class TimeTools { - - private TimeTools() {} - - /** - * 校验时间段 - * - * @param startTime 起始时间 HH:mm - * @param endTime 结束时间 HH:mm - * @return - */ - public static boolean checkTime(String startTime, String endTime) { - boolean result = false; - DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("HH:mm"); - LocalTime pushStartTime = LocalTime.parse(startTime, dateTimeFormatter); - LocalTime pushEndTime = LocalTime.parse(endTime, dateTimeFormatter); - LocalTime zeroTime = LocalTime.parse("00:00"); - if (zeroTime.equals(pushEndTime)) { - pushEndTime = pushEndTime.plusNanos(-10); - } - if (CommonTools.checkInTime(pushStartTime, pushEndTime)) { - result = true; - } - return result; - } -} diff --git a/src/main/resources/bootstrap.yaml b/src/main/resources/bootstrap.yaml index 66034b2..9ea575b 100644 --- a/src/main/resources/bootstrap.yaml +++ b/src/main/resources/bootstrap.yaml @@ -1,20 +1,36 @@ +logging: + config: classpath:log/logback-spring.xml + level: + com: + telpo: + dipperposition: + server: debug + common: debug + service: debug + handler: debug spring: - main: - allow-bean-definition-overriding: true application: name: dipperposition-service - cloud: - nacos: - config: - server-addr: 172.16.192.26:8848 - file-extension: yaml + redis: + database: 1 + host: 172.19.42.44 + port: 8090 + password: telpo#1234 + timeout: 3000 + lettuce: + pool: + max-active: 100 # 连接池最大连接数(使用负值表示没有限制) + max-idle: 100 # 连接池中的最大空闲连接 + min-idle: 50 # 连接池中的最小空闲连接 + max-wait: 6000 # 连接池最大阻塞等待时间(使用负值表示没有限制) + scheduler: + pool: + size: 2 + #等待任务完成退出最大秒数 + await-seconds: 600 task: - pool: - size: 2 - #等待任务完成退出最大秒数 - await-seconds: 600 - cron: "0 */30 * * * *" + cron: "0 0 1 * * ?" pos: centerProvinceFilePath: /csv/provinceLonAlt.csv @@ -28,7 +44,30 @@ pos: timeout: 30000 position-server: - serverAddr: 172.16.192.26 - timeAsycPort: 9011 - posAsycPort: 9013 - starsAsycPort: 9012 \ No newline at end of file + serverAddr: localhost + timeAsycPort: 9011 + posAsycPort: 9013 + starsAsycPort: 9012 + +mongo: + datasource: + dblist: + - uri: mongodb://wangjx:wangjx#1234@172.19.42.40:27018/basicdatatest + database: basicdata + - uri: mongodb://wangjx:wangjx#1234@172.19.42.40:27018/commontest + database: common + + +OkHttp-config: + pool: + max-conn: 200 + keep-alive: 5 + read-timeout: 10 + conn-timeout: 10 + write-timeout: 10 + +async: + pool: + corePoolSize: 4 + maxPoolSize: 8 + queueCapacity: 5000 \ No newline at end of file diff --git a/src/main/resources/log/logback-spring.xml b/src/main/resources/log/logback-spring.xml index f4101af..4b080ce 100644 --- a/src/main/resources/log/logback-spring.xml +++ b/src/main/resources/log/logback-spring.xml @@ -7,7 +7,8 @@ - + + From d2f6fcade1f86c5d0477f72c390702767096d77b Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Mon, 18 Jan 2021 10:14:45 +0800 Subject: [PATCH 078/172] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=88=B0docker?= =?UTF-8?q?=E5=A4=96=E8=BF=90=E8=A1=8C=E7=8E=AF=E5=A2=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- setup_dev.sh | 3 ++- src/main/resources/bootstrap.yaml | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/setup_dev.sh b/setup_dev.sh index ccac94b..6b3dbc1 100644 --- a/setup_dev.sh +++ b/setup_dev.sh @@ -4,7 +4,8 @@ mvn package -Dmaven.test.skip=true #image_version=$(date +%Y%m%d%H%M) image_version=$version -docker cp docker-jenkin:/var/jenkins_home/workspace/dipperpos_service/target/dipperposition.jar /home/data/dipperposition/dipperposition.jar +docker cp docker_jenkins:/var/jenkins_home/workspace/dipperpos_service/target/dipperposition.jar +/home/data/dipperposition #docker stop dipperposition_service || true #docker rm dipperposition_service || true diff --git a/src/main/resources/bootstrap.yaml b/src/main/resources/bootstrap.yaml index 9ea575b..8a2c369 100644 --- a/src/main/resources/bootstrap.yaml +++ b/src/main/resources/bootstrap.yaml @@ -13,7 +13,7 @@ spring: name: dipperposition-service redis: database: 1 - host: 172.19.42.44 + host: 172.16.192.26 port: 8090 password: telpo#1234 timeout: 3000 @@ -52,9 +52,9 @@ position-server: mongo: datasource: dblist: - - uri: mongodb://wangjx:wangjx#1234@172.19.42.40:27018/basicdatatest + - uri: mongodb://wangjx:wangjx#1234@172.16.192.26:27017/basicdata database: basicdata - - uri: mongodb://wangjx:wangjx#1234@172.19.42.40:27018/commontest + - uri: mongodb://wangjx:wangjx#1234@172.16.192.26:27017/common database: common From 003b0fe736618e970cf5e7b358a669139c6a4467 Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Mon, 18 Jan 2021 10:33:48 +0800 Subject: [PATCH 079/172] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=88=B0docker?= =?UTF-8?q?=E5=A4=96=E8=BF=90=E8=A1=8C=E7=8E=AF=E5=A2=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- setup_dev.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/setup_dev.sh b/setup_dev.sh index 6b3dbc1..dc78f39 100644 --- a/setup_dev.sh +++ b/setup_dev.sh @@ -4,8 +4,7 @@ mvn package -Dmaven.test.skip=true #image_version=$(date +%Y%m%d%H%M) image_version=$version -docker cp docker_jenkins:/var/jenkins_home/workspace/dipperpos_service/target/dipperposition.jar -/home/data/dipperposition +docker cp docker_jenkins:/var/jenkins_home/workspace/dipperpos_service/target/dipperposition.jar /home/data/dipperposition/dipperposition.jar #docker stop dipperposition_service || true #docker rm dipperposition_service || true @@ -60,5 +59,6 @@ docker cp docker_jenkins:/var/jenkins_home/workspace/dipperpos_service/target/di # docker logs dipperposition_service echo '=================启动NettyAPP=======================' +ps -ef |grep dipperposition |awk '{print $2}'|xargs kill -9 java -jar -Xms256m -Xmx256m -Xss256k -XX:MetaspaceSize=256m -XX:MaxMetaspaceSize=512m /home/data/dipperposition/dipperposition.jar echo '=================完成NettyAPP启动=======================' From b7582d72016512b981ab8fd49f6416c5deb3b77f Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Mon, 18 Jan 2021 10:42:16 +0800 Subject: [PATCH 080/172] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=88=B0docker?= =?UTF-8?q?=E5=A4=96=E8=BF=90=E8=A1=8C=E7=8E=AF=E5=A2=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- setup_dev.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/setup_dev.sh b/setup_dev.sh index dc78f39..5143a3e 100644 --- a/setup_dev.sh +++ b/setup_dev.sh @@ -4,7 +4,7 @@ mvn package -Dmaven.test.skip=true #image_version=$(date +%Y%m%d%H%M) image_version=$version -docker cp docker_jenkins:/var/jenkins_home/workspace/dipperpos_service/target/dipperposition.jar /home/data/dipperposition/dipperposition.jar +docker cp docker_jenkins:/var/jenkins_home/workspace/dipperpos_service/target/dipperposition.jar /usr/local/dipperposition/dipperposition.jar #docker stop dipperposition_service || true #docker rm dipperposition_service || true @@ -60,5 +60,5 @@ docker cp docker_jenkins:/var/jenkins_home/workspace/dipperpos_service/target/di echo '=================启动NettyAPP=======================' ps -ef |grep dipperposition |awk '{print $2}'|xargs kill -9 -java -jar -Xms256m -Xmx256m -Xss256k -XX:MetaspaceSize=256m -XX:MaxMetaspaceSize=512m /home/data/dipperposition/dipperposition.jar +java -jar -Xms256m -Xmx256m -Xss256k -XX:MetaspaceSize=256m -XX:MaxMetaspaceSize=512m /usr/local/dipperposition/dipperposition.jar echo '=================完成NettyAPP启动=======================' From 37357a6d11d7b2cc5b61c68b0e8f7d88f121cb93 Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Mon, 18 Jan 2021 10:52:06 +0800 Subject: [PATCH 081/172] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=88=B0docker?= =?UTF-8?q?=E5=A4=96=E8=BF=90=E8=A1=8C=E7=8E=AF=E5=A2=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/bootstrap.yaml | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/main/resources/bootstrap.yaml b/src/main/resources/bootstrap.yaml index 8a2c369..eafa131 100644 --- a/src/main/resources/bootstrap.yaml +++ b/src/main/resources/bootstrap.yaml @@ -3,11 +3,7 @@ logging: level: com: telpo: - dipperposition: - server: debug - common: debug - service: debug - handler: debug + dipperposition: debug spring: application: name: dipperposition-service From b62cd990f473b6cc2dd78e0d2f6262395f721f05 Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Mon, 18 Jan 2021 15:23:38 +0800 Subject: [PATCH 082/172] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=88=B0docker?= =?UTF-8?q?=E5=A4=96=E8=BF=90=E8=A1=8C=E7=8E=AF=E5=A2=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/bootstrap-dev.yaml | 1 - src/main/resources/bootstrap.yaml | 4 ++++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/resources/bootstrap-dev.yaml b/src/main/resources/bootstrap-dev.yaml index 8f21889..ea07582 100644 --- a/src/main/resources/bootstrap-dev.yaml +++ b/src/main/resources/bootstrap-dev.yaml @@ -6,5 +6,4 @@ spring: cloud: nacos: config: - server-addr: 172.16.192.26:8848 file-extension: yaml \ No newline at end of file diff --git a/src/main/resources/bootstrap.yaml b/src/main/resources/bootstrap.yaml index eafa131..8f8ae14 100644 --- a/src/main/resources/bootstrap.yaml +++ b/src/main/resources/bootstrap.yaml @@ -7,6 +7,10 @@ logging: spring: application: name: dipperposition-service + cloud: + nacos: + config: + file-extension: yaml redis: database: 1 host: 172.16.192.26 From f6e8de3725c8e6ec8c0eaa955d63308d5ecacf02 Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Mon, 18 Jan 2021 15:24:40 +0800 Subject: [PATCH 083/172] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=88=B0docker?= =?UTF-8?q?=E5=A4=96=E8=BF=90=E8=A1=8C=E7=8E=AF=E5=A2=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- setup_dev.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup_dev.sh b/setup_dev.sh index 5143a3e..dd13c77 100644 --- a/setup_dev.sh +++ b/setup_dev.sh @@ -60,5 +60,5 @@ docker cp docker_jenkins:/var/jenkins_home/workspace/dipperpos_service/target/di echo '=================启动NettyAPP=======================' ps -ef |grep dipperposition |awk '{print $2}'|xargs kill -9 -java -jar -Xms256m -Xmx256m -Xss256k -XX:MetaspaceSize=256m -XX:MaxMetaspaceSize=512m /usr/local/dipperposition/dipperposition.jar +java -jar -Xms256m -Xmx256m -Xss256k -XX:MetaspaceSize=256m -XX:MaxMetaspaceSize=512m /usr/local/dipperposition/dipperposition.jar --spring.profiles.active=dev echo '=================完成NettyAPP启动=======================' From f7224e87473b464dd1d235f886d254fca46ed181 Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Mon, 18 Jan 2021 15:57:25 +0800 Subject: [PATCH 084/172] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=88=B0docker?= =?UTF-8?q?=E5=A4=96=E8=BF=90=E8=A1=8C=E7=8E=AF=E5=A2=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/telpo/dipperposition/server/DipperPositionServer.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/telpo/dipperposition/server/DipperPositionServer.java b/src/main/java/com/telpo/dipperposition/server/DipperPositionServer.java index f81ddfc..64855c4 100644 --- a/src/main/java/com/telpo/dipperposition/server/DipperPositionServer.java +++ b/src/main/java/com/telpo/dipperposition/server/DipperPositionServer.java @@ -244,7 +244,7 @@ public class DipperPositionServer { } }); - //channelFuture.channel().closeFuture().sync(); + channelFuture.channel().closeFuture().sync(); } catch (InterruptedException e) { e.printStackTrace(); } finally { From 910c8aa7b5d4e3ab9fc7e0b0751f2c0fda949fef Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Mon, 18 Jan 2021 16:55:23 +0800 Subject: [PATCH 085/172] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=88=B0docker?= =?UTF-8?q?=E5=A4=96=E8=BF=90=E8=A1=8C=E7=8E=AF=E5=A2=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 6 +++ .../config/NettyServerConfig.java | 33 ++++++++++++ .../dipperposition/config/PositionConfig.java | 50 +++++++------------ .../handler/NettyServerHandler.java | 45 +++++------------ 4 files changed, 68 insertions(+), 66 deletions(-) create mode 100644 src/main/java/com/telpo/dipperposition/config/NettyServerConfig.java diff --git a/pom.xml b/pom.xml index a56dba9..56a6dc9 100644 --- a/pom.xml +++ b/pom.xml @@ -57,6 +57,12 @@ spring-cloud-starter-alibaba-nacos-config + + com.alibaba.boot + nacos-config-spring-boot-starter + 0.2.7 + + com.alibaba.nacos nacos-client diff --git a/src/main/java/com/telpo/dipperposition/config/NettyServerConfig.java b/src/main/java/com/telpo/dipperposition/config/NettyServerConfig.java new file mode 100644 index 0000000..0096803 --- /dev/null +++ b/src/main/java/com/telpo/dipperposition/config/NettyServerConfig.java @@ -0,0 +1,33 @@ +package com.telpo.dipperposition.config; + +import com.alibaba.nacos.api.config.annotation.NacosValue; +import com.alibaba.nacos.spring.context.annotation.config.NacosPropertySource; +import lombok.Getter; +import lombok.Setter; +import org.springframework.context.annotation.Configuration; + +/** + * @program: gateway + * @description: jwt设置 + * @author: linwl + * @create: 2020-06-18 17:45 + */ +@Getter +@Setter +@Configuration +@NacosPropertySource(dataId="position-server", autoRefreshed=true) +public class NettyServerConfig { + + @NacosValue(value = "${serverAddr}") + private String serverAddr; + + @NacosValue(value = "${timeAsycPort:9011}") + private String timeAsycServerPort; + + @NacosValue(value = "${posAsycPort}") + private String posAsycServerPort; + + @NacosValue(value = "${starsAsycPort}") + private String starsAsycServerPort; + +} diff --git a/src/main/java/com/telpo/dipperposition/config/PositionConfig.java b/src/main/java/com/telpo/dipperposition/config/PositionConfig.java index 6e7d36e..b1b36ff 100644 --- a/src/main/java/com/telpo/dipperposition/config/PositionConfig.java +++ b/src/main/java/com/telpo/dipperposition/config/PositionConfig.java @@ -1,5 +1,7 @@ package com.telpo.dipperposition.config; +import com.alibaba.nacos.api.config.annotation.NacosValue; +import com.alibaba.nacos.spring.context.annotation.config.NacosPropertySource; import com.telpo.dipperposition.co.PositionConfigInfo; import lombok.Getter; import lombok.Setter; @@ -20,42 +22,24 @@ import org.springframework.context.annotation.Configuration; @Getter @Setter @Configuration +@NacosPropertySource(dataId="pos", autoRefreshed=true) public class PositionConfig { - //@Autowired - //private ConfigurableApplicationContext configurableApplicationContext; - //@Value(value = "${position.hello}") - //private String hello; + @NacosValue("${centerProvinceFilePath}") + String centerProvinceFilePath; - //@Value(value = "${spring.application.name}") - //private String name; + @NacosValue("${ipPositionRequestPath}") + String ipPositionRequestPath; + @NacosValue("${ipPositionRequestKey}") + String ipPositionRequestKey; + @NacosValue("${centerProvince}") + String centerProvince; -// @Value(value = "${position.server.serverAddr}") -// private String serverAddr; -// -// @Value(value = "${position.server.timeAsycPort}") -// private String timeAsycServerPort; -// -// @Value(value = "${position.server.posAsycPort}") -// private String posAsycServerPort; -// -// @Value(value = "${position.server.starsAsycPort}") -// private String starsAsycServerPort; - PositionConfig() - { - //hello = configurableApplicationContext.getEnvironment().getProperty("position.hello"); - //name = configurableApplicationContext.getEnvironment().getProperty("spring.application.name"); - } -// -// @Bean (name = "positionConfigInfo") -// public PositionConfigInfo positionConfigInfo(){ -// PositionConfigInfo configInfo = new PositionConfigInfo(); -// configInfo.setServerAddr(this.serverAddr); -// configInfo.setTimeAsycServerPort(this.timeAsycServerPort); -// configInfo.setPosAsycServerPort(this.posAsycServerPort); -// configInfo.setStarsAsycServerPort(this.starsAsycServerPort); -// System.out.print(configInfo.toString()); -// return configInfo; -// } + @NacosValue("${astServer}") + String astServer; + @NacosValue("${astPosAstPort}") + int posAstPort; + @NacosValue("${astTimeout}") + int astTimeout; } diff --git a/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java b/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java index c552c23..f176aeb 100644 --- a/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java +++ b/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java @@ -1,5 +1,7 @@ package com.telpo.dipperposition.handler; +import com.telpo.dipperposition.config.NettyServerConfig; +import com.telpo.dipperposition.config.PositionConfig; import com.telpo.dipperposition.enums.DipperReturnValue; import com.telpo.dipperposition.service.IDipperAstPosAsyncTaskService; import com.telpo.dipperposition.service.IDipperAstTimeAsyncTaskService; @@ -36,33 +38,10 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter { @Autowired private IDipperDataAsyncTaskService dipperDataAsyncTaskService; - @Value(value = "${position-server.timeAsycPort}") - private String timeAsycServerPort; - - @Value(value = "${position-server.posAsycPort}") - private String posAsycServerPort; - - @Value(value = "${position-server.starsAsycPort}") - private String starsAsycServerPort; - - - @Value("${pos.centerProvinceFilePath}") - String centerProvinceFilePath; - - @Value("${pos.ipPositionRequestPath}") - String ipPositionRequestPath; - @Value("${pos.ipPositionRequestKey}") - String ipPositionRequestKey; - @Value("${pos.centerProvince}") - String centerProvince; - - - @Value("${pos.ast.server}") - String astServer; - @Value("${pos.ast.posAstPort}") - int posAstPort; - @Value("${pos.ast.timeout}") - int astTimeout; + @Autowired + private NettyServerConfig nettyServerConfig; + @Autowired + private PositionConfig positionConfig; /** * 客户端连接会触发 */ @@ -79,10 +58,10 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter { //通知客户端链接建立成功 // 默认返回取得时间成功 String ackAckCheckRef = "233E0101020004020A1D"; - if (Integer.parseInt(posAsycServerPort) == channel.localAddress().getPort()) { + if (Integer.parseInt(nettyServerConfig.getPosAsycServerPort()) == channel.localAddress().getPort()) { ackAckCheckRef = "233E010102000401091C"; } - if (Integer.parseInt(starsAsycServerPort) == channel.localAddress().getPort()) { + if (Integer.parseInt(nettyServerConfig.getStarsAsycServerPort()) == channel.localAddress().getPort()) { ackAckCheckRef = "233E010102000421293C"; } //String str = "通知客户端链接建立成功" + " " + LocalDateTime.now() + " " + channel.localAddress().getHostString() + @@ -129,10 +108,10 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter { if (AST_POS_CMD.equals(recvmg)) { channelAns = dipperAstPosAsyncTaskService.pushAstPos(ipAddress, - centerProvinceFilePath, - centerProvince, - ipPositionRequestPath, - ipPositionRequestKey); + positionConfig.getCenterProvinceFilePath(), + positionConfig.getCenterProvince(), + positionConfig.getIpPositionRequestPath(), + positionConfig.getIpPositionRequestKey()); buf = Unpooled.buffer(channelAns.getBytes().length); } From 3d0675b874f34a80dc3f4cdcfc4d69dc0c26b8b9 Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Mon, 18 Jan 2021 17:06:15 +0800 Subject: [PATCH 086/172] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=88=B0docker?= =?UTF-8?q?=E5=A4=96=E8=BF=90=E8=A1=8C=E7=8E=AF=E5=A2=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../config/NettyServerConfig.java | 10 ++++---- .../dipperposition/config/PositionConfig.java | 23 +++++++------------ 2 files changed, 13 insertions(+), 20 deletions(-) diff --git a/src/main/java/com/telpo/dipperposition/config/NettyServerConfig.java b/src/main/java/com/telpo/dipperposition/config/NettyServerConfig.java index 0096803..58e328e 100644 --- a/src/main/java/com/telpo/dipperposition/config/NettyServerConfig.java +++ b/src/main/java/com/telpo/dipperposition/config/NettyServerConfig.java @@ -15,19 +15,19 @@ import org.springframework.context.annotation.Configuration; @Getter @Setter @Configuration -@NacosPropertySource(dataId="position-server", autoRefreshed=true) +@NacosPropertySource(dataId="dipperposition-service", autoRefreshed=true) public class NettyServerConfig { - @NacosValue(value = "${serverAddr}") + @NacosValue(value = "${position-server.serverAddr}") private String serverAddr; - @NacosValue(value = "${timeAsycPort:9011}") + @NacosValue(value = "${position-server.timeAsycPort:9011}") private String timeAsycServerPort; - @NacosValue(value = "${posAsycPort}") + @NacosValue(value = "${position-server.posAsycPort}") private String posAsycServerPort; - @NacosValue(value = "${starsAsycPort}") + @NacosValue(value = "${position-server.starsAsycPort}") private String starsAsycServerPort; } diff --git a/src/main/java/com/telpo/dipperposition/config/PositionConfig.java b/src/main/java/com/telpo/dipperposition/config/PositionConfig.java index b1b36ff..a55f01b 100644 --- a/src/main/java/com/telpo/dipperposition/config/PositionConfig.java +++ b/src/main/java/com/telpo/dipperposition/config/PositionConfig.java @@ -2,15 +2,8 @@ package com.telpo.dipperposition.config; import com.alibaba.nacos.api.config.annotation.NacosValue; import com.alibaba.nacos.spring.context.annotation.config.NacosPropertySource; -import com.telpo.dipperposition.co.PositionConfigInfo; import lombok.Getter; import lombok.Setter; -import lombok.ToString; -import okhttp3.OkHttpClient; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.context.ConfigurableApplicationContext; -import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; /** @@ -22,24 +15,24 @@ import org.springframework.context.annotation.Configuration; @Getter @Setter @Configuration -@NacosPropertySource(dataId="pos", autoRefreshed=true) +@NacosPropertySource(dataId="dipperposition-service", autoRefreshed=true) public class PositionConfig { - @NacosValue("${centerProvinceFilePath}") + @NacosValue("${pos.centerProvinceFilePath}") String centerProvinceFilePath; - @NacosValue("${ipPositionRequestPath}") + @NacosValue("${pos.ipPositionRequestPath}") String ipPositionRequestPath; - @NacosValue("${ipPositionRequestKey}") + @NacosValue("${pos.ipPositionRequestKey}") String ipPositionRequestKey; - @NacosValue("${centerProvince}") + @NacosValue("${pos.centerProvince}") String centerProvince; - @NacosValue("${astServer}") + @NacosValue("${pos.astServer}") String astServer; - @NacosValue("${astPosAstPort}") + @NacosValue("${pos.astPosAstPort}") int posAstPort; - @NacosValue("${astTimeout}") + @NacosValue("${pos.astTimeout}") int astTimeout; } From f63310cb98a78d91dda5cc2233d5dc736c674e69 Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Mon, 18 Jan 2021 17:12:27 +0800 Subject: [PATCH 087/172] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=88=B0docker?= =?UTF-8?q?=E5=A4=96=E8=BF=90=E8=A1=8C=E7=8E=AF=E5=A2=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../handler/NettyServerHandler.java | 24 ++++++++++++++----- 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java b/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java index f176aeb..2ed49b1 100644 --- a/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java +++ b/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java @@ -58,10 +58,17 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter { //通知客户端链接建立成功 // 默认返回取得时间成功 String ackAckCheckRef = "233E0101020004020A1D"; - if (Integer.parseInt(nettyServerConfig.getPosAsycServerPort()) == channel.localAddress().getPort()) { +// if (Integer.parseInt(nettyServerConfig.getPosAsycServerPort()) == channel.localAddress().getPort()) { +// ackAckCheckRef = "233E010102000401091C"; +// } +// if (Integer.parseInt(nettyServerConfig.getStarsAsycServerPort()) == channel.localAddress().getPort()) { +// ackAckCheckRef = "233E010102000421293C"; +// } + + if (9013 == channel.localAddress().getPort()) { ackAckCheckRef = "233E010102000401091C"; } - if (Integer.parseInt(nettyServerConfig.getStarsAsycServerPort()) == channel.localAddress().getPort()) { + if (9012 == channel.localAddress().getPort()) { ackAckCheckRef = "233E010102000421293C"; } //String str = "通知客户端链接建立成功" + " " + LocalDateTime.now() + " " + channel.localAddress().getHostString() + @@ -107,11 +114,16 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter { // if (Integer.parseInt(posAsycServerPort) == channel.localAddress().getPort()) { if (AST_POS_CMD.equals(recvmg)) { +// channelAns = dipperAstPosAsyncTaskService.pushAstPos(ipAddress, +// positionConfig.getCenterProvinceFilePath(), +// positionConfig.getCenterProvince(), +// positionConfig.getIpPositionRequestPath(), +// positionConfig.getIpPositionRequestKey()); channelAns = dipperAstPosAsyncTaskService.pushAstPos(ipAddress, - positionConfig.getCenterProvinceFilePath(), - positionConfig.getCenterProvince(), - positionConfig.getIpPositionRequestPath(), - positionConfig.getIpPositionRequestKey()); + "/csv/provinceLonAlt.csv", + "湖北省", + "https://restapi.amap.com/v3/ip", + "65e794b0a1a4b87eeec86f93fea05411"); buf = Unpooled.buffer(channelAns.getBytes().length); } From 5d17c1fd0636b1d5dfdbace8012a26512bf4b471 Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Mon, 18 Jan 2021 17:32:14 +0800 Subject: [PATCH 088/172] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=88=B0docker?= =?UTF-8?q?=E5=A4=96=E8=BF=90=E8=A1=8C=E7=8E=AF=E5=A2=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../telpo/dipperposition/handler/NettyServerHandler.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java b/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java index 2ed49b1..9cb2179 100644 --- a/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java +++ b/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java @@ -92,11 +92,11 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter { */ @Override public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { - //接收msg消息{与上一章节相比,此处已经不需要自己进行解码} + //接收msg消息与上一章节相比,此处已经不需要自己进行解码} SocketChannel channel = (SocketChannel) ctx.channel(); String ipAddress = channel.remoteAddress().toString(); - String message = " 接收到消息:{0}, 客户端IP:{1}"; - log.info(message ,msg, ipAddress); + //String message = " 接收到消息:{0}, 客户端IP:{1}"; + log.info("接收到消息:" + msg + "客户端IP:" + ipAddress); String channelAns = ""; // 返回时间指令 @@ -134,7 +134,7 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter { buf = Unpooled.buffer(astEPHBytes.getBytes().length); } - + log.info(buf.toString()); // 最后把SDBP-AST-TIME、SDBP-AST-POS、SDBP-AST-EPH并包一起发给设备。 // 设备采用16进制获取数据,则代理服务器也是采用16进制返回数据。 // 通知客户端链消息发送成功 From 7d83bee575633ecb4d9fc560331430e2180a8944 Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Mon, 18 Jan 2021 17:43:22 +0800 Subject: [PATCH 089/172] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=88=B0docker?= =?UTF-8?q?=E5=A4=96=E8=BF=90=E8=A1=8C=E7=8E=AF=E5=A2=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../handler/NettyServerHandler.java | 44 +++++++++---------- 1 file changed, 21 insertions(+), 23 deletions(-) diff --git a/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java b/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java index 9cb2179..492ecf7 100644 --- a/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java +++ b/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java @@ -58,19 +58,19 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter { //通知客户端链接建立成功 // 默认返回取得时间成功 String ackAckCheckRef = "233E0101020004020A1D"; -// if (Integer.parseInt(nettyServerConfig.getPosAsycServerPort()) == channel.localAddress().getPort()) { -// ackAckCheckRef = "233E010102000401091C"; -// } -// if (Integer.parseInt(nettyServerConfig.getStarsAsycServerPort()) == channel.localAddress().getPort()) { -// ackAckCheckRef = "233E010102000421293C"; -// } - - if (9013 == channel.localAddress().getPort()) { + if (Integer.parseInt(nettyServerConfig.getPosAsycServerPort()) == channel.localAddress().getPort()) { ackAckCheckRef = "233E010102000401091C"; } - if (9012 == channel.localAddress().getPort()) { + if (Integer.parseInt(nettyServerConfig.getStarsAsycServerPort()) == channel.localAddress().getPort()) { ackAckCheckRef = "233E010102000421293C"; } + +// if (9013 == channel.localAddress().getPort()) { +// ackAckCheckRef = "233E010102000401091C"; +// } +// if (9012 == channel.localAddress().getPort()) { +// ackAckCheckRef = "233E010102000421293C"; +// } //String str = "通知客户端链接建立成功" + " " + LocalDateTime.now() + " " + channel.localAddress().getHostString() + // "\r\n"; ByteBuf buf = Unpooled.buffer(ackAckCheckRef.getBytes().length); @@ -107,34 +107,32 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter { if (AST_TIME_CMD.equals(recvmg)) { // 初始时间辅助输入; channelAns = dipperTimeAsyncTaskService.pushAstTime(); - buf = Unpooled.buffer(channelAns.getBytes().length); } // 发送SDBP-AST-POS获取辅助位置信息 // if (Integer.parseInt(posAsycServerPort) == channel.localAddress().getPort()) { if (AST_POS_CMD.equals(recvmg)) { -// channelAns = dipperAstPosAsyncTaskService.pushAstPos(ipAddress, -// positionConfig.getCenterProvinceFilePath(), -// positionConfig.getCenterProvince(), -// positionConfig.getIpPositionRequestPath(), -// positionConfig.getIpPositionRequestKey()); channelAns = dipperAstPosAsyncTaskService.pushAstPos(ipAddress, - "/csv/provinceLonAlt.csv", - "湖北省", - "https://restapi.amap.com/v3/ip", - "65e794b0a1a4b87eeec86f93fea05411"); - buf = Unpooled.buffer(channelAns.getBytes().length); + positionConfig.getCenterProvinceFilePath(), + positionConfig.getCenterProvince(), + positionConfig.getIpPositionRequestPath(), + positionConfig.getIpPositionRequestKey()); +// channelAns = dipperAstPosAsyncTaskService.pushAstPos(ipAddress, +// "/csv/provinceLonAlt.csv", +// "湖北省", +// "https://restapi.amap.com/v3/ip", +// "65e794b0a1a4b87eeec86f93fea05411"); } // 从缓存获取SDBP-AST-EPH星历数 //if (Integer.parseInt(starsAsycServerPort) == channel.localAddress().getPort()) { if (AST_POS_CMD.equals(recvmg)) { - String astEPHBytes = dipperDataAsyncTaskService.getAstEPH(); - buf = Unpooled.buffer(astEPHBytes.getBytes().length); + channelAns = dipperDataAsyncTaskService.getAstEPH(); } - log.info(buf.toString()); + log.info(channelAns); + buf = Unpooled.buffer(channelAns.getBytes().length); // 最后把SDBP-AST-TIME、SDBP-AST-POS、SDBP-AST-EPH并包一起发给设备。 // 设备采用16进制获取数据,则代理服务器也是采用16进制返回数据。 // 通知客户端链消息发送成功 From 233dc29bbb0d7f7c1f65f1334627c0cf41bed93a Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Mon, 18 Jan 2021 17:47:36 +0800 Subject: [PATCH 090/172] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=88=B0docker?= =?UTF-8?q?=E5=A4=96=E8=BF=90=E8=A1=8C=E7=8E=AF=E5=A2=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../handler/NettyServerHandler.java | 36 +++++++++---------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java b/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java index 492ecf7..73e49e0 100644 --- a/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java +++ b/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java @@ -58,19 +58,19 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter { //通知客户端链接建立成功 // 默认返回取得时间成功 String ackAckCheckRef = "233E0101020004020A1D"; - if (Integer.parseInt(nettyServerConfig.getPosAsycServerPort()) == channel.localAddress().getPort()) { - ackAckCheckRef = "233E010102000401091C"; - } - if (Integer.parseInt(nettyServerConfig.getStarsAsycServerPort()) == channel.localAddress().getPort()) { - ackAckCheckRef = "233E010102000421293C"; - } - -// if (9013 == channel.localAddress().getPort()) { +// if (Integer.parseInt(nettyServerConfig.getPosAsycServerPort()) == channel.localAddress().getPort()) { // ackAckCheckRef = "233E010102000401091C"; // } -// if (9012 == channel.localAddress().getPort()) { +// if (Integer.parseInt(nettyServerConfig.getStarsAsycServerPort()) == channel.localAddress().getPort()) { // ackAckCheckRef = "233E010102000421293C"; // } + + if (9013 == channel.localAddress().getPort()) { + ackAckCheckRef = "233E010102000401091C"; + } + if (9012 == channel.localAddress().getPort()) { + ackAckCheckRef = "233E010102000421293C"; + } //String str = "通知客户端链接建立成功" + " " + LocalDateTime.now() + " " + channel.localAddress().getHostString() + // "\r\n"; ByteBuf buf = Unpooled.buffer(ackAckCheckRef.getBytes().length); @@ -113,16 +113,16 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter { // if (Integer.parseInt(posAsycServerPort) == channel.localAddress().getPort()) { if (AST_POS_CMD.equals(recvmg)) { - channelAns = dipperAstPosAsyncTaskService.pushAstPos(ipAddress, - positionConfig.getCenterProvinceFilePath(), - positionConfig.getCenterProvince(), - positionConfig.getIpPositionRequestPath(), - positionConfig.getIpPositionRequestKey()); // channelAns = dipperAstPosAsyncTaskService.pushAstPos(ipAddress, -// "/csv/provinceLonAlt.csv", -// "湖北省", -// "https://restapi.amap.com/v3/ip", -// "65e794b0a1a4b87eeec86f93fea05411"); +// positionConfig.getCenterProvinceFilePath(), +// positionConfig.getCenterProvince(), +// positionConfig.getIpPositionRequestPath(), +// positionConfig.getIpPositionRequestKey()); + channelAns = dipperAstPosAsyncTaskService.pushAstPos(ipAddress, + "/csv/provinceLonAlt.csv", + "湖北省", + "https://restapi.amap.com/v3/ip", + "65e794b0a1a4b87eeec86f93fea05411"); } // 从缓存获取SDBP-AST-EPH星历数 From 01a7c500a383a919d2d9ebb774aee8de0aeb128c Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Mon, 18 Jan 2021 17:53:10 +0800 Subject: [PATCH 091/172] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=88=B0docker?= =?UTF-8?q?=E5=A4=96=E8=BF=90=E8=A1=8C=E7=8E=AF=E5=A2=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../handler/NettyServerHandler.java | 24 ++++++++++++------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java b/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java index 73e49e0..86868d7 100644 --- a/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java +++ b/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java @@ -27,9 +27,12 @@ import java.time.LocalDateTime; @Slf4j public class NettyServerHandler extends ChannelInboundHandlerAdapter { - private static String AST_TIME_CMD = "54494d45"; - private static String AST_POS_CMD = "504f53"; - private static String AST_EPH_CMD = "455048"; + private static String AST_TIME_CMD = "TIME"; + private static String AST_POS_CMD = "POS"; + private static String AST_EPH_CMD = "EPH"; + private static String AST_TIME_CMD_BYTE = "54494d45"; + private static String AST_POS_CMD_BYTE = "504f53"; + private static String AST_EPH_CMD_BYTE = "455048"; @Autowired private IDipperAstTimeAsyncTaskService dipperTimeAsyncTaskService; @@ -96,15 +99,16 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter { SocketChannel channel = (SocketChannel) ctx.channel(); String ipAddress = channel.remoteAddress().toString(); //String message = " 接收到消息:{0}, 客户端IP:{1}"; - log.info("接收到消息:" + msg + "客户端IP:" + ipAddress); + log.info("接收到消息:" + msg + ",客户端IP:" + ipAddress); String channelAns = ""; // 返回时间指令 //if (Integer.parseInt(timeAsycServerPort) == channel.localAddress().getPort()) { - ByteBuf recvmg = (ByteBuf) msg; + //ByteBuf recvmg = (ByteBuf) msg; ByteBuf buf = null; - String recvmgStr = recvmg.toString(); - if (AST_TIME_CMD.equals(recvmg)) { + //String recvmgStr = recvmg.toString(); + //if (AST_TIME_CMD.equals(recvmg)) { + if (AST_TIME_CMD.equals(msg)) { // 初始时间辅助输入; channelAns = dipperTimeAsyncTaskService.pushAstTime(); } @@ -112,7 +116,8 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter { // 发送SDBP-AST-POS获取辅助位置信息 // if (Integer.parseInt(posAsycServerPort) == channel.localAddress().getPort()) { - if (AST_POS_CMD.equals(recvmg)) { + //if (AST_POS_CMD.equals(recvmg)) { + if (AST_TIME_CMD.equals(msg)) { // channelAns = dipperAstPosAsyncTaskService.pushAstPos(ipAddress, // positionConfig.getCenterProvinceFilePath(), // positionConfig.getCenterProvince(), @@ -127,7 +132,8 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter { // 从缓存获取SDBP-AST-EPH星历数 //if (Integer.parseInt(starsAsycServerPort) == channel.localAddress().getPort()) { - if (AST_POS_CMD.equals(recvmg)) { + //if (AST_POS_CMD.equals(recvmg)) { + if (AST_POS_CMD.equals(msg)) { channelAns = dipperDataAsyncTaskService.getAstEPH(); } From 30454276e6c1b4ca641c762bd34c59135d98fe98 Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Mon, 18 Jan 2021 19:22:05 +0800 Subject: [PATCH 092/172] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=88=B0docker?= =?UTF-8?q?=E5=A4=96=E8=BF=90=E8=A1=8C=E7=8E=AF=E5=A2=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dipperposition/handler/NettyServerHandler.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java b/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java index 86868d7..f82c58b 100644 --- a/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java +++ b/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java @@ -6,6 +6,9 @@ import com.telpo.dipperposition.enums.DipperReturnValue; import com.telpo.dipperposition.service.IDipperAstPosAsyncTaskService; import com.telpo.dipperposition.service.IDipperAstTimeAsyncTaskService; import com.telpo.dipperposition.service.IDipperDataAsyncTaskService; +import com.telpo.dipperposition.service.impl.DipperAstPosAsyncTaskServiceImpl; +import com.telpo.dipperposition.service.impl.DipperAstTimeAsyncTaskServiceImpl; +import com.telpo.dipperposition.service.impl.DipperDataAsyncTaskServiceImpl; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import io.netty.channel.socket.SocketChannel; @@ -110,6 +113,9 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter { //if (AST_TIME_CMD.equals(recvmg)) { if (AST_TIME_CMD.equals(msg)) { // 初始时间辅助输入; + if (dipperTimeAsyncTaskService == null) { + dipperTimeAsyncTaskService = new DipperAstTimeAsyncTaskServiceImpl(); + } channelAns = dipperTimeAsyncTaskService.pushAstTime(); } @@ -123,6 +129,9 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter { // positionConfig.getCenterProvince(), // positionConfig.getIpPositionRequestPath(), // positionConfig.getIpPositionRequestKey()); + if (dipperAstPosAsyncTaskService == null) { + dipperAstPosAsyncTaskService = new DipperAstPosAsyncTaskServiceImpl(); + } channelAns = dipperAstPosAsyncTaskService.pushAstPos(ipAddress, "/csv/provinceLonAlt.csv", "湖北省", @@ -134,6 +143,9 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter { //if (Integer.parseInt(starsAsycServerPort) == channel.localAddress().getPort()) { //if (AST_POS_CMD.equals(recvmg)) { if (AST_POS_CMD.equals(msg)) { + if (dipperDataAsyncTaskService == null) { + dipperDataAsyncTaskService = new DipperDataAsyncTaskServiceImpl(); + } channelAns = dipperDataAsyncTaskService.getAstEPH(); } From fbb4fc4e86f10167c57b838b491539806947c0d5 Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Mon, 18 Jan 2021 19:27:28 +0800 Subject: [PATCH 093/172] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=88=B0docker?= =?UTF-8?q?=E5=A4=96=E8=BF=90=E8=A1=8C=E7=8E=AF=E5=A2=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/DipperAstPosAsyncTaskServiceImpl.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java b/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java index 4b100eb..9ba510e 100644 --- a/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java +++ b/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java @@ -95,6 +95,9 @@ public class DipperAstPosAsyncTaskServiceImpl implements IDipperAstPosAsyncTaskS // 关于IP与省份的关系保存到缓存中 // 使用时,先在缓存中获取匹配信息 // 用mongodb实现 + if(iPProvinceService == null) { + iPProvinceService = new IPProvinceServiceImpl(); + } IPProvinceEntity ipProvinceEntity = iPProvinceService.getIPProvince(ipAddress); if (ipProvinceEntity == null) { // 匹配不到,再请求高德IP定位服务。 @@ -125,6 +128,9 @@ public class DipperAstPosAsyncTaskServiceImpl implements IDipperAstPosAsyncTaskS public void createIPProvince(String ipAddress, String province) { log.debug("异步创建推送失败任务记录!"); try { + if(iPProvinceService == null) { + iPProvinceService = new IPProvinceServiceImpl(); + } IPProvinceEntity ipProvinceEntity = iPProvinceService.getIPProvince(ipAddress); if (ipProvinceEntity == null) { //DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); From 90c96317a59c26e810502661ddcae406aa49be57 Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Mon, 18 Jan 2021 19:30:56 +0800 Subject: [PATCH 094/172] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=88=B0docker?= =?UTF-8?q?=E5=A4=96=E8=BF=90=E8=A1=8C=E7=8E=AF=E5=A2=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/IPProvinceServiceImpl.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/main/java/com/telpo/dipperposition/service/impl/IPProvinceServiceImpl.java b/src/main/java/com/telpo/dipperposition/service/impl/IPProvinceServiceImpl.java index ca2de93..61282e7 100644 --- a/src/main/java/com/telpo/dipperposition/service/impl/IPProvinceServiceImpl.java +++ b/src/main/java/com/telpo/dipperposition/service/impl/IPProvinceServiceImpl.java @@ -26,6 +26,9 @@ public class IPProvinceServiceImpl implements IPProvinceService { @Override public boolean saveIPProvince(IPProvinceEntity entity) { + if (iPProvinceMapper == null) { + iPProvinceMapper = new IPProvinceMapper(); + } iPProvinceMapper.save(entity); return true; } @@ -33,12 +36,18 @@ public class IPProvinceServiceImpl implements IPProvinceService { @Override public boolean updateIPProvince( IPProvinceEntity query, IPProvinceEntity update) { + if (iPProvinceMapper == null) { + iPProvinceMapper = new IPProvinceMapper(); + } iPProvinceMapper.updateFirst(query, update); return true; } @Override public boolean romveById(String id) { + if (iPProvinceMapper == null) { + iPProvinceMapper = new IPProvinceMapper(); + } iPProvinceMapper.deleteById(id); return false; } @@ -48,6 +57,9 @@ public class IPProvinceServiceImpl implements IPProvinceService { try { IPProvinceEntity query = new IPProvinceEntity(); query.setIp(ipAddress); + if (iPProvinceMapper == null) { + iPProvinceMapper = new IPProvinceMapper(); + } List pushRecords = iPProvinceMapper.queryList(query); if (ObjectUtils.isNotEmpty(pushRecords)) { return pushRecords.get(0); From 7ac60505ae016c694bbd2ccc58e6958b31ede669 Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Mon, 18 Jan 2021 19:39:39 +0800 Subject: [PATCH 095/172] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=88=B0docker?= =?UTF-8?q?=E5=A4=96=E8=BF=90=E8=A1=8C=E7=8E=AF=E5=A2=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- setup_dev.sh | 37 ++++++++++++++------------- src/main/resources/bootstrap-dev.yaml | 1 + src/main/resources/bootstrap.yaml | 1 + 3 files changed, 21 insertions(+), 18 deletions(-) diff --git a/setup_dev.sh b/setup_dev.sh index dd13c77..b64f8da 100644 --- a/setup_dev.sh +++ b/setup_dev.sh @@ -4,28 +4,28 @@ mvn package -Dmaven.test.skip=true #image_version=$(date +%Y%m%d%H%M) image_version=$version -docker cp docker_jenkins:/var/jenkins_home/workspace/dipperpos_service/target/dipperposition.jar /usr/local/dipperposition/dipperposition.jar -#docker stop dipperposition_service || true -#docker rm dipperposition_service || true +#docker cp docker_jenkins:/var/jenkins_home/workspace/dipperpos_service/target/dipperposition.jar +# /usr/local/dipperposition/dipperposition.jar +docker stop dipperposition_service || true +docker rm dipperposition_service || true # 删除镜像 -#docker rmi -f $(docker images | grep telpo/dipperposition_service | awk '{print $3}') +docker rmi -f $(docker images | grep telpo/dipperposition_service | awk '{print $3}') -#docker build . -t telpo/dipperposition_service:$image_version +docker build . -t telpo/dipperposition_service:$image_version #TODO:推送镜像到私有仓库 -#echo '=================开始推送镜像=======================' -#docker tag telpo/dipperposition_service:$image_version 139.224.254.18:5000/dipperposition_service:$image_version -#docker push 139.224.254.18:5000/dipperposition_service:$image_version -#echo '=================推送镜像完成=======================' +echo '=================开始推送镜像=======================' +docker tag telpo/dipperposition_service:$image_version 139.224.254.18:5000/dipperposition_service:$image_version +docker push 139.224.254.18:5000/dipperposition_service:$image_version +echo '=================推送镜像完成=======================' #删除产生的None镜像 -#docker rmi -f $(docker images | grep none | awk '{print $3}') +docker rmi -f $(docker images | grep none | awk '{print $3}') # 查看镜像列表 -#docker images +docker images # 启动容器 -#docker run -v /home/data/dipperposition/log:/var/log/dipperposition -d -e active=dev --network host --restart=always -# -p 9011:9011 -p 9012:9012 -p 9013:9013 --name dipperposition_service 139.224.254.18:5000/dipperposition_service:$image_version +docker run -v /home/data/dipperposition/log:/var/log/dipperposition -d -e active=dev --network host --restart=always -p 9011:9011 -p 9012:9012 -p 9013:9013 --name dipperposition_service 139.224.254.18:5000/dipperposition_service:$image_version #echo "scp ${WORKSPACE} files......begin" #set passwd "telpo#1234" @@ -56,9 +56,10 @@ docker cp docker_jenkins:/var/jenkins_home/workspace/dipperpos_service/target/di #expect eof #echo "scp ${WORKSPACE} files......end" # 查看日志 -# docker logs dipperposition_service +#docker logs dipperposition_service -echo '=================启动NettyAPP=======================' -ps -ef |grep dipperposition |awk '{print $2}'|xargs kill -9 -java -jar -Xms256m -Xmx256m -Xss256k -XX:MetaspaceSize=256m -XX:MaxMetaspaceSize=512m /usr/local/dipperposition/dipperposition.jar --spring.profiles.active=dev -echo '=================完成NettyAPP启动=======================' +#echo '=================启动NettyAPP=======================' +#ps -ef |grep dipperposition |awk '{print $2}'|xargs kill -9 +#java -jar -Xms256m -Xmx256m -Xss256k -XX:MetaspaceSize=256m -XX:MaxMetaspaceSize=512m +# /usr/local/dipperposition/dipperposition.jar --spring.profiles.active=dev +#echo '=================完成NettyAPP启动=======================' diff --git a/src/main/resources/bootstrap-dev.yaml b/src/main/resources/bootstrap-dev.yaml index ea07582..8f21889 100644 --- a/src/main/resources/bootstrap-dev.yaml +++ b/src/main/resources/bootstrap-dev.yaml @@ -6,4 +6,5 @@ spring: cloud: nacos: config: + server-addr: 172.16.192.26:8848 file-extension: yaml \ No newline at end of file diff --git a/src/main/resources/bootstrap.yaml b/src/main/resources/bootstrap.yaml index 8f8ae14..b5569d8 100644 --- a/src/main/resources/bootstrap.yaml +++ b/src/main/resources/bootstrap.yaml @@ -10,6 +10,7 @@ spring: cloud: nacos: config: + server-addr: 172.16.192.26:8848 file-extension: yaml redis: database: 1 From 1332fa71562355403c66312426c559c224442768 Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Mon, 18 Jan 2021 19:55:04 +0800 Subject: [PATCH 096/172] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=88=B0docker?= =?UTF-8?q?=E5=A4=96=E8=BF=90=E8=A1=8C=E7=8E=AF=E5=A2=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../handler/NettyServerHandler.java | 2 +- .../mapper/IPProvinceMapper.java | 30 +++++++++---------- .../service/IPProvinceService.java | 4 +-- .../DipperAstPosAsyncTaskServiceImpl.java | 6 ++-- .../impl/DipperDataAsyncTaskServiceImpl.java | 6 ++++ .../service/impl/IPProvinceServiceImpl.java | 12 ++++---- 6 files changed, 33 insertions(+), 27 deletions(-) diff --git a/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java b/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java index f82c58b..1234f48 100644 --- a/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java +++ b/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java @@ -123,7 +123,7 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter { // if (Integer.parseInt(posAsycServerPort) == channel.localAddress().getPort()) { //if (AST_POS_CMD.equals(recvmg)) { - if (AST_TIME_CMD.equals(msg)) { + if (AST_POS_CMD.equals(msg)) { // channelAns = dipperAstPosAsyncTaskService.pushAstPos(ipAddress, // positionConfig.getCenterProvinceFilePath(), // positionConfig.getCenterProvince(), diff --git a/src/main/java/com/telpo/dipperposition/mapper/IPProvinceMapper.java b/src/main/java/com/telpo/dipperposition/mapper/IPProvinceMapper.java index b050e1d..a61925c 100644 --- a/src/main/java/com/telpo/dipperposition/mapper/IPProvinceMapper.java +++ b/src/main/java/com/telpo/dipperposition/mapper/IPProvinceMapper.java @@ -21,16 +21,19 @@ public class IPProvinceMapper extends BaseMongoDbDao { return IPProvinceEntity.class; } - @Override @MongoSwitch("common") - public void save(IPProvinceEntity entity, String collectionName) { - super.save(entity, collectionName); + public void saveIp(IPProvinceEntity entity) { + this.save(entity); + } + + @MongoSwitch("common") + public void saveIp(IPProvinceEntity entity, String collectionName) { + this.save(entity, collectionName); } - @Override @MongoSwitch("common") - public void updateFirst(IPProvinceEntity srcObj, IPProvinceEntity targetObj) { - super.updateFirst(srcObj, targetObj); + public void updateIpFirst(IPProvinceEntity srcObj, IPProvinceEntity targetObj) { + this.updateFirst(srcObj, targetObj); } @Override @@ -38,21 +41,18 @@ public class IPProvinceMapper extends BaseMongoDbDao { return super.getPage(object, start, size); } - @Override @MongoSwitch("common") - public List queryList(IPProvinceEntity object) { - return super.queryList(object); + public List queryIpList(IPProvinceEntity object) { + return this.queryList(object); } - @Override @MongoSwitch("common") - public List queryList(IPProvinceEntity object, String collectionName) { - return super.queryList(object, collectionName); + public List queryIpList(IPProvinceEntity object, String collectionName) { + return this.queryList(object, collectionName); } - @Override @MongoSwitch("common") - public void deleteById(String id) { - super.deleteById(id); + public void deleteIpById(String id) { + this.deleteById(id); } } diff --git a/src/main/java/com/telpo/dipperposition/service/IPProvinceService.java b/src/main/java/com/telpo/dipperposition/service/IPProvinceService.java index f8e3c66..de80294 100644 --- a/src/main/java/com/telpo/dipperposition/service/IPProvinceService.java +++ b/src/main/java/com/telpo/dipperposition/service/IPProvinceService.java @@ -17,7 +17,7 @@ public interface IPProvinceService { * @param entity * @return */ - boolean saveIPProvince(IPProvinceEntity entity); + boolean saveIpProvince(IPProvinceEntity entity); /** * 更新IP省份 @@ -41,5 +41,5 @@ public interface IPProvinceService { * @param ipAddress * 获取IP省份 */ - IPProvinceEntity getIPProvince(String ipAddress); + IPProvinceEntity getIpProvince(String ipAddress); } diff --git a/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java b/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java index 9ba510e..892988c 100644 --- a/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java +++ b/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java @@ -98,7 +98,7 @@ public class DipperAstPosAsyncTaskServiceImpl implements IDipperAstPosAsyncTaskS if(iPProvinceService == null) { iPProvinceService = new IPProvinceServiceImpl(); } - IPProvinceEntity ipProvinceEntity = iPProvinceService.getIPProvince(ipAddress); + IPProvinceEntity ipProvinceEntity = iPProvinceService.getIpProvince(ipAddress); if (ipProvinceEntity == null) { // 匹配不到,再请求高德IP定位服务。 JSONObject userObj = new JSONObject(); @@ -131,12 +131,12 @@ public class DipperAstPosAsyncTaskServiceImpl implements IDipperAstPosAsyncTaskS if(iPProvinceService == null) { iPProvinceService = new IPProvinceServiceImpl(); } - IPProvinceEntity ipProvinceEntity = iPProvinceService.getIPProvince(ipAddress); + IPProvinceEntity ipProvinceEntity = iPProvinceService.getIpProvince(ipAddress); if (ipProvinceEntity == null) { //DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); ipProvinceEntity.setIp(ipAddress); ipProvinceEntity.setProvince(province); - iPProvinceService.saveIPProvince(ipProvinceEntity); + iPProvinceService.saveIpProvince(ipProvinceEntity); // } else { // // ipProvinceEntity.setProvince(province); diff --git a/src/main/java/com/telpo/dipperposition/service/impl/DipperDataAsyncTaskServiceImpl.java b/src/main/java/com/telpo/dipperposition/service/impl/DipperDataAsyncTaskServiceImpl.java index aec944e..9515fd2 100644 --- a/src/main/java/com/telpo/dipperposition/service/impl/DipperDataAsyncTaskServiceImpl.java +++ b/src/main/java/com/telpo/dipperposition/service/impl/DipperDataAsyncTaskServiceImpl.java @@ -39,6 +39,9 @@ public class DipperDataAsyncTaskServiceImpl implements IDipperDataAsyncTaskServi log.error("获取星历数据错误,取不到星历数据。"); } else { // 保存到DB或者缓存 + if (redisUtil == null) { + redisUtil = new RedisUtil(); + } redisUtil.set(DIPPER_DATA_KEY,dipperData); } } @@ -63,6 +66,9 @@ public class DipperDataAsyncTaskServiceImpl implements IDipperDataAsyncTaskServi @Override @Async("asyncServiceExecutor") public String getAstEPH(){ + if (redisUtil == null) { + redisUtil = new RedisUtil(); + } return (String)redisUtil.get(DIPPER_DATA_KEY); } } diff --git a/src/main/java/com/telpo/dipperposition/service/impl/IPProvinceServiceImpl.java b/src/main/java/com/telpo/dipperposition/service/impl/IPProvinceServiceImpl.java index 61282e7..de38265 100644 --- a/src/main/java/com/telpo/dipperposition/service/impl/IPProvinceServiceImpl.java +++ b/src/main/java/com/telpo/dipperposition/service/impl/IPProvinceServiceImpl.java @@ -25,11 +25,11 @@ public class IPProvinceServiceImpl implements IPProvinceService { private IPProvinceMapper iPProvinceMapper; @Override - public boolean saveIPProvince(IPProvinceEntity entity) { + public boolean saveIpProvince(IPProvinceEntity entity) { if (iPProvinceMapper == null) { iPProvinceMapper = new IPProvinceMapper(); } - iPProvinceMapper.save(entity); + iPProvinceMapper.saveIp(entity); return true; } @@ -39,7 +39,7 @@ public class IPProvinceServiceImpl implements IPProvinceService { if (iPProvinceMapper == null) { iPProvinceMapper = new IPProvinceMapper(); } - iPProvinceMapper.updateFirst(query, update); + iPProvinceMapper.updateIpFirst(query, update); return true; } @@ -48,19 +48,19 @@ public class IPProvinceServiceImpl implements IPProvinceService { if (iPProvinceMapper == null) { iPProvinceMapper = new IPProvinceMapper(); } - iPProvinceMapper.deleteById(id); + iPProvinceMapper.deleteIpById(id); return false; } @Override - public IPProvinceEntity getIPProvince(String ipAddress) { + public IPProvinceEntity getIpProvince(String ipAddress) { try { IPProvinceEntity query = new IPProvinceEntity(); query.setIp(ipAddress); if (iPProvinceMapper == null) { iPProvinceMapper = new IPProvinceMapper(); } - List pushRecords = iPProvinceMapper.queryList(query); + List pushRecords = iPProvinceMapper.queryIpList(query); if (ObjectUtils.isNotEmpty(pushRecords)) { return pushRecords.get(0); } else { From 92873d0f37af4c0c4f0c5e573b90842c163f1201 Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Mon, 18 Jan 2021 20:10:18 +0800 Subject: [PATCH 097/172] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=88=B0docker?= =?UTF-8?q?=E5=A4=96=E8=BF=90=E8=A1=8C=E7=8E=AF=E5=A2=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/DipperAstPosAsyncTaskServiceImpl.java | 6 +++--- .../service/impl/DipperAstTimeAsyncTaskServiceImpl.java | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java b/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java index 892988c..5f18ff5 100644 --- a/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java +++ b/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java @@ -242,10 +242,10 @@ public class DipperAstPosAsyncTaskServiceImpl implements IDipperAstPosAsyncTaskS astTimeCmd += HexConvert.encodeHEX(lanLongValue); astTimeCmd += HexConvert.encodeHEX(altLongValue); - String hexIn = HexConvert.convertStringToHex(astTimeCmd) + HexConvert.makeChecksum(astTimeCmd); + //String hexIn = HexConvert.convertStringToHex(astTimeCmd) + HexConvert.makeChecksum(astTimeCmd); + + String hexIn = astTimeCmd + HexConvert.makeChecksum(astTimeCmd); - //String sendResult = client.sendCmd(hexIn, ackAckCheckRef); - //client.closeConnection(); //return sendResult; return hexIn; diff --git a/src/main/java/com/telpo/dipperposition/service/impl/DipperAstTimeAsyncTaskServiceImpl.java b/src/main/java/com/telpo/dipperposition/service/impl/DipperAstTimeAsyncTaskServiceImpl.java index 1ae8c2d..8ecb290 100644 --- a/src/main/java/com/telpo/dipperposition/service/impl/DipperAstTimeAsyncTaskServiceImpl.java +++ b/src/main/java/com/telpo/dipperposition/service/impl/DipperAstTimeAsyncTaskServiceImpl.java @@ -95,8 +95,8 @@ public class DipperAstTimeAsyncTaskServiceImpl implements IDipperAstTimeAsyncTas astTimeCmd += "0000000000"; astTimeCmd += "00286BEE"; - String hexIn = HexConvert.convertStringToHex(astTimeCmd) + HexConvert.makeChecksum(astTimeCmd); - + //String hexIn = HexConvert.convertStringToHex(astTimeCmd) + HexConvert.makeChecksum(astTimeCmd); + String hexIn = astTimeCmd + HexConvert.makeChecksum(astTimeCmd); //String ackAckCheckRef = "233E0101020004020A1D"; //String sendResult = client.sendCmd(hexIn, ackAckCheckRef); //client.closeConnection(); From 90032ae83a6d3abfb83807f3fde728e413761a59 Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Mon, 18 Jan 2021 20:35:20 +0800 Subject: [PATCH 098/172] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=88=B0docker?= =?UTF-8?q?=E5=A4=96=E8=BF=90=E8=A1=8C=E7=8E=AF=E5=A2=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/telpo/dipperposition/DipperPositionApplication.java | 2 +- .../com/telpo/dipperposition/handler/NettyServerHandler.java | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/telpo/dipperposition/DipperPositionApplication.java b/src/main/java/com/telpo/dipperposition/DipperPositionApplication.java index 38c509d..055577f 100644 --- a/src/main/java/com/telpo/dipperposition/DipperPositionApplication.java +++ b/src/main/java/com/telpo/dipperposition/DipperPositionApplication.java @@ -45,7 +45,7 @@ public class DipperPositionApplication { //启动服务端 ConfigurableEnvironment environment = applicationContext.getEnvironment(); DipperPositionServer nettyServer = new DipperPositionServer(environment); - nettyServer.start2(); + nettyServer.start(); } catch (Exception e) { log.error(e.getMessage()); } diff --git a/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java b/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java index 1234f48..0edfe40 100644 --- a/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java +++ b/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java @@ -64,6 +64,7 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter { //通知客户端链接建立成功 // 默认返回取得时间成功 String ackAckCheckRef = "233E0101020004020A1D"; + // if (Integer.parseInt(nettyServerConfig.getPosAsycServerPort()) == channel.localAddress().getPort()) { // ackAckCheckRef = "233E010102000401091C"; // } From e878a142a05792b08bce9fbf9767118d76585ed5 Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Mon, 18 Jan 2021 20:44:09 +0800 Subject: [PATCH 099/172] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=88=B0docker?= =?UTF-8?q?=E5=A4=96=E8=BF=90=E8=A1=8C=E7=8E=AF=E5=A2=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../telpo/dipperposition/handler/NettyServerHandler.java | 2 ++ .../dipperposition/server/DipperPositionServer.java | 9 +++++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java b/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java index 0edfe40..26f0b33 100644 --- a/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java +++ b/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java @@ -124,6 +124,8 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter { // if (Integer.parseInt(posAsycServerPort) == channel.localAddress().getPort()) { //if (AST_POS_CMD.equals(recvmg)) { + log.info("config info is : " + positionConfig.getCenterProvinceFilePath() + positionConfig.getCenterProvince() + positionConfig.getIpPositionRequestPath() + + positionConfig.getIpPositionRequestKey()); if (AST_POS_CMD.equals(msg)) { // channelAns = dipperAstPosAsyncTaskService.pushAstPos(ipAddress, // positionConfig.getCenterProvinceFilePath(), diff --git a/src/main/java/com/telpo/dipperposition/server/DipperPositionServer.java b/src/main/java/com/telpo/dipperposition/server/DipperPositionServer.java index 64855c4..d8e5ebc 100644 --- a/src/main/java/com/telpo/dipperposition/server/DipperPositionServer.java +++ b/src/main/java/com/telpo/dipperposition/server/DipperPositionServer.java @@ -158,12 +158,12 @@ public class DipperPositionServer { EventLoopGroup mainThreadGroup = new NioEventLoopGroup(1); //new 一个工作线程组 EventLoopGroup workThreadGroup = new NioEventLoopGroup(200); - //InetSocketAddress socketAddress = new InetSocketAddress(serverAddr,null); + InetSocketAddress socketAddress = new InetSocketAddress(serverAddr,9011); ServerBootstrap bootstrap = new ServerBootstrap() .group(mainThreadGroup, workThreadGroup) .channel(NioServerSocketChannel.class) .childHandler(new ServerChannelInitializer()) - //.localAddress(socketAddress) + .localAddress(socketAddress) //设置队列大小 .option(ChannelOption.SO_BACKLOG, 1024) // 两小时内没有数据的通信时,TCP会自动发送一个活动探测数据报文 @@ -181,6 +181,7 @@ public class DipperPositionServer { System.out.println("start failed"); } }); + channelFuture.channel().closeFuture().sync(); ChannelFuture channelFuture2 = bootstrap.bind(posAsycPort).sync(); log.info("位置服务器启动开始监听端口: {}", posAsycPort); @@ -191,6 +192,7 @@ public class DipperPositionServer { System.out.println("start failed"); } }); + channelFuture2.channel().closeFuture().sync(); ChannelFuture channelFuture3 = bootstrap.bind(starsAsycPort).sync(); @@ -202,8 +204,7 @@ public class DipperPositionServer { System.out.println("start failed"); } }); - - //channelFuture.channel().closeFuture().sync(); + channelFuture3.channel().closeFuture().sync(); } catch (InterruptedException e) { e.printStackTrace(); } finally { From 9ee68cd85ac6c5a63ffce687002bf856f21bf66a Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Mon, 18 Jan 2021 20:53:34 +0800 Subject: [PATCH 100/172] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=88=B0docker?= =?UTF-8?q?=E5=A4=96=E8=BF=90=E8=A1=8C=E7=8E=AF=E5=A2=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DipperPositionApplication.java | 13 +- .../handler/NettyServerHandler.java | 2 - .../server/DipperPositionServer.java | 127 ++++-------------- .../dipperposition/server/EphAsyncServer.java | 106 --------------- .../server/TimeAsyncServer.java | 75 ++++------- 5 files changed, 51 insertions(+), 272 deletions(-) delete mode 100644 src/main/java/com/telpo/dipperposition/server/EphAsyncServer.java diff --git a/src/main/java/com/telpo/dipperposition/DipperPositionApplication.java b/src/main/java/com/telpo/dipperposition/DipperPositionApplication.java index 055577f..d5fae42 100644 --- a/src/main/java/com/telpo/dipperposition/DipperPositionApplication.java +++ b/src/main/java/com/telpo/dipperposition/DipperPositionApplication.java @@ -1,28 +1,17 @@ package com.telpo.dipperposition; -import com.alibaba.nacos.api.NacosFactory; -import com.alibaba.nacos.api.config.ConfigService; -import com.alibaba.nacos.api.config.listener.Listener; -import com.alibaba.nacos.api.PropertyKeyConst; -import com.alibaba.nacos.api.exception.NacosException; -import com.telpo.dipperposition.co.PositionConfigInfo; import com.telpo.dipperposition.server.DipperPositionServer; -import com.telpo.dipperposition.server.EphAsyncServer; import com.telpo.dipperposition.server.TimeAsyncServer; import lombok.extern.slf4j.Slf4j; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.context.properties.ConfigurationPropertiesScan; -import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.cloud.client.discovery.EnableDiscoveryClient; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.core.env.ConfigurableEnvironment; import org.springframework.scheduling.annotation.EnableAsync; import org.springframework.scheduling.annotation.EnableScheduling; -import java.util.Properties; -import java.util.concurrent.Executor; - /** * @program: gateway * @description: 网关启动类 @@ -44,6 +33,8 @@ public class DipperPositionApplication { log.info("北斗定位服务启动!"); //启动服务端 ConfigurableEnvironment environment = applicationContext.getEnvironment(); + TimeAsyncServer timeAsyncServer = new TimeAsyncServer(environment); + timeAsyncServer.start(); DipperPositionServer nettyServer = new DipperPositionServer(environment); nettyServer.start(); } catch (Exception e) { diff --git a/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java b/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java index 26f0b33..0edfe40 100644 --- a/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java +++ b/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java @@ -124,8 +124,6 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter { // if (Integer.parseInt(posAsycServerPort) == channel.localAddress().getPort()) { //if (AST_POS_CMD.equals(recvmg)) { - log.info("config info is : " + positionConfig.getCenterProvinceFilePath() + positionConfig.getCenterProvince() + positionConfig.getIpPositionRequestPath() + - positionConfig.getIpPositionRequestKey()); if (AST_POS_CMD.equals(msg)) { // channelAns = dipperAstPosAsyncTaskService.pushAstPos(ipAddress, // positionConfig.getCenterProvinceFilePath(), diff --git a/src/main/java/com/telpo/dipperposition/server/DipperPositionServer.java b/src/main/java/com/telpo/dipperposition/server/DipperPositionServer.java index d8e5ebc..0055fc2 100644 --- a/src/main/java/com/telpo/dipperposition/server/DipperPositionServer.java +++ b/src/main/java/com/telpo/dipperposition/server/DipperPositionServer.java @@ -69,101 +69,22 @@ public class DipperPositionServer { // ex.printStackTrace(); // } } -// /* -// * 时间同步进程线程 -// */ -// public void startTimeAsnc() { -// -// //new 一个主线程组 -// EventLoopGroup mainThreadGroup = new NioEventLoopGroup(1); -// //new 一个工作线程组 -// EventLoopGroup workThreadGroup = new NioEventLoopGroup(200); -// InetSocketAddress socketAddress = new InetSocketAddress(serverAddr, -// timeAsycPort); -// ServerBootstrap bootstrap = new ServerBootstrap() -// .group(mainThreadGroup, workThreadGroup) -// .channel(NioServerSocketChannel.class) -// .childHandler(new ServerChannelInitializer()) -// .localAddress(socketAddress) -// //设置队列大小 -// .option(ChannelOption.SO_BACKLOG, 1024) -// // 两小时内没有数据的通信时,TCP会自动发送一个活动探测数据报文 -// .childOption(ChannelOption.SO_KEEPALIVE, true); -// -// -// //绑定端口,开始接收进来的连接 -// try { -// ChannelFuture future = bootstrap.bind(socketAddress).sync(); -// log.info("服务器启动开始监听端口: {}", socketAddress.getPort()); -// -// -// future.channel().closeFuture().sync(); -// } catch (InterruptedException e) { -// e.printStackTrace(); -// } finally { -// //关闭主线程组 -// mainThreadGroup.shutdownGracefully(); -// //关闭工作线程组 -// workThreadGroup.shutdownGracefully(); -// } -// } - -// /* -// * 时间同步进程线程 -// */ -// public void startPosAsnc() { -// -// //new 一个主线程组 -// EventLoopGroup mainThreadGroup = new NioEventLoopGroup(1); -// //new 一个工作线程组 -// EventLoopGroup workThreadGroup = new NioEventLoopGroup(200); -// InetSocketAddress socketAddress = new InetSocketAddress(serverAddr, -// posAsycPort); -// ServerBootstrap bootstrap = new ServerBootstrap() -// .group(mainThreadGroup, workThreadGroup) -// .channel(NioServerSocketChannel.class) -// .childHandler(new ServerChannelInitializer()) -// .localAddress(socketAddress) -// //设置队列大小 -// .option(ChannelOption.SO_BACKLOG, 1024) -// // 两小时内没有数据的通信时,TCP会自动发送一个活动探测数据报文 -// .childOption(ChannelOption.SO_KEEPALIVE, true); -// -// -// //绑定端口,开始接收进来的连接 -// try { -// ChannelFuture future = bootstrap.bind(socketAddress).sync(); -// log.info("服务器启动开始监听端口: {}", socketAddress.getPort()); -// -// -// future.channel().closeFuture().sync(); -// } catch (InterruptedException e) { -// e.printStackTrace(); -// } finally { -// //关闭主线程组 -// mainThreadGroup.shutdownGracefully(); -// //关闭工作线程组 -// workThreadGroup.shutdownGracefully(); -// } -// } - /* * 星历同步进程线程 */ - //public void startStarsAsnc() { public void start() { //new 一个主线程组 EventLoopGroup mainThreadGroup = new NioEventLoopGroup(1); //new 一个工作线程组 EventLoopGroup workThreadGroup = new NioEventLoopGroup(200); - InetSocketAddress socketAddress = new InetSocketAddress(serverAddr,9011); + //InetSocketAddress socketAddress = new InetSocketAddress(serverAddr,9011); ServerBootstrap bootstrap = new ServerBootstrap() .group(mainThreadGroup, workThreadGroup) .channel(NioServerSocketChannel.class) .childHandler(new ServerChannelInitializer()) - .localAddress(socketAddress) + // .localAddress(socketAddress) //设置队列大小 .option(ChannelOption.SO_BACKLOG, 1024) // 两小时内没有数据的通信时,TCP会自动发送一个活动探测数据报文 @@ -172,28 +93,28 @@ public class DipperPositionServer { //绑定端口,开始接收进来的连接 try { - ChannelFuture channelFuture = bootstrap.bind(timeAsycPort).sync(); - log.info("时间辅助服务器启动开始监听端口: {}", timeAsycPort); - channelFuture.addListener(future -> { - if (future.isSuccess()){ - System.out.println("start success"); - }else{ - System.out.println("start failed"); - } - }); - channelFuture.channel().closeFuture().sync(); - - ChannelFuture channelFuture2 = bootstrap.bind(posAsycPort).sync(); - log.info("位置服务器启动开始监听端口: {}", posAsycPort); - channelFuture2.addListener(future -> { - if (future.isSuccess()){ - System.out.println("start success"); - }else{ - System.out.println("start failed"); - } - }); - channelFuture2.channel().closeFuture().sync(); - +// ChannelFuture channelFuture = bootstrap.bind(timeAsycPort).sync(); +// log.info("时间辅助服务器启动开始监听端口: {}", timeAsycPort); +// channelFuture.addListener(future -> { +// if (future.isSuccess()){ +// System.out.println("start success"); +// }else{ +// System.out.println("start failed"); +// } +// }); +// channelFuture.channel().closeFuture().sync(); +// +// ChannelFuture channelFuture2 = bootstrap.bind(posAsycPort).sync(); +// log.info("位置服务器启动开始监听端口: {}", posAsycPort); +// channelFuture2.addListener(future -> { +// if (future.isSuccess()){ +// System.out.println("start success"); +// }else{ +// System.out.println("start failed"); +// } +// }); +// channelFuture2.channel().closeFuture().sync(); +// ChannelFuture channelFuture3 = bootstrap.bind(starsAsycPort).sync(); log.info("星历服务器启动开始监听端口: {}", starsAsycPort); diff --git a/src/main/java/com/telpo/dipperposition/server/EphAsyncServer.java b/src/main/java/com/telpo/dipperposition/server/EphAsyncServer.java deleted file mode 100644 index 28eca89..0000000 --- a/src/main/java/com/telpo/dipperposition/server/EphAsyncServer.java +++ /dev/null @@ -1,106 +0,0 @@ -package com.telpo.dipperposition.server; - -import com.alibaba.nacos.api.NacosFactory; -import com.alibaba.nacos.api.PropertyKeyConst; -import com.alibaba.nacos.api.config.ConfigService; -import com.alibaba.nacos.api.exception.NacosException; -import com.telpo.dipperposition.handler.ServerChannelInitializer; -import io.netty.bootstrap.ServerBootstrap; -import io.netty.channel.ChannelFuture; -import io.netty.channel.ChannelOption; -import io.netty.channel.EventLoopGroup; -import io.netty.channel.nio.NioEventLoopGroup; -import io.netty.channel.socket.nio.NioServerSocketChannel; -import lombok.extern.slf4j.Slf4j; -import org.yaml.snakeyaml.Yaml; - -import java.io.ByteArrayInputStream; -import java.net.Inet4Address; -import java.net.InetAddress; -import java.net.InetSocketAddress; -import java.util.Map; -import java.util.Properties; - - -/** - * @program: DipperPositionServer - * @description: 北斗定位 - * @author: king - * @create: 2021-01-13 14:01 - */ -@Slf4j -public class EphAsyncServer { - - // @Autowired PositionConfigInfo positionConfigInfo; - private String serverAddr; - private Integer starsAsycPort; - - public EphAsyncServer() throws NacosException { - //String serverAddr = positionConfigInfo.getServerAddr(); - try { - try { - InetAddress ip4 = Inet4Address.getLocalHost(); - serverAddr = ip4.getHostAddress(); - } catch (Exception ex) { - serverAddr = "172.16.192.26"; - ex.printStackTrace(); - } - String dataId = "dipperposition-service"; - String group = "DEFAULT_GROUP"; - Properties properties = new Properties(); - properties.put(PropertyKeyConst.SERVER_ADDR, serverAddr); - ConfigService configService = NacosFactory.createConfigService(properties); - String content = configService.getConfig(dataId, group, 5000); - - ByteArrayInputStream tInputStringStream = new ByteArrayInputStream(content.getBytes()); - Yaml yaml = new Yaml(); - Map m1 = yaml.load(tInputStringStream); - Map m2 = (Map) m1.get("position-server"); - this.serverAddr = (String)m2.get("serverAddr"); - this.starsAsycPort = (Integer)m2.get("starsAsycPort"); - //log.info("Map server is:" + m2.get("serverAddr")); - } catch (Exception ex) { - ex.printStackTrace(); - } - //log.info("Config serverAddr is " + serverAddr); - } - - /* - * 星历同步进程线程 - */ - public void startStarsAsnc() { - - //new 一个主线程组 - EventLoopGroup mainThreadGroup = new NioEventLoopGroup(1); - //new 一个工作线程组 - EventLoopGroup workThreadGroup = new NioEventLoopGroup(200); - InetSocketAddress socketAddress = new InetSocketAddress(serverAddr, - starsAsycPort); - ServerBootstrap bootstrap = new ServerBootstrap() - .group(mainThreadGroup, workThreadGroup) - .channel(NioServerSocketChannel.class) - .childHandler(new ServerChannelInitializer()) - .localAddress(socketAddress) - //设置队列大小 - .option(ChannelOption.SO_BACKLOG, 1024) - // 两小时内没有数据的通信时,TCP会自动发送一个活动探测数据报文 - .childOption(ChannelOption.SO_KEEPALIVE, true); - - - //绑定端口,开始接收进来的连接 - try { - ChannelFuture future = bootstrap.bind(socketAddress).sync(); - log.info("服务器启动开始监听端口: {}", socketAddress.getPort()); - - - future.channel().closeFuture().sync(); - } catch (InterruptedException e) { - e.printStackTrace(); - } finally { - //关闭主线程组 - mainThreadGroup.shutdownGracefully(); - //关闭工作线程组 - workThreadGroup.shutdownGracefully(); - } - } -} diff --git a/src/main/java/com/telpo/dipperposition/server/TimeAsyncServer.java b/src/main/java/com/telpo/dipperposition/server/TimeAsyncServer.java index 110e470..c06344b 100644 --- a/src/main/java/com/telpo/dipperposition/server/TimeAsyncServer.java +++ b/src/main/java/com/telpo/dipperposition/server/TimeAsyncServer.java @@ -1,8 +1,5 @@ package com.telpo.dipperposition.server; -import com.alibaba.nacos.api.NacosFactory; -import com.alibaba.nacos.api.PropertyKeyConst; -import com.alibaba.nacos.api.config.ConfigService; import com.alibaba.nacos.api.exception.NacosException; import com.telpo.dipperposition.handler.ServerChannelInitializer; import io.netty.bootstrap.ServerBootstrap; @@ -12,18 +9,12 @@ import io.netty.channel.EventLoopGroup; import io.netty.channel.nio.NioEventLoopGroup; import io.netty.channel.socket.nio.NioServerSocketChannel; import lombok.extern.slf4j.Slf4j; -import org.yaml.snakeyaml.Yaml; +import org.springframework.core.env.ConfigurableEnvironment; -import java.io.ByteArrayInputStream; -import java.net.Inet4Address; -import java.net.InetAddress; import java.net.InetSocketAddress; -import java.util.Map; -import java.util.Properties; - /** - * @program: DipperPositionServer + * @program: TimeAsyncServer * @description: 北斗定位 * @author: king * @create: 2021-01-13 14:01 @@ -33,53 +24,32 @@ public class TimeAsyncServer { // @Autowired PositionConfigInfo positionConfigInfo; private String serverAddr; + private Integer serverPort; private Integer timeAsycPort; + private Integer posAsycPort; + private Integer starsAsycPort; - public TimeAsyncServer() throws NacosException { - //String serverAddr = positionConfigInfo.getServerAddr(); - try { - try { - InetAddress ip4 = Inet4Address.getLocalHost(); - serverAddr = ip4.getHostAddress(); - } catch (Exception ex) { - serverAddr = "172.16.192.26"; - ex.printStackTrace(); - } - String dataId = "dipperposition-service"; - String group = "DEFAULT_GROUP"; - Properties properties = new Properties(); - properties.put(PropertyKeyConst.SERVER_ADDR, serverAddr); - ConfigService configService = NacosFactory.createConfigService(properties); - String content = configService.getConfig(dataId, group, 5000); + public TimeAsyncServer(ConfigurableEnvironment environment) throws NacosException { - ByteArrayInputStream tInputStringStream = new ByteArrayInputStream(content.getBytes()); - Yaml yaml = new Yaml(); - Map m1 = yaml.load(tInputStringStream); - Map m2 = (Map) m1.get("position-server"); - this.serverAddr = (String)m2.get("serverAddr"); - this.timeAsycPort = (Integer)m2.get("timeAsycPort"); - //log.info("Map server is:" + m2.get("serverAddr")); - } catch (Exception ex) { - ex.printStackTrace(); - } - //log.info("Config serverAddr is " + serverAddr); + this.serverAddr = environment.getProperty("position-server.serverAddr"); + this.serverPort = Integer.parseInt(environment.getProperty("server.port")); + this.timeAsycPort = Integer.parseInt(environment.getProperty("position-server.timeAsycPort")); + this.posAsycPort = Integer.parseInt(environment.getProperty("position-server.posAsycPort")); + this.starsAsycPort = Integer.parseInt(environment.getProperty("position-server.starsAsycPort")); } - /* - * 时间同步进程线程 - */ - public void startTimeAsnc() { + + public void start() { //new 一个主线程组 EventLoopGroup mainThreadGroup = new NioEventLoopGroup(1); //new 一个工作线程组 EventLoopGroup workThreadGroup = new NioEventLoopGroup(200); - InetSocketAddress socketAddress = new InetSocketAddress(serverAddr, - timeAsycPort); + //InetSocketAddress socketAddress = new InetSocketAddress(serverAddr,null); ServerBootstrap bootstrap = new ServerBootstrap() .group(mainThreadGroup, workThreadGroup) .channel(NioServerSocketChannel.class) .childHandler(new ServerChannelInitializer()) - .localAddress(socketAddress) + //.localAddress(socketAddress) //设置队列大小 .option(ChannelOption.SO_BACKLOG, 1024) // 两小时内没有数据的通信时,TCP会自动发送一个活动探测数据报文 @@ -88,11 +58,17 @@ public class TimeAsyncServer { //绑定端口,开始接收进来的连接 try { - ChannelFuture future = bootstrap.bind(socketAddress).sync(); - log.info("服务器启动开始监听端口: {}", socketAddress.getPort()); - + ChannelFuture channelFuture = bootstrap.bind(timeAsycPort).sync(); + log.info("时间辅助服务器启动开始监听端口: {}", timeAsycPort); + channelFuture.addListener(future -> { + if (future.isSuccess()){ + System.out.println("start success"); + }else{ + System.out.println("start failed"); + } + }); - future.channel().closeFuture().sync(); + channelFuture.channel().closeFuture().sync(); } catch (InterruptedException e) { e.printStackTrace(); } finally { @@ -102,5 +78,4 @@ public class TimeAsyncServer { workThreadGroup.shutdownGracefully(); } } - } From 196e1aa05afdbfa78abc92e2adf24934a361e5c0 Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Mon, 18 Jan 2021 21:21:21 +0800 Subject: [PATCH 101/172] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=88=B0docker?= =?UTF-8?q?=E5=A4=96=E8=BF=90=E8=A1=8C=E7=8E=AF=E5=A2=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dipperposition/common/OkHttpUtil.java | 16 ++++++++++++--- .../dipperposition/common/RedisUtil.java | 10 ++++++++++ .../config/NettyServerConfig.java | 12 +++++++++++ .../dipperposition/config/PositionConfig.java | 12 +++++++++++ .../mapper/IPProvinceMapper.java | 13 ++++++++++++ .../DipperAstPosAsyncTaskServiceImpl.java | 20 ++++++++++++++++++- .../DipperAstTimeAsyncTaskServiceImpl.java | 13 ++++++++++++ .../impl/DipperDataAsyncTaskServiceImpl.java | 12 +++++++++++ .../service/impl/IPProvinceServiceImpl.java | 10 ++++++++++ 9 files changed, 114 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/telpo/dipperposition/common/OkHttpUtil.java b/src/main/java/com/telpo/dipperposition/common/OkHttpUtil.java index 44b01cc..9063e5c 100644 --- a/src/main/java/com/telpo/dipperposition/common/OkHttpUtil.java +++ b/src/main/java/com/telpo/dipperposition/common/OkHttpUtil.java @@ -25,12 +25,22 @@ public class OkHttpUtil { @Autowired private OkHttpClient okHttpClient; + private static OkHttpUtil okHttpUtil; /** - * 根据map获取get请求参数 + * spring会自动从ioc容器当中根据OkHttpUtil类型找到okHttpUtil,当做参数传进来 * - * @param queries - * @return */ + @Autowired + public void setOkHttpUtil(OkHttpUtil okHttpUtil) { + this.okHttpUtil = okHttpUtil; + } + + /** + * 根据map获取get请求参数 + * + * @param queries + * @return + */ public StringBuffer getQueryString(String url, Map queries) { StringBuffer sb = new StringBuffer(url); if (queries != null && queries.keySet().size() > 0) { diff --git a/src/main/java/com/telpo/dipperposition/common/RedisUtil.java b/src/main/java/com/telpo/dipperposition/common/RedisUtil.java index 97933f0..8ef86a5 100644 --- a/src/main/java/com/telpo/dipperposition/common/RedisUtil.java +++ b/src/main/java/com/telpo/dipperposition/common/RedisUtil.java @@ -1,6 +1,7 @@ package com.telpo.dipperposition.common; import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Component; import org.springframework.util.CollectionUtils; @@ -23,6 +24,15 @@ public class RedisUtil { @Resource private RedisTemplate redisTemplate; + private static RedisUtil redisUtil; + /** + * spring会自动从ioc容器当中根据RedisUtil类型找到redisUtil,当做参数传进来 + * + */ + @Autowired + public void setRedisUtil(RedisUtil redisUtil) { + this.redisUtil = redisUtil; + } // =============================common============================ /** * 指定缓存失效时间 diff --git a/src/main/java/com/telpo/dipperposition/config/NettyServerConfig.java b/src/main/java/com/telpo/dipperposition/config/NettyServerConfig.java index 58e328e..54fcfbb 100644 --- a/src/main/java/com/telpo/dipperposition/config/NettyServerConfig.java +++ b/src/main/java/com/telpo/dipperposition/config/NettyServerConfig.java @@ -2,8 +2,10 @@ package com.telpo.dipperposition.config; import com.alibaba.nacos.api.config.annotation.NacosValue; import com.alibaba.nacos.spring.context.annotation.config.NacosPropertySource; +import com.telpo.dipperposition.common.OkHttpUtil; import lombok.Getter; import lombok.Setter; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Configuration; /** @@ -30,4 +32,14 @@ public class NettyServerConfig { @NacosValue(value = "${position-server.starsAsycPort}") private String starsAsycServerPort; + private static NettyServerConfig nettyServerConfig; + /** + * spring会自动从ioc容器当中根据NettyServerConfig类型找到nettyServerConfig, + * 当做参数传进来 + * + */ + @Autowired + public void setNettyServerConfig(NettyServerConfig nettyServerConfig) { + this.nettyServerConfig = nettyServerConfig; + } } diff --git a/src/main/java/com/telpo/dipperposition/config/PositionConfig.java b/src/main/java/com/telpo/dipperposition/config/PositionConfig.java index a55f01b..97d2d3a 100644 --- a/src/main/java/com/telpo/dipperposition/config/PositionConfig.java +++ b/src/main/java/com/telpo/dipperposition/config/PositionConfig.java @@ -4,6 +4,7 @@ import com.alibaba.nacos.api.config.annotation.NacosValue; import com.alibaba.nacos.spring.context.annotation.config.NacosPropertySource; import lombok.Getter; import lombok.Setter; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Configuration; /** @@ -35,4 +36,15 @@ public class PositionConfig { int posAstPort; @NacosValue("${pos.astTimeout}") int astTimeout; + + + private static PositionConfig positionConfig; + /** + * spring会自动从ioc容器当中根据PositionConfig类型找到positionConfig,当做参数传进来 + * + */ + @Autowired + public void setPositionConfig(PositionConfig positionConfig) { + this.positionConfig = positionConfig; + } } diff --git a/src/main/java/com/telpo/dipperposition/mapper/IPProvinceMapper.java b/src/main/java/com/telpo/dipperposition/mapper/IPProvinceMapper.java index a61925c..4d5055d 100644 --- a/src/main/java/com/telpo/dipperposition/mapper/IPProvinceMapper.java +++ b/src/main/java/com/telpo/dipperposition/mapper/IPProvinceMapper.java @@ -1,8 +1,10 @@ package com.telpo.dipperposition.mapper; import com.telpo.dipperposition.annotation.MongoSwitch; +import com.telpo.dipperposition.config.NettyServerConfig; import com.telpo.dipperposition.entity.mongo.IPProvinceEntity; import db.BaseMongoDbDao; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Repository; import java.util.List; @@ -16,6 +18,17 @@ import java.util.List; @Repository public class IPProvinceMapper extends BaseMongoDbDao { + private static IPProvinceMapper iPProvinceMapper; + /** + * spring会自动从ioc容器当中根据IPProvinceMapper类型找到iPProvinceMapper, + * 当做参数传进来 + * + */ + @Autowired + public void setIPProvinceMapper(IPProvinceMapper iPProvinceMapper) { + this.iPProvinceMapper = iPProvinceMapper; + } + @Override protected Class getEntityClass() { return IPProvinceEntity.class; diff --git a/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java b/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java index 5f18ff5..86c5a7d 100644 --- a/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java +++ b/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java @@ -42,6 +42,16 @@ public class DipperAstPosAsyncTaskServiceImpl implements IDipperAstPosAsyncTaskS @Autowired private IPProvinceService iPProvinceService; + private static IDipperAstPosAsyncTaskService dipperAstPosAsyncTaskService; + /** + * spring会自动从ioc容器当中根据IDipperAstPosAsyncTaskService类型找到dipperAstPosAsyncTaskService,当做参数传进来 + * + */ + @Autowired + public void setDipperAstPosAsyncTaskService(IDipperAstPosAsyncTaskService dipperAstPosAsyncTaskService) { + this.dipperAstPosAsyncTaskService = dipperAstPosAsyncTaskService; + } + private String centerProvince; private String centerProvinceFilePath; private String ipPositionRequestPath; @@ -84,6 +94,9 @@ public class DipperAstPosAsyncTaskServiceImpl implements IDipperAstPosAsyncTaskS } else { centerProvinceName = centerAddressSetArray[3]; centerProvinceLonAndAlt = centerAddressSetArray[1]+","+centerAddressSetArray[2]; + if (redisUtil == null) { + redisUtil = new RedisUtil(); + } redisUtil.set(centerProvinceName, centerProvinceLonAndAlt, 0); } } @@ -104,7 +117,9 @@ public class DipperAstPosAsyncTaskServiceImpl implements IDipperAstPosAsyncTaskS JSONObject userObj = new JSONObject(); userObj.put("ip", ipAddress); userObj.put("key", ipPositionRequestKey); - + if (okHttpUtil == null) { + okHttpUtil = new OkHttpUtil(); + } JSONObject json = okHttpUtil.postRequestWithJson(ipPositionRequestPath, null, userObj); if (ObjectUtils.isNotEmpty(json)) { String province = (String) json.get("province"); @@ -174,6 +189,9 @@ public class DipperAstPosAsyncTaskServiceImpl implements IDipperAstPosAsyncTaskS } String lonAndAlt; + if (redisUtil == null) { + redisUtil = new RedisUtil(); + } if (redisUtil.hasKey(centerAddress)) { // 获取省会城市定位信息 lonAndAlt= (String) redisUtil.get(centerAddress); diff --git a/src/main/java/com/telpo/dipperposition/service/impl/DipperAstTimeAsyncTaskServiceImpl.java b/src/main/java/com/telpo/dipperposition/service/impl/DipperAstTimeAsyncTaskServiceImpl.java index 8ecb290..6bb8f66 100644 --- a/src/main/java/com/telpo/dipperposition/service/impl/DipperAstTimeAsyncTaskServiceImpl.java +++ b/src/main/java/com/telpo/dipperposition/service/impl/DipperAstTimeAsyncTaskServiceImpl.java @@ -2,8 +2,10 @@ package com.telpo.dipperposition.service.impl; import com.telpo.dipperposition.common.HexConvert; import com.telpo.dipperposition.common.SocketClient; +import com.telpo.dipperposition.service.IDipperAstPosAsyncTaskService; import com.telpo.dipperposition.service.IDipperAstTimeAsyncTaskService; import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Service; @@ -20,6 +22,17 @@ import java.time.LocalDateTime; @Slf4j public class DipperAstTimeAsyncTaskServiceImpl implements IDipperAstTimeAsyncTaskService { + + private static IDipperAstTimeAsyncTaskService dipperAstTimeAsyncTaskService; + /** + * spring会自动从ioc容器当中根据IDipperAstPosAsyncTaskService类型找到dipperAstTimeAsyncTaskService,当做参数传进来 + * + */ + @Autowired + public void setDipperAstTimeAsyncTaskService(IDipperAstTimeAsyncTaskService dipperAstTimeAsyncTaskService) { + this.dipperAstTimeAsyncTaskService = dipperAstTimeAsyncTaskService; + } + @Override @Async("asyncServiceExecutor") public String pushAstTime() { diff --git a/src/main/java/com/telpo/dipperposition/service/impl/DipperDataAsyncTaskServiceImpl.java b/src/main/java/com/telpo/dipperposition/service/impl/DipperDataAsyncTaskServiceImpl.java index 9515fd2..3f31de5 100644 --- a/src/main/java/com/telpo/dipperposition/service/impl/DipperDataAsyncTaskServiceImpl.java +++ b/src/main/java/com/telpo/dipperposition/service/impl/DipperDataAsyncTaskServiceImpl.java @@ -4,6 +4,7 @@ import com.telpo.dipperposition.common.HexConvert; import com.telpo.dipperposition.common.RedisUtil; import com.telpo.dipperposition.common.SocketClient; import com.telpo.dipperposition.config.SchedulingExecutorConfig; +import com.telpo.dipperposition.service.IDipperAstPosAsyncTaskService; import com.telpo.dipperposition.service.IDipperDataAsyncTaskService; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; @@ -29,6 +30,17 @@ public class DipperDataAsyncTaskServiceImpl implements IDipperDataAsyncTaskServi @Autowired private SchedulingExecutorConfig schedulingExecutorConfig; + + private static IDipperDataAsyncTaskService dipperDataAsyncTaskService; + /** + * spring会自动从ioc容器当中根据IDipperDataAsyncTaskService类型找到dipperDataAsyncTaskService,当做参数传进来 + * + */ + @Autowired + public void setDipperDataAsyncTaskService(IDipperDataAsyncTaskService dipperDataAsyncTaskService) { + this.dipperDataAsyncTaskService = dipperDataAsyncTaskService; + } + @Override public void pullAstEPH() { // (1) 发送bds获取星历数据 diff --git a/src/main/java/com/telpo/dipperposition/service/impl/IPProvinceServiceImpl.java b/src/main/java/com/telpo/dipperposition/service/impl/IPProvinceServiceImpl.java index de38265..e7493c1 100644 --- a/src/main/java/com/telpo/dipperposition/service/impl/IPProvinceServiceImpl.java +++ b/src/main/java/com/telpo/dipperposition/service/impl/IPProvinceServiceImpl.java @@ -2,6 +2,7 @@ package com.telpo.dipperposition.service.impl; import com.telpo.dipperposition.entity.mongo.IPProvinceEntity; import com.telpo.dipperposition.mapper.IPProvinceMapper; +import com.telpo.dipperposition.service.IDipperDataAsyncTaskService; import com.telpo.dipperposition.service.IPProvinceService; import com.telpo.dipperposition.vo.IPProvinceVo; import lombok.extern.slf4j.Slf4j; @@ -24,6 +25,15 @@ public class IPProvinceServiceImpl implements IPProvinceService { @Autowired private IPProvinceMapper iPProvinceMapper; + private static IPProvinceService ipProvinceService; + /** + * spring会自动从ioc容器当中根据IPProvinceService类型找到ipProvinceService,当做参数传进来 + * + */ + @Autowired + public void setIPProvinceService(IPProvinceService ipProvinceService) { + this.ipProvinceService = ipProvinceService; + } @Override public boolean saveIpProvince(IPProvinceEntity entity) { if (iPProvinceMapper == null) { From 805d0f0e98b93ca27080e8ead045f25caa834d62 Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Mon, 18 Jan 2021 21:22:33 +0800 Subject: [PATCH 102/172] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=88=B0docker?= =?UTF-8?q?=E5=A4=96=E8=BF=90=E8=A1=8C=E7=8E=AF=E5=A2=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/telpo/dipperposition/DipperPositionApplication.java | 4 ++-- .../com/telpo/dipperposition/mapper/IPProvinceMapper.java | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/telpo/dipperposition/DipperPositionApplication.java b/src/main/java/com/telpo/dipperposition/DipperPositionApplication.java index d5fae42..8d61985 100644 --- a/src/main/java/com/telpo/dipperposition/DipperPositionApplication.java +++ b/src/main/java/com/telpo/dipperposition/DipperPositionApplication.java @@ -33,8 +33,8 @@ public class DipperPositionApplication { log.info("北斗定位服务启动!"); //启动服务端 ConfigurableEnvironment environment = applicationContext.getEnvironment(); - TimeAsyncServer timeAsyncServer = new TimeAsyncServer(environment); - timeAsyncServer.start(); +// TimeAsyncServer timeAsyncServer = new TimeAsyncServer(environment); +// timeAsyncServer.start(); DipperPositionServer nettyServer = new DipperPositionServer(environment); nettyServer.start(); } catch (Exception e) { diff --git a/src/main/java/com/telpo/dipperposition/mapper/IPProvinceMapper.java b/src/main/java/com/telpo/dipperposition/mapper/IPProvinceMapper.java index 4d5055d..17b1622 100644 --- a/src/main/java/com/telpo/dipperposition/mapper/IPProvinceMapper.java +++ b/src/main/java/com/telpo/dipperposition/mapper/IPProvinceMapper.java @@ -1,7 +1,6 @@ package com.telpo.dipperposition.mapper; import com.telpo.dipperposition.annotation.MongoSwitch; -import com.telpo.dipperposition.config.NettyServerConfig; import com.telpo.dipperposition.entity.mongo.IPProvinceEntity; import db.BaseMongoDbDao; import org.springframework.beans.factory.annotation.Autowired; From b364abcc170a0f107e2da8f94071ad1f681c6a4b Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Mon, 18 Jan 2021 21:25:12 +0800 Subject: [PATCH 103/172] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=88=B0docker?= =?UTF-8?q?=E5=A4=96=E8=BF=90=E8=A1=8C=E7=8E=AF=E5=A2=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../telpo/dipperposition/handler/NettyServerHandler.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java b/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java index 0edfe40..66173fa 100644 --- a/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java +++ b/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java @@ -124,6 +124,12 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter { // if (Integer.parseInt(posAsycServerPort) == channel.localAddress().getPort()) { //if (AST_POS_CMD.equals(recvmg)) { + if (positionConfig != null) { + log.info("config info is : " + positionConfig.getCenterProvinceFilePath() + positionConfig.getCenterProvince() + positionConfig.getIpPositionRequestPath() + + positionConfig.getIpPositionRequestKey()); + } else { + log.info("positionConfig info is null!!!!!!!!!!!!!! "); + } if (AST_POS_CMD.equals(msg)) { // channelAns = dipperAstPosAsyncTaskService.pushAstPos(ipAddress, // positionConfig.getCenterProvinceFilePath(), From 1228eb73335cc0a63d7490916e62b768ed4acca5 Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Mon, 18 Jan 2021 21:30:59 +0800 Subject: [PATCH 104/172] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=88=B0docker?= =?UTF-8?q?=E5=A4=96=E8=BF=90=E8=A1=8C=E7=8E=AF=E5=A2=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...vinceMapper.java => IpProvinceMapper.java} | 8 ++--- .../DipperAstPosAsyncTaskServiceImpl.java | 11 ++----- ...ceImpl.java => IpProvinceServiceImpl.java} | 31 ++++++------------- 3 files changed, 16 insertions(+), 34 deletions(-) rename src/main/java/com/telpo/dipperposition/mapper/{IPProvinceMapper.java => IpProvinceMapper.java} (88%) rename src/main/java/com/telpo/dipperposition/service/impl/{IPProvinceServiceImpl.java => IpProvinceServiceImpl.java} (65%) diff --git a/src/main/java/com/telpo/dipperposition/mapper/IPProvinceMapper.java b/src/main/java/com/telpo/dipperposition/mapper/IpProvinceMapper.java similarity index 88% rename from src/main/java/com/telpo/dipperposition/mapper/IPProvinceMapper.java rename to src/main/java/com/telpo/dipperposition/mapper/IpProvinceMapper.java index 17b1622..bc428d1 100644 --- a/src/main/java/com/telpo/dipperposition/mapper/IPProvinceMapper.java +++ b/src/main/java/com/telpo/dipperposition/mapper/IpProvinceMapper.java @@ -15,17 +15,17 @@ import java.util.List; * @create: 2020-07-20 11:12 */ @Repository -public class IPProvinceMapper extends BaseMongoDbDao { +public class IpProvinceMapper extends BaseMongoDbDao { - private static IPProvinceMapper iPProvinceMapper; + private static IpProvinceMapper ipProvinceMapper; /** * spring会自动从ioc容器当中根据IPProvinceMapper类型找到iPProvinceMapper, * 当做参数传进来 * */ @Autowired - public void setIPProvinceMapper(IPProvinceMapper iPProvinceMapper) { - this.iPProvinceMapper = iPProvinceMapper; + public void setIPProvinceMapper(IpProvinceMapper ipProvinceMapper) { + this.ipProvinceMapper = ipProvinceMapper; } @Override diff --git a/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java b/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java index 86c5a7d..0ccac44 100644 --- a/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java +++ b/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java @@ -1,24 +1,17 @@ package com.telpo.dipperposition.service.impl; import com.alibaba.fastjson.JSONObject; -import com.google.common.base.Joiner; import com.telpo.dipperposition.common.*; import com.telpo.dipperposition.entity.mongo.IPProvinceEntity; -import com.telpo.dipperposition.mapper.IPProvinceMapper; import com.telpo.dipperposition.service.IDipperAstPosAsyncTaskService; import com.telpo.dipperposition.service.IPProvinceService; -import com.telpo.dipperposition.vo.IPProvinceVo; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.ObjectUtils; -import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Service; import java.io.UnsupportedEncodingException; -import java.time.LocalDateTime; -import java.time.format.DateTimeFormatter; import java.util.List; /** @@ -109,7 +102,7 @@ public class DipperAstPosAsyncTaskServiceImpl implements IDipperAstPosAsyncTaskS // 使用时,先在缓存中获取匹配信息 // 用mongodb实现 if(iPProvinceService == null) { - iPProvinceService = new IPProvinceServiceImpl(); + iPProvinceService = new IpProvinceServiceImpl(); } IPProvinceEntity ipProvinceEntity = iPProvinceService.getIpProvince(ipAddress); if (ipProvinceEntity == null) { @@ -144,7 +137,7 @@ public class DipperAstPosAsyncTaskServiceImpl implements IDipperAstPosAsyncTaskS log.debug("异步创建推送失败任务记录!"); try { if(iPProvinceService == null) { - iPProvinceService = new IPProvinceServiceImpl(); + iPProvinceService = new IpProvinceServiceImpl(); } IPProvinceEntity ipProvinceEntity = iPProvinceService.getIpProvince(ipAddress); if (ipProvinceEntity == null) { diff --git a/src/main/java/com/telpo/dipperposition/service/impl/IPProvinceServiceImpl.java b/src/main/java/com/telpo/dipperposition/service/impl/IpProvinceServiceImpl.java similarity index 65% rename from src/main/java/com/telpo/dipperposition/service/impl/IPProvinceServiceImpl.java rename to src/main/java/com/telpo/dipperposition/service/impl/IpProvinceServiceImpl.java index e7493c1..22bb8f8 100644 --- a/src/main/java/com/telpo/dipperposition/service/impl/IPProvinceServiceImpl.java +++ b/src/main/java/com/telpo/dipperposition/service/impl/IpProvinceServiceImpl.java @@ -1,10 +1,8 @@ package com.telpo.dipperposition.service.impl; import com.telpo.dipperposition.entity.mongo.IPProvinceEntity; -import com.telpo.dipperposition.mapper.IPProvinceMapper; -import com.telpo.dipperposition.service.IDipperDataAsyncTaskService; +import com.telpo.dipperposition.mapper.IpProvinceMapper; import com.telpo.dipperposition.service.IPProvinceService; -import com.telpo.dipperposition.vo.IPProvinceVo; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.ObjectUtils; import org.springframework.beans.factory.annotation.Autowired; @@ -20,10 +18,10 @@ import java.util.List; */ @Slf4j @Service -public class IPProvinceServiceImpl implements IPProvinceService { +public class IpProvinceServiceImpl implements IPProvinceService { @Autowired - private IPProvinceMapper iPProvinceMapper; + private IpProvinceMapper ipProvinceMapper; private static IPProvinceService ipProvinceService; /** @@ -36,29 +34,22 @@ public class IPProvinceServiceImpl implements IPProvinceService { } @Override public boolean saveIpProvince(IPProvinceEntity entity) { - if (iPProvinceMapper == null) { - iPProvinceMapper = new IPProvinceMapper(); - } - iPProvinceMapper.saveIp(entity); + ipProvinceMapper.saveIp(entity); return true; } @Override public boolean updateIPProvince( IPProvinceEntity query, IPProvinceEntity update) { - if (iPProvinceMapper == null) { - iPProvinceMapper = new IPProvinceMapper(); - } - iPProvinceMapper.updateIpFirst(query, update); + + ipProvinceMapper.updateIpFirst(query, update); return true; } @Override public boolean romveById(String id) { - if (iPProvinceMapper == null) { - iPProvinceMapper = new IPProvinceMapper(); - } - iPProvinceMapper.deleteIpById(id); + + ipProvinceMapper.deleteIpById(id); return false; } @@ -67,10 +58,8 @@ public class IPProvinceServiceImpl implements IPProvinceService { try { IPProvinceEntity query = new IPProvinceEntity(); query.setIp(ipAddress); - if (iPProvinceMapper == null) { - iPProvinceMapper = new IPProvinceMapper(); - } - List pushRecords = iPProvinceMapper.queryIpList(query); + + List pushRecords = ipProvinceMapper.queryIpList(query); if (ObjectUtils.isNotEmpty(pushRecords)) { return pushRecords.get(0); } else { From 37ac3fad432ede3b8443a9cc3fd8750683a5f4fe Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Mon, 18 Jan 2021 21:34:21 +0800 Subject: [PATCH 105/172] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=88=B0docker?= =?UTF-8?q?=E5=A4=96=E8=BF=90=E8=A1=8C=E7=8E=AF=E5=A2=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...nceService.java => IpProvinceService.java} | 2 +- .../DipperAstPosAsyncTaskServiceImpl.java | 25 ++++--------------- .../service/impl/IpProvinceServiceImpl.java | 8 +++--- 3 files changed, 10 insertions(+), 25 deletions(-) rename src/main/java/com/telpo/dipperposition/service/{IPProvinceService.java => IpProvinceService.java} (95%) diff --git a/src/main/java/com/telpo/dipperposition/service/IPProvinceService.java b/src/main/java/com/telpo/dipperposition/service/IpProvinceService.java similarity index 95% rename from src/main/java/com/telpo/dipperposition/service/IPProvinceService.java rename to src/main/java/com/telpo/dipperposition/service/IpProvinceService.java index de80294..63f1ab9 100644 --- a/src/main/java/com/telpo/dipperposition/service/IPProvinceService.java +++ b/src/main/java/com/telpo/dipperposition/service/IpProvinceService.java @@ -9,7 +9,7 @@ import com.telpo.dipperposition.vo.IPProvinceVo; * @author: king * @create: 2020-07-20 11:09 */ -public interface IPProvinceService { +public interface IpProvinceService { /** * 保存IP省份 diff --git a/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java b/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java index 0ccac44..e649fc6 100644 --- a/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java +++ b/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java @@ -4,7 +4,7 @@ import com.alibaba.fastjson.JSONObject; import com.telpo.dipperposition.common.*; import com.telpo.dipperposition.entity.mongo.IPProvinceEntity; import com.telpo.dipperposition.service.IDipperAstPosAsyncTaskService; -import com.telpo.dipperposition.service.IPProvinceService; +import com.telpo.dipperposition.service.IpProvinceService; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.ObjectUtils; import org.springframework.beans.factory.annotation.Autowired; @@ -33,7 +33,7 @@ public class DipperAstPosAsyncTaskServiceImpl implements IDipperAstPosAsyncTaskS @Autowired private OkHttpUtil okHttpUtil; @Autowired - private IPProvinceService iPProvinceService; + private IpProvinceService ipProvinceService; private static IDipperAstPosAsyncTaskService dipperAstPosAsyncTaskService; /** @@ -87,9 +87,6 @@ public class DipperAstPosAsyncTaskServiceImpl implements IDipperAstPosAsyncTaskS } else { centerProvinceName = centerAddressSetArray[3]; centerProvinceLonAndAlt = centerAddressSetArray[1]+","+centerAddressSetArray[2]; - if (redisUtil == null) { - redisUtil = new RedisUtil(); - } redisUtil.set(centerProvinceName, centerProvinceLonAndAlt, 0); } } @@ -101,18 +98,12 @@ public class DipperAstPosAsyncTaskServiceImpl implements IDipperAstPosAsyncTaskS // 关于IP与省份的关系保存到缓存中 // 使用时,先在缓存中获取匹配信息 // 用mongodb实现 - if(iPProvinceService == null) { - iPProvinceService = new IpProvinceServiceImpl(); - } - IPProvinceEntity ipProvinceEntity = iPProvinceService.getIpProvince(ipAddress); + IPProvinceEntity ipProvinceEntity = ipProvinceService.getIpProvince(ipAddress); if (ipProvinceEntity == null) { // 匹配不到,再请求高德IP定位服务。 JSONObject userObj = new JSONObject(); userObj.put("ip", ipAddress); userObj.put("key", ipPositionRequestKey); - if (okHttpUtil == null) { - okHttpUtil = new OkHttpUtil(); - } JSONObject json = okHttpUtil.postRequestWithJson(ipPositionRequestPath, null, userObj); if (ObjectUtils.isNotEmpty(json)) { String province = (String) json.get("province"); @@ -136,15 +127,12 @@ public class DipperAstPosAsyncTaskServiceImpl implements IDipperAstPosAsyncTaskS public void createIPProvince(String ipAddress, String province) { log.debug("异步创建推送失败任务记录!"); try { - if(iPProvinceService == null) { - iPProvinceService = new IpProvinceServiceImpl(); - } - IPProvinceEntity ipProvinceEntity = iPProvinceService.getIpProvince(ipAddress); + IPProvinceEntity ipProvinceEntity = ipProvinceService.getIpProvince(ipAddress); if (ipProvinceEntity == null) { //DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); ipProvinceEntity.setIp(ipAddress); ipProvinceEntity.setProvince(province); - iPProvinceService.saveIpProvince(ipProvinceEntity); + ipProvinceService.saveIpProvince(ipProvinceEntity); // } else { // // ipProvinceEntity.setProvince(province); @@ -182,9 +170,6 @@ public class DipperAstPosAsyncTaskServiceImpl implements IDipperAstPosAsyncTaskS } String lonAndAlt; - if (redisUtil == null) { - redisUtil = new RedisUtil(); - } if (redisUtil.hasKey(centerAddress)) { // 获取省会城市定位信息 lonAndAlt= (String) redisUtil.get(centerAddress); diff --git a/src/main/java/com/telpo/dipperposition/service/impl/IpProvinceServiceImpl.java b/src/main/java/com/telpo/dipperposition/service/impl/IpProvinceServiceImpl.java index 22bb8f8..9e52a9f 100644 --- a/src/main/java/com/telpo/dipperposition/service/impl/IpProvinceServiceImpl.java +++ b/src/main/java/com/telpo/dipperposition/service/impl/IpProvinceServiceImpl.java @@ -2,7 +2,7 @@ package com.telpo.dipperposition.service.impl; import com.telpo.dipperposition.entity.mongo.IPProvinceEntity; import com.telpo.dipperposition.mapper.IpProvinceMapper; -import com.telpo.dipperposition.service.IPProvinceService; +import com.telpo.dipperposition.service.IpProvinceService; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.ObjectUtils; import org.springframework.beans.factory.annotation.Autowired; @@ -18,18 +18,18 @@ import java.util.List; */ @Slf4j @Service -public class IpProvinceServiceImpl implements IPProvinceService { +public class IpProvinceServiceImpl implements IpProvinceService { @Autowired private IpProvinceMapper ipProvinceMapper; - private static IPProvinceService ipProvinceService; + private static IpProvinceService ipProvinceService; /** * spring会自动从ioc容器当中根据IPProvinceService类型找到ipProvinceService,当做参数传进来 * */ @Autowired - public void setIPProvinceService(IPProvinceService ipProvinceService) { + public void setIPProvinceService(IpProvinceService ipProvinceService) { this.ipProvinceService = ipProvinceService; } @Override From 74aa79d15d003236f93a89e83f5a0f7e0fd9e891 Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Mon, 18 Jan 2021 21:35:35 +0800 Subject: [PATCH 106/172] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=88=B0docker?= =?UTF-8?q?=E5=A4=96=E8=BF=90=E8=A1=8C=E7=8E=AF=E5=A2=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/DipperDataAsyncTaskServiceImpl.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/com/telpo/dipperposition/service/impl/DipperDataAsyncTaskServiceImpl.java b/src/main/java/com/telpo/dipperposition/service/impl/DipperDataAsyncTaskServiceImpl.java index 3f31de5..4c049bf 100644 --- a/src/main/java/com/telpo/dipperposition/service/impl/DipperDataAsyncTaskServiceImpl.java +++ b/src/main/java/com/telpo/dipperposition/service/impl/DipperDataAsyncTaskServiceImpl.java @@ -4,7 +4,6 @@ import com.telpo.dipperposition.common.HexConvert; import com.telpo.dipperposition.common.RedisUtil; import com.telpo.dipperposition.common.SocketClient; import com.telpo.dipperposition.config.SchedulingExecutorConfig; -import com.telpo.dipperposition.service.IDipperAstPosAsyncTaskService; import com.telpo.dipperposition.service.IDipperDataAsyncTaskService; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; From 24c3e28bba6f046967550d1f522b45d6521ea611 Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Mon, 18 Jan 2021 21:39:12 +0800 Subject: [PATCH 107/172] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=88=B0docker?= =?UTF-8?q?=E5=A4=96=E8=BF=90=E8=A1=8C=E7=8E=AF=E5=A2=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/DipperDataAsyncTaskServiceImpl.java | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/main/java/com/telpo/dipperposition/service/impl/DipperDataAsyncTaskServiceImpl.java b/src/main/java/com/telpo/dipperposition/service/impl/DipperDataAsyncTaskServiceImpl.java index 4c049bf..1b0e665 100644 --- a/src/main/java/com/telpo/dipperposition/service/impl/DipperDataAsyncTaskServiceImpl.java +++ b/src/main/java/com/telpo/dipperposition/service/impl/DipperDataAsyncTaskServiceImpl.java @@ -50,9 +50,6 @@ public class DipperDataAsyncTaskServiceImpl implements IDipperDataAsyncTaskServi log.error("获取星历数据错误,取不到星历数据。"); } else { // 保存到DB或者缓存 - if (redisUtil == null) { - redisUtil = new RedisUtil(); - } redisUtil.set(DIPPER_DATA_KEY,dipperData); } } @@ -77,9 +74,6 @@ public class DipperDataAsyncTaskServiceImpl implements IDipperDataAsyncTaskServi @Override @Async("asyncServiceExecutor") public String getAstEPH(){ - if (redisUtil == null) { - redisUtil = new RedisUtil(); - } return (String)redisUtil.get(DIPPER_DATA_KEY); } } From ef85220e1bcf92670e539aa7409497ac5675738d Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Mon, 18 Jan 2021 21:45:47 +0800 Subject: [PATCH 108/172] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=88=B0docker?= =?UTF-8?q?=E5=A4=96=E8=BF=90=E8=A1=8C=E7=8E=AF=E5=A2=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/DipperAstPosAsyncTaskServiceImpl.java | 4 ++-- .../service/impl/DipperAstTimeAsyncTaskServiceImpl.java | 4 ++-- .../service/impl/DipperDataAsyncTaskServiceImpl.java | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java b/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java index e649fc6..eed8cd0 100644 --- a/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java +++ b/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java @@ -35,13 +35,13 @@ public class DipperAstPosAsyncTaskServiceImpl implements IDipperAstPosAsyncTaskS @Autowired private IpProvinceService ipProvinceService; - private static IDipperAstPosAsyncTaskService dipperAstPosAsyncTaskService; + private static DipperAstPosAsyncTaskServiceImpl dipperAstPosAsyncTaskService; /** * spring会自动从ioc容器当中根据IDipperAstPosAsyncTaskService类型找到dipperAstPosAsyncTaskService,当做参数传进来 * */ @Autowired - public void setDipperAstPosAsyncTaskService(IDipperAstPosAsyncTaskService dipperAstPosAsyncTaskService) { + public void setDipperAstPosAsyncTaskService(DipperAstPosAsyncTaskServiceImpl dipperAstPosAsyncTaskService) { this.dipperAstPosAsyncTaskService = dipperAstPosAsyncTaskService; } diff --git a/src/main/java/com/telpo/dipperposition/service/impl/DipperAstTimeAsyncTaskServiceImpl.java b/src/main/java/com/telpo/dipperposition/service/impl/DipperAstTimeAsyncTaskServiceImpl.java index 6bb8f66..912bc34 100644 --- a/src/main/java/com/telpo/dipperposition/service/impl/DipperAstTimeAsyncTaskServiceImpl.java +++ b/src/main/java/com/telpo/dipperposition/service/impl/DipperAstTimeAsyncTaskServiceImpl.java @@ -23,13 +23,13 @@ import java.time.LocalDateTime; public class DipperAstTimeAsyncTaskServiceImpl implements IDipperAstTimeAsyncTaskService { - private static IDipperAstTimeAsyncTaskService dipperAstTimeAsyncTaskService; + private static DipperAstTimeAsyncTaskServiceImpl dipperAstTimeAsyncTaskService; /** * spring会自动从ioc容器当中根据IDipperAstPosAsyncTaskService类型找到dipperAstTimeAsyncTaskService,当做参数传进来 * */ @Autowired - public void setDipperAstTimeAsyncTaskService(IDipperAstTimeAsyncTaskService dipperAstTimeAsyncTaskService) { + public void setDipperAstTimeAsyncTaskService(DipperAstTimeAsyncTaskServiceImpl dipperAstTimeAsyncTaskService) { this.dipperAstTimeAsyncTaskService = dipperAstTimeAsyncTaskService; } diff --git a/src/main/java/com/telpo/dipperposition/service/impl/DipperDataAsyncTaskServiceImpl.java b/src/main/java/com/telpo/dipperposition/service/impl/DipperDataAsyncTaskServiceImpl.java index 1b0e665..3bb3234 100644 --- a/src/main/java/com/telpo/dipperposition/service/impl/DipperDataAsyncTaskServiceImpl.java +++ b/src/main/java/com/telpo/dipperposition/service/impl/DipperDataAsyncTaskServiceImpl.java @@ -30,13 +30,13 @@ public class DipperDataAsyncTaskServiceImpl implements IDipperDataAsyncTaskServi private SchedulingExecutorConfig schedulingExecutorConfig; - private static IDipperDataAsyncTaskService dipperDataAsyncTaskService; + private static DipperDataAsyncTaskServiceImpl dipperDataAsyncTaskService; /** * spring会自动从ioc容器当中根据IDipperDataAsyncTaskService类型找到dipperDataAsyncTaskService,当做参数传进来 * */ @Autowired - public void setDipperDataAsyncTaskService(IDipperDataAsyncTaskService dipperDataAsyncTaskService) { + public void setDipperDataAsyncTaskService(DipperDataAsyncTaskServiceImpl dipperDataAsyncTaskService) { this.dipperDataAsyncTaskService = dipperDataAsyncTaskService; } From ab05a135dcccda4cbec85654a5d3750da6024504 Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Mon, 18 Jan 2021 21:58:34 +0800 Subject: [PATCH 109/172] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=88=B0docker?= =?UTF-8?q?=E5=A4=96=E8=BF=90=E8=A1=8C=E7=8E=AF=E5=A2=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/IDipperAstPosAsyncTaskService.java | 4 ++++ .../service/IDipperAstTimeAsyncTaskService.java | 5 +++++ .../service/IDipperDataAsyncTaskService.java | 3 +++ .../telpo/dipperposition/service/IpProvinceService.java | 3 +++ .../service/impl/DipperAstPosAsyncTaskServiceImpl.java | 6 +++--- .../service/impl/DipperAstTimeAsyncTaskServiceImpl.java | 9 ++++----- .../service/impl/DipperDataAsyncTaskServiceImpl.java | 9 +++++---- .../service/impl/IpProvinceServiceImpl.java | 2 +- 8 files changed, 28 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/telpo/dipperposition/service/IDipperAstPosAsyncTaskService.java b/src/main/java/com/telpo/dipperposition/service/IDipperAstPosAsyncTaskService.java index dcc0cb8..49417ed 100644 --- a/src/main/java/com/telpo/dipperposition/service/IDipperAstPosAsyncTaskService.java +++ b/src/main/java/com/telpo/dipperposition/service/IDipperAstPosAsyncTaskService.java @@ -1,5 +1,7 @@ package com.telpo.dipperposition.service; +import org.springframework.beans.factory.annotation.Autowired; + import java.io.UnsupportedEncodingException; /** @@ -14,6 +16,8 @@ import java.io.UnsupportedEncodingException; */ public interface IDipperAstPosAsyncTaskService { + @Autowired + void setDipperAstPosAsyncTaskService(IDipperAstPosAsyncTaskService dipperAstPosAsyncTaskService); /** * 同步任务 * diff --git a/src/main/java/com/telpo/dipperposition/service/IDipperAstTimeAsyncTaskService.java b/src/main/java/com/telpo/dipperposition/service/IDipperAstTimeAsyncTaskService.java index 5dfeb0e..ff3ae94 100644 --- a/src/main/java/com/telpo/dipperposition/service/IDipperAstTimeAsyncTaskService.java +++ b/src/main/java/com/telpo/dipperposition/service/IDipperAstTimeAsyncTaskService.java @@ -1,5 +1,8 @@ package com.telpo.dipperposition.service; +import com.telpo.dipperposition.service.impl.DipperDataAsyncTaskServiceImpl; +import org.springframework.beans.factory.annotation.Autowired; + /** * @program: IDipperDataAsyncTaskService * @description: 发送SDBP-AST-TIME获取时间信息 @@ -8,6 +11,8 @@ package com.telpo.dipperposition.service; */ public interface IDipperAstTimeAsyncTaskService { + @Autowired + void setDipperAstTimeAsyncTaskService(IDipperAstTimeAsyncTaskService dipperAstTimeAsyncTaskService); /** * 同步任务 * diff --git a/src/main/java/com/telpo/dipperposition/service/IDipperDataAsyncTaskService.java b/src/main/java/com/telpo/dipperposition/service/IDipperDataAsyncTaskService.java index 708e6df..8778f97 100644 --- a/src/main/java/com/telpo/dipperposition/service/IDipperDataAsyncTaskService.java +++ b/src/main/java/com/telpo/dipperposition/service/IDipperDataAsyncTaskService.java @@ -1,5 +1,6 @@ package com.telpo.dipperposition.service; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; /** @@ -12,6 +13,8 @@ import org.springframework.beans.factory.annotation.Value; */ public interface IDipperDataAsyncTaskService { + @Autowired + void setDipperDataAsyncTaskService(IDipperDataAsyncTaskService IDipperDataAsyncTaskService); /** * 同步任务 * diff --git a/src/main/java/com/telpo/dipperposition/service/IpProvinceService.java b/src/main/java/com/telpo/dipperposition/service/IpProvinceService.java index 63f1ab9..128b778 100644 --- a/src/main/java/com/telpo/dipperposition/service/IpProvinceService.java +++ b/src/main/java/com/telpo/dipperposition/service/IpProvinceService.java @@ -2,6 +2,7 @@ package com.telpo.dipperposition.service; import com.telpo.dipperposition.entity.mongo.IPProvinceEntity; import com.telpo.dipperposition.vo.IPProvinceVo; +import org.springframework.beans.factory.annotation.Autowired; /** * @program: IPProvinceService @@ -11,6 +12,8 @@ import com.telpo.dipperposition.vo.IPProvinceVo; */ public interface IpProvinceService { + @Autowired + void setIPProvinceService(IpProvinceService ipProvinceService); /** * 保存IP省份 * diff --git a/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java b/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java index eed8cd0..ef78714 100644 --- a/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java +++ b/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java @@ -35,13 +35,13 @@ public class DipperAstPosAsyncTaskServiceImpl implements IDipperAstPosAsyncTaskS @Autowired private IpProvinceService ipProvinceService; - private static DipperAstPosAsyncTaskServiceImpl dipperAstPosAsyncTaskService; + private static IDipperAstPosAsyncTaskService dipperAstPosAsyncTaskService; /** * spring会自动从ioc容器当中根据IDipperAstPosAsyncTaskService类型找到dipperAstPosAsyncTaskService,当做参数传进来 * */ - @Autowired - public void setDipperAstPosAsyncTaskService(DipperAstPosAsyncTaskServiceImpl dipperAstPosAsyncTaskService) { + @Override + public void setDipperAstPosAsyncTaskService(IDipperAstPosAsyncTaskService dipperAstPosAsyncTaskService) { this.dipperAstPosAsyncTaskService = dipperAstPosAsyncTaskService; } diff --git a/src/main/java/com/telpo/dipperposition/service/impl/DipperAstTimeAsyncTaskServiceImpl.java b/src/main/java/com/telpo/dipperposition/service/impl/DipperAstTimeAsyncTaskServiceImpl.java index 912bc34..964d01b 100644 --- a/src/main/java/com/telpo/dipperposition/service/impl/DipperAstTimeAsyncTaskServiceImpl.java +++ b/src/main/java/com/telpo/dipperposition/service/impl/DipperAstTimeAsyncTaskServiceImpl.java @@ -22,14 +22,13 @@ import java.time.LocalDateTime; @Slf4j public class DipperAstTimeAsyncTaskServiceImpl implements IDipperAstTimeAsyncTaskService { - - private static DipperAstTimeAsyncTaskServiceImpl dipperAstTimeAsyncTaskService; + private static IDipperAstTimeAsyncTaskService dipperAstTimeAsyncTaskService; /** - * spring会自动从ioc容器当中根据IDipperAstPosAsyncTaskService类型找到dipperAstTimeAsyncTaskService,当做参数传进来 + * spring会自动从ioc容器当中根据IDipperAstTimeAsyncTaskService类型找到dipperAstTimeAsyncTaskService,当做参数传进来 * */ - @Autowired - public void setDipperAstTimeAsyncTaskService(DipperAstTimeAsyncTaskServiceImpl dipperAstTimeAsyncTaskService) { + @Override + public void setDipperAstTimeAsyncTaskService(IDipperAstTimeAsyncTaskService dipperAstTimeAsyncTaskService) { this.dipperAstTimeAsyncTaskService = dipperAstTimeAsyncTaskService; } diff --git a/src/main/java/com/telpo/dipperposition/service/impl/DipperDataAsyncTaskServiceImpl.java b/src/main/java/com/telpo/dipperposition/service/impl/DipperDataAsyncTaskServiceImpl.java index 3bb3234..61f55db 100644 --- a/src/main/java/com/telpo/dipperposition/service/impl/DipperDataAsyncTaskServiceImpl.java +++ b/src/main/java/com/telpo/dipperposition/service/impl/DipperDataAsyncTaskServiceImpl.java @@ -4,6 +4,7 @@ import com.telpo.dipperposition.common.HexConvert; import com.telpo.dipperposition.common.RedisUtil; import com.telpo.dipperposition.common.SocketClient; import com.telpo.dipperposition.config.SchedulingExecutorConfig; +import com.telpo.dipperposition.service.IDipperAstTimeAsyncTaskService; import com.telpo.dipperposition.service.IDipperDataAsyncTaskService; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; @@ -30,13 +31,13 @@ public class DipperDataAsyncTaskServiceImpl implements IDipperDataAsyncTaskServi private SchedulingExecutorConfig schedulingExecutorConfig; - private static DipperDataAsyncTaskServiceImpl dipperDataAsyncTaskService; + private static IDipperDataAsyncTaskService dipperDataAsyncTaskService; /** - * spring会自动从ioc容器当中根据IDipperDataAsyncTaskService类型找到dipperDataAsyncTaskService,当做参数传进来 + * spring会自动从ioc容器当中根据IDipperAstTimeAsyncTaskService类型找到dipperDataAsyncTaskService,当做参数传进来 * */ - @Autowired - public void setDipperDataAsyncTaskService(DipperDataAsyncTaskServiceImpl dipperDataAsyncTaskService) { + @Override + public void setDipperDataAsyncTaskService(IDipperDataAsyncTaskService dipperDataAsyncTaskService) { this.dipperDataAsyncTaskService = dipperDataAsyncTaskService; } diff --git a/src/main/java/com/telpo/dipperposition/service/impl/IpProvinceServiceImpl.java b/src/main/java/com/telpo/dipperposition/service/impl/IpProvinceServiceImpl.java index 9e52a9f..ebc195b 100644 --- a/src/main/java/com/telpo/dipperposition/service/impl/IpProvinceServiceImpl.java +++ b/src/main/java/com/telpo/dipperposition/service/impl/IpProvinceServiceImpl.java @@ -28,7 +28,7 @@ public class IpProvinceServiceImpl implements IpProvinceService { * spring会自动从ioc容器当中根据IPProvinceService类型找到ipProvinceService,当做参数传进来 * */ - @Autowired + @Override public void setIPProvinceService(IpProvinceService ipProvinceService) { this.ipProvinceService = ipProvinceService; } From fa52d5cb216568226513d3e004e8ea960b036ba5 Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Mon, 18 Jan 2021 22:16:52 +0800 Subject: [PATCH 110/172] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=88=B0docker?= =?UTF-8?q?=E5=A4=96=E8=BF=90=E8=A1=8C=E7=8E=AF=E5=A2=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...vinceEntity.java => IpProvinceEntity.java} | 4 +-- .../mapper/IpProvinceMapper.java | 30 +++++++++---------- .../service/IpProvinceService.java | 9 +++--- .../DipperAstPosAsyncTaskServiceImpl.java | 6 ++-- .../service/impl/IpProvinceServiceImpl.java | 12 ++++---- 5 files changed, 30 insertions(+), 31 deletions(-) rename src/main/java/com/telpo/dipperposition/entity/mongo/{IPProvinceEntity.java => IpProvinceEntity.java} (82%) diff --git a/src/main/java/com/telpo/dipperposition/entity/mongo/IPProvinceEntity.java b/src/main/java/com/telpo/dipperposition/entity/mongo/IpProvinceEntity.java similarity index 82% rename from src/main/java/com/telpo/dipperposition/entity/mongo/IPProvinceEntity.java rename to src/main/java/com/telpo/dipperposition/entity/mongo/IpProvinceEntity.java index d9f27df..42edb3d 100644 --- a/src/main/java/com/telpo/dipperposition/entity/mongo/IPProvinceEntity.java +++ b/src/main/java/com/telpo/dipperposition/entity/mongo/IpProvinceEntity.java @@ -7,7 +7,7 @@ import lombok.ToString; import models.BaseMongoDbEntity; /** - * @program: IPProvinceEntity + * @program: IpProvinceEntity * @description: 位置实体类 * @author: linwl * @create: 2020-07-11 15:33 @@ -15,7 +15,7 @@ import models.BaseMongoDbEntity; @ToString @Getter @Setter -public class IPProvinceEntity extends BaseMongoDbEntity { +public class IpProvinceEntity extends BaseMongoDbEntity { /** Ip */ private String ip; diff --git a/src/main/java/com/telpo/dipperposition/mapper/IpProvinceMapper.java b/src/main/java/com/telpo/dipperposition/mapper/IpProvinceMapper.java index bc428d1..c615355 100644 --- a/src/main/java/com/telpo/dipperposition/mapper/IpProvinceMapper.java +++ b/src/main/java/com/telpo/dipperposition/mapper/IpProvinceMapper.java @@ -1,7 +1,7 @@ package com.telpo.dipperposition.mapper; import com.telpo.dipperposition.annotation.MongoSwitch; -import com.telpo.dipperposition.entity.mongo.IPProvinceEntity; +import com.telpo.dipperposition.entity.mongo.IpProvinceEntity; import db.BaseMongoDbDao; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Repository; @@ -15,51 +15,51 @@ import java.util.List; * @create: 2020-07-20 11:12 */ @Repository -public class IpProvinceMapper extends BaseMongoDbDao { +public class IpProvinceMapper extends BaseMongoDbDao { - private static IpProvinceMapper ipProvinceMapper; +// private static IpProvinceMapper ipProvinceMapper; /** * spring会自动从ioc容器当中根据IPProvinceMapper类型找到iPProvinceMapper, * 当做参数传进来 * */ - @Autowired - public void setIPProvinceMapper(IpProvinceMapper ipProvinceMapper) { - this.ipProvinceMapper = ipProvinceMapper; - } +// @Autowired +// public void setIPProvinceMapper(IpProvinceMapper ipProvinceMapper) { +// this.ipProvinceMapper = ipProvinceMapper; +// } @Override - protected Class getEntityClass() { - return IPProvinceEntity.class; + protected Class getEntityClass() { + return IpProvinceEntity.class; } @MongoSwitch("common") - public void saveIp(IPProvinceEntity entity) { + public void saveIp(IpProvinceEntity entity) { this.save(entity); } @MongoSwitch("common") - public void saveIp(IPProvinceEntity entity, String collectionName) { + public void saveIp(IpProvinceEntity entity, String collectionName) { this.save(entity, collectionName); } @MongoSwitch("common") - public void updateIpFirst(IPProvinceEntity srcObj, IPProvinceEntity targetObj) { + public void updateIpFirst(IpProvinceEntity srcObj, IpProvinceEntity targetObj) { this.updateFirst(srcObj, targetObj); } @Override - public List getPage(IPProvinceEntity object, int start, int size) { + public List getPage(IpProvinceEntity object, int start, int size) { return super.getPage(object, start, size); } @MongoSwitch("common") - public List queryIpList(IPProvinceEntity object) { + public List queryIpList(IpProvinceEntity object) { return this.queryList(object); } @MongoSwitch("common") - public List queryIpList(IPProvinceEntity object, String collectionName) { + public List queryIpList(IpProvinceEntity object, String collectionName) { return this.queryList(object, collectionName); } diff --git a/src/main/java/com/telpo/dipperposition/service/IpProvinceService.java b/src/main/java/com/telpo/dipperposition/service/IpProvinceService.java index 128b778..e335e8f 100644 --- a/src/main/java/com/telpo/dipperposition/service/IpProvinceService.java +++ b/src/main/java/com/telpo/dipperposition/service/IpProvinceService.java @@ -1,7 +1,6 @@ package com.telpo.dipperposition.service; -import com.telpo.dipperposition.entity.mongo.IPProvinceEntity; -import com.telpo.dipperposition.vo.IPProvinceVo; +import com.telpo.dipperposition.entity.mongo.IpProvinceEntity; import org.springframework.beans.factory.annotation.Autowired; /** @@ -20,7 +19,7 @@ public interface IpProvinceService { * @param entity * @return */ - boolean saveIpProvince(IPProvinceEntity entity); + boolean saveIpProvince(IpProvinceEntity entity); /** * 更新IP省份 @@ -30,7 +29,7 @@ public interface IpProvinceService { * @return */ boolean updateIPProvince( - IPProvinceEntity query, IPProvinceEntity update); + IpProvinceEntity query, IpProvinceEntity update); /** * 根据ID移除IP省份记录 @@ -44,5 +43,5 @@ public interface IpProvinceService { * @param ipAddress * 获取IP省份 */ - IPProvinceEntity getIpProvince(String ipAddress); + IpProvinceEntity getIpProvince(String ipAddress); } diff --git a/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java b/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java index ef78714..218b1d5 100644 --- a/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java +++ b/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java @@ -2,7 +2,7 @@ package com.telpo.dipperposition.service.impl; import com.alibaba.fastjson.JSONObject; import com.telpo.dipperposition.common.*; -import com.telpo.dipperposition.entity.mongo.IPProvinceEntity; +import com.telpo.dipperposition.entity.mongo.IpProvinceEntity; import com.telpo.dipperposition.service.IDipperAstPosAsyncTaskService; import com.telpo.dipperposition.service.IpProvinceService; import lombok.extern.slf4j.Slf4j; @@ -98,7 +98,7 @@ public class DipperAstPosAsyncTaskServiceImpl implements IDipperAstPosAsyncTaskS // 关于IP与省份的关系保存到缓存中 // 使用时,先在缓存中获取匹配信息 // 用mongodb实现 - IPProvinceEntity ipProvinceEntity = ipProvinceService.getIpProvince(ipAddress); + IpProvinceEntity ipProvinceEntity = ipProvinceService.getIpProvince(ipAddress); if (ipProvinceEntity == null) { // 匹配不到,再请求高德IP定位服务。 JSONObject userObj = new JSONObject(); @@ -127,7 +127,7 @@ public class DipperAstPosAsyncTaskServiceImpl implements IDipperAstPosAsyncTaskS public void createIPProvince(String ipAddress, String province) { log.debug("异步创建推送失败任务记录!"); try { - IPProvinceEntity ipProvinceEntity = ipProvinceService.getIpProvince(ipAddress); + IpProvinceEntity ipProvinceEntity = ipProvinceService.getIpProvince(ipAddress); if (ipProvinceEntity == null) { //DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); ipProvinceEntity.setIp(ipAddress); diff --git a/src/main/java/com/telpo/dipperposition/service/impl/IpProvinceServiceImpl.java b/src/main/java/com/telpo/dipperposition/service/impl/IpProvinceServiceImpl.java index ebc195b..ab282df 100644 --- a/src/main/java/com/telpo/dipperposition/service/impl/IpProvinceServiceImpl.java +++ b/src/main/java/com/telpo/dipperposition/service/impl/IpProvinceServiceImpl.java @@ -1,6 +1,6 @@ package com.telpo.dipperposition.service.impl; -import com.telpo.dipperposition.entity.mongo.IPProvinceEntity; +import com.telpo.dipperposition.entity.mongo.IpProvinceEntity; import com.telpo.dipperposition.mapper.IpProvinceMapper; import com.telpo.dipperposition.service.IpProvinceService; import lombok.extern.slf4j.Slf4j; @@ -33,14 +33,14 @@ public class IpProvinceServiceImpl implements IpProvinceService { this.ipProvinceService = ipProvinceService; } @Override - public boolean saveIpProvince(IPProvinceEntity entity) { + public boolean saveIpProvince(IpProvinceEntity entity) { ipProvinceMapper.saveIp(entity); return true; } @Override public boolean updateIPProvince( - IPProvinceEntity query, IPProvinceEntity update) { + IpProvinceEntity query, IpProvinceEntity update) { ipProvinceMapper.updateIpFirst(query, update); return true; @@ -54,12 +54,12 @@ public class IpProvinceServiceImpl implements IpProvinceService { } @Override - public IPProvinceEntity getIpProvince(String ipAddress) { + public IpProvinceEntity getIpProvince(String ipAddress) { try { - IPProvinceEntity query = new IPProvinceEntity(); + IpProvinceEntity query = new IpProvinceEntity(); query.setIp(ipAddress); - List pushRecords = ipProvinceMapper.queryIpList(query); + List pushRecords = ipProvinceMapper.queryIpList(query); if (ObjectUtils.isNotEmpty(pushRecords)) { return pushRecords.get(0); } else { From 5aaf4a19e271295ff5a013c26141664958bc1d7a Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Mon, 18 Jan 2021 22:24:55 +0800 Subject: [PATCH 111/172] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=88=B0docker?= =?UTF-8?q?=E5=A4=96=E8=BF=90=E8=A1=8C=E7=8E=AF=E5=A2=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dipperposition/config/NettyServerConfig.java | 15 +++++++-------- .../dipperposition/config/PositionConfig.java | 13 ++++++------- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/src/main/java/com/telpo/dipperposition/config/NettyServerConfig.java b/src/main/java/com/telpo/dipperposition/config/NettyServerConfig.java index 54fcfbb..b5f2b55 100644 --- a/src/main/java/com/telpo/dipperposition/config/NettyServerConfig.java +++ b/src/main/java/com/telpo/dipperposition/config/NettyServerConfig.java @@ -8,6 +8,8 @@ import lombok.Setter; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Configuration; +import javax.annotation.PostConstruct; + /** * @program: gateway * @description: jwt设置 @@ -33,13 +35,10 @@ public class NettyServerConfig { private String starsAsycServerPort; private static NettyServerConfig nettyServerConfig; - /** - * spring会自动从ioc容器当中根据NettyServerConfig类型找到nettyServerConfig, - * 当做参数传进来 - * - */ - @Autowired - public void setNettyServerConfig(NettyServerConfig nettyServerConfig) { - this.nettyServerConfig = nettyServerConfig; + + @PostConstruct + public void init() { + nettyServerConfig = this; } + } diff --git a/src/main/java/com/telpo/dipperposition/config/PositionConfig.java b/src/main/java/com/telpo/dipperposition/config/PositionConfig.java index 97d2d3a..f4e16a9 100644 --- a/src/main/java/com/telpo/dipperposition/config/PositionConfig.java +++ b/src/main/java/com/telpo/dipperposition/config/PositionConfig.java @@ -7,6 +7,8 @@ import lombok.Setter; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Configuration; +import javax.annotation.PostConstruct; + /** * @program: gateway * @description: jwt设置 @@ -39,12 +41,9 @@ public class PositionConfig { private static PositionConfig positionConfig; - /** - * spring会自动从ioc容器当中根据PositionConfig类型找到positionConfig,当做参数传进来 - * - */ - @Autowired - public void setPositionConfig(PositionConfig positionConfig) { - this.positionConfig = positionConfig; + + @PostConstruct + public void init() { + positionConfig = this; } } From 01c93f2d02c0b845640c3b787665ee54cbec4b17 Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Mon, 18 Jan 2021 22:27:32 +0800 Subject: [PATCH 112/172] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=88=B0docker?= =?UTF-8?q?=E5=A4=96=E8=BF=90=E8=A1=8C=E7=8E=AF=E5=A2=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/telpo/dipperposition/common/OkHttpUtil.java | 13 +++++-------- .../com/telpo/dipperposition/common/RedisUtil.java | 8 +++++--- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/telpo/dipperposition/common/OkHttpUtil.java b/src/main/java/com/telpo/dipperposition/common/OkHttpUtil.java index 9063e5c..2452e02 100644 --- a/src/main/java/com/telpo/dipperposition/common/OkHttpUtil.java +++ b/src/main/java/com/telpo/dipperposition/common/OkHttpUtil.java @@ -8,6 +8,7 @@ import org.apache.commons.lang3.exception.ExceptionUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import javax.annotation.PostConstruct; import java.text.MessageFormat; import java.util.Iterator; import java.util.Map; @@ -26,15 +27,11 @@ public class OkHttpUtil { @Autowired private OkHttpClient okHttpClient; private static OkHttpUtil okHttpUtil; - /** - * spring会自动从ioc容器当中根据OkHttpUtil类型找到okHttpUtil,当做参数传进来 - * - */ - @Autowired - public void setOkHttpUtil(OkHttpUtil okHttpUtil) { - this.okHttpUtil = okHttpUtil; - } + @PostConstruct + public void init() { + okHttpUtil = this; + } /** * 根据map获取get请求参数 * diff --git a/src/main/java/com/telpo/dipperposition/common/RedisUtil.java b/src/main/java/com/telpo/dipperposition/common/RedisUtil.java index 8ef86a5..107ace8 100644 --- a/src/main/java/com/telpo/dipperposition/common/RedisUtil.java +++ b/src/main/java/com/telpo/dipperposition/common/RedisUtil.java @@ -6,6 +6,7 @@ import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Component; import org.springframework.util.CollectionUtils; +import javax.annotation.PostConstruct; import javax.annotation.Resource; import java.util.List; import java.util.Map; @@ -29,9 +30,10 @@ public class RedisUtil { * spring会自动从ioc容器当中根据RedisUtil类型找到redisUtil,当做参数传进来 * */ - @Autowired - public void setRedisUtil(RedisUtil redisUtil) { - this.redisUtil = redisUtil; + + @PostConstruct + public void init() { + redisUtil = this; } // =============================common============================ /** From 1ccd98eb1f8649571917e9352cac96ac9e73a797 Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Tue, 19 Jan 2021 08:30:34 +0800 Subject: [PATCH 113/172] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=88=B0docker?= =?UTF-8?q?=E5=A4=96=E8=BF=90=E8=A1=8C=E7=8E=AF=E5=A2=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dipperposition/common/OkHttpUtil.java | 2 +- .../dipperposition/common/RedisUtil.java | 7 +--- .../config/NettyServerConfig.java | 2 +- .../dipperposition/config/PositionConfig.java | 2 +- .../DipperAstPosAsyncTaskController.java | 30 +++++++++++++ .../DipperAstTimeAsyncTaskController.java | 32 ++++++++++++++ ...ava => DipperDataAsyncTaskController.java} | 23 +++++++++- .../handler/NettyServerHandler.java | 42 ++++++++++--------- .../IDipperAstPosAsyncTaskService.java | 14 +++---- .../IDipperAstTimeAsyncTaskService.java | 4 +- .../service/IDipperDataAsyncTaskService.java | 4 +- .../service/IpProvinceService.java | 4 +- .../DipperAstPosAsyncTaskServiceImpl.java | 35 +++++++++------- .../DipperAstTimeAsyncTaskServiceImpl.java | 20 ++++----- .../impl/DipperDataAsyncTaskServiceImpl.java | 21 +++++----- .../service/impl/IpProvinceServiceImpl.java | 18 ++++---- 16 files changed, 175 insertions(+), 85 deletions(-) create mode 100644 src/main/java/com/telpo/dipperposition/controller/DipperAstPosAsyncTaskController.java create mode 100644 src/main/java/com/telpo/dipperposition/controller/DipperAstTimeAsyncTaskController.java rename src/main/java/com/telpo/dipperposition/controller/{DipperPositionController.java => DipperDataAsyncTaskController.java} (54%) diff --git a/src/main/java/com/telpo/dipperposition/common/OkHttpUtil.java b/src/main/java/com/telpo/dipperposition/common/OkHttpUtil.java index 2452e02..daac774 100644 --- a/src/main/java/com/telpo/dipperposition/common/OkHttpUtil.java +++ b/src/main/java/com/telpo/dipperposition/common/OkHttpUtil.java @@ -26,7 +26,7 @@ public class OkHttpUtil { @Autowired private OkHttpClient okHttpClient; - private static OkHttpUtil okHttpUtil; + public static OkHttpUtil okHttpUtil; @PostConstruct public void init() { diff --git a/src/main/java/com/telpo/dipperposition/common/RedisUtil.java b/src/main/java/com/telpo/dipperposition/common/RedisUtil.java index 107ace8..33b262a 100644 --- a/src/main/java/com/telpo/dipperposition/common/RedisUtil.java +++ b/src/main/java/com/telpo/dipperposition/common/RedisUtil.java @@ -25,12 +25,7 @@ public class RedisUtil { @Resource private RedisTemplate redisTemplate; - private static RedisUtil redisUtil; - /** - * spring会自动从ioc容器当中根据RedisUtil类型找到redisUtil,当做参数传进来 - * - */ - + public static RedisUtil redisUtil; @PostConstruct public void init() { redisUtil = this; diff --git a/src/main/java/com/telpo/dipperposition/config/NettyServerConfig.java b/src/main/java/com/telpo/dipperposition/config/NettyServerConfig.java index b5f2b55..3c0b6bc 100644 --- a/src/main/java/com/telpo/dipperposition/config/NettyServerConfig.java +++ b/src/main/java/com/telpo/dipperposition/config/NettyServerConfig.java @@ -34,7 +34,7 @@ public class NettyServerConfig { @NacosValue(value = "${position-server.starsAsycPort}") private String starsAsycServerPort; - private static NettyServerConfig nettyServerConfig; + public static NettyServerConfig nettyServerConfig; @PostConstruct public void init() { diff --git a/src/main/java/com/telpo/dipperposition/config/PositionConfig.java b/src/main/java/com/telpo/dipperposition/config/PositionConfig.java index f4e16a9..47d8b0a 100644 --- a/src/main/java/com/telpo/dipperposition/config/PositionConfig.java +++ b/src/main/java/com/telpo/dipperposition/config/PositionConfig.java @@ -40,7 +40,7 @@ public class PositionConfig { int astTimeout; - private static PositionConfig positionConfig; + public static PositionConfig positionConfig; @PostConstruct public void init() { diff --git a/src/main/java/com/telpo/dipperposition/controller/DipperAstPosAsyncTaskController.java b/src/main/java/com/telpo/dipperposition/controller/DipperAstPosAsyncTaskController.java new file mode 100644 index 0000000..78dca24 --- /dev/null +++ b/src/main/java/com/telpo/dipperposition/controller/DipperAstPosAsyncTaskController.java @@ -0,0 +1,30 @@ +package com.telpo.dipperposition.controller; + +import com.telpo.dipperposition.service.IDipperAstPosAsyncTaskService; +import com.telpo.dipperposition.service.IDipperAstTimeAsyncTaskService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.RestController; + + +/** + * @program: DipperAstPosAsyncTaskController + * @description: 北斗定位 + * @author: linwl + * @create: 2020-07-10 14:01 + */ +@RestController +@Slf4j +public class DipperAstPosAsyncTaskController { + + @Autowired + IDipperAstPosAsyncTaskService dipperAstPosAsyncTaskService; + + /* + * 拉取星历数据 + */ + public String pushAstPos(String ipAddress) { + return dipperAstPosAsyncTaskService.pushAstPos(ipAddress); + } + +} diff --git a/src/main/java/com/telpo/dipperposition/controller/DipperAstTimeAsyncTaskController.java b/src/main/java/com/telpo/dipperposition/controller/DipperAstTimeAsyncTaskController.java new file mode 100644 index 0000000..265e5ee --- /dev/null +++ b/src/main/java/com/telpo/dipperposition/controller/DipperAstTimeAsyncTaskController.java @@ -0,0 +1,32 @@ +package com.telpo.dipperposition.controller; + +import com.telpo.dipperposition.service.IDipperAstTimeAsyncTaskService; +import com.telpo.dipperposition.service.IDipperDataAsyncTaskService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + + +/** + * @program: DipperPositionController + * @description: 北斗定位 + * @author: linwl + * @create: 2020-07-10 14:01 + */ +@RestController +@Slf4j +public class DipperAstTimeAsyncTaskController { + + @Autowired + IDipperAstTimeAsyncTaskService dipperTimeAsyncTaskService; + + /* + * 拉取星历数据 + */ + public String pushAstTime() { + return dipperTimeAsyncTaskService.pushAstTime(); + } + +} diff --git a/src/main/java/com/telpo/dipperposition/controller/DipperPositionController.java b/src/main/java/com/telpo/dipperposition/controller/DipperDataAsyncTaskController.java similarity index 54% rename from src/main/java/com/telpo/dipperposition/controller/DipperPositionController.java rename to src/main/java/com/telpo/dipperposition/controller/DipperDataAsyncTaskController.java index 524256a..786a9c8 100644 --- a/src/main/java/com/telpo/dipperposition/controller/DipperPositionController.java +++ b/src/main/java/com/telpo/dipperposition/controller/DipperDataAsyncTaskController.java @@ -1,6 +1,8 @@ package com.telpo.dipperposition.controller; +import com.telpo.dipperposition.service.IDipperDataAsyncTaskService; import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @@ -14,13 +16,32 @@ import org.springframework.web.bind.annotation.RestController; */ @RestController @Slf4j -public class DipperPositionController { +public class DipperDataAsyncTaskController { @Value(value = "${position-server.serverAddr}") private String hello; //RzlAccount rzlAccount; + @Autowired + IDipperDataAsyncTaskService dipperDataAsyncTaskService; + + /* + * 拉取星历数据 + */ + public void pullAstEPH() { + dipperDataAsyncTaskService.pullAstEPH(); + } + + /* + * 获取星历数据 + */ + public String getAstEPH() { + return dipperDataAsyncTaskService.getAstEPH(); + } + + @RequestMapping("/getPos") public String getPos() { return "return serverAddr = " + hello; } + } diff --git a/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java b/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java index 66173fa..651adad 100644 --- a/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java +++ b/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java @@ -2,6 +2,9 @@ package com.telpo.dipperposition.handler; import com.telpo.dipperposition.config.NettyServerConfig; import com.telpo.dipperposition.config.PositionConfig; +import com.telpo.dipperposition.controller.DipperAstPosAsyncTaskController; +import com.telpo.dipperposition.controller.DipperAstTimeAsyncTaskController; +import com.telpo.dipperposition.controller.DipperDataAsyncTaskController; import com.telpo.dipperposition.enums.DipperReturnValue; import com.telpo.dipperposition.service.IDipperAstPosAsyncTaskService; import com.telpo.dipperposition.service.IDipperAstTimeAsyncTaskService; @@ -38,11 +41,11 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter { private static String AST_EPH_CMD_BYTE = "455048"; @Autowired - private IDipperAstTimeAsyncTaskService dipperTimeAsyncTaskService; + private DipperAstTimeAsyncTaskController dipperTimeAsyncTaskController; @Autowired - private IDipperAstPosAsyncTaskService dipperAstPosAsyncTaskService; + private DipperAstPosAsyncTaskController dipperAstPosAsyncTaskController; @Autowired - private IDipperDataAsyncTaskService dipperDataAsyncTaskService; + private DipperDataAsyncTaskController dipperDataAsyncTaskController; @Autowired private NettyServerConfig nettyServerConfig; @@ -114,10 +117,10 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter { //if (AST_TIME_CMD.equals(recvmg)) { if (AST_TIME_CMD.equals(msg)) { // 初始时间辅助输入; - if (dipperTimeAsyncTaskService == null) { - dipperTimeAsyncTaskService = new DipperAstTimeAsyncTaskServiceImpl(); - } - channelAns = dipperTimeAsyncTaskService.pushAstTime(); +// if (dipperTimeAsyncTaskService == null) { +// dipperTimeAsyncTaskService = new DipperAstTimeAsyncTaskServiceImpl(); +// } + channelAns = dipperTimeAsyncTaskController.pushAstTime(); } // 发送SDBP-AST-POS获取辅助位置信息 @@ -136,24 +139,25 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter { // positionConfig.getCenterProvince(), // positionConfig.getIpPositionRequestPath(), // positionConfig.getIpPositionRequestKey()); - if (dipperAstPosAsyncTaskService == null) { - dipperAstPosAsyncTaskService = new DipperAstPosAsyncTaskServiceImpl(); - } - channelAns = dipperAstPosAsyncTaskService.pushAstPos(ipAddress, - "/csv/provinceLonAlt.csv", - "湖北省", - "https://restapi.amap.com/v3/ip", - "65e794b0a1a4b87eeec86f93fea05411"); +// if (dipperAstPosAsyncTaskService == null) { +// dipperAstPosAsyncTaskService = new DipperAstPosAsyncTaskServiceImpl(); +// } + channelAns = dipperAstPosAsyncTaskController.pushAstPos(ipAddress); +// (ipAddress, +// "/csv/provinceLonAlt.csv", +// "湖北省", +// "https://restapi.amap.com/v3/ip", +// "65e794b0a1a4b87eeec86f93fea05411"); } // 从缓存获取SDBP-AST-EPH星历数 //if (Integer.parseInt(starsAsycServerPort) == channel.localAddress().getPort()) { //if (AST_POS_CMD.equals(recvmg)) { if (AST_POS_CMD.equals(msg)) { - if (dipperDataAsyncTaskService == null) { - dipperDataAsyncTaskService = new DipperDataAsyncTaskServiceImpl(); - } - channelAns = dipperDataAsyncTaskService.getAstEPH(); +// if (dipperDataAsyncTaskService == null) { +// dipperDataAsyncTaskService = new DipperDataAsyncTaskServiceImpl(); +// } + channelAns = dipperDataAsyncTaskController.getAstEPH(); } log.info(channelAns); diff --git a/src/main/java/com/telpo/dipperposition/service/IDipperAstPosAsyncTaskService.java b/src/main/java/com/telpo/dipperposition/service/IDipperAstPosAsyncTaskService.java index 49417ed..5c85f4b 100644 --- a/src/main/java/com/telpo/dipperposition/service/IDipperAstPosAsyncTaskService.java +++ b/src/main/java/com/telpo/dipperposition/service/IDipperAstPosAsyncTaskService.java @@ -16,16 +16,16 @@ import java.io.UnsupportedEncodingException; */ public interface IDipperAstPosAsyncTaskService { - @Autowired - void setDipperAstPosAsyncTaskService(IDipperAstPosAsyncTaskService dipperAstPosAsyncTaskService); /** * 同步任务 * */ - String pushAstPos(String ipAddress, - String centerProvinceFilePath, - String centerProvince, - String ipPositionRequestPath, - String ipPositionRequestKey) throws UnsupportedEncodingException; + String pushAstPos(String ipAddress); + +// String pushAstPos(String ipAddress, +// String centerProvinceFilePath, +// String centerProvince, +// String ipPositionRequestPath, +// String ipPositionRequestKey) throws UnsupportedEncodingException; } diff --git a/src/main/java/com/telpo/dipperposition/service/IDipperAstTimeAsyncTaskService.java b/src/main/java/com/telpo/dipperposition/service/IDipperAstTimeAsyncTaskService.java index ff3ae94..7703a56 100644 --- a/src/main/java/com/telpo/dipperposition/service/IDipperAstTimeAsyncTaskService.java +++ b/src/main/java/com/telpo/dipperposition/service/IDipperAstTimeAsyncTaskService.java @@ -11,8 +11,8 @@ import org.springframework.beans.factory.annotation.Autowired; */ public interface IDipperAstTimeAsyncTaskService { - @Autowired - void setDipperAstTimeAsyncTaskService(IDipperAstTimeAsyncTaskService dipperAstTimeAsyncTaskService); +// @Autowired +// void setDipperAstTimeAsyncTaskService(IDipperAstTimeAsyncTaskService dipperAstTimeAsyncTaskService); /** * 同步任务 * diff --git a/src/main/java/com/telpo/dipperposition/service/IDipperDataAsyncTaskService.java b/src/main/java/com/telpo/dipperposition/service/IDipperDataAsyncTaskService.java index 8778f97..d5637f9 100644 --- a/src/main/java/com/telpo/dipperposition/service/IDipperDataAsyncTaskService.java +++ b/src/main/java/com/telpo/dipperposition/service/IDipperDataAsyncTaskService.java @@ -13,8 +13,8 @@ import org.springframework.beans.factory.annotation.Value; */ public interface IDipperDataAsyncTaskService { - @Autowired - void setDipperDataAsyncTaskService(IDipperDataAsyncTaskService IDipperDataAsyncTaskService); +// @Autowired +// void setDipperDataAsyncTaskService(IDipperDataAsyncTaskService IDipperDataAsyncTaskService); /** * 同步任务 * diff --git a/src/main/java/com/telpo/dipperposition/service/IpProvinceService.java b/src/main/java/com/telpo/dipperposition/service/IpProvinceService.java index e335e8f..cb58ab0 100644 --- a/src/main/java/com/telpo/dipperposition/service/IpProvinceService.java +++ b/src/main/java/com/telpo/dipperposition/service/IpProvinceService.java @@ -11,8 +11,8 @@ import org.springframework.beans.factory.annotation.Autowired; */ public interface IpProvinceService { - @Autowired - void setIPProvinceService(IpProvinceService ipProvinceService); +// @Autowired +// void setIPProvinceService(IpProvinceService ipProvinceService); /** * 保存IP省份 * diff --git a/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java b/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java index 218b1d5..b2e42d8 100644 --- a/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java +++ b/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java @@ -2,6 +2,8 @@ package com.telpo.dipperposition.service.impl; import com.alibaba.fastjson.JSONObject; import com.telpo.dipperposition.common.*; +import com.telpo.dipperposition.config.NettyServerConfig; +import com.telpo.dipperposition.config.PositionConfig; import com.telpo.dipperposition.entity.mongo.IpProvinceEntity; import com.telpo.dipperposition.service.IDipperAstPosAsyncTaskService; import com.telpo.dipperposition.service.IpProvinceService; @@ -33,17 +35,21 @@ public class DipperAstPosAsyncTaskServiceImpl implements IDipperAstPosAsyncTaskS @Autowired private OkHttpUtil okHttpUtil; @Autowired + private NettyServerConfig nettyServerConfig; + @Autowired + private PositionConfig positionConfig; + @Autowired private IpProvinceService ipProvinceService; - private static IDipperAstPosAsyncTaskService dipperAstPosAsyncTaskService; +// private static IDipperAstPosAsyncTaskService dipperAstPosAsyncTaskService; /** * spring会自动从ioc容器当中根据IDipperAstPosAsyncTaskService类型找到dipperAstPosAsyncTaskService,当做参数传进来 * */ - @Override - public void setDipperAstPosAsyncTaskService(IDipperAstPosAsyncTaskService dipperAstPosAsyncTaskService) { - this.dipperAstPosAsyncTaskService = dipperAstPosAsyncTaskService; - } +// @Override +// public void setDipperAstPosAsyncTaskService(IDipperAstPosAsyncTaskService dipperAstPosAsyncTaskService) { +// this.dipperAstPosAsyncTaskService = dipperAstPosAsyncTaskService; +// } private String centerProvince; private String centerProvinceFilePath; @@ -149,15 +155,16 @@ public class DipperAstPosAsyncTaskServiceImpl implements IDipperAstPosAsyncTaskS */ @Override @Async("asyncServiceExecutor") - public String pushAstPos(String ipAddress, - String centerProvinceFilePath, - String centerProvince, - String ipPositionRequestPath, - String ipPositionRequestKey) throws UnsupportedEncodingException { - this.ipPositionRequestKey = ipPositionRequestKey; - this.ipPositionRequestPath = ipPositionRequestPath; - this.centerProvince = centerProvince; - this.centerProvinceFilePath = centerProvinceFilePath; +// public String pushAstPos(String ipAddress, +// String centerProvinceFilePath, +// String centerProvince, +// String ipPositionRequestPath, +// String ipPositionRequestKey) throws UnsupportedEncodingException { + public String pushAstPos(String ipAddress) { + this.ipPositionRequestKey = positionConfig.getIpPositionRequestKey(); + this.ipPositionRequestPath = positionConfig.getIpPositionRequestPath(); + this.centerProvince = positionConfig.getCenterProvince(); + this.centerProvinceFilePath = positionConfig.getCenterProvinceFilePath(); // (1) 获取省会城市信息 String centerAddress = getIpPositionProvince(ipAddress); if (ObjectUtils.isEmpty(centerAddress) || centerAddress.equals("0")) { diff --git a/src/main/java/com/telpo/dipperposition/service/impl/DipperAstTimeAsyncTaskServiceImpl.java b/src/main/java/com/telpo/dipperposition/service/impl/DipperAstTimeAsyncTaskServiceImpl.java index 964d01b..eebb377 100644 --- a/src/main/java/com/telpo/dipperposition/service/impl/DipperAstTimeAsyncTaskServiceImpl.java +++ b/src/main/java/com/telpo/dipperposition/service/impl/DipperAstTimeAsyncTaskServiceImpl.java @@ -21,16 +21,16 @@ import java.time.LocalDateTime; @Service @Slf4j public class DipperAstTimeAsyncTaskServiceImpl implements IDipperAstTimeAsyncTaskService { - - private static IDipperAstTimeAsyncTaskService dipperAstTimeAsyncTaskService; - /** - * spring会自动从ioc容器当中根据IDipperAstTimeAsyncTaskService类型找到dipperAstTimeAsyncTaskService,当做参数传进来 - * - */ - @Override - public void setDipperAstTimeAsyncTaskService(IDipperAstTimeAsyncTaskService dipperAstTimeAsyncTaskService) { - this.dipperAstTimeAsyncTaskService = dipperAstTimeAsyncTaskService; - } +// +// private static IDipperAstTimeAsyncTaskService dipperAstTimeAsyncTaskService; +// /** +// * spring会自动从ioc容器当中根据IDipperAstTimeAsyncTaskService类型找到dipperAstTimeAsyncTaskService,当做参数传进来 +// * +// */ +// @Override +// public void setDipperAstTimeAsyncTaskService(IDipperAstTimeAsyncTaskService dipperAstTimeAsyncTaskService) { +// this.dipperAstTimeAsyncTaskService = dipperAstTimeAsyncTaskService; +// } @Override @Async("asyncServiceExecutor") diff --git a/src/main/java/com/telpo/dipperposition/service/impl/DipperDataAsyncTaskServiceImpl.java b/src/main/java/com/telpo/dipperposition/service/impl/DipperDataAsyncTaskServiceImpl.java index 61f55db..5ccce12 100644 --- a/src/main/java/com/telpo/dipperposition/service/impl/DipperDataAsyncTaskServiceImpl.java +++ b/src/main/java/com/telpo/dipperposition/service/impl/DipperDataAsyncTaskServiceImpl.java @@ -31,15 +31,15 @@ public class DipperDataAsyncTaskServiceImpl implements IDipperDataAsyncTaskServi private SchedulingExecutorConfig schedulingExecutorConfig; - private static IDipperDataAsyncTaskService dipperDataAsyncTaskService; - /** - * spring会自动从ioc容器当中根据IDipperAstTimeAsyncTaskService类型找到dipperDataAsyncTaskService,当做参数传进来 - * - */ - @Override - public void setDipperDataAsyncTaskService(IDipperDataAsyncTaskService dipperDataAsyncTaskService) { - this.dipperDataAsyncTaskService = dipperDataAsyncTaskService; - } +// private static IDipperDataAsyncTaskService dipperDataAsyncTaskService; +// /** +// * spring会自动从ioc容器当中根据IDipperAstTimeAsyncTaskService类型找到dipperDataAsyncTaskService,当做参数传进来 +// * +// */ +// @Override +// public void setDipperDataAsyncTaskService(IDipperDataAsyncTaskService dipperDataAsyncTaskService) { +// this.dipperDataAsyncTaskService = dipperDataAsyncTaskService; +// } @Override public void pullAstEPH() { @@ -51,6 +51,7 @@ public class DipperDataAsyncTaskServiceImpl implements IDipperDataAsyncTaskServi log.error("获取星历数据错误,取不到星历数据。"); } else { // 保存到DB或者缓存 + log.info("保存到DB或者缓存"); redisUtil.set(DIPPER_DATA_KEY,dipperData); } } @@ -73,7 +74,7 @@ public class DipperDataAsyncTaskServiceImpl implements IDipperDataAsyncTaskServi } @Override - @Async("asyncServiceExecutor") + //@Async("asyncServiceExecutor") public String getAstEPH(){ return (String)redisUtil.get(DIPPER_DATA_KEY); } diff --git a/src/main/java/com/telpo/dipperposition/service/impl/IpProvinceServiceImpl.java b/src/main/java/com/telpo/dipperposition/service/impl/IpProvinceServiceImpl.java index ab282df..24c54cc 100644 --- a/src/main/java/com/telpo/dipperposition/service/impl/IpProvinceServiceImpl.java +++ b/src/main/java/com/telpo/dipperposition/service/impl/IpProvinceServiceImpl.java @@ -23,15 +23,15 @@ public class IpProvinceServiceImpl implements IpProvinceService { @Autowired private IpProvinceMapper ipProvinceMapper; - private static IpProvinceService ipProvinceService; - /** - * spring会自动从ioc容器当中根据IPProvinceService类型找到ipProvinceService,当做参数传进来 - * - */ - @Override - public void setIPProvinceService(IpProvinceService ipProvinceService) { - this.ipProvinceService = ipProvinceService; - } +// private static IpProvinceService ipProvinceService; +// /** +// * spring会自动从ioc容器当中根据IPProvinceService类型找到ipProvinceService,当做参数传进来 +// * +// */ +// @Override +// public void setIPProvinceService(IpProvinceService ipProvinceService) { +// this.ipProvinceService = ipProvinceService; +// } @Override public boolean saveIpProvince(IpProvinceEntity entity) { ipProvinceMapper.saveIp(entity); From dd1a7f488a2f1eba18c3c2073ff535f102a61088 Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Tue, 19 Jan 2021 08:32:45 +0800 Subject: [PATCH 114/172] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=88=B0docker?= =?UTF-8?q?=E5=A4=96=E8=BF=90=E8=A1=8C=E7=8E=AF=E5=A2=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/DipperDataAsyncTaskController.java | 5 +++-- .../java/com/telpo/dipperposition/task/ScheduleService.java | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/telpo/dipperposition/controller/DipperDataAsyncTaskController.java b/src/main/java/com/telpo/dipperposition/controller/DipperDataAsyncTaskController.java index 786a9c8..7e674df 100644 --- a/src/main/java/com/telpo/dipperposition/controller/DipperDataAsyncTaskController.java +++ b/src/main/java/com/telpo/dipperposition/controller/DipperDataAsyncTaskController.java @@ -18,7 +18,7 @@ import org.springframework.web.bind.annotation.RestController; @Slf4j public class DipperDataAsyncTaskController { @Value(value = "${position-server.serverAddr}") - private String hello; + private String serverAddr; //RzlAccount rzlAccount; @Autowired @@ -35,13 +35,14 @@ public class DipperDataAsyncTaskController { * 获取星历数据 */ public String getAstEPH() { + log.info("DipperDataAsyncTaskController serverAddr = " + serverAddr); return dipperDataAsyncTaskService.getAstEPH(); } @RequestMapping("/getPos") public String getPos() { - return "return serverAddr = " + hello; + return "return serverAddr = " + serverAddr; } } diff --git a/src/main/java/com/telpo/dipperposition/task/ScheduleService.java b/src/main/java/com/telpo/dipperposition/task/ScheduleService.java index 885a633..03e3315 100644 --- a/src/main/java/com/telpo/dipperposition/task/ScheduleService.java +++ b/src/main/java/com/telpo/dipperposition/task/ScheduleService.java @@ -1,5 +1,6 @@ package com.telpo.dipperposition.task; +import com.telpo.dipperposition.controller.DipperDataAsyncTaskController; import com.telpo.dipperposition.service.IDipperDataAsyncTaskService; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; @@ -19,7 +20,7 @@ import org.springframework.stereotype.Component; public class ScheduleService { @Autowired - private IDipperDataAsyncTaskService dipperDataAsyncTaskService; + private DipperDataAsyncTaskController dipperDataAsyncTaskController; /* * 调用9012端口的接口获取星历数据。 @@ -32,7 +33,7 @@ public class ScheduleService { log.info("开始星历数据同步!"); // 获取推送失败的记录 try { - dipperDataAsyncTaskService.pullAstEPH(); + dipperDataAsyncTaskController.pullAstEPH(); } catch (Exception e) { log.error("执行定时获取星历数据发生异常:", e); } From 49ebcb1f8519644b0eb781c51138b8e1057da16f Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Tue, 19 Jan 2021 08:58:41 +0800 Subject: [PATCH 115/172] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=88=B0docker?= =?UTF-8?q?=E5=A4=96=E8=BF=90=E8=A1=8C=E7=8E=AF=E5=A2=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DipperPositionApplication.java | 3 +- .../DipperAstPosAsyncTaskController.java | 7 ++ .../DipperAstTimeAsyncTaskController.java | 7 ++ .../DipperDataAsyncTaskController.java | 7 ++ .../server/DipperPositionServer.java | 104 +----------------- 5 files changed, 26 insertions(+), 102 deletions(-) diff --git a/src/main/java/com/telpo/dipperposition/DipperPositionApplication.java b/src/main/java/com/telpo/dipperposition/DipperPositionApplication.java index 8d61985..038fef7 100644 --- a/src/main/java/com/telpo/dipperposition/DipperPositionApplication.java +++ b/src/main/java/com/telpo/dipperposition/DipperPositionApplication.java @@ -33,8 +33,7 @@ public class DipperPositionApplication { log.info("北斗定位服务启动!"); //启动服务端 ConfigurableEnvironment environment = applicationContext.getEnvironment(); -// TimeAsyncServer timeAsyncServer = new TimeAsyncServer(environment); -// timeAsyncServer.start(); + DipperPositionServer nettyServer = new DipperPositionServer(environment); nettyServer.start(); } catch (Exception e) { diff --git a/src/main/java/com/telpo/dipperposition/controller/DipperAstPosAsyncTaskController.java b/src/main/java/com/telpo/dipperposition/controller/DipperAstPosAsyncTaskController.java index 78dca24..56368eb 100644 --- a/src/main/java/com/telpo/dipperposition/controller/DipperAstPosAsyncTaskController.java +++ b/src/main/java/com/telpo/dipperposition/controller/DipperAstPosAsyncTaskController.java @@ -6,6 +6,8 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.RestController; +import javax.annotation.PostConstruct; + /** * @program: DipperAstPosAsyncTaskController @@ -20,6 +22,11 @@ public class DipperAstPosAsyncTaskController { @Autowired IDipperAstPosAsyncTaskService dipperAstPosAsyncTaskService; + private DipperAstPosAsyncTaskController dipperAstPosAsyncTaskController; + @PostConstruct + public void init() { + dipperAstPosAsyncTaskController = this; + } /* * 拉取星历数据 */ diff --git a/src/main/java/com/telpo/dipperposition/controller/DipperAstTimeAsyncTaskController.java b/src/main/java/com/telpo/dipperposition/controller/DipperAstTimeAsyncTaskController.java index 265e5ee..6d51e7b 100644 --- a/src/main/java/com/telpo/dipperposition/controller/DipperAstTimeAsyncTaskController.java +++ b/src/main/java/com/telpo/dipperposition/controller/DipperAstTimeAsyncTaskController.java @@ -8,6 +8,8 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import javax.annotation.PostConstruct; + /** * @program: DipperPositionController @@ -22,6 +24,11 @@ public class DipperAstTimeAsyncTaskController { @Autowired IDipperAstTimeAsyncTaskService dipperTimeAsyncTaskService; + private DipperAstTimeAsyncTaskController dipperTimeAsyncTaskController; + @PostConstruct + public void init() { + dipperTimeAsyncTaskController = this; + } /* * 拉取星历数据 */ diff --git a/src/main/java/com/telpo/dipperposition/controller/DipperDataAsyncTaskController.java b/src/main/java/com/telpo/dipperposition/controller/DipperDataAsyncTaskController.java index 7e674df..c0e2733 100644 --- a/src/main/java/com/telpo/dipperposition/controller/DipperDataAsyncTaskController.java +++ b/src/main/java/com/telpo/dipperposition/controller/DipperDataAsyncTaskController.java @@ -7,6 +7,8 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import javax.annotation.PostConstruct; + /** * @program: DipperPositionController @@ -24,6 +26,11 @@ public class DipperDataAsyncTaskController { @Autowired IDipperDataAsyncTaskService dipperDataAsyncTaskService; + private DipperDataAsyncTaskController dipperDataAsyncTaskController; + @PostConstruct + public void init() { + dipperDataAsyncTaskController = this; + } /* * 拉取星历数据 */ diff --git a/src/main/java/com/telpo/dipperposition/server/DipperPositionServer.java b/src/main/java/com/telpo/dipperposition/server/DipperPositionServer.java index 0055fc2..634dd69 100644 --- a/src/main/java/com/telpo/dipperposition/server/DipperPositionServer.java +++ b/src/main/java/com/telpo/dipperposition/server/DipperPositionServer.java @@ -26,48 +26,14 @@ import java.net.InetSocketAddress; @Slf4j public class DipperPositionServer { - // @Autowired PositionConfigInfo positionConfigInfo; private String serverAddr; - private Integer serverPort; - private Integer timeAsycPort; - private Integer posAsycPort; private Integer starsAsycPort; public DipperPositionServer(ConfigurableEnvironment environment) throws NacosException { this.serverAddr = environment.getProperty("position-server.serverAddr"); - this.serverPort = Integer.parseInt(environment.getProperty("server.port")); - this.timeAsycPort = Integer.parseInt(environment.getProperty("position-server.timeAsycPort")); - this.posAsycPort = Integer.parseInt(environment.getProperty("position-server.posAsycPort")); + this.starsAsycPort = Integer.parseInt(environment.getProperty("position-server.starsAsycPort")); - //String serverAddr = positionConfigInfo.getServerAddr(); -// try { -// try { -// InetAddress ip4 = Inet4Address.getLocalHost(); -// serverAddr = ip4.getHostAddress(); -// } catch (Exception ex) { -// serverAddr = "172.16.192.26"; -// ex.printStackTrace(); -// } -// String dataId = "dipperposition-service"; -// String group = "DEFAULT_GROUP"; -// Properties properties = new Properties(); -// properties.put(PropertyKeyConst.SERVER_ADDR, serverAddr); -// ConfigService configService = NacosFactory.createConfigService(properties); -// String content = configService.getConfig(dataId, group, 5000); -// -// ByteArrayInputStream tInputStringStream = new ByteArrayInputStream(content.getBytes()); -// Yaml yaml = new Yaml(); -// Map m1 = yaml.load(tInputStringStream); -// Map m2 = (Map) m1.get("position-server"); -// this.serverAddr = (String)m2.get("serverAddr"); -// this.timeAsycPort = (Integer)m2.get("timeAsycPort"); -// this.posAsycPort = (Integer)m2.get("posAsycPort"); -// this.starsAsycPort = (Integer)m2.get("starsAsycPort"); -// log.info("Map server is:" + m2.get("serverAddr")); -// } catch (Exception ex) { -// ex.printStackTrace(); -// } } /* @@ -79,12 +45,12 @@ public class DipperPositionServer { EventLoopGroup mainThreadGroup = new NioEventLoopGroup(1); //new 一个工作线程组 EventLoopGroup workThreadGroup = new NioEventLoopGroup(200); - //InetSocketAddress socketAddress = new InetSocketAddress(serverAddr,9011); + InetSocketAddress socketAddress = new InetSocketAddress(serverAddr,starsAsycPort); ServerBootstrap bootstrap = new ServerBootstrap() .group(mainThreadGroup, workThreadGroup) .channel(NioServerSocketChannel.class) .childHandler(new ServerChannelInitializer()) - // .localAddress(socketAddress) + .localAddress(socketAddress) //设置队列大小 .option(ChannelOption.SO_BACKLOG, 1024) // 两小时内没有数据的通信时,TCP会自动发送一个活动探测数据报文 @@ -93,30 +59,8 @@ public class DipperPositionServer { //绑定端口,开始接收进来的连接 try { -// ChannelFuture channelFuture = bootstrap.bind(timeAsycPort).sync(); -// log.info("时间辅助服务器启动开始监听端口: {}", timeAsycPort); -// channelFuture.addListener(future -> { -// if (future.isSuccess()){ -// System.out.println("start success"); -// }else{ -// System.out.println("start failed"); -// } -// }); -// channelFuture.channel().closeFuture().sync(); -// -// ChannelFuture channelFuture2 = bootstrap.bind(posAsycPort).sync(); -// log.info("位置服务器启动开始监听端口: {}", posAsycPort); -// channelFuture2.addListener(future -> { -// if (future.isSuccess()){ -// System.out.println("start success"); -// }else{ -// System.out.println("start failed"); -// } -// }); -// channelFuture2.channel().closeFuture().sync(); -// - ChannelFuture channelFuture3 = bootstrap.bind(starsAsycPort).sync(); + ChannelFuture channelFuture3 = bootstrap.bind(socketAddress).sync(); log.info("星历服务器启动开始监听端口: {}", starsAsycPort); channelFuture3.addListener(future -> { if (future.isSuccess()){ @@ -136,44 +80,4 @@ public class DipperPositionServer { } } - public void start2() { - - //new 一个主线程组 - EventLoopGroup mainThreadGroup = new NioEventLoopGroup(1); - //new 一个工作线程组 - EventLoopGroup workThreadGroup = new NioEventLoopGroup(200); - //InetSocketAddress socketAddress = new InetSocketAddress(serverAddr,null); - ServerBootstrap bootstrap = new ServerBootstrap() - .group(mainThreadGroup, workThreadGroup) - .channel(NioServerSocketChannel.class) - .childHandler(new ServerChannelInitializer()) - //.localAddress(socketAddress) - //设置队列大小 - .option(ChannelOption.SO_BACKLOG, 1024) - // 两小时内没有数据的通信时,TCP会自动发送一个活动探测数据报文 - .childOption(ChannelOption.SO_KEEPALIVE, true); - - - //绑定端口,开始接收进来的连接 - try { - ChannelFuture channelFuture = bootstrap.bind(timeAsycPort).sync(); - log.info("时间辅助服务器启动开始监听端口: {}", timeAsycPort); - channelFuture.addListener(future -> { - if (future.isSuccess()){ - System.out.println("start success"); - }else{ - System.out.println("start failed"); - } - }); - - channelFuture.channel().closeFuture().sync(); - } catch (InterruptedException e) { - e.printStackTrace(); - } finally { - //关闭主线程组 - mainThreadGroup.shutdownGracefully(); - //关闭工作线程组 - workThreadGroup.shutdownGracefully(); - } - } } From bb906f807086b7edacea98918d8e38b0f89fc2ce Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Tue, 19 Jan 2021 09:21:20 +0800 Subject: [PATCH 116/172] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=88=B0docker?= =?UTF-8?q?=E5=A4=96=E8=BF=90=E8=A1=8C=E7=8E=AF=E5=A2=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/DipperAstPosAsyncTaskController.java | 10 +++++----- .../controller/DipperAstTimeAsyncTaskController.java | 10 +++++----- .../controller/DipperDataAsyncTaskController.java | 10 +++++----- .../dipperposition/handler/NettyServerHandler.java | 11 +++++------ 4 files changed, 20 insertions(+), 21 deletions(-) diff --git a/src/main/java/com/telpo/dipperposition/controller/DipperAstPosAsyncTaskController.java b/src/main/java/com/telpo/dipperposition/controller/DipperAstPosAsyncTaskController.java index 56368eb..19588a8 100644 --- a/src/main/java/com/telpo/dipperposition/controller/DipperAstPosAsyncTaskController.java +++ b/src/main/java/com/telpo/dipperposition/controller/DipperAstPosAsyncTaskController.java @@ -22,11 +22,11 @@ public class DipperAstPosAsyncTaskController { @Autowired IDipperAstPosAsyncTaskService dipperAstPosAsyncTaskService; - private DipperAstPosAsyncTaskController dipperAstPosAsyncTaskController; - @PostConstruct - public void init() { - dipperAstPosAsyncTaskController = this; - } +// private DipperAstPosAsyncTaskController dipperAstPosAsyncTaskController; +// @PostConstruct +// public void init() { +// dipperAstPosAsyncTaskController = this; +// } /* * 拉取星历数据 */ diff --git a/src/main/java/com/telpo/dipperposition/controller/DipperAstTimeAsyncTaskController.java b/src/main/java/com/telpo/dipperposition/controller/DipperAstTimeAsyncTaskController.java index 6d51e7b..8fbfc61 100644 --- a/src/main/java/com/telpo/dipperposition/controller/DipperAstTimeAsyncTaskController.java +++ b/src/main/java/com/telpo/dipperposition/controller/DipperAstTimeAsyncTaskController.java @@ -24,11 +24,11 @@ public class DipperAstTimeAsyncTaskController { @Autowired IDipperAstTimeAsyncTaskService dipperTimeAsyncTaskService; - private DipperAstTimeAsyncTaskController dipperTimeAsyncTaskController; - @PostConstruct - public void init() { - dipperTimeAsyncTaskController = this; - } +// private DipperAstTimeAsyncTaskController dipperTimeAsyncTaskController; +// @PostConstruct +// public void init() { +// dipperTimeAsyncTaskController = this; +// } /* * 拉取星历数据 */ diff --git a/src/main/java/com/telpo/dipperposition/controller/DipperDataAsyncTaskController.java b/src/main/java/com/telpo/dipperposition/controller/DipperDataAsyncTaskController.java index c0e2733..70b1032 100644 --- a/src/main/java/com/telpo/dipperposition/controller/DipperDataAsyncTaskController.java +++ b/src/main/java/com/telpo/dipperposition/controller/DipperDataAsyncTaskController.java @@ -26,11 +26,11 @@ public class DipperDataAsyncTaskController { @Autowired IDipperDataAsyncTaskService dipperDataAsyncTaskService; - private DipperDataAsyncTaskController dipperDataAsyncTaskController; - @PostConstruct - public void init() { - dipperDataAsyncTaskController = this; - } +// private DipperDataAsyncTaskController dipperDataAsyncTaskController; +// @PostConstruct +// public void init() { +// dipperDataAsyncTaskController = this; +// } /* * 拉取星历数据 */ diff --git a/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java b/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java index 651adad..28f23a4 100644 --- a/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java +++ b/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java @@ -40,12 +40,11 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter { private static String AST_POS_CMD_BYTE = "504f53"; private static String AST_EPH_CMD_BYTE = "455048"; - @Autowired - private DipperAstTimeAsyncTaskController dipperTimeAsyncTaskController; - @Autowired - private DipperAstPosAsyncTaskController dipperAstPosAsyncTaskController; - @Autowired - private DipperDataAsyncTaskController dipperDataAsyncTaskController; + private DipperAstTimeAsyncTaskController dipperTimeAsyncTaskController = new DipperAstTimeAsyncTaskController(); + + private DipperAstPosAsyncTaskController dipperAstPosAsyncTaskController = new DipperAstPosAsyncTaskController(); + + private DipperDataAsyncTaskController dipperDataAsyncTaskController = new DipperDataAsyncTaskController(); @Autowired private NettyServerConfig nettyServerConfig; From 69b6671569ab1a5feaceaa234db3627c6061c405 Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Tue, 19 Jan 2021 09:27:27 +0800 Subject: [PATCH 117/172] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=88=B0docker?= =?UTF-8?q?=E5=A4=96=E8=BF=90=E8=A1=8C=E7=8E=AF=E5=A2=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DipperDataAsyncTaskController.java | 16 ++++++++-------- .../handler/NettyServerHandler.java | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/telpo/dipperposition/controller/DipperDataAsyncTaskController.java b/src/main/java/com/telpo/dipperposition/controller/DipperDataAsyncTaskController.java index 70b1032..fbf8b6a 100644 --- a/src/main/java/com/telpo/dipperposition/controller/DipperDataAsyncTaskController.java +++ b/src/main/java/com/telpo/dipperposition/controller/DipperDataAsyncTaskController.java @@ -37,14 +37,14 @@ public class DipperDataAsyncTaskController { public void pullAstEPH() { dipperDataAsyncTaskService.pullAstEPH(); } - - /* - * 获取星历数据 - */ - public String getAstEPH() { - log.info("DipperDataAsyncTaskController serverAddr = " + serverAddr); - return dipperDataAsyncTaskService.getAstEPH(); - } +// +// /* +// * 获取星历数据 +// */ +// public String getAstEPH() { +// log.info("DipperDataAsyncTaskController serverAddr = " + serverAddr); +// return dipperDataAsyncTaskService.getAstEPH(); +// } @RequestMapping("/getPos") diff --git a/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java b/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java index 28f23a4..7895106 100644 --- a/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java +++ b/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java @@ -156,7 +156,7 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter { // if (dipperDataAsyncTaskService == null) { // dipperDataAsyncTaskService = new DipperDataAsyncTaskServiceImpl(); // } - channelAns = dipperDataAsyncTaskController.getAstEPH(); + // channelAns = dipperDataAsyncTaskController.getAstEPH(); } log.info(channelAns); From 64460a0f201234d1954acea9b6e90751ecff1030 Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Tue, 19 Jan 2021 09:49:57 +0800 Subject: [PATCH 118/172] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=88=B0docker?= =?UTF-8?q?=E5=A4=96=E8=BF=90=E8=A1=8C=E7=8E=AF=E5=A2=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dipperposition/handler/NettyServerHandler.java | 14 ++++++++------ .../server/DipperPositionServer.java | 6 ++++++ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java b/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java index 7895106..103e7c7 100644 --- a/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java +++ b/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java @@ -20,6 +20,7 @@ import io.netty.channel.ChannelInboundHandlerAdapter; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; import java.io.InputStream; import java.time.LocalDateTime; @@ -31,6 +32,7 @@ import java.time.LocalDateTime; * @create: 2021-01-13 13:56 **/ @Slf4j +@Component public class NettyServerHandler extends ChannelInboundHandlerAdapter { private static String AST_TIME_CMD = "TIME"; @@ -40,11 +42,11 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter { private static String AST_POS_CMD_BYTE = "504f53"; private static String AST_EPH_CMD_BYTE = "455048"; - private DipperAstTimeAsyncTaskController dipperTimeAsyncTaskController = new DipperAstTimeAsyncTaskController(); + private IDipperAstTimeAsyncTaskService dipperTimeAsyncTaskService; - private DipperAstPosAsyncTaskController dipperAstPosAsyncTaskController = new DipperAstPosAsyncTaskController(); + private IDipperAstPosAsyncTaskService dipperAstPosAsyncTaskService; - private DipperDataAsyncTaskController dipperDataAsyncTaskController = new DipperDataAsyncTaskController(); + private IDipperDataAsyncTaskService dipperDataAsyncTaskService; @Autowired private NettyServerConfig nettyServerConfig; @@ -119,7 +121,7 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter { // if (dipperTimeAsyncTaskService == null) { // dipperTimeAsyncTaskService = new DipperAstTimeAsyncTaskServiceImpl(); // } - channelAns = dipperTimeAsyncTaskController.pushAstTime(); + channelAns = dipperTimeAsyncTaskService.pushAstTime(); } // 发送SDBP-AST-POS获取辅助位置信息 @@ -141,7 +143,7 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter { // if (dipperAstPosAsyncTaskService == null) { // dipperAstPosAsyncTaskService = new DipperAstPosAsyncTaskServiceImpl(); // } - channelAns = dipperAstPosAsyncTaskController.pushAstPos(ipAddress); + channelAns = dipperAstPosAsyncTaskService.pushAstPos(ipAddress); // (ipAddress, // "/csv/provinceLonAlt.csv", // "湖北省", @@ -156,7 +158,7 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter { // if (dipperDataAsyncTaskService == null) { // dipperDataAsyncTaskService = new DipperDataAsyncTaskServiceImpl(); // } - // channelAns = dipperDataAsyncTaskController.getAstEPH(); + channelAns = dipperDataAsyncTaskService.getAstEPH(); } log.info(channelAns); diff --git a/src/main/java/com/telpo/dipperposition/server/DipperPositionServer.java b/src/main/java/com/telpo/dipperposition/server/DipperPositionServer.java index 634dd69..edcf67f 100644 --- a/src/main/java/com/telpo/dipperposition/server/DipperPositionServer.java +++ b/src/main/java/com/telpo/dipperposition/server/DipperPositionServer.java @@ -13,7 +13,9 @@ import io.netty.channel.EventLoopGroup; import io.netty.channel.nio.NioEventLoopGroup; import io.netty.channel.socket.nio.NioServerSocketChannel; import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Value; import org.springframework.core.env.ConfigurableEnvironment; +import org.springframework.stereotype.Component; import java.net.InetSocketAddress; @@ -24,8 +26,11 @@ import java.net.InetSocketAddress; * @create: 2021-01-13 14:01 */ @Slf4j +@Component public class DipperPositionServer { + @Value("position-server.serverAddr") + private String myServerAddr; private String serverAddr; private Integer starsAsycPort; @@ -62,6 +67,7 @@ public class DipperPositionServer { ChannelFuture channelFuture3 = bootstrap.bind(socketAddress).sync(); log.info("星历服务器启动开始监听端口: {}", starsAsycPort); + log.info("服务器: {}", myServerAddr); channelFuture3.addListener(future -> { if (future.isSuccess()){ System.out.println("start success"); From 4d006ec8b5bf8a4e93de991bdbb25dbe8271c69a Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Tue, 19 Jan 2021 09:56:20 +0800 Subject: [PATCH 119/172] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=88=B0docker?= =?UTF-8?q?=E5=A4=96=E8=BF=90=E8=A1=8C=E7=8E=AF=E5=A2=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/telpo/dipperposition/handler/NettyServerHandler.java | 3 +++ .../telpo/dipperposition/server/DipperPositionServer.java | 5 ++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java b/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java index 103e7c7..519e1d1 100644 --- a/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java +++ b/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java @@ -42,10 +42,13 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter { private static String AST_POS_CMD_BYTE = "504f53"; private static String AST_EPH_CMD_BYTE = "455048"; + @Autowired private IDipperAstTimeAsyncTaskService dipperTimeAsyncTaskService; + @Autowired private IDipperAstPosAsyncTaskService dipperAstPosAsyncTaskService; + @Autowired private IDipperDataAsyncTaskService dipperDataAsyncTaskService; @Autowired diff --git a/src/main/java/com/telpo/dipperposition/server/DipperPositionServer.java b/src/main/java/com/telpo/dipperposition/server/DipperPositionServer.java index edcf67f..54dc4ec 100644 --- a/src/main/java/com/telpo/dipperposition/server/DipperPositionServer.java +++ b/src/main/java/com/telpo/dipperposition/server/DipperPositionServer.java @@ -3,7 +3,9 @@ package com.telpo.dipperposition.server; import com.alibaba.nacos.api.NacosFactory; import com.alibaba.nacos.api.PropertyKeyConst; import com.alibaba.nacos.api.config.ConfigService; +import com.alibaba.nacos.api.config.annotation.NacosValue; import com.alibaba.nacos.api.exception.NacosException; +import com.alibaba.nacos.spring.context.annotation.config.NacosPropertySource; import com.telpo.dipperposition.co.PositionConfigInfo; import com.telpo.dipperposition.handler.ServerChannelInitializer; import io.netty.bootstrap.ServerBootstrap; @@ -27,9 +29,10 @@ import java.net.InetSocketAddress; */ @Slf4j @Component +@NacosPropertySource(dataId="dipperposition-service", autoRefreshed=true) public class DipperPositionServer { - @Value("position-server.serverAddr") + @NacosValue("position-server.serverAddr") private String myServerAddr; private String serverAddr; private Integer starsAsycPort; From aa9533018aeffa7f704e2b4d14daa9c5d661f40f Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Tue, 19 Jan 2021 10:14:29 +0800 Subject: [PATCH 120/172] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=88=B0docker?= =?UTF-8?q?=E5=A4=96=E8=BF=90=E8=A1=8C=E7=8E=AF=E5=A2=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../handler/NettyServerHandler.java | 24 +++++++++++++------ 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java b/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java index 519e1d1..3f60e52 100644 --- a/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java +++ b/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java @@ -22,6 +22,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; +import javax.annotation.PostConstruct; import java.io.InputStream; import java.time.LocalDateTime; @@ -42,6 +43,8 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter { private static String AST_POS_CMD_BYTE = "504f53"; private static String AST_EPH_CMD_BYTE = "455048"; + @Autowired + private PositionConfig positionConfig; @Autowired private IDipperAstTimeAsyncTaskService dipperTimeAsyncTaskService; @@ -51,10 +54,17 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter { @Autowired private IDipperDataAsyncTaskService dipperDataAsyncTaskService; - @Autowired - private NettyServerConfig nettyServerConfig; - @Autowired - private PositionConfig positionConfig; + private static NettyServerHandler nettyServerHandler; + + @PostConstruct + public void init() { + nettyServerHandler = this; + nettyServerHandler.positionConfig = this.positionConfig; + nettyServerHandler.dipperTimeAsyncTaskService = this.dipperTimeAsyncTaskService; + nettyServerHandler.dipperAstPosAsyncTaskService = this.dipperAstPosAsyncTaskService; + nettyServerHandler.dipperDataAsyncTaskService = this.dipperDataAsyncTaskService; + } + /** * 客户端连接会触发 */ @@ -124,7 +134,7 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter { // if (dipperTimeAsyncTaskService == null) { // dipperTimeAsyncTaskService = new DipperAstTimeAsyncTaskServiceImpl(); // } - channelAns = dipperTimeAsyncTaskService.pushAstTime(); + channelAns = nettyServerHandler.dipperTimeAsyncTaskService.pushAstTime(); } // 发送SDBP-AST-POS获取辅助位置信息 @@ -146,7 +156,7 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter { // if (dipperAstPosAsyncTaskService == null) { // dipperAstPosAsyncTaskService = new DipperAstPosAsyncTaskServiceImpl(); // } - channelAns = dipperAstPosAsyncTaskService.pushAstPos(ipAddress); + channelAns = nettyServerHandler.dipperAstPosAsyncTaskService.pushAstPos(ipAddress); // (ipAddress, // "/csv/provinceLonAlt.csv", // "湖北省", @@ -161,7 +171,7 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter { // if (dipperDataAsyncTaskService == null) { // dipperDataAsyncTaskService = new DipperDataAsyncTaskServiceImpl(); // } - channelAns = dipperDataAsyncTaskService.getAstEPH(); + channelAns = nettyServerHandler.dipperDataAsyncTaskService.getAstEPH(); } log.info(channelAns); From 20513c1de1098584132c9f60a84b03e194435a78 Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Tue, 19 Jan 2021 10:28:50 +0800 Subject: [PATCH 121/172] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=88=B0docker?= =?UTF-8?q?=E5=A4=96=E8=BF=90=E8=A1=8C=E7=8E=AF=E5=A2=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../config/NettyServerConfig.java | 12 +++++------ .../dipperposition/config/PositionConfig.java | 12 +++++------ .../handler/NettyServerHandler.java | 21 ++++--------------- 3 files changed, 16 insertions(+), 29 deletions(-) diff --git a/src/main/java/com/telpo/dipperposition/config/NettyServerConfig.java b/src/main/java/com/telpo/dipperposition/config/NettyServerConfig.java index 3c0b6bc..9d203c5 100644 --- a/src/main/java/com/telpo/dipperposition/config/NettyServerConfig.java +++ b/src/main/java/com/telpo/dipperposition/config/NettyServerConfig.java @@ -34,11 +34,11 @@ public class NettyServerConfig { @NacosValue(value = "${position-server.starsAsycPort}") private String starsAsycServerPort; - public static NettyServerConfig nettyServerConfig; - - @PostConstruct - public void init() { - nettyServerConfig = this; - } +// public static NettyServerConfig nettyServerConfig; +// +// @PostConstruct +// public void init() { +// nettyServerConfig = this; +// } } diff --git a/src/main/java/com/telpo/dipperposition/config/PositionConfig.java b/src/main/java/com/telpo/dipperposition/config/PositionConfig.java index 47d8b0a..e126a49 100644 --- a/src/main/java/com/telpo/dipperposition/config/PositionConfig.java +++ b/src/main/java/com/telpo/dipperposition/config/PositionConfig.java @@ -40,10 +40,10 @@ public class PositionConfig { int astTimeout; - public static PositionConfig positionConfig; - - @PostConstruct - public void init() { - positionConfig = this; - } +// public static PositionConfig positionConfig; +// +// @PostConstruct +// public void init() { +// positionConfig = this; +// } } diff --git a/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java b/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java index 3f60e52..e186c48 100644 --- a/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java +++ b/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java @@ -1,17 +1,9 @@ package com.telpo.dipperposition.handler; -import com.telpo.dipperposition.config.NettyServerConfig; import com.telpo.dipperposition.config.PositionConfig; -import com.telpo.dipperposition.controller.DipperAstPosAsyncTaskController; -import com.telpo.dipperposition.controller.DipperAstTimeAsyncTaskController; -import com.telpo.dipperposition.controller.DipperDataAsyncTaskController; -import com.telpo.dipperposition.enums.DipperReturnValue; import com.telpo.dipperposition.service.IDipperAstPosAsyncTaskService; import com.telpo.dipperposition.service.IDipperAstTimeAsyncTaskService; import com.telpo.dipperposition.service.IDipperDataAsyncTaskService; -import com.telpo.dipperposition.service.impl.DipperAstPosAsyncTaskServiceImpl; -import com.telpo.dipperposition.service.impl.DipperAstTimeAsyncTaskServiceImpl; -import com.telpo.dipperposition.service.impl.DipperDataAsyncTaskServiceImpl; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import io.netty.channel.socket.SocketChannel; @@ -19,12 +11,9 @@ import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelInboundHandlerAdapter; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; import javax.annotation.PostConstruct; -import java.io.InputStream; -import java.time.LocalDateTime; /** * @program: dipperposition @@ -55,7 +44,7 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter { private IDipperDataAsyncTaskService dipperDataAsyncTaskService; private static NettyServerHandler nettyServerHandler; - + public NettyServerHandler() {} @PostConstruct public void init() { nettyServerHandler = this; @@ -131,9 +120,6 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter { //if (AST_TIME_CMD.equals(recvmg)) { if (AST_TIME_CMD.equals(msg)) { // 初始时间辅助输入; -// if (dipperTimeAsyncTaskService == null) { -// dipperTimeAsyncTaskService = new DipperAstTimeAsyncTaskServiceImpl(); -// } channelAns = nettyServerHandler.dipperTimeAsyncTaskService.pushAstTime(); } @@ -175,11 +161,12 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter { } log.info(channelAns); - buf = Unpooled.buffer(channelAns.getBytes().length); + if (channelAns != null) { + buf = Unpooled.buffer(channelAns.getBytes().length); + } // 最后把SDBP-AST-TIME、SDBP-AST-POS、SDBP-AST-EPH并包一起发给设备。 // 设备采用16进制获取数据,则代理服务器也是采用16进制返回数据。 // 通知客户端链消息发送成功 - // String str = "服务端收到:" + LocalDateTime.now() + " " + msg + "\r\n"; buf.writeBytes(channelAns.getBytes("GBK")); ctx.writeAndFlush(buf); //ctx.write("你也好哦"); From 2f9b51a26e5112ae4040e5f75617c4d962015775 Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Tue, 19 Jan 2021 10:41:47 +0800 Subject: [PATCH 122/172] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=88=B0docker?= =?UTF-8?q?=E5=A4=96=E8=BF=90=E8=A1=8C=E7=8E=AF=E5=A2=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../handler/NettyServerHandler.java | 18 +++++------- .../DipperAstTimeAsyncTaskServiceImpl.java | 29 +------------------ 2 files changed, 9 insertions(+), 38 deletions(-) diff --git a/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java b/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java index e186c48..791dc2c 100644 --- a/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java +++ b/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java @@ -36,10 +36,8 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter { private PositionConfig positionConfig; @Autowired private IDipperAstTimeAsyncTaskService dipperTimeAsyncTaskService; - @Autowired private IDipperAstPosAsyncTaskService dipperAstPosAsyncTaskService; - @Autowired private IDipperDataAsyncTaskService dipperDataAsyncTaskService; @@ -110,6 +108,12 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter { String ipAddress = channel.remoteAddress().toString(); //String message = " 接收到消息:{0}, 客户端IP:{1}"; log.info("接收到消息:" + msg + ",客户端IP:" + ipAddress); + if (positionConfig != null) { + log.info("config info is : " + positionConfig.getCenterProvinceFilePath() + positionConfig.getCenterProvince() + positionConfig.getIpPositionRequestPath() + + positionConfig.getIpPositionRequestKey()); + } else { + log.info("positionConfig info is null!!!!!!!!!!!!!! "); + } String channelAns = ""; // 返回时间指令 @@ -121,18 +125,12 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter { if (AST_TIME_CMD.equals(msg)) { // 初始时间辅助输入; channelAns = nettyServerHandler.dipperTimeAsyncTaskService.pushAstTime(); + log.info("返回时间:" + channelAns); } - // 发送SDBP-AST-POS获取辅助位置信息 // if (Integer.parseInt(posAsycServerPort) == channel.localAddress().getPort()) { //if (AST_POS_CMD.equals(recvmg)) { - if (positionConfig != null) { - log.info("config info is : " + positionConfig.getCenterProvinceFilePath() + positionConfig.getCenterProvince() + positionConfig.getIpPositionRequestPath() + - positionConfig.getIpPositionRequestKey()); - } else { - log.info("positionConfig info is null!!!!!!!!!!!!!! "); - } if (AST_POS_CMD.equals(msg)) { // channelAns = dipperAstPosAsyncTaskService.pushAstPos(ipAddress, // positionConfig.getCenterProvinceFilePath(), @@ -163,11 +161,11 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter { log.info(channelAns); if (channelAns != null) { buf = Unpooled.buffer(channelAns.getBytes().length); + buf.writeBytes(channelAns.getBytes("GBK")); } // 最后把SDBP-AST-TIME、SDBP-AST-POS、SDBP-AST-EPH并包一起发给设备。 // 设备采用16进制获取数据,则代理服务器也是采用16进制返回数据。 // 通知客户端链消息发送成功 - buf.writeBytes(channelAns.getBytes("GBK")); ctx.writeAndFlush(buf); //ctx.write("你也好哦"); //ctx.flush(); diff --git a/src/main/java/com/telpo/dipperposition/service/impl/DipperAstTimeAsyncTaskServiceImpl.java b/src/main/java/com/telpo/dipperposition/service/impl/DipperAstTimeAsyncTaskServiceImpl.java index eebb377..804b0be 100644 --- a/src/main/java/com/telpo/dipperposition/service/impl/DipperAstTimeAsyncTaskServiceImpl.java +++ b/src/main/java/com/telpo/dipperposition/service/impl/DipperAstTimeAsyncTaskServiceImpl.java @@ -21,35 +21,11 @@ import java.time.LocalDateTime; @Service @Slf4j public class DipperAstTimeAsyncTaskServiceImpl implements IDipperAstTimeAsyncTaskService { -// -// private static IDipperAstTimeAsyncTaskService dipperAstTimeAsyncTaskService; -// /** -// * spring会自动从ioc容器当中根据IDipperAstTimeAsyncTaskService类型找到dipperAstTimeAsyncTaskService,当做参数传进来 -// * -// */ -// @Override -// public void setDipperAstTimeAsyncTaskService(IDipperAstTimeAsyncTaskService dipperAstTimeAsyncTaskService) { -// this.dipperAstTimeAsyncTaskService = dipperAstTimeAsyncTaskService; -// } @Override @Async("asyncServiceExecutor") public String pushAstTime() { - // (1) 发送SDBP-AST-TIME - // String sendResult = pushTimeToDipper(); - //if (sendResult == null) { - // log.error("取不到时间。"); - // return null; - //} - - // (2) 获取时间信息 - return pushTimeToDipper(); - //return sendResult; - } - - private String pushTimeToDipper() { - // 创建Socket客户端实例; // SocketClient client = new SocketClient(astServer, timeAstPort, astTimeout); @@ -107,11 +83,8 @@ public class DipperAstTimeAsyncTaskServiceImpl implements IDipperAstTimeAsyncTas astTimeCmd += "0000000000"; astTimeCmd += "00286BEE"; - //String hexIn = HexConvert.convertStringToHex(astTimeCmd) + HexConvert.makeChecksum(astTimeCmd); String hexIn = astTimeCmd + HexConvert.makeChecksum(astTimeCmd); - //String ackAckCheckRef = "233E0101020004020A1D"; - //String sendResult = client.sendCmd(hexIn, ackAckCheckRef); - //client.closeConnection(); + log.info("返回时间:" + hexIn); return hexIn; } From dfa5a59a434b7598a4b8b956405d46b94e0b91cb Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Tue, 19 Jan 2021 10:47:33 +0800 Subject: [PATCH 123/172] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=88=B0docker?= =?UTF-8?q?=E5=A4=96=E8=BF=90=E8=A1=8C=E7=8E=AF=E5=A2=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dipperposition/common/RedisUtil.java | 10 ++-- .../DipperAstPosAsyncTaskServiceImpl.java | 49 ------------------- .../impl/DipperDataAsyncTaskServiceImpl.java | 12 +---- 3 files changed, 6 insertions(+), 65 deletions(-) diff --git a/src/main/java/com/telpo/dipperposition/common/RedisUtil.java b/src/main/java/com/telpo/dipperposition/common/RedisUtil.java index 33b262a..f1e85eb 100644 --- a/src/main/java/com/telpo/dipperposition/common/RedisUtil.java +++ b/src/main/java/com/telpo/dipperposition/common/RedisUtil.java @@ -25,11 +25,11 @@ public class RedisUtil { @Resource private RedisTemplate redisTemplate; - public static RedisUtil redisUtil; - @PostConstruct - public void init() { - redisUtil = this; - } +// public static RedisUtil redisUtil; +// @PostConstruct +// public void init() { +// redisUtil = this; +// } // =============================common============================ /** * 指定缓存失效时间 diff --git a/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java b/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java index b2e42d8..726a305 100644 --- a/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java +++ b/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java @@ -35,50 +35,14 @@ public class DipperAstPosAsyncTaskServiceImpl implements IDipperAstPosAsyncTaskS @Autowired private OkHttpUtil okHttpUtil; @Autowired - private NettyServerConfig nettyServerConfig; - @Autowired private PositionConfig positionConfig; @Autowired private IpProvinceService ipProvinceService; -// private static IDipperAstPosAsyncTaskService dipperAstPosAsyncTaskService; - /** - * spring会自动从ioc容器当中根据IDipperAstPosAsyncTaskService类型找到dipperAstPosAsyncTaskService,当做参数传进来 - * - */ -// @Override -// public void setDipperAstPosAsyncTaskService(IDipperAstPosAsyncTaskService dipperAstPosAsyncTaskService) { -// this.dipperAstPosAsyncTaskService = dipperAstPosAsyncTaskService; -// } - private String centerProvince; private String centerProvinceFilePath; private String ipPositionRequestPath; private String ipPositionRequestKey; -// private String getAstPos(String ipAddress) throws UnsupportedEncodingException { -// -// String centerAddress = getIpPositionProvince(ipAddress); -// if (ObjectUtils.isEmpty(centerAddress) || centerAddress.equals("0")) { -// log.warn("IP地址非法,无法获取辅助位置信息!"); -// // 返回武汉的定位数据 -// centerAddress = centerProvince; -// } else { -// // 保存到mongoDB -// createIPProvince(ipAddress, centerAddress); -// } -// -// String lonAndAlt; -// if (redisUtil.hasKey(centerAddress)) { -// // 获取省会城市定位信息 -// lonAndAlt= (String) redisUtil.get(centerAddress); -// } else { -// // 请求高德IP定位服务 -// this.getPosFromFile(centerAddress); -// lonAndAlt = (String) redisUtil.get(centerAddress); -// } -// -// return lonAndAlt; -// } // 从CSV文件读取省会城市中心点位置信息 private void getPosFromFile(String centerAddress) { @@ -135,14 +99,9 @@ public class DipperAstPosAsyncTaskServiceImpl implements IDipperAstPosAsyncTaskS try { IpProvinceEntity ipProvinceEntity = ipProvinceService.getIpProvince(ipAddress); if (ipProvinceEntity == null) { - //DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); ipProvinceEntity.setIp(ipAddress); ipProvinceEntity.setProvince(province); ipProvinceService.saveIpProvince(ipProvinceEntity); -// } else { -// -// ipProvinceEntity.setProvince(province); -// iPProvinceService.updateIPProvince(ipProvinceEntity, ipProvinceEntity); } } catch (Exception e) { log.error("创建推送失败记录异常:", e); @@ -155,11 +114,6 @@ public class DipperAstPosAsyncTaskServiceImpl implements IDipperAstPosAsyncTaskS */ @Override @Async("asyncServiceExecutor") -// public String pushAstPos(String ipAddress, -// String centerProvinceFilePath, -// String centerProvince, -// String ipPositionRequestPath, -// String ipPositionRequestKey) throws UnsupportedEncodingException { public String pushAstPos(String ipAddress) { this.ipPositionRequestKey = positionConfig.getIpPositionRequestKey(); this.ipPositionRequestPath = positionConfig.getIpPositionRequestPath(); @@ -202,9 +156,6 @@ public class DipperAstPosAsyncTaskServiceImpl implements IDipperAstPosAsyncTaskS // 组装命令发送给设备 private String getCmdOfPos(String astPos) { - // 创建Socket客户端实例; - // SocketClient client = new SocketClient(astServer, posAstPort, astTimeout); - // 时间和位置不是从服务器获取,而是本地生成 String[] astPosArray = astPos.split(","); String lan = astPosArray[0].trim(); diff --git a/src/main/java/com/telpo/dipperposition/service/impl/DipperDataAsyncTaskServiceImpl.java b/src/main/java/com/telpo/dipperposition/service/impl/DipperDataAsyncTaskServiceImpl.java index 5ccce12..dee9a3e 100644 --- a/src/main/java/com/telpo/dipperposition/service/impl/DipperDataAsyncTaskServiceImpl.java +++ b/src/main/java/com/telpo/dipperposition/service/impl/DipperDataAsyncTaskServiceImpl.java @@ -4,7 +4,6 @@ import com.telpo.dipperposition.common.HexConvert; import com.telpo.dipperposition.common.RedisUtil; import com.telpo.dipperposition.common.SocketClient; import com.telpo.dipperposition.config.SchedulingExecutorConfig; -import com.telpo.dipperposition.service.IDipperAstTimeAsyncTaskService; import com.telpo.dipperposition.service.IDipperDataAsyncTaskService; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; @@ -31,15 +30,6 @@ public class DipperDataAsyncTaskServiceImpl implements IDipperDataAsyncTaskServi private SchedulingExecutorConfig schedulingExecutorConfig; -// private static IDipperDataAsyncTaskService dipperDataAsyncTaskService; -// /** -// * spring会自动从ioc容器当中根据IDipperAstTimeAsyncTaskService类型找到dipperDataAsyncTaskService,当做参数传进来 -// * -// */ -// @Override -// public void setDipperDataAsyncTaskService(IDipperDataAsyncTaskService dipperDataAsyncTaskService) { -// this.dipperDataAsyncTaskService = dipperDataAsyncTaskService; -// } @Override public void pullAstEPH() { @@ -74,7 +64,7 @@ public class DipperDataAsyncTaskServiceImpl implements IDipperDataAsyncTaskServi } @Override - //@Async("asyncServiceExecutor") + @Async("asyncServiceExecutor") public String getAstEPH(){ return (String)redisUtil.get(DIPPER_DATA_KEY); } From 7bbba44863db5aa7ae090014ed950c8decdd3873 Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Tue, 19 Jan 2021 11:31:48 +0800 Subject: [PATCH 124/172] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=88=B0docker?= =?UTF-8?q?=E5=A4=96=E8=BF=90=E8=A1=8C=E7=8E=AF=E5=A2=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DipperPositionApplication.java | 2 +- .../telpo/dipperposition/common/CSVUtil.java | 2 +- .../handler/NettyServerHandler.java | 22 +++---------------- .../DipperAstPosAsyncTaskServiceImpl.java | 3 +++ .../DipperAstTimeAsyncTaskServiceImpl.java | 2 +- 5 files changed, 9 insertions(+), 22 deletions(-) diff --git a/src/main/java/com/telpo/dipperposition/DipperPositionApplication.java b/src/main/java/com/telpo/dipperposition/DipperPositionApplication.java index 038fef7..f25c92d 100644 --- a/src/main/java/com/telpo/dipperposition/DipperPositionApplication.java +++ b/src/main/java/com/telpo/dipperposition/DipperPositionApplication.java @@ -31,9 +31,9 @@ public class DipperPositionApplication { log.info("北斗定位服务开始!"); ConfigurableApplicationContext applicationContext = SpringApplication.run(DipperPositionApplication.class, args); log.info("北斗定位服务启动!"); + log.info(applicationContext.getResource("bootstrap.yaml").getFile().getAbsolutePath()); //启动服务端 ConfigurableEnvironment environment = applicationContext.getEnvironment(); - DipperPositionServer nettyServer = new DipperPositionServer(environment); nettyServer.start(); } catch (Exception e) { diff --git a/src/main/java/com/telpo/dipperposition/common/CSVUtil.java b/src/main/java/com/telpo/dipperposition/common/CSVUtil.java index e6d1ab0..0d840a2 100644 --- a/src/main/java/com/telpo/dipperposition/common/CSVUtil.java +++ b/src/main/java/com/telpo/dipperposition/common/CSVUtil.java @@ -27,7 +27,7 @@ public class CSVUtil { List listData = new ArrayList<>(); try { filePath = readPath; - CsvReader csvReader = new CsvReader(filePath); + CsvReader csvReader = new CsvReader(filePath,',',Charset.forName("UTF-8")); // 读表头 boolean re = csvReader.readHeaders(); while (csvReader.readRecord()) { diff --git a/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java b/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java index 791dc2c..685a7b1 100644 --- a/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java +++ b/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java @@ -108,9 +108,9 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter { String ipAddress = channel.remoteAddress().toString(); //String message = " 接收到消息:{0}, 客户端IP:{1}"; log.info("接收到消息:" + msg + ",客户端IP:" + ipAddress); - if (positionConfig != null) { - log.info("config info is : " + positionConfig.getCenterProvinceFilePath() + positionConfig.getCenterProvince() + positionConfig.getIpPositionRequestPath() + - positionConfig.getIpPositionRequestKey()); + if (nettyServerHandler.positionConfig != null) { + log.info("config info is : " + nettyServerHandler.positionConfig.getCenterProvinceFilePath() + nettyServerHandler.positionConfig.getCenterProvince() + nettyServerHandler.positionConfig.getIpPositionRequestPath() + + nettyServerHandler.positionConfig.getIpPositionRequestKey()); } else { log.info("positionConfig info is null!!!!!!!!!!!!!! "); } @@ -132,29 +132,13 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter { //if (AST_POS_CMD.equals(recvmg)) { if (AST_POS_CMD.equals(msg)) { -// channelAns = dipperAstPosAsyncTaskService.pushAstPos(ipAddress, -// positionConfig.getCenterProvinceFilePath(), -// positionConfig.getCenterProvince(), -// positionConfig.getIpPositionRequestPath(), -// positionConfig.getIpPositionRequestKey()); -// if (dipperAstPosAsyncTaskService == null) { -// dipperAstPosAsyncTaskService = new DipperAstPosAsyncTaskServiceImpl(); -// } channelAns = nettyServerHandler.dipperAstPosAsyncTaskService.pushAstPos(ipAddress); -// (ipAddress, -// "/csv/provinceLonAlt.csv", -// "湖北省", -// "https://restapi.amap.com/v3/ip", -// "65e794b0a1a4b87eeec86f93fea05411"); } // 从缓存获取SDBP-AST-EPH星历数 //if (Integer.parseInt(starsAsycServerPort) == channel.localAddress().getPort()) { //if (AST_POS_CMD.equals(recvmg)) { if (AST_POS_CMD.equals(msg)) { -// if (dipperDataAsyncTaskService == null) { -// dipperDataAsyncTaskService = new DipperDataAsyncTaskServiceImpl(); -// } channelAns = nettyServerHandler.dipperDataAsyncTaskService.getAstEPH(); } diff --git a/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java b/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java index 726a305..c404067 100644 --- a/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java +++ b/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java @@ -9,6 +9,7 @@ import com.telpo.dipperposition.service.IDipperAstPosAsyncTaskService; import com.telpo.dipperposition.service.IpProvinceService; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.ObjectUtils; +import org.apache.logging.log4j.util.PropertiesUtil; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Service; @@ -49,6 +50,8 @@ public class DipperAstPosAsyncTaskServiceImpl implements IDipperAstPosAsyncTaskS // 不存在说明token是已过期了 String centerProvinceName = ""; String centerProvinceLonAndAlt = ""; + //ClassLoader classLoader = PropertiesUtil.class.getClassLoader(); + //String classPath = classLoader.get List centerAddressSets = CSVUtil.readCSV(this.centerProvinceFilePath); for (String centerAddressSet:centerAddressSets) { String[] centerAddressSetArray = centerAddressSet.split(","); diff --git a/src/main/java/com/telpo/dipperposition/service/impl/DipperAstTimeAsyncTaskServiceImpl.java b/src/main/java/com/telpo/dipperposition/service/impl/DipperAstTimeAsyncTaskServiceImpl.java index 804b0be..bcf9583 100644 --- a/src/main/java/com/telpo/dipperposition/service/impl/DipperAstTimeAsyncTaskServiceImpl.java +++ b/src/main/java/com/telpo/dipperposition/service/impl/DipperAstTimeAsyncTaskServiceImpl.java @@ -84,7 +84,7 @@ public class DipperAstTimeAsyncTaskServiceImpl implements IDipperAstTimeAsyncTas astTimeCmd += "00286BEE"; String hexIn = astTimeCmd + HexConvert.makeChecksum(astTimeCmd); - log.info("返回时间:" + hexIn); + log.info("DipperAstTimeAsyncTaskServiceImpl 返回时间:" + hexIn); return hexIn; } From 13fa99942093855d8f827cac1d0ae132baeefb67 Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Tue, 19 Jan 2021 11:32:13 +0800 Subject: [PATCH 125/172] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=88=B0docker?= =?UTF-8?q?=E5=A4=96=E8=BF=90=E8=A1=8C=E7=8E=AF=E5=A2=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/DipperAstPosAsyncTaskServiceImpl.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java b/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java index c404067..326bc12 100644 --- a/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java +++ b/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java @@ -50,8 +50,6 @@ public class DipperAstPosAsyncTaskServiceImpl implements IDipperAstPosAsyncTaskS // 不存在说明token是已过期了 String centerProvinceName = ""; String centerProvinceLonAndAlt = ""; - //ClassLoader classLoader = PropertiesUtil.class.getClassLoader(); - //String classPath = classLoader.get List centerAddressSets = CSVUtil.readCSV(this.centerProvinceFilePath); for (String centerAddressSet:centerAddressSets) { String[] centerAddressSetArray = centerAddressSet.split(","); From a805975de9d013e590369ebfa59a9e7f0f885230 Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Tue, 19 Jan 2021 11:46:06 +0800 Subject: [PATCH 126/172] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=88=B0docker?= =?UTF-8?q?=E5=A4=96=E8=BF=90=E8=A1=8C=E7=8E=AF=E5=A2=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dipperposition/DipperPositionApplication.java | 1 - .../impl/DipperAstPosAsyncTaskServiceImpl.java | 13 +++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/telpo/dipperposition/DipperPositionApplication.java b/src/main/java/com/telpo/dipperposition/DipperPositionApplication.java index f25c92d..691fbb1 100644 --- a/src/main/java/com/telpo/dipperposition/DipperPositionApplication.java +++ b/src/main/java/com/telpo/dipperposition/DipperPositionApplication.java @@ -31,7 +31,6 @@ public class DipperPositionApplication { log.info("北斗定位服务开始!"); ConfigurableApplicationContext applicationContext = SpringApplication.run(DipperPositionApplication.class, args); log.info("北斗定位服务启动!"); - log.info(applicationContext.getResource("bootstrap.yaml").getFile().getAbsolutePath()); //启动服务端 ConfigurableEnvironment environment = applicationContext.getEnvironment(); DipperPositionServer nettyServer = new DipperPositionServer(environment); diff --git a/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java b/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java index 326bc12..d6bd996 100644 --- a/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java +++ b/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java @@ -13,7 +13,9 @@ import org.apache.logging.log4j.util.PropertiesUtil; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Service; +import org.springframework.util.ResourceUtils; +import java.io.FileNotFoundException; import java.io.UnsupportedEncodingException; import java.util.List; @@ -46,11 +48,18 @@ public class DipperAstPosAsyncTaskServiceImpl implements IDipperAstPosAsyncTaskS private String ipPositionRequestKey; // 从CSV文件读取省会城市中心点位置信息 - private void getPosFromFile(String centerAddress) { + private void getPosFromFile(String centerAddress) { // 不存在说明token是已过期了 String centerProvinceName = ""; String centerProvinceLonAndAlt = ""; - List centerAddressSets = CSVUtil.readCSV(this.centerProvinceFilePath); + String appResPath = ""; + try { + appResPath = ResourceUtils.getURL("resources:").getPath(); + log.debug(appResPath); + } catch (Exception e) { + log.debug("cannot find path"); + } + List centerAddressSets = CSVUtil.readCSV(appResPath + this.centerProvinceFilePath); for (String centerAddressSet:centerAddressSets) { String[] centerAddressSetArray = centerAddressSet.split(","); if (centerAddressSetArray.length < 3) { From f512d4a85641a2bb81990e235255a5afa22d1221 Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Tue, 19 Jan 2021 11:56:25 +0800 Subject: [PATCH 127/172] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=88=B0docker?= =?UTF-8?q?=E5=A4=96=E8=BF=90=E8=A1=8C=E7=8E=AF=E5=A2=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../handler/NettyServerHandler.java | 18 ++---------------- .../server/DipperPositionServer.java | 8 ++++---- 2 files changed, 6 insertions(+), 20 deletions(-) diff --git a/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java b/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java index 685a7b1..f56de83 100644 --- a/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java +++ b/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java @@ -138,7 +138,7 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter { // 从缓存获取SDBP-AST-EPH星历数 //if (Integer.parseInt(starsAsycServerPort) == channel.localAddress().getPort()) { //if (AST_POS_CMD.equals(recvmg)) { - if (AST_POS_CMD.equals(msg)) { + if (AST_EPH_CMD_BYTE.equals(msg)) { channelAns = nettyServerHandler.dipperDataAsyncTaskService.getAstEPH(); } @@ -146,29 +146,15 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter { if (channelAns != null) { buf = Unpooled.buffer(channelAns.getBytes().length); buf.writeBytes(channelAns.getBytes("GBK")); + ctx.writeAndFlush(buf); } // 最后把SDBP-AST-TIME、SDBP-AST-POS、SDBP-AST-EPH并包一起发给设备。 // 设备采用16进制获取数据,则代理服务器也是采用16进制返回数据。 // 通知客户端链消息发送成功 - ctx.writeAndFlush(buf); //ctx.write("你也好哦"); //ctx.flush(); } -// @Override -// public void channelRead0(ChannelHandlerContext ctx, HttpObject msg) -// throws Exception { -// if (msg instanceof HttpRequest) { -// HttpRequest mReq = (HttpRequest) msg; -// String clientIP = mReq.headers().get("X-Forwarded-For"); -// if (clientIP == null) { -// InetSocketAddress insocket = (InetSocketAddress) ctx.channel() -// .remoteAddress(); -// clientIP = insocket.getAddress().getHostAddress(); -// } -// } -// } - /** * 发生异常触发 */ diff --git a/src/main/java/com/telpo/dipperposition/server/DipperPositionServer.java b/src/main/java/com/telpo/dipperposition/server/DipperPositionServer.java index 54dc4ec..6aa2edc 100644 --- a/src/main/java/com/telpo/dipperposition/server/DipperPositionServer.java +++ b/src/main/java/com/telpo/dipperposition/server/DipperPositionServer.java @@ -29,11 +29,11 @@ import java.net.InetSocketAddress; */ @Slf4j @Component -@NacosPropertySource(dataId="dipperposition-service", autoRefreshed=true) +//@NacosPropertySource(dataId="dipperposition-service", autoRefreshed=true) public class DipperPositionServer { - @NacosValue("position-server.serverAddr") - private String myServerAddr; + //@NacosValue("position-server.serverAddr") + //private String myServerAddr; private String serverAddr; private Integer starsAsycPort; @@ -70,7 +70,7 @@ public class DipperPositionServer { ChannelFuture channelFuture3 = bootstrap.bind(socketAddress).sync(); log.info("星历服务器启动开始监听端口: {}", starsAsycPort); - log.info("服务器: {}", myServerAddr); + //log.info("服务器: {}", myServerAddr); channelFuture3.addListener(future -> { if (future.isSuccess()){ System.out.println("start success"); From 4207a5d7725f34589e96d853c4ef6ecf4e5c5c84 Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Tue, 19 Jan 2021 11:59:30 +0800 Subject: [PATCH 128/172] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=88=B0docker?= =?UTF-8?q?=E5=A4=96=E8=BF=90=E8=A1=8C=E7=8E=AF=E5=A2=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/telpo/dipperposition/handler/NettyServerHandler.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java b/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java index f56de83..3d46275 100644 --- a/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java +++ b/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java @@ -138,7 +138,7 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter { // 从缓存获取SDBP-AST-EPH星历数 //if (Integer.parseInt(starsAsycServerPort) == channel.localAddress().getPort()) { //if (AST_POS_CMD.equals(recvmg)) { - if (AST_EPH_CMD_BYTE.equals(msg)) { + if (AST_EPH_CMD.equals(msg)) { channelAns = nettyServerHandler.dipperDataAsyncTaskService.getAstEPH(); } From 1b21d2d04cd02fc803ee6af7e45cc615a1de3a0e Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Tue, 19 Jan 2021 12:17:42 +0800 Subject: [PATCH 129/172] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=88=B0docker?= =?UTF-8?q?=E5=A4=96=E8=BF=90=E8=A1=8C=E7=8E=AF=E5=A2=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/DipperAstPosAsyncTaskServiceImpl.java | 8 ++++---- .../service/impl/DipperAstTimeAsyncTaskServiceImpl.java | 1 - .../service/impl/DipperDataAsyncTaskServiceImpl.java | 3 +-- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java b/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java index d6bd996..fe3f30e 100644 --- a/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java +++ b/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java @@ -52,14 +52,14 @@ public class DipperAstPosAsyncTaskServiceImpl implements IDipperAstPosAsyncTaskS // 不存在说明token是已过期了 String centerProvinceName = ""; String centerProvinceLonAndAlt = ""; - String appResPath = ""; + String appCsvPath = ""; try { - appResPath = ResourceUtils.getURL("resources:").getPath(); - log.debug(appResPath); + appCsvPath = ResourceUtils.getFile("resources"+this.centerProvinceFilePath).getPath(); + log.debug(appCsvPath); } catch (Exception e) { log.debug("cannot find path"); } - List centerAddressSets = CSVUtil.readCSV(appResPath + this.centerProvinceFilePath); + List centerAddressSets = CSVUtil.readCSV(appCsvPath); for (String centerAddressSet:centerAddressSets) { String[] centerAddressSetArray = centerAddressSet.split(","); if (centerAddressSetArray.length < 3) { diff --git a/src/main/java/com/telpo/dipperposition/service/impl/DipperAstTimeAsyncTaskServiceImpl.java b/src/main/java/com/telpo/dipperposition/service/impl/DipperAstTimeAsyncTaskServiceImpl.java index bcf9583..734aefd 100644 --- a/src/main/java/com/telpo/dipperposition/service/impl/DipperAstTimeAsyncTaskServiceImpl.java +++ b/src/main/java/com/telpo/dipperposition/service/impl/DipperAstTimeAsyncTaskServiceImpl.java @@ -23,7 +23,6 @@ import java.time.LocalDateTime; public class DipperAstTimeAsyncTaskServiceImpl implements IDipperAstTimeAsyncTaskService { @Override - @Async("asyncServiceExecutor") public String pushAstTime() { // 创建Socket客户端实例; diff --git a/src/main/java/com/telpo/dipperposition/service/impl/DipperDataAsyncTaskServiceImpl.java b/src/main/java/com/telpo/dipperposition/service/impl/DipperDataAsyncTaskServiceImpl.java index dee9a3e..dacfb40 100644 --- a/src/main/java/com/telpo/dipperposition/service/impl/DipperDataAsyncTaskServiceImpl.java +++ b/src/main/java/com/telpo/dipperposition/service/impl/DipperDataAsyncTaskServiceImpl.java @@ -32,6 +32,7 @@ public class DipperDataAsyncTaskServiceImpl implements IDipperDataAsyncTaskServi @Override + @Async("asyncServiceExecutor") public void pullAstEPH() { // (1) 发送bds获取星历数据 String dipperData = pullEPHFromDipper(); @@ -46,7 +47,6 @@ public class DipperDataAsyncTaskServiceImpl implements IDipperDataAsyncTaskServi } } - private String pullEPHFromDipper() { // 创建Socket客户端实例; @@ -64,7 +64,6 @@ public class DipperDataAsyncTaskServiceImpl implements IDipperDataAsyncTaskServi } @Override - @Async("asyncServiceExecutor") public String getAstEPH(){ return (String)redisUtil.get(DIPPER_DATA_KEY); } From f518436b964e801f39f3822e929f37c3468b86f0 Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Tue, 19 Jan 2021 12:23:44 +0800 Subject: [PATCH 130/172] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=88=B0docker?= =?UTF-8?q?=E5=A4=96=E8=BF=90=E8=A1=8C=E7=8E=AF=E5=A2=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dipperposition/handler/NettyServerHandler.java | 14 +++++++------- .../impl/DipperAstPosAsyncTaskServiceImpl.java | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java b/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java index 3d46275..a0358ec 100644 --- a/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java +++ b/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java @@ -108,12 +108,12 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter { String ipAddress = channel.remoteAddress().toString(); //String message = " 接收到消息:{0}, 客户端IP:{1}"; log.info("接收到消息:" + msg + ",客户端IP:" + ipAddress); - if (nettyServerHandler.positionConfig != null) { - log.info("config info is : " + nettyServerHandler.positionConfig.getCenterProvinceFilePath() + nettyServerHandler.positionConfig.getCenterProvince() + nettyServerHandler.positionConfig.getIpPositionRequestPath() + - nettyServerHandler.positionConfig.getIpPositionRequestKey()); - } else { - log.info("positionConfig info is null!!!!!!!!!!!!!! "); - } +// if (nettyServerHandler.positionConfig != null) { +// log.info("config info is : " + nettyServerHandler.positionConfig.getCenterProvinceFilePath() + nettyServerHandler.positionConfig.getCenterProvince() + nettyServerHandler.positionConfig.getIpPositionRequestPath() + +// nettyServerHandler.positionConfig.getIpPositionRequestKey()); +// } else { +// log.info("positionConfig info is null!!!!!!!!!!!!!! "); +// } String channelAns = ""; // 返回时间指令 @@ -125,7 +125,7 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter { if (AST_TIME_CMD.equals(msg)) { // 初始时间辅助输入; channelAns = nettyServerHandler.dipperTimeAsyncTaskService.pushAstTime(); - log.info("返回时间:" + channelAns); +// log.info("返回时间:" + channelAns); } // 发送SDBP-AST-POS获取辅助位置信息 // if (Integer.parseInt(posAsycServerPort) == channel.localAddress().getPort()) { diff --git a/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java b/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java index fe3f30e..6af9ce3 100644 --- a/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java +++ b/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java @@ -54,7 +54,7 @@ public class DipperAstPosAsyncTaskServiceImpl implements IDipperAstPosAsyncTaskS String centerProvinceLonAndAlt = ""; String appCsvPath = ""; try { - appCsvPath = ResourceUtils.getFile("resources"+this.centerProvinceFilePath).getPath(); + appCsvPath = ResourceUtils.getFile("resources"+this.centerProvinceFilePath).getAbsolutePath(); log.debug(appCsvPath); } catch (Exception e) { log.debug("cannot find path"); From e87b7fe15427af56b82c2803c60d1c0883894ac8 Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Tue, 19 Jan 2021 12:30:36 +0800 Subject: [PATCH 131/172] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=88=B0docker?= =?UTF-8?q?=E5=A4=96=E8=BF=90=E8=A1=8C=E7=8E=AF=E5=A2=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/DipperAstPosAsyncTaskServiceImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java b/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java index 6af9ce3..defeb4e 100644 --- a/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java +++ b/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java @@ -54,7 +54,7 @@ public class DipperAstPosAsyncTaskServiceImpl implements IDipperAstPosAsyncTaskS String centerProvinceLonAndAlt = ""; String appCsvPath = ""; try { - appCsvPath = ResourceUtils.getFile("resources"+this.centerProvinceFilePath).getAbsolutePath(); + appCsvPath ="/home/data/dipperposition/BOOT-INF/classes" +this.centerProvinceFilePath; log.debug(appCsvPath); } catch (Exception e) { log.debug("cannot find path"); From 193bab385f83cf16cd0ba4df965cab66c04b4580 Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Tue, 19 Jan 2021 13:48:08 +0800 Subject: [PATCH 132/172] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=88=B0docker?= =?UTF-8?q?=E5=A4=96=E8=BF=90=E8=A1=8C=E7=8E=AF=E5=A2=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/DipperAstPosAsyncTaskServiceImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java b/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java index defeb4e..12ca5fa 100644 --- a/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java +++ b/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java @@ -54,7 +54,7 @@ public class DipperAstPosAsyncTaskServiceImpl implements IDipperAstPosAsyncTaskS String centerProvinceLonAndAlt = ""; String appCsvPath = ""; try { - appCsvPath ="/home/data/dipperposition/BOOT-INF/classes" +this.centerProvinceFilePath; + appCsvPath ="/home/data/dipperposition" +this.centerProvinceFilePath; log.debug(appCsvPath); } catch (Exception e) { log.debug("cannot find path"); From 8a97623fe0fd630688819f7a6983c5868ceaae47 Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Tue, 19 Jan 2021 13:55:47 +0800 Subject: [PATCH 133/172] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=88=B0docker?= =?UTF-8?q?=E5=A4=96=E8=BF=90=E8=A1=8C=E7=8E=AF=E5=A2=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DipperAstPosAsyncTaskServiceImpl.java | 5 ++- .../service/impl/csv/provinceLonAlt.csv | 35 +++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/telpo/dipperposition/service/impl/csv/provinceLonAlt.csv diff --git a/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java b/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java index 12ca5fa..f672317 100644 --- a/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java +++ b/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java @@ -15,6 +15,7 @@ import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Service; import org.springframework.util.ResourceUtils; +import java.io.File; import java.io.FileNotFoundException; import java.io.UnsupportedEncodingException; import java.util.List; @@ -54,7 +55,9 @@ public class DipperAstPosAsyncTaskServiceImpl implements IDipperAstPosAsyncTaskS String centerProvinceLonAndAlt = ""; String appCsvPath = ""; try { - appCsvPath ="/home/data/dipperposition" +this.centerProvinceFilePath; + //appCsvPath ="/home/data/dipperposition" +this.centerProvinceFilePath; + File f = new File(this.getClass().getResource("").getPath()); + appCsvPath = f.getAbsolutePath()+this.centerProvinceFilePath; log.debug(appCsvPath); } catch (Exception e) { log.debug("cannot find path"); diff --git a/src/main/java/com/telpo/dipperposition/service/impl/csv/provinceLonAlt.csv b/src/main/java/com/telpo/dipperposition/service/impl/csv/provinceLonAlt.csv new file mode 100644 index 0000000..9904ec8 --- /dev/null +++ b/src/main/java/com/telpo/dipperposition/service/impl/csv/provinceLonAlt.csv @@ -0,0 +1,35 @@ +城市,经度,纬度,省份 +沈阳市,123.429092,41.796768,辽宁省 +长春市,125.324501,43.886841,吉林省 +哈尔滨市,126.642464,45.756966,黑龙江省 +北京市,116.405289,39.904987,北京市 +天津市,117.190186,39.125595,天津市 +呼和浩特市,111.75199,40.84149,内蒙古自治区 +银川市,106.23248,38.48644,宁夏回族自治区 +太原市,112.549248,37.857014,山西省 +石家庄市,114.502464,38.045475,河北省 +济南市,117.000923,36.675808,山东省 +郑州市,113.665413,34.757977,河南省 +西安市,108.948021,34.263161,陕西省 +武汉市,114.298569,30.584354,湖北省 +南京市,118.76741,32.041546,江苏省 +合肥市,117.283043,31.861191,安徽省 +上海市,121.472641,31.231707,上海市 +长沙市,112.982277,28.19409,湖南省 +南昌市,115.892151,28.676493,江西省 +杭州市,120.15358,30.287458,浙江省 +福州市,119.306236,26.075302,福建省 +广州市,113.28064,23.125177,广东省 +台北市,121.520076,25.030724,台湾省 +海口市,110.19989,20.04422,海南省 +南宁市,108.320007,22.82402,广西壮族自治区 +重庆市,106.504959,29.533155,重庆市 +昆明市,102.71225,25.040609,云南省 +贵阳市,106.713478,26.578342,贵州省 +成都市,104.065735,30.659462,四川省 +兰州市,103.83417,36.06138,甘肃省 +西宁市,101.77782,36.61729,青海省 +拉萨市,91.1145,29.64415,西藏自治区 +乌鲁木齐市,87.61688,43.82663,新疆维吾尔自治区 +香港,114.16546,22.27534,香港特别行政区 +澳门,113.54913,22.19875,澳门特别行政区 From f9fac1dd1724eeeff865e603d97f6c9a27f26635 Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Tue, 19 Jan 2021 14:00:34 +0800 Subject: [PATCH 134/172] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=88=B0docker?= =?UTF-8?q?=E5=A4=96=E8=BF=90=E8=A1=8C=E7=8E=AF=E5=A2=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/DipperAstPosAsyncTaskServiceImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java b/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java index f672317..9c3b46f 100644 --- a/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java +++ b/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java @@ -57,7 +57,7 @@ public class DipperAstPosAsyncTaskServiceImpl implements IDipperAstPosAsyncTaskS try { //appCsvPath ="/home/data/dipperposition" +this.centerProvinceFilePath; File f = new File(this.getClass().getResource("").getPath()); - appCsvPath = f.getAbsolutePath()+this.centerProvinceFilePath; + appCsvPath = f.getPath()+this.centerProvinceFilePath; log.debug(appCsvPath); } catch (Exception e) { log.debug("cannot find path"); From 329c87807bde0b87c76c1c3d88829abc8227c49b Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Tue, 19 Jan 2021 14:03:57 +0800 Subject: [PATCH 135/172] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=88=B0docker?= =?UTF-8?q?=E5=A4=96=E8=BF=90=E8=A1=8C=E7=8E=AF=E5=A2=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/DipperAstPosAsyncTaskServiceImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java b/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java index 9c3b46f..6d50af3 100644 --- a/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java +++ b/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java @@ -56,7 +56,7 @@ public class DipperAstPosAsyncTaskServiceImpl implements IDipperAstPosAsyncTaskS String appCsvPath = ""; try { //appCsvPath ="/home/data/dipperposition" +this.centerProvinceFilePath; - File f = new File(this.getClass().getResource("").getPath()); + File f = new File(this.getClass().getResource("/").getPath()); appCsvPath = f.getPath()+this.centerProvinceFilePath; log.debug(appCsvPath); } catch (Exception e) { From 253e650e3d980817a5ac454fbbd5056c266de7bc Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Tue, 19 Jan 2021 14:37:11 +0800 Subject: [PATCH 136/172] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=88=B0docker?= =?UTF-8?q?=E5=A4=96=E8=BF=90=E8=A1=8C=E7=8E=AF=E5=A2=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../entity/mongo/ProvinceInfoEntity.java | 27 +++++++ .../mapper/ProvinceInfoMapper.java | 63 +++++++++++++++ .../service/IProvinceInfoService.java | 56 +++++++++++++ .../DipperAstPosAsyncTaskServiceImpl.java | 59 +++----------- .../service/impl/ProvinceInfoServiceImpl.java | 78 +++++++++++++++++++ .../service/impl/csv/provinceLonAlt.csv | 35 --------- .../dipperposition/vo/ProvinceInfoVo.java | 24 ++++++ 7 files changed, 259 insertions(+), 83 deletions(-) create mode 100644 src/main/java/com/telpo/dipperposition/entity/mongo/ProvinceInfoEntity.java create mode 100644 src/main/java/com/telpo/dipperposition/mapper/ProvinceInfoMapper.java create mode 100644 src/main/java/com/telpo/dipperposition/service/IProvinceInfoService.java create mode 100644 src/main/java/com/telpo/dipperposition/service/impl/ProvinceInfoServiceImpl.java delete mode 100644 src/main/java/com/telpo/dipperposition/service/impl/csv/provinceLonAlt.csv create mode 100644 src/main/java/com/telpo/dipperposition/vo/ProvinceInfoVo.java diff --git a/src/main/java/com/telpo/dipperposition/entity/mongo/ProvinceInfoEntity.java b/src/main/java/com/telpo/dipperposition/entity/mongo/ProvinceInfoEntity.java new file mode 100644 index 0000000..9770ba3 --- /dev/null +++ b/src/main/java/com/telpo/dipperposition/entity/mongo/ProvinceInfoEntity.java @@ -0,0 +1,27 @@ +package com.telpo.dipperposition.entity.mongo; + +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; +import models.BaseMongoDbEntity; + +/** + * @program: IpProvinceEntity + * @description: 省份位置实体类 + * @author: linwl + * @create: 2020-07-11 15:33 + */ +@ToString +@Getter +@Setter +public class ProvinceInfoEntity extends BaseMongoDbEntity { + + /** 所在省份 */ + private String province; + /** lon */ + private String lon; + /** lon */ + private String alt; + /** centerAddress */ + private String centerAddress; +} diff --git a/src/main/java/com/telpo/dipperposition/mapper/ProvinceInfoMapper.java b/src/main/java/com/telpo/dipperposition/mapper/ProvinceInfoMapper.java new file mode 100644 index 0000000..3530e47 --- /dev/null +++ b/src/main/java/com/telpo/dipperposition/mapper/ProvinceInfoMapper.java @@ -0,0 +1,63 @@ +package com.telpo.dipperposition.mapper; + +import com.telpo.dipperposition.annotation.MongoSwitch; +import com.telpo.dipperposition.entity.mongo.IpProvinceEntity; +import com.telpo.dipperposition.entity.mongo.ProvinceInfoEntity; +import db.BaseMongoDbDao; +import org.springframework.stereotype.Repository; + +import java.util.List; + +/** + * @program: ProvinceInfoMapper + * @description: 省份位置记录mapper + * @author: linwl + * @create: 2020-07-20 11:12 + */ +@Repository +public class ProvinceInfoMapper extends BaseMongoDbDao { + + + @Override + protected Class getEntityClass() { + + return ProvinceInfoEntity.class; + } + + @MongoSwitch("common") + public void saveIp(ProvinceInfoEntity entity) { + this.save(entity); + } + + @MongoSwitch("common") + public void saveIp(ProvinceInfoEntity entity, String collectionName) { + + this.save(entity, collectionName); + } + + @MongoSwitch("common") + public void updateIpFirst(ProvinceInfoEntity srcObj, ProvinceInfoEntity targetObj) { + this.updateFirst(srcObj, targetObj); + } + + @Override + public List getPage(ProvinceInfoEntity object, int start, int size) { + return super.getPage(object, start, size); + } + + @MongoSwitch("common") + public List queryIpList(ProvinceInfoEntity object) { + + return this.queryList(object); + } + + @MongoSwitch("common") + public List queryIpList(ProvinceInfoEntity object, String collectionName) { + return this.queryList(object, collectionName); + } + + @MongoSwitch("common") + public void deleteIpById(String id) { + this.deleteById(id); + } +} diff --git a/src/main/java/com/telpo/dipperposition/service/IProvinceInfoService.java b/src/main/java/com/telpo/dipperposition/service/IProvinceInfoService.java new file mode 100644 index 0000000..ee14148 --- /dev/null +++ b/src/main/java/com/telpo/dipperposition/service/IProvinceInfoService.java @@ -0,0 +1,56 @@ +package com.telpo.dipperposition.service; + +import com.telpo.dipperposition.entity.mongo.IpProvinceEntity; +import com.telpo.dipperposition.entity.mongo.ProvinceInfoEntity; + +import java.util.List; + +/** + * @program: IProvinceInfoService + * @description: 省份经纬度信息 + * @author: king + * @create: 2020-07-20 11:09 + */ +public interface IProvinceInfoService { + +// @Autowired +// void setIPProvinceService(IpProvinceService ipProvinceService); + /** + * 保存省份经纬度信息 + * + * @param entity + * @return + */ + boolean saveProvinceInfo(ProvinceInfoEntity entity); + + /** + * 更新省份经纬度信息 + * + * @param query + * @param update + * @return + */ + boolean updateProvinceInfoEntity( + ProvinceInfoEntity query, ProvinceInfoEntity update); + + /** + * 根据ID移除IP省份记录 + * + * @param id + * @return + */ + boolean romveById(String id); + + /* + * @param ipAddress + * 获取省份经纬度信息 + */ + ProvinceInfoEntity getProvinceInfo(String ipAddress); + + /** + * 获取省份经纬度信息 + * + * @return + */ + List getProvinceInfoEntitys(); +} diff --git a/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java b/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java index 6d50af3..febe80a 100644 --- a/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java +++ b/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java @@ -5,7 +5,9 @@ import com.telpo.dipperposition.common.*; import com.telpo.dipperposition.config.NettyServerConfig; import com.telpo.dipperposition.config.PositionConfig; import com.telpo.dipperposition.entity.mongo.IpProvinceEntity; +import com.telpo.dipperposition.entity.mongo.ProvinceInfoEntity; import com.telpo.dipperposition.service.IDipperAstPosAsyncTaskService; +import com.telpo.dipperposition.service.IProvinceInfoService; import com.telpo.dipperposition.service.IpProvinceService; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.ObjectUtils; @@ -34,47 +36,19 @@ import java.util.List; @Slf4j public class DipperAstPosAsyncTaskServiceImpl implements IDipperAstPosAsyncTaskService { - @Autowired - private RedisUtil redisUtil; @Autowired private OkHttpUtil okHttpUtil; @Autowired private PositionConfig positionConfig; @Autowired private IpProvinceService ipProvinceService; + @Autowired + private IProvinceInfoService provinceInfoService; private String centerProvince; - private String centerProvinceFilePath; private String ipPositionRequestPath; private String ipPositionRequestKey; - // 从CSV文件读取省会城市中心点位置信息 - private void getPosFromFile(String centerAddress) { - // 不存在说明token是已过期了 - String centerProvinceName = ""; - String centerProvinceLonAndAlt = ""; - String appCsvPath = ""; - try { - //appCsvPath ="/home/data/dipperposition" +this.centerProvinceFilePath; - File f = new File(this.getClass().getResource("/").getPath()); - appCsvPath = f.getPath()+this.centerProvinceFilePath; - log.debug(appCsvPath); - } catch (Exception e) { - log.debug("cannot find path"); - } - List centerAddressSets = CSVUtil.readCSV(appCsvPath); - for (String centerAddressSet:centerAddressSets) { - String[] centerAddressSetArray = centerAddressSet.split(","); - if (centerAddressSetArray.length < 3) { - log.warn("CSV数据格式错误"); - } else { - centerProvinceName = centerAddressSetArray[3]; - centerProvinceLonAndAlt = centerAddressSetArray[1]+","+centerAddressSetArray[2]; - redisUtil.set(centerProvinceName, centerProvinceLonAndAlt, 0); - } - } - } - // 根据IP获取省会信息 private String getIpPositionProvince(String ipAddress) { @@ -131,7 +105,7 @@ public class DipperAstPosAsyncTaskServiceImpl implements IDipperAstPosAsyncTaskS this.ipPositionRequestKey = positionConfig.getIpPositionRequestKey(); this.ipPositionRequestPath = positionConfig.getIpPositionRequestPath(); this.centerProvince = positionConfig.getCenterProvince(); - this.centerProvinceFilePath = positionConfig.getCenterProvinceFilePath(); + //this.centerProvinceFilePath = positionConfig.getCenterProvinceFilePath(); // (1) 获取省会城市信息 String centerAddress = getIpPositionProvince(ipAddress); if (ObjectUtils.isEmpty(centerAddress) || centerAddress.equals("0")) { @@ -143,14 +117,10 @@ public class DipperAstPosAsyncTaskServiceImpl implements IDipperAstPosAsyncTaskS createIPProvince(ipAddress, centerAddress); } - String lonAndAlt; - if (redisUtil.hasKey(centerAddress)) { - // 获取省会城市定位信息 - lonAndAlt= (String) redisUtil.get(centerAddress); - } else { - // 请求高德IP定位服务 - this.getPosFromFile(centerAddress); - lonAndAlt = (String) redisUtil.get(centerAddress); + String lonAndAlt = null; + ProvinceInfoEntity entity = provinceInfoService.getProvinceInfo(centerAddress); + if (entity != null) { + lonAndAlt = entity.getProvince(); } // (2) 处理返回结果 @@ -158,12 +128,10 @@ public class DipperAstPosAsyncTaskServiceImpl implements IDipperAstPosAsyncTaskS // null处理 log.error("系统错误,请联系系统管理员。"); return null; - //return; } // push to GNNS Server - String pushResult = getCmdOfPos(lonAndAlt); - return pushResult; + return getCmdOfPos(lonAndAlt); } // 组装命令发送给设备 @@ -209,12 +177,7 @@ public class DipperAstPosAsyncTaskServiceImpl implements IDipperAstPosAsyncTaskS astTimeCmd += HexConvert.encodeHEX(lanLongValue); astTimeCmd += HexConvert.encodeHEX(altLongValue); - //String hexIn = HexConvert.convertStringToHex(astTimeCmd) + HexConvert.makeChecksum(astTimeCmd); - - String hexIn = astTimeCmd + HexConvert.makeChecksum(astTimeCmd); - + return astTimeCmd + HexConvert.makeChecksum(astTimeCmd); - //return sendResult; - return hexIn; } } diff --git a/src/main/java/com/telpo/dipperposition/service/impl/ProvinceInfoServiceImpl.java b/src/main/java/com/telpo/dipperposition/service/impl/ProvinceInfoServiceImpl.java new file mode 100644 index 0000000..7b9e776 --- /dev/null +++ b/src/main/java/com/telpo/dipperposition/service/impl/ProvinceInfoServiceImpl.java @@ -0,0 +1,78 @@ +package com.telpo.dipperposition.service.impl; + +import com.telpo.dipperposition.entity.mongo.IpProvinceEntity; +import com.telpo.dipperposition.entity.mongo.ProvinceInfoEntity; +import com.telpo.dipperposition.mapper.IpProvinceMapper; +import com.telpo.dipperposition.mapper.ProvinceInfoMapper; +import com.telpo.dipperposition.service.IProvinceInfoService; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.ObjectUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.List; + +/** + * @program: DataPushServer + * @description: 推送记录服务接口实现类 + * @author: linwl + * @create: 2020-07-20 11:09 + */ +@Slf4j +@Service +public class ProvinceInfoServiceImpl implements IProvinceInfoService { + + @Autowired + private ProvinceInfoMapper provinceInfoMapper; + + + @Override + public boolean saveProvinceInfo(ProvinceInfoEntity entity) { + return false; + } + + @Override + public boolean updateProvinceInfoEntity(ProvinceInfoEntity query, ProvinceInfoEntity update) { + return false; + } + + @Override + public boolean romveById(String id) { + + provinceInfoMapper.deleteIpById(id); + return false; + } + + @Override + public ProvinceInfoEntity getProvinceInfo(String centerAddress) { + try { + ProvinceInfoEntity query = new ProvinceInfoEntity(); + query.setCenterAddress(centerAddress); + List records = provinceInfoMapper.queryIpList(query); + if (ObjectUtils.isNotEmpty(records)) { + return records.get(0); + } else { + return null; + } + } catch (Exception e) { + log.error("获取省份异常:", e); + return null; + } + } + + @Override + public List getProvinceInfoEntitys() { + try { + ProvinceInfoEntity query = new ProvinceInfoEntity(); + List records = provinceInfoMapper.queryIpList(query); + if (ObjectUtils.isNotEmpty(records)) { + return records; + } else { + return null; + } + } catch (Exception e) { + log.error("获取IP省份异常:", e); + return null; + } + } +} diff --git a/src/main/java/com/telpo/dipperposition/service/impl/csv/provinceLonAlt.csv b/src/main/java/com/telpo/dipperposition/service/impl/csv/provinceLonAlt.csv deleted file mode 100644 index 9904ec8..0000000 --- a/src/main/java/com/telpo/dipperposition/service/impl/csv/provinceLonAlt.csv +++ /dev/null @@ -1,35 +0,0 @@ -城市,经度,纬度,省份 -沈阳市,123.429092,41.796768,辽宁省 -长春市,125.324501,43.886841,吉林省 -哈尔滨市,126.642464,45.756966,黑龙江省 -北京市,116.405289,39.904987,北京市 -天津市,117.190186,39.125595,天津市 -呼和浩特市,111.75199,40.84149,内蒙古自治区 -银川市,106.23248,38.48644,宁夏回族自治区 -太原市,112.549248,37.857014,山西省 -石家庄市,114.502464,38.045475,河北省 -济南市,117.000923,36.675808,山东省 -郑州市,113.665413,34.757977,河南省 -西安市,108.948021,34.263161,陕西省 -武汉市,114.298569,30.584354,湖北省 -南京市,118.76741,32.041546,江苏省 -合肥市,117.283043,31.861191,安徽省 -上海市,121.472641,31.231707,上海市 -长沙市,112.982277,28.19409,湖南省 -南昌市,115.892151,28.676493,江西省 -杭州市,120.15358,30.287458,浙江省 -福州市,119.306236,26.075302,福建省 -广州市,113.28064,23.125177,广东省 -台北市,121.520076,25.030724,台湾省 -海口市,110.19989,20.04422,海南省 -南宁市,108.320007,22.82402,广西壮族自治区 -重庆市,106.504959,29.533155,重庆市 -昆明市,102.71225,25.040609,云南省 -贵阳市,106.713478,26.578342,贵州省 -成都市,104.065735,30.659462,四川省 -兰州市,103.83417,36.06138,甘肃省 -西宁市,101.77782,36.61729,青海省 -拉萨市,91.1145,29.64415,西藏自治区 -乌鲁木齐市,87.61688,43.82663,新疆维吾尔自治区 -香港,114.16546,22.27534,香港特别行政区 -澳门,113.54913,22.19875,澳门特别行政区 diff --git a/src/main/java/com/telpo/dipperposition/vo/ProvinceInfoVo.java b/src/main/java/com/telpo/dipperposition/vo/ProvinceInfoVo.java new file mode 100644 index 0000000..7d5cb00 --- /dev/null +++ b/src/main/java/com/telpo/dipperposition/vo/ProvinceInfoVo.java @@ -0,0 +1,24 @@ +package com.telpo.dipperposition.vo; + +import lombok.Getter; +import lombok.Setter; + +/** + * @program: DataPushServer + * @description: 基础类 + * @author: linwl + * @create: 2020-07-17 16:41 + */ +@Setter +@Getter +public class ProvinceInfoVo { + + /** Ip所在省份 */ + private String province; + /** lon */ + private String lon; + /** lon */ + private String alt; + /** centerAddress */ + private String centerAddress; +} From 8ae5e6ede6f5b9072174c16cbb5be96f11342926 Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Tue, 19 Jan 2021 16:43:03 +0800 Subject: [PATCH 137/172] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=88=B0docker?= =?UTF-8?q?=E5=A4=96=E8=BF=90=E8=A1=8C=E7=8E=AF=E5=A2=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- setup_test.sh | 2 +- .../entity/mongo/ProvinceInfoEntity.java | 2 +- src/main/resources/csv/provinceLonAlt.csv | 38 +++---------------- 3 files changed, 7 insertions(+), 35 deletions(-) diff --git a/setup_test.sh b/setup_test.sh index c88ef12..1c0d5f8 100644 --- a/setup_test.sh +++ b/setup_test.sh @@ -22,6 +22,6 @@ docker rmi -f $(docker images | grep none | awk '{print $3}') # 查看镜像列表 docker images # 启动容器 -docker run -v /home/data/dipperposition/log:/var/log/dipperposition -d -e active=test --network host --restart=always -p 9011:9011 --name dipperposition_service 139.224.254.18:5000/dipperposition_service:$image_version +docker run -v /home/data/dipperposition/log:/var/log/dipperposition -d -e active=test --network host --restart=always -p 9012:9012 --name dipperposition_service 139.224.254.18:5000/dipperposition_service:$image_version # 查看日志 # docker logs dipperposition_service diff --git a/src/main/java/com/telpo/dipperposition/entity/mongo/ProvinceInfoEntity.java b/src/main/java/com/telpo/dipperposition/entity/mongo/ProvinceInfoEntity.java index 9770ba3..71cc442 100644 --- a/src/main/java/com/telpo/dipperposition/entity/mongo/ProvinceInfoEntity.java +++ b/src/main/java/com/telpo/dipperposition/entity/mongo/ProvinceInfoEntity.java @@ -20,7 +20,7 @@ public class ProvinceInfoEntity extends BaseMongoDbEntity { private String province; /** lon */ private String lon; - /** lon */ + /** alt */ private String alt; /** centerAddress */ private String centerAddress; diff --git a/src/main/resources/csv/provinceLonAlt.csv b/src/main/resources/csv/provinceLonAlt.csv index 9904ec8..fdb8801 100644 --- a/src/main/resources/csv/provinceLonAlt.csv +++ b/src/main/resources/csv/provinceLonAlt.csv @@ -1,35 +1,7 @@ 城市,经度,纬度,省份 -沈阳市,123.429092,41.796768,辽宁省 -长春市,125.324501,43.886841,吉林省 -哈尔滨市,126.642464,45.756966,黑龙江省 -北京市,116.405289,39.904987,北京市 -天津市,117.190186,39.125595,天津市 -呼和浩特市,111.75199,40.84149,内蒙古自治区 -银川市,106.23248,38.48644,宁夏回族自治区 太原市,112.549248,37.857014,山西省 -石家庄市,114.502464,38.045475,河北省 -济南市,117.000923,36.675808,山东省 -郑州市,113.665413,34.757977,河南省 -西安市,108.948021,34.263161,陕西省 -武汉市,114.298569,30.584354,湖北省 -南京市,118.76741,32.041546,江苏省 -合肥市,117.283043,31.861191,安徽省 -上海市,121.472641,31.231707,上海市 -长沙市,112.982277,28.19409,湖南省 -南昌市,115.892151,28.676493,江西省 -杭州市,120.15358,30.287458,浙江省 -福州市,119.306236,26.075302,福建省 -广州市,113.28064,23.125177,广东省 -台北市,121.520076,25.030724,台湾省 -海口市,110.19989,20.04422,海南省 -南宁市,108.320007,22.82402,广西壮族自治区 -重庆市,106.504959,29.533155,重庆市 -昆明市,102.71225,25.040609,云南省 -贵阳市,106.713478,26.578342,贵州省 -成都市,104.065735,30.659462,四川省 -兰州市,103.83417,36.06138,甘肃省 -西宁市,101.77782,36.61729,青海省 -拉萨市,91.1145,29.64415,西藏自治区 -乌鲁木齐市,87.61688,43.82663,新疆维吾尔自治区 -香港,114.16546,22.27534,香港特别行政区 -澳门,113.54913,22.19875,澳门特别行政区 + + "centerAddress" : "太原市", + "lon" : "112.549248", + "alt" : "37.857014", + "province" : "山西省" \ No newline at end of file From 609c0bea16f7076bf0316ab5b6a54e045c925487 Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Tue, 19 Jan 2021 16:43:44 +0800 Subject: [PATCH 138/172] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=88=B0docker?= =?UTF-8?q?=E5=A4=96=E8=BF=90=E8=A1=8C=E7=8E=AF=E5=A2=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/csv/provinceLonAlt.csv | 7 ------- 1 file changed, 7 deletions(-) delete mode 100644 src/main/resources/csv/provinceLonAlt.csv diff --git a/src/main/resources/csv/provinceLonAlt.csv b/src/main/resources/csv/provinceLonAlt.csv deleted file mode 100644 index fdb8801..0000000 --- a/src/main/resources/csv/provinceLonAlt.csv +++ /dev/null @@ -1,7 +0,0 @@ -城市,经度,纬度,省份 -太原市,112.549248,37.857014,山西省 - - "centerAddress" : "太原市", - "lon" : "112.549248", - "alt" : "37.857014", - "province" : "山西省" \ No newline at end of file From 84df9479263f86650f4981e6dba49e0dbaba3915 Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Tue, 19 Jan 2021 17:37:16 +0800 Subject: [PATCH 139/172] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=88=B0docker?= =?UTF-8?q?=E5=A4=96=E8=BF=90=E8=A1=8C=E7=8E=AF=E5=A2=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../telpo/dipperposition/service/IProvinceInfoService.java | 2 +- .../dipperposition/service/impl/ProvinceInfoServiceImpl.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/telpo/dipperposition/service/IProvinceInfoService.java b/src/main/java/com/telpo/dipperposition/service/IProvinceInfoService.java index ee14148..dafa7d6 100644 --- a/src/main/java/com/telpo/dipperposition/service/IProvinceInfoService.java +++ b/src/main/java/com/telpo/dipperposition/service/IProvinceInfoService.java @@ -45,7 +45,7 @@ public interface IProvinceInfoService { * @param ipAddress * 获取省份经纬度信息 */ - ProvinceInfoEntity getProvinceInfo(String ipAddress); + ProvinceInfoEntity getProvinceInfo(String provicne); /** * 获取省份经纬度信息 diff --git a/src/main/java/com/telpo/dipperposition/service/impl/ProvinceInfoServiceImpl.java b/src/main/java/com/telpo/dipperposition/service/impl/ProvinceInfoServiceImpl.java index 7b9e776..657868a 100644 --- a/src/main/java/com/telpo/dipperposition/service/impl/ProvinceInfoServiceImpl.java +++ b/src/main/java/com/telpo/dipperposition/service/impl/ProvinceInfoServiceImpl.java @@ -44,10 +44,10 @@ public class ProvinceInfoServiceImpl implements IProvinceInfoService { } @Override - public ProvinceInfoEntity getProvinceInfo(String centerAddress) { + public ProvinceInfoEntity getProvinceInfo(String provicne) { try { ProvinceInfoEntity query = new ProvinceInfoEntity(); - query.setCenterAddress(centerAddress); + query.setProvince(provicne); List records = provinceInfoMapper.queryIpList(query); if (ObjectUtils.isNotEmpty(records)) { return records.get(0); From 9f84ca14f23c1541042a41618cd0ca86908151d8 Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Wed, 20 Jan 2021 08:30:30 +0800 Subject: [PATCH 140/172] =?UTF-8?q?mongodb=E8=AE=BF=E9=97=AE=E6=96=B9?= =?UTF-8?q?=E5=BC=8F=E5=8F=98=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../entity/mongo/IpProvinceEntity.java | 6 +- .../entity/mongo/ProvinceInfoEntity.java | 5 +- .../mapper/IpProvinceMapper.java | 55 +------------------ .../mapper/ProvinceInfoMapper.java | 49 +---------------- .../service/impl/ProvinceInfoServiceImpl.java | 22 +++++--- 5 files changed, 25 insertions(+), 112 deletions(-) diff --git a/src/main/java/com/telpo/dipperposition/entity/mongo/IpProvinceEntity.java b/src/main/java/com/telpo/dipperposition/entity/mongo/IpProvinceEntity.java index 42edb3d..0bc7e99 100644 --- a/src/main/java/com/telpo/dipperposition/entity/mongo/IpProvinceEntity.java +++ b/src/main/java/com/telpo/dipperposition/entity/mongo/IpProvinceEntity.java @@ -1,10 +1,9 @@ package com.telpo.dipperposition.entity.mongo; -import com.telpo.dipperposition.vo.IPProvinceVo; import lombok.Getter; import lombok.Setter; import lombok.ToString; -import models.BaseMongoDbEntity; +import org.springframework.data.mongodb.core.mapping.Document; /** * @program: IpProvinceEntity @@ -15,7 +14,8 @@ import models.BaseMongoDbEntity; @ToString @Getter @Setter -public class IpProvinceEntity extends BaseMongoDbEntity { +@Document +public class IpProvinceEntity { /** Ip */ private String ip; diff --git a/src/main/java/com/telpo/dipperposition/entity/mongo/ProvinceInfoEntity.java b/src/main/java/com/telpo/dipperposition/entity/mongo/ProvinceInfoEntity.java index 71cc442..38ad6d2 100644 --- a/src/main/java/com/telpo/dipperposition/entity/mongo/ProvinceInfoEntity.java +++ b/src/main/java/com/telpo/dipperposition/entity/mongo/ProvinceInfoEntity.java @@ -3,7 +3,7 @@ package com.telpo.dipperposition.entity.mongo; import lombok.Getter; import lombok.Setter; import lombok.ToString; -import models.BaseMongoDbEntity; +import org.springframework.data.mongodb.core.mapping.Document; /** * @program: IpProvinceEntity @@ -14,7 +14,8 @@ import models.BaseMongoDbEntity; @ToString @Getter @Setter -public class ProvinceInfoEntity extends BaseMongoDbEntity { +@Document +public class ProvinceInfoEntity { /** 所在省份 */ private String province; diff --git a/src/main/java/com/telpo/dipperposition/mapper/IpProvinceMapper.java b/src/main/java/com/telpo/dipperposition/mapper/IpProvinceMapper.java index c615355..b794c95 100644 --- a/src/main/java/com/telpo/dipperposition/mapper/IpProvinceMapper.java +++ b/src/main/java/com/telpo/dipperposition/mapper/IpProvinceMapper.java @@ -4,6 +4,7 @@ import com.telpo.dipperposition.annotation.MongoSwitch; import com.telpo.dipperposition.entity.mongo.IpProvinceEntity; import db.BaseMongoDbDao; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.mongodb.repository.MongoRepository; import org.springframework.stereotype.Repository; import java.util.List; @@ -15,56 +16,4 @@ import java.util.List; * @create: 2020-07-20 11:12 */ @Repository -public class IpProvinceMapper extends BaseMongoDbDao { - -// private static IpProvinceMapper ipProvinceMapper; - /** - * spring会自动从ioc容器当中根据IPProvinceMapper类型找到iPProvinceMapper, - * 当做参数传进来 - * - */ -// @Autowired -// public void setIPProvinceMapper(IpProvinceMapper ipProvinceMapper) { -// this.ipProvinceMapper = ipProvinceMapper; -// } - - @Override - protected Class getEntityClass() { - return IpProvinceEntity.class; - } - - @MongoSwitch("common") - public void saveIp(IpProvinceEntity entity) { - this.save(entity); - } - - @MongoSwitch("common") - public void saveIp(IpProvinceEntity entity, String collectionName) { - this.save(entity, collectionName); - } - - @MongoSwitch("common") - public void updateIpFirst(IpProvinceEntity srcObj, IpProvinceEntity targetObj) { - this.updateFirst(srcObj, targetObj); - } - - @Override - public List getPage(IpProvinceEntity object, int start, int size) { - return super.getPage(object, start, size); - } - - @MongoSwitch("common") - public List queryIpList(IpProvinceEntity object) { - return this.queryList(object); - } - - @MongoSwitch("common") - public List queryIpList(IpProvinceEntity object, String collectionName) { - return this.queryList(object, collectionName); - } - - @MongoSwitch("common") - public void deleteIpById(String id) { - this.deleteById(id); - } -} +public interface IpProvinceMapper extends MongoRepository {} diff --git a/src/main/java/com/telpo/dipperposition/mapper/ProvinceInfoMapper.java b/src/main/java/com/telpo/dipperposition/mapper/ProvinceInfoMapper.java index 3530e47..5059b33 100644 --- a/src/main/java/com/telpo/dipperposition/mapper/ProvinceInfoMapper.java +++ b/src/main/java/com/telpo/dipperposition/mapper/ProvinceInfoMapper.java @@ -4,6 +4,7 @@ import com.telpo.dipperposition.annotation.MongoSwitch; import com.telpo.dipperposition.entity.mongo.IpProvinceEntity; import com.telpo.dipperposition.entity.mongo.ProvinceInfoEntity; import db.BaseMongoDbDao; +import org.springframework.data.mongodb.repository.MongoRepository; import org.springframework.stereotype.Repository; import java.util.List; @@ -15,49 +16,5 @@ import java.util.List; * @create: 2020-07-20 11:12 */ @Repository -public class ProvinceInfoMapper extends BaseMongoDbDao { - - - @Override - protected Class getEntityClass() { - - return ProvinceInfoEntity.class; - } - - @MongoSwitch("common") - public void saveIp(ProvinceInfoEntity entity) { - this.save(entity); - } - - @MongoSwitch("common") - public void saveIp(ProvinceInfoEntity entity, String collectionName) { - - this.save(entity, collectionName); - } - - @MongoSwitch("common") - public void updateIpFirst(ProvinceInfoEntity srcObj, ProvinceInfoEntity targetObj) { - this.updateFirst(srcObj, targetObj); - } - - @Override - public List getPage(ProvinceInfoEntity object, int start, int size) { - return super.getPage(object, start, size); - } - - @MongoSwitch("common") - public List queryIpList(ProvinceInfoEntity object) { - - return this.queryList(object); - } - - @MongoSwitch("common") - public List queryIpList(ProvinceInfoEntity object, String collectionName) { - return this.queryList(object, collectionName); - } - - @MongoSwitch("common") - public void deleteIpById(String id) { - this.deleteById(id); - } -} +public interface ProvinceInfoMapper + extends MongoRepository {} diff --git a/src/main/java/com/telpo/dipperposition/service/impl/ProvinceInfoServiceImpl.java b/src/main/java/com/telpo/dipperposition/service/impl/ProvinceInfoServiceImpl.java index 657868a..da3f873 100644 --- a/src/main/java/com/telpo/dipperposition/service/impl/ProvinceInfoServiceImpl.java +++ b/src/main/java/com/telpo/dipperposition/service/impl/ProvinceInfoServiceImpl.java @@ -1,14 +1,18 @@ package com.telpo.dipperposition.service.impl; -import com.telpo.dipperposition.entity.mongo.IpProvinceEntity; +import cn.hutool.core.bean.BeanUtil; +import cn.hutool.core.collection.CollectionUtil; import com.telpo.dipperposition.entity.mongo.ProvinceInfoEntity; -import com.telpo.dipperposition.mapper.IpProvinceMapper; import com.telpo.dipperposition.mapper.ProvinceInfoMapper; import com.telpo.dipperposition.service.IProvinceInfoService; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.ObjectUtils; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.domain.Example; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; import org.springframework.stereotype.Service; +import tools.BeanTools; import java.util.List; @@ -39,7 +43,7 @@ public class ProvinceInfoServiceImpl implements IProvinceInfoService { @Override public boolean romveById(String id) { - provinceInfoMapper.deleteIpById(id); + provinceInfoMapper.deleteById(id); return false; } @@ -48,9 +52,12 @@ public class ProvinceInfoServiceImpl implements IProvinceInfoService { try { ProvinceInfoEntity query = new ProvinceInfoEntity(); query.setProvince(provicne); - List records = provinceInfoMapper.queryIpList(query); - if (ObjectUtils.isNotEmpty(records)) { - return records.get(0); + Example example = Example.of(query); + PageRequest pageable = PageRequest.of(0, 1); + Page data = provinceInfoMapper.findAll(example, pageable); + if (CollectionUtil.isNotEmpty(data.getContent())) { + List provinceInfos = BeanTools.copyList(data.getContent(), ProvinceInfoEntity.class); + return provinceInfos.get(0); } else { return null; } @@ -63,8 +70,7 @@ public class ProvinceInfoServiceImpl implements IProvinceInfoService { @Override public List getProvinceInfoEntitys() { try { - ProvinceInfoEntity query = new ProvinceInfoEntity(); - List records = provinceInfoMapper.queryIpList(query); + List records = provinceInfoMapper.findAll(); if (ObjectUtils.isNotEmpty(records)) { return records; } else { From dea9cc730bb92e0b6dfc2a6f803f6fdd849bac2e Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Wed, 20 Jan 2021 08:36:11 +0800 Subject: [PATCH 141/172] =?UTF-8?q?mongodb=E8=AE=BF=E9=97=AE=E6=96=B9?= =?UTF-8?q?=E5=BC=8F=E5=8F=98=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/telpo/dipperposition/handler/NettyServerHandler.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java b/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java index a0358ec..49c6089 100644 --- a/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java +++ b/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java @@ -105,7 +105,7 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter { public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { //接收msg消息与上一章节相比,此处已经不需要自己进行解码} SocketChannel channel = (SocketChannel) ctx.channel(); - String ipAddress = channel.remoteAddress().toString(); + String ipAddress = channel.remoteAddress().getAddress().toString(); //String message = " 接收到消息:{0}, 客户端IP:{1}"; log.info("接收到消息:" + msg + ",客户端IP:" + ipAddress); // if (nettyServerHandler.positionConfig != null) { From a48c298d718a8a84f2117462641d2786570c4b5c Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Wed, 20 Jan 2021 08:43:39 +0800 Subject: [PATCH 142/172] =?UTF-8?q?mongodb=E8=AE=BF=E9=97=AE=E6=96=B9?= =?UTF-8?q?=E5=BC=8F=E5=8F=98=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/telpo/dipperposition/handler/NettyServerHandler.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java b/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java index 49c6089..0fe29bf 100644 --- a/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java +++ b/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java @@ -105,7 +105,7 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter { public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { //接收msg消息与上一章节相比,此处已经不需要自己进行解码} SocketChannel channel = (SocketChannel) ctx.channel(); - String ipAddress = channel.remoteAddress().getAddress().toString(); + String ipAddress = channel.remoteAddress().getHostString().toString(); //String message = " 接收到消息:{0}, 客户端IP:{1}"; log.info("接收到消息:" + msg + ",客户端IP:" + ipAddress); // if (nettyServerHandler.positionConfig != null) { From e96a4d76817449058a62d27efa72ad1b33cd440b Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Wed, 20 Jan 2021 08:50:21 +0800 Subject: [PATCH 143/172] =?UTF-8?q?mongodb=E8=AE=BF=E9=97=AE=E6=96=B9?= =?UTF-8?q?=E5=BC=8F=E5=8F=98=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dipperposition/handler/NettyServerHandler.java | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java b/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java index 0fe29bf..c5b80c1 100644 --- a/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java +++ b/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java @@ -105,15 +105,13 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter { public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { //接收msg消息与上一章节相比,此处已经不需要自己进行解码} SocketChannel channel = (SocketChannel) ctx.channel(); - String ipAddress = channel.remoteAddress().getHostString().toString(); - //String message = " 接收到消息:{0}, 客户端IP:{1}"; + String ipAddress = channel.remoteAddress().getHostString(); log.info("接收到消息:" + msg + ",客户端IP:" + ipAddress); -// if (nettyServerHandler.positionConfig != null) { -// log.info("config info is : " + nettyServerHandler.positionConfig.getCenterProvinceFilePath() + nettyServerHandler.positionConfig.getCenterProvince() + nettyServerHandler.positionConfig.getIpPositionRequestPath() + -// nettyServerHandler.positionConfig.getIpPositionRequestKey()); -// } else { -// log.info("positionConfig info is null!!!!!!!!!!!!!! "); -// } + if(ipAddress.contains(":")) { + String[] ipAddressArr = ipAddress.split(":"); + ipAddress = ipAddressArr[0].replace("/",""); + } + log.info("新客户端IP:" + ipAddress); String channelAns = ""; // 返回时间指令 From b41432dbde602317e8da65a79f54b763befffd71 Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Wed, 20 Jan 2021 09:05:58 +0800 Subject: [PATCH 144/172] =?UTF-8?q?mongodb=E8=AE=BF=E9=97=AE=E6=96=B9?= =?UTF-8?q?=E5=BC=8F=E5=8F=98=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/IProvinceInfoService.java | 4 +-- .../service/IpProvinceService.java | 10 ------- .../service/impl/IpProvinceServiceImpl.java | 28 +++++++++---------- .../service/impl/ProvinceInfoServiceImpl.java | 11 +++++--- 4 files changed, 22 insertions(+), 31 deletions(-) diff --git a/src/main/java/com/telpo/dipperposition/service/IProvinceInfoService.java b/src/main/java/com/telpo/dipperposition/service/IProvinceInfoService.java index dafa7d6..a924d91 100644 --- a/src/main/java/com/telpo/dipperposition/service/IProvinceInfoService.java +++ b/src/main/java/com/telpo/dipperposition/service/IProvinceInfoService.java @@ -27,11 +27,9 @@ public interface IProvinceInfoService { * 更新省份经纬度信息 * * @param query - * @param update * @return */ - boolean updateProvinceInfoEntity( - ProvinceInfoEntity query, ProvinceInfoEntity update); + boolean updateProvinceInfoEntity(ProvinceInfoEntity query); /** * 根据ID移除IP省份记录 diff --git a/src/main/java/com/telpo/dipperposition/service/IpProvinceService.java b/src/main/java/com/telpo/dipperposition/service/IpProvinceService.java index cb58ab0..a216dac 100644 --- a/src/main/java/com/telpo/dipperposition/service/IpProvinceService.java +++ b/src/main/java/com/telpo/dipperposition/service/IpProvinceService.java @@ -21,16 +21,6 @@ public interface IpProvinceService { */ boolean saveIpProvince(IpProvinceEntity entity); - /** - * 更新IP省份 - * - * @param query - * @param update - * @return - */ - boolean updateIPProvince( - IpProvinceEntity query, IpProvinceEntity update); - /** * 根据ID移除IP省份记录 * diff --git a/src/main/java/com/telpo/dipperposition/service/impl/IpProvinceServiceImpl.java b/src/main/java/com/telpo/dipperposition/service/impl/IpProvinceServiceImpl.java index 24c54cc..b47baed 100644 --- a/src/main/java/com/telpo/dipperposition/service/impl/IpProvinceServiceImpl.java +++ b/src/main/java/com/telpo/dipperposition/service/impl/IpProvinceServiceImpl.java @@ -1,12 +1,18 @@ package com.telpo.dipperposition.service.impl; +import cn.hutool.core.collection.CollectionUtil; import com.telpo.dipperposition.entity.mongo.IpProvinceEntity; +import com.telpo.dipperposition.entity.mongo.ProvinceInfoEntity; import com.telpo.dipperposition.mapper.IpProvinceMapper; import com.telpo.dipperposition.service.IpProvinceService; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.ObjectUtils; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.domain.Example; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; import org.springframework.stereotype.Service; +import tools.BeanTools; import java.util.List; @@ -34,22 +40,14 @@ public class IpProvinceServiceImpl implements IpProvinceService { // } @Override public boolean saveIpProvince(IpProvinceEntity entity) { - ipProvinceMapper.saveIp(entity); - return true; - } - - @Override - public boolean updateIPProvince( - IpProvinceEntity query, IpProvinceEntity update) { - - ipProvinceMapper.updateIpFirst(query, update); + ipProvinceMapper.save(entity); return true; } @Override public boolean romveById(String id) { - ipProvinceMapper.deleteIpById(id); + ipProvinceMapper.deleteById(id); return false; } @@ -58,10 +56,12 @@ public class IpProvinceServiceImpl implements IpProvinceService { try { IpProvinceEntity query = new IpProvinceEntity(); query.setIp(ipAddress); - - List pushRecords = ipProvinceMapper.queryIpList(query); - if (ObjectUtils.isNotEmpty(pushRecords)) { - return pushRecords.get(0); + Example example = Example.of(query); + PageRequest pageable = PageRequest.of(0, 1); + Page data = ipProvinceMapper.findAll(example, pageable); + if (CollectionUtil.isNotEmpty(data.getContent())) { + List records = BeanTools.copyList(data.getContent(), IpProvinceEntity.class); + return records.get(0); } else { return null; } diff --git a/src/main/java/com/telpo/dipperposition/service/impl/ProvinceInfoServiceImpl.java b/src/main/java/com/telpo/dipperposition/service/impl/ProvinceInfoServiceImpl.java index da3f873..9ca927e 100644 --- a/src/main/java/com/telpo/dipperposition/service/impl/ProvinceInfoServiceImpl.java +++ b/src/main/java/com/telpo/dipperposition/service/impl/ProvinceInfoServiceImpl.java @@ -32,11 +32,14 @@ public class ProvinceInfoServiceImpl implements IProvinceInfoService { @Override public boolean saveProvinceInfo(ProvinceInfoEntity entity) { + + provinceInfoMapper.save(entity); return false; } @Override - public boolean updateProvinceInfoEntity(ProvinceInfoEntity query, ProvinceInfoEntity update) { + public boolean updateProvinceInfoEntity(ProvinceInfoEntity entity) { + provinceInfoMapper.save(entity); return false; } @@ -53,9 +56,9 @@ public class ProvinceInfoServiceImpl implements IProvinceInfoService { ProvinceInfoEntity query = new ProvinceInfoEntity(); query.setProvince(provicne); Example example = Example.of(query); - PageRequest pageable = PageRequest.of(0, 1); - Page data = provinceInfoMapper.findAll(example, pageable); - if (CollectionUtil.isNotEmpty(data.getContent())) { + PageRequest pageable = PageRequest.of(0, 1); + Page data = provinceInfoMapper.findAll(example, pageable); + if (CollectionUtil.isNotEmpty(data.getContent())) { List provinceInfos = BeanTools.copyList(data.getContent(), ProvinceInfoEntity.class); return provinceInfos.get(0); } else { From d877cccbc11123e1c41ca939160ffe7d8e6cb9e9 Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Wed, 20 Jan 2021 10:04:14 +0800 Subject: [PATCH 145/172] =?UTF-8?q?mongodb=E8=AE=BF=E9=97=AE=E6=96=B9?= =?UTF-8?q?=E5=BC=8F=E5=8F=98=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DipperAstPosAsyncTaskServiceImpl.java | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java b/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java index febe80a..5def78f 100644 --- a/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java +++ b/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java @@ -1,5 +1,6 @@ package com.telpo.dipperposition.service.impl; +import cn.hutool.core.bean.BeanUtil; import com.alibaba.fastjson.JSONObject; import com.telpo.dipperposition.common.*; import com.telpo.dipperposition.config.NettyServerConfig; @@ -20,7 +21,9 @@ import org.springframework.util.ResourceUtils; import java.io.File; import java.io.FileNotFoundException; import java.io.UnsupportedEncodingException; +import java.util.HashMap; import java.util.List; +import java.util.Map; /** * @program: DipperAstPosAsyncTaskServiceImpl @@ -58,14 +61,16 @@ public class DipperAstPosAsyncTaskServiceImpl implements IDipperAstPosAsyncTaskS IpProvinceEntity ipProvinceEntity = ipProvinceService.getIpProvince(ipAddress); if (ipProvinceEntity == null) { // 匹配不到,再请求高德IP定位服务。 - JSONObject userObj = new JSONObject(); - userObj.put("ip", ipAddress); - userObj.put("key", ipPositionRequestKey); - JSONObject json = okHttpUtil.postRequestWithJson(ipPositionRequestPath, null, userObj); - if (ObjectUtils.isNotEmpty(json)) { - String province = (String) json.get("province"); + //JSONObject userObj = new JSONObject(); + Map dataMap = new HashMap(); + dataMap.put("ip", ipAddress); + dataMap.put("key", ipPositionRequestKey); + StringBuffer buffer = okHttpUtil.getQueryString(ipPositionRequestPath, dataMap); + if (ObjectUtils.isNotEmpty(buffer)) { + JSONObject provinceJson = JSONObject.parseObject(buffer.toString()); + String province = (String)provinceJson.get("province"); if (ObjectUtils.isEmpty(province)) { - log.debug("json is :" + json.toString()); + log.debug("json is :" + buffer.toString()); return null; } return province; From 99721a6ff03a08a4d09bac2c915d9c198b60af13 Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Wed, 20 Jan 2021 12:42:14 +0800 Subject: [PATCH 146/172] =?UTF-8?q?mongodb=E8=AE=BF=E9=97=AE=E6=96=B9?= =?UTF-8?q?=E5=BC=8F=E5=8F=98=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/DipperAstPosAsyncTaskServiceImpl.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java b/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java index 5def78f..51aa1d3 100644 --- a/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java +++ b/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java @@ -85,7 +85,6 @@ public class DipperAstPosAsyncTaskServiceImpl implements IDipperAstPosAsyncTaskS } // 将IP对应的省会保存到mongoDB - @Async("asyncServiceExecutor") public void createIPProvince(String ipAddress, String province) { log.debug("异步创建推送失败任务记录!"); try { @@ -105,7 +104,7 @@ public class DipperAstPosAsyncTaskServiceImpl implements IDipperAstPosAsyncTaskS * @param ipAddress */ @Override - @Async("asyncServiceExecutor") + //@Async("asyncServiceExecutor") public String pushAstPos(String ipAddress) { this.ipPositionRequestKey = positionConfig.getIpPositionRequestKey(); this.ipPositionRequestPath = positionConfig.getIpPositionRequestPath(); From e17954f5a2e4337edaf76bd69bb58842daedf549 Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Wed, 20 Jan 2021 18:55:50 +0800 Subject: [PATCH 147/172] =?UTF-8?q?mongodb=E8=AE=BF=E9=97=AE=E6=96=B9?= =?UTF-8?q?=E5=BC=8F=E5=8F=98=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- setup_production.sh => setup_pro.sh | 0 .../impl/DipperAstPosAsyncTaskServiceImpl.java | 18 +++++++++++++----- 2 files changed, 13 insertions(+), 5 deletions(-) rename setup_production.sh => setup_pro.sh (100%) diff --git a/setup_production.sh b/setup_pro.sh similarity index 100% rename from setup_production.sh rename to setup_pro.sh diff --git a/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java b/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java index 51aa1d3..eea974f 100644 --- a/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java +++ b/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java @@ -11,6 +11,7 @@ import com.telpo.dipperposition.service.IDipperAstPosAsyncTaskService; import com.telpo.dipperposition.service.IProvinceInfoService; import com.telpo.dipperposition.service.IpProvinceService; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang.StringUtils; import org.apache.commons.lang3.ObjectUtils; import org.apache.logging.log4j.util.PropertiesUtil; import org.springframework.beans.factory.annotation.Autowired; @@ -67,13 +68,20 @@ public class DipperAstPosAsyncTaskServiceImpl implements IDipperAstPosAsyncTaskS dataMap.put("key", ipPositionRequestKey); StringBuffer buffer = okHttpUtil.getQueryString(ipPositionRequestPath, dataMap); if (ObjectUtils.isNotEmpty(buffer)) { - JSONObject provinceJson = JSONObject.parseObject(buffer.toString()); - String province = (String)provinceJson.get("province"); - if (ObjectUtils.isEmpty(province)) { - log.debug("json is :" + buffer.toString()); + String provinceBuffer = buffer.toString(); + if (StringUtils.isEmpty(provinceBuffer)) { + log.debug("IP省份获取错误,结果为空"); return null; + } else { + log.debug("IP省份获取错误,结果为:" + provinceBuffer); + JSONObject provinceJson = JSONObject.parseObject(provinceBuffer); + String province = (String)provinceJson.get("province"); + if (ObjectUtils.isEmpty(province)) { + log.debug("json is :" + buffer.toString()); + return null; + } + return province; } - return province; } else { // 意外错误 log.debug("ip address is null"); From e8201b6c183b81e5300302edb33f33d129b4ab60 Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Wed, 20 Jan 2021 19:04:22 +0800 Subject: [PATCH 148/172] =?UTF-8?q?mongodb=E8=AE=BF=E9=97=AE=E6=96=B9?= =?UTF-8?q?=E5=BC=8F=E5=8F=98=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../impl/DipperAstPosAsyncTaskServiceImpl.java | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java b/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java index eea974f..c122805 100644 --- a/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java +++ b/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java @@ -67,14 +67,19 @@ public class DipperAstPosAsyncTaskServiceImpl implements IDipperAstPosAsyncTaskS dataMap.put("ip", ipAddress); dataMap.put("key", ipPositionRequestKey); StringBuffer buffer = okHttpUtil.getQueryString(ipPositionRequestPath, dataMap); - if (ObjectUtils.isNotEmpty(buffer)) { - String provinceBuffer = buffer.toString(); - if (StringUtils.isEmpty(provinceBuffer)) { + JSONObject paramObject = new JSONObject(); + String result = okHttpUtil.postJsonParams(buffer.toString(), paramObject.toJSONString()); + if (ObjectUtils.isNotEmpty(result)) { + if (StringUtils.isEmpty(result)) { log.debug("IP省份获取错误,结果为空"); return null; } else { - log.debug("IP省份获取错误,结果为:" + provinceBuffer); - JSONObject provinceJson = JSONObject.parseObject(provinceBuffer); + if (result.equals("FAIL")) { + log.debug("IP省份获取错误,结果为FAIL"); + return null; + } + log.debug("IP省份获取错误,结果为:" + result); + JSONObject provinceJson = JSONObject.parseObject(result); String province = (String)provinceJson.get("province"); if (ObjectUtils.isEmpty(province)) { log.debug("json is :" + buffer.toString()); From 93b1a96838f547385c53190d56ca128de7dc50d3 Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Wed, 20 Jan 2021 19:33:41 +0800 Subject: [PATCH 149/172] =?UTF-8?q?mongodb=E8=AE=BF=E9=97=AE=E6=96=B9?= =?UTF-8?q?=E5=BC=8F=E5=8F=98=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/telpo/dipperposition/common/OkHttpUtil.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/main/java/com/telpo/dipperposition/common/OkHttpUtil.java b/src/main/java/com/telpo/dipperposition/common/OkHttpUtil.java index daac774..5e4dd18 100644 --- a/src/main/java/com/telpo/dipperposition/common/OkHttpUtil.java +++ b/src/main/java/com/telpo/dipperposition/common/OkHttpUtil.java @@ -98,6 +98,17 @@ public class OkHttpUtil { return execNewCall(request); } + + /** Post请求发送JSON数据....{"name":"zhangsan","pwd":"123456"} 参数一:请求Url 参数二:请求的JSON 参数三:请求回调 */ + public String getJsonParams(String url, String jsonParams) { + Request request = new Request.Builder().url(url).addHeader("application/json","charset=utf-8").build(); + log.debug(MessageFormat.format("get json to url<{0}>", url)); + + return execNewCall(request); + } + + + /** Post请求发送xml数据.... 参数一:请求Url 参数二:请求的xmlString 参数三:请求回调 */ public String postXmlParams(String url, String xml) { RequestBody requestBody = From d57bc4398215c0e7849af60c30f1dc9f017e3a48 Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Wed, 20 Jan 2021 19:42:59 +0800 Subject: [PATCH 150/172] =?UTF-8?q?mongodb=E8=AE=BF=E9=97=AE=E6=96=B9?= =?UTF-8?q?=E5=BC=8F=E5=8F=98=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../config/db/MongoDbContext.java | 65 ------------------- .../config/db/MongoListProperties.java | 30 --------- .../config/db/MultiMongoTemplate.java | 26 -------- .../DipperAstPosAsyncTaskServiceImpl.java | 2 +- 4 files changed, 1 insertion(+), 122 deletions(-) delete mode 100644 src/main/java/com/telpo/dipperposition/config/db/MongoDbContext.java delete mode 100644 src/main/java/com/telpo/dipperposition/config/db/MongoListProperties.java delete mode 100644 src/main/java/com/telpo/dipperposition/config/db/MultiMongoTemplate.java diff --git a/src/main/java/com/telpo/dipperposition/config/db/MongoDbContext.java b/src/main/java/com/telpo/dipperposition/config/db/MongoDbContext.java deleted file mode 100644 index 14fbcd8..0000000 --- a/src/main/java/com/telpo/dipperposition/config/db/MongoDbContext.java +++ /dev/null @@ -1,65 +0,0 @@ -package com.telpo.dipperposition.config.db; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.annotation.Bean; -import org.springframework.data.mongodb.MongoDbFactory; -import org.springframework.data.mongodb.core.SimpleMongoClientDbFactory; -import org.springframework.stereotype.Component; -import org.springframework.util.CollectionUtils; - -import javax.annotation.PostConstruct; -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; - -/** - * @program: DataPushServer - * @description: mongdb数据库连接上下文 - * @author: linwl - * @create: 2020-07-11 14:31 - */ -@Component -public class MongoDbContext { - - private static final Map MONGO_CLIENT_DB_FACTORY_MAP = new HashMap<>(); - private static final ThreadLocal MONGO_DB_FACTORY_THREAD_LOCAL = new ThreadLocal<>(); - @Autowired - MongoListProperties mongoListProperties; - - public static MongoDbFactory getMongoDbFactory() { - return MONGO_DB_FACTORY_THREAD_LOCAL.get(); - } - - public static void setMongoDbFactory(String name) { - MONGO_DB_FACTORY_THREAD_LOCAL.set(MONGO_CLIENT_DB_FACTORY_MAP.get(name)); - } - - public static void removeMongoDbFactory() { - MONGO_DB_FACTORY_THREAD_LOCAL.remove(); - } - - @PostConstruct - public void afterPropertiesSet() { - if (!CollectionUtils.isEmpty(mongoListProperties.getDblist())) { - mongoListProperties - .getDblist() - .forEach( - info -> { - MONGO_CLIENT_DB_FACTORY_MAP.put( - info.getDatabase(), new SimpleMongoClientDbFactory(info.getUri())); - }); - } - } - - @Bean(name = "mongoTemplate") - public MultiMongoTemplate dynamicMongoTemplate() { - Iterator iterator = MONGO_CLIENT_DB_FACTORY_MAP.values().iterator(); - return new MultiMongoTemplate(iterator.next()); - } - - @Bean(name = "mongoDbFactory") - public MongoDbFactory mongoDbFactory() { - Iterator iterator = MONGO_CLIENT_DB_FACTORY_MAP.values().iterator(); - return iterator.next(); - } -} diff --git a/src/main/java/com/telpo/dipperposition/config/db/MongoListProperties.java b/src/main/java/com/telpo/dipperposition/config/db/MongoListProperties.java deleted file mode 100644 index 804eff3..0000000 --- a/src/main/java/com/telpo/dipperposition/config/db/MongoListProperties.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.telpo.dipperposition.config.db; - -import lombok.Data; -import lombok.Getter; -import lombok.Setter; -import lombok.ToString; -import org.springframework.boot.context.properties.ConfigurationProperties; - -import java.util.List; - -/** - * @program: DataPushServer - * @description: mongo连接配置类 - * @author: linwl - * @create: 2020-07-11 14:41 - */ -@Getter -@Setter -@ToString -@ConfigurationProperties(prefix = "mongo.datasource") -public class MongoListProperties { - - private List dblist; - - @Data - public static class MongoList { - private String uri; - private String database; - } -} diff --git a/src/main/java/com/telpo/dipperposition/config/db/MultiMongoTemplate.java b/src/main/java/com/telpo/dipperposition/config/db/MultiMongoTemplate.java deleted file mode 100644 index df79df4..0000000 --- a/src/main/java/com/telpo/dipperposition/config/db/MultiMongoTemplate.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.telpo.dipperposition.config.db; - -import com.mongodb.client.MongoDatabase; -import lombok.extern.slf4j.Slf4j; -import org.springframework.data.mongodb.MongoDbFactory; -import org.springframework.data.mongodb.core.MongoTemplate; - -/** - * @program: DataPushServer - * @description: 多mongo数据源配置 - * @author: linwl - * @create: 2020-07-11 14:21 - */ -@Slf4j -public class MultiMongoTemplate extends MongoTemplate { - - public MultiMongoTemplate(MongoDbFactory mongoDbFactory) { - super(mongoDbFactory); - } - - @Override - protected MongoDatabase doGetDatabase() { - MongoDbFactory mongoDbFactory = MongoDbContext.getMongoDbFactory(); - return mongoDbFactory == null ? super.doGetDatabase() : mongoDbFactory.getDb(); - } -} diff --git a/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java b/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java index c122805..3384ab6 100644 --- a/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java +++ b/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java @@ -68,7 +68,7 @@ public class DipperAstPosAsyncTaskServiceImpl implements IDipperAstPosAsyncTaskS dataMap.put("key", ipPositionRequestKey); StringBuffer buffer = okHttpUtil.getQueryString(ipPositionRequestPath, dataMap); JSONObject paramObject = new JSONObject(); - String result = okHttpUtil.postJsonParams(buffer.toString(), paramObject.toJSONString()); + String result = okHttpUtil.getJsonParams(buffer.toString(), paramObject.toJSONString()); if (ObjectUtils.isNotEmpty(result)) { if (StringUtils.isEmpty(result)) { log.debug("IP省份获取错误,结果为空"); From cf45a1856195bea8e7c9c377d6c708b18b3d3137 Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Wed, 20 Jan 2021 20:23:22 +0800 Subject: [PATCH 151/172] =?UTF-8?q?mongodb=E8=AE=BF=E9=97=AE=E6=96=B9?= =?UTF-8?q?=E5=BC=8F=E5=8F=98=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 6 ------ .../service/impl/DipperAstPosAsyncTaskServiceImpl.java | 8 +++++--- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/pom.xml b/pom.xml index 56a6dc9..12008e3 100644 --- a/pom.xml +++ b/pom.xml @@ -138,12 +138,6 @@ 2.0 - - com.mongodb - mongo - 1.0 - - diff --git a/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java b/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java index 3384ab6..d1ea3a1 100644 --- a/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java +++ b/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java @@ -25,6 +25,7 @@ import java.io.UnsupportedEncodingException; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Objects; /** * @program: DipperAstPosAsyncTaskServiceImpl @@ -78,7 +79,7 @@ public class DipperAstPosAsyncTaskServiceImpl implements IDipperAstPosAsyncTaskS log.debug("IP省份获取错误,结果为FAIL"); return null; } - log.debug("IP省份获取错误,结果为:" + result); + //log.debug("IP省份获取错误,结果为:" + result); JSONObject provinceJson = JSONObject.parseObject(result); String province = (String)provinceJson.get("province"); if (ObjectUtils.isEmpty(province)) { @@ -99,16 +100,17 @@ public class DipperAstPosAsyncTaskServiceImpl implements IDipperAstPosAsyncTaskS // 将IP对应的省会保存到mongoDB public void createIPProvince(String ipAddress, String province) { - log.debug("异步创建推送失败任务记录!"); + log.debug("创建IP省份记录!"); try { IpProvinceEntity ipProvinceEntity = ipProvinceService.getIpProvince(ipAddress); if (ipProvinceEntity == null) { + ipProvinceEntity = new IpProvinceEntity(); ipProvinceEntity.setIp(ipAddress); ipProvinceEntity.setProvince(province); ipProvinceService.saveIpProvince(ipProvinceEntity); } } catch (Exception e) { - log.error("创建推送失败记录异常:", e); + log.error("创建IP省份记录异常:", e); } } From 7e3d83bf8b37c917ae3f8d312b803fb9e9ac0084 Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Wed, 20 Jan 2021 20:46:50 +0800 Subject: [PATCH 152/172] =?UTF-8?q?mongodb=E8=AE=BF=E9=97=AE=E6=96=B9?= =?UTF-8?q?=E5=BC=8F=E5=8F=98=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/ProvinceInfoServiceImpl.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/telpo/dipperposition/service/impl/ProvinceInfoServiceImpl.java b/src/main/java/com/telpo/dipperposition/service/impl/ProvinceInfoServiceImpl.java index 9ca927e..b124ac9 100644 --- a/src/main/java/com/telpo/dipperposition/service/impl/ProvinceInfoServiceImpl.java +++ b/src/main/java/com/telpo/dipperposition/service/impl/ProvinceInfoServiceImpl.java @@ -15,6 +15,7 @@ import org.springframework.stereotype.Service; import tools.BeanTools; import java.util.List; +import java.util.Optional; /** * @program: DataPushServer @@ -56,14 +57,13 @@ public class ProvinceInfoServiceImpl implements IProvinceInfoService { ProvinceInfoEntity query = new ProvinceInfoEntity(); query.setProvince(provicne); Example example = Example.of(query); - PageRequest pageable = PageRequest.of(0, 1); - Page data = provinceInfoMapper.findAll(example, pageable); - if (CollectionUtil.isNotEmpty(data.getContent())) { - List provinceInfos = BeanTools.copyList(data.getContent(), ProvinceInfoEntity.class); - return provinceInfos.get(0); - } else { - return null; - } +// PageRequest pageable = PageRequest.of(0, 1); + Optional data = provinceInfoMapper.findOne(example); +// if (CollectionUtil.isNotEmpty(data.getContent())) { +// +// List provinceInfos = BeanTools.copyList(data.getContent(), ProvinceInfoEntity.class); +// return provinceInfos.get(0); + return data.get(); } catch (Exception e) { log.error("获取省份异常:", e); return null; From 0ceb9faa2a8161506255b383eeb581f4ef4faa65 Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Wed, 20 Jan 2021 21:09:42 +0800 Subject: [PATCH 153/172] =?UTF-8?q?mongodb=E8=AE=BF=E9=97=AE=E6=96=B9?= =?UTF-8?q?=E5=BC=8F=E5=8F=98=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../impl/DipperAstPosAsyncTaskServiceImpl.java | 15 ++++++++++++--- .../service/impl/ProvinceInfoServiceImpl.java | 16 +++++++++------- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java b/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java index d1ea3a1..98ccfd2 100644 --- a/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java +++ b/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java @@ -137,11 +137,20 @@ public class DipperAstPosAsyncTaskServiceImpl implements IDipperAstPosAsyncTaskS } String lonAndAlt = null; - ProvinceInfoEntity entity = provinceInfoService.getProvinceInfo(centerAddress); - if (entity != null) { - lonAndAlt = entity.getProvince(); + try { + byte[] utf8 = centerAddress.getBytes("UTF-8"); + String utf8CenterAddress = new String(utf8, "UTF-8"); + log.debug("centerAddress is " + utf8CenterAddress); + + ProvinceInfoEntity entity = provinceInfoService.getProvinceInfo(utf8CenterAddress); + if (entity != null) { + lonAndAlt = entity.getProvince(); + } + } catch (Exception e) { + log.error(e.getMessage()); } + // (2) 处理返回结果 if (lonAndAlt == null) { // null处理 diff --git a/src/main/java/com/telpo/dipperposition/service/impl/ProvinceInfoServiceImpl.java b/src/main/java/com/telpo/dipperposition/service/impl/ProvinceInfoServiceImpl.java index b124ac9..6ccb38a 100644 --- a/src/main/java/com/telpo/dipperposition/service/impl/ProvinceInfoServiceImpl.java +++ b/src/main/java/com/telpo/dipperposition/service/impl/ProvinceInfoServiceImpl.java @@ -2,6 +2,7 @@ package com.telpo.dipperposition.service.impl; import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.collection.CollectionUtil; +import com.telpo.dipperposition.entity.mongo.IpProvinceEntity; import com.telpo.dipperposition.entity.mongo.ProvinceInfoEntity; import com.telpo.dipperposition.mapper.ProvinceInfoMapper; import com.telpo.dipperposition.service.IProvinceInfoService; @@ -57,13 +58,14 @@ public class ProvinceInfoServiceImpl implements IProvinceInfoService { ProvinceInfoEntity query = new ProvinceInfoEntity(); query.setProvince(provicne); Example example = Example.of(query); -// PageRequest pageable = PageRequest.of(0, 1); - Optional data = provinceInfoMapper.findOne(example); -// if (CollectionUtil.isNotEmpty(data.getContent())) { -// -// List provinceInfos = BeanTools.copyList(data.getContent(), ProvinceInfoEntity.class); -// return provinceInfos.get(0); - return data.get(); + PageRequest pageable = PageRequest.of(0, 1); + Page data = provinceInfoMapper.findAll(example, pageable); + if (CollectionUtil.isNotEmpty(data.getContent())) { + List records = BeanTools.copyList(data.getContent(), ProvinceInfoEntity.class); + return records.get(0); + } else { + return null; + } } catch (Exception e) { log.error("获取省份异常:", e); return null; From 53b19e53c5860549fc407763414926030d541138 Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Wed, 20 Jan 2021 21:23:52 +0800 Subject: [PATCH 154/172] =?UTF-8?q?mongodb=E8=AE=BF=E9=97=AE=E6=96=B9?= =?UTF-8?q?=E5=BC=8F=E5=8F=98=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mapper/ProvinceInfoMapper.java | 5 ----- .../service/impl/IpProvinceServiceImpl.java | 17 ++++++++--------- .../service/impl/ProvinceInfoServiceImpl.java | 15 ++++++--------- 3 files changed, 14 insertions(+), 23 deletions(-) diff --git a/src/main/java/com/telpo/dipperposition/mapper/ProvinceInfoMapper.java b/src/main/java/com/telpo/dipperposition/mapper/ProvinceInfoMapper.java index 5059b33..2033a8e 100644 --- a/src/main/java/com/telpo/dipperposition/mapper/ProvinceInfoMapper.java +++ b/src/main/java/com/telpo/dipperposition/mapper/ProvinceInfoMapper.java @@ -1,14 +1,9 @@ package com.telpo.dipperposition.mapper; -import com.telpo.dipperposition.annotation.MongoSwitch; -import com.telpo.dipperposition.entity.mongo.IpProvinceEntity; import com.telpo.dipperposition.entity.mongo.ProvinceInfoEntity; -import db.BaseMongoDbDao; import org.springframework.data.mongodb.repository.MongoRepository; import org.springframework.stereotype.Repository; -import java.util.List; - /** * @program: ProvinceInfoMapper * @description: 省份位置记录mapper diff --git a/src/main/java/com/telpo/dipperposition/service/impl/IpProvinceServiceImpl.java b/src/main/java/com/telpo/dipperposition/service/impl/IpProvinceServiceImpl.java index b47baed..deb0626 100644 --- a/src/main/java/com/telpo/dipperposition/service/impl/IpProvinceServiceImpl.java +++ b/src/main/java/com/telpo/dipperposition/service/impl/IpProvinceServiceImpl.java @@ -5,16 +5,19 @@ import com.telpo.dipperposition.entity.mongo.IpProvinceEntity; import com.telpo.dipperposition.entity.mongo.ProvinceInfoEntity; import com.telpo.dipperposition.mapper.IpProvinceMapper; import com.telpo.dipperposition.service.IpProvinceService; +import jdk.nashorn.internal.runtime.options.Option; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.ObjectUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Example; +import org.springframework.data.domain.ExampleMatcher; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; import org.springframework.stereotype.Service; import tools.BeanTools; import java.util.List; +import java.util.Optional; /** * @program: DataPushServer @@ -56,15 +59,11 @@ public class IpProvinceServiceImpl implements IpProvinceService { try { IpProvinceEntity query = new IpProvinceEntity(); query.setIp(ipAddress); - Example example = Example.of(query); - PageRequest pageable = PageRequest.of(0, 1); - Page data = ipProvinceMapper.findAll(example, pageable); - if (CollectionUtil.isNotEmpty(data.getContent())) { - List records = BeanTools.copyList(data.getContent(), IpProvinceEntity.class); - return records.get(0); - } else { - return null; - } + //忽略_class属性,不参与查询 + ExampleMatcher matcher = ExampleMatcher.matching().withIgnorePaths("_class"); + Example example = Example.of(query, matcher); + Optional data = ipProvinceMapper.findOne(example); + return data.get(); } catch (Exception e) { log.error("获取IP省份异常:", e); return null; diff --git a/src/main/java/com/telpo/dipperposition/service/impl/ProvinceInfoServiceImpl.java b/src/main/java/com/telpo/dipperposition/service/impl/ProvinceInfoServiceImpl.java index 6ccb38a..668f2ad 100644 --- a/src/main/java/com/telpo/dipperposition/service/impl/ProvinceInfoServiceImpl.java +++ b/src/main/java/com/telpo/dipperposition/service/impl/ProvinceInfoServiceImpl.java @@ -10,6 +10,7 @@ import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.ObjectUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Example; +import org.springframework.data.domain.ExampleMatcher; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; import org.springframework.stereotype.Service; @@ -57,15 +58,11 @@ public class ProvinceInfoServiceImpl implements IProvinceInfoService { try { ProvinceInfoEntity query = new ProvinceInfoEntity(); query.setProvince(provicne); - Example example = Example.of(query); - PageRequest pageable = PageRequest.of(0, 1); - Page data = provinceInfoMapper.findAll(example, pageable); - if (CollectionUtil.isNotEmpty(data.getContent())) { - List records = BeanTools.copyList(data.getContent(), ProvinceInfoEntity.class); - return records.get(0); - } else { - return null; - } + //忽略_class属性,不参与查询 + ExampleMatcher matcher = ExampleMatcher.matching().withIgnorePaths("_class"); + Example example = Example.of(query, matcher); + Optional data = provinceInfoMapper.findOne(example); + return data.get(); } catch (Exception e) { log.error("获取省份异常:", e); return null; From 46fc92d62d88a06122499a0c21ad6c2b86e99fa9 Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Wed, 20 Jan 2021 21:34:48 +0800 Subject: [PATCH 155/172] =?UTF-8?q?mongodb=E8=AE=BF=E9=97=AE=E6=96=B9?= =?UTF-8?q?=E5=BC=8F=E5=8F=98=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DipperAstPosAsyncTaskServiceImpl.java | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java b/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java index 98ccfd2..b4f72e6 100644 --- a/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java +++ b/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java @@ -136,7 +136,8 @@ public class DipperAstPosAsyncTaskServiceImpl implements IDipperAstPosAsyncTaskS createIPProvince(ipAddress, centerAddress); } - String lonAndAlt = null; + String lonValue = null; + String altValue = null; try { byte[] utf8 = centerAddress.getBytes("UTF-8"); String utf8CenterAddress = new String(utf8, "UTF-8"); @@ -144,7 +145,8 @@ public class DipperAstPosAsyncTaskServiceImpl implements IDipperAstPosAsyncTaskS ProvinceInfoEntity entity = provinceInfoService.getProvinceInfo(utf8CenterAddress); if (entity != null) { - lonAndAlt = entity.getProvince(); + lonValue = entity.getLon(); + altValue = entity.getAlt(); } } catch (Exception e) { log.error(e.getMessage()); @@ -152,29 +154,29 @@ public class DipperAstPosAsyncTaskServiceImpl implements IDipperAstPosAsyncTaskS // (2) 处理返回结果 - if (lonAndAlt == null) { + if (lonValue == null) { // null处理 log.error("系统错误,请联系系统管理员。"); return null; } // push to GNNS Server - return getCmdOfPos(lonAndAlt); + return getCmdOfPos(lonValue, altValue); } // 组装命令发送给设备 - private String getCmdOfPos(String astPos) { + private String getCmdOfPos(String lonStr, String altStr) { // 时间和位置不是从服务器获取,而是本地生成 - String[] astPosArray = astPos.split(","); - String lan = astPosArray[0].trim(); - String alt = astPosArray[1].trim(); - double lanValue = Double.parseDouble(lan) * 10000000; +// String[] astPosArray = astPos.split(","); +// String lan = astPosArray[0].trim(); +// String alt = astPosArray[1].trim(); + double lanValue = Double.parseDouble(lonStr) * 10000000; long lanLongValue = Double.doubleToLongBits(lanValue); if (lanLongValue < 0) { lanLongValue = lanLongValue + 4294967295L + 1; } - double altValue = Double.parseDouble(alt) * 10000000; + double altValue = Double.parseDouble(altStr) * 10000000; long altLongValue = Double.doubleToLongBits(altValue); if (altLongValue < 0) { altLongValue = altLongValue + 4294967295L + 1; From 49fe9c0799f711f6ed588e3614e1b3ae705a0b11 Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Thu, 21 Jan 2021 09:03:07 +0800 Subject: [PATCH 156/172] =?UTF-8?q?mongodb=E8=AE=BF=E9=97=AE=E6=96=B9?= =?UTF-8?q?=E5=BC=8F=E5=8F=98=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/DipperAstPosAsyncTaskServiceImpl.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java b/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java index b4f72e6..8de6387 100644 --- a/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java +++ b/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java @@ -181,6 +181,11 @@ public class DipperAstPosAsyncTaskServiceImpl implements IDipperAstPosAsyncTaskS if (altLongValue < 0) { altLongValue = altLongValue + 4294967295L + 1; } + // 小端模式补码 + // FFFFFFFF - 439C3270 + 1= BC63CD90(补码) + lanLongValue = 4294967295L - lanLongValue + 1; + altLongValue = 4294967295L - altLongValue + 1; + // 数值换算举例(以经度举例。纬度、高度、位置精度换算方法一致): // (1)经度数值为 113.431,则换算方法如下: // 113.431/比例因子 = 1134310000(十进制) @@ -199,6 +204,8 @@ public class DipperAstPosAsyncTaskServiceImpl implements IDipperAstPosAsyncTaskS // 10 00 表示长度为 16 // 70 32 9C 43 表示注入的辅助经度为 113.431 度 // D0 B2 CE 0D 表示注入的辅助纬度为 23.165 度 + // 70 17 00 00 表示注入的辅助高度为 60 米 + // 40 0D 03 00 表示注入的位置精度为 2000 米 // 00 2F 为校验和 // astTimeCmd 组装 @@ -206,6 +213,8 @@ public class DipperAstPosAsyncTaskServiceImpl implements IDipperAstPosAsyncTaskS astTimeCmd += "1000"; astTimeCmd += HexConvert.encodeHEX(lanLongValue); astTimeCmd += HexConvert.encodeHEX(altLongValue); + astTimeCmd += "70170000"; + astTimeCmd += "400D0300"; return astTimeCmd + HexConvert.makeChecksum(astTimeCmd); From 2d45693abef3380bfb2be1aed53e0fad4352f137 Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Thu, 21 Jan 2021 11:44:54 +0800 Subject: [PATCH 157/172] =?UTF-8?q?=E5=A2=9E=E5=8A=A0ALL=EF=BC=8C=E8=BF=94?= =?UTF-8?q?=E5=9B=9E3=E4=B8=AA=E5=8C=85=EF=BC=9B=E6=97=B6=E9=97=B4?= =?UTF-8?q?=E7=B2=BE=E5=BA=A6=E6=94=B9=E4=B8=BA3=E7=A7=92=EF=BC=9B?= =?UTF-8?q?=E5=AE=9A=E4=BD=8D=E7=B2=BE=E5=BA=A6=E6=94=B9=E4=B8=BA1000?= =?UTF-8?q?=E7=B1=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../handler/NettyServerHandler.java | 16 +++++++++++----- .../impl/DipperAstPosAsyncTaskServiceImpl.java | 5 +++-- .../impl/DipperAstTimeAsyncTaskServiceImpl.java | 3 ++- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java b/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java index c5b80c1..45f7b9f 100644 --- a/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java +++ b/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java @@ -28,9 +28,11 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter { private static String AST_TIME_CMD = "TIME"; private static String AST_POS_CMD = "POS"; private static String AST_EPH_CMD = "EPH"; + private static String AST_ALL_CMD = "ALL"; private static String AST_TIME_CMD_BYTE = "54494d45"; private static String AST_POS_CMD_BYTE = "504f53"; private static String AST_EPH_CMD_BYTE = "455048"; + private static String AST_ALL_CMD_BYTE = "616C6C"; @Autowired private PositionConfig positionConfig; @@ -140,17 +142,21 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter { channelAns = nettyServerHandler.dipperDataAsyncTaskService.getAstEPH(); } + // 最后把SDBP-AST-TIME、SDBP-AST-POS、SDBP-AST-EPH并包一起发给设备。 + // 设备采用16进制获取数据,则代理服务器也是采用16进制返回数据。 + // 通知客户端链消息发送成功 + if (AST_ALL_CMD.equals(msg)) { + channelAns = nettyServerHandler.dipperTimeAsyncTaskService.pushAstTime(); + channelAns += nettyServerHandler.dipperAstPosAsyncTaskService.pushAstPos(ipAddress); + channelAns += nettyServerHandler.dipperDataAsyncTaskService.getAstEPH(); + } + log.info(channelAns); if (channelAns != null) { buf = Unpooled.buffer(channelAns.getBytes().length); buf.writeBytes(channelAns.getBytes("GBK")); ctx.writeAndFlush(buf); } - // 最后把SDBP-AST-TIME、SDBP-AST-POS、SDBP-AST-EPH并包一起发给设备。 - // 设备采用16进制获取数据,则代理服务器也是采用16进制返回数据。 - // 通知客户端链消息发送成功 - //ctx.write("你也好哦"); - //ctx.flush(); } /** diff --git a/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java b/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java index 8de6387..56c3ea6 100644 --- a/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java +++ b/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java @@ -205,7 +205,8 @@ public class DipperAstPosAsyncTaskServiceImpl implements IDipperAstPosAsyncTaskS // 70 32 9C 43 表示注入的辅助经度为 113.431 度 // D0 B2 CE 0D 表示注入的辅助纬度为 23.165 度 // 70 17 00 00 表示注入的辅助高度为 60 米 - // 40 0D 03 00 表示注入的位置精度为 2000 米 + // 40 0D 03 00 表示注入的位置精度为 2000 米 030d40 + // A0 86 01 00 表示注入的位置精度为 1000 米 0186a0 // 00 2F 为校验和 // astTimeCmd 组装 @@ -214,7 +215,7 @@ public class DipperAstPosAsyncTaskServiceImpl implements IDipperAstPosAsyncTaskS astTimeCmd += HexConvert.encodeHEX(lanLongValue); astTimeCmd += HexConvert.encodeHEX(altLongValue); astTimeCmd += "70170000"; - astTimeCmd += "400D0300"; + astTimeCmd += "A0860100"; return astTimeCmd + HexConvert.makeChecksum(astTimeCmd); diff --git a/src/main/java/com/telpo/dipperposition/service/impl/DipperAstTimeAsyncTaskServiceImpl.java b/src/main/java/com/telpo/dipperposition/service/impl/DipperAstTimeAsyncTaskServiceImpl.java index 734aefd..c5bf044 100644 --- a/src/main/java/com/telpo/dipperposition/service/impl/DipperAstTimeAsyncTaskServiceImpl.java +++ b/src/main/java/com/telpo/dipperposition/service/impl/DipperAstTimeAsyncTaskServiceImpl.java @@ -40,6 +40,7 @@ public class DipperAstTimeAsyncTaskServiceImpl implements IDipperAstTimeAsyncTas // 14 表示 20 日 // 0C 22 38 00 00 00 00 00 表示 UTC时间,为12时34分56.0秒(小数秒建议固定为 0) // 00 28 6B EE 表示 4 秒的时间精度(十六进制 EE6B2800 转为十进制为 4000000000,乘以比 例因子 10-9就是 4 秒) + // 00 5E D0 B2 表示 3 秒的时间精度(十六进制 B2 D0 5E 00 转为十进制为3000000000,乘以比 例因子 10-9就是 3 秒 小端模式00 5E D0 B2) // 00 2F 为校验和 // TODO astTimeCmd 组装 String astTimeCmd = "233E0402"; @@ -80,7 +81,7 @@ public class DipperAstTimeAsyncTaskServiceImpl implements IDipperAstTimeAsyncTas } astTimeCmd += hexSecondString; astTimeCmd += "0000000000"; - astTimeCmd += "00286BEE"; + astTimeCmd += "005ED0B2"; String hexIn = astTimeCmd + HexConvert.makeChecksum(astTimeCmd); log.info("DipperAstTimeAsyncTaskServiceImpl 返回时间:" + hexIn); From 6e7c0ada0b28ad78ed8d4c848fa025eb15fbd52f Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Thu, 21 Jan 2021 11:50:22 +0800 Subject: [PATCH 158/172] =?UTF-8?q?ALL=E6=94=B9=E4=B8=BAall?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/telpo/dipperposition/handler/NettyServerHandler.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java b/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java index 45f7b9f..eca0d3e 100644 --- a/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java +++ b/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java @@ -28,7 +28,7 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter { private static String AST_TIME_CMD = "TIME"; private static String AST_POS_CMD = "POS"; private static String AST_EPH_CMD = "EPH"; - private static String AST_ALL_CMD = "ALL"; + private static String AST_ALL_CMD = "all"; private static String AST_TIME_CMD_BYTE = "54494d45"; private static String AST_POS_CMD_BYTE = "504f53"; private static String AST_EPH_CMD_BYTE = "455048"; From ced270333d68853a2f70114d9fa7ceff5b6ccb79 Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Thu, 21 Jan 2021 21:18:45 +0800 Subject: [PATCH 159/172] =?UTF-8?q?ALL=E6=94=B9=E4=B8=BAall?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../handler/NettyServerHandler.java | 2 +- .../DipperAstPosAsyncTaskServiceImpl.java | 39 +++++++++++++++---- .../DipperAstTimeAsyncTaskServiceImpl.java | 30 +++++++------- 3 files changed, 48 insertions(+), 23 deletions(-) diff --git a/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java b/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java index eca0d3e..3d062e5 100644 --- a/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java +++ b/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java @@ -154,7 +154,7 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter { log.info(channelAns); if (channelAns != null) { buf = Unpooled.buffer(channelAns.getBytes().length); - buf.writeBytes(channelAns.getBytes("GBK")); + buf.writeBytes(channelAns.getBytes("UTF-8")); ctx.writeAndFlush(buf); } } diff --git a/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java b/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java index 56c3ea6..f6b4d80 100644 --- a/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java +++ b/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java @@ -210,14 +210,37 @@ public class DipperAstPosAsyncTaskServiceImpl implements IDipperAstPosAsyncTaskS // 00 2F 为校验和 // astTimeCmd 组装 - String astTimeCmd = "233E0401"; - astTimeCmd += "1000"; - astTimeCmd += HexConvert.encodeHEX(lanLongValue); - astTimeCmd += HexConvert.encodeHEX(altLongValue); - astTimeCmd += "70170000"; - astTimeCmd += "A0860100"; - - return astTimeCmd + HexConvert.makeChecksum(astTimeCmd); + String astTimeCmd = "23 3E 04 01 "; + astTimeCmd += "10 00 "; + byte[] lanBytes = HexConvert.hexStringToBytes(HexConvert.encodeHEX(lanLongValue).toUpperCase()); + + byte[] altBytes = HexConvert.hexStringToBytes(HexConvert.encodeHEX(altLongValue).toUpperCase()); + + StringBuffer lanBuf = new StringBuffer(); + for(int i=0; i Date: Thu, 21 Jan 2021 21:30:33 +0800 Subject: [PATCH 160/172] =?UTF-8?q?ALL=E6=94=B9=E4=B8=BAall?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DipperAstPosAsyncTaskServiceImpl.java | 44 +++++++------------ .../DipperAstTimeAsyncTaskServiceImpl.java | 34 +++++++++----- 2 files changed, 38 insertions(+), 40 deletions(-) diff --git a/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java b/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java index f6b4d80..5417f94 100644 --- a/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java +++ b/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java @@ -209,38 +209,26 @@ public class DipperAstPosAsyncTaskServiceImpl implements IDipperAstPosAsyncTaskS // A0 86 01 00 表示注入的位置精度为 1000 米 0186a0 // 00 2F 为校验和 - // astTimeCmd 组装 - String astTimeCmd = "23 3E 04 01 "; - astTimeCmd += "10 00 "; - byte[] lanBytes = HexConvert.hexStringToBytes(HexConvert.encodeHEX(lanLongValue).toUpperCase()); - - byte[] altBytes = HexConvert.hexStringToBytes(HexConvert.encodeHEX(altLongValue).toUpperCase()); - - StringBuffer lanBuf = new StringBuffer(); - for(int i=0; i Date: Thu, 21 Jan 2021 21:41:44 +0800 Subject: [PATCH 161/172] =?UTF-8?q?ALL=E6=94=B9=E4=B8=BAall?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../impl/DipperAstPosAsyncTaskServiceImpl.java | 11 ++++++++++- .../impl/DipperAstTimeAsyncTaskServiceImpl.java | 9 +++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java b/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java index 5417f94..2685cc2 100644 --- a/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java +++ b/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java @@ -217,6 +217,16 @@ public class DipperAstPosAsyncTaskServiceImpl implements IDipperAstPosAsyncTaskS astPosCmd += "70170000"; astPosCmd += "A0860100"; + log.info(astPosCmd); + String checkSum = HexConvert.makeChecksum(astPosCmd).toUpperCase(); + StringBuffer astCheckSumBuf = new StringBuffer(); + astCheckSumBuf.append(checkSum); + while (astCheckSumBuf.length()<4) { + astCheckSumBuf.insert(0,"0"); + } + checkSum = astCheckSumBuf.toString(); + log.info(checkSum); + byte[] astPosCmdBytes = HexConvert.hexStringToBytes(astPosCmd); StringBuffer astPosCmdBuf = new StringBuffer(); for(int i=0; i Date: Thu, 21 Jan 2021 21:50:26 +0800 Subject: [PATCH 162/172] =?UTF-8?q?ALL=E6=94=B9=E4=B8=BAall?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/DipperAstPosAsyncTaskServiceImpl.java | 6 +++--- .../service/impl/DipperAstTimeAsyncTaskServiceImpl.java | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java b/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java index 2685cc2..13e37a6 100644 --- a/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java +++ b/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java @@ -212,8 +212,8 @@ public class DipperAstPosAsyncTaskServiceImpl implements IDipperAstPosAsyncTaskS // astPosCmd 组装 String astPosCmd = "233E0401"; astPosCmd += "1000"; - astPosCmd += HexConvert.hexStringToBytes(HexConvert.encodeHEX(lanLongValue).toUpperCase()); - astPosCmd += HexConvert.hexStringToBytes(HexConvert.encodeHEX(altLongValue).toUpperCase()); + astPosCmd += HexConvert.encodeHEX(lanLongValue).toUpperCase(); + astPosCmd += HexConvert.encodeHEX(altLongValue).toUpperCase(); astPosCmd += "70170000"; astPosCmd += "A0860100"; @@ -237,7 +237,7 @@ public class DipperAstPosAsyncTaskServiceImpl implements IDipperAstPosAsyncTaskS astPosCmdBuf.append(s + " "); } - return astPosCmdBuf.toString() + checkSum.substring(0,1) + " " + checkSum.substring(2,3); + return astPosCmdBuf.toString() + checkSum.substring(0,2) + " " + checkSum.substring(2,4); } } diff --git a/src/main/java/com/telpo/dipperposition/service/impl/DipperAstTimeAsyncTaskServiceImpl.java b/src/main/java/com/telpo/dipperposition/service/impl/DipperAstTimeAsyncTaskServiceImpl.java index 788bee6..e4f7621 100644 --- a/src/main/java/com/telpo/dipperposition/service/impl/DipperAstTimeAsyncTaskServiceImpl.java +++ b/src/main/java/com/telpo/dipperposition/service/impl/DipperAstTimeAsyncTaskServiceImpl.java @@ -104,7 +104,7 @@ public class DipperAstTimeAsyncTaskServiceImpl implements IDipperAstTimeAsyncTas checkSum = astCheckSumBuf.toString(); log.info(checkSum); - return astTimeCmdBuf.toString() + checkSum.substring(0,1) + " " + checkSum.substring(2,3); + return astTimeCmdBuf.toString() + checkSum.substring(0,2) + " " + checkSum.substring(2,4); //String hexIn = astTimeCmd + HexConvert.makeChecksum(astTimeCmd); //log.info("DipperAstTimeAsyncTaskServiceImpl 返回时间:" + hexIn); From 36e4faf9bd409e3cf89898bc0d6796cfd3c0addc Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Mon, 25 Jan 2021 11:21:47 +0800 Subject: [PATCH 163/172] =?UTF-8?q?String=E7=BB=84=E8=A3=85=E6=94=B9?= =?UTF-8?q?=E4=B8=BAStringBuilder=20Handler=E5=86=85=E7=BB=84=E8=A3=85?= =?UTF-8?q?=E5=90=AF=E7=94=A8CompositionBuffer?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dipperposition/common/HexConvert.java | 34 +++++++++++ .../handler/NettyServerHandler.java | 61 +++++++++++++------ .../server/DipperPositionServer.java | 19 ++---- .../DipperAstPosAsyncTaskServiceImpl.java | 33 +++++----- .../DipperAstTimeAsyncTaskServiceImpl.java | 41 +++++++------ .../impl/DipperDataAsyncTaskServiceImpl.java | 10 ++- 6 files changed, 127 insertions(+), 71 deletions(-) diff --git a/src/main/java/com/telpo/dipperposition/common/HexConvert.java b/src/main/java/com/telpo/dipperposition/common/HexConvert.java index 8f79122..20a8708 100644 --- a/src/main/java/com/telpo/dipperposition/common/HexConvert.java +++ b/src/main/java/com/telpo/dipperposition/common/HexConvert.java @@ -118,6 +118,40 @@ public class HexConvert { } return hex; } + + + /** + * 生成校验码的int值 + * */ + public static String makeChecksumForBytes(byte[] byteDatas) { + if (byteDatas == null || byteDatas.length == 0) { + return ""; + } + int total = 0; + int len = byteDatas.length; + + final String HEX = "0123456789abcdef"; + StringBuilder sb = null; + for (byte b : byteDatas) { + sb = new StringBuilder(2); + // 取出这个字节的高4位,然后与0x0f与运算,得到一个0-15之间的数据,通过HEX.charAt(0-15)即为16进制数 + sb.append(HEX.charAt((b >> 4) & 0x0f)); + // 取出这个字节的低位,与0x0f与运算,得到一个0-15之间的数据,通过HEX.charAt(0-15)即为16进制数 + sb.append(HEX.charAt(b & 0x0f)); + total += Integer.parseInt(sb.toString(), 16); + } + /** + * 用256求余最大是255,即16进制的FF + */ + int mod = total % 256; + String hex = Integer.toHexString(mod); + len = hex.length(); + // 如果不够校验位的长度,补0,这里用的是两位校验 + if (len < 2) { + hex = "0" + hex; + } + return hex; + } // // public static void main(String[] args) { // diff --git a/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java b/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java index 3d062e5..c9cae7e 100644 --- a/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java +++ b/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java @@ -5,10 +5,12 @@ import com.telpo.dipperposition.service.IDipperAstPosAsyncTaskService; import com.telpo.dipperposition.service.IDipperAstTimeAsyncTaskService; import com.telpo.dipperposition.service.IDipperDataAsyncTaskService; import io.netty.buffer.ByteBuf; +import io.netty.buffer.CompositeByteBuf; import io.netty.buffer.Unpooled; import io.netty.channel.socket.SocketChannel; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelInboundHandlerAdapter; +import io.netty.util.CharsetUtil; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @@ -87,7 +89,7 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter { //String str = "通知客户端链接建立成功" + " " + LocalDateTime.now() + " " + channel.localAddress().getHostString() + // "\r\n"; ByteBuf buf = Unpooled.buffer(ackAckCheckRef.getBytes().length); - buf.writeBytes(ackAckCheckRef.getBytes("GBK")); + buf.writeBytes(ackAckCheckRef.getBytes(CharsetUtil.UTF_8)); ctx.writeAndFlush(buf); } @@ -117,46 +119,67 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter { String channelAns = ""; // 返回时间指令 - //if (Integer.parseInt(timeAsycServerPort) == channel.localAddress().getPort()) { - //ByteBuf recvmg = (ByteBuf) msg; ByteBuf buf = null; - //String recvmgStr = recvmg.toString(); - //if (AST_TIME_CMD.equals(recvmg)) { if (AST_TIME_CMD.equals(msg)) { // 初始时间辅助输入; channelAns = nettyServerHandler.dipperTimeAsyncTaskService.pushAstTime(); -// log.info("返回时间:" + channelAns); + //log.debug(channelAns); + if (channelAns != null) { + buf = Unpooled.buffer(channelAns.getBytes().length); + buf.writeBytes(channelAns.getBytes(CharsetUtil.UTF_8)); + ctx.writeAndFlush(buf); + } } // 发送SDBP-AST-POS获取辅助位置信息 - // if (Integer.parseInt(posAsycServerPort) == channel.localAddress().getPort()) { - - //if (AST_POS_CMD.equals(recvmg)) { if (AST_POS_CMD.equals(msg)) { channelAns = nettyServerHandler.dipperAstPosAsyncTaskService.pushAstPos(ipAddress); + //log.debug(channelAns); + if (channelAns != null) { + buf = Unpooled.buffer(channelAns.getBytes().length); + buf.writeBytes(channelAns.getBytes(CharsetUtil.UTF_8)); + ctx.writeAndFlush(buf); + } } // 从缓存获取SDBP-AST-EPH星历数 - //if (Integer.parseInt(starsAsycServerPort) == channel.localAddress().getPort()) { - //if (AST_POS_CMD.equals(recvmg)) { if (AST_EPH_CMD.equals(msg)) { channelAns = nettyServerHandler.dipperDataAsyncTaskService.getAstEPH(); + //log.debug(channelAns); + if (channelAns != null) { + buf = Unpooled.buffer(channelAns.getBytes().length); + buf.writeBytes(channelAns.getBytes(CharsetUtil.UTF_8)); + ctx.writeAndFlush(buf); + } } // 最后把SDBP-AST-TIME、SDBP-AST-POS、SDBP-AST-EPH并包一起发给设备。 // 设备采用16进制获取数据,则代理服务器也是采用16进制返回数据。 // 通知客户端链消息发送成功 if (AST_ALL_CMD.equals(msg)) { + CompositeByteBuf compositeByteBuf = Unpooled.compositeBuffer(); channelAns = nettyServerHandler.dipperTimeAsyncTaskService.pushAstTime(); - channelAns += nettyServerHandler.dipperAstPosAsyncTaskService.pushAstPos(ipAddress); - channelAns += nettyServerHandler.dipperDataAsyncTaskService.getAstEPH(); - } - log.info(channelAns); - if (channelAns != null) { - buf = Unpooled.buffer(channelAns.getBytes().length); - buf.writeBytes(channelAns.getBytes("UTF-8")); - ctx.writeAndFlush(buf); + if (channelAns != null) { + ByteBuf channelTimeAnsBuf = Unpooled.buffer(channelAns.getBytes().length); + channelTimeAnsBuf.writeBytes(channelAns.getBytes(CharsetUtil.UTF_8)); + compositeByteBuf.addComponent(channelTimeAnsBuf); + } + channelAns = nettyServerHandler.dipperAstPosAsyncTaskService.pushAstPos(ipAddress); + + if (channelAns != null) { + ByteBuf channelPosAnsBuf = Unpooled.buffer(channelAns.getBytes().length); + channelPosAnsBuf.writeBytes(channelAns.getBytes(CharsetUtil.UTF_8)); + compositeByteBuf.addComponent(channelPosAnsBuf); + } + channelAns = nettyServerHandler.dipperDataAsyncTaskService.getAstEPH(); + if (channelAns != null) { + ByteBuf channelPehAnsBuf = Unpooled.buffer(channelAns.getBytes().length); + channelPehAnsBuf.writeBytes(channelAns.getBytes(CharsetUtil.UTF_8)); + compositeByteBuf.addComponent(channelPehAnsBuf); + } + ctx.writeAndFlush(compositeByteBuf); } + } /** diff --git a/src/main/java/com/telpo/dipperposition/server/DipperPositionServer.java b/src/main/java/com/telpo/dipperposition/server/DipperPositionServer.java index 6aa2edc..e9d63e4 100644 --- a/src/main/java/com/telpo/dipperposition/server/DipperPositionServer.java +++ b/src/main/java/com/telpo/dipperposition/server/DipperPositionServer.java @@ -1,12 +1,5 @@ package com.telpo.dipperposition.server; -import com.alibaba.nacos.api.NacosFactory; -import com.alibaba.nacos.api.PropertyKeyConst; -import com.alibaba.nacos.api.config.ConfigService; -import com.alibaba.nacos.api.config.annotation.NacosValue; -import com.alibaba.nacos.api.exception.NacosException; -import com.alibaba.nacos.spring.context.annotation.config.NacosPropertySource; -import com.telpo.dipperposition.co.PositionConfigInfo; import com.telpo.dipperposition.handler.ServerChannelInitializer; import io.netty.bootstrap.ServerBootstrap; import io.netty.channel.ChannelFuture; @@ -15,7 +8,6 @@ import io.netty.channel.EventLoopGroup; import io.netty.channel.nio.NioEventLoopGroup; import io.netty.channel.socket.nio.NioServerSocketChannel; import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.annotation.Value; import org.springframework.core.env.ConfigurableEnvironment; import org.springframework.stereotype.Component; @@ -29,15 +21,12 @@ import java.net.InetSocketAddress; */ @Slf4j @Component -//@NacosPropertySource(dataId="dipperposition-service", autoRefreshed=true) public class DipperPositionServer { - //@NacosValue("position-server.serverAddr") - //private String myServerAddr; private String serverAddr; private Integer starsAsycPort; - public DipperPositionServer(ConfigurableEnvironment environment) throws NacosException { + public DipperPositionServer(ConfigurableEnvironment environment) { this.serverAddr = environment.getProperty("position-server.serverAddr"); @@ -68,17 +57,17 @@ public class DipperPositionServer { //绑定端口,开始接收进来的连接 try { - ChannelFuture channelFuture3 = bootstrap.bind(socketAddress).sync(); + ChannelFuture channelFuture = bootstrap.bind(socketAddress).sync(); log.info("星历服务器启动开始监听端口: {}", starsAsycPort); //log.info("服务器: {}", myServerAddr); - channelFuture3.addListener(future -> { + channelFuture.addListener(future -> { if (future.isSuccess()){ System.out.println("start success"); }else{ System.out.println("start failed"); } }); - channelFuture3.channel().closeFuture().sync(); + channelFuture.channel().closeFuture().sync(); } catch (InterruptedException e) { e.printStackTrace(); } finally { diff --git a/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java b/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java index 13e37a6..a8f0260 100644 --- a/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java +++ b/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java @@ -210,15 +210,16 @@ public class DipperAstPosAsyncTaskServiceImpl implements IDipperAstPosAsyncTaskS // 00 2F 为校验和 // astPosCmd 组装 - String astPosCmd = "233E0401"; - astPosCmd += "1000"; - astPosCmd += HexConvert.encodeHEX(lanLongValue).toUpperCase(); - astPosCmd += HexConvert.encodeHEX(altLongValue).toUpperCase(); - astPosCmd += "70170000"; - astPosCmd += "A0860100"; - - log.info(astPosCmd); - String checkSum = HexConvert.makeChecksum(astPosCmd).toUpperCase(); + StringBuilder astPosCmdBuf = new StringBuilder(); + astPosCmdBuf.append("233E0401"); + astPosCmdBuf.append("1000"); + astPosCmdBuf.append(HexConvert.encodeHEX(lanLongValue).toUpperCase()); + astPosCmdBuf.append(HexConvert.encodeHEX(altLongValue).toUpperCase()); + astPosCmdBuf.append("70170000"); + astPosCmdBuf.append("A0860100"); + + //log.info(astPosCmd); + String checkSum = HexConvert.makeChecksum(astPosCmdBuf.toString()).toUpperCase(); StringBuffer astCheckSumBuf = new StringBuffer(); astCheckSumBuf.append(checkSum); while (astCheckSumBuf.length()<4) { @@ -227,17 +228,17 @@ public class DipperAstPosAsyncTaskServiceImpl implements IDipperAstPosAsyncTaskS checkSum = astCheckSumBuf.toString(); log.info(checkSum); - byte[] astPosCmdBytes = HexConvert.hexStringToBytes(astPosCmd); - StringBuffer astPosCmdBuf = new StringBuffer(); - for(int i=0; i Date: Tue, 2 Feb 2021 15:53:46 +0800 Subject: [PATCH 164/172] =?UTF-8?q?=E6=98=9F=E5=8E=86=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E7=AE=80=E5=8C=96=E4=B8=BAbyte[]=E6=95=B0=E7=BB=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 4 +- dipper_position_run.sh | 44 ++++----- pom.xml | 40 ++------ .../DipperPositionApplication.java | 3 - .../dipperposition/common/SocketClient.java | 5 +- .../config/AsyncExecutorConfig.java | 8 +- .../config/NettyServerConfig.java | 25 ++--- .../dipperposition/config/OkHttpConfig.java | 14 ++- .../dipperposition/config/PositionConfig.java | 39 ++------ .../config/SchedulingExecutorConfig.java | 16 ++-- .../DipperAstPosAsyncTaskController.java | 37 -------- .../DipperAstTimeAsyncTaskController.java | 39 -------- .../DipperDataAsyncTaskController.java | 55 ----------- .../handler/NettyServerHandler.java | 94 +++++++++++-------- .../handler/ServerChannelInitializer.java | 2 + .../mapper/IpProvinceMapper.java | 4 - .../server/DipperPositionServer.java | 7 +- .../server/TimeAsyncServer.java | 81 ---------------- .../service/IDipperDataAsyncTaskService.java | 2 +- .../DipperAstPosAsyncTaskServiceImpl.java | 15 +-- .../DipperAstTimeAsyncTaskServiceImpl.java | 5 - .../impl/DipperDataAsyncTaskServiceImpl.java | 18 ++-- .../service/impl/IpProvinceServiceImpl.java | 8 -- .../service/impl/ProvinceInfoServiceImpl.java | 6 -- .../dipperposition/task/ScheduleService.java | 6 +- src/main/resources/application.properties | 59 ++++++++++++ src/main/resources/bootstrap-pro.yaml | 83 ++++++++++++++-- src/main/resources/bootstrap-test.yaml | 83 +++++++++++++++- src/main/resources/bootstrap.yaml | 1 - 29 files changed, 360 insertions(+), 443 deletions(-) delete mode 100644 src/main/java/com/telpo/dipperposition/controller/DipperAstPosAsyncTaskController.java delete mode 100644 src/main/java/com/telpo/dipperposition/controller/DipperAstTimeAsyncTaskController.java delete mode 100644 src/main/java/com/telpo/dipperposition/controller/DipperDataAsyncTaskController.java delete mode 100644 src/main/java/com/telpo/dipperposition/server/TimeAsyncServer.java create mode 100644 src/main/resources/application.properties diff --git a/Dockerfile b/Dockerfile index 839622d..190741e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,4 +7,6 @@ ENV TimeZone=Asia/Shanghai ENV active=dev ENV JAVA_OPTS="-Xmx256M -Xms256M" RUN ln -snf /usr/share/zoneinfo/$TimeZone /etc/localtime && echo $TimeZone > /etc/timezone -ENTRYPOINT java $JAVA_OPTS -Djava.security.egd=file:/dev/./urandom -jar /dipperposition.jar --spring.profiles.active=$active \ No newline at end of file +ENTRYPOINT java $JAVA_OPTS -Djava.security.egd=file:/dev/./urandom -Dio.netty.leakDetectionLevel=ADVANCED -jar /dipperposition.jar --spring.profiles.active=$active + +java -Xmx256M -Xms256M -Djava.security.egd=file:/dev/./urandom -Dio.netty.leakDetectionLevel=ADVANCED -jar /dipperposition.jar --spring.profiles.active= \ No newline at end of file diff --git a/dipper_position_run.sh b/dipper_position_run.sh index 79b07f2..fbea5dc 100644 --- a/dipper_position_run.sh +++ b/dipper_position_run.sh @@ -2,29 +2,29 @@ environment=$1 version=$2 echo "环境变量为${environment},版本为$version!" -if [[ ${environment} == 'production' ]]; then - echo "开始远程构建容器" - docker stop dipperposition_service || true - docker rm dipperposition_service || true - docker rmi -f $(docker images | grep registry.cn-shanghai.aliyuncs.com/telpo_platform/rzl_adapter | awk '{print $3}') - docker login --username=rzl_wangjx@1111649216405698 --password=telpo.123 registry.cn-shanghai.aliyuncs.com - docker pull registry.cn-shanghai.aliyuncs.com/telpo_platform/dipperposition_service:$version - docker run -e active=pro -v /home/data/dipperposition/log:/var/log/dipperposition --restart=always -p 8105:8105 -p 9011:9011 -p 9012:9012 -p 9013:9013 -d --name dipperposition_service registry.cn-shanghai.aliyuncs.com/telpo_platform/dipperposition_service:$version - #删除产生的None镜像 - docker rmi -f $(docker images | grep none | awk '{print $3}') - docker ps -a -else -if [[ ${environment} == 'test' ]]; then - #echo "开始远程构建容器" - docker stop dipperposition_service || true - docker rm dipperposition_service || true - docker rmi -f $(docker images | grep 139.224.254.18:5000/dipperposition_service | awk '{print $3}') - docker pull 139.224.254.18:5000/dipperposition_service:$version - docker run -v /home/data/dipperposition/log:/var/log/dipperposition -e active=test --restart=always -d --network host -p 9011:9011 --name dipperposition_service 139.224.254.18:5000/dipperposition_service:$version +#processID='ps -ef | grep dipperposition | awk '{print $2}' | awk NR==1' +ps -ef | grep dipperposition | awk '{print $2}' | xargs kill -9 +#echo $processID +#if [[ "$processID" != "" ]]; then +# kill -9 $processID +#fi + +if [[ ${environment} == 'pro' ]]; then + echo 'run in production environment' + cd /home/data/dipperposition + if [[ -f /home/linwl/dipperposition/dipperposition.jar ]]; then + echo 'mv /home/linwl/dipperposition/dipperposition.jar to destination' + mv /home/linwl/dipperposition/dipperposition.jar /home/data/dipperposition/dipperposition.jar + fi + + nohup java -Xmx2048M -Xms2048M -Djava.security.egd=file:/dev/./urandom -Dio.netty.leakDetectionLevel=ADVANCED -jar dipperposition.jar --spring.profiles.active=pro & - #删除产生的None镜像 - docker rmi -f $(docker images | grep none | awk '{print $3}') - docker ps -a fi +if [[ ${environment} == 'test' ]]; then + cd /home/data/dipperposition + if [[ -f /home/linwl/Work/DipperPosition/dipperposition.jar ]]; then + mv /home/linwl/Work/DipperPosition/dipperposition.jar /home/data/dipperposition/dipperposition.jar + fi + nohup java -Xmx128M -Xms128M -Djava.security.egd=file:/dev/./urandom -Dio.netty.leakDetectionLevel=ADVANCED -jar dipperposition.jar --spring.profiles.active=test & fi diff --git a/pom.xml b/pom.xml index 12008e3..cabac44 100644 --- a/pom.xml +++ b/pom.xml @@ -40,32 +40,10 @@ true - - com.telpo - common - 1.1.19 - - - - com.alibaba.cloud - spring-cloud-starter-alibaba-nacos-discovery - - - - com.alibaba.cloud - spring-cloud-starter-alibaba-nacos-config - - - - com.alibaba.boot - nacos-config-spring-boot-starter - 0.2.7 - - - - com.alibaba.nacos - nacos-client + cn.hutool + hutool-core + 5.5.2 @@ -138,6 +116,11 @@ 2.0 + + org.springframework.data + spring-data-mongodb + 2.2.5.RELEASE + @@ -150,13 +133,6 @@ import - - com.alibaba.cloud - spring-cloud-alibaba-dependencies - ${spring-cloud-alibaba.version} - pom - import - diff --git a/src/main/java/com/telpo/dipperposition/DipperPositionApplication.java b/src/main/java/com/telpo/dipperposition/DipperPositionApplication.java index 691fbb1..452e6e9 100644 --- a/src/main/java/com/telpo/dipperposition/DipperPositionApplication.java +++ b/src/main/java/com/telpo/dipperposition/DipperPositionApplication.java @@ -1,12 +1,10 @@ package com.telpo.dipperposition; import com.telpo.dipperposition.server.DipperPositionServer; -import com.telpo.dipperposition.server.TimeAsyncServer; import lombok.extern.slf4j.Slf4j; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.context.properties.ConfigurationPropertiesScan; -import org.springframework.cloud.client.discovery.EnableDiscoveryClient; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.core.env.ConfigurableEnvironment; import org.springframework.scheduling.annotation.EnableAsync; @@ -19,7 +17,6 @@ import org.springframework.scheduling.annotation.EnableScheduling; * @create: 2020-06-18 16:39 */ @SpringBootApplication -@EnableDiscoveryClient @ConfigurationPropertiesScan @EnableAsync @EnableScheduling diff --git a/src/main/java/com/telpo/dipperposition/common/SocketClient.java b/src/main/java/com/telpo/dipperposition/common/SocketClient.java index b017c6a..dfb6947 100644 --- a/src/main/java/com/telpo/dipperposition/common/SocketClient.java +++ b/src/main/java/com/telpo/dipperposition/common/SocketClient.java @@ -38,7 +38,7 @@ public class SocketClient { } - public String sendCmd(String astCmd, String ackAckCheckRef) { + public byte[] sendCmd(String astCmd, String ackAckCheckRef) { try { OutputStream os=socket.getOutputStream(); PrintWriter pw=new PrintWriter(os); @@ -80,7 +80,8 @@ public class SocketClient { os.close(); //log.debug(ackResult); log.debug("接收服务器的信息:"+HexConvert.BinaryToHexString(in2b)); - return HexConvert.BinaryToHexString(in2b); + //return HexConvert.BinaryToHexString(in2b); + return in2b; } catch (IOException e) { log.error("Socket sendCmd Error:" + e.getMessage()); return null; diff --git a/src/main/java/com/telpo/dipperposition/config/AsyncExecutorConfig.java b/src/main/java/com/telpo/dipperposition/config/AsyncExecutorConfig.java index a339326..32fe03f 100644 --- a/src/main/java/com/telpo/dipperposition/config/AsyncExecutorConfig.java +++ b/src/main/java/com/telpo/dipperposition/config/AsyncExecutorConfig.java @@ -19,17 +19,19 @@ import java.util.concurrent.ThreadPoolExecutor; * @author: linwl * @create: 2020-07-11 09:17 */ +@Getter +@Setter @Configuration @Slf4j public class AsyncExecutorConfig implements AsyncConfigurer { - @Value("${async.pool.corePoolSize}") + @Value(value = "${async.pool.corePoolSize:4}") private int corePoolSize; - @Value("${async.pool.maxPoolSize}") + @Value(value = "${async.pool.maxPoolSize:8}") private int maxPoolSize; - @Value("${async.pool.queueCapacity}") + @Value(value = "${async.pool.queueCapacity:5000}") private int queueCapacity; @Bean(name = "asyncServiceExecutor") diff --git a/src/main/java/com/telpo/dipperposition/config/NettyServerConfig.java b/src/main/java/com/telpo/dipperposition/config/NettyServerConfig.java index 9d203c5..4e5a66d 100644 --- a/src/main/java/com/telpo/dipperposition/config/NettyServerConfig.java +++ b/src/main/java/com/telpo/dipperposition/config/NettyServerConfig.java @@ -1,17 +1,12 @@ package com.telpo.dipperposition.config; -import com.alibaba.nacos.api.config.annotation.NacosValue; -import com.alibaba.nacos.spring.context.annotation.config.NacosPropertySource; -import com.telpo.dipperposition.common.OkHttpUtil; import lombok.Getter; import lombok.Setter; -import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Configuration; -import javax.annotation.PostConstruct; - /** - * @program: gateway + * @program: NettyServerConfig * @description: jwt设置 * @author: linwl * @create: 2020-06-18 17:45 @@ -19,26 +14,18 @@ import javax.annotation.PostConstruct; @Getter @Setter @Configuration -@NacosPropertySource(dataId="dipperposition-service", autoRefreshed=true) public class NettyServerConfig { - @NacosValue(value = "${position-server.serverAddr}") + @Value(value = "${position-server.serverAddr}") private String serverAddr; - @NacosValue(value = "${position-server.timeAsycPort:9011}") + @Value(value = "${position-server.timeAsycPort:9011}") private String timeAsycServerPort; - @NacosValue(value = "${position-server.posAsycPort}") + @Value(value = "${position-server.posAsycPort:9013}") private String posAsycServerPort; - @NacosValue(value = "${position-server.starsAsycPort}") + @Value(value = "${position-server.starsAsycPort:9012}") private String starsAsycServerPort; -// public static NettyServerConfig nettyServerConfig; -// -// @PostConstruct -// public void init() { -// nettyServerConfig = this; -// } - } diff --git a/src/main/java/com/telpo/dipperposition/config/OkHttpConfig.java b/src/main/java/com/telpo/dipperposition/config/OkHttpConfig.java index 6fd53c8..185ced1 100644 --- a/src/main/java/com/telpo/dipperposition/config/OkHttpConfig.java +++ b/src/main/java/com/telpo/dipperposition/config/OkHttpConfig.java @@ -1,5 +1,7 @@ package com.telpo.dipperposition.config; +import lombok.Getter; +import lombok.Setter; import lombok.extern.slf4j.Slf4j; import okhttp3.ConnectionPool; import okhttp3.OkHttpClient; @@ -24,23 +26,25 @@ import java.util.concurrent.TimeUnit; * @author: linwl * @create: 2020-07-17 15:29 */ +@Getter +@Setter @Configuration @Slf4j public class OkHttpConfig { - @Value("${OkHttp-config.pool.max-conn}") + @Value(value = "${OkHttp-config.pool.max-conn}") private Integer maxConn; - @Value("${OkHttp-config.pool.keep-alive}") + @Value(value = "${OkHttp-config.pool.keep-alive}") private Integer keepAlive; - @Value("${OkHttp-config.read-timeout}") + @Value(value = "${OkHttp-config.read-timeout}") private long readTimeout; - @Value("${OkHttp-config.conn-timeout}") + @Value(value = "${OkHttp-config.conn-timeout}") private long connTimeout; - @Value("${OkHttp-config.write-timeout}") + @Value(value = "${OkHttp-config.write-timeout}") private long writeTimeout; @Bean diff --git a/src/main/java/com/telpo/dipperposition/config/PositionConfig.java b/src/main/java/com/telpo/dipperposition/config/PositionConfig.java index e126a49..cc1e5b5 100644 --- a/src/main/java/com/telpo/dipperposition/config/PositionConfig.java +++ b/src/main/java/com/telpo/dipperposition/config/PositionConfig.java @@ -1,16 +1,12 @@ package com.telpo.dipperposition.config; -import com.alibaba.nacos.api.config.annotation.NacosValue; -import com.alibaba.nacos.spring.context.annotation.config.NacosPropertySource; import lombok.Getter; import lombok.Setter; -import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Configuration; -import javax.annotation.PostConstruct; - /** - * @program: gateway + * @program: PositionConfig * @description: jwt设置 * @author: linwl * @create: 2020-06-18 17:45 @@ -18,32 +14,13 @@ import javax.annotation.PostConstruct; @Getter @Setter @Configuration -@NacosPropertySource(dataId="dipperposition-service", autoRefreshed=true) public class PositionConfig { - @NacosValue("${pos.centerProvinceFilePath}") - String centerProvinceFilePath; - - @NacosValue("${pos.ipPositionRequestPath}") - String ipPositionRequestPath; - @NacosValue("${pos.ipPositionRequestKey}") - String ipPositionRequestKey; - @NacosValue("${pos.centerProvince}") - String centerProvince; - - - @NacosValue("${pos.astServer}") - String astServer; - @NacosValue("${pos.astPosAstPort}") - int posAstPort; - @NacosValue("${pos.astTimeout}") - int astTimeout; - + @Value(value = "${pos.ipPositionRequestPath}") + private String ipPositionRequestPath; + @Value(value = "${pos.ipPositionRequestKey}") + private String ipPositionRequestKey; + @Value(value = "${pos.centerProvince}") + private String centerProvince; -// public static PositionConfig positionConfig; -// -// @PostConstruct -// public void init() { -// positionConfig = this; -// } } diff --git a/src/main/java/com/telpo/dipperposition/config/SchedulingExecutorConfig.java b/src/main/java/com/telpo/dipperposition/config/SchedulingExecutorConfig.java index 2bfd302..46dac6b 100644 --- a/src/main/java/com/telpo/dipperposition/config/SchedulingExecutorConfig.java +++ b/src/main/java/com/telpo/dipperposition/config/SchedulingExecutorConfig.java @@ -20,19 +20,19 @@ import org.springframework.scheduling.config.ScheduledTaskRegistrar; @Configuration public class SchedulingExecutorConfig implements SchedulingConfigurer { - @Value("${scheduler.pool.size}") + @Value(value = "${scheduler.pool.size}") private int pollSize; - @Value("${scheduler.pool.await-seconds}") + @Value(value = "${scheduler.pool.await-seconds}") private int awaitSeconds; - @Value("${pos.ast.server}") + @Value(value = "${pos.astServer}") private String astServer; - @Value("${pos.ast.ephAstPort}") - private int ephAstPort; - @Value("${pos.ast.ephAstHexPort}") - private int ephAstHexPort; - @Value("${pos.ast.timeout}") + @Value(value = "${pos.astPosAstPort}") + private int posAstPort; + @Value(value = "${pos.astEphAstHexPort}") + private int astEphAstHexPort; + @Value(value = "${pos.astTimeout}") private int astTimeout; @Override diff --git a/src/main/java/com/telpo/dipperposition/controller/DipperAstPosAsyncTaskController.java b/src/main/java/com/telpo/dipperposition/controller/DipperAstPosAsyncTaskController.java deleted file mode 100644 index 19588a8..0000000 --- a/src/main/java/com/telpo/dipperposition/controller/DipperAstPosAsyncTaskController.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.telpo.dipperposition.controller; - -import com.telpo.dipperposition.service.IDipperAstPosAsyncTaskService; -import com.telpo.dipperposition.service.IDipperAstTimeAsyncTaskService; -import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.RestController; - -import javax.annotation.PostConstruct; - - -/** - * @program: DipperAstPosAsyncTaskController - * @description: 北斗定位 - * @author: linwl - * @create: 2020-07-10 14:01 - */ -@RestController -@Slf4j -public class DipperAstPosAsyncTaskController { - - @Autowired - IDipperAstPosAsyncTaskService dipperAstPosAsyncTaskService; - -// private DipperAstPosAsyncTaskController dipperAstPosAsyncTaskController; -// @PostConstruct -// public void init() { -// dipperAstPosAsyncTaskController = this; -// } - /* - * 拉取星历数据 - */ - public String pushAstPos(String ipAddress) { - return dipperAstPosAsyncTaskService.pushAstPos(ipAddress); - } - -} diff --git a/src/main/java/com/telpo/dipperposition/controller/DipperAstTimeAsyncTaskController.java b/src/main/java/com/telpo/dipperposition/controller/DipperAstTimeAsyncTaskController.java deleted file mode 100644 index 8fbfc61..0000000 --- a/src/main/java/com/telpo/dipperposition/controller/DipperAstTimeAsyncTaskController.java +++ /dev/null @@ -1,39 +0,0 @@ -package com.telpo.dipperposition.controller; - -import com.telpo.dipperposition.service.IDipperAstTimeAsyncTaskService; -import com.telpo.dipperposition.service.IDipperDataAsyncTaskService; -import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - -import javax.annotation.PostConstruct; - - -/** - * @program: DipperPositionController - * @description: 北斗定位 - * @author: linwl - * @create: 2020-07-10 14:01 - */ -@RestController -@Slf4j -public class DipperAstTimeAsyncTaskController { - - @Autowired - IDipperAstTimeAsyncTaskService dipperTimeAsyncTaskService; - -// private DipperAstTimeAsyncTaskController dipperTimeAsyncTaskController; -// @PostConstruct -// public void init() { -// dipperTimeAsyncTaskController = this; -// } - /* - * 拉取星历数据 - */ - public String pushAstTime() { - return dipperTimeAsyncTaskService.pushAstTime(); - } - -} diff --git a/src/main/java/com/telpo/dipperposition/controller/DipperDataAsyncTaskController.java b/src/main/java/com/telpo/dipperposition/controller/DipperDataAsyncTaskController.java deleted file mode 100644 index fbf8b6a..0000000 --- a/src/main/java/com/telpo/dipperposition/controller/DipperDataAsyncTaskController.java +++ /dev/null @@ -1,55 +0,0 @@ -package com.telpo.dipperposition.controller; - -import com.telpo.dipperposition.service.IDipperDataAsyncTaskService; -import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - -import javax.annotation.PostConstruct; - - -/** - * @program: DipperPositionController - * @description: 北斗定位 - * @author: linwl - * @create: 2020-07-10 14:01 - */ -@RestController -@Slf4j -public class DipperDataAsyncTaskController { - @Value(value = "${position-server.serverAddr}") - private String serverAddr; - //RzlAccount rzlAccount; - - @Autowired - IDipperDataAsyncTaskService dipperDataAsyncTaskService; - -// private DipperDataAsyncTaskController dipperDataAsyncTaskController; -// @PostConstruct -// public void init() { -// dipperDataAsyncTaskController = this; -// } - /* - * 拉取星历数据 - */ - public void pullAstEPH() { - dipperDataAsyncTaskService.pullAstEPH(); - } -// -// /* -// * 获取星历数据 -// */ -// public String getAstEPH() { -// log.info("DipperDataAsyncTaskController serverAddr = " + serverAddr); -// return dipperDataAsyncTaskService.getAstEPH(); -// } - - - @RequestMapping("/getPos") - public String getPos() { - return "return serverAddr = " + serverAddr; - } - -} diff --git a/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java b/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java index c9cae7e..9ec061e 100644 --- a/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java +++ b/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java @@ -5,6 +5,7 @@ import com.telpo.dipperposition.service.IDipperAstPosAsyncTaskService; import com.telpo.dipperposition.service.IDipperAstTimeAsyncTaskService; import com.telpo.dipperposition.service.IDipperDataAsyncTaskService; import io.netty.buffer.ByteBuf; +import io.netty.buffer.ByteBufAllocator; import io.netty.buffer.CompositeByteBuf; import io.netty.buffer.Unpooled; import io.netty.channel.socket.SocketChannel; @@ -30,7 +31,7 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter { private static String AST_TIME_CMD = "TIME"; private static String AST_POS_CMD = "POS"; private static String AST_EPH_CMD = "EPH"; - private static String AST_ALL_CMD = "all"; + private static String AST_ALL_CMD = "ALL"; private static String AST_TIME_CMD_BYTE = "54494d45"; private static String AST_POS_CMD_BYTE = "504f53"; private static String AST_EPH_CMD_BYTE = "455048"; @@ -71,23 +72,8 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter { log.info("链接报告完毕"); //通知客户端链接建立成功 // 默认返回取得时间成功 - String ackAckCheckRef = "233E0101020004020A1D"; - -// if (Integer.parseInt(nettyServerConfig.getPosAsycServerPort()) == channel.localAddress().getPort()) { -// ackAckCheckRef = "233E010102000401091C"; -// } -// if (Integer.parseInt(nettyServerConfig.getStarsAsycServerPort()) == channel.localAddress().getPort()) { -// ackAckCheckRef = "233E010102000421293C"; -// } - - if (9013 == channel.localAddress().getPort()) { - ackAckCheckRef = "233E010102000401091C"; - } - if (9012 == channel.localAddress().getPort()) { - ackAckCheckRef = "233E010102000421293C"; - } - //String str = "通知客户端链接建立成功" + " " + LocalDateTime.now() + " " + channel.localAddress().getHostString() + - // "\r\n"; + // String ackAckCheckRef = "233E0101020004020A1D"; + String ackAckCheckRef = "23 3E 01 01 02 00 04 21 29 3C"; ByteBuf buf = Unpooled.buffer(ackAckCheckRef.getBytes().length); buf.writeBytes(ackAckCheckRef.getBytes(CharsetUtil.UTF_8)); ctx.writeAndFlush(buf); @@ -109,6 +95,7 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter { public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { //接收msg消息与上一章节相比,此处已经不需要自己进行解码} SocketChannel channel = (SocketChannel) ctx.channel(); + ByteBufAllocator bba = channel.config().getAllocator(); String ipAddress = channel.remoteAddress().getHostString(); log.info("接收到消息:" + msg + ",客户端IP:" + ipAddress); if(ipAddress.contains(":")) { @@ -125,9 +112,11 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter { channelAns = nettyServerHandler.dipperTimeAsyncTaskService.pushAstTime(); //log.debug(channelAns); if (channelAns != null) { - buf = Unpooled.buffer(channelAns.getBytes().length); + buf = bba.buffer(channelAns.getBytes().length); + //Unpooled.buffer(channelAns.getBytes().length); buf.writeBytes(channelAns.getBytes(CharsetUtil.UTF_8)); - ctx.writeAndFlush(buf); + ctx.write(buf); + ctx.flush(); } } // 发送SDBP-AST-POS获取辅助位置信息 @@ -135,49 +124,72 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter { channelAns = nettyServerHandler.dipperAstPosAsyncTaskService.pushAstPos(ipAddress); //log.debug(channelAns); if (channelAns != null) { - buf = Unpooled.buffer(channelAns.getBytes().length); + buf = bba.buffer(channelAns.getBytes().length); + //Unpooled.buffer(channelAns.getBytes().length); buf.writeBytes(channelAns.getBytes(CharsetUtil.UTF_8)); - ctx.writeAndFlush(buf); + ctx.write(buf); + ctx.flush(); } } // 从缓存获取SDBP-AST-EPH星历数 if (AST_EPH_CMD.equals(msg)) { - channelAns = nettyServerHandler.dipperDataAsyncTaskService.getAstEPH(); + //channelAns = nettyServerHandler.dipperDataAsyncTaskService.getAstEPH(); + byte[] returnBytes = nettyServerHandler.dipperDataAsyncTaskService.getAstEPH(); //log.debug(channelAns); - if (channelAns != null) { - buf = Unpooled.buffer(channelAns.getBytes().length); - buf.writeBytes(channelAns.getBytes(CharsetUtil.UTF_8)); - ctx.writeAndFlush(buf); - } + //if (channelAns != null) { + // buf = bba.buffer(channelAns.getBytes().length); + buf = bba.buffer(returnBytes.length); + //Unpooled.buffer(channelAns.getBytes().length); + buf.writeBytes(returnBytes); + ctx.write(buf); + ctx.flush(); + //} } // 最后把SDBP-AST-TIME、SDBP-AST-POS、SDBP-AST-EPH并包一起发给设备。 // 设备采用16进制获取数据,则代理服务器也是采用16进制返回数据。 // 通知客户端链消息发送成功 - if (AST_ALL_CMD.equals(msg)) { - CompositeByteBuf compositeByteBuf = Unpooled.compositeBuffer(); + if (AST_ALL_CMD.equals(msg.toString().toUpperCase())) { channelAns = nettyServerHandler.dipperTimeAsyncTaskService.pushAstTime(); if (channelAns != null) { - ByteBuf channelTimeAnsBuf = Unpooled.buffer(channelAns.getBytes().length); + log.debug("Time Buffer Length is:" + channelAns.getBytes().length); + ByteBuf channelTimeAnsBuf = bba.buffer(channelAns.getBytes().length); + //Unpooled.buffer(channelAns.getBytes().length); channelTimeAnsBuf.writeBytes(channelAns.getBytes(CharsetUtil.UTF_8)); - compositeByteBuf.addComponent(channelTimeAnsBuf); + // compositeByteBuf.addComponent(channelTimeAnsBuf); + ctx.write(channelTimeAnsBuf); + ctx.flush(); } channelAns = nettyServerHandler.dipperAstPosAsyncTaskService.pushAstPos(ipAddress); if (channelAns != null) { - ByteBuf channelPosAnsBuf = Unpooled.buffer(channelAns.getBytes().length); + log.debug("Pos Buffer Length is:" + channelAns.getBytes().length); + ByteBuf channelPosAnsBuf = bba.buffer(channelAns.getBytes().length); + //Unpooled.buffer(channelAns.getBytes().length); channelPosAnsBuf.writeBytes(channelAns.getBytes(CharsetUtil.UTF_8)); - compositeByteBuf.addComponent(channelPosAnsBuf); - } - channelAns = nettyServerHandler.dipperDataAsyncTaskService.getAstEPH(); - if (channelAns != null) { - ByteBuf channelPehAnsBuf = Unpooled.buffer(channelAns.getBytes().length); - channelPehAnsBuf.writeBytes(channelAns.getBytes(CharsetUtil.UTF_8)); - compositeByteBuf.addComponent(channelPehAnsBuf); + //compositeByteBuf.addComponent(channelPosAnsBuf); + ctx.write(channelPosAnsBuf); + ctx.flush(); } - ctx.writeAndFlush(compositeByteBuf); + byte[] returnBytes = nettyServerHandler.dipperDataAsyncTaskService.getAstEPH(); + //if (channelAns != null) { + log.debug("PEH Buffer Length is:" + returnBytes.length); + // 使用池化的堆内存,以减少内存碎片 + //ByteBuf channelPehAnsBuf = Unpooled.buffer(channelAns.getBytes().length); + //ByteBuf channelPehAnsBuf = bba.buffer(channelAns.getBytes().length); + ByteBuf channelPehAnsBuf = bba.buffer(returnBytes.length); + //channelPehAnsBuf.writeBytes(channelAns.getBytes(CharsetUtil.UTF_8)); + channelPehAnsBuf.writeBytes(returnBytes); + // compositeByteBuf.addComponent(channelPehAnsBuf); + // log.info("CompositeByteBuf Length is:" + compositeByteBuf.capacity()); + ctx.write(channelPehAnsBuf); + ctx.flush(); + //} + + // 写给下一个Handler,最后一个Handler将内容移出pipeline + // ctx.writeAndFlush(compositeByteBuf); } } diff --git a/src/main/java/com/telpo/dipperposition/handler/ServerChannelInitializer.java b/src/main/java/com/telpo/dipperposition/handler/ServerChannelInitializer.java index 95d98dd..a6fb9de 100644 --- a/src/main/java/com/telpo/dipperposition/handler/ServerChannelInitializer.java +++ b/src/main/java/com/telpo/dipperposition/handler/ServerChannelInitializer.java @@ -18,7 +18,9 @@ public class ServerChannelInitializer extends ChannelInitializer //添加编解码 socketChannel.pipeline().addLast("decoder", new StringDecoder(CharsetUtil.UTF_8)); socketChannel.pipeline().addLast("encoder", new StringEncoder(CharsetUtil.UTF_8)); + // pipeline的第一个ChannelHandler:ChannelInboundHandlerAdapter socketChannel.pipeline().addLast(new NettyServerHandler()); + // addLast后会自动创建ChannelHandlerContext } } diff --git a/src/main/java/com/telpo/dipperposition/mapper/IpProvinceMapper.java b/src/main/java/com/telpo/dipperposition/mapper/IpProvinceMapper.java index b794c95..8d176ce 100644 --- a/src/main/java/com/telpo/dipperposition/mapper/IpProvinceMapper.java +++ b/src/main/java/com/telpo/dipperposition/mapper/IpProvinceMapper.java @@ -1,13 +1,9 @@ package com.telpo.dipperposition.mapper; -import com.telpo.dipperposition.annotation.MongoSwitch; import com.telpo.dipperposition.entity.mongo.IpProvinceEntity; -import db.BaseMongoDbDao; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.mongodb.repository.MongoRepository; import org.springframework.stereotype.Repository; -import java.util.List; /** * @program: DataPushServer diff --git a/src/main/java/com/telpo/dipperposition/server/DipperPositionServer.java b/src/main/java/com/telpo/dipperposition/server/DipperPositionServer.java index e9d63e4..6d513bb 100644 --- a/src/main/java/com/telpo/dipperposition/server/DipperPositionServer.java +++ b/src/main/java/com/telpo/dipperposition/server/DipperPositionServer.java @@ -48,8 +48,9 @@ public class DipperPositionServer { .channel(NioServerSocketChannel.class) .childHandler(new ServerChannelInitializer()) .localAddress(socketAddress) - //设置队列大小 + //设置队列大小, 多少合适???? .option(ChannelOption.SO_BACKLOG, 1024) + .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 3000) // 两小时内没有数据的通信时,TCP会自动发送一个活动探测数据报文 .childOption(ChannelOption.SO_KEEPALIVE, true); @@ -62,9 +63,9 @@ public class DipperPositionServer { //log.info("服务器: {}", myServerAddr); channelFuture.addListener(future -> { if (future.isSuccess()){ - System.out.println("start success"); + log.info("start success"); }else{ - System.out.println("start failed"); + log.info("start failed"); } }); channelFuture.channel().closeFuture().sync(); diff --git a/src/main/java/com/telpo/dipperposition/server/TimeAsyncServer.java b/src/main/java/com/telpo/dipperposition/server/TimeAsyncServer.java deleted file mode 100644 index c06344b..0000000 --- a/src/main/java/com/telpo/dipperposition/server/TimeAsyncServer.java +++ /dev/null @@ -1,81 +0,0 @@ -package com.telpo.dipperposition.server; - -import com.alibaba.nacos.api.exception.NacosException; -import com.telpo.dipperposition.handler.ServerChannelInitializer; -import io.netty.bootstrap.ServerBootstrap; -import io.netty.channel.ChannelFuture; -import io.netty.channel.ChannelOption; -import io.netty.channel.EventLoopGroup; -import io.netty.channel.nio.NioEventLoopGroup; -import io.netty.channel.socket.nio.NioServerSocketChannel; -import lombok.extern.slf4j.Slf4j; -import org.springframework.core.env.ConfigurableEnvironment; - -import java.net.InetSocketAddress; - -/** - * @program: TimeAsyncServer - * @description: 北斗定位 - * @author: king - * @create: 2021-01-13 14:01 - */ -@Slf4j -public class TimeAsyncServer { - - // @Autowired PositionConfigInfo positionConfigInfo; - private String serverAddr; - private Integer serverPort; - private Integer timeAsycPort; - private Integer posAsycPort; - private Integer starsAsycPort; - - public TimeAsyncServer(ConfigurableEnvironment environment) throws NacosException { - - this.serverAddr = environment.getProperty("position-server.serverAddr"); - this.serverPort = Integer.parseInt(environment.getProperty("server.port")); - this.timeAsycPort = Integer.parseInt(environment.getProperty("position-server.timeAsycPort")); - this.posAsycPort = Integer.parseInt(environment.getProperty("position-server.posAsycPort")); - this.starsAsycPort = Integer.parseInt(environment.getProperty("position-server.starsAsycPort")); - } - - public void start() { - - //new 一个主线程组 - EventLoopGroup mainThreadGroup = new NioEventLoopGroup(1); - //new 一个工作线程组 - EventLoopGroup workThreadGroup = new NioEventLoopGroup(200); - //InetSocketAddress socketAddress = new InetSocketAddress(serverAddr,null); - ServerBootstrap bootstrap = new ServerBootstrap() - .group(mainThreadGroup, workThreadGroup) - .channel(NioServerSocketChannel.class) - .childHandler(new ServerChannelInitializer()) - //.localAddress(socketAddress) - //设置队列大小 - .option(ChannelOption.SO_BACKLOG, 1024) - // 两小时内没有数据的通信时,TCP会自动发送一个活动探测数据报文 - .childOption(ChannelOption.SO_KEEPALIVE, true); - - - //绑定端口,开始接收进来的连接 - try { - ChannelFuture channelFuture = bootstrap.bind(timeAsycPort).sync(); - log.info("时间辅助服务器启动开始监听端口: {}", timeAsycPort); - channelFuture.addListener(future -> { - if (future.isSuccess()){ - System.out.println("start success"); - }else{ - System.out.println("start failed"); - } - }); - - channelFuture.channel().closeFuture().sync(); - } catch (InterruptedException e) { - e.printStackTrace(); - } finally { - //关闭主线程组 - mainThreadGroup.shutdownGracefully(); - //关闭工作线程组 - workThreadGroup.shutdownGracefully(); - } - } -} diff --git a/src/main/java/com/telpo/dipperposition/service/IDipperDataAsyncTaskService.java b/src/main/java/com/telpo/dipperposition/service/IDipperDataAsyncTaskService.java index d5637f9..b60ffeb 100644 --- a/src/main/java/com/telpo/dipperposition/service/IDipperDataAsyncTaskService.java +++ b/src/main/java/com/telpo/dipperposition/service/IDipperDataAsyncTaskService.java @@ -26,6 +26,6 @@ public interface IDipperDataAsyncTaskService { * 根据IP获取EPH * */ - String getAstEPH(); + byte[] getAstEPH(); } diff --git a/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java b/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java index a8f0260..3095d86 100644 --- a/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java +++ b/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java @@ -1,9 +1,7 @@ package com.telpo.dipperposition.service.impl; -import cn.hutool.core.bean.BeanUtil; import com.alibaba.fastjson.JSONObject; import com.telpo.dipperposition.common.*; -import com.telpo.dipperposition.config.NettyServerConfig; import com.telpo.dipperposition.config.PositionConfig; import com.telpo.dipperposition.entity.mongo.IpProvinceEntity; import com.telpo.dipperposition.entity.mongo.ProvinceInfoEntity; @@ -11,21 +9,12 @@ import com.telpo.dipperposition.service.IDipperAstPosAsyncTaskService; import com.telpo.dipperposition.service.IProvinceInfoService; import com.telpo.dipperposition.service.IpProvinceService; import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang.StringUtils; import org.apache.commons.lang3.ObjectUtils; -import org.apache.logging.log4j.util.PropertiesUtil; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Service; -import org.springframework.util.ResourceUtils; -import java.io.File; -import java.io.FileNotFoundException; -import java.io.UnsupportedEncodingException; import java.util.HashMap; -import java.util.List; import java.util.Map; -import java.util.Objects; /** * @program: DipperAstPosAsyncTaskServiceImpl @@ -71,7 +60,7 @@ public class DipperAstPosAsyncTaskServiceImpl implements IDipperAstPosAsyncTaskS JSONObject paramObject = new JSONObject(); String result = okHttpUtil.getJsonParams(buffer.toString(), paramObject.toJSONString()); if (ObjectUtils.isNotEmpty(result)) { - if (StringUtils.isEmpty(result)) { + if (ObjectUtils.isEmpty(result)) { log.debug("IP省份获取错误,结果为空"); return null; } else { @@ -226,7 +215,7 @@ public class DipperAstPosAsyncTaskServiceImpl implements IDipperAstPosAsyncTaskS astCheckSumBuf.insert(0,"0"); } checkSum = astCheckSumBuf.toString(); - log.info(checkSum); + //log.info(checkSum); byte[] astPosCmdBytes = HexConvert.hexStringToBytes(astPosCmdBuf.toString()); StringBuilder astPosCmdNewBuf = new StringBuilder(); diff --git a/src/main/java/com/telpo/dipperposition/service/impl/DipperAstTimeAsyncTaskServiceImpl.java b/src/main/java/com/telpo/dipperposition/service/impl/DipperAstTimeAsyncTaskServiceImpl.java index 5c35041..65d35c9 100644 --- a/src/main/java/com/telpo/dipperposition/service/impl/DipperAstTimeAsyncTaskServiceImpl.java +++ b/src/main/java/com/telpo/dipperposition/service/impl/DipperAstTimeAsyncTaskServiceImpl.java @@ -1,13 +1,8 @@ package com.telpo.dipperposition.service.impl; import com.telpo.dipperposition.common.HexConvert; -import com.telpo.dipperposition.common.SocketClient; -import com.telpo.dipperposition.service.IDipperAstPosAsyncTaskService; import com.telpo.dipperposition.service.IDipperAstTimeAsyncTaskService; import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Service; import java.time.LocalDateTime; diff --git a/src/main/java/com/telpo/dipperposition/service/impl/DipperDataAsyncTaskServiceImpl.java b/src/main/java/com/telpo/dipperposition/service/impl/DipperDataAsyncTaskServiceImpl.java index bfab90d..36583aa 100644 --- a/src/main/java/com/telpo/dipperposition/service/impl/DipperDataAsyncTaskServiceImpl.java +++ b/src/main/java/com/telpo/dipperposition/service/impl/DipperDataAsyncTaskServiceImpl.java @@ -29,13 +29,11 @@ public class DipperDataAsyncTaskServiceImpl implements IDipperDataAsyncTaskServi @Autowired private SchedulingExecutorConfig schedulingExecutorConfig; - - @Override - @Async("asyncServiceExecutor") + //@Async("asyncServiceExecutor") public void pullAstEPH() { // (1) 发送bds获取星历数据 - String dipperData = pullEPHFromDipper(); + byte[] dipperData = pullEPHFromDipper(); // (2) 获取星历数据 if (dipperData == null) { @@ -47,10 +45,11 @@ public class DipperDataAsyncTaskServiceImpl implements IDipperDataAsyncTaskServi } } - private String pullEPHFromDipper() { + private byte[] pullEPHFromDipper() { // 创建Socket客户端实例; - SocketClient client = new SocketClient(schedulingExecutorConfig.getAstServer(), schedulingExecutorConfig.getEphAstHexPort(),schedulingExecutorConfig.getAstTimeout()); + SocketClient client = new SocketClient(schedulingExecutorConfig.getAstServer(), + schedulingExecutorConfig.getAstEphAstHexPort(),schedulingExecutorConfig.getAstTimeout()); // astTimeCmd 组装 String astTimeCmd = DIPPER_ALL_DATA_REQ; @@ -65,14 +64,15 @@ public class DipperDataAsyncTaskServiceImpl implements IDipperDataAsyncTaskServi String hexIn = astTimeCmd + checkSum.substring(0,2) + " " + checkSum.substring(2,4); String ackAckCheckRef = "233E010102000421293C"; - String sendResult = client.sendCmd(hexIn, ackAckCheckRef); + byte[] sendResult = client.sendCmd(hexIn, ackAckCheckRef); client.closeConnection(); return sendResult; } @Override - public String getAstEPH(){ - return (String)redisUtil.get(DIPPER_DATA_KEY); + public byte[] getAstEPH(){ + // String dipperData = pullEPHFromDipper(); + return (byte[])redisUtil.get(DIPPER_DATA_KEY); } } diff --git a/src/main/java/com/telpo/dipperposition/service/impl/IpProvinceServiceImpl.java b/src/main/java/com/telpo/dipperposition/service/impl/IpProvinceServiceImpl.java index deb0626..a5e03cd 100644 --- a/src/main/java/com/telpo/dipperposition/service/impl/IpProvinceServiceImpl.java +++ b/src/main/java/com/telpo/dipperposition/service/impl/IpProvinceServiceImpl.java @@ -1,22 +1,14 @@ package com.telpo.dipperposition.service.impl; -import cn.hutool.core.collection.CollectionUtil; import com.telpo.dipperposition.entity.mongo.IpProvinceEntity; -import com.telpo.dipperposition.entity.mongo.ProvinceInfoEntity; import com.telpo.dipperposition.mapper.IpProvinceMapper; import com.telpo.dipperposition.service.IpProvinceService; -import jdk.nashorn.internal.runtime.options.Option; import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.ObjectUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Example; import org.springframework.data.domain.ExampleMatcher; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.PageRequest; import org.springframework.stereotype.Service; -import tools.BeanTools; -import java.util.List; import java.util.Optional; /** diff --git a/src/main/java/com/telpo/dipperposition/service/impl/ProvinceInfoServiceImpl.java b/src/main/java/com/telpo/dipperposition/service/impl/ProvinceInfoServiceImpl.java index 668f2ad..b9e7baf 100644 --- a/src/main/java/com/telpo/dipperposition/service/impl/ProvinceInfoServiceImpl.java +++ b/src/main/java/com/telpo/dipperposition/service/impl/ProvinceInfoServiceImpl.java @@ -1,8 +1,5 @@ package com.telpo.dipperposition.service.impl; -import cn.hutool.core.bean.BeanUtil; -import cn.hutool.core.collection.CollectionUtil; -import com.telpo.dipperposition.entity.mongo.IpProvinceEntity; import com.telpo.dipperposition.entity.mongo.ProvinceInfoEntity; import com.telpo.dipperposition.mapper.ProvinceInfoMapper; import com.telpo.dipperposition.service.IProvinceInfoService; @@ -11,10 +8,7 @@ import org.apache.commons.lang3.ObjectUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Example; import org.springframework.data.domain.ExampleMatcher; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.PageRequest; import org.springframework.stereotype.Service; -import tools.BeanTools; import java.util.List; import java.util.Optional; diff --git a/src/main/java/com/telpo/dipperposition/task/ScheduleService.java b/src/main/java/com/telpo/dipperposition/task/ScheduleService.java index 03e3315..70d31f1 100644 --- a/src/main/java/com/telpo/dipperposition/task/ScheduleService.java +++ b/src/main/java/com/telpo/dipperposition/task/ScheduleService.java @@ -1,10 +1,8 @@ package com.telpo.dipperposition.task; -import com.telpo.dipperposition.controller.DipperDataAsyncTaskController; import com.telpo.dipperposition.service.IDipperDataAsyncTaskService; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; @@ -20,7 +18,7 @@ import org.springframework.stereotype.Component; public class ScheduleService { @Autowired - private DipperDataAsyncTaskController dipperDataAsyncTaskController; + private IDipperDataAsyncTaskService dipperDataAsyncTaskService; /* * 调用9012端口的接口获取星历数据。 @@ -33,7 +31,7 @@ public class ScheduleService { log.info("开始星历数据同步!"); // 获取推送失败的记录 try { - dipperDataAsyncTaskController.pullAstEPH(); + dipperDataAsyncTaskService.pullAstEPH(); } catch (Exception e) { log.error("执行定时获取星历数据发生异常:", e); } diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties new file mode 100644 index 0000000..0642c24 --- /dev/null +++ b/src/main/resources/application.properties @@ -0,0 +1,59 @@ +server.port=8105 +logging.config=classpath:log/logback-spring.xml +logging.level.com.telpo.dipperposition.service.impl=DEBUG +logging.level.com.telpo.dipperposition.service.mapper=DEBUG +spring.application.name=dipperposition-service + +spring.redis.database=1 +spring.redis.host=172.19.42.45 +#8090 +spring.redis.port=6389 +spring.redis.password=telpo#1234 +spring.redis.timeout=3000 +spring.redis.lettuce.pool.max-active=100 +# 连接池最大连接数(使用负值表示没有限制) +spring.redis.lettuce.pool.max-idle=100 +# 连接池中的最大空闲连接 +spring.redis.lettuce.pool.min-idle=50 +# 连接池中的最小空闲连接 +spring.redis.lettuce.pool.max-wait=6000 +# 连接池最大阻塞等待时间(使用负值表示没有限制) +spring.data.mongodb.host=172.19.42.45 +spring.data.mongodb.port=27017 +spring.data.mongodb.database=common +spring.data.mongodb.username=wangjx +spring.data.mongodb.password=wangjx#1234 + +position-server.serverAddr=172.19.42.45 +position-server.timeAsycPort=9011 +position-server.posAsycPort=9013 +position-server.starsAsycPort=9012 + +#等待任务完成退出最大秒数 +scheduler.pool.size=2 +scheduler.pool.await-seconds=600 +scheduler.task.cron=0 */30 * * * * + +pos.ipPositionRequestPath=https://restapi.amap.com/v3/ip +pos.ipPositionRequestKey=46eb0eba39494a6e9a90a0dc9e76639e +pos.centerProvince=湖北省 +pos.astServer=agnss.techtotop.com +pos.astPosAstPort=8012 +pos.astEphAstHexPort=9012 +pos.astTimeout=30000 + +OkHttp-config.pool.max-conn=200 +OkHttp-config.pool.keep-alive=5 +OkHttp-config.read-timeout=10 +OkHttp-config.conn-timeout=10 +OkHttp-config.write-timeout=10 + +async.pool.corePoolSize=4 +async.pool.maxPoolSize=8 +async.pool.queueCapacity=5000 + +mongo.datasource.dblist.uri=mongodb://wangjx:wangjx#1234@172.19.42.45:27017/common +mongo.datasource.dblist.database=common + + + diff --git a/src/main/resources/bootstrap-pro.yaml b/src/main/resources/bootstrap-pro.yaml index 721abc4..1c50d09 100644 --- a/src/main/resources/bootstrap-pro.yaml +++ b/src/main/resources/bootstrap-pro.yaml @@ -1,10 +1,79 @@ +server: + port: 8105 + +logging: + config: classpath:log/logback-spring.xml + level: + com: + telpo: + dipperposition: + service: + impl: debug + mapper: debug + org.springframework.data.mongodb.core.MongoTemplate: DEBUG spring: - main: - allow-bean-definition-overriding: true application: name: dipperposition-service - cloud: - nacos: - config: - server-addr: 172.19.42.38:8848 - file-extension: yml \ No newline at end of file + redis: + database: 1 + host: 172.19.42.45 + #8090 + port: 6379 + password: telpo#1234 + timeout: 3000 + lettuce: + pool: + max-active: 100 # 连接池最大连接数(使用负值表示没有限制) + max-idle: 100 # 连接池中的最大空闲连接 + min-idle: 50 # 连接池中的最小空闲连接 + max-wait: 6000 # 连接池最大阻塞等待时间(使用负值表示没有限制) + data: + mongodb: + host: 172.19.42.45 + port: 27017 + database: common + username: wangjx + password: wangjx#1234 + +mongo: + datasource: + dblist: + - uri: mongodb://wangjx:wangjx#1234@172.19.42.45:27015/common + database: common + +scheduler: + pool: + size: 2 + #等待任务完成退出最大秒数 + await-seconds: 600 + task: + cron: "0 */30 * * * *" + +pos: + ipPositionRequestPath: https://restapi.amap.com/v3/ip + ipPositionRequestKey: 46eb0eba39494a6e9a90a0dc9e76639e + centerProvince: 湖北省 + astServer: agnss.techtotop.com + astPosAstPort: 8012 + astEphAstHexPort: 9012 + astTimeout: 30000 + +position-server: + serverAddr: 172.19.42.45 + timeAsycPort: 9011 + posAsycPort: 9013 + starsAsycPort: 9012 + +OkHttp-config: + pool: + max-conn: 200 + keep-alive: 5 + read-timeout: 10 + conn-timeout: 10 + write-timeout: 10 + +async: + pool: + corePoolSize: 4 + maxPoolSize: 8 + queueCapacity: 5000 \ No newline at end of file diff --git a/src/main/resources/bootstrap-test.yaml b/src/main/resources/bootstrap-test.yaml index e8e687a..60cd53e 100644 --- a/src/main/resources/bootstrap-test.yaml +++ b/src/main/resources/bootstrap-test.yaml @@ -1,10 +1,87 @@ +server: + port: 8105 + +logging: + config: classpath:log/logback-spring.xml + level: + com: + telpo: + dipperposition: + service: + impl: debug + mapper: debug + org.springframework.data.mongodb.core.MongoTemplate: DEBUG spring: - main: - allow-bean-definition-overriding: true application: name: dipperposition-service cloud: nacos: config: server-addr: 172.19.42.44:8848 - file-extension: yml \ No newline at end of file + namespace: fee328ef-7348-4984-879a-fd75f9f59cd2 + redis: + database: 1 + host: 172.19.42.44 + #8090 + port: 8090 + password: telpo#1234 + timeout: 3000 + lettuce: + pool: + max-active: 100 # 连接池最大连接数(使用负值表示没有限制) + max-idle: 100 # 连接池中的最大空闲连接 + min-idle: 50 # 连接池中的最小空闲连接 + max-wait: 6000 # 连接池最大阻塞等待时间(使用负值表示没有限制) + data: + mongodb: + host: 172.19.42.40 + port: 27018 + database: common + username: wangjx + password: wangjx#1234 + +mongo: + datasource: + dblist: + - uri: mongodb://wangjx:wangjx#1234@172.19.42.40:27018/common + database: common + - uri: mongodb://wangjx:wangjx#1234@172.19.42.40:27018/basicdata + database: basicdata + +scheduler: + pool: + size: 2 + #等待任务完成退出最大秒数 + await-seconds: 600 + task: + cron: "0 */30 * * * *" + +pos: + centerProvinceFilePath: /csv/provinceLonAlt.csv + ipPositionRequestPath: https://restapi.amap.com/v3/ip + ipPositionRequestKey: 46eb0eba39494a6e9a90a0dc9e76639e + centerProvince: 湖北省 + astServer: agnss.techtotop.com + astPosAstPort: 8012 + astEphAstHexPort: 9012 + astTimeout: 30000 + +position-server: + serverAddr: 172.19.42.44 + timeAsycPort: 9011 + posAsycPort: 9013 + starsAsycPort: 9012 + +OkHttp-config: + pool: + max-conn: 200 + keep-alive: 5 + read-timeout: 10 + conn-timeout: 10 + write-timeout: 10 + +async: + pool: + corePoolSize: 4 + maxPoolSize: 8 + queueCapacity: 5000 \ No newline at end of file diff --git a/src/main/resources/bootstrap.yaml b/src/main/resources/bootstrap.yaml index b5569d8..c34181b 100644 --- a/src/main/resources/bootstrap.yaml +++ b/src/main/resources/bootstrap.yaml @@ -58,7 +58,6 @@ mongo: - uri: mongodb://wangjx:wangjx#1234@172.16.192.26:27017/common database: common - OkHttp-config: pool: max-conn: 200 From 4fb557eaf62b2e6382f245d14df052ff98296392 Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Wed, 3 Feb 2021 10:50:16 +0800 Subject: [PATCH 165/172] =?UTF-8?q?=E6=98=9F=E5=8E=86=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E7=AE=80=E5=8C=96=E4=B8=BAbyte[]=E6=95=B0=E7=BB=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../handler/NettyServerHandler.java | 76 ++++++++++++++----- .../DipperAstPosAsyncTaskServiceImpl.java | 66 ++++++++++------ .../DipperAstTimeAsyncTaskServiceImpl.java | 44 ++++++----- .../impl/DipperDataAsyncTaskServiceImpl.java | 10 ++- .../service/impl/IpProvinceServiceImpl.java | 2 +- src/main/resources/application.properties | 4 +- 6 files changed, 131 insertions(+), 71 deletions(-) diff --git a/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java b/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java index 9ec061e..c4f8578 100644 --- a/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java +++ b/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java @@ -1,5 +1,6 @@ package com.telpo.dipperposition.handler; +import com.telpo.dipperposition.common.HexConvert; import com.telpo.dipperposition.config.PositionConfig; import com.telpo.dipperposition.service.IDipperAstPosAsyncTaskService; import com.telpo.dipperposition.service.IDipperAstTimeAsyncTaskService; @@ -73,10 +74,10 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter { //通知客户端链接建立成功 // 默认返回取得时间成功 // String ackAckCheckRef = "233E0101020004020A1D"; - String ackAckCheckRef = "23 3E 01 01 02 00 04 21 29 3C"; - ByteBuf buf = Unpooled.buffer(ackAckCheckRef.getBytes().length); - buf.writeBytes(ackAckCheckRef.getBytes(CharsetUtil.UTF_8)); - ctx.writeAndFlush(buf); + //String ackAckCheckRef = "23 3E 01 01 02 00 04 21 29 3C"; + //ByteBuf buf = Unpooled.buffer(ackAckCheckRef.getBytes().length); + //buf.writeBytes(ackAckCheckRef.getBytes(CharsetUtil.UTF_8)); + //ctx.writeAndFlush(buf); } @@ -112,9 +113,14 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter { channelAns = nettyServerHandler.dipperTimeAsyncTaskService.pushAstTime(); //log.debug(channelAns); if (channelAns != null) { - buf = bba.buffer(channelAns.getBytes().length); +// buf = bba.buffer(channelAns.getBytes().length); + byte[] returnBytes = getReturnBytes(channelAns); + buf = bba.buffer(returnBytes.length + 4); //Unpooled.buffer(channelAns.getBytes().length); - buf.writeBytes(channelAns.getBytes(CharsetUtil.UTF_8)); +// buf.writeBytes(channelAns.getBytes(CharsetUtil.UTF_8)); + buf.writeBytes(returnBytes); + buf.writeBytes(getCheckSumBytes(channelAns)); + buf.writeBytes(getReturnBytes()); ctx.write(buf); ctx.flush(); } @@ -124,9 +130,15 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter { channelAns = nettyServerHandler.dipperAstPosAsyncTaskService.pushAstPos(ipAddress); //log.debug(channelAns); if (channelAns != null) { - buf = bba.buffer(channelAns.getBytes().length); +// buf = bba.buffer(channelAns.getBytes().length); + byte[] returnBytes = getReturnBytes(channelAns); + buf = bba.buffer(returnBytes.length + 4); //Unpooled.buffer(channelAns.getBytes().length); - buf.writeBytes(channelAns.getBytes(CharsetUtil.UTF_8)); +// buf.writeBytes(channelAns.getBytes(CharsetUtil.UTF_8)); + buf.writeBytes(returnBytes); + buf.writeBytes(getCheckSumBytes(channelAns)); + buf.writeBytes(getReturnBytes()); + ctx.write(buf); ctx.flush(); } @@ -154,23 +166,23 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter { channelAns = nettyServerHandler.dipperTimeAsyncTaskService.pushAstTime(); if (channelAns != null) { - log.debug("Time Buffer Length is:" + channelAns.getBytes().length); - ByteBuf channelTimeAnsBuf = bba.buffer(channelAns.getBytes().length); - //Unpooled.buffer(channelAns.getBytes().length); - channelTimeAnsBuf.writeBytes(channelAns.getBytes(CharsetUtil.UTF_8)); - // compositeByteBuf.addComponent(channelTimeAnsBuf); - ctx.write(channelTimeAnsBuf); + byte[] returnBytes = getReturnBytes(channelAns); + buf = bba.buffer(returnBytes.length + 4); + buf.writeBytes(returnBytes); + buf.writeBytes(getCheckSumBytes(channelAns)); + buf.writeBytes(getReturnBytes()); + ctx.write(buf); ctx.flush(); } channelAns = nettyServerHandler.dipperAstPosAsyncTaskService.pushAstPos(ipAddress); if (channelAns != null) { - log.debug("Pos Buffer Length is:" + channelAns.getBytes().length); - ByteBuf channelPosAnsBuf = bba.buffer(channelAns.getBytes().length); - //Unpooled.buffer(channelAns.getBytes().length); - channelPosAnsBuf.writeBytes(channelAns.getBytes(CharsetUtil.UTF_8)); - //compositeByteBuf.addComponent(channelPosAnsBuf); - ctx.write(channelPosAnsBuf); + byte[] returnBytes = getReturnBytes(channelAns); + buf = bba.buffer(returnBytes.length + 4); + buf.writeBytes(returnBytes); + buf.writeBytes(getCheckSumBytes(channelAns)); + buf.writeBytes(getReturnBytes()); + ctx.write(buf); ctx.flush(); } byte[] returnBytes = nettyServerHandler.dipperDataAsyncTaskService.getAstEPH(); @@ -203,5 +215,29 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter { ctx.close(); } + /* + * 取得byte数组 + */ + private byte[] getReturnBytes(String astCmdBuf) { + return HexConvert.hexStringToBytes(astCmdBuf); + } + + private byte[] getCheckSumBytes(String astCmdBuf) { + String checkSum = HexConvert.makeChecksum(astCmdBuf).toUpperCase(); + StringBuffer astCheckSumBuf = new StringBuffer(); + astCheckSumBuf.append(checkSum); + while (astCheckSumBuf.length()<4) { + astCheckSumBuf.insert(0,"0"); + } + return getReturnBytes(astCheckSumBuf.toString()); + //log.info(checkSum); + } + + + private byte[] getReturnBytes() { + String returnStr = "0D0A"; + return getReturnBytes(returnStr); + } + } diff --git a/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java b/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java index 3095d86..800d6f7 100644 --- a/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java +++ b/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java @@ -163,17 +163,15 @@ public class DipperAstPosAsyncTaskServiceImpl implements IDipperAstPosAsyncTaskS double lanValue = Double.parseDouble(lonStr) * 10000000; long lanLongValue = Double.doubleToLongBits(lanValue); if (lanLongValue < 0) { + // FFFFFFFF - 439C3270 + 1= BC63CD90(补码) lanLongValue = lanLongValue + 4294967295L + 1; } double altValue = Double.parseDouble(altStr) * 10000000; long altLongValue = Double.doubleToLongBits(altValue); if (altLongValue < 0) { + // FFFFFFFF - 439C3270 + 1= BC63CD90(补码) altLongValue = altLongValue + 4294967295L + 1; } - // 小端模式补码 - // FFFFFFFF - 439C3270 + 1= BC63CD90(补码) - lanLongValue = 4294967295L - lanLongValue + 1; - altLongValue = 4294967295L - altLongValue + 1; // 数值换算举例(以经度举例。纬度、高度、位置精度换算方法一致): // (1)经度数值为 113.431,则换算方法如下: @@ -202,32 +200,50 @@ public class DipperAstPosAsyncTaskServiceImpl implements IDipperAstPosAsyncTaskS StringBuilder astPosCmdBuf = new StringBuilder(); astPosCmdBuf.append("233E0401"); astPosCmdBuf.append("1000"); - astPosCmdBuf.append(HexConvert.encodeHEX(lanLongValue).toUpperCase()); - astPosCmdBuf.append(HexConvert.encodeHEX(altLongValue).toUpperCase()); + + + // 小端模式 + String lanString = HexConvert.encodeHEX(lanLongValue).toUpperCase(); + String altSting = HexConvert.encodeHEX(altLongValue).toUpperCase(); + //astPosCmdBuf.append(HexConvert.encodeHEX(lanLongValue).toUpperCase()); + astPosCmdBuf.append(lanString.substring(6,8)); + astPosCmdBuf.append(lanString.substring(4,6)); + astPosCmdBuf.append(lanString.substring(2,4)); + astPosCmdBuf.append(lanString.substring(0,2)); + + //astPosCmdBuf.append(HexConvert.encodeHEX(altLongValue).toUpperCase()); + + astPosCmdBuf.append(altSting.substring(6,8)); + astPosCmdBuf.append(altSting.substring(4,6)); + astPosCmdBuf.append(altSting.substring(2,4)); + astPosCmdBuf.append(altSting.substring(0,2)); astPosCmdBuf.append("70170000"); astPosCmdBuf.append("A0860100"); //log.info(astPosCmd); - String checkSum = HexConvert.makeChecksum(astPosCmdBuf.toString()).toUpperCase(); - StringBuffer astCheckSumBuf = new StringBuffer(); - astCheckSumBuf.append(checkSum); - while (astCheckSumBuf.length()<4) { - astCheckSumBuf.insert(0,"0"); - } - checkSum = astCheckSumBuf.toString(); - //log.info(checkSum); - - byte[] astPosCmdBytes = HexConvert.hexStringToBytes(astPosCmdBuf.toString()); - StringBuilder astPosCmdNewBuf = new StringBuilder(); - for (byte astPosCmdByte : astPosCmdBytes) { - String s = Integer.toHexString(astPosCmdByte & 0xff); - if (s.length() < 2) { - astPosCmdNewBuf.append('0'); - } - astPosCmdNewBuf.append(s + " "); - } +// String checkSum = HexConvert.makeChecksum(astPosCmdBuf.toString()).toUpperCase(); +// StringBuffer astCheckSumBuf = new StringBuffer(); +// astCheckSumBuf.append(checkSum); +// while (astCheckSumBuf.length()<4) { +// astCheckSumBuf.insert(0,"0"); +// } +// checkSum = astCheckSumBuf.toString(); +// //log.info(checkSum); +// +// byte[] astPosCmdBytes = HexConvert.hexStringToBytes(astPosCmdBuf.toString()); +// StringBuilder astPosCmdNewBuf = new StringBuilder(); +// for (byte astPosCmdByte : astPosCmdBytes) { +// String s = Integer.toHexString(astPosCmdByte & 0xff); +// if (s.length() < 2) { +// astPosCmdNewBuf.append('0'); +// } +// astPosCmdNewBuf.append(s + " "); +// } +// + return astPosCmdBuf.toString(); + //+ checkSum.substring(0,2) + " " + checkSum.substring(2,4); + - return astPosCmdNewBuf.toString() + checkSum.substring(0,2) + " " + checkSum.substring(2,4); } } diff --git a/src/main/java/com/telpo/dipperposition/service/impl/DipperAstTimeAsyncTaskServiceImpl.java b/src/main/java/com/telpo/dipperposition/service/impl/DipperAstTimeAsyncTaskServiceImpl.java index 65d35c9..f31cf22 100644 --- a/src/main/java/com/telpo/dipperposition/service/impl/DipperAstTimeAsyncTaskServiceImpl.java +++ b/src/main/java/com/telpo/dipperposition/service/impl/DipperAstTimeAsyncTaskServiceImpl.java @@ -77,30 +77,32 @@ public class DipperAstTimeAsyncTaskServiceImpl implements IDipperAstTimeAsyncTas hexSecondString = "0" + hexSecondString; } astTimeCmdBuf.append(hexSecondString.toUpperCase()); - astTimeCmdBuf.append("0000000000"); + astTimeCmdBuf.append("00000000"); astTimeCmdBuf.append("005ED0B2"); - byte[] astTimeCmdBytes = HexConvert.hexStringToBytes(astTimeCmdBuf.toString()); - StringBuilder astTimeCmdNewBuf = new StringBuilder(); - for(int i=0; i example = Example.of(query, matcher); Optional data = ipProvinceMapper.findOne(example); - return data.get(); + return data.orElse(null); } catch (Exception e) { log.error("获取IP省份异常:", e); return null; diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 0642c24..eee8f0b 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -5,9 +5,9 @@ logging.level.com.telpo.dipperposition.service.mapper=DEBUG spring.application.name=dipperposition-service spring.redis.database=1 -spring.redis.host=172.19.42.45 +spring.redis.host=127.0.0.1 #8090 -spring.redis.port=6389 +spring.redis.port=6379 spring.redis.password=telpo#1234 spring.redis.timeout=3000 spring.redis.lettuce.pool.max-active=100 From b5e4005b7c6160af9d64e6087a140c6d7ca7cb0d Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Wed, 3 Feb 2021 10:51:26 +0800 Subject: [PATCH 166/172] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=8C=97=E6=96=97?= =?UTF-8?q?=E7=9A=84=E7=AB=AF=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/application.properties | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index eee8f0b..0937586 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -39,7 +39,8 @@ pos.ipPositionRequestKey=46eb0eba39494a6e9a90a0dc9e76639e pos.centerProvince=湖北省 pos.astServer=agnss.techtotop.com pos.astPosAstPort=8012 -pos.astEphAstHexPort=9012 +# 占青霞说北斗的是9112端口 +pos.astEphAstHexPort=9112 pos.astTimeout=30000 OkHttp-config.pool.max-conn=200 From 10880df34e9b46a008f8aa5b73c39f7a7e8a08d2 Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Fri, 5 Feb 2021 11:13:03 +0800 Subject: [PATCH 167/172] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=8C=97=E6=96=97?= =?UTF-8?q?=E7=9A=84=E7=AB=AF=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../telpo/dipperposition/common/SocketClient.java | 15 ++------------- .../impl/DipperDataAsyncTaskServiceImpl.java | 8 +++++--- .../service/impl/IpProvinceServiceImpl.java | 7 ++++++- 3 files changed, 13 insertions(+), 17 deletions(-) diff --git a/src/main/java/com/telpo/dipperposition/common/SocketClient.java b/src/main/java/com/telpo/dipperposition/common/SocketClient.java index dfb6947..8b7fca4 100644 --- a/src/main/java/com/telpo/dipperposition/common/SocketClient.java +++ b/src/main/java/com/telpo/dipperposition/common/SocketClient.java @@ -38,7 +38,7 @@ public class SocketClient { } - public byte[] sendCmd(String astCmd, String ackAckCheckRef) { + public byte[] sendCmd(String astCmd) { try { OutputStream os=socket.getOutputStream(); PrintWriter pw=new PrintWriter(os); @@ -56,23 +56,12 @@ public class SocketClient { ByteArrayOutputStream swapStream = new ByteArrayOutputStream(); byte[] buff = new byte[100]; - //StringBuffer ackResultBuf= new StringBuffer(); - //String ackHexOut = HexConvert.convertStringToHex(ackAckCheckRef); -// reply=br.readLine(); -// while(reply!=null){ -// //log.debug("接收服务器的信息:"+reply); -// //if (ackHexOut.equals(reply)) { -// ackResultBuf.append(reply); -// reply=br.readLine(); -// // break; -// //} -// } int rc = 0; while ((rc = is.read(buff, 0, 100)) > 0) { swapStream.write(buff, 0, rc); } byte[] in2b = swapStream.toByteArray(); - //String ackResult = HexConvert.convertHexToString(ackResultBuf.toString()); + //4.关闭资源 swapStream.close(); is.close(); diff --git a/src/main/java/com/telpo/dipperposition/service/impl/DipperDataAsyncTaskServiceImpl.java b/src/main/java/com/telpo/dipperposition/service/impl/DipperDataAsyncTaskServiceImpl.java index 4218819..f034ebe 100644 --- a/src/main/java/com/telpo/dipperposition/service/impl/DipperDataAsyncTaskServiceImpl.java +++ b/src/main/java/com/telpo/dipperposition/service/impl/DipperDataAsyncTaskServiceImpl.java @@ -48,8 +48,9 @@ public class DipperDataAsyncTaskServiceImpl implements IDipperDataAsyncTaskServi private byte[] pullEPHFromDipper() { // 创建Socket客户端实例; - SocketClient client = new SocketClient(schedulingExecutorConfig.getAstServer(), - schedulingExecutorConfig.getAstEphAstHexPort(),schedulingExecutorConfig.getAstTimeout()); + String serverAddr = schedulingExecutorConfig.getAstServer(); + int serverPort = schedulingExecutorConfig.getAstEphAstHexPort(); + SocketClient client = new SocketClient(serverAddr,serverPort,schedulingExecutorConfig.getAstTimeout()); // astTimeCmd 组装 String astTimeCmd = DIPPER_ALL_DATA_REQ; @@ -63,8 +64,9 @@ public class DipperDataAsyncTaskServiceImpl implements IDipperDataAsyncTaskServi String hexIn = astTimeCmd + checkSum.substring(0,2) + " " + checkSum.substring(2,4); + byte[] sendResult = null; String ackAckCheckRef = "233E010102000421293C"; - byte[] sendResult = client.sendCmd(hexIn, ackAckCheckRef); + sendResult = client.sendCmd(hexIn); client.closeConnection(); return sendResult; diff --git a/src/main/java/com/telpo/dipperposition/service/impl/IpProvinceServiceImpl.java b/src/main/java/com/telpo/dipperposition/service/impl/IpProvinceServiceImpl.java index ccd1a63..10bc544 100644 --- a/src/main/java/com/telpo/dipperposition/service/impl/IpProvinceServiceImpl.java +++ b/src/main/java/com/telpo/dipperposition/service/impl/IpProvinceServiceImpl.java @@ -55,7 +55,12 @@ public class IpProvinceServiceImpl implements IpProvinceService { ExampleMatcher matcher = ExampleMatcher.matching().withIgnorePaths("_class"); Example example = Example.of(query, matcher); Optional data = ipProvinceMapper.findOne(example); - return data.orElse(null); + if (data.isPresent() == true) { + return data.get(); + } else { + return null; + } + //return data.orElse(null); } catch (Exception e) { log.error("获取IP省份异常:", e); return null; From 5535e90352b679f0c85c1bcee3440b178735c277 Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Fri, 5 Feb 2021 11:14:50 +0800 Subject: [PATCH 168/172] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=8C=97=E6=96=97?= =?UTF-8?q?=E7=9A=84=E7=AB=AF=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/application.properties | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 0937586..f168b0d 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -37,6 +37,7 @@ scheduler.task.cron=0 */30 * * * * pos.ipPositionRequestPath=https://restapi.amap.com/v3/ip pos.ipPositionRequestKey=46eb0eba39494a6e9a90a0dc9e76639e pos.centerProvince=湖北省 +# 测试 agnss.techtotop.com pos.astServer=agnss.techtotop.com pos.astPosAstPort=8012 # 占青霞说北斗的是9112端口 From f61ea49810afe75ae70c37f8c955b6408141ea62 Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Sat, 6 Feb 2021 06:43:20 +0800 Subject: [PATCH 169/172] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=87=8D=E8=AF=95?= =?UTF-8?q?=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/IDipperDataAsyncTaskService.java | 2 +- .../impl/DipperDataAsyncTaskServiceImpl.java | 19 ++++++++++++++++--- .../dipperposition/task/ScheduleService.java | 6 +++++- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/telpo/dipperposition/service/IDipperDataAsyncTaskService.java b/src/main/java/com/telpo/dipperposition/service/IDipperDataAsyncTaskService.java index b60ffeb..5af5cb2 100644 --- a/src/main/java/com/telpo/dipperposition/service/IDipperDataAsyncTaskService.java +++ b/src/main/java/com/telpo/dipperposition/service/IDipperDataAsyncTaskService.java @@ -19,7 +19,7 @@ public interface IDipperDataAsyncTaskService { * 同步任务 * */ - void pullAstEPH(); + void pullAstEPH(int tryTimes) throws InterruptedException; /** diff --git a/src/main/java/com/telpo/dipperposition/service/impl/DipperDataAsyncTaskServiceImpl.java b/src/main/java/com/telpo/dipperposition/service/impl/DipperDataAsyncTaskServiceImpl.java index f034ebe..e955650 100644 --- a/src/main/java/com/telpo/dipperposition/service/impl/DipperDataAsyncTaskServiceImpl.java +++ b/src/main/java/com/telpo/dipperposition/service/impl/DipperDataAsyncTaskServiceImpl.java @@ -10,6 +10,8 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Service; +import static java.lang.Thread.sleep; + /** * @program: DipperDataAsyncTaskServiceImpl * @description: 获取星历数据。 @@ -31,13 +33,20 @@ public class DipperDataAsyncTaskServiceImpl implements IDipperDataAsyncTaskServi @Override @Async("asyncServiceExecutor") - public void pullAstEPH() { + public void pullAstEPH(int tryTimes) throws InterruptedException { + if (tryTimes==0) { + return; + } else { + tryTimes--; + } // (1) 发送bds获取星历数据 byte[] dipperData = pullEPHFromDipper(); // (2) 获取星历数据 if (dipperData == null) { log.error("获取星历数据错误,取不到星历数据。"); + sleep(10000); + pullAstEPH(tryTimes); } else { // 保存到DB或者缓存 log.info("保存到DB或者缓存"); @@ -65,7 +74,7 @@ public class DipperDataAsyncTaskServiceImpl implements IDipperDataAsyncTaskServi String hexIn = astTimeCmd + checkSum.substring(0,2) + " " + checkSum.substring(2,4); byte[] sendResult = null; - String ackAckCheckRef = "233E010102000421293C"; + //String ackAckCheckRef = "233E010102000421293C"; sendResult = client.sendCmd(hexIn); client.closeConnection(); @@ -77,7 +86,11 @@ public class DipperDataAsyncTaskServiceImpl implements IDipperDataAsyncTaskServi // String dipperData = pullEPHFromDipper(); byte[] dipperData; if (!redisUtil.hasKey(DIPPER_DATA_KEY)) { - this.pullAstEPH(); + try { + this.pullAstEPH(1); + } catch (InterruptedException e) { + log.error("获取星历数据发生异常:", e); + } } dipperData = (byte[])redisUtil.get(DIPPER_DATA_KEY); diff --git a/src/main/java/com/telpo/dipperposition/task/ScheduleService.java b/src/main/java/com/telpo/dipperposition/task/ScheduleService.java index 70d31f1..4a9f49a 100644 --- a/src/main/java/com/telpo/dipperposition/task/ScheduleService.java +++ b/src/main/java/com/telpo/dipperposition/task/ScheduleService.java @@ -31,7 +31,11 @@ public class ScheduleService { log.info("开始星历数据同步!"); // 获取推送失败的记录 try { - dipperDataAsyncTaskService.pullAstEPH(); + // 如果失败,则可以等待10秒再获取1次。 + int tryTimes = 2; + dipperDataAsyncTaskService.pullAstEPH(tryTimes); + } catch (InterruptedException e) { + log.error("获取星历数据重试睡眠发生异常:", e); } catch (Exception e) { log.error("执行定时获取星历数据发生异常:", e); } From dbe2589c99ae37beefa66a3149d5de96cde9ad48 Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Sat, 6 Feb 2021 06:47:21 +0800 Subject: [PATCH 170/172] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=87=8D=E8=AF=95?= =?UTF-8?q?=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../impl/DipperDataAsyncTaskServiceImpl.java | 13 ++++++------- src/main/resources/bootstrap-test.yaml | 2 +- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/telpo/dipperposition/service/impl/DipperDataAsyncTaskServiceImpl.java b/src/main/java/com/telpo/dipperposition/service/impl/DipperDataAsyncTaskServiceImpl.java index e955650..b073e78 100644 --- a/src/main/java/com/telpo/dipperposition/service/impl/DipperDataAsyncTaskServiceImpl.java +++ b/src/main/java/com/telpo/dipperposition/service/impl/DipperDataAsyncTaskServiceImpl.java @@ -34,19 +34,18 @@ public class DipperDataAsyncTaskServiceImpl implements IDipperDataAsyncTaskServi @Override @Async("asyncServiceExecutor") public void pullAstEPH(int tryTimes) throws InterruptedException { - if (tryTimes==0) { - return; - } else { - tryTimes--; - } + tryTimes--; // (1) 发送bds获取星历数据 byte[] dipperData = pullEPHFromDipper(); // (2) 获取星历数据 if (dipperData == null) { log.error("获取星历数据错误,取不到星历数据。"); - sleep(10000); - pullAstEPH(tryTimes); + if (tryTimes>0) { + log.info("等待10秒再获取1次。"); + sleep(10000); + pullAstEPH(tryTimes); + } } else { // 保存到DB或者缓存 log.info("保存到DB或者缓存"); diff --git a/src/main/resources/bootstrap-test.yaml b/src/main/resources/bootstrap-test.yaml index 60cd53e..22f9b81 100644 --- a/src/main/resources/bootstrap-test.yaml +++ b/src/main/resources/bootstrap-test.yaml @@ -63,7 +63,7 @@ pos: centerProvince: 湖北省 astServer: agnss.techtotop.com astPosAstPort: 8012 - astEphAstHexPort: 9012 + astEphAstHexPort: 9112 astTimeout: 30000 position-server: From f3e06605856b1c7d95409c49a3b901d862ec1a92 Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Thu, 1 Apr 2021 13:48:34 +0800 Subject: [PATCH 171/172] =?UTF-8?q?=E5=86=99=E9=80=9A=E9=81=93=E6=97=B6?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=80=9A=E9=81=93=E8=BF=9E=E6=8E=A5=E6=B4=BB?= =?UTF-8?q?=E8=B7=83=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../handler/NettyServerHandler.java | 68 +++++++++++++------ .../server/DipperPositionServer.java | 3 +- .../dipperposition/task/ScheduleService.java | 2 +- 3 files changed, 50 insertions(+), 23 deletions(-) diff --git a/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java b/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java index c4f8578..b275124 100644 --- a/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java +++ b/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java @@ -82,11 +82,13 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter { /** - * 当客户端主动断开服务端的链接后,这个通道就是不活跃的。也就是说客户端与服务端的关闭了通信通道并且不可以传输数据 + * 当客户端主动断开服务端的链接后,这个通道就是不活跃的。 + * 也就是说客户端与服务端的关闭了通信通道并且不可以传输数据 */ @Override public void channelInactive(ChannelHandlerContext ctx) throws Exception { log.info("客户端断开链接,IP:{}", ctx.channel().localAddress().toString()); + ctx.channel().close(); } /** @@ -121,8 +123,12 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter { buf.writeBytes(returnBytes); buf.writeBytes(getCheckSumBytes(channelAns)); buf.writeBytes(getReturnBytes()); - ctx.write(buf); - ctx.flush(); + // 确保通道处于活跃状态 + // 不活跃状态继续写会产生CLOSE_WAIT现象 + if(ctx.channel().isActive()) { + ctx.write(buf); + ctx.flush(); + } } } // 发送SDBP-AST-POS获取辅助位置信息 @@ -138,9 +144,12 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter { buf.writeBytes(returnBytes); buf.writeBytes(getCheckSumBytes(channelAns)); buf.writeBytes(getReturnBytes()); - - ctx.write(buf); - ctx.flush(); + // 确保通道处于活跃状态 + // 不活跃状态继续写会产生CLOSE_WAIT现象 + if(ctx.channel().isActive()) { + ctx.write(buf); + ctx.flush(); + } } } @@ -154,8 +163,12 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter { buf = bba.buffer(returnBytes.length); //Unpooled.buffer(channelAns.getBytes().length); buf.writeBytes(returnBytes); - ctx.write(buf); - ctx.flush(); + // 确保通道处于活跃状态 + // 不活跃状态继续写会产生CLOSE_WAIT现象 + if(ctx.channel().isActive()) { + ctx.write(buf); + ctx.flush(); + } //} } @@ -171,8 +184,13 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter { buf.writeBytes(returnBytes); buf.writeBytes(getCheckSumBytes(channelAns)); buf.writeBytes(getReturnBytes()); - ctx.write(buf); - ctx.flush(); + + // 确保通道处于活跃状态 + // 不活跃状态继续写会产生CLOSE_WAIT现象 + if(ctx.channel().isActive()) { + ctx.write(buf); + ctx.flush(); + } } channelAns = nettyServerHandler.dipperAstPosAsyncTaskService.pushAstPos(ipAddress); @@ -182,22 +200,30 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter { buf.writeBytes(returnBytes); buf.writeBytes(getCheckSumBytes(channelAns)); buf.writeBytes(getReturnBytes()); - ctx.write(buf); - ctx.flush(); + // 确保通道处于活跃状态 + // 不活跃状态继续写会产生CLOSE_WAIT现象 + if(ctx.channel().isActive()) { + ctx.write(buf); + } } + byte[] returnBytes = nettyServerHandler.dipperDataAsyncTaskService.getAstEPH(); //if (channelAns != null) { - log.debug("PEH Buffer Length is:" + returnBytes.length); - // 使用池化的堆内存,以减少内存碎片 - //ByteBuf channelPehAnsBuf = Unpooled.buffer(channelAns.getBytes().length); - //ByteBuf channelPehAnsBuf = bba.buffer(channelAns.getBytes().length); - ByteBuf channelPehAnsBuf = bba.buffer(returnBytes.length); - //channelPehAnsBuf.writeBytes(channelAns.getBytes(CharsetUtil.UTF_8)); - channelPehAnsBuf.writeBytes(returnBytes); - // compositeByteBuf.addComponent(channelPehAnsBuf); - // log.info("CompositeByteBuf Length is:" + compositeByteBuf.capacity()); + log.debug("PEH Buffer Length is:" + returnBytes.length); + // 使用池化的堆内存,以减少内存碎片 + //ByteBuf channelPehAnsBuf = Unpooled.buffer(channelAns.getBytes().length); + //ByteBuf channelPehAnsBuf = bba.buffer(channelAns.getBytes().length); + ByteBuf channelPehAnsBuf = bba.buffer(returnBytes.length); + //channelPehAnsBuf.writeBytes(channelAns.getBytes(CharsetUtil.UTF_8)); + channelPehAnsBuf.writeBytes(returnBytes); + // compositeByteBuf.addComponent(channelPehAnsBuf); + // log.info("CompositeByteBuf Length is:" + compositeByteBuf.capacity()); + // 确保通道处于活跃状态 + // 不活跃状态继续写会产生CLOSE_WAIT现象 + if(ctx.channel().isActive()) { ctx.write(channelPehAnsBuf); ctx.flush(); + } //} // 写给下一个Handler,最后一个Handler将内容移出pipeline diff --git a/src/main/java/com/telpo/dipperposition/server/DipperPositionServer.java b/src/main/java/com/telpo/dipperposition/server/DipperPositionServer.java index 6d513bb..c8e0f44 100644 --- a/src/main/java/com/telpo/dipperposition/server/DipperPositionServer.java +++ b/src/main/java/com/telpo/dipperposition/server/DipperPositionServer.java @@ -52,7 +52,8 @@ public class DipperPositionServer { .option(ChannelOption.SO_BACKLOG, 1024) .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 3000) // 两小时内没有数据的通信时,TCP会自动发送一个活动探测数据报文 - .childOption(ChannelOption.SO_KEEPALIVE, true); + .childOption(ChannelOption.SO_LINGER, 1000); + //.childOption(ChannelOption.SO_KEEPALIVE, true); //绑定端口,开始接收进来的连接 diff --git a/src/main/java/com/telpo/dipperposition/task/ScheduleService.java b/src/main/java/com/telpo/dipperposition/task/ScheduleService.java index 4a9f49a..34eaddc 100644 --- a/src/main/java/com/telpo/dipperposition/task/ScheduleService.java +++ b/src/main/java/com/telpo/dipperposition/task/ScheduleService.java @@ -32,7 +32,7 @@ public class ScheduleService { // 获取推送失败的记录 try { // 如果失败,则可以等待10秒再获取1次。 - int tryTimes = 2; + int tryTimes = 59; dipperDataAsyncTaskService.pullAstEPH(tryTimes); } catch (InterruptedException e) { log.error("获取星历数据重试睡眠发生异常:", e); From c6837861ccf4387e200d50769696fba0f4161716 Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Thu, 17 Jun 2021 15:19:41 +0800 Subject: [PATCH 172/172] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E8=A7=A3=E6=9E=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dipper_position_run.sh | 2 +- .../DipperAstPosAsyncTaskServiceImpl.java | 30 +++++++++++++------ .../service/impl/ProvinceInfoServiceImpl.java | 7 ++++- 3 files changed, 28 insertions(+), 11 deletions(-) diff --git a/dipper_position_run.sh b/dipper_position_run.sh index fbea5dc..fb9d25a 100644 --- a/dipper_position_run.sh +++ b/dipper_position_run.sh @@ -18,7 +18,7 @@ if [[ ${environment} == 'pro' ]]; then mv /home/linwl/dipperposition/dipperposition.jar /home/data/dipperposition/dipperposition.jar fi - nohup java -Xmx2048M -Xms2048M -Djava.security.egd=file:/dev/./urandom -Dio.netty.leakDetectionLevel=ADVANCED -jar dipperposition.jar --spring.profiles.active=pro & + nohup java -Xmx1024M -Xms1024M -Djava.security.egd=file:/dev/./urandom -Dio.netty.leakDetectionLevel=ADVANCED -jar dipperposition.jar --spring.profiles.active=pro & fi if [[ ${environment} == 'test' ]]; then diff --git a/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java b/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java index 800d6f7..ef21201 100644 --- a/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java +++ b/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java @@ -70,11 +70,17 @@ public class DipperAstPosAsyncTaskServiceImpl implements IDipperAstPosAsyncTaskS } //log.debug("IP省份获取错误,结果为:" + result); JSONObject provinceJson = JSONObject.parseObject(result); - String province = (String)provinceJson.get("province"); - if (ObjectUtils.isEmpty(province)) { - log.debug("json is :" + buffer.toString()); - return null; + String province = null; + try { + province = (String)provinceJson.get("province"); + if (ObjectUtils.isEmpty(province)) { + log.debug("json is :" + buffer.toString()); + return null; + } + } catch (Exception e) { + log.error("JSONObject分析出错,provinceJson:" + provinceJson); } + return province; } } else { @@ -116,7 +122,7 @@ public class DipperAstPosAsyncTaskServiceImpl implements IDipperAstPosAsyncTaskS //this.centerProvinceFilePath = positionConfig.getCenterProvinceFilePath(); // (1) 获取省会城市信息 String centerAddress = getIpPositionProvince(ipAddress); - if (ObjectUtils.isEmpty(centerAddress) || centerAddress.equals("0")) { + if (centerAddress == null || ObjectUtils.isEmpty(centerAddress) || centerAddress.equals("0")) { log.warn("IP地址非法,无法获取辅助位置信息!"); // 返回武汉的定位数据 centerAddress = this.centerProvince; @@ -132,10 +138,16 @@ public class DipperAstPosAsyncTaskServiceImpl implements IDipperAstPosAsyncTaskS String utf8CenterAddress = new String(utf8, "UTF-8"); log.debug("centerAddress is " + utf8CenterAddress); - ProvinceInfoEntity entity = provinceInfoService.getProvinceInfo(utf8CenterAddress); - if (entity != null) { - lonValue = entity.getLon(); - altValue = entity.getAlt(); + if (utf8CenterAddress.endsWith("省") || utf8CenterAddress.endsWith("区") || utf8CenterAddress.endsWith("市")) { + + ProvinceInfoEntity entity = provinceInfoService.getProvinceInfo(utf8CenterAddress); + if (entity != null) { + lonValue = entity.getLon(); + altValue = entity.getAlt(); + } + } else { + log.error("非法省份:" + utf8CenterAddress); + return null; } } catch (Exception e) { log.error(e.getMessage()); diff --git a/src/main/java/com/telpo/dipperposition/service/impl/ProvinceInfoServiceImpl.java b/src/main/java/com/telpo/dipperposition/service/impl/ProvinceInfoServiceImpl.java index b9e7baf..46ae674 100644 --- a/src/main/java/com/telpo/dipperposition/service/impl/ProvinceInfoServiceImpl.java +++ b/src/main/java/com/telpo/dipperposition/service/impl/ProvinceInfoServiceImpl.java @@ -1,5 +1,6 @@ package com.telpo.dipperposition.service.impl; +import cn.hutool.core.util.ObjectUtil; import com.telpo.dipperposition.entity.mongo.ProvinceInfoEntity; import com.telpo.dipperposition.mapper.ProvinceInfoMapper; import com.telpo.dipperposition.service.IProvinceInfoService; @@ -56,7 +57,11 @@ public class ProvinceInfoServiceImpl implements IProvinceInfoService { ExampleMatcher matcher = ExampleMatcher.matching().withIgnorePaths("_class"); Example example = Example.of(query, matcher); Optional data = provinceInfoMapper.findOne(example); - return data.get(); + if (ObjectUtil.isNotEmpty(data)) { + return data.get(); + } else { + return null; + } } catch (Exception e) { log.error("获取省份异常:", e); return null;