const path = require('node:path'); /** * 生成应用默认配置。 * @param {Egg.EggAppInfo} appInfo 应用信息。 * @return {Egg.EggAppConfig} 应用配置。 */ module.exports = appInfo => { /** * built-in config * @type {Egg.EggAppConfig} **/ const config = exports = {}; // use for cookie sign key, should change to your own and keep security config.keys = appInfo.name + '_1745985142442_9900'; // add your middleware config here config.middleware = []; // add your user config here const userConfig = { // myAppName: 'egg', }; const tencentCloudConfig = require('./tencent-cloud'); config.redis = { clients: { cache: { port: 6379, host: '127.0.0.1', password: 'qwe2019@', db: 10, }, printer: { port: 6379, host: '127.0.0.1', password: 'qwe2019@', db: 11, }, }, }; config.security = { csrf: { enable: false, }, }; config.qimen = { appKey: 23535631, security: 'd0cbd3935e3afa2b42b5dc600c08a795', }; // 微信开放平台第三方平台(组件)配置:接收授权事件推送与调用授权方接口。 // 值可被 config.local.js / config.prod.js 覆盖。 config.wechatOpen = { component_appid: 'wx6e91ec813bcb7eec', component_secret: '8e76ea205dcc1d3e506ce6c102375bdd', token: 'lujS6QH8jUkabwOwMuAqe9odz7', encoding_aes_key: 'lujS6QH8jUkabwOwMuAqe9odz7jmKEnT37XMahpSmrU', api_base: 'https://api.weixin.qq.com', // 授权完成后的回跳地址(微信开放平台授权链接 redirect_uri,须为系统 /Authorization 路由; // 域名须在微信开放平台登记为授权回调域名,前端 nginx 已将 /Authorization 代理到本系统) redirect_uri: 'https://wms.wms.gztbyc.com/Authorization', }; config.deepseek = { apiKey: process.env.DEEPSEEK_API_KEY || '', baseUrl: 'https://api.deepseek.com', }; // 开放接口(OpenAPI)配置 config.openapi = { // 签约关系级接口配置的默认回调地址:不再由接口配置入参维护,保存时统一写入该值。 // 为空时不写入 callback_url(回调通知需在 config.local.js / config.prod.js 等环境配置中补齐) defaultCallbackUrl: '', }; // 站内信模块配置 config.inbox = { imageBaseUrl: '', // 商品图片域名,为空时用请求 ctx.host // 历史消息过滤:消息原始发送时间距今超过该阈值(毫秒)则跳过 AI 处理,防止补推历史消息被当成新工单 historyMessageMaxAgeMs: 10 * 60 * 1000, // AI 兜底开关:规则引擎未命中时是否回退 AI 推理(默认关闭,节省费用;开启后未命中消息走 AI) aiFallback: false, // 退回收件登记聚合通知防抖窗口(毫秒):等该时长无新登记后合并推送,默认 5 分钟 returnReceivedNotifyDelayMs: 5 * 60 * 1000, // 视频补录结果通知:单轮处理条数上限(定时任务每 1 分钟扫一次) videoRecordNotifyLimit: 10, // 视频补录结果通知:超时阈值(毫秒),超过仍无录像则按超时回信并终止,避免长期占用扫描窗口 videoRecordNotifyTimeoutMs: 60 * 60 * 1000, // 出站推送失败自动重推:全局总开关(默认 true;置 false 后所有仓库都不再自动重推;仓库是否启用由仓库设置的 inbox_push_retry.enabled 决定,默认关闭) pushRetryEnabled: true, // 出站推送失败自动重推:兜底失败时间窗(毫秒,默认 30 分钟);仓库设置项 inbox_push_retry.window_minutes 优先(缺省/非法时用本值) pushRetryWindowMs: 30 * 60 * 1000, // 出站推送失败自动重推:单仓单轮最多重推条数(定时任务每 3 分钟扫一次) pushRetryLimit: 20, }; config.tencentCloud = { ...tencentCloudConfig, }; config.cos = { ...config.tencentCloud, bucket: 'ye4s-1255377868', region: 'ap-guangzhou', uploadurl: 'https://ye4s-1255377868.cos.ap-guangzhou.myqcloud.com', cdnurl: 'https://ye4s.file.gzxunren.com', savekey: '{warehouseId}/{dir}/{year}{mon}{day}/{filemd5}{.suffix}', expire: 600, maxsize: '100M', mimetype: 'jpg,png,bmp,jpeg,gif,zip,rar,xls,xlsx,apk', apiupload: 1, dirs: { image: 'images/', document: 'documents/', apk: 'apks/', temp: 'temp/', // 临时文件目录 }, }; config.fileWriter = { baseDir: path.join(appInfo.baseDir, 'runtime', 'file-writer'), maxFileSize: 100 * 1024 * 1024, maxFileLines: 2000, maxConsumeRecordsPerWindow: 1000, maxConsumeRecordsPerRun: 1000, writeWindowSeconds: 1, maxWriteRecordsPerWindow: 1000, retentionDays: 7, cleanupIntervalMs: 60 * 60 * 1000, sequenceWidth: 4, stateMapMaxEntries: 256, fileExtension: '.log', progressExtension: '.progress', }; // 日志落盘目录:显式声明,避免依赖 $HOME 的隐式默认值 // (生产 HOME=/root 时 egg 默认会落到 /root/logs/wms;此处固定下来便于查询与清理) config.logPaths = { base: process.env.WMS_LOG_DIR || (process.platform === 'win32' ? path.join(appInfo.baseDir, 'logs') : '/root/logs/wms'), }; // 文件日志只保留 WARN/ERROR:INFO(含 egg-sequelize 逐条 SQL 日志)不再落盘, // 避免 wms-web.log 每天增长约 2GB 撑爆根分区(/ 仅 40G)。 // consoleLevel 仍为 INFO,本地开发在终端照常看到 INFO,不受影响。 // 与线上 /www/wwwroot/qimen/v1、v2 的手工配置保持一致(生产 config 不参与 deploy,由人工维护)。 config.logger = { dir: config.logPaths.base, level: 'WARN', consoleLevel: 'INFO', }; // 接口流水日志(已替代 wms_system_log 表,该表已下线):一行一条,字段沿用旧表结构并平铺。 // formatter 直接返回 message,不改写内容;整行形如 `HH:mm:ss {JSON}` // (行首时分秒前缀由 app/lib/api_log_sink.js 加上,行尾 eol 由 egg-logger 追加)。 config.customLogger = { apiLog: { file: path.join(config.logPaths.base, 'wms-api.log'), level: 'INFO', consoleLevel: 'NONE', formatter: meta => meta.message, }, }; config.fileTypes = { // 图片类型 image: 'image', 'image/jpeg': 'image', 'image/jpg': 'image', 'image/png': 'image', 'image/gif': 'image', 'image/bmp': 'image', 'image/webp': 'image', 'image/svg+xml': 'image', // 文档类型 'application/pdf': 'document', 'application/msword': 'document', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document': 'document', 'application/vnd.ms-excel': 'document', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet': 'document', 'application/vnd.ms-powerpoint': 'document', 'application/vnd.openxmlformats-officedocument.presentationml.presentation': 'document', 'text/plain': 'document', // 压缩文件 'application/zip': 'document', 'application/x-rar-compressed': 'document', 'application/x-7z-compressed': 'document', // APK 'application/vnd.android.package-archive': 'apk', // 视频 'video/mp4': 'video', 'video/mpeg': 'video', 'video/quicktime': 'video', 'video/x-msvideo': 'video', // 音频 'audio/mpeg': 'audio', 'audio/wav': 'audio', 'audio/x-wav': 'audio', 'audio/x-m4a': 'audio', }; config.cors = { origin: ctx => ctx.get('Origin'), // 动态返回请求源,配合 credentials: true 使用 allowMethods: 'GET,HEAD,PUT,POST,DELETE,PATCH,OPTIONS', exposeHeaders: 'Authorization', credentials: true, // 允许携带 cookie }; config.mysql = { clients: { wms: { host: '127.0.0.1', port: '3306', user: 'wms', password: 'P6j3YTHTpirepYWz', database: 'wms', }, ye4s: { host: '127.0.0.1', port: '3306', user: 'ye4s', password: 'H@8h^QE4N$L.F_*', database: 'ye4s', }, }, app: true, agent: false, }; exports.sequelize = { dialect: 'mysql', host: '112.124.21.102', port: 3306, database: 'wms', username: 'wms', password: 'P6j3YTHTpirepYWz', define: { freezeTableName: true, underscored: true, timestamps: true, paranoid: true, // 启用软删除 deletedAt: 'deleted_at', // 软删除字段名 }, pool: { max: 225, min: 1, idle: 10000, acquire: 30000, }, }; config.jwt = { expiresIn: 14400, renewThreshold: 7200, secret: 'E5#ex.g@,GfL_8?', }; config.view = { defaultViewEngine: 'ejs', mapping: { '.html': 'ejs', }, }; config.cluster = { listen: { port: 6060, // 使用其他端口避免冲突 hostname: '0.0.0.0', }, }; config.poloapi = { }; config.debug = false; // 生成环境默认关闭 debug,开发环境通过 config.local.js 开启 config.platformOauthReservationCodePrefix = ''; config.printService = { url: 'http://printer.wms.gztbyc.com', }; // 仓库侧前端地址(通知文案快速查看链接) config.frontendUrl = 'http://wms.wms.gztbyc.com'; // 货主侧前端地址(货主群通知使用,与仓库侧不同) config.storeFrontendUrl = 'http://store.wms.gztbyc.com'; config.printRetryCompensation = { enable: false, intervalMs: 60 * 1000, batchSize: 50, force: false, }; // 工作台 token 超期强制下线定时任务配置 config.workbenchTokenExpire = { enable: true, // 扫描间隔(毫秒),默认每小时扫描一次;开发环境可在 config.local.js 覆盖为短循环 scanIntervalMs: 60 * 60 * 1000, // token 有效期阈值(毫秒):token_updated_at 距今超过该时长则强制下线(默认 3 个月,按 30 天/月折算) maxAgeMs: 3 * 30 * 24 * 60 * 60 * 1000, // 单轮批处理大小(按 id 升序分批) batchSize: 50, }; // 微信用户须知版本清理定时任务配置(每 1 小时执行,真实删除未使用且非最终版的历史版本释放磁盘空间) config.wechatAgreementCleanup = { // 开关:false 时不注册本定时任务 enable: true, // 触发 cron(秒 分 时 日 月 周):默认每 1 小时整点;本地环境可在 config.local.js 覆盖为短间隔 cron: '0 0 * * * *', // 单批硬删除行数(按 id 分批,走主键索引) batchSize: 500, }; // 配送表(dispatch) → 历史表(history) 归档定时任务配置 // 每日凌晨 06:00 把配送表超期订单(连同商品明细)迁入历史表,并更新订单索引表位置指针 config.orderDeliveryArchive = { // 开关:false 时不注册本定时任务 enable: true, // 触发 cron(秒 分 时 日 月 周):默认每日凌晨 06:00;本地环境可在 config.local.js 覆盖为短间隔 cron: '0 0 6 * * *', // 归档门槛一:订单创建时间(create_at)距今超过该月数即归档(dispath_time 为 NULL 的存量单只靠此条) archiveAfterMonths: 4, // 归档门槛二:迁移进配送表时间(dispath_time)距今超过该月数即归档 dispatchStayMonths: 3, // 单批条数(单批一个事务:写历史表 + 更新位置指针 + 删源行) batchSize: 1000, // 单仓库单轮最多批次数(异常情况下防死循环) maxBatchesPerWarehouse: 200, // 单轮总时长上限(毫秒):用尽后停止本轮,剩余订单下一轮继续(避免闯入业务高峰) maxRunMs: 30 * 60 * 1000, // 单批查询超时(毫秒) queryTimeoutMs: 60 * 1000, // 单批事务遇到死锁/锁等待的最大尝试次数 batchMaxAttempts: 3, // 跨进程互斥锁 TTL(秒),需覆盖单轮最长执行时间;进程被杀后锁到期自动释放 lockTtlSeconds: 30 * 60, }; // 打印自定义区模板出口域名 config.customAreaBaseUrl = 'https://api.ye4s.com'; // 仓库前端独立部署:证书部署目录。 // 保存接口(setting.warehouse.saveFrontCert)已不再写暂存文件,证书/私钥内容直接入库; // 该目录保留供未来定时任务(Egg schedule 或外部 crontab)从库内 cert_pem/cert_key 读取内容后写 nginx 证书目录使用。 config.frontConfig = { certStagingDir: '/data/wms/cert-staging', // 前端独立部署:域名验证(DNS TXT 校验) cname: '', // 用户把域名 CNAME 指向的目标(未验证时返回给前端展示) domainVerify: { enable: true, // 是否注册域名验证定时任务 interval: '10m', // 扫描间隔 lockTtlSeconds: 600, // Redis 跨进程锁 TTL(略大于 interval) // 单轮最多处理行数:单行最坏耗时 ≈ (DoH 端点数 3 + 系统 DNS 兜底 1) × timeoutMs(3000ms) = 12s, // 20 行最坏 ≈ 240s,明显小于 lockTtlSeconds(600s) 与扫描间隔 interval(600s),跨进程锁不会被下一轮抢走 batchSize: 20, // DoH 端点列表(多端点按序尝试,任一端点拿到 TXT 值即立即返回,不再询问后续端点): // 1) https://dns.alidns.com/resolve 阿里公共 DNS 的 JSON 接口,默认主解析器; // 2) https://223.5.5.5/resolve 阿里公共 DNS 的 IP 直连入口(同一后端,域名侧解析异常时兜底); // 3) https://doh.pub/dns-query 腾讯 doh.pub,保留但置于最后。 // 为什么把 doh.pub 放最后:其负缓存(NODATA)可能长时间滞后于权威服务器。 // 实测案例:主机 wmsv-aa4adaab13.wms.wms.gztbyc.com 的 TXT 记录 ddd9ae51cf95b488db544f23ccd01e7b 真实存在 // (8.8.8.8 / 223.5.5.5 / nslookup / AliDNS DoH 四方一致),而 doh.pub 返回 Status=0 且 Answer 为空 // (同一主机 A 查询亦 NODATA,其 SOA 序列号 2026081813 旧于 TXT 查询的 2026082815),重复两次结果一致。 dohUrls: [ 'https://dns.alidns.com/resolve', 'https://223.5.5.5/resolve', 'https://doh.pub/dns-query', ], // 兼容键(历史单端点配置):dohUrls 缺失/非法时 getDomainVerifyConfig() 回退用 [dohUrl];多端点生效后不应再依赖本键 dohUrl: 'https://doh.pub/dns-query', // 单个 DoH 端点、以及系统 DNS 兜底单次查询的超时(毫秒) timeoutMs: 3000, maxAttempts: 20, // 超过后不再自动重试(仍可手动 checkDomain) }, }; return { ...config, ...userConfig, }; };