--[[ 巨星二期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