issue #7867
git-svn-id: http://desenvolvimento.rjconsultores.com.br/repositorio/sco/AdmVenta/Model/trunk/modelWeb@60094 d1611594-4594-4d17-8e1d-87c2c4800839master
parent
7cc6ff1dcf
commit
8d16dde676
|
@ -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);
|
||||
|
@ -98,7 +104,7 @@ public class CalcularPeajeHibernateDAO extends GenericHibernateDAO<String, Strin
|
|||
.append(" inner join ciudad cdest on cdest.ciudad_id = pdest.ciudad_id ")
|
||||
.append(" inner join estado edest on edest.estado_id = cdest.estado_id ")
|
||||
.append(" inner join empresa_imposto eidest on eidest.empresa_id = e.empresa_id and eidest.estado_id = edest.estado_id ")
|
||||
.append(" inner join tramo_tmp tt on torig.origen_id = tt.orig and tdest.destino_id = tt.dest " )
|
||||
.append(" inner join tramo_tmp tt on torig.origen_id = tt.orig and tdest.destino_id = tt.dest ")
|
||||
.append("), caseta_tramo_da_ruta as ( ")
|
||||
.append(" select rcas.rutacaseta_id as rutacasetaid, rcas.rutasecuencia_id as rutasecuenciaid, rcas.casetapeaje_id, ")
|
||||
.append(" rseq1.numsecuencia as numsecuencia, rseq1.tramo_id as tramoid, rseq2.numsecuencia as numsecuencia2, ")
|
||||
|
@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -160,9 +168,8 @@ public class CalcularPeajeHibernateDAO extends GenericHibernateDAO<String, Strin
|
|||
result = stmt.executeBatch();
|
||||
con.commit();
|
||||
recalcularExcecoesPedagio(peajes);
|
||||
|
||||
}
|
||||
catch (SQLException e) {
|
||||
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
@ -172,49 +179,49 @@ public class CalcularPeajeHibernateDAO extends GenericHibernateDAO<String, Strin
|
|||
private Map<Integer, CasetaPeaje> buscaCasetas(List<PeajeVO> pvo) {
|
||||
Set<Integer> ids = new LinkedHashSet<Integer>();
|
||||
Map<Integer, CasetaPeaje> casetas = new HashMap<Integer, CasetaPeaje>();
|
||||
|
||||
|
||||
for (PeajeVO p : pvo) {
|
||||
ids.add(p.casetaPeajeId);
|
||||
}
|
||||
|
||||
|
||||
Query query = getSession()
|
||||
.createQuery("select c from CasetaPeaje c where c.casetaPeajeId in (:ids) ");
|
||||
query.setParameterList("ids", ids);
|
||||
|
||||
|
||||
for (CasetaPeaje c : (List<CasetaPeaje>) query.list()) {
|
||||
casetas.put(c.getCasetaPeajeId(), c);
|
||||
}
|
||||
|
||||
|
||||
return casetas;
|
||||
}
|
||||
|
||||
private ExcepcionPeaje getExcepcion(Integer rutaId, Integer origenId, Integer destinoId){
|
||||
private ExcepcionPeaje getExcepcion(Integer rutaId, Integer origenId, Integer destinoId) {
|
||||
Query query = getSession().createQuery("select e from ExcepcionPeaje e where e.ruta.rutaId = :rutaId " +
|
||||
"and e.origem.paradaId = :origenId and e.destino.paradaId = :destinoId and e.activo = 1 ");
|
||||
|
||||
|
||||
query.setInteger("rutaId", rutaId);
|
||||
query.setInteger("origenId", origenId);
|
||||
query.setInteger("destinoId", destinoId);
|
||||
return (ExcepcionPeaje)query.uniqueResult();
|
||||
return (ExcepcionPeaje) query.uniqueResult();
|
||||
}
|
||||
|
||||
private Parada getParada(Integer paradaId){
|
||||
return (Parada)getSession().get(Parada.class, paradaId);
|
||||
|
||||
private Parada getParada(Integer paradaId) {
|
||||
return (Parada) getSession().get(Parada.class, paradaId);
|
||||
}
|
||||
|
||||
private Ruta getRuta(Integer rutaId){
|
||||
return (Ruta)getSession().get(Ruta.class, rutaId);
|
||||
|
||||
private Ruta getRuta(Integer rutaId) {
|
||||
return (Ruta) getSession().get(Ruta.class, rutaId);
|
||||
}
|
||||
|
||||
|
||||
@Transactional
|
||||
private void recalcularExcecoesPedagio(List<PeajeVO> pvos){
|
||||
private void recalcularExcecoesPedagio(List<PeajeVO> pvos) {
|
||||
Map<Integer, CasetaPeaje> casetas = buscaCasetas(pvos);
|
||||
for (PeajeVO peaje : pvos){
|
||||
ExcepcionPeaje excepcion = null;
|
||||
CasetaPeaje caseta = casetas.get(peaje.casetaPeajeId);
|
||||
|
||||
for (CasetaPeajeExcepcion cpe : caseta.getLsCasetaPeajeExcepcion()){
|
||||
if (excepcion == null){
|
||||
for (PeajeVO peaje : pvos) {
|
||||
ExcepcionPeaje excepcion = null;
|
||||
CasetaPeaje caseta = casetas.get(peaje.casetaPeajeId);
|
||||
|
||||
for (CasetaPeajeExcepcion cpe : caseta.getLsCasetaPeajeExcepcion()) {
|
||||
if (excepcion == null) {
|
||||
excepcion = new ExcepcionPeaje();
|
||||
excepcion.setActivo(true);
|
||||
excepcion.setDestino(getParada(peaje.destinoId));
|
||||
|
@ -242,13 +249,13 @@ public class CalcularPeajeHibernateDAO extends GenericHibernateDAO<String, Strin
|
|||
epv.setUsuarioId(1);
|
||||
epv.setCasetaPeaje(caseta);
|
||||
excepcion.getLsExcepcionPeajeVigencia().add(epv);
|
||||
}
|
||||
if (excepcion != null){
|
||||
}
|
||||
if (excepcion != null) {
|
||||
getSession().saveOrUpdate(excepcion);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static class PeajeVO {
|
||||
|
||||
private static final int HIGH_PRECISION = 10;
|
||||
|
@ -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?
|
||||
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();
|
||||
|
|
Loading…
Reference in New Issue