using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; using WIDESEA_Common; using WIDESEA_Common.Tools; using WIDESEA_Core.EFDbContext; using WIDESEA_Core.Utilities; using WIDESEA_Entity.DomainModels; using WIDESEA_Services; using WIDESEA_Services.IRepositories; using WIDESEA_Services.Repositories; using WIDESEA_Services.Services; using WIDESEA_WCS.WCSClient; namespace WIDESEA_WCS.Jobs { public partial class EquipmentExecutor : SchedulerExecuteBase { private static int _readJROutBindSignalso = 0; /// /// 拆包站逻辑流程 /// /// /// public static void JROutBind() { if (Interlocked.Exchange(ref _readJROutBindSignalso, 1) == 0) { try { VOLContext Context = new VOLContext(); IJROutBindRepository jrRepository = new JROutBindRepository(Context); Idt_agvtaskRepository agvRepository = new dt_agvtaskRepository(Context); var task = agvRepository.Find(v => v.agv_toaddress.Contains("JR") && v.agv_taskstate == "WaitStockOut"); if (task != null) { var bind = jrRepository.Find(f => f.sum != 0); if (bind != null) { for (int b = 0; b < bind.Count(); b++) { var tasks = agvRepository.Find(v => v.agv_materielid == bind[b].materialtype && v.agv_toaddress.Contains(bind[b].barcode.Substring(0, 2)) && v.agv_toaddress.Contains("JR") && v.agv_taskstate == "WaitStockOut"); if (tasks.Count() > 0) { if (tasks.Count() >= bind[b].sum) { for (int i = 0; i < bind[b].sum; i++) { tasks[i].agv_fromaddress = bind[b].Devid; tasks[i].agv_taskstate = "Create"; if (string.IsNullOrEmpty(bind[b].barcodes)) { tasks[i].agv_materbarcode = bind[b].barcode; } else { tasks[i].agv_materbarcode = bind[b].barcodes.Split(',')[b]; } #region //if (bind[b].Devid == "ZJXL-FBT001") //{ // if (BarcodesData.barcodes1.Count() == 0) // { // tasks[i].agv_materbarcode = bind[b].barcode; // } // else // { // tasks[i].agv_materbarcode = BarcodesData.barcodes1[b]; // } //} //else if (bind[b].Devid == "ZJXL-FBT002") //{ // if (BarcodesData.barcodes2.Count() == 0) // { // tasks[i].agv_materbarcode = bind[b].barcode; // } // else // { // tasks[i].agv_materbarcode = BarcodesData.barcodes2[b]; // } //} //else if (bind[b].Devid == "FJXL-FBT001") //{ // if (BarcodesData.barcodes3.Count() == 0) // { // tasks[i].agv_materbarcode = bind[b].barcode; // } // else // { // tasks[i].agv_materbarcode = BarcodesData.barcodes3[b]; // } //} //else if (bind[b].Devid == "FJXL-FBT002") //{ // if (BarcodesData.barcodes4.Count() == 0) // { // tasks[i].agv_materbarcode = bind[b].barcode; // } // else // { // tasks[i].agv_materbarcode = BarcodesData.barcodes4[b]; // } //} #endregion tasks[i].agv_materielid = bind[b].materialtype; if (i>0) { int size = int.Parse(tasks[i].size); //总宽度 int zwigth = bind[b].sum * size; //已用宽度 int nwigth = size * i; //剩余宽度 int newwigth = zwigth - nwigth; tasks[i].JRunm = bind[b].sum - 1 + ";" + newwigth; } if (i == bind[b].sum - 1) { tasks[i].agv_remark = "true"; tasks[i].agv_qty = tasks.Count(); } agvRepository.Update(tasks[i], true); } bind[b].barcode = ""; bind[b].materialtype = ""; bind[b].sum = 0; bind[b].taskid = ""; bind[b].barcodes = ""; jrRepository.Update(bind[b], true); #region //if (bind[b].Devid == "ZJXL-FBT001") //{ // BarcodesData.barcodes1=null; //} //else if (bind[b].Devid == "ZJXL-FBT002") //{ // BarcodesData.barcodes2= null; //} //else if (bind[b].Devid == "FJXL-FBT001") //{ // BarcodesData.barcodes3 = null; //} //else if (bind[b].Devid == "FJXL-FBT002") //{ // BarcodesData.barcodes4= null; //} #endregion } else { for (int i = 0; i < tasks.Count(); i++) { tasks[i].agv_fromaddress = bind[b].Devid; tasks[i].agv_taskstate = "Create"; if (string.IsNullOrEmpty( bind[b].barcodes)) { tasks[i].agv_materbarcode = bind[b].barcode; } else { tasks[i].agv_materbarcode = bind[b].barcodes.Split(',')[b]; } #region //if (bind[b].Devid == "ZJXL-FBT001") //{ // if (BarcodesData.barcodes1.Count() == 0) // { // tasks[i].agv_materbarcode = bind[b].barcode; // } // else // { // tasks[i].agv_materbarcode = BarcodesData.barcodes1[b]; // } //} //else if (bind[b].Devid == "ZJXL-FBT002") //{ // if (BarcodesData.barcodes2.Count() == 0) // { // tasks[i].agv_materbarcode = bind[b].barcode; // } // else // { // tasks[i].agv_materbarcode = BarcodesData.barcodes2[b]; // } //} //else if (bind[b].Devid == "FJXL-FBT001") //{ // if (BarcodesData.barcodes3.Count() == 0) // { // tasks[i].agv_materbarcode = bind[b].barcode; // } // else // { // tasks[i].agv_materbarcode = BarcodesData.barcodes3[b]; // } //} //else if (bind[b].Devid == "FJXL-FBT002") //{ // if (BarcodesData.barcodes4.Count() == 0) // { // tasks[i].agv_materbarcode = bind[b].barcode; // } // else // { // tasks[i].agv_materbarcode = BarcodesData.barcodes4[b]; // } //} #endregion if (i>0) { int size = int.Parse(tasks[i].size); //总宽度 int zwigth = bind[b].sum * size; //已用宽度 int nwigth = size * i; //剩余宽度 int newwigth = zwigth - nwigth; tasks[i].JRunm = bind[b].sum - 1 + ";" + newwigth; } tasks[i].agv_materielid = bind[b].materialtype; if (i == tasks.Count() - 1) { tasks[i].agv_remark = "true"; tasks[i].agv_qty = tasks.Count(); } agvRepository.Update(tasks[i], true); } bind[b].barcode = ""; bind[b].materialtype = ""; bind[b].sum = 0; bind[b].taskid = ""; bind[b].barcodes = ""; jrRepository.Update(bind[b], true); #region // List newbarcodes = null; //if (bind[b].Devid == "ZJXL-FBT001") //{ // for (int j = tasks.Count(); j < BarcodesData.barcodes1.Count(); j++) // { // newbarcodes.Add(BarcodesData.barcodes1[j]); // WriteLog.Info("剩余卷绕绑定条码").Write(bind[b].Devid+"卷绕绑定条码:" + BarcodesData.barcodes1[j] + DateTime.Now, "剩余卷绕绑定条码"); // } // BarcodesData.barcodes1 = newbarcodes; //} //else if (bind[b].Devid == "ZJXL-FBT002") //{ // for (int j = tasks.Count(); j < BarcodesData.barcodes2.Count(); j++) // { // newbarcodes.Add(BarcodesData.barcodes2[j]); // WriteLog.Info("剩余卷绕绑定条码").Write(bind[b].Devid + "卷绕绑定条码:" + BarcodesData.barcodes1[j] + DateTime.Now, "剩余卷绕绑定条码"); // } // BarcodesData.barcodes2 = newbarcodes; //} //else if (bind[b].Devid == "FJXL-FBT001") //{ // for (int j = tasks.Count(); j < BarcodesData.barcodes3.Count(); j++) // { // newbarcodes.Add(BarcodesData.barcodes3[j]); // WriteLog.Info("剩余卷绕绑定条码").Write(bind[b].Devid + "卷绕绑定条码:" + BarcodesData.barcodes1[j] + DateTime.Now, "剩余卷绕绑定条码"); // } // BarcodesData.barcodes3 = newbarcodes; //} //else if (bind[b].Devid == "FJXL-FBT002") //{ // for (int j = tasks.Count(); j < BarcodesData.barcodes4.Count(); j++) // { // newbarcodes.Add(BarcodesData.barcodes4[j]); // WriteLog.Info("剩余卷绕绑定条码").Write(bind[b].Devid + "卷绕绑定条码:" + BarcodesData.barcodes1[j] + DateTime.Now, "剩余卷绕绑定条码"); // } // BarcodesData.barcodes4 = newbarcodes; //} #endregion } } } } } } catch (Exception) { } finally { Interlocked.Exchange(ref _readJROutBindSignalso, 0); } } } } }