Search in sources :

Example 1 with ChantierBatch

use of me.kadarh.mecaworks.domain.user.ChantierBatch in project mecaworks by KadarH.

the class DashbordServiceImpl method getDashbordFromBatch.

private Dashbord getDashbordFromBatch(int mois, int year) {
    log.info("calling method getDashbordFromBatch() in DashbordServiceImpl -- ");
    log.info("--> Add data for 12 last month [ one year ago ] ");
    List<Quantite> quantites = new ArrayList<>();
    List<ChantierBatch> chantierBatches;
    LocalDate d = LocalDate.of(year, mois, 1);
    for (int i = 12, month, yeaar; i >= 1; i--) {
        month = d.minusMonths(i).getMonthValue();
        yeaar = d.minusMonths(i).getYear();
        chantierBatches = chantierBatchRepo.findAllByMoisAndAnnee(month, yeaar);
        quantites.add(new Quantite(month + "/" + yeaar, chantierBatches.stream().mapToLong(ChantierBatch::getQuantite).sum(), chantierBatches.stream().mapToLong(ChantierBatch::getQuantiteLocation).sum(), chantierBatches.stream().mapToLong(ChantierBatch::getChargeLocataire).sum(), chantierBatches.stream().mapToLong(ChantierBatch::getChargeLocataireExterne).sum(), 8.5f, chantierBatches.stream().mapToLong(ChantierBatch::getConsommationPrevue).sum(), chantierBatches.stream().mapToLong(ChantierBatch::getGazoilAchete).sum(), chantierBatches.stream().mapToLong(ChantierBatch::getGazoilFlotant).sum()));
    }
    Dashbord dashbord = new Dashbord();
    dashbord.setQuantites(quantites);
    return dashbord;
}
Also used : Dashbord(me.kadarh.mecaworks.domain.user.Dashbord) ChantierBatch(me.kadarh.mecaworks.domain.user.ChantierBatch) Quantite(me.kadarh.mecaworks.domain.user.Quantite) ArrayList(java.util.ArrayList) LocalDate(java.time.LocalDate)

Example 2 with ChantierBatch

use of me.kadarh.mecaworks.domain.user.ChantierBatch in project mecaworks by KadarH.

the class BatchFaker method insertBatchChantier.

public void insertBatchChantier() {
    log.info("Preparing to insert fake data ( chantier_batch ) ...");
    ChantierBatch chantierBatch;
    for (Chantier c : chantierService.getList()) {
        for (int i = 1; i < 7; i++) {
            chantierBatch = new ChantierBatch(i, 2018, i == 1 || i == 3 || i == 5 ? 800000 + 100L * i : 550000 + 2510 / i + 1000L * i, i == 2 || i == 3 || i == 5 ? 550000 + 1000L * i : 250000 + 1000L * i, i == 1 || i == 4 || i == 5 ? 500000 + 210000 + 10000L * i : 500000 + 350000 + 10000L * i, i == 1 || i == 3 || i == 5 ? 400000 + 210000 + 10000L * i : 400000 + 90000 + 10000L * i, i == 2 || i == 1 || i == 6 ? 900000 + 1L : 400000 + 10000 + 1L, 8f, i == 2 || i == 1 ? 759800 + 10L * i : 650700 + 10000 + 10L * i, i == 2 || i == 1 ? 80000 + 9000 + 1L : 50000 + 2000 + 1L, c);
            chantierBatchRepo.save(chantierBatch);
        }
        for (int i = 7; i <= 12; i++) {
            chantierBatch = new ChantierBatch(i, 2017, i == 7 || i == 9 ? 700000 + 100L * i : 450000 + 2510 / i + 100L * i, i == 9 || i == 8 || i == 11 || i == 10 || i == 12 ? 350000 + 1000L * i : 550000 + 1000L * i, i == 8 || i == 10 || i == 11 ? 500000 + 210000 + 1L : 500000 + 350000 + 1L, i == 7 || i == 8 || i == 12 ? 300000 + 210000 + 1L : 400000 + 90000 + 1L, i == 7 || i == 9 ? 900000 + 1L : 400000 + 10000 + 1L, 8.5f, i == 7 || i == 8 ? 759800 + 10L * i : 650700 + 10000 + 10L * i, i == 9 || i == 8 || i == 11 ? 100000 + 9000 + 100L * i : 150000 + 9000 + 100L * i, c);
            chantierBatchRepo.save(chantierBatch);
        }
    }
    log.info("Chantier_batch inserted");
}
Also used : ChantierBatch(me.kadarh.mecaworks.domain.user.ChantierBatch) Chantier(me.kadarh.mecaworks.domain.others.Chantier)

Example 3 with ChantierBatch

