initiator = $initiator; $this->project_id = $project_id; // 1 Определяем ид компании ( companyId ) // 1.1 если нет то крах $this->getCompanyId(); // 2 Определяем тип роекта ( projecttype ) $this->GetProjecttype(); // 3. Определяем ид проекта из asusg_project ( projectId ) $this->GetProjectId(); // 4. Определяем ид типа проекта ( projecttypeId ) // 4.1 если нет джойним asusg_project и asusg_projecttype ( projecttypeId ) $this->GetProjecttypeId(); // 5 определяем переменные locoserie, loconumber, tmpText $this->GetLocoProperties(); // 6 получаем строку коммента $this->projectcomment = 'Проект АСУ СГ №' . $this->project_id . ': ' . $this->tmpText . ', ' . $this->locoserie); // 7 собираем все переменные initiator, projecttype, projectId, locoserie, loconumber, projectcomment и фигачим проект магия !!!! ВЫЗОВ ДРУГО ПРОЦЕДУРЫ $this->CallProcedureStartProject(); echo "
";
        var_dump($this->CallProcedureStartProject());
        echo "
"; exit; $result = $this->AsusgCurJob(); //$this->AsusgCurCommand(); //var_dump($this->cur_command); //$this->startProjectForLoco(); $asusgProjectEntity = AsusgProject::find()->where(['id' => $this->project_id , 'status' => 1])->one(); if (null !== $asusgProjectEntity) { $this->projectId = $asusgProjectEntity->id;//select id from asusg_project where id = project_id and status = 1 $this->setUpdateProjects(); $this->organizeCommands(); // протестил работает! } } // получение cur_job !!!!!!!! public function AsusgCurJob() { //declare cur_job cursor for $result = []; $query = "select aj2l.id, coalesce(aj2l.asusg_employee_id1, 0), coalesce(aj2l.asusg_employee_id2, 0), coalesce(aj2l.asusg_employee_id3, 0) from asusg_job2launch aj2l where aj2l.asusg_project_id =" . $this->project_id; $this->cur_job = Yii::$app->db->createCommand($query)->queryAll(); if (count($result)) { //$this->logger->setLog(); } return $result; } public function AsusgCurTask() { $query = 'select id from tasks where parent_id = 0 and input_id = '. $this->project_id; $result = Yii::$app->db->createCommand($query)->queryAll(); if (count($result)) { //$this->logger->setLog(); } return $result; } public function AsusgCurCommand($taskId) { $query = "select t.id from tasks t where t.input_id = " . $this->project_id . " and t.parent_id = " . $taskId . " order by t.project_id, t.priority"; $result = Yii::$app->db->createCommand($query)->queryAll(); if (count($result)) { //$this->logger->setLog(); } $this->cur_command = $result; return $result; } // 1. ======================================================================================================================================== private function getCompanyId() { $result = []; $accountsEntity = Accounts::findOne($this->initiator); $this->companyId = $accountsEntity->company; if (null == $this->companyId) return false; if (count($result)) { // $this->logger->setLog(); } return $this->companyId; } // 2. ======================================================================================================================================== private function GetProjecttype() { $this->projecttype = Projecttypes::find() ->select(['id']) ->where(['name' => 'Проект из мэппинга', 'company' => $this->companyId]) ->all(); } // 3. ======================================================================================================================================== private function GetProjectId() { $asusgProjectEntity = AsusgProject::find()->where(['id' => $this->project_id , 'status' => 1])->one(); if (null !== $asusgProjectEntity) { $this->projectId = $asusgProjectEntity->id; } } // 4. ======================================================================================================================================== private function GetProjecttypeId() { $asusgProjectEntity = AsusgProject::find()->select(['asusg_projecttype_id'])->where(['id' => $this->projectId])->one(); $this->projecttypeId = $asusgProjectEntity->asusg_projecttype_id; if (null == $this->projecttypeId) { $asusgProjectJoinEntity = AsusgProject::find() ->leftJoin('asusg_projecttype', 'asusg_project.loco_serie_id = asusg_projecttype.id and asusg_projecttype.repair_type = asusg_project.repair_type') ->select(['asusg_projecttype.id']) ->where(['asusg_project.id' => $this->project_id]) ->one(); $this->projecttypeId = $asusgProjectJoinEntity->id; } } // 5. ======================================================================================================================================== private function GetLocoProperties() { $asusgProjectJoinEntity = AsusgProject::find() ->leftJoin('locomotive_series', 'asusg_project.loco_serie_id = locomotive_series.id') ->leftJoin('repairtypes', 'repairtypes.id = asusg_project.repair_type') ->select(['locomotive_series.name as lsname', 'asusg_project.loco_number', 'repairtypes.name as rtname']) ->where(['asusg_project.id' => $this->project_id]) ->asArray() ->one(); $this->locoserie = $asusgProjectJoinEntity['lsname']; $this->loconumber = $asusgProjectJoinEntity['loco_number']; $this->tmpText = $asusgProjectJoinEntity['rtname']; } // 7 . ======================================================================================================================================== private function CallProcedureStartProject() { Yii::$app->db->createCommand('CALL coverage_dis_prof(:initiator, :projecttype , @projectId , :loconumber ,:projectcomment);') ->bindValue(':initiator' , $this->initiator) ->bindValue(':projecttype', $this->projecttype) ->bindValue(':loconumber', $this->loconumber) ->bindValue(':projectcomment', $this->projectcomment) ->execute(); Yii::$app->db->createCommand("SELECT @projectId;")->queryScalar(); } public function text_log() { $query = "insert into text_log (msg) values (concat(cast(initiator as char), ': Проект ', cast(project_id as char), '/', cast(projectId as char), ' запущен в работу.'))"; Yii::$app->db->createCommand($query)->queryAll(); } public function wwwer() { $this->s1 = 'А'; $this->s2 = 'Б'; $this->s3 = 'В'; if ($this->s2v < $this->s1v) { $this->tmpsv = $this->s1v; $this->s1v = $this->s2v; $this->s2v = $this->tmpsv; $this->tmps = $this->s1; $this->s1 = $this->s2; $this->s2 = $this->tmps; } if ($this->s3v < $this->s2v) { $this->tmpsv = $this->s2v; $this->s2v = $this->s3v; $this->s3v = $this->tmpsv; $this->tmps = $this->s2; $this->s2 = $this->s3; $this->s3 = $this->tmps; } if ($this->s2v < $this->s1v) { $this->tmpsv = $this->s1v; $this->s1v = $this->s2v; $this->s2v = $this->tmpsv; $this->tmps = $this->s1; $this->s1 = $this->s2; $this->s2 = $this->tmps; } if ($this->s1v > 0) { foreach ($this->cur_job as $jobId) { // break; if ($jobId->asusg_employee_id1 != 0 || $jobId->asusg_employee_id2 != 0 || $jobId->asusg_employee_id3 != 0) { $query = "call asusg_add_job_to_project_for_section_by_employee(initiator, project_id, jobId, s1)"; } else { $query = "call asusg_add_job_to_project_for_section(initiator, project_id, jobId, s1)"; } Yii::$app->db->createCommand($query)->queryAll(); } } if ($this->s2v > 0) { foreach($this->cur_job as $jobId) { // break; if ($jobId->asusg_employee_id1 != 0 || $jobId->asusg_employee_id2 != 0 || $jobId->asusg_employee_id3 != 0) { $query = "call asusg_add_job_to_project_for_section_by_employee(" . $this->initiator . ", " . $this->project_id . ", " . $jobId->id . ", " . $jobId->asusg_employee_id2 .")"; } else { $query = "call asusg_add_job_to_project_for_section(" . $this->initiator . ", " . $this->project_id . ", " . $jobId->id . ", " . $jobId->asusg_employee_id2 .")"; } Yii::$app->db->createCommand($query)->queryAll(); } } if ($this->s3v > 0) { foreach($this->cur_job as $jobId) { // break; if ( $jobId->asusg_employee_id1 != 0 || $jobId->asusg_employee_id2 != 0 || $jobId->asusg_employee_id3 != 0) { $query = "call asusg_add_job_to_project_for_section_by_employee(" . $this->initiator . ", " . $this->project_id . ", " . $jobId->id . ", " . $jobId->asusg_employee_id3 .")"; } else { $query = "call asusg_add_job_to_project_for_section(" . $this->initiator . ", " . $this->project_id . ", " . $jobId->id . ", " . $jobId->asusg_employee_id3 .")"; } Yii::$app->db->createCommand($query)->queryAll(); } } } public function setUpdateProjects() { $query = "UPDATE asusg_project SET status = 2, started = NOW() WHERE id = " . $this->project_id; $query2 = "UPDATE projects_locotech SET tasks = coalesce(right(tasks, length(tasks) - 1), '') WHERE id = " . $this->projectId; $query3 = "INSERT INTO text_log (msg) VALUES (concat(cast(initiator as char), ': Проект ', cast(project_id as char), '/', cast(projectId as char), ' подготовлен. Упорядочиваю команды.'))"; var_dump($query,'
'); var_dump($query2,'
'); var_dump($query3,'
'); //Yii::$app->db->createCommand($query)->queryAll(); //Yii::$app->db->createCommand($query2)->queryAll(); //Yii::$app->db->createCommand($query3)->queryAll(); } public function organizeCommands() { #Упорядочить команды в задачах по project_id, установить project_id = 0. foreach ($this->AsusgCurTask() as $taskId) { $counter = 0; foreach ($this->AsusgCurCommand($taskId["id"]) as $commandId) { $query = "UPDATE tasks SET priority = " . $counter . ", project_id = 0 WHERE id = " . $commandId['id']; var_dump($query,'
'); //Yii::$app->db->createCommand($query)->queryAll(); $counter++; } } } }