43 lines
1.4 KiB
Go
43 lines
1.4 KiB
Go
package handler
|
||||
|
|
|
|||
|
|
import (
|
|||
|
|
"net/http"
|
|||
|
|
"strings"
|
|||
|
|
|
|||
|
|
"bj_power_wms/ent/inventory"
|
|||
|
|
"bj_power_wms/internal/svc"
|
|||
|
|
)
|
|||
|
|
|
|||
|
|
// inventorySnExistsInternalHandler 按成品序列号精确核验 WMS 库存(X-API-TOKEN 内部接口,只读)。
|
|||
|
|
// GET /api/internal/inventory/sn-exists?sn=
|
|||
|
|
// MES「成品试验」登记前调用:成品 SN 必须对应一条仍有效在库的库存行。
|
|||
|
|
// 判定口径:sn_code 精确相等 + 数量>0(inventories 无软删字段,不臆造删除标记,
|
|||
|
|
// 与库存聚合查询 /api/internal/material/query 的 QuantityGT(0) 口径一致)。
|
|||
|
|
// 命中返回 found=true 并带出 materialCode/qty;未命中返回 found=false,不写任何表。
|
|||
|
|
func inventorySnExistsInternalHandler(ctx *svc.ServiceContext) http.HandlerFunc {
|
|||
|
|
return func(w http.ResponseWriter, r *http.Request) {
|
|||
|
|
sn := strings.TrimSpace(r.URL.Query().Get("sn"))
|
|||
|
|
if sn == "" {
|
|||
|
|
fail(w, http.StatusBadRequest, "成品序列号不能为空")
|
|||
|
|
return
|
|||
|
|
}
|
|||
|
|
rows, err := ctx.EntClient.Inventory.Query().
|
|||
|
|
Where(inventory.SnCodeEQ(sn), inventory.QuantityGT(0)).
|
|||
|
|
Limit(1).All(ctx0())
|
|||
|
|
if err != nil {
|
|||
|
|
fail(w, http.StatusInternalServerError, "查询成品库存失败,请稍后重试")
|
|||
|
|
return
|
|||
|
|
}
|
|||
|
|
if len(rows) == 0 {
|
|||
|
|
ok(w, map[string]any{"found": false, "sn": sn})
|
|||
|
|
return
|
|||
|
|
}
|
|||
|
|
ok(w, map[string]any{
|
|||
|
|
"found": true,
|
|||
|
|
"sn": sn,
|
|||
|
|
"materialCode": rows[0].MaterialCode,
|
|||
|
|
"qty": rows[0].Quantity,
|
|||
|
|
})
|
|||
|
|
}
|
|||
|
|
}
|