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>

public interface LoteRepository extends org.springframework.data.jpa.repository.JpaRepository<Lote,Long>
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
     
    findByInsumoId(Long insumoId)
    Returns all batches for a given insumo, ordered by expiry date ascending (nulls last).
    Used for sales to prevent race conditions when decrementing stock
    double
    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, save

    Methods inherited from interface org.springframework.data.jpa.repository.JpaRepository

    deleteAllByIdInBatch, deleteAllInBatch, deleteAllInBatch, deleteInBatch, findAll, findAll, flush, getById, getOne, getReferenceById, saveAllAndFlush, saveAndFlush

    Methods inherited from interface org.springframework.data.repository.ListCrudRepository

    findAll, findAllById, saveAll

    Methods inherited from interface org.springframework.data.repository.ListPagingAndSortingRepository

    findAll

    Methods inherited from interface org.springframework.data.repository.PagingAndSortingRepository

    findAll

    Methods 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

      boolean existsByProveedorId(Long proveedorId)