git-svn-id: http://desenvolvimento.rjconsultores.com.br/repositorio/sco/AdmVenta/Model/trunk/modelWeb@31582 d1611594-4594-4d17-8e1d-87c2c4800839
parent
0df4b6ee64
commit
8f6bc4cdec
|
@ -523,6 +523,10 @@ public class CorridaServiceImpl implements CorridaService {
|
|||
List<EsquemaTramo> lsEsquemaTramo = esquemaTramoService.obtenerPorEsquemaCorridaOrderNumSec(esquemaCorrida);
|
||||
Date horaChegadaAnterior = null;
|
||||
Date tiempoInstanciaAnterior = null; // indica o tempo de instancia que fica no tramo anterior ao atual
|
||||
|
||||
|
||||
Date husoHorVeranoLlegadaAnterior = null;
|
||||
|
||||
for (EsquemaTramo esquemaTramo : lsEsquemaTramo) {
|
||||
CorridaTramo corridaTramo = new CorridaTramo();
|
||||
corridaTramo.setAutobus(null);
|
||||
|
@ -579,7 +583,21 @@ public class CorridaServiceImpl implements CorridaService {
|
|||
}
|
||||
corridaTramo.setCorrida(corrida);
|
||||
corridaTramo.setFechorSalidaOriginal(fecHorSalida);
|
||||
|
||||
|
||||
if (husoHorVeranoLlegadaAnterior == null){
|
||||
corridaTramo.setFechorsalidaH(corridaTramo.getFechorsalida());
|
||||
}else{
|
||||
corridaTramo.setFechorsalidaH(husoHorVeranoLlegadaAnterior);
|
||||
}
|
||||
|
||||
husoHorVeranoLlegadaAnterior = calcularHusoHorVeranoLlegada(esquemaTramo, corridaTramo);
|
||||
|
||||
if (husoHorVeranoLlegadaAnterior != null){
|
||||
corridaTramo.setFechorllegadaH(husoHorVeranoLlegadaAnterior);
|
||||
}else{
|
||||
corridaTramo.setFechorllegadaH(corridaTramo.getFechorllegada());
|
||||
}
|
||||
|
||||
lsCorridaTramo.add(corridaTramo);
|
||||
}
|
||||
corrida.setCorridaTramoList(lsCorridaTramo);
|
||||
|
@ -595,8 +613,6 @@ public class CorridaServiceImpl implements CorridaService {
|
|||
|
||||
corrida = corridaDAO.suscribir(corrida);
|
||||
|
||||
corridaDAO.actualizaFecHusoFecVerano(corrida);
|
||||
|
||||
cantCorridaGenerada++;
|
||||
|
||||
List<EsquemaAsiento> lsEsquemaAsiento = esquemaAsientoService.obtenerPorCorrida(esquemaCorrida);
|
||||
|
@ -631,6 +647,71 @@ public class CorridaServiceImpl implements CorridaService {
|
|||
return corrida;
|
||||
}
|
||||
|
||||
private Date calcularHusoHorVeranoLlegada(EsquemaTramo esquemaTramo, CorridaTramo corridaTramo) {
|
||||
|
||||
Estado estadoOrigen = esquemaTramo.getTramo().getOrigem().getCiudad().getEstado();
|
||||
int tiempoOrigen = estadoOrigen.getTiempoHorHuso() == null ? 0 : estadoOrigen.getTiempoHorHuso();
|
||||
|
||||
Date fecInicioHorVerano = estadoOrigen.getFecInicioHorVerano();
|
||||
Date fecFinHorVerano = estadoOrigen.getFecFinoHorVerano();
|
||||
|
||||
if ((fecInicioHorVerano != null) && (fecFinHorVerano != null)) {
|
||||
if ((DateUtil.compareOnlyDate(fecInicioHorVerano, corridaTramo.getFechorsalida()) <= 0) && (DateUtil.compareOnlyDate(fecFinHorVerano, corridaTramo.getFechorsalida()) >= 0)) {
|
||||
tiempoOrigen += estadoOrigen.getTiempoHorVerano();
|
||||
}
|
||||
}
|
||||
|
||||
Estado estadoDestino = esquemaTramo.getTramo().getDestino().getCiudad().getEstado();
|
||||
int tiempoDestino = 0;
|
||||
|
||||
if (!estadoDestino.equals(estadoOrigen)) {
|
||||
tiempoDestino = estadoDestino.getTiempoHorHuso() == null ? 0 : estadoDestino.getTiempoHorHuso();
|
||||
|
||||
Date fecInicioHorVeranoDestino = estadoDestino.getFecInicioHorVerano();
|
||||
Date fecFinHorVeranDestino = estadoDestino.getFecFinoHorVerano();
|
||||
|
||||
if ((fecInicioHorVeranoDestino != null) && (fecFinHorVeranDestino != null)) {
|
||||
if ((DateUtil.compareOnlyDate(fecInicioHorVeranoDestino, corridaTramo.getFechorllegada()) <= 0) && (DateUtil.compareOnlyDate(fecFinHorVeranDestino, corridaTramo.getFechorllegada()) >= 0)) {
|
||||
tiempoDestino += estadoDestino.getTiempoHorVerano();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
tiempoDestino = tiempoOrigen;
|
||||
}
|
||||
|
||||
Calendar horLlegada = null;
|
||||
// Si los tiempos son distintos, hube cambio de huso horario/horario de verano
|
||||
if (tiempoOrigen != tiempoDestino) {
|
||||
long elapsedHoras = DateUtil.getElapsedHoras(corridaTramo.getFechorsalida(),corridaTramo.getFechorllegada());
|
||||
|
||||
horLlegada = Calendar.getInstance();
|
||||
horLlegada.setTime(corridaTramo.getFechorsalidaH());
|
||||
|
||||
horLlegada.add(Calendar.HOUR, (int)elapsedHoras);
|
||||
horLlegada.add(Calendar.HOUR, difHuso(tiempoOrigen,tiempoDestino));
|
||||
|
||||
}
|
||||
|
||||
return (horLlegada == null) ? null : horLlegada.getTime();
|
||||
}
|
||||
private int difHuso(int a,int b){
|
||||
int mult=0;
|
||||
|
||||
if ( (a < b) && (b<=0) ){
|
||||
mult = -1;
|
||||
}else if ( (a<b) && (a>=0) ){
|
||||
mult = -1;
|
||||
}else if (a> b){
|
||||
mult = -1;
|
||||
}else{
|
||||
mult = 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
return ((Math.abs(a)-Math.abs(b)) * mult);
|
||||
}
|
||||
|
||||
private void generarCorrida(Date dataGeracao, List<EsquemaCorrida> lsEsquemaCorrida) {
|
||||
DefaultTransactionDefinition def = new DefaultTransactionDefinition(DefaultTransactionDefinition.PROPAGATION_REQUIRES_NEW);
|
||||
|
||||
|
|
Loading…
Reference in New Issue