1
Jianw
9 天以前 70f29da38121b9a467841253e3268feb5df02902
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
--[[
    编码: JX-90-12
    名称: 物料刷新
    作者:KUN 
    日期:2025-4-10
 
    函数: Refresh
    功能: 
        -- 基础数据物料更新按钮
        -- 物料信息的刷新,主要刷新物料适配料箱类型和体积
 
--]]
 
json  = require ("json")
mobox = require ("OILua_JavelinExt")
m3 = require ("oi_base_mobox")
 
 
local function GetBoxStyle( strLuaDEID, long, middle, short )
        local nRet, strRetInfo
    
        -- 校验输入参数
        if ( long == nil or long <= 0 or long > 56) then return 1, "长边值不符合规范! 长边不能超过56" end
        if ( middle == nil or middle <= 0 or middle > 36) then return 1, "中边值不符合规范! 中边不能超过36" end
        if ( short == nil or short <= 0 or short > 27) then return 1, "短边值不符合规范! 短边不能超过27" end
        if ( middle > long or short > middle ) then return 1, "长中短边顺序不对!" end
    
        -- 计算料箱型号
        if ( long <= 27 ) then 
            if ( middle <= 18 and short <= 18 ) then
                return 0, '["A","B","C","D","E"]'
            else
                return 0, '["A","B","C","D"]'
            end
        elseif ( long > 27 and long <= 28 ) then
            if ( middle <= 27 and short <= 18 ) then
                return 0, '["A","B","D"]'
            else
                return 0, '["A","B"]'
            end
        elseif ( long > 28 and long <= 36 ) then
            if ( middle <= 27 and short <= 18 ) then
                return 0, '["A","B","C"]'
            elseif ( middle <= 28 and short <= 27 ) then
                return 0, '["A","B"]'
            else
                return 0, '["A"]'
            end
        elseif ( long > 36 and long <= 56 ) then
            return 0, '["A"]'
        end
        return 1, "长边参数不对!"
    end
 
function Refresh(strLuaDEID)
    
    local nRet
    -- 初始查询(获取所有物料)
    local strCondition = "S_CELL_TYPE <> ''"
    local nRet, strRetInfo = mobox.queryDataObjAttr2( strLuaDEID,  "Material",  strCondition, "", 100,  "S_ITEM_CODE", "F_LONG", "F_MIDDLE", "F_SHORT" )
    if (nRet ~= 0) then
        lua.Error(strLuaDEID, debug.getinfo(1), "查询【Material】信息失败!"..strRetInfo)
    end
 
    if (strRetInfo == '') then
        return
    end
    local queryInfo = json.decode(strRetInfo)
    local queryID = queryInfo.queryID
    local nPageCount = queryInfo.pageCount
 
    local nPage = 1
    local dataSet = queryInfo.dataSet
    local material_array
    local long, middle, short
 
    while (nPage <= nPageCount) do
        for n = 1, #dataSet do
            material_array = m3.KeyValueAttrsToObjAttr(dataSet[n].attrs)
            local strCondition = "S_ITEM_CODE = '" .. material_array.S_ITEM_CODE .. "'"
            long = lua.Get_NumAttrValue(material_array.F_LONG)
            middle = lua.Get_NumAttrValue(material_array.F_MIDDLE)
            short = lua.Get_NumAttrValue(material_array.F_SHORT)
            local str_cell_type = ''
            local  strRetInfo
            -- 设置【料箱类型】信息
            nRet, strRetInfo = GetBoxStyle( strLuaDEID, long, middle, short )
            if ( nRet == 0 ) then 
                -- 获取最小的 cell_type
                local box_style = json.decode( strRetInfo )
                local n = #box_style
                if ( n > 0 ) then  str_cell_type = box_style[n] end
            else
                strRetInfo = ''
            end
            
            local strUpdateSql = "S_BOX_STYLE = '".. strRetInfo .."', S_CELL_TYPE = '"..str_cell_type.."', F_VOLUME = "..long*middle*short
            nRet, strRetInfo = mobox.updateDataAttrByCondition(strLuaDEID, "Material", strCondition, strUpdateSql)
            if nRet ~= 0 then
                lua.Error(strLuaDEID, debug.getinfo(1), "更新物料失败:"..strRetInfo)
            end
 
        end
 
        -- 翻到下一页
        nPage = nPage + 1
        if (nPage <= nPageCount) then
            -- 取下一页
            nRet, strRetInfo = mobox.queryDataObjAttr2(queryID, nPage)
            if (nRet ~= 0) then
                lua.Error(strLuaDEID, debug.getinfo(1), "查询失败! nPage="..nPage.."  "..strRetInfo)
            end
            queryInfo = json.decode(strRetInfo)
            dataSet = queryInfo.dataSet
        end
    end
 
end