From a3f50e5bd0d5ecbd0c5992da042fe4292dbb6911 Mon Sep 17 00:00:00 2001
From: fy36 <1046342473@qq.com>
Date: 星期二, 24 六月 2025 10:48:00 +0800
Subject: [PATCH] SKU_Sync.lua 模型字段调整到明细中

---
 lua_code/Lua/SKU_Sync.lua |  418 ++++++++++++++++++++++++++++++++++++-----------------------
 1 files changed, 253 insertions(+), 165 deletions(-)

diff --git a/lua_code/Lua/SKU_Sync.lua b/lua_code/Lua/SKU_Sync.lua
index 1ef0c6c..c1375f1 100644
--- a/lua_code/Lua/SKU_Sync.lua
+++ b/lua_code/Lua/SKU_Sync.lua
@@ -11,104 +11,169 @@
         1. 鎺ユ敹鏉ヨ嚜涓婃父绯荤粺鐨�XML 鏍煎紡鏁版嵁锛屽苟瑙f瀽璇ユ暟鎹� 鍒涘缓SKU鍙奡KU_UPC
     鏇存柊锛�         2025/06/09 鏇存柊浜唘df01~udf04鐨勫睘鎬у彉鏇�-        <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. 浼樺寲浜嗕唬鐮佺粨鏋�---]] --[[ 
-    缂栫爜: 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")
+       V2.3 绉婚櫎error瀛楁锛屽悎骞跺埌message涓�+       V2.4 鏂板SKU_GRID_PARM瀛楁
+
+<?xml version="1.0" encoding="UTF-8"?>
+<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>XR4121-3204A</v1:skuId>
+                            <v1:storerId>CGKHTY</v1:storerId>
+                            <v1:skuName>閲戝睘瑙e墫鍨嬫帴楠ㄦ澘</v1:skuName>
+                            <v1:skuDec>閲戝睘瑙e墫鍨嬫帴楠ㄦ澘YSQ20 4瀛�/v1:skuDec>
+                            <v1:spec>瑙勬牸娴嬭瘯</v1:spec>
+                            <v1:packageCode>鍧�/v1:packageCode>
+                            <v1:packageQty>1</v1:packageQty>
+                            <v1:goodsUnit>鍧�/v1:goodsUnit>
+                            <v1:length>3.5</v1:length>
+                            <v1:width>3.5</v1:width>
+                            <v1:height>3.5</v1:height>
+                            <v1:abcType/>
+                            <v1:isBatchMgr>0</v1:isBatchMgr>
+                            <v1:isSnMgr>0</v1:isSnMgr>
+                            <v1:isSnStorageMgr>0</v1:isSnStorageMgr>
+                            <v1:imgUrl/>
+                            <v1:cidtype>11111A</v1:cidtype>
+                            <v1:productLine>XR-鍒涗激</v1:productLine>
+                            <v1:storageConditions>鎭掓俯</v1:storageConditions>
+                            <v1:skuType>small</v1:skuType>
+                            <v1:maxCount/>
+                            <v1:bMaxCount>10</v1:bMaxCount>
+                            <v1:cMaxCount>11</v1:cMaxCount>
+                             <v1:dMaxCount>12</v1:dMaxCount>
+                            <v1:eMaxCount/>
+                            <v1:fMaxCount/>
+                            <v1:upc>1</v1:upc>
+                        </v1:COMMODITY_TB_ITEM>
+                    </v1:COMMODITY_TB>
+                </v1:InputParameters>
+            </v1:COMMODITY_Input>
+        </v1:inCommodityReq>
+    </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)
+-- 鍒涘缓缁熶竴杩斿洖缁撴灉锛堜慨鏀瑰悗鐗堟湰锛岀Щ闄rror瀛楁锛�+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
+-- 鏂板sku_grid_parm JSON瀛楃涓诧紝鍦⊿KU 鍒涘缓鐨勬椂鍊欐彃鍏son鏁版嵁
+local function build_sku_grid_parm(ctd_code, sku_input_data)
+    -- 瀹氫箟鍩虹json妗嗘灦缁撴瀯锛堟斁鍦ㄦ暟缁勪腑锛�+    local grid_def = {{
+        ctd_code = ctd_code,
+        cell_def = {}
+    }}
 
+    -- 瀹氫箟鏂欑绫诲瀷涓庡搴斿瓧娈电殑鏄犲皠
+    local grid_mapping = {{
+        cell_type = "A",
+        loading_limit = sku_input_data.maxCount
+    }, {
+        cell_type = "B",
+        loading_limit = sku_input_data.bMaxCount
+    }, {
+        cell_type = "C",
+        loading_limit = sku_input_data.cMaxCount
+    }, {
+        cell_type = "D",
+        loading_limit = sku_input_data.dMaxCount
+    }, {
+        cell_type = "E",
+        loading_limit = sku_input_data.eMaxCount
+    }, {
+        cell_type = "F",
+        loading_limit = sku_input_data.fMaxCount
+    }}
+
+    -- 鏋勫缓cell_def鏁扮粍
+    for _, grid in ipairs(grid_mapping) do
+        local limit = lua.Get_NumAttrValue(grid.loading_limit) or 0
+        table.insert(grid_def[1].cell_def, { -- 娉ㄦ剰杩欓噷鏀逛负grid_def[1]
+            cell_type = grid.cell_type,
+            loading_limit = limit,
+            load_capacity = limit -- 杩欓噷鍋囪load_capacity鍜宭oading_limit鐩稿悓
+        })
+    end
+
+    -- 杞崲涓篔SON瀛楃涓�+    return lua.table2str(grid_def)
+end
+-- 鍒涘缓鎴栨洿鏂癎K_PROLINE鏁版嵁(鐢熶骇绾挎暟鎹�
+local function create_or_update_proline(strLuaDEID, proline_no, proline_name)
+    local nRet, strRetInfo
+
+    -- 鍒嗛厤GK_PROLINE瀵硅薄
+    local proline = m3.AllocObject(strLuaDEID, "GK_PROLINE")
+    proline.proline_no = proline_no
+    proline.proline_name = proline_name
+
+    -- 妫�煡鏄惁宸插瓨鍦�+    local strCondition = string.format("S_PROLINE_NO = '%s'", proline_no)
+    local nRet, id, strRetInfo = mobox.getDataObjAttrByKeyAttr(strLuaDEID, "GK_PROLINE", strCondition)
+
+    if nRet > 1 then
+        return 1, "妫�煡GK_PROLINE鏄惁瀛樺湪鏃跺け璐� " .. strRetInfo
+    end
+
+    if nRet == 1 then
+        -- 涓嶅瓨鍦紝鍒涘缓鏂拌褰�+        nRet, strRetInfo = m3.CreateDataObj(strLuaDEID, proline)
+        if nRet ~= 0 then
+            return 1, "鍒涘缓GK_PROLINE澶辫触: " .. strRetInfo
+        end
+    else
+        -- 宸插瓨鍦紝鏇存柊璁板綍
+        local update_proline_obj = {{
+            id = id,
+            attrs = {{
+                attr = "S_PROLINE_NAME",
+                value = proline_name
+            }}
+        }}
+
+        nRet, strRetInfo = mobox.updateDataObj(strLuaDEID, "GK_PROLINE", lua.table2str(update_proline_obj))
+        if nRet ~= 0 then
+            return 1, "鏇存柊GK_PROLINE澶辫触: " .. strRetInfo
+        end
+    end
+    return 0, strRetInfo
+end
+
+-- 鍒涘缓SKU_UPC
 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
@@ -119,80 +184,105 @@
 end
 
 -- 鍒涘缓/鏇存柊SKU瀵瑰簲鐨勮揣鍝佹枡绠辨牸鍙傛暟
--- 杈撳叆鍙傛暟锛歴trLuaDEID - 鎵ц鐜ID
---          skuModel - SKU鏁版嵁妯″瀷锛堝寘鍚枡鏍煎弬鏁帮級
-local function create_or_update_sku_gridbox(strLuaDEID, skuModel)
+local function create_or_update_sku_gridbox(strLuaDEID, skuModel, sku_input_data)
     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
+    -- 瀹氫箟鏂欑鏍肩被鍨嬩笌瀵瑰簲瀛楁鐨勬槧灏勫叧绯�+    local gridbox_types = {{
+        cell_type = "A",
+        loading_limit = sku_input_data.maxCount
+    }, {
+        cell_type = "B",
+        loading_limit = sku_input_data.bMaxCount
+    }, {
+        cell_type = "C",
+        loading_limit = sku_input_data.cMaxCount
+    }, {
+        cell_type = "D",
+        loading_limit = sku_input_data.dMaxCount
+    }, {
+        cell_type = "E",
+        loading_limit = sku_input_data.eMaxCount
+    }, {
+        cell_type = "F",
+        loading_limit = sku_input_data.fMaxCount
+    }}
 
-    -- 璁剧疆榛樿鏂欐牸绫诲瀷
-    skuModel.ctd_code = CONST_CTD_CODE
-    skuModel.cell_type = skuModel.cell_type -- 鏂欐牸绫诲瀷
+    -- 澶勭悊姣忕鏂欑鏍肩被鍨�+    for _, gridbox_type in ipairs(gridbox_types) do
+        -- 璁剧疆瑁呰浇涓婇檺锛屽鏋滄病鏈夊垯璁句负0
+        local loading_limit = 0
+        if gridbox_type.loading_limit and gridbox_type.loading_limit ~= "" then
+            loading_limit = lua.Get_NumAttrValue(gridbox_type.loading_limit) or 0
+        end
 
-    -- 鏍规嵁鍟嗗搧缂栫爜(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 -- 鏇存柊鏂欐牸绫诲瀷
+        -- 绮剧‘鏌ヨ璇ョ被鍨嬬殑鏂欑鏍艰褰�+        local strCondition = string.format(
+            "S_ITEM_CODE = '%s' AND S_STORER = '%s' AND S_CTD_CODE='%s' AND S_CELL_TYPE='%s'", skuModel.item_code,
+            skuModel.storer, CONST_CTD_CODE, gridbox_type.cell_type)
+        local nRet, existing_records = m3.GetDataObjByCondition(strLuaDEID, "SKU_GridBox_Parm", strCondition)
+        if nRet == 0 then
+            -- 鏇存柊鐜版湁璁板綍
+            local update_gridbox_obj = {{
+                id = existing_records.id,
+                attrs = {{
+                    attr = "N_LOADING_LIMIT",
+                    value = loading_limit
+                }}
             }}
-        }}
-        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
+
+            nRet, strRetInfo = mobox.updateDataObj(strLuaDEID, "SKU_GridBox_Parm", lua.table2str(update_gridbox_obj))
+            if nRet ~= 0 then
+                return 1, string.format("鏇存柊%s绫诲瀷鏂欑鏍煎睘鎬уけ璐� %s", gridbox_type.cell_type, strRetInfo)
+            end
+        else
+            -- 鍒涘缓鏂拌褰�+            local gridbox = m3.AllocObject(strLuaDEID, "SKU_GridBox_Parm")
+            gridbox.item_code = skuModel.item_code
+            gridbox.storer = skuModel.storer
+            gridbox.ctd_code = CONST_CTD_CODE
+            gridbox.loading_limit = loading_limit
+            gridbox.cell_type = gridbox_type.cell_type
+
+            nRet, strRetInfo = m3.CreateDataObj(strLuaDEID, gridbox)
+            if nRet ~= 0 then
+                return 1, string.format("鍒涘缓%s绫诲瀷鏂欑鏍煎け璐� %s", gridbox_type.cell_type, strRetInfo)
+            end
         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
+
+    return 0, "鏂欑鏍煎弬鏁板鐞嗗畬鎴�
 end
 
+-- 鍒涘缓鎴栨洿鏂癝KU涓绘暟鎹� local function create_sku(strLuaDEID, sku_input_data)
     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
+    -- 鏂板SKU_grid_param
+    local sku_grid_parm = build_sku_grid_parm(CONST_CTD_CODE, sku_input_data)
 
-    -- 鍒嗛厤SKU瀵硅薄
+    -- 棣栧厛妫�煡SKU鏄惁宸插瓨鍦�+    local strCondition = string.format("S_ITEM_CODE = '%s' AND S_STORER = '%s'", sku_input_data.skuId,
+        sku_input_data.storerId)
+    local nRet, existing_sku = m3.GetDataObjByCondition(strLuaDEID, "SKU", strCondition)
+    lua.DebugEx(strLuaDEID, "鑾峰彇鏉′欢鏌ヨ锛�, existing_sku)
+    if nRet > 1 then
+        return 1, "妫�煡SKU鏄惁瀛樺湪鏃跺け璐� " .. (existing_sku or "鏈煡閿欒")
+    end
+
+    -- 鍒嗛厤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
@@ -202,41 +292,33 @@
     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.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.img_url = sku_input_data.imgUrl or ""
+    lua.DebugEx(strLuaDEID, "cell_type", sku_input_data.cidtype)
     sku.cell_type = sku_input_data.cidtype
     sku.item_type = sku_input_data.skuType
     sku.loading_limit = lua.Get_NumAttrValue(sku_input_data.maxCount) or 0
-    --- 2025/6/9 鏂板/鏇存敼瀛楁
-    sku.udf01 = sku_input_data.productLine or "";
+    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 = 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
-        return 1, "妫�煡SKU鏄惁瀛樺湪鏃跺け璐� " .. strRetInfo
-    end
-
+    sku.udf04 = sku_input_data.packageCode or ""
+    sku.udf05 = lua.Get_NumAttrValue(sku_input_data.packageQty) or 0
+    sku.sku_grid_parm = sku_grid_parm;
+    lua.DebugEx(strLuaDEID, "鏇存柊/鍒涘缓鏁版嵁", sku)
+    lua.DebugEx(strLuaDEID, "鏇存柊/鍒涘缓鏁版嵁", sku.cell_type)
     if nRet == 1 then
-        -- SKU涓嶅瓨鍦紝鍒涘缓鏂癝KU
+        -- SKU涓嶅瓨鍦紝鍒涘缓鏂拌褰�         nRet, strRetInfo = m3.CreateDataObj(strLuaDEID, sku)
         if nRet ~= 0 then
             return 1, "鍒涘缓SKU澶辫触: " .. strRetInfo .. " skuId = " .. sku_input_data.skuId
         end
     else
-        -- SKU宸插瓨鍦紝鏇存柊灞炴�
+        -- SKU宸插瓨鍦紝鏇存柊璁板綍
         local update_sku_obj = {{
-            id = id,
+            id = existing_sku.id,
             attrs = {{
                 attr = "S_ITEM_NAME",
                 value = sku.item_name
@@ -294,16 +376,29 @@
             }, {
                 attr = "S_UDF05",
                 value = sku.udf05
+            }, {
+                attr = "S_SKU_GRID_PARM",
+                value = sku.sku_grid_parm
             }}
         }}
-
         nRet, strRetInfo = mobox.updateDataObj(strLuaDEID, "SKU", lua.table2str(update_sku_obj))
+        lua.DebugEx(strLuaDEID, "鏇存柊杩斿洖鍊�, nRet)
         if nRet ~= 0 then
             return 1, "鏇存柊SKU灞炴�澶辫触: " .. strRetInfo
         end
     end
 
-    -- 澶勭悊SKU_UPC
+    -- 澶勭悊浜у搧绾挎暟鎹�+    if sku_input_data.productLine and sku_input_data.productLine ~= "" then
+        local proline_no = sku_input_data.productLine
+        local proline_name = string.match(proline_no, "KH%-(.+)") or proline_no
+        nRet, strRetInfo = create_or_update_proline(strLuaDEID, proline_no, proline_name)
+        if nRet ~= 0 then
+            return 1, "澶勭悊浜у搧绾挎暟鎹け璐� " .. 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, sku_input_data.upc}
 
@@ -316,8 +411,8 @@
         end
     end
 
-    -- 澶勭悊SKU_GridBox_Parm
-    nRet, strRetInfo = create_or_update_sku_gridbox(strLuaDEID, sku)
+    -- 澶勭悊SKU_GridBox_Parm鏂欑鏍煎弬鏁�+    nRet, strRetInfo = create_or_update_sku_gridbox(strLuaDEID, sku, sku_input_data)
     if nRet ~= 0 then
         return 1, "澶勭悊SKU_GridBox_Parm澶辫触: " .. strRetInfo
     end
@@ -340,8 +435,6 @@
         return
     end
 
-    lua.DebugEx(strLuaDEID, "鑾峰彇鍒扮殑鏁版嵁鍖�, soap_xml)
-
     -- 2. 瑙f瀽xml
     local nRet, parsed_data = xml.parse(soap_xml)
     if nRet ~= 0 then
@@ -362,7 +455,7 @@
         return
     end
 
-    -- 4. 缁熶竴澶勭悊锛氱‘淇漵ku_items鏄暟缁勶紙鍗充娇鍙湁涓�釜SKU锛�+    -- 4. 缁熶竴澶勭悊锛氱‘淇漵ku_items鏄暟缁�     local sku_items = sku_data.COMMODITY_TB_ITEM
     if sku_items[1] == nil then
         sku_items = {sku_items}
@@ -371,22 +464,17 @@
     -- 5. 閬嶅巻鎵�湁SKU鏁版嵁
     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)
+            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")

--
Gitblit v1.9.1