Files
bj_power/bj_power_mes/schema/attachment.go
T

57 lines
2.6 KiB
Go
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.
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 统一方案):<Upload.Dir>/年/月/日/<文件类型大写枚举>/<uuid>.<ext>,
// 库内 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"}, entsql.WithComments(true), schema.Comment("Attachment 业务附件:图纸 / 照片 / 文档等,按 bizType+bizId 关联业务单据。")}
}
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("deleted").Default(false).Comment("逻辑删除"),
field.Int64("deletedAt").Default(0).Comment("删除时间(unix秒)"),
field.String("deletedBy").Default("").MaxLen(64).Comment("删除人"),
field.String("deletedReason").Default("").MaxLen(255).Comment("删除说明(删除弹窗填写,警示留痕)"),
field.Int64("purgedAt").Default(0).Comment("彻底清除时间(unix秒,仅删文件留索引)"),
field.String("purgedBy").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"),
}
}