| | |
| | | --[[ |
| | | 编码: GK-API-001 |
| | | 名称: 盘点计划同步 |
| | | 作者: HAN |
| | | 作者: Yuanfeng |
| | | 日期: 2025-1-29 |
| | | |
| | | 入口函数: SKU_Sync |
| | |
| | | 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微孔涂层髋臼杯62mm</v1:skuName> |
| | | <v1:skuDec>Exceed ABT微孔涂层髋臼杯62mm</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第三代单髁膝关节骨水泥型解剖型标准胫骨底板 左膝内侧 Size B</v1:skuName> |
| | | <v1:skuDec>Oxford第三代单髁膝关节骨水泥型解剖型标准胫骨底板 左膝内侧 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第三代单髁膝关节骨水泥型解剖型标准胫骨底板 左膝内侧 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第三代单髁膝关节骨水泥型解剖型标准胫骨底板 左膝内侧 Size B</v1:skuName> |
| | | <v1:skuDec>Oxford第三代单髁膝关节骨水泥型解剖型标准胫骨底板 左膝内侧 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第三代单髁膝关节骨水泥型解剖型标准胫骨底板 左膝内侧 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)同步逻辑进行优化, |
| | | 解决了在不同cid_type变更场景下的料格处理问题,确保数据同步的准确性和完整性。 |
| | | |
| | | ]] wms_base = require("wms_base") |
| | | xml = require("oi_base_xml") |
| | | mobox = require("OILua_JavelinExt") |
| | | m3 = require("oi_base_mobox") |
| | | |
| | | -- 创建或更新SKU_UPC条码记录(重构版) |
| | | -- @param strLuaDEID: Lua数据交换ID |
| | | -- @param storer: 货主编码 |
| | | -- @param item_code: SKU编码 |
| | | -- @param upc_code: UPC条码 |
| | | -- @return: 返回两个值 (错误码, 错误信息/成功信息) |
| | | -- 创建或更新SKU_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为空,跳过处理" -- 修改为返回0表示跳过 |
| | | end |
| | | |
| | | -- 2. 检查该SKU的UPC记录是否已存在(三字段主键检查) |
| | | 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作为截止范围,而是检查所有maxCount~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 |
| | | -- 创建统一返回结果(修改后版本,移除error字段) |
| | | function Create_result(flag, code, msg) |
| | | return { |
| | |
| | | |
| | | -- 创建或更新GK_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) |
| | |
| | | value = proline_name |
| | | }} |
| | | }} |
| | | |
| | | nRet, strRetInfo = mobox.updateDataObj(strLuaDEID, "GK_PROLINE", lua.table2str(update_proline_obj)) |
| | | if nRet ~= 0 then |
| | | return 1, "更新GK_PROLINE失败: " .. strRetInfo |
| | |
| | | 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函数 |
| | | -- 现在完全基于数据库中的实际料格记录生成JSON |
| | | -- @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. 查询该SKU所有现有的料箱格记录 |
| | | 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字符串,在SKU 创建的时候插入json数据 |
| | | 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 是数据库定义的数据模型sku,也就是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) |
| | | -- 只有当值有效时才添加到JSON |
| | | 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. 转换为JSON字符串 |
| | | local json_str = lua.table2str(grid_def) |
| | | -- -- lua.debugex(strLuaDEID, "生成的grid_json", json_str) |
| | | |
| | | return json_str |
| | | end |
| | | -- 创建或更新SKU主数据 |
| | | -- @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 .. "的适配料格cidtype不允许为空!" |
| | | 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 .. "的适配料格cidtype不允许为空!" |
| | | 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 |
| | |
| | | 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. 基于数据库实际记录生成JSON(不再依赖传入的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 |
| | | }, { |
| | |
| | | }, { |
| | | attr = "S_SHORT_NAME", |
| | | value = sku.short_name |
| | | }, { |
| | | attr = "S_NOTE", |
| | | value = sku.note |
| | | }, { |
| | | attr = "S_ABCTYPE", |
| | | value = sku.abc_type |
| | |
| | | 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 |
| | |
| | | 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条码(修改后版本) |
| | | -- 在create_sku函数中处理SKU_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() |
| | | |