- validação para não gerar corridas q não tenham tramo_servicio
git-svn-id: http://desenvolvimento.rjconsultores.com.br/repositorio/sco/AdmVenta/Model/trunk/modelWeb@27917 d1611594-4594-4d17-8e1d-87c2c4800839master
parent
b713ca3fe8
commit
fc2f3e7d1c
|
@ -34,4 +34,12 @@ public interface TramoServicioDAO extends GenericDAO<TramoServicio, Integer> {
|
|||
* @return
|
||||
*/
|
||||
public TramoServicio buscar(Parada origen,Parada destino,Via via,ClaseServicio clase);
|
||||
|
||||
/**
|
||||
* Indica si existen tiempos para los trechos del esquemaCorrida. O sea, debe de haber para cada tramo del esquema un tramoServicio válido
|
||||
*
|
||||
* @param esquemaCorridaId
|
||||
* @return
|
||||
*/
|
||||
public boolean existenTiemposTramosEsquema(Integer esquemaCorridaId);
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.rjconsultores.ventaboletos.dao.hibernate;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
|
||||
public class HibernateFix {
|
||||
|
@ -24,6 +25,8 @@ public class HibernateFix {
|
|||
|
||||
if (resultado instanceof Integer) {
|
||||
cant = Long.valueOf(((Integer) resultado).longValue());
|
||||
} else if (resultado instanceof BigDecimal){
|
||||
cant= ((BigDecimal)resultado).longValue();
|
||||
} else {
|
||||
cant = (Long) resultado;
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ package com.rjconsultores.ventaboletos.dao.hibernate;
|
|||
import java.util.List;
|
||||
|
||||
import org.hibernate.Criteria;
|
||||
import org.hibernate.FetchMode;
|
||||
import org.hibernate.Query;
|
||||
import org.hibernate.SessionFactory;
|
||||
import org.hibernate.criterion.Restrictions;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
@ -16,6 +16,7 @@ import org.springframework.stereotype.Repository;
|
|||
|
||||
import com.rjconsultores.ventaboletos.dao.TramoServicioDAO;
|
||||
import com.rjconsultores.ventaboletos.entidad.ClaseServicio;
|
||||
import com.rjconsultores.ventaboletos.entidad.EsquemaTramo;
|
||||
import com.rjconsultores.ventaboletos.entidad.Parada;
|
||||
import com.rjconsultores.ventaboletos.entidad.Tramo;
|
||||
import com.rjconsultores.ventaboletos.entidad.TramoServicio;
|
||||
|
@ -62,8 +63,34 @@ public class TramoServicioHibernateDAO extends GenericHibernateDAO<TramoServicio
|
|||
cTramo.add(Restrictions.eq("via", via));
|
||||
cTramo.add(Restrictions.eq("activo", Boolean.TRUE));
|
||||
c.add(Restrictions.eq("claseServicio", clase));
|
||||
|
||||
|
||||
return (TramoServicio) c.uniqueResult();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean existenTiemposTramosEsquema(Integer esquemaCorridaId) {
|
||||
|
||||
Query query = getSession().createQuery("select count(*) from EsquemaTramo ct where ct.activo = 1 and ct.esquemaCorrida.esquemacorridaId = :esquemaCorrida");
|
||||
query.setParameter("esquemaCorrida", esquemaCorridaId);
|
||||
Long cantTramos = HibernateFix.count(query.uniqueResult());
|
||||
|
||||
StringBuilder sb = new StringBuilder("");
|
||||
sb.append("select count(*) ");
|
||||
sb.append("from ");
|
||||
sb.append("esquema_corrida ec ");
|
||||
sb.append("inner join esquema_tramo et on et.esquemacorrida_id = ec.esquemacorrida_id ");
|
||||
sb.append("inner join tramo_servicio ts on ts.tramo_id = et.tramo_id and ts.CLASESERVICIO_ID = ec.CLASESERVICIO_ID ");
|
||||
sb.append("where ");
|
||||
sb.append("et.activo = 1 ");
|
||||
sb.append("and ts.activo = 1 ");
|
||||
sb.append("and ec.esquemacorrida_id = :esquemaCorrida");
|
||||
|
||||
Query query2 = getSession().createSQLQuery(sb.toString());
|
||||
query2.setParameter("esquemaCorrida", esquemaCorridaId);
|
||||
|
||||
Long cantTramosTiempos = HibernateFix.count(query2.uniqueResult());
|
||||
|
||||
return cantTramos.equals(cantTramosTiempos);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -359,7 +359,7 @@ public class EsquemaCorrida implements Serializable {
|
|||
List<EsquemaTramo> esquemaList = new ArrayList<EsquemaTramo>();
|
||||
|
||||
for (EsquemaTramo ec : this.esquemaTramoList) {
|
||||
if (ec.getActivo() == Boolean.TRUE) {
|
||||
if (ec.getActivo()) {
|
||||
esquemaList.add(ec);
|
||||
}
|
||||
}
|
||||
|
@ -376,7 +376,7 @@ public class EsquemaCorrida implements Serializable {
|
|||
public List<EsquemaAsiento> getEsquemaAsientoList() {
|
||||
List<EsquemaAsiento> esquemaList = new ArrayList<EsquemaAsiento>();
|
||||
for (EsquemaAsiento ec : this.esquemaAsientoList) {
|
||||
if (ec.getActivo() == Boolean.TRUE) {
|
||||
if (ec.getActivo()) {
|
||||
esquemaList.add(ec);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ import java.math.BigDecimal;
|
|||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import com.rjconsultores.ventaboletos.dao.TramoServicioDAO;
|
||||
import com.rjconsultores.ventaboletos.entidad.ClaseServicio;
|
||||
import com.rjconsultores.ventaboletos.entidad.Parada;
|
||||
import com.rjconsultores.ventaboletos.entidad.Tramo;
|
||||
|
@ -51,4 +52,12 @@ public interface TramoServicioService extends GenericService<TramoServicio, Inte
|
|||
* @return - Si el tramo existe, return FALSE. Sino, retorna TRUE
|
||||
*/
|
||||
public boolean generarTramoTiempo(Parada origen, Parada destino, Via via, BigDecimal kmsReal, Date tiempoRecorrido, ClaseServicio claseServicio);
|
||||
|
||||
/**
|
||||
* {@link TramoServicioDAO#existenTiemposTramosEsquema(Integer)}
|
||||
*
|
||||
* @param esquemaCorridaId
|
||||
* @return
|
||||
*/
|
||||
public boolean existenTiemposTramosEsquema(Integer esquemaCorridaId);
|
||||
}
|
||||
|
|
|
@ -355,7 +355,7 @@ public class CorridaServiceImpl implements CorridaService {
|
|||
}
|
||||
|
||||
/**
|
||||
* Genera una corrida para el esquemaCorrida informado en el dia y fecha informados.<br/>
|
||||
* Genera una corrida para el esquemaCorrida informado en la fecha informada.<br/>
|
||||
*
|
||||
* Cuando la corrida no es generada : <br/>
|
||||
* - corrida ya existe : eso es checado por el numCorrida e dataGeneracion <br/>
|
||||
|
@ -376,22 +376,29 @@ public class CorridaServiceImpl implements CorridaService {
|
|||
Corrida corrida = null;
|
||||
|
||||
if (!vigenciaValida(esquemaCorrida, dataGeracao)) {
|
||||
log.debug("vigencia invalida=" + dataGeracao);
|
||||
log.info("vigencia invalida=" + dataGeracao);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!((esquemaCorrida.getStatusCorrida() != null) && (esquemaCorrida.getStatusCorrida().equals("A")))) {
|
||||
log.debug("status corrida invalido=" + esquemaCorrida.getStatusCorrida());
|
||||
log.info("status corrida invalido=" + esquemaCorrida.getStatusCorrida());
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!temCorridaDiaSemana(diaSemana, esquemaCorrida, isFeriado)) {
|
||||
log.debug("dia semana no valido=" + diaSemana);
|
||||
log.info("dia semana no valido=" + diaSemana);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!tramoServicioService.existenTiemposTramosEsquema(esquemaCorrida.getEsquemacorridaId())){
|
||||
log.info("nao foi cadastrado o tempo de todos os trechos do esquema corrida=" + esquemaCorrida.getEsquemacorridaId());
|
||||
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
try {
|
||||
Ruta ruta = esquemaCorrida.getRuta();
|
||||
|
|
|
@ -120,4 +120,9 @@ public class TramoServicioServiceImpl implements TramoServicioService {
|
|||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean existenTiemposTramosEsquema(Integer esquemaCorridaId) {
|
||||
return tramoServicioDAO.existenTiemposTramosEsquema(esquemaCorridaId);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue