瀏覽代碼

mongodb访问方式变更

tags/v1.0.0^2
林万龙 3 年之前
父節點
當前提交
9f84ca14f2
共有 5 個文件被更改,包括 25 次插入112 次删除
  1. +3
    -3
      src/main/java/com/telpo/dipperposition/entity/mongo/IpProvinceEntity.java
  2. +3
    -2
      src/main/java/com/telpo/dipperposition/entity/mongo/ProvinceInfoEntity.java
  3. +2
    -53
      src/main/java/com/telpo/dipperposition/mapper/IpProvinceMapper.java
  4. +3
    -46
      src/main/java/com/telpo/dipperposition/mapper/ProvinceInfoMapper.java
  5. +14
    -8
      src/main/java/com/telpo/dipperposition/service/impl/ProvinceInfoServiceImpl.java

+ 3
- 3
src/main/java/com/telpo/dipperposition/entity/mongo/IpProvinceEntity.java 查看文件

@@ -1,10 +1,9 @@
package com.telpo.dipperposition.entity.mongo;

import com.telpo.dipperposition.vo.IPProvinceVo;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import models.BaseMongoDbEntity;
import org.springframework.data.mongodb.core.mapping.Document;

/**
* @program: IpProvinceEntity
@@ -15,7 +14,8 @@ import models.BaseMongoDbEntity;
@ToString
@Getter
@Setter
public class IpProvinceEntity extends BaseMongoDbEntity {
@Document
public class IpProvinceEntity {

/** Ip */
private String ip;


+ 3
- 2
src/main/java/com/telpo/dipperposition/entity/mongo/ProvinceInfoEntity.java 查看文件

@@ -3,7 +3,7 @@ package com.telpo.dipperposition.entity.mongo;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import models.BaseMongoDbEntity;
import org.springframework.data.mongodb.core.mapping.Document;

/**
* @program: IpProvinceEntity
@@ -14,7 +14,8 @@ import models.BaseMongoDbEntity;
@ToString
@Getter
@Setter
public class ProvinceInfoEntity extends BaseMongoDbEntity {
@Document
public class ProvinceInfoEntity {

/** 所在省份 */
private String province;


+ 2
- 53
src/main/java/com/telpo/dipperposition/mapper/IpProvinceMapper.java 查看文件

@@ -4,6 +4,7 @@ import com.telpo.dipperposition.annotation.MongoSwitch;
import com.telpo.dipperposition.entity.mongo.IpProvinceEntity;
import db.BaseMongoDbDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.stereotype.Repository;

import java.util.List;
@@ -15,56 +16,4 @@ import java.util.List;
* @create: 2020-07-20 11:12
*/
@Repository
public class IpProvinceMapper extends BaseMongoDbDao<IpProvinceEntity> {

// private static IpProvinceMapper ipProvinceMapper;
/**
* spring会自动从ioc容器当中根据IPProvinceMapper类型找到iPProvinceMapper,
* 当做参数传进来
*
*/
// @Autowired
// public void setIPProvinceMapper(IpProvinceMapper ipProvinceMapper) {
// this.ipProvinceMapper = ipProvinceMapper;
// }

@Override
protected Class<IpProvinceEntity> getEntityClass() {
return IpProvinceEntity.class;
}

@MongoSwitch("common")
public void saveIp(IpProvinceEntity entity) {
this.save(entity);
}

@MongoSwitch("common")
public void saveIp(IpProvinceEntity entity, String collectionName) {
this.save(entity, collectionName);
}

@MongoSwitch("common")
public void updateIpFirst(IpProvinceEntity srcObj, IpProvinceEntity targetObj) {
this.updateFirst(srcObj, targetObj);
}

@Override
public List<IpProvinceEntity> getPage(IpProvinceEntity object, int start, int size) {
return super.getPage(object, start, size);
}

@MongoSwitch("common")
public List<IpProvinceEntity> queryIpList(IpProvinceEntity object) {
return this.queryList(object);
}

@MongoSwitch("common")
public List<IpProvinceEntity> queryIpList(IpProvinceEntity object, String collectionName) {
return this.queryList(object, collectionName);
}

@MongoSwitch("common")
public void deleteIpById(String id) {
this.deleteById(id);
}
}
public interface IpProvinceMapper extends MongoRepository<IpProvinceEntity, String> {}

+ 3
- 46
src/main/java/com/telpo/dipperposition/mapper/ProvinceInfoMapper.java 查看文件

@@ -4,6 +4,7 @@ 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;
@@ -15,49 +16,5 @@ import java.util.List;
* @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);
}
}
public interface ProvinceInfoMapper
extends MongoRepository<ProvinceInfoEntity,String> {}

+ 14
- 8
src/main/java/com/telpo/dipperposition/service/impl/ProvinceInfoServiceImpl.java 查看文件

@@ -1,14 +1,18 @@
package com.telpo.dipperposition.service.impl;

import com.telpo.dipperposition.entity.mongo.IpProvinceEntity;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollectionUtil;
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.data.domain.Example;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;
import tools.BeanTools;

import java.util.List;

@@ -39,7 +43,7 @@ public class ProvinceInfoServiceImpl implements IProvinceInfoService {
@Override
public boolean romveById(String id) {

provinceInfoMapper.deleteIpById(id);
provinceInfoMapper.deleteById(id);
return false;
}

@@ -48,9 +52,12 @@ public class ProvinceInfoServiceImpl implements IProvinceInfoService {
try {
ProvinceInfoEntity query = new ProvinceInfoEntity();
query.setProvince(provicne);
List<ProvinceInfoEntity> records = provinceInfoMapper.queryIpList(query);
if (ObjectUtils.isNotEmpty(records)) {
return records.get(0);
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> provinceInfos = BeanTools.copyList(data.getContent(), ProvinceInfoEntity.class);
return provinceInfos.get(0);
} else {
return null;
}
@@ -63,8 +70,7 @@ public class ProvinceInfoServiceImpl implements IProvinceInfoService {
@Override
public List<ProvinceInfoEntity> getProvinceInfoEntitys() {
try {
ProvinceInfoEntity query = new ProvinceInfoEntity();
List<ProvinceInfoEntity> records = provinceInfoMapper.queryIpList(query);
List<ProvinceInfoEntity> records = provinceInfoMapper.findAll();
if (ObjectUtils.isNotEmpty(records)) {
return records;
} else {


Loading…
取消
儲存