fixes bug#7510
git-svn-id: http://desenvolvimento.rjconsultores.com.br/repositorio/sco/AdmVenta/Model/trunk/modelWeb@56344 d1611594-4594-4d17-8e1d-87c2c4800839master
parent
a258737a1a
commit
ccf1cb0e96
|
@ -1,5 +1,6 @@
|
|||
package com.rjconsultores.ventaboletos.dao;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
@ -14,12 +15,12 @@ public interface FiscalDAO {
|
|||
|
||||
public int gerarRegistroP2_F2(List<EsquemaCorrida> lsEsquemaCorrida, Date dataDe, Date dataAte);
|
||||
|
||||
public List<ImportacionFiscalVO> buscaDatosFiscaisECF(Date inicio, Date fim, Integer empresaId, boolean isCancelados) throws SQLException;
|
||||
public List<ImportacionFiscalVO> buscaDatosFiscaisECF(Date inicio, Date fim, Integer empresaId, boolean isCancelados, Connection connection) throws SQLException;
|
||||
|
||||
public List<ImportacionFiscalReducaoZVO> buscaDatosFiscaisReducaoZ(Date inicio, Date fim, Integer empresaId) throws SQLException;
|
||||
public List<ImportacionFiscalReducaoZVO> buscaDatosFiscaisReducaoZ(Date inicio, Date fim, Integer empresaId, Connection connection) throws SQLException;
|
||||
|
||||
public List<ImportacionManualFiscalVO> buscaDatosFiscaisECFManual(Date inicio, Date fim, Integer empresaId) throws SQLException;
|
||||
public List<ImportacionManualFiscalVO> buscaDatosFiscaisECFManual(Date inicio, Date fim, Integer empresaId, Connection connection) throws SQLException;
|
||||
|
||||
public List<ImportacionNaoFiscalVO> buscaDatosNaoFiscais(Date inicio, Date fim, Integer empresaId) throws SQLException;
|
||||
public List<ImportacionNaoFiscalVO> buscaDatosNaoFiscais(Date inicio, Date fim, Integer empresaId, Connection connection) throws SQLException;
|
||||
|
||||
}
|
||||
|
|
|
@ -9,13 +9,7 @@ import java.util.ArrayList;
|
|||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.hibernate.Query;
|
||||
import org.hibernate.SessionFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import com.rjconsultores.ventaboletos.dao.FiscalDAO;
|
||||
|
@ -30,27 +24,21 @@ import com.rjconsultores.ventaboletos.vo.impressaofiscal.ItemFiscalVO;
|
|||
import com.rjconsultores.ventaboletos.vo.impressaofiscal.SituacaoTributaria;
|
||||
|
||||
@Repository("fiscalDAO")
|
||||
public class FiscalHibernateDAO extends GenericHibernateDAO<String, String> implements FiscalDAO {
|
||||
public class FiscalHibernateDAO implements FiscalDAO {
|
||||
|
||||
private static Logger log = Logger.getLogger(FiscalHibernateDAO.class);
|
||||
|
||||
public static final String DATE_FORMAT_FISCAL = "yyyyMMdd";
|
||||
|
||||
@Autowired
|
||||
private DataSource dataSourceRead;
|
||||
public FiscalHibernateDAO() {
|
||||
|
||||
@Autowired
|
||||
public FiscalHibernateDAO(@Qualifier("sessionFactory") SessionFactory factory) {
|
||||
setSessionFactory(factory);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ImportacionManualFiscalVO> buscaDatosFiscaisECFManual(Date inicio, Date fim, Integer empresaId) throws SQLException {
|
||||
public List<ImportacionManualFiscalVO> buscaDatosFiscaisECFManual(Date inicio, Date fim, Integer empresaId,Connection connection) throws SQLException {
|
||||
PreparedStatement stmt = null;
|
||||
ResultSet rset = null;
|
||||
|
||||
try {
|
||||
|
||||
StringBuilder sql = new StringBuilder();
|
||||
sql.append("select r4.numserie20 as numImpressora, ");
|
||||
sql.append(" coalesce(r4.coo, b.numfoliopreimpreso) as coo, ");
|
||||
|
@ -150,7 +138,7 @@ public class FiscalHibernateDAO extends GenericHibernateDAO<String, String> impl
|
|||
|
||||
List<ImportacionManualFiscalVO> listManuais = new ArrayList<ImportacionManualFiscalVO>();
|
||||
|
||||
stmt = getConexao().prepareStatement(sql.toString());
|
||||
stmt = connection.prepareStatement(sql.toString());
|
||||
stmt.setFetchSize(100);
|
||||
stmt.setTimestamp(1, new java.sql.Timestamp(inicio.getTime()));
|
||||
stmt.setTimestamp(2, new java.sql.Timestamp(fim.getTime()));
|
||||
|
@ -201,20 +189,14 @@ public class FiscalHibernateDAO extends GenericHibernateDAO<String, String> impl
|
|||
|
||||
return listManuais;
|
||||
|
||||
} catch (Exception e) {
|
||||
log.info(e.getMessage(), e);
|
||||
throw new SQLException(e);
|
||||
} finally {
|
||||
fecharconexao();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ImportacionFiscalReducaoZVO> buscaDatosFiscaisReducaoZ(Date inicio, Date fim, Integer empresaId) throws SQLException {
|
||||
public List<ImportacionFiscalReducaoZVO> buscaDatosFiscaisReducaoZ(Date inicio, Date fim, Integer empresaId,Connection connection) throws SQLException {
|
||||
PreparedStatement stmt = null;
|
||||
ResultSet rset = null;
|
||||
|
||||
try {
|
||||
|
||||
StringBuilder sql = new StringBuilder();
|
||||
sql.append("SELECT r2.datamov AS datamov, ");
|
||||
|
@ -281,7 +263,7 @@ public class FiscalHibernateDAO extends GenericHibernateDAO<String, String> impl
|
|||
|
||||
List<ImportacionFiscalReducaoZVO> listRedZ = new ArrayList<ImportacionFiscalReducaoZVO>();
|
||||
|
||||
stmt = getConexao().prepareStatement(sql.toString());
|
||||
stmt = connection.prepareStatement(sql.toString());
|
||||
stmt.setFetchSize(100);
|
||||
stmt.setInt(1, empresaId);
|
||||
stmt.setString(2, DateUtil.getStringDate(inicio, DATE_FORMAT_FISCAL));
|
||||
|
@ -314,12 +296,7 @@ public class FiscalHibernateDAO extends GenericHibernateDAO<String, String> impl
|
|||
|
||||
return listRedZ;
|
||||
|
||||
} catch (Exception e) {
|
||||
log.info(e.getMessage(), e);
|
||||
throw new SQLException(e);
|
||||
} finally {
|
||||
fecharconexao();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public String sqlFiscaisECFCancelados() {
|
||||
|
@ -488,14 +465,14 @@ public class FiscalHibernateDAO extends GenericHibernateDAO<String, String> impl
|
|||
}
|
||||
|
||||
@Override
|
||||
public List<ImportacionFiscalVO> buscaDatosFiscaisECF(Date inicio, Date fim, Integer empresaId, boolean isCancelados) throws SQLException {
|
||||
public List<ImportacionFiscalVO> buscaDatosFiscaisECF(Date inicio, Date fim, Integer empresaId, boolean isCancelados,Connection connection) throws SQLException {
|
||||
PreparedStatement stmt = null;
|
||||
ResultSet rset = null;
|
||||
|
||||
try {
|
||||
|
||||
|
||||
String sql = isCancelados ? sqlFiscaisECFCancelados() : sqlFiscaisECF();
|
||||
stmt = getConexao().prepareStatement(sql);
|
||||
stmt = connection.prepareStatement(sql);
|
||||
stmt.setFetchSize(100);
|
||||
stmt.setString(1, DateUtil.getStringDate(inicio, DATE_FORMAT_FISCAL));
|
||||
stmt.setString(2, DateUtil.getStringDate(fim, DATE_FORMAT_FISCAL));
|
||||
|
@ -569,13 +546,6 @@ public class FiscalHibernateDAO extends GenericHibernateDAO<String, String> impl
|
|||
}
|
||||
|
||||
return list;
|
||||
|
||||
} catch (Exception e) {
|
||||
log.info(e.getMessage(), e);
|
||||
throw new SQLException(e);
|
||||
} finally {
|
||||
fecharconexao();
|
||||
}
|
||||
}
|
||||
|
||||
private boolean validaValorExiste(BigDecimal valor) {
|
||||
|
@ -711,12 +681,17 @@ public class FiscalHibernateDAO extends GenericHibernateDAO<String, String> impl
|
|||
sb.append(" and c.corrida_id in (:corridaId) ");
|
||||
sb.append(" and ROWNUM < 2 ");
|
||||
|
||||
Query query = getSession().createSQLQuery(sb.toString());
|
||||
query.setParameterList("corridaId", idsCorrida);
|
||||
query.setDate("datIni", new java.sql.Date(dataDe.getTime()));
|
||||
query.setDate("datFim", new java.sql.Date(dataAte.getTime()));
|
||||
//FIXME - Implementar a inserção na base de dados. Atenção para checar se tem q ficar em transação ou não
|
||||
// Query query = getSession().createSQLQuery(sb.toString());
|
||||
// query.setParameterList("corridaId", idsCorrida);
|
||||
// query.setDate("datIni", new java.sql.Date(dataDe.getTime()));
|
||||
// query.setDate("datFim", new java.sql.Date(dataAte.getTime()));
|
||||
|
||||
return query.executeUpdate();
|
||||
// return query.executeUpdate();
|
||||
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
private Integer[] getIdsCorrida(List<EsquemaCorrida> lsEsquemaCorrida) {
|
||||
|
@ -756,13 +731,15 @@ public class FiscalHibernateDAO extends GenericHibernateDAO<String, String> impl
|
|||
sb.append(" and ROWNUM < 2 ");
|
||||
|
||||
Integer[] idsCorrida = getIdsCorrida(lsEsquemaCorrida);
|
||||
//FIXME - Implementar a inserção na base de dados. Atenção para checar se tem q ficar em transação ou não
|
||||
// Query query = getSession().createSQLQuery(sb.toString());
|
||||
// query.setParameterList("corridaId", idsCorrida);
|
||||
// query.setDate("datIni", new java.sql.Date(dataDe.getTime()));
|
||||
// query.setDate("datFim", new java.sql.Date(dataAte.getTime()));
|
||||
//
|
||||
// return query.executeUpdate();
|
||||
|
||||
Query query = getSession().createSQLQuery(sb.toString());
|
||||
query.setParameterList("corridaId", idsCorrida);
|
||||
query.setDate("datIni", new java.sql.Date(dataDe.getTime()));
|
||||
query.setDate("datFim", new java.sql.Date(dataAte.getTime()));
|
||||
|
||||
return query.executeUpdate();
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -773,11 +750,11 @@ public class FiscalHibernateDAO extends GenericHibernateDAO<String, String> impl
|
|||
}
|
||||
|
||||
@Override
|
||||
public List<ImportacionNaoFiscalVO> buscaDatosNaoFiscais(Date inicio, Date fim, Integer empresaId) throws SQLException {
|
||||
public List<ImportacionNaoFiscalVO> buscaDatosNaoFiscais(Date inicio, Date fim, Integer empresaId,Connection connection) throws SQLException {
|
||||
PreparedStatement stmt = null;
|
||||
ResultSet rset = null;
|
||||
|
||||
try {
|
||||
|
||||
|
||||
StringBuilder sQuery = new StringBuilder();
|
||||
sQuery.append("SELECT TEE.TIPOEVENTOEXTRA_ID AS TIPOEVENTOEXTRAID, TEE.DESCTIPOEVENTO AS DESCTIPOEVENTO, ")
|
||||
|
@ -791,7 +768,7 @@ public class FiscalHibernateDAO extends GenericHibernateDAO<String, String> impl
|
|||
.append("GROUP BY TEE.TIPOEVENTOEXTRA_ID, TEE.DESCTIPOEVENTO, TRUNC(CD.FECHORVTA) ")
|
||||
.append("ORDER BY TRUNC(CD.FECHORVTA), TEE.DESCTIPOEVENTO ");
|
||||
|
||||
stmt = getConexao().prepareStatement(sQuery.toString());
|
||||
stmt = connection.prepareStatement(sQuery.toString());
|
||||
stmt.setInt(1, empresaId);
|
||||
stmt.setDate(2, new java.sql.Date(inicio.getTime()));
|
||||
stmt.setDate(3, new java.sql.Date(fim.getTime()));
|
||||
|
@ -810,26 +787,6 @@ public class FiscalHibernateDAO extends GenericHibernateDAO<String, String> impl
|
|||
|
||||
return importacionNaoFiscalVOs;
|
||||
|
||||
} catch (Exception e) {
|
||||
log.info(e.getMessage(), e);
|
||||
throw new SQLException(e);
|
||||
} finally {
|
||||
fecharconexao();
|
||||
}
|
||||
}
|
||||
|
||||
public Connection getConexao() throws SQLException {
|
||||
return dataSourceRead.getConnection();
|
||||
}
|
||||
|
||||
private void fecharconexao() {
|
||||
try {
|
||||
if (getConexao() != null && !getConexao().isClosed()) {
|
||||
getConexao().close();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("Erro ao fechar a conexion", e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ import java.io.IOException;
|
|||
import java.io.OutputStreamWriter;
|
||||
import java.io.PrintWriter;
|
||||
import java.math.BigDecimal;
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
|
@ -17,12 +18,15 @@ import java.util.Date;
|
|||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.apache.poi.hssf.usermodel.HSSFRow;
|
||||
import org.apache.poi.hssf.usermodel.HSSFSheet;
|
||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.jdbc.datasource.DataSourceUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
|
@ -68,6 +72,9 @@ public class FiscalServiceImpl implements FiscalService {
|
|||
@Autowired
|
||||
private FiscalDAO fiscalDAO;
|
||||
|
||||
@Autowired
|
||||
private DataSource dataSourceRead;
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public int gerarRegistroP2_F2(List<EsquemaCorrida> lsEsquemaCorrida, Date dataDe, Date dataAte) {
|
||||
|
@ -76,7 +83,7 @@ public class FiscalServiceImpl implements FiscalService {
|
|||
|
||||
@Override
|
||||
public File importacionFiscalECFManual(Date inicio, Date fim, Empresa empresa) {
|
||||
|
||||
Connection connection = null;
|
||||
try {
|
||||
String nomeArquivo = "fiscal_ecf_manual_" + DateUtil.getStringDate(Calendar.getInstance().getTime(), "yyyyMMddhhmmss");
|
||||
File arquivo = File.createTempFile(nomeArquivo, ".txt");
|
||||
|
@ -99,7 +106,9 @@ public class FiscalServiceImpl implements FiscalService {
|
|||
inicio = DateUtil.inicioFecha(inicio);
|
||||
fim = DateUtil.fimFecha(fim);
|
||||
|
||||
List<ImportacionManualFiscalVO> list = agruparItensFiscaisManual(fiscalDAO.buscaDatosFiscaisECFManual(inicio, fim, empresa.getEmpresaId()));
|
||||
connection = DataSourceUtils.getConnection(dataSourceRead);
|
||||
|
||||
List<ImportacionManualFiscalVO> list = agruparItensFiscaisManual(fiscalDAO.buscaDatosFiscaisECFManual(inicio, fim, empresa.getEmpresaId(),connection));
|
||||
for (ImportacionManualFiscalVO imf : list) {
|
||||
|
||||
qtdDoc++;
|
||||
|
@ -191,6 +200,15 @@ public class FiscalServiceImpl implements FiscalService {
|
|||
log.error("", e);
|
||||
} catch (SQLException e) {
|
||||
log.error("", e);
|
||||
}finally{
|
||||
try {
|
||||
if (connection != null && !connection.isClosed()){
|
||||
connection.close();
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
log.error("error fechar conexão",e);
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
|
@ -314,6 +332,7 @@ public class FiscalServiceImpl implements FiscalService {
|
|||
}
|
||||
|
||||
public File importacionFiscalReducaoZ(Date inicio, Date fim, Empresa empresa) {
|
||||
Connection connection = null;
|
||||
|
||||
try {
|
||||
String nomeArquivo = "fiscal_reducao_z_" + DateUtil.getStringDate(Calendar.getInstance().getTime(), "yyyyMMddhhmmss");
|
||||
|
@ -331,7 +350,9 @@ public class FiscalServiceImpl implements FiscalService {
|
|||
String abertura = aberturaDeArquivo("0", dataAgora, cnpjFilial, brancos371, sequencial);
|
||||
gravarArq.print(abertura + QUEBRA_LINHA);
|
||||
|
||||
List<ImportacionFiscalReducaoZVO> list = agruparReducaoZ(fiscalDAO.buscaDatosFiscaisReducaoZ(inicio, fim, empresa.getEmpresaId()));
|
||||
connection = DataSourceUtils.getConnection(dataSourceRead);
|
||||
|
||||
List<ImportacionFiscalReducaoZVO> list = agruparReducaoZ(fiscalDAO.buscaDatosFiscaisReducaoZ(inicio, fim, empresa.getEmpresaId(),connection));
|
||||
|
||||
for (ImportacionFiscalReducaoZVO ifrZ : list) {
|
||||
|
||||
|
@ -417,6 +438,15 @@ public class FiscalServiceImpl implements FiscalService {
|
|||
log.error("", e);
|
||||
} catch (SQLException e) {
|
||||
log.error("", e);
|
||||
}finally{
|
||||
try {
|
||||
if (connection != null && !connection.isClosed()){
|
||||
connection.close();
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
log.error("error fechar conexão",e);
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
|
@ -450,6 +480,7 @@ public class FiscalServiceImpl implements FiscalService {
|
|||
}
|
||||
|
||||
private File importacionFiscalECFGenerico(Date inicio, Date fim, Empresa empresa, boolean isCancelados) {
|
||||
Connection connection = null;
|
||||
|
||||
try {
|
||||
String nomeArquivo = "fiscal_ecf_" + DateUtil.getStringDate(Calendar.getInstance().getTime(), "yyyyMMddhhmmss");
|
||||
|
@ -473,7 +504,9 @@ public class FiscalServiceImpl implements FiscalService {
|
|||
String header = null;
|
||||
List<String> itensDocs = new ArrayList<String>();
|
||||
|
||||
List<ImportacionFiscalVO> list = fiscalDAO.buscaDatosFiscaisECF(inicio, fim, empresa.getEmpresaId(), isCancelados);
|
||||
connection = DataSourceUtils.getConnection(dataSourceRead);
|
||||
|
||||
List<ImportacionFiscalVO> list = fiscalDAO.buscaDatosFiscaisECF(inicio, fim, empresa.getEmpresaId(), isCancelados,connection);
|
||||
|
||||
for (ImportacionFiscalVO item : list) {
|
||||
|
||||
|
@ -582,7 +615,17 @@ public class FiscalServiceImpl implements FiscalService {
|
|||
log.error("", e);
|
||||
} catch (SQLException e) {
|
||||
log.error("", e);
|
||||
}finally{
|
||||
try {
|
||||
if (connection != null && !connection.isClosed()){
|
||||
connection.close();
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
log.error("error fechar conexão",e);
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -1003,11 +1046,25 @@ public class FiscalServiceImpl implements FiscalService {
|
|||
|
||||
@Override
|
||||
public File importacionNaoFiscal(Date inicio, Date fim, Empresa empresa) {
|
||||
Connection connection = null;
|
||||
try {
|
||||
List<ImportacionNaoFiscalVO> importacionNaoFiscalVOs = fiscalDAO.buscaDatosNaoFiscais(inicio, fim, empresa.getEmpresaId());
|
||||
connection = DataSourceUtils.getConnection(dataSourceRead);
|
||||
|
||||
List<ImportacionNaoFiscalVO> importacionNaoFiscalVOs = fiscalDAO.buscaDatosNaoFiscais(inicio, fim, empresa.getEmpresaId(),connection);
|
||||
|
||||
return new ArchivoIntegracionNaoFiscal().gerarArquivo(empresa.getCnpj(), importacionNaoFiscalVOs);
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
}finally{
|
||||
try {
|
||||
if (connection != null && !connection.isClosed()){
|
||||
connection.close();
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
log.error("error fechar conexão",e);
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue