--[[
|
编码: GT-40-46
|
名称: 作业启动
|
作者: LZH
|
入口函数:OperationStart
|
功能说明:
|
创建一段AGV任务,从作业起点到回库接驳位并调用AGV的任务下发接口
|
变更历史:
|
--]]
|
require("WMS-BASE")
|
wms_op = require("wms_operation")
|
wms_wh = require("wms_wh")
|
wms_task = require("wms_task")
|
require("GT-Base")
|
function OperationStart(strLuaDEID)
|
local nRet, strRetInfo
|
-- 获取作业对象, 从作业对象中获取{扩展数据}, 从{扩展数据}获取线体设备编码
|
local operation
|
nRet, operation = m3.GetSysCurEditDataObj(strLuaDEID, "Operation")
|
if (nRet ~= 0) then
|
lua.Error(strLuaDEID, debug.getinfo(1), "获取作业对象属性失败!" .. operation)
|
end
|
|
-- 获取起点信息
|
local loc_start
|
nRet, loc_start = wms_wh.Location_GetInfo(strLuaDEID, operation.start_loc_code)
|
if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "WMS_Location_GetInfo失败! " .. loc_start) end
|
|
-- 获取起点库区信息
|
local area
|
local strCondition = "S_CODE = '" .. loc_start.area_code .. "'"
|
nRet, area = m3.GetDataObjByCondition(strLuaDEID, "Area", strCondition)
|
if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "m3.GetDataObjByCondition 失败!" .. area) end
|
|
-- 通过楼层 + 库区位置 计算AGV的终点为哪个回库口库区
|
-- 库区的备注为 半钢/全钢
|
strCondition = "N_FLOOR = '" .. area.floor .. "' AND S_NAME LIKE '%" .. area.note .. "回库口%'"
|
nRet, area = m3.GetDataObjByCondition(strLuaDEID, "Area", strCondition)
|
if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "m3.GetDataObjByCondition 失败!" .. area) end
|
|
-- 获取终点接驳位
|
local end_loc_list
|
local end_loc_code = ''
|
strCondition = "N_LOCK_STATE = 0 AND S_AREA_CODE = '" .. area.code .. "'"
|
nRet, end_loc_list = m3.QueryDataObject(strLuaDEID, "Location", strCondition)
|
if (nRet ~= 0 or end_loc_list == '') then lua.Error(strLuaDEID, debug.getinfo(1), '查询货位失败!' .. end_loc_list) end
|
for i = 1, #end_loc_list do
|
local attrs = end_loc_list[i].attrs
|
attrs = m3.KeyValueAttrsToObjAttr(attrs)
|
if (attrs == nil) then goto coroutine end
|
end_loc_code = attrs.S_CODE
|
::coroutine::
|
end
|
|
if (end_loc_code == '') then
|
local msg
|
msg = "作业编码为=" .. operation.code .. " 创建任务失败, 没有可用接驳位!"
|
lua.Warning(strLuaDEID, debug.getinfo(1), msg)
|
lua.Wait(strLuaDEID, msg)
|
return
|
end
|
|
-- 获取终点接驳位
|
local loc_end
|
nRet, loc_end = wms_wh.Location_GetInfo(strLuaDEID, end_loc_code)
|
if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "WMS_Location_GetInfo失败! " .. loc_end) end
|
|
-- 更新作业终点货位信息
|
nRet, strRetInfo = wms_op.SetEndLoc(strLuaDEID, operation.code, loc_end.code, loc_end.area_code,
|
loc_end.wh_code)
|
if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "更新作业终点失败! " .. strRetInfo) end
|
|
-- 创建 AGV 搬运任务
|
local task = m3.AllocObject(strLuaDEID, "Task")
|
task.op_code = operation.code -- 作业编码
|
task.op_name = operation.op_def_name
|
task.factory = operation.factory -- 工厂
|
task.type = wms_base.Get_nConst(strLuaDEID, "任务类型-AGV入库搬运")
|
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 = loc_end.wh_code
|
task.end_area_code = loc_end.area_code
|
task.end_loc_code = loc_end.code
|
task.schedule_type = wms_base.Get_nConst(strLuaDEID, "调度类型-AGV") -- 设置调度类型
|
task.roadway = loc_end.roadway
|
nRet, task = m3.CreateDataObj(strLuaDEID, task)
|
if (nRet ~= 0) then
|
lua.Error(strLuaDEID, debug.getinfo(1), "创建AGV入库任务失败!" .. task)
|
end
|
|
-- 如果是二楼回库口的话,需要给回库口货位上锁,在国自返回 放货完成允许离开 状态时解锁货位
|
if (tonumber(area.floor) == 2) then
|
nRet, strRetInfo = wms.wms_LockLocation(strLuaDEID, loc_end.code,
|
wms_base.Get_nConst(strLuaDEID, "锁类型-入库锁"),
|
operation.cntr_code, operation.cntr_code, operation.op_def_name)
|
if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "wms_LockLocation 失败!" .. strRetInfo) end
|
end
|
|
-- 设置状态未推送
|
wms_task.SetStateByCode(strLuaDEID, task.code, "任务状态-已推送")
|
|
local data = {
|
taskData = {
|
taskNum = task.code,
|
pickStation = task.start_loc_code,
|
dropStation = task.end_loc_code,
|
taskType = 2,
|
carrierType = 1,
|
priority = 1,
|
wmsTaskNo = "", -- 出库才给
|
grade = "", -- 入库等级是默认的
|
produceTime = "",
|
tyreType = "",
|
supplier = "",
|
receiveLot = "",
|
subpool = ""
|
},
|
partData = {
|
rfid = task.cntr_code,
|
lotNumber = nil,
|
partNumber = "KT",
|
partDesc = "空托",
|
partType = nil,
|
weight = nil,
|
unit = nil,
|
maturityTime = nil,
|
productionTime = nil,
|
stewingTime = nil,
|
overdueTime = nil
|
}
|
}
|
|
local url = wms_base.Get_sConst(strLuaDEID, "AGV-url")
|
local strurl = url .. "/CreateTask"
|
local strBody = data
|
local strHeader = ""
|
nRet, strRetInfo = CreateInterfaceExc(strLuaDEID, strurl, strHeader, strBody, "AGV", "任务创建")
|
if (nRet ~= 0) then
|
lua.Error(strLuaDEID, debug.getinfo(1), "调用接口失败!" .. strRetInfo)
|
end
|
end
|