|
|
|
@ -1027,17 +1027,19 @@ public class BaseRepositoryImpl<T, ID extends Serializable> extends SimpleJpaRep
|
|
|
|
|
@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");
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
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();
|
|
|
|
|
double sumResult = 0.0;
|
|
|
|
|
List<?> objList = query.getResultList();
|
|
|
|
|
// query.getSingleResult()
|
|
|
|
|
if(objList.size() > 0){
|
|
|
|
|
sumResult = Double.parseDouble(objList.iterator().next().toString());
|
|
|
|
|
}
|
|
|
|
|
return sumResult;
|
|
|
|
|
}else{
|
|
|
|
|
throw new IllegalArgumentException("sum查询错误!paramName:" + paramName + ",paramValue:" + paramValue);
|
|
|
|
|
}
|
|
|
|
|