Quellcode durchsuchen

mongodb访问方式变更

tags/v1.0.0^2
林万龙 vor 3 Jahren
Ursprung
Commit
0ceb9faa2a
2 geänderte Dateien mit 21 neuen und 10 gelöschten Zeilen
  1. +12
    -3
      src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java
  2. +9
    -7
      src/main/java/com/telpo/dipperposition/service/impl/ProvinceInfoServiceImpl.java

+ 12
- 3
src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java Datei anzeigen

@@ -137,11 +137,20 @@ public class DipperAstPosAsyncTaskServiceImpl implements IDipperAstPosAsyncTaskS
}

String lonAndAlt = null;
ProvinceInfoEntity entity = provinceInfoService.getProvinceInfo(centerAddress);
if (entity != null) {
lonAndAlt = entity.getProvince();
try {
byte[] utf8 = centerAddress.getBytes("UTF-8");
String utf8CenterAddress = new String(utf8, "UTF-8");
log.debug("centerAddress is " + utf8CenterAddress);

ProvinceInfoEntity entity = provinceInfoService.getProvinceInfo(utf8CenterAddress);
if (entity != null) {
lonAndAlt = entity.getProvince();
}
} catch (Exception e) {
log.error(e.getMessage());
}


// (2) 处理返回结果
if (lonAndAlt == null) {
// null处理


+ 9
- 7
src/main/java/com/telpo/dipperposition/service/impl/ProvinceInfoServiceImpl.java Datei anzeigen

@@ -2,6 +2,7 @@ package com.telpo.dipperposition.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollectionUtil;
import com.telpo.dipperposition.entity.mongo.IpProvinceEntity;
import com.telpo.dipperposition.entity.mongo.ProvinceInfoEntity;
import com.telpo.dipperposition.mapper.ProvinceInfoMapper;
import com.telpo.dipperposition.service.IProvinceInfoService;
@@ -57,13 +58,14 @@ public class ProvinceInfoServiceImpl implements IProvinceInfoService {
ProvinceInfoEntity query = new ProvinceInfoEntity();
query.setProvince(provicne);
Example<ProvinceInfoEntity> example = Example.of(query);
// PageRequest pageable = PageRequest.of(0, 1);
Optional<ProvinceInfoEntity> data = provinceInfoMapper.findOne(example);
// if (CollectionUtil.isNotEmpty(data.getContent())) {
//
// List<ProvinceInfoEntity> provinceInfos = BeanTools.copyList(data.getContent(), ProvinceInfoEntity.class);
// return provinceInfos.get(0);
return data.get();
PageRequest pageable = PageRequest.of(0, 1);
Page<ProvinceInfoEntity> data = provinceInfoMapper.findAll(example, pageable);
if (CollectionUtil.isNotEmpty(data.getContent())) {
List<ProvinceInfoEntity> records = BeanTools.copyList(data.getContent(), ProvinceInfoEntity.class);
return records.get(0);
} else {
return null;
}
} catch (Exception e) {
log.error("获取省份异常:", e);
return null;


Laden…
Abbrechen
Speichern