Pārlūkot izejas kodu

Descarga en GDEL

alanittec 2 gadi atpakaļ
vecāks
revīzija
9c63b6578a

+ 58 - 5
sistema-mantenimiento-back/app/Http/Controllers/DocumentManagementController.php

@@ -20,18 +20,17 @@ class DocumentManagementController extends Controller{
     }
 
     public function downloadFile($token, $idUser, $line){
-        DB::enableQueryLog();
 
         $tokenInfo = DB::table('S002V01TTODE')->where([
             ['TODE_NULI', '=', $line],
             ['TODE_TOKE', '=', $token]
         ])->first();
 
-        if(is_null($tokenInfo)){
+/*         if(is_null($tokenInfo)){
             return $this->responseController->makeResponse(true, 'El token de descarga no existe.', [], 404);
         }else if($tokenInfo->TODE_ESTA != 'Activo'){
             return $this->responseController->makeResponse(true, 'El token de descarga ya fue utilizado.', [], 401);
-        }
+        } */
 
         $token = $this->encryptionController->shortDec($token);
         if(!$token){
@@ -96,10 +95,11 @@ class DocumentManagementController extends Controller{
             ['AFAL_EXTE', '=', $exte],
         ])->first();
 
-        if(is_null($usr)){
+        $aux = DB::getQueryLog();
+
+        if(is_null($file)){
             return $this->responseController->makeResponse(true, 'El archivo solicitado no existe.', [], 404);
         }
-
         return response()->download($file->AFAL_UBIC);
     }
 
@@ -149,6 +149,7 @@ class DocumentManagementController extends Controller{
             ['AFAL_EXTE', '=', $exte],
         ])->first();
 
+        $aux = DB::getQueryLog();
         if(is_null($file)){
             return $this->responseController->makeResponse(true, 'El archivo solicitado no existe.', [], 404);
         }
@@ -229,4 +230,56 @@ class DocumentManagementController extends Controller{
 
         return $this->responseController->makeResponse(false, 'EXITO', $fileInfo);
     }
+
+    public function getDocuments($idUser, $line)
+    {
+        DB::enableQueryLog();
+        $idUser = $this->encryptionController->shortDec($idUser);
+        if (!$idUser) {
+            return $this->responseController->makeResponse(true, 'El ID del usuario que realizó la solicitud no está encriptado correctamente', [], 400);
+        }
+
+        $documents = DB::table('s002v01tafal')->select(
+            'AFAL_NOAR as NOMBRE_ARC',
+            'AFAL_EXTE as EXTENSION',
+            'AFAL_TAMA as TAMANIO',
+            'AFAL_NUVE as VERSION',
+            'AFAL_FECR as FECHA_REGISTRO',
+            'AFAL_USRE as PROPIETARIO',
+            'AFAL_UBIC as URL',
+            'AFAL_USAC AS ACCESO',
+            'AFAL_ESTA AS ESTADO',
+            'AFAL_NULI AS NUMERO_LINEA',
+            'AFAL_CLDO AS CLASIFICACION',
+            'AFAL_COMO AS MODULO',
+            'AFAL_NUSE AS SECUENCIAL'
+        )->where('AFAL_USRE', $idUser)->get()->all();
+
+        $nowStr = Carbon::now('America/Mexico_city')->toDateTimeString();
+        $actions = DB::getQueryLog();
+
+        //$this->functionsController->registerActivity($actions, $idUser, $nowStr, $line);
+        return $this->responseController->makeresponse(false, "EXITO", $documents);
+    }
+
+    public function getInfoDocument($idUser, $line, $idDocument){
+        DB::enableQueryLog();
+        $idUser = $this->encryptionController->shortDec($idUser);
+        if(!$idUser){
+            return $this->responseController->makeResponse(true, 'El ID del usuario que realizó la solicitud no está encriptado correctamente', [], 400);
+        }
+
+        $idDocument = $this->encryptionController->shortDec($idDocument);
+        if(!$idDocument){
+            return $this->responseController->makeResponse(true, 'El ID del documento no está encriptado correctamente', [], 400);
+        }
+
+        $document = DB::table('s002v01tafal')->where('AFAL_USRE', $idUser)->where('AFAL_ID', $idDocument)->get();
+
+        $nowStr = Carbon::now('America/Mexico_city')->toDateTimeString();
+        $actions = DB::getQueryLog();
+
+        //$this->functionsController->registerActivity($actions, $idUser, $nowStr, $line);
+        return $this->responseController->makeresponse(false, "EXITO", $document);
+    }
 }

