| | |
| | | 入口函数: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 { |
| | |
| | | -- 1. 获取 xml 数据包 |
| | | local nRet, soap_xml = mobox.getCurEditDataPacket(strLuaDEID) |
| | | if nRet ~= 0 then |
| | | FinalRes = Create_result("failure", "201", "无法获取数据包: " .. soap_xml) |
| | | FinalRes = Create_result("failure", "1", "无法获取数据包: " .. soap_xml) |
| | | lua.Stop(strLuaDEID, "获取数据包失败", FinalRes) |
| | | return |
| | | end |
| | |
| | | return |
| | | end |
| | | |
| | | -- 3. 提取主表数据(可能多个 InventoryTasks_TB) |
| | | -- 提取主表数据(可能多个 InventoryTasks_TB) |
| | | local receipt_data = parsed_data.Envelope.Body.InventoryTasksReq.InventoryTasks_Input |
| | | local input_params = receipt_data.InputParameters |
| | | |
| | |
| | | return |
| | | end |
| | | |
| | | -- 4. 判断 InventoryTasks_TB 是单个对象还是数组 |
| | | -- 判断 InventoryTasks_TB 是单个对象还是数组 |
| | | -- xml 解析后,如果只有一个 InventoryTasks_TB,可能返回 table;多个则可能是数组 |
| | | local mainTables = input_params.InventoryTasks_TB |
| | | if not mainTables then |
| | |
| | | -- 如果 mainTables 不是数组(单个主表),则包装成数组 |
| | | mainTables = {mainTables} |
| | | end |
| | | -- 6. 遍历所有主表数据 |
| | | -- 遍历所有主表数据 |
| | | local result = Create_result() |
| | | for i = 1, #mainTables do |
| | | local mainData = mainTables[i] |
| | |
| | | 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", "201", "获取仓库常量失败", CONST_WH) |
| | | FinalRes = Create_result("failure", "1", "获取仓库常量失败", CONST_WH) |
| | | lua.Stop(strLuaDEID, "获取仓库常量失败", CONST_WH) |
| | | else |
| | | count_plan.wh_code = CONST_WH; -- 仓库 |
| | |
| | | if details[1] == nil then |
| | | details = {details} |
| | | end |
| | | |
| | | -- 遍历主表数据及其明细数据 |
| | | for j = 1, #details do |
| | | local item = details[j] |
| | |
| | | result.code = "102" |
| | | result.message = "创建明细数据失败" |
| | | result.error = "行号[" .. count_plan_item.row_no .. "]创建失败: " .. ret_info |
| | | FinalRes = Create_result("failure", "206", "明细表数据创建失败: ", ret_info) |
| | | lua.DebugEx(strLuaDEID, "明细表数据创建失败: ", 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 |
| | | |
| | | -- 8. 返回成功 |
| | | local xml_result = xml.json_to_xml(FinalRes, "response") |
| | | mobox.returnValue(strLuaDEID, 0, xml_result, 0) |
| | | end |