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
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
ÿþ-- š[INýQpe(uŽNÆbRW[&{2Nv^lbc:NpeW[ƖT
local function splitAndCollectNumbers(str)
    local numbers = {}
    for num in string.gmatch(str, "%d+") do
        numbers[tonumber(num)] = true
    end
    return numbers
end
 
-- š[INýQpe(uŽN~búQ$N*NƖT-N͑T„vpeW[v^üb¥cbW[&{2N
local function findCommonNumbers(strA, strB)
    local setA = splitAndCollectNumbers(strA)
    local setB = splitAndCollectNumbers(strB)
    local commonNumbers = {}
    for num in pairs(setA) do
        if setB[num] then
            table.insert(commonNumbers, tostring(num))
        end
    end
    return table.concat(commonNumbers, ",")
end
 
-- [
-- StockInquiry  “^X[ågâ‹
-- 10·ƒÖS÷]S'MO;`pe
-- 20·ƒÖSán'MO;`pe
-- 30ÿán'MO;`pe / ÷]S;`pe    ÿ* 100 = án'MO~vRÔk
-- 40$R­eán'MO“^X[/f&T¾0R80%,¡l¾0RRԏÞVïSeQ“^÷]S
-- param:
--      str_roadway   ÷]0R
-- ]
local function StockInquiry(strLuaDEID)
    -- ·ƒÖS*g»QÓ~„v÷]S
    local strCondition = "S_AREA_CODE = 'LK' AND N_LOCK_STATE = 0"
    local nRet, roadway = m3.QueryDataObject(strLuaDEID, "Roadway", strCondition)
    if (nRet ~= 0) then
        lua.Error(strLuaDEID, debug.getinfo(1), 'ågâ‹÷]SáOo`1Y%' .. roadway)
    end
    if (roadway == nil or roadway == '') then
        lua.Error(strLuaDEID, debug.getinfo(1), '¡l    gïSeQ“^„v÷]S!')
    end
 
    local str = ''
    for i = 1, #roadway do
        local attrs = roadway[i].attrs
        attrs = m3.KeyValueAttrsToObjAttr(attrs)
        if (attrs == nil) then
            goto coroutine
        end
 
        str = str .. attrs.N_ROADWAY .. ","
        ::coroutine::
    end
    -- »Sd–gTN*N,
    str = lua.trim_laster_char(str)
    lua.Debug(strLuaDEID, debug.getinfo(1), "str", str)
    return 0, str
end
 
--[[
 x: GT-40-37
  Tðy: ûN¡RŒ[b
 \O€:
 eQãSýQpeÿTaskFinish
 ŸRý€ô‹f:
 ØSôf†SòS:
 --]]
wms_op = require("wms_operation")
wms_cntr = require("wms_container")
require("GT_InAndOutboundPolicies")
function FLTaskFinish(strLuaDEID)
    local nRet, strRetInfo
 
    -- ·ƒÖSS_MR\ONù[aŒ
    local operation
    nRet, operation = m3.GetSysCurEditDataObj(strLuaDEID, "Operation")
    if (nRet ~= 0) then
        lua.Error(strLuaDEID, debug.getinfo(1), operation)
    end
 
    -- ·ƒÖSibU\pencÂSpe
    local ext_data = json.decode(operation.ext_data)
    local delivery_no = ext_data.delivery_no -- N¡RUS÷S:N úQ“^US÷S
    lua.Debug(strLuaDEID, debug.getinfo(1), 'ext_data', ext_data)
 
    -- ·ƒÖSûN¡Rù[aŒ
    local task
    nRet, task = m3.SysInputParamToDataObj(strLuaDEID, "Task")
    if (nRet ~= 0) then
        lua.Error(strLuaDEID, debug.getinfo(1), task)
    end
 
    -- $R­eûN¡RÈ~¹pŒT\ONÈ~¹p/f&TNô,NôR¾‹n\ONûN¡RŒ[bv^͑n“^X[
    if (task.end_loc_code == operation.end_loc_code) then
        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
 
        -- ¹[hV㉕
        local container
        nRet, container = wms_cntr.GetInfo(strLuaDEID, operation.cntr_code)
        if (nRet ~= 0) then
            lua.Error(strLuaDEID, debug.getinfo(1), '·ƒÖS¹[hVù[aŒ1Y%!' .. container)
        end
        nRet, strRetInfo = wms_cntr.SetLock(strLuaDEID, container, "•{|‹W-àe", "àe")
        if (nRet ~= 0) then
            lua.Error(strLuaDEID, debug.getinfo(1), 'XbØv¹[hV㉕1Y%!' .. strRetInfo)
        end
 
        -- ¾‹núQ“^USfÆ~¶r`:NŒ[b
        local strCondition = "S_DO_NO = '" .. delivery_no .. "'"
        local strSetSQL_update = " S_STATE = 'Œ[b'"
        nRet, strRetInfo = mobox.updateDataAttrByCondition(strLuaDEID, "GT_SO_Detail", strCondition, strSetSQL_update)
        if (nRet ~= 0) then
            lua.Error(strLuaDEID, debug.getinfo(1), "îO9eúQ“^USnc¶r`1Y%ÿ" .. strRetInfo)
        end
 
        -- ¾‹núQ“^US¶r`:NŒ[b
        strCondition = "S_DO_NO = '" .. delivery_no .. "'"
        strSetSQL_update = " S_STATE = 'Œ[b'"
        nRet, strRetInfo = mobox.updateDataAttrByCondition(strLuaDEID, "GT_Stock_Out", strCondition, strSetSQL_update)
        if (nRet ~= 0) then
            lua.Error(strLuaDEID, debug.getinfo(1), "îO9eúQ“^USnc¶r`1Y%ÿ" .. strRetInfo)
        end
 
        --  Rd–¹[hV'ÁTfÆ~°‹U_
        strCondition = "S_CNTR_CODE = '" .. operation.cntr_code .. "'"
        nRet, strRetInfo = mobox.deleteDataObject(strLuaDEID, "CG_Detail", strCondition)
        if (nRet ~= 0) then
            lua.Error(strLuaDEID, debug.getinfo(1), strRetInfo)
        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
 
        -- S_ûN¡R„vÈ~¹p:N    N|iÞV“^ãSRRú^ŒNµkX›W:gûN¡R
    elseif (task.end_loc_code == wms_base.Get_sConst(strLuaDEID, "sO-    N|iJS¢”ÞV“^ãS") or task.end_loc_code ==
        wms_base.Get_sConst(strLuaDEID, "sO-    N|ihQ¢”ÞV“^ãS")) then
        -- ÇûN¡R„vÈ~¹p·ƒÖSæSN¹„vlÐ/ÞV“^ãS
        local end_loc
        if (task.end_loc_code == wms_base.Get_sConst(strLuaDEID, "sO-    N|iJS¢”ÞV“^ãS")) then
            nRet, end_loc = wms_wh.Location_GetInfo(strLuaDEID, "THREE-QGCKK-QY")
            if (nRet ~= 0) then
                lua.Error(strLuaDEID, debug.getinfo(1), "WMS_Location_GetInfo1Y%! " .. end_loc)
            end
        else
            nRet, end_loc = wms_wh.Location_GetInfo(strLuaDEID, "THREE-BGCKK-QY")
            if (nRet ~= 0) then
                lua.Error(strLuaDEID, debug.getinfo(1), "WMS_Location_GetInfo1Y%! " .. end_loc)
            end
        end
 
        -- ·ƒÖSïSeQ“^÷]S
        local op_num, roadway
        local str
        nRet, str = StockInquiry(strLuaDEID)
        str = findCommonNumbers(str, "3,4")
        if (str == '') then
            lua.Error(strLuaDEID, debug.getinfo(1), "‰|™eŒèb¡l    gïSRM‘„v÷]S!")
        end
        local roadway_list = lua.split(str, ",")
        for i = 1, #roadway_list do
            -- ·ƒÖS÷]SûN¡Rpeϑ
            local strCondition = "N_ROADWAY = " .. roadway_list[i] .. " AND N_B_STATE = 1"
            nRet, strRetInfo = mobox.getDataObjCount(strLuaDEID, "Task", strCondition)
            if (nRet ~= 0) then
                lua.Error(strLuaDEID, debug.getinfo(1), "getDataObjCount 1Y%! " .. strRetInfo)
            end
            if (op_num == nil) then
                op_num = lua.StrToNumber(strRetInfo)
                roadway = roadway_list[i]
            elseif (tonumber(op_num) >= lua.StrToNumber(strRetInfo)) then
                op_num = lua.StrToNumber(strRetInfo)
                roadway = roadway_list[i]
            end
        end
        if (roadway == nil) then
            lua.Error(strLuaDEID, debug.getinfo(1), "‰|™eŒèb¡l    gïSRM‘„v÷]S!")
        end
 
        -- Rú^ûN¡R
        local new_task = m3.AllocObject(strLuaDEID, "Task")
        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-Ëz“^eQ“^,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
        new_task.end_wh_code = end_loc.wh_code
        new_task.end_area_code = end_loc.area_code
        new_task.end_loc_code = end_loc.code
        new_task.roadway = roadway
        new_task.schedule_type = wms_base.Get_nConst(strLuaDEID, "Œ¦^{|‹W-ýVê")
        nRet, new_task = m3.CreateDataObj(strLuaDEID, new_task)
        if (nRet ~= 0) then
            lua.Error(strLuaDEID, debug.getinfo(1), "Rú^û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, new_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
 
        -- ·ƒÖSw¹pÑ~š[„vWCSÙz¹p
        local condition = "S_VALUE = '" .. new_task.start_loc_code .. "' AND S_NOTE NOT LIKE '%ؚ¦^ĉ<hÙzðS%'"
        nRet, strRetInfo = m3.GetDataObjByCondition(strLuaDEID, "WMS_Const", condition)
        if (nRet ~= 0) then
            lua.Error(strLuaDEID, debug.getinfo(1), "·ƒÖS08^ϑ0áOo`1Y%! " .. strRetInfo)
        end
        local start_loc_code_zd = strRetInfo.name
        condition = "S_VALUE = '" .. new_task.end_loc_code .. "' AND S_NOTE NOT LIKE '%ؚ¦^ĉ<hÙzðS%'"
        nRet, strRetInfo = m3.GetDataObjByCondition(strLuaDEID, "WMS_Const", condition)
        if (nRet ~= 0) then
            lua.Error(strLuaDEID, debug.getinfo(1), "·ƒÖS08^ϑ0áOo`1Y%! " .. strRetInfo)
        end
        local end_loc_code_zd = strRetInfo.name
 
        -- Œ(uýVꁄvûN¡R NÑS¥cãS
        local strCode = lua.guid() -- u§NN*NGUIDW[&{2N
        local str_day_time = os.date("%Y-%m-%d %H:%M:%S")
        local url = wms_base.Get_sConst(strLuaDEID, "WCS-url")
        local strurl = url .. "/create"
        local strHeader = ""
        local strBody = {}
        local data = {
            req_no = strCode,
            task_type = 5, -- 1='ireQ“^ÿ2='irúQ“^ÿ3=XbØvÄ~eQ“^ÿ4=XbØvÄ~úQ“^ÿ5=ûy¨Rÿ NǏ“^MO    ÿÿ6= T÷]Sûy“^;7= N T÷]Sûy“^
            task_no = new_task.code,
            tunnel_no = roadway,
            from_pos = start_loc_code_zd,
            to_pos = end_loc_code_zd,
            mat_code = operation.cntr_code,
            mat_type = cg_detail.item_code,
            mat_memo = cg_detail.item_name,
            req_time = str_day_time
        }
        strBody[1] = data
        lua.Debug(strLuaDEID, debug.getinfo(1), 'strBody', strBody)
        nRet, strRetInfo = CreateInterfaceExc(strLuaDEID, strurl, strHeader, strBody, "WCS", "ûN¡RRú^")
        if (nRet ~= 0) then
            lua.Error(strLuaDEID, debug.getinfo(1), "Œ(u¥cãS1Y%!" .. strRetInfo)
        end
        -- ¾‹n¶r`*g¨c
        wms_task.SetStateByCode(strLuaDEID, new_task.code, "ûN¡R¶r`-ò]¨c")
    elseif (tonumber(task.type) == tonumber(wms_base.Get_nConst(strLuaDEID, "ûN¡R{|‹W-Ëz“^eQ“^,dЏ"))) then
        local end_loc
        nRet, end_loc = wms_wh.Location_GetInfo(strLuaDEID, operation.end_loc_code)
        if (nRet ~= 0) then
            lua.Error(strLuaDEID, debug.getinfo(1), "WMS_Location_GetInfo1Y%! " .. end_loc)
        end
 
        -- Rú^ûN¡R
        local new_task = m3.AllocObject(strLuaDEID, "Task")
        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
        new_task.end_wh_code = end_loc.wh_code
        new_task.end_area_code = end_loc.area_code
        new_task.end_loc_code = 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ú^ûN¡R1Y%!" .. new_task)
        end
 
        -- Ç¹[hV·ƒÖSir™eáOo`
        local cg_detail
        nRet, cg_detail = wms_cntr.Get_Container_Goods(strLuaDEID, new_task.cntr_code)
        nRet, cg_detail = m3.ObjAttrStrToLuaObj("CG_Detail", lua.table2str(cg_detail[1].attrs))
        if (nRet ~= 0) then
            lua.Error(strLuaDEID, debug.getinfo(1), cg_detail)
        end
 
        local data = {
            taskData = {
                taskNum = new_task.code,
                pickStation = new_task.start_loc_code,
                dropStation = new_task.end_loc_code,
                taskType = 5,
                carrierType = 1,
                priority = 1,
                source = "YCL"
            },
            partData = {
                rfid = operation.cntr_code,
                lotNumber = nil,
                partNumber = cg_detail.item_code,
                partDesc = cg_detail.item_code,
                partType = nil,
                weight = cg_detail.qty,
                unit = cg_detail.wu,
                maturityTime = nil,
                productionTime = nil,
                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
        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")
    end
end