Interface MovimientoInventarioRepository
- All Superinterfaces:
org.springframework.data.repository.CrudRepository<MovimientoInventario,,Long> org.springframework.data.jpa.repository.JpaRepository<MovimientoInventario,,Long> org.springframework.data.repository.ListCrudRepository<MovimientoInventario,,Long> org.springframework.data.repository.ListPagingAndSortingRepository<MovimientoInventario,,Long> org.springframework.data.repository.PagingAndSortingRepository<MovimientoInventario,,Long> org.springframework.data.repository.query.QueryByExampleExecutor<MovimientoInventario>,org.springframework.data.repository.Repository<MovimientoInventario,Long>
public interface MovimientoInventarioRepository
extends org.springframework.data.jpa.repository.JpaRepository<MovimientoInventario,Long>
-
Method Summary
Modifier and TypeMethodDescriptionagruparPorMotivo(LocalDateTime desde, LocalDateTime hasta) Agrupa movimientos por motivo y tipo dentro de un rango temporal, agregando cantidad total y número de incidencias.agruparPorMotivoYTipo(TipoMovimiento tipo, LocalDateTime desde, LocalDateTime hasta) Igual queagruparPorMotivo(LocalDateTime, LocalDateTime)pero filtrando por un tipo concreto.All movements ordered most-recent first.findByFilters(Long insumoId, TipoMovimiento tipo, LocalDateTime desde, LocalDateTime hasta) Filterable audit query for the owner/root history view.findByInsumoIdOrderByFechaHoraDesc(Long insumoId) Returns all movements for batches belonging to a given insumo, sorted most-recent first.findMovimientosSalidaByInsumoAndRango(Long insumoId, LocalDateTime desde, LocalDateTime hasta) Returns the movements that reduce stock (VENTA, MERMA, ROTURA, AJUSTE_NEGATIVO) for a given insumo within the [desde, hasta] window.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
-
findByInsumoIdOrderByFechaHoraDesc
@Query("SELECT m FROM MovimientoInventario m WHERE m.lote.insumo.id = :insumoId ORDER BY m.fechaHora DESC") List<MovimientoInventario> findByInsumoIdOrderByFechaHoraDesc(@Param("insumoId") Long insumoId) Returns all movements for batches belonging to a given insumo, sorted most-recent first.Uses an explicit JPQL query to avoid Spring Data's derived-query ambiguity between "Lote" + "insumoId" vs "LoteInsumo" + "Id".
-
findAllByOrderByFechaHoraDesc
List<MovimientoInventario> findAllByOrderByFechaHoraDesc()All movements ordered most-recent first. -
findByFilters
@Query("SELECT m FROM MovimientoInventario m WHERE (:insumoId IS NULL OR m.lote.insumo.id = :insumoId) AND (:tipo IS NULL OR m.tipoMovimiento = :tipo) AND (:desde IS NULL OR m.fechaHora >= :desde) AND (:hasta IS NULL OR m.fechaHora <= :hasta) ORDER BY m.fechaHora DESC") List<MovimientoInventario> findByFilters(@Param("insumoId") Long insumoId, @Param("tipo") TipoMovimiento tipo, @Param("desde") LocalDateTime desde, @Param("hasta") LocalDateTime hasta) Filterable audit query for the owner/root history view.All parameters are optional (pass
nullto skip each filter):insumoId– restrict to batches of a specific insumo.tipo– restrict to a specific movement type.desde– lower bound onfechaHora(inclusive).hasta– upper bound onfechaHora(inclusive).
-
findMovimientosSalidaByInsumoAndRango
@Query("SELECT m FROM MovimientoInventario m WHERE m.lote.insumo.id = :insumoId AND m.tipoMovimiento IN ( com.deusto.coffeestack.domain.TipoMovimiento.VENTA, com.deusto.coffeestack.domain.TipoMovimiento.MERMA, com.deusto.coffeestack.domain.TipoMovimiento.ROTURA, com.deusto.coffeestack.domain.TipoMovimiento.AJUSTE_NEGATIVO) AND m.fechaHora BETWEEN :desde AND :hasta") List<MovimientoInventario> findMovimientosSalidaByInsumoAndRango(@Param("insumoId") Long insumoId, @Param("desde") LocalDateTime desde, @Param("hasta") LocalDateTime hasta) Returns the movements that reduce stock (VENTA, MERMA, ROTURA, AJUSTE_NEGATIVO) for a given insumo within the [desde, hasta] window.Used to compute average daily consumption without loading the full movement history into memory.
-
agruparPorMotivo
@Query("SELECT new com.deusto.coffeestack.dto.ReporteMotivoResponse( m.motivo, m.tipoMovimiento, COUNT(m), SUM(m.cantidad), MIN(m.fechaHora), MAX(m.fechaHora)) FROM MovimientoInventario m WHERE m.fechaHora BETWEEN :desde AND :hasta GROUP BY m.motivo, m.tipoMovimiento ORDER BY SUM(m.cantidad) DESC") List<ReporteMotivoResponse> agruparPorMotivo(@Param("desde") LocalDateTime desde, @Param("hasta") LocalDateTime hasta) Agrupa movimientos por motivo y tipo dentro de un rango temporal, agregando cantidad total y número de incidencias. Sin filtro de tipo.Se ofrece como variante separada (vs. una única consulta con
:tipo IS NULL) porque PostgreSQL no puede inferir el tipo de un parámetro JDBC cuando solo aparece comparado contraNULL, y devuelve "could not determine data type of parameter". -
agruparPorMotivoYTipo
@Query("SELECT new com.deusto.coffeestack.dto.ReporteMotivoResponse( m.motivo, m.tipoMovimiento, COUNT(m), SUM(m.cantidad), MIN(m.fechaHora), MAX(m.fechaHora)) FROM MovimientoInventario m WHERE m.tipoMovimiento = :tipo AND m.fechaHora BETWEEN :desde AND :hasta GROUP BY m.motivo, m.tipoMovimiento ORDER BY SUM(m.cantidad) DESC") List<ReporteMotivoResponse> agruparPorMotivoYTipo(@Param("tipo") TipoMovimiento tipo, @Param("desde") LocalDateTime desde, @Param("hasta") LocalDateTime hasta) Igual queagruparPorMotivo(LocalDateTime, LocalDateTime)pero filtrando por un tipo concreto.
-