|
|
@@ -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); |
|
|
|