Fuso e horario de verão
git-svn-id: http://desenvolvimento.rjconsultores.com.br/repositorio/sco/AdmVenta/Model/trunk/modelWeb@31495 d1611594-4594-4d17-8e1d-87c2c4800839master
parent
26cca6a23a
commit
f51b8aa988
|
@ -11,6 +11,7 @@ import com.rjconsultores.ventaboletos.entidad.ClaseServicio;
|
|||
import com.rjconsultores.ventaboletos.entidad.Corrida;
|
||||
import com.rjconsultores.ventaboletos.entidad.Corrida.Id;
|
||||
import com.rjconsultores.ventaboletos.entidad.DiagramaAutobus;
|
||||
import com.rjconsultores.ventaboletos.entidad.Estado;
|
||||
import com.rjconsultores.ventaboletos.entidad.Marca;
|
||||
import com.rjconsultores.ventaboletos.entidad.Parada;
|
||||
import com.rjconsultores.ventaboletos.entidad.Ruta;
|
||||
|
@ -78,4 +79,8 @@ public interface CorridaDAO extends GenericDAO<Corrida, Corrida.Id> {
|
|||
|
||||
public void actualizaFecHusoFecVerano(Corrida corrida);
|
||||
|
||||
public void actualizaFecHusoFecVerano(List<Corrida> corridas);
|
||||
|
||||
public List<Corrida> buscarPorEstado(Estado estado, Date dataInicial);
|
||||
|
||||
}
|
|
@ -27,6 +27,7 @@ import com.rjconsultores.ventaboletos.entidad.ClaseServicio;
|
|||
import com.rjconsultores.ventaboletos.entidad.Corrida;
|
||||
import com.rjconsultores.ventaboletos.entidad.Corrida.Id;
|
||||
import com.rjconsultores.ventaboletos.entidad.DiagramaAutobus;
|
||||
import com.rjconsultores.ventaboletos.entidad.Estado;
|
||||
import com.rjconsultores.ventaboletos.entidad.Marca;
|
||||
import com.rjconsultores.ventaboletos.entidad.Parada;
|
||||
import com.rjconsultores.ventaboletos.entidad.Ruta;
|
||||
|
@ -41,9 +42,10 @@ public class CorridaHibernateDAO extends GenericHibernateDAO<Corrida, Corrida.Id
|
|||
|
||||
@Autowired
|
||||
private SQLBuilder sqlBuilder;
|
||||
private static final Integer ULTIMA_HORA_DIA = new Integer(23);
|
||||
private static final Integer ULTIMO_MINUTO_SEGUNDO = new Integer(59);
|
||||
private static final Integer ULTIMO_MILLISEGUNDO = new Integer(99);
|
||||
private static final Integer ULTIMA_HORA_DIA = Integer.valueOf(23);
|
||||
private static final Integer ULTIMO_MINUTO_SEGUNDO = Integer.valueOf(59);
|
||||
private static final Integer ULTIMO_MILLISEGUNDO = Integer.valueOf(99);
|
||||
private static final Integer MAX_ARRAY = Integer.valueOf(1000);
|
||||
|
||||
@Autowired
|
||||
public CorridaHibernateDAO(@Qualifier("sessionFactory") final SessionFactory factory) {
|
||||
|
@ -329,7 +331,8 @@ public class CorridaHibernateDAO extends GenericHibernateDAO<Corrida, Corrida.Id
|
|||
|
||||
public List<Corrida> buscarGroupCorrridaId(final Integer corridaId, final Integer origem, final Integer destino,
|
||||
final Integer ruta, final Integer numRuta, final Date dateInicio, final Date dateFin) {
|
||||
StringBuffer sql = new StringBuffer();
|
||||
|
||||
StringBuilder sql = new StringBuilder();
|
||||
sql.append(" SELECT c.corrida_id ");
|
||||
sql.append(" FROM corrida c ");
|
||||
if (numRuta != null) {
|
||||
|
@ -394,7 +397,7 @@ public class CorridaHibernateDAO extends GenericHibernateDAO<Corrida, Corrida.Id
|
|||
|
||||
public List<Corrida> buscarGroupCorrridaId(final Integer corridaId, final Date dateInicio, final Date dateFin) {
|
||||
|
||||
StringBuffer sql = new StringBuffer();
|
||||
StringBuilder sql = new StringBuilder();
|
||||
sql.append(" SELECT c.corrida_id ");
|
||||
sql.append(" FROM corrida c ");
|
||||
sql.append(" WHERE c.feccorrida BETWEEN :dateInicio AND :dateFin ");
|
||||
|
@ -447,15 +450,97 @@ public class CorridaHibernateDAO extends GenericHibernateDAO<Corrida, Corrida.Id
|
|||
Date feccorrida = corrida.getId().getFeccorrida();
|
||||
|
||||
Query queryCorrida = getSession().createQuery(
|
||||
sqlBuilder.getSQLActualizarCorridaFecHusoFecVerano(corridaId, feccorrida));
|
||||
sqlBuilder.getSQLActualizarCorridaFecHusoFecVerano());
|
||||
queryCorrida.setInteger("corridaId", corridaId);
|
||||
queryCorrida.setInteger("corridaId", corridaId);
|
||||
queryCorrida.setDate("feccorrida", feccorrida);
|
||||
queryCorrida.executeUpdate();
|
||||
|
||||
Query queryCorridaTramo = getSession().createQuery(
|
||||
sqlBuilder.getSQLActualizarCorridaTramoFecHusoFecVerano(corridaId, feccorrida));
|
||||
sqlBuilder.getSQLActualizarCorridaTramoFecHusoFecVerano());
|
||||
queryCorridaTramo.setInteger("corridaId", corridaId);
|
||||
queryCorridaTramo.setDate("feccorrida", feccorrida);
|
||||
queryCorridaTramo.executeUpdate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actualizaFecHusoFecVerano(final List<Corrida> corridas) {
|
||||
|
||||
List<ArrayList<Integer>> corridaIdList = new ArrayList<ArrayList<Integer>>();
|
||||
List<ArrayList<Date>> fecorridaList = new ArrayList<ArrayList<Date>>();
|
||||
|
||||
ArrayList<Integer> corridaIds = new ArrayList<Integer>();
|
||||
ArrayList<Date> fecorridas = new ArrayList<Date>();
|
||||
|
||||
Integer cont = NumberUtils.INTEGER_ONE;
|
||||
for (Corrida corrida : corridas) {
|
||||
|
||||
if (cont < MAX_ARRAY) {
|
||||
corridaIds.add(corrida.getId().getCorridaId());
|
||||
fecorridas.add(corrida.getId().getFeccorrida());
|
||||
cont++;
|
||||
} else {
|
||||
cont = NumberUtils.INTEGER_ONE;
|
||||
corridaIdList.add(corridaIds);
|
||||
fecorridaList.add(fecorridas);
|
||||
|
||||
corridaIds = new ArrayList<Integer>();
|
||||
fecorridas = new ArrayList<Date>();
|
||||
|
||||
corridaIds.add(corrida.getId().getCorridaId());
|
||||
fecorridas.add(corrida.getId().getFeccorrida());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if (corridaIdList.size() == fecorridaList.size()) {
|
||||
for (int i = 0; i < corridaIdList.size(); i++) {
|
||||
|
||||
try {
|
||||
Query queryCorrida = getSession().createQuery(
|
||||
sqlBuilder.getSQLActualizarCorridaFecHusoFecVerano());
|
||||
queryCorrida.setParameterList("corridaId", corridaIdList.get(i));
|
||||
queryCorrida.setParameterList("feccorrida", fecorridaList.get(i));
|
||||
queryCorrida.executeUpdate();
|
||||
|
||||
Query queryCorridaTramo = getSession().createQuery(
|
||||
sqlBuilder.getSQLActualizarCorridaTramoFecHusoFecVerano());
|
||||
queryCorridaTramo.setParameterList("corridaId", corridaIdList.get(i));
|
||||
queryCorridaTramo.setParameterList("feccorrida", fecorridaList.get(i));
|
||||
queryCorridaTramo.executeUpdate();
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Corrida> buscarPorEstado(final Estado estado, final Date dataInicial) {
|
||||
|
||||
StringBuilder hql = new StringBuilder();
|
||||
|
||||
hql.append(" select ");
|
||||
hql.append(" 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 ");
|
||||
hql.append(" left join ct.origem.ciudad.estado eo ");
|
||||
hql.append(" left join ct.destino.ciudad.estado ed ");
|
||||
hql.append(" where ct.corrida.activo = :isActivo ");
|
||||
hql.append(" and ct.corrida.id.feccorrida >= :feccorrida ");
|
||||
hql.append(" and ( eo.estadoId = :estadoId ");
|
||||
hql.append(" or ed.estadoId = :estadoId )");
|
||||
hql.append(" group by ");
|
||||
hql.append(" ct.corrida.id.corridaId, ");
|
||||
hql.append(" ct.corrida.id.feccorrida ");
|
||||
|
||||
Query query = getSession().createQuery(hql.toString());
|
||||
query.setBoolean("isActivo", Boolean.TRUE);
|
||||
query.setDate("feccorrida", dataInicial);
|
||||
query.setInteger("estadoId", estado.getEstadoId());
|
||||
|
||||
return query.list();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
package com.rjconsultores.ventaboletos.dao.sqlbuilder;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* Interface que indica quais são os SQL nativos da aplicação.
|
||||
*
|
||||
|
@ -35,8 +33,8 @@ public interface SQLBuilder {
|
|||
|
||||
public String getSQLInserirTarifaPelaTarifaOficial(Integer vigenciaTarifaId, Integer usuarioId);
|
||||
|
||||
public String getSQLActualizarCorridaFecHusoFecVerano(Integer corridaId, Date feccorrida);
|
||||
public String getSQLActualizarCorridaFecHusoFecVerano();
|
||||
|
||||
public String getSQLActualizarCorridaTramoFecHusoFecVerano(Integer corridaId, Date feccorrida);
|
||||
public String getSQLActualizarCorridaTramoFecHusoFecVerano();
|
||||
|
||||
}
|
||||
|
|
|
@ -1,12 +1,10 @@
|
|||
package com.rjconsultores.ventaboletos.dao.sqlbuilder.impl;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import com.rjconsultores.ventaboletos.dao.sqlbuilder.SQLBuilder;
|
||||
|
||||
public class SQLBuilderOracle implements SQLBuilder {
|
||||
|
||||
private static final Integer HORAS_NO_DIA = new Integer(24);
|
||||
private static final Integer HORAS_NO_DIA = Integer.valueOf(24);
|
||||
|
||||
@Override
|
||||
public String getSQLGerarTarifaOficial(final Integer codRuta, final Integer usuarioId,
|
||||
|
@ -405,6 +403,7 @@ public class SQLBuilderOracle implements SQLBuilder {
|
|||
return sb.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSQLAtualizarTarifaPorTarifaOfical(final Integer vigenciaTarifaId, final Integer usuarioId,
|
||||
final Boolean calculaPegagio) {
|
||||
StringBuilder sb = new StringBuilder("");
|
||||
|
@ -448,6 +447,7 @@ public class SQLBuilderOracle implements SQLBuilder {
|
|||
return sb.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSQLInserirTarifaPelaTarifaOficial(final Integer vigenciaTarifaId, final Integer usuarioId) {
|
||||
StringBuilder sb = new StringBuilder("");
|
||||
sb.append(" insert ");
|
||||
|
@ -503,9 +503,10 @@ public class SQLBuilderOracle implements SQLBuilder {
|
|||
return sb.toString();
|
||||
}
|
||||
|
||||
public String getSQLActualizarCorridaFecHusoFecVerano(final Integer corridaId, final Date feccorrida) {
|
||||
@Override
|
||||
public String getSQLActualizarCorridaFecHusoFecVerano() {
|
||||
|
||||
StringBuffer sb = new StringBuffer();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
sb.append(" update Corrida cq ");
|
||||
sb.append(" set cq.fechorSalidaOriginalH = ");
|
||||
|
@ -520,19 +521,20 @@ public class SQLBuilderOracle implements SQLBuilder {
|
|||
sb.append(" then (c.origem.ciudad.estado.tiempoHorVerano/").append(HORAS_NO_DIA).append(") ");
|
||||
sb.append(" else 0 end, 0) ");
|
||||
sb.append(" from Corrida c ");
|
||||
sb.append(" where c.id.corridaId = :corridaId ");
|
||||
sb.append(" and c.id.feccorrida = :feccorrida ");
|
||||
sb.append(" where c.id.corridaId in ( :corridaId ) ");
|
||||
sb.append(" and c.id.feccorrida in ( :feccorrida ) ");
|
||||
sb.append(" and c.id.corridaId = cq.id.corridaId ");
|
||||
sb.append(" and c.id.feccorrida = cq.id.feccorrida ");
|
||||
sb.append(" ) ");
|
||||
sb.append(" where cq.id.corridaId = :corridaId ");
|
||||
sb.append(" and cq.id.feccorrida = :feccorrida ");
|
||||
sb.append(" where cq.id.corridaId in ( :corridaId ) ");
|
||||
sb.append(" and cq.id.feccorrida in ( :feccorrida ) ");
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public String getSQLActualizarCorridaTramoFecHusoFecVerano(final Integer corridaId, final Date feccorrida) {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
@Override
|
||||
public String getSQLActualizarCorridaTramoFecHusoFecVerano() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
sb.append(" update CorridaTramo ctq ");
|
||||
sb.append(" set ctq.fechorSalidaOriginalH = ");
|
||||
|
@ -547,8 +549,8 @@ public class SQLBuilderOracle implements SQLBuilder {
|
|||
sb.append(" then (ct.origem.ciudad.estado.tiempoHorVerano/").append(HORAS_NO_DIA).append(") ");
|
||||
sb.append(" else 0 end, 0) ");
|
||||
sb.append(" from CorridaTramo ct ");
|
||||
sb.append(" where ct.corrida.id.corridaId = :corridaId ");
|
||||
sb.append(" and ct.corrida.id.feccorrida = :feccorrida ");
|
||||
sb.append(" where ct.corrida.id.corridaId in ( :corridaId ) ");
|
||||
sb.append(" and ct.corrida.id.feccorrida in ( :feccorrida ) ");
|
||||
sb.append(" and ctq.corridatramoId = ct.corridatramoId ");
|
||||
sb.append(" ) ");
|
||||
|
||||
|
@ -567,8 +569,8 @@ public class SQLBuilderOracle implements SQLBuilder {
|
|||
sb.append(" then (ct.origem.ciudad.estado.tiempoHorVerano/").append(HORAS_NO_DIA).append(") ");
|
||||
sb.append(" else 0 end, 0) ");
|
||||
sb.append(" from CorridaTramo ct ");
|
||||
sb.append(" where ct.corrida.id.corridaId = :corridaId ");
|
||||
sb.append(" and ct.corrida.id.feccorrida = :feccorrida ");
|
||||
sb.append(" where ct.corrida.id.corridaId in ( :corridaId ) ");
|
||||
sb.append(" and ct.corrida.id.feccorrida in ( :feccorrida ) ");
|
||||
sb.append(" and ctq.corridatramoId = ct.corridatramoId ");
|
||||
sb.append(" ) ");
|
||||
|
||||
|
@ -587,13 +589,13 @@ public class SQLBuilderOracle implements SQLBuilder {
|
|||
sb.append(" then (ct.destino.ciudad.estado.tiempoHorVerano/").append(HORAS_NO_DIA).append(") ");
|
||||
sb.append(" else 0 end, 0) ");
|
||||
sb.append(" from CorridaTramo ct ");
|
||||
sb.append(" where ct.corrida.id.corridaId = :corridaId ");
|
||||
sb.append(" and ct.corrida.id.feccorrida = :feccorrida ");
|
||||
sb.append(" where ct.corrida.id.corridaId in ( :corridaId ) ");
|
||||
sb.append(" and ct.corrida.id.feccorrida in ( :feccorrida ) ");
|
||||
sb.append(" and ctq.corridatramoId = ct.corridatramoId ");
|
||||
sb.append(" ) ");
|
||||
|
||||
sb.append(" where ctq.corrida.id.corridaId = :corridaId ");
|
||||
sb.append(" and ctq.corrida.id.feccorrida = :feccorrida ");
|
||||
sb.append(" where ctq.corrida.id.corridaId in ( :corridaId ) ");
|
||||
sb.append(" and ctq.corrida.id.feccorrida in ( :feccorrida ) ");
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
|
|
@ -233,6 +233,11 @@ public class Corrida implements Serializable {
|
|||
public Corrida() {
|
||||
}
|
||||
|
||||
public Corrida(Integer corridaId, Date feccorrida) {
|
||||
this.id.setCorridaId(corridaId);
|
||||
this.id.setFeccorrida(feccorrida);
|
||||
}
|
||||
|
||||
public Corrida(Marca marca, Integer corridaId, Parada origen, Parada destino, ClaseServicio claseServicio, Date horario) {
|
||||
this.id = new Id();
|
||||
this.id.setCorridaId(corridaId);
|
||||
|
|
|
@ -11,6 +11,7 @@ import com.rjconsultores.ventaboletos.entidad.ClaseServicio;
|
|||
import com.rjconsultores.ventaboletos.entidad.Corrida;
|
||||
import com.rjconsultores.ventaboletos.entidad.DiagramaAutobus;
|
||||
import com.rjconsultores.ventaboletos.entidad.EsquemaCorrida;
|
||||
import com.rjconsultores.ventaboletos.entidad.Estado;
|
||||
import com.rjconsultores.ventaboletos.entidad.Parada;
|
||||
|
||||
/**
|
||||
|
@ -60,4 +61,6 @@ public interface CorridaService extends GenericService<Corrida, Corrida.Id> {
|
|||
public List<Corrida> buscarGroupCorrridaId(Integer corridaId, 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);
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@ import java.util.List;
|
|||
|
||||
import javax.persistence.Transient;
|
||||
|
||||
import org.apache.commons.lang.math.NumberUtils;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
|
@ -536,13 +537,20 @@ public class CorridaServiceImpl implements CorridaService {
|
|||
numSec = numSec + 1;
|
||||
corridaTramo.setNumsecdestino(numSec.shortValue());
|
||||
|
||||
Calendar salida = Calendar.getInstance();
|
||||
Date fecHorSalida = calcularFechorsalida(esquemaTramo, dataGeracao, horaChegadaAnterior, tiempoInstanciaAnterior);
|
||||
fecHorSalida.setSeconds(0);
|
||||
corridaTramo.setFechorsalida(fecHorSalida);
|
||||
salida.setTime(fecHorSalida);
|
||||
salida.set(salida.get(Calendar.YEAR), salida.get(Calendar.MONTH), salida.get(Calendar.DATE),
|
||||
salida.get(Calendar.HOUR_OF_DAY), salida.get(Calendar.MINUTE), NumberUtils.INTEGER_ZERO);
|
||||
corridaTramo.setFechorsalida(salida.getTime());
|
||||
|
||||
Calendar llegada = Calendar.getInstance();
|
||||
Date fecHorallegada = calcularFechorllegada(esquemaTramo, corrida.getClaseServicio(), dataGeracao, fecHorSalida);
|
||||
fecHorallegada.setSeconds(0);
|
||||
corridaTramo.setFechorllegada(fecHorallegada);
|
||||
llegada.setTime(fecHorallegada);
|
||||
llegada.set(llegada.get(Calendar.YEAR), llegada.get(Calendar.MONTH), llegada.get(Calendar.DATE),
|
||||
llegada.get(Calendar.HOUR_OF_DAY), llegada.get(Calendar.MINUTE), NumberUtils.INTEGER_ZERO);
|
||||
corridaTramo.setFechorllegada(llegada.getTime());
|
||||
|
||||
horaChegadaAnterior = fecHorallegada;
|
||||
tiempoInstanciaAnterior = esquemaTramo.getTiempoEstancia();
|
||||
|
||||
|
@ -1024,4 +1032,18 @@ public class CorridaServiceImpl implements CorridaService {
|
|||
|
||||
return corridaDAO.buscarGroupCorrridaId(corridaId, origem, destino, ruta, numRuta, gCalendarDe.getTime(), gCalendarAte.getTime());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean atualizarCorridaFecHusoFecVerano(Estado estado, Date dataInicial) {
|
||||
try {
|
||||
List<Corrida> corridas = corridaDAO.buscarPorEstado(estado, dataInicial);
|
||||
corridaDAO.actualizaFecHusoFecVerano(corridas);
|
||||
return Boolean.TRUE;
|
||||
|
||||
} catch (Exception ex) {
|
||||
log.error("Erro ao atualizar corridas FecHuso FecVerano: " + ex, ex);
|
||||
}
|
||||
return Boolean.FALSE;
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue