logger = new MappingHandlerModel($log); return true; } // запускается периодически через крон public function actionGetworks($company) { $mainMappingModel = new MainMappingModel($company); $GWparams = ['url' => 'http://devplatform.digitaldepot.ru:8085/Thingworx/Things/SMoPPIntegrationLibrary/Services/getUserWorks', 'param' => '', 'login' => 'ПройдаковИА', 'pass' => 'Ip15351112' ]; // список сотрудников онлайн $onlineUser = $mainMappingModel->getOnlineMobileUser($company); if( 0 == count($onlineUser)) { return 'Нет сотрудников онлайн'; } // ПОЛУЧАЮ СПИСОК ПОЛЬЗОВАТЕЛЕЙ ОНЛАЙН + НАПАРНИКИ ПО РАБОТАМ $onlineUserPlus = $mainMappingModel->onlineUserPlus($onlineUser); $mainMappingModel->MappingStart($onlineUserPlus); } public function addWorksInJobPlan($listWorks) { $result = []; if (empty($listWorks)){ return $result; } $arrayIdWorks = []; foreach( $listWorks->data as $work ) { $arrayIdWorks[] = $work; } foreach ($arrayIdWorks as $work){ $asusgJobPlanEntity = new AsusgJobPlan(); $asusgJobPlanEntity->name = $work->work_name; $asusgJobPlanEntity->sections = 'АБВ'; if (!$asusgJobPlanEntity->save()) { $result[] = $asusgJobPlanEntity->errors; } } return $result; } // Добавление не существующих работ в Tasktype ( сверхцикловые ) public function addWorksInTaskType($listWorks, $listIsabsentWorks ) { $result = $listIsabsentWorks; if (empty($listWorks)){ return $result; } $arrayIdWorks = []; foreach( $listWorks->data as $work ) { $arrayIdWorks[] = $work; } foreach ($arrayIdWorks as $work){ $tasktypesEntity = new Tasktypes(); $tasktypesEntity->creator_id = 49 ; $tasktypesEntity->name = $work->work_name ; $tasktypesEntity->description = 'По запросу АСУ СГ: сверхцикловая работа' ; $tasktypesEntity->company = \Yii::$app->request->get('company'); $tasktypesEntity->main_task = 0 ; $tasktypesEntity->confirmtype = 0 ; $tasktypesEntity->time_to_complete_minutes = 61 ; $tasktypesEntity->subtasks = '' ; $tasktypesEntity->letter = 'АБВ' ; if ($tasktypesEntity->save()) { $flag = 0; foreach($result as $task) { if ( $task->work_name == $tasktypesEntity->name ){ $flag = 1; } } if ( 0 == $flag ) { $result[] = $work;//$tasktypesEntity->errors; } } } return $result; } // // новая версия GetworksOnLoco public function GetworksOnLoco($listWorks) { $result = []; if (empty($listWorks)){ return $result; } $arrayResult = []; foreach ($listWorks as $work){ $sectionsEntity = new Sections(); $sectionsEntity->section_number = $work->eq_number; $sectionsEntity->locomotive_series = $work->eq_serie; $sectionsEntity->section_subnumber = $work->section_num; $sectionsEntity->uuid = $work->section_id; $sectionsEntity->diagnostic_map = $work->section_DK; $sectionsEntity->letter = mb_substr($work->section_lit, -1); if (! $sectionsEntity->save()) { continue; } } foreach ($listWorks as $work){ $arrayResult[] = $work->section_id; } $sectionsEntity = Sections::find()->where(['in','uuid',$arrayResult])->asArray()->all(); $arrayResult = []; $arrayResultTemp = []; $arrayIdSerieTemp = []; foreach($sectionsEntity as $sec){ $arrayResult[] = $sec['uuid']; $arrayResultTemp[$sec['uuid']] = $sec; $LocomotiveSeriesEntity = LocomotiveSeries::findOne(['name' => $sec['locomotive_series']]); $arrayIdSerieTemp[$sec['uuid']] = $LocomotiveSeriesEntity->id; } $tempArray = []; foreach($listWorks as $w) { //var_dump(( in_array($w->section_id,$arrayResult)), $w->section_id .' ==', ); if ( in_array($w->section_id,$arrayResult)) { $tempArray[] = $w; $result[$w->section_id] = [ 'info_obj' => $tempArray ,'info'=> $arrayResultTemp[$w->section_id],'id_serie' => $arrayIdSerieTemp[$w->section_id]]; } } return $result; } public function checkMapping($arrProj) { $tempResult = []; $result = []; foreach ( $arrProj as &$proj) { foreach ( $proj['info_obj'] as $work) { $tempResult[] = $work->work_name; } $res = AsusgJobPlan::find()->where(['in', 'name',$tempResult])->all(); $proj['jobplan'] = $res; } return $arrProj; } public function addJobproject($minRes) { $projectTypes = []; foreach ( $minRes as &$proj) { foreach($proj['info_obj'] as $obj){ $repairtypesEntity = Repairtypes::find()->select('id')->where(['name'=> $obj->repair_name])->one(); $projectTypes[] = $repairtypesEntity->id; } $projectTypes = array_unique($projectTypes); foreach ( $projectTypes as $type) { $field = Yii::$app->params['sections_letter'][$proj['info']["letter"]]; $asusgProjectEntity = new AsusgProject(); $asusgProjectEntity->loco_serie_id = $proj['id_serie']; //locomotive_series $asusgProjectEntity->repair_type = $type; // repairtypes name из асусг $asusgProjectEntity->loco_number = $proj['info']["section_number"]; $asusgProjectEntity->$field = $proj['info']["section_subnumber"]; $asusgProjectTypeEntity = AsusgProjectType::findOne(['loco_serie_id' => $proj['id_serie'], 'repair_type' => $type]); $asusgProjectEntity->asusg_projecttype_id = $asusgProjectTypeEntity->id; $asusgProjectEntity->save(); echo "
"; var_dump($asusgProjectEntity->errors); //var_dump("Выполнение процедуры => " . $res); echo ""; $proj['asusgProject_id'] = $asusgProjectEntity->id; $proj['repair_type'] = $type; } } return $minRes; } public function addJob2launch($minRes) { foreach ( $minRes as $proj) { $resultArr = []; $order = 1; foreach ( $proj['jobplan'] as $work) { $sectionTemp = ''; $id_workTemp = ''; foreach($proj['info_obj'] as $obj){ //var_dump(( $obj->work_name == $work->name), $obj->work_name.' =='. $work->name); if( $obj->work_name == $work->name){ $sectionTemp = $obj->section_id; $id_workTemp = $obj->id_work; break; } } $asusgJob2LaunchEntity = new AsusgJob2Launch(); $asusgJob2LaunchEntity->asusg_jobplan_id = $work->id; $asusgJob2LaunchEntity->asusg_employee_id1 = $proj['userInfo']->id; $asusgJob2LaunchEntity->asusg_job_uuid = $id_workTemp; $asusgJob2LaunchEntity->section_uuid = $sectionTemp; $asusgJob2LaunchEntity->asusg_project_id = $proj['asusgProject_id']; $asusgJob2LaunchEntity->job_order = $order; $asusgProjectTypeEntity = AsusgProjectType::findOne(['loco_serie_id' => $proj['id_serie'], 'repair_type' => $proj['repair_type']]); //var_dump($id_workTemp); //var_dump($proj['id_serie'],$proj['repair_type']); //var_dump($asusgProjectTypeEntity->id); $asusgJob2LaunchEntity->asusg_projecttype_id = $asusgProjectTypeEntity->id; $asusgJob2LaunchEntity->save(); echo "
"; var_dump($asusgJob2LaunchEntity->id); var_dump($asusgJob2LaunchEntity->errors); //var_dump($sectionsEntity); echo ""; $order++; } } } 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; } // Сверхцикловые public function addJob2launch2($listWorks,$user) { require_once $_SERVER["DOCUMENT_ROOT"].'/functions.php'; //var_dump(gettype($this->entityManager)); foreach ( $listWorks as $work) { $projtype = $this->getProjectType($work["repair_name"],$work["eq_serie"]); $let = mb_substr($work["section_lit"], -1); $resultArr = []; $asusgJob2LaunchEntity = new AsusgJob2Launch(); $asusgJob2LaunchEntity->asusg_jobplan_id = Yii::$app->params['supercycleplan']; $asusgJob2LaunchEntity->asusg_employee_id1 = $user->id; $asusgJob2LaunchEntity->asusg_job_uuid = $work['id_work']; $asusgJob2LaunchEntity->employees_uuid = $user->id; $asusgJob2LaunchEntity->section_uuid = $work["section_id"]; $asusgJob2LaunchEntity->asusg_project_id = 0; $asusgJob2LaunchEntity->job_order = 0; //$asusgJob2LaunchEntity->asusg_projecttype_id = 0; $asusgJob2LaunchEntity->asusg_projecttype_id = $projtype; if (!$asusgJob2LaunchEntity->save()) { $this->logger->setLog('в Job2launch не добавилась работа => "'. $work['work_name']. '" Добавление работ будет пропущено так как такая запись уже есть.'); continue; } $this->logger->setLog('в Job2launch была добавлена работа => "'. $work['work_name'].'"'); $tasktypesEntity = Tasktypes::find()->where(['name' => 'Секция '.$let.', задача','company' => $this->company])->one(); $tasksEntity = new Tasks(); $tasksEntity->parent_id = 0; $tasksEntity->status = 2; $tasksEntity->type = $tasktypesEntity->id; $tasksEntity->assignees_arr = $user->id; $tasksEntity->created = date("Y-m-d H:i;s"); $tasksEntity->asusg_job_mapped_id = $asusgJob2LaunchEntity->id; if($tasksEntity->save()) { $this->logger->setLog('в Tasks была добавлена ЗАДАЧА => "'. $work['work_name'] . '" id => '.$tasksEntity->id); } else { $this->logger->setLog('в Tasks была НЕ добавлена ЗАДАЧА => "'. $work['work_name'] . '" id => '.$tasksEntity->id); } //var_dump($tasksEntity->errors,$user->id); echo '
"; //var_dump($tasksEntity2->errors,$tasksEntity->errors); //echo ""; } } // Цикловые public function addJob2launch3($listWorks,$user) { require_once $_SERVER["DOCUMENT_ROOT"].'/functions.php'; foreach ( $listWorks as $work) { $projtype = $this->getProjectType($work["repair_name"],$work["eq_serie"]); $JobPlanEntitty = AsusgJobplan::find()->where(['name' => $work["work_name"]])->one(); // 1204 1567 $jsusgJob2CommandEntity = AsusgJob2Command::find()->where(['asusg_job_id' => $JobPlanEntitty->id, 'asusg_projecttype_id' => $projtype ])->all(); /* //echo "
"; //var_dump($JobPlanEntitty->id,$projtype); //var_dump($JobPlanEntitty->id,$jsusgJob2CommandEntity); //echo ""; //continue; $let = mb_substr($work["section_lit"], -1); $resultArr = []; $asusgJob2LaunchEntity = new AsusgJob2Launch(); $asusgJob2LaunchEntity->asusg_jobplan_id = $JobPlanEntitty->id; $asusgJob2LaunchEntity->asusg_employee_id1 = $user->id; $asusgJob2LaunchEntity->asusg_job_uuid = $work['id_work']; $asusgJob2LaunchEntity->employees_uuid = $user->id; $asusgJob2LaunchEntity->section_uuid = $work["section_id"]; $asusgJob2LaunchEntity->asusg_project_id = 0; $asusgJob2LaunchEntity->job_order = 0; $asusgJob2LaunchEntity->asusg_projecttype_id = $projtype; if (!$asusgJob2LaunchEntity->save()) { $this->logger->setLog('в Job2launch не добавилась работа => "'. $work['work_name']. '" Добавление работ будет пропущено так как такая запись уже есть.'); continue; } $this->logger->setLog('в Job2launch была добавлена работа => "'. $work['work_name'].'"'); $tasktypesEntity = Tasktypes::find()->where(['name' => 'Секция '.$let.', задача','company' => $this->company])->one(); $tasksEntity = new Tasks(); $tasksEntity->parent_id = 0; $tasksEntity->status = 2; $tasksEntity->type = $tasktypesEntity->id; $tasksEntity->assignees_arr = $user->id; $tasksEntity->created = date("Y-m-d H:i;s"); $tasksEntity->asusg_job_mapped_id = $asusgJob2LaunchEntity->id; if($tasksEntity->save()) { $this->logger->setLog('в Tasks была добавлена ЗАДАЧА => "'. $work['work_name'] . '" id => '.$tasksEntity->id); } else { $this->logger->setLog('в Tasks была НЕ добавлена ЗАДАЧА => "'. $work['work_name'] . '" id => '.$tasksEntity->id); } //var_dump($tasksEntity->errors,$user->id); echo '
"; var_dump($user->id); var_dump($tasktypesEntity); foreach($tasktypesEntity as $task) { var_dump($task->creator_id); } echo ""; // /* $projId = $this->generateProject3($work); $tasksEntity->input_id = $projId; if ($tasksEntity->save()) { $this->logger->setLog('привязка ЗАДАЧИ ( id = '.$tasksEntity->id.') прошла успешно'); } foreach($arrJ as $job_id) { $tasksEnt = Tasks::findOne($job_id); $tasksEnt->input_id = $projId; if($tasksEnt->save()){ $this->logger->setLog('привязка КОМАНДЫ ( id = '.$tasksEntity2->id.') прошла успешно'); } } //$tasksEntity2->input_id = $projId; //if($tasksEntity2->save()){ // $this->logger->setLog('привязка КОМАНДЫ ( id = '.$tasksEntity2->id.') прошла успешно'); //} echo "
"; //var_dump($job->asusgJob2Launch->asusg_project_id); var_dump($tasksEntity2->errors,$tasksEntity->errors); echo ""; */ } } public function pushProject($minRes) { var_dump(count($minRes)); //var_dump($minRes); foreach ( $minRes as $proj) { $arr = ['initiator' => (int)$proj['userInfo']->id, 'project_id' => (int)$proj['asusgProject_id']]; //$res = \Yii::$app->db->createCommand('call asusg_build_and_start_project('.$arr["initiator"].','.$arr["project_id"].')')->execute(); $res = \Yii::$app->db->createCommand('call asusg_build_and_start_project_auto('.$arr["initiator"].','.$arr["project_id"].')')->execute(); echo "
"; var_dump($arr); var_dump("Выполнение процедуры => " . $res); echo ""; } } public function prepareParams($listWorks) { $result = []; foreach ( $listWorks as $work) { $work['user_id'] = '0f9ed850-e473-11e2-aaad-ac162db0b20c'; $result[] = $work; $result = json_encode($result); return $result;//json_decode($result,false); } //$result = count(); } public function generateProject($work){ $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(); $diagnostic_map = $sectionsEntity->diagnostic_map; if ( null == $sectionsEntity->id) { $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) . ' шт.'); } $diagnostic_map = $sectionsEntity->diagnostic_map; } else if( null == $sectionsEntity->diagnostic_map ) { $sectionsEntity->diagnostic_map = $work['section_DK']; $sectionsEntity->save(); } if ($sectionsEntity->diagnostic_map == $work['section_DK'] ) { $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(); $result = $projectId['id']; $this->logger->setLog('в Sections секция с такой диагностической картой => '. $work['section_DK'] . ' существует. Ид проекта '. $result); } if (!$result) { $projectsLocotech = new ProjectsLocotech(); $projectsLocotech->action = 197 ; $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(); $result = $projectsLocotech->id; $this->logger->setLog('Такого проекта еще не было пришлось создать. Ид проекта => '. $result); } //var_dump($result); return $result; } public function generateProject3($work){ $result = ''; $projectsLocotech = new ProjectsLocotech(); $projectsLocotech->action = 197 ; $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(); $result = $projectsLocotech->id; $this->logger->setLog('Такого проекта еще не было пришлось создать. Ид проекта => '. $result); //var_dump($result); return $result; } }