WMS_MAIN/database/migrations/20260925100000-create-wms-client-error-log.js
liufumingren 943c096c5a feat(index): 新增客户端错误日志上报接口 uploadClientErrorLog(建表 wms_client_error_log)
新增免登录/免权限/免鉴权的设备端运行时错误批量上报接口,保留系统日志:

- 建表迁移 database/migrations/20260925100000-create-wms-client-error-log.js(wms_client_error_log,uk_report_uuid 唯一索引幂等去重)
- 新增模型 app/model/client_error_log.js 与服务 app/service/systems/client_error_log.js(三种入参形态、字段归一化与长度截断、report_uuid 幂等;bulkCreate 用 validate:false 修复时间戳注入引发的 notNull 写入失败)
- systemMethods/index.js 新增 uploadClientErrorLog 出口并登记 _noNeedLogin/_noNeedRight/_noNeedAuth;_noNeedLog 由 '*' 改为显式清单 INDEX_NO_NEED_LOG_METHODS
- 文档同步:methods/system.json 版本升至 0.3.190、methods/changes/system.json 新增变更记录、AI_METHOD_ROUTING.md 补充 5.9 能力速查并同步第 6 节方法清单
- 测试:32 个服务层用例与 18 个 HTTP 回归用例通过(test/ 与 test_reports/ 按 .gitignore 约定不入库)
2026-09-25 03:14:15 +08:00

116 lines
3.6 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

'use strict';
/**
* 创建客户端错误日志暂存表 wms_client_error_log。
*
* 背景:Android/iOS/Web 等设备端将运行时错误日志上报到服务端暂存,
* 供人工/后台查询分析跟踪 bug。接口入口 index.uploadClientErrorLog
* (免登录、免权限、免鉴权,保留系统日志)。
*
* 字段:客户端类型/版本、设备标识、系统版本/型号、错误类型、错误信息与堆栈、
* 附加上下文 extra、report_uuid(客户端生成,唯一索引幂等去重)、
* client_time(客户端发生时间,仅参考)、created_at(服务端写入时间)。
*
* 索引:idx_created_at、idx_client_type_app_version、idx_device_id、uk_report_uuid(唯一)。
*/
const TABLE_NAME = 'wms_client_error_log';
module.exports = {
// eslint-disable-next-line no-unused-vars
async up(queryInterface, Sequelize) {
const { BIGINT, STRING, DATE, TEXT } = Sequelize;
await queryInterface.createTable(TABLE_NAME, {
id: {
type: BIGINT(20).UNSIGNED,
primaryKey: true,
autoIncrement: true,
allowNull: false,
comment: '主键ID',
},
client_type: {
type: STRING(32),
allowNull: false,
defaultValue: '',
comment: '客户端类型:android/ios/web 等',
},
app_version: {
type: STRING(64),
allowNull: false,
defaultValue: '',
comment: '客户端版本号',
},
device_id: {
type: STRING(128),
allowNull: false,
defaultValue: '',
comment: '设备唯一标识',
},
os_version: {
type: STRING(64),
allowNull: false,
defaultValue: '',
comment: '操作系统版本',
},
device_model: {
type: STRING(128),
allowNull: false,
defaultValue: '',
comment: '设备型号',
},
error_type: {
type: STRING(64),
allowNull: false,
defaultValue: '',
comment: '错误类型/等级',
},
error_message: {
type: TEXT,
allowNull: true,
comment: '错误信息(服务端截断上限 5000 字符)',
},
error_stack: {
type: TEXT('medium'),
allowNull: true,
comment: '错误堆栈(服务端截断上限 65535 字符)',
},
extra: {
type: TEXT,
allowNull: true,
comment: '附加上下文(JSON 字符串,服务端截断上限 65535 字符)',
},
report_uuid: {
type: STRING(64),
allowNull: false,
defaultValue: '',
comment: '客户端上报幂等ID(唯一索引,重复上报静默成功)',
},
client_time: {
type: DATE,
allowNull: true,
comment: '客户端错误发生时间(仅参考,不作为记录时间)',
},
created_at: {
type: DATE,
allowNull: false,
comment: '服务端写入时间(统一取服务器当前时间)',
},
updated_at: {
type: DATE,
allowNull: false,
comment: '更新时间',
},
});
await queryInterface.addIndex(TABLE_NAME, [ 'created_at' ], { name: 'idx_created_at' });
await queryInterface.addIndex(TABLE_NAME, [ 'client_type', 'app_version' ], { name: 'idx_client_type_app_version' });
await queryInterface.addIndex(TABLE_NAME, [ 'device_id' ], { name: 'idx_device_id' });
await queryInterface.addIndex(TABLE_NAME, [ 'report_uuid' ], { name: 'uk_report_uuid', unique: true });
},
// eslint-disable-next-line no-unused-vars
async down(queryInterface, Sequelize) {
await queryInterface.dropTable(TABLE_NAME);
},
};