Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
L
laravelzh
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
冯超鹏
laravelzh
Commits
537eec59
Commit
537eec59
authored
Jul 02, 2020
by
冯超鹏
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
提交报警
parent
2cd1f183
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
196 additions
and
7 deletions
+196
-7
alarm.php
app/Console/Commands/alarm.php
+93
-0
SwooleCommandController.php
app/Http/Controllers/Auth/SwooleCommandController.php
+16
-0
HomepageController.php
app/Http/Controllers/HomepageController.php
+2
-3
configurl.js
resources/js/api/configurl.js
+2
-0
index.vue
resources/js/layout/components/TagsView/index.vue
+80
-1
chemicals.vue
resources/js/views/monitor/chemicals.vue
+1
-1
fire.vue
resources/js/views/monitor/fire.vue
+1
-1
userStatistics.vue
resources/js/views/user/userStatistics.vue
+1
-1
No files found.
app/Console/Commands/alarm.php
0 → 100644
View file @
537eec59
<?php
namespace
App\Console\Commands
;
use
App\Http\Controllers\Auth\SwooleCommandController
;
use
Illuminate\Console\Command
;
use
Illuminate\Support\Facades\Log
;
class
alarm
extends
Command
{
public
$ws
;
private
$token
=
'zxc123456789ZXC'
;
public
$time
=
10
;
/**
* The name and signature of the console command.
*
* @var string
*/
protected
$signature
=
'swoolealarm {action?}'
;
/**
* The console command description.
*
* @var string
*/
protected
$description
=
'swoolealarm'
;
/**
* Create a new command instance.
*
* @return void
*/
public
function
__construct
()
{
parent
::
__construct
();
}
/**
* Execute the console command.
*
* @return mixed
*/
public
function
handle
()
{
$action
=
$this
->
argument
(
'action'
);
switch
(
$action
)
{
case
'close'
:
break
;
default
:
$this
->
start
();
break
;
}
}
//开启WebSocket
public
function
start
()
{
$url
=
config
(
'public.swoolwebsocketurl'
);
$por
=
config
(
'public.swoolwebsocketurlpor'
);
$this
->
ws
=
new
\swoole_websocket_server
(
'0.0.0.0'
,
9601
);
//创建一个端口
$this
->
ws
->
set
(
array
(
'reactor_num'
=>
2
,
//reactor线程数
'worker_num'
=>
4
,
//worker进程数
'backlog'
=>
128
,
//Listen队列长度
'max_request'
=>
10
,
//最大连接
'daemonize'
=>
0
,
//守护进程
));
$this
->
ws
->
on
(
'open'
,
function
(
$ws
,
$request
)
{
// //链接成功
$userdata
=
new
SwooleCommandController
();
$this
->
ws
->
push
(
$request
->
fd
,
$userdata
->
alarm
(),
1
);
swoole_timer_tick
(
6000
,
function
(
$timerId
)
use
(
$ws
,
$request
)
{
$userdata
=
new
SwooleCommandController
();
$this
->
ws
->
push
(
$request
->
fd
,
$userdata
->
alarm
(),
1
);
});
});
//监听WebSocket消息事件
$this
->
ws
->
on
(
'message'
,
function
(
$ws
,
$frame
)
{
});
$this
->
ws
->
on
(
'request'
,
function
(
$request
,
$response
,
$from_id
,
$fd
)
{
});
//监听WebSocket连接关闭事件
$this
->
ws
->
on
(
'close'
,
function
(
$ws
,
$fd
)
{
echo
"client:
{
$fd
}
is closed
\n
"
;
swoole_timer_clear
(
$this
->
time
);
});
$this
->
ws
->
start
();
}
}
app/Http/Controllers/Auth/SwooleCommandController.php
View file @
537eec59
...
...
@@ -56,4 +56,20 @@ class SwooleCommandController extends Controller
return
$this
->
jsonSuccessData
([
'devicelist'
=>
$devicelist
,
'count'
=>
$count
]);
}
//监测是否设备报警
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
,
'当前无报警'
);
}
}
}
\ No newline at end of file
app/Http/Controllers/HomepageController.php
View file @
537eec59
...
...
@@ -48,12 +48,11 @@ class HomepageController extends Controller
->
groupBy
(
'date'
)
->
get
()
->
toArray
();
$policedata
=
Users
::
whereBetween
(
'created_at'
,
[
$year_start
,
$endThismonth
])
->
selectRaw
(
'from_unixtime(
created_at
,"%Y-%m") as date,COUNT(id) as value'
)
$policedata
=
Users
::
whereBetween
(
'created_at'
,
[
date
(
'Y-m-d H:i:s'
,
$year_start
),
date
(
'Y-m-d H:i:s'
,
$endThismonth
)
])
->
selectRaw
(
'from_unixtime(
unix_timestamp(created_at)
,"%Y-%m") as date,COUNT(id) as value'
)
->
groupBy
(
'date'
)
->
get
()
->
toArray
();
$devicepolice
=
Device
::
whereBetween
(
'deviceaddtime'
,
[
$year_start
,
$endThismonth
])
->
where
(
'devicepolice'
,
'>'
,
1
)
->
selectRaw
(
'from_unixtime(deviceaddtime,"%Y-%m") as date,COUNT(id) as value'
)
...
...
resources/js/api/configurl.js
View file @
537eec59
const
baseURL
=
'ws://127.0.0.1:9502'
;
const
chemicalsUrl
=
'ws://127.0.0.1:9507'
;
const
fireUrl
=
'ws://127.0.0.1:9508'
;
const
alarmUrl
=
'ws://127.0.0.1:9601'
;
const
mapkey
=
'2719fe261fee06a08dcb4980990879da'
;
const
mapurl
=
'https://webapi.amap.com/maps?v=1.4.15&key='
;
export
default
{
...
...
@@ -9,4 +10,5 @@ export default {
mapurl
,
chemicalsUrl
,
fireUrl
,
alarmUrl
,
};
resources/js/layout/components/TagsView/index.vue
View file @
537eec59
...
...
@@ -38,7 +38,7 @@
import
ScrollPane
from
'./ScrollPane'
;
import
{
generateTitle
}
from
'@/utils/i18n'
;
import
path
from
'path'
;
import
websocketurl
from
'@/api/configurl'
;
export
default
{
components
:
{
ScrollPane
},
data
()
{
...
...
@@ -74,6 +74,7 @@ export default {
mounted
()
{
this
.
initTags
();
this
.
addTags
();
this
.
initWebSocket
();
// 返回报警
},
methods
:
{
generateTitle
,
// generateTitle by vue-i18n
...
...
@@ -117,6 +118,84 @@ export default {
}
return
false
;
},
initWebSocket
()
{
const
wsuri
=
websocketurl
.
alarmUrl
;
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
);
if
(
redata
.
code
===
200
)
{
localStorage
.
removeItem
(
'isalam'
);
if
(
localStorage
.
getItem
(
'isalam'
)
===
null
||
localStorage
.
getItem
(
'isalam'
)
===
undefined
)
{
// 第一次没有的话
localStorage
.
setItem
(
'isalam'
,
JSON
.
stringify
(
redata
.
data
));
for
(
let
i
=
0
;
i
<
redata
.
data
.
length
;
i
++
)
{
setTimeout
(()
=>
{
this
.
$notify
.
error
({
title
:
'报警提示!点击X可消警'
,
dangerouslyUseHTMLString
:
true
,
duration
:
0
,
message
:
redata
.
data
[
i
].
devicenumber
+
'正在报警请尽快处理'
,
onClose
:
function
(){
console
.
log
(
redata
.
data
[
i
].
devicenumber
);
},
});
},
3
);
}
}
else
{
for
(
let
j
=
0
;
j
<
redata
.
data
.
length
;
j
++
)
{
console
.
log
(
redata
.
data
[
j
].
devicenumber
,
JSON
.
parse
(
localStorage
.
getItem
(
'isalam'
)));
if
(
!
this
.
isarray
(
redata
.
data
[
j
].
devicenumber
,
JSON
.
parse
(
localStorage
.
getItem
(
'isalam'
))))
{
setTimeout
(()
=>
{
this
.
$notify
.
error
({
title
:
'报警提示!点击X可消警'
,
dangerouslyUseHTMLString
:
true
,
duration
:
0
,
message
:
redata
.
data
[
j
].
devicenumber
+
'正在报警请尽快处理'
,
onClose
:
function
(){
console
.
log
(
redata
.
data
[
j
].
devicenumber
);
},
});
},
3
);
}
}
}
}
},
websocketsend
(){
// 数据发送
this
.
websock
.
send
(
JSON
.
stringify
(
this
.
type
));
},
websocketclose
(
e
){
// 关闭
console
.
log
(
'断开连接'
,
e
);
this
.
$notify
({
title
:
'警告'
,
message
:
'监测报警长连接已断开'
,
type
:
'warning'
,
});
},
isarray
(
needle
,
arr
)
{
// data长连接返回 adata本地储
var
has
=
false
;
for
(
let
i
=
0
;
i
<
arr
.
length
;
i
++
)
{
if
(
arr
[
i
].
devicenumber
===
needle
)
{
return
true
;
}
}
return
has
;
},
moveToCurrentTag
()
{
const
tags
=
this
.
$refs
.
tag
;
this
.
$nextTick
(()
=>
{
...
...
resources/js/views/monitor/chemicals.vue
View file @
537eec59
...
...
@@ -144,7 +144,7 @@ export default {
console
.
log
(
'断开连接'
,
e
);
this
.
$notify
({
title
:
'警告'
,
message
:
'长连接已断开'
,
message
:
'
危化监测
长连接已断开'
,
type
:
'warning'
,
}
);
}
,
...
...
resources/js/views/monitor/fire.vue
View file @
537eec59
...
...
@@ -144,7 +144,7 @@ export default {
console
.
log
(
'断开连接'
,
e
);
this
.
$notify
({
title
:
'警告'
,
message
:
'长连接已断开'
,
message
:
'
消防监测
长连接已断开'
,
type
:
'warning'
,
}
);
}
,
...
...
resources/js/views/user/userStatistics.vue
View file @
537eec59
...
...
@@ -146,7 +146,7 @@ export default {
console
.
log
(
'断开连接'
,
e
);
this
.
$notify
({
title
:
'警告'
,
message
:
'长连接已断开'
,
message
:
'
用户统计
长连接已断开'
,
type
:
'warning'
,
});
},
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment