Jianw
2025-05-13 3b39fe3810c3ee2ec9ec97236c1769c5c85e062c
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
--[[
    编码: WMS-82-10
    名称: 批量入库测试-错误重置
    作者:HAN    
    日期:2025-1-29
 
    入口函数: ResetAllocation
 
    功能说明:
        从新进行货位分配计算
    更改记录:
 
--]]
 
wms_wh = require( "wms_wh" )
 
local function set_error_info( strLuaDEID, id, strErr )
    local nRet, strRetInfo
 
    local strSetSQL = "S_ERR = '"..strErr.."'"
    strCondition = "S_ID = '"..id.."'"
    nRet, strRetInfo = mobox.updateDataAttrByCondition(strLuaDEID, "TEST_Inbound", strCondition, strSetSQL)
    if (nRet ~= 0) then lua.Error( strLuaDEID, debug.getinfo(1), "设置【上架策略测试】信息失败!"..strRetInfo) end    
end
 
local function alloc_location( strLuaDEID, test )
    local item_info = {}
    local nRet, strRetInfo
 
    item_info.cntr_code = test.cntr_code
    item_info.item_code = test.item_code
    item_info.item_name = test.item_name
    item_info.batch_no = test.batch_no
 
    if ( test.area_code ~= '' ) then
        nRet, strRetInfo = wms.wms_GetAreaAvaliableLocByRule( strLuaDEID, test.area_code, test.put_away, lua.table2str(item_info) )
    else
        nRet, strRetInfo = wms.wms_GetWHAvaliableLocByRule( strLuaDEID, test.wh_code, test.put_away, lua.table2str(item_info) )
    end
    if ( nRet ~= 0 ) then
        lua.Debug( strLuaDEID, debug.getinfo(1), "根据上架策略计算可上架货位失败!", strRetInfo )
        set_error_info( strLuaDEID, test.id, "根据上架策略计算可上架货位失败! 见调试日志" )
        return
    end
    if ( strRetInfo == '')  then
        set_error_info( strLuaDEID, test.id, "根据上架策略没有符合条件的货位!" )
        return      
    end
    local success
    local ret_loc
    success, ret_loc = pcall( json.decode, strRetInfo)
    if ( success == false or ret_loc.loc_code == nil or ret_loc.loc_code == '') then 
        lua.Debug( strLuaDEID, debug.getinfo(1), "上架策略返回json不合法!", strRetInfo )
        set_error_info( strLuaDEID, test.id, "上架策略返回json不合法! 见调试日志" )
        return        
    end
 
    -- 不生产作业进行模拟,直接入库
    local loc
    nRet, loc = wms_wh.GetLocInfo( ret_loc.loc_code )
    if ( nRet ~= 0 )  then 
        lua.Debug( strLuaDEID, debug.getinfo(1), "WMS_GetLocInfo失败!", loc )
        set_error_info( strLuaDEID, test.id, "WMS_GetLocInfo失败! 见调试日志" )
        return       
    end 
    lua.Debug( strLuaDEID, debug.getinfo(1), "loc", loc )
 
    nRet, strRetInfo = wms_wh.Loc_Container_Binding( strLuaDEID, loc.code, test.cntr_code, "绑定解绑方法-系统",  "测试" )
    if ( nRet ~= 0 ) then
        lua.Debug( strLuaDEID, debug.getinfo(1), "货位容器绑定错误!", strRetInfo )
        set_error_info( strLuaDEID, test.id, "货位容器绑定错误! 见调试日志" )
        return        
    end              
 
    -- 加库区/库量表 (通过CG_Detail)
    nRet, strRetInfo = wms_base.Add_WHAreaQty_ByCGDetail(strLuaDEID, loc.wh_code, loc.area_code, test.cntr_code ) 
    if ( nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), strRetInfo ) end 
 
    local strSetSQL = "S_LOC_CODE = '"..loc.code.."', N_ROW = "..loc.row..", N_COL = "..loc.col..", N_LAYER = "..loc.layer
    strSetSQL = strSetSQL..", N_POS = "..loc.pos..", N_ROW_GROUP = "..loc.row_group..", N_AISLE = "..loc.aisle..", S_ERR=''"
    strCondition = "S_ID = '"..test.id.."'"
    nRet, strRetInfo = mobox.updateDataAttrByCondition(strLuaDEID, "TEST_Inbound", strCondition, strSetSQL)
    if (nRet ~= 0) then lua.Error( strLuaDEID, debug.getinfo(1), "设置【上架策略测试】信息失败!"..strRetInfo) end             
 
end
 
function ResetAllocation ( strLuaDEID ) 
    local nRet, strRetInfo
    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 strObjJson
    local success    
    local test = {}
    for n = 1, nCount do
        -- 检查一下N_B_STATE是否=3(错误)
        nRet, strObjJson = mobox.objAttrsToLuaJson( "TEST_Inbound", lua.table2str( objs[n].attrs ) )
        success, test = pcall( json.decode, strObjJson ) 
        test.id = lua.trim_guid_str( objs[n].id )
 
        lua.Debug( strLuaDEID, debug.getinfo(1), "test", test )
        if ( success == false ) then lua.Error( strLuaDEID, debug.getinfo(1), "objAttrsToLuaJson (Operation) 返回的的JSON格式不合法 !"..operation ) end
        if ( test.err ~= "" and test.loc_code == '' ) then
            alloc_location( strLuaDEID, test )
        end
 
    end
 
    -- 如果就是一行刷新当前行
    if ( nCount == 1 ) then
        local strAction = '[{"action_type":"refresh_cur_row","value":""}]'
        nRet, strRetInfo = mobox.setAction(strLuaDEID, strAction)
        if ( nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), "setAction错误: "..strRetInfo) end     
    end  
end