responseController = new ResponseController(); $this->functionsController = new FunctionsController(); $this->encryptionController = new EncryptionController(); $this->notificationsController = new NotificationsController(); $url = 'http://localhost:3200'; $this->socketClient = new Client(Client::engine(Client::CLIENT_4X, $url)); $this->socketClient->initialize(); $this->socketClient->of('/'); $this->monitoredItems = ['R650', 'R450']; } public function registerData(Request $request) { $validator = Validator::make($request->all(), [ 'data' => 'required|string' ]); if($validator->fails()){ return $this->responseController->makeResponse( true, "Se encontraron uno o más errores.", $this->responseController->makeErrors( $validator->errors()->messages() ), 401 ); } $form = $request->all(); $now = $this->functionsController->now(); $nowStr = $now->toDateTimeString(); $dataArr = json_decode($form['data'], true); foreach($dataArr as $item){ if(array_key_exists('path', $item)){ $routeStr = ''; foreach($item['path'] as $item0){ $routeStr .= "/$item0[name]"; } foreach($this->monitoredItems as $item0){ if(str_contains($routeStr, $item0)){ if(is_null($item['last_measurement']['display_minimum']) || is_null($item['last_measurement']['display_maximum'])){ $this->notificationsController->emitNotification( 'S002V01M01ADSI', "El canal $item[channel][id] no ha recibido información", "No se ha podido obtener información canal $item[channel][id] - $item[channel][name].", [[ 'BOTON' => 'Ver detalles', 'FUNCION' => 'openCorrectiveWorkOrderDetails', 'PARAMETROS' => json_encode([]) ], [ 'BOTON' => 'Validar orden', 'FUNCION' => 'validateCorrectiveWorkOrder', 'PARAMETROS' => json_encode([]) ], [ 'BOTON' => 'Ir al módulo', 'FUNCION' => 'openModule', 'PARAMETROS' => json_encode([$this->encryptionController->encrypt('GMCO/ORTR/GEOP')]) ]], ['0000000000'], '0000000000', $form['linea'], $this->socketClient, '', '' ); }else{ $minVal = floatval($item['last_measurement']['display_minimum']); $maxVal = floatval($item['last_measurement']['display_maximum']); $value = floatval($item['last_measurement']['display_value']); if($value < $minVal){ $this->notificationsController->emitNotification( 'S002V01M01ADSI', "Valor mínimo excedido en el canal $item[channel][id]", "La medida del valor mínimo del canal $item[channel][id] - $item[channel][name] fue excedido.", [[ 'BOTON' => 'Ver detalles', 'FUNCION' => 'openCorrectiveWorkOrderDetails', 'PARAMETROS' => json_encode([]) ], [ 'BOTON' => 'Validar orden', 'FUNCION' => 'validateCorrectiveWorkOrder', 'PARAMETROS' => json_encode([]) ], [ 'BOTON' => 'Ir al módulo', 'FUNCION' => 'openModule', 'PARAMETROS' => json_encode([$this->encryptionController->encrypt('GMCO/ORTR/GEOP')]) ]], ['0000000000'], '0000000000', $form['linea'], $this->socketClient, '', '' ); } } } } } } $idReport = DB::table('S002V01TPRTG')->insertGetId([ 'PRTG_NULI' => 1, 'PRTG_FERE' => $nowStr, 'PRTG_DATO' => $form['data'] ]); $idReportEnc = $this->encryptionController->encrypt($idReport); $this->socketClient->emit('new_prtg_report', ['report' => $idReportEnc]); return $this->responseController->makeResponse(false, 'EXITO'); } public function getReport($idReport, $idUser, $line) { DB::enableQueryLog(); $idUser = $this->encryptionController->decrypt($idUser); if(!$idUser){ return $this->responseController->makeResponse(true, 'El ID del usuario que realizó la solicitud no está encriptado correctamente', [], 400); } $usr = DB::table('S002V01TUSUA')->where([ ['USUA_NULI', '=', $line], ['USUA_IDUS', '=', $idUser], ])->first(); if(is_null($usr)){ return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no está registrado', [], 404); } $idReport = $this->encryptionController->decrypt($idReport); if(!$idReport){ return $this->responseController->makeResponse(true, 'El ID del reporte solicitado no está encriptado correctamente', [], 400); } $report = DB::table('S002V01TPRTG')->select([ 'PRTG_IDRE AS ID_REPORTE', 'PRTG_FERE AS FECHA_REGISTRO', 'PRTG_DATO AS DATOS' ])->where([ ['PRTG_NULI', '=', $line], ['PRTG_IDRE', '=', $idReport] ])->first(); if(is_null($report)){ return $this->responseController->makeResponse(true, 'El reporte consultado no está registrado', [], 404); } $report->ID_REPORTE = $this->encryptionController->encrypt($report->ID_REPORTE); $report->DATOS = $this->encryptionController->encrypt($report->DATOS); return $this->responseController->makeResponse(false, 'EXITO', $report); } public function getLastReports($idUser, $line) { DB::enableQueryLog(); $idUser = $this->encryptionController->decrypt($idUser); if(!$idUser){ return $this->responseController->makeResponse(true, 'El ID del usuario que realizó la solicitud no está encriptado correctamente', [], 400); } $usr = DB::table('S002V01TUSUA')->where([ ['USUA_NULI', '=', $line], ['USUA_IDUS', '=', $idUser], ])->first(); if(is_null($usr)){ return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no está registrado', [], 404); } $lastReports = DB::table('S002V01TPRTG')->select([ 'PRTG_IDRE AS ID_REPORTE', 'PRTG_FERE AS FECHA_REGISTRO', 'PRTG_DATO AS DATOS' ])->orderBy('PRTG_FERE', 'desc')->limit(5)->get()->all(); foreach($lastReports as $key=>$report){ $report->ID_REPORTE = $this->encryptionController->encrypt($report->ID_REPORTE); $report->DATOS = $this->encryptionController->encrypt($report->DATOS); $lastReports[$key] = $report; } return $this->responseController->makeResponse(false, 'EXITO', $lastReports); } }