insertIgnoreBatch/replaceBatch改造

pro
wj 2 years ago
parent ed0793f0c2
commit aff2dadc3c

@ -34,7 +34,6 @@ import com.glxp.api.req.sync.SpsSyncDataRequest;
import com.glxp.api.req.sync.SyncUpLoadRequest; import com.glxp.api.req.sync.SyncUpLoadRequest;
import com.glxp.api.res.sync.*; import com.glxp.api.res.sync.*;
import com.glxp.api.service.auth.InvWarehouseService; import com.glxp.api.service.auth.InvWarehouseService;
import com.glxp.api.service.basic.IBasicBusTypeChangeService;
import com.glxp.api.service.basic.IBasicBussinessTypeService; import com.glxp.api.service.basic.IBasicBussinessTypeService;
import com.glxp.api.service.inout.IoAddInoutService; import com.glxp.api.service.inout.IoAddInoutService;
import com.glxp.api.service.inout.IoCheckInoutService; import com.glxp.api.service.inout.IoCheckInoutService;
@ -432,34 +431,34 @@ public class SpsSyncDownloadController {
private void saveUploadSysSettingData(SpsSyncSysSettingResponse bean) { private void saveUploadSysSettingData(SpsSyncSysSettingResponse bean) {
if (CollectionUtil.isNotEmpty(bean.getSystemParamConfigEntities())) { if (CollectionUtil.isNotEmpty(bean.getSystemParamConfigEntities())) {
systemParamConfigDao.replaceBatch(bean.getSystemParamConfigEntities()); systemParamConfigDao.replaceBatchs(bean.getSystemParamConfigEntities());
} }
if (CollectionUtil.isNotEmpty(bean.getEntrustReceEntities())) { if (CollectionUtil.isNotEmpty(bean.getEntrustReceEntities())) {
entrustReceDao.replaceBatch(bean.getEntrustReceEntities()); entrustReceDao.replaceBatchs(bean.getEntrustReceEntities());
} }
if (CollectionUtil.isNotEmpty(bean.getSystemPDFModuleEntities())) { if (CollectionUtil.isNotEmpty(bean.getSystemPDFModuleEntities())) {
systemPDFModuleDao.replaceBatch(bean.getSystemPDFModuleEntities()); systemPDFModuleDao.replaceBatchs(bean.getSystemPDFModuleEntities());
} }
if (CollectionUtil.isNotEmpty(bean.getSystemPDFTemplateEntities())) { if (CollectionUtil.isNotEmpty(bean.getSystemPDFTemplateEntities())) {
systemPDFTemplateDao.replaceBatch(bean.getSystemPDFTemplateEntities()); systemPDFTemplateDao.replaceBatchs(bean.getSystemPDFTemplateEntities());
} }
if (CollectionUtil.isNotEmpty(bean.getSysPdfTemplateRelevanceCodeEntities())) { if (CollectionUtil.isNotEmpty(bean.getSysPdfTemplateRelevanceCodeEntities())) {
sysPdfTemplateRelevanceCodeDao.replaceBatch(bean.getSysPdfTemplateRelevanceCodeEntities()); sysPdfTemplateRelevanceCodeDao.replaceBatchs(bean.getSysPdfTemplateRelevanceCodeEntities());
} }
if (CollectionUtil.isNotEmpty(bean.getSysPdfTemplateRelevanceBizEntities())) { if (CollectionUtil.isNotEmpty(bean.getSysPdfTemplateRelevanceBizEntities())) {
sysPdfTemplateRelevanceBizDao.replaceBatch(bean.getSysPdfTemplateRelevanceBizEntities()); sysPdfTemplateRelevanceBizDao.replaceBatchs(bean.getSysPdfTemplateRelevanceBizEntities());
} }
if (CollectionUtil.isNotEmpty(bean.getSysPdfTemplateRelevanceLabelEntities())) { if (CollectionUtil.isNotEmpty(bean.getSysPdfTemplateRelevanceLabelEntities())) {
sysPdfTemplateRelevanceLabelDao.replaceBatch(bean.getSysPdfTemplateRelevanceLabelEntities()); sysPdfTemplateRelevanceLabelDao.replaceBatchs(bean.getSysPdfTemplateRelevanceLabelEntities());
} }
if (CollectionUtil.isNotEmpty(bean.getSysPdfTemplateRelevanceStatemenEntities())) { if (CollectionUtil.isNotEmpty(bean.getSysPdfTemplateRelevanceStatemenEntities())) {
sysPdfTemplateRelevanceStatemenDao.replaceBatch(bean.getSysPdfTemplateRelevanceStatemenEntities()); sysPdfTemplateRelevanceStatemenDao.replaceBatchs(bean.getSysPdfTemplateRelevanceStatemenEntities());
} }
if (CollectionUtil.isNotEmpty(bean.getBasicBusTypePreEntities())) { if (CollectionUtil.isNotEmpty(bean.getBasicBusTypePreEntities())) {
basicBusTypePreDao.replaceBatch(bean.getBasicBusTypePreEntities()); basicBusTypePreDao.replaceBatchs(bean.getBasicBusTypePreEntities());
} }
if (CollectionUtil.isNotEmpty(bean.getBasicBusTypeChangeEntities())) { if (CollectionUtil.isNotEmpty(bean.getBasicBusTypeChangeEntities())) {
basicBusTypeChangeDao.replaceBatch(bean.getBasicBusTypeChangeEntities()); basicBusTypeChangeDao.replaceBatchs(bean.getBasicBusTypeChangeEntities());
} }
@ -473,44 +472,44 @@ public class SpsSyncDownloadController {
private void saveUploadThrData(SpsSyncThrDataResponse bean) { private void saveUploadThrData(SpsSyncThrDataResponse bean) {
if (CollectionUtil.isNotEmpty(bean.getDeptEntities())) { if (CollectionUtil.isNotEmpty(bean.getDeptEntities())) {
thrDeptDao.replaceBatch(bean.getDeptEntities()); thrDeptDao.replaceBatchs(bean.getDeptEntities());
} }
if (CollectionUtil.isNotEmpty(bean.getInvWarehouseEntities())) { if (CollectionUtil.isNotEmpty(bean.getInvWarehouseEntities())) {
thrInvWarehouseDao.replaceBatch(bean.getInvWarehouseEntities()); thrInvWarehouseDao.replaceBatchs(bean.getInvWarehouseEntities());
} }
if (CollectionUtil.isNotEmpty(bean.getProductsEntityList())) { if (CollectionUtil.isNotEmpty(bean.getProductsEntityList())) {
thrProductsDao.replaceBatch(bean.getProductsEntityList()); thrProductsDao.replaceBatchs(bean.getProductsEntityList());
} }
if (CollectionUtil.isNotEmpty(bean.getCorpEntities())) { if (CollectionUtil.isNotEmpty(bean.getCorpEntities())) {
thrCorpDao.replaceBatch(bean.getCorpEntities()); thrCorpDao.replaceBatchs(bean.getCorpEntities());
} }
} }
private void saveUploadUserData(SpsSyncDataResponse bean) { private void saveUploadUserData(SpsSyncDataResponse bean) {
if (CollectionUtil.isNotEmpty(bean.getAuthAdminList())) { if (CollectionUtil.isNotEmpty(bean.getAuthAdminList())) {
authAdminDao.replaceBatch(bean.getAuthAdminList()); authAdminDao.replaceBatchs(bean.getAuthAdminList());
} }
if (CollectionUtil.isNotEmpty(bean.getDeptEntityList())) { if (CollectionUtil.isNotEmpty(bean.getDeptEntityList())) {
deptDao.replaceBatch(bean.getDeptEntityList()); deptDao.replaceBatchs(bean.getDeptEntityList());
} }
if (CollectionUtil.isNotEmpty(bean.getDeptUserEntities())) { if (CollectionUtil.isNotEmpty(bean.getDeptUserEntities())) {
deptUserDao.replaceBatch(bean.getDeptUserEntities()); deptUserDao.replaceBatchs(bean.getDeptUserEntities());
} }
if (CollectionUtil.isNotEmpty(bean.getInvWarehouseEntities())) { if (CollectionUtil.isNotEmpty(bean.getInvWarehouseEntities())) {
invWarehouseDao.replaceBatch(bean.getInvWarehouseEntities()); invWarehouseDao.replaceBatchs(bean.getInvWarehouseEntities());
} }
if (CollectionUtil.isNotEmpty(bean.getWarehouseUserEntities())) { if (CollectionUtil.isNotEmpty(bean.getWarehouseUserEntities())) {
warehouseUserDao.replaceBatch(bean.getWarehouseUserEntities()); warehouseUserDao.replaceBatchs(bean.getWarehouseUserEntities());
} }
if (CollectionUtil.isNotEmpty(bean.getWarehouseBussinessTypeEntities())) { if (CollectionUtil.isNotEmpty(bean.getWarehouseBussinessTypeEntities())) {
warehouseBussinessTypeDao.replaceBatch(bean.getWarehouseBussinessTypeEntities()); warehouseBussinessTypeDao.replaceBatchs(bean.getWarehouseBussinessTypeEntities());
} }
if (CollectionUtil.isNotEmpty(bean.getInvSpaces())) { if (CollectionUtil.isNotEmpty(bean.getInvSpaces())) {
invSpaceDao.replaceBatch(bean.getInvSpaces()); invSpaceDao.replaceBatchs(bean.getInvSpaces());
} }
if (CollectionUtil.isNotEmpty(bean.getInvBusUserEntities())) { if (CollectionUtil.isNotEmpty(bean.getInvBusUserEntities())) {
invBusUserDao.replaceBatch(bean.getInvBusUserEntities()); invBusUserDao.replaceBatchs(bean.getInvBusUserEntities());
} }
} }
@ -526,13 +525,13 @@ public class SpsSyncDownloadController {
*/ */
private void saveUploadDocumentTypeData(SpsSyncBusResponse bean) { private void saveUploadDocumentTypeData(SpsSyncBusResponse bean) {
if (CollectionUtil.isNotEmpty(bean.getBussinessTypeEntities())) { if (CollectionUtil.isNotEmpty(bean.getBussinessTypeEntities())) {
basicBussinessTypeDao.replaceBatch(bean.getBussinessTypeEntities()); basicBussinessTypeDao.replaceBatchs(bean.getBussinessTypeEntities());
} }
if (CollectionUtil.isNotEmpty(bean.getBusTypeChangeEntities())) { if (CollectionUtil.isNotEmpty(bean.getBusTypeChangeEntities())) {
busTypeChangeDao.replaceBatch(bean.getBusTypeChangeEntities()); busTypeChangeDao.replaceBatchs(bean.getBusTypeChangeEntities());
} }
if (CollectionUtil.isNotEmpty(bean.getThrBusTypeOriginEntities())) { if (CollectionUtil.isNotEmpty(bean.getThrBusTypeOriginEntities())) {
thrBusTypeOriginDao.replaceBatch(bean.getThrBusTypeOriginEntities()); thrBusTypeOriginDao.replaceBatchs(bean.getThrBusTypeOriginEntities());
} }
} }
@ -547,10 +546,10 @@ public class SpsSyncDownloadController {
*/ */
private void saveUploadOtherData(SpsSyncOtherDataResponse bean) { private void saveUploadOtherData(SpsSyncOtherDataResponse bean) {
if (CollectionUtil.isNotEmpty(bean.getIoCodeLostList())) { if (CollectionUtil.isNotEmpty(bean.getIoCodeLostList())) {
ioCodeLostMapper.replaceBatch(bean.getIoCodeLostList()); ioCodeLostMapper.replaceBatchs(bean.getIoCodeLostList());
} }
if (CollectionUtil.isNotEmpty(bean.getIoCodeRelList())) { if (CollectionUtil.isNotEmpty(bean.getIoCodeRelList())) {
ioCodeRelMapper.replaceBatch(bean.getIoCodeRelList()); ioCodeRelMapper.replaceBatchs(bean.getIoCodeRelList());
} }
} }
@ -573,34 +572,34 @@ public class SpsSyncDownloadController {
*/ */
private void saveUploadBasicData(SpsSyncBasicDataResponse bean) { private void saveUploadBasicData(SpsSyncBasicDataResponse bean) {
if (CollectionUtil.isNotEmpty(bean.getHospTypeList())) { if (CollectionUtil.isNotEmpty(bean.getHospTypeList())) {
basicHospTypeDao.replaceBatch(bean.getHospTypeList()); basicHospTypeDao.replaceBatchs(bean.getHospTypeList());
} }
if (CollectionUtil.isNotEmpty(bean.getUdiRelevanceList())) { if (CollectionUtil.isNotEmpty(bean.getUdiRelevanceList())) {
udiRelevanceDao.replaceBatch(bean.getUdiRelevanceList()); udiRelevanceDao.replaceBatchs(bean.getUdiRelevanceList());
} }
if (CollectionUtil.isNotEmpty(bean.getProductsList())) { if (CollectionUtil.isNotEmpty(bean.getProductsList())) {
basicProductsDao.replaceBatch(bean.getProductsList()); basicProductsDao.replaceBatchs(bean.getProductsList());
} }
if (CollectionUtil.isNotEmpty(bean.getRelevanceList())) { if (CollectionUtil.isNotEmpty(bean.getRelevanceList())) {
relevanceDao.replaceBatch(bean.getRelevanceList()); relevanceDao.replaceBatchs(bean.getRelevanceList());
} }
if (CollectionUtil.isNotEmpty(bean.getCorpList())) { if (CollectionUtil.isNotEmpty(bean.getCorpList())) {
corpDao.replaceBatch(bean.getCorpList()); corpDao.replaceBatchs(bean.getCorpList());
} }
if (CollectionUtil.isNotEmpty(bean.getSupCertList())) { if (CollectionUtil.isNotEmpty(bean.getSupCertList())) {
supCertDao.replaceBatch(bean.getSupCertList()); supCertDao.replaceBatchs(bean.getSupCertList());
} }
if (CollectionUtil.isNotEmpty(bean.getSupCertSetList())) { if (CollectionUtil.isNotEmpty(bean.getSupCertSetList())) {
supCertSetDao.replaceBatch(bean.getSupCertSetList()); supCertSetDao.replaceBatchs(bean.getSupCertSetList());
} }
if (CollectionUtil.isNotEmpty(bean.getSupCompanyList())) { if (CollectionUtil.isNotEmpty(bean.getSupCompanyList())) {
supCompanyDao.replaceBatch(bean.getSupCompanyList()); supCompanyDao.replaceBatchs(bean.getSupCompanyList());
} }
if (CollectionUtil.isNotEmpty(bean.getSupManufacturerList())) { if (CollectionUtil.isNotEmpty(bean.getSupManufacturerList())) {
supManufacturerDao.replaceBatch(bean.getSupManufacturerList()); supManufacturerDao.replaceBatchs(bean.getSupManufacturerList());
} }
if (CollectionUtil.isNotEmpty(bean.getSupProductList())) { if (CollectionUtil.isNotEmpty(bean.getSupProductList())) {
supProductDao.replaceBatch(bean.getSupProductList()); supProductDao.replaceBatchs(bean.getSupProductList());
} }
} }

@ -18,10 +18,7 @@ import org.apache.ibatis.logging.Log;
import org.apache.ibatis.logging.LogFactory; import org.apache.ibatis.logging.LogFactory;
import java.io.Serializable; import java.io.Serializable;
import java.util.Collection; import java.util.*;
import java.util.List;
import java.util.Map;
import java.util.Objects;
/** /**
* Mapper , * Mapper ,
@ -82,7 +79,7 @@ public interface BaseMapperPlus<M, T, V> extends BaseMapper<T> {
default boolean insertBatch(Collection<T> entityList, int batchSize) { default boolean insertBatch(Collection<T> entityList, int batchSize) {
String sqlStatement = SqlHelper.getSqlStatement(this.currentMapperClass(), SqlMethod.INSERT_ONE); String sqlStatement = SqlHelper.getSqlStatement(this.currentMapperClass(), SqlMethod.INSERT_ONE);
return SqlHelper.executeBatch(this.currentModelClass(), log, entityList, batchSize, return SqlHelper.executeBatch(this.currentModelClass(), log, entityList, batchSize,
(sqlSession, entity) -> sqlSession.insert(sqlStatement, entity)); (sqlSession, entity) -> sqlSession.insert(sqlStatement, entity));
} }
/** /**
@ -91,11 +88,11 @@ public interface BaseMapperPlus<M, T, V> extends BaseMapper<T> {
default boolean updateBatchById(Collection<T> entityList, int batchSize) { default boolean updateBatchById(Collection<T> entityList, int batchSize) {
String sqlStatement = SqlHelper.getSqlStatement(this.currentMapperClass(), SqlMethod.UPDATE_BY_ID); String sqlStatement = SqlHelper.getSqlStatement(this.currentMapperClass(), SqlMethod.UPDATE_BY_ID);
return SqlHelper.executeBatch(this.currentModelClass(), log, entityList, batchSize, return SqlHelper.executeBatch(this.currentModelClass(), log, entityList, batchSize,
(sqlSession, entity) -> { (sqlSession, entity) -> {
MapperMethod.ParamMap<T> param = new MapperMethod.ParamMap<>(); MapperMethod.ParamMap<T> param = new MapperMethod.ParamMap<>();
param.put(Constants.ENTITY, entity); param.put(Constants.ENTITY, entity);
sqlSession.update(sqlStatement, param); sqlSession.update(sqlStatement, param);
}); });
} }
/** /**
@ -110,7 +107,7 @@ public interface BaseMapperPlus<M, T, V> extends BaseMapper<T> {
Object idVal = tableInfo.getPropertyValue(entity, keyProperty); Object idVal = tableInfo.getPropertyValue(entity, keyProperty);
String sqlStatement = SqlHelper.getSqlStatement(this.currentMapperClass(), SqlMethod.SELECT_BY_ID); String sqlStatement = SqlHelper.getSqlStatement(this.currentMapperClass(), SqlMethod.SELECT_BY_ID);
return StringUtils.checkValNull(idVal) return StringUtils.checkValNull(idVal)
|| CollectionUtils.isEmpty(sqlSession.selectList(sqlStatement, entity)); || CollectionUtils.isEmpty(sqlSession.selectList(sqlStatement, entity));
}, (sqlSession, entity) -> { }, (sqlSession, entity) -> {
MapperMethod.ParamMap<T> param = new MapperMethod.ParamMap<>(); MapperMethod.ParamMap<T> param = new MapperMethod.ParamMap<>();
param.put(Constants.ENTITY, entity); param.put(Constants.ENTITY, entity);
@ -242,8 +239,39 @@ public interface BaseMapperPlus<M, T, V> extends BaseMapper<T> {
* @param entityList * @param entityList
* @return * @return
*/ */
default boolean insertIgnoreBatchs(List<T> entityList) {
return insertIgnoreBatchs(entityList, DEFAULT_BATCH_SIZE);
}
default boolean insertIgnoreBatchs(List<T> entityList, int batchSize) {
try {
int size = entityList.size();
int idxLimit = Math.min(DEFAULT_BATCH_SIZE, size);
int i = 1;
//保存单批提交的数据集合
List<T> oneBatchList = new ArrayList<>();
for (Iterator<T> var7 = entityList.iterator(); var7.hasNext(); ++i) {
T element = var7.next();
oneBatchList.add(element);
if (i == idxLimit) {
this.insertIgnoreBatch(oneBatchList);
//每次提交后需要清空集合数据
oneBatchList.clear();
idxLimit = Math.min(idxLimit + batchSize, size);
}
}
} catch (Exception e) {
log.error("insertIgnoreBatch fail", e);
return false;
}
return true;
}
int insertIgnoreBatch(List<T> entityList); int insertIgnoreBatch(List<T> entityList);
/** /**
* *
* replace intoPrimaryKeyuniqueinsert into * replace intoPrimaryKeyuniqueinsert into
@ -262,6 +290,36 @@ public interface BaseMapperPlus<M, T, V> extends BaseMapper<T> {
* @param entityList * @param entityList
* @return * @return
*/ */
default boolean replaceBatchs(List<T> entityList) {
return this.replaceBatchs(entityList, DEFAULT_BATCH_SIZE);
}
default boolean replaceBatchs(List<T> entityList, int batchSize) {
try {
int size = entityList.size();
int idxLimit = Math.min(DEFAULT_BATCH_SIZE, size);
int i = 1;
//保存单批提交的数据集合
List<T> oneBatchList = new ArrayList<>();
for (Iterator<T> var7 = entityList.iterator(); var7.hasNext(); ++i) {
T element = var7.next();
oneBatchList.add(element);
if (i == idxLimit) {
this.insertIgnoreBatch(oneBatchList);
//每次提交后需要清空集合数据
oneBatchList.clear();
idxLimit = Math.min(idxLimit + batchSize, size);
}
}
} catch (Exception e) {
log.error("insertIgnoreBatch fail", e);
return false;
}
return true;
}
int replaceBatch(List<T> entityList); int replaceBatch(List<T> entityList);
} }

@ -6,7 +6,7 @@ import java.util.List;
public interface CustomService<T> extends IService<T> { public interface CustomService<T> extends IService<T> {
int insertIgnore(T entity); int insertIgnore(T entity);
int insertIgnoreBatch(List<T> entityList); boolean insertIgnoreBatch(List<T> entityList);
int replace(T entity); int replace(T entity);
int replaceBatch(List<T> entityList); boolean replaceBatch(List<T> entityList);
} }

@ -13,8 +13,8 @@ public class CustomServiceImpl<M extends BaseMapper<T>, T> extends ServiceImpl<B
} }
@Override @Override
public int insertIgnoreBatch(List<T> entityList) { public boolean insertIgnoreBatch(List<T> entityList) {
return baseMapper.insertIgnoreBatch(entityList); return baseMapper.insertIgnoreBatchs(entityList);
} }
@Override @Override
@ -23,7 +23,7 @@ public class CustomServiceImpl<M extends BaseMapper<T>, T> extends ServiceImpl<B
} }
@Override @Override
public int replaceBatch(List<T> entityList) { public boolean replaceBatch(List<T> entityList) {
return baseMapper.replaceBatch(entityList); return baseMapper.replaceBatchs(entityList);
} }
} }

Loading…
Cancel
Save