소스 검색

mongodb访问方式变更

tags/v1.0.0^2
林万龙 3 년 전
부모
커밋
0ceb9faa2a
2개의 변경된 파일21개의 추가작업 그리고 10개의 파일을 삭제
  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 파일 보기

@@ -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 파일 보기

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


Loading…
취소
저장