--[[ 编码: GT-100-13 名称: 国自任务回报 作者: LZH 入口函数:TaskStatus 功能说明: 接收国自的任务返回状态 输入数据: { "feed_no": "xxx", 唯一码,用于接口校验,默认生成GUID "feed_type": "xxx", 反馈类型 1=任务开始;2=任务完成;3=任务异常;4=任务取消;5=任务更改(待定)6=货物节点 "task_type": "xxx" , 任务类型 1=货物入库;2=货物出库;3=托盘组入库;4=托盘组出库;5=移动(不过库位);6=移库 "task_no": "xxx", 任务号 单托盘唯一任务号 "mat_code": "xxx", 货物RFID "cur_station_no": "xxx", 当前位置 "weight": "xxx", 称重重量 "feed_time": "xxx" 反馈时间 } 处理逻辑 -- step1 解析接口传递的 datajson 参数 -- step2 校验必传字段是否为空,为空则报错 -- step3 反馈类型 2 设置任务完成 3 报错 4 设置任务状态为取消并解锁 变更历史: V1.0 LZH 20250121 feed_type = 3则更新工位异常信息 V2.0 LZH 20250213 新增称重重量字段和类型 --]] require("WMS-Equipment") wms_cntr = require("wms_container") require("GT-Base") wms_task = require("wms_task") function GZTaskStatus(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 -- step2 判断 必填项 是否都有值?没值报错返回 local task_no = in_date.task_no if (task_no == nil or task_no == '') then lua.Error(strLuaDEID, debug.getinfo(1), "任务号不能为空!") end local cntr_code = in_date.cntr_code if (cntr_code == nil or cntr_code == '') then lua.Error(strLuaDEID, debug.getinfo(1), "RFID不能为空!") end local feed_type = tonumber(in_date.feed_type) if (feed_type == nil) then lua.Error(strLuaDEID, debug.getinfo(1), "反馈类型不能为空!") end local task_type = tonumber(in_date.task_type) if (task_type == nil) then lua.Error(strLuaDEID, debug.getinfo(1), "任务类型不能为空!") end local cur_station_no = in_date.cur_station_no -- 当前位置 -- V2.0 LZH 新增重量字段 local weight = in_date.weight -- 称重重量 local err_msg = in_date.err_msg -- 反馈类型为3时传的工位异常信息 -- 获取任务中的容器编码和起始货位编码 local task nRet, task = wms_task.GetInfo(strLuaDEID, task_no) if (nRet ~= 0) then return end if (task.bs_state == 3) then lua.Error(strLuaDEID, debug.getinfo(1), "任务已完成!") elseif (task.bs_state == 4) then lua.Error(strLuaDEID, debug.getinfo(1), "任务异常!") end -- 反馈类型 2 设置任务完成 3 报错 4 设置任务状态为取消并解锁 if (feed_type == 2) then lua.Debug(strLuaDEID, debug.getinfo(1), 'task:', task) lua.Debug(strLuaDEID, debug.getinfo(1), '国自任务反馈参数:', in_date) -- 校验终点位置是否传参 if (task.op_name == '粉料入库' or task.op_name == '立库出库' or task.op_name == '采购退货' or task.op_name == '呼叫空托') then if (cur_station_no == nil or cur_station_no == '') then lua.Error(strLuaDEID, debug.getinfo(1), "终点未传参!") end cur_station_no = wms_base.Get_sConst(strLuaDEID, cur_station_no) lua.Debug(strLuaDEID, debug.getinfo(1), 'cur_station_no:', cur_station_no) task.end_loc_code = cur_station_no lua.Debug(strLuaDEID, debug.getinfo(1), 'task:', task) nRet, strRetInfo = wms_task.Update(strLuaDEID, task) if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "更新任务终点失败!" .. strRetInfo) end end -- 出库无需绑定终点 if (task.op_name == '立库出库' or task.op_name == '呼叫空托' or task.op_name == '采购退货' or task.op_name == '点对点出库') then -- 容器货位解绑 nRet, strRetInfo = wms_wh.Loc_Container_Unbinding(strLuaDEID, task.start_loc_code, cntr_code, "绑定解绑方法-系统", "完成") if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), '货位容器解绑失败!' .. strRetInfo) end elseif (task.op_name == '移库') then -- 容器货位解绑 nRet, strRetInfo = wms_wh.Loc_Container_Unbinding(strLuaDEID, task.start_loc_code, cntr_code, "绑定解绑方法-系统", "完成") if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), '货位容器解绑失败!' .. strRetInfo) end -- 容器货位绑定 nRet, strRetInfo = wms_wh.Loc_Container_Binding(strLuaDEID, task.end_loc_code, cntr_code, "绑定解绑方法-系统", "完成") if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), '货位容器绑定失败!' .. strRetInfo) end else -- 容器货位绑定 nRet, strRetInfo = wms_wh.Loc_Container_Binding(strLuaDEID, task.end_loc_code, cntr_code, "绑定解绑方法-系统", "完成") if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), '货位容器绑定失败!' .. strRetInfo) end end -- 强制任务完成 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 = "国自搬运完成" 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 == 3) then if (cur_station_no == nil or cur_station_no == '') then lua.Error(strLuaDEID, debug.getinfo(1), '异常工位不能为空!') end cur_station_no = wms_base.Get_sConst(strLuaDEID, cur_station_no) -- 根据工位修改异常信息 local condition = "S_START_LOC = '" .. cur_station_no .. "'" local strSetAttr = "S_ERR_MSG = '" .. err_msg .. "'" nRet, strRetInfo = mobox.updateDataAttrByCondition(strLuaDEID, "GT_PDA_Station", condition, strSetAttr) if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "工位异常信息失败!" .. strRetInfo) end elseif (feed_type == 4) then lua.Debug(strLuaDEID, debug.getinfo(1), 'task:', task) lua.Debug(strLuaDEID, debug.getinfo(1), '国自任务反馈参数:', in_date) if (task.op_name == '国自空托回库') then -- 给取消的任务解锁 nRet, strRetInfo = wms.wms_UnlockByTask(strLuaDEID, task_no) if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "wms_UnlockByTask 失败! " .. strRetInfo) end -- 设置任务状态为取消 local condition = "S_CODE = '" .. task_no .. "'" local strSetAttr = "N_B_STATE = " .. wms_base.Get_nConst(strLuaDEID, "任务状态-取消") .. ", S_B_STATE = '取消'" nRet, strRetInfo = mobox.updateDataAttrByCondition(strLuaDEID, "Task", condition, strSetAttr) if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "设置任务状态失败!" .. strRetInfo) end -- 设置作业状态为取消 local condition = "S_CODE = '" .. task.op_code .. "'" strSetAttr = "N_B_STATE = " .. wms_base.Get_nConst(strLuaDEID, "作业状态-取消") .. ", S_B_STATE = '取消'" nRet, strRetInfo = mobox.updateDataAttrByCondition(strLuaDEID, "Operation", condition, strSetAttr) if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "设置作业状态失败!" .. strRetInfo) end end elseif (feed_type == 6) then if (cur_station_no == nil or cur_station_no == '') then lua.Error(strLuaDEID, debug.getinfo(1), '节点工位不能为空!') end -- local cur_station_name = wms_base.GetDictItemName(strLuaDEID, "GT_TaskNode", cur_station_no) -- 增加 任务动作 对象 local task_action = m3.AllocObject(strLuaDEID, "Task_Action") task_action.task_code = task.code task_action.action_code = cur_station_no task_action.action = cur_station_name task_action.eq_code = "system" task_action.eq_type_name = cur_station_name nRet, strRetInfo = m3.CreateDataObj(strLuaDEID, task_action) if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), '创建【任务动作】对象失败!' .. strRetInfo) end -- V2.0 LZH 新增类型8 入库重量上报 elseif (feed_type == 8) then lua.Debug(strLuaDEID, debug.getinfo(1), 'task:', task) lua.Debug(strLuaDEID, debug.getinfo(1), '国自任务反馈参数:', in_date) -- 获取容器货品明细信息 local strCondition = "S_CNTR_CODE = '" .. cntr_code .. "'" local cg_detail nRet, cg_detail = m3.GetDataObjByCondition(strLuaDEID, "CG_Detail", strCondition) if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), '获取容器货品信息失败!' .. cg_detail) end -- 修改入库单据行的称重数量信息 strCondition = "S_SERIAL_NO = '" .. cg_detail.serial_no .. "'" local strSetAttr = "S_WEIGHT = '" .. weight .. "'" nRet, strRetInfo = mobox.updateDataAttrByCondition(strLuaDEID, "GT_Label_Crad", strCondition, strSetAttr) if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "更新【容器】锁状态失败!" .. strRetInfo) end end end