MappingapiModel.php 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528
  1. <?php
  2. namespace app\models;
  3. use Yii;
  4. use app\models\entity\Tasks;
  5. use app\models\logger\LoggerFile;
  6. use app\models\entity\Checkpoints;
  7. use app\models\entity\AsusgJob2Launch;
  8. use app\models\entity\AsusgMeasurements;
  9. use app\models\procedure\AsusgAddMeasurementToTaskModel;
  10. class MappingapiModel extends MainModel
  11. {
  12. private static $_instance;
  13. private $url = '/Thingworx/Things/2050UserLibraryExp/Services/';
  14. private $GWparams = ['login' => 'ПройдаковИА','pass' => 'Ip15351112'];
  15. private $responseEippMeasurement = '';
  16. public $prepareLogString = '';
  17. function __construct()
  18. {
  19. $log = new LoggerFile();
  20. $this->logger = new MappingHandlerModel($log);
  21. }
  22. //public function workDetail($params) {
  23. public function workDetail($user_id, $work_id)
  24. {
  25. $this->GWparams = [
  26. 'url' => Yii::$app->params['api']['domain'] . $this->url . 'work_detail',
  27. //'param' => ['user_id' => $params['user_id'], 'work_id' => $params['work_id']],
  28. 'param' => ['user_id' => $user_id, 'id_work' => $work_id],
  29. ];
  30. //var_dump($this->GWparams['url'],$user_id,$work_id);
  31. ElasticLog::eipp($this->GWparams, $work_id, $user_id);
  32. $response = $this->curlRequestUni($this->GWparams,'post');
  33. $work = json_decode($response,true);
  34. ElasticLog::eipp($response, $work_id, $user_id, false);
  35. //var_dump($work);
  36. $time = time();
  37. LogEippResponse::addLog($time ."wd".$work_id,json_encode($work),'Детализация по работе, ответ ЕИПП');
  38. $this->logger->setLog("\nДЕТАЛИЗАЦИЯ НАЧАЛО =====>\n");
  39. $this->logger->setLog("Параметры: \n user_id => ".$user_id.",\n id_work => ".$work_id.".\n");
  40. $this->logger->setLog("Строка запроса : \n ".$this->GWparams['url'] .".\n");
  41. $this->logger->setLog("Вот тут можно посмотреть что ЕИПП прислал по запросу детализации http://dev.prmsys.net/api/mappinghandler/eippresponse?indx=".$time ."wd".$work_id."\n");
  42. $this->logger->setLog("ДЕТАЛИЗАЦИЯ КОНЕЦ =====>\n\n");
  43. return $this->getTmcList($work);
  44. }
  45. // для функции TasksCancel в server.php
  46. //
  47. public function setPause($accid, $maintask) {
  48. $params = [];
  49. $this->logger->setLog('setPause =>accid' . $accid . ' maintask =>' . $maintask);
  50. // завершаю задачу
  51. $taskEntity2 = Tasks::findOne($maintask);
  52. $launch = $taskEntity2->asusg_job_mapped_id;
  53. if ( null == $launch and null == $taskEntity2->accounts->uuid){
  54. return true;
  55. }
  56. $taskEntity2->status = 5;
  57. //var_dump($maintask);
  58. try {
  59. $taskEntity2->save();
  60. } catch (\yii\db\Exception $e) {
  61. echo 'Поймано исключение: ', $e->getMessage(), "\n";
  62. }
  63. //
  64. $asusgJob2LaunchEntity = AsusgJob2Launch::findOne($launch);
  65. $asusgJob2LaunchEntity->asusg_job_uuid = $asusgJob2LaunchEntity->asusg_job_uuid . ' Отмена';
  66. //var_dump($launch);
  67. try {
  68. $asusgJob2LaunchEntity->save();
  69. } catch (\yii\db\Exception $e) {
  70. echo 'Поймано исключение: ', $e->getMessage(), "\n";
  71. }
  72. $this->logger->setLog('setPause =>id_ launch' . $launch . ' work=>' . $asusgJob2LaunchEntity->id);
  73. // завершаю все команды
  74. Tasks::updateAll(['status' => 5],['parent_id' => $maintask]);
  75. // запрос к еипп
  76. $work_uuid = $taskEntity2->asusgjob2launch->asusg_job_uuid;
  77. $user_uuid = $taskEntity2->accounts->uuid;
  78. $params['user_id'] = $user_uuid;
  79. $params['id_work'] = $work_uuid;
  80. $params['id_reason'] = "прочее";
  81. $params['comment'] = "прочее";
  82. if ( null != $work_uuid) {
  83. $this->setPauseRequest($params);
  84. }
  85. return $params;
  86. }
  87. public static function workMeasurements($id_work, $id_user,$eipp_resp = ''){
  88. //require_once $_SERVER["DOCUMENT_ROOT"].'/measurements.php';
  89. self::$_instance = new self();
  90. $time = time();
  91. $params['user_id'] = $id_user;
  92. $params['work_id'] = $id_work['id_work'];
  93. self::$_instance->GWparams = ['url' => Yii::$app->params['api']['domain'] . self::$_instance->url . 'work_measurements',
  94. 'param' => $params,
  95. ];
  96. self::$_instance->responseEippMeasurement = $eipp_resp;
  97. if ( '' == self::$_instance->responseEippMeasurement ) {
  98. ElasticLog::eipp(self::$_instance->GWparams, $params['work_id'], $params['user_id']);
  99. self::$_instance->responseEippMeasurement = self::$_instance->curlRequestUni(self::$_instance->GWparams,'post');
  100. ElasticLog::eipp(self::$_instance->responseEippMeasurement, $params['work_id'], $params['user_id'], false);
  101. LogEippResponse::addLog($time."/".$id_work['id_work'],self::$_instance->responseEippMeasurement,'Ответ от ЕИПП по замерам, уровень: ' . Yii::$app->params['api']['mesrmntParam']['stage']);
  102. }
  103. //self::$_instance->logger->setLog('ResponseToMeasurement =>user' . $id_user . ' work=>' . $id_work);
  104. self::$_instance->logger->setLog( "\n ЗАМЕРЫ НАЧАЛО =====>");
  105. self::$_instance->logger->setLog( "Параметры: \n user_id =>".$id_user.",\n work_id => ".$id_work['id_work'].".");
  106. self::$_instance->logger->setLog( "Строка запроса : \n ".self::$_instance->GWparams['url'] .".");
  107. self::$_instance->logger->setLog( "Вот тут можно посмотреть что ЕИПП прислал по запросу замеров http://dev.prmsys.net/api/mappinghandler/eippresponse?indx=".$time."/".$id_work);
  108. self::$_instance->logger->setLog( " ЗАМЕРЫ КОНЕЦ =====>\n");
  109. self::$_instance->ResponseToMeasurement();
  110. return self::$_instance->responseEippMeasurement;
  111. }
  112. public static function workDeviceMeasurements($work, $id_user){
  113. //require_once $_SERVER["DOCUMENT_ROOT"].'/measurements.php';
  114. self::$_instance = new self();
  115. $time = time();
  116. $params['user_id'] = $id_user;
  117. $params['work_id'] = $id_work['id_work'];
  118. $params['measurement_stage'] = Yii::$app->params['api']['mesrmntParam']['stage'];
  119. $params['section_position_number'] = mb_substr($id_work['section_lit'], -1);
  120. self::$_instance->GWparams = ['url' => Yii::$app->params['api']['domain'] . self::$_instance->url . 'task_for_hw_measurements',
  121. 'param' => $params,
  122. ];
  123. self::$_instance->responseEippMeasurement = $eipp_resp;
  124. if ( '' == self::$_instance->responseEippMeasurement ) {
  125. $reusltEipp = self::$_instance->curlRequestUni(self::$_instance->GWparams,'post');
  126. LogEippResponse::addLog($time."/".$id_work,self::$_instance->responseEippMeasurement,'Ответ от ЕИПП по замерам, уровень: ' . Yii::$app->params['api']['mesrmntParam']['stage']);
  127. }
  128. $reusltEipp = json_decode( $reusltEipp, true );
  129. //var_dump($reusltEipp['data']['task_id']);
  130. return $reusltEipp['data']['task_id'];;
  131. }
  132. public static function updateMeasurements($id_work){
  133. //require_once $_SERVER["DOCUMENT_ROOT"].'/measurements.php';
  134. //exit;
  135. self::$_instance = new self();
  136. $time = time();
  137. $tasksEntity = Tasks::findOne($id_work);
  138. $params['user_id'] = $tasksEntity->accounts->uuid;
  139. $params['work_id'] = $tasksEntity->asusgjob2launch->asusg_job_uuid;
  140. Yii::$app->params['api']['mesrmntParam']['stage'] = $tasksEntity->measurementone->measurement_stage;
  141. self::$_instance->GWparams = ['url' => Yii::$app->params['api']['domain'] . self::$_instance->url . 'work_measurements',
  142. 'param' => $params,
  143. ];
  144. // self::$_instance->responseEippMeasurement = $eipp_resp;
  145. if ( '' == self::$_instance->responseEippMeasurement ) {
  146. self::$_instance->responseEippMeasurement = self::$_instance->curlRequestUni(self::$_instance->GWparams,'post');
  147. LogEippResponse::addLog($time."/".$id_work['id_work'],self::$_instance->responseEippMeasurement,'Ответ от ЕИПП по замерам, уровень: ' . Yii::$app->params['api']['mesrmntParam']['stage']);
  148. }
  149. //self::$_instance->logger->setLog( "\n ЗАМЕРЫ НАЧАЛО =====>");
  150. //self::$_instance->logger->setLog( "Параметры: \n user_id =>".$id_user.",\n work_id => ".$id_work['id_work'].".");
  151. //self::$_instance->logger->setLog( "Строка запроса : \n ".self::$_instance->GWparams['url'] .".");
  152. //self::$_instance->logger->setLog( "Вот тут можно посмотреть что ЕИПП прислал по запросу замеров http://dev.prmsys.net/api/mappinghandler/eippresponse?indx=".$time."/".$id_work);
  153. //self::$_instance->logger->setLog( " ЗАМЕРЫ КОНЕЦ =====>\n");
  154. self::$_instance->UpdateToMeasurement($id_work);
  155. //return self::$_instance->responseEippMeasurement;
  156. }
  157. private function getTmcList($work) {
  158. $result = [];
  159. $tenpArray = [];
  160. $count = 1;
  161. foreach($work['rows'] as $tmc1) {
  162. // echo "<pre>";
  163. //if ( $key == "cam_list") {
  164. //$tenpArray[] = $tmc4["tmc_name"];
  165. //var_dump($tmc1);
  166. //}
  167. foreach($tmc1 as $tmc2) {
  168. $tmc2 = json_decode($tmc2,true);
  169. foreach($tmc2['data'] as $key => $tmc3) {
  170. //echo "</pre>";
  171. $result[$key] = $tmc3;
  172. foreach($tmc3 as $tmc4) {
  173. if ( '' != $tmc4["tmc_name"]) {
  174. $tenpArray[] = $tmc4["tmc_name"];
  175. }
  176. }
  177. if ( 'workers' == $key) {
  178. $result['workers'] = [];
  179. foreach($tmc3 as $key => $tmc5) {
  180. $result['workers'][] = $tmc5['fio'];
  181. $result['workers_uuid'][] = $tmc5['id'];
  182. }
  183. }
  184. if ( 'measurements' == $key) {
  185. $result['measurements'] = $this->CheckmeasurementField($tmc3);
  186. }
  187. }
  188. }
  189. }
  190. $result['tmcString'] = '';
  191. if ( !empty($tenpArray) ) {
  192. $result['tmcString'] = implode("\n * ", $tenpArray);
  193. $result['tmcString'] = "* " . $result['tmcString'];
  194. }
  195. $result['workers'] = 'Назначены: ' . implode(', ',$result['workers']);
  196. //echo "<pre>";
  197. //var_dump($result);
  198. //echo "</pre>";
  199. return $result;
  200. }
  201. private function setPauseRequest($params) {
  202. if ( !$params ) {
  203. return false;
  204. }
  205. $this->GWparams = ['url' => Yii::$app->params['api']['domain'] . $this->url . 'work_pause',
  206. 'param' => $params,
  207. ];
  208. $mainModel = new MainModel();
  209. $listWorks = json_decode($mainModel->curlRequestUni($this->GWparams,'post'));
  210. LogEippResponse::addLog($time."/".$maintask . "sp", $listWorks ,'Ответ от ЕИПП установка паузы' );
  211. // тут ответ от еипп $listWorks параметры запроса $this->GWparams
  212. return true;
  213. }
  214. private function ResponseToMeasurement() {
  215. $json = json_decode($this->responseEippMeasurement);
  216. $counter = 0;
  217. foreach ($json->data as $item) {
  218. if ( intval($item->measurement_stage) != Yii::$app->params['api']['mesrmntParam']['stage']) {
  219. continue;
  220. }
  221. $counter++;
  222. }
  223. $this->logger->setLog('Количество замеров =>'. $counter);
  224. if ( 0 == $counter) {
  225. return true;
  226. }
  227. // 1. В первую очередь создается команда
  228. Yii::$app->params['api']['mesrmntParam']['type'] = Yii::$app->params['api']['mesrmntTaskType'];
  229. Yii::$app->params['api']['mesrmntParam']['measurement_name'] = 'Выполнить замер: ' . Yii::$app->params['api']['mesrmntParam']['stage_type'];
  230. $mappingHandlerModel = new MappingHandlerModel($this->logger);
  231. $res = $mappingHandlerModel->addNewTask();
  232. $this->logger->setLog("в Tasks была добавлена КОМАНДА( ЗАМЕРЫ ) =>". $res['tasksEntity']->id . " \n приоритет =>" . (Yii::$app->params['countPriority']-1) ."\n
  233. статус => ". $res['tasksEntity']->status . "\n сотрудник => " . $res['tasksEntity']->assignees_arr);
  234. // 2.Далее записываю замеры
  235. foreach ($json->data as $item) {
  236. if ( intval($item->measurement_stage) != Yii::$app->params['api']['mesrmntParam']['stage']) {
  237. continue;
  238. }
  239. $AsusgMeasurementsEntity = new AsusgMeasurements();
  240. $AsusgMeasurementsEntity->measurement_id = $item->measurement_id;
  241. $AsusgMeasurementsEntity->measurement_name = $item->measurement_name;
  242. $AsusgMeasurementsEntity->characteristic_id = $item->characteristic_id;
  243. $AsusgMeasurementsEntity->characteristic_name = $item->characteristic_name;
  244. $AsusgMeasurementsEntity->measurement_stage = intval($item->measurement_stage);
  245. $AsusgMeasurementsEntity->measurement_complete = intval($item->measurement_complete);
  246. $AsusgMeasurementsEntity->measurement_norm = $item->measurement_norm;
  247. $AsusgMeasurementsEntity->measurement_value = floatval($item->measurement_value);
  248. $AsusgMeasurementsEntity->value_type = $item->value_type;
  249. $AsusgMeasurementsEntity->value_compliance = intval($item->value_compliance);
  250. $AsusgMeasurementsEntity->worker = json_encode($item->worker);
  251. $AsusgMeasurementsEntity->measurement_date = $item->measurement_date;
  252. $AsusgMeasurementsEntity->measurement_comment = json_encode($item->measurement_comment);
  253. $AsusgMeasurementsEntity->work_id = $item->work_id;
  254. $AsusgMeasurementsEntity->is_hw_measurement = intval($item->is_hw_measurement);
  255. $AsusgMeasurementsEntity->smopp_date_requested = date('Y-m-d H:i:s');
  256. $AsusgMeasurementsEntity->smopp_task_id = $res['tasksEntity']->id;//Yii::$app->params['api']['mesrmntParam']['parent_id'];
  257. $check = 'ручной';
  258. if ( intval($item->is_hw_measurement)) {
  259. $check = 'аппаратный';
  260. }
  261. //Yii::$app->params['api']['mesrmntParam']['measurement_name'] = "Замер " . $check. ' ' . Yii::$app->params['api']['mesrmntParam']['stage_type'] ." " . $item->characteristic_name ." - " . $item->measurement_name;
  262. $msrmnt_name = $item->characteristic_name ." - " . $item->measurement_name .". \n Норма: " . $item->measurement_norm;
  263. $this->logger->setLog("Сохранение в таблицу замеров. smopp_task_id =>".$AsusgMeasurementsEntity->smopp_task_id."\n");
  264. $AsusgMeasurementsEntity->save();
  265. try {
  266. if( is_bool($item->measurement_value) === true and 'Отметка о выполнении' == $item->measurement_name) {
  267. // Вот тут дожна вызываться процедура
  268. $query = "call asusg_add_finish_mark_to_task(" . Yii::$app->params['api']['mesrmntParam']['assignees_arr'] . ",'" . $res['tasksEntity']->id . "', " . $AsusgMeasurementsEntity->id . ", '" . $msrmnt_name . "' )";
  269. } else {
  270. // Вот тут дожна вызываться процедура
  271. //$query = "call asusg_add_measurement_to_task(" . Yii::$app->params['api']['mesrmntParam']['assignees_arr'] . ",'" . $res['tasksEntity']->id . "', " . $AsusgMeasurementsEntity->id . ", '" . $msrmnt_name . "' )";
  272. $AAMsrTT = new AsusgAddMeasurementToTaskModel();
  273. $AAMsrTT->execute( $res['tasksEntity']->id,$AsusgMeasurementsEntity->id, $msrmnt_name, $item->measurement_value, false);
  274. $query = 'exec AsusgAddMeasurementToTaskModel, params (' . $res['tasksEntity']->id.','.$AsusgMeasurementsEntity->id.','. $msrmnt_name.','. $item->measurement_value .', false)';
  275. }
  276. // Вот это вместо процедуры
  277. // 3 .Далее создание контрольных карт
  278. //$classNew = new AsusgAddMeasurementToTaskModel();
  279. //$classNew->execute( $res['tasksEntity']->id , $AsusgMeasurementsEntity->id , $msrmnt_name , $extraCheckpoint );
  280. $resProc = Yii::$app->db->createCommand($query)->execute();
  281. $this->logger->setLog($query);
  282. $this->logger->setLog('ГЕНЕРАЦИЯ ЧЕКПОИТОВ =>'. $resProc);
  283. //var_dump("Создание кк =>", $resProc);
  284. //$logs->error_text = "Создание кк =>". $resProc;
  285. //$logs->section = 4;
  286. // $logs->save();
  287. //echo "<br>";
  288. } catch (\yii\db\Exception $e) {
  289. //$logs->error_text = "Создание замера => повторное создание.";
  290. //$logs->section = 5;
  291. //$logs->save();
  292. //var_dump("Создание кк => Ошибка");
  293. //echo "<br>";
  294. //echo "====================================";
  295. //var_dump('Название замера:' .$item->measurement_name. ' - НЕ ДОБАВИЛОСЬ' ); echo "<br><br>";
  296. //var_dump($query);
  297. //echo "====================================";
  298. //$res['tasksEntity']->delete();
  299. //echo $res['tasksEntity']->id ." => fall \n" ;
  300. }
  301. }
  302. }
  303. private function ResponseToMeasurement2() {
  304. $json = json_decode($this->responseEippMeasurement);
  305. $counter = 0;
  306. foreach ($json->data as $item) {
  307. if ( intval($item->measurement_stage) != Yii::$app->params['api']['mesrmntParam']['stage']) {
  308. continue;
  309. }
  310. $counter++;
  311. }
  312. $this->logger->setLog('Количество замеров =>'. $counter);
  313. if ( 0 == $counter) {
  314. return true;
  315. }
  316. // 1. В первую очередь создается команда
  317. Yii::$app->params['api']['mesrmntParam']['type'] = Yii::$app->params['api']['mesrmntTaskType'];
  318. Yii::$app->params['api']['mesrmntParam']['measurement_name'] = 'Выполнить замер: ' . Yii::$app->params['api']['mesrmntParam']['stage_type'];
  319. $mappingHandlerModel = new MappingHandlerModel($this->logger);
  320. $res = $mappingHandlerModel->addNewTask();
  321. $this->logger->setLog("в Tasks была добавлена КОМАНДА( ЗАМЕРЫ ) =>". $res['tasksEntity']->id . " \n приоритет =>" . (Yii::$app->params['countPriority']-1) ."\n
  322. статус => ". $res['tasksEntity']->status . "\n сотрудник => " . $res['tasksEntity']->assignees_arr);
  323. // 2.Далее записываю замеры
  324. foreach ($json->data as $item) {
  325. if ( intval($item->measurement_stage) != Yii::$app->params['api']['mesrmntParam']['stage']) {
  326. continue;
  327. }
  328. $AsusgMeasurementsEntity = new AsusgMeasurements();
  329. $AsusgMeasurementsEntity->measurement_id = $item->measurement_id;
  330. $AsusgMeasurementsEntity->measurement_name = $item->measurement_name;
  331. $AsusgMeasurementsEntity->characteristic_id = $item->characteristic_id;
  332. $AsusgMeasurementsEntity->characteristic_name = $item->characteristic_name;
  333. $AsusgMeasurementsEntity->measurement_stage = intval($item->measurement_stage);
  334. $AsusgMeasurementsEntity->measurement_complete = intval($item->measurement_complete);
  335. $AsusgMeasurementsEntity->measurement_norm = $item->measurement_norm;
  336. $AsusgMeasurementsEntity->measurement_value = floatval($item->measurement_value);
  337. $AsusgMeasurementsEntity->value_type = $item->value_type;
  338. $AsusgMeasurementsEntity->value_compliance = intval($item->value_compliance);
  339. $AsusgMeasurementsEntity->worker = json_encode($item->worker);
  340. $AsusgMeasurementsEntity->measurement_date = $item->measurement_date;
  341. $AsusgMeasurementsEntity->measurement_comment = json_encode($item->measurement_comment);
  342. $AsusgMeasurementsEntity->work_id = $item->work_id;
  343. $AsusgMeasurementsEntity->is_hw_measurement = intval($item->is_hw_measurement);
  344. $AsusgMeasurementsEntity->smopp_date_requested = date('Y-m-d H:i:s');
  345. $AsusgMeasurementsEntity->smopp_task_id = $res['tasksEntity']->id;//Yii::$app->params['api']['mesrmntParam']['parent_id'];
  346. $check = 'ручной';
  347. if ( intval($item->is_hw_measurement)) {
  348. $check = 'аппаратный';
  349. }
  350. //Yii::$app->params['api']['mesrmntParam']['measurement_name'] = "Замер " . $check. ' ' . Yii::$app->params['api']['mesrmntParam']['stage_type'] ." " . $item->characteristic_name ." - " . $item->measurement_name;
  351. $msrmnt_name = $item->characteristic_name ." - " . $item->measurement_name .". \n Норма: " . $item->measurement_norm;
  352. $this->logger->setLog("Сохранение в таблицу замеров. smopp_task_id =>".$AsusgMeasurementsEntity->smopp_task_id."\n");
  353. $AsusgMeasurementsEntity->save();
  354. try {
  355. // 3 .Далее создание контрольных карт
  356. if( is_bool($item->measurement_value) === true and 'Отметка о выполнении' == $item->measurement_name) {
  357. // Вот тут дожна вызываться процедура
  358. $query = "call asusg_add_finish_mark_to_task(" . Yii::$app->params['api']['mesrmntParam']['assignees_arr'] . ",'" . $res['tasksEntity']->id . "', " . $AsusgMeasurementsEntity->id . ", '" . $msrmnt_name . "' )";
  359. } else {
  360. // Вот тут дожна вызываться процедура
  361. //$query = "call asusg_add_measurement_to_task(" . Yii::$app->params['api']['mesrmntParam']['assignees_arr'] . ",'" . $res['tasksEntity']->id . "', " . $AsusgMeasurementsEntity->id . ", '" . $msrmnt_name . "' )";
  362. $AAMsrTT = new AsusgAddMeasurementToTaskModel();
  363. $AAMsrTT->execute( $res['tasksEntity']->id,$AsusgMeasurementsEntity->id, $msrmnt_name, $item->measurement_value, false);
  364. $query = '';
  365. }
  366. $resProc = Yii::$app->db->createCommand($query)->execute();
  367. $this->logger->setLog('query => '.$query);
  368. $this->logger->setLog('ГЕНЕРАЦИЯ ЧЕКПОИТОВ =>'. $resProc);
  369. } catch (\yii\db\Exception $e) {
  370. //$logs->error_text = "Создание замера => повторное создание.";
  371. }
  372. }
  373. }
  374. private function UpdateToMeasurement($id_work) {
  375. $json = json_decode($this->responseEippMeasurement);
  376. $counter = 0;
  377. foreach ($json->data as $item) {
  378. if ( (intval($item->measurement_stage) != Yii::$app->params['api']['mesrmntParam']['stage'])
  379. || ( null ==$item->measurement_value)
  380. || ( '' == $item->measurement_value) ) {
  381. continue;
  382. }
  383. $asusgMeasurementsEntity = AsusgMeasurements::findOne(['measurement_id' => $item->measurement_id , 'smopp_task_id' => $id_work ]);
  384. $asusgMeasurementsEntity->measurement_value = $item->measurement_value;
  385. $asusgMeasurementsEntity->worker = $item->worker;
  386. $asusgMeasurementsEntity->comment = $item->comment;
  387. $asusgMeasurementsEntity->value_compliance = $item->value_compliance;
  388. $asusgMeasurementsEntity->measurement_complete = $item->measurement_complete;
  389. $asusgMeasurementsEntity->measurement_date = $item->measurement_date;
  390. $asusgMeasurementsEntity->is_hw_measurement = $item->is_hw_measurement;
  391. $asusgMeasurementsEntity->smopp_date_requested = date('Y-m-d H:i:s');
  392. if ( !$asusgMeasurementsEntity->save() ) {
  393. return false;
  394. }
  395. $checkpointsEntity = Checkpoints::findAll(['measurement_id' => $asusgMeasurementsEntity->id]);
  396. if ( 1 == count($checkpointsEntity)) {
  397. foreach( $checkpointsEntity as $checkpoints) {
  398. $checkpoints->value = $item->measurement_value;
  399. $checkpoints->is_set = 1;
  400. $checkpoints->save();
  401. break;
  402. }
  403. } else {
  404. foreach( $checkpointsEntity as $checkpoints) {
  405. if ( 820 == $checkpoints->type and 1 == $item->measurement_value) {
  406. $checkpoints->is_set = $item->measurement_value;
  407. $checkpoints->save();
  408. break;
  409. }
  410. }
  411. }
  412. //var_dump( $asusgMeasurementsEntity->errors); echo '<br>';
  413. //var_dump( 'Good update =>'. $item->measurement_id, 'cur =>' . $asusgMeasurementsEntity->measurement_value . ' set =>'.$item->measurement_value); echo '<br>';
  414. }
  415. return true;
  416. }
  417. private function CheckmeasurementField($msrm) {
  418. $msrmArr = explode('/', $msrm );
  419. if ( (count($msrmArr) > 1) && ($msrmArr[0] == $msrmArr[1]) ) {
  420. return false; // если $msrm = 25/25/0 и (25==25) то можно не запрашивать замеры
  421. }
  422. return true; // если $msrm = 25/24/0 и (25!=24) то запрашивать замеры
  423. }
  424. }