소스 검색

Merge branch 'salemDev' of http://209.50.56.224/git/JoseBrito/SAM_FRONT_V2 into salemDev

SalemRoman 2 달 전
부모
커밋
a631cc64e3
2개의 변경된 파일169개의 추가작업 그리고 82개의 파일을 삭제
  1. 97 48
      src/app/components/template/notification-dialog/notification-dialog.component.ts
  2. 72 34
      src/app/services/gdel.service.ts

+ 97 - 48
src/app/components/template/notification-dialog/notification-dialog.component.ts

@@ -1,18 +1,27 @@
 import { Component, Inject, OnInit } from '@angular/core';
-import { NotificationAction, NotificationDetailsResponse, NotificationsListItem } from '../../../interfaces/notification.interface';
-import { MAT_DIALOG_DATA, MatDialog, MatDialogRef } from '@angular/material/dialog';
+import {
+  NotificationAction,
+  NotificationDetailsResponse,
+  NotificationsListItem,
+} from '../../../interfaces/notification.interface';
+import {
+  MAT_DIALOG_DATA,
+  MatDialog,
+  MatDialogRef,
+} from '@angular/material/dialog';
 import { EncService } from '../../../services/enc.service';
 import { NotificationsService } from '../../../services/notifications.service';
 import { ResourcesService } from '../../../services/resources.service';
 import { CorrectiveMaintenanceService } from '../../../services/corrective-maintenance.service';
