using Hanhe.iWCS.Business;
|
using Hanhe.iWCS.Common;
|
using Hanhe.iWCS.DeviceDriver;
|
using Hanhe.iWCS.MData;
|
using Hanhe.iWCS.Model;
|
using MongoDB.Bson;
|
using MongoDB.Driver;
|
using MongoDB.Driver.Builders;
|
using Newtonsoft.Json;
|
using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Text;
|
using System.Threading.Tasks;
|
|
namespace Hanhe.iWCS.TaizhouGEMTwoProtocol
|
{
|
public class AMSHelper
|
{
|
|
public static HHAmsExecuteResult CreateTask(string taskNo, string locationFrom, string locationTo, string type, int priorityNo, string batchNo = "",string timeStamp = "") {
|
var result = new HHAmsExecuteResult();
|
List<HHAmsTaskEntity> entities = new List<HHAmsTaskEntity>();
|
HHAmsTaskEntity entity = new HHAmsTaskEntity();
|
entity.batchNo = batchNo;
|
entity.taskNo = taskNo;
|
entity.businessType = type;
|
entity.locationFrom = locationFrom;
|
entity.locationTo = locationTo;
|
entity.priority = priorityNo;
|
entity.ext2 = timeStamp;
|
entity.deviceName = "AMS";
|
entity.sysName = "AMS";
|
entities.Add(entity);
|
|
result = AddTask(entities);
|
|
return result;
|
}
|
public static HHAmsExecuteResult AddTask(List<HHAmsTaskEntity> data) {
|
HardwareAccessObject hao = HardwareAccessHelper.Instance.GetEquipmentsHAO(Constants.WMS_DEVICE_TYPE_AMS);
|
//string url = "http://10.15.73.28:9435/api/AmsInf/"; //正式环境需要改回去
|
string msg = "";
|
string feedback = "";
|
|
var param = JsonConvert.SerializeObject(data);
|
HHAmsExecuteResult amsResponse = new HHAmsExecuteResult() ;
|
if (hao != null) {
|
//if (string.IsNullOrEmpty(url)) {
|
try {
|
string webAPIUrl = hao._WebApiClientInstance.WebApiUrl.Replace("AmsInf", "HHAms") + "AddTask";
|
//string webAPIUrl = url.Replace("AmsInf", "HHAms") + "AddTask";
|
Console.WriteLine(webAPIUrl);
|
feedback = new WebApiHelper().WebPost(webAPIUrl, param);
|
if (!string.IsNullOrEmpty(feedback)) {
|
amsResponse = JsonConvert.DeserializeObject<HHAmsExecuteResult>(feedback);
|
//var res = feedback.Replace("{", "").Replace("}", "").Replace(":", "=").Replace(",", ";").Replace('"', ' ');
|
if (amsResponse.success == true) {
|
msg = "【ams create task】success!;WebUrl=" + hao.WebUrl + "AmsInf/AddTask;param=" + param;
|
}
|
else {
|
string errMsg = amsResponse.errMsg;
|
msg = "【ams create task】fail!err=" + errMsg + ";WebUrl=" + webAPIUrl + ";param=" + param;
|
}
|
}
|
else {
|
string errMsg = "can't find the address";
|
msg = "【ams create task】fail!err=" + errMsg + ";WebUrl=" + webAPIUrl + ";param=" + param;
|
}
|
}
|
catch (Exception e) {
|
CMMLog.Error(string.Format("【ams create task】fail!err={0}", e.Message), e);
|
}
|
}
|
else {
|
msg = string.Format("ams create task fail,ams workcenter not set!");
|
}
|
if (msg != "") {
|
CMMLog.Info(msg);
|
}
|
return amsResponse;
|
|
//{"Success":false,"ErrorCode":"1","FailList":[{"Agv_TaskNo":"sample string 5","Error_Code":"1","Err_Msg":"未配置相关设备的事件解释!"},{"Agv_TaskNo":"sample string 5","Error_Code":"1","Err_Msg":"未配置相关设备的事件解释!"},{"Agv_TaskNo":"sample string 5","Error_Code":"1","Err_Msg":"未配置相关设备的事件解释!"}]}
|
}
|
|
/// <summary>
|
/// 创建任务
|
/// </summary>
|
/// <param name="jasonStr"></param>
|
/// <returns></returns>
|
private static bool CreateAMSTask(string jasonStr) {
|
bool bResult = false;
|
HardwareAccessObject AMSCreateHao = HardwareAccessHelper.Instance.GetEquipmentsHAO(Constants.WMS_DEVICE_TYPE_AMS);
|
if (AMSCreateHao != null) {
|
try {
|
string webAPIUrl = AMSCreateHao._WebApiClientInstance.WebApiUrl.Replace("AmsInf", "HHAms");
|
string amsReturnValue = AMSCreateHao._WebApiClientInstance.GetWebRequest(webAPIUrl + "AddTask", jasonStr, "application/json");
|
var dynamicObject = JsonConvert.DeserializeObject<dynamic>(amsReturnValue);
|
if (dynamicObject.success == "True" || dynamicObject.success == "true") {
|
bResult = true;
|
CMMLog.Info("AMS任务创建成功;请求参数=" + jasonStr + "");
|
}
|
else {
|
CMMLog.Info("AMS任务创建失败;请求参数=" + jasonStr + "");
|
}
|
}
|
catch (Exception ex) {
|
CMMLog.Info("AMS任务创建异常;请求参数=" + jasonStr + ";Exception=" + ex.Message);
|
}
|
}
|
return bResult;
|
}
|
|
/// <summary>
|
/// 变更任务目的地
|
/// </summary>
|
/// <param name="jasonStr"></param>
|
/// <returns></returns>
|
public static bool ChangeTaskTargetBit(string jasonStr) {
|
bool bResult = false;
|
HardwareAccessObject AMSCreateHao = HardwareAccessHelper.Instance.GetEquipmentsHAO(Constants.WMS_DEVICE_TYPE_AMS);
|
if (AMSCreateHao != null) {
|
try {
|
string amsReturnValue = AMSCreateHao._WebApiClientInstance.GetWebRequest(AMSCreateHao._WebApiClientInstance.WebApiUrl + "ChangeTaskTargetBit", jasonStr, "application/json");
|
var dynamicObject = JsonConvert.DeserializeObject<dynamic>(amsReturnValue);
|
if (dynamicObject.Success == "True" || dynamicObject.Success == "true") {
|
bResult = true;
|
CMMLog.Info("AMS变更任务目的地成功;请求参数=" + jasonStr + "");
|
}
|
else {
|
CMMLog.Info("AMS变更任务目的地失败;请求参数=" + jasonStr + "");
|
}
|
}
|
catch (Exception ex) {
|
CMMLog.Info("AMS变更任务目的地异常;请求参数=" + jasonStr + ";Exception=" + ex.Message);
|
}
|
}
|
return bResult;
|
}
|
|
/// <summary>
|
/// 反馈AMS的状态
|
/// </summary>
|
/// <param name="taskNo"></param>
|
/// <param name="orderNo"></param>
|
/// <param name="actionCode"></param>
|
public static void SetStatus(string taskNo, int orderNo, string actionCode, string forkliftNo, bool success = false) {
|
HardwareAccessObject AMSHao = HardwareAccessHelper.Instance.GetEquipmentsHAO(Constants.WMS_DEVICE_TYPE_AMS);
|
if (AMSHao != null)
|
{
|
// if (actionCode == "2")
|
// {
|
//actionCode = "完成";
|
// }
|
string data = "{\"TaskNo\":\"" + taskNo + "\",\"OrderIndex\":\"" + orderNo + "\",\"TaskStatus\":\"" + actionCode + "\",\"ForkliftNo\":\"" + forkliftNo + "\",\"Success\":\"" + success + "\",\"ErrorMsg\":\"\"}";
|
CMMLog.Debug(data);
|
//string resultCode = AMSHao._WebApiClientInstance.GetWebRequest(AMSHao._WebApiClientInstance.WebApiUrl + "SetStatus?jsonData=" + data);
|
WebApiHelper api = new WebApiHelper();
|
api.WebPost(AMSHao._WebApiClientInstance.WebApiUrl + "SetStatus?jsonData=" + data, "");
|
}
|
}
|
|
/// <summary>
|
/// 消息交互日志
|
/// </summary>
|
/// <param name="taskNo"></param>
|
/// <param name="orderNo"></param>
|
/// <param name="cmd"></param>
|
/// <param name="statusText"></param>
|
/// <param name="success"></param>
|
/// <param name="errMsg"></param>
|
/// <param name="createUser"></param>
|
/// <param name="createUserName"></param>
|
public static void TaskTrackLogMessage(string taskNo, string orderNo, string cmd, string statusText, string remark = "") {
|
HardwareAccessObject AMSHao = HardwareAccessHelper.Instance.GetEquipmentsHAO(Constants.WMS_DEVICE_TYPE_AMS);
|
if (AMSHao != null) {
|
string data = "{\"CN_N_ORDER\":\"" + orderNo + "\",\"CN_S_CMD\":\"" + cmd + "\",\"CN_S_CREATOR\":\"wcs\",\"CN_S_CREATOR_NAME\":\"wcs\",\"CN_S_SUCCESS\":\"true\",\"CN_S_TASK_NO\":\"" + taskNo + "\",\"CN_S_TASK_STATUS\":\"" + statusText + "\",\"CN_S_ERROR\":\"" + remark + "\"}";
|
string resultCode = AMSHao._WebApiClientInstance.GetWebRequest(AMSHao._WebApiClientInstance.WebApiUrl + "TaskTrackLogMessage?jsonData=" + data);
|
}
|
}
|
|
|
|
public static void ChangeEndBitNew(TN_I_TASK_MST mstTask, out int agvBit) {
|
string newEndBitCode = mstTask.CN_S_END_BIT;
|
agvBit = StockInstance.Instance.GetAGVCodeForBitCode(newEndBitCode);
|
UpdateEndBit(mstTask, newEndBitCode, agvBit);
|
}
|
private static void UpdateEndBit(TN_I_TASK_MST mstTask, string newEndBitCode, int agvBit) {
|
var updateBuider = Update.Set("CN_S_END_BIT", newEndBitCode);//新目的地
|
updateBuider = updateBuider.Set("CN_N_END_AGV_BIT", agvBit);
|
MongoDBSingleton.Instance.Update<TN_I_TASK_DTL>(Query.EQ("CN_S_TASK_NO", mstTask.CN_S_TASK_NO), updateBuider, UpdateFlags.None);
|
var query = Query.EQ("_id", mstTask._id);
|
updateBuider = Update.Set("CN_S_END_BIT", newEndBitCode).Set("Ext3", "J2SSHB199");
|
updateBuider = updateBuider.Set("CN_S_END_AGVBIT", agvBit.ToString());
|
MongoDBSingleton.Instance.Update<TN_I_TASK_MST>(query, updateBuider, UpdateFlags.None);
|
}
|
|
|
public class HHAmsTaskEntity
|
{
|
//public List<TransportInfo> transportInfo { get; set; }
|
public string batchNo { get; set; }
|
public string businessType { get; set; }
|
public string sysName { get; set; }
|
public string deviceName { get; set; }
|
public string taskNo { get; set; }
|
public string locationFrom { get; set; }
|
public string locationTo { get; set; }
|
public int priority { get; set; }
|
public string ext1 { get; set; }
|
public string ext2 { get; set; }
|
public string ext3 { get; set; }
|
//public class TransportInfo {
|
// /// <summary>
|
// /// 物料编码
|
// /// </summary>
|
// public string itemCode { get; set; }
|
|
// /// <summary>
|
// /// 物料扩展编码
|
// /// </summary>
|
// public string itemPCode { get; set; }
|
|
// /// <summary>
|
// /// 物料名称
|
// /// </summary>
|
// public string itemName { get; set; }
|
|
// /// <summary>
|
// /// 托盘码
|
// /// </summary>
|
// public string trayCode { get; set; }
|
|
// /// <summary>
|
// /// 物料重量
|
// /// </summary>
|
// public string itemWeight { get; set; }
|
|
// /// <summary>
|
// /// 物料特征
|
// /// </summary>
|
// public string itemFeatures { get; set; }
|
//}
|
|
}
|
public class HHAmsExecuteResult
|
{
|
public bool success { get; set; }
|
/// <summary>
|
/// 0:成功 1:数据异常 2:已存在任务 3:程序异常
|
/// </summary>
|
public string errCode { get; set; }
|
public string errMsg { get; set; }
|
|
private List<HHAmsAddTaskResult> _failList = new List<HHAmsAddTaskResult>();
|
public List<HHAmsAddTaskResult> failList {
|
get { return _failList; }
|
set { _failList = value; }
|
}
|
}
|
public class HHAmsAddTaskResult
|
{
|
public string taskNo { get; set; }
|
public string errCode { get; set; }
|
public string errMsg { get; set; }
|
}
|
public class WMSResponseModel
|
{
|
//{"success":false,"errCode":null,"errMsg":"算法返回结果库存不足","okList":[],"failList":[{"index":0,"errCode":null,"errMsg":"算法返回结果库存不足"}],"tasks":[]}
|
public bool success { get; set; }
|
public string errMsg { get; set; }
|
public string errCode { get; set; }
|
//public OKInfo[] tasks { get; set; }
|
//public FailInfo[] failList { get; set; }
|
public OKInfo[] okList { get; set; }
|
public class FailInfo
|
{
|
public int index { get; set; }
|
public string errCode { get; set; }
|
public string errMsg { get; set; }
|
}
|
|
public class OKInfo
|
{
|
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; }
|
}
|
}
|
|
|
|
|
internal static void UpdatePriority(string taskNo, int priority) {
|
//http://localhost:60116/api/AmsInf/UpdatePriority?taskNo=12312313&priority=2
|
HardwareAccessObject AMSHao = HardwareAccessHelper.Instance.GetEquipmentsHAO(Constants.WMS_DEVICE_TYPE_AMS);
|
if (AMSHao != null) {
|
string data = string.Format("taskNo={0}&priority={1}", taskNo, priority);
|
CMMLog.Debug(data);
|
//string resultCode = AMSHao._WebApiClientInstance.GetWebRequest(AMSHao._WebApiClientInstance.WebApiUrl + "UpdatePriority?" + data);
|
WebApiHelper api = new WebApiHelper();
|
api.WebPost(AMSHao._WebApiClientInstance.WebApiUrl + "UpdatePriority?" + data, "");
|
}
|
}
|
}
|
}
|