Commit 0604a0c4 authored by Administrator's avatar Administrator

Merge branch 'release/shutoff_device_user_roles'

parents cd47bb4f 8c13fcc5
Pipeline #175 failed with stage
......@@ -55,10 +55,14 @@ class swooleMeTcp extends Command
public function start()
{
$url = config('public.swooletcpurl');
$this->tcp = new \swoole_server('0.0.0.0', 9503, SWOOLE_PROCESS,SWOOLE_SOCK_TCP | SWOOLE_SSL);
$this->tcp->addlistener('0.0.0.0', 9504, SWOOLE_SOCK_TCP | SWOOLE_SSL); // 添加 TCP端口监听
$this->tcp->addlistener('0.0.0.0', 9505, SWOOLE_SOCK_TCP | SWOOLE_SSL); // 添加 TCP端口监听
$this->tcp->addlistener('0.0.0.0', 9506, SWOOLE_SOCK_TCP | SWOOLE_SSL); // 添加 TCP端口监听
// $this->tcp = new \swoole_server('0.0.0.0', 9503, SWOOLE_PROCESS,SWOOLE_SOCK_TCP | SWOOLE_SSL);
//// $this->tcp->addlistener('0.0.0.0', 9504, SWOOLE_SOCK_TCP | SWOOLE_SSL); // 添加 TCP端口监听
//// $this->tcp->addlistener('0.0.0.0', 9505, SWOOLE_SOCK_TCP | SWOOLE_SSL); // 添加 TCP端口监听
//// $this->tcp->addlistener('0.0.0.0', 9506, SWOOLE_SOCK_TCP | SWOOLE_SSL); // 添加 TCP端口监听
$this->tcp = new \swoole_server('0.0.0.0', 9503, SWOOLE_PROCESS,SWOOLE_SOCK_TCP);
$this->tcp->addlistener('0.0.0.0', 9504, SWOOLE_SOCK_TCP); // 添加 TCP端口监听
$this->tcp->addlistener('0.0.0.0', 9505, SWOOLE_SOCK_TCP); // 添加 TCP端口监听
$this->tcp->addlistener('0.0.0.0', 9506, SWOOLE_SOCK_TCP); // 添加 TCP端口监听
$this->tcp->set([
'worker_num' => 2,//设置启动的 Worker 进程数
'max_request' =>30,//最大任务数
......@@ -67,8 +71,8 @@ class swooleMeTcp extends Command
'backlog' => 128,
'heartbeat_check_interval' => 30,
'heartbeat_idle_time' => 65,
'ssl_cert_file' => base_path() . config('app.ssl_cert_file'),
'ssl_key_file' => base_path() . config('app.ssl_key_file'),
// 'ssl_cert_file' => base_path() . config('app.ssl_cert_file'),
// 'ssl_key_file' => base_path() . config('app.ssl_key_file'),
]);
//监听连接进入事件
$this->tcp->on('Connect', function ($serv, $fd) {
......
......@@ -26,11 +26,30 @@ class HomepageController extends Controller
$usercount = Users::count();
$devicecount = Device::count();
$devicepolice = Device::where('devicepolice', '>', '1')->count();
// 设备在线数量
$device_online = Device::whereNotIn('devicepolice', [9, 15])->count();
// 设备报警数量
$device_alarm = Device::whereIn('devicepolice', [4, 5, 6, 16])->count();
// 未报警设备数量
$device_normal = Device::where('devicepolice', 1)->count();
// 故障设备
$device_offline = Device::whereNotIn('devicepolice', [1, 4, 5, 6, 16])->count();
$t = time();//当前时间
$start = mktime(0, 0, 0, date("m", $t), date("d", $t), date("Y", $t));//今天的开始
$end = mktime(23, 59, 59, date("m", $t), date("d", $t), date("Y", $t));//今天的结束
$timedevicepolice = DB::table('reportpolice')->where('status', '=', '1')->whereBetween('starttime', [$start, $end])->count();
return $this->jsonSuccessData(['usercount' => $usercount, 'devicecount' => $devicecount, 'devicepolice' => $devicepolice, 'timedevicepolice' => $timedevicepolice]);
return $this->jsonSuccessData([
'usercount' => $usercount,
'devicecount' => $devicecount,
'devicepolice' => $devicepolice,
'timedevicepolice' => $timedevicepolice,
'device_online' => $device_online,
'device_alarm' => $device_alarm,
'device_normal' => $device_normal,
'device_offline' => $device_offline,
'percent_alarm' => number_format(($device_alarm/$devicecount) * 100, '2'),
'percent_online' => number_format(($device_online/$devicecount) * 100, '2'),
]);
}
public function gettimeline()
......@@ -159,4 +178,4 @@ class HomepageController extends Controller
return $end_time - $start_time;
}
}
\ No newline at end of file
}
......@@ -280,8 +280,21 @@ class UserController extends Controller
->leftjoin('areachina as p', 'b.provinceid', '=', 'p.areaid')
->leftjoin('areachina as c', 'b.cityid', '=', 'c.areaid')
->leftjoin('areachina as a', 'b.areaid', '=', 'a.areaid')
->leftJoin('user_roles AS ur', 'b.user_role_id', '=', 'ur.id')
->orderBy('b.id', 'desc')
->select('b.username', 'b.id', 'b.created_at', 'b.name', 'b.email', 'b.state', 'a.area_name as area', 'c.area_name as city', 'p.area_name as province')
->select(
'b.username',
'b.id',
'b.created_at',
'b.name',
'b.email',
'b.state',
'b.phone_number',
'ur.name AS role_name',
'a.area_name as area',
'c.area_name as city',
'p.area_name as province'
)
->offset($pagenNum)
->limit($limit)
->get();
......@@ -434,7 +447,7 @@ class UserController extends Controller
return $this->jsonErrorData(105, '用户id不能为空');
}
$userdata = Users::where('id', '=', $userid)
->select('username', 'name', 'email', 'title', 'company', 'mapcenter')
->select('username', 'name', 'email', 'title', 'company', 'mapcenter', 'phone_number', 'user_role_id')
->first();
if ($userdata) {
return $this->jsonSuccessData($userdata);
......
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class AddShutOffToDeviceTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('device', function (Blueprint $table) {
$table->integer('shutoff_status')->default(0)->comment('切断装置状态,0初始化状态,1开启,2关闭');
$table->integer('shutoff_type')->default(0)->comment('切断装置类型,0未绑定,1电磁阀,2机械手');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('device', function (Blueprint $table) {
$table->dropColumn('shutoff_status');
$table->dropColumn('shutoff_type');
});
}
}
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateUserRolesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('user_roles', function (Blueprint $table) {
$table->id();
$table->string('name')->unique();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('user_roles');
}
}
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class AddPhoneAndUserRoleIdToUsersTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('users', function (Blueprint $table) {
$table->string('phone_number',11)->default(null)->comment('手机号码');
$table->integer('user_role_id')->comment('用户角色ID');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('users', function (Blueprint $table) {
$table->dropColumn('phone_number');
$table->dropColumn('user_role_id');
});
}
}
<?php
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
class UserRolesSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
Db::table('user_roles')->insert([
['name' => '行业主管部门负责人', 'created_at' => date('Y-m-d H:i:s')],
['name' => '燃气用户', 'created_at' => date('Y-m-d H:i:s')],
['name' => '应急抢修人员', 'created_at' => date('Y-m-d H:i:s')],
['name' => '村内“两员”', 'created_at' => date('Y-m-d H:i:s')]
]);
}
}
......@@ -8,9 +8,28 @@
<el-row :gutter="20">
<el-col :span="6"><el-card shadow="always">用户数量<span style="margin-left: 12px;color: #606266;">{{ synthesizecount.usercount }}</span></el-card></el-col>
<el-col :span="6"><el-card shadow="always">设备数量<span style="margin-left: 12px;color: #409EFF;">{{ synthesizecount.devicecount }}</span></el-card></el-col>
<el-col :span="6"><el-card shadow="always">报警数量<span style="margin-left: 12px;color: #E6A23C;">{{ synthesizecount.devicepolice }}</span></el-card></el-col>
<el-col :span="6"><el-card shadow="always">在线设备<span style="margin-left: 12px;color: green;">{{ synthesizecount.device_online }}</span></el-card></el-col>
<el-col :span="6"><el-card shadow="always">报警数量<span style="margin-left: 12px;color: #e50015;">{{ synthesizecount.device_alarm }}</span></el-card></el-col>
<el-col :span="6"><el-card shadow="always">未报警数量<span style="margin-left: 12px;color: green;">{{ synthesizecount.device_normal }}</span></el-card></el-col>
<el-col :span="6"><el-card shadow="always">设备故障<span style="margin-left: 12px;color: #5d5f5f;">{{ synthesizecount.device_offline }}</span></el-card></el-col>
<el-col :span="6"><el-card shadow="always">今天报警次数<span style="margin-left: 12px;color: #F56C6C;">{{ synthesizecount.timedevicepolice }}</span></el-card></el-col>
</el-row>
<el-row>
<el-card class="box-card" style="margin-top:12px;height: 200px;">
<div style="display: inline-block;">
<el-progress type="dashboard" :percentage="synthesizecount.percent_alarm" color="red"></el-progress>
<el-tooltip class="item" effect="red" :content="synthesizecount.percent_alarm + '%'" placement="top-start">
<span style="position: relative;left: -115px;top: 12px;">当前报警率</span>
</el-tooltip>
</div>
<div style="display: inline-block;">
<el-progress type="dashboard" :percentage="synthesizecount.percent_online" color="green"></el-progress>
<el-tooltip class="item" effect="green" :content="synthesizecount.percent_online + '%'" placement="top-start">
<span style="position: relative;left: -108px;top: 12px;">设备在线率</span>
</el-tooltip>
</div>
</el-card>
</el-row>
</div>
<!-- 混合统计 -->
<el-card class="box-card" style="margin-top:12px;padding-bottom:24px">
......
......@@ -54,7 +54,7 @@
<el-dialog
:title="dialogTitle"
:visible.sync="dialogTableVisible"
width="20%"
width="40%"
:modal="false"
custom-class="zero-dialog"
>
......@@ -70,7 +70,7 @@
<template slot="title">
设备列表 - {{ leftDeviceName }}
</template>
<el-table :data="markersDevice" style="100%" max-height="700">
<el-table :data="markersDevice" style="100%" max-height="700" @row-click="openDeviceBox">
<el-table-column property="devicenum" label="设备编号" width="200px"></el-table-column>
<el-table-column property="deviceinfo" label="位置" width="200px"></el-table-column>
<el-table-column property="nd" label="值" width="40px"></el-table-column>
......@@ -184,6 +184,7 @@ export default {
data(){
const _this = this;
return {
intervalId: null,
map: {},
amapManager: new AMapManager(),
zoom: 6,
......@@ -247,10 +248,17 @@ export default {
.then(res => {
this.markersDevice = res.data;
});
this.dataRefresh();
},
destroyed(){
// 在页面销毁后,清除计时器
this.clearIntv();
},
methods: {
checkPermission,
allDevices() {
this.clearIntv();
this.dataRefresh();
devices()
.then(res => {
this.leftDeviceName = '全部设备';
......@@ -290,10 +298,13 @@ export default {
},
// 获取单个用户下的设备
getUserDeviceList(uid) {
// 停止定时器
this.clearIntv();
devices({ uid: uid })
.then(res => {
this.markersDevice = res.data;
});
this.dataRefresh(uid);
},
// 获取设备详细信息
getUserDeviceInfo(id) {
......@@ -322,6 +333,14 @@ export default {
title: '检测介质',
content: deviceInfo.gas,
},
{
title: '切断装置',
content: this.shutoffDevice(deviceInfo.shutoff_type),
},
{
title: '切断装置状态',
content: this.shutoffStatus(deviceInfo.shutoff_status),
},
{
title: '状态',
content: deviceInfo.status_name,
......@@ -341,6 +360,59 @@ export default {
];
});
},
// 切断装置
shutoffDevice(id) {
const shutoff_types = [];
shutoff_types[0] = '未绑定';
shutoff_types[1] = '电磁阀';
shutoff_types[2] = '机械手';
return shutoff_types[id];
},
shutoffStatus(id) {
const shutoff = [];
shutoff[0] = '初始化';
shutoff[1] = '开启';
shutoff[2] = '关闭';
return shutoff[id];
},
openDeviceBox(row, column, event) {
this.getUserDeviceInfo(row.id);
},
// 定时刷新数据
dataRefresh(uid = null) {
// 计时器正在进行中,退出函数
if (this.intervalId != null) {
return;
}
// 计时器为空,操作
this.intervalId = setInterval(() => {
console.log('刷新' + uid + '--' + new Date());
if (uid > 0) {
users({ uid: uid })
.then(res => {
this.markers = res.data;
});
devices({ uid: uid })
.then(res => {
this.markersDevice = res.data;
});
} else {
users()
.then(res => {
this.markers = res.data;
});
devices({})
.then(res => {
this.markersDevice = res.data;
});
}
}, 3000);
},
// 停止定时器
clearIntv() {
clearInterval(this.intervalId); // 清除计时器
this.intervalId = null; // 设置为null
},
},
};
</script>
......
......@@ -40,6 +40,11 @@
<el-form-item>
<el-button type="primary" @click="onSubmit">查询</el-button>
</el-form-item>
<el-form-item>
<el-button v-if="device != '' " v-waves :loading="downloadLoading" class="filter-item" type="primary" icon="el-icon-download" @click="handleDownload">
{{ $t('table.export') }}
</el-button>
</el-form-item>
</el-form>
<el-table :key="tableKey" v-loading="loading" :data="device" border fit highlight-current-rows>
<el-table-column align="center" label="ID" width="80">
......@@ -72,6 +77,11 @@
<span>{{ scope.row.gas }}</span>
</template>
</el-table-column>
<el-table-column align="center" label="切断装置" width="170">
<template slot-scope="scope">
<span>{{ shutoffDevice(scope.row.shutoff_type) }}</span>
</template>
</el-table-column>
<el-table-column align="center" label="检测值" width="100">
<template slot-scope="scope">
<span>{{ scope.row.nd }}</span>
......@@ -82,6 +92,13 @@
<span>{{ scope.row.danwei }}</span>
</template>
</el-table-column>
<el-table-column align="center" label="切断装置状态" width="120">
<template slot-scope="scope">
<span>
<el-tag :type=" scope.row.shutoff_status==1 ? 'success' : 'warning' " effect="dark">{{ shutoffStatus(scope.row.shutoff_status) }}</el-tag>
</span>
</template>
</el-table-column>
<el-table-column align="center" label="实时状态" width="120">
<template slot-scope="scope">
<span>
......@@ -117,11 +134,15 @@ import { control } from '@/api/device';
import Pagination from '@/components/Pagination'; // 分页
import websocketurl from '@/api/configurl';
import clip from '@/utils/clipboard';
import waves from '@/directive/waves'; // 水波纹效果
import { parseTime } from '@/utils';
export default {
name: 'Devicetype',
directives: { waves },
components: { Pagination },
data() {
return {
downloadLoading: false,
tableKey: 0,
loading: true,
device: [],
......@@ -223,6 +244,21 @@ export default {
},
methods: {
// 切断装置
shutoffDevice(id) {
const shutoff_types = [];
shutoff_types[0] = '未绑定';
shutoff_types[1] = '电磁阀';
shutoff_types[2] = '机械手';
return shutoff_types[id];
},
shutoffStatus(id) {
const shutoff = [];
shutoff[0] = '初始化';
shutoff[1] = '开启';
shutoff[2] = '关闭';
return shutoff[id];
},
onSubmit() {
this.formSearch.page = 1;
this.devicelist();
......@@ -294,6 +330,34 @@ export default {
handleCopyphone(text, event){
clip(text, event);
},
// 导出到excel
handleDownload() {
this.downloadLoading = true;
import('@/vendor/Export2Excel').then(excel => {
const tHeader = ['ID', '设备编号', '设备名称', '设备详情', '设备类型', '检测介质', '切断装置', '单位', '切断装置状态', '实时状态', '最后更新时间'];
const filterVal = ['id', 'devicenum', 'username', 'deviceinfo', 'tname', 'gas', 'shutoff_type', 'danwei', 'shutoff_status', 'status_name', 'update_time'];
const data = this.formatJson(filterVal, this.device);
excel.export_json_to_excel({
header: tHeader,
data,
filename: '消防监测',
});
this.downloadLoading = false;
});
},
formatJson(filterVal, jsonData) {
return jsonData.map(v => filterVal.map(j => {
if (j === 'shutoff_type') {
return this.shutoffDevice(v[j]);
} else if (j === 'shutoff_status') {
return this.shutoffStatus(v[j]);
} else if (j === 'update_time') {
return parseTime(v[j]);
} else {
return v[j];
}
}));
},
},
};
</script>
......
......@@ -47,7 +47,17 @@
</el-table-column>
<el-table-column align="center" label="用户地址" width="340">
<template slot-scope="scope">
<span>{{ scope.row.province }}-{{ scope.row.area }}-{{ scope.row.city }}</span>
<span>{{ scope.row.province }}<br>{{ scope.row.area }}<br>{{ scope.row.city }}</span>
</template>
</el-table-column>
<el-table-column align="center" label="手机号">
<template slot-scope="scope">
<span>{{ scope.row.phone_number }}</span>
</template>
</el-table-column>
<el-table-column align="center" label="角色">
<template slot-scope="scope">
<span>{{ scope.row.role_name }}</span>
</template>
</el-table-column>
<el-table-column align="center" label="创建时间" width="170">
......@@ -87,6 +97,14 @@
<el-form-item label="邮箱" prop="email">
<el-input v-model.number="upUserData.email"></el-input>
</el-form-item>
<el-form-item label="手机号" prop="phone_number">
<el-input v-model.number="upUserData.phone_number"></el-input>
</el-form-item>
<el-form-item label="角色" prop="user_role">
<el-select v-model="upUserData.user_role_id" clearable class="filter-item" @change="selectOne">
<el-option v-for="item in user_roles" :key="item.id" :label="item.name" :value="item.id" />
</el-select>
</el-form-item>
<el-form-item label="自定义标题" prop="title">
<el-input v-model.number="upUserData.title"></el-input>
</el-form-item>
......@@ -133,8 +151,16 @@ export default {
email: undefined,
company: undefined,
userid: undefined,
phone_number: undefined,
user_role_id: undefined,
},
paper: undefined,
user_roles: [
{ id: 1, name: '行业主管部门负责人' },
{ id: 2, name: '燃气用户' },
{ id: 3, name: '应急抢修人员' },
{ id: 4, name: '村内“两员”' },
],
};
},
created() {
......@@ -280,6 +306,7 @@ export default {
type: 'warning',
});
} else {
console.log(response.data);
for (const key in this.upUserData) {
for (const k in response.data) {
if (key === k) {
......
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