From f01dbecb66e96d528d1ec70feebe3e87611a936a Mon Sep 17 00:00:00 2001
From: Jianw <Jianw@DJW>
Date: 星期三, 14 五月 2025 15:01:28 +0800
Subject: [PATCH] 增加出库单同步接口

---
 lua_code/test.lua                               |    6 
 lua_code/test051301.lua                         |    9 -
 lua_code/Lua/GK-API-06 GK-WMS-Outbound_Sync.lua |  243 ++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 250 insertions(+), 8 deletions(-)

diff --git a/lua_code/Lua/GK-API-06 GK-WMS-Outbound_Sync.lua b/lua_code/Lua/GK-API-06 GK-WMS-Outbound_Sync.lua
new file mode 100644
index 0000000..a29bc27
--- /dev/null
+++ b/lua_code/Lua/GK-API-06 GK-WMS-Outbound_Sync.lua
@@ -0,0 +1,243 @@
+--[[ 
+    缂栫爜: GK-API-06
+    鍚嶇О: 鍑哄簱鍗曞垱寤烘帴鍙�+    浣滆�: DJW
+    鏃ユ湡: 2025-5-14
+
+    鍏ュ彛鍑芥暟锛�Main
+    鍔熻兘璇存槑:
+        1. 鎺ユ敹涓婃父绯荤粺鐨勫叆搴撲换鍔ML鏁版嵁
+        2. 妫�煡鍏ュ簱鍗曟槸鍚﹀凡瀛樺湪
+        3. 鍒涘缓Outbound_Order涓昏〃鍜孫utbound_Detail瀛愯〃璁板綍
+        4. 杩斿洖澶勭悊缁撴灉
+
+    杈撳叆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:InTaskCreationReq
+            xmlns:v1="http://www.gkht.com/OutReceive/INV/Ebs/Schemas/OutTaskCreation/V1.0">
+			<v1:TaskCreation_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:TaskCreation_TB>
+						<!--						1 or more repetitions:-->
+						<v1:taskId>TASK20000001</v1:taskId>
+						<v1:taskType>normal</v1:taskType>
+						<v1:orderFlag>
+						</v1:orderFlag>
+						<v1:orderNo>2025050602</v1:orderNo>
+						<v1:waveId>BCH1001</v1:waveId>
+						<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:TaskCreation_TB_ITEM>
+							<v1:orderItemId>1</v1:orderItemId>
+							<v1:skuId>XR33201-2L080B</v1:skuId>
+							<v1:skuStatus>AVL</v1:skuStatus>
+							<v1:qty>2</v1:qty>
+							<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:cid>
+							</v1:cid>
+						</v1:TaskCreation_TB_ITEM>
+						<v1:TaskCreation_TB_ITEM>
+							<v1:orderItemId>2</v1:orderItemId>
+							<v1:skuId>KH32803017</v1:skuId>
+							<v1:skuStatus>AVL</v1:skuStatus>
+							<v1:qty>5</v1:qty>
+							<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:cid>
+							</v1:cid>
+						</v1:TaskCreation_TB_ITEM>
+					</v1:TaskCreation_TB>
+				</v1:InputParameters>
+			</v1:TaskCreation_Input>
+		</v1:InTaskCreationReq>
+	</soapenv:Body>
+</soapenv:Envelope>
+--]] 
+wms_base = require("wms_base")
+xml = require("oi_base_xml")
+-- 鍒涘缓鍏ュ簱鍗曚富琛ㄨ褰�+local function create_outbound_order(strLuaDEID, order_data)
+    local order = m3.AllocObject(strLuaDEID, "Outbound_Order")
+
+    -- 涓昏〃瀛楁鏄犲皠
+    order.no = order_data.taskId
+    order.bs_type = order_data.taskType
+    order.bs_no = order_data.orderNo
+    order.wave_no = order_data.waveId
+    --order.D_OP_DATE = order_data.orderDate
+    --order.N_PRIORITY = order_data.priority
+    order.note = order_data.memo or ""
+    order.wh_code = "WH01"
+    order.area_code=""
+    order.factory=""
+
+    local nRet, result = m3.CreateDataObj(strLuaDEID, order)
+    return nRet, result
+end
+
+-- 鍒涘缓鍑哄簱鍗曟槑缁嗚褰�+local function create_outbound_detail(strLuaDEID, order_no, item_data)
+    local detail = m3.AllocObject(strLuaDEID, "Outbound_Detail")
+
+    -- 鏄庣粏琛ㄥ瓧娈垫槧灏�+    detail.oo_no = order_no
+    detail.storer = item_data.storerId
+    detail.owner = item_data.ownerId
+    detail.row_no = item_data.orderItemId
+    detail.item_code = item_data.skuId
+    detail.item_state = item_data.skuStatus
+    detail.qty = lua.Get_NumAttrValue(item_data.qty)
+    detail.batch_no = item_data.produceCode
+    detail.wms_bn = item_data.batchNo
+    --detail.D_PRD_DATE = item_data.productDate
+    --detail.D_EXP_DATE = item_data.expiryDate
+    detail.ext_attr3 = item_data.registerNo or ""
+    detail.ext_attr1 = item_data.cid or ""
+
+    local nRet, result = m3.CreateDataObj(strLuaDEID, detail)
+    return nRet, result
+end
+
+-- isJson浼�琛ㄧずjson鏍煎紡锛�琛ㄧずxml鏍煎紡
+-- value鏄痶able鏁版嵁
+-- isStop浼�琛ㄧず姝e父锛�琛ㄧず瑕佸洖婊�+function ApiReturn(strLuaDEID, isJson, value, isStop)
+    local strReturn = value
+    --Debug( strLuaDEID, debug.getinfo(1), "ApiReturn澶辫触!", value )
+    mobox.writeLuaLog( lua.table2str( value ) )
+    if isJson == 0 then
+        strReturn = xml2lua.toXml(value)
+        mobox.writeLuaLog(strReturn)
+    end
+    mobox.returnValue(strLuaDEID, isJson, value, isStop);
+    return
+end
+function Main(strLuaDEID)
+    local nRet, strRetInfo,err_msg
+    local soap_xml,parsed_data,task_data,input_params,task_tb,order_no
+    local strCondition,id,task_items
+    local isStop = 0
+    local err = {}
+    local items = {}
+
+
+
+    -- m3.PrintLuaDEInfo(strLuaDEID)
+    local result = {
+        flag = "success",
+        code = "0",
+        msg = ""
+    }
+    -- 1. 鑾峰彇鎺ュ彛杈撳叆鏁版嵁
+    
+    nRet, soap_xml = mobox.getCurEditDataPacket(strLuaDEID)
+    if nRet ~= 0 then
+        -- lua.Stop(strLuaDEID, "鏃犳硶鑾峰彇鏁版嵁鍖� " .. soap_xml)
+        result.flag = "failure"
+        result.code = "1"
+        result.msg = "鏃犳硶鑾峰彇鏁版嵁鍖� "
+        goto api_call_return
+
+        -- return
+    end
+
+    -- 2. 瑙f瀽XML
+   
+    nRet, parsed_data = xml.parse(soap_xml)
+    if nRet ~= 0 then
+        -- lua.Stop(strLuaDEID, "鎺ュ彛杈撳叆鐨刋ML鏍煎紡闈炴硶!")
+        result.flag = "failure"
+        result.code = "2"
+        result.msg = "鎺ュ彛杈撳叆鐨刋ML鏍煎紡闈炴硶: "
+        goto api_call_return
+        -- return
+    end
+
+    -- 3. 鎻愬彇浠诲姟鏁版嵁
+    task_data = parsed_data.Envelope.Body.InTaskCreationReq.TaskCreation_Input
+    input_params = task_data.InputParameters
+    task_tb = input_params.TaskCreation_TB
+
+    -- 4. 妫�煡鍑哄簱鍗曟槸鍚﹀凡瀛樺湪
+    order_no = task_tb.taskId
+    strCondition = string.format("S_NO = '%s'", order_no)
+    nRet, id, strRetInfo = mobox.getDataObjAttrByKeyAttr(strLuaDEID, "Outbound_Order", strCondition)
+    if nRet > 1 then
+        result.flag = "failure"
+        result.code = "3"
+        result.msg = "妫�煡鍑哄簱鍗曟槸鍚﹀瓨鍦ㄦ椂鍑洪敊: " .. strRetInfo
+        goto api_call_return
+    elseif nRet == 0 then
+        result.flag = "failure"
+        result.code = "4"
+        result.msg = "鍑哄簱鍗曞凡瀛樺湪: "
+        goto api_call_return
+    end
+    -- 5. 鍒涘缓鍑哄簱鍗曚富琛�+    nRet, strRetInfo = create_outbound_order(strLuaDEID, task_tb)
+    if nRet ~= 0 then
+        -- lua.Stop(strLuaDEID, "鍒涘缓鍑哄簱鍗曚富琛ㄥけ璐�" .. strRetInfo)
+        result.flag = "failure"
+        result.code = "5"
+        result.msg = "鍒涘缓鍑哄簱鍗曚富琛ㄥけ璐�" .. strRetInfo
+        isStop=3
+        goto api_call_return
+        -- return
+    end
+
+    -- 6. 澶勭悊鏄庣粏鏁版嵁
+    task_items = task_tb.TaskCreation_TB_ITEM
+    
+    -- 鎯呭喌2锛氬鏉℃槑缁嗭紙鏁扮粍褰㈠紡锛�+    if task_items[1] ~= nil then
+        items = task_items
+        -- 鎯呭喌3锛氬崟鏉℃槑缁嗭紙闈炴暟缁勫舰寮忥級
+    else
+        items = {task_items}
+    end
+
+    for i, item in ipairs(items) do
+        nRet, strRetInfo = create_outbound_detail(strLuaDEID, order_no, item)
+        if nRet ~= 0 then
+            err_msg = string.format("鍒涘缓鍑哄簱鍗曟槑缁嗗け璐�琛屽彿:%d): %s", item.orderItemId, strRetInfo)
+            -- wms_base.Warning(strLuaDEID, 1, 604, err_msg, "鍒涘缓鍑哄簱鍗曟槑缁�)
+            -- nErr = nErr + 1
+            -- err[nErr] = err_msg
+            -- lua.Stop(strLuaDEID, err_msg)
+            result.flag = "failure"
+            result.code = "5"
+            result.msg = err_msg
+            isStop=3
+            goto api_call_return
+        end
+    end
+    ::api_call_return::
+    -- 7. 杩斿洖澶勭悊缁撴灉
+
+    -- m3.EPI_Return(strLuaDEID, result)
+    ApiReturn(strLuaDEID, 0, result, isStop)
+end
diff --git a/lua_code/test.lua b/lua_code/test.lua
index 36a747c..69d8152 100644
--- a/lua_code/test.lua
+++ b/lua_code/test.lua
@@ -12,16 +12,16 @@
                 ";./Lua/300-WMS-API/?.lua"
   
 -- 闇�璋冭瘯鐨勮剼鏈�-require("GK-API-01 SKU_Sync")
+require("Inbound_Sync")
 
-local strLuaDEID = "{8CC8704F-70BE-41E0-8B31-4E44CE98EC75}"
+local strLuaDEID = "{92651F21-7477-4AFB-B597-C7C22E92D54B}"
 local nRet
 
 -- 鍚姩浜嬪姟
 mobox.startTransaction( strLuaDEID )
 
 -- 璋冭瘯鑴氭湰鐨勫叆鍙e嚱鏁�-nRet = SKU_Sync( strLuaDEID )
+nRet = Inbound_Sync( strLuaDEID )
 
 if ( nRet == 0 ) then
   mobox.commit(strLuaDEID)
diff --git a/lua_code/test051301.lua b/lua_code/test051301.lua
index fcdfd0b..dc514d0 100644
--- a/lua_code/test051301.lua
+++ b/lua_code/test051301.lua
@@ -109,17 +109,16 @@
 mobox = require("OILua_JavelinExt")
 local wms_base = require("wms_base")
 -- 闇�璋冭瘯鐨勮剼鏈�---require("WMS-28-10 Count_Order-AddByCountPlan")
-require("WMS-00-10 Factory-BaseDataExport")
-local strLuaDEID = "{55521D04-144A-4423-96DF-0C8516FA4DBE}"
+require("Inbound_Sync")
+
+local strLuaDEID = "{8755C06B-CC0D-44FE-A62C-96954F3B716B}"
 local nRet
 
 -- 鍚姩浜嬪姟
 mobox.startTransaction( strLuaDEID )
 
 -- 璋冭瘯鑴氭湰鐨勫叆鍙e嚱鏁�---nRet = AfterClickOK ( strLuaDEID )
-nRet = WMS_BaseData_Export ( strLuaDEID )
+nRet = Inbound_Sync( strLuaDEID )
 
 if ( nRet == 0 ) then
   mobox.commit(strLuaDEID)

--
Gitblit v1.9.1