1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663 |
- <?php
- namespace app\controllers;
- use app\models\ElasticLog;
- use Yii;
- use app\models\Logs;
- use yii\web\Controller;
- use app\models\MainModel;
- use app\models\QueueModel;
- use app\models\ProcedureModel;
- use app\models\entity\Tasks;
- use app\models\logger\LoggerDB;
- use app\models\entity\Sections;
- use app\models\LocomotiveModel;
- use app\models\MappingapiModel;
- use app\models\entity\Tasktypes;
- use \app\models\LogEippResponse;
- use app\models\logger\LoggerFile;
- use app\models\entity\Repairtypes;
- use app\models\entity\AsusgJobPlan;
- use app\models\MappingHandlerModel;
- use app\models\entity\AsusgJob2Launch;
- use app\models\entity\AsusgProjectType;
- use app\models\entity\LocomotiveSeries;
- use app\models\entity\ProjectsLocotech;
- use app\models\entity\AsusgJob2Command;
- use app\models\Mywork;
- use app\models\Workworker;
- class MappinghandlermwnewController extends Controller
- {
- private $logger;
- private $company;
- private $sectionList;
- private $testIdpl2;
- private $testIdpl3;
- private $datailWorkArray = [];
- private $locoGetInfoArray = [];
- private $statusMaintask;
- private $logEtn;
- private $prepareLogString = '';
- private $issetLaunch = false;
- private $listWorkForExtraArray = [];
- private $createProjects = [];
- private $url = '/Thingworx/Things/2050UserLibraryExp/Services/';
- private $user;
-
- public function beforeAction($action)
- {
- parent::beforeAction($action);
- $logEtn = new Logs();
- $logEtn->index_t = strtotime(date("Y-m-d H:i:s"));
- $logEtn->section = 3;
-
-
- $log = new LoggerDB();
-
- $this->logger = new MappingHandlerModel($log);
- return true;
- }
-
-
-
- public function actionGetworks($company)
- {
-
-
-
- $this->company = $company;
- $GWparams = [
- 'url' => 'http://' . Yii::$app->params['api']['domain'].'/Thingworx/Things/2050UserLibraryExp/Services/my_works',
-
- 'param' => '',
- 'login' => 'ПройдаковИА',
- 'pass' => 'Ip15351112'
- ];
-
- $onlineUser = $this->getOnlineMobileUser($company);
- if( 0 == count($onlineUser)) {
- return 'Нет сотрудников онлайн';
- }
-
-
- $this->logger->setLog( "\n=================== СТАРТ МЕППИНГА ==================================\n");
-
- $this->logger->setLog( date("Y-m-d H:i:s") . "\n");
-
- $mainModel = new MainModel();
-
- $setOnlineWorkers = [];
- $this->logger->setLog( "Колличество cотрудников онлайн :" . count($onlineUser) ."\n");
- foreach($onlineUser as $user) {
- $this->logger->indx = $user->uuid;
-
- $buisy = $this->buisyEmployee($user);
- if( $buisy || ('' == $user->uuid and null == $user->uuid )) {
- var_dump('Занят => '.$user->name,'<br>'.$user->id);
-
-
- }
-
- $GWparams['param'] = $user->uuid;
- $responseMyWorks = $mainModel->curlRequest2($GWparams);
- $listWorks2 = json_decode($responseMyWorks,true);
- $listWorks2 = $this->prepareListWorks($listWorks2);
- $this->insertEippJob($listWorks2);
-
-
-
-
-
-
-
- foreach ( $listWorks2['data'] as $work) {
-
- foreach( $work['workers'] as $key => $uuid) {
- $this->attachWorkUser($work['id_work'],$uuid['id']);
-
- }
- $asusgJob2LaunchEntity = AsusgJob2Launch::find()->where(['asusg_job_uuid' => $work['id_work']])->andWhere(['like','employees_uuid',$user->uuid])->one();
- if ( null != $asusgJob2LaunchEntity) {
-
- continue;
- }
-
- $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 = \app\models\entity\Accounts::find()->where(['in','uuid',$setOnlineWorkers])->andWhere(['company' =>$company])->all();
- $this->logger->setLog( "Колличество cотрудников онлайн для них есть работа ( с напарниками ):" . count($setOnlineWorkers)."\n");
-
- foreach($onlineUserModificate as $user) {
- $this->logger->indx = $user->uuid;
- $this->user = $user;
-
-
- $this->logger->setLog( "\n Сотрудник =>".$user->name.". Его uuid = ".$user->uuid." \n" );
-
- $buisy = $this->buisyEmployee($user);
- if( $buisy || ('' == $user->uuid and null == $user->uuid )) {
-
- continue;
- }
- $this->issetLaunch = false;
- $GWparams['param'] = $user->uuid;
- ElasticLog::eipp($GWparams, 'my_works', 0);
- $listWorks2 = $mainModel->curlRequest2($GWparams);
- $unixTime = time();
- LogEippResponse::addLog($unixTime.'gw'. $user->id ,$listWorks2,'Получение работ от ЕИПП');
- ElasticLog::eipp($listWorks2, 'my_works', 0, false);
- $this->logger->setLog( "\nMY_WORK =====>\n" );
- $this->logger->setLog("Параметры: \n user_id =>". $GWparams['param'] .".\n");
- $this->logger->setLog( "Строка запроса : \n " . $GWparams['url'] .".\n");
- $this->logger->setLog("Вот тут можно посмотреть что ЕИПП прислал по запросу http://dev.prmsys.net/api/mappinghandler/eippresponse?indx=".$unixTime."\n");
- $this->logger->setLog("MY_WORK ======>\n\n");
- $listWorks2 = json_decode($listWorks2,true);
- $listWorks2 = $this->prepareListWorks($listWorks2);
-
-
-
-
-
-
- $this->logger->setLog("Колличество работ из еипп: ". count($listWorks2['data'])." \n Cотрудник:" . $user->id . "( ". $user->name ." )\n");
- echo "Колличество работ из еипп: ". count($listWorks2['data'])." \n Cотрудник:" . $user->id . "( ". $user->name ." )\n";
-
- $listIsabsentWorks2 = $this->Getisabsentworksjp($listWorks2);
-
- $listIssetWorks3 = $this->Getissetworksjp($listWorks2);
- $this->logger->setLog('Колличество работ из еипп ( сверхциклвая ): '. count($listIsabsentWorks2)."\n");
- $this->logger->setLog('Колличество работ из еипп ( цикловая ): '. count($listIssetWorks3)."\n");
- $this->logger->setLog("\n СВЕРХЦИКЛОВЫЕ \n\n");
- var_dump('Колличество работ из еипп ( цикловая ): '. count($listIssetWorks3)."\n");
- var_dump('Колличество работ из еипп ( сверхциклвая ): '. count($listIsabsentWorks2)."\n");
- $addJob2launch2 = $this->addJob2launch2($listIsabsentWorks2,$user);
- $this->logger->setLog("\n ЦИКЛОВЫЕ \n\n");
- $addJob2launch3 = $this->addJob2launch3($listIssetWorks3,$user);
- if(!empty($this->listWorkForExtraArray)){
- $this->logger->setLog("\n СВЕРХЦИКЛОВЫЕ (ДОП) \n\n");
- $this->addJob2launch2($this->listWorkForExtraArray,$user);
- $this->listWorkForExtraArray = [];
- }
-
-
- if (!$this->issetLaunch) {
- continue;
- }
-
- $this->logger->setLog("Интеграция сверхцикловых работ прошла без падений!");
- $this->logger->setLog("=====================================================\n\n");
-
-
-
-
-
-
-
-
- }
- $this->fixPriority(1);
- $this->clearEmptyProjects();
- return true;
-
- }
-
- public function actionDojob()
- {
- Yii::$app->db->createCommand('update `accounts_internal` set `last_seen_mobile` = NOW() where id in (351,349,350)')->execute();
- }
-
- public function actionDopro()
- {
-
- $JobPlanEntitty = AsusgJobplan::find()->where(['name' => 'Тормозное и пневматическое оборудование после ремонта испытать , отрегулировать согласно инструкции'])->one();
- $jsusgJob2CommandEntity = AsusgJob2Command::find()->where(['asusg_job_id' => $JobPlanEntitty->id])->all();
- foreach($jsusgJob2CommandEntity as $job) {
- echo '<pre>';
- var_dump('3 =>'. $job->id, $job->asusg_job_id);
- var_dump('3 =>'. $job->jobplantie->id);
- echo '</pre>';
- }
- exit;
- }
-
- public function actionMktest()
- {
-
- Yii::$app->params['countPriority'] = ((2*100)-1);
- var_dump(Yii::$app->params['countPriority']);
-
- $this->logger->setLog('приоритет '.((2*100)-1));
-
-
- $paramsMeaserm = ['input_id' => 7078, 'assignees_arr' => 333, 'work' => 'c57839e6-49ed-4791-9353-925fc2d737b8','stage' =>0, 'parent_id' => 137340 ,'stage_type' => 'доремонтный','asusg_job_mapped_id' => 20456];
- Yii::$app->params['api']['mesrmntParam'] = $paramsMeaserm;
- MappingapiModel::workMeasurements('c57839e6-49ed-4791-9353-925fc2d737b8','c57839e6-49ed-4791-9353-925fc2d737b8');
-
-
-
- }
-
- public function actionProctest()
- {
- $procedureModel = new ProcedureModel();
- $procedureModel->asusg_build_and_start_project_auto(27,210);
- }
-
- public 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;
- }
-
- public 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;
- }
-
- public function getOnlineMobileUser($company){
-
- $result = [];
- $accountsEntity = \app\models\entity\Accounts::find()->where(['company' => $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;
- }
-
- public function addJob2launch2($listWorks,$user)
- {
- $this->logger->indx = $this->user->uuid;
-
- foreach ( $listWorks as $work) {
- $this->logger->header = $work['id_work'];
- Yii::$app->params['countPriority']= 1;
- $dwResult = $this->datailWorkArray[$work['id_work']];
- $this->logger->setLog("Название работы:". $work['work_name']. ".\n UUID работы: " . $work['id_work'] . "\n\n");
- $queueModel = new QueueModel();
-
- $this->logger->setLog("\n 1. ДОБАВЛЕНИЕ В LAUNCH \n\n");
- $asusgJob2LaunchEntity = AsusgJob2Launch::findOne(['asusg_job_uuid' => $work['id_work']]);
- $this->logger->setLog("\n AsusgJob2Launch = " . count($asusgJob2LaunchEntity). " id work = " . $work['id_work'] . "\n");
- $this->addTypeWork($work['id_work'], 0);
- $let = mb_substr($work["section_lit"], -1);
- if( null != $let
- and !in_array($let,['А','Б','В'])
- ) {
- $let = 'А';
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- $projtype = $this->getProjectType($work["repair_name"],$work["eq_serie"]);
-
- $switcher = $asusgJob2LaunchEntity;
-
- if ( null == $switcher) {
- $this->logger->setLog("\n switcher = null \n");
- $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->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 = $work['work_name'];
- $asusgJob2LaunchEntity->section_name = $work["section_lit"];
-
- $asusgJob2LaunchEntity->asusg_projecttype_id = $projtype;
- if (!$asusgJob2LaunchEntity->save()) {
- $this->logger->setLog('в Job2launch не добавилась работа => "'. $work['work_name']. '" Добавление работ будет пропущено так как такая запись уже есть.');
- continue;
- }
- $this->issetLaunch = true;
-
-
- $this->logger->setLog('в Job2launch была добавлена работа => "'. $work['work_name'].'"');
-
- $projId = $this->generateProject($work);
-
- } else {
- $this->logger->setLog("\n switcher != null \n");
- $userUuidArr = explode(',', $asusgJob2LaunchEntity->employees_uuid);
-
- if ( in_array( $user->uuid , $userUuidArr)) {
- $this->logger->setLog('сотрудник '.$user->name .' ('.$user->id.') уже привязан к лаунчу'. $asusgJob2LaunchEntity->id);
- continue;
- } else {
- $asusgJob2LaunchEntity->employees_uuid .= ','. $user->uuid;
- $asusgJob2LaunchEntity->save();
- $this->logger->setLog('сотрудники ('.$asusgJob2LaunchEntity->employees_uuid.') привязаны к лаунчу'. $asusgJob2LaunchEntity->id);
- }
-
- $projId = $this->getCreateProject($work);
-
-
- $this->logger->setLog("ВОТ ТУТ Я ХОТЕЛ ПОЛУЧИТЬ ИД ПРОЕКТА ЧЕРЕЗ ЗАДАЧУ( launch_id = ".$asusgJob2LaunchEntity->id.") => " . $asusgJob2LaunchEntity->onetask->id .", ВОТ ЧТО ПОЛУЧИЛ => " . $asusgJob2LaunchEntity->onetask->input_id ."!\n");
-
-
-
-
-
-
-
-
- }
-
- $this->createProjects[] = $projId;
-
- $this->logger->setLog("\n 3. ДОБАВЛЕНИЕ ЗАДАЧИ \n\n");
- $this->logger->setLog("\n Метка 1.1 \n");
- $tasktypesEntity = Tasktypes::find()->where(['name' => 'Секция '.$let.', задача','company' => $this->company])->one();
- $this->logger->setLog("\n Метка 1.2 (типи задачи ".$tasktypesEntity->id.")\n");
-
-
-
-
- $this->statusMaintask = 0;
- $mainTaskId = $this->getIssetMainTask($work,$user);
- $isCloseMaintask = false;
-
-
- if ( $mainTaskId ) {
- $this->logger->setLog("\n Задача для " . $work["section_lit"] . " уже есть ". $mainTaskId . "\n\n");
- if( 5 == $this->statusMaintask ) {
- $isCloseMaintask = true;
- }
-
-
- } else {
- $this->logger->setLog("\n Метка 1.3 \n");
-
-
- $tasksEntity = new Tasks();
- $tasksEntity->parent_id = 0;
- $tasksEntity->input_id = $projId;
- $tasksEntity->status = 2;
- $tasksEntity->type = $tasktypesEntity->id;
- $tasksEntity->assignees_arr = $this->user->id;
- $tasksEntity->preferred_assignee = $this->user->id;
- $tasksEntity->created = date("Y-m-d H:i;s");
- $tasksEntity->asusg_job_mapped_id = $asusgJob2LaunchEntity->id;
- $tasksEntity->mapping_comment = $work["outfit"] . ': ' . $work['work_name'];
- $tasksEntity->text = $work["section_lit"] . "\n" . $work["outfit"] . ': ' . $work['work_name'] . "\n" . $dwResult['workers'];
- $this->logger->setLog("\n Метка 1.4 \n");
- $this->logger->setLog(json_encode($tasksEntity->attributes));
- $this->logger->setLog('валидация =>'.json_encode($tasksEntity->validate()));
- $this->logger->setLog(json_encode($tasksEntity-> getErrors()));
- if($tasksEntity->save()) {
- $mainTaskId = $tasksEntity->id;
- $this->logger->setLog('в Tasks была добавлена ЗАДАЧА => "'. $work['work_name'] . '" id => '.$tasksEntity->id);
- } else {
- $this->logger->setLog('в Tasks была НЕ добавлена ЗАДАЧА => "'. $work['work_name']);
- }
-
- }
-
- $this->logger->setLog("\n Метка 3 \n");
-
- if ( null == $switcher) {
-
-
-
-
- $this->logger->setLog("\n ДОБАВЛЕНИЕ ТМЦ " . strlen($dwResult['tmcString']) . "\n");
- if ( '' != $dwResult['tmcString']) {
- $tasksEntity3 = new Tasks();
- $tasksEntity3->parent_id = $mainTaskId;
- $tasksEntity3->status = 2;
- $tasksEntity3->priority = Yii::$app->params['tmcPriority'];
-
- $tasksEntity3->created = date("Y-m-d H:i;s");
- $tasksEntity3->type = 2159;
- $tasksEntity3->assignees_arr = $this->user->id;
- $tasksEntity3->preferred_assignee = $this->user->id;
- $tasksEntity3->asusg_job_mapped_id = $asusgJob2LaunchEntity->id;
- $tasksEntity3->text = $dwResult['tmcString'];
- $tasksEntity3->mapping_comment = $dwResult['tmcString'];
- $tasksEntity3->input_id = $projId;
- if ( $tasksEntity3->save()) {
-
-
- $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 );
- }
- Yii::$app->params['countPriority']++;
- }
- $this->logger->setLog( "\n 4. ДОБАВЛЕНИЕ ЗАМЕРОВ ЭТАП 0 \n");
-
- if ( $this->datailWorkArray[$work['id_work']]['measurements'] == null) {
-
- $priority = $queueModel->insertExtraPlan($work,$asusgJob2LaunchEntity,$user->id);
- Yii::$app->params['countPriority'] = $priority;
-
- $paramsMeaserm = ['input_id' => $projId, 'assignees_arr' => $user->id, 'work' => $work,'stage' => 0, 'parent_id' => $mainTaskId , 'stage_type' => 'доремонтный','asusg_job_mapped_id' => $asusgJob2LaunchEntity->id ];
- Yii::$app->params['api']['mesrmntParam'] = $paramsMeaserm;
- MappingapiModel::workMeasurements($work,$user->uuid);
- }
- }
- $this->logger->setLog("\n 5. ДОБАВЛЕНИЕ НА РЕМОНТ \n");
- $priority = $queueModel->insertExtraPlan($work,$asusgJob2LaunchEntity,$user->id);
-
-
- $tasksEntity2 = new Tasks();
- $tasksEntity2->parent_id = $mainTaskId;
- $tasksEntity2->status = 2;
- $tasksEntity2->priority = $priority;
- $tasksEntity2->created = date("Y-m-d H:i;s");
- $tasksEntity2->type = Yii::$app->params['supercycletype'];
- $tasksEntity2->assignees_arr = $this->user->id;
- $tasksEntity2->preferred_assignee = $this->user->id;
- $tasksEntity2->asusg_job_mapped_id = $asusgJob2LaunchEntity->id;
- $tasksEntity2->text = $work["eq_serie"] . ' '.$work["section_lit"] . ', '. $work["outfit"] . ': ' . $work['work_name'];
- $tasksEntity2->input_id = $projId;
- $tasksEntity2->mapping_comment = $work["outfit"] . ': ' . $work['work_name'];
- if ( $tasksEntity2->save()) {
- if ( $isCloseMaintask ) {
- $updateTasks = Tasks::findOne($mainTaskId);
- $updateTasks->status = 2;
- $updateTasks->save();
- }
-
-
-
-
-
- $this->logger->setLog('в Tasks была добавлена КОМАНДА => "'. $work['work_name'] . '" id => '.$tasksEntity2->id . ' приоритет =>' . $priority . ', cтатус => ' . $tasksEntity2->status);
- } else {
- $this->logger->setLog('в Tasks была НЕ добавлена КОМАНДА => "'. $work['work_name'] . '" id => '.$tasksEntity2->id);
- }
-
-
-
-
-
-
-
-
-
-
-
-
- if ( null == $switcher) {
-
- $this->logger->setLog("\n 6. ДОБАВЛЕНИЕ ЗАМЕРОВ ЭТАП 1 \n");
-
-
- if ( $this->datailWorkArray[$work['id_work']]['measurements'] ) { echo "сверхцикловые замеры 1";echo "<br>";
- $paramsMeaserm['stage'] = 1;
- $paramsMeaserm['stage_type'] = 'контрольный';
- $paramsMeaserm['asusg_job_mapped_id'] = $asusgJob2LaunchEntity->id;
- Yii::$app->params['api']['mesrmntParam'] = $paramsMeaserm;
-
- $priority = $queueModel->insertExtraPlan($work,$asusgJob2LaunchEntity,$user->id);
- Yii::$app->params['countPriority'] = $priority;
-
- MappingapiModel::workMeasurements($work,$user->uuid);
- }
-
-
- $this->logger->setLog("\n 7. ДОБАВЛЕНИЕ ЗАМЕРОВ ЭТАП 2 \n");
-
- if ( $this->datailWorkArray[$work['id_work']]['measurements'] ) { echo "сверхцикловые замеры 2";echo "<br>";
- $paramsMeaserm['stage'] = 2;
- $paramsMeaserm['stage_type'] = 'послеремонтный';
- $paramsMeaserm['asusg_job_mapped_id'] = $asusgJob2LaunchEntity->id;
- Yii::$app->params['api']['mesrmntParam'] = $paramsMeaserm;
-
- $priority = $queueModel->insertExtraPlan($work,$asusgJob2LaunchEntity,$user->id);
- Yii::$app->params['countPriority'] = $priority;
-
- MappingapiModel::workMeasurements($work,$user->uuid);
- }
- }
-
-
-
-
-
-
- }
-
- }
-
-
-
- public function addJob2launch3($listWorks,$user)
- {
-
- foreach ( $listWorks as $work) {
- $this->logger->indx = $user->uuid;
- $this->logger->header = $work['id_work'];
- Yii::$app->params['countPriority']= 1;
- $this->logger->setLog("\n 1. ДОБАВЛЕНИЕ В LAUNCH \n\n");
- $asusgJob2LaunchEntity = AsusgJob2Launch::findOne(['asusg_job_uuid' => $work['id_work']]);
- $this->addTypeWork($work['id_work'], 1);
- $let = mb_substr($work["section_lit"], -1);
-
-
-
-
-
-
-
-
-
- $dwResult = $this->datailWorkArray[$work['id_work']];
-
-
-
-
-
-
-
-
-
-
- $projtype = $this->getProjectType($work["repair_name"],$work["eq_serie"]);
- $JobPlanEntitty = AsusgJobplan::find()->where(['name' => $work["work_name"]])->one();
- if ( null == $JobPlanEntitty->id ) {
- $this->logger->setLog(" ВНИМАНИЕ не нашел работу в AsusgJobplan ('name' => ".$work['work_name'].")\n\n");
- }
-
- $jsusgJob2CommandEntity = AsusgJob2Command::find()->where(['asusg_job_id' => $JobPlanEntitty->id, 'asusg_projecttype_id' => $projtype ])->all();
-
- if ( null == $jsusgJob2CommandEntity || 0 == count($jsusgJob2CommandEntity)){
- $this->listWorkForExtraArray[] = $work;
- $this->logger->setLog(" ВНИМАНИЕ не нашел работу в asusgJob2Command ('name' => ".$work['work_name'].")\n\n");
- continue;
- }
- $switcher = $asusgJob2LaunchEntity;
-
- if ( null == $switcher) {
- $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->uuid;
- $asusgJob2LaunchEntity->section_uuid = $work["section_id"];
- $asusgJob2LaunchEntity->asusg_project_id = 0;
- $asusgJob2LaunchEntity->job_order = 0;
- $asusgJob2LaunchEntity->asusg_projecttype_id = $projtype;
- $asusgJob2LaunchEntity->time_limit = $dwResult['time_limit'];
- $asusgJob2LaunchEntity->outfit = $dwResult['outfit'];
- $asusgJob2LaunchEntity->name = $work['work_name'];
- $asusgJob2LaunchEntity->section_name = $work["section_lit"];
- if (!$asusgJob2LaunchEntity->save()) {
- $this->logger->setLog('в Job2launch не добавилась работа => "'. $work['work_name']. '" Добавление работ будет пропущено так как такая запись уже есть.');
- continue;
- }
- $this->issetLaunch = true;
-
-
- $this->logger->setLog('в Job2launch была добавлена работа => "'. $work['work_name'].'"');
-
-
- $projId = $this->generateProject($work);
-
- } else {
- $userUuidArr = explode(',', $asusgJob2LaunchEntity->employees_uuid);
-
- if ( in_array( $user->uuid , $userUuidArr)) {
- $this->logger->setLog('сотрудник '.$user->name .' ('.$user->id.') уже привязан к лаунчу'. $asusgJob2LaunchEntity->id);
- continue;
- } else {
- $asusgJob2LaunchEntity->employees_uuid .= ','. $user->uuid;
- $asusgJob2LaunchEntity->save();
- $this->logger->setLog('сотрудники ('.$asusgJob2LaunchEntity->employees_uuid.') привязаны к лаунчу'. $asusgJob2LaunchEntity->id);
- }
-
-
-
- $projId = $this->getCreateProject($work);
-
-
-
-
-
-
-
-
-
-
- }
-
- $this->logger->setLog("\n 3. ДОБАВЛЕНИЕ ЗАДАЧИ \n\n");
- $tasktypesEntity = Tasktypes::find()->where(['name' => 'Секция '.$let.', задача','company' => $this->company])->one();
-
- $this->statusMaintask = 0;
- $mainTaskId = $this->getIssetMainTask($work,$user);
- $isCloseMaintask = false;
- if ( $mainTaskId ) {
-
- $this->logger->setLog("\n Такая задача( цикловая ) уже есть \n\n");
-
- if( 5 == $this->statusMaintask ) {
- $isCloseMaintask = true;
- }
-
-
-
- } else {
-
-
-
- $tasksEntity = new Tasks();
- $tasksEntity->parent_id = 0;
- $tasksEntity->status = 2;
- $tasksEntity->type = $tasktypesEntity->id;
- $tasksEntity->assignees_arr = $user->id;
- $tasksEntity->preferred_assignee = $user->id;
- $tasksEntity->created = date("Y-m-d H:i;s");
- $tasksEntity->asusg_job_mapped_id = $asusgJob2LaunchEntity->id;
- $tasksEntity->mapping_comment = $work["outfit"] . ': ' . $work['work_name'];
- $tasksEntity->text = $work["section_lit"] . "\n" . $work["outfit"] . ': ' . $work['work_name'] . "\n" . $dwResult['workers'];
- $tasksEntity->input_id = $projId;
-
- if($tasksEntity->save()) {
- $mainTaskId = $tasksEntity->id;
-
- $this->logger->setLog('в Tasks была добавлена ЗАДАЧА => "'. $work['work_name'] . '" id => '.$tasksEntity->id);
- } else {
- $this->logger->setLog('в Tasks была НЕ добавлена ЗАДАЧА => "'. $work['work_name'] . '" id => '.$tasksEntity->id);
- continue;
- }
-
-
- $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']);
-
-
- $this->logger->setLog("\n ДОБАВЛЕНИЕ ТМЦ " . strlen($dwResult['tmcString']) . "\n");
- if ( '' != $dwResult['tmcString']) {
- $tasksEntity3 = new Tasks();
- $tasksEntity3->parent_id = $tasksEntity->id;
- $tasksEntity3->status = 2;
- $tasksEntity3->priority = Yii::$app->params['tmcPriority'];
-
- $tasksEntity3->created = date("Y-m-d H:i;s");
- $tasksEntity3->type = 2159;
- $tasksEntity3->assignees_arr = $user->id;
- $tasksEntity3->preferred_assignee = $user->id;
- $tasksEntity3->asusg_job_mapped_id = $asusgJob2LaunchEntity->id;
- $tasksEntity3->text = $dwResult['tmcString'];
- $tasksEntity3->mapping_comment = $dwResult['tmcString'];
- $tasksEntity3->input_id = $projId;
- if ( $tasksEntity3->save()) {
-
- $arrJ[] = $tasksEntity3->id;
- $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);
- } else {
-
- $this->logger->setLog('в Tasks была НЕ добавлена КОМАНДА => "'. $work['work_name'] . '" id => '.$tasksEntity3->id);
- }
-
- }
-
-
- $this->logger->setLog("\n 4. ДОБАВЛЕНИЕ ЗАМЕРОВ ЭТАП 0 \n");
-
-
- if ( $this->datailWorkArray[$work['id_work']]['measurements'] ) {
-
- Yii::$app->params['countPriority'] = (100-1);
- $this->logger->setLog('приоритет '.(100-1));
- $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,$user->uuid);
- }
- }
-
- $this->logger->setLog("\n 5. ДОБАВЛЕНИЕ НА РЕМОНТ \n");
- $countpr = 100;
- foreach($jsusgJob2CommandEntity as $job) {
-
-
-
- $job->job_uuid = $work['id_work'];
- $tasksEntity2 = new Tasks();
- $tasksEntity2->parent_id = $mainTaskId;
- $tasksEntity2->status = 2;
- $tasksEntity2->priority = ($job->original_order*100);
-
- $tasksEntity2->created = date("Y-m-d H:i;s");
- $tasksEntity2->type = $job->smopp_cmd_id;
- $tasksEntity2->assignees_arr = $user->id;
- $tasksEntity2->preferred_assignee = $user->id;
- $tasksEntity2->asusg_job_mapped_id = $job->jobplantieuuid->id;
- $tasksEntity2->text = $work["eq_serie"] . ' '.$work["section_lit"] . ', '. $work["outfit"] . ':' . $work['work_name'].'..';
- $tasksEntity2->mapping_comment = $work["outfit"] . ': ' . $job->tasktypes->name;
- $tasksEntity2->input_id = $projId;
- if ( $tasksEntity2->save()) {
- if ( $isCloseMaintask ) {
- $taskEntity = Task::findOne($mainTaskId);
- $taskEntity->status = 2;
- $taskEntity->save();
- $isCloseMaintask = false;
- }
-
-
-
-
-
- $this->logger->setLog('в Tasks была добавлена КОМАНДА => "'. $work['work_name'] . '" id => '.$tasksEntity2->id);
- } else {
- $this->logger->setLog('в Tasks была НЕ добавлена КОМАНДА => "'. $work['work_name'] . '" id => '.$tasksEntity2->id);
- }
-
- if ( ($job->original_order*100) > $countpr ) {
- $countpr = ($job->original_order*100);
- }
-
-
-
- }
-
-
-
-
-
-
-
-
- $tasksEntity = null;
-
- if ( null != $tasksEntity3) {
- $tasksEntity3->input_id = $projId;
-
-
-
- }
-
- if ( null == $switcher) {
-
-
- $this->logger->setLog("\n 6. ДОБАВЛЕНИЕ ЗАМЕРОВ ЭТАП 1 \n");
-
- if ( $this->datailWorkArray[$work['id_work']]['measurements'] ) {
- $paramsMeaserm['stage'] = 1;
- $paramsMeaserm['stage_type'] = 'контрольный';
- $paramsMeaserm['asusg_job_mapped_id'] = $asusgJob2LaunchEntity->id;
-
- Yii::$app->params['countPriority'] = ($countpr+1);
- $this->logger->setLog('приоритет '.($countpr+1));
- Yii::$app->params['api']['mesrmntParam'] = $paramsMeaserm;
- MappingapiModel::workMeasurements($work,$user->uuid);
- }
-
-
-
- $this->logger->setLog("\n 7. ДОБАВЛЕНИЕ ЗАМЕРОВ ЭТАП 2 \n");
-
- if ( $this->datailWorkArray[$work['id_work']]['measurements'] ) {
- $paramsMeaserm['stage'] = 2;
- $paramsMeaserm['stage_type'] = 'послеремонтный';
- $paramsMeaserm['asusg_job_mapped_id'] = $asusgJob2LaunchEntity->id;
- Yii::$app->params['countPriority'] = ($countpr+2);
- $this->logger->setLog('приоритет '.($countpr+2));
- Yii::$app->params['api']['mesrmntParam'] = $paramsMeaserm;
- MappingapiModel::workMeasurements($work,$user->uuid);
- }
-
-
- }
-
-
-
-
-
-
- }
- }
-
-
- public function generateProject($work){
-
- $this->logger->setLog("\n 2. ГЕНЕРАЦИЯ ПРОЕКТА \n");
-
-
- $result = '';
- $status = '';
- $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),'section_subnumber' => $work["section_num"]])
- ->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) {
- $sectionsEntity2 = new Sections();
- $sectionsEntity2->locomotive_series = $work["eq_serie"];
- $sectionsEntity2->section_number = mb_substr($work['section_lit'],0,-1);
- $sectionsEntity2->section_subnumber = $work["section_num"];
- $sectionsEntity2->diagnostic_map = $work["section_DK"];
- $sectionsEntity2->uuid = $work["section_id"];
- $sectionsEntity2->letter = $let;
- if ( $sectionsEntity2->save()) {
- $this->logger->setLog('в Sections была добавлена новая секция => '. $work["section_num"] . ' id => '.$sectionsEntity2->id);
- } else {
-
- $this->logger->setLog('в Sections при добавлении секции произошли ошибки => '. count($sectionsEntity2->errors) . ' шт.');
- $sectionsEntity->diagnostic_map = $work['section_DK'];
- $sectionsEntity->save();
- $this->logger->setLog('Пришлось просто обновить диагностическую карту секция=> '. $sectionsEntity . ', номер карты =>' . $work['section_DK']);
- }
- $diagnostic_map = $sectionsEntity->diagnostic_map;
- }
- else if( ( null == $sectionsEntity->diagnostic_map ) || ($sectionsEntity->diagnostic_map != $work['section_DK'])) {
-
- $sectionsEntity->diagnostic_map = $work['section_DK'];
- $sectionsEntity->save();
- }
-
-
-
- $this->logger->setLog('Условие проверки1: ' . $sectionsEntity->diagnostic_map .'=='. $work['section_DK']);
- $this->logger->setLog('Условие проверки1: ' . $sectionsEntity2->diagnostic_map .'=='. $work['section_DK']);
- if ( $sectionsEntity->diagnostic_map == $work['section_DK'] ) {
-
- $projectRes = $this->getIssetProject($work);
- $result = ( isset($projectRes['id']) ) ? $projectRes['id'] : '' ;
- $status = ( isset($projectRes['status']) ) ? $projectRes['status'] : '' ;
-
- $this->logger->setLog('в Sections секция с такой диагностической картой => '. $work['section_DK'] . ' существует. Ид проекта '. $result);
- }
-
- if ( $sectionsEntity2->diagnostic_map == $work['section_DK'] ) {
-
- $projectRes = $this->getIssetProject($work);
- $result = ( isset($projectRes['id']) ) ? $projectRes['id'] : '' ;
- $status = ( isset($projectRes['status']) ) ? $projectRes['status'] : '' ;
-
- $this->logger->setLog('в Sections секция с такой диагностической картой => '. $work['section_DK'] . ' существует. Ид проекта '. $result);
- }
- $ProjectsL = ProjectsLocotech::findOne($result);
- $status = $ProjectsL->status;
-
- if ((!$result) || ( 5 == $status )) {
- $this->logger->setLog('Условие проверки2: '.(!$result) .' статус '. $status . json_encode($projectRes));
- $result = $this->generateProject3($work);
- $this->logger->setLog('Такого проекта еще не было пришлось создать. Ид проекта => '. $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;
-
-
-
- return $result;
- }
-
- private function getCreateProject($work) {
-
- $result = '';
-
- $projectRes = $this->getIssetProject($work);
- $result = $projectRes['id'];
- $status = $projectRes['status'];
-
-
-
-
- return $result;
- }
-
- private function getIssetProject($work) {
-
- $query = "select pl.id, pl.status from projects_locotech pl
- inner join tasks t on pl.id = t.input_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 pl.uuid like '%" . $work['repair_name']. ",%'
- order by pl.id desc
- limit 1";
- $this->logger->setLog('Текст запроса ' . $query);
- $projectRes = Yii::$app->db->createCommand($query)->queryOne();
-
-
-
- return $projectRes;
- }
-
-
- private function getIssetMainTask($work,$user) {
-
- $result = null;
-
-
-
- $query = "select t.id as task_id, pl.status, t.status as maintask_status
- from projects_locotech pl
- inner join tasks t on pl.id = t.input_id
- left join tasks tc on tc.parent_id = t.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 pl.status <> 5
- and tc.text like '%" . $work["section_lit"]. "%'
- and tc.assignees_arr = " . $user->id . "
- and pl.uuid like '%" . $work["repair_name"]. "%'
- order by pl.id desc
- limit 1";
-
-
- $this->logger->setLog('Текст запроса ' . $query);
- $projectRes = Yii::$app->db->createCommand($query)->queryOne();
-
- $this->logger->setLog('Текст ответа ' . json_encode($projectRes));
- if ( is_array($projectRes) and !empty($projectRes)){
- $result = $projectRes['task_id'];
- $this->statusMaintask = $projectRes['maintask_status'];
- }
- return $result;
- }
-
- private function getIssetMainTask_false($work,$user) {
-
- $result = null;
- $asusgJob2LaunchEntity = AsusgJob2Launch::find()->where(['asusg_job_uuid' => $work['id_work']])->andWhere(['like','employees_uuid', $user->uuid])->one();
- $tasksEntity = Tasks::find()->where(['parent_id' => 0,'asusg_job_mapped_id' => $asusgJob2LaunchEntity->id, 'assignees_arr' => $user->id])->one();
- $this->logger->setLog('Запрос на существовании задачи, ответ =>' . $tasksEntity->id);
- if ( $tasksEntity->id ){
- $result = $tasksEntity->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"];
-
-
-
-
-
-
-
-
- foreach ( $work['workers'] as $worker) {
- $tempArray['workers'][] = $worker;
-
-
-
- }
- $dataArr[] = $tempArray;
- }
- }
- }
- $result['result'] = 'true';
- $result['data'] = $dataArr;
- break;
- }
- return $result;
- }
-
- private function sectionList() {
-
- $result = [];
-
-
- $params['place'] = 'a84d0a15-08ec-11e5-829d-00155d6cab05';
- $params['date'] = '1581324560';
- $locomotiveModel = new LocomotiveModel();
- $result = $locomotiveModel->getSectionList($params);
-
-
- $this->sectionList = json_decode($result,true);
- return $result;
- }
-
- private function getSectionInfo( $id,$repair) {
-
- $result = [];
- if (empty($this->sectionList)) {
- $this->sectionList();
- }
-
- foreach ($this->sectionList as $items) {
-
-
- foreach ( $items as $section) {
- if ( $section["Section"] == $id and $section['TypeOfRepair'] == $repair ) {
-
- $result['section_num'] = $section["NumberSection"];
- $result['section_DK'] = $section['DiagnosticMapslocomotive'];
- return $result;
- }
- }
- }
- return $result;
- }
-
- private function buisyEmployee($user){
- $tasksEntity = Tasks::find()->where(['assignees_arr' => $user->id])->andWhere(['<>','status',5])->all();
-
- if ( 0 < count($tasksEntity)){
-
- return true;
- }
-
- return false;
- }
-
- private function clearEmptyProjects() {
-
- if (empty($this->createProjects)) {
- return true;
- }
- $projectsArray = array_unique($this->createProjects);
- foreach ($projectsArray as $proj){
- $tasksEntity = Tasks::find()->where(['input_id' => $proj])->all();
- if ( 0 == count($tasksEntity)){
- $projectsLocotech = ProjectsLocotech::findOne($proj);
- $projectsLocotech->delete();
- }
-
- }
- return true;
- }
-
-
-
-
-
-
- private function insertEippJob($listWorks) {
-
- foreach( $listWorks['data'] as $work) {
- $myworkEntity = new Mywork();
- $myworkEntity->id_work = $work['id_work'];
- $myworkEntity->section_DK = $work['section_DK'];
- $myworkEntity->eq_number = $work['eq_number'];
- $myworkEntity->repeats = $work['repeats'];
- $myworkEntity->outfit = $work['outfit'];
- $myworkEntity->work_name = $work['work_name'];
- $myworkEntity->section_id = $work['section_id'];
- $myworkEntity->section_num = $work['section_num'];
- $myworkEntity->section_lit = $work['section_lit'];
- $myworkEntity->repair_name = $work['repair_name'];
- $myworkEntity->eq_serie = $work['eq_serie'];
- $myworkEntity->save();
- }
- }
-
-
-
-
-
-
-
- public function workDetail($user_id, $work_id)
- {
- $myworkEntity = Mywork::findOne(['id_work' => $work_id,'detail' => 1]);
- if( $myworkEntity ){
- return true;
- }
- $this->GWparams = [
- 'url' => Yii::$app->params['api']['domain'] . $this->url . 'work_detail',
- 'param' => [
- 'user_id' => $user_id,
- 'id_work' => $work_id
- ]];
-
- $response = $this->curlRequestUni($this->GWparams,'post');
- $work = json_decode($response,true);
-
-
- $tmcList = $this->getTmcList($work);
- $myworkEntity = Mywork::findOne(['id_work' => $work_id]);
- $myworkEntity->hw_measurements_status = $tmcList['hw_measurements_status'];
- $myworkEntity->repeats = $tmcList['repeats'];
- $myworkEntity->time_limit = $tmcList['time_limit'];
- $myworkEntity->work_part_percent = $tmcList['work_part_percent'];
- $myworkEntity->time_remain = $tmcList['time_remain'];
- $myworkEntity->cam_list = json_encode($tmcList['cam_list']);
- $myworkEntity->equipement_name = $tmcList['equipement_name'];
- $myworkEntity->equipement_number = $tmcList['equipement_number'];
- $myworkEntity->work_status = $tmcList['work_status'];
- $myworkEntity->measurements = $tmcList['measurements'];
- $myworkEntity->tmsString = $tmcList['tmsString'];
- $myworkEntity->detail = 1;
- $myworkEntity->save();
-
- return true;
- }
-
-
-
-
-
- public function getTmcList($work) {
-
- $result = [];
- $tenpArray = [];
- $count = 1;
- foreach($work['rows'] as $tmc1) {
- foreach($tmc1 as $tmc2) {
- $tmc2 = json_decode($tmc2,true);
- foreach($tmc2['data'] as $key => $tmc3) {
- $result[$key] = $tmc3;
- foreach($tmc3 as $tmc4) {
- if ( '' != $tmc4["tmc_name"]) {
- $tenpArray[] = $tmc4["tmc_name"];
- }
- }
- if ( 'workers' == $key) {
- $result['workers'] = [];
- foreach($tmc3 as $key => $tmc5) {
- $result['workers'][] = $tmc5['fio'];
- $result['workers_uuid'][] = $tmc5['id'];
- }
- }
- if ( 'measurements' == $key) {
- $result['measurements'] = $this->CheckmeasurementField($tmc3);
- }
- }
- }
- }
-
- $result['tmcString'] = '';
- if ( !empty($tenpArray) ) {
- $result['tmcString'] = implode("\n * ", $tenpArray);
- $result['tmcString'] = "* " . $result['tmcString'];
- }
- $result['workers'] = 'Назначены: ' . implode(', ',$result['workers']);
- return $result;
- }
-
-
-
-
-
-
- private function CheckmeasurementField($msrm) {
-
- $msrmArr = explode('/', $msrm );
- if ( (count($msrmArr) > 1) && ($msrmArr[0] == $msrmArr[1]) ) {
- return false;
- }
- return true;
- }
-
-
-
-
-
-
-
-
- private function attachWorkUser($work,$user) {
-
- $workworkerEntity = new Workworker();
- $workworkerEntity->id_work = $work;
- $workworkerEntity->workers = $user;
- $workworkerEntity->save();
- return true;
- }
-
- private function addTypeWork($workId, $workType) {
- $myworkEntity = Mywork::findOne(['id_work' => $workId]);
- $myworkEntity->type_work = $workType;
- $myworkEntity->save();
- }
-
-
- private function fixPriority($k) {
-
- $tasksArray = [];
- $flag = 0;
- $pl = ProjectsLocotech::find()->where(['>','created', date('Y-m-d').' 00:00:00'])->andWhere(['<','created', date('Y-m-d').' 23:59:59'])->all();
- $arrPL = [];
- foreach ($pl as $plEnt) {
- $arrPL[] = $plEnt->id;
- }
- $tE = Tasks::find()->andWhere(['IN', 'input_id',$arrPL])
- ->groupBy(['assignees_arr'])
- ->all();
- $arrT = [];
- foreach ($tE as $tEnt) {
- $arrT[] = $tEnt->assignees_arr;
- }
- $tt = Tasks::find()->where(['parent_id' => 0 ])
- ->andWhere(['IN', 'input_id',$arrPL])
- ->andWhere(['IN', 'assignees_arr',$arrT])
- ->andWhere(['>','created', date('Y-m-d').' 00:00:00'])
- ->andWhere(['<','created', date('Y-m-d').' 23:59:59'])
- ->orderBy(['parent_id' => SORT_ASC])->all();
- foreach ($tt as $t) {
- $mt = Tasks::find()->where(['parent_id' => $t->id ])->orderBy(['priority' => SORT_ASC])->all();
- foreach ( $mt as $e) {
- if ( 0 != $prior['pr'] ) {
- if ( $prior['pr'] == $e->priority){
- $tasksArray[$t->id][] = [['pr' =>$e->priority, 'id' => $e->id],$prior];
- }
- }
- $prior['pr'] = $e->priority;
- $prior['id'] = $e->id;
- }
- }
-
- $i = 0;
-
- foreach( $tasksArray as &$task){
- foreach( $task as &$t){
- $mt = Tasks::findOne($t[1]['id']);
- $mt->scenario = Tasks::SCENARIO_UPDATE_PRIORITY;
- if ( 110 < $mt->priority) {
-
- $mt->priority = ($t[1]['pr'] + 5);
- $mt->save();
-
- }
- if ( 89 > $mt->priority) {
-
- $mt->priority = ($t[1]['pr'] + 1);
- $mt->save();
-
- }
- break;
- }
-
- $i++;
- }
- if ( empty($tasksArray) ) {
-
- return true;
- } else {
- $k++;
- if( 50 == $k ) {
- return true;
- }
- $this->fixPriority($k);
- }
- }
-
- }
|