| | |
| | | 变更历史: 2025-05-14 优化返回结果处理 |
| | | |
| | | XML 报文示例如下; |
| | | <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"> |
| | | <soap:Header xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> |
| | | <soapenv:Envelope |
| | | xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"> |
| | | <soap:Header |
| | | xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> |
| | | </soap:Header> |
| | | <soapenv:Body> |
| | | <v1:InSmallPieceReq xmlns:v1="http://www.gkht.com/InReceive/INV/Ebs/Schemas/InSmallPiece/V1.0"> |
| | | <v1:InSmallPieceReq |
| | | xmlns:v1="http://www.gkht.com/InReceive/INV/Ebs/Schemas/InSmallPiece/V1.0"> |
| | | <v1:SmallPiece_Input> |
| | | <v1:RESTHeader> |
| | | <v1:Responsibility/> |
| | |
| | | <v1:Org_Id>0</v1:Org_Id> |
| | | </v1:RESTHeader> |
| | | <v1:InputParameters> |
| | | <!-- 第一个收货单 --> |
| | | <v1:SmallPiece_TB> |
| | | <v1:orderNo>SO2025050701</v1:orderNo> |
| | | <v1:asnNo>KPD00002</v1:asnNo> |
| | | <v1:storerId>CGKHTY</v1:storerId> |
| | | <v1:ownerId>CGKHTY</v1:ownerId> |
| | | <v1:orderDate>2025-05-07</v1:orderDate> |
| | | <v1:priority>0</v1:priority> |
| | | <v1:memo>收货单1备注</v1:memo> |
| | | <v1:SmallPiece_TB_ITEM> |
| | | <!--1 or more repetitions:--> |
| | | <v1:SmallPiece_TB> |
| | | <v1:orderNo>SO2025050601</v1:orderNo> |
| | | <v1:asnNo>KPD00001</v1:asnNo> |
| | | <v1:storerId>CGKHTY</v1:storerId> |
| | | <v1:ownerId>CGKHTY</v1:ownerId> |
| | | <v1:orderDate>2025-05-06</v1:orderDate> |
| | | <v1:priority>0</v1:priority> |
| | | <v1:memo></v1:memo> |
| | | <v1:SmallPiece_TB_ITEM> |
| | | <v1:orderItemId>1</v1:orderItemId> |
| | | <v1:skuId>100118100</v1:skuId> |
| | | <v1:skuStatus>AVL</v1:skuStatus> |
| | | <v1:qty>3</v1:qty> |
| | | <v1:batchNo>PHI00000000000001310</v1:batchNo> |
| | | <v1:produceCode>YL201126</v1:produceCode> |
| | | <v1:productDate>2016-05-23</v1:productDate> |
| | | <v1:expiryDate>2099-12-31</v1:expiryDate> |
| | | <v1:registerNo>国食药监械(准)字2013</v1:registerNo> |
| | | </v1:SmallPiece_TB_ITEM> |
| | | <v1:SmallPiece_TB_ITEM> |
| | | <v1:orderItemId>2</v1:orderItemId> |
| | | <v1:skuId>100117231</v1:skuId> |
| | | <v1:skuStatus>AVL</v1:skuStatus> |
| | | <v1:qty>4</v1:qty> |
| | | <v1:batchNo>PHI00000000000001311</v1:batchNo> |
| | | <v1:produceCode>YL201127</v1:produceCode> |
| | | <v1:productDate>2023-05-23</v1:productDate> |
| | | <v1:expiryDate>2099-12-31</v1:expiryDate> |
| | | <v1:registerNo></v1:registerNo> |
| | | </v1:SmallPiece_TB_ITEM> |
| | | </v1:SmallPiece_TB> |
| | | <!-- 第二个收货单 --> |
| | | <v1:SmallPiece_TB> |
| | | <v1:orderNo>SO2025050702</v1:orderNo> |
| | | <v1:asnNo>KPD00003</v1:asnNo> |
| | | <v1:storerId>CGKHTY</v1:storerId> |
| | | <v1:ownerId>CGKHTY</v1:ownerId> |
| | | <v1:orderDate>2025-05-07</v1:orderDate> |
| | | <v1:priority>1</v1:priority> |
| | | <v1:memo>收货单2备注</v1:memo> |
| | | <v1:SmallPiece_TB_ITEM> |
| | | <v1:orderItemId>1</v1:orderItemId> |
| | | <v1:skuId>200000002</v1:skuId> |
| | | <v1:skuId>XR33201-2L080B</v1:skuId> |
| | | <v1:skuStatus>AVL</v1:skuStatus> |
| | | <v1:qty>2</v1:qty> |
| | | <v1:batchNo>PHI00000000000001312</v1:batchNo> |
| | | <v1:produceCode>YL201128</v1:produceCode> |
| | | <v1:productDate>2016-06-23</v1:productDate> |
| | | <v1:expiryDate>2099-12-31</v1:expiryDate> |
| | | <v1:registerNo>国食药监械(准)字2014</v1:registerNo> |
| | | <v1:batchNo>PHI00000000000001309</v1:batchNo> |
| | | <v1:produceCode>YL201125</v1:produceCode> |
| | | <v1:productDate>2016-04-23</v1:productDate> |
| | | <v1:expiryDate>2099-12-31</v1:expiryDate> |
| | | <v1:registerNo>国食药监械(准)字2012</v1:registerNo> |
| | | </v1:SmallPiece_TB_ITEM> |
| | | <v1:SmallPiece_TB_ITEM> |
| | | <v1:SmallPiece_TB_ITEM> |
| | | <v1:orderItemId>2</v1:orderItemId> |
| | | <v1:skuId>100117238</v1:skuId> |
| | | <v1:skuId>KH32803017</v1:skuId> |
| | | <v1:skuStatus>AVL</v1:skuStatus> |
| | | <v1:qty>5</v1:qty> |
| | | <v1:batchNo>PHI00000000000001313</v1:batchNo> |
| | | <v1:produceCode>YL201129</v1:produceCode> |
| | | <v1:productDate>2023-06-23</v1:productDate> |
| | | <v1:expiryDate>2099-12-31</v1:expiryDate> |
| | | <v1:registerNo></v1:registerNo> |
| | | <v1:batchNo>PHI00000000000001308</v1:batchNo> |
| | | <v1:produceCode>YL2011256</v1:produceCode> |
| | | <v1:productDate>2023-04-23</v1:productDate> |
| | | <v1:expiryDate>2099-12-31</v1:expiryDate> |
| | | <v1:registerNo></v1:registerNo> |
| | | </v1:SmallPiece_TB_ITEM> |
| | | </v1:SmallPiece_TB> |
| | | </v1:InputParameters> |
| | |
| | | </v1:InSmallPieceReq> |
| | | </soapenv:Body> |
| | | </soapenv:Envelope> |
| | | |
| | | --]] |
| | | |
| | | wms_base = require("wms_base") |
| | | --]] wms_base = require("wms_base") |
| | | xml = require("oi_base_xml") |
| | | mobox = require("OILua_JavelinExt") |
| | | m3 = require("oi_base_mobox") |
| | | |
| | | -- 创建统一返回结果 |
| | | function Create_result(flag, code, msg, error) |
| | | return { |
| | | flag = flag or "success", |
| | | code = code or "0", |
| | | message = msg or "", |
| | | error = error or "" |
| | | } |
| | | end |
| | | |
| | | function Receipt_Sync(strLuaDEID) |
| | | -- 初始化最终结果 |
| | | local FinalRes = Create_result() |
| | | |
| | | -- 1. 获取 xml 数据包 |
| | | local nRet, soap_xml = mobox.getCurEditDataPacket(strLuaDEID) |
| | | if nRet ~= 0 then |
| | | FinalRes = Create_result("failure", "201", "无法获取数据包: " .. soap_xml) |
| | | lua.Stop(strLuaDEID, "获取数据包失败", FinalRes) |
| | | |
| | | local xml_result = xml.json_to_xml(FinalRes, "response") |
| | | mobox.returnValue(strLuaDEID, 0, xml_result, 0) |
| | | lua.Stop(strLuaDEID, "获取数据包失败", soap_xml) |
| | | return |
| | | end |
| | | |
| | | lua.DebugEx(strLuaDEID, "获取到的数据包", soap_xml) |
| | | |
| | | -- 2. 解析 xml |
| | | local nRet, parsed_data = xml.parse(soap_xml) |
| | | if nRet ~= 0 then |
| | | FinalRes = Create_result("failure", "202", "xml 格式非法") |
| | | lua.Stop(strLuaDEID, "xml格式非法", FinalRes) |
| | | |
| | | local xml_result = xml.json_to_xml(FinalRes, "response") |
| | | mobox.returnValue(strLuaDEID, 0, xml_result, 0) |
| | | lua.Stop(strLuaDEID, "xml格式非法", parsed_data) |
| | | return |
| | | end |
| | | |
| | | -- 3. 提取主表数据 |
| | |
| | | -- 检查是否存在 SmallPiece_TB |
| | | if not input_params or not input_params.SmallPiece_TB then |
| | | FinalRes = Create_result("failure", "203", "xml 数据格式错误,缺少 SmallPiece_TB") |
| | | lua.Stop(strLuaDEID, "xml 数据格式错误", FinalRes) |
| | | local xml_result = xml.json_to_xml(FinalRes, "response") |
| | | mobox.returnValue(strLuaDEID, 0, xml_result, 0) |
| | | lua.Stop(strLuaDEID, "xml 数据格式错误", xml_result) |
| | | return |
| | | end |
| | | |
| | |
| | | local RetFAC_COE, CONST_FACTORY = wms_base.Get_sConst2(strLuaDEID, "GK_Default_Factory") |
| | | if (RetWH_COE ~= 0 or RetFAC_COE ~= 0) then |
| | | FinalRes = Create_result("failure", "204", "获取仓库/工厂常量失败") |
| | | lua.Stop(strLuaDEID, "获取系统常量失败", FinalRes) |
| | | return |
| | | local xml_result = xml.json_to_xml(FinalRes, "response") |
| | | mobox.returnValue(strLuaDEID, 0, xml_result, 0) |
| | | lua.Stop(strLuaDEID, "获取系统常量失败", xml_result) |
| | | return |
| | | end |
| | | |
| | | -- 6. 遍历所有收货单 |
| | | local result = Create_result() |
| | | for i = 1, #receipt_headers do |
| | | local header = receipt_headers[i] |
| | | |
| | | -- 检查收货单是否已存在 |
| | | local strCondition = string.format("S_NO = '%s'", header.orderNo) |
| | | lua.DebugEx(strLuaDEID, "SQL 条件", strCondition) |
| | | local nRet, strRetInfo = mobox.getDataObjAttrByKeyAttr(strLuaDEID, "Receipt_Order", strCondition) |
| | | lua.DebugEx(strLuaDEID, "查询收货单条件", strCondition) |
| | | local nRet, retReceipt = m3.GetDataObjByCondition(strLuaDEID, "Receipt_Order", strCondition) |
| | | |
| | | if nRet == 0 then |
| | | FinalRes = Create_result("failure", "205", "收货单已存在", |
| | | -- 查询成功且找到记录,说明收货单已存在 |
| | | lua.DebugEx(strLuaDEID, "查询成功,收货单已存在", retReceipt) |
| | | FinalRes = Create_result("failure", "1", "收货单已存在", |
| | | "收货单[" .. header.orderNo .. "]已存在") |
| | | lua.Stop(strLuaDEID, "收货单已存在", FinalRes) |
| | | |
| | | elseif nRet > 1 then |
| | | FinalRes = Create_result("failure", "206", "系统错误", |
| | | "检查收货单是否存在时出错: " .. strRetInfo) |
| | | lua.Stop(strLuaDEID, "检查收货单是否存在时出错", FinalRes) |
| | | |
| | | local xml_result = xml.json_to_xml(FinalRes, "response") |
| | | mobox.returnValue(strLuaDEID, 0, xml_result, 0) |
| | | lua.Stop(strLuaDEID, "收货单已存在", retReceipt) |
| | | return |
| | | elseif nRet ~= 1 then |
| | | -- 查询出错 |
| | | lua.DebugEx(strLuaDEID, "查询出错", retReceipt) |
| | | FinalRes = Create_result("failure", "206", "检查收货单是否存在时出错", |
| | | "检查收货单[" .. header.orderNo .. "]时出错: " .. retReceipt) |
| | | local xml_result = xml.json_to_xml(FinalRes, "response") |
| | | mobox.returnValue(strLuaDEID, 0, xml_result, 0) |
| | | lua.Stop(strLuaDEID, "检查收货单是否存在时出错", xml_result) |
| | | return |
| | | end |
| | | |
| | | -- 创建主表数据 |
| | |
| | | receipt.bs_type = "SMALL_PIECE" |
| | | receipt.factory = CONST_FACTORY |
| | | receipt.wh_code = CONST_WH |
| | | lua.DebugEx(strLuaDEID, "创建的表单:", receipt); |
| | | |
| | | -- 检查是否已存在相同关键字的记录 |
| | | local nRet, ret_info = m3.CreateDataObj(strLuaDEID, receipt) |
| | | if nRet ~= 0 then |
| | | FinalRes = Create_result("failure", "207", "创建收货单主表失败", |
| | | "收货单[" .. header.orderNo .. "]创建失败: " .. ret_info) |
| | | lua.Stop(strLuaDEID, "创建收货单主表失败", FinalRes) |
| | | |
| | | -- 再次检查是否真的存在 |
| | | local nRetCheck, retReceiptCheck = m3.GetDataObjByCondition(strLuaDEID, "Receipt_Order", strCondition) |
| | | if nRetCheck == 0 then |
| | | FinalRes = Create_result("failure", "205", "收货单已存在", |
| | | "收货单[" .. header.orderNo .. "]已存在") |
| | | else |
| | | FinalRes = Create_result("failure", "207", "创建收货单主表失败", |
| | | "收货单[" .. header.orderNo .. "]创建失败: " .. ret_info) |
| | | end |
| | | local xml_result = xml.json_to_xml(FinalRes, "response") |
| | | mobox.returnValue(strLuaDEID, 0, xml_result, 0) |
| | | lua.Stop(strLuaDEID, "创建收货单主表失败", ret_info) |
| | | return |
| | | end |
| | | |
| | | -- 检查明细数据是否存在 |
| | | if not header.SmallPiece_TB_ITEM then |
| | | if header.SmallPiece_TB_ITEM == nil then |
| | | lua.DebugEx(strLuaDEID, "警告:收货单 " .. header.orderNo .. " 无明细数据") |
| | | else |
| | | -- 7. 遍历当前收货单的所有明细数据 |
| | | local details = header.SmallPiece_TB_ITEM |
| | | -- 确保 details 是数组(即使只有一个明细) |
| | | if details[1] == nil then |
| | | details = {details} |
| | | FinalRes = Create_result("failure", "208", "收货单无明细数据", |
| | | "收货单[" .. header.orderNo .. "]无明细数据") |
| | | local xml_result = xml.json_to_xml(FinalRes, "response") |
| | | mobox.returnValue(strLuaDEID, 0, xml_result, 0) |
| | | lua.Stop(strLuaDEID, "收货单无明细数据", xml_result) |
| | | return |
| | | end |
| | | |
| | | -- 7. 遍历当前收货单的所有明细数据 |
| | | local details = header.SmallPiece_TB_ITEM |
| | | -- 确保 details 是数组(即使只有一个明细) |
| | | if details[1] == nil then |
| | | details = {details} |
| | | end |
| | | |
| | | for j = 1, #details do |
| | | local item = details[j] |
| | | -- 先检验skuId是否存在 |
| | | local strCondition = string.format("S_ITEM_CODE= '%s' AND S_STORER = '%s'", item.skuId, header.storerId) |
| | | -- 执行查询 |
| | | local nRet, receiptInfo = m3.GetDataObjByCondition(strLuaDEID, "SKU", strCondition) |
| | | if (nRet ~= 0) then |
| | | lua.DebugEx(strLuaDEID, "SKU查询出错", |
| | | "ITEM_CODE: " .. item.skuId .. ", 错误信息: " .. receiptInfo) |
| | | FinalRes = Create_result("failure", "207", "检查 SKU 是否存在时出错", |
| | | "SKU ID: " .. item.skuId .. ", 错误: " .. receiptInfo) |
| | | local xml_result = xml.json_to_xml(FinalRes, "response") |
| | | mobox.returnValue(strLuaDEID, 0, xml_result, 0) |
| | | lua.Stop(strLuaDEID, "查询失败", xml_result) |
| | | return |
| | | elseif (receiptInfo == "") then |
| | | lua.DebugEx(strLuaDEID, "查询为空", "ITEM_CODE:" .. item.skuId) |
| | | FinalRes = Create_result("failure", "208", "查询数据为空", "ITEM_CODE : " .. item.skuId) |
| | | local xml_result = xml.json_to_xml(FinalRes, "response") |
| | | mobox.returnValue(strLuaDEID, 0, xml_result, 0) |
| | | lua.Stop(strLuaDEID, "物料数据不存在", xml_result) |
| | | return |
| | | end |
| | | |
| | | for j = 1, #details do |
| | | local item = details[j] |
| | | -- 创建明细数据 |
| | | local receipt_detail = m3.AllocObject(strLuaDEID, "Receipt_Detail") |
| | | receipt_detail.row_no = item.orderItemId |
| | | receipt_detail.receipt_no = header.orderNo |
| | | receipt_detail.qty = lua.Get_NumAttrValue(item.qty) or 0 |
| | | receipt_detail.acc_put_qty = lua.Get_NumAttrValue("0") |
| | | receipt_detail.acc_unq_qty = lua.Get_NumAttrValue("0") |
| | | receipt_detail.acc_c_qty = lua.Get_NumAttrValue("0") |
| | | receipt_detail.item_code = item.skuId |
| | | receipt_detail.item_state = item.skuStatus |
| | | receipt_detail.wu = "kg" |
| | | receipt_detail.batch_no = item.produceCode |
| | | receipt_detail.prd_date = item.productDate |
| | | receipt_detail.exp_date = item.expiryDate |
| | | receipt_detail.udf01 = item.registerNo |
| | | receipt_detail.storer = header.storerId |
| | | receipt_detail.owner = header.ownerId |
| | | -- 创建明细数据 |
| | | local receipt_detail = m3.AllocObject(strLuaDEID, "Receipt_Detail") |
| | | receipt_detail.row_no = item.orderItemId |
| | | receipt_detail.receipt_no = header.orderNo |
| | | receipt_detail.qty = lua.Get_NumAttrValue(item.qty) or 0 |
| | | receipt_detail.acc_put_qty = lua.Get_NumAttrValue("0") |
| | | receipt_detail.acc_unq_qty = lua.Get_NumAttrValue("0") |
| | | receipt_detail.acc_c_qty = lua.Get_NumAttrValue("0") |
| | | receipt_detail.item_code = item.skuId |
| | | receipt_detail.item_state = item.skuStatus |
| | | receipt_detail.item_name = receiptInfo.item_name or "" |
| | | receipt_detail.wu = "kg" |
| | | receipt_detail.batch_no = item.produceCode |
| | | receipt_detail.prd_date = item.productDate |
| | | receipt_detail.exp_date = item.expiryDate |
| | | receipt_detail.udf01 = item.registerNo |
| | | receipt_detail.storer = header.storerId |
| | | receipt_detail.owner = header.ownerId |
| | | receipt_detail.item_name = receiptInfo.item_name or "" |
| | | receipt_detail.net_weight = receiptInfo.weight or 0 |
| | | receipt_detail.gross_weight = receiptInfo.weight or 0 |
| | | receipt_detail.uom = receiptInfo.uom or "" |
| | | |
| | | -- 获取物料信息 |
| | | if item.skuId ~= nil then |
| | | local nRet, mat_info = m3.GetDataObjByCondition(strLuaDEID, "Material", |
| | | "S_ITEM_CODE='" .. item.skuId .. "'") |
| | | if nRet == 0 then |
| | | receipt_detail.item_name = mat_info.item_name or "" |
| | | receipt_detail.net_weight = mat_info.weight or 0 |
| | | receipt_detail.gross_weight = mat_info.weight or 0 |
| | | receipt_detail.uom = mat_info.uom or "" |
| | | end |
| | | end |
| | | |
| | | local nRet, ret_info = m3.CreateDataObj(strLuaDEID, receipt_detail) |
| | | if nRet ~= 0 then |
| | | FinalRes = Create_result("failure", "208", "创建收货明细失败", |
| | | "行号[" .. item.orderItemId .. "]创建失败: " .. ret_info) |
| | | lua.Stop(strLuaDEID, "创建收货明细失败", FinalRes) |
| | | |
| | | end |
| | | lua.DebugEx(strLuaDEID, "创建明细数据:", receipt_detail) |
| | | local nRet, ret_info = m3.CreateDataObj(strLuaDEID, receipt_detail) |
| | | if nRet ~= 0 then |
| | | FinalRes = Create_result("failure", "208", "创建收货明细失败", "创建失败: " .. ret_info) |
| | | local xml_result = xml.json_to_xml(FinalRes, "response") |
| | | mobox.returnValue(strLuaDEID, 0, xml_result, 0) |
| | | lua.DebugEx(strLuaDEID, "创建收货明细失败", xml_result) |
| | | lua.Stop(strLuaDEID, "创建收货明细失败", ret_info) |
| | | return |
| | | end |
| | | end |
| | | end |
| | | |
| | | -- 8. 返回成功 |
| | | -- FinalRes = Create_result("success", "0", "收货单创建成功") |
| | | FinalRes = Create_result("success", "0", "收货单创建成功") |
| | | local xml_result = xml.json_to_xml(FinalRes, "response") |
| | | mobox.returnValue(strLuaDEID, 0, xml_result, 0) |
| | | end |