-- 库存查询 --[ -- 1、获取巷道货位总数 -- 2、获取满货位总数 -- 3、(满货位总数 / 巷道总数)* 100 = 满货位百分比 -- 4、判断满货位库存是否达到80%,没达到则返回可入库巷道 --] local function StockInquiry(strLuaDEID) -- 获取未冻结的巷道 local strCondition = "N_LOCK_STATE = 0" local nRet, roadway = m3.QueryDataObject(strLuaDEID, "Roadway", strCondition) if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), '查询巷道信息失败' .. roadway) end if (roadway == nil or roadway == '') then lua.Error(strLuaDEID, debug.getinfo(1), '没有可入库的巷道!') end -- 获取字典定义的移库比例 local strRetInfo nRet, strRetInfo = mobox.getDictItemIInfo("GT_LK_RATIO") if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "getDictItemIInfo 失败!" .. strRetInfo) end strRetInfo = json.decode(strRetInfo) local item_ratio = tonumber(strRetInfo[1].name) -- 字典定义的巷道安全库存比例 local str = '' for i = 1, #roadway do local attrs = roadway[i].attrs attrs = m3.KeyValueAttrsToObjAttr(attrs) -- 获取巷道货位总数 strCondition = "S_AREA_CODE = 'LK' AND N_ROADWAY = " .. attrs.N_ROADWAY nRet, strRetInfo = mobox.getDataObjCount(strLuaDEID, "Location", strCondition) if (nRet ~= 0) then return 2, "getDataObjCount 失败!" .. strRetInfo end local hw_count = tonumber(strRetInfo) -- 指定巷道的货位总数 lua.Debug(strLuaDEID, debug.getinfo(1), "hw_count", hw_count) strCondition = "S_AREA_CODE = 'LK' AND N_CURRENT_NUM <> 0 AND N_ROADWAY = " .. attrs.N_ROADWAY nRet, strRetInfo = mobox.getDataObjCount(strLuaDEID, "Location", strCondition) if (nRet ~= 0) then return 2, "getDataObjCount 失败!" .. strRetInfo end local mhw_count = tonumber(strRetInfo) -- 指定巷道的满货位总数 lua.Debug(strLuaDEID, debug.getinfo(1), "mhw_count", mhw_count) local mhw_ratio = (mhw_count / hw_count) * 100 -- 满货位占比 if (mhw_ratio == nil) then return 1, "计算失败!巷道:" .. attrs.N_ROADWAY .. " 满货位数量:" .. mhw_count .. "货位总数:" .. hw_count end if (mhw_ratio <= item_ratio) then str = str .. attrs.N_ROADWAY .. "," end end -- 去除最后一个, str = lua.trim_laster_char(str) lua.Debug(strLuaDEID, debug.getinfo(1), "str", str) return 0, str end --[[ 编码: GT-100-06 名称: GT-WMS 作者:LZH 入口函数: CreateROM 功能说明: GT-WMS下发退料信息给 GZ-WMS系统,GZ-WMS系统创建相关数据绑定和入库作业 输入数据: { "delivery_no": "xxx", 收货单号 "delivery_row_no": "xxx", 收货单行号 "serial_no": "xxx", 流水号 "batch_no": "xxx", 批次号 "qty": xxx, 重量 "item_code": "xxx", 物料编码 "product_date": "xxx", 生产日期 "storage_loc": "xxx", 库位 "wh_code": "xxx", 仓库编号 "is_bonded": "xxx", 是否保税 "cntr_code": "xxx", 托盘号 "start_loc_code": "xxx", 起点 "item_state": "xxx", 质量状态 "req_no": "xxx", 唯一标识 "inbound_policy": 3, 胶料入库策略 "wheel_type_rot": "xxx", 轮型/左右旋 "vendor":"xxx", 供应商 "remark1": "", -- 备注 暂未启用 "remark2": "", -- 备注 暂未启用 "remark3": "", -- 备注 暂未启用 "remark4": "" -- 备注 暂未启用 } 处理逻辑 -- step1 解析接口传递的 datajson 参数 -- step2 校验必传字段是否为空,为空则报错 -- step3 容器货品绑定 -- step4 创建退料单 -- step5 起点不为空则 货位容器绑定 并创建AGV两段搬运任务,一段从起点到起点库区绑定的接驳位,一段从接驳位到立库 变更记录: V1.1 LZH 20250417 加上供应商字段 --]] m3 = require("oi_base_mobox") json = require("json") mobox = require("OILua_JavelinExt") require("WMS-Equipment") wms_cntr = require("wms_container") wms_wh = require("wms_wh") require("GT-Base") function CreateROM(strLuaDEID) local nRet, strRetInfo, in_date -- step1 获取接口数据 nRet, in_date = m3.GetSysDataJson(strLuaDEID) if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "WCStoreCallback 无法获取数据包!" .. in_date) end lua.Debug(strLuaDEID, debug.getinfo(1), '退料入库下发参数:', in_date) -- step2 判断是否都有值?没值报错返回 local delivery_no = in_date.delivery_no if (delivery_no == nil or delivery_no == '') then lua.Error(strLuaDEID, debug.getinfo(1), "收货单号不能为空!") end local delivery_row_no = in_date.delivery_row_no if (delivery_row_no == nil) then lua.Error(strLuaDEID, debug.getinfo(1), "收货单行号不能为空!") end local serial_no = in_date.serial_no if (serial_no == nil or serial_no == '') then lua.Error(strLuaDEID, debug.getinfo(1), "流水号不能为空!") end local batch_no = in_date.batch_no if (batch_no == nil or batch_no == '') then lua.Error(strLuaDEID, debug.getinfo(1), "批次号不能为空!") end local qty = tonumber(in_date.qty) if (qty == nil) then lua.Error(strLuaDEID, debug.getinfo(1), "托盘重量不能为空!") end local item_code = in_date.item_code if (item_code == nil or item_code == '') then lua.Error(strLuaDEID, debug.getinfo(1), "物料编码不能为空!") end local product_date = in_date.product_date if (product_date == nil or product_date == '') then lua.Error(strLuaDEID, debug.getinfo(1), "生产日期不能为空!") end local wh_code = in_date.wh_code if (wh_code == nil or wh_code == '') then lua.Error(strLuaDEID, debug.getinfo(1), "仓库编号不能为空!") end local is_bonded = in_date.is_bonded if (is_bonded == nil or is_bonded == '') then lua.Error(strLuaDEID, debug.getinfo(1), "是否保税不能为空!") end local item_state = in_date.item_state if (item_state == nil or item_state == '') then lua.Error(strLuaDEID, debug.getinfo(1), "质量状态不能为空!") end local wheel_type_rot = in_date.wheel_type_rot local storage_loc = in_date.storage_loc local cntr_code = in_date.cntr_code local start_loc_code = in_date.start_loc_code local req_no = in_date.req_no local inbound_policy = in_date.inbound_policy local vendor = in_date.vendor local remark1 = in_date.remark1 local remark2 = in_date.remark2 local remark3 = in_date.remark3 local remark4 = in_date.remark4 -- 获取物料信息的物料种类 local item_type, material nRet, item_type, material = GT_Get_ItemType(strLuaDEID, item_code) if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), item_type) end lua.Debug(strLuaDEID, debug.getinfo(1), '物料信息', material) -- step3 容器货品绑定 local cg_detail = m3.AllocObject(strLuaDEID, "CG_Detail") cg_detail.cntr_code = cntr_code cg_detail.batch_no = batch_no cg_detail.item_code = item_code cg_detail.item_name = material.item_name cg_detail.qty = qty cg_detail.uom = 'kg' cg_detail.serial_no = serial_no cg_detail.is_tl = 1 -- 退料标识 0 正常 1 退料 lua.Debug(strLuaDEID, debug.getinfo(1), 'cg_detail', cg_detail) nRet, cg_detail = m3.CreateDataObj(strLuaDEID, cg_detail) if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), 'mobox 创建【容器货品明细】对象失败!' .. cg_detail) end -- step4 创建退料单 -- 获取一个初始的【退料单】数据对象 local rom = m3.AllocObject(strLuaDEID, "GT_ROM") -- 生成作业编码 local strCode = '' local strHeader = 'TL' .. os.date("%y%m%d") .. '-' nRet, strCode = mobox.getSerialNumber("退料", strHeader, 5) if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), '申请退料单编码失败!' .. strCode) end rom.no = strCode rom.delivery_no = delivery_no rom.delivery_row_no = delivery_row_no rom.item_code = item_code rom.product_date = product_date rom.batch_no = batch_no rom.item_state = item_state rom.qty = qty rom.serial_no = serial_no rom.wheel_type_rot = wheel_type_rot rom.wh_code = wh_code rom.storage_loc = storage_loc rom.is_bonded = is_bonded rom.cntr_code = cntr_code rom.start_loc_code = start_loc_code rom.req_no = req_no rom.inbound_policy = inbound_policy rom.vendor = vendor if (start_loc_code == nil or start_loc_code == '') then nRet, rom = m3.CreateDataObj(strLuaDEID, rom) if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), 'mobox 创建【退料单】对象失败!' .. rom) end else rom.state = "执行" nRet, rom = m3.CreateDataObj(strLuaDEID, rom) if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), 'mobox 创建【退料单】对象失败!' .. rom) end local ext_table = {} ext_table.is_insulate = material.is_insulate -- V1.3 获取巷道库存未达到 80% 的可入库巷道 nRet, strRetInfo = StockInquiry(strLuaDEID) if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), strRetInfo) end ext_table.roadway_inventory = strRetInfo -- 作业扩展数据存入这个巷道库存字符串,里面是库存未超过80%的巷道 -- 获取起点信息 local loc_start nRet, loc_start = wms_wh.GetLocInfo(start_loc_code) if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), 'WMS_GetLocInfo失败!' .. loc_start) end -- step5 创建作业 local operation = m3.AllocObject(strLuaDEID, "Operation") operation.start_wh_code = loc_start.wh_code operation.start_area_code = loc_start.area_code operation.start_loc_code = loc_start.code operation.op_type = wms_base.Get_nConst(strLuaDEID, "作业类型-入库") operation.op_def_name = "退料入库" operation.cntr_code = cntr_code ext_table.batch_no = batch_no -- 批次号 ext_table.item_code = item_code -- 物料编码 ext_table.item_type = item_type -- 物料类型 ext_table.rom_no = strCode -- 退料单号 ext_table.is_sign = "AGV搬运" -- 退料单号 ext_table.area_code = material.area_code -- 库区 ext_table.isothermal = material.isothermal -- 是否恒温 operation.ext_data = lua.table2str(ext_table) nRet, operation = m3.CreateDataObj(strLuaDEID, operation) if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), '创建【作业】失败!' .. operation) end lua.Debug(strLuaDEID, debug.getinfo(1), "作业创建后信息", operation) end end