WMS_MAIN/app/model/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

113 lines
3.2 KiB
JavaScript
Raw 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 等设备端通过 index.uploadClientErrorLog 上报的运行时错误日志暂存,
* 仅做数据落库供人工/后台查询分析;report_uuid 唯一索引承担幂等去重(重复上报静默成功)。
* created_at/updated_at 由 Sequelize 时间戳统一取服务器当前时间,不采信客户端时间。
*
* @param {import('egg').Application} app Egg 应用实例。
* @return {import('sequelize').ModelCtor<import('sequelize').Model>} Sequelize 模型。
*/
module.exports = app => {
const { BIGINT, STRING, DATE, TEXT } = app.Sequelize;
const ClientErrorLog = app.model.define('client_error_log', {
id: {
type: BIGINT(20).UNSIGNED,
primaryKey: true,
autoIncrement: true,
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: '更新时间',
},
}, {
tableName: 'wms_client_error_log',
underscored: true,
timestamps: true,
createdAt: 'created_at',
updatedAt: 'updated_at',
paranoid: false,
comment: '客户端错误日志暂存表(设备端运行时错误上报暂存)',
indexes: [
{ name: 'uk_report_uuid', unique: true, fields: [ 'report_uuid' ] },
{ name: 'idx_created_at', fields: [ 'created_at' ] },
{ name: 'idx_client_type_app_version', fields: [ 'client_type', 'app_version' ] },
{ name: 'idx_device_id', fields: [ 'device_id' ] },
],
});
return ClientErrorLog;
};