mirror of
https://git.imnavajas.es/jjimenez/erp-imprimelibros.git
synced 2026-02-08 11:59:13 +00:00
24 lines
899 B
Java
24 lines
899 B
Java
package com.imprimelibros.erp.pedidos;
|
|
|
|
import java.time.Instant;
|
|
|
|
import org.springframework.data.jpa.repository.JpaRepository;
|
|
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
|
import org.springframework.data.jpa.repository.Query;
|
|
import org.springframework.data.repository.query.Param;
|
|
import org.springframework.stereotype.Repository;
|
|
|
|
@Repository
|
|
public interface PedidoRepository extends JpaRepository<Pedido, Long>, JpaSpecificationExecutor<Pedido> {
|
|
|
|
// Suma de "total" para un "createdBy" desde una fecha dada
|
|
@Query("""
|
|
SELECT COALESCE(SUM(p.total), 0)
|
|
FROM Pedido p
|
|
WHERE p.createdBy.id = :userId
|
|
AND p.createdAt >= :afterDate
|
|
""")
|
|
Double sumTotalByCreatedByAndCreatedAtAfter(@Param("userId") Long userId,
|
|
@Param("afterDate") Instant afterDate);
|
|
}
|