MappingHandlerController.php 62 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468
  1. <?php
  2. namespace app\controllers;
  3. use app\models\ElasticLog;
  4. use Yii;
  5. use yii\web\Controller;
  6. use app\models\MappingworksModel;
  7. use app\models\MainModel;
  8. use app\models\LogDoneList;
  9. use app\models\ProcedureModel;
  10. use app\models\entity\Tasks;
  11. use app\models\ProjectsModel;
  12. use app\models\entity\Accounts;
  13. use app\models\entity\Sections;
  14. use app\models\LocomotiveModel;
  15. use app\models\entity\Tasktypes;
  16. use app\models\logger\LoggerFile;
  17. use app\models\entity\Repairtypes;
  18. use app\models\entity\Projecttypes;
  19. use app\models\entity\AsusgProject;
  20. use app\models\entity\AsusgJobPlan;
  21. use app\models\MappingHandlerModel;
  22. use app\models\entity\AsusgJob2Launch;
  23. use app\models\entity\AsusgProjectType;
  24. use app\models\entity\LocomotiveSeries;
  25. use app\models\entity\ProjectsLocotech;
  26. use app\models\entity\AsusgJob2Command;
  27. use app\models\entity\AsusgMeasurements;
  28. use \app\models\LogEippResponse;
  29. use app\models\entity\Jobtypes;
  30. use app\models\procedure\AsusgAddMeasurementToTaskModel;
  31. use app\models\MappingapiModel;
  32. use app\models\QueueModel;
  33. use app\models\procedure\StartProjectForLocoModel;
  34. class MappinghandlerController extends Controller
  35. {
  36. private $logger;
  37. private $company;
  38. private $testIdpl2;
  39. private $testIdpl3;
  40. public function beforeAction($action)
  41. {
  42. parent::beforeAction($action);
  43. $log = new LoggerFile();
  44. $this->logger = new MappingHandlerModel($log);
  45. return true;
  46. }
  47. // запускается периодически через крон
  48. public function actionGetworks($company)
  49. {
  50. $this->company = $company;
  51. $GWparams = [
  52. 'url' => 'http://devplatform.digitaldepot.ru:8085/Thingworx/Things/SMoPPIntegrationLibrary/Services/getUserWorks',
  53. 'param' => '',
  54. 'login' => 'ПройдаковИА',
  55. 'pass' => 'Ip15351112'
  56. ];
  57. // список сотрудников онлайн
  58. $onlineUser = $this->getOnlineMobileUser($company);
  59. if( 0 == count($onlineUser)) {
  60. return 'Нет сотрудников онлайн';
  61. }
  62. //$this->logger->setLog('ID пользователя => ' . (int)$_SESSION["id"]);
  63. $this->logger->setLog( date("Y-m-d H:i:s") . "\n");
  64. $mainModel = new MainModel();
  65. // для каждого сотрудника онлайн запускаем проекты если они еще не запущены
  66. foreach($onlineUser as $user) {
  67. if ( '' == $user->uuid and null == $user->uuid) {
  68. continue;
  69. }
  70. $GWparams['param'] = $user->uuid;
  71. // Запрос к асусг список работ
  72. //$GWparams['param'] = '';
  73. //$listWorks = json_decode($this->curlRequest2($GWparams));
  74. $listWorks = [];//json_decode($mainModel->curlRequest2($GWparams));
  75. // Список отсутствующих работ
  76. $listIsabsentWorks = $this->Getisabsentworks($listWorks,$GWparams);
  77. // проверка на существование работ в jobplan
  78. //=========================================================================================================
  79. ElasticLog::eipp($GWparams, 'начало выполнения работы', $user->uuid);
  80. $listWorks2 = json_decode($mainModel->curlRequest2($GWparams),true);
  81. ElasticLog::eipp($listWorks2, 'завершение выполнения работы', $user->uuid, false);
  82. $this->logger->setLog('Колличество работ из еипп =>'. count($listWorks2).' для сотрудника =>' . $user->id);
  83. $listIsabsentWorks2 = $this->Getisabsentworksjp($listWorks2); // вновь утвержденный план 1 | вернет список работ кот нет ( в JobPlan )
  84. $listIssetWorks3 = $this->Getissetworksjp($listWorks2);
  85. $this->logger->setLog('Колличество работ из еипп ( нет в jobplan) =>'. count($listIsabsentWorks2));
  86. $this->logger->setLog('Колличество работ из еипп ( есть в jobplan) =>'. count($listIssetWorks3));
  87. $this->logger->setLog('Сверхцикловые');
  88. $addJob2launch2 = $this->addJob2launch2($listIsabsentWorks2,$user);
  89. $this->logger->setLog('Мэппинг');
  90. $addJob2launch3 = $this->addJob2launch3($listIssetWorks3,$user);
  91. $this->logger->setLog("Интеграция сверхцикловых работ прошла без падений!\n=================== НОВАЯ ИТЕРАЦИЯ ==================================\n");
  92. //echo '<pre>';
  93. //var_dump($user->id,$listIsabsentWorks2);
  94. //var_dump($user->id,$listIssetWorks3);
  95. // var_dump($user->id,$listWorks2);
  96. // echo '</pre>';
  97. continue;
  98. //=========================================================================================================
  99. $this->addWorksInJobPlan($listWorks);
  100. //$this->addWorksInTasks($listWorks);
  101. $listIsabsentWorks = $this->addWorksInTaskType($listWorks,$listIsabsentWorks);
  102. //echo "<pre>"; var_dump($listIsabsentWorks); echo "</pre>";
  103. //echo "++++++++++++++";
  104. // Группировка работ по локомотивам/секциям
  105. //echo "<pre>"; var_dump($listIsabsentWorks); echo "</pre>"; exit;
  106. $listW = $this->GetworksOnLoco($listIsabsentWorks);
  107. // временный костыль
  108. //$userInfo = $this->getUserInfo($GWparams);
  109. // временный костыль
  110. // возвращает тип проекта
  111. $projecttypeId = $this->getTypeProject($user);
  112. //->addProject()
  113. // Запускаем проект
  114. $startedProj = $this->startProject($listW,$user,$projecttypeId);
  115. // проверить есть ли для таких работ инструкции
  116. $minRes = $this->checkMapping($startedProj);
  117. // если что-то есть то запланировать asusg_job2launch
  118. $minRes = $this->addJobproject($minRes);
  119. $this->addJob2launch($minRes);
  120. $this->pushProject($minRes);
  121. //echo "<pre>";
  122. //var_dump($listIsabsentWorks);
  123. //echo "</pre>";
  124. }
  125. exit;
  126. //return $listWorks;
  127. }
  128. // запускается по запросу ЕИПП
  129. public function actionStartuserwork()
  130. {
  131. $mainModel = new MainModel();
  132. // для каждого сотрудника онлайн запускаем проекты если они еще не запущены
  133. //if( '' == $user->uuid and null == $user->uuid) {
  134. // continue;
  135. // }
  136. $params = \Yii::$app->request->post();
  137. //$param = json_decode($params['params'],true);
  138. //$GWparams['param'] = $user->uuid;
  139. // Запрос к асусг список работ
  140. $listWorks = json_decode($params['params'],true);
  141. //$listWorks = json_decode($params);
  142. //$ee = $param['data'] ;
  143. $GWparams['param'] = '0f9ed850-e473-11e2-aaad-ac162db0b20c';
  144. $listWorks = $this->prepareParams($listWorks['data']); // временный метод для подготовки параметров нужного вида.
  145. // echo "<pre>"; var_dump(gettype($listWorks)); echo "</pre>";
  146. return json_encode(['r' => gettype($listWorks)],true);
  147. //exit;
  148. // Список отсутствующих работ
  149. $listIsabsentWorks = $this->Getisabsentworks($listWorks,$GWparams);
  150. // проверка на существование работ в jobplan
  151. $this->addWorksInJobPlan($listWorks);
  152. $listIsabsentWorks = $this->addWorksInTaskType($listWorks,$listIsabsentWorks);
  153. //echo "<pre>"; var_dump($listIsabsentWorks); echo "</pre>";
  154. //echo "++++++++++++++";
  155. //echo "<pre>"; var_dump($user['id'],$listIsabsentWorks); echo "</pre>"; exit;
  156. // Группировка работ по локомотивам/секциям
  157. //echo "<pre>"; var_dump($listIsabsentWorks); echo "</pre>"; exit;
  158. $listW = $this->GetworksOnLoco($listIsabsentWorks);
  159. // временный костыль
  160. //$userInfo = $this->getUserInfo($GWparams);
  161. // временный костыль
  162. // возвращает тип проекта
  163. $projecttypeId = $this->getTypeProject($user);
  164. //->addProject()
  165. // Запускаем проект
  166. $startedProj = $this->startProject($listW,$user,$projecttypeId);
  167. // проверить есть ли для таких работ инструкции
  168. $minRes = $this->checkMapping($startedProj);
  169. // если что-то есть то запланировать asusg_job2launch
  170. $minRes = $this->addJobproject($minRes);
  171. $this->addJob2launch($minRes);
  172. $this->pushProject($minRes);
  173. //echo "<pre>";
  174. //var_dump($listIsabsentWorks);
  175. //echo "</pre>";
  176. //return $listWorks;
  177. }
  178. public function actionDojob()
  179. {
  180. //phpinfo();
  181. //$this->logger->setLog('text');
  182. //$procedureModel = new ProcedureModel();
  183. //$procedureModel->asusg_build_and_start_project_auto(27,3183);
  184. 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();
  185. //echo 'sdfsd';
  186. }
  187. public function actionDojob2()
  188. {
  189. $doneList = LogDoneList::find()->where(['>','date',date('Y-m-d').' 00:00:00'])->all();
  190. echo "<pre>";
  191. foreach($doneList as $desc){
  192. //var_dump($desc->desc);
  193. }
  194. //$d = json_decode($res,true);
  195. //$d = json_decode($res);
  196. //var_dump($jobtypes);
  197. //$res = new QueueModel();
  198. //$r = $res->execute([],'0f9ed870-e473-11e2-aaad-ac162db0b20c');
  199. $query = "select t.id as task_id, pl.status from projects_locotech pl
  200. inner join tasks t on pl.id = t.input_id
  201. left join tasks tc on tc.parent_id = t.id
  202. where pl.company = 3
  203. and pl.loco_type = '3ЭС5К'
  204. and pl.loco_number = 0364
  205. and t.parent_id = 0
  206. and pl.status <> 5
  207. and tc.text like '%0364А%'
  208. and tc.assignees_arr = 393
  209. and pl.uuid like '%ТР-1%'
  210. order by pl.id desc
  211. limit 1";
  212. //echo $query;
  213. $projectRes = Yii::$app->db->createCommand($query)->queryOne();
  214. //echo $projectRes['task_id'];
  215. //\app\models\entity\UserActivity::ping(387);
  216. //$response = $logEippResponseEntity->response;
  217. //$work = json_decode($response,true);
  218. var_dump($projectRes);
  219. echo "sfsfsdf";
  220. exit;
  221. foreach ( $arr as $b) {
  222. $resd = AsusgJob2Launch::findOne(['asusg_job_uuid' => $b]);
  223. //var_dump($resd->id, $resd->employees_uuid);
  224. }
  225. echo "</pre>";
  226. //$jsusgJob2CommandEntity = AsusgJob2Command::find()->where(['asusg_job_id' => 1222, 'asusg_projecttype_id' => 16 ])->all();
  227. //$work_uuid = '602cfd16-9cef-4ff6-b31e-8e89a85b0854';
  228. foreach($jobtypes as $job) {
  229. //$job->job_uuid = $work_uuid;
  230. //var_dump($job->id);
  231. }
  232. //$tasksEntity = Tasks::find()->where(['_parent_id' => 23455])->andWhere(['>', 'priority', 0])->min('type');
  233. // $MappingworksModel = new MappingworksModel();
  234. // $MappingworksModel->workToExecute(115220);exit;
  235. \app\models\LogEippResponse::addLog('123123','asdasdasdasd');
  236. //require_once $_SERVER["DOCUMENT_ROOT"].'/functions.php';
  237. //$r = FindActions();
  238. //$date->timezone_type = 5;
  239. //var_dump($date);
  240. //echo "Из такого = " . date_format($date); echo "<br><br>";
  241. //$count = 0;
  242. /*
  243. $tokens = [
  244. '0x03 0x72 0x7D 0xA2 0xF3 2x91 0x95',
  245. 'plastic',
  246. '0x02 0x73 0x7D 0xA3 0xF3 2x92 0x90',
  247. 'metall',
  248. '0x01 0x54 0x7D 0xC1 0xF3 1x93 0x91',
  249. '0x14 0x76 0x7D 0xD7 0xF3 x95 0x93',
  250. '0x05 0x75 0x7D 0xE5 0xF3 5x94 0x92',
  251. '0x24 0x54 0x7B 0xF2 0xF3 9x98 0x94',
  252. ];
  253. foreach( $tokens as $token) {
  254. $oil = new \app\models\entity\Oilstat();
  255. $oil->cond = 'N';
  256. $oil->token = $token;
  257. $oil->date = date('Y-m-d H:i:s');
  258. $oil->device_id = 777;
  259. //$oil->save();
  260. sleep(1);
  261. var_dump($oil->id);
  262. var_dump($oil->errors);
  263. }
  264. $r = \app\models\entity\OilstatTemp::findOne();
  265. var_dump($r);
  266. */
  267. /*
  268. $conf = ['true' => true, 'false' => false];
  269. $execResult = json_decode($str,true);
  270. foreach( $execResult['rows'] as $row) {
  271. $rowArray = json_decode($row["result"],true);
  272. if ( null != $rowArray["result"]) {
  273. //return $conf[$rowArray["result"]];
  274. }
  275. }
  276. echo 0;
  277. return false;*/
  278. }
  279. public function actionEippresponse()
  280. {
  281. $time = Yii::$app->request->get('indx');
  282. if ( null == $time) {
  283. return false;
  284. }
  285. $logEipp = LogEippResponse::find()->where(['indx' => $time])->orderBy(['id' => SORT_DESC])->one();
  286. $resp = json_decode($logEipp->response,true);
  287. foreach ($resp["rows"] as &$item ) {
  288. $item['result'] = json_decode($item['result'],true);
  289. }
  290. //echo "<pre>";
  291. //print_r($resp);
  292. //echo "<pre>";
  293. return $this->render('index', [
  294. 'model' => $resp,
  295. ]);
  296. }
  297. public function actionCleartasks()
  298. {
  299. $tasksEntity = Tasks::find()->where(['in', 'assignees_arr', [ ] ])->all();
  300. $launch = [];
  301. $projects = [];
  302. var_dump(count($tasksEntity));
  303. foreach( $tasksEntity as $task) {
  304. var_dump($task->id);
  305. $proj = projectsLocotech::findOne($task->input_id);
  306. if ( null != $proj) {
  307. //var_dump($proj->id);
  308. //$proj->delete();
  309. }
  310. $launch = AsusgJob2Launch::findOne($task->asusg_job_mapped_id);
  311. if ( null != $launch) {
  312. //var_dump($launch->id);
  313. //$launch->delete();
  314. }
  315. $smrmnt = AsusgMeasurements::find()->where(['smopp_task_id' => $task->id])->all();
  316. if ( null != $smrmnt) {
  317. foreach($smrmnt as $item) {
  318. //$item->delete();
  319. }
  320. }
  321. //$projects[] = $task->input_id;
  322. //$launch[] = $task->asusg_job_mapped_id;
  323. }
  324. foreach( $tasksEntity as $task) {
  325. //$task->delete();
  326. }
  327. var_dump('true');
  328. }
  329. public function actionCheckeippworks()
  330. {
  331. $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];
  332. $accountsEntity = Accounts::find()->where(['in','id',$userArr])->andWhere(['company' => 3])->all();
  333. $GWparams = ['url' => 'http://' . Yii::$app->params['api']['domain'].'/Thingworx/Things/2050UserLibraryExp/Services/my_works',
  334. //'url' => 'http://devplatform.digitaldepot.ru:8085/Thingworx/Things/SMoPPIntegrationLibrary/Services/getUserWorks',
  335. 'param' => '',
  336. 'login' => 'ПройдаковИА',
  337. 'pass' => 'Ip15351112'
  338. ];
  339. $mainModel = new MainModel();
  340. $resArray = [];
  341. foreach( $accountsEntity as $user) {
  342. $tempArr = [];
  343. $GWparams['param'] = $user->uuid;
  344. $responseMyWorks = $mainModel->curlRequest2($GWparams);
  345. $listWorks = json_decode($responseMyWorks,true);
  346. $tempArr = ['id' => $user->id,'uuid' => $user->uuid,'response' => $listWorks['rows'][0]["result"],'responseAll' => $listWorks];
  347. $resArray[$user->name] = $tempArr;
  348. }
  349. $resArray = json_encode($resArray,true);
  350. LogDoneList::addLog('CheckIssueWorks',$resArray);
  351. //var_dump(json_decode(LogDoneList::findOne(83)->desc,true));
  352. }
  353. public function actionDopro()
  354. {
  355. //$procedureModel = new StartProjectForLocoModel();
  356. //$procedureModel->execute(49,208,'Э5К',100121,'Проект АСУ СГ № test');
  357. /*set taskId = (select max(t.id)
  358. from tasks t
  359. where t.input_id = projectId
  360. and t.text = tmpText
  361. and t.parent_id = 0);*/
  362. //$ttt = \app\models\procedure\AsusgAddCheckpointsToTaskModel::execute(27,18807);
  363. $JobPlanEntitty = AsusgJobplan::find()->where(['name' => 'Тормозное и пневматическое оборудование после ремонта испытать , отрегулировать согласно инструкции'])->one(); // 1204 1567
  364. $jsusgJob2CommandEntity = AsusgJob2Command::find()->where(['asusg_job_id' => $JobPlanEntitty->id])->all();
  365. foreach($jsusgJob2CommandEntity as $job) {
  366. echo '<pre>';
  367. var_dump('3 =>'. $job->id, $job->asusg_job_id);
  368. var_dump('3 =>'. $job->jobplantie->id);
  369. echo '</pre>';
  370. }
  371. exit;
  372. }
  373. public function actionProctest()
  374. {
  375. //phpinfo();
  376. //$this->logger->setLog('text');
  377. $procedureModel = new ProcedureModel();
  378. $procedureModel->asusg_build_and_start_project_auto(27,210);
  379. }
  380. /*
  381. public function curlRequest2($params){
  382. $urlWithParam = $params['url'].'?user_id='. $params['param'] ;
  383. $curl = curl_init();
  384. curl_setopt($curl, CURLOPT_URL, $urlWithParam);
  385. curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
  386. curl_setopt($curl, CURLOPT_USERPWD, $params['login'] . ":" . $params['pass']);
  387. curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-Type: application/json","Accept: application/json"));
  388. curl_setopt($curl, CURLOPT_TIMEOUT, 20);
  389. curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
  390. curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
  391. curl_setopt($curl, CURLOPT_POST, 1);
  392. curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
  393. curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
  394. $result = curl_exec($curl);
  395. return $result;
  396. }
  397. */
  398. public function Getisabsentworks($listWorks = null, $GWparams ){
  399. if ( null == $listWorks) {
  400. return false;
  401. }
  402. $arrayIdWorks = [];
  403. foreach( $listWorks->data as $work ) {
  404. $arrayIdWorks[] = ($work->id_work)?$work->id_work:$work['id_work'];
  405. }
  406. if( empty($arrayIdWorks) and is_array($listWorks)) {
  407. foreach( $listWorks as $work ) {
  408. $arrayIdWorks[] = $work['id_work'];
  409. }
  410. }
  411. //$arrayIdWorks[] = 'c7cfdeb5-9293-4314-9958-15d15a297532';
  412. //$asusgJob2LaunchEntity = AsusgJob2Launch::find()->where(['not in','asusg_job_uuid_',$arrayIdWorks])->all();
  413. $asusgJob2LaunchEntity = (new \yii\db\Query())
  414. ->select(['t.assignees_arr','ai.id','t.status','t.id','jl.asusg_job_uuid'])
  415. //->select(['t.assignees_arr'])
  416. ->from('`asusg_job2launch` as `jl`')
  417. ->leftJoin('`tasks` as `t`', 'jl.id = t.asusg_job_mapped_id')
  418. ->rightJoin('`accounts_internal` as `ai`', 't.assignees_arr = cast(ai.id as char)')
  419. //->where(['jl.asusg_job_uuid' => $job_uuid])
  420. ->andWhere(['in','asusg_job_uuid',$arrayIdWorks])
  421. ->andWhere(['ai.uuid' => $GWparams['param']])
  422. ->andWhere(['<>','t.parent_id', 0])
  423. ->groupBy(['jl.asusg_job_uuid'])
  424. ->all();
  425. $resultArrWork = [];
  426. foreach( $asusgJob2LaunchEntity as $work ) {
  427. $resultArrWork[] = $work["asusg_job_uuid"];
  428. }
  429. array_diff ($arrayIdWorks, $resultArrWork);
  430. foreach( $listWorks->data as $works ) {
  431. if ( in_array($works->id_work, array_diff ($arrayIdWorks, $resultArrWork))) {
  432. $result[] = $works;
  433. }
  434. }
  435. if( empty($result) and is_array($listWorks)) {
  436. foreach( $listWorks as $work ) {
  437. if ( in_array($work['id_work'], array_diff ($arrayIdWorks, $resultArrWork))) {
  438. $result[] = $works;
  439. }
  440. }
  441. }
  442. return $result;
  443. }
  444. public function Getisabsentworksjp( $listWorks = null){
  445. $result = [];
  446. if ( null == $listWorks) {
  447. return false;
  448. }
  449. foreach( $listWorks['data'] as $work) {
  450. $asusgJobPlan = AsusgJobPlan::find()->where(['name' => $work['work_name']])->one();
  451. if ( null == $asusgJobPlan ){
  452. $result[] = $work;
  453. }
  454. }
  455. return $result;
  456. }
  457. public function Getissetworksjp( $listWorks = null){
  458. $result = [];
  459. if ( null == $listWorks) {
  460. return false;
  461. }
  462. foreach( $listWorks['data'] as $work) {
  463. $asusgJobPlan = AsusgJobPlan::find()->where(['name' => $work['work_name']])->one();
  464. if ( null != $asusgJobPlan ){
  465. $result[] = $work;
  466. }
  467. }
  468. return $result;
  469. }
  470. public function getOnlineMobileUser($company){
  471. $result = [];
  472. $accountsEntity = \app\models\entity\Accounts::find()->where(['company' => $company])->all();
  473. foreach ($accountsEntity as $account) {
  474. //var_dump($account->id,'<br>');
  475. $last_seen_mobile = ( null != $account->last_seen_mobile )? new \DateTime($account->last_seen_mobile): $account->last_seen_mobile ;
  476. $online_mobile = $this->OnlineAccountCheck($this->TimeString($last_seen_mobile));
  477. //var_dump(( !$online_mobile ),'<br>');
  478. if ( !$online_mobile ){
  479. continue;
  480. }
  481. $result[] = $account;//['id' => $account->id, 'uuid' => $account->uuid];
  482. }
  483. return $result;
  484. }
  485. public function startProject($params,$userInfo,$projecttypeId){
  486. $arrayResultTemp = [];
  487. $projectsModel = new ProjectsModel();
  488. foreach($params as &$item){
  489. $arrayResult = [];
  490. $arrayResult['loco_type'] = $item['info']['locomotive_series'];
  491. $arrayResult['loco_number'] = $item['info']["section_subnumber"];
  492. $arrayResult['action'] = $projecttypeId->id;
  493. $arrayResult['company'] = $userInfo->company;
  494. //$arrayResult['section_id'] = $item['info']["section_number"];
  495. $arrayResult['depo'] = '';
  496. $arrayResult['depo_service'] = '';
  497. $arrayResult['kind'] = '';
  498. $item['project'] = 'sdfsdfsd';//$projectsModel->ProjectsModel($arrayResult,$item['info']["section_number"]);
  499. $item['userInfo'] = $userInfo;
  500. $item['projecttypeId'] = $projecttypeId->id;
  501. }
  502. return $params;
  503. }
  504. public function getUserInfo($user)
  505. {
  506. if (!$user){
  507. return '';
  508. }
  509. $accountsEntity = Accounts::find()->where(['uuid' => $user['param'] ])->one();
  510. return $accountsEntity;
  511. }
  512. /*
  513. public function getTypeProject($user)
  514. {
  515. $projettypesEntity = Projecttypes::find()->select('id')->where(['company' => $user->company, 'name' => 'Проект из мэппинга'])->one();
  516. return $projettypesEntity;
  517. }
  518. */
  519. public function getTypeProject($onlineUser)
  520. {
  521. if (empty($onlineUser)) {
  522. return [];
  523. }
  524. //foreach($onlineUser as $user) {
  525. $company = $onlineUser->company;
  526. //}
  527. $projettypesEntity = Projecttypes::find()->select('id')->where(['company' => $company, 'name' => 'Проект из мэппинга'])->one();
  528. return $projettypesEntity;
  529. }
  530. public function OnlineAccountCheck($last_seen)
  531. {
  532. $last_seen = date($last_seen);
  533. $time = (time()-strtotime($last_seen));
  534. if ($time <= Yii::$app->params['onlineMobileTimeoutSeconds'])
  535. return true;
  536. return false;
  537. }
  538. public function TimeString($timeobj)
  539. {
  540. if ($timeobj != null)
  541. return $timeobj->format('d.m.Y H:i');
  542. //return date('d.m.Y H:i', $timeobj);
  543. }
  544. // // устаревшая версия GetworksOnLoco
  545. /*
  546. public function GetworksOnLoco($listWorks)
  547. {
  548. $result = [];
  549. if (empty($listWorks)){
  550. return $result;
  551. }
  552. $arrayResult = [];
  553. foreach ($listWorks as $work){
  554. $arrayResult[] = $work->section_id;
  555. }
  556. $sectionsEntity = Sections::find()->where(['in','uuid',$arrayResult])->asArray()->all();
  557. $arrayResult = [];
  558. $arrayResultTemp = [];
  559. $arrayIdSerieTemp = [];
  560. foreach($sectionsEntity as $sec){
  561. $arrayResult[] = $sec['uuid'];
  562. $arrayResultTemp[$sec['uuid']] = $sec;
  563. $LocomotiveSeriesEntity = LocomotiveSeries::findOne(['name' => $sec['locomotive_series']]);
  564. $arrayIdSerieTemp[$sec['uuid']] = $LocomotiveSeriesEntity->id;
  565. }
  566. $tempArray = [];
  567. foreach($listWorks as $w) {
  568. if ( in_array($w->section_id,$arrayResult)) {
  569. $tempArray[] = $w;
  570. $result[$w->section_id] = [ 'info_obj' => $tempArray ,'info'=> $arrayResultTemp[$w->section_id],'id_serie' => $arrayIdSerieTemp[$w->section_id]];
  571. }
  572. }
  573. return $result;
  574. }
  575. */
  576. // Добавление не существующих работ в JobPlan ( сверхцикловые )
  577. public function addWorksInJobPlan($listWorks) {
  578. $result = [];
  579. if (empty($listWorks)){
  580. return $result;
  581. }
  582. $arrayIdWorks = [];
  583. foreach( $listWorks->data as $work ) {
  584. $arrayIdWorks[] = $work;
  585. }
  586. foreach ($arrayIdWorks as $work){
  587. $asusgJobPlanEntity = new AsusgJobPlan();
  588. $asusgJobPlanEntity->name = $work->work_name;
  589. $asusgJobPlanEntity->sections = 'АБВ';
  590. if (!$asusgJobPlanEntity->save()) {
  591. $result[] = $asusgJobPlanEntity->errors;
  592. }
  593. }
  594. return $result;
  595. }
  596. // Добавление не существующих работ в Tasktype ( сверхцикловые )
  597. public function addWorksInTaskType($listWorks, $listIsabsentWorks ) {
  598. $result = $listIsabsentWorks;
  599. if (empty($listWorks)){
  600. return $result;
  601. }
  602. $arrayIdWorks = [];
  603. foreach( $listWorks->data as $work ) {
  604. $arrayIdWorks[] = $work;
  605. }
  606. foreach ($arrayIdWorks as $work){
  607. $tasktypesEntity = new Tasktypes();
  608. $tasktypesEntity->creator_id = 49 ;
  609. $tasktypesEntity->name = $work->work_name ;
  610. $tasktypesEntity->description = 'По запросу АСУ СГ: сверхцикловая работа' ;
  611. $tasktypesEntity->company = \Yii::$app->request->get('company');
  612. $tasktypesEntity->main_task = 0 ;
  613. $tasktypesEntity->confirmtype = 0 ;
  614. $tasktypesEntity->time_to_complete_minutes = 61 ;
  615. $tasktypesEntity->subtasks = '' ;
  616. $tasktypesEntity->letter = 'АБВ' ;
  617. if ($tasktypesEntity->save()) {
  618. $flag = 0;
  619. foreach($result as $task) {
  620. if ( $task->work_name == $tasktypesEntity->name ){
  621. $flag = 1;
  622. }
  623. }
  624. if ( 0 == $flag ) {
  625. $result[] = $work;//$tasktypesEntity->errors;
  626. }
  627. }
  628. }
  629. return $result;
  630. }
  631. // // новая версия GetworksOnLoco
  632. public function GetworksOnLoco($listWorks)
  633. {
  634. $result = [];
  635. if (empty($listWorks)){
  636. return $result;
  637. }
  638. $arrayResult = [];
  639. foreach ($listWorks as $work){
  640. $sectionsEntity = new Sections();
  641. $sectionsEntity->section_number = $work->eq_number;
  642. $sectionsEntity->locomotive_series = $work->eq_serie;
  643. $sectionsEntity->section_subnumber = $work->section_num;
  644. $sectionsEntity->uuid = $work->section_id;
  645. $sectionsEntity->diagnostic_map = $work->section_DK;
  646. $sectionsEntity->letter = mb_substr($work->section_lit, -1);
  647. if (! $sectionsEntity->save()) {
  648. continue;
  649. }
  650. }
  651. foreach ($listWorks as $work){
  652. $arrayResult[] = $work->section_id;
  653. }
  654. $sectionsEntity = Sections::find()->where(['in','uuid',$arrayResult])->asArray()->all();
  655. $arrayResult = [];
  656. $arrayResultTemp = [];
  657. $arrayIdSerieTemp = [];
  658. foreach($sectionsEntity as $sec){
  659. $arrayResult[] = $sec['uuid'];
  660. $arrayResultTemp[$sec['uuid']] = $sec;
  661. $LocomotiveSeriesEntity = LocomotiveSeries::findOne(['name' => $sec['locomotive_series']]);
  662. $arrayIdSerieTemp[$sec['uuid']] = $LocomotiveSeriesEntity->id;
  663. }
  664. $tempArray = [];
  665. foreach($listWorks as $w) {
  666. //var_dump(( in_array($w->section_id,$arrayResult)), $w->section_id .' ==', );
  667. if ( in_array($w->section_id,$arrayResult)) {
  668. $tempArray[] = $w;
  669. $result[$w->section_id] = [ 'info_obj' => $tempArray ,'info'=> $arrayResultTemp[$w->section_id],'id_serie' => $arrayIdSerieTemp[$w->section_id]];
  670. }
  671. }
  672. return $result;
  673. }
  674. public function checkMapping($arrProj)
  675. {
  676. $tempResult = [];
  677. $result = [];
  678. foreach ( $arrProj as &$proj) {
  679. foreach ( $proj['info_obj'] as $work) {
  680. $tempResult[] = $work->work_name;
  681. }
  682. $res = AsusgJobPlan::find()->where(['in', 'name',$tempResult])->all();
  683. $proj['jobplan'] = $res;
  684. }
  685. return $arrProj;
  686. }
  687. public function addJobproject($minRes)
  688. {
  689. $projectTypes = [];
  690. foreach ( $minRes as &$proj) {
  691. foreach($proj['info_obj'] as $obj){
  692. $repairtypesEntity = Repairtypes::find()->select('id')->where(['name'=> $obj->repair_name])->one();
  693. $projectTypes[] = $repairtypesEntity->id;
  694. }
  695. $projectTypes = array_unique($projectTypes);
  696. foreach ( $projectTypes as $type) {
  697. $field = Yii::$app->params['sections_letter'][$proj['info']["letter"]];
  698. $asusgProjectEntity = new AsusgProject();
  699. $asusgProjectEntity->loco_serie_id = $proj['id_serie']; //locomotive_series
  700. $asusgProjectEntity->repair_type = $type; // repairtypes name из асусг
  701. $asusgProjectEntity->loco_number = $proj['info']["section_number"];
  702. $asusgProjectEntity->$field = $proj['info']["section_subnumber"];
  703. $asusgProjectTypeEntity = AsusgProjectType::findOne(['loco_serie_id' => $proj['id_serie'], 'repair_type' => $type]);
  704. $asusgProjectEntity->asusg_projecttype_id = $asusgProjectTypeEntity->id;
  705. $asusgProjectEntity->save();
  706. echo "<pre>";
  707. var_dump($asusgProjectEntity->errors);
  708. //var_dump("Выполнение процедуры => " . $res);
  709. echo "</pre>";
  710. $proj['asusgProject_id'] = $asusgProjectEntity->id;
  711. $proj['repair_type'] = $type;
  712. }
  713. }
  714. return $minRes;
  715. }
  716. public function addJob2launch($minRes)
  717. {
  718. foreach ( $minRes as $proj) {
  719. $resultArr = [];
  720. $order = 1;
  721. foreach ( $proj['jobplan'] as $work) {
  722. $sectionTemp = '';
  723. $id_workTemp = '';
  724. foreach($proj['info_obj'] as $obj){
  725. //var_dump(( $obj->work_name == $work->name), $obj->work_name.' =='. $work->name);
  726. if( $obj->work_name == $work->name){
  727. $sectionTemp = $obj->section_id;
  728. $id_workTemp = $obj->id_work;
  729. break;
  730. }
  731. }
  732. $asusgJob2LaunchEntity = new AsusgJob2Launch();
  733. $asusgJob2LaunchEntity->asusg_jobplan_id = $work->id;
  734. $asusgJob2LaunchEntity->asusg_employee_id1 = $proj['userInfo']->id;
  735. $asusgJob2LaunchEntity->asusg_job_uuid = $id_workTemp;
  736. $asusgJob2LaunchEntity->section_uuid = $sectionTemp;
  737. $asusgJob2LaunchEntity->asusg_project_id = $proj['asusgProject_id'];
  738. $asusgJob2LaunchEntity->job_order = $order;
  739. $asusgProjectTypeEntity = AsusgProjectType::findOne(['loco_serie_id' => $proj['id_serie'], 'repair_type' => $proj['repair_type']]);
  740. //var_dump($id_workTemp);
  741. //var_dump($proj['id_serie'],$proj['repair_type']);
  742. //var_dump($asusgProjectTypeEntity->id);
  743. $asusgJob2LaunchEntity->asusg_projecttype_id = $asusgProjectTypeEntity->id;
  744. $asusgJob2LaunchEntity->save();
  745. echo "<pre>";
  746. var_dump($asusgJob2LaunchEntity->id);
  747. var_dump($asusgJob2LaunchEntity->errors);
  748. //var_dump($sectionsEntity);
  749. echo "</pre>";
  750. $order++;
  751. }
  752. }
  753. }
  754. public function getProjectType($repairName,$serieName)
  755. {
  756. $result = null;
  757. $repairtypesEntity = Repairtypes::findOne(['name' => $repairName]);
  758. $locomotiveSeriesEntity = LocomotiveSeries::findOne(['name' => $serieName]);
  759. $asusgProjectTypeEntity = AsusgProjectType::findOne(['repair_type' => $repairtypesEntity->id , 'loco_serie_id' => $locomotiveSeriesEntity->id]);
  760. if ( null != $asusgProjectTypeEntity->id ) {
  761. $result = $asusgProjectTypeEntity->id;
  762. }
  763. return $result;
  764. }
  765. public function addJob2launch2($listWorks,$user)
  766. {
  767. require_once $_SERVER["DOCUMENT_ROOT"].'/functions.php';
  768. //var_dump(gettype($this->entityManager));
  769. foreach ( $listWorks as $work) {
  770. $mappingapiModel = new \app\models\MappingapiModel();
  771. $dwResult = $mappingapiModel->workDetail($user->uuid,$work['id_work']);
  772. $projtype = $this->getProjectType($work["repair_name"],$work["eq_serie"]);
  773. $let = mb_substr($work["section_lit"], -1);
  774. $resultArr = [];
  775. $asusgJob2LaunchEntity = new AsusgJob2Launch();
  776. $asusgJob2LaunchEntity->asusg_jobplan_id = Yii::$app->params['supercycleplan'];
  777. $asusgJob2LaunchEntity->asusg_employee_id1 = $user->id;
  778. $asusgJob2LaunchEntity->asusg_job_uuid = $work['id_work'];
  779. $asusgJob2LaunchEntity->employees_uuid = $user->id;
  780. $asusgJob2LaunchEntity->section_uuid = $work["section_id"];
  781. $asusgJob2LaunchEntity->asusg_project_id = 0;
  782. $asusgJob2LaunchEntity->job_order = 0;
  783. $asusgJob2LaunchEntity->time_limit = $dwResult['time_limit'];
  784. $asusgJob2LaunchEntity->outfit = $dwResult['outfit'];
  785. $asusgJob2LaunchEntity->name = $dwResult['work_name'];
  786. $asusgJob2LaunchEntity->section_name = $work["section_lit"];
  787. //$asusgJob2LaunchEntity->asusg_projecttype_id = 0;
  788. $asusgJob2LaunchEntity->asusg_projecttype_id = $projtype;
  789. if (!$asusgJob2LaunchEntity->save()) {
  790. $this->logger->setLog('в Job2launch не добавилась работа => "'. $work['work_name']. '" Добавление работ будет пропущено так как такая запись уже есть.');
  791. continue;
  792. }
  793. $this->logger->setLog('в Job2launch была добавлена работа => "'. $work['work_name'].'"');
  794. $tasktypesEntity = Tasktypes::find()->where(['name' => 'Секция '.$let.', задача','company' => $this->company])->one();
  795. $tasksEntity = new Tasks();
  796. $tasksEntity->parent_id = 0;
  797. $tasksEntity->status = 2;
  798. $tasksEntity->type = $tasktypesEntity->id;
  799. $tasksEntity->assignees_arr = $user->id;
  800. $tasksEntity->created = date("Y-m-d H:i;s");
  801. $tasksEntity->asusg_job_mapped_id = $asusgJob2LaunchEntity->id;
  802. if($tasksEntity->save()) {
  803. $this->testIdpl2 = $tasksEntity->id;
  804. $this->logger->setLog('в Tasks была добавлена ЗАДАЧА => "'. $work['work_name'] . '" id => '.$tasksEntity->id);
  805. } else {
  806. $this->logger->setLog('в Tasks была НЕ добавлена ЗАДАЧА => "'. $work['work_name'] . '" id => '.$tasksEntity->id);
  807. }
  808. //var_dump($tasksEntity->errors,$user->id); echo '<br>';
  809. $countPriority = 1;
  810. ///////////////// ДОБАВЛЕНИЕ ТМЦ
  811. //$mappingapiModel = new \app\models\MappingapiModel();
  812. //var_dump($user->id-uuid,$work['id_work']);
  813. //$tmcString = $mappingapiModel->workDetail($user->uuid,$work['id_work']);
  814. if ( '' != $dwResult['tmcString']) {
  815. $tasksEntity3 = new Tasks();
  816. $tasksEntity3->parent_id = $tasksEntity->id; // +
  817. $tasksEntity3->status = 2; // +
  818. $tasksEntity3->priority = $countPriority; // +
  819. // $tasksEntity2->input_id = $job->asusgJob2Launch->asusg_project_id;
  820. $tasksEntity3->created = date("Y-m-d H:i;s"); // +
  821. $tasksEntity3->type = 2159; // +
  822. $tasksEntity3->assignees_arr = $user->id; // +
  823. $tasksEntity3->asusg_job_mapped_id = $asusgJob2LaunchEntity->id; // +
  824. $tasksEntity3->text = $dwResult['tmcString']; // +
  825. $tasksEntity3->mapping_comment = $dwResult['tmcString']; // +
  826. if ( $tasksEntity3->save()) {
  827. $query3 = "call asusg_add_checkpoints_to_task(" . $user->id . ",'" . $tasksEntity3->id . "')";
  828. $resProc = Yii::$app->db->createCommand($query3)->query();
  829. $logResProc = 'false';
  830. if ($resProc){
  831. $logResProc = 'true';
  832. }
  833. $this->logger->setLog('в Tasks была добавлена КОМАНДА => "'. $work['work_name'] . '" id => '.$tasksEntity3->id. ' процедура => ' . $logResProc);
  834. } else {
  835. $this->logger->setLog('в Tasks была НЕ добавлена КОМАНДА => "'. $work['work_name'] . '" id => '.$tasksEntity3->id);
  836. }
  837. $countPriority++;
  838. }
  839. ///////////////////
  840. $tasksEntity2 = new Tasks();
  841. $tasksEntity2->parent_id = $tasksEntity->id;
  842. $tasksEntity2->status = 2;
  843. $tasksEntity2->priority = $countPriority;
  844. $tasksEntity2->created = date("Y-m-d H:i;s");
  845. $tasksEntity2->type = Yii::$app->params['supercycletype'];
  846. $tasksEntity2->assignees_arr = $user->id;
  847. $tasksEntity2->asusg_job_mapped_id = $asusgJob2LaunchEntity->id;
  848. $tasksEntity2->text = $work["eq_serie"] . ' '.$work["section_lit"] . ', '. $work["outfit"] . ': ' . $work['work_name'];
  849. $tasksEntity2->mapping_comment = $work["outfit"] . ': ' . $work['work_name'];
  850. if ( $tasksEntity2->save()) {
  851. ///////////////////
  852. //$query3 = "call asusg_add_checkpoints_to_task(" . $user->id . ",'" . $tasksEntity2->id . "')";
  853. //$resProc = Yii::$app->db->createCommand($query3)->query();
  854. ///////////////////
  855. $this->logger->setLog('в Tasks была добавлена КОМАНДА => "'. $work['work_name'] . '" id => '.$tasksEntity2->id );
  856. } else {
  857. $this->logger->setLog('в Tasks была НЕ добавлена КОМАНДА => "'. $work['work_name'] . '" id => '.$tasksEntity2->id);
  858. }
  859. $projId = $this->generateProject($work);
  860. $tasksEntity->input_id = $projId;
  861. if ($tasksEntity->save()) {
  862. $this->logger->setLog('привязка ЗАДАЧИ ( id = '.$tasksEntity->id.') прошла успешно');
  863. }
  864. $tasksEntity2->input_id = $projId;
  865. $this->logger->setLog('2 =>' .$asusgJob2LaunchEntity->id);
  866. if($tasksEntity2->save()){
  867. $this->logger->setLog('привязка КОМАНДЫ ( id = '.$tasksEntity2->id.') прошла успешно');
  868. }
  869. $tasksEntity3->input_id = $projId;
  870. if($tasksEntity3->save()){
  871. $this->logger->setLog('привязка КОМАНДЫ ( id = '.$tasksEntity2->id.') прошла успешно');
  872. }
  873. //echo "<pre>";
  874. //var_dump($tasksEntity2->errors,$tasksEntity->errors);
  875. //echo "</pre>";
  876. }
  877. }
  878. public function addJob2launch3($listWorks,$user)
  879. {
  880. foreach ( $listWorks as $work) {
  881. $mappingapiModel = new \app\models\MappingapiModel();
  882. $dwResult = $mappingapiModel->workDetail($user->uuid,$work['id_work']);
  883. $projtype = $this->getProjectType($work["repair_name"],$work["eq_serie"]);
  884. $JobPlanEntitty = AsusgJobplan::find()->where(['name' => $work["work_name"]])->one(); // 1204 1567
  885. $jsusgJob2CommandEntity = AsusgJob2Command::find()->where(['asusg_job_id' => $JobPlanEntitty->id, 'asusg_projecttype_id' => $projtype ])->all();
  886. //echo "<pre>";
  887. //var_dump($JobPlanEntitty->id,$projtype);
  888. //var_dump($JobPlanEntitty->id,$jsusgJob2CommandEntity);
  889. //echo "</pre>";
  890. //continue;
  891. $let = mb_substr($work["section_lit"], -1);
  892. $resultArr = [];
  893. $asusgJob2LaunchEntity = new AsusgJob2Launch();
  894. $asusgJob2LaunchEntity->asusg_jobplan_id = $JobPlanEntitty->id;
  895. $asusgJob2LaunchEntity->asusg_employee_id1 = $user->id;
  896. $asusgJob2LaunchEntity->asusg_job_uuid = $work['id_work'];
  897. $asusgJob2LaunchEntity->employees_uuid = $user->id;
  898. $asusgJob2LaunchEntity->section_uuid = $work["section_id"];
  899. $asusgJob2LaunchEntity->asusg_project_id = 0;
  900. $asusgJob2LaunchEntity->job_order = 0;
  901. $asusgJob2LaunchEntity->asusg_projecttype_id = $projtype;
  902. $asusgJob2LaunchEntity->time_limit = $dwResult['time_limit'];
  903. $asusgJob2LaunchEntity->outfit = $dwResult['outfit'];
  904. $asusgJob2LaunchEntity->name = $dwResult['work_name'];
  905. $asusgJob2LaunchEntity->section_name = $work["section_lit"];
  906. if (!$asusgJob2LaunchEntity->save()) {
  907. $this->logger->setLog('в Job2launch не добавилась работа => "'. $work['work_name']. '" Добавление работ будет пропущено так как такая запись уже есть.');
  908. continue;
  909. }
  910. $this->logger->setLog('в Job2launch была добавлена работа => "'. $work['work_name'].'"');
  911. $tasktypesEntity = Tasktypes::find()->where(['name' => 'Секция '.$let.', задача','company' => $this->company])->one();
  912. $tasksEntity = new Tasks();
  913. $tasksEntity->parent_id = 0;
  914. $tasksEntity->status = 2;
  915. $tasksEntity->type = $tasktypesEntity->id;
  916. $tasksEntity->assignees_arr = $user->id;
  917. $tasksEntity->created = date("Y-m-d H:i;s");
  918. $tasksEntity->asusg_job_mapped_id = $asusgJob2LaunchEntity->id;
  919. if($tasksEntity->save()) {
  920. $this->testIdpl3 = $tasksEntity->id;
  921. $this->logger->setLog('в Tasks была добавлена ЗАДАЧА => "'. $work['work_name'] . '" id => '.$tasksEntity->id);
  922. } else {
  923. $this->logger->setLog('в Tasks была НЕ добавлена ЗАДАЧА => "'. $work['work_name'] . '" id => '.$tasksEntity->id);
  924. }
  925. //var_dump($tasksEntity->errors,$user->id); echo '<br>';
  926. $this->logger->setLog(' колво записей => ' . count($jsusgJob2CommandEntity) . 'type => '. gettype($jsusgJob2CommandEntity));
  927. $this->logger->setLog($JobPlanEntitty->id . ' - ' . $projtype );
  928. $arrJ = [];
  929. $countPriority = 1;
  930. ///////////////// ДОБАВЛЕНИЕ ТМЦ
  931. $mappingapiModel = new \app\models\MappingapiModel();
  932. //var_dump($user->id-uuid,$work['id_work']);
  933. $tmcString = $mappingapiModel->workDetail($user->uuid,$work['id_work']);
  934. if ( '' != $dwResult['tmcString']) {
  935. $tasksEntity2 = new Tasks();
  936. $tasksEntity2->parent_id = $tasksEntity->id; // +
  937. $tasksEntity2->status = 2; // +
  938. $tasksEntity2->priority = $countPriority; // +
  939. // $tasksEntity2->input_id = $job->asusgJob2Launch->asusg_project_id;
  940. $tasksEntity2->created = date("Y-m-d H:i;s"); // +
  941. $tasksEntity2->type = 2159; // +
  942. $tasksEntity2->assignees_arr = $user->id; // +
  943. $tasksEntity2->asusg_job_mapped_id = $asusgJob2LaunchEntity->id;
  944. $tasksEntity2->text = $dwResult['tmcString']; // +
  945. $tasksEntity2->mapping_comment = $dwResult['tmcString']; // +
  946. if ( $tasksEntity2->save()) {
  947. $arrJ[] = $tasksEntity2->id;
  948. $query3 = "call asusg_add_checkpoints_to_task(" . $user->id . ",'" . $tasksEntity2->id . "')";
  949. $resProc = Yii::$app->db->createCommand($query3)->query();
  950. $logResProc = 'false';
  951. if ($resProc){
  952. $logResProc = 'true';
  953. }
  954. $this->logger->setLog('в Tasks была добавлена КОМАНДА => "'. $work['work_name'] . '" id => '.$tasksEntity2->id. ' процедура => ' . $logResProc);
  955. } else {
  956. $this->logger->setLog('в Tasks была НЕ добавлена КОМАНДА => "'. $work['work_name'] . '" id => '.$tasksEntity2->id);
  957. }
  958. $countPriority++;
  959. }
  960. ///////////////////
  961. foreach($jsusgJob2CommandEntity as $job) {
  962. $this->logger->setLog('3 =>'. $job->jobplantie->id);
  963. $tasksEntity2 = new Tasks();
  964. $tasksEntity2->parent_id = $tasksEntity->id;
  965. $tasksEntity2->status = 2;
  966. $tasksEntity2->priority = $countPriority;
  967. // $tasksEntity2->input_id = $job->asusgJob2Launch->asusg_project_id;
  968. $tasksEntity2->created = date("Y-m-d H:i;s");
  969. $tasksEntity2->type = $job->smopp_cmd_id;//Yii::$app->params['supercycletype'];
  970. $tasksEntity2->assignees_arr = $user->id;
  971. $tasksEntity2->asusg_job_mapped_id = $job->jobplantie->id;
  972. $tasksEntity2->text = $work["eq_serie"] . ' '.$work["section_lit"] . ', '. $work["outfit"] . ':' . $work['work_name'];
  973. $tasksEntity2->mapping_comment = $work["outfit"] . ': ' . $work['work_name'];
  974. if ( $tasksEntity2->save()) {
  975. $arrJ[] = $tasksEntity2->id;
  976. ///////////////////
  977. //$query3 = "call asusg_add_checkpoints_to_task(" . $user->id . ",'" . $tasksEntity2->id . "')";
  978. //$resProc = Yii::$app->db->createCommand($query3)->query();
  979. ///////////////////
  980. $this->logger->setLog('в Tasks была добавлена КОМАНДА => "'. $work['work_name'] . '" id => '.$tasksEntity2->id);
  981. } else {
  982. $this->logger->setLog('в Tasks была НЕ добавлена КОМАНДА => "'. $work['work_name'] . '" id => '.$tasksEntity2->id);
  983. }
  984. $countPriority++;
  985. }
  986. $projId = $this->generateProject3($work);
  987. $tasksEntity->input_id = $projId;
  988. if ($tasksEntity->save()) {
  989. $this->logger->setLog('привязка ЗАДАЧИ ( id = '.$tasksEntity->id.') прошла успешно');
  990. }
  991. foreach($arrJ as $job_id) {
  992. $tasksEnt = Tasks::findOne($job_id);
  993. $tasksEnt->input_id = $projId;
  994. if($tasksEnt->save()){
  995. $this->logger->setLog('привязка КОМАНДЫ ( id = '.$tasksEntity2->id.') прошла успешно');
  996. }
  997. }
  998. //$tasksEntity2->input_id = $projId;
  999. //if($tasksEntity2->save()){
  1000. // $this->logger->setLog('привязка КОМАНДЫ ( id = '.$tasksEntity2->id.') прошла успешно');
  1001. //}
  1002. echo "<pre>";
  1003. //var_dump($job->asusgJob2Launch->asusg_project_id);
  1004. var_dump($tasksEntity2->errors,$tasksEntity->errors);
  1005. echo "</pre>";
  1006. }
  1007. }
  1008. public function pushProject($minRes)
  1009. {
  1010. //var_dump(count($minRes));
  1011. //var_dump($minRes);
  1012. foreach ( $minRes as $proj) {
  1013. $arr = ['initiator' => (int)$proj['userInfo']->id, 'project_id' => (int)$proj['asusgProject_id']];
  1014. //$res = \Yii::$app->db->createCommand('call asusg_build_and_start_project('.$arr["initiator"].','.$arr["project_id"].')')->execute();
  1015. $res = \Yii::$app->db->createCommand('call asusg_build_and_start_project_auto('.$arr["initiator"].','.$arr["project_id"].')')->execute();
  1016. echo "<pre>";
  1017. var_dump($arr);
  1018. var_dump("Выполнение процедуры => " . $res);
  1019. echo "</pre>";
  1020. }
  1021. }
  1022. public function prepareParams($listWorks)
  1023. {
  1024. $result = [];
  1025. foreach ( $listWorks as $work) {
  1026. $work['user_id'] = '0f9ed850-e473-11e2-aaad-ac162db0b20c';
  1027. $result[] = $work;
  1028. $result = json_encode($result);
  1029. return $result;//json_decode($result,false);
  1030. }
  1031. //$result = count();
  1032. }
  1033. public function generateProject($work){
  1034. $result = '';
  1035. $let = mb_substr($work["section_lit"], -1);
  1036. $sectionsEntity = Sections::find()->select(['id', 'diagnostic_map'])
  1037. ->where(['locomotive_series' => $work["eq_serie"],'section_number' => mb_substr($work['section_lit'],0,-1),'letter' => $let])
  1038. ->one();
  1039. $diagnostic_map = $sectionsEntity->diagnostic_map;
  1040. if ( null == $sectionsEntity->id) {
  1041. $sectionsEntity = new Sections();
  1042. $sectionsEntity->locomotive_series = $work["eq_serie"];
  1043. $sectionsEntity->section_number = mb_substr($work['section_lit'],0,-1);
  1044. $sectionsEntity->section_subnumber = $work["section_num"];
  1045. $sectionsEntity->diagnostic_map = $work["section_DK"];
  1046. $sectionsEntity->uuid = $work["section_id"];
  1047. $sectionsEntity->letter = $let;
  1048. if ( $sectionsEntity->save()) {
  1049. $this->logger->setLog('в Sections была добавлена новая секция => '. $work["section_num"] . ' id => '.$sectionsEntity->id);
  1050. } else {
  1051. $this->logger->setLog('в Sections при добавлении секции произошли ошибки => '. count($sectionsEntity->errors) . ' шт.');
  1052. }
  1053. $diagnostic_map = $sectionsEntity->diagnostic_map;
  1054. }
  1055. else if( null == $sectionsEntity->diagnostic_map ) {
  1056. $sectionsEntity->diagnostic_map = $work['section_DK'];
  1057. $sectionsEntity->save();
  1058. }
  1059. if ($sectionsEntity->diagnostic_map == $work['section_DK'] ) {
  1060. $query = "select pl.id from projects_locotech pl
  1061. inner join tasks t on pl.id = t.input_id
  1062. left join tasktypes tt on t.type = tt.id
  1063. where pl.company = " . $this->company . "
  1064. and pl.loco_type = '" . $work["eq_serie"] . "'
  1065. and pl.loco_number = " . $work["eq_number"] . "
  1066. and t.parent_id = 0
  1067. and tt.letter like '%" . $let . "%'
  1068. and pl.uuid like '%" . $work['repair_name']. ",%'
  1069. order by pl.id desc
  1070. limit 1";
  1071. $projectId = Yii::$app->db->createCommand($query)->queryOne();
  1072. $result = $projectId['id'];
  1073. $this->logger->setLog('в Sections секция с такой диагностической картой => '. $work['section_DK'] . ' существует. Ид проекта '. $result);
  1074. }
  1075. if (!$result) {
  1076. $projectsLocotech = new ProjectsLocotech();
  1077. $projectsLocotech->action = 197 ;
  1078. $projectsLocotech->company = $this->company;
  1079. $projectsLocotech->status = 2;
  1080. $projectsLocotech->loco_type = $work["eq_serie"];
  1081. $projectsLocotech->loco_number = $work["eq_number"];
  1082. $projectsLocotech->depo ='' ;
  1083. $projectsLocotech->depo_service = '';
  1084. $projectsLocotech->created = date('Y-m-d H:i:s');
  1085. $projectsLocotech->urgent = 0;
  1086. $projectsLocotech->uuid = $work['work_name'].":".$work['repair_name'].",".$work["eq_serie"];
  1087. $projectsLocotech->tasks = $this->testIdpl2;
  1088. $projectsLocotech->save();
  1089. $result = $projectsLocotech->id;
  1090. var_dump($this->testIdpl2);
  1091. $this->logger->setLog('Такого проекта еще не было пришлось создать. Ид проекта => '. $result);
  1092. }
  1093. return $result;
  1094. }
  1095. public function generateProject3($work){
  1096. $result = '';
  1097. $projectsLocotech = new ProjectsLocotech();
  1098. $projectsLocotech->action = 197 ;
  1099. $projectsLocotech->company = $this->company;
  1100. $projectsLocotech->status = 2;
  1101. $projectsLocotech->loco_type = $work["eq_serie"];
  1102. $projectsLocotech->loco_number = $work["eq_number"];
  1103. $projectsLocotech->depo ='' ;
  1104. $projectsLocotech->depo_service = '';
  1105. $projectsLocotech->created = date('Y-m-d H:i:s');
  1106. $projectsLocotech->urgent = 0;
  1107. $projectsLocotech->uuid = $work['work_name'].":".$work['repair_name'].",".$work["eq_serie"];
  1108. $projectsLocotech->tasks = $this->testIdpl3;
  1109. $projectsLocotech->save();
  1110. var_dump($this->testIdpl3);
  1111. $result = $projectsLocotech->id;
  1112. $this->logger->setLog('Такого проекта еще не было пришлось создать. Ид проекта => '. $result);
  1113. //var_dump($result);
  1114. return $result;
  1115. }
  1116. private function prepareListWorks($listWorks) {
  1117. $result = [];
  1118. $dataArr = [];
  1119. if ( null == $listWorks || empty($listWorks)) {
  1120. return [];
  1121. }
  1122. var_dump();
  1123. foreach ( $listWorks["rows"] as $rows) {
  1124. $rows["result"] = json_decode($rows["result"],true);
  1125. foreach ( $rows["result"]['data'] as $key => $data) {
  1126. //echo '<pre>';
  1127. // var_dump($data);
  1128. // echo '</pre>';
  1129. $tempArray = [];
  1130. $tempArray["eq_serie"] = explode(" ",$data["equip_sect_name"])[0];
  1131. $eq = explode(" ",$data["equip_sect_name"])[1];
  1132. $tempArray["eq_number"] = explode("/",$eq)[0];
  1133. //echo '<pre>';
  1134. //var_dump($tempArray["eq_number"]);
  1135. //echo '</pre>';
  1136. foreach ( $data["sections"] as $sections) {
  1137. $tempArray["section_id"] = $sections["id_section"];
  1138. $tempArray["section_lit"] = $sections["section_name"];
  1139. //$this->getLocoInfoMore($sections["section_subnumber"]);
  1140. $tempArray["section_num"] = $sections["section_subnumber"];
  1141. $tempArray["section_DK"] = $sections["section_dk"];
  1142. // echo '<pre>';
  1143. // var_dump($sections);
  1144. // echo '</pre>';
  1145. foreach ( $sections['works'] as $work) {
  1146. $tempArray["id_work"] = $work["id_work"];
  1147. $tempArray["outfit"] = $work["outfit"];
  1148. $tempArray["work_name"] = $work["work_name"];
  1149. $tempArray["repair_name"] = $work["repair_type"];
  1150. $tempArray["work_status"] = $work["work_status"];
  1151. $tempArray["repeats"] = $work["repeats"];
  1152. //$extraSection = $this->getSectionInfo( $tempArray["section_id"], $tempArray["repair_name"]);
  1153. //$tempArray["section_num"] = $extraSection['section_num'];
  1154. //$tempArray['section_DK'] = $extraSection['section_DK'];
  1155. $dataArr[] = $tempArray;
  1156. foreach ( $works['workers'] as $worker) {
  1157. //echo '<pre>';
  1158. //var_dump($worker);
  1159. //echo '</pre>';
  1160. }
  1161. }
  1162. }
  1163. }
  1164. $result['result'] = 'true';
  1165. $result['data'] = $dataArr;
  1166. break;
  1167. }
  1168. return $result;
  1169. }
  1170. }