浏览代码

se elimina la migracion, la tabla se crea manual y siguiendo nomenclatura oficial.

EmilianoOrtiz 2 月之前
父节点
当前提交
3a411bbdfe

+ 12 - 10
sistema-mantenimiento-back/app/Http/Controllers/AsyncValidateLoadArchivesController.php

@@ -198,21 +198,23 @@ class AsyncValidateLoadArchivesController extends Controller
         Log::info($idFileZip);
         
 
-        // Guardar en bd::validation_jobs 
-        $jobId = DB::table('validation_jobs')->insertGetId([
-            'job_id' => $jobId,
-            'user_id' => $userId,
-            'linea' => $request->input('linea'),
-            'excel_temp_id' => $idFileExcel,
-            'zip_temp_id' => $idFileZip,
-            'created_at' => now(),
-            'updated_at' => now()
+        // Guardar en bd::S002V01TVAJO 
+        $validationJobId = DB::table('S002V01TVAJO')->insertGetId([
+            'VAJO_COJO' => $jobId,
+            'VAJO_IDUS' => $userId,
+            'VAJO_NULI' => $request->input('linea'),
+            'VAJO_ESTA' => 'queued',
+            'VAJO_PRPE' => 0,
+            'VAJO_EXTE' => $idFileExcel,
+            'VAJO_ZITE' => $idFileZip,
+            'VAJO_FERE' => now(),
+            'VAJO_FEMO' => now()
         ]);
         
         return $this->responseController->makeResponse(
             false, 
             'Validación iniciada', 
-            ['job_id' => $jobId, 'status' => 'processing']
+            ['job_id' => $validationJobId, 'status' => 'queued']
         );
     }
 

+ 41 - 41
sistema-mantenimiento-back/bash/validateLoadArchives.php

@@ -27,9 +27,9 @@ try {
 
     // Primero buscar un job que quedó a medias
     $stmt = $pdo->prepare("
-        SELECT * FROM validation_jobs
-        WHERE status = 'processing' AND progress_percentage < 100
-        ORDER BY created_at ASC
+        SELECT * FROM S002V01TVAJO
+        WHERE VAJO_ESTA = 'processing' AND VAJO_PRPE < 100
+        ORDER BY VAJO_FERE ASC
         LIMIT 1
         FOR UPDATE
     ");
@@ -39,9 +39,9 @@ try {
     // Si no hay, buscar jobs fallidos para reintentar
     if (!$job) {
         $stmt = $pdo->prepare("
-            SELECT * FROM validation_jobs
-            WHERE status = 'failed'
-            ORDER BY created_at ASC
+            SELECT * FROM S002V01TVAJO
+            WHERE VAJO_ESTA = 'failed'
+            ORDER BY VAJO_FERE ASC
             LIMIT 1
             FOR UPDATE
         ");
@@ -49,22 +49,22 @@ try {
         $job = $stmt->fetch(PDO::FETCH_ASSOC);
         
         if ($job) {
-            echo "Reintentando job fallido: {$job['id']}\n";
+            echo "Reintentando job fallido: {$job['VAJO_IDJO']}\n";
             $update = $pdo->prepare("
-                UPDATE validation_jobs
-                SET status = 'processing', error_message = NULL, updated_at = NOW()
-                WHERE id = ?
+                UPDATE S002V01TVAJO
+                SET VAJO_ESTA = 'processing', VAJO_ERME = NULL, VAJO_FEMO = NOW()
+                WHERE VAJO_IDJO = ?
             ");
-            $update->execute([$job['id']]);
+            $update->execute([$job['VAJO_IDJO']]);
         }
     }
 
     // Si no hay, tomar uno en cola
     if (!$job) {
         $stmt = $pdo->prepare("
-            SELECT * FROM validation_jobs
-            WHERE status = 'queued'
-            ORDER BY created_at ASC
+            SELECT * FROM S002V01TVAJO
+            WHERE VAJO_ESTA = 'queued'
+            ORDER BY VAJO_FERE ASC
             LIMIT 1
             FOR UPDATE
         ");
@@ -73,11 +73,11 @@ try {
 
         if ($job) {
             $update = $pdo->prepare("
-                UPDATE validation_jobs
-                SET status = 'processing', updated_at = NOW()
-                WHERE id = ?
+                UPDATE S002V01TVAJO
+                SET VAJO_ESTA = 'processing', VAJO_FEMO = NOW()
+                WHERE VAJO_IDJO = ?
             ");
-            $update->execute([$job['id']]);
+            $update->execute([$job['VAJO_IDJO']]);
         }
     }
 
@@ -89,22 +89,22 @@ try {
         exit;
     }
 
-    echo "Procesando Job ID: {$job['id']}\n";
+    echo "Procesando Job ID: {$job['VAJO_IDJO']}\n";
     
     // Enviar notificación WebSocket de inicio
-    sendWebSocketNotification($job['user_id'], 'processing', $job['id']);
+    sendWebSocketNotification($job['VAJO_IDUS'], 'processing', $job['VAJO_IDJO']);
 
     // 4. Determinar archivos ya procesados
-    $results = json_decode($job['results'], true) ?? ['processed_files' => []];
+    $results = json_decode($job['VAJO_RESU'], true) ?? ['processed_files' => []];
     $procesados = $results['processed_files'] ?? [];
 
     // 5. Buscar ruta del ZIP en base de datos
     $stmt = $pdo->prepare("SELECT ARTE_UBTE FROM s002v01tarte WHERE ARTE_IDAR = ?");
-    $stmt->execute([$job['zip_temp_id']]);
+    $stmt->execute([$job['VAJO_ZITE']]);
     $zipData = $stmt->fetch(PDO::FETCH_ASSOC);
     
     if (!$zipData) {
-        throw new Exception("ZIP ID no encontrado: {$job['zip_temp_id']}");
+        throw new Exception("ZIP ID no encontrado: {$job['VAJO_ZITE']}");
     }
     
     $zipPath = $zipData['ARTE_UBTE'];
@@ -114,8 +114,8 @@ try {
     
     // Guardar IDs de archivos temporales
     $tempFiles = [
-        'excel' => getEncrypt($job['excel_temp_id']),
-        'zip' => getEncrypt($job['zip_temp_id'])
+        'excel' => getEncrypt($job['VAJO_EXTE']),
+        'zip' => getEncrypt($job['VAJO_ZITE'])
     ];
     
     $individualTempFiles = [];
@@ -178,8 +178,8 @@ try {
         curl_setopt($ch, CURLOPT_POST, true);
         curl_setopt($ch, CURLOPT_POSTFIELDS, [
             'file' => new CURLFile($archivoExtraido, mime_content_type($archivoExtraido), $nombreArchivo),
-            'id_user' => $job['user_id'],
-            'linea' => $job['linea']
+            'id_user' => $job['VAJO_IDUS'],
+            'linea' => $job['VAJO_NULI']
         ]);
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
         $response = curl_exec($ch);
@@ -204,14 +204,14 @@ try {
 
             $results['processed_files'] = $procesados;
             $stmt = $pdo->prepare("
-                UPDATE validation_jobs
-                SET results = ?, progress_percentage = ?, updated_at = NOW()
-                WHERE id = ?
+                UPDATE S002V01TVAJO
+                SET VAJO_RESU = ?, VAJO_PRPE = ?, VAJO_FEMO = NOW()
+                WHERE VAJO_IDJO = ?
             ");
-            $stmt->execute([json_encode($results), $progress, $job['id']]);
+            $stmt->execute([json_encode($results), $progress, $job['VAJO_IDJO']]);
             
             // Enviar notificación de progreso
-            sendWebSocketNotification($job['user_id'], 'progress', $job['id'], $progress);
+            sendWebSocketNotification($job['VAJO_IDUS'], 'progress', $job['VAJO_IDJO'], $progress);
 
             //echo "Progreso: {$progress}%\n";
         } else {
@@ -227,11 +227,11 @@ try {
 
     // 7. Marcar como completado
     $stmt = $pdo->prepare("
-        UPDATE validation_jobs
-        SET status = 'completed', progress_percentage = 100, completed_at = NOW(), updated_at = NOW()
-        WHERE id = ?
+        UPDATE S002V01TVAJO
+        SET VAJO_ESTA = 'completed', VAJO_PRPE = 100, VAJO_FECO = NOW(), VAJO_FEMO = NOW()
+        WHERE VAJO_IDJO = ?
     ");
-    $stmt->execute([$job['id']]);
+    $stmt->execute([$job['VAJO_IDJO']]);
     
     // Enviar notificación de completado con archivos temporales
     $completionData = [
@@ -239,18 +239,18 @@ try {
         'individual_temp_files' => $individualTempFiles
     ];
 
-    sendWebSocketNotification($job['user_id'], 'completed', $job['id'], 100, $completionData);
+    sendWebSocketNotification($job['VAJO_IDUS'], 'completed', $job['VAJO_IDJO'], 100, $completionData);
 
-    echo "Job completado: {$job['id']}\n";
+    echo "Job completado: {$job['VAJO_IDJO']}\n";
 
 } catch (Exception $e) {
     echo "ERROR: " . $e->getMessage() . "\n";
     
     // Enviar notificación de error si hay job activo
     if (isset($job)) {
-        $stmt = $pdo->prepare("UPDATE validation_jobs SET status = 'failed', error_message = ? WHERE id = ?");
-        $stmt->execute([$e->getMessage(), $job['id']]);
-        sendWebSocketNotification($job['user_id'], 'failed', $job['id']);
+        $stmt = $pdo->prepare("UPDATE S002V01TVAJO SET VAJO_ESTA = 'failed', VAJO_ERME = ? WHERE VAJO_IDJO = ?");
+        $stmt->execute([$e->getMessage(), $job['VAJO_IDJO']]);
+        sendWebSocketNotification($job['VAJO_IDUS'], 'failed', $job['VAJO_IDJO']);
     }
 } finally {
     // 8. Limpiar y eliminar lock global

+ 0 - 31
sistema-mantenimiento-back/database/migrations/2024_01_01_000001_create_validation_jobs_table.php

@@ -1,31 +0,0 @@
-<?php
-
-use Illuminate\Database\Migrations\Migration;
-use Illuminate\Database\Schema\Blueprint;
-use Illuminate\Support\Facades\Schema;
-
-return new class extends Migration
-{
-    public function up(): void
-    {
-        Schema::create('validation_jobs', function (Blueprint $table) {
-            $table->id()->autoIncrement();
-            $table->string('job_id')->unique();
-            $table->string('user_id');
-            $table->integer('linea');
-            $table->enum('status', ['queued', 'processing', 'completed', 'failed'])->default('queued');
-            $table->integer('progress_percentage')->default(0);
-            $table->json('results')->nullable();
-            $table->text('error_message')->nullable();
-            $table->string('excel_temp_id')->nullable();
-            $table->string('zip_temp_id')->nullable();
-            $table->timestamps();
-            $table->timestamp('completed_at')->nullable();
-        });
-    }
-
-    public function down(): void
-    {
-        Schema::dropIfExists('validation_jobs');
-    }
-};