yun-zuoyi
gragon.xu 6 years ago
commit fbd32befea

@ -18,23 +18,45 @@ public class BaseFallBackBean {
// LOGGER.error("【微服出错,熔断】{}",cause.getCause()); // LOGGER.error("【微服出错,熔断】{}",cause.getCause());
// cause.printStackTrace(); // cause.printStackTrace();
/**
*
* @param cause
* @return
*/
public BaseResultBean makeBaseFallBack(Throwable cause){ public BaseResultBean makeBaseFallBack(Throwable cause){
LOGGER.error("【熔断信息】{}",cause.getMessage()); LOGGER.error("【熔断信息】{}", cause.getMessage());
LOGGER.error("【熔断原因】{}",cause.getCause()); LOGGER.error("【熔断原因】{}", cause.getCause());
return makeBaseFallBack("【微服熔断】服务暂停,请稍后再试。",cause); cause.printStackTrace();
return makeBaseFallBack("【微服熔断】服务暂停,请稍后再试。", cause);
} }
public BaseResultBean makeBaseFallBack(String msg,Throwable cause){ /**
LOGGER.error("【熔断信息】{}",cause.getMessage()); *
LOGGER.error("【熔断原因】{}",cause.getCause()); * @param msg
return BaseResultBean.buildBaseResultBean(false,cause.getMessage() + ",信息:" + msg); * @param cause
* @return
*/
public BaseResultBean makeBaseFallBack(String msg, Throwable cause){
LOGGER.error("【熔断信息】{}", cause.getMessage());
LOGGER.error("【熔断原因】{}", cause.getCause());
cause.printStackTrace();
return BaseResultBean.buildBaseResultBean(false, cause.getMessage() + ",信息:" + msg);
} }
/**
*
* @return
*/
public BaseResultBean makeBaseFallBack(){ public BaseResultBean makeBaseFallBack(){
return makeBaseFallBack("【微服熔断】服务暂停,请稍后再试。"); return makeBaseFallBack("【微服熔断】服务暂停,请稍后再试。");
} }
/**
*
* @param msg
* @return
*/
public BaseResultBean makeBaseFallBack(String msg){ public BaseResultBean makeBaseFallBack(String msg){
return BaseResultBean.buildBaseResultBean(false,msg); return BaseResultBean.buildBaseResultBean(false, msg);
} }
} }

