using Newtonsoft.Json; using Newtonsoft.Json.Linq; using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Text; using XS_DAL; using XS_Model; using static System.Windows.Forms.VisualStyles.VisualStyleElement.TaskbarClock; namespace XS_BLL { /// /// 码垛托盘申请 /// public class CONTAINER_QUERYSTATUS_BLL { #region 全局参数 /// /// 接口地址,请求路径 /// //public static string InterfaceAdd = Global.upper_WMSURL + "api/wcs/container/status";//请求路径 BarCodeAsk public static string InterfaceAdd = Global.upper_WMSURL + "BarCodeAsk";//请求路径 /// /// 接口名称,接口日志文件名 /// public static string InterfaceName = "BarCodeAsk"; /// /// 接口描述 /// public static string InterfaceNote = "拆盘托盘状态查询"; /// /// 接口流向 /// public static string InterfaceFlow = "WCS==>>WMS"; /// /// 请求JSON /// public static string reqJson = string.Empty; /// /// 反馈JSON /// public static string retJson = string.Empty; #endregion /// /// 测试--码垛托盘申请 /// /// public static string response_CONTAINER_QUERYSTATUS() { string json = JsonConvert.SerializeObject(new { code = 0, //调试时自行约定,只要类型对应接口,后面不做说明 success = true, // 当为false的时候,则不用进入到分拨的线体,直行到异常线体口 msg = "", //"XXX数据,成功接收" data = new { taskNo = 1344, taskDescr = "",//任务描述 pointCode = "12007",//资源点 containerCode = "LT10004",//托盘号 stats = 0 //int 0 空闲,1 占用 } }); #region json JObject objMis = new JObject(); objMis.Add(new JProperty("code", 0)); objMis.Add(new JProperty("success", true)); objMis.Add(new JProperty("msg", "")); JObject objDate = new JObject(); objDate.Add(new JProperty("taskNo", 234567));//任务号 objDate.Add(new JProperty("taskDescr", "手动"));//任务描述 objDate.Add(new JProperty("pointCode", "12016"));//资源点 objDate.Add(new JProperty("containerCode", "T10001"));//托盘号 objDate.Add(new JProperty("stats", 1));//0 空闲,1 占用 objMis.Add(new JProperty("data", objDate)); //json = JsonConvert.DeserializeObject(objMis.ToString()).ToString(); #endregion return json; } /// /// 拆盘托盘状态查询 /// public static void CONTAINER_QUERYSTATUS() { string msg = string.Empty; string err = string.Empty; IO_CONTROL model = new IO_CONTROL(); int[] port = new int[] { 12007, 12008, 12011, 12014 }; IO_CONTROL_APPLY caModel = new IO_CONTROL_APPLY(); ZH_pallet zpModel = new ZH_pallet(); IO_INTERFACE_TASK_STATE_LOG itsModel = new IO_INTERFACE_TASK_STATE_LOG(); List modelList = caModel.GetModelList(" APPLY_TASK_STATUS = 0 and CONTROL_APPLY_TYPE = 13 and DEVICE_CODE in(" + string.Join(",", port) + ")");//13 托盘是否可用验证 foreach (var item in modelList) { try { string dataVerify = string.Empty; #region reqJson JObject objMis = new JObject(); //objMis.Add(new JProperty("taskId", UtilityBLL.GetUuid()));//接口交互 任务号 谁发起,谁生成 objMis.Add(new JProperty("taskId", DateTime.Now.ToString("yyyyMMddHHmmss")));//接口交互 任务号 objMis.Add(new JProperty("pointCode", Convert.ToString(item.DEVICE_CODE)));//资源点 string STOCK_BARCODE = string.Empty; //如果扫码为空直接给空 if (item.STOCK_BARCODE.Equals("\u0018")) { STOCK_BARCODE = ""; } else { STOCK_BARCODE = item.STOCK_BARCODE.Length >= 7 ? item.STOCK_BARCODE.Substring(0, 7) : item.STOCK_BARCODE; } objMis.Add(new JProperty("containerCode", STOCK_BARCODE));//托盘条码 #endregion reqJson = JsonConvert.DeserializeObject(objMis.ToString()).ToString(); retJson = HttpHelper.PostJson(InterfaceAdd, reqJson); bool success = Convert.ToBoolean(UtilityBLL.GetReceiveValues(retJson, "success")); string retdata = UtilityBLL.GetReceiveValues(retJson, "data"); int state = string.IsNullOrEmpty(STOCK_BARCODE) ? 1 : 0; if (success) { CONTAINER_QUERYSTATUS_MODEL cqModel = new CONTAINER_QUERYSTATUS_MODEL(); //TODO 待定托盘扫码验证托盘是否可用 List cqModelList = JsonConvert.DeserializeObject>(retdata); cqModel = cqModelList[0]; state = cqModel.stats == "1" ? 1 : 0; //是否占用 0 托盘可用 1/-1 托盘不可用流到异常口 if (state != 0) { //不可用,流到异常口 PUBLIC_BLL.errDischarge(item.DEVICE_CODE, "19002", "3", STOCK_BARCODE); msg = "托盘" + item.STOCK_BARCODE + ",不可用异常排出。"; } else { DataTable dt = DBOperator.GetTableSql("select qty from IO_INTERFACE_PALLET where productCode = (select top 1 productCode from IO_INTERFACE_TASK_STATE_LOG)"); int qty = dt.Rows.Count > 0 ? Convert.ToInt32(dt.Rows[0]["qty"]) : 0; List zpList = zpModel.GetModelList($" Device = {item.DEVICE_CODE} "); if (zpList.Count > 0) { zpModel.Update($" Gflag = {state},SN = '',qty = 0,GOODS_COUNT = 0,qty_count = {qty}", $" STOCK_BARCODE = '{item.STOCK_BARCODE}' and Device ={item.DEVICE_CODE}"); } else { zpModel = new ZH_pallet(); zpModel.Device = item.DEVICE_CODE; zpModel.STOCK_BARCODE = item.STOCK_BARCODE; zpModel.Mflag = ""; zpModel.taskNo = ""; zpModel.subTaskNo = ""; zpModel.Gflag = "0"; zpModel.qty = 0; zpModel.GOODS_COUNT = 0; zpModel.qty_count = qty; zpModel.Insert(out err); } } caModel.Update(" APPLY_TASK_STATUS = 1 ", " CONTROL_APPLY_ID = '" + item.CONTROL_APPLY_ID + "'"); caModel.Delete(" CONTROL_APPLY_ID = '" + item.CONTROL_APPLY_ID + "'"); } else if (success == false) { PUBLIC_BLL.errDischarge(item.DEVICE_CODE, "19002", "3", STOCK_BARCODE); caModel.Update(" APPLY_TASK_STATUS = 1 ", " CONTROL_APPLY_ID = '" + item.CONTROL_APPLY_ID + "'"); } #region 添加接口日志 及界面显示 UtilityBLL.CreateINTERFACE_LOG(InterfaceName, InterfaceFlow, reqJson, retJson + dataVerify, InterfaceNote); #endregion } catch (Exception ex) { new DisplaySet().ErrorAddListBoxItem(InterfaceName, ex.Message); new DisplaySet().AddListBoxItem(InterfaceName, ex.Message); UtilityBLL.CreateINTERFACE_LOG(InterfaceName, InterfaceFlow, reqJson + err, retJson + ex.Message, InterfaceNote); LogHelper.ErrorLog(ex); throw; } } } /// /// 托盘申请 返回实体类 /// public class CONTAINER_QUERYSTATUS_MODEL { /// /// 任务号 /// public int taskNo { get; set; } /// /// 任务描述 /// public string taskDescr { get; set; } /// /// 资源点 /// public string pointCode { get; set; } /// /// 托盘号 /// public string containerCode { get; set; } /// /// 托盘状态 0 空闲,1 占用,非空闲 /// public string stats { get; set; } public int taskId { get; set; } /// /// 子任务号 /// public string subTaskNo { get; set; } /// /// SN码 /// public string productUniqueCode { get; set; } /// /// 源位置点 /// public string fromLocatorCode { get; set; } /// /// 目标位置点 /// public string toLocatorCode { get; set; } /// /// 线路编号 就是起点-终点的线路编号 /// public string lineCode { get; set; } /// /// 是否质检 /// public int ifTestingRandom { get; set; } /// /// 物料编码 /// public string productCode { get; set; } /// /// 物料名称 /// public string productName { get; set; } /// /// 物料长 /// public string packingLength { get; set; } /// /// 物料宽 /// public string packingWidth { get; set; } /// /// 物料高 /// public string packinghigh { get; set; } /// /// 物料码托排 /// public string palletArrangePlatoon { get; set; } /// /// 物料码托列 /// public string palletArrangeLie { get; set; } /// /// 物料码托层 /// public string palletArrangeStorey { get; set; } public int ifNotWrapper { get; set; } public bool error { get; set; } public string taskType { get; set; } public string fromRoadwayCode { get; set; } public string fromStorey { get; set; } public string fromPlatoon { get; set; } public string fromLie { get; set; } public int fromLocatorCodeDepth { get; set; } public string toRoadwayCode { get; set; } public string toStorey { get; set; } public string toPlatoon { get; set; } public string toLie { get; set; } public int toLocatorDepth { get; set; } public int taskGroupPriority { get; set; } public int taskPriority { get; set; } } /// /// 托盘申请 实体类 /// public class ZH_pallet { /// /// 任务号 /// public string taskNo { get; set; } /// /// 子任务号 /// public string subTaskNo { get; set; } /// /// 资源点 /// public string Device { get; set; } /// /// 托盘号 /// public string STOCK_BARCODE { get; set; } /// /// 托盘状态 0 空闲可用,1 不可用 /// public string Gflag { get; set; } /// /// 是否是托盘 0 托盘 1物料 /// public string Mflag { get; set; } /// /// 码垛数量 /// public int qty { get; set; } /// /// 是否满垛 0 未满,1满垛 /// public int GOODS_COUNT { get; set; } /// /// 码垛最大数量 /// public int qty_count { get; set; } } } }