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
ÿþ--[[
    x: GT-40-54
     Tðy: \ON-Ëz“^úQ“^-ûN¡RŒ[b
    \O€ÿHAN
    åegÿ2024-5-10
 
    Hr,g: V1.0
 
    :Wofÿ\ON-N„vûN¡RŒ[bTæ‰ÑSُ*N,g
 
    ýQpeÿ TaskFinish
 
    ŸRý€:
        -- ‚YœgûN¡R{|‹W:NËz“^úQ“^,dЏ RNµkûN¡R“:g,dЏ0R¿~¹“^ù[”^„v¥csšMO ÿŒNµkûN¡RAGVÎN¥csšMO0RÈ~¹p¿~¹“^
 
    ôf9e°‹U_ÿ
 
--]]
wms_op = require("wms_operation")
wms_cntr = require("wms_container")
require("GT_InAndOutboundPolicies")
require("GT-Base")
 
function LKTaskFinish(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
    lua.Debug(strLuaDEID, debug.getinfo(1), 'operation:', operation)
 
    -- ·ƒÖSûN¡Rù[aŒ
    local task
    nRet, task = m3.SysInputParamToDataObj(strLuaDEID, "Task")
    if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), task) end
    lua.Debug(strLuaDEID, debug.getinfo(1), 'task:', task)
 
    -- ·ƒÖSibU\pencÂSpe
    local ext_data    = json.decode(operation.ext_data)
    local item_type   = ext_data.item_type   -- ir™e{|‹W
    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
    lua.Debug(strLuaDEID, debug.getinfo(1), 'ext_data', ext_data)
 
    if (task.type == wms_base.Get_nConst(strLuaDEID, "ûN¡R{|‹W-Ëz“^úQ“^,dЏ") and item_type ~= '¢”N') then
        -- Rú^AGV,dЏû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.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
        -- È~¹p:N\ON„vÈ~¹p
        new_task.end_wh_code     = operation.end_wh_code
        new_task.end_area_code   = operation.end_area_code
        new_task.end_loc_code    = operation.end_loc_code
        new_task.type            = wms_base.Get_nConst(strLuaDEID, "ûN¡R{|‹W-AGVúQ“^,dЏ")
        new_task.schedule_type   = wms_base.Get_nConst(strLuaDEID, "Œ¦^{|‹W-AGV") -- ¾‹nŒ¦^{|‹W
        nRet, new_task           = m3.CreateDataObj(strLuaDEID, new_task)
        if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "Rú^ºNå],dЏûN¡R1Y%!" .. new_task) end
 
        -- Ù~
NN*NûN¡R㉕
        nRet, strRetInfo = wms.wms_UnlockByTask(strLuaDEID, task.code)
        if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "wms_UnlockByTask 1Y%! " .. strRetInfo) 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
 
        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
 
        --  NÑSûN¡RÙ~AGV
        local data = {
            taskData = {
                taskNum = new_task.code,
                pickStation = task.end_loc_code,
                dropStation = operation.end_area_code,
                taskType = 1,
                carrierType = "RC",
                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_code,
                partType = nil,
                weight = cg_detail.qty,
                unit = cg_detail.wu,
                maturityTime = nil,
                productionTime = label_crad.product_date,
                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")
    else
        -- ‚YœgŒ[b„v/fAGV,dЏûN¡R ÿ¾‹n\ONŒ[b
        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
        lua.Debug(strLuaDEID, debug.getinfo(1), 'item_type:', item_type)
        if (item_type ~= '¢”N') then
            -- ö€™e0‰|™e2µkûN¡RŒ[bRôv¥ccb“^X[ã‰Ñ~
            -- ¹[hV'MOã‰Ñ~
            nRet, strRetInfo = wms_wh.Loc_Container_Unbinding(strLuaDEID, task.end_loc_code, operation.cntr_code,
                "Ñ~š[ã‰Ñ~¹eÕl-û|ß~", ":_6RŒ[b")
            if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), ''MO¹[hVã‰Ñ~1Y%!' .. 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
        end
    end
end