use of me.kadarh.mecaworks.domain.user.ChantierBatch in project mecaworks by KadarH.

the class BatchHelper method updateBatcheLastMonth.

public List<ChantierBatch> updateBatcheLastMonth() {
    log.info("Calling method updateBatcheLastMonth() in BatchHelper ");
    int mois = LocalDate.now().getMonth().getValue() - 1;
    int year = LocalDate.now().getYear();
    List<ChantierBatch> chantierBatches = userCalculService.getListChantierWithQuantities(mois, year);
    for (ChantierBatch c : chantierBatches) {
        ChantierBatch old = chantierBatchRepo.findByMoisAndAnneeAndChantier(mois, year, c.getChantier()).get();
        if (c.getQuantite() != null && c.getQuantite().equals(old.getQuantite()))
            old.setQuantite(c.getQuantite());
        if (c.getQuantiteLocation() != null && c.getQuantiteLocation().equals(old.getQuantiteLocation()))
            old.setQuantiteLocation(c.getQuantiteLocation());
        if (c.getChargeLocataire() != null && c.getChargeLocataire().equals(old.getChargeLocataire()))
            old.setChargeLocataire(c.getChargeLocataire());
        if (c.getChargeLocataireExterne() != null && c.getChargeLocataireExterne().equals(old.getChargeLocataireExterne()))
            old.setChargeLocataireExterne(c.getChargeLocataireExterne());
        if (c.getConsommationPrevue() != null && c.getConsommationPrevue().equals(old.getConsommationPrevue()))
            old.setConsommationPrevue(c.getConsommationPrevue());
        chantierBatches.set(chantierBatches.indexOf(c), old);
    }
    return chantierBatches;
}
Also used : ChantierBatch(me.kadarh.mecaworks.domain.user.ChantierBatch)

Example 4 with ChantierBatch

use of me.kadarh.mecaworks.domain.user.ChantierBatch in project mecaworks by KadarH.

the class UserCalculService method getListChantierWithQuantities.

