1. 国科盘点信息同步功能代码校验
2. 小件收货信息同步
3. 完善SKU同步Grid料箱
| | |
| | | </soapenv:Envelope> |
| | | |
| | | 响应示例: |
| | | <flag>sucess</flag> |
| | | <response> |
| | | <flag>success</flag> |
| | | <code>0</code> |
| | | <message>成功</message> |
| | | ]] --[[ |
| | | 功能:盘点计划同步接口(支持多主表+多明细) |
| | | 作者:袁峰 |
| | | 入口函数:Count_Pan_Sync |
| | | 说明:解析 xml,支持多个 InventoryTasks_TB(主表),每个主表下可包含多个明细(InventoryTasks_TB_ITEM) |
| | | </response> |
| | | ]] -- |
| | | |
| | | wms_base = require("wms_base") |
| | | xml = require("oi_base_xml") |
| | | mobox = require("OILua_JavelinExt") |
| | | m3 = require("oi_base_mobox") |
| | | wms = require("OILua_WMS") |
| | | |
| | | -- 创建统一返回结果 |
| | | function Create_result(flag, code, msg, error) |
| | | return { |
| | | flag = flag or "success", |
| | | code = code or "0", |
| | | message = msg or "", |
| | | error = error or "" |
| | | message = msg or "" |
| | | } |
| | | end |
| | | |
| | | function Count_Pan_Sync(strLuaDEID) |
| | | -- 初始化最终结果 |
| | | local FinalRes = Create_result() |
| | | |
| | | -- 1. 获取 xml 数据包 |
| | | local nRet, soap_xml = mobox.getCurEditDataPacket(strLuaDEID) |
| | | if nRet ~= 0 then |
| | | FinalRes = Create_result("failure", "1", "无法获取数据包: " .. soap_xml) |
| | | lua.Stop(strLuaDEID, "获取数据包失败", FinalRes) |
| | | FinalRes = Create_result("failure", "201", "无法获取数据包: " .. soap_xml) |
| | | local xml_result = xml.json_to_xml(FinalRes, "response") |
| | | mobox.returnValue(strLuaDEID, 0, xml_result, 0) |
| | | lua.Stop(strLuaDEID, "获取数据包失败", soap_xml) |
| | | return |
| | | end |
| | | |
| | | lua.DebugEx(strLuaDEID, "获取到的数据包", soap_xml) |
| | | |
| | | -- 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) |
| | | local xml_result = xml.json_to_xml(FinalRes, "response") |
| | | mobox.returnValue(strLuaDEID, 0, xml_result, 0) |
| | | lua.Stop(strLuaDEID, "xml格式非法", parsed_data) |
| | | return |
| | | end |
| | | |
| | | -- 提取主表数据(可能多个 InventoryTasks_TB) |
| | | -- 3. 提取主表数据 |
| | | 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) |
| | | local xml_result = xml.json_to_xml(FinalRes, "response") |
| | | mobox.returnValue(strLuaDEID, 0, xml_result, 0) |
| | | lua.Stop(strLuaDEID, "xml 数据格式错误", xml_result) |
| | | return |
| | | end |
| | | |
| | | -- 判断 InventoryTasks_TB 是单个对象还是数组 |
| | | -- xml 解析后,如果只有一个 InventoryTasks_TB,可能返回 table;多个则可能是数组 |
| | | -- 4. 统一处理:确保 mainTables 是数组(即使只有一个主表) |
| | | 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() |
| | | -- 5. 获取系统常量 |
| | | local RetWH_COE, CONST_WH = wms_base.Get_sConst2("GK_Default_Warehouse") |
| | | if RetWH_COE ~= 0 then |
| | | lua.DebugEx(strLuaDEID, "获取仓库常量失败!", CONST_WH) |
| | | FinalRes = Create_result("failure", "204", "获取仓库常量失败" .. CONST_WH) |
| | | local xml_result = xml.json_to_xml(FinalRes, "response") |
| | | mobox.returnValue(strLuaDEID, 0, xml_result, 0) |
| | | lua.Stop(strLuaDEID, "获取系统常量失败", xml_result) |
| | | return |
| | | end |
| | | |
| | | -- 6. 遍历所有盘点任务 |
| | | for i = 1, #mainTables do |
| | | local mainData = mainTables[i] |
| | | -- lua.DebugEx(strLuaDEID, "主表任务ID:", mainData.taskId) |
| | | |
| | | -- 检查盘点任务是否已存在 |
| | | local strCondition = string.format("S_CP_NO = '%s'", mainData.taskId) |
| | | lua.DebugEx(strLuaDEID, "查询盘点任务条件", strCondition) |
| | | local nRet, retCountPlan = m3.GetDataObjByCondition(strLuaDEID, "Count_Plan", strCondition) |
| | | lua.DebugEx(strLuaDEID, "查询结果", retCountPlan) |
| | | if nRet == 0 then |
| | | -- 查询成功且找到记录,说明盘点任务已存在 |
| | | lua.DebugEx(strLuaDEID, "查询成功,盘点任务已存在", retCountPlan) |
| | | FinalRes = Create_result("failure", "1", "盘点任务已存在", |
| | | "盘点任务[" .. mainData.taskId .. "]已存在") |
| | | local xml_result = xml.json_to_xml(FinalRes, "response") |
| | | mobox.returnValue(strLuaDEID, 0, xml_result, 0) |
| | | lua.Stop(strLuaDEID, "盘点任务已存在", retCountPlan) |
| | | return |
| | | -- 如果是nRet=1,那么表示这个数据在表中不存在,可以放心插入新数据 |
| | | elseif nRet ~= 1 then |
| | | -- 查询出错 |
| | | lua.DebugEx(strLuaDEID, "查询出错", retCountPlan) |
| | | FinalRes = Create_result("failure", "206", "检查盘点任务是否存在时出错", |
| | | "检查盘点任务[" .. mainData.taskId .. "]时出错: " .. retCountPlan) |
| | | local xml_result = xml.json_to_xml(FinalRes, "response") |
| | | mobox.returnValue(strLuaDEID, 0, xml_result, 0) |
| | | lua.Stop(strLuaDEID, "检查盘点任务是否存在时出错", xml_result) |
| | | return |
| | | end |
| | | |
| | | -- 创建主表数据 |
| | | 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); |
| | | count_plan.cp_no = mainData.taskId |
| | | count_plan.inventory_mode = mainData.inventoryMode |
| | | count_plan.work_mode = mainData.workMode |
| | | count_plan.count_limit = mainData.MaintenanceNumber |
| | | count_plan.pan_type = mainData.inventoryType or "" |
| | | lua.DebugEx(strLuaDEID, "容器类型:", count_plan.pan_type); |
| | | count_plan.bs_no = mainData.orderNo |
| | | count_plan.storer = mainData.storerId |
| | | count_plan.owner = mainData.ownerId |
| | | count_plan.begin_time = mainData.mtBeginDate |
| | | count_plan.end_time = mainData.mtEndDate |
| | | count_plan.wh_code = CONST_WH |
| | | count_plan.plan_total = 0 |
| | | count_plan.b_state = 0 |
| | | count_plan.acc_finish = 0 |
| | | lua.DebugEx(strLuaDEID, "获取创建数据:", count_plan); |
| | | -- 检查是否已存在相同关键字的记录 |
| | | local nRet, ret_info = m3.CreateDataObj(strLuaDEID, count_plan) |
| | | lua.DebugEx(strLuaDEID, "创建结果", ret_info) |
| | | 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 .. " 无明细数据") |
| | | -- 再次检查是否真的存在 |
| | | local nRetCheck, retCountPlanCheck = m3.GetDataObjByCondition(strLuaDEID, "Count_Plan", strCondition) |
| | | lua.DebugEx(strLuaDEID, "再次查询结果", retCountPlanCheck) |
| | | if nRetCheck == 0 then |
| | | FinalRes = Create_result("failure", "205", "盘点任务已存在", |
| | | "盘点任务[" .. mainData.taskId .. "]已存在") |
| | | else |
| | | -- 7. 遍历当前主表的所有明细数据 |
| | | FinalRes = Create_result("failure", "207", "创建盘点任务主表失败", |
| | | "盘点任务[" .. mainData.taskId .. "]创建失败: " .. ret_info) |
| | | end |
| | | local xml_result = xml.json_to_xml(FinalRes, "response") |
| | | mobox.returnValue(strLuaDEID, 0, xml_result, 0) |
| | | lua.Stop(strLuaDEID, "创建盘点任务主表失败", ret_info) |
| | | return |
| | | end |
| | | |
| | | -- 检查明细数据是否存在 |
| | | if mainData.InventoryTasks_TB_ITEM == nil 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; -- 商品编码 |
| | | count_plan_item.cp_no = mainData.taskId |
| | | count_plan_item.row_no = item.orderItemId |
| | | count_plan_item.qty = lua.Get_NumAttrValue(item.qty) or 0 |
| | | count_plan_item.wms_bn = item.batchNo |
| | | count_plan_item.batch_no = item.produceCode or "" |
| | | count_plan_item.prd_date = item.productDate or "" |
| | | count_plan_item.exp_date = item.expiryDate or "" |
| | | count_plan_item.reg_no = item.registerNo or "" |
| | | |
| | | 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") |
| | | FinalRes = Create_result("failure", "208", "创建盘点明细失败", "创建失败: " .. ret_info) |
| | | local xml_result = xml.json_to_xml(FinalRes, "response") |
| | | mobox.returnValue(strLuaDEID, 0, xml_result, 0) |
| | | lua.DebugEx(strLuaDEID, "创建盘点明细失败", xml_result) |
| | | lua.Stop(strLuaDEID, "创建盘点明细失败", ret_info) |
| | | return |
| | | end |
| | | end |
| | | end |
| | | end |
| | | |
| | | -- 8. 返回成功 |
| | | FinalRes = Create_result("success", "0", "盘点任务创建成功") |
| | | local xml_result = xml.json_to_xml(FinalRes, "response") |
| | | mobox.returnValue(strLuaDEID, 0, xml_result, 0) |
| | | end |
| | |
| | | xml = require("oi_base_xml") |
| | | mobox = require("OILua_JavelinExt") |
| | | m3 = require("oi_base_mobox") |
| | | function Create_result(flag, code, msg) |
| | | return { |
| | | flag = flag or "success", |
| | | code = code or "0", |
| | | message = msg or "" |
| | | } |
| | | end |
| | | function Receipt_Sync(strLuaDEID) |
| | | -- 初始化最终结果 |
| | | local FinalRes = Create_result() |
| | | |
| | | -- 1. 获取 xml 数据包 |
| | | local nRet, soap_xml = mobox.getCurEditDataPacket(strLuaDEID) |
| | | if nRet ~= 0 then |
| | |
| | | -- 2. 解析 xml |
| | | local nRet, parsed_data = xml.parse(soap_xml) |
| | | if nRet ~= 0 then |
| | | FinalRes = Create_result("failure", "202", "xml 格式非法") |
| | | FinalRes = Create_result("failure", "202", "xml 格式非法" .. parsed_data) |
| | | local xml_result = xml.json_to_xml(FinalRes, "response") |
| | | mobox.returnValue(strLuaDEID, 0, xml_result, 0) |
| | | lua.Stop(strLuaDEID, "xml格式非法", parsed_data) |
| | |
| | | end |
| | | |
| | | -- 5. 获取系统常量 |
| | | local RetWH_COE, CONST_WH = wms_base.Get_sConst2(strLuaDEID, "GK_Default_Warehouse") |
| | | local RetFAC_COE, CONST_FACTORY = wms_base.Get_sConst2(strLuaDEID, "GK_Default_Factory") |
| | | if (RetWH_COE ~= 0 or RetFAC_COE ~= 0) then |
| | | FinalRes = Create_result("failure", "204", "获取仓库/工厂常量失败") |
| | | local RetWH_COE, CONST_WH = wms_base.Get_sConst2("GK_Default_Warehouse") |
| | | local RetFAC_COE, CONST_FACTORY = wms_base.Get_sConst2("GK_Default_Factory") |
| | | |
| | | -- 仓库常量异常捕获 |
| | | if (RetWH_COE ~= 0) then |
| | | FinalRes = Create_result("failure", "204", "获取仓库常量失败" .. CONST_WH) |
| | | local xml_result = xml.json_to_xml(FinalRes, "response") |
| | | mobox.returnValue(strLuaDEID, 0, xml_result, 0) |
| | | lua.Stop(strLuaDEID, "获取系统常量失败", xml_result) |
| | | lua.Stop(strLuaDEID, "获取系统常量:GK_Default_Warehouse 失败", xml_result) |
| | | return |
| | | end |
| | | |
| | | -- 工厂常量异常捕获 |
| | | if (RetFAC_COE ~= 0) then |
| | | FinalRes = Create_result("failure", "204", "获取工厂常量失败" .. CONST_FACTORY) |
| | | local xml_result = xml.json_to_xml(FinalRes, "response") |
| | | mobox.returnValue(strLuaDEID, 0, xml_result, 0) |
| | | lua.Stop(strLuaDEID, "获取系统常量:GK_Default_Factory失败", xml_result) |
| | | return |
| | | end |
| | | -- 6. 遍历所有收货单 |
| | | for i = 1, #receipt_headers do |
| | | local header = receipt_headers[i] |
| | |
| | | if nRet == 0 then |
| | | -- 查询成功且找到记录,说明收货单已存在 |
| | | lua.DebugEx(strLuaDEID, "查询成功,收货单已存在", retReceipt) |
| | | FinalRes = Create_result("failure", "1", "收货单已存在", |
| | | "收货单[" .. header.orderNo .. "]已存在") |
| | | FinalRes = Create_result("failure", "1", "收货单[" .. header.orderNo .. "]已存在") |
| | | local xml_result = xml.json_to_xml(FinalRes, "response") |
| | | mobox.returnValue(strLuaDEID, 0, xml_result, 0) |
| | | lua.Stop(strLuaDEID, "收货单已存在", retReceipt) |
| | |
| | | elseif nRet ~= 1 then |
| | | -- 查询出错 |
| | | lua.DebugEx(strLuaDEID, "查询出错", retReceipt) |
| | | FinalRes = Create_result("failure", "206", "检查收货单是否存在时出错", |
| | | FinalRes = Create_result("failure", "206", |
| | | "检查收货单[" .. header.orderNo .. "]时出错: " .. retReceipt) |
| | | local xml_result = xml.json_to_xml(FinalRes, "response") |
| | | mobox.returnValue(strLuaDEID, 0, xml_result, 0) |
| | |
| | | -- 再次检查是否真的存在 |
| | | local nRetCheck, retReceiptCheck = m3.GetDataObjByCondition(strLuaDEID, "Receipt_Order", strCondition) |
| | | if nRetCheck == 0 then |
| | | FinalRes = Create_result("failure", "205", "收货单已存在", |
| | | "收货单[" .. header.orderNo .. "]已存在") |
| | | FinalRes = Create_result("failure", "205", "收货单[" .. header.orderNo .. "]已存在") |
| | | else |
| | | FinalRes = Create_result("failure", "207", "创建收货单主表失败", |
| | | FinalRes = Create_result("failure", "207", |
| | | "收货单[" .. header.orderNo .. "]创建失败: " .. ret_info) |
| | | end |
| | | local xml_result = xml.json_to_xml(FinalRes, "response") |
| | |
| | | -- 检查明细数据是否存在 |
| | | if header.SmallPiece_TB_ITEM == nil then |
| | | lua.DebugEx(strLuaDEID, "警告:收货单 " .. header.orderNo .. " 无明细数据") |
| | | FinalRes = Create_result("failure", "208", "收货单无明细数据", |
| | | "收货单[" .. header.orderNo .. "]无明细数据") |
| | | FinalRes = Create_result("failure", "208", "收货单[" .. header.orderNo .. "]无明细数据") |
| | | local xml_result = xml.json_to_xml(FinalRes, "response") |
| | | mobox.returnValue(strLuaDEID, 0, xml_result, 0) |
| | | lua.Stop(strLuaDEID, "收货单无明细数据", xml_result) |
| | |
| | | if (nRet ~= 0) then |
| | | lua.DebugEx(strLuaDEID, "SKU查询出错", |
| | | "ITEM_CODE: " .. item.skuId .. ", 错误信息: " .. receiptInfo) |
| | | FinalRes = Create_result("failure", "207", "检查 SKU 是否存在时出错", |
| | | "SKU ID: " .. item.skuId .. ", 错误: " .. receiptInfo) |
| | | FinalRes = Create_result("failure", "207", |
| | | "检查 SKU 是否存在时出错:SKU ID为 " .. item.skuId .. ", 错误: " .. receiptInfo) |
| | | local xml_result = xml.json_to_xml(FinalRes, "response") |
| | | mobox.returnValue(strLuaDEID, 0, xml_result, 0) |
| | | lua.Stop(strLuaDEID, "查询失败", xml_result) |
| | | return |
| | | elseif (receiptInfo == "") then |
| | | lua.DebugEx(strLuaDEID, "查询为空", "ITEM_CODE:" .. item.skuId) |
| | | FinalRes = Create_result("failure", "208", "查询数据为空", "ITEM_CODE : " .. item.skuId) |
| | | FinalRes = Create_result("failure", "208", "查询数据为空:ITEM_CODE : " .. item.skuId) |
| | | local xml_result = xml.json_to_xml(FinalRes, "response") |
| | | mobox.returnValue(strLuaDEID, 0, xml_result, 0) |
| | | lua.Stop(strLuaDEID, "物料数据不存在", xml_result) |
| | |
| | | lua.DebugEx(strLuaDEID, "创建明细数据:", receipt_detail) |
| | | local nRet, ret_info = m3.CreateDataObj(strLuaDEID, receipt_detail) |
| | | if nRet ~= 0 then |
| | | FinalRes = Create_result("failure", "208", "创建收货明细失败", "创建失败: " .. ret_info) |
| | | FinalRes = Create_result("failure", "208", "创建收货明细失败: " .. ret_info) |
| | | local xml_result = xml.json_to_xml(FinalRes, "response") |
| | | mobox.returnValue(strLuaDEID, 0, xml_result, 0) |
| | | lua.DebugEx(strLuaDEID, "创建收货明细失败", xml_result) |
| | |
| | | |
| | | 功能说明: |
| | | 1. 接收来自上游系统的 XML 格式数据,并解析该数据, 创建SKU及SKU_UPC |
| | | |
| | | 更新: |
| | | 2025/06/09 更新了udf01~udf04的属性变更 |
| | | <soapenv:Envelope |
| | | xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"> |
| | | <soap:Header |
| | |
| | | V2.1 Yuanfeng |
| | | 1. 统一了返回结果格式,使用Create_result函数创建标准化的返回结构 |
| | | 2. 优化了代码结构 |
| | | --]] wms_base = require("wms_base") |
| | | --]] --[[ |
| | | 编码: GK-API-001 |
| | | 名称: 盘点计划同步 |
| | | 作者: HAN |
| | | 日期: 2025-1-29 |
| | | |
| | | 入口函数: SKU_Sync |
| | | 来源项目: 国科项目 |
| | | |
| | | 功能说明: |
| | | 1. 接收来自上游系统的 XML 格式数据,并解析该数据, 创建SKU及SKU_UPC |
| | | |
| | | 更改记录: |
| | | V2.0 HAN 20250402 代码规范 |
| | | V2.1 Yuanfeng 优化返回结果处理 |
| | | V2.2 优化错误处理和返回逻辑 |
| | | ]] wms_base = require("wms_base") |
| | | xml = require("oi_base_xml") |
| | | mobox = require("OILua_JavelinExt") |
| | | m3 = require("oi_base_mobox") |
| | |
| | | |
| | | local function create_sku_upc(strLuaDEID, storer, item_code, upc_code) |
| | | local nRet, strRetInfo |
| | | |
| | | if (upc_code == '' or upc_code == nil) then |
| | | return 0 |
| | | end |
| | |
| | | return nRet, strRetInfo |
| | | end |
| | | |
| | | -- 创建/更新SKU对应的货品料箱格参数 |
| | | -- 输入参数:strLuaDEID - 执行环境ID |
| | | -- skuModel - SKU数据模型(包含料格参数) |
| | | local function create_or_update_sku_gridbox(strLuaDEID, skuModel) |
| | | local nRet, strRetInfo |
| | | local err_msg = '' |
| | | |
| | | -- 获取默认容器类型定义编码 |
| | | local nConstRet, CONST_CTD_CODE = wms_base.Get_sConst2("WMS_Default_CNTR_Type") |
| | | if nConstRet ~= 0 then |
| | | return 1, "获取默认容器类型定义编码失败: " .. CONST_CTD_CODE |
| | | end |
| | | |
| | | -- 检查必填字段 |
| | | if not skuModel.item_code or not skuModel.storer then |
| | | return 1, "缺少必要参数: item_code或storer" |
| | | end |
| | | |
| | | -- 设置默认料格类型 |
| | | skuModel.ctd_code = CONST_CTD_CODE |
| | | skuModel.cell_type = skuModel.cell_type -- 料格类型 |
| | | |
| | | -- 根据商品编码(item_code)和货主(storer)以及容器类型定义编码(ctd_code)关联查询货品料箱格参数 |
| | | local strCondition = string.format("S_ITEM_CODE = '%s' AND S_STORER = '%s' AND S_CTD_CODE='%s'", skuModel.item_code, |
| | | skuModel.storer, skuModel.ctd_code) |
| | | lua.DebugEx(strLuaDEID, "查询SKU_GridBox_Parm条件", strCondition) |
| | | |
| | | local nRet, gridBoxParams = m3.GetDataObjByCondition(strLuaDEID, "SKU_GridBox_Parm", strCondition) |
| | | lua.DebugEx(strLuaDEID, "查询SKU_GridBox_Parm结果", gridBoxParams) |
| | | |
| | | if nRet == 0 then |
| | | -- 记录已存在,执行更新操作 |
| | | local update_gridbox_obj = {{ |
| | | id = gridBoxParams.id, |
| | | attrs = {{ |
| | | attr = "N_LOADING_LIMIT", |
| | | value = skuModel.loading_limit -- 更新容器装载上限 |
| | | }, { |
| | | attr = "S_CELL_TYPE", |
| | | value = skuModel.cell_type -- 更新料格类型 |
| | | }} |
| | | }} |
| | | lua.DebugEx(strLuaDEID, "准备更新SKU_GridBox_Parm属性", update_gridbox_obj) |
| | | nRet, strRetInfo = mobox.updateDataObj(strLuaDEID, "SKU_GridBox_Parm", lua.table2str(update_gridbox_obj)) |
| | | lua.DebugEx(strLuaDEID, "更新SKU_GridBox_Parm结果", nRet .. " 返回值" .. strRetInfo) |
| | | if nRet ~= 0 then |
| | | return 1, "更新SKU_GridBox_Parm属性失败: " .. strRetInfo |
| | | end |
| | | elseif nRet == 1 then |
| | | -- 记录不存在,创建新的料箱格参数 |
| | | local gridbox = m3.AllocObject(strLuaDEID, "SKU_GridBox_Parm") |
| | | gridbox.item_code = skuModel.item_code -- 商品编码 |
| | | gridbox.storer = skuModel.storer -- 货主 |
| | | gridbox.ctd_code = skuModel.ctd_code -- 容器类型定义编码 |
| | | gridbox.loading_limit = skuModel.loading_limit -- 设置容器装载上限 |
| | | gridbox.cell_type = skuModel.cell_type -- 格类型 |
| | | lua.DebugEx(strLuaDEID, "准备创建SKU_GridBox_Parm", gridbox) |
| | | nRet, strRetInfo = m3.CreateDataObj(strLuaDEID, gridbox) |
| | | if nRet ~= 0 then |
| | | return 1, "创建SKU_GridBox_Parm失败: " .. strRetInfo |
| | | end |
| | | else |
| | | -- 查询出错 |
| | | return 1, "查询SKU_GridBox_Parm时出错: " .. strRetInfo |
| | | end |
| | | return 0, strRetInfo |
| | | end |
| | | |
| | | local function create_sku(strLuaDEID, sku_input_data) |
| | | local nRet, strRetInfo |
| | | local err_msg = '' |
| | | |
| | | -- 分配SKU对象 |
| | | local sku = m3.AllocObject(strLuaDEID, "SKU") |
| | | lua.DebugEx(strLuaDEID, "SKU分配对象", sku) |
| | | sku.item_code = sku_input_data.skuId |
| | | sku.storer = sku_input_data.storerId |
| | | sku.short_name = sku_input_data.skuName |
| | | sku.item_name = sku_input_data.skuDec |
| | | sku.spec = sku_input_data.spec |
| | | sku.udf01 = sku_input_data.packageCode |
| | | sku.udf02 = sku_input_data.packageQty |
| | | sku.unit = sku_input_data.goodsUnit |
| | | sku.long = lua.Get_NumAttrValue(sku_input_data.length) |
| | | sku.middle = lua.Get_NumAttrValue(sku_input_data.width) |
| | | sku.short = lua.Get_NumAttrValue(sku_input_data.height) |
| | | sku.abc_type = sku_input_data.abcType |
| | | sku.long = lua.Get_NumAttrValue(sku_input_data.length) or 0 |
| | | sku.middle = lua.Get_NumAttrValue(sku_input_data.width) or 0 |
| | | sku.short = lua.Get_NumAttrValue(sku_input_data.height) or 0 |
| | | sku.count_method = "Limit"; |
| | | sku.abc_type = sku_input_data.abcType or "" |
| | | sku.is_life_mgt = (sku_input_data.isBatchMgr == "1" and 'Y') or 'N' |
| | | sku.is_sn_mgt = (sku_input_data.isSnMgr == "1" and 'Y') or 'N' |
| | | sku.udf03 = sku_input_data.isSnStorageMgr |
| | | sku.img_url = sku_input_data.imgUrl |
| | | sku.img_url = sku_input_data.imgUrl or "" |
| | | sku.cell_type = sku_input_data.cidtype |
| | | sku.prod_line = sku_input_data.productLine |
| | | sku.udf04 = sku_input_data.storageConditions |
| | | sku.item_type = sku_input_data.skuType |
| | | sku.loading_limit = lua.Get_NumAttrValue(sku_input_data.maxCount) |
| | | sku.loading_limit = lua.Get_NumAttrValue(sku_input_data.maxCount) or 0 |
| | | --- 2025/6/9 新增/更改字段 |
| | | sku.udf01 = sku_input_data.productLine or ""; |
| | | sku.udf03 = sku_input_data.isSnStorageMgr or "" |
| | | sku.udf02 = sku_input_data.storageConditions or "" |
| | | sku.udf04 = sku_input_data.packageCode or ""; |
| | | sku.udf05 = lua.Get_NumAttrValue(sku_input_data.packageQty) or 0; |
| | | lua.DebugEx(strLuaDEID, "SKU赋值后", sku) |
| | | |
| | | -- 检查SKU是否已存在 |
| | | local id |
| | | local strCondition = "S_ITEM_CODE = '" .. sku.item_code .. "' AND S_STORER = '" .. sku.storer .. "'" |
| | | local strCondition = string.format("S_ITEM_CODE = '%s' AND S_STORER = '%s'", sku.item_code, sku.storer) |
| | | nRet, id, strRetInfo = mobox.getDataObjAttrByKeyAttr(strLuaDEID, "SKU", strCondition) |
| | | |
| | | if nRet > 1 then |
| | |
| | | attr = "S_CELL_TYPE", |
| | | value = sku.cell_type |
| | | }, { |
| | | attr = "S_PROD_LINE", |
| | | value = sku.prod_line |
| | | }, { |
| | | attr = "N_LOADING_LIMIT", |
| | | value = sku.loading_limit |
| | | }, { |
| | |
| | | }, { |
| | | attr = "S_UDF04", |
| | | value = sku.udf04 |
| | | }, { |
| | | attr = "S_UDF05", |
| | | value = sku.udf05 |
| | | }} |
| | | }} |
| | | |
| | |
| | | |
| | | -- 处理SKU_UPC |
| | | local upc_codes = {sku_input_data.sptm, sku_input_data.barcode1, sku_input_data.barcode2, sku_input_data.barcode3, |
| | | sku_input_data.barcode_pk} |
| | | sku_input_data.barcode_pk, sku_input_data.upc} |
| | | |
| | | for _, upc_code in ipairs(upc_codes) do |
| | | if upc_code and upc_code ~= '' then |
| | |
| | | end |
| | | end |
| | | |
| | | -- 处理SKU_GridBox_Parm |
| | | nRet, strRetInfo = create_or_update_sku_gridbox(strLuaDEID, sku) |
| | | if nRet ~= 0 then |
| | | return 1, "处理SKU_GridBox_Parm失败: " .. strRetInfo |
| | | end |
| | | |
| | | return 0 |
| | | end |
| | | |
| | | -- Main函数 |
| | | function SKU_Sync(strLuaDEID) |
| | | -- 初始化最终结果 |
| | | local FinalRes = Create_result() |
| | | |
| | | -- 1. 获取xml数据包 |
| | | local nRet, soap_xml = mobox.getCurEditDataPacket(strLuaDEID) |
| | | if nRet ~= 0 then |
| | | FinalRes = Create_result("failure", "201", "无法获取数据包: " .. soap_xml) |
| | | local xml_result = xml.json_to_xml(FinalRes, "response") |
| | | mobox.returnValue(strLuaDEID, 0, xml_result, 0) |
| | | lua.Stop(strLuaDEID, "获取数据包失败", FinalRes) |
| | | return |
| | | end |
| | | |
| | | lua.DebugEx(strLuaDEID, "获取到的数据包", soap_xml) |
| | | |
| | | -- 2. 解析xml |
| | | local nRet, parsed_data = xml.parse(soap_xml) |
| | | if nRet ~= 0 then |
| | | FinalRes = Create_result("failure", "202", "xml格式非法") |
| | | local xml_result = xml.json_to_xml(FinalRes, "response") |
| | | mobox.returnValue(strLuaDEID, 0, xml_result, 0) |
| | | lua.Stop(strLuaDEID, "xml格式非法", FinalRes) |
| | | return |
| | | end |
| | |
| | | local sku_data = parsed_data.Envelope.Body.inCommodityReq.COMMODITY_Input.InputParameters.COMMODITY_TB |
| | | if not sku_data or not sku_data.COMMODITY_TB_ITEM then |
| | | FinalRes = Create_result("failure", "203", "xml数据格式错误,缺少COMMODITY_TB_ITEM") |
| | | local xml_result = xml.json_to_xml(FinalRes, "response") |
| | | mobox.returnValue(strLuaDEID, 0, xml_result, 0) |
| | | lua.Stop(strLuaDEID, "xml数据格式错误", FinalRes) |
| | | return |
| | | end |
| | |
| | | end |
| | | |
| | | -- 5. 遍历所有SKU数据 |
| | | local FinalRes = Create_result() |
| | | for i = 1, #sku_items do |
| | | local sku_item = sku_items[i] |
| | | |
| | |
| | | |
| | | -- 设置错误结果并停止处理 |
| | | FinalRes = Create_result("failure", "204", "SKU同步失败", err_msg) |
| | | local xml_result = xml.json_to_xml(FinalRes, "response") |
| | | mobox.returnValue(strLuaDEID, 0, xml_result, 0) |
| | | lua.Stop(strLuaDEID, "SKU同步失败: " .. sku_item.skuId, FinalRes) |
| | | return |
| | | end |
| | | end |
| | | |
| | | -- 6. 返回成功 |
| | | FinalRes = Create_result("success", "0", "SKU同步成功") |
| | | local xml_result = xml.json_to_xml(FinalRes, "response") |
| | | mobox.returnValue(strLuaDEID, 0, xml_result, 0) |
| | | end |