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
ÿþ-- 9hncyb!k·ƒÖSËz“^úQ“^'MO
-- OHQ§~ 10YñmMO \ 20YñmMO¡l    g'ÁT„vUS*N…QñmMO \ 30YñmMOX[(W'ÁT„v…QñmMOÿُÍyÅ`µQ—‰HQûy“^    ÿ
local function GT_GetLocCodeByBatchNo(strLuaDEID, batch_no)
   -- ·ƒÖSYñmMO'MO
   local nRet, inside_data, strRetInfo
   local strFromTabInfo = "TN_Loc_Container a LEFT JOIN TN_CG_Detail b ON a.S_CNTR_CODE = b.S_CNTR_CODE"
   strFromTabInfo = strFromTabInfo .. " LEFT JOIN TN_Location c ON a.S_LOC_CODE = c.S_CODE"
   -- ågâ‹ÔÞV„vW[µk
   local strAttrInfo = " a.S_LOC_CODE,a.S_CNTR_CODE,c.N_ROW_GROUP "
   -- ågâ‹agöN yb!k÷Søv T ¹[hV¡l    g
N• 'MO:NYñmMO 'MO¡l    g
N•
   local strCondition = "b.S_BATCH_NO = '" .. batch_no .. "' AND c.N_POS = 1 AND c.N_LOCK_STATE = 0"
   nRet, inside_data = mobox.queryMultiTable(strLuaDEID, strAttrInfo, strFromTabInfo, 1, strCondition)
   if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "queryMultiTable1Y%! " .. inside_data) end
   if (inside_data ~= '') then
      inside_data = json.decode(inside_data)
      local loc_code = inside_data[1][1]  -- 'MO
      local cntr_code = inside_data[1][2] -- ¹[hV
      return loc_code, cntr_code
   end
 
   -- ‚Yœgå‹yb!k NX[(WYñmMO„v'MORåg⋅QñmMO'MO
   local data
   strCondition = "b.S_BATCH_NO = '" .. batch_no .. "' AND c.N_POS = 2 AND c.N_LOCK_STATE = 0"
   nRet, inside_data = mobox.queryMultiTable(strLuaDEID, strAttrInfo, strFromTabInfo, 10, strCondition)
   if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "queryMultiTable1Y%! " .. inside_data) end
   if (inside_data == '') then lua.Error(strLuaDEID, debug.getinfo(1), "Ëz“^ NX[(Wyb!k÷S:N" .. batch_no .. "„v'ÁT!") end
   inside_data = json.decode(inside_data)
   for i = 1, #inside_data do
      local loc_code = inside_data[i][1]  -- 'MO
      local cntr_code = inside_data[i][2] -- ¹[hV
      local row_group = inside_data[i][2] -- ¹[hV
      -- ·ƒÖS…QñmMOù[”^„vYñmMO
      local new_loc_code
      nRet, new_loc_code = OuterDeepPosition(strLuaDEID, row_group, loc_code)
      if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), new_loc_code) end
      -- $R­eYñmMO/f&TX[(W'ÁT,X[(WRRú^ûy“^\ON, NX[(WRôv¥cԏÞV'MOx
      strCondition = "N_CURRENT_NUM = 0 AND S_CODE = '" .. new_loc_code .. "'"
      nRet, strRetInfo = mobox.getDataObjCount(strLuaDEID, "Location", strCondition)
      if (nRet ~= 0) then return 1, strRetInfo end
      lua.Debug(strLuaDEID, debug.getinfo(1), 'strRetInfo', strRetInfo)
      if (tonumber(strRetInfo) > 0) then
         return loc_code, cntr_code
      else
         data[i] = {
            loc_code = loc_code,
            cntr_code = cntr_code,
            new_loc_code = new_loc_code
         }
      end
   end
 
   -- S_ãNxp0Rُ,ãNhˆÙ*Nyb!k„vir™e(WYñmMOŒTUS*N…QñmMO/f NX[(W„v,’cåg/f&TX[(W …QñmMOFO/fYñmMOX[(W'ÁT
   if (data == nil) then
      return 2, "å‹yb!k¡l    gïSúQ“^„vir™e!"
   else
      local loc_code = data[1].loc_code
      local cntr_code = data[2].cntr_code
      local new_loc_code = data[3].new_loc_code
      -- OHQRú^ûy“^\ON
      -- ·ƒÖSw¹páOo`
      local start_loc, end_loc
      nRet, start_loc = wms_wh.GetLocInfo(new_loc_code)
      if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), 'WMS_GetLocInfo1Y%!' .. start_loc) end
 
      -- ·ƒÖSÈ~¹páOo`
      nRet, end_loc = GetEndLoc(strLuaDEID, start_loc.roadway)
      if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), end_loc) end
 
      -- ·ƒÖS¹[hVáOo`
      strCondition = "S_LOC_CODE = '" .. new_loc_code .. "'"
      local cntr_loc
      nRet, cntr_loc = m3.GetDataObjByCondition(strLuaDEID, "Loc_Container", strCondition)
      if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "·ƒÖS0'MO¹[hV0áOo`1Y%! " .. cntr_loc) end
 
      -- Rú^sOûN¡R
      local gt_task = m3.AllocObject(strLuaDEID, "GT_Task")
      lua.Debug(strLuaDEID, debug.getinfo(1), 'gt_task', gt_task)
      -- w¹páOo`
      gt_task.start_wh_code = start_loc.wh_code
      gt_task.start_area_code = start_loc.area_code
      gt_task.start_loc_code = start_loc.code
      -- È~¹páOo`
      gt_task.end_wh_code = end_loc.wh_code
      gt_task.end_area_code = end_loc.area_code
      gt_task.end_loc_code = end_loc.code
      gt_task.type = 3     -- 1 ‰|™eŒèb,dЏ 2 Øpö€,dЏ 3  T÷]Sûy“^
      gt_task.priority = 2 -- 'Y„vOHQ
      gt_task.cntr_code = cntr_loc.cntr_code
      nRet, gt_task = m3.CreateDataObj(strLuaDEID, gt_task)
      if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), 'Rú^0sOûN¡R01Y%!' .. gt_task) end
      return loc_code, cntr_code
   end
