移除mongo依赖

yun-zuoyi
wynne1005 4 years ago
commit d627d024a7

@ -1,30 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>i3plus-pojo</artifactId>
<groupId>i3plus.pojo</groupId>
<version>1.0-TEST-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>i3plus-pojo-base-mongo</artifactId>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>
<dependency>
<groupId>i3plus.pojo</groupId>
<artifactId>i3plus-pojo-base</artifactId>
</dependency>
<dependency>
<groupId>i3plus.pojo</groupId>
<artifactId>i3plus-pojo-platform</artifactId>
</dependency>
</dependencies>
</project>

@ -1,52 +0,0 @@
package cn.estsh.i3plus.pojo.base.jpa.dao;
import cn.estsh.i3plus.pojo.base.common.Pager;
import org.bson.conversions.Bson;
import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.data.repository.NoRepositoryBean;
import java.io.Serializable;
import java.util.List;
/**
* @Description : Repository
* @Reference : MongoRepository
* @Author : alwaysfrin
* @CreateDate : 2018-09-13 10:34
* @Modify:
**/
@NoRepositoryBean
public interface BaseMongoRepository<T, ID extends Serializable> extends MongoRepository<T, ID> {
T getById(long id);
List<T> findByProperty(String propertyName, Object value);
List<T> findByProperty(String propertyName, Object value,String orderByParam, int ascOrDesc);
List<T> findByPropertyLike(String propertyName, Object value);
List<T> findByPropertyLike(String propertyName, Object value,String orderByParam, int ascOrDesc);
T getByProperty(String propertyName, Object value);
List<T> findByBson(Bson bson);
List<T> findByBson(Bson bson,String orderByParam, int ascOrDesc);
int findByBsonCount(Bson bson);
List<T> findByBsonPager(Bson bson,Pager pager);
List<T> findByBsonPager(Bson bson,Pager pager,String orderByParam, int ascOrDesc);
int listCount();
List<T> listPager(Pager pager);
List<T> listPager(Pager pager,String orderByParam, int ascOrDesc);
long deleteByProperty(Bson bson);
long deleteByPropertyIn(String propName, Object[] propValues);
long deleteByIds(ID[] ids);
}

