--[[
|
编码: GT-40-26
|
名称: 作业启动
|
作者:
|
入口函数:OperationStart
|
功能说明:
|
变更历史:
|
--]]
|
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 strRetInfo
|
-- 获取作业对象
|
local 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
|
|
local type = ext_data.type -- 1 粉料调拨搬运 2 烘胶搬运
|
|
-- 创建 立库 搬运任务
|
local task = m3.AllocObject(strLuaDEID, "Task")
|
task.code = ext_data.task_no
|
task.op_code = operation.code -- 作业编码
|
task.op_name = operation.op_def_name
|
task.factory = operation.factory -- 工厂
|
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
|
|
-- 粉料调拨搬运
|
local end_loc, start_loc
|
if (tonumber(type) == 1) then
|
task.type = wms_base.Get_nConst(strLuaDEID, "任务类型-AGV出库搬运")
|
task.schedule_type = wms_base.Get_nConst(strLuaDEID, "调度类型-AGV") -- 设置调度类型
|
local end_loc_code
|
|
-- 起点为半钢库区则终点为三楼半钢转运\回库口,全钢库区则终点为三楼全钢转运\回库口
|
if (operation.start_area_code == 'PFL' or operation.start_area_code == 'HWPFL') then
|
end_loc_code = "THREE-BGHHK-01"
|
elseif (operation.start_area_code == 'TFL' or operation.start_area_code == 'HWTFL') then
|
end_loc_code = "THREE-QGHHK-01"
|
end
|
|
-- 获取终点信息
|
nRet, end_loc = wms_wh.Location_GetInfo(strLuaDEID, end_loc_code)
|
if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "WMS_Location_GetInfo失败! " .. end_loc) end
|
|
-- 终点
|
task.end_wh_code = end_loc.wh_code
|
task.end_area_code = end_loc.area_code
|
task.end_loc_code = end_loc.code
|
lua.Debug(strLuaDEID, debug.getinfo(1), "任务创建前信息", task)
|
nRet, task = m3.CreateDataObj(strLuaDEID, task)
|
if (nRet ~= 0) then
|
lua.Error(strLuaDEID, debug.getinfo(1), "创建立库出库任务失败!" .. task)
|
end
|
-- 通过容器获取物料信息
|
local cg_detail
|
nRet, cg_detail = wms_cntr.Get_Container_Goods(strLuaDEID, task.cntr_code)
|
nRet, cg_detail = m3.ObjAttrStrToLuaObj("CG_Detail", lua.table2str(cg_detail[1].attrs))
|
if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), cg_detail) end
|
|
local data = {
|
taskData = {
|
taskNum = task.code,
|
pickStation = task.start_loc_code,
|
dropStation = task.end_loc_code,
|
taskType = 5,
|
carrierType = 1,
|
priority = 1
|
},
|
partData = {
|
rfid = operation.cntr_code,
|
lotNumber = nil,
|
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, task.code, "任务状态-已推送")
|
|
-- 烘胶搬运
|
elseif (tonumber(type) == 2) then
|
elseif (tonumber(type) == 3) then
|
task.type = wms_base.Get_nConst(strLuaDEID, "任务类型-移库搬运")
|
task.schedule_type = wms_base.Get_nConst(strLuaDEID, "调度类型-国自") -- 设置调度类型
|
-- 终点
|
task.end_wh_code = operation.end_wh_code
|
task.end_area_code = operation.end_area_code
|
task.end_loc_code = operation.end_loc_code
|
lua.Debug(strLuaDEID, debug.getinfo(1), "任务创建前信息", task)
|
nRet, task = m3.CreateDataObj(strLuaDEID, task)
|
if (nRet ~= 0) then
|
lua.Error(strLuaDEID, debug.getinfo(1), "创建立库出库任务失败!" .. task)
|
end
|
-- 起点终点加锁
|
-- wms_task.LockLocation(strLuaDEID, task, "锁类型-出库锁", "锁类型-入库锁")
|
-- 通过容器获取物料信息
|
local cg_detail
|
nRet, cg_detail = wms_cntr.Get_Container_Goods(strLuaDEID, task.cntr_code)
|
nRet, cg_detail = m3.ObjAttrStrToLuaObj("CG_Detail", lua.table2str(cg_detail[1].attrs))
|
if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), cg_detail) end
|
|
nRet, start_loc = wms_wh.Location_GetInfo(strLuaDEID, task.start_loc_code)
|
if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), start_loc) end
|
|
nRet, end_loc = wms_wh.Location_GetInfo(strLuaDEID, task.end_loc_code)
|
if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), end_loc) end
|
|
-- 起点终点巷道相同则任务类型为6,不同则任务类型为7
|
local task_type
|
if (tonumber(end_loc.roadway) == tonumber(start_loc.roadway)) then
|
task_type = 6
|
else
|
task_type = 7
|
end
|
|
-- 判断起点是否是内深位,如果起点是内深位则获取对应的外深位
|
local pre_task_no = ''
|
local success, loc_code = GetPosLoc(strLuaDEID, operation.start_loc_code)
|
if (success == true) then
|
-- 判断外深位是否存在未完成的作业
|
local strCondition = "S_START_LOC = '" .. loc_code .. "' AND N_B_STATE <> 2 AND S_OP_DEF_NAME = '移库'"
|
nRet, strRetInfo = m3.GetDataObjByCondition(strLuaDEID, "Operation", strCondition)
|
if (nRet == 2) then
|
lua.Error(strLuaDEID, debug.getinfo(1), "m3.GetDataObjByCondition 失败!"..strRetInfo)
|
elseif (nRet == 0) then
|
-- 判断外深位是否存在未完成的任务,如果有则将这个任务号输入到 WCS参数中的前置任务号中
|
strCondition = "S_START_LOC = '" .. loc_code .. "' AND N_B_STATE IN (0,1,2)"
|
nRet, strRetInfo = m3.GetDataObjByCondition(strLuaDEID, "Task", strCondition)
|
if (nRet == 2) then
|
lua.Error(strLuaDEID, debug.getinfo(1), "m3.GetDataObjByCondition 失败!" .. strRetInfo)
|
elseif (nRet == 1) then
|
lua.Error(strLuaDEID, debug.getinfo(1), "创建移库任务失败,前置移库任务未生成!")
|
elseif (nRet == 0) then
|
pre_task_no = strRetInfo.code
|
end
|
end
|
end
|
|
-- 调用国自的任务下发接口
|
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 = task_type, -- 1=货物入库;2=货物出库;3=托盘组入库;4=托盘组出库;5=移动(不过库位);6=同巷道移库;7=不同巷道移库
|
task_no = task.code,
|
tunnel_no = end_loc.roadway,
|
from_pos = task.start_loc_code,
|
to_pos = task.end_loc_code,
|
mat_code = operation.cntr_code,
|
mat_type = cg_detail.item_code,
|
mat_memo = cg_detail.item_name,
|
req_time = str_day_time,
|
mat_size = 1,
|
pre_task_no = pre_task_no
|
}
|
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
|
end
|
|
--
|