123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367 |
- <?php
- namespace app\models;
- use Yii;
- use yii\base\Model;
- use app\models\entity\Tasks;
- use app\models\logger;
- class MappingHandlerModel extends Model
- {
-
-
- public $arResult = [];
- private $logger;
-
- public function __construct($logger) {
-
- $this->logger = $logger;
- }
-
- public function setLog($text)
- {
- $this->logger->log($text,$this->className());
- }
-
- public function curlRequest2($params){
-
- $urlWithParam = $params['url'].'?user_id='. $params['param'] ;
-
- $curl = curl_init();
- curl_setopt($curl, CURLOPT_URL, $urlWithParam);
- curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
- curl_setopt($curl, CURLOPT_USERPWD, $params['login'] . ":" . $params['pass']);
- curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-Type: application/json","Accept: application/json"));
- curl_setopt($curl, CURLOPT_TIMEOUT, 20);
- curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
- curl_setopt($curl, CURLOPT_POST, 1);
- curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
- curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
- $result = curl_exec($curl);
- return $result;
- }
-
- public function Getisabsentworks($listWorks = null, $GWparams ){
-
- if ( null == $listWorks) {
- return false;
- }
- $arrayIdWorks = [];
- foreach( $listWorks->data as $work ) {
- $arrayIdWorks[] = $work->id_work;
- }
- //$arrayIdWorks[] = 'c7cfdeb5-9293-4314-9958-15d15a297532';
- //$asusgJob2LaunchEntity = AsusgJob2Launch::find()->where(['not in','asusg_job_uuid_',$arrayIdWorks])->all();
-
- $asusgJob2LaunchEntity = (new \yii\db\Query())
- ->select(['t.assignees_arr','ai.id','t.status','t.id','jl.asusg_job_uuid'])
- //->select(['t.assignees_arr'])
- ->from('`asusg_job2launch` as `jl`')
- ->leftJoin('`tasks` as `t`', 'jl.id = t.asusg_job_mapped_id')
- ->rightJoin('`accounts_internal` as `ai`', 't.assignees_arr = cast(ai.id as char)')
- //->where(['jl.asusg_job_uuid' => $job_uuid])
- ->andWhere(['in','asusg_job_uuid',$arrayIdWorks])
- ->andWhere(['ai.uuid' => $GWparams['param']])
- ->andWhere(['<>','t.parent_id', 0])
- ->groupBy(['jl.asusg_job_uuid'])
- ->all();
-
- $resultArrWork = [];
- foreach( $asusgJob2LaunchEntity as $work ) {
- $resultArrWork[] = $work["asusg_job_uuid"];
- }
- array_diff ($arrayIdWorks, $resultArrWork);
-
- foreach( $listWorks->data as $works ) {
- if ( in_array($works->id_work, array_diff ($arrayIdWorks, $resultArrWork))) {
- $result[] = $works;
- }
- //$resultArrWork[] = $work["asusg_job_uuid"];
-
- }
- return $result;
- /*
- echo "<pre>";
- var_dump($resultArrWork);
- echo "</pre>";
- */
-
- }
- public function getOnlineMobileUser(){
-
- $result = [];
- $accountsEntity = \app\models\entity\Accounts::find()->all();
- foreach ($accountsEntity as $account) {
-
- $last_seen_mobile = ( null != $account->last_seen_mobile )? new \DateTime($account->last_seen_mobile): $account->last_seen_mobile ;
- $online_mobile = $this->OnlineAccountCheck($this->TimeString($last_seen_mobile));
-
- if ( !$online_mobile ){
- continue;
- }
- $result[] = ['id' => $account->id, 'uuid' => $account->uuid];
- }
-
- return $result;
- }
-
- //public function startProject($params,$userInfo,$projecttypeId){
- public function startProject(){
-
- $arrayResultTemp = [];
- $projectsModel = new ProjectsModel();
- foreach($this->arResult['listW'] as &$item){
-
- $arrayResult = [];
- $arrayResult['loco_type'] = $item['info']['locomotive_series'];
- $arrayResult['loco_number'] = $item['info']["section_subnumber"];
- $arrayResult['action'] = $projecttypeId->id;
- $arrayResult['company'] = $this->arResult['userInfo']->company;//'//$userInfo->company;
- //$arrayResult['section_id'] = $item['info']["section_number"];
- $arrayResult['depo'] = '';
- $arrayResult['depo_service'] = '';
- $arrayResult['kind'] = '';
- $item['project'] = 'sdfsdfsd';//$projectsModel->ProjectsModel($arrayResult,$item['info']["section_number"]);
- $item['userInfo'] = $this->arResult['userInfo'];//$userInfo;
- $item['projecttypeId'] = $this->arResult['projecttypeId']->id;//$projecttypeId->id;
- }
- //return $params;
-
- }
-
- public function getUserInfo($user)
- {
- if (!$user){
- return '';
- }
- $accountsEntity = Accounts::find()->where(['uuid' => $user['param'] ])->one();
- return $accountsEntity;
- }
-
- public function getTypeProject($user)
- {
- $projettypesEntity = Projecttypes::find()->select('id')->where(['company' => $user->company, 'name' => 'Проект из мэппинга'])->one();
- return $projettypesEntity;
-
- }
-
- public function OnlineAccountCheck($last_seen)
- {
- $last_seen = date($last_seen);
- $time = (time()-strtotime($last_seen));
- if ($time <= Yii::$app->params['onlineMobileTimeoutSeconds'])
- return true;
- return false;
- }
-
- public function TimeString($timeobj)
- {
- if ($timeobj != null)
- return $timeobj->format('d.m.Y H:i');
- //return date('d.m.Y H:i', $timeobj);
- }
-
-
- public function GetworksOnLoco($listWorks)
- {
- $result = [];
- if (empty($listWorks)){
- return $result;
- }
- $arrayResult = [];
- foreach ($listWorks as $work){
- $arrayResult[] = $work->section_id;
- }
- $sectionsEntity = Sections::find()->where(['in','uuid',$arrayResult])->asArray()->all();
- $arrayResult = [];
- $arrayResultTemp = [];
- $arrayIdSerieTemp = [];
- foreach($sectionsEntity as $sec){
- $arrayResult[] = $sec['uuid'];
- $arrayResultTemp[$sec['uuid']] = $sec;
-
- $LocomotiveSeriesEntity = LocomotiveSeries::findOne(['name' => $sec['locomotive_series']]);
- $arrayIdSerieTemp[$sec['uuid']] = $LocomotiveSeriesEntity->id;
- }
- $tempArray = [];
- foreach($listWorks as $w) {
- if ( in_array($w->section_id,$arrayResult)) {
- $tempArray[] = $w;
- $result[$w->section_id] = [ 'info_obj' => $tempArray ,'info'=> $arrayResultTemp[$w->section_id],'id_serie' => $arrayIdSerieTemp[$w->section_id]];
- }
- }
- return $result;
- /*
- echo "<pre>";
- var_dump($result);
- //var_dump($sectionsEntity);
- echo "</pre>";
- var_dump(count($arrayResult),count($sectionsEntity));
- */
-
- }
-
- public function checkMapping($arrProj)
- {
- $tempResult = [];
- $result = [];
-
- foreach ( $arrProj as &$proj) {
- foreach ( $proj['info_obj'] as $work) {
- $tempResult[] = $work->work_name;
- }
- $res = AsusgJobPlan::find()->where(['in', 'name',$tempResult])->all();
- $proj['jobplan'] = $res;
- }
- return $arrProj;
- }
-
- public function addJobproject($minRes)
- {
- $projectTypes = [];
- foreach ( $minRes as &$proj) {
-
- foreach($proj['info_obj'] as $obj){
- $repairtypesEntity = Repairtypes::find()->select('id')->where(['name'=> $obj->repair_name])->one();
- $projectTypes[] = $repairtypesEntity->id;
- }
- $projectTypes = array_unique($projectTypes);
-
- foreach ( $projectTypes as $type) {
-
- $field = Yii::$app->params['sections_letter'][$proj['info']["letter"]];
- $asusgProjectEntity = new AsusgProject();
- $asusgProjectEntity->loco_serie_id = $proj['id_serie']; //locomotive_series
- $asusgProjectEntity->repair_type = $type; // repairtypes name из асусг
- $asusgProjectEntity->loco_number = $proj['info']["section_number"];
- $asusgProjectEntity->$field = $proj['info']["section_subnumber"];
- $asusgProjectTypeEntity = AsusgProjectType::findOne(['loco_serie_id' => $proj['id_serie'], 'repair_type' => $type]);
- $asusgProjectEntity->asusg_projecttype_id = $asusgProjectTypeEntity->id;
- $asusgProjectEntity->save();
- $proj['asusgProject_id'] = $asusgProjectEntity->id;
- }
- }
- return $minRes;
- }
-
- public function addJob2launch($minRes)
- {
-
- foreach ( $minRes as $proj) {
- $resultArr = [];
- $order = 1;
- foreach ( $proj['jobplan'] as $work) {
- $sectionTemp = '';
- $id_workTemp = '';
- foreach($proj['info_obj'] as $obj){
- if( $obj->work_name == $work->name){
- $sectionTemp = $obj->section_id;
- $id_workTemp = $obj->id_work;
- break;
- }
- }
-
- $asusgJob2LaunchEntity = new AsusgJob2Launch();
- $asusgJob2LaunchEntity->asusg_jobplan_id = $work->id;
- $asusgJob2LaunchEntity->asusg_employee_id1 = $proj['userInfo']->id;
- $asusgJob2LaunchEntity->asusg_job_uuid = $id_workTemp;
- $asusgJob2LaunchEntity->section_uuid = $sectionTemp;
- $asusgJob2LaunchEntity->asusg_project_id = $proj['asusgProject_id'];
- $asusgJob2LaunchEntity->job_order = $order;
- $asusgJob2LaunchEntity->save();
- echo "<pre>";
- var_dump($asusgJob2LaunchEntity->errors);
- //var_dump($sectionsEntity);
- echo "</pre>";
- $order++;
- }
-
- }
-
-
- }
-
- // Добавление новой ЗАДАЧИ
-
- public function addNewMainTask()
- {
- $work = Yii::$app->params['api']['mesrmntParam']['work'];
- /*echo "<pre> Main Task";
- var_dump(Yii::$app->params['api']['mesrmntParam']);
- echo "</pre>";
- return true;*/
- $tasksEntity = new Tasks();
- $tasksEntity->parent_id = 0;
- $tasksEntity->status = 2;
- $tasksEntity->type = Yii::$app->params['api']['mesrmntParam']['type'];//$tasktypesEntity->id;
- $tasksEntity->assignees_arr = Yii::$app->params['api']['mesrmntParam']['assignees_arr'];//Yii::$app->params['assignees_arr'];//$user->id;
- $tasksEntity->created = date("Y-m-d H:i;s");
- $tasksEntity->asusg_job_mapped_id = Yii::$app->params['api']['mesrmntParam']['asusg_job_mapped_id'];//$asusgJob2LaunchEntity->id;
- $tasksEntity->mapping_comment = $work["outfit"] . ': ' . $work['work_name'];
- $tasksEntity->text = $work["outfit"] . ': ' . $work['work_name'];
-
- if($tasksEntity->save()) {
- Yii::$app->params['api']['mesrmntParam']['parent_id'] = $tasksEntity->id;
- //$this->testIdpl3 = $tasksEntity->id;
- //$this->setLog('в Tasks была добавлена ЗАДАЧА => "'. $work['work_name'] . '" id => '.$tasksEntity->id);
- } else {
- //$this->setLog('в Tasks была НЕ добавлена ЗАДАЧА => "'. $work['work_name'] . '" id => '.$tasksEntity->id);
- }
- return $tasksEntity;
- }
-
-
- // Добавление новой КОМАНДЫ
-
- // param
- // $chp => boolean ( добавлять чекпоинты или нет )
- public function addNewTask($chp = false)
- {
- // $tasksEntity->id; родительская задача
- // $countPriority приоритет
- // $user->id сотрудник
- // $job->jobplantie->id launch
- Yii::$app->params['countPriority']++;
- $work = Yii::$app->params['api']['mesrmntParam']['work'];
- /*echo "<pre> Task";
- var_dump(Yii::$app->params['api']['mesrmntParam']);
- echo "</pre>";
- return true;*/
- $result = [];
- $arrJ = [];
- $tasksEntity = new Tasks();
- $tasksEntity->input_id = Yii::$app->params['api']['mesrmntParam']['input_id'];//$tasksEntity->id;
- $tasksEntity->parent_id = Yii::$app->params['api']['mesrmntParam']['parent_id'];//$tasksEntity->id;
- $tasksEntity->status = 2;
- $tasksEntity->priority = Yii::$app->params['countPriority'];//$countPriority;
- $tasksEntity->created = date("Y-m-d H:i:s");
- $tasksEntity->type = Yii::$app->params['api']['mesrmntParam']['type'];//$job->smopp_cmd_id;//Yii::$app->params['supercycletype'];
- $tasksEntity->assignees_arr = Yii::$app->params['api']['mesrmntParam']['assignees_arr'];//$user->id;
- $tasksEntity->asusg_job_mapped_id = Yii::$app->params['api']['mesrmntParam']['asusg_job_mapped_id'];//$job->jobplantie->id;
- $tasksEntity->name = Yii::$app->params['api']['mesrmntParam']['measurement_name'];
- $tasksEntity->text = $work["eq_serie"] . " ".$work["section_lit"] . ", ". $work["outfit"] . ": " . $work['work_name'];
- $tasksEntity->mapping_comment = $work["outfit"] . ': ' . $work['work_name'];
- if ( $tasksEntity->save()) {
- $arrJ[] = $tasksEntity->id;
- if( $chp ) {
- //$query = "call asusg_add_checkpoints_to_task(" . Yii::$app->params['api']['mesrmntParam']['assignees_arr'] . ",'" . $tasksEntity->id . "')";
- //$resProc = Yii::$app->db->createCommand($query)->execute();
-
- //var_dump($resProc, 'запись checkpoints',$query); echo "\n";
- }
- //$this->setLog('в Tasks была добавлена КОМАНДА => "'. $work['work_name'] . '" id => '.$tasksEntity->id);
- } else {
- //$this->setLog('в Tasks была НЕ добавлена КОМАНДА => "'. $work['work_name'] . '" id => '.$tasksEntity->id);
- }
- Yii::$app->params['countPriority']++;
- $result['arrJ'] = $arrJ;
- $result['tasksEntity'] = $tasksEntity;
- return $result;
- }
- }
|