MappingHandlerTestController.php 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744
  1. <?php
  2. namespace app\controllers;
  3. use Yii;
  4. use yii\web\Controller;
  5. use app\models\MainModel;
  6. use app\models\ProcedureModel;
  7. use app\models\entity\Tasks;
  8. use app\models\ProjectsModel;
  9. use app\models\entity\Accounts;
  10. use app\models\entity\Sections;
  11. use app\models\LocomotiveModel;
  12. use app\models\entity\Tasktypes;
  13. use app\models\logger\LoggerFile;
  14. use app\models\entity\Repairtypes;
  15. use app\models\entity\Projecttypes;
  16. use app\models\entity\AsusgProject;
  17. use app\models\entity\AsusgJobPlan;
  18. use app\models\MappingHandlerModel;
  19. use app\models\entity\AsusgJob2Launch;
  20. use app\models\entity\AsusgProjectType;
  21. use app\models\entity\LocomotiveSeries;
  22. use app\models\entity\ProjectsLocotech;
  23. use app\models\entity\AsusgJob2Command;
  24. use app\models\MainMappingModel;
  25. use app\models\procedure\StartProjectForLocoModel;
  26. class MappinghandlertestController extends Controller
  27. {
  28. private $logger;
  29. private $company;
  30. private $entityManager;
  31. public function beforeAction($action)
  32. {
  33. parent::beforeAction($action);
  34. $log = new LoggerFile();
  35. $this->logger = new MappingHandlerModel($log);
  36. return true;
  37. }
  38. // запускается периодически через крон
  39. public function actionGetworks($company)
  40. {
  41. $mainMappingModel = new MainMappingModel($company);
  42. $GWparams = ['url' => 'http://devplatform.digitaldepot.ru:8085/Thingworx/Things/SMoPPIntegrationLibrary/Services/getUserWorks',
  43. 'param' => '',
  44. 'login' => 'ПройдаковИА',
  45. 'pass' => 'Ip15351112'
  46. ];
  47. // список сотрудников онлайн
  48. $onlineUser = $mainMappingModel->getOnlineMobileUser($company);
  49. if( 0 == count($onlineUser)) {
  50. return 'Нет сотрудников онлайн';
  51. }
  52. // ПОЛУЧАЮ СПИСОК ПОЛЬЗОВАТЕЛЕЙ ОНЛАЙН + НАПАРНИКИ ПО РАБОТАМ
  53. $onlineUserPlus = $mainMappingModel->onlineUserPlus($onlineUser);
  54. $mainMappingModel->MappingStart($onlineUserPlus);
  55. }
  56. public function addWorksInJobPlan($listWorks) {
  57. $result = [];
  58. if (empty($listWorks)){
  59. return $result;
  60. }
  61. $arrayIdWorks = [];
  62. foreach( $listWorks->data as $work ) {
  63. $arrayIdWorks[] = $work;
  64. }
  65. foreach ($arrayIdWorks as $work){
  66. $asusgJobPlanEntity = new AsusgJobPlan();
  67. $asusgJobPlanEntity->name = $work->work_name;
  68. $asusgJobPlanEntity->sections = 'АБВ';
  69. if (!$asusgJobPlanEntity->save()) {
  70. $result[] = $asusgJobPlanEntity->errors;
  71. }
  72. }
  73. return $result;
  74. }
  75. // Добавление не существующих работ в Tasktype ( сверхцикловые )
  76. public function addWorksInTaskType($listWorks, $listIsabsentWorks ) {
  77. $result = $listIsabsentWorks;
  78. if (empty($listWorks)){
  79. return $result;
  80. }
  81. $arrayIdWorks = [];
  82. foreach( $listWorks->data as $work ) {
  83. $arrayIdWorks[] = $work;
  84. }
  85. foreach ($arrayIdWorks as $work){
  86. $tasktypesEntity = new Tasktypes();
  87. $tasktypesEntity->creator_id = 49 ;
  88. $tasktypesEntity->name = $work->work_name ;
  89. $tasktypesEntity->description = 'По запросу АСУ СГ: сверхцикловая работа' ;
  90. $tasktypesEntity->company = \Yii::$app->request->get('company');
  91. $tasktypesEntity->main_task = 0 ;
  92. $tasktypesEntity->confirmtype = 0 ;
  93. $tasktypesEntity->time_to_complete_minutes = 61 ;
  94. $tasktypesEntity->subtasks = '' ;
  95. $tasktypesEntity->letter = 'АБВ' ;
  96. if ($tasktypesEntity->save()) {
  97. $flag = 0;
  98. foreach($result as $task) {
  99. if ( $task->work_name == $tasktypesEntity->name ){
  100. $flag = 1;
  101. }
  102. }
  103. if ( 0 == $flag ) {
  104. $result[] = $work;//$tasktypesEntity->errors;
  105. }
  106. }
  107. }
  108. return $result;
  109. }
  110. // // новая версия GetworksOnLoco
  111. public function GetworksOnLoco($listWorks)
  112. {
  113. $result = [];
  114. if (empty($listWorks)){
  115. return $result;
  116. }
  117. $arrayResult = [];
  118. foreach ($listWorks as $work){
  119. $sectionsEntity = new Sections();
  120. $sectionsEntity->section_number = $work->eq_number;
  121. $sectionsEntity->locomotive_series = $work->eq_serie;
  122. $sectionsEntity->section_subnumber = $work->section_num;
  123. $sectionsEntity->uuid = $work->section_id;
  124. $sectionsEntity->diagnostic_map = $work->section_DK;
  125. $sectionsEntity->letter = mb_substr($work->section_lit, -1);
  126. if (! $sectionsEntity->save()) {
  127. continue;
  128. }
  129. }
  130. foreach ($listWorks as $work){
  131. $arrayResult[] = $work->section_id;
  132. }
  133. $sectionsEntity = Sections::find()->where(['in','uuid',$arrayResult])->asArray()->all();
  134. $arrayResult = [];
  135. $arrayResultTemp = [];
  136. $arrayIdSerieTemp = [];
  137. foreach($sectionsEntity as $sec){
  138. $arrayResult[] = $sec['uuid'];
  139. $arrayResultTemp[$sec['uuid']] = $sec;
  140. $LocomotiveSeriesEntity = LocomotiveSeries::findOne(['name' => $sec['locomotive_series']]);
  141. $arrayIdSerieTemp[$sec['uuid']] = $LocomotiveSeriesEntity->id;
  142. }
  143. $tempArray = [];
  144. foreach($listWorks as $w) {
  145. //var_dump(( in_array($w->section_id,$arrayResult)), $w->section_id .' ==', );
  146. if ( in_array($w->section_id,$arrayResult)) {
  147. $tempArray[] = $w;
  148. $result[$w->section_id] = [ 'info_obj' => $tempArray ,'info'=> $arrayResultTemp[$w->section_id],'id_serie' => $arrayIdSerieTemp[$w->section_id]];
  149. }
  150. }
  151. return $result;
  152. }
  153. public function checkMapping($arrProj)
  154. {
  155. $tempResult = [];
  156. $result = [];
  157. foreach ( $arrProj as &$proj) {
  158. foreach ( $proj['info_obj'] as $work) {
  159. $tempResult[] = $work->work_name;
  160. }
  161. $res = AsusgJobPlan::find()->where(['in', 'name',$tempResult])->all();
  162. $proj['jobplan'] = $res;
  163. }
  164. return $arrProj;
  165. }
  166. public function addJobproject($minRes)
  167. {
  168. $projectTypes = [];
  169. foreach ( $minRes as &$proj) {
  170. foreach($proj['info_obj'] as $obj){
  171. $repairtypesEntity = Repairtypes::find()->select('id')->where(['name'=> $obj->repair_name])->one();
  172. $projectTypes[] = $repairtypesEntity->id;
  173. }
  174. $projectTypes = array_unique($projectTypes);
  175. foreach ( $projectTypes as $type) {
  176. $field = Yii::$app->params['sections_letter'][$proj['info']["letter"]];
  177. $asusgProjectEntity = new AsusgProject();
  178. $asusgProjectEntity->loco_serie_id = $proj['id_serie']; //locomotive_series
  179. $asusgProjectEntity->repair_type = $type; // repairtypes name из асусг
  180. $asusgProjectEntity->loco_number = $proj['info']["section_number"];
  181. $asusgProjectEntity->$field = $proj['info']["section_subnumber"];
  182. $asusgProjectTypeEntity = AsusgProjectType::findOne(['loco_serie_id' => $proj['id_serie'], 'repair_type' => $type]);
  183. $asusgProjectEntity->asusg_projecttype_id = $asusgProjectTypeEntity->id;
  184. $asusgProjectEntity->save();
  185. echo "<pre>";
  186. var_dump($asusgProjectEntity->errors);
  187. //var_dump("Выполнение процедуры => " . $res);
  188. echo "</pre>";
  189. $proj['asusgProject_id'] = $asusgProjectEntity->id;
  190. $proj['repair_type'] = $type;
  191. }
  192. }
  193. return $minRes;
  194. }
  195. public function addJob2launch($minRes)
  196. {
  197. foreach ( $minRes as $proj) {
  198. $resultArr = [];
  199. $order = 1;
  200. foreach ( $proj['jobplan'] as $work) {
  201. $sectionTemp = '';
  202. $id_workTemp = '';
  203. foreach($proj['info_obj'] as $obj){
  204. //var_dump(( $obj->work_name == $work->name), $obj->work_name.' =='. $work->name);
  205. if( $obj->work_name == $work->name){
  206. $sectionTemp = $obj->section_id;
  207. $id_workTemp = $obj->id_work;
  208. break;
  209. }
  210. }
  211. $asusgJob2LaunchEntity = new AsusgJob2Launch();
  212. $asusgJob2LaunchEntity->asusg_jobplan_id = $work->id;
  213. $asusgJob2LaunchEntity->asusg_employee_id1 = $proj['userInfo']->id;
  214. $asusgJob2LaunchEntity->asusg_job_uuid = $id_workTemp;
  215. $asusgJob2LaunchEntity->section_uuid = $sectionTemp;
  216. $asusgJob2LaunchEntity->asusg_project_id = $proj['asusgProject_id'];
  217. $asusgJob2LaunchEntity->job_order = $order;
  218. $asusgProjectTypeEntity = AsusgProjectType::findOne(['loco_serie_id' => $proj['id_serie'], 'repair_type' => $proj['repair_type']]);
  219. //var_dump($id_workTemp);
  220. //var_dump($proj['id_serie'],$proj['repair_type']);
  221. //var_dump($asusgProjectTypeEntity->id);
  222. $asusgJob2LaunchEntity->asusg_projecttype_id = $asusgProjectTypeEntity->id;
  223. $asusgJob2LaunchEntity->save();
  224. echo "<pre>";
  225. var_dump($asusgJob2LaunchEntity->id);
  226. var_dump($asusgJob2LaunchEntity->errors);
  227. //var_dump($sectionsEntity);
  228. echo "</pre>";
  229. $order++;
  230. }
  231. }
  232. }
  233. public function getProjectType($repairName,$serieName)
  234. {
  235. $result = null;
  236. $repairtypesEntity = Repairtypes::findOne(['name' => $repairName]);
  237. $locomotiveSeriesEntity = LocomotiveSeries::findOne(['name' => $serieName]);
  238. $asusgProjectTypeEntity = AsusgProjectType::findOne(['repair_type' => $repairtypesEntity->id , 'loco_serie_id' => $locomotiveSeriesEntity->id]);
  239. if ( null != $asusgProjectTypeEntity->id ) {
  240. $result = $asusgProjectTypeEntity->id;
  241. }
  242. return $result;
  243. }
  244. // Сверхцикловые
  245. public function addJob2launch2($listWorks,$user)
  246. {
  247. require_once $_SERVER["DOCUMENT_ROOT"].'/functions.php';
  248. //var_dump(gettype($this->entityManager));
  249. foreach ( $listWorks as $work) {
  250. $projtype = $this->getProjectType($work["repair_name"],$work["eq_serie"]);
  251. $let = mb_substr($work["section_lit"], -1);
  252. $resultArr = [];
  253. $asusgJob2LaunchEntity = new AsusgJob2Launch();
  254. $asusgJob2LaunchEntity->asusg_jobplan_id = Yii::$app->params['supercycleplan'];
  255. $asusgJob2LaunchEntity->asusg_employee_id1 = $user->id;
  256. $asusgJob2LaunchEntity->asusg_job_uuid = $work['id_work'];
  257. $asusgJob2LaunchEntity->employees_uuid = $user->id;
  258. $asusgJob2LaunchEntity->section_uuid = $work["section_id"];
  259. $asusgJob2LaunchEntity->asusg_project_id = 0;
  260. $asusgJob2LaunchEntity->job_order = 0;
  261. //$asusgJob2LaunchEntity->asusg_projecttype_id = 0;
  262. $asusgJob2LaunchEntity->asusg_projecttype_id = $projtype;
  263. if (!$asusgJob2LaunchEntity->save()) {
  264. $this->logger->setLog('в Job2launch не добавилась работа => "'. $work['work_name']. '" Добавление работ будет пропущено так как такая запись уже есть.');
  265. continue;
  266. }
  267. $this->logger->setLog('в Job2launch была добавлена работа => "'. $work['work_name'].'"');
  268. $tasktypesEntity = Tasktypes::find()->where(['name' => 'Секция '.$let.', задача','company' => $this->company])->one();
  269. $tasksEntity = new Tasks();
  270. $tasksEntity->parent_id = 0;
  271. $tasksEntity->status = 2;
  272. $tasksEntity->type = $tasktypesEntity->id;
  273. $tasksEntity->assignees_arr = $user->id;
  274. $tasksEntity->created = date("Y-m-d H:i;s");
  275. $tasksEntity->asusg_job_mapped_id = $asusgJob2LaunchEntity->id;
  276. if($tasksEntity->save()) {
  277. $this->logger->setLog('в Tasks была добавлена ЗАДАЧА => "'. $work['work_name'] . '" id => '.$tasksEntity->id);
  278. } else {
  279. $this->logger->setLog('в Tasks была НЕ добавлена ЗАДАЧА => "'. $work['work_name'] . '" id => '.$tasksEntity->id);
  280. }
  281. //var_dump($tasksEntity->errors,$user->id); echo '<br>';
  282. $countPriority = 1;
  283. ///////////////// ДОБАВЛЕНИЕ ТМЦ
  284. $mappingapiModel = new \app\models\MappingapiModel();
  285. var_dump($user->id-uuid,$work['id_work']);
  286. $tmcString = $mappingapiModel->workDetail($user->uuid,$work['id_work']);
  287. if ( '' != $tmcString) {
  288. $tasksEntity3 = new Tasks();
  289. $tasksEntity3->parent_id = $tasksEntity->id; // +
  290. $tasksEntity3->status = 2; // +
  291. $tasksEntity3->priority = $countPriority; // +
  292. // $tasksEntity2->input_id = $job->asusgJob2Launch->asusg_project_id;
  293. $tasksEntity3->created = date("Y-m-d H:i;s"); // +
  294. $tasksEntity3->type = 2159; // +
  295. $tasksEntity3->assignees_arr = $user->id; // +
  296. $tasksEntity3->asusg_job_mapped_id = $asusgJob2LaunchEntity->id; // +
  297. $tasksEntity3->text = $tmcString; // +
  298. $tasksEntity3->mapping_comment = $tmcString; // +
  299. if ( $tasksEntity3->save()) {
  300. $this->logger->setLog('в Tasks была добавлена КОМАНДА => "'. $work['work_name'] . '" id => '.$tasksEntity3->id);
  301. } else {
  302. $this->logger->setLog('в Tasks была НЕ добавлена КОМАНДА => "'. $work['work_name'] . '" id => '.$tasksEntity3->id);
  303. }
  304. $countPriority++;
  305. }
  306. ///////////////////
  307. $tasksEntity2 = new Tasks();
  308. $tasksEntity2->parent_id = $tasksEntity->id;
  309. $tasksEntity2->status = 2;
  310. $tasksEntity2->priority = $countPriority;
  311. $tasksEntity2->created = date("Y-m-d H:i;s");
  312. $tasksEntity2->type = Yii::$app->params['supercycletype'];
  313. $tasksEntity2->assignees_arr = $user->id;
  314. $tasksEntity2->asusg_job_mapped_id = $asusgJob2LaunchEntity->id;
  315. $tasksEntity2->text = $work["eq_serie"] . ' '.$work["section_lit"] . ', '. $work["outfit"] . ': ' . $work['work_name'];
  316. $tasksEntity2->mapping_comment = $work["outfit"] . ': ' . $work['work_name'];
  317. if ( $tasksEntity2->save()) {
  318. ///////////////////
  319. $query3 = "call asusg_add_checkpoints_to_task(" . $user->id . ",'" . $tasksEntity2->id . "')";
  320. Yii::$app->db->createCommand($query3)->query();
  321. ///////////////////
  322. $this->logger->setLog('в Tasks была добавлена КОМАНДА => "'. $work['work_name'] . '" id => '.$tasksEntity2->id);
  323. } else {
  324. $this->logger->setLog('в Tasks была НЕ добавлена КОМАНДА => "'. $work['work_name'] . '" id => '.$tasksEntity2->id);
  325. }
  326. $projId = $this->generateProject($work);
  327. $tasksEntity->input_id = $projId;
  328. if ($tasksEntity->save()) {
  329. $this->logger->setLog('привязка ЗАДАЧИ ( id = '.$tasksEntity->id.') прошла успешно');
  330. }
  331. $tasksEntity2->input_id = $projId;
  332. $this->logger->setLog('2 =>' .$asusgJob2LaunchEntity->id);
  333. if($tasksEntity2->save()){
  334. $this->logger->setLog('привязка КОМАНДЫ ( id = '.$tasksEntity2->id.') прошла успешно');
  335. }
  336. $tasksEntity3->input_id = $projId;
  337. if($tasksEntity3->save()){
  338. $this->logger->setLog('привязка КОМАНДЫ ( id = '.$tasksEntity2->id.') прошла успешно');
  339. }
  340. //echo "<pre>";
  341. //var_dump($tasksEntity2->errors,$tasksEntity->errors);
  342. //echo "</pre>";
  343. }
  344. }
  345. // Цикловые
  346. public function addJob2launch3($listWorks,$user)
  347. {
  348. require_once $_SERVER["DOCUMENT_ROOT"].'/functions.php';
  349. foreach ( $listWorks as $work) {
  350. $projtype = $this->getProjectType($work["repair_name"],$work["eq_serie"]);
  351. $JobPlanEntitty = AsusgJobplan::find()->where(['name' => $work["work_name"]])->one(); // 1204 1567
  352. $jsusgJob2CommandEntity = AsusgJob2Command::find()->where(['asusg_job_id' => $JobPlanEntitty->id, 'asusg_projecttype_id' => $projtype ])->all();
  353. /*
  354. //echo "<pre>";
  355. //var_dump($JobPlanEntitty->id,$projtype);
  356. //var_dump($JobPlanEntitty->id,$jsusgJob2CommandEntity);
  357. //echo "</pre>";
  358. //continue;
  359. $let = mb_substr($work["section_lit"], -1);
  360. $resultArr = [];
  361. $asusgJob2LaunchEntity = new AsusgJob2Launch();
  362. $asusgJob2LaunchEntity->asusg_jobplan_id = $JobPlanEntitty->id;
  363. $asusgJob2LaunchEntity->asusg_employee_id1 = $user->id;
  364. $asusgJob2LaunchEntity->asusg_job_uuid = $work['id_work'];
  365. $asusgJob2LaunchEntity->employees_uuid = $user->id;
  366. $asusgJob2LaunchEntity->section_uuid = $work["section_id"];
  367. $asusgJob2LaunchEntity->asusg_project_id = 0;
  368. $asusgJob2LaunchEntity->job_order = 0;
  369. $asusgJob2LaunchEntity->asusg_projecttype_id = $projtype;
  370. if (!$asusgJob2LaunchEntity->save()) {
  371. $this->logger->setLog('в Job2launch не добавилась работа => "'. $work['work_name']. '" Добавление работ будет пропущено так как такая запись уже есть.');
  372. continue;
  373. }
  374. $this->logger->setLog('в Job2launch была добавлена работа => "'. $work['work_name'].'"');
  375. $tasktypesEntity = Tasktypes::find()->where(['name' => 'Секция '.$let.', задача','company' => $this->company])->one();
  376. $tasksEntity = new Tasks();
  377. $tasksEntity->parent_id = 0;
  378. $tasksEntity->status = 2;
  379. $tasksEntity->type = $tasktypesEntity->id;
  380. $tasksEntity->assignees_arr = $user->id;
  381. $tasksEntity->created = date("Y-m-d H:i;s");
  382. $tasksEntity->asusg_job_mapped_id = $asusgJob2LaunchEntity->id;
  383. if($tasksEntity->save()) {
  384. $this->logger->setLog('в Tasks была добавлена ЗАДАЧА => "'. $work['work_name'] . '" id => '.$tasksEntity->id);
  385. } else {
  386. $this->logger->setLog('в Tasks была НЕ добавлена ЗАДАЧА => "'. $work['work_name'] . '" id => '.$tasksEntity->id);
  387. }
  388. //var_dump($tasksEntity->errors,$user->id); echo '<br>';
  389. $this->logger->setLog(' колво записей => ' . count($jsusgJob2CommandEntity) . 'type => '. gettype($jsusgJob2CommandEntity));
  390. $this->logger->setLog($JobPlanEntitty->id . ' - ' . $projtype );
  391. $arrJ = [];
  392. $countPriority = 1;
  393. ///////////////// ДОБАВЛЕНИЕ ТМЦ
  394. $mappingapiModel = new \app\models\MappingapiModel();
  395. var_dump($user->id-uuid,$work['id_work']);
  396. $tmcString = $mappingapiModel->workDetail($user->uuid,$work['id_work']);
  397. if ( '' != $tmcString) {
  398. $tasksEntity2 = new Tasks();
  399. $tasksEntity2->parent_id = $tasksEntity->id; // +
  400. $tasksEntity2->status = 2; // +
  401. $tasksEntity2->priority = $countPriority; // +
  402. // $tasksEntity2->input_id = $job->asusgJob2Launch->asusg_project_id;
  403. $tasksEntity2->created = date("Y-m-d H:i;s"); // +
  404. $tasksEntity2->type = 2159; // +
  405. $tasksEntity2->assignees_arr = $user->id; // +
  406. $tasksEntity2->asusg_job_mapped_id = $asusgJob2LaunchEntity->id;
  407. $tasksEntity2->text = $tmcString; // +
  408. $tasksEntity2->mapping_comment = $tmcString; // +
  409. if ( $tasksEntity2->save()) {
  410. $arrJ[] = $tasksEntity2->id;
  411. $this->logger->setLog('в Tasks была добавлена КОМАНДА => "'. $work['work_name'] . '" id => '.$tasksEntity2->id);
  412. } else {
  413. $this->logger->setLog('в Tasks была НЕ добавлена КОМАНДА => "'. $work['work_name'] . '" id => '.$tasksEntity2->id);
  414. }
  415. $countPriority++;
  416. }
  417. ///////////////////
  418. */
  419. $arr = [];
  420. foreach($jsusgJob2CommandEntity as $job) {
  421. $this->logger->setLog('3 =>'. $job->jobplantie->id);
  422. $tasksEntity2 = new Tasks();
  423. $tasksEntity2->parent_id = $tasksEntity->id;
  424. $tasksEntity2->status = 2;
  425. $tasksEntity2->priority = $countPriority;
  426. // $tasksEntity2->input_id = $job->asusgJob2Launch->asusg_project_id;
  427. $tasksEntity2->created = date("Y-m-d H:i;s");
  428. $tasksEntity2->type = $job->smopp_cmd_id;//Yii::$app->params['supercycletype'];
  429. $tasksEntity2->assignees_arr = $user->id;
  430. $tasksEntity2->asusg_job_mapped_id = $job->jobplantie->id;
  431. $tasksEntity2->text = $work["eq_serie"] . ' '.$work["section_lit"] . ', '. $work["outfit"] . ':' . $work['work_name'];
  432. $tasksEntity2->mapping_comment = $work["outfit"] . ': ' . $work['work_name'];
  433. $arr[] = $job->smopp_cmd_id;
  434. continue;
  435. if ( $tasksEntity2->save()) {
  436. $arrJ[] = $tasksEntity2->id;
  437. ///////////////////
  438. $query3 = "call asusg_add_checkpoints_to_task(" . $user->id . ",'" . $tasksEntity2->id . "')";
  439. Yii::$app->db->createCommand($query3)->query();
  440. ///////////////////
  441. $this->logger->setLog('в Tasks была добавлена КОМАНДА => "'. $work['work_name'] . '" id => '.$tasksEntity2->id);
  442. } else {
  443. $this->logger->setLog('в Tasks была НЕ добавлена КОМАНДА => "'. $work['work_name'] . '" id => '.$tasksEntity2->id);
  444. }
  445. $countPriority++;
  446. }
  447. $projectsLocotech = new ProjectsLocotech();
  448. $projectsLocotech->action = 197 ;
  449. $projectsLocotech->company = $this->company;
  450. $projectsLocotech->status = 2;
  451. $projectsLocotech->loco_type = $work["eq_serie"];
  452. $projectsLocotech->loco_number = $work["eq_number"];
  453. $projectsLocotech->depo ='' ;
  454. $projectsLocotech->depo_service = '';
  455. $projectsLocotech->created = date('Y-m-d H:i:s');
  456. $projectsLocotech->urgent = 0;
  457. $projectsLocotech->uuid = $work['work_name'].":".$work['repair_name'].",".$work["eq_serie"];
  458. //$projectsLocotech->save();
  459. $project_id = $projectsLocotech->id;
  460. $tasktypesarr = Tasktypes::find()->where(['in','id',$arr])->all();
  461. CreateTasks($tasktypesarr, $project_id);
  462. echo "<pre>";
  463. var_dump($user->id);
  464. var_dump($tasktypesEntity);
  465. foreach($tasktypesEntity as $task) {
  466. var_dump($task->creator_id);
  467. }
  468. echo "</pre>";
  469. //
  470. /*
  471. $projId = $this->generateProject3($work);
  472. $tasksEntity->input_id = $projId;
  473. if ($tasksEntity->save()) {
  474. $this->logger->setLog('привязка ЗАДАЧИ ( id = '.$tasksEntity->id.') прошла успешно');
  475. }
  476. foreach($arrJ as $job_id) {
  477. $tasksEnt = Tasks::findOne($job_id);
  478. $tasksEnt->input_id = $projId;
  479. if($tasksEnt->save()){
  480. $this->logger->setLog('привязка КОМАНДЫ ( id = '.$tasksEntity2->id.') прошла успешно');
  481. }
  482. }
  483. //$tasksEntity2->input_id = $projId;
  484. //if($tasksEntity2->save()){
  485. // $this->logger->setLog('привязка КОМАНДЫ ( id = '.$tasksEntity2->id.') прошла успешно');
  486. //}
  487. echo "<pre>";
  488. //var_dump($job->asusgJob2Launch->asusg_project_id);
  489. var_dump($tasksEntity2->errors,$tasksEntity->errors);
  490. echo "</pre>";
  491. */
  492. }
  493. }
  494. public function pushProject($minRes)
  495. {
  496. var_dump(count($minRes));
  497. //var_dump($minRes);
  498. foreach ( $minRes as $proj) {
  499. $arr = ['initiator' => (int)$proj['userInfo']->id, 'project_id' => (int)$proj['asusgProject_id']];
  500. //$res = \Yii::$app->db->createCommand('call asusg_build_and_start_project('.$arr["initiator"].','.$arr["project_id"].')')->execute();
  501. $res = \Yii::$app->db->createCommand('call asusg_build_and_start_project_auto('.$arr["initiator"].','.$arr["project_id"].')')->execute();
  502. echo "<pre>";
  503. var_dump($arr);
  504. var_dump("Выполнение процедуры => " . $res);
  505. echo "</pre>";
  506. }
  507. }
  508. public function prepareParams($listWorks)
  509. {
  510. $result = [];
  511. foreach ( $listWorks as $work) {
  512. $work['user_id'] = '0f9ed850-e473-11e2-aaad-ac162db0b20c';
  513. $result[] = $work;
  514. $result = json_encode($result);
  515. return $result;//json_decode($result,false);
  516. }
  517. //$result = count();
  518. }
  519. public function generateProject($work){
  520. $result = '';
  521. $let = mb_substr($work["section_lit"], -1);
  522. $sectionsEntity = Sections::find()->select(['id', 'diagnostic_map'])
  523. ->where(['locomotive_series' => $work["eq_serie"],'section_number' => mb_substr($work['section_lit'],0,-1),'letter' => $let])
  524. ->one();
  525. $diagnostic_map = $sectionsEntity->diagnostic_map;
  526. if ( null == $sectionsEntity->id) {
  527. $sectionsEntity = new Sections();
  528. $sectionsEntity->locomotive_series = $work["eq_serie"];
  529. $sectionsEntity->section_number = mb_substr($work['section_lit'],0,-1);
  530. $sectionsEntity->section_subnumber = $work["section_num"];
  531. $sectionsEntity->diagnostic_map = $work["section_DK"];
  532. $sectionsEntity->uuid = $work["section_id"];
  533. $sectionsEntity->letter = $let;
  534. if ( $sectionsEntity->save()) {
  535. $this->logger->setLog('в Sections была добавлена новая секция => '. $work["section_num"] . ' id => '.$sectionsEntity->id);
  536. } else {
  537. $this->logger->setLog('в Sections при добавлении секции произошли ошибки => '. count($sectionsEntity->errors) . ' шт.');
  538. }
  539. $diagnostic_map = $sectionsEntity->diagnostic_map;
  540. }
  541. else if( null == $sectionsEntity->diagnostic_map ) {
  542. $sectionsEntity->diagnostic_map = $work['section_DK'];
  543. $sectionsEntity->save();
  544. }
  545. if ($sectionsEntity->diagnostic_map == $work['section_DK'] ) {
  546. $query = "select pl.id from projects_locotech pl
  547. inner join tasks t on pl.id = t.input_id
  548. left join tasktypes tt on t.type = tt.id
  549. where pl.company = " . $this->company . "
  550. and pl.loco_type = '" . $work["eq_serie"] . "'
  551. and pl.loco_number = " . $work["eq_number"] . "
  552. and t.parent_id = 0
  553. and tt.letter like '%" . $let . "%'
  554. and pl.uuid like '%" . $work['repair_name']. ",%'
  555. order by pl.id desc
  556. limit 1";
  557. $projectId = Yii::$app->db->createCommand($query)->queryOne();
  558. $result = $projectId['id'];
  559. $this->logger->setLog('в Sections секция с такой диагностической картой => '. $work['section_DK'] . ' существует. Ид проекта '. $result);
  560. }
  561. if (!$result) {
  562. $projectsLocotech = new ProjectsLocotech();
  563. $projectsLocotech->action = 197 ;
  564. $projectsLocotech->company = $this->company;
  565. $projectsLocotech->status = 2;
  566. $projectsLocotech->loco_type = $work["eq_serie"];
  567. $projectsLocotech->loco_number = $work["eq_number"];
  568. $projectsLocotech->depo ='' ;
  569. $projectsLocotech->depo_service = '';
  570. $projectsLocotech->created = date('Y-m-d H:i:s');
  571. $projectsLocotech->urgent = 0;
  572. $projectsLocotech->uuid = $work['work_name'].":".$work['repair_name'].",".$work["eq_serie"];
  573. $projectsLocotech->save();
  574. $result = $projectsLocotech->id;
  575. $this->logger->setLog('Такого проекта еще не было пришлось создать. Ид проекта => '. $result);
  576. }
  577. //var_dump($result);
  578. return $result;
  579. }
  580. public function generateProject3($work){
  581. $result = '';
  582. $projectsLocotech = new ProjectsLocotech();
  583. $projectsLocotech->action = 197 ;
  584. $projectsLocotech->company = $this->company;
  585. $projectsLocotech->status = 2;
  586. $projectsLocotech->loco_type = $work["eq_serie"];
  587. $projectsLocotech->loco_number = $work["eq_number"];
  588. $projectsLocotech->depo ='' ;
  589. $projectsLocotech->depo_service = '';
  590. $projectsLocotech->created = date('Y-m-d H:i:s');
  591. $projectsLocotech->urgent = 0;
  592. $projectsLocotech->uuid = $work['work_name'].":".$work['repair_name'].",".$work["eq_serie"];
  593. $projectsLocotech->save();
  594. $result = $projectsLocotech->id;
  595. $this->logger->setLog('Такого проекта еще не было пришлось создать. Ид проекта => '. $result);
  596. //var_dump($result);
  597. return $result;
  598. }
  599. }