Merge pull request 'Legalizacao Massiva por arquivo feat #AL-5054' (!299) from AL-5054 into master
Reviewed-on: adm/ModelWeb#299 Reviewed-by: Valdir Cordeiro <valdir.cordeiro@totvs.com.br>master
commit
07e9bd46f7
2
pom.xml
2
pom.xml
|
@ -3,7 +3,7 @@
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>br.com.rjconsultores</groupId>
|
<groupId>br.com.rjconsultores</groupId>
|
||||||
<artifactId>ModelWeb</artifactId>
|
<artifactId>ModelWeb</artifactId>
|
||||||
<version>1.120.0</version>
|
<version>1.121.0</version>
|
||||||
|
|
||||||
<distributionManagement>
|
<distributionManagement>
|
||||||
<repository>
|
<repository>
|
||||||
|
|
|
@ -146,6 +146,11 @@ public class ContratoCorporativo implements Serializable {
|
||||||
this.nomeClienteCorp = nomeClienteCorp;
|
this.nomeClienteCorp = nomeClienteCorp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ContratoCorporativo(String numContrato) {
|
||||||
|
this();
|
||||||
|
this.numContrato = numContrato;
|
||||||
|
}
|
||||||
|
|
||||||
public ContratoCorporativo(Long clienteCorporativoId, Date fecModif) {
|
public ContratoCorporativo(Long clienteCorporativoId, Date fecModif) {
|
||||||
this();
|
this();
|
||||||
this.clienteCorporativoId = clienteCorporativoId;
|
this.clienteCorporativoId = clienteCorporativoId;
|
||||||
|
|
|
@ -34,6 +34,7 @@ public class Transportadora implements Serializable{
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "TRANSPORTADORA_SEQ")
|
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "TRANSPORTADORA_SEQ")
|
||||||
|
@Renderizado()
|
||||||
@Column(name = "TRANSPORTADORA_ID")
|
@Column(name = "TRANSPORTADORA_ID")
|
||||||
private Long transportadoraId;
|
private Long transportadoraId;
|
||||||
|
|
||||||
|
@ -70,4 +71,8 @@ public class Transportadora implements Serializable{
|
||||||
public Transportadora(String nomeTransportadora) {
|
public Transportadora(String nomeTransportadora) {
|
||||||
this.nomeTransportadora = nomeTransportadora;
|
this.nomeTransportadora = nomeTransportadora;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Transportadora(Long transportadoraId) {
|
||||||
|
this.transportadoraId = transportadoraId;
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -19,4 +19,6 @@ public interface VoucherService extends GenericService<Voucher, Long> {
|
||||||
|
|
||||||
public List<Voucher> faturar(List<Voucher> lista, Long numFatura, Date datCorte);
|
public List<Voucher> faturar(List<Voucher> lista, Long numFatura, Date datCorte);
|
||||||
|
|
||||||
|
public List<VoucherVO> lerArquivo(String data) throws Exception;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -138,7 +138,6 @@ public class MudancaMassivaContratoServiceImpl implements MudancaMassivaContrato
|
||||||
return arquivo;
|
return arquivo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(readOnly = false)
|
@Transactional(readOnly = false)
|
||||||
public boolean salvarTarifaVO(TarifaGrupoContratoVO tarifaVO, Integer usuarioId) throws SQLException{
|
public boolean salvarTarifaVO(TarifaGrupoContratoVO tarifaVO, Integer usuarioId) throws SQLException{
|
||||||
|
@ -174,7 +173,7 @@ public class MudancaMassivaContratoServiceImpl implements MudancaMassivaContrato
|
||||||
return novo;
|
return novo;
|
||||||
}
|
}
|
||||||
|
|
||||||
private InputStream converterInputStream(String in) throws IOException {
|
private InputStream converterInputStream(String in){
|
||||||
byte[] buff = in.getBytes(StandardCharsets.UTF_8);
|
byte[] buff = in.getBytes(StandardCharsets.UTF_8);
|
||||||
return new ByteArrayInputStream(buff);
|
return new ByteArrayInputStream(buff);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,13 @@
|
||||||
package com.rjconsultores.ventaboletos.service.impl;
|
package com.rjconsultores.ventaboletos.service.impl;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.ByteArrayInputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.text.ParseException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
@ -13,12 +20,15 @@ import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.zkoss.lang.Strings;
|
import org.zkoss.lang.Strings;
|
||||||
import org.zkoss.util.resource.Labels;
|
import org.zkoss.util.resource.Labels;
|
||||||
|
|
||||||
|
import com.rjconsultores.ventaboletos.dao.TransportadoraDAO;
|
||||||
import com.rjconsultores.ventaboletos.dao.VoucherDAO;
|
import com.rjconsultores.ventaboletos.dao.VoucherDAO;
|
||||||
|
import com.rjconsultores.ventaboletos.entidad.ContratoCorporativo;
|
||||||
import com.rjconsultores.ventaboletos.entidad.Parada;
|
import com.rjconsultores.ventaboletos.entidad.Parada;
|
||||||
import com.rjconsultores.ventaboletos.entidad.Transportadora;
|
import com.rjconsultores.ventaboletos.entidad.Transportadora;
|
||||||
import com.rjconsultores.ventaboletos.entidad.Voucher;
|
import com.rjconsultores.ventaboletos.entidad.Voucher;
|
||||||
import com.rjconsultores.ventaboletos.enums.SituacaoVoucher;
|
import com.rjconsultores.ventaboletos.enums.SituacaoVoucher;
|
||||||
import com.rjconsultores.ventaboletos.service.VoucherService;
|
import com.rjconsultores.ventaboletos.service.VoucherService;
|
||||||
|
import com.rjconsultores.ventaboletos.utilerias.DateUtil;
|
||||||
import com.rjconsultores.ventaboletos.utilerias.UsuarioLogado;
|
import com.rjconsultores.ventaboletos.utilerias.UsuarioLogado;
|
||||||
import com.rjconsultores.ventaboletos.vo.configuracioneccomerciales.VoucherVO;
|
import com.rjconsultores.ventaboletos.vo.configuracioneccomerciales.VoucherVO;
|
||||||
|
|
||||||
|
@ -28,6 +38,9 @@ public class VoucherServiceImpl implements VoucherService {
|
||||||
@Autowired
|
@Autowired
|
||||||
private VoucherDAO voucherDAO;
|
private VoucherDAO voucherDAO;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private TransportadoraDAO transportadoraDAO;
|
||||||
|
|
||||||
public List<Voucher> obtenerTodos() {
|
public List<Voucher> obtenerTodos() {
|
||||||
return voucherDAO.obtenerTodos();
|
return voucherDAO.obtenerTodos();
|
||||||
}
|
}
|
||||||
|
@ -117,38 +130,67 @@ public class VoucherServiceImpl implements VoucherService {
|
||||||
null,
|
null,
|
||||||
null);
|
null);
|
||||||
|
|
||||||
|
return efetuarLegalizacao(numContrato, transportadora, valor, origem, destino, dados);
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<VoucherVO> efetuarLegalizacao(String numContrato,
|
||||||
|
Transportadora transportadora,
|
||||||
|
BigDecimal valor,
|
||||||
|
Parada origem,
|
||||||
|
Parada destino,
|
||||||
|
List<Voucher> dados) {
|
||||||
|
|
||||||
List<VoucherVO> retorno = new ArrayList<VoucherVO>();
|
List<VoucherVO> retorno = new ArrayList<VoucherVO>();
|
||||||
for (Voucher vou : dados) {
|
for (Voucher vou : dados) {
|
||||||
VoucherVO vo;
|
|
||||||
|
|
||||||
|
if( validarLegalizacao(numContrato, origem, destino, retorno, vou) ) {
|
||||||
|
retorno.add(legalizar(transportadora, valor, vou));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return retorno;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean validarLegalizacao(String numContrato,
|
||||||
|
Parada origem,
|
||||||
|
Parada destino,
|
||||||
|
List<VoucherVO> retorno,
|
||||||
|
Voucher vou) {
|
||||||
|
VoucherVO vo;
|
||||||
if( StringUtils.isNotEmpty(numContrato) && !vou.getContrato().getNumContrato().equals(numContrato)) {
|
if( StringUtils.isNotEmpty(numContrato) && !vou.getContrato().getNumContrato().equals(numContrato)) {
|
||||||
vo = VoucherVO.converteVoucher(vou);
|
vo = VoucherVO.converteVoucher(vou);
|
||||||
vo.setMensagem(Labels.getLabel("legalizacaoMassivaController.MSG.contratoDiferente"));
|
vo.setMensagem(Labels.getLabel("legalizacaoMassivaController.MSG.contratoDiferente"));
|
||||||
retorno.add(vo);
|
retorno.add(vo);
|
||||||
continue;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( !vou.getStatus().equals(SituacaoVoucher.EMITIDO.getValor())) {
|
if( !vou.getStatus().equals(SituacaoVoucher.EMITIDO.getValor())) {
|
||||||
vo = VoucherVO.converteVoucher(vou);
|
vo = VoucherVO.converteVoucher(vou);
|
||||||
vo.setMensagem(Labels.getLabel("legalizacaoMassivaController.MSG.statusDiferente"));
|
vo.setMensagem(Labels.getLabel("legalizacaoMassivaController.MSG.statusDiferente"));
|
||||||
retorno.add(vo);
|
retorno.add(vo);
|
||||||
continue;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( origem != null && !vou.getOrigenId().equals(origem.getParadaId())) {
|
if( origem != null && !vou.getOrigenId().equals(origem.getParadaId())) {
|
||||||
vo = VoucherVO.converteVoucher(vou);
|
vo = VoucherVO.converteVoucher(vou);
|
||||||
vo.setMensagem(Labels.getLabel("legalizacaoMassivaController.MSG.origemDiferente"));
|
vo.setMensagem(Labels.getLabel("legalizacaoMassivaController.MSG.origemDiferente"));
|
||||||
retorno.add(vo);
|
retorno.add(vo);
|
||||||
continue;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( destino != null && !vou.getDestinoId().equals(destino.getParadaId())) {
|
if( destino != null && !vou.getDestinoId().equals(destino.getParadaId())) {
|
||||||
vo = VoucherVO.converteVoucher(vou);
|
vo = VoucherVO.converteVoucher(vou);
|
||||||
vo.setMensagem(Labels.getLabel("legalizacaoMassivaController.MSG.destinoDiferente"));
|
vo.setMensagem(Labels.getLabel("legalizacaoMassivaController.MSG.destinoDiferente"));
|
||||||
retorno.add(vo);
|
retorno.add(vo);
|
||||||
continue;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private VoucherVO legalizar(Transportadora transportadora, BigDecimal valor, Voucher vou) {
|
||||||
|
VoucherVO vo;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
vou.setValorLegalizado(valor);
|
vou.setValorLegalizado(valor);
|
||||||
vou.setTransportadora(transportadora);
|
vou.setTransportadora(transportadora);
|
||||||
|
@ -163,10 +205,7 @@ public class VoucherServiceImpl implements VoucherService {
|
||||||
vo.setMensagem(e.getMessage());
|
vo.setMensagem(e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
retorno.add(vo);
|
return vo;
|
||||||
}
|
|
||||||
|
|
||||||
return retorno;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -196,4 +235,77 @@ public class VoucherServiceImpl implements VoucherService {
|
||||||
|
|
||||||
return lista;
|
return lista;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional
|
||||||
|
public List<VoucherVO> lerArquivo(String stream) throws Exception{
|
||||||
|
List<VoucherVO> retorno = new ArrayList<VoucherVO>();
|
||||||
|
|
||||||
|
List<VoucherVO> arquivosEnviados = processarArquivoEnviado(stream);
|
||||||
|
|
||||||
|
for (VoucherVO vo : arquivosEnviados) {
|
||||||
|
if( StringUtils.isNotEmpty(vo.getMensagem()) ) {
|
||||||
|
retorno.add(vo);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
Voucher voucher = voucherDAO.obtenerID(vo.getVoucherId());
|
||||||
|
|
||||||
|
if ( !validarLegalizacao(null, null, null, retorno, voucher)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
Transportadora transportadora = transportadoraDAO.obtenerID(vo.getTransportadora().getTransportadoraId());
|
||||||
|
|
||||||
|
retorno.add(legalizar(transportadora, vo.getValorLegalizado(), voucher));
|
||||||
|
}
|
||||||
|
|
||||||
|
return retorno;
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<VoucherVO> processarArquivoEnviado(String stream) throws IOException, ParseException {
|
||||||
|
String linha = null;
|
||||||
|
List<VoucherVO> arquivo = new ArrayList<VoucherVO>();
|
||||||
|
|
||||||
|
InputStream inputStream = converterInputStream(stream);
|
||||||
|
|
||||||
|
try( BufferedReader leitor = new BufferedReader(new InputStreamReader(inputStream))){
|
||||||
|
|
||||||
|
while ((linha = leitor.readLine()) != null) {
|
||||||
|
if( linha.isEmpty() || linha.startsWith("ID;")) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
VoucherVO voucher = new VoucherVO();
|
||||||
|
String[] split = linha.split(";");
|
||||||
|
voucher.setVoucherId( Long.valueOf(split[0]) );
|
||||||
|
voucher.setContrato( new ContratoCorporativo(split[1]) );
|
||||||
|
voucher.setDataValidade( DateUtil.getDateFromString(split[2], DateUtil.ddMMaaaa));
|
||||||
|
voucher.setStatus(SituacaoVoucher.EMITIDO.getValor());
|
||||||
|
voucher.setDescOrigem(split[3]);
|
||||||
|
voucher.setDescDestino(split[4]);
|
||||||
|
voucher.setValorLicitado( new BigDecimal(split[5].replace(',', '.')) );
|
||||||
|
|
||||||
|
if( split[6].equals("INFORMAR")) {
|
||||||
|
voucher.setMensagem(Labels.getLabel("legalizacaoMassivaController.MSG.faltaValor"));
|
||||||
|
}else {
|
||||||
|
voucher.setValorLegalizado( new BigDecimal(split[6].replace(',', '.')) );
|
||||||
|
}
|
||||||
|
|
||||||
|
if( split[7].equals("INFORMAR")) {
|
||||||
|
voucher.setMensagem(Labels.getLabel("legalizacaoMassivaController.MSG.faltaTransportadora"));
|
||||||
|
}else {
|
||||||
|
voucher.setTransportadora( new Transportadora( Long.valueOf( split[7])) );
|
||||||
|
}
|
||||||
|
arquivo.add(voucher);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return arquivo;
|
||||||
|
}
|
||||||
|
|
||||||
|
private InputStream converterInputStream(String in){
|
||||||
|
byte[] buff = in.getBytes(StandardCharsets.UTF_8);
|
||||||
|
return new ByteArrayInputStream(buff);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,7 @@ import com.rjconsultores.ventaboletos.entidad.ContratoCorporativo;
|
||||||
import com.rjconsultores.ventaboletos.entidad.Transportadora;
|
import com.rjconsultores.ventaboletos.entidad.Transportadora;
|
||||||
import com.rjconsultores.ventaboletos.entidad.Voucher;
|
import com.rjconsultores.ventaboletos.entidad.Voucher;
|
||||||
import com.rjconsultores.ventaboletos.enums.SituacaoVoucher;
|
import com.rjconsultores.ventaboletos.enums.SituacaoVoucher;
|
||||||
|
import com.rjconsultores.ventaboletos.utilerias.DateUtil;
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
@ -149,4 +150,14 @@ public class VoucherVO implements Serializable {
|
||||||
return new VoucherVO(pai);
|
return new VoucherVO(pai);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String toCsv() {
|
||||||
|
String base = "\r\n%s;%s;%s;%s;%s;INFORMAR;INFORMAR";
|
||||||
|
return String.format(base, getVoucherId(),
|
||||||
|
getNumContrato(),
|
||||||
|
DateUtil.getStringDate(getDataValidade()),
|
||||||
|
getDescOrigem(),
|
||||||
|
getDescDestino(),
|
||||||
|
getValorLicitado());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue