From c6837861ccf4387e200d50769696fba0f4161716 Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Thu, 17 Jun 2021 15:19:41 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=95=B0=E6=8D=AE=E8=A7=A3?= =?UTF-8?q?=E6=9E=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dipper_position_run.sh | 2 +- .../DipperAstPosAsyncTaskServiceImpl.java | 30 +++++++++++++------ .../service/impl/ProvinceInfoServiceImpl.java | 7 ++++- 3 files changed, 28 insertions(+), 11 deletions(-) diff --git a/dipper_position_run.sh b/dipper_position_run.sh index fbea5dc..fb9d25a 100644 --- a/dipper_position_run.sh +++ b/dipper_position_run.sh @@ -18,7 +18,7 @@ if [[ ${environment} == 'pro' ]]; then mv /home/linwl/dipperposition/dipperposition.jar /home/data/dipperposition/dipperposition.jar fi - nohup java -Xmx2048M -Xms2048M -Djava.security.egd=file:/dev/./urandom -Dio.netty.leakDetectionLevel=ADVANCED -jar dipperposition.jar --spring.profiles.active=pro & + nohup java -Xmx1024M -Xms1024M -Djava.security.egd=file:/dev/./urandom -Dio.netty.leakDetectionLevel=ADVANCED -jar dipperposition.jar --spring.profiles.active=pro & fi if [[ ${environment} == 'test' ]]; then 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 800d6f7..ef21201 100644 --- a/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java +++ b/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java @@ -70,11 +70,17 @@ public class DipperAstPosAsyncTaskServiceImpl implements IDipperAstPosAsyncTaskS } //log.debug("IP省份获取错误,结果为:" + result); JSONObject provinceJson = JSONObject.parseObject(result); - String province = (String)provinceJson.get("province"); - if (ObjectUtils.isEmpty(province)) { - log.debug("json is :" + buffer.toString()); - return null; + String province = null; + try { + province = (String)provinceJson.get("province"); + if (ObjectUtils.isEmpty(province)) { + log.debug("json is :" + buffer.toString()); + return null; + } + } catch (Exception e) { + log.error("JSONObject分析出错,provinceJson:" + provinceJson); } + return province; } } else { @@ -116,7 +122,7 @@ public class DipperAstPosAsyncTaskServiceImpl implements IDipperAstPosAsyncTaskS //this.centerProvinceFilePath = positionConfig.getCenterProvinceFilePath(); // (1) 获取省会城市信息 String centerAddress = getIpPositionProvince(ipAddress); - if (ObjectUtils.isEmpty(centerAddress) || centerAddress.equals("0")) { + if (centerAddress == null || ObjectUtils.isEmpty(centerAddress) || centerAddress.equals("0")) { log.warn("IP地址非法,无法获取辅助位置信息!"); // 返回武汉的定位数据 centerAddress = this.centerProvince; @@ -132,10 +138,16 @@ public class DipperAstPosAsyncTaskServiceImpl implements IDipperAstPosAsyncTaskS String utf8CenterAddress = new String(utf8, "UTF-8"); log.debug("centerAddress is " + utf8CenterAddress); - ProvinceInfoEntity entity = provinceInfoService.getProvinceInfo(utf8CenterAddress); - if (entity != null) { - lonValue = entity.getLon(); - altValue = entity.getAlt(); + if (utf8CenterAddress.endsWith("省") || utf8CenterAddress.endsWith("区") || utf8CenterAddress.endsWith("市")) { + + ProvinceInfoEntity entity = provinceInfoService.getProvinceInfo(utf8CenterAddress); + if (entity != null) { + lonValue = entity.getLon(); + altValue = entity.getAlt(); + } + } else { + log.error("非法省份:" + utf8CenterAddress); + return null; } } catch (Exception e) { log.error(e.getMessage()); diff --git a/src/main/java/com/telpo/dipperposition/service/impl/ProvinceInfoServiceImpl.java b/src/main/java/com/telpo/dipperposition/service/impl/ProvinceInfoServiceImpl.java index b9e7baf..46ae674 100644 --- a/src/main/java/com/telpo/dipperposition/service/impl/ProvinceInfoServiceImpl.java +++ b/src/main/java/com/telpo/dipperposition/service/impl/ProvinceInfoServiceImpl.java @@ -1,5 +1,6 @@ package com.telpo.dipperposition.service.impl; +import cn.hutool.core.util.ObjectUtil; import com.telpo.dipperposition.entity.mongo.ProvinceInfoEntity; import com.telpo.dipperposition.mapper.ProvinceInfoMapper; import com.telpo.dipperposition.service.IProvinceInfoService; @@ -56,7 +57,11 @@ public class ProvinceInfoServiceImpl implements IProvinceInfoService { ExampleMatcher matcher = ExampleMatcher.matching().withIgnorePaths("_class"); Example example = Example.of(query, matcher); Optional data = provinceInfoMapper.findOne(example); - return data.get(); + if (ObjectUtil.isNotEmpty(data)) { + return data.get(); + } else { + return null; + } } catch (Exception e) { log.error("获取省份异常:", e); return null;