Quellcode durchsuchen

mongodb访问方式变更

tags/v1.0.0^2
林万龙 vor 3 Jahren
Ursprung
Commit
53b19e53c5
3 geänderte Dateien mit 14 neuen und 23 gelöschten Zeilen
  1. +0
    -5
      src/main/java/com/telpo/dipperposition/mapper/ProvinceInfoMapper.java
  2. +8
    -9
      src/main/java/com/telpo/dipperposition/service/impl/IpProvinceServiceImpl.java
  3. +6
    -9
      src/main/java/com/telpo/dipperposition/service/impl/ProvinceInfoServiceImpl.java

+ 0
- 5
src/main/java/com/telpo/dipperposition/mapper/ProvinceInfoMapper.java Datei anzeigen

@@ -1,14 +1,9 @@
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.data.mongodb.repository.MongoRepository;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
* @program: ProvinceInfoMapper
* @description: 省份位置记录mapper


+ 8
- 9
src/main/java/com/telpo/dipperposition/service/impl/IpProvinceServiceImpl.java Datei anzeigen

@@ -5,16 +5,19 @@ import com.telpo.dipperposition.entity.mongo.IpProvinceEntity;
import com.telpo.dipperposition.entity.mongo.ProvinceInfoEntity;
import com.telpo.dipperposition.mapper.IpProvinceMapper;
import com.telpo.dipperposition.service.IpProvinceService;
import jdk.nashorn.internal.runtime.options.Option;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.ExampleMatcher;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;
import tools.BeanTools;

import java.util.List;
import java.util.Optional;

/**
* @program: DataPushServer
@@ -56,15 +59,11 @@ public class IpProvinceServiceImpl implements IpProvinceService {
try {
IpProvinceEntity query = new IpProvinceEntity();
query.setIp(ipAddress);
Example<IpProvinceEntity> example = Example.of(query);
PageRequest pageable = PageRequest.of(0, 1);
Page<IpProvinceEntity> data = ipProvinceMapper.findAll(example, pageable);
if (CollectionUtil.isNotEmpty(data.getContent())) {
List<IpProvinceEntity> records = BeanTools.copyList(data.getContent(), IpProvinceEntity.class);
return records.get(0);
} else {
return null;
}
//忽略_class属性,不参与查询
ExampleMatcher matcher = ExampleMatcher.matching().withIgnorePaths("_class");
Example<IpProvinceEntity> example = Example.of(query, matcher);
Optional<IpProvinceEntity> data = ipProvinceMapper.findOne(example);
return data.get();
} catch (Exception e) {
log.error("获取IP省份异常:", e);
return null;


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

@@ -10,6 +10,7 @@ import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.ExampleMatcher;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;
@@ -57,15 +58,11 @@ public class ProvinceInfoServiceImpl implements IProvinceInfoService {
try {
ProvinceInfoEntity query = new ProvinceInfoEntity();
query.setProvince(provicne);
Example<ProvinceInfoEntity> example = Example.of(query);
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;
}
//忽略_class属性,不参与查询
ExampleMatcher matcher = ExampleMatcher.matching().withIgnorePaths("_class");
Example<ProvinceInfoEntity> example = Example.of(query, matcher);
Optional<ProvinceInfoEntity> data = provinceInfoMapper.findOne(example);
return data.get();
} catch (Exception e) {
log.error("获取省份异常:", e);
return null;


Laden…
Abbrechen
Speichern