Search in sources :

Example 6 with BonEngin

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

the class BonEnginServiceImpl method hasErrorsAttention.

/**
 * @param bon the current BonEngin
 * @return boolean value
 * 0 if one of (quantity or meter) hasn't a logic value
 * 1 else ( if compteur and quantité are logic )
 */
@Override
public boolean hasErrorsAttention(BonEngin bon) {
    calculAbsoluService.fillBon(bon);
    BonEngin bonEngin = persistService.getLastBonEngin(bon.getEngin(), bon.getDate());
    if (bonEngin == null)
        return false;
    if (bon.getEngin().getSousFamille().getTypeCompteur().equals(TypeCompteur.H))
        return (bon.getCompteurH() < bonEngin.getCompteurH() && !bon.getCompteurHenPanne());
    if (bon.getEngin().getSousFamille().getTypeCompteur().equals(TypeCompteur.KM))
        return (bon.getCompteurKm() < bonEngin.getCompteurKm());
    if (bon.getEngin().getSousFamille().getTypeCompteur().equals(TypeCompteur.KM_H))
        return (bon.getCompteurH() < bonEngin.getCompteurH()) || (bon.getCompteurKm() < bonEngin.getCompteurKm());
    return false;
}
Also used : BonEngin(me.kadarh.mecaworks.domain.bons.BonEngin)

Example 7 with BonEngin

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

the class CalculConsommationServiceImpl method calculConsommation.

public BonEngin calculConsommation(BonEngin bonEngin) {
    TypeCompteur typeCompteur = bonEngin.getEngin().getSousFamille().getTypeCompteur();
    BonEngin lastBon, lastBon2;
    long som_Q = 0;
    List<BonEngin> list = new ArrayList<>();
    if (typeCompteur.equals(TypeCompteur.H)) {
        lastBon = bonEnginRepo.findLastBonEnginH_toConsommation(bonEngin.getEngin().getId(), bonEngin.getDate());
        if (lastBon != null) {
            list = bonEnginRepo.findAllBetweenLastBonAndCurrentBon_H(bonEngin.getEngin().getId(), lastBon.getCompteurAbsoluH());
            list.remove(lastBon);
            for (BonEngin b : list) som_Q += b.getQuantite();
            som_Q += bonEngin.getQuantite();
            if (bonEngin.getCompteurAbsoluH() > lastBon.getCompteurAbsoluH())
                bonEngin.setConsommationH((float) som_Q / (bonEngin.getCompteurAbsoluH() - lastBon.getCompteurAbsoluH()));
            else
                bonEngin.setConsommationH(0f);
        }
        if (bonEngin.getCompteurHenPanne() || (!list.isEmpty() && list.get(list.size() - 1).getCompteurHenPanne()))
            bonEngin.setConsommationH(0f);
    }
    if (typeCompteur.equals(TypeCompteur.KM)) {
        lastBon = bonEnginRepo.findLastBonEnginKm_toConsommation(bonEngin.getEngin().getId(), bonEngin.getDate());
        if (lastBon != null) {
            list = bonEnginRepo.findAllBetweenLastBonAndCurrentBon_Km(bonEngin.getEngin().getId(), lastBon.getCompteurAbsoluKm());
            list.remove(lastBon);
            for (BonEngin b : list) som_Q += b.getQuantite();
            som_Q += bonEngin.getQuantite();
            if (bonEngin.getCompteurAbsoluKm() > lastBon.getCompteurAbsoluKm())
                bonEngin.setConsommationKm((float) som_Q * 100 / (bonEngin.getCompteurAbsoluKm() - lastBon.getCompteurAbsoluKm()));
            else
                bonEngin.setConsommationKm(0f);
        }
        if (bonEngin.getCompteurKmenPanne() || (!list.isEmpty() && list.get(list.size() - 1).getCompteurKmenPanne()))
            bonEngin.setConsommationKm(0f);
    }
    if (typeCompteur.equals(TypeCompteur.KM_H)) {
        long som_Q_2 = 0;
        lastBon = bonEnginRepo.findLastBonEnginKm_toConsommation(bonEngin.getEngin().getId(), bonEngin.getDate());
        lastBon2 = bonEnginRepo.findLastBonEnginH_toConsommation(bonEngin.getEngin().getId(), bonEngin.getDate());
        if (lastBon != null) {
            list = bonEnginRepo.findAllBetweenLastBonAndCurrentBon_Km(bonEngin.getEngin().getId(), lastBon.getCompteurAbsoluKm());
            list.remove(lastBon);
            for (BonEngin b : list) {
                if (b.getQuantite() != null)
                    som_Q += b.getQuantite();
            }
            som_Q += bonEngin.getQuantite();
            bonEngin.setConsommationKm((float) som_Q * 100 / (bonEngin.getCompteurAbsoluKm() - lastBon.getCompteurAbsoluKm()));
        }
        if (bonEngin.getCompteurHenPanne() || (!list.isEmpty() && list.get(list.size() - 1).getCompteurHenPanne()))
            bonEngin.setConsommationH(0f);
        if (lastBon2 != null) {
            list = bonEnginRepo.findAllBetweenLastBonAndCurrentBon_H(bonEngin.getEngin().getId(), lastBon2.getCompteurAbsoluH());
            list.remove(lastBon);
            for (BonEngin b : list) {
                if (b.getQuantite() != null)
                    som_Q_2 += b.getQuantite();
            }
            som_Q_2 += bonEngin.getQuantite();
            bonEngin.setConsommationH((float) som_Q_2 / (bonEngin.getCompteurAbsoluH() - lastBon2.getCompteurAbsoluH()));
        }
        if (bonEngin.getCompteurKmenPanne() || (!list.isEmpty() && list.get(list.size() - 1).getCompteurKmenPanne()))
            bonEngin.setConsommationKm(0f);
    }
    return bonEngin;
}
Also used : TypeCompteur(me.kadarh.mecaworks.domain.others.TypeCompteur) BonEngin(me.kadarh.mecaworks.domain.bons.BonEngin) ArrayList(java.util.ArrayList)

