using Newtonsoft.Json; using Newtonsoft.Json.Linq; using System; using System.Collections.Generic; using System.Data; using System.Diagnostics; using System.Linq; using System.Text; using XS_DAL; using XS_Model; namespace XS_BLL { /// /// 码垛完成上报 /// public class CONTAINER_PALLET_BLL { #region 全局参数 /// /// 接口地址,请求路径 /// //public static string InterfaceAdd = Global.upper_WMSURL + "api/wcs/container/pallet";//请求路径 BarCodeApplyConfirm public static string InterfaceAdd = Global.upper_WMSURL + "BarCodeApplyConfirm";//请求路径 BarCodeApplyConfirm /// /// 接口名称,接口日志文件名 /// public static string InterfaceName = "BarCodeApplyConfirm"; /// /// 接口描述 /// 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_PALLET(string RecieveBuffer) { string json = JsonConvert.SerializeObject(new { code = 0, //调试时自行约定,只要类型对应接口,后面不做说明 success = true, // 当为false的时候,则不用进入到分拨的线体,直行到异常线体口 msg = "", //"XXX数据,成功接收" data = new { taskId = 123578,//long taskNo = "1752223977984925734",//string subTaskNo = "1752224238472175665",//string taskDesc = "",//任务描述 string fromLocatorCode = "12008",//string 资源点 toLocatorCode = "12007",//string 资源点 containerCode = "T00003",//string 托盘条码 lineCode = "", ifNotWrapper = 0, //1 不缠膜;0 缠膜 int error = false,//是否异常 bool } }); #region json string pointCode = UtilityBLL.GetReceiveValues(RecieveBuffer, "pointCode"); string containerCode = UtilityBLL.GetReceiveValues(RecieveBuffer, "containerCode"); string endDevice = pointCode == "12007" || pointCode == "12008" ? "12005" : "12012"; 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("taskId", 1234567));//任务号 objDate.Add(new JProperty("taskNo", "1752223977984925734"));//任务号 objDate.Add(new JProperty("subTaskNo", "1752224238472175665"));//任务号 objDate.Add(new JProperty("taskDescr", "手动"));//任务描述 objDate.Add(new JProperty("fromLocatorCode", pointCode));//起点 objDate.Add(new JProperty("toLocatorCode", endDevice));//终点 objDate.Add(new JProperty("containerCode", containerCode));//托盘码 objDate.Add(new JProperty("lineCode", ""));//托盘码 objDate.Add(new JProperty("ifNotWrapper", 1));//是否缠膜1 不缠膜;0 缠膜 int objDate.Add(new JProperty("error", false));//是否异常 objMis.Add(new JProperty("data", objDate)); json = JsonConvert.DeserializeObject(objMis.ToString()).ToString(); #endregion return json; } /// /// 码垛完成上报 /// public static void CONTAINER_PALLET() { IO_CONTROL model = new IO_CONTROL(); IO_CONTROL_APPLY caModel = new IO_CONTROL_APPLY(); List caModleList = new List(); CONTAINER_PALLET_MODEL paModel = new CONTAINER_PALLET_MODEL(); ZH_pallet zhpModel = new ZH_pallet(); try { //未分配码货端口 int[] port = new int[] { 12011, 12014, 12007, 12008 }; port = Global.CONTAINER_PALLET_port; caModleList = caModel.GetModelList(" APPLY_TASK_STATUS = 0 and CONTROL_APPLY_TYPE = 14 and DEVICE_CODE in(" + string.Join(",", port) + ")"); foreach (var item in caModleList) { try { if (!string.IsNullOrEmpty(item.STOCK_BARCODE)) { string STOCK_BARCODE = item.STOCK_BARCODE.Length >= 7 ? item.STOCK_BARCODE.Substring(0, 7) : item.STOCK_BARCODE; #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("taskNo", "")); objMis.Add(new JProperty("subTaskNo", "")); objMis.Add(new JProperty("pointCode", item.DEVICE_CODE));//资源点 objMis.Add(new JProperty("containerCode", item.STOCK_BARCODE));//托盘码 objMis.Add(new JProperty("qty", Convert.ToInt32(item.CONTROL_APPLY_PARAMETER.Split(',').Length)));//托盘上存放数量 objMis.Add(new JProperty("list", item.CONTROL_APPLY_PARAMETER.Split(',')));//商品条码 集合 reqJson = JsonConvert.DeserializeObject(objMis.ToString()).ToString(); #endregion retJson = HttpHelper.PostJson(InterfaceAdd, reqJson); bool success = Convert.ToBoolean(UtilityBLL.GetReceiveValues(retJson, "success")); string retdata = UtilityBLL.GetReceiveValues(retJson, "data"); string dataVerify = string.Empty; if (success) { List paModelList = JsonConvert.DeserializeObject>(retdata); paModel = paModelList[0]; #region 数据赋值 string retEx = string.Empty; #region add 修改人:yy 修改时间:2024年3月3日 原因/内容:添加数据验证 if (string.IsNullOrEmpty(paModel.taskNo)) { dataVerify += "任务号不能为空;"; } if (string.IsNullOrEmpty(paModel.subTaskNo)) { dataVerify += "子任务号不能为空;"; } if (string.IsNullOrEmpty(paModel.fromLocatorCode)) { dataVerify += "原位置点不能为空"; } if (string.IsNullOrEmpty(paModel.toLocatorCode)) { dataVerify += "目标位置不能为空"; } if (string.IsNullOrEmpty(paModel.containerCode)) { //dataVerify += "托盘条码不能为空"; } if ((paModel.ifNotWrapper != "0" && paModel.ifNotWrapper != "1") || (paModel.ifNotWrapper.ToUpper() != "TRUE" && paModel.ifNotWrapper.ToUpper() != "FALSE")) { } else { dataVerify += "是否缠膜状态不正确;"; } if (paModel.error != true && paModel.error != false) { dataVerify += "是否异常状态不正确;"; } //数据验证异常,跳出当前循环 if (!string.IsNullOrEmpty(dataVerify)) {//返回数据异常 UtilityBLL.CreateINTERFACE_LOG(InterfaceName, InterfaceFlow, reqJson, dataVerify + retJson, InterfaceNote); continue; } #endregion model = new IO_CONTROL(); model.CONTROL_ID = Convert.ToString(UtilityBLL.GetTempManageIdx()); model.RELATIVE_CONTROL_ID = -1; model.MANAGE_ID = Convert.ToDecimal(paModel.subTaskNo); model.STOCK_BARCODE = STOCK_BARCODE;//SN 码 未码垛前当 托盘码用 model.MANAGE_TASK_TYPE = "1"; model.CONTROL_TASK_TYPE = 4;//1:入库 2:出库 3:倒库 4:托盘移动/盘点 model.CONTROL_TASK_LEVEL = "1"; model.START_WAREHOUSE_CODE = "1"; model.END_WAREHOUSE_CODE = "1"; model.START_DEVICE_CODE = paModel.fromLocatorCode; model.WORK_MODE = paModel.ifNotWrapper;//工作模式:0 缠膜,1不缠膜 model.CONTROL_STATUS = 0; model.GOODS_PATTERN_CODE = "0"; model.CONTROL_REMARK = paModel.taskNo; //model.ERROR_TEXT = ""; model.CONTROL_BEGIN_TIME = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); model.taskflag = 4; model.END_DEVICE_CODE = paModel.toLocatorCode; if (paModel.error || success == false) { model.END_DEVICE_CODE = "19002"; model.WORK_MODE = "1"; } if (model.Insert(out retEx)) { //删除托盘计数 zhpModel.Delete($" Device = { model.START_DEVICE_CODE}"); //zhpModel = new ZH_pallet(); //zhpModel.Device = model.START_DEVICE_CODE; //zhpModel.Insert(out retEx); } #endregion 数据赋值 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", "4", 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, retJson + ex.Message, InterfaceNote); LogHelper.ErrorLog(ex); } } } catch (Exception) { throw; } /* ZH_pallet model1 = new ZH_pallet(); List model2 = new List(); IO_CONTROL model = new IO_CONTROL(); IO_CONTROL mode22 = new IO_CONTROL(); List amodelList = new List(); IO_INTERFACE_TASK_STATE_LOG itsModel = new IO_INTERFACE_TASK_STATE_LOG(); CONTAINER_PALLET_MODEL paModel = new CONTAINER_PALLET_MODEL(); //未分配码货端口 int[] port = new int[] { 12011, 12014, 12007, 12008 }; port = Global.CONTAINER_PALLET_port; model2 = model1.GetModelList(" GOODS_COUNT = 1 and DEVICE in(" + string.Join(",", port) + ")"); List itsModelList = itsModel.GetModelList(); foreach (var item in model2) { try { if (!string.IsNullOrEmpty(item.STOCK_BARCODE)) { string BARCODE = item.STOCK_BARCODE.Length >= 7 ? item.STOCK_BARCODE.Substring(0, 7) : item.STOCK_BARCODE; if (itsModelList.Count > 0) { item.taskNo = string.IsNullOrEmpty(item.taskNo) ? itsModelList[0].taskId : item.taskNo; item.subTaskNo = string.IsNullOrEmpty(item.subTaskNo) ? itsModelList[0].taskNo : item.subTaskNo; } if (item.stockUp == 0) { #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("taskNo", item.taskNo));// task 任务号,使用申请表的任务索引 //objMis.Add(new JProperty("subTaskNo", item.subTaskNo));// task 任务号,使用申请表的任务索引 objMis.Add(new JProperty("taskNo", "")); objMis.Add(new JProperty("subTaskNo", "")); objMis.Add(new JProperty("pointCode", item.Device));//资源点 objMis.Add(new JProperty("containerCode", BARCODE));//托盘码 objMis.Add(new JProperty("qty", Convert.ToInt32(item.qty)));//托盘上存放数量 objMis.Add(new JProperty("list", item.SN.Split(',')));//商品条码 集合 reqJson = JsonConvert.DeserializeObject(objMis.ToString()).ToString(); #endregion //TODO 临时指定路径 //InterfaceAdd = "http://10.10.16.23:8089/XS_HttpServer/api/wcs/container/pallet";//临时指定路径 retJson = HttpHelper.PostJson(InterfaceAdd, reqJson); } else { #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("taskNo", item.taskNo));// task 任务号,使用申请表的任务索引 //objMis.Add(new JProperty("subTaskNo", item.subTaskNo));// task 任务号,使用申请表的任务索引 objMis.Add(new JProperty("taskNo", "")); objMis.Add(new JProperty("subTaskNo", "")); objMis.Add(new JProperty("pointCode", item.Device));//资源点 objMis.Add(new JProperty("originalContainerCode", item.OLD_STOCK_BARCODE));//托盘码 objMis.Add(new JProperty("containerCode", BARCODE));//托盘码 objMis.Add(new JProperty("qty", Convert.ToInt32(item.qty)));//托盘上存放数量 objMis.Add(new JProperty("list", item.SN.Split(',')));//商品条码 集合 reqJson = JsonConvert.DeserializeObject(objMis.ToString()).ToString(); #endregion //TODO 临时指定路径 //InterfaceAdd = "http://10.10.16.23:8089/XS_HttpServer/api/wcs/container/splitPallet";//临时指定路径 //InterfaceAdd = Global.upper_WMSURL + "api/wcs/container/splitPallet";//请求路径 retJson = HttpHelper.PostJson(InterfaceAdd, reqJson); } string retdata = UtilityBLL.GetReceiveValues(retJson, "data"); string dataVerify = string.Empty; if (retdata != "" && retdata != "{}") { bool success = Convert.ToBoolean(UtilityBLL.GetReceiveValues(retJson, "success")); if (success) { List paModelList = JsonConvert.DeserializeObject>(retdata); paModel = paModelList[0]; #region 数据赋值 string retEx = string.Empty; if (paModel.error) { model = new IO_CONTROL(); model.CONTROL_ID = Convert.ToString(UtilityBLL.GetTempManageIdx()); model.RELATIVE_CONTROL_ID = -1; model.MANAGE_ID = Convert.ToDecimal(paModel.subTaskNo); model.STOCK_BARCODE = BARCODE;//SN 码 未码垛前当 托盘码用 model.MANAGE_TASK_TYPE = "1"; model.CONTROL_TASK_TYPE = 4;//1:入库 2:出库 3:倒库 4:托盘移动/盘点 model.CONTROL_TASK_LEVEL = "1"; model.START_WAREHOUSE_CODE = "1"; model.END_WAREHOUSE_CODE = "1"; model.START_DEVICE_CODE = paModel.fromLocatorCode; model.WORK_MODE = paModel.ifNotWrapper;//工作模式:0 缠膜,1不缠膜 model.CONTROL_STATUS = 0; model.GOODS_PATTERN_CODE = "0"; model.CONTROL_REMARK = paModel.taskNo; //model.ERROR_TEXT = ""; model.CONTROL_BEGIN_TIME = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); model.taskflag = 4; mode22 = new IO_CONTROL(); mode22.CONTROL_ID = Convert.ToString(UtilityBLL.GetTempManageIdx() + 1); mode22.RELATIVE_CONTROL_ID = -1; mode22.MANAGE_ID = Convert.ToDecimal(paModel.subTaskNo); mode22.STOCK_BARCODE = item.STOCK_BARCODE;//SN 码 未码垛前当 托盘码用 mode22.MANAGE_TASK_TYPE = "1"; mode22.CONTROL_TASK_TYPE = 4;//1:入库 2:出库 3:倒库 4:托盘移动/盘点 mode22.CONTROL_TASK_LEVEL = "1"; mode22.START_WAREHOUSE_CODE = "1"; mode22.END_WAREHOUSE_CODE = "1"; mode22.START_DEVICE_CODE = paModel.fromLocatorCode; //是否缠膜测试 mode22.WORK_MODE = "1"; // mode22.WORK_MODE = paModel.ifNotWrapper;//工作模式:0 缠膜,1不缠膜 mode22.CONTROL_STATUS = 0; mode22.GOODS_PATTERN_CODE = "0"; mode22.CONTROL_REMARK = paModel.taskNo; //model.ERROR_TEXT = ""; mode22.CONTROL_BEGIN_TIME = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); mode22.taskflag = 5; switch (paModel.fromLocatorCode) { case "12014": model.END_DEVICE_CODE = "12012"; model.WORK_MODE = "1"; mode22.START_DEVICE_CODE = "12012"; mode22.END_DEVICE_CODE = "19002"; mode22.WORK_MODE = "1"; break; case "12011": model.END_DEVICE_CODE = "12012"; model.WORK_MODE = "1"; mode22.START_DEVICE_CODE = "12012"; mode22.END_DEVICE_CODE = "19002"; mode22.WORK_MODE = "1"; break; case "12007": model.END_DEVICE_CODE = "12005"; model.WORK_MODE = "1"; mode22.START_DEVICE_CODE = "12005"; mode22.END_DEVICE_CODE = "19002"; mode22.WORK_MODE = "1"; break; case "12008": model.END_DEVICE_CODE = "12005"; model.WORK_MODE = "1"; mode22.START_DEVICE_CODE = "12005"; mode22.END_DEVICE_CODE = "19002"; mode22.WORK_MODE = "1"; break; } amodelList.Add(model); amodelList.Add(mode22); if (amodelList.Insert()) { //删除托盘计数并吧托盘送到异常排除位置 model1.Update("GOODS_COUNT=2", "Device=" + item.Device); } } else if (string.IsNullOrEmpty(dataVerify)) { #region add 修改人:yy 修改时间:2024年3月3日 原因/内容:添加数据验证 if (string.IsNullOrEmpty(paModel.taskNo)) { dataVerify += "任务号不能为空;"; } if (string.IsNullOrEmpty(paModel.subTaskNo)) { dataVerify += "子任务号不能为空;"; } if (string.IsNullOrEmpty(paModel.fromLocatorCode)) { dataVerify += "原位置点不能为空"; } if (string.IsNullOrEmpty(paModel.toLocatorCode)) { dataVerify += "目标位置不能为空"; } if (string.IsNullOrEmpty(paModel.containerCode)) { dataVerify += "托盘条码不能为空"; } if ((paModel.ifNotWrapper != "0" && paModel.ifNotWrapper != "1") || (paModel.ifNotWrapper.ToUpper() != "TRUE" && paModel.ifNotWrapper.ToUpper() != "FALSE")) { } else { dataVerify += "是否缠膜状态不正确;"; } if (paModel.error != true && paModel.error != false) { dataVerify += "是否异常状态不正确;"; } //数据验证异常,跳出当前循环 if (!string.IsNullOrEmpty(dataVerify)) {//返回数据异常 UtilityBLL.CreateINTERFACE_LOG(InterfaceName, InterfaceFlow, reqJson, dataVerify + retJson, InterfaceNote); continue; } #endregion model = new IO_CONTROL(); model.CONTROL_ID = Convert.ToString(UtilityBLL.GetTempManageIdx()); model.RELATIVE_CONTROL_ID = -1; model.MANAGE_ID = Convert.ToDecimal(paModel.subTaskNo); model.STOCK_BARCODE = BARCODE;//SN 码 未码垛前当 托盘码用 model.MANAGE_TASK_TYPE = "1"; model.CONTROL_TASK_TYPE = 4;//1:入库 2:出库 3:倒库 4:托盘移动/盘点 model.CONTROL_TASK_LEVEL = "1"; model.START_WAREHOUSE_CODE = "1"; model.END_WAREHOUSE_CODE = "1"; model.START_DEVICE_CODE = paModel.fromLocatorCode; model.WORK_MODE = paModel.ifNotWrapper;//工作模式:0 缠膜,1不缠膜 model.CONTROL_STATUS = 0; model.GOODS_PATTERN_CODE = "0"; model.CONTROL_REMARK = paModel.taskNo; //model.ERROR_TEXT = ""; model.CONTROL_BEGIN_TIME = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); model.taskflag = 4; model.END_DEVICE_CODE = paModel.toLocatorCode; if (model.Insert(out retEx)) { //删除托盘计数 model1.Update("GOODS_COUNT=2", "Device=" + item.Device); //if (model1.Update("GOODS_COUNT=2", "Device=" + item.Device)) //{ // //拆垛任务变更成正常任务上报wms获取是否再次拆垛指令 // model.Update("CONTROL_STATUS=999", "CONTROL_STATUS=77"); //} } } #endregion 数据赋值 } } else { dataVerify += "返回值为空;"; } #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, ex.Message, InterfaceNote); LogHelper.ErrorLog(ex); } } */ } /// /// 码垛完成上报 返回实体类 /// public class CONTAINER_PALLET_MODEL { /// /// 任务号 /// public string taskNo { get; set; } /// /// 任务描述 /// public string taskDescr { get; set; } /// /// 源位置点 /// public string fromLocatorCode { get; set; } /// /// 目标位置点 /// public string toLocatorCode { get; set; } /// /// 托盘条码 /// public string containerCode { get; set; } /// /// 路径编码 /// public string lineCode { get; set; } /// /// 是否缠膜 true 缠膜;false 缠膜 /// public string ifNotWrapper { get; set; } /// /// 是否异常 /// public bool error { get; set; } /// /// 子任务号 /// public string subTaskNo { get; set; } /// /// 任务ID /// public long taskId { get; set; } /// /// SN码 /// public string productUniqueCode { 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 string pointCode { get; set; } public int stats { 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; } } } }