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
ÿþ--[[
 x:
  Tðy: \ON/T¨R
 \O€:
 eQãSýQpeÿOperationStart
 ŸRý€ô‹f:
 ØSôf†SòS:
 --]]
wms_op = require("wms_operation")
wms_wh = require("wms_wh")
wms_task = require("wms_task")
require("GT_InAndOutboundPolicies")
require("GT-Base")
function FLOperationStart(strLuaDEID)
    local nRet, strRetInfo, store_loc, operation, end_loc
 
    -- ·ƒÖS\ONù[aŒ, ÎN\ONù[aŒ-N·ƒÖS{ibU\penc}, ÎN{ibU\penc}·ƒÖS¿~SO¾‹Yx
    nRet, operation = m3.GetSysCurEditDataObj(strLuaDEID, "Operation")
    if (nRet ~= 0) then
        lua.Error(strLuaDEID, debug.getinfo(1), "·ƒÖS\ONù[aŒ^\'`1Y%!" .. operation)
    end
 
    -- $R­e\ON̑/f&T    gfnx¹[hV ÿ‚Yœgò]Ï~fnx†N¹[hVô‹fúQ“^„v'ÁTò]Ï~nxš[
    if (operation.cntr_code == '') then
        lua.Error(strLuaDEID, debug.getinfo(1), "\ON-NÅ_{˜‰    g¹[hV÷S!")
    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
    lua.Debug(strLuaDEID, debug.getinfo(1), 'ö€™eeQ“^\ONibU\ÂSpe!', ext_data)
    local task_no = ext_data.task_no -- ûN¡R÷S
    local delivery_no = ext_data.delivery_no -- N¡RUS÷S:N úQ“^US÷S
    local mes_task_no = ext_data.mes_task_no
    local wms_task_no = ext_data.wms_task_no
    local wmsLot = ext_data.wmsLot
 
    -- ·ƒÖSw¹p“^:SáOo`
    local start_area_info, end_area_info
    local condition = "S_CODE = '" .. operation.start_area_code .. "'"
    nRet, start_area_info = m3.GetDataObjByCondition(strLuaDEID, "Area", condition)
    if (nRet ~= 0) then
        lua.Error(strLuaDEID, debug.getinfo(1), "·ƒÖS0“^:S0áOo`1Y%! " .. start_area_info)
    end
 
    -- ·ƒÖSÈ~¹p“^:SáOo`
    condition = "S_CODE = '" .. operation.end_area_code .. "'"
    nRet, end_area_info = m3.GetDataObjByCondition(strLuaDEID, "Area", condition)
    if (nRet ~= 0) then
        lua.Error(strLuaDEID, debug.getinfo(1), "·ƒÖS0“^:S0áOo`1Y%! " .. end_area_info)
    end
 
    -- $R­ew¹pŒTÈ~¹p/f&T(W TN¹ÿJS¢”/hQ¢”    ÿ ÿ N(WRꁨRŒèb
    if (start_area_info.note == end_area_info.note) then
        -- Rú^ AGV ,dЏûN¡R
        local task = m3.AllocObject(strLuaDEID, "Task")
        task.code = task_no
        task.op_code = operation.code -- \ONx
        task.op_name = operation.op_def_name
        task.factory = operation.factory -- å]‚S
        task.type = wms_base.Get_nConst(strLuaDEID, "ûN¡R{|‹W-AGVúQ“^,dЏ")
        task.cntr_code = operation.cntr_code
        -- w¹p
        task.start_wh_code = operation.start_wh_code
        task.start_area_code = operation.start_area_code
        task.start_loc_code = operation.start_loc_code
        -- È~¹p
        task.end_wh_code = operation.end_wh_code
        task.end_area_code = operation.end_area_code
        task.end_loc_code = operation.end_loc_code
        task.schedule_type = wms_base.Get_nConst(strLuaDEID, "Œ¦^{|‹W-AGV") -- ¾‹nŒ¦^{|‹W
        lua.Debug(strLuaDEID, debug.getinfo(1), "ûN¡RRú^MRáOo`", task)
 
        nRet, task = m3.CreateDataObj(strLuaDEID, task)
        if (nRet ~= 0) then
            lua.Error(strLuaDEID, debug.getinfo(1), "Rú^AGVeQ“^ûN¡R1Y%!" .. task)
        end
        -- ¾‹n¶r`*g¨c
        wms_task.SetStateByCode(strLuaDEID, task.code, "ûN¡R¶r`-ò]¨c")
 
        -- Ç¹[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 strCondition = "S_SERIAL_NO = '" .. cg_detail.serial_no .. "'"
        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
 
        -- üb¥cpenc NÑSAGVûN¡R
        --  NÑSûN¡RÙ~AGV
        local data = {
            taskData = {
                taskNum = task.code,
                pickStation = task.start_loc_code,
                dropStation = task.end_loc_code,
                taskType = 5,
                carrierType = 1,
                priority = 1,
                mesTaskNo = mes_task_no,
                wmsTaskNo = wms_task_no,
                level = incoming_Info.level,
                tyreType = "",
                supplier = incoming_Info.vendor,
                receiveLot = cg_detail.batch_no,
                subpool = "",
                source = "YCL",
                wmsLot = wmsLot
            },
            partData = {
                rfid = task.cntr_code,
                lotNumber = cg_detail.serial_no,
                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
            }
        }
        lua.Debug(strLuaDEID, debug.getinfo(1), "data", data)
        -- Œ(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
    else
        -- HQÎNw¹p,dЏ0Rù[”^„vÞV“^ãS,QÇX›W:glÐ0RæSN¹„vúQ“^ãS,(W|TëSAGV
        -- ·ƒÖSÈ~¹p 
        local end_loc
        if (start_area_info.note == 'JS¢”') then
            nRet, end_loc = wms_wh.GetLocInfo("THREE-BGHKK-01")
            if (nRet ~= 0) then
                lua.Error(strLuaDEID, debug.getinfo(1), "·ƒÖS'MOúW,gáOo`1Y%!" .. end_loc)
            end
        else
            nRet, end_loc = wms_wh.GetLocInfo("THREE-QGHKK-01")
            if (nRet ~= 0) then
                lua.Error(strLuaDEID, debug.getinfo(1), "·ƒÖS'MOúW,gáOo`1Y%!" .. end_loc)
            end
        end
 
        -- Rú^ AGV ,dЏûN¡R
        local task = m3.AllocObject(strLuaDEID, "Task")
        task.code = task_no
        task.op_code = operation.code -- \ONx
        task.op_name = operation.op_def_name
        task.factory = operation.factory -- å]‚S
        task.type = wms_base.Get_nConst(strLuaDEID, "ûN¡R{|‹W-AGVúQ“^,dЏ")
        task.cntr_code = operation.cntr_code
        -- w¹p
        task.start_wh_code = operation.start_wh_code
        task.start_area_code = operation.start_area_code
        task.start_loc_code = operation.start_loc_code
        -- È~¹p
        task.end_wh_code = end_loc.wh_code
        task.end_area_code = end_loc.area_code
        task.end_loc_code = end_loc.code
        task.schedule_type = wms_base.Get_nConst(strLuaDEID, "Œ¦^{|‹W-AGV") -- ¾‹nŒ¦^{|‹W
        lua.Debug(strLuaDEID, debug.getinfo(1), "ûN¡RRú^MRáOo`", task)
 
        nRet, task = m3.CreateDataObj(strLuaDEID, task)
        if (nRet ~= 0) then
            lua.Error(strLuaDEID, debug.getinfo(1), "Rú^AGVeQ“^ûN¡R1Y%!" .. task)
        end
        -- ¾‹n¶r`*g¨c
        wms_task.SetStateByCode(strLuaDEID, task.code, "ûN¡R¶r`-ò]¨c")
 
        -- Ç¹[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 strCondition = "S_SERIAL_NO = '" .. cg_detail.serial_no .. "'"
        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
 
        -- üb¥cpenc NÑSAGVûN¡R
        --  NÑSûN¡RÙ~AGV
        local data = {
            taskData = {
                taskNum = task.code,
                pickStation = task.start_loc_code,
                dropStation = task.end_loc_code,
                taskType = 5,
                carrierType = 1,
                priority = 1,
                mesTaskNo = mes_task_no,
                wmsTaskNo = wms_task_no,
                level = incoming_Info.level,
                tyreType = "",
                supplier = incoming_Info.vendor,
                receiveLot = cg_detail.batch_no,
                subpool = "",
                source = "YCL",
                wmsLot = wmsLot
            },
            partData = {
                rfid = task.cntr_code,
                lotNumber = cg_detail.serial_no,
                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
            }
        }
        lua.Debug(strLuaDEID, debug.getinfo(1), "data", data)
        -- Œ(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
    end
end