feat: 新增预警与附件模块,优化工位派工功能

1. 新增预警规则、预警消息、业务附件数据库表与CRUD逻辑
2. 为拧紧记录添加审核人、审核时间字段及审核留痕功能
3. 优化产线点位类型与编号描述,更新工位组合下发菜单名称为工艺路线派工
4. 新增上传文件获取原文件名与大小的工具方法
5. 在系统管理菜单新增预警中心与附件中心入口
This commit is contained in:
SunYF
2026-09-14 16:31:08 +08:00
parent 0ab21b1234
commit 5c3b747a20
399 changed files with 147674 additions and 2213 deletions
+43
View File
@@ -0,0 +1,43 @@
package schema
import (
"time"
"entgo.io/ent"
"entgo.io/ent/dialect/entsql"
"entgo.io/ent/schema"
"entgo.io/ent/schema/field"
"entgo.io/ent/schema/index"
)
// Alert 预警消息:规则命中或手动触发后写入,供前端预警中心收件箱展示
type Alert struct {
ent.Schema
}
func (Alert) Annotations() []schema.Annotation {
return []schema.Annotation{entsql.Annotation{Table: "alert"}}
}
func (Alert) Fields() []ent.Field {
return []ent.Field{
field.Int("id").Positive(),
field.Int("ruleId").Default(0).Comment("关联规则ID,0=手动触发"),
field.String("type").MaxLen(40).Comment("预警类型"),
field.String("title").MaxLen(120).Comment("标题"),
field.String("content").Default("").MaxLen(500).Comment("内容"),
field.String("refType").Default("").MaxLen(40).Comment("关联业务类型"),
field.String("refId").Default("").MaxLen(64).Comment("关联业务ID"),
field.String("status").Default("UNREAD").MaxLen(10).Comment("UNREAD/READ"),
field.String("receiver").Default("").MaxLen(255).Comment("接收人"),
field.Time("createdAt").Default(time.Now).Immutable(),
}
}
func (Alert) Indexes() []ent.Index {
return []ent.Index{
index.Fields("status"),
index.Fields("type"),
index.Fields("createdAt"),
}
}
+40
View File
@@ -0,0 +1,40 @@
package schema
import (
"time"
"entgo.io/ent"
"entgo.io/ent/dialect/entsql"
"entgo.io/ent/schema"
"entgo.io/ent/schema/field"
"entgo.io/ent/schema/index"
)
// AlertRule 预警规则:按类型 + 阈值触发,命中后写入 alert 消息表
type AlertRule struct {
ent.Schema
}
func (AlertRule) Annotations() []schema.Annotation {
return []schema.Annotation{entsql.Annotation{Table: "alert_rule"}}
}
func (AlertRule) Fields() []ent.Field {
return []ent.Field{
field.Int("id").Positive(),
field.String("name").MaxLen(80).Comment("规则名称"),
field.String("type").MaxLen(40).Comment("预警类型 torque_ng/inspection_ng/inventory_low/task_overdue"),
field.Float("threshold").Default(0).Comment("阈值(不同类含义不同)"),
field.String("receiver").Default("").MaxLen(255).Comment("接收人,逗号分隔"),
field.Bool("enabled").Default(true).Comment("是否启用"),
field.String("createdBy").Default("").MaxLen(64).Comment("创建人"),
field.Time("createdAt").Default(time.Now).Immutable(),
}
}
func (AlertRule) Indexes() []ent.Index {
return []ent.Index{
index.Fields("type"),
index.Fields("enabled"),
}
}
+40
View File
@@ -0,0 +1,40 @@
package schema
import (
"time"
"entgo.io/ent"
"entgo.io/ent/dialect/entsql"
"entgo.io/ent/schema"
"entgo.io/ent/schema/field"
"entgo.io/ent/schema/index"
)
// Attachment 业务附件:图纸 / 照片 / 文档等,按 bizType+bizId 关联业务单据
type Attachment struct {
ent.Schema
}
func (Attachment) Annotations() []schema.Annotation {
return []schema.Annotation{entsql.Annotation{Table: "attachment"}}
}
func (Attachment) Fields() []ent.Field {
return []ent.Field{
field.Int("id").Positive(),
field.String("bizType").MaxLen(40).Comment("业务类型 work_order/material/process_flow/inspection"),
field.String("bizId").MaxLen(64).Comment("业务ID"),
field.String("fileName").MaxLen(255).Comment("原始文件名"),
field.String("filePath").MaxLen(255).Comment("上传目录相对路径"),
field.Int("fileSize").Default(0).Comment("字节数"),
field.String("uploader").Default("").MaxLen(64).Comment("上传人"),
field.Time("createdAt").Default(time.Now).Immutable(),
}
}
func (Attachment) Indexes() []ent.Index {
return []ent.Index{
index.Fields("bizType", "bizId"),
index.Fields("createdAt"),
}
}
+41
View File
@@ -0,0 +1,41 @@
package schema
import (
"time"
"entgo.io/ent"
"entgo.io/ent/dialect/entsql"
"entgo.io/ent/schema"
"entgo.io/ent/schema/field"
"entgo.io/ent/schema/index"
)
// TorqueAuditLog 拧紧记录修改留痕(审核签字 / 补录 / 修正,谁在何时改了什么)
type TorqueAuditLog struct {
ent.Schema
}
func (TorqueAuditLog) Annotations() []schema.Annotation {
return []schema.Annotation{entsql.Annotation{Table: "torque_audit_log"}}
}
func (TorqueAuditLog) Fields() []ent.Field {
return []ent.Field{
field.Int("id").Positive(),
field.Int("torqueRecordId").Comment("拧紧记录ID"),
field.String("action").MaxLen(20).Comment("审核/补录/修正"),
field.String("fieldName").Default("").MaxLen(40).Comment("字段名"),
field.String("oldVal").Default("").MaxLen(255).Comment("改前"),
field.String("newVal").Default("").MaxLen(255).Comment("改后"),
field.String("operator").MaxLen(64).Comment("操作人"),
field.String("remark").Default("").MaxLen(255).Comment("备注/原因"),
field.Time("createdAt").Default(time.Now).Immutable(),
}
}
func (TorqueAuditLog) Indexes() []ent.Index {
return []ent.Index{
index.Fields("torqueRecordId"),
index.Fields("createdAt"),
}
}
+3
View File
@@ -33,6 +33,9 @@ func (TorqueRecord) Fields() []ent.Field {
field.String("operator").Default("").MaxLen(64).Comment("操作人"),
field.String("stationNo").Default("").MaxLen(32).Comment("工位"),
field.Time("time").Default(time.Now).Comment("采集时间"),
// 审核签字
field.String("auditBy").Default("").MaxLen(64).Comment("审核人"),
field.Time("auditAt").Optional().Comment("审核时间"),
field.Time("createdAt").Default(time.Now).Immutable(),
}
}