@ -1,352 +0,0 @@
package cn.estsh.i3plus.pojo.base.jpa.daoimpl;
import cn.estsh.i3plus.pojo.base.common.Pager;
import cn.estsh.i3plus.pojo.base.enumutil.CommonEnumUtil;
import cn.estsh.i3plus.pojo.base.jpa.dao.BaseMongoRepository;
import cn.estsh.i3plus.pojo.base.codemaker.SnowflakeIdMaker;
import com.alibaba.fastjson.JSONObject;
import com.mongodb.BasicDBObject;
import com.mongodb.Block;
import com.mongodb.client.FindIterable;
import com.mongodb.client.model.CountOptions;
import com.mongodb.client.model.Filters;
import com.mongodb.client.model.Sorts;
import org.apache.commons.lang3.StringUtils;
import org.bson.Document;
import org.bson.conversions.Bson;
import org.bson.json.JsonMode;
import org.bson.json.JsonWriterSettings;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.dao.DuplicateKeyException;
import org.springframework.data.mapping.context.MappingContext;
import org.springframework.data.mongodb.core.MongoOperations;
import org.springframework.data.mongodb.core.mapping.MongoPersistentEntity;
import org.springframework.data.mongodb.core.mapping.MongoPersistentProperty;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.mongodb.repository.query.MongoEntityInformation;
import org.springframework.data.mongodb.repository.support.SimpleMongoRepository;
import javax.persistence.Id;
import java.io.Serializable;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
/**
* @Description : mongodb
* @Reference :
* @Author : alwaysfrin
* @CreateDate : 2018-09-13 11:24
* @Modify:
**/
public class BaseMongoRepositoryImpl<T, ID extends Serializable> extends SimpleMongoRepository<T, ID>
implements BaseMongoRepository<T, ID> {
public static final Logger LOGGER = LoggerFactory.getLogger(BaseMongoRepositoryImpl.class);
/**
*
*/
private final MongoOperations mongoOperations;
private final MongoEntityInformation<T, ID> entityInformation;
private final MappingContext<? extends MongoPersistentEntity<?>, MongoPersistentProperty> mongoContext;
private final Class<T> entityClass;
private SnowflakeIdMaker snowflakeIdMaker;
public BaseMongoRepositoryImpl(MongoEntityInformation<T, ID> metadata, MongoOperations mongoOperations,SnowflakeIdMaker snowflakeIdMaker) {
super(metadata, mongoOperations);
this.entityInformation = metadata;
this.mongoOperations = mongoOperations;
this.entityClass = this.entityInformation.getJavaType();
mongoContext = mongoOperations.getConverter().getMappingContext();
this.snowflakeIdMaker = snowflakeIdMaker;
}
/**
*
* @param entity
* @param <S>
* @return
*/
@Override
public <S extends T> S insert(S entity) {
innerSave(entity);
return entity;
}
/**
*
* @param item
* @return
*/
private T innerSave(T item) {
try {
if(item==null)return null;
Class<?> clazz = item.getClass();
//获取主键
Field idField = clazz.getField("id");
if(idField == null){
idField = clazz.getField("primaryKey");
}
if(idField == null){
// 遍历所有属性,以@Id声明确认主键
Field[] fields = clazz.getFields();
for(Field f : fields){
if(f.getAnnotation(Id.class) != null){
idField = f;
break;
}
}
}
if(idField != null){
Class<?> type = idField.getType();
Object val = idField.get(item);
if((type == long.class || type == Long.class) && (val == null || Long.parseLong(val.toString()) == 0)){
// long类型主键以snowflake为主键
idField.set(item, snowflakeIdMaker.nextId() + System.currentTimeMillis());
} else if(type == String.class && (val==null || "".equals(val))){
// String类型主键以UUID为主键
idField.set(item, UUID.randomUUID().toString().replace("-", "").toLowerCase());
}
}
// try {
this.mongoOperations.insert(item, this.entityInformation.getCollectionName());
// }catch (DuplicateKeyException dke){
// LOGGER.error("【出现重复主键】");
// //出现重复主键,再次插入
// if(idField != null){
// Class<?> type = idField.getType();
// Object val = idField.get(item);
// if((type == long.class || type == Long.class) && (val == null || Long.parseLong(val.toString()) == 0)){
// // long类型主键以snowflake为主键
// idField.set(item, snowflakeIdMaker.nextId());
// } else if(type == String.class && (val==null || "".equals(val))){
// // String类型主键以UUID为主键
// idField.set(item, UUID.randomUUID().toString().replace("-", "").toLowerCase());
// }
// }
//
// this.mongoOperations.insert(item, this.entityInformation.getCollectionName());
// }
if(idField != null){
return item;
}else {
return null;
}
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException(e);
}
}
@Override
public Optional<T> findById(ID id) {
T entity = this.mongoOperations.findById(id, this.entityInformation.getJavaType(), this.entityInformation.getCollectionName());
if(entity != null) {
return Optional.of(entity);
}else{
return null;
}
}
@Override
public T getById(long id) {
return this.mongoOperations.findById(id, this.entityInformation.getJavaType(), this.entityInformation.getCollectionName());
}
@Override
public List<T> findByProperty(String propertyName, Object value) {
return findByProperty(propertyName,value,null,0);
}
@Override
public List<T> findByProperty(String propertyName, Object value, String orderByParam, int ascOrDesc) {
Bson bson = Filters.and(
Filters.eq(propertyName, value)
);
return findByBson(bson,orderByParam,ascOrDesc);
}
@Override
public List<T> findByPropertyLike(String propertyName, Object value) {
return findByPropertyLike(propertyName,value,null,0);
}
@Override
public List<T> findByPropertyLike(String propertyName, Object value, String orderByParam, int ascOrDesc) {
Bson bson = Filters.and(
Filters.regex(propertyName, value.toString())
);
return findByBson(bson,orderByParam,ascOrDesc);
}
@Override
public T getByProperty(String propertyName, Object value) {
List<T> tList = this.findByProperty(propertyName,value);
if(tList.size() > 0){
return tList.iterator().next();
}else{
return null;
}
}
/**
* bson
* @param bson
* @return
*/
public List<T> findByBson(Bson bson) {
return findByBson(bson,null,0);
}
@Override
public List<T> findByBson(Bson bson, String orderByParam, int ascOrDesc) {
List<Document> dList = new ArrayList<>();
Block<Document> saveBlock = new Block<Document>() {
@Override
public void apply(final Document document) {
dList.add(document);
}
};
FindIterable findIter = null;
if(bson != null) {
findIter = mongoOperations.getCollection(this.entityInformation.getCollectionName()).find(bson);
}else{
findIter = mongoOperations.getCollection(this.entityInformation.getCollectionName()).find();
}
if(StringUtils.isNotBlank(orderByParam) && ascOrDesc != 0){
//排序
if(ascOrDesc == CommonEnumUtil.ASC_OR_DESC.ASC.getValue()){
findIter.sort(Sorts.ascending(orderByParam));
}else{
findIter.sort(Sorts.descending(orderByParam));
}
}
findIter.forEach(saveBlock);
return packObjectListFromDocument(dList);
}
@Override
public int findByBsonCount(Bson bson) {
if(bson == null){
return (int) mongoOperations.getCollection(this.entityInformation.getCollectionName()).count();
}else {
return (int) mongoOperations.getCollection(this.entityInformation.getCollectionName()).count(bson);
}
}
private List<T> packObjectListFromDocument(List<Document> dList) {
//将获取的document转为对象
List<T> resultList = new ArrayList<>();
// 设置为宽松模式
JsonWriterSettings jsonWriterSettings = JsonWriterSettings.builder().outputMode(JsonMode.RELAXED).build();
for(Document d : dList){
resultList.add(JSONObject.parseObject(d.toJson(jsonWriterSettings), entityClass));
}
return resultList;
}
@Override
public List<T> findByBsonPager(Bson bson, Pager pager) {
return findByBsonPager(bson,pager,null,0);
}
@Override
public List<T> findByBsonPager(Bson bson, Pager pager, String orderByParam, int ascOrDesc) {
List<Document> dList = new ArrayList<>();
Block<Document> saveBlock = new Block<Document>() {
@Override
public void apply(final Document document) {
dList.add(document);
}
};
FindIterable findIter = null;
if(bson == null) {
findIter = mongoOperations.getCollection(this.entityInformation.getCollectionName()).find();
}else{
findIter = mongoOperations.getCollection(this.entityInformation.getCollectionName()).find(bson);
}
if(StringUtils.isNotBlank(orderByParam) && ascOrDesc != 0){
//排序
if(ascOrDesc == CommonEnumUtil.ASC_OR_DESC.ASC.getValue()){
findIter.sort(Sorts.ascending(orderByParam));
}else{
findIter.sort(Sorts.descending(orderByParam));
}
}else{
//根据id排序
findIter.sort(new BasicDBObject("_id", 1));
}
findIter.skip(pager.getStartRow()).limit(pager.getPageSize());
findIter.forEach(saveBlock);
return packObjectListFromDocument(dList);
}
@Override
public int listCount() {
return (int) mongoOperations.getCollection(this.entityInformation.getCollectionName()).count();
}
@Override
public List<T> listPager(Pager pager) {
return listPager(pager,null,0);
}
@Override
public List<T> listPager(Pager pager, String orderByParam, int ascOrDesc) {
List<Document> dList = new ArrayList<>();
Block<Document> saveBlock = new Block<Document>() {
@Override
public void apply(final Document document) {
dList.add(document);
}
};
FindIterable findIter = mongoOperations.getCollection(this.entityInformation.getCollectionName()).find();
if(StringUtils.isNotBlank(orderByParam) && ascOrDesc != 0){
//排序
if(ascOrDesc == CommonEnumUtil.ASC_OR_DESC.ASC.getValue()){
findIter.sort(Sorts.ascending(orderByParam));
}else{
findIter.sort(Sorts.descending(orderByParam));
}
}else{
//根据id排序
findIter.sort(new BasicDBObject("_id", 1));
}
findIter.skip(pager.getStartRow()).limit(pager.getPageSize());
findIter.forEach(saveBlock);
return packObjectListFromDocument(dList);
}
@Override
public long deleteByProperty(Bson bson) {
return mongoOperations.getCollection(this.entityInformation.getCollectionName()).deleteMany(bson).getDeletedCount();
}
@Override
public long deleteByPropertyIn(String propName, Object[] propValues) {
Bson bson = Filters.and(
Filters.in(propName, propValues)
);
return deleteByProperty(bson);
}
@Override
public long deleteByIds(ID[] ids) {
return deleteByPropertyIn("_id",ids);
}
}

