提交
This commit is contained in:
@@ -509,9 +509,10 @@ 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」起连续生成)
|
||||
Level int `json:"level"` // 3=批量生成层(level3) 4=批量生成位置号(level4,默认,需指定已存在的层)
|
||||
Preview bool `json:"preview"`
|
||||
Layers []zoneBatchLayerName `json:"layers"` // level=3 提交时携带预览表中(可能手改过的)层名称,非空则优先采用
|
||||
@@ -622,53 +623,53 @@ func batchGenerateHandler(ctx *svc.ServiceContext) http.HandlerFunc {
|
||||
return
|
||||
}
|
||||
|
||||
// ---------- level=4:批量生成位置号 ----------
|
||||
// 只允许在「已存在的具体层」下批量生成位置号(批量生成只生成自己,不创建父级层)。
|
||||
layerNo := strings.TrimSpace(req.LayerNo)
|
||||
// ---------- level=4:批量生成位置号(层号放开字母+数字,按最近编码序号+1 生成 N 个) ----------
|
||||
layerNo := strings.ToUpper(strings.TrimSpace(req.LayerNo))
|
||||
if layerNo == "" {
|
||||
fail(w, http.StatusBadRequest, "请选择具体的层")
|
||||
fail(w, http.StatusBadRequest, "请填写层号")
|
||||
return
|
||||
}
|
||||
if req.PosStart < 0 || req.PosEnd < req.PosStart {
|
||||
fail(w, http.StatusBadRequest, "位置起止不合法(起始需 ≤ 结束,且 ≥ 0)")
|
||||
if req.Count <= 0 {
|
||||
fail(w, http.StatusBadRequest, "请填写生成数量(≥1)")
|
||||
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, "层不存在:"+req.ShelfNo+"架"+layerNo+"层,请先在「层」页签创建该层后再生成位置号")
|
||||
if req.Count > 2000 {
|
||||
fail(w, http.StatusBadRequest, "一次最多生成 2000 个位置,请缩小数量")
|
||||
return
|
||||
}
|
||||
poss := make([]int, 0)
|
||||
for p := req.PosStart; p <= req.PosEnd; p++ {
|
||||
poss = append(poss, p)
|
||||
// 层号放开:该层节点不存在则自动创建(作为位置号的父级)
|
||||
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
|
||||
}
|
||||
}
|
||||
if len(poss) > 2000 {
|
||||
fail(w, http.StatusBadRequest, "一次最多生成 2000 个位置,请缩小范围")
|
||||
return
|
||||
// 最近编码序号:该层下已存在的最大位置号(按整数解析,非整数忽略)
|
||||
maxNo := 0
|
||||
cur, _ := ctx.EntClient.Zone.Query().Where(zone.LevelEQ(4), zone.ZoneCodeEQ(zoneCode), zone.ShelfNoEQ(req.ShelfNo), zone.LayerNoEQ(layerNo)).All(ctx0())
|
||||
for _, p := range cur {
|
||||
if n, err := strconv.Atoi(p.Code); err == nil && n > maxNo {
|
||||
maxNo = n
|
||||
}
|
||||
}
|
||||
|
||||
// 预览:返回将生成的位置清单(含是否已存在)
|
||||
// 预览:从 maxNo+1 起连续生成 N 个,标注是否已存在(按层号+位置号去重跳过)
|
||||
type genItem struct {
|
||||
LayerNo string `json:"layerNo"`
|
||||
PositionNo string `json:"positionNo"`
|
||||
PositionName string `json:"positionName"`
|
||||
Exists bool `json:"exists"`
|
||||
}
|
||||
preview := make([]genItem, 0, len(poss))
|
||||
for _, p := range poss {
|
||||
ps := strconv.Itoa(p)
|
||||
exists, _ := ctx.EntClient.Zone.Query().
|
||||
Where(zone.LevelEQ(4), zone.ZoneCodeEQ(zoneCode), zone.ShelfNoEQ(req.ShelfNo),
|
||||
zone.LayerNoEQ(layerNo), zone.CodeEQ(ps)).Exist(ctx0())
|
||||
preview := make([]genItem, 0, req.Count)
|
||||
for i := 1; i <= req.Count; i++ {
|
||||
ps := strconv.Itoa(maxNo + i)
|
||||
exists, _ := ctx.EntClient.Zone.Query().Where(zone.LevelEQ(4), zone.ZoneCodeEQ(zoneCode), zone.ShelfNoEQ(req.ShelfNo), zone.LayerNoEQ(layerNo), zone.CodeEQ(ps)).Exist(ctx0())
|
||||
preview = append(preview, genItem{LayerNo: layerNo, PositionNo: ps, PositionName: req.ShelfNo + "架" + layerNo + "层" + ps + "位", Exists: exists})
|
||||
}
|
||||
if req.Preview {
|
||||
ok(w, map[string]any{"preview": true, "list": preview, "total": len(preview)})
|
||||
return
|
||||
}
|
||||
|
||||
// 提交:仅在选定层下创建不存在的位置号(层必须已存在,不再自动创建父级层)
|
||||
// 手改位置名称优先:前端预览后可点击位置名称修改,提交时按 positionNo 带回
|
||||
// 提交:创建不存在的位置号(按层号+位置号去重跳过);手改位置名称优先采用
|
||||
nameByPos := make(map[string]string, len(req.Positions))
|
||||
for _, pn := range req.Positions {
|
||||
no := strings.TrimSpace(pn.PositionNo)
|
||||
@@ -678,11 +679,9 @@ func batchGenerateHandler(ctx *svc.ServiceContext) http.HandlerFunc {
|
||||
}
|
||||
}
|
||||
created, skipped := 0, 0
|
||||
for _, p := range poss {
|
||||
ps := strconv.Itoa(p)
|
||||
if exist, _ := ctx.EntClient.Zone.Query().
|
||||
Where(zone.LevelEQ(4), zone.ZoneCodeEQ(zoneCode), zone.ShelfNoEQ(req.ShelfNo),
|
||||
zone.LayerNoEQ(layerNo), zone.CodeEQ(ps)).Exist(ctx0()); exist {
|
||||
for i := 1; i <= req.Count; i++ {
|
||||
ps := strconv.Itoa(maxNo + i)
|
||||
if exist, _ := ctx.EntClient.Zone.Query().Where(zone.LevelEQ(4), zone.ZoneCodeEQ(zoneCode), zone.ShelfNoEQ(req.ShelfNo), zone.LayerNoEQ(layerNo), zone.CodeEQ(ps)).Exist(ctx0()); exist {
|
||||
skipped++
|
||||
continue
|
||||
}
|
||||
@@ -690,10 +689,7 @@ func batchGenerateHandler(ctx *svc.ServiceContext) http.HandlerFunc {
|
||||
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(name).SetStatus("启用").Save(ctx0()); err != nil {
|
||||
if _, err := ctx.EntClient.Zone.Create().SetLevel(4).SetCode(ps).SetParentCode(layerNo).SetZoneCode(zoneCode).SetShelfNo(req.ShelfNo).SetLayerNo(layerNo).SetPositionNo(ps).SetName(name).SetStatus("启用").Save(ctx0()); err != nil {
|
||||
fail(w, http.StatusInternalServerError, "创建位置失败: "+err.Error())
|
||||
return
|
||||
}
|
||||
@@ -701,7 +697,8 @@ func batchGenerateHandler(ctx *svc.ServiceContext) http.HandlerFunc {
|
||||
}
|
||||
ctx.EventLog.Write(ctx0(), "zone.batch", r.Header.Get("X-Username"), "zone", req.ShelfNo,
|
||||
"批量生成位置 "+req.ZoneCode+"/"+req.ShelfNo+" 层"+layerNo+
|
||||
" 位"+strconv.Itoa(req.PosStart)+"-"+strconv.Itoa(req.PosEnd)+":新建"+strconv.Itoa(created)+" 跳过"+strconv.Itoa(skipped), nil)
|
||||
ok(w, map[string]any{"preview": false, "created": created, "skipped": skipped, "total": len(poss)})
|
||||
" 从"+(strconv.Itoa(maxNo+1))+"起生成"+strconv.Itoa(req.Count)+"个:新建"+strconv.Itoa(created)+" 跳过"+strconv.Itoa(skipped), nil)
|
||||
ok(w, map[string]any{"preview": false, "created": created, "skipped": skipped, "total": req.Count})
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user