@@ -40,6 +40,25 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter { | |||||
@Value(value = "${position.server.starsAsycPort}") | @Value(value = "${position.server.starsAsycPort}") | ||||
private String starsAsycServerPort; | 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获取辅助位置信息 | // 发送SDBP-AST-POS获取辅助位置信息 | ||||
if (Integer.parseInt(posAsycServerPort) == channel.localAddress().getPort()) { | if (Integer.parseInt(posAsycServerPort) == channel.localAddress().getPort()) { | ||||
channelAns = dipperAstPosAsyncTaskService.pushAstPos(ipAddress); | |||||
channelAns = dipperAstPosAsyncTaskService.pushAstPos(ipAddress, | |||||
centerProvinceFilePath, | |||||
centerProvince, | |||||
ipPositionRequestPath, | |||||
ipPositionRequestKey); | |||||
} | } | ||||
// 从缓存获取SDBP-AST-EPH星历数 | // 从缓存获取SDBP-AST-EPH星历数 | ||||
@@ -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; | |||||
} | } |
@@ -1,5 +1,7 @@ | |||||
package com.telpo.dipperposition.service; | package com.telpo.dipperposition.service; | ||||
import org.springframework.beans.factory.annotation.Value; | |||||
/** | /** | ||||
* @program: IDipperDataAsyncTaskService | * @program: IDipperDataAsyncTaskService | ||||
* @description: 发送bds获取星历数据。 | * @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); | |||||
/** | /** | ||||
@@ -42,24 +42,10 @@ public class DipperAstPosAsyncTaskServiceImpl implements IDipperAstPosAsyncTaskS | |||||
@Autowired | @Autowired | ||||
private IPProvinceService iPProvinceService; | 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 { | // private String getAstPos(String ipAddress) throws UnsupportedEncodingException { | ||||
// | // | ||||
// String centerAddress = getIpPositionProvince(ipAddress); | // String centerAddress = getIpPositionProvince(ipAddress); | ||||
@@ -90,7 +76,7 @@ public class DipperAstPosAsyncTaskServiceImpl implements IDipperAstPosAsyncTaskS | |||||
// 不存在说明token是已过期了 | // 不存在说明token是已过期了 | ||||
String centerProvinceName = ""; | String centerProvinceName = ""; | ||||
String centerProvinceLonAndAlt = ""; | String centerProvinceLonAndAlt = ""; | ||||
List<String> centerAddressSets = CSVUtil.readCSV(centerProvinceFilePath); | |||||
List<String> centerAddressSets = CSVUtil.readCSV(this.centerProvinceFilePath); | |||||
for (String centerAddressSet:centerAddressSets) { | for (String centerAddressSet:centerAddressSets) { | ||||
String[] centerAddressSetArray = centerAddressSet.split(","); | String[] centerAddressSetArray = centerAddressSet.split(","); | ||||
if (centerAddressSetArray.length < 3) { | if (centerAddressSetArray.length < 3) { | ||||
@@ -159,13 +145,21 @@ public class DipperAstPosAsyncTaskServiceImpl implements IDipperAstPosAsyncTaskS | |||||
* @param ipAddress | * @param ipAddress | ||||
*/ | */ | ||||
@Override | @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) 获取省会城市信息 | // (1) 获取省会城市信息 | ||||
String centerAddress = getIpPositionProvince(ipAddress); | String centerAddress = getIpPositionProvince(ipAddress); | ||||
if (ObjectUtils.isEmpty(centerAddress) || centerAddress.equals("0")) { | if (ObjectUtils.isEmpty(centerAddress) || centerAddress.equals("0")) { | ||||
log.warn("IP地址非法,无法获取辅助位置信息!"); | log.warn("IP地址非法,无法获取辅助位置信息!"); | ||||
// 返回武汉的定位数据 | // 返回武汉的定位数据 | ||||
centerAddress = centerProvince; | |||||
centerAddress = this.centerProvince; | |||||
} else { | } else { | ||||
// 保存到mongoDB | // 保存到mongoDB | ||||
createIPProvince(ipAddress, centerAddress); | createIPProvince(ipAddress, centerAddress); | ||||
@@ -22,21 +22,18 @@ public class DipperDataAsyncTaskServiceImpl implements IDipperDataAsyncTaskServi | |||||
@Autowired | @Autowired | ||||
private RedisUtil redisUtil; | 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 static String DIPPER_DATA_KEY = "TaidouDipperData"; | ||||
private String astServer; | |||||
private int ephAstHexPort; | |||||
private int astTimeout; | |||||
@Override | @Override | ||||
public void pullAstEPH() { | |||||
public void pullAstEPH(String astServer, | |||||
int ephAstHexPort, | |||||
int astTimeout) { | |||||
this.astServer = astServer; | |||||
this.ephAstHexPort = ephAstHexPort; | |||||
this.astTimeout = astTimeout; | |||||
// (1) 发送bds获取星历数据 | // (1) 发送bds获取星历数据 | ||||
String dipperData = pullEPHFromDipper(); | String dipperData = pullEPHFromDipper(); | ||||
@@ -53,7 +50,7 @@ public class DipperDataAsyncTaskServiceImpl implements IDipperDataAsyncTaskServi | |||||
private String pullEPHFromDipper() { | private String pullEPHFromDipper() { | ||||
// 创建Socket客户端实例; | // 创建Socket客户端实例; | ||||
SocketClient client = new SocketClient(astServer, ephAstPort, astTimeout); | |||||
SocketClient client = new SocketClient(astServer, ephAstHexPort, astTimeout); | |||||
// astTimeCmd 组装 | // astTimeCmd 组装 | ||||
String astTimeCmd = "all"; | String astTimeCmd = "all"; | ||||
@@ -3,6 +3,7 @@ package com.telpo.dipperposition.task; | |||||
import com.telpo.dipperposition.service.IDipperDataAsyncTaskService; | import com.telpo.dipperposition.service.IDipperDataAsyncTaskService; | ||||
import lombok.extern.slf4j.Slf4j; | import lombok.extern.slf4j.Slf4j; | ||||
import org.springframework.beans.factory.annotation.Autowired; | import org.springframework.beans.factory.annotation.Autowired; | ||||
import org.springframework.beans.factory.annotation.Value; | |||||
import org.springframework.scheduling.annotation.Scheduled; | import org.springframework.scheduling.annotation.Scheduled; | ||||
import org.springframework.stereotype.Component; | import org.springframework.stereotype.Component; | ||||
@@ -17,6 +18,15 @@ import org.springframework.stereotype.Component; | |||||
@Slf4j | @Slf4j | ||||
public class ScheduleService { | 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 | @Autowired | ||||
private IDipperDataAsyncTaskService dipperDataAsyncTaskService; | private IDipperDataAsyncTaskService dipperDataAsyncTaskService; | ||||
@@ -31,7 +41,7 @@ public class ScheduleService { | |||||
log.info("开始星历数据同步!"); | log.info("开始星历数据同步!"); | ||||
// 获取推送失败的记录 | // 获取推送失败的记录 | ||||
try { | try { | ||||
dipperDataAsyncTaskService.pullAstEPH(); | |||||
dipperDataAsyncTaskService.pullAstEPH(astServer,ephAstHexPort,astTimeout); | |||||
} catch (Exception e) { | } catch (Exception e) { | ||||
log.error("执行定时获取星历数据发生异常:", e); | log.error("执行定时获取星历数据发生异常:", e); | ||||
} | } | ||||