git-svn-id: http://desenvolvimento.rjconsultores.com.br/repositorio/sco/AdmVenta/Model/trunk/modelWeb@28914 d1611594-4594-4d17-8e1d-87c2c4800839
parent
3b031de5ed
commit
c2cbaab6b1
|
@ -3,6 +3,8 @@ package com.rjconsultores.ventaboletos.dao;
|
|||
import java.sql.Date;
|
||||
import java.util.List;
|
||||
|
||||
import com.rjconsultores.ventaboletos.entidad.Empresa;
|
||||
import com.rjconsultores.ventaboletos.entidad.Estado;
|
||||
import com.rjconsultores.ventaboletos.entidad.Feriado;
|
||||
|
||||
|
||||
|
@ -10,6 +12,6 @@ public interface FeriadoDAO extends GenericDAO<Feriado, Integer> {
|
|||
|
||||
public List<Feriado> buscar(Date fecferiado);
|
||||
|
||||
public boolean ehFeriado(Date fecFeriado);
|
||||
public boolean ehFeriado(Date fecFeriado, Empresa empresa, Estado estadoOrigem);
|
||||
}
|
||||
|
||||
|
|
|
@ -19,7 +19,6 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @author MCosso
|
||||
|
@ -51,7 +50,6 @@ public class EstadoHibernateDAO extends GenericHibernateDAO<Estado, Integer>
|
|||
return c.list();
|
||||
}
|
||||
|
||||
|
||||
public List<Estado> buscarNotInEmpresaImposto(Empresa empresa) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
|
@ -64,14 +62,11 @@ public class EstadoHibernateDAO extends GenericHibernateDAO<Estado, Integer>
|
|||
sb.append(" )");
|
||||
sb.append(" order by es.nombestado");
|
||||
|
||||
|
||||
Query query = getSession().createQuery(sb.toString());
|
||||
query.setParameter("empresaId", empresa.getEmpresaId());
|
||||
|
||||
List<Estado> lsEstado = query.list();
|
||||
|
||||
|
||||
return lsEstado;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -14,9 +14,10 @@ import org.springframework.beans.factory.annotation.Qualifier;
|
|||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import com.rjconsultores.ventaboletos.dao.FeriadoDAO;
|
||||
import com.rjconsultores.ventaboletos.entidad.Empresa;
|
||||
import com.rjconsultores.ventaboletos.entidad.Estado;
|
||||
import com.rjconsultores.ventaboletos.entidad.Feriado;
|
||||
|
||||
|
||||
@Repository("feriadoDAO")
|
||||
public class FeriadoHibernateDAO extends GenericHibernateDAO<Feriado, Integer> implements FeriadoDAO {
|
||||
|
||||
|
@ -39,8 +40,6 @@ public class FeriadoHibernateDAO extends GenericHibernateDAO<Feriado, Integer> i
|
|||
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();
|
||||
|
@ -48,17 +47,15 @@ public class FeriadoHibernateDAO extends GenericHibernateDAO<Feriado, Integer> i
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean ehFeriado(Date fecFeriado) {
|
||||
public boolean ehFeriado(Date fecFeriado, Empresa empresa, Estado estadoOrigem) {
|
||||
Criteria c = makeCriteria();
|
||||
|
||||
c.add(Restrictions.eq("activo", true));
|
||||
c.add(Restrictions.eq("fecferiado", fecFeriado));
|
||||
c.add(Restrictions.or(Restrictions.eq("estado", estadoOrigem), Restrictions.isNull("estado")));
|
||||
c.add(Restrictions.or(Restrictions.eq("empresa", empresa), Restrictions.isNull("empresa")));
|
||||
c.setProjection(Projections.rowCount());
|
||||
|
||||
|
||||
return HibernateFix.count(c.uniqueResult()) > 0;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -5,20 +5,16 @@
|
|||
package com.rjconsultores.ventaboletos.entidad;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import javax.persistence.Basic;
|
||||
import javax.persistence.CascadeType;
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.ManyToOne;
|
||||
import javax.persistence.OneToMany;
|
||||
import javax.persistence.OneToOne;
|
||||
import javax.persistence.SequenceGenerator;
|
||||
import javax.persistence.Table;
|
||||
import javax.persistence.Temporal;
|
||||
|
@ -51,8 +47,12 @@ public class Feriado implements Serializable {
|
|||
private Date fecmodif;
|
||||
@Column(name = "USUARIO_ID")
|
||||
private Integer usuarioId;
|
||||
|
||||
|
||||
@OneToOne
|
||||
@JoinColumn(name = "ESTADO_ID")
|
||||
private Estado estado;
|
||||
@OneToOne
|
||||
@JoinColumn(name = "EMPRESA_ID")
|
||||
private Empresa empresa;
|
||||
|
||||
public Feriado(Integer feriadoId, Date fecferiado, String descferiado) {
|
||||
super();
|
||||
|
@ -116,12 +116,21 @@ public class Feriado implements Serializable {
|
|||
this.usuarioId = usuarioId;
|
||||
}
|
||||
|
||||
public Estado getEstado() {
|
||||
return estado;
|
||||
}
|
||||
|
||||
public void setEstado(Estado estado) {
|
||||
this.estado = estado;
|
||||
}
|
||||
|
||||
public Empresa getEmpresa() {
|
||||
return empresa;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public void setEmpresa(Empresa empresa) {
|
||||
this.empresa = empresa;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
|
@ -132,8 +141,6 @@ public class Feriado implements Serializable {
|
|||
|
||||
@Override
|
||||
public boolean equals(Object object) {
|
||||
// TODO: Warning - this method won't work in the case the id fields are
|
||||
// not set
|
||||
if (!(object instanceof Feriado)) {
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -133,7 +133,6 @@ public class Ruta implements Serializable {
|
|||
this.usuarioId = usuarioId;
|
||||
}
|
||||
|
||||
|
||||
public Integer getNumRuta() {
|
||||
return numRuta;
|
||||
}
|
||||
|
@ -231,7 +230,6 @@ public class Ruta implements Serializable {
|
|||
this.orgaoConcedente = orgaoConcedente;
|
||||
}
|
||||
|
||||
|
||||
public Boolean getIndSentidoIda() {
|
||||
return indSentidoIda;
|
||||
}
|
||||
|
|
|
@ -33,13 +33,16 @@ import com.rjconsultores.ventaboletos.entidad.Corrida;
|
|||
import com.rjconsultores.ventaboletos.entidad.CorridaCtrl;
|
||||
import com.rjconsultores.ventaboletos.entidad.CorridaTramo;
|
||||
import com.rjconsultores.ventaboletos.entidad.DiagramaAutobus;
|
||||
import com.rjconsultores.ventaboletos.entidad.Empresa;
|
||||
import com.rjconsultores.ventaboletos.entidad.EsquemaAsiento;
|
||||
import com.rjconsultores.ventaboletos.entidad.EsquemaCorrida;
|
||||
import com.rjconsultores.ventaboletos.entidad.EsquemaTramo;
|
||||
import com.rjconsultores.ventaboletos.entidad.Estado;
|
||||
import com.rjconsultores.ventaboletos.entidad.Marca;
|
||||
import com.rjconsultores.ventaboletos.entidad.Parada;
|
||||
import com.rjconsultores.ventaboletos.entidad.RolOperativo;
|
||||
import com.rjconsultores.ventaboletos.entidad.Ruta;
|
||||
import com.rjconsultores.ventaboletos.entidad.RutaSecuencia;
|
||||
import com.rjconsultores.ventaboletos.entidad.Tramo;
|
||||
import com.rjconsultores.ventaboletos.entidad.TramoServicio;
|
||||
import com.rjconsultores.ventaboletos.entidad.TramoTiempo;
|
||||
|
@ -50,7 +53,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.RutaSecuenciaService;
|
||||
import com.rjconsultores.ventaboletos.service.RutaService;
|
||||
import com.rjconsultores.ventaboletos.service.TramoServicioService;
|
||||
import com.rjconsultores.ventaboletos.utilerias.DateUtil;
|
||||
|
@ -87,6 +90,8 @@ public class CorridaServiceImpl implements CorridaService {
|
|||
private EsquemaCorridaDAO esquemaCorridaDAO;
|
||||
@Autowired
|
||||
private ConstanteService constanteService;
|
||||
@Autowired
|
||||
private RutaSecuenciaService rutaSecuenciaService;
|
||||
private static Logger log = Logger.getLogger(CorridaServiceImpl.class);
|
||||
private PlatformTransactionManager transactionManager;
|
||||
@Transient
|
||||
|
@ -94,8 +99,6 @@ public class CorridaServiceImpl implements CorridaService {
|
|||
@Transient
|
||||
private int cantCorridaCommit;
|
||||
@Autowired
|
||||
private FeriadoService feriadoService;
|
||||
@Autowired
|
||||
private FeriadoCache feriadoCache;
|
||||
|
||||
@Autowired
|
||||
|
@ -334,8 +337,18 @@ public class CorridaServiceImpl implements CorridaService {
|
|||
return dataCorreta;
|
||||
}
|
||||
|
||||
private boolean isFeriado(java.sql.Date data) {
|
||||
return feriadoCache.ehFeriado(data);
|
||||
private boolean isFeriado(java.sql.Date data, EsquemaCorrida esquemaCorrida) {
|
||||
Empresa empresa = esquemaCorrida.getEmpresa();
|
||||
|
||||
Estado estadoOrigem = null;
|
||||
List<RutaSecuencia> lsRutaSequencia = rutaSecuenciaService.buscarSecuenciaOrdenado(esquemaCorrida.getRuta());
|
||||
if (!lsRutaSequencia.isEmpty()) {
|
||||
Tramo tramoOrigem = lsRutaSequencia.get(0).getTramo();
|
||||
Parada origem = tramoOrigem.getOrigem();
|
||||
estadoOrigem = origem.getCiudad().getEstado();
|
||||
}
|
||||
|
||||
return feriadoCache.ehFeriado(data, empresa, estadoOrigem);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -614,9 +627,10 @@ public class CorridaServiceImpl implements CorridaService {
|
|||
cantCorridaGenerada = 0;
|
||||
cantCorridaCommit = 1;
|
||||
java.sql.Date data = new java.sql.Date(dataGeracao.getTime());
|
||||
Boolean isFeriado = this.isFeriado(data);
|
||||
|
||||
for (EsquemaCorrida esquemaCorrida : lsEsquemaCorrida) {
|
||||
Boolean isFeriado = this.isFeriado(data, esquemaCorrida);
|
||||
|
||||
log.info("esquema=" + esquemaCorrida.getEsquemacorridaId() + " numCorrida=" + esquemaCorrida.getNumCorrida());
|
||||
|
||||
if (!esquemaCorridaDAO.esHijoRebote(esquemaCorrida)) {
|
||||
|
@ -791,7 +805,7 @@ public class CorridaServiceImpl implements CorridaService {
|
|||
tmp.setTime(dataGeracao);
|
||||
tmp.add(Calendar.DAY_OF_MONTH, 1);
|
||||
java.sql.Date data = new java.sql.Date(dataGeracao.getTime());
|
||||
Boolean isFeriado = this.isFeriado(data);
|
||||
Boolean isFeriado = this.isFeriado(data, esquemaCorrida);
|
||||
|
||||
return generarCorrida(esquemaCorrida.getEsquemaCorridaRebote(), tmp.getTime(), false, isFeriado);
|
||||
}
|
||||
|
@ -894,7 +908,7 @@ public class CorridaServiceImpl implements CorridaService {
|
|||
|
||||
while (DateUtil.compareOnlyDate(dataDe, dataAte) <= 0) {
|
||||
|
||||
Boolean isFeriado = this.isFeriado(new java.sql.Date(dataDe.getTime()));
|
||||
Boolean isFeriado = this.isFeriado(new java.sql.Date(dataDe.getTime()), esquemaCorrida);
|
||||
|
||||
generarCorrida(esquemaCorrida, dataDe, false, isFeriado);
|
||||
|
||||
|
|
|
@ -12,6 +12,8 @@ import org.springframework.context.annotation.Scope;
|
|||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.rjconsultores.ventaboletos.dao.FeriadoDAO;
|
||||
import com.rjconsultores.ventaboletos.entidad.Empresa;
|
||||
import com.rjconsultores.ventaboletos.entidad.Estado;
|
||||
|
||||
@Service("feriadoCache")
|
||||
@Scope(value = "prototype")
|
||||
|
@ -21,26 +23,26 @@ public class FeriadoCache {
|
|||
|
||||
@Autowired
|
||||
private FeriadoDAO feriadoDAO;
|
||||
private Map<String,Boolean> mapFeriado;
|
||||
|
||||
private Map<KeyFeriadoMap, Boolean> mapFeriado;
|
||||
|
||||
public FeriadoCache() {
|
||||
mapFeriado = new LinkedHashMap<String, Boolean>();
|
||||
mapFeriado = new LinkedHashMap<KeyFeriadoMap, Boolean>();
|
||||
}
|
||||
|
||||
public boolean ehFeriado(Date dataFeriado){
|
||||
public boolean ehFeriado(Date dataFeriado, Empresa empresa, Estado estadoOrigem) {
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
|
||||
String strDataFeriado = sdf.format(dataFeriado);
|
||||
KeyFeriadoMap key = new KeyFeriadoMap(strDataFeriado, empresa.getEmpresaId(), estadoOrigem.getEstadoId());
|
||||
|
||||
Boolean ehFeriado = mapFeriado.get(strDataFeriado);
|
||||
Boolean ehFeriado = mapFeriado.get(key);
|
||||
|
||||
if (ehFeriado == null) {
|
||||
ehFeriado = feriadoDAO.ehFeriado(new java.sql.Date(dataFeriado.getTime()));
|
||||
ehFeriado = feriadoDAO.ehFeriado(new java.sql.Date(dataFeriado.getTime()), empresa, estadoOrigem);
|
||||
|
||||
mapFeriado.put(strDataFeriado, ehFeriado);
|
||||
mapFeriado.put(key, ehFeriado);
|
||||
}
|
||||
|
||||
log.debug("feriado " + strDataFeriado + " = " + ehFeriado);
|
||||
log.debug("data feriado = " + strDataFeriado + "; empresa = " + empresa.getNombempresa() + "; estado = " + estadoOrigem.getNombestado() + "; eh feriado = " + ehFeriado);
|
||||
|
||||
return ehFeriado;
|
||||
}
|
||||
|
@ -49,4 +51,60 @@ public class FeriadoCache {
|
|||
mapFeriado.clear();
|
||||
}
|
||||
|
||||
class KeyFeriadoMap {
|
||||
private String dataFeriado;
|
||||
private Integer empresaId;
|
||||
private Integer estadoOrigemId;
|
||||
|
||||
public KeyFeriadoMap(String dataFeriado, Integer empresaId, Integer estadoOrigemId) {
|
||||
super();
|
||||
this.dataFeriado = dataFeriado;
|
||||
this.empresaId = empresaId;
|
||||
this.estadoOrigemId = estadoOrigemId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + getOuterType().hashCode();
|
||||
result = prime * result + ((dataFeriado == null) ? 0 : dataFeriado.hashCode());
|
||||
result = prime * result + ((empresaId == null) ? 0 : empresaId.hashCode());
|
||||
result = prime * result + ((estadoOrigemId == null) ? 0 : estadoOrigemId.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
KeyFeriadoMap other = (KeyFeriadoMap) obj;
|
||||
if (!getOuterType().equals(other.getOuterType()))
|
||||
return false;
|
||||
if (dataFeriado == null) {
|
||||
if (other.dataFeriado != null)
|
||||
return false;
|
||||
} else if (!dataFeriado.equals(other.dataFeriado))
|
||||
return false;
|
||||
if (empresaId == null) {
|
||||
if (other.empresaId != null)
|
||||
return false;
|
||||
} else if (!empresaId.equals(other.empresaId))
|
||||
return false;
|
||||
if (estadoOrigemId == null) {
|
||||
if (other.estadoOrigemId != null)
|
||||
return false;
|
||||
} else if (!estadoOrigemId.equals(other.estadoOrigemId))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
private FeriadoCache getOuterType() {
|
||||
return FeriadoCache.this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue