lzh
2025-06-24 13c4a636539584ab977fddacfae884b3ec250aee
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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
ÿþ--[[
 x: GT-100-13
  Tðy: ýVêûN¡RÞV¥b
 \O€: LZH
 eQãSýQpeÿTaskStatus
 ŸRý€ô‹f: ¥c6eýVꁄvûN¡RԏÞV¶r`
    “eQpencÿ                                                                                        
    {    
        "feed_no": "xxx",  /UNx ÿ(uŽN¥cãS!hŒš ÿ؞¤‹ubGUID
        "feed_type": "xxx",  ÍSˆ™{|‹W 1=ûN¡R_ËYÿ2=ûN¡RŒ[bÿ3=ûN¡R_8^ÿ4=ûN¡RÖSˆmÿ5=ûN¡Rôf9eÿ…_š[    ÿ6='ir‚‚¹p
        "task_type": "xxx" ,  ûN¡R{|‹W 1='ireQ“^ÿ2='irúQ“^ÿ3=XbØvÄ~eQ“^ÿ4=XbØvÄ~úQ“^ÿ5=ûy¨Rÿ NǏ“^MO    ÿÿ6= T÷]Sûy“^ÿ7=^— T÷]Sûy“^
        "task_no": "xxx",  ûN¡R÷S USXbØv/UNûN¡R÷S
        "mat_code": "xxx", 'irRFID
        "cur_station_no": "xxx", S_MRMOn
        "weight": "xxx", ðy͑͑ϑ
        "feed_time": "xxx" ÍSˆ™öeô•
    }
 
    Yt;‘
    -- step1 ã‰g¥cãS O„v datajson ÂSpe
    -- step2 !hŒšÅ_ OW[µk/f&T:Nzz ÿ:NzzR¥b•
    -- step3 ÍSˆ™{|‹W 2 ¾‹nûN¡RŒ[b 3 ¥b• 4 ¾‹nûN¡R¶r`:NÖSˆmv^㉕
 ØSôf†SòS:
    V1.0 LZH 20250121 feed_type = 3Rôf°eå]MO_8^áOo`
    V2.0 LZH 20250213 °ežXðy͑͑ϑW[µkŒT{|‹W
 --]]
wms_cntr = require("wms_container")
require("GT-Base")
wms_task = require("wms_task")
function GZTaskStatus(strLuaDEID)
    local nRet, in_date, strRetInfo
    -- step1 ·ƒÖS¥cãSpenc
    nRet, in_date = m3.GetSysDataJson(strLuaDEID)
    if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "WCStoreCallback àeÕl·ƒÖSpencS!" .. in_date) end
 
 
    -- step2 $R­e Å_kXy˜ /f&Tý    g<Pÿ¡l<P¥b•ԏÞV
    local task_no = in_date.task_no
    if (task_no == nil or task_no == '') then lua.Error(strLuaDEID, debug.getinfo(1), "ûN¡R÷S Ný€:Nzz!") end
    local cntr_code = in_date.cntr_code
    if (cntr_code == nil or cntr_code == '') then lua.Error(strLuaDEID, debug.getinfo(1), "RFID Ný€:Nzz!") end
    local feed_type = tonumber(in_date.feed_type)
    if (feed_type == nil) then lua.Error(strLuaDEID, debug.getinfo(1), "ÍSˆ™{|‹W Ný€:Nzz!") end
    local task_type = tonumber(in_date.task_type)
    if (task_type == nil) then lua.Error(strLuaDEID, debug.getinfo(1), "ûN¡R{|‹W Ný€:Nzz!") end
    local cur_station_no = in_date.cur_station_no -- S_MRMOn
    -- V2.0 LZH °ežX͑ϑW[µk
    local weight = in_date.weight                 -- ðy͑͑ϑ
    local err_msg = in_date.err_msg               -- ÍSˆ™{|‹W:N3öe O„vå]MO_8^áOo`
 
    -- ·ƒÖSûN¡R-N„v¹[hVxŒTwËY'MOx
    local task
    nRet, task = wms_task.GetInfo(strLuaDEID, task_no)
    if (nRet ~= 0) then return end
    
    -- ·ƒÖS\ONáOo`
    local condition = "S_CODE = '" .. task.op_code .. "'"
    nRet, operation = m3.GetDataObjByCondition(strLuaDEID, "Operation", condition)
    if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), operation) end
    lua.Debug(strLuaDEID, debug.getinfo(1), 'operation:', operation)
 
 
    if (task.bs_state == 3) then
        lua.Error(strLuaDEID, debug.getinfo(1), "ûN¡Rò]Œ[b!")
    elseif (task.bs_state == 4) then
        lua.Error(strLuaDEID, debug.getinfo(1), "ûN¡R_8^!")
    end
 
    -- ÍSˆ™{|‹W 2 ¾‹nûN¡RŒ[b 3 ¥b• 4 ¾‹nûN¡R¶r`:NÖSˆmv^㉕
    if (feed_type == 2) then
        lua.Debug(strLuaDEID, debug.getinfo(1), 'task:', task)
        lua.Debug(strLuaDEID, debug.getinfo(1), 'ýVêûN¡RÍSˆ™ÂSpe:', in_date)
        -- !hŒšÈ~¹pMOn/f&T OÂS
        if (task.op_name == '‰|™eeQ“^' or task.op_name == 'Ëz“^úQ“^' or task.op_name == 'Ǒ-'' or task.op_name == '|TëSzzXb' or task.op_name == 'ûy“^' or task.op_name == '‰|™eúQ“^') then
            if (cur_station_no == nil or cur_station_no == '') then
                lua.Error(strLuaDEID, debug.getinfo(1), "È~¹p*g OÂS!")
            end
            if(task.op_name == 'ûy“^')then
                local ext_data    = json.decode(operation.ext_data)
                local type = ext_data.type
                if(tonumber(type) == 3)then
                    goto back
                end
            end
            cur_station_no = wms_base.Get_sConst(strLuaDEID, cur_station_no)
            lua.Debug(strLuaDEID, debug.getinfo(1), 'cur_station_no:', cur_station_no)
            task.end_loc_code = cur_station_no
            lua.Debug(strLuaDEID, debug.getinfo(1), 'task:', task)
            nRet, strRetInfo = wms_task.Update(strLuaDEID, task)
            if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "ôf°eûN¡RÈ~¹p1Y%!" .. strRetInfo) end
        end
        
        ::back::
 
 
        -- úQ“^àe—Ñ~š[È~¹p
        if (task.op_name == 'Ëz“^úQ“^' or task.op_name == '|TëSzzXb' or task.op_name == 'Ǒ-'' or task.op_name == '¹pù[¹púQ“^') then
            -- ¹[hV'MOã‰Ñ~
            nRet, strRetInfo = wms_wh.Loc_Container_Unbinding(strLuaDEID, task.start_loc_code, cntr_code,
                "Ñ~š[ã‰Ñ~¹eÕl-û|ß~",
                "Œ[b")
            if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), ''MO¹[hVã‰Ñ~1Y%!' .. strRetInfo) end
        elseif (task.op_name == 'ûy“^') then
            -- ·ƒÖS\ONáOo`
            local condition = "S_CODE = '" .. task.op_code .. "'"
            nRet, operation = m3.GetDataObjByCondition(strLuaDEID, "Operation", condition)
            if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), operation) end
            
            -- ã‰g\ON-N„vibU\ÂSpe
            local ext_data, success
            success, ext_data = pcall(json.decode, operation.ext_data)
            if (success == false) then
                lua.Error(strLuaDEID, debug.getinfo(1), "operation_obj.ext_data -N…Q¹[JSON<h_ NTÕl!")
            end
            local type = ext_data.type -- 1 ‰|™eŒèb,dЏ 
    
            -- ¹[hV'MOã‰Ñ~
            nRet, strRetInfo = wms_wh.Loc_Container_Unbinding(strLuaDEID, task.start_loc_code, cntr_code,
                "Ñ~š[ã‰Ñ~¹eÕl-û|ß~",
                "Œ[b")
            if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), ''MO¹[hVã‰Ñ~1Y%!' .. strRetInfo) end
 
            if(tonumber(type) == 3)then
                -- ¹[hV'MOÑ~š[
                nRet, strRetInfo = wms_wh.Loc_Container_Binding(strLuaDEID, task.end_loc_code, cntr_code, "Ñ~š[ã‰Ñ~¹eÕl-û|ß~",
                    "Œ[b")
                if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), ''MO¹[hVÑ~š[1Y%!' .. strRetInfo) end
            end
            
        elseif (task.op_name ~= '‰|™eeQ“^' and task.op_name ~= '‰|™eúQ“^') then
            -- ¹[hV'MOÑ~š[
            nRet, strRetInfo = wms_wh.Loc_Container_Binding(strLuaDEID, task.end_loc_code, cntr_code, "Ñ~š[ã‰Ñ~¹eÕl-û|ß~",
                "Œ[b")
            if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), ''MO¹[hVÑ~š[1Y%!' .. strRetInfo) end
        end
 
        -- :_6RûN¡RŒ[b
        nRet, strRetInfo = wms.wms_TaskFinish(strLuaDEID, task_no)
        if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "ûN¡Rx='" .. task_no .. "'„vûN¡R¾‹nŒ[b1Y%!" .. strRetInfo) end
 
        -- žX R ûN¡R¨R\O ù[aŒ
        local task_action = m3.AllocObject(strLuaDEID, "Task_Action")
        task_action.task_code = task_no
        task_action.action_code = 2
        task_action.action = "ýVê,dЏŒ[b"
        task_action.eq_code = "system"
        task_action.eq_type_name = 'Œ[b'
        nRet, strRetInfo = m3.CreateDataObj(strLuaDEID, task_action)
        if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), 'Rú^0ûN¡R¨R\O0ù[aŒ1Y%!' .. strRetInfo) end
    elseif (feed_type == 3) then
        if (cur_station_no == nil or cur_station_no == '') then lua.Error(strLuaDEID, debug.getinfo(1), '_8^å]MO Ný€:Nzz!') end
        cur_station_no = wms_base.Get_sConst(strLuaDEID, cur_station_no)
 
        -- 9hncå]MOîO9e_8^áOo`
        local condition = "S_START_LOC = '" .. cur_station_no .. "'"
        local strSetAttr = "S_ERR_MSG = '" .. err_msg .. "'"
        nRet, strRetInfo = mobox.updateDataAttrByCondition(strLuaDEID, "GT_PDA_Station", condition, strSetAttr)
        if (nRet ~= 0) then
            lua.Error(strLuaDEID, debug.getinfo(1), "å]MO_8^áOo`1Y%!" .. strRetInfo)
        end
    elseif (feed_type == 4) then
        lua.Debug(strLuaDEID, debug.getinfo(1), 'task:', task)
        lua.Debug(strLuaDEID, debug.getinfo(1), 'ýVêûN¡RÍSˆ™ÂSpe:', in_date)
        if (task.op_name == 'ýVêzzXbÞV“^' or task.op_name == 'Ëz“^eQ“^' or task.op_name == '‰|™eeQ“^') then
            -- Ù~ÖSˆm„vûN¡R㉕
            nRet, strRetInfo = wms.wms_UnlockByTask(strLuaDEID, task_no)
            if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "wms_UnlockByTask 1Y%! " .. strRetInfo) end
            -- ¾‹nûN¡R¶r`:NÖSˆm
            local condition = "S_CODE = '" .. task_no .. "'"
            local strSetAttr = "N_B_STATE = " .. wms_base.Get_nConst(strLuaDEID, "ûN¡R¶r`-ÖSˆm") .. ", S_B_STATE = 'ÖSˆm'"
            nRet, strRetInfo = mobox.updateDataAttrByCondition(strLuaDEID, "Task", condition, strSetAttr)
            if (nRet ~= 0) then
                lua.Error(strLuaDEID, debug.getinfo(1), "¾‹nûN¡R¶r`1Y%!" .. strRetInfo)
            end
            -- ¾‹n\ON¶r`:NÖSˆm
            local condition = "S_CODE = '" .. task.op_code .. "'"
            strSetAttr = "N_B_STATE = " .. wms_base.Get_nConst(strLuaDEID, "\ON¶r`-ÖSˆm") .. ", S_B_STATE = 'ÖSˆm'"
            nRet, strRetInfo = mobox.updateDataAttrByCondition(strLuaDEID, "Operation", condition, strSetAttr)
            if (nRet ~= 0) then
                lua.Error(strLuaDEID, debug.getinfo(1), "¾‹n\ON¶r`1Y%!" .. strRetInfo)
            end
 
            -- Ëz“^eQ“^ŒT‰|™eeQ“^—‰îO9eeQ“^US¶r`:N/T(uv^¾‹n/}¡‹Xbpe -1
            if(task.op_name == 'Ëz“^eQ“^' or task.op_name == '‰|™eeQ“^')then
                -- ¹[hV'ÁTfÆ~
                local cg_detail
                condition = "S_CNTR_CODE = '" .. cntr_code .. "'"
                nRet, cg_detail = m3.GetDataObjByCondition(strLuaDEID, "CG_Detail", condition)
                if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), cg_detail) end
 
                if(tonumber(cg_detail.is_tl) == 1)then
                    return
                end
 
                -- ·ƒÖSeQ“^USnc4YáOo`
                local incoming_info
                condition = "S_ORDER_NO = (SELECT S_ORDER_NO FROM TN_GT_Label_Crad WHERE S_SERIAL_NO = '" .. cg_detail.serial_no .. "')"
                nRet, incoming_info = m3.GetDataObjByCondition(strLuaDEID, "GT_Incoming_Info", condition)
                if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), incoming_info) end
 
                -- $R­eeQ“^USnc4Y„vXbpe/f&T:N0
                if(tonumber(incoming_info.cntr_qty) == 0)then
                    return
                end
 
                -- îO9eeQ“^USnc4Y„v¶r`ŒT/}¡‹Xbpe -1
                condition = "S_ORDER_NO = '" .. incoming_info.order_no .. "'"
                local strSetSQL = "S_STATE = 'Œ[b',N_ACC_PACK_QTY = N_ACC_PACK_QTY - 1"
                nRet, strRetInfo = mobox.updateTableAttrByCondition(strLuaDEID, "TN_GT_Packing_Order", condition,strSetSQL)
                if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), strRetInfo) end
            end
        end
    elseif (feed_type == 6) then
        if (cur_station_no == nil or cur_station_no == '') then lua.Error(strLuaDEID, debug.getinfo(1), '‚‚¹på]MO Ný€:Nzz!') end
        nRet, a = mobox.getDictItemIInfo("GT_TaskNode")
        if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1),"getDictItemIInfo 1Y%!" .. a) end
        a = json.decode(a)
        
        local cur_station_name = ''
        for i = 1,#a do
            if(a[i].name == cur_station_no)then
                cur_station_name = a[i].value
            end
        end
        
        if(cur_station_name == '')then
            lua.Error(strLuaDEID, debug.getinfo(1),"Am z‚‚¹p¡l    gô~¤b'"..cur_station_no.."'Ùz¹p!")
        end
        
        -- local cur_station_name = wms_base.GetDictItemName(strLuaDEID, "GT_TaskNode", cur_station_no)
        -- žX R ûN¡R¨R\O ù[aŒ
        local task_action = m3.AllocObject(strLuaDEID, "Task_Action")
        task_action.task_code = task.code
        task_action.action_code = cur_station_no
        task_action.action = cur_station_name
        task_action.eq_code = "system"
        task_action.eq_type_name = cur_station_name
        nRet, strRetInfo = m3.CreateDataObj(strLuaDEID, task_action)
        if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), 'Rú^0ûN¡R¨R\O0ù[aŒ1Y%!' .. strRetInfo) end
 
        -- V2.0 LZH °ežX{|‹W8 eQ“^͑ϑ
N¥b
    elseif (feed_type == 8) then
        lua.Debug(strLuaDEID, debug.getinfo(1), 'task:', task)
        lua.Debug(strLuaDEID, debug.getinfo(1), 'ýVêûN¡RÍSˆ™ÂSpe:', in_date)
        -- ·ƒÖS¹[hV'ÁTfÆ~áOo`
        local strCondition = "S_CNTR_CODE = '" .. cntr_code .. "'"
        local cg_detail
        nRet, cg_detail = m3.GetDataObjByCondition(strLuaDEID, "CG_Detail", strCondition)
        if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), '·ƒÖS¹[hV'ÁTáOo`1Y%!' .. cg_detail) end
 
        -- îO9eeQ“^USncLˆ„vðy͑peϑáOo`
        strCondition = "S_SERIAL_NO = '" .. cg_detail.serial_no .. "'"
        local strSetAttr = "S_WEIGHT = '" .. weight .. "'"
        nRet, strRetInfo = mobox.updateDataAttrByCondition(strLuaDEID, "GT_Label_Crad", strCondition, strSetAttr)
        if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "ôf°e0¹[hV0•¶r`1Y%!" .. strRetInfo) end
    end
end