use of me.kadarh.mecaworks.domain.dtos.BonEnginDto in project mecaworks by KadarH.
the class BonFilterServiceImpl method filterBonEngin.
@Override
public List<BonEngin> filterBonEngin(BonEnginDto bonEnginDto) {
try {
String famille = bonEnginDto.getFamille().equals("") ? null : bonEnginDto.getFamille();
String classe = bonEnginDto.getClasse().equals("") ? null : bonEnginDto.getClasse();
String engin = bonEnginDto.getCodeEngin().equals("") ? null : bonEnginDto.getCodeEngin();
String sousFamille = bonEnginDto.getSousFamille().equals("") ? null : bonEnginDto.getSousFamille();
String groupe = bonEnginDto.getGroupe().equals("") ? null : bonEnginDto.getGroupe();
String marque = bonEnginDto.getMarque().equals("") ? null : bonEnginDto.getMarque();
String chantierDepart = bonEnginDto.getChantierDepart().equals("") ? null : bonEnginDto.getChantierDepart();
String chantierArrivee = bonEnginDto.getChantierArrivee().equals("") ? null : bonEnginDto.getChantierArrivee();
String chauffeur = bonEnginDto.getChauffeur().equals("") ? null : bonEnginDto.getChauffeur();
String pompiste = bonEnginDto.getPompiste().equals("") ? null : bonEnginDto.getPompiste();
String locataire = bonEnginDto.getLocataire().equals("") ? "all" : bonEnginDto.getLocataire();
BonEngin bonEngin = new BonEngin();
bonEngin.setCode(null);
bonEngin.setCompteurAbsoluKm(null);
bonEngin.setCompteurKm(null);
bonEngin.setCompteurH(null);
bonEngin.setCompteurAbsoluH(null);
bonEngin.setConsommationH(null);
bonEngin.setConsommationKm(null);
bonEngin.setQuantite(null);
bonEngin.setCarburant(null);
bonEngin.setCompteurPompe(null);
bonEngin.setCompteurHenPanne(null);
bonEngin.setCompteurKmenPanne(null);
bonEngin.setNbrHeures(null);
bonEngin.setNbrKm(null);
bonEngin.setConsommationPrevu(null);
bonEngin.setChargeHoraire(null);
Employe chauf = new Employe();
chauf.setNom(chauffeur);
Employe pomp = new Employe();
pomp.setNom(pompiste);
Engin engin1 = new Engin();
engin1.setCode(engin);
engin1.setObjectif(null);
engin1.setConsommationMoyenne(null);
SousFamille sousFamille1 = new SousFamille();
sousFamille1.setNom(sousFamille);
Famille famille1 = new Famille();
famille1.setNom(famille);
Groupe groupe1 = new Groupe();
groupe1.setNom(groupe);
Chantier chantierDepart1 = new Chantier();
Chantier chantierArrivee1 = new Chantier();
chantierDepart1.setNom(chantierDepart);
chantierArrivee1.setNom(chantierArrivee);
Marque marque1 = new Marque();
marque1.setNom(marque);
Classe classe1 = new Classe();
classe1.setNom(classe);
famille1.setClasse(classe1);
sousFamille1.setFamille(famille1);
sousFamille1.setMarque(marque1);
engin1.setSousFamille(sousFamille1);
engin1.setGroupe(groupe1);
bonEngin.setPompiste(pomp);
bonEngin.setChauffeur(chauf);
bonEngin.setEngin(engin1);
bonEngin.setChantierGazoil(chantierDepart1);
bonEngin.setChantierTravail(chantierArrivee1);
ExampleMatcher matcher = ExampleMatcher.matchingAll().withStringMatcher(ExampleMatcher.StringMatcher.EXACT).withIgnoreCase().withIgnoreNullValues();
Example<BonEngin> example = Example.of(bonEngin, matcher);
log.debug("getting search results");
List<BonEngin> page = bonEnginRepo.findAll(example);
if (locataire.equals("oui"))
page = page.stream().filter(bonEngin1 -> bonEngin1.getEngin().getGroupe().getLocataire()).collect(Collectors.toList());
else if (locataire.equals("non"))
page = page.stream().filter(bonEngin1 -> !bonEngin1.getEngin().getGroupe().getLocataire()).collect(Collectors.toList());
try {
page = page.stream().filter(bonEngin1 -> bonEngin1.getDate().isBefore(LocalDate.parse(bonEnginDto.getDateTo(), DateTimeFormatter.ofPattern("yyyy-MM-dd"))) || bonEngin1.getDate().isEqual(LocalDate.parse(bonEnginDto.getDateTo(), DateTimeFormatter.ofPattern("yyyy-MM-dd")))).filter(bonEngin1 -> bonEngin1.getDate().isAfter(LocalDate.parse(bonEnginDto.getDateFrom(), DateTimeFormatter.ofPattern("yyyy-MM-dd"))) || bonEngin1.getDate().isEqual(LocalDate.parse(bonEnginDto.getDateFrom(), DateTimeFormatter.ofPattern("yyyy-MM-dd")))).collect(Collectors.toList());
} catch (DateTimeParseException e) {
return page;
}
log.debug("filter by dates successfully");
return page;
} catch (Exception e) {
log.debug("Failed retrieving list of bons Engins");
throw new OperationFailedException("Operation échouée", e);
}
}
use of me.kadarh.mecaworks.domain.dtos.BonEnginDto in project mecaworks by KadarH.
the class FilterBonEnginController method home.
@GetMapping("/be")
public String home(Model model) {
List<Chantier> list = chantierService.getList();
model.addAttribute("chantiers", list);
model.addAttribute("engins", enginService.getList());
model.addAttribute("classes", classeService.list());
model.addAttribute("groupes", groupeService.list());
model.addAttribute("marques", marqueService.list());
model.addAttribute("familles", familleService.list());
model.addAttribute("sousFamilles", sousFamilleService.list());
model.addAttribute("employes", employeService.getList());
BonEnginDto bonEnginDto = new BonEnginDto();
bonEnginDto.setChantierArrivee(list.size() != 0 ? list.get(0).getNom() : "");
List<BonEngin> bonEngins = bonFilterService.filterBonEngin(bonEnginDto);
model.addAttribute("page", bonEngins);
double conH = bonEngins.stream().filter(bonEngin -> bonEngin.getConsommationH() != 0).mapToDouble(BonEngin::getConsommationH).average().orElse(0);
double conKm = bonEngins.stream().filter(bonEngin -> bonEngin.getConsommationKm() != 0).mapToDouble(BonEngin::getConsommationKm).average().orElse(0);
model.addAttribute("consommationH_avg", conH);
model.addAttribute("consommationKm_avg", conKm);
model.addAttribute("bonEnginDto", bonEnginDto);
return "user/filter/bonEngins";
}
use of me.kadarh.mecaworks.domain.dtos.BonEnginDto in project mecaworks by KadarH.
the class FilterEnginController method home.
@GetMapping
public String home(Model model) {
fillModel(model);
BonEnginDto bonEnginDto = new BonEnginDto();
List<Chantier> list = chantierService.getList();
bonEnginDto.setChantierArrivee(list.size() != 0 ? list.get(0).getNom() : "");
model.addAttribute("bonEnginDto", bonEnginDto);
model.addAttribute("page", bonFilterService.filterEngins(bonEnginDto));
return "user/filter/engins";
}
Aggregations