1
Jianw
10 天以前 70f29da38121b9a467841253e3268feb5df02902
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
--[[
    编码: WMS-80-22
    名称: Picking车设备动作监听
    作者:HAN    
    日期:2025-6-20
        
    入口函数: EQActionProcess
             
        
    功能说明:
            Action
            -- LocationChange   位置变化
            -- Dispatched       调度派车
            -- Pickup_Finish    取货完成
            -- Finish           卸货完成
 
    变更记录:
--]]
 
wms_mang = require( "wms_in_whmang" )
 
function EQActionProcess ( strLuaDEID ) 
    local nRet, strRetInfo
    
    -- step1  获取设备动作队列 MQ_EQAction
    local mq_eq_action
    nRet, mq_eq_action = m3.GetSysCurEditDataObj( strLuaDEID, "MQ_EQAction ")
    if ( nRet ~= 0 ) then 
        lua.Stop( strLuaDEID, mq_eq_action ) 
        return
    end 
    m3.PrintLuaDEInfo( strLuaDEID )
    lua.DebugEx( strLuaDEID, "mq_eq_action", mq_eq_action )
 
    -- step2: 
    -- 获取 容器信息 通过容器去判断是否存在 Task 
    -- 检查任务的状态是否=完成,已经完成的任务也不能继续接收 action
    local task = {}
    local task_code = mq_eq_action.task_code or ''
    local cntr_code = ''
    if task_code == '' then
        lua.Stop( strLuaDEID, "消息队列中缺少任务号信息!")
        return
    end
    nRet, task = m3.GetDataObjectByKey( strLuaDEID, "Task", "S_CODE", task_code )
    if nRet ~= 0 then 
        lua.Stop( strLuaDEID, "获取【Task】信息失败! " .. task_objs ) 
        return
    end
    cntr_code = task.cntr_code
    if cntr_code == '' then
        lua.Stop( strLuaDEID, "任务'" .. task_code.."'没有容器信息!" ) 
        return
    end       
 
    local task_id = lua.trim_guid_str( task.id )
 
    -- 解析 Grace 系统上报上来的 信息
    --[[
            { 
              "id": 4761262, 
              "orderID": 1174692, 
              "orderName": "TA250707-00005", 
              "orderStatus": "dispatched", 
              "agvIDList": "9", 
              "priority": 1, 
              "currentDes": "AG02", 
              "currentCmd": null, 
              "errorCode": 0, 
              "extraInfo1": [], 
              "extraInfo2": "", 
              "deadLine": "None", 
              "createdTime": "2025-07-07 16:03:35", 
              "createdUser": "mobox_api", 
              "StatusChangeTime": "2025-07-07 16:13:27"
            }        
    --]]
    local str_body = mq_eq_action.data or ''
    if str_body == '' then
        lua.Stop( strLuaDEID, "获取【Task】信息失败! " .. task_objs ) 
        return
    end
    local body, success
    success, body = pcall( json.decode, str_body )
    if ( success == false ) then
        lua.Stop( strLuaDEID, "Grace 上传的 body 数据JSON格式非法! " )
        return
    end    
    local task_action_value = ''
    local strUpdateSql, strCondition
 
    if mq_eq_action.action == "LocationChange" then
        --[[
        local from_loc = body.start_location or ''
        local to_loc = body.current_location or ''
 
        if from_loc == '' then
            lua.Stop( strLuaDEID, "Grace 上传的 body 数据 中 start_location 为空! " )
            return
        end   
        if to_loc == '' then
            lua.Stop( strLuaDEID, "Grace 上传的 body 数据 中 current_location 为空! " )
            return
        end  
        -- 容器所在货位移动
        nRet, strRetInfo = wms_mang.CNTR_Move( strLuaDEID, cntr_code, to_loc_code, "Picking AGV Moving...")
        if nRet ~= 0 then
            lua.Stop( strLuaDEID, strRetInfo )
            return
        end          
        task_action_value = "Picking 搬运从: ["..from_loc.."] --> ["..to_loc.."]"
        ]]
    elseif mq_eq_action.action == "Dispatched" then
        -- 调度派车
        local agv_id = body.agvIDList or ''
        -- 更新Task状态为 Run/执行
        strUpdateSql = "N_B_STATE = "..TASK_STATE.Run..", S_EQ_NO = '"..agv_id.."', S_B_STATE = '执行'"
        strCondition = "S_CODE = '"..task_code.."'"
        nRet, strRetInfo = mobox.updateDataAttrByCondition( strLuaDEID, "Task", strCondition, strUpdateSql )
        if ( nRet ~= 0 ) then
            lua.Stop( strLuaDEID, "更新任务状态信息失败!"..strRetInfo )
            return
        end   
        task_action_value = "调度系统派编号='"..agv_id.."'的AGV执行任务!"        
    elseif mq_eq_action.action == "Pickup_Finish" then
        -- 取货完成
        -- 容器和作业、任务的开始货位解绑,移动到 current_location
        local from_loc = task.start_loc_code
        local to_loc = body.currentDes or ''
        if from_loc == '' then
            lua.Stop( strLuaDEID, "任务起始位置为空! " )
            return
        end   
        if to_loc == '' then
            lua.Stop( strLuaDEID, "Grace 上传的 body 数据 中 current_location 为空! " )
            return
        end  
        task_action_value = "取货完成"    
        
        nRet, strRetInfo = wms_mang.CNTR_Move( strLuaDEID, cntr_code, to_loc, "Picking AGV Moving...")
        if nRet ~= 0 then
            lua.Stop( strLuaDEID, strRetInfo )
            return
        end  
 
    elseif mq_eq_action.action == "Finish" then
        -- 更新 Task 和 Operation的最终位置
        local to_loc_code = body.currentDes or '' 
        if to_loc_code == '' then
            lua.Stop( strLuaDEID, "Grace 上传的 body 数据 中 current_location 为空! " )
            return
        end    
        local to_loc 
        nRet, to_loc = wms_wh.GetLocInfo( to_loc_code )
        if nRet ~= 0 then
            lua.Stop( strLuaDEID, "系统获取货位'"..to_loc_code.."'信息失败! "..to_loc )
            return
        end
        strUpdateSql = "S_END_LOC = '"..to_loc.code.."', S_END_AREA = '"..to_loc.area_code.."', S_END_WH = '"..to_loc.wh_code.."'"
        strCondition = "S_CODE = '"..task_code.."'"
        nRet, strRetInfo = mobox.updateDataAttrByCondition( strLuaDEID, "Task", strCondition, strUpdateSql )
        if ( nRet ~= 0 ) then
            lua.Stop( strLuaDEID, "更新任务信息失败!"..strRetInfo )
            return
        end   
 
        -- Picking 车搬运完成    
        nRet, strRetInfo = wms.wms_TaskFinish( strLuaDEID, task_code )
        if ( nRet ~= 0 ) then 
            -- V7.2
            local setAttr, strErr
            setAttr = "S_ERR = '".."在设备动作监听脚本 WMS-80-22 中执行 wms_TaskFinish 失败! 原因:"..strRetInfo.."'"
            nRet, strErr = mobox.addProcSQL2( "Task", task_id, setAttr )
            if ( nRet ~= 0 ) then
                lua.Stop( strLuaDEID, "addProcSQL2 失败!"..strErr )
                return
            end
            lua.Stop( strLuaDEID, "任务编码='"..task_code.."'的任务设置完成失败!"..strRetInfo ) 
            return
        end  
        task_action_value = "Picking 车搬运完成"        
    end             
 
 
    -- 增加 任务动作 对象
    local task_action = m3.AllocObject(strLuaDEID,"Task_Action")
    task_action.task_code = mq_eq_action.task_code
    task_action.action_code = mq_eq_action.action_code
    task_action.action = mq_eq_action.action
    task_action.eq_code = mq_eq_action.eq_code
    task_action.eq_type_name = mq_eq_action.eq_type_name
    task_action.data = lua.FormatJsonString( mq_eq_action.data )
    task_action.value = task_action_value
    nRet, strRetInfo = m3.CreateDataObj( strLuaDEID, task_action )
 
end