edgar 2016-09-08 14:01:53 +00:00
parent 7cc6ff1dcf
commit 8d16dde676
1 changed files with 62 additions and 45 deletions

View File

@ -26,17 +26,23 @@ import com.rjconsultores.ventaboletos.constantes.Constantes;
import com.rjconsultores.ventaboletos.dao.CalcularPeajeDAO;
import com.rjconsultores.ventaboletos.entidad.CasetaPeaje;
import com.rjconsultores.ventaboletos.entidad.CasetaPeajeExcepcion;
import com.rjconsultores.ventaboletos.entidad.ClaseServicio;
import com.rjconsultores.ventaboletos.entidad.ClasseIndicePeaje;
import com.rjconsultores.ventaboletos.entidad.ExcepcionPeaje;
import com.rjconsultores.ventaboletos.entidad.ExcepcionPeajeVigencia;
import com.rjconsultores.ventaboletos.entidad.OrgaoConcedente;
import com.rjconsultores.ventaboletos.entidad.Parada;
import com.rjconsultores.ventaboletos.entidad.Ruta;
import com.rjconsultores.ventaboletos.service.OrgaoConcedenteService;
import com.rjconsultores.ventaboletos.utilerias.UsuarioLogado;
@Repository("calcularPeajeDAO")
public class CalcularPeajeHibernateDAO extends GenericHibernateDAO<String, String>
implements CalcularPeajeDAO {
@Autowired
private OrgaoConcedenteService orgaoConcedenteService;
@Autowired
public CalcularPeajeHibernateDAO(@Qualifier("sessionFactory") SessionFactory factory) {
setSessionFactory(factory);
@ -131,11 +137,13 @@ public class CalcularPeajeHibernateDAO extends GenericHibernateDAO<String, Strin
// pra cada ruta obter as combinacoes de tramos, cada tramo com sua lista de casetaPeaje
public int[] gerarSQLInserirPeajes(List<Ruta> lsRuta, OrgaoConcedente orgao) {
List<PeajeVO> peajes = new ArrayList<PeajeVO>();
OrgaoConcedente orgaoConcedente = orgaoConcedenteService.obtenerID(orgao.getOrgaoConcedenteId());
List<ClasseIndicePeaje> classeIndicePeajes = orgaoConcedente.getClassesIndicePeaje();
for (Ruta ruta : lsRuta) {
List<Object> lsObj = buscarCasetasPeajeWithinTramo(ruta);
if (null != lsObj) {
for (Object arrObj : lsObj) {
peajes.add(PeajeVO.create(ruta, orgao, (Object[]) arrObj));
peajes.add(PeajeVO.create(ruta, orgaoConcedente, (Object[]) arrObj, classeIndicePeajes));
}
}
}
@ -161,8 +169,7 @@ public class CalcularPeajeHibernateDAO extends GenericHibernateDAO<String, Strin
con.commit();
recalcularExcecoesPedagio(peajes);
}
catch (SQLException e) {
} catch (SQLException e) {
e.printStackTrace();
}
@ -271,16 +278,15 @@ public class CalcularPeajeHibernateDAO extends GenericHibernateDAO<String, Strin
private static BigDecimal getCantEixos(Ruta ruta) {
try {
return new BigDecimal(ruta.getCantEixos());
}
catch (NullPointerException e) {
} catch (NullPointerException e) {
throw new RuntimeException("rutaSemQtdEixos;" + ruta.getRutaId());
}
}
private static BigDecimal getRutaCantAsientos(Ruta ruta) {
try {
return new BigDecimal(ruta.getCantAsientos());
}
catch (NullPointerException e) {
} catch (NullPointerException e) {
throw new RuntimeException("rutaSemQtdAsientos;" + ruta.getRutaId());
}
}
@ -288,8 +294,7 @@ public class CalcularPeajeHibernateDAO extends GenericHibernateDAO<String, Strin
private static BigDecimal getImporte(Ruta ruta, Object[] obj) {
if (ruta.getIndSentidoIda()) {
return new BigDecimal(obj[22].toString());
}
else {
} else {
return new BigDecimal(obj[23].toString());
}
}
@ -298,8 +303,7 @@ public class CalcularPeajeHibernateDAO extends GenericHibernateDAO<String, Strin
String icms = null;
if (ruta.getIndSentidoIda()) {
icms = obj[27].toString();
}
else {
} else {
icms = obj[28].toString();
}
@ -323,10 +327,9 @@ public class CalcularPeajeHibernateDAO extends GenericHibernateDAO<String, Strin
.divide(BigDecimal.ONE.subtract(icms), HIGH_PRECISION, RoundingMode.HALF_UP);
}
private static BigDecimal calculateImportePeaje(Ruta ruta, OrgaoConcedente orgao, Object[] obj) {
private static BigDecimal calculateImportePeaje(Ruta ruta, OrgaoConcedente orgao, Object[] obj, BigDecimal indicePeaje) {
BigDecimal rutaCantEixos = getCantEixos(ruta);
BigDecimal rutaCantAsientos = getRutaCantAsientos(ruta);
BigDecimal indice = orgao.getIndicePeaje();
BigDecimal indice = indicePeaje;
BigDecimal importe = getImporte(ruta, obj);
BigDecimal icms = getIcms(ruta, obj);
@ -334,13 +337,27 @@ public class CalcularPeajeHibernateDAO extends GenericHibernateDAO<String, Strin
return calculateImportePeajeARTESP(importe, icms, indice, rutaCantEixos);
}
if (Constantes.ORGAOS_CONCEDENTES_CALCULO_ANTT.contains(orgao.getOrgaoConcedenteId())) {
return calculateImportePeajeANTT(importe, icms, indice, rutaCantEixos, rutaCantAsientos);
return calculateImportePeajeANTT(importe, icms, indice, rutaCantEixos, getRutaCantAsientos(ruta));
}
return BigDecimal.ZERO; // TODO throw an exception? como calcular quando é outro orgao concendente?
}
private static PeajeVO create(Ruta ruta, OrgaoConcedente orgao, Object[] obj) {
private static BigDecimal getIndicePeaje(ClaseServicio claseServicio,
OrgaoConcedente orgao,
List<ClasseIndicePeaje> lsClasseIndicePeaje) {
for (ClasseIndicePeaje classeIndicePeaje : lsClasseIndicePeaje) {
if (claseServicio.equals(classeIndicePeaje.getClasseServicio())) {
return classeIndicePeaje.getIndicePeaje();
}
}
return orgao.getIndicePeaje();
}
private static PeajeVO create(Ruta ruta, OrgaoConcedente orgao,
Object[] obj, List<ClasseIndicePeaje> lsClasseIndicePeaje) {
PeajeVO pvo = new PeajeVO();
pvo.rutaId = ruta.getRutaId();
@ -350,8 +367,8 @@ public class CalcularPeajeHibernateDAO extends GenericHibernateDAO<String, Strin
pvo.destinoId = Integer.parseInt(obj[9].toString());
pvo.orgaoId = orgao.getOrgaoConcedenteId();
pvo.casetaPeajeId = Integer.parseInt(obj[20].toString());
pvo.indicePeaje = orgao.getIndicePeaje();
pvo.importePeaje = calculateImportePeaje(ruta, orgao, obj);
pvo.indicePeaje = getIndicePeaje(ruta.getClaseServicio(), orgao, lsClasseIndicePeaje);
pvo.importePeaje = calculateImportePeaje(ruta, orgao, obj, pvo.indicePeaje);
pvo.activo = 1;
pvo.fecmodif = new Date();