/* * Créé le Jun 17, 2007 * * TODO Pour changer le modèle de ce fichier généré, allez à : * Fenêtre - Préférences - Java - Style de code - Modèles de code */ package com.eccgnet.gestionSinistre.dao.auto; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.List; import org.apache.log4j.Logger; import org.hibernate.Query; import org.hibernate.Session; import org.hibernate.Transaction; import org.springframework.orm.hibernate3.support.HibernateDaoSupport; import com.eccgnet.gestionSinistre.bean.Client; import com.eccgnet.gestionSinistre.bean.Prestation; import com.eccgnet.gestionSinistre.dao.search.SearchClient; /** * @author cheikh * * TODO Pour changer le modèle de ce commentaire de type généré, allez à : * Fenêtre - Préférences - Java - Style de code - Modèles de code */ public class ClientDaoAutoImpl extends HibernateDaoSupport { protected static final String hqlRequest = " from Adherent as adherent"; protected Logger log = Logger.getLogger(ClientDaoAutoImpl.class); public void profondeur(SearchClient searchClient, StringBuffer hqlRequest) { if (searchClient.lienFeuilleMaladie == true) { hqlRequest.append(" , FeuilleMaladie as feuilleMaladie "); if (searchClient.lienPrestation == true) { hqlRequest.append(" , Prestation as prestation "); hqlRequest.append(" , SousGarantie as sousGarantie "); hqlRequest.append(" , Zone as zone "); } } if(searchClient.lienAffilie == true){ hqlRequest.append(" , Affilie as affilie "); } // Modif Verdy if (searchClient.lienFeuilleMaladie == true) { hqlRequest.append(" WHERE adherent.numeroPolice=feuilleMaladie.numeroPolice "); hqlRequest.append(" AND adherent.numeroAdherent=feuilleMaladie.numeroAdherent "); hqlRequest.append(" AND feuilleMaladie.numeroPolice=affilie.numeroPolice "); hqlRequest.append(" AND feuilleMaladie.numeroAdherent=affilie.numeroAdherent "); hqlRequest.append(" AND feuilleMaladie.numeroAffilie=affilie.numeroAffilie "); if (searchClient.lienPrestation == true) { hqlRequest.append(" AND prestation.numeroFeuille=feuilleMaladie.numeroFeuille "); hqlRequest.append(" AND prestation.codeSousGarantie=sousGarantie.codeSousGarantie "); hqlRequest.append(" AND prestation.codeZone=zone.codeZone "); } } // **************** if(searchClient.lienAffilie == true){ hqlRequest.append(" AND affilie.numeroPolice=adherent.numeroPolice "); hqlRequest.append(" AND affilie.numeroAdherent=adherent.numeroAdherent "); } } //Modif Verdy public List getEtatSinistre(SearchClient searchClient) throws Exception{ //TODO Raccord de méthode auto-généré Session session = this.getSessionFactory().openSession(); try { Transaction tx = session.beginTransaction(); StringBuffer sbHqlRequest = new StringBuffer(hqlRequest); HashMap paramMap = new HashMap(); HashMap paramListMap = new HashMap(); if (searchClient != null) profondeur(searchClient, sbHqlRequest); sbHqlRequest.append(" AND feuilleMaladie.numeroPolice=:numeroPolice "); sbHqlRequest.append(" AND feuilleMaladie.numeroAdherent=:numeroAdherent "); paramMap.put("numeroPolice", searchClient.getNumeroPolice()); paramMap.put("numeroAdherent", searchClient.getNumeroAdherent()); String sHqlRequest = sbHqlRequest.toString(); Query query = session.createQuery(sHqlRequest); String[] namedParams = query.getNamedParameters(); if (namedParams != null) { for (int i = 0; i < namedParams.length; i++) { //Paramètre simple if (paramMap.containsKey(namedParams[i])) { query.setParameter(namedParams[i], paramMap.get(namedParams[i])); // Paramètre liste } else if (paramListMap.containsKey(namedParams[i])) { query.setParameterList(namedParams[i], (Collection) paramListMap.get(namedParams[i])); } } } List listeBilan = query.list(); // test ---> affichage sur la console Iterator I = query.iterate(); while(I.hasNext()) { Object[] bilan=(Object[]) I.next(); Prestation presta=(Prestation) bilan[2]; System.out.print("les fraix reels :"+ presta.getMontantFraisReel()); } //fin test <----------- List lstBilan = new ArrayList(); if(listeBilan != null){ for(int i = 0; i < listeBilan.size(); i++) { lstBilan.add(new Client((Object[])listeBilan.get(i))); } } tx.commit(); return lstBilan; } catch (Exception e) { log.error(e.getMessage(), e); throw e; } finally { session.close(); } } public List getEtatSinistreByDatePrestation(SearchClient searchClient) throws Exception{ //TODO Raccord de méthode auto-généré Session session = this.getSessionFactory().openSession(); try { Transaction tx = session.beginTransaction(); StringBuffer sbHqlRequest = new StringBuffer(hqlRequest); HashMap paramMap = new HashMap(); HashMap paramListMap = new HashMap(); if (searchClient != null) profondeur(searchClient, sbHqlRequest); sbHqlRequest.append(" AND feuilleMaladie.numeroPolice=:numeroPolice "); sbHqlRequest.append(" AND feuilleMaladie.numeroAdherent=:numeroAdherent "); sbHqlRequest.append(" AND prestation.datePrestation >= :dateDebut"); sbHqlRequest.append(" AND prestation.datePrestation <= :dateFin"); paramMap.put("numeroPolice", searchClient.getNumeroPolice()); paramMap.put("numeroAdherent", searchClient.getNumeroAdherent()); paramMap.put("dateDebut", searchClient.getDateDebut()); paramMap.put("dateFin", searchClient.getDateFin()); String sHqlRequest = sbHqlRequest.toString(); Query query = session.createQuery(sHqlRequest); String[] namedParams = query.getNamedParameters(); if (namedParams != null) { for (int i = 0; i < namedParams.length; i++) { //Paramètre simple if (paramMap.containsKey(namedParams[i])) { query.setParameter(namedParams[i], paramMap.get(namedParams[i])); // Paramètre liste } else if (paramListMap.containsKey(namedParams[i])) { query.setParameterList(namedParams[i], (Collection) paramListMap.get(namedParams[i])); } } } List listeBilan = query.list(); List listeBilan2 = new ArrayList((Collection) new HashSet(listeBilan)); List lstBilan = new ArrayList(); if(listeBilan2 != null){ for(int i = 0; i < listeBilan2.size(); i++){ lstBilan.add(new Client((Object[])listeBilan2.get(i))); } } tx.commit(); return lstBilan; } catch (Exception e) { log.error(e.getMessage(), e); throw e; } finally { session.close(); } } //********************* /*public List getEtatSinistreByDatePrestation(SearchClient searchClient) throws Exception{ //TODO Raccord de méthode auto-généré Session session = this.getSessionFactory().openSession(); try { Transaction tx = session.beginTransaction(); StringBuffer sbHqlRequest = new StringBuffer(hqlRequest); HashMap paramMap = new HashMap(); HashMap paramListMap = new HashMap(); if (searchClient != null) profondeur(searchClient, sbHqlRequest); sbHqlRequest.append(" AND decompte.numeroPolice=:numeroPolice "); sbHqlRequest.append(" AND decompte.numeroAdherent=:numeroAdherent "); sbHqlRequest.append(" AND prestation.datePrestation >= :dateDebut"); sbHqlRequest.append(" AND prestation.datePrestation <= :dateFin"); paramMap.put("numeroPolice", searchClient.getNumeroPolice()); paramMap.put("numeroAdherent", searchClient.getNumeroAdherent()); paramMap.put("dateDebut", searchClient.getDateDebut()); paramMap.put("dateFin", searchClient.getDateFin()); String sHqlRequest = sbHqlRequest.toString(); Query query = session.createQuery(sHqlRequest); String[] namedParams = query.getNamedParameters(); if (namedParams != null) { for (int i = 0; i < namedParams.length; i++) { //Paramètre simple if (paramMap.containsKey(namedParams[i])) { query.setParameter(namedParams[i], paramMap.get(namedParams[i])); // Paramètre liste } else if (paramListMap.containsKey(namedParams[i])) { query.setParameterList(namedParams[i], (Collection) paramListMap.get(namedParams[i])); } } } List listeBilan = query.list(); List listeBilan2 = new ArrayList((Collection) new HashSet(listeBilan)); List lstBilan = new ArrayList(); if(listeBilan2 != null){ for(int i = 0; i < listeBilan2.size(); i++){ lstBilan.add(new Client((Object[])listeBilan2.get(i))); } } tx.commit(); return lstBilan; } catch (Exception e) { log.error(e.getMessage(), e); throw e; } finally { session.close(); } }*/ }