Commit 387d00d5 by liimin

初始化数据库

1 parent 9aa6f649
......@@ -6,7 +6,7 @@
<!-- add docs here for user -->
### see [egg docs][egg] for more detail.
see [egg docs][egg] for more detail.
### Development
......@@ -36,7 +36,9 @@ $ npm stop
1.安装sequelize-auto和mysql
npm install -g sequelize-auto mysql
### npm install -g sequelize-auto mysql
npm install -g egg-sequelize-auto mysql2
2. 使用说明
常用参数:
......@@ -49,7 +51,7 @@ npm install -g sequelize-auto mysql
-e 数据库类型
-a json定义文件路径,可以追加一些自定义配置,如{"timestamps": false}
- create model: $ 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 test -h 192.168.0.39 -u root -p 3306 -x 123456 -t usedrow -e mysql
- 不指定-t 为所有表
-- shell
......
......@@ -23,31 +23,38 @@ module.exports = class ServerResponse {
return this.msg;
}
static createBySuccess() {
return new ServerResponse(SUCCESS);
static success({code = SUCCESS,msg='success',data=null}) {
return new ServerResponse(code, msg, data);
}
static createBySuccessMsg(msg) {
return new ServerResponse(SUCCESS, msg, null);
}
// static createBySuccess() {
// return new ServerResponse(SUCCESS);
// }
static createBySuccessData(data) {
return new ServerResponse(SUCCESS, null, data);
}
// static createBySuccessMsg(msg) {
// return new ServerResponse(SUCCESS, msg, null);
// }
static createBySuccessMsgAndData(msg, data) {
return new ServerResponse(SUCCESS, msg, data);
}
// static createBySuccessData(data) {
// return new ServerResponse(SUCCESS, null, data);
// }
static createByError() {
return new ServerResponse(ERROR, 'error', null);
// static createBySuccessMsgAndData(msg, data) {
// return new ServerResponse(SUCCESS, msg, data);
// }
static error({code=ERROR,msg='error', data=null}) {
return new ServerResponse(code, msg, data);
}
// static createByError() {
// return new ServerResponse(ERROR, 'error', null);
// }
static createByErrorMsg(errorMsg) {
return new ServerResponse(ERROR, errorMsg, null);
}
// static createByErrorMsg(errorMsg) {
// return new ServerResponse(ERROR, errorMsg, null);
// }
static createByErrorCodeMsg(errorCode, errorMsg) {
return new ServerResponse(errorCode, errorMsg, null);
}
// static createByErrorCodeMsg(errorCode, errorMsg) {
// return new ServerResponse(errorCode, errorMsg, null);
// }
};
\ No newline at end of file
......@@ -5,6 +5,8 @@ module.exports = app => class DemoController extends Controller {
this.session = ctx.session;
this.request = ctx.request;
this.DemoService = ctx.service.demo;
this.ServerResponseCode = ctx.response.ServerResponseCode;
this.ServerResponse = ctx.response.ServerResponse;
}
// hello
......
// const moment = require('moment');
// exports.relativeTime = time => moment(new Date(time * 1000)).fromNow();
\ No newline at end of file
const ServerResponse = require("../common/server_response");
const ServerResponseCode = require("../common/server_response_code");
module.exports = {
ServerResponse,
ServerResponseCode
};
/* indent size: 2 */
module.exports = app => {
const DataTypes = app.Sequelize;
const Model = app.model.define('t_user_active_daily', {
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: false,
defaultValue: '0'
},
create_time: {
type: DataTypes.DATE,
allowNull: true
},
update_time: {
type: DataTypes.DATE,
allowNull: true
}
}, {
tableName: 't_user_active_daily'
});
Model.associate = function() {
}
return Model;
};
/* indent size: 2 */
module.exports = app => {
const DataTypes = app.Sequelize;
const Model = app.model.define('t_user_average_drive_month', {
id: {
type: DataTypes.INTEGER(10),
allowNull: false,
primaryKey: true,
autoIncrement: true
},
days_range: {
type: DataTypes.STRING(32),
allowNull: false,
unique: true
},
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_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_average_miles_day', {
id: {
type: DataTypes.INTEGER(10),
allowNull: false,
primaryKey: true,
autoIncrement: true
},
miles_range: {
type: DataTypes.STRING(32),
allowNull: false,
unique: true
},
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_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_carbrand', {
id: {
type: DataTypes.INTEGER(10),
allowNull: false,
primaryKey: true,
autoIncrement: true
},
brand_code: {
type: DataTypes.STRING(32),
allowNull: false,
unique: true
},
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_carbrand'
});
Model.associate = function() {
}
return Model;
};
/* indent size: 2 */
module.exports = app => {
const DataTypes = app.Sequelize;
const Model = app.model.define('t_user_carprice', {
id: {
type: DataTypes.INTEGER(10),
allowNull: false,
primaryKey: true,
autoIncrement: true
},
price_range: {
type: DataTypes.STRING(32),
allowNull: false,
unique: true
},
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_carprice'
});
Model.associate = function() {
}
return Model;
};
/* indent size: 2 */
module.exports = app => {
const DataTypes = app.Sequelize;
const Model = app.model.define('t_user_city', {
id: {
type: DataTypes.INTEGER(10),
allowNull: false,
primaryKey: true,
autoIncrement: true
},
prov_code: {
type: DataTypes.STRING(32),
allowNull: false,
unique: true
},
prov_name: {
type: DataTypes.STRING(32),
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'
});
Model.associate = function() {
}
return Model;
};
/* indent size: 2 */
module.exports = app => {
const DataTypes = app.Sequelize;
const Model = app.model.define('t_user_gender', {
id: {
type: DataTypes.INTEGER(10),
allowNull: false,
primaryKey: true,
autoIncrement: true
},
gender_range: {
type: DataTypes.STRING(32),
allowNull: false,
unique: true
},
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_gender'
});
Model.associate = function() {
}
return Model;
};
/* indent size: 2 */
module.exports = app => {
const DataTypes = app.Sequelize;
const Model = app.model.define('t_user_increased_daily', {
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: false,
defaultValue: '0'
},
create_time: {
type: DataTypes.DATE,
allowNull: true
},
update_time: {
type: DataTypes.DATE,
allowNull: true
}
}, {
tableName: 't_user_increased_daily'
});
Model.associate = function() {
}
return Model;
};
/* indent size: 2 */
module.exports = app => {
const DataTypes = app.Sequelize;
const Model = app.model.define('t_user_journey_daily', {
id: {
type: DataTypes.INTEGER(10),
allowNull: false,
primaryKey: true,
autoIncrement: true
},
day: {
type: DataTypes.DATE,
allowNull: false,
unique: true
},
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_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', {
id: {
type: DataTypes.INTEGER(10),
allowNull: false,
primaryKey: true,
autoIncrement: true
},
prov_code: {
type: DataTypes.STRING(32),
allowNull: false,
unique: true
},
prov_name: {
type: DataTypes.STRING(32),
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'
});
Model.associate = function() {
}
return Model;
};
/* indent size: 2 */
module.exports = app => {
const DataTypes = app.Sequelize;
const Model = app.model.define('t_user_renew_daily', {
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: false,
defaultValue: '0'
},
create_time: {
type: DataTypes.DATE,
allowNull: true
},
update_time: {
type: DataTypes.DATE,
allowNull: true
}
}, {
tableName: 't_user_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
},
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_summary'
});
Model.associate = function() {
}
return Model;
};
module.exports = app => {
app.router.get('/screen/', app.controller.demo.hello);
};
\ No newline at end of file
......@@ -5,9 +5,10 @@ class DemoService extends Service {
super(ctx);
this.session = ctx.session;
this.DemoModel = ctx.model.Usedrow;
this.ResponseCode = ctx.response.ResponseCode;
this.ServerResponse = ctx.response.ServerResponse;
this.ServerResponseCode = ctx.response.ServerResponseCode;
}
/**
*
* @param field {String}
......@@ -15,7 +16,7 @@ class DemoService extends Service {
* @return {Promise.<boolean>}
*/
async hello() {
const data = await this.DemoModel.findOne({
const data = await this.DemoModel.findAndCountAll({
where: { tname: "app" }
});
return data;
......
const Service = require("egg").Service;
class UserService extends Service {
constructor(ctx) {
super(ctx);
this.session = ctx.session;
this.UserActiveDailyModel = ctx.model.TUserActiveDaily;
this.ResponseCode = ctx.response.ResponseCode;
this.ServerResponse = ctx.response.ServerResponse;
}
/**
*
* @param field {String}
* @param value {String}
* @return {Promise.<boolean>}
*/
async hello() {
const data = await this.DemoModel.findAndCountAll({
where: { tname: "app" }
});
return data;
}
}
module.exports = UserService;
/*
* @Author: limin
* @Date: 2019-11-16 09:26:47
* @Last Modified by: limin
* @Last Modified time: 2019-11-16 09:26:47
* @Last Modified by: limin
* @Last Modified time: 2019-11-20 18:29:52
*/
/* eslint valid-jsdoc: "off" */
......@@ -29,7 +29,7 @@ module.exports = appInfo => {
dialect: "mysql",
host: "192.168.0.39",
port: 3306,
database: "test",
database: "glsx_data_screen",
username: "root",
password: "123456"
};
......
......@@ -2,7 +2,7 @@
* @Author: limin
* @Date: 2019-11-16 09:27:00
* @Last Modified by: limin
* @Last Modified time: 2019-11-16 09:29:21
* @Last Modified time: 2019-11-18 15:16:23
*/
"use strict";
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!