false, 'int'=> 0, 'error'=> '']; private $url = '/Thingworx/Things/2050UserLibraryExp/Services/'; private $execMethod = 'work_to_execute'; private $doneMethod = 'work_done'; public static function workToExecute($tid,$test = 0) { $result = false; self::$_instance = new self(); $GWparams = [ 'url' => 'http://' . Yii::$app->params['api']['domain'] . self::$_instance->url, 'param' => [], 'login' => 'ПройдаковИА', 'pass' => 'Ip15351112' ]; $tasksEntity = Tasks::findOne($tid); if ( null == $tasksEntity->asusg_job_mapped_id ) { Logs::addlog(2,'работы не нашел => '.$tid.' ->' . $tasksEntity->asusg_job_mapped_id); return $result; } Logs::addlog(2,'принял работу => '.$tid.', завершение команды => ' . $tasksEntity->accounts->uuid); Logs::addlog(2,'принял работу => '.$tid.', завершение команды => ' . $tasksEntity->asusgjob2launch->asusg_job_uuid); if( null == $tasksEntity->accounts->uuid || null == $tasksEntity->asusgjob2launch->asusg_job_uuid ) { Logs::addlog(2,'не нашел uuid-ы. id = ' . $tid); return $result; } $status = self::$_instance->worksStatusHandler( $tasksEntity->accounts->uuid, $tasksEntity->asusgjob2launch->asusg_job_uuid ); $GWparams['param'] = ['id_work' => $tasksEntity->asusgjob2launch->asusg_job_uuid, 'user_id' => $tasksEntity->accounts->uuid]; if ( $status ) { $GWparams['url'] .= self::$_instance->doneMethod; //Logs::addlog(4,json_encode($GWparams),true); ElasticLog::eipp($GWparams, $tasksEntity->asusgjob2launch->asusg_job_uuid, $tasksEntity->accounts->uuid); $execResult = self::$_instance->curlRequestUni($GWparams,'post'); ElasticLog::eipp($execResult, $tasksEntity->asusgjob2launch->asusg_job_uuid, $tasksEntity->accounts->uuid, false); //Logs::addlog(4,$execResult); LogEippResponse::addLog($time . "done1" . $tasksEntity->asusgjob2launch->asusg_job_uuid, json_encode($GWparams) ,'Попытка закрыть, параметры'); LogEippResponse::addLog($time . "done2" . $tasksEntity->asusgjob2launch->asusg_job_uuid, $execResult ,'Попытка закрыть, ответ от ЕИПП'); Logs::addlog(4,'ФИО : '. $tasksEntity->accounts->name. ', Заказ наряд: '. $tasksEntity->asusgjob2launch->outfit . ', Секция: ' . $tasksEntity->project->sections->section_number.$tasksEntity->project->sections->letter); $result = self::$_instance->checkResponse($execResult); //$result = 'true'; Logs::addlog(4,$result); LogEippResponse::addLog($time . "done4" . $tasksEntity->asusgjob2launch->asusg_job_uuid, $result ,'Работа должна закрыться'); return $result; } Logs::addlog(2,'execMethod'); $GWparams['url'] .= self::$_instance->execMethod; ElasticLog::eipp($GWparams, $tasksEntity->asusgjob2launch->asusg_job_uuid, $tasksEntity->accounts->uuid); $execResult = self::$_instance->curlRequestUni($GWparams,'post'); ElasticLog::eipp($execResult, $tasksEntity->asusgjob2launch->asusg_job_uuid, $tasksEntity->accounts->uuid, false); LogEippResponse::addLog($time . "done" . $tasksEntity->asusgjob2launch->asusg_job_uuid, $execResult ,'Работа не должна закрыться'); //var_dump($execResult); //$result = self::$_instance->checkResponse($execResult); // ЗАГЛУШКА $result = true; //var_dump($result); return $result; } public static function workToExecuteBegin($tid,$test = 0) { $result = false; self::$_instance = new self(); $GWparams = [ 'url' => 'http://' . Yii::$app->params['api']['domain'] . self::$_instance->url, 'param' => [], 'login' => 'ПройдаковИА', 'pass' => 'Ip15351112' ]; $tasksEntity = Tasks::findOne($tid); if ( null == $tasksEntity->asusg_job_mapped_id ) { Logs::addlog(2,'работы не нашел => '.$tid.' ->' . $tasksEntity->asusg_job_mapped_id); return $result; } Logs::addlog(2,'принял работу => '.$tid.', завершение команды => ' . $tasksEntity->accounts->uuid); Logs::addlog(2,'принял работу => '.$tid.', завершение команды => ' . $tasksEntity->asusgjob2launch->asusg_job_uuid); if( null == $tasksEntity->accounts->uuid || null == $tasksEntity->asusgjob2launch->asusg_job_uuid ) { Logs::addlog(2,'не нашел uuid-ы. id = ' . $tid); return $result; } //$status = self::$_instance->worksStatusHandler( $tasksEntity->accounts->uuid, $tasksEntity->asusgjob2launch->asusg_job_uuid ); $GWparams['param'] = ['id_work' => $tasksEntity->asusgjob2launch->asusg_job_uuid, 'user_id' => $tasksEntity->accounts->uuid]; Logs::addlog(2,'execMethod'); $GWparams['url'] .= self::$_instance->execMethod; ElasticLog::eipp($GWparams, $tasksEntity->asusgjob2launch->asusg_job_uuid, $tasksEntity->accounts->uuid); $execResult = self::$_instance->curlRequestUni($GWparams,'post'); ElasticLog::eipp($execResult, $tasksEntity->asusgjob2launch->asusg_job_uuid, $tasksEntity->accounts->uuid, false); LogEippResponse::addLog($time . "done" . $tasksEntity->asusgjob2launch->asusg_job_uuid, $execResult ,'Работа не должна закрыться'); //var_dump($execResult); //$result = self::$_instance->checkResponse($execResult); // ЗАГЛУШКА $result = true; //var_dump($result); return $result; } public static function checkResponse($execResult) { $conf = ['true' => true, 'false' => false]; $execResult = json_decode($execResult,true); if ( is_array($execResult)) { foreach( $execResult['rows'] as $row) { $rowArray = json_decode($row["result"],true); foreach($rowArray as $key => $r) { if ( $key == 'result' and null != $r) { return $rowArray["result"]; } } } } return false; } public function worksStatusHandler($user_uuid, $job_uuid){ //public function worksStatusHandler(){ /* $accountsEntity = Accounts::find()->where(['uuid' => $user_uuid])->one(); //var_dump($accountsEntity); exit; //if ( 0 == count($accountsEntity) ) { if ( null == $accountsEntity ) { self::$_instance->returnArrayWorks['error'] = 'Не найден сотрудник'; return false;//self::$_instance->returnArrayWorks; } */ $asusgJob2LaunchEntity = AsusgJob2Launch::find()->where(['asusg_job_uuid' => $job_uuid])->one(); //if ( 0 == count($asusgJob2LaunchEntity) ) { if ( null == $asusgJob2LaunchEntity ) { self::$_instance->returnArrayWorks['error'] = 'Не найдена работа'; return false;//self::$_instance->returnArrayWorks; } //var_dump($asusgJob2LaunchEntity->tasks->id); exit; $qu = 1; $parLog = 'jl.asusg_job_uuid' . $job_uuid; $row_last = (new \yii\db\Query()) ->select(['t.assignees_arr','ai.id','t.status','t.id']) //->select(['t.assignees_arr']) ->from('`asusg_job2launch` as `jl`') ->leftJoin('`tasks` as `t`', 'jl.id = t.asusg_job_mapped_id') ->rightJoin('`accounts_internal` as `ai`', 't.assignees_arr = cast(ai.id as char)') ->where(['jl.asusg_job_uuid' => $job_uuid]) //->andWhere(['ai.uuid' => $user_uuid]) ->andWhere(['<>','t.parent_id', 0]) ->all(); if ( 0 == count($row_last) ) { $qu = 2; $parLog = 't.parent_id = '.$asusgJob2LaunchEntity->tasks->id; $row_last = (new \yii\db\Query()) ->select(['t.assignees_arr','t.status','t.id']) //->select(['t.assignees_arr']) //->from('`asusg_job2launch` as `jl`') ->from('`tasks` as `t`', 'jl.id = t.asusg_job_mapped_id') //->rightJoin('`accounts_internal` as `ai`', 't.assignees_arr = cast(ai.id as char)') //->where(['jl.asusg_job_uuid' => $job_uuid]) //->andWhere(['ai.uuid' => $user_uuid]) ->andWhere(['t.parent_id' => $asusgJob2LaunchEntity->tasks->id]) ->all(); } //var_dump($row_last) ; //exit; if ( 0 == count($row_last) ) { self::$_instance->returnArrayWorks['error'] = 'Работа не запланирована'; return false;//self::$_instance->returnArrayWorks; } $countWorks = count($row_last); $countWorksDone = 1; foreach($row_last as $work){ //Logs::addlog(2,'status =>' . $work['status']); if( 5 == $work['status'] ){ $countWorksDone++; } } Logs::addlog(2,'Кол-во команд =>'.count($row_last). ', Сработал запрос №=' . $qu . ', переменная для проверки ' . $parLog); $doneWorks = (int)round((100/$countWorks)* $countWorksDone); Logs::addlog(2,'worksStatusHandler2 =>'.$doneWorks . ': (100/'.$countWorks.')* '.$countWorksDone); if ( 100 != $doneWorks ) { return false; } /* if ( 0 <= $doneWorks ) {//var_dump('asda'); self::$_instance->returnArrayWorks['result'] = true; self::$_instance->returnArrayWorks['int'] = $doneWorks; return self::$_instance->returnArrayWorks; } */ return true;//self::$_instance->returnArrayWorks; //$sqlText = $row_last->createCommand()->getRawSql(); //var_dump($sqlText); //var_dump($doneWorks); //exit; //$workParams = []; //foreach( $listWorks as $work){ // $workParams[] = $work->id_work; // } // return AsusgJob2Launch::find()->where(['in','asusg_job_uuid',$workParams])->all(); } }