1
This commit is contained in:
92
config/config.js
Normal file
92
config/config.js
Normal file
@@ -0,0 +1,92 @@
|
||||
/**
|
||||
* 应用配置文件 - 业务配置
|
||||
* 包含数据库、端口、第三方服务等配置
|
||||
*/
|
||||
|
||||
const env = process.env.NODE_ENV || 'development';
|
||||
|
||||
module.exports = {
|
||||
// 环境配置
|
||||
env,
|
||||
|
||||
// 端口配置
|
||||
port: {
|
||||
node: 9097, // Node服务端口
|
||||
web: 9000 // 前端服务端口
|
||||
},
|
||||
|
||||
// 数据库配置
|
||||
db: {
|
||||
"username": "autoaiworksys",
|
||||
"password": "tRWZXxH6a4AdnXf6",
|
||||
"database": "autoaiworksys",
|
||||
"host": "192.144.167.231",
|
||||
"port": 3306,
|
||||
"dialect": "mysql"
|
||||
},
|
||||
|
||||
// Redis配置
|
||||
redis: {
|
||||
host: process.env.REDIS_HOST || 'localhost',
|
||||
port: process.env.REDIS_PORT || 6379,
|
||||
password: process.env.REDIS_PASSWORD || '',
|
||||
db: process.env.REDIS_DB || 0,
|
||||
keyPrefix: 'autowork:', // key前缀
|
||||
ttl: 60 * 60 * 24 * 7 // 默认过期时间(7天)
|
||||
},
|
||||
oos: {
|
||||
"accessKeyId": "LTAI5t7kYFnwxKMBUgdQLvVT",
|
||||
"accessKeySecret": "TqXxL6rTYaXDg4RGOgCukyc9gWgl54",
|
||||
region: 'oss-cn-shanghai',
|
||||
bucket: 'bimwe'
|
||||
},
|
||||
|
||||
// 分页配置
|
||||
pagination: {
|
||||
defaultPageSize: 20,
|
||||
maxPageSize: 100
|
||||
},
|
||||
|
||||
// 文件上传配置
|
||||
upload: {
|
||||
path: './upload',
|
||||
maxFileSize: 200 * 1024 * 1024, // 200MB
|
||||
allowedTypes: ['image/jpeg', 'image/png', 'image/gif', 'application/pdf', 'application/msword']
|
||||
},
|
||||
|
||||
// 日志配置
|
||||
log: {
|
||||
path: './logs',
|
||||
level: env === 'development' ? 'debug' : 'info',
|
||||
maxFiles: '14d', // 保留14天日志
|
||||
maxSize: '20m' // 单文件最大20MB
|
||||
},
|
||||
|
||||
// 白名单URL - 不需要token验证的接口
|
||||
"allowUrls": ["/admin_api/sys_user/login", "/admin_api/sys_user/authorityMenus", "/admin_api/sys_user/register", "/api/user/loginByWeixin", "/file/", "/sys_file/", "/admin_api/win_data/viewLogInfo", "/api/user/wx_auth", '/api/docs', 'api/swagger.json', 'payment/notify', 'payment/refund-notify', 'wallet/transfer_notify', 'user/sms/send', 'user/sms/verify'],
|
||||
|
||||
|
||||
// AI服务配置
|
||||
ai: {
|
||||
"apiKey": "sk-c83cdb06a6584f99bb2cd6e8a5ae3bbc",
|
||||
"baseUrl": "https://dashscope.aliyuncs.com/api/v1"
|
||||
},
|
||||
|
||||
// MQTT配置
|
||||
mqtt: {
|
||||
host: process.env.MQTT_HOST || 'localhost',
|
||||
port: process.env.MQTT_PORT || 1883,
|
||||
username: process.env.MQTT_USERNAME || '',
|
||||
password: process.env.MQTT_PASSWORD || '',
|
||||
clientId: 'autowork-' + Math.random().toString(16).substr(2, 8)
|
||||
},
|
||||
|
||||
// 定时任务配置
|
||||
schedule: {
|
||||
enabled: true,
|
||||
timezone: 'Asia/Shanghai'
|
||||
},
|
||||
qq_map_key: "7AXBZ-Z7M3V-BZQPK-53TUZ-2QLC6-RAFKU",
|
||||
|
||||
|
||||
};
|
||||
112
config/custom.schemas.js
Normal file
112
config/custom.schemas.js
Normal file
@@ -0,0 +1,112 @@
|
||||
/**
|
||||
* Swagger自定义Schema定义
|
||||
* 用于生成API文档的数据模型定义
|
||||
*/
|
||||
|
||||
module.exports = {
|
||||
// 通用响应格式
|
||||
ApiResponse: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
code: {
|
||||
type: 'integer',
|
||||
description: '状态码,200表示成功',
|
||||
example: 200
|
||||
},
|
||||
message: {
|
||||
type: 'string',
|
||||
description: '响应消息',
|
||||
example: '操作成功'
|
||||
},
|
||||
data: {
|
||||
type: 'object',
|
||||
description: '响应数据'
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
// 分页响应格式
|
||||
PageResponse: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
code: {
|
||||
type: 'integer',
|
||||
example: 200
|
||||
},
|
||||
message: {
|
||||
type: 'string',
|
||||
example: '查询成功'
|
||||
},
|
||||
data: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
total: {
|
||||
type: 'integer',
|
||||
description: '总记录数'
|
||||
},
|
||||
pageSize: {
|
||||
type: 'integer',
|
||||
description: '每页记录数'
|
||||
},
|
||||
currentPage: {
|
||||
type: 'integer',
|
||||
description: '当前页码'
|
||||
},
|
||||
list: {
|
||||
type: 'array',
|
||||
items: {
|
||||
type: 'object'
|
||||
},
|
||||
description: '数据列表'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
// 登录请求
|
||||
LoginRequest: {
|
||||
type: 'object',
|
||||
required: ['username', 'password'],
|
||||
properties: {
|
||||
username: {
|
||||
type: 'string',
|
||||
description: '用户名',
|
||||
example: 'admin'
|
||||
},
|
||||
password: {
|
||||
type: 'string',
|
||||
description: '密码',
|
||||
example: '123456'
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
// 登录响应
|
||||
LoginResponse: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
code: {
|
||||
type: 'integer',
|
||||
example: 200
|
||||
},
|
||||
message: {
|
||||
type: 'string',
|
||||
example: '登录成功'
|
||||
},
|
||||
data: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
token: {
|
||||
type: 'string',
|
||||
description: 'JWT Token'
|
||||
},
|
||||
userInfo: {
|
||||
type: 'object',
|
||||
description: '用户信息'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
110
config/framework.config.js
Normal file
110
config/framework.config.js
Normal file
@@ -0,0 +1,110 @@
|
||||
/**
|
||||
* Framework 配置文件
|
||||
* 基于 node-core-framework 的配置
|
||||
*/
|
||||
|
||||
const baseConfig = require('./config.js');
|
||||
const customSchemas = require('./custom.schemas.js');
|
||||
|
||||
module.exports = {
|
||||
// ===== 必需配置 =====
|
||||
env: process.env.NODE_ENV || 'development',
|
||||
"project_key": "BallBookingMiniProgram",
|
||||
// 数据库配置(必需)
|
||||
db: {
|
||||
username: baseConfig.db.username,
|
||||
password: baseConfig.db.password,
|
||||
database: baseConfig.db.database,
|
||||
host: baseConfig.db.host,
|
||||
port: baseConfig.db.port || 3306,
|
||||
dialect: baseConfig.db.dialect || 'mysql',
|
||||
timezone: '+08:00',
|
||||
pool: {
|
||||
max: 10,
|
||||
min: 0,
|
||||
acquire: 30000,
|
||||
idle: 10000
|
||||
},
|
||||
logging: false
|
||||
},
|
||||
|
||||
// API 路径配置(必需)
|
||||
apiPaths: [
|
||||
{
|
||||
path: './api/controller_front',
|
||||
prefix: '/api',
|
||||
authType: 'applet'
|
||||
},
|
||||
{
|
||||
path: './api/controller_admin',
|
||||
prefix: '/admin_api',
|
||||
authType: 'admin'
|
||||
}
|
||||
],
|
||||
|
||||
"fileConifg": {
|
||||
"vue": {
|
||||
"api": "../../admin/src/api/",
|
||||
"view": "../../admin/src/view/"
|
||||
},
|
||||
"node": {
|
||||
"controller": "../controller_admin/",
|
||||
"model": "../model/"
|
||||
}
|
||||
},
|
||||
|
||||
// API文档配置
|
||||
swagger: {
|
||||
title: '约球小程序后端 API',
|
||||
version: '1.0.0',
|
||||
description: '约球小程序后端服务 API 文档',
|
||||
contact: {
|
||||
name: '开发团队',
|
||||
email: 'dev@example.com'
|
||||
}
|
||||
},
|
||||
|
||||
// ===== 建议配置 =====
|
||||
|
||||
// 基础 URL(根据环境区分)
|
||||
baseUrl: (() => {
|
||||
const env = process.env.NODE_ENV || 'production';
|
||||
|
||||
switch (env) {
|
||||
case 'production':
|
||||
return 'https://work.light120.com'; // 生产环境
|
||||
case 'development':
|
||||
default:
|
||||
return 'http://localhost:9097'; // 开发环境
|
||||
}
|
||||
})(),
|
||||
|
||||
// 日志路径
|
||||
logPath: './logs',
|
||||
|
||||
// 白名单 URL(不需要认证的接口)
|
||||
allowUrls: baseConfig.allowUrls,
|
||||
|
||||
// 授权文件路径(可选,如果不需要授权验证可以设置为 null)
|
||||
// 授权验证配置
|
||||
license: {
|
||||
licensePath: require('path').join(__dirname, '_license', 'license.lic')
|
||||
},
|
||||
|
||||
|
||||
// Redis 配置
|
||||
redis: baseConfig.redis || null,
|
||||
|
||||
// 模型路径
|
||||
modelPaths: './api/model',
|
||||
|
||||
// ===== 业务配置(从原 config.js 继承)=====
|
||||
|
||||
// 端口配置
|
||||
port: baseConfig.port,
|
||||
|
||||
|
||||
// 自定义 Swagger Schemas
|
||||
customSchemas: customSchemas
|
||||
};
|
||||
|
||||
49
config/model.associations.js
Normal file
49
config/model.associations.js
Normal file
@@ -0,0 +1,49 @@
|
||||
/**
|
||||
* 数据模型关联配置
|
||||
* 定义各个模型之间的关系(一对一、一对多、多对多)
|
||||
*/
|
||||
|
||||
module.exports = (models) => {
|
||||
// 示例: 用户和账户关联
|
||||
// if (models.pla_account && models.sys_user) {
|
||||
// models.pla_account.belongsTo(models.sys_user, {
|
||||
// foreignKey: 'user_id',
|
||||
// as: 'user'
|
||||
// });
|
||||
// models.sys_user.hasMany(models.pla_account, {
|
||||
// foreignKey: 'user_id',
|
||||
// as: 'accounts'
|
||||
// });
|
||||
// }
|
||||
|
||||
// 示例: 职位和任务状态关联
|
||||
if (models.job_postings && models.task_status) {
|
||||
models.job_postings.hasMany(models.task_status, {
|
||||
foreignKey: 'job_id',
|
||||
as: 'tasks'
|
||||
});
|
||||
models.task_status.belongsTo(models.job_postings, {
|
||||
foreignKey: 'job_id',
|
||||
as: 'job'
|
||||
});
|
||||
}
|
||||
|
||||
// 任务状态和任务指令关联(已禁用,不在数据库层面添加外键约束)
|
||||
// if (models.task_status && models.task_commands) {
|
||||
// models.task_status.hasMany(models.task_commands, {
|
||||
// foreignKey: 'task_id',
|
||||
// as: 'commands'
|
||||
// });
|
||||
// models.task_commands.belongsTo(models.task_status, {
|
||||
// foreignKey: 'task_id',
|
||||
// as: 'task'
|
||||
// });
|
||||
// }
|
||||
|
||||
// 在这里添加更多模型关联
|
||||
// 一对一: hasOne / belongsTo
|
||||
// 一对多: hasMany / belongsTo
|
||||
// 多对多: belongsToMany
|
||||
|
||||
console.log('模型关联配置完成');
|
||||
};
|
||||
Reference in New Issue
Block a user