* Refactor getStoryTaskCounts method of task module.

This commit is contained in:
tianshujie
2023-06-01 09:26:42 +08:00
parent b6400ba020
commit 36e1916836
4 changed files with 43 additions and 36 deletions
+7 -4
View File
@@ -1695,23 +1695,26 @@ class taskModel extends model
}
/**
* Get counts of some stories' tasks.
* 获取关联需求的任务数。
* Get the number of tasks linked with the story.
*
* @param array $stories
* @param int $executionID
* @access public
* @return int
* @return array
*/
public function getStoryTaskCounts($stories, $executionID = 0)
public function getStoryTaskCounts(array $stories, int $executionID = 0): array
{
if(empty($stories)) return array();
$taskCounts = $this->dao->select('story, COUNT(*) AS tasks')
$taskCounts = $this->dao->select('story, COUNT(id) AS tasks')
->from(TABLE_TASK)
->where('story')->in($stories)
->andWhere('deleted')->eq(0)
->beginIF($executionID)->andWhere('execution')->eq($executionID)->fi()
->groupBy('story')
->fetchPairs();
foreach($stories as $storyID)
{
if(!isset($taskCounts[$storyID])) $taskCounts[$storyID] = 0;
+18 -11
View File
@@ -1,24 +1,31 @@
#!/usr/bin/env php
<?php
include dirname(__FILE__, 5) . '/test/lib/init.php';
include dirname(__FILE__, 2) . '/task.class.php';
su('admin');
zdTable('task')->config('task')->gen(10);
/**
title=taskModel->getStoryTaskCounts();
timeout=0
cid=1
pid=1
根据需求1查看任务数量 >> 6
根据需求5查看任务数量 >> 6
根据需求9查看任务数量 >> 6
*/
$storyIDList = array('1','5','9');
$storyIdList = array(array(), array(1, 2, 3), array(4), array(1, 2, 3, 4));
$executionIdList = array(2, 3);
$task = new taskTest();
r($task->getStoryTaskCountsTest($storyIDList)) && p('1') && e('6'); // 根据需求1查看任务数量
r($task->getStoryTaskCountsTest($storyIDList)) && p('5') && e('6'); // 根据需求5查看任务数量
r($task->getStoryTaskCountsTest($storyIDList)) && p('9') && e('6'); // 根据需求9查看任务数量
$taskModel = $tester->loadModel('task');
r($taskModel->getStoryTaskCounts($storyIdList[0])) && p() && e('0'); // 测试传入空数据
r($taskModel->getStoryTaskCounts($storyIdList[1])) && p('2') && e('2'); // 测试获取所有关联需求1、2、3的任务数量
r($taskModel->getStoryTaskCounts($storyIdList[2])) && p('4') && e('0'); // 测试获取所有关联需求4的任务数量
r($taskModel->getStoryTaskCounts($storyIdList[3])) && p('3') && e('2'); // 测试获取所有关联需求1、2、3、4的任务数量
r($taskModel->getStoryTaskCounts($storyIdList[0], $executionIdList[0])) && p() && e('0'); // 测试执行ID为2需求为空数组的任务数量
r($taskModel->getStoryTaskCounts($storyIdList[1], $executionIdList[0])) && p('1') && e('1'); // 测试执行ID为2需求为1、2、3的任务数量
r($taskModel->getStoryTaskCounts($storyIdList[2], $executionIdList[0])) && p('4') && e('0'); // 测试执行ID为2需求为4的任务数量
r($taskModel->getStoryTaskCounts($storyIdList[3], $executionIdList[0])) && p('2') && e('1'); // 测试执行ID为2需求为1、2、3、4的任务数量
r($taskModel->getStoryTaskCounts($storyIdList[1], $executionIdList[1])) && p('2') && e('1'); // 测试执行ID为3需求为1、2、3的任务数量
r($taskModel->getStoryTaskCounts($storyIdList[2], $executionIdList[1])) && p('4') && e('0'); // 测试执行ID为3需求为4的任务数量
r($taskModel->getStoryTaskCounts($storyIdList[3], $executionIdList[1])) && p('2') && e('1'); // 测试执行ID为3需求为1、2、3、4的任务数量
+18
View File
@@ -0,0 +1,18 @@
title: zt_task
author: Tian Shujie
version: "1.0"
fields:
- field: id
range: 1-10
- field: story
range: 0-3
- field: type
range: design,devel,test,study,discuss,ui,affair,misc
- field: status
range: wait
- field: execution
range: "2{5},3{5}"
- field: deleted
range: 0{4},1
- field: vision
range: rnd
-21
View File
@@ -606,27 +606,6 @@ class taskTest
}
}
/**
* Test get counts of some stories' tasks.
*
* @param array $storyIDList
* @access public
* @return int
*/
public function getStoryTaskCountsTest($storyIDList)
{
$object = $this->objectModel->getStoryTaskCounts($storyIDList);
if(dao::isError())
{
$error = dao::getError();
return $error;
}
else
{
return $object;
}
}
/**
* Test get task efforts.
*