|
|
|
@ -222,6 +222,59 @@ public class BaseRepositoryImpl<T, ID extends Serializable> extends SimpleJpaRep
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public int updateValidStatusById(ID id,int status) {
|
|
|
|
|
return updateValidStatusByProperty("id", id,status);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public int updateValidStatusByIds(Long[] ids,int status) {
|
|
|
|
|
return updateValidStatusByPropertyIn("id", ids,status);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public int updateValidStatusByProperty(String propName, Object propValue,int status) {
|
|
|
|
|
return updateValidStatusByProperties(new String[] { propName }, new Object[] { propValue },status);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 批量弱删除
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public int updateValidStatusByPropertyIn(String propName, Object[] propValues,int status) {
|
|
|
|
|
if(propValues != null && propValues.length > 0){
|
|
|
|
|
String hql = "update " + persistentClass.getName() + " model set model.isValid = :isValid where model."+propName+" in(:"+propName+") ";
|
|
|
|
|
Query query = entityManager.createQuery(hql);
|
|
|
|
|
query.setParameter("isValid",status);
|
|
|
|
|
query.setParameter(propName, Arrays.asList(propValues));
|
|
|
|
|
|
|
|
|
|
return query.executeUpdate();
|
|
|
|
|
}else{
|
|
|
|
|
throw new IllegalArgumentException("弱删除失败:"+propName+":" + propValues);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 批量弱删除
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public int updateValidStatusByProperties(String[] propName, Object[] propValue,int status) {
|
|
|
|
|
if ((propName != null) && (propName.length > 0) && (propValue != null) && (propValue.length > 0) && (propValue.length == propName.length)) {
|
|
|
|
|
StringBuffer sb = new StringBuffer("update " + persistentClass.getName() + " model set model.isValid = :isValid where 1=1 ");
|
|
|
|
|
appendQL(sb,propName,propValue);
|
|
|
|
|
Query query = entityManager.createQuery(sb.toString());
|
|
|
|
|
query.setParameter("isValid",status);
|
|
|
|
|
|
|
|
|
|
setParameter(query,propName,propValue);
|
|
|
|
|
|
|
|
|
|
return query.executeUpdate();
|
|
|
|
|
}else{
|
|
|
|
|
throw new IllegalArgumentException("弱删除失败:"+propName+":" + propValue);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public int updateByProperties(String conditionName, Object conditionValue, String propertyName, Object propertyValue) {
|
|
|
|
|
return updateByProperties(new String[] { conditionName }, new Object[] { conditionValue }, new String[] { propertyName }, new Object[] { propertyValue });
|
|
|
|
|
}
|
|
|
|
|