123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360 |
- <?php
- namespace app\models\procedure;
- use Yii;
- use yii\base\Model;
- use app\models\entity\Accounts;
- use app\models\entity\Projecttypes;
- use app\models\entity\ProjectsLocotech;
- use app\models\entity\ProjecttypesTasktypes;
- use app\models\entity\JobtypesTasktypes;
- /*
- cptask: BEGIN
- declare tasktype integer;
- declare jobtype_old integer;
- declare jobtype_new integer;
- declare pt_old integer;
- declare toptasktype integer;
- declare jobtype_tmp integer;
- #declare taskpriority integer;
- declare tmptxt varchar(255);
- declare taskname varchar(255);
- declare taskdescription varchar(255);
- declare taskcompany integer;
- declare taskconfirmtype integer;
- declare tasktime2complete integer;
- 1. Запись в лог
- insert into text_log
- (msg)
- values
- (concat(cast(initiator as char), ': перенос команды ', cast(task_id as char), ' в задачу ', cast(parent_task as char), '.'));
- 2. Получаем инфо по задаче
- select t.type, t.parent_id into tasktype, pt_old
- from tasks t
- where t.id = task_id;
-
- 2.1 если задача родитель то выпадаем.
- if pt_old = parent_task then leave cptask; end if;
-
- 3 получение приоритетной задачи
-
- select min(type) into toptasktype
- from tasks
- where parent_id = parent_task
- and priority > 0;
- if toptasktype is null then leave cptask; end if;
-
- 4 получение типа задачи
- select max(jttt.jobtype_id) into jobtype_old
- from jobtypes_tasktypes jttt
- where jttt.tasktype_id = tasktype;
-
- select max(jttt.jobtype_id) into jobtype_new
- from jobtypes_tasktypes jttt
- where jttt.tasktype_id = toptasktype;
-
- 5 обновление родительской задачи
- if jobtype_old = jobtype_new then
- update tasks
- set parent_id = parent_task
- #, priority = taskpriority
- where id = task_id;
- insert into text_log (msg) values (concat(cast(initiator as char), ': команда ', cast(task_id as char), ' перенесена.'));
- leave cptask;
- end if;
-
- 6 получение типов тасков
- select name, description, company, confirmtype, time_to_complete_minutes
- into taskname, taskdescription, taskcompany, taskconfirmtype, tasktime2complete
- from tasktypes
- where id = tasktype;
- set toptasktype = null;
-
- 7 переопределение приоритетной задачи
- select tt.id into toptasktype
- from tasktypes tt
- left join jobtypes_tasktypes jttt on tt.id = jttt.tasktype_id
- where tt.name = taskname
- and tt.description = taskdescription
- and tt.company = taskcompany
- and tt.main_task = 0
- and tt.confirmtype = taskconfirmtype
- and tt.time_to_complete_minutes = tasktime2complete
- and jttt.jobtype_id = jobtype_new;
- if toptasktype is null then
- set tmptxt = uuid();
- insert into tasktypes
- (creator_id, name, description, company, main_task, confirmtype, time_to_complete_minutes, control_map)
- values
- (initiator, tmptxt, taskdescription, taskcompany, 0, taskconfirmtype, tasktime2complete, 0);
- select id into toptasktype
- from tasktypes
- where name = tmptxt;
- update tasktypes
- set name = taskname
- where id = toptasktype;
- insert into text_log (msg) values (concat('Создан новый тип задач: ', cast(toptasktype as char)));
- else
- insert into text_log (msg) values (concat('Найден тип задачи: ', cast(toptasktype as char)));
- end if;
- 8
- set jobtype_tmp = null;
- select max(jobtype_id) into jobtype_tmp
- from jobtypes_tasktypes
- where tasktype_id = toptasktype;
- if (jobtype_tmp is null) or (jobtype_tmp <> jobtype_new) then
- insert into jobtypes_tasktypes
- (jobtype_id, tasktype_id)
- values
- (jobtype_new, toptasktype);
- end if;
- 9
-
- update tasks
- set parent_id = parent_task,
- #priority = taskpriority,
- type = toptasktype
- where id = task_id;
- insert into text_log (msg) values (concat(cast(initiator as char), ': команда ', cast(task_id as char), ' перенесена с новым типом задачи.'));
- END
- */
- class AsusgChangeParentTaskModel extends Model
- {
- private $tasktype;
- private $jobtype_old;
- private $jobtype_new;
- private $pt_old;
- private $initiator;
- private $parent_task;
- private $task_id;
- private $toptasktype;
- private $jobtype_tmp;
-
- private $tmptxt;
- private $taskname;
- private $taskdescription;
- private $taskcompany;
- private $taskconfirmtype;
- private $tasktime2complete;
- public function execute($initiator, $task_id, $parent_task)
- {
-
- $this->initiator = $initiator;
- $this->task_id = $task_id;
- $this->parent_task = $parent_task;
-
- //1. Запись в лог
- $this->insertLog($this->initiator. ': перенос команды ' . $this->task_id . ' в задачу '. $this->parent_task . '.');
-
- //2. Получаем инфо по задаче
- if(!$this->GetTaskInfo()) {
- return false;
- }
-
- // 3 получение приоритетной задачи
-
- if(!$this->GetTopTask()) {
- return false;
- }
-
- // 4 получение типа задачи
- if(!$this->GetTaskTypes()) {
- return false;
- }
- //5 обновление родительской задачи
- if(!$this->ParentUpdate()) {
- return false;
- }
-
- //6 получение типов тасков
- if(!$this->GetListTasktypes()) {
- return false;
- }
-
- $this->toptasktype = null;
-
- // 7 переопределение приоритетной задачи
- if(!$this->RedefineTopTask()) {
- return false;
- }
-
- // 8 переопределение приоритетной задачи
- if(!$this->TempTaskType()) {
- return false;
- }
-
- // 9 переопределение родителя задачи
- if(!$this->SetParent()) {
- return false;
- }
-
- return false;
-
- }
-
-
- private function insertLog($mgs) {
-
- $textlogEntity = new Textlog();
- $textlogEntity->msg = $mgs;
- $textlogEntity->save();
- }
-
- private function GetTaskInfo()
- {
- $tasksEntity = Tasks::findOne($this->task_id);
- if ( null == $tasksEntity){
- return false;
- }
- $this->tasktype = $tasksEntity->type;
- $this->pt_old = $tasksEntity->parent_id;
- if ( null == $this->pt_old){
- return false;
- }
- if pt_old = parent_task then leave cptask; end if;
- return true;
- }
-
- private function GetTopTask()
- {
- $tasksEntity = Tasks::find()->where(['parent_id' => $this->parent_task])->andWhere(['>', 'priority', 0])->min('type');
- $this->toptasktype = $tasksEntity->type;
- if ( null == $this->toptasktype){
- return false;
- }
- return true;
- }
-
- private function GetTaskTypes() {
-
- $jobtypesTasktypes = JobtypesTasktypes::find()->where(['tasktype_id' => $this->tasktype])->max('jobtype_id');
- $this->jobtype_old = $jobtypesTasktypes->jobtype_id;
- $jobtypesTasktypes = JobtypesTasktypes::find()->where(['tasktype_id' => $this->toptasktype])->max('jobtype_id');
- $this->jobtype_new = $jobtypesTasktypes->jobtype_id;
- if ( (null == $this->jobtype_new) or ( null == $this->jobtype_old) ){
- return false;
- }
- return true;
- }
-
- private function ParentUpdate() {
- if ( $this->jobtype_old == $this->jobtype_new ){
- $tasksEntity = Tasks::findOne($this->task_id);
- $tasksEntity->parent_id = $this->parent_task;
- $tasksEntity->save();
-
- $textlogEntity = new Textlog();
- $textlogEntity->msg = $this->initiator . ': команда ' . $this->task_id . ' перенесена.';
- $textlogEntity->save();
- return false;
- }
- return true;
- }
- private function GetListTasktypes(){
- $tasktypesEntity = Tasktypes::findOne($this->tasktype);
- if ( null != $tasktypesEntity) {
- $this->taskname = $tasktypesEntity->name;
- $this->taskdescription = $tasktypesEntity->description;
- $this->taskcompany = $tasktypesEntity->company;
- $this->taskconfirmtype = $tasktypesEntity->confirmtype;
- $this->tasktime2complete = $tasktypesEntity->time_to_complete_minutes;
- return true;
- }
- return false;
- }
-
- private function RedefineTopTask(){
- $tasktypesEntity = Tasktypes::find()->select('tt.id')
- ->leftJoin('jobtypes_tasktypes', '`tasktypes`.`id` = `jobtypes_tasktypes`.`tasktype_id`')
- ->where([
- 'tasktypes.name' => $this->taskname,
- 'tasktypes.description' => $this->taskdescription,
- 'tasktypes.company' => $this->taskcompany,
- 'tasktypes.main_task' => 0,
- 'tasktypes.confirmtype' => $this->taskconfirmtype,
- 'tasktypes.time_to_complete_minutes' => $this->tasktime2complete,
- 'jobtypes_tasktypes.jobtype_id' => $this->jobtype_new
- ])
-
- ->all();
- $this->toptasktype = $tasktypesEntity->id;
- if ( null == $this->toptasktype ) {
- $this->tmptxt = Yii::$app->db->createCommand('select UUID() as uuid')->queryOne();
- $tasktypesEntity = new Tasktypes();
- $tasktypesEntity->creator_id = $this->initiator;
- $tasktypesEntity->name = $this->tmptxt;
- $tasktypesEntity->description = $this->taskdescription
- $tasktypesEntity->company = $this->taskcompany
- $tasktypesEntity->main_task = 0;
- $tasktypesEntity->confirmtype = $this->taskconfirmtype
- $tasktypesEntity->time_to_complete_minutes = $this->tasktime2complete;
- $tasktypesEntity->control_map = 0;
- $tasktypesEntity->save();
-
- $tasktypesEnt = Tasktypes::find()->where(['name' => $this->tmptxt])->one();
- $this->toptasktype = $tasktypesEnt->id; // !!
- if ( null == $this->toptasktype ) {
- return false;
- }
-
- $tasktypes = Tasktypes::find()->where(['id' => $this->toptasktype])->one();
- $tasktypes->name = $this->taskname;
- $tasktypes->save(); // !!
-
- $this->insertLog('Создан новый тип задач: ' . $this->toptasktype);
-
- } else {
- $this->insertLog('Найден тип задачи: ' . $this->toptasktype);
- }
- return true;
- }
-
- private function TempTaskType() {
-
- $this->jobtype_tmp = null;
- $jobtypesTasktypes = JobtypesTasktypes::find()->where(['tasktype_id' => $this->toptasktype])->max('jobtype_id');
- $this->jobtype_tmp = $jobtypesTasktypes->jobtype_id;
- if (( null == $this->jobtype_tmp) or ($this->jobtype_tmp <> $this->jobtype_new)) {
- $jobtypesTasktypesEntity = new JobtypesTasktypes();
- $jobtypesTasktypesEntity->jobtype_id = $this->jobtype_new;
- $jobtypesTasktypesEntity->tasktype_id = $this->toptasktype;
- if (!$jobtypesTasktypesEntity->save()){
- return false;
- }
- }
- return true;
- }
-
- private function SetParent() {
- $tasksEntity = Tasks::findOne($this->task_id);
- $tasksEntity->parent_id = $this->parent_task;
- $tasksEntity->type = $this->toptasktype;
- if ( !$tasksEntity->save() ) {
- return false;
- }
- $this->insertLog($this->initiator . ': команда ' . $this->task_id . ' перенесена с новым типом задачи.');
- return true;
- }
- }
|