diff --git a/app/Http/Controllers/Auth/SwooleCommandMeTcpController.php b/app/Http/Controllers/Auth/SwooleCommandMeTcpController.php index d5ef87c6ad2b49a75c6f8f687318a5b664ec19cf..8a3aa5d029d227d9346de5e545473b86dfad0947 100644 --- a/app/Http/Controllers/Auth/SwooleCommandMeTcpController.php +++ b/app/Http/Controllers/Auth/SwooleCommandMeTcpController.php @@ -16,12 +16,29 @@ class SwooleCommandMeTcpController extends Controller { if ($data != '') { $datadevice = $this->stringdata($data); - Redis::set('sbjc:' . $datadevice[0], $data); - $this->dbdevice($this->stringdata($data)); + Redis::set('dbtype',0); + if(Redis::get('sbjc:' . $datadevice[0]) == ''){ + Redis::set('sbjc:' . $datadevice[0], $data); + $this->dbdevice($this->stringdata($data)); + }else if (Redis::get('sbjc:' . $datadevice[0]) != $data){ + $this->dbdevice($this->stringdata($data)); + Redis::set('sbjc:' . $datadevice[0], $data); + } Redis::lpush('police',$data); $this->police(); } + $dalen = Redis::llen('Devicesdata');//返回队列长度 + if ($dalen > 5000 ) { //当队列值达到巅峰以åŽåˆ‡æ¢æ•°æ®åº“ + Redis::select(1);//使用备用数æ®åº“//释放主数æ®åº“ + Redis::set('dbtype',1); + $this->deleteDbRedis(); + } + if($dalen > 5000 && Redis::get('dbtype') == 1){ + Redis::select(0); + Redis::set('dbtype',0); + $this->deleteDb(); + } } //分割å—符串 @@ -44,6 +61,18 @@ class SwooleCommandMeTcpController extends Controller } return $arrdata; } + //清楚指定数æ®åº“ redis + private function deleteDbRedis (){ + Redis::select(0); + Redis::flushdb(); + Redis::select(1); + } + + private function deleteDb(){ + Redis::select(1); + Redis::flushdb(); + Redis::select(0); + } //查询出返回值 private function dbdevice($data = []) @@ -58,12 +87,9 @@ class SwooleCommandMeTcpController extends Controller ->leftjoin('status as s', 's.id', '=', 'd.devicepolice') ->select('d.devicenum', 'd.username', 'd.deviceremark', 'd.devicelinkman', 'd.devicephone', 'd.deviceinfo', 't.tname', 'g.gas', 'c.danwei', 's.status_name') ->first(); - Redis::lPush('Devicesdata', serialize($devicedata));//进入队列进行 - $dalen = Redis::llen('Devicesdata');//返回队列长度 - if ($dalen == 2) { - $Devices->equipment();//推é€å‰å° + if($devicedata != ''){ + Redis::lPush('Devicesdata', serialize($devicedata));//进入队列进行 } - } } diff --git a/app/Http/Controllers/DevicesController.php b/app/Http/Controllers/DevicesController.php index 8c128bf26c67826de1fd9e98412b0bbf304c08ff..486d5393b988d237611aa580fc3ddb2f9f78d93f 100644 --- a/app/Http/Controllers/DevicesController.php +++ b/app/Http/Controllers/DevicesController.php @@ -15,6 +15,7 @@ use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Hash; use Illuminate\Support\Facades\Redis; use Validator; + class DevicesController extends Controller { //设备列表 @@ -23,14 +24,15 @@ class DevicesController extends Controller * type ä¸ä¼ 默认是第一个 * @type 设备类型id * */ - public function devicelist(Request $request){ + public function devicelist(Request $request) + { $type = $request->input('type');//设备类型id - $pagenNum=$request->input('page')-1;//页数 + $pagenNum = $request->input('page') - 1;//页数 $limit = $request->input('limit'); - if($pagenNum === '' || $limit == ''){ - return $this->jsonErrorData(105,'页数或limitä¸èƒ½ä¸ºç©º'); + if ($pagenNum === '' || $limit == '') { + return $this->jsonErrorData(105, '页数或limitä¸èƒ½ä¸ºç©º'); } - return $this->jsonSuccessData($this->whertype($type==''? '1':$type,$pagenNum,$limit)); + return $this->jsonSuccessData($this->whertype($type == '' ? '1' : $type, $pagenNum, $limit)); } //用户设备列表 @@ -39,73 +41,77 @@ class DevicesController extends Controller * type ä¸ä¼ 默认是第一个 * @type 设备类型id * */ - public function userdevicelist(Request $request){ + public function userdevicelist(Request $request) + { $type = $request->input('type');//设备类型id - $pagenNum=$request->input('page')-1;//页数 + $pagenNum = $request->input('page') - 1;//页数 $limit = $request->input('limit'); - if($pagenNum === '' || $limit == ''){ - return $this->jsonErrorData(105,'页数或limitä¸èƒ½ä¸ºç©º'); + if ($pagenNum === '' || $limit == '') { + return $this->jsonErrorData(105, '页数或limitä¸èƒ½ä¸ºç©º'); } - return $this->jsonSuccessData($this->userdevice($type==''? '1':$type,$pagenNum,$limit)); + return $this->jsonSuccessData($this->userdevice($type == '' ? '1' : $type, $pagenNum, $limit)); } + /* * åˆ é™¤è®¾å¤‡ * type 1==é€»è¾‘åˆ é™¤ * type 2== 物ç†åˆ 除 * */ - public function deletedecice(Request $request){ - $type = (int)$request->input('type'); + public function deletedecice(Request $request) + { + $type = (int)$request->input('type'); $deviceid = (int)$request->input('deviceid');//设备id - if ($type == '' || $deviceid == ''){ - return $this->jsonErrorData(105,'å‚æ•°ä¸èƒ½ä¸ºç©º'); + if ($type == '' || $deviceid == '') { + return $this->jsonErrorData(105, 'å‚æ•°ä¸èƒ½ä¸ºç©º'); } - if ($type == 1){//é€»è¾‘åˆ é™¤ - $dete = Device::where('id','=',$deviceid) + if ($type == 1) {//é€»è¾‘åˆ é™¤ + $dete = Device::where('id', '=', $deviceid) ->value('delete'); - if ($dete != 1){ - $update = Device::where('id','=',$deviceid) - ->update(['delete'=>1]); + if ($dete != 1) { + $update = Device::where('id', '=', $deviceid) + ->update(['delete' => 1]); return $this->jsonSuccessData($update); - }else{ - return $this->jsonErrorData(105,'æ•°æ®å¼‚常'); + } else { + return $this->jsonErrorData(105, 'æ•°æ®å¼‚常'); } - }else if ($type == 2){//物ç†åˆ 除 - $dete = Device::where('id','=',$deviceid) + } else if ($type == 2) {//物ç†åˆ 除 + $dete = Device::where('id', '=', $deviceid) ->value('delete'); - if ($dete != 2){ - $delete = Device::where('id','=',$deviceid) + if ($dete != 2) { + $delete = Device::where('id', '=', $deviceid) ->delete(); return $this->jsonSuccessData($delete); - }else{ - return $this->jsonErrorData(105,'æ•°æ®å¼‚常'); + } else { + return $this->jsonErrorData(105, 'æ•°æ®å¼‚常'); } } } //è¿”å›žé€»è¾‘åˆ é™¤çš„è®¾å¤‡å’Œä¿®å¤è®¾å¤‡ - public function physicsdelete(Request $request){ + public function physicsdelete(Request $request) + { $deviceid = $request->input('deviceid'); $databadevice = DB::table('device'); - if($_POST){ + if ($_POST) { $up = $databadevice - ->where('id','=',$deviceid) - ->update(['delete'=>2]); + ->where('id', '=', $deviceid) + ->update(['delete' => 2]); return $this->jsonSuccessData($up); - }else{ + } else { //返回物ç†åˆ 除设备列表 - $type = (int)$request->input('type');//设备类型 - $pagenNum=$request->input('page')-1;//页数 + $type = (int)$request->input('type');//设备类型 + $pagenNum = $request->input('page') - 1;//页数 $limit = $request->input('limit');//æ¡æ•° - if($pagenNum === '' || $limit == ''){ - return $this->jsonErrorData(105,'页数或limitä¸èƒ½ä¸ºç©º'); + if ($pagenNum === '' || $limit == '') { + return $this->jsonErrorData(105, '页数或limitä¸èƒ½ä¸ºç©º'); } $devicelist = $databadevice - ->where('dtype','=',$type == '' ? '1':$type) - ->where('delete','=','1')//è®¾å¤‡é€»è¾‘åˆ é™¤çŠ¶æ€ - ->join('device_type as dy',"device.dtype",'=','dy.tid') - ->join('gas as g',"device.status",'=','g.id') - ->select('dy.tname','g.gas','device.*') + ->where('dtype', '=', $type == '' ? '1' : $type) + ->where('delete', '=', '1')//è®¾å¤‡é€»è¾‘åˆ é™¤çŠ¶æ€ + ->join('device_type as dy', "device.dtype", '=', 'dy.tid') + ->join('gas as g', "device.status", '=', 'g.id') + ->select('dy.tname', 'g.gas', 'device.*') ->orderBy('device.id', 'desc') ->offset($pagenNum) ->limit($limit) @@ -116,7 +122,8 @@ class DevicesController extends Controller } //æ·»åŠ è®¾å¤‡ - public function adddevice(Request $request){ + public function adddevice(Request $request) + { //验è¯ç”¨æˆ·æäº¤è¡¨å• $validator = Validator::make($request->all(), $this->getValidationRulesdevice(false)); if ($validator->fails()) { @@ -127,192 +134,241 @@ class DevicesController extends Controller } - //编辑设备 - public function updatedevice(Request $request){ + //编辑设备 + public function updatedevice(Request $request) + { $deid = $request->input('deid'); $data = $request->all(); - if(is_null($deid)){ - return $this->jsonErrorData(105,'设备IDä¸èƒ½ä¸ºç©º'); + if (is_null($deid)) { + return $this->jsonErrorData(105, '设备IDä¸èƒ½ä¸ºç©º'); } - if ($_POST){ + if ($_POST) { $validator = Validator::make($request->all(), $this->getValidationRulesupdevice(false)); if ($validator->fails()) { return response()->json(['errors' => $validator->errors()], 403); } - foreach ($data as $k=>$v){ + foreach ($data as $k => $v) { if ($k == 'deid') { unset($data[$k]); } } - return $this->jsonSuccessData(Device::where('id','=',$deid)->update($data)); - }else{ + return $this->jsonSuccessData(Device::where('id', '=', $deid)->update($data)); + } else { $devi = DB::table('device as de') - ->where('de.id','=',$deid) - ->leftjoin('device_type as dt','de.dtype','=','dt.tid') - ->leftjoin('gas','de.status','=','gas.id') - ->leftjoin('danwei as da','de.devicemonad','=','da.id') - ->select('dt.*','gas.*','da.*','de.*') + ->where('de.id', '=', $deid) + ->leftjoin('device_type as dt', 'de.dtype', '=', 'dt.tid') + ->leftjoin('gas', 'de.status', '=', 'gas.id') + ->leftjoin('danwei as da', 'de.devicemonad', '=', 'da.id') + ->select('dt.*', 'gas.*', 'da.*', 'de.*') ->first(); return $this->jsonSuccessData($devi); } } + //返回设备类型和å•ä½å’Œä»‹è´¨ - public function devicetype(){ + public function devicetype() + { $gas = DB::table('gas')->get(); $danwei = DB::table('danwei')->get(); $devicetypecount = DB::table('device_type as t') - ->leftjoin('device as d', 'd.dtype','=','t.tid') + ->leftjoin('device as d', 'd.dtype', '=', 't.tid') ->selectRaw('t.*,count(d.id) as counnum') ->groupBy('t.tid') ->get(); - return $this->jsonSuccessData(['devicetype'=>$devicetypecount,'gas'=>$gas,'danwei'=>$danwei]); + return $this->jsonSuccessData(['devicetype' => $devicetypecount, 'gas' => $gas, 'danwei' => $danwei]); } + //返回设备列表 - private function whertype($type,$pagenNum,$limit) : array { + private function whertype($type, $pagenNum, $limit): array + { $databadevice = DB::table('device'); $devicelist = $databadevice - ->where('dtype','=',$type) + ->where('dtype', '=', $type) //->where('delete','=','2')//设备ä¸æ˜¯åˆ é™¤çŠ¶æ€ //->where('devicestatus','=','1')// - ->leftjoin('device_type as dy',"device.dtype",'=','dy.tid') - ->leftjoin('gas as g',"device.status",'=','g.id') - ->leftjoin('status as p',"device.devicepolice",'=','p.id') - ->select('dy.tname','g.gas','device.*','p.status_name') + ->leftjoin('device_type as dy', "device.dtype", '=', 'dy.tid') + ->leftjoin('gas as g', "device.status", '=', 'g.id') + ->leftjoin('status as p', "device.devicepolice", '=', 'p.id') + ->select('dy.tname', 'g.gas', 'device.*', 'p.status_name') ->orderBy('device.id', 'desc') ->offset($pagenNum) ->limit($limit) ->get()->toArray(); $count = $databadevice - ->where('dtype','=',$type) + ->where('dtype', '=', $type) //->where('delete','=','2')//设备ä¸æ˜¯åˆ é™¤çŠ¶æ€ //->where('devicestatus','=','1')// ->count(); - return ['devicelist'=>$devicelist,'count'=>$count]; + return ['devicelist' => $devicelist, 'count' => $count]; } //返回用户设备列表 - private function userdevice($type,$pagenNum,$limit) : array { + private function userdevice($type, $pagenNum, $limit): array + { $databadevice = DB::table('device'); $devicelist = $databadevice - ->where('dtype','=',$type) - ->where('uid','=',Auth::id()) + ->where('dtype', '=', $type) + ->where('uid', '=', Auth::id()) //->where('delete','=','2')//设备ä¸æ˜¯åˆ é™¤çŠ¶æ€ //->where('devicestatus','=','1')// - ->leftjoin('device_type as dy',"device.dtype",'=','dy.tid') - ->leftjoin('gas as g',"device.status",'=','g.id') - ->leftjoin('status as p',"device.devicepolice",'=','p.id') - ->select('dy.tname','g.gas','device.*','p.status_name') + ->leftjoin('device_type as dy', "device.dtype", '=', 'dy.tid') + ->leftjoin('gas as g', "device.status", '=', 'g.id') + ->leftjoin('status as p', "device.devicepolice", '=', 'p.id') + ->select('dy.tname', 'g.gas', 'device.*', 'p.status_name') ->orderBy('device.id', 'desc') ->offset($pagenNum) ->limit($limit) ->get()->toArray(); $count = $databadevice - ->where('dtype','=',$type) - ->where('uid','=',Auth::id()) - // ->where('delete','=','2')//设备ä¸æ˜¯åˆ é™¤çŠ¶æ€ + ->where('dtype', '=', $type) + ->where('uid', '=', Auth::id()) + // ->where('delete','=','2')//设备ä¸æ˜¯åˆ é™¤çŠ¶æ€ //->where('devicestatus','=','1')// ->count(); - return ['devicelist'=>$devicelist,'count'=>$count]; + return ['devicelist' => $devicelist, 'count' => $count]; } - private function deviceDataSearchData($devicenum,$pagenNum,$limit) : array { + + private function deviceDataSearchData($devicenum, $pagenNum, $limit): array + { $databadevice = DB::table('device'); $devicelist = $databadevice - ->where('devicenum','=',$devicenum) + ->where('devicenum', '=', $devicenum) //->where('delete','=','2')//设备ä¸æ˜¯åˆ é™¤çŠ¶æ€ //->where('devicestatus','=','1')// - ->leftjoin('device_type as dy',"device.dtype",'=','dy.tid') - ->leftjoin('gas as g',"device.status",'=','g.id') - ->leftjoin('status as p',"device.devicepolice",'=','p.id') - ->select('dy.tname','g.gas','device.*','p.status_name') + ->leftjoin('device_type as dy', "device.dtype", '=', 'dy.tid') + ->leftjoin('gas as g', "device.status", '=', 'g.id') + ->leftjoin('status as p', "device.devicepolice", '=', 'p.id') + ->select('dy.tname', 'g.gas', 'device.*', 'p.status_name') ->orderBy('device.id', 'desc') ->offset($pagenNum) ->limit($limit) ->get()->toArray(); $count = $databadevice - ->where('dtype','=',$devicenum) + ->where('dtype', '=', $devicenum) //->where('delete','=','2')//设备ä¸æ˜¯åˆ é™¤çŠ¶æ€ //->where('devicestatus','=','1')// ->count(); - return ['devicelist'=>$devicelist,'count'=>$count]; + return ['devicelist' => $devicelist, 'count' => $count]; } + //批é‡ä¸Šä¼ 设备 - public function batchdevice(){ + public function batchdevice() + { } + //获å–è®¾å¤‡è¯¦æƒ…ä¿¡æ¯ - public function deviceDataInfo($id){ - $devicedata = Device::where('device.id','=',$id) - ->leftjoin('contactsuser as c','c.contactsid','=','device.contactsid') - ->select('c.*','device.deviceuuid','device.devicelinkman','device.devicephone','device.devicecoord') - ->get(); - $devicedatainfo = Device::where('id','=',$id) - ->select('deviceuuid','devicelinkman','devicephone','devicecoord') + public function deviceDataInfo($id) + { + $devicedata = Device::where('device.id', '=', $id) + ->leftjoin('contactsuser as c', 'c.contactsid', '=', 'device.contactsid') + ->select('c.*', 'device.deviceuuid', 'device.devicelinkman', 'device.devicephone', 'device.devicecoord') + ->get(); + $devicedatainfo = Device::where('id', '=', $id) + ->select('deviceuuid', 'devicelinkman', 'devicephone', 'devicecoord') ->get(); - return $this->jsonSuccessData(['devicedata'=>$devicedata,'devicedatainfo'=>$devicedatainfo]); + return $this->jsonSuccessData(['devicedata' => $devicedata, 'devicedatainfo' => $devicedatainfo]); } //æœç´¢è®¾å¤‡è´¦å· - public function deviceDataSearch(Request $request){ + public function deviceDataSearch(Request $request) + { $data = $request->input('deviceName'); - $pagenNum=$request->input('page')-1;//页数 + $pagenNum = $request->input('page') - 1;//页数 $limit = $request->input('limit'); - if($pagenNum === '' || $limit == '' || $data == ''){ - return $this->jsonErrorData(105,'请求å‚æ•°ä¸èƒ½ä¸ºç©º'); + if ($pagenNum === '' || $limit == '' || $data == '') { + return $this->jsonErrorData(105, '请求å‚æ•°ä¸èƒ½ä¸ºç©º'); } - return $this->jsonSuccessData($this->deviceDataSearchData($data,$pagenNum,$limit)); + return $this->jsonSuccessData($this->deviceDataSearchData($data, $pagenNum, $limit)); } + //推é€èŽ·å–æ•°æ®ç›‘æµ‹æ•°æ® - public function equipment(){ - $dalen = Redis::llen('Devicesdata');//返回队列长度 - if ($dalen > 0){ - return $this->jsonSuccessData(unserialize(Redis::lpop('Devicesdata'))); + public function equipment() + { + $dalen = Redis::llen('Devicesdata');//返回队列长度 +// $num = round($dalen / 2); + $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){ + $dete = $request->input('dete'); + $devicetime = $this->devicetime($dete); + if($devicetime != 105){ + return $this->jsonSuccessData($devicetime); }else{ - return $this->jsonErrorData(105,'æš‚æ— æ•°æ®'); + return $this->jsonErrorData(105,'æš‚æ— æ•°æ®'); } } + //返回设备当å‰æŠ¥è¦ - public function police(){ - return DB::table('reportpolice as r') - ->where('r.status','=','1') - ->join('status as s','r.policestatus','=','s.id') - ->select('r.*','s.status_name') - ->get()->toArray(); + public function police() + { + $data = DB::table('reportpolice as r') + //->where('r.status', '=', '1') + ->join('status as s', 'r.policestatus', '=', 's.id') + ->select('r.*', 's.status_name') + ->get(); + return $this->jsonSuccessData($data); + } + //è¿”å›žè®¾å¤‡åºŸçº¸ç¯“æ•°é‡ - public function deviceBasket(){ - return $this->jsonSuccessData(DB::table('device')->where('delete','=','1')->count()); + public function deviceBasket() + { + return $this->jsonSuccessData(DB::table('device')->where('delete', '=', '1')->count()); } //返回设备废纸篓和ç¦ç”¨è®¾å¤‡ - public function deviceBasketList(){ - $paper = DB::table('device')->where('delete','=','1')->get()->toArray(); + public function deviceBasketList() + { + $paper = DB::table('device')->where('delete', '=', '1')->get()->toArray(); return $this->jsonSuccessData($paper); } - public function deviceDelete(Request $request){ + public function deviceDelete(Request $request) + { $id = $request->input('id'); $type = $request->input('type'); - if ($type == 1){//丢弃废纸篓 - return $this->jsonSuccessData(DB::table('device')->where('id','=',$id)->update(['delete'=>1,'devicestatus'=>6])); - }else{ - return $this->jsonSuccessData(DB::table('device')->where('id','=',$id)->update(['devicestatus'=>6])); + if ($type == 1) {//丢弃废纸篓 + return $this->jsonSuccessData(DB::table('device')->where('id', '=', $id)->update(['delete' => 1, 'devicestatus' => 6])); + } else { + return $this->jsonSuccessData(DB::table('device')->where('id', '=', $id)->update(['devicestatus' => 6])); } } - public function UpPaperBasket($id){ - return $this->jsonSuccessData(DB::table('device')->where('id','=',$id)->update(['delete'=>2,'devicestatus'=>1])); + public function UpPaperBasket($id) + { + return $this->jsonSuccessData(DB::table('device')->where('id', '=', $id)->update(['delete' => 2, 'devicestatus' => 1])); } - public function addClassify($data){ + public function addClassify($data) + { //æ·»åŠ åˆ†ç±» - return $this->jsonSuccessData(DB::table('device_type')->insertGetId(['tname'=>$data])); + return $this->jsonSuccessData(DB::table('device_type')->insertGetId(['tname' => $data])); } - public function delteClassify($id){ + public function delteClassify($id) + { //åˆ é™¤åˆ†ç±» - return $this->jsonSuccessData(DB::table('device_type')->where('tid','=',$id)->delete()); + return $this->jsonSuccessData(DB::table('device_type')->where('tid', '=', $id)->delete()); } + /** * @param bool $isNew * @return array @@ -321,36 +377,82 @@ class DevicesController extends Controller private function getValidationRulesdevice($isNew = true) { return [ - 'devicenum'=>'required|between:2,25|unique:device,devicenum',//è®¾å¤‡ç¼–å· - 'username'=>'required|unique:device,username|max:40',//设备å称 - 'devicephone'=> 'sometimes|required|regex:/^1[3465789]\d{9}$/|max:11',//è”ç³»äººæ‰‹æœºå· - 'devicelinkman'=>'sometimes|required|max:15', - 'dtype'=>'required', - 'status'=>'required', - 'devicemonad'=>'required', - 'deviceremark'=>'sometimes|required|max:15', - 'devicecoord'=>'sometimes|required', - 'contactsid'=>'sometimes|required',//绑定è”系人id - 'deviceinfo'=>'sometimes|required', - 'devicenumber'=>'required|unique:device,devicenumber|max:40' + 'devicenum' => 'required|between:2,25|unique:device,devicenum',//è®¾å¤‡ç¼–å· + 'username' => 'required|unique:device,username|max:40',//设备å称 + 'devicephone' => 'sometimes|required|regex:/^1[3465789]\d{9}$/|max:11',//è”ç³»äººæ‰‹æœºå· + 'devicelinkman' => 'sometimes|required|max:15', + 'dtype' => 'required', + 'status' => 'required', + 'devicemonad' => 'required', + 'deviceremark' => 'sometimes|required|max:15', + 'devicecoord' => 'sometimes|required', + 'contactsid' => 'sometimes|required',//绑定è”系人id + 'deviceinfo' => 'sometimes|required', + 'devicenumber' => 'required|unique:device,devicenumber|max:40' ]; } + //更新设备列表 private function getValidationRulesupdevice($isNew = true) { return [ - 'username'=>'sometimes|required|unique:device,username|max:40',//设备å称 - 'devicephone'=> 'sometimes|required|regex:/^1[3465789]\d{9}$/|max:11',//è”ç³»äººæ‰‹æœºå· - 'devicelinkman'=>'sometimes|required|max:15', - 'dtype'=>'sometimes|required', - 'status'=>'sometimes|required', - 'devicemonad'=>'sometimes|required', - 'deviceremark'=>'sometimes|required|max:15',//备注 - 'devicecoord'=>'sometimes|required', - 'contactsid'=>'sometimes|required',//绑定è”系人id - 'deviceinfo'=>'sometimes|required', - 'devicenumber'=>'sometimes|required|unique:device,devicenumber|max:40' + 'username' => 'sometimes|required|unique:device,username|max:40',//设备å称 + 'devicephone' => 'sometimes|required|regex:/^1[3465789]\d{9}$/|max:11',//è”ç³»äººæ‰‹æœºå· + 'devicelinkman' => 'sometimes|required|max:15', + 'dtype' => 'sometimes|required', + 'status' => 'sometimes|required', + 'devicemonad' => 'sometimes|required', + 'deviceremark' => 'sometimes|required|max:15',//备注 + 'devicecoord' => 'sometimes|required', + 'contactsid' => 'sometimes|required',//绑定è”系人id + 'deviceinfo' => 'sometimes|required', + 'devicenumber' => 'sometimes|required|unique:device,devicenumber|max:40' ]; } + private function devicemkdir($data) + { + $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); + + $this->devicelistopen($path); + } + + private function devicelistopen() :array + { + $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 = []; + foreach (array_filter($exp) as $key => $vel) { + $newstring = str_replace('[', '', $vel); + $newstring1 = str_replace(']', '', $newstring); + array_push($datadevice, json_decode($newstring1, true)); + } + return $datadevice; + }else{ + return 105; + } + } + + 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 = []; + foreach (array_filter($exp) as $key => $vel) { + $newstring = str_replace('[', '', $vel); + $newstring1 = str_replace(']', '', $newstring); + array_push($datadevice, json_decode($newstring1, true)); + } + return $datadevice; + }else{ + return 105; + } + } } \ No newline at end of file diff --git a/dump.rdb b/dump.rdb index f08989c311ad96a251c76ffa0b0faaa11ce24a01..9aeae46beba2e616b7f3ea0f6b01a45148d916a5 100644 Binary files a/dump.rdb and b/dump.rdb differ diff --git a/public/device/2020-05-14/devicelistdata.text b/public/device/2020-05-14/devicelistdata.text new file mode 100644 index 0000000000000000000000000000000000000000..891358c207a923a8860c29809f3ec7cf91057f02 --- /dev/null +++ b/public/device/2020-05-14/devicelistdata.text @@ -0,0 +1,3 @@ +[{"devicenum":"ZHGAS000131031","username":"123214","deviceremark":null,"devicelinkman":"1","devicephone":"16631150870","deviceinfo":null,"tname":"\u5bb6\u7528\u62a5\u8b66\u5668(IOT)","gas":"\u7532\u70f7","danwei":"%LEL","status_name":"\u62a5\u8b66"}] +[{"devicenum":"ZHGAS000131031","username":"123214","deviceremark":null,"devicelinkman":"1","devicephone":"16631150870","deviceinfo":null,"tname":"\u5bb6\u7528\u62a5\u8b66\u5668(IOT)","gas":"\u7532\u70f7","danwei":"%LEL","status_name":"\u4f20\u611f\u5668\u6545\u969c"}] +[{"devicenum":"ZHGAS000131031","username":"123214","deviceremark":null,"devicelinkman":"1","devicephone":"16631150870","deviceinfo":null,"tname":"\u5bb6\u7528\u62a5\u8b66\u5668(IOT)","gas":"\u7532\u70f7","danwei":"%LEL","status_name":"\u9ad8\u62a5"}] diff --git a/resources/js/api/device.js b/resources/js/api/device.js index 6877a88541ae31ff4e2dd17c9e6562fcf4e1c270..e31524cd24c11f5fe4fd6e36656dc130dcab6bad 100644 --- a/resources/js/api/device.js +++ b/resources/js/api/device.js @@ -70,3 +70,25 @@ export function delteClassify(id) { method: 'get', }); } + +export function equipment() { + return request({ + url: '/devices/equipment', + method: 'get', + }); +} + +export function detedevice(dete) { + return request({ + url: '/devices/detedevice?dete=' + dete, + method: 'get', + }); +} + +export function police(dete) { + return request({ + url: '/devices/police', + method: 'get', + }); +} + diff --git a/resources/js/router/index.js b/resources/js/router/index.js index aa3a745f62bde772bd880242112710f0bb0608c2..1d36264a3873f939d9ca51db065aa824e89653b0 100644 --- a/resources/js/router/index.js +++ b/resources/js/router/index.js @@ -13,17 +13,15 @@ Vue.use(Router); import Layout from '@/layout'; /* Router for modules */ -import elementUiRoutes from './modules/element-ui'; -import componentRoutes from './modules/components'; -import chartsRoutes from './modules/charts'; -import tableRoutes from './modules/table'; +// import componentRoutes from './modules/components'; +// import chartsRoutes from './modules/charts'; +// import tableRoutes from './modules/table'; import adminRoutes from './modules/admin'; import deviceRoutes from './modules/device'; import usersRoutes from './modules/users'; -import nestedRoutes from './modules/nested'; -import errorRoutes from './modules/error'; -import excelRoutes from './modules/excel'; -import permissionRoutes from './modules/permission'; +// import nestedRoutes from './modules/nested'; +// import errorRoutes from './modules/error'; +// import permissionRoutes from './modules/permission'; import historyRoutes from './modules/history.js'; import monitorRoutes from './modules/monitor.js'; @@ -119,117 +117,115 @@ export const constantRoutes = [ deviceRoutes, usersRoutes, adminRoutes, - { - path: '/documentation', - component: Layout, - redirect: '/documentation/index', - children: [ - { - path: 'index', - component: () => import('@/views/documentation/index'), - name: 'Documentation', - meta: { title: 'documentation', icon: 'documentation', noCache: true }, - }, - ], - }, - { - path: '/guide', - component: Layout, - redirect: '/guide/index', - children: [ - { - path: 'index', - component: () => import('@/views/guide/index'), - name: 'Guide', - meta: { title: 'guide', icon: 'guide', noCache: true }, - }, - ], - }, - elementUiRoutes, + // { + // path: '/documentation', + // component: Layout, + // redirect: '/documentation/index', + // children: [ + // { + // path: 'index', + // component: () => import('@/views/documentation/index'), + // name: 'Documentation', + // meta: { title: 'documentation', icon: 'documentation', noCache: true }, + // }, + // ], + // }, + // { + // path: '/guide', + // component: Layout, + // redirect: '/guide/index', + // children: [ + // { + // path: 'index', + // component: () => import('@/views/guide/index'), + // name: 'Guide', + // meta: { title: 'guide', icon: 'guide', noCache: true }, + // }, + // ], + // }, ]; export const asyncRoutes = [ - permissionRoutes, - componentRoutes, - chartsRoutes, - nestedRoutes, - tableRoutes, - { - path: '/theme', - component: Layout, - redirect: 'noredirect', - children: [ - { - path: 'index', - component: () => import('@/views/theme/index'), - name: 'Theme', - meta: { title: 'theme', icon: 'theme' }, - }, - ], - }, - { - path: '/clipboard', - component: Layout, - redirect: 'noredirect', - meta: { permissions: ['view menu clipboard'] }, - children: [ - { - path: 'index', - component: () => import('@/views/clipboard/index'), - name: 'ClipboardDemo', - meta: { title: 'clipboardDemo', icon: 'clipboard', roles: ['admin', 'manager', 'editor', 'user'] }, - }, - ], - }, - errorRoutes, - excelRoutes, - { - path: '/zip', - component: Layout, - redirect: '/zip/download', - alwaysShow: true, - meta: { title: 'zip', icon: 'zip', permissions: ['view menu zip'] }, - children: [ - { - path: 'download', - component: () => import('@/views/zip'), - name: 'ExportZip', - meta: { title: 'exportZip' }, - }, - ], - }, - { - path: '/pdf', - component: Layout, - redirect: '/pdf/index', - meta: { title: 'pdf', icon: 'pdf', permissions: ['view menu pdf'] }, - children: [ - { - path: 'index', - component: () => import('@/views/pdf'), - name: 'Pdf', - meta: { title: 'pdf' }, - }, - ], - }, - { - path: '/pdf/download', - component: () => import('@/views/pdf/Download'), - hidden: true, - }, - { - path: '/i18n', - component: Layout, - meta: { permissions: ['view menu i18n'] }, - children: [ - { - path: 'index', - component: () => import('@/views/i18n'), - name: 'I18n', - meta: { title: 'i18n', icon: 'international' }, - }, - ], - }, + // permissionRoutes, + // componentRoutes, + // chartsRoutes, + // nestedRoutes, + // tableRoutes, + // { + // path: '/theme', + // component: Layout, + // redirect: 'noredirect', + // children: [ + // { + // path: 'index', + // component: () => import('@/views/theme/index'), + // name: 'Theme', + // meta: { title: 'theme', icon: 'theme' }, + // }, + // ], + // }, + // { + // path: '/clipboard', + // component: Layout, + // redirect: 'noredirect', + // meta: { permissions: ['view menu clipboard'] }, + // children: [ + // { + // path: 'index', + // component: () => import('@/views/clipboard/index'), + // name: 'ClipboardDemo', + // meta: { title: 'clipboardDemo', icon: 'clipboard', roles: ['admin', 'manager', 'editor', 'user'] }, + // }, + // ], + // }, + // errorRoutes, + // { + // path: '/zip', + // component: Layout, + // redirect: '/zip/download', + // alwaysShow: true, + // meta: { title: 'zip', icon: 'zip', permissions: ['view menu zip'] }, + // children: [ + // { + // path: 'download', + // component: () => import('@/views/zip'), + // name: 'ExportZip', + // meta: { title: 'exportZip' }, + // }, + // ], + // }, + // { + // path: '/pdf', + // component: Layout, + // redirect: '/pdf/index', + // meta: { title: 'pdf', icon: 'pdf', permissions: ['view menu pdf'] }, + // children: [ + // { + // path: 'index', + // component: () => import('@/views/pdf'), + // name: 'Pdf', + // meta: { title: 'pdf' }, + // }, + // ], + // }, + // { + // path: '/pdf/download', + // component: () => import('@/views/pdf/Download'), + // hidden: true, + // }, + // { + // path: '/i18n', + // component: Layout, + // meta: { permissions: ['view menu i18n'] }, + // children: [ + // { + // path: 'index', + // component: () => import('@/views/i18n'), + // name: 'I18n', + // meta: { title: 'i18n', icon: 'international' }, + // }, + // ], + // }, { path: '*', redirect: '/404', hidden: true }, ]; diff --git a/resources/js/router/modules/element-ui.js b/resources/js/router/modules/element-ui.js index 1488fe7ed00b19373787c6eca5a30492fc887ee8..03676f63beabb25bc1ec0dbba6109ff89c5504d5 100644 --- a/resources/js/router/modules/element-ui.js +++ b/resources/js/router/modules/element-ui.js @@ -1,5 +1,5 @@ import Layout from '@/layout'; - +// const elementUiRoutes = { path: '/element-ui', component: Layout, diff --git a/resources/js/views/documentation/index.vue b/resources/js/views/documentation/index.vue deleted file mode 100644 index 13c3d16d46c49c570e746a081f234ed8fbbcd2b6..0000000000000000000000000000000000000000 --- a/resources/js/views/documentation/index.vue +++ /dev/null @@ -1,47 +0,0 @@ -<template> - <div class="app-container documentation-container"> - <a class="document-btn" target="_blank" href="https://laravel.com/docs/5.8">{{ $t('documentation.laravel') }}</a> - <a class="document-btn" target="_blank" href="https://vuejs.org/">VueJS</a> - <a class="document-btn" target="_blank" href="https://github.com/tuandm/laravue/">{{ $t('documentation.github') }}</a> - <dropdown-menu :items="articleList" style="float:left;margin-left:50px;" title="Components" /> - </div> -</template> -<script> -import DropdownMenu from '@/components/Share/DropdownMenu'; - -export default { - name: 'Documentation', - components: { DropdownMenu }, - data() { - return { - articleList: [ - { title: 'Laravel Envoy', href: 'https://laravel.com/docs/5.8/envoy' }, - { title: 'Vuex', href: 'https://vuex.vuejs.org/' }, - { title: 'Vue Router', href: 'https://router.vuejs.org/' }, - { title: 'laravue-core', href: 'https://github.com/tuandm/laravue-core' }, - { title: 'vue-admin-template', href: 'https://github.com/PanJiaChen/vue-admin-template' }, - { title: 'Axios', href: 'https://github.com/axios/axios' }, - ], - }; - }, -}; -</script> - -<style rel="stylesheet/scss" lang="scss" scoped> -.documentation-container { - margin: 50px; - .document-btn { - float: left; - margin-left: 50px; - display: block; - cursor: pointer; - background: black; - color: white; - height: 60px; - width: 200px; - line-height: 60px; - font-size: 20px; - text-align: center; - } -} -</style> diff --git a/resources/js/views/history/alarms.vue b/resources/js/views/history/alarms.vue index 2e12e4ac07bb766012fca18957deb5ba76fe4500..9676a90a0f0863bba49c74b231c913510e064fad 100644 --- a/resources/js/views/history/alarms.vue +++ b/resources/js/views/history/alarms.vue @@ -1,8 +1,99 @@ <template> - <div>报è¦è®°å½•</div> + <div class="app-container"> + <el-table :key="tableKey" :data="reportpolice" border fit highlight-current-rows> + <el-table-column label="设备编å·" width="150"> + <template slot-scope="scope"> + <span @click="handleCopy(scope.row.devicenumber,$event)">{{ scope.row.devicenumber }}</span> + </template> + </el-table-column> + <el-table-column label="设备报è¦å¼€å§‹æ—¶é—´" width="150"> + <template slot-scope="scope"> + <span>{{ scope.row.starttime | parseTime('{y}-{m}-{d} {h}:{i}') }}</span> + </template> + </el-table-column> + <el-table-column label="设备结æŸæŠ¥è¦æ—¶é—´" width="150"> + <template slot-scope="scope"> + <span>{{ scope.row.endtime=='0-0-0 0:0' ? '' : scope.row.endtime | parseTime('{y}-{m}-{d} {h}:{i}') }}</span> + </template> + </el-table-column> + <el-table-column label="报è¦æµ“度" width="150"> + <template slot-scope="scope"> + <span @click="handleCopy(scope.row.concentration,$event)">{{ scope.row.concentration }}</span> + </template> + </el-table-column> + <el-table-column label="报è¦ä½ç½®" width="150"> + <template slot-scope="scope"> + <span @click="handleCopy(scope.row.location,$event)">{{ scope.row.location }}</span> + </template> + </el-table-column> + <el-table-column label="报è¦ç±»åž‹" width="150"> + <template slot-scope="scope"> + <span>{{ scope.row.status_name }}</span> + </template> + </el-table-column> + <el-table-column label="设备状æ€" width="155"> + <template slot-scope="scope"> + <el-tag :type="scope.row.status==1 ? 'danger' : 'success' " effect="dark">{{ scope.row.status==1 ? '报è¦' : 'æ£å¸¸' }}</el-tag> + </template> + </el-table-column> + <el-table-column label="设备是å¦å½“å‰æŠ¥è¦" width="150"> + <template slot-scope="scope"> + <el-tag :type="scope.row.status==1 ? 'danger' : 'success' " effect="dark">{{ scope.row.status==1 ? '当å‰æ£åœ¨æŠ¥è¦' : '已结æŸæŠ¥è¦' }}</el-tag> + </template> + </el-table-column> + </el-table> + <el-tooltip placement="top" content="tooltip"> + <back-to-top :custom-style="myBackToTopStyle" :visibility-height="300" :back-position="50" transition-name="fade" /> + </el-tooltip> + </div> </template> <script> +import { police } from '@/api/device'; +import clip from '@/utils/clipboard'; +import BackToTop from '@/components/BackToTop'; +export default { + components: { BackToTop }, + data() { + return { + tableKey: 0, + reportpolice: [], + myBackToTopStyle: { + right: '50px', + bottom: '50px', + width: '40px', + height: '40px', + 'border-radius': '4px', + 'line-height': '45px', // Please keep consistent with height to center vertically + background: '#e7eaf1', // The background color of the button + }, + }; + }, + created() { + this.police(); // 列表 + }, + methods: { + police() { + police() + .then(response => { + if (response.code === 200) { + this.reportpolice = response.data; + } else if (response.code === 105) { + this.$message({ + message: response.msg, + type: 'warning', + }); + } + }) + .catch(err => { + console.log(err); + }); + }, + handleCopy(text, event) { + clip(text, event); + }, + }, +}; </script> <style> diff --git a/resources/js/views/history/index.vue b/resources/js/views/history/index.vue index 3912592937a7a5331fe88deef7664a5ba9b508b3..67e19b7b9bbcc724fafd27431dbb51a41885d4a7 100644 --- a/resources/js/views/history/index.vue +++ b/resources/js/views/history/index.vue @@ -1,9 +1,163 @@ <template> - <div>设备记录</div> + <div class="app-container"> + <div class="filter-container"> + <el-date-picker v-model="value2" align="right" type="date" placeholder="选择日期" :picker-options="pickerOptions" value-format="yyyy-MM-dd" @change="dataSearch"></el-date-picker> + </div> + <el-table :key="tableKey" :data="equipment" border fit highlight-current-rows> + <el-table-column label="设备编å·" width="130"> + <template slot-scope="scope"> + <span @click="handleCopy(scope.row.devicenum,$event)">{{ scope.row.devicenum }}</span> + </template> + </el-table-column> + <el-table-column label="用户姓å" width="130"> + <template slot-scope="scope"> + <span>{{ scope.row.username }}</span> + </template> + </el-table-column> + <el-table-column label="设备备注" width="130"> + <template slot-scope="scope"> + <span>{{ scope.row.deviceremark }}</span> + </template> + </el-table-column> + <el-table-column label="设备è”系人" width="130"> + <template slot-scope="scope"> + <span>{{ scope.row.devicelinkman }}</span> + </template> + </el-table-column> + <el-table-column label="设备手机å·" width="130"> + <template slot-scope="scope"> + <span @click="handleCopy(scope.row.devicephone,$event)">{{ scope.row.devicephone }}</span> + </template> + </el-table-column> + <el-table-column label="设备详情" width="130"> + <template slot-scope="scope"> + <span>{{ scope.row.deviceinfo }}</span> + </template> + </el-table-column> + <el-table-column label="设备分类" width="130"> + <template slot-scope="scope"> + <span>{{ scope.row.tname }}</span> + </template> + </el-table-column> + <el-table-column label="设备介质" width="130"> + <template slot-scope="scope"> + <span>{{ scope.row.gas }}</span> + </template> + </el-table-column> + <el-table-column label="设备å•ä½" width="130"> + <template slot-scope="scope"> + <span>{{ scope.row.danwei }}</span> + </template> + </el-table-column> + <el-table-column label="设备状æ€" width="130"> + <template slot-scope="scope"> + <span>{{ scope.row.status_name }}</span> + </template> + </el-table-column> + </el-table> + <el-tooltip placement="top" content="tooltip"> + <back-to-top :custom-style="myBackToTopStyle" :visibility-height="300" :back-position="50" transition-name="fade" /> + </el-tooltip> + </div> </template> <script> +import { equipment, detedevice } from '@/api/device'; +import clip from '@/utils/clipboard'; +import BackToTop from '@/components/BackToTop'; +export default { + components: { BackToTop }, + data() { + return { + equipment: [], + tableKey: 0, + value2: undefined, + pickerOptions: { + disabledDate(time) { + return time.getTime() > Date.now(); + }, + shortcuts: [{ + text: '今天', + onClick(picker) { + picker.$emit('pick', new Date()); + }, + }, { + text: '昨天', + onClick(picker) { + const date = new Date(); + date.setTime(date.getTime() - 3600 * 1000 * 24); + picker.$emit('pick', date); + }, + }, { + text: '一周å‰', + onClick(picker) { + const date = new Date(); + date.setTime(date.getTime() - 3600 * 1000 * 24 * 7); + picker.$emit('pick', date); + }, + }], + }, + myBackToTopStyle: { + right: '50px', + bottom: '50px', + width: '40px', + height: '40px', + 'border-radius': '4px', + 'line-height': '45px', // Please keep consistent with height to center vertically + background: '#e7eaf1', // The background color of the button + }, + }; + }, + created() { + this.equipmentlist(); // 列表 + }, + methods: { + equipmentlist() { + equipment() + .then(response => { + if (response.code === 200) { + this.equipment = response.data; + } else if (response.code === 105) { + this.$message({ + message: response.msg, + type: 'warning', + }); + } + }) + .catch(err => { + console.log(err); + }); + }, + handleCopy(text, event) { + clip(text, event); + }, + dataSearch() { + detedevice(this.value2) + .then(response => { + if (response.code === 200) { + this.equipment = response.data; + } else if (response.code === 105) { + this.$message({ + message: response.msg, + type: 'warning', + }); + this.equipment = response.data; + } + }) + .catch(err => { + console.log(err); + }); + }, + }, +}; </script> - -<style> +<style scoped lang="scss"> +.placeholder-container { + ul { + li { + margin: 10px; + list-style-type: none; + } + } +} </style> diff --git a/routes/api.php b/routes/api.php index 3b5cc4c4747c52247b17dcb68b25ee3f1bcad74f..12fef3a82c97542c08ab036781eab07a37ed6dcb 100644 --- a/routes/api.php +++ b/routes/api.php @@ -80,6 +80,7 @@ Route::group(['middleware'=>'auth:api'],function (){ Route::get('devices/deviceBasketList','DevicesController@deviceBasketList');//返回ç¦ç”¨è®¾å¤‡å’ŒåºŸçº¸ç¯“设备 Route::get('devices/addClassify/{data}','DevicesController@addClassify');//æ·»åŠ åˆ†ç±» Route::get('devices/delteClassify/{id}','DevicesController@delteClassify');//åˆ é™¤åˆ†ç±» + Route::get('devices/detedevice','DevicesController@detedevice');//查看历å²æ•°æ® }); //装维ä¸å¿ƒ