using iWareCommon.Utils;
|
using iWareModel.Entity.AGV;
|
using iWareModel.Entity.MES;
|
using iWareModel.Entity.WCS;
|
using iWareModel.Entity.WMS;
|
using Newtonsoft.Json;
|
using System;
|
using System.Dynamic;
|
using System.Net.Http;
|
using System.Windows.Forms;
|
|
namespace iWareCC.Common.Helper
|
{
|
/// <summary>
|
/// 跟WMS交互的帮助类
|
/// </summary>
|
public class WMSRequestHelper
|
{
|
/// <summary>
|
/// WMS的主机host
|
/// </summary>
|
private static string wmsApiHost = ConfigHelper.GetConfigString("WmsApiHost");
|
private static HttpClient _httpClient = null;
|
private static string base_Path = wmsApiHost;
|
/// <summary>
|
/// 3巷道寻找空库位,用途:移库任务、入库任务
|
/// </summary>
|
/// <param name="high">货物高度</param>
|
/// <param name="containerCode">要处理的托盘号</param>
|
/// <param name="flag">标记,0:正常入库 1:移库</param>
|
/// <returns></returns>
|
/// <exception cref="Exception"></exception>
|
public static CriterionContainerOutput FindEmptyLocationForLane3(int high, string containerCode, int flag)
|
{
|
var flagName = flag == 1 ? "移库任务" : "入库任务";
|
var logTitle = $"[{flagName}],容器号{containerCode},高度{high}。";
|
var utl = string.Format(@"task/FindEmptyLocationForLane3?high={0}&containerCode={1}&flag={2}", high, containerCode, flag);
|
var result = new HTTPService(wmsApiHost).postContentForString(utl, "", "");
|
|
if (result == null)
|
{
|
throw new Exception(logTitle + "创建失败!");
|
}
|
Log4NetHelper.WriteErrorLog(LogType.CCWCFService, logTitle + "FindEmptyLocationForLane3 返回的值:" + result + ",参数:high:" + high
|
+ ",参数:containerCode:" + containerCode + ",参数:flag:" + flag + ",地址:" + wmsApiHost + "/task/FindEmptyLocationForLane3");
|
|
var wmsSysReturn = JsonConvert.DeserializeObject<WmsSysReturn>(result);
|
if (wmsSysReturn.success == false)
|
{
|
throw new Exception(logTitle + "请求WMS失败!" + wmsSysReturn.message);
|
}
|
if (wmsSysReturn.data == null)
|
{
|
return null;
|
}
|
var data = JsonConvert.DeserializeObject<CriterionContainerOutput>(wmsSysReturn.data.ToString());
|
return data;
|
}
|
|
/// <summary>
|
/// Post请求
|
/// </summary>
|
/// <typeparam name="TResult">返回参数的数据类型</typeparam>
|
/// <param name="url">请求地址</param>
|
/// <param name="data">传入的数据</param>
|
/// <returns></returns>
|
public static TResult Post<TResult>(string url, object data)
|
{
|
try
|
{
|
_httpClient = new HttpClient();
|
_httpClient.BaseAddress = new Uri(base_Path);
|
|
var jsonData = JsonConvert.SerializeObject(data);
|
HttpContent content = new StringContent(jsonData);
|
content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json");
|
HttpResponseMessage res = _httpClient.PostAsync(url, content).Result;
|
if (res.StatusCode == System.Net.HttpStatusCode.OK)
|
{
|
string resMsgStr = res.Content.ReadAsStringAsync().Result;
|
var result = JsonConvert.DeserializeObject<TResult>(resMsgStr);
|
return result;
|
}
|
else
|
{
|
MessageBox.Show(res.StatusCode.ToString());
|
return default;
|
}
|
}
|
catch (Exception ex)
|
{
|
MessageBox.Show(ex.Message);
|
return default;
|
}
|
}
|
}
|
}
|