using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Text;
|
using System.Threading.Tasks;
|
using HH.WCS.Mobox3.YNJT_PT.util;
|
using HH.WCS.Mobox3.YNJT_PT.wms;
|
using Newtonsoft.Json;
|
using static HH.WCS.Mobox3.YNJT_PT.api.ApiModel;
|
|
namespace HH.WCS.Mobox3.YNJT_PT.dispatch
|
{
|
public class WCSDispatch
|
{
|
private static readonly HttpHelper apiHelper = new HttpHelper();
|
private static readonly string baseUrl = "http://192.168.1.99:2000/";
|
|
|
internal static string GenerateReqId()
|
{
|
var id = SYSHelper.GetSerialNumber("请求ID", "RE");
|
var date = DateTime.Now.ToString("yyMMdd");
|
return $"{date}{id.ToString().PadLeft(4, '0')}";
|
}
|
|
/// <summary>
|
/// 任务下发
|
/// </summary>
|
/// <param name="model"></param>
|
/// <returns></returns>
|
public static bool sendTask(SendTaskModel model)
|
{
|
var result = false;
|
model.reqId = GenerateReqId();
|
model.reqTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
|
var request = JsonConvert.SerializeObject(model);
|
try
|
{
|
var response = apiHelper.Post(baseUrl + "/sendTask", request);
|
LogHelper.Info($"[WCS-sendTask] request={request} response={response}", "WMS");
|
if (response != null && response != "")
|
{
|
var dataResult = JsonConvert.DeserializeObject<ResponseResult>(response);
|
if (dataResult.code == 200)
|
{
|
result = true;
|
}
|
else
|
{
|
LogHelper.Info($"调用WCS任务下发接口成功,但WCS反馈下发任务失败,失败原因:{dataResult.msg}", "WMS");
|
}
|
}
|
else
|
{
|
LogHelper.Info("调用WCS任务下发接口失败", "WMS");
|
}
|
}
|
catch (Exception ex)
|
{
|
LogHelper.Info($"调用WCS任务下发接口错误,错误原因:{ex.Message}", "WMS");
|
}
|
return result;
|
}
|
|
/// <summary>
|
/// 任务取消(任务执行中不允许取消)
|
/// </summary>
|
/// <param name="model"></param>
|
/// <returns></returns>
|
public static bool cancelTask(CancelTaskModel model)
|
{
|
var result = false;
|
model.reqId = GenerateReqId();
|
model.reqTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
|
var request = JsonConvert.SerializeObject(model);
|
try
|
{
|
var response = apiHelper.Post(baseUrl + "/api/hecWms/produceProcessTracing/trayMaterialUnBind", request);
|
LogHelper.Info($"[WCS-cancelTask] request={request} response={response}", "WMS");
|
if (response != null && response != "")
|
{
|
|
var dataResult = JsonConvert.DeserializeObject<ResponseResult>(response);
|
if (dataResult.code == 200)
|
{
|
result = true;
|
}
|
|
}
|
else
|
{
|
LogHelper.Info("调用WCS任务取消接口失败", "WMS");
|
}
|
}
|
catch (Exception ex)
|
{
|
LogHelper.Info($"调用WCS任务取消接口错误,错误原因:{ex.Message}", "WMS");
|
}
|
return result;
|
}
|
|
/// <summary>
|
/// 获取设备状态
|
/// </summary>
|
/// <param name="deviceNoList"></param>
|
/// <returns></returns>
|
public static List<DeviceStatusData> getDeviceStatus(List<string> deviceNoList)
|
{
|
List<DeviceStatusData> deviceStatusDatas = new List<DeviceStatusData>();
|
|
DeviceStatusModel model = new DeviceStatusModel()
|
{
|
reqId = GenerateReqId(),
|
reqTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
|
deviceNoList = deviceNoList
|
};
|
|
var request = JsonConvert.SerializeObject(model);
|
try
|
{
|
var response = apiHelper.Post(baseUrl + "/api/hecWms/produceProcessTracing/trayMaterialUnBind", request);
|
LogHelper.Info($"[WCS-getDeviceStatus] request={request} response={response}", "WMS");
|
if (response != null && response != "")
|
{
|
|
var dataResult = JsonConvert.DeserializeObject<ResponseResult>(response);
|
if (dataResult.code == 200)
|
{
|
deviceStatusDatas = JsonConvert.DeserializeObject<List<DeviceStatusData>>(response);
|
}
|
|
}
|
else
|
{
|
LogHelper.Info("调用WCS获取设备状态接口失败", "WMS");
|
}
|
}
|
catch (Exception ex)
|
{
|
LogHelper.Info($"调用WCS获取设备状态接口错误,错误原因:{ex.Message}", "WMS");
|
}
|
return deviceStatusDatas;
|
}
|
|
/// <summary>
|
/// 修改任务优先级
|
/// </summary>
|
/// <param name="model"></param>
|
/// <returns></returns>
|
public static bool changePriority(ChangePriorityModel model)
|
{
|
var result = false;
|
model.reqId = GenerateReqId();
|
model.reqTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
|
var request = JsonConvert.SerializeObject(model);
|
try
|
{
|
var response = apiHelper.Post(baseUrl + "/api/hecWms/produceProcessTracing/trayMaterialUnBind", request);
|
LogHelper.Info($"[WCS-changePriority] request={request} response={response}", "WMS");
|
if (response != null && response != "")
|
{
|
|
var dataResult = JsonConvert.DeserializeObject<ResponseResult>(response);
|
if (dataResult.code == 200)
|
{
|
result = true;
|
}
|
|
}
|
else
|
{
|
LogHelper.Info("调用WCS修改任务优先级接口失败", "WMS");
|
}
|
}
|
catch (Exception ex)
|
{
|
LogHelper.Info($"调用WCS修改任务优先级接口错误,错误原因:{ex.Message}", "WMS");
|
}
|
return result;
|
}
|
|
/// <summary>
|
/// AGV安全交互
|
/// </summary>
|
/// <param name="req_no"></param>
|
/// <param name="locCode"></param>
|
/// <param name="type"></param>
|
/// <returns></returns>
|
public static bool safetyInteraction(string req_no, string locCode, string type)
|
{
|
var result = false;
|
LocStateModel model = new LocStateModel()
|
{
|
req_no = req_no,
|
loc_code = locCode,
|
type = type
|
};
|
|
var request = JsonConvert.SerializeObject(model);
|
try
|
{
|
var response = apiHelper.Post(baseUrl + "/api/hecWms/produceProcessTracing/trayMaterialUnBind", request);
|
LogHelper.Info($"[WCS-changePriority] request={request} response={response}", "WMS");
|
if (response != null && response != "")
|
{
|
|
var dataResult = JsonConvert.DeserializeObject<ResponseResult>(response);
|
if (dataResult.code == 200)
|
{
|
result = true;
|
}
|
}
|
else
|
{
|
LogHelper.Info("调用WCS安全请求接口失败", "AGV");
|
}
|
}
|
catch (Exception ex)
|
{
|
LogHelper.Info($"调用WCS安全请求接口错误,错误原因:{ex.Message}", "AGV");
|
}
|
return result;
|
}
|
|
|
public class LocStateModel
|
{
|
public string req_no { get; set; } // 请求id
|
public string loc_code { get; set; } // 货位
|
public string type { get; set; } // 货位 1 请求取货 2 请求放货 3 取货完成离开信号 4 放货完成离开信号
|
}
|
|
public class ChangePriorityModel
|
{
|
public string reqId { get; set; } // 请求id
|
public string reqTime { get; set; } // 请求时间
|
public string taskNo { get; set; } // 任务号
|
public int priority { get; set; } // 优先级
|
}
|
|
public class DeviceStatusData
|
{
|
public string deviceNo { get; set; } // 设备号
|
public int workStatus { get; set; } // 工作状态 1正常 ,2禁用 ,3故障
|
public int photoStatus { get; set; } // 光电状态 1是空载 ,2是有载
|
public int manualStatus { get; set; } //手动状态 1手动,2自动
|
}
|
|
public class DeviceStatusModel
|
{
|
public string reqId { get; set; } // 请求id
|
public string reqTime { get; set; } // 请求时间
|
public List<string> deviceNoList { get; set; } // 设备号
|
}
|
|
public class CancelTaskModel
|
{
|
public string reqId { get; set; } // 请求id
|
public string reqTime { get; set; } // 请求时间
|
public string taskNo { get; set; } // 任务号
|
}
|
|
public class SendTaskModel
|
{
|
public string reqId { get; set; } // 请求id
|
public string reqTime { get; set; } // 请求时间
|
public string taskNo { get; set; } // 任务号
|
public int groupNo { get; set; } // 任务组
|
public string taskType { get; set; } // 任务类型 1.物料入库 2.物料出库
|
public string from { get; set; } // 起点
|
public string to { get; set; } // 终点
|
public string cntrNo { get; set; } // 容器编码
|
public string cntrType { get; set; } // 容器类型
|
public List<object> extData { get; set; } //
|
|
}
|
}
|
}
|