feat: 完成多模块迭代更新

- 新增过程巡检按步骤上报、数量不符上报、工位退料功能
- 增加工单工程编号三级归属字段
- 新增物料安全库存与缺货预警
- 新增附件管理、退库单管理模块
- 优化生产看板展示逻辑与前端页面文案
- 清理冗余的工艺路线相关代码与备份文件
This commit is contained in:
SunYF
2026-09-15 16:37:39 +08:00
parent 951f3dfecd
commit 4a5e2d7bac
494 changed files with 24702 additions and 139223 deletions
+35
View File
@@ -1,6 +1,7 @@
package db
import (
"context"
"database/sql"
"fmt"
"log/slog"
@@ -77,6 +78,9 @@ func AutoMigrate(client *ent.Client) error {
if err := client.Schema.Create(ctx); err != nil {
return fmt.Errorf("自动迁移失败: %w", err)
}
// ent 的 Schema.Create 只会"建新表",不会给已存在的表补列(本项目已知约束)。
// 新增字段统一在此以幂等 DDL 补齐(ADD COLUMN IF NOT EXISTS 可重复执行)。
applyColumnPatches(ctx)
// 清理历史独立装箱表:装箱已合并到统一的出库主表 OutboundOrder
// 原 package_boxes 表成为孤儿表,此处幂等删除(DROP TABLE IF EXISTS 可重复执行)。
if rawDB != nil {
@@ -89,3 +93,34 @@ func AutoMigrate(client *ent.Client) error {
slog.Info("数据库迁移完成")
return nil
}
// applyColumnPatches 幂等补齐已有表的新增列。
// 背景:ent 的 Schema.Create 对已存在表不会 ADD COLUMN,故新增字段必须在此登记,
// 否则新库正常、存量库缺列导致运行时 500。
func applyColumnPatches(ctx context.Context) {
if rawDB == nil {
return
}
stmts := []string{
// P0-2 不合格品处置(问题记录 L135-145)
`ALTER TABLE inspection_records ADD COLUMN IF NOT EXISTS disposal_type text NOT NULL DEFAULT 'NONE'`,
`ALTER TABLE inspection_records ADD COLUMN IF NOT EXISTS disposal_remark text`,
`ALTER TABLE inspection_records ADD COLUMN IF NOT EXISTS return_tracking_no text`,
// D5 区域库位:货架号 / 第几层 / 位置号(手填)
`ALTER TABLE zones ADD COLUMN IF NOT EXISTS shelf_no text`,
`ALTER TABLE zones ADD COLUMN IF NOT EXISTS layer_no text`,
`ALTER TABLE zones ADD COLUMN IF NOT EXISTS position_no text`,
// D6 其他入库:归属(工单号/科技项目号/无)
`ALTER TABLE inbound_orders ADD COLUMN IF NOT EXISTS ownership_type text NOT NULL DEFAULT 'none'`,
`ALTER TABLE inbound_orders ADD COLUMN IF NOT EXISTS ownership_no text`,
// 缺货预警:物料安全库存
`ALTER TABLE materials ADD COLUMN IF NOT EXISTS safety_stock bigint NOT NULL DEFAULT 0`,
// 备料台账:目标工位(备料送到哪个装配工位)
`ALTER TABLE order_material_ledgers ADD COLUMN IF NOT EXISTS target_station text`,
}
for _, s := range stmts {
if _, err := rawDB.ExecContext(ctx, s); err != nil {
slog.Warn("补齐列失败(可忽略): " + err.Error())
}
}
}