@@ -26,7 +26,7 @@ public class OkHttpUtil { | |||
@Autowired private OkHttpClient okHttpClient; | |||
private static OkHttpUtil okHttpUtil; | |||
public static OkHttpUtil okHttpUtil; | |||
@PostConstruct | |||
public void init() { | |||
@@ -25,12 +25,7 @@ public class RedisUtil { | |||
@Resource private RedisTemplate<String, Object> redisTemplate; | |||
private static RedisUtil redisUtil; | |||
/** | |||
* spring会自动从ioc容器当中根据RedisUtil类型找到redisUtil,当做参数传进来 | |||
* | |||
*/ | |||
public static RedisUtil redisUtil; | |||
@PostConstruct | |||
public void init() { | |||
redisUtil = this; | |||
@@ -34,7 +34,7 @@ public class NettyServerConfig { | |||
@NacosValue(value = "${position-server.starsAsycPort}") | |||
private String starsAsycServerPort; | |||
private static NettyServerConfig nettyServerConfig; | |||
public static NettyServerConfig nettyServerConfig; | |||
@PostConstruct | |||
public void init() { | |||
@@ -40,7 +40,7 @@ public class PositionConfig { | |||
int astTimeout; | |||
private static PositionConfig positionConfig; | |||
public static PositionConfig positionConfig; | |||
@PostConstruct | |||
public void init() { | |||
@@ -0,0 +1,30 @@ | |||
package com.telpo.dipperposition.controller; | |||
import com.telpo.dipperposition.service.IDipperAstPosAsyncTaskService; | |||
import com.telpo.dipperposition.service.IDipperAstTimeAsyncTaskService; | |||
import lombok.extern.slf4j.Slf4j; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.web.bind.annotation.RestController; | |||
/** | |||
* @program: DipperAstPosAsyncTaskController | |||
* @description: 北斗定位 | |||
* @author: linwl | |||
* @create: 2020-07-10 14:01 | |||
*/ | |||
@RestController | |||
@Slf4j | |||
public class DipperAstPosAsyncTaskController { | |||
@Autowired | |||
IDipperAstPosAsyncTaskService dipperAstPosAsyncTaskService; | |||
/* | |||
* 拉取星历数据 | |||
*/ | |||
public String pushAstPos(String ipAddress) { | |||
return dipperAstPosAsyncTaskService.pushAstPos(ipAddress); | |||
} | |||
} |
@@ -0,0 +1,32 @@ | |||
package com.telpo.dipperposition.controller; | |||
import com.telpo.dipperposition.service.IDipperAstTimeAsyncTaskService; | |||
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.web.bind.annotation.RequestMapping; | |||
import org.springframework.web.bind.annotation.RestController; | |||
/** | |||
* @program: DipperPositionController | |||
* @description: 北斗定位 | |||
* @author: linwl | |||
* @create: 2020-07-10 14:01 | |||
*/ | |||
@RestController | |||
@Slf4j | |||
public class DipperAstTimeAsyncTaskController { | |||
@Autowired | |||
IDipperAstTimeAsyncTaskService dipperTimeAsyncTaskService; | |||
/* | |||
* 拉取星历数据 | |||
*/ | |||
public String pushAstTime() { | |||
return dipperTimeAsyncTaskService.pushAstTime(); | |||
} | |||
} |
@@ -1,6 +1,8 @@ | |||
package com.telpo.dipperposition.controller; | |||
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.web.bind.annotation.RequestMapping; | |||
import org.springframework.web.bind.annotation.RestController; | |||
@@ -14,13 +16,32 @@ import org.springframework.web.bind.annotation.RestController; | |||
*/ | |||
@RestController | |||
@Slf4j | |||
public class DipperPositionController { | |||
public class DipperDataAsyncTaskController { | |||
@Value(value = "${position-server.serverAddr}") | |||
private String hello; | |||
//RzlAccount rzlAccount; | |||
@Autowired | |||
IDipperDataAsyncTaskService dipperDataAsyncTaskService; | |||
/* | |||
* 拉取星历数据 | |||
*/ | |||
public void pullAstEPH() { | |||
dipperDataAsyncTaskService.pullAstEPH(); | |||
} | |||
/* | |||
* 获取星历数据 | |||
*/ | |||
public String getAstEPH() { | |||
return dipperDataAsyncTaskService.getAstEPH(); | |||
} | |||
@RequestMapping("/getPos") | |||
public String getPos() { | |||
return "return serverAddr = " + hello; | |||
} | |||
} |
@@ -2,6 +2,9 @@ package com.telpo.dipperposition.handler; | |||
import com.telpo.dipperposition.config.NettyServerConfig; | |||
import com.telpo.dipperposition.config.PositionConfig; | |||
import com.telpo.dipperposition.controller.DipperAstPosAsyncTaskController; | |||
import com.telpo.dipperposition.controller.DipperAstTimeAsyncTaskController; | |||
import com.telpo.dipperposition.controller.DipperDataAsyncTaskController; | |||
import com.telpo.dipperposition.enums.DipperReturnValue; | |||
import com.telpo.dipperposition.service.IDipperAstPosAsyncTaskService; | |||
import com.telpo.dipperposition.service.IDipperAstTimeAsyncTaskService; | |||
@@ -38,11 +41,11 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter { | |||
private static String AST_EPH_CMD_BYTE = "455048"; | |||
@Autowired | |||
private IDipperAstTimeAsyncTaskService dipperTimeAsyncTaskService; | |||
private DipperAstTimeAsyncTaskController dipperTimeAsyncTaskController; | |||
@Autowired | |||
private IDipperAstPosAsyncTaskService dipperAstPosAsyncTaskService; | |||
private DipperAstPosAsyncTaskController dipperAstPosAsyncTaskController; | |||
@Autowired | |||
private IDipperDataAsyncTaskService dipperDataAsyncTaskService; | |||
private DipperDataAsyncTaskController dipperDataAsyncTaskController; | |||
@Autowired | |||
private NettyServerConfig nettyServerConfig; | |||
@@ -114,10 +117,10 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter { | |||
//if (AST_TIME_CMD.equals(recvmg)) { | |||
if (AST_TIME_CMD.equals(msg)) { | |||
// 初始时间辅助输入; | |||
if (dipperTimeAsyncTaskService == null) { | |||
dipperTimeAsyncTaskService = new DipperAstTimeAsyncTaskServiceImpl(); | |||
} | |||
channelAns = dipperTimeAsyncTaskService.pushAstTime(); | |||
// if (dipperTimeAsyncTaskService == null) { | |||
// dipperTimeAsyncTaskService = new DipperAstTimeAsyncTaskServiceImpl(); | |||
// } | |||
channelAns = dipperTimeAsyncTaskController.pushAstTime(); | |||
} | |||
// 发送SDBP-AST-POS获取辅助位置信息 | |||
@@ -136,24 +139,25 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter { | |||
// positionConfig.getCenterProvince(), | |||
// positionConfig.getIpPositionRequestPath(), | |||
// positionConfig.getIpPositionRequestKey()); | |||
if (dipperAstPosAsyncTaskService == null) { | |||
dipperAstPosAsyncTaskService = new DipperAstPosAsyncTaskServiceImpl(); | |||
} | |||
channelAns = dipperAstPosAsyncTaskService.pushAstPos(ipAddress, | |||
"/csv/provinceLonAlt.csv", | |||
"湖北省", | |||
"https://restapi.amap.com/v3/ip", | |||
"65e794b0a1a4b87eeec86f93fea05411"); | |||
// if (dipperAstPosAsyncTaskService == null) { | |||
// dipperAstPosAsyncTaskService = new DipperAstPosAsyncTaskServiceImpl(); | |||
// } | |||
channelAns = dipperAstPosAsyncTaskController.pushAstPos(ipAddress); | |||
// (ipAddress, | |||
// "/csv/provinceLonAlt.csv", | |||
// "湖北省", | |||
// "https://restapi.amap.com/v3/ip", | |||
// "65e794b0a1a4b87eeec86f93fea05411"); | |||
} | |||
// 从缓存获取SDBP-AST-EPH星历数 | |||
//if (Integer.parseInt(starsAsycServerPort) == channel.localAddress().getPort()) { | |||
//if (AST_POS_CMD.equals(recvmg)) { | |||
if (AST_POS_CMD.equals(msg)) { | |||
if (dipperDataAsyncTaskService == null) { | |||
dipperDataAsyncTaskService = new DipperDataAsyncTaskServiceImpl(); | |||
} | |||
channelAns = dipperDataAsyncTaskService.getAstEPH(); | |||
// if (dipperDataAsyncTaskService == null) { | |||
// dipperDataAsyncTaskService = new DipperDataAsyncTaskServiceImpl(); | |||
// } | |||
channelAns = dipperDataAsyncTaskController.getAstEPH(); | |||
} | |||
log.info(channelAns); | |||
@@ -16,16 +16,16 @@ import java.io.UnsupportedEncodingException; | |||
*/ | |||
public interface IDipperAstPosAsyncTaskService { | |||
@Autowired | |||
void setDipperAstPosAsyncTaskService(IDipperAstPosAsyncTaskService dipperAstPosAsyncTaskService); | |||
/** | |||
* 同步任务 | |||
* | |||
*/ | |||
String pushAstPos(String ipAddress, | |||
String centerProvinceFilePath, | |||
String centerProvince, | |||
String ipPositionRequestPath, | |||
String ipPositionRequestKey) throws UnsupportedEncodingException; | |||
String pushAstPos(String ipAddress); | |||
// String pushAstPos(String ipAddress, | |||
// String centerProvinceFilePath, | |||
// String centerProvince, | |||
// String ipPositionRequestPath, | |||
// String ipPositionRequestKey) throws UnsupportedEncodingException; | |||
} |
@@ -11,8 +11,8 @@ import org.springframework.beans.factory.annotation.Autowired; | |||
*/ | |||
public interface IDipperAstTimeAsyncTaskService { | |||
@Autowired | |||
void setDipperAstTimeAsyncTaskService(IDipperAstTimeAsyncTaskService dipperAstTimeAsyncTaskService); | |||
// @Autowired | |||
// void setDipperAstTimeAsyncTaskService(IDipperAstTimeAsyncTaskService dipperAstTimeAsyncTaskService); | |||
/** | |||
* 同步任务 | |||
* | |||
@@ -13,8 +13,8 @@ import org.springframework.beans.factory.annotation.Value; | |||
*/ | |||
public interface IDipperDataAsyncTaskService { | |||
@Autowired | |||
void setDipperDataAsyncTaskService(IDipperDataAsyncTaskService IDipperDataAsyncTaskService); | |||
// @Autowired | |||
// void setDipperDataAsyncTaskService(IDipperDataAsyncTaskService IDipperDataAsyncTaskService); | |||
/** | |||
* 同步任务 | |||
* | |||
@@ -11,8 +11,8 @@ import org.springframework.beans.factory.annotation.Autowired; | |||
*/ | |||
public interface IpProvinceService { | |||
@Autowired | |||
void setIPProvinceService(IpProvinceService ipProvinceService); | |||
// @Autowired | |||
// void setIPProvinceService(IpProvinceService ipProvinceService); | |||
/** | |||
* 保存IP省份 | |||
* | |||
@@ -2,6 +2,8 @@ package com.telpo.dipperposition.service.impl; | |||
import com.alibaba.fastjson.JSONObject; | |||
import com.telpo.dipperposition.common.*; | |||
import com.telpo.dipperposition.config.NettyServerConfig; | |||
import com.telpo.dipperposition.config.PositionConfig; | |||
import com.telpo.dipperposition.entity.mongo.IpProvinceEntity; | |||
import com.telpo.dipperposition.service.IDipperAstPosAsyncTaskService; | |||
import com.telpo.dipperposition.service.IpProvinceService; | |||
@@ -33,17 +35,21 @@ public class DipperAstPosAsyncTaskServiceImpl implements IDipperAstPosAsyncTaskS | |||
@Autowired | |||
private OkHttpUtil okHttpUtil; | |||
@Autowired | |||
private NettyServerConfig nettyServerConfig; | |||
@Autowired | |||
private PositionConfig positionConfig; | |||
@Autowired | |||
private IpProvinceService ipProvinceService; | |||
private static IDipperAstPosAsyncTaskService dipperAstPosAsyncTaskService; | |||
// private static IDipperAstPosAsyncTaskService dipperAstPosAsyncTaskService; | |||
/** | |||
* spring会自动从ioc容器当中根据IDipperAstPosAsyncTaskService类型找到dipperAstPosAsyncTaskService,当做参数传进来 | |||
* | |||
*/ | |||
@Override | |||
public void setDipperAstPosAsyncTaskService(IDipperAstPosAsyncTaskService dipperAstPosAsyncTaskService) { | |||
this.dipperAstPosAsyncTaskService = dipperAstPosAsyncTaskService; | |||
} | |||
// @Override | |||
// public void setDipperAstPosAsyncTaskService(IDipperAstPosAsyncTaskService dipperAstPosAsyncTaskService) { | |||
// this.dipperAstPosAsyncTaskService = dipperAstPosAsyncTaskService; | |||
// } | |||
private String centerProvince; | |||
private String centerProvinceFilePath; | |||
@@ -149,15 +155,16 @@ public class DipperAstPosAsyncTaskServiceImpl implements IDipperAstPosAsyncTaskS | |||
*/ | |||
@Override | |||
@Async("asyncServiceExecutor") | |||
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; | |||
// public String pushAstPos(String ipAddress, | |||
// String centerProvinceFilePath, | |||
// String centerProvince, | |||
// String ipPositionRequestPath, | |||
// String ipPositionRequestKey) throws UnsupportedEncodingException { | |||
public String pushAstPos(String ipAddress) { | |||
this.ipPositionRequestKey = positionConfig.getIpPositionRequestKey(); | |||
this.ipPositionRequestPath = positionConfig.getIpPositionRequestPath(); | |||
this.centerProvince = positionConfig.getCenterProvince(); | |||
this.centerProvinceFilePath = positionConfig.getCenterProvinceFilePath(); | |||
// (1) 获取省会城市信息 | |||
String centerAddress = getIpPositionProvince(ipAddress); | |||
if (ObjectUtils.isEmpty(centerAddress) || centerAddress.equals("0")) { | |||
@@ -21,16 +21,16 @@ import java.time.LocalDateTime; | |||
@Service | |||
@Slf4j | |||
public class DipperAstTimeAsyncTaskServiceImpl implements IDipperAstTimeAsyncTaskService { | |||
private static IDipperAstTimeAsyncTaskService dipperAstTimeAsyncTaskService; | |||
/** | |||
* spring会自动从ioc容器当中根据IDipperAstTimeAsyncTaskService类型找到dipperAstTimeAsyncTaskService,当做参数传进来 | |||
* | |||
*/ | |||
@Override | |||
public void setDipperAstTimeAsyncTaskService(IDipperAstTimeAsyncTaskService dipperAstTimeAsyncTaskService) { | |||
this.dipperAstTimeAsyncTaskService = dipperAstTimeAsyncTaskService; | |||
} | |||
// | |||
// private static IDipperAstTimeAsyncTaskService dipperAstTimeAsyncTaskService; | |||
// /** | |||
// * spring会自动从ioc容器当中根据IDipperAstTimeAsyncTaskService类型找到dipperAstTimeAsyncTaskService,当做参数传进来 | |||
// * | |||
// */ | |||
// @Override | |||
// public void setDipperAstTimeAsyncTaskService(IDipperAstTimeAsyncTaskService dipperAstTimeAsyncTaskService) { | |||
// this.dipperAstTimeAsyncTaskService = dipperAstTimeAsyncTaskService; | |||
// } | |||
@Override | |||
@Async("asyncServiceExecutor") | |||
@@ -31,15 +31,15 @@ public class DipperDataAsyncTaskServiceImpl implements IDipperDataAsyncTaskServi | |||
private SchedulingExecutorConfig schedulingExecutorConfig; | |||
private static IDipperDataAsyncTaskService dipperDataAsyncTaskService; | |||
/** | |||
* spring会自动从ioc容器当中根据IDipperAstTimeAsyncTaskService类型找到dipperDataAsyncTaskService,当做参数传进来 | |||
* | |||
*/ | |||
@Override | |||
public void setDipperDataAsyncTaskService(IDipperDataAsyncTaskService dipperDataAsyncTaskService) { | |||
this.dipperDataAsyncTaskService = dipperDataAsyncTaskService; | |||
} | |||
// private static IDipperDataAsyncTaskService dipperDataAsyncTaskService; | |||
// /** | |||
// * spring会自动从ioc容器当中根据IDipperAstTimeAsyncTaskService类型找到dipperDataAsyncTaskService,当做参数传进来 | |||
// * | |||
// */ | |||
// @Override | |||
// public void setDipperDataAsyncTaskService(IDipperDataAsyncTaskService dipperDataAsyncTaskService) { | |||
// this.dipperDataAsyncTaskService = dipperDataAsyncTaskService; | |||
// } | |||
@Override | |||
public void pullAstEPH() { | |||
@@ -51,6 +51,7 @@ public class DipperDataAsyncTaskServiceImpl implements IDipperDataAsyncTaskServi | |||
log.error("获取星历数据错误,取不到星历数据。"); | |||
} else { | |||
// 保存到DB或者缓存 | |||
log.info("保存到DB或者缓存"); | |||
redisUtil.set(DIPPER_DATA_KEY,dipperData); | |||
} | |||
} | |||
@@ -73,7 +74,7 @@ public class DipperDataAsyncTaskServiceImpl implements IDipperDataAsyncTaskServi | |||
} | |||
@Override | |||
@Async("asyncServiceExecutor") | |||
//@Async("asyncServiceExecutor") | |||
public String getAstEPH(){ | |||
return (String)redisUtil.get(DIPPER_DATA_KEY); | |||
} | |||
@@ -23,15 +23,15 @@ public class IpProvinceServiceImpl implements IpProvinceService { | |||
@Autowired | |||
private IpProvinceMapper ipProvinceMapper; | |||
private static IpProvinceService ipProvinceService; | |||
/** | |||
* spring会自动从ioc容器当中根据IPProvinceService类型找到ipProvinceService,当做参数传进来 | |||
* | |||
*/ | |||
@Override | |||
public void setIPProvinceService(IpProvinceService ipProvinceService) { | |||
this.ipProvinceService = ipProvinceService; | |||
} | |||
// private static IpProvinceService ipProvinceService; | |||
// /** | |||
// * spring会自动从ioc容器当中根据IPProvinceService类型找到ipProvinceService,当做参数传进来 | |||
// * | |||
// */ | |||
// @Override | |||
// public void setIPProvinceService(IpProvinceService ipProvinceService) { | |||
// this.ipProvinceService = ipProvinceService; | |||
// } | |||
@Override | |||
public boolean saveIpProvince(IpProvinceEntity entity) { | |||
ipProvinceMapper.saveIp(entity); | |||