--[[
|
编码: WMS-03-11
|
名称: 库区-库区初始化
|
作者:HAN
|
日期:2025-1-29
|
|
级别:固定 (说明本段代码在项目中不太会变化)
|
|
函数: ClearStorageArea
|
|
功能:
|
主要用在实施测试阶段,清空某库区用
|
|
-- 清除和这个库区相关的 锁
|
-- 库区货位绑定容器全部解绑
|
-- 货位表 Location N_LOCK_STATE = 0 S_LOCK_OP = ‘’ T_EMPTY_TIME = 当前日期 T_FULL_TIME = 1900 N_CURRENT_NUM = 0
|
-- 逻辑库区量 重置
|
-= 库区量表 清空
|
更改记录:
|
|
--]]
|
|
wms_wh = require( "wms_wh" )
|
|
local function area_initial( strLuaDEID, wh_code, area_code )
|
local nRet, strRetInfo
|
|
-- 删除锁表
|
local strCondition = "S_AREA_CODE = '" .. area_code .."'"
|
nRet, strRetInfo = mobox.dbdeleteData(strLuaDEID, "Lock", strCondition)
|
if (nRet ~= 0) then lua.Error( strLuaDEID, debug.getinfo(1), "删除【锁】失败!"..strRetInfo) end
|
|
-- 删除【货位容器绑定】Loc_Container
|
strCondition = "S_LOC_CODE IN (SELECT S_CODE FROM TN_Location WHERE S_AREA_CODE = '"..area_code.."')"
|
nRet, strRetInfo = mobox.dbdeleteData(strLuaDEID, "Loc_Container", strCondition)
|
if (nRet ~= 0) then lua.Error( strLuaDEID, debug.getinfo(1), "删除【货位容器绑定】失败!"..strRetInfo) end
|
nRet, strRetInfo = mobox.dbdeleteData(strLuaDEID, "LC_Log", strCondition)
|
if (nRet ~= 0) then lua.Error( strLuaDEID, debug.getinfo(1), "删除【货位容器绑定记录】失败!"..strRetInfo) end
|
|
-- 更新货位表信息
|
local curTime = os.date("%Y-%m-%d %H:%M:%S")
|
local strSetSQL = "S_LOCK_STATE ='无', N_LOCK_STATE = 0, S_LOCK_OP = '', N_CURRENT_NUM = 0, T_FULL_TIME = '1900-1-1 0:0:0',T_EMPTY_TIME = '"..curTime.."'"
|
strCondition = "S_AREA_CODE = '"..area_code.."'"
|
nRet, strRetInfo = mobox.updateDataAttrByCondition(strLuaDEID, "Location", strCondition, strSetSQL)
|
if (nRet ~= 0) then lua.Error( strLuaDEID, debug.getinfo(1), "设置【货位】信息失败!"..strRetInfo) end
|
|
-- 减去仓库量表
|
-- 获取库区量表
|
strCondition = "S_AREA_CODE = '"..area_code.."'"
|
nRet, strRetInfo = mobox.queryDataObjAttr2( strLuaDEID, "AZ_Inventory", strCondition, "", 100, "S_ITEM_CODE",
|
"S_ITEM_NAME","S_ITEM_SPEC","F_QTY")
|
if ( nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), "查询【库区量表】信息失败!"..strRetInfo) end
|
|
if ( strRetInfo ~= '' ) then
|
local queryInfo = json.decode(strRetInfo)
|
local queryID = queryInfo.queryID
|
local nPageCount = queryInfo.pageCount
|
local nPage = 1
|
local dataSet = queryInfo.dataSet
|
local n
|
local attrs
|
local strAddAttr, strBaseAttr
|
local nOpType = 4 -- 出库减量表
|
local strItemInfo = {}
|
local strChgItem
|
local strZoneCode = ''
|
|
strItemInfo.wh_code = wh_code
|
strItemInfo.area_code = area_code
|
|
while (nPage <= nPageCount) do
|
strChgItem = ''
|
for n = 1, #dataSet do
|
attrs = m3.KeyValueAttrsToObjAttr(dataSet[n].attrs)
|
|
-- 获取查询出来的数据属性,减库存量
|
strItemInfo.item_code = attrs.S_ITEM_CODE
|
strItemInfo.item_name = attrs.S_ITEM_NAME
|
strItemInfo.qty = attrs.F_QTY
|
strChgItem = strChgItem..lua.table2str(strItemInfo)..','
|
|
end
|
if ( strChgItem ~= '') then
|
strChgItem = '['..lua.trim_laster_char( strChgItem )..']'
|
nRet, strRetInfo = wms.wms_AddWHInventoryChange( strLuaDEID, nOpType, strChgItem )
|
if ( nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), "wms_AddWHInventoryChange 失败!"..strRetInfo) end
|
end
|
nPage = nPage + 1
|
if ( nPage <= nPageCount ) then
|
-- 取下一页
|
nRet, strRetInfo = mobox.queryDataObjAttr2( queryID, nPage)
|
if ( nRet ~= 0 ) then
|
lua.Error( strLuaDEID, debug.getinfo(1), "查询【库区量表】失败! nPage="..nPage.." "..strRetInfo )
|
end
|
queryInfo = json.decode(strRetInfo)
|
dataSet = queryInfo.dataSet
|
end
|
end
|
end
|
|
-- 删除库区量表
|
local strCondition = "S_AREA_CODE = '" .. area_code .."'"
|
nRet, strRetInfo = mobox.dbdeleteData(strLuaDEID, "AZ_Inventory", strCondition)
|
if (nRet ~= 0) then lua.Error( strLuaDEID, debug.getinfo(1), "删除【库区量表】失败!"..strRetInfo) end
|
|
-- 更新逻辑库区
|
local strSetSQL = "S_LOCK_STATE ='无', N_LOCK_STATE = 0"
|
strCondition = "S_AREA_CODE = '"..area_code.."'"
|
nRet, strRetInfo = mobox.updateDataAttrByCondition(strLuaDEID, "Zone", strCondition, strSetSQL)
|
if (nRet ~= 0) then lua.Error( strLuaDEID, debug.getinfo(1), "设置【货位】信息失败!"..strRetInfo) end
|
|
-- 调用 WMS 服务后台函数 重置逻辑库区 存储量
|
-- 获取库区里的逻辑库区
|
local zone_list = wms_wh.GetAreaZoneList(area_code)
|
local n
|
local zone_code = ''
|
for n = 1, #zone_list do
|
zone_code = zone_code..zone_list[n]..';'
|
end
|
-- 重置逻辑库区中货位的可用量,后面的参数=1 表示要先重置货位中的容量,包括内存中的
|
nRet, strRetInfo = wms.wms_ResetZoneStoreNum( strLuaDEID, zone_code, 1 )
|
if ( nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), strRetInfo ) end
|
end
|
|
function ClearStorageArea ( strLuaDEID )
|
local nRet, strRetInfo
|
|
-- step1 获取当前选中的库区
|
local data_json
|
nRet, data_json = m3.GetSysDataJson( strLuaDEID )
|
if (nRet ~= 0) then lua.Error( strLuaDEID, debug.getinfo(1), data_json ) end
|
|
local obj_attrs = {}
|
for n = 1, #data_json do
|
obj_attrs = m3.KeyValueAttrsToObjAttr( data_json[n].attrs )
|
area_initial( strLuaDEID, obj_attrs.S_WH_CODE, obj_attrs.S_CODE )
|
end
|
|
end
|