feat: 新增预警定时扫描器,移除附件归档字段并为角色表补充更新时间

This commit is contained in:
SunYF
2026-10-31 15:41:27 +08:00
parent 11dbdaae75
commit 0c03d32682
107 changed files with 10790 additions and 1844 deletions
+58 -3
View File
@@ -9,6 +9,55 @@ import (
)
var (
// AlertsColumns holds the columns for the "alerts" table.
AlertsColumns = []*schema.Column{
{Name: "id", Type: field.TypeInt, Increment: true},
{Name: "rule_code", Type: field.TypeString, Comment: "关联规则编码(固定五类)"},
{Name: "level", Type: field.TypeString, Size: 16, Comment: "级别 info/warning/error", Default: "warning"},
{Name: "title", Type: field.TypeString, Comment: "预警标题"},
{Name: "content", Type: field.TypeString, Comment: "预警内容"},
{Name: "target", Type: field.TypeString, Nullable: true, Comment: "关联对象(物料编码/批次/SN/库存行ID等)"},
{Name: "status", Type: field.TypeString, Size: 16, Comment: "状态 unread/read", Default: "unread"},
{Name: "created_at", Type: field.TypeInt64, Comment: "创建时间"},
{Name: "updated_at", Type: field.TypeInt64, Comment: "更新时间"},
}
// AlertsTable holds the schema information for the "alerts" table.
AlertsTable = &schema.Table{
Name: "alerts",
Comment: "Alert 预警实例:扫描器按规则产生,用户标记已读闭环",
Columns: AlertsColumns,
PrimaryKey: []*schema.Column{AlertsColumns[0]},
Indexes: []*schema.Index{
{
Name: "alert_status",
Unique: false,
Columns: []*schema.Column{AlertsColumns[6]},
},
{
Name: "alert_rule_code",
Unique: false,
Columns: []*schema.Column{AlertsColumns[1]},
},
},
}
// AlertRulesColumns holds the columns for the "alert_rules" table.
AlertRulesColumns = []*schema.Column{
{Name: "id", Type: field.TypeInt, Increment: true},
{Name: "code", Type: field.TypeString, Unique: true, Comment: "规则编码(唯一,固定五类)"},
{Name: "name", Type: field.TypeString, Comment: "规则名称"},
{Name: "enabled", Type: field.TypeBool, Comment: "是否启用", Default: true},
{Name: "threshold", Type: field.TypeInt, Comment: "阈值(含义随规则:超期小时/库龄天;0=按默认)", Default: 0},
{Name: "remark", Type: field.TypeString, Nullable: true, Comment: "备注"},
{Name: "created_at", Type: field.TypeInt64, Comment: "创建时间"},
{Name: "updated_at", Type: field.TypeInt64, Comment: "更新时间"},
}
// AlertRulesTable holds the schema information for the "alert_rules" table.
AlertRulesTable = &schema.Table{
Name: "alert_rules",
Comment: "AlertRule 预警规则:控制各类预警是否启用与阈值",
Columns: AlertRulesColumns,
PrimaryKey: []*schema.Column{AlertRulesColumns[0]},
}
// AttachmentsColumns holds the columns for the "attachments" table.
AttachmentsColumns = []*schema.Column{
{Name: "id", Type: field.TypeInt, Increment: true},
@@ -22,8 +71,6 @@ var (
{Name: "file_size", Type: field.TypeInt64, Comment: "文件大小(字节)", Default: 0},
{Name: "mime_type", Type: field.TypeString, Nullable: true, Comment: "MIME 类型"},
{Name: "uploaded_by", Type: field.TypeString, Nullable: true, Comment: "上传人"},
{Name: "archived", Type: field.TypeBool, Comment: "是否已归档(备份到外部存储)", Default: false},
{Name: "archived_at", Type: field.TypeInt64, Nullable: true, Comment: "归档时间(unix秒)"},
{Name: "deleted", Type: field.TypeBool, Comment: "逻辑删除标记", Default: false},
{Name: "deleted_at", Type: field.TypeInt64, Nullable: true, Comment: "删除时间(unix秒)"},
{Name: "deleted_by", Type: field.TypeString, Nullable: true, Comment: "删除人"},
@@ -57,7 +104,7 @@ var (
{
Name: "attachment_created_at",
Unique: false,
Columns: []*schema.Column{AttachmentsColumns[19]},
Columns: []*schema.Column{AttachmentsColumns[17]},
},
},
}
@@ -869,6 +916,8 @@ var (
}
// Tables holds all the tables in the schema.
Tables = []*schema.Table{
AlertsTable,
AlertRulesTable,
AttachmentsTable,
BackupRecordTable,
EventLogTable,
@@ -895,6 +944,12 @@ var (
)
func init() {
AlertsTable.Annotation = &entsql.Annotation{
Table: "alerts",
}
AlertRulesTable.Annotation = &entsql.Annotation{
Table: "alert_rules",
}
AttachmentsTable.Annotation = &entsql.Annotation{
Table: "attachments",
}