* Refactor reportModel::getUserYearProducts, and modify its unit test.
This commit is contained in:
+4
-70
@@ -357,84 +357,18 @@ class reportModel extends model
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户某年的产品下创建的需求、计划,创建和关闭的需求数量统计。
|
||||
* Get count of created story,plan and closed story by accounts every product in this year.
|
||||
*
|
||||
* @param array $accounts
|
||||
* @param int $year
|
||||
* @param string $year
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function getUserYearProducts($accounts, $year)
|
||||
public function getUserYearProducts(array $accounts, string $year): array
|
||||
{
|
||||
/* Get changed products in this year. */
|
||||
$products = $this->dao->select('id,name')->from(TABLE_PRODUCT)
|
||||
->where('deleted')->eq(0)
|
||||
->andWhere('LEFT(createdDate, 4)')->eq($year)
|
||||
->beginIF($accounts)
|
||||
->andWhere('createdBy', true)->in($accounts)
|
||||
->orWhere('PO')->in($accounts)
|
||||
->orWhere('QD')->in($accounts)
|
||||
->orWhere('RD')->in($accounts)
|
||||
->markRight(1)
|
||||
->fi()
|
||||
->andWhere('shadow')->eq(0)
|
||||
->fetchAll('id');
|
||||
|
||||
/* Get created plans in this year. */
|
||||
$plans = $this->dao->select('t1.id,t1.product')->from(TABLE_PRODUCTPLAN)->alias('t1')
|
||||
->leftJoin(TABLE_ACTION)->alias('t2')->on("t1.id=t2.objectID and t2.objectType='productplan'")
|
||||
->where('LEFT(t2.date, 4)')->eq($year)
|
||||
->andWhere('t1.deleted')->eq(0)
|
||||
->andWhere('t1.product')->in(array_keys($products))
|
||||
->beginIF($accounts)
|
||||
->andWhere('t2.actor')->in($accounts)
|
||||
->fi()
|
||||
->andWhere('t2.action')->eq('opened')
|
||||
->fetchAll();
|
||||
|
||||
$planProducts = array();
|
||||
$planGroups = array();
|
||||
foreach($plans as $plan)
|
||||
{
|
||||
$planProducts[$plan->product] = $plan->product;
|
||||
$planGroups[$plan->product][$plan->id] = $plan->id;
|
||||
}
|
||||
|
||||
$createStoryProducts = $this->dao->select('DISTINCT product')->from(TABLE_STORY)
|
||||
->where('LEFT(openedDate, 4)')->eq($year)
|
||||
->andWhere('deleted')->eq(0)
|
||||
->andWhere('product')->in(array_keys($products))
|
||||
->beginIF($accounts)->andWhere('openedBy')->in($accounts)->fi()
|
||||
->fetchPairs('product', 'product');
|
||||
$closeStoryProducts = $this->dao->select('DISTINCT product')->from(TABLE_STORY)
|
||||
->where('LEFT(closedDate, 4)')->eq($year)
|
||||
->andWhere('deleted')->eq(0)
|
||||
->andWhere('product')->in(array_keys($products))
|
||||
->beginIF($accounts)->andWhere('closedBy')->in($accounts)->fi()
|
||||
->fetchPairs('product', 'product');
|
||||
if($createStoryProducts or $closeStoryProducts)
|
||||
{
|
||||
$products += $this->dao->select('id,name')->from(TABLE_PRODUCT)
|
||||
->where('id')->in($createStoryProducts + $closeStoryProducts + $planProducts)
|
||||
->andWhere('deleted')->eq(0)
|
||||
->fetchAll('id');
|
||||
}
|
||||
|
||||
$createdStoryStats = $this->dao->select("product,sum(if((type = 'requirement'), 1, 0)) as requirement, sum(if((type = 'story'), 1, 0)) as story")->from(TABLE_STORY)
|
||||
->where('product')->in(array_keys($products))
|
||||
->andWhere('deleted')->eq(0)
|
||||
->andWhere('LEFT(openedDate, 4)')->eq($year)
|
||||
->beginIF($accounts)->andWhere('openedBy')->in($accounts)->fi()
|
||||
->groupBy('product')
|
||||
->fetchAll('product');
|
||||
|
||||
$closedStoryStats = $this->dao->select("product,sum(if((status = 'closed'), 1, 0)) as closed")->from(TABLE_STORY)
|
||||
->where('product')->in(array_keys($products))
|
||||
->andWhere('deleted')->eq(0)
|
||||
->andWhere('LEFT(closedDate, 4)')->eq($year)
|
||||
->beginIF($accounts)->andWhere('closedBy')->in($accounts)->fi()
|
||||
->groupBy('product')
|
||||
->fetchAll('product');
|
||||
list($products, $planGroups, $createdStoryStats, $closedStoryStats) = $this->reportTao->getAnnualProductStat($accounts, $year);
|
||||
|
||||
/* Merge created plan, created story and closed story in every product. */
|
||||
foreach($products as $productID => $product)
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* The tao file of report module of ZenTaoPMS.
|
||||
*
|
||||
* @copyright Copyright 2009-2023 禅道软件(青岛)有限公司(ZenTao Software (Qingdao) Co., Ltd. www.zentao.net)
|
||||
* @license ZPL(https://zpl.pub/page/zplv12.html) or AGPL(https://www.gnu.org/licenses/agpl-3.0.en.html)
|
||||
* @author Mengyi Liu <liumengyi@easycorp.ltd>
|
||||
* @package report
|
||||
* @link https://www.zentao.net
|
||||
*/
|
||||
class reportTao extends reportModel
|
||||
{
|
||||
/**
|
||||
* 获取某年的年度产品数据。
|
||||
* Get annual product stat.
|
||||
*
|
||||
* @param array $accounts
|
||||
* @param string $year
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
protected function getAnnualProductStat(array $accounts, string $year): array
|
||||
{
|
||||
/* Get created plans, created stories and closed stories in this year. */
|
||||
$planGroups = $this->dao->select('t1.id,t1.product')->from(TABLE_PRODUCTPLAN)->alias('t1')
|
||||
->leftJoin(TABLE_ACTION)->alias('t2')->on("t1.id=t2.objectID and t2.objectType='productplan'")
|
||||
->where('t1.deleted')->eq(0)
|
||||
->andWhere('LEFT(t2.date, 4)')->eq($year)
|
||||
->beginIF($accounts)->andWhere('t2.actor')->in($accounts)->fi()
|
||||
->andWhere('t2.action')->eq('opened')
|
||||
->fetchGroup('product', 'id');
|
||||
$createdStoryStats = $this->dao->select("product,sum(if((type = 'requirement'), 1, 0)) as requirement, sum(if((type = 'story'), 1, 0)) as story")->from(TABLE_STORY)
|
||||
->where('deleted')->eq(0)
|
||||
->andWhere('LEFT(openedDate, 4)')->eq($year)
|
||||
->beginIF($accounts)->andWhere('openedBy')->in($accounts)->fi()
|
||||
->groupBy('product')
|
||||
->fetchAll('product');
|
||||
$closedStoryStats = $this->dao->select("product,sum(if((status = 'closed'), 1, 0)) as closed")->from(TABLE_STORY)
|
||||
->where('deleted')->eq(0)
|
||||
->andWhere('LEFT(closedDate, 4)')->eq($year)
|
||||
->beginIF($accounts)->andWhere('closedBy')->in($accounts)->fi()
|
||||
->groupBy('product')
|
||||
->fetchAll('product');
|
||||
|
||||
/* Get products created or operated in this year. */
|
||||
$products = $this->dao->select('id,name')->from(TABLE_PRODUCT)
|
||||
->where('deleted')->eq(0)
|
||||
->andWhere('LEFT(createdDate, 4)', true)->eq($year)
|
||||
->beginIF($accounts)
|
||||
->andWhere('createdBy', true)->in($accounts)
|
||||
->orWhere('PO')->in($accounts)
|
||||
->orWhere('QD')->in($accounts)
|
||||
->orWhere('RD')->in($accounts)
|
||||
->markRight(1)
|
||||
->fi()
|
||||
->orWhere('id')->in(array_merge(array_keys($planGroups), array_keys($createdStoryStats), array_keys($closedStoryStats)))
|
||||
->markRight(1)
|
||||
->andWhere('shadow')->eq(0)
|
||||
->fetchAll('id');
|
||||
|
||||
return array($products, $planGroups, $createdStoryStats, $closedStoryStats);
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,15 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
include dirname(__FILE__, 5) . '/test/lib/init.php';
|
||||
include dirname(__FILE__, 2) . '/report.class.php';
|
||||
su('po1');
|
||||
|
||||
zdTable('product')->gen(20);
|
||||
zdTable('story')->gen(20);
|
||||
zdTable('productplan')->gen(20);
|
||||
zdTable('user')->gen(1);
|
||||
|
||||
su('admin');
|
||||
|
||||
/**
|
||||
|
||||
@@ -10,19 +17,14 @@ title=测试 reportModel->getUserYearProducts();
|
||||
cid=1
|
||||
pid=1
|
||||
|
||||
测试获取本年度 po1 的产品数 >> 1,11,21,31,41,51,61,71,81,91,101,111
|
||||
测试获取本年度 dev17 的产品数 >> 17,117
|
||||
测试获取本年度 test18 的产品数 >> 18,118
|
||||
测试获取本年度 po1 dev17 的产品数 >> 1,11,17,21,31,41,51,61,71,81,91,101,111,117
|
||||
测试获取本年度 po1 test18 的产品数 >> 1,11,18,21,31,41,51,61,71,81,91,101,111,118
|
||||
|
||||
*/
|
||||
$account = array('po1', 'dev17', 'test18', 'po1,dev17', 'po1,test18');
|
||||
$account = array(array('admin'), array('dev17'), array('test18'), array('admin', 'dev17'), array('admin', 'test18'), array());
|
||||
|
||||
$report = new reportTest();
|
||||
|
||||
r($report->getUserYearProductsTest($account[0])) && p() && e('1,11,21,31,41,51,61,71,81,91,101,111'); // 测试获取本年度 po1 的产品数
|
||||
r($report->getUserYearProductsTest($account[1])) && p() && e('17,117'); // 测试获取本年度 dev17 的产品数
|
||||
r($report->getUserYearProductsTest($account[2])) && p() && e('18,118'); // 测试获取本年度 test18 的产品数
|
||||
r($report->getUserYearProductsTest($account[3])) && p() && e('1,11,17,21,31,41,51,61,71,81,91,101,111,117'); // 测试获取本年度 po1 dev17 的产品数
|
||||
r($report->getUserYearProductsTest($account[4])) && p() && e('1,11,18,21,31,41,51,61,71,81,91,101,111,118'); // 测试获取本年度 po1 test18 的产品数
|
||||
r($report->getUserYearProductsTest($account[0])) && p() && e('1,2,3,4,5'); // 测试获取本年度 admin 的产品数
|
||||
r($report->getUserYearProductsTest($account[1])) && p() && e('17'); // 测试获取本年度 dev17 的产品数
|
||||
r($report->getUserYearProductsTest($account[2])) && p() && e('1,18'); // 测试获取本年度 test18 的产品数
|
||||
r($report->getUserYearProductsTest($account[3])) && p() && e('1,2,3,4,5,17'); // 测试获取本年度 admin dev17 的产品数
|
||||
r($report->getUserYearProductsTest($account[4])) && p() && e('1,2,3,4,5,18'); // 测试获取本年度 admin test18 的产品数
|
||||
r($report->getUserYearProductsTest($account[5])) && p() && e('1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20'); // 测试获取本年度 所有用户 的产品数
|
||||
|
||||
@@ -394,17 +394,16 @@ class reportTest
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试获取本年度用户相关的每个产品的创建的需求和计划,关闭的需求数据。
|
||||
* Test get count of created story,plan and closed story by accounts every product in this year.
|
||||
*
|
||||
* @param mixed $accounts
|
||||
* @param array $accounts
|
||||
* @access public
|
||||
* @return void
|
||||
* @return string|array
|
||||
*/
|
||||
public function getUserYearProductsTest($accounts)
|
||||
public function getUserYearProductsTest(array $accounts): string|array
|
||||
{
|
||||
$year = date('Y');
|
||||
|
||||
$objects = $this->objectModel->getUserYearProducts($accounts, $year);
|
||||
$objects = $this->objectModel->getUserYearProducts($accounts, date('Y'));
|
||||
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user