Commit 3781ff76 authored by Administrator's avatar Administrator

回滚

parent ac06c1dd
Pipeline #57 failed with stages
......@@ -125,12 +125,19 @@ class DevicesController extends Controller
public function adddevice(Request $request)
{
//验证用户提交表单
$validator = Validator::make($request->all(), $this->getValidationRulesdevice(false));
$addDeviceData = $request->all();
$validator = Validator::make($addDeviceData, $this->getValidationRulesdevice(false));
if ($validator->fails()) {
return response()->json(['errors' => $validator->errors()], 403);
}
foreach ($addDeviceData as $k => $v) {
if ($k == 'isadmin') {
unset($addDeviceData[$k]);
}
}
$type = new Device();
return $this->jsonSuccessData($type->adddevice($request->all()));
return $this->jsonSuccessData($type->adddevice($addDeviceData, $request->input('isadmin') == 1 ? 1 : 2));
}
......@@ -188,7 +195,7 @@ class DevicesController extends Controller
->leftjoin('gas as g', "device.status", '=', 'g.id')
->leftjoin('BackgroundUser as u', "device.uid", '=', 'u.id')
->leftjoin('status as p', "device.devicepolice", '=', 'p.id')
->select('dy.tname', 'g.gas', 'device.*', 'p.status_name','u.nickname as usernickname')
->select('dy.tname', 'g.gas', 'device.*', 'p.status_name', 'u.nickname as usernickname')
->orderBy('device.id', 'desc')
->offset($pagenNum)
->limit($limit)
......@@ -230,7 +237,7 @@ class DevicesController extends Controller
->leftjoin('gas as g', "device.status", '=', 'g.id')
->leftjoin('BackgroundUser as u', "device.uid", '=', 'u.id')
->leftjoin('status as p', "device.devicepolice", '=', 'p.id')
->select('dy.tname', 'g.gas', 'device.*', 'p.status_name','u.nickname as usernickname')
->select('dy.tname', 'g.gas', 'device.*', 'p.status_name', 'u.nickname as usernickname')
->orderBy('device.id', 'desc')
->offset($pagenNum)
->limit($limit)
......@@ -250,7 +257,7 @@ class DevicesController extends Controller
public function deviceDataInfo($id)
{
$devicedata = Device::where('device.id', '=', $id)
->leftjoin('contactsuser as c', 'c.contactsid', '=', 'device.contactsid')
->leftjoin('contactsuser as c', 'c.contactsid', '=', 'device.id')
->select('c.*', 'device.deviceuuid', 'device.devicelinkman', 'device.devicephone', 'device.devicecoord')
->get();
$devicedatainfo = Device::where('id', '=', $id)
......@@ -258,17 +265,20 @@ class DevicesController extends Controller
->get();
return $this->jsonSuccessData(['devicedata' => $devicedata, 'devicedatainfo' => $devicedatainfo]);
}
// 返回设备地图详情信息
public function device_info($id){
public function device_info($id)
{
$devicedata = Device::where('device.id', '=', $id)
->leftjoin('device_type as dy', "device.dtype", '=', 'dy.tid')
->leftjoin('gas as g', "device.status", '=', 'g.id')
->leftjoin('BackgroundUser as u', "device.uid", '=', 'u.id')
->leftjoin('status as p', "device.devicepolice", '=', 'p.id')
->select('dy.tname', 'g.gas', 'device.*', 'p.status_name','u.nickname as usernickname')
->select('dy.tname', 'g.gas', 'device.*', 'p.status_name', 'u.nickname as usernickname')
->first();
return $this->jsonSuccessData($devicedata);
}
//搜索设备账号
public function deviceDataSearch(Request $request)
{
......@@ -288,31 +298,33 @@ class DevicesController extends Controller
* 将写入文件改为时序数据库!
* */
$dalen = Redis::llen('Devicesdata');//返回队列长度
$data = [];
if ($dalen > 0) {
for ($i = 0; $i < $dalen; $i++) {
array_push($data, unserialize(Redis::lpop('Devicesdata')));
}
}
if ($data != []) {
$this->devicemkdir($data); //写入文件
}
$devicelistopen = $this->devicelistopen();
if($devicelistopen != 105){
return $this->jsonSuccessData($devicelistopen);
}else{
return $this->jsonErrorData(105,'暂无数据');
$data = [];
if ($dalen > 0) {
for ($i = 0; $i < $dalen; $i++) {
array_push($data, unserialize(Redis::lpop('Devicesdata')));
}
}
if ($data != []) {
$this->devicemkdir($data); //写入文件
}
$devicelistopen = $this->devicelistopen();
if ($devicelistopen != 105) {
return $this->jsonSuccessData($devicelistopen);
} else {
return $this->jsonErrorData(105, '暂无数据');
}
}
//历史数据查询
public function detedevice(Request $request){
public function detedevice(Request $request)
{
$dete = $request->input('dete');
$devicetime = $this->devicetime($dete);
if($devicetime != 105){
$devicetime = $this->devicetime($dete);
if ($devicetime != 105) {
return $this->jsonSuccessData($devicetime);
}else{
return $this->jsonErrorData(105,'暂无数据');
} else {
return $this->jsonErrorData(105, '暂无数据');
}
}
......@@ -320,11 +332,11 @@ class DevicesController extends Controller
//返回设备当前报警
public function police()
{
$data = DB::table('reportpolice as r')
$data = DB::table('reportpolice as r')
->join('status as s', 'r.policestatus', '=', 's.id')
->select('r.*', 's.status_name')
->get();
return $this->jsonSuccessData($data);
return $this->jsonSuccessData($data);
}
......@@ -334,6 +346,11 @@ class DevicesController extends Controller
return $this->jsonSuccessData(DB::table('device')->where('delete', '=', '1')->count());
}
public function addUserDevice()
{
return $this->jsonSuccessData(DB::table('BackgroundUser')->where('state', '=', '2')->select('nickname', 'id')->get());
}
//返回设备废纸篓和禁用设备
public function deviceBasketList()
{
......@@ -369,7 +386,7 @@ class DevicesController extends Controller
//删除分类
return $this->jsonSuccessData(DB::table('device_type')->where('tid', '=', $id)->delete());
}
public function deviceLocation(Request $request)
{
$where = [];
......@@ -384,6 +401,7 @@ class DevicesController extends Controller
//返回用户安装位置
return $this->jsonSuccessData($data);
}
//返回消防监测
public function control(Request $request)
{
......@@ -393,11 +411,11 @@ class DevicesController extends Controller
if ($pagenNum === '' || $limit == '' || $type === '') {
return $this->jsonErrorData(105, '页数或limit不能为空');
}
if($type ==1){//返回消防监测
$wherein = [2,4,6,7,8,9,11];
}else{
if ($type == 1) {//返回消防监测
$wherein = [2, 4, 6, 7, 8, 9, 11];
} else {
//返回危化
$wherein = [1,5,10];
$wherein = [1, 5, 10];
}
$databadevice = DB::table('device');
$devicelist = $databadevice
......@@ -411,7 +429,7 @@ class DevicesController extends Controller
->limit($limit)
->get()->toArray();
$count = $databadevice
->whereIn('dtype',$wherein)
->whereIn('dtype', $wherein)
->count();
return $this->jsonSuccessData(['devicelist' => $devicelist, 'count' => $count]);
}
......@@ -435,7 +453,7 @@ class DevicesController extends Controller
'devicecoord' => 'sometimes|required',
'contactsid' => 'sometimes|required',//绑定联系人id
'deviceinfo' => 'sometimes|required',
'devicenumber' => 'required|unique:device,devicenumber|max:40'
'devicenumber' => 'sometimes|required|unique:device,devicenumber|max:40'
];
}
......@@ -459,19 +477,19 @@ class DevicesController extends Controller
private function devicemkdir($data)
{
$path = public_path().'/device/' . date('Y-m-d' . '/');
if (!is_dir($path)){
$path = public_path() . '/device/' . date('Y-m-d' . '/');
if (!is_dir($path)) {
mkdir($path);
}
file_put_contents($path . "devicelistdata.text", json_encode($data) . PHP_EOL, FILE_APPEND);
file_put_contents($path . "devicelistdata.text", json_encode($data) . PHP_EOL, FILE_APPEND);
$this->devicelistopen($path);
}
private function devicelistopen() :array
private function devicelistopen(): array
{
$path = public_path().'/device/' . date('Y-m-d' . '/');
if (is_file( $path . 'devicelistdata.text')) {
$path = public_path() . '/device/' . date('Y-m-d' . '/');
if (is_file($path . 'devicelistdata.text')) {
$myfile = file_get_contents($path . 'devicelistdata.text');
$exp = explode("\n", $myfile);
$datadevice = [];
......@@ -481,14 +499,15 @@ class DevicesController extends Controller
array_push($datadevice, json_decode($newstring1, true));
}
return $datadevice;
}else{
} else {
return 105;
}
}
private function devicetime($dete) {
$path = public_path().'/device/' . $dete . '/';
if (is_file( $path . 'devicelistdata.text')) {
private function devicetime($dete)
{
$path = public_path() . '/device/' . $dete . '/';
if (is_file($path . 'devicelistdata.text')) {
$myfile = file_get_contents($path . 'devicelistdata.text');
$exp = explode("\n", $myfile);
$datadevice = [];
......@@ -498,7 +517,7 @@ class DevicesController extends Controller
array_push($datadevice, json_decode($newstring1, true));
}
return $datadevice;
}else{
} else {
return 105;
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment