feat: 新增预警定时扫描器,移除附件归档字段并为角色表补充更新时间
This commit is contained in:
@@ -1,12 +1,17 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"bj_power_wms/ent"
|
||||
"bj_power_wms/ent/inboundorder"
|
||||
"bj_power_wms/ent/inventory"
|
||||
"bj_power_wms/ent/outboundorder"
|
||||
"bj_power_wms/ent/stocktakeitem"
|
||||
"bj_power_wms/ent/zone"
|
||||
"bj_power_wms/internal/svc"
|
||||
)
|
||||
@@ -19,6 +24,18 @@ const (
|
||||
zoneLevelPos = 4
|
||||
)
|
||||
|
||||
// zoneGenLocks 进程内互斥表:按父级键串行化「查重+创建」,弥补「不建唯一索引」下的并发重复编码(规则5)。
|
||||
// WMS 为单进程部署,进程内锁即可;若未来多实例需改为 pg_advisory_xact_lock。
|
||||
var zoneGenLocks sync.Map
|
||||
|
||||
// zoneGenLock 对给定父级键加锁,返回解锁函数(配合 defer 使用)。
|
||||
func zoneGenLock(key string) func() {
|
||||
v, _ := zoneGenLocks.LoadOrStore(key, &sync.Mutex{})
|
||||
mu := v.(*sync.Mutex)
|
||||
mu.Lock()
|
||||
return func() { mu.Unlock() }
|
||||
}
|
||||
|
||||
func zoneLevelName(l int) string {
|
||||
switch l {
|
||||
case 1:
|
||||
@@ -33,6 +50,77 @@ func zoneLevelName(l int) string {
|
||||
return "节点"
|
||||
}
|
||||
|
||||
// zoneSuffix 各级编码后缀(规则3):区域=N区 / 货架=N架 / 层=N层 / 位置号=N号
|
||||
func zoneSuffix(level int) string {
|
||||
switch level {
|
||||
case 1:
|
||||
return "区"
|
||||
case 2:
|
||||
return "架"
|
||||
case 3:
|
||||
return "层"
|
||||
case 4:
|
||||
return "号"
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// zoneTrailingNum 提取编码尾部连续数字("1区"->1、"12架"->12、"7"->7);无数字返回 0。
|
||||
// 自增引擎据此在同父级下找最大尾部数字 +1,兼容纯数字与「N+后缀」两种历史格式。
|
||||
func zoneTrailingNum(code string) int {
|
||||
code = strings.TrimSpace(code)
|
||||
i := len(code) - 1
|
||||
for i >= 0 && code[i] >= '0' && code[i] <= '9' {
|
||||
i--
|
||||
}
|
||||
if i == len(code)-1 {
|
||||
return 0
|
||||
}
|
||||
n, err := strconv.Atoi(code[i+1:])
|
||||
if err != nil {
|
||||
return 0
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
// nextZoneCode 计算某父级下下一个编码:取同父级现有节点尾部数字最大值 +1,拼后缀。
|
||||
// 父级约束:level1 无父;level2 按 zoneCode(区域);level3 按 zoneCode+shelfNo;level4 按 zoneCode+shelfNo+layerNo。
|
||||
func nextZoneCode(ctx *svc.ServiceContext, level int, zoneCode, shelfNo, layerNo string) (string, error) {
|
||||
q := ctx.EntClient.Zone.Query().Where(zone.LevelEQ(level))
|
||||
switch level {
|
||||
case 2:
|
||||
q = q.Where(zone.ZoneCodeEQ(zoneCode))
|
||||
case 3:
|
||||
q = q.Where(zone.ZoneCodeEQ(zoneCode), zone.ShelfNoEQ(shelfNo))
|
||||
case 4:
|
||||
q = q.Where(zone.ZoneCodeEQ(zoneCode), zone.ShelfNoEQ(shelfNo), zone.LayerNoEQ(layerNo))
|
||||
}
|
||||
nodes, err := q.All(ctx0())
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
max := 0
|
||||
for _, n := range nodes {
|
||||
if v := zoneTrailingNum(n.Code); v > max {
|
||||
max = v
|
||||
}
|
||||
}
|
||||
return strconv.Itoa(max+1) + zoneSuffix(level), nil
|
||||
}
|
||||
|
||||
// zoneDefaultName 默认名称(规则4):区域/货架=编码本身;层=区域-货架-层;位置号=区域-货架-层-位置号
|
||||
func zoneDefaultName(level int, code, zoneCode, shelfNo, layerNo string) string {
|
||||
switch level {
|
||||
case 1, 2:
|
||||
return code
|
||||
case 3:
|
||||
return zoneCode + "-" + shelfNo + "-" + code
|
||||
case 4:
|
||||
return zoneCode + "-" + shelfNo + "-" + layerNo + "-" + code
|
||||
}
|
||||
return code
|
||||
}
|
||||
|
||||
// zoneNodeVO 层级节点视图对象(列表/下拉共用)
|
||||
type zoneNodeVO struct {
|
||||
ID int `json:"id"`
|
||||
@@ -265,16 +353,28 @@ func createZoneNodeHandler(ctx *svc.ServiceContext) http.HandlerFunc {
|
||||
fail(w, http.StatusBadRequest, "level 必须为 1~4")
|
||||
return
|
||||
}
|
||||
if req.Code == "" {
|
||||
fail(w, http.StatusBadRequest, "编码必填")
|
||||
// 层/位置号只能通过「批量生成」创建,禁止单条手填(规则2)
|
||||
if req.Level == 3 || req.Level == 4 {
|
||||
fail(w, http.StatusBadRequest, "层级/位置号只能通过“批量生成”创建,不可单条新增")
|
||||
return
|
||||
}
|
||||
// 并发防重(规则5):同父级「查重+创建」加进程内互斥,弥补无唯一索引
|
||||
unlock := zoneGenLock(fmt.Sprintf("z:%d:%s:%s:%s", req.Level, req.ZoneCode, req.ShelfNo, req.LayerNo))
|
||||
defer unlock()
|
||||
// 编码自增引擎(规则3):区域/货架新建时若未填编码,自动取同父级最大尾部数字+1 拼后缀
|
||||
if req.Code == "" {
|
||||
nc, err := nextZoneCode(ctx, req.Level, req.ZoneCode, req.ShelfNo, req.LayerNo)
|
||||
if err != nil {
|
||||
fail(w, http.StatusInternalServerError, err.Error())
|
||||
return
|
||||
}
|
||||
req.Code = nc
|
||||
}
|
||||
if req.Level == 1 {
|
||||
req.Code = strings.ToUpper(req.Code)
|
||||
if req.Name == "" {
|
||||
fail(w, http.StatusBadRequest, "区域名称必填")
|
||||
return
|
||||
}
|
||||
}
|
||||
if req.Name == "" {
|
||||
req.Name = zoneDefaultName(req.Level, req.Code, req.ZoneCode, req.ShelfNo, req.LayerNo)
|
||||
}
|
||||
|
||||
// 逐级解析父级:父级必须已存在,路径(区域+货架+层)唯一确定,避免仅凭 code 跨父级歧义。
|
||||
@@ -360,11 +460,12 @@ 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"`
|
||||
ID int `json:"id"`
|
||||
Code string `json:"code"` // 已不再用于编辑编码(编码锁定,见规则2)
|
||||
Name string `json:"name"`
|
||||
Remark string `json:"remark"`
|
||||
Status string `json:"status"`
|
||||
ZoneCode string `json:"zoneCode"` // 仅 level=2 货架允许改所属区域(整体搬家),级联子孙层/位置与库存
|
||||
}
|
||||
|
||||
// updateZoneNodeHandler 编辑节点(四级均可改名称/备注/启用停用;区域额外同步 zone_name 冗余)。
|
||||
@@ -393,59 +494,57 @@ 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, "位置号必填")
|
||||
// 层/位置号不可编辑(规则2):只允许区域/货架编辑名称/备注/状态
|
||||
if z.Level == zoneLevelLayer || z.Level == zoneLevelPos {
|
||||
fail(w, http.StatusBadRequest, "层级/位置号不支持编辑,只能通过批量生成管理")
|
||||
return
|
||||
}
|
||||
// 货架(level2)改所属区域(整体搬家):级联子孙层/位置 zone_code 与库存 zone_code(规则:所属货架/层不可改,但货架可整体换区)
|
||||
newZone := strings.ToUpper(strings.TrimSpace(req.ZoneCode))
|
||||
if z.Level == zoneLevelShelf && newZone != "" && newZone != z.ZoneCode {
|
||||
reg, rerr := ctx.EntClient.Zone.Query().Where(zone.LevelEQ(zoneLevelRegion), zone.CodeEQ(newZone)).Only(ctx0())
|
||||
if rerr != nil {
|
||||
fail(w, http.StatusBadRequest, "目标区域不存在:"+newZone)
|
||||
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
|
||||
shelfNo := z.ShelfNo
|
||||
if _, err := ctx.EntClient.Zone.Update().Where(zone.IDEQ(z.ID)).SetZoneCode(newZone).SetParentCode(reg.Code).Save(ctx0()); err != nil {
|
||||
fail(w, http.StatusInternalServerError, "货架改区域失败: "+err.Error())
|
||||
return
|
||||
}
|
||||
if _, err := ctx.EntClient.Zone.Update().Where(zone.ShelfNoEQ(shelfNo)).SetZoneCode(newZone).Save(ctx0()); err != nil {
|
||||
fail(w, http.StatusInternalServerError, "级联层/位置失败: "+err.Error())
|
||||
return
|
||||
}
|
||||
if _, err := ctx.EntClient.Inventory.Update().Where(inventory.ShelfNoEQ(shelfNo), inventory.ZoneCodeEQ(z.ZoneCode)).SetZoneCode(newZone).Save(ctx0()); err != nil {
|
||||
fail(w, http.StatusInternalServerError, "级联库存失败(inventories): "+err.Error())
|
||||
return
|
||||
}
|
||||
if _, err := ctx.EntClient.InboundOrder.Update().Where(inboundorder.ShelfNoEQ(shelfNo), inboundorder.ZoneCodeEQ(z.ZoneCode)).SetZoneCode(newZone).Save(ctx0()); err != nil {
|
||||
fail(w, http.StatusInternalServerError, "级联库存失败(inbound_orders): "+err.Error())
|
||||
return
|
||||
}
|
||||
if _, err := ctx.EntClient.OutboundOrder.Update().Where(outboundorder.ShelfNoEQ(shelfNo), outboundorder.ZoneCodeEQ(z.ZoneCode)).SetZoneCode(newZone).Save(ctx0()); err != nil {
|
||||
fail(w, http.StatusInternalServerError, "级联库存失败(outbound_orders): "+err.Error())
|
||||
return
|
||||
}
|
||||
if _, err := ctx.EntClient.StocktakeItem.Update().Where(stocktakeitem.ShelfNoEQ(shelfNo), stocktakeitem.ZoneCodeEQ(z.ZoneCode)).SetZoneCode(newZone).Save(ctx0()); err != nil {
|
||||
fail(w, http.StatusInternalServerError, "级联库存失败(stocktake_items): "+err.Error())
|
||||
return
|
||||
}
|
||||
}
|
||||
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
|
||||
}
|
||||
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)
|
||||
logMsg := "编辑" + zoneLevelName(z.Level) + " " + z.Code
|
||||
ctx.EventLog.Write(ctx0(), "zone.update", r.Header.Get("X-Username"), "zone", z.Code, logMsg, nil)
|
||||
ok(w, map[string]any{"id": req.ID})
|
||||
}
|
||||
}
|
||||
@@ -568,18 +667,14 @@ func listZonesForPicker(ctx *svc.ServiceContext) http.HandlerFunc {
|
||||
}
|
||||
|
||||
type zoneBatchGenReq struct {
|
||||
ZoneCode string `json:"zoneCode"`
|
||||
ShelfNo string `json:"shelfNo"`
|
||||
LayerStart int `json:"layerStart"` // level=3 批量生成层:层范围起
|
||||
LayerEnd int `json:"layerEnd"` // level=3 批量生成层:层范围止
|
||||
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 提交时携带预览表中(可能手改过的)层名称,非空则优先采用
|
||||
Positions []zoneBatchPosName `json:"positions"` // level=4 提交时携带预览表中(可能手改过的)位置名称,非空则优先采用
|
||||
ZoneCode string `json:"zoneCode"`
|
||||
ShelfNo string `json:"shelfNo"`
|
||||
LayerNo string `json:"layerNo"` // level=4 批量生成位置号:层号(必须为已存在的层)
|
||||
Count int `json:"count"` // level=3 生成层 / level=4 生成位置号:均从「该父级最大尾部数字+1」起连续生成
|
||||
Level int `json:"level"` // 3=批量生成层(level3) 4=批量生成位置号(level4,默认,需指定已存在的层)
|
||||
Preview bool `json:"preview"`
|
||||
Layers []zoneBatchLayerName `json:"layers"` // level=3 提交时携带预览表中(可能手改过的)层名称,非空则优先采用
|
||||
Positions []zoneBatchPosName `json:"positions"` // level=4 提交时携带预览表中(可能手改过的)位置名称,非空则优先采用
|
||||
}
|
||||
|
||||
// zoneBatchLayerName 批量生成层:前端预览后手改的层名称(layerNo→layerName)
|
||||
@@ -621,18 +716,14 @@ func batchGenerateHandler(ctx *svc.ServiceContext) http.HandlerFunc {
|
||||
}
|
||||
zoneCode := sh.ZoneCode
|
||||
|
||||
// ---------- level=3:批量生成层节点(父级货架必须已存在,只生成层自己) ----------
|
||||
// ---------- level=3:批量生成层节点(父级货架必须已存在,按「数量」从 max+1 连续生成) ----------
|
||||
if level == 3 {
|
||||
if req.LayerStart < 0 || req.LayerEnd < req.LayerStart {
|
||||
fail(w, http.StatusBadRequest, "层起止不合法(起始需 ≤ 结束,且 ≥ 0)")
|
||||
if req.Count <= 0 {
|
||||
fail(w, http.StatusBadRequest, "请填写生成数量(≥1)")
|
||||
return
|
||||
}
|
||||
layers := make([]int, 0)
|
||||
for l := req.LayerStart; l <= req.LayerEnd; l++ {
|
||||
layers = append(layers, l)
|
||||
}
|
||||
if len(layers) > 2000 {
|
||||
fail(w, http.StatusBadRequest, "一次最多生成 2000 个层,请缩小范围")
|
||||
if req.Count > 2000 {
|
||||
fail(w, http.StatusBadRequest, "一次最多生成 2000 个层,请缩小数量")
|
||||
return
|
||||
}
|
||||
type genLayer struct {
|
||||
@@ -640,6 +731,14 @@ func batchGenerateHandler(ctx *svc.ServiceContext) http.HandlerFunc {
|
||||
LayerName string `json:"layerName"`
|
||||
Exists bool `json:"exists"`
|
||||
}
|
||||
// 现有层最大尾部数字(兼容纯数字与 N层 两种历史格式)
|
||||
maxNo := 0
|
||||
cur, _ := ctx.EntClient.Zone.Query().Where(zone.LevelEQ(3), zone.ZoneCodeEQ(zoneCode), zone.ShelfNoEQ(req.ShelfNo)).All(ctx0())
|
||||
for _, p := range cur {
|
||||
if v := zoneTrailingNum(p.Code); v > maxNo {
|
||||
maxNo = v
|
||||
}
|
||||
}
|
||||
// 手改层名称优先:前端预览后可点击层名称修改,提交时按 layerNo 带回
|
||||
nameByNo := make(map[string]string, len(req.Layers))
|
||||
for _, ly := range req.Layers {
|
||||
@@ -649,12 +748,12 @@ func batchGenerateHandler(ctx *svc.ServiceContext) http.HandlerFunc {
|
||||
nameByNo[no] = nm
|
||||
}
|
||||
}
|
||||
layerList := make([]genLayer, 0, len(layers))
|
||||
for _, l := range layers {
|
||||
ls := strconv.Itoa(l)
|
||||
layerList := make([]genLayer, 0, req.Count)
|
||||
for i := 1; i <= req.Count; i++ {
|
||||
ls := strconv.Itoa(maxNo+i) + "层"
|
||||
exists, _ := ctx.EntClient.Zone.Query().
|
||||
Where(zone.LevelEQ(3), zone.ZoneCodeEQ(zoneCode), zone.ShelfNoEQ(req.ShelfNo), zone.CodeEQ(ls)).Exist(ctx0())
|
||||
name := req.ShelfNo + "架" + ls + "层"
|
||||
name := zoneDefaultName(3, ls, zoneCode, req.ShelfNo, ls)
|
||||
if v, ok := nameByNo[ls]; ok {
|
||||
name = v
|
||||
}
|
||||
@@ -664,6 +763,9 @@ func batchGenerateHandler(ctx *svc.ServiceContext) http.HandlerFunc {
|
||||
ok(w, map[string]any{"preview": true, "level": 3, "list": layerList, "total": len(layerList)})
|
||||
return
|
||||
}
|
||||
// 并发防重(规则5):同货架下的「查重+创建」加进程内互斥
|
||||
unlock := zoneGenLock(fmt.Sprintf("z:3:%s:%s:", zoneCode, req.ShelfNo))
|
||||
defer unlock()
|
||||
createdL, skippedL := 0, 0
|
||||
for _, it := range layerList {
|
||||
if it.Exists {
|
||||
@@ -680,9 +782,8 @@ func batchGenerateHandler(ctx *svc.ServiceContext) http.HandlerFunc {
|
||||
createdL++
|
||||
}
|
||||
ctx.EventLog.Write(ctx0(), "zone.batch", r.Header.Get("X-Username"), "zone", req.ShelfNo,
|
||||
"批量生成层 "+req.ZoneCode+"/"+req.ShelfNo+" 层"+strconv.Itoa(req.LayerStart)+"-"+strconv.Itoa(req.LayerEnd)+
|
||||
":新建"+strconv.Itoa(createdL)+" 跳过"+strconv.Itoa(skippedL), nil)
|
||||
ok(w, map[string]any{"preview": false, "level": 3, "created": createdL, "skipped": skippedL, "total": len(layers)})
|
||||
"批量生成层 "+req.ZoneCode+"/"+req.ShelfNo+" 从"+(strconv.Itoa(maxNo+1))+"起生成"+strconv.Itoa(req.Count)+"个:新建"+strconv.Itoa(createdL)+" 跳过"+strconv.Itoa(skippedL), nil)
|
||||
ok(w, map[string]any{"preview": false, "level": 3, "created": createdL, "skipped": skippedL, "total": req.Count})
|
||||
return
|
||||
}
|
||||
|
||||
@@ -705,12 +806,12 @@ func batchGenerateHandler(ctx *svc.ServiceContext) http.HandlerFunc {
|
||||
fail(w, http.StatusBadRequest, "层不存在,请先在层管理里创建")
|
||||
return
|
||||
}
|
||||
// 最近编码序号:该层下已存在的最大位置号(按整数解析,非整数忽略)
|
||||
// 最近编码序号:该层下已存在的最大位置号(取编码尾部数字,兼容纯数字与 N号 两种格式)
|
||||
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
|
||||
if v := zoneTrailingNum(p.Code); v > maxNo {
|
||||
maxNo = v
|
||||
}
|
||||
}
|
||||
// 预览:从 maxNo+1 起连续生成 N 个,标注是否已存在(按层号+位置号去重跳过)
|
||||
@@ -722,14 +823,17 @@ func batchGenerateHandler(ctx *svc.ServiceContext) http.HandlerFunc {
|
||||
}
|
||||
preview := make([]genItem, 0, req.Count)
|
||||
for i := 1; i <= req.Count; i++ {
|
||||
ps := strconv.Itoa(maxNo + 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})
|
||||
preview = append(preview, genItem{LayerNo: layerNo, PositionNo: ps, PositionName: zoneDefaultName(4, ps, zoneCode, req.ShelfNo, layerNo), Exists: exists})
|
||||
}
|
||||
if req.Preview {
|
||||
ok(w, map[string]any{"preview": true, "list": preview, "total": len(preview)})
|
||||
return
|
||||
}
|
||||
// 并发防重(规则5):同层下的「查重+创建」加进程内互斥
|
||||
unlock := zoneGenLock(fmt.Sprintf("z:4:%s:%s:%s", zoneCode, req.ShelfNo, layerNo))
|
||||
defer unlock()
|
||||
// 提交:创建不存在的位置号(按层号+位置号去重跳过);手改位置名称优先采用
|
||||
nameByPos := make(map[string]string, len(req.Positions))
|
||||
for _, pn := range req.Positions {
|
||||
@@ -741,12 +845,12 @@ func batchGenerateHandler(ctx *svc.ServiceContext) http.HandlerFunc {
|
||||
}
|
||||
created, skipped := 0, 0
|
||||
for i := 1; i <= req.Count; i++ {
|
||||
ps := strconv.Itoa(maxNo + 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
|
||||
}
|
||||
name := req.ShelfNo + "架" + layerNo + "层" + ps + "位"
|
||||
name := zoneDefaultName(4, ps, zoneCode, req.ShelfNo, layerNo)
|
||||
if v, ok := nameByPos[ps]; ok {
|
||||
name = v
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user