|
@@ -148,14 +148,17 @@ public class ServiceImpl<M extends BaseMapper<T>, T> implements IService<T> {
|
|
|
Assert.notNull(tableInfo, "error: can not execute. because can not find cache of TableInfo for entity!");
|
|
|
String keyProperty = tableInfo.getKeyProperty();
|
|
|
Assert.notEmpty(keyProperty, "error: can not execute. because can not find column for id from entity!");
|
|
|
- return SqlHelper.saveOrUpdateBatch(this.entityClass, this.log, entityList, batchSize, entity -> {
|
|
|
+ return SqlHelper.executeBatch(this.entityClass, this.log, entityList, batchSize, ((sqlSession, entity) -> {
|
|
|
Object idVal = ReflectionKit.getFieldValue(entity, keyProperty);
|
|
|
- return StringUtils.checkValNull(idVal) || Objects.isNull(getById((Serializable) idVal));
|
|
|
- }, (sqlSession, entity) -> {
|
|
|
- MapperMethod.ParamMap<T> param = new MapperMethod.ParamMap<>();
|
|
|
- param.put(Constants.ENTITY, entity);
|
|
|
- sqlSession.update(tableInfo.getSqlStatement(SqlMethod.UPDATE_BY_ID.getMethod()), param);
|
|
|
- });
|
|
|
+ if (StringUtils.checkValNull(idVal)
|
|
|
+ || CollectionUtils.isEmpty(sqlSession.selectList(tableInfo.getSqlStatement(SqlMethod.SELECT_BY_ID.getMethod()), entity))) {
|
|
|
+ sqlSession.insert(tableInfo.getSqlStatement(SqlMethod.INSERT_ONE.getMethod()), entity);
|
|
|
+ } else {
|
|
|
+ MapperMethod.ParamMap<T> param = new MapperMethod.ParamMap<>();
|
|
|
+ param.put(Constants.ENTITY, entity);
|
|
|
+ sqlSession.update(tableInfo.getSqlStatement(SqlMethod.UPDATE_BY_ID.getMethod()), param);
|
|
|
+ }
|
|
|
+ }));
|
|
|
}
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|