1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
|
CriteriaBuilder cb = getEntityManager().getCriteriaBuilder();
CriteriaQuery<Tuple> cq= cb.createTupleQuery();
Predicate predicate = cb.and();
Root<SessionPersonne> root = cq.from(SessionPersonne.class);
Join <ReponseClient,SessionPersonne> reponseClient = null;
Join <Categorie,SessionPersonne> categorie = null;
Join<Reponse,ReponseClient> reponse = null;
Join<Question,Reponse> question = null;
Join <Personne,SessionPersonne> personne = null;
Join <Session,SessionPersonne> Session = null;
Join <Entreprise,Personne> entreprise = null;
Join <Adresse,Entreprise> adresse = null;
Join <Localite,Adresse> localite = null;
Join <Departement,Localite> departement = null;
Join <Pays,Localite> pays = null;
Join <Civilite,Personne> civilite = null ;
Join <AutreInformation,Personne> autreInformation = null;
Expression<String> champsCrm =null;
personne = root.join("personne");
Session = root.join("session");
if("Personne".equals(crm.getNomTable())){
champsCrm = personne.get(crm.getNomChamps());
}
// ==========================jointure =======================================
if("Entreprise".equals(crm.getNomTable()) && entreprise== null){
entreprise = personne.join("entreprise");
champsCrm = entreprise.get(crm.getNomChamps());
// System.out.println("jointure Entreprise");
}
if("Adresse".equals(crm.getNomTable()) && adresse== null){
if(entreprise== null) entreprise = personne.join("entreprise");
if(adresse== null) adresse = entreprise.join("Adresse");
// System.out.println("jointure adresse");
champsCrm = adresse.get(crm.getNomChamps());
}
if("Localite".equals(crm.getNomTable()) && localite== null){
if(entreprise== null) entreprise = personne.join("entreprise");
if(adresse== null) adresse = entreprise.join("adresse");
if(localite == null) localite = adresse.join("localite");
champsCrm = localite.get(crm.getNomChamps());
// System.out.println("jointure Localite");
}
if("Departement".equals(crm.getNomTable()) && departement== null){
if(entreprise== null) entreprise = personne.join("entreprise");
if(adresse== null) adresse = entreprise.join("adresse");
if(localite == null) localite = adresse.join("localite");
if(departement== null)pays = localite.join("departement");
champsCrm = departement.get(crm.getNomChamps());
//System.out.println("jointure Pays");
}
if("Pays".equals(crm.getNomTable()) && pays== null){
if(entreprise== null) entreprise = personne.join("entreprise");
if(adresse== null) adresse = entreprise.join("adresse");
if(localite == null) localite = adresse.join("localite");
if(pays== null)pays = localite.join("pays");
champsCrm = pays.get(crm.getNomChamps());
//System.out.println("jointure Pays");
}
if("Civilite".equals(crm.getNomTable()) && civilite== null){
civilite = personne.join("civilite");
champsCrm = civilite.get(crm.getNomChamps());
//System.out.println("jointure Civilite");
}
if("AutreInformation".equals(crm.getNomTable()) && autreInformation== null){
autreInformation = personne.join("AutreInformation");
champsCrm = autreInformation.get(crm.getNomChamps());
//System.out.println("jointure autre inforation ");
}
if("Categorie".equals(crm.getNomTable()) && categorie== null){
categorie = root.join("categorie");
champsCrm = categorie.get(crm.getNomChamps());
//System.out.println("jointure autre inforation ");
}
if("Question".equals(crm.getNomTable()) && reponseClient== null){
reponseClient = root.join("reponseClientCollection");
reponse = reponseClient.join("reponse");
question = reponse.join("question");
champsCrm = reponse.get("nomReponse");
//System.out.println("reponseClient");
}
// ========================== recherche =======================================
Expression<String> userId = root.get("keySessionPersonne");
Expression<Long> count = cb.count(userId);
cq.multiselect(champsCrm.alias("USERID"), count.alias("CNT"));
Expression<String> sessionType = Session.get("keySession");
Expression<Date> date = root.get("dateCreation");
cb.and(cb.equal(sessionType,session));
cb.and(cb.between(date, dateDebut, dateFin));
//cq.where(cb.between(root.get("dateCreation"),dateDebut,dateFin));
if("Question".equals(crm.getNomTable())){
Expression<String> ExpressionQuestion = question.get("nomQuestion");
cb.and(cb.like(ExpressionQuestion,crm.getNomChamps()));
}
if("PE".equals(typeChoisi)){
Expression<String> pe = root.get("typeEnregistrement");
cb.and(cb.equal(pe,"PE"));
}
if("SS".equals(typeChoisi)){
Expression<String> ss = root.get("typeEnregistrement");
cb.and(cb.equal(ss,"SS"));
}
if("PAV".equals(typeChoisi)){
Expression<Collection<String>> passageCollection = root.get("passageCollection");
Expression<Integer> size = cb.size(passageCollection);
cb.and(cb.equal(size,0));
}
if("PEV".equals(typeChoisi)){
Expression<Collection<String>> passageCollection = root.get("passageCollection");
Expression<Integer> size = cb.size(passageCollection);
cb.and(cb.equal(size,1));
}
if("R".equals(typeChoisi)){
Expression<Collection<String>> passageCollection = root.get("passageCollection");
Expression<Integer> size = cb.size(passageCollection);
cb.and(cb.greaterThan(size,1));
}
cq.where(cb.and());
cq.groupBy(champsCrm);
List<Reporting> lResporting = new ArrayList<>();
TypedQuery<Tuple> tq = getEntityManager().createQuery(cq);
for (Tuple t : tq.getResultList()) {
//System.out.println(t.get("USERID")+" "+t.get("CNT"));
lResporting.add(new Reporting((Long)t.get("CNT"),(String)t.get("USERID")));
}
return lResporting ; |
Partager