Java tutorial
/* * Copyright (C) 2016 Dominion Global * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ package com.dominion.salud.pedicom.negocio.repositories.impl; import com.dominion.salud.pedicom.negocio.entities.LinParInt; import com.dominion.salud.pedicom.negocio.entities.Pedidos; import com.dominion.salud.pedicom.negocio.repositories.LinParIntRepository; import java.text.ParseException; import java.util.Date; import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; import javax.persistence.EntityManager; import javax.persistence.PersistenceContext; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.time.DateUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Repository; /** * * @author jcgonzalez */ @Repository("pedidosRepository") public class PedidosRepositoryImpl { @PersistenceContext(unitName = "MainEM") private EntityManager entityManager; @Autowired private LinParIntRepository linParIntRepository; public List<Pedidos> findTransN() { String initDate = "01/01/2016"; Date date = null; List<LinParInt> list = linParIntRepository.getModulos(); for (LinParInt lin : list) { if (lin.getLinParIntPK().getTipo().equals("MIN_FECHA_ENVIO")) { initDate = StringUtils.trim(lin.getParametro()); } } try { date = DateUtils.parseDate(initDate, "dd/MM/yyyy"); } catch (ParseException ex) { } return entityManager.createQuery( "from Pedidos where (transferido = 'N' or transferido = null or transferido ='T') and (estado = 'S') and fechaPedido > :fecha order by centros.linea, proveedor.codigo", Pedidos.class).setParameter("fecha", date).getResultList(); } public List<Pedidos> findTransNCentro(Pedidos ped) { int dias = 30; List<LinParInt> list = linParIntRepository.getModulos(); for (LinParInt lin : list) { if (lin.getLinParIntPK().getTipo().equals("LISTADO_DIAS")) { dias = Integer.parseInt(StringUtils.trim(lin.getParametro())); } } return entityManager .createQuery("from Pedidos where centros.linea = :centroid and fechaPedido > :fecha", Pedidos.class) .setParameter("fecha", DateUtils.addDays(new Date(), -dias)) .setParameter("centroid", ped.getCentros().getLinea()).getResultList(); } public Pedidos findOnePedido(Pedidos ped) { return entityManager .createQuery( "from Pedidos where pedidosPK.numPedido = :numpedido and pedidosPK.codCentro = :centroid", Pedidos.class) .setParameter("numpedido", ped.getPedidosPK().getNumPedido()) .setParameter("centroid", ped.getPedidosPK().getCodCentro()).getSingleResult(); } }