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"), } }