diff --git a/src/main/java/com/ffii/fpsms/modules/stock/entity/InventoryLotLineRepository.kt b/src/main/java/com/ffii/fpsms/modules/stock/entity/InventoryLotLineRepository.kt index b5c6711..1ab7b17 100644 --- a/src/main/java/com/ffii/fpsms/modules/stock/entity/InventoryLotLineRepository.kt +++ b/src/main/java/com/ffii/fpsms/modules/stock/entity/InventoryLotLineRepository.kt @@ -52,6 +52,14 @@ interface InventoryLotLineRepository : AbstractRepository // InventoryLotLineRepository.kt 中添加 @Query("SELECT ill FROM InventoryLotLine ill WHERE ill.warehouse.id IN :warehouseIds AND ill.deleted = false") fun findAllByWarehouseIdInAndDeletedIsFalse(@Param("warehouseIds") warehouseIds: List): List diff --git a/src/main/java/com/ffii/fpsms/modules/stock/entity/InventoryRepository.kt b/src/main/java/com/ffii/fpsms/modules/stock/entity/InventoryRepository.kt index 16598df..8b907a8 100644 --- a/src/main/java/com/ffii/fpsms/modules/stock/entity/InventoryRepository.kt +++ b/src/main/java/com/ffii/fpsms/modules/stock/entity/InventoryRepository.kt @@ -21,6 +21,20 @@ interface InventoryRepository: AbstractRepository { "AND i.deleted = false") fun findInventoryInfoByItemCodeContainsAndItemNameContainsAndItemTypeAndDeletedIsFalse(code: String, name: String, type: String, pageable: Pageable): Page + @Query("SELECT i FROM Inventory i " + + "WHERE (:code IS NULL OR i.item.code LIKE CONCAT('%', :code, '%')) " + + "AND (:name IS NULL OR i.item.name LIKE CONCAT('%', :name, '%')) " + + "AND (:type IS NULL OR :type = '' OR i.item.type = :type) " + + "AND i.item.id IN :itemIds " + + "AND i.deleted = false") + fun findInventoryInfoByItemCodeContainsAndItemNameContainsAndItemTypeAndItemIdInAndDeletedIsFalse( + code: String, + name: String, + type: String, + itemIds: List, + pageable: Pageable + ): Page + fun findInventoryInfoByItemIdInAndDeletedIsFalse(itemIds: List): List fun findInventoryInfoByItemInAndDeletedIsFalse(items: List): List diff --git a/src/main/java/com/ffii/fpsms/modules/stock/service/InventoryService.kt b/src/main/java/com/ffii/fpsms/modules/stock/service/InventoryService.kt index 9dd6fcb..84ff44c 100644 --- a/src/main/java/com/ffii/fpsms/modules/stock/service/InventoryService.kt +++ b/src/main/java/com/ffii/fpsms/modules/stock/service/InventoryService.kt @@ -59,13 +59,28 @@ open class InventoryService( open fun allInventoriesByPage(request: SearchInventoryRequest): RecordsRes{ val pageable = PageRequest.of(request.pageNum ?: 0, request.pageSize ?: 10) + val lotNo = request.lotNo?.trim()?.takeIf { it.isNotEmpty() } - val response = inventoryRepository.findInventoryInfoByItemCodeContainsAndItemNameContainsAndItemTypeAndDeletedIsFalse( - code = request.code, - name = request.name, - type = request.type, - pageable = pageable - ) + val response = if (lotNo != null) { + val itemIds = inventoryLotLineRepository.findDistinctItemIdsByLotNo(lotNo) + if (itemIds.isEmpty()) { + return RecordsRes(emptyList(), 0) + } + inventoryRepository.findInventoryInfoByItemCodeContainsAndItemNameContainsAndItemTypeAndItemIdInAndDeletedIsFalse( + code = request.code, + name = request.name, + type = request.type, + itemIds = itemIds, + pageable = pageable + ) + } else { + inventoryRepository.findInventoryInfoByItemCodeContainsAndItemNameContainsAndItemTypeAndDeletedIsFalse( + code = request.code, + name = request.name, + type = request.type, + pageable = pageable + ) + } val records = response.content val total = response.totalElements diff --git a/src/main/java/com/ffii/fpsms/modules/stock/web/model/SearchInventoryRequest.kt b/src/main/java/com/ffii/fpsms/modules/stock/web/model/SearchInventoryRequest.kt index 4f473a6..c40dcb4 100644 --- a/src/main/java/com/ffii/fpsms/modules/stock/web/model/SearchInventoryRequest.kt +++ b/src/main/java/com/ffii/fpsms/modules/stock/web/model/SearchInventoryRequest.kt @@ -4,6 +4,7 @@ data class SearchInventoryRequest( val code: String, val name: String, val type: String, + val lotNo: String? = null, val pageNum: Int?, val pageSize: Int? )