|
@@ -58,7 +58,11 @@ public abstract class BaseService<M extends BaseMapper<E>, E,PK extends Serializ
|
|
|
@Override
|
|
@Override
|
|
|
public boolean saveBatch(Collection<E> entityList, int batchSize) {
|
|
public boolean saveBatch(Collection<E> entityList, int batchSize) {
|
|
|
entityList.forEach(this::validateBeforeSave);
|
|
entityList.forEach(this::validateBeforeSave);
|
|
|
- return super.saveBatch(entityList, batchSize);
|
|
|
|
|
|
|
+ if (super.saveBatch(entityList, batchSize)) {
|
|
|
|
|
+ entityList.forEach(this::postSave);
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+ return false;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -78,7 +82,19 @@ public abstract class BaseService<M extends BaseMapper<E>, E,PK extends Serializ
|
|
|
String keyProperty = tableInfo.getKeyProperty();
|
|
String keyProperty = tableInfo.getKeyProperty();
|
|
|
Assert.notEmpty(keyProperty, "error: can not execute. because can not find column for id from entity!");
|
|
Assert.notEmpty(keyProperty, "error: can not execute. because can not find column for id from entity!");
|
|
|
Object idVal = tableInfo.getPropertyValue(entity, tableInfo.getKeyProperty());
|
|
Object idVal = tableInfo.getPropertyValue(entity, tableInfo.getKeyProperty());
|
|
|
- return StringUtils.checkValNull(idVal) || Objects.isNull(getById((Serializable) idVal)) ? save(entity) : updateById(entity);
|
|
|
|
|
|
|
+ if (StringUtils.checkValNull(idVal) || Objects.isNull(getById((Serializable) idVal))) {
|
|
|
|
|
+ if(save(entity)){
|
|
|
|
|
+ postSave(entity);
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }else {
|
|
|
|
|
+ if(updateById(entity)){
|
|
|
|
|
+ postUpdate(entity);
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
@@ -106,50 +122,77 @@ public abstract class BaseService<M extends BaseMapper<E>, E,PK extends Serializ
|
|
|
MapperMethod.ParamMap<E> param = new MapperMethod.ParamMap<>();
|
|
MapperMethod.ParamMap<E> param = new MapperMethod.ParamMap<>();
|
|
|
validateBeforeUpdate(entity);
|
|
validateBeforeUpdate(entity);
|
|
|
param.put(Constants.ENTITY, entity);
|
|
param.put(Constants.ENTITY, entity);
|
|
|
- sqlSession.update(getSqlStatement(SqlMethod.UPDATE_BY_ID), param);
|
|
|
|
|
|
|
+ if (sqlSession.update(getSqlStatement(SqlMethod.UPDATE_BY_ID), param)==0) {
|
|
|
|
|
+ postUpdate(entity);
|
|
|
|
|
+ }
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public boolean removeById(Serializable id) {
|
|
public boolean removeById(Serializable id) {
|
|
|
validateBeforeDelete((PK) id);
|
|
validateBeforeDelete((PK) id);
|
|
|
- return super.removeById(id);
|
|
|
|
|
|
|
+ if (super.removeById(id)) {
|
|
|
|
|
+ postDelete((PK) id);
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+ return false;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public boolean removeByIds(Collection<?> list) {
|
|
public boolean removeByIds(Collection<?> list) {
|
|
|
list.stream().map(id->(PK)id).forEach(this::validateBeforeDelete);
|
|
list.stream().map(id->(PK)id).forEach(this::validateBeforeDelete);
|
|
|
- return super.removeByIds(list);
|
|
|
|
|
|
|
+ if (super.removeByIds(list)) {
|
|
|
|
|
+ list.stream().map(id->(PK)id).forEach(this::postDelete);
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+ return false;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public boolean removeById(Serializable id, boolean useFill) {
|
|
public boolean removeById(Serializable id, boolean useFill) {
|
|
|
this.validateBeforeDelete((PK) id);
|
|
this.validateBeforeDelete((PK) id);
|
|
|
- return super.removeById(id, useFill);
|
|
|
|
|
|
|
+ if (super.removeById(id, useFill)) {
|
|
|
|
|
+ postDelete((PK) id);
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+ return false;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public boolean removeBatchByIds(Collection<?> list, int batchSize) {
|
|
public boolean removeBatchByIds(Collection<?> list, int batchSize) {
|
|
|
list.stream().map(id->(PK)id).forEach(this::validateBeforeDelete);
|
|
list.stream().map(id->(PK)id).forEach(this::validateBeforeDelete);
|
|
|
- return super.removeBatchByIds(list, batchSize);
|
|
|
|
|
|
|
+ if (super.removeBatchByIds(list, batchSize)) {
|
|
|
|
|
+ list.stream().map(id->(PK)id).forEach(this::postDelete);
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+ return false;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public boolean removeBatchByIds(Collection<?> list, int batchSize, boolean useFill) {
|
|
public boolean removeBatchByIds(Collection<?> list, int batchSize, boolean useFill) {
|
|
|
list.stream().map(id->(PK)id).forEach(this::validateBeforeDelete);
|
|
list.stream().map(id->(PK)id).forEach(this::validateBeforeDelete);
|
|
|
- return super.removeBatchByIds(list, batchSize, useFill);
|
|
|
|
|
|
|
+ if (super.removeBatchByIds(list, batchSize, useFill)) {
|
|
|
|
|
+ list.stream().map(id->(PK)id).forEach(this::postDelete);
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+ return false;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public boolean updateById(E entity) {
|
|
public boolean updateById(E entity) {
|
|
|
validateBeforeUpdate(entity);
|
|
validateBeforeUpdate(entity);
|
|
|
- return super.updateById(entity);
|
|
|
|
|
|
|
+ if (super.updateById(entity)) {
|
|
|
|
|
+ postUpdate(entity);
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+ return false;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public boolean updateBatchById(Collection<E> entityList) {
|
|
public boolean updateBatchById(Collection<E> entityList) {
|
|
|
entityList.forEach(this::validateBeforeUpdate);
|
|
entityList.forEach(this::validateBeforeUpdate);
|
|
|
|
|
+ entityList.forEach(this::postUpdate);
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -191,6 +234,26 @@ public abstract class BaseService<M extends BaseMapper<E>, E,PK extends Serializ
|
|
|
return queryWrapper;
|
|
return queryWrapper;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 保存成功后操作
|
|
|
|
|
+ */
|
|
|
|
|
+ public void postSave(E entity ){
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 更新成功后操作
|
|
|
|
|
+ */
|
|
|
|
|
+ public void postUpdate(E entity){
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 删除成功后操作
|
|
|
|
|
+ */
|
|
|
|
|
+ public void postDelete(PK id){
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* @Author lifang
|
|
* @Author lifang
|
|
@@ -211,6 +274,7 @@ public abstract class BaseService<M extends BaseMapper<E>, E,PK extends Serializ
|
|
|
public abstract void validateBeforeUpdate(E entity) ;
|
|
public abstract void validateBeforeUpdate(E entity) ;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* @Author lifang
|
|
* @Author lifang
|
|
|
* @Date 10:02 2022/3/14
|
|
* @Date 10:02 2022/3/14
|