Jianw
2025-05-14 29f8b36ebb718d2051bf0e7e701973ec4419ee80
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
198
199
200
201
202
203
204
205
206
207
208
ÿþ--[[
    x: JX-300-02
     Tðy: StackerLocRequest
    \O€ÿHAN    
    åegÿ2025-1-29
 
    eQãSýQpeÿ main
              
    ŸRý€ô‹f:
        “eQ 
            {
                "requestPk":"PK000",
                "contNo":"FB-0029",
                "taskNo":"TA241017-00001",
                "contNo2":"",
                "taskNo2":"",
                "curPos":"L003",
                "isFull":1,
                "clientCode":"WCS",
                "reqTime":"2024-10-18 8:0:0"
            }
    ØSôf°‹U_:
--]]
 
wms_task = require( "wms_task" )
wms_op = require( "wms_operation" )
wms_wh = require( "wms_wh" )
jx_base = require( "jx_base" )
wms_alg = require( "wms_base_algorithm" )
 
-- 9hncûN¡R÷S~b0R\ON ÿŠb\ON„v¶r`¾‹n:N 1 
local function restart_operation( strLuaDEID, task_code, cntr_code, to_loc_code )
    local nRet, strRetInfo
    local task
 
    nRet, task = wms_task.GetInfo( strLuaDEID, task_code )
    -- ‚YœgûN¡R NX[(WbúQ• ÿ ÔÞV
    if ( nRet ~= 0 ) then return 1, "·ƒÖSûN¡Rù[aŒ1Y%!"..task  end
 
    local to_loc
    nRet, to_loc = wms_wh.GetLocInfo( to_loc_code )
    if ( nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), '·ƒÖS'MOáOo`1Y%! '..to_loc_code ) end      
 
    local operation
    nRet, operation = wms_op.GetInfo( strLuaDEID, task.op_code )
    if ( nRet ~= 0 ) then return 1, "·ƒÖS\ONù[aŒ1Y%!"..operation end
    if ( operation.bs_state ~= 6 ) then
        return 1, "ûN¡R'"..task_code.."'„v\ON¶r` NI{ŽN'I{…_', Ný€gbLˆÍ‘/T\ON!"
    end
    
    lua.Debug(strLuaDEID, debug.getinfo(1), "operation", operation)
    
    local strCondition = "S_CODE = '"..task.op_code.."'"
    local strUpdateSql = "N_B_STATE = 1, S_B_STATE = 'gbLˆ', S_END_WH = '"..to_loc.wh_code.."',"
    strUpdateSql = strUpdateSql.."S_END_AREA = '"..to_loc.area_code.."', S_END_LOC = '"..to_loc_code.."'"
    nRet, strRetInfo = mobox.updateDataAttrByCondition( strLuaDEID, "Operation", strCondition, strUpdateSql )
    if ( nRet ~= 0 ) then  return 2, "ôf°e0\ON0¶r`1Y%!"..strRetInfo end  
 
    local task_source
    if (operation.op_def_name == "è]fúQ“^" or operation.op_def_name == "è]feQ“^") then
        task_source = "è]f"
    else
        task_source = "è]ƒl"
    end
    
    -- Rú^“¿~,dЏûN¡R
    local task = m3.AllocObject(strLuaDEID,"Task")
 
    -- Rú^“:g,dЏûN¡R
    task.op_code = operation.code                            -- \ONx
    task.op_name = operation.op_def_name   
    task.source_sys = task_source
    new_task.factory = operation.factory                         -- å]‚S
    new_task.type = wms_base.Get_nConst(strLuaDEID, "ûN¡R{|‹W-X›W:geQ“^,dЏ") 
    new_task.cntr_code = cntr_code
    new_task.bs_no = operation.bs_no  
    
    -- w¹p
    new_task.start_wh_code = task.end_wh_code
    new_task.start_area_code  = task.end_area_code
    new_task.start_loc_code  = task.end_loc_code
    -- È~¹p
    new_task.end_wh_code  = to_loc.wh_code
    new_task.end_area_code  = to_loc.area_code
    new_task.end_loc_code  = to_loc_code
    new_task.schedule_type = wms_base.Get_nConst(strLuaDEID, "Œ¦^{|‹W-X›W:g") -- ¾‹nŒ¦^{|‹W
 
    -- È~¹p'MO R•
    new_task.bs_state = 2       -- Rú^1\/fgbLˆ¶r`
    nRet, new_task = m3.CreateDataObj(strLuaDEID, new_task)
    if (nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1),"Rú^X›W:gûN¡R1Y%!"..new_task) end
 
    -- 'MO ReQ“^•
    nRet, strRetInfo = wms.wms_LockLocation(strLuaDEID, new_task.end_loc_code, wms_base.Get_nConst( strLuaDEID, "•{|‹W-eQ“^•" ),
                                            new_task.code, new_task.op_code, new_task.op_name )
    if (nRet ~= 0) then return 1, "wms_LockLocation 1Y%!"..strRetInfo end  
    return 0, new_task.code
end
 
--[[
    —‰€Q†„vàQ*N˜: 
    1# WCSO NO͑ Y3u÷‹ ÿÔk‚Y3u÷‹†NN!k WMS Ù~ƒ[ԏÞV¡l6e0Rˆmo`?
]]
function LocRequest( strLuaDEID ) 
    local nRet, strRetInfo 
    local body
 
    -- ·ƒÖS¥cãS OeQ„vpenc
    nRet, body = m3.GetSysDataJson(strLuaDEID)  
    
    -- “eQpencÀhåg
    local cntr_num = 1
    local cntr_code1 = body.contNo
    local task_code1 = body.taskNo
    local cntr_code2
    local task_code2 = ''
    local cur_pos,ret_loc
    local roadway
    local operation
 
    if ( cntr_code1 == nil or cntr_code1 == '') then
        mobox.stopProgram( strLuaDEID, "contNoÅ_{˜    g<P!" ) 
        return
    end
    if ( task_code1 == nil or task_code1 == '') then
        mobox.stopProgram( strLuaDEID, "taskNoÅ_{˜    g<P!" ) 
        return
    end
 
    cntr_code2 = lua.Get_StrAttrValue( body.contNo2 )
    task_code2 = lua.Get_StrAttrValue( body.taskNo2 )
    if ( cntr_code2 ~= "") then 
        cntr_num = 2 
        if ( task_code2 == nil or task_code2 == '') then
            mobox.stopProgram( strLuaDEID, "taskNo2Å_{˜    g<P!" ) 
            return
        end        
    end
 
    cur_pos = body.curPos
    if ( cur_pos == nil or cur_pos == '') then
        mobox.stopProgram( strLuaDEID, "cur_posÅ_{˜    g<P!" ) 
        return
    end
    -- ·ƒÖS cur_pos „v'MOáOo`
    local loc
    nRet, loc = wms_wh.GetLocInfo( cur_pos )
    
    if ( nRet ~= 0 ) then 
        mobox.stopProgram( strLuaDEID, "·ƒÖS'MO'"..cur_pos.."'áOo`1Y%! "..loc ) 
        return
    end  
 
    -- ¡‹—{÷]S…Q'MO
    roadway = lua.Get_NumAttrValue( loc.ext_attr )            -- ·ƒÖS÷]S÷S
    if ( roadway <= 0 ) then
        mobox.stopProgram( strLuaDEID, "'MO'"..cur_pos.."'¾‹š[„v÷]SáOo`àeHe! " )
        return
    end
 
    local storage_arae
    nRet, storage_arae = wms_base.Get_sConst2( strLuaDEID, "™e±{“^X[¨P:S" )
    if ( nRet ~= 0 ) then
        lua.Stop( strLuaDEID, "û|ß~àeÕl·ƒÖS8^ϑ'™e±{“^X[¨P:S'")
        return
    end
 
    nRet, ret_loc = wms_alg.Get_Aisle_Empty_Loc( strLuaDEID, storage_arae, roadway, 0, 0, "", cntr_num  )
    if ( nRet ~= 0 ) then
        mobox.stopProgram( strLuaDEID, "¡‹—{÷]S…Q'MO1Y%!"..ret_loc ) 
        return
    end  
 
    nRet, strRetInfo = restart_operation( strLuaDEID, task_code1, cntr_code1, ret_loc.loc_code )
    if ( nRet ~= 0 ) then
        mobox.stopProgram( strLuaDEID, "restart_operation1Y%!"..strRetInfo ) 
        return        
    end  
    local new_task_code1 = strRetInfo
    local toPos1 = ret_loc.loc_code
    local new_task_code2 = ""
    local toPos2 = ""
 
    if ( task_code2 ~= '') then
        nRet, strRetInfo = restart_operation( strLuaDEID, task_code2, cntr_code2, ret_loc.adjacent_loc )
        if ( nRet ~= 0 ) then
            mobox.stopProgram( strLuaDEID, "restart_operation1Y%!"..strRetInfo ) 
            -- èla‰Šb
Nb—„vُ*NûN¡RRM‘„v'MO㉕
            wms.wms_UnlockLocation( strLuaDEID, ret_loc.loc_code, new_task_code1 )
            return                
        end 
        new_task_code2 = strRetInfo
        toPos2 = ret_loc.adjacent_loc
    end            
 
    local result = {
        taskCode1 = new_task_code1,
        toPos1 = toPos1,
        taskCode2 = new_task_code2,
        toPos2 = toPos2,
        requestPk = body.requestPk
    }
 
    lua.Debug(strLuaDEID, debug.getinfo(1), "response", result )
    mobox.returnValue(strLuaDEID, 1, table2str(result) )        
    
end