@@ -0,0 +1,27 @@ | |||
package com.telpo.dipperposition.entity.mongo; | |||
import lombok.Getter; | |||
import lombok.Setter; | |||
import lombok.ToString; | |||
import models.BaseMongoDbEntity; | |||
/** | |||
* @program: IpProvinceEntity | |||
* @description: 省份位置实体类 | |||
* @author: linwl | |||
* @create: 2020-07-11 15:33 | |||
*/ | |||
@ToString | |||
@Getter | |||
@Setter | |||
public class ProvinceInfoEntity extends BaseMongoDbEntity { | |||
/** 所在省份 */ | |||
private String province; | |||
/** lon */ | |||
private String lon; | |||
/** lon */ | |||
private String alt; | |||
/** centerAddress */ | |||
private String centerAddress; | |||
} |
@@ -0,0 +1,63 @@ | |||
package com.telpo.dipperposition.mapper; | |||
import com.telpo.dipperposition.annotation.MongoSwitch; | |||
import com.telpo.dipperposition.entity.mongo.IpProvinceEntity; | |||
import com.telpo.dipperposition.entity.mongo.ProvinceInfoEntity; | |||
import db.BaseMongoDbDao; | |||
import org.springframework.stereotype.Repository; | |||
import java.util.List; | |||
/** | |||
* @program: ProvinceInfoMapper | |||
* @description: 省份位置记录mapper | |||
* @author: linwl | |||
* @create: 2020-07-20 11:12 | |||
*/ | |||
@Repository | |||
public class ProvinceInfoMapper extends BaseMongoDbDao<ProvinceInfoEntity> { | |||
@Override | |||
protected Class<ProvinceInfoEntity> getEntityClass() { | |||
return ProvinceInfoEntity.class; | |||
} | |||
@MongoSwitch("common") | |||
public void saveIp(ProvinceInfoEntity entity) { | |||
this.save(entity); | |||
} | |||
@MongoSwitch("common") | |||
public void saveIp(ProvinceInfoEntity entity, String collectionName) { | |||
this.save(entity, collectionName); | |||
} | |||
@MongoSwitch("common") | |||
public void updateIpFirst(ProvinceInfoEntity srcObj, ProvinceInfoEntity targetObj) { | |||
this.updateFirst(srcObj, targetObj); | |||
} | |||
@Override | |||
public List<ProvinceInfoEntity> getPage(ProvinceInfoEntity object, int start, int size) { | |||
return super.getPage(object, start, size); | |||
} | |||
@MongoSwitch("common") | |||
public List<ProvinceInfoEntity> queryIpList(ProvinceInfoEntity object) { | |||
return this.queryList(object); | |||
} | |||
@MongoSwitch("common") | |||
public List<ProvinceInfoEntity> queryIpList(ProvinceInfoEntity object, String collectionName) { | |||
return this.queryList(object, collectionName); | |||
} | |||
@MongoSwitch("common") | |||
public void deleteIpById(String id) { | |||
this.deleteById(id); | |||
} | |||
} |
@@ -0,0 +1,56 @@ | |||
package com.telpo.dipperposition.service; | |||
import com.telpo.dipperposition.entity.mongo.IpProvinceEntity; | |||
import com.telpo.dipperposition.entity.mongo.ProvinceInfoEntity; | |||
import java.util.List; | |||
/** | |||
* @program: IProvinceInfoService | |||
* @description: 省份经纬度信息 | |||
* @author: king | |||
* @create: 2020-07-20 11:09 | |||
*/ | |||
public interface IProvinceInfoService { | |||
// @Autowired | |||
// void setIPProvinceService(IpProvinceService ipProvinceService); | |||
/** | |||
* 保存省份经纬度信息 | |||
* | |||
* @param entity | |||
* @return | |||
*/ | |||
boolean saveProvinceInfo(ProvinceInfoEntity entity); | |||
/** | |||
* 更新省份经纬度信息 | |||
* | |||
* @param query | |||
* @param update | |||
* @return | |||
*/ | |||
boolean updateProvinceInfoEntity( | |||
ProvinceInfoEntity query, ProvinceInfoEntity update); | |||
/** | |||
* 根据ID移除IP省份记录 | |||
* | |||
* @param id | |||
* @return | |||
*/ | |||
boolean romveById(String id); | |||
/* | |||
* @param ipAddress | |||
* 获取省份经纬度信息 | |||
*/ | |||
ProvinceInfoEntity getProvinceInfo(String ipAddress); | |||
/** | |||
* 获取省份经纬度信息 | |||
* | |||
* @return | |||
*/ | |||
List<ProvinceInfoEntity> getProvinceInfoEntitys(); | |||
} |
@@ -5,7 +5,9 @@ import com.telpo.dipperposition.common.*; | |||
import com.telpo.dipperposition.config.NettyServerConfig; | |||
import com.telpo.dipperposition.config.PositionConfig; | |||
import com.telpo.dipperposition.entity.mongo.IpProvinceEntity; | |||
import com.telpo.dipperposition.entity.mongo.ProvinceInfoEntity; | |||
import com.telpo.dipperposition.service.IDipperAstPosAsyncTaskService; | |||
import com.telpo.dipperposition.service.IProvinceInfoService; | |||
import com.telpo.dipperposition.service.IpProvinceService; | |||
import lombok.extern.slf4j.Slf4j; | |||
import org.apache.commons.lang3.ObjectUtils; | |||
@@ -34,47 +36,19 @@ import java.util.List; | |||
@Slf4j | |||
public class DipperAstPosAsyncTaskServiceImpl implements IDipperAstPosAsyncTaskService { | |||
@Autowired | |||
private RedisUtil redisUtil; | |||
@Autowired | |||
private OkHttpUtil okHttpUtil; | |||
@Autowired | |||
private PositionConfig positionConfig; | |||
@Autowired | |||
private IpProvinceService ipProvinceService; | |||
@Autowired | |||
private IProvinceInfoService provinceInfoService; | |||
private String centerProvince; | |||
private String centerProvinceFilePath; | |||
private String ipPositionRequestPath; | |||
private String ipPositionRequestKey; | |||
// 从CSV文件读取省会城市中心点位置信息 | |||
private void getPosFromFile(String centerAddress) { | |||
// 不存在说明token是已过期了 | |||
String centerProvinceName = ""; | |||
String centerProvinceLonAndAlt = ""; | |||
String appCsvPath = ""; | |||
try { | |||
//appCsvPath ="/home/data/dipperposition" +this.centerProvinceFilePath; | |||
File f = new File(this.getClass().getResource("/").getPath()); | |||
appCsvPath = f.getPath()+this.centerProvinceFilePath; | |||
log.debug(appCsvPath); | |||
} catch (Exception e) { | |||
log.debug("cannot find path"); | |||
} | |||
List<String> centerAddressSets = CSVUtil.readCSV(appCsvPath); | |||
for (String centerAddressSet:centerAddressSets) { | |||
String[] centerAddressSetArray = centerAddressSet.split(","); | |||
if (centerAddressSetArray.length < 3) { | |||
log.warn("CSV数据格式错误"); | |||
} else { | |||
centerProvinceName = centerAddressSetArray[3]; | |||
centerProvinceLonAndAlt = centerAddressSetArray[1]+","+centerAddressSetArray[2]; | |||
redisUtil.set(centerProvinceName, centerProvinceLonAndAlt, 0); | |||
} | |||
} | |||
} | |||
// 根据IP获取省会信息 | |||
private String getIpPositionProvince(String ipAddress) { | |||
@@ -131,7 +105,7 @@ public class DipperAstPosAsyncTaskServiceImpl implements IDipperAstPosAsyncTaskS | |||
this.ipPositionRequestKey = positionConfig.getIpPositionRequestKey(); | |||
this.ipPositionRequestPath = positionConfig.getIpPositionRequestPath(); | |||
this.centerProvince = positionConfig.getCenterProvince(); | |||
this.centerProvinceFilePath = positionConfig.getCenterProvinceFilePath(); | |||
//this.centerProvinceFilePath = positionConfig.getCenterProvinceFilePath(); | |||
// (1) 获取省会城市信息 | |||
String centerAddress = getIpPositionProvince(ipAddress); | |||
if (ObjectUtils.isEmpty(centerAddress) || centerAddress.equals("0")) { | |||
@@ -143,14 +117,10 @@ public class DipperAstPosAsyncTaskServiceImpl implements IDipperAstPosAsyncTaskS | |||
createIPProvince(ipAddress, centerAddress); | |||
} | |||
String lonAndAlt; | |||
if (redisUtil.hasKey(centerAddress)) { | |||
// 获取省会城市定位信息 | |||
lonAndAlt= (String) redisUtil.get(centerAddress); | |||
} else { | |||
// 请求高德IP定位服务 | |||
this.getPosFromFile(centerAddress); | |||
lonAndAlt = (String) redisUtil.get(centerAddress); | |||
String lonAndAlt = null; | |||
ProvinceInfoEntity entity = provinceInfoService.getProvinceInfo(centerAddress); | |||
if (entity != null) { | |||
lonAndAlt = entity.getProvince(); | |||
} | |||
// (2) 处理返回结果 | |||
@@ -158,12 +128,10 @@ public class DipperAstPosAsyncTaskServiceImpl implements IDipperAstPosAsyncTaskS | |||
// null处理 | |||
log.error("系统错误,请联系系统管理员。"); | |||
return null; | |||
//return; | |||
} | |||
// push to GNNS Server | |||
String pushResult = getCmdOfPos(lonAndAlt); | |||
return pushResult; | |||
return getCmdOfPos(lonAndAlt); | |||
} | |||
// 组装命令发送给设备 | |||
@@ -209,12 +177,7 @@ public class DipperAstPosAsyncTaskServiceImpl implements IDipperAstPosAsyncTaskS | |||
astTimeCmd += HexConvert.encodeHEX(lanLongValue); | |||
astTimeCmd += HexConvert.encodeHEX(altLongValue); | |||
//String hexIn = HexConvert.convertStringToHex(astTimeCmd) + HexConvert.makeChecksum(astTimeCmd); | |||
String hexIn = astTimeCmd + HexConvert.makeChecksum(astTimeCmd); | |||
return astTimeCmd + HexConvert.makeChecksum(astTimeCmd); | |||
//return sendResult; | |||
return hexIn; | |||
} | |||
} |
@@ -0,0 +1,78 @@ | |||
package com.telpo.dipperposition.service.impl; | |||
import com.telpo.dipperposition.entity.mongo.IpProvinceEntity; | |||
import com.telpo.dipperposition.entity.mongo.ProvinceInfoEntity; | |||
import com.telpo.dipperposition.mapper.IpProvinceMapper; | |||
import com.telpo.dipperposition.mapper.ProvinceInfoMapper; | |||
import com.telpo.dipperposition.service.IProvinceInfoService; | |||
import lombok.extern.slf4j.Slf4j; | |||
import org.apache.commons.lang3.ObjectUtils; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.stereotype.Service; | |||
import java.util.List; | |||
/** | |||
* @program: DataPushServer | |||
* @description: 推送记录服务接口实现类 | |||
* @author: linwl | |||
* @create: 2020-07-20 11:09 | |||
*/ | |||
@Slf4j | |||
@Service | |||
public class ProvinceInfoServiceImpl implements IProvinceInfoService { | |||
@Autowired | |||
private ProvinceInfoMapper provinceInfoMapper; | |||
@Override | |||
public boolean saveProvinceInfo(ProvinceInfoEntity entity) { | |||
return false; | |||
} | |||
@Override | |||
public boolean updateProvinceInfoEntity(ProvinceInfoEntity query, ProvinceInfoEntity update) { | |||
return false; | |||
} | |||
@Override | |||
public boolean romveById(String id) { | |||
provinceInfoMapper.deleteIpById(id); | |||
return false; | |||
} | |||
@Override | |||
public ProvinceInfoEntity getProvinceInfo(String centerAddress) { | |||
try { | |||
ProvinceInfoEntity query = new ProvinceInfoEntity(); | |||
query.setCenterAddress(centerAddress); | |||
List<ProvinceInfoEntity> records = provinceInfoMapper.queryIpList(query); | |||
if (ObjectUtils.isNotEmpty(records)) { | |||
return records.get(0); | |||
} else { | |||
return null; | |||
} | |||
} catch (Exception e) { | |||
log.error("获取省份异常:", e); | |||
return null; | |||
} | |||
} | |||
@Override | |||
public List<ProvinceInfoEntity> getProvinceInfoEntitys() { | |||
try { | |||
ProvinceInfoEntity query = new ProvinceInfoEntity(); | |||
List<ProvinceInfoEntity> records = provinceInfoMapper.queryIpList(query); | |||
if (ObjectUtils.isNotEmpty(records)) { | |||
return records; | |||
} else { | |||
return null; | |||
} | |||
} catch (Exception e) { | |||
log.error("获取IP省份异常:", e); | |||
return null; | |||
} | |||
} | |||
} |
@@ -1,35 +0,0 @@ | |||
城市,经度,纬度,省份 | |||
沈阳市,123.429092,41.796768,辽宁省 | |||
长春市,125.324501,43.886841,吉林省 | |||
哈尔滨市,126.642464,45.756966,黑龙江省 | |||
北京市,116.405289,39.904987,北京市 | |||
天津市,117.190186,39.125595,天津市 | |||
呼和浩特市,111.75199,40.84149,内蒙古自治区 | |||
银川市,106.23248,38.48644,宁夏回族自治区 | |||
太原市,112.549248,37.857014,山西省 | |||
石家庄市,114.502464,38.045475,河北省 | |||
济南市,117.000923,36.675808,山东省 | |||
郑州市,113.665413,34.757977,河南省 | |||
西安市,108.948021,34.263161,陕西省 | |||
武汉市,114.298569,30.584354,湖北省 | |||
南京市,118.76741,32.041546,江苏省 | |||
合肥市,117.283043,31.861191,安徽省 | |||
上海市,121.472641,31.231707,上海市 | |||
长沙市,112.982277,28.19409,湖南省 | |||
南昌市,115.892151,28.676493,江西省 | |||
杭州市,120.15358,30.287458,浙江省 | |||
福州市,119.306236,26.075302,福建省 | |||
广州市,113.28064,23.125177,广东省 | |||
台北市,121.520076,25.030724,台湾省 | |||
海口市,110.19989,20.04422,海南省 | |||
南宁市,108.320007,22.82402,广西壮族自治区 | |||
重庆市,106.504959,29.533155,重庆市 | |||
昆明市,102.71225,25.040609,云南省 | |||
贵阳市,106.713478,26.578342,贵州省 | |||
成都市,104.065735,30.659462,四川省 | |||
兰州市,103.83417,36.06138,甘肃省 | |||
西宁市,101.77782,36.61729,青海省 | |||
拉萨市,91.1145,29.64415,西藏自治区 | |||
乌鲁木齐市,87.61688,43.82663,新疆维吾尔自治区 | |||
香港,114.16546,22.27534,香港特别行政区 | |||
澳门,113.54913,22.19875,澳门特别行政区 |
@@ -0,0 +1,24 @@ | |||
package com.telpo.dipperposition.vo; | |||
import lombok.Getter; | |||
import lombok.Setter; | |||
/** | |||
* @program: DataPushServer | |||
* @description: 基础类 | |||
* @author: linwl | |||
* @create: 2020-07-17 16:41 | |||
*/ | |||
@Setter | |||
@Getter | |||
public class ProvinceInfoVo { | |||
/** Ip所在省份 */ | |||
private String province; | |||
/** lon */ | |||
private String lon; | |||
/** lon */ | |||
private String alt; | |||
/** centerAddress */ | |||
private String centerAddress; | |||
} |