'ПройдаковИА','pass' => 'Ip15351112']; private $responseEippMeasurement = ''; public $prepareLogString = ''; public $company; private $launchObj; private $parent_id; private $projId; private $arrStage = [0 => 'ЗАДАЧИ', 1 => 'КОМАНДЫ ТМЦ', 2 => 'КОМАНДЫ']; private $create_task_id; function __construct($company) { $this->company = $company; } // ВОЗВРАЩАЕТ СПИСОК ПОЛЬЗОВАТЕЛЕЙ ОНЛАЙН + НАПАРНИКИ ПО РАБОТАМ // params => $onlineUser: array // // result => array public function onlineUserPlus($onlineUser) { $setOnlineWorkers = []; foreach($onlineUser as $user) { if( '' == $user->uuid and null == $user->uuid) { continue; } $this->GWparams['param'] = $user->uuid; $listWorks2 = json_decode($this->curlRequest2($this->GWparams),true); $listWorks2 = $this->prepareListWorks($listWorks2); foreach ( $listWorks2['data'] as $work) { $mappingapiModel = new \app\models\MappingapiModel(); $this->datailWorkArray[$work['id_work']] = $mappingapiModel->workDetail( $user->uuid, $work['id_work'] ); foreach( $this->datailWorkArray[$work['id_work']]['workers_uuid'] as $uuid) { $setOnlineWorkers[] = $uuid; } } } $setOnlineWorkers = array_unique($setOnlineWorkers); $onlineUserModificate = Accounts::find()->where(['in','uuid',$setOnlineWorkers])->andWhere(['company' => $this->company])->all(); return $onlineUserModificate; } public function MappingStart($onlineUserPlus) { foreach($onlineUserPlus as $user) { $this->GWparams['param'] = $user->uuid; $listWorks2 = json_decode($this->curlRequest2($this->GWparams),true); $listWorks2 = $this->prepareListWorks($listWorks2); $listIsabsentWorks2 = $this->Getisabsentworksjp($listWorks2); // вновь утвержденный план 1 | вернет список работ кот нет ( в JobPlan ) $listIssetWorks3 = $this->Getissetworksjp($listWorks2); $addJob2launch2 = $this->addJob2launch2($listIsabsentWorks2,$user); $addJob2launch3 = $this->addJob2launch3($listIssetWorks3,$user); //echo '
'; //var_dump($user->id,$listWorks2); //echo ''; } return true; } // ВОЗВРАЩАЕТ СПИСОК РАБОТ СВЕРХЦИКЛОВЫХ // params => $listWorks: array // // result => array private function Getisabsentworksjp( $listWorks = null){ $result = []; if ( null == $listWorks) { return false; } foreach( $listWorks['data'] as $work) { $asusgJobPlan = AsusgJobPlan::find()->where(['name' => $work['work_name']])->one(); if ( null == $asusgJobPlan ){ $result[] = $work; } } return $result; } // ВОЗВРАЩАЕТ СПИСОК РАБОТ ЦИКЛОВЫХ // params => $listWorks: array // // result => array private function Getissetworksjp( $listWorks = null){ $result = []; if ( null == $listWorks) { return false; } foreach( $listWorks['data'] as $work) { $asusgJobPlan = AsusgJobPlan::find()->where(['name' => $work['work_name']])->one(); if ( null != $asusgJobPlan ){ $result[] = $work; } } return $result; } // ВОЗВРАЩАЕТ СПИСОК СОТРУДНИКОВ ОНЛАЙН // params => $listWorks: integer // // result => array public function getOnlineMobileUser(){ $result = []; $accountsEntity = Accounts::find()->where(['company' => $this->company])->all(); foreach ($accountsEntity as $account) { $last_seen_mobile = ( null != $account->last_seen_mobile )? new \DateTime($account->last_seen_mobile): $account->last_seen_mobile ; $online_mobile = $this->OnlineAccountCheck($this->TimeString($last_seen_mobile)); if ( !$online_mobile ){ continue; } $result[] = $account; } return $result; } public function OnlineAccountCheck($last_seen) { $last_seen = date($last_seen); $time = (time()-strtotime($last_seen)); if ($time <= Yii::$app->params['onlineMobileTimeoutSeconds']) return true; return false; } public function TimeString($timeobj) { if ($timeobj != null) return $timeobj->format('d.m.Y H:i'); } public function getProjectType($repairName,$serieName) { $result = null; $repairtypesEntity = Repairtypes::findOne(['name' => $repairName]); $locomotiveSeriesEntity = LocomotiveSeries::findOne(['name' => $serieName]); $asusgProjectTypeEntity = AsusgProjectType::findOne(['repair_type' => $repairtypesEntity->id , 'loco_serie_id' => $locomotiveSeriesEntity->id]); if ( null != $asusgProjectTypeEntity->id ) { $result = $asusgProjectTypeEntity->id; } return $result; } private function prepareListWorks($listWorks) { $result = []; $dataArr = []; if ( null == $listWorks || empty($listWorks)) { return []; } foreach ( $listWorks["rows"] as $rows) { $rows["result"] = json_decode($rows["result"],true); foreach ( $rows["result"]['data'] as $key => $data) { $tempArray = []; $tempArray["eq_serie"] = explode(" ",$data["equip_sect_name"])[0]; $eq = explode(" ",$data["equip_sect_name"])[1]; $tempArray["eq_number"] = explode("/",$eq)[0]; foreach ( $data["sections"] as $sections) { $tempArray["section_id"] = $sections["id_section"]; $tempArray["section_lit"] = $sections["section_name"]; $tempArray["section_num"] = $sections["section_subnumber"]; $tempArray["section_DK"] = $sections["section_dk"]; foreach ( $sections['works'] as $work) { $tempArray["id_work"] = $work["id_work"]; $tempArray["outfit"] = $work["outfit"]; $tempArray["work_name"] = $work["work_name"]; $tempArray["repair_name"] = $work["repair_type"]; $tempArray["work_status"] = $work["work_status"]; $tempArray["repeats"] = $work["repeats"]; $dataArr[] = $tempArray; foreach ( $works['workers'] as $worker) { //echo '
'; //var_dump($worker); //echo ''; } } } } $result['result'] = 'true'; $result['data'] = $dataArr; break; } return $result; } private function AddAsusgJob2Launch( $work, $dwResult, $user, $projtype, $jobPlan = null ) { $jp = Yii::$app->params['supercycleplan']; if (!$jobPlan){ $jp = $jobPlan; } $asusgJob2LaunchEntity = new AsusgJob2Launch(); $asusgJob2LaunchEntity->asusg_jobplan_id = $jp; // + $asusgJob2LaunchEntity->asusg_employee_id1 = $user->id; // + $asusgJob2LaunchEntity->asusg_job_uuid = $work['id_work']; // + $asusgJob2LaunchEntity->employees_uuid = $user->uuid; // + $asusgJob2LaunchEntity->section_uuid = $work["section_id"]; // + $asusgJob2LaunchEntity->asusg_project_id = 0; // + $asusgJob2LaunchEntity->job_order = 0; // + $asusgJob2LaunchEntity->time_limit = $dwResult['time_limit']; // + $asusgJob2LaunchEntity->outfit = $dwResult['outfit']; // + $asusgJob2LaunchEntity->name = $dwResult['work_name']; // + $asusgJob2LaunchEntity->section_name = $work["section_lit"]; // + $asusgJob2LaunchEntity->asusg_projecttype_id = $projtype; if ( $asusgJob2LaunchEntity->save() ) { $this->launchObj = $asusgJob2LaunchEntity; return true; } else { return false; } } // Добавление задачи // params => $works: array ( инфо о работе ) // $tasktypesEntity: integer ( тип работы id-шник) // $user object ( инфо о пользователе ) // $dwResult array ( инфо детализация о работе ) // $stage: integer ( это команда на ТМЦ или 1 да /0 нет ) // $parent_id: integer ( 0 == задача / 0 <> команда) // // result => array $tasksEntity2->asusg_job_mapped_id = $job->jobplantie->id; $tasksEntity2->text = $work["eq_serie"] . ' '.$work["section_lit"] . ', '. $work["outfit"] . ':' . $work['work_name']; $tasksEntity2->mapping_comment = $work["outfit"] . ': ' . $work['work_name']; private function addTasks($work, $tasktypesEntity, $launch_id = null, $stage = 0, $parent_id = 0 ) { $result = false; $type = $tasktypesEntity; $tasksEntity = new Tasks(); $tasksEntity->input_id = $this->projId; $tasksEntity->parent_id = $parent_id; // + $tasksEntity->status = 2; // + $tasksEntity->type = $type; // + $tasksEntity->assignees_arr = $work['user_info']->id; // + $tasksEntity->created = date("Y-m-d H:i;s"); // + $tasksEntity->asusg_job_mapped_id = ( is_object($this->launchObj) ) ? $this->launchObj->id : null ; // + $tasksEntity->priority = Yii::$app->params['countPriority']; $tasksEntity->text = $work["eq_serie"] . ' '.$work["section_lit"] . ', '. $work["outfit"] . ': ' . $work['work_name']; $tasksEntity->mapping_comment = $work["outfit"] . ': ' . $work['work_name']; if ( self::TMC == $stage) { $tasksEntity->text = $work['dwResult']['tmcString']; // + $tasksEntity->mapping_comment = $work['dwResult']['tmcString']; // + } if ( self::MAINTASK == $stage ) { $tasksEntity->priority = 0; $tasksEntity->mapping_comment = $work["outfit"] . ': ' . $work['work_name']; // + $tasksEntity->text = $work["section_lit"] . "\n" . $work["outfit"] . ': ' . $work['work_name'] . "\n" . $work['dwResult']['workers'];// + } if($tasksEntity->save()) { $this->create_task_id = $tasksEntity->id; if ( self::MAINTASK == $stage ) { $this->parent_id = $tasksEntity->id; // присвоение ид ЗАДАЧИ } $this->logger->setLog('привязка ' . $this->arrStage[$stage] . ' ( id = '.$tasksEntity->id.') прошла успешно.'); $result = true; } Yii::$app->params['countPriority']++; return $result; } public function addJob2launch2($listWorks,$user) { foreach ( $listWorks as $work) { $dwResult = $this->datailWorkArray[$work['id_work']]; $work['user_info'] = $user; $work['dwResult'] = $dwResult; $this->prepareLogString .= "Название работы:". $work['work_name']. ".\n UUID работы: " . $work['id_work'] . "\n\n"; $this->prepareLogString .= "\n 1. ДОБАВЛЕНИЕ В LAUNCH \n\n"; $asusgJob2LaunchEntity = AsusgJob2Launch::findOne(['asusg_job_uuid' => $work['id_work']]); $let = mb_substr($work["section_lit"], -1); // ВАЖНО ПОНИМАТЬ !!!! // если проект для такой работы уже есть, его создавать нельзя // но можно прикреплять к нему задачи. Сотрудник который зашел первый получает и замеры и тмц и работы // тот кто зашел вторым получает только работы. $projtype = $this->getProjectType($work["repair_name"],$work["eq_serie"]); $switcher = $asusgJob2LaunchEntity; if ( null == $switcher) { $AsusgJob2LaunchRes = $this->AddAsusgJob2Launch($work, $dwResult, $user, $projtype); if ( !$AsusgJob2LaunchRes ) { $this->logger->setLog('в Job2launch не добавилась работа => "'. $work['work_name']. '" Добавление работ будет пропущено так как такая запись уже есть.'); continue; } $this->logger->setLog($this->prepareLogString); $this->prepareLogString = ''; $this->logger->setLog('в Job2launch была добавлена работа => "'. $work['work_name'].'"'); /// сначала генерю проект $this->projId = $this->generateProject($work); } else { $this->prepareLogString .= "ВОТ ТУТ Я ХОТЕЛ ПОЛУЧИТЬ ИД ПРОЕКТА ЧЕРЕЗ ЗАДАЧУ( launch_id = ".$asusgJob2LaunchEntity->id.") => " . $asusgJob2LaunchEntity->tasks->id .", ВОТ ЧТО ПОЛУЧИЛ => " . $this->launchObj->tasks->input_id ."!\n"; $this->projId = $this->launchObj->tasks->input_id; } /////////////// ДОБАВЛЕНИЕ ЗАДАЧИ $this->prepareLogString .= "\n 3. ДОБАВЛЕНИЕ ЗАДАЧИ \n\n"; $tasktypesEntity = Tasktypes::find()->where(['name' => 'Секция '.$let.', задача','company' => $this->company])->one(); $tasksEnt = Tasks::find()->where(['parent_id' => 0,'asusg_job_mapped_id' => $asusgJob2LaunchEntity->id,'assignees_arr' => $user->id])->one(); if ( null != $tasksEnt) { continue; } $this->logger->setLog($this->prepareLogString); $this->prepareLogString = ''; $addTasksRes = $this->addTasks($work, $tasktypesEntity->id, $this->launchObj->id, 0, 0 ); if( $addTasksRes ) { $this->testIdpl2 = $tasksEntity->id; $this->logger->setLog('в Tasks была добавлена ЗАДАЧА => "'. $work['work_name'] . '" id => '.$tasksEntity->id); } else { $this->logger->setLog('в Tasks была НЕ добавлена ЗАДАЧА => "'. $work['work_name'] . '" id => '.$tasksEntity->id); } if ( null == $switcher) { ///////////////// ДОБАВЛЕНИЕ ТМЦ $this->logger->setLog("\n ДОБАВЛЕНИЕ ТМЦ " . strlen($dwResult['tmcString']) . "\n"); if ( '' != $dwResult['tmcString']) { $addTasksTMC = $this->addTasks($work, 2159, $this->launchObj->id, 1, $this->parent_id ); if ( $addTasksTMC ) { $query3 = "call asusg_add_checkpoints_to_task(" . $user->id . ",'" . $tasksEntity3->id . "')"; $resProc = Yii::$app->db->createCommand($query3)->query(); $logResProc = 'false'; if ($resProc){ $logResProc = 'true'; } $this->logger->setLog('в Tasks была добавлена КОМАНДА => "'. $work['work_name'] . '" id => '.$tasksEntity3->id. ' процедура => ' . $logResProc . ' приоритет =>' . Yii::$app->params['countPriority']); } else { $this->logger->setLog('в Tasks была НЕ добавлена КОМАНДА => "'. $work['work_name'] . '" id => '.$tasksEntity3->id ); } } ///////////////// ДОБАВЛЕНИЕ ЗАМЕРОВ ЭТАП 0 $this->logger->setLog( "\n 4. ДОБАВЛЕНИЕ ЗАМЕРОВ ЭТАП 0 \n"); //if ( Yii::$app->params['api']['hw_msrmnt_stat'][ $dwResult["hw_measurements_status"] ]) { // выполнение hw_measurements_status = waiting $paramsMeaserm = ['input_id' => $projId, 'assignees_arr' => $user->id, 'work' => $work,'stage' => 0, 'parent_id' => $tasksEntity->id , 'stage_type' => 'доремонтный','asusg_job_mapped_id' => $asusgJob2LaunchEntity->id ]; Yii::$app->params['api']['mesrmntParam'] = $paramsMeaserm; MappingapiModel::workMeasurements($work['id_work'],$user->uuid); //} } /////////////// НА РЕМОНТ $this->logger->setLog("\n 5. ДОБАВЛЕНИЕ НА РЕМОНТ \n"); $addTasksJob = $this->addTasks($work, Yii::$app->params['supercycletype'], $this->launchObj->id, 2, $this->parent_id ); if ( $addTasksJob ) { $this->logger->setLog('в Tasks была добавлена КОМАНДА => "'. $work['work_name'] . '" id => '.$tasksEntity2->id . ' приоритет =>' . Yii::$app->params['countPriority']); } else { $this->logger->setLog('в Tasks была НЕ добавлена КОМАНДА => "'. $work['work_name'] . '" id => '.$tasksEntity2->id); } if ( null == $switcher) { ///////////////// ДОБАВЛЕНИЕ ЗАМЕРОВ ЭТАП 1 $this->logger->setLog("\n 6. ДОБАВЛЕНИЕ ЗАМЕРОВ ЭТАП 1 \n"); //if ( Yii::$app->params['api']['hw_msrmnt_stat'][ $dwResult["hw_measurements_status"] ]) { // выполнение hw_measurements_status = waiting $paramsMeaserm['asusg_job_mapped_id' => $asusgJob2LaunchEntity->id, 'stage_type' => 'контрольный','stage' => 1]; Yii::$app->params['api']['mesrmntParam'] = $paramsMeaserm; MappingapiModel::workMeasurements($work['id_work'],$user->uuid); //} ///////////////// ДОБАВЛЕНИЕ ЗАМЕРОВ ЭТАП 2 $this->logger->setLog("\n 7. ДОБАВЛЕНИЕ ЗАМЕРОВ ЭТАП 2 \n"); //if ( Yii::$app->params['api']['hw_msrmnt_stat'][ $dwResult["hw_measurements_status"] ]) { // выполнение hw_measurements_status = waiting $paramsMeaserm['asusg_job_mapped_id' => $asusgJob2LaunchEntity->id, 'stage_type' => 'послеремонтный', 'stage' => 2]; Yii::$app->params['api']['mesrmntParam'] = $paramsMeaserm; MappingapiModel::workMeasurements($work['id_work'],$user->uuid); //} } Yii::$app->params['countPriority'] = 1; } } public function addJob2launch3($listWorks,$user) { foreach ( $listWorks as $work) { $dwResult = $this->datailWorkArray[$work['id_work']]; $work['user_info'] = $user; $work['dwResult'] = $dwResult; $this->prepareLogString .= "\n 1. ДОБАВЛЕНИЕ В LAUNCH \n\n"; $asusgJob2LaunchEntity = AsusgJob2Launch::findOne(['asusg_job_uuid' => $work['id_work']]); $let = mb_substr($work["section_lit"], -1); // ВАЖНО ПОНИМАТЬ !!!! // если проект для такой работы уже есть, его создавать нельзя // но можно прикреплять к нему задачи. Сотрудник который зашел первый получает и замеры и тмц и работы // тот кто зашел вторым получает только работы. $projtype = $this->getProjectType($work["repair_name"],$work["eq_serie"]); $JobPlanEntitty = AsusgJobplan::find()->where(['name' => $work["work_name"]])->one(); // 1204 1567 if ( null == $JobPlanEntitty->id ) { $this->prepareLogString .= " ВНИМАНИЕ не нашел работу в AsusgJobplan ('name' => ".$work['work_name'].")\n\n"; } $jsusgJob2CommandEntity = AsusgJob2Command::find()->where(['asusg_job_id' => $JobPlanEntitty->id, 'asusg_projecttype_id' => $projtype ])->all(); $switcher = $asusgJob2LaunchEntity; if ( null == $switcher) { $AsusgJob2LaunchRes = $this->AddAsusgJob2Launch($work, $dwResult, $user, $projtype, $JobPlanEntitty->id); // ADD LAUNCH if (!$AsusgJob2LaunchRes) { $this->logger->setLog('в Job2launch не добавилась работа => "'. $work['work_name']. '" Добавление работ будет пропущено так как такая запись уже есть.'); continue; } $this->issetLaunch = true; $this->logger->setLog($this->prepareLogString); $this->prepareLogString = ''; $this->logger->setLog('в Job2launch была добавлена работа => "'. $work['work_name'].'"'); /// сначала генерю проект $projId = $this->generateProject($work); } else { $this->prepareLogString .= "ВОТ ТУТ Я ХОТЕЛ ПОЛУЧИТЬ ИД ПРОЕКТА ЧЕРЕЗ ЗАДАЧУ => " . $asusgJob2LaunchEntity->tasks->id .", ВОТ ЧТО ПОЛУЧИЛ => " . $asusgJob2LaunchEntity->tasks->input_id ."!\n"; $projId = $asusgJob2LaunchEntity->tasks->input_id; } /////////////// ДОБАВЛЕНИЕ ЗАДАЧИ $this->prepareLogString .= "\n 3. ДОБАВЛЕНИЕ ЗАДАЧИ \n\n"; $tasktypesEntity = Tasktypes::find()->where(['name' => 'Секция '.$let.', задача','company' => $this->company])->one(); $tasksEnt = Tasks::find()->where(['parent_id' => 0,'asusg_job_mapped_id' => $asusgJob2LaunchEntity->id,'assignees_arr' => $user->id])->one(); if ( null != $tasksEnt) { continue; } $this->logger->setLog($this->prepareLogString); $this->prepareLogString = ''; $addTasksRes = $this->addTasks($work, $tasktypesEntity->id, 0, 0 ); if($addTasksRes) { $this->logger->setLog('в Tasks была добавлена ЗАДАЧА => "'. $work['work_name'] . '" id => '.$tasksEntity->id); } else { $this->logger->setLog('в Tasks была НЕ добавлена ЗАДАЧА => "'. $work['work_name'] . '" id => '.$tasksEntity->id); } $this->logger->setLog(' колво записей => ' . count($jsusgJob2CommandEntity) . 'type => '. gettype($jsusgJob2CommandEntity)); $arrJ = []; if ( null == $switcher) { $this->logger->setLog("switcher = null"); ///////////////// ДОБАВЛЕНИЕ ТМЦ $mappingapiModel = new \app\models\MappingapiModel(); $this->logger->setLog("сотрудник => " . $user->uuid . ", работа => " . $work['id_work']); $tmcString = $mappingapiModel->workDetail($user->uuid,$work['id_work']); $this->logger->setLog("\n ДОБАВЛЕНИЕ ТМЦ " . strlen($dwResult['tmcString']) . "\n"); if ( '' != $dwResult['tmcString']) { $addTasksTMC = $this->addTasks($work, 2159, 1, $this->parent_id ); if ( $addTasksTMC ) { var_dump('создана ТМЦ, задача =>' . $this->create_task_id); $arrJ[] = $this->create_task_id; $query3 = "call asusg_add_checkpoints_to_task(" . $user->id . ",'" . $this->create_task_id . "')"; $resProc = Yii::$app->db->createCommand($query3)->query(); $logResProc = 'false'; if ( $resProc ){ $logResProc = 'true'; } $this->logger->setLog('в Tasks была добавлена КОМАНДА => "'. $work['work_name'] . '" id => ' . $this->create_task_id. ' процедура => ' . $logResProc); } else { var_dump('не создана ТМЦ'); $this->logger->setLog('в Tasks была НЕ добавлена КОМАНДА => "'. $work['work_name'] . '" id => ' . $this->create_task_id ); } } ///////////////// ДОБАВЛЕНИЕ ЗАМЕРОВ ЭТАП 0 $this->logger->setLog("\n 4. ДОБАВЛЕНИЕ ЗАМЕРОВ ЭТАП 0 \n"); //if ( Yii::$app->params['api']['hw_msrmnt_stat'][ $dwResult["hw_measurements_status"] ]) { // выполнение hw_measurements_status = waiting $paramsMeaserm = ['input_id' => $projId, 'assignees_arr' => $user->id, 'work' => $work,'stage' =>0, 'parent_id' => $tasksEntity->id ,'stage_type' => 'доремонтный','asusg_job_mapped_id' => $asusgJob2LaunchEntity->id]; Yii::$app->params['api']['mesrmntParam'] = $paramsMeaserm; MappingapiModel::workMeasurements($work['id_work'],$user->uuid); //} } /////////////// НА РЕМОНТ $this->logger->setLog("\n 5. ДОБАВЛЕНИЕ НА РЕМОНТ \n"); foreach($jsusgJob2CommandEntity as $job) { $tasksEntity2 = new Tasks(); $tasksEntity2->parent_id = $tasksEntity->id; $tasksEntity2->status = 2; $tasksEntity2->priority = Yii::$app->params['countPriority']; $tasksEntity2->input_id = $projId; $tasksEntity2->created = date("Y-m-d H:i;s"); $tasksEntity2->type = $job->smopp_cmd_id; $tasksEntity2->assignees_arr = $user->id; $tasksEntity2->asusg_job_mapped_id = $job->jobplantie->id; $tasksEntity2->text = $work["eq_serie"] . ' '.$work["section_lit"] . ', '. $work["outfit"] . ':' . $work['work_name']; $tasksEntity2->mapping_comment = $work["outfit"] . ': ' . $work['work_name']; if ( $tasksEntity2->save()) { $arrJ[] = $this->create_task_id; $this->logger->setLog('в Tasks была добавлена КОМАНДА => "'. $work['work_name'] . '" id => '.$tasksEntity2->id); } else { $this->logger->setLog('в Tasks была НЕ добавлена КОМАНДА => "'. $work['work_name'] . '" id => '.$tasksEntity2->id); } Yii::$app->params['countPriority']++; } foreach($arrJ as $job_id) { $tasksEnt = Tasks::findOne($job_id); $tasksEnt->input_id = $tasksEnt->input_id ?? $projId; if($tasksEnt->save()){ $this->logger->setLog('привязка КОМАНДЫ ( id = '.$tasksEntity2->id.') прошла успешно'); } else { $this->logger->setLog('привязка КОМАНДЫ ( id = '.$tasksEntity2->id.') прошла не успешно'); } } if ( null == $switcher) { ///////////////// ДОБАВЛЕНИЕ ЗАМЕРОВ ЭТАП 1 $this->logger->setLog("\n 6. ДОБАВЛЕНИЕ ЗАМЕРОВ ЭТАП 1 \n"); //if ( Yii::$app->params['api']['hw_msrmnt_stat'][ $dwResult["hw_measurements_status"] ]) { // выполнение hw_measurements_status = waiting $paramsMeaserm['asusg_job_mapped_id' => $asusgJob2LaunchEntity->id, 'stage_type' => 'контрольный', 'stage' => 1]; Yii::$app->params['api']['mesrmntParam'] = $paramsMeaserm; MappingapiModel::workMeasurements($work['id_work'],$user->uuid); //} ///////////////// ДОБАВЛЕНИЕ ЗАМЕРОВ ЭТАП 2 $this->logger->setLog("\n 7. ДОБАВЛЕНИЕ ЗАМЕРОВ ЭТАП 2 \n"); //if ( Yii::$app->params['api']['hw_msrmnt_stat'][ $dwResult["hw_measurements_status"] ]) { // выполнение hw_measurements_status = waiting $paramsMeaserm['asusg_job_mapped_id' => $asusgJob2LaunchEntity->id, 'stage_type' => 'послеремонтный','stage' => 2]; Yii::$app->params['api']['mesrmntParam'] = $paramsMeaserm; MappingapiModel::workMeasurements($work['id_work'],$user->uuid); //} } } } private function generateProject($work){ $this->logger->setLog("\n 2. ГЕНЕРАЦИЯ ПРОЕКТА \n"); $result = ''; $let = mb_substr($work["section_lit"], -1); $sectionsEntity = Sections::find()->select(['id', 'diagnostic_map']) ->where(['locomotive_series' => $work["eq_serie"],'section_number' => mb_substr($work['section_lit'],0,-1),'letter' => $let]) ->one(); $this->logger->setLog("Параметры локомотива locomotive_series => " . $work["eq_serie"]. ", section_number => " . $work['section_lit'] . " ,letter => " .$let. " \n"); $diagnostic_map = $sectionsEntity->diagnostic_map; if ( null == $sectionsEntity->id) { $sectionsEntity = addNewSection($work); } else if( null == $sectionsEntity->diagnostic_map ) { $sectionsEntity->diagnostic_map = $work['section_DK']; $sectionsEntity->save(); } if ($sectionsEntity->diagnostic_map == $work['section_DK'] ) { $result = getProjectId($work); $this->logger->setLog('в Sections секция с такой диагностической картой => '. $work['section_DK'] . ' существует. Ид проекта '. $result); } if (!$result) { $result = addProjectLocotech($work); $this->logger->setLog('Такого проекта еще не было пришлось создать. Ид проекта => '. $result); } return $result; } private function prepareListWorks($listWorks) { $result = []; $dataArr = []; if ( null == $listWorks || empty($listWorks)) { return []; } foreach ( $listWorks["rows"] as $rows) { $rows["result"] = json_decode($rows["result"],true); foreach ( $rows["result"]['data'] as $key => $data) { $tempArray = []; $tempArray["eq_serie"] = explode(" ",$data["equip_sect_name"])[0]; $eq = explode(" ",$data["equip_sect_name"])[1]; $tempArray["eq_number"] = explode("/",$eq)[0]; foreach ( $data["sections"] as $sections) { $tempArray["section_id"] = $sections["id_section"]; $tempArray["section_lit"] = $sections["section_name"]; $tempArray["section_num"] = $sections["section_subnumber"]; $tempArray["section_DK"] = $sections["section_dk"]; foreach ( $sections['works'] as $work) { $tempArray["id_work"] = $work["id_work"]; $tempArray["outfit"] = $work["outfit"]; $tempArray["work_name"] = $work["work_name"]; $tempArray["repair_name"] = $work["repair_type"]; $tempArray["work_status"] = $work["work_status"]; $tempArray["repeats"] = $work["repeats"]; $dataArr[] = $tempArray; } } } $result['result'] = 'true'; $result['data'] = $dataArr; break; } return $result; } private function addNewSwction($work) { $let = mb_substr($work["section_lit"], -1); $sectionsEntity = new Sections(); $sectionsEntity->locomotive_series = $work["eq_serie"]; $sectionsEntity->section_number = mb_substr($work['section_lit'],0,-1); $sectionsEntity->section_subnumber = $work["section_num"]; $sectionsEntity->diagnostic_map = $work["section_DK"]; $sectionsEntity->uuid = $work["section_id"]; $sectionsEntity->letter = $let; if ( $sectionsEntity->save()) { $this->logger->setLog('в Sections была добавлена новая секция => '. $work["section_num"] . ' id => '.$sectionsEntity->id); } else { $this->logger->setLog('в Sections при добавлении секции произошли ошибки => '. count($sectionsEntity->errors) . ' шт.'); } return $sectionsEntity; } private function getProjectId($work) { $let = mb_substr($work["section_lit"], -1); $query = "select pl.id from projects_locotech pl inner join tasks t on pl.id = t.input_id left join tasktypes tt on t.type = tt.id where pl.company = " . $this->company . " and pl.loco_type = '" . $work["eq_serie"] . "' and pl.loco_number = " . $work["eq_number"] . " and t.parent_id = 0 and tt.letter like '%" . $let . "%' and pl.uuid like '%" . $work['repair_name']. ",%' order by pl.id desc limit 1"; $projectId = Yii::$app->db->createCommand($query)->queryOne(); return $projectId['id']; } private function addProjectLocotech($work) { $projectsLocotech = new ProjectsLocotech(); $projectsLocotech->action = self::MAPPINGTYPE; $projectsLocotech->company = $this->company; $projectsLocotech->status = 2; $projectsLocotech->loco_type = $work["eq_serie"]; $projectsLocotech->loco_number = $work["eq_number"]; $projectsLocotech->depo ='' ; $projectsLocotech->depo_service = ''; $projectsLocotech->created = date('Y-m-d H:i:s'); $projectsLocotech->urgent = 0; $projectsLocotech->uuid = $work['work_name'].":".$work['repair_name'].",".$work["eq_serie"]; $projectsLocotech->save(); return $projectsLocotech->id; } }