+ 5 - 2
sistema-mantenimiento-front/src/app/components/gdel/addo/addo.component.html

@@ -1,7 +1,7 @@
 <div class="items-container animated fadeIn">
     <div id="navigation" class="mb-8">
-        <div class="prev-page prevent-select indigo_primary_background mat-elevation-z8"
-            [routerLink]="['/sam/GDEL']" matRipple>
+        <div class="prev-page prevent-select indigo_primary_background mat-elevation-z8" [routerLink]="['/sam/GDEL']"
+            matRipple>
             <mat-icon style="color: white;">arrow_back</mat-icon>
             <div class="page-name ml-4">Administración de documentos</div>
         </div>
@@ -131,6 +131,9 @@
                 </tr>
             </table>
         </mat-card-content>
+        <mat-card-actions align="end">
+            
+        </mat-card-actions>
     </mat-card>
 </div>
 

+ 7 - 6
sistema-mantenimiento-front/src/app/components/gdel/addo/addo.component.ts

@@ -24,6 +24,7 @@ import { GETBGMService } from 'src/app/services/forms-management/getbgm/getbgm.s
 import { UsersProfilesService } from 'src/app/services/users-profiles.service';
 import { UsersResponse } from 'src/app/interfaces/users.interface';
 import { ProfilesResponse } from 'src/app/interfaces/profiles.interface';
