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
ÿþ--[[  
    x: JX-API-08
     Tðy: úQ“^US‹NöNYt
    \O€ÿkun  
    åeg: 2025-1-29
 
    eQãSýQpeÿ main
              
    ŸRý€ô‹f:
        9hnc“eQpencRú^úQ“^USv^Ytøv”^;‘
        
    “eQ„v Data
    {
        "workorderNo": "YT10023105655",
        "sourceSys": "è]f",
        "startTime": "",
        "endTime": "",
        "type": 0,
        "priority": 99,
        "data": [{
            "startBit": "",
            "endBit": "",
            "endArea": "ZA2",
            "sourNo": "jx76543",
            "trayCode": "P90037073",
            "trayType": "ánXb"
        }, {
            "startBit": "",
            "endBit": "",
            "endArea": "ZA2",
            "sourNo": "jx76543",
            "trayCode": "P90099095",
            "trayType": "zzXb"
        }]
    }
    ôf9e°‹U_:
        V2.0 HAN 20241128 žX RTðSYt,gubè]fúQ“^\ON
--]]
 
wms_wh = require( "wms_wh" )
wms_base = require( "wms_base" )
 
function main(strLuaDEID)
    local nRet, strRetInfo
 
    -- ·ƒÖS¥cãS„vdatapenc
    local getinput
    nRet, getinput = m3.GetSysDataJson(strLuaDEID)
    if (nRet ~= 0) then 
        lua.Error(strLuaDEID, debug.getinfo(1), "àeÕl·ƒÖSpencS!" .. getinput) 
    end  
    lua.Debug(strLuaDEID, debug.getinfo(1), "getinput", getinput)
 
    -- ÂSpeÀhåg
    if (getinput.sourceSys == nil or getinput.sourceSys == '') then
        lua.Error(strLuaDEID, debug.getinfo(1), "egnû|ß~penc:Nzz,÷‹ÀhågÂSpe")
    end
    if (getinput.type == nil or getinput.type == '') then
        lua.Error(strLuaDEID, debug.getinfo(1), "ûN¡R{|‹W:Nzz,÷‹ÀhågÂSpe")
    end
    if (getinput.priority == nil or getinput.priority == '') then
        lua.Error(strLuaDEID, debug.getinfo(1), "OHQ§~penc:Nzz,÷‹ÀhågÂSpe")
    end
    if (#getinput.data == 0) then
        lua.Error(strLuaDEID, debug.getinfo(1), "data P[penc:Nzz,÷‹ÀhågÂSpe")
    end
 
    local sourceSys = getinput.sourceSys
 
    local startBit,area_code,task
    local endArea,strCondition
    local trayCode,cntr_obj
    local sourNo
    local endBit
    local trayType
    local priority
    local errorMessages = {}  
    local taskCondition,condition,loc_code
 
    -- M†S data peÄ~ ÿagRú^ûN¡R`l°‹U_
    for n = 1, #getinput.data do
        startBit = getinput.data[n].startBit    -- wËY'MO
        endArea = getinput.data[n].endArea      -- È~¹p“^:S
        trayCode = getinput.data[n].trayCode    -- XbØv÷S
        sourNo = getinput.data[n].sourNo        -- 
N8nûN¡R÷S
        endBit = getinput.data[n].endBit        -- È~¹p'MO
        trayType = getinput.data[n].trayType    -- XbØv{|‹W
        priority = getinput.priority            -- ûN¡ROHQ§~
 
 
        if (trayCode == nil or trayCode == '') then
            table.insert(errorMessages, "™e±{"..trayCode.."XbØv÷S:Nzz,÷‹ÀhågÂSpe")
            goto continue
        end
        if (endArea == nil or endArea == '') then
            table.insert(errorMessages, "™e±{"..trayCode.."È~¹p“^:S:Nzz,÷‹ÀhågÂSpe")
            goto continue
        end
        if (sourNo == nil or sourNo == '') then
            table.insert(errorMessages, "™e±{"..trayCode.."
N8nûN¡R÷S:Nzz,÷‹ÀhågÂSpe")
            goto continue
        end
 
        -- ågâ‹ûN¡R`l/f&Tò]X[(Wøv TûN¡RÿXbØv÷S0
N8nûN¡R÷S0¶r`    ÿ
        condition = "(S_CNTR_CODE = '" .. trayCode .. "' AND N_B_STATE IN (0,1)) OR (S_SOURNO = '" .. sourNo .. "')"
        nRet, strRetInfo = mobox.existThisData(strLuaDEID, "JX_Task", condition)
        if (nRet ~= 0) then
            table.insert(errorMessages, "ågâ‹ûN¡R`löeÑSuû|ß~•ï‹: " .. strRetInfo)
            goto continue
        end
        if (strRetInfo == "yes") then
            table.insert(errorMessages, "ûN¡R`l-Nò]X[(WXbØv÷S'" .. trayCode .. "'0egnû|ß~'" .. sourceSys .. "'ŒT
N8nûN¡R÷S'" .. sourNo .. "'„vûN¡R ÿàeÕl͑ YRú^")
            goto continue
        end
        -- $R­e“^:S/f&TX[(W
        strCondition = "S_CODE='" .. endArea .. "'"
        nRet, strRetInfo = mobox.existThisData(strLuaDEID, "Area", strCondition)
        if (nRet ~= 0) then
            table.insert(errorMessages, "ÀhågÈ~¹p“^:S'" .. endArea .. "'öeÑSu•ï‹ ÿïSý€/f: " .. strRetInfo)
            goto continue
        end
        if (strRetInfo ~= "yes") then
            table.insert(errorMessages, "È~¹p“^:S'" .. endArea .. "' NX[(W ÿ÷‹Àhåg“eQ")
            goto continue
        end
            
        --$R­e¹[hVŒTegnû|ß~/f&Tù[„v
N
        nRet, cntr_obj = wms_cntr.GetInfo( strLuaDEID, trayCode )
        lua.Debug( strLuaDEID, debug.getinfo(1), "cntr_obj-->", cntr_obj )
        if ( nRet ~= 0 ) then
            table.insert(errorMessages, "·ƒÖS¹[hVù[aŒ1Y%! "..cntr_obj)
            goto continue
        end 
        if ( cntr_obj == '' or cntr_obj == nil ) then
            table.insert(errorMessages, "x = '"..trayCode.."'„vãb™e±{ NX[(W!")
            goto continue
        end
        if ( cntr_obj.source ~=  'è]f' ) then
            table.insert(errorMessages, "ãb™e±{x = '"..trayCode.."' N/fè]f„v")
            goto continue
        end
 
        -- 'MOŒTûN¡R`l°‹U_Rú^;‘
        loc_code = wms_wh.GetLocCodeByCNTR(strLuaDEID, trayCode)
        if (loc_code == '') then
            table.insert(errorMessages, "™e±{"..trayCode..' N(W™e±{“^…Q!')
            goto continue
        end
 
        nRet, start_loc = wms_wh.GetLocInfo(loc_code)
        if (nRet ~= 0) then
            table.insert(errorMessages, "™e±{"..trayCode.."·ƒÖS'MO'" .. loc_code .. "'áOo`1Y%!")
            goto continue
        end
 
        area_code = start_loc.area_code
        if (area_code ~= wms_base.Get_sConst( strLuaDEID, "™e±{“^X[¨P:S" )) then
            table.insert(errorMessages, "™e±{"..trayCode.. "' N(WËz“^:Sÿ")
            goto continue
        end
 
        -- Rú^ûN¡R`l°‹U_
        task = m3.AllocObject(strLuaDEID, "JX_Task")
        task.start_loc_code = startBit          -- wËY'MO
        task.end_area_code = endArea            -- È~¹p“^:S
        task.end_loc_code = endBit              -- È~¹p'MO
        task.cntr_code = trayCode               -- XbØv÷S
        task.sour_no = sourNo                   -- 
N8nûN¡R÷S
        task.tray_type = trayType               -- XbØv{|‹W
 
        task.bs_no = getinput.workorderNo       -- úQ“^US÷S
        task.source_sys = getinput.sourceSys    -- egnû|ß~
        task.priority = priority                -- ûN¡ROHQ§~
        task.task_type = "úQ“^"                 -- \ON{|‹W
        task.create_method = "JX-WMS"
        task.start_wh_code =wms_base.Get_sConst(strLuaDEID, "؞¤‹ÓN“^hƋ")               --ÓN“^ T
 
        nRet, task = m3.CreateDataObj(strLuaDEID, task)
        if (nRet ~= 0) then
            table.insert(errorMessages, "Rú^ûN¡R`l1Y%ÿ" .. strRetInfo)
        end
        lua.Debug(strLuaDEID, debug.getinfo(1), "task", task)
        -- žX RN*NTðSۏ zRú^è]fúQ“^\ON
        local add_wfp = {
            wfp_type = 1,  -- æ‰ÑSpencù[aŒ‹NöNÿcš[pencù[aŒhƋ    ÿ
            cls = "JX_Task",
            obj_id = task.id,
            obj_name = "ûN¡R÷S'" .. task.sour_no .. "'è]fûN¡R-->Rú^è]fúQ“^\ON",
            trigger_event = "Rú^è]fúQ“^\ON"
        }
        nRet, strRetInfo = m3.AddSysWFP(strLuaDEID, add_wfp)
        if (nRet ~= 0) then
            table.insert(errorMessages, "AddSysWFP1Y%!" .. strRetInfo)
        end
        lua.Debug(strLuaDEID, debug.getinfo(1), "nRet", nRet)
        ::continue::
    end
 
    -- ÔÞVÂSpe
    local result = {
        success = true,
        errCode = 0,
        errMsg = ""
    }
 
 
    if (#errorMessages > 0) then
        result.success = false
        result.errCode = 1
        result.errMsg = table.concat(errorMessages, ",")
    end
 
    mobox.returnValue(strLuaDEID, 1, table2str(result))
    lua.Debug(strLuaDEID, debug.getinfo(1), "result", result)
    
end