* Finish generate metric php template.

This commit is contained in:
qixinzhi
2023-08-30 06:41:59 +00:00
parent 3f2b3f5b2b
commit 3ce417d9e6
2 changed files with 90 additions and 0 deletions
+30
View File
@@ -151,6 +151,36 @@ class metricModel extends model
return $returnType == 'sql' ? $sql : $statement;
}
/**
* 根据度量项信息生成度量项php模板内容。
* Generante php template content from metric information.
*
* @param int $metricID
* @access public
* @return string
*/
public function getMetricPHPTemplate(int $metricID): string
{
$metric = $this->getByID($metricID);
$metric->nameEN = ucfirst(str_replace('_', ' ', $metric->code));
$metric->scope = $this->lang->metric->scopeList[$metric->scope];
$metric->object = $this->lang->metric->objectList[$metric->object];
$metric->purpose = $this->lang->metric->purposeList[$metric->purpose];
$replaceFields = array('name', 'nameEN', 'code', 'scope', 'object', 'purpose', 'unit', 'desc', 'definition');
$content = file_get_contents($this->app->getModuleRoot() . DS . 'metric' . DS . 'template' . DS . 'metric.php.tmp');
foreach($replaceFields as $replaceField)
{
$replaceContent = str_replace("\n", ';', $metric->$replaceField);
$content = str_replace("{{{$replaceField}}}", $replaceContent, $content);
}
return $content;
}
/**
* 根据代号获取计算实时度量项的结果。
* Get result of calculate metric by code.
+60
View File
@@ -0,0 +1,60 @@
<?php
/**
* {{name}}。
* {{nameEN}}.
*
* 范围:{{scope}}
* 对象:{{object}}
* 目的:{{purpose}}
* 度量名称:{{name}}
* 单位:{{unit}}
* 描述:{{desc}}
* 定义:{{definition}}
*/
class {{code}} extends baseCalc
{
/**
* 度量项计算临时结果。
*/
public $result = 1;
// public $result = array();
/**
* 获取自定义数据源pdo句柄。
*
* @access public
* @return PDOStatement
*/
public function getStatement()
{
return $this->dao->XXX->query();
}
/**
* 计算度量项。
*
* 对数据源查询得到的数据集进行逐行计算,该函数实现对于一行数据的计算逻辑
* 计算完成后将数据临时记录到$this->result上
*
* @param object $row 数据源的一行数据
* @access public
* @return void|false
*/
public function calculate($row)
{
$this->result += 1;
}
/**
* 汇总并获取度量项计算结果。
*
* @param array $options 筛选参数
* @access public
* @return array 度量数据
*/
public function getResult($options = array())
{
$records = $this->getRecords(array('value'));
return $this->filterByOptions($records, $options);
}
}