Search in sources :

Example 1 with BonEngin

use of me.kadarh.mecaworks.domain.bons.BonEngin in project mecaworks by KadarH.

the class BonEnginServiceImpl method insertAlertes.

/* ------------------------------------------------------------------------------ */
/* ------------ PRIVATE METHODES ----------------------------------------------- */
/* ---------------------------------------------------------------------------- */
private void insertAlertes(BonEngin bonEngin) {
    BonEngin lastBonEngin = getLastBonEngin(bonEngin.getEngin());
    // Verify if chauffeur is changed.
    if (lastBonEngin.getChauffeur() != bonEngin.getChauffeur())
        insertAlerte(bonEngin, "Chauffeur changé", TypeAlerte.CHAUFFEUR_CHANGED);
    // Verify if compteur is en panne , and if no verify if compteur last bon was en panne
    if (whichCompteurIsDown(bonEngin) == 1)
        insertAlerte(bonEngin, "Compteur H En Panne", TypeAlerte.COMPTEUR_H_EN_PANNE);
    else if (whichCompteurIsDown(getLastBonEngin(bonEngin.getEngin())) == 1)
        insertAlerte(bonEngin, "Compteur H Reparé", TypeAlerte.COMPTEUR_H_REPARE);
    if (whichCompteurIsDown(bonEngin) == 2)
        insertAlerte(bonEngin, "Compteur Km En Panne", TypeAlerte.COMPTEUR_KM_EN_PANNE);
    else if (whichCompteurIsDown(getLastBonEngin(bonEngin.getEngin())) == 2)
        insertAlerte(bonEngin, "Compteur Km Reparé", TypeAlerte.COMPTEUR_KM_REPARE);
    if (whichCompteurIsDown(bonEngin) == 3) {
        insertAlerte(bonEngin, "Compteur H En Panne", TypeAlerte.COMPTEUR_H_EN_PANNE);
        insertAlerte(bonEngin, "Compteur Km En Panne", TypeAlerte.COMPTEUR_KM_EN_PANNE);
    } else {
        if (whichCompteurIsDown(getLastBonEngin(bonEngin.getEngin())) == 1)
            insertAlerte(bonEngin, "Compteur H Reparé", TypeAlerte.COMPTEUR_H_REPARE);
        if (whichCompteurIsDown(getLastBonEngin(bonEngin.getEngin())) == 2)
            insertAlerte(bonEngin, "Compteur Km Reparé", TypeAlerte.COMPTEUR_KM_REPARE);
    }
    // verify quantité
    if (bonEngin.getQuantite() > bonEngin.getEngin().getSousFamille().getCapaciteReservoir())
        insertAlerte(bonEngin, "Quantité de gazoil depasse la capacité de reservoir", TypeAlerte.QUANTITE_MORE_THAN_RESERVOIR);
}
Also used : BonEngin(me.kadarh.mecaworks.domain.bons.BonEngin)

Example 2 with BonEngin

use of me.kadarh.mecaworks.domain.bons.BonEngin in project mecaworks by KadarH.

the class BonFilterServiceImpl method filterEngins.

