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
ÿþ--[[
 x: GT-40-38
  Tðy: \ON/T¨R
 \O€:
 eQãSýQpeÿOperationStart
 ŸRý€ô‹f:
 ØSôf†SòS:
 --]]
require("WMS-BASE")
wms_op = require("wms_operation")
wms_wh = require("wms_wh")
wms_task = require("wms_task")
 
function OperationStart(strLuaDEID)
    local nRet
 
    -- ÇhQ@\ÂSpe ·ƒÖSæ‰ÑS0\ON0/T¨R‹NöNöe g¡Rïz¾‹n„vN›N“eQÂSpe
    -- start_loc,op_code,start_area, cntr_code æ‹Æ~Á‰mobox-WMS  zcWS
    local global_attrs
    nRet, global_attrs = m3.GetSysGloablAttr(strLuaDEID)
    if (nRet ~= 0) then
        lua.Error(strLuaDEID, debug.getinfo(1), global_attrs)
    end
 
 
    -- ·ƒÖSS_MR„v0\ONš[IN0 áOo`
    -- 9hnc0\ONš[IN0-Nš[IN„vÈ~¹pÓN“^0“^:S0'MOáOo`nxš[eQ“^„vîvh'MO
    local op_def
    nRet, op_def = m3.GetSysDataJson(strLuaDEID)
    if (nRet ~= 0) then
        lua.Error(strLuaDEID, debug.getinfo(1), op_def)
    end
 
 
    -- ·ƒÖS\ONù[aŒ, ÎN\ONù[aŒ-N·ƒÖS{ibU\penc}, ÎN{ibU\penc}·ƒÖS¿~SO¾‹Yx
    local operation = {}
    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{|‹W
    if (op_def.type ~= wms_base.Get_nConst(strLuaDEID, "\ON{|‹W-eQ“^")) then
        -- èlȃُ N(uErrorô‹f؏/f—‰;N¿~ zç~í~9SM‘æSY„v \ONš[IN
        -- ‚YœgǑ(uError;N¿~ z z^O«ˆÈ~bk
        lua.Warning(strLuaDEID, debug.getinfo(1), "\ONš[IN-N„v{|‹W N/feQ“^{|‹W!")
        return
    end
 
 
    -- $R­e\ON̑/f&T    gfnx¹[hV ÿ‚Yœgò]Ï~fnx†N¹[hVô‹fúQ“^„v'ÁTò]Ï~nxš[
    -- (W°etQy˜îv-N¹[hV/fÅ_{˜‰    g ÿàV:NbÁTúQ“^/fÇÑS'US0RãbUSegub„v
    if (operation.cntr_code == '') then
        lua.Error(strLuaDEID, debug.getinfo(1), "\ON-NÅ_{˜‰    g¹[hV÷S!")
    end
 
    -- V1.1 $R­eå‹÷]S„vûN¡R/f&T…Ç–<P ÿ‚Yœg…ÇR\\ON¾‹n:NI{…_¶r`v^\•ï‹áOo`¾‹n0Ru˜b—
    local store_loc, strRetInfo
    nRet, store_loc = wms_wh.GetLocInfo(operation.end_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 = 3 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) > 2) 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ú^ AGV ,dЏûN¡R
    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.type = wms_base.Get_nConst(strLuaDEID, "ûN¡R{|‹W-AGVeQ“^,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
    task.roadway = store_loc.roadway -- ûm R÷]S
 
    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
 
    -- Ç¹[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
    -- üb¥cpenc NÑSAGVûN¡R
    local data = {
        taskData = {
            taskNum = task.code,
            pickStation = task.start_loc_code,
            dropStation = task.end_loc_code,
            taskType = 5,
            carrierType = 1,
            priority = 1,
            source = "YCL"
        },
        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 = nil,
            stewingTime = nil,
            overdueTime = nil
        }
    }
 
    lua.Debug(strLuaDEID, debug.getinfo(1), "data", data)
    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