Example 8 with BonEngin

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

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

the class DataFakerB method loadBonsEngin.

private void loadBonsEngin(int n, int m) {
    for (int i = 0; i < n; i++) {
        Chantier chantierGazoil = chantierRepo.getOne(i / 20 + 1L);
        Chantier chantierTravail = chantierRepo.getOne(i / 20 + 2L);
        // Getting chantier + engin +
        Engin engin = enginRepo.getOne(i / 4 + 1L);
        // Creating the object
        BonEngin bonEngin = new BonEngin();
        bonEngin.setCode("2093" + (i * 13));
        bonEngin.setCompteurH(100L + i * 5);
        bonEngin.setCompteurAbsoluH(100L + i * 10);
        bonEngin.setCompteurKm(100L + i * 5);
        bonEngin.setCompteurAbsoluKm(100L + i * 10);
        bonEngin.setQuantite(20);
        bonEngin.setChantierGazoil(chantierGazoil);
        bonEngin.setChantierTravail(chantierTravail);
        Employe chauffeur = new Employe();
        chauffeur.setNom("Mr C" + i);
        chauffeur.setMetier(Metier.CHAUFFEUR.name());
        bonEngin.setChauffeur(employeRepo.save(chauffeur));
        Employe pompiste = new Employe();
        pompiste.setNom("Mr P" + i);
        pompiste.setMetier(Metier.POMPISTE.name());
        bonEngin.setPompiste(employeRepo.save(pompiste));
        DateTimeFormatter d = DateTimeFormatter.ofPattern("yyyy-MM-dd");
        LocalDate date = LocalDate.parse(LocalDate.now().format(d), d);
        bonEngin.setDate(date);
        if (i % 2 == 1) {
            bonEngin.setCompteurKmenPanne(true);
            bonEngin.setCompteurHenPanne(true);
            bonEngin.setPlein(true);
        } else {
            bonEngin.setCompteurKmenPanne(false);
            bonEngin.setCompteurHenPanne(false);
            bonEngin.setPlein(false);
        }
        bonEngin.setEngin(engin);
        bonEnginRepo.save(bonEngin);
    }
    log.info(n + " Bons Engin Loaded *****");
    for (int i = 0; i < m; i++) {
        Chantier chantierGazoil = chantierRepo.getOne(i / 10 + 1L);
        Chantier chantierTravail = chantierRepo.getOne(i / 10 + 2L);
        // Getting chantier + engin +
        Engin engin = enginRepo.getOne(i / 4 + 1L);
        BonEngin bonEngin = new BonEngin();
        bonEngin.setCode("3297" + (i * 10));
        bonEngin.setCompteurH(100L + i * 5);
        bonEngin.setCompteurAbsoluH(100L + i * 10);
        bonEngin.setCompteurKm(100L + i * 5);
        bonEngin.setCompteurAbsoluKm(100L + i * 10);
        bonEngin.setQuantite(20 + i * 10);
        bonEngin.setChantierGazoil(chantierGazoil);
        bonEngin.setChantierTravail(chantierTravail);
        bonEngin.setDate(LocalDate.now());
        if (i % 2 == 0) {
            bonEngin.setCompteurKmenPanne(true);
            bonEngin.setCompteurHenPanne(false);
            bonEngin.setPlein(true);
        } else {
            bonEngin.setCompteurKmenPanne(false);
            bonEngin.setCompteurHenPanne(false);
            bonEngin.setPlein(false);
        }
        bonEngin.setEngin(engin);
        bonEnginRepo.save(bonEngin);
        BonLivraison bonLivraison = new BonLivraison();
        bonLivraison.setCode("KHS" + i + "LL");
        bonLivraison.setChantierDepart(chantierGazoil);
        bonLivraison.setChantierArrivee(chantierTravail);
        bonLivraison.setQuantite(20 + i * 10);
        bonLivraison.setDate(LocalDate.now());
        Employe transporteur = new Employe();
        transporteur.setNom("Mr Tr" + i);
        transporteur.setMetier(Metier.CHAUFFEUR.name());
        bonLivraison.setTransporteur(employeRepo.save(transporteur));
        Employe pompiste = new Employe();
        pompiste.setNom("Mr Pom" + i);
        pompiste.setMetier(Metier.POMPISTE.name());
        bonEngin.setPompiste(employeRepo.save(pompiste));
        bonLivraison.setPompiste(pompiste);
        bonLivraisonRepo.save(bonLivraison);
    }
    log.info(n + " Bons Engin + Bons Livraison direct Loaded *****");
}
Also used : BonLivraison(me.kadarh.mecaworks.domain.bons.BonLivraison) BonEngin(me.kadarh.mecaworks.domain.bons.BonEngin) BonEngin(me.kadarh.mecaworks.domain.bons.BonEngin) DateTimeFormatter(java.time.format.DateTimeFormatter) LocalDate(java.time.LocalDate)

