--[[
|
编码: GK-API-09
|
名称: 盘点计划同步接口
|
作者: 袁峰
|
入口函数:Count_Pan_Sync
|
功能说明: 该接口是同步接口,
|
上游系统 调用该接口后,WES 的响应报文 success 说明 WES 已经将该报文接收成功;
|
需要同步盘点任务表和盘点任务明细表xml结构。
|
变更历史:
|
|
<soapenv:Envelope
|
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
|
xmlns:v1="http://www.gkht.com/Inventory/INV/Ebs/Schemas/InventoryTasks/V1.0">
|
<soapenv:Header/>
|
<soapenv:Body>
|
<v1:InventoryTasksReq>
|
<v1:InventoryTasks_Input>
|
<v1:RESTHeader>
|
<v1:NLSLanguage>SIMPLIFIED CHINESE</v1:NLSLanguage>
|
<v1:Org_Id>0</v1:Org_Id>
|
</v1:RESTHeader>
|
<v1:InputParameters>
|
<!-- 第一个盘点任务 -->
|
<v1:InventoryTasks_TB>
|
<v1:taskId>TASK30000100</v1:taskId>
|
<v1:inventoryMode>01</v1:inventoryMode>
|
<v1:workMode>Manual</v1:workMode>
|
<v1:MaintenanceNumber>10</v1:MaintenanceNumber>
|
<v1:inventoryType>YH</v1:inventoryType>
|
<v1:orderNo>YH100001</v1:orderNo>
|
<v1:storerId>CGKHTY</v1:storerId>
|
<v1:ownerId>CGKHTY</v1:ownerId>
|
<v1:mtBeginDate>2025-05-06</v1:mtBeginDate>
|
<v1:mtEndDate>2025-05-06</v1:mtEndDate>
|
<!-- 第一个任务的明细数据 -->
|
<v1:InventoryTasks_TB_ITEM>
|
<v1:orderItemId>100</v1:orderItemId>
|
<v1:skuId>XR33201-2L080B</v1:skuId>
|
<v1:qty>2</v1:qty>
|
<v1:batchNo>PHI00000000000001309</v1:batchNo>
|
</v1:InventoryTasks_TB_ITEM>
|
</v1:InventoryTasks_TB>
|
|
<!-- 第二个盘点任务 -->
|
<v1:InventoryTasks_TB>
|
<v1:taskId>TASK300000101</v1:taskId>
|
<v1:inventoryMode>02</v1:inventoryMode>
|
<v1:workMode>Auto</v1:workMode>
|
<v1:MaintenanceNumber>5</v1:MaintenanceNumber>
|
<v1:inventoryType>PD</v1:inventoryType>
|
<v1:orderNo>PD200001</v1:orderNo>
|
<v1:storerId>GKHT</v1:storerId>
|
<v1:ownerId>GKHT</v1:ownerId>
|
<v1:mtBeginDate>2025-05-07</v1:mtBeginDate>
|
<v1:mtEndDate>2025-05-07</v1:mtEndDate>
|
<!-- 第二个任务的明细数据 -->
|
<v1:InventoryTasks_TB_ITEM>
|
<v1:orderItemId>110</v1:orderItemId>
|
<v1:skuId>ABC123</v1:skuId>
|
<v1:qty>10</v1:qty>
|
<v1:batchNo>BATCH2025001</v1:batchNo>
|
</v1:InventoryTasks_TB_ITEM>
|
<v1:InventoryTasks_TB_ITEM>
|
<v1:orderItemId>111</v1:orderItemId>
|
<v1:skuId>XYZ456</v1:skuId>
|
<v1:qty>3</v1:qty>
|
<v1:batchNo>BATCH2025002</v1:batchNo>
|
</v1:InventoryTasks_TB_ITEM>
|
</v1:InventoryTasks_TB>
|
</v1:InputParameters>
|
</v1:InventoryTasks_Input>
|
</v1:InventoryTasksReq>
|
</soapenv:Body>
|
</soapenv:Envelope>
|
|
响应示例:
|
<flag>sucess</flag>
|
<code>0</code>
|
<message>成功</message>
|
]] --[[
|
功能:盘点计划同步接口(支持多主表+多明细)
|
作者:袁峰
|
入口函数:Count_Pan_Sync
|
说明:解析 xml,支持多个 InventoryTasks_TB(主表),每个主表下可包含多个明细(InventoryTasks_TB_ITEM)
|
]] --
|
|
wms_base = require("wms_base")
|
xml = require("oi_base_xml")
|
mobox = require("OILua_JavelinExt")
|
m3 = require("oi_base_mobox")
|
|
-- 创建统一返回结果
|
function Create_result(flag, code, msg, error)
|
return {
|
flag = flag or "success",
|
code = code or "0",
|
message = msg or "",
|
error = error or ""
|
}
|
end
|
|
function Count_Pan_Sync(strLuaDEID)
|
-- 1. 获取 xml 数据包
|
local nRet, soap_xml = mobox.getCurEditDataPacket(strLuaDEID)
|
if nRet ~= 0 then
|
FinalRes = Create_result("failure", "1", "无法获取数据包: " .. soap_xml)
|
lua.Stop(strLuaDEID, "获取数据包失败", FinalRes)
|
return
|
end
|
|
-- 2. 解析 xml
|
local nRet, parsed_data = xml.parse(soap_xml)
|
if nRet ~= 0 then
|
FinalRes = Create_result("failure", "202", "xml 格式非法")
|
lua.Stop(strLuaDEID, "xml格式非法", FinalRes)
|
return
|
end
|
|
-- 提取主表数据(可能多个 InventoryTasks_TB)
|
local receipt_data = parsed_data.Envelope.Body.InventoryTasksReq.InventoryTasks_Input
|
local input_params = receipt_data.InputParameters
|
|
-- 检查是否存在 InventoryTasks_TB
|
if not input_params or not input_params.InventoryTasks_TB then
|
FinalRes = Create_result("failure", "203", "xml 数据格式错误,缺少 InventoryTasks_TB")
|
lua.Stop(strLuaDEID, "xml 数据格式错误", FinalRes)
|
return
|
end
|
|
-- 判断 InventoryTasks_TB 是单个对象还是数组
|
-- xml 解析后,如果只有一个 InventoryTasks_TB,可能返回 table;多个则可能是数组
|
local mainTables = input_params.InventoryTasks_TB
|
if not mainTables then
|
FinalRes = Create_result("failure", "204", "xml 数据格式错误,InventoryTasks_TB 为空")
|
lua.Stop(strLuaDEID, "xml 数据格式错误", FinalRes)
|
return
|
end
|
-- 5. 统一处理:确保 mainTables 是数组(即使只有一个主表)
|
if mainTables[1] == nil then
|
-- 如果 mainTables 不是数组(单个主表),则包装成数组
|
mainTables = {mainTables}
|
end
|
-- 遍历所有主表数据
|
local result = Create_result()
|
for i = 1, #mainTables do
|
local mainData = mainTables[i]
|
-- lua.DebugEx(strLuaDEID, "主表任务ID:", mainData.taskId)
|
-- 创建主表数据
|
local count_plan = m3.AllocObject(strLuaDEID, "Count_Plan")
|
count_plan.cp_no = mainData.taskId; -- 盘点计划号
|
count_plan.inventory_mode = mainTables[i].inventoryMode; -- 盘点方式
|
count_plan.work_mode = mainData.workMode; -- 作业方式
|
count_plan.count_limit = mainData.MaintenanceNumber; -- 盘点数量限制
|
count_plan.type = mainTables[i].inventoryType; -- 盘点类型
|
count_plan.bs_no = mainData.orderNo; -- 来源单号
|
count_plan.storeId = mainData.storer; -- 货主编码
|
count_plan.ownerId = mainData.owner; -- 物权
|
count_plan.begin_time = mainData.mtBeginDate; -- 动碰开始时间
|
count_plan.end_time = mainData.mtEndDate; -- 动碰结束时间
|
count_plan.prod_line = mainData.productLine; -- 产品线
|
count_plan.begin_location = mainData.beginLocation; -- 开始库位
|
count_plan.end_location = mainData.endLocation; -- 结束库位
|
count_plan.area_code = mainData.areaCode; -- 库区
|
count_plan.op_date = mainData.orderDate; -- 订单日期
|
count_plan.priority = mainData.priority; -- 优先级
|
count_plan.note = mainData.memo; -- 备注
|
-- count_plan.type = wms_base.Get_nConst2(strLuaDEID, "WMS_CountType")
|
count_plan.plan_total = 0; -- 计划盘点数
|
count_plan.b_state = 0;
|
local RetWH_COE, CONST_WH = wms_base.Get_sConst2(strLuaDEID, "GK_Default_Warehouse")
|
if (RetWH_COE ~= 0) then
|
FinalRes = Create_result("failure", "1", "获取仓库常量失败", CONST_WH)
|
lua.Stop(strLuaDEID, "获取仓库常量失败", CONST_WH)
|
else
|
count_plan.wh_code = CONST_WH; -- 仓库
|
count_plan.acc_finish = 0;
|
end
|
lua.DebugEx(strLuaDEID, "创建的表单:", count_plan);
|
local nRet, ret_info = m3.CreateDataObj(strLuaDEID, count_plan)
|
if nRet ~= 0 then
|
result.flag = "failure"
|
result.code = "102"
|
result.message = "创建主表数据失败"
|
result.error = "行号[" .. count_plan.cp_no .. "]创建失败: " .. ret_info
|
lua.DebugEx(strLuaDEID, "主表数据创建失败: ", ret_info)
|
FinalRes = Create_result("failure", "205", "主表数据创建失败: ", ret_info)
|
lua.Stop(strLuaDEID, "创建主表数据失败" .. count_plan.cp_no, ret_info)
|
end
|
-- 检查明细数据是否存在
|
if not mainData.InventoryTasks_TB_ITEM then
|
lua.DebugEx(strLuaDEID, "警告:任务 " .. mainData.taskId .. " 无明细数据")
|
else
|
-- 7. 遍历当前主表的所有明细数据
|
local details = mainData.InventoryTasks_TB_ITEM
|
-- 确保 details 是数组(即使只有一个明细)
|
if details[1] == nil then
|
details = {details}
|
end
|
-- 遍历主表数据及其明细数据
|
for j = 1, #details do
|
local item = details[j]
|
-- 创建明细数据
|
local count_plan_item = m3.AllocObject(strLuaDEID, "Count_Plan_Detail")
|
count_plan_item.cp_no = mainData.taskId; -- 盘点计划号(关联主表)
|
count_plan_item.row_no = item.orderItemId; -- 订单编号
|
count_plan_item.qty = item.qty; -- 计划数量
|
count_plan_item.wms_bn = item.batchNo; -- WMS批次编号
|
count_plan_item.batch_no = item.produceCode; -- 生产批次
|
count_plan_item.prd_date = item.productDate; -- 生产日期
|
count_plan_item.exp_date = item.expiryDate; -- 有效期
|
count_plan_item.reg_no = item.registerNo; -- 商品编码
|
local nRet, ret_info = m3.CreateDataObj(strLuaDEID, count_plan_item)
|
if nRet ~= 0 then
|
result.flag = "failure"
|
result.code = "102"
|
result.message = "创建明细数据失败"
|
result.error = "行号[" .. count_plan_item.row_no .. "]创建失败: " .. ret_info
|
FinalRes = Create_result("failure", "1", "明细表数据创建失败 ", ret_info)
|
lua.Stop(strLuaDEID, "创建明细表数据失败" .. count_plan.cp_no, ret_info)
|
else
|
lua.DebugEx(strLuaDEID, "明细数据创建成功!", count_plan_item)
|
FinalRes = Create_result("success", "0", "成功", "123")
|
end
|
end
|
end
|
end
|
local xml_result = xml.json_to_xml(FinalRes, "response")
|
mobox.returnValue(strLuaDEID, 0, xml_result, 0)
|
end
|