This commit is contained in:
jukui
2023-05-08 16:27:02 +08:00
3 changed files with 57 additions and 28 deletions
+13 -11
View File
@@ -1471,31 +1471,33 @@ class programplanModel extends model
* @access public
* @return void
*/
public function computeProgress($stageID, $action = '', $isParent = false)
public function computeProgress(int $stageID, string $action = '', bool $isParent = false)
{
$stage = $this->loadModel('execution')->getByID($stageID);
$project = $this->loadModel('project')->getByID($stage->project);
if(empty($stage) or empty($stage->path) or ($project->model != 'waterfall' and $project->model != 'waterfallplus')) return false;
$this->loadModel('execution');
$this->loadModel('project');
$this->loadModel('action');
$stage = $this->execution->getByID($stageID);
$project = $this->project->getByID($stage->project);
if(empty($stage) || empty($stage->path) || ($project->model != 'waterfall' && $project->model != 'waterfallplus')) return false;
$action = strtolower($action);
$parentIdList = explode(',', trim($stage->path, ','));
$parentIdList = array_reverse($parentIdList);
foreach($parentIdList as $id)
{
$parent = $this->execution->getByID($id);
if(empty($this->lang->execution->typeList[$parent->type]) or (!$isParent and $id == $stageID)) continue;
if(empty($this->lang->execution->typeList[$parent->type]) || (!$isParent && $id == $stageID)) continue;
$statusCount = array();
$children = $this->execution->getChildExecutions($parent->id);
$allChildren = $this->dao->select('id')->from(TABLE_EXECUTION)->where('deleted')->eq(0)->andWhere('path')->like("{$parent->path}%")->andWhere('id')->ne($id)->fetchPairs();
$startTasks = $this->dao->select('count(1) as count')->from(TABLE_TASK)->where('deleted')->eq(0)->andWhere('execution')->in($allChildren)->andWhere('consumed')->ne(0)->fetch('count');
foreach($children as $childID => $childExecution) $statusCount[$childExecution->status] = empty($statusCount[$childExecution->status]) ? 1 : $statusCount[$childExecution->status] ++;
foreach($children as $childExecution) $statusCount[$childExecution->status] = empty($statusCount[$childExecution->status]) ? 1 : $statusCount[$childExecution->status] ++;
if(empty($statusCount)) continue;
if(isset($statusCount['wait']) and count($statusCount) == 1 and helper::isZeroDate($parent->realBegan) and $startTasks == 0)
$count = count($statusCount);
if(isset($statusCount['wait']) && $count == 1 && helper::isZeroDate($parent->realBegan) && $startTasks == 0)
{
if($parent->status != 'wait')
{
@@ -1503,7 +1505,7 @@ class programplanModel extends model
$parentAction = 'waitbychild';
}
}
elseif(isset($statusCount['closed']) and count($statusCount) == 1)
elseif(isset($statusCount['closed']) && $count == 1)
{
if($parent->status != 'closed')
{
@@ -1511,7 +1513,7 @@ class programplanModel extends model
$parentAction = 'closedbychild';
}
}
elseif(isset($statusCount['suspended']) and (count($statusCount) == 1 or (isset($statusCount['closed']) and count($statusCount) == 2)))
elseif(isset($statusCount['suspended']) && ($count == 1 || (isset($statusCount['closed']) && $count == 2)))
{
if($parent->status != 'suspended')
{
@@ -1,23 +1,16 @@
#!/usr/bin/env php
<?php
include dirname(__FILE__, 5) . "/test/lib/init.php";
include dirname(__FILE__, 5) . '/test/lib/init.php';
include dirname(__FILE__, 2) . '/programplan.class.php';
zdTable('user')->gen(5);
function initData()
{
zdTable('user')->gen(5);
zdTable('project')->config('checkleafstage')->gen(5);
}
su('admin');
$execution = zdTable('project');
$execution->id->range('1-5');
$execution->name->range('瀑布项目1,阶段a,阶段a子1,阶段a子1子1,阶段b');
$execution->type->range('project,stage{4}');
$execution->project->range('0,1{4}');
$execution->parent->range('0,1,2,3,1');
$execution->path->range("`,1,`,`,1,2,`,`,1,2,3,`,`,1,2,3,4,`,`,1,5,`");
$execution->status->range('doing,doing,doing,closed,suspended');
$execution->openedBy->range('admin,user1');
$execution->begin->range('20220112 000000:0')->type('timestamp')->format('YY/MM/DD');
$execution->end->range('20220212 000000:0')->type('timestamp')->format('YY/MM/DD');
$execution->realBegan->range('20220212 000000:0')->type('timestamp')->format('YY/MM/DD');
$execution->gen(5);
/**
@@ -25,8 +18,9 @@ title=测试programplanModel->checkLeafStage();
cid=1
pid=1
测试id为2判断是否为叶子节点 >> 0
测试id为5判断是否为叶子节点 >> 1
- 测试id为2判断是否为叶子节点 @0
- 测试id为5判断是否为叶子节点 @1
*/
@@ -0,0 +1,33 @@
title: programplanModel::checkLeafStage UTC.
desc: programplanModel::checkLeafStage UTC.
author: xushenjie
version: '1.0'
fields:
- field: name
range: '瀑布项目1,阶段a,阶段a子1,阶段a子1子1,阶段b'
- field: type
range: '0,1{4}'
- field: project
range: '0,1{4}'
- field: parent
range: '0,1,2,3,1'
- field: grade
range: 1
- field: path
range: "`,1,`,`,1,2,`,`,1,2,3,`,`,1,2,3,4,`,`,1,5,`"
- field: status
range: 'doing,doing,doing,closed,suspended'
- field: openedBy
range: 'admin,user1'
- field: begin
range: '20230501 000000:0'
type: 'timestamp'
format: 'YY/MM/DD'
- field: end
range: '20300501 000000:0'
type: 'timestamp'
format: 'YY/MM/DD'
- field: realBegan
range: '20230501 000000:0'
type: 'timestamp'
format: 'YY/MM/DD'