public List<ChantierBatch> getListChantierWithQuantities(int month, int year) {
    log.info("calling method getListChantierWithQuantities(month,year) in UserCalculService -- ");
    try {
        List<ChantierBatch> list = new ArrayList<>();
        ChantierBatch chantierBatch;
        LocalDate from = LocalDate.of(year, Month.of(month).getValue(), 1);
        LocalDate to = LocalDate.of(year + 1, Month.of(month).plus(1).getValue(), 1);
        List<BonEngin> bonEngins = bonEnginRepo.findAllBetweenDates(from, to);
        List<BonLivraison> bonLivraisons = bonLivraisonRepo.findAllBetweenDates(from, to);
        List<BonFournisseur> bonFournisseurs = bonFournisseurRepo.findAllBetweenDates(from, to);
        Map<Chantier, Long> sum = bonEngins.stream().collect(Collectors.groupingBy(BonEngin::getChantierTravail, Collectors.summingLong(BonEngin::getQuantite)));
        Map<Chantier, Long> sum2 = bonEngins.stream().filter(bonEngin -> bonEngin.getEngin().getGroupe().getLocataire() && bonEngin.getId() != null).collect(Collectors.groupingBy(BonEngin::getChantierTravail, Collectors.summingLong(BonEngin::getQuantite)));
        Map<Chantier, Long> chargeLocataire = bonEngins.stream().collect(Collectors.groupingBy(BonEngin::getChantierTravail, Collectors.summingLong(BonEngin::getChargeHoraire)));
        Map<Chantier, Long> chargeLocataireExterne = bonEngins.stream().filter(bonEngin -> bonEngin.getEngin().getGroupe().getLocataire()).collect(Collectors.groupingBy(BonEngin::getChantierTravail, Collectors.summingLong(BonEngin::getChargeHoraire)));
        Map<Chantier, Long> consommationPrevue = bonEngins.stream().collect(Collectors.groupingBy(BonEngin::getChantierTravail, Collectors.summingLong(BonEngin::getConsommationPrevu)));
        Map<Chantier, Double> prix = bonFournisseurs.stream().collect(Collectors.groupingBy(BonFournisseur::getChantier, Collectors.averagingDouble(BonFournisseur::getPrixUnitaire)));
        Map<Chantier, Long> quantiteAchetee = bonFournisseurs.stream().collect(Collectors.groupingBy(BonFournisseur::getChantier, Collectors.summingLong(BonFournisseur::getQuantite)));
        Map<Chantier, Long> quantiteFlotante = bonLivraisons.stream().collect(Collectors.groupingBy(BonLivraison::getChantierDepart, Collectors.summingLong(BonLivraison::getQuantite)));
        for (Map.Entry<Chantier, Long> entry : sum.entrySet()) {
            if (entry != null) {
                // Fix in 0 if null
                Long quantite = entry.getValue();
                Long quantiteL = sum2.get(entry.getKey()) == null ? 0L : sum2.get(entry.getKey());
                Long cl = chargeLocataire.get(entry.getKey()) == null ? 0L : chargeLocataire.get(entry.getKey());
                Long clex = chargeLocataireExterne.get(entry.getKey()) == null ? 0L : chargeLocataireExterne.get(entry.getKey());
                Long cp = consommationPrevue.get(entry.getKey()) == null ? 0L : consommationPrevue.get(entry.getKey());
                Long qa = quantiteAchetee.get(entry.getKey()) == null ? 0L : quantiteAchetee.get(entry.getKey());
                Long qf = quantiteFlotante.get(entry.getKey()) == null ? 0L : quantiteFlotante.get(entry.getKey());
                Float p = prix.get(entry.getKey()) == null ? 0f : prix.get(entry.getKey()).floatValue();
                chantierBatch = new ChantierBatch(month, year, quantite, quantiteL, cl, clex, cp, p, qa, qf, entry.getKey());
                if (chantierBatch.getQuantiteLocation() == null)
                    chantierBatch.setQuantiteLocation(0L);
                if (chantierBatch.getQuantite() == null)
                    chantierBatch.setQuantite(0L);
                if (chantierBatch.getChargeLocataireExterne() == null)
                    chantierBatch.setChargeLocataireExterne(0L);
                if (chantierBatch.getChargeLocataire() == null)
                    chantierBatch.setChargeLocataire(0L);
                if (chantierBatch.getConsommationPrevue() == null)
                    chantierBatch.setConsommationPrevue(0L);
                if (chantierBatch.getGazoilAchete() == null)
                    chantierBatch.setGazoilAchete(0L);
                if (chantierBatch.getGazoilFlotant() == null)
                    chantierBatch.setGazoilFlotant(0L);
                list.add(chantierBatch);
            }
        }
        log.info("--> List of Chantier_Batch contains " + list.size() + " elements");
        return list;
    } catch (NoSuchElementException e) {
        log.info("Operation failed : No element in ChantierBatch table -- ");
        throw new ResourceNotFoundException("Opération echouée, Il n'y a aucun element pour les mois precedents", e);
    } catch (Exception e) {
        log.info("Operation failed -- ");
        throw new OperationFailedException("Opération echouée, problème de la base", e);
    }
}
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) OperationFailedException(me.kadarh.mecaworks.service.exceptions.OperationFailedException) LocalDate(java.time.LocalDate) ResourceNotFoundException(me.kadarh.mecaworks.service.exceptions.ResourceNotFoundException) OperationFailedException(me.kadarh.mecaworks.service.exceptions.OperationFailedException) ChantierBatch(me.kadarh.mecaworks.domain.user.ChantierBatch) BonLivraison(me.kadarh.mecaworks.domain.bons.BonLivraison) BonEngin(me.kadarh.mecaworks.domain.bons.BonEngin) Chantier(me.kadarh.mecaworks.domain.others.Chantier) ResourceNotFoundException(me.kadarh.mecaworks.service.exceptions.ResourceNotFoundException)

Aggregations

ChantierBatch (me.kadarh.mecaworks.domain.user.ChantierBatch)4 LocalDate (java.time.LocalDate)2 Chantier (me.kadarh.mecaworks.domain.others.Chantier)2 Quantite (me.kadarh.mecaworks.domain.user.Quantite)2 Month (java.time.Month)1 ChronoUnit (java.time.temporal.ChronoUnit)1 java.util (java.util)1 ArrayList (java.util.ArrayList)1 Collectors (java.util.stream.Collectors)1 Slf4j (lombok.extern.slf4j.Slf4j)1 BonEngin (me.kadarh.mecaworks.domain.bons.BonEngin)1 BonFournisseur (me.kadarh.mecaworks.domain.bons.BonFournisseur)1 BonLivraison (me.kadarh.mecaworks.domain.bons.BonLivraison)1 Engin (me.kadarh.mecaworks.domain.others.Engin)1 Stock (me.kadarh.mecaworks.domain.others.Stock)1 Dashbord (me.kadarh.mecaworks.domain.user.Dashbord)1 BonEnginRepo (me.kadarh.mecaworks.repo.bons.BonEnginRepo)1 BonFournisseurRepo (me.kadarh.mecaworks.repo.bons.BonFournisseurRepo)1 BonLivraisonRepo (me.kadarh.mecaworks.repo.bons.BonLivraisonRepo)1 StockRepo (me.kadarh.mecaworks.repo.others.StockRepo)1