1
Jianw
2025-07-09 f6f5e6b632d6649386a380558d84003f3de7ec6c
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
--[[
   编码: AMS-52-22
   名称: 
   作者:
   日期:2025-05-28
 
   函数: WaveNoChange
   功能:
 
   更改记录:
 
--]]
 
json  = require ("json")
mobox = require ("OILua_JavelinExt")
m3 = require ("oi_base_mobox")
 
function WaveNoChange( strLuaDEID )
        nRet, attrs = m3.GetSysInputParameter(strLuaDEID)
    if (nRet ~= 0) then
        mobox.setInfo(strLuaDEID,  "获取当前输入面板里的属性失败! " .. attrs)
        return
    end
    
    local input_attr = m3.KeyValueAttrsToObjAttr(attrs)
    local wave_no = input_attr.S_WAVE_NO            --波次号
    
 
    
    local Condition = "S_WAVE_NO = '" .. wave_no .. "'"
    nRet, container_data = m3.QueryDataObject(strLuaDEID, "Distribution_CNTR_Detail", Condition)
    if (nRet ~= 0 or container_data == '') then
        lua.Stop(strLuaDEID, "查询配盘明细失败!!!")
        return
    end
 
    local page_info = {}
 
    -- 合并相同料箱号、料格号、物料编码的数据
    local merged_data = {}
 
    -- 使用for循环来遍历container_data并合并数据
    for i = 1, #container_data do
        local record = m3.KeyValueAttrsToObjAttr(container_data[i].attrs)
        local loc = record.S_LOC_CODE      -- 获取料格号
        local item_code = record.S_ITEM_CODE  -- 获取物料编码
        local item_name = record.S_ITEM_NAME
        local qty = lua.Get_NumAttrValue(record.F_QTY)  -- 获取数量
        
        lua.Debug(strLuaDEID, debug.getinfo(1), "record--->", record)
        local key = loc .. "_" .. item_code
        -- 如果该组合键已存在,则合并数据(如合并数量)
        if not merged_data[key] then
            merged_data[key] = {
                loc = loc,
                item_code = item_code,
                item_name = item_name,
                qty = qty,  -- 初始数量
            }
        else
            -- 如果已存在,增加数量
            merged_data[key].qty = merged_data[key].qty + qty  -- 累加数量
        end
    end
 
    -- 将合并后的数据转换回一个数组,方便后续操作
    for _, merged_record in pairs(merged_data) do
        -- 生成唯一的 ID 使用时间戳 + 随机数
        local id = "ID_" .. os.time() .. "_" .. math.random(1000, 9999)
        local state = "编辑"  -- 设置为编辑状态
        local attrs = {
            { value = merged_record.loc, attr = "S_LOC_CODE" },
            { value = merged_record.item_code, attr = "S_ITEM_CODE" },
            { value = merged_record.item_name, attr = "S_ITEM_NAME" },
            { value = tostring(merged_record.qty), attr = "F_QTY" }
        }
 
        local item = {
            id = id,
            state = state,
            attrs = attrs
        }
 
        -- 将合并后的记录添加到页面信息中
        table.insert(page_info, item)
    end
 
    lua.Debug(strLuaDEID, debug.getinfo(1), "page_info--->", page_info)
 
    -- 设置待分拣页面信息
    local action_array = {}
    action_array[1] = {
        action_type = "set_subtable_page_content",
        value = {
            page_name = "波次子界面",
            content = page_info,
            clear = true,
            clear_confirm = false,
            checkbox = false
        }
    }
    
        -- 执行所有操作
    nRet, strRetInfo = mobox.setAction(strLuaDEID, lua.table2str(action_array))
    lua.Debug(strLuaDEID, debug.getinfo(1), "lua.table2str(action_array)-->", lua.table2str(action_array))
    if (nRet ~= 0) then
        mobox.setInfo(strLuaDEID, "执行操作失败! " .. strRetInfo)
        return
    end
 
end