--[[ 编码: GT-40-36 名称: 作业启动-立库入库 作者: LZH 入口函数:OperationStart 功能说明: -- 计算出入库终点货位 -- 在作业下面创建任务类型 = <立库入库搬运> 的任务(Task),调度系统,设备为“国自” -- 入库终点货位加入库锁 变更历史: --]] wms_op = require("wms_operation") wms_wh = require("wms_wh") wms_task = require("wms_task") require("GT_InAndOutboundPolicies") require("GT-Base") function OperationStart(strLuaDEID) local nRet, strRetInfo, strErr, ret_loc -- 获取作业对象 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 ext_data, success success, ext_data = pcall(json.decode, operation.ext_data) if (success == false) then lua.Error(strLuaDEID, debug.getinfo(1), "operation_obj.ext_data 中内容JSON格式不合法!") end lua.Debug(strLuaDEID, debug.getinfo(1), '入库作业扩展参数!', ext_data) -- 计算终点货位 local item_type = ext_data.item_type local mat_size if (item_type == '钢丝') then mat_size = 2 else mat_size = 1 end -- 获取终点信息 nRet, end_loc = wms_wh.GetLocInfo(operation.end_loc_code) if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), 'WMS_GetLocInfo失败!' .. end_loc) end -- 判断该巷道的任务是否超过阙值,如果超过则将作业设置为等待状态并将错误信息设置到页面 local strCondition = "( N_B_STATE = " .. wms_base.Get_nConst(strLuaDEID, "任务状态-已推送") strCondition = strCondition .. " OR N_B_STATE = " .. wms_base.Get_nConst(strLuaDEID, "任务状态-执行") .. ") AND N_ROADWAY =" .. end_loc.roadway nRet, strRetInfo = mobox.getDataObjCount(strLuaDEID, "Task", strCondition) if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), strRetInfo) end if (tonumber(strRetInfo) > tonumber(wms_base.Get_sConst(strLuaDEID, "Task-最大任务数"))) then local msg msg = "作业编码为=" .. operation.code .. " 创建任务失败, 巷道" .. ext_data.roadway .. "的任务数量已超过2个" lua.Warning(strLuaDEID, debug.getinfo(1), msg) lua.Wait(strLuaDEID, msg) return end -- 创建立库入库搬运任务 local task = m3.AllocObject(strLuaDEID, "Task") task.code = ext_data.task_no -- 创建输送机搬运任务 task.op_code = operation.code -- 作业编码 task.op_name = "立库入库" task.factory = operation.factory -- 工厂 task.type = wms_base.Get_nConst(strLuaDEID, "任务类型-立库入库搬运") task.cntr_code = operation.cntr_code -- 起点 task.start_wh_code = operation.start_wh_code task.start_area_code = operation.start_area_code task.start_loc_code = operation.start_loc_code -- 终点 task.end_wh_code = operation.end_wh_code task.end_area_code = operation.end_area_code task.end_loc_code = operation.end_loc_code task.schedule_type = wms_base.Get_nConst(strLuaDEID, "调度类型-国自") -- 设置调度类型 task.roadway = ext_data.roadway -- 添加巷道 nRet, task = m3.CreateDataObj(strLuaDEID, task) if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "创建【任务】失败!" .. task) end lua.Debug(strLuaDEID, debug.getinfo(1), 'task', task) -- 通过容器获取物料信息 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 -- 获取起点绑定的WCS站点 local condition = "S_VALUE = '" .. task.start_loc_code .. "' AND S_NOTE LIKE '%入库站台%'" nRet, strRetInfo = m3.GetDataObjByCondition(strLuaDEID, "WMS_Const", condition) if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "获取【常量】信息失败! " .. strRetInfo) end local loc_code_zd = strRetInfo.name -- 调用国自的任务下发接口 local strCode = lua.guid() -- 生产一个GUID字符串 local str_day_time = os.date("%Y-%m-%d %H:%M:%S") local url = wms_base.Get_sConst(strLuaDEID, "WCS-url") local strurl = url .. "/create" local strHeader = "" local strBody = {} local data = { req_no = strCode, task_type = 1, -- 1=货物入库;2=货物出库;3=托盘组入库;4=托盘组出库;5=移动(不过库位);6=移库 task_no = task.code, tunnel_no = task.roadway, from_pos = loc_code_zd, to_pos = task.end_loc_code, mat_code = task.cntr_code, mat_type = cg_detail.item_code, mat_memo = cg_detail.item_name, req_time = str_day_time, mat_size = mat_size } strBody[1] = data lua.Debug(strLuaDEID, debug.getinfo(1), 'strBody', strBody) nRet, strRetInfo = CreateInterfaceExc(strLuaDEID, strurl, strHeader, strBody, "WCS", "任务创建") if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "调用接口失败!" .. strRetInfo) end -- 设置状态未推送 wms_task.SetStateByCode(strLuaDEID, task.code, "任务状态-已推送") end