+import { GdelService } from 'src/app/services/gdel/gdel.service';
 export interface TempFileInfo {
   id: string;
   name: string;
@@ -92,7 +93,7 @@ export class ADDOComponent implements OnInit {
     private _moduloService: GETBGMService,
     private _routeActivated: ActivatedRoute,
     private _snackBar: MatSnackBar,
-    private _documentManagement: DocumentManagementService,
+    private _documentManagement: GdelService,
     private _usersProfilesService: UsersProfilesService
   ) {
     this.isNew = false;
@@ -111,7 +112,7 @@ export class ADDOComponent implements OnInit {
   }
 
   ngOnInit(): void {
-    this.consultarModulos();
+    this.getModulesInfo();
     this._routeActivated.queryParams.subscribe((params) => {
       let idDoc = params['idDoc'];
       this.isNew = idDoc == undefined;
@@ -347,12 +348,12 @@ export class ADDOComponent implements OnInit {
   }
 
   async downloadFile(idFile: string) {
-    /*     try{
+    try{
       let shortAvi = await lastValueFrom(this._encService.shortEncrypt(idFile));
       let idEnc = localStorage.getItem('idusuario');
       let shortEnc = await lastValueFrom(this._encService.shortEncrypt(idEnc!));
 
-      let downloadToken = await lastValueFrom(this._advicesService.getDownloadToken(shortAvi.response.encrypted, shortEnc.response.encrypted, 1));
+      let downloadToken = await lastValueFrom(this._documentManagement.getDownloadToken(shortAvi.response.encrypted, shortEnc.response.encrypted, 1));
       //this.downloadLink = "http://git.ittec.mx/sam/public/api/download-file///1";
       this.downloadLink = `http://git.ittec.mx/sam/public/api/download-file/${downloadToken.response.TOKEN}/${shortEnc.response.encrypted}/1`;
       console.log(this.downloadLink);
@@ -368,10 +369,10 @@ export class ADDOComponent implements OnInit {
       }
 
       this.openSnackBar(msg);
-    } */
+    } 
   }
 
-  public async consultarModulos() {
+  public async getModulesInfo() {
     this.isLoading = true;
     await lastValueFrom(this._moduloService.getModules()).then(
       (data: ResponseData) => {

+ 6 - 4
sistema-mantenimiento-front/src/app/components/gdel/gdel.component.html

@@ -62,7 +62,7 @@
                                     <mat-icon>note_add</mat-icon>
                                 </button>
                                 <button mat-mini-fab color="info" matTooltip="Actualizar Datos"
-                                    class="override-no-shadow mr-10" (click)="getDocuments()">
+                                    class="override-no-shadow mr-10" (click)="refreshDocuments()">
                                     <mat-icon>refresh</mat-icon>
                                 </button>
                             </div>
@@ -79,7 +79,7 @@
                                         <th mat-header-cell *matHeaderCellDef mat-sort-header>Código</th>
                                         <td mat-cell *matCellDef="let row"
                                             style="overflow:hidden; white-space:nowrap; text-overflow: ellipsis;">{{
-                                            row.ID }} </td>
+                                            row.NOMBRE_ARC }} </td>
                                     </ng-container>
 
                                     <ng-container matColumnDef="NAME">
@@ -134,9 +134,11 @@
                                                     <mat-icon>history</mat-icon>
                                                 </button>
                                                 <button mat-mini-fab color="info" class="override-no-shadow mr-4"
-                                                    matTooltip="Descargar">
+                                                    matTooltip="Descargar" (click)="downloadFile(element.ID)">
                                                     <mat-icon>download</mat-icon>
                                                 </button>
+                                                <a #download [href]="downloadLink" target="_blank" [download]="element.NOMBRE_ARC"></a>
+
                                                 <button mat-mini-fab color="warn" class="override-no-shadow mr-4"
                                                     matTooltip="Eliminar">
                                                     <mat-icon>delete</mat-icon>
@@ -162,7 +164,7 @@
                                                     <button mat-menu-item>
                                                         <mat-icon>history</mat-icon> Historial de Versiones
                                                     </button>
-                                                    <button mat-menu-item>
+                                                    <button mat-menu-item (click)="downloadFile(element.ID)">
                                                         <mat-icon>download</mat-icon> Descargar
                                                     </button>
                                                     <button mat-menu-item>

+ 74 - 40
sistema-mantenimiento-front/src/app/components/gdel/gdel.component.ts

@@ -33,6 +33,7 @@ export class GDELComponent implements AfterViewInit, OnInit {
   public dataSource: MatTableDataSource<any>;
   @ViewChild(MatPaginator) paginator!: MatPaginator;
   @ViewChild(MatSort) sort!: MatSort;
+  @ViewChild('download') a?: ElementRef;
 
   public isLoading: boolean;
   public isLoadingForm: boolean;
@@ -41,6 +42,7 @@ export class GDELComponent implements AfterViewInit, OnInit {
   public ulOptSmall: boolean;
   public txtBuscador: string;
   public clickedIndex: any = 0;
+  public downloadLink: String;
   public options = [
     {
       id: 1,
@@ -65,7 +67,6 @@ export class GDELComponent implements AfterViewInit, OnInit {
     private _dialog: MatDialog,
     private _router: Router,
     public dialog: MatDialog,
-    private _documentManagement: DocumentManagementService,
     private _gdelService: GdelService,
     private _snackBar: MatSnackBar
   ) {
@@ -85,6 +86,7 @@ export class GDELComponent implements AfterViewInit, OnInit {
     this.btnSmall = false;
     this.ulOptSmall = false;
     this.txtBuscador = '';
+    this.downloadLink = '';
   }
 
   ngOnInit(): void {
@@ -132,25 +134,39 @@ export class GDELComponent implements AfterViewInit, OnInit {
     let shortEnc = await lastValueFrom(this._encService.shortEncrypt(idEnc));
 
     let documents: any = await lastValueFrom(
-      this._gdelService.getDocumentsByUser(
-        shortEnc.response.encrypted,
-        1
-      )
+      this._gdelService.getDocumentsByUser(shortEnc.response.encrypted, 1)
     );
 
     if (documents.error) {
       this.openSnackBar(documents.msg);
     } else {
       for (let index = 0; index < documents.response.length; index++) {
+        let codeSAM =
+          documents.response[index].NUMERO_LINEA +
+          '-' +
+          documents.response[index].MODULO +
+          '-' +
+          documents.response[index].CLASIFICACION +
+          '-' +
+          documents.response[index].FECHA_REGISTRO +
+          '-' +
+          documents.response[index].SECUENCIAL +
+          '=' +
+          documents.response[index].VERSION +
+          '=' +
+          documents.response[index].NOMBRE_ARC +
+          '.' +
+          documents.response[index].EXTENSION;
+        let encript = await this._encService.encriptar(codeSAM);
+        let short = await lastValueFrom(this._encService.shortEncrypt(encript));
+        documents.response[index].ID = short.response.encrypted;
         documents.response[index].TAMANIO = this.formatBytes(
           documents.response[index].TAMANIO
         );
       }
       this.dataSource.data = documents.response;
       this.isLoading = false;
-
     }
-    console.log(documents);
   }
 
   async modifyDocument(idDocument: number) {
@@ -183,25 +199,7 @@ export class GDELComponent implements AfterViewInit, OnInit {
     this.ulOptSmall = window.innerWidth <= 1405;
   }
 
-  selectTab(index: number) {
-    this.active = index;
-    console.log(index);
-    
-    switch (index) {
-      case 0:
-        this.getDocuments();
-        break;
-      case 1:
-        this.getShareDocuments();
-        break;
-      case 2:
-        break;
-      default:
-        break;
-    }
-  }
-
-  public openViewer(url: string) {
+   public openViewer(url: string) {
     let dialogRef: any;
     let fileData = {
       url: url,
@@ -257,31 +255,36 @@ export class GDELComponent implements AfterViewInit, OnInit {
   }
 
   // Funcion para descargar archivos
-  async downloadFile(idFile: string) {
-    console.log('descargar archivo');
-
-    /*     try{
-      let shortAvi = await lastValueFrom(this._encService.shortEncrypt(idFile));
+  async downloadFile(idFile: any) {
+    try {
       let idEnc = localStorage.getItem('idusuario');
       let shortEnc = await lastValueFrom(this._encService.shortEncrypt(idEnc!));
 
-      let downloadToken = await lastValueFrom(this._advicesService.getDownloadToken(shortAvi.response.encrypted, shortEnc.response.encrypted, 1));
-      //this.downloadLink = "http://git.ittec.mx/sam/public/api/download-file///1";
-      this.downloadLink = `http://git.ittec.mx/sam/public/api/download-file/${downloadToken.response.TOKEN}/${shortEnc.response.encrypted}/1`;
-      console.log(this.downloadLink);
+      let downloadToken = await lastValueFrom(
+        this._gdelService.getDownloadToken(
+          idFile,
+          shortEnc.response.encrypted,
+          1
+        )
+      );
+      //this.downloadL  ink = "http://git.ittec.mx/sam/public/api/download-file///1";
+      //this.downloadLink = `http://git.ittec.mx/sam/public/api/download-file/${downloadToken.response.TOKEN}/${shortEnc.response.encrypted}/1`;
+      this.downloadLink = `http://192.168.1.2:8000/api/download-file/${downloadToken.response.TOKEN}/${shortEnc.response.encrypted}/1`;
+      console.log(this.downloadLink );
+      
       this.a?.nativeElement.click();
-    }catch(error: any){
+    } catch (error: any) {
       let msg = '';
-      if(error.error == undefined){
+      if (error.error == undefined) {
         msg = 'Ocurrió un error inesperado.';
-      }else if(error.error.msg == undefined){
+      } else if (error.error.msg == undefined) {
         msg = 'Ocurrió un error inesperado.';
-      }else{
+      } else {
         msg = error.error.msg;
       }
 
       this.openSnackBar(msg);
-    } */
+    }
   }
 
   public goBack(steps: number) {
@@ -305,4 +308,35 @@ export class GDELComponent implements AfterViewInit, OnInit {
       duration: 2500,
     });
   }
+
+  selectTab(index: number) {
+    this.active = index;
+    switch (index) {
+      case 0:
+        this.getDocuments();
+        break;
+      case 1:
+        this.getShareDocuments();
+        break;
+      case 2:
+        break;
+      default:
+        break;
+    }
+  }
+
+  refreshDocuments() {
+    switch (this.active) {
+      case 0:
+        this.getDocuments();
+        break;
+      case 1:
+        this.getShareDocuments();
+        break;
+      case 2:
+        break;
+      default:
+        break;
+    }
+  }
 }

+ 2 - 0
sistema-mantenimiento-front/src/app/services/gdel/document-management.service.ts

@@ -23,6 +23,8 @@ export class DocumentManagementService {
     return this.postQuery('delete-file', body).pipe(map((data: any) => data));
   }
 
+  
+
   getQuery(query: string) {
     const JWT = `Bearer ${localStorage.getItem('token')}`;
     const URL = `${apiTemp}${query}`;

+ 19 - 1
sistema-mantenimiento-front/src/app/services/gdel/gdel.service.ts

@@ -19,11 +19,29 @@ export class GdelService {
     const URL = `${apiUriAlan}${query}`;
     return this.http.get(URL, {
       headers: new HttpHeaders({
-        Authorization: JWT
+        Authorization: JWT,
       })
     });
   }
 
+  getFileInfo(id: string, idUser: string, line: number) {
+    return this.getQuery(`get-file-info/${id}/${idUser}/${line}`).pipe(
+      map((data: any) => data)
+    );
+  }
+
+  uploadTempFile(body: any) {
+    return this.postQuery('upload-file', body).pipe(map((data: any) => data));
+  }
+
+  deleteTempFile(body: any) {
+    return this.postQuery('delete-file', body).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));
+  }
+
   postQuery(query: string, body: any){
     const JWT = `Bearer ${localStorage.getItem('token')}`;
     const URL = `${apiUriAlan}${query}`;