Przeglądaj źródła

修改到docker外运行环境

tags/v1.0.0^2
林万龙 3 lat temu
rodzic
commit
37ac3fad43
3 zmienionych plików z 10 dodań i 25 usunięć
  1. +1
    -1
      src/main/java/com/telpo/dipperposition/service/IpProvinceService.java
  2. +5
    -20
      src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java
  3. +4
    -4
      src/main/java/com/telpo/dipperposition/service/impl/IpProvinceServiceImpl.java

src/main/java/com/telpo/dipperposition/service/IPProvinceService.java → src/main/java/com/telpo/dipperposition/service/IpProvinceService.java Wyświetl plik

@@ -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省份

+ 5
- 20
src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java Wyświetl plik

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


+ 4
- 4
src/main/java/com/telpo/dipperposition/service/impl/IpProvinceServiceImpl.java Wyświetl plik

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


Ładowanie…
Anuluj
Zapisz