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,59 +19,54 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author MCosso
|
||||
*/
|
||||
@Repository("estadoDAO")
|
||||
public class EstadoHibernateDAO extends GenericHibernateDAO<Estado, Integer>
|
||||
implements EstadoDAO {
|
||||
implements EstadoDAO {
|
||||
|
||||
@Autowired
|
||||
public EstadoHibernateDAO(@Qualifier("sessionFactory") SessionFactory factory) {
|
||||
setSessionFactory(factory);
|
||||
}
|
||||
@Autowired
|
||||
public EstadoHibernateDAO(@Qualifier("sessionFactory") SessionFactory factory) {
|
||||
setSessionFactory(factory);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Estado> obtenerTodos() {
|
||||
Criteria c = getSession().createCriteria(getPersistentClass());
|
||||
c.add(Restrictions.eq("activo", Boolean.TRUE));
|
||||
c.addOrder(Order.asc("nombestado"));
|
||||
@Override
|
||||
public List<Estado> obtenerTodos() {
|
||||
Criteria c = getSession().createCriteria(getPersistentClass());
|
||||
c.add(Restrictions.eq("activo", Boolean.TRUE));
|
||||
c.addOrder(Order.asc("nombestado"));
|
||||
|
||||
return c.list();
|
||||
}
|
||||
return c.list();
|
||||
}
|
||||
|
||||
public List<Estado> buscar(String nombestado, Pais pais) {
|
||||
Criteria c = getSession().createCriteria(getPersistentClass());
|
||||
c.add(Restrictions.eq("activo", Boolean.TRUE));
|
||||
c.add(Restrictions.eq("nombestado", nombestado));
|
||||
c.add(Restrictions.eq("pais", pais));
|
||||
public List<Estado> buscar(String nombestado, Pais pais) {
|
||||
Criteria c = getSession().createCriteria(getPersistentClass());
|
||||
c.add(Restrictions.eq("activo", Boolean.TRUE));
|
||||
c.add(Restrictions.eq("nombestado", nombestado));
|
||||
c.add(Restrictions.eq("pais", pais));
|
||||
|
||||
return c.list();
|
||||
}
|
||||
|
||||
|
||||
public List<Estado> buscarNotInEmpresaImposto(Empresa empresa) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
sb.append(" select es ");
|
||||
sb.append(" from Estado es ");
|
||||
sb.append(" where es.activo = 1 ");
|
||||
sb.append(" and es.estadoId not in ( ");
|
||||
sb.append(" select ei.estado.estadoId from EmpresaImposto ei ");
|
||||
sb.append(" where ei.activo = 1 and ei.empresa.empresaId =:empresaId ");
|
||||
sb.append(" )");
|
||||
sb.append(" order by es.nombestado");
|
||||
|
||||
return c.list();
|
||||
}
|
||||
|
||||
public List<Estado> buscarNotInEmpresaImposto(Empresa empresa) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
sb.append(" select es ");
|
||||
sb.append(" from Estado es ");
|
||||
sb.append(" where es.activo = 1 ");
|
||||
sb.append(" and es.estadoId not in ( ");
|
||||
sb.append(" select ei.estado.estadoId from EmpresaImposto ei ");
|
||||
sb.append(" where ei.activo = 1 and ei.empresa.empresaId =:empresaId ");
|
||||
sb.append(" )");
|
||||
sb.append(" order by es.nombestado");
|
||||
|
||||
Query query = getSession().createQuery(sb.toString());
|
||||
query.setParameter("empresaId", empresa.getEmpresaId());
|
||||
|
||||
List<Estado> lsEstado = query.list();
|
||||
|
||||
List<Estado> lsEstado = query.list();
|
||||
|
||||
return lsEstado;
|
||||
}
|
||||
|
||||
return lsEstado;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,51 +14,48 @@ 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 {
|
||||
|
||||
@Autowired
|
||||
public FeriadoHibernateDAO(
|
||||
@Qualifier("sessionFactory") SessionFactory factory) {
|
||||
setSessionFactory(factory);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Feriado> obtenerTodos() {
|
||||
Criteria c = getSession().createCriteria(getPersistentClass());
|
||||
c.add(Restrictions.eq("activo", Boolean.TRUE));
|
||||
c.addOrder(Order.asc("id"));
|
||||
|
||||
return c.list();
|
||||
}
|
||||
|
||||
public List<Feriado> buscar(Date descferiado) {
|
||||
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;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean ehFeriado(Date fecFeriado) {
|
||||
Criteria c= makeCriteria();
|
||||
|
||||
c.add(Restrictions.eq("activo", true));
|
||||
c.add(Restrictions.eq("fecferiado", fecFeriado));
|
||||
c.setProjection(Projections.rowCount());
|
||||
|
||||
|
||||
return HibernateFix.count(c.uniqueResult()) > 0;
|
||||
@Autowired
|
||||
public FeriadoHibernateDAO(
|
||||
@Qualifier("sessionFactory") SessionFactory factory) {
|
||||
setSessionFactory(factory);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@Override
|
||||
public List<Feriado> obtenerTodos() {
|
||||
Criteria c = getSession().createCriteria(getPersistentClass());
|
||||
c.add(Restrictions.eq("activo", Boolean.TRUE));
|
||||
c.addOrder(Order.asc("id"));
|
||||
|
||||
return c.list();
|
||||
}
|
||||
|
||||
public List<Feriado> buscar(Date descferiado) {
|
||||
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;
|
||||
}
|
||||
|
||||
@Override
|
||||
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;
|
||||
|
@ -33,28 +29,32 @@ import javax.persistence.TemporalType;
|
|||
@Table(name = "FERIADO")
|
||||
public class Feriado implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
@Id
|
||||
@Basic(optional = false)
|
||||
@Column(name = "FERIADO_ID")
|
||||
@GeneratedValue(strategy = GenerationType.AUTO, generator = "FERIADO_SEQ")
|
||||
private Integer feriadoId;
|
||||
@Column(name = "FECFERIADO")
|
||||
@Temporal(TemporalType.DATE)
|
||||
private Date fecferiado;
|
||||
@Column(name = "DESCFERIADO")
|
||||
private String descferiado;
|
||||
@Column(name = "ACTIVO")
|
||||
private Boolean activo;
|
||||
@Column(name = "FECMODIF")
|
||||
@Temporal(TemporalType.TIMESTAMP)
|
||||
private Date fecmodif;
|
||||
@Column(name = "USUARIO_ID")
|
||||
private Integer usuarioId;
|
||||
private static final long serialVersionUID = 1L;
|
||||
@Id
|
||||
@Basic(optional = false)
|
||||
@Column(name = "FERIADO_ID")
|
||||
@GeneratedValue(strategy = GenerationType.AUTO, generator = "FERIADO_SEQ")
|
||||
private Integer feriadoId;
|
||||
@Column(name = "FECFERIADO")
|
||||
@Temporal(TemporalType.DATE)
|
||||
private Date fecferiado;
|
||||
@Column(name = "DESCFERIADO")
|
||||
private String descferiado;
|
||||
@Column(name = "ACTIVO")
|
||||
private Boolean activo;
|
||||
@Column(name = "FECMODIF")
|
||||
@Temporal(TemporalType.TIMESTAMP)
|
||||
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) {
|
||||
public Feriado(Integer feriadoId, Date fecferiado, String descferiado) {
|
||||
super();
|
||||
this.feriadoId = feriadoId;
|
||||
this.fecferiado = fecferiado;
|
||||
|
@ -62,13 +62,13 @@ public class Feriado implements Serializable {
|
|||
}
|
||||
|
||||
public Feriado() {
|
||||
}
|
||||
}
|
||||
|
||||
public Feriado(Integer feriadoId) {
|
||||
this.feriadoId = feriadoId;
|
||||
}
|
||||
public Feriado(Integer feriadoId) {
|
||||
this.feriadoId = feriadoId;
|
||||
}
|
||||
|
||||
public Integer getFeriadoId() {
|
||||
public Integer getFeriadoId() {
|
||||
return feriadoId;
|
||||
}
|
||||
|
||||
|
@ -93,59 +93,66 @@ public class Feriado implements Serializable {
|
|||
}
|
||||
|
||||
public Date getFecmodif() {
|
||||
return fecmodif;
|
||||
}
|
||||
return fecmodif;
|
||||
}
|
||||
|
||||
public Boolean getActivo() {
|
||||
return activo;
|
||||
}
|
||||
public Boolean getActivo() {
|
||||
return activo;
|
||||
}
|
||||
|
||||
public void setActivo(Boolean activo) {
|
||||
this.activo = activo;
|
||||
}
|
||||
public void setActivo(Boolean activo) {
|
||||
this.activo = activo;
|
||||
}
|
||||
|
||||
public void setFecmodif(Date fecmodif) {
|
||||
this.fecmodif = fecmodif;
|
||||
}
|
||||
public void setFecmodif(Date fecmodif) {
|
||||
this.fecmodif = fecmodif;
|
||||
}
|
||||
|
||||
public Integer getUsuarioId() {
|
||||
return usuarioId;
|
||||
}
|
||||
public Integer getUsuarioId() {
|
||||
return usuarioId;
|
||||
}
|
||||
|
||||
public void setUsuarioId(Integer usuarioId) {
|
||||
this.usuarioId = usuarioId;
|
||||
}
|
||||
public void setUsuarioId(Integer usuarioId) {
|
||||
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() {
|
||||
int hash = 0;
|
||||
hash += (feriadoId != null ? feriadoId.hashCode() : 0);
|
||||
return hash;
|
||||
}
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hash = 0;
|
||||
hash += (feriadoId != null ? feriadoId.hashCode() : 0);
|
||||
return hash;
|
||||
}
|
||||
|
||||
@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;
|
||||
}
|
||||
Feriado other = (Feriado) object;
|
||||
if ((this.feriadoId == null && other.feriadoId != null) || (this.feriadoId != null && !this.feriadoId.equals(other.feriadoId))) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public boolean equals(Object object) {
|
||||
if (!(object instanceof Feriado)) {
|
||||
return false;
|
||||
}
|
||||
Feriado other = (Feriado) object;
|
||||
if ((this.feriadoId == null && other.feriadoId != null) || (this.feriadoId != null && !this.feriadoId.equals(other.feriadoId))) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.descferiado;
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.descferiado;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -71,10 +71,10 @@ public class Ruta implements Serializable {
|
|||
@OneToOne
|
||||
@JoinColumn(name = "ORGAOCONCEDENTE_ID")
|
||||
private OrgaoConcedente orgaoConcedente;
|
||||
|
||||
|
||||
@Column(name = "INDSENTIDOIDA")
|
||||
private Boolean indSentidoIda;
|
||||
|
||||
|
||||
@Column(name = "NUMRUTA")
|
||||
private Integer numRuta;
|
||||
|
||||
|
@ -132,7 +132,6 @@ public class Ruta implements Serializable {
|
|||
public void setUsuarioId(Integer usuarioId) {
|
||||
this.usuarioId = usuarioId;
|
||||
}
|
||||
|
||||
|
||||
public Integer getNumRuta() {
|
||||
return numRuta;
|
||||
|
@ -230,7 +229,6 @@ public class Ruta implements Serializable {
|
|||
public void setOrgaoConcedente(OrgaoConcedente orgaoConcedente) {
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -392,12 +405,12 @@ public class CorridaServiceImpl implements CorridaService {
|
|||
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!tramoServicioService.existenTiemposTramosEsquema(esquemaCorrida.getEsquemacorridaId())){
|
||||
|
||||
if (!tramoServicioService.existenTiemposTramosEsquema(esquemaCorrida.getEsquemacorridaId())) {
|
||||
log.info("nao foi cadastrado o tempo de todos os trechos do esquema corrida=" + esquemaCorrida.getEsquemacorridaId());
|
||||
|
||||
return null;
|
||||
|
||||
|
||||
}
|
||||
|
||||
try {
|
||||
|
@ -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,41 +12,99 @@ 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")
|
||||
@Scope(value = "prototype")
|
||||
public class FeriadoCache {
|
||||
|
||||
private static Logger log = LoggerFactory.getLogger(FeriadoCache.class);
|
||||
|
||||
|
||||
@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);
|
||||
|
||||
Boolean ehFeriado = mapFeriado.get(strDataFeriado);
|
||||
|
||||
if (ehFeriado == null){
|
||||
ehFeriado = feriadoDAO.ehFeriado(new java.sql.Date(dataFeriado.getTime()));
|
||||
|
||||
mapFeriado.put(strDataFeriado, ehFeriado);
|
||||
KeyFeriadoMap key = new KeyFeriadoMap(strDataFeriado, empresa.getEmpresaId(), estadoOrigem.getEstadoId());
|
||||
|
||||
Boolean ehFeriado = mapFeriado.get(key);
|
||||
|
||||
if (ehFeriado == null) {
|
||||
ehFeriado = feriadoDAO.ehFeriado(new java.sql.Date(dataFeriado.getTime()), empresa, estadoOrigem);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
public void limpar(){
|
||||
|
||||
public void limpar() {
|
||||
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