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 4a826dbe
authored
Dec 02, 2019
by
liimin
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
修改表
1 parent
534a0c9f
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
218 additions
and
172 deletions
README.md
app/common/constant.js
app/controller/screen/user.js
app/extend/helper.js
app/model/t_user_city_average_miles_day.js
app/model/t_user_city_carprice.js
app/model/t_user_city_average_drive_month.js → app/model/t_user_city_drive_info.js
app/schedule/update_cache.js
app/service/screen/user.js
README.md
View file @
4a826db
...
@@ -51,7 +51,7 @@ npm install -g egg-sequelize-auto mysql2
...
@@ -51,7 +51,7 @@ npm install -g egg-sequelize-auto mysql2
-e 数据库类型
-e 数据库类型
-a json定义文件路径,可以追加一些自定义配置,如{"timestamps": false}
-a json定义文件路径,可以追加一些自定义配置,如{"timestamps": false}
-
create model: $ egg-sequelize-auto -o "./app/model" -d
test
-h 192.168.0.39 -u root -p 3306 -x 123456 -t usedrow -e mysql
-
create model: $ egg-sequelize-auto -o "./app/model" -d
glsx_data_screen
-h 192.168.0.39 -u root -p 3306 -x 123456 -t usedrow -e mysql
-
不指定-t 为所有表
-
不指定-t 为所有表
-- shell
-- shell
...
...
app/common/constant.js
View file @
4a826db
...
@@ -2,11 +2,11 @@
...
@@ -2,11 +2,11 @@
* @Author: limin
* @Author: limin
* @Date: 2019-11-21 11:20:15
* @Date: 2019-11-21 11:20:15
* @Last Modified by: limin
* @Last Modified by: limin
* @Last Modified time: 2019-1
1-29 09:43:28
* @Last Modified time: 2019-1
2-02 12:16:54
*/
*/
module
.
exports
=
{
module
.
exports
=
{
PREFIX
:
'_glsx_data_screen_'
,
PREFIX
:
'_glsx_data_screen_'
,
USER_SUMMARY_
YESTERDAY
:
'user_summary_yester
day'
,
USER_SUMMARY_
30_DAY
:
'user_summary_30_
day'
,
DATES
:
'dates'
DATES
:
'dates'
};
};
\ No newline at end of file
\ No newline at end of file
app/controller/screen/user.js
View file @
4a826db
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
* @Author: limin
* @Author: limin
* @Date: 2019-11-21 11:20:01
* @Date: 2019-11-21 11:20:01
* @Last Modified by: limin
* @Last Modified by: limin
* @Last Modified time: 2019-1
1-29 14:12:17
* @Last Modified time: 2019-1
2-02 18:10:30
*/
*/
"use strict"
;
"use strict"
;
...
@@ -24,28 +24,45 @@ class UserController extends Controller {
...
@@ -24,28 +24,45 @@ class UserController extends Controller {
this
.
ServerResponseCode
=
ctx
.
response
.
ServerResponseCode
;
this
.
ServerResponseCode
=
ctx
.
response
.
ServerResponseCode
;
this
.
ServerResponse
=
ctx
.
response
.
ServerResponse
;
this
.
ServerResponse
=
ctx
.
response
.
ServerResponse
;
}
}
async
_fetch_date_in_cache
(){
const
{
DATES
}
=
this
.
helper
.
constant
;
return
await
this
.
CacheService
.
get
(
DATES
);
}
/**
/**
* 内部方法 从内存获取 昨天的统计数据
* 内部方法 从内存获取 昨天的统计数据
* 比较数据时间 如果不是昨天的数据 则启动定时任务 更新一遍数据 再次获取数据并返回
* 比较数据时间 如果不是昨天的数据 则启动定时任务 更新一遍数据 再次获取数据并返回
*/
*/
async
_fetch_summary
_yesterday
(){
async
_fetch_summary
(
arg
){
const
{
DATES
,
USER_SUMMARY_YESTER
DAY
}
=
this
.
helper
.
constant
;
const
{
USER_SUMMARY_30_
DAY
}
=
this
.
helper
.
constant
;
var
yesterday_total
=
await
this
.
CacheService
.
get
(
USER_SUMMARY_YESTER
DAY
);
var
summary_30_day
=
await
this
.
CacheService
.
get
(
USER_SUMMARY_30_
DAY
);
const
{
date
}
=
yesterday_total
;
const
{
date
}
=
summary_30_day
;
const
{
yesterday
}
=
await
this
.
CacheService
.
get
(
DATES
);
const
{
yesterday
}
=
await
this
.
_fetch_date_in_cache
(
);
if
(
date
!==
yesterday
){
//如果 内存中的数据的日期不是昨天的 则手动启动定时器 更新缓存数据
if
(
date
!==
yesterday
){
//如果 内存中的数据的日期不是昨天的 则手动启动定时器 更新缓存数据
await
this
.
app
.
runSchedule
(
'update_cache'
);
await
this
.
app
.
runSchedule
(
'update_cache'
);
yesterday_total
=
await
this
.
CacheService
.
get
(
USER_SUMMARY_YESTER
DAY
);
summary_30_day
=
await
this
.
CacheService
.
get
(
USER_SUMMARY_30_
DAY
);
}
}
return
yesterday_total
var
result
=
null
;
if
(
arg
){
const
{
beginDate
,
endDate
}
=
arg
result
=
[]
for
(
const
day
in
summary_30_day
){
if
(
day
>=
+
beginDate
&&
day
<=
+
endDate
){
result
.
push
(
summary_30_day
[
day
])
}
}
}
else
{
result
=
summary_30_day
[
date
]
}
return
result
}
}
/**
/**
* 内部方法 从内存获取
昨
天的统计数据
* 内部方法 从内存获取
最后一
天的统计数据
*/
*/
async
_fetch_total
({
pid
,
cid
,
field
}
){
async
_fetch_total
_last_day
({
pid
,
cid
,
field
}
){
const
_summary
=
await
this
.
_fetch_summary
_yesterday
();
const
_summary
=
await
this
.
_fetch_summary
();
var
{
p
rovince
}
=
_summary
;
var
{
p
}
=
_summary
;
var
total
=
0
;
var
total
=
0
;
function
_set
(
target
){
function
_set
(
target
){
var
total
;
var
total
;
...
@@ -60,28 +77,35 @@ class UserController extends Controller {
...
@@ -60,28 +77,35 @@ class UserController extends Controller {
return
total
;
return
total
;
}
}
if
(
pid
)
{
if
(
pid
)
{
var
obj
=
cid
?
p
rovince
[
pid
][
"city"
][
cid
]
:
province
[
pid
];
var
obj
=
cid
?
p
[
pid
][
"c"
][
cid
]
:
p
[
pid
];
obj
&&
(
total
=
_set
(
obj
));
obj
&&
(
total
=
_set
(
obj
));
}
else
{
}
else
{
total
=
_set
(
_summary
)
total
=
_set
(
_summary
)
}
}
return
total
;
return
total
;
}
}
_reduce
(
obj
,
field
){
return
obj
.
reduce
((
pre
,
next
)
=>
pre
+
+
next
[
field
],
0
)
}
/**
* 内部方法 从内存获取 范围时间内的数据
*/
async
_fetch_total_by_range
({
pid
,
cid
,
field
,
beginDate
,
endDate
}
){
const
_list
=
await
this
.
_fetch_summary
({
beginDate
,
endDate
});
console
.
log
(
_list
);
}
/**
/**
* @Router GET /screen/user/total
* @Router GET /screen/user/total
* @Description 数据大屏-用户总数统计.----参数pid 有 则返回对应的省份数据.没有则是全国数据的统计
* @Description 数据大屏-用户总数统计.----参数pid 有 则返回对应的省份数据.没有则是全国数据的统计
* @Request query integer pid 省份id
* @Request query integer pid 省份id
*/
*/
async
total
({
query
:
{
pid
,
cid
}
})
{
async
total
({
query
:
{
pid
,
cid
}
})
{
var
total
=
await
this
.
_fetch_total
({
pid
,
cid
,
field
:
'total'
})
var
total
=
await
this
.
_fetch_total_last_day
({
pid
,
cid
,
field
:
'u'
})
const
today_total
=
await
this
.
UserService
.
last_n_day_user_increased
({
n
:
0
,
pid
,
cid
});
const
realtime
=
await
this
.
UserService
.
user_realtime
({
pid
,
cid
});
total
+=
~~
today_total
;
const
realtime_total
=
this
.
_reduce
(
realtime
,
'increase'
);
// console.log(this.app.cache.today);
total
+=
~~
realtime_total
;
// `user_summary_${day}`
// const data = await this.CacheService.get("test", () =>
// this.DemoService.hello(this.request.body)
// );
// const statics = await this.UserService.total(pid);
const
data
=
{
total
};
const
data
=
{
total
};
this
.
ctx
.
body
=
this
.
ServerResponse
.
Success
(
data
);
this
.
ctx
.
body
=
this
.
ServerResponse
.
Success
(
data
);
}
}
...
@@ -90,10 +114,11 @@ class UserController extends Controller {
...
@@ -90,10 +114,11 @@ class UserController extends Controller {
* @Description 数据大屏-数据统计 1. 近七天新增用户数 2.近七天用户活跃度 3.近30天用户留存率 4.用户付费转化率
* @Description 数据大屏-数据统计 1. 近七天新增用户数 2.近七天用户活跃度 3.近30天用户留存率 4.用户付费转化率
* @Request query integer pid 省份id
* @Request query integer pid 省份id
*/
*/
async
statistics
({
query
:
{
pid
,
n
=
-
7
,
cid
}
})
{
async
statistics
({
query
:
{
pid
,
cid
}
})
{
const
data
=
await
this
.
UserService
.
last_n_day_user_increased_detail
({
n
,
pid
,
cid
});
const
beginDate7
=
this
.
helper
.
date
(
-
7
,
'YYYYMMDD'
);
// //近7天新增用户数
const
{
yesterday
}
=
await
this
.
_fetch_date_in_cache
();
// const increased7 = await this.UserService.last_n_day_user_increased({ n, pid, cid });
//近7天新增用户数
const
increased7
=
await
this
.
_fetch_total_by_range
({
pid
,
cid
,
field
:
'i'
,
beginDate
:
beginDate7
,
endDate
:
yesterday
});
// //近七天 活跃用户数
// //近七天 活跃用户数
// const nLive7 = await this.UserService.last_n_day_user_lively({ n, pid, cid });
// const nLive7 = await this.UserService.last_n_day_user_lively({ n, pid, cid });
// // 近七天 用户活跃度 (近N天 活跃用户数 / 近N天新增用户数)
// // 近七天 用户活跃度 (近N天 活跃用户数 / 近N天新增用户数)
...
@@ -109,6 +134,7 @@ class UserController extends Controller {
...
@@ -109,6 +134,7 @@ class UserController extends Controller {
// // 昨天的付费转化率 (昨天的付费总人数 / 昨天用户总数)
// // 昨天的付费转化率 (昨天的付费总人数 / 昨天用户总数)
// const renew_yesterday = this.helper.percent(renew,total);
// const renew_yesterday = this.helper.percent(renew,total);
// const data = { increased7, live7,increased30,live30,renew_yesterday };
// const data = { increased7, live7,increased30,live30,renew_yesterday };
const
data
=
{
increased7
};
this
.
ctx
.
body
=
this
.
ServerResponse
.
Success
(
data
);
this
.
ctx
.
body
=
this
.
ServerResponse
.
Success
(
data
);
}
}
...
...
app/extend/helper.js
View file @
4a826db
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
* @Author: limin
* @Author: limin
* @Date: 2019-11-21 11:19:43
* @Date: 2019-11-21 11:19:43
* @Last Modified by: limin
* @Last Modified by: limin
* @Last Modified time: 2019-1
1-29 11:38:08
* @Last Modified time: 2019-1
2-02 12:15:42
*/
*/
const
moment
=
require
(
"moment"
);
const
moment
=
require
(
"moment"
);
...
...
app/model/t_user_city_average_miles_day.js
deleted
100644 → 0
View file @
534a0c9
/* indent size: 2 */
module
.
exports
=
app
=>
{
const
DataTypes
=
app
.
Sequelize
;
const
Model
=
app
.
model
.
define
(
't_user_city_average_miles_day'
,
{
id
:
{
type
:
DataTypes
.
INTEGER
(
10
),
allowNull
:
false
,
primaryKey
:
true
,
autoIncrement
:
true
},
prov_code
:
{
type
:
DataTypes
.
STRING
(
32
),
allowNull
:
false
},
city_code
:
{
type
:
DataTypes
.
STRING
(
32
),
allowNull
:
false
},
miles_range
:
{
type
:
DataTypes
.
STRING
(
32
),
allowNull
:
false
},
total_users
:
{
type
:
DataTypes
.
INTEGER
(
10
),
allowNull
:
true
},
range_users
:
{
type
:
DataTypes
.
INTEGER
(
10
),
allowNull
:
true
},
create_time
:
{
type
:
DataTypes
.
DATE
,
allowNull
:
true
},
update_time
:
{
type
:
DataTypes
.
DATE
,
allowNull
:
true
}
},
{
tableName
:
't_user_city_average_miles_day'
});
Model
.
associate
=
function
()
{
}
return
Model
;
};
app/model/t_user_city_carprice.js
deleted
100644 → 0
View file @
534a0c9
/* indent size: 2 */
module
.
exports
=
app
=>
{
const
DataTypes
=
app
.
Sequelize
;
const
Model
=
app
.
model
.
define
(
't_user_city_carprice'
,
{
id
:
{
type
:
DataTypes
.
INTEGER
(
10
),
allowNull
:
false
,
primaryKey
:
true
,
autoIncrement
:
true
},
prov_code
:
{
type
:
DataTypes
.
STRING
(
32
),
allowNull
:
false
},
city_code
:
{
type
:
DataTypes
.
STRING
(
32
),
allowNull
:
false
},
price_range
:
{
type
:
DataTypes
.
STRING
(
32
),
allowNull
:
false
},
range_cars
:
{
type
:
DataTypes
.
INTEGER
(
10
),
allowNull
:
true
},
create_time
:
{
type
:
DataTypes
.
DATE
,
allowNull
:
true
},
update_time
:
{
type
:
DataTypes
.
DATE
,
allowNull
:
true
}
},
{
tableName
:
't_user_city_carprice'
});
Model
.
associate
=
function
()
{
}
return
Model
;
};
app/model/t_user_city_
average_drive_month
.js
→
app/model/t_user_city_
drive_info
.js
View file @
4a826db
...
@@ -3,7 +3,7 @@
...
@@ -3,7 +3,7 @@
module
.
exports
=
app
=>
{
module
.
exports
=
app
=>
{
const
DataTypes
=
app
.
Sequelize
;
const
DataTypes
=
app
.
Sequelize
;
const
Model
=
app
.
model
.
define
(
't_user_city_
average_drive_month
'
,
{
const
Model
=
app
.
model
.
define
(
't_user_city_
drive_info
'
,
{
id
:
{
id
:
{
type
:
DataTypes
.
INTEGER
(
10
),
type
:
DataTypes
.
INTEGER
(
10
),
allowNull
:
false
,
allowNull
:
false
,
...
@@ -16,17 +16,70 @@ module.exports = app => {
...
@@ -16,17 +16,70 @@ module.exports = app => {
},
},
city_code
:
{
city_code
:
{
type
:
DataTypes
.
STRING
(
32
),
type
:
DataTypes
.
STRING
(
32
),
allowNull
:
false
allowNull
:
false
,
unique
:
true
},
},
days_range
:
{
total
:
{
type
:
DataTypes
.
STRING
(
32
),
type
:
DataTypes
.
INTEGER
(
10
),
allowNull
:
false
allowNull
:
true
},
d_0_5
:
{
type
:
DataTypes
.
INTEGER
(
10
),
allowNull
:
true
},
d_5_10
:
{
type
:
DataTypes
.
INTEGER
(
10
),
allowNull
:
true
},
d_10_15
:
{
type
:
DataTypes
.
INTEGER
(
10
),
allowNull
:
true
},
d_15_20
:
{
type
:
DataTypes
.
INTEGER
(
10
),
allowNull
:
true
},
d_20_25
:
{
type
:
DataTypes
.
INTEGER
(
10
),
allowNull
:
true
},
d_25_31
:
{
type
:
DataTypes
.
INTEGER
(
10
),
allowNull
:
true
},
km_0_40
:
{
type
:
DataTypes
.
INTEGER
(
10
),
allowNull
:
true
},
km_40_70
:
{
type
:
DataTypes
.
INTEGER
(
10
),
allowNull
:
true
},
km_70_100
:
{
type
:
DataTypes
.
INTEGER
(
10
),
allowNull
:
true
},
km_100_
:
{
type
:
DataTypes
.
INTEGER
(
10
),
allowNull
:
true
},
w_0_10
:
{
type
:
DataTypes
.
INTEGER
(
10
),
allowNull
:
true
},
w_10_20
:
{
type
:
DataTypes
.
INTEGER
(
10
),
allowNull
:
true
},
w_20_30
:
{
type
:
DataTypes
.
INTEGER
(
10
),
allowNull
:
true
},
},
total_users
:
{
w_30_50
:
{
type
:
DataTypes
.
INTEGER
(
10
),
type
:
DataTypes
.
INTEGER
(
10
),
allowNull
:
true
allowNull
:
true
},
},
range_users
:
{
w_50_
:
{
type
:
DataTypes
.
INTEGER
(
10
),
type
:
DataTypes
.
INTEGER
(
10
),
allowNull
:
true
allowNull
:
true
},
},
...
@@ -39,7 +92,7 @@ module.exports = app => {
...
@@ -39,7 +92,7 @@ module.exports = app => {
allowNull
:
true
allowNull
:
true
}
}
},
{
},
{
tableName
:
't_user_city_
average_drive_month
'
tableName
:
't_user_city_
drive_info
'
});
});
Model
.
associate
=
function
()
{
Model
.
associate
=
function
()
{
...
...
app/schedule/update_cache.js
View file @
4a826db
...
@@ -30,64 +30,84 @@ class UpdateCache extends Subscription {
...
@@ -30,64 +30,84 @@ class UpdateCache extends Subscription {
}
}
_group
(
cities
,
f
)
{
_group
(
cities
,
f
)
{
const
country
=
{
const
data
=
{
total
:
0
,
date
:
'20000101'
,
date
:
''
,
};
renew
:
0
,
function
__push
(
target
,
obj
){
province
:{}
target
=
target
||
{}
if
(
obj
){
const
{
r
,
u
,
a
,
i
,
j
,
m
,
o
}
=
obj
;
target
[
'r'
]
+=
+
r
;
//续费 renew
target
[
'u'
]
+=
+
u
;
//用户总数 user
target
[
'a'
]
+=
+
a
;
// 活跃用户数 active
target
[
'i'
]
+=
+
i
;
// 新增用户数 increase
target
[
'j'
]
+=
+
j
;
// 出行 journey
target
[
'm'
]
+=
+
m
;
// 里程 miles
target
[
'o'
]
+=
+
o
;
// online 在线时间
}
else
{
target
[
'r'
]
=
0
;
//续费 renew
target
[
'u'
]
=
0
;
//用户总数 user
target
[
'a'
]
=
0
;
// 活跃用户数 active
target
[
'i'
]
=
0
;
// 新增用户数 increase
target
[
'j'
]
=
0
;
// 出行 journey
target
[
'm'
]
=
0.00
;
// 里程 miles
target
[
'o'
]
=
0
;
// online 在线时间
}
return
target
;
};
};
cities
.
forEach
(
function
(
city
)
{
cities
.
forEach
(
function
(
city
)
{
const
prov_code
=
f
(
city
);
const
prov_code
=
f
(
city
);
let
{
city_code
,
total
,
city_name
,
prov_name
,
renew
}
=
city
let
{
city_code
,
city_name
,
prov_name
,
total_user
:
u
,
renew
:
r
,
active
:
a
,
increase
:
i
,
journey
:
j
,
miles
:
m
,
online_time
:
o
,
day
}
=
city
renew
=
+
renew
;
day
=
day
.
replace
(
/-/g
,
''
);
total
=
+
total
;
data
.
date
=
Math
.
max
(
data
.
date
,
day
)
country
.
total
+=
total
;
if
(
!
data
[
day
]){
country
.
renew
+=
renew
;
data
[
day
]
=
{
country
[
'province'
][
prov_code
]
=
country
[
'province'
][
prov_code
]
||
{}
p
:{}
//省 province
if
(
!
country
[
'province'
][
prov_code
][
'name'
]){
}
country
[
'province'
][
prov_code
][
'name'
]
=
prov_name
;
data
[
day
]
=
__push
(
data
[
day
])
country
[
'province'
][
prov_code
][
'total'
]
=
0
;
}
country
[
'province'
][
prov_code
][
'renew'
]
=
0
;
data
[
day
]
=
__push
(
data
[
day
],{
r
,
u
,
a
,
i
,
j
,
m
,
o
})
data
[
day
][
'p'
][
prov_code
]
=
data
[
day
][
'p'
][
prov_code
]
||
{}
if
(
typeof
data
[
day
][
'p'
][
prov_code
][
'u'
]
===
'undefined'
){
data
[
day
][
'p'
][
prov_code
]
=
__push
(
data
[
day
][
'p'
][
prov_code
])
}
data
[
day
][
'p'
][
prov_code
]
=
__push
(
data
[
day
][
'p'
][
prov_code
],{
r
,
u
,
a
,
i
,
j
,
m
,
o
})
if
(
!
data
[
day
][
'p'
][
prov_code
][
'c'
]){
data
[
day
][
'p'
][
prov_code
][
'c'
]
=
{}
}
}
country
[
'province'
][
prov_code
][
'total'
]
+=
total
;
data
[
day
][
'p'
][
prov_code
][
'c'
][
city_code
]
=
{
u
,
r
,
a
,
i
,
j
,
m
,
o
};
country
[
'province'
][
prov_code
][
'renew'
]
+=
renew
;
// country['province'][prov_code]['city'] = country['province'][prov_code]['city'] || [];
// country['province'][prov_code]['city'].push({ city_code,total,city_name});
country
[
'province'
][
prov_code
][
'city'
]
=
country
[
'province'
][
prov_code
][
'city'
]
||
{};
country
[
'province'
][
prov_code
][
'city'
][
city_code
]
=
{
total
,
city_name
,
renew
};
});
});
return
country
return
data
}
}
// subscribe 是真正定时任务执行时被运行的函数
// subscribe 是真正定时任务执行时被运行的函数
async
subscribe
()
{
async
subscribe
()
{
this
.
logger
.
info
(
"===============执行日常任务-缓存每日用户总数 begin=================="
);
this
.
logger
.
info
(
"===============执行日常任务-缓存每日用户总数 begin=================="
);
const
yesterday
=
this
.
helper
.
date
(
-
1
)
const
_f
=
'YYYYMMDD'
const
today
=
this
.
helper
.
date
(
0
)
const
yesterday
=
this
.
helper
.
date
(
-
1
,
_f
)
const
today
=
this
.
helper
.
date
(
0
,
_f
)
const
day30before
=
this
.
helper
.
date
(
-
30
)
const
day30before
=
this
.
helper
.
date
(
-
30
)
// 查询昨天 所有城市 分别 对应的 用户总数 列表
// 查询昨天 所有城市 分别 对应的 用户总数 列表
const
cities
=
await
this
.
UserService
.
user_summary_city_by_day
({
beginDate
:
day30before
,
endDate
:
yesterday
});
const
cities
=
await
this
.
UserService
.
user_summary_city_by_day
({
beginDate
:
day30before
,
endDate
:
yesterday
});
// 近 30天新增用户明细
// 近 30天新增用户明细
// const increased30 = await this.UserService.user_increased_city_by_day({beginDate:day30before,endDate:yesterday});
// const increased30 = await this.UserService.user_increased_city_by_day({beginDate:day30before,endDate:yesterday});
console
.
log
(
cities
);
if
(
cities
.
length
)
{
if
(
cities
.
length
)
{
const
data
=
this
.
_group
(
cities
,
city
=>
city
.
prov_code
);
const
data
=
this
.
_group
(
cities
,
city
=>
city
.
prov_code
);
data
.
date
=
yesterday
;
const
value
=
JSON
.
stringify
(
data
);
const
value
=
JSON
.
stringify
(
data
);
await
this
.
CacheService
.
set
(
await
this
.
CacheService
.
set
(
this
.
helper
.
constant
.
USER_SUMMARY_
YESTER
DAY
,
this
.
helper
.
constant
.
USER_SUMMARY_
30_
DAY
,
value
,
value
,
2
*
24
*
60
*
60
//两天过期
2
*
24
*
60
*
60
//两天过期
);
);
this
.
logger
.
info
(
"user_summary_%s:%s"
,
yesterday
,
value
);
this
.
logger
.
info
(
"user_summary_%s:%s"
,
data
.
date
,
value
);
}
else
{
}
else
{
this
.
logger
.
warn
(
"warnning=============user_summary_
yester
day===========is empty!"
);
this
.
logger
.
warn
(
"warnning=============user_summary_
30_
day===========is empty!"
);
}
}
//缓存日期.方便业务使用
//缓存日期.方便业务使用
await
this
.
CacheService
.
set
(
await
this
.
CacheService
.
set
(
this
.
helper
.
constant
.
DATES
,
this
.
helper
.
constant
.
DATES
,
{
{
today
:
this
.
helper
.
date
(
0
)
,
today
,
yesterday
yesterday
},
},
2
*
24
*
60
*
60
//两天过期
2
*
24
*
60
*
60
//两天过期
...
...
app/service/screen/user.js
View file @
4a826db
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
* @Author: limin
* @Author: limin
* @Date: 2019-11-21 11:18:37
* @Date: 2019-11-21 11:18:37
* @Last Modified by: limin
* @Last Modified by: limin
* @Last Modified time: 2019-1
1-29 17:53:5
4
* @Last Modified time: 2019-1
2-02 16:39:0
4
*/
*/
const
Service
=
require
(
"egg"
).
Service
;
const
Service
=
require
(
"egg"
).
Service
;
...
@@ -21,10 +21,8 @@ class UserService extends Service {
...
@@ -21,10 +21,8 @@ class UserService extends Service {
const
{
const
{
TUserCityGender
,
TUserCityGender
,
TUserCityCarbrand
,
TUserCityCarbrand
,
TUserCityCarprice
,
TUserCityDaily
,
TUserCityDaily
,
TUserCityAverageMilesDay
,
TUserCityDriveInfo
,
TUserCityAverageDriveMonth
,
TUserCityRealtime
,
TUserCityRealtime
,
TProvince
,
TProvince
,
TCity
TCity
...
@@ -32,10 +30,8 @@ class UserService extends Service {
...
@@ -32,10 +30,8 @@ class UserService extends Service {
this
.
MUserRealTime
=
TUserCityRealtime
;
this
.
MUserRealTime
=
TUserCityRealtime
;
this
.
MUserGender
=
TUserCityGender
;
this
.
MUserGender
=
TUserCityGender
;
this
.
MUserCarBrand
=
TUserCityCarbrand
;
this
.
MUserCarBrand
=
TUserCityCarbrand
;
this
.
MUserCarPrice
=
TUserCityCarprice
;
this
.
MUserDaily
=
TUserCityDaily
;
this
.
MUserDaily
=
TUserCityDaily
;
this
.
MUserMilesDaily
=
TUserCityAverageMilesDay
;
this
.
MUserDriveInfo
=
TUserCityDriveInfo
;
this
.
MUserDriveDaysMonth
=
TUserCityAverageDriveMonth
;
this
.
MProvice
=
TProvince
;
this
.
MProvice
=
TProvince
;
this
.
MCity
=
TCity
;
this
.
MCity
=
TCity
;
}
}
...
@@ -52,6 +48,14 @@ class UserService extends Service {
...
@@ -52,6 +48,14 @@ class UserService extends Service {
foreignKey
:
"city_code"
,
foreignKey
:
"city_code"
,
targetKey
:
"city_code"
targetKey
:
"city_code"
});
});
this
.
MUserRealTime
.
belongsTo
(
this
.
MProvice
,
{
foreignKey
:
"prov_code"
,
targetKey
:
"prov_code"
});
this
.
MUserRealTime
.
belongsTo
(
this
.
MCity
,
{
foreignKey
:
"city_code"
,
targetKey
:
"city_code"
});
}
}
/**
/**
...
@@ -243,6 +247,16 @@ class UserService extends Service {
...
@@ -243,6 +247,16 @@ class UserService extends Service {
const
data
=
await
MUserCity
.
findAll
(
option
);
const
data
=
await
MUserCity
.
findAll
(
option
);
return
data
;
return
data
;
}
}
/**
/**
* @param field {String}
* @param field {String}
* @param value {String}
* @param value {String}
...
@@ -263,7 +277,7 @@ class UserService extends Service {
...
@@ -263,7 +277,7 @@ class UserService extends Service {
'increase'
,
'increase'
,
'journey'
,
'journey'
,
'miles'
,
'miles'
,
'online_time'
,
"online_time"
,
'day'
,
'day'
,
col
(
"t_city.city_name"
),
col
(
"t_city.city_name"
),
col
(
"t_province.prov_name"
)
col
(
"t_province.prov_name"
)
...
@@ -274,6 +288,35 @@ class UserService extends Service {
...
@@ -274,6 +288,35 @@ class UserService extends Service {
const
data
=
await
MUserCity
.
findAll
(
option
);
const
data
=
await
MUserCity
.
findAll
(
option
);
return
data
;
return
data
;
}
}
/**
* @param field {String}
* @param value {String}
* @return {Promise.<boolean>}
* @Description 获取实时数据(详细)
*/
async
user_realtime
({
pid
,
cid
})
{
const
{
app
,
helper
,
MUserRealTime
,
MCity
,
MProvice
}
=
this
;
const
{
col
}
=
app
.
Sequelize
;
var
option
=
helper
.
seqOption
({
pid
,
cid
});
Object
.
assign
(
option
,
{
attributes
:
[
"city_code"
,
'prov_code'
,
"online_total"
,
'renew'
,
'active'
,
'increase'
,
"online_time"
,
col
(
"t_city.city_name"
),
col
(
"t_province.prov_name"
)
],
include
:
[{
model
:
MCity
,
attributes
:
[]
},{
model
:
MProvice
,
attributes
:
[]}],
raw
:
true
});
const
data
=
await
MUserRealTime
.
findAll
(
option
);
return
data
;
}
}
}
module
.
exports
=
UserService
;
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