From 1d1df1a503030db8ff53e13a7f5f0445860cda3d Mon Sep 17 00:00:00 2001 From: wangyidong Date: Thu, 21 Nov 2024 14:12:51 +0800 Subject: [PATCH] * [perf story #69501] set task relation for child. --- module/task/model.php | 14 ++++--- module/task/tao.php | 39 ++++++++++++++++++++ module/task/test/lib/task.unittest.class.php | 18 +++++++++ module/task/test/tao/updaterelation.php | 27 ++++++++++++++ module/upgrade/config/upgradeflow.php | 1 + module/upgrade/model.php | 33 +++++++++++++++++ 6 files changed, 126 insertions(+), 6 deletions(-) create mode 100644 module/task/test/tao/updaterelation.php diff --git a/module/task/model.php b/module/task/model.php index 4d353e272b..0de730c0f3 100755 --- a/module/task/model.php +++ b/module/task/model.php @@ -374,7 +374,7 @@ class taskModel extends model $isParentChanged = $task->parent != $oldTask->parent; /* If there is a parent task before updating the task, update the parent. */ - if($task->parent > 0) $this->updateParent($task, $isParentChanged); + $this->updateParent($task, $isParentChanged); if($isParentChanged && $oldTask->parent > 0) { $oldParentTask = $this->dao->select('*')->from(TABLE_TASK)->where('id')->eq($oldTask->parent)->fetch(); @@ -3223,11 +3223,12 @@ class taskModel extends model public function updateParent(object $task, bool $isParentChanged): void { $oldTask = $this->fetchByID($task->id); - $parentTask = $this->fetchByID((int)$task->parent); - $path = $parentTask->path . $task->id . ','; + $parentTask = empty($task->parent) ? null : $this->fetchByID((int)$task->parent); + $parentPath = $parentTask ? $parentTask->path : ','; + $path = $parentPath . $task->id . ','; $this->dao->update(TABLE_TASK)->set('path')->eq($path)->where('id')->eq($task->id)->exec(); - if(!$parentTask->isParent) $this->dao->update(TABLE_TASK)->set('isParent')->eq(1)->where('id')->eq((int)$task->parent)->exec(); + if($parentTask && !$parentTask->isParent) $this->dao->update(TABLE_TASK)->set('isParent')->eq(1)->where('id')->eq((int)$task->parent)->exec(); /* 更新所有子任务的path. */ $childIdList = $this->getAllChildId($task->id, false); @@ -3242,9 +3243,10 @@ class taskModel extends model } $this->updateParentStatus($task->id, $task->parent, !$isParentChanged); - $this->computeBeginAndEnd($task->parent); + if($task->parent) $this->computeBeginAndEnd($task->parent); - if($isParentChanged) + $this->taskTao->updateRelation((int)$task->id, (int)$task->parent); + if($isParentChanged && $task->parent) { $this->loadModel('action')->create('task', $task->id, 'linkParentTask', '', $task->parent, '', false); $actionID = $this->action->create('task', $task->parent, 'linkChildTask', '', $task->id, '', false); diff --git a/module/task/tao.php b/module/task/tao.php index f1657a5ffa..64d1900ecc 100644 --- a/module/task/tao.php +++ b/module/task/tao.php @@ -1055,4 +1055,43 @@ class taskTao extends taskModel if($task->mode == 'linear' && empty($record->order)) $this->updateEffortOrder($effortID, $currentTeam->order); } + + /** + * 更新父子任务关系。 + * Update relation of parent and child. + * + * @param int $childID + * @param int $parentID + * @access protected + * @return void + */ + protected function updateRelation(int $childID, int $parentID = 0): void + { + if(empty($childID)) return; + + $relation = $this->dao->select('*')->from(TABLE_RELATION)->where('AID')->eq($childID)->andWhere('relation')->eq('subdividefrom')->andWhere('AType')->eq('task')->andWhere('BType')->eq('task')->fetch(); + if($relation) + { + if($parentID && $relation->BID == $parentID) return; + + $this->dao->delete()->from(TABLE_RELATION)->where('BID')->eq($childID)->andWhere('relation')->eq('subdivideinto')->andWhere('AType')->eq('task')->andWhere('BType')->eq('task')->exec(); + $this->dao->delete()->from(TABLE_RELATION)->where('AID')->eq($childID)->andWhere('relation')->eq('subdividefrom')->andWhere('AType')->eq('task')->andWhere('BType')->eq('task')->exec(); + } + + if(empty($parentID)) return; + + $data = new stdclass(); + $data->AType = 'task'; + $data->BType = 'task'; + $data->AID = $childID; + $data->BID = $parentID; + $data->relation = 'subdividefrom'; + $this->dao->insert(TABLE_RELATION)->data($data)->exec(); + + $data->AID = $parentID; + $data->BID = $childID; + $data->relation = 'subdivideinto'; + $this->dao->insert(TABLE_RELATION)->data($data)->exec(); + return; + } } diff --git a/module/task/test/lib/task.unittest.class.php b/module/task/test/lib/task.unittest.class.php index bf9c5ae089..0f49349cb8 100755 --- a/module/task/test/lib/task.unittest.class.php +++ b/module/task/test/lib/task.unittest.class.php @@ -2246,4 +2246,22 @@ class taskTest foreach($childTasks as $key => $value) $result .= $key . ':' . $value . ';'; return rtrim($result, ';'); } + + /** + * 测试 updateRelation 方法 + * Test updateRelationq + * + * @param int $childID + * @param int $parentID + * @access public + * @return void + */ + public function updateRelationTest(int $childID, int $parentID = 0) + { + $this->objectModel->updateRelation($childID, $parentID); + $relation = $this->objectModel->dao->select('*')->from(TABLE_RELATION)->where('AID')->eq($childID)->andWhere('relation')->eq('subdividefrom')->andWhere('AType')->eq('task')->andWhere('BType')->eq('task')->fetch(); + + if(empty($relation)) return 'null'; + return $relation->BID; + } } diff --git a/module/task/test/tao/updaterelation.php b/module/task/test/tao/updaterelation.php new file mode 100644 index 0000000000..239964e086 --- /dev/null +++ b/module/task/test/tao/updaterelation.php @@ -0,0 +1,27 @@ +#!/usr/bin/env php +updateRelation(); +cid=0 + +- 都传入空参数 @null +- childID传入空参数 @null +- 传入正常参数 @1 +- 修改关联父任务 @3 +- 解除关联 @null + +*/ + +zenData('relation')->gen(0); + +$task = new taskTest(); + +r($task->updateRelationTest(0, 0)) && p() && e('null'); //都传入空参数 +r($task->updateRelationTest(0, 1)) && p() && e('null'); //childID传入空参数 +r($task->updateRelationTest(2, 1)) && p() && e('1'); //传入正常参数 +r($task->updateRelationTest(2, 3)) && p() && e('3'); //修改关联父任务 +r($task->updateRelationTest(2, 0)) && p() && e('null'); //解除关联 diff --git a/module/upgrade/config/upgradeflow.php b/module/upgrade/config/upgradeflow.php index fcb21144d1..eaa12ab3af 100644 --- a/module/upgrade/config/upgradeflow.php +++ b/module/upgrade/config/upgradeflow.php @@ -105,6 +105,7 @@ $config->upgrade->execFlow['20_5'] = array('functions' => 'fixWorkflowFie $config->upgrade->execFlow['20_6'] = array('functions' => 'processDemandFiles,processSqlbuilderTables'); $config->upgrade->execFlow['20_7'] = array('functions' => 'upgradeMyDocSpace'); $config->upgrade->execFlow['20_8'] = array('functions' => 'processWorkflowGroups'); +$config->upgrade->execFlow['20_9'] = array('functions' => 'initTaskRelation'); if(!empty($config->isINT)) { diff --git a/module/upgrade/model.php b/module/upgrade/model.php index a1b842ae0c..a0cdd8e0cb 100644 --- a/module/upgrade/model.php +++ b/module/upgrade/model.php @@ -10451,4 +10451,37 @@ class upgradeModel extends model } } } + + /** + * 初始化任务关联。 + * Init task relation. + * + * @access public + * @return void + */ + public function initTaskRelation() + { + $childTasks = $this->dao->select('id,parent')->from(TABLE_TASK)->where('parent')->gt(0)->fetchPairs('id', 'parent'); + if(empty($childTasks)) return; + + $childIdList = array_keys($childTasks); + $this->dao->delete()->from(TABLE_RELATION)->where('BID')->in($childIdList)->andWhere('relation')->eq('subdivideinto')->andWhere('AType')->eq('task')->andWhere('BType')->eq('task')->exec(); + $this->dao->delete()->from(TABLE_RELATION)->where('AID')->in($childIdList)->andWhere('relation')->eq('subdividefrom')->andWhere('AType')->eq('task')->andWhere('BType')->eq('task')->exec(); + + $data = new stdclass(); + $data->AType = 'task'; + $data->BType = 'task'; + foreach($childTasks as $taskID => $parentID) + { + $data->AID = $taskID; + $data->BID = $parentID; + $data->relation = 'subdividefrom'; + $this->dao->insert(TABLE_RELATION)->data($data)->exec(); + + $data->AID = $parentID; + $data->BID = $taskID; + $data->relation = 'subdivideinto'; + $this->dao->insert(TABLE_RELATION)->data($data)->exec(); + } + } }