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
ÿþ--[[
    x: WMS-04-03
     Tðy: ybϑü[eQ
    \O€ÿHAN    
    eQãSýQpeÿImportLocation
 
    ŸRý€ô‹f:
        Yt'MOü[eQ ÿ(Wü[eQ„vöeP$R­eN NÓN“^0“^:SI{/f&TX[(Wÿ‚Yœg NX[(W‰°eRú^
        ü[eQ<h_Á‰
0#MOWMS-001 ÓN“^'MOš[INhˆ.xlsx 0
    ØSôf†SòS:
        V1.0  HAN    2022-9-11      °eú^
        V1.1  HAN    2022-10-5      ÖSˆm N_LOC_TYPE 'MO{|‹W ÿ^\'`ØS†N ÿ÷]SI{^\'`ÎN S_ 9e:N N_
        V1.2  HANXU  2022-10-8      °ežXÓN“^ Tðy ÿ'MO Tðy ÿ“^:S Tðy ÿ'MO{|‹W,AGVù[gqx
        V6.0  HAN    2023/9/6       lua.Error/lua.Debug ýQpeØSS  
        V6.1  NAN    2023/9/16      “eQÂSpeÎNInputParamter9ebÎNDataJson·ƒÖS ÿ
                                    ÎNŸSeg„vNagpencû‹ÖSØSbYagÿÐcؚHe‡s    ÿ
                                    'MOù[aŒ-N„v S_LOC_CODE 9e:N S_CODE ÿÓN“^ù[aŒ-N„v S_WH_CODE 9e:N S_CODE ÿ S_WH_NAME 9e:N S_NAME
                                    “^:Sù[aŒ-N„v S_AREA_CODE 9e:N S_CODE ÿ S_AREA_NAME 9e:N S_NAME
        V7.0  HAN    2023/11/15     ÖSˆm deep_type, ñmMO ÿWMS_LocDeepPosition
--]]
wms_base = require( "wms_base" )
 
local location_type = {}        -- 'MO{|‹W
local purpose = {}              -- (u
 
-- ·ƒÖSW[xQy˜-N„vName ÿv^Nlbpe<PԏÞV
local function GetLocationTyeValue( strLocTypeName )
    local n, nCount
    local nValue = 1
 
    nCount = #location_type
    for n = 1, nCount do
        if ( location_type[n].Value == strLocTypeName ) then
            nValue = lua.StrToNumber( location_type[n].Name )
            if ( nValue == 0 ) then nValue = 1 end
            return nValue
        end
    end
    return nValue
end
 
-- ·ƒÖSW[xQy˜-N„vName ÿv^Nlbpe<PԏÞV
local function GetPurposeValue( strPurpose )
    local n, nCount
    local nValue = 0
 
    nCount = #purpose
    for n = 1, nCount do
        if ( purpose[n].Value == strPurpose ) then
            return lua.StrToNumber( purpose[n].Name )
        end
    end
    return nValue
end
 
function ImportLocation(strLuaDEID)
    local nRet, strRetInfo
    -- ·ƒÖSü[eQ„vpenc, ÔÞV [{"attr":"xx","value":""},...]
    local row_data = {}
    nRet, row_data = m3.GetSysDataJson(strLuaDEID)
    if (nRet ~= 0 or strRetInfo == '') then lua.Error( strLuaDEID, debug.getinfo(1), "àeÕl·ƒÖSü[eQpenc!") end
 
    lua.Debug( strLuaDEID, debug.getinfo(1), 'row_data', row_data )
 
    local row_attrs
    local n, nCount, nValue, nRows
    nRows = #row_data
    if ( nRows == 0 ) then return end
 
    -- ·ƒÖSÍd\O€„vå]‚ShƋ
    local factory
    nRet, factory = m3.GetMyFactory( strLuaDEID )
    if ( nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), "GetMyFactory1Y%! "..factory ) end
    if ( factory == '' ) then factory = '0000' end
 
    -- N›NsQ.•^\'`
    local strWHCode = ''
    local strWHName = ''
    local strAreaCode = ''
    local strAreaName = ''
    local strLocCode = ''
    local strLocName = ''
    local location = {}
 
    -- ·ƒÖS 'MO{|‹W W[xQ ÿŠb “eQ „v 8^ĉ/XàS  lb tepe<P
    nRet, strRetInfo = mobox.getDictItemIInfo( "WMS_LocationType" )
    if ( nRet ~= 0 or strRetInfo == '') then lua.Error( strLuaDEID, debug.getinfo(1), "û|ß~¡l    gš[INWMS_LocationTypeW[xQ!") end
    location_type = json.decode( strRetInfo ) 
 
    nRet, strRetInfo = mobox.getDictItemIInfo( "WMS_LocationPurpose" )
    if ( nRet ~= 0 or strRetInfo == '') then lua.Error( strLuaDEID, debug.getinfo(1), "û|ß~¡l    gš[INWMS_LocationPurposeW[xQ!") end
    purpose = json.decode( strRetInfo )     
    
    -- ek¤š1 ·ƒÖSÎNexcelü[eQ„vNLˆpenc
    for row = 1, nRows do
        row_attrs = row_data[row]
        nCount = #row_attrs
        strWHCode = ''
        strWHName = ''
        strAreaCode = ''
        strAreaName = ''
        strLocCode = ''
        strLocName = ''  
        -- RËYS 'MO ù[aŒ
        location = m3.AllocObject(strLuaDEID,"Location")
        for n = 1, nCount do
            strAttr = row_attrs[n].attr
            strValue = row_attrs[n].value
            if (strAttr ~= '') then
 
                -- 9hncü[eQ„vexcelR4Y TðyۏLˆ$R­e
                -- sQ.•^\'`$R­e ÿ‚Yœg^\'` NX[(W‰¥b•
                if (strAttr == "ÓN“^x") then
                    if (strValue == '') then lua.Error( strLuaDEID, debug.getinfo(1), strAttr .. " Ný€:Nzz!") end
                    strWHCode = strValue
                    location.wh_code = strWHCode
                --V1.2 
                elseif (strAttr == "ÓN“^ Tðy") then
                    strWHName = strValue
                elseif (strAttr == "“^:Sx") then
                    if (strValue == '') then lua.Error( strLuaDEID, debug.getinfo(1), strAttr .. " Ný€:Nzz!") end
                    strAreaCode = strValue
                    location.area_code = strAreaCode
                elseif (strAttr == "“^:S Tðy") then
                    strAreaName = strValue
                elseif (strAttr == "'MOx") then
                    if (strValue == '') then lua.Error( strLuaDEID, debug.getinfo(1), strAttr .. " Ný€:Nzz!") end
                    strLocCode = strValue
                    location.code = strValue
                elseif (strAttr == "'MO Tðy") then
                    if (strValue == '') then lua.Error( strLuaDEID, debug.getinfo(1), strAttr .. " Ný€:Nzz!") end
                    strLocName = strValue
                    location.name = strValue
                 -- 8^ĉ^\'`
                elseif (strAttr == "÷]S") then
                    location.roadway = lua.StrToNumber( strValue )
                elseif (strAttr == "’c") then
                    location.row = lua.StrToNumber( strValue )
                elseif (strAttr == "R") then
                    location.col = lua.StrToNumber( strValue )
                elseif (strAttr == "B\") then
                    location.layer = lua.StrToNumber( strValue )
                elseif (strAttr == "'MO{|‹W") then
                    location.loc_type = GetLocationTyeValue( strValue )
                elseif (strAttr == "(u") then
                    location.loc_type = GetPurposeValue( strValue )                    
                elseif (strAttr == "¹[ϑ") then
                    location.capacity = lua.StrToNumber( strValue )
                elseif (strAttr == "•¦^") then
                    location.length = lua.StrToNumber( strValue )
                elseif (strAttr == "½[¦^") then
                    location.width = lua.StrToNumber( strValue )
                elseif (strAttr == "ؚ¦^") then
                    location.height = lua.StrToNumber( strValue )
                --V1.2    
                elseif (strAttr == "AGVù[gqx") then
                    location.agv_site = strValue
                elseif (strAttr == "MOn") then
                    location.pos = strValue
                elseif (strAttr == "ñm¦^") then
                    location.deep = strValue
                elseif (strAttr == "’cÄ~÷S") then
                    location.row_group = strValue
                end
            end
        end
 
        -- ek¤š2 9hnc'MOxeg$R­eü[eQ„v'MO/f&Tò]Ï~X[(W
        --       ‚Yœgò]Ï~X[(W ÿ9hncü[eQ„vpencۏLˆ†‰Öv
        --       ‚Yœg NX[(W—‰Rú^
        local attrs
        local strCondition = "S_CODE='" .. strLocCode .. "'"
        nRet, strRetInfo = mobox.existThisData(strLuaDEID, "Location", strCondition)
        if (nRet ~= 0) then lua.Error( strLuaDEID, debug.getinfo(1), "(WÀhåg'MO/f&TX[(Wöe1Y%! " .. strRetInfo) end
 
        if (strRetInfo == 'yes') then
            -- ò]Ï~X[(W ÿ9hncü[eQ„vpencۏLˆ†‰Öv
            strCondition = "S_CODE='" .. strLocCode .. "'"
            strSetSQL = "S_WH_CODE = '" ..strWHCode .."' , S_AREA_CODE = '" .. strAreaCode .. "' , S_CODE = '" ..strLocCode .."' , S_NAME = '" ..
                strLocName .. "' , N_ROADWAY = '" ..location.roadway.. "' , N_ROW = '" ..location.row.. "' , N_COL = '" ..
                location.col.. "' , N_LAYER = '" .. location.layer .. "' , N_TYPE = '" .. location.loc_type .. "' , N_CAPACITY ='" ..
                location.capacity .. "', N_LENGTH = '" .. location.length .. "' , N_WIDTH = '" .. location.width ..
                "' , N_HEIGHT = '" .. location.height .. "' , S_AGV_SITE = '" .. location.agv_site .. "', N_POS = '" .. location.pos .. "', N_DEEP = '" .. location.deep .. "' "
            if(location.row_group ~= nil and location.row_group ~= '')then
                strSetSQL =strSetSQL .. ", N_ROW_GROUP = '" .. location.row_group .. "'"
            end
            nRet, strRetInfo = mobox.updateDataAttrByCondition(strLuaDEID, "'MO", strCondition, strSetSQL)
            if (nRet ~= 0) then lua.Error( strLuaDEID, debug.getinfo(1), strRetInfo) end
            return
        end
 
        -- ü[eQ„v'MO NX[(W—‰Rú^
        -- (W°ežX'MOMRHQ$R­eN NÓN“^0“^:S/f&TX[(W ÿ‚Yœg NX[(W—‰Rú^
        -- $R­eÓN“^/f&TX[(W
        strCondition = "S_CODE='" .. strWHCode .. "'"
        nRet, strRetInfo = mobox.existThisData(strLuaDEID, "Warehouse", strCondition)
        if (nRet ~= 0) then lua.Error( strLuaDEID, debug.getinfo(1), "(WÀhågÓN“^/f&TX[(Wöe1Y%! " .. strRetInfo) end
        if (strRetInfo == 'no') then
            -- °ežXÓN“^
            if (strWHName == '') then strWHName = strWHCode end
            local warehouse = m3.AllocObject(strLuaDEID,"Warehouse")
            warehouse.code = strWHCode
            warehouse.name = strWHName
            warehouse.factory = factory
            nRet, strRetInfo = m3.CreateDataObj( strLuaDEID, warehouse )
            if ( nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), 'mobox Rú^0ÓN“^0ù[aŒ1Y%!'..strRetInfo ) end 
        end
        -- $R­e“^:S/f&TX[(W
        strCondition = "S_WH_CODE='" .. strWHCode .. "' AND S_CODE = '" .. strAreaCode .. "'"
        nRet, strRetInfo = mobox.existThisData(strLuaDEID, "Area", strCondition)
        if (nRet ~= 0) then lua.Error( strLuaDEID, debug.getinfo(1), "(WÀhåg“^:S/f&TX[(Wöe1Y%! " .. strRetInfo) end
        --mobox.writeSysLog("strRetInfo",strRetInfo)
        if (strRetInfo == 'no') then
            -- °ežX“^:S
            if (strAreaName == '') then strAreaName = strAreaCode end
 
            local area = m3.AllocObject(strLuaDEID,"Area")
            area.code = strAreaCode
            area.name = strAreaName
            area.wh_code = strWHCode
            area.factory = factory
            nRet, area = m3.CreateDataObj( strLuaDEID, area )
            if ( nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), 'mobox Rú^0“^:S0ù[aŒ1Y%!'..area ) end
            if ( location.loc_type == 0 ) then  
                location.loc_type = area.loc_type
            end
        end
        if  (location.loc_type == 0 ) then  location.loc_type = 1 end
        -- Rú^'MO
        nRet, strRetInfo = m3.CreateDataObj( strLuaDEID, location )
        if (nRet ~= 0) then lua.Error( strLuaDEID, debug.getinfo(1), "Rú^'MO1Y%! " .. strRetInfo ) end
    end
end