+import { GdelService } from '../../../services/gdel.service';
 import { lastValueFrom } from 'rxjs';
 import { CorrectiveOrderDetailsComponent } from '../../corrective-maintenance/operations-management/corrective-order-details/corrective-order-details.component';
 
 @Component({
-    selector: 'app-notification-dialog',
-    templateUrl: './notification-dialog.component.html',
-    styleUrl: './notification-dialog.component.css',
-    standalone: false
+  selector: 'app-notification-dialog',
+  templateUrl: './notification-dialog.component.html',
+  styleUrl: './notification-dialog.component.css',
+  standalone: false,
 })
 export class NotificationDialogComponent implements OnInit {
   idNotification: string;
@@ -29,7 +38,8 @@ export class NotificationDialogComponent implements OnInit {
     private _dialog: MatDialog,
     private _resourcesService: ResourcesService,
     private _correctiveMaintenanceService: CorrectiveMaintenanceService,
-    private _dialogRef: MatDialogRef<NotificationDialogComponent>,
+    private _gdelService: GdelService,
+    private _dialogRef: MatDialogRef<NotificationDialogComponent>
   ) {
     this.idNotification = '';
     this.isLoading = true;
@@ -42,30 +52,38 @@ export class NotificationDialogComponent implements OnInit {
     this.init();
   }
 
-  async init(){
-    this.idNotification = await this._encService.decrypt(this._data.idNotification);
+  async init() {
+    this.idNotification = await this._encService.decrypt(
+      this._data.idNotification
+    );
     this.getNotification();
   }
 
-  async getNotification(){
-    try{
+  async getNotification() {
+    try {
       let idUser = localStorage.getItem('idusuario')!;
-      let notification: NotificationDetailsResponse = await lastValueFrom(this._notificationsService.getNotification(
-        this._data.idNotification, 
-        'S',
-        idUser, 
-        1
-      ));
+      let notification: NotificationDetailsResponse = await lastValueFrom(
+        this._notificationsService.getNotification(
+          this._data.idNotification,
+          'S',
+          idUser,
+          1
+        )
+      );
 
       this.hasError = notification.error;
       this.errorStr = notification.msg;
 
-      if(!this.hasError){
-        let notificationActionsArr: NotificationAction[] = JSON.parse(notification.response.ACCIONES);
-        
+      if (!this.hasError) {
+        let notificationActionsArr: NotificationAction[] = JSON.parse(
+          notification.response.ACCIONES
+        );
+
         notification.response.ACCIONES_ARR = notificationActionsArr;
         if (notification.response.ID_ORDEN !== null) {
-          notification.response.ID_ORDEN = await this._encService.decrypt(notification.response.ID_ORDEN);
+          notification.response.ID_ORDEN = await this._encService.decrypt(
+            notification.response.ID_ORDEN
+          );
         }
 
         this.notification = notification.response;
@@ -73,14 +91,14 @@ export class NotificationDialogComponent implements OnInit {
       }
 
       this.isLoading = false;
-    }catch(error: any){
+    } catch (error: any) {
       console.log(error);
-      
-      if(error.error == undefined){
+
+      if (error.error == undefined) {
         this.errorStr = 'Ocurrió un error inesperado.';
-      }else if(error.error.msg == undefined){
+      } else if (error.error.msg == undefined) {
         this.errorStr = 'Ocurrió un error inesperado.';
-      }else{
+      } else {
         this.errorStr = error.error.msg;
       }
 
@@ -89,38 +107,65 @@ export class NotificationDialogComponent implements OnInit {
     }
   }
 
-  executeNotificationAction(func: string, params: string){
+  executeNotificationAction(func: string, params: string) {
     let paramsArr = JSON.parse(params);
-    switch(func){
-      case "openCorrectiveWorkOrderDetails":
+    switch (func) {
+      case 'openCorrectiveWorkOrderDetails':
         this.openCorrectiveWorkOrderDetails(paramsArr[0]);
-      break;
-      case "validateCorrectiveWorkOrder":
+        break;
+      case 'validateCorrectiveWorkOrder':
         this.validateCorrectiveWorkOrder(paramsArr[0]);
-      break;
-      case "openModule":
+        break;
+      case 'openModule':
         console.log(paramsArr[0]);
-        
+
         this._dialogRef.close(`go|${paramsArr[0]}`);
-      break;
+        break;
+      case 'processLoadArchives':
+        this.processLoadArchives(paramsArr);
+        break;
       default:
-        this._resourcesService.openSnackBar('La función seleccionada no existe.');
-      break;
+        this._resourcesService.openSnackBar(
+          'La función seleccionada no existe.'
+        );
+        break;
     }
   }
 
   //FUNCIONES POSIBLES PARA LAS NOTIFICACIONES
-  openCorrectiveWorkOrderDetails(idOrder: string){
+  async processLoadArchives(params: any) {
+    try {
+      let idUser = localStorage.getItem('idusuario')!;
+      let body = {
+        id_user: idUser,
+        linea: '1',
+        temp_files: params.temp_files,
+        individual_temp_files: params.individual_temp_files
+      };
+
+      await lastValueFrom(this._gdelService.processZipFile(body));
+      this._resourcesService.openSnackBar('Archivos procesados correctamente.');
+      this._dialogRef.close();
+    } catch (error: any) {
+      if (error.error?.msg) {
+        this._resourcesService.openSnackBar(error.error.msg);
+      } else {
+        this._resourcesService.openSnackBar('Ocurrió un error inesperado.');
+      }
+    }
+  }
+
+  openCorrectiveWorkOrderDetails(idOrder: string) {
     this._dialog.open(CorrectiveOrderDetailsComponent, {
       width: '480px',
       data: {
         idOrder: idOrder,
-      }
-    })
+      },
+    });
   }
 
-  async validateCorrectiveWorkOrder(idOrder: string){
-    try{
+  async validateCorrectiveWorkOrder(idOrder: string) {
+    try {
       let idUser = localStorage.getItem('idusuario')!;
       let formData = new FormData();
 
@@ -128,15 +173,19 @@ export class NotificationDialogComponent implements OnInit {
       formData.append('linea', '1');
       formData.append('id_order', idOrder);
 
-      await lastValueFrom(this._correctiveMaintenanceService.approveWorkOrder(formData));
-      this._resourcesService.openSnackBar('La orden de trabajo se aprobó correctamente.');
+      await lastValueFrom(
+        this._correctiveMaintenanceService.approveWorkOrder(formData)
+      );
+      this._resourcesService.openSnackBar(
+        'La orden de trabajo se aprobó correctamente.'
+      );
       this._dialogRef.close();
-    }catch(error: any){
-      if(error.error.msg == undefined){
+    } catch (error: any) {
+      if (error.error.msg == undefined) {
         this._resourcesService.openSnackBar('Ocurrió un error inesperado.');
-      }else if(error.error.msg == undefined){
+      } else if (error.error.msg == undefined) {
         this._resourcesService.openSnackBar('Ocurrió un error inesperado.');
-      }else{
+      } else {
         this._resourcesService.openSnackBar(error.error.msg);
       }
     }

+ 72 - 34
src/app/services/gdel.service.ts

@@ -2,49 +2,79 @@ import { HttpClient, HttpHeaders } from '@angular/common/http';
 import { Injectable } from '@angular/core';
 import { map, Observable } from 'rxjs';
 import { apiTemp } from '../../environments/environment.prod';
-import { BackendResponse, ProcessResponse } from '../components/initial-data-upload/zipfile-upload/zipfile-upload.component';
+import {
+  BackendResponse,
+  ProcessResponse,
+} from '../components/initial-data-upload/zipfile-upload/zipfile-upload.component';
 
 @Injectable({
-  providedIn: 'root'
+  providedIn: 'root',
 })
 export class GdelService {
+  constructor(private _http: HttpClient) {}
 
-  constructor(private _http: HttpClient,) {}
-
-  getDocumentsByUser(idUser: string, line: number){
-    return this.getQuery(`get-documents/${idUser}/${line}`).pipe(map((data: any) => data));
-  }
-
-  getFiles(mod: string, cla: string, sda: string, eda: string, dna: string, ext: string, mode: string, idUser: string, line: number){
-    return this.getQuery(`get-files/${mod}/${cla}/${sda}/${eda}/${dna}/${ext}/${mode}/${idUser}/${line}`).pipe(map((data: any) => data));
+  getDocumentsByUser(idUser: string, line: number) {
+    return this.getQuery(`get-documents/${idUser}/${line}`).pipe(
+      map((data: any) => data)
+    );
   }
 
-  getDownloadToken(id: string, idUser: string, line: number){
-    return this.getQuery(`get-download-token/${id}/${idUser}/${line}`).pipe(map((data: any) => data));
+  getFiles(
+    mod: string,
+    cla: string,
+    sda: string,
+    eda: string,
+    dna: string,
+    ext: string,
+    mode: string,
+    idUser: string,
+    line: number
+  ) {
+    return this.getQuery(
+      `get-files/${mod}/${cla}/${sda}/${eda}/${dna}/${ext}/${mode}/${idUser}/${line}`
+    ).pipe(map((data: any) => data));
+  }
+
+  getDownloadToken(id: string, idUser: string, line: number) {
+    return this.getQuery(`get-download-token/${id}/${idUser}/${line}`).pipe(
+      map((data: any) => data)
+    );
   }
 
   getFileInfo(id: string, idUser: string, line: number) {
-    return this.getQuery(`get-file-info/${id}/${idUser}/${line}`).pipe(map((data: any) => data));
+    return this.getQuery(`get-file-info/${id}/${idUser}/${line}`).pipe(
+      map((data: any) => data)
+    );
   }
 
-  getPublicDocumentUrl(id: string, idUser: string, line: number){
-    return this.getQuery(`get-public-document-url/${id}/${idUser}/${line}`).pipe(map((data: any) => data));
+  getPublicDocumentUrl(id: string, idUser: string, line: number) {
+    return this.getQuery(
+      `get-public-document-url/${id}/${idUser}/${line}`
+    ).pipe(map((data: any) => data));
   }
 
-  getFileAccess(id: string, idUser: string, line: number){
-    return this.getQuery(`get-file-access/${id}/${idUser}/${line}`).pipe(map((data: any) => data));
+  getFileAccess(id: string, idUser: string, line: number) {
+    return this.getQuery(`get-file-access/${id}/${idUser}/${line}`).pipe(
+      map((data: any) => data)
+    );
   }
 
-  getAssociatedWorkOrders(id: string, idUser: string, line: number){
-    return this.getQuery(`get-associated-work-orders/${id}/${idUser}/${line}`).pipe(map((data: any) => data));
+  getAssociatedWorkOrders(id: string, idUser: string, line: number) {
+    return this.getQuery(
+      `get-associated-work-orders/${id}/${idUser}/${line}`
+    ).pipe(map((data: any) => data));
   }
 
-  getPublicTempDocumentUrl(id: string, idUser: string, line: number){
-    return this.getQuery(`get-public-temp-document-url/${id}/${idUser}/${line}`).pipe(map((data: any) => data));
+  getPublicTempDocumentUrl(id: string, idUser: string, line: number) {
+    return this.getQuery(
+      `get-public-temp-document-url/${id}/${idUser}/${line}`
+    ).pipe(map((data: any) => data));
   }
 
   uploadTempFile(body: any) {
-    return this.postQuery('upload-temp-file', body).pipe(map((data: any) => data));
+    return this.postQuery('upload-temp-file', body).pipe(
+      map((data: any) => data)
+    );
   }
 
   validateZipFile(body: any): Observable<BackendResponse> {
@@ -61,19 +91,26 @@ export class GdelService {
 
   validateEquipFromExcel(body: any) {
     return this.postQuery('equipment-data/verify-template', body).pipe(
-      map((data: any) => data));
+      map((data: any) => data)
+    );
   }
 
   deleteTempFile(body: any) {
-    return this.postQuery('delete-temp-file', body).pipe(map((data: any) => data));
+    return this.postQuery('delete-temp-file', body).pipe(
+      map((data: any) => data)
+    );
   }
 
   saveFinalFile(body: any) {
-    return this.postQuery('save-final-file', body).pipe(map((data: any) => data));
+    return this.postQuery('save-final-file', body).pipe(
+      map((data: any) => data)
+    );
   }
 
   updateFilePermissions(body: any) {
-    return this.postQuery('update-file-permissions', body).pipe(map((data: any) => data));
+    return this.postQuery('update-file-permissions', body).pipe(
+      map((data: any) => data)
+    );
   }
 
   deleteFile(body: any) {
@@ -81,27 +118,28 @@ export class GdelService {
   }
 
   changeAssociationStatus(body: any) {
-    return this.postQuery('change-association-status', body).pipe(map((data: any) => data));
+    return this.postQuery('change-association-status', body).pipe(
+      map((data: any) => data)
+    );
   }
 
-
-  postQuery(query: string, body: any){
+  postQuery(query: string, body: any) {
     const JWT = `Bearer ${localStorage.getItem('token')}`;
     const URL = `${apiTemp}${query}`;
     return this._http.post(URL, body, {
       headers: new HttpHeaders({
-        Authorization: JWT!
-      })
+        Authorization: JWT!,
+      }),
     });
   }
 
-  getQuery(query: string){
+  getQuery(query: string) {
     const JWT = `Bearer ${localStorage.getItem('token')}`;
-    const URL = `${apiTemp}${query}`; 
+    const URL = `${apiTemp}${query}`;
     return this._http.get(URL, {
       headers: new HttpHeaders({
         Authorization: JWT,
-      })
+      }),
     });
   }
 }