ajuste de geração de corrida de acordo com feriado
git-svn-id: http://desenvolvimento.rjconsultores.com.br/repositorio/sco/AdmVenta/Model/trunk/modelWeb@23893 d1611594-4594-4d17-8e1d-87c2c4800839master
parent
61d86a1423
commit
0c66ac077d
|
@ -1,6 +1,6 @@
|
|||
package com.rjconsultores.ventaboletos.dao;
|
||||
|
||||
import java.util.Date;
|
||||
import java.sql.Date;
|
||||
import java.util.List;
|
||||
|
||||
import com.rjconsultores.ventaboletos.entidad.Feriado;
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
package com.rjconsultores.ventaboletos.dao.hibernate;
|
||||
|
||||
import java.util.Date;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.sql.Date;
|
||||
import java.util.List;
|
||||
|
||||
import org.hibernate.Criteria;
|
||||
import org.hibernate.Query;
|
||||
import org.hibernate.SessionFactory;
|
||||
import org.hibernate.criterion.Order;
|
||||
import org.hibernate.criterion.Restrictions;
|
||||
|
@ -13,6 +15,7 @@ import org.springframework.stereotype.Repository;
|
|||
|
||||
import com.rjconsultores.ventaboletos.dao.FeriadoDAO;
|
||||
import com.rjconsultores.ventaboletos.entidad.Feriado;
|
||||
import com.rjconsultores.ventaboletos.entidad.Marca;
|
||||
|
||||
|
||||
@Repository("feriadoDAO")
|
||||
|
@ -35,12 +38,15 @@ public class FeriadoHibernateDAO extends GenericHibernateDAO<Feriado, Integer>
|
|||
}
|
||||
|
||||
public List<Feriado> buscar(Date descferiado) {
|
||||
Criteria c = getSession().createCriteria(getPersistentClass());
|
||||
c.add(Restrictions.eq("activo", Boolean.TRUE));
|
||||
c.add(Restrictions.eq("fecferiado", descferiado));
|
||||
|
||||
|
||||
return c.list();
|
||||
String hql = " select new com.rjconsultores.ventaboletos.entidad.Feriado(feriado.feriadoId, feriado.fecferiado,feriado.descferiado) from Feriado feriado" +
|
||||
" where feriado.activo = 1 and feriado.fecferiado =:data";
|
||||
|
||||
|
||||
|
||||
Query sq = getSession().createQuery(hql);
|
||||
sq.setParameter("data", descferiado);
|
||||
List<Feriado> lsMarca = sq.list();
|
||||
return lsMarca;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -118,6 +118,17 @@ public class EsquemaCorrida implements Serializable {
|
|||
private Integer numCorridaPisoExtra;
|
||||
@Column(name = "INDGENERAFERIADO")
|
||||
private String indGeneraFeriado;
|
||||
|
||||
|
||||
|
||||
private static List<String> tpGeneraFeriadoList = new ArrayList<String>();
|
||||
|
||||
static{
|
||||
|
||||
tpGeneraFeriadoList.add("GERAR SEMPRE");
|
||||
tpGeneraFeriadoList.add("GERAR SO QUANDO FOR FERIADO");
|
||||
tpGeneraFeriadoList.add("GERAR QUANDO NAO FOR FERIADO");
|
||||
}
|
||||
|
||||
public String getTipocorrida() {
|
||||
return tipocorrida;
|
||||
|
@ -407,6 +418,16 @@ public class EsquemaCorrida implements Serializable {
|
|||
this.indGeneraFeriado = indGeneraFeriado;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static List<String> getTpGeneraFeriadoList() {
|
||||
return tpGeneraFeriadoList;
|
||||
}
|
||||
|
||||
public static void setTpGeneraFeriadoList(List<String> tpGeneraFeriadoList) {
|
||||
EsquemaCorrida.tpGeneraFeriadoList = tpGeneraFeriadoList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hash = 0;
|
||||
|
|
|
@ -40,7 +40,7 @@ public class Feriado implements Serializable {
|
|||
@GeneratedValue(strategy = GenerationType.AUTO, generator = "FERIADO_SEQ")
|
||||
private Integer feriadoId;
|
||||
@Column(name = "FECFERIADO")
|
||||
@Temporal(TemporalType.TIMESTAMP)
|
||||
@Temporal(TemporalType.DATE)
|
||||
private Date fecferiado;
|
||||
@Column(name = "DESCFERIADO")
|
||||
private String descferiado;
|
||||
|
@ -54,7 +54,14 @@ public class Feriado implements Serializable {
|
|||
|
||||
|
||||
|
||||
public Feriado() {
|
||||
public Feriado(Integer feriadoId, Date fecferiado, String descferiado) {
|
||||
super();
|
||||
this.feriadoId = feriadoId;
|
||||
this.fecferiado = fecferiado;
|
||||
this.descferiado = descferiado;
|
||||
}
|
||||
|
||||
public Feriado() {
|
||||
}
|
||||
|
||||
public Feriado(Integer feriadoId) {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package com.rjconsultores.ventaboletos.service;
|
||||
|
||||
import java.util.Date;
|
||||
import java.sql.Date;
|
||||
import java.util.List;
|
||||
|
||||
import com.rjconsultores.ventaboletos.entidad.Feriado;
|
||||
|
|
|
@ -36,6 +36,7 @@ import com.rjconsultores.ventaboletos.entidad.DiagramaAutobus;
|
|||
import com.rjconsultores.ventaboletos.entidad.EsquemaAsiento;
|
||||
import com.rjconsultores.ventaboletos.entidad.EsquemaCorrida;
|
||||
import com.rjconsultores.ventaboletos.entidad.EsquemaTramo;
|
||||
import com.rjconsultores.ventaboletos.entidad.Feriado;
|
||||
import com.rjconsultores.ventaboletos.entidad.Marca;
|
||||
import com.rjconsultores.ventaboletos.entidad.Parada;
|
||||
import com.rjconsultores.ventaboletos.entidad.RolOperativo;
|
||||
|
@ -50,6 +51,7 @@ import com.rjconsultores.ventaboletos.service.CorridaService;
|
|||
import com.rjconsultores.ventaboletos.service.EsquemaAsientoService;
|
||||
import com.rjconsultores.ventaboletos.service.EsquemaCorridaService;
|
||||
import com.rjconsultores.ventaboletos.service.EsquemaTramoService;
|
||||
import com.rjconsultores.ventaboletos.service.FeriadoService;
|
||||
import com.rjconsultores.ventaboletos.service.RutaService;
|
||||
import com.rjconsultores.ventaboletos.service.TramoServicioService;
|
||||
import com.rjconsultores.ventaboletos.utilerias.DateUtil;
|
||||
|
@ -90,6 +92,8 @@ public class CorridaServiceImpl implements CorridaService {
|
|||
private int cantCorridaGenerada;
|
||||
@Transient
|
||||
private int cantCorridaCommit;
|
||||
@Autowired
|
||||
private FeriadoService feriadoService;
|
||||
|
||||
@Autowired
|
||||
public CorridaServiceImpl(@Qualifier("transactionManager") PlatformTransactionManager transactionManager) {
|
||||
|
@ -142,74 +146,92 @@ public class CorridaServiceImpl implements CorridaService {
|
|||
public List<Corrida> buscarFiltro(Parada ori, Parada des, Date hora, ClaseServicio cs) {
|
||||
return corridaDAO.buscarFiltro(ori, des, hora, cs);
|
||||
}
|
||||
|
||||
|
||||
private Boolean geraDiaSemana (Integer diaSemana,EsquemaCorrida esquemaCorrida){
|
||||
Boolean retorno = Boolean.FALSE;
|
||||
switch (diaSemana) {
|
||||
case 1: {
|
||||
// diaSemana = "Domingo";
|
||||
if (esquemaCorrida.getInddomingo() == null) {
|
||||
retorno = Boolean.FALSE;
|
||||
} else if (esquemaCorrida.getInddomingo()) {
|
||||
retorno = Boolean.TRUE;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 2: {
|
||||
// diaSemana = "Segunda";
|
||||
if (esquemaCorrida.getIndlunes() == null) {
|
||||
retorno = Boolean.FALSE;
|
||||
} else if (esquemaCorrida.getIndlunes()) {
|
||||
retorno = Boolean.TRUE;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 3: {
|
||||
// diaSemana = "Terca";
|
||||
if (esquemaCorrida.getIndmartes() == null) {
|
||||
retorno = Boolean.FALSE;
|
||||
} else if (esquemaCorrida.getIndmartes()) {
|
||||
retorno = Boolean.TRUE;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 4: {
|
||||
// diaSemana = "Quarta";
|
||||
if (esquemaCorrida.getIndmiercoles() == null) {
|
||||
retorno = Boolean.FALSE;
|
||||
} else if (esquemaCorrida.getIndmiercoles()) {
|
||||
retorno = Boolean.TRUE;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 5: {
|
||||
// diaSemana = "Quinta";
|
||||
if (esquemaCorrida.getIndjueves() == null) {
|
||||
retorno = Boolean.FALSE;
|
||||
} else if (esquemaCorrida.getIndjueves()) {
|
||||
|
||||
retorno = Boolean.TRUE;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 6: {
|
||||
// diaSemana = "Sexta";
|
||||
if (esquemaCorrida.getIndviernes() == null) {
|
||||
retorno = Boolean.FALSE;
|
||||
} else if (esquemaCorrida.getIndviernes()) {
|
||||
retorno = Boolean.TRUE;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 7: {
|
||||
// diaSemana = "Sabado";
|
||||
if (esquemaCorrida.getIndsabado() == null) {
|
||||
retorno = Boolean.FALSE;
|
||||
} else if (esquemaCorrida.getIndsabado()) {
|
||||
retorno = Boolean.TRUE;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return retorno;
|
||||
}
|
||||
|
||||
private boolean temCorridaDiaSemana(Integer diaSemana, EsquemaCorrida esquemaCorrida) {
|
||||
private boolean temCorridaDiaSemana(Integer diaSemana, EsquemaCorrida esquemaCorrida, Boolean isFeriado) {
|
||||
Boolean retorno = Boolean.FALSE;
|
||||
|
||||
switch (diaSemana) {
|
||||
case 1: {
|
||||
// diaSemana = "Domingo";
|
||||
if (esquemaCorrida.getInddomingo() == null) {
|
||||
retorno = Boolean.FALSE;
|
||||
} else if (esquemaCorrida.getInddomingo()) {
|
||||
retorno = Boolean.TRUE;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 2: {
|
||||
// diaSemana = "Segunda";
|
||||
if (esquemaCorrida.getIndlunes() == null) {
|
||||
retorno = Boolean.FALSE;
|
||||
} else if (esquemaCorrida.getIndlunes()) {
|
||||
retorno = Boolean.TRUE;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 3: {
|
||||
// diaSemana = "Terca";
|
||||
if (esquemaCorrida.getIndmartes() == null) {
|
||||
retorno = Boolean.FALSE;
|
||||
} else if (esquemaCorrida.getIndmartes()) {
|
||||
retorno = Boolean.TRUE;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 4: {
|
||||
// diaSemana = "Quarta";
|
||||
if (esquemaCorrida.getIndmiercoles() == null) {
|
||||
retorno = Boolean.FALSE;
|
||||
} else if (esquemaCorrida.getIndmiercoles()) {
|
||||
retorno = Boolean.TRUE;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 5: {
|
||||
// diaSemana = "Quinta";
|
||||
if (esquemaCorrida.getIndjueves() == null) {
|
||||
retorno = Boolean.FALSE;
|
||||
} else if (esquemaCorrida.getIndjueves()) {
|
||||
retorno = Boolean.TRUE;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 6: {
|
||||
// diaSemana = "Sexta";
|
||||
if (esquemaCorrida.getIndviernes() == null) {
|
||||
retorno = Boolean.FALSE;
|
||||
} else if (esquemaCorrida.getIndviernes()) {
|
||||
retorno = Boolean.TRUE;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 7: {
|
||||
// diaSemana = "Sabado";
|
||||
if (esquemaCorrida.getIndsabado() == null) {
|
||||
retorno = Boolean.FALSE;
|
||||
} else if (esquemaCorrida.getIndsabado()) {
|
||||
retorno = Boolean.TRUE;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if(esquemaCorrida.getIndGeneraFeriado() != null){
|
||||
if (esquemaCorrida.getIndGeneraFeriado().equals("S")){
|
||||
retorno = geraDiaSemana(diaSemana,esquemaCorrida);
|
||||
}else if (isFeriado){
|
||||
if (esquemaCorrida.getIndGeneraFeriado().equals("F")){
|
||||
retorno = geraDiaSemana(diaSemana,esquemaCorrida);
|
||||
}
|
||||
}else if (esquemaCorrida.getIndGeneraFeriado().equals("N")){
|
||||
retorno = geraDiaSemana(diaSemana,esquemaCorrida);
|
||||
}
|
||||
}
|
||||
|
||||
return retorno;
|
||||
|
@ -288,6 +310,16 @@ public class CorridaServiceImpl implements CorridaService {
|
|||
|
||||
return dataCorreta;
|
||||
}
|
||||
|
||||
public boolean isFeriado (java.sql.Date data){
|
||||
|
||||
List<Feriado> feriadoList = feriadoService.buscar(data);
|
||||
if (feriadoList.isEmpty()){
|
||||
return false;
|
||||
}else{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Genera una corrida para el esquemaCorrida informado en el dia y fecha
|
||||
|
@ -300,14 +332,14 @@ public class CorridaServiceImpl implements CorridaService {
|
|||
* @param dataGeracao
|
||||
* @return - La corrida generada o null si no fue generada.
|
||||
*/
|
||||
public Corrida generarCorrida(EsquemaCorrida esquemaCorrida, Date dataGeracao, boolean isPisoExtra) {
|
||||
public Corrida generarCorrida(EsquemaCorrida esquemaCorrida, Date dataGeracao, boolean isPisoExtra, Boolean isFeriado) {
|
||||
GregorianCalendar calendario = new GregorianCalendar();
|
||||
calendario.setTime(dataGeracao);
|
||||
|
||||
Integer diaSemana = calendario.get(Calendar.DAY_OF_WEEK);
|
||||
Corrida corrida = null;
|
||||
if ((esquemaCorrida.getStatusCorrida() != null) && (esquemaCorrida.getStatusCorrida().equals("A"))) {
|
||||
if (temCorridaDiaSemana(diaSemana, esquemaCorrida)) {
|
||||
if (temCorridaDiaSemana(diaSemana, esquemaCorrida,isFeriado)) {
|
||||
try {
|
||||
Ruta ruta = esquemaCorrida.getRuta();
|
||||
ClaseServicio claseServicio = esquemaCorrida.getClaseServicio();
|
||||
|
@ -521,13 +553,15 @@ public class CorridaServiceImpl implements CorridaService {
|
|||
TransactionStatus status = transactionManager.getTransaction(def);
|
||||
cantCorridaGenerada = 0;
|
||||
cantCorridaCommit = 1;
|
||||
java.sql.Date data = new java.sql.Date(dataGeracao.getTime());
|
||||
Boolean isFeriado = this.isFeriado(data);
|
||||
|
||||
for (EsquemaCorrida esquemaCorrida : lsEsquemaCorrida) {
|
||||
log.info("esquema=" + esquemaCorrida.getEsquemacorridaId() + " numCorrida=" + esquemaCorrida.getNumCorrida());
|
||||
|
||||
if (!esquemaCorridaDAO.esHijoRebote(esquemaCorrida)) {
|
||||
|
||||
Corrida corrida = generarCorrida(esquemaCorrida, dataGeracao, false);
|
||||
Corrida corrida = generarCorrida(esquemaCorrida, dataGeracao, false, isFeriado);
|
||||
Corrida corridaPisoExtra = null;
|
||||
|
||||
if (corrida == null) {// Si no gener<65> la corrida, no va a
|
||||
|
@ -546,7 +580,7 @@ public class CorridaServiceImpl implements CorridaService {
|
|||
esquemaCorrida.setRolOperativo(esquemaCorrida.getRolOperativo2());
|
||||
esquemaCorrida.setClaseServicio(esquemaCorrida.getClaseServicio2());
|
||||
|
||||
corridaPisoExtra = generarCorrida(esquemaCorrida, dataGeracao, true);
|
||||
corridaPisoExtra = generarCorrida(esquemaCorrida, dataGeracao, true, isFeriado);
|
||||
if (corrida != null && corridaPisoExtra != null) {
|
||||
// Voltando RolOperativo e Classe de Servi<76>o
|
||||
esquemaCorrida.setRolOperativo(ro);
|
||||
|
@ -568,7 +602,7 @@ public class CorridaServiceImpl implements CorridaService {
|
|||
|
||||
log.info("Corrida Rebote=" + esquemaCorrida.getEsquemacorridaId());
|
||||
|
||||
Corrida corridaRebote = generarCorrida(esquemaCorrida.getEsquemaCorridaRebote(), dataGeracao, false);
|
||||
Corrida corridaRebote = generarCorrida(esquemaCorrida.getEsquemaCorridaRebote(), dataGeracao, false, isFeriado);
|
||||
Corrida corridaPisoExtraRebote = null;
|
||||
|
||||
boolean generaReboteDiaSeguinte = false;
|
||||
|
@ -584,7 +618,7 @@ public class CorridaServiceImpl implements CorridaService {
|
|||
ecRebote.setRolOperativo(ecRebote.getRolOperativo2());
|
||||
ecRebote.setClaseServicio(ecRebote.getClaseServicio2());
|
||||
|
||||
corridaPisoExtraRebote = generarCorrida(ecRebote, dataGeracao, true);
|
||||
corridaPisoExtraRebote = generarCorrida(ecRebote, dataGeracao, true, isFeriado);
|
||||
if (corridaRebote != null && corridaPisoExtraRebote != null) {
|
||||
// Salvando Referencia da Corrida no piso extra
|
||||
corridaPisoExtraRebote.setCorridaPiso(corridaRebote);
|
||||
|
@ -698,7 +732,9 @@ public class CorridaServiceImpl implements CorridaService {
|
|||
Calendar tmp = Calendar.getInstance();
|
||||
tmp.setTime(dataGeracao);
|
||||
tmp.add(Calendar.DAY_OF_MONTH, 1);
|
||||
return generarCorrida(esquemaCorrida.getEsquemaCorridaRebote(), tmp.getTime(), false);
|
||||
java.sql.Date data = new java.sql.Date(dataGeracao.getTime());
|
||||
Boolean isFeriado = this.isFeriado(data) ;
|
||||
return generarCorrida(esquemaCorrida.getEsquemaCorridaRebote(), tmp.getTime(), false, isFeriado);
|
||||
}
|
||||
|
||||
private List<Integer> getDiaDeLaSemana(TramoTiempo tramoTiempo) {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package com.rjconsultores.ventaboletos.service.impl;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.sql.Date;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
|
Loading…
Reference in New Issue