diff --git a/src/com/rjconsultores/ventaboletos/dao/hibernate/SeguroKmHibernateDAO.java b/src/com/rjconsultores/ventaboletos/dao/hibernate/SeguroKmHibernateDAO.java new file mode 100644 index 000000000..f0b4435b6 --- /dev/null +++ b/src/com/rjconsultores/ventaboletos/dao/hibernate/SeguroKmHibernateDAO.java @@ -0,0 +1,30 @@ +package com.rjconsultores.ventaboletos.dao.hibernate; + +import org.hibernate.SQLQuery; +import org.hibernate.SessionFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.stereotype.Repository; + +import com.rjconsultores.ventaboletos.dao.SeguroKmDAO; +import com.rjconsultores.ventaboletos.dao.sqlbuilder.SQLBuilder; +import com.rjconsultores.ventaboletos.entidad.SeguroKm; + +@Repository("seguroKmDAO") +public class SeguroKmHibernateDAO extends GenericHibernateDAO implements SeguroKmDAO { + + @Autowired + private SQLBuilder sqlBuilder; + + @Autowired + public SeguroKmHibernateDAO(@Qualifier("sessionFactory") SessionFactory factory) { + setSessionFactory(factory); + } + + @Override + public void atualizarSeguroPorKm(Integer rutaId, Integer orgaoId, Integer usuarioId) { + SQLQuery query = getSession().createSQLQuery(sqlBuilder.getSQLAtualizarSeguroPorKm(rutaId, usuarioId, orgaoId)); + query.executeUpdate(); + } + +} diff --git a/src/com/rjconsultores/ventaboletos/dao/hibernate/TarifaOficialHibernateDAO.java b/src/com/rjconsultores/ventaboletos/dao/hibernate/TarifaOficialHibernateDAO.java index 17beb9d41..9ecc65a1f 100644 --- a/src/com/rjconsultores/ventaboletos/dao/hibernate/TarifaOficialHibernateDAO.java +++ b/src/com/rjconsultores/ventaboletos/dao/hibernate/TarifaOficialHibernateDAO.java @@ -26,7 +26,7 @@ public class TarifaOficialHibernateDAO extends GenericHibernateDAO= t.CANTKMREAL and sk.activo = 1 and tao.ORGAOCONCEDENTE_ID = sk.ORGAOCONCEDENTE_ID "); + sb.append("where "); + sb.append(" sk.kmate= "); + sb.append(" (select min(sk1.KMATE) "); + sb.append(" from "); + sb.append(" seguro_km sk1 "); + sb.append(" where "); + sb.append(" sk1.KMATE >= t.CANTKMREAL and sk1.activo = 1 "); + sb.append(" ) "); + sb.append(" and tao.marca_id = tarifa_oficial.marca_id "); + sb.append(" and tao.orgaoconcedente_id = tarifa_oficial.orgaoconcedente_id "); + sb.append(" and tao.claseservicio_id=tarifa_oficial.claseservicio_id "); + sb.append(" and tao.moneda_id = tarifa_oficial.moneda_id "); + sb.append(" and tao.ruta_id = tarifa_oficial.ruta_id "); + sb.append(" and tao.tramo_id = tarifa_oficial.tramo_id "); + sb.append(") "); + sb.append(", usuario_id = ").append(usuarioId).append(",fecmodif = sysdate "); + sb.append(" "); + sb.append("where "); + sb.append(" tarifa_oficial.activo = 1 "); + if (rutaId != null){ + sb.append(" and tarifa_oficial.ruta_id = ").append(rutaId); + } + if (orgaoConcedenteId != null){ + sb.append(" and tarifa_oficial.orgaoconcedente_id = ").append(orgaoConcedenteId); + } + + return sb.toString(); + } + } \ No newline at end of file diff --git a/src/com/rjconsultores/ventaboletos/service/impl/SeguroServiceImpl.java b/src/com/rjconsultores/ventaboletos/service/impl/SeguroServiceImpl.java index 0a1fe2737..b1fe61f7f 100644 --- a/src/com/rjconsultores/ventaboletos/service/impl/SeguroServiceImpl.java +++ b/src/com/rjconsultores/ventaboletos/service/impl/SeguroServiceImpl.java @@ -1,21 +1,29 @@ package com.rjconsultores.ventaboletos.service.impl; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import com.rjconsultores.ventaboletos.dao.SeguroKmDAO; import com.rjconsultores.ventaboletos.exception.BusinessException; import com.rjconsultores.ventaboletos.service.SeguroService; +import com.rjconsultores.ventaboletos.utilerias.UsuarioLogado; @Service("seguroService") public class SeguroServiceImpl implements SeguroService{ + @Autowired + private SeguroKmDAO seguroKmDAO; + @Override + @Transactional public void atualizarSeguroPorKm(Integer rutaId, Integer orgaoId) throws BusinessException { if (orgaoId == null){ throw new BusinessException("SeguroServiceImpl.msg.validacion.orgaoObligatorio"); } - + seguroKmDAO.atualizarSeguroPorKm(rutaId, orgaoId, UsuarioLogado.getUsuarioLogado().getUsuarioId()); }