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
ÿþ--[[
     x: GT-40-59
      Tðy: \ON/T¨R-Ǒ-'
     \O€: LZH
     eQãSýQpeÿOperationStart
     ŸRý€ô‹f: Ç‘-'/fôv¥cúQ“^0R úVš[:gðSABCxô~¤b„v úQ“^“^:Sb'MO ÿ‚Yœg/fËz“^úQ“^RRú^NµkýVêûN¡R
            ‚Yœg/f‰|™e-RRú^NµkAGVûN¡R0Rù[”^|iB\„vÞV“^ãS,6qT(WRú^NµkýVêûN¡R0RúQ“^ãS
     Ø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, strRetInfo, store_loc
 
    -- ·ƒÖ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 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
 
    -- 9hnc\ON„vw¹p“^:S$R­e\ON{|‹W
    local schedule_type
    if (operation.start_area_code == 'LK') then
        schedule_type = wms_base.Get_nConst(strLuaDEID, "Œ¦^{|‹W-AGV") -- ¾‹nŒ¦^{|‹W
    else
        schedule_type = wms_base.Get_nConst(strLuaDEID, "Œ¦^{|‹W-ýVê") -- ¾‹nŒ¦^{|‹W
    end
 
    -- $R­eå‹÷]S„vûN¡R/f&T…Ç–<P ÿ‚Yœg…ÇR\\ON¾‹n:NI{…_¶r`v^\•ï‹áOo`¾‹n0Ru˜b—
    nRet, store_loc = wms_wh.GetLocInfo(operation.start_loc_code)
    if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), store_loc) end
 
    -- ·ƒÖSÐgÍyŒ¦^{|‹W„vûN¡Rpeϑ
    local strCondition = "N_SCHEDULE_TYPE = " ..
        schedule_type .. " AND ( N_B_STATE = " .. wms_base.Get_nConst(strLuaDEID, "ûN¡R¶r`-ò]¨c")
    strCondition = strCondition ..
        " OR N_B_STATE = " .. wms_base.Get_nConst(strLuaDEID, "ûN¡R¶r`-gbLˆ") .. ") AND N_ROADWAY =" .. store_loc.roadway
    nRet, strRetInfo = mobox.getDataObjCount(strLuaDEID, "Task", strCondition)
    if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), strRetInfo) end
    if (tonumber(strRetInfo) > tonumber(wms_base.Get_sConst(strLuaDEID, "Task-g'YûN¡Rpe"))) then
        local msg
        msg = "\ONx:N=" .. operation.code .. " Rú^ûN¡R1Y%, ÷]S" .. store_loc.roadway .. "„vûN¡Rpeϑò]…Ç2*N"
        lua.Warning(strLuaDEID, debug.getinfo(1), msg)
        lua.Wait(strLuaDEID, msg)
        return
    end
 
    -- Rú^,dЏ\ON
    local task = m3.AllocObject(strLuaDEID, "Task")
    task.op_code = operation.code    -- \ONx
    task.op_name = operation.op_def_name
    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
 
    -- ¾‹n,dЏ{|‹WŒTŒ¦^{|‹W
    if (operation.start_area_code ~= 'LK') then
        -- ·ƒÖSw¹pù[”^„vÞV“^ãS
        local end_loc
        if (operation.start_area_code == 'PFL' or operation.start_area_code == 'HWPFL') then
            nRet, end_loc = wms_wh.GetLocInfo("THREE-BGHHK-01")
            if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "·ƒÖSÈ~¹páOo`1Y%!" .. end_loc) end
        elseif (operation.start_area_code == 'TFL' or operation.start_area_code == 'HWTFL') then
            nRet, end_loc = wms_wh.GetLocInfo("THREE-QGHHK-01")
            if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "·ƒÖSÈ~¹páOo`1Y%!" .. end_loc) end
        else
            lua.Error(strLuaDEID, debug.getinfo(1), "*gš[IN„vǑ-'Am z!")
        end
        -- È~¹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.roadway = end_loc.roadway -- ûm R÷]S
        task.type = wms_base.Get_nConst(strLuaDEID, "ûN¡R{|‹W-AGVúQ“^,dЏ")
        task.schedule_type = wms_base.Get_nConst(strLuaDEID, "Œ¦^{|‹W-AGV") -- ¾‹nŒ¦^{|‹W
    else
        -- È~¹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.roadway = store_loc.roadway -- ûm R÷]S
        task.type = wms_base.Get_nConst(strLuaDEID, "ûN¡R{|‹W-Ëz“^úQ“^,dЏ")
        task.schedule_type = wms_base.Get_nConst(strLuaDEID, "Œ¦^{|‹W-ýVê") -- ¾‹nŒ¦^{|‹W
    end
    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
 
 
    local data = {}
    local strBody = {}
    local url, strHeader
    -- Ç¹[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
    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
    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
    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
 
    --9hnc,dЏûN¡R{|‹WÄ~ňûN¡R NÑSÂSpe
    if (task.type == wms_base.Get_nConst(strLuaDEID, "ûN¡R{|‹W-AGVúQ“^,dЏ")) then
        --  NÑSûN¡RÙ~AGV
        data = {
            taskData = {
                taskNum = task.code,
                pickStation = task.start_loc_code,
                dropStation = task.end_area_code,
                taskType = 2,
                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 = nil,
                partNumber = cg_detail.item_code,
                partDesc = cg_detail.item_code,
                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
        url = wms_base.Get_sConst(strLuaDEID, "AGV-url")
        url = url .. "/CreateTask"
        strBody = data
        nRet, strRetInfo = CreateInterfaceExc(strLuaDEID, url, strHeader, strBody, "AGV", "ûN¡RRú^")
        if (nRet ~= 0) then
            lua.Error(strLuaDEID, debug.getinfo(1), "Œ(uWCS¥cãS1Y%!" .. strRetInfo)
        end
    else
        -- úQ“^ Ncš[wQSOÈ~¹p,    gWCSÍSˆ™È~¹p,·ƒÖSúQ“^ãS“^:SÑ~š[„vWCSÙz¹p
        local condition = "S_VALUE = '" .. task.end_area_code .. "-01" .. "'"
        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 loc_code_zd = strRetInfo.name
 
        -- $R­ew¹p/f&T/f…QñmMO,‚Yœgw¹p/f…QñmMOR·ƒÖSù[”^„vYñmMO
        local pre_task_no = ''
        local success, loc_code = GetPosLoc(strLuaDEID, operation.start_loc_code)
        if (success == true) then
            -- $R­eYñmMO/f&TX[(W*gŒ[b„vûN¡R,‚Yœg    gR\ُ*NûN¡R÷S“eQ0R WCSÂSpe-N„vMRnûN¡R÷S-N
            strCondition = "S_START_LOC = '" .. loc_code .. "' AND N_B_STATE IN (0,1,2)"
            nRet, strRetInfo = m3.GetDataObjByCondition(strLuaDEID, "Task", strCondition)
            if (nRet == 2) then
                lua.Error(strLuaDEID, debug.getinfo(1), "m3.GetDataObjByCondition 1Y%!" .. strRetInfo)
            elseif (nRet == 0) then
                pre_task_no = strRetInfo.code
            end
        end
 
        local strCode = lua.guid() -- u§NN*NGUIDW[&{2N
        local str_day_time = os.date("%Y-%m-%d %H:%M:%S")
        data = {
            req_no = strCode,
            task_type = 2, -- 1='ireQ“^ÿ2='irúQ“^ÿ3=XbØvÄ~eQ“^ÿ4=XbØvÄ~úQ“^ÿ5=ûy¨Rÿ NǏ“^MO    ÿÿ6=ûy“^
            task_no = task.code,
            tunnel_no = store_loc.roadway,
            from_pos = task.start_loc_code,
            to_pos = loc_code_zd,
            mat_code = task.cntr_code,
            mat_type = cg_detail.item_code,
            mat_memo = cg_detail.item_name,
            req_time = str_day_time,
            pre_task_no = pre_task_no
        }
 
        url = wms_base.Get_sConst(strLuaDEID, "WCS-url")
        url = url .. "/create"
        strBody[1] = data
        nRet, strRetInfo = CreateInterfaceExc(strLuaDEID, url, strHeader, strBody, "WCS", "ûN¡RRú^")
        if (nRet ~= 0) then
            lua.Error(strLuaDEID, debug.getinfo(1), "Œ(uWCS¥cãS1Y%!" .. strRetInfo)
        end
    end
 
    -- ¾‹n¶r`*g¨c
    wms_task.SetStateByCode(strLuaDEID, task.code, "ûN¡R¶r`-ò]¨c")
    -- ûN¡R„vw¹p R
N•
    nRet, strRetInfo = wms.wms_LockLocation(strLuaDEID, task.start_loc_code,
        wms_base.Get_nConst(strLuaDEID, "•{|‹W-úQ“^•"),
        task.code, operation.code, operation.op_def_name)
    if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "wms_LockLocation 1Y%!" .. strRetInfo) end
end