From e00adfb629b4860e91f368bf92b5d8a8e8933154 Mon Sep 17 00:00:00 2001 From: tianshujie Date: Wed, 28 May 2025 10:17:45 +0800 Subject: [PATCH] * [task#144204,done,0.5h] optimize compute delay logic for task list. --- module/execution/js/task.ui.js | 2 +- module/execution/model.php | 4 +--- module/programplan/model.php | 7 ++---- module/task/model.php | 43 +++++++++++++++++++++++++++------- 4 files changed, 39 insertions(+), 17 deletions(-) diff --git a/module/execution/js/task.ui.js b/module/execution/js/task.ui.js index b1b0ef6041..76cd4b08cb 100644 --- a/module/execution/js/task.ui.js +++ b/module/execution/js/task.ui.js @@ -132,7 +132,7 @@ window.renderCell = function(result, info) if(task.color) result[0].props.style = 'color: ' + task.color; if(html) result.unshift({html}); - if(typeof task.delay != 'undefined' && task.delay && !['done', 'cancel', 'close'].includes(task.rawStatus)) + if(typeof task.delay != 'undefined' && task.delay > 0) { result[result.length] = { html: '' + delayWarning.replace('%s', task.delay) + '', className: 'flex items-end', style: { flexDirection: "column" } }; } diff --git a/module/execution/model.php b/module/execution/model.php index 42f84d57ee..f3e39f5d16 100755 --- a/module/execution/model.php +++ b/module/execution/model.php @@ -1985,9 +1985,7 @@ class executionModel extends model ->orderBy('t1.order_asc, t1.id_desc') ->fetchGroup('execution', 'id'); - $today = helper::today(); - $begin = $today; - $end = $today; + $today = $begin = $end = helper::today(); $taskIdList = array(); foreach($executionTasks as $tasks) { diff --git a/module/programplan/model.php b/module/programplan/model.php index 738ca4ab98..489b951ae9 100755 --- a/module/programplan/model.php +++ b/module/programplan/model.php @@ -876,9 +876,7 @@ class programplanModel extends model $isGantt = $this->app->rawModule == 'programplan' && $this->app->rawMethod == 'browse'; if($isGantt) $plans = $this->loadModel('execution')->getByIdList($planIdList); - $today = helper::today(); - $begin = $today; - $end = $today; + $today = $begin = $end = helper::today(); $deadlineList = array(); foreach($tasks as $taskID => $task) { @@ -911,8 +909,7 @@ class programplanModel extends model if($isComputeDelay) { $endDate = helper::isZeroDate($task->finishedDate) ? $today : $task->finishedDate; - $deadline = $deadlineList[$taskID]; - $betweenDays = $this->holiday->getDaysBetween($deadline, $endDate); + $betweenDays = $this->holiday->getDaysBetween($deadlineList[$taskID], $endDate); if($betweenDays) { $delayDays = array_intersect($betweenDays, $workingDays); diff --git a/module/task/model.php b/module/task/model.php index ab8dc5508a..a9dbce2d1d 100755 --- a/module/task/model.php +++ b/module/task/model.php @@ -2759,20 +2759,31 @@ class taskModel extends model * * @param object $task * @param bool $convertParent + * @param array $workingDays * @access public * @return object */ - public function processTask(object $task, bool $convertParent = true): object + public function processTask(object $task, bool $convertParent = true, array $workingDays = array()): object { $today = helper::today(); /* Delayed or not?. */ - if(!empty($task->deadline) && !helper::isZeroDate($task->deadline)) + $this->loadModel('holiday'); + + $task->delay = 0; + $isNotCancel = !in_array($task->status, array('cancel', 'closed')) || ($task->status == 'closed' && !helper::isZeroDate($task->finishedDate) && $task->closedReason != 'cancel'); + $isComputeDelay = $isNotCancel && !helper::isZeroDate($task->deadline); + $workingDays = empty($workingDays) && $isComputeDelay ? $this->holiday->getActualWorkingDays($task->deadline, $today) : $workingDays; + if($isComputeDelay) { - $finishedDate = ($task->status == 'done' || $task->status == 'closed') && !helper::isZeroDate($task->finishedDate) ? substr($task->finishedDate, 0, 10) : $today; - $actualDays = $this->loadModel('holiday')->getActualWorkingDays($task->deadline, $finishedDate); - $delay = !is_array($actualDays) ? 0 : count($actualDays) - 1; - if($delay > 0 && !in_array($task->status, array('done', 'closed', 'cancel'))) $task->delay = $delay; + $endDate = helper::isZeroDate($task->finishedDate) ? $today : $task->finishedDate; + $betweenDays = $this->holiday->getDaysBetween($task->deadline, $endDate); + if($betweenDays) + { + $delayDays = array_intersect($betweenDays, $workingDays); + $delay = !empty($delayDays) ? count($delayDays) - 1: 0; + if($delay > 0) $task->delay = $delay; + } } /* Story changed or not. */ @@ -2850,15 +2861,31 @@ class taskModel extends model */ public function processTasks(array $tasks): array { + $today = $begin = $end = helper::today(); + foreach($tasks as $taskID => $task) + { + if(helper::isZeroDate($task->deadline)) continue; + $begin = $task->deadline < $begin ? $task->deadline : $begin; + if(!empty($task->children)) + { + foreach($task->children as $child) + { + if(helper::isZeroDate($child->deadline)) continue; + $begin = $child->deadline < $begin ? $child->deadline : $begin; + } + } + } + + $workingDays = $this->loadModel('holiday')->getActualWorkingDays($begin, $end); $storyVersionPairs = $this->getTeamStoryVersion(array_keys($tasks)); foreach($tasks as &$task) { $task->storyVersion = zget($storyVersionPairs, $task->id, $task->storyVersion); - $task = $this->processTask($task, false); + $task = $this->processTask($task, false, $workingDays); if(!empty($task->children)) { - foreach($task->children as &$child) $child = $this->processTask($child, false); + foreach($task->children as &$child) $child = $this->processTask($child, false, $workingDays); } }