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
ÿþ--[[
    Tðy: ÷]S»QÓ~
   \O€ÿLZH
   åegÿ2024-09-26
 
   ýQpeÿ RoadwayFreeze
   ŸRý€: ÷]SŒTù[”^;‘“^:S
N•
 
   ôf9e°‹U_:
   V1.1 20241024 LZH eˆEQÞV O¥cãS
 
--]]
 
json  = require("json")
mobox = require("OILua_JavelinExt")
m3 = require( "oi_base_mobox" )
wms_wh = require( "wms_wh" )
require("GT-Base")
function RoadwayFreeze(strLuaDEID)
    local nRet, strRetInfo, objs
 
    -- ·ƒÖSS_MR    -N„vpencù[aŒ
    nRet, objs = m3.GetSysDataJson(strLuaDEID)
    if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), objs) end
    lua.Debug(strLuaDEID, debug.getinfo(1), '0÷]S»QÓ~0ÂSpe:', objs)
    if (objs == '') then lua.Error(strLuaDEID, debug.getinfo(1), "÷‹    éb»QÓ~„v÷]S!") end
 
    local obj_attrs
    local strCondition
 
    for n = 1, #objs do
        obj_attrs = m3.KeyValueAttrsToObjAttr(objs[n].attrs)
        if (obj_attrs ~= nil and obj_attrs ~= '') then
            -- $R­e÷]S/f&Tò]»QÓ~
            strCondition = "S_ZONE_CODE = '" .. obj_attrs.S_ZONE_CODE .. "' AND N_LOCK_STATE = 0"
            nRet, strRetInfo = mobox.existThisData(strLuaDEID, "Roadway", strCondition)
            if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "(WÀhåg0÷]S0/f&TX[(Wöe1Y%! " .. strRetInfo) end
            if (strRetInfo == 'no') then goto coroutine end
            
            -- ;‘“^:S
N•
            nRet, strRetInfo = wms.wms_LockZone(strLuaDEID, obj_attrs.S_ZONE_CODE, 3)
            if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "wms_LockZone 1Y%!" .. strRetInfo) end
 
            -- îO9e÷]S„v•¶r`
            strCondition = "S_ZONE_CODE = '" .. obj_attrs.S_ZONE_CODE .. "'"
            local strSetSQL = " N_LOCK_STATE = 3 "
            nRet, strRetInfo = mobox.updateTableAttrByCondition(strLuaDEID, "TN_Roadway", strCondition, strSetSQL)
            if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), 'îO9e0÷]S0¶r`1Y%' .. strRetInfo) end
 
            -- ·ƒÖSù[”^÷]S(WÓN“^…Q„v'ÁTáOo`ÞV OÙ~GT-WMS
            local num = 0
            local numList = {}
            -- ·ƒÖS-Nô•hˆáOo`
            local strTabName =
            "TN_CG_Detail"                                                                             -- penc“^hˆ T
            local strFieldList =
            '["S_SERIAL_NO","S_ITEM_CODE","S_BATCH_NO","F_QTY"]'                                                     -- ‰·ƒÖS„vW[µk
            local nPageSize = 100                                                                      -- Ïku˜pencagpe
            strCondition = "S_ITEM_CODE <> 'KGZ' AND S_CNTR_CODE IN (Select S_CNTR_CODE From TN_Loc_Container Where S_LOC_CODE" -- ågâ‹agöN
            strCondition = strCondition ..
                " In ( Select S_CODE From TN_Location Where N_ROADWAY = " ..
                obj_attrs.N_ROADWAY .. " And S_Area_Code = 'LK' ) )"
            local strOrderBy = "" -- ’c^agöN
            nRet, strRetInfo = mobox.queryTable2(strLuaDEID, strTabName, strFieldList, nPageSize, strCondition,
                strOrderBy)
            if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), 'Œ(uqueryTable21Y%!' .. strRetInfo) end
            if(strRetInfo == '')then goto coroutine end
            -- ã‰gԏÞVpenc
            local resData = json.decode(strRetInfo)
            if (resData.record_count == 0) then goto coroutine end
 
            for nPage = 1, resData.page_count do
                nRet, strRetInfo = mobox.queryTable2(strLuaDEID, nPage)
                local pageData = json.decode(strRetInfo).data_list
 
                for m = 1, #pageData do
                    num = num + 1
                    local serial_no = pageData[m].S_SERIAL_NO
                    local batch_no = pageData[m].S_BATCH_NO
                    local qty = tonumber(pageData[m].F_QTY)
                    
                    -- ÇAm4l÷S·ƒÖSmQMOx
                    condition = "S_SERIAL_NO = '" .. serial_no .. "'"
                    nRet, strRetInfo = m3.GetDataObjByCondition(strLuaDEID, "GT_Label_Crad", condition)
                    if (nRet == 1) then
                        condition = "S_SERIAL_NO = '" .. serial_no .. "'"
                        nRet, strRetInfo = m3.GetDataObjByCondition(strLuaDEID, "GT_ROM", condition)
                        if (nRet ~= 0) then
                            lua.Error(strLuaDEID, debug.getinfo(1), strRetInfo)
                        end
                    elseif (nRet > 1) then
                        lua.Error(strLuaDEID, debug.getinfo(1), strRetInfo)
                    end
                    
                    local item_code = strRetInfo.item_code_9
                    numList[num] = {
                        item_code = item_code,
                        batch_no = batch_no,
                        qty = qty
                    }
                end
            end
            lua.Debug(strLuaDEID, debug.getinfo(1), 'numList', numList)
 
            local result = {}
 
            for _, item in ipairs(numList) do
                local key = item.item_code .. "_" .. item.batch_no
                if not result[key] then
                    result[key] = {
                        item_code = item.item_code,
                        batch_no = item.batch_no,
                        total_qty = item.qty
                    }
                else
                    result[key].total_qty = result[key].total_qty + item.qty
                end
            end
 
            local final_result = {}
            for _, value in pairs(result) do
                table.insert(final_result, value)
            end
 
            for j = 1, #final_result do
                lua.Debug(strLuaDEID, debug.getinfo(1), 'j', j)
                local attr = final_result[j]
                -- Œ(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_FREEZE_WMS",
                    data = {
                        wh_code = "wmwhse1",
                        batch_no = attr.batch_no,
                        sku = attr.item_code,
                        qty = attr.total_qty,
                        fromloc = "LK001",
                        toloc = "LK006",
                        loctype = nil,
                        type = 1
                    }
                }
                lua.Debug(strLuaDEID, debug.getinfo(1), 'strBody', strBody)
                source = "GTWMS“^X[»QÓ~"
                nRet, strRetInfo = CreateInterfaceExc(strLuaDEID, strurl, strHeader, strBody, "GTWMS", source)
                if (nRet ~= 0) then
                    lua.Error(strLuaDEID, debug.getinfo(1), "Œ(u¥cãS1Y%!" .. strRetInfo)
                end
                --  nRet, strRetInfo = mobox.sendHttpRequest(strurl, strHeader, lua.table2str(strBody))
                -- if (nRet ~= 0) then
                --     lua.Error(strLuaDEID, debug.getinfo(1), "Œ(uWMSÞV O¥cãS1Y%!" .. strRetInfo)
                -- end
            end
        end
        ::coroutine::
    end
    mobox.setInfo(strLuaDEID, "»QÓ~bŸR!")
end