merge sanjiangyuan-sub r5224 - r5246 into sjy-erc

This commit is contained in:
wlx 2015-02-02 01:25:33 +00:00
parent 90d11af44e
commit 61a7bebab6
7 changed files with 115 additions and 51 deletions

View File

@ -2856,14 +2856,14 @@ class Admin_DataController extends Zend_Controller_Action
} }
//文件列表 //文件列表
if($ac == "files"){ elseif($ac == "files"){
$file = new Westdc\Dataimport\File; $file = new Westdc\Dataimport\File;
$this->_helper->json($file->getUploadFiles()); $this->_helper->json($file->getUploadFiles());
return true; return true;
} }
//刪除上传的文件 //刪除上传的文件
if($ac == "delete"){ elseif($ac == "delete"){
$file = $this->_getParam('file'); $file = $this->_getParam('file');
$fileHandle = new Westdc\Dataimport\File; $fileHandle = new Westdc\Dataimport\File;
$this->_helper->json(['success'=>$fileHandle->deleteFile($file)]); $this->_helper->json(['success'=>$fileHandle->deleteFile($file)]);
@ -2872,7 +2872,7 @@ class Admin_DataController extends Zend_Controller_Action
//预处理 //预处理
//判断文件类型,初步识别文件內容 //判断文件类型,初步识别文件內容
if($ac == "prepare"){ elseif($ac == "prepare"){
$this->_helper->viewRenderer('dataimport-preprocess'); $this->_helper->viewRenderer('dataimport-preprocess');
$file = $this->_getParam('file'); $file = $this->_getParam('file');
@ -2911,7 +2911,7 @@ class Admin_DataController extends Zend_Controller_Action
} }
//檢查文件是否規則 //檢查文件是否規則
if($ac == "check"){ elseif($ac == "check"){
$file = $this->_getParam('file'); $file = $this->_getParam('file');
if(empty($file)){ if(empty($file)){
$this->_helper->json(['error'=>'参数错误']); $this->_helper->json(['error'=>'参数错误']);
@ -2931,7 +2931,7 @@ class Admin_DataController extends Zend_Controller_Action
} }
//選擇導入目標 //選擇導入目標
if($ac == "target") elseif($ac == "target")
{ {
$this->_helper->viewRenderer('dataimport-target'); $this->_helper->viewRenderer('dataimport-target');
@ -2947,7 +2947,7 @@ class Admin_DataController extends Zend_Controller_Action
} }
//获得数据表 //获得数据表
if($ac == "gettables") elseif($ac == "gettables")
{ {
$schema = $this->_getParam('schema'); $schema = $this->_getParam('schema');
if(empty($schema)){ if(empty($schema)){
@ -2959,8 +2959,24 @@ class Admin_DataController extends Zend_Controller_Action
return true; return true;
} }
//获取表格字段名称和类型
elseif($ac=="getfields")
{
$schema = $this->_getParam('schema');
$table = $this->_getParam('table');
if(empty($schema) || empty($table)){
$this->_helper->json(['error'=>'参数错误']);
return true;
}
$tableControl = new Westdc\Visual\DataTableControl;
$fields = $tableControl->readFields($schema . "." .$table);
if ($fields[0]['column_name']=='id') unset($fields[0]);
$this->_helper->json($fields);
return true;
}
//检查能否写入数据表 和 导入数据 //检查能否写入数据表 和 导入数据
if($ac == "checktables" || $ac == "import"){ elseif($ac == "checktables" || $ac == "import"){
$this->_helper->layout->disableLayout(); $this->_helper->layout->disableLayout();
$this->_helper->viewRenderer->setNoRender(); $this->_helper->viewRenderer->setNoRender();
@ -2983,6 +2999,7 @@ class Admin_DataController extends Zend_Controller_Action
{ {
$tableControl = new Westdc\Visual\DataTableControl; $tableControl = new Westdc\Visual\DataTableControl;
$fields = $tableControl->readFields($schema . "." .$table); $fields = $tableControl->readFields($schema . "." .$table);
if ($fields[0]['column_name']=='id') unset($fields[0]);
$status = $processing->checkTableField($fields); $status = $processing->checkTableField($fields);
$this->_helper->json($status); $this->_helper->json($status);
@ -2990,7 +3007,13 @@ class Admin_DataController extends Zend_Controller_Action
} }
elseif($ac == "import"){ elseif($ac == "import"){
$status = $processing->import($schema . "." .$table); $tableControl = new Westdc\Visual\DataTableControl;
$fields = $tableControl->readFields($schema . "." .$table);
$status = $processing->import($schema . "." .$table,$fields[0]['column_name']=='id');
if($status===true)
{
$fileHandle->deleteFile($file);
}
$this->_helper->json($status); $this->_helper->json($status);
return true; return true;
} }

View File

@ -22,7 +22,8 @@ $this->headTitle()->setSeparator(' - ');
</label> </label>
</div> </div>
<div class="span3" id="table-list"> <div class="span3" id="table-list">
</div>
<div class="span4" id="field-list">
</div> </div>
</div> </div>
<hr class="clear" /> <hr class="clear" />
@ -39,7 +40,6 @@ $this->headTitle()->setSeparator(' - ');
<input type="hidden" name="schema" value=""> <input type="hidden" name="schema" value="">
<input type="hidden" name="table" value="" id="input-table"> <input type="hidden" name="table" value="" id="input-table">
<button type="button" id="ctl-next" class="btn btn-success disabled" disabled>下一步</button> <button type="button" id="ctl-next" class="btn btn-success disabled" disabled>下一步</button>
<button type="button" id="ctl-show-table" class="btn btn-info hidden" disabled>查看数据表结构</button>
<button type="button" id="ctl-import" class="btn btn-info" disabled="disabled" style="display: none;">导入数据表</button> <button type="button" id="ctl-import" class="btn btn-info" disabled="disabled" style="display: none;">导入数据表</button>
</form> </form>
</div> </div>
@ -51,10 +51,6 @@ $this->headTitle()->setSeparator(' - ');
ctl.checkTable(); ctl.checkTable();
}); });
$("#ctl-show-table").click(function(){
});
$("#ctl-import").click(function(){ $("#ctl-import").click(function(){
$.ajax({ $.ajax({
'type':"POST", 'type':"POST",
@ -122,6 +118,7 @@ $this->headTitle()->setSeparator(' - ');
{ {
ctl.enableNext(); ctl.enableNext();
} }
ctl.getFields();
}); });
$('#clt-next').removeClass('disabled'); $('#clt-next').removeClass('disabled');
@ -163,6 +160,7 @@ $this->headTitle()->setSeparator(' - ');
'url':'/admin/data/dataimport/ac/checktables', 'url':'/admin/data/dataimport/ac/checktables',
'data':$('#schema-form').serialize(), 'data':$('#schema-form').serialize(),
'success':function(data){ 'success':function(data){
if (data!=true) if (data!=true)
{ {
if(!$.isEmptyObject(data)) if(!$.isEmptyObject(data))
@ -187,6 +185,49 @@ $this->headTitle()->setSeparator(' - ');
$('#error-loading').html("正在校验数据是否可以导入......"); $('#error-loading').html("正在校验数据是否可以导入......");
$('#error-loading').show(); $('#error-loading').show();
}, },
'complete' : function(){
$('#error-loading').hide();
},
'error' : function(){
$(".error-alerts").show();
$("#errors").html("数据表字段检测失败,请检查导入得文件是否于数据表中得字段对应");
}
});
},
getFields : function (){
$.ajax({
'type':"POST",
'url':'/admin/data/dataimport/ac/getfields',
'data':$('#schema-form').serialize(),
'success':function(data){
if($.isEmptyObject(data))
{
return true;
}
$(".error-alerts").show();
var html = new Array();
html.push('<span>数据表字段信息</span>');
html.push('<table class="table table-striped table-bordered" style="width:300px;">');
html.push('<thead><th>排序</th><th>列名</th><th>数据类型</th></thead>');
$.each(data,function(index,value){
html.push("<tr><td>"+value.dtd_identifier+"</td><td>" + value.column_name + "</td><td>" + value.data_type + "</td></tr>");
});
html.push('</table>');
$('#errors').html(html.join(""));
},
'timeout': 30000,
'beforeSend' : function(){
$('#error-loading').html("正在获取数据表信息......");
$('#error-loading').show();
},
'complete' : function(){ 'complete' : function(){
$('#error-loading').hide(); $('#error-loading').hide();
} }

View File

@ -60,12 +60,12 @@
<label class="control-label">绘图插件</label> <label class="control-label">绘图插件</label>
<div class="controls"> <div class="controls">
<label class="radio inline"> <label class="radio inline">
<input type="radio" name="chartjs" id="optionsRadios1" value="highcharts" <?= (isset($this->info['chartjs']) && $this->info['chartjs']=='highcharts') || empty($this->info['chartjs']) ? "checked":"" ?>> <input type="radio" name="chartjs" id="optionsRadios1" value="highcharts" <?= (isset($this->info['chartjs']) && $this->info['chartjs']=='highcharts') ? "checked":"" ?>>
Highcharts适合分类数据展示和三维展示 Highcharts适合分类数据展示和三维展示
</label> </label>
<label class="radio inline"> <label class="radio inline">
<input type="radio" name="chartjs" id="optionsRadios2" value="highstock" <input type="radio" name="chartjs" id="optionsRadios2" value="highstock"
<?= isset($this->info['chartjs']) && $this->info['chartjs'] == 'highstock' ? 'checked="checked"':"" ?>> <?= (isset($this->info['chartjs']) && $this->info['chartjs'] == 'highstock') || empty($this->info['chartjs']) ? 'checked="checked"':"" ?>>
Highstock适合时间序列数据可视化 Highstock适合时间序列数据可视化
</label> </label>
</div> </div>
@ -124,7 +124,7 @@
<label class="control-label">X轴取值</label> <label class="control-label">X轴取值</label>
<div class="controls"> <div class="controls">
<input type="text" name="xaxis" placeholder="时间字段读取SQL" class="input-block-level" value="<?= isset($this->info['xaxis']) ? $this->info['xaxis']:'' ?>" /> <input type="text" name="xaxis" placeholder="时间字段读取SQL" class="input-block-level" value="<?= isset($this->info['xaxis']) ? $this->info['xaxis']:'' ?>" />
<p class="help-block">例如: utctime, times , (year||'-'||month||'-1')::timestamp without time zone ,不需要在最外层加括号或者双引号</p> <p class="help-block">例如: utctime, times , (year||'-'||month||'-1')::timestamp without time zone ,不需要在最外层加括号或者双引号。如果是制作分类图则X轴必须是category请在数据读取SQL中用将所需字段命名为category。</p>
</div> </div>
</div> </div>

View File

@ -2079,28 +2079,12 @@ class DataController extends Zend_Controller_Action
function listAction() function listAction()
{ {
$sql="select m.uuid,m.title,m.citation,m.doi,d.doi as datadoi,d.ts_published,d.authors,d.publisher,date_part('year',d.ts_published) as publish_year from normalmetadata m $sql="select m.uuid,m.title,m.citation,m.doi,d.doi as datadoi,d.ts_published,d.authors,d.publisher,date_part('year',d.ts_published) as publish_year from {$this->submd} m
left join mdstatus s on m.uuid=s.uuid left join mdstatus s on m.uuid=s.uuid
left join datadoi d on d.uuid=m.uuid left join datadoi d on d.uuid=m.uuid
where s.status>4 where s.status>4
and m.uuid not in
(select d.uuid from datasource d left join source s on d.sourceid=s.id
where s.code in ('heihe','water','hiwater','westee'))
order by m.title"; order by m.title";
$this->view->metadata=$this->db->fetchAll($sql); $this->view->metadata=$this->db->fetchAll($sql);
$sql="select m.uuid,m.title,m.citation,m.doi,d.doi as datadoi,d.ts_published,d.authors,d.publisher,date_part('year',d.ts_published) as publish_year
from normalmetadata m left join datadoi d on d.uuid=m.uuid left join mdstatus s on m.uuid=s.uuid where s.status>4 and m.title like '黑河综合遥感联合试验%' order by title";
$this->view->water=$this->db->fetchAll($sql);
$sql="select m.uuid,m.title,m.citation ,m.doi,d.doi as datadoi,d.ts_published,d.authors,d.publisher,date_part('year',d.ts_published) as publish_year
from normalmetadata m left join datadoi d on d.uuid=m.uuid left join mdstatus s on m.uuid=s.uuid where s.status>0 and m.title like '黑河生态水文遥感试验%' order by title";
$this->view->hiwater=$this->db->fetchAll($sql);
$sql="select m.uuid,m.title,m.citation ,m.doi,d.doi as datadoi,d.ts_published,d.authors,d.publisher,date_part('year',d.ts_published) as publish_year
from normalmetadata m left join datadoi d on d.uuid=m.uuid left join mdstatus s on m.uuid=s.uuid left join datasource ds on ds.uuid=m.uuid left join source sr on ds.sourceid=sr.id where sr.code='heihe' and s.status>0 and m.title not like '黑河生态水文遥感试验%' order by title";
$this->view->heihe=$this->db->fetchAll($sql);
$sql="select m.uuid,m.title,m.citation ,m.doi,d.doi as datadoi,d.ts_published,d.authors,d.publisher,date_part('year',d.ts_published) as publish_year
from normalmetadata m left join datadoi d on d.uuid=m.uuid left join mdstatus s on m.uuid=s.uuid left join datasource ds on ds.uuid=m.uuid left join source sr on ds.sourceid=sr.id where sr.code='westee' and s.status>4 order by title";
$this->view->westee=$this->db->fetchAll($sql);
} }
//可视化数据 //可视化数据

View File

@ -6,7 +6,6 @@ $theme = new Theme;
$theme->appendPlus($this,'highcharts'); $theme->appendPlus($this,'highcharts');
$this->nav[] = array('link'=>"/data/visual",'title'=>'数据可视化'); $this->nav[] = array('link'=>"/data/visual",'title'=>'数据可视化');
?> ?>
<?= $this->render('breadcrumbs.phtml'); ?>
<div class="row"> <div class="row">
<div class="span12"> <div class="span12">
<h3><?= $this->info['title'] ?> <small><a href="/data/<?= $this->info['uuid'] ?>">查看元数据</a></small></h3> <h3><?= $this->info['title'] ?> <small><a href="/data/<?= $this->info['uuid'] ?>">查看元数据</a></small></h3>

View File

@ -22,13 +22,14 @@ abstract class AbstractProcessing {
switch ($pgsql_data_type){ switch ($pgsql_data_type){
case "integer": case "integer":
case "bigint": case "bigint":
case "int2vector":
case "real": case "real":
case "double precision": case "double precision":
return is_int($data) || is_float($data); return is_int($data) || is_float($data);
case "date": case "date":
case "timestamp without time zone":
case "char": case "char":
case "character varying": case "character varying":
case "text":
return is_string($data); return is_string($data);
default: default:

View File

@ -18,8 +18,8 @@ class Csv extends AbstractProcessing implements ProcessingInterface{
private $csv_object; private $csv_object;
private $csv_line_data; private $csv_line_data;
const ERROR_INDEX_NOT_MATCHED = "值的个数其它行不匹配"; const ERROR_INDEX_NOT_MATCHED = "值的个数其它行不匹配";
const ERROR_INDEX_TYPE_DIFFERENT = "值的类型上一行不同"; const ERROR_INDEX_TYPE_DIFFERENT = "值的类型上一行不同";
const ERROR_EMPTY_FILE = "文件是空的"; const ERROR_EMPTY_FILE = "文件是空的";
const ERROR_LINE_TITLE = "行:"; const ERROR_LINE_TITLE = "行:";
const ERROR_COLUMN_TITLE = "列:"; const ERROR_COLUMN_TITLE = "列:";
@ -108,6 +108,19 @@ class Csv extends AbstractProcessing implements ProcessingInterface{
return $this->csv_object; return $this->csv_object;
} }
/**
* 面向数据库字段的类型判断
* @return bool
*/
private function typeCompare($var1,$var2)
{
$t1=gettype($var1);
$t2=gettype($var2);
if ($t1==$t2) return true;
if (($t1=='integer' || $t1=='double') && ($t2=='integer' || $t2=='double'))
return true;
return false;
}
/** /**
* 檢查文件內容是否規則 * 檢查文件內容是否規則
* @return array|bool * @return array|bool
@ -132,7 +145,7 @@ class Csv extends AbstractProcessing implements ProcessingInterface{
} }
foreach($v as $vIndex => $item){ foreach($v as $vIndex => $item){
if(gettype($item) != gettype($lines[$k-1][$vIndex])) if(!$this->typeCompare($item,$lines[$k-1][$vIndex]))
{ {
$error_stack[] = self::ERROR_LINE_TITLE . ($k + 1) .":".self::ERROR_INDEX_TYPE_DIFFERENT; $error_stack[] = self::ERROR_LINE_TITLE . ($k + 1) .":".self::ERROR_INDEX_TYPE_DIFFERENT;
} }
@ -158,15 +171,15 @@ class Csv extends AbstractProcessing implements ProcessingInterface{
$first_line = $this->getLines()[0]; $first_line = $this->getLines()[0];
foreach($fields as $index => $field) $index=0;
foreach($fields as $field)
{
if (!$this->checkFieldsDataType($field['data_type'],$first_line[$index]))
{ {
$func = $this->checkFieldsDataType($field['data_type'],$first_line[$index]);
if($func)
continue;
else
$error_stack[] = self::ERROR_COLUMN_TITLE . $index .":" . self::ERROR_DATA_TYPE_NOT_MATCHED; $error_stack[] = self::ERROR_COLUMN_TITLE . $index .":" . self::ERROR_DATA_TYPE_NOT_MATCHED;
} }
$index++;
}
if(count($error_stack) < 1) if(count($error_stack) < 1)
return true; return true;
@ -176,7 +189,7 @@ class Csv extends AbstractProcessing implements ProcessingInterface{
} }
public function import($table) public function import($table,$withid=fasle)
{ {
$config = \Zend_Registry::get('config'); $config = \Zend_Registry::get('config');
$db = new PDO([ $db = new PDO([
@ -200,6 +213,9 @@ class Csv extends AbstractProcessing implements ProcessingInterface{
$place_holder[] = "?"; $place_holder[] = "?";
} }
if ($withid)
$sth = $db->prepare("INSERT INTO $table VALUES (default,".join(",",$place_holder).")");
else
$sth = $db->prepare("INSERT INTO $table VALUES (".join(",",$place_holder).")"); $sth = $db->prepare("INSERT INTO $table VALUES (".join(",",$place_holder).")");
foreach($this->getLines() as $line) foreach($this->getLines() as $line)