Parcourir la source

增加配置文件读取

tags/v1.0.0^2
林万龙 il y a 4 ans
Parent
révision
db517c2631
6 fichiers modifiés avec 73 ajouts et 38 suppressions
  1. +24
    -1
      src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java
  2. +5
    -1
      src/main/java/com/telpo/dipperposition/service/IDipperAstPosAsyncTaskService.java
  3. +8
    -1
      src/main/java/com/telpo/dipperposition/service/IDipperDataAsyncTaskService.java
  4. +15
    -21
      src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java
  5. +10
    -13
      src/main/java/com/telpo/dipperposition/service/impl/DipperDataAsyncTaskServiceImpl.java
  6. +11
    -1
      src/main/java/com/telpo/dipperposition/task/ScheduleService.java

+ 24
- 1
src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java Voir le fichier

@@ -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星历数


+ 5
- 1
src/main/java/com/telpo/dipperposition/service/IDipperAstPosAsyncTaskService.java Voir le fichier

@@ -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;

}

+ 8
- 1
src/main/java/com/telpo/dipperposition/service/IDipperDataAsyncTaskService.java Voir le fichier

@@ -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);


/**


+ 15
- 21
src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java Voir le fichier

@@ -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<String> centerAddressSets = CSVUtil.readCSV(centerProvinceFilePath);
List<String> 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);


+ 10
- 13
src/main/java/com/telpo/dipperposition/service/impl/DipperDataAsyncTaskServiceImpl.java Voir le fichier

@@ -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";


+ 11
- 1
src/main/java/com/telpo/dipperposition/task/ScheduleService.java Voir le fichier

@@ -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);
}


Chargement…
Annuler
Enregistrer