From 196e1aa05afdbfa78abc92e2adf24934a361e5c0 Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Mon, 18 Jan 2021 21:21:21 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=88=B0docker=E5=A4=96?= =?UTF-8?q?=E8=BF=90=E8=A1=8C=E7=8E=AF=E5=A2=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dipperposition/common/OkHttpUtil.java | 16 ++++++++++++--- .../dipperposition/common/RedisUtil.java | 10 ++++++++++ .../config/NettyServerConfig.java | 12 +++++++++++ .../dipperposition/config/PositionConfig.java | 12 +++++++++++ .../mapper/IPProvinceMapper.java | 13 ++++++++++++ .../DipperAstPosAsyncTaskServiceImpl.java | 20 ++++++++++++++++++- .../DipperAstTimeAsyncTaskServiceImpl.java | 13 ++++++++++++ .../impl/DipperDataAsyncTaskServiceImpl.java | 12 +++++++++++ .../service/impl/IPProvinceServiceImpl.java | 10 ++++++++++ 9 files changed, 114 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/telpo/dipperposition/common/OkHttpUtil.java b/src/main/java/com/telpo/dipperposition/common/OkHttpUtil.java index 44b01cc..9063e5c 100644 --- a/src/main/java/com/telpo/dipperposition/common/OkHttpUtil.java +++ b/src/main/java/com/telpo/dipperposition/common/OkHttpUtil.java @@ -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 queries) { StringBuffer sb = new StringBuffer(url); if (queries != null && queries.keySet().size() > 0) { diff --git a/src/main/java/com/telpo/dipperposition/common/RedisUtil.java b/src/main/java/com/telpo/dipperposition/common/RedisUtil.java index 97933f0..8ef86a5 100644 --- a/src/main/java/com/telpo/dipperposition/common/RedisUtil.java +++ b/src/main/java/com/telpo/dipperposition/common/RedisUtil.java @@ -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 redisTemplate; + private static RedisUtil redisUtil; + /** + * spring会自动从ioc容器当中根据RedisUtil类型找到redisUtil,当做参数传进来 + * + */ + @Autowired + public void setRedisUtil(RedisUtil redisUtil) { + this.redisUtil = redisUtil; + } // =============================common============================ /** * 指定缓存失效时间 diff --git a/src/main/java/com/telpo/dipperposition/config/NettyServerConfig.java b/src/main/java/com/telpo/dipperposition/config/NettyServerConfig.java index 58e328e..54fcfbb 100644 --- a/src/main/java/com/telpo/dipperposition/config/NettyServerConfig.java +++ b/src/main/java/com/telpo/dipperposition/config/NettyServerConfig.java @@ -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; + } } diff --git a/src/main/java/com/telpo/dipperposition/config/PositionConfig.java b/src/main/java/com/telpo/dipperposition/config/PositionConfig.java index a55f01b..97d2d3a 100644 --- a/src/main/java/com/telpo/dipperposition/config/PositionConfig.java +++ b/src/main/java/com/telpo/dipperposition/config/PositionConfig.java @@ -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; + } } diff --git a/src/main/java/com/telpo/dipperposition/mapper/IPProvinceMapper.java b/src/main/java/com/telpo/dipperposition/mapper/IPProvinceMapper.java index a61925c..4d5055d 100644 --- a/src/main/java/com/telpo/dipperposition/mapper/IPProvinceMapper.java +++ b/src/main/java/com/telpo/dipperposition/mapper/IPProvinceMapper.java @@ -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 { + private static IPProvinceMapper iPProvinceMapper; + /** + * spring会自动从ioc容器当中根据IPProvinceMapper类型找到iPProvinceMapper, + * 当做参数传进来 + * + */ + @Autowired + public void setIPProvinceMapper(IPProvinceMapper iPProvinceMapper) { + this.iPProvinceMapper = iPProvinceMapper; + } + @Override protected Class getEntityClass() { return IPProvinceEntity.class; diff --git a/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java b/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java index 5f18ff5..86c5a7d 100644 --- a/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java +++ b/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java @@ -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); diff --git a/src/main/java/com/telpo/dipperposition/service/impl/DipperAstTimeAsyncTaskServiceImpl.java b/src/main/java/com/telpo/dipperposition/service/impl/DipperAstTimeAsyncTaskServiceImpl.java index 8ecb290..6bb8f66 100644 --- a/src/main/java/com/telpo/dipperposition/service/impl/DipperAstTimeAsyncTaskServiceImpl.java +++ b/src/main/java/com/telpo/dipperposition/service/impl/DipperAstTimeAsyncTaskServiceImpl.java @@ -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() { diff --git a/src/main/java/com/telpo/dipperposition/service/impl/DipperDataAsyncTaskServiceImpl.java b/src/main/java/com/telpo/dipperposition/service/impl/DipperDataAsyncTaskServiceImpl.java index 9515fd2..3f31de5 100644 --- a/src/main/java/com/telpo/dipperposition/service/impl/DipperDataAsyncTaskServiceImpl.java +++ b/src/main/java/com/telpo/dipperposition/service/impl/DipperDataAsyncTaskServiceImpl.java @@ -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获取星历数据 diff --git a/src/main/java/com/telpo/dipperposition/service/impl/IPProvinceServiceImpl.java b/src/main/java/com/telpo/dipperposition/service/impl/IPProvinceServiceImpl.java index de38265..e7493c1 100644 --- a/src/main/java/com/telpo/dipperposition/service/impl/IPProvinceServiceImpl.java +++ b/src/main/java/com/telpo/dipperposition/service/impl/IPProvinceServiceImpl.java @@ -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) {