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
ÿþ--[[
     x: GT-40-36
      Tðy: \ON/T¨R-™eeQ“^
     \O€: LZH
     eQãSýQpeÿOperationStart
     ŸRý€ô‹f:
            -- ¡‹—{úQeQ“^È~¹p'MO
            -- (W\ON Nb—Rú^ûN¡R{|‹W = <AGVeQ“^,dЏ> „vûN¡R(Task) ÿŒ¦^û|ß~ ÿ¾‹Y:N AGV 
            -- eQ“^È~¹p'MO ReQ“^•
 
    YèlÿîvMRò]åwêS    g )Y6qö€\‰|™e —‰AGV,dЏ ÿvQÖN„v    cgqck8^eQ“^Am zp
     Ø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 OperationStart(strLuaDEID)
    local nRet, data, strRetInfo
 
    -- ·ƒÖS\ONù[aŒ
    local operation
    nRet, operation = m3.GetSysCurEditDataObj(strLuaDEID, "Operation")
    if (nRet ~= 0) then
        lua.Error(strLuaDEID, debug.getinfo(1), "·ƒÖS\ONù[aŒ^\'`1Y%!" .. operation)
    end
    lua.Debug(strLuaDEID, debug.getinfo(1), '™eeQ“^operationÂSpe!', operation)
 
    -- ã‰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 item_type = ext_data.item_type   -- ir™e{|‹W
    local isothermal = ext_data.isothermal -- /f&TR`)n
 
    -- Rú^,dЏûN¡R
    local task = m3.AllocObject(strLuaDEID, "Task")
    task.op_code = operation.code    -- \ONx
    task.op_name = "™eeQ“^"
    task.factory = operation.factory -- å]‚S
    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
 
    -- ·ƒÖSw¹p“^:SáOo`
    local area
    local strCondition = "S_CODE = '" .. operation.start_area_code .. "'"
    nRet, area = m3.GetDataObjByCondition(strLuaDEID, "Area", strCondition)
    if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "m3.GetDataObjByCondition 1Y%!" .. area) end
 
    -- Ç¹[hV·ƒÖSfÆ~áOo`
    local cg_detail
    nRet, cg_detail = wms_cntr.Get_Container_Goods(strLuaDEID, operation.cntr_code)
    if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "·ƒÖSxØváOo`1Y%!" .. cg_detail) end
    nRet, cg_detail = m3.ObjAttrStrToLuaObj("CG_Detail", lua.table2str(cg_detail[1].attrs))
    if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "ObjAttrStrToLuaObj1Y%! " .. cg_detail) end
    lua.Debug(strLuaDEID, debug.getinfo(1), 'cg_detail!', cg_detail)
 
    local store_loc
    -- îvMRò]åw—‰AGV,dЏ„vêS    g ir™e{|‹W:N )Y6qö€\‰|™e
    -- )Y6qö€ ŒNµkAGVûN¡R ÎN¿~¹“^0R¥csšMO ÎN¥csšMO0RËz“^
    task.type = wms_base.Get_nConst(strLuaDEID, "ûN¡R{|‹W-AGVeQ“^,dЏ")
    task.schedule_type = wms_base.Get_nConst(strLuaDEID, "Œ¦^{|‹W-AGV") -- ¾‹nŒ¦^{|‹W
    if (item_type == '‰|™e' or item_type == '}v­pў') then
        -- ·ƒÖSÈ~¹p
        local new_area_code = ''
        if (area.note == 'JS¢”') then
            if (isothermal == 'Y') then
                new_area_code = "HWPFL"
            else
                new_area_code = "PFL"
            end
        else
            if (isothermal == 'Y') then
                new_area_code = "HWTFL"
            else
                new_area_code = "TFL"
            end
        end
        -- ågâ‹agöN:N“^:S:Ncš[“^:S„vzz'MO
        strCondition = "S_AREA_CODE = '" ..
            new_area_code .. "' AND N_CURRENT_NUM = 0 AND N_LOCK_STATE = 0 AND C_ENABLE = 'Y'"
        -- 9hncÈ~¹p“^:S·ƒÖSÈ~¹p'MO     cgq’cRB\’c^
        local strOrder = "N_ROW,N_COL,N_LAYER"
        -- gY·ƒÖS 10 ag
        nRet, strRetInfo = mobox.queryDataObjAttr3(strLuaDEID, "Location", strCondition, 10, strOrder)
        if (nRet ~= 0) then
            lua.Error(strLuaDEID, debug.getinfo(1), "·ƒÖS'MOáOo`•ï‹! " .. strRetInfo .. " SQLagöN: " .. strCondition)
        end
 
        local loc
        if (strRetInfo ~= '') then
            local retObjs = json.decode(strRetInfo)
            nRet, loc = m3.ObjAttrStrToLuaObj("Location", lua.table2str(retObjs[1].attrs))
            if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "m3.ObjAttrStrToLuaObj(Location) 1Y%! " .. loc) end
        else
            lua.Error(strLuaDEID, debug.getinfo(1), "¡l    gågâ‹0RïSeQ“^„vzz'MO!")
        end
 
        -- ·ƒÖSÈ~¹páOo`
        nRet, store_loc = wms_wh.GetLocInfo(loc.code)
        if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), 'WMS_GetLocInfo1Y%!' .. store_loc) end
 
        -- È~¹p:N\ON„vÈ~¹p
        task.end_wh_code = store_loc.wh_code
        task.end_area_code = store_loc.area_code
        task.end_loc_code = store_loc.code
 
        nRet, task = m3.CreateDataObj(strLuaDEID, task)
        lua.Debug(strLuaDEID, debug.getinfo(1), 'task', task)
 
        nRet, strRetInfo = wms.wms_LockLocation(strLuaDEID, task.end_loc_code,
            wms_base.Get_nConst(strLuaDEID, "•{|‹W-eQ“^•"), operation.code, operation.code, operation.op_def_name)
        if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "wms_LockLocation 1Y%!" .. strRetInfo) end
    else
        -- Çw¹p·ƒÖS“^:S(WàQ|i,·ƒÖS“^:Sù[”^„v:gðS/f(WJS¢”؏/fhQ¢”,9hncُ$N*NagöN[{    úQ“^ãS:SßWnxš[È~¹p
        -- Ç|iB\ + “^:SMOn ¡‹—{AGV„vÈ~¹p:NêT*NÞV“^ãS“^:S
        -- “^:S„vYèl:N JS¢”/hQ¢”
        strCondition = "N_FLOOR = '" .. area.floor .. "' AND S_NAME LIKE '%" .. area.note .. "ÞV“^ãS%'"
        nRet, area = m3.GetDataObjByCondition(strLuaDEID, "Area", strCondition)
        if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "m3.GetDataObjByCondition 1Y%!" .. area) end
 
        -- ·ƒÖSÈ~¹p¥csšMO
        local end_loc_list
        local end_loc_code = ''
        strCondition = "N_LOCK_STATE = 0 AND S_AREA_CODE = '" .. area.code .. "' AND N_CURRENT_NUM = 0"
        nRet, end_loc_list = m3.QueryDataObject(strLuaDEID, "Location", strCondition)
        if (nRet ~= 0 or end_loc_list == '') then
            local msg
            msg = "\ONx:N=" .. operation.code .. " Rú^ûN¡R1Y%, ¡l    gïS(u¥csšMO"
            lua.Warning(strLuaDEID, debug.getinfo(1), msg)
            lua.Wait(strLuaDEID, msg)
            return
        end
 
        for i = 1, #end_loc_list do
            local attrs = end_loc_list[i].attrs
            attrs = m3.KeyValueAttrsToObjAttr(attrs)
            if (attrs == nil) then goto coroutine end
            end_loc_code = attrs.S_CODE
            -- ÷‹BlWCS·ƒÖS'MO/f&TïS(u,ïS(uRԏÞV'MO(*gYt)
            ::coroutine::
        end
 
        if (end_loc_code == '') then
            local msg
            msg = "\ONx:N=" .. operation.code .. " Rú^ûN¡R1Y%, ¡l    gïS(u¥csšMO"
            lua.Warning(strLuaDEID, debug.getinfo(1), msg)
            lua.Wait(strLuaDEID, msg)
            return
        end
 
        -- Ç·ƒÖS0R„vÈ~¹p'MO\O:NÈ~¹p~b0R
NN*N™eeQ“^\ON ÿ‚YœgÓ~_göeô•*g¾0RNRŸ”Rç~í~I{…_
        local condition = "S_OP_DEF_NAME = '™eeQ“^' AND S_END_LOC = '" .. end_loc_code .. "'"
        nRet, strRetInfo = m3.GetDataObjByCondition(strLuaDEID, "Operation", condition)
        if (nRet == 0) then
            condition = "S_OP_DEF_NAME = '™eeQ“^' AND S_END_LOC = '" ..
                end_loc_code .. "' AND T_END_TIME IS NOT NULL AND T_END_TIME + INTERVAL '1' MINUTE <= SYSDATE"
            nRet, strRetInfo = m3.GetDataObjByCondition(strLuaDEID, "Operation", condition)
            if (nRet == 1) then
                local msg
                msg = "\ONx:N=" .. operation.code .. " Rú^ûN¡R1Y%, ¡l    gïS(u¥csšMO"
                lua.Warning(strLuaDEID, debug.getinfo(1), msg)
                lua.Wait(strLuaDEID, msg)
                return
            elseif (nRet > 1) then
                lua.Error(strLuaDEID, debug.getinfo(1), "m3.GetDataObjByCondition 1Y%!" .. strRetInfo)
            end
        elseif (nRet > 1) then
            lua.Error(strLuaDEID, debug.getinfo(1), "m3.GetDataObjByCondition 1Y%!" .. strRetInfo)
        end
 
        -- ·ƒÖS'MOáOo`
        nRet, store_loc = wms_wh.GetLocInfo(end_loc_code)
        if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), 'WMS_GetLocInfo1Y%!' .. store_loc) end
 
        -- ¾‹n\ONù[aŒ„vÈ~¹p'MOáOo`
        nRet, strRetInfo = wms_op.SetEndLoc(strLuaDEID, operation.code, store_loc.code, store_loc.area_code,
            store_loc.wh_code)
        if (nRet ~= 0) then
            local strErr = "¾‹n\ONx = '" .. operation.code .. "' „vÈ~¹p'MOáOo`1Y%! " .. strRetInfo
            lua.Error(strLuaDEID, debug.getinfo(1), strErr)
        end
 
        -- È~¹p
        task.end_wh_code = store_loc.wh_code
        task.end_area_code = store_loc.area_code
        task.end_loc_code = store_loc.code
 
        nRet, task = m3.CreateDataObj(strLuaDEID, task)
        if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), 'Rú^ûN¡R1Y%!' .. task) end
        lua.Debug(strLuaDEID, debug.getinfo(1), 'task', task)
 
        -- ‚Yœg/fŒN|iÞV“^ãS„v݋ ÿ—‰Ù~ÞV“^ãS'MO
