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
--[[
   编码: WMS-01-22
   名称:
   作者:
   日期:2025-06-18
 
   函数: emptyBoxQuery
   功能: 需要使用MBC登录,取得mac地址,然后从机台取得对应的 存储区 如 S1  并设置到查询条件中去
 
   更改记录:
 
--]]
 
 
local json = require("json")
local mobox = require("OILua_JavelinExt")
local lua = require("oi_base_func")
local m3 = require("oi_base_mobox")
 
 
--[[
固定-错误捕获处理
在core_main函数中配合 error(msg) 取得外抛出错误
]]
local ERR
local luaDEID
 
local function main()
 
    -- 取得查询表单数据
    local loc, con = "",""
    do
        local nRet, attrs = m3.GetSysInputParameter(luaDEID)
        if type(attrs) == "table" then
            local parameter = m3.KeyValueAttrsToObjAttr(attrs)
            loc = lua.Get_StrAttrValue(parameter.S_POSITION)
            con = lua.Get_StrAttrValue(parameter.S_CODE)
        end
    end
 
 
 
    -- 登录人
    local user
    do
        local nRet, strRetInfo = mobox.getCurUserInfo(luaDEID)
        print(type(strRetInfo))
        print(strRetInfo)
        user = strRetInfo
    end
 
    -- mac地址
    local mac
 
    do
        local nRet, strRetInfo = mobox.getUserInfo(user, 1, 1)
        print(nRet)
        print(type(strRetInfo)) -- 返回json 字符串
        print(strRetInfo)
 
        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 -- 查询条件
        --do
        --    local filters = {}
        --    table.insert(filters, string.format(" %s = '%s' ", "S_BS_NO", "2025050602"))
        --    strCondition = table.concat(filters, " and ")
        --end
 
        -- 查询全部-统一处理
        local nRet, strRetInfo = mobox.queryDataObjAttr(luaDEID, "Machine_Station", {})
        print('type:' .. type(strRetInfo))
        print('nRet:' .. nRet)
        print('data:' .. strRetInfo)
 
        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
 
        print(json.encode(kvmap))
 
        area = kvmap[mac]
    end
 
 
    -- 在条件设置阶段直接的过滤目标数据
    local constrlist
    do
 
        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,  con.S_ID ]]
 
        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
        )
        if  string.len(loc) > 0 then 
            strCondition = strCondition ..  string.format(" and loc.S_CODE = '%s' ",loc)
        end
 
        if  string.len(con) > 0 then 
            strCondition = strCondition ..  string.format("  and con.S_CODE = '%s' ",con)
        end
 
 
        local    nRet, strRetInfo = mobox.queryMultiTable(luaDEID, strAttrs, strTable, 2000, strCondition )
 
        local  luadata_conlist 
        if #strRetInfo == 0 then 
           luadata_conlist  = {}
           else
            luadata_conlist = json.decode(strRetInfo)
        end
        
        local conlist = {}
        for _, item in ipairs(luadata_conlist) do
            local it = item[1]
            table.insert( conlist, "'" .. item[1] .. "'" )
        end
 
        constrlist = table.concat(conlist , " , ")
    end
 
    local strCondition 
 
    if #constrlist > 0 then 
        strCondition = string.format(" S_CODE in (%s)  ", constrlist )
    else
        strCondition = " S_CODE is null " -- 达到查不到数据的目标
    end
 
 
 
    local action = {
        {
            action_type = "set_query_condition",
            value = {
                condition = strCondition
            }
        }
    }
    local jsonstr = lua.table2str(action)
    print(jsonstr)
    do
        local nRet, strRetInfo = mobox.setAction(luaDEID, lua.table2str(action))
    end
 
 
end
 
local function errorHandler(err)
    ERR = err
    lua.Debug(luaDEID, debug.getinfo(1), "err-捕获", err)
    return err
end
 
--[[ 入口函数 ]]
function emptyBoxQuery(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