diff --git a/src/main/java/com/ffii/fpsms/modules/stock/service/StockTakeRecordService.kt b/src/main/java/com/ffii/fpsms/modules/stock/service/StockTakeRecordService.kt index cc2bcd6..9d492fe 100644 --- a/src/main/java/com/ffii/fpsms/modules/stock/service/StockTakeRecordService.kt +++ b/src/main/java/com/ffii/fpsms/modules/stock/service/StockTakeRecordService.kt @@ -1496,7 +1496,7 @@ open fun batchSaveApproverStockTakeRecordsAll( val roundStockTakeIds: Set = resolveRoundStockTakeIds(stockTake) - val stockTakeRecords = stockTakeRecordRepository.findAll() + var stockTakeRecords = stockTakeRecordRepository.findAll() .filter { !it.deleted && it.stockTake?.id != null && @@ -1505,7 +1505,57 @@ open fun batchSaveApproverStockTakeRecordsAll( (it.pickerFirstStockTakeQty != null || it.pickerSecondStockTakeQty != null) && it.approverStockTakeQty == null } + val sectionParts = request.stockTakeSections + ?.split(",") + ?.map { it.trim() } + ?.filter { it.isNotEmpty() } + .orEmpty() + + if (sectionParts.isNotEmpty()) { + stockTakeRecords = stockTakeRecords.filter { r -> + val sec = r.stockTakeSection ?: "" + sectionParts.any { part -> sec.equals(part, ignoreCase = true) || sec.contains(part, ignoreCase = true) } + } + } + val sectionDesc = request.sectionDescription?.trim() + if (!sectionDesc.isNullOrBlank() && sectionDesc != "All") { + stockTakeRecords = stockTakeRecords.filter { r -> + r.warehouse?.stockTakeSectionDescription?.equals(sectionDesc, ignoreCase = true) == true + } + } + val whParts = request.warehouseKeyword + ?.split(",") + ?.map { it.trim() } + ?.filter { it.isNotEmpty() } + .orEmpty() +if (whParts.isNotEmpty()) { + stockTakeRecords = stockTakeRecords.filter { r -> + val code = r.warehouse?.code ?: "" + whParts.any { part -> code.contains(part, ignoreCase = true) } + } +} +val itemParts = request.itemKeyword + ?.split(",") + ?.map { it.trim() } + ?.filter { it.isNotEmpty() } + .orEmpty() + +if (itemParts.isNotEmpty()) { + val allowedItemIds = itemParts + .flatMap { kw -> itemsRepository.findIdsByCodeOrNameContains(kw) } + .distinct() + .toSet() + + + if (allowedItemIds.isEmpty()) { + return BatchSaveApproverStockTakeRecordResponse(0, 0, listOf("No items found matching itemKeyword")) + } + stockTakeRecords = stockTakeRecords.filter { r -> + val itemId = r.itemId + itemId != null && allowedItemIds.contains(itemId) + } +} println("Found ${stockTakeRecords.size} records to process for round (all sections)") if (stockTakeRecords.isEmpty()) { @@ -1535,26 +1585,7 @@ open fun batchSaveApproverStockTakeRecordsAll( val bookQty = record.bookQty ?: BigDecimal.ZERO val varianceQty = qty.subtract(bookQty) - val tolerancePercent = request.variancePercentTolerance ?: BigDecimal.ZERO - val shouldSkip = if (tolerancePercent.compareTo(BigDecimal.ZERO) <= 0) { - // 0 或负数表示不过滤差异:所有已盘点记录都参与批量保存 - false - } else { - if (bookQty.compareTo(BigDecimal.ZERO) == 0) { - varianceQty.compareTo(BigDecimal.ZERO) != 0 - } else { - val threshold = bookQty.abs() - .multiply(tolerancePercent) - .divide(BigDecimal("100"), 10, RoundingMode.HALF_UP) - varianceQty.abs().compareTo(threshold) > 0 - } - } - if (shouldSkip) { - skippedCount++ - println("Skipping record ${record.id}: |variance| > ${tolerancePercent}% of bookQty (variance=$varianceQty, bookQty=$bookQty)") - return@forEach - } - + record.apply { this.approverId = request.approverId this.approverName = user?.name diff --git a/src/main/java/com/ffii/fpsms/modules/stock/web/model/StockTakeRecordReponse.kt b/src/main/java/com/ffii/fpsms/modules/stock/web/model/StockTakeRecordReponse.kt index 6ca8588..9ce611c 100644 --- a/src/main/java/com/ffii/fpsms/modules/stock/web/model/StockTakeRecordReponse.kt +++ b/src/main/java/com/ffii/fpsms/modules/stock/web/model/StockTakeRecordReponse.kt @@ -114,7 +114,11 @@ data class BatchSaveApproverStockTakeRecordRequest( data class BatchSaveApproverStockTakeAllRequest( val stockTakeId: Long, val approverId: Long, - val variancePercentTolerance: BigDecimal? = null, + //val variancePercentTolerance: BigDecimal? = null, + val itemKeyword: String? = null, + val warehouseKeyword: String? = null, + val sectionDescription: String? = null, + val stockTakeSections: String? = null, ) data class BatchSaveApproverStockTakeRecordResponse(