---
|
--- Generated by EmmyLua(https://github.com/EmmyLua)
|
--- Created by HUI.
|
--- DateTime: 2024/3/7 9:58
|
---
|
|
require("WMS-WHAreaLoc")
|
require("oi_basestrfunc")
|
json = require("json")
|
mobox = require("OILua_JavelinExt")
|
|
function ClippingOutStock (strLuaDEID)
|
|
local nRet, strRetInfo, resData
|
|
-- 获取勾选的信息
|
nRet, strRetInfo = mobox.getCurEditDataPacket(strLuaDEID)
|
if (nRet ~= 0) then
|
Error(strLuaDEID, debug.getinfo(1), "调用getCurEditDataPacket接口出错" .. strRetInfo)
|
end
|
if (strRetInfo == "") then
|
Error(strLuaDEID, debug.getinfo(1), "未获取到勾选信息")
|
end
|
|
Debug(strLuaDEID, debug.getinfo(1), "勾选的信息strRetInfo:", strRetInfo)
|
|
resData = json.decode(strRetInfo)
|
|
local cntr_code
|
-- 获取容器编码
|
for n = 1, #resData do
|
local resAttrs = resData[n].attrs
|
for m = 1, #resAttrs do
|
local resAttr = resAttrs[m].attr
|
local resValue = resAttrs[m].value
|
if (resAttr == "S_CNTR_CODE") then
|
cntr_code = resValue
|
-- 根据容器编码查询所在货位编码
|
local strTableName = "TN_Loc_Container"
|
local strFieldList = '["S_LOC_CODE"]'
|
local nRetCount = 10
|
local strCondition = "S_CNTR_CODE = '" .. cntr_code .. "'"
|
local strOrderBy = ""
|
nRet, strRetInfo = mobox.queryTable(strLuaDEID, strTableName, strFieldList, nRetCount, strCondition, strOrderBy)
|
if (nRet ~= 0) then
|
Error(strLuaDEID, debug.getinfo(1), "调用queryTable接口出错" .. strRetInfo)
|
end
|
if (strRetInfo == "") then
|
Error(strLuaDEID, debug.getinfo(1), "未获取到勾选信息")
|
end
|
Debug(strLuaDEID, debug.getinfo(1), "根据容器编码查询到的货位信息strRetInfo:", strRetInfo)
|
local loc_info = json.decode(strRetInfo)
|
for i = 1, #loc_info do
|
local start_bit = loc_info[i].S_LOC_CODE
|
-- 判断起点有没有非完成或者非错误的作业, 有则跳过循环, 不进行创建
|
local strTabName = 'TN_Operation'
|
local strCondition1 = "S_START_LOC = '" .. start_bit .. "' AND N_B_STATE NOT IN ('" .. WMS_nConst(strLuaDEID, "作业状态-完成") .. "', '" .. WMS_nConst(strLuaDEID, "作业状态-错误") .. "')"
|
-- 获取满足条件的任务条数
|
nRet, strRetInfo = mobox.getDBRecordCount(strLuaDEID, strTabName, strCondition1)
|
if (nRet ~= 0) then
|
Error(strLuaDEID, debug.getinfo(1), "调用接口getDBRecordCount获取数据失败" .. strRetInfo)
|
end
|
-- 有未完成的作业
|
if (strRetInfo ~= "0") then
|
Debug(strLuaDEID, debug.getinfo(1), "根据容器编码" .. cntr_code .. "查询到的货位创建作业失败, 当前位置有未完成的作业", loc_code)
|
else
|
-- 没有未完成的作业
|
-- 获取起点货位信息
|
local location_start
|
nRet, location_start = WMS_Location_GetInfo(strLuaDEID, start_bit)
|
if (nRet ~= 0) then
|
Error(strLuaDEID, debug.getinfo(1), 'WMS_Location_GetInfo获取起点货位信息失败!' .. location_start)
|
end
|
if (strRetInfo == "") then
|
Error(strLuaDEID, debug.getinfo(1), "WMS_Location_GetInfo获取起点货位信息为空")
|
end
|
|
-- 根据起点获取起点所在库区,再确定出库口
|
local end_bit
|
local start_area_code = location_start.area_code
|
if (start_area_code == "AF1-01") then
|
end_bit = "LL1-1001"
|
elseif (start_area_code == "AF2-01") then
|
end_bit = "LL2-1001"
|
elseif (start_area_code == "AF3-01") then
|
end_bit = "LL3-1060"
|
elseif (start_area_code == "AF4-01") then
|
end_bit = "LL4-1064"
|
elseif (start_area_code == "AF5-01") then
|
end_bit = "LL5-1068"
|
end
|
|
-- 获取终点货位信息
|
local location_end
|
nRet, location_end = WMS_Location_GetInfo(strLuaDEID, end_bit)
|
if (nRet ~= 0) then
|
Error(strLuaDEID, debug.getinfo(1), 'WMS_Location_GetInfo获取终点货位信息失败!' .. location_end)
|
end
|
if (strRetInfo == "") then
|
Error(strLuaDEID, debug.getinfo(1), "WMS_Location_GetInfo获取终点货位信息为空")
|
end
|
|
-- 创建作业
|
local operation = AllocObject(strLuaDEID, "Operation")
|
operation.start_wh_code = location_start.wh_code
|
operation.start_area_code = location_start.area_code
|
operation.start_loc_code = location_start.code
|
operation.end_wh_code = location_end.wh_code
|
operation.end_area_code = location_end.area_code
|
operation.end_loc_code = location_end.code
|
operation.op_type = WMS_nConst(strLuaDEID, "作业类型-出库")
|
operation.op_def_code = "OP014"
|
operation.op_def_name = "剪版出库"
|
operation.cntr_code = cntr_code
|
|
Debug(strLuaDEID, debug.getinfo(1), "作业创建前:", operation)
|
|
nRet, strRetInfo = CreateDataObj(strLuaDEID, operation)
|
if (nRet ~= 0) then
|
Error(strLuaDEID, debug.getinfo(1), '创建【作业】失败!' .. strRetInfo)
|
end
|
end
|
end
|
end
|
end
|
end
|
end
|