Série para venda embarcada
bug#13748 dev:trevezani qua: git-svn-id: http://desenvolvimento.rjconsultores.com.br/repositorio/sco/AdmVenta/Model/trunk/modelWeb@91304 d1611594-4594-4d17-8e1d-87c2c4800839master
parent
2232c48237
commit
d1615f458f
|
@ -4,6 +4,9 @@ import com.rjconsultores.ventaboletos.entidad.CtrlSerieBPe;
|
|||
|
||||
public interface CtrlSerieBPeDAO extends GenericDAO<CtrlSerieBPe, Long> {
|
||||
|
||||
public void gerarSeqSerieBPe(Integer empresaId, String estado, Integer minvalue) throws RuntimeException;
|
||||
public Integer buscarSequencia(Integer empresaId, String estado);
|
||||
|
||||
public CtrlSerieBPe buscarPorEmpresaEstado(Integer empresaId, Integer estadoId);
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,12 @@
|
|||
package com.rjconsultores.ventaboletos.dao.hibernate;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.hibernate.Query;
|
||||
import org.hibernate.SessionFactory;
|
||||
import org.slf4j.Logger;
|
||||
|
@ -15,11 +22,88 @@ import com.rjconsultores.ventaboletos.entidad.CtrlSerieBPe;
|
|||
public class CtrlSerieBPeHibernateDAO extends GenericHibernateDAO<CtrlSerieBPe, Long> implements CtrlSerieBPeDAO {
|
||||
private static final Logger log = LoggerFactory.getLogger(CtrlSerieBPeHibernateDAO.class);
|
||||
|
||||
@Autowired
|
||||
private DataSource dataSource;
|
||||
|
||||
@Autowired
|
||||
public CtrlSerieBPeHibernateDAO(@Qualifier("sessionFactory") SessionFactory factory) {
|
||||
setSessionFactory(factory);
|
||||
}
|
||||
|
||||
public void gerarSeqSerieBPe(Integer empresaId, String estado, Integer minvalue) throws RuntimeException {
|
||||
Connection conn = null;
|
||||
|
||||
try {
|
||||
conn = dataSource.getConnection();
|
||||
|
||||
StringBuilder seq = new StringBuilder();
|
||||
seq.append("SERIE_BPE_");
|
||||
seq.append(estado).append("_");
|
||||
seq.append(empresaId).append("_");
|
||||
seq.append("SEQ");
|
||||
|
||||
if (!conn.createStatement().executeQuery("select SEQUENCE_NAME from DBA_SEQUENCES where SEQUENCE_NAME like '" + seq.toString() + "%'").next()) {
|
||||
conn.createStatement().execute("CREATE SEQUENCE " + seq.toString() + " MINVALUE 1 MAXVALUE 999 INCREMENT BY 1 START WITH " + minvalue.toString() + " ORDER NOCACHE");
|
||||
|
||||
log.info("SEQUENCIA " + seq.toString() + " GERADA COM SUCESSO.");
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
} finally {
|
||||
try {
|
||||
if (conn != null && !conn.isClosed()) {
|
||||
conn.close();
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
log.error(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Integer buscarSequencia(Integer empresaId, String estado) {
|
||||
Integer retorno = null;
|
||||
|
||||
Connection conn = null;
|
||||
Statement st = null;
|
||||
ResultSet rs = null;
|
||||
|
||||
try {
|
||||
conn = dataSource.getConnection();
|
||||
|
||||
StringBuilder seq = new StringBuilder();
|
||||
seq.append("SERIE_BPE_");
|
||||
seq.append(estado).append("_");
|
||||
seq.append(empresaId).append("_");
|
||||
seq.append("SEQ");
|
||||
|
||||
StringBuilder sql = new StringBuilder();
|
||||
sql.append("select ").append(seq.toString()).append(".nextval from dual");
|
||||
|
||||
st = conn.createStatement();
|
||||
rs = st.executeQuery(sql.toString());
|
||||
|
||||
rs.next();
|
||||
|
||||
retorno = rs.getInt(1);
|
||||
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
} finally {
|
||||
try { if (rs != null) rs.close(); } catch (Exception e) { log.error("", e); }
|
||||
try { if (st != null) st.close(); } catch (Exception e) { log.error("", e); }
|
||||
|
||||
try {
|
||||
if (conn != null && !conn.isClosed()) {
|
||||
conn.close();
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
log.error(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
return retorno;
|
||||
}
|
||||
|
||||
public CtrlSerieBPe buscarPorEmpresaEstado(Integer empresaId, Integer estadoId) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("SELECT ctrl ");
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
package com.rjconsultores.ventaboletos.service.impl;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
@ -49,15 +47,22 @@ public class ControleSerieEmbarcadaServiceImpl implements ControleSerieEmbarcada
|
|||
if (serieembarcada == null) {
|
||||
CtrlSerieBPe ctrlSerieBpe = ctrlSerieBPeDAO.buscarPorEmpresaEstado(controleSerieEmbarcada.getEmpresa().getEmpresaId(), controleSerieEmbarcada.getEstado().getEstadoId());
|
||||
|
||||
Integer serie = 0;
|
||||
Integer serie = 1;
|
||||
|
||||
if (ctrlSerieBpe != null) {
|
||||
serie = Integer.valueOf(ctrlSerieBpe.getSerie());
|
||||
if (ctrlSerieBpe == null) {
|
||||
try {
|
||||
ctrlSerieBPeDAO.gerarSeqSerieBPe(controleSerieEmbarcada.getEmpresa().getEmpresaId(), controleSerieEmbarcada.getEstado().getCveestado(), serie);
|
||||
} catch (Exception e) {
|
||||
serie = ctrlSerieBPeDAO.buscarSequencia(controleSerieEmbarcada.getEmpresa().getEmpresaId(), controleSerieEmbarcada.getEstado().getCveestado());
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
ctrlSerieBPeDAO.gerarSeqSerieBPe(controleSerieEmbarcada.getEmpresa().getEmpresaId(), controleSerieEmbarcada.getEstado().getCveestado(), Integer.valueOf(ctrlSerieBpe.getSerie()) + 1);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
|
||||
do {
|
||||
serie++;
|
||||
} while (ctrlSerieEmbarcadaDAO.validaPossuiDispositivo(controleSerieEmbarcada.getEmpresa().getEmpresaId(), controleSerieEmbarcada.getEstado().getEstadoId(), serie.toString()));
|
||||
serie = ctrlSerieBPeDAO.buscarSequencia(controleSerieEmbarcada.getEmpresa().getEmpresaId(), controleSerieEmbarcada.getEstado().getCveestado());
|
||||
}
|
||||
|
||||
serieembarcada = new SerieEmbarcada();
|
||||
serieembarcada.setSerie(serie.toString());
|
||||
|
|
Loading…
Reference in New Issue