Commit 9244f6ae authored by Laurent Lecluse's avatar Laurent Lecluse
Browse files

#42080

parent e912f80f
Loading
Loading
Loading
Loading
+1
Changes for CHANGELOG.md: 1 added line, 0 removed lines.
Original line number Diff line number Diff line
@@ -87,6 +87,7 @@ Objectif : Plafonds personnalisables & refonte gestion des statuts
* Correction sur un problème de route dans l'écran Engagements & Liquidation (#38763)
* Export CSV des agréments : inversion de colonnes (#41513)
* Correction sur la suppression de service lorsque la clôture de service a été historisé (#42046)
* Le calcul des choix minimum/maximum est de nouveau fiable (#42080)

## Notes de mise à jour

+3 −2
Changes for admin/actul/actions/synchronisation.php: 3 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -29,8 +29,9 @@ $c->end('Synchronisation terminée');


$c->begin('Mise à jour des caches de données');
$c->print('Vue matérialisée TBL_NOEUD ... ');
$ca->ose->exec('BEGIN UNICAEN_IMPORT.REFRESH_MV(\'TBL_NOEUD\'); END;');
$c->print('Vues matérialisées pour les charges d\'enseignement ... ');
$ca->ose->exec('BEGIN OSE_CHARGENS.MAJ_CACHE; END;');

$c->println('OK');

$oa->run('chargens-calcul-effectifs', true);
+28 −60
Changes for data/ddl/package/OSE_CHARGENS/body.sql: 28 added lines, 60 removed lines.
Original line number Diff line number Diff line
CREATE OR REPLACE PACKAGE BODY "OSE_CHARGENS" AS

  PROCEDURE MAJ_CACHE IS
  BEGIN
    UNICAEN_IMPORT.REFRESH_MV('TBL_NOEUD');
    UNICAEN_IMPORT.REFRESH_MV('MV_LIEN');
    UNICAEN_TBL.CALCULER('chargens');
  END;


  FUNCTION CALC_COEF( choix_min NUMERIC, choix_max NUMERIC, poids NUMERIC, max_poids NUMERIC, total_poids NUMERIC, nb_choix NUMERIC ) RETURN FLOAT IS
    cmin NUMERIC;
    cmax NUMERIC;
@@ -36,7 +44,7 @@ CREATE OR REPLACE PACKAGE BODY "OSE_CHARGENS" AS
        res := coef_choix * nb_choix * (coef_poids + (((1/nb_choix)-coef_poids)*correcteur));
      END IF;

      --ose_test.echo('choix_min= ' || cmin || ', choix_max= ' || cmax || ', poids = ' || poids || ', max_poids = ' || max_poids || ', total_poids = ' || total_poids || ', nb_choix = ' || nb_choix || ', RES = ' || res);
      ose_test.echo('choix_min= ' || cmin || ', choix_max= ' || cmax || ', poids = ' || poids || ', max_poids = ' || max_poids || ', total_poids = ' || total_poids || ', nb_choix = ' || nb_choix || ', RES = ' || res);
      RETURN res;
  END;

@@ -61,75 +69,51 @@ CREATE OR REPLACE PACKAGE BODY "OSE_CHARGENS" AS
    ;

    FOR p IN (
      SELECT * FROM (
        SELECT
        ninf.id                     noeud_id,
          l.noeud_inf_id              noeud_id,
          snsup.scenario_id           scenario_id,
          sninf.id                    scenario_noeud_id,
          sne.type_heures_id          type_heures_id,
          sne.etape_id                etape_id,
          sne.effectif                effectif,
          slsup.choix_minimum         choix_minimum,
          slsup.choix_maximum         choix_maximum,
          COALESCE(slinf.poids,1)     poids,
        MAX(COALESCE(slinf.poids,1))   max_poids,
        SUM(COALESCE(slinf.poids,1))   total_poids,
        COUNT(*)                    nb_choix,
        sne.effectif                effectif
          MAX(COALESCE(slinf.poids,1)) OVER (PARTITION BY l.noeud_liste_id, snsup.scenario_id, sne.type_heures_id, sne.etape_id) max_poids,
          SUM(COALESCE(slinf.poids,1)) OVER (PARTITION BY l.noeud_liste_id, snsup.scenario_id, sne.type_heures_id, sne.etape_id) total_poids,
          COUNT(*)                     OVER (PARTITION BY l.noeud_liste_id, snsup.scenario_id, sne.type_heures_id, sne.etape_id) nb_choix
        FROM
                  noeud                nsup

             JOIN lien                 lsup   ON lsup.noeud_sup_id = nsup.id
                                             AND lsup.histo_destruction IS NULL
                    mv_lien                lrem
               JOIN mv_lien                   l ON l.noeud_sup_id = lrem.noeud_sup_id

             JOIN noeud                  nl   ON nl.liste = 1
                                             AND nl.histo_destruction IS NULL
                                             AND nl.id = lsup.noeud_inf_id

             JOIN lien                 linf   ON linf.noeud_sup_id = nl.id
                                             AND linf.histo_destruction IS NULL

             JOIN noeud                ninf   ON ninf.id = linf.noeud_inf_id
                                             AND ninf.histo_destruction IS NULL
                                             AND ninf.liste = 0

             JOIN scenario_noeud        snsup ON snsup.noeud_id = nsup.id
               JOIN scenario_noeud        snsup ON snsup.noeud_id = l.noeud_sup_id
                                               AND snsup.histo_destruction IS NULL

               JOIN scenario_noeud_effectif sne ON sne.scenario_noeud_id = snsup.id

          LEFT JOIN scenario_lien         slsup ON slsup.histo_destruction IS NULL
                                             AND slsup.lien_id = lsup.id
                                               AND slsup.lien_id = l.lien_sup_id
                                               AND slsup.scenario_id = snsup.scenario_id

          LEFT JOIN scenario_lien         slinf ON slinf.histo_destruction IS NULL
                                             AND slinf.lien_id = linf.id
                                               AND slinf.lien_id = l.lien_inf_id
                                               AND slinf.scenario_id = snsup.scenario_id

        LEFT JOIN scenario_noeud        sninf ON sninf.noeud_id = ninf.id
          LEFT JOIN scenario_noeud        sninf ON sninf.noeud_id = l.noeud_inf_id
                                               AND sninf.scenario_id = snsup.scenario_id
                                               AND sninf.histo_destruction IS NULL

        WHERE
        nsup.histo_destruction IS NULL
        AND nsup.liste = 0
          lrem.noeud_inf_id = CALC_EFFECTIF.noeud_id
          AND (slsup.actif = 1 OR slsup.actif IS NULL)
          AND (slinf.actif = 1 OR slinf.actif IS NULL)
        AND ninf.id = CALC_EFFECTIF.noeud_id
        --AND ninf.id = 389005
          AND snsup.scenario_id = CALC_EFFECTIF.scenario_id
          AND sne.type_heures_id = CALC_EFFECTIF.type_heures_id
          AND sne.etape_id = CALC_EFFECTIF.etape_id
      GROUP BY
        nsup.id,
        ninf.id,
        snsup.scenario_id,
        sninf.id,
        sne.type_heures_id,
        sne.etape_id,
        sne.effectif,
        slsup.choix_minimum,
        slsup.choix_maximum,
        slinf.poids

      ) WHERE noeud_id = CALC_EFFECTIF.noeud_id
    ) LOOP
      ose_test.echo('Calcul pour le noeud ' || p.noeud_id);
      effectif := OSE_CHARGENS.CALC_COEF(
          p.choix_minimum,
          p.choix_maximum,
@@ -154,27 +138,11 @@ CREATE OR REPLACE PACKAGE BODY "OSE_CHARGENS" AS
  BEGIN
    FOR p IN (
      SELECT
        ninf.id noeud_inf_id
        l.noeud_inf_id
      FROM
             noeud            nsup

        JOIN lien             lsup   ON lsup.noeud_sup_id = nsup.id
                                    AND lsup.histo_destruction IS NULL

        JOIN noeud              nl   ON nl.liste = 1
                                    AND nl.histo_destruction IS NULL
                                    AND nl.id = lsup.noeud_inf_id

        JOIN lien             linf   ON linf.noeud_sup_id = nl.id
                                    AND linf.histo_destruction IS NULL

        JOIN noeud            ninf   ON ninf.id = linf.noeud_inf_id
                                    AND ninf.histo_destruction IS NULL
                                    AND ninf.liste = 0
        mv_lien l
      WHERE
        nsup.histo_destruction IS NULL
        AND nsup.liste = 0
        AND nsup.id = CALC_SUB_EFFECTIF.noeud_id
        l.noeud_sup_id = CALC_SUB_EFFECTIF.noeud_id
    ) LOOP
      CALC_EFFECTIF( p.noeud_inf_id, scenario_id, type_heures_id, etape_id );
    END LOOP;
+2
Changes for data/ddl/package/OSE_CHARGENS/definition.sql: 2 added lines, 0 removed lines.
Original line number Diff line number Diff line
CREATE OR REPLACE PACKAGE "OSE_CHARGENS" AS

  PROCEDURE MAJ_CACHE;

  PROCEDURE CALC_EFFECTIF( noeud_id NUMERIC, scenario_id NUMERIC, type_heures_id NUMERIC, etape_id NUMERIC);
  PROCEDURE CALC_SUB_EFFECTIF( noeud_id NUMERIC, scenario_id NUMERIC, type_heures_id NUMERIC, etape_id NUMERIC);

+1 −2
Changes for doc/Connecteurs-Import/Connecteurs-IMPORT.md: 1 added line, 2 removed lines.
Original line number Diff line number Diff line
@@ -796,6 +796,5 @@ UNICAEN_IMPORT.REFRESH_MV('MV_INTERVENANT');
- Table NOEUD : mise à jour de tableaux de bord après la synchro :

```sql
UNICAEN_IMPORT.REFRESH_MV('TBL_NOEUD');
UNICAEN_TBL.CALCULER('chargens');
OSE_CHARGENS.MAJ_CACHE;
```
 No newline at end of file