New file |
| | |
| | | --- |
| | | --- Created by wsz. |
| | | --- DateTime: 2025/5/13 上午9:02 |
| | | --- |
| | | --[[ |
| | | 编码:GK-API-03 |
| | | 名称: 商品批次同步接口 |
| | | 作者: |
| | | 入口函数:Batch_Sync |
| | | 功能说明:创建、覆盖GK_BATCH实体 同时更新CG_Detail相关自定义字段 |
| | | 变更历史: |
| | | |
| | | v0.0.2 |
| | | 格式验证不通过的返回报文 |
| | | 系统异常需要error抛出 |
| | | resp |
| | | |
| | | v0.0.3 |
| | | CG_Detail弃用,变更为 库存表 INV_Detail |
| | | |
| | | --]] |
| | | |
| | | local json = require("json") |
| | | local mobox = require("OILua_JavelinExt") |
| | | local m3 = require("oi_base_mobox") |
| | | |
| | | local xml = require("oi_base_xml") |
| | | |
| | | --- 实体标识-商品批次同步 TN_GK_BATCH |
| | | local CLSID_GKbatch = "GK_BATCH" |
| | | --- 实体标识-货位容器货品明细 TN_CG_Detail | 变更为 库存表 INV_Detail |
| | | local CLSID_INVdetail = "INV_Detail" |
| | | |
| | | -- local apiDesc = "商品批次同步接口" |
| | | |
| | | |
| | | --根标签 |
| | | local RootTag = "response" |
| | | |
| | | |
| | | |
| | | --[[ |
| | | desc:处理xml->table 部分空节点被转化为{} |
| | | parameter: |
| | | value-字符串或空table{} |
| | | return: nil/字符串 |
| | | -- 备 集中处理 |
| | | --]] |
| | | local function getStrHandle(value) |
| | | --if (type(value) == "table" and #value == 0) then |
| | | -- return nil |
| | | --else |
| | | -- return lua.Get_StrAttrValue(value) |
| | | --end |
| | | return lua.Get_StrAttrValue(value) |
| | | end |
| | | |
| | | |
| | | -- mergeTablesDeep辅助-递归 |
| | | local function deepCopy(original) |
| | | if type(original) ~= 'table' then |
| | | return original |
| | | end |
| | | local copy = {} |
| | | for key, value in pairs(original) do |
| | | copy[key] = deepCopy(value) |
| | | end |
| | | return copy |
| | | end |
| | | |
| | | -- 将tableb合并到tablea |
| | | local function mergeTablesDeep(tablea, tableb) |
| | | local bCopy = deepCopy(tableb) |
| | | for key, value in pairs(bCopy) do |
| | | tablea[key] = value |
| | | end |
| | | return tablea |
| | | end |
| | | |
| | | |
| | | --[[ |
| | | -- 事务回滚-返回信息后终止执行 |
| | | ]] |
| | | local function result_transaction_back(strLuaDEID, msg) |
| | | |
| | | -- 回滚当次处理 |
| | | lua.Stop(strLuaDEID, msg) |
| | | |
| | | local result = {} |
| | | result.flag = "failure" -- success|failure |
| | | result.code = 5 |
| | | result.message = msg |
| | | |
| | | do |
| | | local nRet = mobox.returnValue(strLuaDEID, 1, xml.json_to_xml(result, RootTag), result.code) |
| | | if nRet ~= 0 then |
| | | lua.Error(strLuaDEID, debug.getinfo(1), 'result_transaction_back-执行mobox.returnValue失败 ' .. nRet) |
| | | end |
| | | end |
| | | |
| | | lua.Error(strLuaDEID, debug.getinfo(1), msg) |
| | | end |
| | | |
| | | |
| | | --[[ |
| | | -- 执行成功 |
| | | ]] |
| | | local function result_success(strLuaDEID) |
| | | |
| | | local result = {} |
| | | result.flag = "success" -- success|failure |
| | | result.code = 0 |
| | | result.message = "" |
| | | do |
| | | local nRet = mobox.returnValue(strLuaDEID, 1, xml.json_to_xml(result, RootTag), result.code) |
| | | if nRet ~= 0 then |
| | | lua.Error(strLuaDEID, debug.getinfo(1), 'result_success-执行mobox.returnValue失败 ' .. nRet) |
| | | end |
| | | end |
| | | end |
| | | |
| | | |
| | | |
| | | |
| | | --[[ |
| | | 组装临时对象 |
| | | ]] |
| | | local function buildTemp(dataSet) |
| | | local temp = {} -- 放置待创建数据 |
| | | |
| | | -- 物料编码/商品代码 |
| | | temp.storer_no = getStrHandle(dataSet.storerId)-- getStrHandle(dataSet.skuId) |
| | | -- 货主编码 |
| | | temp.item_code = getStrHandle(dataSet.skuId) --getStrHandle(dataSet.storerId) |
| | | -- 物权 |
| | | temp.owner_no = getStrHandle(dataSet.ownerId) |
| | | -- 批次编码 |
| | | temp.wms_bn = getStrHandle(dataSet.batchNo) |
| | | -- 批号 |
| | | temp.batch_no = getStrHandle(dataSet.produceCode) |
| | | -- 生产日期 |
| | | temp.product_date = getStrHandle(dataSet.productDate) |
| | | -- 有效日期 |
| | | temp.expiry_date = getStrHandle(dataSet.expiryDate) |
| | | -- 注册证号 |
| | | temp.register_no = getStrHandle(dataSet.registerNo) |
| | | -- 生产企业 |
| | | temp.company_name = getStrHandle(dataSet.companyName) |
| | | -- 证件生产厂家 |
| | | temp.cert_company_name = getStrHandle(dataSet.certCompanyName) |
| | | -- 委托生产厂家 |
| | | temp.consign_company_name = getStrHandle(dataSet.consignCompanyWTName) |
| | | -- 灭菌日期 |
| | | temp.sterilization_date = getStrHandle(dataSet.sterilizationData) |
| | | -- 备注 |
| | | temp.note = getStrHandle(dataSet.memo) |
| | | -- 备注 |
| | | temp.ex1 = getStrHandle(dataSet.ex1) |
| | | -- 备注 |
| | | temp.ex2 = getStrHandle(dataSet.ex2) |
| | | -- 备注 |
| | | temp.ex3 = getStrHandle(dataSet.ex3) |
| | | |
| | | return temp |
| | | end |
| | | |
| | | |
| | | --[[ |
| | | |
| | | strClsID: 数据类id |
| | | dataObj:待创建的数据对象 |
| | | |
| | | --]] |
| | | local function create_obj(strLuaDEID, strClsID, dataObj) |
| | | |
| | | -- 基础验证 |
| | | if (nil == strClsID or strClsID == '') then |
| | | result_transaction_back(strLuaDEID, "[商品批次同步接口]-创建对象失败,strClsID不可为空") |
| | | end |
| | | if type(dataObj) ~= 'table' then |
| | | result_transaction_back(strLuaDEID, "[商品批次同步接口]-创建对象失败,dataObj必须为table类型") |
| | | end |
| | | |
| | | -- |
| | | local creatobj = m3.AllocObject(strLuaDEID, strClsID) |
| | | |
| | | mergeTablesDeep(creatobj, dataObj) |
| | | local nRet, resultData = m3.CreateDataObj(strLuaDEID, creatobj) |
| | | if (nRet ~= 0) then |
| | | result_transaction_back(strLuaDEID, string.format("创建对象[%s]失败,msg:%s", strClsID, resultData)) |
| | | end |
| | | end |
| | | |
| | | |
| | | --[[ |
| | | desc:更新目标数据 |
| | | ]] |
| | | local function updateBussData(strLuaDEID, dataSet, id) |
| | | local temp = buildTemp(dataSet) |
| | | |
| | | local attrValueObj |
| | | do |
| | | -- 取得 可用来更新数据库的 attr-value 的 table 类型 [attrValueObj] |
| | | -- luaJsonToObjAttrs 执行后返回的str_data_attrset 是字符串,且attr 是数据库字符串 需反序列化处理为table |
| | | local nRet, str_data_attrset = mobox.luaJsonToObjAttrs(CLSID_GKbatch, json.encode(temp)) |
| | | |
| | | if nRet ~= 0 then |
| | | result_transaction_back(strLuaDEID, 'upd-goodsbatsh item 时luaJsonToObjAttrs执行失败,详细:' .. str_data_attrset) |
| | | end |
| | | -- 反序列化为目标格式 |
| | | attrValueObj = json.decode(str_data_attrset) |
| | | end |
| | | -- 当程序可以运行以下时 - 认为 if nRet == 0 --- 执行upd逻辑 |
| | | lua.Debug(strLuaDEID, debug.getinfo(1), "attrValueObj", attrValueObj) |
| | | -- 组装批量更新的数据格式 |
| | | local updateObj = {} |
| | | |
| | | local updateObj_item = {} |
| | | updateObj_item.id = id |
| | | updateObj_item.attrs = attrValueObj |
| | | table.insert(updateObj, updateObj_item) |
| | | |
| | | --local updateObj = { |
| | | -- { |
| | | -- id = id, |
| | | -- attrs = attrValueObj |
| | | -- } |
| | | --} |
| | | |
| | | local updateStrDataJson = lua.table2str(updateObj) |
| | | lua.Debug(strLuaDEID, debug.getinfo(1), "goodsbatch-update准备覆盖已有数据", updateStrDataJson) |
| | | local nRet, strRetInfo = mobox.updateDataObj(strLuaDEID, CLSID_GKbatch, updateStrDataJson) |
| | | if (nRet ~= 0) then |
| | | result_transaction_back(strLuaDEID, string.format("goodbatch更新操作失败。code:%s,msg:%s", nRet, strRetInfo)) |
| | | end |
| | | end |
| | | |
| | | |
| | | --[[ |
| | | desc:创建目标数据 |
| | | ]] |
| | | local function creatBussData(strLuaDEID, dataSet) |
| | | local temp = buildTemp(dataSet) |
| | | |
| | | lua.Debug(strLuaDEID, debug.getinfo(1), "goodsbatch待新增数据-temp", temp) |
| | | |
| | | create_obj(strLuaDEID, CLSID_GKbatch, temp) |
| | | end |
| | | |
| | | |
| | | --[[ |
| | | 单条 |
| | | ]] |
| | | local function bussHandle(strLuaDEID, dataSet) |
| | | |
| | | -- 对于 非数组表 返回0 认定仅单条??? |
| | | lua.Debug(strLuaDEID, debug.getinfo(1), "dataSet", dataSet) |
| | | |
| | | -- 组装sql过滤条件 |
| | | local strCondition |
| | | do |
| | | local filters = {} |
| | | table.insert(filters, string.format([[ %s = '%s' ]], "S_STORER", getStrHandle(dataSet.storerId)))--getStrHandle(dataSet.skuId))) |
| | | table.insert(filters, string.format([[ %s = '%s' ]], "S_ITEM_CODE", getStrHandle(dataSet.skuId)))--getStrHandle(dataSet.storerId))) |
| | | table.insert(filters, string.format([[ %s = '%s' ]], "S_OWNER", getStrHandle(dataSet.ownerId))) |
| | | table.insert(filters, string.format([[ %s = '%s' ]], "S_WMS_BN", getStrHandle(dataSet.batchNo))) |
| | | strCondition = table.concat(filters, " and ") |
| | | lua.Debug(strLuaDEID, debug.getinfo(1), "filters-组装的goodsbatch的where条件", strCondition) |
| | | end |
| | | |
| | | local nRet, id, strRetInfo = mobox.getDataObjAttrByKeyAttr(strLuaDEID, CLSID_GKbatch, strCondition) |
| | | lua.Debug(strLuaDEID, debug.getinfo(1), "getDataObjAttrByKeyAttr", strRetInfo) |
| | | if nRet == 0 then |
| | | -- key已存在,更新原数据 |
| | | lua.Debug(strLuaDEID, debug.getinfo(1), "add", "数据更新:" .. strRetInfo) |
| | | updateBussData(strLuaDEID, dataSet, id) |
| | | elseif nRet == 1 then |
| | | -- key不存在,新增 |
| | | lua.Debug(strLuaDEID, debug.getinfo(1), "upd", "数据新增") |
| | | creatBussData(strLuaDEID, dataSet) |
| | | else |
| | | result_transaction_back(strLuaDEID, string.format("查询目标数据失败,code:%s,msg:%s", nRet, strRetInfo)) |
| | | end |
| | | end |
| | | |
| | | --[[ |
| | | 组装数据key |
| | | skuId+storerId+ownerId+batchNo唯一(必填) |
| | | ]] |
| | | local function getId(dataSet) |
| | | return getStrHandle(dataSet.skuId) |
| | | .. getStrHandle(dataSet.storerId) |
| | | .. getStrHandle(dataSet.ownerId) |
| | | .. getStrHandle(dataSet.batchNo) |
| | | end |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | --[[ |
| | | 同时更新 CGDetail 字段 |
| | | 策略:查找 skuId+storerId+ownerId+batchNo 数据,然后的 |
| | | ]] |
| | | local function updateCG_Detail(strLuaDEID, dataSet) |
| | | |
| | | lua.Debug(strLuaDEID, debug.getinfo(1), "开始更新updateCG_Detail", '') |
| | | -- 1. 组装查询条件 type:str |
| | | local strCondition |
| | | do |
| | | local filters = {} |
| | | table.insert(filters, string.format([[ %s = '%s' ]], "S_STORER", getStrHandle(dataSet.storerId))) |
| | | table.insert(filters, string.format([[ %s = '%s' ]], "S_OWNER", getStrHandle(dataSet.ownerId))) |
| | | table.insert(filters, string.format([[ %s = '%s' ]], "S_ITEM_CODE", getStrHandle(dataSet.skuId))) |
| | | table.insert(filters, string.format([[ %s = '%s' ]], "S_WMS_BN", getStrHandle(dataSet.batchNo))) |
| | | strCondition = table.concat(filters, " and ") |
| | | lua.Debug(strLuaDEID, debug.getinfo(1), "filters-组装的cg-detail的where条件", strCondition) |
| | | end |
| | | |
| | | -- 2. 组装待更新字段 type:str |
| | | local strUpdateSql |
| | | do |
| | | local updater = {} |
| | | table.insert(updater, string.format([[ %s = '%s' ]], "S_BATCH_NO", getStrHandle(dataSet.produceCode))) -- 批号 | 批号 |
| | | table.insert(updater, string.format([[ %s = '%s' ]], "D_PRD_DATE", getStrHandle(dataSet.productDate))) -- 生产日期 | 生产日期 |
| | | table.insert(updater, string.format([[ %s = '%s' ]], "D_EXP_DATE", getStrHandle(dataSet.expiryDate))) -- 有效日期 | 有效日期 |
| | | table.insert(updater, string.format([[ %s = '%s' ]], "S_UDF01", getStrHandle(dataSet.registerNo))) -- 注册证号 | 自定义字段1 |
| | | table.insert(updater, string.format([[ %s = '%s' ]], "S_UDF02", getStrHandle(dataSet.companyName))) -- 生产企业 | 自定义字段2 |
| | | table.insert(updater, string.format([[ %s = '%s' ]], "S_UDF03", getStrHandle(dataSet.certCompanyName))) -- 证件生产厂家 | 自定义字段3 |
| | | table.insert(updater, string.format([[ %s = '%s' ]], "S_UDF04", getStrHandle(dataSet.consignCompanyWTName))) -- 委托生产厂家 | 自定义字段4 |
| | | table.insert(updater, string.format([[ %s = '%s' ]], "S_UDF05", getStrHandle(dataSet.sterilizationDate))) -- 灭菌日期 | 自定义字段5 |
| | | table.insert(updater, string.format([[ %s = '%s' ]], "S_UDF06", getStrHandle(dataSet.ex1))) -- 扩展字段1 | 自定义字段6 |
| | | table.insert(updater, string.format([[ %s = '%s' ]], "S_UDF07", getStrHandle(dataSet.ex2))) -- 扩展字段2 | 自定义字段7 |
| | | table.insert(updater, string.format([[ %s = '%s' ]], "S_UDF08", getStrHandle(dataSet.ex3))) -- 扩展字段3 | 自定义字段8 |
| | | strUpdateSql = table.concat(updater, " , ") |
| | | lua.Debug(strLuaDEID, debug.getinfo(1), "filters-组装的cg-detail的set字段", strUpdateSql) |
| | | end |
| | | -- 3. 更新执行 |
| | | do |
| | | local nRet, strRetInfo = mobox.updateDataAttrByCondition(strLuaDEID, CLSID_INVdetail, strCondition, strUpdateSql) |
| | | if (nRet ~= 0) then |
| | | result_transaction_back(strLuaDEID, CLSID_INVdetail .. "更新信息失败!" .. strRetInfo) |
| | | end |
| | | end |
| | | end |
| | | |
| | | function Batch_Sync(strLuaDEID) |
| | | |
| | | -- 1.1 getxml |
| | | local soap_xml |
| | | do |
| | | local nRet, data = mobox.getCurEditDataPacket(strLuaDEID) |
| | | if (nRet ~= 0) then |
| | | result_transaction_back(strLuaDEID, "无法获取数据包 datajson !" .. data) |
| | | end |
| | | soap_xml = data |
| | | lua.Debug(strLuaDEID, debug.getinfo(1), "GK-API-03xml报文", soap_xml) |
| | | end |
| | | |
| | | -- 1.2 xml->luaobj |
| | | local parsed_data |
| | | do |
| | | local nRet, data = xml.parse(soap_xml) |
| | | if (nRet ~= 0) then |
| | | result_transaction_back(strLuaDEID, "接口输入的XML格式非法!") |
| | | end |
| | | parsed_data = data |
| | | end |
| | | |
| | | |
| | | -- 1.3 取得商品批次表item的tableObj |
| | | local dataSet = parsed_data["Envelope"]["Body"] |
| | | ["InBatchGoodsReq"] |
| | | ["BatchGoods_Input"] |
| | | ["InputParameters"] |
| | | ["BATCHGOODS_TB"] |
| | | ["BATCHGOODS_TB_ITEM"] |
| | | |
| | | if nil == dataSet then |
| | | -- wms_base.Warning( strLuaDEID, 1, 601, err_msg, "从GK-WMS系统同步SKU信息" ) |
| | | --wms_base.Warning(strLuaDEID, 2, 201, "[商品批次同步接口]-未解析到soap商品批次节点!", json.encode(dataSet), "", "[商品批次同步接口]-dataSet") |
| | | result_transaction_back(strLuaDEID, "[商品批次同步接口]-未解析到soap商品批次节点!") |
| | | elseif #dataSet == 0 then |
| | | -- 仅单条数据 |
| | | lua.Debug(strLuaDEID, debug.getinfo(1), "单条", "") |
| | | bussHandle(strLuaDEID, dataSet) |
| | | updateCG_Detail(strLuaDEID, dataSet) |
| | | else |
| | | for i = 1, #dataSet do |
| | | lua.Debug(strLuaDEID, debug.getinfo(1), "多条", "") |
| | | bussHandle(strLuaDEID, dataSet[i]) |
| | | updateCG_Detail(strLuaDEID, dataSet) |
| | | end |
| | | end |
| | | |
| | | result_success(strLuaDEID) |
| | | |
| | | end |
New file |
| | |
| | | --- |
| | | --- Created by wsz. |
| | | --- DateTime: 2025/5/15 下午3:31 |
| | | --- |
| | | |
| | | --[[ |
| | | 编码: GK-API-07 |
| | | 名称: 订单取消接口 |
| | | 作者: wsz |
| | | 入口函数:Order_Sync |
| | | 功能说明: 接收报文创建 Order_Hold 实体 ,对于已存在的数据无条件更新,返回报无需创建还货单 ;新增的数据设置需要创建还货单 |
| | | 变更历史:v0.0.1 |
| | | |
| | | 注意: |
| | | 1、按照此报文形式,这应是单条发送 |
| | | 2、报文解析项少了来源单号、拦截类型、:存储时 来源单号不填,拦截类型填Interface |
| | | 3、needReturnOrder 仅 根据出库单的状态会涉及到 |
| | | |
| | | 订单类型: asn 入库订单 so出库订单 inventory 盘点单 |
| | | 三者单据的主键no-与报文的taskId 对应 |
| | | 入库单和盘点单已执行不允许取消,出库单订单未完成都允许取消,允许取消才插入Order_Hold |
| | | |
| | | ----------------------------------------- |
| | | |
| | | 入库单 Inbound_Order no | b_state |
| | | 状态为N_B_STATE>=20 AND N_B_STATE<=55 不允许取消 |
| | | 取消插入Order_Hold 表 同时更新N_BSTATE=91 |
| | | |
| | | 盘点单 Count_Order count_no | b_state |
| | | 状态为N_B_STATE>=20 AND N_B_STATE<=50不允许取消, |
| | | 取消插入Order_Hold 表 同时更新N_BSTATE=91 |
| | | |
| | | 出库单 Outbound_Order no | b_state |
| | | 状态为N_B_STATE IN(50,55,90,91)不允许取消, |
| | | ,取消插入Order_Hold 表, |
| | | 如果状态N_B_STATE>=25 AND N_B_STATE<=55,出参needReturnOrder=1 |
| | | |
| | | |
| | | |
| | | --]] |
| | | |
| | | local json = require("json") |
| | | local mobox = require("OILua_JavelinExt") |
| | | local m3 = require("oi_base_mobox") |
| | | |
| | | local xml = require("oi_base_xml") |
| | | |
| | | --- 实体标识-订单取消同步 TN_ORDER_CANCEL |
| | | local CLSID_OrderHold = "Order_Hold" |
| | | |
| | | local CLSID_OrderHold_desc = "订单取消接口" |
| | | |
| | | --- 实体标识-入库单 |
| | | local CLSID_InboundOrder = "Inbound_Order" |
| | | --- 实体标识-出库单 |
| | | local CLSID_OutboundOrder = "Outbound_Order" |
| | | --- 实体标识-盘点单 |
| | | local CLSID_CountOrder = "Count_Order" |
| | | |
| | | --根标签 |
| | | local RootTag = "response" |
| | | |
| | | |
| | | ----- 出库单 -状态列表 |
| | | --local STATUS_array_OutboundOrder = {"0"} |
| | | ----- 入库单 - 状态列表 |
| | | --local STATUS_array_Inbound_Order = {"0"} |
| | | ----- 盘点单 - 状态列表 |
| | | --local STATUS_array_Count_Order = {"0"} |
| | | |
| | | -- |
| | | local luaDEID |
| | | |
| | | local ERR |
| | | |
| | | |
| | | -- 返回部分----------------------------------------- |
| | | --[[ |
| | | -- 事务回滚-返回信息后终止执行 |
| | | ]] |
| | | local function result_transaction_back(strLuaDEID, msg) |
| | | |
| | | -- 回滚当次处理 |
| | | lua.Stop(strLuaDEID, msg) |
| | | lua.Debug(strLuaDEID, debug.getinfo(1), "result_transaction_back-Stop 执行完毕", "") |
| | | |
| | | local result = {} |
| | | result.flag = "failure" -- success|failure |
| | | result.code = 5 |
| | | result.message = msg |
| | | |
| | | local xmlstr = xml.json_to_xml(result,RootTag) |
| | | |
| | | do |
| | | local nRet = mobox.returnValue(strLuaDEID, 1, xmlstr, result.code) |
| | | if nRet ~= 0 then |
| | | lua.Error(strLuaDEID, debug.getinfo(1), 'result_transaction_back-执行mobox.returnValue失败 ' .. nRet) |
| | | end |
| | | end |
| | | error(msg,0) |
| | | -- lua.Error(strLuaDEID, debug.getinfo(1), xmlstr) |
| | | end |
| | | |
| | | |
| | | --[[ |
| | | -- 执行成功 |
| | | ]] |
| | | local function result_success(strLuaDEID,needReturnOrder,msg) |
| | | |
| | | local result = {} |
| | | result.flag = "success" -- success|failure |
| | | result.code = 0 |
| | | result.message = msg |
| | | if needReturnOrder then -- nil false |
| | | result.needReturnOrder = needReturnOrder |
| | | end |
| | | |
| | | do |
| | | local nRet = mobox.returnValue(strLuaDEID, 1, xml.json_to_xml(result,RootTag), result.code) |
| | | if nRet ~= 0 then |
| | | lua.Error(strLuaDEID, debug.getinfo(1), 'result_success-执行mobox.returnValue失败 ' .. nRet) |
| | | end |
| | | end |
| | | end |
| | | |
| | | |
| | | |
| | | --[[ |
| | | -- 执行失败- 终止执行 |
| | | ]] |
| | | local function result_failure(strLuaDEID,msg) |
| | | |
| | | local result = {} |
| | | result.flag = "failure" -- success|failure |
| | | result.code = 0 |
| | | result.message = msg |
| | | do |
| | | local nRet = mobox.returnValue(strLuaDEID, 1, xml.json_to_xml(result,RootTag), result.code) |
| | | if nRet~=0 then |
| | | lua.Error(strLuaDEID, debug.getinfo(1), 'result_failure-执行mobox.returnValue失败 ' .. nRet) |
| | | end |
| | | end |
| | | end |
| | | |
| | | |
| | | ------------------------------------------- |
| | | |
| | | -- util-------------------- |
| | | |
| | | ------------------------ |
| | | -- mergeTablesDeep辅助-递归 |
| | | local function deepCopy(original) |
| | | if type(original) ~= 'table' then |
| | | return original |
| | | end |
| | | local copy = {} |
| | | for key, value in pairs(original) do |
| | | copy[key] = deepCopy(value) |
| | | end |
| | | return copy |
| | | end |
| | | |
| | | -- 将tableb合并到tablea |
| | | local function mergeTablesDeep(tablea, tableb) |
| | | local bCopy = deepCopy(tableb) |
| | | for key, value in pairs(bCopy) do |
| | | tablea[key] = value |
| | | end |
| | | return tablea |
| | | end |
| | | |
| | | |
| | | --[[ |
| | | |
| | | strClsID: 数据类id |
| | | dataObj:待创建的数据对象 |
| | | |
| | | --]] |
| | | local function create_obj(strLuaDEID, strClsID, dataObj) |
| | | |
| | | -- 基础验证 |
| | | if (nil == strClsID or strClsID == '') then |
| | | result_transaction_back(strLuaDEID, CLSID_OrderHold_desc .. "-创建对象失败,strClsID不可为空") |
| | | end |
| | | if type(dataObj) ~= 'table' then |
| | | result_transaction_back(strLuaDEID, CLSID_OrderHold_desc .. "-创建对象失败,dataObj必须为table类型") |
| | | end |
| | | |
| | | -- |
| | | local creatobj = m3.AllocObject(strLuaDEID, strClsID) |
| | | |
| | | mergeTablesDeep(creatobj, dataObj) |
| | | local nRet, resultData = m3.CreateDataObj(strLuaDEID, creatobj) |
| | | if (nRet ~= 0) then |
| | | result_transaction_back(strLuaDEID, string.format("创建对象[%s]失败,msg:%s", strClsID, resultData)) |
| | | end |
| | | end |
| | | |
| | | |
| | | --[[ |
| | | param |
| | | table:字符串数组 |
| | | value:要判断是否存在的值 |
| | | return |
| | | true:存在 |
| | | false:不存在 |
| | | ]] |
| | | local function contains(table, value) |
| | | for _, v in ipairs(table) do |
| | | if v == value then return true end |
| | | end |
| | | return false |
| | | end |
| | | |
| | | |
| | | |
| | | --[[ |
| | | 组装临时对象 |
| | | ]] |
| | | local function buildTemp(dataSet) |
| | | local temp = {} -- 放置待创建数据 |
| | | |
| | | -- 任务编号 |
| | | temp.no = lua.Get_StrAttrValue(dataSet.taskId) |
| | | -- 订单类型 |
| | | temp.no_type = lua.Get_StrAttrValue(dataSet.taskType) |
| | | -- 来源单号 |
| | | temp.bs_no = "" |
| | | -- 货主编码 |
| | | temp.storer = lua.Get_StrAttrValue(dataSet.storerId) |
| | | -- 物权 |
| | | temp.owner = lua.Get_StrAttrValue(dataSet.ownerId) |
| | | -- 拦截类型 |
| | | temp.hold_type = "Interface" |
| | | -- 状态 |
| | | temp.state = "10" |
| | | -- 取消原因 |
| | | temp.note = lua.Get_StrAttrValue(dataSet.reason) |
| | | |
| | | return temp |
| | | end |
| | | |
| | | |
| | | |
| | | --[[ |
| | | desc:更新目标数据 |
| | | ]] |
| | | local function updateBussData(strLuaDEID, dataSet, id) |
| | | local temp = buildTemp(dataSet) |
| | | |
| | | local attrValueObj |
| | | do |
| | | -- 取得 可用来更新数据库的 attr-value 的 table 类型 [attrValueObj] |
| | | -- luaJsonToObjAttrs 执行后返回的str_data_attrset 是字符串,且attr 是数据库字符串 需反序列化处理为table |
| | | local nRet, str_data_attrset = mobox.luaJsonToObjAttrs(CLSID_OrderHold, json.encode(temp)) |
| | | |
| | | if nRet ~= 0 then |
| | | result_transaction_back(strLuaDEID, CLSID_OrderHold ..' 更新时luaJsonToObjAttrs执行失败,详细:' .. str_data_attrset) |
| | | end |
| | | -- 反序列化为目标格式 |
| | | attrValueObj = json.decode(str_data_attrset) |
| | | end |
| | | -- 当程序可以运行以下时 - 认为 if nRet == 0 --- 执行upd逻辑 |
| | | lua.Debug(strLuaDEID, debug.getinfo(1), "attrValueObj", attrValueObj) |
| | | -- 组装批量更新的数据格式 |
| | | local updateObj = {} |
| | | |
| | | local updateObj_item = {} |
| | | updateObj_item.id = id |
| | | updateObj_item.attrs = attrValueObj |
| | | table.insert(updateObj, updateObj_item) |
| | | |
| | | local updateStrDataJson = lua.table2str(updateObj) |
| | | lua.Debug(strLuaDEID, debug.getinfo(1), CLSID_OrderHold .."-update准备覆盖已有数据", updateStrDataJson) |
| | | local nRet, strRetInfo = mobox.updateDataObj(strLuaDEID, CLSID_OrderHold, updateStrDataJson) |
| | | if (nRet ~= 0) then |
| | | result_transaction_back(strLuaDEID, string.format(CLSID_OrderHold .."更新操作失败。code:%s,msg:%s", nRet, strRetInfo)) |
| | | end |
| | | end |
| | | |
| | | |
| | | --[[ |
| | | desc:创建目标数据 |
| | | ]] |
| | | local function creatBussData(strLuaDEID, dataSet) |
| | | |
| | | -- 前置判断 |
| | | if dataSet.taskType == nil and lua.trim(dataSet.taskType) == "" then |
| | | result_transaction_back(strLuaDEID, string.format([[ %s 数据验证-操作失败。%s ]], CLSID_OrderHold, "报文‘订单类型(taskType)’-字段,不可为空")) |
| | | end |
| | | |
| | | -- 允许创建‘订单取消实体’标记 - 暂留 |
| | | local FLAG = false |
| | | -- 仅用于出库单组装返回报文用 nil、 0、 1 |
| | | local needReturnOrder |
| | | |
| | | -- 1. 出库订单判断-Outbound_Order |
| | | if dataSet.taskType == "so" then |
| | | lua.Debug(strLuaDEID, debug.getinfo(1), "订单类型-出库订单", dataSet.taskType) |
| | | |
| | | local strCondition |
| | | do |
| | | local filters = {} |
| | | table.insert(filters, string.format([[ %s = '%s' ]], "S_NO", lua.Get_StrAttrValue(dataSet.taskId))) |
| | | strCondition = table.concat(filters, " and ") |
| | | lua.Debug(strLuaDEID, debug.getinfo(1), "filters-组装 出库订单 的where条件", strCondition) |
| | | end |
| | | -- strRetInfo:str attr-value 型的数据 |
| | | local nRet, id, strRetInfo = mobox.getDataObjAttrByKeyAttr(strLuaDEID, CLSID_OutboundOrder, strCondition) |
| | | if nRet == 0 then |
| | | local luaDataArray = json.decode(strRetInfo) |
| | | lua.Debug(strLuaDEID, debug.getinfo(1), "出库单-luaDataArray", luaDataArray) |
| | | local luaData = m3.KeyValueAttrsToObjAttr(luaDataArray) |
| | | lua.Debug(strLuaDEID, debug.getinfo(1), "出库单-luaData", luaData) |
| | | --local state = lua.Get_StrAttrValue( luaData.b_state) |
| | | local state = lua.Get_StrAttrValue( luaData.N_B_STATE) |
| | | lua.Debug(strLuaDEID, debug.getinfo(1), "出库订单 b_state", state) |
| | | |
| | | FLAG = not contains( { "50","55","90","91" },state ) --包含状态不准取消 |
| | | |
| | | if FLAG then |
| | | local state_toNum = lua.Get_NumAttrValue(state) |
| | | needReturnOrder = (state_toNum >=25 and state_toNum <= 55 ) and 1 or 0 |
| | | end |
| | | |
| | | elseif nRet == 1 then |
| | | --目标单据不存在 |
| | | result_transaction_back(strLuaDEID, string.format([[出库订单-出库单号:%s,不存在!]],lua.Get_StrAttrValue(dataSet.taskId))) |
| | | else |
| | | result_transaction_back(strLuaDEID, string.format([[异常:查询出库订单-出库单号:%s,时失败:%s]],lua.Get_StrAttrValue(dataSet.taskId),strRetInfo)) |
| | | end |
| | | end |
| | | |
| | | |
| | | -- 2. 入库单-Inbound_Order |
| | | if dataSet.taskType == "asn" then |
| | | lua.Debug(strLuaDEID, debug.getinfo(1), "订单类型-入库单", dataSet.taskType) |
| | | |
| | | local strCondition |
| | | do |
| | | local filters = {} |
| | | table.insert(filters, string.format([[ %s = '%s' ]], "S_NO", lua.Get_StrAttrValue(dataSet.taskId))) |
| | | strCondition = table.concat(filters, " and ") |
| | | lua.Debug(strLuaDEID, debug.getinfo(1), "filters-组装 入库单 的where条件", strCondition) |
| | | end |
| | | -- strRetInfo:str attr-value 型的数据 |
| | | local nRet, id, strRetInfo = mobox.getDataObjAttrByKeyAttr(strLuaDEID, CLSID_InboundOrder, strCondition) |
| | | --local nRet, id, strRetInfo = mobox.GetDataObjByCondition(strLuaDEID, CLSID_InboundOrder, strCondition) |
| | | |
| | | if nRet == 0 then |
| | | local luaDataArray = json.decode(strRetInfo) |
| | | --lua.Debug(strLuaDEID, debug.getinfo(1), "入库单 strRetInfo 类型", type(strRetInfo)) |
| | | --lua.Debug(strLuaDEID, debug.getinfo(1), "入库单 strRetInfo", strRetInfo) |
| | | --local luaJson = m3.objAttrsToLuaJson(CLSID_InboundOrder,strRetInfo) |
| | | --lua.Debug(strLuaDEID, debug.getinfo(1), "入库单 luaJson", luaJson) |
| | | local luaData = m3.KeyValueAttrsToObjAttr(luaDataArray) |
| | | lua.Debug(strLuaDEID, debug.getinfo(1), "入库单 luaData", luaData) |
| | | --FLAG = contains( STATUS_array_OutboundOrder, lua.Get_StrAttrValue( luaData.b_state)) |
| | | --local state = lua.Get_StrAttrValue( luaData.b_state) |
| | | local state = lua.Get_StrAttrValue( luaData.N_B_STATE) |
| | | lua.Debug(strLuaDEID, debug.getinfo(1), "入库单 b_state", state) |
| | | local state_toNum = lua.Get_NumAttrValue(state) |
| | | FLAG = not (state_toNum >=20 and state_toNum <= 55 ) |
| | | |
| | | if FLAG then -- 需要更新 入库单 N_BSTATE=91 |
| | | local temp = {} |
| | | temp.b_state = 91 |
| | | local nRet, str_data_attrset = mobox.luaJsonToObjAttrs(CLSID_InboundOrder, json.encode(temp)) |
| | | if nRet ~= 0 then |
| | | result_transaction_back(strLuaDEID, '更新入库单状态b_state时 luaJsonToObjAttrs 函数执行失败!msg:' .. str_data_attrset) |
| | | end |
| | | -- 反序列化为目标格式 |
| | | local attrValueObj = json.decode(str_data_attrset) |
| | | |
| | | -- 组装批量更新的数据格式 |
| | | local updateObj = {} |
| | | |
| | | local updateObj_item = {} |
| | | updateObj_item.id = id |
| | | updateObj_item.attrs = attrValueObj |
| | | table.insert(updateObj, updateObj_item) |
| | | |
| | | local updateStrDataJson = lua.table2str(updateObj) |
| | | lua.Debug(strLuaDEID, debug.getinfo(1), "入库单-update准备覆盖已有数据", updateStrDataJson) |
| | | local nRet, strRetInfo = mobox.updateDataObj(strLuaDEID, CLSID_InboundOrder, updateStrDataJson) |
| | | if (nRet ~= 0) then |
| | | result_transaction_back(strLuaDEID, string.format("入库单更新操作失败!code:%s,msg:%s", nRet, strRetInfo)) |
| | | end |
| | | end |
| | | |
| | | elseif nRet == 1 then |
| | | --目标单据不存在 |
| | | result_transaction_back(strLuaDEID, string.format([[入库单-入库单号:%s,不存在!]],lua.Get_StrAttrValue(dataSet.taskId))) |
| | | else |
| | | result_transaction_back(strLuaDEID, string.format([[异常:查询入库单-入库单号:%s,时失败:%s]],lua.Get_StrAttrValue(dataSet.taskId),strRetInfo)) |
| | | end |
| | | end |
| | | |
| | | |
| | | -- 3. 盘点单-Count_Order |
| | | if dataSet.taskType == "inventory" then |
| | | lua.Debug(strLuaDEID, debug.getinfo(1), "订单类型-盘点单", dataSet.taskType) |
| | | |
| | | local strCondition |
| | | do |
| | | local filters = {} |
| | | table.insert(filters, string.format([[ %s = '%s' ]], "S_COUNT_NO", lua.Get_StrAttrValue(dataSet.taskId))) |
| | | strCondition = table.concat(filters, " and ") |
| | | lua.Debug(strLuaDEID, debug.getinfo(1), "filters-组装 盘点单 的where条件", strCondition) |
| | | end |
| | | -- strRetInfo:str attr-value 型的数据 |
| | | local nRet, id, strRetInfo = mobox.getDataObjAttrByKeyAttr(strLuaDEID, CLSID_CountOrder, strCondition) |
| | | if nRet == 0 then |
| | | local luaDataArray = json.decode(strRetInfo) |
| | | lua.Debug(strLuaDEID, debug.getinfo(1), "盘点单-luaDataArray", luaDataArray) |
| | | local luaData = m3.KeyValueAttrsToObjAttr(luaDataArray) |
| | | |
| | | local state = lua.Get_StrAttrValue( luaData.N_B_STATE) |
| | | |
| | | lua.Debug(strLuaDEID, debug.getinfo(1), "盘点单 b_state", state) |
| | | |
| | | local state_toNum = lua.Get_NumAttrValue(state) |
| | | FLAG = not (state_toNum >=20 and state_toNum <= 50 ) |
| | | |
| | | if FLAG then -- 需要更新 盘点单 N_BSTATE=91 |
| | | local temp = {} |
| | | temp.b_state = 91 |
| | | local nRet, str_data_attrset = mobox.luaJsonToObjAttrs(CLSID_CountOrder, json.encode(temp)) |
| | | if nRet ~= 0 then |
| | | result_transaction_back(strLuaDEID, '更新盘点单状态b_state时 luaJsonToObjAttrs 函数执行失败!msg:' .. str_data_attrset) |
| | | end |
| | | -- 反序列化为目标格式 |
| | | local attrValueObj = json.decode(str_data_attrset) |
| | | |
| | | -- 组装批量更新的数据格式 |
| | | local updateObj = {} |
| | | |
| | | local updateObj_item = {} |
| | | updateObj_item.id = id |
| | | updateObj_item.attrs = attrValueObj |
| | | table.insert(updateObj, updateObj_item) |
| | | |
| | | local updateStrDataJson = lua.table2str(updateObj) |
| | | lua.Debug(strLuaDEID, debug.getinfo(1), "盘点单-update准备覆盖已有数据", updateStrDataJson) |
| | | local nRet, strRetInfo = mobox.updateDataObj(strLuaDEID, CLSID_CountOrder, updateStrDataJson) |
| | | if (nRet ~= 0) then |
| | | result_transaction_back(strLuaDEID, string.format("盘点单更新操作失败!code:%s,msg:%s", nRet, strRetInfo)) |
| | | end |
| | | end |
| | | |
| | | elseif nRet == 1 then |
| | | --目标单据不存在 |
| | | result_transaction_back(strLuaDEID, string.format([[盘点单-盘点单号:%s,不存在!]],lua.Get_StrAttrValue(dataSet.taskId))) |
| | | else |
| | | result_transaction_back(strLuaDEID, string.format([[异常:查询盘点单-盘点单号:%s,时失败:%s]],lua.Get_StrAttrValue(dataSet.taskId),strRetInfo)) |
| | | end |
| | | end |
| | | |
| | | |
| | | ------ |
| | | if not FLAG then |
| | | result_failure(strLuaDEID, "目标单据状态不满足取消条件!不会生成‘单据取消’记录!") |
| | | return -- 结束后续执行 |
| | | end |
| | | |
| | | -- 创建取消单记录 |
| | | local temp = buildTemp(dataSet) |
| | | lua.Debug(strLuaDEID, debug.getinfo(1), "OrderHold待新增数据-temp", temp) |
| | | create_obj(strLuaDEID, CLSID_OrderHold, temp) |
| | | |
| | | -- 返回数据 |
| | | result_success(strLuaDEID,needReturnOrder) |
| | | |
| | | end |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | --[[ |
| | | 业务数据处理 |
| | | ]] |
| | | local function bussHandle(strLuaDEID, dataSet) |
| | | |
| | | -- 组装sql过滤条件 |
| | | local strCondition |
| | | do |
| | | local filters = {} |
| | | table.insert(filters, string.format([[ %s = '%s' ]], "S_NO", lua.Get_StrAttrValue(dataSet.taskId))) |
| | | strCondition = table.concat(filters, " and ") |
| | | lua.Debug(strLuaDEID, debug.getinfo(1), "filters-组装的ordercancel的where条件", strCondition) |
| | | end |
| | | |
| | | local nRet, id, strRetInfo = mobox.getDataObjAttrByKeyAttr(strLuaDEID, CLSID_OrderHold, strCondition) |
| | | |
| | | if nRet == 0 then |
| | | -- key已存在 |
| | | lua.Debug(strLuaDEID, debug.getinfo(1), "add", "数据更新:" .. strRetInfo) |
| | | -- updateBussData(strLuaDEID, dataSet, id) |
| | | |
| | | --result_failure(strLuaDEID, string.format("任务id:%s 已存在",id)) |
| | | result_success(strLuaDEID, nil,string.format("任务id:%s 已存在",id)) |
| | | |
| | | |
| | | elseif nRet == 1 then |
| | | -- key不存在 |
| | | |
| | | lua.Debug(strLuaDEID, debug.getinfo(1), "upd", "数据新增") |
| | | creatBussData(strLuaDEID, dataSet) |
| | | |
| | | else |
| | | result_transaction_back(strLuaDEID, string.format("查询目标数据失败,code:%s,msg:%s", nRet, strRetInfo)) |
| | | end |
| | | |
| | | -- result_success(strLuaDEID,1) -- 更新的数据不需要创建 WMS还货入库单 |
| | | |
| | | end |
| | | |
| | | |
| | | |
| | | |
| | | local function Order_Cancel_main(strLuaDEID) |
| | | -- 1.1 getxml |
| | | local soap_xml |
| | | do |
| | | local nRet, data = mobox.getCurEditDataPacket(strLuaDEID) |
| | | if (nRet ~= 0) then |
| | | result_transaction_back(strLuaDEID, "无法获取数据包 datajson !" .. data) |
| | | end |
| | | soap_xml = data |
| | | lua.Debug(strLuaDEID, debug.getinfo(1), "GK-API-07xml报文", soap_xml) |
| | | end |
| | | |
| | | -- 1.2 xml->luaobj |
| | | local parsed_data |
| | | do |
| | | local nRet, data = xml.parse(soap_xml) |
| | | if (nRet ~= 0) then |
| | | result_transaction_back(strLuaDEID, "接口输入的XML格式非法!") |
| | | end |
| | | parsed_data = data |
| | | end |
| | | |
| | | -- 1.3 取得商品批次表item的tableObj |
| | | local dataSet = parsed_data["Envelope"]["Body"] |
| | | ["OrderCancellationReq"] |
| | | ["OrderCancellation_Input"] |
| | | ["InputParameters"] |
| | | ["OrderCancellation_TB"] |
| | | |
| | | if nil == dataSet then |
| | | -- wms_base.Warning(strLuaDEID, 2, 201, CLSID_OrderHold_desc .."-未解析到soap目标节点!", json.encode(dataSet), "", CLSID_OrderHold_desc .."-dataSet") |
| | | result_transaction_back(strLuaDEID, CLSID_OrderHold_desc .."-未解析到soap目标节点!") |
| | | elseif #dataSet == 0 then |
| | | -- 仅单条数据 |
| | | lua.Debug(strLuaDEID, debug.getinfo(1), "单条", dataSet) |
| | | bussHandle(strLuaDEID, dataSet) |
| | | else |
| | | for i = 1, #dataSet do |
| | | lua.Debug(strLuaDEID, debug.getinfo(1), "多条", "") |
| | | bussHandle(strLuaDEID, dataSet[i]) |
| | | end |
| | | end |
| | | |
| | | |
| | | |
| | | end |
| | | |
| | | --[[ |
| | | 固定-错误捕获处理 |
| | | ]] |
| | | local function errorHandler(err) |
| | | ERR = err |
| | | lua.Debug(luaDEID, debug.getinfo(1), "err-记录", err) |
| | | --lua.Error(strLuaDEID, debug.getinfo(1), "err-记录:" .. err) |
| | | return err |
| | | end |
| | | |
| | | --[[ 入口函数 ]] |
| | | function Order_Cancel(strLuaDEID) |
| | | luaDEID = strLuaDEID |
| | | local success, result = xpcall(Order_Cancel_main, errorHandler,strLuaDEID) |
| | | |
| | | if not success then |
| | | -- lua.Error(strLuaDEID, debug.getinfo(1), ERR) |
| | | end |
| | | |
| | | end |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
New file |
| | |
| | | --- Created by w1832. |
| | | --- DateTime: 2025/5/20 上午8:57 |
| | | --- |
| | | |
| | | --[[ |
| | | 编码: GK-API-08 |
| | | 名称: Outbound_Priority_Change |
| | | 作者:wsz |
| | | 入口函数:Outbound_Priority_Change |
| | | 功能说明:更新发货单 Shipping_Order 优先级,已分配后不允许更新 |
| | | 变更历史: |
| | | v0.0.1 初始 |
| | | |
| | | v0.0.2 CLSID 为出库单,非Shipping_Order发货单 |
| | | 注意: |
| | | 1、此报文结构应是单条推送 |
| | | 2、S_BS_NO查到的数据不一定唯一,同S_BS_NO数据的N_B_STATE状态也不一定全部满足要求,仅处理满足条件的数据 |
| | | v0.0.3 修改映射字段S_BS_NO -> S_NO |
| | | --]] |
| | | |
| | | |
| | | json = require("json") |
| | | mobox = require("OILua_JavelinExt") |
| | | m3 = require("oi_base_mobox") |
| | | |
| | | xml = require("oi_base_xml") |
| | | |
| | | --- 实体标识-出库订单优先级调整接口 |
| | | local CLSID_OutboundOrder = "Outbound_Order" |
| | | -- 表名 |
| | | local TB_NAME_OutboundOrder = "TN_Outbound_Order" |
| | | |
| | | local CLSID_OutboundOrder_desc = "出库订单优先级调整接口" |
| | | |
| | | local luaDEID |
| | | |
| | | |
| | | |
| | | --根标签 |
| | | local RootTag = "response" |
| | | |
| | | |
| | | |
| | | |
| | | -- 简化 debug.info记录 |
| | | local function DebugInfo(desc, param) |
| | | if param == nil then |
| | | param = "" |
| | | end |
| | | lua.Debug(luaDEID, debug.getinfo(1), desc, param) |
| | | end |
| | | |
| | | |
| | | --[[ |
| | | -- 执行成功 |
| | | ]] |
| | | local function result_success(strLuaDEID) |
| | | |
| | | local result = {} |
| | | result.flag = "success" -- success|failure |
| | | result.code = 0 |
| | | result.message = "" |
| | | |
| | | do |
| | | local nRet = mobox.returnValue(strLuaDEID, 1, xml.json_to_xml(result,RootTag), result.code) |
| | | if nRet ~= 0 then |
| | | lua.Error(strLuaDEID, debug.getinfo(1), 'result_success-执行mobox.returnValue失败 ' .. nRet) |
| | | end |
| | | end |
| | | end |
| | | |
| | | --[[ |
| | | -- 事务回滚-返回信息后终止执行 |
| | | ]] |
| | | local function result_transaction_back(strLuaDEID, msg) |
| | | |
| | | -- 回滚当次处理 |
| | | lua.Stop(strLuaDEID, msg) |
| | | -- |
| | | --local result = {} |
| | | --result.flag = "failure" -- success|failure |
| | | --result.code = 5 |
| | | --result.message = msg |
| | | -- |
| | | --local xmlstr = xml.json_to_xml(result) |
| | | -- |
| | | --do |
| | | -- local nRet = mobox.returnValue(strLuaDEID, 1, xmlstr, result.code) |
| | | -- if nRet ~= 0 then |
| | | -- lua.Error(strLuaDEID, debug.getinfo(1), 'result_transaction_back-执行mobox.returnValue失败 ' .. nRet) |
| | | -- end |
| | | --end |
| | | error(msg, 0) |
| | | -- lua.Error(strLuaDEID, debug.getinfo(1), xmlstr) |
| | | end |
| | | |
| | | |
| | | --[[ |
| | | param |
| | | CLSID:目标实例calssid |
| | | id目标数据的S_ID |
| | | temp:待更新字段对象,lua属性table |
| | | |
| | | |
| | | --]] |
| | | local function butchUpdateData(strLuaDEID,CLSID,id,temp) |
| | | |
| | | local nRet, str_data_attrset = mobox.luaJsonToObjAttrs(CLSID_OutboundOrder, json.encode(temp)) |
| | | if nRet ~= 0 then |
| | | result_transaction_back(strLuaDEID, "luaJsonToObjAttrs 函数 转化格式失败" .. nRet .. str_data_attrset) |
| | | end |
| | | -- 反序列化为目标格式 |
| | | local attrValueObj = json.decode(str_data_attrset) |
| | | |
| | | -- 组装批量更新的数据格式 |
| | | local updateObj = {} |
| | | |
| | | local updateObj_item = {} |
| | | updateObj_item.id = id |
| | | updateObj_item.attrs = attrValueObj |
| | | table.insert(updateObj, updateObj_item) |
| | | |
| | | local updateStrDataJson = lua.table2str(updateObj) |
| | | lua.Debug(strLuaDEID, debug.getinfo(1), CLSID .. "update准备覆盖已有数据", updateStrDataJson) |
| | | local nRet, strRetInfo = mobox.updateDataObj(strLuaDEID, CLSID, updateStrDataJson) |
| | | if (nRet ~= 0) then |
| | | result_transaction_back(strLuaDEID, string.format(CLSID.."更新操作失败!code:%s,msg:%s", nRet, strRetInfo)) |
| | | end |
| | | |
| | | end |
| | | |
| | | |
| | | --[[ |
| | | 业务数据处理 |
| | | 1、查询 orderNo:S_BS_NO 记录 来源单号非主键,可能存在多条数据 |
| | | 2.判断 N_B_STATE 状态 更新出库单 Outbound_Order 优先级,已分配后不允许更新(N_B_STATE>=25 AND N_B_STATE<=55) |
| | | |
| | | ]] |
| | | local function bussHandle(strLuaDEID, dataSet) |
| | | |
| | | local strCondition |
| | | do |
| | | local filters = {} |
| | | table.insert(filters, string.format([[ %s = '%s' ]], "S_NO", lua.Get_StrAttrValue(dataSet.orderNo))) |
| | | strCondition = table.concat(filters, " and ") |
| | | lua.Debug(strLuaDEID, debug.getinfo(1), "filters-组装的Shipping_Order的where条件", strCondition) |
| | | end |
| | | |
| | | |
| | | -- 查找总数量 |
| | | local nRetCount |
| | | do |
| | | local nRet, nCount = mobox.getDataObjCount(strLuaDEID, CLSID_OutboundOrder, strCondition) |
| | | if nRet == 0 then |
| | | nRetCount = nCount |
| | | DebugInfo(string.format("%s-查询总数量为%s", CLSID_OutboundOrder, nCount)) |
| | | else |
| | | result_transaction_back(strLuaDEID, string.format("查询目标数据失败,code:%s,msg:%s", nRet, nCount)) |
| | | end |
| | | |
| | | if nCount == "0" then |
| | | result_transaction_back(strLuaDEID, dataSet.orderNo .. "查找不到报文对应的出库单数据!") |
| | | end |
| | | end |
| | | |
| | | |
| | | -- 查询目标数据, 存储lua数组,内部为数据库字段格式对象 |
| | | local datas = {} |
| | | do |
| | | local strFieldList = { "S_ID", "S_NO", "S_BS_NO", "N_PRIORITY", "S_NOTE", "N_PRIORITY" } |
| | | -- 返回 json型 str,格式 [ { "attr1": "xxx", "attr2": "xxx1", … }, … |
| | | local nRet, strRetInfo = mobox.queryTable(strLuaDEID, TB_NAME_OutboundOrder, json.encode(strFieldList), nRetCount, strCondition) |
| | | if nRet == 0 then |
| | | DebugInfo(string.format("%s-queryTable函数返回", CLSID_OutboundOrder), strRetInfo) |
| | | local tableData = json.decode(strRetInfo) |
| | | DebugInfo("tableData", tableData) |
| | | |
| | | datas = tableData |
| | | |
| | | --for n = 1, #tableData do |
| | | -- -- local nRet1, strObjJson = mobox.objAttrToObjJson(CLSID_ShippingOrder, tableData[n]) |
| | | -- -- local nRet1, strObjJson = mobox.objJsonToLuaJson(CLSID_ShippingOrder, tableData[n]) |
| | | -- |
| | | -- if nRet1 == 0 then |
| | | -- table.insert(datas, strObjJson) |
| | | -- else |
| | | -- result_transaction_back(strLuaDEID, string.format("queryTable-objAttrToObjJson转化失败,code:%s,msg:%s", nRet1, strObjJson)) |
| | | -- end |
| | | --end |
| | | else |
| | | result_transaction_back(strLuaDEID, string.format("queryTable查询目标数据失败,code:%s,msg:%s", nRet, strRetInfo)) |
| | | end |
| | | end |
| | | |
| | | DebugInfo(string.format("%s-queryTable-取得datas数据", CLSID_OutboundOrder), datas) |
| | | |
| | | -- 迭代更新满足条件的数据 |
| | | for n = 1, #datas do |
| | | |
| | | local b_state = lua.Get_NumAttrValue(datas[n].N_B_STATE) |
| | | local id = datas[n].S_ID |
| | | local flag = b_state >= 25 and b_state <= 55 |
| | | DebugInfo("b_state", b_state) |
| | | DebugInfo("id", id) |
| | | DebugInfo("flag", flag) |
| | | |
| | | if not flag then |
| | | -- 执行更新 |
| | | local temp = {} |
| | | temp.priority = dataSet.priority --优先级 |
| | | temp.note = dataSet.memo -- 备注 |
| | | |
| | | butchUpdateData(strLuaDEID, CLSID_OutboundOrder,id,temp) |
| | | |
| | | --local nRet, str_data_attrset = mobox.luaJsonToObjAttrs(CLSID_ShippingOrder, json.encode(temp)) |
| | | --if nRet ~= 0 then |
| | | -- result_transaction_back(strLuaDEID, "luaJsonToObjAttrs 函数 转化格式失败" .. nRet .. str_data_attrset) |
| | | --end |
| | | ---- 反序列化为目标格式 |
| | | --local attrValueObj = json.decode(str_data_attrset) |
| | | -- |
| | | ---- 组装批量更新的数据格式 |
| | | --local updateObj = {} |
| | | -- |
| | | --local updateObj_item = {} |
| | | --updateObj_item.id = id |
| | | --updateObj_item.attrs = attrValueObj |
| | | --table.insert(updateObj, updateObj_item) |
| | | -- |
| | | --local updateStrDataJson = lua.table2str(updateObj) |
| | | --lua.Debug(strLuaDEID, debug.getinfo(1), CLSID_ShippingOrder .. "update准备覆盖已有数据", updateStrDataJson) |
| | | --local nRet, strRetInfo = mobox.updateDataObj(strLuaDEID, CLSID_ShippingOrder, updateStrDataJson) |
| | | --if (nRet ~= 0) then |
| | | -- result_transaction_back(strLuaDEID, string.format("发货单更新操作失败!code:%s,msg:%s", nRet, strRetInfo)) |
| | | --end |
| | | end |
| | | |
| | | end |
| | | |
| | | end |
| | | |
| | | |
| | | |
| | | local function Outbound_Priority_Change_main(strLuaDEID) |
| | | -- 1.1 getxml |
| | | local soap_xml |
| | | do |
| | | local nRet, data = mobox.getCurEditDataPacket(strLuaDEID) |
| | | if (nRet ~= 0) then |
| | | result_transaction_back(strLuaDEID, "无法获取数据包 datajson !" .. data) |
| | | end |
| | | soap_xml = data |
| | | lua.Debug(strLuaDEID, debug.getinfo(1), "GK-API-08xml报文", soap_xml) |
| | | end |
| | | |
| | | -- 1.2 xml->luaobj |
| | | local parsed_data |
| | | do |
| | | local nRet, data = xml.parse(soap_xml) |
| | | if (nRet ~= 0) then |
| | | result_transaction_back(strLuaDEID, "接口输入的XML格式非法!") |
| | | end |
| | | parsed_data = data |
| | | end |
| | | |
| | | -- 1.3 取得商品批次表item的tableObj |
| | | local dataSet = parsed_data["Envelope"]["Body"] |
| | | ["OrderAdjustmentsReq"] |
| | | ["OrderAdjustments_Input"] |
| | | ["InputParameters"] |
| | | ["OrderAdjustments_TB"] |
| | | |
| | | if nil == dataSet then |
| | | -- wms_base.Warning(strLuaDEID, 2, 201, CLSID_OutboundOrder_desc .. "-未解析到soap目标节点!", json.encode(dataSet), "", CLSID_OutboundOrder_desc .. "-dataSet") |
| | | result_transaction_back(strLuaDEID, CLSID_OutboundOrder_desc .. "-未解析到soap目标节点!") |
| | | elseif #dataSet == 0 then |
| | | -- 仅单条数据 |
| | | lua.Debug(strLuaDEID, debug.getinfo(1), "单条", dataSet) |
| | | bussHandle(strLuaDEID, dataSet) |
| | | else |
| | | for i = 1, #dataSet do |
| | | lua.Debug(strLuaDEID, debug.getinfo(1), "多条", "") |
| | | bussHandle(strLuaDEID, dataSet[i]) |
| | | end |
| | | end |
| | | |
| | | result_success(strLuaDEID) |
| | | end |
| | | |
| | | |
| | | --[[ |
| | | 固定-错误捕获处理 |
| | | ]] |
| | | local ERR |
| | | local function errorHandler(err) |
| | | ERR = err |
| | | lua.Debug(luaDEID, debug.getinfo(1), "err-记录", err) |
| | | return err |
| | | end |
| | | |
| | | --[[ 入口函数 ]] |
| | | function Outbound_Priority_Change(strLuaDEID) |
| | | |
| | | m3.PrintLuaDEInfo(strLuaDEID) |
| | | |
| | | luaDEID = strLuaDEID |
| | | --Outbound_Priority_Change_main(strLuaDEID) |
| | | local success, result = xpcall(Outbound_Priority_Change_main, errorHandler, strLuaDEID) |
| | | |
| | | if not success then |
| | | |
| | | |
| | | local result = {} |
| | | result.flag = "failure" -- success|failure |
| | | result.code = 5 |
| | | result.message = ERR |
| | | |
| | | local xmlstr = xml.json_to_xml(result,RootTag) |
| | | |
| | | do |
| | | local nRet = mobox.returnValue(strLuaDEID, 1, xmlstr, result.code) |
| | | if nRet ~= 0 then |
| | | lua.Error(strLuaDEID, debug.getinfo(1), 'result_transaction_back-执行mobox.returnValue失败 ' .. nRet) |
| | | end |
| | | end |
| | | |
| | | -- lua.Error(strLuaDEID, debug.getinfo(1), ERR) |
| | | end |
| | | |
| | | end |