123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266 |
- <?php
- namespace app\models\procedure;
- use Yii;
- use yii\base\Model;
- use app\models\entity\Accounts;
- use app\models\entity\Companies;
- use app\models\entity\AsusgProject;
- use app\models\entity\Projecttypes;
- use app\models\entity\ProjectsLocotech;
- use app\models\entity\JobtypesTasktypes;
- use app\models\entity\ProjecttypesTasktypes;
- /*
- build_project: BEGIN
- declare companyId integer default 0;
- declare tmpGuid varchar(255);
- declare current_task integer;
- declare current_jobtype integer;
- declare jobtype integer;
- declare taskPriority integer;
- declare taskName varchar(255);
- declare command integer;
- declare done integer;
- declare asusg_job integer;
- declare projectId integer;
- declare locoserieId integer;
- declare cur_job_mapped cursor for select ajm.asusg_jobplan_id from asusg_job_mapped ajm where ajm.asusg_project_id = projectId order by ajm.job_order;
- declare cur_job2cmd cursor for select a.smopp_cmd_id from asusg_job2command a where a.asusg_job_id = asusg_job order by a.cmd_order;
- declare continue handler for not found set done = true;
- 1 //получяю ид компании
- set companyId = (select company from accounts where id = initiator and cmdlevel > 1);
- if (companyId is null) then leave build_project; end if;
- set locoserieId = (select id from locomotive_series where name like locoserie);
- if (locoserieId is null) then leave build_project; end if;
- 2 // Создание проекта АСУ СГ.
- set tmpGuid = (select UUID());
- insert into asusg_project
- (text, loco_serie_id, repair_type, loco_number, section_a, section_b, section_c)
- values
- (tmpGuid, locoserieId, repairtype, loconumber, section1, section2, section3);
- set projectId = (select id from asusg_project where text = tmpGuid);
- if (projectId is null) then leave build_project; end if;
- 3 // генерю проект
- set tmpGuid = (select UUID());
- insert into projects_locotech
- (action, tasks, company, status, loco_type, loco_number, urgent, created, uuid)
- values
- (projecttype, tmpGuid, companyId, 1, locoserie, loconumber, 0, NOW(), 'Запрос из АСУ СГ');
- 4 //переопределяю ид компании
- set companyId = (select id from projects_locotech where tasks = tmpGuid);
- if (companyId is null) then leave build_project; end if;
- 5 // прикрепляю команды к проекту
- update projects_locotech
- set tasks = ''
- where id = companyId;
- #Проект создан, можно добавлять задачи.
-
- set current_task = 0;
- set current_jobtype = 0;
- set taskPriority = 1;
-
- 6 // генерю таски к проекту
- open cur_job2cmd;
- task_loop: loop
- fetch cur_job2cmd into command;
- if done then leave task_loop;
- end if;
- set jobtype = (select jobtype_id from jobtypes_tasktypes where tasktype_id = command);
- if (jobtype is null) or (jobtype <> current_jobtype) then
- set current_jobtype = coalesce(jobtype, 0);
- set taskName = (select name from jobtypes where id = current_jobtype);
- set taskName = concat('Должность: ', coalesce(taskName, '(не задано)'));
- set tmpGuid = (select UUID());
- insert into tasks
- (status, parent_id, type, input_id, text, project_id, assignees_arr, priority, assignedby, created)
- values (1, 0, tasktype, companyId, tmpGuid, 0, 0, 0, 0, NOW());
- set current_task = (select id from tasks where text like tmpGuid);
- update projects_locotech
- set tasks = concat(tasks, ',', cast(current_task as char))
- where id = companyId;
- set taskPriority = 1;
- update tasks
- set text = taskName
- where id = current_task;
- end if;
- #set tmpGuid = (select UUID());
- insert into tasks
- (status, parent_id, type, input_id, text, project_id, assignees_arr, priority, assignedby, created)
- values (1, current_task, command, companyId, taskName, 0, 0, taskPriority, 0, NOW());
- #values (1, current_task, command, companyId, tmpGuid, 0, 0, taskPriority, 0, NOW());
- set taskPriority = taskPriority + 1;
- end loop;
- close cur_job2cmd;
- END
- */
- class AsusgBuildProjectFromMappingModel extends Model
- {
- private $companyId = 0;
- private $tmpGuid;
- private $current_task;
- private $current_jobtype;
- private $jobtype;
- private $taskPriority;
- private $taskNameprivate;
- private $command;
- private $done;
- private $initiator;
- private $projecttype;
- private $tasktype;
- private $locoserie;
- private $loconumber;
- private $asusg_job;
-
- //declare cur cursor for select a.smopp_cmd_id from asusg_job2command a where a.asusg_job_id = asusg_job order by a.cmd_order;
- //declare continue handler for not found set done = true;
- public static function execute($initiator, $projecttype, $tasktype, $locoserie, $loconumber, $repairtype,$section1,$section2,$section3) {
-
- $this->initiator = $initiator,
- $this->projecttype = $projecttype,
- $this->tasktype = $tasktype,
- $this->locoserie = $locoserie,
- $this->loconumber = $loconumber,
- $this->asusg_job = $asusg_job,
- $this->repairtype = $repairtype,
- $this->section1 = $section1;
- $this->section2 = $section2;
- $this->section3 = $section3;
-
- // 1. получяю ид компании
- if(!$this->GetCompanyId()) {
- return false;
- }
-
- // 2. Создание проекта АСУ СГ.
- if(!$this->GenerateAsusgProject()) {
- return false;
- }
-
- // 3. генерю проект
- if(!$this->GenerateProject()) {
- return false;
- }
-
- // 4. переопределяю ид компании
- if(!$this->RedefineCompanyId()) {
- return false;
- }
- // 5. прикрепляю команды к проекту
- if(!$this->attachCommands()) {
- return false;
- }
- // 6. генерю таски к проекту
- if(!$this->attachCommandsToProj()) {
- return false;
- }
- }
-
- private function GetCompanyId(){
- $companiesEntity = Companies::find()->where(['id' => $this->initiator])->andWhere(['>','cmdlevel',1])->one();
- $this->companyId = $companiesEntity->id;
- if ( null == $this->companyId) {
- return false;
- }
- return true;
- }
-
- private function GetUuid()
- {
- $uuid = Yii::$app->db->createCommand('select UUID() as uuid')->queryOne();
- $this->tmpGuid = $uuid["uuid"];
- if ( $this->tmpGuid ) {
- return true;
- }
- true false;
- }
-
- private function GenerateProject(){
-
- $this->GetUuid();
- $projectsLocotech = new ProjectsLocotech();
- $projectsLocotech->action = $this->projecttype;
- $projectsLocotech->tasks = $this->tmpGuid;
- $projectsLocotech->company = $this->companyId;
- $projectsLocotech->status = 1;
- $projectsLocotech->loco_type = $this->locoserie;
- $projectsLocotech->loco_number = $this->loconumber;
- $projectsLocotech->urgent = 0;
- $projectsLocotech->created = date("Y-m-d H:i:s");
- $projectsLocotech->uuid = 'Задача из АСУ СГ';
- $projectsLocotech->save();
- }
-
-
- private function GenerateAsusgProject(){
-
- $this->GetUuid();
- $AsusgProjectEntity = new AsusgProject();
- $AsusgProjectEntity->text = $this->tmpGuid;
- $AsusgProjectEntity->loco_serie_id = $this->locoserieId;
- $AsusgProjectEntity->repair_type = $this->repairtype;
- $AsusgProjectEntity->loco_number = $this->loconumber;
- $AsusgProjectEntity->section_a = $this->section1;
- $AsusgProjectEntity->section_b = $this->section2;
- $AsusgProjectEntity->section_c = $this->section3;
- $AsusgProjectEntity->save();
-
- $asuproj = AsusgProject::find()->where(['text' => $this->tmpGuid])->one();
- if ( null == $asuproj->projectId) {
- return false;
- }
- return true;
- }
-
- private function RedefineCompanyId(){
-
- $ProjectsLocotech = ProjectsLocotech::find()->where(['tasks' => $this->tmpGuid])->one();
- $rhis->companyId = $ProjectsLocotech->id;
- if ( null == $rhis->companyId ) {
- return false;
- }
- return true;
- }
-
- private function attachCommands() {
-
- ProjectsLocotech::updateAll(['tasks' = ''],['id' => $this->companyId]);
- $this->current_task = 0;
- $this->current_jobtype = 0;
- $this->taskPriority = 1;
- return true;
- }
-
- private function attachCommandsToProj() {
-
- $AsusgJob2CommandEntity = AsusgJob2Command::find()->where(['asusg_job_id' = $tgis->asusg_job])->orderBy(['cmd_order'=> SORT_ASC])->all();
- foreach( $AsusgJob2CommandEntity as $comand) {
-
- $JobtypesTasktypes = JobtypesTasktypes::find()->where(['tasktype_id' => $comand])->all();
- $this->jobtype = $JobtypesTasktypes->jobtype_id;
- if ( (null == $this->jobtype) || ($this->jobtype <> $this->current_jobtype) ) {
-
- //...
-
-
- }
- }
- }
-
- }
|