|
- 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;
- import org.springframework.scheduling.annotation.Async;
- import org.springframework.stereotype.Service;
-
- /**
- * @program: DipperDataAsyncTaskServiceImpl
- * @description: 获取星历数据。
- * @author: king
- * @create: 2021-01-10 14:01
- */
- @Service
- @Slf4j
- public class DipperDataAsyncTaskServiceImpl implements IDipperDataAsyncTaskService {
-
-
- private static String DIPPER_DATA_KEY = "TaidouDipperData";
- private static String DIPPER_ALL_DATA_REQ = "616C6C";
-
- @Autowired
- private RedisUtil redisUtil;
- @Autowired
- private SchedulingExecutorConfig schedulingExecutorConfig;
-
-
-
- @Override
- @Async("asyncServiceExecutor")
- public void pullAstEPH() {
- // (1) 发送bds获取星历数据
- String dipperData = pullEPHFromDipper();
-
- // (2) 获取星历数据
- if (dipperData == null) {
- log.error("获取星历数据错误,取不到星历数据。");
- } else {
- // 保存到DB或者缓存
- log.info("保存到DB或者缓存");
- redisUtil.set(DIPPER_DATA_KEY,dipperData);
- }
- }
-
- private String pullEPHFromDipper() {
-
- // 创建Socket客户端实例;
- SocketClient client = new SocketClient(schedulingExecutorConfig.getAstServer(), schedulingExecutorConfig.getEphAstHexPort(),schedulingExecutorConfig.getAstTimeout());
-
- // astTimeCmd 组装
- String astTimeCmd = DIPPER_ALL_DATA_REQ;
- String hexIn = 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);
- }
- }
|