--[[
|
编码: WMS-04-50#2
|
名称: 货位-批量创建货位
|
作者:HAN
|
日期:2025-6-24
|
|
级别:固定 (说明本段代码在项目中不太会变化)
|
|
函数: CreateAreaLocation
|
|
功能:
|
-- 适合单排的库区,比如播种墙,站台拣货架
|
-- 在创建前先删除指定库区里所有货位(因此执行这个功能要小心)
|
-- 在项目实施初期通过这个事件可以批量创建一些货位,特别是在立库项目中特别有用
|
|
通过弹框出现的自定义界面,获取立库库位初始化所需要的信息,通过这些信息来批量创建货位(库位)
|
|
更改记录:
|
|
--]]
|
wms_wh = require( "wms_wh" )
|
|
function CreateAreaLocation ( strLuaDEID )
|
local nRet, strRetInfo
|
|
m3.PrintLuaDEInfo( strLuaDEID )
|
|
-- 获取输入界面中的属性
|
nRet, strRetInfo = mobox.getCurEditDataObjAttr( strLuaDEID, "AREA_CODE","LOC_TYPE","LOC_CAPACITY","MAX_COL","MAX_LAYER","MAX_ROW" )
|
if ( nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), "获取当前编辑属性失败! "..strRetInfo ) end
|
|
local obj_attrs = json.decode( strRetInfo )
|
local area_code = obj_attrs[1].value -- 库区编码
|
local loc_type = obj_attrs[2].value -- 库位类型
|
capacity = lua.StrToNumber( obj_attrs[3].value ) -- 货位容量
|
max_col = lua.StrToNumber( obj_attrs[4].value ) -- 最大列数
|
if max_col <= 0 then
|
lua.Stop( strLuaDEID, "最大列数不能小于等于0! " )
|
return
|
end
|
max_layer = lua.StrToNumber( obj_attrs[5].value ) -- 最大层数
|
if max_layer <= 0 then
|
lua.Stop( strLuaDEID, "最大层数不能小于等于0! " )
|
return
|
end
|
max_row = lua.StrToNumber( obj_attrs[6].value ) -- 最大排数
|
if max_row <= 0 then
|
lua.Stop( strLuaDEID, "最大排数不能小于等于0! " )
|
return
|
end
|
|
-- 判断库区是否已经存在
|
if ( area_code == nil or area_code == '') then
|
lua.Stop( strLuaDEID, "库区编码不能为空! "..strRetInfo )
|
return
|
end
|
|
nRet, area = wms_wh.GetAreaInfo( area_code )
|
if (nRet ~= 0) then
|
lua.Stop( strLuaDEID, "从内存获取编码'"..area_code.."'的库区信息失败!, 库区不存在!" )
|
return
|
end
|
|
-- 判断货位容量
|
if ( capacity <= 0 ) then
|
lua.Stop( strLuaDEID, "货位容量必须大于0" )
|
return
|
end
|
|
-- 删除库区中的所有货位定义
|
local strCondition = "S_AREA_CODE = '"..area_code.."'"
|
nRet, strRetInfo = mobox.dbdeleteData( strLuaDEID, "Location", strCondition )
|
if ( nRet ~= 0) then
|
lua.Stop( strLuaDEID, "删除【货位】信息失败! "..strRetInfo )
|
return
|
end
|
|
-- 根据一个巷道创建巷道左右两边的货位
|
local col,layer, row
|
|
for row = 1, max_row do
|
for col = 1, max_col do
|
for layer = 1, max_layer do
|
local location = m3.AllocObject(strLuaDEID,"Location")
|
location.wh_code = area.wh_code
|
location.area_code = area.code
|
location.code = area.code.."-"..row.."-"..col.."-"..layer
|
location.row = row
|
location.col = col
|
location.layer = layer
|
location.capacity = capacity
|
location.enable = 'Y'
|
location.deep = 1
|
|
nRet, strRetInfo = m3.CreateDataObj( strLuaDEID, location )
|
if ( nRet ~= 0 ) then
|
lua.Stop( strLuaDEID, '创建【货位】对象失败!'..strRetInfo )
|
return
|
end
|
end
|
end
|
end
|
end
|