Search in sources :

Example 1 with BonEnginDto

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);
    }
}
Also used : BonEnginRepo(me.kadarh.mecaworks.repo.bons.BonEnginRepo) BonFournisseur(me.kadarh.mecaworks.domain.bons.BonFournisseur) BonEngin(me.kadarh.mecaworks.domain.bons.BonEngin) BonLivraison(me.kadarh.mecaworks.domain.bons.BonLivraison) ExampleMatcher(org.springframework.data.domain.ExampleMatcher) BonEnginDto(me.kadarh.mecaworks.domain.dtos.BonEnginDto) Example(org.springframework.data.domain.Example) Collectors(java.util.stream.Collectors) BonFournisseurDto(me.kadarh.mecaworks.domain.dtos.BonFournisseurDto) BonFilterService(me.kadarh.mecaworks.service.bons.BonFilterService) ArrayList(java.util.ArrayList) Slf4j(lombok.extern.slf4j.Slf4j) OperationFailedException(me.kadarh.mecaworks.service.exceptions.OperationFailedException) DateTimeParseException(java.time.format.DateTimeParseException) List(java.util.List) BonFournisseurRepo(me.kadarh.mecaworks.repo.bons.BonFournisseurRepo) ChronoUnit(java.time.temporal.ChronoUnit) Service(org.springframework.stereotype.Service) LocalDate(java.time.LocalDate) DateTimeFormatter(java.time.format.DateTimeFormatter) BonLivraisonRepo(me.kadarh.mecaworks.repo.bons.BonLivraisonRepo) BonLivraisonDto(me.kadarh.mecaworks.domain.dtos.BonLivraisonDto) me.kadarh.mecaworks.domain.others(me.kadarh.mecaworks.domain.others) Transactional(org.springframework.transaction.annotation.Transactional) OperationFailedException(me.kadarh.mecaworks.service.exceptions.OperationFailedException) OperationFailedException(me.kadarh.mecaworks.service.exceptions.OperationFailedException) DateTimeParseException(java.time.format.DateTimeParseException) DateTimeParseException(java.time.format.DateTimeParseException) BonEngin(me.kadarh.mecaworks.domain.bons.BonEngin) ExampleMatcher(org.springframework.data.domain.ExampleMatcher) BonEngin(me.kadarh.mecaworks.domain.bons.BonEngin)

Example 2 with BonEnginDto

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";
}
Also used : Valid(javax.validation.Valid) PostMapping(org.springframework.web.bind.annotation.PostMapping) Model(org.springframework.ui.Model) List(java.util.List) me.kadarh.mecaworks.service(me.kadarh.mecaworks.service) BonEngin(me.kadarh.mecaworks.domain.bons.BonEngin) GetMapping(org.springframework.web.bind.annotation.GetMapping) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) Controller(org.springframework.stereotype.Controller) BonEnginDto(me.kadarh.mecaworks.domain.dtos.BonEnginDto) Chantier(me.kadarh.mecaworks.domain.others.Chantier) BonFilterService(me.kadarh.mecaworks.service.bons.BonFilterService) BonEngin(me.kadarh.mecaworks.domain.bons.BonEngin) Chantier(me.kadarh.mecaworks.domain.others.Chantier) BonEnginDto(me.kadarh.mecaworks.domain.dtos.BonEnginDto) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 3 with BonEnginDto

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";
}
Also used : Chantier(me.kadarh.mecaworks.domain.others.Chantier) BonEnginDto(me.kadarh.mecaworks.domain.dtos.BonEnginDto) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Aggregations

BonEnginDto (me.kadarh.mecaworks.domain.dtos.BonEnginDto)3 List (java.util.List)2 BonEngin (me.kadarh.mecaworks.domain.bons.BonEngin)2 Chantier (me.kadarh.mecaworks.domain.others.Chantier)2 BonFilterService (me.kadarh.mecaworks.service.bons.BonFilterService)2 GetMapping (org.springframework.web.bind.annotation.GetMapping)2 LocalDate (java.time.LocalDate)1 DateTimeFormatter (java.time.format.DateTimeFormatter)1 DateTimeParseException (java.time.format.DateTimeParseException)1 ChronoUnit (java.time.temporal.ChronoUnit)1 ArrayList (java.util.ArrayList)1 Collectors (java.util.stream.Collectors)1 Valid (javax.validation.Valid)1 Slf4j (lombok.extern.slf4j.Slf4j)1 BonFournisseur (me.kadarh.mecaworks.domain.bons.BonFournisseur)1 BonLivraison (me.kadarh.mecaworks.domain.bons.BonLivraison)1 BonFournisseurDto (me.kadarh.mecaworks.domain.dtos.BonFournisseurDto)1 BonLivraisonDto (me.kadarh.mecaworks.domain.dtos.BonLivraisonDto)1 me.kadarh.mecaworks.domain.others (me.kadarh.mecaworks.domain.others)1 BonEnginRepo (me.kadarh.mecaworks.repo.bons.BonEnginRepo)1