2026-09-17 12:49:07 +08:00
|
|
|
package handler
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"net/http"
|
2026-09-19 10:54:15 +08:00
|
|
|
"strings"
|
2026-09-17 12:49:07 +08:00
|
|
|
|
|
|
|
|
"bj_power_wms/ent"
|
2026-09-19 10:54:15 +08:00
|
|
|
"bj_power_wms/ent/inboundorder"
|
2026-09-19 17:04:58 +08:00
|
|
|
"bj_power_wms/ent/inventory"
|
2026-09-17 12:49:07 +08:00
|
|
|
"bj_power_wms/internal/svc"
|
|
|
|
|
)
|
|
|
|
|
|
2026-09-19 10:54:15 +08:00
|
|
|
// lastInboundLocationHandler 入库库位联动:返回该物料最近一次入库的库位(区域/货架/层/位置号)。
|
|
|
|
|
// 前端在「选物料」后自动回填到入库表单(可手动修改),替代原「推荐库位」按钮式交互。
|
|
|
|
|
func lastInboundLocationHandler(ctx *svc.ServiceContext) http.HandlerFunc {
|
2026-09-17 12:49:07 +08:00
|
|
|
return func(w http.ResponseWriter, r *http.Request) {
|
2026-09-19 10:54:15 +08:00
|
|
|
materialCode := strings.TrimSpace(r.URL.Query().Get("materialCode"))
|
2026-09-17 12:49:07 +08:00
|
|
|
if materialCode == "" {
|
|
|
|
|
fail(w, http.StatusBadRequest, "materialCode 必填")
|
|
|
|
|
return
|
|
|
|
|
}
|
2026-09-19 10:54:15 +08:00
|
|
|
ib, err := ctx.EntClient.InboundOrder.Query().
|
|
|
|
|
Where(inboundorder.MaterialCodeEQ(materialCode)).
|
|
|
|
|
Order(ent.Desc("created_at"), ent.Desc("id")).
|
|
|
|
|
First(ctx0())
|
|
|
|
|
if err != nil {
|
|
|
|
|
if ent.IsNotFound(err) {
|
|
|
|
|
ok(w, map[string]any{"zoneCode": "", "shelfNo": "", "layerNo": "", "positionNo": ""})
|
|
|
|
|
return
|
2026-09-17 12:49:07 +08:00
|
|
|
}
|
2026-09-19 10:54:15 +08:00
|
|
|
fail(w, http.StatusInternalServerError, err.Error())
|
|
|
|
|
return
|
2026-09-17 12:49:07 +08:00
|
|
|
}
|
|
|
|
|
ok(w, map[string]any{
|
2026-09-19 10:54:15 +08:00
|
|
|
"zoneCode": ib.ZoneCode,
|
|
|
|
|
"shelfNo": ib.ShelfNo,
|
|
|
|
|
"layerNo": ib.LayerNo,
|
|
|
|
|
"positionNo": ib.PositionNo,
|
2026-09-17 12:49:07 +08:00
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-09-19 17:04:58 +08:00
|
|
|
|
|
|
|
|
// outboundLocationHintHandler 出库库位联动(客户诉求 一.9「出库相同」)。
|
|
|
|
|
// 取值优先级:① 指定批次在库的实际四级库位(最准,出库就是从该货位取货)
|
|
|
|
|
// ② 该物料最近一次入库的库位(历史常用库位)③ 均无则返回空,前端可继续走同区空位推荐。
|
|
|
|
|
func outboundLocationHintHandler(ctx *svc.ServiceContext) http.HandlerFunc {
|
|
|
|
|
return func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
materialCode := strings.TrimSpace(r.URL.Query().Get("materialCode"))
|
|
|
|
|
batchNo := strings.TrimSpace(r.URL.Query().Get("batchNo"))
|
|
|
|
|
emptyHint := map[string]any{"zoneCode": "", "shelfNo": "", "layerNo": "", "positionNo": ""}
|
|
|
|
|
if materialCode == "" && batchNo == "" {
|
|
|
|
|
ok(w, emptyHint)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if batchNo != "" {
|
|
|
|
|
if b, err := ctx.EntClient.Inventory.Query().
|
|
|
|
|
Where(inventory.ManageModeEQ(1), inventory.BatchNoEQ(batchNo)).
|
|
|
|
|
Only(ctx0()); err == nil {
|
|
|
|
|
ok(w, map[string]any{
|
|
|
|
|
"zoneCode": b.ZoneCode,
|
|
|
|
|
"shelfNo": b.ShelfNo,
|
|
|
|
|
"layerNo": b.LayerNo,
|
|
|
|
|
"positionNo": b.PositionNo,
|
|
|
|
|
})
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if materialCode == "" {
|
|
|
|
|
ok(w, emptyHint)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
ib, err := ctx.EntClient.InboundOrder.Query().
|
|
|
|
|
Where(inboundorder.MaterialCodeEQ(materialCode)).
|
|
|
|
|
Order(ent.Desc("created_at"), ent.Desc("id")).
|
|
|
|
|
First(ctx0())
|
|
|
|
|
if err != nil {
|
|
|
|
|
ok(w, emptyHint)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
ok(w, map[string]any{
|
|
|
|
|
"zoneCode": ib.ZoneCode,
|
|
|
|
|
"shelfNo": ib.ShelfNo,
|
|
|
|
|
"layerNo": ib.LayerNo,
|
|
|
|
|
"positionNo": ib.PositionNo,
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|