N• ÿ(WýVêÔÞV >e'Œ[bAQ¸‹»y_ ¶r`öe㉕'MO
        if (tonumber(area.floor) == 2) then
            nRet, strRetInfo = wms.wms_LockLocation(strLuaDEID, task.end_loc_code,
                wms_base.Get_nConst(strLuaDEID, "•{|‹W-eQ“^•"), operation.cntr_code, operation.cntr_code,
                operation.op_def_name)
            if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "wms_LockLocation 1Y%!" .. strRetInfo) end
        end
    end
 
    local label_crad
    strCondition = "S_SERIAL_NO = '" .. cg_detail.serial_no .. "'"
    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
 
    --  NÑSûN¡RÙ~AGV
    data = {
        taskData = {
            taskNum = task.code,
            pickStation = task.start_loc_code,
            dropStation = task.end_loc_code,
            taskType = 2,
            carrierType = 1,
            priority = 1,
            wmsTaskNo = "",                 -- úQ“^MbÙ~
            level = "",                     -- eQ“^I{§~/f؞¤‹„v
            tyreType = "",
            supplier = label_crad.vendor,
            receiveLot = cg_detail.batch_no,
            subpool = "",
            source = "YCL"
        },
        partData = {
            rfid = task.cntr_code,
            lotNumber = 1,
            partNumber = cg_detail.item_code,
            partDesc = cg_detail.item_code,
            partType = "",
            weight = cg_detail.qty,
            unit = cg_detail.wu,
            maturityTime = "",
            productionTime = label_crad.product_date,
            stewingTime = "",
            overdueTime = ""
        }
    }
 
    -- Œ(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), "Œ(u¥cãS1Y%!" .. strRetInfo)
    end
 
    -- ¾‹n¶r`*g¨c
    wms_task.SetStateByCode(strLuaDEID, task.code, "ûN¡R¶r`-ò]¨c")
end