@@ -921,7 +932,7 @@ async function onMaterialFile(e) {
查询
- 新增物料
+ 新增物料档案导入导出
@@ -983,7 +994,7 @@ async function onMaterialFile(e) {
@size-change="(s) => { matPage.size = s; matPage.current = 1; loadMaterials() }" />
-
diff --git a/bj_power_wms/internal/handler/zone.go b/bj_power_wms/internal/handler/zone.go
index 6bdd7ed..2e8094c 100644
--- a/bj_power_wms/internal/handler/zone.go
+++ b/bj_power_wms/internal/handler/zone.go
@@ -463,7 +463,8 @@ type zoneBatchGenReq struct {
PosEnd int `json:"posEnd"`
Level int `json:"level"` // 3=批量生成层(level3) 4=批量生成位置号(level4,默认,需指定已存在的层)
Preview bool `json:"preview"`
- Layers []zoneBatchLayerName `json:"layers"` // level=3 提交时携带预览表中(可能手改过的)层名称,非空则优先采用
+ Layers []zoneBatchLayerName `json:"layers"` // level=3 提交时携带预览表中(可能手改过的)层名称,非空则优先采用
+ Positions []zoneBatchPosName `json:"positions"` // level=4 提交时携带预览表中(可能手改过的)位置名称,非空则优先采用
}
// zoneBatchLayerName 批量生成层:前端预览后手改的层名称(layerNo→layerName)
@@ -472,6 +473,12 @@ type zoneBatchLayerName struct {
LayerName string `json:"layerName"`
}
+// zoneBatchPosName 批量生成位置号:前端预览后手改的位置名称(positionNo→positionName)
+type zoneBatchPosName struct {
+ PositionNo string `json:"positionNo"`
+ PositionName string `json:"positionName"`
+}
+
// batchGenerateHandler 批量生成库位节点:选区域→货架→范围,先预览后提交。
// level=3:只生成「层」节点(按层范围);level=4(默认):在「已存在的具体层」下生成「位置号」节点。
// 批量生成只生成自己这一级,绝不自动创建父级;已存在的节点跳过不重复建。
@@ -610,6 +617,15 @@ func batchGenerateHandler(ctx *svc.ServiceContext) http.HandlerFunc {
}
// 提交:仅在选定层下创建不存在的位置号(层必须已存在,不再自动创建父级层)
+ // 手改位置名称优先:前端预览后可点击位置名称修改,提交时按 positionNo 带回
+ nameByPos := make(map[string]string, len(req.Positions))
+ for _, pn := range req.Positions {
+ no := strings.TrimSpace(pn.PositionNo)
+ nm := strings.TrimSpace(pn.PositionName)
+ if no != "" && nm != "" {
+ nameByPos[no] = nm
+ }
+ }
created, skipped := 0, 0
for _, p := range poss {
ps := strconv.Itoa(p)
@@ -619,10 +635,14 @@ func batchGenerateHandler(ctx *svc.ServiceContext) http.HandlerFunc {
skipped++
continue
}
+ name := req.ShelfNo + "架" + layerNo + "层" + ps + "位"
+ if v, ok := nameByPos[ps]; ok {
+ name = v
+ }
if _, err := ctx.EntClient.Zone.Create().
SetLevel(4).SetCode(ps).SetParentCode(layerNo).
SetZoneCode(zoneCode).SetShelfNo(req.ShelfNo).SetLayerNo(layerNo).SetPositionNo(ps).
- SetName(req.ShelfNo + "架" + layerNo + "层" + ps + "位").SetStatus("启用").Save(ctx0()); err != nil {
+ SetName(name).SetStatus("启用").Save(ctx0()); err != nil {
fail(w, http.StatusInternalServerError, "创建位置失败: "+err.Error())
return
}
diff --git a/bj_power_wms/schema/agv_task.go b/bj_power_wms/schema/agv_task.go
index debd7e9..683e10e 100644
--- a/bj_power_wms/schema/agv_task.go
+++ b/bj_power_wms/schema/agv_task.go
@@ -2,6 +2,8 @@ package schema
import (
"entgo.io/ent"
+ "entgo.io/ent/dialect/entsql"
+ "entgo.io/ent/schema"
"entgo.io/ent/schema/field"
"entgo.io/ent/schema/index"
)
@@ -12,6 +14,9 @@ type AgvTask struct {
ent.Schema
}
+func (AgvTask) Annotations() []schema.Annotation {
+ return []schema.Annotation{entsql.Table("agv_tasks"), entsql.WithComments(true), schema.Comment("AgvTask AGV 搬运任务记录:仓管下发后落库,用于状态跟踪/追溯。")}
+}
func (AgvTask) Fields() []ent.Field {
return []ent.Field{
field.String("task_no").Unique().MaxLen(64).Comment("我方任务号(内部)"),
@@ -38,4 +43,4 @@ func (AgvTask) Indexes() []ent.Index {
index.Fields("status"),
index.Fields("hik_task_code"),
}
-}
\ No newline at end of file
+}
diff --git a/bj_power_wms/schema/attachment.go b/bj_power_wms/schema/attachment.go
index 7b41808..a7ede94 100644
--- a/bj_power_wms/schema/attachment.go
+++ b/bj_power_wms/schema/attachment.go
@@ -2,6 +2,8 @@ package schema
import (
"entgo.io/ent"
+ "entgo.io/ent/dialect/entsql"
+ "entgo.io/ent/schema"
"entgo.io/ent/schema/field"
"entgo.io/ent/schema/index"
)
@@ -27,6 +29,9 @@ type Attachment struct {
ent.Schema
}
+func (Attachment) Annotations() []schema.Annotation {
+ return []schema.Annotation{entsql.Table("attachments"), entsql.WithComments(true), schema.Comment("Attachment 附件(挂载在业务单据/档案上的文件)")}
+}
func (Attachment) Fields() []ent.Field {
return []ent.Field{
field.String("biz_type").Comment("业务类型 inbound/material/inspection/semi/outbound"),
diff --git a/bj_power_wms/schema/event_log.go b/bj_power_wms/schema/event_log.go
index ba63f5e..24a44ae 100644
--- a/bj_power_wms/schema/event_log.go
+++ b/bj_power_wms/schema/event_log.go
@@ -20,7 +20,7 @@ type EventLog struct {
}
func (EventLog) Annotations() []schema.Annotation {
- return []schema.Annotation{entsql.Annotation{Table: "event_log"}}
+ return []schema.Annotation{entsql.Table("event_log"), entsql.WithComments(true), schema.Comment("EventLog 操作日志(事件审计)")}
}
func (EventLog) Fields() []ent.Field {
diff --git a/bj_power_wms/schema/inbound_detail.go b/bj_power_wms/schema/inbound_detail.go
index e17ab1e..38aeb68 100644
--- a/bj_power_wms/schema/inbound_detail.go
+++ b/bj_power_wms/schema/inbound_detail.go
@@ -2,6 +2,8 @@ package schema
import (
"entgo.io/ent"
+ "entgo.io/ent/dialect/entsql"
+ "entgo.io/ent/schema"
"entgo.io/ent/schema/field"
"entgo.io/ent/schema/index"
)
@@ -13,6 +15,9 @@ type InboundDetail struct {
ent.Schema
}
+func (InboundDetail) Annotations() []schema.Annotation {
+ return []schema.Annotation{entsql.Table("inbound_details"), entsql.WithComments(true), schema.Comment("InboundDetail 入库明细(一张入库单可含多行)")}
+}
func (InboundDetail) Fields() []ent.Field {
return []ent.Field{
field.String("inbound_no").Comment("入库单号"),
diff --git a/bj_power_wms/schema/inbound_order.go b/bj_power_wms/schema/inbound_order.go
index 1659622..8b3338d 100644
--- a/bj_power_wms/schema/inbound_order.go
+++ b/bj_power_wms/schema/inbound_order.go
@@ -2,6 +2,8 @@ package schema
import (
"entgo.io/ent"
+ "entgo.io/ent/dialect/entsql"
+ "entgo.io/ent/schema"
"entgo.io/ent/schema/field"
"entgo.io/ent/schema/index"
)
@@ -11,6 +13,9 @@ type InboundOrder struct {
ent.Schema
}
+func (InboundOrder) Annotations() []schema.Annotation {
+ return []schema.Annotation{entsql.Table("inbound_orders"), entsql.WithComments(true), schema.Comment("InboundOrder 入库单")}
+}
func (InboundOrder) Fields() []ent.Field {
return []ent.Field{
field.String("inbound_no").Unique().Comment("入库单号"),
diff --git a/bj_power_wms/schema/inspection_record.go b/bj_power_wms/schema/inspection_record.go
index eae0955..fe01ac4 100644
--- a/bj_power_wms/schema/inspection_record.go
+++ b/bj_power_wms/schema/inspection_record.go
@@ -2,6 +2,8 @@ package schema
import (
"entgo.io/ent"
+ "entgo.io/ent/dialect/entsql"
+ "entgo.io/ent/schema"
"entgo.io/ent/schema/field"
"entgo.io/ent/schema/index"
)
@@ -12,6 +14,9 @@ type InspectionRecord struct {
ent.Schema
}
+func (InspectionRecord) Annotations() []schema.Annotation {
+ return []schema.Annotation{entsql.Table("inspection_records"), entsql.WithComments(true), schema.Comment("InspectionRecord 检验记录")}
+}
func (InspectionRecord) Fields() []ent.Field {
return []ent.Field{
// 检验对象:BATCH/SN
diff --git a/bj_power_wms/schema/inventory.go b/bj_power_wms/schema/inventory.go
index 8dc690d..2549dbf 100644
--- a/bj_power_wms/schema/inventory.go
+++ b/bj_power_wms/schema/inventory.go
@@ -2,6 +2,8 @@ package schema
import (
"entgo.io/ent"
+ "entgo.io/ent/dialect/entsql"
+ "entgo.io/ent/schema"
"entgo.io/ent/schema/field"
"entgo.io/ent/schema/index"
)
@@ -38,6 +40,9 @@ const (
InvCategoryFinished = 3
)
+func (Inventory) Annotations() []schema.Annotation {
+ return []schema.Annotation{entsql.Table("inventories"), entsql.WithComments(true), schema.Comment("Inventory 统一库存台账")}
+}
func (Inventory) Fields() []ent.Field {
return []ent.Field{
// 类型(分类语境:结构件/电气件/其他,仅用于分类统计/筛选,2026-09-30 与记账方式解耦)
diff --git a/bj_power_wms/schema/inventory_lock.go b/bj_power_wms/schema/inventory_lock.go
index 7b12215..8e350c1 100644
--- a/bj_power_wms/schema/inventory_lock.go
+++ b/bj_power_wms/schema/inventory_lock.go
@@ -2,6 +2,8 @@ package schema
import (
"entgo.io/ent"
+ "entgo.io/ent/dialect/entsql"
+ "entgo.io/ent/schema"
"entgo.io/ent/schema/field"
"entgo.io/ent/schema/index"
)
@@ -11,6 +13,9 @@ type InventoryLock struct {
ent.Schema
}
+func (InventoryLock) Annotations() []schema.Annotation {
+ return []schema.Annotation{entsql.Table("inventory_locks"), entsql.WithComments(true), schema.Comment("InventoryLock 库存锁定(工单锁库存,防超卖)")}
+}
func (InventoryLock) Fields() []ent.Field {
return []ent.Field{
// 锁定对象:批次或 SN
diff --git a/bj_power_wms/schema/material.go b/bj_power_wms/schema/material.go
index 23abf6d..dfb770b 100644
--- a/bj_power_wms/schema/material.go
+++ b/bj_power_wms/schema/material.go
@@ -2,6 +2,8 @@ package schema
import (
"entgo.io/ent"
+ "entgo.io/ent/dialect/entsql"
+ "entgo.io/ent/schema"
"entgo.io/ent/schema/field"
"entgo.io/ent/schema/index"
)
@@ -28,6 +30,9 @@ type Material struct {
ent.Schema
}
+func (Material) Annotations() []schema.Annotation {
+ return []schema.Annotation{entsql.Table("materials"), entsql.WithComments(true), schema.Comment("Material 物料档案(主数据)")}
+}
func (Material) Fields() []ent.Field {
return []ent.Field{
field.String("code").Unique().Comment("物料唯一编码"),
diff --git a/bj_power_wms/schema/material_demand.go b/bj_power_wms/schema/material_demand.go
index bb8deb7..08612f2 100644
--- a/bj_power_wms/schema/material_demand.go
+++ b/bj_power_wms/schema/material_demand.go
@@ -2,6 +2,8 @@ package schema
import (
"entgo.io/ent"
+ "entgo.io/ent/dialect/entsql"
+ "entgo.io/ent/schema"
"entgo.io/ent/schema/field"
)
@@ -14,6 +16,9 @@ type MaterialDemand struct {
ent.Schema
}
+func (MaterialDemand) Annotations() []schema.Annotation {
+ return []schema.Annotation{entsql.Table("material_demands"), entsql.WithComments(true), schema.Comment("MaterialDemand 物料未来需求(MES 按日排产推送,WMS 备料四态“预警”判定的数据源)")}
+}
func (MaterialDemand) Fields() []ent.Field {
return []ent.Field{
field.String("material_code").Unique().Comment("物料编码(图号)"),
diff --git a/bj_power_wms/schema/order_material_ledger.go b/bj_power_wms/schema/order_material_ledger.go
index d837b69..401ac05 100644
--- a/bj_power_wms/schema/order_material_ledger.go
+++ b/bj_power_wms/schema/order_material_ledger.go
@@ -2,6 +2,8 @@ package schema
import (
"entgo.io/ent"
+ "entgo.io/ent/dialect/entsql"
+ "entgo.io/ent/schema"
"entgo.io/ent/schema/field"
"entgo.io/ent/schema/index"
)
@@ -20,6 +22,9 @@ type OrderMaterialLedger struct {
ent.Schema
}
+func (OrderMaterialLedger) Annotations() []schema.Annotation {
+ return []schema.Annotation{entsql.Table("order_material_ledgers"), entsql.WithComments(true), schema.Comment("OrderMaterialLedger 工单物料台账(WMS 侧)")}
+}
func (OrderMaterialLedger) Fields() []ent.Field {
return []ent.Field{
field.String("order_no").Comment("工单号"),
diff --git a/bj_power_wms/schema/outbound_detail.go b/bj_power_wms/schema/outbound_detail.go
index f8bb34c..9e5acfd 100644
--- a/bj_power_wms/schema/outbound_detail.go
+++ b/bj_power_wms/schema/outbound_detail.go
@@ -2,6 +2,8 @@ package schema
import (
"entgo.io/ent"
+ "entgo.io/ent/dialect/entsql"
+ "entgo.io/ent/schema"
"entgo.io/ent/schema/field"
"entgo.io/ent/schema/index"
)
@@ -13,6 +15,9 @@ type OutboundDetail struct {
ent.Schema
}
+func (OutboundDetail) Annotations() []schema.Annotation {
+ return []schema.Annotation{entsql.Table("outbound_details"), entsql.WithComments(true), schema.Comment("OutboundDetail 出库明细(一张出库单可含多行)")}
+}
func (OutboundDetail) Fields() []ent.Field {
return []ent.Field{
field.String("outbound_no").Comment("出库单号"),
diff --git a/bj_power_wms/schema/outbound_order.go b/bj_power_wms/schema/outbound_order.go
index 417f7de..1fc6fb6 100644
--- a/bj_power_wms/schema/outbound_order.go
+++ b/bj_power_wms/schema/outbound_order.go
@@ -2,6 +2,8 @@ package schema
import (
"entgo.io/ent"
+ "entgo.io/ent/dialect/entsql"
+ "entgo.io/ent/schema"
"entgo.io/ent/schema/field"
"entgo.io/ent/schema/index"
)
@@ -16,6 +18,9 @@ type OutboundOrder struct {
ent.Schema
}
+func (OutboundOrder) Annotations() []schema.Annotation {
+ return []schema.Annotation{entsql.Table("outbound_orders"), entsql.WithComments(true), schema.Comment("OutboundOrder 出库统一主表")}
+}
func (OutboundOrder) Fields() []ent.Field {
return []ent.Field{
field.String("outbound_no").Unique().Comment("出库单号"),
diff --git a/bj_power_wms/schema/permission.go b/bj_power_wms/schema/permission.go
index 293f3d8..2914c50 100644
--- a/bj_power_wms/schema/permission.go
+++ b/bj_power_wms/schema/permission.go
@@ -18,7 +18,7 @@ type Permission struct {
}
func (Permission) Annotations() []schema.Annotation {
- return []schema.Annotation{entsql.Annotation{Table: "permissions"}}
+ return []schema.Annotation{entsql.Table("permissions"), entsql.WithComments(true), schema.Comment("Permission 权限/菜单")}
}
func (Permission) Fields() []ent.Field {
diff --git a/bj_power_wms/schema/return_order.go b/bj_power_wms/schema/return_order.go
index 538059c..27896e6 100644
--- a/bj_power_wms/schema/return_order.go
+++ b/bj_power_wms/schema/return_order.go
@@ -2,6 +2,8 @@ package schema
import (
"entgo.io/ent"
+ "entgo.io/ent/dialect/entsql"
+ "entgo.io/ent/schema"
"entgo.io/ent/schema/field"
"entgo.io/ent/schema/index"
)
@@ -13,6 +15,9 @@ type ReturnOrder struct {
ent.Schema
}
+func (ReturnOrder) Annotations() []schema.Annotation {
+ return []schema.Annotation{entsql.Table("return_orders"), entsql.WithComments(true), schema.Comment("ReturnOrder 退库单(客户诉求 问题记录 L488/L491):")}
+}
func (ReturnOrder) Fields() []ent.Field {
return []ent.Field{
field.String("return_no").Unique().Comment("退库单号"),
diff --git a/bj_power_wms/schema/role.go b/bj_power_wms/schema/role.go
index 0142d2f..1492495 100644
--- a/bj_power_wms/schema/role.go
+++ b/bj_power_wms/schema/role.go
@@ -19,7 +19,7 @@ type Role struct {
}
func (Role) Annotations() []schema.Annotation {
- return []schema.Annotation{entsql.Annotation{Table: "roles"}}
+ return []schema.Annotation{entsql.Table("roles"), entsql.WithComments(true), schema.Comment("Role 角色:承载菜单/按钮权限")}
}
func (Role) Fields() []ent.Field {
diff --git a/bj_power_wms/schema/semi_finished.go b/bj_power_wms/schema/semi_finished.go
index 2b3ef60..cd1a80c 100644
--- a/bj_power_wms/schema/semi_finished.go
+++ b/bj_power_wms/schema/semi_finished.go
@@ -2,6 +2,8 @@ package schema
import (
"entgo.io/ent"
+ "entgo.io/ent/dialect/entsql"
+ "entgo.io/ent/schema"
"entgo.io/ent/schema/field"
"entgo.io/ent/schema/index"
)
@@ -14,6 +16,9 @@ type SemiFinished struct {
ent.Schema
}
+func (SemiFinished) Annotations() []schema.Annotation {
+ return []schema.Annotation{entsql.Table("semi_finisheds"), entsql.WithComments(true), schema.Comment("SemiFinished 半成品库存")}
+}
func (SemiFinished) Fields() []ent.Field {
return []ent.Field{
field.String("sn").Unique().Comment("半成品 SN"),
diff --git a/bj_power_wms/schema/stocktake.go b/bj_power_wms/schema/stocktake.go
index cf9eec2..e37ed8d 100644
--- a/bj_power_wms/schema/stocktake.go
+++ b/bj_power_wms/schema/stocktake.go
@@ -2,6 +2,8 @@ package schema
import (
"entgo.io/ent"
+ "entgo.io/ent/dialect/entsql"
+ "entgo.io/ent/schema"
"entgo.io/ent/schema/field"
"entgo.io/ent/schema/index"
)
@@ -11,6 +13,9 @@ type StocktakeOrder struct {
ent.Schema
}
+func (StocktakeOrder) Annotations() []schema.Annotation {
+ return []schema.Annotation{entsql.Table("stocktake_orders"), entsql.WithComments(true), schema.Comment("StocktakeOrder 盘点单:发起时冻结当时库存快照(明细行)")}
+}
func (StocktakeOrder) Fields() []ent.Field {
return []ent.Field{
field.String("stocktake_no").Unique().Comment("盘点单号"),
@@ -45,6 +50,9 @@ type StocktakeItem struct {
ent.Schema
}
+func (StocktakeItem) Annotations() []schema.Annotation {
+ return []schema.Annotation{entsql.Table("stocktake_items"), entsql.WithComments(true), schema.Comment("StocktakeItem 盘点明细(发起时的账面快照 + 扫码实盘数)")}
+}
func (StocktakeItem) Fields() []ent.Field {
return []ent.Field{
field.String("stocktake_no").Comment("所属盘点单号"),
diff --git a/bj_power_wms/schema/user.go b/bj_power_wms/schema/user.go
index bf34ee0..1bb330f 100644
--- a/bj_power_wms/schema/user.go
+++ b/bj_power_wms/schema/user.go
@@ -2,6 +2,8 @@ package schema
import (
"entgo.io/ent"
+ "entgo.io/ent/dialect/entsql"
+ "entgo.io/ent/schema"
"entgo.io/ent/schema/field"
"entgo.io/ent/schema/index"
)
@@ -13,6 +15,9 @@ type User struct {
ent.Schema
}
+func (User) Annotations() []schema.Annotation {
+ return []schema.Annotation{entsql.Table("users"), entsql.WithComments(true), schema.Comment("User 系统用户(账号与权限)")}
+}
func (User) Fields() []ent.Field {
return []ent.Field{
field.String("username").Unique().Comment("登录名"),
diff --git a/bj_power_wms/schema/zone.go b/bj_power_wms/schema/zone.go
index 3005438..726d7c6 100644
--- a/bj_power_wms/schema/zone.go
+++ b/bj_power_wms/schema/zone.go
@@ -2,6 +2,8 @@ package schema
import (
"entgo.io/ent"
+ "entgo.io/ent/dialect/entsql"
+ "entgo.io/ent/schema"
"entgo.io/ent/schema/field"
)
@@ -14,6 +16,9 @@ type Zone struct {
ent.Schema
}
+func (Zone) Annotations() []schema.Annotation {
+ return []schema.Annotation{entsql.Table("zones"), entsql.WithComments(true), schema.Comment("Zone 库房库位主数据(统一主表 + 层级类型字段,符合「统一主表+类型字段,禁拆表」铁律)。")}
+}
func (Zone) Fields() []ent.Field {
return []ent.Field{
field.Int("level").Comment("层级 1区域/2货架/3层/4位置号"),
diff --git a/bj_power_wms/web/static/index.html b/bj_power_wms/web/static/index.html
index 14732ac..a5141e7 100644
--- a/bj_power_wms/web/static/index.html
+++ b/bj_power_wms/web/static/index.html
@@ -6,7 +6,7 @@
WMS库房管理
-
+
diff --git a/go.work b/go.work
new file mode 100644
index 0000000..a788483
--- /dev/null
+++ b/go.work
@@ -0,0 +1,7 @@
+go 1.26.4
+
+use (
+ ./bj_power_mes
+ ./bj_power_wms
+ ./bj_power_workstation
+)
diff --git a/go.work.sum b/go.work.sum
new file mode 100644
index 0000000..74017a9
--- /dev/null
+++ b/go.work.sum
@@ -0,0 +1 @@
+golang.org/x/net v0.56.0/go.mod h1:D3Ku6r+V6JROoZK144D2XfMHFcMq/0zSfLelVTCFKec=
diff --git a/sql/_mes_catalog.tsv b/sql/_mes_catalog.tsv
new file mode 100644
index 0000000..02c720e
--- /dev/null
+++ b/sql/_mes_catalog.tsv
@@ -0,0 +1,402 @@
+table_name column_name data_type col_comment
+alert id bigint
+alert rule_id bigint
+alert type character varying
+alert title character varying
+alert content character varying
+alert ref_type character varying
+alert ref_id character varying
+alert order_no character varying
+alert status character varying
+alert receiver character varying
+alert created_at timestamp with time zone
+alert_rule id bigint
+alert_rule name character varying
+alert_rule type character varying
+alert_rule threshold double precision
+alert_rule receiver character varying
+alert_rule enabled boolean
+alert_rule created_by character varying
+alert_rule created_at timestamp with time zone
+association_trace id bigint
+association_trace finished_sn character varying
+association_trace order_no character varying
+association_trace process_code character varying
+association_trace batch_items jsonb
+association_trace serial_items jsonb
+association_trace operator character varying
+association_trace created_at timestamp with time zone
+attachment id bigint
+attachment biz_type character varying
+attachment biz_id character varying
+attachment file_name character varying
+attachment file_path character varying
+attachment file_size bigint
+attachment uploader character varying
+attachment created_at timestamp with time zone
+attachment file_type character varying
+attachment file_ext character varying
+attachment file_md5 character varying
+attachment mime_type character varying
+attachment archived boolean
+attachment archived_at bigint
+attachment deleted boolean
+attachment deleted_at bigint
+attachment deleted_by character varying
+daily_plan id bigint
+daily_plan order_no character varying
+daily_plan plan_date character varying
+daily_plan plan_qty bigint
+daily_plan completed_qty bigint
+daily_plan station_plan_qty jsonb
+daily_plan status character varying
+daily_plan operator character varying
+daily_plan created_at timestamp with time zone
+daily_plan updated_at timestamp with time zone
+dock id bigint
+dock dock_code character varying
+dock name character varying
+dock dock_type character varying
+dock station_no bigint
+dock has_pallet boolean
+dock pallet_ref character varying
+dock status character varying
+dock created_at timestamp with time zone
+event_log id bigint
+event_log event_type character varying
+event_log work_order_no character varying
+event_log operator character varying
+event_log entity_type character varying
+event_log entity_id character varying
+event_log description text
+event_log payload jsonb
+event_log created_at timestamp with time zone
+flow_material id bigint
+flow_material flow_id bigint
+flow_material material_code character varying
+flow_material material_name character varying
+flow_material spec character varying
+flow_material unit character varying
+flow_material unit_qty double precision
+flow_material loss_rate double precision
+flow_material created_at timestamp with time zone
+flow_material sn_mode bigint
+inspection_record id bigint
+inspection_record category character varying
+inspection_record station_no character varying
+inspection_record shift character varying
+inspection_record order_no character varying
+inspection_record sn character varying
+inspection_record result character varying
+inspection_record items jsonb
+inspection_record photo character varying
+inspection_record remark character varying
+inspection_record operator character varying
+inspection_record process_code bigint
+inspection_record step_id bigint
+inspection_record step_name character varying
+inspection_record measured_value character varying
+inspection_record report_no character varying
+inspection_record material_code character varying
+inspection_record material_name character varying
+inspection_record manufacturer character varying
+inspection_record inspection_no character varying
+inspection_record attachment_ids character varying
+inspection_record disposal_type character varying
+inspection_record disposal_remark character varying
+inspection_record created_at timestamp with time zone
+inspection_record batch_sn character varying
+inspection_record related_standard character varying
+inspection_record test_record_no character varying
+line_point id bigint
+line_point point_type character varying
+line_point point_no character varying
+line_point label character varying
+line_point seq bigint
+line_point station_no bigint
+line_point current_sn character varying
+line_point order_no character varying
+line_point occupied boolean
+line_point updated_at timestamp with time zone
+material_qty_report id bigint
+material_qty_report station_no bigint
+material_qty_report order_no character varying
+material_qty_report sn character varying
+material_qty_report material_code character varying
+material_qty_report material_name character varying
+material_qty_report plan_qty bigint
+material_qty_report actual_qty bigint
+material_qty_report diff_qty bigint
+material_qty_report cause character varying
+material_qty_report status character varying
+material_qty_report handle_type character varying
+material_qty_report handle_doc_no character varying
+material_qty_report handle_note character varying
+material_qty_report handled_by character varying
+material_qty_report handled_at bigint
+material_qty_report operator character varying
+material_qty_report created_at timestamp with time zone
+material_qty_report resolved_at timestamp with time zone
+material_request id bigint
+material_request request_no character varying
+material_request order_no character varying
+material_request plan_date character varying
+material_request material_code character varying
+material_request material_name character varying
+material_request unit character varying
+material_request req_qty double precision
+material_request status character varying
+material_request target_dock character varying
+material_request station_no bigint
+material_request flow_id bigint
+material_request sent_qty double precision
+material_request received_qty double precision
+material_request received_at bigint
+material_request receive_by character varying
+material_request source character varying
+material_request over_qty double precision
+material_request over_reason character varying
+material_request ref_report_no character varying
+material_request need_agv boolean
+material_request batch_no character varying
+material_request operator character varying
+material_request created_at timestamp with time zone
+material_request updated_at timestamp with time zone
+material_request sn_mode bigint
+materials id bigint
+materials code character varying
+materials name character varying
+materials spec character varying
+materials unit character varying
+materials description character varying
+materials item_type bigint
+materials manage_mode bigint
+materials template_code character varying
+materials safety_stock bigint
+materials is_active boolean
+materials sync_pending boolean
+materials created_at timestamp with time zone
+materials updated_at timestamp with time zone
+materials sn_mode bigint
+permission id bigint
+permission code character varying
+permission name character varying
+permission type character varying
+permission parent_code character varying
+permission path character varying
+permission icon character varying
+permission sort bigint
+permission remark character varying
+permission created_at timestamp with time zone
+plc_move_cmd id bigint
+plc_move_cmd cmd_no character varying
+plc_move_cmd sn character varying
+plc_move_cmd order_no character varying
+plc_move_cmd from_point character varying
+plc_move_cmd to_point character varying
+plc_move_cmd status character varying
+plc_move_cmd operator character varying
+plc_move_cmd message character varying
+plc_move_cmd created_at timestamp with time zone
+plc_move_cmd updated_at timestamp with time zone
+plc_send_log id bigint
+plc_send_log order_no character varying
+plc_send_log sn character varying
+plc_send_log station_no bigint
+plc_send_log process_combination character varying
+plc_send_log process_codes jsonb
+plc_send_log status character varying
+plc_send_log send_time timestamp with time zone
+plc_send_log done_time timestamp with time zone
+plc_send_log ack boolean
+plc_send_log remark character varying
+plc_send_log operator character varying
+plc_send_log created_at timestamp with time zone
+process_flow id bigint
+process_flow name character varying
+process_flow pdf_file character varying
+process_flow status character varying
+process_flow remark character varying
+process_flow created_at timestamp with time zone
+process_flow updated_at timestamp with time zone
+process_step id bigint
+process_step flow_id bigint
+process_step seq bigint
+process_step name character varying
+process_step collect_type character varying
+process_step is_torque boolean
+process_step need_check boolean
+process_step attachment jsonb
+process_step remark character varying
+process_step created_at timestamp with time zone
+process_step need_operator_sign boolean
+process_step need_inspector_sign boolean
+role id bigint
+role name character varying
+role code character varying
+role remark character varying
+role permission_codes jsonb
+role created_at timestamp with time zone
+semi_flow id bigint
+semi_flow sn character varying
+semi_flow order_no character varying
+semi_flow done_process_codes jsonb
+semi_flow completed_text character varying
+semi_flow action character varying
+semi_flow target_dock character varying
+semi_flow operator character varying
+semi_flow created_at timestamp with time zone
+station id bigint
+station station_no bigint
+station name character varying
+station flow_id bigint
+station station_type character varying
+station status character varying
+station is_builtin boolean
+station has_dock boolean
+station dock_code character varying
+station visible_tabs jsonb
+station created_at timestamp with time zone
+station_state id bigint
+station_state station_no bigint
+station_state date character varying
+station_state paused boolean
+station_state reason character varying
+station_state operator character varying
+station_state created_at timestamp with time zone
+station_state updated_at timestamp with time zone
+step_criterion id bigint
+step_criterion step_id bigint
+step_criterion name character varying
+step_criterion unit character varying
+step_criterion logic character varying
+step_criterion target double precision
+step_criterion min double precision
+step_criterion max double precision
+step_criterion created_at timestamp with time zone
+step_data id bigint
+step_data sn character varying
+step_data process_id bigint
+step_data step_id bigint
+step_data step_name character varying
+step_data criterion_id bigint
+step_data criterion_name character varying
+step_data criterion_logic character varying
+step_data value double precision
+step_data value_text character varying
+step_data is_ok boolean
+step_data operator character varying
+step_data created_at timestamp with time zone
+step_sign_record id bigint
+step_sign_record sn character varying
+step_sign_record order_no character varying
+step_sign_record flow_id bigint
+step_sign_record station_no character varying
+step_sign_record step_id bigint
+step_sign_record step_name character varying
+step_sign_record sign_role character varying
+step_sign_record result character varying
+step_sign_record signed_by character varying
+step_sign_record signed_at timestamp with time zone
+step_sign_record round bigint
+step_sign_record source character varying
+step_sign_record remark character varying
+step_sign_record revoked boolean
+step_sign_record revoked_by character varying
+step_sign_record revoked_at timestamp with time zone
+step_sign_record revoke_reason character varying
+step_sign_record created_at timestamp with time zone
+sys_config id bigint
+sys_config key character varying
+sys_config value character varying
+sys_config remark character varying
+torque_record id bigint
+torque_record work_order_no character varying
+torque_record sn character varying
+torque_record screw_no character varying
+torque_record strain double precision
+torque_record torque double precision
+torque_record angle double precision
+torque_record result character varying
+torque_record operator character varying
+torque_record station_no character varying
+torque_record time timestamp with time zone
+torque_record created_at timestamp with time zone
+torque_record operator_id bigint
+user id bigint
+user username character varying
+user password character varying
+user name character varying
+user role_id bigint
+user can_login_workstation boolean
+user workstation_password character varying
+user status character varying
+user last_login_at bigint
+user created_at timestamp with time zone
+user updated_at timestamp with time zone
+user_station id bigint
+user_station user_id bigint
+user_station station_no bigint
+user_station created_at timestamp with time zone
+work_order id bigint
+work_order work_order_no character varying
+work_order product_type_id bigint
+work_order product_code character varying
+work_order product_name character varying
+work_order quantity bigint
+work_order finished_num bigint
+work_order fail_num bigint
+work_order contract_no character varying
+work_order project_no character varying
+work_order product_serial character varying
+work_order created_by character varying
+work_order due_date timestamp with time zone
+work_order flow_combination jsonb
+work_order status character varying
+work_order plan_start timestamp with time zone
+work_order plan_end timestamp with time zone
+work_order context jsonb
+work_order completed_at timestamp with time zone
+work_order created_at timestamp with time zone
+work_order updated_at timestamp with time zone
+work_order ownership_type character varying
+workpiece id bigint
+workpiece sn character varying
+workpiece order_no character varying
+workpiece work_order_id bigint
+workpiece current_station_no bigint
+workpiece status character varying
+workpiece online_at timestamp with time zone
+workpiece done_at timestamp with time zone
+workpiece created_at timestamp with time zone
+workpiece updated_at timestamp with time zone
+workpiece_bind id bigint
+workpiece_bind sn character varying
+workpiece_bind order_no character varying
+workpiece_bind flow_id bigint
+workpiece_bind station_no character varying
+workpiece_bind material_code character varying
+workpiece_bind material_name character varying
+workpiece_bind spec character varying
+workpiece_bind unit character varying
+workpiece_bind bind_value character varying
+workpiece_bind bind_type character varying
+workpiece_bind operator character varying
+workpiece_bind created_at timestamp with time zone
+workpiece_bind sn_mode bigint
+workpiece_process id bigint
+workpiece_process sn character varying
+workpiece_process flow_id bigint
+workpiece_process station_no character varying
+workpiece_process order_no character varying
+workpiece_process process_name character varying
+workpiece_process status character varying
+workpiece_process operator character varying
+workpiece_process result character varying
+workpiece_process started_at timestamp with time zone
+workpiece_process ended_at timestamp with time zone
+workpiece_process duration_sec bigint
+workpiece_process remark character varying
+workpiece_process created_at timestamp with time zone
+workpiece_process operator_id bigint
+(400 rows)
diff --git a/sql/_wms_catalog.tsv b/sql/_wms_catalog.tsv
new file mode 100644
index 0000000..6304c76
--- /dev/null
+++ b/sql/_wms_catalog.tsv
@@ -0,0 +1,318 @@
+table_name column_name data_type col_comment
+agv_tasks id bigint
+agv_tasks task_no character varying
+agv_tasks hik_task_code character varying
+agv_tasks source_dock character varying
+agv_tasks target_dock character varying
+agv_tasks materials_json character varying
+agv_tasks related_outbound_no character varying
+agv_tasks status character varying
+agv_tasks operator character varying
+agv_tasks dispatched_at bigint
+agv_tasks arrived_at bigint
+agv_tasks remark character varying
+agv_tasks created_at bigint
+attachments id bigint
+attachments biz_type character varying
+attachments biz_id character varying
+attachments file_name character varying
+attachments file_path character varying
+attachments file_type character varying
+attachments file_ext character varying
+attachments file_md5 character varying
+attachments file_size bigint
+attachments mime_type character varying
+attachments uploaded_by character varying
+attachments archived boolean
+attachments archived_at bigint
+attachments deleted boolean
+attachments deleted_at bigint
+attachments deleted_by character varying
+attachments created_at bigint
+event_log id bigint
+event_log event_type character varying
+event_log operator character varying
+event_log entity_type character varying
+event_log entity_id character varying
+event_log description text
+event_log payload jsonb
+event_log created_at bigint
+inbound_details id bigint
+inbound_details inbound_no character varying
+inbound_details sn_code character varying
+inbound_details batch_no character varying
+inbound_details material_code character varying
+inbound_details quantity bigint
+inbound_details created_at bigint
+inbound_orders id bigint
+inbound_orders inbound_no character varying
+inbound_orders inbound_type character varying
+inbound_orders material_code character varying
+inbound_orders material_name character varying
+inbound_orders manage_mode bigint
+inbound_orders batch_no character varying
+inbound_orders zone_code character varying
+inbound_orders shelf_no character varying
+inbound_orders layer_no character varying
+inbound_orders position_no character varying
+inbound_orders quantity bigint
+inbound_orders operator character varying
+inbound_orders remark character varying
+inbound_orders inspection_no character varying
+inbound_orders ownership_type character varying
+inbound_orders ownership_no character varying
+inbound_orders quality_status character varying
+inbound_orders voided boolean
+inbound_orders void_reason character varying
+inbound_orders voided_by character varying
+inbound_orders voided_at bigint
+inbound_orders created_at bigint
+inbound_orders product_work_no character varying
+inbound_orders sn_mode bigint
+inspection_records id bigint
+inspection_records target_type character varying
+inspection_records target_id character varying
+inspection_records material_code character varying
+inspection_records material_name character varying
+inspection_records ownership_type character varying
+inspection_records ownership_no character varying
+inspection_records related_standard character varying
+inspection_records manufacturer character varying
+inspection_records inspection_type character varying
+inspection_records status character varying
+inspection_records result_value character varying
+inspection_records inspect_qty bigint
+inspection_records pass_qty bigint
+inspection_records reject_qty bigint
+inspection_records check_desc character varying
+inspection_records inspector character varying
+inspection_records inspection_no character varying
+inspection_records report_no character varying
+inspection_records disposal_type character varying
+inspection_records disposal_remark character varying
+inspection_records return_tracking_no character varying
+inspection_records remark character varying
+inspection_records created_at bigint
+inspection_records updated_at bigint
+inspection_records product_work_no character varying
+inspection_records batch_seq bigint
+inspection_records batch_total bigint
+inventories id bigint
+inventories manage_mode bigint
+inventories category bigint
+inventories material_code character varying
+inventories material_name character varying
+inventories batch_no character varying
+inventories sn_code character varying
+inventories quantity bigint
+inventories locked_qty bigint
+inventories quality_status character varying
+inventories zone_code character varying
+inventories shelf_no character varying
+inventories layer_no character varying
+inventories position_no character varying
+inventories status character varying
+inventories production_date character varying
+inventories supplier character varying
+inventories inbound_no character varying
+inventories order_no character varying
+inventories completed_process character varying
+inventories ownership_type character varying
+inventories ownership_no character varying
+inventories product_status character varying
+inventories related_standard character varying
+inventories test_record_no character varying
+inventories recorded_by character varying
+inventories recorded_at bigint
+inventories outbound_reason character varying
+inventories stocktake_no character varying
+inventories remark character varying
+inventories created_at bigint
+inventories updated_at bigint
+inventories product_work_no character varying
+inventories sn_mode bigint
+inventory_locks id bigint
+inventory_locks target_type character varying
+inventory_locks target_id character varying
+inventory_locks material_code character varying
+inventory_locks locked_qty bigint
+inventory_locks order_no character varying
+inventory_locks status character varying
+inventory_locks expired_at bigint
+inventory_locks remark character varying
+inventory_locks created_at bigint
+inventory_locks updated_at bigint
+material_demands id bigint
+material_demands material_code character varying
+material_demands future5_qty bigint
+material_demands updated_at bigint
+materials id bigint
+materials code character varying
+materials name character varying
+materials spec character varying
+materials unit character varying
+materials description character varying
+materials item_type bigint
+materials manage_mode bigint
+materials is_batch_managed boolean
+materials is_serial_managed boolean
+materials template_code character varying
+materials safety_stock bigint
+materials is_active boolean
+materials created_at bigint
+materials updated_at bigint
+materials sn_mode bigint
+order_material_ledgers id bigint
+order_material_ledgers order_no character varying
+order_material_ledgers material_code character varying
+order_material_ledgers material_name character varying
+order_material_ledgers total_qty bigint
+order_material_ledgers out_qty bigint
+order_material_ledgers returned_qty bigint
+order_material_ledgers consumed_qty bigint
+order_material_ledgers status character varying
+order_material_ledgers target_station character varying
+order_material_ledgers completed_at bigint
+order_material_ledgers remark character varying
+order_material_ledgers created_at bigint
+order_material_ledgers updated_at bigint
+outbound_details id bigint
+outbound_details outbound_no character varying
+outbound_details sn_code character varying
+outbound_details batch_no character varying
+outbound_details material_code character varying
+outbound_details quantity bigint
+outbound_details order_no character varying
+outbound_details created_at bigint
+outbound_orders id bigint
+outbound_orders outbound_no character varying
+outbound_orders outbound_type character varying
+outbound_orders status character varying
+outbound_orders need_agv boolean
+outbound_orders outbound_category character varying
+outbound_orders ownership_type character varying
+outbound_orders ownership_no character varying
+outbound_orders target_station character varying
+outbound_orders order_no character varying
+outbound_orders material_code character varying
+outbound_orders material_name character varying
+outbound_orders manage_mode bigint
+outbound_orders batch_no character varying
+outbound_orders zone_code character varying
+outbound_orders shelf_no character varying
+outbound_orders layer_no character varying
+outbound_orders position_no character varying
+outbound_orders quantity bigint
+outbound_orders operator character varying
+outbound_orders reviewer character varying
+outbound_orders target_dock character varying
+outbound_orders remark character varying
+outbound_orders box_no character varying
+outbound_orders box_sn_list character varying
+outbound_orders contract_no character varying
+outbound_orders inspection_no character varying
+outbound_orders created_at bigint
+outbound_orders product_work_no character varying
+outbound_orders sn_mode bigint
+permissions id bigint
+permissions code character varying
+permissions name character varying
+permissions type character varying
+permissions parent_code character varying
+permissions path character varying
+permissions icon character varying
+permissions sort bigint
+permissions remark character varying
+permissions created_at bigint
+permissions updated_at bigint
+return_orders id bigint
+return_orders return_no character varying
+return_orders source_type character varying
+return_orders order_no character varying
+return_orders station_no bigint
+return_orders sn character varying
+return_orders material_code character varying
+return_orders material_name character varying
+return_orders spec character varying
+return_orders qty bigint
+return_orders unit character varying
+return_orders reason character varying
+return_orders status character varying
+return_orders operator character varying
+return_orders receive_by character varying
+return_orders created_at bigint
+return_orders receive_at bigint
+roles id bigint
+roles name character varying
+roles code character varying
+roles remark character varying
+roles permission_codes jsonb
+roles created_at bigint
+roles updated_at bigint
+semi_finisheds id bigint
+semi_finisheds sn character varying
+semi_finisheds material_code character varying
+semi_finisheds completed_process character varying
+semi_finisheds quantity bigint
+semi_finisheds zone_code character varying
+semi_finisheds status character varying
+semi_finisheds order_no character varying
+semi_finisheds created_at bigint
+semi_finisheds updated_at bigint
+stocktake_items id bigint
+stocktake_items stocktake_no character varying
+stocktake_items target_type character varying
+stocktake_items target_id character varying
+stocktake_items material_code character varying
+stocktake_items zone_code character varying
+stocktake_items shelf_no character varying
+stocktake_items layer_no character varying
+stocktake_items position_no character varying
+stocktake_items book_qty bigint
+stocktake_items scanned_qty bigint
+stocktake_items diff_qty bigint
+stocktake_items counted boolean
+stocktake_items counted_by character varying
+stocktake_items counted_at bigint
+stocktake_items updated_at bigint
+stocktake_orders id bigint
+stocktake_orders stocktake_no character varying
+stocktake_orders status character varying
+stocktake_orders operator character varying
+stocktake_orders total_targets bigint
+stocktake_orders diff_count bigint
+stocktake_orders adjusted boolean
+stocktake_orders adjust_no character varying
+stocktake_orders written_at bigint
+stocktake_orders written_by character varying
+stocktake_orders uncounted_mode character varying
+stocktake_orders cancel_reason character varying
+stocktake_orders created_at bigint
+stocktake_orders finished_at bigint
+users id bigint
+users username character varying
+users password character varying
+users real_name character varying
+users role character varying
+users role_id bigint
+users dept character varying
+users phone character varying
+users is_active boolean
+users last_login_at bigint
+users created_at bigint
+users updated_at bigint
+zones id bigint
+zones level bigint
+zones code character varying
+zones name character varying
+zones parent_code character varying
+zones zone_code character varying
+zones zone_name character varying
+zones description character varying
+zones shelf_no character varying
+zones layer_no character varying
+zones position_no character varying
+zones status character varying
+zones created_at bigint
+zones updated_at bigint
+(316 rows)
diff --git a/sql/bake_comments.py b/sql/bake_comments.py
new file mode 100644
index 0000000..59c6cdc
--- /dev/null
+++ b/sql/bake_comments.py
@@ -0,0 +1,110 @@
+# -*- coding: utf-8 -*-
+"""
+WMS 注释固化进 schema 源码(正确机制):
+ - 列注释:字段已有 .Comment("..."),表级 entsql.WithComments(true) 让 ent 生成 SQL 时
+ 自动把字段注释写成列注释(无需逐字段注入)。
+ - 表注释:结构体 schema.Comment("...") + WithComments(true)。
+ - 因此本脚本只改造每个 schema 结构体的 Annotations(),不改动 Fields()。
+幂等:已含 WithComments 的结构体跳过重新写入(按表名归一)。
+"""
+import os, re
+
+SCHEMA_DIR = os.environ.get("SCHEMA_DIR", r"D:/hardman/bj_power/bj_power_wms/schema")
+SQL_PATH = r"D:/hardman/bj_power/sql/db_comments_wms.sql"
+
+STRUCT_TABLE = {
+ "AgvTask": "agv_tasks", "Attachment": "attachments", "EventLog": "event_log",
+ "InboundDetail": "inbound_details", "InboundOrder": "inbound_orders",
+ "InspectionRecord": "inspection_records", "Inventory": "inventories",
+ "InventoryLock": "inventory_locks", "Material": "materials",
+ "MaterialDemand": "material_demands", "OrderMaterialLedger": "order_material_ledgers",
+ "OutboundDetail": "outbound_details", "OutboundOrder": "outbound_orders",
+ "Permission": "permissions", "ReturnOrder": "return_orders", "Role": "roles",
+ "SemiFinished": "semi_finisheds", "StocktakeItem": "stocktake_items",
+ "StocktakeOrder": "stocktake_orders", "User": "users", "Zone": "zones",
+}
+
+table_comment = {}
+with open(SQL_PATH, encoding="utf-8") as f:
+ for line in f:
+ m = re.match(r"COMMENT ON TABLE \"(\w+)\" IS '(.*)';", line.strip())
+ if m:
+ table_comment[m.group(1)] = m.group(2)
+
+def sanitize_quotes(s):
+ # 把 ASCII 双引号包裹的文本转成全角引号,避免 ent 生成 schema.go 时破坏 Go 字符串字面量
+ # (ent 生成器写 Comment: 字段不转义 ASCII 双引号,源里含 " 会直接破坏生成的 Go 代码)
+ s = re.sub(r'"([^"]*)"', '\u201c\\1\u201d', s)
+ return s.replace('"', '\u201c')
+
+def gostr(s):
+ s = sanitize_quotes(s)
+ return s.replace('\\', '\\\\').replace('"', '\\"')
+
+def ensure_import(src, pkg):
+ if re.search(r'"%s"' % re.escape(pkg), src):
+ return src
+ m = re.search(r'import \(\n((?:.*\n)*?)\)', src)
+ if m:
+ newblock = m.group(0).replace(')', '\t"%s"\n)' % pkg, 1)
+ return src[:m.start()] + newblock + src[m.end():]
+ m2 = re.search(r'import\s+"([^"]+)"', src)
+ if m2:
+ path = m2.group(1)
+ block = 'import (\n\t"%s"\n\t"%s"\n)' % (path, pkg)
+ return src[:m2.start()] + block + src[m2.end():]
+ return src
+
+def replace_or_insert_annotations(src, struct, table, tbl_comment):
+ sig = 'func (%s) Annotations() []schema.Annotation {' % struct
+ new_body = ('func (%s) Annotations() []schema.Annotation {\n'
+ '\treturn []schema.Annotation{entsql.Table("%s"), entsql.WithComments(true), schema.Comment("%s")}\n'
+ '}') % (struct, table, gostr(tbl_comment))
+ if sig in src:
+ i = src.index(sig)
+ depth, j = 0, i
+ while j < len(src):
+ if src[j] == '{':
+ depth += 1
+ elif src[j] == '}':
+ depth -= 1
+ if depth == 0:
+ break
+ j += 1
+ src = src[:i] + new_body + src[j + 1:]
+ else:
+ fs = 'func (%s) Fields() []ent.Field {' % struct
+ src = src.replace('\n' + fs, '\n' + new_body + '\n' + fs, 1)
+ return src
+
+for fn in sorted(os.listdir(SCHEMA_DIR)):
+ if not fn.endswith('.go') or fn in ('mixin.go', 'generate.go'):
+ continue
+ path = os.path.join(SCHEMA_DIR, fn)
+ with open(path, encoding='utf-8') as f:
+ src = f.read()
+ structs = re.findall(r'type (\w+) struct \{\s*ent\.Schema\s*\}', src)
+ if not structs:
+ continue
+ changed = False
+ for st in structs:
+ table = STRUCT_TABLE.get(st)
+ if not table:
+ print("!! no table mapping for", st, fn)
+ continue
+ if 'entsql.WithComments(true)' in src and ('func (%s) Annotations()' % st) in src:
+ # already done (idempotent guard)
+ continue
+ new = replace_or_insert_annotations(src, st, table, table_comment.get(table, ''))
+ if new != src:
+ src = new
+ changed = True
+ if changed:
+ src = ensure_import(src, 'entgo.io/ent/dialect/entsql')
+ src = ensure_import(src, 'entgo.io/ent/schema')
+ with open(path, 'w', encoding='utf-8') as f:
+ f.write(src)
+ print("updated:", fn)
+ else:
+ print("no change:", fn)
+print("DONE")
diff --git a/sql/bake_comments_mes.py b/sql/bake_comments_mes.py
new file mode 100644
index 0000000..efae56c
--- /dev/null
+++ b/sql/bake_comments_mes.py
@@ -0,0 +1,62 @@
+# -*- coding: utf-8 -*-
+"""
+MES 注释固化进 schema 源码(对齐 WMS bake_comments.py 的正确机制):
+ - MES 32 个 struct 已有 Annotations()(形态统一:[]schema.Annotation{entsql.Annotation{Table: "xxx"}})。
+ - 在既有返回切片里追加 entsql.WithComments(true) + schema.Comment("表注释"):
+ WithComments(true) 让字段已有 field.Comment() 自动生成为列注释;
+ schema.Comment() 为表注释。
+ - 不动 Fields()、不动既有 entsql.Annotation{Table:...}。
+幂等:已含 WithComments(true) 的文件跳过。
+"""
+import os, re
+
+SCHEMA_DIR = os.environ.get("SCHEMA_DIR", r"D:/hardman/bj_power/bj_power_mes/schema")
+SQL_PATH = r"D:/hardman/bj_power/sql/db_comments_mes.sql"
+
+table_comment = {}
+with open(SQL_PATH, encoding="utf-8") as f:
+ for line in f:
+ m = re.match(r"COMMENT ON TABLE \"(\w+)\" IS '(.*)';", line.strip())
+ if m:
+ table_comment[m.group(1)] = m.group(2)
+
+def sanitize_quotes(s):
+ # ent 生成 Comment: 字面量不转义 ASCII 双引号,统一转全角避免破坏生成的 Go 代码
+ s = re.sub(r'"([^"]*)"', '\u201c\\1\u201d', s)
+ return s.replace('"', '\u201c')
+
+def gostr(s):
+ s = sanitize_quotes(s)
+ return s.replace('\\', '\\\\').replace('"', '\\"')
+
+RETURN_RE = re.compile(
+ r'return \[\]schema\.Annotation\{entsql\.Annotation\{Table: "(\w+)"\}\}')
+
+for fn in sorted(os.listdir(SCHEMA_DIR)):
+ if not fn.endswith('.go') or fn in ('mixin.go', 'gen.go'):
+ continue
+ path = os.path.join(SCHEMA_DIR, fn)
+ with open(path, encoding='utf-8') as f:
+ src = f.read()
+ structs = re.findall(r'type (\w+) struct \{\s*ent\.Schema\s*\}', src)
+ if not structs:
+ continue
+ m = RETURN_RE.search(src)
+ if not m:
+ print("!! no plain-table Annotations return in", fn)
+ continue
+ if 'entsql.WithComments(true)' in src:
+ print("no change (already done):", fn)
+ continue
+ table = m.group(1)
+ if table not in table_comment:
+ print("!! no table comment found for", table, "in", fn)
+ continue
+ old = m.group(0)
+ new = ('return []schema.Annotation{entsql.Annotation{Table: "%s"}, '
+ 'entsql.WithComments(true), schema.Comment("%s")}' % (table, gostr(table_comment[table])))
+ src = src.replace(old, new, 1)
+ with open(path, 'w', encoding='utf-8') as f:
+ f.write(src)
+ print("updated:", fn, "->", table)
+print("DONE")
diff --git a/sql/db_comments_mes.sql b/sql/db_comments_mes.sql
new file mode 100644
index 0000000..8def6f5
--- /dev/null
+++ b/sql/db_comments_mes.sql
@@ -0,0 +1,426 @@
+-- ============================================================
+-- MES 数据库 表/列 注释(COMMENT ON),可重复执行
+-- 由 ent schema 源文件抽取生成;表名/列名均以真实库目录为准
+-- ============================================================
+
+COMMENT ON TABLE "alert" IS 'Alert 预警消息:规则命中或手动触发后写入,供前端预警中心收件箱展示';
+COMMENT ON COLUMN "alert"."id" IS '主键ID';
+COMMENT ON COLUMN "alert"."rule_id" IS '关联规则ID,0=手动触发';
+COMMENT ON COLUMN "alert"."type" IS '预警类型';
+COMMENT ON COLUMN "alert"."title" IS '标题';
+COMMENT ON COLUMN "alert"."content" IS '内容';
+COMMENT ON COLUMN "alert"."ref_type" IS '关联业务类型';
+COMMENT ON COLUMN "alert"."ref_id" IS '关联业务ID';
+COMMENT ON COLUMN "alert"."order_no" IS '关联工单号(按工单号查询用)';
+COMMENT ON COLUMN "alert"."status" IS 'UNREAD/READ';
+COMMENT ON COLUMN "alert"."receiver" IS '接收人';
+COMMENT ON COLUMN "alert"."created_at" IS '创建时间';
+COMMENT ON TABLE "alert_rule" IS 'AlertRule 预警规则:按类型 + 阈值触发,命中后写入 alert 消息表';
+COMMENT ON COLUMN "alert_rule"."id" IS '主键ID';
+COMMENT ON COLUMN "alert_rule"."name" IS '规则名称';
+COMMENT ON COLUMN "alert_rule"."type" IS '预警类型 torque_ng/inspection_ng/inventory_low/task_overdue';
+COMMENT ON COLUMN "alert_rule"."threshold" IS '阈值(不同类含义不同)';
+COMMENT ON COLUMN "alert_rule"."receiver" IS '接收人,逗号分隔';
+COMMENT ON COLUMN "alert_rule"."enabled" IS '是否启用';
+COMMENT ON COLUMN "alert_rule"."created_by" IS '创建人';
+COMMENT ON COLUMN "alert_rule"."created_at" IS '创建时间';
+COMMENT ON TABLE "association_trace" IS 'AssociationTrace 成品追溯关联:成品SN ↔ 结构件批次 + 电气件SN';
+COMMENT ON COLUMN "association_trace"."id" IS '主键ID';
+COMMENT ON COLUMN "association_trace"."finished_sn" IS '成品SN(主件)';
+COMMENT ON COLUMN "association_trace"."order_no" IS '关联工单号';
+COMMENT ON COLUMN "association_trace"."process_code" IS '成品的工序组合';
+COMMENT ON COLUMN "association_trace"."batch_items" IS '结构件批次号列表';
+COMMENT ON COLUMN "association_trace"."serial_items" IS '电气件SN码列表';
+COMMENT ON COLUMN "association_trace"."operator" IS '完工关联登记人';
+COMMENT ON COLUMN "association_trace"."created_at" IS '创建时间';
+COMMENT ON TABLE "attachment" IS 'Attachment 业务附件:图纸 / 照片 / 文档等,按 bizType+bizId 关联业务单据。';
+COMMENT ON COLUMN "attachment"."id" IS '主键ID';
+COMMENT ON COLUMN "attachment"."biz_type" IS '业务类型 work_order/material/process_flow/inspection';
+COMMENT ON COLUMN "attachment"."biz_id" IS '业务ID';
+COMMENT ON COLUMN "attachment"."file_name" IS '原始文件名';
+COMMENT ON COLUMN "attachment"."file_path" IS '上传目录相对路径';
+COMMENT ON COLUMN "attachment"."file_size" IS '字节数';
+COMMENT ON COLUMN "attachment"."uploader" IS '上传人';
+COMMENT ON COLUMN "attachment"."created_at" IS '创建时间';
+COMMENT ON COLUMN "attachment"."file_type" IS '文件类型 大写枚举 PROCESS_PDF/INSPECTION_PHOTO/...';
+COMMENT ON COLUMN "attachment"."file_ext" IS '扩展名(小写,不含点)';
+COMMENT ON COLUMN "attachment"."file_md5" IS '文件MD5(秒传/去重)';
+COMMENT ON COLUMN "attachment"."mime_type" IS 'MIME类型';
+COMMENT ON COLUMN "attachment"."archived" IS '是否已归档';
+COMMENT ON COLUMN "attachment"."archived_at" IS '归档时间(unix秒)';
+COMMENT ON COLUMN "attachment"."deleted" IS '逻辑删除';
+COMMENT ON COLUMN "attachment"."deleted_at" IS '删除时间(unix秒)';
+COMMENT ON COLUMN "attachment"."deleted_by" IS '删除人';
+COMMENT ON TABLE "daily_plan" IS 'DailyPlan 日排产:仅预告,不触发出库/领料';
+COMMENT ON COLUMN "daily_plan"."id" IS '主键ID';
+COMMENT ON COLUMN "daily_plan"."order_no" IS '工单号';
+COMMENT ON COLUMN "daily_plan"."plan_date" IS '排产日期 yyyy-MM-dd';
+COMMENT ON COLUMN "daily_plan"."plan_qty" IS '计划数量';
+COMMENT ON COLUMN "daily_plan"."completed_qty" IS '已完成数量';
+COMMENT ON COLUMN "daily_plan"."station_plan_qty" IS '各工位产量分配 stationNo→计划产量';
+COMMENT ON COLUMN "daily_plan"."status" IS 'PENDING / PROCESSING / DONE';
+COMMENT ON COLUMN "daily_plan"."operator" IS '操作人';
+COMMENT ON COLUMN "daily_plan"."created_at" IS '创建时间';
+COMMENT ON COLUMN "daily_plan"."updated_at" IS '更新时间';
+COMMENT ON TABLE "dock" IS 'Dock 接驳台主数据:DOCK01~DOCK20(产线,DOCKn↔工位n)+ DOCK21(库房收货)。';
+COMMENT ON COLUMN "dock"."id" IS '主键ID';
+COMMENT ON COLUMN "dock"."dock_code" IS '接驳台编码 DOCK01..21';
+COMMENT ON COLUMN "dock"."name" IS '接驳台名称';
+COMMENT ON COLUMN "dock"."dock_type" IS '类型 line产线/store库房/other其他';
+COMMENT ON COLUMN "dock"."station_no" IS '关联工位号(与工位1:1,非产线为0)';
+COMMENT ON COLUMN "dock"."has_pallet" IS '当前是否有托盘';
+COMMENT ON COLUMN "dock"."pallet_ref" IS '托盘关联(出库单号/备料单号)';
+COMMENT ON COLUMN "dock"."status" IS 'ENABLED / DISABLED';
+COMMENT ON COLUMN "dock"."created_at" IS '创建时间';
+COMMENT ON TABLE "event_log" IS 'EventLog 操作日志:必须含 workOrderNo(工单号)、operator(操作人)';
+COMMENT ON COLUMN "event_log"."id" IS '主键ID';
+COMMENT ON COLUMN "event_log"."event_type" IS '事件类型,如 work.order.create';
+COMMENT ON COLUMN "event_log"."work_order_no" IS '关联工单号';
+COMMENT ON COLUMN "event_log"."operator" IS '操作人';
+COMMENT ON COLUMN "event_log"."entity_type" IS '实体类型';
+COMMENT ON COLUMN "event_log"."entity_id" IS '实体标识';
+COMMENT ON COLUMN "event_log"."description" IS '描述';
+COMMENT ON COLUMN "event_log"."payload" IS '载荷';
+COMMENT ON COLUMN "event_log"."created_at" IS '创建时间';
+COMMENT ON TABLE "flow_material" IS 'FlowMaterial 工艺物料清单:一道工艺装什么料、单台用多少(备料/齐套校验的唯一源头)。';
+COMMENT ON COLUMN "flow_material"."id" IS '主键ID';
+COMMENT ON COLUMN "flow_material"."flow_id" IS '所属工艺ID';
+COMMENT ON COLUMN "flow_material"."material_code" IS '物料编码';
+COMMENT ON COLUMN "flow_material"."material_name" IS '物料名称';
+COMMENT ON COLUMN "flow_material"."spec" IS '规格';
+COMMENT ON COLUMN "flow_material"."unit" IS '单位';
+COMMENT ON COLUMN "flow_material"."unit_qty" IS '单台用量';
+COMMENT ON COLUMN "flow_material"."loss_rate" IS '损耗率%';
+COMMENT ON COLUMN "flow_material"."created_at" IS '创建时间';
+COMMENT ON COLUMN "flow_material"."sn_mode" IS '是否逐件SN管理(冗余自物料档案 sn_mode,绑定/备料行为唯一依据):1 序列号件(录SN) / 2 批次件';
+COMMENT ON TABLE "inspection_record" IS 'InspectionRecord 巡检与质量检验记录(PAD 巡检终端 + MES 质量检验录入共用):';
+COMMENT ON COLUMN "inspection_record"."id" IS '主键ID';
+COMMENT ON COLUMN "inspection_record"."category" IS '记录类型 CHECKIN/POINT/PROCESS/DONE/ALARM/INCOMING/FINAL/QC_PROCESS';
+COMMENT ON COLUMN "inspection_record"."station_no" IS '工位号';
+COMMENT ON COLUMN "inspection_record"."shift" IS '班次 早/中/晚';
+COMMENT ON COLUMN "inspection_record"."order_no" IS '工单号';
+COMMENT ON COLUMN "inspection_record"."sn" IS '工件SN';
+COMMENT ON COLUMN "inspection_record"."result" IS '结论';
+COMMENT ON COLUMN "inspection_record"."items" IS '点检项/异常类型列表';
+COMMENT ON COLUMN "inspection_record"."photo" IS '拍照文件名';
+COMMENT ON COLUMN "inspection_record"."remark" IS '文字描述/签字';
+COMMENT ON COLUMN "inspection_record"."operator" IS '操作人';
+COMMENT ON COLUMN "inspection_record"."process_code" IS '所属工位号(过程巡检所在工位)';
+COMMENT ON COLUMN "inspection_record"."step_id" IS '工艺步骤ID(过程巡检逐条关联)';
+COMMENT ON COLUMN "inspection_record"."step_name" IS '工艺步骤名称';
+COMMENT ON COLUMN "inspection_record"."measured_value" IS '实测值(过程巡检录入)';
+COMMENT ON COLUMN "inspection_record"."report_no" IS '报检单号';
+COMMENT ON COLUMN "inspection_record"."material_code" IS '物料编码(图号)';
+COMMENT ON COLUMN "inspection_record"."material_name" IS '物料名称';
+COMMENT ON COLUMN "inspection_record"."manufacturer" IS '生产厂家';
+COMMENT ON COLUMN "inspection_record"."inspection_no" IS '检验单号';
+COMMENT ON COLUMN "inspection_record"."attachment_ids" IS '附件ID,逗号分隔(关联 attachment 表)';
+COMMENT ON COLUMN "inspection_record"."disposal_type" IS '处置类型 退货/返修/退换/报废';
+COMMENT ON COLUMN "inspection_record"."disposal_remark" IS '处置说明';
+COMMENT ON COLUMN "inspection_record"."created_at" IS '创建时间';
+COMMENT ON COLUMN "inspection_record"."batch_sn" IS '批次号/SN(联动 WMS 在库处置:序列号件=SN 批次件=批次)';
+COMMENT ON COLUMN "inspection_record"."related_standard" IS '相关标准/试验方案号(完工检用,随成品回流 WMS)';
+COMMENT ON COLUMN "inspection_record"."test_record_no" IS '试验记录单号(完工检用,随成品回流 WMS)';
+COMMENT ON TABLE "line_point" IS 'LinePoint 产线点位台账:记录每个点位当前存放的工件(唯一事实源)。';
+COMMENT ON COLUMN "line_point"."id" IS '主键ID';
+COMMENT ON COLUMN "line_point"."point_type" IS 'FEED上料位/STATION工位/CACHE缓存位/DOCK接驳台/END末端';
+COMMENT ON COLUMN "line_point"."point_no" IS '点位编号:IN上料位 / 1~10工位 / C1~C8缓存位 / 1-R1接驳台 / END-U上排末端 / END-D下排末端';
+COMMENT ON COLUMN "line_point"."label" IS '点位名称';
+COMMENT ON COLUMN "line_point"."seq" IS '传送带顺序(上料位→工位→末端,用于相邻缓存位判定)';
+COMMENT ON COLUMN "line_point"."station_no" IS '所属工位号(DOCK/CACHE 归属;0=无)';
+COMMENT ON COLUMN "line_point"."current_sn" IS '当前存放工件SN(空=空闲)';
+COMMENT ON COLUMN "line_point"."order_no" IS '当前工件所属工单号';
+COMMENT ON COLUMN "line_point"."occupied" IS '是否占用';
+COMMENT ON COLUMN "line_point"."updated_at" IS '更新时间';
+COMMENT ON TABLE "material_qty_report" IS 'MaterialQtyReport 工位数量不符上报(客户诉求 问题记录 L482/L486):';
+COMMENT ON COLUMN "material_qty_report"."id" IS '主键ID';
+COMMENT ON COLUMN "material_qty_report"."station_no" IS '工位号';
+COMMENT ON COLUMN "material_qty_report"."order_no" IS '工单号';
+COMMENT ON COLUMN "material_qty_report"."sn" IS '工件SN';
+COMMENT ON COLUMN "material_qty_report"."material_code" IS '物料编码';
+COMMENT ON COLUMN "material_qty_report"."material_name" IS '物料名称';
+COMMENT ON COLUMN "material_qty_report"."plan_qty" IS '应发数量';
+COMMENT ON COLUMN "material_qty_report"."actual_qty" IS '实收数量';
+COMMENT ON COLUMN "material_qty_report"."diff_qty" IS '差异=应发-实收';
+COMMENT ON COLUMN "material_qty_report"."cause" IS '差异原因';
+COMMENT ON COLUMN "material_qty_report"."status" IS 'PENDING/PROCESSING/REPLENISHED/RETURNED/ADJUSTED/CLOSED';
+COMMENT ON COLUMN "material_qty_report"."handle_type" IS '处理方式 REPLENISH补发/RETURN退库/ADJUST调整';
+COMMENT ON COLUMN "material_qty_report"."handle_doc_no" IS '处理生成的单据号(补料单号/退库单号)';
+COMMENT ON COLUMN "material_qty_report"."handle_note" IS '处理说明';
+COMMENT ON COLUMN "material_qty_report"."handled_by" IS '处理人';
+COMMENT ON COLUMN "material_qty_report"."handled_at" IS '处理时间(unix 秒)';
+COMMENT ON COLUMN "material_qty_report"."operator" IS '上报人';
+COMMENT ON COLUMN "material_qty_report"."created_at" IS '创建时间';
+COMMENT ON COLUMN "material_qty_report"."resolved_at" IS '处理时间';
+COMMENT ON TABLE "material_request" IS 'MaterialRequest 备料单:按日排产自动算料生成';
+COMMENT ON COLUMN "material_request"."id" IS '主键ID';
+COMMENT ON COLUMN "material_request"."request_no" IS '备料单号';
+COMMENT ON COLUMN "material_request"."order_no" IS '工单号';
+COMMENT ON COLUMN "material_request"."plan_date" IS '对应排产日';
+COMMENT ON COLUMN "material_request"."material_code" IS '物料编码';
+COMMENT ON COLUMN "material_request"."material_name" IS '物料名称';
+COMMENT ON COLUMN "material_request"."unit" IS '单位';
+COMMENT ON COLUMN "material_request"."req_qty" IS '需备数量';
+COMMENT ON COLUMN "material_request"."status" IS 'PENDING / LOCKED / DELIVERING / DONE';
+COMMENT ON COLUMN "material_request"."target_dock" IS '目标接驳台 DOCK01..20';
+COMMENT ON COLUMN "material_request"."station_no" IS '目标工位号(0=未指定)';
+COMMENT ON COLUMN "material_request"."flow_id" IS '该物料所属工艺ID(0=整线共用)';
+COMMENT ON COLUMN "material_request"."sent_qty" IS '已发出量(分批出库累加;幂等基准,勿与已接料混用)';
+COMMENT ON COLUMN "material_request"."received_qty" IS '已接料量(工位扫码接料累加)';
+COMMENT ON COLUMN "material_request"."received_at" IS '最近接料时间(unix 秒)';
+COMMENT ON COLUMN "material_request"."receive_by" IS '接料人';
+COMMENT ON COLUMN "material_request"."source" IS '来源 PLAN/REFILL';
+COMMENT ON COLUMN "material_request"."over_qty" IS '超出 BOM 需求的数量';
+COMMENT ON COLUMN "material_request"."over_reason" IS '超领原因 损耗/报废/返修/其他';
+COMMENT ON COLUMN "material_request"."ref_report_no" IS '关联数量不符单号';
+COMMENT ON COLUMN "material_request"."need_agv" IS '是否需要AGV配送到接驳台';
+COMMENT ON COLUMN "material_request"."batch_no" IS '发料批次号(分批出库时填写)';
+COMMENT ON COLUMN "material_request"."operator" IS '操作人';
+COMMENT ON COLUMN "material_request"."created_at" IS '创建时间';
+COMMENT ON COLUMN "material_request"."updated_at" IS '更新时间';
+COMMENT ON COLUMN "material_request"."sn_mode" IS '是否逐件SN管理(冗余自物料档案 sn_mode,出库口径唯一依据):1 序列号件(逐件SN) / 2 批次件';
+COMMENT ON TABLE "materials" IS 'Material 物料主数据 MES 本地副本(两库对等双向同步,2026-09-29 定稿 M1)。';
+COMMENT ON COLUMN "materials"."id" IS '主键ID';
+COMMENT ON COLUMN "materials"."code" IS '物料编码(图号),两库同步唯一业务键';
+COMMENT ON COLUMN "materials"."name" IS '物料名称';
+COMMENT ON COLUMN "materials"."spec" IS '规格型号';
+COMMENT ON COLUMN "materials"."unit" IS '计量单位';
+COMMENT ON COLUMN "materials"."description" IS '说明';
+COMMENT ON COLUMN "materials"."item_type" IS '品类 1原材料/3成品/4其他(半成品不是物料品类)';
+COMMENT ON COLUMN "materials"."manage_mode" IS '类型 1结构件/2电气件/3其他(仅分类,不决定SN行为)';
+COMMENT ON COLUMN "materials"."template_code" IS '模板编码';
+COMMENT ON COLUMN "materials"."safety_stock" IS '安全库存(低于触发缺货预警)';
+COMMENT ON COLUMN "materials"."is_active" IS '启用/停用(两库均不物理删除)';
+COMMENT ON COLUMN "materials"."sync_pending" IS '推送WMS失败标记,列表请求时异步重推';
+COMMENT ON COLUMN "materials"."created_at" IS '创建时间';
+COMMENT ON COLUMN "materials"."updated_at" IS '更新时间';
+COMMENT ON COLUMN "materials"."sn_mode" IS '是否逐件SN管理 0未选择(必填)/1序列号件(录SN)/2批次件(不录SN)';
+COMMENT ON TABLE "permission" IS 'Permission 权限/菜单';
+COMMENT ON COLUMN "permission"."id" IS '主键ID';
+COMMENT ON COLUMN "permission"."code" IS '权限编码';
+COMMENT ON COLUMN "permission"."name" IS '名称';
+COMMENT ON COLUMN "permission"."type" IS 'MENU / BUTTON';
+COMMENT ON COLUMN "permission"."parent_code" IS '所属菜单权限码(按钮必填)';
+COMMENT ON COLUMN "permission"."path" IS '前端路由';
+COMMENT ON COLUMN "permission"."icon" IS '图标';
+COMMENT ON COLUMN "permission"."sort" IS '排序';
+COMMENT ON COLUMN "permission"."remark" IS '备注';
+COMMENT ON COLUMN "permission"."created_at" IS '创建时间';
+COMMENT ON TABLE "plc_send_log" IS 'PlcSendLog PLC 工序码下发日志';
+COMMENT ON COLUMN "plc_send_log"."id" IS '主键ID';
+COMMENT ON COLUMN "plc_send_log"."order_no" IS '工单号';
+COMMENT ON COLUMN "plc_send_log"."sn" IS '工件SN';
+COMMENT ON COLUMN "plc_send_log"."station_no" IS '工位号';
+COMMENT ON COLUMN "plc_send_log"."process_combination" IS '工序组合,如 135';
+COMMENT ON COLUMN "plc_send_log"."process_codes" IS '工序码表';
+COMMENT ON COLUMN "plc_send_log"."status" IS 'PENDING / SENT / DONE / TIMEOUT / REPLY_NG';
+COMMENT ON COLUMN "plc_send_log"."send_time" IS '下发时间';
+COMMENT ON COLUMN "plc_send_log"."done_time" IS '收到完成信号时间';
+COMMENT ON COLUMN "plc_send_log"."ack" IS '是否收到完成信号';
+COMMENT ON COLUMN "plc_send_log"."remark" IS '备注';
+COMMENT ON COLUMN "plc_send_log"."operator" IS '操作人';
+COMMENT ON COLUMN "plc_send_log"."created_at" IS '创建时间';
+COMMENT ON TABLE "process_flow" IS 'ProcessFlow 工艺流程图(菜谱):描述“这个工位怎么干”,承载工艺图纸 PDF + 工序步骤模板。';
+COMMENT ON COLUMN "process_flow"."id" IS '主键ID';
+COMMENT ON COLUMN "process_flow"."name" IS '流程名称,如 3号工位装配流程';
+COMMENT ON COLUMN "process_flow"."pdf_file" IS '工艺图纸文件名';
+COMMENT ON COLUMN "process_flow"."status" IS 'ACTIVE / INACTIVE';
+COMMENT ON COLUMN "process_flow"."remark" IS '备注';
+COMMENT ON COLUMN "process_flow"."created_at" IS '创建时间';
+COMMENT ON COLUMN "process_flow"."updated_at" IS '更新时间';
+COMMENT ON TABLE "process_step" IS 'ProcessStep 工序步骤模板:一份工艺流程包含多个采集/考核步骤(按 seq 顺序执行)';
+COMMENT ON COLUMN "process_step"."id" IS '主键ID';
+COMMENT ON COLUMN "process_step"."flow_id" IS '所属工艺流程图ID';
+COMMENT ON COLUMN "process_step"."seq" IS '步骤序号';
+COMMENT ON COLUMN "process_step"."name" IS '步骤名称';
+COMMENT ON COLUMN "process_step"."collect_type" IS 'AUTO/MANUAL/NONE';
+COMMENT ON COLUMN "process_step"."is_torque" IS '是否拧紧采集';
+COMMENT ON COLUMN "process_step"."need_check" IS '是否需要检测确认(报工前须检验通过)';
+COMMENT ON COLUMN "process_step"."attachment" IS '本步骤图纸/附件列表 [{name,url}]';
+COMMENT ON COLUMN "process_step"."remark" IS '备注';
+COMMENT ON COLUMN "process_step"."created_at" IS '创建时间';
+COMMENT ON COLUMN "process_step"."need_operator_sign" IS '是否需要操作工签字(报工前须签字确认)';
+COMMENT ON COLUMN "process_step"."need_inspector_sign" IS '是否需要检验员签字(审核通过并签字后放行)';
+COMMENT ON TABLE "role" IS 'Role 角色:承载菜单/按钮权限';
+COMMENT ON COLUMN "role"."id" IS '主键ID';
+COMMENT ON COLUMN "role"."name" IS '角色名称';
+COMMENT ON COLUMN "role"."code" IS '角色编码';
+COMMENT ON COLUMN "role"."remark" IS '备注';
+COMMENT ON COLUMN "role"."permission_codes" IS '权限编码列表,如 produce.workorder:view';
+COMMENT ON COLUMN "role"."created_at" IS '创建时间';
+COMMENT ON TABLE "semi_flow" IS 'SemiFlow 半成品流转记录:进度快照(完成至工位N),调用 WMS /api/internal/semi/*';
+COMMENT ON COLUMN "semi_flow"."id" IS '主键ID';
+COMMENT ON COLUMN "semi_flow"."sn" IS '工件SN';
+COMMENT ON COLUMN "semi_flow"."order_no" IS '关联工单号';
+COMMENT ON COLUMN "semi_flow"."done_process_codes" IS '已完成工序码(已废除,历史数据保留)';
+COMMENT ON COLUMN "semi_flow"."completed_text" IS '完成至工位快照(如:已完成至工位3;空=尚未报工)';
+COMMENT ON COLUMN "semi_flow"."action" IS 'INBOUND / OUTBOUND';
+COMMENT ON COLUMN "semi_flow"."target_dock" IS '目标接驳台';
+COMMENT ON COLUMN "semi_flow"."operator" IS '操作人';
+COMMENT ON COLUMN "semi_flow"."created_at" IS '创建时间';
+COMMENT ON TABLE "station" IS 'Station 工位主数据:工位固定只对应一个工序编号,绑定一个工艺流程图(flowId)';
+COMMENT ON COLUMN "station"."id" IS '主键ID';
+COMMENT ON COLUMN "station"."station_no" IS '工位号 1..12';
+COMMENT ON COLUMN "station"."name" IS '工位名称';
+COMMENT ON COLUMN "station"."flow_id" IS '绑定工艺流程图ID';
+COMMENT ON COLUMN "station"."station_type" IS '工位类型 LINE/OFFLINE';
+COMMENT ON COLUMN "station"."status" IS 'ENABLED / DISABLED';
+COMMENT ON COLUMN "station"."is_builtin" IS '内置工位:不可改类型/不可删除';
+COMMENT ON COLUMN "station"."has_dock" IS '是否有接驳台(实体位置,内置不可改)';
+COMMENT ON COLUMN "station"."dock_code" IS '接驳台编码 DOCK01..21';
+COMMENT ON COLUMN "station"."visible_tabs" IS '终端可见页签(按工位配置,2026-09-23):空=全部显示(兼容存量工位); 可选值 online(上线建档)/work(作业)/material(物料叫料)/move(产线点位:上料/下料,历史 key 沿用)/pdf(工艺文件)/inspect(巡检异常)/offline(下线完工)';
+COMMENT ON COLUMN "station"."created_at" IS '创建时间';
+COMMENT ON TABLE "station_state" IS 'StationState 工位运行状态(当日有效):工人自主 停止接单/恢复接单。';
+COMMENT ON COLUMN "station_state"."id" IS '主键ID';
+COMMENT ON COLUMN "station_state"."station_no" IS '工位号';
+COMMENT ON COLUMN "station_state"."date" IS '生效日期 yyyy-MM-dd(只认当天)';
+COMMENT ON COLUMN "station_state"."paused" IS '是否停止接单';
+COMMENT ON COLUMN "station_state"."reason" IS '停单原因(缺料/故障/其他)';
+COMMENT ON COLUMN "station_state"."operator" IS '操作人';
+COMMENT ON COLUMN "station_state"."created_at" IS '创建时间';
+COMMENT ON COLUMN "station_state"."updated_at" IS '更新时间';
+COMMENT ON TABLE "step_criterion" IS 'StepCriterion 工序步骤考核标准:如 扭矩在RANGE[35,45] 自动判定 OK';
+COMMENT ON COLUMN "step_criterion"."id" IS '主键ID';
+COMMENT ON COLUMN "step_criterion"."step_id" IS '步骤ID';
+COMMENT ON COLUMN "step_criterion"."name" IS '指标名,如 扭矩/角度';
+COMMENT ON COLUMN "step_criterion"."unit" IS '单位';
+COMMENT ON COLUMN "step_criterion"."logic" IS 'GE / LE / GT / LT / RANGE / EQUAL / NONE';
+COMMENT ON COLUMN "step_criterion"."target" IS '目标值';
+COMMENT ON COLUMN "step_criterion"."min" IS '范围下限';
+COMMENT ON COLUMN "step_criterion"."max" IS '范围上限';
+COMMENT ON COLUMN "step_criterion"."created_at" IS '创建时间';
+COMMENT ON TABLE "step_data" IS 'StepData 步骤考核数据:某工件某工序步骤采集/手填实际值,按考核标准判定 OK/NG';
+COMMENT ON COLUMN "step_data"."id" IS '主键ID';
+COMMENT ON COLUMN "step_data"."sn" IS '工件SN';
+COMMENT ON COLUMN "step_data"."process_id" IS '工件工序实绩ID';
+COMMENT ON COLUMN "step_data"."step_id" IS '步骤ID';
+COMMENT ON COLUMN "step_data"."step_name" IS '工序名称';
+COMMENT ON COLUMN "step_data"."criterion_id" IS '考核标准ID';
+COMMENT ON COLUMN "step_data"."criterion_name" IS '判据名称';
+COMMENT ON COLUMN "step_data"."criterion_logic" IS '判据逻辑';
+COMMENT ON COLUMN "step_data"."value" IS '实际测量值';
+COMMENT ON COLUMN "step_data"."value_text" IS '文本值(OK/NG/钢印号)';
+COMMENT ON COLUMN "step_data"."is_ok" IS '是否合格';
+COMMENT ON COLUMN "step_data"."operator" IS '操作人';
+COMMENT ON COLUMN "step_data"."created_at" IS '创建时间';
+COMMENT ON TABLE "step_sign_record" IS 'StepSignRecord 步骤签字记录:工艺步骤配置 need_operator_sign/need_inspector_sign 后,';
+COMMENT ON COLUMN "step_sign_record"."id" IS '主键ID';
+COMMENT ON COLUMN "step_sign_record"."sn" IS '工件SN';
+COMMENT ON COLUMN "step_sign_record"."order_no" IS '工单号';
+COMMENT ON COLUMN "step_sign_record"."flow_id" IS '工艺流程ID';
+COMMENT ON COLUMN "step_sign_record"."station_no" IS '工位号';
+COMMENT ON COLUMN "step_sign_record"."step_id" IS '工艺步骤ID';
+COMMENT ON COLUMN "step_sign_record"."step_name" IS '步骤名称';
+COMMENT ON COLUMN "step_sign_record"."sign_role" IS '签字角色 OPERATOR/INSPECTOR';
+COMMENT ON COLUMN "step_sign_record"."result" IS '签字时点的结论 OK/NG';
+COMMENT ON COLUMN "step_sign_record"."signed_by" IS '签字人(登录账号)';
+COMMENT ON COLUMN "step_sign_record"."signed_at" IS '签字时间';
+COMMENT ON COLUMN "step_sign_record"."round" IS '返修重做轮次(1=首做)';
+COMMENT ON COLUMN "step_sign_record"."source" IS '签字来源 station/inspect/migrate';
+COMMENT ON COLUMN "step_sign_record"."remark" IS '签字备注(签字弹框选填)';
+COMMENT ON COLUMN "step_sign_record"."revoked" IS '是否已撤销';
+COMMENT ON COLUMN "step_sign_record"."revoked_by" IS '撤销人';
+COMMENT ON COLUMN "step_sign_record"."revoked_at" IS '撤销时间';
+COMMENT ON COLUMN "step_sign_record"."revoke_reason" IS '撤销原因';
+COMMENT ON COLUMN "step_sign_record"."created_at" IS '创建时间';
+COMMENT ON TABLE "sys_config" IS 'SysConfig 系统基础设置(key/value)。';
+COMMENT ON COLUMN "sys_config"."id" IS '主键ID';
+COMMENT ON COLUMN "sys_config"."key" IS '配置键,如 wms.base_url';
+COMMENT ON COLUMN "sys_config"."value" IS '配置值';
+COMMENT ON COLUMN "sys_config"."remark" IS '说明';
+COMMENT ON TABLE "torque_record" IS 'TorqueRecord 拧紧数据(工位终端上报,sn,strain扭矩,angle角度,result,operator,workOrder,time)';
+COMMENT ON COLUMN "torque_record"."id" IS '主键ID';
+COMMENT ON COLUMN "torque_record"."work_order_no" IS 'workOrder 工单号';
+COMMENT ON COLUMN "torque_record"."sn" IS '工件SN';
+COMMENT ON COLUMN "torque_record"."screw_no" IS '螺丝编号 S1..Sn';
+COMMENT ON COLUMN "torque_record"."strain" IS '扭矩 Nm';
+COMMENT ON COLUMN "torque_record"."torque" IS '扭矩别名,与 strain 一致';
+COMMENT ON COLUMN "torque_record"."angle" IS '角度 °';
+COMMENT ON COLUMN "torque_record"."result" IS 'OK / NG';
+COMMENT ON COLUMN "torque_record"."operator" IS '操作人';
+COMMENT ON COLUMN "torque_record"."station_no" IS '工位';
+COMMENT ON COLUMN "torque_record"."time" IS '采集时间';
+COMMENT ON COLUMN "torque_record"."created_at" IS '创建时间';
+COMMENT ON COLUMN "torque_record"."operator_id" IS '操作人用户ID(0=未采集:虚拟工位/PLC路径或历史数据)';
+COMMENT ON TABLE "user" IS 'User 用户';
+COMMENT ON COLUMN "user"."id" IS '主键ID';
+COMMENT ON COLUMN "user"."username" IS '登录名';
+COMMENT ON COLUMN "user"."password" IS 'bcrypt 密码';
+COMMENT ON COLUMN "user"."name" IS '姓名/显示名';
+COMMENT ON COLUMN "user"."role_id" IS '角色ID';
+COMMENT ON COLUMN "user"."can_login_workstation" IS '是否允许登录工位终端';
+COMMENT ON COLUMN "user"."workstation_password" IS '工位终端密码(bcrypt)';
+COMMENT ON COLUMN "user"."status" IS 'ENABLED / DISABLED';
+COMMENT ON COLUMN "user"."last_login_at" IS '最近登录时间(unix秒,后台登录更新;工位终端登录不计)';
+COMMENT ON COLUMN "user"."created_at" IS '创建时间';
+COMMENT ON COLUMN "user"."updated_at" IS '更新时间';
+COMMENT ON TABLE "user_station" IS 'UserStation 用户-工位 关联(一个操作员可绑定多个工位)';
+COMMENT ON COLUMN "user_station"."id" IS '主键ID';
+COMMENT ON COLUMN "user_station"."user_id" IS '用户ID';
+COMMENT ON COLUMN "user_station"."station_no" IS '工位号 1..12';
+COMMENT ON COLUMN "user_station"."created_at" IS '创建时间';
+COMMENT ON TABLE "work_order" IS 'WorkOrder 工单:一个合同 = 一个工单';
+COMMENT ON COLUMN "work_order"."id" IS '主键ID';
+COMMENT ON COLUMN "work_order"."work_order_no" IS '工单号';
+COMMENT ON COLUMN "work_order"."product_type_id" IS '产品类型ID';
+COMMENT ON COLUMN "work_order"."product_code" IS '产品编码';
+COMMENT ON COLUMN "work_order"."product_name" IS '产品名称';
+COMMENT ON COLUMN "work_order"."quantity" IS '工件数量';
+COMMENT ON COLUMN "work_order"."finished_num" IS '完成数量';
+COMMENT ON COLUMN "work_order"."fail_num" IS 'NG数量';
+COMMENT ON COLUMN "work_order"."contract_no" IS '归属编号(合同号或科技项目号,随归属类型二选一)';
+COMMENT ON COLUMN "work_order"."project_no" IS '工程编号(已废弃,保留防历史数据迁移)';
+COMMENT ON COLUMN "work_order"."product_serial" IS '产品序号(工单内每台产品的序号)';
+COMMENT ON COLUMN "work_order"."created_by" IS '创建人';
+COMMENT ON COLUMN "work_order"."due_date" IS '完成日期(必填)';
+COMMENT ON COLUMN "work_order"."flow_combination" IS '工艺组合 [{flowId,stationNo}] 按工位号升序';
+COMMENT ON COLUMN "work_order"."status" IS 'CREATED / RELEASED / IN_PROGRESS / COMPLETED / CLOSED';
+COMMENT ON COLUMN "work_order"."plan_start" IS '计划开始';
+COMMENT ON COLUMN "work_order"."plan_end" IS '计划结束';
+COMMENT ON COLUMN "work_order"."context" IS '扩展字段';
+COMMENT ON COLUMN "work_order"."completed_at" IS '完成时间';
+COMMENT ON COLUMN "work_order"."created_at" IS '创建时间';
+COMMENT ON COLUMN "work_order"."updated_at" IS '更新时间';
+COMMENT ON COLUMN "work_order"."ownership_type" IS '归属类型:workorder=合同号/project=科技项目号/other=其他';
+COMMENT ON TABLE "workpiece" IS 'Workpiece 工件(SN):序列号管理的成品/主件';
+COMMENT ON COLUMN "workpiece"."id" IS '主键ID';
+COMMENT ON COLUMN "workpiece"."sn" IS '工件唯一SN';
+COMMENT ON COLUMN "workpiece"."order_no" IS '所属工单';
+COMMENT ON COLUMN "workpiece"."work_order_id" IS '工单ID';
+COMMENT ON COLUMN "workpiece"."current_station_no" IS '最后完成报工的工位号(0=未报任何工艺;下一道=工艺组合中工位号更大的下一条)';
+COMMENT ON COLUMN "workpiece"."status" IS 'ONLINE(已进线) / PROCESSING(在工位) / DONE(完工) / REPAIR / SCRAPPED';
+COMMENT ON COLUMN "workpiece"."online_at" IS '进线时间';
+COMMENT ON COLUMN "workpiece"."done_at" IS '完工时间';
+COMMENT ON COLUMN "workpiece"."created_at" IS '创建时间';
+COMMENT ON COLUMN "workpiece"."updated_at" IS '更新时间';
+COMMENT ON TABLE "workpiece_bind" IS 'WorkpieceBind 装机绑定:某工件在某一工序装配时,把实际装上的部件(结构件=批次号 / 电气件=SN)';
+COMMENT ON COLUMN "workpiece_bind"."id" IS '主键ID';
+COMMENT ON COLUMN "workpiece_bind"."sn" IS '工件SN';
+COMMENT ON COLUMN "workpiece_bind"."order_no" IS '工单号';
+COMMENT ON COLUMN "workpiece_bind"."flow_id" IS '装配工艺ID';
+COMMENT ON COLUMN "workpiece_bind"."station_no" IS '绑定工位';
+COMMENT ON COLUMN "workpiece_bind"."material_code" IS '物料编码';
+COMMENT ON COLUMN "workpiece_bind"."material_name" IS '物料名称';
+COMMENT ON COLUMN "workpiece_bind"."spec" IS '规格';
+COMMENT ON COLUMN "workpiece_bind"."unit" IS '单位';
+COMMENT ON COLUMN "workpiece_bind"."bind_value" IS '绑定值:批次号 或 SN';
+COMMENT ON COLUMN "workpiece_bind"."bind_type" IS 'BATCH(批次绑定) / SN(序列号绑定),冗余自 snMode 便于直接展示';
+COMMENT ON COLUMN "workpiece_bind"."operator" IS '操作人';
+COMMENT ON COLUMN "workpiece_bind"."created_at" IS '绑定时间';
+COMMENT ON COLUMN "workpiece_bind"."sn_mode" IS '是否逐件SN管理(冗余自物料档案 sn_mode,追溯展示/绑定口径依据):1 序列号件(SN) / 2 批次件';
+COMMENT ON TABLE "workpiece_process" IS 'WorkpieceProcess 工件-工艺实绩(某工件在某工位完成某道工艺的一次记录,构成工艺时间线)。';
+COMMENT ON COLUMN "workpiece_process"."id" IS '主键ID';
+COMMENT ON COLUMN "workpiece_process"."sn" IS '工件SN';
+COMMENT ON COLUMN "workpiece_process"."flow_id" IS '完成的工艺ID';
+COMMENT ON COLUMN "workpiece_process"."station_no" IS '工位号';
+COMMENT ON COLUMN "workpiece_process"."order_no" IS '关联工单号';
+COMMENT ON COLUMN "workpiece_process"."process_name" IS '工序名称';
+COMMENT ON COLUMN "workpiece_process"."status" IS 'PENDING / DOING / DONE / NG / REPAIRED';
+COMMENT ON COLUMN "workpiece_process"."operator" IS '操作人';
+COMMENT ON COLUMN "workpiece_process"."result" IS '总判定 OK/NG';
+COMMENT ON COLUMN "workpiece_process"."started_at" IS '开始时间';
+COMMENT ON COLUMN "workpiece_process"."ended_at" IS '结束时间';
+COMMENT ON COLUMN "workpiece_process"."duration_sec" IS '作业时长(秒)=endedAt-startedAt';
+COMMENT ON COLUMN "workpiece_process"."remark" IS '备注';
+COMMENT ON COLUMN "workpiece_process"."created_at" IS '创建时间';
+COMMENT ON COLUMN "workpiece_process"."operator_id" IS '操作人用户ID(0=未采集:虚拟工位/PLC路径或历史数据)';
diff --git a/sql/db_comments_wms.sql b/sql/db_comments_wms.sql
new file mode 100644
index 0000000..086a771
--- /dev/null
+++ b/sql/db_comments_wms.sql
@@ -0,0 +1,342 @@
+-- ============================================================
+-- WMS 数据库 表/列 注释(COMMENT ON),可重复执行
+-- 由 ent schema 源文件抽取生成;表名/列名均以真实库目录为准
+-- ============================================================
+
+COMMENT ON TABLE "agv_tasks" IS 'AgvTask AGV 搬运任务记录:仓管下发后落库,用于状态跟踪/追溯。';
+COMMENT ON COLUMN "agv_tasks"."id" IS '主键ID';
+COMMENT ON COLUMN "agv_tasks"."task_no" IS '我方任务号(内部)';
+COMMENT ON COLUMN "agv_tasks"."hik_task_code" IS '海康返回 robotTaskCode(MOCK- 开头为模拟)';
+COMMENT ON COLUMN "agv_tasks"."source_dock" IS '起点接驳台(常为 DOCK21 库房)';
+COMMENT ON COLUMN "agv_tasks"."target_dock" IS '终点接驳台 DOCK01..20';
+COMMENT ON COLUMN "agv_tasks"."materials_json" IS '物料清单 JSON';
+COMMENT ON COLUMN "agv_tasks"."related_outbound_no" IS '关联出库单号(可选)';
+COMMENT ON COLUMN "agv_tasks"."status" IS 'PENDING/DISPATCHED/DELIVERING/DONE/FAILED/CANCELLED';
+COMMENT ON COLUMN "agv_tasks"."operator" IS '下发人';
+COMMENT ON COLUMN "agv_tasks"."dispatched_at" IS '下发时间 unix秒';
+COMMENT ON COLUMN "agv_tasks"."arrived_at" IS '到位时间 unix秒';
+COMMENT ON COLUMN "agv_tasks"."remark" IS '备注/失败原因';
+COMMENT ON COLUMN "agv_tasks"."created_at" IS '创建时间';
+COMMENT ON TABLE "attachments" IS 'Attachment 附件(挂载在业务单据/档案上的文件)';
+COMMENT ON COLUMN "attachments"."id" IS '主键ID';
+COMMENT ON COLUMN "attachments"."biz_type" IS '业务类型 inbound/material/inspection/semi/outbound';
+COMMENT ON COLUMN "attachments"."biz_id" IS '业务对象标识(单号/编码/ID)';
+COMMENT ON COLUMN "attachments"."file_name" IS '原始文件名(含扩展名)';
+COMMENT ON COLUMN "attachments"."file_path" IS '磁盘相对路径(年/月/日/文件类型/uuid.ext)';
+COMMENT ON COLUMN "attachments"."file_type" IS '文件类型大写枚举 PROCESS_PDF/INSPECTION_PHOTO/...';
+COMMENT ON COLUMN "attachments"."file_ext" IS '扩展名(小写,不含点)';
+COMMENT ON COLUMN "attachments"."file_md5" IS '文件MD5(秒传/去重)';
+COMMENT ON COLUMN "attachments"."file_size" IS '文件大小(字节)';
+COMMENT ON COLUMN "attachments"."mime_type" IS 'MIME 类型';
+COMMENT ON COLUMN "attachments"."uploaded_by" IS '上传人';
+COMMENT ON COLUMN "attachments"."archived" IS '是否已归档(备份到外部存储)';
+COMMENT ON COLUMN "attachments"."archived_at" IS '归档时间(unix秒)';
+COMMENT ON COLUMN "attachments"."deleted" IS '逻辑删除标记';
+COMMENT ON COLUMN "attachments"."deleted_at" IS '删除时间(unix秒)';
+COMMENT ON COLUMN "attachments"."deleted_by" IS '删除人';
+COMMENT ON COLUMN "attachments"."created_at" IS '创建时间';
+COMMENT ON TABLE "event_log" IS 'EventLog 操作日志(事件审计)';
+COMMENT ON COLUMN "event_log"."id" IS '主键ID';
+COMMENT ON COLUMN "event_log"."event_type" IS '事件类型,如 user.create / inbound.create / auth.login';
+COMMENT ON COLUMN "event_log"."operator" IS '操作人';
+COMMENT ON COLUMN "event_log"."entity_type" IS '对象类型,如 user/role/material/inbound/outbound';
+COMMENT ON COLUMN "event_log"."entity_id" IS '对象标识:主键ID或业务单号';
+COMMENT ON COLUMN "event_log"."description" IS '事件描述';
+COMMENT ON COLUMN "event_log"."payload" IS '扩展负载';
+COMMENT ON COLUMN "event_log"."created_at" IS '发生时间';
+COMMENT ON TABLE "inbound_details" IS 'InboundDetail 入库明细(一张入库单可含多行)';
+COMMENT ON COLUMN "inbound_details"."id" IS '主键ID';
+COMMENT ON COLUMN "inbound_details"."inbound_no" IS '入库单号';
+COMMENT ON COLUMN "inbound_details"."sn_code" IS 'SN(电气件)';
+COMMENT ON COLUMN "inbound_details"."batch_no" IS '批次号(结构件)';
+COMMENT ON COLUMN "inbound_details"."material_code" IS '物料编码';
+COMMENT ON COLUMN "inbound_details"."quantity" IS '数量';
+COMMENT ON COLUMN "inbound_details"."created_at" IS '创建时间';
+COMMENT ON TABLE "inbound_orders" IS 'InboundOrder 入库单';
+COMMENT ON COLUMN "inbound_orders"."id" IS '主键ID';
+COMMENT ON COLUMN "inbound_orders"."inbound_no" IS '入库单号';
+COMMENT ON COLUMN "inbound_orders"."inbound_type" IS '入库类型 purchase/semi/finished/return/other';
+COMMENT ON COLUMN "inbound_orders"."material_code" IS '物料编码';
+COMMENT ON COLUMN "inbound_orders"."material_name" IS '物料名称(冗余)';
+COMMENT ON COLUMN "inbound_orders"."manage_mode" IS '类型 1结构件/2电气件/3其他';
+COMMENT ON COLUMN "inbound_orders"."batch_no" IS '批次号(结构件)';
+COMMENT ON COLUMN "inbound_orders"."zone_code" IS '入库区域(大区)';
+COMMENT ON COLUMN "inbound_orders"."shelf_no" IS '货架号(如 A)';
+COMMENT ON COLUMN "inbound_orders"."layer_no" IS '第几层(如 3)';
+COMMENT ON COLUMN "inbound_orders"."position_no" IS '位置号(如 12)';
+COMMENT ON COLUMN "inbound_orders"."quantity" IS '本次入库总数量(批次合计或SN条数)';
+COMMENT ON COLUMN "inbound_orders"."operator" IS '操作人';
+COMMENT ON COLUMN "inbound_orders"."remark" IS '备注';
+COMMENT ON COLUMN "inbound_orders"."inspection_no" IS '检测单号(入库检报告单号)';
+COMMENT ON COLUMN "inbound_orders"."ownership_type" IS '归属类型 workorder/project/none';
+COMMENT ON COLUMN "inbound_orders"."ownership_no" IS '归属编号(合同号/科技项目号)';
+COMMENT ON COLUMN "inbound_orders"."quality_status" IS '质量状态 合格/不合格/部分(空=未关联检验)';
+COMMENT ON COLUMN "inbound_orders"."voided" IS '是否已作废';
+COMMENT ON COLUMN "inbound_orders"."void_reason" IS '作废原因';
+COMMENT ON COLUMN "inbound_orders"."voided_by" IS '作废人';
+COMMENT ON COLUMN "inbound_orders"."voided_at" IS '作废时间(unix秒)';
+COMMENT ON COLUMN "inbound_orders"."created_at" IS '创建时间';
+COMMENT ON COLUMN "inbound_orders"."product_work_no" IS '产品工号(手填)';
+COMMENT ON COLUMN "inbound_orders"."sn_mode" IS 'SN管理 1序列号件(逐件SN)/2批次件(数量)/0未选择';
+COMMENT ON TABLE "inspection_records" IS 'InspectionRecord 检验记录';
+COMMENT ON COLUMN "inspection_records"."id" IS '主键ID';
+COMMENT ON COLUMN "inspection_records"."target_type" IS 'BATCH/SN';
+COMMENT ON COLUMN "inspection_records"."target_id" IS '批次号或 SN';
+COMMENT ON COLUMN "inspection_records"."material_code" IS '物料编码';
+COMMENT ON COLUMN "inspection_records"."material_name" IS '物料名称(冗余,列表直接展示/模糊查询)';
+COMMENT ON COLUMN "inspection_records"."ownership_type" IS '归属类型 workorder/project/other';
+COMMENT ON COLUMN "inspection_records"."ownership_no" IS '归属编号(工单号/科技项目号/其他)';
+COMMENT ON COLUMN "inspection_records"."related_standard" IS '相关标准(检验细则号)';
+COMMENT ON COLUMN "inspection_records"."manufacturer" IS '生产厂家';
+COMMENT ON COLUMN "inspection_records"."inspection_type" IS '来料检(过程检/完工检已移至 MES)';
+COMMENT ON COLUMN "inspection_records"."status" IS '未检/合格/不合格';
+COMMENT ON COLUMN "inspection_records"."result_value" IS '实测值(部分检验项)';
+COMMENT ON COLUMN "inspection_records"."inspect_qty" IS '检验数量(抽检件数)';
+COMMENT ON COLUMN "inspection_records"."pass_qty" IS '合格数量(≤检验数量)';
+COMMENT ON COLUMN "inspection_records"."reject_qty" IS '不合格数量(=检验数量-合格数量)';
+COMMENT ON COLUMN "inspection_records"."check_desc" IS '检测说明(检验项目/方法)';
+COMMENT ON COLUMN "inspection_records"."inspector" IS '检验人';
+COMMENT ON COLUMN "inspection_records"."inspection_no" IS '检测单号(检验报告单号)';
+COMMENT ON COLUMN "inspection_records"."report_no" IS '报检单号(生产报检关联)';
+COMMENT ON COLUMN "inspection_records"."disposal_type" IS '不合格处置 NONE/RETURN/SCRAP/PARTIAL';
+COMMENT ON COLUMN "inspection_records"."disposal_remark" IS '处置说明(报废/退货原因)';
+COMMENT ON COLUMN "inspection_records"."return_tracking_no" IS '退货货运单号';
+COMMENT ON COLUMN "inspection_records"."remark" IS '备注';
+COMMENT ON COLUMN "inspection_records"."created_at" IS '创建时间';
+COMMENT ON COLUMN "inspection_records"."updated_at" IS '更新时间';
+COMMENT ON COLUMN "inspection_records"."product_work_no" IS '产品工号(随入库单带入,来料检验展示/筛选)';
+COMMENT ON COLUMN "inspection_records"."batch_seq" IS '第几批(批次件来料检验必填≥1,0=未填)';
+COMMENT ON COLUMN "inspection_records"."batch_total" IS '共几件(批次件来料检验必填≥1,0=未填)';
+COMMENT ON TABLE "inventories" IS 'Inventory 统一库存台账';
+COMMENT ON COLUMN "inventories"."id" IS '主键ID';
+COMMENT ON COLUMN "inventories"."manage_mode" IS '类型 1结构件/2电气件/3其他';
+COMMENT ON COLUMN "inventories"."category" IS '品类 1=原材料 2=半成品 3=成品';
+COMMENT ON COLUMN "inventories"."material_code" IS '物料编码(关联 materials 表)';
+COMMENT ON COLUMN "inventories"."material_name" IS '物料名称(冗余,便于直接展示)';
+COMMENT ON COLUMN "inventories"."batch_no" IS '批次号(系统生成);序列号件可关联所属批次';
+COMMENT ON COLUMN "inventories"."sn_code" IS '序列号(SN,仅序列号件);全局唯一,空值表示非 SN 行';
+COMMENT ON COLUMN "inventories"."quantity" IS '数量:批次件=批次余量;序列号件=1';
+COMMENT ON COLUMN "inventories"."locked_qty" IS '已锁定数量(库存占用):批次件=件数;序列号件=0/1';
+COMMENT ON COLUMN "inventories"."quality_status" IS '检验状态 未检/合格/不合格';
+COMMENT ON COLUMN "inventories"."zone_code" IS '所在区域(Z01~Z04 大分区)';
+COMMENT ON COLUMN "inventories"."shelf_no" IS '货架号(手填,如 A)';
+COMMENT ON COLUMN "inventories"."layer_no" IS '第几层(手填,如 3)';
+COMMENT ON COLUMN "inventories"."position_no" IS '位置号(手填,如 12)';
+COMMENT ON COLUMN "inventories"."status" IS '生命周期:在库/锁定/出库/使用/报废(序列号件用;批次件恒在库)';
+COMMENT ON COLUMN "inventories"."production_date" IS '生产日期';
+COMMENT ON COLUMN "inventories"."supplier" IS '供应商';
+COMMENT ON COLUMN "inventories"."inbound_no" IS '关联入库单号';
+COMMENT ON COLUMN "inventories"."order_no" IS '关联工单号(半成品/成品回流)';
+COMMENT ON COLUMN "inventories"."completed_process" IS '已完成工序(半成品用,如 135)';
+COMMENT ON COLUMN "inventories"."ownership_type" IS '归属类型 workorder/project/other';
+COMMENT ON COLUMN "inventories"."ownership_no" IS '归属编号(工单号/科技项目号/其他)';
+COMMENT ON COLUMN "inventories"."product_status" IS '产品状态 已通过/部分通过/返修(成品用)';
+COMMENT ON COLUMN "inventories"."related_standard" IS '相关标准(试验方案号)';
+COMMENT ON COLUMN "inventories"."test_record_no" IS '试验记录单号';
+COMMENT ON COLUMN "inventories"."recorded_by" IS '记录员';
+COMMENT ON COLUMN "inventories"."recorded_at" IS '记录日期(unix 秒)';
+COMMENT ON COLUMN "inventories"."outbound_reason" IS '出库原因(半成品/成品出库用)';
+COMMENT ON COLUMN "inventories"."stocktake_no" IS '盘点冻结标记(进行中盘点单号;空=未冻结)';
+COMMENT ON COLUMN "inventories"."remark" IS '备注';
+COMMENT ON COLUMN "inventories"."created_at" IS '创建时间';
+COMMENT ON COLUMN "inventories"."updated_at" IS '更新时间';
+COMMENT ON COLUMN "inventories"."product_work_no" IS '产品工号(贯穿库存,出库/检验/半成品带出展示)';
+COMMENT ON COLUMN "inventories"."sn_mode" IS 'SN管理 1序列号件(逐件SN)/2批次件(数量)/0未选择';
+COMMENT ON TABLE "inventory_locks" IS 'InventoryLock 库存锁定(工单锁库存,防超卖)';
+COMMENT ON COLUMN "inventory_locks"."id" IS '主键ID';
+COMMENT ON COLUMN "inventory_locks"."target_type" IS 'BATCH/SN';
+COMMENT ON COLUMN "inventory_locks"."target_id" IS '批次号或 SN';
+COMMENT ON COLUMN "inventory_locks"."material_code" IS '物料编码';
+COMMENT ON COLUMN "inventory_locks"."locked_qty" IS '锁定数量';
+COMMENT ON COLUMN "inventory_locks"."order_no" IS '关联工单号';
+COMMENT ON COLUMN "inventory_locks"."status" IS 'ACTIVE/RELEASED/CONSUMED';
+COMMENT ON COLUMN "inventory_locks"."expired_at" IS '过期时间戳';
+COMMENT ON COLUMN "inventory_locks"."remark" IS '备注';
+COMMENT ON COLUMN "inventory_locks"."created_at" IS '创建时间';
+COMMENT ON COLUMN "inventory_locks"."updated_at" IS '更新时间';
+COMMENT ON TABLE "material_demands" IS 'MaterialDemand 物料未来需求(MES 按日排产推送,WMS 备料四态“预警”判定的数据源)';
+COMMENT ON COLUMN "material_demands"."id" IS '主键ID';
+COMMENT ON COLUMN "material_demands"."material_code" IS '物料编码(图号)';
+COMMENT ON COLUMN "material_demands"."future5_qty" IS '未来5天需求量(近5天日排产×单台用量)';
+COMMENT ON COLUMN "material_demands"."updated_at" IS '更新时间(unix 秒)';
+COMMENT ON TABLE "materials" IS 'Material 物料档案(主数据)';
+COMMENT ON COLUMN "materials"."id" IS '主键ID';
+COMMENT ON COLUMN "materials"."code" IS '物料唯一编码';
+COMMENT ON COLUMN "materials"."name" IS '物料真实名称';
+COMMENT ON COLUMN "materials"."spec" IS '规格型号';
+COMMENT ON COLUMN "materials"."unit" IS '单位';
+COMMENT ON COLUMN "materials"."description" IS '描述';
+COMMENT ON COLUMN "materials"."item_type" IS '品类 1原材料/3成品/4其他(半成品不是物料品类,由库存 category=2 承载)';
+COMMENT ON COLUMN "materials"."manage_mode" IS '类型 1结构件/2电气件/3其他';
+COMMENT ON COLUMN "materials"."is_batch_managed" IS '是否批次管理(按 sn_mode=2 派生)';
+COMMENT ON COLUMN "materials"."is_serial_managed" IS '是否序列号管理(按 sn_mode=1 派生)';
+COMMENT ON COLUMN "materials"."template_code" IS '物料模板编码(物料种类)';
+COMMENT ON COLUMN "materials"."safety_stock" IS '安全库存(低于则缺货预警,0=不预警)';
+COMMENT ON COLUMN "materials"."is_active" IS '是否启用';
+COMMENT ON COLUMN "materials"."created_at" IS '创建时间';
+COMMENT ON COLUMN "materials"."updated_at" IS '更新时间';
+COMMENT ON COLUMN "materials"."sn_mode" IS 'SN管理 1序列号件(逐件SN)/2批次件(数量)/0未选择';
+COMMENT ON TABLE "order_material_ledgers" IS 'OrderMaterialLedger 工单物料台账(WMS 侧)';
+COMMENT ON COLUMN "order_material_ledgers"."id" IS '主键ID';
+COMMENT ON COLUMN "order_material_ledgers"."order_no" IS '工单号';
+COMMENT ON COLUMN "order_material_ledgers"."material_code" IS '物料编码';
+COMMENT ON COLUMN "order_material_ledgers"."material_name" IS '物料名称(冗余)';
+COMMENT ON COLUMN "order_material_ledgers"."total_qty" IS '物料总需求数量';
+COMMENT ON COLUMN "order_material_ledgers"."out_qty" IS '累计已发出数量(仅出库写入)';
+COMMENT ON COLUMN "order_material_ledgers"."returned_qty" IS '累计已退回数量(仅退库收货写入)';
+COMMENT ON COLUMN "order_material_ledgers"."consumed_qty" IS '累计已消耗数量(仅报工反冲核销写入;不动库存)';
+COMMENT ON COLUMN "order_material_ledgers"."status" IS '进行中/领料完结';
+COMMENT ON COLUMN "order_material_ledgers"."target_station" IS '目标工位(装配工位号)';
+COMMENT ON COLUMN "order_material_ledgers"."completed_at" IS '领料完结时间(unix 秒)';
+COMMENT ON COLUMN "order_material_ledgers"."remark" IS '备注';
+COMMENT ON COLUMN "order_material_ledgers"."created_at" IS '创建时间';
+COMMENT ON COLUMN "order_material_ledgers"."updated_at" IS '更新时间';
+COMMENT ON TABLE "outbound_details" IS 'OutboundDetail 出库明细(一张出库单可含多行)';
+COMMENT ON COLUMN "outbound_details"."id" IS '主键ID';
+COMMENT ON COLUMN "outbound_details"."outbound_no" IS '出库单号';
+COMMENT ON COLUMN "outbound_details"."sn_code" IS 'SN(电气件)';
+COMMENT ON COLUMN "outbound_details"."batch_no" IS '批次号(结构件)';
+COMMENT ON COLUMN "outbound_details"."material_code" IS '物料编码';
+COMMENT ON COLUMN "outbound_details"."quantity" IS '数量';
+COMMENT ON COLUMN "outbound_details"."order_no" IS '关联工单号';
+COMMENT ON COLUMN "outbound_details"."created_at" IS '创建时间';
+COMMENT ON TABLE "outbound_orders" IS 'OutboundOrder 出库统一主表';
+COMMENT ON COLUMN "outbound_orders"."id" IS '主键ID';
+COMMENT ON COLUMN "outbound_orders"."outbound_no" IS '出库单号';
+COMMENT ON COLUMN "outbound_orders"."outbound_type" IS '出库类型';
+COMMENT ON COLUMN "outbound_orders"."status" IS '出库单状态 已出库/已送达';
+COMMENT ON COLUMN "outbound_orders"."need_agv" IS '是否需要AGV配送到接驳台';
+COMMENT ON COLUMN "outbound_orders"."outbound_category" IS '出库类别 return/sample/scrap/deliver/other';
+COMMENT ON COLUMN "outbound_orders"."ownership_type" IS '归属类型 workorder/project/other';
+COMMENT ON COLUMN "outbound_orders"."ownership_no" IS '归属编号(工单号/科技项目号)';
+COMMENT ON COLUMN "outbound_orders"."target_station" IS '目标工位(装配工位号)';
+COMMENT ON COLUMN "outbound_orders"."order_no" IS '关联工单号(工单为唯一挂靠载体)';
+COMMENT ON COLUMN "outbound_orders"."material_code" IS '物料编码';
+COMMENT ON COLUMN "outbound_orders"."material_name" IS '物料名称(冗余)';
+COMMENT ON COLUMN "outbound_orders"."manage_mode" IS '类型 1结构件/2电气件/3其他';
+COMMENT ON COLUMN "outbound_orders"."batch_no" IS '批次号(结构件)';
+COMMENT ON COLUMN "outbound_orders"."zone_code" IS '出库区域(大区)';
+COMMENT ON COLUMN "outbound_orders"."shelf_no" IS '货架号(与入库同口径)';
+COMMENT ON COLUMN "outbound_orders"."layer_no" IS '第几层(与入库同口径)';
+COMMENT ON COLUMN "outbound_orders"."position_no" IS '位置号(与入库同口径)';
+COMMENT ON COLUMN "outbound_orders"."quantity" IS '本次出库总数量';
+COMMENT ON COLUMN "outbound_orders"."operator" IS '操作人';
+COMMENT ON COLUMN "outbound_orders"."reviewer" IS '复核人';
+COMMENT ON COLUMN "outbound_orders"."target_dock" IS '目标接驳台(AGV配送)';
+COMMENT ON COLUMN "outbound_orders"."remark" IS '备注';
+COMMENT ON COLUMN "outbound_orders"."box_no" IS '箱号(装箱出库时填写,用于整箱发货追溯)';
+COMMENT ON COLUMN "outbound_orders"."box_sn_list" IS '装箱 SN 清单(JSON 数组字符串)';
+COMMENT ON COLUMN "outbound_orders"."contract_no" IS '合同号(装箱选填)';
+COMMENT ON COLUMN "outbound_orders"."inspection_no" IS '检测单号(溯源关联检验单据)';
+COMMENT ON COLUMN "outbound_orders"."created_at" IS '创建时间';
+COMMENT ON COLUMN "outbound_orders"."product_work_no" IS '产品工号(随库存带入,出库记录展示/筛选)';
+COMMENT ON COLUMN "outbound_orders"."sn_mode" IS 'SN管理 1序列号件(逐件SN)/2批次件(数量)/0未选择';
+COMMENT ON TABLE "permissions" IS 'Permission 权限/菜单';
+COMMENT ON COLUMN "permissions"."id" IS '主键ID';
+COMMENT ON COLUMN "permissions"."code" IS '权限编码,如 inbound:view';
+COMMENT ON COLUMN "permissions"."name" IS '名称';
+COMMENT ON COLUMN "permissions"."type" IS '类型 MENU菜单/BUTTON按钮';
+COMMENT ON COLUMN "permissions"."parent_code" IS '父级编码';
+COMMENT ON COLUMN "permissions"."path" IS '前端路由(菜单类)';
+COMMENT ON COLUMN "permissions"."icon" IS '图标(菜单类)';
+COMMENT ON COLUMN "permissions"."sort" IS '排序';
+COMMENT ON COLUMN "permissions"."remark" IS '备注';
+COMMENT ON COLUMN "permissions"."created_at" IS '创建时间';
+COMMENT ON COLUMN "permissions"."updated_at" IS '更新时间';
+COMMENT ON TABLE "return_orders" IS 'ReturnOrder 退库单(客户诉求 问题记录 L488/L491):';
+COMMENT ON COLUMN "return_orders"."id" IS '主键ID';
+COMMENT ON COLUMN "return_orders"."return_no" IS '退库单号';
+COMMENT ON COLUMN "return_orders"."source_type" IS '来源 station=工位退库';
+COMMENT ON COLUMN "return_orders"."order_no" IS '关联工单号';
+COMMENT ON COLUMN "return_orders"."station_no" IS '退库工位号';
+COMMENT ON COLUMN "return_orders"."sn" IS '工件SN(可空)';
+COMMENT ON COLUMN "return_orders"."material_code" IS '物料编码';
+COMMENT ON COLUMN "return_orders"."material_name" IS '物料名称(冗余)';
+COMMENT ON COLUMN "return_orders"."spec" IS '规格';
+COMMENT ON COLUMN "return_orders"."qty" IS '退库数量';
+COMMENT ON COLUMN "return_orders"."unit" IS '单位';
+COMMENT ON COLUMN "return_orders"."reason" IS '退库原因';
+COMMENT ON COLUMN "return_orders"."status" IS 'PENDING/RECEIVED';
+COMMENT ON COLUMN "return_orders"."operator" IS '退库发起人(工位终端操作人)';
+COMMENT ON COLUMN "return_orders"."receive_by" IS 'WMS 确认收货人';
+COMMENT ON COLUMN "return_orders"."created_at" IS '创建时间';
+COMMENT ON COLUMN "return_orders"."receive_at" IS '确认收货时间';
+COMMENT ON TABLE "roles" IS 'Role 角色:承载菜单/按钮权限';
+COMMENT ON COLUMN "roles"."id" IS '主键ID';
+COMMENT ON COLUMN "roles"."name" IS '角色名称';
+COMMENT ON COLUMN "roles"."code" IS '角色编码,如 admin/operator/inspector';
+COMMENT ON COLUMN "roles"."remark" IS '备注';
+COMMENT ON COLUMN "roles"."permission_codes" IS '权限编码列表';
+COMMENT ON COLUMN "roles"."created_at" IS '创建时间';
+COMMENT ON COLUMN "roles"."updated_at" IS '更新时间';
+COMMENT ON TABLE "semi_finisheds" IS 'SemiFinished 半成品库存';
+COMMENT ON COLUMN "semi_finisheds"."id" IS '主键ID';
+COMMENT ON COLUMN "semi_finisheds"."sn" IS '半成品 SN';
+COMMENT ON COLUMN "semi_finisheds"."material_code" IS '物料编码(MES 未传时按 SN 反查,可空)';
+COMMENT ON COLUMN "semi_finisheds"."completed_process" IS '已完成工序(如 135)';
+COMMENT ON COLUMN "semi_finisheds"."quantity" IS '数量';
+COMMENT ON COLUMN "semi_finisheds"."zone_code" IS '所在区域';
+COMMENT ON COLUMN "semi_finisheds"."status" IS '在库/出库/使用';
+COMMENT ON COLUMN "semi_finisheds"."order_no" IS '关联工单';
+COMMENT ON COLUMN "semi_finisheds"."created_at" IS '创建时间';
+COMMENT ON COLUMN "semi_finisheds"."updated_at" IS '更新时间';
+COMMENT ON TABLE "stocktake_items" IS 'StocktakeItem 盘点明细(发起时的账面快照 + 扫码实盘数)';
+COMMENT ON COLUMN "stocktake_items"."id" IS '主键ID';
+COMMENT ON COLUMN "stocktake_items"."stocktake_no" IS '盘点单号';
+COMMENT ON COLUMN "stocktake_items"."target_type" IS '目标类型';
+COMMENT ON COLUMN "stocktake_items"."target_id" IS '目标ID';
+COMMENT ON COLUMN "stocktake_items"."material_code" IS '物料编码';
+COMMENT ON COLUMN "stocktake_items"."zone_code" IS '区域编码';
+COMMENT ON COLUMN "stocktake_items"."shelf_no" IS '货架号';
+COMMENT ON COLUMN "stocktake_items"."layer_no" IS '层号';
+COMMENT ON COLUMN "stocktake_items"."position_no" IS '位置号';
+COMMENT ON COLUMN "stocktake_items"."book_qty" IS '账面数量';
+COMMENT ON COLUMN "stocktake_items"."scanned_qty" IS '扫描数量';
+COMMENT ON COLUMN "stocktake_items"."diff_qty" IS '差异数量';
+COMMENT ON COLUMN "stocktake_items"."counted" IS '是否已盘点';
+COMMENT ON COLUMN "stocktake_items"."counted_by" IS '盘点人';
+COMMENT ON COLUMN "stocktake_items"."counted_at" IS '盘点时间';
+COMMENT ON COLUMN "stocktake_items"."updated_at" IS '更新时间';
+COMMENT ON TABLE "stocktake_orders" IS 'StocktakeOrder 盘点单:发起时冻结当时库存快照(明细行)';
+COMMENT ON COLUMN "stocktake_orders"."id" IS '主键ID';
+COMMENT ON COLUMN "stocktake_orders"."stocktake_no" IS '盘点单号';
+COMMENT ON COLUMN "stocktake_orders"."status" IS '进行中/已完成/已写回/已取消';
+COMMENT ON COLUMN "stocktake_orders"."operator" IS '发起人';
+COMMENT ON COLUMN "stocktake_orders"."total_targets" IS '快照目标数(本次盘点覆盖的批次/SN总数)';
+COMMENT ON COLUMN "stocktake_orders"."diff_count" IS '差异项数(diff!=0 的明细数)';
+COMMENT ON COLUMN "stocktake_orders"."adjusted" IS '差异是否已写回库存';
+COMMENT ON COLUMN "stocktake_orders"."adjust_no" IS '盘点调整单号(写回时生成)';
+COMMENT ON COLUMN "stocktake_orders"."written_at" IS '写回时间(unix 秒)';
+COMMENT ON COLUMN "stocktake_orders"."written_by" IS '写回操作人';
+COMMENT ON COLUMN "stocktake_orders"."uncounted_mode" IS '未盘项处理 keep=按账面保留/zero=盘亏为0';
+COMMENT ON COLUMN "stocktake_orders"."cancel_reason" IS '取消原因';
+COMMENT ON COLUMN "stocktake_orders"."created_at" IS '创建时间';
+COMMENT ON COLUMN "stocktake_orders"."finished_at" IS '完成时间';
+COMMENT ON TABLE "users" IS 'User 系统用户(账号与权限)';
+COMMENT ON COLUMN "users"."id" IS '主键ID';
+COMMENT ON COLUMN "users"."username" IS '登录名';
+COMMENT ON COLUMN "users"."password" IS '密码(哈希)';
+COMMENT ON COLUMN "users"."real_name" IS '姓名';
+COMMENT ON COLUMN "users"."role" IS '角色 admin/operator/inspector(旧字段,权限数据化后由 role_id 决定,此字段仅作兼容/展示)';
+COMMENT ON COLUMN "users"."role_id" IS '角色ID,关联 roles 表;为空时回退按 role 字符串取权限';
+COMMENT ON COLUMN "users"."dept" IS '部门';
+COMMENT ON COLUMN "users"."phone" IS '电话';
+COMMENT ON COLUMN "users"."is_active" IS '是否启用';
+COMMENT ON COLUMN "users"."last_login_at" IS '最近登录时间';
+COMMENT ON COLUMN "users"."created_at" IS '创建时间';
+COMMENT ON COLUMN "users"."updated_at" IS '更新时间';
+COMMENT ON TABLE "zones" IS 'Zone 库房库位主数据(统一主表 + 层级类型字段,符合「统一主表+类型字段,禁拆表」铁律)。';
+COMMENT ON COLUMN "zones"."id" IS '主键ID';
+COMMENT ON COLUMN "zones"."level" IS '层级 1区域/2货架/3层/4位置号';
+COMMENT ON COLUMN "zones"."code" IS '本级编码(区域编码/货架号/层号/位置号)';
+COMMENT ON COLUMN "zones"."name" IS '显示名:区域名称(level1)或位置名称(level4,现场可读如''A架3层12位'');其他级可空';
+COMMENT ON COLUMN "zones"."parent_code" IS '上级节点编码;根级(level1)为空';
+COMMENT ON COLUMN "zones"."zone_code" IS '区域编码(冗余:本节点所属区域;level1=自身code)';
+COMMENT ON COLUMN "zones"."zone_name" IS '区域名称(仅 level1 区域行有值)';
+COMMENT ON COLUMN "zones"."description" IS '说明(区域级)';
+COMMENT ON COLUMN "zones"."shelf_no" IS '货架号(冗余)';
+COMMENT ON COLUMN "zones"."layer_no" IS '第几层(冗余;默认位置为空)';
+COMMENT ON COLUMN "zones"."position_no" IS '位置号(冗余;level4=自身code)';
+COMMENT ON COLUMN "zones"."status" IS '状态:启用/停用';
+COMMENT ON COLUMN "zones"."created_at" IS '创建时间';
+COMMENT ON COLUMN "zones"."updated_at" IS '更新时间';
diff --git a/sql/gen_comments.py b/sql/gen_comments.py
new file mode 100644
index 0000000..a1524cb
--- /dev/null
+++ b/sql/gen_comments.py
@@ -0,0 +1,231 @@
+# -*- coding: utf-8 -*-
+"""
+从 ent schema 源文件抽取 表注释(类型 doc) + 列注释(.Comment 或字段上方 inline //),
+与真实数据库目录(information_schema 导出 TSV) join,生成可重复执行的 COMMENT ON SQL。
+仅对库中真实存在的 表/列 生成语句;不猜测业务含义。
+"""
+import os, re, sys
+
+ROOT = "D:/hardman/bj_power"
+SCHEMA_DIRS = {
+ "mes": os.path.join(ROOT, "bj_power_mes", "schema"),
+ "wms": os.path.join(ROOT, "bj_power_wms", "schema"),
+}
+CATALOG = {
+ "mes": os.path.join(ROOT, "sql", "_mes_catalog.tsv"),
+ "wms": os.path.join(ROOT, "sql", "_wms_catalog.tsv"),
+}
+OUT = {
+ "mes": os.path.join(ROOT, "sql", "db_comments_mes.sql"),
+ "wms": os.path.join(ROOT, "sql", "db_comments_wms.sql"),
+}
+
+# ---------- helpers ----------
+def snake(name):
+ out = []
+ for i, ch in enumerate(name):
+ if ch.isupper() and i > 0:
+ out.append('_')
+ out.append(ch.lower())
+ return "".join(out)
+
+def pluralize(s):
+ if s.endswith('y') and s[-2:-1] not in 'aeiou':
+ return s[:-1] + 'ies'
+ if s.endswith(('s', 'x', 'ch', 'sh')):
+ return s + 'es'
+ return s + 's'
+
+SYS_MAP = {
+ 'id': '主键ID',
+ 'created_at': '创建时间',
+ 'updated_at': '更新时间',
+ 'deleted_at': '逻辑删除时间',
+ 'created_by': '创建人',
+ 'updated_by': '更新人',
+}
+# 兜底:声明了但既无 .Comment 也无 inline // 的列,按列名给出安全中文(字面翻译,低误判)
+NAME_MAP = {
+ 'remark': '备注',
+ 'operator': '操作人',
+ 'order_no': '关联工单号',
+ 'material_name': '物料名称',
+ 'spec': '规格',
+ 'unit': '单位',
+ 'icon': '图标',
+ 'sort': '排序',
+ 'target_dock': '目标接驳台',
+ 'process_name': '工序名称',
+ 'step_name': '工序名称',
+ 'criterion_name': '判据名称',
+ 'criterion_logic': '判据逻辑',
+ 'is_ok': '是否合格',
+ 'started_at': '开始时间',
+ 'ended_at': '结束时间',
+ 'resolved_at': '处理时间',
+ 'parent_code': '父级编码',
+ 'target_type': '目标类型',
+ 'target_id': '目标ID',
+ 'material_code': '物料编码',
+ 'zone_code': '区域编码',
+ 'shelf_no': '货架号',
+ 'layer_no': '层号',
+ 'position_no': '位置号',
+ 'book_qty': '账面数量',
+ 'scanned_qty': '扫描数量',
+ 'diff_qty': '差异数量',
+ 'counted': '是否已盘点',
+ 'counted_by': '盘点人',
+ 'counted_at': '盘点时间',
+ 'product_name': '产品名称',
+ 'completed_at': '完成时间',
+}
+
+def find_block(text, brace_idx):
+ depth = 0
+ for i in range(brace_idx, len(text)):
+ if text[i] == '{':
+ depth += 1
+ elif text[i] == '}':
+ depth -= 1
+ if depth == 0:
+ return text[brace_idx+1:i]
+ return ""
+
+FIELD_RE = re.compile(r'^\s*field\.\w+\(\s*"(\w+)"')
+COMMENT_RE = re.compile(r'\.Comment\(\s*"((?:[^"\\]|\\.)*)"')
+TABLE_RE = re.compile(r'entsql\.Annotation\{\s*Table:\s*"(\w+)"')
+TYPE_RE = re.compile(r'^type\s+(\w+)\s+struct', re.MULTILINE)
+
+def parse_file(path):
+ with open(path, encoding='utf-8') as f:
+ text = f.read()
+ results = [] # list of (type_name, doc, table_name, [(col, comment), ...])
+ for tm in TYPE_RE.finditer(text):
+ type_name = tm.group(1)
+ type_line = text[:tm.start()].count('\n')
+ # doc comment: walk up from type line over consecutive // lines
+ lines = text.split('\n')
+ doc = []
+ j = type_line - 1
+ while j >= 0 and lines[j].strip().startswith('//'):
+ doc.insert(0, lines[j].strip()[2:].strip())
+ j -= 1
+ doc_text = doc[0] if doc else type_name
+ # table name
+ ann_m = re.search(r'func\s*\(\w+\)\s*Annotations\(\)\s*\[\]schema\.Annotation\s*\{', text)
+ table = None
+ if ann_m:
+ ab = find_block(text, ann_m.end()-1)
+ tm2 = TABLE_RE.search(ab)
+ if tm2:
+ table = tm2.group(1)
+ if not table:
+ table = pluralize(snake(type_name))
+ # fields block
+ fm = re.search(r'func\s*\(\w+\)\s*Fields\(\)\s*\[\]ent\.Field\s*\{', text)
+ fields = []
+ if fm:
+ fb = find_block(text, fm.end()-1)
+ flines = fb.split('\n')
+ starts = [(i, FIELD_RE.match(flines[i]).group(1))
+ for i in range(len(flines))
+ if FIELD_RE.match(flines[i])]
+ for k, (i, fname) in enumerate(starts):
+ end = starts[k+1][0] if k+1 < len(starts) else len(flines)
+ seg = '\n'.join(flines[i:end])
+ cm = COMMENT_RE.search(seg)
+ if cm:
+ comment = cm.group(1)
+ else:
+ # inline // immediately above the field start line (within fb)
+ buf = []
+ jj = i - 1
+ while jj >= 0 and flines[jj].strip().startswith('//'):
+ buf.insert(0, flines[jj].strip()[2:].strip())
+ jj -= 1
+ comment = " ".join(buf) if buf else ""
+ col = snake(fname)
+ if not comment:
+ comment = SYS_MAP.get(col, "")
+ fields.append((col, comment))
+ results.append((type_name, doc_text, table, fields))
+ return results
+
+def clean(s):
+ s = s.replace("\\", "\\\\")
+ s = s.replace("'", "''")
+ s = re.sub(r'\s+', ' ', s).strip()
+ return s
+
+def main():
+ for side in ("mes", "wms"):
+ # parse all schema files
+ schema_map = {} # table_name -> (doc, {col: comment})
+ unparsed_files = []
+ for fn in sorted(os.listdir(SCHEMA_DIRS[side])):
+ if not fn.endswith('.go'):
+ continue
+ if fn in ('gen.go', 'mixin.go'):
+ continue
+ parsed = parse_file(os.path.join(SCHEMA_DIRS[side], fn))
+ for type_name, doc, table, fields in parsed:
+ colmap = {}
+ for col, comment in fields:
+ colmap[col] = comment
+ schema_map[table] = (doc, colmap, type_name)
+ # read catalog
+ cat = {} # table -> [(col, dtype, existing_comment)]
+ with open(CATALOG[side], encoding='utf-8') as f:
+ header = f.readline()
+ for line in f:
+ line = line.rstrip('\n')
+ if not line:
+ continue
+ parts = line.split('\t')
+ if len(parts) < 4:
+ continue
+ t, c, dt, ec = parts[0], parts[1], parts[2], parts[3]
+ cat.setdefault(t, []).append((c, dt, ec))
+ # generate SQL
+ out_lines = []
+ out_lines.append("-- ============================================================")
+ out_lines.append(f"-- {side.upper()} 数据库 表/列 注释(COMMENT ON),可重复执行")
+ out_lines.append("-- 由 ent schema 源文件抽取生成;表名/列名均以真实库目录为准")
+ out_lines.append("-- ============================================================\n")
+ tables_done = set()
+ table_comments_emitted = 0
+ col_comments_emitted = 0
+ cols_without = [] # (table, col) no comment available
+ for t in sorted(cat.keys()):
+ if t in schema_map:
+ doc, colmap, type_name = schema_map[t]
+ # table comment
+ if doc:
+ out_lines.append(f'COMMENT ON TABLE "{t}" IS \'{clean(doc)}\';')
+ table_comments_emitted += 1
+ # column comments
+ for (c, dt, ec) in cat[t]:
+ comment = colmap.get(c, "") or NAME_MAP.get(c, "") or SYS_MAP.get(c, "")
+ if comment:
+ out_lines.append(f'COMMENT ON COLUMN "{t}"."{c}" IS \'{clean(comment)}\';')
+ col_comments_emitted += 1
+ else:
+ cols_without.append((t, c))
+ tables_done.add(t)
+ out_lines.append("")
+ with open(OUT[side], 'w', encoding='utf-8') as f:
+ f.write('\n'.join(out_lines))
+ # report
+ unmatched = [t for t in cat.keys() if t not in schema_map]
+ print(f"[{side.upper()}] schema tables matched: {len(tables_done)}")
+ print(f"[{side.upper()}] table comments emitted: {table_comments_emitted}")
+ print(f"[{side.upper()}] column comments emitted: {col_comments_emitted}")
+ print(f"[{side.upper()}] columns WITHOUT comment (skipped): {len(cols_without)}")
+ for t, c in cols_without:
+ print(f" NO-COMMENT {t}.{c}")
+ print(f"[{side.upper()}] DB tables WITHOUT schema file: {unmatched}")
+ print(f"[{side.upper()}] -> wrote {OUT[side]}\n")
+
+if __name__ == '__main__':
+ main()