From 19c88ede74e7d7849b2a90802fc32b137f643f6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E6=80=A1=E6=A0=8B?= Date: Mon, 8 Nov 2021 11:05:12 +0800 Subject: [PATCH] * adjust for remove deleted data. --- module/report/model.php | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/module/report/model.php b/module/report/model.php index 6c25d1865a..88b98130c5 100644 --- a/module/report/model.php +++ b/module/report/model.php @@ -1074,13 +1074,15 @@ class reportModel extends model */ public function getOutput4API($accounts, $year) { - $stmt = $this->dao->select('*')->from(TABLE_ACTION) + $stmt = $this->dao->select('id,objectType,objectID,action,extra')->from(TABLE_ACTION) ->where('objectType')->in(array_keys($this->config->report->outputData)) ->andWhere('LEFT(date, 4)')->eq($year) ->beginIF($accounts)->andWhere('actor')->in($accounts)->fi() ->query(); - $outputData = array(); + $outputData = array(); + $actionGroup = array(); + $objectIdList = array(); while($action = $stmt->fetch()) { if($action->objectType == 'release' and $action->action == 'changestatus') @@ -1088,11 +1090,24 @@ class reportModel extends model if($action->extra == 'terminate') $action->action = 'stoped'; if($action->extra == 'normal') $action->action = 'activated'; } + unset($action->extra); if(!isset($this->config->report->outputData[$action->objectType][$action->action])) continue; - if(!isset($outputData[$action->objectType][$action->action])) $outputData[$action->objectType][$action->action] = 0; - $outputData[$action->objectType][$action->action] += 1; + if(!isset($outputData[$action->objectType][$action->action])) $outputData[$action->objectType][$action->action] = 0; + $objectIdList[$action->objectType][$action->objectID] = $action->objectID; + $actionGroup[$action->objectType][$action->id] = $action; + } + + foreach($actionGroup as $objectType => $actions) + { + $deletedIdList = $this->dao->select('id')->from($this->config->objectTables[$objectType])->where('deleted')->eq(1)->andWhere('id')->in($objectIdList[$objectType])->fetchPairs('id', 'id'); + + foreach($actions as $action) + { + if(isset($deletedIdList[$action->objectID])) continue; + $outputData[$action->objectType][$action->action] += 1; + } } $stmt = $this->dao->select('t1.*')->from(TABLE_ACTION)->alias('t1')