feat: AGV点位锁与缓存迁移 + 工位终端去离线队列 + WMS出入库增强
【MES】 - AGV点位/线路点位/AGV任务/工单 ent schema 重构(全量重生成 ent 代码) - 新增派车锁 agv_point_lock.go:目标点位占用即拒车,JBT21 库房接驳台卸货后保持锁定待库管手动解锁 - 新增进程内 TTL 缓存 cache.go,由 Redis 看板缓存迁移至内存(singleflight 防击穿,去除外部依赖) - AGV 三段链安全机制、车辆状态/接驳台左右互换、补料损耗闭环完善 - 来料检/工序卡/工单/质检/日排产/AGV 前端与帮助文档更新 - 新增 migrations/、sql/ 目录 【WMS】 - 出库、Excel 导出、物料、路由处理增强 - 配置与 DB 初始化调整;基础数据/成品入库/入库前端调整 【工位终端】 - 移除离线同步队列(syncer 包、sync.go、SyncQueueDialog.vue),改为实时直连上报 MES(断网即失败报错),以本人身份操作 - 本地 SQLite 仅保留操作日志 + 内置账号 + 登录态;保留空闲自动登出 【文档】 - 删除 AGV海康litev1.5.md;案例.md 更新
This commit is contained in:
@@ -304,128 +304,8 @@ func excelInboundHandler(ctx *svc.ServiceContext) http.HandlerFunc {
|
||||
return
|
||||
}
|
||||
|
||||
type planRow struct {
|
||||
row int
|
||||
code string
|
||||
sn string
|
||||
qty int
|
||||
prodDate string
|
||||
supplier string
|
||||
zone string
|
||||
remark string
|
||||
shelfNo string
|
||||
layerNo string
|
||||
positionNo string
|
||||
inspectionNo string
|
||||
productWorkNo string
|
||||
ownershipType string
|
||||
ownershipNo string
|
||||
}
|
||||
plans := make([]planRow, 0, len(rows)-1)
|
||||
errs := make([]importErr, 0)
|
||||
|
||||
// ---- 阶段1:解析 + 校验(不落库) ----
|
||||
snSeen := map[string]bool{}
|
||||
for i, row := range rows {
|
||||
if i == 0 {
|
||||
continue // 表头
|
||||
}
|
||||
cell := func(idx int) string {
|
||||
if idx < len(row) {
|
||||
return strings.TrimSpace(row[idx])
|
||||
}
|
||||
return ""
|
||||
}
|
||||
pr := planRow{row: i + 1}
|
||||
pr.code = cell(0)
|
||||
if mode == "sn" {
|
||||
// 图号|SN|区域|生产日期|供应商|架|层|位|备注|检测单号|产品工号|归属类型|归属编号
|
||||
pr.sn = cell(1)
|
||||
pr.zone = cell(2)
|
||||
pr.prodDate = cell(3)
|
||||
pr.supplier = cell(4)
|
||||
pr.shelfNo = cell(5)
|
||||
pr.layerNo = cell(6)
|
||||
pr.positionNo = cell(7)
|
||||
pr.remark = cell(8)
|
||||
pr.inspectionNo = cell(9)
|
||||
pr.productWorkNo = cell(10)
|
||||
pr.ownershipType = cell(11)
|
||||
pr.ownershipNo = cell(12)
|
||||
} else {
|
||||
// 图号|数量|生产日期|供应商|区域|架|层|位|备注|检测单号|产品工号|归属类型|归属编号(批次号由系统自动生成,模板不再含该列)
|
||||
pr.qty = atoi(cell(1), 0)
|
||||
pr.prodDate = cell(2)
|
||||
pr.supplier = cell(3)
|
||||
pr.zone = cell(4)
|
||||
pr.shelfNo = cell(5)
|
||||
pr.layerNo = cell(6)
|
||||
pr.positionNo = cell(7)
|
||||
pr.remark = cell(8)
|
||||
pr.inspectionNo = cell(9)
|
||||
pr.productWorkNo = cell(10)
|
||||
pr.ownershipType = cell(11)
|
||||
pr.ownershipNo = cell(12)
|
||||
}
|
||||
|
||||
if pr.code == "" {
|
||||
errs = append(errs, importErr{pr.row, pr.code, "图号为空"})
|
||||
continue
|
||||
}
|
||||
m, e := ctx.EntClient.Material.Query().Where(material.CodeEQ(pr.code)).Only(ctx0())
|
||||
if e != nil {
|
||||
errs = append(errs, importErr{pr.row, pr.code, "物料不存在"})
|
||||
continue
|
||||
}
|
||||
if mode == "sn" {
|
||||
if m.SnMode != snModeSN {
|
||||
errs = append(errs, importErr{pr.row, pr.code, "该物料序列号=否(按数量管理),SN 导入仅支持序列号=是(逐件SN)"})
|
||||
continue
|
||||
}
|
||||
if pr.sn == "" {
|
||||
errs = append(errs, importErr{pr.row, pr.code, "SN 为空"})
|
||||
continue
|
||||
}
|
||||
if snSeen[pr.sn] {
|
||||
errs = append(errs, importErr{pr.row, pr.code, "SN 在文件中重复: " + pr.sn})
|
||||
continue
|
||||
}
|
||||
snSeen[pr.sn] = true
|
||||
exists, _ := ctx.EntClient.Inventory.Query().
|
||||
Where(inventory.SnModeEQ(snModeSN), inventory.SnCodeEQ(pr.sn)).Exist(ctx0())
|
||||
if exists {
|
||||
errs = append(errs, importErr{pr.row, pr.code, "SN 已存在: " + pr.sn})
|
||||
continue
|
||||
}
|
||||
} else {
|
||||
if m.SnMode != snModeBatch {
|
||||
errs = append(errs, importErr{pr.row, pr.code, "该物料序列号=是(逐件SN管理),请使用 SN 导入"})
|
||||
continue
|
||||
}
|
||||
if pr.qty <= 0 {
|
||||
errs = append(errs, importErr{pr.row, pr.code, "数量必须大于 0"})
|
||||
continue
|
||||
}
|
||||
}
|
||||
if pr.zone == "" {
|
||||
errs = append(errs, importErr{pr.row, pr.code, "区域为空(必填)"})
|
||||
continue
|
||||
}
|
||||
// 货位必填(货架/层/位置):与手动录入(InboundEntry)口径一致,杜绝"有区域无货架"脏数据;任一为空则整批拒绝
|
||||
if pr.shelfNo == "" || pr.layerNo == "" || pr.positionNo == "" {
|
||||
errs = append(errs, importErr{pr.row, pr.code, "货位不完整(货架/层/位置均为必填)"})
|
||||
continue
|
||||
}
|
||||
// 归属校验(与手动录入口径一致:workorder/project 必填编号;other/空 不需要)
|
||||
pr.ownershipType = ownershipTypeOrNone(pr.ownershipType)
|
||||
if pr.ownershipType == "workorder" || pr.ownershipType == "project" {
|
||||
if pr.ownershipNo == "" {
|
||||
errs = append(errs, importErr{pr.row, pr.code, "归属类型为" + pr.ownershipType + "时归属编号必填"})
|
||||
continue
|
||||
}
|
||||
}
|
||||
plans = append(plans, pr)
|
||||
}
|
||||
// ---- 阶段1:解析 + 校验(不落库)——与预检端点 excelInboundPreviewHandler 共用同一函数,规则同源 ----
|
||||
plans, errs, _ := parseInboundImportPlan(ctx, rows, mode)
|
||||
|
||||
// ---- 阶段2:有错则整体拒绝,一行都不写 ----
|
||||
if len(errs) > 0 {
|
||||
@@ -569,6 +449,180 @@ func excelInboundHandler(ctx *svc.ServiceContext) http.HandlerFunc {
|
||||
}
|
||||
}
|
||||
|
||||
// inboundImportPlan 入库导入单行写入计划(预检与写入共用同一解析/校验,规则同源不漂移)。
|
||||
type inboundImportPlan struct {
|
||||
row int
|
||||
code string
|
||||
sn string
|
||||
qty int
|
||||
prodDate string
|
||||
supplier string
|
||||
zone string
|
||||
remark string
|
||||
shelfNo string
|
||||
layerNo string
|
||||
positionNo string
|
||||
inspectionNo string
|
||||
productWorkNo string
|
||||
ownershipType string
|
||||
ownershipNo string
|
||||
}
|
||||
|
||||
// parseInboundImportPlan 入库导入阶段1:解析 + 逐行校验(只读不落库):
|
||||
// 物料存在/数量>0/SN 不重复/区域与货位必填/归属编号规则。返回行计划、逐行错误与总数据行数。
|
||||
func parseInboundImportPlan(ctx *svc.ServiceContext, rows [][]string, mode string) ([]inboundImportPlan, []importErr, int) {
|
||||
total := len(rows) - 1
|
||||
plans := make([]inboundImportPlan, 0, total)
|
||||
errs := make([]importErr, 0)
|
||||
|
||||
snSeen := map[string]bool{}
|
||||
for i, row := range rows {
|
||||
if i == 0 {
|
||||
continue // 表头
|
||||
}
|
||||
cell := func(idx int) string {
|
||||
if idx < len(row) {
|
||||
return strings.TrimSpace(row[idx])
|
||||
}
|
||||
return ""
|
||||
}
|
||||
pr := inboundImportPlan{row: i + 1}
|
||||
pr.code = cell(0)
|
||||
if mode == "sn" {
|
||||
// 图号|SN|区域|生产日期|供应商|架|层|位|备注|检测单号|产品工号|归属类型|归属编号
|
||||
pr.sn = cell(1)
|
||||
pr.zone = cell(2)
|
||||
pr.prodDate = cell(3)
|
||||
pr.supplier = cell(4)
|
||||
pr.shelfNo = cell(5)
|
||||
pr.layerNo = cell(6)
|
||||
pr.positionNo = cell(7)
|
||||
pr.remark = cell(8)
|
||||
pr.inspectionNo = cell(9)
|
||||
pr.productWorkNo = cell(10)
|
||||
pr.ownershipType = cell(11)
|
||||
pr.ownershipNo = cell(12)
|
||||
} else {
|
||||
// 图号|数量|生产日期|供应商|区域|架|层|位|备注|检测单号|产品工号|归属类型|归属编号(批次号由系统自动生成,模板不再含该列)
|
||||
pr.qty = atoi(cell(1), 0)
|
||||
pr.prodDate = cell(2)
|
||||
pr.supplier = cell(3)
|
||||
pr.zone = cell(4)
|
||||
pr.shelfNo = cell(5)
|
||||
pr.layerNo = cell(6)
|
||||
pr.positionNo = cell(7)
|
||||
pr.remark = cell(8)
|
||||
pr.inspectionNo = cell(9)
|
||||
pr.productWorkNo = cell(10)
|
||||
pr.ownershipType = cell(11)
|
||||
pr.ownershipNo = cell(12)
|
||||
}
|
||||
|
||||
if pr.code == "" {
|
||||
errs = append(errs, importErr{pr.row, pr.code, "图号为空"})
|
||||
continue
|
||||
}
|
||||
m, e := ctx.EntClient.Material.Query().Where(material.CodeEQ(pr.code)).Only(ctx0())
|
||||
if e != nil {
|
||||
errs = append(errs, importErr{pr.row, pr.code, "物料不存在"})
|
||||
continue
|
||||
}
|
||||
if mode == "sn" {
|
||||
if m.SnMode != snModeSN {
|
||||
errs = append(errs, importErr{pr.row, pr.code, "该物料序列号=否(按数量管理),SN 导入仅支持序列号=是(逐件SN)"})
|
||||
continue
|
||||
}
|
||||
if pr.sn == "" {
|
||||
errs = append(errs, importErr{pr.row, pr.code, "SN 为空"})
|
||||
continue
|
||||
}
|
||||
if snSeen[pr.sn] {
|
||||
errs = append(errs, importErr{pr.row, pr.code, "SN 在文件中重复: " + pr.sn})
|
||||
continue
|
||||
}
|
||||
snSeen[pr.sn] = true
|
||||
exists, _ := ctx.EntClient.Inventory.Query().
|
||||
Where(inventory.SnModeEQ(snModeSN), inventory.SnCodeEQ(pr.sn)).Exist(ctx0())
|
||||
if exists {
|
||||
errs = append(errs, importErr{pr.row, pr.code, "SN 已存在: " + pr.sn})
|
||||
continue
|
||||
}
|
||||
} else {
|
||||
if m.SnMode != snModeBatch {
|
||||
errs = append(errs, importErr{pr.row, pr.code, "该物料序列号=是(逐件SN管理),请使用 SN 导入"})
|
||||
continue
|
||||
}
|
||||
if pr.qty <= 0 {
|
||||
errs = append(errs, importErr{pr.row, pr.code, "数量必须大于 0"})
|
||||
continue
|
||||
}
|
||||
}
|
||||
if pr.zone == "" {
|
||||
errs = append(errs, importErr{pr.row, pr.code, "区域为空(必填)"})
|
||||
continue
|
||||
}
|
||||
// 货位必填(货架/层/位置):与手动录入(InboundEntry)口径一致,杜绝"有区域无货架"脏数据;任一为空则整批拒绝
|
||||
if pr.shelfNo == "" || pr.layerNo == "" || pr.positionNo == "" {
|
||||
errs = append(errs, importErr{pr.row, pr.code, "货位不完整(货架/层/位置均为必填)"})
|
||||
continue
|
||||
}
|
||||
// 归属校验(与手动录入口径一致:workorder/project 必填编号;other/空 不需要)
|
||||
pr.ownershipType = ownershipTypeOrNone(pr.ownershipType)
|
||||
if pr.ownershipType == "workorder" || pr.ownershipType == "project" {
|
||||
if pr.ownershipNo == "" {
|
||||
errs = append(errs, importErr{pr.row, pr.code, "归属类型为" + pr.ownershipType + "时归属编号必填"})
|
||||
continue
|
||||
}
|
||||
}
|
||||
plans = append(plans, pr)
|
||||
}
|
||||
return plans, errs, total
|
||||
}
|
||||
|
||||
// excelInboundPreviewHandler POST /api/inbound/batch-excel/preview 入库导入预检(只读):
|
||||
// 复用写入端点的阶段1校验(parseInboundImportPlan,同一函数保证规则同源),不写任何数据。
|
||||
// 返回 {total 总行数, success 将成功行数, failed 失败行数, errors 逐行失败原因(行号+图号+原因)}。
|
||||
func excelInboundPreviewHandler(ctx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
if err := r.ParseMultipartForm(20 << 20); err != nil {
|
||||
fail(w, http.StatusBadRequest, "文件上传失败: "+err.Error())
|
||||
return
|
||||
}
|
||||
mode := r.FormValue("mode")
|
||||
if mode != "sn" {
|
||||
mode = "batch"
|
||||
}
|
||||
f, _, err := r.FormFile("file")
|
||||
if err != nil {
|
||||
fail(w, http.StatusBadRequest, "缺少 file 字段")
|
||||
return
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
xl, err := excelize.OpenReader(f)
|
||||
if err != nil {
|
||||
fail(w, http.StatusBadRequest, "无法解析 Excel: "+err.Error())
|
||||
return
|
||||
}
|
||||
defer xl.Close()
|
||||
sheet := xl.GetSheetList()[0]
|
||||
rows, err := xl.GetRows(sheet)
|
||||
if err != nil {
|
||||
fail(w, http.StatusBadRequest, "读取工作表失败: "+err.Error())
|
||||
return
|
||||
}
|
||||
if len(rows) <= 1 {
|
||||
fail(w, http.StatusBadRequest, "文件无数据行(首行为表头,需至少一行数据)")
|
||||
return
|
||||
}
|
||||
plans, errs, total := parseInboundImportPlan(ctx, rows, mode)
|
||||
if errs == nil {
|
||||
errs = []importErr{}
|
||||
}
|
||||
ok(w, map[string]any{"total": total, "success": len(plans), "failed": len(errs), "errors": errs})
|
||||
}
|
||||
}
|
||||
|
||||
// ternary 小工具:condition 为真返回 a,否则 b
|
||||
func ternary(cond bool, a, b int) int {
|
||||
if cond {
|
||||
|
||||
Reference in New Issue
Block a user