Merge branch 'daitingting_process_filterAndGroup' into 'master'

* Process filter of chart.

See merge request easycorp/zentaopms!7362
This commit is contained in:
王怡栋
2023-04-11 07:13:31 +00:00
2 changed files with 80 additions and 10 deletions
+1 -2
View File
@@ -26,7 +26,7 @@ CREATE TABLE IF NOT EXISTS `zt_pivot` (
`objects` mediumtext NULL,
`settings` mediumtext NOT NULL,
`filters` mediumtext NOT NULL,
`step` tinyint(1) unsigned NOT NULL DEFAULT '',
`step` tinyint(1) unsigned NOT NULL,
`stage` enum('draft','published') NOT NULL DEFAULT 'draft',
`builtin` enum('0', '1') NOT NULL DEFAULT '0',
`createdBy` varchar(30) NOT NULL,
@@ -46,7 +46,6 @@ ALTER TABLE `zt_chart` MODIFY `group` varchar(255) NOT NULL;
ALTER TABLE `zt_chart` ADD `stage` enum('draft','published') NOT NULL DEFAULT 'draft' AFTER `sql`;
ALTER TABLE `zt_chart` ADD `langs` text NULL AFTER `fields`;
ALTER TABLE `zt_chart` ADD `step` tinyint(1) unsigned NOT NULL DEFAULT '0' AFTER `filters`;
ALTER TABLE `zt_chart` DROP `dataset`;
ALTER TABLE `zt_dataview` ADD `langs` text NULL AFTER `fields`;
+79 -8
View File
@@ -8692,7 +8692,6 @@ class upgradeModel extends model
}
$data->settings = json_encode(array($settings));
$data->filters = json_encode($filters);
if(isset($dataviewList[$chart->dataset]))
{
@@ -8706,6 +8705,41 @@ class upgradeModel extends model
$data->fields = json_encode($fieldSettings);
}
if(!empty($filters))
{
$where = array();
$operatorMap = array('in' => 'IN', 'notin' => 'NOT IN', 'notnull' => 'IS NOT NULL', 'null' => 'IS NULL');
foreach($filters as $filter)
{
$operator = zget($operatorMap, $filter->operator);
$value = '';
if(!in_array($filter->operator, array('null', 'notnull')))
{
if(!is_array($filter->value))
{
$value = "'" . $filter->value . "'";
}
else
{
$values = array();
foreach($filter->value as $v) $values[] = $type == 'number' ? $v : "'" . $v . "'";
$value = '(' . implode(',', $values) . ')';
}
}
$where[] = $filter->field . ' ' . $operator . ' ' . $value;
}
if(stripos($data->sql, 'where') === false)
{
$data->sql .= ' WHERE ' . implode(' AND ', $where);
}
else
{
$data->sql .= ' ' . implode(' AND ', $where);
}
}
$this->dao->update(TABLE_CHART)->data($data)->autoCheck()->where('id')->eq($chart->id)->exec();
}
@@ -8763,6 +8797,7 @@ class upgradeModel extends model
$pivotSettings = new stdclass();
$tableSettings = json_decode($table->settings);
$filters = array();
if($tableSettings)
{
$index = 1;
@@ -8793,7 +8828,8 @@ class upgradeModel extends model
$pivotSettings->columns = $columns;
$pivot->settings = json_encode($pivotSettings);
$pivot->filters = json_encode($tableSettings->filter);
if(!empty($tableSettings->filter)) $filters = $tableSettings->filter;
}
if(isset($dataviewList[$table->dataset]))
@@ -8808,6 +8844,41 @@ class upgradeModel extends model
$pivot->fields = json_encode($fieldSettings);
}
if(!empty($filters))
{
$where = array();
$operatorMap = array('in' => 'IN', 'notin' => 'NOT IN', 'notnull' => 'IS NOT NULL', 'null' => 'IS NULL');
foreach($filters as $filter)
{
$operator = zget($operatorMap, $filter->operator);
$value = '';
if(!in_array($filter->operator, array('null', 'notnull')))
{
if(!is_array($filter->value))
{
$value = "'" . $filter->value . "'";
}
else
{
$values = array();
foreach($filter->value as $v) $values[] = $type == 'number' ? $v : "'" . $v . "'";
$value = '(' . implode(',', $values) . ')';
}
}
$where[] = $filter->field . ' ' . $operator . ' ' . $value;
}
if(stripos($pivot->sql, 'where') === false)
{
$pivot->sql .= ' WHERE ' . implode(' AND ', $where);
}
else
{
$pivot->sql .= ' ' . implode(' AND ', $where);
}
}
/* Process fieldSettings. */
$this->dao->insert(TABLE_PIVOT)->data($pivot)->autoCheck()->exec();
@@ -8830,8 +8901,7 @@ class upgradeModel extends model
{
$reports = $this->dao->select('*')->from(TABLE_REPORT)->fetchAll();
$modulePairs = $this->dao->select('id, name')->from(TABLE_MODULE)->where('type')->eq('report')->fetchPairs();
$groupNames = $this->dao->select('name, id')->from(TABLE_MODULE)->where('type')->eq('pivot')->fetchPairs();
$groupCollectors = $this->dao->select('collector, id')->from(TABLE_MODULE)->where('type')->eq('pivot')->fetchPairs();
$this->loadModel('pivot');
@@ -8850,14 +8920,15 @@ class upgradeModel extends model
$data->createdDate = $report->addedDate;
/* Process group. */
$modules = explode($report->module, ',');
$modules = explode(',', $report->module);
$groups = array();
foreach($modules as $module)
{
$moduleName = zget($modulePairs, $module, '');
if(isset($groupNames[$moduleName]))
if(!$module) continue;
if(isset($groupCollectors[$module]))
{
$groups[] = $groupNames[$moduleName];
$groups[] = $groupCollectors[$module];
}
else
{