From 61a7bebab6aeaa20b22163d880c2062832185ef8 Mon Sep 17 00:00:00 2001 From: wlx Date: Mon, 2 Feb 2015 01:25:33 +0000 Subject: [PATCH] merge sanjiangyuan-sub r5224 - r5246 into sjy-erc --- .../admin/controllers/DataController.php | 39 +++++++++++--- .../scripts/data/dataimport-target.phtml | 53 ++++++++++++++++--- .../admin/views/scripts/data/visual-add.phtml | 6 +-- .../default/controllers/DataController.php | 26 ++------- .../scripts/visual/view-highcharts.phtml | 1 - .../Westdc/Dataimport/AbstractProcessing.php | 3 +- .../Westdc/Dataimport/Processing/Csv.php | 38 +++++++++---- 7 files changed, 115 insertions(+), 51 deletions(-) diff --git a/application/admin/controllers/DataController.php b/application/admin/controllers/DataController.php index ee90f013..ebb9f71b 100755 --- a/application/admin/controllers/DataController.php +++ b/application/admin/controllers/DataController.php @@ -2856,14 +2856,14 @@ class Admin_DataController extends Zend_Controller_Action } //文件列表 - if($ac == "files"){ + elseif($ac == "files"){ $file = new Westdc\Dataimport\File; $this->_helper->json($file->getUploadFiles()); return true; } //刪除上传的文件 - if($ac == "delete"){ + elseif($ac == "delete"){ $file = $this->_getParam('file'); $fileHandle = new Westdc\Dataimport\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'); $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'); if(empty($file)){ $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'); @@ -2947,7 +2947,7 @@ class Admin_DataController extends Zend_Controller_Action } //获得数据表 - if($ac == "gettables") + elseif($ac == "gettables") { $schema = $this->_getParam('schema'); if(empty($schema)){ @@ -2959,8 +2959,24 @@ class Admin_DataController extends Zend_Controller_Action 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->viewRenderer->setNoRender(); @@ -2983,6 +2999,7 @@ class Admin_DataController extends Zend_Controller_Action { $tableControl = new Westdc\Visual\DataTableControl; $fields = $tableControl->readFields($schema . "." .$table); + if ($fields[0]['column_name']=='id') unset($fields[0]); $status = $processing->checkTableField($fields); $this->_helper->json($status); @@ -2990,7 +3007,13 @@ class Admin_DataController extends Zend_Controller_Action } 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); return true; } diff --git a/application/admin/views/scripts/data/dataimport-target.phtml b/application/admin/views/scripts/data/dataimport-target.phtml index d9274eca..20415efe 100644 --- a/application/admin/views/scripts/data/dataimport-target.phtml +++ b/application/admin/views/scripts/data/dataimport-target.phtml @@ -22,7 +22,8 @@ $this->headTitle()->setSeparator(' - ');
- +
+

