fixed bug #7674: Correção no cálculo de pedágio
git-svn-id: http://desenvolvimento.rjconsultores.com.br/repositorio/sco/AdmVenta/Model/trunk/modelWeb@59024 d1611594-4594-4d17-8e1d-87c2c4800839master
parent
80eba63a15
commit
89c8d07ff3
|
@ -128,29 +128,12 @@ 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<String> batchSql = new ArrayList<String>();
|
||||
List<String> batchExcepcionPeajeVigenciaSql = new ArrayList<String>();
|
||||
List<PeajeVO> peajes = new ArrayList<PeajeVO>();
|
||||
for (Ruta ruta : lsRuta) {
|
||||
|
||||
List<Object> lsObj = buscarCasetasPeajeWithinTramo(ruta);
|
||||
if (null != lsObj) {
|
||||
|
||||
int i = 0;
|
||||
for (Object arrObj : lsObj) {
|
||||
PeajeVO pvo = PeajeVO.create(ruta, orgao, (Object[]) arrObj);
|
||||
if (pvo != null){
|
||||
batchSql.add(pvo.toInsertQuery());
|
||||
batchExcepcionPeajeVigenciaSql.add("update EXCEPCION_PEAJE_VIGENCIA set activo = 0 " +
|
||||
"where excepcionpeaje_id in (select excepcionpeaje_id from EXCEPCION_PEAJE "+
|
||||
"where ruta_id = " + pvo.rutaId +
|
||||
" and origen_id = " + pvo.origenId + " and " +
|
||||
"destino_id = " + pvo.destinoId + ")");
|
||||
batchExcepcionPeajeVigenciaSql.add("update EXCEPCION_PEAJE set activo = 0 where ruta_id = " + pvo.rutaId +
|
||||
" and origen_id = " + pvo.origenId + " and " +
|
||||
"destino_id = " + pvo.destinoId + "");
|
||||
peajes.add(pvo);
|
||||
}
|
||||
peajes.add(PeajeVO.create(ruta, orgao, (Object[]) arrObj));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -166,15 +149,16 @@ public class CalcularPeajeHibernateDAO extends GenericHibernateDAO<String, Strin
|
|||
Statement stmt = con.createStatement();
|
||||
con.setAutoCommit(false);
|
||||
stmt.addBatch(updateSql.toString());
|
||||
for (String sql : batchSql) {
|
||||
stmt.addBatch(sql);
|
||||
}
|
||||
for (String sql : batchExcepcionPeajeVigenciaSql) {
|
||||
stmt.addBatch(sql);
|
||||
for (PeajeVO pvo : peajes) {
|
||||
stmt.addBatch(pvo.toInsertQuery());
|
||||
stmt.addBatch(pvo.toUpdateExcepcionPeajeQuery());
|
||||
stmt.addBatch(pvo.toUpdateExcepcionPeajeVigenciaQuery());
|
||||
}
|
||||
|
||||
result = stmt.executeBatch();
|
||||
con.commit();
|
||||
recalcularExcecoesPedagio(peajes);
|
||||
|
||||
}
|
||||
catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
|
@ -183,23 +167,24 @@ public class CalcularPeajeHibernateDAO extends GenericHibernateDAO<String, Strin
|
|||
return result;
|
||||
}
|
||||
|
||||
private Map<Integer, CasetaPeaje> buscaCasetas(List<PeajeVO> pvo){
|
||||
private Map<Integer, CasetaPeaje> buscaCasetas(List<PeajeVO> pvo) {
|
||||
List<Integer> ids = new ArrayList<Integer>();
|
||||
Map<Integer, CasetaPeaje> casetas = new HashMap<Integer, CasetaPeaje>();
|
||||
for(PeajeVO p : pvo){
|
||||
for (PeajeVO p : pvo) {
|
||||
ids.add(p.casetaPeajeId);
|
||||
}
|
||||
Query query = getSession().createQuery("select c from CasetaPeaje c where c.casetaPeajeId in (:ids) ");
|
||||
}
|
||||
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()){
|
||||
for (CasetaPeaje c : (List<CasetaPeaje>) query.list()) {
|
||||
casetas.put(c.getCasetaPeajeId(), c);
|
||||
}
|
||||
return casetas;
|
||||
}
|
||||
|
||||
|
||||
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 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);
|
||||
|
@ -218,7 +203,6 @@ public class CalcularPeajeHibernateDAO extends GenericHibernateDAO<String, Strin
|
|||
@Transactional
|
||||
private void recalcularExcecoesPedagio(List<PeajeVO> pvos){
|
||||
Map<Integer, CasetaPeaje> casetas = buscaCasetas(pvos);
|
||||
Map<Integer, ExcepcionPeaje> excepciones = new HashMap<Integer, ExcepcionPeaje>();
|
||||
for (PeajeVO peaje : pvos){
|
||||
ExcepcionPeaje excepcion = null;
|
||||
CasetaPeaje caseta = casetas.get(peaje.casetaPeajeId);
|
||||
|
@ -263,6 +247,7 @@ public class CalcularPeajeHibernateDAO extends GenericHibernateDAO<String, Strin
|
|||
|
||||
private static final int LOW_PRECISION = 2;
|
||||
private static final int HIGH_PRECISION = 10;
|
||||
private static final BigDecimal A_HUNDRED = new BigDecimal(100);
|
||||
private static final SimpleDateFormat SDF = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
|
||||
|
||||
private Integer rutaId;
|
||||
|
@ -305,21 +290,25 @@ public class CalcularPeajeHibernateDAO extends GenericHibernateDAO<String, Strin
|
|||
}
|
||||
|
||||
private static BigDecimal getIcms(Ruta ruta, Object[] obj) {
|
||||
String icms = null;
|
||||
if (ruta.getIndSentidoIda()) {
|
||||
return new BigDecimal(obj[27].toString());
|
||||
icms = obj[27].toString();
|
||||
}
|
||||
else {
|
||||
return new BigDecimal(obj[28].toString());
|
||||
icms = obj[28].toString();
|
||||
}
|
||||
|
||||
return new BigDecimal(icms)
|
||||
.divide(A_HUNDRED, HIGH_PRECISION, RoundingMode.HALF_UP);
|
||||
}
|
||||
|
||||
// ((importe * rutaCantEixos) / (indice * rutaCantAsientos)) / ( 1 - icms)
|
||||
private static BigDecimal calculateImportePeajeANTT(BigDecimal importe, BigDecimal icms,
|
||||
BigDecimal indice, BigDecimal rutaCantEixos, BigDecimal rutaCantAsientos) {
|
||||
|
||||
return importe.multiply(rutaCantEixos)
|
||||
.divide(indice.multiply(rutaCantAsientos), HIGH_PRECISION, RoundingMode.HALF_UP)
|
||||
.divide(BigDecimal.ONE.min(icms), LOW_PRECISION, RoundingMode.HALF_UP);
|
||||
.divide(BigDecimal.ONE.subtract(icms), HIGH_PRECISION, RoundingMode.HALF_UP)
|
||||
.setScale(LOW_PRECISION, RoundingMode.HALF_UP);
|
||||
}
|
||||
|
||||
// ((importe * rutaCantEixos) / (indice)) / ( 1 - icms)
|
||||
|
@ -327,7 +316,8 @@ public class CalcularPeajeHibernateDAO extends GenericHibernateDAO<String, Strin
|
|||
BigDecimal indice, BigDecimal rutaCantEixos) {
|
||||
return importe.multiply(rutaCantEixos)
|
||||
.divide(indice, HIGH_PRECISION, RoundingMode.HALF_UP)
|
||||
.divide(BigDecimal.ONE.min(icms), LOW_PRECISION, RoundingMode.HALF_UP);
|
||||
.divide(BigDecimal.ONE.subtract(icms), HIGH_PRECISION, RoundingMode.HALF_UP)
|
||||
.setScale(LOW_PRECISION, RoundingMode.HALF_UP);
|
||||
}
|
||||
|
||||
private static BigDecimal calculateImportePeaje(Ruta ruta, OrgaoConcedente orgao, Object[] obj) {
|
||||
|
@ -388,6 +378,30 @@ public class CalcularPeajeHibernateDAO extends GenericHibernateDAO<String, Strin
|
|||
.append("', 'yyyy/mm/dd hh24:mi:ss'), ")
|
||||
.append(usuarioId).append(" ) ")
|
||||
.toString();
|
||||
}
|
||||
}
|
||||
|
||||
private String toUpdateExcepcionPeajeQuery() {
|
||||
return new StringBuilder()
|
||||
.append("update excepcion_peaje ")
|
||||
.append("set activo = 0 ")
|
||||
.append("where ruta_id = ").append(rutaId)
|
||||
.append(" and origen_id = ").append(origenId)
|
||||
.append(" and destino_id = ").append(origenId)
|
||||
.toString();
|
||||
}
|
||||
|
||||
private String toUpdateExcepcionPeajeVigenciaQuery() {
|
||||
return new StringBuilder()
|
||||
.append("update excepcion_peaje_vigencia ")
|
||||
.append("set activo = 0 ")
|
||||
.append("where excepcionpeaje_id in ( ")
|
||||
.append(" select excepcionpeaje_id ")
|
||||
.append(" from excepcion_peaje ")
|
||||
.append(" where ruta_id = ").append(rutaId)
|
||||
.append(" and origen_id = ").append(origenId)
|
||||
.append(" and destino_id = ").append(origenId)
|
||||
.append(")")
|
||||
.toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue