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>
|
||||
<groupId>br.com.rjconsultores</groupId>
|
||||
<artifactId>ModelWeb</artifactId>
|
||||
<version>1.120.0</version>
|
||||
<version>1.121.0</version>
|
||||
|
||||
<distributionManagement>
|
||||
<repository>
|
||||
|
|
|
@ -145,6 +145,11 @@ public class ContratoCorporativo implements Serializable {
|
|||
this.clienteCorporativoId = clienteCorporativoId;
|
||||
this.nomeClienteCorp = nomeClienteCorp;
|
||||
}
|
||||
|
||||
public ContratoCorporativo(String numContrato) {
|
||||
this();
|
||||
this.numContrato = numContrato;
|
||||
}
|
||||
|
||||
public ContratoCorporativo(Long clienteCorporativoId, Date fecModif) {
|
||||
this();
|
||||
|
|
|
@ -33,7 +33,8 @@ public class Transportadora implements Serializable{
|
|||
private static final long serialVersionUID = -8441764653321195183L;
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "TRANSPORTADORA_SEQ")
|
||||
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "TRANSPORTADORA_SEQ")
|
||||
@Renderizado()
|
||||
@Column(name = "TRANSPORTADORA_ID")
|
||||
private Long transportadoraId;
|
||||
|
||||
|
@ -70,4 +71,8 @@ public class Transportadora implements Serializable{
|
|||
public Transportadora(String 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<VoucherVO> lerArquivo(String data) throws Exception;
|
||||
|
||||
}
|
||||
|
|
|
@ -121,7 +121,7 @@ public class MudancaMassivaContratoServiceImpl implements MudancaMassivaContrato
|
|||
if( linha.startsWith("ID;")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
TarifaGrupoContratoVO tarifa = new TarifaGrupoContratoVO();
|
||||
String[] split = linha.split(";");
|
||||
tarifa.setTarifaGrupoContratoId( split[0] );
|
||||
|
@ -137,7 +137,6 @@ public class MudancaMassivaContratoServiceImpl implements MudancaMassivaContrato
|
|||
|
||||
return arquivo;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@Transactional(readOnly = false)
|
||||
|
@ -174,7 +173,7 @@ public class MudancaMassivaContratoServiceImpl implements MudancaMassivaContrato
|
|||
return novo;
|
||||
}
|
||||
|
||||
private InputStream converterInputStream(String in) throws IOException {
|
||||
private InputStream converterInputStream(String in){
|
||||
byte[] buff = in.getBytes(StandardCharsets.UTF_8);
|
||||
return new ByteArrayInputStream(buff);
|
||||
}
|
||||
|
|
|
@ -1,6 +1,13 @@
|
|||
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.nio.charset.StandardCharsets;
|
||||
import java.text.ParseException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
|
@ -13,20 +20,26 @@ import org.springframework.transaction.annotation.Transactional;
|
|||
import org.zkoss.lang.Strings;
|
||||
import org.zkoss.util.resource.Labels;
|
||||
|
||||
import com.rjconsultores.ventaboletos.dao.TransportadoraDAO;
|
||||
import com.rjconsultores.ventaboletos.dao.VoucherDAO;
|
||||
import com.rjconsultores.ventaboletos.entidad.ContratoCorporativo;
|
||||
import com.rjconsultores.ventaboletos.entidad.Parada;
|
||||
import com.rjconsultores.ventaboletos.entidad.Transportadora;
|
||||
import com.rjconsultores.ventaboletos.entidad.Voucher;
|
||||
import com.rjconsultores.ventaboletos.enums.SituacaoVoucher;
|
||||
import com.rjconsultores.ventaboletos.service.VoucherService;
|
||||
import com.rjconsultores.ventaboletos.utilerias.DateUtil;
|
||||
import com.rjconsultores.ventaboletos.utilerias.UsuarioLogado;
|
||||
import com.rjconsultores.ventaboletos.vo.configuracioneccomerciales.VoucherVO;
|
||||
|
||||
@Service("voucherService")
|
||||
public class VoucherServiceImpl implements VoucherService {
|
||||
|
||||
|
||||
@Autowired
|
||||
private VoucherDAO voucherDAO;
|
||||
|
||||
@Autowired
|
||||
private TransportadoraDAO transportadoraDAO;
|
||||
|
||||
public List<Voucher> obtenerTodos() {
|
||||
return voucherDAO.obtenerTodos();
|
||||
|
@ -117,58 +130,84 @@ public class VoucherServiceImpl implements VoucherService {
|
|||
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>();
|
||||
for (Voucher vou : dados) {
|
||||
VoucherVO vo;
|
||||
|
||||
if( StringUtils.isNotEmpty(numContrato) && !vou.getContrato().getNumContrato().equals(numContrato)) {
|
||||
vo = VoucherVO.converteVoucher(vou);
|
||||
vo.setMensagem(Labels.getLabel("legalizacaoMassivaController.MSG.contratoDiferente"));
|
||||
retorno.add(vo);
|
||||
continue;
|
||||
}
|
||||
|
||||
if( !vou.getStatus().equals(SituacaoVoucher.EMITIDO.getValor())) {
|
||||
vo = VoucherVO.converteVoucher(vou);
|
||||
vo.setMensagem(Labels.getLabel("legalizacaoMassivaController.MSG.statusDiferente"));
|
||||
retorno.add(vo);
|
||||
continue;
|
||||
}
|
||||
|
||||
if( origem != null && !vou.getOrigenId().equals(origem.getParadaId())) {
|
||||
vo = VoucherVO.converteVoucher(vou);
|
||||
vo.setMensagem(Labels.getLabel("legalizacaoMassivaController.MSG.origemDiferente"));
|
||||
retorno.add(vo);
|
||||
continue;
|
||||
}
|
||||
|
||||
if( destino != null && !vou.getDestinoId().equals(destino.getParadaId())) {
|
||||
vo = VoucherVO.converteVoucher(vou);
|
||||
vo.setMensagem(Labels.getLabel("legalizacaoMassivaController.MSG.destinoDiferente"));
|
||||
retorno.add(vo);
|
||||
continue;
|
||||
}
|
||||
|
||||
try {
|
||||
vou.setValorLegalizado(valor);
|
||||
vou.setTransportadora(transportadora);
|
||||
vou.setStatus(SituacaoVoucher.LEGALIZADO.getValor());
|
||||
vou.setDataLegaliza(Calendar.getInstance().getTime());
|
||||
|
||||
vou = voucherDAO.actualizacion(vou);
|
||||
vo = VoucherVO.converteVoucher(vou);
|
||||
vo.setMensagem(Labels.getLabel("label.sucesso"));
|
||||
}catch (Exception e) {
|
||||
vo = VoucherVO.converteVoucher(vou);
|
||||
vo.setMensagem(e.getMessage());
|
||||
if( validarLegalizacao(numContrato, origem, destino, retorno, vou) ) {
|
||||
retorno.add(legalizar(transportadora, valor, vou));
|
||||
}
|
||||
|
||||
retorno.add(vo);
|
||||
}
|
||||
|
||||
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)) {
|
||||
vo = VoucherVO.converteVoucher(vou);
|
||||
vo.setMensagem(Labels.getLabel("legalizacaoMassivaController.MSG.contratoDiferente"));
|
||||
retorno.add(vo);
|
||||
return false;
|
||||
}
|
||||
|
||||
if( !vou.getStatus().equals(SituacaoVoucher.EMITIDO.getValor())) {
|
||||
vo = VoucherVO.converteVoucher(vou);
|
||||
vo.setMensagem(Labels.getLabel("legalizacaoMassivaController.MSG.statusDiferente"));
|
||||
retorno.add(vo);
|
||||
return false;
|
||||
}
|
||||
|
||||
if( origem != null && !vou.getOrigenId().equals(origem.getParadaId())) {
|
||||
vo = VoucherVO.converteVoucher(vou);
|
||||
vo.setMensagem(Labels.getLabel("legalizacaoMassivaController.MSG.origemDiferente"));
|
||||
retorno.add(vo);
|
||||
return false;
|
||||
}
|
||||
|
||||
if( destino != null && !vou.getDestinoId().equals(destino.getParadaId())) {
|
||||
vo = VoucherVO.converteVoucher(vou);
|
||||
vo.setMensagem(Labels.getLabel("legalizacaoMassivaController.MSG.destinoDiferente"));
|
||||
retorno.add(vo);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private VoucherVO legalizar(Transportadora transportadora, BigDecimal valor, Voucher vou) {
|
||||
VoucherVO vo;
|
||||
|
||||
try {
|
||||
vou.setValorLegalizado(valor);
|
||||
vou.setTransportadora(transportadora);
|
||||
vou.setStatus(SituacaoVoucher.LEGALIZADO.getValor());
|
||||
vou.setDataLegaliza(Calendar.getInstance().getTime());
|
||||
|
||||
vou = voucherDAO.actualizacion(vou);
|
||||
vo = VoucherVO.converteVoucher(vou);
|
||||
vo.setMensagem(Labels.getLabel("label.sucesso"));
|
||||
}catch (Exception e) {
|
||||
vo = VoucherVO.converteVoucher(vou);
|
||||
vo.setMensagem(e.getMessage());
|
||||
}
|
||||
|
||||
return vo;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public List<Voucher> faturar(List<Voucher> lista, Long numFatura, Date datCorte) {
|
||||
|
@ -196,4 +235,77 @@ public class VoucherServiceImpl implements VoucherService {
|
|||
|
||||
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.Voucher;
|
||||
import com.rjconsultores.ventaboletos.enums.SituacaoVoucher;
|
||||
import com.rjconsultores.ventaboletos.utilerias.DateUtil;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
@ -149,4 +150,14 @@ public class VoucherVO implements Serializable {
|
|||
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