@@ -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(); | |||
@@ -14,14 +14,9 @@ public interface IDipperDataAsyncTaskService { | |||
/** | |||
* 同步任务 | |||
* @param astServer | |||
* @param ephAstHexPort | |||
* @param astTimeout | |||
* | |||
*/ | |||
void pullAstEPH(String astServer, | |||
int ephAstHexPort, | |||
int astTimeout); | |||
void pullAstEPH(); | |||
/** | |||
@@ -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"; | |||
@@ -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); | |||
} | |||