Example 10 with BonEngin

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

the class BonEnginServiceImpl method calculConsommation.

private BonEngin calculConsommation(BonEngin bonEngin) {
    // get last bon Engin [ BX ] with cmpEnpanne=non && plein =oui
    // get list of bons between BX and the current bon
    // SOM_Q = calculate lmejmou3 dial les quantite ,
    // AA = absolu current bon - absolu BX
    // calculate consommatio = SOM_Q/AA ( l7ala dial km : SOM_Q*100/AA
    TypeCompteur typeCompteur = bonEngin.getEngin().getSousFamille().getTypeCompteur();
    BonEngin lastBon, lastBon2;
    long som_Q = 0;
    long som_Q_2 = 0;
    if (typeCompteur.equals(TypeCompteur.H)) {
        lastBon = bonEnginRepo.findLastBonEnginH_toConsommation(bonEngin.getEngin());
        for (BonEngin b : bonEnginRepo.findAllBetweenLastBonAndCurrentBon_H(lastBon.getCompteurAbsoluH())) som_Q += b.getQuantite();
        bonEngin.setConsommationH((float) som_Q / (bonEngin.getCompteurAbsoluH() - lastBon.getCompteurAbsoluH()));
        if (bonEngin.getConsommationH() > bonEngin.getEngin().getSousFamille().getConsommationHMax())
            insertAlerte(bonEngin, "La consommation H est Annormale", TypeAlerte.CONSOMMATION_H_ANNORMALE);
    }
    if (typeCompteur.equals(TypeCompteur.KM)) {
        lastBon = bonEnginRepo.findLastBonEnginKm_toConsommation(bonEngin.getEngin());
        for (BonEngin b : bonEnginRepo.findAllBetweenLastBonAndCurrentBon_Km(lastBon.getCompteurAbsoluKm())) som_Q += b.getQuantite();
        bonEngin.setConsommationKm((float) som_Q * 100 / (bonEngin.getCompteurAbsoluKm() - lastBon.getCompteurAbsoluKm()));
        if (bonEngin.getConsommationKm() > bonEngin.getEngin().getSousFamille().getConsommationKmMax())
            insertAlerte(bonEngin, "La consommation Km est Annormale", TypeAlerte.CONSOMMATION_KM_ANNORMALE);
    }
    if (typeCompteur.equals(TypeCompteur.KM_H)) {
        lastBon = bonEnginRepo.findLastBonEnginKm_toConsommation(bonEngin.getEngin());
        lastBon2 = bonEnginRepo.findLastBonEnginH_toConsommation(bonEngin.getEngin());
        for (BonEngin b : bonEnginRepo.findAllBetweenLastBonAndCurrentBon_Km(lastBon.getCompteurAbsoluKm())) som_Q += b.getQuantite();
        for (BonEngin b : bonEnginRepo.findAllBetweenLastBonAndCurrentBon_H(lastBon2.getCompteurAbsoluH())) som_Q_2 += b.getQuantite();
        bonEngin.setConsommationKm((float) som_Q * 100 / (bonEngin.getCompteurAbsoluKm() - lastBon.getCompteurAbsoluKm()));
        bonEngin.setConsommationH((float) som_Q_2 / (bonEngin.getCompteurAbsoluH() - lastBon.getCompteurAbsoluH()));
        if (bonEngin.getConsommationKm() > bonEngin.getEngin().getSousFamille().getConsommationKmMax())
            insertAlerte(bonEngin, "La consommation Km est Annormale", TypeAlerte.CONSOMMATION_KM_ANNORMALE);
        if (bonEngin.getConsommationH() > bonEngin.getEngin().getSousFamille().getConsommationHMax())
            insertAlerte(bonEngin, "La consommation H est Annormale", TypeAlerte.CONSOMMATION_H_ANNORMALE);
    }
    return bonEngin;
}
Also used : TypeCompteur(me.kadarh.mecaworks.domain.others.TypeCompteur) BonEngin(me.kadarh.mecaworks.domain.bons.BonEngin)

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