diff --git a/pom.xml b/pom.xml
index bf6319c58..c0c9c144b 100644
--- a/pom.xml
+++ b/pom.xml
@@ -3,7 +3,7 @@
4.0.0
br.com.rjconsultores
ModelWeb
- 1.103.3
+ 1.104.0
diff --git a/src/com/rjconsultores/ventaboletos/dao/TarifaGrupoContratoDAO.java b/src/com/rjconsultores/ventaboletos/dao/TarifaGrupoContratoDAO.java
index 91b273939..91be55282 100644
--- a/src/com/rjconsultores/ventaboletos/dao/TarifaGrupoContratoDAO.java
+++ b/src/com/rjconsultores/ventaboletos/dao/TarifaGrupoContratoDAO.java
@@ -3,9 +3,12 @@ package com.rjconsultores.ventaboletos.dao;
import java.util.List;
import com.rjconsultores.ventaboletos.entidad.TarifaGrupoContrato;
+import com.rjconsultores.ventaboletos.vo.configuracioneccomerciales.TarifaGrupoContratoVO;
public interface TarifaGrupoContratoDAO extends GenericDAO{
public boolean gravarTarifasGrupoContrato( List tarifas);
+ public TarifaGrupoContrato obterTarifaPeloVo(TarifaGrupoContratoVO tarifa);
+
}
diff --git a/src/com/rjconsultores/ventaboletos/dao/hibernate/GenericHibernateDAO.java b/src/com/rjconsultores/ventaboletos/dao/hibernate/GenericHibernateDAO.java
index bf70a4d48..de4d22bc7 100644
--- a/src/com/rjconsultores/ventaboletos/dao/hibernate/GenericHibernateDAO.java
+++ b/src/com/rjconsultores/ventaboletos/dao/hibernate/GenericHibernateDAO.java
@@ -9,7 +9,6 @@ import java.util.List;
import org.hibernate.Criteria;
import org.hibernate.HibernateException;
-import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.Projections;
diff --git a/src/com/rjconsultores/ventaboletos/dao/hibernate/TarifaGrupoContratoHibernateDAO.java b/src/com/rjconsultores/ventaboletos/dao/hibernate/TarifaGrupoContratoHibernateDAO.java
index 139cb550d..646ee4386 100644
--- a/src/com/rjconsultores/ventaboletos/dao/hibernate/TarifaGrupoContratoHibernateDAO.java
+++ b/src/com/rjconsultores/ventaboletos/dao/hibernate/TarifaGrupoContratoHibernateDAO.java
@@ -11,6 +11,7 @@ import org.springframework.stereotype.Repository;
import com.rjconsultores.ventaboletos.dao.TarifaGrupoContratoDAO;
import com.rjconsultores.ventaboletos.entidad.TarifaGrupoContrato;
+import com.rjconsultores.ventaboletos.vo.configuracioneccomerciales.TarifaGrupoContratoVO;
@SuppressWarnings("unchecked")
@Repository("tarifaGrupoContratoDAO")
@@ -42,4 +43,12 @@ public class TarifaGrupoContratoHibernateDAO extends GenericHibernateDAO arquivosEnviados = processaArquivoEnviado(stream);
+
+ if( arquivosEnviados == null ) {
+ throw new BusinessException("mudancaMassivaContrato.MSG.arquivoSemTarifa");
+ }
+
+ Integer usuarioId = UsuarioLogado.getUsuarioLogado().getUsuarioId();
+ for (TarifaGrupoContratoVO tarifa : arquivosEnviados) {
+
+ try {
+ if( tarifa.getNumContrato() == null && tarifa.getGrupoContratoId() == null ) {
+ erros++;
+ detalhado.append(Labels.getLabel("mudancaMassivaContrato.MSG.semContratoGrupo"))
+ .append(tarifa.getTarifaGrupoContratoId()).append(".\n");
+ }else
+ if( !tarifa.getNumContrato().equals(numContrato) &&
+ !tarifa.getGrupoContratoId().equals(grupo.getGrupoContratoId())) {
+ erros++;
+ detalhado.append(Labels.getLabel("mudancaMassivaContrato.MSG.contratoGrupoDiferente"))
+ .append(tarifa.getTarifaGrupoContratoId()).append(".\n");
+ }else
+ if( salvarTarifaVO( tarifa, usuarioId )) {
+ atualizados++;
+ detalhado.append(Labels.getLabel("label.processado"))
+ .append(tarifa.getTarifaGrupoContratoId()).append(".\n");
+ }else {
+ erros++;
+ detalhado.append(Labels.getLabel("label.naoProcessado"))
+ .append(tarifa.getTarifaGrupoContratoId()).append(".\n");
+ }
+ } catch (SQLException se) {
+ detalhado.append(Labels.getLabel("mudancaMassivaContrato.MSG.dbErro"))
+ .append(tarifa.getTarifaGrupoContratoId()).append(".\n");
+ log.error(se);
+ erros++;
+ }
+ }
+
+ resultado.append(Labels.getLabel("label.arquivoProcessado"));
+ if(erros > 0) {
+ resultado.append(Labels.getLabel("label.comRessalva")).append(".\n");
+ }else {
+ resultado.append(Labels.getLabel("label.comSucesso")).append(".\n");
+ }
+ resultado.append(Labels.getLabel("label.processado")).append(atualizados).append(".\n");
+ resultado.append(Labels.getLabel("label.naoProcessado")).append(erros).append(".\n");
+ resultado.append(detalhado);
+ return resultado.toString();
+
+ } catch (IOException ioe) {
+ resultado.append(Labels.getLabel("MSG.Error.processarArquivo"));
+ log.error(ioe);
+ return resultado.toString();
+ } catch (RuntimeException re) {
+ resultado.append( re.getMessage() );
+ log.error(re);
+ return resultado.toString();
+ } catch (Exception e) {
+ resultado.append(Labels.getLabel("MSG.Error.processarArquivo"));
+ log.error(e);
+ return resultado.toString();
+ }
+ }
+
+ private List processaArquivoEnviado(String stream) throws IOException {
+ String linha = null;
+ List arquivo = new ArrayList();
+
+ InputStream inputStream = converterInputStream(stream);
+
+ try( BufferedReader leitor = new BufferedReader(new InputStreamReader(inputStream))){
+
+ while ((linha = leitor.readLine()) != null) {
+ TarifaGrupoContratoVO tarifa = new TarifaGrupoContratoVO();
+ String[] split = linha.split(";");
+ tarifa.setTarifaGrupoContratoId( split[0] );
+ tarifa.setNumContrato(split[1]);
+ tarifa.setGrupoContratoId(split[2]);
+ tarifa.setCveOrigem(split[3]);
+ tarifa.setDescOrigem(split[4]);
+ tarifa.setCveDestino(split[5]);
+ tarifa.setDescDestino(split[6]);
+ tarifa.setTarifa(split[7]);
+ arquivo.add(tarifa);
+ }
+ }
+
+ return arquivo;
+ }
+
+
+ @Override
+ @Transactional(readOnly = false)
+ public boolean salvarTarifaVO(TarifaGrupoContratoVO tarifaVO, Integer usuarioId) throws SQLException{
+ TarifaGrupoContrato tarifa = tarifaDAO.obterTarifaPeloVo( tarifaVO );
+
+ tarifa.setActivo(false);
+ tarifa.setUsuarioId(usuarioId);
+ tarifa.setFecModif(Calendar.getInstance().getTime());
+ tarifaDAO.actualizacion(tarifa);
+
+ TarifaGrupoContrato tarifanew = duplicaTarifa(tarifa);
+ tarifanew.setActivo(true);
+ tarifanew.setTarifa(tarifaVO.getTarifa());
+ tarifanew.setUsuarioId(usuarioId);
+ tarifanew.setFecModif(Calendar.getInstance().getTime());
+ tarifaDAO.suscribir(tarifanew);
+
+ return tarifanew.getTarifaGrupoContratoId()!=null;
+
+ }
+
+ private TarifaGrupoContrato duplicaTarifa(TarifaGrupoContrato tarifa) {
+ TarifaGrupoContrato novo = new TarifaGrupoContrato();
+ novo.setTarifa(tarifa.getTarifa());
+ novo.setOrigem(tarifa.getOrigem());
+ novo.setDestino(tarifa.getDestino());
+ novo.setIndCobertura(tarifa.isIndCobertura());
+ novo.setGrupoContrato(tarifa.getGrupoContrato());
+ novo.setClaseServicio(tarifa.getClaseServicio());
+ novo.setActivo(tarifa.isActivo());
+ novo.setUsuarioId(tarifa.getUsuarioId());
+ novo.setFecModif(Calendar.getInstance().getTime());
+ return novo;
+ }
+
+ private InputStream converterInputStream(String in) throws IOException {
+ byte[] buff = in.getBytes(StandardCharsets.UTF_8);
+ return new ByteArrayInputStream(buff);
+ }
+
+
+}
diff --git a/src/com/rjconsultores/ventaboletos/vo/configuracioneccomerciales/TarifaGrupoContratoVO.java b/src/com/rjconsultores/ventaboletos/vo/configuracioneccomerciales/TarifaGrupoContratoVO.java
new file mode 100644
index 000000000..81524b5e8
--- /dev/null
+++ b/src/com/rjconsultores/ventaboletos/vo/configuracioneccomerciales/TarifaGrupoContratoVO.java
@@ -0,0 +1,64 @@
+package com.rjconsultores.ventaboletos.vo.configuracioneccomerciales;
+
+import java.io.Serializable;
+import java.math.BigDecimal;
+import java.util.Date;
+
+import javax.persistence.Temporal;
+import javax.persistence.TemporalType;
+
+import com.rjconsultores.ventaboletos.entidad.ClaseServicio;
+import com.rjconsultores.ventaboletos.entidad.GrupoContrato;
+import com.rjconsultores.ventaboletos.entidad.Parada;
+
+import lombok.Getter;
+import lombok.Setter;
+
+@Getter
+@Setter
+public class TarifaGrupoContratoVO implements Serializable{
+
+ private static final long serialVersionUID = -8044552223526401469L;
+
+ private Integer tarifaGrupoContratoId;
+ private String numContrato;
+
+ private GrupoContrato grupoContrato;
+ private String descGrupoContrato;
+ private Long grupoContratoId;
+
+ private Parada origem;
+ private String descOrigem;
+ private String cveOrigem;
+
+ private Parada destino;
+ private String descDestino;
+ private String cveDestino;
+
+ private ClaseServicio claseServicio;
+ private String descClaseServicio;
+
+ private BigDecimal tarifa;
+
+ private Integer usuarioId;
+
+ private boolean indCobertura;
+
+ private boolean activo;
+
+ @Temporal(TemporalType.TIMESTAMP)
+ private Date fecModif;
+
+ public void setTarifaGrupoContratoId(String id) {
+ this.tarifaGrupoContratoId = Integer.valueOf(id);
+ }
+
+ public void setGrupoContratoId(String grupoId) {
+ this.grupoContratoId = Long.valueOf(grupoId);
+ }
+
+ public void setTarifa(String tarifa) {
+ this.tarifa = new BigDecimal(tarifa.replace(',', '.'));
+ }
+
+}
\ No newline at end of file