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
--[[
    编码: WMS-32-11
    名称: 巷道-重置货位权重
    作者:HAN  
    日期:2025-1-29
    
    级别:固定 (说明本段代码在项目中不太会变化)
    
    函数: ResetLocWeight
 
    功能:
        -- 重新计算一下巷道内货位的 weight, weight2
--]]
 
json  = require ("json")
mobox = require ("OILua_JavelinExt")
m3 = require("oi_base_mobox")
 
local function reset_lane_loc_weight( strLuaDEID, sql_condition )
    local nRet, strRetInfo
 
    -- 多页查询
    local strOrder = "N_COL desc"
    local max_col = 0
 
    nRet, strRetInfo = mobox.queryDataObjAttr2( strLuaDEID, "Location", sql_condition, strOrder, 100, "S_CODE","N_COL","N_LAYER" )
    if ( nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), "queryDataObjAttr2: "..strRetInfo) end  
    if  ( strRetInfo == '' ) then return 0 end
 
    local success
    local queryInfo
    success, queryInfo = pcall( json.decode, strRetInfo )
    if ( success == false ) then lua.Error( strLuaDEID, debug.getinfo(1), "queryDataObjAttr2 返回结果啊非法的JSON格式!" ) end
 
    local queryID = queryInfo.queryID
    local nPageCount = queryInfo.pageCount
    local nPage = 1
    local dataSet = queryInfo.dataSet       -- 查询出来的数据集
    local loc_code, col, layer, weight, weight2
    local strCondition, strSetAttr
 
    while (nPage <= nPageCount) do
 
        for n = 1, #dataSet do
            loc_code = lua.Get_StrAttrValue( dataSet[n].attrs[1].value )
            col = lua.Get_NumAttrValue( dataSet[n].attrs[2].value )
            layer = lua.Get_NumAttrValue( dataSet[n].attrs[3].value )
            if ( max_col == 0 ) then max_col = col end
            weight = col+layer
            weight2 = (max_col-col+1)+layer
            -- 更新货位权重
            strCondition = "S_CODE = '"..loc_code.."'"
            strSetAttr = "N_POS_WEIGHT = "..weight..", N_POS_WEIGHT_2 = "..weight2
            nRet, strRetInfo = mobox.updateDataAttrByCondition( strLuaDEID, "Location", strCondition, strSetAttr )
            if ( nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), "updateDataAttrByCondition失败"..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), "queryDataObjAttr2失败! nPage="..nPage.."  "..strRetInfo )
            end 
            queryInfo = json.decode(strRetInfo) 
            dataSet = queryInfo.dataSet              
        end
    end 
    
    return 0
end
 
function ResetLocWeight ( strLuaDEID ) 
    local nRet, strRetInfo, n, m
    local objs
 
    -- step1  获取当前需要进行重置的数据对象
    nRet, objs = m3.GetSysDataJson( strLuaDEID )
    if ( nRet ~=0 ) then lua.Error( strLuaDEID, debug.getinfo(1), objs ) end  
    -- [{"id":"","attrs":[{"attr":"","value":""},..]},..]
    local nCount = #objs
    if (nCount == 0) then  return end
 
    local obj_attrs
    local wh_code, area_codel, lane_no
    local strCondition
    local loc_objs, col, layer, max_col, weight, weight2
 
    for n = 1, nCount do
        obj_attrs = m3.KeyValueAttrsToObjAttr( objs[n].attrs )
        wh_code = lua.Get_StrAttrValue( obj_attrs.S_WH_CODE )
        if ( wh_code == '' ) then
            mobox.setInfo( strLuaDEID, "Grid中必须有仓库编码列!")
            return
        end
        area_code = lua.Get_StrAttrValue( obj_attrs.S_AREA_CODE )
        if ( area_code == '' ) then
            mobox.setInfo( strLuaDEID, "Grid中必须有库区编码列!")
            return
        end        
        lane_no = lua.Get_NumAttrValue( obj_attrs.N_AISLE )
        if ( lane_no == 0 ) then
            mobox.setInfo( strLuaDEID, "Grid中必须有巷道列!")
            return
        end        
 
        -- 重置巷道内货位权重
        strCondition = "S_WH_CODE = '"..wh_code.."' AND S_AREA_CODE = '"..area_code.."' AND N_AISLE = "..lane_no
        nRet, strRetInfo = reset_lane_loc_weight( strLuaDEID, strCondition )
        if (nRet ~= 0) then lua.Error( strLuaDEID, debug.getinfo(1), "reset_lane_loc_weight失败! " .. strRetInfo) end
    end
end