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