--[[
|
编码: GT-100-17
|
名称: 重新计算终点货位
|
作者: LZH
|
入口函数:RecalculateLoc
|
功能说明: 获取任务号、容器编码,重新计算终点货位
|
输入数据:
|
{
|
"task_no": "xxx", 单托盘任务号
|
"type": "xxx", 异常类型 1 取货无货(锁一组货位) 2 放货有货(锁一组货位,重新申请货位)3 取深浅有(锁一组货位) 4 放深浅有(锁一组货位,重新申请货位)
|
"cntr_code": "xxx" 货物RFID
|
}
|
|
处理逻辑
|
-- step1 解析接口传递的 datajson 参数
|
-- step2 校验必传字段是否为空,为空则报错
|
-- step3 重新计算终点货位
|
变更历史:
|
--]]
|
require("WMS-Equipment")
|
wms_cntr = require("wms_container")
|
wms_wh = require("wms_wh")
|
require("GT-Base")
|
require("GT_InAndOutboundPolicies")
|
wms_task = require("wms_task")
|
function RecalculateLoc(strLuaDEID)
|
local nRet, in_date, strRetInfo
|
-- step1 获取接口数据
|
nRet, in_date = m3.GetSysDataJson(strLuaDEID)
|
if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "WCStoreCallback 无法获取数据包!" .. in_date) end
|
lua.Debug(strLuaDEID, debug.getinfo(1), '重新计算终点货位参数:', in_date)
|
|
-- step2 判断 必填项 是否都有值?没值报错返回
|
local task_no = in_date.task_no
|
local cntr_code = in_date.cntr_code
|
local type = in_date.type
|
if (task_no == nil or task_no == '') then lua.Error(strLuaDEID, debug.getinfo(1), "任务号不能为空!") end
|
if (type == nil or type == '') then lua.Error(strLuaDEID, debug.getinfo(1), "异常类型不能为空!") end
|
|
-- step3 获取任务对象信息
|
local task
|
nRet, task = wms_task.GetInfo(strLuaDEID, task_no)
|
if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), task) end
|
lua.Debug(strLuaDEID, debug.getinfo(1), 'task:', task)
|
|
if (task.bs_state == 3) then
|
lua.Error(strLuaDEID, debug.getinfo(1), "任务已完成!")
|
elseif (task.bs_state == 4) then
|
lua.Error(strLuaDEID, debug.getinfo(1), "任务异常!")
|
end
|
|
-- 获取任务位置的【货位】信息
|
local localtion
|
local strCondition
|
if (tonumber(type) == 1 or tonumber(type) == 3) then
|
strCondition = "S_CODE = '" .. task.start_loc_code .. "'"
|
elseif (tonumber(type) == 2 or tonumber(type) == 4) then
|
strCondition = "S_CODE = '" .. task.end_loc_code .. "'"
|
end
|
nRet, localtion = m3.GetDataObjByCondition(strLuaDEID, "Location", strCondition)
|
if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "获取【货位】信息失败! " .. localtion) end
|
|
-- 给终点货位和对应的内外深位加锁
|
-- 随机生成异常的编号
|
local strCode = 'YC' .. os.date("%y%m%d") .. '-'
|
nRet, strCode = mobox.getSerialNumber("异常编码", strCode, 5)
|
if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), '申请异常编码失败!' .. strCode) end
|
|
-- 解锁
|
nRet, strRetInfo = wms.wms_UnlockByTask(strLuaDEID, task.code)
|
if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "wms_UnlockByTask 失败! " .. strRetInfo) end
|
|
nRet, strRetInfo = wms.wms_LockLocation(strLuaDEID, task.end_loc_code, wms_base.Get_nConst(strLuaDEID, "锁类型-其它"),
|
strCode, strCode, "重新计算货位异常锁定")
|
if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "wms_LockLocation 失败!" .. strRetInfo) end
|
|
nRet, strRetInfo = OuterDeepPosition(strLuaDEID, localtion.row_group, localtion.code)
|
if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), '获取对应的内外深位的货位!' .. strRetInfo) end
|
|
nRet, strRetInfo = wms.wms_LockLocation(strLuaDEID, strRetInfo, wms_base.Get_nConst(strLuaDEID, "锁类型-其它"),
|
strCode, strCode, "重新计算货位异常锁定")
|
if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "wms_LockLocation 失败!" .. strRetInfo) end
|
|
local loc_code
|
if (tonumber(type) == 2 or tonumber(type) == 4) then
|
-- 根据容器获取货品信息
|
local cg_detail
|
nRet, cg_detail = wms_cntr.Get_Container_Goods(strLuaDEID, cntr_code)
|
if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), cg_detail) end
|
if (cg_detail == nil or cg_detail == '') then
|
lua.Error(strLuaDEID, debug.getinfo(1), cg_detail)
|
end
|
nRet, cg_detail = m3.ObjAttrStrToLuaObj("CG_Detail", lua.table2str(cg_detail[1].attrs))
|
if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "ObjAttrStrToLuaObj失败! " .. cg_detail) end
|
|
-- 获取物料类型
|
local item_type, material
|
nRet, item_type, material = GT_Get_ItemType(strLuaDEID, cg_detail.item_code)
|
if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), item_type) end
|
|
local param = {}
|
param.item_code = cg_detail.item_code -- 物料编码
|
param.batch_no = cg_detail.batch_no -- 批次号
|
param.condition = localtion.roadway -- 可入库巷道
|
param.remark = false -- 标识,false 不查询同批次的外深位
|
-- 根据物料类型重新计算立库货位(目前立库只有胶料和钢丝)
|
if (item_type == '散装胶' or item_type == '胶料' or item_type == '天然胶') then
|
nRet, loc_code = JL_StorageTactics(strLuaDEID, param)
|
elseif (item_type == '钢丝') then
|
nRet, loc_code = GS_StorageTactics(strLuaDEID, param)
|
else
|
lua.Error(strLuaDEID, debug.getinfo(1), "立库没有" .. item_type .. "类型的物料!")
|
end
|
if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), loc_code) end
|
strCondition = "S_CODE = '" .. loc_code .. "'"
|
nRet, localtion = m3.GetDataObjByCondition(strLuaDEID, "Location", strCondition)
|
if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "获取【货位】信息失败! " .. localtion) end
|
end
|
if (loc_code ~= nil) then
|
task.end_loc_code = loc_code
|
nRet, strRetInfo = wms_task.Update(strLuaDEID, task)
|
if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "更新任务终点失败!" .. strRetInfo) end
|
else
|
lua.Error(strLuaDEID, debug.getinfo(1), "巷道库存已满!")
|
end
|
-- 拼接返回的数据
|
local data = {
|
end_loc_code = loc_code,
|
task_no = task_no,
|
roadway = localtion.roadway
|
}
|
|
mobox.returnValue(strLuaDEID, 1, lua.table2str(data))
|
end
|