fy36
2025-07-01 350eb5ec9163d3ea21416b1525bb80191e958071
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
---
--- Created by wsz.
--- DateTime: 2025/6/19 下午4:23
---
 
--[[
   编码: WMS-01-23
   名称:
   作者:
   日期:2025-06-19
 
   函数: emptyBoxFormQuery
   功能: 空容器设置下拉项   | 初始化   、  loc值变化
 
   更改记录:
 
--]]
 
local json = require("json")
local mobox = require("OILua_JavelinExt")
local lua = require("oi_base_func")
local m3 = require("oi_base_mobox")
 
------------------------------------------------------------------------------------------------------------------------
-- page 常量定义
local ERR
local luaDEID
 
 
------------------------------------------------------------------------------------------------------------------------
-- 独立方法区
local function deduplicate_array(arr)
    local seen = {}
    local result = {}
    for _, v in ipairs(arr) do
        if not seen[v] then
            seen[v] = true
            table.insert(result, v)
        end
    end
    return result
end
 
 
------------------------------------------------------------------------------------------------------------------------
-- 1. 取得mac映射配置的库区  return area-code  注意此实现需要保证机台配置  mac-库区  1-1 且不可为空,不满足时准确不可保证
local function getMacArea()
    -- 登录人
    local user
    do
        local nRet, strRetInfo = mobox.getCurUserInfo(luaDEID)
        user = strRetInfo
    end
 
    -- mac地址
    local mac
    do
        local nRet, strRetInfo = mobox.getUserInfo(user, 1, 1)
 
        if nRet == 0 then
            local loginInfo = json.decode(strRetInfo)
            mac = loginInfo.client_info.mac
        else
            mobox.setInfo(luaDEID, "查询登录人mac地址为空!")
            error("查询mac地址为空", 0)
        end
    end
 
    -- 库区
    local area
    do
        local strCondition -- 查询条件
 
        -- 查询全部-统一处理
        local nRet, strRetInfo = mobox.queryDataObjAttr(luaDEID, "Machine_Station", {})
 
        local kvmap = {}
        for _, item in pairs(json.decode(strRetInfo)) do
            local luadata = m3.KeyValueAttrsToObjAttr(item.attrs)
            kvmap[luadata.S_MAC_ADDRESS] = luadata.S_STORAGE_AREA
        end
 
        area = kvmap[mac]
    end
 
    return area
end
 
-- 2. 取得指定库区下all 空容器 的货位  返回 为空 {}  列表型table location-code ,视 queryMultiTable  限制,可能为1000 或 2000 限制
local function getAllLocation(area)
 
    local locList = {}
 
    local strTable = [[
         tn_container con
          inner join tn_loc_container lc on lc.s_cntr_code = con.s_code
          left join tn_inv_detail ind on lc.s_cntr_code = ind.s_cntr_code
          inner join tn_location loc on loc.s_code = lc.s_loc_code
          inner join tn_area area on loc.s_area_code = area.s_code
        ]]
 
    local strAttrs = [[ loc.s_code ]]
 
    local strCondition = string.format([[
    (ind.S_CNTR_CODE is null or ind.F_QTY = 0)
    and con.N_LOCK_STATE == 0
    and area.S_CODE = '%s'
     ]], area)
 
    local nRet, strRetInfo = mobox.queryMultiTable(luaDEID, strAttrs, strTable, 2000, strCondition)
 
    local luadata_conlist = #strRetInfo == 0 and {} or json.decode(strRetInfo)
 
    for _, item in ipairs(luadata_conlist) do
        local it = item[1]
        table.insert(locList, it)
    end
 
    -- 查询主体的原因,需要去重
    locList = deduplicate_array(locList)
 
    return locList
