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
ÿþ--[[
    Hr,gÿ    Version 1.0
    Rú^åegÿ 2024-6-10
    Rú^ºNÿ   HAN
 
    ŸRý€ÿ
        WMS N›NúW@xpencôv¥cOq_ÍTTb—„vN¡R;‘ ÿàVdk—‰ZPN›Npenc!hŒš
        ÀhŒšpencSìbÿ
        Location_Group
              -- N_CAPACITY, N_CURRENT_NUM, N_OUT_LOCK_NUM, S_ITEM_CODE,...
 
        -- WMS_DataCheck_Loaction_Group  'MOÄ~
 
--]]
require ("WMS-BASE")
 
 
local function upadte_location_group( strLuaDEID, id, strSetAttr, strCheckResult )
    local nRet, strRetInfo
 
    local curTime = os.date("%Y-%m-%d %H:%M:%S Checked -> ")
    if ( strCheckResult == '' ) then strCheckResult = "OK" end
    strCheckResult = curTime..strCheckResult
    strSetAttr = strSetAttr.."S_CHECK_RESULT = '"..strCheckResult.."'"
 
    strCondition = "S_ID = '"..id.."'"
    nRet, strRetInfo = mobox.updateDataAttrByCondition( strLuaDEID, "Location_Group", strCondition, strSetAttr )
    if ( nRet ~= 0 ) then  
        Debug( strLuaDEID, debug.getinfo(1), "ôf°e0'MOÄ~01Y%!", strRetInfo )
        return 1, "ôf°e0'MOÄ~01Y%! Á‰ŒÕ‹åe×_"        
    end
    return 0, "ok"
end
 
