diff --git a/app/src/main/java/com/example/bpa/app/BusinessServer.java b/app/src/main/java/com/example/bpa/app/BusinessServer.java index e5a470b..4713677 100644 --- a/app/src/main/java/com/example/bpa/app/BusinessServer.java +++ b/app/src/main/java/com/example/bpa/app/BusinessServer.java @@ -6,6 +6,7 @@ import com.example.bpa.Model.IThread; import com.example.bpa.Model.IWriteCallBack; import com.example.bpa.config.DataBus; import com.example.bpa.db.QueryDB; +import com.example.bpa.db.mode.BPA_GOODS; import com.example.bpa.db.mode.BPA_SILOS; import com.example.bpa.db.mode.BPA_SUGAR; import com.example.bpa.helper.MessageLog; @@ -38,12 +39,14 @@ public class BusinessServer { ConcurrentLinkedQueue Commoditys = new ConcurrentLinkedQueue(); /** - * 添加配方 + * 增加一个订单 * * @param info 配方信息 */ public void AddCommodity(String info) { + //1.添加制作队列 Commoditys.offer(info); + //2.数据中心添加制作队列商品数据 DataBus.getInstance().AddGoodsMake(info); } @@ -51,97 +54,117 @@ public class BusinessServer { * 订单制作线程 */ public void Init() { - //DeviceData.Get().TestInit(); - ThreadManager.Get().StartLong("配方执行业务流程", true, new IThread() { + ThreadManager.Get().StartLong("订单执行业务流程", true, new IThread() { @Override public void Run() throws InterruptedException { while (Commoditys.size() > 0) { + //0.验证物料是否充足【待编写】 + //1.取出需要制作的订单商品 String GoodId = Commoditys.poll(); + //2.获取商品的配方信息 ArrayList goods = QueryDB.GetGoodsSrecipeList(GoodId); + BPA_GOODS good= QueryDB.GetGoodsId(GoodId); + //3.根据物料配方排序Sort步骤分组 + //region 根据物料配方排序Sort步骤分组 LinkedHashMap> rgrs = new LinkedHashMap<>(); - - //更具步骤分组 for (int i = 0; i < goods.size(); i++) { if (!rgrs.containsKey(goods.get(i).sort)) rgrs.put(goods.get(i).sort, new ArrayList<>()); rgrs.get(goods.get(i).sort).add(goods.get(i)); } - + //endregion + //4.根据步骤分组进行物料下发 + //region 物料下发 + int count=0; for (LinkedHashMap.Entry> entry : rgrs.entrySet()) { - for (int m = 0; m < entry.getValue().size(); m++) { - int materialType = entry.getValue().get(m).materialType; - //1.正常物料 - if (materialType == 1) { - //1.获取物料关联的料仓信息 - List bss = QueryDB.GetSolisByMaterialID(entry.getValue().get(m).materialID); - //GetsugarId - for (int x = 0; x < bss.size(); x++) { - //if (DeviceData.Get().getCallCurrentWeight(bss.get(x).num) >= (float) entry.getValue().get(m).value) { - MessageLog.ShowInfo("下发【" + bss.get(x).num + "】号料仓PLC控制命令,需求量:=" + entry.getValue().get(m).value); - DeviceData.Get().setDemandValue((short) entry.getValue().get(m).value, bss.get(x).num, new IWriteCallBack() { - @Override - public void onSuccess() { - MessageLog.ShowInfo("下发物料成功!"); - } - - @Override - public void onFailure(String ErrorMsg) { - MessageLog.ShowInfo("下发物料失败!"); - } - }); - //} + final Integer key=entry.getKey(); + //当前一次性下发物料集合 + List goodsRecipes= entry.getValue(); + String RecipesNames=""; + for (ResGoodsRecipe item:goodsRecipes ){RecipesNames+=item.materialName+",";} + DataBus.getInstance().UpdateGoodsMake(good.id,"步骤【" + key+ "】准备下发物料:"+RecipesNames,count); + for (int m = 0; m < goodsRecipes.size(); m++) { + ResGoodsRecipe recipe=goodsRecipes.get(m); + int materialType = recipe.materialType; + final String message="步骤【" + key+ "】下发【"+recipe.materialName+"】"; + if(materialType==1)//1.正常物料 + { + //获取物料关联的料仓信息 + BPA_SILOS silos=null; + List siloslist = QueryDB.GetSolisByMaterialID(recipe.materialID); + for (BPA_SILOS item:siloslist) + { + //临时屏蔽物料量检测 + // if(DeviceData.Get().getCallCurrentWeight(item.num)>=recipe.value){silos=item;break;} + silos=item;break; } - DeviceData.Get().setChargeMixtureStart(new IWriteCallBack() { - @Override - public void onSuccess() { - MessageLog.ShowInfo("启动配料成功!"); - } - - @Override - public void onFailure(String ErrorMsg) { - MessageLog.ShowInfo("启动配料失败!"); - } - });//启动配料 - final boolean[] IsComplete = {false}; - final String goodsID=entry.getValue().get(m).goodsID; - final String materialID=entry.getValue().get(m).materialID; - final String materialName=entry.getValue().get(m).materialName; - DeviceData.Get().OnChargeMixtureCompleteNotify = new IRun() { - @Override - public void Run() { - IsComplete[0] = true; - MessageLog.ShowInfo(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())+":"+materialName+"配料完成!"); - } - }; - while (!IsComplete[0]) { - Thread.sleep(100); + if (silos==null) + { + MessageLog.ShowInfo(message+"下发失败!物料没有管理料仓!"); + }else + { + MessageLog.ShowInfo(message+"准备下发【" + silos.num + "】号料仓PLC控制命令,需求量:=" + recipe.value); + DeviceData.Get().setDemandValue((short) recipe.value, silos.num, new IWriteCallBack() { + @Override + public void onSuccess() { + MessageLog.ShowInfo(message+"下发成功!"); + } + @Override + public void onFailure(String ErrorMsg) { + MessageLog.ShowInfo(message+"下发失败!"+ErrorMsg); + } + }); } - //更新缓存商品制作列表状态 - DataBus.getInstance().UpdateGoodsMake(goodsID,materialID,m); - MessageLog.ShowInfo("步骤【" + entry.getKey() + "】执行完成"); - } - //2.果糖 - else if (materialType == 2) { - BPA_SUGAR bs = QueryDB.GetsugarId(entry.getValue().get(m).materialID); + }else if (materialType == 2)//果糖 + { + BPA_SUGAR bs = QueryDB.GetsugarId(recipe.materialID); ModbusTcpServer.get().WriteBool(bs.plcvar, true); - Thread.sleep(500); + Thread.sleep(200); ModbusTcpServer.get().WriteBool(bs.plcvar, false); - MessageLog.ShowInfo("步骤【" + entry.getKey() + "】下发"+entry.getValue().get(m).materialName+"执行完成"); + MessageLog.ShowInfo(message+"下发成功!"); } } + //启动配料 + DeviceData.Get().setChargeMixtureStart(new IWriteCallBack() { + @Override + public void onSuccess() { + MessageLog.ShowInfo("步骤【" + key+ "】启动配料成功!"); + } + @Override + public void onFailure(String ErrorMsg) { + MessageLog.ShowInfo("步骤【" + key+ "】启动配料失败!"); + } + }); + + //等待配料完成,一直等待 + final boolean[] IsComplete = {false}; + DeviceData.Get().OnChargeMixtureCompleteNotify = new IRun() { + @Override + public void Run() { + IsComplete[0] = true; + MessageLog.ShowInfo("步骤【" + key+ "】配料完成!"); + } + }; + while (!IsComplete[0]) { + Thread.sleep(100); + } + //更新缓存商品制作列表状态 + count+=goodsRecipes.size(); + DataBus.getInstance().UpdateGoodsMake(good.id,"步骤【" + key+ "】:"+RecipesNames+"-配料完成",count); + MessageLog.ShowInfo("步骤【" + key + "】执行完成"); } - //设置商品已制作完成 + //endregion + //5.设置数据中心商品已制作完成 DataBus.getInstance().DeleteGoodsMake(GoodId); - MessageLog.ShowInfo("配方执行完成"); + MessageLog.ShowInfo(good.name+"-订单执行完成"); } Thread.sleep(1000); } - @Override public void RunComplete() throws InterruptedException { - } }); } + } diff --git a/app/src/main/java/com/example/bpa/app/ICSApp.java b/app/src/main/java/com/example/bpa/app/ICSApp.java index 720fd4b..5ebe6ca 100644 --- a/app/src/main/java/com/example/bpa/app/ICSApp.java +++ b/app/src/main/java/com/example/bpa/app/ICSApp.java @@ -39,6 +39,8 @@ public class ICSApp extends Application { Main.getInstance(); //5.PLC数据监控 ModbusTcpServer.get().Connect(ConfigName.getInstance().Address, ConfigName.getInstance().Post); + + BusinessServer.Get().Init(); } /** diff --git a/app/src/main/java/com/example/bpa/config/ConfigName.java b/app/src/main/java/com/example/bpa/config/ConfigName.java index daa22f6..46ec438 100644 --- a/app/src/main/java/com/example/bpa/config/ConfigName.java +++ b/app/src/main/java/com/example/bpa/config/ConfigName.java @@ -25,6 +25,7 @@ public class ConfigName { //region 程序进入界面 public Context dishesCon; + public Context Home; //endregion //region SD卡路径设置 diff --git a/app/src/main/java/com/example/bpa/config/DataBus.java b/app/src/main/java/com/example/bpa/config/DataBus.java index f01b0f4..42efb6c 100644 --- a/app/src/main/java/com/example/bpa/config/DataBus.java +++ b/app/src/main/java/com/example/bpa/config/DataBus.java @@ -54,7 +54,7 @@ public class DataBus { */ public List GoodsMake = new ArrayList(); /** - * 商品制作列表 + * 商品制作完成列表 */ public List GoodsMakeOver = new ArrayList(); /** @@ -83,28 +83,23 @@ public class DataBus { /** * 根据商品id,物料id修改制作进度 - * @param wlid + * @param id + * @param makeMs + * @param count */ - public void UpdateGoodsMake(String id, String wlid,int m) + public void UpdateGoodsMake(String id,String makeMs,int count) { try { - for (ResGoodsMake item:GoodsMake) + for (int m=0;m