fy36
2025-07-01 350eb5ec9163d3ea21416b1525bb80191e958071
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
ÿþ--[[  
    x: JX-API-07
     Tðy: Rú^ûN¡R`lv^ TekFUÁTagxáOo`
    \O€:     
    åeg: 2025-1-29
 
    eQãSýQpeÿ sync
              
    ŸRý€ô‹f:
        ¥c6eegê
N8nû|ß~„vFUÁTagxáOo` ÿv^\vQ Tek0RûN¡R`l `TaskPool`0
 
        “eQ: FUÁTagxáOo` (Array)
 
            {
                "trayNo": "TK0012345",      -- XbØv÷S
                "trayType": "ánXb",         -- XbØv{|‹W
                "sourceSys": "è]f",        -- egnû|ß~
                "sourNo": "JX78",           -- 
N8nûN¡R÷S
                "IsLong": "0",              -- /f&T•öeô• NO(u
                "taskType": "eQ“^",         -- \ON{|‹W
                "desArea":"ZG2"             -- È~¹p“^:S
            }
    
 
    ØSôf°‹U_:
--]]
 
wms_base = require( "wms_base" )
wms_cntr = require( "wms_container" )
 
function sync(strLuaDEID)
    local nRet, idcode  
    local empty_full
    local outTaskInfo
    local taskCondition,strRetInfo
 
    nRet, idcode = m3.GetSysDataJson(strLuaDEID)  
    if (nRet ~= 0) then  
        lua.Error(strLuaDEID, debug.getinfo(1), "àeÕl·ƒÖSpencS datajson!" .. idcode)  
    end  
    -- Àhåg OeQ„vXbØváOo`/f&T:Nzz
    if (idcode == nil or idcode == '')then
        lua.Error(strLuaDEID, debug.getinfo(1), "¡l    gïSYt„vXbØváOo`")
    end
    
    lua.Debug( strLuaDEID, debug.getinfo(1), "idcode-->", idcode ) 
    
    local cntr_code = lua.Get_StrAttrValue(idcode.trayNo)           --XbØv÷S
    local source_sys = lua.Get_StrAttrValue(idcode.sourceSys)       --egnû|ß~
    local sour_no = lua.Get_StrAttrValue(idcode.sourNo)             --
N8nûN¡R÷S
    local tray_type = lua.Get_StrAttrValue(idcode.trayType)         --XbØv{|‹W
    local end_area_code = lua.Get_StrAttrValue(idcode.desArea)     --È~¹p“^:S
    local task_type = lua.Get_StrAttrValue(idcode.taskType)         --\ON{|‹W
 
    if (cntr_code == '') then
        lua.Error(strLuaDEID, debug.getinfo(1), "XbØv÷S Ný€:Nzz!")  
    end
    if (tray_type == '') then
        lua.Error(strLuaDEID, debug.getinfo(1), "XbØv{|‹W Ný€:Nzz!")  
    end
    if (source_sys == '') then
        lua.Error(strLuaDEID, debug.getinfo(1), "egnû|ß~ Ný€:Nzz!")  
    end
    if (sour_no == '') then
        lua.Error(strLuaDEID, debug.getinfo(1), "
N8nûN¡R÷S Ný€:Nzz!")  
    end
    if (end_area_code == '') then
        lua.Error(strLuaDEID, debug.getinfo(1), "È~¹p“^:S Ný€:Nzz!")  
    end
    -- if (task_type == '') then
    --     lua.Error(strLuaDEID, debug.getinfo(1), "\ON{|‹W Ný€:Nzz!")  
    -- end
    
    -- if (task_type == "eQ“^" and end_area_code ~= "ZG2") then
    --     lua.Error(strLuaDEID, debug.getinfo(1), "\ON{|‹W:NeQ“^öe,È~¹p“^:SÅ_{˜:NZG2")
    -- elseif (task_type == "ÙzðS,dЏ" and end_area_code == "ZG2") then
    --     lua.Error(strLuaDEID, debug.getinfo(1), "\ON{|‹W:NÙzðS,dЏöe,È~¹p“^:S Ný€:NZG2")
    -- end
 
    
 
    -- ågâ‹ûN¡R`l-N/f&Tò]X[(Wøv Tpencÿ9hncXbØv÷S0ûN¡R¶r`ŒTûN¡R÷S    ÿ
    local outTaskCondition = "(S_CNTR_CODE = '" .. cntr_code .. "' AND N_B_STATE IN (0,1)) OR (S_SOURNO = '" .. sour_no .. "')"
    local nRetTask, outTaskInfo = mobox.existThisData(strLuaDEID, "JX_Task", outTaskCondition)
    if (nRetTask ~= 0) then
        lua.Error(strLuaDEID, debug.getinfo(1), "ågâ‹ûN¡R`löeÑSu•ï‹: " .. outTaskInfo)
    end
    if (outTaskInfo == "yes") then
        lua.Error(strLuaDEID, debug.getinfo(1), "ûN¡R`l-Nò]X[(Wøv TûN¡R: XbØv÷S " .. cntr_code .. ", ûN¡R÷S " .. sour_no)
    end
    --$R­eÈ~¹p“^:S/f&TX[(W
    strCondition = "S_CODE='" .. end_area_code .. "'"
    nRet, strRetInfo = mobox.existThisData(strLuaDEID, "Area", strCondition)
    if (nRet ~= 0) then
        lua.Error(strLuaDEID, debug.getinfo(1), "ÀhågÈ~¹p“^:S'" .. end_area_code .. "'öeÑSu•ï‹ ÿïSý€/f: " .. strRetInfo)
    end
    if (strRetInfo ~= "yes") then
        lua.Error(strLuaDEID, debug.getinfo(1), "È~¹p“^:S'" .. end_area_code .. "' NX[(W ÿ÷‹Àhåg“eQ")
    end
    --$R­e¹[hVŒTegnû|ß~/f&Tù[„v
N
    local cntr_obj
    nRet, cntr_obj = wms_cntr.GetInfo( strLuaDEID, cntr_code )
    lua.Debug( strLuaDEID, debug.getinfo(1), "cntr_obj-->", cntr_obj )
    if ( nRet ~= 0 ) then 
        lua.Error( strLuaDEID, debug.getinfo(1), "·ƒÖS¹[hVù[aŒ1Y%! "..cntr_obj ) 
    end 
    if ( cntr_obj == '' ) then
        lua.Error( strLuaDEID, "x = '"..cntr_code.."'„vãb™e±{ NX[(W!")
    end
    -- $R­e™e±{/f&Tò]Ï~    gÑ~š[
    if ( cntr_obj.source ~=  'è]f' ) then
        lua.Error( strLuaDEID, "x = '"..cntr_code.."'„vãb™e±{ N/fè]f„v")
    end
    
    if (cntr_obj.position ~= nil and cntr_obj.position ~= "") then
        lua.Error(strLuaDEID, debug.getinfo(1), "™e±{÷S = '"..cntr_code.."' „vãb™e±{ò](W“^…Q ÿMOn: " .. tostring(cntr_obj.position))
    end
    -- Rú^ûN¡R`lù[aŒ
    local jx_task = m3.AllocObject(strLuaDEID, "JX_Task")
    jx_task.cntr_code = cntr_code               --XbØv÷S
    jx_task.tray_type = tray_type               --XbØv{|‹W
    jx_task.source_sys = source_sys             --egnû|ß~
    jx_task.sour_no = sour_no                   --
N8nûN¡R÷S
    jx_task.is_long = idcode.IsLong 
    jx_task.end_area_code = idcode.desArea      --È~¹p“^:S
    jx_task.task_type = "eQ“^"              -- \ON{|‹W
    jx_task.create_method = "JX-WMS"
    jx_task.start_wh_code = wms_base.Get_sConst(strLuaDEID, "؞¤‹ÓN“^hƋ")               --ÓN“^
 
    nRet, jx_task = m3.CreateDataObj(strLuaDEID, jx_task)  
    if (nRet ~= 0) then
        lua.Error(strLuaDEID, debug.getinfo(1), "Rú^ûN¡R`l°‹U_1Y%!" .. jx_task)  
    end
    
    lua.Debug( strLuaDEID, debug.getinfo(1), "jx_task-->", jx_task ) 
    
    --(uegôf°e¹[hVhˆ„vzzán¶r`
    if (tray_type == "ánXb") then
        empty_full = 2
    else
        empty_full = 0
    end
    local strUpdateSql = "N_EMPTY_FULL = " .. empty_full
    local strCondition = "S_CODE = '"..cntr_code.."'"
    nRet, strRetInfo = mobox.updateDataAttrByCondition( strLuaDEID, "Container", strCondition, strUpdateSql )
    if ( nRet ~= 0 ) then  
        lua.Error( strLuaDEID, debug.getinfo(1), "ôf°e0¹[hV0¶r`o`1Y%!"..strRetInfo ) 
    end   
 
 
    -- ÔÞVbŸRˆmo`
    return json.encode({status = "success", message = "ûN¡R`lRú^bŸR!"})  
end