--[[ 编码: GT-40-54 名称: 作业-立库出库-任务完成 作者:HAN 日期:2024-5-10 版本: V1.0 场景:作业中的任务完成后触发这个脚本 函数: TaskFinish 功能: -- 如果任务类型为立库出库搬运 则一段任务输送机搬运到线边库对应的接驳位,二段任务AGV从接驳位到终点线边库 更改记录: --]] wms_op = require("wms_operation") wms_cntr = require("wms_container") require("GT_InAndOutboundPolicies") require("GT-Base") function LKTaskFinish(strLuaDEID) local nRet, strRetInfo -- 获取当前作业对象 local operation nRet, operation = m3.GetSysCurEditDataObj(strLuaDEID, "Operation") if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), operation) end lua.Debug(strLuaDEID, debug.getinfo(1), 'operation:', operation) -- 获取任务对象 local task nRet, task = m3.SysInputParamToDataObj(strLuaDEID, "Task") if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), task) end lua.Debug(strLuaDEID, debug.getinfo(1), 'task:', task) -- 获取扩展数据参数 local ext_data = json.decode(operation.ext_data) local item_type = ext_data.item_type -- 物料类型 local delivery_no = ext_data.delivery_no -- 业务单号为 出库单号 local mes_task_no = ext_data.mes_task_no local wmsLot = ext_data.wmsLot lua.Debug(strLuaDEID, debug.getinfo(1), 'ext_data', ext_data) if (task.type == wms_base.Get_nConst(strLuaDEID, "任务类型-立库出库搬运") and item_type ~= '钢丝') then -- 创建AGV搬运任务 local new_task = m3.AllocObject(strLuaDEID, "Task") new_task.op_code = operation.code new_task.op_name = operation.op_def_name new_task.factory = operation.factory new_task.cntr_code = operation.cntr_code -- 起点为上一个任务的终点 new_task.start_wh_code = task.end_wh_code new_task.start_area_code = task.end_area_code new_task.start_loc_code = task.end_loc_code -- 终点为作业的终点 new_task.end_wh_code = operation.end_wh_code new_task.end_area_code = operation.end_area_code new_task.end_loc_code = operation.end_loc_code new_task.type = wms_base.Get_nConst(strLuaDEID, "任务类型-AGV出库搬运") new_task.schedule_type = wms_base.Get_nConst(strLuaDEID, "调度类型-AGV") -- 设置调度类型 nRet, new_task = m3.CreateDataObj(strLuaDEID, new_task) if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "创建人工搬运任务失败!" .. new_task) end -- 给上一个任务解锁 nRet, strRetInfo = wms.wms_UnlockByTask(strLuaDEID, task.code) if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "wms_UnlockByTask 失败! " .. strRetInfo) end -- 通过容器获取物料信息 local cg_detail_list, cg_detail nRet, cg_detail_list = wms_cntr.Get_Container_Goods(strLuaDEID, task.cntr_code) nRet, cg_detail = m3.ObjAttrStrToLuaObj("CG_Detail", lua.table2str(cg_detail_list[1].attrs)) 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 strCondition = "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", strCondition, "T_CREATE DESC") if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "获取入库单据头信息失败!") end -- 下发任务给AGV local data = { taskData = { taskNum = new_task.code, pickStation = task.end_loc_code, dropStation = operation.end_area_code, taskType = 1, carrierType = "RC", priority = 1, wmsTaskNo = mes_task_no, level = incoming_Info.level, produceTime = incoming_Info.product_date, tyreType = "", supplier = incoming_Info.vendor, receiveLot = cg_detail.batch_no, subpool = "", source = "YCL", wmsLot = wmsLot }, partData = { rfid = task.cntr_code, lotNumber = cg_detail.serial_no, partNumber = cg_detail.item_code, partDesc = cg_detail.item_code, partType = nil, weight = cg_detail.qty, unit = cg_detail.wu, maturityTime = nil, productionTime = nil, stewingTime = nil, overdueTime = nil } } -- 调用AGV任务下发 local url = wms_base.Get_sConst(strLuaDEID, "AGV-url") local strurl = url .. "/CreateTask" local strHeader = "" local strBody = data nRet, strRetInfo = CreateInterfaceExc(strLuaDEID, strurl, strHeader, strBody, "AGV", "任务创建") if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "调用WCS接口失败!" .. strRetInfo) end -- 设置状态未推送 wms_task.SetStateByCode(strLuaDEID, new_task.code, "任务状态-已推送") else -- 如果完成的是AGV搬运任务,设置作业完成 nRet, strRetInfo = wms_op.SetFinish(strLuaDEID, operation.code) if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "设置作业编号='" .. operation.code .. "' 的作业完成失败!" .. strRetInfo) end lua.Debug(strLuaDEID, debug.getinfo(1), 'item_type:', item_type) if (item_type ~= '钢丝') then -- 胶料、粉料2段任务完成则直接扣库存解绑 -- 容器货位解绑 nRet, strRetInfo = wms_wh.Loc_Container_Unbinding(strLuaDEID, task.end_loc_code, operation.cntr_code, "绑定解绑方法-系统", "强制完成") if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), '货位容器解绑失败!' .. strRetInfo) end -- 减库区/库量表 (通过CG_Detail) nRet = wms.wms_ResetInventory("Area", task.end_area_code) -- 容器解锁 local container nRet, container = wms_cntr.GetInfo(strLuaDEID, operation.cntr_code) if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), '获取容器对象失败!' .. container) end nRet, strRetInfo = wms_cntr.SetLock(strLuaDEID, container, "锁类型-无", "无") if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), '托盘容器解锁失败!' .. strRetInfo) end -- 设置出库单明细状态为完成 local strCondition = "S_DO_NO = '" .. delivery_no .. "'" local strSetSQL_update = " S_STATE = '完成'" nRet, strRetInfo = mobox.updateDataAttrByCondition(strLuaDEID, "GT_SO_Detail", strCondition, strSetSQL_update) if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "修改出库单据状态失败!" .. strRetInfo) end -- 设置出库单状态为完成 strCondition = "S_DO_NO = '" .. delivery_no .. "'" strSetSQL_update = " S_STATE = '完成'" nRet, strRetInfo = mobox.updateDataAttrByCondition(strLuaDEID, "GT_Stock_Out", strCondition, strSetSQL_update) if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "修改出库单据状态失败!" .. strRetInfo) end -- 删除容器货品明细记录 strCondition = "S_CNTR_CODE = '" .. operation.cntr_code .. "'" nRet, strRetInfo = mobox.deleteDataObject(strLuaDEID, "CG_Detail", strCondition) if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), strRetInfo) end end end end