Commit 2d0a2ba7 by liimin

优化项目

1 parent 48cbf837
const path = require('path');
// module.exports = app => { // module.exports = app => {
// app.beforeStart(async function() { // app.beforeStart(async function() {
// // 应用会等待这个函数执行完成才启动 // // 应用会等待这个函数执行完成才启动
...@@ -8,7 +9,7 @@ ...@@ -8,7 +9,7 @@
constructor(app) { constructor(app) {
this.app = app; this.app = app;
} }
configWillLoad() { async configWillLoad() {
console.log(` console.log(`
◆ 项目:广联赛讯数据大屏后台 ◆ 项目:广联赛讯数据大屏后台
◆ 语言:Javascript ◆ 语言:Javascript
...@@ -21,6 +22,13 @@ ...@@ -21,6 +22,13 @@
◆ author: limin ◆ author: limin
`) `)
} }
async didReady() {
// 应用已经启动完毕
// 加载所有的校验规则
console.log('================加载所有的校验规则================')
const directory = path.join(this.app.config.baseDir, './app/validate');
this.app.loader.loadToApp(directory, 'validate');
}
} }
module.exports = AppBootHook; module.exports = AppBootHook;
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* @Author: limin * @Author: limin
* @Date: 2019-11-21 11:20:08 * @Date: 2019-11-21 11:20:08
* @Last Modified by: limin * @Last Modified by: limin
* @Last Modified time: 2019-11-21 17:12:52 * @Last Modified time: 2019-11-25 12:46:01
*/ */
const { SUCCESS, ERROR } = require("./server_response_code"); const { SUCCESS, ERROR } = require("./server_response_code");
...@@ -51,8 +51,8 @@ module.exports = class ServerResponse { ...@@ -51,8 +51,8 @@ module.exports = class ServerResponse {
// return new ServerResponse(SUCCESS, msg, data); // return new ServerResponse(SUCCESS, msg, data);
// } // }
static Error(data = null , respo = ERROR ) { static Error(respo = ERROR) {
const { code,message } = respo const { code=ERROR.code,message,data } = respo
return new ServerResponse(code,message, data); return new ServerResponse(code,message, data);
} }
// static createByError() { // static createByError() {
......
...@@ -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-11-21 17:12:45 * @Last Modified time: 2019-11-25 18:09:24
*/ */
"use strict"; "use strict";
...@@ -15,97 +15,96 @@ const Controller = require("egg").Controller; ...@@ -15,97 +15,96 @@ const Controller = require("egg").Controller;
class UserController extends Controller { class UserController extends Controller {
constructor(ctx) { constructor(ctx) {
super(ctx); super(ctx);
this.validate = ctx.app.validator.validate;
this.session = ctx.session; this.session = ctx.session;
this.request = ctx.request; this.request = ctx.request;
this.helper = ctx.helper;
this.redis = ctx.app.redis;
this.UserService = ctx.service.screen.user; this.UserService = ctx.service.screen.user;
this.CacheService = ctx.service.cache; //redis 缓存服务 this.CacheService = ctx.service.cache; //redis 缓存服务
this.ServerResponseCode = ctx.response.ServerResponseCode; this.ServerResponseCode = ctx.response.ServerResponseCode;
this.ServerResponse = ctx.response.ServerResponse; this.ServerResponse = ctx.response.ServerResponse;
} }
/** /**
* @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() { async total({ query: { pid } }) {
const nPid = this.request.query.pid; const statics = await this.UserService.total(pid);
const statics = await this.UserService.total(nPid);
const data = { statics }; const data = { statics };
this.ctx.body = this.ServerResponse.Success(data); this.ctx.body = this.ServerResponse.Success(data);
} }
/** /**
* @Router GET /screen/user/statistics * @Router GET /screen/user/statistics
* @Description 数据大屏-数据统计 1. 近七天新增用户数 2.近七天用户活跃度 3.近30天用户留存率 4.用户付费转化率 * @Description 数据大屏-数据统计 1. 近七天新增用户数 2.近七天用户活跃度 3.近30天用户留存率 4.用户付费转化率
* @Request query integer pid 省份id * @Request query integer pid 省份id
*/ */
async statistics() { async statistics({ query: { pid, n = 7 } }) {
const nPid = this.request.query.pid; console.log( this.app.cache);
const n = this.request.query.n || 7; //近 n 天 默认 7天 // console.log( await this.redis.set(`test_${this.helper.date(-1,'YYYY_MM_DD')}`,'aaa'));
console.log( await this.redis.get(`test_${this.helper.date(-1,'YYYY_MM_DD')}`));
// this.validate({ n: 'userName' },{ pid, n});
//近7天新增用户数 //近7天新增用户数
const increased = await this.UserService.last_n_day_user_increased(nPid,n); const increased = await this.UserService.last_n_day_user_increased(pid, n);
//近七天 活跃用户数 //近七天 活跃用户数
const nLive = await this.UserService.last_n_day_user_lively(nPid,n); const nLive = await this.UserService.last_n_day_user_lively(pid, n);
// 近七天 用户活跃度 (近N天 活跃用户数 / 近N天新增用户数) // 近七天 用户活跃度 (近N天 活跃用户数 / 近N天新增用户数)
const live = ((nLive / increased) * 100).toFixed(2) + '%'; const live = ((nLive / increased) * 100).toFixed(2) + "%";
const data = { increased,live }; const data = { increased, live };
this.ctx.body = this.ServerResponse.Success(data); this.ctx.body = this.ServerResponse.Success(data);
} }
/** /**
* @Router GET /screen/user/increase * @Router GET /screen/user/increase
* @Description 数据大屏-用户 N天 新增趋势 (默认 7天 不包括当天) * @Description 数据大屏-用户 N天 新增趋势 (默认 7天 不包括当天)
* @Request query integer pid 省份id * @Request query integer pid 省份id
* @Request query integer n 初始化 近n 天(默认7天) * @Request query integer n 初始化 近n 天(默认7天)
*/ */
async increase() { async increase({ query: { pid, n = 7 } }) {
const nPid = this.request.query.pid;
const n = this.request.query.n || 7; //近 n 天 默认 7天
//近7天新增用户数 明细 //近7天新增用户数 明细
const list = await this.UserService.last_n_day_user_increased_detail(nPid,n); const list = await this.UserService.last_n_day_user_increased_detail(
pid,
n
);
const data = { list }; const data = { list };
this.ctx.body = this.ServerResponse.Success(data); this.ctx.body = this.ServerResponse.Success(data);
} }
/** /**
* @Router GET /screen/user/lively * @Router GET /screen/user/lively
* @Description 数据大屏-用户N天 活跃趋势 (默认 7天 不包括当天) * @Description 数据大屏-用户N天 活跃趋势 (默认 7天 不包括当天)
* @Request query integer pid 省份id * @Request query integer pid 省份id
* @Request query integer n 初始化 近n天(默认7天) * @Request query integer n 初始化 近n天(默认7天)
*/ */
async lively() { async lively({ query: { pid, n = 7 } }) {
const nPid = this.request.query.pid;
const n = this.request.query.n || 7; //近 n 天 默认 7天
//近7天新增用户数 明细 //近7天新增用户数 明细
const list = await this.UserService.last_n_day_user_lively_detail(nPid,n); const list = await this.UserService.last_n_day_user_lively_detail(pid, n);
const data = { list }; const data = { list };
this.ctx.body = this.ServerResponse.Success(data); this.ctx.body = this.ServerResponse.Success(data);
} }
/** /**
* @Router GET /screen/user/renew * @Router GET /screen/user/renew
* @Description 数据大屏-用户 N天 付费转化趋势 (默认 7天 不包括当天) * @Description 数据大屏-用户 N天 付费转化趋势 (默认 7天 不包括当天)
* @Request query integer pid 省份id * @Request query integer pid 省份id
* @Request query integer n 初始化 近n 天(默认7天) * @Request query integer n 初始化 近n 天(默认7天)
*/ */
async renew() { async renew({ query: { pid, n = 7 } }) {
const nPid = this.request.query.pid;
const n = this.request.query.n || 7; //近 n 天 默认 7天
//近7天新增用户数 明细 //近7天新增用户数 明细
const list = await this.UserService.last_n_day_user_renew_detail(nPid,n); const list = await this.UserService.last_n_day_user_renew_detail(pid, n);
const data = { list }; const data = { list };
this.ctx.body = this.ServerResponse.Success(data); this.ctx.body = this.ServerResponse.Success(data);
} }
/** /**
* @Router GET /screen/user/journey * @Router GET /screen/user/journey
* @Description 数据大屏-用户N天 出行趋势 (默认 7天 不包括当天) * @Description 数据大屏-用户N天 出行趋势 (默认 7天 不包括当天)
* @Request query integer pid 省份id * @Request query integer pid 省份id
* @Request query integer n 初始化 近n天(默认7天) * @Request query integer n 初始化 近n天(默认7天)
*/ */
async journey() { async journey({ query: { pid, n = 7 } }) {
const nPid = this.request.query.pid;
const n = this.request.query.n || 7; //近 n 天 默认 7天
//近7天新增用户数 明细 //近7天新增用户数 明细
const list = await this.UserService.last_n_day_user_journey_detail(nPid,n); const list = await this.UserService.last_n_day_user_journey_detail(pid, n);
const data = { list }; const data = { list };
this.ctx.body = this.ServerResponse.Success(data); this.ctx.body = this.ServerResponse.Success(data);
} }
...@@ -115,9 +114,8 @@ class UserController extends Controller { ...@@ -115,9 +114,8 @@ class UserController extends Controller {
* @Description 数据大屏-用户分析 * @Description 数据大屏-用户分析
* @Request query integer pid 省份id * @Request query integer pid 省份id
*/ */
async analysis() { async analysis({ query: { pid } }) {
const nPid = this.request.query.pid; const list = await this.UserService.analysis(pid);
const list = await this.UserService.analysis(nPid);
const data = { list }; const data = { list };
this.ctx.body = this.ServerResponse.Success(data); this.ctx.body = this.ServerResponse.Success(data);
} }
...@@ -128,10 +126,8 @@ class UserController extends Controller { ...@@ -128,10 +126,8 @@ class UserController extends Controller {
* @Request query integer pid 省份id * @Request query integer pid 省份id
* @Request query integer n 前n名(默认 5) * @Request query integer n 前n名(默认 5)
*/ */
async carbrand() { async carbrand({ query: { pid, n = 5 } }) {
const nPid = this.request.query.pid; const list = await this.UserService.carbrand(pid, n);
const n = this.request.query.n || 5; //前n名(默认 5)
const list = await this.UserService.carbrand(nPid,n);
const data = { list }; const data = { list };
this.ctx.body = this.ServerResponse.Success(data); this.ctx.body = this.ServerResponse.Success(data);
} }
...@@ -141,35 +137,31 @@ class UserController extends Controller { ...@@ -141,35 +137,31 @@ class UserController extends Controller {
* @Description 数据大屏-用户车辆品牌排行 * @Description 数据大屏-用户车辆品牌排行
* @Request query integer pid 省份id * @Request query integer pid 省份id
*/ */
async carprice() { async carprice({ query: { pid } }) {
const nPid = this.request.query.pid; const list = await this.UserService.carprice(pid);
const list = await this.UserService.carprice(nPid);
const data = { list }; const data = { list };
this.ctx.body = this.ServerResponse.Success(data); this.ctx.body = this.ServerResponse.Success(data);
} }
/** /**
* @Router GET /screen/user/city * @Router GET /screen/user/city
* @Description 数据大屏-用户城市排行 * @Description 数据大屏-用户城市排行
* @Request query integer pid 省份id * @Request query integer pid 省份id
* @Request query integer n 前n名(默认 8) * @Request query integer n 前n名(默认 8)
*/ */
async city() { async city({ query: { pid, n = 8 } }) {
const nPid = this.request.query.pid; const list = await this.UserService.city(pid, n);
const n = this.request.query.n || 8; //前n名 默认 8
const list = await this.UserService.city(nPid,n);
const data = { list }; const data = { list };
this.ctx.body = this.ServerResponse.Success(data); this.ctx.body = this.ServerResponse.Success(data);
} }
/** /**
* @Router GET /screen/user/milesdaily * @Router GET /screen/user/milesdaily
* @Description 数据大屏-用户日均里程分布 * @Description 数据大屏-用户日均里程分布
* @Request query integer pid 省份id * @Request query integer pid 省份id
*/ */
async milesdaily() { async milesdaily({ query: { pid } }) {
const nPid = this.request.query.pid; const list = await this.UserService.milesdaily(pid);
const list = await this.UserService.milesdaily(nPid);
const data = { list }; const data = { list };
this.ctx.body = this.ServerResponse.Success(data); this.ctx.body = this.ServerResponse.Success(data);
} }
...@@ -179,9 +171,8 @@ class UserController extends Controller { ...@@ -179,9 +171,8 @@ class UserController extends Controller {
* @Description 数据大屏-用户日均里程分布 * @Description 数据大屏-用户日均里程分布
* @Request query integer pid 省份id * @Request query integer pid 省份id
*/ */
async drivedays() { async drivedays({ query: { pid } }) {
const nPid = this.request.query.pid; const list = await this.UserService.drivedays(pid);
const list = await this.UserService.drivedays(nPid);
const data = { list }; const data = { list };
this.ctx.body = this.ServerResponse.Success(data); this.ctx.body = this.ServerResponse.Success(data);
} }
......
/* /*
* @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-11-21 11:19:43 * @Last Modified time: 2019-11-25 17:27:05
*/ */
const moment = require('moment'); const moment = require("moment");
// exports.relativeTime = time => moment(new Date(time * 1000)).fromNow(); // exports.relativeTime = time => moment(new Date(time * 1000)).fromNow();
exports.date = (n,f='YYYY-MM-DD') => moment().add(n,'days').format(f);
\ No newline at end of file \ No newline at end of file
exports.date = (n, f = "YYYY-MM-DD") =>
moment()
.add(n, "days")
.format(f);
/**
* 简单封装 sequelize 查询参数
*/
exports.seqOption = function({ pid, n, limit, order }) {
let where = {};
const { between } = this.ctx.app.Sequelize.Op
if (pid) {
where.prov_code = pid;
}
if (n || n === 0) {
where.day = {
[between]: [this.date(-n), this.date(0)]
};
}
const option = {
where
};
if (limit) {
option.limit = limit;
}
if (order) {
option.order = order;
}
return option;
};
module.exports = () => {
return async function errorHandler(ctx, next) {
try {
await next();
} catch (err) {
// 所有的异常都在 app 上触发一个 error 事件,框架会记录一条错误日志
ctx.app.emit("error", err, ctx);
const status = err.status || 500;
// 生产环境时 500 错误的详细错误内容不返回给客户端,因为可能包含敏感信息
const error =
status === 500 && ctx.app.config.env === "prod"
? "Internal Server Error"
: err.message;
// 从 error 对象上读出各个属性,设置到响应中
ctx.body = JSON.stringify(
ctx.response.ServerResponse.Error({ msg: error })
);
if (status === 422) {
ctx.body.detail = err.errors;
}
ctx.status = status;
}
};
};
...@@ -3,19 +3,26 @@ ...@@ -3,19 +3,26 @@
module.exports = app => { module.exports = app => {
const DataTypes = app.Sequelize; const DataTypes = app.Sequelize;
const Model = app.model.define('t_user_summary', { const Model = app.model.define('t_user_city_active_daily', {
id: { id: {
type: DataTypes.INTEGER(10), type: DataTypes.INTEGER(10),
allowNull: false, allowNull: false,
primaryKey: true, primaryKey: true,
autoIncrement: true autoIncrement: true
}, },
total: { prov_code: {
type: DataTypes.INTEGER(10), type: DataTypes.STRING(32),
allowNull: false, allowNull: false
defaultValue: '0'
}, },
online_total: { city_code: {
type: DataTypes.STRING(32),
allowNull: false
},
day: {
type: DataTypes.DATE,
allowNull: false
},
total: {
type: DataTypes.INTEGER(10), type: DataTypes.INTEGER(10),
allowNull: false, allowNull: false,
defaultValue: '0' defaultValue: '0'
...@@ -27,17 +34,9 @@ module.exports = app => { ...@@ -27,17 +34,9 @@ module.exports = app => {
update_time: { update_time: {
type: DataTypes.DATE, type: DataTypes.DATE,
allowNull: true allowNull: true
},
created_at: {
type: DataTypes.DATE,
allowNull: false
},
updated_at: {
type: DataTypes.DATE,
allowNull: false
} }
}, { }, {
tableName: 't_user_summary' tableName: 't_user_city_active_daily'
}); });
Model.associate = function() { Model.associate = function() {
......
/* indent size: 2 */
module.exports = app => {
const DataTypes = app.Sequelize;
const Model = app.model.define('t_user_city_average_drive_month', {
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
},
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_city_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_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;
};
/* indent size: 2 */
module.exports = app => {
const DataTypes = app.Sequelize;
const Model = app.model.define('t_user_city_carbrand', {
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
},
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_city_carbrand'
});
Model.associate = function() {
}
return Model;
};
/* 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
},
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_city_carprice'
});
Model.associate = function() {
}
return Model;
};
/* indent size: 2 */
module.exports = app => {
const DataTypes = app.Sequelize;
const Model = app.model.define('t_user_city_gender', {
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
},
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_city_gender'
});
Model.associate = function() {
}
return Model;
};
/* 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;
};
/* indent size: 2 */
module.exports = app => {
const DataTypes = app.Sequelize;
const Model = app.model.define('t_user_city_journey_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
},
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_city_journey_daily'
});
Model.associate = function() {
}
return Model;
};
/* 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;
};
...@@ -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_active_daily', { const Model = app.model.define('t_user_province_active_daily', {
id: { id: {
type: DataTypes.INTEGER(10), type: DataTypes.INTEGER(10),
allowNull: false, allowNull: false,
...@@ -16,8 +16,7 @@ module.exports = app => { ...@@ -16,8 +16,7 @@ module.exports = app => {
}, },
day: { day: {
type: DataTypes.DATE, type: DataTypes.DATE,
allowNull: false, allowNull: false
unique: true
}, },
total: { total: {
type: DataTypes.INTEGER(10), type: DataTypes.INTEGER(10),
...@@ -33,7 +32,7 @@ module.exports = app => { ...@@ -33,7 +32,7 @@ module.exports = app => {
allowNull: true allowNull: true
} }
}, { }, {
tableName: 't_user_active_daily' tableName: 't_user_province_active_daily'
}); });
Model.associate = function() { Model.associate = function() {
......
...@@ -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_average_drive_month', { const Model = app.model.define('t_user_province_average_drive_month', {
id: { id: {
type: DataTypes.INTEGER(10), type: DataTypes.INTEGER(10),
allowNull: false, allowNull: false,
...@@ -16,8 +16,7 @@ module.exports = app => { ...@@ -16,8 +16,7 @@ module.exports = app => {
}, },
days_range: { days_range: {
type: DataTypes.STRING(32), type: DataTypes.STRING(32),
allowNull: false, allowNull: false
unique: true
}, },
total_users: { total_users: {
type: DataTypes.INTEGER(10), type: DataTypes.INTEGER(10),
...@@ -36,7 +35,7 @@ module.exports = app => { ...@@ -36,7 +35,7 @@ module.exports = app => {
allowNull: true allowNull: true
} }
}, { }, {
tableName: 't_user_average_drive_month' tableName: 't_user_province_average_drive_month'
}); });
Model.associate = function() { Model.associate = function() {
......
...@@ -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_average_miles_day', { const Model = app.model.define('t_user_province_average_miles_day', {
id: { id: {
type: DataTypes.INTEGER(10), type: DataTypes.INTEGER(10),
allowNull: false, allowNull: false,
...@@ -16,8 +16,7 @@ module.exports = app => { ...@@ -16,8 +16,7 @@ module.exports = app => {
}, },
miles_range: { miles_range: {
type: DataTypes.STRING(32), type: DataTypes.STRING(32),
allowNull: false, allowNull: false
unique: true
}, },
total_users: { total_users: {
type: DataTypes.INTEGER(10), type: DataTypes.INTEGER(10),
...@@ -36,7 +35,7 @@ module.exports = app => { ...@@ -36,7 +35,7 @@ module.exports = app => {
allowNull: true allowNull: true
} }
}, { }, {
tableName: 't_user_average_miles_day' tableName: 't_user_province_average_miles_day'
}); });
Model.associate = function() { Model.associate = function() {
......
...@@ -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_carbrand', { const Model = app.model.define('t_user_province_carbrand', {
id: { id: {
type: DataTypes.INTEGER(10), type: DataTypes.INTEGER(10),
allowNull: false, allowNull: false,
...@@ -16,8 +16,7 @@ module.exports = app => { ...@@ -16,8 +16,7 @@ module.exports = app => {
}, },
brand_code: { brand_code: {
type: DataTypes.STRING(32), type: DataTypes.STRING(32),
allowNull: false, allowNull: false
unique: true
}, },
brand_name: { brand_name: {
type: DataTypes.STRING(32), type: DataTypes.STRING(32),
...@@ -41,7 +40,7 @@ module.exports = app => { ...@@ -41,7 +40,7 @@ module.exports = app => {
allowNull: true allowNull: true
} }
}, { }, {
tableName: 't_user_carbrand' tableName: 't_user_province_carbrand'
}); });
Model.associate = function() { Model.associate = function() {
......
...@@ -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_carprice', { const Model = app.model.define('t_user_province_carprice', {
id: { id: {
type: DataTypes.INTEGER(10), type: DataTypes.INTEGER(10),
allowNull: false, allowNull: false,
...@@ -16,8 +16,7 @@ module.exports = app => { ...@@ -16,8 +16,7 @@ module.exports = app => {
}, },
price_range: { price_range: {
type: DataTypes.STRING(32), type: DataTypes.STRING(32),
allowNull: false, allowNull: false
unique: true
}, },
total_cars: { total_cars: {
type: DataTypes.INTEGER(10), type: DataTypes.INTEGER(10),
...@@ -37,7 +36,7 @@ module.exports = app => { ...@@ -37,7 +36,7 @@ module.exports = app => {
allowNull: true allowNull: true
} }
}, { }, {
tableName: 't_user_carprice' tableName: 't_user_province_carprice'
}); });
Model.associate = function() { Model.associate = function() {
......
...@@ -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_gender', { const Model = app.model.define('t_user_province_gender', {
id: { id: {
type: DataTypes.INTEGER(10), type: DataTypes.INTEGER(10),
allowNull: false, allowNull: false,
...@@ -16,8 +16,7 @@ module.exports = app => { ...@@ -16,8 +16,7 @@ module.exports = app => {
}, },
gender_range: { gender_range: {
type: DataTypes.STRING(32), type: DataTypes.STRING(32),
allowNull: false, allowNull: false
unique: true
}, },
total: { total: {
type: DataTypes.INTEGER(10), type: DataTypes.INTEGER(10),
...@@ -43,7 +42,7 @@ module.exports = app => { ...@@ -43,7 +42,7 @@ module.exports = app => {
allowNull: true allowNull: true
} }
}, { }, {
tableName: 't_user_gender' tableName: 't_user_province_gender'
}); });
Model.associate = function() { Model.associate = function() {
......
...@@ -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_increased_daily', { const Model = app.model.define('t_user_province_increased_daily', {
id: { id: {
type: DataTypes.INTEGER(10), type: DataTypes.INTEGER(10),
allowNull: false, allowNull: false,
...@@ -16,8 +16,7 @@ module.exports = app => { ...@@ -16,8 +16,7 @@ module.exports = app => {
}, },
day: { day: {
type: DataTypes.DATE, type: DataTypes.DATE,
allowNull: false, allowNull: false
unique: true
}, },
total: { total: {
type: DataTypes.INTEGER(10), type: DataTypes.INTEGER(10),
...@@ -33,7 +32,7 @@ module.exports = app => { ...@@ -33,7 +32,7 @@ module.exports = app => {
allowNull: true allowNull: true
} }
}, { }, {
tableName: 't_user_increased_daily' tableName: 't_user_province_increased_daily'
}); });
Model.associate = function() { Model.associate = function() {
......
...@@ -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_journey_daily', { const Model = app.model.define('t_user_province_journey_daily', {
id: { id: {
type: DataTypes.INTEGER(10), type: DataTypes.INTEGER(10),
allowNull: false, allowNull: false,
...@@ -16,8 +16,7 @@ module.exports = app => { ...@@ -16,8 +16,7 @@ module.exports = app => {
}, },
day: { day: {
type: DataTypes.DATE, type: DataTypes.DATE,
allowNull: false, allowNull: false
unique: true
}, },
journey: { journey: {
type: DataTypes.INTEGER(10), type: DataTypes.INTEGER(10),
...@@ -36,7 +35,7 @@ module.exports = app => { ...@@ -36,7 +35,7 @@ module.exports = app => {
allowNull: true allowNull: true
} }
}, { }, {
tableName: 't_user_journey_daily' tableName: 't_user_province_journey_daily'
}); });
Model.associate = function() { Model.associate = function() {
......
...@@ -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_renew_daily', { const Model = app.model.define('t_user_province_renew_daily', {
id: { id: {
type: DataTypes.INTEGER(10), type: DataTypes.INTEGER(10),
allowNull: false, allowNull: false,
...@@ -16,8 +16,7 @@ module.exports = app => { ...@@ -16,8 +16,7 @@ module.exports = app => {
}, },
day: { day: {
type: DataTypes.DATE, type: DataTypes.DATE,
allowNull: false, allowNull: false
unique: true
}, },
total: { total: {
type: DataTypes.INTEGER(10), type: DataTypes.INTEGER(10),
...@@ -33,7 +32,7 @@ module.exports = app => { ...@@ -33,7 +32,7 @@ module.exports = app => {
allowNull: true allowNull: true
} }
}, { }, {
tableName: 't_user_renew_daily' tableName: 't_user_province_renew_daily'
}); });
Model.associate = function() { Model.associate = function() {
......
/* indent size: 2 */
module.exports = app => {
const DataTypes = app.Sequelize;
const Model = app.model.define('usedrow', {
dbname: {
type: DataTypes.STRING(100),
allowNull: false,
defaultValue: '',
primaryKey: true
},
tname: {
type: DataTypes.STRING(100),
allowNull: true
},
cname: {
type: DataTypes.STRING(100),
allowNull: true
},
datatype: {
type: DataTypes.STRING(30),
allowNull: true
},
maxrows: {
type: DataTypes.INTEGER(11),
allowNull: true
},
usedpercent: {
type: DataTypes.DECIMAL,
allowNull: true
},
tablerows: {
type: DataTypes.INTEGER(11),
allowNull: true
},
extra: {
type: DataTypes.STRING(30),
allowNull: true
}
}, {
tableName: 'usedrow'
});
Model.associate = function() {
}
return Model;
};
const Subscription = require('egg').Subscription;
class UpdateCache extends Subscription {
// 通过 schedule 属性来设置定时任务的执行间隔等配置
static get schedule() {
return {
interval: '1s', // 1 分钟间隔
type: 'all', // 指定所有的 worker 都需要执行
immediate:true
};
}
// subscribe 是真正定时任务执行时被运行的函数
async subscribe() {
console.log('1111111111111');
}
}
module.exports = UpdateCache;
\ No newline at end of file \ No newline at end of file
...@@ -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-11-21 17:21:17 * @Last Modified time: 2019-11-25 17:28:20
*/ */
const Service = require("egg").Service; const Service = require("egg").Service;
...@@ -12,17 +12,17 @@ class UserService extends Service { ...@@ -12,17 +12,17 @@ class UserService extends Service {
super(ctx); super(ctx);
this.session = ctx.session; this.session = ctx.session;
this.helper = ctx.helper; this.helper = ctx.helper;
this.Op = ctx.app.Sequelize.Op this.Op = ctx.app.Sequelize.Op;
this.ModelActive = ctx.model.TUserActiveDaily; this.MCityActive = ctx.model.TUserCityActiveDaily;
this.ModelIncreased = ctx.model.TUserIncreasedDaily; this.MCityIncreased = ctx.model.TUserCityIncreasedDaily;
this.ModelRenew = ctx.model.TUserRenewDaily; this.MCityRenew = ctx.model.TUserCityRenewDaily;
this.ModelGender = ctx.model.TUserGender; this.MCityGender = ctx.model.TUserCityGender;
this.ModelCarBrand = ctx.model.TUserCarbrand; this.MCityCarBrand = ctx.model.TUserCityCarbrand;
this.ModelCarPrice = ctx.model.TUserCarprice; this.MCityCarPrice = ctx.model.TUserCityCarprice;
this.ModelCity = ctx.model.TUserCity; this.MCity = ctx.model.TUserCity;
this.ModelMilesDaily = ctx.model.TUserAverageMilesDay; this.MCityMilesDaily = ctx.model.TUserCityAverageMilesDay;
this.ModelDriveDaysMonth = ctx.model.TUserAverageDriveMonth; this.MCityDriveDaysMonth = ctx.model.TUserCityAverageDriveMonth;
this.ModelJourney = ctx.model.TUserJourneyDaily; this.MCityJourney = ctx.model.TUserCityJourneyDaily;
this.ResponseCode = ctx.response.ResponseCode; this.ResponseCode = ctx.response.ResponseCode;
this.ServerResponse = ctx.response.ServerResponse; this.ServerResponse = ctx.response.ServerResponse;
} }
...@@ -32,8 +32,8 @@ class UserService extends Service { ...@@ -32,8 +32,8 @@ class UserService extends Service {
* @return {Promise.<boolean>} * @return {Promise.<boolean>}
*/ */
async total(pid) { async total(pid) {
const where = pid ? { prov_code: pid } : {}; const option = this.helper.seqOption({ pid });
const data = await this.ModelActive.sum("total", { where }); const data = await this.MCityActive.sum("total", option);
return data; return data;
} }
/** /**
...@@ -42,16 +42,9 @@ class UserService extends Service { ...@@ -42,16 +42,9 @@ class UserService extends Service {
* @return {Promise.<boolean>} * @return {Promise.<boolean>}
* @Description 近N天 新增用户数 * @Description 近N天 新增用户数
*/ */
async last_n_day_user_increased(pid,n) { async last_n_day_user_increased(pid, n) {
let where = { const option = this.helper.seqOption({ n, pid });
'day': { const data = await this.MCityIncreased.sum("total", option);
[this.Op.between]:[this.helper.date(-n), this.helper.date(0)]
}
}
if(pid){
where.prov_code = pid;
}
const data = await this.ModelIncreased.sum("total", { where });
return data; return data;
} }
...@@ -61,16 +54,9 @@ class UserService extends Service { ...@@ -61,16 +54,9 @@ class UserService extends Service {
* @return {Promise.<boolean>} * @return {Promise.<boolean>}
* @Description 近N天 新增用户数 明细 * @Description 近N天 新增用户数 明细
*/ */
async last_n_day_user_increased_detail(pid,n) { async last_n_day_user_increased_detail(pid, n) {
let where = { const option = this.helper.seqOption({ n, pid });
'day': { const data = await this.MCityIncreased.findAll(option);
[this.Op.between]:[this.helper.date(-n), this.helper.date(0)]
}
}
if(pid){
where.prov_code = pid;
}
const data = await this.ModelIncreased.findAll({ where });
return data; return data;
} }
...@@ -80,58 +66,37 @@ class UserService extends Service { ...@@ -80,58 +66,37 @@ class UserService extends Service {
* @return {Promise.<boolean>} * @return {Promise.<boolean>}
* @Description 近N天 用户活跃度 * @Description 近N天 用户活跃度
*/ */
async last_n_day_user_lively(pid,n) { async last_n_day_user_lively(pid, n) {
let where = { const option = this.helper.seqOption({ n, pid });
'day': { const data = await this.MCityActive.sum("total", option);
[this.Op.between]:[this.helper.date(-n), this.helper.date(0)]
}
}
if(pid){
where.prov_code = pid;
}
const data = await this.ModelActive.sum("total", { where });
return data; return data;
} }
/** /**
* @param field {String} * @param field {String}
* @param value {String} * @param value {String}
* @return {Promise.<boolean>} * @return {Promise.<boolean>}
* @Description 近N天 活跃 明细 * @Description 近N天 活跃 明细
*/ */
async last_n_day_user_lively_detail(pid,n) { async last_n_day_user_lively_detail(pid, n) {
let where = { const option = this.helper.seqOption({ n, pid });
'day': { const data = await this.MCityActive.findAll(option);
[this.Op.between]:[this.helper.date(-n), this.helper.date(0)]
}
}
if(pid){
where.prov_code = pid;
}
const data = await this.ModelActive.findAll({ where });
return data; return data;
} }
/** /**
* @param field {String} * @param field {String}
* @param value {String} * @param value {String}
* @return {Promise.<boolean>} * @return {Promise.<boolean>}
* @Description 近N天 付费转换 明细 * @Description 近N天 付费转换 明细
*/ */
async last_n_day_user_renew_detail(pid,n) { async last_n_day_user_renew_detail(pid, n) {
let where = { const option = this.helper.seqOption({ n, pid });
'day': { const data = await this.MCityRenew.findAll(option);
[this.Op.between]:[this.helper.date(-n), this.helper.date(0)]
}
}
if(pid){
where.prov_code = pid;
}
const data = await this.ModelRenew.findAll({ where });
return data; return data;
} }
/** /**
* @param field {String} * @param field {String}
* @param value {String} * @param value {String}
* @return {Promise.<boolean>} * @return {Promise.<boolean>}
...@@ -146,18 +111,19 @@ class UserService extends Service { ...@@ -146,18 +111,19 @@ class UserService extends Service {
// return data; // return data;
} }
/** /**
* @param field {String} * @param field {String}
* @param value {String} * @param value {String}
* @return {Promise.<boolean>} * @return {Promise.<boolean>}
* @Description 用户车辆品牌分布 * @Description 用户车辆品牌分布
*/ */
async carbrand(pid,limit) { async carbrand(pid, limit) {
let where = {} const option = this.helper.seqOption({
if(pid){ pid,
where.prov_code = pid; limit,
} order: [["brand_cars", "DESC"]]
const data = await this.ModelCarBrand.findAll({ where,limit,order: [['brand_cars', 'DESC']]}); });
const data = await this.MCityCarBrand.findAll(option);
return data; return data;
} }
...@@ -168,26 +134,24 @@ class UserService extends Service { ...@@ -168,26 +134,24 @@ class UserService extends Service {
* @Description 用户车辆价格分布 * @Description 用户车辆价格分布
*/ */
async carprice(pid) { async carprice(pid) {
let where = {} const option = this.helper.seqOption({ pid });
if(pid){ const data = await this.MCityCarPrice.findAll(option);
where.prov_code = pid;
}
const data = await this.ModelCarPrice.findAll({ where });
return data; return data;
} }
/** /**
* @param field {String} * @param field {String}
* @param value {String} * @param value {String}
* @return {Promise.<boolean>} * @return {Promise.<boolean>}
* @Description 用户城市排行 * @Description 用户城市排行
*/ */
async city(pid,limit) { async city(pid, limit) {
let where = {} const option = this.helper.seqOption({
if(pid){ pid,
where.prov_code = pid; limit,
} order: [["brand_cars", "DESC"]]
const data = await this.ModelCity.findAll({ where,limit,order: [['total', 'DESC']]}); });
const data = await this.MCity.findAll(option);
return data; return data;
} }
...@@ -198,11 +162,8 @@ class UserService extends Service { ...@@ -198,11 +162,8 @@ class UserService extends Service {
* @Description 用户日均里程分布 * @Description 用户日均里程分布
*/ */
async milesdaily(pid) { async milesdaily(pid) {
let where = {} const option = this.helper.seqOption({ pid });
if(pid){ const data = await this.MCityMilesDaily.findAll(option);
where.prov_code = pid;
}
const data = await this.ModelMilesDaily.findAll({ where });
return data; return data;
} }
/** /**
...@@ -212,30 +173,20 @@ class UserService extends Service { ...@@ -212,30 +173,20 @@ class UserService extends Service {
* @Description 用户日均里程分布 * @Description 用户日均里程分布
*/ */
async drivedays(pid) { async drivedays(pid) {
let where = {} const option = this.helper.seqOption({ pid });
if(pid){ const data = await this.MCityDriveDaysMonth.findAll(option);
where.prov_code = pid;
}
const data = await this.ModelDriveDaysMonth.findAll({ where });
return data; return data;
} }
/** /**
* @param field {String} * @param field {String}
* @param value {String} * @param value {String}
* @return {Promise.<boolean>} * @return {Promise.<boolean>}
* @Description 近N天 用户出行明细 * @Description 近N天 用户出行明细
*/ */
async last_n_day_user_journey_detail(pid,n) { async last_n_day_user_journey_detail(pid, n) {
let where = { const option = this.helper.seqOption({ pid, n });
'day': { const data = await this.MCityJourney.findAll(option);
[this.Op.between]:[this.helper.date(-n), this.helper.date(0)]
}
}
if(pid){
where.prov_code = pid;
}
const data = await this.ModelJourney.findAll({ where });
return data; return data;
} }
} }
......
module.exports = app => {
let { validator } = app;
// 校验用户名是否正确
validator.addRule("userName", (rule, value) => {
if (/^\d+$/.test(value)) {
throw new Error('用户名应该是字符串')
} else if (value.length < 3 || value.length > 10) {
console.log("用户名的长度应该在3-10之间");
}
});
// 添加自定义参数校验规则
validator.addRule("123", (rule, value) => {
if (value !== "123") {
return "must be 123";
}
});
};
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* @Author: limin * @Author: limin
* @Date: 2019-11-16 09:26:53 * @Date: 2019-11-16 09:26:53
* @Last Modified by: limin * @Last Modified by: limin
* @Last Modified time: 2019-11-22 09:48:42 * @Last Modified time: 2019-11-25 12:46:32
*/ */
/* eslint valid-jsdoc: "off" */ /* eslint valid-jsdoc: "off" */
...@@ -23,17 +23,30 @@ module.exports = app => { ...@@ -23,17 +23,30 @@ module.exports = app => {
config.keys = app.name + "_1573615133248_6253"; config.keys = app.name + "_1573615133248_6253";
// add your middleware config here // add your middleware config here
config.middleware = []; // config.middleware = [ 'errorHandler'];
config.onerror = { config.onerror = {
//全局异常捕获 //全局异常捕获
all(err, ctx) { all(err, ctx) {
// 在此处定义针对所有响应类型的错误处理方法 // 在此处定义针对所有响应类型的错误处理方法
// 注意,定义了 config.all 之后,其他错误处理方法不会再生效 // 注意,定义了 config.all 之后,其他错误处理方法不会再生效
// 所有的异常都在 app 上触发一个 error 事件,框架会记录一条错误日志
ctx.app.emit("error", err, ctx);
const status = err.status || 500;
// 生产环境时 500 错误的详细错误内容不返回给客户端,因为可能包含敏感信息
const error =
status === 500 && ctx.app.config.env === "prod"
? "Internal Server Error"
: err.message;
// 从 error 对象上读出各个属性,设置到响应中
ctx.body = JSON.stringify( ctx.body = JSON.stringify(
ctx.response.ServerResponse.Error({ msg: err.message }) ctx.response.ServerResponse.Error({ message: error })
); );
ctx.status = 500; if (status === 422) {
ctx.body.detail = err.errors;
}
ctx.status = status;
} }
// html(err, ctx) { // html(err, ctx) {
// // html hander // // html hander
...@@ -51,84 +64,68 @@ module.exports = app => { ...@@ -51,84 +64,68 @@ module.exports = app => {
}; };
// add your user config here // add your user config here
const userConfig = { // const userConfig = {
jwt: { config.jwt = {
secret: "glsx-data-screen-server" //自定义 token 的加密条件字符串 secret: "glsx-data-screen-server" //自定义 token 的加密条件字符串
}, };
cors: { config.cors = {
origin: "*", origin: "*",
allowMethods: "GET,HEAD,PUT,POST,DELETE,PATCH" allowMethods: "GET,HEAD,PUT,POST,DELETE,PATCH"
}, };
security: { config.security = {
csrf: { csrf: {
enable: false, enable: false,
ignoreJSON: true ignoreJSON: true
},
domainWhiteList: ["http://localhost:8080"] //允许访问接口的白名单
},
redis: {
client: {
port: 6379, // Redis port
host: "127.0.0.1", // Redis host
password: "auth",
db: 0
}
}, },
sequelize: { domainWhiteList: ["http://localhost:8080"] //允许访问接口的白名单
timezone: "+08:00", // 保存为本地时区 };
define: { config.redis = {
underscored: true, // 注意需要加上这个, egg-sequelize只是简单的使用Object.assign对配置和默认配置做了merge, 如果不加这个 update_at会被转变成 updateAt故报错 client: {
freezeTableName: true, // 禁止修改表名,默认情况下,sequelize将自动将所有传递的模型名称(define的第一个参数)转换为复数 port: 6379, // Redis port
// 但是为了安全着想,复数的转换可能会发生变化,所以禁止该行为 host: "127.0.0.1", // Redis host
timestamps: false, // 不自动维护时间戳 [ created_at、updated_at ] password: "auth",
dialectOptions: { db: 0
dateStrings: true, }
typeCast(field, next) { };
// for reading from database config.validate = {
if (field.type === "DATETIME") { // convert: false,
return field.string(); // validateRoot: false,
} };
return next(); config.sequelize = {
timezone: "+08:00", // 保存为本地时区
define: {
underscored: true, // 注意需要加上这个, egg-sequelize只是简单的使用Object.assign对配置和默认配置做了merge, 如果不加这个 update_at会被转变成 updateAt故报错
freezeTableName: true, // 禁止修改表名,默认情况下,sequelize将自动将所有传递的模型名称(define的第一个参数)转换为复数
// 但是为了安全着想,复数的转换可能会发生变化,所以禁止该行为
timestamps: false, // 不自动维护时间戳 [ created_at、updated_at ]
dialectOptions: {
dateStrings: true,
typeCast(field, next) {
// for reading from database
if (field.type === "DATETIME") {
return field.string();
} }
return next();
} }
} }
},
swaggerdoc : {
dirScanner: './app/controller',
apiInfo: {
title: 'egg-swagger',
description: 'swagger-ui for egg',
version: '1.0.0',
},
schemes: ['http', 'https'],
consumes: ['application/json'],
produces: ['application/json'],
securityDefinitions: {
// apikey: {
// type: 'apiKey',
// name: 'clientkey',
// in: 'header',
// },
// oauth2: {
// type: 'oauth2',
// tokenUrl: 'http://petstore.swagger.io/oauth/dialog',
// flow: 'password',
// scopes: {
// 'write:access_token': 'write access_token',
// 'read:access_token': 'read access_token',
// },
// },
},
enableSecurity: false,
// enableValidate: true,
routerMap: true ,
enable: true,
} }
}; };
return { config.swaggerdoc = {
...config, dirScanner: "./app/controller",
...userConfig apiInfo: {
title: "egg-swagger",
description: "swagger-ui for egg",
version: "1.0.0"
},
schemes: ["http", "https"],
consumes: ["application/json"],
produces: ["application/json"],
securityDefinitions: {},
enableSecurity: false,
// enableValidate: true,
routerMap: true,
enable: true
}; };
return config;
}; };
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* @Author: limin * @Author: limin
* @Date: 2019-11-16 09:27:00 * @Date: 2019-11-16 09:27:00
* @Last Modified by: limin * @Last Modified by: limin
* @Last Modified time: 2019-11-22 09:48:48 * @Last Modified time: 2019-11-25 17:57:59
*/ */
"use strict"; "use strict";
...@@ -31,7 +31,7 @@ exports.cors = { ...@@ -31,7 +31,7 @@ exports.cors = {
}; };
exports.redis = { exports.redis = {
enable: false, enable: true,
package: "egg-redis" package: "egg-redis"
}; };
...@@ -39,3 +39,8 @@ exports.swaggerdoc = { ...@@ -39,3 +39,8 @@ exports.swaggerdoc = {
enable: true, enable: true,
package: 'egg-swagger-doc-feat', package: 'egg-swagger-doc-feat',
}; };
exports.validate = {
enable: true,
package: 'egg-validate',
};
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
"egg-redis": "^2.4.0", "egg-redis": "^2.4.0",
"egg-scripts": "^2.11.0", "egg-scripts": "^2.11.0",
"egg-sequelize": "^5.2.0", "egg-sequelize": "^5.2.0",
"egg-validate": "^2.0.2",
"moment": "^2.24.0", "moment": "^2.24.0",
"mysql2": "^2.0.0" "mysql2": "^2.0.0"
}, },
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!