diff --git a/db/pgsql_function.sql b/db/pgsql_function.sql index 12581e772d..303115fd2e 100644 --- a/db/pgsql_function.sql +++ b/db/pgsql_function.sql @@ -254,6 +254,21 @@ BEGIN RETURN (end_date - start_date)::INTEGER; END; $$ LANGUAGE plpgsql; +-- + +CREATE OR REPLACE FUNCTION IF( + condition BOOLEAN, + true_val BOOLEAN, + false_val BOOLEAN +) RETURNS BOOLEAN AS $$ +BEGIN + IF condition THEN + RETURN true_val; + ELSE + RETURN false_val; + END IF; +END; +$$ LANGUAGE plpgsql; -- diff --git a/module/bi/config/pivots.php b/module/bi/config/pivots.php index f9b77c85aa..764817a726 100644 --- a/module/bi/config/pivots.php +++ b/module/bi/config/pivots.php @@ -267,9 +267,9 @@ from zt_product as t1 select product, count(id) as bug, - sum(case when resolution in ('fixed', 'postponed') or status = 'active' then 1 else 0 end) as effbugs, - sum(case when resolution = 'fixed' then 1 else 0 end) as fixedbugs, - sum(case when severity IN (1, 2) then 1 else 0 end) as pri12bugs + sum(case when resolution in ('fixed', 'postponed') or status = 'active' then 1=1 else 0 end) as effbugs, + sum(case when resolution = 'fixed' then 1=1 else 0 end) as fixedbugs, + sum(case when severity IN (1, 2) then 1=1 else 0 end) as pri12bugs from zt_bug where deleted = '0' group by product @@ -374,7 +374,7 @@ $config->bi->builtin->pivots[] = array select t1.product, t2.name, - (case when t1.closedReason = 'done' or t1.stage = 'released' then 1 else 0 end) as done, + (case when t1.closedReason = 'done' or t1.stage = 'released' then 1=1 else 1=0 end) as done, 1 as count from zt_story as t1 left join zt_product as t2 on t1.product=t2.id left join zt_project as t3 on t2.program=t3.id @@ -687,7 +687,7 @@ select and t2.deadline is not null and t2.status != 'closed' and t2.status != 'done' - and t2.status != 'cancel' then 1 else 0 end + and t2.status != 'cancel' then 1=1 else 0 end ) as timeout from zt_project as t1 left join zt_task as t2 on t1.id=t2.execution @@ -909,7 +909,7 @@ and (case when \$executionStatus='' then 1=1 else t1.status=\$executionStatus en and (case when \$project='' then 1=1 else t4.id=\$project end) and (case when \$execution='' then 1=1 else t1.id=\$execution end) and (case when \$beginDate='' then 1=1 else t1.begin>=cast(\$beginDate as date) end) -and (case when \$endDate='' then 1 else t1.end<=cast(\$endDate as date) end) +and (case when \$endDate='' then 1=1 else t1.end<=cast(\$endDate as date) end) and not (\$projectStatus='' and \$executionStatus='' and \$project='' and \$beginDate='' and \$endDate) EOT, 'settings' => array @@ -1012,9 +1012,9 @@ and t2.deleted='0' and t2.finishedBy!='' and (case when \$projectStatus='' then 1=1 else t3.status=\$projectStatus end) and (case when \$executionStatus='' then 1=1 else t1.status=\$executionStatus end) -and (case when \$project='' then 1 else t3.id=\$project end) -and (case when \$dept='' then 1 else t4.dept=\$dept end) -and (case when \$user='' then 1 else t2.finishedBy=\$user end) +and (case when \$project='' then 1=1 else t3.id=\$project end) +and (case when \$dept='' then 1=1 else t4.dept=\$dept end) +and (case when \$user='' then 1=1 else t2.finishedBy=\$user end) and not (\$projectStatus='' and \$executionStatus='' and \$project='' and \$execution='' and \$dept='' and \$user='') EOT, 'settings' => array @@ -1832,10 +1832,10 @@ left join zt_bug as t2 on t1.id=t2.execution left join zt_project as t3 on t3.id=t1.project where t1.deleted='0' and t2.deleted='0' -and (case when \$projectStatus='' then 1 else t3.status=\$projectStatus end) -and (case when \$executionStatus='' then 1 else t1.status=\$executionStatus end) -and (case when \$project='' then 1 else t3.id=\$project end) -and (case when \$execution='' then 1 else t1.id=\$execution end) +and (case when \$projectStatus='' then 1=1 else t3.status=\$projectStatus end) +and (case when \$executionStatus='' then 1=1 else t1.status=\$executionStatus end) +and (case when \$project='' then 1=1 else t3.id=\$project end) +and (case when \$execution='' then 1=1 else t1.id=\$execution end) EOT, 'settings' => array ( @@ -1937,10 +1937,10 @@ left join zt_project as t5 on t5.id=t1.project where t1.deleted='0' and t1.type in ('sprint','stage') and t1.grade='1' -and (case when \$projectStatus='' then 1 else t5.status=\$projectStatus end) -and (case when \$executionStatus='' then 1 else t1.status=\$executionStatus end) -and (case when \$project='' then 1 else t5.id=\$project end) -and (case when \$execution='' then 1 else t1.id=\$execution end) +and (case when \$projectStatus='' then 1=1 else t5.status=\$projectStatus end) +and (case when \$executionStatus='' then 1=1 else t1.status=\$executionStatus end) +and (case when \$project='' then 1=1 else t5.id=\$project end) +and (case when \$execution='' then 1=1 else t1.id=\$execution end) EOT, 'settings' => array ( @@ -2449,7 +2449,7 @@ EOT, ( 'field' => 'consumed', 'object' => 'effort', - 'whereSql' => "left join zt_user as t2 on t1.account = t2.account left join zt_dept as t3 on t2.dept = t3.id where t1.`deleted` = '0' and (case when \$startDate='' then 1 else cast(t1.`date` as date) >= cast(\$startDate as date) end) and (case when \$endDate='' then 1 else cast(t1.`date` as date) <= cast(\$endDate as date) end) and (t3.path like concat((select path from zt_dept where id=\$dept), '%') or \$dept=0) order by t1.`date` asc", + 'whereSql' => "left join zt_user as t2 on t1.account = t2.account left join zt_dept as t3 on t2.dept = t3.id where t1.`deleted` = '0' and (case when \$startDate='' then 1=1 else cast(t1.`date` as date) >= cast(\$startDate as date) end) and (case when \$endDate='' then 1=1 else cast(t1.`date` as date) <= cast(\$endDate as date) end) and (t3.path like concat((select path from zt_dept where id=\$dept), '%') or \$dept=0) order by t1.`date` asc", 'condition' => array ( array('drillObject' => 'zt_effort', 'drillAlias' => 't1', 'drillField' => 'account', 'queryField' => 'account'), @@ -2659,9 +2659,9 @@ left join zt_product as t2 on t1.product = t2.id where t1.deleted='0' and t2.deleted='0' and t1.resolution!='' -and (case when \$startDate='' then 1 else cast(t1.resolvedDate as date)>=cast(\$startDate as date) end) -and (case when \$endDate='' then 1 else cast(t1.resolvedDate as date)<=cast(\$endDate as date) end) -and (case when \$product = '' then 1 else t1.product=\$product end) +and (case when \$startDate='' then 1=1 else cast(t1.resolvedDate as date)>=cast(\$startDate as date) end) +and (case when \$endDate='' then 1=1 else cast(t1.resolvedDate as date)<=cast(\$endDate as date) end) +and (case when \$product = '' then 1=1 else t1.product=\$product end) and not (\$product='' and \$startDate='' and \$endDate='') EOT, 'settings' => array @@ -2704,7 +2704,7 @@ EOT, ( 'field' => 'resolution', 'object' => 'bug', - 'whereSql' => "left join zt_product as t2 on t1.product = t2.id WHERE t1.deleted='0' AND t1.resolution!='' and (case when \$startDate='' then 1 else cast(t1.resolvedDate as date)>=cast(\$startDate as date) end) and (case when \$endDate='' then 1 else cast(t1.resolvedDate as date)<=cast(\$endDate as date) end) and (case when \$product = '' then 1 else t1.product=\$product end)", + 'whereSql' => "left join zt_product as t2 on t1.product = t2.id WHERE t1.deleted='0' AND t1.resolution!='' and (case when \$startDate='' then 1=1 else cast(t1.resolvedDate as date)>=cast(\$startDate as date) end) and (case when \$endDate='' then 1=1 else cast(t1.resolvedDate as date)<=cast(\$endDate as date) end) and (case when \$product = '' then 1=1 else t1.product=\$product end)", 'condition' => array ( array('drillObject' => 'zt_bug', 'drillAlias' => 't1', 'drillField' => 'resolvedBy', 'queryField' => 'resolvedBy'), @@ -2747,10 +2747,10 @@ left join ztv_projectstories as t3 on t1.id=t3.execution left join zt_project as t4 on t4.id=t1.project where t1.deleted='0' and t1.type in ('sprint','stage') -and (case when \$projectStatus='' then 1 else t4.status=\$projectStatus end) -and (case when \$executionStatus='' then 1 else t1.status=\$executionStatus end) -and (case when \$project='' then 1 else t4.id=\$project end) -and (case when \$execution='' then 1 else t1.id=\$execution end) +and (case when \$projectStatus='' then 1=1 else t4.status=\$projectStatus end) +and (case when \$executionStatus='' then 1=1 else t1.status=\$executionStatus end) +and (case when \$project='' then 1=1 else t4.id=\$project end) +and (case when \$execution='' then 1=1 else t1.id=\$execution end) EOT, 'settings' => array ( @@ -2912,10 +2912,10 @@ left join zt_bug as t2 on t1.id=t2.execution left join zt_project as t3 on t3.id=t1.project where t1.deleted='0' and t2.deleted='0' -and (case when \$projectStatus='' then 1 else t3.status=\$projectStatus end) -and (case when \$executionStatus='' then 1 else t1.status=\$executionStatus end) -and (case when \$project='' then 1 else t3.id=\$project end) -and (case when \$execution='' then 1 else t1.id=\$execution end) +and (case when \$projectStatus='' then 1=1 else t3.status=\$projectStatus end) +and (case when \$executionStatus='' then 1=1 else t1.status=\$executionStatus end) +and (case when \$project='' then 1=1 else t3.id=\$project end) +and (case when \$execution='' then 1=1 else t1.id=\$execution end) EOT, 'settings' => array ( @@ -3019,7 +3019,7 @@ EOT, ( array('from' => 'query', 'field' => 'productStatus', 'name' => '产品状态', 'type' => 'select', 'typeOption' => 'product.status', 'default' => 'normal'), array('from' => 'query', 'field' => 'productType', 'name' => '产品类型', 'type' => 'select', 'typeOption' => 'product.type', 'default' => 'normal'), - array('from' => 'query', 'field' => 'product', 'name' => '产品列表', 'type' => 'select', 'typeOption' => 'product', 'default' => '') + array('from' => 'query', 'field' => 'product', 'name' => '产品列表', 'type' => 'select', 'typeOption' => 'product', 'default' => '0') ), 'fields' => array ( @@ -3073,9 +3073,9 @@ left join zt_product as t2 on t1.product = t2.id where t1.deleted='0' and t2.deleted='0' and t1.resolution!='' -and (case when \$startDate='' then 1 else cast(t1.resolvedDate as date)>=cast(\$startDate as date) end) -and (case when \$endDate='' then 1 else cast(t1.resolvedDate as date)<=cast(\$endDate as date) end) -and (case when \$product = '' then 1 else t1.product=\$product end) +and (case when \$startDate='' then 1=1 else cast(t1.resolvedDate as date)>=cast(\$startDate as date) end) +and (case when \$endDate='' then 1=1 else cast(t1.resolvedDate as date)<=cast(\$endDate as date) end) +and (case when \$product = '' then 1=1 else t1.product=\$product end) and not (\$product='' and \$startDate='' and \$endDate='') EOT, 'settings' => array @@ -3118,7 +3118,7 @@ EOT, ( 'field' => 'resolution', 'object' => 'bug', - 'whereSql' => "left join zt_product as t2 on t1.product = t2.id WHERE t1.deleted='0' AND t1.resolution!='' and (case when \$startDate='' then 1 else cast(t1.resolvedDate as date)>=cast(\$startDate as date) end) and (case when \$endDate='' then 1 else cast(t1.resolvedDate as date)<=cast(\$endDate as date) end) and (case when \$product = '' then 1 else t1.product=\$product end)", + 'whereSql' => "left join zt_product as t2 on t1.product = t2.id WHERE t1.deleted='0' AND t1.resolution!='' and (case when \$startDate='' then 1=1 else cast(t1.resolvedDate as date)>=cast(\$startDate as date) end) and (case when \$endDate='' then 1=1 else cast(t1.resolvedDate as date)<=cast(\$endDate as date) end) and (case when \$product = '' then 1=1 else t1.product=\$product end)", 'condition' => array ( array('drillObject' => 'zt_bug', 'drillAlias' => 't1', 'drillField' => 'resolvedBy', 'queryField' => 'resolvedBy'), diff --git a/module/bi/model.php b/module/bi/model.php index df8b9ca873..3d3c313d1f 100755 --- a/module/bi/model.php +++ b/module/bi/model.php @@ -548,9 +548,9 @@ class biModel extends model $table = isset($this->config->objectTables[$useTable]) ? $this->config->objectTables[$useTable] : zget($this->config->objectTables, $object, ''); if($table) { - $columns = $this->dbh->query("SHOW COLUMNS FROM $table")->fetchAll(); + $columns = $this->dbh->descTable($table); foreach($columns as $id => $column) $columns[$id] = (array)$column; - $fieldList = array_column($columns, 'Field'); + $fieldList = array_column($columns, 'field'); $useField = in_array($useField, $fieldList) ? $useField : 'id'; $options = $this->dao->select("id, {$useField}")->from($table)->fetchPairs();