From 2dff6a55fee4ad77ea59eeb8562229632da03377 Mon Sep 17 00:00:00 2001 From: fy36 <1046342473@qq.com> Date: 星期四, 22 五月 2025 14:08:16 +0800 Subject: [PATCH] 1. SKU数据同步代码更新返回格式,修复返回非xml报文格式问题 2. 盘点数据同步代码优化 3. 小件收货品信息同步代码优化 --- lua_code/Lua/Count_Pan_Sync.lua | 231 ++++++++++++++++ lua_code/Lua/SKU_Sync.lua | 286 ++++++++++++++++++++ lua_code/Lua/Receipt_Sync.lua | 267 +++++++++++++++++++ 3 files changed, 784 insertions(+), 0 deletions(-) diff --git a/lua_code/Lua/Count_Pan_Sync.lua b/lua_code/Lua/Count_Pan_Sync.lua new file mode 100644 index 0000000..d1f0dad --- /dev/null +++ b/lua_code/Lua/Count_Pan_Sync.lua @@ -0,0 +1,231 @@ +--[[ + 缂栫爜: GK-API-09 + 鍚嶇О: 鐩樼偣璁″垝鍚屾鎺ュ彛 + 浣滆�: 琚佸嘲 + 鍏ュ彛鍑芥暟锛欳ount_Pan_Sync + 鍔熻兘璇存槑: 璇ユ帴鍙f槸鍚屾鎺ュ彛锛�+ 涓婃父绯荤粺 璋冪敤璇ユ帴鍙e悗锛學ES 鐨勫搷搴旀姤鏂�success 璇存槑 WES 宸茬粡灏嗚鎶ユ枃鎺ユ敹鎴愬姛; + 闇�鍚屾鐩樼偣浠诲姟琛ㄥ拰鐩樼偣浠诲姟鏄庣粏琛▁ml缁撴瀯銆�+ 鍙樻洿鍘嗗彶: + +<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> +]] --[[ + 鍔熻兘锛氱洏鐐硅鍒掑悓姝ユ帴鍙o紙鏀寔澶氫富琛�澶氭槑缁嗭級 + 浣滆�锛氳宄�+ 鍏ュ彛鍑芥暟锛欳ount_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", "201", "鏃犳硶鑾峰彇鏁版嵁鍖� " .. soap_xml) + lua.Stop(strLuaDEID, "鑾峰彇鏁版嵁鍖呭け璐�, FinalRes) + return + end + + -- 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) + return + end + + -- 3. 鎻愬彇涓昏〃鏁版嵁锛堝彲鑳藉涓�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 + + -- 4. 鍒ゆ柇 InventoryTasks_TB 鏄崟涓璞¤繕鏄暟缁�+ -- xml 瑙f瀽鍚庯紝濡傛灉鍙湁涓�釜 InventoryTasks_TB锛屽彲鑳借繑鍥�table锛涘涓垯鍙兘鏄暟缁�+ 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 + -- 6. 閬嶅巻鎵�湁涓昏〃鏁版嵁 + 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", "201", "鑾峰彇浠撳簱甯搁噺澶辫触", 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", "206", "鏄庣粏琛ㄦ暟鎹垱寤哄け璐� ", ret_info) + lua.DebugEx(strLuaDEID, "鏄庣粏琛ㄦ暟鎹垱寤哄け璐� ", ret_info) + lua.Stop(strLuaDEID, "鍒涘缓鏄庣粏琛ㄦ暟鎹け璐� .. count_plan.cp_no, ret_info) + else + lua.DebugEx(strLuaDEID, "鏄庣粏鏁版嵁鍒涘缓鎴愬姛锛�, count_plan_item) + end + end + end + end + + -- 8. 杩斿洖鎴愬姛 + 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 new file mode 100644 index 0000000..08c5da6 --- /dev/null +++ b/lua_code/Lua/Receipt_Sync.lua @@ -0,0 +1,267 @@ +--[[ + 缂栫爜: GK-API-04 + 鍚嶇О: GK-WMS-Receipt_Sync + 浣滆�: 琚佸嘲 + 鍏ュ彛鍑芥暟锛歊eceipt_Sync + 鍔熻兘璇存槑: 鎺ユ敹涓婃父绯荤粺鐨刋ML鏁版嵁锛屽垱寤烘敹璐у崟涓昏〃锛圧eceipt_Order锛夊拰鏄庣粏璁板綍锛圧eceipt_Detail锛夈� + 杈撳叆鍙傛暟: xmlData锛圶ML鏍煎紡鐨勫瓧绗︿覆锛�+ 杩斿洖鍙傛暟: xml 鏍煎紡鐨勫搷搴旀姤鏂囷細 + 褰㈠锛�+ <response> + <message>鏀惰揣鍗曞凡瀛樺湪</message> + <code>204</code> + <flag>failure</flag> + <error>鏀惰揣鍗昜SO2025050701]宸插瓨鍦�/error> + </response> + + 璋冪敤绀轰緥: Receipt_Sync(xmlData) + 娉ㄦ剰浜嬮」: 1. 杈撳叆鍙傛暟xmlData涓篨ML鏍煎紡鐨勫瓧绗︿覆锛屽寘鍚簡鏀惰揣鍗曚富琛ㄥ拰鏄庣粏璁板綍鐨勬暟鎹� + 2. 鍑芥暟浼氳В鏋怷ML鏁版嵁锛屽苟灏嗗叾鎻掑叆鍒版暟鎹簱涓� + 3. 鍏佽xml 浼犲叆1鏉℃垨鑰呭鏉℃敹璐у崟涓昏〃鏁版嵁锛屾瘡鏉℃敹璐у崟涓昏〃鏁版嵁鍙互鍖呭惈澶氭潯鏀惰揣鍗曟槑缁嗘暟鎹� + + 鍙樻洿鍘嗗彶: 2025-05-14 浼樺寲杩斿洖缁撴灉澶勭悊 + + XML 鎶ユ枃绀轰緥濡備笅锛�+ <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"> + <soap:Header xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> + </soap:Header> + <soapenv:Body> + <v1:InSmallPieceReq xmlns:v1="http://www.gkht.com/InReceive/INV/Ebs/Schemas/InSmallPiece/V1.0"> + <v1:SmallPiece_Input> + <v1:RESTHeader> + <v1:Responsibility/> + <v1:RespApplication/> + <v1:SecurityGroup/> + <v1:NLSLanguage>SIMPLIFIED CHINESE</v1:NLSLanguage> + <v1:Org_Id>0</v1:Org_Id> + </v1:RESTHeader> + <v1:InputParameters> + <!-- 绗竴涓敹璐у崟 --> + <v1:SmallPiece_TB> + <v1:orderNo>SO2025050701</v1:orderNo> + <v1:asnNo>KPD00002</v1:asnNo> + <v1:storerId>CGKHTY</v1:storerId> + <v1:ownerId>CGKHTY</v1:ownerId> + <v1:orderDate>2025-05-07</v1:orderDate> + <v1:priority>0</v1:priority> + <v1:memo>鏀惰揣鍗�澶囨敞</v1:memo> + <v1:SmallPiece_TB_ITEM> + <v1:orderItemId>1</v1:orderItemId> + <v1:skuId>100118100</v1:skuId> + <v1:skuStatus>AVL</v1:skuStatus> + <v1:qty>3</v1:qty> + <v1:batchNo>PHI00000000000001310</v1:batchNo> + <v1:produceCode>YL201126</v1:produceCode> + <v1:productDate>2016-05-23</v1:productDate> + <v1:expiryDate>2099-12-31</v1:expiryDate> + <v1:registerNo>鍥介鑽洃姊帮紙鍑�瀛�013</v1:registerNo> + </v1:SmallPiece_TB_ITEM> + <v1:SmallPiece_TB_ITEM> + <v1:orderItemId>2</v1:orderItemId> + <v1:skuId>100117231</v1:skuId> + <v1:skuStatus>AVL</v1:skuStatus> + <v1:qty>4</v1:qty> + <v1:batchNo>PHI00000000000001311</v1:batchNo> + <v1:produceCode>YL201127</v1:produceCode> + <v1:productDate>2023-05-23</v1:productDate> + <v1:expiryDate>2099-12-31</v1:expiryDate> + <v1:registerNo></v1:registerNo> + </v1:SmallPiece_TB_ITEM> + </v1:SmallPiece_TB> + <!-- 绗簩涓敹璐у崟 --> + <v1:SmallPiece_TB> + <v1:orderNo>SO2025050702</v1:orderNo> + <v1:asnNo>KPD00003</v1:asnNo> + <v1:storerId>CGKHTY</v1:storerId> + <v1:ownerId>CGKHTY</v1:ownerId> + <v1:orderDate>2025-05-07</v1:orderDate> + <v1:priority>1</v1:priority> + <v1:memo>鏀惰揣鍗�澶囨敞</v1:memo> + <v1:SmallPiece_TB_ITEM> + <v1:orderItemId>1</v1:orderItemId> + <v1:skuId>200000002</v1:skuId> + <v1:skuStatus>AVL</v1:skuStatus> + <v1:qty>2</v1:qty> + <v1:batchNo>PHI00000000000001312</v1:batchNo> + <v1:produceCode>YL201128</v1:produceCode> + <v1:productDate>2016-06-23</v1:productDate> + <v1:expiryDate>2099-12-31</v1:expiryDate> + <v1:registerNo>鍥介鑽洃姊帮紙鍑�瀛�014</v1:registerNo> + </v1:SmallPiece_TB_ITEM> + <v1:SmallPiece_TB_ITEM> + <v1:orderItemId>2</v1:orderItemId> + <v1:skuId>100117238</v1:skuId> + <v1:skuStatus>AVL</v1:skuStatus> + <v1:qty>5</v1:qty> + <v1:batchNo>PHI00000000000001313</v1:batchNo> + <v1:produceCode>YL201129</v1:produceCode> + <v1:productDate>2023-06-23</v1:productDate> + <v1:expiryDate>2099-12-31</v1:expiryDate> + <v1:registerNo></v1:registerNo> + </v1:SmallPiece_TB_ITEM> + </v1:SmallPiece_TB> + </v1:InputParameters> + </v1:SmallPiece_Input> + </v1:InSmallPieceReq> + </soapenv:Body> +</soapenv:Envelope> + +--]] + +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 Receipt_Sync(strLuaDEID) + -- 1. 鑾峰彇 xml 鏁版嵁鍖�+ local nRet, soap_xml = mobox.getCurEditDataPacket(strLuaDEID) + if nRet ~= 0 then + FinalRes = Create_result("failure", "201", "鏃犳硶鑾峰彇鏁版嵁鍖� " .. soap_xml) + lua.Stop(strLuaDEID, "鑾峰彇鏁版嵁鍖呭け璐�, FinalRes) + + end + + -- 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) + + end + + -- 3. 鎻愬彇涓昏〃鏁版嵁 + local receipt_data = parsed_data.Envelope.Body.InSmallPieceReq.SmallPiece_Input + local input_params = receipt_data.InputParameters + + -- 妫�煡鏄惁瀛樺湪 SmallPiece_TB + if not input_params or not input_params.SmallPiece_TB then + FinalRes = Create_result("failure", "203", "xml 鏁版嵁鏍煎紡閿欒锛岀己灏�SmallPiece_TB") + lua.Stop(strLuaDEID, "xml 鏁版嵁鏍煎紡閿欒", FinalRes) + return + end + + -- 4. 缁熶竴澶勭悊锛氱‘淇�receipt_headers 鏄暟缁勶紙鍗充娇鍙湁涓�釜涓昏〃锛�+ local receipt_headers = input_params.SmallPiece_TB + if receipt_headers[1] == nil then + receipt_headers = {receipt_headers} + 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", "鑾峰彇浠撳簱/宸ュ巶甯搁噺澶辫触") + lua.Stop(strLuaDEID, "鑾峰彇绯荤粺甯搁噺澶辫触", FinalRes) + return + end + + -- 6. 閬嶅巻鎵�湁鏀惰揣鍗�+ local result = Create_result() + for i = 1, #receipt_headers do + local header = receipt_headers[i] + + -- 妫�煡鏀惰揣鍗曟槸鍚﹀凡瀛樺湪 + local strCondition = string.format("S_NO = '%s'", header.orderNo) + lua.DebugEx(strLuaDEID, "SQL 鏉′欢", strCondition) + local nRet, strRetInfo = mobox.getDataObjAttrByKeyAttr(strLuaDEID, "Receipt_Order", strCondition) + if nRet == 0 then + FinalRes = Create_result("failure", "205", "鏀惰揣鍗曞凡瀛樺湪", + "鏀惰揣鍗昜" .. header.orderNo .. "]宸插瓨鍦�) + lua.Stop(strLuaDEID, "鏀惰揣鍗曞凡瀛樺湪", FinalRes) + + elseif nRet > 1 then + FinalRes = Create_result("failure", "206", "绯荤粺閿欒", + "妫�煡鏀惰揣鍗曟槸鍚﹀瓨鍦ㄦ椂鍑洪敊: " .. strRetInfo) + lua.Stop(strLuaDEID, "妫�煡鏀惰揣鍗曟槸鍚﹀瓨鍦ㄦ椂鍑洪敊", FinalRes) + + end + + -- 鍒涘缓涓昏〃鏁版嵁 + local receipt = m3.AllocObject(strLuaDEID, "Receipt_Order") + receipt.no = header.orderNo + receipt.asn_no = header.asnNo + receipt.op_date = header.orderDate + receipt.priority = header.priority + receipt.note = header.memo or "" + receipt.bs_type = "SMALL_PIECE" + receipt.factory = CONST_FACTORY + receipt.wh_code = CONST_WH + lua.DebugEx(strLuaDEID, "鍒涘缓鐨勮〃鍗曪細", receipt); + local nRet, ret_info = m3.CreateDataObj(strLuaDEID, receipt) + if nRet ~= 0 then + FinalRes = Create_result("failure", "207", "鍒涘缓鏀惰揣鍗曚富琛ㄥけ璐�, + "鏀惰揣鍗昜" .. header.orderNo .. "]鍒涘缓澶辫触: " .. ret_info) + lua.Stop(strLuaDEID, "鍒涘缓鏀惰揣鍗曚富琛ㄥけ璐�, FinalRes) + + end + + -- 妫�煡鏄庣粏鏁版嵁鏄惁瀛樺湪 + if not header.SmallPiece_TB_ITEM then + lua.DebugEx(strLuaDEID, "璀﹀憡锛氭敹璐у崟 " .. header.orderNo .. " 鏃犳槑缁嗘暟鎹�) + else + -- 7. 閬嶅巻褰撳墠鏀惰揣鍗曠殑鎵�湁鏄庣粏鏁版嵁 + local details = header.SmallPiece_TB_ITEM + -- 纭繚 details 鏄暟缁勶紙鍗充娇鍙湁涓�釜鏄庣粏锛�+ if details[1] == nil then + details = {details} + end + + for j = 1, #details do + local item = details[j] + -- 鍒涘缓鏄庣粏鏁版嵁 + local receipt_detail = m3.AllocObject(strLuaDEID, "Receipt_Detail") + receipt_detail.row_no = item.orderItemId + receipt_detail.receipt_no = header.orderNo + receipt_detail.qty = lua.Get_NumAttrValue(item.qty) or 0 + receipt_detail.acc_put_qty = lua.Get_NumAttrValue("0") + receipt_detail.acc_unq_qty = lua.Get_NumAttrValue("0") + receipt_detail.acc_c_qty = lua.Get_NumAttrValue("0") + receipt_detail.item_code = item.skuId + receipt_detail.item_state = item.skuStatus + receipt_detail.wu = "kg" + receipt_detail.batch_no = item.produceCode + receipt_detail.prd_date = item.productDate + receipt_detail.exp_date = item.expiryDate + receipt_detail.udf01 = item.registerNo + receipt_detail.storer = header.storerId + receipt_detail.owner = header.ownerId + + -- 鑾峰彇鐗╂枡淇℃伅 + if item.skuId ~= nil then + local nRet, mat_info = m3.GetDataObjByCondition(strLuaDEID, "Material", + "S_ITEM_CODE='" .. item.skuId .. "'") + if nRet == 0 then + receipt_detail.item_name = mat_info.item_name or "" + receipt_detail.net_weight = mat_info.weight or 0 + receipt_detail.gross_weight = mat_info.weight or 0 + receipt_detail.uom = mat_info.uom or "" + end + end + + local nRet, ret_info = m3.CreateDataObj(strLuaDEID, receipt_detail) + if nRet ~= 0 then + FinalRes = Create_result("failure", "208", "鍒涘缓鏀惰揣鏄庣粏澶辫触", + "琛屽彿[" .. item.orderItemId .. "]鍒涘缓澶辫触: " .. ret_info) + lua.Stop(strLuaDEID, "鍒涘缓鏀惰揣鏄庣粏澶辫触", FinalRes) + + 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/SKU_Sync.lua b/lua_code/Lua/SKU_Sync.lua new file mode 100644 index 0000000..6382c96 --- /dev/null +++ b/lua_code/Lua/SKU_Sync.lua @@ -0,0 +1,286 @@ +--[[ + 缂栫爜: GK-API-001 + 鍚嶇О: 鐩樼偣璁″垝鍚屾 + 浣滆�: HAN + 鏃ユ湡: 2025-1-29 + + 鍏ュ彛鍑芥暟锛�SKU_Sync + 鏉ユ簮椤圭洰: 鍥界椤圭洰 + + 鍔熻兘璇存槑: + 1. 鎺ユ敹鏉ヨ嚜涓婃父绯荤粺鐨�XML 鏍煎紡鏁版嵁锛屽苟瑙f瀽璇ユ暟鎹� 鍒涘缓SKU鍙奡KU_UPC + + <soapenv:Envelope + xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"> + <soap:Header + xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> + </soap:Header> + <soapenv:Body> + <v1:inCommodityReq + xmlns:v1="http://www.gkht.com/Information/INV/Ebs/Schemas/InCommodity/V1.0"> + <v1:COMMODITY_Input> + <v1:RESTHeader> + <v1:Responsibility/> + <v1:RespApplication/> + <v1:SecurityGroup/> + <v1:NLSLanguage>SIMPLIFIED CHINESE</v1:NLSLanguage> + <v1:Org_Id>0</v1:Org_Id> + </v1:RESTHeader> + <v1:InputParameters> + <v1:COMMODITY_TB> + <!--1 or more repetitions:--> + <v1:COMMODITY_TB_ITEM> + <v1:skuId>KH32803017</v1:skuId> + <v1:storerId>CGKHTY</v1:storerId> + <v1:skuName>铻烘棆鍒�墖寮忛珦鍐呴拤</v1:skuName> + <v1:skuDec>铻烘棆鍒�墖寮忚偂楠ㄨ繎绔珦鍐呴拤10脳170</v1:skuDec> + <v1:spec>JGD鈪�蠁10脳170</v1:spec> + <v1:packageCode>涓�/v1:packageCode> + <v1:packageQty>1</v1:packageQty> + <v1:goodsUnit>浠�/v1:goodsUnit> + <v1:length>1</v1:length> + <v1:width>2</v1:width> + <v1:height>3</v1:height> + <v1:abcType></v1:abcType> + <v1:isBatchMgr>1</v1:isBatchMgr> + <v1:isSnMgr>1</v1:isSnMgr> + <v1:isSnStorageMgr>0</v1:isSnStorageMgr> + <v1:imgUrl></v1:imgUrl> + <v1:cidtype>A</v1:cidtype> + <v1:productLine>KH-鍒涗激</v1:productLine> + <v1:storageConditions>甯告俯</v1:storageConditions> + <v1:skuType>small</v1:skuType> + <v1:maxCount>50</v1:maxCount> + <v1:sptm></v1:sptm> + <v1:barcode1></v1:barcode1> + <v1:barcode2></v1:barcode2> + <v1:barcode3></v1:barcode3> + <v1:barcode_pk></v1:barcode_pk> + </v1:COMMODITY_TB_ITEM> + </v1:COMMODITY_TB> + </v1:InputParameters> + </v1:COMMODITY_Input> + </v1:inCommodityReq> + </soapenv:Body> + </soapenv:Envelope> + + 鏇存敼璁板綍: + V2.0 HAN 20250402 浠g爜瑙勮寖 + + V2.1 Yuanfeng + 1. 缁熶竴浜嗚繑鍥炵粨鏋滄牸寮忥紝浣跨敤Create_result鍑芥暟鍒涘缓鏍囧噯鍖栫殑杩斿洖缁撴瀯 + 2. 浼樺寲浜嗕唬鐮佺粨鏋�+--]] 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 + +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 + + -- 鍒涘缓SKU_UPC + local sku_upc = m3.AllocObject(strLuaDEID, "SKU_UPC") + sku_upc.storer = storer + sku_upc.item_code = item_code + sku_upc.upc_code = upc_code + nRet, strRetInfo = m3.CreateDataObj(strLuaDEID, sku_upc) + + return nRet, strRetInfo +end + +local function create_sku(strLuaDEID, sku_input_data) + local nRet, strRetInfo + local err_msg = '' + + -- 鍒嗛厤SKU瀵硅薄 + local sku = m3.AllocObject(strLuaDEID, "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.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.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鏄惁宸插瓨鍦�+ local id + local strCondition = "S_ITEM_CODE = '" .. sku.item_code .. "' AND S_STORER = '" .. sku.storer .. "'" + nRet, id, strRetInfo = mobox.getDataObjAttrByKeyAttr(strLuaDEID, "SKU", strCondition) + + if nRet > 1 then + return 1, "妫�煡SKU鏄惁瀛樺湪鏃跺け璐� " .. strRetInfo + end + + if nRet == 1 then + -- SKU涓嶅瓨鍦紝鍒涘缓鏂癝KU + nRet, strRetInfo = m3.CreateDataObj(strLuaDEID, sku) + if nRet ~= 0 then + return 1, "鍒涘缓SKU澶辫触: " .. strRetInfo .. " skuId = " .. sku_input_data.skuId + end + else + -- SKU宸插瓨鍦紝鏇存柊灞炴� + local update_sku_obj = {{ + id = id, + attrs = {{ + attr = "S_ITEM_NAME", + value = sku.item_name + }, { + attr = "S_SPEC", + value = sku.spec + }, { + attr = "S_ITEM_TYPE", + value = sku.item_type + }, { + attr = "S_UNIT", + value = sku.unit + }, { + attr = "S_SHORT_NAME", + value = sku.short_name + }, { + attr = "S_ABCTYPE", + value = sku.abc_type + }, { + attr = "C_ISSNMGT", + value = sku.is_sn_mgt + }, { + attr = "C_ISLIFEMGT", + value = sku.is_life_mgt + }, { + attr = "S_IMG_URL", + value = sku.img_url + }, { + 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 = "F_LONG", + value = sku.long + }, { + attr = "F_MIDDLE", + value = sku.middle + }, { + attr = "F_SHORT", + value = sku.short + }, { + attr = "S_UDF01", + value = sku.udf01 + }, { + attr = "S_UDF02", + value = sku.udf02 + }, { + attr = "S_UDF03", + value = sku.udf03 + }, { + attr = "S_UDF04", + value = sku.udf04 + }} + }} + + nRet, strRetInfo = mobox.updateDataObj(strLuaDEID, "SKU", lua.table2str(update_sku_obj)) + if nRet ~= 0 then + return 1, "鏇存柊SKU灞炴�澶辫触: " .. strRetInfo + end + end + + -- 澶勭悊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} + + for _, upc_code in ipairs(upc_codes) do + if upc_code and upc_code ~= '' then + nRet, strRetInfo = create_sku_upc(strLuaDEID, sku.storer, sku.item_code, upc_code) + if nRet ~= 0 then + return 1, "鍒涘缓SKU_UPC澶辫触: " .. strRetInfo .. " UPC: " .. upc_code + end + end + end + + return 0 +end + +function SKU_Sync(strLuaDEID) + -- 1. 鑾峰彇xml鏁版嵁鍖�+ local nRet, soap_xml = mobox.getCurEditDataPacket(strLuaDEID) + if nRet ~= 0 then + FinalRes = Create_result("failure", "201", "鏃犳硶鑾峰彇鏁版嵁鍖� " .. soap_xml) + lua.Stop(strLuaDEID, "鑾峰彇鏁版嵁鍖呭け璐�, FinalRes) + return + end + + -- 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) + return + end + + -- 3. 鎻愬彇SKU鏁版嵁 + 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") + lua.Stop(strLuaDEID, "xml鏁版嵁鏍煎紡閿欒", FinalRes) + return + end + + -- 4. 缁熶竴澶勭悊锛氱‘淇漵ku_items鏄暟缁勶紙鍗充娇鍙湁涓�釜SKU锛�+ local sku_items = sku_data.COMMODITY_TB_ITEM + if sku_items[1] == nil then + sku_items = {sku_items} + end + + -- 5. 閬嶅巻鎵�湁SKU鏁版嵁 + local FinalRes = Create_result() + for i = 1, #sku_items do + local sku_item = sku_items[i] + + -- 鍒涘缓SKU鍙婂叾UPC + local nRet, err_msg = create_sku(strLuaDEID, sku_item) + if nRet ~= 0 then + -- 璁板綍璀﹀憡鏃ュ織 + wms_base.Warning(strLuaDEID, 1, 601, err_msg, "浠嶨K-WMS绯荤粺鍚屾SKU淇℃伅") + + -- 璁剧疆閿欒缁撴灉骞跺仠姝㈠鐞�+ FinalRes = Create_result("failure", "204", "SKU鍚屾澶辫触", err_msg) + lua.Stop(strLuaDEID, "SKU鍚屾澶辫触: " .. sku_item.skuId, FinalRes) + return + end + end + + -- 6. 杩斿洖鎴愬姛 + local xml_result = xml.json_to_xml(FinalRes, "response") + mobox.returnValue(strLuaDEID, 0, xml_result, 0) +end -- Gitblit v1.9.1