From 4b38ff1eb89bd014a4e01ff7c33fd3781bdcdc15 Mon Sep 17 00:00:00 2001 From: gleimar Date: Fri, 22 Feb 2013 17:23:13 +0000 Subject: [PATCH] git-svn-id: http://desenvolvimento.rjconsultores.com.br/repositorio/sco/AdmVenta/Model/trunk/modelWeb@24588 d1611594-4594-4d17-8e1d-87c2c4800839 --- .../service/impl/CorridaServiceImpl.java | 16 +-- .../service/impl/TramoRutaServiceImpl.java | 8 +- .../ventaboletos/utilerias/DateUtil.java | 77 +------------ .../ventaboletos/utilerias/HoraSistema.java | 101 ++++++++++++++++++ .../SecuenciaRutaTramoVO.java | 16 +-- 5 files changed, 123 insertions(+), 95 deletions(-) create mode 100644 src/com/rjconsultores/ventaboletos/utilerias/HoraSistema.java diff --git a/src/com/rjconsultores/ventaboletos/service/impl/CorridaServiceImpl.java b/src/com/rjconsultores/ventaboletos/service/impl/CorridaServiceImpl.java index 7200b49a9..47d15abbb 100644 --- a/src/com/rjconsultores/ventaboletos/service/impl/CorridaServiceImpl.java +++ b/src/com/rjconsultores/ventaboletos/service/impl/CorridaServiceImpl.java @@ -55,6 +55,7 @@ import com.rjconsultores.ventaboletos.service.FeriadoService; import com.rjconsultores.ventaboletos.service.RutaService; import com.rjconsultores.ventaboletos.service.TramoServicioService; import com.rjconsultores.ventaboletos.utilerias.DateUtil; +import com.rjconsultores.ventaboletos.utilerias.HoraSistema; import com.rjconsultores.ventaboletos.utilerias.UsuarioLogado; /** @@ -260,13 +261,10 @@ public class CorridaServiceImpl implements CorridaService { gHoraChegada.setTime(horaChegada); for (TramoServicio ts : lsTramoServicio) { - - GregorianCalendar gTiemporecorrido = new GregorianCalendar(); - gTiemporecorrido.setTime(ts.getTiemporecorrido()); - - gHoraChegada.set(Calendar.HOUR_OF_DAY, gHoraChegada.get(Calendar.HOUR_OF_DAY) + gTiemporecorrido.get(Calendar.HOUR_OF_DAY)); - - gHoraChegada.set(Calendar.MINUTE, gHoraChegada.get(Calendar.MINUTE) + gTiemporecorrido.get(Calendar.MINUTE)); + HoraSistema hs = new HoraSistema(ts.getTiemporecorrido()); + + gHoraChegada.add(Calendar.HOUR_OF_DAY, hs.getHora()); + gHoraChegada.add(Calendar.MINUTE, hs.getMinuto()); } return gHoraChegada.getTime(); @@ -285,9 +283,11 @@ public class CorridaServiceImpl implements CorridaService { log.debug("Tempo Recorrido : " + sdf.format(gHoraSaidaProximo.getTime())); if (tiempoEstanciaAnterior != null) { + gHoraSaidaProximo.add(Calendar.MINUTE, tiempoEstanciaAnterior.getMinutes()); gHoraSaidaProximo.add(Calendar.HOUR_OF_DAY, tiempoEstanciaAnterior.getHours()); - System.out.println("Tempo Recorrido + Estancia: " + sdf.format(gHoraSaidaProximo.getTime())); + + log.debug("Tempo Recorrido + Estancia: " + sdf.format(gHoraSaidaProximo.getTime())); } horaSaida = gHoraSaidaProximo.getTime(); diff --git a/src/com/rjconsultores/ventaboletos/service/impl/TramoRutaServiceImpl.java b/src/com/rjconsultores/ventaboletos/service/impl/TramoRutaServiceImpl.java index 9fbbda69e..c178653e3 100644 --- a/src/com/rjconsultores/ventaboletos/service/impl/TramoRutaServiceImpl.java +++ b/src/com/rjconsultores/ventaboletos/service/impl/TramoRutaServiceImpl.java @@ -28,7 +28,7 @@ import com.rjconsultores.ventaboletos.service.RutaService; import com.rjconsultores.ventaboletos.service.TramoRutaService; import com.rjconsultores.ventaboletos.service.TramoService; import com.rjconsultores.ventaboletos.service.TramoServicioService; -import com.rjconsultores.ventaboletos.utilerias.DateUtil.Hora; +import com.rjconsultores.ventaboletos.utilerias.HoraSistema; import com.rjconsultores.ventaboletos.utilerias.UsuarioLogado; import com.rjconsultores.ventaboletos.vo.esquemaoperacional.RutaTramoVO; import com.rjconsultores.ventaboletos.vo.esquemaoperacional.SecuenciaRutaTramoVO; @@ -259,7 +259,7 @@ public class TramoRutaServiceImpl implements TramoRutaService { SecuenciaRutaTramoVO secuenciaInicial = lsSecuenciaRutaTramoVO.get(i); Parada origen = secuenciaInicial.getOrigen(); BigDecimal totalKmsReal = secuenciaInicial.getKmReal(); - Hora totalTiempoRecorrido = secuenciaInicial.getTiempoRecorrido(); + HoraSistema totalTiempoRecorrido = secuenciaInicial.getTiempoRecorrido(); boolean primeraCombinacion = true; int j = i + 1; for (; j < (qtdTramos); j++) { @@ -279,7 +279,7 @@ public class TramoRutaServiceImpl implements TramoRutaService { log.debug("TRAMO EXISTE"); nuevaSecuencia.setKmReal(tramoServicio.getTramo().getKmReal()); - nuevaSecuencia.setTiempoRecorrido(new Hora(tramoServicio.getTiemporecorrido())); + nuevaSecuencia.setTiempoRecorrido(new HoraSistema(tramoServicio.getTiemporecorrido())); nuevaSecuencia.setTramoId(tramoServicio.getTramo().getTramoId()); nuevaSecuencia.setTramoServicioId(tramoServicio.getTramoservicioId()); @@ -310,7 +310,7 @@ public class TramoRutaServiceImpl implements TramoRutaService { log.debug("TRAMO EXISTE"); nuevaSecuencia.setKmReal(tramoServicio.getTramo().getKmReal()); - nuevaSecuencia.setTiempoRecorrido(new Hora(tramoServicio.getTiemporecorrido())); + nuevaSecuencia.setTiempoRecorrido(new HoraSistema(tramoServicio.getTiemporecorrido())); nuevaSecuencia.setTramoId(tramoServicio.getTramo().getTramoId()); nuevaSecuencia.setTramoServicioId(tramoServicio.getTramoservicioId()); } diff --git a/src/com/rjconsultores/ventaboletos/utilerias/DateUtil.java b/src/com/rjconsultores/ventaboletos/utilerias/DateUtil.java index ebe13a28c..3afca3a12 100644 --- a/src/com/rjconsultores/ventaboletos/utilerias/DateUtil.java +++ b/src/com/rjconsultores/ventaboletos/utilerias/DateUtil.java @@ -388,8 +388,8 @@ public final class DateUtil { * @param dtFim * @return */ - public static Hora getHorasMinutosByInicio(Date dtFim) { - return new Hora(dtFim); + public static HoraSistema getHorasMinutosByInicio(Date dtFim) { + return new HoraSistema(dtFim); } /** @@ -503,77 +503,4 @@ public final class DateUtil { return gcalendar.getTime(); } - - public static class Hora { - private Integer hora; - private Integer minuto; - - public Hora() { - this.hora = 0; - this.minuto = 0; - } - - public Hora(Date fecha) { - conf(fecha); - } - - private void conf(Date fecha) { - Long tempo = DateUtil.getElapsedMinutos(DateUtil.getFecInicio().getTime(), fecha); - - long minutos = (tempo % 60); - int horas = (tempo.intValue() / 60); - - hora = horas; - minuto = (int) minutos; - - } - - @Override - public String toString() { - - return (hora + ":" + ((String.valueOf(minuto).length() < 2) ? "0" + minuto : minuto)); - } - - public Integer getHora() { - return hora; - } - - public Integer getMinuto() { - return minuto; - } - - public void setMinuto(Integer minuto) { - this.minuto = minuto; - } - - public void setHora(Integer hora) { - this.hora = hora; - } - - public Date getFecha() { - Calendar c = getFecInicio(); - c.add(Calendar.HOUR_OF_DAY, hora); - c.add(Calendar.MINUTE, minuto); - - return c.getTime(); - } - - public Hora sumar(Hora horaAdicao) { - Calendar horaAtual = Calendar.getInstance(); - horaAtual.setTime(getFecha()); - - Calendar horaSomar = Calendar.getInstance(); - horaSomar.setTime(horaAdicao.getFecha()); - - int horaTotal = horaAtual.get(Calendar.HOUR_OF_DAY) + horaSomar.get(Calendar.HOUR_OF_DAY); - int minutoTotal = horaAtual.get(Calendar.MINUTE) + horaSomar.get(Calendar.MINUTE); - - Calendar fecInicio = getFecInicio(); - fecInicio.add(Calendar.HOUR_OF_DAY, horaTotal); - fecInicio.add(Calendar.MINUTE, minutoTotal); - - return new Hora(fecInicio.getTime()); - } - - } } \ No newline at end of file diff --git a/src/com/rjconsultores/ventaboletos/utilerias/HoraSistema.java b/src/com/rjconsultores/ventaboletos/utilerias/HoraSistema.java new file mode 100644 index 000000000..59f3c6ad6 --- /dev/null +++ b/src/com/rjconsultores/ventaboletos/utilerias/HoraSistema.java @@ -0,0 +1,101 @@ +package com.rjconsultores.ventaboletos.utilerias; + +import java.util.Calendar; +import java.util.Date; + +/** + * Classe criada para realizar operações sobre a hora inicial do sistema.
+ * + * A hora inicial do sistema pode ser obtida pelo método DateUtil.getFecInicio() e retorna : YEAR, 1970; DAY_OF_MONTH, 1; MONTH, 0; HOUR_OF_DAY, 0;MINUTE, 0;
+ * MILLISECOND, 0; SECOND, 0.
+ * + * + * Assim é possível armazenar e somar tempos como 24:30 + 36:00 = 60 horas e 30 minutos + * + * @author gleimar + * + */ +public class HoraSistema { + private Integer hora; + private Integer minuto; + + public HoraSistema() { + this.hora = 0; + this.minuto = 0; + } + + public HoraSistema(Date fecha) { + conf(fecha); + } + + private void conf(Date fecha) { + Long tempo = DateUtil.getElapsedMinutos(DateUtil.getFecInicio().getTime(), fecha); + + long minutos = (tempo % 60); + int horas = (tempo.intValue() / 60); + + hora = horas; + minuto = (int) minutos; + + } + + @Override + public String toString() { + + return (hora + ":" + ((String.valueOf(minuto).length() < 2) ? "0" + minuto : minuto)); + } + + public Integer getHora() { + return hora; + } + + public Integer getMinuto() { + return minuto; + } + + public void setMinuto(Integer minuto) { + this.minuto = minuto; + } + + public void setHora(Integer hora) { + this.hora = hora; + } + + public Date getFecha() { + Calendar c = DateUtil.getFecInicio(); + c.add(Calendar.HOUR_OF_DAY, hora); + c.add(Calendar.MINUTE, minuto); + + return c.getTime(); + } + + /** + * Realiza a soma da hora/minuto atual com o informado no parametro + * + * @param horaAdicao + * @return + */ + public HoraSistema sumar(HoraSistema horaAdicao) { + Calendar horaAtual = Calendar.getInstance(); + horaAtual.setTime(getFecha()); + + Calendar horaSomar = Calendar.getInstance(); + horaSomar.setTime(horaAdicao.getFecha()); + + int horaTotal = horaAtual.get(Calendar.HOUR_OF_DAY) + horaSomar.get(Calendar.HOUR_OF_DAY); + int minutoTotal = horaAtual.get(Calendar.MINUTE) + horaSomar.get(Calendar.MINUTE); + + int cantDiasAtual = DateUtil.getElapsedDias(DateUtil.getFecInicio().getTime(), horaAtual.getTime()); + int cantDiasSumar = DateUtil.getElapsedDias(DateUtil.getFecInicio().getTime(), horaSomar.getTime()); + + Calendar fecInicio = DateUtil.getFecInicio(); + fecInicio.add(Calendar.HOUR_OF_DAY, horaTotal); + fecInicio.add(Calendar.MINUTE, minutoTotal); + + fecInicio.add(Calendar.DATE, cantDiasAtual); + fecInicio.add(Calendar.DATE, cantDiasSumar); + + return new HoraSistema(fecInicio.getTime()); + } + +} \ No newline at end of file diff --git a/src/com/rjconsultores/ventaboletos/vo/esquemaoperacional/SecuenciaRutaTramoVO.java b/src/com/rjconsultores/ventaboletos/vo/esquemaoperacional/SecuenciaRutaTramoVO.java index be49d8034..49eb97342 100644 --- a/src/com/rjconsultores/ventaboletos/vo/esquemaoperacional/SecuenciaRutaTramoVO.java +++ b/src/com/rjconsultores/ventaboletos/vo/esquemaoperacional/SecuenciaRutaTramoVO.java @@ -4,7 +4,7 @@ import java.math.BigDecimal; import com.rjconsultores.ventaboletos.entidad.Parada; import com.rjconsultores.ventaboletos.entidad.Via; -import com.rjconsultores.ventaboletos.utilerias.DateUtil.Hora; +import com.rjconsultores.ventaboletos.utilerias.HoraSistema; public class SecuenciaRutaTramoVO { @@ -13,12 +13,12 @@ public class SecuenciaRutaTramoVO { private Via via; private Integer secuencia; private BigDecimal kmReal; - private Hora tiempoRecorrido; + private HoraSistema tiempoRecorrido; private Integer tramoId; private Integer tramoServicioId; public SecuenciaRutaTramoVO(Parada origen, Parada destino, Via via, Integer secuencia, BigDecimal kmReal, - Hora tiempoRecorrido) { + HoraSistema tiempoRecorrido) { super(); this.origen = origen; this.destino = destino; @@ -38,7 +38,7 @@ public class SecuenciaRutaTramoVO { } public SecuenciaRutaTramoVO(Parada origen, Parada destino, Via via, Integer secuencia, BigDecimal kmReal, - Hora tiempoRecorrido, Integer tramoId, Integer tramoServicioId) { + HoraSistema tiempoRecorrido, Integer tramoId, Integer tramoServicioId) { super(); this.origen = origen; this.destino = destino; @@ -62,13 +62,13 @@ public class SecuenciaRutaTramoVO { return destino; } - public Hora getTiempoRecorrido() { + public HoraSistema getTiempoRecorrido() { return tiempoRecorrido; } - public void setTiempoRecorrido(Hora tiempoRecorrido) { + public void setTiempoRecorrido(HoraSistema tiempoRecorrido) { if (tiempoRecorrido == null) { - tiempoRecorrido = new Hora(); + tiempoRecorrido = new HoraSistema(); } this.tiempoRecorrido = tiempoRecorrido; } @@ -119,7 +119,7 @@ public class SecuenciaRutaTramoVO { @Override public String toString() { - Hora hora = getTiempoRecorrido(); + HoraSistema hora = getTiempoRecorrido(); return secuencia + ";" + origen + ";" + destino + ";" + via + ";" + kmReal + ";" + ((hora != null) ? hora.getHora() : "-") + ";" + ((hora != null) ? hora.getMinuto() : "-");