Files
bj_power/bj_power_wms/internal/handler/zone_recommend.go
T

41 lines
1.2 KiB
Go
Raw Normal View History

package handler
import (
"net/http"
"strings"
"bj_power_wms/ent"
"bj_power_wms/ent/inboundorder"
"bj_power_wms/internal/svc"
)
// lastInboundLocationHandler 入库库位联动:返回该物料最近一次入库的库位(区域/货架/层/位置号)。
// 前端在「选物料」后自动回填到入库表单(可手动修改),替代原「推荐库位」按钮式交互。
func lastInboundLocationHandler(ctx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
materialCode := strings.TrimSpace(r.URL.Query().Get("materialCode"))
if materialCode == "" {
fail(w, http.StatusBadRequest, "materialCode 必填")
return
}
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
}
fail(w, http.StatusInternalServerError, err.Error())
return
}
ok(w, map[string]any{
"zoneCode": ib.ZoneCode,
"shelfNo": ib.ShelfNo,
"layerNo": ib.LayerNo,
"positionNo": ib.PositionNo,
})
}
}