* Refactor computeestimate method.

This commit is contained in:
wangyidong
2023-05-30 09:44:29 +08:00
parent 61dc8f6eb5
commit 31ec715e8d
3 changed files with 27 additions and 15 deletions
+10 -11
View File
@@ -86,11 +86,11 @@ class storyModel extends model
$story->children = array();
if($story->parent == '-1') $story->children = $this->dao->select('*')->from(TABLE_STORY)->where('parent')->eq($storyID)->andWhere('deleted')->eq(0)->fetchAll('id');
$story->openedDate = substr($story->openedDate, 0, 19);
$story->assignedDate = substr($story->assignedDate, 0, 19);
$story->reviewedDate = substr($story->reviewedDate, 0, 19);
$story->closedDate = substr($story->closedDate, 0, 19);
$story->lastEditedDate= substr($story->lastEditedDate, 0, 19);
$story->openedDate = empty($story->openedDate) ? '' : substr($story->openedDate, 0, 19);
$story->assignedDate = empty($story->assignedDate) ? '' : substr($story->assignedDate, 0, 19);
$story->reviewedDate = empty($story->reviewedDate) ? '' : substr($story->reviewedDate, 0, 19);
$story->closedDate = empty($story->closedDate) ? '' : substr($story->closedDate, 0, 19);
$story->lastEditedDate= empty($story->lastEditedDate)? '' : substr($story->lastEditedDate, 0, 19);
return $story;
}
@@ -1423,16 +1423,15 @@ class storyModel extends model
* @access public
* @return bool
*/
public function computeEstimate($storyID)
public function computeEstimate(int $storyID): bool
{
if(!$storyID) return true;
$stories = $this->dao->select('`id`,`estimate`,status')->from(TABLE_STORY)->where('parent')->eq($storyID)->andWhere('deleted')->eq(0)->fetchAll('id');
if(empty($stories)) return true;
$estimates = $this->dao->select('`id`,`estimate`')->from(TABLE_STORY)->where('parent')->eq($storyID)->andWhere('deleted')->eq(0)->fetchPairs('id', 'estimate');
if(empty($estimates)) return true;
$estimate = 0;
foreach($stories as $story) $estimate += $story->estimate;
$this->dao->update(TABLE_STORY)->set('estimate')->eq($estimate)->autoCheck()->where('id')->eq($storyID)->exec();
$estimate = round(array_sum($estimates), 2);
$this->dao->update(TABLE_STORY)->set('estimate')->eq($estimate)->where('id')->eq($storyID)->exec();
return !dao::isError();
}
+10 -1
View File
@@ -4,6 +4,11 @@ include dirname(__FILE__, 5) . '/test/lib/init.php';
include dirname(__FILE__, 2) . '/story.class.php';
su('admin');
$story = zdTable('story');
$story->parent->range('0,`-1`,2{3}');
$story->estimate->range('[1-4]');
$story->gen(5);
/**
title=测试 storyModel->computeEstimate();
@@ -16,4 +21,8 @@ pid=1
$story = new storyTest();
r() && p() && e();
r($story->computeEstimateTest(0)) && p() && e('0'); //不传入需求。
r($story->computeEstimateTest(1)) && p('old,new') && e('1,1'); //传入普通需求,检查计算前后预计工时变化。
r($story->computeEstimateTest(2)) && p('old,new') && e('2,8'); //传入父需求,检查计算前后预计工时变化。
r($story->computeEstimateTest(3)) && p('old,new') && e('3,3'); //传入子需求,检查计算前后预计工时变化。
r($story->computeEstimateTest(10)) && p() && e('0'); //传入不存在的需求。
+7 -3
View File
@@ -239,15 +239,19 @@ class storyTest
*
* @param int $storyID
* @access public
* @return void
* @return array
*/
public function computeEstimateTest($storyID)
public function computeEstimateTest(int $storyID): array
{
$oldStory = $this->objectModel->getByID($storyID);
if(empty($oldStory)) return array();
$this->objectModel->computeEstimate($storyID);
if(dao::isError()) return dao::getError();
return $this->objectModel->getByID($storyID);
$newStory = $this->objectModel->getByID($storyID);
return array('old' => $oldStory->estimate, 'new' => $newStory->estimate);
}
/**