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);
}
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);
}
}
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);
}
}
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);
}
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;
}
Aggregations