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 关联业务单据。 // 存储落地约定(2026-09-19 统一方案):/年/月/日/<文件类型大写枚举>/., // 库内 filePath 只存相对路径(如 2026/09/19/INSPECTION_PHOTO/xxx.jpg),不存绝对路径。 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(), // 文件类型(大写枚举):决定存储目录分层,与 bizType(业务对象)正交 field.String("fileType").Default("OTHER").MaxLen(32).Comment("文件类型 大写枚举 PROCESS_PDF/INSPECTION_PHOTO/..."), field.String("fileExt").Default("").MaxLen(16).Comment("扩展名(小写,不含点)"), field.String("fileMd5").Default("").MaxLen(64).Comment("文件MD5(秒传/去重)"), field.String("mimeType").Default("").MaxLen(128).Comment("MIME类型"), // 归档 / 逻辑删除:物理文件由归档任务统一处理,库内保留索引可追溯 field.Bool("archived").Default(false).Comment("是否已归档"), field.Int64("archivedAt").Default(0).Comment("归档时间(unix秒)"), field.Bool("deleted").Default(false).Comment("逻辑删除"), field.Int64("deletedAt").Default(0).Comment("删除时间(unix秒)"), field.String("deletedBy").Default("").MaxLen(64).Comment("删除人"), } } func (Attachment) Indexes() []ent.Index { return []ent.Index{ index.Fields("bizType", "bizId"), index.Fields("createdAt"), index.Fields("fileType"), index.Fields("fileMd5"), } }