You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
254 lines
9.0 KiB
254 lines
9.0 KiB
<?php
|
|
|
|
namespace app\api\controller\pass;
|
|
|
|
use app\api\controller\Controller;
|
|
use app\common\dm\Dm;
|
|
use app\common\dm\DmDB;
|
|
use app\common\exception\BaseException;
|
|
use think\Db;
|
|
|
|
class Create extends Controller
|
|
{
|
|
protected $token = '9c4cb25665cf08667c815420ab383cb5';
|
|
|
|
/**
|
|
* API基类初始化
|
|
* @throws BaseException
|
|
* @throws \think\exception\DbException
|
|
*/
|
|
public function _initialize()
|
|
{
|
|
$this->validateToken();
|
|
}
|
|
/**
|
|
* 创建客流统计数据
|
|
* @return array
|
|
* @throws \think\Exception
|
|
* @throws \think\exception\PDOException
|
|
*/
|
|
public function createPassengerFlow()
|
|
{
|
|
|
|
$data_json = base64_decode($this->request->param('data'));
|
|
$data = json_decode(html_entity_decode($data_json),true);
|
|
|
|
$dm = new Dm();
|
|
foreach ($data as $val) {
|
|
|
|
$queryWhere = ['groupId' => $val['groupId'],'granularity' => $val['granularity'],'statTime' => $val['statTime']];
|
|
$query = $dm->find('bt_passenger_flow',$queryWhere);
|
|
|
|
$groupRes = $dm->find('bt_passenger_monitor_group',['groupId' => $val['groupId']]);
|
|
$groupName = isset($groupRes['groupName']) ? $groupRes['groupName']:$val['groupName'];
|
|
|
|
$insert_arr = [
|
|
'groupId' => $val['groupId'],
|
|
'groupName' => $groupName,
|
|
'flowInNum' => $val['flowInNum'],
|
|
'flowOutNum' => $val['flowOutNum'],
|
|
'noRepeatInNum' => $val['noRepeatInNum'],
|
|
'noRepeatOutNum' => $val['noRepeatOutNum'],
|
|
'holdValue' => $val['holdValue'],
|
|
'createTime' => $val['createTime'],
|
|
'updateTime' => $val['updateTime'],
|
|
'netValue' => $val['netValue'],
|
|
'statTime' => $val['statTime'],
|
|
'granularity' => $val['granularity']
|
|
];
|
|
|
|
if ($query) {
|
|
$this->mergeYearlyData($insert_arr);
|
|
# 判断数据是否发生变化, 发生变化及更新
|
|
$queryUpdate = $dm->find('bt_passenger_flow',$insert_arr);
|
|
if (!$queryUpdate) {
|
|
$dm->update('bt_passenger_flow',$insert_arr,['id' => $query['id']]);
|
|
}
|
|
} else {
|
|
$dm->insert('bt_passenger_flow',$insert_arr);
|
|
}
|
|
}
|
|
|
|
return $this->renderSuccess();
|
|
}
|
|
|
|
/**
|
|
* 创建总客流统计数据
|
|
* @return array
|
|
* @throws \think\Exception
|
|
* @throws \think\exception\PDOException
|
|
*/
|
|
public function createPassengerFlowAll()
|
|
{
|
|
$data_json = base64_decode( $this->request->param('data'));
|
|
$data = json_decode(html_entity_decode($data_json),true);
|
|
|
|
$dm = new Dm();
|
|
foreach ($data as $val) {
|
|
|
|
$queryWhere = ['groupId' => $val['groupId'],'granularity' => $val['granularity'],'statTime' => $val['statTime'],'date'=>$val['date']];
|
|
$query = $dm->find('bt_passenger_flow_all',$queryWhere);
|
|
|
|
$groupRes = $dm->find('bt_passenger_monitor_group',['groupId' => $val['groupId']]);
|
|
$groupName = isset($groupRes['groupName']) ? $groupRes['groupName']:$val['groupName'];
|
|
|
|
$insert_arr = [
|
|
'groupId' => $val['groupId'],
|
|
'groupName' => $groupName,
|
|
'flowInNum' => $val['flowInNum'],
|
|
'flowOutNum' => $val['flowOutNum'],
|
|
'noRepeatInNum' => $val['noRepeatInNum'],
|
|
'noRepeatOutNum' => $val['noRepeatOutNum'],
|
|
'holdValue' => $val['holdValue'],
|
|
'createTime' => $val['createTime'],
|
|
'updateTime' => $val['updateTime'],
|
|
'netValue' => $val['netValue'],
|
|
'statTime' => $val['statTime'],
|
|
'granularity' => $val['granularity'],
|
|
'date' => $val['date']
|
|
];
|
|
|
|
if ($query) {
|
|
$this->mergeYearlyData($insert_arr);
|
|
$updateQuery = $dm->find('bt_passenger_flow_all',$insert_arr);
|
|
if (!$updateQuery) {
|
|
$dm->update('bt_passenger_flow_all',$insert_arr,['id' => $query['id']]);
|
|
}
|
|
} else {
|
|
|
|
$dm->insert('bt_passenger_flow_all',$insert_arr);
|
|
|
|
}
|
|
}
|
|
|
|
return $this->renderSuccess();
|
|
}
|
|
|
|
protected function mergeYearlyData(&$val)
|
|
{
|
|
if ($val['granularity'] == 'yearly' && date("Y") == '2023') {
|
|
$mergeData = [
|
|
'110' => [
|
|
'flowInNum' => 0,
|
|
'noRepeatInNum' => 0,
|
|
],
|
|
'210' => [
|
|
'flowInNum' => 0,
|
|
'noRepeatInNum' => 0,
|
|
],
|
|
'310' => [
|
|
'flowInNum' => 0,
|
|
'noRepeatInNum' => 0,
|
|
],
|
|
'510' => [
|
|
'flowInNum' => 0,
|
|
'noRepeatInNum' => 0,
|
|
],
|
|
];
|
|
|
|
$val['flowInNum'] = round($val['flowInNum']+$mergeData[$val['groupId']]['flowInNum']);
|
|
$val['noRepeatInNum'] = round($val['noRepeatInNum']+$mergeData[$val['groupId']]['noRepeatInNum']);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 创建总客流统计数据
|
|
* @return array
|
|
* @throws \think\Exception
|
|
* @throws \think\exception\PDOException
|
|
*/
|
|
public function createPassengerFlowReal()
|
|
{
|
|
$data_json = $this->request->param('data');
|
|
$data = json_decode(html_entity_decode($data_json),true);
|
|
|
|
$dm = new Dm();
|
|
foreach ($data as $val) {
|
|
|
|
$insert_arr = [
|
|
'groupId' => $val['groupId'],
|
|
'regionId' => $val['regionId'],
|
|
'statisticsTime' => $val['statisticsTime'],
|
|
'enter' => $val['enter'],
|
|
'exit' => $val['exit'],
|
|
'pass' => $val['pass'],
|
|
'holdValue' => $val['holdValue'],
|
|
'allEnter' => $val['allEnter'],
|
|
'allExit' => $val['allExit']
|
|
];
|
|
|
|
// query first
|
|
$query=$dm->find('bt_passenger_flow_real','"groupId"='."'{$val['groupId']}'");
|
|
if($query){
|
|
$dm->update('bt_passenger_flow_real',$insert_arr,'"id"='."'{$query['id']}'");
|
|
}else{
|
|
$dm->insert('bt_passenger_flow_real',$insert_arr);
|
|
}
|
|
}
|
|
|
|
return $this->renderSuccess();
|
|
}
|
|
|
|
public function createVideo()
|
|
{
|
|
$data_json = $this->request->param('data');
|
|
$data = json_decode(html_entity_decode($data_json),true);
|
|
|
|
$dm = new Dm();
|
|
foreach ($data as $val) {
|
|
|
|
$insert_arr = [
|
|
'cameraIndexCode' => $val['cameraIndexCode'],
|
|
'cameraName' => base64_decode($val['cameraName']),
|
|
'cameraType' => $val['cameraType'],
|
|
'cameraTypeName' => $val['cameraTypeName'],
|
|
'regionIndexCode' => $val['regionIndexCode'],
|
|
'regionName' => base64_decode($val['regionName']),
|
|
'transTypeName' => $val['transTypeName'],
|
|
'transType' => $val['transType'],
|
|
'createTime' => $val['createTime'],
|
|
'url' => $val['url']
|
|
];
|
|
#Db::table('bt_passenger_flow_real')->insert($insert_arr);
|
|
|
|
$dm->insert('bt_video',$insert_arr);
|
|
}
|
|
|
|
return $this->renderSuccess();
|
|
}
|
|
|
|
public function createGroup()
|
|
{
|
|
$data_json = base64_decode($this->request->param('data'));
|
|
$data = json_decode(html_entity_decode($data_json),true);
|
|
|
|
$dbarr= config('database')['connections']['dm'];
|
|
$dm = new Dm();
|
|
|
|
foreach ($data as $val) {
|
|
|
|
$query = $dm->find('bt_passenger_monitor_group','"groupId"='."'{$val['groupId']}'");
|
|
if (!empty($query)) continue;
|
|
|
|
$insert_arr = [
|
|
'groupId' => $val['groupId'],
|
|
'groupName' => $val['groupName'],
|
|
'groupType' => $val['groupType'],
|
|
'statType' => $val['statType'],
|
|
'regionId' => $val['regionId'],
|
|
'thirdPartCode' => $val['thirdPartCode'],
|
|
'workStartTime' => $val['workStartTime'],
|
|
'workEndTime' => $val['workEndTime'],
|
|
'holdBase' => $val['holdBase'],
|
|
'earlyWarningValue' => $val['earlyWarningValue'],
|
|
'warningValue' => $val['warningValue'],
|
|
'warningSwitch' => $val['warningSwitch']
|
|
];
|
|
$dm->insert('bt_passenger_monitor_group',$insert_arr);
|
|
}
|
|
|
|
return $this->renderSuccess();
|
|
}
|
|
|
|
|
|
}
|
|
|