add data preprocessing actions
This commit is contained in:
parent
045b849dbf
commit
460ec78cb7
|
@ -4154,15 +4154,31 @@ class Admin_DataController extends Zend_Controller_Action
|
|||
|
||||
//文件上傳
|
||||
if($ac == "upload") {
|
||||
$upload = new Dataimport\Upload;
|
||||
$file = $upload($_FILES['FileData']);
|
||||
$upload = new Dataimport\File;
|
||||
$file = $upload->upload($_FILES['FileData']);
|
||||
|
||||
$this->_helper->json($file);
|
||||
return true;
|
||||
}
|
||||
|
||||
//文件列表
|
||||
if($ac == "files"){
|
||||
$file = new Dataimport\File;
|
||||
$this->_helper->json($file->getUploadFiles());
|
||||
return true;
|
||||
}
|
||||
|
||||
//刪除上傳的文件
|
||||
if($ac == "delete"){
|
||||
$file = $this->_getParam('file');
|
||||
$fileHandle = new Dataimport\File;
|
||||
$this->_helper->json(['success'=>$fileHandle->deleteFile($file)]);
|
||||
return true;
|
||||
}
|
||||
|
||||
//預處理
|
||||
//判斷文件類型,初步識別文件內容
|
||||
if($ac == "preprocess"){
|
||||
if($ac == "prepare"){
|
||||
$this->_helper->viewRenderer('dataimport-preprocess');
|
||||
|
||||
$file = $this->_getParam('file');
|
||||
|
@ -4170,7 +4186,9 @@ class Admin_DataController extends Zend_Controller_Action
|
|||
if(empty($file))
|
||||
$this->view->error = "参数错误";
|
||||
|
||||
if(!file_exists($file))
|
||||
$fileHandle = new Dataimport\File;
|
||||
$realfile = $fileHandle->getRealName($file);
|
||||
if(!file_exists($realfile))
|
||||
$this->view->error = "要导入的文件已不存在,请返回上一步重新上传";
|
||||
|
||||
if(isset($this->view->error))
|
||||
|
@ -4178,6 +4196,43 @@ class Admin_DataController extends Zend_Controller_Action
|
|||
|
||||
$this->view->file = $file;
|
||||
|
||||
$fileExt = $fileHandle->getFileTextExt($realfile);
|
||||
|
||||
$processing = Dataimport\ProcessFactory::Bootstrap($fileExt);
|
||||
|
||||
/** @var \Westdc\Dataimport\Processing\Csv $processing */
|
||||
$processing->init($realfile);
|
||||
|
||||
//文件行數
|
||||
$this->view->Count = $processing->getLineCount();
|
||||
//文件大小
|
||||
$this->view->Size = $processing->getSize();
|
||||
//文件類型>view->error
|
||||
$this->view->Type = $processing->getType();
|
||||
|
||||
view::Dump($processing->getLines(),false);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//檢查文件是否規則
|
||||
if($ac == "check"){
|
||||
$file = $this->_getParam('file');
|
||||
if(empty($file)){
|
||||
$this->_helper->json(['error'=>'參數錯誤']);
|
||||
return true;
|
||||
}
|
||||
|
||||
$fileHandle = new Dataimport\File;
|
||||
$realFile = $fileHandle->getRealName($file);
|
||||
|
||||
$processing = Dataimport\ProcessFactory::Bootstrap($fileHandle->getFileTextExt($file));
|
||||
/** @var \Westdc\Dataimport\Processing\Csv $processing */
|
||||
$processing->init($realFile);
|
||||
|
||||
$status = $processing->checkRegularity();
|
||||
$this->_helper->json(['status'=>$status]);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -12,7 +12,59 @@ $this->headTitle()->setSeparator(' - ');
|
|||
<h3>數據導入<small>文件預處理</small></h3>
|
||||
<hr />
|
||||
|
||||
處理文件:<?= $this->file ?>
|
||||
處理文件:<?= $this->file ?>...
|
||||
|
||||
<h5>文件信息</h5>
|
||||
<ul>
|
||||
<li>文件行數:<?= $this->Count ?></li>
|
||||
<li>文件大小:<?= $this->Size ?></li>
|
||||
<li>文件類型:<?= $this->Type ?></li>
|
||||
</ul>
|
||||
|
||||
<hr />
|
||||
|
||||
<h5 class="error-alerts" style="display: none;">錯誤消息</h5>
|
||||
<ul id="errors" class="error-alerts" style="display: none;">
|
||||
|
||||
</ul>
|
||||
|
||||
<h6 id="error-loading"></h6>
|
||||
|
||||
<a href="javascript:void(0);">下一步</a>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script>
|
||||
$(document).ready(function(){
|
||||
$.ajax({
|
||||
'type':"POST",
|
||||
'url':'/admin/data/dataimport/ac/check',
|
||||
'data':'file=<?= $this->file ?>',
|
||||
'success':function(data){
|
||||
if (data!=null)
|
||||
{
|
||||
if(data.status == true)
|
||||
{
|
||||
alert("數據完整性檢查成功,可以進行下一步");
|
||||
return true;
|
||||
}
|
||||
$('.error-alerts').show();
|
||||
$.each(data.status,function(index,value){
|
||||
$('#errors').append("<li>"+value+"</li>");
|
||||
});
|
||||
}else{
|
||||
alert('处理中出现错误');
|
||||
}
|
||||
},
|
||||
'timeout': 30000,
|
||||
'beforeSend' : function(){
|
||||
$('#error-loading').html("正在對文件進行初始化檢查......");
|
||||
$('#error-loading').show();
|
||||
},
|
||||
'complete' : function(){
|
||||
$('#error-loading').hide();
|
||||
}
|
||||
|
||||
});
|
||||
});
|
||||
</script>
|
|
@ -17,6 +17,7 @@ $theme->AppendPlus($this,"jquery-fileupload");
|
|||
<label>上傳文件,請選擇Excel文件進行上傳</label>
|
||||
|
||||
<span class="btn btn-success fileinput-button file-upload-ctls">上傳文件<input id="fileupload" type="file" name="FileData"></span>
|
||||
<a href="javascript:void(0);" class="btn btn-info" id="ctl-show-files">查看已上傳的文件</a>
|
||||
<div class="progress" id="pdf-upload-progress" style="display: none;">
|
||||
<div class="progress-bar progress-bar-striped active" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" style="width: 0%">
|
||||
</div>
|
||||
|
@ -34,57 +35,118 @@ $theme->AppendPlus($this,"jquery-fileupload");
|
|||
dataType: 'json',
|
||||
done: function (e, data) {
|
||||
|
||||
if(typeof(data.result.error) != 'undefined' && data.result.error != 0)
|
||||
{
|
||||
alert(data.result.error);
|
||||
return false;
|
||||
}
|
||||
if(typeof(data.result.error) != 'undefined' && data.result.error != 0)
|
||||
{
|
||||
alert(data.result.error);
|
||||
return false;
|
||||
}
|
||||
|
||||
if($('#uploadedFile').html() == "")
|
||||
$('#uploadedFile').html(upload.makeFileHtml(data.result));
|
||||
else
|
||||
$('#uploadedFile').append(upload.makeFileHtml(data.result));
|
||||
if($('#uploadedFile').html() == "")
|
||||
$('#uploadedFile').html(upload.makeFileHtml(data.result));
|
||||
else
|
||||
$('#uploadedFile').append(upload.makeFileHtml(data.result));
|
||||
|
||||
return true;
|
||||
return true;
|
||||
|
||||
},
|
||||
stop : function (e) {
|
||||
$('#pdf-upload-progress').hide();
|
||||
$('.file-upload-ctls').show();
|
||||
},//stop
|
||||
start : function (e) {
|
||||
$('.file-upload-ctls').hide();
|
||||
$('#pdf-upload-progress .progress-bar').css('width', 0 + '%');
|
||||
$('#pdf-upload-progress').show();
|
||||
},//start
|
||||
progressall: function (e, data) {
|
||||
var progress = parseInt(data.loaded / data.total * 100, 10);
|
||||
$('#pdf-upload-progress .progress-bar').css(
|
||||
'width',
|
||||
progress + '%'
|
||||
);
|
||||
},//progressall
|
||||
add: function (e, data) {
|
||||
if($('input[name=attid]').length >= 1)
|
||||
{
|
||||
upload.deleteFile($('input[name=attid]').val());
|
||||
$('file-alert').alert('close')
|
||||
}
|
||||
},
|
||||
stop : function (e) {
|
||||
$('#pdf-upload-progress').hide();
|
||||
$('.file-upload-ctls').show();
|
||||
},//stop
|
||||
start : function (e) {
|
||||
$('.file-upload-ctls').hide();
|
||||
$('#pdf-upload-progress .progress-bar').css('width', 0 + '%');
|
||||
$('#pdf-upload-progress').show();
|
||||
},//start
|
||||
progressall: function (e, data) {
|
||||
var progress = parseInt(data.loaded / data.total * 100, 10);
|
||||
$('#pdf-upload-progress .progress-bar').css(
|
||||
'width',
|
||||
progress + '%'
|
||||
);
|
||||
},//progressall
|
||||
add: function (e, data) {
|
||||
if($('input[name=attid]').length >= 1)
|
||||
{
|
||||
upload.deleteFile($('input[name=attid]').val());
|
||||
$('file-alert').alert('close')
|
||||
}
|
||||
|
||||
data.process().done(function () {
|
||||
data.submit();
|
||||
data.process().done(function () {
|
||||
data.submit();
|
||||
});
|
||||
}//add
|
||||
}).prop('disabled', !$.support.fileInput)
|
||||
.parent().addClass($.support.fileInput ? undefined : 'disabled');
|
||||
//file upload end
|
||||
|
||||
$('#ctl-show-files').click(function(){
|
||||
|
||||
$.ajax({
|
||||
'type':"POST",
|
||||
'url':'/admin/data/dataimport/ac/files',
|
||||
'data':'',
|
||||
'success':function(data){
|
||||
if (data!=null)
|
||||
{
|
||||
if($.isEmptyObject(data))
|
||||
{
|
||||
alert("目前沒有文件");
|
||||
return;
|
||||
}
|
||||
|
||||
if($('#uploadedFile').html() == "")
|
||||
$('#uploadedFile').html(upload.makeFileList(data));
|
||||
else
|
||||
$('#uploadedFile').append(upload.makeFileList(data));
|
||||
|
||||
$('#ctl-show-files').attr('disabled','disabled');
|
||||
$("#ctl-show-files").unbind( "click" );
|
||||
}else{
|
||||
alert('处理中出现错误');
|
||||
}
|
||||
},
|
||||
'timeout': 30000
|
||||
});
|
||||
}//add
|
||||
}).prop('disabled', !$.support.fileInput)
|
||||
.parent().addClass($.support.fileInput ? undefined : 'disabled');
|
||||
|
||||
});//show files
|
||||
});
|
||||
|
||||
var upload = {
|
||||
makeFileHtml : function(data){
|
||||
return '<div class="alert alert-success">'
|
||||
+ data.file
|
||||
+ ' <a href="/admin/data/dataimport/ac/preprocess/?file='+ encodeURI(data.file) +'">導入數據</a>'
|
||||
+ '<span class="ctl-files">'+data.file+'</span>'
|
||||
+ ' <a href="/admin/data/dataimport/ac/prepare/?file='+ encodeURI(data.file) +'">導入數據</a>'
|
||||
+ '<a href="javascript:void(0)" onclick="upload.delete(this,\''+data.file+'\')" class="pull-right">刪除</a>'
|
||||
+ "</div>";
|
||||
},
|
||||
makeFileList : function(data){
|
||||
|
||||
var li = [];
|
||||
|
||||
$.each(data,function(k,v){
|
||||
li.push('<div class="alert alert-success ctl-files">'
|
||||
+ '<span class="ctl-files">'+v+'</span>'
|
||||
+ ' <a href="/admin/data/dataimport/ac/prepare/?file='+ encodeURI(v) +'">導入數據</a>'
|
||||
+ '<a href="javascript:void(0);" onclick="upload.delete(this,\''+v+'\')" class="pull-right">刪除</a>'
|
||||
+ "</div>");
|
||||
});
|
||||
|
||||
return li.join("");
|
||||
},
|
||||
delete : function(dom,file){
|
||||
$.ajax({
|
||||
'type':"POST",
|
||||
'url':'/admin/data/dataimport/ac/delete',
|
||||
'data':'file='+file,
|
||||
'success':function(data){
|
||||
if(data.success == true)
|
||||
$(dom).parent('div').remove();
|
||||
else
|
||||
alert("failed");
|
||||
},
|
||||
'timeout': 30000
|
||||
});
|
||||
}
|
||||
};
|
||||
</script>
|
Loading…
Reference in New Issue