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-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
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|