|
|
|
@ -49,6 +49,12 @@ public class PhysicalInventoryServiceImpl extends ServiceImpl<PhysicalInventoryM |
|
|
|
@Autowired |
|
|
|
private WcsApiService wcsApiService; // rqrq - 注入WCS接口服务 |
|
|
|
|
|
|
|
/** 多行 VALUES 批量插入每批最大行数(count_label/count_pallet/count_result),避免 SQL Server 2100 参数上限 - rqrq */ |
|
|
|
private static final int BATCH_INSERT_MAX_ROWS = 100; |
|
|
|
|
|
|
|
/** unit_id IN 列表分批大小(每 id 一个参数,另含 site 等,宜小于 2100)- rqrq */ |
|
|
|
private static final int UNIT_ID_IN_CLAUSE_CHUNK_SIZE = 2000; |
|
|
|
|
|
|
|
// ==================== 盘点主表 ==================== |
|
|
|
|
|
|
|
@Override |
|
|
|
@ -285,7 +291,7 @@ public class PhysicalInventoryServiceImpl extends ServiceImpl<PhysicalInventoryM |
|
|
|
} |
|
|
|
|
|
|
|
if (!countLabels.isEmpty()) { |
|
|
|
baseMapper.batchInsertCountLabel(countLabels); |
|
|
|
batchInsertCountLabelInChunks(countLabels); |
|
|
|
} |
|
|
|
|
|
|
|
// 12. 创建盘点栈板子表 - rqrq |
|
|
|
@ -318,7 +324,7 @@ public class PhysicalInventoryServiceImpl extends ServiceImpl<PhysicalInventoryM |
|
|
|
} |
|
|
|
|
|
|
|
if (!countPallets.isEmpty()) { |
|
|
|
baseMapper.batchInsertCountPallet(countPallets); |
|
|
|
batchInsertCountPalletInChunks(countPallets); |
|
|
|
} |
|
|
|
|
|
|
|
log.info("createCycleCount 结束,盘点单号: {}", countNo); |
|
|
|
@ -517,7 +523,7 @@ public class PhysicalInventoryServiceImpl extends ServiceImpl<PhysicalInventoryM |
|
|
|
} |
|
|
|
|
|
|
|
if (!countLabels.isEmpty()) { |
|
|
|
baseMapper.batchInsertCountLabel(countLabels); |
|
|
|
batchInsertCountLabelInChunks(countLabels); |
|
|
|
} |
|
|
|
|
|
|
|
// 7. 创建/更新盘点栈板子表 - rqrq |
|
|
|
@ -563,7 +569,7 @@ public class PhysicalInventoryServiceImpl extends ServiceImpl<PhysicalInventoryM |
|
|
|
} |
|
|
|
|
|
|
|
if (!countPallets.isEmpty()) { |
|
|
|
baseMapper.batchInsertCountPallet(countPallets); |
|
|
|
batchInsertCountPalletInChunks(countPallets); |
|
|
|
} |
|
|
|
|
|
|
|
log.info("addMaterialToCount 结束,新增标签数: {}", countLabels.size()); |
|
|
|
@ -643,7 +649,7 @@ public class PhysicalInventoryServiceImpl extends ServiceImpl<PhysicalInventoryM |
|
|
|
} |
|
|
|
|
|
|
|
if (!countLabels.isEmpty()) { |
|
|
|
baseMapper.batchInsertCountLabel(countLabels); |
|
|
|
batchInsertCountLabelInChunks(countLabels); |
|
|
|
} |
|
|
|
|
|
|
|
// 8. 创建/更新盘点栈板子表 - rqrq |
|
|
|
@ -682,7 +688,7 @@ public class PhysicalInventoryServiceImpl extends ServiceImpl<PhysicalInventoryM |
|
|
|
} |
|
|
|
|
|
|
|
if (!countPallets.isEmpty()) { |
|
|
|
baseMapper.batchInsertCountPallet(countPallets); |
|
|
|
batchInsertCountPalletInChunks(countPallets); |
|
|
|
} |
|
|
|
|
|
|
|
log.info("quickAddMaterialByPartNo 结束,新增标签数: {}", countLabels.size()); |
|
|
|
@ -1628,6 +1634,68 @@ public class PhysicalInventoryServiceImpl extends ServiceImpl<PhysicalInventoryM |
|
|
|
.orElse(null); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @Description 分批插入 count_label,每批最多 100 行(BATCH_INSERT_MAX_ROWS)- rqrq |
|
|
|
*/ |
|
|
|
private void batchInsertCountLabelInChunks(List<CountLabel> 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<CountPallet> 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<CountResult> 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<CountLabelData> getHandlingUnitsByUnitIdListInChunks(String site, List<String> unitIdList) { |
|
|
|
if (unitIdList == null || unitIdList.isEmpty()) { |
|
|
|
return Collections.emptyList(); |
|
|
|
} |
|
|
|
List<CountLabelData> 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<PhysicalInventoryM |
|
|
|
if (!surplusUnitIds.isEmpty()) { |
|
|
|
// 查询多盘标签的详细信息 - rqrq |
|
|
|
List<String> surplusList = new ArrayList<>(surplusUnitIds); |
|
|
|
List<CountLabelData> surplusLabels = baseMapper.getHandlingUnitsByUnitIdList(site, surplusList); |
|
|
|
List<CountLabelData> surplusLabels = getHandlingUnitsByUnitIdListInChunks(site, surplusList); |
|
|
|
|
|
|
|
for (CountLabelData surplus : surplusLabels) { |
|
|
|
CountResult result = new CountResult(); |
|
|
|
@ -1823,7 +1891,7 @@ public class PhysicalInventoryServiceImpl extends ServiceImpl<PhysicalInventoryM |
|
|
|
|
|
|
|
// 6. 批量写入盘点结果 - rqrq |
|
|
|
if (!resultList.isEmpty()) { |
|
|
|
baseMapper.batchInsertCountResult(resultList); |
|
|
|
batchInsertCountResultInChunks(resultList); |
|
|
|
log.info("写入盘点结果数量: {}", resultList.size()); |
|
|
|
} |
|
|
|
|
|
|
|
@ -2168,7 +2236,7 @@ public class PhysicalInventoryServiceImpl extends ServiceImpl<PhysicalInventoryM |
|
|
|
} |
|
|
|
|
|
|
|
if (!resultList.isEmpty()) { |
|
|
|
baseMapper.batchInsertCountResult(resultList); |
|
|
|
batchInsertCountResultInChunks(resultList); |
|
|
|
log.info("已插入盘点结果,数量: {}", resultList.size()); |
|
|
|
} |
|
|
|
|
|
|
|
@ -2296,7 +2364,7 @@ public class PhysicalInventoryServiceImpl extends ServiceImpl<PhysicalInventoryM |
|
|
|
} |
|
|
|
|
|
|
|
if (!resultList.isEmpty()) { |
|
|
|
baseMapper.batchInsertCountResult(resultList); |
|
|
|
batchInsertCountResultInChunks(resultList); |
|
|
|
log.info("已插入盘点结果,数量: {}", resultList.size()); |
|
|
|
} |
|
|
|
|
|
|
|
|