|
|
|
@ -11,10 +11,7 @@ import org.slf4j.Logger;
|
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
import org.springframework.data.jpa.repository.support.SimpleJpaRepository;
|
|
|
|
|
|
|
|
|
|
import javax.persistence.EntityManager;
|
|
|
|
|
import javax.persistence.Id;
|
|
|
|
|
import javax.persistence.NoResultException;
|
|
|
|
|
import javax.persistence.Query;
|
|
|
|
|
import javax.persistence.*;
|
|
|
|
|
import java.io.Serializable;
|
|
|
|
|
import java.lang.reflect.Field;
|
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
|
@ -196,6 +193,42 @@ public class BaseRepositoryImpl<T, ID extends Serializable> extends SimpleJpaRep
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public int updateByProperties(String[] conditionName, Object[] conditionValue, String[] propertyName, Object[] propertyValue) {
|
|
|
|
|
return updateByPropertiesMain(conditionName, conditionValue, propertyName, propertyValue,true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public int updateByPropertiesWithVal(String conditionName, Object conditionValue, String propertyName, Object propertyValue) {
|
|
|
|
|
return updateByPropertiesWithVal(new String[] { conditionName }, new Object[] { conditionValue }, new String[] { propertyName }, new Object[] { propertyValue });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public int updateByPropertiesWithVal(String conditionName, Object conditionValue, String[] propertyName, Object[] propertyValue) {
|
|
|
|
|
return updateByPropertiesWithVal(new String[] { conditionName }, new Object[] { conditionValue }, propertyName, propertyValue);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public int updateByPropertiesWithVal(String[] conditionName, Object[] conditionValue, String propertyName, Object propertyValue) {
|
|
|
|
|
return updateByPropertiesWithVal(conditionName, conditionValue, new String[] { propertyName }, new Object[] { propertyValue });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public int updateByPropertiesWithVal(String[] conditionName, Object[] conditionValue, String[] propertyName, Object[] propertyValue) {
|
|
|
|
|
return updateByPropertiesMain(conditionName, conditionValue, propertyName, propertyValue,false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 更新参数汇总方法
|
|
|
|
|
* @param conditionName 条件属性名
|
|
|
|
|
* @param conditionValue 条件属性值
|
|
|
|
|
* @param propertyName 更新属性名
|
|
|
|
|
* @param propertyValue 更新属性值
|
|
|
|
|
* @param valWithSimple 是否简单赋值
|
|
|
|
|
* true为正常eg: price = :price
|
|
|
|
|
* false为自身添加eg: price = price + :price
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
private int updateByPropertiesMain(String[] conditionName, Object[] conditionValue,
|
|
|
|
|
String[] propertyName, Object[] propertyValue,boolean valWithSimple) {
|
|
|
|
|
if ((propertyName != null) && (propertyName.length > 0) && (propertyValue != null)
|
|
|
|
|
&& (propertyValue.length > 0) && (propertyName.length == propertyValue.length)
|
|
|
|
|
&& (conditionValue != null) && (conditionValue.length > 0)) {
|
|
|
|
@ -203,7 +236,11 @@ public class BaseRepositoryImpl<T, ID extends Serializable> extends SimpleJpaRep
|
|
|
|
|
|
|
|
|
|
sb.append("update " + persistentClass.getName() + " model set ");
|
|
|
|
|
for (int i = 0; i < propertyName.length; i++) {
|
|
|
|
|
sb.append(propertyName[i] + " = :p_" + propertyName[i] + ",");
|
|
|
|
|
if(valWithSimple) {
|
|
|
|
|
sb.append(propertyName[i] + " = :p_" + propertyName[i] + ",");
|
|
|
|
|
}else{
|
|
|
|
|
sb.append(propertyName[i] + " = " + propertyName[i] + " + :p_" + propertyName[i] + ",");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
sb.deleteCharAt(sb.length() - 1);
|
|
|
|
|
|
|
|
|
@ -229,13 +266,32 @@ public class BaseRepositoryImpl<T, ID extends Serializable> extends SimpleJpaRep
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public int updateByProperties(String[] propertyName, Object[] propertyValue,DdlPackBean packBean) {
|
|
|
|
|
return updateByPropertiesDdlPack(propertyName, propertyValue,packBean,true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public int updateByPropertiesWithVal(String propertyName, Object propertyValue,DdlPackBean packBean) {
|
|
|
|
|
return updateByPropertiesWithVal(new String[] { propertyName }, new Object[] { propertyValue },packBean);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public int updateByPropertiesWithVal(String[] propertyName, Object[] propertyValue,DdlPackBean packBean) {
|
|
|
|
|
return updateByPropertiesDdlPack(propertyName, propertyValue,packBean,false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private int updateByPropertiesDdlPack(String[] propertyName, Object[] propertyValue,
|
|
|
|
|
DdlPackBean packBean,boolean valWithSimple) {
|
|
|
|
|
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] + ",");
|
|
|
|
|
if(valWithSimple) {
|
|
|
|
|
sb.append(propertyName[i] + " = :p_" + propertyName[i] + ",");
|
|
|
|
|
}else{
|
|
|
|
|
sb.append(propertyName[i] + " = " + propertyName[i] + " + :p_" + propertyName[i] + ",");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
sb.deleteCharAt(sb.length() - 1);
|
|
|
|
|
sb.append(" where 1=1 " + packBean.getWhereAppend());
|
|
|
|
@ -297,7 +353,9 @@ public class BaseRepositoryImpl<T, ID extends Serializable> extends SimpleJpaRep
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public List<T> list() {
|
|
|
|
|
return this.findAll();
|
|
|
|
|
List<T> l = this.findAll();
|
|
|
|
|
this.flush();
|
|
|
|
|
return l;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@ -1349,7 +1407,11 @@ public class BaseRepositoryImpl<T, ID extends Serializable> extends SimpleJpaRep
|
|
|
|
|
if ((paramName != null) && (paramName.length > 0) && (paramValue != null) && (paramValue.length > 0)) {
|
|
|
|
|
StringBuffer sb = new StringBuffer("select sum(model." + sumPropertyName + ") from " + persistentClass.getName() + " model where 1=1 ");
|
|
|
|
|
appendQL(sb, paramName, paramValue);
|
|
|
|
|
sb.append(" group by model." + groupByName);
|
|
|
|
|
|
|
|
|
|
if(StringUtils.isNotBlank(groupByName)) {
|
|
|
|
|
sb.append(" group by model." + groupByName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Query query = entityManager.createQuery(sb.toString());
|
|
|
|
|
setParameter(query,paramName,paramValue);
|
|
|
|
|
|
|
|
|
@ -1374,7 +1436,10 @@ public class BaseRepositoryImpl<T, ID extends Serializable> extends SimpleJpaRep
|
|
|
|
|
if ((paramName != null) && (paramName.length > 0) && (paramValue != null) && (paramValue.length > 0)) {
|
|
|
|
|
StringBuffer sb = new StringBuffer("select avg(model."+sumPropertyName+") from " + persistentClass.getName() + " model where 1=1 ");
|
|
|
|
|
appendQL(sb,paramName,paramValue);
|
|
|
|
|
sb.append(" group by model." + groupByName);
|
|
|
|
|
|
|
|
|
|
if(StringUtils.isNotBlank(groupByName)) {
|
|
|
|
|
sb.append(" group by model." + groupByName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Query query = entityManager.createQuery(sb.toString());
|
|
|
|
|
setParameter(query,paramName,paramValue);
|
|
|
|
@ -1400,7 +1465,7 @@ public class BaseRepositoryImpl<T, ID extends Serializable> extends SimpleJpaRep
|
|
|
|
|
if ((paramName != null) && (paramName.length > 0) && (paramValue != null) && (paramValue.length > 0)) {
|
|
|
|
|
StringBuffer sb = new StringBuffer("select max(model." + sumPropertyName + ") from " + persistentClass.getName() + " model where 1=1 ");
|
|
|
|
|
appendQL(sb, paramName, paramValue);
|
|
|
|
|
if(!StringUtils.isEmpty(groupByName)){
|
|
|
|
|
if(StringUtils.isNotBlank(groupByName)){
|
|
|
|
|
sb.append(" group by model." + groupByName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -1428,7 +1493,10 @@ public class BaseRepositoryImpl<T, ID extends Serializable> extends SimpleJpaRep
|
|
|
|
|
if ((paramName != null) && (paramName.length > 0) && (paramValue != null) && (paramValue.length > 0)) {
|
|
|
|
|
StringBuffer sb = new StringBuffer("select min(model." + sumPropertyName + ") from " + persistentClass.getName() + " model where 1=1 ");
|
|
|
|
|
appendQL(sb, paramName, paramValue);
|
|
|
|
|
sb.append(" group by model." + groupByName);
|
|
|
|
|
|
|
|
|
|
if(StringUtils.isNotBlank(groupByName)) {
|
|
|
|
|
sb.append(" group by model." + groupByName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Query query = entityManager.createQuery(sb.toString());
|
|
|
|
|
setParameter(query,paramName,paramValue);
|
|
|
|
|