Interface LoteRepository
- All Superinterfaces:
org.springframework.data.repository.CrudRepository<Lote,,Long> org.springframework.data.jpa.repository.JpaRepository<Lote,,Long> org.springframework.data.repository.ListCrudRepository<Lote,,Long> org.springframework.data.repository.ListPagingAndSortingRepository<Lote,,Long> org.springframework.data.repository.PagingAndSortingRepository<Lote,,Long> org.springframework.data.repository.query.QueryByExampleExecutor<Lote>,org.springframework.data.repository.Repository<Lote,Long>
-
Method Summary
Modifier and TypeMethodDescriptionbooleanexistsByProveedorId(Long proveedorId) findByInsumoId(Long insumoId) Returns all batches for a given insumo, ordered by expiry date ascending (nulls last).findByInsumoIdForUpdate(Long insumoId) Used for sales to prevent race conditions when decrementing stockdoublesumCantidadActualByInsumoId(Long insumoId) Sums the current quantity across all batches for an insumo.Methods inherited from interface org.springframework.data.repository.CrudRepository
count, delete, deleteAll, deleteAll, deleteAllById, deleteById, existsById, findById, saveMethods inherited from interface org.springframework.data.jpa.repository.JpaRepository
deleteAllByIdInBatch, deleteAllInBatch, deleteAllInBatch, deleteInBatch, findAll, findAll, flush, getById, getOne, getReferenceById, saveAllAndFlush, saveAndFlushMethods inherited from interface org.springframework.data.repository.ListCrudRepository
findAll, findAllById, saveAllMethods inherited from interface org.springframework.data.repository.ListPagingAndSortingRepository
findAllMethods inherited from interface org.springframework.data.repository.PagingAndSortingRepository
findAllMethods inherited from interface org.springframework.data.repository.query.QueryByExampleExecutor
count, exists, findAll, findBy, findOne
-
Method Details
-
findByInsumoId
@Query("SELECT l FROM Lote l WHERE l.insumo.id = :insumoId ORDER BY l.fechaVencimiento ASC NULLS LAST") List<Lote> findByInsumoId(@Param("insumoId") Long insumoId) Returns all batches for a given insumo, ordered by expiry date ascending (nulls last). -
findByInsumoIdForUpdate
@Lock(PESSIMISTIC_WRITE) @Query("SELECT l FROM Lote l WHERE l.insumo.id = :insumoId ORDER BY l.fechaVencimiento ASC NULLS LAST") List<Lote> findByInsumoIdForUpdate(@Param("insumoId") Long insumoId) Used for sales to prevent race conditions when decrementing stock -
sumCantidadActualByInsumoId
@Query("SELECT COALESCE(SUM(l.cantidadActual), 0.0) FROM Lote l WHERE l.insumo.id = :insumoId") double sumCantidadActualByInsumoId(@Param("insumoId") Long insumoId) Sums the current quantity across all batches for an insumo. Returns 0.0 if no batches exist. -
existsByProveedorId
-