Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
glsx-business
/
glsx-data-screen-server
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 9595019e
authored
Dec 12, 2019
by
liimin
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
新增接口
1 parent
bd2cd596
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
49 additions
and
11 deletions
app/common/queue.js
app/controller/screen/user.js
app/router/screen/user.js
app/service/screen/user.js
app/common/queue.js
View file @
9595019
...
...
@@ -2,7 +2,7 @@
* @Author: limin
* @Date: 2019-12-06 14:58:35
* @Last Modified by: limin
* @Last Modified time: 2019-12-0
7 16:11:22
* @Last Modified time: 2019-12-0
8 21:19:20
*/
// const items = new WeakMap(); //WeakMap对象是密钥/值对的集合,其中密钥被弱引用。键必须是对象,值可以是任意值。
...
...
@@ -58,9 +58,10 @@
// }
module
.
exports
=
class
Queue
{
constructor
({
size
})
{
constructor
({
size
,
data
,
fn
})
{
this
.
_elements
=
[];
this
.
_size
=
size
;
this
.
_last_dequeue
=
data
;
}
isArray
(
arr
)
{
return
Object
.
prototype
.
toString
.
call
(
arr
)
===
"[object Array]"
;
...
...
@@ -98,15 +99,15 @@ module.exports = class Queue {
return
this
.
_elements
.
shift
();
}
peek
()
{
const
r
=
this
.
_elements
;
this
.
_last_dequeue
=
this
.
_elements
;
this
.
_elements
=
[];
return
r
;
return
this
.
_last_dequeue
;
}
async
fill
(
fn
,
last_peek_data
)
{
async
fill
(
fn
)
{
const
result
=
await
fn
();
const
_result_size
=
result
.
length
;
if
(
!
_result_size
)
{
this
.
enqueue
(
last_peek_data
);
this
.
enqueue
(
this
.
_last_dequeue
);
}
else
if
(
_result_size
<
this
.
_size
)
{
// 从上一次返回的数据中 获取相差的几条数据 补充到最新数据的末尾 保证队列数据的数量 公式为: [data][_result_size]
const
_last_data_list
=
data
.
filter
((
item
,
index
)
=>
index
>=
_result_size
);
...
...
app/controller/screen/user.js
View file @
9595019
...
...
@@ -2,7 +2,7 @@
* @Author: limin
* @Date: 2019-11-21 11:20:01
* @Last Modified by: limin
* @Last Modified time: 2019-12-
07 16:01:48
* @Last Modified time: 2019-12-
12 11:10:21
*/
"use strict"
;
...
...
@@ -184,8 +184,10 @@ class UserController extends Controller {
var
total
=
await
this
.
_fetch_total_last_day_
({
pid
,
cid
,
field
:
'u'
})
const
realtime
=
await
this
.
UserService
.
user_realtime
({
pid
,
cid
});
const
realtime_total
=
realtime
.
reduce
((
pre
,
next
)
=>
pre
+
+
next
[
'increase'
],
0
);
const
online_total
=
realtime
.
reduce
((
pre
,
next
)
=>
pre
+
+
next
[
'online_total'
],
0
);
const
online_time
=
realtime
.
reduce
((
pre
,
next
)
=>
pre
+
+
next
[
'online_time'
],
0
);
total
+=
~~
realtime_total
;
const
data
=
{
total
};
const
data
=
{
total
,
online_total
,
online_time
};
this
.
ctx
.
body
=
this
.
ServerResponse
.
Success
(
data
);
}
/**
...
...
@@ -289,10 +291,20 @@ class UserController extends Controller {
const
data
=
this
.
queue
.
peek
();
const
{
USER_ACTIVE_DATA_LASI_ID
}
=
this
.
helper
.
constant
;
const
_last_id
=
await
this
.
CacheService
.
get
(
USER_ACTIVE_DATA_LASI_ID
);
this
.
queue
.
fill
(
async
()
=>
await
this
.
UserService
.
activation
({
pid
,
limit
:
this
.
queue
.
size
(),
last_id
:
_last_id
})
,
data
)
this
.
queue
.
fill
(
async
()
=>
await
this
.
UserService
.
activation
({
pid
,
limit
:
this
.
queue
.
size
(),
last_id
:
_last_id
}))
.
then
(
last_id
=>
last_id
&&
this
.
CacheService
.
set
(
USER_ACTIVE_DATA_LASI_ID
,
last_id
))
this
.
ctx
.
body
=
this
.
ServerResponse
.
Success
(
data
);
}
/**
* @Router GET /screen/user/total_group_by_province
* @Description 获取每个省的总用户数
* @Request query integer pid 省份id
*/
async
total_group_by_province
({
query
:
{
pid
}
})
{
const
data
=
await
this
.
UserService
.
total_group_by_province
({
pid
});
this
.
ctx
.
body
=
this
.
ServerResponse
.
Success
(
data
);
}
}
module
.
exports
=
UserController
;
app/router/screen/user.js
View file @
9595019
...
...
@@ -2,7 +2,7 @@
* @Author: limin
* @Date: 2019-11-21 11:18:45
* @Last Modified by: limin
* @Last Modified time: 2019-12-
07 11:48:43
* @Last Modified time: 2019-12-
12 11:07:44
*/
module
.
exports
=
app
=>
{
...
...
@@ -14,4 +14,5 @@ module.exports = app => {
app
.
router
.
get
(
'/screen/user/drive_range'
,
app
.
controller
.
screen
.
user
.
drive_range
);
app
.
router
.
get
(
'/screen/user/trend'
,
app
.
controller
.
screen
.
user
.
trend
);
app
.
router
.
get
(
'/screen/user/activation'
,
app
.
controller
.
screen
.
user
.
activation
);
app
.
router
.
get
(
'/screen/user/total_group_by_province'
,
app
.
controller
.
screen
.
user
.
total_group_by_province
);
};
\ No newline at end of file
app/service/screen/user.js
View file @
9595019
...
...
@@ -2,7 +2,7 @@
* @Author: limin
* @Date: 2019-11-21 11:18:37
* @Last Modified by: limin
* @Last Modified time: 2019-12-
07 15:04:3
2
* @Last Modified time: 2019-12-
12 11:09:1
2
*/
const
Service
=
require
(
"egg"
).
Service
;
...
...
@@ -253,6 +253,30 @@ class UserService extends Service {
const
data
=
await
MUserGender
.
findAll
(
option
);
return
data
;
}
/**
* @param field {String}
* @param value {String}
* @return {Promise.<boolean>}
* @Description 获取每个省的用户数
*/
async
total_group_by_province
({
pid
})
{
const
{
app
,
helper
,
MUserDaily
,
MProvice
}
=
this
;
var
option
=
helper
.
seq_option
({
pid
});
const
{
fn
,
col
}
=
app
.
Sequelize
;
Object
.
assign
(
option
,
{
attributes
:
[
'prov_code'
,
[
fn
(
"SUM"
,
col
(
"total_user"
)),
"total_user"
],
col
(
"t_province.prov_name"
)
],
include
:
[{
model
:
MProvice
,
attributes
:
[]}],
group
:
'prov_code'
,
raw
:
true
});
const
data
=
await
MUserDaily
.
findAll
(
option
);
return
data
;
}
}
module
.
exports
=
UserService
;
Write
Preview
Markdown
is supported
Attach a file
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 post a comment