Commit 4df1e763 authored by 冯超鹏's avatar 冯超鹏

提交新模块,用户统计,列表

parent 6be05993
Pipeline #39 failed with stages
...@@ -9,6 +9,7 @@ class swoole extends Command ...@@ -9,6 +9,7 @@ class swoole extends Command
{ {
public $ws; public $ws;
private $token = 'zxc123456789ZXC'; private $token = 'zxc123456789ZXC';
public $time = 10;
/** /**
* The name and signature of the console command. * The name and signature of the console command.
* *
...@@ -63,36 +64,44 @@ class swoole extends Command ...@@ -63,36 +64,44 @@ class swoole extends Command
'daemonize'=>0,//守护进程 'daemonize'=>0,//守护进程
)); ));
$this->ws->on('open', function ($ws, $request) { $this->ws->on('open', function ($ws, $request) {
//链接成功 // //链接成功
$data = [ // $data = [
'code' => 200, // 'code' => 200,
'token' => md5($this->token), // 'token' => md5($this->token),
'time' => date("Y-m-d H:i:s", time()), // 'time' => date("Y-m-d H:i:s", time()),
'msg' => '连接成功' // 'msg' => '连接成功'
]; // ];
$this->ws->push(1, json_encode($data), 1); // $this->ws->push(1, json_encode($data), 1);
$userdata = new SwooleCommandController();
$this->ws->push($request->fd,$userdata->userslist(),1);
swoole_timer_tick(6000, function($timerId) use ($ws, $request) {
$userdata = new SwooleCommandController();
$this->ws->push($request->fd,$userdata->userslist(),1);
});
}); });
//监听WebSocket消息事件 //监听WebSocket消息事件
$this->ws->on('message', function ($ws, $frame) { $this->ws->on('message', function ($ws, $frame) {
$data = json_decode($frame->data, true); // $data = json_decode($frame->data, true);
$token = (string)$data['token']; // //监测是否是有效链接
if ($token != md5($this->token)) { // if($this->ws->isEstablished($frame->fd)){
Log::channel('single')->info('token错误'. ',' .'token=>'. $token . ',' . 'id=>' . $frame->fd); // $ws->bind($frame->fd, $data['id']);
$this->ws->push($frame->fd, 'token错误', 1); // $userdata = new SwooleCommandController();
$this->ws->disconnect($frame->fd, 105, '已断开连接,token错误'); // $this->ws->push($frame->fd,$userdata->userslist(),1);
} else { // }else{
// 监测是否是有效链接 // Log::channel('single')->info('不是有效连接'. ','.'id=>'. $frame->fd);
if($this->ws->isEstablished($frame->fd)){ // $this->ws->push($frame->fd, '不是有效连接', 1);
$ws->bind($frame->fd, $data['id']); // $this->ws->disconnect($frame->fd, 105, '已断开连接,不是有效连接');
$userdata = new SwooleCommandController(); // }
$this->ws->push($frame->fd,$userdata->userslist(),1); //// $token = (string)$data['token'];
}else{ //// if ($token != md5($this->token)) {
Log::channel('single')->info('不是有效连接'. ','.'id=>'. $frame->fd); //// Log::channel('single')->info('token错误'. ',' .'token=>'. $token . ',' . 'id=>' . $frame->fd);
$this->ws->push($frame->fd, '不是有效连接', 1); //// $this->ws->push($frame->fd, 'token错误', 1);
$this->ws->disconnect($frame->fd, 105, '已断开连接,不是有效连接'); //// $this->ws->disconnect($frame->fd, 105, '已断开连接,token错误');
} //// } else {
} //////
//// }
}); });
$this->ws->on('request', function ($request, $response) { $this->ws->on('request', function ($request, $response) {
...@@ -104,6 +113,7 @@ class swoole extends Command ...@@ -104,6 +113,7 @@ class swoole extends Command
//监听WebSocket连接关闭事件 //监听WebSocket连接关闭事件
$this->ws->on('close', function ($ws, $fd) { $this->ws->on('close', function ($ws, $fd) {
echo "client:{$fd} is closed\n"; echo "client:{$fd} is closed\n";
swoole_timer_clear($this->time);
}); });
$this->ws->start(); $this->ws->start();
......
...@@ -15,34 +15,13 @@ class SwooleCommandController extends Controller ...@@ -15,34 +15,13 @@ class SwooleCommandController extends Controller
//查询用户数量 //查询用户数量
$usercount = DB::table('BackgroundUser')->count();//获取用户数量 $usercount = DB::table('BackgroundUser')->count();//获取用户数量
//查询设备类型 //查询设备类型
$device_type = DB::table('device_type')->get()->toArray(); $count = DB::table('BackgroundUser as b')
//量产 ->leftjoin('device as d','b.id','=','d.uid')
$userdata = DB::table('BackgroundUser as b') ->leftjoin('device_type as t','d.dtype','=','t.tid')
->leftjoin('device as de', 'b.id', '=', 'de.uid') ->selectRaw('b.username,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')
->where('b.state', '=', '2')
->select('b.id', 'b.username', 'b.nickname', 'de.dtype', 'de.uid')
->groupBy('b.id') ->groupBy('b.id')
->get()->toArray(); ->get();
$data = []; $countdata = ['usercount' => $usercount, 'userdata' => $count];
foreach (array_column($device_type, 'tid') as $key => $value) {
foreach (array_column($device_type, 'tname') as $k => $v) {
foreach (array_column($userdata, 'id') as $uk => $uv){
foreach (array_column($userdata, 'username') as $usk => $usv)
if ($key == $k && $uk == $usk){
$countdevice_type = DB::table('device')
->where('uid','=',$uv)
->where('dtype', '=', $value)
->count();
$username['username'] = $usv;
$username['tname'] = $v;
$username['count_dtype'] = $countdevice_type;
array_push($data,$username);
}
}
}
}
$countdata = ['usercount' => $usercount, 'userdata' => $data];
return $this->jsonSuccessData($countdata); return $this->jsonSuccessData($countdata);
} }
......
...@@ -158,10 +158,14 @@ class DevicesController extends Controller ...@@ -158,10 +158,14 @@ class DevicesController extends Controller
} }
//返回设备类型和单位和介质 //返回设备类型和单位和介质
public function devicetype(){ public function devicetype(){
$databadevice = DB::table('device_type')->get();
$gas = DB::table('gas')->get(); $gas = DB::table('gas')->get();
$danwei = DB::table('danwei')->get(); $danwei = DB::table('danwei')->get();
return $this->jsonSuccessData(['devicetype'=>$databadevice,'gas'=>$gas,'danwei'=>$danwei]); $devicetypecount = DB::table('device_type as t')
->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]);
} }
//返回设备列表 //返回设备列表
private function whertype($type,$pagenNum,$limit) : array { private function whertype($type,$pagenNum,$limit) : array {
...@@ -299,6 +303,16 @@ class DevicesController extends Controller ...@@ -299,6 +303,16 @@ class DevicesController extends Controller
return $this->jsonSuccessData(DB::table('device')->where('id','=',$id)->update(['delete'=>2,'devicestatus'=>1])); return $this->jsonSuccessData(DB::table('device')->where('id','=',$id)->update(['delete'=>2,'devicestatus'=>1]));
} }
public function addClassify($data){
//添加分类
return $this->jsonSuccessData(DB::table('device_type')->insertGetId(['tname'=>$data]));
}
public function delteClassify($id){
//删除分类
return $this->jsonSuccessData(DB::table('device_type')->where('tid','=',$id)->delete());
}
/** /**
* @param bool $isNew * @param bool $isNew
* @return array * @return array
......
...@@ -517,4 +517,8 @@ class UserController extends Controller ...@@ -517,4 +517,8 @@ class UserController extends Controller
$stutus = DB::table('BackgroundUser')->where('state','=','3')->get()->toArray(); $stutus = DB::table('BackgroundUser')->where('state','=','3')->get()->toArray();
return $this->jsonSuccessData(['paper'=>$paper,'stutus'=>$stutus]); return $this->jsonSuccessData(['paper'=>$paper,'stutus'=>$stutus]);
} }
public function textcountuser (){
}
} }
\ No newline at end of file
...@@ -56,3 +56,17 @@ export function UpPaperBasket(id) { ...@@ -56,3 +56,17 @@ export function UpPaperBasket(id) {
method: 'get', method: 'get',
}); });
} }
export function addClassify(data) {
return request({
url: '/devices/addClassify/' + data,
method: 'get',
});
}
export function delteClassify(id) {
return request({
url: '/devices/delteClassify/' + id,
method: 'get',
});
}
<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg t="1588815030007" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="2651" xmlns:xlink="http://www.w3.org/1999/xlink" width="200" height="200"><defs><style type="text/css"></style></defs><path d="M1024 1024H0V122.197333h136.533333V887.466667h887.466667v136.533333z" p-id="2652"></path><path d="M426.666667 307.2v533.162667H219.136V307.2zM725.674667 0v840.362667H518.144V0zM1024 460.8v379.562667h-207.530667V460.8z" p-id="2653"></path></svg>
\ No newline at end of file
...@@ -36,6 +36,12 @@ const usersRoutes = { ...@@ -36,6 +36,12 @@ const usersRoutes = {
name: 'userStatus', name: 'userStatus',
meta: { title: '用户状态', icon: 'userstutus', permissions: ['manage user'] }, meta: { title: '用户状态', icon: 'userstutus', permissions: ['manage user'] },
}, },
{
path: 'userStatistics',
component: () => import('@/views/user/userStatistics'),
name: 'userStatistics',
meta: { title: '用户统计', icon: 'userStatistics', permissions: ['manage user'] },
},
], ],
}; };
export default usersRoutes; export default usersRoutes;
<template> <template>
<div>设备分类</div> <div class="app-container">
<el-table :data="deviceListType" border style="width: 33%">
<el-table-column prop="date" label="id" width="100">
<template slot-scope="scope">
<span>{{ scope.row.tid }}</span>
</template>
</el-table-column>
<el-table-column prop="name" label="分类名称" width="150">
<template slot-scope="scope">
<span>{{ scope.row.tname }}</span>
</template>
</el-table-column>
<el-table-column label="操作" width="150">
<template slot-scope="scope">
<el-button type="info" size="small" @click="handleClick()">添加</el-button>
<el-button type="danger" size="small" @click="delteClassify(scope.row.tid)">删除</el-button>
</template>
</el-table-column>
</el-table>
</div>
</template> </template>
<script> <script>
import { deviceTypeList, addClassify, delteClassify } from '@/api/device';
export default {
data() {
return {
deviceListType: [], // 设备分类
};
},
created() {
this.getList();// 设备分类
},
methods: {
getList() {
deviceTypeList()
.then(response => {
var devicetype = response.data;
this.deviceListType = devicetype['devicetype'];
})
.catch(err => {
console.log(err);
});
},
// 添加
handleClick() {
this.$prompt('请输入分类名称', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
inputPattern: /\S/,
inputErrorMessage: '分类名称格式不正确',
}).then(({ value }) => {
addClassify(value)
.then(response => {
if (response.code === 200) {
this.getList();
}
})
.catch(err => {
console.log(err);
});
}).catch(() => {
this.$message({
type: 'info',
message: '取消输入',
});
});
},
delteClassify(id){
this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning',
}).then(() => {
delteClassify(id)
.then(response => {
if (response.code === 200) {
this.getList();
}
})
.catch(err => {
console.log(err);
});
}).catch(() => {
this.$message({
type: 'info',
message: '已取消删除',
});
});
},
},
};
</script> </script>
<style> <style>
......
<template>
<div class="app-container">
<el-tooltip v-for=" item in deviceListType " :key="item.id" class="item" effect="dark" :content=" '设备分类下总数量' + item.counnum" placement="top">
<el-button>{{ item.tname }}</el-button>
</el-tooltip>
<el-badge :value="devicenum" class="item" type="primary">
<el-button size="small">总共设备</el-button>
</el-badge>
<el-table :data="countdata" stripe style="width: 100%">
<el-table-column prop="date" label="姓名" width="180">
<template slot-scope="scope">
<span>{{ scope.row.username }}</span>
</template>
</el-table-column>
<el-table-column prop="name" label="工业探测器" width="170">
<template slot-scope="scope">
<span style="margin-left: 10px; color: #13CE66;">{{ scope.row.type_1 }}<span style="color: #878D99;"> 个设备</span></span>
</template>
</el-table-column>
<el-table-column prop="name" label="家用报警器" width="170">
<template slot-scope="scope">
<span style="margin-left: 10px; color: #13CE66;">{{ scope.row.type_2 }}<span style="color: #878D99;"> 个设备</span></span>
</template>
</el-table-column>
<el-table-column prop="name" label="家用报警器(IOT)" width="170">
<template slot-scope="scope">
<span style="margin-left: 10px; color: #13CE66;">{{ scope.row.type_4 }}<span style="color: #878D99;"> 个设备</span></span>
</template>
</el-table-column>
<el-table-column prop="name" label="压力监测设备" width="170">
<template slot-scope="scope">
<span style="margin-left: 10px; color: #13CE66;">{{ scope.row.type_5 }}<span style="color: #878D99;"> 个设备</span></span>
</template>
</el-table-column>
<el-table-column prop="name" label="烟雾感应设备" width="170">
<template slot-scope="scope">
<span style="margin-left: 10px; color: #13CE66;">{{ scope.row.type_6 }}<span style="color: #878D99;"> 个设备</span></span>
</template>
</el-table-column>
<el-table-column prop="name" label="烟雾感应设备(联通)" width="170">
<template slot-scope="scope">
<span style="margin-left: 10px; color: #13CE66;">{{ scope.row.type_7 }}<span style="color: #878D99;"> 个设备</span></span>
</template>
</el-table-column>
<el-table-column prop="name" label="家用报警器(RTU)" width="170">
<template slot-scope="scope">
<span style="margin-left: 10px; color: #13CE66;">{{ scope.row.type_8 }}<span style="color: #878D99;"> 个设备</span></span>
</template>
</el-table-column>
<el-table-column prop="name" label="液位探测器" width="170">
<template slot-scope="scope">
<span style="margin-left: 10px; color: #13CE66;">{{ scope.row.type_9 }}<span style="color: #878D99;"> 个设备</span></span>
</template>
</el-table-column>
<el-table-column prop="name" label="温度变送器" width="170">
<template slot-scope="scope">
<span style="margin-left: 10px; color: #13CE66;">{{ scope.row.type_10 }}<span style="color: #878D99;"> 个设备</span></span>
</template>
</el-table-column>
<el-table-column prop="name" label="消防报警及联动设备" width="170">
<template slot-scope="scope">
<span style="margin-left: 10px; color: #13CE66;">{{ scope.row.type_11 }}<span style="color: #878D99;"> 个设备</span></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 { deviceTypeList } from '@/api/device';
import BackToTop from '@/components/BackToTop';
export default {
components: { BackToTop },
data() {
return {
deviceListType: [], // 设备分类
countdata: [],
websock: null,
devicenum: undefined,
type: {
token: undefined,
id: '1',
},
timer: undefined,
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.getList();// 设备分类
this.initWebSocket();
},
destroyed() {
this.websock.close(); // 离开路由之后断开websocket连接
},
methods: {
getList() {
deviceTypeList()
.then(response => {
var devicetype = response.data;
this.deviceListType = devicetype['devicetype'];
})
.catch(err => {
console.log(err);
});
},
initWebSocket(){ // 初始化weosocket
const wsuri = 'ws://127.0.0.1:9502';
this.websock = new WebSocket(wsuri);
this.websock.onmessage = this.websocketonmessage;
this.websock.onopen = this.websocketonopen;
this.websock.onerror = this.websocketonerror;
this.websock.onclose = this.websocketclose;
},
websocketonopen(){ // 连接建立之后执行send方法发送数据
console.log('连接成功');
},
websocketonerror(){ // 连接建立失败重连
this.$notify({
title: '警告',
message: '建立链接失败,正在重连',
type: 'warning',
});
this.initWebSocket();
},
websocketonmessage(e){ // 数据接收
const redata = JSON.parse(e.data);
this.type.token = redata.token;
this.countdata = redata.data.userdata;
this.devicenum = redata.data.usercount;
},
websocketsend(){ // 数据发送
this.websock.send(JSON.stringify(this.type));
},
websocketclose(e){ // 关闭
console.log('断开连接', e);
this.$notify({
title: '警告',
message: '长连接已断开',
type: 'warning',
});
},
},
};
</script>
<style>
</style>
...@@ -43,17 +43,24 @@ Route::group(['middleware' => 'auth:api'], function () { ...@@ -43,17 +43,24 @@ Route::group(['middleware' => 'auth:api'], function () {
Route::get('user/paperBasket','UserController@paperBasket');//返回废纸篓数量 Route::get('user/paperBasket','UserController@paperBasket');//返回废纸篓数量
Route::get('user/paperBasketList','UserController@paperBasketList');//返回废纸篓和用户状态 Route::get('user/paperBasketList','UserController@paperBasketList');//返回废纸篓和用户状态
Route::get('user/textcountuser','UserController@textcountuser');//返回废纸篓和用户状态
}); });
//上传图片路由 //上传图片路由
Route::group(['middleware'=>'auth:api'],function (){ Route::group(['middleware'=>'auth:api'],function (){
Route::post('SwooleCommand/SwooleCommand','SwooleCommandController@index');//添加图片
Route::post('upload_img/uploadingimg','UploadimgController@uploadingimg')->middleware('permission:' . \App\Laravue\Acl::PERMISSION_PERMISSION_MANAGE);//添加图片 Route::post('upload_img/uploadingimg','UploadimgController@uploadingimg')->middleware('permission:' . \App\Laravue\Acl::PERMISSION_PERMISSION_MANAGE);//添加图片
Route::get('userimglist/userimglist','UploadimgController@userlist');//图片列表 Route::get('userimglist/userimglist','UploadimgController@userlist');//图片列表
Route::get('userimgdetele/userimgdetele','UploadimgController@userimgdetele');//删除图片 Route::get('userimgdetele/userimgdetele','UploadimgController@userimgdetele');//删除图片
Route::match(['get','post'],'updateimg/updateimg','UploadimgController@updateimg');//更新图片信息,返回逻辑图片列表 Route::match(['get','post'],'updateimg/updateimg','UploadimgController@updateimg');//更新图片信息,返回逻辑图片列表
}); });
//swoole
Route::group(['middleware'=>'auth:api'],function (){
Route::post('SwooleCommand/SwooleCommand','SwooleCommandController@index');
});
//设备路由 //设备路由
Route::group(['middleware'=>'auth:api'],function (){ Route::group(['middleware'=>'auth:api'],function (){
Route::get('devices/devicelist', 'DevicesController@devicelist');//设备列表 Route::get('devices/devicelist', 'DevicesController@devicelist');//设备列表
...@@ -71,7 +78,8 @@ Route::group(['middleware'=>'auth:api'],function (){ ...@@ -71,7 +78,8 @@ Route::group(['middleware'=>'auth:api'],function (){
Route::get('devices/deviceDelete','DevicesController@deviceDelete');//禁用设备和丢弃废纸篓 Route::get('devices/deviceDelete','DevicesController@deviceDelete');//禁用设备和丢弃废纸篓
Route::get('devices/UpPaperBasket/{id}','DevicesController@UpPaperBasket');//更新废纸篓和禁用用户 Route::get('devices/UpPaperBasket/{id}','DevicesController@UpPaperBasket');//更新废纸篓和禁用用户
Route::get('devices/deviceBasketList','DevicesController@deviceBasketList');//返回禁用设备和废纸篓设备 Route::get('devices/deviceBasketList','DevicesController@deviceBasketList');//返回禁用设备和废纸篓设备
Route::get('devices/addClassify/{data}','DevicesController@addClassify');//添加分类
Route::get('devices/delteClassify/{id}','DevicesController@delteClassify');//删除分类
}); });
//装维中心 //装维中心
......
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