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.Linq;
|
using System.Security.Cryptography;
|
using System.Text;
|
using System.Threading.Tasks;
|
using static Hanhe.iWCS.IndonesiaGLMProtocol.ERPService;
|
using static Hanhe.iWCS.IndonesiaGLMProtocol.MESHelper;
|
using static System.Runtime.CompilerServices.RuntimeHelpers;
|
|
namespace Hanhe.iWCS.IndonesiaGLMProtocol
|
{
|
public class WMSHelper
|
{
|
private static WebApiHelper helper = new WebApiHelper();
|
private static T WmsRequest<T>(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<T>(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<BaseResponse>("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; }
|
/// <summary>
|
/// 托盘码
|
/// </summary>
|
public string trayCode { get; set; }
|
public List<ItemData> data { get; set; }
|
//public List<TimeData> 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 List<ItemData> 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 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<TaskInfo> Data { get; set; }
|
public int AffectedRows { get; set; }
|
|
public bool Success { get; set; }
|
//public List<TaskInfo> failList { get; set; }
|
//public List<TaskInfo> 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 设备通道信息
|
|
/// <summary>
|
/// 设备通道数据3——托盘码
|
/// </summary>
|
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<TaskInfo> Data { get; set; }
|
public int AffectedRows { get; set; }
|
|
public bool Success { get; set; }
|
//public List<TaskInfo> failList { get; set; }
|
//public List<TaskInfo> 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 设备通道信息
|
|
/// <summary>
|
/// 设备通道数据3——托盘码
|
/// </summary>
|
public string trayCode { get; set; }
|
|
#endregion
|
}
|
}
|
public class ItemData
|
{
|
//托盘尺寸:trayDimension
|
//物料编号:itemCode
|
//物料数量:qty
|
public string itemCode { 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; }
|
|
/// <summary>
|
/// 是否叠底托(1-不叠底托 2-叠底托)
|
/// </summary>
|
public string palletLayers { get; set; }
|
|
public int qty { get; set; }
|
|
#region MES传输的数据
|
//传输MES信息以及设备信息给WMS
|
/// <summary>
|
/// mes返回的包装机号(T1,T2,......,T9)
|
/// </summary>
|
public string machineNo { get; set; }
|
/// <summary>
|
/// mes返回的成品批次号
|
/// </summary>
|
public string lotNo { get; set; }
|
/// <summary>
|
/// mes返回的袋号
|
/// </summary>
|
//public string bagNo { get; set; }
|
/// <summary>
|
/// mes返回的产品型号
|
/// </summary>
|
//public string productType { get; set; }
|
/// <summary>
|
/// mes返回的物料编码
|
/// </summary>
|
//public string materialCode { get; set; }
|
/// <summary>
|
/// mes返回的叠包层数 (例1,2,3:1代表不叠包,2代表叠2层,3代表叠3层)
|
/// </summary>
|
public string foldingbag { get; set; }
|
#endregion
|
|
#region 设备通道信息
|
|
/// <summary>
|
/// 设备通道数据3——托盘码
|
/// </summary>
|
//public string trayCode { get; set; }
|
/// <summary>
|
/// 设备通道数据1——包装机号
|
/// </summary>
|
//public string location { get; set; }
|
/// <summary>
|
/// 设备通道数据2——产品需求重量:32位整数
|
/// </summary>
|
public string productWeight { get; set; }
|
/// <summary>
|
/// 设备通道数据2——托盘重量:32位整数
|
/// </summary>
|
public string trayCodeWeight { get; set; }
|
/// <summary>
|
/// 设备通道数据2——单托实际重量:32位整数
|
/// </summary>
|
public string oneTrayWeight { get; set; }
|
/// <summary>
|
/// 设备通道数据2——叠包后实际重量:32位整数
|
/// </summary>
|
//public string addWeight { get; set; }
|
/// <summary>
|
/// 设备通道数据1——包装机出口称重结果:1:OK,2:NG
|
/// </summary>
|
//public int packNg { get; set; }
|
/// <summary>
|
/// 设备通道数据1——复称口称重结果:1:OK,2:NG
|
/// </summary>
|
public int itemState { get; set; }
|
/// <summary>
|
/// 设备通道数据1——是否需要叠包:1:叠包,2:不叠包
|
/// </summary>
|
//public int addState { get; set; }
|
/// <summary>
|
/// 设备通道数据1——袋号(001,002,003…999)
|
/// </summary>
|
public string packageCode { get; set; }
|
|
#endregion
|
|
#region 时间戳信息
|
/// <summary>
|
/// 是否叠包(1,2,3)
|
/// </summary>
|
public int isFold { get; set; } = 0;
|
/// <summary>
|
/// 包装机号
|
/// </summary>
|
public int packingMachineNumber { get; set; }
|
/// <summary>
|
/// 袋号(001,002,003…999)1
|
/// </summary>
|
public string bagNumber { get; set; }
|
/// <summary>
|
/// 产品需求重量1:32位整数
|
/// </summary>
|
public int needWeight { get; set; }
|
/// <summary>
|
/// 单托实际重量1:32位整数
|
/// </summary>
|
public int realWeight { get; set; }
|
/// <summary>
|
/// 叠托后的实际重量:32位整数
|
/// </summary>
|
public int totalWeight { get; set; }
|
/// <summary>
|
/// 产品批次号
|
/// </summary>
|
public string batchNumber { get; set; }
|
/// <summary>
|
/// 产品型号
|
/// </summary>
|
public string productModel { get; set; }
|
/// <summary>
|
/// 计数(只在数据库)
|
/// </summary>
|
public int totalCount { get; set; }
|
/// <summary>
|
/// 时间戳
|
/// </summary>
|
public int timeStamp { get; set; }
|
/// <summary>
|
/// 照片url
|
/// </summary>
|
public string photoURL { get; set; }
|
#endregion
|
|
#region WMS显示信息
|
/// <summary>
|
/// 物料编码
|
/// </summary>
|
public string Jm_Item_Code { get; set; }
|
/// <summary>
|
/// 物料名称
|
/// </summary>
|
public string Jm_Item_Name { get; set; }
|
/// <summary>
|
/// 规格型号
|
/// </summary>
|
public string Jm_Item_Model { get; set; }
|
/// <summary>
|
/// 单位
|
/// </summary>
|
public string Jm_Item_Unit { get; set; }
|
/// <summary>
|
/// 员工
|
/// </summary>
|
public string Jm_Item_Staff { 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<ItemData>();
|
model.locationGear = "";
|
if (!string.IsNullOrEmpty(ItemCode)) {
|
CMMLog.Info($"WMSIn-{startBit}:ItemCode不为空,获取信息!111!");
|
CMMLog.Info($"{ItemCode}");
|
//var time = MongoDBSingleton.Instance.FindOne<TimeCuoInfoCom>(Query.Or(Query.EQ("isNeedTray", 1), Query.EQ("isNeedTray", 2)), "TimeCuoInfoCom");
|
if (ItemCode == "time" || ItemCode == "拆盘变更" || ItemCode == "打包下线")
|
{
|
CMMLog.Info($"{trayCode}");
|
var time = MongoDBSingleton.Instance.FindOne<TimeCuoInfoCom>(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,
|
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<TimeCuoInfoCom>(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(timeStamp) ? time.timeStamp : int.Parse(timeStamp);
|
List<string> 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,
|
lotNo = time.batchNumber,
|
qty = time.needWeight,
|
machineNo = time.packingMachineNumber.ToString(),
|
isFold = time.isFold,
|
packageCode = time.bagNumber,
|
needWeight = time.needWeight,
|
realWeight = time.realWeight,
|
totalWeight = time.totalWeight,
|
batchNumber = batch,
|
productModel = time.productModel,
|
totalCount = time.totalCount,
|
timeStamp = TimeStamp,
|
photoURL = time.photoURL
|
}) ;
|
|
//将数据插入中间表
|
ERPService.senderpTask(time, startBit);
|
}
|
}
|
else
|
{
|
var info = MongoDBSingleton.Instance.FindOne<MachineInfo>(Query.EQ("trayCode", ItemCode), "MachineInfo");
|
// ERP变更新增数据直接从 ERP物料中间表-ERPItemTable 获取(根据物料编码)
|
//CMMLog.Info($"WMSIn-{startBit}:查询条件:trayCode={ItemCode},读出 MachineInfo 表数据为:{JsonConvert.SerializeObject(info)}");
|
|
//var info = MongoDBSingleton.Instance.FindOne<MachineInfo>(Query.EQ("trayCode", ItemCode), "MachineInfo");
|
if (info != null)
|
{
|
//var erpItemTableInfo = MongoDBSingleton.Instance.FindOne<ERPItemTable>(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;
|
//string product = !string.IsNullOrEmpty(info.productType) ? info.productType : erpItemTableInfo.item_spec;
|
model.data.Add(new ItemData()
|
{
|
itemCode = info.materialCode,
|
qty = int.Parse(info.productWeight), //重量
|
//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,
|
|
//Jm_Item_Code = info.materialCode,
|
//Jm_Item_Name = erpItemTableInfo.item_name,
|
//Jm_Item_Model = erpItemTableInfo.item_spec,
|
//Jm_Item_Unit = erpItemTableInfo.item_uom,
|
//Jm_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<WMSResponseModel>(feedback.Substring(1, feedback.Length - 2));
|
var wmsResponse = JsonConvert.DeserializeObject<WMSResponseModel>(feedback);
|
//var res = feedback.Replace("{", "").Replace("}", "").Replace(":", "=").Replace(",", ";").Replace('"', ' ');
|
if (wmsResponse.Success == true) {
|
if (ItemCode == "打包下线") MongoDBSingleton.Instance.Remove<TimeCuoInfoCom>(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) {
|
//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.Data = new List<ItemData>();
|
//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<WMSResponseModel>(feedback.Substring(1, feedback.Length - 2));
|
var wmsResponse = JsonConvert.DeserializeObject<WMSResponseModel>(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, 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";
|
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<WMSResponseModel>(feedback.Substring(1, feedback.Length - 2));
|
var wmsResponse = JsonConvert.DeserializeObject<WMSResponseModel>(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;
|
}
|
|
|
/// <summary>
|
/// 改道接口
|
/// </summary>
|
/// <param name="taskNo">WMS任务号</param>
|
/// <param name="changeArea">改道库区</param>
|
/// <returns></returns>
|
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;
|
}
|
|
/// <summary>
|
/// WebPost
|
/// </summary>
|
/// <param name="param">发送内容</param>
|
/// <param name="postName">接口名称</param>
|
/// <param name="Par1">扩展参数</param>
|
/// <returns></returns>
|
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<WmsResModel>(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<WMSResponseModel>(feedback.Substring(1, feedback.Length - 2));
|
|
var wmsResponse = JsonConvert.DeserializeObject<WMSResponseModel1>(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; }
|
|
}
|
}
|
}
|