@ -1,69 +0,0 @@
package cn.estsh.i3plus.pojo.base.jpa.factory;
import cn.estsh.i3plus.pojo.base.jpa.daoimpl.BaseMongoRepositoryImpl;
import cn.estsh.i3plus.pojo.base.codemaker.SnowflakeIdMaker;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoOperations;
import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.data.mongodb.repository.query.MongoEntityInformation;
import org.springframework.data.mongodb.repository.support.MongoRepositoryFactory;
import org.springframework.data.mongodb.repository.support.MongoRepositoryFactoryBean;
import org.springframework.data.repository.core.RepositoryInformation;
import org.springframework.data.repository.core.RepositoryMetadata;
import org.springframework.data.repository.core.support.RepositoryFactorySupport;
import java.io.Serializable;
/**
* @Description : mongodb
* @Reference :
* @Author : alwaysfrin
* @CreateDate : 2018-09-13 14:55
* @Modify:
**/
public class BaseMongoRepositoryFactoryBean<R extends MongoRepository<T, I>, T, I extends Serializable> extends MongoRepositoryFactoryBean<R, T, I> {
public static final Logger LOGGER = LoggerFactory.getLogger(BaseMongoRepositoryFactoryBean.class);
@Autowired
public SnowflakeIdMaker snowflakeIdMaker;
public BaseMongoRepositoryFactoryBean(Class<? extends R> repositoryInterface) {
super(repositoryInterface);
}
@Override
protected RepositoryFactorySupport getFactoryInstance(MongoOperations operations) {
//LOGGER.info("【初始mongo持久仓】");
//生成持久mongo仓库实例
return new BaseMongoRepositoryFactory(operations,snowflakeIdMaker);
}
//创建一个内部类,该类不用在外部访问
private static class BaseMongoRepositoryFactory<T, I extends Serializable> extends MongoRepositoryFactory {
private final MongoOperations mongoOperations;
//private final MappingContext<? extends MongoPersistentEntity<?>, MongoPersistentProperty> mappingContext;
private final SnowflakeIdMaker snowflakeIdMaker;
public BaseMongoRepositoryFactory(MongoOperations mongoOperations,SnowflakeIdMaker snowflakeIdMaker) {
super(mongoOperations);
this.mongoOperations = mongoOperations;
this.snowflakeIdMaker = snowflakeIdMaker;
//this.mappingContext = mongoOperations.getConverter().getMappingContext();
}
//设置具体的实现类是BaseRepositoryImpl
@Override
protected Object getTargetRepository(RepositoryInformation information) {
MongoEntityInformation<?, Serializable> entityInformation = getEntityInformation(information.getDomainType());
return new BaseMongoRepositoryImpl(entityInformation, mongoOperations,snowflakeIdMaker);
}
//设置具体的实现类的class
@Override
protected Class<?> getRepositoryBaseClass(RepositoryMetadata metadata) {
return BaseMongoRepositoryImpl.class;
}
}
}

