@@ -25,12 +25,22 @@ public class OkHttpUtil { | |||
@Autowired private OkHttpClient okHttpClient; | |||
private static OkHttpUtil okHttpUtil; | |||
/** | |||
* 根据map获取get请求参数 | |||
* spring会自动从ioc容器当中根据OkHttpUtil类型找到okHttpUtil,当做参数传进来 | |||
* | |||
* @param queries | |||
* @return | |||
*/ | |||
@Autowired | |||
public void setOkHttpUtil(OkHttpUtil okHttpUtil) { | |||
this.okHttpUtil = okHttpUtil; | |||
} | |||
/** | |||
* 根据map获取get请求参数 | |||
* | |||
* @param queries | |||
* @return | |||
*/ | |||
public StringBuffer getQueryString(String url, Map<String, String> queries) { | |||
StringBuffer sb = new StringBuffer(url); | |||
if (queries != null && queries.keySet().size() > 0) { | |||
@@ -1,6 +1,7 @@ | |||
package com.telpo.dipperposition.common; | |||
import lombok.extern.slf4j.Slf4j; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.data.redis.core.RedisTemplate; | |||
import org.springframework.stereotype.Component; | |||
import org.springframework.util.CollectionUtils; | |||
@@ -23,6 +24,15 @@ public class RedisUtil { | |||
@Resource private RedisTemplate<String, Object> redisTemplate; | |||
private static RedisUtil redisUtil; | |||
/** | |||
* spring会自动从ioc容器当中根据RedisUtil类型找到redisUtil,当做参数传进来 | |||
* | |||
*/ | |||
@Autowired | |||
public void setRedisUtil(RedisUtil redisUtil) { | |||
this.redisUtil = redisUtil; | |||
} | |||
// =============================common============================ | |||
/** | |||
* 指定缓存失效时间 | |||
@@ -2,8 +2,10 @@ package com.telpo.dipperposition.config; | |||
import com.alibaba.nacos.api.config.annotation.NacosValue; | |||
import com.alibaba.nacos.spring.context.annotation.config.NacosPropertySource; | |||
import com.telpo.dipperposition.common.OkHttpUtil; | |||
import lombok.Getter; | |||
import lombok.Setter; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.context.annotation.Configuration; | |||
/** | |||
@@ -30,4 +32,14 @@ public class NettyServerConfig { | |||
@NacosValue(value = "${position-server.starsAsycPort}") | |||
private String starsAsycServerPort; | |||
private static NettyServerConfig nettyServerConfig; | |||
/** | |||
* spring会自动从ioc容器当中根据NettyServerConfig类型找到nettyServerConfig, | |||
* 当做参数传进来 | |||
* | |||
*/ | |||
@Autowired | |||
public void setNettyServerConfig(NettyServerConfig nettyServerConfig) { | |||
this.nettyServerConfig = nettyServerConfig; | |||
} | |||
} |
@@ -4,6 +4,7 @@ import com.alibaba.nacos.api.config.annotation.NacosValue; | |||
import com.alibaba.nacos.spring.context.annotation.config.NacosPropertySource; | |||
import lombok.Getter; | |||
import lombok.Setter; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.context.annotation.Configuration; | |||
/** | |||
@@ -35,4 +36,15 @@ public class PositionConfig { | |||
int posAstPort; | |||
@NacosValue("${pos.astTimeout}") | |||
int astTimeout; | |||
private static PositionConfig positionConfig; | |||
/** | |||
* spring会自动从ioc容器当中根据PositionConfig类型找到positionConfig,当做参数传进来 | |||
* | |||
*/ | |||
@Autowired | |||
public void setPositionConfig(PositionConfig positionConfig) { | |||
this.positionConfig = positionConfig; | |||
} | |||
} |
@@ -1,8 +1,10 @@ | |||
package com.telpo.dipperposition.mapper; | |||
import com.telpo.dipperposition.annotation.MongoSwitch; | |||
import com.telpo.dipperposition.config.NettyServerConfig; | |||
import com.telpo.dipperposition.entity.mongo.IPProvinceEntity; | |||
import db.BaseMongoDbDao; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.stereotype.Repository; | |||
import java.util.List; | |||
@@ -16,6 +18,17 @@ import java.util.List; | |||
@Repository | |||
public class IPProvinceMapper extends BaseMongoDbDao<IPProvinceEntity> { | |||
private static IPProvinceMapper iPProvinceMapper; | |||
/** | |||
* spring会自动从ioc容器当中根据IPProvinceMapper类型找到iPProvinceMapper, | |||
* 当做参数传进来 | |||
* | |||
*/ | |||
@Autowired | |||
public void setIPProvinceMapper(IPProvinceMapper iPProvinceMapper) { | |||
this.iPProvinceMapper = iPProvinceMapper; | |||
} | |||
@Override | |||
protected Class<IPProvinceEntity> getEntityClass() { | |||
return IPProvinceEntity.class; | |||
@@ -42,6 +42,16 @@ public class DipperAstPosAsyncTaskServiceImpl implements IDipperAstPosAsyncTaskS | |||
@Autowired | |||
private IPProvinceService iPProvinceService; | |||
private static IDipperAstPosAsyncTaskService dipperAstPosAsyncTaskService; | |||
/** | |||
* spring会自动从ioc容器当中根据IDipperAstPosAsyncTaskService类型找到dipperAstPosAsyncTaskService,当做参数传进来 | |||
* | |||
*/ | |||
@Autowired | |||
public void setDipperAstPosAsyncTaskService(IDipperAstPosAsyncTaskService dipperAstPosAsyncTaskService) { | |||
this.dipperAstPosAsyncTaskService = dipperAstPosAsyncTaskService; | |||
} | |||
private String centerProvince; | |||
private String centerProvinceFilePath; | |||
private String ipPositionRequestPath; | |||
@@ -84,6 +94,9 @@ public class DipperAstPosAsyncTaskServiceImpl implements IDipperAstPosAsyncTaskS | |||
} else { | |||
centerProvinceName = centerAddressSetArray[3]; | |||
centerProvinceLonAndAlt = centerAddressSetArray[1]+","+centerAddressSetArray[2]; | |||
if (redisUtil == null) { | |||
redisUtil = new RedisUtil(); | |||
} | |||
redisUtil.set(centerProvinceName, centerProvinceLonAndAlt, 0); | |||
} | |||
} | |||
@@ -104,7 +117,9 @@ public class DipperAstPosAsyncTaskServiceImpl implements IDipperAstPosAsyncTaskS | |||
JSONObject userObj = new JSONObject(); | |||
userObj.put("ip", ipAddress); | |||
userObj.put("key", ipPositionRequestKey); | |||
if (okHttpUtil == null) { | |||
okHttpUtil = new OkHttpUtil(); | |||
} | |||
JSONObject json = okHttpUtil.postRequestWithJson(ipPositionRequestPath, null, userObj); | |||
if (ObjectUtils.isNotEmpty(json)) { | |||
String province = (String) json.get("province"); | |||
@@ -174,6 +189,9 @@ public class DipperAstPosAsyncTaskServiceImpl implements IDipperAstPosAsyncTaskS | |||
} | |||
String lonAndAlt; | |||
if (redisUtil == null) { | |||
redisUtil = new RedisUtil(); | |||
} | |||
if (redisUtil.hasKey(centerAddress)) { | |||
// 获取省会城市定位信息 | |||
lonAndAlt= (String) redisUtil.get(centerAddress); | |||
@@ -2,8 +2,10 @@ package com.telpo.dipperposition.service.impl; | |||
import com.telpo.dipperposition.common.HexConvert; | |||
import com.telpo.dipperposition.common.SocketClient; | |||
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.beans.factory.annotation.Value; | |||
import org.springframework.scheduling.annotation.Async; | |||
import org.springframework.stereotype.Service; | |||
@@ -20,6 +22,17 @@ import java.time.LocalDateTime; | |||
@Slf4j | |||
public class DipperAstTimeAsyncTaskServiceImpl implements IDipperAstTimeAsyncTaskService { | |||
private static IDipperAstTimeAsyncTaskService dipperAstTimeAsyncTaskService; | |||
/** | |||
* spring会自动从ioc容器当中根据IDipperAstPosAsyncTaskService类型找到dipperAstTimeAsyncTaskService,当做参数传进来 | |||
* | |||
*/ | |||
@Autowired | |||
public void setDipperAstTimeAsyncTaskService(IDipperAstTimeAsyncTaskService dipperAstTimeAsyncTaskService) { | |||
this.dipperAstTimeAsyncTaskService = dipperAstTimeAsyncTaskService; | |||
} | |||
@Override | |||
@Async("asyncServiceExecutor") | |||
public String pushAstTime() { | |||
@@ -4,6 +4,7 @@ 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.IDipperAstPosAsyncTaskService; | |||
import com.telpo.dipperposition.service.IDipperDataAsyncTaskService; | |||
import lombok.extern.slf4j.Slf4j; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
@@ -29,6 +30,17 @@ public class DipperDataAsyncTaskServiceImpl implements IDipperDataAsyncTaskServi | |||
@Autowired | |||
private SchedulingExecutorConfig schedulingExecutorConfig; | |||
private static IDipperDataAsyncTaskService dipperDataAsyncTaskService; | |||
/** | |||
* spring会自动从ioc容器当中根据IDipperDataAsyncTaskService类型找到dipperDataAsyncTaskService,当做参数传进来 | |||
* | |||
*/ | |||
@Autowired | |||
public void setDipperDataAsyncTaskService(IDipperDataAsyncTaskService dipperDataAsyncTaskService) { | |||
this.dipperDataAsyncTaskService = dipperDataAsyncTaskService; | |||
} | |||
@Override | |||
public void pullAstEPH() { | |||
// (1) 发送bds获取星历数据 | |||
@@ -2,6 +2,7 @@ package com.telpo.dipperposition.service.impl; | |||
import com.telpo.dipperposition.entity.mongo.IPProvinceEntity; | |||
import com.telpo.dipperposition.mapper.IPProvinceMapper; | |||
import com.telpo.dipperposition.service.IDipperDataAsyncTaskService; | |||
import com.telpo.dipperposition.service.IPProvinceService; | |||
import com.telpo.dipperposition.vo.IPProvinceVo; | |||
import lombok.extern.slf4j.Slf4j; | |||
@@ -24,6 +25,15 @@ public class IPProvinceServiceImpl implements IPProvinceService { | |||
@Autowired | |||
private IPProvinceMapper iPProvinceMapper; | |||
private static IPProvinceService ipProvinceService; | |||
/** | |||
* spring会自动从ioc容器当中根据IPProvinceService类型找到ipProvinceService,当做参数传进来 | |||
* | |||
*/ | |||
@Autowired | |||
public void setIPProvinceService(IPProvinceService ipProvinceService) { | |||
this.ipProvinceService = ipProvinceService; | |||
} | |||
@Override | |||
public boolean saveIpProvince(IPProvinceEntity entity) { | |||
if (iPProvinceMapper == null) { | |||