| @@ -52,6 +52,14 @@ interface InventoryLotLineRepository : AbstractRepository<InventoryLotLine, Long | |||||
| AND ill.deleted = false | AND ill.deleted = false | ||||
| """) | """) | ||||
| fun findByLotNoAndItemId(lotNo: String, itemId: Long): InventoryLotLine? | fun findByLotNoAndItemId(lotNo: String, itemId: Long): InventoryLotLine? | ||||
| @Query(""" | |||||
| SELECT DISTINCT ill.inventoryLot.item.id | |||||
| FROM InventoryLotLine ill | |||||
| WHERE ill.deleted = false | |||||
| AND ill.inventoryLot.lotNo = :lotNo | |||||
| """) | |||||
| fun findDistinctItemIdsByLotNo(@Param("lotNo") lotNo: String): List<Long> | |||||
| // InventoryLotLineRepository.kt 中添加 | // InventoryLotLineRepository.kt 中添加 | ||||
| @Query("SELECT ill FROM InventoryLotLine ill WHERE ill.warehouse.id IN :warehouseIds AND ill.deleted = false") | @Query("SELECT ill FROM InventoryLotLine ill WHERE ill.warehouse.id IN :warehouseIds AND ill.deleted = false") | ||||
| fun findAllByWarehouseIdInAndDeletedIsFalse(@Param("warehouseIds") warehouseIds: List<Long>): List<InventoryLotLine> | fun findAllByWarehouseIdInAndDeletedIsFalse(@Param("warehouseIds") warehouseIds: List<Long>): List<InventoryLotLine> | ||||
| @@ -21,6 +21,20 @@ interface InventoryRepository: AbstractRepository<Inventory, Long> { | |||||
| "AND i.deleted = false") | "AND i.deleted = false") | ||||
| fun findInventoryInfoByItemCodeContainsAndItemNameContainsAndItemTypeAndDeletedIsFalse(code: String, name: String, type: String, pageable: Pageable): Page<InventoryInfo> | fun findInventoryInfoByItemCodeContainsAndItemNameContainsAndItemTypeAndDeletedIsFalse(code: String, name: String, type: String, pageable: Pageable): Page<InventoryInfo> | ||||
| @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<Long>, | |||||
| pageable: Pageable | |||||
| ): Page<InventoryInfo> | |||||
| fun findInventoryInfoByItemIdInAndDeletedIsFalse(itemIds: List<Serializable>): List<InventoryInfo> | fun findInventoryInfoByItemIdInAndDeletedIsFalse(itemIds: List<Serializable>): List<InventoryInfo> | ||||
| fun findInventoryInfoByItemInAndDeletedIsFalse(items: List<Items>): List<InventoryInfo> | fun findInventoryInfoByItemInAndDeletedIsFalse(items: List<Items>): List<InventoryInfo> | ||||
| @@ -59,13 +59,28 @@ open class InventoryService( | |||||
| open fun allInventoriesByPage(request: SearchInventoryRequest): RecordsRes<InventoryInfo>{ | open fun allInventoriesByPage(request: SearchInventoryRequest): RecordsRes<InventoryInfo>{ | ||||
| val pageable = PageRequest.of(request.pageNum ?: 0, request.pageSize ?: 10) | 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 records = response.content | ||||
| val total = response.totalElements | val total = response.totalElements | ||||
| @@ -4,6 +4,7 @@ data class SearchInventoryRequest( | |||||
| val code: String, | val code: String, | ||||
| val name: String, | val name: String, | ||||
| val type: String, | val type: String, | ||||
| val lotNo: String? = null, | |||||
| val pageNum: Int?, | val pageNum: Int?, | ||||
| val pageSize: Int? | val pageSize: Int? | ||||
| ) | ) | ||||