diff --git a/BPASmartClient.Business/BPASmartClient.Business.csproj b/BPASmartClient.Business/BPASmartClient.Business.csproj index 39f36251..87d1b161 100644 --- a/BPASmartClient.Business/BPASmartClient.Business.csproj +++ b/BPASmartClient.Business/BPASmartClient.Business.csproj @@ -8,8 +8,8 @@ - - + + diff --git a/BPASmartClient.Business/Plugin/DeviceMgr.cs b/BPASmartClient.Business/Plugin/DeviceMgr.cs index 887ec80a..d960924c 100644 --- a/BPASmartClient.Business/Plugin/DeviceMgr.cs +++ b/BPASmartClient.Business/Plugin/DeviceMgr.cs @@ -6,6 +6,7 @@ using BPASmartClient.Http; using BPASmartClient.Message; using BPASmartClient.Model; using BPASmartClient.Model.小炒机; +using BPASmartClient.Model.调酒机; using BPASmartClient.Peripheral; using Newtonsoft.Json; using System; @@ -95,7 +96,7 @@ namespace BPASmartClient.Business #region 获取物料数据 string result = string.Empty; - for (int i = 0; i < 3; i++) + for (int i = 0; i < 4; i++) { try { @@ -138,6 +139,15 @@ namespace BPASmartClient.Business }.Publish(); MessageLog.GetInstance.Show("接收到【 API 】获取的小炒流程信息"); } + else if (PushType == 3) + { + new MorkMWGoodsEvent() + { + DeviceId = device.DeviceId, + morkMWPushMessage = JsonConvert.DeserializeObject(result) + }.Publish(); + MessageLog.GetInstance.Show("接收到【API】获取的调酒机配方信息"); + } } catch (Exception ex) { diff --git a/BPASmartClient.CustomResource/BPASmartClient.CustomResource.csproj b/BPASmartClient.CustomResource/BPASmartClient.CustomResource.csproj index 68a96d9a..b728b8dd 100644 --- a/BPASmartClient.CustomResource/BPASmartClient.CustomResource.csproj +++ b/BPASmartClient.CustomResource/BPASmartClient.CustomResource.csproj @@ -410,7 +410,7 @@ - + diff --git a/BPASmartClient.Device/BPASmartClient.Device.csproj b/BPASmartClient.Device/BPASmartClient.Device.csproj index 34e40440..91f97e5b 100644 --- a/BPASmartClient.Device/BPASmartClient.Device.csproj +++ b/BPASmartClient.Device/BPASmartClient.Device.csproj @@ -7,7 +7,7 @@ - + diff --git a/BPASmartClient.JXJFoodBigStation/Properties/Settings.Designer.cs b/BPASmartClient.JXJFoodBigStation/Properties/Settings.Designer.cs index 804602c2..02053c8a 100644 --- a/BPASmartClient.JXJFoodBigStation/Properties/Settings.Designer.cs +++ b/BPASmartClient.JXJFoodBigStation/Properties/Settings.Designer.cs @@ -12,7 +12,7 @@ namespace BPASmartClient.JXJFoodBigStation.Properties { [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.1.0.0")] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.3.0.0")] internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); diff --git a/BPASmartClient.JXJFoodSmallStation/BPASmartClient.JXJFoodSmallStation.csproj b/BPASmartClient.JXJFoodSmallStation/BPASmartClient.JXJFoodSmallStation.csproj index fc69dd26..61188e67 100644 --- a/BPASmartClient.JXJFoodSmallStation/BPASmartClient.JXJFoodSmallStation.csproj +++ b/BPASmartClient.JXJFoodSmallStation/BPASmartClient.JXJFoodSmallStation.csproj @@ -8,7 +8,7 @@ - + diff --git a/BPASmartClient.Model/BPASmartClient.Model.csproj b/BPASmartClient.Model/BPASmartClient.Model.csproj index 5c60f04d..660a436c 100644 --- a/BPASmartClient.Model/BPASmartClient.Model.csproj +++ b/BPASmartClient.Model/BPASmartClient.Model.csproj @@ -17,7 +17,7 @@ - + diff --git a/BPASmartClient.Model/MixWinkModel.cs b/BPASmartClient.Model/MixWinkModel.cs new file mode 100644 index 00000000..ae41ddbb --- /dev/null +++ b/BPASmartClient.Model/MixWinkModel.cs @@ -0,0 +1,25 @@ +using Microsoft.Toolkit.Mvvm.ComponentModel; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPASmartClient.Model +{ + public class MixWinkModel:ObservableObject + { + private string _materialName; + public string materialName { get { return _materialName; } set { _materialName = value;OnPropertyChanged(); } } + /// + /// 位置 + /// + private int _loc; + public int Loc { get { return _loc; } set { _loc = value;OnPropertyChanged(); } } + /// + /// 停留时间 + /// + public int Time { get { return _time; } set { _time = value;OnPropertyChanged(); } } + private int _time; + } +} diff --git a/BPASmartClient.Model/订单/MorkMWSimOrder.cs b/BPASmartClient.Model/订单/MorkMWSimOrder.cs new file mode 100644 index 00000000..60e110fa --- /dev/null +++ b/BPASmartClient.Model/订单/MorkMWSimOrder.cs @@ -0,0 +1,14 @@ +using BPA.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPASmartClient.Model.订单 +{ + public class MorkMWSimOrder:BaseEvent + { + public List mixWink = new List(); + } +} diff --git a/BPASmartClient.Model/调酒机/MorkMWGoodsEvent.cs b/BPASmartClient.Model/调酒机/MorkMWGoodsEvent.cs new file mode 100644 index 00000000..f9814dba --- /dev/null +++ b/BPASmartClient.Model/调酒机/MorkMWGoodsEvent.cs @@ -0,0 +1,15 @@ +using BPA.Message; +using BPA.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPASmartClient.Model.调酒机 +{ + public class MorkMWGoodsEvent : BaseEvent + { + public MORKMWPushMessage morkMWPushMessage = new MORKMWPushMessage(); + } +} diff --git a/BPASmartClient.MorkF/BPASmartClient.MorkF.csproj b/BPASmartClient.MorkF/BPASmartClient.MorkF.csproj index 2984a36c..e7ac07e7 100644 --- a/BPASmartClient.MorkF/BPASmartClient.MorkF.csproj +++ b/BPASmartClient.MorkF/BPASmartClient.MorkF.csproj @@ -10,7 +10,7 @@ - + diff --git a/BPASmartClient.MorkF/Control_MorkF.cs b/BPASmartClient.MorkF/Control_MorkF.cs index 085bf88e..8b657e91 100644 --- a/BPASmartClient.MorkF/Control_MorkF.cs +++ b/BPASmartClient.MorkF/Control_MorkF.cs @@ -33,7 +33,7 @@ namespace BPASmartClient.MorkF /// /// 菜品库while循环最大sleep次数 /// - private const int materialSleepCount = 400; + private const int materialSleepCount = 600; /// /// 菜品库while循环每次sleep时间 @@ -54,17 +54,17 @@ namespace BPASmartClient.MorkF private const int materialHigh = 34500; /// - /// + /// 菜品库第一层的起始基点,为最下层盒子的中间点 /// private const int materialOne = 34500; /// - /// + /// 菜品库第二层的起始基点,为最下层盒子的中间点 /// private const int materialTwo = 34500; /// - /// + /// 菜品库第三层的起始基点,为最下层盒子的中间点 /// private const int materialThree = 34500; @@ -109,7 +109,7 @@ namespace BPASmartClient.MorkF /// /// 小炒菜单集合 - /// + /// f public static List LocalstirFryGoods = new List(); /// @@ -153,6 +153,18 @@ namespace BPASmartClient.MorkF ///初始化菜品库 //FoodLibInit(); Task2ReadMaterialData(); + + ScreenDataServer(); + + //读取坐标系 + MaterialCoordinate materialCoordinate = ReadMaterialCoordinate(); + if(materialCoordinate != null) + { + MaterialCoordinate.GetInstance().dicNoMaterialCoordinate = materialCoordinate.dicNoMaterialCoordinate; + MaterialCoordinate.GetInstance().MLCoordinateList = materialCoordinate.MLCoordinateList; + } + ////菜品库编号与坐标系对象存储 + //SaveMaterialCoordinate(); } /// @@ -168,6 +180,50 @@ namespace BPASmartClient.MorkF //SingleProcess(); } + private static object saveMaterialLock = new object(); + private void SaveMaterialData() + { + lock (saveMaterialLock) + { + Json.Data = MaterialSurplusOperation.GetInstance().materialSurplus; + Json.Save(); + } + } + + private static object saveMaterialCoordinateLock = new object(); + /// + /// 保存当前的坐标系 + /// + public void SaveMaterialCoordinate() + { + lock (saveMaterialLock) + { + Json.Data = MaterialCoordinate.GetInstance(); + Json.Save(); + } + } + + /// + /// 读取坐标系 + /// + /// + private MaterialCoordinate ReadMaterialCoordinate() + { + try + { + lock (saveMaterialLock) + { + Json.Read(); + MaterialCoordinate materialCoordinate = Json.Data; + return materialCoordinate; + } + } + catch(Exception ex) + { + return null; + } + } + private void Task2ReadMaterialData() { ThreadManage.GetInstance().StartLong(new Action(() => { @@ -299,6 +355,16 @@ namespace BPASmartClient.MorkF FoodLibInit(); }), "FoodLibInit"); }), "FoodLibInit"); + ActionManage.GetInstance.Register(new Action(() => + { + ThreadManage.GetInstance().Start(new Action(() => + { + if(!UpdateMaterialLibraryStock()) + { + MessageLog.GetInstance.Show("菜品库检测余量失败"); + } + }), "SurplusCheck"); + }), "SurplusCheck"); ActionManage.GetInstance.Register(new Action((o) => { ThreadManage.GetInstance().Start(new Action(() => @@ -726,7 +792,8 @@ namespace BPASmartClient.MorkF #endregion - #region 菜品库PLC操作方法 + #region 菜品库方法 + #region PLC操作 /// /// 菜品库数据写入 /// @@ -765,6 +832,7 @@ namespace BPASmartClient.MorkF { if (!ml_morkf.InitialComplete) { + MessageLog.GetInstance.Show("电磁阀启停出错,菜品库未初始化"); return; } @@ -779,6 +847,7 @@ namespace BPASmartClient.MorkF { if (!ml_morkf.InitialComplete) { + MessageLog.GetInstance.Show("爪子去到1号位出错,菜品库未初始化"); return false; } @@ -804,6 +873,7 @@ namespace BPASmartClient.MorkF { if (!ml_morkf.InitialComplete) { + MessageLog.GetInstance.Show("爪子去到2号位出错,菜品库未初始化"); return false; } @@ -829,6 +899,7 @@ namespace BPASmartClient.MorkF { if (!ml_morkf.InitialComplete) { + MessageLog.GetInstance.Show("爪子去到3号位出错,菜品库未初始化"); return false; } @@ -854,6 +925,7 @@ namespace BPASmartClient.MorkF { if (!ml_morkf.InitialComplete) { + MessageLog.GetInstance.Show("1号测距出错,菜品库未初始化"); return false; } @@ -868,6 +940,7 @@ namespace BPASmartClient.MorkF { if (!ml_morkf.InitialComplete) { + MessageLog.GetInstance.Show("2号测距出错,菜品库未初始化"); return false; } @@ -882,6 +955,7 @@ namespace BPASmartClient.MorkF { if (!ml_morkf.InitialComplete) { + MessageLog.GetInstance.Show("3号测距出错,菜品库未初始化"); return false; } @@ -900,25 +974,43 @@ namespace BPASmartClient.MorkF /// public bool GetDistance(int x) { + bool ret = true; //是否在第一层菜品库 if (x > 0 && x <= materialLaserHigh) { //获取传感器1的距离 - return GetDistance_1(); + ret &= GetDistance_1(); + + Thread.Sleep(400); + + //获取传感器1的距离 + ret &= GetDistance_1(); } //是否在第二层菜品库 else if (x > materialLaserHigh && x <= (2 * materialLaserHigh + clapboardLaserHigh)) { - //获取传感器1的距离 - return GetDistance_2(); + //获取传感器2的距离 + ret &= GetDistance_2(); + + Thread.Sleep(400); + + ret &= GetDistance_2(); } //是否在第三层菜品库 else if (x > (2 * materialLaserHigh + clapboardLaserHigh) && x <= (3 * materialLaserHigh + 2 * clapboardLaserHigh)) { - //获取传感器1的距离 - return GetDistance_3(); + //获取传感器3的距离 + ret &= GetDistance_3(); + + Thread.Sleep(400); + + ret &= GetDistance_3(); } - return false; + if (!ret) + { + MessageLog.GetInstance.Show($"错误:X轴:{x}获取传感器数据出错"); + } + return ret; } public void PawTurnFront() @@ -939,12 +1031,13 @@ namespace BPASmartClient.MorkF { if (!ml_morkf.InitialComplete) { + MessageLog.GetInstance.Show($"机械臂移动出错,菜品库未初始化"); return false; } //取反 - x -= 2 * x; - y -= 2 * y; + x = 0 - Math.Abs(x); + y = 0 - Math.Abs(y); if (x > 0 || y > 0) { MessageLog.GetInstance.Show($"机械臂移动到[{x},{y}]非法"); @@ -1045,6 +1138,7 @@ namespace BPASmartClient.MorkF MaterailLibrary_Write("M5.6", startOrStop); Thread.Sleep(200); } + #endregion //菜品库锁 object lock_Materail = new object(); @@ -1055,26 +1149,18 @@ namespace BPASmartClient.MorkF /// 取菜x轴坐标 /// 取菜y轴坐标 /// 炒锅编号 - public void GetMaterail(int x, int y, int fryNum = 0) + public bool GetMaterail(int x, int y, int fryNum) { //设置到抓菜处 if (!SetArmPosition(x, y)) { - return; - } - - if (!GetDistance(x)) - { - MessageLog.GetInstance.Show("错误:获取传感器数据出错"); - return; + return false; } - Thread.Sleep(200); - if (!GetDistance(x)) { MessageLog.GetInstance.Show("错误:获取传感器数据出错"); - return; + return false; } Thread.Sleep(1000); @@ -1087,26 +1173,26 @@ namespace BPASmartClient.MorkF if (laserHigh > 29) { MessageLog.GetInstance.Show("错误:传感器获取数据大于隔板与传感器之间的距离"); - return; + return false; } int moveX = 0; if (LaserDistance2Coordinate(laserHigh, out moveX) != Laser2CoordinateState.MaterialNormal) { MessageLog.GetInstance.Show("错误:传感器距离转坐标值失败"); - return; + return false; } if(x < moveX) { MessageLog.GetInstance.Show("错误:传感器距离转坐标值大于当前x轴坐标"); - return; + return false; } //设置到传感器感应的距离处 if (!SetArmPosition(x - moveX, y)) { - return; + return false; } ////关闭电磁阀 @@ -1117,14 +1203,14 @@ namespace BPASmartClient.MorkF //爪子去1号位抓菜 if (!PawToPoint1()) { - return; + return false; } #endif //设置到该层菜品库最高处 if (!SetArmPosition(x - materialHigh, y)) { - return; + return false; } ////移动前开启电磁阀 @@ -1135,13 +1221,13 @@ namespace BPASmartClient.MorkF //爪子去2号位放菜 if (!PawToPoint2()) { - return; + return false; } #endif ////判断炒锅是否可以放盒 - //for(int i = 0;materialSleepCount > i && !morkFs[fryIndex].FryPot1_HOBTPut;i++) + //for (int i = 0; materialSleepCount > i && !morkFs[fryIndex].FryPot1_HOBTPut; i++) //{ - // Thread.Sleep(materialSleepTime); + // Thread.Sleep(materialSleepTime); // if (i >= materialSleepCount - 1) // { // MessageLog.GetInstance.Show("等待炒锅允许放盒超时"); @@ -1169,14 +1255,14 @@ namespace BPASmartClient.MorkF //设置到炒锅1出菜处 if (!SetArmPosition(x, y)) { - return; + return false; } #if true //爪子去3号位放菜 if (!PawToPoint3()) { - return; + return false; } #endif @@ -1188,14 +1274,14 @@ namespace BPASmartClient.MorkF //设置到炒锅1出菜处 if (!SetArmPosition(x + materialToFryDistance, y)) { - return; + return false; } #if true //爪子回到2号位 if (!PawToPoint2()) { - return; + return false; } #endif ////关闭电磁阀 @@ -1205,6 +1291,71 @@ namespace BPASmartClient.MorkF { morkFs[fryNum].GetMaterialComplete = true; } + return true; + } + + /// + /// 更新菜品库存量 + /// + /// + public bool UpdateMaterialLibraryStock() + { + try + { + ////判断是否初始化 + //if (!ml_morkf.InitialComplete) + //{ + // MessageLog.GetInstance.Show("更新菜品库存量出错,菜品库未初始化"); + // return false; + //} + + if (MaterialCoordinate.GetInstance().dicNoMaterialCoordinate == null || MaterialCoordinate.GetInstance().dicNoMaterialCoordinate.Count != 27) + { + MessageLog.GetInstance.Show("更新菜品库存量出错,菜品库坐标系数据未建立"); + return false; + } + + //遍历坐标系与位置,并根据位置更新菜品余量 + foreach(var item in MaterialCoordinate.GetInstance().dicNoMaterialCoordinate) + { + //设置到抓菜处 + if (!SetArmPosition(item.Value.X, item.Value.Y)) + { + return false; + } + + //获取该处的距离 + if (!GetDistance(item.Value.X)) + { + MessageLog.GetInstance.Show("错误:获取传感器数据出错"); + return false; + } + + Thread.Sleep(1000); + + //获取传感器的距离 + int laserHigh = ml_morkf.LaserDistance; + int surplus = 0; + //根据距离算出菜品余量 + Laser2CoordinateState state = LaserDistance2MaterialCount(laserHigh, out surplus); + if (state != Laser2CoordinateState.MaterialNormal || state != Laser2CoordinateState.MaterialEmpty) + { + return false; + } + + //更新菜品余量 + if (!MaterialSurplusOperation.GetInstance().UpdateSurplus(item.Key, surplus)) + { + return false; + } + } + + return true; + } + catch(Exception ex) + { + return false; + } } /// @@ -1259,50 +1410,86 @@ namespace BPASmartClient.MorkF } } + /// + /// 传感器距离转为菜品数量 + /// + /// + /// + /// + public Laser2CoordinateState LaserDistance2MaterialCount(int distance, out int count) + { + count = 0; + try + { + //菜盒放多了 + if (distance < 6) + { + return Laser2CoordinateState.MaterialOverdo; + } + else if (distance >= 6 && distance < 10) + { + count = 5; + return Laser2CoordinateState.MaterialNormal; + } + else if (distance >= 10 && distance < 14) + { + count = 4; + return Laser2CoordinateState.MaterialNormal; + } + else if (distance >= 14 && distance < 19) + { + count = 3; + return Laser2CoordinateState.MaterialNormal; + } + else if (distance >= 19 && distance < 23) + { + count = 2; + return Laser2CoordinateState.MaterialNormal; + } + else if (distance >= 23 && distance < 28) + { + count = 1; + return Laser2CoordinateState.MaterialNormal; + } + else + { + count = 0; + return Laser2CoordinateState.MaterialEmpty; + } + } + catch (Exception ex) + { + return Laser2CoordinateState.MaterialUnkown; + } + } + /// /// 获取菜品测试 /// /// - private void GetMaterailTest(Coordinate coordinate) + private void GetMaterailTest(MaterialOperation materialOperation) { ThreadManage.GetInstance().Start(new Action(() => { - //int x1 = 0, x2 = 0, y = 0; - - //if (getNum % 2 == 0) - //{ - // x2 = 35000; - // y = 82000; - - //} - //else if (getNum % 2 == 1) - //{ - // x2 = 35000; - // y = 9000; - //} - //else - //{ - // MessageLog.GetInstance.Show("菜品库无效操作"); - // return; - //} + bool ret = false; try { + Coordinate myCoordinate = new Coordinate(); + //获取坐标,根据菜品的位置信息 + if (!NoMaterial2Coordinate(materialOperation.materialInfo.Loc, out myCoordinate)) + { + MessageLog.GetInstance.Show($"炒锅{materialOperation.fryNum}获取菜品[{materialOperation.materialInfo.Name}]失败,找不到对应位置"); + return; + } lock (lock_Materail) { ml_morkf.MaterailIsWorking = true; } //取菜操作 - GetMaterail(coordinate.X, coordinate.Y); - - ////机械臂回原点 - //if (!SetArmPosition(0, 0)) - //{ - // MessageLog.GetInstance.Show("菜品库[机械臂操作失败]"); - // return; - //} + ret =GetMaterail(myCoordinate.X, myCoordinate.Y, materialOperation.fryNum); } catch (Exception ex) { - + ret = false; } finally { @@ -1310,6 +1497,12 @@ namespace BPASmartClient.MorkF { ml_morkf.MaterailIsWorking = false; } + if (ret == true) + { + //指定位置菜品减一 + MaterialSurplusOperation.GetInstance().ReduceSurplus(materialOperation.materialInfo.Loc); + SaveMaterialData(); + } } }), $"菜品库操作"); @@ -1469,48 +1662,52 @@ namespace BPASmartClient.MorkF Thread.Sleep(200); } //倒菜 - public void OutFood(int num) + public void OutFood(int num,bool isMaterial = false) { if (!morkFs.ContainsKey(num)) { return; } int i = 0; - //判断是否完成取菜 - for (i = 0; i < sleepCount * 2 && !morkFs[num].GetMaterialComplete; i++) + + if(isMaterial) { - if (i == 3) + //判断是否完成取菜 + for (i = 0; i < materialSleepCount && !morkFs[num].GetMaterialComplete; i++) { - //停止搅拌 - StopStir(num); - //火力设置为2档 - SetFire(new List { 2 }, num); + if (i == 10) + { + //停止搅拌 + StopStir(num); + //火力设置为2档 + SetFire(new List { 2 }, num); + } + Thread.Sleep(materialSleepTime); + if (i >= materialSleepCount - 1) + { + MessageLog.GetInstance.Show($"炒锅{num}倒菜超时:未能等到取菜完成"); + return; + } } - Thread.Sleep(sleepTime); - if (i >= sleepCount * 2 - 1) + + if (i > 9) { - MessageLog.GetInstance.Show($"炒锅{num}倒菜超时:未能等到取菜完成"); - return; + //开启搅拌 + StartStir(num); + //火力设置回原本火力 + SetFire(new List { morkFs[num].Fire }, num); } } - if (i > 3) - { - //开启搅拌 - StartStir(num); - //火力设置回原本火力 - SetFire(new List { morkFs[num].Fire }, num); - } - FirePot_Write("LB3", true, num); MessageLog.GetInstance.Show("倒菜启动"); - Thread.Sleep(200); + Thread.Sleep(500); - for (i = 0; i < sleepCount && !morkFs[num].FryPot1_MaterialIntoPot; i++) + for (i = 0; i < materialSleepCount && !morkFs[num].FryPot1_MaterialIntoPot; i++) { - Thread.Sleep(sleepTime); - if (i >= sleepCount - 1) + Thread.Sleep(materialSleepTime); + if (i >= materialSleepCount - 1) { MessageLog.GetInstance.Show($"炒锅{num}倒菜超时"); } @@ -1519,6 +1716,7 @@ namespace BPASmartClient.MorkF FirePot_Write("LB3", false, num); Thread.Sleep(200); MessageLog.GetInstance.Show("倒菜完成"); + morkFs[num].GetMaterialComplete = false; } //搅拌臂去原点位 public void StirArmGoOrigin(int num) @@ -1645,7 +1843,7 @@ namespace BPASmartClient.MorkF FirePot_Write("LB8", true, num); Thread.Sleep(200); } -#endregion + #endregion bool isInitialArrive = false; @@ -1698,106 +1896,108 @@ namespace BPASmartClient.MorkF }); } } - } - MessageLog.GetInstance.Show("接收到小炒流程信息"); - //流程解析 - foreach (var item in LocalstirFryGoods) - { - MessageLog.GetInstance.Show($"添加菜谱{item.GoodsKey}"); - // morkF.listStirBom.Add(item.StirFryBomInfo);//添加订单制作流程 - string MenuStep = "菜单步骤:"; - foreach (var items in item.StirPotActions) + MessageLog.GetInstance.Show("接收到小炒流程信息"); + //流程解析 + foreach (var item in LocalstirFryGoods) { - switch (items.Actions) + MessageLog.GetInstance.Show($"添加菜谱{item.GoodsKey}"); + // morkF.listStirBom.Add(item.StirFryBomInfo);//添加订单制作流程 + string MenuStep = "菜单步骤:"; + foreach (var items in item.StirPotActions) { - case nameof(StirFryPotActionEnum.加热开启): - MenuStep += items.Actions + ","; - break; - case nameof(StirFryPotActionEnum.设置加热挡位1): - MenuStep += items.Actions + ","; - break; - case nameof(StirFryPotActionEnum.设置加热挡位2): - MenuStep += items.Actions + ","; - break; - case nameof(StirFryPotActionEnum.设置加热挡位3): - MenuStep += items.Actions + ","; - break; - case nameof(StirFryPotActionEnum.设置加热挡位4): - MenuStep += items.Actions + ","; - break; - case nameof(StirFryPotActionEnum.设置加热挡位5): - MenuStep += items.Actions + ","; - break; - case nameof(StirFryPotActionEnum.设置加热挡位6): - MenuStep += items.Actions + ","; - break; - case nameof(StirFryPotActionEnum.设置加热挡位7): - MenuStep += items.Actions + ","; - break; - case nameof(StirFryPotActionEnum.设置加热挡位8): - MenuStep += items.Actions + ","; - break; - case nameof(StirFryPotActionEnum.设置加热挡位9): - MenuStep += items.Actions + ","; - break; - case nameof(StirFryPotActionEnum.设置加热挡位10): - MenuStep += items.Actions + ","; - break; - case nameof(StirFryPotActionEnum.停止加热): - MenuStep += items.Actions + ","; - break; - case nameof(StirFryPotActionEnum.加调料): - MenuStep += items.Actions + ","; - break; - case nameof(StirFryPotActionEnum.取原料): - MenuStep += items.Actions + ","; - break; - case nameof(StirFryPotActionEnum.开启搅拌): - MenuStep += items.Actions + ","; - break; - case nameof(StirFryPotActionEnum.设置搅拌挡位1): - MenuStep += items.Actions + ","; - break; - case nameof(StirFryPotActionEnum.设置搅拌挡位2): - MenuStep += items.Actions + ","; - break; - case nameof(StirFryPotActionEnum.设置搅拌挡位3): - MenuStep += items.Actions + ","; - break; - case nameof(StirFryPotActionEnum.关闭搅拌): - MenuStep += items.Actions + ","; - break; - case nameof(StirFryPotActionEnum.出餐启动): - MenuStep += items.Actions + ","; - break; - case nameof(StirFryPotActionEnum.道菜启动): - MenuStep += items.Actions + ","; - break; - case nameof(StirFryPotActionEnum.炒制菜品): - MenuStep += items.Actions + ","; - break; - case nameof(StirFryPotActionEnum.搅拌臂原点位): - MenuStep += items.Actions + ","; - break; - case nameof(StirFryPotActionEnum.搅拌臂炒制位): - MenuStep += items.Actions + ","; - break; - case nameof(StirFryPotActionEnum.洗锅): - MenuStep += items.Actions + ","; - break; - default: - break; - + switch (items.Actions) + { + case nameof(StirFryPotActionEnum.加热开启): + MenuStep += items.Actions + ","; + break; + case nameof(StirFryPotActionEnum.设置加热挡位1): + MenuStep += items.Actions + ","; + break; + case nameof(StirFryPotActionEnum.设置加热挡位2): + MenuStep += items.Actions + ","; + break; + case nameof(StirFryPotActionEnum.设置加热挡位3): + MenuStep += items.Actions + ","; + break; + case nameof(StirFryPotActionEnum.设置加热挡位4): + MenuStep += items.Actions + ","; + break; + case nameof(StirFryPotActionEnum.设置加热挡位5): + MenuStep += items.Actions + ","; + break; + case nameof(StirFryPotActionEnum.设置加热挡位6): + MenuStep += items.Actions + ","; + break; + case nameof(StirFryPotActionEnum.设置加热挡位7): + MenuStep += items.Actions + ","; + break; + case nameof(StirFryPotActionEnum.设置加热挡位8): + MenuStep += items.Actions + ","; + break; + case nameof(StirFryPotActionEnum.设置加热挡位9): + MenuStep += items.Actions + ","; + break; + case nameof(StirFryPotActionEnum.设置加热挡位10): + MenuStep += items.Actions + ","; + break; + case nameof(StirFryPotActionEnum.停止加热): + MenuStep += items.Actions + ","; + break; + case nameof(StirFryPotActionEnum.加调料): + MenuStep += items.Actions + ","; + break; + case nameof(StirFryPotActionEnum.取原料): + MenuStep += items.Actions + ","; + break; + case nameof(StirFryPotActionEnum.开启搅拌): + MenuStep += items.Actions + ","; + break; + case nameof(StirFryPotActionEnum.设置搅拌挡位1): + MenuStep += items.Actions + ","; + break; + case nameof(StirFryPotActionEnum.设置搅拌挡位2): + MenuStep += items.Actions + ","; + break; + case nameof(StirFryPotActionEnum.设置搅拌挡位3): + MenuStep += items.Actions + ","; + break; + case nameof(StirFryPotActionEnum.关闭搅拌): + MenuStep += items.Actions + ","; + break; + case nameof(StirFryPotActionEnum.出餐启动): + MenuStep += items.Actions + ","; + break; + case nameof(StirFryPotActionEnum.道菜启动): + MenuStep += items.Actions + ","; + break; + case nameof(StirFryPotActionEnum.炒制菜品): + MenuStep += items.Actions + ","; + break; + case nameof(StirFryPotActionEnum.搅拌臂原点位): + MenuStep += items.Actions + ","; + break; + case nameof(StirFryPotActionEnum.搅拌臂炒制位): + MenuStep += items.Actions + ","; + break; + case nameof(StirFryPotActionEnum.洗锅): + MenuStep += items.Actions + ","; + break; + default: + break; + + } } - - + MessageLog.GetInstance.Show(MenuStep); } - MessageLog.GetInstance.Show(MenuStep); - - + if (stirFry.stirFrymessage.materials.Count > 0) + { + MaterialSurplusOperation.GetInstance().UpdateSurplusAll(stirFry.stirFrymessage.materials); + SaveMaterialData(); + } } + } }); } @@ -2005,22 +2205,41 @@ namespace BPASmartClient.MorkF case nameof(StirFryPotActionEnum.取原料): //炒锅取菜状态置为未取到 morkFs[i].GetMaterialComplete = false; - if(getMaterailNum == 0) + if(potActions.MaterialLists != null) { - if (NoMaterial2Coordinate("A2", out myCoordinate)) + foreach (var item in potActions.MaterialLists) { - materialOperationQuenes.Enqueue(new MaterialOperation() { fryNum = i, coordinate = myCoordinate }); - getMaterailNum++; + //通过ID获取有效的菜品对象 + MaterialInfo materialInfo = MaterialSurplusOperation.GetInstance().GetVailedMaterial(item.MaterialId); + if (materialInfo == null) + { + MessageLog.GetInstance.Show($"炒锅{i}获取菜品[{materialInfo.Name}]失败,库存不足"); + continue; + } + + materialOperationQuenes.Enqueue(new MaterialOperation { materialInfo = materialInfo, fryNum = i }); } } - else if(getMaterailNum == 1) + else { - if (NoMaterial2Coordinate("B2", out myCoordinate)) - { - materialOperationQuenes.Enqueue(new MaterialOperation() { fryNum = i, coordinate = myCoordinate }); - getMaterailNum++; - } + MessageLog.GetInstance.Show($"炒锅{i}获取菜品失败,菜品列表为空"); } + //if(getMaterailNum == 0) + //{ + // if (NoMaterial2Coordinate(MaterialCoordinate.MLNumberList[1], out myCoordinate)) + // { + // materialOperationQuenes.Enqueue(new MaterialOperation() { fryNum = i, coordinate = myCoordinate }); + // getMaterailNum++; + // } + //} + //else if(getMaterailNum == 1) + //{ + // if (NoMaterial2Coordinate(MaterialCoordinate.MLNumberList[4], out myCoordinate)) + // { + // materialOperationQuenes.Enqueue(new MaterialOperation() { fryNum = i, coordinate = myCoordinate }); + // getMaterailNum++; + // } + //} MessageLog.GetInstance.Show(potActions.Actions); break; case nameof(StirFryPotActionEnum.开启搅拌): @@ -2047,7 +2266,7 @@ namespace BPASmartClient.MorkF MessageLog.GetInstance.Show(potActions.Actions); break; case nameof(StirFryPotActionEnum.道菜启动): - OutFood(i); + OutFood(i, true); break; case nameof(StirFryPotActionEnum.炒制菜品): Thread.Sleep(potActions.During * 1000); @@ -2075,8 +2294,6 @@ namespace BPASmartClient.MorkF StirArmGoOrigin(i); MessageLog.GetInstance.Show($"菜品{res.GoodName}完成"); - - } catch (Exception ex) { @@ -2099,8 +2316,6 @@ namespace BPASmartClient.MorkF } } - private int testNum = 0; - /// /// 菜品库主流程 /// @@ -2108,21 +2323,21 @@ namespace BPASmartClient.MorkF { if(materialOperationQuenes.Count > 0) { - //判断是否初始化与是否在工作中 - if (ml_morkf.InitialComplete && !ml_morkf.MaterailIsWorking) - { + ////判断是否初始化与是否在工作中 + //if (ml_morkf.InitialComplete && !ml_morkf.MaterailIsWorking) + //{ //待菜品库操作列出队列 if (materialOperationQuenes.TryDequeue(out var res)) { + ml_morkf.MaterailIsWorking = true; MessageLog.GetInstance.Show("开始操作菜品库"); //ThreadManage.GetInstance().Start(new Action(()=>{ // GetMaterail(res.x, res.y, res.fryNum); //}),"菜品库操作"); - GetMaterailTest(res.coordinate); - testNum++; + GetMaterailTest(res); } - } + //} } } @@ -2137,11 +2352,35 @@ namespace BPASmartClient.MorkF private void ScreenDataServer() { - LocalMqtt.GetInstance.Init(ScreenDeviceType.大炒); + LocalMqtt.GetInstance.Init(ScreenDeviceType.小炒); ThreadManage.GetInstance().StartLong(new Action(() => { List statsModels = new List(); statsModels.Add(new StatsModel() { Name = "帝王蟹", Count = 666 }); + int i = new Random().Next(0, 100); + List processModels= new List(); + switch ((i / 5) % 6) + { + case 0: + processModels = new List() { new ProcessModel() { Id = 1, Name = "启动", Status = ProcessStatus.正在执行 }, new ProcessModel() { Id = 1, Name = "热油", Status = ProcessStatus.未执行 }, new ProcessModel() { Id = 1, Name = "炒制", Status = ProcessStatus.未执行 }, new ProcessModel() { Id = 1, Name = "出餐", Status = ProcessStatus.未执行 }, new ProcessModel() { Id = 1, Name = "结束", Status = ProcessStatus.未执行 } }; + break; + case 1: + processModels = new List() { new ProcessModel() { Id = 1, Name = "启动", Status = ProcessStatus.执行完成 }, new ProcessModel() { Id = 1, Name = "热油", Status = ProcessStatus.正在执行 }, new ProcessModel() { Id = 1, Name = "炒制", Status = ProcessStatus.未执行 }, new ProcessModel() { Id = 1, Name = "出餐", Status = ProcessStatus.未执行 }, new ProcessModel() { Id = 1, Name = "结束", Status = ProcessStatus.未执行 } }; + break; + case 2: + processModels = new List() { new ProcessModel() { Id = 1, Name = "启动", Status = ProcessStatus.执行完成 }, new ProcessModel() { Id = 1, Name = "热油", Status = ProcessStatus.执行完成 }, new ProcessModel() { Id = 1, Name = "炒制", Status = ProcessStatus.正在执行 }, new ProcessModel() { Id = 1, Name = "出餐", Status = ProcessStatus.未执行 }, new ProcessModel() { Id = 1, Name = "结束", Status = ProcessStatus.未执行 } }; + break; + case 3: + processModels = new List() { new ProcessModel() { Id = 1, Name = "启动", Status = ProcessStatus.执行完成 }, new ProcessModel() { Id = 1, Name = "热油", Status = ProcessStatus.执行完成 }, new ProcessModel() { Id = 1, Name = "炒制", Status = ProcessStatus.执行完成 }, new ProcessModel() { Id = 1, Name = "出餐", Status = ProcessStatus.正在执行 }, new ProcessModel() { Id = 1, Name = "结束", Status = ProcessStatus.未执行 } }; + break; + case 4: + processModels = new List() { new ProcessModel() { Id = 1, Name = "启动", Status = ProcessStatus.执行完成 }, new ProcessModel() { Id = 1, Name = "热油", Status = ProcessStatus.执行完成 }, new ProcessModel() { Id = 1, Name = "炒制", Status = ProcessStatus.执行完成 }, new ProcessModel() { Id = 1, Name = "出餐", Status = ProcessStatus.执行完成 }, new ProcessModel() { Id = 1, Name = "结束", Status = ProcessStatus.正在执行 } }; + break; + case 5: + processModels = new List() { new ProcessModel() { Id = 1, Name = "启动", Status = ProcessStatus.执行完成 }, new ProcessModel() { Id = 1, Name = "热油", Status = ProcessStatus.执行完成 }, new ProcessModel() { Id = 1, Name = "炒制", Status = ProcessStatus.执行完成 }, new ProcessModel() { Id = 1, Name = "出餐", Status = ProcessStatus.执行完成 }, new ProcessModel() { Id = 1, Name = "结束", Status = ProcessStatus.执行完成 } }; + break; + default: break; + } ScreenModelMinWok maxWok = new ScreenModelMinWok { IsRun = new Random().Next(0, 2) == 0 ? IsRun.运行 : IsRun.停止, //设备是否运行 @@ -2155,7 +2394,8 @@ namespace BPASmartClient.MorkF MinWok_Dishes_2 = "海鲜大餐", MinWok_Task_1 = "炒制菜品",//当前任务 MinWok_Task_2 = "热油", //当前任务 - MinWok_Process_1 = new List(), //炒锅当前任务流程 + //MinWok_Process_1 = new List() { new ProcessModel() { Id = 1, Name = "启动", Status = ProcessStatus.正在执行 }, new ProcessModel() { Id = 1, Name = "热油", Status = ProcessStatus.未执行 }, new ProcessModel() { Id = 1, Name = "炒制", Status = ProcessStatus.未执行 }, new ProcessModel() { Id = 1, Name = "出餐", Status = ProcessStatus.未执行 }, new ProcessModel() { Id = 1, Name = "结束", Status = ProcessStatus.未执行 } }, + MinWok_Process_1 = processModels, //炒锅当前任务流程 MinWok_Process_2 = new List(), //炒锅当前任务流程 MinWok_HeatGear_1 = new Random().Next(0, 5).ToString(), //炒锅加热档位 MinWok_HeatGear_2 = new Random().Next(0, 5).ToString(), //炒锅加热档位 @@ -2194,9 +2434,9 @@ namespace BPASmartClient.MorkF try { - if(dicNoMaterialCoordinate.ContainsKey(no)) + if(MaterialCoordinate.GetInstance().dicNoMaterialCoordinate.ContainsKey(no)) { - coordinate = dicNoMaterialCoordinate[no]; + coordinate = MaterialCoordinate.GetInstance().dicNoMaterialCoordinate[no]; return true; } else @@ -2214,43 +2454,6 @@ namespace BPASmartClient.MorkF } } - /// - /// 每个取菜点的编号与坐标字典 - /// - private static Dictionary dicNoMaterialCoordinate { get; set; } = new Dictionary() - { - {"A1",new Coordinate(){ X = 34500,Y=0} }, - {"A2",new Coordinate(){ X = 34500,Y=9000} }, - {"A3",new Coordinate(){ X = 34500,Y=0} }, - {"B1",new Coordinate(){ X = 34500,Y=0} }, - {"B2",new Coordinate(){ X = 34500,Y=83000} }, - {"B3",new Coordinate(){ X = 34500,Y=0} }, - {"C1",new Coordinate(){ X = 34500,Y=0} }, - {"C2",new Coordinate(){ X = 34500,Y=0} }, - {"C3",new Coordinate(){ X = 34500,Y=0} }, - {"D1",new Coordinate(){ X = 0,Y=0} }, - {"D2",new Coordinate(){ X = 0,Y=0} }, - {"D3",new Coordinate(){ X = 0,Y=0} }, - {"E1",new Coordinate(){ X = 0,Y=0} }, - {"E2",new Coordinate(){ X = 0,Y=0} }, - {"E3",new Coordinate(){ X = 0,Y=0} }, - {"F1",new Coordinate(){ X = 0,Y=0} }, - {"F2",new Coordinate(){ X = 0,Y=0} }, - {"F3",new Coordinate(){ X = 0,Y=0} }, - {"G1",new Coordinate(){ X = 0,Y=0} }, - {"G2",new Coordinate(){ X = 0,Y=0} }, - {"G3",new Coordinate(){ X = 0,Y=0} }, - {"H1",new Coordinate(){ X = 0,Y=0} }, - {"H2",new Coordinate(){ X = 0,Y=0} }, - {"H3",new Coordinate(){ X = 0,Y=0} }, - {"I1",new Coordinate(){ X = 0,Y=0} }, - {"I2",new Coordinate(){ X = 0,Y=0} }, - {"I3",new Coordinate(){ X = 0,Y=0} }, - {"J1",new Coordinate(){ X = 0,Y=0} }, - {"J2",new Coordinate(){ X = 0,Y=0} }, - {"J3",new Coordinate(){ X = 0,Y=0} }, - }; - public enum Laser2CoordinateState { MaterialOverdo = 0,//菜品过量 diff --git a/BPASmartClient.MorkF/Model/MaterialCoordinate.cs b/BPASmartClient.MorkF/Model/MaterialCoordinate.cs new file mode 100644 index 00000000..ab00316e --- /dev/null +++ b/BPASmartClient.MorkF/Model/MaterialCoordinate.cs @@ -0,0 +1,99 @@ +using BPA.Helper; +using Org.BouncyCastle.Asn1.X509; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPASmartClient.MorkF.Model +{ + internal class MaterialCoordinate : Singleton + { + public List MLNumberList { get; set; } = new List() { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16" + , "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27" }; + + public List MLCoordinateList { get;set;} = new List() + { new Coordinate() { X = 34500, Y = 0 }, new Coordinate() { X = 34500, Y = 9000 } , new Coordinate() { X = 34500, Y = 0 } , //第1层 + new Coordinate(){ X = 34500,Y=0} , new Coordinate() { X = 34500, Y = 83000 }, new Coordinate(){ X = 34500,Y=0}, //第1层 + new Coordinate(){ X = 34500,Y=0} , new Coordinate() { X = 34500, Y = 0 }, new Coordinate(){ X = 34500,Y=0}, //第1层 + new Coordinate(){ X = 0,Y=0} , new Coordinate() { X = 0, Y = 0 }, new Coordinate(){ X = 0,Y=0}, //第2层 + new Coordinate(){ X = 0,Y=0} , new Coordinate() { X = 0, Y = 0 }, new Coordinate(){ X = 0,Y=0}, //第2层 + new Coordinate(){ X = 0,Y=0} , new Coordinate() { X = 0, Y = 0 }, new Coordinate(){ X = 0,Y=0}, //第2层 + new Coordinate(){ X = 0,Y=0} , new Coordinate() { X = 0, Y = 0 }, new Coordinate(){ X = 0,Y=0}, //第3层 + new Coordinate(){ X = 0,Y=0} , new Coordinate() { X = 0, Y = 0 }, new Coordinate(){ X = 0,Y=0}, //第3层 + new Coordinate(){ X = 0,Y=0} , new Coordinate() { X = 0, Y = 0 }, new Coordinate(){ X = 0,Y=0} //第3层 + }; + + public MaterialCoordinate() + { + if(MLNumberList.Count == MLCoordinateList.Count && MLNumberList.Count == 27) + { + for(int i = 0;i + /// 更新键值对 + /// + /// + /// + /// + public bool UpdateMLCoordinateList(string mlNumber,Coordinate coordinate) + { + if(dicNoMaterialCoordinate.ContainsKey(mlNumber)) + { + dicNoMaterialCoordinate[mlNumber] = coordinate; + return true; + } + else + { + return false; + } + } + + /// + /// 每个取菜点的编号与坐标字典 + /// + public Dictionary dicNoMaterialCoordinate { get; set; } = new Dictionary(); + //{ + // {"A1",new Coordinate(){ X = 34500,Y=0} }, + // {"A2",new Coordinate(){ X = 34500,Y=9000} }, + // {"A3",new Coordinate(){ X = 34500,Y=0} }, + // {"B1",new Coordinate(){ X = 34500,Y=0} }, + // {"B2",new Coordinate(){ X = 34500,Y=83000} }, + // {"B3",new Coordinate(){ X = 34500,Y=0} }, + // {"C1",new Coordinate(){ X = 34500,Y=0} }, + // {"C2",new Coordinate(){ X = 34500,Y=0} }, + // {"C3",new Coordinate(){ X = 34500,Y=0} }, + // {"D1",new Coordinate(){ X = 0,Y=0} }, + // {"D2",new Coordinate(){ X = 0,Y=0} }, + // {"D3",new Coordinate(){ X = 0,Y=0} }, + // {"E1",new Coordinate(){ X = 0,Y=0} }, + // {"E2",new Coordinate(){ X = 0,Y=0} }, + // {"E3",new Coordinate(){ X = 0,Y=0} }, + // {"F1",new Coordinate(){ X = 0,Y=0} }, + // {"F2",new Coordinate(){ X = 0,Y=0} }, + // {"F3",new Coordinate(){ X = 0,Y=0} }, + // {"G1",new Coordinate(){ X = 0,Y=0} }, + // {"G2",new Coordinate(){ X = 0,Y=0} }, + // {"G3",new Coordinate(){ X = 0,Y=0} }, + // {"H1",new Coordinate(){ X = 0,Y=0} }, + // {"H2",new Coordinate(){ X = 0,Y=0} }, + // {"H3",new Coordinate(){ X = 0,Y=0} }, + // {"I1",new Coordinate(){ X = 0,Y=0} }, + // {"I2",new Coordinate(){ X = 0,Y=0} }, + // {"I3",new Coordinate(){ X = 0,Y=0} }, + // {"J1",new Coordinate(){ X = 0,Y=0} }, + // {"J2",new Coordinate(){ X = 0,Y=0} }, + // {"J3",new Coordinate(){ X = 0,Y=0} }, + //}; + } +} diff --git a/BPASmartClient.MorkF/MaterialOperation.cs b/BPASmartClient.MorkF/Model/MaterialOperation.cs similarity index 66% rename from BPASmartClient.MorkF/MaterialOperation.cs rename to BPASmartClient.MorkF/Model/MaterialOperation.cs index 130546bd..9beb7e10 100644 --- a/BPASmartClient.MorkF/MaterialOperation.cs +++ b/BPASmartClient.MorkF/Model/MaterialOperation.cs @@ -1,4 +1,5 @@ -using System; +using BPA.Models; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -20,6 +21,18 @@ namespace BPASmartClient.MorkF { public Coordinate coordinate { get; set; } = new Coordinate(); + /// + /// 菜品编号 + /// + public string id; + + /// + /// 菜品位置 + /// + public string loc; + + public MaterialInfo materialInfo; + /// /// 炒锅编号 /// diff --git a/BPASmartClient.MorkF/Model/MaterialSurplus.cs b/BPASmartClient.MorkF/Model/MaterialSurplus.cs new file mode 100644 index 00000000..dc9d0e18 --- /dev/null +++ b/BPASmartClient.MorkF/Model/MaterialSurplus.cs @@ -0,0 +1,207 @@ +using BPA.Helper; +using BPA.Models; +using BPASmartClient.MorkF.Model; +using System; +using System.Collections.Concurrent; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPASmartClient.MorkF +{ + internal class MaterialSurplusOperation : Singleton + { + public MaterialSurplus materialSurplus { get; set; } = new MaterialSurplus(); + + /// + /// 更新余量 + /// + /// 编号 + /// 余量 + public bool UpdateSurplus(string loc, int surplus) + { + //找到所有id对应的 + MaterialInfo material = materialSurplus.dicSurplus.Find(t => t.Loc == loc); + if(material == null) + { + return false; + } + else + { + material.Qty = decimal.Parse(surplus.ToString()); + return true; + } + } + + /// + /// 返回有效的菜品库对象 + /// + /// + /// + public MaterialInfo GetVailedMaterial(string id) + { + int surplus = 0; + //获取该菜品所有的余量 + if(!GetAllSurplus(id,out surplus)) + { + return null; + } + + //判断库存数量是否有效 + if(surplus <= 0) + { + return null; + } + + return GetMaterial(id); + } + + /// + /// 根据编号返回余量 + /// + /// 编号 + /// 余量 + /// + private MaterialInfo GetMaterial(string id) + { + //找到所有id对应的 + MaterialInfo material = materialSurplus.dicSurplus.Find(t => t.Id == id && t.Qty != 0); + + return material; + } + + /// + /// 根据编号返回余量 + /// + /// 编号 + /// 余量 + /// + private bool GetAllSurplus(string id, out int surplus) + { + surplus = 0; + //找到所有id对应的 + List materials = materialSurplus.dicSurplus.FindAll(t=>t.Id == id); + if (materials != null) + { + foreach(MaterialInfo material in materials) + { + //surplus += int.Parse(material.Qty.ToString()); + surplus += Convert.ToInt32(material.Qty); + } + return true; + } + else + { + return false; + } + } + + /// + /// 余量减少 + /// + /// + /// + public bool ReduceSurplus(string loc) + { + MaterialInfo materialInfo = materialSurplus.dicSurplus.Find(t => t.Loc == loc); + if (materialInfo != null) + { + materialInfo.Qty--; + return true; + } + else + { + return false; + } + } + + /// + /// 余量增加 + /// + /// + /// + public bool AddSurplus(string loc) + { + MaterialInfo materialInfo = materialSurplus.dicSurplus.Find(t => t.Loc == loc); + if (materialInfo != null) + { + materialInfo.Qty++; + return true; + } + else + { + return false; + } + } + + /// + /// + /// + /// + public void UpdateSurplusAll(List newMaterialSurplus) + { + if (newMaterialSurplus != null) + { + List materialInfos = materialSurplus.dicSurplus; + if(materialInfos.Count != newMaterialSurplus.Count) + { + materialInfos.Clear(); + materialSurplus.dicSurplus = newMaterialSurplus; + } + else + { + MaterialInfo findMaterial = null; + //遍历旧菜品库,是否与服务器的新菜品库一致 + foreach (MaterialInfo materialInfo in materialSurplus.dicSurplus) + { + //查找该菜品是否还在 + findMaterial = newMaterialSurplus.Find(t => (t.Id == materialInfo.Id && t.Loc == materialInfo.Loc)); + //不存在则准备移除 + if (findMaterial == null) + { + //查找该菜品是否还在 + //位置上的菜品可能会更变 + findMaterial = newMaterialSurplus.Find(t => (t.Loc == materialInfo.Loc)); + if (findMaterial != null) + { + materialInfo.Qty = findMaterial.Qty; + materialInfo.Key = findMaterial.Key; + materialInfo.Id = findMaterial.Id; + materialInfo.Name = findMaterial.Name; + } + } + //存在则更新菜品库数据 + else + { + materialInfo.Qty = findMaterial.Qty; + materialInfo.Key = findMaterial.Key; + materialInfo.Name = findMaterial.Name; + } + } + } + } + else + { + //materialSurplus.dicSurplus.Clear(); + } + } + } + internal class MaterialSurplus + { + /// + /// 余量字典,key:菜品库编号,value:余量 + /// + public List dicSurplus = new List(); + + //public MaterialSurplus() + //{ + // //增加新的 + // foreach (var item in MaterialCoordinate.MLNumberList) + // { + // dicSurplus.Add(item, 0); + // } + //} + + } +} diff --git a/BPASmartClient.MorkF/View/DebugView.xaml b/BPASmartClient.MorkF/View/DebugView.xaml index 9b3ad9a5..d38f9db3 100644 --- a/BPASmartClient.MorkF/View/DebugView.xaml +++ b/BPASmartClient.MorkF/View/DebugView.xaml @@ -76,6 +76,7 @@