Browse Source

盘点纠错

master
常熟吴彦祖 3 weeks ago
parent
commit
a9f424e86b
  1. 88
      src/main/java/com/gaotao/modules/check/service/impl/PhysicalInventoryServiceImpl.java
  2. 8
      src/main/resources/mapper/check/PhysicalInventoryMapper.xml

88
src/main/java/com/gaotao/modules/check/service/impl/PhysicalInventoryServiceImpl.java

@ -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());
}

8
src/main/resources/mapper/check/PhysicalInventoryMapper.xml

@ -197,7 +197,7 @@
ORDER BY l.pallet_id, l.unit_id
</select>
<!-- rqrq - 批量插入盘点标签 -->
<!-- rqrq - 批量插入盘点标签(单批行数由 PhysicalInventoryServiceImpl 按 100 条分批调用,避免超 2100 参数) -->
<insert id="batchInsertCountLabel">
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
</select>
<!-- rqrq - 批量插入盘点栈板 -->
<!-- rqrq - 批量插入盘点栈板(行数由 Service 按 BATCH_INSERT_MAX_ROWS 分批) -->
<insert id="batchInsertCountPallet">
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>
<!-- rqrq - 批量插入盘点结果(包含diff_qty、handle_flag、handle_type字段)-->
<!-- rqrq - 批量插入盘点结果(行数由 Service 按 BATCH_INSERT_MAX_ROWS 分批) -->
<insert id="batchInsertCountResult">
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}
</update>
<!-- rqrq - 根据标签号列表查询handling_unit信息 -->
<!-- rqrq - 根据标签号列表查询handling_unit(列表过长时由 Service 按 UNIT_ID_IN_CLAUSE_CHUNK_SIZE 分批) -->
<select id="getHandlingUnitsByUnitIdList" resultType="CountLabelData">
SELECT
h.site,

Loading…
Cancel
Save