Commit 7ce0251b authored by 冯超鹏's avatar 冯超鹏

no message

parent 6cff6c7d
......@@ -6,7 +6,7 @@ use Illuminate\Support\Facades\DB;
use App\Laravue\Models\Users;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Auth;
class SwooleCommandController extends Controller
{
//返回用户列表
......@@ -16,15 +16,17 @@ class SwooleCommandController extends Controller
$usercount = DB::table('users')->count();//获取用户数量
//查询设备类型
$count = DB::table('users as b')
->leftjoin('device as d','b.id','=','d.uid')
->leftjoin('device_type as t','d.dtype','=','t.tid')
->leftjoin('device as d', 'b.id', '=', 'd.uid')
->leftjoin('device_type as t', 'd.dtype', '=', 't.tid')
->selectRaw('b.name,count(IF(d.dtype=1,true,null)) AS type_1, COUNT(IF(t.tid=2, true, null)) AS type_2,COUNT(IF(t.tid=4, true, null)) AS type_4,COUNT(IF(t.tid=5, true, null)) AS type_5,COUNT(IF(t.tid=6, true, null)) AS type_6,COUNT(IF(t.tid=7, true, null)) AS type_7,COUNT(IF(t.tid=8, true, null)) AS type_8,COUNT(IF(t.tid=9, true, null)) AS type_9,COUNT(IF(t.tid=10, true, null)) AS type_10,COUNT(IF(t.tid=11, true, null)) AS type_11')
->groupBy('b.id')
->get();
$countdata = ['usercount' => $usercount, 'userdata' => $count];
return $this->jsonSuccessData($countdata);
}
public function chemicals(){
public function chemicals()
{
$databadevice = DB::table('device');
$devicelist = $databadevice
->whereIn('dtype', [1, 5, 10])
......@@ -40,7 +42,8 @@ class SwooleCommandController extends Controller
return $this->jsonSuccessData(['devicelist' => $devicelist, 'count' => $count]);
}
public function fire(){
public function fire()
{
$databadevice = DB::table('device');
$devicelist = $databadevice
->whereIn('dtype', [2, 4, 6, 7, 8, 9, 11])
......@@ -58,18 +61,32 @@ class SwooleCommandController extends Controller
//监测是否设备报警
public function alarm() {
$isalarm = DB::table('reportpolice')
->where('status','=','1')
->where('police','=','1')
->groupBy('id')
->select('devicenumber')
->get()->toArray();
if($isalarm){
return $this->jsonSuccessData($isalarm);
}else{
return $this->jsonErrorData(105,'当前无报警');
}
public function alarm()
{
$user = Auth::user();//获取当前用户信息
$isadmin = DB::table('users')->where([['name', '=', $user['name']], ['email', '=', $user['email']]])->first();
if (!is_null($isadmin)) {
$isalarm = DB::table('reportpolice')
->where('status', '=', '1')
->where('police', '=', '1')
->groupBy('id')
->select('devicenumber')
->get()->toArray();
} else {
$isalarm = DB::table('reportpolice')
->join('device as d','reportpolice.devicenumber','=','d.devicenum')
->where('reportpolice.status', '=', '1')
->where('reportpolice.police', '=', '1')
->where('d.uid', '=', Auth::id())
->groupBy('reportpolice.id')
->select('reportpolice.devicenumber')
->get()->toArray();
}
if ($isalarm) {
return $this->jsonSuccessData($isalarm);
} else {
return $this->jsonErrorData(105, '当前无报警');
}
}
}
\ No newline at end of file
......@@ -98,39 +98,44 @@ class SwooleCommandMeTcpController extends Controller
{
$davicedata = $this->stringdata(Redis::lpop('police'));
// 处理发送数据报警
$isdavice = DB::table('reportpolice')
->where('devicenumber', '=', $davicedata[0])
->select('status', 'endtime')
$isdevicenumm = DB::table('device')
->where('devicenum','=',$davicedata[0])
->first();
$type = json_decode(json_encode($isdavice), true);
//设备再次报警
if ($type['endtime'] != '' && $type['status'] == 2 && $davicedata[1] != 1){
$up = DB::table('reportpolice')
->where('devicenumber', '=', $davicedata[0])
->update(['endtime'=>'','status' => 1,'policestatus'=> $davicedata[1],'concentration' => $davicedata[2]]);
}
if($type['status'] == 1 && $type['endtime'] == '' && $davicedata[1] == 1){
$up = DB::table('reportpolice')
if($isdevicenumm){
$isdavice = DB::table('reportpolice')
->where('devicenumber', '=', $davicedata[0])
->update(['endtime'=>time(),'status' => 2,'policestatus'=> $davicedata[1]]);
}
if ($isdavice) {
//改成报警状态
if ($davicedata[1] != 1 && $type['endtime'] == '') {
->select('status', 'endtime')
->first();
$type = json_decode(json_encode($isdavice), true);
//设备再次报警
if ($type['endtime'] != '' && $type['status'] == 2 && $davicedata[1] != 1){
$up = DB::table('reportpolice')
->where('devicenumber', '=', $davicedata[0])
->update(['concentration' => $davicedata[2], 'policestatus' => $davicedata[1], 'status' => 1]);
->update(['endtime'=>'','status' => 1,'policestatus'=> $davicedata[1],'concentration' => $davicedata[2]]);
}
} else {
if ($davicedata[1] != 1) {
$add = DB::table('reportpolice')
->insertGetId(['devicenumber' => $davicedata[0], 'starttime' => time(), 'concentration' => $davicedata[2], 'policestatus' => $davicedata[1], 'status' => 1]);
if($type['status'] == 1 && $type['endtime'] == '' && $davicedata[1] == 1){
$up = DB::table('reportpolice')
->where('devicenumber', '=', $davicedata[0])
->update(['endtime'=>time(),'status' => 2,'policestatus'=> $davicedata[1]]);
}
if ($isdavice) {
//改成报警状态
if ($davicedata[1] != 1 && $type['endtime'] == '') {
$up = DB::table('reportpolice')
->where('devicenumber', '=', $davicedata[0])
->update(['concentration' => $davicedata[2], 'policestatus' => $davicedata[1], 'status' => 1]);
}
} else {
if ($davicedata[1] != 1) {
$add = DB::table('reportpolice')
->insertGetId(['devicenumber' => $davicedata[0], 'starttime' => time(), 'concentration' => $davicedata[2], 'policestatus' => $davicedata[1], 'status' => 1]);
}
}
$updavice = DB::table('device')
->where('devicenum', '=', $davicedata[0])
->update(['devicepolice' => $davicedata[1], 'nd' => $davicedata[2]]);
}
$updavice = DB::table('device')
->where('devicenum', '=', $davicedata[0])
->update(['devicepolice' => $davicedata[1], 'nd' => $davicedata[2]]);
}
}
\ No newline at end of file
......@@ -77,7 +77,6 @@ class Controller extends BaseController
$isadmin = DB::table('users')->where([['name', '=', $user['name']], ['email', '=', $user['email']]])->first();
return get_object_vars($isadmin)['isadmin'] == 1 ? '1' : null;
}
public function timeline($instructions)
{
return DB::table('timeline')->insertGetId(['instructions'=>$instructions,'operationip'=>$_SERVER["REMOTE_ADDR"],'timestamp'=>date("Y-m-d H:i:s",time())]);
......
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