From f1a64ab92120ffc0f1b1cf2c4848528a0d6b5d18 Mon Sep 17 00:00:00 2001 From: fy36 <1046342473@qq.com> Date: 星期一, 28 七月 2025 18:42:41 +0800 Subject: [PATCH] 一系列脚本更新 --- lua_code/Lua/GK-API-01-SKU_Sync.lua | 790 +++++++++++++++++++------------------------------------ 1 files changed, 279 insertions(+), 511 deletions(-) diff --git a/lua_code/Lua/GK-API-01-SKU_Sync.lua b/lua_code/Lua/GK-API-01-SKU_Sync.lua index 65e2d0f..a8c19d6 100644 --- a/lua_code/Lua/GK-API-01-SKU_Sync.lua +++ b/lua_code/Lua/GK-API-01-SKU_Sync.lua @@ -1,7 +1,7 @@ --[[ 缂栫爜: GK-API-001 鍚嶇О: 鐩樼偣璁″垝鍚屾 - 浣滆�: HAN + 浣滆�: Yuanfeng 鏃ユ湡: 2025-1-29 鍏ュ彛鍑芥暟锛�SKU_Sync @@ -19,326 +19,170 @@ V2.3 绉婚櫎error瀛楁锛屽悎骞跺埌message涓� V2.4 鏂板SKU_GRID_PARM瀛楁 V2.5 2025-07-01 SKU_GRID鏂欑鏍煎弬鏁颁紭鍖栦负鏍规嵁cell_type 鑷姩鍚屾 - -<?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>BM125262</v1:skuId> - <v1:storerId>TGKHMB</v1:storerId> - <v1:skuName>Exceed ABT寰瓟娑傚眰楂嬭嚰鏉�2mm</v1:skuName> - <v1:skuDec>Exceed ABT寰瓟娑傚眰楂嬭嚰鏉�2mm</v1:skuDec> - <v1:spec>Acetabular Shell PC 52 x 62mm</v1:spec> - <v1:packageCode>浠�/v1:packageCode> - <v1:packageQty>1</v1:packageQty> - <v1:goodsUnit>浠�/v1:goodsUnit> - <v1:length>10</v1:length> - <v1:width>10</v1:width> - <v1:height>10</v1:height> - <v1:abcType/> - <v1:isBatchMgr>0</v1:isBatchMgr> - <v1:isSnMgr>0</v1:isSnMgr> - <v1:isSnStorageMgr>0</v1:isSnStorageMgr> - <v1:imgUrl/> - <v1:cidtype>A</v1:cidtype> - <v1:productLine>BM-鍏宠妭</v1:productLine> - <v1:storageConditions>鏄�/v1:storageConditions> - <v1:skuType>small</v1:skuType> - <v1:maxCount>120</v1:maxCount> - <v1:bMaxCount/> - <v1:cMaxCount/> - <v1:dMaxCount/> - <v1:eMaxCount/> - <v1:fMaxCount/> - <v1:upc>501927908583</v1:upc> - </v1:COMMODITY_TB_ITEM> - <v1:COMMODITY_TB_ITEM> - <v1:skuId>BM141234</v1:skuId> - <v1:storerId>CGKHTY</v1:storerId> - <v1:skuName>Biomet 鍥哄畾鍗佸瓧鍨嬫焺鑳骞冲彴鍋囦綋 75mm</v1:skuName> - <v1:skuDec>Biomet 鍥哄畾鍗佸瓧鍨嬫焺鑳骞冲彴鍋囦綋 75mm</v1:skuDec> - <v1:spec>75mm</v1:spec> - <v1:packageCode>浠�/v1:packageCode> - <v1:packageQty>1</v1:packageQty> - <v1:goodsUnit>浠�/v1:goodsUnit> - <v1:length>.5</v1:length> - <v1:width>.5</v1:width> - <v1:height>.5</v1:height> - <v1:abcType/> - <v1:isBatchMgr>0</v1:isBatchMgr> - <v1:isSnMgr>0</v1:isSnMgr> - <v1:isSnStorageMgr>0</v1:isSnStorageMgr> - <v1:imgUrl/> - <v1:cidtype>A</v1:cidtype> - <v1:productLine>BM-鍏宠妭</v1:productLine> - <v1:storageConditions>鏄�/v1:storageConditions> - <v1:skuType>small</v1:skuType> - <v1:maxCount>120</v1:maxCount> - <v1:bMaxCount/> - <v1:cMaxCount/> - <v1:dMaxCount/> - <v1:eMaxCount/> - <v1:fMaxCount/> - <v1:upc>1</v1:upc> - </v1:COMMODITY_TB_ITEM> - <v1:COMMODITY_TB_ITEM> - <v1:skuId>BM141234</v1:skuId> - <v1:storerId>GGKHN1</v1:storerId> - <v1:skuName>Biomet 鍥哄畾鍗佸瓧鍨嬫焺鑳骞冲彴鍋囦綋 75mm</v1:skuName> - <v1:skuDec>-</v1:skuDec> - <v1:spec>75mm</v1:spec> - <v1:packageCode>浠�/v1:packageCode> - <v1:packageQty>1</v1:packageQty> - <v1:goodsUnit>浠�/v1:goodsUnit> - <v1:length>10</v1:length> - <v1:width>10</v1:width> - <v1:height>10</v1:height> - <v1:abcType>C</v1:abcType> - <v1:isBatchMgr>0</v1:isBatchMgr> - <v1:isSnMgr>0</v1:isSnMgr> - <v1:isSnStorageMgr>0</v1:isSnStorageMgr> - <v1:imgUrl/> - <v1:cidtype>A</v1:cidtype> - <v1:productLine>BM-鍏宠妭</v1:productLine> - <v1:storageConditions/> - <v1:skuType>small</v1:skuType> - <v1:maxCount>120</v1:maxCount> - <v1:bMaxCount/> - <v1:cMaxCount/> - <v1:dMaxCount/> - <v1:eMaxCount/> - <v1:fMaxCount/> - <v1:upc>088030400832</v1:upc> - </v1:COMMODITY_TB_ITEM> - <v1:COMMODITY_TB_ITEM> - <v1:skuId>BM141234</v1:skuId> - <v1:storerId>TGKHMB</v1:storerId> - <v1:skuName>Biomet 鍥哄畾鍗佸瓧鍨嬫焺鑳骞冲彴鍋囦綋 75mm</v1:skuName> - <v1:skuDec>Biomet 鍥哄畾鍗佸瓧鍨嬫焺鑳骞冲彴鍋囦綋 75mm</v1:skuDec> - <v1:spec>75mm</v1:spec> - <v1:packageCode>浠�/v1:packageCode> - <v1:packageQty>1</v1:packageQty> - <v1:goodsUnit>浠�/v1:goodsUnit> - <v1:length>10</v1:length> - <v1:width>10</v1:width> - <v1:height>10</v1:height> - <v1:abcType/> - <v1:isBatchMgr>0</v1:isBatchMgr> - <v1:isSnMgr>0</v1:isSnMgr> - <v1:isSnStorageMgr>0</v1:isSnStorageMgr> - <v1:imgUrl/> - <v1:cidtype>A</v1:cidtype> - <v1:productLine>BM-鍏宠妭</v1:productLine> - <v1:storageConditions>鏄�/v1:storageConditions> - <v1:skuType>small</v1:skuType> - <v1:maxCount>120</v1:maxCount> - <v1:bMaxCount/> - <v1:cMaxCount/> - <v1:dMaxCount/> - <v1:eMaxCount/> - <v1:fMaxCount/> - <v1:upc>088030400832</v1:upc> - </v1:COMMODITY_TB_ITEM> - <v1:COMMODITY_TB_ITEM> - <v1:skuId>BM141234</v1:skuId> - <v1:storerId>TGKRTH</v1:storerId> - <v1:skuName>Biomet 鍥哄畾鍗佸瓧鍨嬫焺鑳骞冲彴鍋囦綋 75mm</v1:skuName> - <v1:skuDec>-</v1:skuDec> - <v1:spec>75mm</v1:spec> - <v1:packageCode>浠�/v1:packageCode> - <v1:packageQty>1</v1:packageQty> - <v1:goodsUnit>浠�/v1:goodsUnit> - <v1:length>10</v1:length> - <v1:width>10</v1:width> - <v1:height>10</v1:height> - <v1:abcType/> - <v1:isBatchMgr>0</v1:isBatchMgr> - <v1:isSnMgr>0</v1:isSnMgr> - <v1:isSnStorageMgr>0</v1:isSnStorageMgr> - <v1:imgUrl/> - <v1:cidtype>A</v1:cidtype> - <v1:productLine>BM-鍏宠妭</v1:productLine> - <v1:storageConditions>鏄�/v1:storageConditions> - <v1:skuType>small</v1:skuType> - <v1:maxCount>120</v1:maxCount> - <v1:bMaxCount/> - <v1:cMaxCount/> - <v1:dMaxCount/> - <v1:eMaxCount/> - <v1:fMaxCount/> - <v1:upc>088030400832</v1:upc> - </v1:COMMODITY_TB_ITEM> - <v1:COMMODITY_TB_ITEM> - <v1:skuId>BM141234</v1:skuId> - <v1:storerId>TNMGGK</v1:storerId> - <v1:skuName>Biomet 鍥哄畾鍗佸瓧鍨嬫焺鑳骞冲彴鍋囦綋 75mm</v1:skuName> - <v1:skuDec>-</v1:skuDec> - <v1:spec>75mm</v1:spec> - <v1:packageCode>浠�/v1:packageCode> - <v1:packageQty>1</v1:packageQty> - <v1:goodsUnit>浠�/v1:goodsUnit> - <v1:length>10</v1:length> - <v1:width>10</v1:width> - <v1:height>10</v1:height> - <v1:abcType/> - <v1:isBatchMgr>0</v1:isBatchMgr> - <v1:isSnMgr>0</v1:isSnMgr> - <v1:isSnStorageMgr>0</v1:isSnStorageMgr> - <v1:imgUrl/> - <v1:cidtype>A</v1:cidtype> - <v1:productLine>BM-鍏宠妭</v1:productLine> - <v1:storageConditions>鏄�/v1:storageConditions> - <v1:skuType>small</v1:skuType> - <v1:maxCount>120</v1:maxCount> - <v1:bMaxCount/> - <v1:cMaxCount/> - <v1:dMaxCount/> - <v1:eMaxCount/> - <v1:fMaxCount/> - <v1:upc>088030400832</v1:upc> - </v1:COMMODITY_TB_ITEM> - <v1:COMMODITY_TB_ITEM> - <v1:skuId>BM154720</v1:skuId> - <v1:storerId>CGKHTY</v1:storerId> - <v1:skuName>Oxford绗笁浠e崟楂佽啙鍏宠妭楠ㄦ按娉ュ瀷瑙e墫鍨嬫爣鍑嗚儷楠ㄥ簳鏉�宸﹁啙鍐呬晶 Size B</v1:skuName> - <v1:skuDec>Oxford绗笁浠e崟楂佽啙鍏宠妭楠ㄦ按娉ュ瀷瑙e墫鍨嬫爣鍑嗚儷楠ㄥ簳鏉�宸﹁啙鍐呬晶 Size B</v1:skuDec> - <v1:spec>宸﹁啙鍐呬晶 Size B</v1:spec> - <v1:packageCode>浠�/v1:packageCode> - <v1:packageQty>1</v1:packageQty> - <v1:goodsUnit>浠�/v1:goodsUnit> - <v1:length>10</v1:length> - <v1:width>10</v1:width> - <v1:height>10</v1:height> - <v1:abcType/> - <v1:isBatchMgr>0</v1:isBatchMgr> - <v1:isSnMgr>0</v1:isSnMgr> - <v1:isSnStorageMgr>0</v1:isSnStorageMgr> - <v1:imgUrl/> - <v1:cidtype>A</v1:cidtype> - <v1:productLine>BM-鍏宠妭</v1:productLine> - <v1:storageConditions>鏄�/v1:storageConditions> - <v1:skuType>small</v1:skuType> - <v1:maxCount>120</v1:maxCount> - <v1:bMaxCount/> - <v1:cMaxCount/> - <v1:dMaxCount/> - <v1:eMaxCount/> - <v1:fMaxCount/> - <v1:upc>501927938886</v1:upc> - </v1:COMMODITY_TB_ITEM> - <v1:COMMODITY_TB_ITEM> - <v1:skuId>BM154720</v1:skuId> - <v1:storerId>GGKHN1</v1:storerId> - <v1:skuName>Oxford绗笁浠e崟楂佽啙鍏宠妭楠ㄦ按娉ュ瀷瑙e墫鍨嬫爣鍑嗚儷楠ㄥ簳鏉�宸﹁啙鍐呬晶 Size B</v1:skuName> - <v1:skuDec>-</v1:skuDec> - <v1:spec>宸﹁啙鍐呬晶 Size B</v1:spec> - <v1:packageCode>浠�/v1:packageCode> - <v1:packageQty>1</v1:packageQty> - <v1:goodsUnit>浠�/v1:goodsUnit> - <v1:length>10</v1:length> - <v1:width>10</v1:width> - <v1:height>10</v1:height> - <v1:abcType>C</v1:abcType> - <v1:isBatchMgr>0</v1:isBatchMgr> - <v1:isSnMgr>0</v1:isSnMgr> - <v1:isSnStorageMgr>0</v1:isSnStorageMgr> - <v1:imgUrl/> - <v1:cidtype>A</v1:cidtype> - <v1:productLine>BM-鍏宠妭</v1:productLine> - <v1:storageConditions/> - <v1:skuType>small</v1:skuType> - <v1:maxCount>120</v1:maxCount> - <v1:bMaxCount/> - <v1:cMaxCount/> - <v1:dMaxCount/> - <v1:eMaxCount/> - <v1:fMaxCount/> - <v1:upc>501927938886</v1:upc> - </v1:COMMODITY_TB_ITEM> - <v1:COMMODITY_TB_ITEM> - <v1:skuId>BM154720</v1:skuId> - <v1:storerId>TGKHMB</v1:storerId> - <v1:skuName>Oxford绗笁浠e崟楂佽啙鍏宠妭楠ㄦ按娉ュ瀷瑙e墫鍨嬫爣鍑嗚儷楠ㄥ簳鏉�宸﹁啙鍐呬晶 Size B</v1:skuName> - <v1:skuDec>Oxford绗笁浠e崟楂佽啙鍏宠妭楠ㄦ按娉ュ瀷瑙e墫鍨嬫爣鍑嗚儷楠ㄥ簳鏉�宸﹁啙鍐呬晶 Size B</v1:skuDec> - <v1:spec>宸﹁啙鍐呬晶 Size B</v1:spec> - <v1:packageCode>浠�/v1:packageCode> - <v1:packageQty>1</v1:packageQty> - <v1:goodsUnit>浠�/v1:goodsUnit> - <v1:length>10</v1:length> - <v1:width>10</v1:width> - <v1:height>10</v1:height> - <v1:abcType/> - <v1:isBatchMgr>0</v1:isBatchMgr> - <v1:isSnMgr>0</v1:isSnMgr> - <v1:isSnStorageMgr>0</v1:isSnStorageMgr> - <v1:imgUrl/> - <v1:cidtype>A</v1:cidtype> - <v1:productLine>BM-鍏宠妭</v1:productLine> - <v1:storageConditions>鏄�/v1:storageConditions> - <v1:skuType>small</v1:skuType> - <v1:maxCount>120</v1:maxCount> - <v1:bMaxCount/> - <v1:cMaxCount/> - <v1:dMaxCount/> - <v1:eMaxCount/> - <v1:fMaxCount/> - <v1:upc>501927938886</v1:upc> - </v1:COMMODITY_TB_ITEM> - <v1:COMMODITY_TB_ITEM> - <v1:skuId>BM154720</v1:skuId> - <v1:storerId>TNMGGK</v1:storerId> - <v1:skuName>Oxford绗笁浠e崟楂佽啙鍏宠妭楠ㄦ按娉ュ瀷瑙e墫鍨嬫爣鍑嗚儷楠ㄥ簳鏉�宸﹁啙鍐呬晶 Size B</v1:skuName> - <v1:skuDec>-</v1:skuDec> - <v1:spec>宸﹁啙鍐呬晶 Size B</v1:spec> - <v1:packageCode>浠�/v1:packageCode> - <v1:packageQty>1</v1:packageQty> - <v1:goodsUnit>浠�/v1:goodsUnit> - <v1:length>10</v1:length> - <v1:width>10</v1:width> - <v1:height>10</v1:height> - <v1:abcType/> - <v1:isBatchMgr>0</v1:isBatchMgr> - <v1:isSnMgr>0</v1:isSnMgr> - <v1:isSnStorageMgr>0</v1:isSnStorageMgr> - <v1:imgUrl/> - <v1:cidtype>A</v1:cidtype> - <v1:productLine>BM-鍏宠妭</v1:productLine> - <v1:storageConditions>鏄�/v1:storageConditions> - <v1:skuType>small</v1:skuType> - <v1:maxCount>120</v1:maxCount> - <v1:bMaxCount/> - <v1:cMaxCount/> - <v1:dMaxCount/> - <v1:eMaxCount/> - <v1:fMaxCount/> - <v1:upc>501927938886</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") + V2.6 鏈鏇存柊涓昏閽堝SKU鏂欑鏍煎弬鏁帮紙SKU_GridBox_Parm锛夊悓姝ラ�杈戣繘琛屼紭鍖栵紝 + 瑙e喅浜嗗湪涓嶅悓cid_type鍙樻洿鍦烘櫙涓嬬殑鏂欐牸澶勭悊闂锛岀‘淇濇暟鎹悓姝ョ殑鍑嗙‘鎬у拰瀹屾暣鎬с� + + ]] wms_base = require("wms_base") xml = require("oi_base_xml") -mobox = require("OILua_JavelinExt") m3 = require("oi_base_mobox") +-- 鍒涘缓鎴栨洿鏂癝KU_UPC鏉$爜璁板綍锛堥噸鏋勭増锛�+-- @param strLuaDEID: Lua鏁版嵁浜ゆ崲ID +-- @param storer: 璐т富缂栫爜 +-- @param item_code: SKU缂栫爜 +-- @param upc_code: UPC鏉$爜 +-- @return: 杩斿洖涓や釜鍊�(閿欒鐮� 閿欒淇℃伅/鎴愬姛淇℃伅) +-- 鍒涘缓鎴栨洿鏂癝KU_UPC鏉$爜璁板綍锛堜紭鍖栫増锛�+-- @param strLuaDEID: Lua鏁版嵁浜ゆ崲ID +-- @param storer: 璐т富缂栫爜 +-- @param item_code: SKU缂栫爜 +-- @param upc_code: UPC鏉$爜 +-- @return: 杩斿洖涓や釜鍊�(閿欒鐮� 閿欒淇℃伅/鎴愬姛淇℃伅) +local function create_or_update_sku_upc(strLuaDEID, storer, item_code, upc_code) + local nRet, strRetInfo + + -- 1. 妫�煡UPC鏄惁鏈夋晥 + if not upc_code or upc_code == '' then + -- lua.debugex(strLuaDEID, "UPC涓虹┖", "璐т富:"..storer..", SKU:"..item_code) + return 0, "UPC涓虹┖锛岃烦杩囧鐞� -- 淇敼涓鸿繑鍥�琛ㄧず璺宠繃 + end + + -- 2. 妫�煡璇KU鐨刄PC璁板綍鏄惁宸插瓨鍦紙涓夊瓧娈典富閿鏌ワ級 + local strCondition = string.format("S_STORER = '%s' AND S_ITEM_CODE = '%s'", storer, item_code) + nRet, strRetInfo = mobox.existThisData(strLuaDEID, "SKU_UPC", strCondition) + if nRet ~= 0 then + local errMsg = "妫�煡SKU_UPC璁板綍澶辫触: " .. tostring(strRetInfo) + return 1, errMsg + end + + -- 3. 澶勭悊妫�煡缁撴灉 + if strRetInfo == 'yes' then + -- 璁板綍宸插瓨鍦ㄤ笖瀹屽叏鐩稿悓锛岀洿鎺ヨ烦杩�+ local updateAttr = string.format("S_UPC_CODE='%s'", upc_code); + local nRet, strRetInfo = mobox.updateDataAttrByCondition(strLuaDEID, "SKU_UPC", strCondition, updateAttr) + if (nRet ~= 0) then + return 1, "鏁版嵁鏇存柊澶辫触!" .. strRetInfo + else + lua.DebugEx(strLuaDEID, "鏁版嵁鏇存柊鎴愬姛....", strRetInfo) + return 0, "UPC 宸叉洿鏂� .. strRetInfo + end + + -- 鍙綔涓烘洿鏂版搷浣�+ 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.UpdateDataObj(strLuaDEID, sku_upc) + if nRet ~= 0 then + local errMsg = "鏇存柊SKU_UPC澶辫触: " .. tostring(strRetInfo) + return 1, errMsg + end + return 0, "SKU_UPC宸插瓨鍦ㄤ笖鐩稿悓锛岃烦杩囧鐞� + end + + -- 5. 鍒涘缓鏂拌褰�+ 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) + if nRet ~= 0 then + local errMsg = "鍒涘缓SKU_UPC澶辫触: " .. tostring(strRetInfo) + return 1, errMsg + end + return 0, "鍒涘缓SKU_UPC鎴愬姛" +end + +-- 鍒涘缓/鏇存柊SKU瀵瑰簲鐨勮揣鍝佹枡绠辨牸鍙傛暟 +-- 涓嶅啀渚濊禆cell_type浣滀负鎴鑼冨洿锛岃�鏄鏌ユ墍鏈塵axCount~fMaxCount瀛楁 +-- @param strLuaDEID: Lua鏁版嵁浜ゆ崲ID +-- @param skuModel: SKU妯″瀷瀵硅薄 +-- @param sku_input_data: 杈撳叆鏁版嵁 +-- @return: 杩斿洖閿欒鐮佸拰閿欒淇℃伅 +local function create_or_update_sku_gridbox(strLuaDEID, skuModel, sku_input_data) + local strRetInfo + + -- 1. 鑾峰彇榛樿瀹瑰櫒绫诲瀷缂栫爜 + local nConstRet, CONST_CTD_CODE = wms_base.Get_sConst2("WMS_Default_CNTR_Type") + if nConstRet ~= 0 then + return 1, "鑾峰彇榛樿瀹瑰櫒绫诲瀷瀹氫箟缂栫爜澶辫触: " .. CONST_CTD_CODE + end + -- 2. 瀹氫箟鏂欑鏍肩被鍨嬩笌瀛楁鏄犲皠鍏崇郴 + local gridbox_types = { + A = { + field = "maxCount", + value = sku_input_data.maxCount + }, + B = { + field = "bMaxCount", + value = sku_input_data.bMaxCount + }, + C = { + field = "cMaxCount", + value = sku_input_data.cMaxCount + }, + D = { + field = "dMaxCount", + value = sku_input_data.dMaxCount + }, + E = { + field = "eMaxCount", + value = sku_input_data.eMaxCount + }, + F = { + field = "fMaxCount", + value = sku_input_data.fMaxCount + } + } + -- 3. 澶勭悊鎵�湁鏂欑鏍肩被鍨�+ for cell_type, type_info in pairs(gridbox_types) do + local loading_limit = lua.Get_NumAttrValue(type_info.value) or 0 + + -- 鍙湁褰撻檺鍒跺�澶т簬0鏃舵墠澶勭悊 + if loading_limit > 0 then + -- 绮剧‘鏌ヨ璇ョ被鍨嬬殑鏂欑鏍艰褰�+ 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, 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 + }} + }} + nRet, strRetInfo = + mobox.updateDataObj(strLuaDEID, "SKU_GridBox_Parm", lua.table2str(update_gridbox_obj)) + if nRet ~= 0 then + return 1, string.format("鏇存柊%s绫诲瀷鏂欑鏍煎睘鎬уけ璐� %s", cell_type, 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 = CONST_CTD_CODE + gridbox.loading_limit = loading_limit + gridbox.cell_type = cell_type + nRet, strRetInfo = m3.CreateDataObj(strLuaDEID, gridbox) + if nRet ~= 0 then + return 1, string.format("鍒涘缓%s绫诲瀷鏂欑鏍煎け璐� %s", cell_type, strRetInfo) + end + else + -- 鏌ヨ鍑洪敊 + return 1, string.format("鏌ヨ%s绫诲瀷鏂欑鏍艰褰曞け璐� %s", cell_type, + existing_records or "鏈煡閿欒") + end + end + end + + return 0, "鏂欑鏍煎弬鏁板鐞嗗畬鎴� +end -- 鍒涘缓缁熶竴杩斿洖缁撴灉锛堜慨鏀瑰悗鐗堟湰锛岀Щ闄rror瀛楁锛� function Create_result(flag, code, msg) return { @@ -350,13 +194,10 @@ -- 鍒涘缓鎴栨洿鏂癎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) @@ -380,7 +221,6 @@ value = proline_name }} }} - nRet, strRetInfo = mobox.updateDataObj(strLuaDEID, "GK_PROLINE", lua.table2str(update_proline_obj)) if nRet ~= 0 then return 1, "鏇存柊GK_PROLINE澶辫触: " .. strRetInfo @@ -389,204 +229,99 @@ 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 +-- 閲嶆瀯鍚庣殑build_sku_grid_json鍑芥暟 +-- 鐜板湪瀹屽叏鍩轰簬鏁版嵁搴撲腑鐨勫疄闄呮枡鏍艰褰曠敓鎴怞SON +-- @param strLuaDEID: Lua鏁版嵁浜ゆ崲ID +-- @param item_code: SKU缂栫爜 +-- @param storer: 璐т富缂栫爜 +-- @return: 杩斿洖涓や釜鍊�(JSON瀛楃涓� 閿欒淇℃伅) +local function build_sku_grid_json(strLuaDEID, item_code, storer) + -- 1. 鑾峰彇榛樿瀹瑰櫒绫诲瀷缂栫爜 + local nConstRet, CONST_CTD_CODE = wms_base.Get_sConst2("WMS_Default_CNTR_Type") + if nConstRet ~= 0 then + return "", "鑾峰彇榛樿瀹瑰櫒绫诲瀷瀹氫箟缂栫爜澶辫触: " .. CONST_CTD_CODE end - 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) + -- 2. 鏌ヨ璇KU鎵�湁鐜版湁鐨勬枡绠辨牸璁板綍 + local strCondition = string.format("S_ITEM_CODE = '%s' AND S_STORER = '%s' AND S_CTD_CODE='%s'", item_code, storer, + CONST_CTD_CODE) + local nRet, grid_records = m3.QueryDataObject(strLuaDEID, "SKU_GridBox_Parm", strCondition) - return nRet, strRetInfo -end - - --- 鏂板sku_grid_parm JSON瀛楃涓诧紝鍦⊿KU 鍒涘缓鐨勬椂鍊欐彃鍏son鏁版嵁 -local function build_sku_grid_parm(ctd_code, sku_input_data, cell_type) - -- 濡傛灉cell_type涓虹┖鍒欒烦杩�- if not cell_type or cell_type == "" then - return "" + -- 3. 澶勭悊鏌ヨ缁撴灉 + if nRet ~= 0 then + return "", "鏌ヨSKU_GridBox_Parm璁板綍澶辫触: " .. (grid_records or "鏈煡閿欒") end - -- 瀹氫箟鍩虹json妗嗘灦缁撴瀯锛堟斁鍦ㄦ暟缁勪腑锛�+ -- 4. 鏋勫缓鍩虹JSON缁撴瀯 local grid_def = {{ - ctd_code = ctd_code, + ctd_code = CONST_CTD_CODE, cell_def = {} }} - -- 鏍规嵁cell_type纭畾澶勭悊鑼冨洿 - local types_to_process = {} - if cell_type == "A" then - types_to_process = {"A"} - elseif cell_type == "B" then - types_to_process = {"A", "B"} - elseif cell_type == "C" then - types_to_process = {"A", "B", "C"} - elseif cell_type == "D" then - types_to_process = {"A", "B", "C", "D"} - elseif cell_type == "E" then - types_to_process = {"A", "B", "C", "D", "E"} - elseif cell_type == "F" then - types_to_process = {"A", "B", "C", "D", "E", "F"} - else - -- 鏈煡绫诲瀷锛岄粯璁ゅ彧澶勭悊A绫诲瀷 - types_to_process = {"A"} - end + -- 5. 澶勭悊鏌ヨ鍒扮殑璁板綍 + if grid_records and #grid_records > 0 then + for _, record in ipairs(grid_records) do + -- 灏嗗睘鎬ф暟缁勮浆鎹负瀵硅薄 + local record_obj = m3.KeyValueAttrsToObjAttr(record.attrs) - -- 瀹氫箟鏂欑绫诲瀷涓庡搴斿瓧娈电殑鏄犲皠 - local grid_mapping = { - A = {loading_limit = sku_input_data.maxCount}, - B = {loading_limit = sku_input_data.bMaxCount}, - C = {loading_limit = sku_input_data.cMaxCount}, - D = {loading_limit = sku_input_data.dMaxCount}, - E = {loading_limit = sku_input_data.eMaxCount}, - F = {loading_limit = sku_input_data.fMaxCount} - } + -- 鎻愬彇闇�鐨勫瓧娈�+ local cell_type = record_obj.S_CELL_TYPE or "" + local loading_limit = lua.Get_NumAttrValue(record_obj.N_LOADING_LIMIT) or 0 + local load_capacity = lua.Get_NumAttrValue(record_obj.F_LOAD_CAPACITY) or loading_limit -- 榛樿绛変簬loading_limit - -- 鏋勫缓cell_def鏁扮粍 - for _, type_key in ipairs(types_to_process) do - local grid = grid_mapping[type_key] - local limit = lua.Get_NumAttrValue(grid.loading_limit) or 0 - if limit > 0 then -- 鍙湁褰撻檺鍒跺�澶т簬0鏃舵墠娣诲姞 - table.insert(grid_def[1].cell_def, { - cell_type = type_key, - loading_limit = limit, - load_capacity = limit - }) - end - end - - lua.DebugEx(strLuaDEID, "grid", grid_def) - return lua.table2str(grid_def) -end - --- 鍒涘缓/鏇存柊SKU瀵瑰簲鐨勮揣鍝佹枡绠辨牸鍙傛暟 --- skuModel 鏄暟鎹簱瀹氫箟鐨勬暟鎹ā鍨媠ku锛屼篃灏辨槸Alloc鎵�垱寤虹殑SKU瀵硅薄銆�-local function create_or_update_sku_gridbox(strLuaDEID, skuModel, sku_input_data) - local strRetInfo - -- 鑾峰彇榛樿瀹瑰櫒绫诲瀷缂栫爜 - local nConstRet, CONST_CTD_CODE = wms_base.Get_sConst2("WMS_Default_CNTR_Type") - if nConstRet ~= 0 then - return 1, "鑾峰彇榛樿瀹瑰櫒绫诲瀷瀹氫箟缂栫爜澶辫触: " .. CONST_CTD_CODE - end - - -- 濡傛灉cell_type涓虹┖鍒欒烦杩�- if not skuModel.cell_type or skuModel.cell_type == "" then - return 0, "cell_type涓虹┖锛岃烦杩囨枡绠辨牸鍙傛暟澶勭悊" - end - - -- 鏍规嵁cell_type纭畾澶勭悊鑼冨洿 - local types_to_process = {} - if skuModel.cell_type == "A" then - types_to_process = {"A"} - elseif skuModel.cell_type == "B" then - types_to_process = {"A", "B"} - elseif skuModel.cell_type == "C" then - types_to_process = {"A", "B", "C"} - elseif skuModel.cell_type == "D" then - types_to_process = {"A", "B", "C", "D"} - elseif skuModel.cell_type == "E" then - types_to_process = {"A", "B", "C", "D", "E"} - elseif skuModel.cell_type == "F" then - types_to_process = {"A", "B", "C", "D", "E", "F"} - else - -- 鏈煡绫诲瀷锛岄粯璁ゅ彧澶勭悊A绫诲瀷 - types_to_process = {"A"} - end - - -- 瀹氫箟鏂欑鏍肩被鍨嬩笌瀵瑰簲瀛楁鐨勬槧灏�- local gridbox_types = { - A = sku_input_data.maxCount, - B = sku_input_data.bMaxCount, - C = sku_input_data.cMaxCount, - D = sku_input_data.dMaxCount, - E = sku_input_data.eMaxCount, - F = sku_input_data.fMaxCount - } - - -- 澶勭悊姣忕鏂欑鏍肩被鍨�- for _, type_key in ipairs(types_to_process) do - local loading_limit = lua.Get_NumAttrValue(gridbox_types[type_key]) or 0 - if loading_limit <= 0 then -- 鍙湁褰撻檺鍒跺�澶т簬0鏃舵墠澶勭悊 - goto continue - end - - -- 绮剧‘鏌ヨ璇ョ被鍨嬬殑鏂欑鏍艰褰�- 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, type_key) - 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 - }} - }} - - nRet, strRetInfo = mobox.updateDataObj(strLuaDEID, "SKU_GridBox_Parm", lua.table2str(update_gridbox_obj)) - if nRet ~= 0 then - return 1, string.format("鏇存柊%s绫诲瀷鏂欑鏍煎睘鎬уけ璐� %s", type_key, strRetInfo) + -- 鍙湁褰撳�鏈夋晥鏃舵墠娣诲姞鍒癑SON + if cell_type ~= "" and loading_limit > 0 then + table.insert(grid_def[1].cell_def, { + cell_type = cell_type, + loading_limit = loading_limit, + load_capacity = load_capacity + }) 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 = CONST_CTD_CODE - gridbox.loading_limit = loading_limit - gridbox.cell_type = type_key - - nRet, strRetInfo = m3.CreateDataObj(strLuaDEID, gridbox) - if nRet ~= 0 then - return 1, string.format("鍒涘缓%s绫诲瀷鏂欑鏍煎け璐� %s", type_key, strRetInfo) - end - else - -- 鏌ヨ鍑洪敊 - return 1, string.format("鏌ヨ%s绫诲瀷鏂欑鏍艰褰曞け璐� %s", type_key, existing_records or "鏈煡閿欒") end - - ::continue:: end - return 0, "鏂欑鏍煎弬鏁板鐞嗗畬鎴� + -- 6. 杞崲涓篔SON瀛楃涓�+ local json_str = lua.table2str(grid_def) + -- -- lua.debugex(strLuaDEID, "鐢熸垚鐨刧rid_json", json_str) + + return json_str end -- 鍒涘缓鎴栨洿鏂癝KU涓绘暟鎹�+-- @param sku_input_data: 瀹為檯涓婂氨鏄姤鏂囦腑鐨勶細sku_data.COMMODITY_TB_ITEM 涓嬮潰鐨勫瓧娈靛唴瀹� local function create_sku(strLuaDEID, sku_input_data) local nRet, strRetInfo - local err_msg = '' + -- 棣栧厛鏍¢獙cidtype鏄惁涓虹┖ + if not sku_input_data.cidtype or sku_input_data.cidtype == '' then + return 1, "skuId涓猴細" .. sku_input_data.skuId .. "鐨勯�閰嶆枡鏍糲idtype涓嶅厑璁镐负绌猴紒" + end + -- 鑾峰彇绯荤粺甯搁噺 -- 鑾峰彇榛樿瀹瑰櫒绫诲瀷缂栫爜 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_input_data.cidtype) - lua.DebugEx(strLuaDEID, "sku_grid_parm", sku_grid_parm) + if (sku_input_data.cidtype == nil or sku_input_data.cidtype == '') then + return 1, "skuId涓猴細" .. sku_input_data.skuId .. "鐨勯�閰嶆枡鏍糲idtype涓嶅厑璁镐负绌猴紒" + end + -- 棣栧厛妫�煡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 "鏈煡閿欒") + + local existSKUnRet, existingSKU = mobox.existThisData(strLuaDEID, "SKU", strCondition) + lua.DebugEx(strLuaDEID, "妫�煡SKU鏄惁瀛樺湪杩斿洖缁撴灉", existingSKU); + + if existSKUnRet ~= 0 then + return 1, "妫�煡SKU鏄惁瀛樺湪鏃跺け璐� " .. (existingSKU or "鏈煡閿欒") end -- 鍒嗛厤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.item_name = sku_input_data.skuName + sku.note = sku_input_data.skuDec sku.spec = sku_input_data.spec sku.unit = sku_input_data.goodsUnit sku.long = lua.Get_NumAttrValue(sku_input_data.length) or 0 @@ -600,24 +335,46 @@ 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 + sku.sku_grid_parm = '[{"ctd_code":"CTD-001","cell_def":{}}]'; -- 鍏堢粰涓粯璁ゅ� + + -- 2025-07-21 鏂板涓昏〃瀛楁 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 - sku.sku_grid_parm = sku_grid_parm; - -- lua.DebugEx(strLuaDEID, "鏇存柊/鍒涘缓鏁版嵁缁撴灉锛�, sku) - if nRet == 1 then - -- SKU涓嶅瓨鍦紝鍒涘缓鏂拌褰�- nRet, strRetInfo = m3.CreateDataObj(strLuaDEID, sku) - if nRet ~= 0 then - return 1, "鍒涘缓SKU澶辫触: " .. strRetInfo .. " skuId = " .. sku_input_data.skuId + sku.udf02 = sku_input_data.registerNo or "" -- 娉ㄥ唽璇佸彿 + sku.udf03 = sku_input_data.companyName or "" -- 鐢熶骇浼佷笟 + sku.udf04 = sku_input_data.certCompanyName or "" -- 璇佷欢鐢熶骇鍘傚 + sku.udf05 = sku_input_data.consignCompanyWTName or "" -- 濮旀墭鐢熶骇鍘傚 + sku.udf06 = sku_input_data.sterilizationDate or "" -- 鐏弻鏃ユ湡 + sku.udf06 = sku_input_data.ex1 or "" -- 鎵╁睍瀛楁1 + sku.udf07 = sku_input_data.ex2 or "" -- 鎵╁睍瀛楁2 + sku.udf08 = sku_input_data.ex3 or "" -- 鎵╁睍瀛楁3 + -- 1. 鍏堝鐞嗘枡绠辨牸鍙傛暟锛堢‘淇濇暟鎹簱璁板綍鏈�柊锛�+ local nRet, strRetInfo = create_or_update_sku_gridbox(strLuaDEID, sku, sku_input_data) + if nRet ~= 0 then + return 1, "澶勭悊SKU_GridBox_Parm澶辫触: " .. strRetInfo + end + + -- 2. 鍩轰簬鏁版嵁搴撳疄闄呰褰曠敓鎴怞SON锛堜笉鍐嶄緷璧栦紶鍏ョ殑cidtype锛�+ local sku_grid_parm, err = build_sku_grid_json(strLuaDEID, sku.item_code, sku.storer) + if err then + return 1, "鐢熸垚SKU_GRID_PARM澶辫触: " .. err + end + sku.sku_grid_parm = sku_grid_parm -- 鐩存帴鏇存柊SKU瀵硅薄鐨勫睘鎬�+ + -- SKU涓嶅瓨鍦紝鍒涘缓鏂拌褰�+ if existingSKU == 'no' then + lua.DebugEx(strLuaDEID, "SKU涓嶅瓨鍦紝鍒涘缓鏂拌褰�); + local createnRet, strRetInfo = m3.CreateDataObj(strLuaDEID, sku) + if createnRet ~= 0 then + return 1, "鍒涘缓SKU澶辫触: 淇℃伅锛� .. strRetInfo end else -- SKU宸插瓨鍦紝鏇存柊璁板綍 local update_sku_obj = {{ - id = existing_sku.id, + id = sku.id, attrs = {{ + attr = "S_CTD_CODE", + value = CONST_CTD_CODE + }, { attr = "S_ITEM_NAME", value = sku.item_name }, { @@ -632,6 +389,9 @@ }, { attr = "S_SHORT_NAME", value = sku.short_name + }, { + attr = "S_NOTE", + value = sku.note }, { attr = "S_ABCTYPE", value = sku.abc_type @@ -675,12 +435,21 @@ attr = "S_UDF05", value = sku.udf05 }, { + attr = "S_UDF06", + value = sku.udf06 + }, { + attr = "S_UDF07", + value = sku.udf07 + }, { + attr = "S_UDF08", + value = sku.udf08 + }, { 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) + lua.DebugEx(strLuaDEID, "鏇存柊SKU瀵硅薄缁撴灉", nRet .. " " .. strRetInfo); if nRet ~= 0 then return 1, "鏇存柊SKU灞炴�澶辫触: " .. strRetInfo end @@ -697,29 +466,28 @@ 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} - - 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 + -- 澶勭悊SKU_UPC鏉$爜锛堜慨鏀瑰悗鐗堟湰锛�+ -- 鍦╟reate_sku鍑芥暟涓鐞哠KU_UPC鏉$爜鐨勯儴鍒嗕慨鏀逛负锛�+ local upc_code = sku_input_data.upc + if upc_code and upc_code ~= '' then + nRet, strRetInfo = create_or_update_sku_upc(strLuaDEID, sku.storer, sku.item_code, upc_code) + if nRet ~= 0 then + -- lua.debugex(strLuaDEID, "澶勭悊SKU_UPC澶辫触", strRetInfo) + return 1, "澶勭悊SKU_UPC澶辫触: " .. strRetInfo end + -- lua.debugex(strLuaDEID, "澶勭悊SKU_UPC鎴愬姛", upc_code) end - -- 澶勭悊SKU_GridBox_Parm鏂欑鏍煎弬鏁�- nRet, strRetInfo = create_or_update_sku_gridbox(strLuaDEID, sku, sku_input_data) + local nRet, strRetInfo = create_or_update_sku_gridbox(strLuaDEID, sku, sku_input_data) if nRet ~= 0 then return 1, "澶勭悊SKU_GridBox_Parm澶辫触: " .. strRetInfo end - return 0 end -- Main鍑芥暟 function SKU_Sync(strLuaDEID) + m3.PrintLuaDEInfo(strLuaDEID) -- 鍒濆鍖栨渶缁堢粨鏋� local FinalRes = Create_result() -- Gitblit v1.9.1