diff --git a/module/holiday/model.php b/module/holiday/model.php index 2ee48c7d43..2bc88080a4 100644 --- a/module/holiday/model.php +++ b/module/holiday/model.php @@ -382,6 +382,7 @@ class holidayModel extends model } /** + * 更新任务的实际工期。 * Update task real duration. * * @param string $beginDate @@ -389,7 +390,7 @@ class holidayModel extends model * @access public * @return void */ - public function updateTaskRealDuration($beginDate, $endDate) + public function updateTaskRealDuration(string $beginDate, string $endDate): void { $updateTaskList = $this->dao->select('id, realStarted, finishedDate') ->from(TABLE_TASK) @@ -401,7 +402,7 @@ class holidayModel extends model foreach($updateTaskList as $task) { - $realDuration = $this->getActualWorkingDays($task->realStarted, date('Y-m-d',strtotime($task->finishedDate))); + $realDuration = $this->getActualWorkingDays($task->realStarted, date('Y-m-d', $task->finishedDate ? strtotime($task->finishedDate) : time())); $realDuration = count($realDuration); $this->dao->update(TABLE_TASK)->set('realDuration')->eq($realDuration)->where('id')->eq($task->id)->exec(); diff --git a/module/holiday/test/holiday.class.php b/module/holiday/test/holiday.class.php index 7cc757f01b..383296e560 100644 --- a/module/holiday/test/holiday.class.php +++ b/module/holiday/test/holiday.class.php @@ -309,7 +309,7 @@ class holidayTest * Test update task plan duration. * * @param int $testTaskID - * @param int $holiday + * @param int $holidayID * @param bool $updateDuration * @access public * @return int|array @@ -332,20 +332,24 @@ class holidayTest } /** - * Test updateTaskRealDuration method. + * 测试更新任务实际工期。 + * Test update task real duration. * * @param int $testTaskID - * @param object $holiday + * @param int $holidayID + * @param bool $updateDuration * @access public - * @return int + * @return int|array */ - public function updateTaskRealDurationTest($testTaskID, $holidayID) + public function updateTaskRealDurationTest(int $testTaskID, int $holidayID, bool $updateDuration): int|array { global $tester; - $holiday = $tester->dao->select('*')->from(TABLE_HOLIDAY)->where('id')->eq($holidayID)->fetch(); - - $this->objectModel->updateTaskRealDuration($holiday->begin, $holiday->end); + if($updateDuration) + { + $holiday = $tester->dao->select('*')->from(TABLE_HOLIDAY)->where('id')->eq($holidayID)->fetch(); + $this->objectModel->updateTaskRealDuration($holiday->begin, $holiday->end); + } $task = $tester->dao->select('*')->from(TABLE_TASK)->where('id')->eq($testTaskID)->fetch(); diff --git a/module/holiday/test/model/updatetaskrealduration.php b/module/holiday/test/model/updatetaskrealduration.php new file mode 100755 index 0000000000..1e06ce8b27 --- /dev/null +++ b/module/holiday/test/model/updatetaskrealduration.php @@ -0,0 +1,39 @@ +#!/usr/bin/env php +gen(10); +zdTable('task')->config('task')->gen(10); +zdTable('user')->gen(1); + +su('admin'); + +/** + +title=测试 holidayModel->updateTaskRealDurationTest(); +cid=1 +pid=1 + +*/ + +$holiday = new holidayTest(); + +$holidayIdList = array(10, 5, 1); +$taskIdList = array(1, 2, 3); +$updateDuration = array(true, false); + +$holiday = new holidayTest(); + +r($holiday->updateTaskRealDurationTest($taskIdList[0], $holidayIdList[0], $updateDuration[0])) && p() && e('1'); //测试插入id为 10 的节假日时任务 1 任务的计划工期 +r($holiday->updateTaskRealDurationTest($taskIdList[1], $holidayIdList[0], $updateDuration[1])) && p() && e('1'); //测试插入id为 10 的节假日时任务 2 任务的计划工期 +r($holiday->updateTaskRealDurationTest($taskIdList[2], $holidayIdList[0], $updateDuration[1])) && p() && e('6'); //测试插入id为 10 的节假日时任务 3 任务的计划工期 + +r($holiday->updateTaskRealDurationTest($taskIdList[0], $holidayIdList[1], $updateDuration[0])) && p() && e('1'); //测试插入id为 5 的节假日时任务 1 任务的计划工期 +r($holiday->updateTaskRealDurationTest($taskIdList[1], $holidayIdList[1], $updateDuration[1])) && p() && e('5'); //测试插入id为 5 的节假日时任务 2 任务的计划工期 +r($holiday->updateTaskRealDurationTest($taskIdList[2], $holidayIdList[1], $updateDuration[1])) && p() && e('6'); //测试插入id为 5 的节假日时任务 3 任务的计划工期 + +r($holiday->updateTaskRealDurationTest($taskIdList[0], $holidayIdList[2], $updateDuration[0])) && p() && e('6'); //测试插入id为 5 的节假日时任务 1 任务的计划工期 +r($holiday->updateTaskRealDurationTest($taskIdList[1], $holidayIdList[2], $updateDuration[1])) && p() && e('5'); //测试插入id为 5 的节假日时任务 2 任务的计划工期 +r($holiday->updateTaskRealDurationTest($taskIdList[2], $holidayIdList[2], $updateDuration[1])) && p() && e('6'); //测试插入id为 5 的节假日时任务 3 任务的计划工期 diff --git a/module/holiday/test/yaml/task.yaml b/module/holiday/test/yaml/task.yaml index 1719b88407..581720f3d5 100644 --- a/module/holiday/test/yaml/task.yaml +++ b/module/holiday/test/yaml/task.yaml @@ -13,3 +13,13 @@ fields: type: timestamp format: "YY/MM/DD" postfix: "\t" + - field: realStarted + range: "(-5w)-(+1w):5D" + type: timestamp + format: "YY/MM/DD" + postfix: "\t" + - field: finishedDate + range: "(-4w)-(+2w):5D" + type: timestamp + format: "YY/MM/DD" + postfix: "\t"