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 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194
|
private List<Predicate> ajouterFiltres(Map<String, String> map, Root<Appel> appel, List<Predicate> predicates, CriteriaBuilder cb) throws ParseException{
// DEBUT FILTRE A.
if(map.containsKey("mySelect1")) {
if( map.get("AV1") != null && map.get("AV1Bis") != null){
predicates.add(
cb.between(appel.get("dateHeure"),
new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(map.get("AV1") + " 00:00:00"),
new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(map.get("AV1Bis") + " 23:59:59"))
);
/*String AV1 = map.get("AV1") + " 00:00:00";
DateTimeFormatter formatterAV1 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
LocalDateTime startDateAV1 = LocalDateTime.parse(AV1, formatterAV1);
String AV1Bis = map.get("AV1Bis") + " 23:59:59";
DateTimeFormatter formatterAV1Bis = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
LocalDateTime endDateAV1Bis = LocalDateTime.parse(AV1Bis, formatterAV1Bis );
Date startDate_AV1 = Date.from(startDateAV1.atZone(ZoneId.systemDefault()).toInstant());
Date endDate_AV1Bis = Date.from(endDateAV1Bis.atZone(ZoneId.systemDefault()).toInstant());
predicates.add(cb.between(appel.get("dateHeure"), startDate_AV1, endDate_AV1Bis));*/
}
if( map.get("AV2") != null){
predicates.add(cb.equal(appel.get("agence"), Integer.parseInt(map.get("AV2"))));
} // Note the parse method throws an exception if it fails so we have to throw it.
if( map.get("AV3") != null){
predicates.add(cb.equal(appel.get("suiviPar"), Integer.parseInt(map.get("AV3"))));
}
if( map.get("AV4") != null){
predicates.add(cb.equal(appel.get("typeAppelant"), Integer.parseInt(map.get("AV4"))));
}
if( map.get("AV5") != null){
predicates.add(cb.like(appel.get("nom"), map.get("AV5")));
}
if( map.get("AV6") != null){
predicates.add(cb.like(appel.get("prenom"), map.get("AV6")));
}
if( map.get("AV7") != null){
predicates.add(cb.like(appel.get("mobile"), map.get("AV7")));
}
if( map.get("AV8") != null){
predicates.add(cb.like(appel.get("telephone"), map.get("AV8")));
}
if( map.get("AV9") != null){
predicates.add(cb.like(appel.get("email"), map.get("AV9")));
}
if( map.get("AV10") != null){
predicates.add(cb.like(appel.get("objet"), map.get("AV10")));
}
if( map.get("AV11") != null){
predicates.add(cb.equal(appel.get("annonce"), Integer.parseInt(map.get("AV11"))));
}
if( map.get("AV12") != null){
predicates.add(cb.equal(appel.get("origine"), Integer.parseInt(map.get("AV12"))));
}
if( map.get("AV14") != null){
predicates.add(cb.like(appel.get("nomDuMandat"), map.get("AV14")));
}
if( map.get("AV15") != null){
predicates.add(cb.equal(appel.get("recuPar"), Integer.parseInt(map.get("AV15"))));
}
if( map.get("AV16") != null){
predicates.add(cb.equal(appel.get("estAccuse"), 1));
}
if( map.get("AV17") != null){
predicates.add(cb.like(appel.get("suivre"), map.get("AV17")));
}
}
// DEBUT FILTRE B
System.out.println("\n\n");
System.out.println("mySelect2 : " + map.get("mySelect2"));
System.out.println("\n\n");
if(map.containsKey("mySelect2")) {
if( map.get("BV1") != null && map.get("BV1Bis") != null){
predicates.add(cb.between(appel.get("dateHeure"),
new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(map.get("BV1")+" 00:00:00"),
new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(map.get("BV1Bis") + " 23:59:59")));
//predicates.add(cb.between(appel.get("dateHeure"), map.get("AV1"), map.get("AV1Bis"))); //Génère une erreur de type format.
}
if( map.get("BV2") != null){
predicates.add(cb.equal(appel.get("agence"), Integer.parseInt(map.get("BV2"))));
}
if( map.get("BV3") != null){
predicates.add(cb.equal(appel.get("suiviPar"), Integer.parseInt(map.get("BV3"))));
}
if( map.get("BV4") != null){
predicates.add(cb.equal(appel.get("typeAppelant"), Integer.parseInt(map.get("BV4"))));
}
if( map.get("BV5") != null){
predicates.add(cb.like(appel.get("nom"), map.get("BV5")));
}
if( map.get("BV6") != null){
predicates.add(cb.like(appel.get("prenom"), map.get("BV6")));
}
if( map.get("BV7") != null){
predicates.add(cb.like(appel.get("mobile"), map.get("BV7")));
}
if( map.get("BV8") != null){
predicates.add(cb.like(appel.get("telephone"), map.get("BV8")));
}
if( map.get("BV9") != null){
predicates.add(cb.like(appel.get("email"), map.get("BV9")));
}
if( map.get("BV10") != null){
predicates.add(cb.like(appel.get("objet"), map.get("BV10")));
}
if( map.get("BV11") != null){
predicates.add(cb.equal(appel.get("annonce"), Integer.parseInt(map.get("BV11"))));
}
if( map.get("BV12") != null){
predicates.add(cb.equal(appel.get("origine"), Integer.parseInt(map.get("BV12"))));
}
if( map.get("BV14") != null){
predicates.add(cb.like(appel.get("nomDuMandat"), map.get("BV14")));
}
if( map.get("BV15") != null){
predicates.add(cb.equal(appel.get("recuPar"), Integer.parseInt(map.get("BV15"))));
}
if( map.get("BV16") != null){
predicates.add(cb.equal(appel.get("estAccuse"), 1));
}
if( map.get("BV17") != null){
predicates.add(cb.like(appel.get("suivre"), map.get("BV17")));
}
}
// DEBUT FILTRE C
System.out.println("\n\n");
System.out.println("mySelect3 : " + map.get("mySelect3"));
System.out.println("\n\n");
if(map.containsKey("mySelect3")) {
if( map.get("CV1") != null && map.get("CV1Bis") != null){
predicates.add(cb.between(appel.get("dateHeure"),
new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(map.get("CV1")+" 00:00:00"),
new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(map.get("CV1Bis") + " 23:59:59"))
);
}
if( map.get("CV2") != null){
predicates.add(cb.equal(appel.get("agence"), Integer.parseInt(map.get("CV2"))));
}
if( map.get("CV3") != null){
predicates.add(cb.equal(appel.get("suiviPar"), Integer.parseInt(map.get("CV3"))));
}
if( map.get("CV4") != null){
predicates.add(cb.equal(appel.get("typeAppelant"), Integer.parseInt(map.get("CV4"))));
}
if( map.get("CV5") != null){
predicates.add(cb.like(appel.get("nom"), map.get("CV5")));
}
if( map.get("CV6") != null){
predicates.add(cb.like(appel.get("prenom"), map.get("CV6")));
}
if( map.get("CV7") != null){
predicates.add(cb.like(appel.get("mobile"), map.get("CV7")));
}
if( map.get("CV8") != null){
predicates.add(cb.like(appel.get("telephone"), map.get("CV8")));
}
if( map.get("CV9") != null){
predicates.add(cb.like(appel.get("email"), map.get("CV9")));
}
if( map.get("CV10") != null){
predicates.add(cb.like(appel.get("objet"), map.get("CV10")));
}
if( map.get("CV11") != null){
predicates.add(cb.equal(appel.get("annonce"), Integer.parseInt(map.get("CV11"))));
}
if( map.get("CV12") != null){
predicates.add(cb.equal(appel.get("origine"), Integer.parseInt(map.get("CV12"))));
}
if( map.get("CV14") != null){
predicates.add(cb.like(appel.get("nomDuMandat"), map.get("CV14")));
}
if( map.get("CV15") != null){
predicates.add(cb.equal(appel.get("recuPar"), Integer.parseInt(map.get("CV15"))));
}
if( map.get("CV16") != null){
predicates.add(cb.equal(appel.get("estAccuse"), 1));
}
if( map.get("CV17") != null){
predicates.add(cb.like(appel.get("suivre"), map.get("CV17")));
}
}
if(map.get("CP") != null && ! map.get("CP").equals("3")) {
predicates.add(cb.equal(appel.get("estTermine"), map.get("CP")));
}
return predicates;
} |
Partager