From 37ac3fad432ede3b8443a9cc3fd8750683a5f4fe Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Mon, 18 Jan 2021 21:34: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 --- ...nceService.java => IpProvinceService.java} | 2 +- .../DipperAstPosAsyncTaskServiceImpl.java | 25 ++++--------------- .../service/impl/IpProvinceServiceImpl.java | 8 +++--- 3 files changed, 10 insertions(+), 25 deletions(-) rename src/main/java/com/telpo/dipperposition/service/{IPProvinceService.java => IpProvinceService.java} (95%) diff --git a/src/main/java/com/telpo/dipperposition/service/IPProvinceService.java b/src/main/java/com/telpo/dipperposition/service/IpProvinceService.java similarity index 95% rename from src/main/java/com/telpo/dipperposition/service/IPProvinceService.java rename to src/main/java/com/telpo/dipperposition/service/IpProvinceService.java index de80294..63f1ab9 100644 --- a/src/main/java/com/telpo/dipperposition/service/IPProvinceService.java +++ b/src/main/java/com/telpo/dipperposition/service/IpProvinceService.java @@ -9,7 +9,7 @@ import com.telpo.dipperposition.vo.IPProvinceVo; * @author: king * @create: 2020-07-20 11:09 */ -public interface IPProvinceService { +public interface IpProvinceService { /** * 保存IP省份 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 0ccac44..e649fc6 100644 --- a/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java +++ b/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java @@ -4,7 +4,7 @@ import com.alibaba.fastjson.JSONObject; import com.telpo.dipperposition.common.*; import com.telpo.dipperposition.entity.mongo.IPProvinceEntity; import com.telpo.dipperposition.service.IDipperAstPosAsyncTaskService; -import com.telpo.dipperposition.service.IPProvinceService; +import com.telpo.dipperposition.service.IpProvinceService; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.ObjectUtils; import org.springframework.beans.factory.annotation.Autowired; @@ -33,7 +33,7 @@ public class DipperAstPosAsyncTaskServiceImpl implements IDipperAstPosAsyncTaskS @Autowired private OkHttpUtil okHttpUtil; @Autowired - private IPProvinceService iPProvinceService; + private IpProvinceService ipProvinceService; private static IDipperAstPosAsyncTaskService dipperAstPosAsyncTaskService; /** @@ -87,9 +87,6 @@ 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); } } @@ -101,18 +98,12 @@ public class DipperAstPosAsyncTaskServiceImpl implements IDipperAstPosAsyncTaskS // 关于IP与省份的关系保存到缓存中 // 使用时,先在缓存中获取匹配信息 // 用mongodb实现 - if(iPProvinceService == null) { - iPProvinceService = new IpProvinceServiceImpl(); - } - IPProvinceEntity ipProvinceEntity = iPProvinceService.getIpProvince(ipAddress); + IPProvinceEntity ipProvinceEntity = ipProvinceService.getIpProvince(ipAddress); if (ipProvinceEntity == null) { // 匹配不到,再请求高德IP定位服务。 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"); @@ -136,15 +127,12 @@ public class DipperAstPosAsyncTaskServiceImpl implements IDipperAstPosAsyncTaskS public void createIPProvince(String ipAddress, String province) { log.debug("异步创建推送失败任务记录!"); try { - if(iPProvinceService == null) { - iPProvinceService = new IpProvinceServiceImpl(); - } - IPProvinceEntity ipProvinceEntity = iPProvinceService.getIpProvince(ipAddress); + IPProvinceEntity ipProvinceEntity = ipProvinceService.getIpProvince(ipAddress); if (ipProvinceEntity == null) { //DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); ipProvinceEntity.setIp(ipAddress); ipProvinceEntity.setProvince(province); - iPProvinceService.saveIpProvince(ipProvinceEntity); + ipProvinceService.saveIpProvince(ipProvinceEntity); // } else { // // ipProvinceEntity.setProvince(province); @@ -182,9 +170,6 @@ 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/IpProvinceServiceImpl.java b/src/main/java/com/telpo/dipperposition/service/impl/IpProvinceServiceImpl.java index 22bb8f8..9e52a9f 100644 --- a/src/main/java/com/telpo/dipperposition/service/impl/IpProvinceServiceImpl.java +++ b/src/main/java/com/telpo/dipperposition/service/impl/IpProvinceServiceImpl.java @@ -2,7 +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.IPProvinceService; +import com.telpo.dipperposition.service.IpProvinceService; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.ObjectUtils; import org.springframework.beans.factory.annotation.Autowired; @@ -18,18 +18,18 @@ import java.util.List; */ @Slf4j @Service -public class IpProvinceServiceImpl implements IPProvinceService { +public class IpProvinceServiceImpl implements IpProvinceService { @Autowired private IpProvinceMapper ipProvinceMapper; - private static IPProvinceService ipProvinceService; + private static IpProvinceService ipProvinceService; /** * spring会自动从ioc容器当中根据IPProvinceService类型找到ipProvinceService,当做参数传进来 * */ @Autowired - public void setIPProvinceService(IPProvinceService ipProvinceService) { + public void setIPProvinceService(IpProvinceService ipProvinceService) { this.ipProvinceService = ipProvinceService; } @Override