--[[
|
编码:
|
名称: 作业启动
|
作者:
|
入口函数:OperationStart
|
功能说明:
|
变更历史:
|
--]] require("WMS-BASE")
|
wms_op = require("wms_operation")
|
wms_wh = require("wms_wh")
|
wms_task = require("wms_task")
|
require("GT_InAndOutboundPolicies")
|
require("GT-Base")
|
function FLOperationStart(strLuaDEID)
|
local nRet, strRetInfo, store_loc, operation, end_loc
|
|
-- 获取作业对象, 从作业对象中获取{扩展数据}, 从{扩展数据}获取线体设备编码
|
nRet, operation = m3.GetSysCurEditDataObj(strLuaDEID, "Operation")
|
if (nRet ~= 0) then
|
lua.Error(strLuaDEID, debug.getinfo(1), "获取作业对象属性失败!" .. operation)
|
end
|
|
-- 判断作业里是否有明确容器,如果已经明确了容器说明出库的货品已经确定
|
if (operation.cntr_code == '') then
|
lua.Error(strLuaDEID, debug.getinfo(1), "作业中必须要有容器编号!")
|
end
|
|
-- 解析作业中的扩展参数
|
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 task_no = ext_data.task_no -- 任务号
|
local delivery_no = ext_data.delivery_no -- 业务单号为 出库单号
|
local mes_task_no = ext_data.mes_task_no
|
local wms_task_no = ext_data.wms_task_no
|
local wmsLot = ext_data.wmsLot
|
|
-- 获取起点库区信息
|
local start_area_info, end_area_info
|
local condition = "S_CODE = '" .. operation.start_area_code .. "'"
|
nRet, start_area_info = m3.GetDataObjByCondition(strLuaDEID, "Area", condition)
|
if (nRet ~= 0) then
|
lua.Error(strLuaDEID, debug.getinfo(1), "获取【库区】信息失败! " .. start_area_info)
|
end
|
|
-- 获取终点库区信息
|
condition = "S_CODE = '" .. operation.end_area_code .. "'"
|
nRet, end_area_info = m3.GetDataObjByCondition(strLuaDEID, "Area", condition)
|
if (nRet ~= 0) then
|
lua.Error(strLuaDEID, debug.getinfo(1), "获取【库区】信息失败! " .. end_area_info)
|
end
|
|
-- 判断起点和终点是否在同一边(半钢/全钢),不在则自动调拨
|
if (start_area_info.note == end_area_info.note) then
|
-- 创建 AGV 搬运任务
|
local task = m3.AllocObject(strLuaDEID, "Task")
|
task.code = task_no
|
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 = 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, "调度类型-AGV") -- 设置调度类型
|
lua.Debug(strLuaDEID, debug.getinfo(1), "任务创建前信息", task)
|
|
nRet, task = m3.CreateDataObj(strLuaDEID, task)
|
if (nRet ~= 0) then
|
lua.Error(strLuaDEID, debug.getinfo(1), "创建AGV入库任务失败!" .. task)
|
end
|
-- 设置状态未推送
|
wms_task.SetStateByCode(strLuaDEID, task.code, "任务状态-已推送")
|
|
-- 通过容器获取物料信息
|
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 .. "'"
|
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
|
|
-- 获取入库单据头信息
|
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任务
|
-- 下发任务给AGV
|
local data = {
|
taskData = {
|
taskNum = task.code,
|
pickStation = task.start_loc_code,
|
dropStation = task.end_loc_code,
|
taskType = 5,
|
carrierType = 1,
|
priority = 1,
|
mesTaskNo = mes_task_no,
|
wmsTaskNo = wms_task_no,
|
level = incoming_Info.level,
|
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_name,
|
partType = nil,
|
weight = cg_detail.qty,
|
unit = cg_detail.wu,
|
maturityTime = nil,
|
productionTime = label_crad.product_date,
|
stewingTime = nil,
|
overdueTime = nil
|
}
|
}
|
lua.Debug(strLuaDEID, debug.getinfo(1), "data", data)
|
-- 调用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
|
else
|
-- 先从起点搬运到对应的回库口,再通过堆垛机转运到另一边的出库口,在呼叫AGV
|
-- 获取终点
|
local end_loc
|
if (start_area_info.note == '半钢') then
|
nRet, end_loc = wms.wms_GetLocBaseInfo("THREE-BGHKK-01")
|
if (nRet ~= 0) then
|
lua.Error(strLuaDEID, debug.getinfo(1), "获取货位基本信息失败!" .. end_loc)
|
end
|
else
|
nRet, end_loc = wms.wms_GetLocBaseInfo("THREE-QGHKK-01")
|
if (nRet ~= 0) then
|
lua.Error(strLuaDEID, debug.getinfo(1), "获取货位基本信息失败!" .. end_loc)
|
end
|
end
|
|
-- 创建 AGV 搬运任务
|
local task = m3.AllocObject(strLuaDEID, "Task")
|
task.code = task_no
|
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 = end_loc.wh_code
|
task.end_area_code = end_loc.area_code
|
task.end_loc_code = end_loc.loc_code
|
task.schedule_type = wms_base.Get_nConst(strLuaDEID, "调度类型-AGV") -- 设置调度类型
|
lua.Debug(strLuaDEID, debug.getinfo(1), "任务创建前信息", task)
|
|
nRet, task = m3.CreateDataObj(strLuaDEID, task)
|
if (nRet ~= 0) then
|
lua.Error(strLuaDEID, debug.getinfo(1), "创建AGV入库任务失败!" .. task)
|
end
|
-- 设置状态未推送
|
wms_task.SetStateByCode(strLuaDEID, task.code, "任务状态-已推送")
|
|
-- 通过容器获取物料信息
|
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 .. "'"
|
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
|
|
-- 获取入库单据头信息
|
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任务
|
-- 下发任务给AGV
|
local data = {
|
taskData = {
|
taskNum = task.code,
|
pickStation = task.start_loc_code,
|
dropStation = task.end_loc_code,
|
taskType = 5,
|
carrierType = 1,
|
priority = 1,
|
mesTaskNo = mes_task_no,
|
wmsTaskNo = wms_task_no,
|
level = incoming_Info.level,
|
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_name,
|
partType = nil,
|
weight = cg_detail.qty,
|
unit = cg_detail.wu,
|
maturityTime = nil,
|
productionTime = label_crad.product_date,
|
stewingTime = nil,
|
overdueTime = nil
|
}
|
}
|
lua.Debug(strLuaDEID, debug.getinfo(1), "data", data)
|
-- 调用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
|
end
|
end
|