--[[
|
编码: WMS-04-50
|
名称: 货位-批量创建货位
|
作者:HAN
|
日期:2025-1-29
|
|
级别:固定 (说明本段代码在项目中不太会变化)
|
|
函数: CreateAreaLocation
|
|
功能:
|
-- 适合有巷道的立库创建货位
|
-- 在创建前先删除指定库区里所有货位(因此执行这个功能要小心)
|
-- 在项目实施初期通过这个事件可以批量创建一些货位,特别是在立库项目中特别有用
|
-- 可以一次把一个立库中的所有货位都创建,编码可以根据项目要求调整
|
-- 特别是对有深位的立库中,通过该脚本能快速完成仓库库位的设置
|
|
通过弹框出现的自定义界面,获取立库库位初始化所需要的信息,通过这些信息来批量创建货位(库位)
|
|
更改记录:
|
V2.0 HAN 20250330 巷道号属性名改进, 新增巷道数据对象的创建
|
|
--]]
|
wms_wh = require( "wms_wh" )
|
|
local nRowNo -- 排号
|
local nRowGroup -- 用于深位货位
|
local max_col, max_layer, nRowSegLen, nColSegLen, nLayerSegLen, nRowGroupSegLen
|
local capacity = 1
|
|
local aisle_list = {}
|
-- bIsLeftRow 创建的排是否在巷道左边
|
-- nRowCount 创建的排数量
|
-- nAisleNo 巷道号
|
local function create_loaction( strLuaDEID, area, bIsLeftRow, nRowCount, nAisleNo )
|
local nRow
|
local nRet, strRetInfo
|
local strRowNo, strColNo, strLayerNo
|
|
for nRow = 1, nRowCount do
|
nRowNo = nRowNo + 1
|
strRowNo = tostring( nRowNo )
|
strRowNo = lua.strFill(strRowNo,nRowSegLen,"0")
|
for nCol = 1, max_col do
|
strColNo = tostring( nCol )
|
strColNo = lua.strFill(strColNo,nColSegLen,"0")
|
for nLayer = 1, max_layer do
|
strLayerNo = tostring( nLayer )
|
strLayerNo = lua.strFill(strLayerNo,nLayerSegLen,"0")
|
|
local location = m3.AllocObject(strLuaDEID,"Location")
|
location.wh_code = area.wh_code
|
location.area_code = area.code
|
location.code = area.code..'-'..strRowNo.."-"..strColNo.."-"..strLayerNo
|
location.aisle = nAisleNo
|
location.aisle_code = aisle_list[nAisleNo].aisle_code
|
location.row = nRowNo
|
location.col = nCol
|
location.layer = nLayer
|
location.capacity = capacity
|
location.enable = 'Y'
|
location.deep = nRowCount
|
if ( nRowCount > 1 ) then
|
location.loc_type = 4 -- 深位
|
if ( bIsLeftRow ) then -- 巷道左边的排
|
location.pos = nRowCount - nRow + 1
|
else
|
location.pos = nRow
|
end
|
location.row_group = nRowGroup
|
end
|
nRet, strRetInfo = m3.CreateDataObj( strLuaDEID, location )
|
if ( nRet ~= 0 ) then return 2, '创建【货位】对象失败!'..strRetInfo end
|
end
|
end
|
end
|
|
-- 如果是深位货位需要继续创建 Location_Group
|
if ( nRowCount <= 1 ) then return 0 end
|
local strRowGroupNo = tostring( nRowGroup )
|
strRowGroupNo = lua.strFill(strRowGroupNo,nRowGroupSegLen,"0")
|
|
for nCol = 1, max_col do
|
strColNo = tostring( nCol )
|
strColNo = lua.strFill(strColNo,nColSegLen,"0")
|
for nLayer = 1, max_layer do
|
strLayerNo = tostring( nLayer )
|
strLayerNo = lua.strFill(strLayerNo,nLayerSegLen,"0")
|
local location_group = m3.AllocObject(strLuaDEID,"Location_Group")
|
location_group.wh_code = area.wh_code
|
location_group.area_code = area.code
|
location_group.code = "LG-"..strRowGroupNo.."."..strColNo.."."..strLayerNo
|
location_group.aisle = nAisleNo
|
location_group.row_group = nRowGroup
|
location_group.col = nCol
|
location_group.layer = nLayer
|
location_group.capacity = nRowCount*capacity -- 货位组的容量
|
location_group.deep = nRowCount
|
nRet, strRetInfo = m3.CreateDataObj( strLuaDEID, location_group )
|
if ( nRet ~= 0 ) then return 2, '创建【货位组】对象失败!'..strRetInfo end
|
end
|
end
|
return 0
|
end
|
|
local function get_row_str( nCount )
|
local n
|
local str_row = ''
|
|
for n = 1, nCount do
|
str_row = str_row..(n+nRowNo)..","
|
end
|
lua.trim_laster_char( str_row )
|
return str_row
|
end
|
|
function CreateAreaLocation ( strLuaDEID )
|
local nRet, strRetInfo
|
|
m3.PrintLuaDEInfo( strLuaDEID )
|
|
-- 获取输入界面中的属性
|
nRet, strRetInfo = mobox.getCurEditDataObjAttr( strLuaDEID, "AREA_CODE","LOC_TYPE","LOC_CAPACITY","AISLE_COUNT","LEFT_ROW",
|
"RIGHT_ROW","MAX_COL","MAX_LAYER" )
|
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 ) -- 货位容量
|
|
local aisle_count = lua.StrToNumber( obj_attrs[4].value ) -- 巷道数量
|
local left_row = lua.StrToNumber( obj_attrs[5].value ) -- 左边排数
|
local right_row = lua.StrToNumber( obj_attrs[6].value ) -- 右边排数
|
max_col = lua.StrToNumber( obj_attrs[7].value ) -- 最大列数
|
max_layer = lua.StrToNumber( obj_attrs[8].value ) -- 最大层数
|
|
-- 判断库区是否已经存在
|
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
|
|
lua.DebugEx( strLuaDEID, "area", area )
|
|
-- 判断巷道数量
|
if ( aisle_count <= 0 ) then
|
lua.Stop( strLuaDEID, "巷道数量必须大于0" )
|
return
|
end
|
-- 判断货位容量
|
if ( capacity <= 0 ) then
|
lua.Stop( strLuaDEID, "货位容量必须大于0" )
|
return
|
end
|
|
-- 删除库区里的所有巷道数据对象
|
local strCondition = "S_AREA_CODE = '"..area_code.."'"
|
nRet, strRetInfo = mobox.dbdeleteData( strLuaDEID, "Aisle", strCondition )
|
if ( nRet ~= 0) then
|
lua.Stop( strLuaDEID, "删除【巷道】信息失败! "..strRetInfo )
|
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 n
|
for n = 1, aisle_count do
|
local aisle_obj = m3.AllocObject(strLuaDEID,"Aisle")
|
aisle_obj.wh_code = area.wh_code
|
aisle_obj.area_code = area.code
|
aisle_obj.aisle = n
|
nRet, aisle_obj = m3.CreateDataObj(strLuaDEID, aisle_obj)
|
if ( nRet ~= 0 ) then
|
lua.Stop( strLuaDEID, '创建巷道时失败!'..aisle_obj )
|
return
|
end
|
aisle_list[n] = aisle_obj
|
end
|
|
-- 根据一个巷道创建巷道左右两边的货位
|
local nRow, nCol, nLayer
|
|
nRowNo = 0 -- 排号
|
nRowGroup = 1 -- 用于深位货位
|
|
-- 确定巷道,排,列,层码段的字符串长度,用于生成货位编码
|
|
local strBuf
|
local max_row = ( left_row + right_row )*aisle_count
|
strBuf = tostring( max_row )
|
nRowSegLen = #strBuf
|
strBuf = tostring( max_col )
|
nColSegLen = #strBuf
|
strBuf = tostring( max_layer )
|
nLayerSegLen = #strBuf
|
|
local max_row_group = 2*aisle_count
|
strBuf = tostring( max_row_group )
|
nRowGroupSegLen = #strBuf
|
|
local left_row_group, right_row_group
|
local left_row_str, right_row_str
|
local strUpdateSql
|
for n = 1, aisle_count do
|
-- 创建左边排
|
left_row_group = nRowGroup
|
left_row_str = get_row_str( left_row )
|
nRet, strRetInfo = create_loaction( strLuaDEID, area, true, left_row, n )
|
if ( nRet ~= 0 ) then
|
lua.Stop( strLuaDEID, strRetInfo )
|
return
|
end
|
nRowGroup = nRowGroup + 1
|
-- 创建右边排
|
right_row_group = nRowGroup
|
right_row_str = get_row_str( left_row )
|
nRet, strRetInfo = create_loaction( strLuaDEID, area, false, right_row, n )
|
if ( nRet ~= 0 ) then
|
lua.Stop( strLuaDEID, strRetInfo )
|
return
|
end
|
nRowGroup = nRowGroup + 1
|
|
-- 更新巷道管理对象属性
|
|
strUpdateSql = "S_LEFT_ROW = '"..left_row_str.."', S_RIGHT_ROW = '"..right_row_str.."',"..
|
"N_LEFT_ROW_GROUP = "..left_row_group..", N_RIGHT_ROW_GROUP = "..right_row_group..","..
|
"N_LEFT_DEEP = "..left_row..", N_RIGHT_DEEP = "..right_row
|
strCondition = "S_AREA_CODE = '"..area.code.."'"
|
nRet, strRetInfo = mobox.updateDataAttrByCondition( strLuaDEID, "Aisle", strCondition, strUpdateSql )
|
if ( nRet ~= 0 ) then
|
lua.Stop( strLuaDEID, "更新【巷道】信息失败!"..strRetInfo )
|
return
|
end
|
end
|
|
end
|