@@ -39,7 +40,6 @@ $this->headTitle()->setSeparator(' - '); - @@ -51,10 +51,6 @@ $this->headTitle()->setSeparator(' - '); ctl.checkTable(); }); - $("#ctl-show-table").click(function(){ - - }); - $("#ctl-import").click(function(){ $.ajax({ 'type':"POST", @@ -122,6 +118,7 @@ $this->headTitle()->setSeparator(' - '); { ctl.enableNext(); } + ctl.getFields(); }); $('#clt-next').removeClass('disabled'); @@ -163,6 +160,7 @@ $this->headTitle()->setSeparator(' - '); 'url':'/admin/data/dataimport/ac/checktables', 'data':$('#schema-form').serialize(), 'success':function(data){ + if (data!=true) { if(!$.isEmptyObject(data)) @@ -187,6 +185,49 @@ $this->headTitle()->setSeparator(' - '); $('#error-loading').html("正在校验数据是否可以导入......"); $('#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('数据表字段信息'); + html.push(''); + html.push(''); + + $.each(data,function(index,value){ + html.push(""); + }); + + html.push('
排序列名数据类型
"+value.dtd_identifier+"" + value.column_name + "" + value.data_type + "
'); + + $('#errors').html(html.join("")); + + }, + 'timeout': 30000, + 'beforeSend' : function(){ + $('#error-loading').html("正在获取数据表信息......"); + $('#error-loading').show(); + }, 'complete' : function(){ $('#error-loading').hide(); } diff --git a/application/admin/views/scripts/data/visual-add.phtml b/application/admin/views/scripts/data/visual-add.phtml index 489d4744..d7a20cd9 100644 --- a/application/admin/views/scripts/data/visual-add.phtml +++ b/application/admin/views/scripts/data/visual-add.phtml @@ -60,12 +60,12 @@
@@ -124,7 +124,7 @@
-

例如: utctime, times , (year||'-'||month||'-1')::timestamp without time zone ,不需要在最外层加括号或者双引号

+

例如: utctime, times , (year||'-'||month||'-1')::timestamp without time zone ,不需要在最外层加括号或者双引号。如果是制作分类图,则X轴必须是category,请在数据读取SQL中用将所需字段命名为category。

diff --git a/application/default/controllers/DataController.php b/application/default/controllers/DataController.php index e410c7ca..001a9e33 100755 --- a/application/default/controllers/DataController.php +++ b/application/default/controllers/DataController.php @@ -2079,28 +2079,12 @@ class DataController extends Zend_Controller_Action 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 -left join mdstatus s on m.uuid=s.uuid -left join datadoi d on d.uuid=m.uuid -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"; + $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 datadoi d on d.uuid=m.uuid + where s.status>4 + order by m.title"; $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); - } //可视化数据 diff --git a/application/default/views/scripts/visual/view-highcharts.phtml b/application/default/views/scripts/visual/view-highcharts.phtml index a7752635..d71379df 100644 --- a/application/default/views/scripts/visual/view-highcharts.phtml +++ b/application/default/views/scripts/visual/view-highcharts.phtml @@ -6,7 +6,6 @@ $theme = new Theme; $theme->appendPlus($this,'highcharts'); $this->nav[] = array('link'=>"/data/visual",'title'=>'数据可视化'); ?> -render('breadcrumbs.phtml'); ?>

info['title'] ?> 查看元数据

diff --git a/application/module/Westdc/Dataimport/AbstractProcessing.php b/application/module/Westdc/Dataimport/AbstractProcessing.php index 135a9d37..6153121c 100644 --- a/application/module/Westdc/Dataimport/AbstractProcessing.php +++ b/application/module/Westdc/Dataimport/AbstractProcessing.php @@ -22,13 +22,14 @@ abstract class AbstractProcessing { switch ($pgsql_data_type){ case "integer": case "bigint": - case "int2vector": case "real": case "double precision": return is_int($data) || is_float($data); case "date": + case "timestamp without time zone": case "char": case "character varying": + case "text": return is_string($data); default: diff --git a/application/module/Westdc/Dataimport/Processing/Csv.php b/application/module/Westdc/Dataimport/Processing/Csv.php index b1c65f5c..2db91d4b 100644 --- a/application/module/Westdc/Dataimport/Processing/Csv.php +++ b/application/module/Westdc/Dataimport/Processing/Csv.php @@ -18,8 +18,8 @@ class Csv extends AbstractProcessing implements ProcessingInterface{ private $csv_object; private $csv_line_data; - const ERROR_INDEX_NOT_MATCHED = "值的个数于其它行不匹配"; - const ERROR_INDEX_TYPE_DIFFERENT = "值的类型于上一行不同"; + const ERROR_INDEX_NOT_MATCHED = "值的个数与其它行不匹配"; + const ERROR_INDEX_TYPE_DIFFERENT = "值的类型与上一行不同"; const ERROR_EMPTY_FILE = "文件是空的"; const ERROR_LINE_TITLE = "行:"; const ERROR_COLUMN_TITLE = "列:"; @@ -108,6 +108,19 @@ class Csv extends AbstractProcessing implements ProcessingInterface{ 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 @@ -132,7 +145,7 @@ class Csv extends AbstractProcessing implements ProcessingInterface{ } 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; } @@ -158,14 +171,14 @@ class Csv extends AbstractProcessing implements ProcessingInterface{ $first_line = $this->getLines()[0]; - foreach($fields as $index => $field) + $index=0; + foreach($fields as $field) { - $func = $this->checkFieldsDataType($field['data_type'],$first_line[$index]); - - if($func) - continue; - else + if (!$this->checkFieldsDataType($field['data_type'],$first_line[$index])) + { $error_stack[] = self::ERROR_COLUMN_TITLE . $index .":" . self::ERROR_DATA_TYPE_NOT_MATCHED; + } + $index++; } if(count($error_stack) < 1) @@ -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'); $db = new PDO([ @@ -200,7 +213,10 @@ class Csv extends AbstractProcessing implements ProcessingInterface{ $place_holder[] = "?"; } - $sth = $db->prepare("INSERT INTO $table VALUES (".join(",",$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).")"); foreach($this->getLines() as $line) {