git-svn-id: http://desenvolvimento.rjconsultores.com.br/repositorio/sco/AdmVenta/Model/trunk/modelWeb@31586 d1611594-4594-4d17-8e1d-87c2c4800839
parent
29655a0976
commit
8970739612
|
@ -83,4 +83,6 @@ public interface CorridaDAO extends GenericDAO<Corrida, Corrida.Id> {
|
|||
|
||||
public List<Corrida> buscarPorEstado(Estado estado, Date dataInicial);
|
||||
|
||||
List<Corrida> buscarPorEstado(Estado estado, Date dataInicial, Integer corridaId);
|
||||
|
||||
}
|
|
@ -469,58 +469,58 @@ public class CorridaHibernateDAO extends GenericHibernateDAO<Corrida, Corrida.Id
|
|||
@Override
|
||||
public void actualizaFecHusoFecVerano(final List<Corrida> corridas) {
|
||||
List<Object[]> tramos = null;
|
||||
|
||||
Integer corridatramoId = 0;
|
||||
Date fechorSalidaOriginal = null;
|
||||
Date fechorsalida = null;
|
||||
Date fechorllegada = null;
|
||||
|
||||
Integer corridatramoId = 0;
|
||||
Date fechorSalidaOriginal = null;
|
||||
Date fechorsalida = null;
|
||||
Date fechorllegada = null;
|
||||
Integer tiempoHorHusoOrigem = Integer.valueOf(0);
|
||||
Integer tiempoHorVeranoOrigem = Integer.valueOf(0);
|
||||
Integer tiempoHorHusoDestino = Integer.valueOf(0);
|
||||
Integer tiempoHorVeranoDestino = Integer.valueOf(0);
|
||||
|
||||
|
||||
Date husoHorVeranoLlegadaAnterior = null;
|
||||
|
||||
Date fechorSalidaOriginalUpdate = null;
|
||||
Date fechorsalidaUpdate = null;
|
||||
Date fechorllegadaUpdate = null;
|
||||
|
||||
|
||||
Date fechorSalidaOriginalUpdate = null;
|
||||
Date fechorsalidaUpdate = null;
|
||||
Date fechorllegadaUpdate = null;
|
||||
|
||||
for (Corrida corrida : corridas) {
|
||||
tramos = buscarTramosCorrida(corrida);
|
||||
|
||||
|
||||
husoHorVeranoLlegadaAnterior = null;
|
||||
|
||||
|
||||
for (Object[] objeto : tramos) {
|
||||
corridatramoId = Integer.valueOf(objeto[0].toString());
|
||||
corridatramoId = Integer.valueOf(objeto[0].toString());
|
||||
fechorSalidaOriginal = (Date) objeto[2];
|
||||
fechorsalida = (Date) objeto[3];
|
||||
fechorllegada = (Date) objeto[4];
|
||||
fechorsalida = (Date) objeto[3];
|
||||
fechorllegada = (Date) objeto[4];
|
||||
tiempoHorHusoOrigem = Integer.valueOf(objeto[5].toString());
|
||||
tiempoHorVeranoOrigem = Integer.valueOf(objeto[6].toString());
|
||||
tiempoHorVeranoOrigem = Integer.valueOf(objeto[6].toString());
|
||||
tiempoHorHusoDestino = Integer.valueOf(objeto[7].toString());
|
||||
tiempoHorVeranoDestino = Integer.valueOf(objeto[8].toString());
|
||||
|
||||
if (husoHorVeranoLlegadaAnterior == null){
|
||||
tiempoHorVeranoDestino = Integer.valueOf(objeto[8].toString());
|
||||
|
||||
if (husoHorVeranoLlegadaAnterior == null) {
|
||||
fechorSalidaOriginalUpdate = fechorSalidaOriginal;
|
||||
fechorsalidaUpdate = fechorsalida;
|
||||
}else{
|
||||
} else {
|
||||
fechorSalidaOriginalUpdate = husoHorVeranoLlegadaAnterior;
|
||||
fechorsalidaUpdate = husoHorVeranoLlegadaAnterior;
|
||||
}
|
||||
|
||||
|
||||
husoHorVeranoLlegadaAnterior = calcularHusoHorVeranoLlegada(
|
||||
fechorsalida,
|
||||
fechorllegada,
|
||||
fechorsalidaUpdate,
|
||||
tiempoHorHusoOrigem + tiempoHorVeranoOrigem,
|
||||
tiempoHorHusoDestino + tiempoHorVeranoDestino);
|
||||
|
||||
if (husoHorVeranoLlegadaAnterior != null){
|
||||
fechorsalida,
|
||||
fechorllegada,
|
||||
fechorsalidaUpdate,
|
||||
tiempoHorHusoOrigem + tiempoHorVeranoOrigem,
|
||||
tiempoHorHusoDestino + tiempoHorVeranoDestino);
|
||||
|
||||
if (husoHorVeranoLlegadaAnterior != null) {
|
||||
fechorllegadaUpdate = husoHorVeranoLlegadaAnterior;
|
||||
}else{
|
||||
} else {
|
||||
fechorllegadaUpdate = fechorllegada;
|
||||
}
|
||||
|
||||
|
||||
Query queryCorridaTramo = getSession().createQuery(sqlBuilder.getSQLActualizarCorridaTramoFecHusoFecVerano());
|
||||
queryCorridaTramo.setTimestamp("fechorSalidaOriginalH", fechorSalidaOriginalUpdate);
|
||||
queryCorridaTramo.setTimestamp("fechorsalidaH", fechorsalidaUpdate);
|
||||
|
@ -533,44 +533,44 @@ public class CorridaHibernateDAO extends GenericHibernateDAO<Corrida, Corrida.Id
|
|||
|
||||
private Date calcularHusoHorVeranoLlegada(Date fechorsalida, Date fechorllegada, Date fechorsalidaH, int tiempoOrigen, int tiempoDestino) {
|
||||
Calendar horLlegada = null;
|
||||
|
||||
|
||||
// Si los tiempos son distintos, hube cambio de huso horario/horario de verano
|
||||
if (tiempoOrigen != tiempoDestino) {
|
||||
long elapsedHoras = DateUtil.getElapsedHoras(fechorsalida,fechorllegada);
|
||||
|
||||
long elapsedMinutes = DateUtil.getElapsedMinutos(fechorsalida, fechorllegada);
|
||||
|
||||
horLlegada = Calendar.getInstance();
|
||||
horLlegada.setTime(fechorsalidaH);
|
||||
|
||||
horLlegada.add(Calendar.HOUR, (int)elapsedHoras);
|
||||
horLlegada.add(Calendar.HOUR, difHuso(tiempoOrigen,tiempoDestino));
|
||||
|
||||
horLlegada.add(Calendar.MINUTE, (int) elapsedMinutes);
|
||||
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) ){
|
||||
|
||||
private int difHuso(int a, int b) {
|
||||
int mult = 0;
|
||||
|
||||
if ((a < b) && (b <= 0)) {
|
||||
mult = -1;
|
||||
}else if ( (a<b) && (a>=0) ){
|
||||
} else if ((a < b) && (a >= 0)) {
|
||||
mult = -1;
|
||||
}else if (a> b){
|
||||
} else if (a > b) {
|
||||
mult = -1;
|
||||
}else{
|
||||
} else {
|
||||
mult = 1;
|
||||
}
|
||||
|
||||
return ((Math.abs(a)-Math.abs(b)) * mult);
|
||||
|
||||
return ((Math.abs(a) - Math.abs(b)) * mult);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Corrida> buscarPorEstado(final Estado estado, final Date dataInicial) {
|
||||
public List<Corrida> buscarPorEstado(final Estado estado, final Date dataInicial, Integer corridaId) {
|
||||
StringBuilder hql = new StringBuilder();
|
||||
|
||||
hql.append(" select ");
|
||||
hql.append(" new com.rjconsultores.ventaboletos.entidad.Corrida").append("(");
|
||||
hql.append(" distinct new com.rjconsultores.ventaboletos.entidad.Corrida").append("(");
|
||||
hql.append(" ct.corrida.id.corridaId, ");
|
||||
hql.append(" ct.corrida.id.feccorrida").append(")");
|
||||
hql.append(" from CorridaTramo ct ");
|
||||
|
@ -580,6 +580,9 @@ public class CorridaHibernateDAO extends GenericHibernateDAO<Corrida, Corrida.Id
|
|||
hql.append(" and ct.corrida.id.feccorrida >= :feccorrida ");
|
||||
hql.append(" and ( eo.estadoId = :estadoId ");
|
||||
hql.append(" or ed.estadoId = :estadoId )");
|
||||
if (corridaId != null) {
|
||||
hql.append(" and ct.corrida.id.corridaId = :corridaId )");
|
||||
}
|
||||
hql.append(" group by ");
|
||||
hql.append(" ct.corrida.id.corridaId, ");
|
||||
hql.append(" ct.corrida.id.feccorrida ");
|
||||
|
@ -589,9 +592,18 @@ public class CorridaHibernateDAO extends GenericHibernateDAO<Corrida, Corrida.Id
|
|||
query.setDate("feccorrida", dataInicial);
|
||||
query.setInteger("estadoId", estado.getEstadoId());
|
||||
|
||||
if (corridaId != null) {
|
||||
query.setInteger("corridaId", corridaId);
|
||||
}
|
||||
|
||||
return query.list();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Corrida> buscarPorEstado(final Estado estado, final Date dataInicial) {
|
||||
return buscarPorEstado(estado, dataInicial, null);
|
||||
}
|
||||
|
||||
private List<Object[]> buscarTramosCorrida(final Corrida corrida) {
|
||||
StringBuilder hql = new StringBuilder();
|
||||
|
||||
|
|
|
@ -63,4 +63,6 @@ public interface CorridaService extends GenericService<Corrida, Corrida.Id> {
|
|||
public List<Corrida> buscarGroupCorrridaId(Integer corridaId, Integer origem, Integer destino, Integer ruta, Integer numRuta, Date dateInicio, Date dateFin);
|
||||
|
||||
public Boolean atualizarCorridaFecHusoFecVerano(Estado estado, Date dataInicial);
|
||||
|
||||
Boolean atualizarCorridaFecHusoFecVerano(Estado estado, Date dataInicial, Integer corridaId);
|
||||
}
|
||||
|
|
|
@ -524,11 +524,10 @@ public class CorridaServiceImpl implements CorridaService {
|
|||
Date horaChegadaAnterior = null;
|
||||
Date tiempoInstanciaAnterior = null; // indica o tempo de instancia que fica no tramo anterior ao atual
|
||||
|
||||
|
||||
Date husoHorVeranoLlegadaAnterior = null;
|
||||
Date husoHorVeranoLlegadaAnterior = null;
|
||||
|
||||
for (EsquemaTramo esquemaTramo : lsEsquemaTramo) {
|
||||
|
||||
|
||||
CorridaTramo corridaTramo = new CorridaTramo();
|
||||
corridaTramo.setAutobus(null);
|
||||
corridaTramo.setConductor(null);
|
||||
|
@ -584,28 +583,27 @@ public class CorridaServiceImpl implements CorridaService {
|
|||
}
|
||||
corridaTramo.setCorrida(corrida);
|
||||
corridaTramo.setFechorSalidaOriginal(fecHorSalida);
|
||||
|
||||
if (husoHorVeranoLlegadaAnterior == null){
|
||||
|
||||
if (husoHorVeranoLlegadaAnterior == null) {
|
||||
corridaTramo.setFechorsalidaH(corridaTramo.getFechorsalida());
|
||||
}else{
|
||||
} else {
|
||||
corridaTramo.setFechorsalidaH(husoHorVeranoLlegadaAnterior);
|
||||
}
|
||||
|
||||
|
||||
husoHorVeranoLlegadaAnterior = calcularHusoHorVeranoLlegada(esquemaTramo, corridaTramo);
|
||||
|
||||
if (husoHorVeranoLlegadaAnterior != null){
|
||||
|
||||
if (husoHorVeranoLlegadaAnterior != null) {
|
||||
corridaTramo.setFechorllegadaH(husoHorVeranoLlegadaAnterior);
|
||||
corridaTramo.setFechorSalidaOriginalH(husoHorVeranoLlegadaAnterior);
|
||||
}else{
|
||||
} else {
|
||||
corridaTramo.setFechorllegadaH(corridaTramo.getFechorllegada());
|
||||
corridaTramo.setFechorSalidaOriginalH(corridaTramo.getFechorSalidaOriginal());
|
||||
}
|
||||
|
||||
|
||||
if (numSec == 1){
|
||||
|
||||
if (numSec == 1) {
|
||||
corrida.setFechorSalidaOriginalH(corridaTramo.getFechorsalidaH());
|
||||
}
|
||||
|
||||
|
||||
lsCorridaTramo.add(corridaTramo);
|
||||
}
|
||||
corrida.setCorridaTramoList(lsCorridaTramo);
|
||||
|
@ -690,34 +688,33 @@ public class CorridaServiceImpl implements CorridaService {
|
|||
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());
|
||||
|
||||
long elapsedMinutes = DateUtil.getElapsedMinutos(corridaTramo.getFechorsalida(), corridaTramo.getFechorllegada());
|
||||
|
||||
horLlegada = Calendar.getInstance();
|
||||
horLlegada.setTime(corridaTramo.getFechorsalidaH());
|
||||
|
||||
horLlegada.add(Calendar.HOUR, (int)elapsedHoras);
|
||||
horLlegada.add(Calendar.HOUR, difHuso(tiempoOrigen,tiempoDestino));
|
||||
|
||||
horLlegada.add(Calendar.MINUTE, (int) elapsedMinutes);
|
||||
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) ){
|
||||
|
||||
private int difHuso(int a, int b) {
|
||||
int mult = 0;
|
||||
|
||||
if ((a < b) && (b <= 0)) {
|
||||
mult = -1;
|
||||
}else if ( (a<b) && (a>=0) ){
|
||||
} else if ((a < b) && (a >= 0)) {
|
||||
mult = -1;
|
||||
}else if (a> b){
|
||||
} else if (a > b) {
|
||||
mult = -1;
|
||||
}else{
|
||||
} else {
|
||||
mult = 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
return ((Math.abs(a)-Math.abs(b)) * mult);
|
||||
|
||||
return ((Math.abs(a) - Math.abs(b)) * mult);
|
||||
}
|
||||
|
||||
private void generarCorrida(Date dataGeracao, List<EsquemaCorrida> lsEsquemaCorrida) {
|
||||
|
@ -1123,7 +1120,7 @@ public class CorridaServiceImpl implements CorridaService {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Boolean atualizarCorridaFecHusoFecVerano(Estado estado, Date dataInicial) {
|
||||
public Boolean atualizarCorridaFecHusoFecVerano(Estado estado, Date dataInicial, Integer corridaId) {
|
||||
try {
|
||||
List<Corrida> corridas = corridaDAO.buscarPorEstado(estado, dataInicial);
|
||||
corridaDAO.actualizaFecHusoFecVerano(corridas);
|
||||
|
@ -1135,4 +1132,9 @@ public class CorridaServiceImpl implements CorridaService {
|
|||
return Boolean.FALSE;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean atualizarCorridaFecHusoFecVerano(Estado estado, Date dataInicial) {
|
||||
return atualizarCorridaFecHusoFecVerano(estado, dataInicial, null);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue