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 51a44a2..6f25d9b 100644 --- a/app/src/main/java/com/example/bpa/app/BusinessServer.java +++ b/app/src/main/java/com/example/bpa/app/BusinessServer.java @@ -19,7 +19,7 @@ import java.util.concurrent.ConcurrentLinkedQueue; public class BusinessServer { private static volatile BusinessServer _instance; - public static BusinessServer get() { + public static BusinessServer Get() { if (_instance == null) _instance = new BusinessServer(); return _instance; @@ -28,9 +28,11 @@ public class BusinessServer { private BusinessServer() { } + /** + * 商品制作队列 + */ ConcurrentLinkedQueue Commoditys = new ConcurrentLinkedQueue(); - /** * 添加配方 * @@ -40,8 +42,12 @@ public class BusinessServer { Commoditys.offer(info); } - public void Start() { - DeviceData.Get().TestInit(); + /** + * 订单制作线程 + */ + public void Init() { + //DeviceData.Get().TestInit(); + ThreadManager.Get().StartLong("配方执行业务流程", true, new IThread() { @Override public void Run() throws InterruptedException { @@ -60,6 +66,7 @@ public class BusinessServer { 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) { //获取料仓信息 List bss = QueryDB.GetSolisByMaterialID(entry.getValue().get(m).materialID); @@ -70,7 +77,9 @@ public class BusinessServer { DeviceData.Get().setDemandValue((short) entry.getValue().get(m).value, bss.get(x).num, null); } } - } else if (materialType == 2) { + } + //2.果糖 + else if (materialType == 2) { BPA_SUGAR bs = QueryDB.GetsugarId(entry.getValue().get(m).materialID); ModbusTcpServer.get().WriteBool(bs.plcvar, true); } diff --git a/app/src/main/java/com/example/bpa/app/DeviceData.java b/app/src/main/java/com/example/bpa/app/DeviceData.java index baff4db..98eec04 100644 --- a/app/src/main/java/com/example/bpa/app/DeviceData.java +++ b/app/src/main/java/com/example/bpa/app/DeviceData.java @@ -25,7 +25,7 @@ public class DeviceData { } - //----------------------------------------------------------------Start 测试 ---------------------------------------------------------------- + //----------------------------------------------------------------Start 模拟测试 ---------------------------------------------------------------- ConcurrentLinkedQueue testComms = new ConcurrentLinkedQueue<>(); public void testAddComm(int value) { @@ -52,7 +52,7 @@ public class DeviceData { }); ; } - //----------------------------------------------------------------End 测试 ---------------------------------------------------------------- + //----------------------------------------------------------------End 模拟测试 ---------------------------------------------------------------- //region 初始化 public void Init() { 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 ef49dcf..02eed59 100644 --- a/app/src/main/java/com/example/bpa/app/ICSApp.java +++ b/app/src/main/java/com/example/bpa/app/ICSApp.java @@ -30,8 +30,6 @@ public class ICSApp extends Application { @Override public void onCreate() { super.onCreate(); - - MessageLog.MsgNotify = new IMessageLogNotify() { @Override public void ErrorMsg(String msg) { @@ -57,7 +55,7 @@ public class ICSApp extends Application { //2.初始化SD卡,数据库DB SdCart.getInstance().initSD(); - BusinessServer.get().Start(); + ModbusTcpServer.get().Connect("", 502); //3.初始化数据 InitDBdata(); //4.初始化Main diff --git a/app/src/main/java/com/example/bpa/app/ModbusTcpServer.java b/app/src/main/java/com/example/bpa/app/ModbusTcpServer.java index 145885a..8ba6c01 100644 --- a/app/src/main/java/com/example/bpa/app/ModbusTcpServer.java +++ b/app/src/main/java/com/example/bpa/app/ModbusTcpServer.java @@ -116,6 +116,8 @@ public class ModbusTcpServer { @Override public void onSuccess(ModbusMaster modbusMaster) { MessageLog.ShowInfo("设备 " + host + " 连接成功"); + DeviceData.Get().Init(); + BusinessServer.Get().Init(); } @Override diff --git a/app/src/main/java/com/example/bpa/view/from/yfpf_activity.java b/app/src/main/java/com/example/bpa/view/from/yfpf_activity.java index 7ea7de5..4e93db6 100644 --- a/app/src/main/java/com/example/bpa/view/from/yfpf_activity.java +++ b/app/src/main/java/com/example/bpa/view/from/yfpf_activity.java @@ -54,7 +54,7 @@ public class yfpf_activity extends AppCompatActivity implements View.OnClickList /** * 商品数据 */ - ArrayList bpa_goods=new ArrayList<>(); + ArrayList bpa_goods = new ArrayList<>(); //endregion //region 私有函数 @@ -72,13 +72,13 @@ public class yfpf_activity extends AppCompatActivity implements View.OnClickList /** * 初始化 */ - private void Init(){ + private void Init() { gongneng_fanhui = this.findViewById(R.id.gongneng_fanhui); gongneng_title = this.findViewById(R.id.gongneng_title); - buttonaddpf=this.findViewById(R.id.buttonaddpf); - datatab= this.findViewById(R.id.datatab); + buttonaddpf = this.findViewById(R.id.buttonaddpf); + datatab = this.findViewById(R.id.datatab); //通过Activity.getIntent()获取当前页面接收到的Intent。 getXxxExtra方法获取Intent传递过来的数据 - String msg=getIntent().getStringExtra("data"); + String msg = getIntent().getStringExtra("data"); gongneng_title.setText(msg); Initdata();//初始化数据 RegisterMessage();//消息中心事件接收 @@ -95,19 +95,19 @@ public class yfpf_activity extends AppCompatActivity implements View.OnClickList /** * 初始化数据加载 */ - public void Initdata() - { - try{ - bpa_goods= QueryDB.GetGoodsALL(); - sp_adapter adapter = new sp_adapter(yfpf_activity.this, R.layout.sp_item, bpa_goods,this); + public void Initdata() { + try { + bpa_goods = QueryDB.GetGoodsALL(); + sp_adapter adapter = new sp_adapter(yfpf_activity.this, R.layout.sp_item, bpa_goods, this); datatab.setAdapter(adapter); - }catch(Exception e){ + } catch (Exception e) { } } //endregion //region 点击事件 + /** * 本页面点击事件监听22 * @@ -132,89 +132,82 @@ public class yfpf_activity extends AppCompatActivity implements View.OnClickList * 接口方法,响应ListView按钮点击事件 */ @Override - public void clickListener(View v,Object data) { - switch (v.getId()) - { + public void clickListener(View v, Object data) { + switch (v.getId()) { case R.id.button_item://删除按钮 - int sort=((BPA_GOODS)data).sort; - String id=((BPA_GOODS)data).id; - Log.i("日志",sort + "--- "+id); - QueryDB.DeleteGoods((BPA_GOODS)data); + int sort = ((BPA_GOODS) data).sort; + String id = ((BPA_GOODS) data).id; + Log.i("日志", sort + "--- " + id); + QueryDB.DeleteGoods((BPA_GOODS) data); Initdata(); - for (BPA_GOODS k:bpa_goods) { - if(k.sort>sort) - { - QueryDB.GetGoodsSort(k,1); + for (BPA_GOODS k : bpa_goods) { + if (k.sort > sort) { + QueryDB.GetGoodsSort(k, 1); } } Initdata(); break; case R.id.button_item_Up://上移动按钮 - BPA_GOODS good=(BPA_GOODS)data; - if(good.sort==1) - { + BPA_GOODS good = (BPA_GOODS) data; + if (good.sort == 1) { T.show(this, "已是最顶部!"); return; } - QueryDB.GetGoodsSort((BPA_GOODS)data,1); + QueryDB.GetGoodsSort((BPA_GOODS) data, 1); Initdata(); break; case R.id.button_item_Down://下移动按钮 - BPA_GOODS good2=(BPA_GOODS)data; - if(good2.sort==bpa_goods.size()) - { + BPA_GOODS good2 = (BPA_GOODS) data; + if (good2.sort == bpa_goods.size()) { T.show(this, "已是最底部!"); return; } - QueryDB.GetGoodsSort((BPA_GOODS)data,0); + QueryDB.GetGoodsSort((BPA_GOODS) data, 0); Initdata(); break; case R.id.button_item_update://修改按钮 Intent intent = new Intent(this, add_pf_activity.class); intent.putExtra("title", "修改配方"); - intent.putExtra("data",new Json().objectToJson(BPA_GOODS.class,data)); + intent.putExtra("data", new Json().objectToJson(BPA_GOODS.class, data)); startActivity(intent); break; case R.id.button_xf://下发按钮 - BusinessServer.get().AddCommodity(((BPA_GOODS)data).id); + BusinessServer.Get().AddCommodity(((BPA_GOODS) data).id); T.show(this, "下发成功!"); break; case R.id.button_qy://启用按钮 - BPA_GOODS good3=(BPA_GOODS)data; - good3.status=1; + BPA_GOODS good3 = (BPA_GOODS) data; + good3.status = 1; QueryDB.UpdateGoods(good3); Initdata(); - T.show(this, good3.name+"-启用成功!"); + T.show(this, good3.name + "-启用成功!"); break; case R.id.button_jy://下发按钮 - BPA_GOODS good4=(BPA_GOODS)data; - good4.status=0; + BPA_GOODS good4 = (BPA_GOODS) data; + good4.status = 0; QueryDB.UpdateGoods(good4); Initdata(); - T.show(this, good4.name+"-禁用成功!"); + T.show(this, good4.name + "-禁用成功!"); break; } } //endregion //region 接收事件 - public void RegisterMessage() - { + public void RegisterMessage() { //配方界面关闭事件 MessageManager.getInstance().registerMessageReceiver(this, MessageName.PF_From_Close.name(), new MessageLooper.OnMessageListener() { @Override public void onMessage(Object msg) { if (msg != null) { - if(msg.equals("Close")) - { + if (msg.equals("Close")) { Initdata(); } - }else - { + } else { runOnUiThread(new Runnable() { @Override public void run() { - T.show(yfpf_activity.this,"服务器异常,请稍后重试!"); + T.show(yfpf_activity.this, "服务器异常,请稍后重试!"); } }); } @@ -225,16 +218,14 @@ public class yfpf_activity extends AppCompatActivity implements View.OnClickList @Override public void onMessage(Object msg) { if (msg != null) { - if(msg.equals("Close")) - { + if (msg.equals("Close")) { Initdata(); } - }else - { + } else { runOnUiThread(new Runnable() { @Override public void run() { - T.show(yfpf_activity.this,"服务器异常,请稍后重试!"); + T.show(yfpf_activity.this, "服务器异常,请稍后重试!"); } }); }