1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468 |
- <?php
- namespace app\controllers;
- use app\models\ElasticLog;
- use Yii;
- use yii\web\Controller;
- use app\models\MappingworksModel;
- use app\models\MainModel;
- use app\models\LogDoneList;
- use app\models\ProcedureModel;
- use app\models\entity\Tasks;
- 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\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\AsusgProjectType;
- use app\models\entity\LocomotiveSeries;
- use app\models\entity\ProjectsLocotech;
- use app\models\entity\AsusgJob2Command;
- use app\models\entity\AsusgMeasurements;
- use \app\models\LogEippResponse;
- use app\models\entity\Jobtypes;
- use app\models\procedure\AsusgAddMeasurementToTaskModel;
- use app\models\MappingapiModel;
- use app\models\QueueModel;
- use app\models\procedure\StartProjectForLocoModel;
- class MappinghandlerController extends Controller
- {
- private $logger;
- private $company;
- private $testIdpl2;
- private $testIdpl3;
-
- public function beforeAction($action)
- {
- parent::beforeAction($action);
- $log = new LoggerFile();
-
- $this->logger = new MappingHandlerModel($log);
- return true;
- }
-
- // запускается периодически через крон
- public function actionGetworks($company)
- {
- $this->company = $company;
- $GWparams = [
- 'url' => 'http://devplatform.digitaldepot.ru:8085/Thingworx/Things/SMoPPIntegrationLibrary/Services/getUserWorks',
- 'param' => '',
- 'login' => 'ПройдаковИА',
- 'pass' => 'Ip15351112'
- ];
- // список сотрудников онлайн
- $onlineUser = $this->getOnlineMobileUser($company);
- if( 0 == count($onlineUser)) {
- return 'Нет сотрудников онлайн';
- }
- //$this->logger->setLog('ID пользователя => ' . (int)$_SESSION["id"]);
- $this->logger->setLog( date("Y-m-d H:i:s") . "\n");
- $mainModel = new MainModel();
- // для каждого сотрудника онлайн запускаем проекты если они еще не запущены
- foreach($onlineUser as $user) {
- if ( '' == $user->uuid and null == $user->uuid) {
- continue;
- }
- $GWparams['param'] = $user->uuid;
- // Запрос к асусг список работ
- //$GWparams['param'] = '';
- //$listWorks = json_decode($this->curlRequest2($GWparams));
- $listWorks = [];//json_decode($mainModel->curlRequest2($GWparams));
- // Список отсутствующих работ
- $listIsabsentWorks = $this->Getisabsentworks($listWorks,$GWparams);
- // проверка на существование работ в jobplan
- //=========================================================================================================
- ElasticLog::eipp($GWparams, 'начало выполнения работы', $user->uuid);
- $listWorks2 = json_decode($mainModel->curlRequest2($GWparams),true);
- ElasticLog::eipp($listWorks2, 'завершение выполнения работы', $user->uuid, false);
- $this->logger->setLog('Колличество работ из еипп =>'. count($listWorks2).' для сотрудника =>' . $user->id);
- $listIsabsentWorks2 = $this->Getisabsentworksjp($listWorks2); // вновь утвержденный план 1 | вернет список работ кот нет ( в JobPlan )
- $listIssetWorks3 = $this->Getissetworksjp($listWorks2);
- $this->logger->setLog('Колличество работ из еипп ( нет в jobplan) =>'. count($listIsabsentWorks2));
- $this->logger->setLog('Колличество работ из еипп ( есть в jobplan) =>'. count($listIssetWorks3));
- $this->logger->setLog('Сверхцикловые');
- $addJob2launch2 = $this->addJob2launch2($listIsabsentWorks2,$user);
- $this->logger->setLog('Мэппинг');
- $addJob2launch3 = $this->addJob2launch3($listIssetWorks3,$user);
- $this->logger->setLog("Интеграция сверхцикловых работ прошла без падений!\n=================== НОВАЯ ИТЕРАЦИЯ ==================================\n");
- //echo '<pre>';
- //var_dump($user->id,$listIsabsentWorks2);
- //var_dump($user->id,$listIssetWorks3);
- // var_dump($user->id,$listWorks2);
- // echo '</pre>';
- continue;
- //=========================================================================================================
- $this->addWorksInJobPlan($listWorks);
- //$this->addWorksInTasks($listWorks);
- $listIsabsentWorks = $this->addWorksInTaskType($listWorks,$listIsabsentWorks);
- //echo "<pre>"; var_dump($listIsabsentWorks); echo "</pre>";
- //echo "++++++++++++++";
- // Группировка работ по локомотивам/секциям
- //echo "<pre>"; var_dump($listIsabsentWorks); echo "</pre>"; exit;
- $listW = $this->GetworksOnLoco($listIsabsentWorks);
- // временный костыль
- //$userInfo = $this->getUserInfo($GWparams);
- // временный костыль
- // возвращает тип проекта
- $projecttypeId = $this->getTypeProject($user);
- //->addProject()
- // Запускаем проект
- $startedProj = $this->startProject($listW,$user,$projecttypeId);
- // проверить есть ли для таких работ инструкции
- $minRes = $this->checkMapping($startedProj);
- // если что-то есть то запланировать asusg_job2launch
- $minRes = $this->addJobproject($minRes);
- $this->addJob2launch($minRes);
- $this->pushProject($minRes);
- //echo "<pre>";
- //var_dump($listIsabsentWorks);
- //echo "</pre>";
- }
- exit;
- //return $listWorks;
-
- }
-
-
-
- // запускается по запросу ЕИПП
-
- public function actionStartuserwork()
- {
-
- $mainModel = new MainModel();
- // для каждого сотрудника онлайн запускаем проекты если они еще не запущены
- //if( '' == $user->uuid and null == $user->uuid) {
- // continue;
- // }
- $params = \Yii::$app->request->post();
- //$param = json_decode($params['params'],true);
- //$GWparams['param'] = $user->uuid;
- // Запрос к асусг список работ
- $listWorks = json_decode($params['params'],true);
-
- //$listWorks = json_decode($params);
- //$ee = $param['data'] ;
- $GWparams['param'] = '0f9ed850-e473-11e2-aaad-ac162db0b20c';
-
-
- $listWorks = $this->prepareParams($listWorks['data']); // временный метод для подготовки параметров нужного вида.
- // echo "<pre>"; var_dump(gettype($listWorks)); echo "</pre>";
- return json_encode(['r' => gettype($listWorks)],true);
- //exit;
- // Список отсутствующих работ
- $listIsabsentWorks = $this->Getisabsentworks($listWorks,$GWparams);
- // проверка на существование работ в jobplan
- $this->addWorksInJobPlan($listWorks);
- $listIsabsentWorks = $this->addWorksInTaskType($listWorks,$listIsabsentWorks);
- //echo "<pre>"; var_dump($listIsabsentWorks); echo "</pre>";
- //echo "++++++++++++++";
- //echo "<pre>"; var_dump($user['id'],$listIsabsentWorks); echo "</pre>"; exit;
- // Группировка работ по локомотивам/секциям
- //echo "<pre>"; var_dump($listIsabsentWorks); echo "</pre>"; exit;
- $listW = $this->GetworksOnLoco($listIsabsentWorks);
- // временный костыль
- //$userInfo = $this->getUserInfo($GWparams);
- // временный костыль
- // возвращает тип проекта
- $projecttypeId = $this->getTypeProject($user);
- //->addProject()
- // Запускаем проект
- $startedProj = $this->startProject($listW,$user,$projecttypeId);
- // проверить есть ли для таких работ инструкции
- $minRes = $this->checkMapping($startedProj);
- // если что-то есть то запланировать asusg_job2launch
- $minRes = $this->addJobproject($minRes);
-
- $this->addJob2launch($minRes);
- $this->pushProject($minRes);
-
- //echo "<pre>";
- //var_dump($listIsabsentWorks);
- //echo "</pre>";
-
- //return $listWorks;
-
- }
-
-
-
- public function actionDojob()
- {
- //phpinfo();
- //$this->logger->setLog('text');
- //$procedureModel = new ProcedureModel();
- //$procedureModel->asusg_build_and_start_project_auto(27,3183);
- Yii::$app->db->createCommand('update `accounts_internal` set `last_seen_mobile` = NOW() where id in (364,369,371,373,390,333,325,310,409,393,308,385)')->execute();
- //echo 'sdfsd';
- }
-
- public function actionDojob2()
- {
-
- $doneList = LogDoneList::find()->where(['>','date',date('Y-m-d').' 00:00:00'])->all();
- echo "<pre>";
- foreach($doneList as $desc){
- //var_dump($desc->desc);
- }
-
- //$d = json_decode($res,true);
- //$d = json_decode($res);
- //var_dump($jobtypes);
-
-
- //$res = new QueueModel();
- //$r = $res->execute([],'0f9ed870-e473-11e2-aaad-ac162db0b20c');
-
- $query = "select t.id as task_id, pl.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 = 3
- and pl.loco_type = '3ЭС5К'
- and pl.loco_number = 0364
- and t.parent_id = 0
- and pl.status <> 5
- and tc.text like '%0364А%'
- and tc.assignees_arr = 393
- and pl.uuid like '%ТР-1%'
- order by pl.id desc
- limit 1";
-
- //echo $query;
-
- $projectRes = Yii::$app->db->createCommand($query)->queryOne();
- //echo $projectRes['task_id'];
- //\app\models\entity\UserActivity::ping(387);
- //$response = $logEippResponseEntity->response;
- //$work = json_decode($response,true);
- var_dump($projectRes);
-
- echo "sfsfsdf";
- exit;
- foreach ( $arr as $b) {
- $resd = AsusgJob2Launch::findOne(['asusg_job_uuid' => $b]);
- //var_dump($resd->id, $resd->employees_uuid);
- }
- echo "</pre>";
- //$jsusgJob2CommandEntity = AsusgJob2Command::find()->where(['asusg_job_id' => 1222, 'asusg_projecttype_id' => 16 ])->all();
- //$work_uuid = '602cfd16-9cef-4ff6-b31e-8e89a85b0854';
- foreach($jobtypes as $job) {
- //$job->job_uuid = $work_uuid;
- //var_dump($job->id);
- }
- //$tasksEntity = Tasks::find()->where(['_parent_id' => 23455])->andWhere(['>', 'priority', 0])->min('type');
-
- // $MappingworksModel = new MappingworksModel();
- // $MappingworksModel->workToExecute(115220);exit;
- \app\models\LogEippResponse::addLog('123123','asdasdasdasd');
- //require_once $_SERVER["DOCUMENT_ROOT"].'/functions.php';
- //$r = FindActions();
-
- //$date->timezone_type = 5;
- //var_dump($date);
-
- //echo "Из такого = " . date_format($date); echo "<br><br>";
- //$count = 0;
- /*
- $tokens = [
- '0x03 0x72 0x7D 0xA2 0xF3 2x91 0x95',
- 'plastic',
- '0x02 0x73 0x7D 0xA3 0xF3 2x92 0x90',
- 'metall',
- '0x01 0x54 0x7D 0xC1 0xF3 1x93 0x91',
- '0x14 0x76 0x7D 0xD7 0xF3 x95 0x93',
- '0x05 0x75 0x7D 0xE5 0xF3 5x94 0x92',
- '0x24 0x54 0x7B 0xF2 0xF3 9x98 0x94',
- ];
-
- foreach( $tokens as $token) {
-
- $oil = new \app\models\entity\Oilstat();
- $oil->cond = 'N';
- $oil->token = $token;
- $oil->date = date('Y-m-d H:i:s');
- $oil->device_id = 777;
- //$oil->save();
- sleep(1);
- var_dump($oil->id);
- var_dump($oil->errors);
- }
- $r = \app\models\entity\OilstatTemp::findOne();
- var_dump($r);
- */
- /*
- $conf = ['true' => true, 'false' => false];
- $execResult = json_decode($str,true);
- foreach( $execResult['rows'] as $row) {
- $rowArray = json_decode($row["result"],true);
- if ( null != $rowArray["result"]) {
- //return $conf[$rowArray["result"]];
- }
- }
- echo 0;
- return false;*/
-
- }
-
- public function actionEippresponse()
- {
- $time = Yii::$app->request->get('indx');
- if ( null == $time) {
- return false;
- }
- $logEipp = LogEippResponse::find()->where(['indx' => $time])->orderBy(['id' => SORT_DESC])->one();
-
- $resp = json_decode($logEipp->response,true);
- foreach ($resp["rows"] as &$item ) {
- $item['result'] = json_decode($item['result'],true);
- }
- //echo "<pre>";
- //print_r($resp);
- //echo "<pre>";
-
- return $this->render('index', [
- 'model' => $resp,
- ]);
-
- }
-
- public function actionCleartasks()
- {
-
- $tasksEntity = Tasks::find()->where(['in', 'assignees_arr', [ ] ])->all();
- $launch = [];
- $projects = [];
- var_dump(count($tasksEntity));
- foreach( $tasksEntity as $task) {
- var_dump($task->id);
- $proj = projectsLocotech::findOne($task->input_id);
- if ( null != $proj) {
- //var_dump($proj->id);
- //$proj->delete();
- }
-
- $launch = AsusgJob2Launch::findOne($task->asusg_job_mapped_id);
- if ( null != $launch) {
- //var_dump($launch->id);
- //$launch->delete();
- }
- $smrmnt = AsusgMeasurements::find()->where(['smopp_task_id' => $task->id])->all();
- if ( null != $smrmnt) {
- foreach($smrmnt as $item) {
- //$item->delete();
- }
- }
- //$projects[] = $task->input_id;
- //$launch[] = $task->asusg_job_mapped_id;
- }
-
- foreach( $tasksEntity as $task) {
- //$task->delete();
- }
-
- var_dump('true');
-
- }
-
- public function actionCheckeippworks()
- {
- $userArr = [295,297,308,309,310,311,313,314,317,325,333,348,354,361,364,366,371,373,368,369,382,384,390,393,409,424,425,426,429];
- $accountsEntity = Accounts::find()->where(['in','id',$userArr])->andWhere(['company' => 3])->all();
- $GWparams = ['url' => 'http://' . Yii::$app->params['api']['domain'].'/Thingworx/Things/2050UserLibraryExp/Services/my_works',
- //'url' => 'http://devplatform.digitaldepot.ru:8085/Thingworx/Things/SMoPPIntegrationLibrary/Services/getUserWorks',
- 'param' => '',
- 'login' => 'ПройдаковИА',
- 'pass' => 'Ip15351112'
- ];
- $mainModel = new MainModel();
- $resArray = [];
- foreach( $accountsEntity as $user) {
- $tempArr = [];
- $GWparams['param'] = $user->uuid;
- $responseMyWorks = $mainModel->curlRequest2($GWparams);
- $listWorks = json_decode($responseMyWorks,true);
-
- $tempArr = ['id' => $user->id,'uuid' => $user->uuid,'response' => $listWorks['rows'][0]["result"],'responseAll' => $listWorks];
- $resArray[$user->name] = $tempArr;
- }
- $resArray = json_encode($resArray,true);
- LogDoneList::addLog('CheckIssueWorks',$resArray);
-
- //var_dump(json_decode(LogDoneList::findOne(83)->desc,true));
-
-
-
-
- }
-
-
- public function actionDopro()
- {
- //$procedureModel = new StartProjectForLocoModel();
- //$procedureModel->execute(49,208,'Э5К',100121,'Проект АСУ СГ № test');
- /*set taskId = (select max(t.id)
- from tasks t
- where t.input_id = projectId
- and t.text = tmpText
- and t.parent_id = 0);*/
- //$ttt = \app\models\procedure\AsusgAddCheckpointsToTaskModel::execute(27,18807);
-
- $JobPlanEntitty = AsusgJobplan::find()->where(['name' => 'Тормозное и пневматическое оборудование после ремонта испытать , отрегулировать согласно инструкции'])->one(); // 1204 1567
- $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 actionProctest()
- {
- //phpinfo();
- //$this->logger->setLog('text');
- $procedureModel = new ProcedureModel();
- $procedureModel->asusg_build_and_start_project_auto(27,210);
-
- }
-
- /*
- public function curlRequest2($params){
-
- $urlWithParam = $params['url'].'?user_id='. $params['param'] ;
-
- $curl = curl_init();
- curl_setopt($curl, CURLOPT_URL, $urlWithParam);
- curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
- curl_setopt($curl, CURLOPT_USERPWD, $params['login'] . ":" . $params['pass']);
- curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-Type: application/json","Accept: application/json"));
- curl_setopt($curl, CURLOPT_TIMEOUT, 20);
- curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
- curl_setopt($curl, CURLOPT_POST, 1);
- curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
- curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
- $result = curl_exec($curl);
- return $result;
- }
- */
-
- public function Getisabsentworks($listWorks = null, $GWparams ){
-
- if ( null == $listWorks) {
- return false;
- }
- $arrayIdWorks = [];
-
- foreach( $listWorks->data as $work ) {
- $arrayIdWorks[] = ($work->id_work)?$work->id_work:$work['id_work'];
- }
- if( empty($arrayIdWorks) and is_array($listWorks)) {
- foreach( $listWorks as $work ) {
- $arrayIdWorks[] = $work['id_work'];
- }
- }
-
- //$arrayIdWorks[] = 'c7cfdeb5-9293-4314-9958-15d15a297532';
- //$asusgJob2LaunchEntity = AsusgJob2Launch::find()->where(['not in','asusg_job_uuid_',$arrayIdWorks])->all();
-
- $asusgJob2LaunchEntity = (new \yii\db\Query())
- ->select(['t.assignees_arr','ai.id','t.status','t.id','jl.asusg_job_uuid'])
- //->select(['t.assignees_arr'])
- ->from('`asusg_job2launch` as `jl`')
- ->leftJoin('`tasks` as `t`', 'jl.id = t.asusg_job_mapped_id')
- ->rightJoin('`accounts_internal` as `ai`', 't.assignees_arr = cast(ai.id as char)')
- //->where(['jl.asusg_job_uuid' => $job_uuid])
- ->andWhere(['in','asusg_job_uuid',$arrayIdWorks])
- ->andWhere(['ai.uuid' => $GWparams['param']])
- ->andWhere(['<>','t.parent_id', 0])
- ->groupBy(['jl.asusg_job_uuid'])
- ->all();
-
- $resultArrWork = [];
- foreach( $asusgJob2LaunchEntity as $work ) {
- $resultArrWork[] = $work["asusg_job_uuid"];
- }
- array_diff ($arrayIdWorks, $resultArrWork);
- foreach( $listWorks->data as $works ) {
- if ( in_array($works->id_work, array_diff ($arrayIdWorks, $resultArrWork))) {
- $result[] = $works;
- }
- }
- if( empty($result) and is_array($listWorks)) {
- foreach( $listWorks as $work ) {
- if ( in_array($work['id_work'], array_diff ($arrayIdWorks, $resultArrWork))) {
- $result[] = $works;
- }
- }
- }
- return $result;
- }
-
-
- 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) {
- //var_dump($account->id,'<br>');
- $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));
- //var_dump(( !$online_mobile ),'<br>');
- if ( !$online_mobile ){
- continue;
- }
- $result[] = $account;//['id' => $account->id, 'uuid' => $account->uuid];
- }
-
- return $result;
- }
-
- public function startProject($params,$userInfo,$projecttypeId){
-
- $arrayResultTemp = [];
- $projectsModel = new ProjectsModel();
- foreach($params as &$item){
-
- $arrayResult = [];
- $arrayResult['loco_type'] = $item['info']['locomotive_series'];
- $arrayResult['loco_number'] = $item['info']["section_subnumber"];
- $arrayResult['action'] = $projecttypeId->id;
- $arrayResult['company'] = $userInfo->company;
- //$arrayResult['section_id'] = $item['info']["section_number"];
- $arrayResult['depo'] = '';
- $arrayResult['depo_service'] = '';
- $arrayResult['kind'] = '';
- $item['project'] = 'sdfsdfsd';//$projectsModel->ProjectsModel($arrayResult,$item['info']["section_number"]);
- $item['userInfo'] = $userInfo;
- $item['projecttypeId'] = $projecttypeId->id;
- }
- return $params;
-
- }
-
- public function getUserInfo($user)
- {
- if (!$user){
- return '';
- }
- $accountsEntity = Accounts::find()->where(['uuid' => $user['param'] ])->one();
- return $accountsEntity;
- }
-
- /*
- public function getTypeProject($user)
- {
- $projettypesEntity = Projecttypes::find()->select('id')->where(['company' => $user->company, 'name' => 'Проект из мэппинга'])->one();
- return $projettypesEntity;
-
- }
- */
- public function getTypeProject($onlineUser)
- {
- if (empty($onlineUser)) {
- return [];
- }
- //foreach($onlineUser as $user) {
- $company = $onlineUser->company;
- //}
- $projettypesEntity = Projecttypes::find()->select('id')->where(['company' => $company, 'name' => 'Проект из мэппинга'])->one();
-
- return $projettypesEntity;
-
- }
-
- 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');
- //return date('d.m.Y H:i', $timeobj);
- }
-
- // // устаревшая версия GetworksOnLoco
- /*
- public function GetworksOnLoco($listWorks)
- {
- $result = [];
- if (empty($listWorks)){
- return $result;
- }
- $arrayResult = [];
- 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) {
- 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;
- }
- */
-
- // Добавление не существующих работ в JobPlan ( сверхцикловые )
-
- 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 "<pre>";
- var_dump($asusgProjectEntity->errors);
-
- //var_dump("Выполнение процедуры => " . $res);
- echo "</pre>";
-
- $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 "<pre>";
- var_dump($asusgJob2LaunchEntity->id);
- var_dump($asusgJob2LaunchEntity->errors);
- //var_dump($sectionsEntity);
- echo "</pre>";
- $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) {
-
- $mappingapiModel = new \app\models\MappingapiModel();
- $dwResult = $mappingapiModel->workDetail($user->uuid,$work['id_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->time_limit = $dwResult['time_limit'];
- $asusgJob2LaunchEntity->outfit = $dwResult['outfit'];
- $asusgJob2LaunchEntity->name = $dwResult['work_name'];
- $asusgJob2LaunchEntity->section_name = $work["section_lit"];
- //$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->testIdpl2 = $tasksEntity->id;
- $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 '<br>';
-
- $countPriority = 1;
- ///////////////// ДОБАВЛЕНИЕ ТМЦ
-
- //$mappingapiModel = new \app\models\MappingapiModel();
- //var_dump($user->id-uuid,$work['id_work']);
- //$tmcString = $mappingapiModel->workDetail($user->uuid,$work['id_work']);
-
- if ( '' != $dwResult['tmcString']) {
- $tasksEntity3 = new Tasks();
- $tasksEntity3->parent_id = $tasksEntity->id; // +
- $tasksEntity3->status = 2; // +
- $tasksEntity3->priority = $countPriority; // +
- // $tasksEntity2->input_id = $job->asusgJob2Launch->asusg_project_id;
- $tasksEntity3->created = date("Y-m-d H:i;s"); // +
- $tasksEntity3->type = 2159; // +
- $tasksEntity3->assignees_arr = $user->id; // +
- $tasksEntity3->asusg_job_mapped_id = $asusgJob2LaunchEntity->id; // +
- $tasksEntity3->text = $dwResult['tmcString']; // +
- $tasksEntity3->mapping_comment = $dwResult['tmcString']; // +
- if ( $tasksEntity3->save()) {
- $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);
- }
- $countPriority++;
- }
-
- ///////////////////
-
-
- $tasksEntity2 = new Tasks();
- $tasksEntity2->parent_id = $tasksEntity->id;
- $tasksEntity2->status = 2;
- $tasksEntity2->priority = $countPriority;
- $tasksEntity2->created = date("Y-m-d H:i;s");
- $tasksEntity2->type = Yii::$app->params['supercycletype'];
- $tasksEntity2->assignees_arr = $user->id;
- $tasksEntity2->asusg_job_mapped_id = $asusgJob2LaunchEntity->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()) {
- ///////////////////
- //$query3 = "call asusg_add_checkpoints_to_task(" . $user->id . ",'" . $tasksEntity2->id . "')";
- //$resProc = Yii::$app->db->createCommand($query3)->query();
- ///////////////////
- $this->logger->setLog('в Tasks была добавлена КОМАНДА => "'. $work['work_name'] . '" id => '.$tasksEntity2->id );
- } else {
- $this->logger->setLog('в Tasks была НЕ добавлена КОМАНДА => "'. $work['work_name'] . '" id => '.$tasksEntity2->id);
- }
-
-
-
- $projId = $this->generateProject($work);
-
- $tasksEntity->input_id = $projId;
- if ($tasksEntity->save()) {
- $this->logger->setLog('привязка ЗАДАЧИ ( id = '.$tasksEntity->id.') прошла успешно');
- }
-
-
- $tasksEntity2->input_id = $projId;
- $this->logger->setLog('2 =>' .$asusgJob2LaunchEntity->id);
- if($tasksEntity2->save()){
- $this->logger->setLog('привязка КОМАНДЫ ( id = '.$tasksEntity2->id.') прошла успешно');
- }
-
- $tasksEntity3->input_id = $projId;
-
- if($tasksEntity3->save()){
- $this->logger->setLog('привязка КОМАНДЫ ( id = '.$tasksEntity2->id.') прошла успешно');
- }
- //echo "<pre>";
- //var_dump($tasksEntity2->errors,$tasksEntity->errors);
- //echo "</pre>";
-
- }
-
- }
-
-
-
- public function addJob2launch3($listWorks,$user)
- {
-
- foreach ( $listWorks as $work) {
-
- $mappingapiModel = new \app\models\MappingapiModel();
- $dwResult = $mappingapiModel->workDetail($user->uuid,$work['id_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 "<pre>";
- //var_dump($JobPlanEntitty->id,$projtype);
- //var_dump($JobPlanEntitty->id,$jsusgJob2CommandEntity);
- //echo "</pre>";
- //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;
- $asusgJob2LaunchEntity->time_limit = $dwResult['time_limit'];
- $asusgJob2LaunchEntity->outfit = $dwResult['outfit'];
- $asusgJob2LaunchEntity->name = $dwResult['work_name'];
- $asusgJob2LaunchEntity->section_name = $work["section_lit"];
- 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->testIdpl3 = $tasksEntity->id;
- $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 '<br>';
- $this->logger->setLog(' колво записей => ' . count($jsusgJob2CommandEntity) . 'type => '. gettype($jsusgJob2CommandEntity));
- $this->logger->setLog($JobPlanEntitty->id . ' - ' . $projtype );
-
- $arrJ = [];
- $countPriority = 1;
-
- ///////////////// ДОБАВЛЕНИЕ ТМЦ
- $mappingapiModel = new \app\models\MappingapiModel();
- //var_dump($user->id-uuid,$work['id_work']);
- $tmcString = $mappingapiModel->workDetail($user->uuid,$work['id_work']);
-
- if ( '' != $dwResult['tmcString']) {
- $tasksEntity2 = new Tasks();
- $tasksEntity2->parent_id = $tasksEntity->id; // +
- $tasksEntity2->status = 2; // +
- $tasksEntity2->priority = $countPriority; // +
- // $tasksEntity2->input_id = $job->asusgJob2Launch->asusg_project_id;
- $tasksEntity2->created = date("Y-m-d H:i;s"); // +
- $tasksEntity2->type = 2159; // +
- $tasksEntity2->assignees_arr = $user->id; // +
- $tasksEntity2->asusg_job_mapped_id = $asusgJob2LaunchEntity->id;
- $tasksEntity2->text = $dwResult['tmcString']; // +
- $tasksEntity2->mapping_comment = $dwResult['tmcString']; // +
- if ( $tasksEntity2->save()) {
- $arrJ[] = $tasksEntity2->id;
- $query3 = "call asusg_add_checkpoints_to_task(" . $user->id . ",'" . $tasksEntity2->id . "')";
- $resProc = Yii::$app->db->createCommand($query3)->query();
- $logResProc = 'false';
- if ($resProc){
- $logResProc = 'true';
- }
- $this->logger->setLog('в Tasks была добавлена КОМАНДА => "'. $work['work_name'] . '" id => '.$tasksEntity2->id. ' процедура => ' . $logResProc);
- } else {
- $this->logger->setLog('в Tasks была НЕ добавлена КОМАНДА => "'. $work['work_name'] . '" id => '.$tasksEntity2->id);
- }
- $countPriority++;
- }
-
- ///////////////////
-
- foreach($jsusgJob2CommandEntity as $job) {
- $this->logger->setLog('3 =>'. $job->jobplantie->id);
- $tasksEntity2 = new Tasks();
- $tasksEntity2->parent_id = $tasksEntity->id;
- $tasksEntity2->status = 2;
- $tasksEntity2->priority = $countPriority;
- // $tasksEntity2->input_id = $job->asusgJob2Launch->asusg_project_id;
- $tasksEntity2->created = date("Y-m-d H:i;s");
- $tasksEntity2->type = $job->smopp_cmd_id;//Yii::$app->params['supercycletype'];
- $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[] = $tasksEntity2->id;
- ///////////////////
- //$query3 = "call asusg_add_checkpoints_to_task(" . $user->id . ",'" . $tasksEntity2->id . "')";
- //$resProc = Yii::$app->db->createCommand($query3)->query();
- ///////////////////
- $this->logger->setLog('в Tasks была добавлена КОМАНДА => "'. $work['work_name'] . '" id => '.$tasksEntity2->id);
- } else {
- $this->logger->setLog('в Tasks была НЕ добавлена КОМАНДА => "'. $work['work_name'] . '" id => '.$tasksEntity2->id);
- }
- $countPriority++;
- }
-
-
-
-
- $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 "<pre>";
- //var_dump($job->asusgJob2Launch->asusg_project_id);
- var_dump($tasksEntity2->errors,$tasksEntity->errors);
- echo "</pre>";
-
- }
- }
-
-
-
- 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 "<pre>";
- var_dump($arr);
-
- var_dump("Выполнение процедуры => " . $res);
- echo "</pre>";
- }
- }
-
-
- 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->tasks = $this->testIdpl2;
- $projectsLocotech->save();
- $result = $projectsLocotech->id;
- var_dump($this->testIdpl2);
- $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->tasks = $this->testIdpl3;
- $projectsLocotech->save();
- var_dump($this->testIdpl3);
- $result = $projectsLocotech->id;
- $this->logger->setLog('Такого проекта еще не было пришлось создать. Ид проекта => '. $result);
-
- //var_dump($result);
- return $result;
- }
-
- private function prepareListWorks($listWorks) {
-
- $result = [];
- $dataArr = [];
- if ( null == $listWorks || empty($listWorks)) {
- return [];
- }
-
- var_dump();
- foreach ( $listWorks["rows"] as $rows) {
-
- $rows["result"] = json_decode($rows["result"],true);
-
- foreach ( $rows["result"]['data'] as $key => $data) {
-
- //echo '<pre>';
- // var_dump($data);
- // echo '</pre>';
- $tempArray = [];
- $tempArray["eq_serie"] = explode(" ",$data["equip_sect_name"])[0];
- $eq = explode(" ",$data["equip_sect_name"])[1];
- $tempArray["eq_number"] = explode("/",$eq)[0];
-
- //echo '<pre>';
- //var_dump($tempArray["eq_number"]);
- //echo '</pre>';
- foreach ( $data["sections"] as $sections) {
- $tempArray["section_id"] = $sections["id_section"];
- $tempArray["section_lit"] = $sections["section_name"];
- //$this->getLocoInfoMore($sections["section_subnumber"]);
- $tempArray["section_num"] = $sections["section_subnumber"];
- $tempArray["section_DK"] = $sections["section_dk"];
- // echo '<pre>';
- // var_dump($sections);
- // echo '</pre>';
-
- 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"];
-
- //$extraSection = $this->getSectionInfo( $tempArray["section_id"], $tempArray["repair_name"]);
-
- //$tempArray["section_num"] = $extraSection['section_num'];
- //$tempArray['section_DK'] = $extraSection['section_DK'];
-
- $dataArr[] = $tempArray;
-
- foreach ( $works['workers'] as $worker) {
- //echo '<pre>';
- //var_dump($worker);
- //echo '</pre>';
- }
- }
- }
- }
- $result['result'] = 'true';
- $result['data'] = $dataArr;
- break;
- }
- return $result;
- }
-
- }
|