@Override
public List<BonEngin> filterEngins(BonEnginDto bonEnginDto) {
    try {
        // if dateFrom and dateTo was not set, get bons for the past week.
        if (bonEnginDto.getDateFrom().equals("") && bonEnginDto.getDateTo().equals("")) {
            bonEnginDto.setDateFrom((LocalDate.now().minus(6, ChronoUnit.DAYS)).format(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
            bonEnginDto.setDateTo(LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
        }
        List<BonEngin> bonEngins = filterBonEngin(bonEnginDto);
        // sort by engin & date
        bonEngins.sort((o1, o2) -> {
            if (o1.getEngin().getCode().equals(o2.getEngin().getCode()))
                return o1.getDate().compareTo(o2.getDate());
            return o1.getEngin().getCode().compareTo(o2.getEngin().getCode());
        });
        if (bonEngins.size() == 0)
            return bonEngins;
        List<BonEngin> list = new ArrayList<>();
        BonEngin help = new BonEngin(bonEngins.get(0));
        float consommationKmMoyenne = 0;
        float consommationHMoyenne = 0;
        int totalH = 0;
        int totalKm = 0;
        long nbH = 0;
        long nbKm = 0;
        for (BonEngin bonEngin : bonEngins) {
            if (help.getEngin().getCode().equals(bonEngin.getEngin().getCode())) {
                consommationHMoyenne += bonEngin.getConsommationH();
                consommationKmMoyenne += bonEngin.getConsommationKm();
                if (bonEngin.getConsommationH() != 0)
                    totalH++;
                if (bonEngin.getConsommationKm() != 0)
                    totalKm++;
                nbH += bonEngin.getNbrHeures();
                nbKm += bonEngin.getNbrKm();
            } else {
                help.setChargeHoraire((long) (consommationHMoyenne / totalH));
                help.setConsommationPrevu((long) (consommationKmMoyenne / totalKm));
                help.setNbrKm(nbKm);
                help.setNbrHeures(nbH);
                list.add(help);
                consommationHMoyenne = bonEngin.getConsommationH();
                consommationKmMoyenne = bonEngin.getConsommationKm();
                totalH = bonEngin.getConsommationH() != 0 ? 1 : 0;
                totalKm = bonEngin.getConsommationKm() != 0 ? 1 : 0;
                nbH = bonEngin.getNbrHeures();
                nbKm = bonEngin.getNbrKm();
            }
            help = new BonEngin(bonEngin);
        }
        help.setChargeHoraire((long) (consommationHMoyenne / totalH));
        help.setConsommationPrevu((long) (consommationKmMoyenne / totalKm));
        help.setNbrKm(nbKm);
        help.setNbrHeures(nbH);
        list.add(help);
        return list;
    } catch (Exception e) {
        log.debug("Failed retrieving list of Engins");
        throw new OperationFailedException("Operation échouée", e);
    }
}
Also used : BonEngin(me.kadarh.mecaworks.domain.bons.BonEngin) ArrayList(java.util.ArrayList) OperationFailedException(me.kadarh.mecaworks.service.exceptions.OperationFailedException) OperationFailedException(me.kadarh.mecaworks.service.exceptions.OperationFailedException) DateTimeParseException(java.time.format.DateTimeParseException)

Example 3 with BonEngin

use of me.kadarh.mecaworks.domain.bons.BonEngin 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 4 with BonEngin

use of me.kadarh.mecaworks.domain.bons.BonEngin in project mecaworks by KadarH.

the class UserCalculService method getMonthsWithQuantities.

public Quantite getMonthsWithQuantities(Chantier chantier, int month, int year) {
    log.info("calling method getListChantierWithQuantities(month,year) in UserCalculService -- ");
    LocalDate from = LocalDate.of(year, Month.of(month).getValue(), 1);
    LocalDate to = LocalDate.of(year, Month.of(month).plus(1).getValue(), 1);
    if (month == 12)
        to = LocalDate.of(year + 1, Month.of(month).plus(1).getValue(), 1);
    List<BonEngin> bonEngins = bonEnginRepo.findAllByChantier(chantier.getId(), from, to);
    List<BonLivraison> bonLivraisons = bonLivraisonRepo.findAllByChantier(chantier.getId(), from, to);
    List<BonFournisseur> bonFournisseurs = bonFournisseurRepo.findAllByChantier(chantier.getId(), from, to);
    Long quantiteTotal, quantiteLocation, chargeLocataireTotale, chargeLocataireExterne, consommationPrevue, gazoilAchetee, gazoilFlottant;
    quantiteTotal = bonEngins.stream().mapToLong(BonEngin::getQuantite).sum();
    quantiteLocation = bonEngins.stream().filter(bonEngin -> bonEngin.getEngin().getGroupe().getLocataire()).mapToLong(BonEngin::getQuantite).sum();
    chargeLocataireTotale = bonEngins.stream().mapToLong(bonEngin -> bonEngin.getChargeHoraire()).sum();
    chargeLocataireExterne = bonEngins.stream().filter(bonEngin -> bonEngin.getEngin().getGroupe().getLocataire()).mapToLong(BonEngin::getQuantite).sum();
    consommationPrevue = bonEngins.stream().mapToLong(BonEngin::getConsommationPrevu).sum();
    gazoilAchetee = bonFournisseurs.stream().mapToLong(BonFournisseur::getQuantite).sum();
    gazoilFlottant = bonLivraisons.stream().mapToLong(BonLivraison::getQuantite).sum();
    return new Quantite(month + "/" + year, quantiteTotal, quantiteLocation, chargeLocataireTotale, chargeLocataireExterne, 8.5f, consommationPrevue, gazoilAchetee, gazoilFlottant);
}
Also used : Engin(me.kadarh.mecaworks.domain.others.Engin) java.util(java.util) BonEnginRepo(me.kadarh.mecaworks.repo.bons.BonEnginRepo) Month(java.time.Month) BonFournisseur(me.kadarh.mecaworks.domain.bons.BonFournisseur) Quantite(me.kadarh.mecaworks.domain.user.Quantite) EnginService(me.kadarh.mecaworks.service.EnginService) BonEngin(me.kadarh.mecaworks.domain.bons.BonEngin) BonLivraison(me.kadarh.mecaworks.domain.bons.BonLivraison) Chantier(me.kadarh.mecaworks.domain.others.Chantier) Collectors(java.util.stream.Collectors) ResourceNotFoundException(me.kadarh.mecaworks.service.exceptions.ResourceNotFoundException) Slf4j(lombok.extern.slf4j.Slf4j) OperationFailedException(me.kadarh.mecaworks.service.exceptions.OperationFailedException) BonFournisseurRepo(me.kadarh.mecaworks.repo.bons.BonFournisseurRepo) ChronoUnit(java.time.temporal.ChronoUnit) ChantierBatch(me.kadarh.mecaworks.domain.user.ChantierBatch) StockRepo(me.kadarh.mecaworks.repo.others.StockRepo) Service(org.springframework.stereotype.Service) LocalDate(java.time.LocalDate) BonLivraisonRepo(me.kadarh.mecaworks.repo.bons.BonLivraisonRepo) Stock(me.kadarh.mecaworks.domain.others.Stock) Transactional(org.springframework.transaction.annotation.Transactional) BonLivraison(me.kadarh.mecaworks.domain.bons.BonLivraison) BonEngin(me.kadarh.mecaworks.domain.bons.BonEngin) BonFournisseur(me.kadarh.mecaworks.domain.bons.BonFournisseur) Quantite(me.kadarh.mecaworks.domain.user.Quantite) LocalDate(java.time.LocalDate)

Example 5 with BonEngin

use of me.kadarh.mecaworks.domain.bons.BonEngin in project mecaworks by KadarH.

the class UserCalculService method getListDaysQuantities.

public List<Quantite> getListDaysQuantities(Chantier chantier, int month, int year) {
    // Declaring variables
    List<Quantite> quantites = new ArrayList<>();
    LocalDate from = LocalDate.of(year, Month.of(month).getValue(), 1);
    LocalDate to = LocalDate.of(year, Month.of(month).plus(1).getValue(), 1);
    if (month == 12)
        to = LocalDate.of(year + 1, Month.of(month).plus(1).getValue(), 1);
    List<BonEngin> bonEngins = bonEnginRepo.findAllByChantier(chantier.getId(), from, to);
    List<BonLivraison> bonLivraisons = bonLivraisonRepo.findAllByChantier(chantier.getId(), from, to);
    List<BonFournisseur> bonFournisseurs = bonFournisseurRepo.findAllByChantier(chantier.getId(), from, to);
    Long quantiteTotal, quantiteLocation, chargeLocataireTotale, chargeLocataireExterne, consommationPrevue, gazoilAchetee, gazoilFlottant;
    String date;
    long days = ChronoUnit.DAYS.between(from, to);
    for (int i = 0; i < days; i++) {
        LocalDate localDate = LocalDate.of(year, month, i + 1);
        date = (i + 1) + "-" + month + "-" + year;
        quantiteTotal = bonEngins.stream().filter(be -> be.getDate().equals(localDate)).mapToLong(BonEngin::getQuantite).sum();
        quantiteLocation = bonEngins.stream().filter(be -> be.getDate().equals(localDate)).filter(bonEngin -> bonEngin.getEngin().getGroupe().getLocataire()).mapToLong(BonEngin::getQuantite).sum();
        chargeLocataireTotale = bonEngins.stream().filter(be -> be.getDate().equals(localDate)).mapToLong(BonEngin::getNbrHeures).sum();
        chargeLocataireExterne = bonEngins.stream().filter(be -> be.getDate().equals(localDate)).mapToLong(BonEngin::getQuantite).sum();
        consommationPrevue = bonEngins.stream().filter(be -> be.getDate().equals(localDate)).mapToLong(BonEngin::getQuantite).sum();
        gazoilAchetee = bonFournisseurs.stream().filter(bf -> bf.getDate().equals(localDate)).mapToLong(BonFournisseur::getQuantite).sum();
        gazoilFlottant = bonLivraisons.stream().filter(bl -> bl.getDate().equals(localDate)).mapToLong(BonLivraison::getQuantite).sum();
        quantites.add(new Quantite(date, quantiteTotal, quantiteLocation, chargeLocataireTotale, chargeLocataireExterne, 8.5f, consommationPrevue, gazoilAchetee, gazoilFlottant));
    }
    return quantites;
}
Also used : Engin(me.kadarh.mecaworks.domain.others.Engin) java.util(java.util) BonEnginRepo(me.kadarh.mecaworks.repo.bons.BonEnginRepo) Month(java.time.Month) BonFournisseur(me.kadarh.mecaworks.domain.bons.BonFournisseur) Quantite(me.kadarh.mecaworks.domain.user.Quantite) EnginService(me.kadarh.mecaworks.service.EnginService) BonEngin(me.kadarh.mecaworks.domain.bons.BonEngin) BonLivraison(me.kadarh.mecaworks.domain.bons.BonLivraison) Chantier(me.kadarh.mecaworks.domain.others.Chantier) Collectors(java.util.stream.Collectors) ResourceNotFoundException(me.kadarh.mecaworks.service.exceptions.ResourceNotFoundException) Slf4j(lombok.extern.slf4j.Slf4j) OperationFailedException(me.kadarh.mecaworks.service.exceptions.OperationFailedException) BonFournisseurRepo(me.kadarh.mecaworks.repo.bons.BonFournisseurRepo) ChronoUnit(java.time.temporal.ChronoUnit) ChantierBatch(me.kadarh.mecaworks.domain.user.ChantierBatch) StockRepo(me.kadarh.mecaworks.repo.others.StockRepo) Service(org.springframework.stereotype.Service) LocalDate(java.time.LocalDate) BonLivraisonRepo(me.kadarh.mecaworks.repo.bons.BonLivraisonRepo) Stock(me.kadarh.mecaworks.domain.others.Stock) Transactional(org.springframework.transaction.annotation.Transactional) BonFournisseur(me.kadarh.mecaworks.domain.bons.BonFournisseur) LocalDate(java.time.LocalDate) BonLivraison(me.kadarh.mecaworks.domain.bons.BonLivraison) BonEngin(me.kadarh.mecaworks.domain.bons.BonEngin) Quantite(me.kadarh.mecaworks.domain.user.Quantite)

Aggregations

BonEngin (me.kadarh.mecaworks.domain.bons.BonEngin)21 OperationFailedException (me.kadarh.mecaworks.service.exceptions.OperationFailedException)8 LocalDate (java.time.LocalDate)6 BonLivraison (me.kadarh.mecaworks.domain.bons.BonLivraison)6 ChronoUnit (java.time.temporal.ChronoUnit)5 Collectors (java.util.stream.Collectors)5 Slf4j (lombok.extern.slf4j.Slf4j)5 BonFournisseur (me.kadarh.mecaworks.domain.bons.BonFournisseur)5 Chantier (me.kadarh.mecaworks.domain.others.Chantier)5 BonEnginRepo (me.kadarh.mecaworks.repo.bons.BonEnginRepo)5 BonFournisseurRepo (me.kadarh.mecaworks.repo.bons.BonFournisseurRepo)5 BonLivraisonRepo (me.kadarh.mecaworks.repo.bons.BonLivraisonRepo)5 Service (org.springframework.stereotype.Service)5 Transactional (org.springframework.transaction.annotation.Transactional)5 Month (java.time.Month)4 java.util (java.util)4 ArrayList (java.util.ArrayList)4 Engin (me.kadarh.mecaworks.domain.others.Engin)4 Stock (me.kadarh.mecaworks.domain.others.Stock)4 ChantierBatch (me.kadarh.mecaworks.domain.user.ChantierBatch)4