fixes bug#17529

dev:thiago
qua:

git-svn-id: http://desenvolvimento.rjconsultores.com.br/repositorio/sco/AdmVenta/Model/trunk/modelWeb@99318 d1611594-4594-4d17-8e1d-87c2c4800839
master
wilian 2019-12-11 14:43:07 +00:00
parent 4daeda560d
commit 7c0a6899bb
5 changed files with 242 additions and 0 deletions

View File

@ -5,8 +5,10 @@ import java.util.Date;
import java.util.List;
import com.rjconsultores.ventaboletos.entidad.Estado;
import com.rjconsultores.ventaboletos.exception.BusinessException;
import com.rjconsultores.ventaboletos.utilerias.exportacao.bpe.ExportacaoBPEVo;
import com.rjconsultores.ventaboletos.utilerias.fiscal.vo.FiscalRdi;
import com.rjconsultores.ventaboletos.vo.bpe.BPeVO;
public interface BpeDAO {
@ -15,4 +17,8 @@ public interface BpeDAO {
public ExportacaoBPEVo buscarRegistroExportacaoBpe(Connection connection, Date inicio, Date fim, Integer empresaId, String cveestado, boolean consultaOtimizada);
public String buscarXmlBPE(Connection connection, String chBpe);
public List<BPeVO> buscarBPeRejeitadosContingencia(Integer empresaId, String numBpe, String chbpe, Date dtVendaInicio, Date dtVendaFim, List<Integer> estados, List<String> codigosRejeicoes);
public void definirBPeRejeitadoSefazReenvio(Integer bpeId, String codstat) throws BusinessException;
}

View File

@ -15,7 +15,12 @@ import java.util.Map;
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.hibernate.Query;
import org.hibernate.SessionFactory;
import org.hibernate.transform.AliasToBeanResultTransformer;
import org.hibernate.type.IntegerType;
import org.hibernate.type.StringType;
import org.hibernate.type.TimestampType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
@ -24,9 +29,11 @@ import org.springframework.stereotype.Repository;
import com.rjconsultores.ventaboletos.dao.BpeDAO;
import com.rjconsultores.ventaboletos.entidad.Constante;
import com.rjconsultores.ventaboletos.entidad.Estado;
import com.rjconsultores.ventaboletos.exception.BusinessException;
import com.rjconsultores.ventaboletos.service.ConstanteService;
import com.rjconsultores.ventaboletos.utilerias.DateUtil;
import com.rjconsultores.ventaboletos.utilerias.MoneyHelper;
import com.rjconsultores.ventaboletos.utilerias.UsuarioLogado;
import com.rjconsultores.ventaboletos.utilerias.exportacao.bpe.ExportacaoBPEBase;
import com.rjconsultores.ventaboletos.utilerias.exportacao.bpe.ExportacaoBPEVo;
import com.rjconsultores.ventaboletos.utilerias.exportacao.bpe.ExportacaoBPEVo.TipoComp;
@ -34,6 +41,7 @@ import com.rjconsultores.ventaboletos.utilerias.exportacao.bpe.xml.BPeUtil;
import com.rjconsultores.ventaboletos.utilerias.fiscal.vo.DetalhadoFiscal;
import com.rjconsultores.ventaboletos.utilerias.fiscal.vo.FiscalRdi;
import com.rjconsultores.ventaboletos.utilerias.fiscal.vo.RdiValidacion;
import com.rjconsultores.ventaboletos.vo.bpe.BPeVO;
import com.rjconsultores.ventaboletos.web.utilerias.NamedParameterStatement;
import com.rjconsultores.ventaboletos.web.utilerias.spring.AppContext;
@ -1539,4 +1547,98 @@ public class BpeHibernateDAO extends HibernateDaoSupport implements BpeDAO {
return sql.toString();
}
@Override
public List<BPeVO> buscarBPeRejeitadosContingencia(Integer empresaId, String numBpe, String chbpe, Date dtVendaInicio, Date dtVendaFim, List<Integer> estados, List<String> codigosRejeicoes) {
StringBuilder sQuery = new StringBuilder();
sQuery.append("select bpe.bpe_id bpeId, bpe.codstat, bpe.chbpe, b.num_bpe numBpe, b.numserie_bpe numserieBpe, e.cveestado uf, bpe.motivo, ")
.append("bpe.errocontingencia, b.fechorventa, em.nombempresa ")
.append("from bpe bpe ")
.append("join boleto b on b.boleto_id = bpe.boleto_id ")
.append("join marca m on m.marca_id = b.marca_id ")
.append("left join estado e on e.codibge = bpe.uf ")
.append("join empresa em on em.empresa_id = m.empresa_id ")
.append("where bpe.activo = 1 ")
.append("and b.activo = 1 ")
.append("and bpe.codstat in ('-10','-20') ");
if(empresaId != null) {
sQuery.append("and m.empresa_id = :empresaId ");
}
if(StringUtils.isNotBlank(numBpe)) {
sQuery.append("and b.num_bpe = :numBpe ");
}
if(StringUtils.isNotBlank(chbpe)) {
sQuery.append("and bpe.chbpe = :chbpe ");
}
if(dtVendaInicio != null && dtVendaFim != null) {
sQuery.append("and b.fechorventa between to_date(:dtVendaInicio,'dd/mm/yyyy hh24:mi') and to_date(:dtVendaFim,'dd/mm/yyyy hh24:mi') ");
}
if(estados != null && !estados.isEmpty()) {
sQuery.append("and e.estado_id in (:estados) ");
}
if(codigosRejeicoes != null && !codigosRejeicoes.isEmpty()) {
sQuery.append("and substr(bpe.errocontingencia,1,3) in (:codigosRejeicoes) ");
}
Query qr = getSession().createSQLQuery(sQuery.toString())
.addScalar("bpeId", IntegerType.INSTANCE)
.addScalar("codstat", StringType.INSTANCE)
.addScalar("chbpe", StringType.INSTANCE)
.addScalar("numBpe", StringType.INSTANCE)
.addScalar("numserieBpe", StringType.INSTANCE)
.addScalar("uf", StringType.INSTANCE)
.addScalar("motivo", StringType.INSTANCE)
.addScalar("errocontingencia", StringType.INSTANCE)
.addScalar("fechorventa", TimestampType.INSTANCE)
.addScalar("nombempresa", StringType.INSTANCE)
.setResultTransformer(new AliasToBeanResultTransformer(BPeVO.class));
if(empresaId != null) {
qr.setParameter("empresaId", empresaId);
}
if(StringUtils.isNotBlank(numBpe)) {
qr.setParameter("numBpe", numBpe);
}
if(StringUtils.isNotBlank(chbpe)) {
qr.setParameter("chbpe", chbpe);
}
if(dtVendaInicio != null && dtVendaFim != null) {
qr.setParameter("dtVendaInicio", DateUtil.getStringDate(DateUtil.inicioFecha(dtVendaInicio), "dd/MM/yyyy HH:mm"));
qr.setParameter("dtVendaFim", DateUtil.getStringDate(DateUtil.fimFecha(dtVendaFim), "dd/MM/yyyy HH:mm"));
}
if(estados != null && !estados.isEmpty()) {
qr.setParameterList("estados", estados);
}
if(codigosRejeicoes != null && !codigosRejeicoes.isEmpty()) {
qr.setParameterList("codigosRejeicoes", codigosRejeicoes);
}
return qr.list();
}
@Override
public void definirBPeRejeitadoSefazReenvio(Integer bpeId, String codstat) throws BusinessException {
String codstatUpdate = null;
if("-10".equals(codstat)) {
codstatUpdate = "-1";
} else if("-20".equals(codstat)) {
codstatUpdate = "-2";
}
if(codstatUpdate == null || bpeId == null) {
throw new BusinessException("Não foi possível atualizar o BPe selecionado");
}
try {
Query qr = getSession().createSQLQuery("update bpe set codstat = :codstatUpdate, xmlregular = null, fecmodif = :dataAtual, usuario_id = :usuarioId where bpe_id = :bpeId");
qr.setParameter("codstatUpdate", codstatUpdate);
qr.setParameter("bpeId", bpeId);
qr.setParameter("dataAtual", new Date());
qr.setParameter("usuarioId", UsuarioLogado.getUsuarioLogado().getUsuarioId());
qr.executeUpdate();
} catch (Exception e) {
log.error(e.getMessage(), e);
throw new BusinessException(e.getMessage(), e);
}
}
}

