初始化2
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
package schema
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect"
|
||||
"entgo.io/ent/dialect/entsql"
|
||||
"entgo.io/ent/schema"
|
||||
"entgo.io/ent/schema/field"
|
||||
"entgo.io/ent/schema/index"
|
||||
)
|
||||
|
||||
// AssociationTrace 成品追溯关联:成品SN ↔ 结构件批次 + 精密件SN
|
||||
type AssociationTrace struct {
|
||||
ent.Schema
|
||||
}
|
||||
|
||||
func (AssociationTrace) Annotations() []schema.Annotation {
|
||||
return []schema.Annotation{entsql.Annotation{Table: "association_trace"}}
|
||||
}
|
||||
|
||||
func (AssociationTrace) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.Int("id").Positive(),
|
||||
field.String("finishedSn").Unique().MaxLen(64).Comment("成品SN(主件)"),
|
||||
field.String("orderNo").Default("").MaxLen(64),
|
||||
field.String("processCode").Default("").MaxLen(64).Comment("成品的工序组合"),
|
||||
field.JSON("batchItems", []string{}).Optional().SchemaType(map[string]string{
|
||||
dialect.Postgres: "jsonb",
|
||||
}).Comment("结构件批次号列表"),
|
||||
field.JSON("serialItems", []string{}).Optional().SchemaType(map[string]string{
|
||||
dialect.Postgres: "jsonb",
|
||||
}).Comment("精密件SN码列表"),
|
||||
field.String("operator").Default("").MaxLen(64).Comment("完工关联登记人"),
|
||||
field.Time("createdAt").Default(time.Now).Immutable(),
|
||||
}
|
||||
}
|
||||
|
||||
func (AssociationTrace) Indexes() []ent.Index {
|
||||
return []ent.Index{index.Fields("finishedSn").Unique()}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package schema
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect"
|
||||
"entgo.io/ent/dialect/entsql"
|
||||
"entgo.io/ent/schema"
|
||||
"entgo.io/ent/schema/field"
|
||||
"entgo.io/ent/schema/index"
|
||||
)
|
||||
|
||||
// BomItem 工单 BOM 明细
|
||||
type BomItem struct {
|
||||
ent.Schema
|
||||
}
|
||||
|
||||
func (BomItem) Annotations() []schema.Annotation {
|
||||
return []schema.Annotation{entsql.Annotation{Table: "work_order_bom"}}
|
||||
}
|
||||
|
||||
func (BomItem) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.Int("id").Positive(),
|
||||
field.String("workOrderNo").MaxLen(64).Comment("工单号"),
|
||||
field.String("materialCode").MaxLen(64).Comment("物料编码"),
|
||||
field.String("materialName").Default("").MaxLen(128),
|
||||
field.String("spec").Default("").MaxLen(128),
|
||||
field.String("unit").Default("").MaxLen(16),
|
||||
// 1 批次(结构件) / 2 序列号(精密件)
|
||||
field.String("manageMode").Default("2").MaxLen(10),
|
||||
field.Float("unitQty").Default(0).Comment("单台用量"),
|
||||
field.Float("lossRate").Default(0).Comment("损耗率%"),
|
||||
field.Float("requiredQty").Default(0).Comment("需求总量=总台数*单台*(1+损耗)"),
|
||||
field.JSON("serialSns", []string{}).Optional().SchemaType(map[string]string{
|
||||
dialect.Postgres: "jsonb",
|
||||
}).Comment("精密件SN下发列表(可选)"),
|
||||
field.Time("createdAt").Default(time.Now).Immutable(),
|
||||
}
|
||||
}
|
||||
|
||||
func (BomItem) Indexes() []ent.Index {
|
||||
return []ent.Index{
|
||||
index.Fields("workOrderNo"),
|
||||
index.Fields("workOrderNo", "materialCode").Unique(),
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
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"
|
||||
)
|
||||
|
||||
// DailyPlan 日排产:仅预告,不触发出库/领料
|
||||
type DailyPlan struct {
|
||||
ent.Schema
|
||||
}
|
||||
|
||||
func (DailyPlan) Annotations() []schema.Annotation {
|
||||
return []schema.Annotation{entsql.Annotation{Table: "daily_plan"}}
|
||||
}
|
||||
|
||||
func (DailyPlan) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.Int("id").Positive(),
|
||||
field.String("orderNo").MaxLen(64).Comment("工单号"),
|
||||
field.String("planDate").MaxLen(10).Comment("排产日期 yyyy-MM-dd"),
|
||||
field.Int("planQty").Default(0).Comment("计划数量"),
|
||||
field.Int("completedQty").Default(0).Comment("已完成数量"),
|
||||
// PENDING / PROCESSING / DONE
|
||||
field.String("status").Default("PENDING").MaxLen(20),
|
||||
field.String("operator").Default("").MaxLen(64),
|
||||
field.Time("createdAt").Default(time.Now).Immutable(),
|
||||
field.Time("updatedAt").Default(time.Now).UpdateDefault(time.Now).Optional().Nillable(),
|
||||
}
|
||||
}
|
||||
|
||||
func (DailyPlan) Indexes() []ent.Index {
|
||||
return []ent.Index{
|
||||
index.Fields("orderNo"),
|
||||
index.Fields("planDate"),
|
||||
index.Fields("planDate", "orderNo").Unique(),
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package schema
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect"
|
||||
"entgo.io/ent/dialect/entsql"
|
||||
"entgo.io/ent/schema"
|
||||
"entgo.io/ent/schema/field"
|
||||
"entgo.io/ent/schema/index"
|
||||
)
|
||||
|
||||
// EventLog 操作日志:必须含 workOrderNo(工单号)、operator(操作人)
|
||||
type EventLog struct {
|
||||
ent.Schema
|
||||
}
|
||||
|
||||
func (EventLog) Annotations() []schema.Annotation {
|
||||
return []schema.Annotation{entsql.Annotation{Table: "event_log"}}
|
||||
}
|
||||
|
||||
func (EventLog) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.Int("id").Positive(),
|
||||
field.String("eventType").MaxLen(50).Comment("事件类型,如 work.order.create"),
|
||||
field.String("workOrderNo").MaxLen(64).Default("").Comment("关联工单号"),
|
||||
field.String("operator").MaxLen(64).Default("").Comment("操作人"),
|
||||
field.String("entityType").Default("").MaxLen(30).Comment("实体类型"),
|
||||
field.String("entityId").Default("").MaxLen(50).Comment("实体标识"),
|
||||
field.Text("description").Default("").Comment("描述"),
|
||||
field.JSON("payload", map[string]any{}).Optional().SchemaType(map[string]string{
|
||||
dialect.Postgres: "jsonb",
|
||||
}).Comment("载荷"),
|
||||
field.Time("createdAt").Default(time.Now).Immutable().Comment("创建时间"),
|
||||
}
|
||||
}
|
||||
|
||||
func (EventLog) Indexes() []ent.Index {
|
||||
return []ent.Index{
|
||||
index.Fields("eventType"),
|
||||
index.Fields("workOrderNo"),
|
||||
index.Fields("operator"),
|
||||
index.Fields("createdAt"),
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package schema
|
||||
|
||||
import _ "entgo.io/ent/entc"
|
||||
|
||||
//go:generate go run ./tools/generate.go
|
||||
@@ -0,0 +1,48 @@
|
||||
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"
|
||||
)
|
||||
|
||||
// MaterialRequest 备料单:按日排产自动算料生成
|
||||
type MaterialRequest struct {
|
||||
ent.Schema
|
||||
}
|
||||
|
||||
func (MaterialRequest) Annotations() []schema.Annotation {
|
||||
return []schema.Annotation{entsql.Annotation{Table: "material_request"}}
|
||||
}
|
||||
|
||||
func (MaterialRequest) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.Int("id").Positive(),
|
||||
field.String("requestNo").MaxLen(64).Comment("备料单号"),
|
||||
field.String("orderNo").MaxLen(64).Comment("工单号"),
|
||||
field.String("planDate").MaxLen(10).Comment("对应排产日"),
|
||||
field.String("materialCode").MaxLen(64).Comment("物料编码"),
|
||||
field.String("materialName").Default("").MaxLen(128),
|
||||
field.String("unit").Default("").MaxLen(16),
|
||||
field.String("manageMode").Default("2").MaxLen(10),
|
||||
field.Float("reqQty").Default(0).Comment("需备数量"),
|
||||
// PENDING / LOCKED / DELIVERING / DONE
|
||||
field.String("status").Default("PENDING").MaxLen(20),
|
||||
field.String("targetDock").Default("").MaxLen(20).Comment("目标接驳台 DOCK01..20"),
|
||||
field.String("operator").Default("").MaxLen(64),
|
||||
field.Time("createdAt").Default(time.Now).Immutable(),
|
||||
field.Time("updatedAt").Default(time.Now).UpdateDefault(time.Now).Optional().Nillable(),
|
||||
}
|
||||
}
|
||||
|
||||
func (MaterialRequest) Indexes() []ent.Index {
|
||||
return []ent.Index{
|
||||
index.Fields("orderNo"),
|
||||
index.Fields("materialCode"),
|
||||
index.Fields("status"),
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
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"
|
||||
)
|
||||
|
||||
// Permission 权限/菜单
|
||||
type Permission struct {
|
||||
ent.Schema
|
||||
}
|
||||
|
||||
func (Permission) Annotations() []schema.Annotation {
|
||||
return []schema.Annotation{entsql.Annotation{Table: "permission"}}
|
||||
}
|
||||
|
||||
func (Permission) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.Int("id").Positive(),
|
||||
field.String("code").Unique().MaxLen(64).Comment("权限编码"),
|
||||
field.String("name").MaxLen(64).Comment("名称"),
|
||||
// MENU / BUTTON
|
||||
field.String("type").Default("MENU").MaxLen(20),
|
||||
field.String("path").Default("").MaxLen(128).Comment("前端路由"),
|
||||
field.String("icon").Default("").MaxLen(64),
|
||||
field.Int("sort").Default(0).Optional(),
|
||||
field.String("remark").Default("").MaxLen(255),
|
||||
field.Time("createdAt").Default(time.Now).Immutable(),
|
||||
}
|
||||
}
|
||||
|
||||
func (Permission) Indexes() []ent.Index {
|
||||
return []ent.Index{index.Fields("code").Unique()}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
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"
|
||||
)
|
||||
|
||||
// PlcSendLog PLC 工序码下发日志
|
||||
type PlcSendLog struct {
|
||||
ent.Schema
|
||||
}
|
||||
|
||||
func (PlcSendLog) Annotations() []schema.Annotation {
|
||||
return []schema.Annotation{entsql.Annotation{Table: "plc_send_log"}}
|
||||
}
|
||||
|
||||
func (PlcSendLog) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.Int("id").Positive(),
|
||||
field.String("orderNo").Default("").MaxLen(64).Comment("工单号"),
|
||||
field.String("sn").Default("").MaxLen(64).Comment("工件SN"),
|
||||
field.Int("stationNo").Optional().Comment("工位号"),
|
||||
field.String("processCombination").Default("").MaxLen(64).Comment("工序组合,如 135"),
|
||||
field.JSON("processCodes", []int{}).Optional().Comment("工序码表"),
|
||||
// PENDING / SENT / DONE / TIMEOUT / REPLY_NG
|
||||
field.String("status").Default("PENDING").MaxLen(20),
|
||||
field.Time("sendTime").Optional().Nillable().Comment("下发时间"),
|
||||
field.Time("doneTime").Optional().Nillable().Comment("收到完成信号时间"),
|
||||
field.Bool("ack").Default(false).Comment("是否收到完成信号"),
|
||||
field.String("remark").Default("").MaxLen(255),
|
||||
field.String("operator").Default("").MaxLen(64),
|
||||
field.Time("createdAt").Default(time.Now).Immutable(),
|
||||
}
|
||||
}
|
||||
|
||||
func (PlcSendLog) Indexes() []ent.Index {
|
||||
return []ent.Index{
|
||||
index.Fields("orderNo"),
|
||||
index.Fields("sn"),
|
||||
index.Fields("status"),
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
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"
|
||||
)
|
||||
|
||||
// ProcessStep 工序步骤模板:一道工序包含多个采集/考核步骤
|
||||
type ProcessStep struct {
|
||||
ent.Schema
|
||||
}
|
||||
|
||||
func (ProcessStep) Annotations() []schema.Annotation {
|
||||
return []schema.Annotation{entsql.Annotation{Table: "process_step"}}
|
||||
}
|
||||
|
||||
func (ProcessStep) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.Int("id").Positive(),
|
||||
field.Int("processCode").Comment("工序代码"),
|
||||
field.Int("seq").Default(1).Comment("步骤序号"),
|
||||
field.String("name").MaxLen(128).Comment("步骤名称"),
|
||||
field.String("collectType").Default("NONE").MaxLen(20).Comment("AUTO/MANUAL/NONE"),
|
||||
field.Bool("isTorque").Default(false).Comment("是否拧紧采集"),
|
||||
field.String("remark").Default("").MaxLen(255),
|
||||
field.Time("createdAt").Default(time.Now).Immutable(),
|
||||
}
|
||||
}
|
||||
|
||||
func (ProcessStep) Indexes() []ent.Index {
|
||||
return []ent.Index{index.Fields("processCode")}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
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"
|
||||
)
|
||||
|
||||
// ProductType 产品类型
|
||||
type ProductType struct {
|
||||
ent.Schema
|
||||
}
|
||||
|
||||
func (ProductType) Annotations() []schema.Annotation {
|
||||
return []schema.Annotation{entsql.Annotation{Table: "product_type"}}
|
||||
}
|
||||
|
||||
func (ProductType) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.Int("id").Positive(),
|
||||
field.String("name").MaxLen(50).Comment("产品名称"),
|
||||
field.String("code").MaxLen(20).Comment("产品代号"),
|
||||
field.String("category").Default("").MaxLen(30).Comment("产品分类"),
|
||||
field.String("remark").Default("").MaxLen(255),
|
||||
field.Bool("isActive").Default(true),
|
||||
field.Time("createdAt").Default(time.Now).Immutable(),
|
||||
field.Time("updatedAt").Default(time.Now).UpdateDefault(time.Now).Optional().Nillable(),
|
||||
}
|
||||
}
|
||||
|
||||
func (ProductType) Indexes() []ent.Index {
|
||||
return []ent.Index{
|
||||
index.Fields("code"),
|
||||
index.Fields("isActive"),
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package schema
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect"
|
||||
"entgo.io/ent/dialect/entsql"
|
||||
"entgo.io/ent/schema"
|
||||
"entgo.io/ent/schema/field"
|
||||
"entgo.io/ent/schema/index"
|
||||
)
|
||||
|
||||
// Role 角色:承载菜单/按钮权限
|
||||
type Role struct {
|
||||
ent.Schema
|
||||
}
|
||||
|
||||
func (Role) Annotations() []schema.Annotation {
|
||||
return []schema.Annotation{entsql.Annotation{Table: "role"}}
|
||||
}
|
||||
|
||||
func (Role) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.Int("id").Positive(),
|
||||
field.String("name").MaxLen(64).Comment("角色名称"),
|
||||
field.String("code").Unique().MaxLen(64).Comment("角色编码"),
|
||||
field.String("remark").Default("").MaxLen(255),
|
||||
field.JSON("permissionCodes", []string{}).Optional().SchemaType(map[string]string{
|
||||
dialect.Postgres: "jsonb",
|
||||
}).Comment("权限编码列表,如 produce.workorder:view"),
|
||||
field.Time("createdAt").Default(time.Now).Immutable(),
|
||||
}
|
||||
}
|
||||
|
||||
func (Role) Indexes() []ent.Index {
|
||||
return []ent.Index{index.Fields("code").Unique()}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
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"
|
||||
)
|
||||
|
||||
// ScanRecord 扫码报工记录(station,sn,orderNo,type,operator,time)
|
||||
type ScanRecord struct {
|
||||
ent.Schema
|
||||
}
|
||||
|
||||
func (ScanRecord) Annotations() []schema.Annotation {
|
||||
return []schema.Annotation{entsql.Annotation{Table: "scan_record"}}
|
||||
}
|
||||
|
||||
func (ScanRecord) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.Int("id").Positive(),
|
||||
field.String("station").Default("").MaxLen(32).Comment("工位/扫码点"),
|
||||
field.String("sn").MaxLen(64).Comment("工件SN"),
|
||||
field.String("orderNo").Default("").MaxLen(64).Comment("工单号"),
|
||||
// ONLINE(进线) / PROCESS(工序报工) / DONE(完工) / TEMP_STORE(暂存)
|
||||
field.String("type").Default("PROCESS").MaxLen(20).Comment("报工类型"),
|
||||
field.Int("processCode").Optional().Comment("工序号 1~12"),
|
||||
field.String("operator").Default("").MaxLen(64).Comment("操作人"),
|
||||
field.Time("time").Default(time.Now).Comment("报工时间"),
|
||||
field.Time("createdAt").Default(time.Now).Immutable(),
|
||||
}
|
||||
}
|
||||
|
||||
func (ScanRecord) Indexes() []ent.Index {
|
||||
return []ent.Index{
|
||||
index.Fields("station"),
|
||||
index.Fields("sn"),
|
||||
index.Fields("orderNo"),
|
||||
index.Fields("createdAt"),
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
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"
|
||||
)
|
||||
|
||||
// SemiFlow 半成品流转记录:记录已完成工序,调用 WMS /api/internal/semi/*
|
||||
type SemiFlow struct {
|
||||
ent.Schema
|
||||
}
|
||||
|
||||
func (SemiFlow) Annotations() []schema.Annotation {
|
||||
return []schema.Annotation{entsql.Annotation{Table: "semi_flow"}}
|
||||
}
|
||||
|
||||
func (SemiFlow) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.Int("id").Positive(),
|
||||
field.String("sn").MaxLen(64).Comment("工件SN"),
|
||||
field.String("orderNo").Default("").MaxLen(64),
|
||||
field.JSON("doneProcessCodes", []int{}).Optional().Comment("已完成工序码"),
|
||||
// INBOUND / OUTBOUND
|
||||
field.String("action").Default("INBOUND").MaxLen(20),
|
||||
field.String("targetDock").Default("").MaxLen(20),
|
||||
field.String("operator").Default("").MaxLen(64),
|
||||
field.Time("createdAt").Default(time.Now).Immutable(),
|
||||
}
|
||||
}
|
||||
|
||||
func (SemiFlow) Indexes() []ent.Index {
|
||||
return []ent.Index{
|
||||
index.Fields("sn"),
|
||||
index.Fields("orderNo"),
|
||||
index.Fields("action"),
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
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"
|
||||
)
|
||||
|
||||
// StationProcess 工位↔工序 派工(当日/班次可换)
|
||||
type StationProcess struct {
|
||||
ent.Schema
|
||||
}
|
||||
|
||||
func (StationProcess) Annotations() []schema.Annotation {
|
||||
return []schema.Annotation{entsql.Annotation{Table: "station_process"}}
|
||||
}
|
||||
|
||||
func (StationProcess) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.Int("id").Positive(),
|
||||
field.Int("stationNo").Comment("工位号 1..12"),
|
||||
field.Int("processCode").Comment("工序代码"),
|
||||
field.String("effectDate").Default("").MaxLen(10).Comment("生效日期"),
|
||||
field.String("shift").Default("").MaxLen(20).Comment("班次"),
|
||||
field.String("operator").Default("").MaxLen(64),
|
||||
field.Time("createdAt").Default(time.Now).Immutable(),
|
||||
}
|
||||
}
|
||||
|
||||
func (StationProcess) Indexes() []ent.Index {
|
||||
return []ent.Index{
|
||||
index.Fields("stationNo"),
|
||||
index.Fields("effectDate"),
|
||||
index.Fields("stationNo", "effectDate"),
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
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"
|
||||
)
|
||||
|
||||
// StepCriterion 工序步骤考核标准:如 扭矩在RANGE[35,45] 自动判定 OK
|
||||
type StepCriterion struct {
|
||||
ent.Schema
|
||||
}
|
||||
|
||||
func (StepCriterion) Annotations() []schema.Annotation {
|
||||
return []schema.Annotation{entsql.Annotation{Table: "step_criterion"}}
|
||||
}
|
||||
|
||||
func (StepCriterion) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.Int("id").Positive(),
|
||||
field.Int("stepId").Comment("步骤ID"),
|
||||
field.String("name").MaxLen(64).Comment("指标名,如 扭矩/角度"),
|
||||
field.String("unit").Default("").MaxLen(16),
|
||||
// GE / LE / GT / LT / RANGE / EQUAL / NONE
|
||||
field.String("logic").Default("NONE").MaxLen(16),
|
||||
field.Float("target").Default(0).Comment("目标值"),
|
||||
field.Float("min").Optional().Nillable().Comment("范围下限"),
|
||||
field.Float("max").Optional().Nillable().Comment("范围上限"),
|
||||
field.Time("createdAt").Default(time.Now).Immutable(),
|
||||
}
|
||||
}
|
||||
|
||||
func (StepCriterion) Indexes() []ent.Index {
|
||||
return []ent.Index{index.Fields("stepId")}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
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"
|
||||
)
|
||||
|
||||
// StepData 步骤考核数据:某工件某工序步骤采集/手填实际值,按考核标准判定 OK/NG
|
||||
type StepData struct {
|
||||
ent.Schema
|
||||
}
|
||||
|
||||
func (StepData) Annotations() []schema.Annotation {
|
||||
return []schema.Annotation{entsql.Annotation{Table: "step_data"}}
|
||||
}
|
||||
|
||||
func (StepData) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.Int("id").Positive(),
|
||||
field.String("sn").MaxLen(64).Comment("工件SN"),
|
||||
field.Int("processId").Optional().Comment("工件工序实绩ID"),
|
||||
field.Int("stepId").Comment("步骤ID"),
|
||||
field.String("stepName").Default("").MaxLen(128),
|
||||
field.Int("criterionId").Optional().Comment("考核标准ID"),
|
||||
field.String("criterionName").Default("").MaxLen(64),
|
||||
field.String("criterionLogic").Default("NONE").MaxLen(16),
|
||||
field.Float("value").Default(0).Comment("实际测量值"),
|
||||
field.String("valueText").Default("").MaxLen(64).Comment("文本值(OK/NG/钢印号)"),
|
||||
field.Bool("isOK").Default(true).Comment("是否合格(可人工修正)"),
|
||||
field.String("operator").Default("").MaxLen(64),
|
||||
field.Time("createdAt").Default(time.Now).Immutable(),
|
||||
}
|
||||
}
|
||||
|
||||
func (StepData) Indexes() []ent.Index {
|
||||
return []ent.Index{
|
||||
index.Fields("sn"),
|
||||
index.Fields("processId"),
|
||||
index.Fields("stepId"),
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
//go:build ignore
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
|
||||
"entgo.io/ent/entc"
|
||||
"entgo.io/ent/entc/gen"
|
||||
)
|
||||
|
||||
func main() {
|
||||
if err := entc.Generate(
|
||||
".",
|
||||
&gen.Config{
|
||||
Target: "../ent",
|
||||
Package: "bj_power_mes/ent",
|
||||
Features: []gen.Feature{
|
||||
gen.FeatureExecQuery,
|
||||
gen.FeatureLock,
|
||||
gen.FeatureModifier,
|
||||
gen.FeatureNamedEdges,
|
||||
},
|
||||
}); err != nil {
|
||||
log.Fatal("running ent codegen:", err)
|
||||
}
|
||||
log.Println("ent code generated successfully!")
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
//go:build ignore
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"flag"
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
"bj_power_mes/ent"
|
||||
"bj_power_mes/internal/db"
|
||||
|
||||
"entgo.io/ent/dialect"
|
||||
entsql "entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/schema"
|
||||
_ "github.com/jackc/pgx/v5/stdlib"
|
||||
"github.com/zeromicro/go-zero/core/conf"
|
||||
)
|
||||
|
||||
// 建表工具:DSN 一律从 etc 配置文件读取,不硬编码
|
||||
// 用法(在 bj_power_mes 目录下):go run schema/tools/migrate.go
|
||||
|
||||
var (
|
||||
client *ent.Client
|
||||
|
||||
ctx = context.Background()
|
||||
configFile = flag.String("config", "etc/bj_power_mes-api.yaml", "配置文件路径")
|
||||
)
|
||||
|
||||
// migrateConf 与主配置结构一致,只取 Database 段
|
||||
type migrateConf struct {
|
||||
Database db.DatabaseConf
|
||||
}
|
||||
|
||||
func setUp() {
|
||||
var c migrateConf
|
||||
conf.MustLoad(*configFile, &c)
|
||||
|
||||
dsn := fmt.Sprintf("host=%s port=%d user=%s password=%s dbname=%s sslmode=disable",
|
||||
c.Database.Host, c.Database.Port, c.Database.User, c.Database.Password, c.Database.Dbname)
|
||||
db, err := sql.Open("pgx", dsn)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
if _, err = db.Query("select 1"); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
drv := entsql.OpenDB(dialect.Postgres, db)
|
||||
client = ent.NewClient(ent.Driver(drv))
|
||||
}
|
||||
|
||||
func tearDown() {
|
||||
if client != nil {
|
||||
_ = client.Close()
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
flag.Parse()
|
||||
setUp()
|
||||
defer tearDown()
|
||||
|
||||
// 只建新表/加列,不删列,保证生产数据安全
|
||||
if err := client.Debug().Schema.Create(
|
||||
context.Background(),
|
||||
schema.WithDropIndex(true),
|
||||
schema.WithDropColumn(false),
|
||||
schema.WithDialect(dialect.Postgres),
|
||||
schema.WithForeignKeys(false),
|
||||
); err != nil {
|
||||
log.Fatalf("failed creating schema resources: %v", err)
|
||||
}
|
||||
log.Println("schemas migrated successfully!")
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
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"
|
||||
)
|
||||
|
||||
// TorqueRecord 拧紧数据(工位终端上报,sn,strain扭矩,angle角度,result,operator,workOrder,time)
|
||||
type TorqueRecord struct {
|
||||
ent.Schema
|
||||
}
|
||||
|
||||
func (TorqueRecord) Annotations() []schema.Annotation {
|
||||
return []schema.Annotation{entsql.Annotation{Table: "torque_record"}}
|
||||
}
|
||||
|
||||
func (TorqueRecord) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.Int("id").Positive(),
|
||||
field.String("workOrderNo").Default("").MaxLen(64).Comment("workOrder 工单号"),
|
||||
field.String("sn").MaxLen(64).Comment("工件SN"),
|
||||
field.String("screwNo").Default("").MaxLen(32).Comment("螺丝编号 S1..Sn"),
|
||||
field.Float("strain").Default(0).Comment("扭矩 Nm"),
|
||||
field.Float("torque").Default(0).Comment("扭矩别名,与 strain 一致"),
|
||||
field.Float("angle").Default(0).Comment("角度 °"),
|
||||
// OK / NG
|
||||
field.String("result").Default("OK").MaxLen(10),
|
||||
field.String("operator").Default("").MaxLen(64).Comment("操作人"),
|
||||
field.String("stationNo").Default("").MaxLen(32).Comment("工位"),
|
||||
field.Time("time").Default(time.Now).Comment("采集时间"),
|
||||
field.Time("createdAt").Default(time.Now).Immutable(),
|
||||
}
|
||||
}
|
||||
|
||||
func (TorqueRecord) Indexes() []ent.Index {
|
||||
return []ent.Index{
|
||||
index.Fields("sn"),
|
||||
index.Fields("workOrderNo"),
|
||||
index.Fields("createdAt"),
|
||||
index.Fields("time"),
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
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"
|
||||
)
|
||||
|
||||
// User 用户
|
||||
type User struct {
|
||||
ent.Schema
|
||||
}
|
||||
|
||||
func (User) Annotations() []schema.Annotation {
|
||||
return []schema.Annotation{entsql.Annotation{Table: "user"}}
|
||||
}
|
||||
|
||||
func (User) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.Int("id").Positive(),
|
||||
field.String("username").Unique().MaxLen(64).Comment("登录名"),
|
||||
field.String("password").MaxLen(128).Comment("bcrypt 密码"),
|
||||
field.String("name").Default("").MaxLen(64).Comment("姓名/显示名"),
|
||||
field.Int("roleId").Optional().Comment("角色ID"),
|
||||
// ENABLED / DISABLED
|
||||
field.String("status").Default("ENABLED").MaxLen(20),
|
||||
field.Time("createdAt").Default(time.Now).Immutable(),
|
||||
field.Time("updatedAt").Default(time.Now).UpdateDefault(time.Now).Optional().Nillable(),
|
||||
}
|
||||
}
|
||||
|
||||
func (User) Indexes() []ent.Index {
|
||||
return []ent.Index{
|
||||
index.Fields("username").Unique(),
|
||||
index.Fields("roleId"),
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
package schema
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect"
|
||||
"entgo.io/ent/dialect/entsql"
|
||||
"entgo.io/ent/schema"
|
||||
"entgo.io/ent/schema/field"
|
||||
"entgo.io/ent/schema/index"
|
||||
)
|
||||
|
||||
// WorkOrder 工单:一个合同 = 一个工单
|
||||
type WorkOrder struct {
|
||||
ent.Schema
|
||||
}
|
||||
|
||||
func (WorkOrder) Annotations() []schema.Annotation {
|
||||
return []schema.Annotation{entsql.Annotation{Table: "work_order"}}
|
||||
}
|
||||
|
||||
func (WorkOrder) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.Int("id").Positive(),
|
||||
field.String("workOrderNo").MaxLen(64).Comment("工单号"),
|
||||
field.Int("productTypeId").Comment("产品类型ID"),
|
||||
field.String("productCode").Default("").MaxLen(64).Comment("产品编码"),
|
||||
field.String("productName").Default("").MaxLen(128),
|
||||
field.Int("quantity").Default(1).Comment("工件数量"),
|
||||
field.Int("finishedNum").Default(0).Comment("完成数量"),
|
||||
field.Int("failNum").Default(0).Comment("NG数量"),
|
||||
field.String("processSeq").Default("").MaxLen(64).Comment("工序组合,如 135"),
|
||||
// CREATED / RELEASED / IN_PROGRESS / COMPLETED / CLOSED
|
||||
field.String("status").Default("CREATED").MaxLen(20),
|
||||
field.Time("planStart").Optional().Nillable().Comment("计划开始"),
|
||||
field.Time("planEnd").Optional().Nillable().Comment("计划结束"),
|
||||
field.JSON("context", map[string]any{}).Optional().SchemaType(map[string]string{
|
||||
dialect.Postgres: "jsonb",
|
||||
}).Comment("扩展字段"),
|
||||
field.Time("completedAt").Optional().Nillable(),
|
||||
field.Time("createdAt").Default(time.Now).Immutable(),
|
||||
field.Time("updatedAt").Default(time.Now).UpdateDefault(time.Now).Optional().Nillable(),
|
||||
}
|
||||
}
|
||||
|
||||
func (WorkOrder) Indexes() []ent.Index {
|
||||
return []ent.Index{
|
||||
index.Fields("workOrderNo").Unique(),
|
||||
index.Fields("status"),
|
||||
index.Fields("productTypeId"),
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
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"
|
||||
)
|
||||
|
||||
// Workpiece 工件(SN):序列号管理的成品/主件
|
||||
type Workpiece struct {
|
||||
ent.Schema
|
||||
}
|
||||
|
||||
func (Workpiece) Annotations() []schema.Annotation {
|
||||
return []schema.Annotation{entsql.Annotation{Table: "workpiece"}}
|
||||
}
|
||||
|
||||
func (Workpiece) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.Int("id").Positive(),
|
||||
field.String("sn").Unique().MaxLen(64).Comment("工件唯一SN"),
|
||||
field.String("orderNo").Default("").MaxLen(64).Comment("所属工单"),
|
||||
field.Int("workOrderId").Optional().Comment("工单ID"),
|
||||
field.String("processSeq").Default("").MaxLen(64).Comment("工序组合,如 135"),
|
||||
field.Int("currentProcess").Optional().Comment("当前进行到的工序码"),
|
||||
// ONLINE(已进线) / PROCESSING(在工位) / DONE(完工) / REPAIR / SCRAPPED
|
||||
field.String("status").Default("ONLINE").MaxLen(20),
|
||||
field.Time("onlineAt").Optional().Nillable().Comment("进线时间"),
|
||||
field.Time("doneAt").Optional().Nillable().Comment("完工时间"),
|
||||
field.Time("createdAt").Default(time.Now).Immutable(),
|
||||
field.Time("updatedAt").Default(time.Now).UpdateDefault(time.Now).Optional().Nillable(),
|
||||
}
|
||||
}
|
||||
|
||||
func (Workpiece) Indexes() []ent.Index {
|
||||
return []ent.Index{
|
||||
index.Fields("sn").Unique(),
|
||||
index.Fields("orderNo"),
|
||||
index.Fields("status"),
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
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"
|
||||
)
|
||||
|
||||
// WorkpieceProcess 工件-工序实绩(某工件在某工位完成某道工序的一次记录,构成工序时间线)
|
||||
type WorkpieceProcess struct {
|
||||
ent.Schema
|
||||
}
|
||||
|
||||
func (WorkpieceProcess) Annotations() []schema.Annotation {
|
||||
return []schema.Annotation{entsql.Annotation{Table: "workpiece_process"}}
|
||||
}
|
||||
|
||||
func (WorkpieceProcess) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.Int("id").Positive(),
|
||||
field.String("sn").MaxLen(64).Comment("工件SN"),
|
||||
field.Int("processCode").Comment("工序代码"),
|
||||
field.String("stationNo").Default("").MaxLen(32).Comment("工位号"),
|
||||
field.String("orderNo").Default("").MaxLen(64),
|
||||
field.String("processName").Default("").MaxLen(64),
|
||||
// PENDING / DOING / DONE / NG / REPAIRED
|
||||
field.String("status").Default("DONE").MaxLen(20),
|
||||
field.String("operator").Default("").MaxLen(64),
|
||||
field.String("result").Default("OK").MaxLen(10).Comment("总判定 OK/NG"),
|
||||
field.Time("startedAt").Optional().Nillable(),
|
||||
field.Time("endedAt").Optional().Nillable(),
|
||||
field.String("remark").Default("").MaxLen(255),
|
||||
field.Time("createdAt").Default(time.Now).Immutable(),
|
||||
}
|
||||
}
|
||||
|
||||
func (WorkpieceProcess) Indexes() []ent.Index {
|
||||
return []ent.Index{
|
||||
index.Fields("sn"),
|
||||
index.Fields("sn", "processCode"),
|
||||
index.Fields("orderNo"),
|
||||
index.Fields("stationNo"),
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user