daniel.zauli 2017-01-17 20:58:55 +00:00
parent 7b83af06da
commit aa51e6902e
1 changed files with 25 additions and 5 deletions

View File

@ -14,6 +14,8 @@ import java.util.LinkedHashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import org.apache.log4j.Logger;
import org.hibernate.Query; import org.hibernate.Query;
import org.hibernate.SessionFactory; import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -51,6 +53,8 @@ public class CalcularPeajeHibernateDAO extends GenericHibernateDAO<String, Strin
public CalcularPeajeHibernateDAO(@Qualifier("sessionFactory") SessionFactory factory) { public CalcularPeajeHibernateDAO(@Qualifier("sessionFactory") SessionFactory factory) {
setSessionFactory(factory); setSessionFactory(factory);
} }
private static Logger log = Logger.getLogger(CalcularPeajeHibernateDAO.class);
@Override @Override
public List<Ruta> buscarRutaWithCasetaPeajeFromOrgao(OrgaoConcedente oc) { public List<Ruta> buscarRutaWithCasetaPeajeFromOrgao(OrgaoConcedente oc) {
@ -141,31 +145,47 @@ public class CalcularPeajeHibernateDAO extends GenericHibernateDAO<String, Strin
List<PeajeVO> peajes = new ArrayList<PeajeVO>(); List<PeajeVO> peajes = new ArrayList<PeajeVO>();
orgao = orgaoConcedenteService.obtenerID(orgao.getOrgaoConcedenteId()); orgao = orgaoConcedenteService.obtenerID(orgao.getOrgaoConcedenteId());
List<ClasseIndicePeaje> classeIndicePeajes = orgao.getClassesIndicePeaje(); List<ClasseIndicePeaje> classeIndicePeajes = orgao.getClassesIndicePeaje();
log.debug("****** INICIO DO PROCESSO DE CALCULO DE PEDAGIO ******");
log.debug("****** QTD DE LINHAS = "+lsRuta.size()+"******");
int z = 0;
for (Ruta ruta : lsRuta) { for (Ruta ruta : lsRuta) {
log.debug("****** Linha "+(++z)+" de "+lsRuta.size()+" ******");
log.debug("****** LINHA : "+ruta.toString()+" ******");
List<Object> lsObj = buscarCasetasPeajeWithinTramo(ruta); List<Object> lsObj = buscarCasetasPeajeWithinTramo(ruta);
log.debug("****** QTD COMBINAÇÕES DE TRECHOS x QTD PEDAGIOS POR TRECHO: "+lsObj.size()+" ******");
if (null != lsObj) { if (null != lsObj) {
for (Object arrObj : lsObj) { for (Object arrObj : lsObj) {
BigDecimal bigKm = new BigDecimal(((Object[]) arrObj)[11].toString()) ; BigDecimal bigKm = new BigDecimal(((Object[]) arrObj)[11].toString()) ;
peajes.add(PeajeVO.create(ruta, orgao, (Object[]) arrObj, classeIndicePeajes, usaICMS, bigKm)); peajes.add(PeajeVO.create(ruta, orgao, (Object[]) arrObj, classeIndicePeajes, usaICMS, bigKm));
} }
} }
log.debug("****** FIM LINHA : "+ruta.toString()+" . INSTRUCOES DE INSERT NO BANCO PRONTAS ******");
} }
StringBuilder updateSql = new StringBuilder() StringBuilder updateSql = new StringBuilder()
.append("update peaje set activo = 0 ") .append("update peaje set activo = 0 ")
.append("where orgaoconcedente_id = ") .append("where orgaoconcedente_id = ")
.append(orgao.getOrgaoConcedenteId()); .append(orgao.getOrgaoConcedenteId());
int[] result = {}; int[] result = {};
Connection con = getSession().connection(); Connection con = getSession().connection();
try { try {
Statement stmt = con.createStatement(); Statement stmt = con.createStatement();
con.setAutoCommit(false); con.setAutoCommit(false);
stmt.addBatch(updateSql.toString()); stmt.addBatch(updateSql.toString());
for (PeajeVO pvo : peajes) { for(int i = 0 ; i < peajes.size(); i++){
stmt.addBatch(pvo.toInsertQuery()); stmt.addBatch(peajes.get(i).toInsertQuery());
stmt.addBatch(pvo.toUpdateExcepcionPeajeQuery()); stmt.addBatch(peajes.get(i).toUpdateExcepcionPeajeQuery());
stmt.addBatch(pvo.toUpdateExcepcionPeajeVigenciaQuery()); stmt.addBatch(peajes.get(i).toUpdateExcepcionPeajeVigenciaQuery());
log.debug("**** "+i+ "- de "+ peajes.size()+" de combinacoes de trecho X (praca pedagio por trecho) ****");
if(i%100 == 0){
result = stmt.executeBatch();
con.commit();
stmt = con.createStatement();
}
} }
result = stmt.executeBatch(); result = stmt.executeBatch();