123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327 |
- <?php
- namespace app\models;
- use Yii;
- use yii\base\Model;
- use app\models\entity\AsusgProject;
- use app\models\entity\Accounts;
- use app\models\entity\Projecttypes;
- class ProcedureModel extends Model
- {
- private $projectId;
- private $project_id;
- private $locoserie;
- private $loconumber;
- private $projecttypeId;
- private $projectcomment;
- private $tmpText;
- private $taskId;
- private $commandId;
- private $counter;
-
- private $jobId;
- private $projecttype;
- private $companyId;
-
- private $s1;
- private $s2;
- private $s3;
- private $tmps;
- private $s1v;
- private $s2v;
- private $s3v;
- private $tmpsv;
-
- private $done;
-
- private $initiator;
- private $cur_job;
- private $cur_command;
- public function asusg_build_and_start_project_auto($initiator, $project_id)
- {
- $initiator = '27';
- $this->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 "<pre>";
- var_dump($this->CallProcedureStartProject());
- echo "</pre>";
- 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,'<br>');
- var_dump($query2,'<br>');
- var_dump($query3,'<br>');
- //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,'<br>');
- //Yii::$app->db->createCommand($query)->queryAll();
- $counter++;
- }
- }
- }
- }
|