--[[
    !hŒš'MOÄ~^\'`„vcknx'`
--]]
function WMS_DataCheck_Loaction_Group( strLuaDEID, id )
    local nRet, strValue
 
    if (id == '' or id == nil ) then
        return 1, "WMS_DataCheck_Loaction_Group ÂSpeidÅ_{˜    g<P!"
    end
    -- ŠbGUID {xxxx-xxxx} 9eb xxxx-xxxx
    id = trim_guid_str(id)
 
    local data_obj
    nRet, data_obj = GetDataObject( strLuaDEID, "Location_Group", id ) 
    if ( nRet ~= 0 )  then 
        Debug( strLuaDEID, debug.getinfo(1), "GetDataObject1Y%!", data_obj )
        return 1, "GetDataObject1Y%! Á‰ŒÕ‹åe×_" 
    end 
 
    -- –™HQ—‰·ƒÖS 'MOÄ~     gêT›N'MOÄ~b
    local loc_set = {}
    local strOrder = ''
    local strLocCondition = "S_AREA_CODE ='"..data_obj.area_code.."' AND N_ROW_GROUP = "..data_obj.row_group.." AND N_COL = "..data_obj.col.." AND N_LAYER = "..data_obj.layer
    nRet, strRetInfo = mobox.queryDataObjAttr( strLuaDEID, "Location", strLocCondition, strOrder )
    if ( nRet ~= 0 ) then 
        Debug( strLuaDEID, debug.getinfo(1), "·ƒÖS0Location01Y%!", strLocCondition )
        return 1, "·ƒÖS0Location01Y%! Á‰ŒÕ‹åe×_"
    end
 
    local ext_data = {}
    ext_data.id = id
    ext_data.cls = "Location_Group"
    local strSetAttr = ''
    local strCheckResult = ''           -- !hŒšÓ~œg
 
    if ( strRetInfo == '' ) then 
        -- 201 àeHepenc
        WMS_Warning2( strLuaDEID, 2, 201, "àeHe'MOÄ~ ÿú^®‹ Rd–!", table2str(ext_data), "", "DataCheck" )
        nRet, strRetInfo = upadte_location_group( strLuaDEID, id, "", "àeHe'MOÄ~ ÿú^®‹ Rd–!" )
        return nRet, strRetInfo
    end
 
    local retObjs = json.decode( strRetInfo )
    local n
    local capacity = 0
    local cur_num = 0
    local in_lock_num = 0
    local out_lock_num = 0
    local loc = {}
 
    -- ·ƒÖS TN*N'MOÄ~„v'MOáOo` ÿ͑°e¡‹—{ capacity I{pe<Pϑ
    for n = 1, #retObjs do
        nRet, loc = ObjAttrStrToLuaObj( "Location", table2str(retObjs[n].attrs) )
        if ( nRet ~= 0 ) then 
            Debug( strLuaDEID, debug.getinfo(1), "ObjAttrStrToLuaObj(Location) 1Y%!", loc )
            return 1, "ObjAttrStrToLuaObj(Location) 1Y%! Á‰ŒÕ‹åe×_"
        end  
        capacity = capacity + loc.capacity
        cur_num = cur_num + loc.cur_num
        -- 1 eQ“^•  2 úQ“^•
        if ( loc.lock_state == 1 ) then 
            in_lock_num = in_lock_num + 1
        elseif ( loc.lock_state == 2 ) then 
            out_lock_num = out_lock_num + 1
        end
    end   
 
    if ( data_obj.capacity ~= capacity ) then
        strSetAttr = strSetAttr.."N_CAPACITY = "..capacity..","
        strCheckResult = strCheckResult.."¹[ϑ:("..data_obj.capacity.." -> "..capacity.."),"
    end
 
    if ( data_obj.cur_num ~= cur_num ) then
        strSetAttr = strSetAttr.."N_CURRENT_NUM = "..cur_num..","
        strCheckResult = strCheckResult.."¹[hVpeϑ:("..data_obj.cur_num.." -> "..cur_num.."),"
    end
    
    if ( data_obj.in_lock_num ~= in_lock_num ) then
        strSetAttr = strSetAttr.."N_IN_LOCK_NUM = "..in_lock_num..","
        strCheckResult = strCheckResult.."eQ“^•peϑ:("..data_obj.in_lock_num.." -> "..in_lock_num.."),"
    end
    
    if ( data_obj.out_lock_num ~= out_lock_num ) then
        strSetAttr = strSetAttr.."N_OUT_LOCK_NUM = "..out_lock_num..","
        strCheckResult = strCheckResult.."úQ“^•peϑ:("..data_obj.out_lock_num.." -> "..out_lock_num.."),"
    end    
 
    -- ·ƒÖS'MOÄ~̑„vX[¨P„v'ÁTáOo`
    local strCondition = "S_CNTR_CODE IN ( Select S_CNTR_CODE From TN_Loc_Container Where S_LOC_CODE In ( Select S_CODE From TN_Location "
    strCondition = strCondition.." Where "..strLocCondition.."))"
    local strOrder = "S_CNTR_CODE"
    nRet, strRetInfo = mobox.queryDataObjAttr( strLuaDEID, "CG_Detail", strCondition, strOrder )
    if ( nRet ~= 0 ) then  
        Debug( strLuaDEID, debug.getinfo(1), "·ƒÖS0CG_Detail01Y%!", strCondition )
        return 1, "·ƒÖS0CG_Detail01Y%! Á‰ŒÕ‹åe×_"
    end 
 
    if ( strRetInfo ~= '' ) then
        local cg_detail
        local item_code = ''
        local item_name = ''
        local batch_no = ''
        local owner = ''
        local end_user = ''
        local supplier = ''
 
        retObjs = json.decode( strRetInfo )
        for n = 1, #retObjs do
            nRet, cg_detail = ObjAttrStrToLuaObj( "CG_Detail", table2str(retObjs[n].attrs) )
            if ( nRet ~= 0 ) then 
                Debug( strLuaDEID, debug.getinfo(1), "ObjAttrStrToLuaObj(CG_Detail) 1Y%!", loc )
                return 1, "ObjAttrStrToLuaObj(CG_Detail)) 1Y%! Á‰ŒÕ‹åe×_"
            end 
            if ( n == 1 ) then
                item_code = cg_detail.item_code
                item_name = cg_detail.item_name
                batch_no = cg_detail.batch_no
                owner = cg_detail.owner
                end_user = cg_detail.end_user
                supplier = cg_detail.supplier
            else
                if ( item_code ~= cg_detail.item_code ) then item_code = '' end
                if ( item_name ~= cg_detail.item_name ) then item_name = '' end
                if ( batch_no ~= cg_detail.batch_no ) then batch_no = '' end
                if ( owner ~= cg_detail.owner ) then owner = '' end
                if ( end_user ~= cg_detail.end_user ) then end_user = '' end
                if ( supplier ~= cg_detail.supplier ) then supplier = '' end
            end 
        end  
        
        if ( data_obj.item_code ~= item_code ) then
            strSetAttr = strSetAttr.."S_ITEM_CODE = '"..item_code.."',"
            strCheckResult = strCheckResult..'ir™ex:("'..data_obj.item_code..'" -> "'..item_code..'"),'
        end
        if ( data_obj.item_name ~= item_name ) then
            strSetAttr = strSetAttr.."S_ITEM_NAME = '"..item_name.."',"
            strCheckResult = strCheckResult..'ir™e Tðy:("'..data_obj.item_name..'" -> "'..item_name..'"),'
        end
        if ( data_obj.batch_no ~= batch_no ) then
            strSetAttr = strSetAttr.."S_BATCH_NO = '"..batch_no.."',"
            strCheckResult = strCheckResult..'yb!k÷S:("'..data_obj.batch_no..'" -> "'..batch_no..'"),'
        end
        if ( data_obj.owner ~= owner ) then
            strSetAttr = strSetAttr.."S_OWNER = '"..owner.."',"
            strCheckResult = strCheckResult..'';N:("'..data_obj.owner..'" -> "'..owner..'"),'
        end
        if ( data_obj.end_user ~= end_user ) then
            strSetAttr = strSetAttr.."S_ITEM_CODE = '"..end_user.."',"
            strCheckResult = strCheckResult..'O(uUSMO:("'..data_obj.end_user..'" -> "'..end_user..'"),'
        end
        if ( data_obj.supplier ~= supplier ) then
            strSetAttr = strSetAttr.."S_ITEM_CODE = '"..supplier.."',"
            strCheckResult = strCheckResult..'›O”^FU:("'..data_obj.supplier..'" -> "'..supplier..'"),'
        end     
    end
 
    nRet, strRetInfo = upadte_location_group( strLuaDEID, id, strSetAttr, strCheckResult )
    return nRet, strRetInfo
end
 
function Test( strLuaDEID )
    local nRet, strRetInfo
 
    local strOrder = "S_CODE"
    nRet, strRetInfo = mobox.queryDataObjAttr( strLuaDEID, "Location_Group", "", strOrder )
    if ( nRet ~= 0 or strRetInfo == '') then 
        Error( strLuaDEID, debug.getinfo(1), "·ƒÖS0Location_Group01Y%!"..strRetInfo )
    end 
    local n
    local retObjs
    retObjs = json.decode( strRetInfo )
 
    for n = 1, #retObjs do
        nRet, strRetInfo = WMS_DataCheck_Loaction_Group( strLuaDEID, retObjs[n].id )
        if ( nRet ~= 0 ) then 
            Error( strLuaDEID, debug.getinfo(1), "WMS_DataCheck_Loaction_Group 1Y%!"..strRetInfo )
        end
    end
end