From 3a6b4611221ac3873fbcc483293676ae33be46d5 Mon Sep 17 00:00:00 2001 From: yahaha Date: Sat, 19 Nov 2022 15:49:44 +0800 Subject: [PATCH] =?UTF-8?q?=E8=8F=9C=E5=93=81=E5=BA=93=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E4=B8=8A=E4=BC=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Properties/Settings.Designer.cs | 2 +- BPASmartClient.MorkF/Control_MorkF.cs | 402 ++++++++++++------ .../Model/MaterialCoordinate.cs | 77 ++++ .../{ => Model}/MaterialOperation.cs | 15 +- BPASmartClient.MorkF/Model/MaterialSurplus.cs | 206 +++++++++ 5 files changed, 559 insertions(+), 143 deletions(-) create mode 100644 BPASmartClient.MorkF/Model/MaterialCoordinate.cs rename BPASmartClient.MorkF/{ => Model}/MaterialOperation.cs (66%) create mode 100644 BPASmartClient.MorkF/Model/MaterialSurplus.cs 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.MorkF/Control_MorkF.cs b/BPASmartClient.MorkF/Control_MorkF.cs index 085bf88e..28b26e12 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; @@ -153,6 +153,8 @@ namespace BPASmartClient.MorkF ///初始化菜品库 //FoodLibInit(); Task2ReadMaterialData(); + + //Json.Read(); } /// @@ -900,25 +902,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(); + } + if (!ret) + { + MessageLog.GetInstance.Show($"错误:X轴:{x}获取传感器数据出错"); } - return false; + return ret; } public void PawTurnFront() @@ -1055,26 +1075,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 +1099,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 +1129,14 @@ namespace BPASmartClient.MorkF //爪子去1号位抓菜 if (!PawToPoint1()) { - return; + return false; } #endif //设置到该层菜品库最高处 if (!SetArmPosition(x - materialHigh, y)) { - return; + return false; } ////移动前开启电磁阀 @@ -1135,13 +1147,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 +1181,14 @@ namespace BPASmartClient.MorkF //设置到炒锅1出菜处 if (!SetArmPosition(x, y)) { - return; + return false; } #if true //爪子去3号位放菜 if (!PawToPoint3()) { - return; + return false; } #endif @@ -1188,14 +1200,14 @@ namespace BPASmartClient.MorkF //设置到炒锅1出菜处 if (!SetArmPosition(x + materialToFryDistance, y)) { - return; + return false; } #if true //爪子回到2号位 if (!PawToPoint2()) { - return; + return false; } #endif ////关闭电磁阀 @@ -1205,6 +1217,62 @@ namespace BPASmartClient.MorkF { morkFs[fryNum].GetMaterialComplete = true; } + return true; + } + + /// + /// 更新菜品库存量 + /// + /// + public bool UpdateMaterialLibraryStock() + { + try + { + //判断是否初始化 + if(!ml_morkf.InitialComplete) + { + return false; + } + + foreach(var item in MaterialCoordinate.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 +1327,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 +1414,11 @@ namespace BPASmartClient.MorkF { ml_morkf.MaterailIsWorking = false; } + if (ret == true) + { + //指定位置菜品减一 + MaterialSurplusOperation.GetInstance().ReduceSurplus(materialOperation.materialInfo.Loc); + } } }), $"菜品库操作"); @@ -1469,48 +1578,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 +1632,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 +1759,17 @@ namespace BPASmartClient.MorkF FirePot_Write("LB8", true, num); Thread.Sleep(200); } -#endregion + #endregion + + private static object saveMaterialLock = new object(); + private void SaveMaterialData() + { + lock(saveMaterialLock) + { + Json.Data = MaterialSurplusOperation.GetInstance().materialSurplus; + Json.Save(); + } + } bool isInitialArrive = false; @@ -1698,6 +1822,22 @@ namespace BPASmartClient.MorkF }); } } + if(stirFry.stirFrymessage.materials.Count > 0) + { + MaterialSurplusOperation.GetInstance().UpdateSurplusAll(stirFry.stirFrymessage.materials); + //foreach (var item in stirFry.stirFrymessage.materials) + //{ + // MaterialSurplusOperation.GetInstance().materialSurplus.dicSurplus.Add(new MaterialInfo + // { + // Id = item.Id, + // Key = item.Key, + // Name = item.Name, + // Loc = item.Loc, + // Qty = item.Qty, + // }); + //} + SaveMaterialData(); + } } MessageLog.GetInstance.Show("接收到小炒流程信息"); @@ -2005,22 +2145,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 +2206,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); @@ -2099,8 +2258,6 @@ namespace BPASmartClient.MorkF } } - private int testNum = 0; - /// /// 菜品库主流程 /// @@ -2114,13 +2271,13 @@ namespace BPASmartClient.MorkF //待菜品库操作列出队列 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); } } } @@ -2194,9 +2351,9 @@ namespace BPASmartClient.MorkF try { - if(dicNoMaterialCoordinate.ContainsKey(no)) + if(MaterialCoordinate.dicNoMaterialCoordinate.ContainsKey(no)) { - coordinate = dicNoMaterialCoordinate[no]; + coordinate = MaterialCoordinate.dicNoMaterialCoordinate[no]; return true; } else @@ -2214,43 +2371,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..5b00b0a1 --- /dev/null +++ b/BPASmartClient.MorkF/Model/MaterialCoordinate.cs @@ -0,0 +1,77 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPASmartClient.MorkF.Model +{ + internal class MaterialCoordinate + { + public static List MLNumberList = 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 static List MLCoordinateList = 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 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} }, + //}; + } +} 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..494110b8 --- /dev/null +++ b/BPASmartClient.MorkF/Model/MaterialSurplus.cs @@ -0,0 +1,206 @@ +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 id, int surplus) + { + //找到所有id对应的 + MaterialInfo material = materialSurplus.dicSurplus.Find(t => t.Id == id); + 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()); + } + 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); + // } + //} + + } +}