bug#17121
qua:Wallysson dev:Thiago git-svn-id: http://desenvolvimento.rjconsultores.com.br/repositorio/sco/AdmVenta/Model/trunk/modelWeb@99566 d1611594-4594-4d17-8e1d-87c2c4800839master
parent
eb307505f9
commit
3ce7f6463b
|
@ -0,0 +1,12 @@
|
|||
package com.rjconsultores.ventaboletos.dao;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.rjconsultores.ventaboletos.entidad.Cotacao;
|
||||
import com.rjconsultores.ventaboletos.entidad.Moneda;
|
||||
|
||||
public interface CotacaoDAO extends GenericDAO<Cotacao, Integer> {
|
||||
|
||||
void inativarCotacoesAntigas(Moneda moneda);
|
||||
|
||||
}
|
|
@ -0,0 +1,51 @@
|
|||
package com.rjconsultores.ventaboletos.dao.hibernate;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.hibernate.Criteria;
|
||||
import org.hibernate.SessionFactory;
|
||||
import org.hibernate.criterion.Restrictions;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import com.rjconsultores.ventaboletos.dao.CotacaoDAO;
|
||||
import com.rjconsultores.ventaboletos.entidad.Cotacao;
|
||||
import com.rjconsultores.ventaboletos.entidad.Moneda;
|
||||
|
||||
@Repository("cotacaoHibernateDAO")
|
||||
@SuppressWarnings("unchecked")
|
||||
public class CotacaoHibernateDAO extends GenericHibernateDAO<Cotacao, Integer>
|
||||
implements CotacaoDAO {
|
||||
|
||||
@Autowired
|
||||
public CotacaoHibernateDAO(@Qualifier("sessionFactory") SessionFactory factory) {
|
||||
setSessionFactory(factory);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Cotacao> obtenerTodos() {
|
||||
Criteria c = getSession().createCriteria(getPersistentClass());
|
||||
c.add(Restrictions.eq("activo", Boolean.TRUE));
|
||||
|
||||
return c.list();
|
||||
}
|
||||
|
||||
public List<Cotacao> buscar(String descmoneda) {
|
||||
Criteria c = getSession().createCriteria(getPersistentClass());
|
||||
c.add(Restrictions.eq("activo", Boolean.TRUE));
|
||||
|
||||
return c.list();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void inativarCotacoesAntigas(Moneda moneda) {
|
||||
|
||||
StringBuilder sql = new StringBuilder("UPDATE COTACAO SET ACTIVO = 0 WHERE MONEDA_ID = ");
|
||||
sql.append(moneda.getMonedaId());
|
||||
|
||||
getSession().createSQLQuery(sql.toString()).executeUpdate();
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,106 @@
|
|||
package com.rjconsultores.ventaboletos.entidad;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
|
||||
import javax.persistence.Basic;
|
||||
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.OneToOne;
|
||||
import javax.persistence.SequenceGenerator;
|
||||
import javax.persistence.Table;
|
||||
import javax.persistence.Temporal;
|
||||
import javax.persistence.TemporalType;
|
||||
|
||||
|
||||
@Entity
|
||||
@SequenceGenerator(name = "COTACAO_SEQ", sequenceName = "COTACAO_SEQ", allocationSize = 1)
|
||||
@Table(name = "COTACAO")
|
||||
public class Cotacao implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Id
|
||||
@Basic(optional = false)
|
||||
@GeneratedValue(strategy = GenerationType.AUTO, generator = "COTACAO_SEQ")
|
||||
@Column(name = "COTACAO_ID")
|
||||
private Integer cotacaoId;
|
||||
@OneToOne
|
||||
@JoinColumn(name = "MONEDA_ID")
|
||||
private Moneda moneda;
|
||||
@Column(name = "VALOR", precision = 7)
|
||||
private BigDecimal valor;
|
||||
@Column(name = "ACTIVO")
|
||||
private Boolean activo;
|
||||
@Column(name = "FECMODIF")
|
||||
@Temporal(TemporalType.TIMESTAMP)
|
||||
private Date fecmodif;
|
||||
@Column(name = "USUARIO_ID")
|
||||
private Integer usuarioId;
|
||||
|
||||
public Integer getCotacaoId() {
|
||||
return cotacaoId;
|
||||
}
|
||||
|
||||
public void setCotacaoId(Integer cotacaoId) {
|
||||
this.cotacaoId = cotacaoId;
|
||||
}
|
||||
|
||||
public Moneda getMoneda() {
|
||||
return moneda;
|
||||
}
|
||||
|
||||
public void setMoneda(Moneda moneda) {
|
||||
this.moneda = moneda;
|
||||
}
|
||||
|
||||
public BigDecimal getValor() {
|
||||
return valor;
|
||||
}
|
||||
|
||||
public void setValor(BigDecimal valor) {
|
||||
this.valor = valor;
|
||||
}
|
||||
|
||||
public Boolean getActivo() {
|
||||
return activo;
|
||||
}
|
||||
|
||||
public void setActivo(Boolean activo) {
|
||||
this.activo = activo;
|
||||
}
|
||||
|
||||
public Date getFecmodif() {
|
||||
return fecmodif;
|
||||
}
|
||||
|
||||
public void setFecmodif(Date fecmodif) {
|
||||
this.fecmodif = fecmodif;
|
||||
}
|
||||
|
||||
public Integer getUsuarioId() {
|
||||
return usuarioId;
|
||||
}
|
||||
|
||||
public void setUsuarioId(Integer usuarioId) {
|
||||
this.usuarioId = usuarioId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object object) {
|
||||
if (!(object instanceof Cotacao)) {
|
||||
return false;
|
||||
}
|
||||
Cotacao other = (Cotacao) object;
|
||||
if ((this.cotacaoId == null && other.cotacaoId != null) || (this.cotacaoId != null && !this.cotacaoId.equals(other.cotacaoId))) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
package com.rjconsultores.ventaboletos.service;
|
||||
|
||||
import com.rjconsultores.ventaboletos.entidad.Cotacao;
|
||||
import com.rjconsultores.ventaboletos.entidad.Moneda;
|
||||
|
||||
public interface CotacaoService extends GenericService<Cotacao, Integer> {
|
||||
|
||||
public void inativarCotacoesAntigas(Moneda moneda);
|
||||
}
|
|
@ -12,7 +12,7 @@ import java.util.List;
|
|||
* @author Rafius
|
||||
*/
|
||||
public interface MonedaService extends GenericService<Moneda, Integer> {
|
||||
|
||||
public List<Moneda> buscar(String descmoneda);
|
||||
|
||||
public List<Moneda> obterTodosExcetoReais();
|
||||
}
|
||||
|
|
|
@ -0,0 +1,67 @@
|
|||
package com.rjconsultores.ventaboletos.service.impl;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import com.rjconsultores.ventaboletos.dao.CotacaoDAO;
|
||||
import com.rjconsultores.ventaboletos.entidad.Cotacao;
|
||||
import com.rjconsultores.ventaboletos.entidad.Moneda;
|
||||
import com.rjconsultores.ventaboletos.service.CotacaoService;
|
||||
import com.rjconsultores.ventaboletos.utilerias.UsuarioLogado;
|
||||
|
||||
@Service("cotacaoService")
|
||||
public class CotacaoServiceImpl implements CotacaoService {
|
||||
|
||||
private static Logger log = Logger.getLogger(CotacaoServiceImpl.class);
|
||||
|
||||
@Autowired
|
||||
private CotacaoDAO cotacaoDAO;
|
||||
|
||||
public List<Cotacao> obtenerTodos() {
|
||||
return cotacaoDAO.obtenerTodos();
|
||||
}
|
||||
|
||||
public Cotacao obtenerID(Integer id) {
|
||||
return cotacaoDAO.obtenerID(id);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public Cotacao suscribir(Cotacao entidad) {
|
||||
entidad.setUsuarioId(UsuarioLogado.getUsuarioLogado().getUsuarioId());
|
||||
entidad.setFecmodif(Calendar.getInstance().getTime());
|
||||
entidad.setActivo(Boolean.TRUE);
|
||||
|
||||
return cotacaoDAO.suscribir(entidad);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public Cotacao actualizacion(Cotacao entidad) {
|
||||
entidad.setUsuarioId(UsuarioLogado.getUsuarioLogado().getUsuarioId());
|
||||
entidad.setFecmodif(Calendar.getInstance().getTime());
|
||||
entidad.setActivo(Boolean.TRUE);
|
||||
|
||||
return cotacaoDAO.actualizacion(entidad);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void borrar(Cotacao entidad) {
|
||||
entidad.setUsuarioId(UsuarioLogado.getUsuarioLogado().getUsuarioId());
|
||||
entidad.setFecmodif(Calendar.getInstance().getTime());
|
||||
entidad.setActivo(Boolean.FALSE);
|
||||
|
||||
cotacaoDAO.actualizacion(entidad);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void inativarCotacoesAntigas(Moneda moneda) {
|
||||
|
||||
cotacaoDAO.inativarCotacoesAntigas(moneda);
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -8,8 +8,12 @@ import com.rjconsultores.ventaboletos.dao.MonedaDAO;
|
|||
import com.rjconsultores.ventaboletos.entidad.Moneda;
|
||||
import com.rjconsultores.ventaboletos.service.MonedaService;
|
||||
import com.rjconsultores.ventaboletos.utilerias.UsuarioLogado;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
@ -21,6 +25,8 @@ import org.springframework.transaction.annotation.Transactional;
|
|||
@Service("monedaService")
|
||||
public class MonedaServiceImpl implements MonedaService {
|
||||
|
||||
private static Logger log = Logger.getLogger(MonedaServiceImpl.class);
|
||||
|
||||
@Autowired
|
||||
private MonedaDAO monedaDAO;
|
||||
|
||||
|
@ -63,5 +69,22 @@ public class MonedaServiceImpl implements MonedaService {
|
|||
return monedaDAO.buscar(descmoneda);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Moneda> obterTodosExcetoReais() {
|
||||
try {
|
||||
List<Moneda> monedas = monedaDAO.obtenerTodos();
|
||||
|
||||
Moneda real = new Moneda();
|
||||
real.setMonedaId(1);
|
||||
|
||||
monedas.remove(real);
|
||||
|
||||
return monedas;
|
||||
} catch (Exception ex) {
|
||||
log.error(ex.getMessage(), ex);
|
||||
return new ArrayList<Moneda>();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue