|
|
|
@@ -471,4 +471,97 @@ open class InventorySetup { |
|
|
|
errorMessage = null |
|
|
|
) |
|
|
|
} |
|
|
|
@Transactional(rollbackFor = [Exception::class]) |
|
|
|
open fun printLotStockInLabelsByStoreIdsV1( |
|
|
|
printerId: Long, |
|
|
|
storeIds: List<String>, |
|
|
|
printQty: Int = 1, |
|
|
|
fromIndex: Int? = null, |
|
|
|
toIndex: Int? = null |
|
|
|
): PrintProgressResult { |
|
|
|
|
|
|
|
if (storeIds.isEmpty()) { |
|
|
|
return PrintProgressResult( |
|
|
|
success = false, |
|
|
|
lastIndex = -1, |
|
|
|
totalLots = 0, |
|
|
|
errorMessage = "storeIds is empty" |
|
|
|
) |
|
|
|
} |
|
|
|
|
|
|
|
// 1. 查出对应 store_id 的 lot line |
|
|
|
val allInventoryLotLines = inventoryLotLineRepository |
|
|
|
.findAllByStoreIdsAndHasStockInLine(storeIds) |
|
|
|
|
|
|
|
if (allInventoryLotLines.isEmpty()) { |
|
|
|
return PrintProgressResult( |
|
|
|
success = false, |
|
|
|
lastIndex = -1, |
|
|
|
totalLots = 0, |
|
|
|
errorMessage = "no lots found for given storeIds" |
|
|
|
) |
|
|
|
} |
|
|
|
|
|
|
|
val effectiveTotal = allInventoryLotLines.size |
|
|
|
|
|
|
|
// 2. 计算要打印的 index 范围 |
|
|
|
val startIndex = (fromIndex ?: 0).coerceAtLeast(0) |
|
|
|
val endIndex = (toIndex ?: (effectiveTotal - 1)).coerceAtMost(effectiveTotal - 1) |
|
|
|
|
|
|
|
if (startIndex > endIndex || startIndex >= effectiveTotal) { |
|
|
|
return PrintProgressResult( |
|
|
|
success = false, |
|
|
|
lastIndex = startIndex - 1, |
|
|
|
totalLots = effectiveTotal, |
|
|
|
errorMessage = "invalid index range" |
|
|
|
) |
|
|
|
} |
|
|
|
|
|
|
|
var lastIndex = startIndex - 1 |
|
|
|
|
|
|
|
// 3. 逐张打印,遇到打印机错误就立即返回,支持断点续打 |
|
|
|
for (globalIndex in startIndex..endIndex) { |
|
|
|
val inventoryLotLine = allInventoryLotLines[globalIndex] |
|
|
|
val stockInLineId = inventoryLotLine.inventoryLot?.stockInLine?.id |
|
|
|
?: return PrintProgressResult( |
|
|
|
success = false, |
|
|
|
lastIndex = lastIndex, |
|
|
|
totalLots = effectiveTotal, |
|
|
|
errorMessage = "Stock in line missing for inventoryLotLineId=${inventoryLotLine.id}" |
|
|
|
) |
|
|
|
|
|
|
|
try { |
|
|
|
stockInLineService.printQrCode( |
|
|
|
PrintQrCodeForSilRequest( |
|
|
|
stockInLineId = stockInLineId, |
|
|
|
printerId = printerId, |
|
|
|
printQty = printQty |
|
|
|
) |
|
|
|
) |
|
|
|
lastIndex = globalIndex |
|
|
|
} catch (e: Exception) { |
|
|
|
val msg = when { |
|
|
|
e.message?.contains("paper", ignoreCase = true) == true -> |
|
|
|
"Printer error (maybe out of paper): ${e.message}" |
|
|
|
else -> |
|
|
|
"Printer error: ${e.message}" |
|
|
|
} |
|
|
|
|
|
|
|
return PrintProgressResult( |
|
|
|
success = false, |
|
|
|
lastIndex = lastIndex, |
|
|
|
totalLots = effectiveTotal, |
|
|
|
errorMessage = msg |
|
|
|
) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// 全部打印成功 |
|
|
|
return PrintProgressResult( |
|
|
|
success = true, |
|
|
|
lastIndex = lastIndex, |
|
|
|
totalLots = effectiveTotal, |
|
|
|
errorMessage = null |
|
|
|
) |
|
|
|
} |
|
|
|
} |