@Override
public List FindByUsuario(int idSeguridadUsuario) {
Date start = fourDaysLater3pm();
Date end = nextDay11Am();
Query query = em.createQuery("select object(o)
from OrdenProduccionRegistros as o
where o.idSeguridadUsuario.idSeguridadUsuario='" + idSeguridadUsuario + "'
and o.fecha BETWEEN :start AND :end
ORDER BY o.fecha, o.idOrdenProduccionRegistros DESC")
.setParameter("start", start, TemporalType.DATE)
.setParameter("end", end, TemporalType.DATE);
query.setMaxResult(10);
return query.getResultList();
}
@SuppressWarnings("unused")
private Date nextDay11Am() {
Calendar t = (Calendar) today().clone();
t.set(Calendar.AM_PM, Calendar.AM);
t.set(Calendar.DATE, t.get(Calendar.DATE) + 1);
t.set(Calendar.HOUR, 11);
return t.getTime();
}
@SuppressWarnings("unused")
private Date fourDaysLater3pm() {
Calendar t = (Calendar) today().clone();
t.set(Calendar.AM_PM, Calendar.PM);
t.set(Calendar.DATE, t.get(Calendar.DATE) + 4);
t.set(Calendar.HOUR, 3);
return t.getTime();
}
private Calendar today() {
Calendar calendar = Calendar.getInstance();
calendar.set(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DATE), 0, 0, 0);
return calendar;
}