using Hanhe.iWCS.Common; using Hanhe.iWCS.DeviceDriver; using Hanhe.iWCS.MData; using Hanhe.iWCS.Model; using MongoDB.Driver; using MongoDB.Driver.Builders; using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Globalization; using System.Linq; using System.Security.Cryptography; using System.Text; using System.Threading.Tasks; using static Hanhe.iWCS.JingmenGEMTwoProtocol.ApiHelper; using static Hanhe.iWCS.JingmenGEMTwoProtocol.ERPService; using static Hanhe.iWCS.JingmenGEMTwoProtocol.MESHelper; using static System.Runtime.CompilerServices.RuntimeHelpers; namespace Hanhe.iWCS.JingmenGEMTwoProtocol { public class WMSHelper { private static WebApiHelper helper = new WebApiHelper(); private static T WmsRequest(string name, string param) where T : BaseResponse { HardwareAccessObject hao = HardwareAccessHelper.Instance.GetEquipmentsHAO(Constants.WMS_DEVICE_TYPE_WMS); string msg = ""; string feedback = ""; T response = default(T); if (hao != null) { try { //http://[IP]:[端口]/api/ApiTask/ string webAPIUrl = hao.WebUrl + name; //Console.WriteLine(webAPIUrl); //Console.WriteLine(param); feedback = new WebApiHelper().WebPost(webAPIUrl, param).Replace(@"\", "").Trim(); //feedback = "{\"success\":false,\"errCode\":\"5001\",\"errMsg\":\"托盘号不存在121!\"}"; //feedback = "{\"success\":true,\"errCode\":\"0\",\"task\":{\"taskNo\":\"RWH2103300000013\",\"warehouse\":\"CK002\",\"warehouseArea\":\"BCPLK01\",\"bit\":\"P01-02-06-08\"}}"; if (!string.IsNullOrEmpty(feedback)) { feedback = feedback.Substring(1, feedback.Length - 2); //Console.WriteLine(feedback); response = JsonConvert.DeserializeObject(feedback); if (response.success == true) { msg = $"【wms {name}】success!;WebUrl=" + webAPIUrl + ";param=" + param + ";feedback=" + feedback; } else { string errMsg = response.errMsg; msg = $"【wms {name}】fail!err=" + errMsg + ";WebUrl=" + webAPIUrl + ";param=" + param + ";feedback=" + feedback; } } else { string errMsg = "can't find the address"; msg = $"【wms {name}】fail!err=" + errMsg + ";WebUrl=" + webAPIUrl + ";param=" + param; } //Console.WriteLine(msg); CMMLog.Info(msg); } catch (Exception e) { CMMLog.Error($"【wms {name}】fail!err={e.Message}", e); } } else { msg = string.Format($"wms {name} fail,ams workcenter not set!"); } return response; } internal static void ExecuteState(string taskNo, int state, string bit = "") { var param = new { taskNo = taskNo, stateNo = state }; WmsRequest("ExecuteState", JsonConvert.SerializeObject(param)); } public class BaseResponse { public bool success { get; set; } public string errCode { get; set; } public string errMsg { get; set; } } public class WMSInModel { public string taskNo { get; set; } public string locationGear { get; set; } public string startStock { get; set; } public string startArea { get; set; } public string endArea { get; set; } public string startBit { get; set; } public string trayDimension { get; set; } public string isTransport { get; set; } public string needCreateAMSTask { get; set; } public int priority { get; set; } public int isFull { get; set; } public string projectCode { get; set; } /// /// 托盘码 /// public string trayCode { get; set; } /// /// 托盘类型 /// public string trayType { get; set; } /// /// 生产订单号 /// public string CN_S_PONO { get; set; } //变更注释 public List data { get; set; } //public List TimeData { get; set; } } public class WMSOutModel { //public string taskNo { get; set; } //public string endStock { get; set; } //public string endArea { get; set; } public string endBit { get; set; } public string trayDimension { get; set; } public string needCreateAMSTask { get; set; } public int priority { get; set; } //public int isFull { get; set; } public string projectCode { get; set; } public string TrayType { get; set; } //public List Data { get; set; } } public class WMSEmptyOutModel { //public string taskNo { get; set; } //public string endStock { get; set; } //public string endArea { get; set; } public string endBit { get; set; } public string trayDimension { get; set; } public string needCreateAMSTask { get; set; } public int priority { get; set; } //public int isFull { get; set; } public string projectCode { get; set; } public string trayType { get; set; } } public class WMSEmptyUnbindModel { //public string taskNo { get; set; } //public string endStock { get; set; } //public string endArea { get; set; } public string locationCode { get; set; } } public class WMSResponseModel { //"{\"Success\":false,\"ErrCode\":null,\"ErrMsg\":\"\",\"OkList\":[],\"FailList\":[{\"Index\":0,\"ErrCode\":null,\"ErrMsg\":\"未找到aaa位置的所属仓库\"}],\"Tasks\":[]}" // "{\"Success\":true,\"ErrCode\":null,\"ErrMsg\":null,\"OkList\":[{\"Index\":0,\"TaskNo\":\"RKT00032\",\"StartStock\":\"XMZ001\",\"StartArea\":\"XMZ001005\",\"StartBit\":\"XMZ001Q71-1\",\"EndStock\":\"XMZ001\",\"EndArea\":\"XMZ001001\",\"EndBit\":\"XMZ001B61-2\",\"Priority\":0}],\"FailList\":[],\"Tasks\":[]}" public int Status { get; set; } public string Code { get; set; } public string Msg { get; set; } public List Data { get; set; } public int AffectedRows { get; set; } public bool Success { get; set; } //public List failList { get; set; } //public List tasks { get; set; } //{"taskNo":"任务号","startStock":"起始仓库","startArea":"起始库区","startBit":"起始货位","endStock":"目的仓库","endArea":"目的库区","endBit":"目的货位"} public class TaskInfo { public string taskNo { get; set; } public string startStock { get; set; } public string startArea { get; set; } public string startBit { get; set; } public string endStock { get; set; } public string endArea { get; set; } public string endBit { get; set; } #region 设备通道信息 /// /// 设备通道数据3——托盘码 /// public string trayCode { get; set; } #endregion } } public class WMSResponseModel1 { //"{\"Success\":false,\"ErrCode\":null,\"ErrMsg\":\"\",\"OkList\":[],\"FailList\":[{\"Index\":0,\"ErrCode\":null,\"ErrMsg\":\"未找到aaa位置的所属仓库\"}],\"Tasks\":[]}" // "{\"Success\":true,\"ErrCode\":null,\"ErrMsg\":null,\"OkList\":[{\"Index\":0,\"TaskNo\":\"RKT00032\",\"StartStock\":\"XMZ001\",\"StartArea\":\"XMZ001005\",\"StartBit\":\"XMZ001Q71-1\",\"EndStock\":\"XMZ001\",\"EndArea\":\"XMZ001001\",\"EndBit\":\"XMZ001B61-2\",\"Priority\":0}],\"FailList\":[],\"Tasks\":[]}" public int Status { get; set; } //public string Code { get; set; } public string Msg { get; set; } public List Data { get; set; } public int AffectedRows { get; set; } public bool Success { get; set; } //public List failList { get; set; } //public List tasks { get; set; } //{"taskNo":"任务号","startStock":"起始仓库","startArea":"起始库区","startBit":"起始货位","endStock":"目的仓库","endArea":"目的库区","endBit":"目的货位"} public class TaskInfo { public string taskNo { get; set; } public string startStock { get; set; } public string startArea { get; set; } public string startBit { get; set; } public string endStock { get; set; } public string endArea { get; set; } public string endBit { get; set; } #region 设备通道信息 /// /// 设备通道数据3——托盘码 /// public string trayCode { get; set; } #endregion } } public class ItemData { //托盘尺寸:trayDimension //物料编号:itemCode //物料数量:qty public string itemCode { get; set; } //物料名称 public string itemName { get; set; } //物料规格 public string itemModel { get; set; } //生产订单号 public string CN_S_PONO { get; set; } //public string itemFeature { get; set; } //public string itemState { get; set; } //public string ProductionDate { get; set; } //public string ColourNumber { get; set; } //public string Specification { get; set; } //public string BatchNumber { get; set; } public int qty { get; set; } /// /// 是否叠底托(1-不叠底托 2-叠底托) /// public string palletLayers { get; set; } #region MES传输的数据 //传输MES信息以及设备信息给WMS /// /// mes返回的包装机号(T1,T2,......,T9) /// public string machineNo { get; set; } /// /// mes返回的成品批次号 /// public string lotNo { get; set; } /// /// mes返回的袋号 /// //public string bagNo { get; set; } /// /// mes返回的产品型号 /// //public string productType { get; set; } /// /// mes返回的物料编码 /// //public string materialCode { get; set; } /// /// mes返回的叠包层数 (例1,2,3:1代表不叠包,2代表叠2层,3代表叠3层) /// public string foldingbag { get; set; } #endregion #region 设备通道信息 /// /// 设备通道数据3——托盘码 /// //public string trayCode { get; set; } /// /// 设备通道数据1——包装机号 /// //public string location { get; set; } /// /// 设备通道数据2——产品需求重量:32位整数 /// public string productWeight { get; set; } /// /// 设备通道数据2——托盘重量:32位整数 /// public string trayCodeWeight { get; set; } /// /// 设备通道数据2——单托实际重量:32位整数 /// public string oneTrayWeight { get; set; } /// /// 设备通道数据2——叠包后实际重量:32位整数 /// //public string addWeight { get; set; } /// /// 设备通道数据1——包装机出口称重结果:1:OK,2:NG /// //public int packNg { get; set; } /// /// 设备通道数据1——复称口称重结果:1:OK,2:NG /// public int itemState { get; set; } /// /// 设备通道数据1——是否需要叠包:1:叠包,2:不叠包 /// //public int addState { get; set; } /// /// 设备通道数据1——袋号(001,002,003…999) /// public string packageCode { get; set; } #endregion #region 时间戳信息 /// /// 是否叠包(1,2,3) /// public int isFold { get; set; } = 0; /// /// 包装机号 /// public int packingMachineNumber { get; set; } /// /// 袋号(001,002,003…999)1 /// public string bagNumber { get; set; } /// /// 产品需求重量1:32位整数 /// public int needWeight { get; set; } /// /// 单托实际重量1:32位整数 /// public int realWeight { get; set; } /// /// 叠托后的实际重量:32位整数 /// public int totalWeight { get; set; } /// /// 产品批次号 /// public string batchNumber { get; set; } /// /// 产品型号 /// public string productModel { get; set; } /// /// 计数(只在数据库) /// public int totalCount { get; set; } /// /// 时间戳 /// public int timeStamp { get; set; } /// /// 照片url /// public string photoURL { get; set; } public DateTime GproductionDate { get; set; } #endregion #region WMS显示信息 /// /// 物料编码 /// public string Jm_Item_Code { get; set; } /// /// 物料名称 /// public string Jm_Item_Name { get; set; } /// /// 规格型号 /// public string Jm_Item_Model { get; set; } /// /// 单位 /// public string Jm_Item_Unit { get; set; } /// /// 员工 /// public string Jm_Item_Staff { get; set; } /// /// 分录ID /// public string JournalId { get; set; } #endregion } public static bool WMSIn(string startBit, string ItemCode, ref string taskNo,ref string trayCode,string timeStamp = "",string endArea = "") { //XMZ001A11-1 //startBit = startBit.Substring(0, 9); bool result = false; HardwareAccessObject hao = HardwareAccessHelper.Instance.GetEquipmentsHAO(Constants.WMS_DEVICE_TYPE_WMS); string msg = ""; if (hao != null) { //http://192.168.1.199:9001/api/wmsapi/InWorkArea WMSInModel model = new WMSInModel(); model.startBit = startBit; model.isTransport = "N"; model.needCreateAMSTask = "Y"; model.projectCode = "glm"; model.data = new List(); model.locationGear = ""; if (!string.IsNullOrEmpty(ItemCode)) { CMMLog.Info($"WMSIn-{startBit}:ItemCode不为空,获取信息!111!"); CMMLog.Info($"{ItemCode}"); if (ItemCode == "time" || ItemCode == "拆盘变更" || ItemCode == "打包下线") { CMMLog.Info($"{trayCode}"); var time = MongoDBSingleton.Instance.FindOne(Query.EQ("timeStamp", int.Parse(trayCode)), "TimeCuoInfoCom"); if (ItemCode == "time" && time != null) { int TimeStamp = string.IsNullOrEmpty(timeStamp) ? time.timeStamp : int.Parse(timeStamp); CMMLog.Info($"time获取时间戳数据,获取信息!"); model.data.Add(new ItemData() { //1楼拆盘机调WMS获取入库终点,传输时间戳数据(暂定) //isFold = time.isFold, //packingMachineNumber = time.packingMachineNumber, itemCode = time.productModel, lotNo = time.batchNumber, machineNo = time.packingMachineNumber.ToString(), packageCode = time.bagNumber_1, palletLayers = time.isNeedTray.ToString(), foldingbag = time.isFold.ToString(), //totalWeight = time.totalWeight, timeStamp = TimeStamp, photoURL = time.photoURL, //productType = time.productModel, //bagNumber = time.bagNumber, //needWeight = time.needWeight, realWeight = time.realWeight //batchNumber = time.batchNumber, //totalCount = time.totalCount, }); MongoDBSingleton.Instance.Remove(Query.EQ("timeStamp", int.Parse(trayCode)), RemoveFlags.Single); } else if (ItemCode == "拆盘变更") { model.data.Add(new ItemData() { //1楼拆盘机调WMS获取入库终点,传输时间戳数据(暂定) //isFold = time.isFold, //packingMachineNumber = time.packingMachineNumber, itemCode = "1", lotNo = "1", machineNo = "1", packageCode = "1", palletLayers = "1", foldingbag = "1", //totalWeight = time.totalWeight, timeStamp = 1, photoURL = "1", //productType = time.productModel, //bagNumber = time.bagNumber, //needWeight = time.needWeight, realWeight = 1, //batchNumber = time.batchNumber, //totalCount = time.totalCount, }); } else if (ItemCode == "打包下线") { int TimeStamp = string.IsNullOrEmpty(trayCode) ? time.timeStamp : int.Parse(trayCode); //List batchList = time.batchNumber.Split('-').ToList(); //string batch = ""; //for(int i = 0; i < 1; i++) //{ // batch = batch + batchList[i] + "-"; //} //batch = batch.Substring(0,batch.Length - 1); //CMMLog.Info($"batch:{batch}"); CMMLog.Info($"time获取时间戳数据,获取信息!"); model.endArea = endArea; model.data.Add(new ItemData() { itemCode = time.materialCode, itemName = time.materialName, itemModel = time.productModel, CN_S_PONO = time.orderCode, palletLayers = "1", GproductionDate = Convert.ToDateTime(time.ProductionDate), //时间需要处理 //GproductionDate = DateTime.ParseExact(time.ProductionDate, "yyyyMd", CultureInfo.InvariantCulture), //时间需要处理 qty = time.needWeight, //重量 machineNo = time.packingMachineNumber, //packageCode = info.packageCode, lotNo = time.batchNumber, foldingbag = "1", isFold = time.isFold, //bagNumber = time.bagNumber, packageCode = time.bagNumber_1, //needWeight = time.needWeight, productWeight = (time.needWeight * 100).ToString(), realWeight = time.realWeight, totalWeight = time.totalWeight / 100, batchNumber = time.batchNumber, productModel = time.productModel, totalCount = time.totalCount, timeStamp = TimeStamp, photoURL = time.photoURL, Jm_Item_Code = time.materialCode, Jm_Item_Name = time.materialName, Jm_Item_Model = time.productModel, Jm_Item_Unit = time.measurementUnit, Jm_Item_Staff = time.employeeID1, JournalId = time.FEntryID_1.ToString(), }); //将数据插入中间表 ERPService.senderpTask(time, startBit); } else if (ItemCode == "四钴打包下线") { var DGinfoList = MongoDBSingleton.Instance.FindAll("DGPackingLineFullModel"); if(DGinfoList.Count > 0){ var DGinfo = DGinfoList.OrderBy(a => a.createTime).First(); model.trayCode = DGinfo.trayCode; //将数据插入中间表 ERPService.senderpTaskDG(startBit); } } } else { var info = MongoDBSingleton.Instance.FindOne(Query.EQ("trayCode", ItemCode), "MachineInfo"); // ERP变更新增数据直接从 ERP物料中间表-ERPItemTable 获取(根据物料编码) CMMLog.Info($"WMSIn-{startBit}:查询条件:trayCode={ItemCode},读出 MachineInfo 表数据为:{JsonConvert.SerializeObject(info)}"); //var info = MongoDBSingleton.Instance.FindOne(Query.EQ("trayCode", ItemCode), "MachineInfo"); if (info != null) { //var erpItemTableInfo = MongoDBSingleton.Instance.FindOne(Query.EQ("item_code", info.materialCode), "ERPItemTable"); //CMMLog.Info($"WMSIn-{startBit}:查询条件:item_code={info.materialCode},读出 ERPItemTable 表数据为:{JsonConvert.SerializeObject(erpItemTableInfo)}"); model.locationGear = info.secondNg.ToString(); model.trayCode = info.trayCode; model.trayType = info.trayType == "1" ? "田字托" : info.trayType == "2" ? "川字托" : "4小包"; if (info.trayType == "3") model.locationGear = "3"; model.CN_S_PONO = info.orderCode; //变更注释 //string product = !string.IsNullOrEmpty(info.productType) ? info.productType : erpItemTableInfo.item_spec; model.data.Add(new ItemData() { itemCode = info.materialCode, //itemCode = product, lotNo = info.lotNo, machineNo = info.machineNo, packageCode = info.packageCode, palletLayers = info.palletLayers, foldingbag = info.overlappingLayers, itemState = info.secondNg, productWeight = info.productWeight, trayCodeWeight = info.trayCodeWeight, oneTrayWeight = info.oneTrayWeight, //bagNo = info.bagNo, //productType = info.productType, //materialCode = info.materialCode, //location = info.location, //addWeight = info.addWeight, //packNg = info.packNg, //addState = info.addState, //m_Item_Code = info.materialCode, //m_Item_Name = time.item_name, //m_Item_Model = erpItemTableInfo.item_spec, //m_Item_Unit = erpItemTableInfo.item_uom, //m_Item_Staff = info.trayCodeWeight }); } } } CMMLog.Info("-------------------------"); string msgData = JsonConvert.SerializeObject(model); CMMLog.Info($"{msgData}"); string reqStr = "物料名=" + ItemCode + ";数量"; string feedback = ""; CMMLog.Info($"WMSIn-{startBit}:【调用wms获取入库货位】:发送数据:{JsonConvert.SerializeObject(msgData)},物料条件:ItemCode:{ItemCode},trayCode:{trayCode}"); var url = hao.WebUrl + "GlmInSendTask"; try { //hao.WebUrl = "http://192.168.1.199:9001/api/"; feedback = helper.WebPost(url, msgData).Replace(@"\", "").Trim(); //Console.WriteLine(feedback); CMMLog.Info($"WMSIn-{startBit}:【调用wms获取入库货位】:接收数据:" + feedback); if (!string.IsNullOrEmpty(feedback)) { //var wmsResponse = JsonConvert.DeserializeObject(feedback.Substring(1, feedback.Length - 2)); var wmsResponse = JsonConvert.DeserializeObject(feedback); //var res = feedback.Replace("{", "").Replace("}", "").Replace(":", "=").Replace(",", ";").Replace('"', ' '); if (wmsResponse.Success == true) { if(ItemCode == "打包下线") MongoDBSingleton.Instance.Remove(Query.EQ("timeStamp", int.Parse(trayCode)), RemoveFlags.Single); msg = $"WMSIn-{startBit}:【调用wms获取入库货位】成功!返回结果=" + wmsResponse.Success + ";调用WebUrl=" + url + ";输入参数=" + msgData; } else { string errMsg = wmsResponse.Code + "-" + wmsResponse.Msg; msg = $"WMSIn-{startBit}:【调用wms获取入库货位】失败!错误原因=" + errMsg + ";调用WebUrl=" + url + ";输入参数=" + msgData; } result = wmsResponse.Success; } else { string errMsg = "参数反馈空值"; msg = $"WMSIn-{startBit}:【调用wms获取入库货位】失败!错误原因=" + errMsg + ";调用WebUrl=" + url + ";输入参数=" + msgData; } } catch (Exception e) { CMMLog.Error(string.Format("【调用wms获取入库货位失败】异常{0}", e.Message), e); msg = $"WMSIn-{startBit}:【调用wms获取入库货位】失败!解析返回值出错=" + feedback + ";调用WebUrl=" + url + ";输入参数=" + msgData; } } else msg = string.Format($"WMSIn-{startBit}:调用wms失败,ams工作中心没有设置!"); CMMLog.Info(msg); //Console.WriteLine(msg); return result; } public static bool WMSOut(string endBit, string ItemCode,string TrayType) { //endBit = endBit.Substring(0, 9); bool result = false; HardwareAccessObject hao = HardwareAccessHelper.Instance.GetEquipmentsHAO(Constants.WMS_DEVICE_TYPE_WMS); string msg = ""; if (hao != null) { //http://192.168.1.199:9001/api/wmsapi/InWorkArea WMSOutModel model = new WMSOutModel(); model.endBit = endBit; model.projectCode = "glm"; model.needCreateAMSTask = "Y"; model.TrayType = TrayType; //model.Data = new List(); //if (!string.IsNullOrEmpty(ItemCode)) //{ // model.Data.Add(new ItemData() // { // itemCode = ItemCode // }); //} string msgData = JsonConvert.SerializeObject(model); string reqStr = "物料名=" + ItemCode + ";"; string feedback = ""; var url = hao.WebUrl + "GlmOutSendAmsTask"; try { //hao.WebUrl = "http://192.168.1.199:9001/api/"; feedback = helper.WebPost(url, msgData).Replace(@"\", "").Trim(); CMMLog.Info($"WMS出库接口回报数据:{feedback}"); if (!string.IsNullOrEmpty(feedback)) { //var wmsResponse = JsonConvert.DeserializeObject(feedback.Substring(1, feedback.Length - 2)); var wmsResponse = JsonConvert.DeserializeObject(feedback); CMMLog.Info($"{wmsResponse.Success}"); if (wmsResponse.Success == true) msg = "【调用wms获取出库货位】成功!返回结果=" + wmsResponse.Success + ";调用WebUrl=" + url + ";输入参数=" + msgData; else msg = "【调用wms获取出库货位】失败!错误原因=" + wmsResponse.Code + "-" + wmsResponse.Msg + ";调用WebUrl=" + url + ";输入参数=" + msgData; result = wmsResponse.Success; } else msg = "【调用wms获取出库货位】失败!错误原因=参数反馈空值;调用WebUrl=" + url + ";输入参数=" + msgData; } catch (Exception e) { CMMLog.Error(string.Format("【调用wms获取出库货位失败】异常{0}", e.Message), e); msg = "【调用wms获取出库货位】失败!解析返回值出错=" + feedback + ";调用WebUrl=" + url + ";输入参数=" + msgData; } } else msg = string.Format("调用wms失败,ams工作中心没有设置!"); CMMLog.Info(msg); //Console.WriteLine(msg); return result; } public static bool WMSEmptyOut(string endBit, string ItemCode,string trayType, ref string taskNo, ref string trayCode) { bool result = false; HardwareAccessObject hao = HardwareAccessHelper.Instance.GetEquipmentsHAO(Constants.WMS_DEVICE_TYPE_WMS); string msg = ""; if (hao != null) { //http://192.168.1.199:9001/api/wmsapi/InWorkArea WMSEmptyOutModel model = new WMSEmptyOutModel(); model.endBit = endBit; model.projectCode = "glm"; model.needCreateAMSTask = "Y"; model.trayType = trayType; string msgData = JsonConvert.SerializeObject(model); string reqStr = "物料名=" + ItemCode + ";"; string feedback = ""; var url = hao.WebUrl + "TrayOutCallTask"; try { //hao.WebUrl = "http://192.168.1.199:9001/api/"; feedback = helper.WebPost(url, msgData).Replace(@"\", "").Trim(); CMMLog.Info($"WMS回报数据:{feedback}"); if (!string.IsNullOrEmpty(feedback)) { //var wmsResponse = JsonConvert.DeserializeObject(feedback.Substring(1, feedback.Length - 2)); var wmsResponse = JsonConvert.DeserializeObject(feedback); CMMLog.Info($"{wmsResponse.Success}"); if (wmsResponse.Success == true) { // 增加非空判断 //var ok = wmsResponse.Data[0]; //taskNo = ok.taskNo; //trayCode = ok.trayCode; msg = "【调用wms获取出库货位】成功!返回结果=" + wmsResponse.Success + ";调用WebUrl=" + url + ";输入参数=" + msgData; } else { string errMsg = wmsResponse.Code + "-" + wmsResponse.Msg; msg = "【调用wms获取出库货位】失败!错误原因=" + errMsg + ";调用WebUrl=" + url + ";输入参数=" + msgData; } result = wmsResponse.Success; } else { string errMsg = "参数反馈空值"; msg = "【调用wms获取出库货位】失败!错误原因=" + errMsg + ";调用WebUrl=" + url + ";输入参数=" + msgData; } } catch (Exception e) { CMMLog.Error(string.Format("【调用wms获取出库货位失败】异常{0}", e.Message), e); msg = "【调用wms获取出库货位】失败!解析返回值出错=" + feedback + ";调用WebUrl=" + url + ";输入参数=" + msgData; } } else msg = string.Format("调用wms失败,ams工作中心没有设置!"); CMMLog.Info(msg); //Console.WriteLine(msg); return result; } /// /// 改道接口 /// /// WMS任务号 /// 改道库区 /// internal static string WmsUpdateWay(string taskNo, string changeArea) { string result = ""; string param = JsonConvert.SerializeObject(new { taskNo = taskNo, updateType = "终点", changeArea = changeArea }); var req = WmsWebPost(param, "UpdateWay"); if (req != null && req.success) result = req.location; return result; } /// /// WebPost /// /// 发送内容 /// 接口名称 /// 扩展参数 /// private static WmsResModel WmsWebPost(string param, string postName, string Par1 = "") { string msg = ""; string feedback = ""; WmsResModel response = new WmsResModel(); response.success = false; try { HardwareAccessObject hao = HardwareAccessHelper.Instance.GetEquipmentsHAO(Constants.WMS_DEVICE_TYPE_WMS); if (hao != null) { string webAPIUrl = hao.WebUrl + postName; feedback = new WebApiHelper().WebPost(webAPIUrl, param); if (!string.IsNullOrEmpty(feedback)) { msg = $"【WMS Post {postName}】WebUrl={webAPIUrl} ;param={param} ;return={feedback}"; response = JsonConvert.DeserializeObject(feedback.Substring(1, feedback.Length - 2).Replace(@"\","")); if (response.success == true) msg = $"【WMS Post {postName}】success!;WebUrl={ webAPIUrl};param={param} ;return={feedback}"; else msg = $"【WMS Post {postName}】fail!WebUrl={ webAPIUrl} ;param={param} ;return={feedback}"; } else { string errMsg = "can't find the address"; msg = $"【WMS Post {postName}】fail!err={errMsg};WebUrl={ webAPIUrl} ;param={param}"; } } else msg = $"调用wms失败,ams工作中心没有设置!"; CMMLog.Info(msg); } catch (Exception ex) { CMMLog.Info($"【WMS Post {postName}】fail!err={ex.Message}"); } return response; } internal static bool WMSEmptyUnbind(string extend) { bool result = false; string feedback = ""; HardwareAccessObject hao = HardwareAccessHelper.Instance.GetEquipmentsHAO(Constants.WMS_DEVICE_TYPE_WMS); string msg = ""; if (hao != null) { //http://192.168.1.199:9001/api/wmsapi/UnbindLocation WMSEmptyUnbindModel model = new WMSEmptyUnbindModel(); model.locationCode = extend; string msgData = JsonConvert.SerializeObject(model); var url = hao.WebUrl + "UnbindLocation"; try { //hao.WebUrl = "http://192.168.1.199:9001/api/"; feedback = helper.WebGet(url + "?locationCode=" + extend).Replace(@"\", "").Trim(); CMMLog.Info($"调用解绑接口WMS回报数据:{feedback}"); if (!string.IsNullOrEmpty(feedback)) { //var wmsResponse = JsonConvert.DeserializeObject(feedback.Substring(1, feedback.Length - 2)); var wmsResponse = JsonConvert.DeserializeObject(feedback); CMMLog.Info($"{wmsResponse.Success}"); if (wmsResponse.Success == true) { //var ok = wmsResponse.Data[0]; msg = "【调用wms解绑空托缓存位】成功!返回结果=" + wmsResponse.Success + ";调用WebUrl=" + url + ";输入参数=" + msgData; } else { string errMsg = wmsResponse.Msg; msg = "【调用wms解绑空托缓存位】失败!错误原因=" + errMsg + ";调用WebUrl=" + url + ";输入参数=" + msgData; } result = wmsResponse.Success; } else { string errMsg = "参数反馈空值"; msg = "【调用wms解绑空托缓存位】失败!错误原因=" + errMsg + ";调用WebUrl=" + url + ";输入参数=" + msgData; } } catch (Exception e) { CMMLog.Error(string.Format("【调用wms获取出库货位失败】异常{0}", e.Message), e); msg = "【调用wms解绑空托缓存位】失败!解析返回值出错=" + feedback + ";调用WebUrl=" + url + ";输入参数=" + msgData; } } else msg = string.Format("调用wms失败,ams工作中心没有设置!"); CMMLog.Info(msg); //Console.WriteLine(msg); return result; } public class WmsResModel { public bool success { get; set; } public string errCode { get; set; } public string errMsg { get; set; } public string location { get; set; } } } }