From 19898bd66dec87b500b200d5d50961d0fb538ce5 Mon Sep 17 00:00:00 2001 From: wsz <w1832984788@outlook.com> Date: 星期五, 20 六月 2025 15:54:16 +0800 Subject: [PATCH] WMS-01-22 WMS-01-23 --- lua_code/Lua/Receipt_Sync.lua | 312 ++++++++++++++++++++++++++++------------------------ 1 files changed, 168 insertions(+), 144 deletions(-) diff --git a/lua_code/Lua/Receipt_Sync.lua b/lua_code/Lua/Receipt_Sync.lua index 08c5da6..8305e15 100644 --- a/lua_code/Lua/Receipt_Sync.lua +++ b/lua_code/Lua/Receipt_Sync.lua @@ -22,11 +22,14 @@ 鍙樻洿鍘嗗彶: 2025-05-14 浼樺寲杩斿洖缁撴灉澶勭悊 XML 鎶ユ枃绀轰緥濡備笅锛�- <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"> - <soap:Header xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> +<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:InSmallPieceReq + xmlns:v1="http://www.gkht.com/InReceive/INV/Ebs/Schemas/InSmallPiece/V1.0"> <v1:SmallPiece_Input> <v1:RESTHeader> <v1:Responsibility/> @@ -36,68 +39,36 @@ <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> + <!--1 or more repetitions:--> + <v1:SmallPiece_TB> + <v1:orderNo>SO2025050601</v1:orderNo> + <v1:asnNo>KPD00001</v1:asnNo> + <v1:storerId>CGKHTY</v1:storerId> + <v1:ownerId>CGKHTY</v1:ownerId> + <v1:orderDate>2025-05-06</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:skuId>XR33201-2L080B</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:batchNo>PHI00000000000001309</v1:batchNo> + <v1:produceCode>YL201125</v1:produceCode> + <v1:productDate>2016-04-23</v1:productDate> + <v1:expiryDate>2099-12-31</v1:expiryDate> + <v1:registerNo>鍥介鑽洃姊帮紙鍑�瀛�012</v1:registerNo> </v1:SmallPiece_TB_ITEM> - <v1:SmallPiece_TB_ITEM> + <v1:SmallPiece_TB_ITEM> <v1:orderItemId>2</v1:orderItemId> - <v1:skuId>100117238</v1:skuId> + <v1:skuId>KH32803017</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:batchNo>PHI00000000000001308</v1:batchNo> + <v1:produceCode>YL2011256</v1:produceCode> + <v1:productDate>2023-04-23</v1:productDate> + <v1:expiryDate>2099-12-31</v1:expiryDate> + <v1:registerNo></v1:registerNo> </v1:SmallPiece_TB_ITEM> </v1:SmallPiece_TB> </v1:InputParameters> @@ -105,39 +76,40 @@ </v1:InSmallPieceReq> </soapenv:Body> </soapenv:Envelope> - ---]] - -wms_base = require("wms_base") +--]] 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) +function Create_result(flag, code, msg) return { flag = flag or "success", code = code or "0", - message = msg or "", - error = error or "" + 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 FinalRes = Create_result("failure", "201", "鏃犳硶鑾峰彇鏁版嵁鍖� " .. soap_xml) - lua.Stop(strLuaDEID, "鑾峰彇鏁版嵁鍖呭け璐�, FinalRes) - + 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) - + 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) + return end -- 3. 鎻愬彇涓昏〃鏁版嵁 @@ -147,7 +119,9 @@ -- 妫�煡鏄惁瀛樺湪 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) + local xml_result = xml.json_to_xml(FinalRes, "response") + mobox.returnValue(strLuaDEID, 0, xml_result, 0) + lua.Stop(strLuaDEID, "xml 鏁版嵁鏍煎紡閿欒", xml_result) return end @@ -158,33 +132,51 @@ 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 + 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, "鑾峰彇绯荤粺甯搁噺锛欸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. 閬嶅巻鎵�湁鏀惰揣鍗�- 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) + lua.DebugEx(strLuaDEID, "鏌ヨ鏀惰揣鍗曟潯浠�, strCondition) + local nRet, retReceipt = m3.GetDataObjByCondition(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) - + -- 鏌ヨ鎴愬姛涓旀壘鍒拌褰曪紝璇存槑鏀惰揣鍗曞凡瀛樺湪 + lua.DebugEx(strLuaDEID, "鏌ヨ鎴愬姛锛屾敹璐у崟宸插瓨鍦�, retReceipt) + 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) + return + elseif nRet ~= 1 then + -- 鏌ヨ鍑洪敊 + lua.DebugEx(strLuaDEID, "鏌ヨ鍑洪敊", retReceipt) + FinalRes = Create_result("failure", "206", + "妫�煡鏀惰揣鍗昜" .. header.orderNo .. "]鏃跺嚭閿� " .. retReceipt) + local xml_result = xml.json_to_xml(FinalRes, "response") + mobox.returnValue(strLuaDEID, 0, xml_result, 0) + lua.Stop(strLuaDEID, "妫�煡鏀惰揣鍗曟槸鍚﹀瓨鍦ㄦ椂鍑洪敊", xml_result) + return end -- 鍒涘缓涓昏〃鏁版嵁 @@ -197,71 +189,103 @@ 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) - + -- 鍐嶆妫�煡鏄惁鐪熺殑瀛樺湪 + local nRetCheck, retReceiptCheck = m3.GetDataObjByCondition(strLuaDEID, "Receipt_Order", strCondition) + if nRetCheck == 0 then + FinalRes = Create_result("failure", "205", "鏀惰揣鍗昜" .. header.orderNo .. "]宸插瓨鍦�) + else + FinalRes = Create_result("failure", "207", + "鏀惰揣鍗昜" .. header.orderNo .. "]鍒涘缓澶辫触: " .. 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 header.SmallPiece_TB_ITEM then + if header.SmallPiece_TB_ITEM == nil then lua.DebugEx(strLuaDEID, "璀﹀憡锛氭敹璐у崟 " .. header.orderNo .. " 鏃犳槑缁嗘暟鎹�) - else - -- 7. 閬嶅巻褰撳墠鏀惰揣鍗曠殑鎵�湁鏄庣粏鏁版嵁 - local details = header.SmallPiece_TB_ITEM - -- 纭繚 details 鏄暟缁勶紙鍗充娇鍙湁涓�釜鏄庣粏锛�- if details[1] == nil then - details = {details} + 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) + return + end + + -- 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] + -- 鍏堟楠宻kuId鏄惁瀛樺湪 + local strCondition = string.format("S_ITEM_CODE= '%s' AND S_STORER = '%s'", item.skuId, header.storerId) + -- 鎵ц鏌ヨ + local nRet, receiptInfo = m3.GetDataObjByCondition(strLuaDEID, "SKU", strCondition) + if (nRet ~= 0) then + lua.DebugEx(strLuaDEID, "SKU鏌ヨ鍑洪敊", + "ITEM_CODE: " .. 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", "鏌ヨ鏁版嵁涓虹┖锛欼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) + return 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 + -- 鍒涘缓鏄庣粏鏁版嵁 + 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.item_name = receiptInfo.item_name or "" + 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 + receipt_detail.item_name = receiptInfo.item_name or "" + receipt_detail.net_weight = receiptInfo.weight or 0 + receipt_detail.gross_weight = receiptInfo.weight or 0 + receipt_detail.uom = receiptInfo.uom or "" - -- 鑾峰彇鐗╂枡淇℃伅 - 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 + 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) + 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 -- 8. 杩斿洖鎴愬姛 - -- FinalRes = Create_result("success", "0", "鏀惰揣鍗曞垱寤烘垚鍔�) + FinalRes = Create_result("success", "0", "鏀惰揣鍗曞垱寤烘垚鍔�) local xml_result = xml.json_to_xml(FinalRes, "response") mobox.returnValue(strLuaDEID, 0, xml_result, 0) end -- Gitblit v1.9.1