| @@ -53,7 +53,6 @@ interface InventoryLotLineRepository : AbstractRepository<InventoryLotLine, Long | |||
| """) | |||
| fun findByLotNoAndItemId(lotNo: String, itemId: Long): InventoryLotLine? | |||
| <<<<<<< HEAD | |||
| @Query(""" | |||
| SELECT DISTINCT ill.inventoryLot.item.id | |||
| FROM InventoryLotLine ill | |||
| @@ -61,41 +60,42 @@ interface InventoryLotLineRepository : AbstractRepository<InventoryLotLine, Long | |||
| AND ill.inventoryLot.lotNo = :lotNo | |||
| """) | |||
| fun findDistinctItemIdsByLotNo(@Param("lotNo") lotNo: String): List<Long> | |||
| ======= | |||
| // lotNo + itemId may not be unique (multiple warehouses/lines); pick one deterministically | |||
| fun findFirstByInventoryLotLotNoAndInventoryLotItemIdAndDeletedFalseOrderByIdDesc( | |||
| lotNo: String, | |||
| itemId: Long | |||
| ): InventoryLotLine? | |||
| >>>>>>> 9760717ed6a5c59383467921464fb2b89a7f85a8 | |||
| // InventoryLotLineRepository.kt 中添加 | |||
| @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> | |||
| @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> | |||
| @Query(""" | |||
| @Query(""" | |||
| SELECT ill FROM InventoryLotLine ill | |||
| WHERE ill.warehouse.code = :warehouseCode | |||
| AND ill.deleted = false | |||
| ORDER BY ill.inventoryLot.item.code, ill.inventoryLot.lotNo | |||
| """) | |||
| fun findAllByWarehouseCodeAndDeletedIsFalse(@Param("warehouseCode") warehouseCode: String): List<InventoryLotLine> | |||
| @Query(""" | |||
| fun findAllByWarehouseCodeAndDeletedIsFalse(@Param("warehouseCode") warehouseCode: String): List<InventoryLotLine> | |||
| @Query(""" | |||
| SELECT COUNT(DISTINCT ill.inventoryLot.item.id) | |||
| FROM InventoryLotLine ill | |||
| WHERE ill.warehouse.id IN :warehouseIds | |||
| AND ill.deleted = false | |||
| """) | |||
| fun countDistinctItemsByWarehouseIds(@Param("warehouseIds") warehouseIds: List<Long>): Long | |||
| fun countDistinctItemsByWarehouseIds(@Param("warehouseIds") warehouseIds: List<Long>): Long | |||
| @Query(""" | |||
| @Query(""" | |||
| SELECT COUNT(ill.id) | |||
| FROM InventoryLotLine ill | |||
| WHERE ill.warehouse.id IN :warehouseIds | |||
| AND ill.deleted = false | |||
| """) | |||
| fun countAllByWarehouseIds(@Param("warehouseIds") warehouseIds: List<Long>): Long | |||
| fun countAllByWarehouseIds(@Param("warehouseIds") warehouseIds: List<Long>): Long | |||
| @Query(""" | |||
| @Query(""" | |||
| SELECT ill FROM InventoryLotLine ill | |||
| JOIN ill.inventoryLot il | |||
| WHERE il.expiryDate < :today | |||
| @@ -103,7 +103,7 @@ fun countAllByWarehouseIds(@Param("warehouseIds") warehouseIds: List<Long>): Lon | |||
| AND ill.deleted = false | |||
| ORDER BY il.expiryDate ASC | |||
| """) | |||
| fun findExpiredItems(@Param("today") today: LocalDate): List<InventoryLotLine> | |||
| fun findExpiredItems(@Param("today") today: LocalDate): List<InventoryLotLine> | |||
| @Query(""" | |||
| SELECT ill FROM InventoryLotLine ill | |||
| @@ -131,7 +131,7 @@ fun findExpiredItems(@Param("today") today: LocalDate): List<InventoryLotLine> | |||
| AND il.stockInLine IS NOT NULL | |||
| ORDER BY w.store_id, il.item.code, il.lotNo | |||
| """) | |||
| fun findAllByStoreIdsAndHasStockInLine( | |||
| @Param("storeIds") storeIds: List<String> | |||
| ): List<InventoryLotLine> | |||
| fun findAllByStoreIdsAndHasStockInLine( | |||
| @Param("storeIds") storeIds: List<String> | |||
| ): List<InventoryLotLine> | |||
| } | |||