diff --git a/src/main/java/com/gaotao/modules/check/service/impl/PhysicalInventoryServiceImpl.java b/src/main/java/com/gaotao/modules/check/service/impl/PhysicalInventoryServiceImpl.java index e944b9b..978bd3f 100644 --- a/src/main/java/com/gaotao/modules/check/service/impl/PhysicalInventoryServiceImpl.java +++ b/src/main/java/com/gaotao/modules/check/service/impl/PhysicalInventoryServiceImpl.java @@ -49,6 +49,12 @@ public class PhysicalInventoryServiceImpl extends ServiceImpl countLabels) { + if (countLabels == null || countLabels.isEmpty()) { + return; + } + int total = countLabels.size(); + for (int from = 0; from < total; from += BATCH_INSERT_MAX_ROWS) { + int to = Math.min(from + BATCH_INSERT_MAX_ROWS, total); + baseMapper.batchInsertCountLabel(countLabels.subList(from, to)); + log.info("batchInsertCountLabel 分批写入 {}~{}/{} 条 - rqrq", from + 1, to, total); + } + } + + /** + * @Description 分批插入 count_pallet,避免单条 INSERT 参数超过 SQL Server 限制 - rqrq + */ + private void batchInsertCountPalletInChunks(List countPallets) { + if (countPallets == null || countPallets.isEmpty()) { + return; + } + int total = countPallets.size(); + for (int from = 0; from < total; from += BATCH_INSERT_MAX_ROWS) { + int to = Math.min(from + BATCH_INSERT_MAX_ROWS, total); + baseMapper.batchInsertCountPallet(countPallets.subList(from, to)); + log.info("batchInsertCountPallet 分批写入 {}~{}/{} 条 - rqrq", from + 1, to, total); + } + } + + /** + * @Description 分批插入 count_result,避免单条 INSERT 参数超过 SQL Server 限制 - rqrq + */ + private void batchInsertCountResultInChunks(List resultList) { + if (resultList == null || resultList.isEmpty()) { + return; + } + int total = resultList.size(); + for (int from = 0; from < total; from += BATCH_INSERT_MAX_ROWS) { + int to = Math.min(from + BATCH_INSERT_MAX_ROWS, total); + baseMapper.batchInsertCountResult(resultList.subList(from, to)); + log.info("batchInsertCountResult 分批写入 {}~{}/{} 条 - rqrq", from + 1, to, total); + } + } + + /** + * @Description 按 unit_id 列表分批查询 handling_unit,避免 IN 子句参数超过 SQL Server 限制 - rqrq + */ + private List getHandlingUnitsByUnitIdListInChunks(String site, List unitIdList) { + if (unitIdList == null || unitIdList.isEmpty()) { + return Collections.emptyList(); + } + List merged = new ArrayList<>(); + int total = unitIdList.size(); + for (int from = 0; from < total; from += UNIT_ID_IN_CLAUSE_CHUNK_SIZE) { + int to = Math.min(from + UNIT_ID_IN_CLAUSE_CHUNK_SIZE, total); + merged.addAll(baseMapper.getHandlingUnitsByUnitIdList(site, unitIdList.subList(from, to))); + } + log.info("getHandlingUnitsByUnitIdList 分批查询 unitId 数: {} - rqrq", total); + return merged; + } + /** * @Description 创建盘点标签实体 - rqrq * @param site 工厂编码 @@ -1766,7 +1834,7 @@ public class PhysicalInventoryServiceImpl extends ServiceImpl surplusList = new ArrayList<>(surplusUnitIds); - List surplusLabels = baseMapper.getHandlingUnitsByUnitIdList(site, surplusList); + List surplusLabels = getHandlingUnitsByUnitIdListInChunks(site, surplusList); for (CountLabelData surplus : surplusLabels) { CountResult result = new CountResult(); @@ -1823,7 +1891,7 @@ public class PhysicalInventoryServiceImpl extends ServiceImpl - + INSERT INTO count_label (site, count_no, unit_id, part_no, qty, batch_no, location_id, warehouse_id, wdr, pallet_id, label_type, count_flag, created_by, created_date) VALUES @@ -259,7 +259,7 @@ ORDER BY pp.seq_no - + INSERT INTO count_pallet (site, count_no, seq_no, pallet_id, count_flag, label_count, checked_count, location_z, created_by, created_date) VALUES @@ -363,7 +363,7 @@ GETDATE(), #{result.countUser}, #{result.countResult}, #{result.diffQty}, #{result.handleFlag}, #{result.handleType}, #{result.remark}, #{result.createdBy}, GETDATE()) - + INSERT INTO count_result (site, count_no, unit_id, pallet_id, part_no, qty, batch_no, location_id, warehouse_id, wdr, count_date, count_user, count_result, diff_qty, handle_flag, handle_type, remark, created_by, created_date) VALUES @@ -412,7 +412,7 @@ WHERE site = #{site} AND count_no = #{countNo} AND pallet_id = #{palletId} - +