123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735 |
- <?php
- namespace app\models;
- use Yii;
- use yii\base\Model;
- //use yii\web\Controller;
- //use app\models\MainModel;
- //use app\models\ProcedureModel;
- use app\models\entity\Tasks;
- use app\models\Logs;
- //use app\models\ProjectsModel;
- use app\models\entity\Accounts;
- //use app\models\entity\Sections;
- //use app\models\LocomotiveModel;
- //use app\models\entity\Tasktypes;
- use app\models\logger\LoggerFile;
- use app\models\entity\Checkpoints;
- //use app\models\entity\Repairtypes;
- //use app\models\entity\Projecttypes;
- //use app\models\entity\AsusgProject;
- use app\models\entity\AsusgJobPlan;
- use app\models\MappingHandlerModel;
- use app\models\entity\AsusgJob2Launch;
- use app\models\entity\AsusgMeasurements;
- //use app\models\entity\AsusgProjectType;
- //use app\models\entity\LocomotiveSeries;
- //use app\models\entity\ProjectsLocotech;
- //use app\models\entity\AsusgJob2Command;
- use app\models\procedure\AsusgAddMeasurementToTaskModel;
- use app\models\LogEippResponse;
- class MainMappingModel extends MainModel
- {
- const MAINTASK = 0;
- const TMC = 1;
- const TASK = 2;
- const MAPPINGTYPE = 197
- private static $_instance;
- private $url = 'http://devplatform.digitaldepot.ru:8085/Thingworx/Things/2050UserLibraryExp/Services/';
- private $GWparams = ['login' => 'ПройдаковИА','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 '<pre>';
- //var_dump($user->id,$listWorks2);
- //echo '</pre>';
- }
- 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 '<pre>';
- //var_dump($worker);
- //echo '</pre>';
- }
- }
- }
- }
- $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;
- }
- }
|