From c2299ef9bf98400faa90ad16cc8d296e89580f85 Mon Sep 17 00:00:00 2001 From: qixinzhi Date: Wed, 22 May 2024 08:54:06 +0000 Subject: [PATCH] * Optimize sql of dynamic pivot. --- module/bi/config/pivots.php | 44 ++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/module/bi/config/pivots.php b/module/bi/config/pivots.php index b136e24fd3..a49aa79bbe 100644 --- a/module/bi/config/pivots.php +++ b/module/bi/config/pivots.php @@ -1596,7 +1596,49 @@ $config->bi->builtin->pivots[] = array 'dimension' => '1', 'group' => '62', 'sql' => <<=\$startDate) and if(\$endDate='',1,t1.day<=\$endDate) +select + t1.day, + sum(t1.userlogin) as userlogin, + sum(t1.consumed) as consumed, + sum(t1.storyopen) as storyopen, + sum(t1.storyclose) as storyclose, + sum(t1.taskopen) as taskopen, + sum(t1.taskfinish) as taskfinish, + sum(t1.bugopen) as bugopen, + sum(t1.bugresolve) as bugresolve, + sum(t1.actions) as actions +from ( + select + left(`zt_action`.`date`, 10) as day, + count(case when `zt_action`.`objectType` = 'user' and `zt_action`.`action` = 'login' then 1 end) as userlogin, + 0 as consumed, + count(case when `zt_action`.`objectType` = 'story' and `zt_action`.`action` = 'opened' then 1 end) as storyopen, + count(case when `zt_action`.`objectType` = 'story' and `zt_action`.`action` = 'closed' then 1 end) as storyclose, + count(case when `zt_action`.`objectType` = 'task' and `zt_action`.`action` = 'opened' then 1 end) as taskopen, + count(case when `zt_action`.`objectType` = 'task' and `zt_action`.`action` = 'finished' then 1 end) as taskfinish, + count(case when `zt_action`.`objectType` = 'bug' and `zt_action`.`action` = 'opened' then 1 end) as bugopen, + count(case when `zt_action`.`objectType` = 'bug' and `zt_action`.`action` = 'resolved' then 1 end) as bugresolve, + count(*) as actions + from `zt_action` + where if(\$startDate='',1,`zt_action`.`date`>=\$startDate) and if(\$endDate='',1,`zt_action`.`date`<=\$endDate) + group by left(`zt_action`.`date`, 10) + union all + select + `zt_effort`.`date` as day, + 0 as userlogin, + round(sum(`zt_effort`.`consumed`), 1) as consumed, + 0 as storyopen, + 0 as storyclose, + 0 as taskopen, + 0 as taskfinish, + 0 as bugopen, + 0 as bugresolve, + 0 as actions + from `zt_effort` + where if(\$startDate='',1,`zt_effort`.`date`>=\$startDate) and if(\$endDate='',1,`zt_effort`.`date`<=\$endDate) + group by `zt_effort`.`date` +) as t1 +group by t1.day EOT, 'settings' => array (