feat: 大屏改为纯流式自适应布局,新增KPI带与产线动态拓扑地图
This commit is contained in:
@@ -123,8 +123,29 @@ func listZonesHandler(ctx *svc.ServiceContext) http.HandlerFunc {
|
||||
}
|
||||
list := make([]zoneNodeVO, 0, len(rows))
|
||||
byZone, byShelf, byLayer, byPos, byUnshelved := zoneStockMaps(ctx)
|
||||
// 区域名称回填:zone_name 冗余字段仅 level1 区域行有值;子层级(货架/层/位置号)按 zone_code 反查所属区域名称。
|
||||
zoneNameByCode := map[string]string{}
|
||||
zcKeys := make([]string, 0)
|
||||
for _, z := range rows {
|
||||
if z.Level != zoneLevelRegion && z.ZoneCode != "" {
|
||||
k := strings.ToUpper(strings.TrimSpace(z.ZoneCode))
|
||||
if _, ok := zoneNameByCode[k]; !ok {
|
||||
zcKeys = append(zcKeys, k)
|
||||
}
|
||||
}
|
||||
}
|
||||
if len(zcKeys) > 0 {
|
||||
if regs, err := ctx.EntClient.Zone.Query().Where(zone.LevelEQ(zoneLevelRegion), zone.CodeIn(zcKeys...)).All(ctx0()); err == nil {
|
||||
for _, rg := range regs {
|
||||
zoneNameByCode[strings.ToUpper(strings.TrimSpace(rg.Code))] = rg.Name
|
||||
}
|
||||
}
|
||||
}
|
||||
for _, z := range rows {
|
||||
vo := toZoneNodeVO(z)
|
||||
if z.Level != zoneLevelRegion {
|
||||
vo.ZoneName = zoneNameByCode[strings.ToUpper(strings.TrimSpace(z.ZoneCode))]
|
||||
}
|
||||
zc := strings.ToLower(strings.TrimSpace(z.ZoneCode))
|
||||
sh := strings.ToLower(strings.TrimSpace(z.ShelfNo))
|
||||
ly := strings.TrimSpace(z.LayerNo)
|
||||
@@ -340,6 +361,7 @@ func createZoneNodeHandler(ctx *svc.ServiceContext) http.HandlerFunc {
|
||||
|
||||
type zoneNodeUpdateReq struct {
|
||||
ID int `json:"id"`
|
||||
Code string `json:"code"` // 仅 level=4 位置号允许改编码;货架/层/区域忽略(避免级联子节点与库存的破坏性重命名)
|
||||
Name string `json:"name"`
|
||||
Remark string `json:"remark"`
|
||||
Status string `json:"status"`
|
||||
@@ -371,18 +393,59 @@ func updateZoneNodeHandler(ctx *svc.ServiceContext) http.HandlerFunc {
|
||||
fail(w, http.StatusBadRequest, "状态取值非法")
|
||||
return
|
||||
}
|
||||
// 位置号(level4)放开编辑:允许改编码(支持字符串,如 P-01);同步冗余 position_no 并级联库存,避免库存挂空。
|
||||
// 货架/层/区域编码维持不可改(重命名会级联全部子节点+库存,破坏性,需单独裁决)。
|
||||
renamedCode := ""
|
||||
if z.Level == zoneLevelPos {
|
||||
newCode := strings.ToUpper(strings.TrimSpace(req.Code))
|
||||
if newCode == "" {
|
||||
fail(w, http.StatusBadRequest, "位置号必填")
|
||||
return
|
||||
}
|
||||
if newCode != z.Code {
|
||||
dup, _ := ctx.EntClient.Zone.Query().
|
||||
Where(zone.LevelEQ(zoneLevelPos), zone.ZoneCodeEQ(z.ZoneCode),
|
||||
zone.ShelfNoEQ(z.ShelfNo), zone.LayerNoEQ(z.LayerNo),
|
||||
zone.CodeEQ(newCode), zone.Not(zone.IDEQ(z.ID))).Exist(ctx0())
|
||||
if dup {
|
||||
fail(w, http.StatusConflict, "该位置号已存在:"+newCode)
|
||||
return
|
||||
}
|
||||
renamedCode = newCode
|
||||
}
|
||||
}
|
||||
upd := ctx.EntClient.Zone.UpdateOneID(req.ID).SetStatus(status).
|
||||
SetName(strings.TrimSpace(req.Name)).
|
||||
SetNillableDescription(strPtr(strings.TrimSpace(req.Remark)))
|
||||
if renamedCode != "" {
|
||||
upd.SetCode(renamedCode).SetNillablePositionNo(strPtr(renamedCode))
|
||||
}
|
||||
if z.Level == 1 {
|
||||
upd.SetZoneName(strings.TrimSpace(req.Name)) // 区域名称冗余同步
|
||||
}
|
||||
// 位置号重命名:先级联库存 position_no(用旧码定位→新码),再落库 zone,保证库存不挂空。
|
||||
if renamedCode != "" {
|
||||
if _, err := ctx.EntClient.Inventory.Update().
|
||||
Where(inventory.ZoneCodeEQ(z.ZoneCode), inventory.ShelfNoEQ(z.ShelfNo),
|
||||
inventory.LayerNoEQ(z.LayerNo), inventory.PositionNoEQ(z.Code)).
|
||||
SetPositionNo(renamedCode).Save(ctx0()); err != nil {
|
||||
fail(w, http.StatusInternalServerError, "级联更新库存位置号失败: "+err.Error())
|
||||
return
|
||||
}
|
||||
}
|
||||
if _, err := upd.Save(ctx0()); err != nil {
|
||||
fail(w, http.StatusInternalServerError, err.Error())
|
||||
return
|
||||
}
|
||||
ctx.EventLog.Write(ctx0(), "zone.update", r.Header.Get("X-Username"), "zone", z.Code,
|
||||
"编辑"+zoneLevelName(z.Level)+" "+z.Code, nil)
|
||||
finalCode := z.Code
|
||||
if renamedCode != "" {
|
||||
finalCode = renamedCode
|
||||
}
|
||||
logMsg := "编辑" + zoneLevelName(z.Level) + " " + finalCode
|
||||
if renamedCode != "" {
|
||||
logMsg = "位置号更名 " + z.Code + " → " + renamedCode + "(已级联库存 position_no)"
|
||||
}
|
||||
ctx.EventLog.Write(ctx0(), "zone.update", r.Header.Get("X-Username"), "zone", finalCode, logMsg, nil)
|
||||
ok(w, map[string]any{"id": req.ID})
|
||||
}
|
||||
}
|
||||
@@ -509,7 +572,7 @@ type zoneBatchGenReq struct {
|
||||
ShelfNo string `json:"shelfNo"`
|
||||
LayerStart int `json:"layerStart"` // level=3 批量生成层:层范围起
|
||||
LayerEnd int `json:"layerEnd"` // level=3 批量生成层:层范围止
|
||||
LayerNo string `json:"layerNo"` // level=4 批量生成位置号:层号(放开字母+数字,层节点不存在时自动创建)
|
||||
LayerNo string `json:"layerNo"` // level=4 批量生成位置号:层号(必须为已存在的层)
|
||||
PosStart int `json:"posStart"`
|
||||
PosEnd int `json:"posEnd"`
|
||||
Count int `json:"count"` // level=4 批量生成位置号:生成数量(从「该层最大位置号+1」起连续生成)
|
||||
@@ -623,27 +686,25 @@ func batchGenerateHandler(ctx *svc.ServiceContext) http.HandlerFunc {
|
||||
return
|
||||
}
|
||||
|
||||
// ---------- level=4:批量生成位置号(层号放开字母+数字,按最近编码序号+1 生成 N 个) ----------
|
||||
layerNo := strings.ToUpper(strings.TrimSpace(req.LayerNo))
|
||||
if layerNo == "" {
|
||||
fail(w, http.StatusBadRequest, "请填写层号")
|
||||
return
|
||||
}
|
||||
if req.Count <= 0 {
|
||||
fail(w, http.StatusBadRequest, "请填写生成数量(≥1)")
|
||||
return
|
||||
}
|
||||
if req.Count > 2000 {
|
||||
fail(w, http.StatusBadRequest, "一次最多生成 2000 个位置,请缩小数量")
|
||||
return
|
||||
}
|
||||
// 层号放开:该层节点不存在则自动创建(作为位置号的父级)
|
||||
if exist, _ := ctx.EntClient.Zone.Query().Where(zone.LevelEQ(3), zone.ZoneCodeEQ(zoneCode), zone.ShelfNoEQ(req.ShelfNo), zone.CodeEQ(layerNo)).Exist(ctx0()); !exist {
|
||||
if _, err := ctx.EntClient.Zone.Create().SetLevel(3).SetCode(layerNo).SetParentCode(req.ShelfNo).SetZoneCode(zoneCode).SetShelfNo(req.ShelfNo).SetLayerNo(layerNo).SetName(req.ShelfNo + "架" + layerNo + "层").SetStatus("启用").Save(ctx0()); err != nil {
|
||||
fail(w, http.StatusInternalServerError, "自动创建层失败: "+err.Error())
|
||||
return
|
||||
}
|
||||
}
|
||||
// ---------- level=4:批量生成位置号(必须选已存在的层,按最近编码序号+1 生成 N 个) ----------
|
||||
layerNo := strings.ToUpper(strings.TrimSpace(req.LayerNo))
|
||||
if layerNo == "" {
|
||||
fail(w, http.StatusBadRequest, "请选择具体的层")
|
||||
return
|
||||
}
|
||||
if req.Count <= 0 {
|
||||
fail(w, http.StatusBadRequest, "请填写生成数量(≥1)")
|
||||
return
|
||||
}
|
||||
if req.Count > 2000 {
|
||||
fail(w, http.StatusBadRequest, "一次最多生成 2000 个位置,请缩小数量")
|
||||
return
|
||||
}
|
||||
// 层级字段用下拉选择,层必须已存在;不存在则报错,不自动创建
|
||||
if exist, _ := ctx.EntClient.Zone.Query().Where(zone.LevelEQ(3), zone.ZoneCodeEQ(zoneCode), zone.ShelfNoEQ(req.ShelfNo), zone.CodeEQ(layerNo)).Exist(ctx0()); !exist {
|
||||
fail(w, http.StatusBadRequest, "层不存在,请先在层管理里创建")
|
||||
return
|
||||
}
|
||||
// 最近编码序号:该层下已存在的最大位置号(按整数解析,非整数忽略)
|
||||
maxNo := 0
|
||||
cur, _ := ctx.EntClient.Zone.Query().Where(zone.LevelEQ(4), zone.ZoneCodeEQ(zoneCode), zone.ShelfNoEQ(req.ShelfNo), zone.LayerNoEQ(layerNo)).All(ctx0())
|
||||
|
||||
Reference in New Issue
Block a user