--[[
|
编码: JX-19-20
|
名称:
|
作者:
|
日期:2025-03-25
|
|
函数: Query
|
功能:
|
|
更改记录:
|
|
--]]
|
json = require ("json")
|
mobox = require ("OILua_JavelinExt")
|
m3 = require("oi_base_mobox")
|
lua = require ("oi_base_func")
|
|
function Query(strLuaDEID)
|
local nRet, strRetInfo
|
local parameter = {}
|
local attrs
|
|
-- 获取查询面板里的输入属性
|
nRet, attrs = m3.GetSysInputParameter(strLuaDEID)
|
if (nRet ~= 0) then
|
lua.Error(strLuaDEID, debug.getinfo(1), "GetSysInputParameter 失败! " .. attrs)
|
end
|
parameter = m3.KeyValueAttrsToObjAttr(attrs)
|
|
lua.Debug(strLuaDEID, debug.getinfo(1), "parameter", parameter)
|
local item_code = lua.Get_StrAttrValue(parameter.S_ITEM_CODE) -- 物料编码
|
local cntr_code = lua.Get_StrAttrValue(parameter.S_CNTR_CODE) -- 料箱编码
|
local code = lua.Get_StrAttrValue(parameter.S_CODE) -- 拣料框号
|
local item_name = lua.Get_StrAttrValue(parameter.S_ITEM_NAME) -- 商品名称
|
|
|
-- 条件构建(重点修改部分)
|
local conditions = {}
|
|
-- 1. 处理Z开头条件(完美解决方案)
|
if code == '有' then
|
table.insert(conditions, "SUBSTR(S_CNTR_CODE,1,1) = 'Z'") -- 更可靠的写法
|
elseif code == '无' then
|
table.insert(conditions, "(SUBSTR(S_CNTR_CODE,1,1) <> 'Z' OR S_CODE IS NULL)")
|
end
|
|
-- 2. 添加其他条件
|
if cntr_code ~= "" then
|
table.insert(conditions, "S_CNTR_CODE = '"..cntr_code.."'")
|
end
|
if item_code ~= "" then
|
table.insert(conditions, "S_ITEM_CODE = '"..item_code.."'")
|
end
|
if item_name ~= "" then
|
table.insert(conditions, "S_ITEM_NAME = '"..item_name.."'")
|
end
|
|
-- 3. 构建最终SQL(安全方式)
|
local strSQL = ""
|
if #conditions > 0 then
|
strSQL = table.concat(conditions, " AND ")
|
-- 特殊处理:确保语法兼容性
|
strSQL = string.gsub(strSQL, "<>", "!=") -- 统一不等号语法
|
end
|
|
-- 调试输出
|
lua.Debug(strLuaDEID, debug.getinfo(1), "最终查询条件:", strSQL)
|
|
-- 设置查询条件
|
local action = {}
|
action[1] = {
|
action_type = "set_query_condition",
|
value = {
|
condition = strSQL,
|
order = "T_CREATE DESC"
|
}
|
}
|
|
nRet, strRetInfo = mobox.setAction(strLuaDEID, lua.table2str(action))
|
if (nRet ~= 0) then
|
lua.Error(strLuaDEID, debug.getinfo(1), "setAction失败! " .. strRetInfo .. ' action = ' .. lua.table2str(action))
|
end
|
end
|