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] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=85=8D=E7=BD=AE=E6=96=87?= =?UTF-8?q?=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); }