Search in sources :

Example 1 with TypeCompteur

use of me.kadarh.mecaworks.domain.others.TypeCompteur 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 2 with TypeCompteur

use of me.kadarh.mecaworks.domain.others.TypeCompteur 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)

Example 3 with TypeCompteur

use of me.kadarh.mecaworks.domain.others.TypeCompteur in project mecaworks by KadarH.

the class MiseAjourBonsServiceImpl method bonEnginsToUpdate.

private List<BonEngin> bonEnginsToUpdate(BonEngin bonEngin) {
    log.info("Get List of bons to update :");
    List<BonEngin> bonEngins = new ArrayList<>();
    BonEngin lastBonPlein;
    TypeCompteur typeCompteur = bonEngin.getEngin().getSousFamille().getTypeCompteur();
    if (typeCompteur.equals(TypeCompteur.H)) {
        lastBonPlein = bonEnginRepo.findLastBonEnginH_toConsommation(bonEngin.getEngin().getId(), bonEngin.getDate());
        if (lastBonPlein != null)
            bonEngins = bonEnginRepo.findListBonEnginH_toConsommation(bonEngin.getEngin().getId(), lastBonPlein.getCompteurAbsoluH());
    } else if (typeCompteur.equals(TypeCompteur.KM)) {
        lastBonPlein = bonEnginRepo.findLastBonEnginKm_toConsommation(bonEngin.getEngin().getId(), bonEngin.getDate());
        bonEngins = bonEnginRepo.findListBonEnginKm_toConsommation(bonEngin.getEngin().getId(), lastBonPlein.getCompteurAbsoluKm());
    } else if (typeCompteur.equals(TypeCompteur.KM_H)) {
        lastBonPlein = bonEnginRepo.findLastBonEnginH_toConsommation(bonEngin.getEngin().getId(), bonEngin.getDate());
        bonEngins = bonEnginRepo.findListBonEnginH_toConsommation(bonEngin.getEngin().getId(), lastBonPlein.getCompteurAbsoluH());
        lastBonPlein = bonEnginRepo.findLastBonEnginKm_toConsommation(bonEngin.getEngin().getId(), bonEngin.getDate());
        bonEngins.addAll(bonEnginRepo.findListBonEnginKm_toConsommation(bonEngin.getEngin().getId(), lastBonPlein.getCompteurAbsoluH()));
    }
    log.info("List bons to update :" + bonEngins.size());
    return bonEngins;
}
Also used : TypeCompteur(me.kadarh.mecaworks.domain.others.TypeCompteur) BonEngin(me.kadarh.mecaworks.domain.bons.BonEngin) ArrayList(java.util.ArrayList)

Aggregations

BonEngin (me.kadarh.mecaworks.domain.bons.BonEngin)3 TypeCompteur (me.kadarh.mecaworks.domain.others.TypeCompteur)3 ArrayList (java.util.ArrayList)2