初始化

This commit is contained in:
robin
2022-08-02 19:21:03 +08:00
parent 73c1343060
commit b7e5ee5fec
27 changed files with 564 additions and 156 deletions
+1 -1
View File
@@ -36,7 +36,7 @@ beforeAll(() => {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
bamboo.fullList.push(async (app) => { bamboo.fullList.push(async (app) => {
server = app.server server = app.server
//复测试数据镜像sql文件 //复测试数据镜像sql文件
await app.db.tool.reduction() await app.db.tool.reduction()
resolve() resolve()
}) })
+14 -13
View File
@@ -1,19 +1,20 @@
module.exports = { module.exports = {
doc: "消息表", doc : "消息表",
api: true,//是否需要生成api接口 api : true,//是否需要生成api接口
model: { model: {
uid: {type: "STRING", comment: '发送人用户id'}, oid : {type: "INTEGER", comment: '发送人用户机构id'},
name: {type: "STRING", comment: '发送人名称'}, uid : {type: "INTEGER", comment: '发送人用户id'},
avatar: {type: "STRING", comment: '发送人头像'}, name : {type: "STRING", comment: '发送人名称'},
to_uid: {type: "STRING", comment: '接收人用户id'}, avatar : {type: "STRING", comment: '发送人头像'},
to_name: {type: "STRING", comment: '接收人名称'}, to_uid : {type: "STRING", comment: '接收人用户id'},
to_name : {type: "STRING", comment: '接收人名称'},
to_avatar: {type: "STRING", comment: '接收人头像'}, to_avatar: {type: "STRING", comment: '接收人头像'},
status: {type: "STRING", comment: '状态:已读/未读:y/n'}, status : {type: "STRING", comment: '状态:已读/未读:y/n'},
type: {type: "STRING", comment: '消息类型:file / image / text / event'}, type : {type: "STRING", comment: '消息类型:file / image / text / event'},
sendTime: {type: "STRING", comment: '消息发送时间'}, sendTime : {type: "STRING", comment: '消息发送时间'},
content: {type: "STRING", comment: '消息内容,如果type=file,此属性表示文件的URL地址'}, content : {type: "STRING", fieldNameCus: '消息内容', comment: '消息内容,如果type=file,此属性表示文件的URL地址'},
fileSize: {type: "STRING", comment: '文件大小'}, fileSize : {type: "STRING", comment: '文件大小'},
fileName: {type: "STRING", comment: '文件名称'}, fileName : {type: "STRING", comment: '文件名称'},
}, },
} }
+2 -35
View File
@@ -1,39 +1,6 @@
module.exports = { module.exports = {
describe_name: "permission/权限管理", describe_name: "message/消息中心",
testList : [ testList : [
{
test_name: "账号密码注册",
fun : async (request, server) => {
const response = await request(server)
.post('/permission/api/registered')
.send({
type: "accountPassword",
data: {
account : "test",
password: "123456",
},
})
// expect(response.status).toEqual(200)
expect(response.body.status).toEqual(200)
expect(response.body.data).toHaveProperty('token')
}
},
{
test_name: "账号密码登录",
fun : async (request, server) => {
const response = await request(server)
.post('/permission/api/login')
.send({
type: "accountPassword",
data: {
account : "test",
password: "123456",
},
})
// expect(response.status).toEqual(200)
expect(response.body.status).toEqual(200)
expect(response.body.data).toHaveProperty('token')
}
},
] ]
} }
+19
View File
@@ -0,0 +1,19 @@
'use strict';
module.exports = {
params: {
"uid": "string",//数据
"general_management": "string",//数据
},
fun : async (ctx, app) => {
const {name, general_management} = ctx.params
if (await $components.registered[type](data)) {
return $res.success({
token: await $components.jwt.sign({})
}, "注册成功")
}
return $res.error({}, "登录失败")
}
}
+19
View File
@@ -0,0 +1,19 @@
'use strict';
module.exports = {
params: {
"name": "string",//数据
"general_management": "string",//数据
},
fun : async (ctx, app) => {
const {name, general_management} = ctx.params
if (await $components.registered[type](data)) {
return $res.success({
token: await $components.jwt.sign({})
}, "注册成功")
}
return $res.error({}, "登录失败")
}
}
@@ -1,4 +1,5 @@
const crypto = require('crypto'); const crypto = require('crypto');
const shortid = require('shortid');
module.exports = { module.exports = {
// 随机数(盐值) // 随机数(盐值)
getRandomSalt() { getRandomSalt() {
@@ -20,4 +21,8 @@ module.exports = {
cryptPwdVerification(password, salt, user_password_md5) { cryptPwdVerification(password, salt, user_password_md5) {
return this.cryptPwd(password, salt) === user_password_md5; return this.cryptPwd(password, salt) === user_password_md5;
}, },
// 返回随机短uuid
shortid() {
return shortid.generate()
},
} }
@@ -0,0 +1,10 @@
module.exports = {
//添加机构
async add(name, general_management) {
$db.table('Organization').data({
oid: $components.encrypt.shortid(),
name,
general_management
}).save()
},
}
@@ -7,9 +7,9 @@
* @return {boolean} 注册 是否 成功. * @return {boolean} 注册 是否 成功.
*/ */
module.exports = async (data) => { module.exports = async (data) => {
const {account, password} = data const {account, password, oid} = data
const salt = app.components.encrypt.getRandomSalt() const salt = app.components.encrypt.getRandomSalt()
const md5 = app.components.encrypt.cryptPwd(password, salt) const md5 = app.components.encrypt.cryptPwd(password, salt)
await app.db.table("User").data({account, password: md5, salt}).save() await app.db.table("User").data({account, password: md5, salt, to_oid: oid}).save()
return true return true
} }
+5 -5
View File
@@ -1,10 +1,10 @@
module.exports = { module.exports = {
doc: "组织表", doc : "机构表",
api: true,//是否需要生成api接口 api : true,//是否需要生成api接口
model: { model: {
oid: {type: "STRING", comment: '组织id'}, oid : {type: "INTEGER", comment: '机构id', primaryKey: true},
name: {type: "STRING", comment: '组织名称'}, name : {type: "STRING", comment: '机构名称'},
general_management: {type: "STRING", comment: '是否为总管理平台(可以管理所有组织)'}, general_management: {type: "STRING", comment: '是否为总管理平台(可以管理所有机构):y/n'},
}, },
} }
@@ -0,0 +1,13 @@
module.exports = {
doc: "组织配置表",
api: true,//是否需要生成api接口
model: {
oid: {type: "STRING", comment: '组织id'},
name: {type: "STRING", comment: '名称'},
type: {type: "STRING", comment: '类型:string/number/json'},
code: {type: "STRING", comment: '识别码'},
value: {type: "STRING", comment: '权限值'},
},
}
+1 -1
View File
@@ -2,7 +2,7 @@ module.exports = {
doc: "权限列表", doc: "权限列表",
api: true,//是否需要生成api接口 api: true,//是否需要生成api接口
model: { model: {
pid: {type: "STRING", comment: '权限id'}, pid: {type: "INTEGER", comment: '权限id', primaryKey: true},
name: {type: "STRING", comment: '权限名称'}, name: {type: "STRING", comment: '权限名称'},
type: {type: "STRING", comment: '权限类型:接口/字段/表格/按钮:jk/zd/bg/an'}, type: {type: "STRING", comment: '权限类型:接口/字段/表格/按钮:jk/zd/bg/an'},
code: {type: "STRING", comment: '权限识别码'}, code: {type: "STRING", comment: '权限识别码'},
+1 -1
View File
@@ -2,7 +2,7 @@ module.exports = {
doc: "角色表", doc: "角色表",
api: true,//是否需要生成api接口 api: true,//是否需要生成api接口
model: { model: {
rid: {type: "STRING", comment: '角色id'}, rid: {type: "INTEGER", comment: '角色id', primaryKey: true},
name: {type: "STRING", comment: '角色名称'}, name: {type: "STRING", comment: '角色名称'},
to_oid: {type: "STRING", comment: '所属组织id'}, to_oid: {type: "STRING", comment: '所属组织id'},
}, },
+1 -3
View File
@@ -2,12 +2,10 @@ module.exports = {
doc: "用户表", doc: "用户表",
api: true,//是否需要生成api接口 api: true,//是否需要生成api接口
model: { model: {
uid: {type: "STRING", comment: '用户id'}, uid: {type: "INTEGER", comment: '用户id', primaryKey: true},
account: {type: "STRING", comment: '用户账号'}, account: {type: "STRING", comment: '用户账号'},
password: {type: "STRING", comment: '用户加密密码'}, password: {type: "STRING", comment: '用户加密密码'},
salt: {type: "STRING", comment: '用户加密随机数'}, salt: {type: "STRING", comment: '用户加密随机数'},
to_oid: {type: "STRING", comment: '所属组织id'},
to_rid: {type: "STRING", comment: '所属角色id'},
}, },
} }
+4 -2
View File
@@ -2,13 +2,15 @@ module.exports = {
doc: "用户资料表", doc: "用户资料表",
api: true,//是否需要生成api接口 api: true,//是否需要生成api接口
model: { model: {
uid: {type: "STRING", comment: '用户id'}, uid: {type: "INTEGER", comment: '用户id'},
to_oid: {type: "INTEGER", comment: '所属组织id'},
to_rid: {type: "INTEGER", comment: '所属角色id'},
account: {type: "STRING", comment: '用户账号'}, account: {type: "STRING", comment: '用户账号'},
name: {type: "STRING", comment: '名称'}, name: {type: "STRING", comment: '名称'},
avatar: {type: "STRING", comment: '头像'}, avatar: {type: "STRING", comment: '头像'},
wechat_openid: {type: "STRING", comment: '微信openid'}, wechat_openid: {type: "STRING", comment: '微信openid'},
phone_number: {type: "STRING", comment: '手机号'}, phone_number: {type: "STRING", comment: '手机号'},
age: {type: "STRING", comment: '年龄'}, age: {type: "INTEGER", comment: '年龄'},
sex: {type: "STRING", comment: '性别'}, sex: {type: "STRING", comment: '性别'},
province: {type: "STRING", comment: '省份'}, province: {type: "STRING", comment: '省份'},
city: {type: "STRING", comment: '城市'}, city: {type: "STRING", comment: '城市'},
+27
View File
@@ -0,0 +1,27 @@
'use strict';
//获取数据库模型列表
module.exports = {
params: {},
fun : async (ctx, app) => {
const {} = ctx.params
const data = Object.keys($db.models).map(item => {
let tableAttributes = $db.models[item].tableAttributes
let ta = {}
Object.keys(tableAttributes).forEach(ta_item => {
ta[ta_item] = {
fieldName: tableAttributes[ta_item].fieldName,//字段名
field : tableAttributes[ta_item].field,//字段
headName : tableAttributes[ta_item].fieldNameCus,//字段自定义名
comment : tableAttributes[ta_item].comment,//注释
}
})
return {
tableName : $db.models[item].tableName,
tableAttributes: ta,
primaryKeyField: $db.models[item].primaryKeyField,
}
})
return data
}
}
+12
View File
@@ -0,0 +1,12 @@
'use strict';
module.exports = {
params: {
"taskList": "array",
},
fun : async (ctx, app) => {
const {taskList} = ctx.params
const data = await $db.jsonTasks(taskList)
return data
}
}
+20
View File
@@ -0,0 +1,20 @@
module.exports = {
doc : "数据库模型映射到前端目录表",
api : true,//是否需要生成api接口
model: {
// id : {type: "INTEGER", comment: '导航id', primaryKey: true},
name: {type: "STRING", comment: '导航名称'},
path: {type: "STRING", comment: '导航路径'},
index: {type: "INTEGER", comment: '权重,越大越靠前'},
icon : {type: "STRING", comment: '图标'},
group: {type: "STRING", comment: '导航分组'},
table: {type: "STRING", comment: '绑定的表名'},
table_key: {type: "STRING", comment: '表的主键名称,一般是id'},
search: {type: "STRING", comment: '模糊查询的字段用/分割'},
table_field: {type: "JSON", comment: '表格字段'},
table_field_key: {type: "JSON", comment: '已选择的字段'},
user: {type: "JSON", comment: '查询表字段的时候,默认带上的用户数据,比如["oid"],这样用户就只能看到自己机构的数据'},
},
}
+318
View File
@@ -0,0 +1,318 @@
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
# ------------------------------------------------------------
# SCHEMA DUMP FOR TABLE: Contact
# ------------------------------------------------------------
CREATE TABLE IF NOT EXISTS `Contact` (
`uid` varchar(255) DEFAULT NULL COMMENT '用户id/群id',
`to_uid` varchar(255) DEFAULT NULL COMMENT '接收人用户id',
`type` varchar(255) DEFAULT NULL COMMENT '类型,单人/群:one/group',
`status` varchar(255) DEFAULT NULL COMMENT '状态:已结束/未结束:y/n',
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT '表自增id',
`createdAt` datetime NOT NULL,
`updatedAt` datetime NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `id` (`id`)
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4;
# ------------------------------------------------------------
# SCHEMA DUMP FOR TABLE: Group
# ------------------------------------------------------------
CREATE TABLE IF NOT EXISTS `Group` (
`gid` varchar(255) DEFAULT NULL COMMENT '分组id',
`name` varchar(255) DEFAULT NULL COMMENT '分组名称',
`to_gid` varchar(255) DEFAULT NULL COMMENT '上级分组id',
`to_oid` varchar(255) DEFAULT NULL COMMENT '所属组织id',
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT '表自增id',
`createdAt` datetime NOT NULL,
`updatedAt` datetime NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `id` (`id`)
) ENGINE = InnoDB AUTO_INCREMENT = 2 DEFAULT CHARSET = utf8mb4;
# ------------------------------------------------------------
# SCHEMA DUMP FOR TABLE: Message
# ------------------------------------------------------------
CREATE TABLE IF NOT EXISTS `Message` (
`uid` varchar(255) DEFAULT NULL COMMENT '发送人用户id',
`name` varchar(255) DEFAULT NULL COMMENT '发送人名称',
`avatar` varchar(255) DEFAULT NULL COMMENT '发送人头像',
`to_uid` varchar(255) DEFAULT NULL COMMENT '接收人用户id',
`to_name` varchar(255) DEFAULT NULL COMMENT '接收人名称',
`to_avatar` varchar(255) DEFAULT NULL COMMENT '接收人头像',
`status` varchar(255) DEFAULT NULL COMMENT '状态:已读/未读:y/n',
`type` varchar(255) DEFAULT NULL COMMENT '消息类型:file / image / text / event',
`sendTime` varchar(255) DEFAULT NULL COMMENT '消息发送时间',
`content` varchar(255) DEFAULT NULL COMMENT '消息内容,如果type=file,此属性表示文件的URL地址',
`fileSize` varchar(255) DEFAULT NULL COMMENT '文件大小',
`fileName` varchar(255) DEFAULT NULL COMMENT '文件名称',
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT '表自增id',
`createdAt` datetime NOT NULL,
`updatedAt` datetime NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `id` (`id`)
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4;
# ------------------------------------------------------------
# SCHEMA DUMP FOR TABLE: Organization
# ------------------------------------------------------------
CREATE TABLE IF NOT EXISTS `Organization` (
`oid` varchar(255) DEFAULT NULL COMMENT '组织id',
`name` varchar(255) DEFAULT NULL COMMENT '组织名称',
`general_management` varchar(255) DEFAULT NULL COMMENT '是否为总管理平台(可以管理所有组织):y/n',
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT '表自增id',
`createdAt` datetime NOT NULL,
`updatedAt` datetime NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `id` (`id`)
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4;
# ------------------------------------------------------------
# SCHEMA DUMP FOR TABLE: OrganizationSetting
# ------------------------------------------------------------
CREATE TABLE IF NOT EXISTS `OrganizationSetting` (
`oid` varchar(255) DEFAULT NULL COMMENT '组织id',
`name` varchar(255) DEFAULT NULL COMMENT '名称',
`type` varchar(255) DEFAULT NULL COMMENT '类型:string/number/json',
`code` varchar(255) DEFAULT NULL COMMENT '识别码',
`value` varchar(255) DEFAULT NULL COMMENT '权限值',
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT '表自增id',
`createdAt` datetime NOT NULL,
`updatedAt` datetime NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `id` (`id`)
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4;
# ------------------------------------------------------------
# SCHEMA DUMP FOR TABLE: Permission
# ------------------------------------------------------------
CREATE TABLE IF NOT EXISTS `Permission` (
`pid` varchar(255) DEFAULT NULL COMMENT '权限id',
`name` varchar(255) DEFAULT NULL COMMENT '权限名称',
`code` varchar(255) DEFAULT NULL COMMENT '权限识别码',
`value` varchar(255) DEFAULT NULL COMMENT '权限值',
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT '表自增id',
`createdAt` datetime NOT NULL,
`updatedAt` datetime NOT NULL,
`type` varchar(255) DEFAULT NULL COMMENT '权限类型:接口/字段/表格/按钮:jk/zd/bg/an',
PRIMARY KEY (`id`),
UNIQUE KEY `id` (`id`)
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4;
# ------------------------------------------------------------
# SCHEMA DUMP FOR TABLE: PermissionClass
# ------------------------------------------------------------
CREATE TABLE IF NOT EXISTS `PermissionClass` (
`name` varchar(255) DEFAULT NULL COMMENT '权限分类名称',
`pccode` varchar(255) DEFAULT NULL COMMENT '权限分类识别码',
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT '表自增id',
`createdAt` datetime NOT NULL,
`updatedAt` datetime NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `id` (`id`)
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4;
# ------------------------------------------------------------
# SCHEMA DUMP FOR TABLE: Role
# ------------------------------------------------------------
CREATE TABLE IF NOT EXISTS `Role` (
`rid` varchar(255) DEFAULT NULL COMMENT '角色id',
`name` varchar(255) DEFAULT NULL COMMENT '角色名称',
`to_oid` varchar(255) DEFAULT NULL COMMENT '所属组织id',
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT '表自增id',
`createdAt` datetime NOT NULL,
`updatedAt` datetime NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `id` (`id`)
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4;
# ------------------------------------------------------------
# SCHEMA DUMP FOR TABLE: RoleToPermission
# ------------------------------------------------------------
CREATE TABLE IF NOT EXISTS `RoleToPermission` (
`to_rid` varchar(255) DEFAULT NULL COMMENT '角色id',
`to_pid` varchar(255) DEFAULT NULL COMMENT '权限id',
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT '表自增id',
`createdAt` datetime NOT NULL,
`updatedAt` datetime NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `id` (`id`)
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4;
# ------------------------------------------------------------
# SCHEMA DUMP FOR TABLE: User
# ------------------------------------------------------------
CREATE TABLE IF NOT EXISTS `User` (
`uid` varchar(255) DEFAULT NULL COMMENT '用户id',
`account` varchar(255) DEFAULT NULL COMMENT '用户账号',
`password` varchar(255) DEFAULT NULL COMMENT '用户加密密码',
`salt` varchar(255) DEFAULT NULL COMMENT '用户加密随机数',
`to_oid` varchar(255) DEFAULT NULL COMMENT '所属组织id',
`to_rid` varchar(255) DEFAULT NULL COMMENT '所属角色id',
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT '表自增id',
`createdAt` datetime NOT NULL,
`updatedAt` datetime NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `id` (`id`)
) ENGINE = InnoDB AUTO_INCREMENT = 1043 DEFAULT CHARSET = utf8mb4;
# ------------------------------------------------------------
# SCHEMA DUMP FOR TABLE: UserInfo
# ------------------------------------------------------------
CREATE TABLE IF NOT EXISTS `UserInfo` (
`uid` varchar(255) DEFAULT NULL COMMENT '用户id',
`account` varchar(255) DEFAULT NULL COMMENT '用户账号',
`name` varchar(255) DEFAULT NULL COMMENT '名称',
`avatar` varchar(255) DEFAULT NULL COMMENT '头像',
`wechat_openid` varchar(255) DEFAULT NULL COMMENT '微信openid',
`phone_number` varchar(255) DEFAULT NULL COMMENT '手机号',
`age` varchar(255) DEFAULT NULL COMMENT '年龄',
`sex` varchar(255) DEFAULT NULL COMMENT '性别',
`province` varchar(255) DEFAULT NULL COMMENT '省份',
`city` varchar(255) DEFAULT NULL COMMENT '城市',
`area` varchar(255) DEFAULT NULL COMMENT '地区',
`address` varchar(255) DEFAULT NULL COMMENT '详细地址',
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT '表自增id',
`createdAt` datetime NOT NULL,
`updatedAt` datetime NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `id` (`id`)
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4;
# ------------------------------------------------------------
# SCHEMA DUMP FOR TABLE: autoRes
# ------------------------------------------------------------
CREATE TABLE IF NOT EXISTS `autoRes` (
`type` varchar(255) DEFAULT NULL COMMENT '类型,自动回复/问候语:auto/hello',
`status` varchar(255) DEFAULT NULL COMMENT '状态:显示/隐藏:y/n',
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT '表自增id',
`createdAt` datetime NOT NULL,
`updatedAt` datetime NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `id` (`id`)
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4;
# ------------------------------------------------------------
# SCHEMA DUMP FOR TABLE: role
# ------------------------------------------------------------
CREATE TABLE IF NOT EXISTS `role` (
`uid` varchar(255) DEFAULT NULL COMMENT '用户id',
`age` int(11) DEFAULT '0' COMMENT '年龄',
`age2` int(11) DEFAULT '0' COMMENT '年龄',
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT '表自增id',
`createdAt` datetime NOT NULL,
`updatedAt` datetime NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `id` (`id`)
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4;
# ------------------------------------------------------------
# DATA DUMP FOR TABLE: Contact
# ------------------------------------------------------------
# ------------------------------------------------------------
# DATA DUMP FOR TABLE: Group
# ------------------------------------------------------------
INSERT INTO
`Group` (
`gid`,
`name`,
`to_gid`,
`to_oid`,
`id`,
`createdAt`,
`updatedAt`
)
VALUES
(
'1',
'1',
NULL,
NULL,
1,
'2022-06-18 03:53:29',
'2022-06-18 03:53:32'
);
# ------------------------------------------------------------
# DATA DUMP FOR TABLE: Message
# ------------------------------------------------------------
# ------------------------------------------------------------
# DATA DUMP FOR TABLE: Organization
# ------------------------------------------------------------
# ------------------------------------------------------------
# DATA DUMP FOR TABLE: OrganizationSetting
# ------------------------------------------------------------
# ------------------------------------------------------------
# DATA DUMP FOR TABLE: Permission
# ------------------------------------------------------------
# ------------------------------------------------------------
# DATA DUMP FOR TABLE: PermissionClass
# ------------------------------------------------------------
# ------------------------------------------------------------
# DATA DUMP FOR TABLE: Role
# ------------------------------------------------------------
# ------------------------------------------------------------
# DATA DUMP FOR TABLE: RoleToPermission
# ------------------------------------------------------------
# ------------------------------------------------------------
# DATA DUMP FOR TABLE: User
# ------------------------------------------------------------
# ------------------------------------------------------------
# DATA DUMP FOR TABLE: UserInfo
# ------------------------------------------------------------
# ------------------------------------------------------------
# DATA DUMP FOR TABLE: autoRes
# ------------------------------------------------------------
# ------------------------------------------------------------
# DATA DUMP FOR TABLE: role
# ------------------------------------------------------------
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
+23 -3
View File
@@ -43,7 +43,11 @@ module.exports = class Api {
* @param {object} value 筛选条件对象. * @param {object} value 筛选条件对象.
*/ */
where(value) { where(value) {
if (!this.tableWhere) {
this.tableWhere = value this.tableWhere = value
} else {
Object.assign(this.tableWhere, value)
}
return this return this
} }
@@ -84,12 +88,26 @@ module.exports = class Api {
return this return this
} }
/**
* 模糊查询
* @param {string} value 关键字:你好.
* @param {array} fieldList 字段列表['createdAt'].
*/
search({value, fieldList}) {
if (!value|| !fieldList) return this
if (!this.tableWhere) this.tableWhere = {}
this.tableWhere['$or'] = fieldList.map(item => {
return {[item]: {'$like': `%${value || ''}%`}}
})
return this
}
/** /**
* 常用时间筛选 * 常用时间筛选
* @param {string|array|Number} value 时间内容:按时间段:['2000-1-1','2000-1-2'],按常用时间:day,按最近60分钟:60. * @param {string|array|Number} value 时间内容:按时间段:['2000-1-1','2000-1-2'],按常用时间:day,按最近60分钟:60.
* @param {string} field 时间字段(默认createdAt字段) * @param {string} field 时间字段(默认createdAt字段)
*/ */
time(value, field) { time({value, field}) {
if (!this.tableName) { if (!this.tableName) {
throw "请传表名" throw "请传表名"
} }
@@ -251,7 +269,7 @@ module.exports = class Api {
* @param {number} min 字段减小后的值不能小于最小值 * @param {number} min 字段减小后的值不能小于最小值
* @param {number} setValue 如果减小后的字段小于min,设置字段值为n * @param {number} setValue 如果减小后的字段小于min,设置字段值为n
*/ */
async setDec(min, setValue) { async setDec({min, setValue}) {
if (!this.tableName) { if (!this.tableName) {
throw "请传表名" throw "请传表名"
} }
@@ -317,7 +335,7 @@ module.exports = class Api {
* @param {number} max 字段增加后的值不能大于最大值 * @param {number} max 字段增加后的值不能大于最大值
* @param {number} setValue 如果增加后的字段大于max,设置字段值为n * @param {number} setValue 如果增加后的字段大于max,设置字段值为n
*/ */
async setInc(max, setValue) { async setInc({max, setValue}) {
if (!this.tableName) { if (!this.tableName) {
throw "请传表名" throw "请传表名"
} }
@@ -494,6 +512,7 @@ module.exports = class Api {
...options ...options
} }
) )
this.init()
return res return res
} }
@@ -523,6 +542,7 @@ module.exports = class Api {
...options ...options
} }
) )
this.init()
return res return res
} }
+13 -3
View File
@@ -16,7 +16,7 @@ module.exports = async (app) => {
const {database, username, password, options,} = config const {database, username, password, options,} = config
const sequelize = new Sequelize(database, username, password, { const sequelize = new Sequelize(database, username, password, {
...options, ...options,
operatorsAliases, operatorsAliases:operatorsAliases,
}); });
// 加载model文件 // 加载model文件
@@ -24,10 +24,20 @@ module.exports = async (app) => {
list.forEach(item => { list.forEach(item => {
const {res, parse} = item const {res, parse} = item
const model = {} const model = {}
let primaryKey = false
for (let key of Object.keys(res.model)) { for (let key of Object.keys(res.model)) {
res.model[key].type = Sequelize[res.model[key].type] res.model[key].type = Sequelize[res.model[key].type]
model[key] = res.model[key] model[key] = res.model[key]
//如果表设置了主键,那么就不设置默认主键为id了
if (res.model[key].primaryKey) {
primaryKey = true
res.model[key].allowNull = false
res.model[key].unique = key
res.model[key].autoIncrement = true
} }
}
//如果没有默认主键
if (!primaryKey) {
model['id'] = { model['id'] = {
type : Sequelize.INTEGER, type : Sequelize.INTEGER,
comment : '表自增id', comment : '表自增id',
@@ -36,10 +46,10 @@ module.exports = async (app) => {
primaryKey : true, primaryKey : true,
autoIncrement: true, autoIncrement: true,
} }
}
sequelize.define(parse.name, model) sequelize.define(parse.name, model)
}) })
app.models = sequelize.models app.models = sequelize.models
const api = new Api(sequelize, sequelize.models) const api = new Api(sequelize, sequelize.models)
app.db = api app.db = api
+39 -42
View File
@@ -1,46 +1,43 @@
//定义别名 //定义别名
const Sequelize = require("sequelize"); const Sequelize = require("sequelize");
module.exports = () => { const Op = Sequelize.Op;
const Op = Sequelize.Op;
//操作符别名 module.exports = {
const operatorsAliases = { $eq : Op.eq,
$eq: Op.eq, $ne : Op.ne,
$ne: Op.ne, $gte : Op.gte,
$gte: Op.gte, $gt : Op.gt,
$gt: Op.gt, $lte : Op.lte,
$lte: Op.lte, $lt : Op.lt,
$lt: Op.lt, $not : Op.not,
$not: Op.not, $in : Op.in,
$in: Op.in, $notIn : Op.notIn,
$notIn: Op.notIn, $is : Op.is,
$is: Op.is, $like : Op.like,
$like: Op.like, $notLike : Op.notLike,
$notLike: Op.notLike, $iLike : Op.iLike,
$iLike: Op.iLike, $notILike : Op.notILike,
$notILike: Op.notILike, $regexp : Op.regexp,
$regexp: Op.regexp, $notRegexp : Op.notRegexp,
$notRegexp: Op.notRegexp, $iRegexp : Op.iRegexp,
$iRegexp: Op.iRegexp, $notIRegexp : Op.notIRegexp,
$notIRegexp: Op.notIRegexp, $between : Op.between,
$between: Op.between, $notBetween : Op.notBetween,
$notBetween: Op.notBetween, $overlap : Op.overlap,
$overlap: Op.overlap, $contains : Op.contains,
$contains: Op.contains, $contained : Op.contained,
$contained: Op.contained, $adjacent : Op.adjacent,
$adjacent: Op.adjacent, $strictLeft : Op.strictLeft,
$strictLeft: Op.strictLeft, $strictRight : Op.strictRight,
$strictRight: Op.strictRight,
$noExtendRight: Op.noExtendRight, $noExtendRight: Op.noExtendRight,
$noExtendLeft: Op.noExtendLeft, $noExtendLeft : Op.noExtendLeft,
$substring: Op.substring, $substring : Op.substring,
$startsWith: Op.startsWith, $startsWith : Op.startsWith,
$endsWith: Op.endsWith, $endsWith : Op.endsWith,
$and: Op.and, $and : Op.and,
$or: Op.or, $or : Op.or,
$any: Op.any, $any : Op.any,
$all: Op.all, $all : Op.all,
$values: Op.values, $values : Op.values,
$col: Op.col $col : Op.col
};
return operatorsAliases
} }
+2 -1
View File
@@ -43,7 +43,8 @@ module.exports = class {
database: config.database, database: config.database,
}); });
this.file = this.app.root + '/' + config.database + '.sql' this.file = this.app.root + '/' + config.database + '.sql'
await importer.import(this.file) // const res = await importer.import(this.file)
// console.log(res);
console.timeEnd("reduction") console.timeEnd("reduction")
} }
+2 -2
View File
@@ -1,6 +1,6 @@
module.exports = { module.exports = {
port: 6379, // Redis port port: 6380, // Redis port
host: "192.168.1.26", // Redis host host: "127.0.0.1", // Redis host
// username: "", // needs Redis >= 6 // username: "", // needs Redis >= 6
password: "9715115286", password: "9715115286",
db: 0, // Defaults to 0 db: 0, // Defaults to 0
-4
View File
@@ -1,4 +0,0 @@
module.exports = {
path : "app/*/model/*.js",
prefix : "auto",//接口前缀
}
-27
View File
@@ -1,27 +0,0 @@
'use strict';
/**
* 加载模型到路由
* 加载app/api目录下的文件到路由
*/
const Router = require('koa-router')
const config = require("./config")
// 错误处理
module.exports = {
sort : 999, //排序
use : false, // 是否使用
loadFun: async (app, fun) => { // 自行定义中间件的加载方式,将覆盖默认加载方法
const router = await fun(app)
app.use(router.routes()).use(router.allowedMethods())
},
fun : async (app) => {
const router = new Router({ //设置前缀
prefix: config.prefix
});
let list = await app.load(config.path)
list.forEach(item => {
})
return router
}
}
+1 -2
View File
@@ -58,9 +58,8 @@ module.exports = {
}) })
}) })
//默认根路由
router.all('/', async (ctx, next) => { router.all('/', async (ctx, next) => {
ctx.body = app.res.success("ok") ctx.body = app.res.success("ok")
ctx.status = 200 ctx.status = 200
await next(); await next();
+1
View File
@@ -77,6 +77,7 @@
"require-directory": "^2.1.1", "require-directory": "^2.1.1",
"sequelize": "^6.20.1", "sequelize": "^6.20.1",
"shelljs": "^0.8.5", "shelljs": "^0.8.5",
"shortid": "^2.2.16",
"socket.io": "^4.5.1", "socket.io": "^4.5.1",
"sqlite3": "^5.0.2", "sqlite3": "^5.0.2",
"supertest": "^6.2.3", "supertest": "^6.2.3",