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 0040163d..001a9e33 100755 --- a/application/default/controllers/DataController.php +++ b/application/default/controllers/DataController.php @@ -1977,23 +1977,23 @@ class DataController extends Zend_Controller_Action $ac = $this->_request->getParam('ac'); if ($ac=='unready') { //列出没有DOI的数据 - $sql="select m.* from {$this->submd} m where length(m.doi)<3 and m.uuid not in (select uuid from datadoi) order by m.ts_created desc"; + $sql="select m.* from {$this->submd} m where m.uuid not in (select uuid from datadoi) order by m.ts_created desc"; $this->view->pageID='doi-unready'; } else if ($ac=='prepare') { //列出有DOI但还未进行提交申请的数据 - $sql="select m.* from {$this->submd} m where length(m.doi)>3 and m.uuid not in (select uuid from datadoi) order by m.ts_created desc"; + $sql="select m.* from {$this->submd} m where m.uuid not in (select uuid from datadoi) order by m.ts_created desc"; $this->view->pageID='doi-prepare'; } else if ($ac=='unsubmit') { //列出有DOI并计划提交申请的数据 - $sql="select m.*,d.doi as datadoi,date(d.ts_created) as ts_created from {$this->submd} m left join datadoi d on m.uuid=d.uuid where length(m.doi)>3 and d.ts_created is not null and d.ts_submitted is null order by d.ts_created desc"; + $sql="select m.*,d.doi as datadoi,date(d.ts_created) as ts_created from {$this->submd} m left join datadoi d on m.uuid=d.uuid where d.ts_created is not null and d.ts_submitted is null order by d.ts_created desc"; $this->view->pageID='doi-unsubmit'; } else if ($ac=='submit') { //列出有DOI并计划提交申请的数据 - $sql="select m.*,d.doi as datadoi,date(d.ts_submitted) as ts_submitted from {$this->submd} m left join datadoi d on m.uuid=d.uuid where length(m.doi)>3 and d.ts_submitted is not null and d.ts_published is null order by d.ts_submitted desc,d.ts_created desc"; + $sql="select m.*,d.doi as datadoi,date(d.ts_submitted) as ts_submitted from {$this->submd} m left join datadoi d on m.uuid=d.uuid where d.ts_submitted is not null and d.ts_published is null order by d.ts_submitted desc,d.ts_created desc"; $this->view->pageID='doi-submit'; } else if ($ac=='publish' || empty($ac)) { //默认:列出最新发布的DOI数据 - $sql="select m.*,d.doi as datadoi,date(d.ts_submitted) as ts_submitted,date(d.ts_published) as ts_published from {$this->submd} m left join datadoi d on m.uuid=d.uuid where length(m.doi)>3 and d.ts_published is not null order by d.ts_published desc,d.ts_submitted desc,d.ts_created desc"; + $sql="select m.*,d.doi as datadoi,date(d.ts_submitted) as ts_submitted,date(d.ts_published) as ts_published from {$this->submd} m left join datadoi d on m.uuid=d.uuid where d.ts_published is not null order by d.ts_published desc,d.ts_submitted desc,d.ts_created desc"; $this->view->pageID='doi-publish'; } $sth = $this->db->prepare($sql); @@ -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/data/doi.phtml b/application/default/views/scripts/data/doi.phtml index 3d5f9091..369fc9bd 100644 --- a/application/default/views/scripts/data/doi.phtml +++ b/application/default/views/scripts/data/doi.phtml @@ -7,7 +7,6 @@ $this->nav[] = array('link'=>"/data/doi",'title'=>'DOI浏览'); $this->theme->AppendPlus($this,'colorbox'); ?>
-render('breadcrumbs.phtml') ?> partial('data/tools.phtml'); ?>

escape($md['title']);?>

400?$this->escape(mb_substr($md['description'],0,400,'UTF-8').'...'):$this->escape($md['description']);?> +

可视化查看

paginator; ?> 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) {