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
ÿþ--[[
 x: GT-40-22
  Tðy: ûN¡RŒ[b
 \O€:
 eQãSýQpeÿTaskFinish
 ŸRý€ô‹f:
    -- $R­eûN¡R{|‹W/f&T:NËz“^,dЏûN¡R ÿ/fRRú^ŒNµkûN¡R ÿ$R­eir™e/f&T‰>e(WR`)n“^ ÿ/fRÎNúQ“^ãS0R    N|iR`)n“^ ÿ N/fR0Rs^“^
    -- ûN¡R{|‹W:NAGV,dЏûN¡RR¾‹n\ONŒ[b ÿžX RÓN“^ϑhˆ
 ØSôf†SòS:
 --]]
require("WMS-BASE")
wms_op = require("wms_operation")
wms_cntr = require("wms_container")
require("GT_InAndOutboundPolicies")
wms_task = require("wms_task")
function TaskFinish(strLuaDEID)
    local nRet, strRetInfo, end_loc, area
 
    -- ·ƒÖSS_MR\ONù[aŒ
    local operation
    nRet, operation = m3.GetSysCurEditDataObj(strLuaDEID, "Operation")
    if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), operation) end
 
    -- ·ƒÖSûN¡Rù[aŒ
    local task
    nRet, task = m3.SysInputParamToDataObj(strLuaDEID, "Task")
    if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), task) end
 
    -- ‚YœgŒ[b„vûN¡R/f Ëz“^,dЏûN¡R ÿRú^ŒNµkûN¡R ÿÎNúQ“^ãS0R‰|™e“^
    if (task.type == wms_base.Get_nConst(strLuaDEID, "ûN¡R{|‹W-Ëz“^eQ“^,dЏ")) then
        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
        lua.Debug(strLuaDEID, debug.getinfo(1), 'eQ“^\ONibU\ÂSpe!', ext_data)
 
        -- Rú^AGVÉSf,dЏûN¡R
        local new_task           = m3.AllocObject(strLuaDEID, "Task")
        new_task.code            = ext_data.task_no
        new_task.op_code         = operation.code
        new_task.op_name         = operation.op_def_name
        new_task.factory         = operation.factory
        new_task.type            = wms_base.Get_nConst(strLuaDEID, "ûN¡R{|‹W-AGVeQ“^,dЏ")
        new_task.cntr_code       = operation.cntr_code
        -- w¹p:N
NN*NûN¡R„vÈ~¹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:N
Nb—·ƒÖS„vÈ~¹p
        new_task.end_wh_code     = operation.end_wh_code
        new_task.end_area_code   = operation.end_area_code
        new_task.end_loc_code    = operation.end_loc_code
 
        new_task.schedule_type   = wms_base.Get_nConst(strLuaDEID, "Œ¦^{|‹W-AGV")
        nRet, new_task           = m3.CreateDataObj(strLuaDEID, new_task)
        if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "Rú^AGV,dЏûN¡R1Y%!" .. new_task) end
 
        -- Ç¹[hV·ƒÖSir™eáOo`
        local cg_detail_list, cg_detail
        nRet, cg_detail_list = wms_cntr.Get_Container_Goods(strLuaDEID, task.cntr_code)
        nRet, cg_detail = m3.ObjAttrStrToLuaObj("CG_Detail", lua.table2str(cg_detail_list[1].attrs))
        if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), cg_detail) end
 
        local label_crad
        local vendor
        local strCondition = "S_SERIAL_NO = '" .. cg_detail.serial_no .. "'"
        if(tonumber(cg_detail.is_tl) == 1)then
            nRet, label_crad = m3.GetDataObjByCondition(strLuaDEID, "GT_ROM", strCondition, "T_CREATE DESC")
            if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1),"·ƒÖSAm4l÷SáOo`1Y%!" .. label_crad) end
            vendor = label_crad.vendor
        else
            nRet, label_crad = m3.GetDataObjByCondition(strLuaDEID, "GT_Label_Crad", strCondition, "T_CREATE DESC")
            if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1),"·ƒÖSAm4l÷SáOo`1Y%!" .. label_crad) end
            
            -- ·ƒÖSeQ“^USnc4YáOo`
            local incoming_Info
            strCondition = "S_DELIVERY_NO = '" ..
            label_crad.delivery_no .. "' AND N_DELIVERY_ROW_NO = '" .. label_crad.delivery_row_no .. "'"
            nRet, incoming_Info = m3.GetDataObjByCondition(strLuaDEID, "GT_Incoming_Info", strCondition, "T_CREATE DESC")
            if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "·ƒÖSeQ“^USnc4YáOo`1Y%!") end
            vendor = incoming_Info.vendor
        end
 
        local data = {
            taskData = {
                taskNum = new_task.code,
                pickStation = new_task.start_loc_code,
                dropStation = new_task.end_loc_code,
                taskType = 3,
                carrierType = 1,
                priority = 1,
                wmsTaskNo = "", -- úQ“^MbÙ~
                level = "", -- eQ“^I{§~/f؞¤‹„v
                tyreType = "",
                supplier = vendor,
                receiveLot = cg_detail.batch_no,
                subpool = "",
                source = "YCL"
            },
            partData = {
                rfid = task.cntr_code,
                lotNumber = nil,
                partNumber = cg_detail.item_code,
                partDesc = cg_detail.item_name,
                partType = nil,
                weight = cg_detail.qty,
                unit = cg_detail.wu,
                maturityTime = nil,
                productionTime = label_crad.product_date,
                stewingTime = nil,
                overdueTime = nil
            }
        }
        -- Œ(uAGVûN¡R NÑS
        local url = wms_base.Get_sConst(strLuaDEID, "AGV-url")
        local strurl = url .. "/CreateTask"
        local strHeader = ""
        local strBody = data
        lua.Debug(strLuaDEID, debug.getinfo(1), 'strurl:', strurl)
        lua.Debug(strLuaDEID, debug.getinfo(1), 'strBody:', strBody)
        nRet, strRetInfo = CreateInterfaceExc(strLuaDEID, strurl, strHeader, strBody, "AGV", "ûN¡RRú^")
        if (nRet ~= 0) then
            lua.Error(strLuaDEID, debug.getinfo(1), "Œ(uWCS¥cãS1Y%!" .. strRetInfo)
        end
 
        -- ¾‹n¶r`*g¨c
        wms_task.SetStateByCode(strLuaDEID, new_task.code, "ûN¡R¶r`-ò]¨c")
    else
        -- ‚YœgŒ[b„v/fAGV,dЏûN¡R ÿ¾‹n\ONŒ[b ÿžX RÓN“^ϑhˆ
        nRet, strRetInfo = wms_op.SetFinish(strLuaDEID, operation.code)
        if (nRet ~= 0) then
            lua.Error(strLuaDEID, debug.getinfo(1), "¾‹n\ON÷S='" .. operation.code .. "' „v\ONŒ[b1Y%!" .. strRetInfo)
        end
        -- ·ƒÖS¹[hV'ÁTfÆ~
        local cg_detail
        local strCondition = "S_CNTR_CODE = '" .. operation.cntr_code .. "'"
        nRet, cg_detail = m3.GetDataObjByCondition(strLuaDEID, "CG_Detail", strCondition)
        if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "m3.GetDataObjByCondition 1Y%!" .. cg_detail) end
 
        if (tonumber(cg_detail.is_fj) == 0) then
            -- ·ƒÖSeQ“^USncLˆáOo`
            local label_crad
            strCondition = "S_SERIAL_NO = '" .. cg_detail.serial_no .. "'"
            nRet, label_crad = m3.GetDataObjByCondition(strLuaDEID, "GT_Label_Crad", strCondition, "T_CREATE DESC")
            if (nRet == 1) then
                nRet, label_crad = m3.GetDataObjByCondition(strLuaDEID, "GT_ROM", strCondition, "T_CREATE DESC")
                if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "·ƒÖSAm4l÷SáOo`1Y%!" .. label_crad) end
            elseif (nRet > 1) then
                lua.Error(strLuaDEID, debug.getinfo(1), "·ƒÖSeQ“^USncLˆáOo`1Y%!" .. label_crad)
            end
 
            -- ·ƒÖSeQ“^USnc4YáOo`
            local incoming_Info
            strCondition = "S_DELIVERY_NO = '" ..label_crad.delivery_no.. "' AND N_DELIVERY_ROW_NO = '" .. label_crad.delivery_row_no .. "'"
            nRet, incoming_Info = m3.GetDataObjByCondition(strLuaDEID, "GT_Incoming_Info", strCondition, "T_CREATE DESC")
            if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "·ƒÖSeQ“^USnc4YáOo`1Y%!") end
 
            -- ‚YœgeQ“^US/fKbå]U_eQ„vR
            if (incoming_Info.type == 'Kbå]U_eQ') then
                -- Rú^0GTWMS Tek°‹U_0
                local sys_record = m3.AllocObject(strLuaDEID, "GTWMS_SYNC_RECORD")
                sys_record.delivery_no = incoming_Info.delivery_no
                sys_record.delivery_row_no = incoming_Info.delivery_row_no
                sys_record.lpn = cg_detail.serial_no
                sys_record.rfid = operation.cntr_code
                sys_record.lpnweight = cg_detail.qty
                sys_record.sku = cg_detail.item_code
                sys_record.batch_no = cg_detail.batch_no
                sys_record.remark3 = cg_detail.serial_no
                sys_record.type = "eQ“^ÞV O"
                lua.Debug(strLuaDEID, debug.getinfo(1), 'sys_record', sys_record)
                nRet, sys_record = m3.CreateDataObj(strLuaDEID, sys_record)
                if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), 'mobox Rú^0GTWMS Tek°‹U_0ù[aŒ1Y%!' .. sys_record) end
            else
                -- eQ“^Ó~œgÞV O
                local data
                local source = "GTWMSeQ“^ÞV O"
                nRet, data = StorageResult(strLuaDEID, operation.code, source)
                if (nRet ~= 0) then
                    lua.Error(strLuaDEID, debug.getinfo(1), "eQ“^Ó~œgÞV O1Y%!" .. data)
                end
                -- 9hnc\ON„vÈ~¹p“^:SÞV O“^MO
                if(operation.end_area_code == 'PFL' or operation.end_area_code == 'HWPFL')then
                    data.loc = 'LK007'
                elseif(operation.end_area_code == 'TFL' or operation.end_area_code == 'HWTFL')then
                    data.loc = 'LK005'
                end
                lua.Debug(strLuaDEID, debug.getinfo(1), 'data', data)
                -- Œ(uGT-WMS„vÞV O¥cãS
                local url = wms_base.Get_sConst(strLuaDEID, "GTWMS-url")
                local strurl = url
                local strHeader = ""
                local strBody = {
                    application = "GITI",
                    code = "WCS_ASN_WMS",
                    data = data
                }
 
                nRet, strRetInfo = CreateInterfaceExc(strLuaDEID, strurl, strHeader, strBody, "GTWMS", source)
                if (nRet ~= 0) then
                    lua.Error(strLuaDEID, debug.getinfo(1), "Œ(u¥cãS1Y%!" .. strRetInfo)
                end
            end
        else
            -- îO9e¹[hV'ÁTfÆ~„vhƋ:N YÀhúQ“^
            local condition = "S_CNTR_CODE = '" .. operation.cntr_code .. "'"
            local strSetSQL_update = "N_IS_FJ = 0"
            nRet, strRetInfo = mobox.updateDataAttrByCondition(strLuaDEID, "CG_Detail", condition, strSetSQL_update)
            if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "îO9e¹[hV'ÁTfÆ~1Y%ÿ" .. strRetInfo) end
        end
 
        -- ‚Yœg/f™eUSRîO9e™eUS¶r`:NŒ[b
        if (tonumber(cg_detail.is_tl) == 1) then
            local condition = "S_CNTR_CODE = '" .. operation.cntr_code .. "'"
            local strSetAttr = "S_STATE = 'Œ[b'"
            nRet, strRetInfo = mobox.updateDataAttrByCondition(strLuaDEID, "GT_ROM", condition, strSetAttr)
            if (nRet ~= 0) then
                lua.Error(strLuaDEID, debug.getinfo(1), "¾‹n¶r`1Y%!" .. strRetInfo)
            end
        end
        
        -- Í‘n“^:S“^X[
        nRet,strRetInfo = wms.wms_ResetInventory("Area", task.end_area_code)
        if (nRet ~= 0) then
            lua.Error(strLuaDEID, debug.getinfo(1), strRetInfo)
        end
    end
end