diff --git a/Admin.Core.Model/Model_New/BaseSpaceInfo.cs b/Admin.Core.Model/Model_New/BaseSpaceInfo.cs index d196dd2d..f300eb36 100644 --- a/Admin.Core.Model/Model_New/BaseSpaceInfo.cs +++ b/Admin.Core.Model/Model_New/BaseSpaceInfo.cs @@ -159,7 +159,7 @@ namespace Admin.Core.Model [SugarColumn(ColumnName = "IS_TWO_SPACE")] public int IsTwoSpace { get; set; } /// - /// 分垛使用字段,记录同型号上次入的货道,如FD01_002 + /// 分垛使用字段,记录同型号上次入的货道,如FD01_002 == >记录上次货道ObjId /// [SugarColumn(ColumnName = "LAST_SPACE")] public string LastSpace { get; set; } diff --git a/Aucma.Core.BoxFoam/ViewModels/SelectTypeViewModel.cs b/Aucma.Core.BoxFoam/ViewModels/SelectTypeViewModel.cs index 79479066..9a40b283 100644 --- a/Aucma.Core.BoxFoam/ViewModels/SelectTypeViewModel.cs +++ b/Aucma.Core.BoxFoam/ViewModels/SelectTypeViewModel.cs @@ -76,6 +76,9 @@ namespace Aucma.Core.BoxFoam.ViewModels materialDataGrid = new ObservableCollection(); SearchCriteriaViewModel.RefreshPageEvent += SaveSearchCriteria; Console.WriteLine(spaceCode); + BaseSpaceInfo space = _baseSpaceInfoServices.FirstAsync(x => x.SpaceCode.Equals(spaceCode)).Result; + + //加载快捷方式 SaveSearchCriteria(); @@ -83,14 +86,21 @@ namespace Aucma.Core.BoxFoam.ViewModels if (ncount == 1) { IsSelectedOptionA = true; + PlanInfo.MaterialCode = space.MaterialType; + PlanInfo.MaterialName = space.typeNameA; + } else if (ncount == 2) { IsSelectedOptionB = true; + PlanInfo.MaterialCode = space.typeCodeB; + PlanInfo.MaterialName = space.typeNameB; } else if (ncount == 3) { IsSelectedOptionC = true; + PlanInfo.MaterialCode = space.typeCodeC; + PlanInfo.MaterialName = space.typeNameC; } } diff --git a/Aucma.Core.Palletiz/Business/InstoreBusiness.cs b/Aucma.Core.Palletiz/Business/InstoreBusiness.cs index e9542be2..30531092 100644 --- a/Aucma.Core.Palletiz/Business/InstoreBusiness.cs +++ b/Aucma.Core.Palletiz/Business/InstoreBusiness.cs @@ -14,6 +14,7 @@ using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; +using static System.Windows.Forms.VisualStyles.VisualStyleElement.StartPanel; namespace Aucma.Core.Palletiz.Business { @@ -35,7 +36,8 @@ namespace Aucma.Core.Palletiz.Business #region 变量定义 public readonly List allScanners = Appsettings.app("ScannerServer").ToList(); - public readonly string storeCode = Appsettings.app("StoreInfo", "PalletizStoreCode");//分垛库code + public readonly string storeCodeA = Appsettings.app("StoreInfo", "PalletizStoreCodeA");//分垛库A + public readonly string storeCodeB = Appsettings.app("StoreInfo", "PalletizStoreCodeB");//分垛库B #endregion #region 接口引用 @@ -49,7 +51,7 @@ namespace Aucma.Core.Palletiz.Business public void test() { - // B24010183025014160001 SN:16160030000000910999 + // B240101 8302501416 0001 SN:16160030000000910999 Task.Run(async () => { Thread.Sleep(3000); @@ -76,66 +78,59 @@ namespace Aucma.Core.Palletiz.Business List spaceNumList = new List(); // 入库记录 RecordInStore recordInstore = new RecordInStore(); - recordInstore.StoreCode = storeCode; - + //1.根据成品码找货道 List spaceList = getSpaceBySNCode(SNCode,recordInstore); // 根据货道信息判断下发plc信号 - if (spaceList == null) + if (spaceList == null || spaceList.Count==0) { logHelper.Error("未找到匹配货道,请手动入库!"); // 刷新页面提示信息 return; } - if (spaceList.Count == 1) + // 过滤货道,找到最终需要下发的货道 + BaseSpaceInfo finalSpace = FilterSpace(spaceList); + + // 大产品占两道 + if (finalSpace.IsTwoSpace == 1) { - spaceNumList.Add(int.Parse(spaceList[0].SpaceCode.Substring(5, 3))); - spaceNumList.Add(0); + spaceNumList.Add(int.Parse(finalSpace.SpaceCode.Substring(5, 3))); + spaceNumList.Add(int.Parse(getOtherSpace(finalSpace, spaceList).SpaceCode.Substring(5, 3))); plcResult = sendAndAnswerPlc(scannerIp, spaceList[0].RotationRange, spaceNumList); - spaceList[0].LastSpace = spaceList[0].SpaceCode; - recordInstore.SpaceCode = spaceList[0].SpaceCode; - + recordInstore.SpaceCode = finalSpace.SpaceCode; + recordInstore.StoreCode = finalSpace.StoreCode; + // 更新货道信息,大产品last存objId大的,如货道7,8存8 + BaseSpaceInfo otherSpace = getOtherSpace(finalSpace, spaceList); + if (otherSpace != null) + { + updateSapceList(otherSpace.ObjId,spaceList); + } } - // 暂时只考虑两个货道入一种型号 - else if (spaceList.Count >= 2) + else { - // 大产品占两道 - if (spaceList[0].IsTwoSpace == 1) + // last不等于自己,可以先入自己,否则入另一条货道 + if (isOddNumber(finalSpace)) { - spaceNumList.Add(int.Parse(spaceList[0].SpaceCode.Substring(5, 3))); - spaceNumList.Add(int.Parse(spaceList[1].SpaceCode.Substring(5, 3))); - plcResult = sendAndAnswerPlc(scannerIp, spaceList[0].RotationRange, spaceNumList); - recordInstore.SpaceCode = spaceList[0].SpaceCode; + spaceNumList.Add(int.Parse(finalSpace.SpaceCode.Substring(5, 3))); + spaceNumList.Add(0); + plcResult = sendAndAnswerPlc(scannerIp, finalSpace.RotationRange, spaceNumList); + updateSapceList(finalSpace.ObjId, spaceList); } else { - // last不等于自己,可以先入自己,否则入另一条货道 - if (!spaceList[0].LastSpace.Equals(spaceList[0].SpaceCode)) - { - spaceNumList.Add(int.Parse(spaceList[0].SpaceCode.Substring(5, 3))); - spaceNumList.Add(0); - plcResult = sendAndAnswerPlc(scannerIp, spaceList[0].RotationRange, spaceNumList); - spaceList[0].LastSpace = spaceList[0].SpaceCode; - recordInstore.SpaceCode = spaceList[0].SpaceCode; - } - else - { - spaceNumList.Add(0); - spaceNumList.Add(int.Parse(spaceList[1].SpaceCode.Substring(5, 3))); - sendAndAnswerPlc(scannerIp, spaceList[0].RotationRange, spaceNumList); - spaceList[0].LastSpace = spaceList[1].SpaceCode; - recordInstore.SpaceCode = spaceList[1].SpaceCode; - } + spaceNumList.Add(0); + spaceNumList.Add(int.Parse(finalSpace.SpaceCode.Substring(5, 3))); + plcResult = sendAndAnswerPlc(scannerIp, finalSpace.RotationRange, spaceNumList); + updateSapceList(finalSpace.ObjId, spaceList); } - } - if(plcResult==true) + if (plcResult==true) { - // 更新货道信息,入库记录,刷新界面 - _baseSpaceInfoServices.UpdateAsync(spaceList); - + // 更新入库记录,刷新界面 #region 添加入库记录 + recordInstore.SpaceCode = finalSpace.SpaceCode; + recordInstore.StoreCode = finalSpace.StoreCode; recordInstore.InStoreAmount = 1; recordInstore.InStoreTime = DateTime.Now; recordInstore.CreatedTime = DateTime.Now; @@ -169,12 +164,13 @@ namespace Aucma.Core.Palletiz.Business CodeBindingRecord bindingRecord = _codeBindingServices.Query(c => c.ProductCode.Equals(SNCode)).FirstOrDefault(); if (bindingRecord == null) return null; + recordInstore.BarCodeCode = bindingRecord.BoxCode; recordInstore.MaterialCode = bindingRecord.BoxCode; recordInstore.MaterialType = bindingRecord.BoxCode.Substring(7, 10); recordInstore.MaterialName = bindingRecord.BoxName; - return _baseSpaceInfoServices.Query(s => s.MaterialType.Equals(bindingRecord.BoxCode.Substring(7, 10)) &&s.StoreCode.Equals(storeCode)); + return _baseSpaceInfoServices.Query(s => s.MaterialType.Equals(bindingRecord.BoxCode.Substring(7, 10)) && (s.StoreCode.Equals(storeCodeA) || s.StoreCode.Equals(storeCodeB)) ).OrderBy(x=>x.ObjId).ToList(); } catch (Exception ex) { @@ -183,26 +179,90 @@ namespace Aucma.Core.Palletiz.Business } } + private BaseSpaceInfo FilterSpace(List spaceInfos) + { + if (spaceInfos.Count == 1 || string.IsNullOrEmpty(spaceInfos[0].LastSpace)) + { + return spaceInfos[0]; + } + List spaceList = spaceInfos.Where(s=>s.ObjId> int.Parse(spaceInfos[0].LastSpace)).ToList(); + if(spaceList==null|| spaceList.Count == 0) + { + return spaceInfos[0]; + } + else + { + return spaceList[0]; + } + } /// /// 大产品占据两条货道,根据一条货道找到另一条货道 /// /// - private string getOtherSpace(BaseSpaceInfo spaceInfo) + private BaseSpaceInfo getOtherSpace(BaseSpaceInfo spaceInfo,List spaceList) { - // 找到当前货道匹配的另一条货道 - int num = int.Parse(spaceInfo.SpaceCode.Substring(5, 3)); - string otherSpaceCode = string.Empty; - if (num % 2 == 0) // 偶数,如7,8,当前8找7 + try { - otherSpaceCode = spaceInfo.SpaceCode.Substring(0, 5) + (num - 1).ToString("D3"); + // 找到当前货道匹配的另一条货道 + int num = int.Parse(spaceInfo.SpaceCode.Substring(5, 3)); + string otherSpaceCode = string.Empty; + if (num % 2 == 0) // 偶数,如7,8,当前8找7 + { + otherSpaceCode = spaceInfo.SpaceCode.Substring(0, 5) + (num - 1).ToString("D3"); + } + else + { + otherSpaceCode = spaceInfo.SpaceCode.Substring(0, 5) + (num + 1).ToString("D3"); + } + spaceList = spaceList.Where(s => s.SpaceCode.Equals(otherSpaceCode)).ToList(); + if (spaceList.Count > 0) + { + return spaceList[0]; + } + else + { + return null; + } + } + catch (Exception ex) + { + logHelper.Error(ex.Message.ToString()); + return null; + } + } + /// + /// 判断货道编号是否为奇数 + /// + /// + /// + private bool isOddNumber(BaseSpaceInfo space) + { + int num = int.Parse(space.SpaceCode.Substring(5, 3)); + if(num % 2 == 0) + { + return false; } else { - otherSpaceCode = spaceInfo.SpaceCode.Substring(0, 5) + (num + 1).ToString("D3"); + return true; } - return otherSpaceCode; } - + + + /// + /// 将该物料的所有货道列表的last修改为上次入库货道objId + /// + /// + /// + /// + private bool updateSapceList(int objId,List spaceList) + { + foreach(BaseSpaceInfo space in spaceList) + { + space.LastSpace = objId.ToString(); + } + return _baseSpaceInfoServices.UpdateAsync(spaceList).Result; + } #endregion #region plc信号下发 @@ -318,7 +378,7 @@ namespace Aucma.Core.Palletiz.Business } /// - /// 根据扫码器ip确定是属于哪个plc + /// 根据扫码器ip确定是属于哪个plc /// /// /// diff --git a/Aucma.Core.Palletiz/ViewModels/IndexPageViewModel.cs b/Aucma.Core.Palletiz/ViewModels/IndexPageViewModel.cs index 77e3195a..313c58b1 100644 --- a/Aucma.Core.Palletiz/ViewModels/IndexPageViewModel.cs +++ b/Aucma.Core.Palletiz/ViewModels/IndexPageViewModel.cs @@ -28,7 +28,7 @@ namespace Aucma.Core.Palletiz.ViewModels HandPalletizCommand = new RelayCommand(obj => HandPalletizCommandExecute()); InitEveryDayMethod(); - // InstoreBusiness.Instance.test(); + InstoreBusiness.Instance.test(); } #region 扫描信息 diff --git a/Aucma.Core.Palletiz/Views/PalletizPageView.xaml b/Aucma.Core.Palletiz/Views/PalletizPageView.xaml index b6bc8e79..91433b30 100644 --- a/Aucma.Core.Palletiz/Views/PalletizPageView.xaml +++ b/Aucma.Core.Palletiz/Views/PalletizPageView.xaml @@ -100,7 +100,7 @@ - + diff --git a/Aucma.Core.Palletiz/appsettings.json b/Aucma.Core.Palletiz/appsettings.json index 59e90f6e..6365ce92 100644 --- a/Aucma.Core.Palletiz/appsettings.json +++ b/Aucma.Core.Palletiz/appsettings.json @@ -224,7 +224,8 @@ "LinerInventory": "NDK-001", "AfterStoreCode": "PHK-001", "BeforeStoreCode": "PQK-001", - "PalletizStoreCode": "FDK-001", + "PalletizStoreCodeA": "FDK-001", + "PalletizStoreCodeB": "FDK-002", "ProductlineCode": "CX_02" }, "IpRateLimiting": {