Add order to sql, default is to sort old first

This commit is contained in:
Michael RICOIS 2014-09-17 06:25:36 +00:00
parent a8bc0db8d6
commit b6e2e8d651

View File

@ -119,16 +119,22 @@ $tabQueries = array(
/* Défaut divers Facto (D:Défaut, 24:Groupe en diff, 31:Cessation Annoncée, 50:Terrorisme)*/ /* Défaut divers Facto (D:Défaut, 24:Groupe en diff, 31:Cessation Annoncée, 50:Terrorisme)*/
'defaut' => "SELECT $strSelect, 'defaut' AS source FROM ".$tableSurvTmp."_defaut s, sdv1.ge_cs2 p WHERE p.siren>1000 AND s.siren = p.siren AND (p.dateInsert>=s.dateUpdate OR p.dateConf>=s.dateUpdate) AND p.cs IN ('D','24','31','50') /*AND s.procol NOT IN('P')*/ GROUP BY siren", 'defaut' => "SELECT $strSelect, 'defaut' AS source FROM ".$tableSurvTmp."_defaut s, sdv1.ge_cs2 p WHERE p.siren>1000 AND s.siren = p.siren AND (p.dateInsert>=s.dateUpdate OR p.dateConf>=s.dateUpdate) AND p.cs IN ('D','24','31','50') /*AND s.procol NOT IN('P')*/ GROUP BY siren",
/* RAS Facto */ /* RAS Facto */
'regulier' => "SELECT $strSelect, 'regulier' AS source FROM ".$tableSurvTmp."_regulier s, sdv1.ge_cs2 p WHERE p.siren>1000 AND s.siren = p.siren AND (p.dateInsert>=s.dateUpdate OR p.dateConf>=s.dateUpdate) AND p.cs='00' AND s.procol NOT IN('P') GROUP BY siren ORDER BY siren ASC LIMIT 100000", 'regulier' => "SELECT $strSelect, 'regulier' AS source FROM ".$tableSurvTmp."_regulier s, sdv1.ge_cs2 p WHERE p.siren>1000 AND s.siren = p.siren AND (p.dateInsert>=s.dateUpdate OR p.dateConf>=s.dateUpdate) AND p.cs='00' AND s.procol NOT IN('P') GROUP BY siren",
// Rajouter AND (DATEDIFF(NOW(),s.indiScoreDate)>365 // Rajouter AND (DATEDIFF(NOW(),s.indiScoreDate)>365
// et vérifier si ça en enlève en recalcul régulier // et vérifier si ça en enlève en recalcul régulier
/* Scores trop anciens */ /* Scores trop anciens */
'ancien' => "SELECT $strSelect, 'ancien' AS source FROM ".$tableSurvTmp."_ancien s WHERE s.siren>1000 AND (DATEDIFF(NOW(),s.indiScoreDate)>365 /*OR DATEDIFF(NOW(),s.indiScoreDate) IS NULL*/) AND s.procol NOT IN('P') AND s.dateUpdate<DATE(NOW()) GROUP BY siren ORDER BY siren DESC LIMIT 100000", 'ancien' => "SELECT $strSelect, 'ancien' AS source FROM ".$tableSurvTmp."_ancien s WHERE s.siren>1000 AND (DATEDIFF(NOW(),s.indiScoreDate)>365) AND s.procol NOT IN('P') AND s.dateUpdate<DATE(NOW()) GROUP BY siren",
/** @todo A revoir **/ /** @todo A revoir **/
/* Bilans déposés */ /* Bilans déposés */
//'bilans2'=>"SELECT s.siren, s.actif, s.procol, s.indiScore, s.indiScore20, s.encours, s.indiScoreDate, scoreSolv, scoreConf, scoreDir, scoreZ, scoreCH, scoreAfdcc1, scoreAfdcc2, scoreAfdcc2note, scoreAltman, scoreAltmanCote, scoreCCF, situFi, infoNote, noteStruct, noteFin, tendance, nbModifs, 'bilans2' as source, s.dateUpdate FROM scores_surveillance_tmp s, bilans_deposes b WHERE b.siren>1000 AND s.siren=b.siren AND b.dateInsert>s.dateUpdate AND s.procol NOT IN('P') GROUP BY siren", //'bilans2'=>"SELECT s.siren, s.actif, s.procol, s.indiScore, s.indiScore20, s.encours, s.indiScoreDate, scoreSolv, scoreConf, scoreDir, scoreZ, scoreCH, scoreAfdcc1, scoreAfdcc2, scoreAfdcc2note, scoreAltman, scoreAltmanCote, scoreCCF, situFi, infoNote, noteStruct, noteFin, tendance, nbModifs, 'bilans2' as source, s.dateUpdate FROM scores_surveillance_tmp s, bilans_deposes b WHERE b.siren>1000 AND s.siren=b.siren AND b.dateInsert>s.dateUpdate AND s.procol NOT IN('P') GROUP BY siren",
); );
$tabQueriesOrder = array(
'siren' => " ORDER BY siren ASC LIMIT 50000",
'old' => " ORDER BY s.dateUpdate ASC LIMIT 50000",
);
$queryOrder = 'old';
/** /**
* Liste des déclencheurs * Liste des déclencheurs
*/ */
@ -242,7 +248,7 @@ foreach ($tabQueries as $declencheur => $query)
echo date('Y/m/d - H:i:s') ." - Recherche par la source '$declencheur'...".PHP_EOL; echo date('Y/m/d - H:i:s') ." - Recherche par la source '$declencheur'...".PHP_EOL;
try { try {
$res = $db->fetchAll($query); $res = $db->fetchAll($query . $tabQueriesOrder[$queryOrder]);
} catch(Zend_Db_Exception $e) { } catch(Zend_Db_Exception $e) {
echo $e->getMessage() . PHP_EOL; echo $e->getMessage() . PHP_EOL;
exit; exit;
@ -296,6 +302,9 @@ foreach ($tabQueries as $declencheur => $query)
//Arrêt de l'execution à 18h30 pour le déclencheur tout //Arrêt de l'execution à 18h30 pour le déclencheur tout
if ( date('Hi')*1>=1830 && $opts->tout ) break; if ( date('Hi')*1>=1830 && $opts->tout ) break;
//Arrêt de l'execution à 23h45
if ( date('Hi')*1>=2345 ) break;
// Arret sur indicateur maximum // Arret sur indicateur maximum
if ( $opts->max && $iRow >= $opts->max) break; if ( $opts->max && $iRow >= $opts->max) break;
} }