diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 09568588..e89d3e1a 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -35,145 +35,96 @@ tools:replace="android:icon"> + android:exported="false" tools:ignore="Instantiatable"/> + android:exported="false" tools:ignore="Instantiatable"/> + android:exported="false" tools:ignore="Instantiatable"/> + android:exported="false" tools:ignore="Instantiatable"/> + android:exported="false" tools:ignore="Instantiatable"/> + android:exported="false" tools:ignore="Instantiatable"/> + android:exported="false" tools:ignore="Instantiatable"/> + android:exported="false" tools:ignore="Instantiatable"/> + android:exported="false" tools:ignore="Instantiatable"/> + android:exported="false" tools:ignore="Instantiatable"/> + android:exported="false" tools:ignore="Instantiatable"/> + android:exported="false" tools:ignore="Instantiatable"/> + android:exported="false" tools:ignore="Instantiatable"/> + android:exported="false" tools:ignore="Instantiatable"/> + android:exported="false" tools:ignore="Instantiatable"/> + android:exported="false" tools:ignore="Instantiatable"/> + android:exported="false" tools:ignore="Instantiatable"/> + android:exported="false" tools:ignore="Instantiatable"/> + android:exported="false" tools:ignore="Instantiatable"/> + android:exported="false" tools:ignore="Instantiatable"/> + android:exported="false" tools:ignore="Instantiatable"/> + android:exported="false" tools:ignore="Instantiatable"/> + android:exported="false" tools:ignore="Instantiatable"/> + android:exported="false" tools:ignore="Instantiatable"/> + android:exported="false" tools:ignore="Instantiatable"/> + android:exported="false" + tools:ignore="Instantiatable" /> - - - - - - - - - - - - - - @@ -217,8 +168,7 @@ --> - - + diff --git a/app/src/main/java/com/bonait/bnframework/business/ConfigData.java b/app/src/main/java/com/bonait/bnframework/business/ConfigData.java index 974eda83..21a72df8 100644 --- a/app/src/main/java/com/bonait/bnframework/business/ConfigData.java +++ b/app/src/main/java/com/bonait/bnframework/business/ConfigData.java @@ -111,6 +111,7 @@ public class ConfigData { LoadingPZ(); //3.初始化业务 //4.初始化日志上报adad + PLC_Init(); } /** diff --git a/app/src/main/java/com/bonait/bnframework/business/ExecuteTheRecipe.java b/app/src/main/java/com/bonait/bnframework/business/ExecuteTheRecipe.java index 9cd24455..49444619 100644 --- a/app/src/main/java/com/bonait/bnframework/business/ExecuteTheRecipe.java +++ b/app/src/main/java/com/bonait/bnframework/business/ExecuteTheRecipe.java @@ -9,17 +9,23 @@ import android.util.Log; import androidx.annotation.NonNull; import com.bonait.bnframework.common.constant.ConfigName; +import com.bonait.bnframework.common.constant.DataBus; import com.bonait.bnframework.common.db.QueryDB; import com.bonait.bnframework.common.db.mode.BPA_GOODSRECIPE; import com.bonait.bnframework.common.db.mode.BPA_MATERIAL; import com.bonait.bnframework.common.db.mode.BPA_PLCADDRESS; import com.bonait.bnframework.common.db.mode.BPA_SILOS; +import com.bonait.bnframework.common.db.res.AlertLogEnum; +import com.bonait.bnframework.common.db.res.ResGoodsMake; +import com.bonait.bnframework.common.db.res.ResGoodsRecipe; +import com.bonait.bnframework.common.db.res.UserLogEnum; import com.bonait.bnframework.common.helper.ByteHelper; import com.bonait.bnframework.common.helper.I.IReadCallBack; import com.bonait.bnframework.common.helper.I.IRun; import com.bonait.bnframework.common.helper.I.IRunT; import com.bonait.bnframework.common.helper.I.IThread; import com.bonait.bnframework.common.helper.I.IWriteCallBack; +import com.bonait.bnframework.common.helper.MessageLog; import com.bonait.bnframework.common.helper.RTrig; import com.bonait.bnframework.common.helper.ThreadManager; import com.bonait.bnframework.common.modbus.ModbusTcpServer; @@ -33,6 +39,7 @@ import com.qmuiteam.qmui.widget.dialog.QMUIDialogAction; import java.util.ArrayList; import java.util.HashMap; import java.util.IdentityHashMap; +import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; @@ -61,25 +68,9 @@ public class ExecuteTheRecipe { public static ConcurrentHashMap IoStatus = new ConcurrentHashMap(); /** - * 外部界面 + * 商品是否制作 */ - public static Context context = null; - - /** - * 商品是否强制结束 - */ - public static boolean IsForcedEnd = false; - - /** - * 当前配方 - */ - static ArrayList all_list=new ArrayList<>(); - - static BPA_GOODSRECIPE selectpf; - /** - * 当前工序的index - */ - static int Index_select=0; + public static boolean IsMakeGood = false; /** * 扫码信息 @@ -107,194 +98,31 @@ public class ExecuteTheRecipe { */ public static IRun CleaningComplete; - //endregion - - //region 强制结束 /** - * 设置强制结束 + * 当前制作商品 */ - public static void SetForcedEnd() - { - ToastUtils.info("客官,小菠萝正在强制结束当前炒制菜品,请耐心等候!!!"); - IsForcedEnd=true; - } - - /** - * 停止强制结束 - */ - public static void StopForcedEnd() - { - IsForcedEnd=false; - } + public static ResGoodsMake GoodMake=null; //endregion //region 执行配方 /** * 执行配方 * - * @param recipe + * @param * @return */ - public static boolean Execute(BPA_GOODSRECIPE recipe,ArrayList all,int index) { - boolean status = false; - all_list=all; - selectpf=recipe; - Index_select=index; + public static void Execute(ResGoodsMake makegood) { try { - //1.解析 - if(IsForcedEnd) - { - ToastUtils.info("客官,小菠萝正在强制结束当前炒制菜品,请耐心等候!!!"); - return false; - } - ToastUtils.info("开始执行:" + recipe.sort + "、" + recipe.processms); - if (recipe.materialType == 0)//正常物料 - { - ExecuteMaterialIssuance(recipe.processvalue); - } else if (recipe.materialType == 1)//工序模型 - { - ExecuteOperationSteps(recipe.processname, recipe.processvalue); - } + GoodMake=makegood; + IsMakeGood=true; } catch (Exception ex) { ToastUtils.error("异常信息:" + ex.getMessage()); - status = false; } finally { - return status; } } - /** - * 液体物料信息-配料 - * - * @param text - */ - private static void ExecuteMaterialIssuance(String text) { - try { - ToastUtils.info("准备下料!!!"); - - if (!text.isEmpty()) { - //仓号 值 - HashMap formulation = new HashMap<>(); - //region 获取仓号和值 - List data = new ArrayList<>(); - if (text.contains("|")) { - String[] res = text.split("[|]"); - for (int i = 0; i < res.length; i++) { - data.add(res[i]); - } - } else { - data.add(text); - } - for (String item : data) { - if (!item.isEmpty() && item.contains(",")) { - String[] wl = item.split("[,]"); - if (wl != null && wl.length == 2) { - String name = wl[0]; - int val = (int)Math.round((Double.parseDouble(wl[1]) * 10)); - //int val = Integer.parseInt(wl[1]); - List bpa_silos = QueryDB.GetSolisByMaterialName(name); - if (bpa_silos.size() > 0 && val > 0) { - BPA_SILOS silos = bpa_silos.get(0); - formulation.put(silos.num, val); - } - } - } - } - //endregion - //写入PLC,直接出料,不用等待 - for (Map.Entry entry : formulation.entrySet()) { - Integer key = entry.getKey(); - Integer value = entry.getValue(); - Write_PLC_Material(key, value); - } - Thread.sleep(200);//等待写入完成 - - //一直等待下料完成 否则就一直等待 40s超时 - for (Map.Entry entry : formulation.entrySet()) { - Integer num = entry.getKey(); - Integer val = entry.getValue(); - String name = "料仓" + num + "下料完成"; - final boolean[] IsComplete = {false}; - long a = System.currentTimeMillis(); - while (!IsComplete[0]) { - if ((System.currentTimeMillis() - a) > 1000 * whileTime) { - break; - } else { - Object sb = ReadPLC(name);// ListeningValue.get(name); - if (sb != null) { - IsComplete[0] = (boolean) (sb); - } - } - Thread.sleep(100);//10 *6 - } - ToastUtils.info(name); - } - } - } catch (Exception ex) { - ToastUtils.error("异常信息:" + ex.getMessage()); - } - } - /** - * 执行工序步骤 - * - * @param text - */ - private static void ExecuteOperationSteps(String processname, String text) { - try { - if (!text.isEmpty() && !processname.isEmpty()) { - //工序名称和值 - HashMap formulation = new HashMap<>(); - //region 获取仓号和值 - List data = new ArrayList<>(); - if (text.contains("|")) { - String[] res = text.split("[|]"); - for (int i = 0; i < res.length; i++) { - data.add(res[i]); - } - } else { - data.add(text); - } - for (String item : data) { - if (!item.isEmpty() && item.contains(",")) { - String[] wl = item.split("[,]"); - if (wl != null && wl.length == 2) { - String name = wl[0]; - String val = wl[1]; - formulation.put(name, val); - } - } - } - //endregion - //写入PLC - if (formulation.size() > 0) { - switch (processname) { - case "搅拌": - Write_PLC_Stir(formulation); - break; - case "位置": - Write_PLC_Location(formulation); - break; - case "加热": - Write_PLC_Heating(formulation); - break; - case "主料": - Write_PLC_Ingredients(formulation); - break; - case "延迟": - Write_PLC_Delay(formulation); - break; - case "出菜": - Write_PLC_Outdishes(formulation); - break; - } - } - } - } catch (Exception ex) { - ToastUtils.error("异常信息:" + ex.getMessage()); - } - } //endregion //region 物料PLC控制 @@ -340,275 +168,6 @@ public class ExecuteTheRecipe { //endregion //region 写PLC工序 - - /** - * 写PLC搅拌 - * - * @param data - */ - private static void Write_PLC_Stir(HashMap data) { - try { - int val=0; - - for (HashMap.Entry entry : data.entrySet()) { - String key = entry.getKey(); - String value = entry.getValue(); - ToastUtils.info("工序:" + key + "," + value); - if (key.contains("(秒)")) { - val = Integer.parseInt(value); - } else { - int writeValue = GetMXValue(key, value); - WritePLC(key, writeValue, new IWriteCallBack() { - @Override - public void onSuccess() { - if (writeValue == 0) { - WritePLC("搅拌", false, null); - } else { - WritePLC("搅拌", true, null); - } - } - - @Override - public void onFailure(String ErrorMsg) { - } - }); - } - } - - if(val>0) - { - Thread.sleep(val * 1000); - } - } catch (Exception ex) { - ToastUtils.error("异常信息:" + ex.getMessage()); - } - } - - /** - * 写PLC位置 - * - * @param data - */ - private static void Write_PLC_Location(HashMap data) { - try { - int val=0; - ToastUtils.info("准备控制炒锅移动!!!"); - for (HashMap.Entry entry : data.entrySet()) { - String key = entry.getKey(); - String value = entry.getValue(); - if (key.contains("(秒)")) { - val = Integer.parseInt(value); - } else if (key.contains("速度")) { - int writeValue = GetMXValue(key, value); - WritePLC(key, writeValue, null); - } - } - - for (HashMap.Entry entry : data.entrySet()) { - String key = entry.getKey(); - String value = entry.getValue(); - ToastUtils.info("工序:" + key + "," + value); - if (!key.contains("(秒)") && !key.contains("速度")) { - //原点位,等待机器移动倒响应位置 - BottomClick(value); - - //一直等待机器移动到该位置,否则就一直等待 6s超时 - String name = value + "反馈"; - final boolean[] IsComplete = {false}; - long a = System.currentTimeMillis(); - while (!IsComplete[0]) { - if ((System.currentTimeMillis() - a) > 1000 * whileTime) { - break; - } else { - Object sb = ReadPLC(name);//ListeningValue.get(name); - if (sb != null) { - IsComplete[0] = (boolean) (sb); - } - } - Thread.sleep(100);//10 *6 - } - ToastUtils.info("炒锅到达"+value+",继续制作!!!"); - } - } - - if(val>0) - { - Thread.sleep(val * 1000); - } - } catch (Exception ex) { - ToastUtils.error("异常信息:" + ex.getMessage()); - } - } - - /** - * 写PLC主料 - * - * @param data - */ - private static void Write_PLC_Ingredients(HashMap data) { - try { - //是否手动 - boolean ishand=true; - ToastUtils.info("准备倒入主料!"); - - //region 判断是否手动 - if(ConfigName.getInstance().versionSelectionEnum.equals("大炒版本")) - { - ishand=true; - }else - { - for (HashMap.Entry entry : data.entrySet()) { - String key = entry.getKey(); - String value = entry.getValue(); - if (key.contains("投料动作")) { - if(value.contains("手动投料")) - { - ishand=true; - }else - { - ishand=false; - } - } - } - } - //endregion - - - - if(ishand) - { - if(ConfigName.getInstance().versionSelectionEnum.equals("大炒自动投料版本") || ConfigName.getInstance().versionSelectionEnum.equals("小炒版本")) - { - ExecuteTheRecipe.BottomClick("平移-去1号位"); - } - String name = ""; - String zl = ""; - int val = 0; - for (HashMap.Entry entry : data.entrySet()) { - String key = entry.getKey(); - String value = entry.getValue(); - if (key.contains("名称")) { - name = value; - } else if (key.contains("重量")) { - zl = value; - } - } - ToastUtils.info("工序:手动投料," + name + "," + zl); - String title = "手动投料-温馨提示!"; - String message = "客官请投入主料,[" + name + "]重量" + zl + "g,投入后点击[确定]继续流程!"; - - final boolean[] IsComplete = {false}; - Activity activity = findActivity(context); - if (activity != null) { - activity.runOnUiThread(new Runnable() { - @Override - public void run() { - try { - AlertDialogUtils.showDialog(context, title, message, new QMUIDialogAction.ActionListener() { - @Override - public void onClick(QMUIDialog dialog, int index) { - IsComplete[0] = true; - dialog.dismiss(); - } - }); - } catch (Exception e) { - - } - } - }); - } - - while (!IsComplete[0]) { - Thread.sleep(100);//10 *6 - } - ToastUtils.info("确定完成,继续制作!"); - }else - { - //自动投料 - if(ConfigName.getInstance().versionSelectionEnum.equals("大炒自动投料版本") || ConfigName.getInstance().versionSelectionEnum.equals("小炒版本")) - { - String writeValue = "1号位"; - for (HashMap.Entry entry : data.entrySet()) { - String key = entry.getKey(); - String value = entry.getValue(); - if (key.contains("主料位置")) { - writeValue=value; - } - } - - //1.去某一个位置 - BottomClick("平移-去"+writeValue); - Log.d("平移", "平移-去"+writeValue); - //一直等待机器移动到该位置,否则就一直等待 6s超时 - String name = "平移轴在"+writeValue; - final boolean[] IsComplete = {false}; - long a = System.currentTimeMillis(); - while (!IsComplete[0]) { - if ((System.currentTimeMillis() - a) > 1000 * whileTime) { - break; - } else { - Object sb =ReadPLC(name);// ListeningValue.get(name); - if (sb != null) { - IsComplete[0] = (boolean) (sb); - } - } - Thread.sleep(100);//10 *6 - } - Log.d("平移", name+"已经就位"); - - //2.给倒菜启动 - BottomClick("主料"); - name = "倒菜完成"; - IsComplete[0]=false; - a = System.currentTimeMillis(); - while (!IsComplete[0]) { - if ((System.currentTimeMillis() - a) > 1000 * whileTime) { - break; - } else { - Object sb =ReadPLC(name);// ListeningValue.get(name); - if (sb != null) { - IsComplete[0] = (boolean) (sb); - } - } - Thread.sleep(100);//10 *6 - } - ToastUtils.info("主料倒入完成,继续制作!"); - - } - } - Log.d("倒菜", "倒菜完成了"); - - if(IsMoveYiHaoWei()) - { - if(ConfigName.getInstance().versionSelectionEnum.equals("大炒自动投料版本") || ConfigName.getInstance().versionSelectionEnum.equals("小炒版本")) - { - ExecuteTheRecipe.BottomClick("平移-去1号位"); - Log.d("移动去", "1号位"); - } - } - - //判断是否有烹饪时间 - int val=0; - for (HashMap.Entry entry : data.entrySet()) { - String key = entry.getKey(); - String value = entry.getValue(); - if (key.contains("(秒)")) { - val = Integer.parseInt(value); - } - } - if(val>0) - { - Thread.sleep(val * 1000); - } - - Log.d("烹饪时间", "烹饪时间完成了"); - - - } catch (Exception ex) { - ToastUtils.error("异常信息:" + ex.getMessage()); - } - } - /** * 按下 * @param name @@ -629,7 +188,6 @@ public class ExecuteTheRecipe { } } - private static Activity findActivity(@NonNull Context context) { if (context instanceof Activity) { return (Activity) context; @@ -639,279 +197,212 @@ public class ExecuteTheRecipe { return null; } } - - /** - * 写PLC 加热 - * - * @param data - */ - private static void Write_PLC_Heating(HashMap data) { - try { - int val=0; - for (HashMap.Entry entry : data.entrySet()) { - String key = entry.getKey(); - String value = entry.getValue(); - ToastUtils.info("工序:" + key + "," + value); - if (key.contains("(秒)")) { - val = Integer.parseInt(value); - } else { - int writeValue = GetMXValue(key, value); - WritePLC(key, writeValue, new IWriteCallBack() { - @Override - public void onSuccess() { - if (writeValue == 0) { - WritePLC("加热", false, null); - } else { - WritePLC("加热", true, null); - } - } - - @Override - public void onFailure(String ErrorMsg) { - } - }); - } - } - - if(val>0) - { - Thread.sleep(val * 1000); - } - - } catch (Exception ex) { - ToastUtils.error("异常信息:" + ex.getMessage()); - } - } - - /** - * 写PLC 延迟 - * - * @param data - */ - private static void Write_PLC_Delay(HashMap data) { - try { - for (HashMap.Entry entry : data.entrySet()) { - String key = entry.getKey(); - String value = entry.getValue(); - ToastUtils.info("工序:" + key + "," + value); - if (key.contains("(秒)")) { - int val = Integer.parseInt(value); - Thread.sleep(val * 1000); - } - } - } catch (Exception ex) { - ToastUtils.error("异常信息:" + ex.getMessage()); - } - } - - /** - * 写PLC 出菜 - * - * @param data - */ - private static void Write_PLC_Outdishes(HashMap data) { - try { - ToastUtils.info("准备出菜!"); - - BottomClick("出菜"); - - //一直等待机器移动到该位置,否则就一直等待 6s超时 - String name = "出餐启动反馈"; - final boolean[] IsComplete = {false}; - long a = System.currentTimeMillis(); - while (!IsComplete[0]) { - if ((System.currentTimeMillis() - a) > 1000 * 120) { - break; - } else { - Object sb =ReadPLC(name);//ListeningValue.get(name); - if (sb != null) { - IsComplete[0] = (boolean) (sb); - } - } - Thread.sleep(100);//10 *6 - } - - - for (HashMap.Entry entry : data.entrySet()) { - String key = entry.getKey(); - String value = entry.getValue(); - ToastUtils.info("工序:" + key + "," + value); - if (key.contains("(秒)")) { - int val = Integer.parseInt(value); - Thread.sleep(val * 1000); - } - } - ToastUtils.info("出菜完成,结束制作!"); - } catch (Exception ex) { - ToastUtils.error("异常信息:" + ex.getMessage()); - } - } - //endregion - - //region 判断当前工序后是否还有 主料 不包含 手动配料 - - /** - * 是否还有 主料 不包含 手动配料 如果没有主料的话 那么就是对的 - * @return - */ - public static boolean IsMoveYiHaoWei() - { - boolean IsMove=false; - try{ - int k=0; - ArrayList kkkkkk=new ArrayList<>(); - for (BPA_GOODSRECIPE item:all_list) - { - if(k>Index_select) //查找当前工序 后的步骤 所有主料 - { - if(item.processname.contains("主料") && !item.processvalue.contains("手动投料"))// && - { - kkkkkk.add(item); - } - } - k++; - } - - if(kkkkkk.size()<=0) - { - IsMove=true; - } - - }catch (Exception ex) - { - - }finally { - return IsMove; - } - } - //endregion - - //region 主页按钮 - /** - * 点击摇欠按钮 - * - * @param data - */ - public static void Write_PLC_YaoQian(MyStatus data) { - try { - if (data == MyStatus.Start) { - ToastUtils.info("点击摇浅按钮"); - - } else if (data == MyStatus.Stop) { - ToastUtils.info("点击停摇按钮"); - } - } catch (Exception ex) { - ToastUtils.error("异常信息:" + ex.getMessage()); - } - } - - /** - * 火力点击 - * - * @param data - */ - public static void Write_PLC_HuoLI(int data) { - try { - WritePLC("加热功率", data, new IWriteCallBack() { - @Override - public void onSuccess() { - if (data == 0) { - WritePLC("加热", false, null); - } else { - WritePLC("加热", true, null); - } - } - - @Override - public void onFailure(String ErrorMsg) { - } - }); - ToastUtils.info("火力按钮点击,当前级别:" + data); - - } catch (Exception ex) { - ToastUtils.error("异常信息:" + ex.getMessage()); - } - } //endregion //region PLC监听线程 public static void Listening() { - ConfigName.getInstance().PLC_Address.clear(); - ArrayList address = QueryDB.GetPlcaddressALL(); - for (BPA_PLCADDRESS item : address) { - if (!item.address.isEmpty() && !item.address.equals("-------------")) { - ConfigName.getInstance().PLC_Address.put(item.name, item); - } - } - - ThreadManager.Get().StartLong("PLC设备数据监听", true, new IThread() { +// ConfigName.getInstance().PLC_Address.clear(); +// ArrayList address = QueryDB.GetPlcaddressALL(); +// for (BPA_PLCADDRESS item : address) { +// if (!item.address.isEmpty() && !item.address.equals("-------------")) { +// ConfigName.getInstance().PLC_Address.put(item.name, item); +// } +// } +// +// ThreadManager.Get().StartLong("PLC设备数据监听", true, new IThread() { +// @Override +// public void Run() throws InterruptedException { +// try { +// for (String item : ConfigName.getInstance().PLC_Address.keySet()) { +// String key = item; +// BPA_PLCADDRESS plcaddress = ConfigName.getInstance().PLC_Address.get(item); +// if (plcaddress.isread == 1) { +// Object val = ReadPLC(key); +// ListeningValue.put(key, val); +// } +// } +// } catch (Exception ex) { +// ToastUtils.error("异常信息:" + ex.getMessage()); +// } +// Thread.sleep(100); +// } +// +// @Override +// public void RunComplete() throws InterruptedException { +// +// } +// }); +// +// ThreadManager.Get().StartLong("PLC设备数据监听-扫码信息", true, new IThread() { +// @Override +// public void Run() throws InterruptedException { +// try { +// ReadCode(); +// } catch (Exception ex) { +// ToastUtils.error("异常信息:" + ex.getMessage()); +// } +// Thread.sleep(100); +// } +// +// @Override +// public void RunComplete() throws InterruptedException { +// +// } +// }); +// +// ThreadManager.Get().StartLong("PLC设备数据监听-实时状态", true, new IThread() { +// @Override +// public void Run() throws InterruptedException { +// try { +// ReadPLCStatus(); +// } catch (Exception ex) { +// ToastUtils.error("异常信息:" + ex.getMessage()); +// } +// Thread.sleep(100); +// } +// +// @Override +// public void RunComplete() throws InterruptedException { +// +// } +// }); +// +// ThreadManager.Get().StartLong("PLC设备数据监听-信号检测", true, new IThread() { +// @Override +// public void Run() throws InterruptedException { +// try { +// ChargeSignal(); +// } catch (Exception ex) { +// ToastUtils.error("异常信息:" + ex.getMessage()); +// } +// Thread.sleep(10); +// } +// @Override +// public void RunComplete() throws InterruptedException { +// +// } +// }); + + ThreadManager.Get().StartLong("商品制作线程", true, new IThread() { @Override public void Run() throws InterruptedException { try { - for (String item : ConfigName.getInstance().PLC_Address.keySet()) { - String key = item; - BPA_PLCADDRESS plcaddress = ConfigName.getInstance().PLC_Address.get(item); - if (plcaddress.isread == 1) { - Object val = ReadPLC(key); - ListeningValue.put(key, val); + if(IsMakeGood && GoodMake!=null) + { + ArrayList recipes= GoodMake.recipes; + + //region 根据物料配方排序Sort步骤分组 + LinkedHashMap> rgrs = new LinkedHashMap<>(); + for (int i = 0; i < recipes.size(); i++) { + if (!rgrs.containsKey(recipes.get(i).sort)) + rgrs.put(recipes.get(i).sort, new ArrayList<>()); + rgrs.get(recipes.get(i).sort).add(recipes.get(i)); } - } - } catch (Exception ex) { - ToastUtils.error("异常信息:" + ex.getMessage()); - } - Thread.sleep(100); - } + //endregion - @Override - public void RunComplete() throws InterruptedException { + int count = 0; + for (LinkedHashMap.Entry> entry : rgrs.entrySet()) { - } - }); + //复位完成信号 +// WritePLC("手自切换", true,null); +// WritePLC("配料完成", false,null); + Thread.sleep(10); - ThreadManager.Get().StartLong("PLC设备数据监听-扫码信息", true, new IThread() { - @Override - public void Run() throws InterruptedException { - try { - ReadCode(); - } catch (Exception ex) { - ToastUtils.error("异常信息:" + ex.getMessage()); - } - Thread.sleep(100); - } + final Integer key = entry.getKey(); - @Override - public void RunComplete() throws InterruptedException { - - } - }); + List goodsRecipes = entry.getValue(); - ThreadManager.Get().StartLong("PLC设备数据监听-实时状态", true, new IThread() { - @Override - public void Run() throws InterruptedException { - try { - ReadPLCStatus(); - } catch (Exception ex) { - ToastUtils.error("异常信息:" + ex.getMessage()); - } - Thread.sleep(100); - } - - @Override - public void RunComplete() throws InterruptedException { + //region 当前一次性下发物料集合 + String RecipesNames = ""; + for (ResGoodsRecipe item : goodsRecipes) { + RecipesNames += item.materialName + ","; + } + count=2; + DataBus.getInstance().UpdateGoodsMake(GoodMake.subOrder.id, "步骤【" + key + "】准备下发物料:" + RecipesNames, count, key, false); + ArrayList liaochang = new ArrayList(); + for (int m = 0; m < goodsRecipes.size(); m++) { + ResGoodsRecipe recipe = goodsRecipes.get(m); + final String message = "[" + GoodMake.good.name + "]步骤【" + key + "】下发【" + recipe.materialName + "】"; + + + //获取物料关联的料仓信息 + BPA_SILOS silos = null; + List siloslist = QueryDB.GetSolisByMaterialID(recipe.materialID); + for (BPA_SILOS item : siloslist) { + if(silos==null) + silos = item; + } + if (silos == null) { + MessageLog.ShowUserMessage(UserLogEnum.订单处理日志, message + "下发失败!物料没有管理料仓!"); + } else { + liaochang.add(silos.num); + MessageLog.ShowUserMessage(UserLogEnum.订单处理日志, message + "准备下发【" + silos.num + "】号料仓PLC控制命令,需求量:=" + recipe.value); + int _val = (int)Math.round((Double.parseDouble(recipe.value) * 10)); + +// WritePLC("需求值" + silos.num, (short) _val, new IWriteCallBack() { +// @Override +// public void onSuccess() { +// MessageLog.ShowInfo(message + "下发成功!"); +// } +// +// @Override +// public void onFailure(String ErrorMsg) { +// MessageLog.ShowInfo(message + "下发失败!" + ErrorMsg); +// } +// }); + } + } + //endregion + + //等待配料完成,一直等待 + final boolean[] IsComplete = {false}; + OnChargeMixtureCompleteNotify = new IRun() { + @Override + public void Run() { + IsComplete[0] = true; + MessageLog.ShowUserMessage(UserLogEnum.订单处理日志, "[" + GoodMake.good.name + "]步骤【" + key + "】配料完成!"); + } + }; + + //启动配料 +// WritePLC("配料启动",true,new IWriteCallBack() { +// @Override +// public void onSuccess() { +// MessageLog.ShowInfo("[" + GoodMake.good.name + "]步骤【" + key + "】启动配料成功!"); +// } +// +// @Override +// public void onFailure(String ErrorMsg) { +// MessageLog.ShowInfo("[" + GoodMake.good.name + "]步骤【" + key + "】启动配料失败!"); +// MessageLog.ShowAlertMessage(AlertLogEnum.异常订单未制作日志, "[" + GoodMake.good.name + "]步骤【" + key + "】启动配料失败!"); +// } +// }); + + long a = System.currentTimeMillis(); + while (!IsComplete[0]) { + if ((System.currentTimeMillis() - a) > 1000 * 5) { + break; + } + Thread.sleep(100);//10 *6 + } + //更新缓存商品制作列表状态 + count += goodsRecipes.size(); + DataBus.getInstance().UpdateGoodsMake(GoodMake.subOrder.id, "步骤【" + key + "】:" + RecipesNames + "-配料完成!", count, key, true); + MessageLog.ShowUserMessage(UserLogEnum.订单处理日志, "[" + GoodMake.good.name + "]步骤【" + key + "】下发" + RecipesNames + "执行完成!"); + } - } - }); + DataBus.getInstance().DeleteGoodsMake(GoodMake.subOrder.id); + MessageLog.ShowUserMessage(UserLogEnum.订单处理日志, "[" + GoodMake.good.name + "]-订单执行完成,请取餐!"); - ThreadManager.Get().StartLong("PLC设备数据监听-信号检测", true, new IThread() { - @Override - public void Run() throws InterruptedException { - try { - ChargeSignal(); + GoodMake=null; + IsMakeGood=false; + } } catch (Exception ex) { ToastUtils.error("异常信息:" + ex.getMessage()); + IsMakeGood=false; } - Thread.sleep(10); + Thread.sleep(100); } @Override public void RunComplete() throws InterruptedException { diff --git a/app/src/main/java/com/bonait/bnframework/business/MainInit.java b/app/src/main/java/com/bonait/bnframework/business/MainInit.java index f885d748..fc81f41b 100644 --- a/app/src/main/java/com/bonait/bnframework/business/MainInit.java +++ b/app/src/main/java/com/bonait/bnframework/business/MainInit.java @@ -31,6 +31,7 @@ import com.bonait.bnframework.common.notification.MainNotification; import com.bonait.bnframework.common.utils.AppUtils; import com.bonait.bnframework.common.utils.NetworkUtils; import com.bonait.bnframework.common.utils.PreferenceUtils; +import com.bonait.bnframework.common.utils.ToastUtils; import com.bonait.bnframework.common.utils.WifiInterceptor; import com.bonait.bnframework.manager.ActivityLifecycleManager; import com.lzy.okgo.OkGo; @@ -100,6 +101,7 @@ public class MainInit { InitDBdata(); ConfigData.getInstance().LoadingCloud();//加载云端数据 + DataBus.getInstance().GetTodayNoMake(); //设置连接到有线网络 // NetworkUtils.connetEnternet(app); @@ -240,6 +242,7 @@ public class MainInit { public void UserMsg(UserLogEnum type, String msg) { BPA_LOG log = new BPA_LOG(); log.userID = ConfigName.getInstance().user.userID; + ToastUtils.info(msg); switch (type.toString()) { case "登录日志":log.type=1; diff --git a/app/src/main/java/com/bonait/bnframework/common/constant/DataBus.java b/app/src/main/java/com/bonait/bnframework/common/constant/DataBus.java index 9f5af486..08986565 100644 --- a/app/src/main/java/com/bonait/bnframework/common/constant/DataBus.java +++ b/app/src/main/java/com/bonait/bnframework/common/constant/DataBus.java @@ -26,6 +26,7 @@ import com.bonait.bnframework.common.helper.I.MyClickListener; import com.bonait.bnframework.common.helper.MessageLog; import com.bonait.bnframework.common.helper.mode.OrderA; import com.bonait.bnframework.common.helper.mode.ResultA; +import com.bonait.bnframework.modules.home.adapter.loadinggood_adapter; import com.bonait.bnframework.modules.home.adapter.lsjy_adapter; import com.bonait.bnframework.modules.home.adapter.wdsz_adapter; import com.bonait.bnframework.modules.home.fragment.mode.sdkz_control; @@ -94,6 +95,18 @@ public class DataBus { * 商品制作列表 */ public ArrayList GoodsMake = new ArrayList(); + + public loadinggood_adapter loadinggoodAdapter=null; + public void GetTodayNoMake() + { + GoodsMake.clear(); + ArrayList suborders= QueryDB.GetSubOrdersTodayNoMake(); + for (BPA_SUBORDER item:suborders) + { + AddGoodsMake(item); + } + } + /** * 增加一个订单商品 * @param suborder @@ -126,6 +139,7 @@ public class DataBus { GoodsMake.add(make); MessageLog.ShowUserMessage(UserLogEnum.订单处理日志, "[" + make.good.name + "]准备配料!"); + if(loadinggoodAdapter!=null)loadinggoodAdapter.refresh(); }catch(Exception e){ MessageLog.ShowInfo( "增加订单异常!"+e.getMessage()); } @@ -153,7 +167,10 @@ public class DataBus { GoodsMake.get(m).makeStatus= MakeStatus.制作中; GoodsMake.get(m).makeMs=makeMs; - GoodsMake.get(m).makeProcess=(count/ GoodsMake.get(m).recipes.size())*100; + GoodsMake.get(m).makeProcess=(int)(((count*1.00)/ GoodsMake.get(m).recipes.size())*100); + + if(loadinggoodAdapter!=null)loadinggoodAdapter.refresh(); + return; } } @@ -185,6 +202,9 @@ public class DataBus { { GoodsMake.remove(good); } + + if(loadinggoodAdapter!=null)loadinggoodAdapter.refresh(); + }catch(Exception e){ } } diff --git a/app/src/main/java/com/bonait/bnframework/common/db/QueryDB.java b/app/src/main/java/com/bonait/bnframework/common/db/QueryDB.java index d9e420ac..17661eaf 100644 --- a/app/src/main/java/com/bonait/bnframework/common/db/QueryDB.java +++ b/app/src/main/java/com/bonait/bnframework/common/db/QueryDB.java @@ -1212,6 +1212,29 @@ public class QueryDB { return null; } } + + /** + * 做法ID查询配方关联表 + * + * @param + * @return + */ + public static BPA_GOODSRECIPENAME GetGoodsRecipeNameDesignId(String zfid) { + try { + String orderby = Desc_Time_Up;//出料顺序 + String where = "isDelete=? and design=?"; + String[] args = new String[]{"0", zfid}; + ArrayList data = new ArrayList<>(); + ArrayList obj = Get(BPA_GOODSRECIPENAME.class, where, args, orderby); + for (Object k : obj) { + data.add((BPA_GOODSRECIPENAME) k); + } + return data.size()>0?data.get(0):null; + } catch (Exception e) { + Log.d("商品ID查询配方信息", "商品ID查询配方信息异常: " + e.getMessage()); + return null; + } + } //endregion //region BPA_GOODSRECIPE 商品配方明细表 @@ -1561,7 +1584,25 @@ public class QueryDB { } return data; } +// + /** + * 根据条件查询子订单 + * + * @return + */ + public static ArrayList GetSubOrdersTodayNoMake() { + String orderby = Desc_Time_Down;//先按排序 创建时间倒序 + String sta=new SimpleDateFormat("yyyy-MM-dd 00:00:00").format(new Date()); + String where = "isDelete=? and createTime>=? and status=0"; + String[] args = new String[]{"0", sta}; + ArrayList data = new ArrayList<>(); + ArrayList obj = Get(BPA_SUBORDER.class, where, args, orderby); + for (Object k : obj) { + data.add((BPA_SUBORDER)k); + } + return data; + } /** * 根据条件查询子订单 * diff --git a/app/src/main/java/com/bonait/bnframework/common/tabbar/MainNavigateTabBar.java b/app/src/main/java/com/bonait/bnframework/common/tabbar/MainNavigateTabBar.java index 300241ba..8d1e87e7 100644 --- a/app/src/main/java/com/bonait/bnframework/common/tabbar/MainNavigateTabBar.java +++ b/app/src/main/java/com/bonait/bnframework/common/tabbar/MainNavigateTabBar.java @@ -374,6 +374,4 @@ public class MainNavigateTabBar extends LinearLayout implements View.OnClickList public int getCurrentSelectedTab() { return mCurrentSelectedTab; } - - } diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/activity/BottomNavigationMainActivity.java b/app/src/main/java/com/bonait/bnframework/modules/home/activity/BottomNavigationMainActivity.java index 24a47806..74400a1f 100644 --- a/app/src/main/java/com/bonait/bnframework/modules/home/activity/BottomNavigationMainActivity.java +++ b/app/src/main/java/com/bonait/bnframework/modules/home/activity/BottomNavigationMainActivity.java @@ -21,6 +21,13 @@ import com.bonait.bnframework.common.modbus.ModbusTcpServer; import com.bonait.bnframework.common.tabbar.MainNavigateTabBar; import com.bonait.bnframework.common.utils.NetworkUtils; import com.bonait.bnframework.modules.home.adapter.FragmentAdapter; +import com.bonait.bnframework.modules.home.fragment.DingDanfragment; +import com.bonait.bnframework.modules.home.fragment.GongnengFragment; +import com.bonait.bnframework.modules.home.fragment.GuanLifragment; +import com.bonait.bnframework.modules.home.fragment.JiaoYanFragment; +import com.bonait.bnframework.modules.home.fragment.MakeGoodFragment; +import com.bonait.bnframework.modules.home.fragment.SheZhifragment; +import com.bonait.bnframework.modules.mine.fragment.MyFragment; import com.qmuiteam.qmui.widget.QMUIViewPager; import java.util.ArrayList; @@ -65,16 +72,19 @@ public class BottomNavigationMainActivity extends BaseActivity { super.onDestroy(); } - private List fragmentList; + private List fragmentList=new ArrayList(); /** * viewPager里添加fragment */ private void initFragment() { fragmentList = new ArrayList<>(); - for (Fragment item:ConfigName.getInstance().fragmentList) - { - fragmentList.add(item); - } + fragmentList.add(new GongnengFragment()); + fragmentList.add(new JiaoYanFragment()); + fragmentList.add(new DingDanfragment()); + fragmentList.add(new MakeGoodFragment()); + fragmentList.add(new GuanLifragment()); + fragmentList.add(new SheZhifragment()); + fragmentList.add(new MyFragment()); ConfigName.getInstance().fragmentAdapter = new FragmentAdapter(getSupportFragmentManager(),fragmentList); viewPager.setAdapter(ConfigName.getInstance().fragmentAdapter); ConfigName.getInstance().fragmentAdapter.SetViewPage(viewPager); @@ -82,7 +92,6 @@ public class BottomNavigationMainActivity extends BaseActivity { viewPager.addOnPageChangeListener(pageChangeListener); // 设置viewPager缓存多少个fragment viewPager.setOffscreenPageLimit(7); - // 再来一杯 viewPager.setCurrentItem(3); } diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/adapter/loadinggood_adapter.java b/app/src/main/java/com/bonait/bnframework/modules/home/adapter/loadinggood_adapter.java index c4bafdb8..8384e405 100644 --- a/app/src/main/java/com/bonait/bnframework/modules/home/adapter/loadinggood_adapter.java +++ b/app/src/main/java/com/bonait/bnframework/modules/home/adapter/loadinggood_adapter.java @@ -1,62 +1,165 @@ package com.bonait.bnframework.modules.home.adapter; +import android.app.Activity; import android.content.Context; +import android.content.ContextWrapper; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ArrayAdapter; import android.widget.Button; +import android.widget.ImageView; +import android.widget.ProgressBar; +import android.widget.RelativeLayout; import android.widget.TextView; import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import androidx.recyclerview.widget.RecyclerView; import com.bonait.bnframework.R; +import com.bonait.bnframework.business.ExecuteTheRecipe; +import com.bonait.bnframework.common.constant.DataBus; +import com.bonait.bnframework.common.db.QueryDB; import com.bonait.bnframework.common.db.mode.BPA_MATERIAL; import com.bonait.bnframework.common.db.mode.BPA_SUBORDER; +import com.bonait.bnframework.common.db.res.MakeStatus; +import com.bonait.bnframework.common.db.res.ResGoodsMake; import com.bonait.bnframework.common.helper.I.MyClickListener; +import com.bonait.bnframework.common.utils.AlertDialogUtils; +import com.bonait.bnframework.common.utils.ToastUtils; +import com.qmuiteam.qmui.widget.dialog.QMUIDialog; +import com.qmuiteam.qmui.widget.dialog.QMUIDialogAction; import java.util.ArrayList; import java.util.List; -public class loadinggood_adapter extends ArrayAdapter { +public class loadinggood_adapter extends RecyclerView.Adapter { /** * 内部点击事件 */ private MyClickListener mListener; - private ArrayList datas; + private ArrayList datas= DataBus.getInstance().GoodsMake; int resource1; - public loadinggood_adapter(@NonNull Context context, int resource, @NonNull ArrayList objects, MyClickListener listener) { - super(context, resource, objects); - mListener = listener; - datas=objects; - this.resource1=resource; + public Context conmain; + public Activity activity; + + private final LayoutInflater mLayoutInflater; + + + public loadinggood_adapter(Context context,MyClickListener myClickListener,Activity ac) { + this.conmain = context; + activity=ac; + mListener=myClickListener; + mLayoutInflater = LayoutInflater.from(context); + } + @Override + public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { + View inflate = mLayoutInflater.inflate(R.layout.loadinggood_item, parent, false); + return new MyViewHolder(inflate); + } - //每个子项被滚动到屏幕内的时候会被调用 - @NonNull + @Override - public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) { - BPA_SUBORDER bpa_suborder = (BPA_SUBORDER) getItem(position);//得到当前项选中item实例 - //为每一个子项加载设定的布局 - View view = LayoutInflater.from(getContext()).inflate(resource1, parent, false); - //分别获取 image view 和 textview 的实例 -// TextView name = view.findViewById(R.id.name); -// Button button = view.findViewById(R.id.button_item); -// // 设置要显示的图片和文字 -// name.setText(bpa_material.name); -// name.setOnClickListener(new View.OnClickListener() { -// @Override -// public void onClick(View view) { -// if(mListener!=null) mListener.clickListener(view,bpa_material); -// } -// }); -// -// button.setOnClickListener(new View.OnClickListener() { -// @Override -// public void onClick(View view) { -// if(mListener!=null) mListener.clickListener(view,bpa_material); -// } -// }); - return view; + public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { + if (holder instanceof MyViewHolder) { + MyViewHolder myViewHolder = (MyViewHolder) holder; + ResGoodsMake goodsMake =datas.get(position); + // 设置要显示的图片和文字 + myViewHolder.loading_ProgressBar.setProgress(goodsMake.makeProcess); + myViewHolder.loading_name.setText(goodsMake.good.name); + myViewHolder.loading_status.setText(goodsMake.makeStatus.name()); + myViewHolder.loading_zuofa.setText(goodsMake.subOrder.exp); + myViewHolder.loading_time.setText(goodsMake.subOrder.createTime); + + switch (goodsMake.makeStatus.name()) + { + case "等待制作": + myViewHolder.loading_status.setTextColor(conmain.getResources().getColor(R.color.text4)); + break; + case "制作中": + myViewHolder.loading_status.setTextColor(conmain.getResources().getColor(R.color.green_primary_dark)); + break; + case "制作完成": + myViewHolder.loading_status.setTextColor(conmain.getResources().getColor(R.color.tab_text_normal)); + break; + } + myViewHolder.loading_main.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + if(mListener!=null) mListener.clickListener(view,goodsMake); + } + }); + + myViewHolder.quxiaozhizuo.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + + String title = "温馨提示!"; + String message = "客官确定要取消制作【"+goodsMake.good.name+"】吗?"; + AlertDialogUtils.showDialog(conmain, title, message, new QMUIDialogAction.ActionListener() { + @Override + public void onClick(QMUIDialog dialog, int index) { + DataBus.getInstance().DeleteGoodsMake(goodsMake.subOrder.id); + dialog.dismiss(); + } + }); + + } + }); + } + } + + private Activity findActivity(@NonNull Context context) { + if (context instanceof Activity) { + return (Activity) context; + } else if (context instanceof ContextWrapper) { + return findActivity(((ContextWrapper) context).getBaseContext()); + } else { + return null; + } + } + /** + * 刷新 + * + * @param + */ + public void refresh() { + activity.runOnUiThread(new Runnable() { + @Override + public void run() { + try { + notifyDataSetChanged(); + } catch (Exception e) { + + } + } + }); + } + + @Override + public int getItemCount() { + return datas.size(); + } + + static class MyViewHolder extends RecyclerView.ViewHolder { + RelativeLayout loading_main; + ProgressBar loading_ProgressBar; + TextView loading_name; + TextView loading_zuofa; + TextView loading_status; + TextView loading_time; + + Button quxiaozhizuo; + public MyViewHolder(View view) { + super(view); + loading_main = view.findViewById(R.id.loading_main); + loading_ProgressBar = view.findViewById(R.id.loading_ProgressBar); + loading_name = view.findViewById(R.id.loading_name); + loading_zuofa = view.findViewById(R.id.loading_zuofa); + loading_status = view.findViewById(R.id.loading_status); + loading_time= view.findViewById(R.id.loading_time); + quxiaozhizuo= view.findViewById(R.id.quxiaozhizuo); + } } } \ No newline at end of file diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/MakeGoodFragment.java b/app/src/main/java/com/bonait/bnframework/modules/home/fragment/MakeGoodFragment.java index 2e0163d1..9b264bdb 100644 --- a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/MakeGoodFragment.java +++ b/app/src/main/java/com/bonait/bnframework/modules/home/fragment/MakeGoodFragment.java @@ -8,17 +8,23 @@ import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; import android.content.Context; +import android.content.res.Resources; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.widget.ListView; import com.bonait.bnframework.R; +import com.bonait.bnframework.business.ConfigData; +import com.bonait.bnframework.business.ExecuteTheRecipe; import com.bonait.bnframework.common.base.BaseFragment; +import com.bonait.bnframework.common.constant.DataBus; import com.bonait.bnframework.common.constant.MessageName; import com.bonait.bnframework.common.db.QueryDB; import com.bonait.bnframework.common.db.mode.BPA_GOODS; import com.bonait.bnframework.common.db.mode.BPA_GOODSTYPE; +import com.bonait.bnframework.common.db.res.ResGoodsMake; +import com.bonait.bnframework.common.helper.I.MyClickListener; import com.bonait.bnframework.common.linktab.LinkMode; import com.bonait.bnframework.common.linktab.TopItemDecoration; import com.bonait.bnframework.common.linktab.good.GoodLeftAdapter; @@ -27,11 +33,17 @@ import com.bonait.bnframework.common.linktab.makegood.MakeGoodLeftAdapter; import com.bonait.bnframework.common.linktab.makegood.MakeGoodRightAdapter; import com.bonait.bnframework.common.message.MessageLooper; import com.bonait.bnframework.common.message.MessageManager; +import com.bonait.bnframework.common.utils.AlertDialogUtils; import com.bonait.bnframework.common.utils.ToastUtils; +import com.bonait.bnframework.modules.home.adapter.loadinggood_adapter; import com.bonait.bnframework.modules.home.adapter.wl_adapter; +import com.bonait.bnframework.modules.home.fragment.mode.add_makegood_control; +import com.bonait.bnframework.modules.home.fragment.mode.add_pf_control; import com.litao.slider.NiftySlider; import com.orhanobut.logger.Logger; import com.qmuiteam.qmui.widget.QMUITopBarLayout; +import com.qmuiteam.qmui.widget.dialog.QMUIDialog; +import com.qmuiteam.qmui.widget.dialog.QMUIDialogAction; import java.util.ArrayList; import java.util.Arrays; @@ -67,7 +79,13 @@ public class MakeGoodFragment extends BaseFragment { * 商品制作列表 */ @BindView(R.id.datatab_paiduishangping) - ListView datatab_paiduishangping; + RecyclerView datatab_paiduishangping; + + /** + * 增加配方 + */ + @BindView(R.id.add_makegood) + add_makegood_control add_makegood; private Context context; @@ -94,59 +112,114 @@ public class MakeGoodFragment extends BaseFragment { */ public void Initdata() { - //1.商品类型 - goodstypes = QueryDB.GetGoodsTypeALL(); + if(isAdded()) + { + //1.商品类型 + goodstypes = QueryDB.GetGoodsTypeALL(); - Fdata.clear(); + Fdata.clear(); - int i=0; - for(BPA_GOODSTYPE item :goodstypes) - { - ArrayList goodsm= QueryDB.GetGoodsTypeId(item.id); - Fdata.add(new LinkMode(item, Arrays.asList(goodsm.toArray()), i==0?true:false)); - i++; - } + int i=0; + for(BPA_GOODSTYPE item :goodstypes) + { + ArrayList goodsm= QueryDB.GetGoodsTypeId(item.id); + Fdata.add(new LinkMode(item, Arrays.asList(goodsm.toArray()), i==0?true:false)); + i++; + } - LinearLayoutManager manager = (LinearLayoutManager) rv_right.getLayoutManager(); - MakeGoodLeftAdapter leftAdapter = new MakeGoodLeftAdapter(R.layout.item_left_makegood, Fdata,getResources(),manager); - MakeGoodRightAdapter rightAdapter = new MakeGoodRightAdapter(R.layout.item_right_lc, Fdata,getResources()); - rv_left.setAdapter(leftAdapter); - rv_right.setAdapter(rightAdapter); + LinearLayoutManager manager = (LinearLayoutManager) rv_right.getLayoutManager(); + MakeGoodLeftAdapter leftAdapter = new MakeGoodLeftAdapter(R.layout.item_left_makegood, Fdata,getResources(),manager); + MakeGoodRightAdapter rightAdapter = new MakeGoodRightAdapter(R.layout.item_right_lc, Fdata,getResources()); + rv_left.setAdapter(leftAdapter); + rv_right.setAdapter(rightAdapter); - //添加分组悬浮效果 - List typeListener = new ArrayList<>(); - for (LinkMode item : Fdata) { - typeListener.add(((BPA_GOODSTYPE) item.type).name); - } + //添加分组悬浮效果 + List typeListener = new ArrayList<>(); + for (LinkMode item : Fdata) { + typeListener.add(((BPA_GOODSTYPE) item.type).name); + } - if(rv_right.getItemDecorationCount()>0) - { - rv_right.removeItemDecorationAt(0); - } - TopItemDecoration top = new TopItemDecoration(context, typeListener); - rv_right.addItemDecoration(top); + if(rv_right.getItemDecorationCount()>0) + { + rv_right.removeItemDecorationAt(0); + } + TopItemDecoration top = new TopItemDecoration(context, typeListener); + rv_right.addItemDecoration(top); - //左侧联动 - rv_right.addOnScrollListener(new RecyclerView.OnScrollListener() { - @Override - public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) { - super.onScrolled(recyclerView, dx, dy); - int firstItemPosition = manager.findFirstVisibleItemPosition(); - if (firstItemPosition != -1 && dy != 0) { - rv_left.smoothScrollToPosition(firstItemPosition); - leftAdapter.setChoose(firstItemPosition); + //左侧联动 + rv_right.addOnScrollListener(new RecyclerView.OnScrollListener() { + @Override + public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) { + super.onScrolled(recyclerView, dx, dy); + int firstItemPosition = manager.findFirstVisibleItemPosition(); + if (firstItemPosition != -1 && dy != 0) { + rv_left.smoothScrollToPosition(firstItemPosition); + leftAdapter.setChoose(firstItemPosition); + } } - } - }); + }); + + LoadingGood(); + } + } + /** + * 加载商品 + */ public void LoadingGood() { -// wl_adapter adapter = new wl_adapter(context, R.layout.wl_item, bpa_materials, this); -// datatab_paiduishangping.setAdapter(adapter); + + LinearLayoutManager layoutManager=new LinearLayoutManager(context); + layoutManager.setOrientation(LinearLayoutManager.VERTICAL); + datatab_paiduishangping.setLayoutManager(layoutManager); + + DataBus.getInstance().loadinggoodAdapter = new loadinggood_adapter(context, myClickListener,getActivity()); + datatab_paiduishangping.setAdapter(DataBus.getInstance().loadinggoodAdapter); } + /** + * 点击商品 开始制作 + */ + public MyClickListener myClickListener=new MyClickListener() { + @Override + public void clickListener(View v, Object data) { + ResGoodsMake makegood=(ResGoodsMake)data; + if(ExecuteTheRecipe.IsMakeGood) + { + ToastUtils.warning("请耐心等待上一商品制作完成..."); + return; + } + + if(makegood.subOrder.status==1) + { + ToastUtils.warning("商品:"+makegood.good.name+",已在制作中..."); + return; + } + + if(makegood.subOrder.status==2) + { + ToastUtils.warning("商品:"+makegood.good.name+",已制作完成..."); + return; + } + String title = "温馨提示!"; + String message = "客官确定要开始制作【"+makegood.good.name+"】吗?"; + AlertDialogUtils.showDialog(context, title, message, new QMUIDialogAction.ActionListener() { + @Override + public void onClick(QMUIDialog dialog, int index) { + ExecuteTheRecipe.Execute(makegood); + ToastUtils.warning("商品:"+makegood.good.name+",开始制作"); + dialog.dismiss(); + } + }); + } + + @Override + public void clickListenerNew(View v, int k, Object data) { + + } + }; /** * 初始化TopBar */ @@ -159,7 +232,9 @@ public class MakeGoodFragment extends BaseFragment { public void onMessage(Object msg) { if (msg != null) { BPA_GOODS goods=(BPA_GOODS) msg; - ToastUtils.info("商品:"+goods.name+",加入队列中..."); + + add_makegood.SetData(goods); + add_makegood.setVisibility(View.VISIBLE); } } }); @@ -173,6 +248,23 @@ public class MakeGoodFragment extends BaseFragment { } } }); + + add_makegood.mListener=new MyClickListener() { + @Override + public void clickListener(View v, Object data) { + } + + @Override + public void clickListenerNew(View v, int k, Object data) { + if(k==0) + { + add_makegood.setVisibility(View.GONE); + }else + { + add_makegood.setVisibility(View.GONE); + } + } + }; } diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/mode/add_makegood_control.java b/app/src/main/java/com/bonait/bnframework/modules/home/fragment/mode/add_makegood_control.java new file mode 100644 index 00000000..f72f5f1d --- /dev/null +++ b/app/src/main/java/com/bonait/bnframework/modules/home/fragment/mode/add_makegood_control.java @@ -0,0 +1,245 @@ +package com.bonait.bnframework.modules.home.fragment.mode; + +import android.content.Context; +import android.util.AttributeSet; +import android.view.LayoutInflater; +import android.view.View; +import android.widget.Button; +import android.widget.EditText; +import android.widget.LinearLayout; +import android.widget.ListView; +import android.widget.TextView; + +import androidx.annotation.Nullable; +import androidx.recyclerview.widget.RecyclerView; + +import com.bonait.bnframework.R; +import com.bonait.bnframework.common.constant.ConfigName; +import com.bonait.bnframework.common.constant.DataBus; +import com.bonait.bnframework.common.db.QueryDB; +import com.bonait.bnframework.common.db.mode.BPA_GOODPROPERTY; +import com.bonait.bnframework.common.db.mode.BPA_GOODS; +import com.bonait.bnframework.common.db.mode.BPA_GOODSRECIPE; +import com.bonait.bnframework.common.db.mode.BPA_GOODSRECIPENAME; +import com.bonait.bnframework.common.db.mode.BPA_MATERIAL; +import com.bonait.bnframework.common.db.mode.BPA_ORDER; +import com.bonait.bnframework.common.db.mode.BPA_SUBORDER; +import com.bonait.bnframework.common.db.res.ResGoodProperty; +import com.bonait.bnframework.common.db.res.ResGoodsRecipe; +import com.bonait.bnframework.common.helper.I.MyClickListener; +import com.bonait.bnframework.common.utils.ToastUtils; +import com.bonait.bnframework.common.view.MyLayoutManager; +import com.bonait.bnframework.modules.home.adapter.newneatril_adapter; +import com.bonait.bnframework.modules.home.adapter.pfsx_adapter; +import com.bonait.bnframework.modules.home.adapter.xxpf_adapter; + +import java.util.ArrayList; + +import butterknife.BindView; +import butterknife.ButterKnife; + +public class add_makegood_control extends LinearLayout implements MyClickListener { + + + @BindView(R.id.quzhizuo) + Button quzhizuo; + + @BindView(R.id.close_from_good) + Button close_from_good; + + public BPA_GOODS Good = null; + + @BindView(R.id.datatab_makesx) + ListView datatab_makesx;//属性 + + @BindView(R.id.makegoodtitle) + TextView makegoodtitle;//配方名称 + /** + * 属性数据 + */ + ArrayList bpa_goodproperties = new ArrayList<>(); + /** + * 点击事件 + */ + public MyClickListener mListener = null; + private View root; + + public add_makegood_control(Context context, @Nullable AttributeSet attrs) { + super(context, attrs); + root = LayoutInflater.from(context).inflate(R.layout.dialog_add_makegood, this); + ButterKnife.bind(this, root); + Init(); + } + + + public void Init() { + //初始化界面控件的事件 + initEvent(); + } + + + private void initData() { + //2.填充规则数据,查询所有属性大类 + bpa_goodproperties.clear(); + ArrayList da = QueryDB.GetGoodsPropertyALL("0"); + for (BPA_GOODPROPERTY item : da) { + ResGoodProperty re = new ResGoodProperty(); + re.id = item.id; + re.name = item.name; + + ArrayList zsx = QueryDB.GetGoodsPropertyALL(item.id); + re.child = new ArrayList<>(); + + + ArrayList _chid = new ArrayList<>(); + for (BPA_GOODPROPERTY k : zsx) { + ResGoodProperty m = new ResGoodProperty(); + m.id = k.id; + m.name = k.name; + m.isSelect = false; + _chid.add(m); + } + re.child = _chid; + + bpa_goodproperties.add(re); + } + + for (ResGoodProperty item : bpa_goodproperties) { + int i = 0; + for (ResGoodProperty c : item.child) { + if (i == 0) { + c.isSelect = true; + } + i++; + } + } + + + pfsx_adapter sxadapter = new pfsx_adapter(getContext(), R.layout.pfsx_item, bpa_goodproperties, this); + datatab_makesx.setAdapter(sxadapter); + } + + /** + * 设置数据 + * + * @param + */ + public void SetData(BPA_GOODS good) { + try { + Good = good; + makegoodtitle.setText(Good.name + ""); + initData(); + } catch (Exception ex) { + + } + } + + + private void initEvent() { + quzhizuo.setOnClickListener(new OnClickListener() { + @Override + public void onClick(View view) { + if (mListener != null && SaveData()) { + + mListener.clickListenerNew(view, 1, null); + } + } + }); + close_from_good.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (mListener != null) { + mListener.clickListenerNew(v, 0, null); + } + } + }); + } + + /** + * 保存数据 + */ + public boolean SaveData() { + if (DataValidation()) { + + BPA_ORDER order = new BPA_ORDER(); + order.thirdPartyID = "手动下单"; + order.status = 0; + order.deviceID = ConfigName.getInstance().DeviceId; + order.userID = ConfigName.getInstance().user.userID; + QueryDB.AddOrder(order); + + BPA_SUBORDER suborder = new BPA_SUBORDER(); + suborder.deviceID = ConfigName.getInstance().DeviceId; + suborder.userID = ConfigName.getInstance().user.userID; + suborder.orderID = order.id; + suborder.goodsID = ((BPA_GOODS) Good).id; + suborder.recipeID=goodsrecipename.id; + suborder.number = 1; + suborder.status = 0; + suborder.exp=names; + QueryDB.AddSubOrder(suborder); + + DataBus.getInstance().AddGoodsMake(suborder); + ToastUtils.info("商品:"+Good.name+",加入队列中..."); + return true; + }else + { + return false; + } + } + + BPA_GOODSRECIPENAME goodsrecipename = null; + String pfname = "";//配方名称集合 + String ggids = "";//规格id集合 + String names=""; + /** + * 数据验证 + */ + public boolean DataValidation() { + //1.数据名称不能为空 + ggids = "";names=""; + for (ResGoodProperty item : bpa_goodproperties) { + for (ResGoodProperty k : item.child) { + if (k.isSelect) { + ggids += k.id + ","; + names+="/"+k.name; + } + } + } + + if (!ggids.isEmpty()) { + ggids = ggids.substring(0, ggids.length() - 1); + } + + goodsrecipename = QueryDB.GetGoodsRecipeNameDesignId(ggids); + if (goodsrecipename == null) { + ToastUtils.info("没有查询到配方,不能制作!"); + return false; + } + return true; + } + + + /** + * 点击事件 + * + * @param v + * @param data + */ + @Override + public void clickListener(View v, Object data) { + switch (v.getId()) { + case R.id.name://点击 修改 + + break; + case R.id.button_item://删除按钮 + + break; + } + } + + @Override + public void clickListenerNew(View v, int k, Object data) { + + } +} \ No newline at end of file diff --git a/app/src/main/res/drawable/progressbar.xml b/app/src/main/res/drawable/progressbar.xml new file mode 100644 index 00000000..de5d2d4f --- /dev/null +++ b/app/src/main/res/drawable/progressbar.xml @@ -0,0 +1,43 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/fragment_make_good.xml b/app/src/main/res/layout/fragment_make_good.xml index d3e22ffa..d128c921 100644 --- a/app/src/main/res/layout/fragment_make_good.xml +++ b/app/src/main/res/layout/fragment_make_good.xml @@ -53,26 +53,37 @@ app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" android:layout_height="match_parent"/> + + - + android:layout_width="match_parent" + android:fadingEdge="vertical" + tools:ignore="Suspicious0dp"> + + + + diff --git a/app/src/main/res/layout/item/layout/dialog_add_makegood.xml b/app/src/main/res/layout/item/layout/dialog_add_makegood.xml new file mode 100644 index 00000000..ce0a4ac5 --- /dev/null +++ b/app/src/main/res/layout/item/layout/dialog_add_makegood.xml @@ -0,0 +1,122 @@ + + + + + +