--[[
|
编码: JX-19-16
|
名称: 解盘确定后事件
|
作者:
|
日期:
|
|
级别:
|
|
函数: ClickOK
|
|
--]]
|
|
jx_base = require("jx_base")
|
wms_base = require("wms_base")
|
wms_wh = require("wms_wh")
|
|
-- 主函数
|
function ClickOK(strLuaDEID)
|
local nRet, strRetInfo
|
local attrs
|
|
|
local now = os.date("%Y%m%d%H%M%S")
|
local randomNum = math.random(1, 99999)
|
local strHeader = 'HHWMS'..os.date("%y%m")..'-'
|
local strCode
|
|
-- 获取
|
nRet, strCode = mobox.getSerialNumber( "巨沃移库单明细", strHeader, 5 )
|
if (nRet ~= 0) then
|
mobox.setInfo(strLuaDEID,'申请编码失败!'..strCode)
|
return
|
end
|
|
|
-- 获取输入参数
|
nRet, attrs = m3.GetSysInputParameter(strLuaDEID)
|
if (nRet ~= 0) then
|
mobox.setInfo(strLuaDEID, "获取当前输入面板里的属性失败! " .. attrs)
|
return
|
end
|
|
local input_attr = m3.KeyValueAttrsToObjAttr(attrs)
|
local cntr_code = input_attr.S_CNTR_CODE
|
if (cntr_code == nil or cntr_code == '') then
|
mobox.setInfo(strLuaDEID, "容器编码不能为空!")
|
return
|
end
|
|
-- 查询 JX_Transfer_Order 表,如果有调接口失败(N_CR_STATE = 2)的,不允许解盘报错
|
strCondition = "S_CNTR_CODE = '" .. cntr_code .. "'"
|
nRet, cntr_list = m3.QueryDataObject(strLuaDEID, "JX_Transfer_Order", strCondition)
|
lua.Debug(strLuaDEID, debug.getinfo(1), "cntr_list-->", cntr_list)
|
|
-- 检查查询是否成功
|
if (nRet ~= 0) then
|
mobox.setInfo(strLuaDEID, "查询 JX_Transfer_Order 表失败!错误信息: " .. tostring(cntr_list))
|
return
|
end
|
|
for i = 1, #cntr_list do
|
local order_attrs = m3.KeyValueAttrsToObjAttr(cntr_list[i].attrs)
|
local cr_state = order_attrs.N_CR_STATE
|
|
if (cr_state == "2") then
|
mobox.setInfo(strLuaDEID, "容器号 " .. cntr_code .. " 存在调接口失败的记录,不允许解盘!")
|
return
|
end
|
end
|
|
-- 查询 JX_TO_Detail 表
|
local container_data, nRet
|
local strCondition = "S_TO_NO IN (SELECT S_NO FROM TN_JX_Transfer_Order WHERE S_CNTR_CODE = '" .. cntr_code .. "' AND N_B_STATE = 1)"
|
|
nRet, container_data = m3.QueryDataObject(strLuaDEID, "JX_TO_Detail", strCondition)
|
|
if (nRet ~= 0 or container_data == '') then
|
mobox.setInfo(strLuaDEID,"查询 JX_TO_Detail 表失败: " .. container_data)
|
return
|
end
|
|
-- 用来存储合并后的数据
|
local merged_data = {}
|
|
-- 遍历查询到的每条数据
|
local item_code, qty
|
for i = 1, #container_data do
|
local record = m3.KeyValueAttrsToObjAttr(container_data[i].attrs)
|
item_code = record.S_ITEM_CODE -- 获取物料编码
|
qty = lua.Get_NumAttrValue(record.F_QTY) -- 获取数量
|
|
-- 将物料数据加入批量调用接口的列表
|
table.insert(merged_data, { inco = item_code,
|
qty = qty,
|
fwid = "JX-C-P002",
|
owid = "JX-C-P003" })
|
|
end
|
|
-- 获取巨沃WMS服务地址
|
local jw_wms = wms_base.Get_sConst(strLuaDEID, "巨沃WMS服务地址")
|
local strurl = jw_wms .. '?service=newOffShelfs&appkey=gwall&secret=null&format=JSON'
|
|
-- 设置请求体
|
local body = {
|
whco = "JX", -- 仓库编码
|
items = merged_data,
|
orderID = strCode -- 传递给巨沃的订单号
|
}
|
|
-- 输出调试信息
|
lua.Debug(strLuaDEID, debug.getinfo(1), "调巨沃接口-->", strurl)
|
lua.Debug(strLuaDEID, debug.getinfo(1), "body", body)
|
|
local nRet, strRetInfo = mobox.sendHttpRequest(strurl, "", "content=" .. lua.table2str(body))
|
if (nRet ~= 0 or strRetInfo == '') then
|
lua.Error(strLuaDEID, debug.getinfo(1), "调用巨沃WMS接口失败! " .. strRetInfo)
|
end
|
|
lua.Debug(strLuaDEID, debug.getinfo(1), "调巨沃接口结果-->", strRetInfo)
|
-- 解析接口返回结果,判断是否成功
|
local result = json.decode(strRetInfo)
|
if not result.isSuccess then
|
local errorMsg = result.body or "未知错误"
|
mobox.setInfo(strLuaDEID, "调用巨沃WMS接口失败: " .. errorMsg)
|
return
|
end
|
|
|
-- 更新JX_Transfer_Order状态值为1的数据为3(关闭)
|
|
local strUpdateSql = "S_CNTR_CODE = '" .. cntr_code .. "' AND N_B_STATE = 1"
|
local strCondition = "N_B_STATE = 3 , S_UNDO_NO = '" .. strCode .. "'"
|
|
nRet, strRetInfo = mobox.updateDataAttrByCondition(strLuaDEID, "JX_Transfer_Order", strUpdateSql, strCondition)
|
if (nRet ~= 0) then
|
mobox.setInfo(strLuaDEID, "更新 JX_Transfer_Order 表失败: " .. strRetInfo)
|
return
|
end
|
|
-- 删除JX_Transfer_Order状态值为0的记录
|
local strCondition = "S_CNTR_CODE = '" .. cntr_code .. "' AND N_B_STATE = 0"
|
nRet, strRetInfo = mobox.deleteDataObject( strLuaDEID, "JX_Transfer_Order", strCondition )
|
if ( nRet ~= 0) then
|
mobox.setInfo( strLuaDEID, "JX_Transfer_Order: " .. strRetInfo )
|
return
|
end
|
|
-- 清空“解盘”页面
|
local action = {}
|
action[1] = {
|
action_type = "clear_subpage_rows",
|
value = {
|
page_name = "需解盘"
|
}
|
}
|
|
action[2] = {
|
action_type = "set_dlg_attr",
|
value = {
|
{
|
attr = "S_CNTR_CODE",
|
value = "",
|
}
|
}
|
}
|
|
nRet, strRetInfo = mobox.setAction(strLuaDEID, lua.table2str(action))
|
if (nRet ~= 0) then
|
mobox.setInfo(strLuaDEID, "清空正在码盘页面失败! " .. strRetInfo)
|
return
|
end
|
|
|
|
mobox.setInfo(strLuaDEID, "操作成功!")
|
end
|