Commit 534a0c9f by liimin

数据表调整

1 parent e9ab53f2
......@@ -2,10 +2,11 @@
* @Author: limin
* @Date: 2019-11-21 11:20:15
* @Last Modified by: limin
* @Last Modified time: 2019-11-28 15:16:50
* @Last Modified time: 2019-11-29 09:43:28
*/
module.exports = {
PREFIX: '_glsx_data_screen_',
USER_SUMMARY_YESTERDAY:'user_summary_yesterday'
USER_SUMMARY_YESTERDAY:'user_summary_yesterday',
DATES:'dates'
};
\ No newline at end of file
......@@ -2,7 +2,7 @@
* @Author: limin
* @Date: 2019-11-21 11:20:01
* @Last Modified by: limin
* @Last Modified time: 2019-11-28 18:11:13
* @Last Modified time: 2019-11-29 14:12:17
*/
"use strict";
......@@ -25,19 +25,57 @@ class UserController extends Controller {
this.ServerResponse = ctx.response.ServerResponse;
}
/**
* @Router GET /screen/user/total
* @Description 数据大屏-用户总数统计.----参数pid 有 则返回对应的省份数据.没有则是全国数据的统计
* @Request query integer pid 省份id
* 内部方法 从内存获取 昨天的统计数据
* 比较数据时间 如果不是昨天的数据 则启动定时任务 更新一遍数据 再次获取数据并返回
*/
async _fetch_summary_yesterday(){
const { DATES, USER_SUMMARY_YESTERDAY } = this.helper.constant;
var yesterday_total = await this.CacheService.get(USER_SUMMARY_YESTERDAY);
const { date } = yesterday_total;
const { yesterday } = await this.CacheService.get(DATES);
if(date !== yesterday){ //如果 内存中的数据的日期不是昨天的 则手动启动定时器 更新缓存数据
await this.app.runSchedule('update_cache');
yesterday_total = await this.CacheService.get(USER_SUMMARY_YESTERDAY);
}
return yesterday_total
}
/**
* 内部方法 从内存获取 昨天的统计数据
*/
async total({ query: { pid,cid} }) {
var yesterday_total = await this.CacheService.get(this.helper.constant.USER_SUMMARY_YESTERDAY);
var { total, province } = yesterday_total
async _fetch_total({ pid, cid , field } ){
const _summary = await this._fetch_summary_yesterday();
var { province } =_summary;
var total= 0;
function _set(target){
var total;
if(typeof field ==='string'){
total = target[field];
}else{
total = {}
for (const f of field) {
total[f] = target[f]
}
}
return total;
}
if (pid) {
var obj = cid ? province[pid]["city"][cid] : province[pid];
total = obj ? obj.total : 0;
obj && (total =_set(obj));
}else{
total = _set(_summary)
}
const today_total = await this.UserService.last_n_day_user_increased({n:0,pid,cid});
total += ~~today_total;
return total;
}
/**
* @Router GET /screen/user/total
* @Description 数据大屏-用户总数统计.----参数pid 有 则返回对应的省份数据.没有则是全国数据的统计
* @Request query integer pid 省份id
*/
async total({ query: { pid,cid } }) {
var total = await this._fetch_total({ pid,cid,field:'total' })
const today_total = await this.UserService.last_n_day_user_increased({ n:0, pid, cid });
total += ~~today_total;
// console.log(this.app.cache.today);
// `user_summary_${day}`
// const data = await this.CacheService.get("test", () =>
......@@ -53,22 +91,25 @@ class UserController extends Controller {
* @Request query integer pid 省份id
*/
async statistics({ query: { pid, n = -7,cid } }) {
await this.app.runSchedule('update_cache');
//近7天新增用户数
const increased7 = await this.UserService.last_n_day_user_increased({n,pid,cid});
//近七天 活跃用户数
const nLive7 = await this.UserService.last_n_day_user_lively({n,pid,cid});
// 近七天 用户活跃度 (近N天 活跃用户数 / 近N天新增用户数)
const live7 = ((~~nLive7 / ~~increased7) * 100).toFixed(2)+ "%";
//近30天新增用户数
const increased30 = await this.UserService.last_n_day_user_increased({n:-30,pid,cid});
//近30天 活跃用户数
const nLive30 = await this.UserService.last_n_day_user_lively({n:-30,pid,cid});
// 近30天 用户活跃度 (近N天 活跃用户数 / 近N天新增用户数)
const live30 = ((~~nLive30 / ~~increased30) * 100).toFixed(2)+ "%";
const data = await this.UserService.last_n_day_user_increased_detail({ n, pid, cid });
// //近7天新增用户数
// const increased7 = await this.UserService.last_n_day_user_increased({ n, pid, cid });
// //近七天 活跃用户数
// const nLive7 = await this.UserService.last_n_day_user_lively({ n, pid, cid });
// // 近七天 用户活跃度 (近N天 活跃用户数 / 近N天新增用户数)
// const live7 = this.helper.percent(nLive7,increased7);
// //近30天新增用户数
// const increased30 = await this.UserService.last_n_day_user_increased({ n:-30, pid, cid });
// //近30天 活跃用户数
// const nLive30 = await this.UserService.last_n_day_user_lively({ n:-30, pid, cid });
// // 近30天 用户活跃度 (近N天 活跃用户数 / 近N天新增用户数)
// const live30 = this.helper.percent(nLive30,increased30);
// const { total ,renew } = await this._fetch_total({ pid,cid,field:['total','renew'] });
// // 昨天的付费转化率 (昨天的付费总人数 / 昨天用户总数)
// const renew_yesterday = this.helper.percent(renew,total);
// const data = { increased7, live7,increased30,live30,renew_yesterday };
const data = { increased7, live7,increased30,live30 };
this.ctx.body = this.ServerResponse.Success(data);
}
......
......@@ -2,7 +2,7 @@
* @Author: limin
* @Date: 2019-11-21 11:19:43
* @Last Modified by: limin
* @Last Modified time: 2019-11-28 16:22:53
* @Last Modified time: 2019-11-29 11:38:08
*/
const moment = require("moment");
......@@ -27,6 +27,26 @@ exports.jsonParser =str=>{
return res
}
/**
* json对象转字符串
*/
exports.jsonStringify =obj=>{
var res;
if(typeof obj === 'string'){
return obj
}
try {
res = JSON.stringify(obj)
} catch (error) {
res = obj
}
return res
}
/**
*
*/
exports.percent=(num,total,fixed =2 )=>((~~num / ~~total) * 100).toFixed(fixed)+ "%";
/**
* 简单封装 sequelize 查询参数
*/
exports.seqOption = function({ pid,cid, n, limit, order, day,beginDate,endDate }) {
......
/* indent size: 2 */
module.exports = app => {
const DataTypes = app.Sequelize;
const Model = app.model.define('t_user_city_active_daily', {
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
},
day: {
type: DataTypes.DATE,
allowNull: false
},
total: {
type: DataTypes.INTEGER(10),
allowNull: false,
defaultValue: '0'
},
create_time: {
type: DataTypes.DATE,
allowNull: true
},
update_time: {
type: DataTypes.DATE,
allowNull: true
}
}, {
tableName: 't_user_city_active_daily'
});
Model.associate = function() {
}
return Model;
};
......@@ -18,19 +18,10 @@ module.exports = app => {
type: DataTypes.STRING(32),
allowNull: false
},
brand_code: {
type: DataTypes.STRING(32),
allowNull: false
},
brand_name: {
type: DataTypes.STRING(32),
allowNull: false
},
total_cars: {
type: DataTypes.INTEGER(10),
allowNull: true,
defaultValue: '0'
},
brand_cars: {
type: DataTypes.INTEGER(10),
allowNull: true
......
......@@ -22,11 +22,6 @@ module.exports = app => {
type: DataTypes.STRING(32),
allowNull: false
},
total_cars: {
type: DataTypes.INTEGER(10),
allowNull: true,
defaultValue: '0'
},
range_cars: {
type: DataTypes.INTEGER(10),
allowNull: true
......
......@@ -3,13 +3,17 @@
module.exports = app => {
const DataTypes = app.Sequelize;
const Model = app.model.define('t_user_city_journey_daily', {
const Model = app.model.define('t_user_city_daily', {
id: {
type: DataTypes.INTEGER(10),
allowNull: false,
primaryKey: true,
autoIncrement: true
},
day: {
type: DataTypes.DATE,
allowNull: false
},
prov_code: {
type: DataTypes.STRING(32),
allowNull: false
......@@ -18,17 +22,40 @@ module.exports = app => {
type: DataTypes.STRING(32),
allowNull: false
},
day: {
type: DataTypes.DATE,
allowNull: false
total_user: {
type: DataTypes.INTEGER(10),
allowNull: true,
defaultValue: '0'
},
renew: {
type: DataTypes.INTEGER(10),
allowNull: true,
defaultValue: '0'
},
active: {
type: DataTypes.INTEGER(10),
allowNull: true,
defaultValue: '0'
},
increase: {
type: DataTypes.INTEGER(10),
allowNull: true,
defaultValue: '0'
},
journey: {
type: DataTypes.INTEGER(10),
allowNull: true
allowNull: true,
defaultValue: '0'
},
miles: {
type: "DOUBLE(12,2)",
allowNull: true
allowNull: true,
defaultValue: '0.00'
},
online_time: {
type: DataTypes.BIGINT,
allowNull: true,
defaultValue: '0'
},
create_time: {
type: DataTypes.DATE,
......@@ -39,7 +66,7 @@ module.exports = app => {
allowNull: true
}
}, {
tableName: 't_user_city_journey_daily'
tableName: 't_user_city_daily'
});
Model.associate = function() {
......
/* indent size: 2 */
module.exports = app => {
const DataTypes = app.Sequelize;
const Model = app.model.define('t_user_city_increased_daily', {
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
},
day: {
type: DataTypes.DATE,
allowNull: false
},
total: {
type: DataTypes.INTEGER(10),
allowNull: false,
defaultValue: '0'
},
create_time: {
type: DataTypes.DATE,
allowNull: true
},
update_time: {
type: DataTypes.DATE,
allowNull: true
}
}, {
tableName: 't_user_city_increased_daily'
});
Model.associate = function() {
}
return Model;
};
......@@ -3,7 +3,7 @@
module.exports = app => {
const DataTypes = app.Sequelize;
const Model = app.model.define('t_user_city', {
const Model = app.model.define('t_user_city_realtime', {
id: {
type: DataTypes.INTEGER(10),
allowNull: false,
......@@ -14,18 +14,34 @@ module.exports = app => {
type: DataTypes.STRING(32),
allowNull: false
},
day: {
type: DataTypes.DATE,
allowNull: false
},
city_code: {
type: DataTypes.STRING(32),
allowNull: false,
unique: true
},
total: {
online_total: {
type: DataTypes.INTEGER(10),
allowNull: false,
allowNull: true,
defaultValue: '0'
},
online_time: {
type: DataTypes.BIGINT,
allowNull: true,
defaultValue: '0'
},
increase: {
type: DataTypes.INTEGER(10),
allowNull: true,
defaultValue: '0'
},
active: {
type: DataTypes.INTEGER(10),
allowNull: true,
defaultValue: '0'
},
renew: {
type: DataTypes.INTEGER(10),
allowNull: true,
defaultValue: '0'
},
create_time: {
......@@ -37,7 +53,7 @@ module.exports = app => {
allowNull: true
}
}, {
tableName: 't_user_city'
tableName: 't_user_city_realtime'
});
Model.associate = function() {
......
/* indent size: 2 */
module.exports = app => {
const DataTypes = app.Sequelize;
const Model = app.model.define('t_user_city_renew_daily', {
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
},
day: {
type: DataTypes.DATE,
allowNull: false
},
total: {
type: DataTypes.INTEGER(10),
allowNull: false,
defaultValue: '0'
},
create_time: {
type: DataTypes.DATE,
allowNull: true
},
update_time: {
type: DataTypes.DATE,
allowNull: true
}
}, {
tableName: 't_user_city_renew_daily'
});
Model.associate = function() {
}
return Model;
};
/* indent size: 2 */
module.exports = app => {
const DataTypes = app.Sequelize;
const Model = app.model.define('t_user_province', {
id: {
type: DataTypes.INTEGER(10),
allowNull: false,
primaryKey: true,
autoIncrement: true
},
prov_code: {
type: DataTypes.STRING(32),
allowNull: false,
unique: true
},
total: {
type: DataTypes.INTEGER(10),
allowNull: false,
defaultValue: '0'
},
online_total: {
type: DataTypes.INTEGER(10),
allowNull: false,
defaultValue: '0'
},
create_time: {
type: DataTypes.DATE,
allowNull: true
},
update_time: {
type: DataTypes.DATE,
allowNull: true
}
}, {
tableName: 't_user_province'
});
Model.associate = function() {
}
return Model;
};
/* indent size: 2 */
module.exports = app => {
const DataTypes = app.Sequelize;
const Model = app.model.define('t_user_province_active_daily', {
id: {
type: DataTypes.INTEGER(10),
allowNull: false,
primaryKey: true,
autoIncrement: true
},
prov_code: {
type: DataTypes.STRING(32),
allowNull: false
},
day: {
type: DataTypes.DATE,
allowNull: false
},
total: {
type: DataTypes.INTEGER(10),
allowNull: false,
defaultValue: '0'
},
create_time: {
type: DataTypes.DATE,
allowNull: true
},
update_time: {
type: DataTypes.DATE,
allowNull: true
}
}, {
tableName: 't_user_province_active_daily'
});
Model.associate = function() {
}
return Model;
};
/* indent size: 2 */
module.exports = app => {
const DataTypes = app.Sequelize;
const Model = app.model.define('t_user_province_average_drive_month', {
id: {
type: DataTypes.INTEGER(10),
allowNull: false,
primaryKey: true,
autoIncrement: true
},
prov_code: {
type: DataTypes.STRING(32),
allowNull: false
},
days_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_province_average_drive_month'
});
Model.associate = function() {
}
return Model;
};
/* indent size: 2 */
module.exports = app => {
const DataTypes = app.Sequelize;
const Model = app.model.define('t_user_province_average_miles_day', {
id: {
type: DataTypes.INTEGER(10),
allowNull: false,
primaryKey: true,
autoIncrement: true
},
prov_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_province_average_miles_day'
});
Model.associate = function() {
}
return Model;
};
/* indent size: 2 */
module.exports = app => {
const DataTypes = app.Sequelize;
const Model = app.model.define('t_user_province_carbrand', {
id: {
type: DataTypes.INTEGER(10),
allowNull: false,
primaryKey: true,
autoIncrement: true
},
prov_code: {
type: DataTypes.STRING(32),
allowNull: false
},
brand_code: {
type: DataTypes.STRING(32),
allowNull: false
},
brand_name: {
type: DataTypes.STRING(32),
allowNull: false
},
total_cars: {
type: DataTypes.INTEGER(10),
allowNull: true,
defaultValue: '0'
},
brand_cars: {
type: DataTypes.INTEGER(10),
allowNull: true
},
create_time: {
type: DataTypes.DATE,
allowNull: true
},
update_time: {
type: DataTypes.DATE,
allowNull: true
}
}, {
tableName: 't_user_province_carbrand'
});
Model.associate = function() {
}
return Model;
};
/* indent size: 2 */
module.exports = app => {
const DataTypes = app.Sequelize;
const Model = app.model.define('t_user_province_carprice', {
id: {
type: DataTypes.INTEGER(10),
allowNull: false,
primaryKey: true,
autoIncrement: true
},
prov_code: {
type: DataTypes.STRING(32),
allowNull: false
},
price_range: {
type: DataTypes.STRING(32),
allowNull: false
},
total_cars: {
type: DataTypes.INTEGER(10),
allowNull: true,
defaultValue: '0'
},
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_province_carprice'
});
Model.associate = function() {
}
return Model;
};
/* indent size: 2 */
module.exports = app => {
const DataTypes = app.Sequelize;
const Model = app.model.define('t_user_province_gender', {
id: {
type: DataTypes.INTEGER(10),
allowNull: false,
primaryKey: true,
autoIncrement: true
},
prov_code: {
type: DataTypes.STRING(32),
allowNull: false
},
gender_range: {
type: DataTypes.STRING(32),
allowNull: false
},
total: {
type: DataTypes.INTEGER(10),
allowNull: false,
defaultValue: '0'
},
male: {
type: DataTypes.INTEGER(11),
allowNull: false,
defaultValue: '0'
},
female: {
type: DataTypes.INTEGER(11),
allowNull: false,
defaultValue: '0'
},
create_time: {
type: DataTypes.DATE,
allowNull: true
},
update_time: {
type: DataTypes.DATE,
allowNull: true
}
}, {
tableName: 't_user_province_gender'
});
Model.associate = function() {
}
return Model;
};
/* indent size: 2 */
module.exports = app => {
const DataTypes = app.Sequelize;
const Model = app.model.define('t_user_province_increased_daily', {
id: {
type: DataTypes.INTEGER(10),
allowNull: false,
primaryKey: true,
autoIncrement: true
},
prov_code: {
type: DataTypes.STRING(32),
allowNull: false
},
day: {
type: DataTypes.DATE,
allowNull: false
},
total: {
type: DataTypes.INTEGER(10),
allowNull: false,
defaultValue: '0'
},
create_time: {
type: DataTypes.DATE,
allowNull: true
},
update_time: {
type: DataTypes.DATE,
allowNull: true
}
}, {
tableName: 't_user_province_increased_daily'
});
Model.associate = function() {
}
return Model;
};
/* indent size: 2 */
module.exports = app => {
const DataTypes = app.Sequelize;
const Model = app.model.define('t_user_province_journey_daily', {
id: {
type: DataTypes.INTEGER(10),
allowNull: false,
primaryKey: true,
autoIncrement: true
},
prov_code: {
type: DataTypes.STRING(32),
allowNull: false
},
day: {
type: DataTypes.DATE,
allowNull: false
},
journey: {
type: DataTypes.INTEGER(10),
allowNull: true
},
miles: {
type: "DOUBLE(12,2)",
allowNull: true
},
create_time: {
type: DataTypes.DATE,
allowNull: true
},
update_time: {
type: DataTypes.DATE,
allowNull: true
}
}, {
tableName: 't_user_province_journey_daily'
});
Model.associate = function() {
}
return Model;
};
/* indent size: 2 */
module.exports = app => {
const DataTypes = app.Sequelize;
const Model = app.model.define('t_user_province_renew_daily', {
id: {
type: DataTypes.INTEGER(10),
allowNull: false,
primaryKey: true,
autoIncrement: true
},
prov_code: {
type: DataTypes.STRING(32),
allowNull: false
},
day: {
type: DataTypes.DATE,
allowNull: false
},
total: {
type: DataTypes.INTEGER(10),
allowNull: false,
defaultValue: '0'
},
create_time: {
type: DataTypes.DATE,
allowNull: true
},
update_time: {
type: DataTypes.DATE,
allowNull: true
}
}, {
tableName: 't_user_province_renew_daily'
});
Model.associate = function() {
}
return Model;
};
/* indent size: 2 */
module.exports = app => {
const DataTypes = app.Sequelize;
const Model = app.model.define('t_user_summary', {
id: {
type: DataTypes.INTEGER(10),
allowNull: false,
primaryKey: true,
autoIncrement: true
},
day: {
type: DataTypes.DATE,
allowNull: false,
unique: true
},
total: {
type: DataTypes.INTEGER(10),
allowNull: true
},
create_time: {
type: DataTypes.DATE,
allowNull: true
},
update_time: {
type: DataTypes.DATE,
allowNull: true
}
}, {
tableName: 't_user_summary'
});
Model.associate = function() {
}
return Model;
};
......@@ -22,7 +22,7 @@ class UpdateCache extends Subscription {
static get schedule() {
return {
// interval: '1m', // 定时任务 1 分钟间隔
cron: "0 33 9 * * *", // 定点任务 每天 凌晨 0点30 执行一次
cron: "0 30 6 * * *", // 定点任务 每天 凌晨 6点30 执行一次
type: "worker", // 随机 worker 执行
immediate: true //启动立即执行一次
// disable:true // 不启动
......@@ -47,6 +47,7 @@ class UpdateCache extends Subscription {
if(!country['province'][prov_code]['name']){
country['province'][prov_code]['name']=prov_name;
country['province'][prov_code]['total']= 0;
country['province'][prov_code]['renew']= 0;
}
country['province'][prov_code]['total'] += total;
country['province'][prov_code]['renew'] += renew;
......@@ -62,8 +63,13 @@ class UpdateCache extends Subscription {
async subscribe() {
this.logger.info( "===============执行日常任务-缓存每日用户总数 begin==================");
const yesterday = this.helper.date(-1)
const today = this.helper.date(0)
const day30before = this.helper.date(-30)
// 查询昨天 所有城市 分别 对应的 用户总数 列表
const cities = await this.UserService.user_summary_city_by_day({beginDate:yesterday});
const cities = await this.UserService.user_summary_city_by_day({beginDate:day30before,endDate:yesterday});
// 近 30天新增用户明细
// const increased30 = await this.UserService.user_increased_city_by_day({beginDate:day30before,endDate:yesterday});
console.log(cities);
if (cities.length) {
const data = this._group(cities, city=>city.prov_code);
data.date = yesterday;
......@@ -77,10 +83,15 @@ class UpdateCache extends Subscription {
}else{
this.logger.warn("warnning=============user_summary_yesterday===========is empty!");
}
this.app.cache = {
today: this.helper.date(0),
yesterday
};
//缓存日期.方便业务使用
await this.CacheService.set(
this.helper.constant.DATES,
{
today: this.helper.date(0),
yesterday
},
2 * 24 * 60 * 60 //两天过期
);
this.logger.info("===============执行日常任务-缓存每日用户总数 end==================");
}
}
......
......@@ -2,7 +2,7 @@
* @Author: limin
* @Date: 2019-11-21 14:32:51
* @Last Modified by: limin
* @Last Modified time: 2019-11-28 15:31:53
* @Last Modified time: 2019-11-29 09:47:18
*/
"use strict";
......@@ -19,7 +19,7 @@ class CacheService extends Service {
this.PREFIX = ctx.helper.constant.PREFIX;
}
async set(key, value, ex = 60 * 60) {
this.app.redis && (await this.app.redis.set(`${this.PREFIX}${key}`, value, "EX", ex));
this.app.redis && (await this.app.redis.set(`${this.PREFIX}${key}`, this.helper.jsonStringify(value), "EX", ex));
}
async get(key, fnGetFromDB, ex) {
......
......@@ -2,7 +2,7 @@
* @Author: limin
* @Date: 2019-11-21 11:18:37
* @Last Modified by: limin
* @Last Modified time: 2019-11-28 18:19:53
* @Last Modified time: 2019-11-29 17:53:54
*/
const Service = require("egg").Service;
......@@ -19,31 +19,23 @@ class UserService extends Service {
*/
_reg_models_alias() {
const {
TUserCityActiveDaily,
TUserCityIncreasedDaily,
TUserCityRenewDaily,
TUserCityGender,
TUserCityCarbrand,
TUserCityCarprice,
TUserCity,
TUserCityDaily,
TUserCityAverageMilesDay,
TUserCityAverageDriveMonth,
TUserCityJourneyDaily,
TUserSummary,
TUserCityRealtime,
TProvince,
TCity
} = this.app.model;
this.MCityActive = TUserCityActiveDaily;
this.MCityIncreased = TUserCityIncreasedDaily;
this.MCityRenew = TUserCityRenewDaily;
this.MCityGender = TUserCityGender;
this.MCityCarBrand = TUserCityCarbrand;
this.MCityCarPrice = TUserCityCarprice;
this.MUserCity = TUserCity;
this.MCityMilesDaily = TUserCityAverageMilesDay;
this.MCityDriveDaysMonth = TUserCityAverageDriveMonth;
this.MCityJourney = TUserCityJourneyDaily;
this.MUserSummary = TUserSummary;
this.MUserRealTime = TUserCityRealtime;
this.MUserGender = TUserCityGender;
this.MUserCarBrand = TUserCityCarbrand;
this.MUserCarPrice = TUserCityCarprice;
this.MUserDaily = TUserCityDaily;
this.MUserMilesDaily = TUserCityAverageMilesDay;
this.MUserDriveDaysMonth = TUserCityAverageDriveMonth;
this.MProvice = TProvince;
this.MCity = TCity;
}
......@@ -52,15 +44,11 @@ class UserService extends Service {
* 绑定表关系
*/
_associate() {
this.MUserCity.belongsTo(this.MProvice, {
this.MUserDaily.belongsTo(this.MProvice, {
foreignKey: "prov_code",
targetKey: "prov_code"
});
this.MUserCity.belongsTo(this.MCity, {
foreignKey: "city_code",
targetKey: "city_code"
});
this.MUserCity.belongsTo(this.MCityRenew, {
this.MUserDaily.belongsTo(this.MCity, {
foreignKey: "city_code",
targetKey: "city_code"
});
......@@ -92,11 +80,11 @@ class UserService extends Service {
* @param field {String}
* @param value {String}
* @return {Promise.<boolean>}
* @Description 近N天 新增用户数 明细
* @Description 近N天 用户活跃度
*/
async last_n_day_user_increased_detail(pid, n) {
const option = this.helper.seqOption({ n, pid });
const data = await this.MCityIncreased.findAll(option);
async last_n_day_user_lively({pid,cid,n}) {
const option = this.helper.seqOption({pid,cid,n});
const data = await this.MCityActive.sum("total", option);
return data;
}
......@@ -104,11 +92,11 @@ class UserService extends Service {
* @param field {String}
* @param value {String}
* @return {Promise.<boolean>}
* @Description 近N天 用户活跃度
* @Description 获取实时在线人数
*/
async last_n_day_user_lively({pid,cid,n}) {
const option = this.helper.seqOption({pid,cid,n});
const data = await this.MCityActive.sum("total", option);
async online_total_reletime({pid,cid}) {
const option = this.helper.seqOption({pid,cid,n:0});
const data = await this.MCityOnline.sum("total", option);
return data;
}
......@@ -163,7 +151,7 @@ class UserService extends Service {
limit,
order: [["brand_cars", "DESC"]]
});
const data = await this.MCityCarBrand.findAll(option);
const data = await this.MUserCarBrand.findAll(option);
return data;
}
......@@ -175,7 +163,7 @@ class UserService extends Service {
*/
async carprice(pid) {
const option = this.helper.seqOption({ pid });
const data = await this.MCityCarPrice.findAll(option);
const data = await this.MUserCarPrice.findAll(option);
return data;
}
......@@ -203,7 +191,7 @@ class UserService extends Service {
*/
async milesdaily(pid) {
const option = this.helper.seqOption({ pid });
const data = await this.MCityMilesDaily.findAll(option);
const data = await this.MUserMilesDaily.findAll(option);
return data;
}
/**
......@@ -214,7 +202,7 @@ class UserService extends Service {
*/
async drivedays(pid) {
const option = this.helper.seqOption({ pid });
const data = await this.MCityDriveDaysMonth.findAll(option);
const data = await this.MUserDriveDaysMonth.findAll(option);
return data;
}
......@@ -237,7 +225,7 @@ class UserService extends Service {
* @Description 获取某生某天用户总数 不传pid 统计所有
*/
async user_summary_provice_by_day(beginDate, endDate, pid) {
const { app, helper, MProvice, MUserCity } = this;
const { app, helper, MProvice, MUserDaily: MUserCity } = this;
const { fn, col } = app.Sequelize;
var option = helper.seqOption({ beginDate, endDate, pid });
Object.assign(option, {
......@@ -262,19 +250,25 @@ class UserService extends Service {
* @Description 获取某天城市用户总数列表
*/
async user_summary_city_by_day({beginDate, endDate, pid, cid}) {
const { app, helper, MUserCity, MCity, MProvice, MCityRenew } = this;
const { app, helper, MUserDaily: MUserCity, MCity, MProvice } = this;
const { col } = app.Sequelize;
var option = helper.seqOption({ beginDate, endDate, pid, cid });
Object.assign(option, {
attributes: [
"city_code",
'prov_code',
"total",
[col("t_user_city_renew_daily.total"),'renew'],
"total_user",
'renew',
'active',
'increase',
'journey',
'miles',
'online_time',
'day',
col("t_city.city_name"),
col("t_province.prov_name")
],
include: [{ model: MCity, attributes: [] },{ model: MProvice, attributes: []},{ model: MCityRenew, attributes: []}],
include: [{ model: MCity, attributes: [] },{ model: MProvice, attributes: []}],
raw: true
});
const data = await MUserCity.findAll(option);
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!