Quellcode durchsuchen

BiAuditGenerate - bug fix + zaczątek importera bazy pracowników

Mariusz Muszyński vor 8 Jahren
Ursprung
Commit
ee7807d3f3
1 geänderte Dateien mit 50 neuen und 7 gelöschten Zeilen
  1. 50 7
      SE/se-lib/Route/UrlAction/BiAuditGenerate.php

+ 50 - 7
SE/se-lib/Route/UrlAction/BiAuditGenerate.php

@@ -1236,6 +1236,50 @@ Router::getRoute("UrlAction_BiAuditGenerate")->' . $function . ';
 		}
 	}
 
+	private static function importPracownicy() { //TODO
+		$fields = [
+			'BI_audit_ENERGA_PRACOWNICY' = [
+				'PERNR',
+				'imiona',
+				'nazwisko',
+				'pesel',
+				'nr_konta',
+				'jednostka_organizacyjna',
+				'nip',
+				'regon',
+				'source',
+			],
+			'BI_audit_ENERGA_PRACOWNICY_adresy' = [
+				'kodPocztowy',
+				'miejscowosc',
+				'ulica',
+				'nrBudynku',
+				'nrLokalu',
+			],
+		];
+
+		$query = "select * from `BI_audit_ENERGA_PRACOWNICY_import` where `importResult` = 'none'";
+		$pracownicy = DB::getPDO()->query($query);
+		while ($pracownik = $pracownicy->fetch()) {
+			$ID_pracownik = DB::getPDO()->fetchValue("select `ID` from `BI_audit_ENERGA_PRACOWNICY` where `pesel` = '{$pracownik['pesel']}'");
+			$sqlArr = [];
+			foreach ($fields['BI_audit_ENERGA_PRACOWNICY'] as $field) $sqlArr[$field] = trim($pracownik[$field]);
+			if ($ID_pracownik) DB::getPDO()->update('BI_audit_ENERGA_PRACOWNICY', 'ID', $ID, $sqlArr);
+			else $ID_pracownik = DB::getPDO()->insert('BI_audit_ENERGA_PRACOWNICY', $sqlArr);
+
+			$sqlArr = [];
+			foreach ($fields['BI_audit_ENERGA_PRACOWNICY_adresy'] as $field) {
+				$sqlArr[$field] = trim($pracownik[$field]);
+				if (!$sqlArr[$field]) unset $sqlArr[$field];
+			}
+			if (!$sqlArr) break;
+			$sql = [];
+//			foreach ($fields['BI_audit_ENERGA_PRACOWNICY_adresy'] as $field) {
+////				if (isset($sqlArr[$field])) $sql[] = "`{$field}` = " . DUPA;
+			}
+		}
+	}
+
 	private static function reloadCache_parseUmowy($full = false) {
 		$fields = [
 			'BI_audit_ENERGA_RUM_KONTRAHENCI' => [
@@ -1776,6 +1820,7 @@ SQL;
 		$reloadCacheResultFile = $tasksDirLocation . "/reloadCache.result";
 		file_put_contents($reloadCachePidFile, getmypid());
 		try {
+			//self::importPracownicy(); //TODO
 			self::reloadCache_reTeryt($full);
 			self::reloadCache_parseUmowy($full);
 			self::reloadCache_updateAll($full, $onlyBase);
@@ -1993,7 +2038,7 @@ class BiAuditPowiazania {
 	private $lowProgressCount = 0;
 	private $count, $i;
 	private $splittedResults = [];
-	private $maxResults = 200000;
+	private $maxResults = 1000000;
 
 	private function getRefTable($tableFrom, $tableTo, $returnException = true) {
 		if (!isset($this->refTables[$tableFrom][$tableTo])) {
@@ -2024,12 +2069,12 @@ class BiAuditPowiazania {
 	private function saveProgress($progress, $message = null) {
 		$timestamp = microtime(true);
 		if ($progress !== null && $this->i) {
-			$this->lastProgress = $progress;
 			$elapsed = $timestamp - $this->startTimestamp;
 			if ($progress) {
-				$lastElapsed = $timestamp - $this->lastTimestamp;
-				$lastProgress = $progress - $this->lastProgress;
-				$estimated = (($elapsed * (1 - $progress)) / $progress + ($lastElapsed * (1 - $lastProgress)) / $lastProgress) / 2;
+				//$lastElapsed = $timestamp - $this->lastTimestamp;
+				//$lastProgress = $progress - $this->lastProgress;
+				//$estimated = (($elapsed * (1 - $progress)) / $progress + ($lastElapsed * (1 - $lastProgress)) / $lastProgress) / 2;
+				$estimated = ($elapsed * (1 - $progress)) / $progress;
 			} else $estimated = "N/A";
 			$this->lastProgress = $progress;
 			$this->lastTimestamp = $timestamp;
@@ -2042,8 +2087,6 @@ class BiAuditPowiazania {
 		file_put_contents($this->progressFile, json_encode($this->progress));
 	}
 
-	
-
 	private static function throwException($message) {
 		self::saveToLog($message);
 		throw new Exception($message);