--[[ 编码: GT-100-14 名称: AGV任务回报 作者: LZH 入口函数:TaskStatus 功能说明: 接收AGV的任务返回状态 输入数据: { "taskNum": "任务号", "taskStatus": 订单状态:1 开始执行,2 任务完成 ,3 开始取货,4 取货完成,5 开始放货,6 放货完成 ,7 任务取消,8 强制完成 } 处理逻辑 -- step1 解析接口传递的 datajson 参数 -- step2 校验必传字段是否为空,为空则报错 -- step3 反馈类型 2 设置任务完成 4 容器货品解绑 6 容器货品绑定 变更历史: V1.1 LZH 20250506 立库出库和粉料出库AGV取货完成之后直接回传GTWMS --]] require("WMS-Equipment") wms_cntr = require("wms_container") wms_wh = require("wms_wh") require("GT-Base") wms_task = require("wms_task") function AGVTaskStatus(strLuaDEID) local nRet, in_date, strRetInfo -- 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), 'AGV任务回报参数:', in_date) -- step2 判断 必填项 是否都有值?没值报错返回 local task_no = in_date.taskNum if (task_no == nil or task_no == '') then lua.Error(strLuaDEID, debug.getinfo(1), "任务号不能为空!") end local feed_type = tonumber(in_date.taskStatus) if (feed_type == nil) then lua.Error(strLuaDEID, debug.getinfo(1), "反馈类型不能为空!") end -- 获取任务信息 local task, operation nRet, task = wms_task.GetInfo(strLuaDEID, task_no) if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), task) end -- 获取作业信息 local condition = "S_CODE = '" .. task.op_code .. "'" nRet, operation = m3.GetDataObjByCondition(strLuaDEID, "Operation", condition) if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), operation) end -- 反馈类型 2 设置任务完成 4 容器货品解绑 6 容器货品绑定 if (feed_type == 2) then -- 设置任务完成 nRet, strRetInfo = wms.wms_TaskFinish(strLuaDEID, task_no) if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "任务编码='" .. task_no .. "'的任务设置完成失败!" .. strRetInfo) end -- 增加 任务动作 对象 local task_action = m3.AllocObject(strLuaDEID, "Task_Action") task_action.task_code = task_no task_action.action_code = 2 task_action.action = "AGV搬运完成" task_action.eq_code = "system" task_action.eq_type_name = '完成' nRet, strRetInfo = m3.CreateDataObj(strLuaDEID, task_action) if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), '创建【任务动作】对象失败!' .. strRetInfo) end elseif (feed_type == 4) then -- V1.1 LZH 20250506 立库出库和粉料出库AGV取货完成之后直接回传GTWMS -- 立库出库的二段AGV任务是托盘离开货位则扣除库存 if (task.op_name == '立库出库' or task.op_name == '粉料出库') then if (task.op_name == '粉料出库') then nRet, strRetInfo = wms_wh.Loc_Container_Unbinding(strLuaDEID, task.start_loc_code, operation.cntr_code, "绑定解绑方法-系统", "完成") if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), '货位容器解绑失败!' .. strRetInfo) end end -- 获取扩展数据参数 local ext_data = json.decode(operation.ext_data) local delivery_no = ext_data.delivery_no -- 业务单号为 出库单号 --获取出库单信息 local stock_out condition = "S_DO_NO = '" .. delivery_no .. "'" nRet, stock_out = m3.GetDataObjByCondition(strLuaDEID, "GT_Stock_Out", condition) if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), stock_out) end -- 获取容器货品明细 local cg_detail condition = "S_CNTR_CODE = '" .. operation.cntr_code .. "'" nRet, cg_detail = m3.GetDataObjByCondition(strLuaDEID, "CG_Detail", condition) if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), cg_detail) end -- 获取入库单据行信息 local label_crad local strCondition = "S_SERIAL_NO = '" .. cg_detail.serial_no .. "'" if (tonumber(cg_detail.is_tl) == 1) then nRet, label_crad = m3.GetDataObjByCondition(strLuaDEID, "GT_ROM", strCondition, "T_CREATE DESC") if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1),"获取流水号信息失败!" .. label_crad) end else nRet, label_crad = m3.GetDataObjByCondition(strLuaDEID, "GT_Label_Crad", strCondition, "T_CREATE DESC") if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1),"获取流水号信息失败!" .. label_crad) end end -- 获取入库单据头信息 local incoming_Info condition = "S_DELIVERY_NO = '" .. label_crad.delivery_no .. "' AND N_DELIVERY_ROW_NO = '" .. label_crad.delivery_row_no .. "'" nRet, incoming_Info = m3.GetDataObjByCondition(strLuaDEID, "GT_Incoming_Info", condition, "T_CREATE DESC") if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "获取入库单据头信息失败!" .. incoming_Info) end -- if (stock_out.type == '人工录入') then -- -- 创建【GTWMS同步记录】 -- local sys_record = m3.AllocObject(strLuaDEID, "GTWMS_SYNC_RECORD") -- sys_record.delivery_no = incoming_Info.delivery_no -- sys_record.delivery_row_no = incoming_Info.delivery_row_no -- sys_record.task_no = delivery_no -- sys_record.lpn = cg_detail.serial_no -- sys_record.rfid = operation.cntr_code -- sys_record.lpnweight = cg_detail.qty -- sys_record.sku = cg_detail.item_code -- sys_record.batch_no = cg_detail.batch_no -- sys_record.grade = incoming_Info.level -- sys_record.type = "出库回传" -- lua.Debug(strLuaDEID, debug.getinfo(1), 'sys_record', sys_record) -- nRet, sys_record = m3.CreateDataObj(strLuaDEID, sys_record) -- if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), 'mobox 创建【GTWMS同步记录】对象失败!' .. sys_record) end -- else -- 出库结果回传 local data local source = "GTWMS出库回传" nRet, data = StorageResult(strLuaDEID, operation.code, source) if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "出库结果回传失败!" .. data) end lua.Debug(strLuaDEID, debug.getinfo(1), 'data', data) -- 调用GT-WMS的回传接口 local url = wms_base.Get_sConst(strLuaDEID, "GTWMS-url") local strurl = url local strHeader = "" local strBody = { application = "GITI", code = "WCS_SO_WMS", data = data } nRet, strRetInfo = CreateInterfaceExc(strLuaDEID, strurl, strHeader, strBody, "GTWMS", source) if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "调用接口失败!" .. strRetInfo) end -- end end elseif (feed_type == 6) then if (task.op_name == '粉料入库') then nRet, strRetInfo = wms_wh.Loc_Container_Binding(strLuaDEID, task.end_loc_code, operation.cntr_code, "绑定解绑方法-系统", "完成") if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), '货位容器解绑失败!' .. strRetInfo) end end elseif (feed_type == 7) then end end