end
 
--[[
 x: GT-100-12
  Tðy: 009“^…Q YÀhúQ“^
 \O€: LZH
 eQãSýQpeÿRecheckOutbound
 ŸRý€ô‹f: 9hncyb!k÷SŒTXbØvpeϑR \ON
 
        “eQpencÿ                                                                                        
        {    
        "location": "xxx",    MOn(    N|i YÀhúQ“^cš[ù[”^„v\s^“^)
        "batch_no": "xxx",    yb!k÷S
        "cntr_qty": "xxx",    XbØvpeϑ
        "wh_code": "xxx"    ÓN“^÷S
        }    
 
 
        Yt;‘
        -- step1 ã‰g¥cãS O„v datajson ÂSpe
        -- step2 !hŒšÅ_ OW[µk/f&T:Nzz ÿ:NzzR¥b•
        -- step3 Rú^\ON
 
 ØSôf†SòS:
 --]]
m3    = require("oi_base_mobox")
json  = require("json")
mobox = require("OILua_JavelinExt")
require("WMS-Equipment")
wms_cntr = require("wms_container")
wms_wh = require("wms_wh")
require("GT-Base")
require("GT_InAndOutboundPolicies")
function RecheckOutbound(strLuaDEID)
   local nRet, in_date
   -- step1 ·ƒÖS¥cãSpenc
   nRet, in_date = m3.GetSysDataJson(strLuaDEID)
   if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "WCStoreCallback àeÕl·ƒÖSpencS!" .. in_date) end
   lua.Debug(strLuaDEID, debug.getinfo(1), '“^…Q YÀhúQ“^ NÑSÂSpe:', in_date)
 
   -- step2 $R­e/f&Tý    g<Pÿ¡l<P¥b•ԏÞV
   local location = in_date.location
   if (location == nil or location == '') then location = 'GSXXK-03' end
   local batch_no = in_date.batch_no
   if (batch_no == nil or batch_no == '') then lua.Error(strLuaDEID, debug.getinfo(1), "yb!k÷S Ný€:Nzz!") end
   local cntr_qty = tonumber(in_date.cntr_qty)
   if (cntr_qty == nil or cntr_qty == 0) then lua.Error(strLuaDEID, debug.getinfo(1), "peϑ Ný€:Nzz!") end
   local wh_code = in_date.wh_code
   if (wh_code == nil or wh_code == '') then lua.Error(strLuaDEID, debug.getinfo(1), "ÓN“^÷S Ný€:Nzz!") end
 
   local start_loc, end_loc
   for i = 1, cntr_qty do
      -- 9hncyb!k÷S·ƒÖS'MOx
      local loc_code, cntr_code = GT_GetLocCodeByBatchNo(strLuaDEID, batch_no)
      -- ·ƒÖSw¹p
      nRet, start_loc = wms_wh.Location_GetInfo(strLuaDEID, loc_code)
      if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "WMS_Location_GetInfo1Y%!" .. start_loc) end
      -- ·ƒÖSÈ~¹p(È~¹p:N YÀhúQ“^USìr„vN*N\s^“^(uegX[>e YÀh„v¹[hVŒT'ÁT)
      nRet, end_loc = wms_wh.Location_GetInfo(strLuaDEID, location)
      if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "WMS_Location_GetInfo1Y%!" .. end_loc) end
 
      -- step3 Rú^\ON
      local operation           = m3.AllocObject(strLuaDEID, "Operation")
      -- w¹páOo`
      operation.start_wh_code   = start_loc.wh_code
      operation.start_area_code = start_loc.area_code
      operation.start_loc_code  = start_loc.code
      -- È~¹páOo`
      operation.end_wh_code     = end_loc.wh_code
      operation.end_area_code   = end_loc.area_code
      operation.end_loc_code    = end_loc.code
 
      operation.op_type         = wms_base.Get_nConst(strLuaDEID, "\ON{|‹W-úQ“^")
      operation.op_def_name     = " YÀhúQ“^"
      operation.cntr_code       = cntr_code
 
      -- àV:N/f(W\ON̑b—1\—‰•š['MO ÿ@båNÐcMRK<P–™!kûN¡R÷S ÿ(uŽN•š['MO
      local strCode             = ''
      local strHeader           = 'TA' .. os.date("%y%m%d") .. '-'
      nRet, strCode             = mobox.getSerialNumber("ûN¡R", strHeader, 5)
      -- ¾‹nibU\ÂSpe&^eQ\ON/T¨R ÿûN¡RŒ[b
      local ext_table           = {}
      ext_table.task_no         = strCode
      -- ibU\ÂSpe
      operation.ext_data        = lua.table2str(ext_table)
      nRet, operation           = m3.CreateDataObj(strLuaDEID, operation)
      if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), 'Rú^0\ON01Y%!' .. operation) end
 
      -- Ù~w¹p'MO R
NúQ“^•
      local strRetInfo
      nRet, strRetInfo = wms.wms_LockLocation(strLuaDEID, operation.start_loc_code,
         wms_base.Get_nConst(strLuaDEID, "•{|‹W-úQ“^•"), strCode, operation.code, operation.op_def_name)
      if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "wms_LockLocation 1Y%!" .. strRetInfo) end
 
      -- îO9e¹[hV'ÁTfÆ~„vhƋ:N YÀhúQ“^
      local condition = "S_CNTR_CODE = '" .. cntr_code .. "'"
      local strSetSQL_update = "N_IS_FJ = 1"
      nRet, strRetInfo = mobox.updateDataAttrByCondition(strLuaDEID, "CG_Detail", condition, strSetSQL_update)
      if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "îO9e¹[hV'ÁTfÆ~1Y%ÿ" .. strRetInfo) end
   end
end