end
 
 
-- 3. 取得指定货位下 全体 空容器 返回 为空 {}  列表型table con-code ,视 queryMultiTable  限制,可能为1000 或 2000 限制
local function getContainer(area,loc)
 
    local conList = {}
 
    local strTable = [[
         tn_container con
          inner join tn_loc_container lc on lc.s_cntr_code = con.s_code
          left join tn_inv_detail ind on lc.s_cntr_code = ind.s_cntr_code
          inner join tn_location loc on loc.s_code = lc.s_loc_code
          inner join tn_area area on loc.s_area_code = area.s_code
        ]]
 
    local strAttrs = [[ con.s_code ]]
 
    local strCondition = string.format([[
    (ind.S_CNTR_CODE is null or ind.F_QTY = 0)
    and con.N_LOCK_STATE == 0
    and area.s_code = '%s'
     ]], area)
 
     strCondition = loc == "" and strCondition  or  strCondition .. string.format(" and loc.s_code = '%s' ", loc)
 
 
    local nRet, strRetInfo = mobox.queryMultiTable(luaDEID, strAttrs, strTable, 2000, strCondition)
 
    local luadata_conlist = #strRetInfo == 0 and {} or json.decode(strRetInfo)
 
    for _, item in ipairs(luadata_conlist) do
        local it = item[1]
        table.insert(conList, it)
    end
 
    return conList
end
 
-- 4. 取得页面输入的库位、容器  未输入|初始化时为 ""
local function getPagaInput()
    local loc, con = "", ""
    do
        local nRet, parameter_attrs = m3.GetSysInputParameter(luaDEID)
        -- 当初始化时 parameter_attrs  为 "" 空字串
        if type(parameter_attrs) == "table" then
            local parameter = m3.KeyValueAttrsToObjAttr(parameter_attrs)
            if parameter ~= nil then
                loc = lua.Get_StrAttrValue(parameter.S_POSITION)
                con = lua.Get_StrAttrValue(parameter.S_CODE)
            end
        end
    end
    print(loc, "--", con)
    return loc, con
end
 
 
-- 核心功能实现
local function main()
 
    local area = getMacArea()
 
    local loc, con = getPagaInput()
 
    local action_dlgAttr = { action_type = "set_dlg_attr", value = {} }
    --[[
    1. loc= "" 时 需要全量 初始化   loc 和 con  仅 area 指定
    2. loc有值时  设置con 为指定库位的数据
    ]]
 
    if loc == "" then
        print("库位未输入")
        local locList = getAllLocation(area)
        if #locList > 0 then
            local action_input1 = {
                attr = "S_POSITION",
                choice_list = locList,
            }
            table.insert(action_dlgAttr.value, action_input1)
        end
    end
 
    --
    local conList = getContainer(area,loc)
    if #conList > 0 then
        local action_input2 = {
            attr = "S_CODE",
            choice_list = conList,
        }
        table.insert(action_dlgAttr.value, action_input2)
    end
 
    -- --------------------------------------------------------------------------
 
    local action = { action_dlgAttr }
    local strjson = json.encode(action)
    local nRet, strRetInfo = mobox.setAction(luaDEID, strjson)
    print(nRet)
    print(strRetInfo)
    if nRet ~= 0 then  mobox.setInfo( luaDEID,"设置表单失败",5 )   end
 
end
 
------------------------------------------------------------------------------------------------------------------------
-----
local function errorHandler(err)
    ERR = err
    lua.Debug(luaDEID, debug.getinfo(1), "err-捕获", err)
    return err
end
 
--[[ 入口函数 ]]
function emptyBoxFormQuery(strLuaDEID)
 
    luaDEID = strLuaDEID
 
    -- lua交换区数据记录
    m3.PrintLuaDEInfo(strLuaDEID)
 
    -- core_main 为目标函数,从第2个参数后均为core_main的传入参数
    local success, result = xpcall(main, errorHandler)
 
    if not success then
        -- 函数执行失败时处理
        print("发生错误", ERR)
        lua.Error(strLuaDEID, debug.getinfo(1), ERR)
    else
        --函数成功时处理
    end
end