using DBModel; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using System; using System.Collections.Generic; using XS_DAL; using XS_Model; namespace XS_BLL { /// /// 立库出库接口 /// public class WMS_REQUEST_OUT_BLL { public static string Wms_request_out(string recieveJson) { string data = UtilityBLL.GetReceiveValues(recieveJson, "data"); List rModelList = new List(); try { List modelList = UtilityBLL.GetReceiveValuesList(recieveJson, "data"); foreach (var item in modelList) { IO_CONTROL model = new IO_CONTROL(); T_RESULT rModdel = new T_RESULT(); #region 数据验证 if (string.IsNullOrEmpty(item.taskId)) { rModdel.code = "01"; rModdel.msg = "任务号不能为空!!!"; rModdel.taskId = item.taskId; rModelList.Add(rModdel); continue; } if (string.IsNullOrEmpty(item.containerCode)) { rModdel.code = "01"; rModdel.msg = "容器号不能为空!!!"; rModdel.taskId = item.containerCode; rModelList.Add(rModdel); continue; } if (string.IsNullOrEmpty(item.bankId)) { rModdel.code = "01"; rModdel.msg = "巷道号不能为空!!!"; rModdel.taskId = item.bankId; rModelList.Add(rModdel); continue; } if (string.IsNullOrEmpty(item.sourceAddress)) { rModdel.code = "01"; rModdel.msg = "源地址(起点货位)不能为空!!!"; rModdel.taskId = item.sourceAddress; rModelList.Add(rModdel); continue; } if (string.IsNullOrEmpty(item.targetAddress)) { rModdel.code = "01"; rModdel.msg = "目标地址(终点货位)不能为空!!!"; rModdel.taskId = item.targetAddress; rModelList.Add(rModdel); continue; } if (!string.IsNullOrEmpty(item.sourceAddress) && !string.IsNullOrEmpty(item.targetAddress)) { string staRTeTunnel = Global.deviceCell[item.sourceAddress]; string endTunnel = Global.deviceCell[item.targetAddress]; if (staRTeTunnel != endTunnel) { rModdel.code = "01"; rModdel.msg = "容器:" + item.containerCode + " 起始地址:" + item.sourceAddress + "与终止地址:" + item.targetAddress + "不在同一巷道内!!!"; rModdel.taskId = item.targetAddress; rModelList.Add(rModdel); continue; } } else { rModdel.code = "01"; rModdel.msg = "目标地址(起点/终点货位)不能为空!!!"; rModdel.taskId = item.targetAddress; rModelList.Add(rModdel); continue; } #endregion 数据验证 #region 数据赋值 model.CONTROL_ID = Convert.ToDecimal(item.taskId); model.RELATIVE_CONTROL_ID = -1; model.MANAGE_ID = 0; model.STOCK_BARCODE = item.containerCode; model.MANAGE_TASK_TYPE = "1"; model.CONTROL_TASK_TYPE = 2;//1:入库 2:出库 3:倒库 model.CONTROL_TASK_LEVEL = "10"; model.START_WAREHOUSE_CODE = "1"; model.START_DEVICE_CODE = item.sourceAddress; //model.END_WAREHOUSE_CODE = ""; model.END_DEVICE_CODE = item.targetAddress.ToString(); model.CONTROL_STATUS = 0; //model.ERROR_TEXT = ""; model.CONTROL_BEGIN_TIME = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); ; //model.CONTROL_END_TIME = ""; //model.CONTROL_REMARK = ""; //model.CONTORL_BATCH = ""; //model.LOGIC_AREA = ""; //model.CELL_MODEL = ""; //model.WORK_MODE = ""; //model.GOODS_BARCODE = ""; //model.GOODS_NUM = ""; #endregion 数据赋值 int rows = model.GetTable(" CONTROL_STATUS != 999 and (CONTROL_ID = " + model.CONTROL_ID + " or STOCK_BARCODE = '" + model.STOCK_BARCODE + "' ) ").Rows.Count; //是否已存在该托盘或任务号的任务 if (rows <= 0) { if (model.Insert()) { rModdel.code = "00"; rModdel.msg = "WCS接出库任务成功。"; rModdel.taskId = item.taskId; rModelList.Add(rModdel); continue; } else { rModdel.code = "01"; rModdel.msg = "WCS接收出库任务失败。"; rModdel.taskId = item.taskId; rModelList.Add(rModdel); continue; } } else { rModdel.code = "01"; rModdel.msg = "WCS已存在该条码/任务号未完成任务。"; rModdel.taskId = item.taskId; rModelList.Add(rModdel); continue; } } string retJSON = JsonConvert.SerializeObject( new { method = "wms_request_out", timestamp = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), data = rModelList }); #region 接口日志记录 IO_INTERFACE IModel = new IO_INTERFACE(); //IModel.INTERFACE_ID = ""; IModel.INTERFACE_NAME = "wms_request_out"; IModel.INTERFACE_FLOW = "WMS==>>WCS"; IModel.INTERFACE_REQUEST = recieveJson; IModel.INTERFACE_FEEDBACK = retJSON; IModel.INTERFACE_DATETIME = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); IModel.INTERFACE_MENO = ""; IModel.Insert(); LogHelper.LogOperation("wms_request_out", recieveJson, retJSON); new DisplaySet().AddListBoxItem("", ""); new DisplaySet().AddListBoxItem("出库接收:", recieveJson); new DisplaySet().AddListBoxItem("反馈:", retJSON); #endregion 接口日志记录 return retJSON; } catch (Exception ex) { new DisplaySet().ErrorAddListBoxItem("wms_request_out", ex.Message); new DisplaySet().AddListBoxItem("wms_request_out", ex.Message); T_RESULT rModdel = new T_RESULT(); rModdel.code = "01"; rModdel.msg = ex.Message; rModdel.taskId = ""; rModelList.Add(rModdel); string retJSON = JsonConvert.SerializeObject( new { method = "wms_request_out", timestamp = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), data = rModdel }); return retJSON; } } public class wms_request_out_Model { /// /// 任务号 /// public String taskId { get; set; } /// /// 容器号 /// public String containerCode { get; set; } /// /// 巷道号(18001-18004) /// public String bankId { get; set; } /// /// 货位地址(如01-03-03) /// public String sourceAddress { get; set; } /// /// 目标出库输送机编号 /// public String targetAddress { get; set; } /// /// 优先级 0-10 数字越大,优先级越高 /// public String tasklevel { get; set; } } } }