MappingHandlerMWController.php 57 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161
  1. <?php
  2. namespace app\controllers;
  3. use app\models\ElasticLog;
  4. use Yii;
  5. use app\models\Logs;
  6. use yii\web\Controller;
  7. use app\models\MainModel;
  8. use app\models\ProcedureModel;
  9. use app\models\entity\Tasks;
  10. use app\models\ProjectsModel;
  11. use app\models\entity\Accounts;
  12. use app\models\entity\Sections;
  13. use app\models\LocomotiveModel;
  14. use app\models\MappingapiModel;
  15. use app\models\entity\Tasktypes;
  16. use \app\models\LogEippResponse;
  17. use app\models\logger\LoggerFile;
  18. use app\models\entity\Repairtypes;
  19. use app\models\entity\Projecttypes;
  20. use app\models\entity\AsusgProject;
  21. use app\models\entity\AsusgJobPlan;
  22. use app\models\MappingHandlerModel;
  23. use app\models\entity\AsusgJob2Launch;
  24. use app\models\entity\AsusgProjectType;
  25. use app\models\entity\LocomotiveSeries;
  26. use app\models\entity\ProjectsLocotech;
  27. use app\models\entity\AsusgJob2Command;
  28. use app\models\procedure\StartProjectForLocoModel;
  29. class MappinghandlermwController extends Controller
  30. {
  31. private $logger;
  32. private $company;
  33. private $sectionList;
  34. private $testIdpl2;
  35. private $testIdpl3;
  36. private $datailWorkArray = [];
  37. private $locoGetInfoArray = [];
  38. private $logEtn;
  39. private $prepareLogString = '';
  40. private $issetLaunch = false;
  41. public function beforeAction($action)
  42. {
  43. parent::beforeAction($action);
  44. $logEtn = new Logs();
  45. $logEtn->index_t = strtotime(date("Y-m-d H:i:s"));
  46. $logEtn->section = 3;
  47. $this->logEtn = $logEtn;
  48. $log = new LoggerFile();
  49. $this->logger = new MappingHandlerModel($log);
  50. return true;
  51. }
  52. // запускается периодически через крон
  53. public function actionGetworks($company)
  54. {
  55. //$this->sectionList();
  56. //exit;
  57. $this->company = $company;
  58. $GWparams = [
  59. 'url' => 'http://' . Yii::$app->params['api']['domain'].'/Thingworx/Things/2050UserLibraryExp/Services/my_works',
  60. //'url' => 'http://devplatform.digitaldepot.ru:8085/Thingworx/Things/SMoPPIntegrationLibrary/Services/getUserWorks',
  61. 'param' => '',
  62. 'login' => 'ПройдаковИА',
  63. 'pass' => 'Ip15351112'
  64. ];
  65. // список сотрудников онлайн
  66. $onlineUser = $this->getOnlineMobileUser($company);
  67. if( 0 == count($onlineUser)) {
  68. return 'Нет сотрудников онлайн';
  69. }
  70. //$this->logger->setLog('ID пользователя => ' . (int)$_SESSION["id"]);
  71. $this->prepareLogString .= "\n=================== СТАРТ МЕППИНГА ==================================\n";
  72. $this->prepareLogString .= date("Y-m-d H:i:s") . "\n";
  73. $mainModel = new MainModel();
  74. // для каждого сотрудника онлайн запускаем проекты если они еще не запущены
  75. $setOnlineWorkers = [];
  76. $this->prepareLogString .= "Колличество cотрудников онлайн :" . count($onlineUser) ."\n";
  77. foreach($onlineUser as $user) {
  78. $buisy = $this->buisyEmployee($user);
  79. if( $buisy || ('' == $user->uuid and null == $user->uuid )) {
  80. continue;
  81. }
  82. $GWparams['param'] = $user->uuid;
  83. $listWorks2 = json_decode($mainModel->curlRequest2($GWparams),true);
  84. $listWorks2 = $this->prepareListWorks($listWorks2);
  85. //foreach ( $listIssetWorks3 as $work) { !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  86. //echo '<pre>';
  87. //var_dump($user->id);
  88. //var_dump($listWorks2);
  89. //echo '</pre>';
  90. foreach ( $listWorks2['data'] as $work) {
  91. $mappingapiModel = new \app\models\MappingapiModel();
  92. $this->datailWorkArray[$work['id_work']] = $mappingapiModel->workDetail($user->uuid,$work['id_work']);
  93. foreach( $this->datailWorkArray[$work['id_work']]['workers_uuid'] as $uuid) {
  94. $setOnlineWorkers[] = $uuid;
  95. }
  96. }
  97. $this->prepareLogString .= $mappingapiModel->prepareLogString."\n";
  98. $this->prepareLogString .= "Вот это сейчас должен получить работу :" . $user->id . "( ".$user->name." )\n";
  99. }
  100. $setOnlineWorkers = array_unique($setOnlineWorkers);
  101. $onlineUserModificate = \app\models\entity\Accounts::find()->where(['in','uuid',$setOnlineWorkers])->andWhere(['company' =>$company])->all();
  102. $this->prepareLogString .= "Колличество cотрудников онлайн для них есть работа ( с напарниками ):" . count($setOnlineWorkers)."\n";
  103. foreach($onlineUserModificate as $user) {
  104. //var_dump($user->id);continue;
  105. if( '' == $user->uuid and null == $user->uuid || 349 == $user->id) {
  106. continue;
  107. }
  108. $this->issetLaunch = false;
  109. $GWparams['param'] = $user->uuid;
  110. ElasticLog::eipp($GWparams, 'my_works', 0);
  111. $listWorks2 = $mainModel->curlRequest2($GWparams);
  112. $unixTime = time();
  113. LogEippResponse::addLog($unixTime.'gw'. $user->id ,$listWorks2,'Получение работ от ЕИПП');
  114. ElasticLog::eipp($listWorks2, 'my_works', 0, false);
  115. $this->prepareLogString .= "\nMY_WORK =====>\n";
  116. $this->prepareLogString .= "Параметры: \n user_id =>". $GWparams['param'] .".\n";
  117. $this->prepareLogString .= "Строка запроса : \n " . $GWparams['url'] .".\n";
  118. $this->prepareLogString .= "Вот тут можно посмотреть что ЕИПП прислал по запросу http://dev.prmsys.net/api/mappinghandler/eippresponse?indx=".$unixTime."\n";
  119. $this->prepareLogString .= "MY_WORK ======>\n\n";
  120. $listWorks2 = json_decode($listWorks2,true);
  121. $listWorks2 = $this->prepareListWorks($listWorks2);
  122. /// НЕТ ДВУХ ПОЛЕЙ ["section_num"] ["section_DK"]
  123. //echo '<pre>';
  124. //var_dump($user->id);
  125. //var_dump('Привет', $user->id , "\n");
  126. //echo '</pre>';
  127. //continue;
  128. //$this->logEtn->addlogText('','sdfsdfsdf');
  129. $this->prepareLogString .= "Колличество работ из еипп: ". count($listWorks2['data'])." \n Cотрудник:" . $user->id . "( ". $user->name ." )\n";
  130. $listIsabsentWorks2 = $this->Getisabsentworksjp($listWorks2); // вновь утвержденный план 1 | вернет список работ кот нет ( в JobPlan )
  131. $listIssetWorks3 = $this->Getissetworksjp($listWorks2);
  132. $this->prepareLogString .= 'Колличество работ из еипп ( сверхциклвая ): '. count($listIsabsentWorks2)."\n";
  133. $this->prepareLogString .= 'Колличество работ из еипп ( цикловая ): '. count($listIssetWorks3)."\n";
  134. $this->prepareLogString .= "\n СВЕРХЦИКЛОВЫЕ \n\n";
  135. //$addJob2launch2 = $this->addJob2launch2($listIsabsentWorks2,$user);
  136. $this->prepareLogString .= "\n ЦИКЛОВЫЕ \n\n";
  137. //$addJob2launch3 = $this->addJob2launch3($listIssetWorks3,$user);
  138. if (!$this->issetLaunch) {
  139. continue;
  140. }
  141. $this->logger->setLog("Интеграция сверхцикловых работ прошла без падений!");
  142. $this->logger->setLog("=====================================================\n\n");
  143. }
  144. return true;//$listWorks;
  145. }
  146. public function actionDojob()
  147. {
  148. Yii::$app->db->createCommand('update `accounts_internal` set `last_seen_mobile` = NOW() where id in (351,349,350)')->execute();
  149. }
  150. public function actionDopro()
  151. {
  152. $JobPlanEntitty = AsusgJobplan::find()->where(['name' => 'Тормозное и пневматическое оборудование после ремонта испытать , отрегулировать согласно инструкции'])->one(); // 1204 1567
  153. $jsusgJob2CommandEntity = AsusgJob2Command::find()->where(['asusg_job_id' => $JobPlanEntitty->id])->all();
  154. foreach($jsusgJob2CommandEntity as $job) {
  155. echo '<pre>';
  156. var_dump('3 =>'. $job->id, $job->asusg_job_id);
  157. var_dump('3 =>'. $job->jobplantie->id);
  158. echo '</pre>';
  159. }
  160. exit;
  161. }
  162. public function actionProctest()
  163. {
  164. $procedureModel = new ProcedureModel();
  165. $procedureModel->asusg_build_and_start_project_auto(27,210);
  166. }
  167. public function Getisabsentworksjp( $listWorks = null){
  168. $result = [];
  169. if ( null == $listWorks) {
  170. return false;
  171. }
  172. foreach( $listWorks['data'] as $work) {
  173. $asusgJobPlan = AsusgJobPlan::find()->where(['name' => $work['work_name']])->one();
  174. if ( null == $asusgJobPlan ){
  175. $result[] = $work;
  176. }
  177. }
  178. return $result;
  179. }
  180. public function Getissetworksjp( $listWorks = null){
  181. $result = [];
  182. if ( null == $listWorks) {
  183. return false;
  184. }
  185. foreach( $listWorks['data'] as $work) {
  186. $asusgJobPlan = AsusgJobPlan::find()->where(['name' => $work['work_name']])->one();
  187. if ( null != $asusgJobPlan ){
  188. $result[] = $work;
  189. }
  190. }
  191. return $result;
  192. }
  193. public function getOnlineMobileUser($company){
  194. $result = [];
  195. $accountsEntity = \app\models\entity\Accounts::find()->where(['company' => $company])->all();
  196. foreach ($accountsEntity as $account) {
  197. //var_dump($account->id,'<br>');
  198. $last_seen_mobile = ( null != $account->last_seen_mobile )? new \DateTime($account->last_seen_mobile): $account->last_seen_mobile ;
  199. $online_mobile = $this->OnlineAccountCheck($this->TimeString($last_seen_mobile));
  200. //var_dump(( !$online_mobile ),'<br>');
  201. if ( !$online_mobile ){
  202. continue;
  203. }
  204. $result[] = $account;//['id' => $account->id, 'uuid' => $account->uuid];
  205. }
  206. return $result;
  207. }
  208. public function OnlineAccountCheck($last_seen)
  209. {
  210. $last_seen = date($last_seen);
  211. $time = (time()-strtotime($last_seen));
  212. if ($time <= Yii::$app->params['onlineMobileTimeoutSeconds'])
  213. return true;
  214. return false;
  215. }
  216. public function TimeString($timeobj)
  217. {
  218. if ($timeobj != null)
  219. return $timeobj->format('d.m.Y H:i');
  220. //return date('d.m.Y H:i', $timeobj);
  221. }
  222. public function getProjectType($repairName,$serieName)
  223. {
  224. $result = null;
  225. $repairtypesEntity = Repairtypes::findOne(['name' => $repairName]);
  226. $locomotiveSeriesEntity = LocomotiveSeries::findOne(['name' => $serieName]);
  227. $asusgProjectTypeEntity = AsusgProjectType::findOne(['repair_type' => $repairtypesEntity->id , 'loco_serie_id' => $locomotiveSeriesEntity->id]);
  228. if ( null != $asusgProjectTypeEntity->id ) {
  229. $result = $asusgProjectTypeEntity->id;
  230. }
  231. return $result;
  232. }
  233. public function addJob2launch2($listWorks,$user)
  234. {
  235. foreach ( $listWorks as $work) {
  236. $dwResult = $this->datailWorkArray[$work['id_work']];
  237. $this->prepareLogString .= "Название работы:". $work['work_name']. ".\n UUID работы: " . $work['id_work'] . "\n\n";
  238. $this->prepareLogString .= "\n 1. ДОБАВЛЕНИЕ В LAUNCH \n\n";
  239. $asusgJob2LaunchEntity = AsusgJob2Launch::findOne(['asusg_job_uuid' => $work['id_work']]);
  240. $let = mb_substr($work["section_lit"], -1);
  241. // ВАЖНО ПОНИМАТЬ !!!!
  242. // если проект для такой работы уже есть, его создавать нельзя
  243. // но можно прикреплять к нему задачи. Сотрудник который зашел первый получает и замеры и тмц и работы
  244. // тот кто зашел вторым получает только работы.
  245. //$mappingapiModel = new \app\models\MappingapiModel();
  246. //$dwResult = $mappingapiModel->workDetail($user->uuid,$work['id_work']);
  247. //echo "<pre>";
  248. //var_dump($user->id);
  249. //var_dump($work['work_name']);
  250. //var_dump($dwResult["hw_measurements_status"]);
  251. //var_dump($asusgJob2LaunchEntity->id);
  252. //echo "</pre>";
  253. //continue;
  254. $projtype = $this->getProjectType($work["repair_name"],$work["eq_serie"]);
  255. $switcher = $asusgJob2LaunchEntity;
  256. if ( null == $switcher) {
  257. $resultArr = [];
  258. $asusgJob2LaunchEntity = new AsusgJob2Launch();
  259. $asusgJob2LaunchEntity->asusg_jobplan_id = Yii::$app->params['supercycleplan'];
  260. $asusgJob2LaunchEntity->asusg_employee_id1 = $user->id;
  261. $asusgJob2LaunchEntity->asusg_job_uuid = $work['id_work'];
  262. $asusgJob2LaunchEntity->employees_uuid = $user->uuid;
  263. $asusgJob2LaunchEntity->section_uuid = $work["section_id"];
  264. $asusgJob2LaunchEntity->asusg_project_id = 0;
  265. $asusgJob2LaunchEntity->job_order = 0;
  266. $asusgJob2LaunchEntity->time_limit = $dwResult['time_limit'];
  267. $asusgJob2LaunchEntity->outfit = $dwResult['outfit'];
  268. $asusgJob2LaunchEntity->name = $work['work_name'];
  269. $asusgJob2LaunchEntity->section_name = $work["section_lit"];
  270. //$asusgJob2LaunchEntity->asusg_projecttype_id = 0;
  271. $asusgJob2LaunchEntity->asusg_projecttype_id = $projtype;
  272. if (!$asusgJob2LaunchEntity->save()) {
  273. $this->logger->setLog('в Job2launch не добавилась работа => "'. $work['work_name']. '" Добавление работ будет пропущено так как такая запись уже есть.');
  274. continue;
  275. }
  276. $this->issetLaunch = true;
  277. $this->logger->setLog($this->prepareLogString);
  278. $this->prepareLogString = '';
  279. $this->logger->setLog('в Job2launch была добавлена работа => "'. $work['work_name'].'"');
  280. /// сначала генерю проект
  281. $projId = $this->generateProject($work);
  282. /// сначала генерю проетк
  283. } else {
  284. $userUuidArr = explode(',', $asusgJob2LaunchEntity->employees_uuid);
  285. if ( in_array( $user->uuid , $userUuidArr)) { // если сотрудник уже привязан к лаунчу
  286. $this->logger->setLog('сотрудник '.$user->name .' ('.$user->id.') уже привязан к лаунчу'. $asusgJob2LaunchEntity->id);
  287. continue;
  288. } else {
  289. $asusgJob2LaunchEntity->employees_uuid .= ','. $user->uuid;
  290. $asusgJob2LaunchEntity->save();
  291. $this->logger->setLog('сотрудники ('.$asusgJob2LaunchEntity->employees_uuid.') привязаны к лаунчу'. $asusgJob2LaunchEntity->id);
  292. }
  293. //continue;
  294. $this->prepareLogString .= "ВОТ ТУТ Я ХОТЕЛ ПОЛУЧИТЬ ИД ПРОЕКТА ЧЕРЕЗ ЗАДАЧУ( launch_id = ".$asusgJob2LaunchEntity->id.") => " . $asusgJob2LaunchEntity->tasks->id .", ВОТ ЧТО ПОЛУЧИЛ => " . $asusgJob2LaunchEntity->tasks->input_id ."!\n";
  295. $projId = $asusgJob2LaunchEntity->tasks->input_id;
  296. }
  297. /////////////// ДОБАВЛЕНИЕ ЗАДАЧИ
  298. $this->prepareLogString .= "\n 3. ДОБАВЛЕНИЕ ЗАДАЧИ \n\n";
  299. $tasktypesEntity = Tasktypes::find()->where(['name' => 'Секция '.$let.', задача','company' => $this->company])->one();
  300. $tasksEnt = Tasks::find()->where(['parent_id' => 0,'asusg_job_mapped_id' => $asusgJob2LaunchEntity->id,'assignees_arr' => $user->id])->one();
  301. if ( null != $tasksEnt) {
  302. continue;
  303. }
  304. $this->logger->setLog($this->prepareLogString);
  305. $this->prepareLogString = '';
  306. $tasksEntity = new Tasks();
  307. $tasksEntity->parent_id = 0;
  308. $tasksEntity->status = 2;
  309. $tasksEntity->type = $tasktypesEntity->id;
  310. $tasksEntity->assignees_arr = $user->id;
  311. $tasksEntity->preferred_assignee = $user->id;
  312. $tasksEntity->created = date("Y-m-d H:i;s");
  313. $tasksEntity->asusg_job_mapped_id = $asusgJob2LaunchEntity->id;
  314. $tasksEntity->mapping_comment = $work["outfit"] . ': ' . $work['work_name'];
  315. $tasksEntity->text = $work["section_lit"] . "\n" . $work["outfit"] . ': ' . $work['work_name'] . "\n" . $dwResult['workers'];
  316. if($tasksEntity->save()) {
  317. $this->testIdpl2 = $tasksEntity->id;
  318. $this->logger->setLog('в Tasks была добавлена ЗАДАЧА => "'. $work['work_name'] . '" id => '.$tasksEntity->id);
  319. } else {
  320. $this->logger->setLog('в Tasks была НЕ добавлена ЗАДАЧА => "'. $work['work_name'] . '" id => '.$tasksEntity->id);
  321. }
  322. //var_dump($tasksEntity->errors,$user->id); echo '<br>';
  323. //$countPriority = 1;
  324. if ( null == $switcher) {
  325. ///////////////// ДОБАВЛЕНИЕ ТМЦ
  326. //$mappingapiModel = new \app\models\MappingapiModel();
  327. //var_dump($user->id-uuid,$work['id_work']);
  328. //$tmcString = $mappingapiModel->workDetail($user->uuid,$work['id_work']);
  329. $this->logger->setLog("\n ДОБАВЛЕНИЕ ТМЦ " . strlen($dwResult['tmcString']) . "\n");
  330. if ( '' != $dwResult['tmcString']) {
  331. $tasksEntity3 = new Tasks();
  332. $tasksEntity3->parent_id = $tasksEntity->id; // +
  333. $tasksEntity3->status = 2; // +
  334. $tasksEntity3->priority = Yii::$app->params['countPriority']; // +
  335. // $tasksEntity2->input_id = $job->asusgJob2Launch->asusg_project_id;
  336. $tasksEntity3->created = date("Y-m-d H:i;s"); // +
  337. $tasksEntity3->type = 2159; // +
  338. $tasksEntity3->assignees_arr = $user->id; // +
  339. $tasksEntity3->preferred_assignee = $user->id; // +
  340. $tasksEntity3->asusg_job_mapped_id = $asusgJob2LaunchEntity->id; // +
  341. $tasksEntity3->text = $dwResult['tmcString']; // +
  342. $tasksEntity3->mapping_comment = $dwResult['tmcString']; // +
  343. $tasksEntity3->input_id = $projId;
  344. if ( $tasksEntity3->save()) {
  345. $query3 = "call asusg_add_checkpoints_to_task(" . $user->id . ",'" . $tasksEntity3->id . "')";
  346. $resProc = Yii::$app->db->createCommand($query3)->query();
  347. $logResProc = 'false';
  348. if ($resProc){
  349. $logResProc = 'true';
  350. }
  351. $this->logger->setLog('в Tasks была добавлена КОМАНДА => "'. $work['work_name'] . '" id => '.$tasksEntity3->id. ' процедура => ' . $logResProc . ' приоритет =>' . Yii::$app->params['countPriority']);
  352. } else {
  353. $this->logger->setLog('в Tasks была НЕ добавлена КОМАНДА => "'. $work['work_name'] . '" id => '.$tasksEntity3->id );
  354. }
  355. Yii::$app->params['countPriority']++;
  356. }
  357. ///////////////////
  358. ///////////////// ДОБАВЛЕНИЕ ЗАМЕРОВ ЭТАП 0
  359. $this->logger->setLog( "\n 4. ДОБАВЛЕНИЕ ЗАМЕРОВ ЭТАП 0 \n");
  360. //if ( Yii::$app->params['api']['hw_msrmnt_stat'][ $dwResult["hw_measurements_status"] ]) { // выполнение hw_measurements_status = waiting
  361. $paramsMeaserm = ['input_id' => $projId, 'assignees_arr' => $user->id, 'work' => $work,'stage' => 0, 'parent_id' => $tasksEntity->id , 'stage_type' => 'доремонтный','asusg_job_mapped_id' => $asusgJob2LaunchEntity->id ];
  362. Yii::$app->params['api']['mesrmntParam'] = $paramsMeaserm;
  363. MappingapiModel::workMeasurements($work['id_work'],$user->uuid);
  364. //}
  365. ///////////////////
  366. }
  367. /////////////// НА РЕМОНТ
  368. $this->logger->setLog("\n 5. ДОБАВЛЕНИЕ НА РЕМОНТ \n");
  369. $tasksEntity2 = new Tasks();
  370. $tasksEntity2->parent_id = $tasksEntity->id;
  371. $tasksEntity2->status = 2;
  372. $tasksEntity2->priority = Yii::$app->params['countPriority'];
  373. $tasksEntity2->created = date("Y-m-d H:i;s");
  374. $tasksEntity2->type = Yii::$app->params['supercycletype'];
  375. $tasksEntity2->assignees_arr = $user->id;
  376. $tasksEntity2->preferred_assignee = $user->id;
  377. $tasksEntity2->asusg_job_mapped_id = $asusgJob2LaunchEntity->id;
  378. $tasksEntity2->text = $work["eq_serie"] . ' '.$work["section_lit"] . ', '. $work["outfit"] . ': ' . $work['work_name'];
  379. $tasksEntity2->mapping_comment = $work["outfit"] . ': ' . $work['work_name'];
  380. if ( $tasksEntity2->save()) {
  381. ///////////////////
  382. //$query3 = "call asusg_add_checkpoints_to_task(" . $user->id . ",'" . $tasksEntity2->id . "')";
  383. //$resProc = Yii::$app->db->createCommand($query3)->query();
  384. ///////////////////
  385. $this->logger->setLog('в Tasks была добавлена КОМАНДА => "'. $work['work_name'] . '" id => '.$tasksEntity2->id . ' приоритет =>' . Yii::$app->params['countPriority']. ', cтатус => ' . $tasksEntity2->status);
  386. } else {
  387. $this->logger->setLog('в Tasks была НЕ добавлена КОМАНДА => "'. $work['work_name'] . '" id => '.$tasksEntity2->id);
  388. }
  389. // $projId = $this->generateProject($work);
  390. $tasksEntity->input_id = $projId;
  391. if ($tasksEntity->save()) {
  392. $this->logger->setLog('привязка ЗАДАЧИ ( id = '.$tasksEntity->id.') прошла успешно ( "assignees_arr" => ' . $tasksEntity->assignees_arr . ')');
  393. }
  394. $tasksEntity2->input_id = $projId;
  395. if($tasksEntity2->save()){
  396. $this->logger->setLog('привязка КОМАНДЫ ( id = '.$tasksEntity2->id.') прошла успешно ( "assignees_arr" => ' . $tasksEntity2->assignees_arr . ')');
  397. }
  398. //if ( null != $tasksEntity3) {
  399. // $tasksEntity3->input_id = $projId;
  400. //
  401. // if($tasksEntity3->save()){
  402. // $this->logger->setLog('привязка КОМАНДЫ ТМЦ ( id = '.$tasksEntity3->id.') прошла успешно');
  403. // }
  404. //}
  405. if ( null == $switcher) {
  406. ///////////////// ДОБАВЛЕНИЕ ЗАМЕРОВ ЭТАП 1
  407. $this->logger->setLog("\n 6. ДОБАВЛЕНИЕ ЗАМЕРОВ ЭТАП 1 \n");
  408. //if ( Yii::$app->params['api']['hw_msrmnt_stat'][ $dwResult["hw_measurements_status"] ]) { // выполнение hw_measurements_status = waiting
  409. $paramsMeaserm['stage'] = 1;
  410. $paramsMeaserm['stage_type'] = 'контрольный';
  411. $paramsMeaserm['asusg_job_mapped_id'] = $asusgJob2LaunchEntity->id;
  412. Yii::$app->params['api']['mesrmntParam'] = $paramsMeaserm;
  413. MappingapiModel::workMeasurements($work['id_work'],$user->uuid);
  414. //}
  415. ///////////////////
  416. ///////////////// ДОБАВЛЕНИЕ ЗАМЕРОВ ЭТАП 2
  417. $this->logger->setLog("\n 7. ДОБАВЛЕНИЕ ЗАМЕРОВ ЭТАП 2 \n");
  418. //if ( Yii::$app->params['api']['hw_msrmnt_stat'][ $dwResult["hw_measurements_status"] ]) { // выполнение hw_measurements_status = waiting
  419. $paramsMeaserm['stage'] = 2;
  420. $paramsMeaserm['stage_type'] = 'послеремонтный';
  421. $paramsMeaserm['asusg_job_mapped_id'] = $asusgJob2LaunchEntity->id;
  422. Yii::$app->params['api']['mesrmntParam'] = $paramsMeaserm;
  423. MappingapiModel::workMeasurements($work['id_work'],$user->uuid);
  424. //}
  425. ///////////////////
  426. }
  427. //( все правильно сначала 2 потом 1)
  428. //echo "<pre>";
  429. //var_dump($tasksEntity2->errors,$tasksEntity->errors);
  430. //echo "</pre>";
  431. }
  432. Yii::$app->params['countPriority'] = 1;
  433. }
  434. public function addJob2launch3($listWorks,$user)
  435. {
  436. foreach ( $listWorks as $work) {
  437. $this->prepareLogString .= "\n 1. ДОБАВЛЕНИЕ В LAUNCH \n\n";
  438. $asusgJob2LaunchEntity = AsusgJob2Launch::findOne(['asusg_job_uuid' => $work['id_work']]);
  439. $let = mb_substr($work["section_lit"], -1);
  440. // ВАЖНО ПОНИМАТЬ !!!!
  441. // если проект для такой работы уже есть, его создавать нельзя
  442. // но можно прикреплять к нему задачи. Сотрудник который зашел первый получает и замеры и тмц и работы
  443. // тот кто зашел вторым получает только работы.
  444. //$mappingapiModel = new \app\models\MappingapiModel();
  445. //$dwResult = $mappingapiModel->workDetail($user->uuid,$work['id_work']);
  446. $dwResult = $this->datailWorkArray[$work['id_work']];
  447. //echo "<pre>";
  448. //var_dump($user->id);
  449. //var_dump($work['work_name']);
  450. //var_dump($dwResult["hw_measurements_status"]);
  451. //var_dump($dwResult);
  452. //var_dump($user->uuid);
  453. //echo "</pre>";
  454. //continue;
  455. $projtype = $this->getProjectType($work["repair_name"],$work["eq_serie"]);
  456. $JobPlanEntitty = AsusgJobplan::find()->where(['name' => $work["work_name"]])->one(); // 1204 1567
  457. if ( null == $JobPlanEntitty->id ) {
  458. $this->prepareLogString .= " ВНИМАНИЕ не нашел работу в AsusgJobplan ('name' => ".$work['work_name'].")\n\n";
  459. }
  460. $jsusgJob2CommandEntity = AsusgJob2Command::find()->where(['asusg_job_id' => $JobPlanEntitty->id, 'asusg_projecttype_id' => $projtype ])->all();
  461. $switcher = $asusgJob2LaunchEntity;
  462. if ( null == $switcher) {
  463. $resultArr = [];
  464. $asusgJob2LaunchEntity = new AsusgJob2Launch();
  465. $asusgJob2LaunchEntity->asusg_jobplan_id = $JobPlanEntitty->id;
  466. $asusgJob2LaunchEntity->asusg_employee_id1 = $user->id;
  467. $asusgJob2LaunchEntity->asusg_job_uuid = $work['id_work'];
  468. $asusgJob2LaunchEntity->employees_uuid = $user->uuid;
  469. $asusgJob2LaunchEntity->section_uuid = $work["section_id"];
  470. $asusgJob2LaunchEntity->asusg_project_id = 0;
  471. $asusgJob2LaunchEntity->job_order = 0;
  472. $asusgJob2LaunchEntity->asusg_projecttype_id = $projtype;
  473. $asusgJob2LaunchEntity->time_limit = $dwResult['time_limit'];
  474. $asusgJob2LaunchEntity->outfit = $dwResult['outfit'];
  475. $asusgJob2LaunchEntity->name = $work['work_name'];
  476. $asusgJob2LaunchEntity->section_name = $work["section_lit"];
  477. if (!$asusgJob2LaunchEntity->save()) {
  478. $this->logger->setLog('в Job2launch не добавилась работа => "'. $work['work_name']. '" Добавление работ будет пропущено так как такая запись уже есть.');
  479. continue;
  480. }
  481. $this->issetLaunch = true;
  482. $this->logger->setLog($this->prepareLogString);
  483. $this->prepareLogString = '';
  484. $this->logger->setLog('в Job2launch была добавлена работа => "'. $work['work_name'].'"');
  485. /// сначала генерю проект
  486. $projId = $this->generateProject($work);
  487. /// сначала генерю проект
  488. } else {
  489. $userUuidArr = explode(',', $asusgJob2LaunchEntity->employees_uuid);
  490. if ( in_array( $user->uuid , $userUuidArr)) { // если сотрудник уже привязан к лаунчу
  491. $this->logger->setLog('сотрудник '.$user->name .' ('.$user->id.') уже привязан к лаунчу'. $asusgJob2LaunchEntity->id);
  492. continue;
  493. } else {
  494. $asusgJob2LaunchEntity->employees_uuid .= ','. $user->uuid;
  495. $asusgJob2LaunchEntity->save();
  496. $this->logger->setLog('сотрудники ('.$asusgJob2LaunchEntity->employees_uuid.') привязаны к лаунчу'. $asusgJob2LaunchEntity->id);
  497. }
  498. //continue;
  499. $this->prepareLogString .= "ВОТ ТУТ Я ХОТЕЛ ПОЛУЧИТЬ ИД ПРОЕКТА ЧЕРЕЗ ЗАДАЧУ => " . $asusgJob2LaunchEntity->tasks->id .", ВОТ ЧТО ПОЛУЧИЛ => " . $asusgJob2LaunchEntity->tasks->input_id ."!\n";
  500. $projId = $asusgJob2LaunchEntity->tasks->input_id;
  501. }
  502. /////////////// ДОБАВЛЕНИЕ ЗАДАЧИ
  503. $this->prepareLogString .= "\n 3. ДОБАВЛЕНИЕ ЗАДАЧИ \n\n";
  504. $tasktypesEntity = Tasktypes::find()->where(['name' => 'Секция '.$let.', задача','company' => $this->company])->one();
  505. $tasksEnt = Tasks::find()->where(['parent_id' => 0,'asusg_job_mapped_id' => $asusgJob2LaunchEntity->id,'assignees_arr' => $user->id])->one();
  506. if ( null != $tasksEnt) {
  507. continue;
  508. }
  509. $this->logger->setLog($this->prepareLogString);
  510. $this->prepareLogString = '';
  511. $tasksEntity = new Tasks();
  512. $tasksEntity->parent_id = 0;
  513. $tasksEntity->status = 2;
  514. $tasksEntity->type = $tasktypesEntity->id;
  515. $tasksEntity->assignees_arr = $user->id;
  516. $tasksEntity->preferred_assignee = $user->id;
  517. $tasksEntity->created = date("Y-m-d H:i;s");
  518. $tasksEntity->asusg_job_mapped_id = $asusgJob2LaunchEntity->id;
  519. $tasksEntity->mapping_comment = $work["outfit"] . ': ' . $work['work_name'];
  520. $tasksEntity->text = $work["section_lit"] . "\n" . $work["outfit"] . ': ' . $work['work_name'] . "\n" . $dwResult['workers'];
  521. if($tasksEntity->save()) {
  522. //$this->testIdpl3 = $tasksEntity->id;
  523. $this->logger->setLog('в Tasks была добавлена ЗАДАЧА => "'. $work['work_name'] . '" id => '.$tasksEntity->id);
  524. } else {
  525. $this->logger->setLog('в Tasks была НЕ добавлена ЗАДАЧА => "'. $work['work_name'] . '" id => '.$tasksEntity->id);
  526. }
  527. //var_dump($tasksEntity->errors,$user->id); echo '<br>';
  528. $this->logger->setLog(' колво записей => ' . count($jsusgJob2CommandEntity) . 'type => '. gettype($jsusgJob2CommandEntity));
  529. $arrJ = [];
  530. //$countPriority = 1;
  531. /////////////////
  532. if ( null == $switcher) {
  533. $this->logger->setLog("switcher = null");
  534. ///////////////// ДОБАВЛЕНИЕ ТМЦ
  535. $mappingapiModel = new \app\models\MappingapiModel();
  536. //var_dump($user->id-uuid,$work['id_work']);
  537. $this->logger->setLog("сотрудник => " . $user->uuid . ", работа => " . $work['id_work']);
  538. $tmcString = $mappingapiModel->workDetail($user->uuid,$work['id_work']);
  539. $this->logger->setLog("\n ДОБАВЛЕНИЕ ТМЦ " . strlen($dwResult['tmcString']) . "\n");
  540. if ( '' != $dwResult['tmcString']) {
  541. $tasksEntity3 = new Tasks();
  542. $tasksEntity3->parent_id = $tasksEntity->id; // +
  543. $tasksEntity3->status = 2; // +
  544. $tasksEntity3->priority = Yii::$app->params['countPriority']; // +
  545. // $tasksEntity2->input_id = $job->asusgJob2Launch->asusg_project_id;
  546. $tasksEntity3->created = date("Y-m-d H:i;s"); // +
  547. $tasksEntity3->type = 2159; // +
  548. $tasksEntity3->assignees_arr = $user->id; // +
  549. $tasksEntity3->preferred_assignee = $user->id; // +
  550. $tasksEntity3->asusg_job_mapped_id = $asusgJob2LaunchEntity->id;
  551. $tasksEntity3->text = $dwResult['tmcString']; // +
  552. $tasksEntity3->mapping_comment = $dwResult['tmcString']; // +
  553. $tasksEntity3->input_id = $projId;
  554. if ( $tasksEntity3->save()) {
  555. var_dump('создана ТМЦ, задача =>' . $tasksEntity3->id);
  556. $arrJ[] = $tasksEntity3->id;
  557. $query3 = "call asusg_add_checkpoints_to_task(" . $user->id . ",'" . $tasksEntity3->id . "')";
  558. $resProc = Yii::$app->db->createCommand($query3)->query();
  559. $logResProc = 'false';
  560. if ($resProc){
  561. $logResProc = 'true';
  562. }
  563. $this->logger->setLog('в Tasks была добавлена КОМАНДА => "'. $work['work_name'] . '" id => '.$tasksEntity3->id. ' процедура => ' . $logResProc);
  564. } else {
  565. var_dump('не создана ТМЦ');
  566. $this->logger->setLog('в Tasks была НЕ добавлена КОМАНДА => "'. $work['work_name'] . '" id => '.$tasksEntity3->id);
  567. }
  568. Yii::$app->params['countPriority']++;
  569. }
  570. ///////////////////
  571. ///////////////// ДОБАВЛЕНИЕ ЗАМЕРОВ ЭТАП 0
  572. $this->logger->setLog("\n 4. ДОБАВЛЕНИЕ ЗАМЕРОВ ЭТАП 0 \n");
  573. //var_dump(Yii::$app->params['api']['hw_msrmnt_stat'][ $dwResult["hw_measurements_status"] ],$dwResult["hw_measurements_status"]); echo "\n";
  574. //if ( Yii::$app->params['api']['hw_msrmnt_stat'][ $dwResult["hw_measurements_status"] ]) { // выполнение hw_measurements_status = waiting
  575. $paramsMeaserm = ['input_id' => $projId, 'assignees_arr' => $user->id, 'work' => $work,'stage' =>0, 'parent_id' => $tasksEntity->id ,'stage_type' => 'доремонтный','asusg_job_mapped_id' => $asusgJob2LaunchEntity->id];
  576. Yii::$app->params['api']['mesrmntParam'] = $paramsMeaserm;
  577. MappingapiModel::workMeasurements($work['id_work'],$user->uuid);
  578. //}
  579. ///////////////////
  580. }
  581. /////////////// НА РЕМОНТ
  582. $this->logger->setLog("\n 5. ДОБАВЛЕНИЕ НА РЕМОНТ \n");
  583. foreach($jsusgJob2CommandEntity as $job) {
  584. $tasksEntity2 = new Tasks();
  585. $tasksEntity2->parent_id = $tasksEntity->id;
  586. $tasksEntity2->status = 2;
  587. $tasksEntity2->priority = Yii::$app->params['countPriority'];
  588. // $tasksEntity2->input_id = $job->asusgJob2Launch->asusg_project_id;
  589. $tasksEntity2->created = date("Y-m-d H:i;s");
  590. $tasksEntity2->type = $job->smopp_cmd_id;//Yii::$app->params['supercycletype'];
  591. $tasksEntity2->assignees_arr = $user->id;
  592. $tasksEntity2->preferred_assignee = $user->id;
  593. $tasksEntity2->asusg_job_mapped_id = $job->jobplantie->id;
  594. $tasksEntity2->text = $work["eq_serie"] . ' '.$work["section_lit"] . ', '. $work["outfit"] . ':' . $work['work_name'];
  595. $tasksEntity2->mapping_comment = $work["outfit"] . ': ' . $work['work_name'];
  596. if ( $tasksEntity2->save()) {
  597. $arrJ[] = $tasksEntity2->id;
  598. ///////////////////
  599. //$query3 = "call asusg_add_checkpoints_to_task(" . $user->id . ",'" . $tasksEntity2->id . "')";
  600. //$resProc = Yii::$app->db->createCommand($query3)->query();
  601. ///////////////////
  602. $this->logger->setLog('в Tasks была добавлена КОМАНДА => "'. $work['work_name'] . '" id => '.$tasksEntity2->id);
  603. } else {
  604. $this->logger->setLog('в Tasks была НЕ добавлена КОМАНДА => "'. $work['work_name'] . '" id => '.$tasksEntity2->id);
  605. }
  606. Yii::$app->params['countPriority']++;
  607. }
  608. /////////////////////////////////////
  609. // $projId = $this->generateProject3($work);
  610. $tasksEntity->input_id = $tasksEntity->input_id ?? $projId;
  611. if ($tasksEntity->save()) {
  612. $this->logger->setLog('привязка ЗАДАЧИ ( id = '.$tasksEntity->id.') прошла успешно');
  613. }
  614. $tasksEntity = null;
  615. foreach($arrJ as $job_id) {
  616. $tasksEnt = Tasks::findOne($job_id);
  617. $tasksEnt->input_id = $tasksEnt->input_id ?? $projId;
  618. if($tasksEnt->save()){
  619. $this->logger->setLog('привязка КОМАНДЫ ( id = '.$tasksEntity2->id.') прошла успешно');
  620. } else {
  621. $this->logger->setLog('привязка КОМАНДЫ ( id = '.$tasksEntity2->id.') прошла не успешно');
  622. }
  623. }
  624. if ( null != $tasksEntity3) {
  625. $tasksEntity3->input_id = $projId;
  626. //if($tasksEntity3->save()){
  627. // $this->logger->setLog('привязка КОМАНДЫ ТМЦ ( id = '.$tasksEntity3->id.') прошла успешно');
  628. //}
  629. }
  630. if ( null == $switcher) {
  631. ///////////////// ДОБАВЛЕНИЕ ЗАМЕРОВ ЭТАП 1
  632. $this->logger->setLog("\n 6. ДОБАВЛЕНИЕ ЗАМЕРОВ ЭТАП 1 \n");
  633. //if ( Yii::$app->params['api']['hw_msrmnt_stat'][ $dwResult["hw_measurements_status"] ]) { // выполнение hw_measurements_status = waiting
  634. $paramsMeaserm['stage'] = 1;
  635. $paramsMeaserm['stage_type'] = 'контрольный';
  636. $paramsMeaserm['asusg_job_mapped_id'] = $asusgJob2LaunchEntity->id;
  637. Yii::$app->params['api']['mesrmntParam'] = $paramsMeaserm;
  638. MappingapiModel::workMeasurements($work['id_work'],$user->uuid);
  639. //}
  640. ///////////////////
  641. ///////////////// ДОБАВЛЕНИЕ ЗАМЕРОВ ЭТАП 2
  642. $this->logger->setLog("\n 7. ДОБАВЛЕНИЕ ЗАМЕРОВ ЭТАП 2 \n");
  643. //if ( Yii::$app->params['api']['hw_msrmnt_stat'][ $dwResult["hw_measurements_status"] ]) { // выполнение hw_measurements_status = waiting
  644. $paramsMeaserm['stage'] = 2;
  645. $paramsMeaserm['stage_type'] = 'послеремонтный';
  646. $paramsMeaserm['asusg_job_mapped_id'] = $asusgJob2LaunchEntity->id;
  647. Yii::$app->params['api']['mesrmntParam'] = $paramsMeaserm;
  648. MappingapiModel::workMeasurements($work['id_work'],$user->uuid);
  649. //}
  650. ///////////////////
  651. //
  652. }
  653. Yii::$app->params['countPriority']= 1;
  654. //echo "<pre>";
  655. //var_dump($job->asusgJob2Launch->asusg_project_id);
  656. //var_dump($tasksEntity2->errors,$tasksEntity->errors);
  657. //echo "</pre>";
  658. }
  659. }
  660. public function generateProject($work){
  661. $this->logger->setLog("\n 2. ГЕНЕРАЦИЯ ПРОЕКТА \n");
  662. $result = '';
  663. $let = mb_substr($work["section_lit"], -1);
  664. $sectionsEntity = Sections::find()->select(['id', 'diagnostic_map'])
  665. //->where(['locomotive_series' => $work["eq_serie"],'section_number' => mb_substr($work['section_lit'],0,-1),'letter' => $let])
  666. ->where(['locomotive_series' => $work["eq_serie"],'section_number' => mb_substr($work['section_lit'],0,-1),'section_subnumber' => $work["section_num"]])
  667. ->one();
  668. $this->logger->setLog("Параметры локомотива locomotive_series => " . $work["eq_serie"]. ", section_number => " . $work['section_lit'] . " ,letter => " .$let. " \n");
  669. $diagnostic_map = $sectionsEntity->diagnostic_map;
  670. if ( null == $sectionsEntity->id) {
  671. $sectionsEntity2 = new Sections();
  672. $sectionsEntity2->locomotive_series = $work["eq_serie"];
  673. $sectionsEntity2->section_number = mb_substr($work['section_lit'],0,-1);
  674. $sectionsEntity2->section_subnumber = $work["section_num"];
  675. $sectionsEntity2->diagnostic_map = $work["section_DK"];
  676. $sectionsEntity2->uuid = $work["section_id"];
  677. $sectionsEntity2->letter = $let;
  678. if ( $sectionsEntity2->save()) {
  679. $this->logger->setLog('в Sections была добавлена новая секция => '. $work["section_num"] . ' id => '.$sectionsEntity2->id);
  680. } else {
  681. //var_dump($sectionsEntity2->errors);
  682. $this->logger->setLog('в Sections при добавлении секции произошли ошибки => '. count($sectionsEntity2->errors) . ' шт.');
  683. $sectionsEntity->diagnostic_map = $work['section_DK'];
  684. $sectionsEntity->save();
  685. $this->logger->setLog('Пришлось просто обновить диагностическую карту секция=> '. $sectionsEntity . ', номер карты =>' . $work['section_DK']);
  686. }
  687. $diagnostic_map = $sectionsEntity->diagnostic_map;
  688. }
  689. else if( null == $sectionsEntity->diagnostic_map ) {
  690. $sectionsEntity->diagnostic_map = $work['section_DK'];
  691. $sectionsEntity->save();
  692. }
  693. if ($sectionsEntity->diagnostic_map == $work['section_DK'] ) {
  694. $query = "select pl.id from projects_locotech pl
  695. inner join tasks t on pl.id = t.input_id
  696. left join tasktypes tt on t.type = tt.id
  697. where pl.company = " . $this->company . "
  698. and pl.loco_type = '" . $work["eq_serie"] . "'
  699. and pl.loco_number = " . $work["eq_number"] . "
  700. and t.parent_id = 0
  701. and tt.letter like '%" . $let . "%'
  702. and pl.uuid like '%" . $work['repair_name']. ",%'
  703. order by pl.id desc
  704. limit 1";
  705. $projectId = Yii::$app->db->createCommand($query)->queryOne();
  706. $result = $projectId['id'];
  707. $this->logger->setLog('в Sections секция с такой диагностической картой => '. $work['section_DK'] . ' существует. Ид проекта '. $result);
  708. }
  709. if (!$result) {
  710. $projectsLocotech = new ProjectsLocotech();
  711. $projectsLocotech->action = 197 ;
  712. $projectsLocotech->company = $this->company;
  713. $projectsLocotech->status = 2;
  714. $projectsLocotech->loco_type = $work["eq_serie"];
  715. $projectsLocotech->loco_number = $work["eq_number"];
  716. $projectsLocotech->depo ='' ;
  717. $projectsLocotech->depo_service = '';
  718. $projectsLocotech->created = date('Y-m-d H:i:s');
  719. $projectsLocotech->urgent = 0;
  720. $projectsLocotech->uuid = $work['work_name'].":".$work['repair_name'].",".$work["eq_serie"];
  721. $projectsLocotech->save();
  722. $result = $projectsLocotech->id;
  723. $this->logger->setLog('Такого проекта еще не было пришлось создать. Ид проекта => '. $result);
  724. }
  725. //var_dump($result);
  726. return $result;
  727. }
  728. public function generateProject3($work){
  729. $result = '';
  730. $projectsLocotech = new ProjectsLocotech();
  731. $projectsLocotech->action = 197 ;
  732. $projectsLocotech->company = $this->company;
  733. $projectsLocotech->status = 2;
  734. $projectsLocotech->loco_type = $work["eq_serie"];
  735. $projectsLocotech->loco_number = $work["eq_number"];
  736. $projectsLocotech->depo ='' ;
  737. $projectsLocotech->depo_service = '';
  738. $projectsLocotech->created = date('Y-m-d H:i:s');
  739. $projectsLocotech->urgent = 0;
  740. $projectsLocotech->uuid = $work['work_name'].":".$work['repair_name'].",".$work["eq_serie"];
  741. $projectsLocotech->save();
  742. $result = $projectsLocotech->id;
  743. $this->logger->setLog('Такого проекта еще не было пришлось создать. Ид проекта => '. $result);
  744. //var_dump($result);
  745. return $result;
  746. }
  747. private function prepareListWorks($listWorks) {
  748. $result = [];
  749. $dataArr = [];
  750. if ( null == $listWorks || empty($listWorks)) {
  751. return [];
  752. }
  753. foreach ( $listWorks["rows"] as $rows) {
  754. $rows["result"] = json_decode($rows["result"],true);
  755. foreach ( $rows["result"]['data'] as $key => $data) {
  756. //echo '<pre>';
  757. // var_dump($data);
  758. // echo '</pre>';
  759. $tempArray = [];
  760. $tempArray["eq_serie"] = explode(" ",$data["equip_sect_name"])[0];
  761. $eq = explode(" ",$data["equip_sect_name"])[1];
  762. $tempArray["eq_number"] = explode("/",$eq)[0];
  763. //echo '<pre>';
  764. //var_dump($tempArray["eq_number"]);
  765. //echo '</pre>';
  766. foreach ( $data["sections"] as $sections) {
  767. $tempArray["section_id"] = $sections["id_section"];
  768. $tempArray["section_lit"] = $sections["section_name"];
  769. //$this->getLocoInfoMore($sections["section_subnumber"]);
  770. $tempArray["section_num"] = $sections["section_subnumber"];
  771. $tempArray["section_DK"] = $sections["section_dk"];
  772. // echo '<pre>';
  773. // var_dump($sections);
  774. // echo '</pre>';
  775. foreach ( $sections['works'] as $work) {
  776. $tempArray["id_work"] = $work["id_work"];
  777. $tempArray["outfit"] = $work["outfit"];
  778. $tempArray["work_name"] = $work["work_name"];
  779. $tempArray["repair_name"] = $work["repair_type"];
  780. $tempArray["work_status"] = $work["work_status"];
  781. $tempArray["repeats"] = $work["repeats"];
  782. //$extraSection = $this->getSectionInfo( $tempArray["section_id"], $tempArray["repair_name"]);
  783. //$tempArray["section_num"] = $extraSection['section_num'];
  784. //$tempArray['section_DK'] = $extraSection['section_DK'];
  785. $dataArr[] = $tempArray;
  786. foreach ( $works['workers'] as $worker) {
  787. //echo '<pre>';
  788. //var_dump($worker);
  789. //echo '</pre>';
  790. }
  791. }
  792. }
  793. }
  794. $result['result'] = 'true';
  795. $result['data'] = $dataArr;
  796. break;
  797. }
  798. return $result;
  799. }
  800. private function sectionList() {
  801. $result = [];
  802. //$params['place'] = 'a84d0a15-08ec-11e5-829d-00155d6cab05';
  803. //$params['place'] = '95d7646d-e7ee-11e4-829d-00155d6cab05';
  804. $params['place'] = 'a84d0a15-08ec-11e5-829d-00155d6cab05';
  805. $params['date'] = '1581324560';
  806. $locomotiveModel = new LocomotiveModel();
  807. $result = $locomotiveModel->getSectionList($params);
  808. //$result = json_decode($result,true);
  809. //$this->sectionList = $result['array'];
  810. $this->sectionList = json_decode($result,true);
  811. return $result;
  812. }
  813. private function getSectionInfo( $id,$repair) {
  814. $result = [];
  815. if (empty($this->sectionList)) {
  816. $this->sectionList();
  817. }
  818. foreach ($this->sectionList as $items) {
  819. //var_dump($section["Section"] .' == '. $id , $section['TypeOfRepair'] .' == '. $repair); echo '<br>';
  820. foreach ( $items as $section) {
  821. if ( $section["Section"] == $id and $section['TypeOfRepair'] == $repair ) {
  822. $result['section_num'] = $section["NumberSection"];
  823. $result['section_DK'] = $section['DiagnosticMapslocomotive'];
  824. return $result;
  825. }
  826. }
  827. }
  828. return $result;
  829. }
  830. private function buisyEmployee($user){
  831. $tasksEntity = Tasks::find()->where(['assignees_arr' => $user->id])->andWhere(['<>','status',5])->all();
  832. if ( null != $tasksEntity){
  833. var_dump('Return =>true');
  834. return true;
  835. }
  836. var_dump('Return =>false');
  837. return false;
  838. }
  839. }
  840. /*
  841. int(349)
  842. array(2) {
  843. ["dataShape"]=>
  844. array(1) {
  845. ["fieldDefinitions"]=>
  846. array(1) {
  847. ["result"]=>
  848. array(5) {
  849. ["name"]=>
  850. string(6) "result"
  851. ["description"]=>
  852. string(0) ""
  853. ["baseType"]=>
  854. string(4) "TEXT"
  855. ["ordinal"]=>
  856. int(0)
  857. ["aspects"]=>
  858. array(0) {
  859. }
  860. }
  861. }
  862. }
  863. ["rows"]=>
  864. array(1) {
  865. [0]=>
  866. array(1) {
  867. ["result"]=>
  868. string(1290) "{"result":"true",
  869. "data":
  870. [{"id_equipment":"95078df8-4487-46b9-9771-5c6b6e1f6b81",
  871. "equip_sect_name":"3ЭС5К 0362/3ЭС5К", // ["eq_serie"]/ ["eq_number"]
  872. "sections":
  873. [{"works":
  874. [{"id_work":"a7869ca0-0153-41f5-93c4-51393ccc574a",
  875. "repeats":1,
  876. "work_name":"Тормозное и пневматическое оборудование после ремонта испытать, // ["work_name"]
  877. отрегулировать согласно инструкции",
  878. "work_status":4,
  879. "workers":
  880. [{"id":"0f9ed850-e473-11e2-aaad-ac162db0b20c","fio":"Новосад Я. И."},
  881. {"id":"0f9ed854-e473-11e2-aaad-ac162db0b20c","fio":"Ознобихин О. А."}],
  882. "measurements":"--/--/--"}],
  883. "section_name":"0362А", // ["section_lit"]
  884. "id_section":"6ddd13a5-986b-11e2-99b5-ac162db0b20c"}, // ["section_id"]
  885. {"works":
  886. [{"id_work":"a0a572e0-4d70-45d7-ac4a-9483933c70b9",
  887. "repeats":1,
  888. "work_name":"Тормозное и пневматическое оборудование после ремонта испытать,
  889. отрегулировать согласно инструкции",
  890. "work_status":4,
  891. "workers":
  892. [{"id":"0f9ed850-e473-11e2-aaad-ac162db0b20c","fio":"Новосад Я. И."},
  893. {"id":"0f9ed854-e473-11e2-aaad-ac162db0b20c","fio":"Ознобихин О.А."}],
  894. "measurements":"--/--/--"}],
  895. "section_name":"0362В",
  896. "id_section":"6ddd13a6-986b-11e2-99b5-ac162db0b20c"}],
  897. "equip_percent":10730}]}"
  898. }
  899. }
  900. }
  901. repair_name - ?
  902. section_num - ? +
  903. outfit - ?
  904. section_DK - ?
  905. int(349)
  906. array(2) {
  907. ["result"]=>
  908. string(4) "true"
  909. ["data"]=>
  910. array(2) {
  911. [0]=>
  912. array(10) {
  913. ["id_work"]=>
  914. string(36) "a7869ca0-0153-41f5-93c4-51393ccc574a" +
  915. ["section_DK"]=>
  916. string(36) "6d4acb88-685e-11ea-80d6-005056011052" +
  917. ["eq_number"]=>
  918. string(4) "0362" +
  919. ["outfit"]=>
  920. float(1460789) +
  921. ["work_name"]=>
  922. string(187) "Тормозное и пневматическое оборудование после ремонта испытать , отрегулировать согласно инструкции" +
  923. ["section_id"]=>
  924. string(36) "6ddd13a5-986b-11e2-99b5-ac162db0b20c" +
  925. ["section_num"]=>
  926. string(8) "11381969" +
  927. ["section_lit"]=>
  928. string(6) "0362А" +
  929. ["repair_name"]=>
  930. string(6) "ТР-1" +
  931. ["eq_serie"]=>
  932. string(8) "3ЭС5К" +
  933. }
  934. [1]=>
  935. array(10) {
  936. ["id_work"]=>
  937. string(36) "a0a572e0-4d70-45d7-ac4a-9483933c70b9"
  938. ["section_DK"]=>
  939. string(36) "6d4acb89-685e-11ea-80d6-005056011052"
  940. ["eq_number"]=>
  941. string(4) "0362"
  942. ["outfit"]=>
  943. float(1460871)
  944. ["work_name"]=>
  945. string(187) "Тормозное и пневматическое оборудование после ремонта испытать , отрегулировать согласно инструкции"
  946. ["section_id"]=>
  947. string(36) "6ddd13a6-986b-11e2-99b5-ac162db0b20c"
  948. ["section_num"]=>
  949. string(8) "11381985"
  950. ["section_lit"]=>
  951. string(6) "0362В"
  952. ["repair_name"]=>
  953. string(6) "ТР-1"
  954. ["eq_serie"]=>
  955. string(8) "3ЭС5К"
  956. }
  957. }
  958. }
  959. */