2026-09-15 16:37:39 +08:00
|
|
|
|
package schema
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
|
"entgo.io/ent"
|
|
|
|
|
|
"entgo.io/ent/schema/field"
|
|
|
|
|
|
"entgo.io/ent/schema/index"
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
// Attachment 附件(挂载在业务单据/档案上的文件)
|
|
|
|
|
|
//
|
|
|
|
|
|
// 客户诉求(问题记录 L30):"列表可以查看附件、上传附件"——入库单/物料档案/检验记录
|
|
|
|
|
|
// 都要能挂图纸 PDF、检验报告、成品资料。故用统一单表,biz_type 区分挂载对象:
|
|
|
|
|
|
//
|
|
|
|
|
|
// biz_type=inbound biz_id=入库单号(inbound_no)
|
|
|
|
|
|
// biz_type=material biz_id=物料编码(material.code)
|
|
|
|
|
|
// biz_type=inspection biz_id=检验记录ID(inspection_records.id)
|
|
|
|
|
|
// biz_type=semi biz_id=半成品 SN
|
|
|
|
|
|
// biz_type=outbound biz_id=出库单号
|
|
|
|
|
|
//
|
2026-09-19 10:54:15 +08:00
|
|
|
|
// 磁盘落盘约定(2026-09-19 重构):<根目录>/年/月/日/<文件类型大写>/<uuid>.<ext>,
|
|
|
|
|
|
// file_path 存相对路径(如 2026/09/19/INSPECTION_PHOTO/xxx.jpg),不存绝对路径;
|
|
|
|
|
|
// 根目录由 etc/*.yaml 的 Attachment.RootDir 提供,不硬编码。
|
|
|
|
|
|
// 预览/下载走 GET /uploads/<相对路径>(服务端限根目录内,阻断穿越)。
|
|
|
|
|
|
// 文件类型(file_type,大写枚举)决定所在目录:PROCESS_PDF/INSPECTION_PHOTO/INSPECTION_PDF/
|
|
|
|
|
|
// DRAWING/PROCESS_CARD/PACKAGE_PHOTO/EXCEL_IMPORT/OTHER;biz_type 仍表示挂载的业务对象类型。
|
2026-09-15 16:37:39 +08:00
|
|
|
|
type Attachment struct {
|
|
|
|
|
|
ent.Schema
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (Attachment) Fields() []ent.Field {
|
|
|
|
|
|
return []ent.Field{
|
|
|
|
|
|
field.String("biz_type").Comment("业务类型 inbound/material/inspection/semi/outbound"),
|
|
|
|
|
|
field.String("biz_id").Comment("业务对象标识(单号/编码/ID)"),
|
|
|
|
|
|
field.String("file_name").Comment("原始文件名(含扩展名)"),
|
2026-09-19 10:54:15 +08:00
|
|
|
|
// file_path 现为相对路径(年/月/日/文件类型/uuid.ext),历史扁平文件名仍兼容
|
|
|
|
|
|
field.String("file_path").Comment("磁盘相对路径(年/月/日/文件类型/uuid.ext)"),
|
|
|
|
|
|
// 文件类型(大写枚举),决定存储目录;与 biz_type(业务对象)正交
|
|
|
|
|
|
field.String("file_type").Optional().Comment("文件类型大写枚举 PROCESS_PDF/INSPECTION_PHOTO/..."),
|
|
|
|
|
|
field.String("file_ext").Optional().Comment("扩展名(小写,不含点)"),
|
|
|
|
|
|
field.String("file_md5").Optional().Comment("文件MD5(秒传/去重)"),
|
2026-09-15 16:37:39 +08:00
|
|
|
|
field.Int64("file_size").Default(0).Comment("文件大小(字节)"),
|
|
|
|
|
|
field.String("mime_type").Optional().Comment("MIME 类型"),
|
|
|
|
|
|
field.String("uploaded_by").Optional().Comment("上传人"),
|
2026-09-19 10:54:15 +08:00
|
|
|
|
field.Bool("archived").Default(false).Comment("是否已归档(备份到外部存储)"),
|
|
|
|
|
|
field.Int64("archived_at").Optional().Comment("归档时间(unix秒)"),
|
|
|
|
|
|
field.Bool("deleted").Default(false).Comment("逻辑删除标记"),
|
|
|
|
|
|
field.Int64("deleted_at").Optional().Comment("删除时间(unix秒)"),
|
|
|
|
|
|
field.String("deleted_by").Optional().Comment("删除人"),
|
2026-09-15 16:37:39 +08:00
|
|
|
|
field.Int64("created_at").DefaultFunc(nowUnix),
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (Attachment) Indexes() []ent.Index {
|
|
|
|
|
|
return []ent.Index{
|
|
|
|
|
|
index.Fields("biz_type", "biz_id"),
|
2026-09-19 10:54:15 +08:00
|
|
|
|
index.Fields("file_type"),
|
|
|
|
|
|
index.Fields("file_md5"),
|
|
|
|
|
|
index.Fields("created_at"),
|
2026-09-15 16:37:39 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|