diff --git a/src/com/rjconsultores/ventaboletos/dao/ClasseServicoDAO.java b/src/com/rjconsultores/ventaboletos/dao/ClasseServicoDAO.java index ec26fbdef..11d6da15d 100644 --- a/src/com/rjconsultores/ventaboletos/dao/ClasseServicoDAO.java +++ b/src/com/rjconsultores/ventaboletos/dao/ClasseServicoDAO.java @@ -16,4 +16,6 @@ public interface ClasseServicoDAO extends GenericDAO { public List buscarPorNome(String nomeClaseServicio); public List buscarTodosExceto(Integer ... idClase); + + public List buscarPorEmpresasDoUsuario (String idEmpresasUsuario); } \ No newline at end of file diff --git a/src/com/rjconsultores/ventaboletos/dao/hibernate/ClasseServicoHibernateDAO.java b/src/com/rjconsultores/ventaboletos/dao/hibernate/ClasseServicoHibernateDAO.java index 4c8a10737..0f869567a 100644 --- a/src/com/rjconsultores/ventaboletos/dao/hibernate/ClasseServicoHibernateDAO.java +++ b/src/com/rjconsultores/ventaboletos/dao/hibernate/ClasseServicoHibernateDAO.java @@ -4,17 +4,22 @@ */ package com.rjconsultores.ventaboletos.dao.hibernate; -import com.rjconsultores.ventaboletos.dao.ClasseServicoDAO; -import com.rjconsultores.ventaboletos.entidad.ClaseServicio; import java.util.List; + import org.hibernate.Criteria; +import org.hibernate.SQLQuery; import org.hibernate.SessionFactory; import org.hibernate.criterion.Order; import org.hibernate.criterion.Restrictions; +import org.hibernate.transform.AliasToBeanResultTransformer; +import org.hibernate.type.StringType; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.stereotype.Repository; +import com.rjconsultores.ventaboletos.dao.ClasseServicoDAO; +import com.rjconsultores.ventaboletos.entidad.ClaseServicio; + /** * * @author Administrador @@ -35,6 +40,24 @@ public class ClasseServicoHibernateDAO extends GenericHibernateDAO buscarPorEmpresasDoUsuario (String empresasUsuario) { + + String consulta = "" + + " SELECT DISTINCT CS.DESCCLASE AS descclase " + + " FROM MARCA_CLASESERVICIO MC " + + " JOIN CLASE_SERVICIO CS ON CS.CLASESERVICIO_ID = MC.CLASESERVICIO_ID " + + " JOIN MARCA M ON M.MARCA_ID = MC.MARCA_ID " + + " WHERE M.EMPRESA_ID IN (:empresas)"; + + SQLQuery query = getSession().createSQLQuery(consulta); + query.setParameterList("empresas", empresasUsuario.split(",")); + query.setResultTransformer(new AliasToBeanResultTransformer(getPersistentClass())); + query.addScalar("descclase", StringType.INSTANCE); + List result = (List) query.list(); + return result; + } public List buscarPorNome(String nomeClaseServicio) { Criteria c = getSession().createCriteria(getPersistentClass()); diff --git a/src/com/rjconsultores/ventaboletos/entidad/ClaseServicio.java b/src/com/rjconsultores/ventaboletos/entidad/ClaseServicio.java index 9a3e5c209..99bda5f73 100644 --- a/src/com/rjconsultores/ventaboletos/entidad/ClaseServicio.java +++ b/src/com/rjconsultores/ventaboletos/entidad/ClaseServicio.java @@ -210,4 +210,4 @@ public class ClaseServicio implements Serializable { public void setEquivalenciaElektraId(String equivalenciaElektraId) { this.equivalenciaElektraId = equivalenciaElektraId; } -} +} \ No newline at end of file diff --git a/src/com/rjconsultores/ventaboletos/service/ClaseServicioService.java b/src/com/rjconsultores/ventaboletos/service/ClaseServicioService.java index 8655bce58..0930f69ad 100644 --- a/src/com/rjconsultores/ventaboletos/service/ClaseServicioService.java +++ b/src/com/rjconsultores/ventaboletos/service/ClaseServicioService.java @@ -5,6 +5,8 @@ package com.rjconsultores.ventaboletos.service; import com.rjconsultores.ventaboletos.entidad.ClaseServicio; +import com.rjconsultores.ventaboletos.entidad.Empresa; + import java.util.List; /** @@ -16,4 +18,6 @@ public interface ClaseServicioService extends GenericService buscarPorNome(String nomeClaseServicio); public List buscarTodosExceto(Integer ... idClase); + + public List buscarPorEmpresasDoUsuario (List empresasUsuario); } diff --git a/src/com/rjconsultores/ventaboletos/service/impl/ClaseServicioServiceImpl.java b/src/com/rjconsultores/ventaboletos/service/impl/ClaseServicioServiceImpl.java index e8293910e..f3179830e 100644 --- a/src/com/rjconsultores/ventaboletos/service/impl/ClaseServicioServiceImpl.java +++ b/src/com/rjconsultores/ventaboletos/service/impl/ClaseServicioServiceImpl.java @@ -6,10 +6,13 @@ package com.rjconsultores.ventaboletos.service.impl; import com.rjconsultores.ventaboletos.dao.ClasseServicoDAO; import com.rjconsultores.ventaboletos.entidad.ClaseServicio; +import com.rjconsultores.ventaboletos.entidad.Empresa; import com.rjconsultores.ventaboletos.service.ClaseServicioService; import com.rjconsultores.ventaboletos.utilerias.UsuarioLogado; + import java.util.Calendar; import java.util.List; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -62,7 +65,28 @@ public class ClaseServicioServiceImpl implements ClaseServicioService { public List buscarPorNome(String nomeClaseServicio) { return claseServicoDAO.buscarPorNome(nomeClaseServicio); } + public List buscarTodosExceto(Integer ... idClase){ return claseServicoDAO.buscarTodosExceto(idClase); } + + public List buscarPorEmpresasDoUsuario (List empresasUsuario) { + + if(empresasUsuario == null || empresasUsuario.isEmpty()) { + return null; + } + + StringBuilder idEmpresasBuilder = new StringBuilder(); + String idEmpresas = ""; + + for (Empresa empresa : empresasUsuario) { + idEmpresasBuilder.append(empresa.getEmpresaId().toString()).append(","); + } + + idEmpresasBuilder = idEmpresasBuilder.deleteCharAt(idEmpresasBuilder.length() -1); + idEmpresas = idEmpresasBuilder.toString(); + + List result = (List) claseServicoDAO.buscarPorEmpresasDoUsuario(idEmpresas); + return result; + } }