Browse Source

订单制作 与 主页订单制作显示

master
fyf 1 year ago
parent
commit
f80fe365b1
7 changed files with 132 additions and 86 deletions
  1. +88
    -65
      app/src/main/java/com/example/bpa/app/BusinessServer.java
  2. +2
    -0
      app/src/main/java/com/example/bpa/app/ICSApp.java
  3. +1
    -0
      app/src/main/java/com/example/bpa/config/ConfigName.java
  4. +12
    -17
      app/src/main/java/com/example/bpa/config/DataBus.java
  5. +1
    -1
      app/src/main/java/com/example/bpa/db/mode/BPA_GOODSRECIPE.java
  6. +28
    -2
      app/src/main/java/com/example/bpa/view/adapter/makegood_adapter.java
  7. +0
    -1
      app/src/main/java/com/example/bpa/view/fragment/HomeFragment.java

+ 88
- 65
app/src/main/java/com/example/bpa/app/BusinessServer.java View File

@@ -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<String> Commoditys = new ConcurrentLinkedQueue<String>();

/**
* 添加配方
* 增加一个订单
*
* @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<ResGoodsRecipe> goods = QueryDB.GetGoodsSrecipeList(GoodId);
BPA_GOODS good= QueryDB.GetGoodsId(GoodId);
//3.根据物料配方排序Sort步骤分组
//region 根据物料配方排序Sort步骤分组
LinkedHashMap<Integer, List<ResGoodsRecipe>> 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<Integer, List<ResGoodsRecipe>> 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<BPA_SILOS> 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<ResGoodsRecipe> 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<BPA_SILOS> 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 {

}
});
}


}

+ 2
- 0
app/src/main/java/com/example/bpa/app/ICSApp.java View File

@@ -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();
}

/**


+ 1
- 0
app/src/main/java/com/example/bpa/config/ConfigName.java View File

@@ -25,6 +25,7 @@ public class ConfigName {

//region 程序进入界面
public Context dishesCon;
public Context Home;
//endregion

//region SD卡路径设置


+ 12
- 17
app/src/main/java/com/example/bpa/config/DataBus.java View File

@@ -54,7 +54,7 @@ public class DataBus {
*/
public List<ResGoodsMake> GoodsMake = new ArrayList<ResGoodsMake>();
/**
* 商品制作列表
* 商品制作完成列表
*/
public List<ResGoodsMake> GoodsMakeOver = new ArrayList<ResGoodsMake>();
/**
@@ -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<GoodsMake.size();m++)
{
if(item.good.id.equals(id))
if(GoodsMake.get(m).good.id.equals(id))
{
for (ResGoodsRecipe pf:item.recipes)
{
if(pf.id.equals(wlid))
{
pf.IsRun=true;
item.makeStatus= MakeStatus.制作中;
item.makeMs="当前配置["+pf.materialName+"]中..请稍后...";
item.makeProcess=(m/ item.recipes.size())*100;
goodmakeadapter.refresh();
return;
}
}
GoodsMake.get(m).makeStatus= MakeStatus.制作中;
GoodsMake.get(m).makeMs=makeMs;
GoodsMake.get(m).makeProcess=(count/ GoodsMake.get(m).recipes.size())*100;
goodmakeadapter.refresh();
return;
}
}
}catch(Exception e){


+ 1
- 1
app/src/main/java/com/example/bpa/db/mode/BPA_GOODSRECIPE.java View File

@@ -13,6 +13,6 @@ public class BPA_GOODSRECIPE extends ModeBase {
public int value;
//排序
public int sort;
//物料类型
public int materialType;
}

+ 28
- 2
app/src/main/java/com/example/bpa/view/adapter/makegood_adapter.java View File

@@ -1,6 +1,8 @@
package com.example.bpa.view.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;
@@ -14,8 +16,11 @@ import androidx.recyclerview.widget.RecyclerView;

import com.example.bpa.R;
import com.example.bpa.app.BusinessServer;
import com.example.bpa.app.DeviceData;
import com.example.bpa.config.ConfigName;
import com.example.bpa.config.DataBus;
import com.example.bpa.helper.T;
import com.example.bpa.view.from.lsjy_activity;
import com.example.bpa.view.mode.ResGoodsMake;
import com.example.bpa.view.mode.mainGoods;

@@ -61,13 +66,34 @@ public class makegood_adapter extends RecyclerView.Adapter<RecyclerView.ViewHold
e.printStackTrace();
}
}

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(){
notifyDataSetChanged();
Activity activity= findActivity(context);
if(activity!=null)
{
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
try {
notifyDataSetChanged();
} catch (Exception e) {

}
}
});
}
}

@Override


+ 0
- 1
app/src/main/java/com/example/bpa/view/fragment/HomeFragment.java View File

@@ -97,7 +97,6 @@ public class HomeFragment extends Fragment implements View.OnClickListener, MyCl
MakeGood.setLayoutManager(new LinearLayoutManager(view.getContext(), LinearLayoutManager.HORIZONTAL,false));
DataBus.getInstance().goodmakeadapter = new makegood_adapter(getContext());
MakeGood.setAdapter(DataBus.getInstance().goodmakeadapter);

}catch(Exception e){

}


Loading…
Cancel
Save