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
ÿþ--[[
    x: GT-40-60
     Tðy: \ON-Ǒ-'-ûN¡RŒ[b
    \O€ÿLZH
    åegÿ2025-3-28
    ýQpeÿ TaskFinish
    ŸRý€:
        -- ‚YœgûN¡R{|‹W:N ûN¡R{|‹W-AGVúQ“^,dЏ RRú^ŒNµkûN¡RÎNNµkûN¡R„vÈ~¹p0R\ON„vÈ~¹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
 
    -- ·ƒÖSûN¡Rù[aŒ
    local task
    nRet, task = m3.SysInputParamToDataObj(strLuaDEID, "Task")
    if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), task) 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), 'Ǒ-'\ONibU\ÂSpe!', ext_data)
    local delivery_no = ext_data.delivery_no     -- úQ“^US÷S
 
    if (task.type == wms_base.Get_nConst(strLuaDEID, "ûN¡R{|‹W-AGVúQ“^,dЏ")) then
        -- ·ƒÖSûN¡Rpeϑg\„vïSRM‘„v÷]S
        local code, rodadway = LeastTaskRoadway(strLuaDEID, wms_base.Get_nConst(strLuaDEID, "sO-N|iæ]§OÞV“^ãS÷]S"))
        if (code ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), rodadway) end
        -- 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.roadway         = rodadway -- ûm R÷]S
        new_task.type            = wms_base.Get_nConst(strLuaDEID, "ûN¡R{|‹W-Ëz“^úQ“^,dЏ")
        new_task.schedule_type   = wms_base.Get_nConst(strLuaDEID, "Œ¦^{|‹W-ýVê") -- ¾‹nŒ¦^{|‹W
        nRet, new_task           = m3.CreateDataObj(strLuaDEID, new_task)
        if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "Rú^,dЏûN¡R1Y%!" .. new_task) end
 
        -- ¾‹n¶r`*g¨c
        wms_task.SetStateByCode(strLuaDEID, new_task.code, "ûN¡R¶r`-ò]¨c")
        -- Ù~
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
 
        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
        -- ú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
            local 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 = 5, -- 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 = rodadway,
            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
    else
        -- ‚YœgŒ[b„v/fýVê,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
 
        -- ¹[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
 
        -- ¾‹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
        -- eQ“^Ó~œgÞV O
        local data
        local source = "GTWMSúQ“^ÞV O"
        nRet, data = StorageResult(strLuaDEID, operation.code, source)
        if (nRet ~= 0) then
            lua.Error(strLuaDEID, debug.getinfo(1), "eQ“^Ó~œgÞV O1Y%!" .. data)
        end
        lua.Debug(strLuaDEID, debug.getinfo(1), 'data', data)
 
        -- Œ(uGT-WMS„vÞV O¥cãS
        local url = wms_base.Get_sConst(strLuaDEID, "GTWMS-url")
        local strurl = url
        local strHeader = ""
        local strBody = {
            application = "GITI",
            code = "WCS_SO_WMS",
            data = data
        }
        nRet, strRetInfo = CreateInterfaceExc(strLuaDEID, strurl, strHeader, strBody, "GTWMS", source)
        if (nRet ~= 0) then
            lua.Error(strLuaDEID, debug.getinfo(1), "Œ(uWCS¥cãS1Y%!" .. 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