package com.qianwen.core.mp.service.impl;
|
|
import com.baomidou.mybatisplus.extension.toolkit.SqlHelper;
|
import java.util.Collection;
|
import com.qianwen.core.mp.base.BaseEntity;
|
import com.qianwen.core.mp.base.BaseServiceImpl;
|
import com.qianwen.core.mp.injector.BladeSqlMethod;
|
import com.qianwen.core.mp.mapper.BladeMapper;
|
import com.qianwen.core.mp.service.BladeService;
|
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.validation.annotation.Validated;
|
|
@Validated
|
public class BladeServiceImpl<M extends BladeMapper<T>, T extends BaseEntity> extends BaseServiceImpl<M, T> implements BladeService<T> {
|
|
|
public boolean saveIgnore(T entity) {
|
return SqlHelper.retBool(Integer.valueOf(((BladeMapper) this.baseMapper).insertIgnore(entity)));
|
}
|
|
public boolean saveReplace(T entity) {
|
return SqlHelper.retBool(Integer.valueOf(((BladeMapper) this.baseMapper).replace(entity)));
|
}
|
|
@Override
|
@Transactional(rollbackFor = {Exception.class})
|
public boolean saveIgnoreBatch(Collection<T> entityList, int batchSize) {
|
return saveBatch(entityList, batchSize, BladeSqlMethod.INSERT_IGNORE_ONE);
|
}
|
|
@Override
|
@Transactional(rollbackFor = {Exception.class})
|
public boolean saveReplaceBatch(Collection<T> entityList, int batchSize) {
|
return saveBatch(entityList, batchSize, BladeSqlMethod.REPLACE_ONE);
|
}
|
|
private boolean saveBatch(Collection<T> entityList, int batchSize, BladeSqlMethod sqlMethod) {
|
String sqlStatement = bladeSqlStatement(sqlMethod);
|
|
executeBatch(entityList, batchSize, (sqlSession, entity) -> sqlSession.insert(sqlStatement, entity));
|
|
return true;
|
}
|
|
protected String bladeSqlStatement(BladeSqlMethod sqlMethod) {
|
return SqlHelper.table(currentModelClass()).getSqlStatement(sqlMethod.getMethod());
|
}
|
}
|