View File

@ -5,7 +5,9 @@ import java.util.List;
import com.rjconsultores.ventaboletos.entidad.Empresa;
import com.rjconsultores.ventaboletos.entidad.Estado;
import com.rjconsultores.ventaboletos.exception.BusinessException;
import com.rjconsultores.ventaboletos.utilerias.fiscal.vo.FiscalRdi;
import com.rjconsultores.ventaboletos.vo.bpe.BPeVO;
public interface BpeService {
@ -14,5 +16,9 @@ public interface BpeService {
public String buscarArquivoExportacaoBPE(Date inicio, Date fim, Empresa empresa, Estado estado, String nomeArquivo, boolean consultaOtimizada);
public String buscarXmlBPE(String chBpe);
public List<BPeVO> buscarBPeRejeitadosContingencia(Integer empresaId, String numBpe, String chbpe, Date dtVendaInicio, Date dtVendaFim, List<Integer> estados, List<String> codigosRejeicoes);
public void definirBPeRejeitadoSefazReenvio(List<BPeVO> bpesReenvio) throws BusinessException;
}

View File

@ -11,14 +11,17 @@ import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.datasource.DataSourceUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.rjconsultores.ventaboletos.dao.BpeDAO;
import com.rjconsultores.ventaboletos.entidad.Empresa;
import com.rjconsultores.ventaboletos.entidad.Estado;
import com.rjconsultores.ventaboletos.exception.BusinessException;
import com.rjconsultores.ventaboletos.service.BpeService;
import com.rjconsultores.ventaboletos.utilerias.exportacao.ExportacaoBpe;
import com.rjconsultores.ventaboletos.utilerias.exportacao.bpe.ExportacaoBPEVo;
import com.rjconsultores.ventaboletos.utilerias.fiscal.vo.FiscalRdi;
import com.rjconsultores.ventaboletos.vo.bpe.BPeVO;
@Service("bpeService")
public class BpeServiceImpl implements BpeService {
@ -101,4 +104,18 @@ public class BpeServiceImpl implements BpeService {
return DataSourceUtils.getConnection(dataSourceRead);
}
@Override
@Transactional
public List<BPeVO> buscarBPeRejeitadosContingencia(Integer empresaId, String numBpe, String chbpe, Date dtVendaInicio, Date dtVendaFim, List<Integer> estados, List<String> codigosRejeicoes) {
return bpeDAO.buscarBPeRejeitadosContingencia(empresaId, numBpe, chbpe, dtVendaInicio, dtVendaFim, estados, codigosRejeicoes);
}
@Override
@Transactional
public void definirBPeRejeitadoSefazReenvio(List<BPeVO> bpesReenvio) throws BusinessException {
for (BPeVO bpe : bpesReenvio) {
bpeDAO.definirBPeRejeitadoSefazReenvio(bpe.getBpeId(), bpe.getCodstat());
}
}
}

View File

@ -0,0 +1,111 @@
package com.rjconsultores.ventaboletos.vo.bpe;
import java.util.Date;
import org.apache.commons.lang.StringUtils;
public class BPeVO {
private Integer bpeId;
private String codstat;
private String chbpe;
private String numBpe;
private String numserieBpe;
private String uf;
private String motivo;
private String errocontingencia;
private Date fechorventa;
private String nombempresa;
public Integer getBpeId() {
return bpeId;
}
public void setBpeId(Integer bpeId) {
this.bpeId = bpeId;
}
public String getCodstat() {
return codstat;
}
public void setCodstat(String codstat) {
this.codstat = codstat;
}
public String getChbpe() {
return chbpe;
}
public void setChbpe(String chbpe) {
this.chbpe = chbpe;
}
public String getNumBpeSerie() {
StringBuilder numBpeSerie = new StringBuilder();
if(StringUtils.isNotBlank(numBpe)) {
numBpeSerie.append(numBpe);
}
if(numBpeSerie.length() > 0 && StringUtils.isNotBlank(numserieBpe)) {
numBpeSerie.append("/").append(numserieBpe);
}
return numBpeSerie.toString();
}
public String getUf() {
return uf;
}
public void setUf(String uf) {
this.uf = uf;
}
public String getMotivo() {
return motivo;
}
public void setMotivo(String motivo) {
this.motivo = motivo;
}
public String getErrocontingencia() {
return errocontingencia;
}
public void setErrocontingencia(String errocontingencia) {
this.errocontingencia = errocontingencia;
}
public Date getFechorventa() {
return fechorventa;
}
public void setFechorventa(Date fechorventa) {
this.fechorventa = fechorventa;
}
public String getNumBpe() {
return numBpe;
}
public void setNumBpe(String numBpe) {
this.numBpe = numBpe;
}
public String getNumserieBpe() {
return numserieBpe;
}
public void setNumserieBpe(String numserieBpe) {
this.numserieBpe = numserieBpe;
}
public String getNombempresa() {
return nombempresa;
}
public void setNombempresa(String nombempresa) {
this.nombempresa = nombempresa;
}
}