作者 郭文星

123

... ... @@ -16,6 +16,7 @@ class Jiangxingapi extends Api
protected $dam_seepagesql = "reservoir_dam_seepage";//渗流sql
protected $dam_isotonicsql = "reservoir_dam_isotonic";//渗压sql
protected $dam_displacementsql = "reservoir_dam_displacement";//坝体位移sql
protected $reservoir_rain_flowsql = "reservoir_rain_flow";//流量sql
public function _initialize()
{
... ... @@ -412,6 +413,89 @@ class Jiangxingapi extends Api
}
}
/**
*添加坝体位移信息
* @return void
*/
public function flow(){
$number=$this->request->param("number");//设备编号
$flow=$this->request->param("flow");//瞬时流量
$accumulate_flow=$this->request->param("accumulate_flow");//瞬时流量
$reporttime=$this->request->param("reporttime");//检测时间 1704780600000
$createtime=time();//创建时间
try {
$equipment=Db::name("reservoir_equipment")->where('type',7)->where("deviceId",$number)->find();
if(empty($equipment)){
$this->error("设备编号错误");
}
//重组数组
$data=[
"number"=>$number,
"accumulate_flow"=>$accumulate_flow,
"flow"=>$flow,
"reporttime"=>$reporttime,
"createtime"=>$createtime,
"reservoir_id"=>$equipment['reservoir_id'],
"updatetime"=>$createtime,
];
$res=Db::name($this->reservoir_rain_flowsql)->insert($data);
$this->success("流量信息插入成功");
}catch (ErrorException $exception){
//写入记录失败表
$fail_data=json_encode($data);
$fail_data=[
"createtime"=>$createtime,
"fail_data"=>$fail_data,
"number"=>$number,
];
$res=Db::name("jxapi_fail_log")->insert($fail_data);
$this->error("流量信息插入失败");
}
}
/**
* 批量添加坝体位移信息
* @return void
*/
public function batch_flow(){
$param=$this->request->param();//设备编号
$flow_data=$param['flow_data'];
if(empty($flow_data)){
$this->error("坝体位移信息不能为空");
}
$createtime=time();//创建时间
try {
foreach ($flow_data as $k=>$v){
$equipment=Db::name("reservoir_equipment")->where('type',7)->where("deviceId",$v['number'])->find();
if(empty($equipment)){
$this->error($v['number'].":坝体位移设备编号错误");
continue;
}
$data[$k]=[
"number"=>$v['number'],
"accumulate_flow"=>$v['accumulate_flow'],
"flow"=>$v['flow'],
"reporttime"=>$v['reporttime']*1000,
"createtime"=>$v['reporttime'],
"reservoir_id"=>$equipment['reservoir_id'],
"updatetime"=>$createtime,
];
}
$res=Db::name($this->dam_displacementsql)->insertAll($data);
$this->success("流量信息插入成功");
}catch (ErrorException $exception ){
//写入记录失败表
$fail_data=json_encode($data);
$fail_data=[
"createtime"=>$createtime,
"fail_data"=>$fail_data,
];
$res=Db::name("jxapi_fail_log")->insert($fail_data);
$this->error("流量信息插入失败");
}
}
/**
* 批量添加坝体位移信息
* @return void
*/
... ...