|
|
|
@ -1018,4 +1018,100 @@ public class BaseRepositoryImpl<T, ID extends Serializable> extends SimpleJpaRep
|
|
|
|
|
public boolean isExitBySql(String sql) {
|
|
|
|
|
return findBySqlCount(sql) > 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public double findSumByProperty(String sumPropertyName, String groupByName, String propertyName, Object value) {
|
|
|
|
|
return findSumByProperties(sumPropertyName,groupByName,new String[]{propertyName},new Object[]{value});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public double findSumByProperties(String sumPropertyName, String groupByName, String[] paramName, Object[] paramValue) {
|
|
|
|
|
if ((paramName != null) && (paramName.length > 0) && (paramValue != null) && (paramValue.length > 0)) {
|
|
|
|
|
StringBuffer sb = new StringBuffer("select sum(:"+sumPropertyName+") from " + persistentClass.getName() + " model where 1=1 ");
|
|
|
|
|
appendQL(sb,paramName,paramValue);
|
|
|
|
|
sb.append(" group by :groupByName");
|
|
|
|
|
|
|
|
|
|
Query query = entityManager.createQuery(sb.toString());
|
|
|
|
|
query.setParameter(":sumPropertyName", sumPropertyName);
|
|
|
|
|
setParameter(query,paramName,paramValue);
|
|
|
|
|
query.setParameter(":groupByName", groupByName);
|
|
|
|
|
|
|
|
|
|
Double sumResult = entityManager.createQuery(query.toString(),Double.class).getSingleResult();
|
|
|
|
|
return sumResult == null ? 0.0 : sumResult.doubleValue();
|
|
|
|
|
}else{
|
|
|
|
|
throw new IllegalArgumentException("sum查询错误!paramName:" + paramName + ",paramValue:" + paramValue);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public double findAvgByProperty(String sumPropertyName, String groupByName, String propertyName, Object value) {
|
|
|
|
|
return findAvgByProperties(sumPropertyName,groupByName,new String[]{propertyName},new Object[]{value});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public double findAvgByProperties(String sumPropertyName, String groupByName, String[] paramName, Object[] paramValue) {
|
|
|
|
|
if ((paramName != null) && (paramName.length > 0) && (paramValue != null) && (paramValue.length > 0)) {
|
|
|
|
|
StringBuffer sb = new StringBuffer("select avg(:"+sumPropertyName+") from " + persistentClass.getName() + " model where 1=1 ");
|
|
|
|
|
appendQL(sb,paramName,paramValue);
|
|
|
|
|
sb.append(" group by :groupByName");
|
|
|
|
|
|
|
|
|
|
Query query = entityManager.createQuery(sb.toString());
|
|
|
|
|
query.setParameter(":sumPropertyName", sumPropertyName);
|
|
|
|
|
setParameter(query,paramName,paramValue);
|
|
|
|
|
query.setParameter(":groupByName", groupByName);
|
|
|
|
|
|
|
|
|
|
Double sumResult = entityManager.createQuery(query.toString(),Double.class).getSingleResult();
|
|
|
|
|
return sumResult == null ? 0.0 : sumResult.doubleValue();
|
|
|
|
|
}else{
|
|
|
|
|
throw new IllegalArgumentException("sum查询错误!paramName:" + paramName + ",paramValue:" + paramValue);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public double findMaxByProperty(String sumPropertyName, String groupByName, String propertyName, Object value) {
|
|
|
|
|
return findMaxByProperties(sumPropertyName,groupByName,new String[]{propertyName},new Object[]{value});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public double findMaxByProperties(String sumPropertyName, String groupByName, String[] paramName, Object[] paramValue) {
|
|
|
|
|
if ((paramName != null) && (paramName.length > 0) && (paramValue != null) && (paramValue.length > 0)) {
|
|
|
|
|
StringBuffer sb = new StringBuffer("select max(:"+sumPropertyName+") from " + persistentClass.getName() + " model where 1=1 ");
|
|
|
|
|
appendQL(sb,paramName,paramValue);
|
|
|
|
|
sb.append(" group by :groupByName");
|
|
|
|
|
|
|
|
|
|
Query query = entityManager.createQuery(sb.toString());
|
|
|
|
|
query.setParameter(":sumPropertyName", sumPropertyName);
|
|
|
|
|
setParameter(query,paramName,paramValue);
|
|
|
|
|
query.setParameter(":groupByName", groupByName);
|
|
|
|
|
|
|
|
|
|
Double sumResult = entityManager.createQuery(query.toString(),Double.class).getSingleResult();
|
|
|
|
|
return sumResult == null ? 0.0 : sumResult.doubleValue();
|
|
|
|
|
}else{
|
|
|
|
|
throw new IllegalArgumentException("sum查询错误!paramName:" + paramName + ",paramValue:" + paramValue);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public double findMinByProperty(String sumPropertyName, String groupByName, String propertyName, Object value) {
|
|
|
|
|
return findMinByProperties(sumPropertyName,groupByName,new String[]{propertyName},new Object[]{value});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public double findMinByProperties(String sumPropertyName, String groupByName, String[] paramName, Object[] paramValue) {
|
|
|
|
|
if ((paramName != null) && (paramName.length > 0) && (paramValue != null) && (paramValue.length > 0)) {
|
|
|
|
|
StringBuffer sb = new StringBuffer("select min(:"+sumPropertyName+") from " + persistentClass.getName() + " model where 1=1 ");
|
|
|
|
|
appendQL(sb,paramName,paramValue);
|
|
|
|
|
sb.append(" group by :groupByName");
|
|
|
|
|
|
|
|
|
|
Query query = entityManager.createQuery(sb.toString());
|
|
|
|
|
query.setParameter(":sumPropertyName", sumPropertyName);
|
|
|
|
|
setParameter(query,paramName,paramValue);
|
|
|
|
|
query.setParameter(":groupByName", groupByName);
|
|
|
|
|
|
|
|
|
|
Double sumResult = entityManager.createQuery(query.toString(),Double.class).getSingleResult();
|
|
|
|
|
return sumResult == null ? 0.0 : sumResult.doubleValue();
|
|
|
|
|
}else{
|
|
|
|
|
throw new IllegalArgumentException("sum查询错误!paramName:" + paramName + ",paramValue:" + paramValue);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|