@ -1,816 +0,0 @@
package cn.estsh.i3plus.pojo.base.tool;
import cn.estsh.i3plus.pojo.base.enumutil.CommonEnumUtil;
import com.alibaba.fastjson.JSONObject;
import com.mongodb.Block;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.model.Filters;
import com.mongodb.client.model.Sorts;
import org.apache.commons.lang3.StringUtils;
import org.bson.Document;
import org.bson.conversions.Bson;
import org.springframework.data.mongodb.core.MongoOperations;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Objects;
import java.util.regex.Pattern;
/**
* @Description :
* @Reference :
* @Author : alwaysfrin
* @CreateDate : 2018-11-01 16:26
* @Modify:
*
* (>) - $gt
* (<) - $lt
* (>=) - $gte
* (<= ) - $lte
* $ne ----------- not equal !=
* $eq -------- equal =
*
* title "库"
* db.col.find({title://})
*
* title "教"
* db.col.find({title:/^/})
*
* titl e"教"
* db.col.find({title:/$/})
**/
public class BsonPackTool {
/**
* sql
* @param data
* @return
*/
public static String getSafeParam(Object data){
return data.toString().replaceAll(";","")
.replaceAll("'","")
.replaceAll("\"","")
.replaceAll("/","")
.replaceAll("\\\\","")
.replaceAll("delete","")
.replaceAll("update","")
.replaceAll("insert","");
}
/**
* document
* @param mongoOperations
* @param tableName
* @param bson
* @param skip
* @param limit
* @return document
*/
public static List<Document> query(MongoOperations mongoOperations, String tableName, Bson bson, int skip, int limit) {
List<Document> newLins = new ArrayList<>();
Block<Document> saveBlock = new Block<Document>() {
@Override
public void apply(final Document document) {
newLins.add(document);
}
};
//查询
MongoCollection<Document> collection = mongoOperations.getCollection(tableName);
if(bson == null) {
collection.count();
collection.find().skip(skip).limit(limit).forEach(saveBlock);
}else {
collection.count(bson);
collection.find(bson).skip(skip).limit(limit).forEach(saveBlock);
}
return newLins;
}
/**
*
* @param mongoOperations
* @param tableName
* @param bson
* @param pageSize
* @return
*/
public static List<Document> queryPages(MongoOperations mongoOperations, String tableName, Bson bson, int pageSize) {
//分页查询
List<Document> list = new ArrayList<>();
long count = mongoOperations.getCollection(tableName).count(bson);
int loops = (int)((count + pageSize - 1) / pageSize);
List<Document> newFinds = null;
for(int i = 0; i < loops; i++) {
newFinds = query(mongoOperations, tableName, bson, i * pageSize, pageSize);
list.addAll(newFinds);
}
return list;
}
/**
*
* @param startDate
* @param endDate
* @param columnName HQL
* @param bson bson
* @param isShowTime
*/
public static Bson timeBuilder( String startDate,String endDate, String columnName, Bson bson, boolean isShowTime) {
if (startDate == null || startDate.trim().length() == 0) {
startDate = "1900-01-01";
} else {
startDate = getSafeParam(startDate);
startDate = startDate.trim();
}
if (isShowTime && startDate.trim().length()<=11) {
startDate+= " 00:00:00";
}
if (endDate == null || endDate.trim().length() == 0) {
endDate = "2100-01-01";
} else {
endDate = getSafeParam(endDate);
endDate = endDate.trim();
}
if (isShowTime&& endDate.trim().length()<=11) {
endDate+= " 23:59:59";
}
if(bson == null) {
bson = Filters.and(
Filters.gte(columnName, startDate), //大于等于开始日期
Filters.lte(columnName, endDate) //小于等于结束日期
);
}else{
bson = Filters.and(
bson,
Filters.gte(columnName, startDate), //大于等于开始日期
Filters.lte(columnName, endDate) //小于等于结束日期
);
}
return bson;
}
/**
*
* @param date
* @param columnName HQL
* @param bson bson
* @param showToday true:false:
* @param isShowTime
*/
public static Bson timeBuilder( String date, String columnName, Bson bson, boolean showToday,boolean isShowTime) {
if(date != null && !"null".equals(date) && date.trim().length() > 0){
date = getSafeParam(date);
String today = (new SimpleDateFormat("yyyy-MM-dd")).format(new Date());
if(date.length() == 1 || ",".equals(date)){
//只有一个逗号
date = "";
}
String[] time = date.split(",");
if(time.length == 1){
//只有开始日期,没有结束日期
if(bson == null){
bson = Filters.and(
Filters.regex(columnName, "^" + time[0]) //like 日期%^
);
}else {
bson = Filters.and(
bson,
Filters.regex(columnName, "^" + time[0]) //like 日期%^
);
}
}else if (time.length == 2 && ((time[0] != null && time[0].trim().length() > 0) || (time[1] != null & time[1].trim().length() > 0))) {
if (time[0] == null || time[0].trim().length() == 0) {
time[0] = "1900-01-01";
} else {
time[0] = time[0].trim();
}
if (isShowTime && time[0].trim().length()<=11) {
time[0]+= " 00:00:00";
}
if (time[1] == null || time[1].trim().length() == 0) {
time[1] = "2100-01-01";
} else {
time[1] = time[1].trim();
}
if (isShowTime&& time[1].trim().length()<=11) {
time[1]+= " 23:59:59";
}
if(bson == null) {
bson = Filters.and(
Filters.gte(columnName, time[0]), //大于等于开始日期
Filters.lte(columnName, time[1]) //小于等于结束日期
);
}else{
bson = Filters.and(
bson,
Filters.gte(columnName, time[0]), //大于等于开始日期
Filters.lte(columnName, time[1]) //小于等于结束日期
);
}
} else {
if (showToday) {
if (isShowTime) {
if(bson == null) {
bson = Filters.and(
Filters.gte(columnName, time[0] + " 00:00:00"), //大于等于开始日期
Filters.lte(columnName, time[1] + " 23:59:59") //小于等于结束日期
);
}else{
bson = Filters.and(
bson,
Filters.gte(columnName, time[0] + " 00:00:00"), //大于等于开始日期
Filters.lte(columnName, time[1] + " 23:59:59") //小于等于结束日期
);
}
}else{
if(bson == null) {
bson = Filters.and(
Filters.gte(columnName, time[0]), //大于等于开始日期
Filters.lte(columnName, time[1]) //小于等于结束日期
);
}else{
bson = Filters.and(
bson,
Filters.gte(columnName, time[0]), //大于等于开始日期
Filters.lte(columnName, time[1]) //小于等于结束日期
);
}
}
}
}
}
return bson;
}
/**
*
* @param columnName
* @param bson
* @param startTime
* @param endTime
* @return
*/
public static Bson timeBuilder(String columnName, Bson bson, String startTime,String endTime) {
if( Objects.nonNull(bson) && StringUtils.isNotBlank(columnName) &&StringUtils.isNotBlank(startTime)&& StringUtils.isNotBlank(endTime)){
bson = Filters.and(
bson,
Filters.gte(columnName, startTime), //大于等于开始日期
Filters.lte(columnName, endTime) //小于等于结束日期
);
}
return bson;
}
/**
*
* @param dateTime
* @param columnName HQL
* @param bson bson
* @param isShowTime
*/
public static Bson timeMore( String dateTime, String columnName, Bson bson, boolean isShowTime) {
if (dateTime == null || dateTime.trim().length() == 0) {
dateTime = "1900-01-01";
} else {
dateTime = getSafeParam(dateTime);
dateTime = dateTime.trim();
}
if (isShowTime && dateTime.trim().length()<=11) {
dateTime+= " 00:00:00";
}
if(bson == null) {
bson = Filters.and(
Filters.gte(columnName, dateTime) //大于等于开始日期
);
}else{
bson = Filters.and(
bson,
Filters.gte(columnName, dateTime) //大于等于开始日期
);
}
return bson;
}
/**
*
* @param dateTime
* @param columnName HQL
* @param bson bson
* @param isShowTime
*/
public static Bson timeLess( String dateTime, String columnName, Bson bson, boolean isShowTime) {
if (dateTime == null || dateTime.trim().length() == 0) {
dateTime = "2100-01-01";
} else {
dateTime = getSafeParam(dateTime);
dateTime = dateTime.trim();
}
if (isShowTime&& dateTime.trim().length()<=11) {
dateTime+= " 23:59:59";
}
if(bson == null) {
bson = Filters.and(
Filters.lte(columnName, dateTime) //小于等于结束日期
);
}else{
bson = Filters.and(
bson,
Filters.lte(columnName, dateTime) //小于等于结束日期
);
}
return bson;
}
/**
* Stringlike
* @param str
* @param columnName
* @param bson
*/
public static Bson getStringLikerPack(String str,String columnName, Bson bson) {
if (str != null && str.trim().length() > 0) {
str = getSafeParam(str);
if(bson == null) {
bson = Filters.and(
Filters.regex(columnName, str) //like
);
}else{
bson = Filters.and(
bson,
Filters.regex(columnName, str)//like
);
}
}
return bson;
}
/**
* Stringlike
* @param str
* @param columnName
* @param bson
*/
public static Bson getStringLikerPackOr(String str,String columnName, Bson bson) {
if (str != null && str.trim().length() > 0) {
str = getSafeParam(str);
if(bson == null) {
bson = Filters.or(
Filters.regex(columnName, str) //like
);
}else {
bson = Filters.and(
bson,
Filters.or(
Filters.regex(columnName, str) //like
)
);
}
}
return bson;
}
/**
* Stringlike()
* @param str
* @param columnName
* @param bson
*/
public static Bson getStringRightLikerPack(String str,String columnName, Bson bson) {
if (str != null && str.trim().length() > 0) {
str = getSafeParam(str);
if(bson == null) {
bson = Filters.and(
Filters.regex(columnName, str + "^") //like
);
}else{
bson = Filters.and(
bson,
Filters.regex(columnName, str + "^") //like
);
}
}
return bson;
}
/**
* Stringlike()
* @param str
* @param columnName
* @param bson
*/
public static Bson getStringLeftLikerPack(String str,String columnName, Bson bson) {
if (str != null && str.trim().length() > 0) {
str = getSafeParam(str);
if(bson == null) {
bson = Filters.and(
Filters.regex(columnName, "^" + str) //like
);
}else{
bson = Filters.and(
bson,
Filters.regex(columnName, "^" + str) //like
);
}
}
return bson;
}
/**
* Stringequal
* @param columnName
* @param bson
*/
public static Bson getStringEqualPack(String data,String columnName, Bson bson) {
if(data != null && data.trim().length() > 0){
data = getSafeParam(data);
if(bson == null) {
bson = Filters.and(
Filters.eq(columnName, data)
);
}else{
bson = Filters.and(
bson,
Filters.eq(columnName, data)
);
}
}
return bson;
}
/**
* longintequal
* @param columnName
* @param bson
*/
public static Bson getNumEqualPack(Object data,String columnName, Bson bson) {
if(data!=null&&Long.parseLong(data.toString()) > 0){
if(bson == null) {
bson = Filters.and(
Filters.eq(columnName, data)
);
}else{
bson = Filters.and(
bson,
Filters.eq(columnName, data)
);
}
}
return bson;
}
/**
* longintequal
* @param columnName
* @param bson
*/
public static Bson getNumEqualPackForZero(Object data,String columnName, Bson bson) {
if(data!=null&&Long.parseLong(data.toString()) >= 0){
if(bson == null) {
bson = Filters.and(
Filters.eq(columnName, data)
);
}else{
bson = Filters.and(
bson,
Filters.eq(columnName, data)
);
}
}
return bson;
}
/**
* longintequal
* @param columnName
* @param bson
*/
public static Bson getNumWithZeroEqualPack(Object data,String columnName, Bson bson) {
if(data!=null&&Long.parseLong(data.toString()) >= 0){
if(bson == null) {
bson = Filters.and(
Filters.eq(columnName, data)
);
}else{
bson = Filters.and(
bson,
Filters.eq(columnName, data)
);
}
}
return bson;
}
/**
* longint
* @param columnName
* @param bson
*/
public static Bson getNumBiggerPack(Object data,String columnName, Bson bson) {
if(data!=null&&Long.parseLong(data.toString()) > 0){
if(bson == null) {
bson = Filters.and(
Filters.gt(columnName, data)
);
}else{
bson = Filters.and(
bson,
Filters.gt(columnName, data)
);
}
}
return bson;
}
/**
* longint
* @param columnName
* @param bson
*/
public static Bson getNumSmallerPack(Object data,String columnName, Bson bson) {
if(data!=null&&Long.parseLong(data.toString()) > 0){
if(bson == null) {
bson = Filters.and(
Filters.lt(columnName, data)
);
}else{
bson = Filters.and(
bson,
Filters.lt(columnName, data)
);
}
}
return bson;
}
/**
* double
* @param columnName
* @param bson
*/
public static Bson getDoubleBiggerPack(Object data,String columnName, Bson bson) {
if(data!=null&&Double.parseDouble(data.toString()) > 0){
if(bson == null) {
bson = Filters.and(
Filters.gt(columnName, data)
);
}else{
bson = Filters.and(
bson,
Filters.gt(columnName, data)
);
}
}
return bson;
}
/**
* double
* @param columnName
* @param bson
*/
public static Bson getDoubleSmallerPack(Object data,String columnName, Bson bson) {
if(data!=null&&Double.parseDouble(data.toString()) > 0){
if(bson == null) {
bson = Filters.and(
Filters.lt(columnName, data)
);
}else{
bson = Filters.and(
bson,
Filters.lt(columnName, data)
);
}
}
return bson;
}
/**
* longintequal
* @param columnName
* @param bson
*/
public static Bson getNumEqualPack(Object data,String columnName, Bson bson,Integer expvalue) {
if(data!=null&&Long.parseLong(data.toString()) > (long)expvalue){
if(bson == null) {
bson = Filters.and(
Filters.eq(columnName, data)
);
}else{
bson = Filters.and(
bson,
Filters.eq(columnName, data)
);
}
}
return bson;
}
/**
* doubleequal
* @param columnName
* @param bson
*/
public static Bson getNumEqualPackDouble(Object data,String columnName, Bson bson) {
if(data!=null&&Double.parseDouble(data.toString()) > 0){
if(bson == null) {
bson = Filters.and(
Filters.eq(columnName, data)
);
}else{
bson = Filters.and(
bson,
Filters.eq(columnName, data)
);
}
}
return bson;
}
/**
* longintequal
* @param columnName
* @param bson
*/
public static Bson getNumEqualPackDouble(Object data,String columnName, Bson bson,Integer expvalue) {
if(data!=null&&Double.parseDouble(data.toString()) > (double)expvalue){
if(bson == null) {
bson = Filters.and(
Filters.eq(columnName, data)
);
}else{
bson = Filters.and(
bson,
Filters.eq(columnName, data)
);
}
}
return bson;
}
/**
* longintequal()
* @param columnName
* @param bson
*/
public static Bson getNumNOEqualPack(Object data,String columnName, Bson bson) {
if(data!=null){
if(bson == null) {
bson = Filters.and(
Filters.ne(columnName, data)
);
}else{
bson = Filters.and(
bson,
Filters.ne(columnName, data)
);
}
}
return bson;
}
/**
* in
* @param data
* @param columnName
* @param bson
*/
public static Bson getInPack(String data,String columnName, Bson bson){
if (data!=null&&data.trim().length()>0) {
data = getSafeParam(data);
if(bson == null) {
bson = Filters.and(
Filters.in(columnName, data)
);
}else{
bson = Filters.and(
bson,
Filters.in(columnName, data)
);
}
}
return bson;
}
/**
* in String
* @param data
* @param columnName
* @param bson
*/
public static Bson getInPackString(String data,String columnName, Bson bson){
if (data != null && data.trim().length()>0) {
data = getSafeParam(data);
//判断最后一位是不是逗号
if(data.lastIndexOf(",") != (data.length()-1)){
data += ",";
}
String[] dataArray = data.substring(0, data.length()-1).split(",");
data = "";
for (int i = 0 ; i < dataArray.length ;i++) {
if(i == dataArray.length -1){
data += "'" + dataArray[i] + "'";
}else{
data += "'" + dataArray[i] + "',";
}
}
if(bson == null) {
bson = Filters.and(
Filters.in(columnName, data)
);
}else{
bson = Filters.and(
bson,
Filters.in(columnName, data)
);
}
}
return bson;
}
/**
* in String
* @param data
* @param columnName
* @param bson
*/
public static Bson getNotInPackString(String data,String columnName, Bson bson){
if (data != null && data.trim().length()>0) {
data = getSafeParam(data);
//判断最后一位是不是逗号
if(data.lastIndexOf(",") != (data.length()-1)){
data += ",";
}
String[] dataArray = data.substring(0, data.length()-1).split(",");
data = "";
for (int i = 0 ; i < dataArray.length ;i++) {
if(i == dataArray.length -1){
data += "'" + dataArray[i] + "'";
}else{
data += "'" + dataArray[i] + "',";
}
}
if(bson == null) {
bson = Filters.and(
Filters.nin(columnName, data)
);
}else{
bson = Filters.and(
bson,
Filters.nin(columnName, data)
);
}
}
return bson;
}
/**
* not in
* @param data
* @param columnName
* @param bson
*/
public static Bson getNotInPack(String data,String columnName, Bson bson){
if (data!=null&&data.trim().length()>0) {
data = getSafeParam(data);
if(bson == null) {
bson = Filters.and(
Filters.nin(columnName, data)
);
}else{
bson = Filters.and(
bson,
Filters.nin(columnName, data)
);
}
}
return bson;
}
/**
* MONGODBBSON
* @param dList
* @param entityClass
* @return
*/
public List<?> packDocumentToObjectList(List<Document> dList,Class entityClass){
//将获取的document转为对象
List resultList = new ArrayList();
for(Document d : dList){
resultList.add(JSONObject.parseObject(d.toJson(), entityClass));
}
return resultList;
}
}

