-- 判断货位是否是内深位,是则返回true和对应的外深位,不是则返回false
|
local function GetPosLoc(strLuaDEID, loc_code)
|
-- 获取货位信息
|
local nRet, location = wms_wh.Location_GetInfo(strLuaDEID, loc_code)
|
if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "获取【货位】信息失败!" .. strRetInfo) end
|
|
-- 判断货位是否是内深位,不是内深位则返回
|
if (tonumber(location.pos) == 1) then return false, "" end
|
|
local loc_code_table = lua.split(loc_code, "-") -- 通过符号分割字符串为数组
|
local loc_row = loc_code_table[2]
|
|
-- 通过库区、排组号 定位巷道信息
|
local roadway
|
local strCondition = "S_AREA_CODE = 'LK' AND (N_LEFT_ROW_GROUP = "
|
.. location.row_group .. " or N_RIGHT_ROW_GROUP = " .. location.row_group .. " )"
|
nRet, roadway = m3.GetDataObjByCondition(strLuaDEID, "Roadway", strCondition)
|
if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "获取【巷道】信息失败!" .. roadway) end
|
|
local row = "" -- 所属巷道信息中的 (内/外 深位)2排 的字符串信息(例: 21,22,)
|
if (location.row_group == tonumber(roadway.left_row_group)) then
|
row = roadway.left_row
|
else
|
row = roadway.right_row
|
end
|
local row_table = lua.split(row, ",")
|
local str = ""
|
for j = 1, #row_table do
|
if (loc_row ~= row_table[j]) then
|
str = row_table[j]
|
end
|
end
|
|
local new_loc_code = loc_code_table[1] .. "-" .. str .. "-" .. loc_code_table[3] .. "-" .. loc_code_table[4]
|
return true, new_loc_code
|
end
|
|
--[[
|
编码: GT-40-22
|
名称: 作业-立库出库-作业启动
|
作者:LZH
|
日期:2024-05-29
|
|
版本:
|
|
说明:该脚本和项目关联度较高,会根据项目不同而不同
|
函数: OperationStart
|
|
功能:
|
1)根据入库规则计算出入库位置
|
2)创建立库出库任务
|
|
更改说明:
|
|
--]]
|
|
wms_op = require("wms_operation")
|
wms_wh = require("wms_wh")
|
wms_task = require("wms_task")
|
require("GT-Base")
|
require("GT_InAndOutboundPolicies")
|
function LKOperationStart(strLuaDEID)
|
local nRet
|
-- 获取作业对象
|
local operation
|
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 item_type = ext_data.item_type -- 物料类型
|
local delivery_no = ext_data.delivery_no -- 出库单号
|
local task_no = ext_data.task_no -- 出库单号
|
|
-- V1.1 判断该巷道的任务是否超过阙值,如果超过则将作业设置为等待状态并将错误信息设置到页面
|
local store_loc, strRetInfo
|
nRet, store_loc = wms_wh.GetLocInfo(operation.start_loc_code)
|
if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), store_loc) end
|
|
-- 获取某种调度类型的任务数量
|
local strCondition = "N_SCHEDULE_TYPE = 3 AND ( N_B_STATE = " .. wms_base.Get_nConst(strLuaDEID, "任务状态-已推送")
|
strCondition = strCondition ..
|
" OR N_B_STATE = " .. wms_base.Get_nConst(strLuaDEID, "任务状态-执行") .. ") AND N_ROADWAY =" .. store_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 .. " 创建任务失败, 巷道" .. store_loc.roadway .. "的任务数量已超过2个"
|
lua.Warning(strLuaDEID, debug.getinfo(1), msg)
|
lua.Wait(strLuaDEID, msg)
|
return
|
end
|
-- 第一段任务的终点都在某个出库口
|
-- 获取线边库区信息
|
local area_info
|
strCondition = "S_CODE = (SELECT S_MS_CODE FROM TN_GT_Stock_Out WHERE S_DO_NO = '" .. delivery_no .. "')"
|
nRet, area_info = m3.GetDataObjByCondition(strLuaDEID, "Area", strCondition)
|
if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "获取库区信息失败!" .. area_info) end
|
|
-- 根据机台的区域来判断一段任务的终点为哪一个出库口
|
if (area_info.note == '半钢') then
|
strCondition = "N_FLOOR = " .. area_info.floor .. " AND S_CODE like '%BGCKK%'"
|
nRet, area_info = m3.GetDataObjByCondition(strLuaDEID, "Area", strCondition)
|
if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "获取库区信息失败!" .. area_info) end
|
elseif (area_info.note == '全钢') then
|
strCondition = "N_FLOOR = " .. area_info.floor .. " AND S_CODE like '%QGCKK%'"
|
nRet, area_info = m3.GetDataObjByCondition(strLuaDEID, "Area", strCondition)
|
if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "获取库区信息失败!" .. area_info) end
|
else
|
lua.Error(strLuaDEID, debug.getinfo(1), "未定义机台属于半钢还是全钢区域!")
|
end
|
|
local area = area_info.code -- 出库库区
|
local end_loc_code = area_info.code .. "-QY" -- 出库位置区域
|
|
-- 创建 立库 搬运任务
|
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.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.roadway = store_loc.roadway
|
|
task.type = wms_base.Get_nConst(strLuaDEID, "任务类型-立库出库搬运")
|
task.schedule_type = wms_base.Get_nConst(strLuaDEID, "调度类型-国自") -- 设置调度类型
|
-- 终点
|
task.end_wh_code = operation.start_wh_code
|
task.end_area_code = area
|
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 pre_task_no = ''
|
local success, loc_code = GetPosLoc(strLuaDEID, operation.start_loc_code)
|
if (success == true) then
|
-- 判断外深位是否存在未完成的作业
|
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 失败!" .. area)
|
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 失败!" .. area)
|
elseif (nRet == 1) then
|
lua.Error(strLuaDEID, debug.getinfo(1), "创建立库出库任务失败,前置移库任务未生成!")
|
elseif (nRet == 0) then
|
pre_task_no = strRetInfo.code
|
end
|
end
|
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
|
|
-- 出库不指定具体终点,有WCS反馈终点,获取出库口库区绑定的WCS站点
|
local condition = "S_VALUE = '" .. end_loc_code .. "'"
|
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 = 2, -- 1=货物入库;2=货物出库;3=托盘组入库;4=托盘组出库;5=移动(不过库位);6=移库
|
task_no = task.code,
|
tunnel_no = store_loc.roadway,
|
from_pos = task.start_loc_code,
|
to_pos = loc_code_zd,
|
mat_code = task.cntr_code,
|
mat_type = cg_detail.item_code,
|
mat_memo = cg_detail.item_name,
|
req_time = str_day_time,
|
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), "调用WCS接口失败!" .. strRetInfo)
|
end
|
|
-- 设置状态未推送
|
wms_task.SetStateByCode(strLuaDEID, task.code, "任务状态-已推送")
|
end
|