1
Jianw
9 天以前 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
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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
--[[
     巨星二期WMS项目中Lua调用外包第3方WebAPI接口
     更新记录:
     V1.0  HAN 20241108  -- 创建
     V2.0  HAN 20241109
           新增巨星WMS接口
           改进JW接口
--]]
 
wms_base = require( "wms_base" )
 
local jx_api = {_version = "0.1.1"}
 
--[[
    1# JW_WMS_API_subPickDown    巨沃WMS出库单分拣完成后完工回报接口
    2# JW_WMS_API_newTrans       巨沃WMS入库单上架完成后完工回报接口
    3# JW_WMS_API_subStockCheck  巨沃WMS盘点完成后完工回报接口
    4# JW_WMS_API_newOffShelfs   巨沃WMS盘点差异回报接口
    5# WMS_API_SetPLCJobStatus   巨星WMS出库完成进行状态回报处理
    6# WMS_API_SetLocation      巨星WMS接口,出入库异动,这边是两个,出库和入库都需要
    7# WMS_API_PutOn             巨星WMS接口入库任务完成后,把容器的货位回传巨星WMS
    8# JW_DVC_State              获取设备状态
    9# JW_Cancel                 巨星任务取消
 
]]
 
--//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-- 巨沃WMS出库单分拣完成后完工回报接口
-- oo_no 出库单号, 巨沃WMS这里的波次号
function jx_api.JW_WMS_API_subPickDown(strLuaDEID, oo_no)
    local nRet, strRetInfo
    -- 检查出库单号
    if (oo_no == nil or oo_no == '') then
        return 1, "jx_api.JW_WMS_API_subPickDown 函数中 oo_no 必须有值!"
    end
 
    -- 查询出库单类型(S_BS_TYPE字段)
    local strCondition = "S_NO = '"..oo_no.."'"
    local outbound_order_objs
    nRet, outbound_order_objs = m3.QueryDataObject(strLuaDEID, "Outbound_Order", strCondition, "")
    if (nRet ~= 0 or #outbound_order_objs == 0) then
        lua.Error(strLuaDEID, debug.getinfo(1), "查询出库单信息失败! " .. (strRetInfo or "无数据"))
    end
    -- 获取 S_BS_TYPE 字段值
    local obj_attrs = m3.KeyValueAttrsToObjAttr(outbound_order_objs[1].attrs)
    local bs_type = obj_attrs.S_BS_TYPE
    lua.Debug(strLuaDEID, debug.getinfo(1), "bs_type", bs_type)
    -- 获取出库单明细信息
    local detailCondition = "S_OO_NO = '"..oo_no.."'"
    local detailOrder = "N_ROW_NO"
    local oo_detail_objs
    nRet, oo_detail_objs = m3.QueryDataObject(strLuaDEID, "Outbound_Detail", detailCondition, detailOrder)
    if (nRet ~= 0) then 
        lua.Error(strLuaDEID, debug.getinfo(1), "获取【Outbound_Detail】信息失败! " .. oo_detail_objs) 
    end
 
    local obj_attrs_detail
    local item_list = {}
 
    -- 遍历出库单明细
    for n = 1, #oo_detail_objs do
        obj_attrs_detail = m3.KeyValueAttrsToObjAttr(oo_detail_objs[n].attrs)
        local item = {
            inco = obj_attrs_detail.S_ITEM_CODE,
            container_id = obj_attrs_detail.S_PICK_BOX_CODE,            
            qty = lua.StrToNumber(obj_attrs_detail.F_ACC_O_QTY)
        }
        table.insert(item_list, item)
    end
    lua.Debug(strLuaDEID, debug.getinfo(1), "item_list", item_list)
 
    -- 判断出库单类型
    local jw_wms = wms_base.Get_sConst(strLuaDEID, "巨沃WMS服务地址")
    local strurl
    local body = {}
    if bs_type == "分拣单" then
        -- 分拣单
        strurl = jw_wms..'?service=subPickDown&appkey=gwall&secret=null&format=JSON'
        body = {
                    taskno = oo_no,  
                    items = item_list
               }
    elseif bs_type == "出库单" then
    lua.Debug(strLuaDEID, debug.getinfo(1), "出库单","1" )
        -- 出库单
        strurl = jw_wms..'?service=newOffShelfs&appkey=gwall&secret=null&format=JSON'
        body = {
                    orderId = oo_no, 
                    items = item_list
               }
    else
        return 1, "无效的出库单类型"
    end
 
    -- 调用巨沃接口
    lua.Debug(strLuaDEID, debug.getinfo(1), "调巨沃接口-->", strurl)                     
    lua.Debug(strLuaDEID, debug.getinfo(1), "body", body)
 
    nRet, strRetInfo = mobox.sendHttpRequest(strurl, "", "content="..lua.table2str(body))
    if (nRet ~= 0 or strRetInfo == '') then 
        lua.Error(strLuaDEID, debug.getinfo(1), "调用巨沃WMS接口失败! "..strRetInfo) 
    end  
    lua.Debug( strLuaDEID, debug.getinfo(1), "调巨沃接口结果-->", strRetInfo ) 
 
--王志坤--返回错误信息 
    if (strRetInfo ~= '') then
        local ret_info = json.decode(strRetInfo)
        if (ret_info.isSuccess == false) then
            return 1,"返回错误-->" ..ret_info.body
        end
    end
    return 0
end
 
 
--//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-- 巨沃WMS入库单上架完成后完工回报接口
-- io_no 入库单号, 
function jx_api.JW_WMS_API_newTrans( strLuaDEID, io_no )
    local nRet, strRetInfo, n
    if ( io_no == nil or io_no == '' ) then return 1, "jx_api.JW_WMS_API_newTrans 函数中 io_no 必须有值!" end
 
    local strCondition = "S_IO_NO = '"..io_no.."'"
    local strOrder = "N_ROW_NO"
    local io_detail_objs
    nRet, io_detail_objs = m3.QueryDataObject( strLuaDEID, "Inbound_Detail", strCondition, strOrder )
    if (nRet ~= 0) then lua.Error( strLuaDEID, debug.getinfo(1), "获取【Inbound_Detail】信息失败! " .. io_detail_objs ) end
 
    local obj_attrs
    local item_list = {}
 
    for n = 1, #io_detail_objs do
        obj_attrs = m3.KeyValueAttrsToObjAttr(io_detail_objs[n].attrs)
        local item = {
            inco = obj_attrs.S_ITEM_CODE,
            qty = lua.StrToNumber( obj_attrs.F_ACC_I_QTY )
        }
        table.insert( item_list, item )
    end
    local jw_wms = wms_base.Get_sConst( strLuaDEID, "巨沃WMS服务地址")
 
    local strurl =  jw_wms..'?service=newTrans&appkey=gwall&secret=null&format=JSON'
    local body = {
                    orderId = io_no,
                    type = "Shelf",
                    items = item_list
                }
    lua.Debug( strLuaDEID, debug.getinfo(1), "调巨沃接口-->", strurl )                
    lua.Debug( strLuaDEID, debug.getinfo(1), "body", body )
 
    nRet, strRetInfo = mobox.sendHttpRequest( strurl, "","content="..  lua.table2str(body) )
    if ( nRet ~= 0 or strRetInfo == '' ) then 
        lua.Error( strLuaDEID, debug.getinfo(1), "调用巨沃WMS #subPickDown 接口失败! "..strRetInfo ) 
    end  
    lua.Debug( strLuaDEID, debug.getinfo(1), "调巨沃接口结果-->", strRetInfo )     
 
--返回错误信息 
    if (strRetInfo ~= '') then
        local ret_info = json.decode(strRetInfo)
        if (ret_info.isSuccess == false) then
            return 1,"返回错误-->" ..ret_info.body
        end
    end
 
    return 0
end
 
--//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-- 巨沃WMS盘点完成后完工回报接口
-- orderno 盘点计划单号, 
function jx_api.JW_WMS_API_subStockCheck( strLuaDEID, orderno )
    local nRet, strRetInfo, n
    if ( orderno == nil or orderno == '' ) then return 1, "jx_api.JW_WMS_API_subStockCheck 函数中 orderno 必须有值!" end
 
    local strCondition = "S_CP_NO = '"..orderno.."'"
    local count_plan
    nRet, count_plan = m3.QueryDataObject( strLuaDEID, "CP_Good_List", strCondition )--查询计划盘点货品
    if (nRet ~= 0) then lua.Error( strLuaDEID, debug.getinfo(1), "获取【Inbound_Detail】信息失败! " .. count_plan ) end
 
    local obj_attrs
    local item_list = {}
 
    for n = 1, #count_plan do
        obj_attrs = m3.KeyValueAttrsToObjAttr(count_plan[n].attrs)
        local item = {
            inco = obj_attrs.S_ITEM_CODE,
            qty = lua.StrToNumber( obj_attrs.F_ACT_QTY )
        }
        table.insert( item_list, item )
    end
    local jw_wms = wms_base.Get_sConst( strLuaDEID, "巨沃WMS服务地址")
 
    local strurl = jw_wms..'?service=subStockCheck&appkey=gwall&secret=null&format=JSON'
    local body = {
                    orderno = orderno,--盘点计划单号
                    items = item_list
                }
    lua.Debug( strLuaDEID, debug.getinfo(1), "调巨沃接口-->", strurl )                
    lua.Debug( strLuaDEID, debug.getinfo(1), "body", body )
 
    nRet, strRetInfo = mobox.sendHttpRequest( strurl, "","content="..  lua.table2str(body) )
    if ( nRet ~= 0 or strRetInfo == '' ) then 
        lua.Error( strLuaDEID, debug.getinfo(1), "调用巨沃WMS #subPickDown 接口失败! "..strRetInfo ) 
    end  
    lua.Debug( strLuaDEID, debug.getinfo(1), "调巨沃接口结果-->", strRetInfo )     
 
--返回错误信息 
    if (strRetInfo ~= '') then
        local ret_info = json.decode(strRetInfo)
        if (ret_info.isSuccess == false) then
            return 1,"返回错误-->" ..ret_info.body
        end
    end
 
    return 0
end
 
--//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-- 巨沃WMS盘点差异回报接口
-- count_no 盘点差异单号, 
function jx_api.JW_WMS_API_newOffShelfs( strLuaDEID, count_no )
    local nRet, strRetInfo, n
    if ( count_no == nil or count_no == '' ) then return 1, "jx_api.JW_WMS_API_newOffShelfs 函数中 count_no 必须有值!" end
 
    local strCondition = "S_COUNT_NO = '"..count_no.."'"
    --local strOrder = "N_ROW_NO"--是否需要修改
    local count_diff
    nRet, count_diff = m3.QueryDataObject( strLuaDEID, "Count_Diff", strCondition, strOrder )--盘点差异表,是否需要判断差异是否移库的状态Y/N的状态值
    if (nRet ~= 0) then 
        lua.Error( strLuaDEID, debug.getinfo(1), "获取【Inbound_Detail】信息失败! " .. count_diff ) 
    end
 
 
    local obj_attrs
    local item_list = {}
    --取差异值
    for n = 1, #count_diff do
        obj_attrs = m3.KeyValueAttrsToObjAttr(count_diff[n].attrs)
        local item = {
            inco = obj_attrs.S_ITEM_CODE,
            qty = lua.StrToNumber( obj_attrs.F_QTY ) - lua.StrToNumber( obj_attrs.F_ACTUAL_QTY )
        }
        table.insert( item_list, item )
    end
    lua.Debug( strLuaDEID, debug.getinfo(1), "item_list", item_list )
    local jw_wms = wms_base.Get_sConst( strLuaDEID, "巨沃WMS服务地址")
 
    local strurl =  jw_wms..'?service=newOffShelfs&appkey=gwall&secret=null&format=JSON'
    local body = {
                    
                    items = item_list
                }
    lua.Debug( strLuaDEID, debug.getinfo(1), "调巨沃接口-->", strurl )                
    lua.Debug( strLuaDEID, debug.getinfo(1), "body", body )
 
    nRet, strRetInfo = mobox.sendHttpRequest( strurl, "","content="..  lua.table2str(body) )
    if ( nRet ~= 0 or strRetInfo == '' ) then 
        lua.Error( strLuaDEID, debug.getinfo(1), "调用巨沃WMS #subPickDown 接口失败! "..strRetInfo ) 
    end  
    lua.Debug( strLuaDEID, debug.getinfo(1), "调巨沃接口结果-->", strRetInfo )     
 
--返回错误信息 
    if (strRetInfo ~= '') then
        local ret_info = json.decode(strRetInfo)
        if (ret_info.isSuccess == false) then
            return 1,"返回错误-->" ..ret_info.body
        end
    end
 
    return 0
end
 
--//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-- 巨星WMS接口
-- 完工回报
-- 任务状态:Status Y:完工回报; 9:已下发已接,强制完成传Y
function jx_api.WMS_API_SetPLCJobStatus( strLuaDEID, jx_task, Status )
    local nRet, strRetInfo, n
    if ( jx_task == nil ) then return 1, "jx_api.WMS_API_SetPLCJobStatus 函数中 jx_task 必须有值!" end
 
    local jx_wms = wms_base.Get_sConst( strLuaDEID, "巨星WMS服务地址")
    local strurl =  jx_wms..'/api/SetPLCJobStatus'
    local body = {
                    clientKey1 = "GREATSTAR",
                    clientKey2 = "HNWSRFID",
                    jobNo = jx_task.sour_no,
                    palletNo = jx_task.cntr_code,
                    destLocationCode = jx_task.end_loc_code,
                    whCode = jx_task.start_wh_code,
                    jobStatus = Status,
                    oper ="WMS"
                    --oper = jx_task.operator_name
                }
    lua.Debug( strLuaDEID, debug.getinfo(1), "调巨星接口-->", strurl )                     
    lua.Debug( strLuaDEID, debug.getinfo(1), "body", body )
 
 
    nRet, strRetInfo = mobox.sendHttpRequest( strurl, "", lua.table2str(body) )
    if ( nRet ~= 0 or strRetInfo == '' ) then 
        lua.Error( strLuaDEID, debug.getinfo(1), "调用巨星WMS #subPickDown 接口失败! "..strRetInfo ) 
    end  
    lua.Debug( strLuaDEID, debug.getinfo(1), "调巨星接口结果-->", strRetInfo )     
 
    if (strRetInfo ~= '') then
        local ret_info = json.decode(strRetInfo)
        if (ret_info.isSuccess == false) then
            return 1,"返回错误-->" ..ret_info.body
        end
    end
    return 0
end
 
--//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
--  巨星WMS接口,具体位置在出入库异动
--  model 出/入库
function jx_api.WMS_API_SetLocation(strLuaDEID, jx_task, model)
    local nRet, strRetInfo, n
    if ( jx_task == nil ) then return 1, "jx_api.WMS_API_SetLocation 函数中必须有值!" end
 
    local jx_wms = wms_base.Get_sConst( strLuaDEID, "巨星WMS服务地址")
    local strurl =  jx_wms..'/api/SetLocation'
    local body = {
                clientKey1 = "GREATSTAR",
                clientKey2 = "HNWSRFID",
                jobNo = jx_task.sour_no,
                palletNo = jx_task.cntr_code,
                destLocationCode = jx_task.end_loc_code,
                locationCode = jx_task.start_loc_code, --托盘起点货位
                model = model,
                oper = "WMS"
                --oper = jx_task.operator_name
                }
    lua.Debug( strLuaDEID, debug.getinfo(1), "调巨星接口-->", strurl )                     
    lua.Debug( strLuaDEID, debug.getinfo(1), "body", body )
 
 
    nRet, strRetInfo = mobox.sendHttpRequest( strurl, "", lua.table2str(body) )
    if ( nRet ~= 0 or strRetInfo == '' ) then 
        lua.Error( strLuaDEID, debug.getinfo(1), "调用巨星WMS #SetLocation 接口失败! "..strRetInfo ) 
    end  
    lua.Debug( strLuaDEID, debug.getinfo(1), "调巨星接口结果-->", strRetInfo )     
 
 
    if (strRetInfo ~= '') then
        local ret_info = json.decode(strRetInfo)
        if (ret_info.isSuccess == false) then
            return 1,"返回错误-->" ..ret_info.body
        end
    end
 
    return 0
end
 
--//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-- 巨星WMS接口
-- 入库任务完成后,把容器的货位回传巨星WMS
function jx_api.WMS_API_PutOn( strLuaDEID, jx_task )
    local nRet, strRetInfo, n
    if ( jx_task == nil ) then return 1, "jx_api.WMS_API_PutOn 函数中 jx_task 必须有值!" end
 
    local jx_wms = wms_base.Get_sConst( strLuaDEID, "巨星WMS服务地址")
    local strurl =  jx_wms..'/api/PutOn'
    local body = {
                    clientKey1 = "GREATSTAR",
                    clientKey2 = "HNWSRFID",
                    flag = true,
                    transType = 0,
                    sourcePallet = jx_task.cntr_code,
                    destLocationCode = jx_task.end_loc_code,
                    oper ="WMS"
                    --oper = jx_task.operator_name
                }
    lua.Debug( strLuaDEID, debug.getinfo(1), "调巨星接口-->", strurl )                     
    lua.Debug( strLuaDEID, debug.getinfo(1), "body", body )
 
 
    nRet, strRetInfo = mobox.sendHttpRequest( strurl, "", lua.table2str(body) )
    if ( nRet ~= 0 or strRetInfo == '' ) then 
        lua.Error( strLuaDEID, debug.getinfo(1), "调用巨星WMS #subPickDown 接口失败! "..strRetInfo ) 
    end  
    lua.Debug( strLuaDEID, debug.getinfo(1), "调巨星接口结果-->", strRetInfo )     
 
    if (strRetInfo ~= '') then
        local ret_info = json.decode(strRetInfo)
        if (ret_info.isSuccess == false) then
            return 1,"返回错误-->" ..ret_info.body
        end
    end
 
    return 0
end
 
--//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
--JW_DVC_State获取设备状态
--reqDvc设备号, readingBit -- 读码位
function jx_api.JW_DVC_State( strLuaDEID, reqDvc, readingBit )
    local dev_state = {
        {DVC_NO = "ZD01", IS_USE = 1},
        {DVC_NO = "ZD02", IS_USE = 1},
        {DVC_NO = "ZD03", IS_USE = 0},
        {DVC_NO = "ZD04", IS_USE = 1}
    }
    return 0, dev_state
end
--[[    
    local nRet, strRetInfo
    local now = os.date("%Y%m%d%H%M%S")  
    local randomNum = math.random(1, 99999)  
    local requestPk = "PK"..now..randomNum
    local wcs_url = wms_base.Get_sConst( strLuaDEID, "WCS服务地址")
    local strurl =  wcs_url..'/wcs-admin/api/dvc-state'
 
    local body = {
                    requestPk = requestPk,
                    reqDvc = reqDvc,
                    readingBit = readingBit
                }
    lua.Debug( strLuaDEID, debug.getinfo(1), "调WCS接口-->", strurl )                     
    lua.Debug( strLuaDEID, debug.getinfo(1), "body", body )
 
 
    nRet, strRetInfo = mobox.sendHttpRequest( strurl, "", lua.table2str(body) )
    if ( nRet ~= 0 or strRetInfo == '' ) then 
        lua.Error( strLuaDEID, debug.getinfo(1), "调用WCS /wcs-admin/api/receive 接口失败! "..strRetInfo ) 
    end  
 
    lua.Debug( strLuaDEID, debug.getinfo(1), "strRetInfo", strRetInfo )
    
    local ret_info = json.decode(strRetInfo)
    return 0, ret_info.data
 
end
]]
 
--//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
--JW_Cancel取消任务
--注意requestPk并不是时间戳而是任务号,任务号的唯一标识
function jx_api.JW_Cancel(strLuaDEID,cntr_code,task_code)
    return 0, ""
end
--[[
    local nRet, strRetInfo,n
    -- local now = os.date("%Y%m%d%H%M%S")  
    -- local randomNum = math.random(1, 99999)  
    -- local requestPk = "PK"..now..randomNum
    local wcs_url = wms_base.Get_sConst( strLuaDEID, "WCS服务地址")
 
    local strurl =  wcs_url..'/wcs-admin/api/cancel'
    local body = {
                    requestPk = task_code,
                    contNo = cntr_code,
                    clientCode = wms,
                    reqTime = 2022-11-11
                }
    lua.Debug( strLuaDEID, debug.getinfo(1), "调WCS接口-->", strurl )                     
    lua.Debug( strLuaDEID, debug.getinfo(1), "body", body )
 
 
    nRet, strRetInfo = mobox.sendHttpRequest( strurl, "",lua.table2str(body) )
    if ( nRet ~= 0 or strRetInfo == '' ) then 
        lua.Error( strLuaDEID, debug.getinfo(1), "调用WCS /wcs-admin/api/receive 接口失败! "..strRetInfo ) 
    end  
 
    lua.Debug( strLuaDEID, debug.getinfo(1), "strRetInfo", strRetInfo )
    
    local ret_info = json.decode(strRetInfo)
    return 0, ret_info.msg
end
]]
 
return jx_api