完成了dataservice中wsn接口的开发和调用。在heihe\view中添加了wsn数据选择子集的功能

This commit is contained in:
Li Jianxuan 2013-08-26 02:39:22 +00:00
parent a9a92ffacb
commit 7c6f3e3f0c
22 changed files with 267 additions and 69 deletions

View File

@ -1,4 +1,9 @@
<?php <?php
use \data\DataService;
use Helpers\View as view;
use Order\Order;
use Order\listener\OrderListener;
class DataController extends Zend_Controller_Action class DataController extends Zend_Controller_Action
{ {
private $limit=10; private $limit=10;
@ -704,6 +709,7 @@ class DataController extends Zend_Controller_Action
//特殊数据服务 //特殊数据服务
public function dataserviceAction() public function dataserviceAction()
{ {
$uuid = $this->_getParam('uuid'); $uuid = $this->_getParam('uuid');
if(empty($uuid)) if(empty($uuid))
@ -717,6 +723,9 @@ class DataController extends Zend_Controller_Action
//暂时只有wsn //暂时只有wsn
{ {
$this->_helper->layout->disableLayout();
$this->_helper->viewRenderer->setNoRender();
$data = array( $data = array(
"type"=>"wsn", //服务类型 "type"=>"wsn", //服务类型
"info"=>$info, //信息 dataservice 表中的字段 "info"=>$info, //信息 dataservice 表中的字段
@ -728,11 +737,13 @@ class DataController extends Zend_Controller_Action
if(empty($data['data'])) if(empty($data['data']))
{ {
$this->jsonexit(array("error"=>'数据接口错误,请联系管理员')); $this->jsonexit(array("error"=>'数据接口错误,请联系管理员'));
return true;
} }
if(!is_array($data['data'])) if(!is_array($data['data']))
{ {
$this->jsonexit(array("error"=>$data['data'])); $this->jsonexit(array("error"=>$data['data']));
return true;
} }
$this->_helper->layout->disableLayout(); $this->_helper->layout->disableLayout();
@ -748,35 +759,84 @@ class DataController extends Zend_Controller_Action
{ {
$this->_helper->layout->disableLayout(); $this->_helper->layout->disableLayout();
$this->_helper->viewRenderer->setNoRender(); $this->_helper->viewRenderer->setNoRender();
$type = $this->_getParam('type');
$uuid = $this->_getParam("uuid"); $uuid = $this->_getParam("uuid");
$sites = array("chk"=>$this->_getParam("siteid"));
$dataservice = new \data\DataService(); $dataservice = new DataService();
$info = $dataservice->get($uuid);
$dataservice = new \data\DataService(); if($type == 'var')
$data = array(
"type"=>"wsn", //服务类型
"info"=>$info, //信息 dataservice 表中的字段
"callback"=>"alert('ok')", //成功后的js回调函数
);
$data['data'] = $dataservice->getWsnData("var",$uuid,$sites);
if(empty($data['data']))
{ {
$this->jsonexit(array("error"=>'数据接口错误,请联系管理员')); $sites = array(
} "chk"=>$this->_getParam("siteid")
);
if(!is_array($data['data']))
{
$this->jsonexit(array("error"=>$data['data']));
}
$this->jsonexit($data); $info = $dataservice->get($uuid);
return true;
$data = array(
"type"=>"wsn", //服务类型
"info"=>$info, //信息 dataservice 表中的字段
"callback"=>"westdc.dataservice.wsn.Submit()", //成功后的js回调函数
);
$data['data'] = $dataservice->getWsnData("var",$uuid,$sites);
if(empty($data['data']))
{
$this->jsonexit(array("error"=>'数据接口错误,请联系管理员'));
return true;
}
if(!is_array($data['data']))
{
$this->jsonexit(array("error"=>$data['data']));
return true;
}
$this->jsonexit($data);
return true;
}
if($type == "submit")
{
$info = $dataservice->get($uuid);
$param = array(
"site" => $this->_getParam("site"),
);
$data = array(
"type"=>"wsn", //服务类型
"info"=>$info, //信息 dataservice 表中的字段
"callback"=>"westdc.dataservice.wsn.Submited()", //成功后的js回调函数
);
$data['data'] = $dataservice->getWsnData("submit",$uuid,$param);
if(empty($data['data']))
{
$this->jsonexit(array("error"=>'数据接口错误,请联系管理员'));
return true;
}
if(!is_array($data['data']))
{
$this->jsonexit(array("error"=>$data['data']));
return true;
}
$order = new Order();
$orderListener = new OrderListener();
@$order->events()->attachAggregate($orderListener);
$status = $order->addOrder($uuid,json_encode($data['data']['site'],JSON_NUMERIC_CHECK));
if($status !== true)
{
$this->jsonexit(array("error"=>$status));
return true;
}
$this->jsonexit($data);
return true;
}
} }
@ -1553,7 +1613,6 @@ class DataController extends Zend_Controller_Action
{ {
$this->view->pageID = "account-dataorder"; $this->view->pageID = "account-dataorder";
$ac = $this->_request->getParam('ac'); $ac = $this->_request->getParam('ac');
include_once("helper/view.php");
$uuid = $this->_request->getParam('uuid'); $uuid = $this->_request->getParam('uuid');
@ -1573,8 +1632,8 @@ class DataController extends Zend_Controller_Action
{ {
//存在历史遗留问题,原来的数据并不能保证唯一 //存在历史遗留问题,原来的数据并不能保证唯一
$order = new order\Order(); $order = new Order();
$orderListener = new order\listener\OrderListener(); $orderListener = new OrderListener();
@$order->events()->attachAggregate($orderListener); @$order->events()->attachAggregate($orderListener);
$state = $order->addOrder($uuid); $state = $order->addOrder($uuid);
@ -1582,18 +1641,18 @@ class DataController extends Zend_Controller_Action
{ {
if(!is_array($state)) if(!is_array($state))
{ {
$this->view->msg = \view::Msg('alert-error',$state); $this->view->msg = view::Msg('alert-error',$state);
}else{ }else{
$service_type = $order->serviceTypeTest($state['service_type']); $service_type = $order->serviceTypeTest($state['service_type']);
if($service_type !== false) if($service_type !== false)
{ {
\view::Post($this,$service_type,$state['service_url']."?href=".urlencode(\view::getHostLink()."/data/order/")."&uuid=".$state['uuid']."&uid=".$userid); view::Post($this,$service_type,$state['service_url']."?href=".urlencode(\view::getHostLink()."/data/order/")."&uuid=".$state['uuid']."&uid=".$userid);
}else{ }else{
$this->view->msg = \view::Msg('alert-error',"无法申请:此元数据的数据类型未知"); $this->view->msg = view::Msg('alert-error',"无法申请:此元数据的数据类型未知");
} }
} }
}else{ }else{
$this->view->msg = \view::Msg('alert-success',"添加成功!您可以继续浏览数据或是继续提交申请表"); $this->view->msg = view::Msg('alert-success',"添加成功!您可以继续浏览数据或是继续提交申请表");
} }
if (empty($ac)) $ac='offline1'; if (empty($ac)) $ac='offline1';
@ -1604,19 +1663,19 @@ class DataController extends Zend_Controller_Action
{ {
if(empty($uuid)) if(empty($uuid))
{ {
$this->view->msg = \view::Msg('alert-error',"无法申请:参数出错,请通过正确的途径访问"); $this->view->msg = view::Msg('alert-error',"无法申请:参数出错,请通过正确的途径访问");
} }
$order = new order\Order(); $order = new Order();
$orderListener = new order\listener\OrderListener(); $orderListener = new OrderListener();
@$order->events()->attachAggregate($orderListener); @$order->events()->attachAggregate($orderListener);
$state = $order->addOrder($uuid,$selections); $state = $order->addOrder($uuid,$selections);
if($state !== true) if($state !== true)
{ {
$this->view->msg = \view::Msg('alert-error',$state); $this->view->msg = view::Msg('alert-error',$state);
}else{ }else{
$this->view->msg = \view::Msg('alert-success',"添加成功!您可以继续浏览数据或是继续提交申请表"); $this->view->msg = view::Msg('alert-success',"添加成功!您可以继续浏览数据或是继续提交申请表");
} }
if (empty($ac)) $ac='offline1'; if (empty($ac)) $ac='offline1';
@ -1624,13 +1683,13 @@ class DataController extends Zend_Controller_Action
//删除申请 //删除申请
elseif ($del) { elseif ($del) {
$order = new order\Order(); $order = new Order();
$state = $order->del($del); $state = $order->del($del);
if($state !== true) if($state !== true)
{ {
$this->view->msg = \view::Msg('alert-error',$state); $this->view->msg = view::Msg('alert-error',$state);
}else{ }else{
$this->view->msg = \view::Msg('alert-success',"数据申请取消成功"); $this->view->msg = view::Msg('alert-success',"数据申请取消成功");
} }
$this->_redirect('/data/order'); $this->_redirect('/data/order');
} }
@ -1641,13 +1700,13 @@ class DataController extends Zend_Controller_Action
{ {
$apply = -1; $apply = -1;
} }
$order = new order\Order(); $order = new Order();
$state = $order->apply($apply); $state = $order->apply($apply);
if($state !== true) if($state !== true)
{ {
$this->view->msg = \view::Msg('alert-error',$state); $this->view->msg = view::Msg('alert-error',$state);
}else{ }else{
$this->view->msg = \view::Msg('alert-success',"提交成功您可以点击“提交离线申请”来生成PDF申请表"); $this->view->msg = view::Msg('alert-success',"提交成功您可以点击“提交离线申请”来生成PDF申请表");
} }
if (empty($ac)) $ac='offline2'; if (empty($ac)) $ac='offline2';
} }
@ -1694,7 +1753,7 @@ class DataController extends Zend_Controller_Action
//用户信息可以从SESSION中读取离线申请信息 //用户信息可以从SESSION中读取离线申请信息
//$sql="select * from users where id=?"; //$sql="select * from users where id=?";
$order = new order\Order(); $order = new Order();
$rows = $order->getOrderItemForPdf(); $rows = $order->getOrderItemForPdf();
$this->view->projectType = $order->projectType; $this->view->projectType = $order->projectType;
@ -1716,7 +1775,7 @@ class DataController extends Zend_Controller_Action
if (@$formData['save']) { if (@$formData['save']) {
$orderListener = new order\listener\OrderListener(); $orderListener = new OrderListener();
@$order->events()->attachAggregate($orderListener); @$order->events()->attachAggregate($orderListener);
@ -1726,7 +1785,7 @@ class DataController extends Zend_Controller_Action
if($s !== true) if($s !== true)
{ {
$this->view->error = \view::Msg('alert-error',$s); $this->view->error = view::Msg('alert-error',$s);
return true; return true;
} }

View File

@ -0,0 +1,33 @@
<?php
$this->headTitle($this->config->title->site);
$this->headTitle($this->config->title->data);
$this->headTitle('离线申请');
$this->headTitle()->setSeparator(' - ');
$this->breadcrumb('<a href="/">首页</a>');
$this->breadcrumb('<a href="/data">'.$this->config->title->data.'</a>');
$this->breadcrumb('离线申请');
$this->breadcrumb()->setSeparator(' > ');
$this->nav[] = array('link'=>"/data/order",'title'=>'数据蓝');
?>
<?= $this->render('breadcrumbs.phtml') ?>
<div class="row">
<div class="span3">
<div class="well sidebar-nav">
<?= $this->partial('account/left.phtml'); ?>
</div><!--/.well -->
</div><!--/span-->
<div class="span9">
<h3>数据篮</h3>
<hr />
<?php
if(!empty($this->msg))
{
echo $this->msg;
}
?>
<h2>请选择要下载的数据</h2>
<!-- /content -->
</div><!--/span-->
</div><!--/row-->
<script>$('#Nav-<?= $this->tabID?>').addClass("active");</script>

View File

@ -365,7 +365,8 @@ endforeach;
<?php else: ?> <?php else: ?>
<?php <?php
if(!empty($this->dataService)) { ?> if(!empty($this->dataService)) { ?>
<a href="javascript:void(0);" class="btn btn-primary btn-large btn-block" title="此数据需要选择要下载的子集" onclick="westdc.dataservice.choiceData('<?= $md->uuid ?>');"> <?php $this->theme->AppendPlus($this,'datepicker'); ?>
<a href="javascript:void(0);" class="btn btn-primary btn-large btn-block" title="此数据需要选择要下载的子集" onclick="westdc.dataservice.choiceData('<?= $md->uuid ?>',this);">
<?php }else{ ?> <?php }else{ ?>
<a href="/data/order/uuid/<?php echo $md->uuid; ?>" class="btn btn-primary btn-large btn-block" title="免费!离线申请此数据(在线数据和离线数据都可申请)"> <a href="/data/order/uuid/<?php echo $md->uuid; ?>" class="btn btn-primary btn-large btn-block" title="免费!离线申请此数据(在线数据和离线数据都可申请)">
<?php } ?> <?php } ?>
@ -517,4 +518,4 @@ var bound = {
<p>没有找到对应的元数据。</p> <p>没有找到对应的元数据。</p>
<?php endif;?> <?php endif;?>
</div> </div>
<script type="text/javascript" src="http://v3.jiathis.com/code_mini/jia.js?uid=1336100079460458" charset="utf-8"></script> <!--<script type="text/javascript" src="http://v3.jiathis.com/code_mini/jia.js?uid=1336100079460458" charset="utf-8"></script>-->

View File

@ -1,5 +1,9 @@
<?php <?php
namespace data; namespace data;
use Helpers\View as view;
use Helpers\Curl;
class DataService class DataService
{ {
private $db; //传入PDO对象. private $db; //传入PDO对象.
@ -34,19 +38,17 @@ class DataService
} }
public function getWsnData($type,$uuid = "",$param = ""){ public function getWsnData($type,$uuid = "",$param = ""){
include_once("helper/view.php");
$info = $this->get($uuid);
$dataservice = new \data\DataService();
$info = $dataservice->get($uuid);
$curl = new \helper\Curl(); $curl = new Curl();
if($type == 'site') if($type == 'site')
{ {
$param = array( $param = array(
//'uuid'=>$uuid, 'uuid'=>$uuid,
'uuid'=>'78e2423f-fe4a-4f9e-a368-c932afc5d257', ///TEST TEST TEST //'uuid'=> '78e2423f-fe4a-4f9e-a368-c932afc5d257', ///TEST TEST TEST
'uid'=>\view::User('id') 'uid'=> view::User('id')
); );
$data = $curl->request($info['service_url']."site/",$param,"POST"); $data = $curl->request($info['service_url']."site/",$param,"POST");
$data = json_decode($data['response'],TRUE); $data = json_decode($data['response'],TRUE);
@ -55,15 +57,27 @@ class DataService
if($type == 'var') if($type == 'var')
{ {
$param_temp = array( $param_temp = array(
//'uuid'=>$uuid, 'uuid'=>$uuid,
'uuid'=>'78e2423f-fe4a-4f9e-a368-c932afc5d257', ///TEST TEST TEST //'uuid'=> '78e2423f-fe4a-4f9e-a368-c932afc5d257', ///TEST TEST TEST
'uid'=>\view::User('id'), 'uid'=> view::User('id'),
); );
$param = array_merge($param,$param_temp); $param = array_merge($param,$param_temp);
$data = $curl->request($info['service_url']."var/",$param,"POST"); $data = $curl->request($info['service_url']."var/",$param,"POST");
$data = json_decode($data['response'],TRUE); $data = json_decode($data['response'],TRUE);
} }
if($type == 'submit')
{
$param_temp = array(
'uuid'=>$uuid,
//'uuid'=> '78e2423f-fe4a-4f9e-a368-c932afc5d257', ///TEST TEST TEST
'uid'=> view::User('id'),
);
$param = array_merge($param,$param_temp);
$data = $curl->request($info['service_url']."insert/",$param,"POST");
$data = json_decode($data['response'],TRUE);
}
if($data['status'] == 0) if($data['status'] == 0)
{ {
return $data['error']; return $data['error'];

View File

@ -54,6 +54,7 @@ westdc.dataservice = {
$.colorbox({ $.colorbox({
initialHeight: '0', initialHeight: '0',
initialWidth: '0', initialWidth: '0',
maxWidth : '80%',
html: html, html: html,
opacity: '0.3', opacity: '0.3',
onComplete: function(){ onComplete: function(){
@ -91,6 +92,7 @@ westdc.dataservice.wsn = {
html = westdc.dataservice.wsn.dialog.vars(data); html = westdc.dataservice.wsn.dialog.vars(data);
westdc.dataservice.creatWindow(html); westdc.dataservice.creatWindow(html);
westdc.dataservice.wsn._init.vars();
}, },
'timeout': 30000, 'timeout': 30000,
@ -99,6 +101,45 @@ westdc.dataservice.wsn = {
} }
}); });
}, },
Submit : function(){
$.ajax({
'type':"POST",
'url':'/data/wsn/',
'data':$('#dataservice-wsn-form').serialize(),
'success':function(data){
if(typeof(data) == 'undefined')
{
alert("数据源错误,请联系管理员");
return false;
}
if(!$.isEmptyObject(data.error))
{
alert(data.error);
return false;
}
if($.isEmptyObject(data.data))
{
alert("提交失败,可能是服务器通信错误,请联系管理员");
return false;
}
if(data.data.success == 1)
{
window.location = '/data/order/ac/offline1';
return true;
}else{
alert('提交失败,请重试');
return false;
}
},
'timeout': 30000,
'error': function(){
alert('出现错误,请刷新后重试');
}
});
},
dialog : { dialog : {
site : function(data){ site : function(data){
this.input = new Array(); this.input = new Array();
@ -124,29 +165,67 @@ westdc.dataservice.wsn = {
return this.HTML; return this.HTML;
}, },
vars : function(data){ vars : function(data){
this.input = new Array(); this.selects = "";
this.uls = new Array();
for(i in data.data) for(i in data.data)
{ {
for(i in data.data) this.input = new Array();
this.li = '<label class="checkbox">' this.input.push('<label class="checkbox inline"><input type="checkbox" class="wsnctl-select-all" value="-1" name="site['+i+'][var]" checked="checked" /> 全选</label>');
+ '<input type="checkbox" value="' + data.data[i].varid + '" name="siteid[]" checked="checked" /> ' for(x in data.data[i].var)
+ data.data[i].nameview {
this.li = '<label class="checkbox inline">'
+ '<input class="wsnctl-select" type="checkbox" value="' + data.data[i].var[x]['varid'] + '" name="site['+i+'][var][]" checked="checked" disabled="disabled" /> '
+ data.data[i].var[x]['nameview']
+ '</label>'; + '</label>';
this.input.push(this.li); this.input.push(this.li);
}
this.timemap = '<div class="wsnctl-time">数据时间范围: '
+ '<input class="wsnctl-timestart" type="text" name="site['+i+'][starttime]" value="' + data.data[i].starttime + '" /> - '
+ '<input class="wsnctl-timeend" type="text" name="site['+i+'][endtime]" value="' + data.data[i].endtime + '" />'
+ '</div>';
this.uls.push('<div class="wsnctl" rel="'+i+'" style="float:left"><h4>观测点:'+data.data[i].name+'</h4>可下载的变量: '+ this.input.join("") + this.timemap + '<hr /></div>');
} }
this.selects = this.uls.join("");
this.HTML = '<div class=""><div class="modal-header"><h3>'+data.info.service_title+'</h3></div>' this.HTML = '<div class=""><div class="modal-header"><h3>'+data.info.service_title+'</h3></div>'
+ '<div class="modal-body"><form id="dataservice-wsn-form">' + '<div class="modal-body"><form id="dataservice-wsn-form">'
+ '<div>请选择需要下载的变量</div>'
+ '<div>' + '<div>'
+ this.input.join("") + this.selects
+ '</div>' + '</div>'
+ '<input type="hidden" name="uuid" value="'+data.uuid+'" />' + '<input type="hidden" name="uuid" value="'+data.info.uuid+'" />'
+ '<input type="hidden" name="type" value="var" />' + '<input type="hidden" name="type" value="submit" />'
+ '</form></div>' + '</form></div>'
+ '<div class="modal-footer"><a href="javascript:void(0);" class="btn btn-primary confirm_yes" onclick=' + data.callback + '>提交</a>' + '<div class="modal-footer"><a href="javascript:void(0);" class="btn btn-primary confirm_yes" onclick=' + data.callback + '>提交</a>'
+ '<a href="javascript:void(0);" class="btn confirm_no">取消</a></div></div>'; + '<a href="javascript:void(0);" class="btn confirm_no">取消</a></div></div>';
return this.HTML; return this.HTML;
}
},
_init : {
vars : function(){
$('.wsnctl').each(function(index, element) {
_this = $(this);
siteid = $(this).attr('rel');
timestart = $(this).children('.wsnctl-time').children('.wsnctl-timestart');
timeend = $(this).children('.wsnctl-time').children('.wsnctl-timeend');
year_start=(timestart).val().substr(0,4);
month_start=parseInt((timestart).val().substr(5,2))-1;
day_start=parseInt((timestart).val().substr(8,2));
year_end=(timeend.val()).substr(0,4);
month_end=parseInt((timeend.val()).substr(5,2))-1;
day_end=parseInt((timeend.val()).substr(8,2))
timestart.datepicker({ minDate: new Date(year_start, month_start, day_start), maxDate: new Date(year_end, month_end, day_end) });
timeend.datepicker({ minDate: new Date(year_start, month_start, day_start), maxDate: new Date(year_end, month_end, day_end) });
$(this).find('.wsnctl-select-all').click(function(e) {
if($(this).attr('checked') == 'checked')
{
_this.find('.wsnctl-select').attr('disabled','disabled');
}else{
_this.find('.wsnctl-select').removeAttr('disabled');
}
});
});
} }
} }
} }

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 418 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 312 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 205 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 262 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 348 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 207 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 278 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 328 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.2 KiB

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long