1
Jianw
2025-07-09 f6f5e6b632d6649386a380558d84003f3de7ec6c
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
--[[
    编码: WMS-19-10
    名称: 国自Grace系统-任务推送
    作者:HAN    
    日期: 2025-1-29
    
    入口函数: Push
 
    功能说明:
              调用Grace的创建订单接口
              http://IP:2000/api/om/order/
              其中IP:2000定义在项目常量 Grace_Service 中
 
              参数:
                {
                    "order_name": "test1",  -- 订单名,必须有值
                    "priority": 1,          -- 优先级
                    "dead_line": "2025-02-01 16:00:00",     -- 订单截止时间, 可以不输入
                    "ts_name": "picking_ts",                -- Picking车固定
                    "parameters": "{"tote_id":"LX100001","task_type":"inbound","src":"S4-01-1-1",
                                    "dst":"AG01b","extra_info":[{"layer":[1,2,3,4],"put":true}]}",
                                tote_id -- 托盘/容器编码
                                task_type --    inbound/return/outbound/ic/empty/tally/move
                                                inbound    站台收完货到存储区
                                                return    站台拣选、盘点、理货完返库到存储区
                                                outbound    出库存储区到站台,到产线
                                                ic    盘点存储区到站台
                                                tally    理货存储区到站台
                                                move    库内移库
                                                empty    叫空托、产线搬运
                                src -- 起始货位/区域
                                dst -- 目标库位/区域
                                indicator -- 托盘冷热度 (A,B,C,D),A为最热门托盘。 默认值:D
                                extra_info -- 任务约束信息。默认值:空
                                                [
                                                    {”layer”:[1、2、3、4] “put”:false}、
                                                    {”toxic”:  true  “put” : false}、
                                                    {"size”: 10  "put" : false}
                                                ]
                                                layer -- 表示托盘能放哪些层,
                                                put   -- 表示当这些层放满后是否放其他层,true时可以放其他层
                                                toxic -- 表示物料是否为有毒有害物品,需要放置到特殊区域。
                                                put   -- 表示当特殊区域放满时,是否可以放置到其他位置
                                                size  -- 表示当前托盘尺寸级别,需要放置到尺寸对应区域。Put表示当对应尺寸区域放满,是否可以放置到其他位置
                    "created_user": "sa"    -- 创建者的名称
                }              
 
    变更记录:
 
--]]
 
wms_task = require( "wms_task" )
wms_op = require( "wms_operation" )
 
function Push( strLuaDEID ) 
    local nRet, strRetInfo, strObjJson
    local task
 
    lua.DebugEx( strLuaDEID, "In Push-->Grace", "In" )
 
    -- 获取需要推送的任务对象
    nRet, task = m3.GetSysCurEditDataObj( strLuaDEID, "Task" )
    if ( nRet ~= 0  ) then 
        lua.Stop( strLuaDEID, "m3.GetSysCurEditDataObj 失败!"..task )
        return
    end
 
    -- 如果任务状态 不等于 "等待" 状态就返回,不需要推送
    if task.bs_state ~= TASK_STATE.Wait  then 
        return 
    end
    if lua.StrIsEmpty( task.start_loc_code ) then
        lua.Stop( strLuaDEID, "任务中的起始位置不能为空" )
        return
    end
    if lua.StrIsEmpty( task.cntr_code ) then
        lua.Stop( strLuaDEID, "任务中的容器号不能为空" )
        return
    end    
 
    local svr_url
    nRet, svr_url = wms_base.Get_sConst2( "Grace_Service")
    if ( nRet ~= 0 ) then
        lua.Stop( strLuaDEID, "系统无法获取常量'Grace_Service'")
        return
    end
 
    -- 根据任务类型判断时 AGV 车还是 Picking 车
    local ts_name = ''
    local task_type = ''
    local vehicle_type = ''
 
    if task.type == TASK_TYPE.In_AGV then
        ts_name = "p2p"
        task_type = "inbound"
        vehicle_type = "AGV"
    elseif task.type == TASK_TYPE.Out_AGV then
         ts_name = "p2p"
         task_type = "outbound"
         vehicle_type = "AGV"
    elseif task.type == TASK_TYPE.In_Picking then
         ts_name = "picking_ts"
         task_type = "inbound"
         vehicle_type = "PICKING"
    elseif task.type == TASK_TYPE.Out_Picking then
        ts_name = "picking_ts"
        task_type = "outbound"
        vehicle_type = "PICKING"
    else
        lua.Stop( strLuaDEID, "目前 Grace 系统不支持类型值 = "..task.type.." 的任务推送")
        return        
    end
    local dts = ''
    if lua.StrIsEmpty( task.end_loc_code ) then
        if vehicle_type == "AGV" then
            lua.Stop( strLuaDEID, "AGV车辆必须要有明确的目标位置!" )
            return
        end
        dts = task.end_area_code
    else
        dts = task.end_loc_code
    end
 
    local extra_info = {}
    if not lua.StrIsEmpty( task.ext_info ) then
        local success
        success, extra_info = pcall( json.decode, task.ext_info )
        if ( success == false ) then
            lua.Stop( strLuaDEID, "Task中的S_EXT_INFO属性的JSON格式非法! " )
            return
        end 
    end
 
    local array_extra_info={}
    table.insert(array_extra_info,extra_info)
    local parameters = {
        tote_id = task.cntr_code,
        task_type = task_type,
        src = task.start_loc_code,
        dst = dts,
        extra_info = array_extra_info
    }
 
    local strurl =  svr_url..'/api/om/order/'
    local body = {
                order_name = task.code,
                priority = task.priority,
                ts_name = ts_name,
                parameters = json.encode(parameters),
                created_user = "mobox_api",
                dead_line="2025-07-07 15:00:00"
    }
 
    lua.DebugEx( strLuaDEID, "Gracy Order --> ", body )
    lua.DebugEx( strLuaDEID, "strurl --> ", strurl )
    
    --[[
    nRet, strRetInfo = mobox.sendHttpRequest( strurl, "",lua.table2str(body) )
    if ( nRet ~= 0 or strRetInfo == '' ) then 
        lua.Stop( strLuaDEID, "调用 Grace /api/om/order 接口失败! "..strRetInfo ) 
        return
    end   
    local ret_info = json.decode( strRetInfo ) 
    ]]
    local ret_info = { code = 0 }
    
    -- 设置任务状态=已推送
    if ret_info.code == 0 then
        -- 任务推送成功
        nRet, strRetInfo = wms_task.SetStateByCode( strLuaDEID, task.code, TASK_STATE.Pushed )
        if nRet ~= 0 then 
            lua.Stop( strLuaDEID, strRetInfo ) 
            return
        end
        -- 表示任务已经推送到设备
        nRet, strRetInfo = wms_op.SetTaskState( strLuaDEID, task.op_code, OP_TASK_STATE.Pushed )
        if ( nRet ~= 0 ) then 
            lua.Stop( strLuaDEID, strRetInfo ) 
            return
        end        
 
        local task_action = m3.AllocObject(strLuaDEID,"Task_Action")
        task_action.task_code = task_code
        task_action.action_code = 0
        task_action.action = "任务推送"
        task_action.eq_code = "unknow"
        task_action.eq_type_name = vehicle_type
        m3.CreateDataObj( strLuaDEID, task_action ) 
 
    else
        lua.DebugEx( strLuaDEID, "调用 Grace /api/om/order 接口失败!", ret_info.msg ) 
    end
end