From a2861d59d2245b349ded89a6afe8249dd96c52e1 Mon Sep 17 00:00:00 2001 From: fy36 <1046342473@qq.com> Date: 星期一, 09 六月 2025 20:58:05 +0800 Subject: [PATCH] 1. 国科盘点信息同步功能代码校验 2. 小件收货信息同步 3. 完善SKU同步Grid料箱 --- lua_code/Lua/Count_Pan_Sync.lua | 207 +++++++++++++++++------------ lua_code/Lua/SKU_Sync.lua | 148 ++++++++++++++++++-- lua_code/Lua/Receipt_Sync.lua | 51 ++++-- 3 files changed, 281 insertions(+), 125 deletions(-) diff --git a/lua_code/Lua/Count_Pan_Sync.lua b/lua_code/Lua/Count_Pan_Sync.lua index 2e8ef42..2ed8118 100644 --- a/lua_code/Lua/Count_Pan_Sync.lua +++ b/lua_code/Lua/Count_Pan_Sync.lua @@ -4,7 +4,7 @@ 浣滆�: 琚佸嘲 鍏ュ彛鍑芥暟锛欳ount_Pan_Sync 鍔熻兘璇存槑: 璇ユ帴鍙f槸鍚屾鎺ュ彛锛�- 涓婃父绯荤粺 璋冪敤璇ユ帴鍙e悗锛學ES 鐨勫搷搴旀姤鏂�success 璇存槑 WES 宸茬粡灏嗚鎶ユ枃鎺ユ敹鎴愬姛; + 涓婃父绯荤粺璋冪敤璇ユ帴鍙e悗锛學ES鐨勫搷搴旀姤鏂噑uccess璇存槑WES宸茬粡灏嗚鎶ユ枃鎺ユ敹鎴愬姛; 闇�鍚屾鐩樼偣浠诲姟琛ㄥ拰鐩樼偣浠诲姟鏄庣粏琛▁ml缁撴瀯銆� 鍙樻洿鍘嗗彶: @@ -74,156 +74,191 @@ </soapenv:Envelope> 鍝嶅簲绀轰緥锛�-<flag>sucess</flag> -<code>0</code> -<message>鎴愬姛</message> -]] --[[ - 鍔熻兘锛氱洏鐐硅鍒掑悓姝ユ帴鍙o紙鏀寔澶氫富琛�澶氭槑缁嗭級 - 浣滆�锛氳宄�- 鍏ュ彛鍑芥暟锛欳ount_Pan_Sync - 璇存槑锛氳В鏋�xml锛屾敮鎸佸涓�InventoryTasks_TB锛堜富琛級锛屾瘡涓富琛ㄤ笅鍙寘鍚涓槑缁嗭紙InventoryTasks_TB_ITEM锛�+<response> + <flag>success</flag> + <code>0</code> + <message>鎴愬姛</message> +</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. 瑙f瀽 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 瑙f瀽鍚庯紝濡傛灉鍙湁涓�釜 InventoryTasks_TB锛屽彲鑳借繑鍥�table锛涘涓垯鍙兘鏄暟缁�+ -- 4. 缁熶竴澶勭悊锛氱‘淇�mainTables 鏄暟缁勶紙鍗充娇鍙湁涓�釜涓昏〃锛� local mainTables = input_params.InventoryTasks_TB - if not mainTables then - FinalRes = Create_result("failure", "204", "xml 鏁版嵁鏍煎紡閿欒锛孖nventoryTasks_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 + -- 濡傛灉鏄痭Ret=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) + -- 鍐嶆妫�煡鏄惁鐪熺殑瀛樺湪 + 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 + 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 not mainData.InventoryTasks_TB_ITEM then - lua.DebugEx(strLuaDEID, "璀﹀憡锛氫换鍔�" .. mainData.taskId .. " 鏃犳槑缁嗘暟鎹�) + if mainData.InventoryTasks_TB_ITEM == nil then + lua.DebugEx(strLuaDEID, "璀﹀憡锛氱洏鐐逛换鍔�" .. mainData.taskId .. " 鏃犳槑缁嗘暟鎹�) + -- 鏃犳槑缁嗘暟鎹笉瑙嗕负閿欒锛岀户缁鐞嗕笅涓�釜浠诲姟 else - -- 7. 閬嶅巻褰撳墠涓昏〃鐨勬墍鏈夋槑缁嗘暟鎹�+ -- 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 diff --git a/lua_code/Lua/Receipt_Sync.lua b/lua_code/Lua/Receipt_Sync.lua index 8abe6e7..8305e15 100644 --- a/lua_code/Lua/Receipt_Sync.lua +++ b/lua_code/Lua/Receipt_Sync.lua @@ -80,10 +80,16 @@ 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 @@ -99,7 +105,7 @@ -- 2. 瑙f瀽 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) @@ -126,16 +132,26 @@ 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, "鑾峰彇绯荤粺甯搁噺锛欸K_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, "鑾峰彇绯荤粺甯搁噺锛欸K_Default_Factory澶辫触", xml_result) + return + end -- 6. 閬嶅巻鎵�湁鏀惰揣鍗� for i = 1, #receipt_headers do local header = receipt_headers[i] @@ -147,8 +163,7 @@ 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) @@ -156,7 +171,7 @@ 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) @@ -181,10 +196,9 @@ -- 鍐嶆妫�煡鏄惁鐪熺殑瀛樺湪 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") @@ -196,8 +210,7 @@ -- 妫�煡鏄庣粏鏁版嵁鏄惁瀛樺湪 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) @@ -220,15 +233,15 @@ 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", "鏌ヨ鏁版嵁涓虹┖锛欼TEM_CODE : " .. item.skuId) local xml_result = xml.json_to_xml(FinalRes, "response") mobox.returnValue(strLuaDEID, 0, xml_result, 0) lua.Stop(strLuaDEID, "鐗╂枡鏁版嵁涓嶅瓨鍦�, xml_result) @@ -261,7 +274,7 @@ 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) diff --git a/lua_code/Lua/SKU_Sync.lua b/lua_code/Lua/SKU_Sync.lua index 6382c96..1ef0c6c 100644 --- a/lua_code/Lua/SKU_Sync.lua +++ b/lua_code/Lua/SKU_Sync.lua @@ -9,7 +9,8 @@ 鍔熻兘璇存槑: 1. 鎺ユ敹鏉ヨ嚜涓婃父绯荤粺鐨�XML 鏍煎紡鏁版嵁锛屽苟瑙f瀽璇ユ暟鎹� 鍒涘缓SKU鍙奡KU_UPC - + 鏇存柊锛�+ 2025/06/09 鏇存柊浜唘df01~udf04鐨勫睘鎬у彉鏇� <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"> <soap:Header @@ -70,7 +71,23 @@ V2.1 Yuanfeng 1. 缁熶竴浜嗚繑鍥炵粨鏋滄牸寮忥紝浣跨敤Create_result鍑芥暟鍒涘缓鏍囧噯鍖栫殑杩斿洖缁撴瀯 2. 浼樺寲浜嗕唬鐮佺粨鏋�---]] wms_base = require("wms_base") +--]] --[[ + 缂栫爜: GK-API-001 + 鍚嶇О: 鐩樼偣璁″垝鍚屾 + 浣滆�: HAN + 鏃ユ湡: 2025-1-29 + + 鍏ュ彛鍑芥暟锛�SKU_Sync + 鏉ユ簮椤圭洰: 鍥界椤圭洰 + + 鍔熻兘璇存槑: + 1. 鎺ユ敹鏉ヨ嚜涓婃父绯荤粺鐨�XML 鏍煎紡鏁版嵁锛屽苟瑙f瀽璇ユ暟鎹� 鍒涘缓SKU鍙奡KU_UPC + + 鏇存敼璁板綍: + V2.0 HAN 20250402 浠g爜瑙勮寖 + V2.1 Yuanfeng 浼樺寲杩斿洖缁撴灉澶勭悊 + V2.2 浼樺寲閿欒澶勭悊鍜岃繑鍥為�杈�+ ]] wms_base = require("wms_base") xml = require("oi_base_xml") mobox = require("OILua_JavelinExt") m3 = require("oi_base_mobox") @@ -87,7 +104,6 @@ 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 @@ -102,37 +118,109 @@ return nRet, strRetInfo end +-- 鍒涘缓/鏇存柊SKU瀵瑰簲鐨勮揣鍝佹枡绠辨牸鍙傛暟 +-- 杈撳叆鍙傛暟锛歴trLuaDEID - 鎵ц鐜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鎴杝torer" + 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 @@ -180,9 +268,6 @@ attr = "S_CELL_TYPE", value = sku.cell_type }, { - attr = "S_PROD_LINE", - value = sku.prod_line - }, { attr = "N_LOADING_LIMIT", value = sku.loading_limit }, { @@ -206,6 +291,9 @@ }, { attr = "S_UDF04", value = sku.udf04 + }, { + attr = "S_UDF05", + value = sku.udf05 }} }} @@ -217,7 +305,7 @@ -- 澶勭悊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 @@ -228,22 +316,38 @@ 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. 瑙f瀽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 @@ -252,6 +356,8 @@ 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鏁版嵁鏍煎紡閿欒锛岀己灏慍OMMODITY_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 @@ -263,7 +369,6 @@ end -- 5. 閬嶅巻鎵�湁SKU鏁版嵁 - local FinalRes = Create_result() for i = 1, #sku_items do local sku_item = sku_items[i] @@ -275,12 +380,15 @@ -- 璁剧疆閿欒缁撴灉骞跺仠姝㈠鐞� 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 -- Gitblit v1.9.1