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.
144 lines
4.4 KiB
144 lines
4.4 KiB
1 year ago
|
<?php
|
||
|
|
||
|
namespace app\adminapi\controller\v1\ipc;
|
||
|
|
||
|
use app\services\user\IpcServices;
|
||
|
|
||
|
use app\services\crud\SchoolGradeClassServices;
|
||
|
use app\services\crud\SchoolClassIpcServices;
|
||
|
|
||
|
use app\adminapi\controller\AuthController;
|
||
|
use think\facade\App;
|
||
|
|
||
|
class Ipc extends AuthController
|
||
|
{
|
||
|
|
||
|
public function __construct(App $app, IpcServices $services)
|
||
|
{
|
||
|
parent::__construct($app);
|
||
|
$this->services = $services;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 摄像头列表
|
||
|
* @return mixed
|
||
|
*/
|
||
|
public function index()
|
||
|
{
|
||
|
$res = $this->services->IpcQueryDeviceRequest();
|
||
|
$lits = [];
|
||
|
if ($res['success'] == true) {
|
||
|
$obj = $res['data'];
|
||
|
|
||
|
if (is_array($obj->deviceInfo)) {
|
||
|
$lits = $obj->deviceInfo;
|
||
|
}
|
||
|
$arr = [
|
||
|
'ONLINE' => '设备在线',
|
||
|
'OFFLINE' => '设备离线',
|
||
|
'UNACTIVE' => '设备未激活',
|
||
|
'DISABLE' => '设备已禁用',
|
||
|
];
|
||
|
foreach ($lits as $value) {
|
||
|
$dateTime = strtotime($value->utcCreate);
|
||
|
$value->utcCreate = date('Y-m-d H:i:s', $dateTime);
|
||
|
$value->deviceStatus = $arr[$value->deviceStatus];
|
||
|
}
|
||
|
return app('json')->success([
|
||
|
'count' => $res['total'],
|
||
|
'list' => $lits,
|
||
|
]);
|
||
|
}
|
||
|
return app('json')->fail($res);
|
||
|
}
|
||
|
|
||
|
public function create()
|
||
|
{
|
||
|
$data = $this->request->getMore([
|
||
|
['iotId', '']
|
||
|
]);
|
||
|
return app('json')->success($this->services->getCrudForm($data));
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 保存数据
|
||
|
*/
|
||
|
public function save()
|
||
|
{
|
||
|
$data = $this->request->postMore([
|
||
|
['class_code', ''],
|
||
|
['iot_id', ''],
|
||
|
['create_time', date('Y-m-d H:i:s', time())],
|
||
|
]);
|
||
|
|
||
|
if (empty($data['class_code'])) {
|
||
|
return app('json')->fail(500061);
|
||
|
}
|
||
|
if (empty($data['iot_id'])) {
|
||
|
return app('json')->fail(500063);
|
||
|
}
|
||
|
|
||
|
$SchoolGradeClassServices = app()->make(SchoolGradeClassServices::class);
|
||
|
$classData = $SchoolGradeClassServices->selectClassCodeData($data['class_code']);
|
||
|
if ($classData === true) {
|
||
|
return app('json')->fail(500062);
|
||
|
}
|
||
|
|
||
|
$res = $this->services->DitDeviceNicknameInfo($data['iot_id'], $data['class_code']);
|
||
|
|
||
|
if ($res['success'] == true) {
|
||
|
// 添加设备连续录像计划
|
||
|
$this->services->AddRecordPlanDevice($data['iot_id']);
|
||
|
// 设置设备云存储时间
|
||
|
$this->services->SetDeviceRecordLifeCycle($data['iot_id']);
|
||
|
|
||
|
// 设置接口备注成功,数据入库
|
||
|
$SchoolClassIpcServices = app()->make(SchoolClassIpcServices::class);
|
||
|
|
||
|
$findData = $SchoolClassIpcServices->selectDataByIotId($data['iot_id']);
|
||
|
|
||
|
if (empty($findData)) {
|
||
|
// 新增
|
||
|
$data['class_id'] = $classData['id'];
|
||
|
$SchoolClassIpcServices->crudSave($data);
|
||
|
} else {
|
||
|
// 修改
|
||
|
$ditData = [
|
||
|
'update_time' => date('Y-m-d H:i:s', time()),
|
||
|
'class_code' => $data['class_code'],
|
||
|
'class_id' => $classData['id'],
|
||
|
];
|
||
|
$SchoolClassIpcServices->crudUpdate($findData['id'], $ditData);
|
||
|
}
|
||
|
return app('json')->success(100010);
|
||
|
}
|
||
|
return app('json')->fail($res);
|
||
|
}
|
||
|
|
||
|
public function getRecordTime()
|
||
|
{
|
||
|
$resultData = $this->services->getRecordForm();
|
||
|
return app('json')->success($resultData);
|
||
|
}
|
||
|
|
||
|
public function setRecordTime()
|
||
|
{
|
||
|
$data = $this->request->postMore([
|
||
|
['start_day', 0],
|
||
|
['end_day', 0],
|
||
|
['start_time', 0],
|
||
|
['end_time', 0]
|
||
|
]);
|
||
|
|
||
|
validate(\app\adminapi\validate\ipc\IpcValidate::class)->check($data);
|
||
|
if ($data['start_day'] > $data['end_day'] || $data['start_time'] > $data['end_time']) {
|
||
|
return app('json')->fail('开始的天数/时间,不可以大于结束的天数/时间');
|
||
|
}
|
||
|
// 更新时间模版
|
||
|
$this->services->UpdateTimeTemplate($data['start_day'], $data['end_day'], $data['start_time'], $data['end_time']);
|
||
|
// 更新录像计划
|
||
|
$this->services->UpdateRecordPlan();
|
||
|
return app('json')->success(100010);
|
||
|
}
|
||
|
}
|