44 lines
1.6 KiB
Go
44 lines
1.6 KiB
Go
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=出库单号
|
||
|
|
//
|
||
|
|
// 磁盘落盘约定:uploads/<uuid><ext>(纯 ASCII 文件名,避免中文 URL 编码问题),
|
||
|
|
// 原始文件名存 file_name,预览走静态路由 GET /uploads/:name。
|
||
|
|
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("原始文件名(含扩展名)"),
|
||
|
|
field.String("file_path").Comment("磁盘相对文件名(uuid+ext)"),
|
||
|
|
field.Int64("file_size").Default(0).Comment("文件大小(字节)"),
|
||
|
|
field.String("mime_type").Optional().Comment("MIME 类型"),
|
||
|
|
field.String("uploaded_by").Optional().Comment("上传人"),
|
||
|
|
field.Int64("created_at").DefaultFunc(nowUnix),
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
func (Attachment) Indexes() []ent.Index {
|
||
|
|
return []ent.Index{
|
||
|
|
index.Fields("biz_type", "biz_id"),
|
||
|
|
}
|
||
|
|
}
|