Pastebin
Retrouvez, créez et partagez vos snippets en temps réel.
Rechercher un Pastebin
Aucun paste trouvé.
Créer un paste
Pastebin
Blog
dd
public class EtatIndividuelRecuperationsDHeuresService { private final EditiqueService editiqueService; private final EditiqueFeignClient editiqueClient; private final EtatIndividuelRecuperationDHeuresSierhService etatIndividuelRecuperationDHeuresSierhService; private static final String COULEUR_FOND_SEMAINE = "#dbe8f7"; public EtatIndividuelRecuperationsDHeuresService(EditiqueService editiqueService, EditiqueFeignClient editiqueClient, EtatIndividuelRecuperationDHeuresSierhService etatIndividuelRecuperationDHeuresSierhService) { this.editiqueService = editiqueService; this.editiqueClient = editiqueClient; this.etatIndividuelRecuperationDHeuresSierhService = etatIndividuelRecuperationDHeuresSierhService; } public byte[] genererEtatIndividuelRecuperationsDHeuresService(IdentifiantCompletAgentSI identifiantCompletAgentSI, String semaineDebut, String semaineFin) throws IOException { List < LigneRSInformationSemaineRemplacantSIERH > listEtatIndividuelRecuperationsDHeuresService = this.etatIndividuelRecuperationDHeuresSierhService.recupererInformationSemaines( identifiantCompletAgentSI, this.extraireDateDebut(semaineDebut), this.extraireDateFin(semaineFin)); Tableau tableauRemplacant = this.creerSectionRecuperationsDHeures(listEtatIndividuelRecuperationsDHeuresService, semaineDebut, semaineFin); ModeleDocument modele = ModeleDocument.extraireModeleDocument( FichierUtil.recupererFichierDepuisClasspath("modeles/modele_etat_individuel_recap_heures.docx")); GenerateurDocument generateurDocument = GenerateurDocument.builder().editiqueClient(editiqueClient).modele(modele) .build(); String libelleAcademie = "Académie de LILLE"; String libelleDSDEN = "Direction des services départementaux de l'éducation nationale du Nord"; String libelleCirconscription = "0595716T - Circonscription d'inspection du 1er degré de Lille 1 Lille 3 - ASH - Lille"; String libelleEtablissement = "0590174U - Institut de Réhabilitation de la Parole et de l'Audition (I.R.P.A.) de Ronchin - Ronchin"; String libelleZoneRemplacement = "0590174U - Institut de Réhabilitation de la Parole et de l'Audition (I.R.P.A.) de Ronchin - Ronchin"; String nomPrenom = "KRIKORIAN MARION"; generateurDocument.ajouterTexte("academieEtDSDEN", "Académie de " + libelleAcademie + "\n" + libelleDSDEN) .ajouterTexte("circonscription", libelleCirconscription).ajouterTexte("nomEtPrenom", nomPrenom) .ajouterTexte("ecoleDeRattachement", libelleEtablissement).ajouterTexte("zoneRemplacement", libelleZoneRemplacement) .ajouterTexte("titreRecap", "Etat individuel : Récapitulatif des heures") .ajouterTableau("tableauRecap", tableauRemplacant); return this.editiqueService.genererDocument(generateurDocument); } private Tableau creerSectionRecuperationsDHeures( List < LigneRSInformationSemaineRemplacantSIERH > listEtatIndividuelRecuperationsDHeuresService, String semaineDebut, String semaineFin) throws IOException { Map < LocalDate, List < LigneRSInformationSemaineRemplacantSIERH > > donneesParJour = listEtatIndividuelRecuperationsDHeuresService.stream() .collect(Collectors.groupingBy(LigneRSInformationSemaineRemplacantSIERH::getJourdt)); WeekFields weekFields = WeekFields.ISO; DateTimeFormatter formatteurDate = DateTimeFormatter.ofPattern("dd/MM/yyyy"); DateTimeFormatter jourSemaineFormatter = DateTimeFormatter.ofPattern("EEEE", Locale.FRENCH); int anneeDebut = Integer.parseInt(semaineDebut.substring(0, 4)); int numeroSemaineDebut = Integer.parseInt(semaineDebut.substring(6)); int anneeFin = Integer.parseInt(semaineFin.substring(0, 4)); int numeroSemaineFin = Integer.parseInt(semaineFin.substring(6)); LocalDate debutSemaine = LocalDate.of(anneeDebut, 1, 1).with(weekFields.weekOfWeekBasedYear(), numeroSemaineDebut) .with(weekFields.dayOfWeek(), 1); LocalDate finSemaine = LocalDate.of(anneeFin, 1, 1).with(weekFields.weekOfWeekBasedYear(), numeroSemaineFin) .with(weekFields.dayOfWeek(), 7); Tableau.TableauBuilder tableauBuilder = Tableau.builder(8) // ---------- ENTÊTE ---------- .ligneEntete("Semaine", StringUtil.EMPTY, StringUtil.EMPTY, "Etablissement", "Enseignant remplacé", "Modalité", "Heures\neffectuées", "Heures\nrécupérées") .styleCellule(0, celluleStyle(6, true, Alignement.CENTRE,VAlignement.MILIEU, null)) // Semaine .styleCellule(1, CelluleStyle.builder().largeur(7).build()) // date (yyyy-mm--dd) .styleCellule(2, CelluleStyle.builder().largeur(2).build()) // AM OU PM .styleCellule(3, celluleStyle(42, true, Alignement.CENTRE,VAlignement.MILIEU, null)) // Etablissement .styleCellule(4, celluleStyle(20, true, Alignement.CENTRE,VAlignement.MILIEU, null)) // Enseignant remplacé .styleCellule(5, celluleStyle(5, true, Alignement.CENTRE,VAlignement.MILIEU, null)) // Modalité .styleCellule(6, celluleStyle(5, true, Alignement.CENTRE,VAlignement.MILIEU, null)) // Heures effectuées .styleCellule(7, celluleStyle(5, true, Alignement.CENTRE,VAlignement.MILIEU, null)) // Heures récupérées .fusion(0, 0, 0, 2); // ---------- LIGNE COMPTEUR GENERAL ---------- // .ligne("Compteur général au début de la période : 8h00", StringUtil.EMPTY, StringUtil.EMPTY, StringUtil.EMPTY, // StringUtil.EMPTY, StringUtil.EMPTY, StringUtil.EMPTY, StringUtil.EMPTY) // .styleCellule(0, celluleStyleEntete(9, true, Alignement.GAUCHE, null)).fusion(1, 1, 0, 7); int numeroLigne = 1; LocalDate dateCourante = debutSemaine; while (!dateCourante.isAfter(finSemaine)) { LocalDate debutSemaineCourante = dateCourante.with(weekFields.dayOfWeek(), 1); LocalDate finSemaineCourante = dateCourante.with(weekFields.dayOfWeek(), 7); if (finSemaineCourante.isAfter(finSemaine)) { finSemaineCourante = finSemaine; } int numeroSemaineCourante = debutSemaineCourante.get(weekFields.weekOfWeekBasedYear()); // ---------- LIGNE NUMERO SEMAINE ---------- tableauBuilder.ligne("Semaine " + numeroSemaineCourante, StringUtil.EMPTY, StringUtil.EMPTY, StringUtil.EMPTY, StringUtil.EMPTY, StringUtil.EMPTY, StringUtil.EMPTY, StringUtil.EMPTY) .styleCellule(0, celluleStyle(9, true, Alignement.GAUCHE,VAlignement.MILIEU, COULEUR_FOND_SEMAINE)); // Fusionner toutes les colonnes de la ligne "Semaine" tableauBuilder.fusion(numeroLigne, numeroLigne, 0, 7); numeroLigne++; int totalHeuresEffectuees = 0; int totalHeuresRecuperees = 0; // ---------- LIGNE PAR JOUR ---------- LocalDate jour = debutSemaineCourante; while (!jour.isAfter(finSemaineCourante)) { if (jour.getDayOfWeek() != DayOfWeek.SUNDAY) { List < LigneRSInformationSemaineRemplacantSIERH > lignes = donneesParJour.get(jour); String etabAM = ""; String remplaceAM = ""; String affichageHeuresEffectueesAM = ""; String affichageHeuresRecupereesAM = ""; String typeAffectationAM = ""; if (lignes != null) { LigneRSInformationSemaineRemplacantSIERH dataAM = trouverLignePrioritaire(lignes, true); int heuresEffectueesAM = 0; int heuresRecupereesAM = 0; if("Absence - Récupération dépassement ORS".equals(dataAM.getUaarne())){ heuresRecupereesAM = dataAM != null ? (dataAM.getJouram()) : 0; affichageHeuresRecupereesAM = dataAM != null && !dataAM.getRang().startsWith("3") ? convertirMinutesEnHeures(dataAM.getJouram()) : ""; }else { heuresEffectueesAM = dataAM != null ? (dataAM.getJouram()) : 0; affichageHeuresEffectueesAM = dataAM != null && !dataAM.getRang().startsWith("3") ? convertirMinutesEnHeures(dataAM.getJouram()) : ""; } totalHeuresEffectuees = calculTotalHeuresEffectueesOuRecuperees(totalHeuresEffectuees, heuresEffectueesAM, 0); totalHeuresRecuperees = calculTotalHeuresEffectueesOuRecuperees(totalHeuresRecuperees, heuresRecupereesAM, 0); etabAM = dataAM != null ? dataAM.getUaarne().trim() : ""; remplaceAM = dataAM != null ? (dataAM.getAinomu().trim() + " " + dataAM.getAipren().trim()).trim() : ""; typeAffectationAM = dataAM != null ? dataAM.getAfmico().trim() : ""; } String nomJour = jour.format(jourSemaineFormatter); nomJour = nomJour.substring(0, 1).toUpperCase() + nomJour.substring(1); tableauBuilder.ligne(nomJour, jour.format(formatteurDate), "AM", etabAM, remplaceAM, typeAffectationAM, affichageHeuresEffectueesAM, affichageHeuresRecupereesAM) .styleCellule(0, celluleStyle(6, false, Alignement.GAUCHE,VAlignement.BAS, null)) // Semaine .styleCellule(1, celluleStyle(7, false, Alignement.GAUCHE, VAlignement.BAS, null)) // date (yyyy-mm-dd) .styleCellule(2, celluleStyle(2, false, Alignement.GAUCHE,VAlignement.MILIEU, null)) // AM OU PM .styleCellule(3, celluleStyle(43, false, Alignement.GAUCHE,VAlignement.MILIEU, null)) // Etablissement .styleCellule(4, celluleStyle(20, false, Alignement.GAUCHE,VAlignement.MILIEU, null)) // Enseignant remplacé .styleCellule(5, celluleStyle(5, false, Alignement.GAUCHE, VAlignement.MILIEU,null)) // Modalité .styleCellule(6, celluleStyle(5, false, Alignement.GAUCHE,VAlignement.MILIEU, null)) // Heures effectuées .styleCellule(7, celluleStyle(5, false, Alignement.GAUCHE,VAlignement.MILIEU, null)); // Heures récupérées numeroLigne++; String etabPM = ""; String remplacePM = ""; String affichageHeuresEffectueesPM = ""; String affichageHeuresRecupereesPM = ""; String typeAffectationPM = ""; if (lignes != null) { LigneRSInformationSemaineRemplacantSIERH dataPM = trouverLignePrioritaire(lignes, false); int heuresEffectueesPM = 0; int heuresRecupereesPM = 0; if("Absence - Récupération dépassement ORS".equals(dataPM.getUaarne())){ heuresRecupereesPM = dataPM != null ? (dataPM.getJouram()) : 0; affichageHeuresRecupereesPM = dataPM != null && !dataPM.getRang().startsWith("3") ? convertirMinutesEnHeures(dataPM.getJouram()) : ""; }else { heuresEffectueesPM = dataPM != null ? (dataPM.getJouram()) : 0; affichageHeuresEffectueesPM = dataPM != null && !dataPM.getRang().startsWith("3") ? convertirMinutesEnHeures(dataPM.getJouram()) : ""; } totalHeuresEffectuees = calculTotalHeuresEffectueesOuRecuperees(totalHeuresEffectuees, 0, heuresEffectueesPM); totalHeuresRecuperees = calculTotalHeuresEffectueesOuRecuperees(totalHeuresRecuperees, 0, heuresRecupereesPM); etabPM = dataPM != null ? dataPM.getUaarne().trim() : ""; remplacePM = dataPM != null ? (dataPM.getAinomu().trim() + " " + dataPM.getAipren().trim()).trim() : ""; typeAffectationPM = dataPM != null ? dataPM.getAfmico().trim() : ""; } // ---------- LIGNE PM ---------- tableauBuilder.ligne("", "", "PM", etabPM, remplacePM, typeAffectationPM, affichageHeuresEffectueesPM, affichageHeuresRecupereesPM) .styleCellule(0, celluleStyle(6, false, Alignement.GAUCHE,VAlignement.BAS, null)) // Semaine .styleCellule(1, celluleStyle(7, false, Alignement.GAUCHE,VAlignement.BAS, null)) // date (yyyy-mm-dd) .styleCellule(2, celluleStyle(2, false, Alignement.GAUCHE,VAlignement.MILIEU, null)) // AM OU PM .styleCellule(3, celluleStyle(43, false, Alignement.GAUCHE,VAlignement.MILIEU, null)) // Etablissement .styleCellule(4, celluleStyle(20, false, Alignement.GAUCHE,VAlignement.MILIEU, null)) // Enseignant remplacé .styleCellule(5, celluleStyle(5, false, Alignement.GAUCHE,VAlignement.MILIEU, null)) // Modalité .styleCellule(6, celluleStyle(5, false, Alignement.GAUCHE,VAlignement.MILIEU, null)) // Heures effectuées .styleCellule(7, celluleStyle(5, false, Alignement.GAUCHE,VAlignement.MILIEU, null)) // Heures récupérées .fusion(numeroLigne-1 ,numeroLigne, 0, 0) .fusion(numeroLigne-1 ,numeroLigne, 1, 1) ; numeroLigne++; } jour = jour.plusDays(1); } // ---------- LIGNE TOTAL SEMAINE ---------- tableauBuilder.ligne("Total Semaine " + numeroSemaineCourante, StringUtil.EMPTY, StringUtil.EMPTY, StringUtil.EMPTY, StringUtil.EMPTY, StringUtil.EMPTY, this.convertirMinutesEnHeures(totalHeuresEffectuees), this.convertirMinutesEnHeures(totalHeuresRecuperees)) .styleCellule(0, celluleStyle(9, true, Alignement.GAUCHE,VAlignement.MILIEU, null)) .styleCellule(6, celluleStyle(5, true, Alignement.CENTRE,VAlignement.MILIEU, null)) .styleCellule(7, celluleStyle(5, true, Alignement.CENTRE,VAlignement.MILIEU, null)); // Fusionner toutes les colonnes de la ligne "Total Semaine" tableauBuilder.fusion(numeroLigne, numeroLigne, 0, 5); numeroLigne++; // ---------- LIGNE RESUME ---------- tableauBuilder.ligne("Résumé de la semaine " + numeroSemaineCourante + " : 0h00 en dépassement .....", StringUtil.EMPTY, StringUtil.EMPTY, StringUtil.EMPTY, StringUtil.EMPTY, StringUtil.EMPTY, StringUtil.EMPTY, StringUtil.EMPTY).styleCellule(0, celluleStyle(9, true, Alignement.GAUCHE,VAlignement.MILIEU, null)) .styleCellule(6, celluleStyle(5, true, Alignement.CENTRE,VAlignement.MILIEU, null)) .styleCellule(7, celluleStyle(5, true, Alignement.CENTRE, VAlignement.MILIEU,null)); // Fusionner toutes les colonnes de la ligne "Total Semaine" tableauBuilder.fusion(numeroLigne, numeroLigne, 0, 7); numeroLigne++; dateCourante = finSemaineCourante.plusDays(1); } return tableauBuilder.build(); } private LigneRSInformationSemaineRemplacantSIERH trouverLignePrioritaire( List<LigneRSInformationSemaineRemplacantSIERH> lignes, boolean isAM ) { return lignes.stream().filter(d -> isAM ? d.getJouram() > 0 : d.getJourpm() > 0) .min((a, b) -> Integer.compare(verifierPriorite(a), verifierPriorite(b))) .orElse(null); } private int verifierPriorite(LigneRSInformationSemaineRemplacantSIERH d) { if ("1".equals(d.getRang())) return 1; if ("2".equals(d.getAfmico())) return 2; if ("3".equals(d.getAfmico())) return 3; if (d.getRang().startsWith("3")) return 4; return 99; } private CelluleStyle celluleStyle(int largeur, boolean gras, Alignement alignement, VAlignement vAlignement, String couleurFond) { return CelluleStyle.builder().gras(gras).alignement(alignement).alignementVertical(vAlignement).tailleTexte(7).largeur(largeur).couleurFond(couleurFond) .build(); } private LocalDate lundiDeSemaine(String isoWeek) { String[] parts = isoWeek.split("-W"); int year = Integer.parseInt(parts[0]); int week = Integer.parseInt(parts[1]); return LocalDate.now().withYear(year).with(java.time.temporal.IsoFields.WEEK_OF_WEEK_BASED_YEAR, week) .with(java.time.temporal.IsoFields.WEEK_BASED_YEAR, year).with(java.time.DayOfWeek.MONDAY); } private LocalDate extraireDateDebut(String semaines) { return Arrays.stream(semaines.split(",")).map(String::trim).map(this::lundiDeSemaine).min(LocalDate::compareTo) .orElseThrow(); } private LocalDate extraireDateFin(String semaines) { return Arrays.stream(semaines.split(",")).map(String::trim).map(this::lundiDeSemaine).map(d -> d.plusDays(6)) .max(LocalDate::compareTo).orElseThrow(); } private String convertirMinutesEnHeures(int minutes) { if (minutes <= 1) { return ""; } int heures = minutes / 60; int mins = minutes % 60; return String.format("%dh%02d", heures, mins); } private int calculTotalHeuresEffectueesOuRecuperees(int totalHeuresEffectuees, int heureEffectueeAM, int heureEffectueePM) { return totalHeuresEffectuees + (heureEffectueeAM > 1 ? heureEffectueeAM : 0) + (heureEffectueePM > 1 ? heureEffectueePM : 0); }
Créé il y a 1 mois.