@ -1,14 +0,0 @@
package cn.estsh.i3plus.pojo.platform.platrepositorymongo;
import cn.estsh.i3plus.pojo.base.jpa.dao.BaseMongoRepository;
import cn.estsh.i3plus.pojo.platform.platbean.SysLogException;
/**
* @Description : (使Mongodb)
* @Reference :
* @Author : frin
* @Date : 2018-11-8 12:03:00
* @Modify :
**/
public interface SysLogExceptionRepository extends BaseMongoRepository<SysLogException, Long> {
}

@ -1,14 +0,0 @@
package cn.estsh.i3plus.pojo.platform.platrepositorymongo;
import cn.estsh.i3plus.pojo.base.jpa.dao.BaseMongoRepository;
import cn.estsh.i3plus.pojo.platform.platbean.SysLogOperate;
/**
* @Description : (使Mongodb)
* @Reference :
* @Author : wei.peng
* @Date : 2018-10-22 12:03:00.118
* @Modify :
**/
public interface SysLogOperateRepository extends BaseMongoRepository<SysLogOperate, Long> {
}

@ -1,14 +0,0 @@
package cn.estsh.i3plus.pojo.platform.platrepositorymongo;
import cn.estsh.i3plus.pojo.base.jpa.dao.BaseMongoRepository;
import cn.estsh.i3plus.pojo.platform.platbean.SysLogSystem;
/**
* @Description :
* @Reference :
* @Author : wei.peng
* @Date : 2018-10-22 12:03:00.158
* @Modify :
**/
public interface SysLogSystemRepository extends BaseMongoRepository<SysLogSystem, Long> {
}

@ -1,14 +0,0 @@
package cn.estsh.i3plus.pojo.platform.platrepositorymongo;
import cn.estsh.i3plus.pojo.base.jpa.dao.BaseMongoRepository;
import cn.estsh.i3plus.pojo.platform.platbean.SysLogTaskTime;
/**
* @Description :
* @Reference :
* @Author : yunhao
* @CreateDate : 2018-12-20 22:35
* @Modify:
**/
public interface SysLogTaskTimeRepository extends BaseMongoRepository<SysLogTaskTime, Long> {
}

@ -35,7 +35,6 @@
<module>modules/i3plus-pojo-ptl</module>
<module>modules/i3plus-pojo-ics</module>
<module>modules/i3plus-pojo-mdm</module>
<module>modules/i3plus-pojo-base-mongo</module>
</modules>
<dependencies>

Loading…
Cancel
Save