130 lines
5.1 KiB
Python
130 lines
5.1 KiB
Python
#!/usr/bin/env python3
|
|||
|
|
# -*- coding: utf-8 -*-
|
||
|
|
"""统一出库主表 + 装箱属性落库 端到端验证脚本"""
|
||
|
|
import json
|
||
|
|
import urllib.request
|
||
|
|
import urllib.error
|
||
|
|
|
||
|
|
BASE = "http://127.0.0.1:8890"
|
||
|
|
|
||
|
|
def req(method, path, body=None, token=None, raw=False):
|
||
|
|
url = BASE + path
|
||
|
|
data = None
|
||
|
|
headers = {"Content-Type": "application/json"}
|
||
|
|
if token:
|
||
|
|
headers["Authorization"] = "Bearer " + token
|
||
|
|
if body is not None:
|
||
|
|
data = json.dumps(body).encode("utf-8")
|
||
|
|
r = urllib.request.Request(url, data=data, headers=headers, method=method)
|
||
|
|
try:
|
||
|
|
with urllib.request.urlopen(r, timeout=10) as resp:
|
||
|
|
raw_text = resp.read().decode("utf-8")
|
||
|
|
return resp.status, raw_text
|
||
|
|
except urllib.error.HTTPError as e:
|
||
|
|
return e.code, e.read().decode("utf-8", "replace")
|
||
|
|
|
||
|
|
def j(resp_text):
|
||
|
|
try:
|
||
|
|
return json.loads(resp_text)
|
||
|
|
except Exception:
|
||
|
|
return {"_raw": resp_text}
|
||
|
|
|
||
|
|
def data_of(resp_text):
|
||
|
|
d = j(resp_text)
|
||
|
|
return d.get("data") if isinstance(d, dict) else None
|
||
|
|
|
||
|
|
print("=== 0) login ===")
|
||
|
|
st, txt = req("POST", "/api/auth/login", {"username": "admin", "password": "123456"})
|
||
|
|
print(st, txt)
|
||
|
|
tok_data = data_of(txt)
|
||
|
|
TOKEN = tok_data.get("token") if isinstance(tok_data, dict) else None
|
||
|
|
print("token:", (TOKEN[:20] + "...") if TOKEN else None)
|
||
|
|
|
||
|
|
def ensure_material(code, name, mode):
|
||
|
|
# 查是否已存在
|
||
|
|
st, txt = req("GET", "/api/material/query?keyword=" + code, token=TOKEN)
|
||
|
|
lst = data_of(txt)
|
||
|
|
if isinstance(lst, dict):
|
||
|
|
for m in lst.get("list", []):
|
||
|
|
if m.get("code") == code:
|
||
|
|
print(" 物料已存在:", m.get("id"), code, "mode=", m.get("manageMode"))
|
||
|
|
return m
|
||
|
|
# 创建
|
||
|
|
st, txt = req("POST", "/api/material/create",
|
||
|
|
{"code": code, "name": name, "manageMode": mode, "unit": "PCS"},
|
||
|
|
token=TOKEN)
|
||
|
|
print(" 创建物料", st, txt)
|
||
|
|
return data_of(txt)
|
||
|
|
|
||
|
|
print("=== 1) 物料档案 ===")
|
||
|
|
MAT_B = ensure_material("TEST_BATCH_001", "测试结构件", 1)
|
||
|
|
MAT_S = ensure_material("TEST_SN_001", "测试精密件", 2)
|
||
|
|
|
||
|
|
print("=== 2) 批次入库 TEST_BATCH_001 B-BOX001 qty5 ===")
|
||
|
|
st, txt = req("POST", "/api/inbound/create",
|
||
|
|
{"inboundType": "purchase", "materialCode": "TEST_BATCH_001",
|
||
|
|
"batchNo": "B-BOX001", "quantity": 5, "zoneCode": "Z01", "operator": "tester"},
|
||
|
|
token=TOKEN)
|
||
|
|
print(st, txt)
|
||
|
|
|
||
|
|
print("=== 3) SN入库 TEST_SN_001 SNBOX001/SNBOX002 ===")
|
||
|
|
st, txt = req("POST", "/api/inbound/create",
|
||
|
|
{"inboundType": "purchase", "materialCode": "TEST_SN_001",
|
||
|
|
"snList": ["SNBOX001", "SNBOX002"], "zoneCode": "Z01", "operator": "tester"},
|
||
|
|
token=TOKEN)
|
||
|
|
print(st, txt)
|
||
|
|
|
||
|
|
print("=== 4) 通用出库(批次+箱号 BOXTEST001) ===")
|
||
|
|
st, txt = req("POST", "/api/outbound/general",
|
||
|
|
{"materialCode": "TEST_BATCH_001", "batchNo": "B-BOX001", "qty": 3,
|
||
|
|
"operator": "tester", "zoneCode": "Z01", "boxNo": "BOXTEST001",
|
||
|
|
"contractNo": "HT2026-001", "remark": "批次装箱测试"},
|
||
|
|
token=TOKEN)
|
||
|
|
print(st, txt)
|
||
|
|
|
||
|
|
print("=== 5) 通用出库(SN+箱号 BOXTEST002) ===")
|
||
|
|
st, txt = req("POST", "/api/outbound/general",
|
||
|
|
{"materialCode": "TEST_SN_001", "snList": ["SNBOX001"],
|
||
|
|
"operator": "tester", "zoneCode": "Z01", "boxNo": "BOXTEST002",
|
||
|
|
"contractNo": "HT2026-002"},
|
||
|
|
token=TOKEN)
|
||
|
|
print(st, txt)
|
||
|
|
|
||
|
|
print("=== 6) 查询 general 出库单(校验装箱字段落库) ===")
|
||
|
|
st, txt = req("GET", "/api/outbound/query?outboundType=general", token=TOKEN)
|
||
|
|
d = data_of(txt)
|
||
|
|
lst = d.get("list", []) if isinstance(d, dict) else []
|
||
|
|
print(" total=", d.get("total") if isinstance(d, dict) else None)
|
||
|
|
for row in lst:
|
||
|
|
print(" ---")
|
||
|
|
print(" outboundNo=", row.get("outboundNo"), "type=", row.get("outboundType"),
|
||
|
|
"material=", row.get("materialCode"), "qty=", row.get("quantity"))
|
||
|
|
print(" boxNo=", repr(row.get("boxNo")), "contractNo=", repr(row.get("contractNo")),
|
||
|
|
"boxSnList=", repr(row.get("boxSnList")))
|
||
|
|
for det in row.get("details", []):
|
||
|
|
print(" detail:", det.get("snCode") or det.get("batchNo"), "qty=", det.get("quantity"))
|
||
|
|
|
||
|
|
print("=== 7) 导出全部出库(整表导出) ===")
|
||
|
|
st, txt = req("GET", "/api/outbound/export", token=TOKEN)
|
||
|
|
d = data_of(txt)
|
||
|
|
lst = d.get("list", []) if isinstance(d, dict) else []
|
||
|
|
print(" total=", d.get("total") if isinstance(d, dict) else None)
|
||
|
|
boxnos = sorted({r.get("boxNo") for r in lst if r.get("boxNo")})
|
||
|
|
print(" boxNos=", boxnos)
|
||
|
|
# 抽样打印含装箱字段的行
|
||
|
|
for row in lst:
|
||
|
|
if row.get("boxNo"):
|
||
|
|
print(" 导出行:", row.get("outboundNo"), "boxNo=", row.get("boxNo"),
|
||
|
|
"contractNo=", row.get("contractNo"), "snCodes=", row.get("snCodes"))
|
||
|
|
|
||
|
|
print("=== 8) 旧装箱接口应 404 ===")
|
||
|
|
st, txt = req("GET", "/api/package/query", token=TOKEN)
|
||
|
|
print(" HTTP", st)
|
||
|
|
|
||
|
|
print("=== 9) 大屏 packageCount(应随箱号记录增长) ===")
|
||
|
|
st, txt = req("GET", "/api/display/overview")
|
||
|
|
d = data_of(txt)
|
||
|
|
print(" packageCount=", d.get("packageCount") if isinstance(d, dict) else txt)
|
||
|
|
|
||
|
|
print("=== DONE ===")
|