diff --git a/src/main/java/com/glxp/api/controller/sync/SpsSyncDownloadController.java b/src/main/java/com/glxp/api/controller/sync/SpsSyncDownloadController.java index 6409a716..8a286df5 100644 --- a/src/main/java/com/glxp/api/controller/sync/SpsSyncDownloadController.java +++ b/src/main/java/com/glxp/api/controller/sync/SpsSyncDownloadController.java @@ -34,7 +34,6 @@ import com.glxp.api.req.sync.SpsSyncDataRequest; import com.glxp.api.req.sync.SyncUpLoadRequest; import com.glxp.api.res.sync.*; 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.inout.IoAddInoutService; import com.glxp.api.service.inout.IoCheckInoutService; @@ -432,34 +431,34 @@ public class SpsSyncDownloadController { private void saveUploadSysSettingData(SpsSyncSysSettingResponse bean) { if (CollectionUtil.isNotEmpty(bean.getSystemParamConfigEntities())) { - systemParamConfigDao.replaceBatch(bean.getSystemParamConfigEntities()); + systemParamConfigDao.replaceBatchs(bean.getSystemParamConfigEntities()); } if (CollectionUtil.isNotEmpty(bean.getEntrustReceEntities())) { - entrustReceDao.replaceBatch(bean.getEntrustReceEntities()); + entrustReceDao.replaceBatchs(bean.getEntrustReceEntities()); } if (CollectionUtil.isNotEmpty(bean.getSystemPDFModuleEntities())) { - systemPDFModuleDao.replaceBatch(bean.getSystemPDFModuleEntities()); + systemPDFModuleDao.replaceBatchs(bean.getSystemPDFModuleEntities()); } if (CollectionUtil.isNotEmpty(bean.getSystemPDFTemplateEntities())) { - systemPDFTemplateDao.replaceBatch(bean.getSystemPDFTemplateEntities()); + systemPDFTemplateDao.replaceBatchs(bean.getSystemPDFTemplateEntities()); } if (CollectionUtil.isNotEmpty(bean.getSysPdfTemplateRelevanceCodeEntities())) { - sysPdfTemplateRelevanceCodeDao.replaceBatch(bean.getSysPdfTemplateRelevanceCodeEntities()); + sysPdfTemplateRelevanceCodeDao.replaceBatchs(bean.getSysPdfTemplateRelevanceCodeEntities()); } if (CollectionUtil.isNotEmpty(bean.getSysPdfTemplateRelevanceBizEntities())) { - sysPdfTemplateRelevanceBizDao.replaceBatch(bean.getSysPdfTemplateRelevanceBizEntities()); + sysPdfTemplateRelevanceBizDao.replaceBatchs(bean.getSysPdfTemplateRelevanceBizEntities()); } if (CollectionUtil.isNotEmpty(bean.getSysPdfTemplateRelevanceLabelEntities())) { - sysPdfTemplateRelevanceLabelDao.replaceBatch(bean.getSysPdfTemplateRelevanceLabelEntities()); + sysPdfTemplateRelevanceLabelDao.replaceBatchs(bean.getSysPdfTemplateRelevanceLabelEntities()); } if (CollectionUtil.isNotEmpty(bean.getSysPdfTemplateRelevanceStatemenEntities())) { - sysPdfTemplateRelevanceStatemenDao.replaceBatch(bean.getSysPdfTemplateRelevanceStatemenEntities()); + sysPdfTemplateRelevanceStatemenDao.replaceBatchs(bean.getSysPdfTemplateRelevanceStatemenEntities()); } if (CollectionUtil.isNotEmpty(bean.getBasicBusTypePreEntities())) { - basicBusTypePreDao.replaceBatch(bean.getBasicBusTypePreEntities()); + basicBusTypePreDao.replaceBatchs(bean.getBasicBusTypePreEntities()); } 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) { if (CollectionUtil.isNotEmpty(bean.getDeptEntities())) { - thrDeptDao.replaceBatch(bean.getDeptEntities()); + thrDeptDao.replaceBatchs(bean.getDeptEntities()); } if (CollectionUtil.isNotEmpty(bean.getInvWarehouseEntities())) { - thrInvWarehouseDao.replaceBatch(bean.getInvWarehouseEntities()); + thrInvWarehouseDao.replaceBatchs(bean.getInvWarehouseEntities()); } if (CollectionUtil.isNotEmpty(bean.getProductsEntityList())) { - thrProductsDao.replaceBatch(bean.getProductsEntityList()); + thrProductsDao.replaceBatchs(bean.getProductsEntityList()); } if (CollectionUtil.isNotEmpty(bean.getCorpEntities())) { - thrCorpDao.replaceBatch(bean.getCorpEntities()); + thrCorpDao.replaceBatchs(bean.getCorpEntities()); } } private void saveUploadUserData(SpsSyncDataResponse bean) { if (CollectionUtil.isNotEmpty(bean.getAuthAdminList())) { - authAdminDao.replaceBatch(bean.getAuthAdminList()); + authAdminDao.replaceBatchs(bean.getAuthAdminList()); } if (CollectionUtil.isNotEmpty(bean.getDeptEntityList())) { - deptDao.replaceBatch(bean.getDeptEntityList()); + deptDao.replaceBatchs(bean.getDeptEntityList()); } if (CollectionUtil.isNotEmpty(bean.getDeptUserEntities())) { - deptUserDao.replaceBatch(bean.getDeptUserEntities()); + deptUserDao.replaceBatchs(bean.getDeptUserEntities()); } if (CollectionUtil.isNotEmpty(bean.getInvWarehouseEntities())) { - invWarehouseDao.replaceBatch(bean.getInvWarehouseEntities()); + invWarehouseDao.replaceBatchs(bean.getInvWarehouseEntities()); } if (CollectionUtil.isNotEmpty(bean.getWarehouseUserEntities())) { - warehouseUserDao.replaceBatch(bean.getWarehouseUserEntities()); + warehouseUserDao.replaceBatchs(bean.getWarehouseUserEntities()); } if (CollectionUtil.isNotEmpty(bean.getWarehouseBussinessTypeEntities())) { - warehouseBussinessTypeDao.replaceBatch(bean.getWarehouseBussinessTypeEntities()); + warehouseBussinessTypeDao.replaceBatchs(bean.getWarehouseBussinessTypeEntities()); } if (CollectionUtil.isNotEmpty(bean.getInvSpaces())) { - invSpaceDao.replaceBatch(bean.getInvSpaces()); + invSpaceDao.replaceBatchs(bean.getInvSpaces()); } 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) { if (CollectionUtil.isNotEmpty(bean.getBussinessTypeEntities())) { - basicBussinessTypeDao.replaceBatch(bean.getBussinessTypeEntities()); + basicBussinessTypeDao.replaceBatchs(bean.getBussinessTypeEntities()); } if (CollectionUtil.isNotEmpty(bean.getBusTypeChangeEntities())) { - busTypeChangeDao.replaceBatch(bean.getBusTypeChangeEntities()); + busTypeChangeDao.replaceBatchs(bean.getBusTypeChangeEntities()); } 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) { if (CollectionUtil.isNotEmpty(bean.getIoCodeLostList())) { - ioCodeLostMapper.replaceBatch(bean.getIoCodeLostList()); + ioCodeLostMapper.replaceBatchs(bean.getIoCodeLostList()); } 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) { if (CollectionUtil.isNotEmpty(bean.getHospTypeList())) { - basicHospTypeDao.replaceBatch(bean.getHospTypeList()); + basicHospTypeDao.replaceBatchs(bean.getHospTypeList()); } if (CollectionUtil.isNotEmpty(bean.getUdiRelevanceList())) { - udiRelevanceDao.replaceBatch(bean.getUdiRelevanceList()); + udiRelevanceDao.replaceBatchs(bean.getUdiRelevanceList()); } if (CollectionUtil.isNotEmpty(bean.getProductsList())) { - basicProductsDao.replaceBatch(bean.getProductsList()); + basicProductsDao.replaceBatchs(bean.getProductsList()); } if (CollectionUtil.isNotEmpty(bean.getRelevanceList())) { - relevanceDao.replaceBatch(bean.getRelevanceList()); + relevanceDao.replaceBatchs(bean.getRelevanceList()); } if (CollectionUtil.isNotEmpty(bean.getCorpList())) { - corpDao.replaceBatch(bean.getCorpList()); + corpDao.replaceBatchs(bean.getCorpList()); } if (CollectionUtil.isNotEmpty(bean.getSupCertList())) { - supCertDao.replaceBatch(bean.getSupCertList()); + supCertDao.replaceBatchs(bean.getSupCertList()); } if (CollectionUtil.isNotEmpty(bean.getSupCertSetList())) { - supCertSetDao.replaceBatch(bean.getSupCertSetList()); + supCertSetDao.replaceBatchs(bean.getSupCertSetList()); } if (CollectionUtil.isNotEmpty(bean.getSupCompanyList())) { - supCompanyDao.replaceBatch(bean.getSupCompanyList()); + supCompanyDao.replaceBatchs(bean.getSupCompanyList()); } if (CollectionUtil.isNotEmpty(bean.getSupManufacturerList())) { - supManufacturerDao.replaceBatch(bean.getSupManufacturerList()); + supManufacturerDao.replaceBatchs(bean.getSupManufacturerList()); } if (CollectionUtil.isNotEmpty(bean.getSupProductList())) { - supProductDao.replaceBatch(bean.getSupProductList()); + supProductDao.replaceBatchs(bean.getSupProductList()); } } diff --git a/src/main/java/com/glxp/api/dao/BaseMapperPlus.java b/src/main/java/com/glxp/api/dao/BaseMapperPlus.java index 0a4da8b0..77ce77ec 100644 --- a/src/main/java/com/glxp/api/dao/BaseMapperPlus.java +++ b/src/main/java/com/glxp/api/dao/BaseMapperPlus.java @@ -18,10 +18,7 @@ import org.apache.ibatis.logging.Log; import org.apache.ibatis.logging.LogFactory; import java.io.Serializable; -import java.util.Collection; -import java.util.List; -import java.util.Map; -import java.util.Objects; +import java.util.*; /** * 自定义 Mapper 接口, 实现 自定义扩展 @@ -82,7 +79,7 @@ public interface BaseMapperPlus extends BaseMapper { default boolean insertBatch(Collection entityList, int batchSize) { String sqlStatement = SqlHelper.getSqlStatement(this.currentMapperClass(), SqlMethod.INSERT_ONE); 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 extends BaseMapper { default boolean updateBatchById(Collection entityList, int batchSize) { String sqlStatement = SqlHelper.getSqlStatement(this.currentMapperClass(), SqlMethod.UPDATE_BY_ID); return SqlHelper.executeBatch(this.currentModelClass(), log, entityList, batchSize, - (sqlSession, entity) -> { - MapperMethod.ParamMap param = new MapperMethod.ParamMap<>(); - param.put(Constants.ENTITY, entity); - sqlSession.update(sqlStatement, param); - }); + (sqlSession, entity) -> { + MapperMethod.ParamMap param = new MapperMethod.ParamMap<>(); + param.put(Constants.ENTITY, entity); + sqlSession.update(sqlStatement, param); + }); } /** @@ -110,7 +107,7 @@ public interface BaseMapperPlus extends BaseMapper { Object idVal = tableInfo.getPropertyValue(entity, keyProperty); String sqlStatement = SqlHelper.getSqlStatement(this.currentMapperClass(), SqlMethod.SELECT_BY_ID); return StringUtils.checkValNull(idVal) - || CollectionUtils.isEmpty(sqlSession.selectList(sqlStatement, entity)); + || CollectionUtils.isEmpty(sqlSession.selectList(sqlStatement, entity)); }, (sqlSession, entity) -> { MapperMethod.ParamMap param = new MapperMethod.ParamMap<>(); param.put(Constants.ENTITY, entity); @@ -242,8 +239,39 @@ public interface BaseMapperPlus extends BaseMapper { * @param entityList 实体类列表 * @return 影响条数 */ + default boolean insertIgnoreBatchs(List entityList) { + return insertIgnoreBatchs(entityList, DEFAULT_BATCH_SIZE); + } + + default boolean insertIgnoreBatchs(List entityList, int batchSize) { + + try { + int size = entityList.size(); + int idxLimit = Math.min(DEFAULT_BATCH_SIZE, size); + int i = 1; + //保存单批提交的数据集合 + List oneBatchList = new ArrayList<>(); + for (Iterator 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 entityList); + /** * 替换数据 * replace into表示插入替换数据,需求表中有PrimaryKey,或者unique索引,如果数据库已经存在数据,则用新数据替换,如果没有数据效果则和insert into一样; @@ -262,6 +290,36 @@ public interface BaseMapperPlus extends BaseMapper { * @param entityList 实体类列表 * @return 影响条数 */ + default boolean replaceBatchs(List entityList) { + return this.replaceBatchs(entityList, DEFAULT_BATCH_SIZE); + } + + default boolean replaceBatchs(List entityList, int batchSize) { + + try { + int size = entityList.size(); + int idxLimit = Math.min(DEFAULT_BATCH_SIZE, size); + int i = 1; + //保存单批提交的数据集合 + List oneBatchList = new ArrayList<>(); + for (Iterator 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 entityList); } diff --git a/src/main/java/com/glxp/api/service/CustomService.java b/src/main/java/com/glxp/api/service/CustomService.java index 6f5771ca..f7e0cfe2 100644 --- a/src/main/java/com/glxp/api/service/CustomService.java +++ b/src/main/java/com/glxp/api/service/CustomService.java @@ -6,7 +6,7 @@ import java.util.List; public interface CustomService extends IService { int insertIgnore(T entity); - int insertIgnoreBatch(List entityList); + boolean insertIgnoreBatch(List entityList); int replace(T entity); - int replaceBatch(List entityList); + boolean replaceBatch(List entityList); } diff --git a/src/main/java/com/glxp/api/service/CustomServiceImpl.java b/src/main/java/com/glxp/api/service/CustomServiceImpl.java index fbe97193..e180c905 100644 --- a/src/main/java/com/glxp/api/service/CustomServiceImpl.java +++ b/src/main/java/com/glxp/api/service/CustomServiceImpl.java @@ -13,8 +13,8 @@ public class CustomServiceImpl, T> extends ServiceImpl entityList) { - return baseMapper.insertIgnoreBatch(entityList); + public boolean insertIgnoreBatch(List entityList) { + return baseMapper.insertIgnoreBatchs(entityList); } @Override @@ -23,7 +23,7 @@ public class CustomServiceImpl, T> extends ServiceImpl entityList) { - return baseMapper.replaceBatch(entityList); + public boolean replaceBatch(List entityList) { + return baseMapper.replaceBatchs(entityList); } }