@ -105,6 +105,15 @@ public interface BaseRepository <T, ID extends Serializable> extends JpaReposito
int updateByProperties(String conditionName, Object conditionValue, String[] propertyName, Object[] propertyValue); int updateByProperties(String conditionName, Object conditionValue, String[] propertyName, Object[] propertyValue);
/** /**
*
* @param propertyName
* @param propertyValue
*/
int updateByProperties(String propertyName, Object propertyValue,DdlPackBean packBean);
int updateByProperties(String[] propertyName, Object[] propertyValue,DdlPackBean packBean);
/**
* *
* @param conditionName * @param conditionName
* @param conditionValue * @param conditionValue

@ -5,8 +5,10 @@ import cn.estsh.i3plus.pojo.base.enumutil.CommonEnumUtil;
import cn.estsh.i3plus.pojo.base.jpa.dao.BaseMongoRepository; import cn.estsh.i3plus.pojo.base.jpa.dao.BaseMongoRepository;
import cn.estsh.i3plus.pojo.base.codemaker.SnowflakeIdMaker; import cn.estsh.i3plus.pojo.base.codemaker.SnowflakeIdMaker;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.mongodb.BasicDBObject;
import com.mongodb.Block; import com.mongodb.Block;
import com.mongodb.client.FindIterable; import com.mongodb.client.FindIterable;
import com.mongodb.client.model.CountOptions;
import com.mongodb.client.model.Filters; import com.mongodb.client.model.Filters;
import com.mongodb.client.model.Sorts; import com.mongodb.client.model.Sorts;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
@ -21,6 +23,7 @@ import org.springframework.data.mapping.context.MappingContext;
import org.springframework.data.mongodb.core.MongoOperations; import org.springframework.data.mongodb.core.MongoOperations;
import org.springframework.data.mongodb.core.mapping.MongoPersistentEntity; import org.springframework.data.mongodb.core.mapping.MongoPersistentEntity;
import org.springframework.data.mongodb.core.mapping.MongoPersistentProperty; 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.query.MongoEntityInformation;
import org.springframework.data.mongodb.repository.support.SimpleMongoRepository; import org.springframework.data.mongodb.repository.support.SimpleMongoRepository;
@ -271,13 +274,9 @@ public class BaseMongoRepositoryImpl<T, ID extends Serializable> extends SimpleM
FindIterable findIter = null; FindIterable findIter = null;
if(bson == null) { if(bson == null) {
findIter = mongoOperations.getCollection(this.entityInformation.getCollectionName()).find() findIter = mongoOperations.getCollection(this.entityInformation.getCollectionName()).find();
.skip(pager.getStartRow())
.limit(pager.getPageSize());
}else{ }else{
findIter = mongoOperations.getCollection(this.entityInformation.getCollectionName()).find(bson) findIter = mongoOperations.getCollection(this.entityInformation.getCollectionName()).find(bson);
.skip(pager.getStartRow())
.limit(pager.getPageSize());
} }
if(StringUtils.isNotBlank(orderByParam) && ascOrDesc != 0){ if(StringUtils.isNotBlank(orderByParam) && ascOrDesc != 0){
//排序 //排序
@ -286,8 +285,13 @@ public class BaseMongoRepositoryImpl<T, ID extends Serializable> extends SimpleM
}else{ }else{
findIter.sort(Sorts.descending(orderByParam)); findIter.sort(Sorts.descending(orderByParam));
} }
}else{
//根据id排序
findIter.sort(new BasicDBObject("_id", 1));
} }
findIter.skip(pager.getStartRow()).limit(pager.getPageSize());
findIter.forEach(saveBlock); findIter.forEach(saveBlock);
return packObjectListFromDocument(dList); return packObjectListFromDocument(dList);
} }
@ -310,9 +314,7 @@ public class BaseMongoRepositoryImpl<T, ID extends Serializable> extends SimpleM
dList.add(document); dList.add(document);
} }
}; };
FindIterable findIter = mongoOperations.getCollection(this.entityInformation.getCollectionName()).find() FindIterable findIter = mongoOperations.getCollection(this.entityInformation.getCollectionName()).find();
.skip(pager.getStartRow())
.limit(pager.getPageSize());
if(StringUtils.isNotBlank(orderByParam) && ascOrDesc != 0){ if(StringUtils.isNotBlank(orderByParam) && ascOrDesc != 0){
//排序 //排序
if(ascOrDesc == CommonEnumUtil.ASC_OR_DESC.ASC.getValue()){ if(ascOrDesc == CommonEnumUtil.ASC_OR_DESC.ASC.getValue()){
@ -320,7 +322,11 @@ public class BaseMongoRepositoryImpl<T, ID extends Serializable> extends SimpleM
}else{ }else{
findIter.sort(Sorts.descending(orderByParam)); findIter.sort(Sorts.descending(orderByParam));
} }
}else{
//根据id排序
findIter.sort(new BasicDBObject("_id", 1));
} }
findIter.skip(pager.getStartRow()).limit(pager.getPageSize());
findIter.forEach(saveBlock); findIter.forEach(saveBlock);
return packObjectListFromDocument(dList); return packObjectListFromDocument(dList);
} }

@ -222,6 +222,40 @@ public class BaseRepositoryImpl<T, ID extends Serializable> extends SimpleJpaRep
} }
@Override @Override
public int updateByProperties(String propertyName, Object propertyValue,DdlPackBean packBean) {
return updateByProperties(new String[] { propertyName }, new Object[] { propertyValue },packBean);
}
@Override
public int updateByProperties(String[] propertyName, Object[] propertyValue,DdlPackBean packBean) {
if ((propertyName != null) && (propertyName.length > 0) && (propertyValue != null)
&& (propertyValue.length > 0) && (propertyName.length == propertyValue.length)) {
StringBuffer sb = new StringBuffer();
sb.append("update " + persistentClass.getName() + " model set ");
for (int i = 0; i < propertyName.length; i++) {
sb.append(propertyName[i] + " = :p_" + propertyName[i] + ",");
}
sb.deleteCharAt(sb.length() - 1);
sb.append(" where 1=1 " + packBean.getWhereAppend());
Query query = entityManager.createQuery(sb.toString());
//更新值
for (int i = 0; i < propertyName.length; i++) {
query.setParameter("p_" + propertyName[i], propertyValue[i]);
}
//查询条件
for (String key : packBean.getHqlPreparedMap().keySet()) {
query.setParameter(key,packBean.getHqlPreparedMap().get(key));
}
return query.executeUpdate();
} else {
throw new IllegalArgumentException("参数值错误!,propertyName:" + propertyName + ",propertyValue:" + propertyValue);
}
}
@Override
public int updateByHqlWhere(String hqlWhere, String propertyName, Object propertyValue) { public int updateByHqlWhere(String hqlWhere, String propertyName, Object propertyValue) {
return updateByHqlWhere(hqlWhere, new String[]{propertyName}, new Object[]{propertyValue}); return updateByHqlWhere(hqlWhere, new String[]{propertyName}, new Object[]{propertyValue});
} }

Loading…
Cancel
Save