Просмотр исходного кода

增加进度条2312000-

master
fyf 1 год назад
Родитель
Сommit
495f49d8de
2 измененных файлов: 187 добавлений и 165 удалений
  1. +5
    -0
      app/src/main/java/com/example/bpa/helper/MessageLog.java
  2. +182
    -165
      app/src/main/java/com/example/bpa/service/BusinessServer.java

+ 5
- 0
app/src/main/java/com/example/bpa/helper/MessageLog.java Просмотреть файл

@@ -22,6 +22,7 @@ public class MessageLog {
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date = new Date();
String tempMsg = formatter.format(date) + ":" + msg;
if(MsgInfo.length()>=20000)MsgInfo="";
MsgInfo = tempMsg + "\r\n" + MsgInfo;
if (MsgNotify != null)
MsgNotify.InfoMsg(tempMsg);
@@ -32,6 +33,7 @@ public class MessageLog {
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date = new Date();
String tempMsg = formatter.format(date) + ":" + msg;
if(MsgInfo.length()>=20000)MsgInfo="";
MsgInfo = tempMsg + "\r\n" + MsgInfo;
if (MsgNotify != null)
MsgNotify.WarnMsg(tempMsg);
@@ -42,6 +44,7 @@ public class MessageLog {
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date = new Date();
String tempMsg = formatter.format(date) + ":" + msg;
if(MsgInfo.length()>=20000)MsgInfo="";
MsgInfo = tempMsg + "\r\n" + MsgInfo;
if (MsgNotify != null)
MsgNotify.ErrorMsg(tempMsg);
@@ -58,6 +61,7 @@ public class MessageLog {
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date = new Date();
String tempMsg = formatter.format(date) + ":" + msg;
if(MsgInfo.length()>=20000)MsgInfo="";
MsgInfo = tempMsg + "\r\n" + MsgInfo;
if (MsgNotify != null)
MsgNotify.UserMsg(type,tempMsg);
@@ -74,6 +78,7 @@ public class MessageLog {
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date = new Date();
String tempMsg = formatter.format(date) + ":" + msg;
if(MsgInfo.length()>=20000)MsgInfo="";
MsgInfo = tempMsg + "\r\n" + MsgInfo;
if (MsgNotify != null)
MsgNotify.AlertMsg(type,tempMsg);


+ 182
- 165
app/src/main/java/com/example/bpa/service/BusinessServer.java Просмотреть файл

@@ -63,10 +63,11 @@ public class BusinessServer {
public void Run() throws InterruptedException {
while (Commoditys.size() > 0) {
//1.取出需要制作的订单商品 验证物料是否充足
BPA_SUBORDER suborder=Commoditys.poll();
BPA_SUBORDER suborder = Commoditys.peek();
String GoodId = suborder.goodsID;
try {
// boolean IsMake=true;
ResultA resultA= DataBus.getInstance().InspectMaterial(GoodId);
ResultA resultA = DataBus.getInstance().InspectMaterial(GoodId);
// if(resultA.IsMake==false)//如果商品物料不足
// {
// DataBus.getInstance().UpdateGoodsMake(GoodId,resultA.Message,0);
@@ -77,138 +78,150 @@ public class BusinessServer {
// IsMake=DataBus.getInstance().InspectMaterial(GoodId).IsMake;
// Thread.sleep(2000);
// }
//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()) {
final Integer key=entry.getKey();
//当前一次性下发物料集合
List<ResGoodsRecipe> goodsRecipes= entry.getValue();
String RecipesNames="";
for (ResGoodsRecipe item:goodsRecipes ){RecipesNames+=item.materialName+",";}
DataBus.getInstance().UpdateGoodsMake(suborder.id,"步骤【" + key+ "】准备下发物料:"+RecipesNames,count);
ArrayList<Integer> liaochang=new ArrayList<Integer>();
for (int m = 0; m < goodsRecipes.size(); m++) {
ResGoodsRecipe recipe=goodsRecipes.get(m);
int materialType = recipe.materialType;
final String message="["+good.name+"]步骤【" + 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;
}
if (silos==null)
//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()) {
final Integer key = entry.getKey();
//当前一次性下发物料集合
List<ResGoodsRecipe> goodsRecipes = entry.getValue();
String RecipesNames = "";
for (ResGoodsRecipe item : goodsRecipes) {
RecipesNames += item.materialName + ",";
}
DataBus.getInstance().UpdateGoodsMake(suborder.id, "步骤【" + key + "】准备下发物料:" + RecipesNames, count);
ArrayList<Integer> liaochang = new ArrayList<Integer>();
for (int m = 0; m < goodsRecipes.size(); m++) {
ResGoodsRecipe recipe = goodsRecipes.get(m);
int materialType = recipe.materialType;
final String message = "[" + good.name + "]步骤【" + 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;
}
if (silos == null) {

MessageLog.ShowUserMessage(UserLogEnum.订单处理日志,message+"下发失败!物料没有管理料仓!");
}else
MessageLog.ShowUserMessage(UserLogEnum.订单处理日志, message + "下发失败!物料没有管理料仓!");
} else {
liaochang.add(silos.num);
MessageLog.ShowUserMessage(UserLogEnum.订单处理日志, 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);
}
});
}
} else if (materialType == 2)//果糖
{
liaochang.add(silos.num);
MessageLog.ShowUserMessage(UserLogEnum.订单处理日志,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);
}
});
BPA_SUGAR bs = QueryDB.GetsugarId(recipe.materialID);
ModbusTcpServer.get().WriteBool(bs.plcvar, true);
Thread.sleep(200);
ModbusTcpServer.get().WriteBool(bs.plcvar, false);
MessageLog.ShowUserMessage(UserLogEnum.订单处理日志, message + "下发成功!");
}
}else if (materialType == 2)//果糖
{
BPA_SUGAR bs = QueryDB.GetsugarId(recipe.materialID);
ModbusTcpServer.get().WriteBool(bs.plcvar, true);
Thread.sleep(200);
ModbusTcpServer.get().WriteBool(bs.plcvar, false);
MessageLog.ShowUserMessage(UserLogEnum.订单处理日志,message+"下发成功!");
}
//将其余料仓出料设置为0,重置
for (int k=1;k<=10;k++)
{
if(!liaochang.contains(k))
{
DeviceData.Get().setDemandValue((short) 0, k, new IWriteCallBack() {
@Override
public void onSuccess() { }
@Override
public void onFailure(String ErrorMsg) {}
});
//将其余料仓出料设置为0,重置
for (int k = 1; k <= 10; k++) {
if (!liaochang.contains(k)) {
DeviceData.Get().setDemandValue((short) 0, k, new IWriteCallBack() {
@Override
public void onSuccess() {
}

@Override
public void onFailure(String ErrorMsg) {
}
});
}
}
}
}
//启动配料
DeviceData.Get().setChargeMixtureStart(new IWriteCallBack() {
@Override
public void onSuccess() {
MessageLog.ShowInfo("["+good.name+"]步骤【" + key+ "】启动配料成功!");
}
@Override
public void onFailure(String ErrorMsg) {
MessageLog.ShowInfo("["+good.name+"]步骤【" + key+ "】启动配料失败!");
MessageLog.ShowAlertMessage(AlertLogEnum.异常订单未制作日志,"["+good.name+"]步骤【" + key+ "】启动配料失败!");
}
});
//启动配料
DeviceData.Get().setChargeMixtureStart(new IWriteCallBack() {
@Override
public void onSuccess() {
MessageLog.ShowInfo("[" + good.name + "]步骤【" + key + "】启动配料成功!");
}

//等待配料完成,一直等待
final boolean[] IsComplete = {false};
DeviceData.Get().OnChargeMixtureCompleteNotify = new IRun() {
@Override
public void Run() {
IsComplete[0] = true;
MessageLog.ShowUserMessage(UserLogEnum.订单处理日志,"["+good.name+"]步骤【" + key+ "】配料完成!");
@Override
public void onFailure(String ErrorMsg) {
MessageLog.ShowInfo("[" + good.name + "]步骤【" + key + "】启动配料失败!");
MessageLog.ShowAlertMessage(AlertLogEnum.异常订单未制作日志, "[" + good.name + "]步骤【" + key + "】启动配料失败!");
}
});

//等待配料完成,一直等待
final boolean[] IsComplete = {false};
DeviceData.Get().OnChargeMixtureCompleteNotify = new IRun() {
@Override
public void Run() {
IsComplete[0] = true;
MessageLog.ShowUserMessage(UserLogEnum.订单处理日志, "[" + good.name + "]步骤【" + key + "】配料完成!");
}
};
while (!IsComplete[0]) {
Thread.sleep(100);
}
};
while (!IsComplete[0]) {
Thread.sleep(100);
//更新缓存商品制作列表状态
count += goodsRecipes.size();
DataBus.getInstance().UpdateGoodsMake(suborder.id, "步骤【" + key + "】:" + RecipesNames + "-配料完成!", count);
MessageLog.ShowUserMessage(UserLogEnum.订单处理日志, "[" + good.name + "]步骤【" + key + "】下发" + RecipesNames + "执行完成!");
}
//更新缓存商品制作列表状态
count+=goodsRecipes.size();
DataBus.getInstance().UpdateGoodsMake(suborder.id,"步骤【" + key+ "】:"+RecipesNames+"-配料完成!",count);
MessageLog.ShowUserMessage(UserLogEnum.订单处理日志,"["+good.name+"]步骤【" + key + "】下发"+RecipesNames+"执行完成!");
//endregion
//5.设置数据中心商品已制作完成
DataBus.getInstance().DeleteGoodsMake(suborder.id);
MessageLog.ShowUserMessage(UserLogEnum.订单处理日志, "[" + good.name + "]-订单执行完成,请取餐!");
Commoditys.poll();
} catch (Exception ex) {

}
//endregion
//5.设置数据中心商品已制作完成
DataBus.getInstance().DeleteGoodsMake(suborder.id);
MessageLog.ShowUserMessage(UserLogEnum.订单处理日志,"["+good.name+"]-订单执行完成,请取餐!");
}
Thread.sleep(1000);
}

@Override
public void RunComplete() throws InterruptedException {
;
}
});
}



public void test() {
ThreadManager.Get().StartLong("订单执行业务流程-新", true, new IThread() {
@Override
public void Run() throws InterruptedException {


while (Commoditys.size() > 0) {
//1.取出需要制作的订单商品 验证物料是否充足
BPA_SUBORDER suborder=Commoditys.poll();
BPA_SUBORDER suborder = Commoditys.peek();
String GoodId = suborder.goodsID;

_L1:
try {
// boolean IsMake=true;
// ResultA resultA= DataBus.getInstance().InspectMaterial(GoodId);
// if(resultA.IsMake==false)//如果商品物料不足
@@ -220,49 +233,48 @@ public class BusinessServer {
// IsMake=DataBus.getInstance().InspectMaterial(GoodId).IsMake;
// Thread.sleep(2000);
// }
//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()) {
final Integer key=entry.getKey();
//当前一次性下发物料集合
List<ResGoodsRecipe> goodsRecipes= entry.getValue();
String RecipesNames="";
for (ResGoodsRecipe item:goodsRecipes ){RecipesNames+=item.materialName+",";}
DataBus.getInstance().UpdateGoodsMake(suborder.id,"步骤【" + key+ "】准备下发物料:"+RecipesNames,count);
for (int m = 0; m < goodsRecipes.size(); m++) {
ResGoodsRecipe recipe=goodsRecipes.get(m);
int materialType = recipe.materialType;
final String message="["+good.name+"]步骤【" + 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;
}
if (silos==null)
{
MessageLog.ShowUserMessage(UserLogEnum.订单处理日志,message+"下发失败!物料没有管理料仓!");
}else
//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()) {
final Integer key = entry.getKey();
//当前一次性下发物料集合
List<ResGoodsRecipe> goodsRecipes = entry.getValue();
String RecipesNames = "";
for (ResGoodsRecipe item : goodsRecipes) {
RecipesNames += item.materialName + ",";
}
DataBus.getInstance().UpdateGoodsMake(suborder.id, "步骤【" + key + "】准备下发物料:" + RecipesNames, count);
for (int m = 0; m < goodsRecipes.size(); m++) {
ResGoodsRecipe recipe = goodsRecipes.get(m);
int materialType = recipe.materialType;
final String message = "[" + good.name + "]步骤【" + key + "】下发【" + recipe.materialName + "】";
if (materialType == 1)//1.正常物料
{
MessageLog.ShowUserMessage(UserLogEnum.订单处理日志,message+"准备下发【" + silos.num + "】号料仓PLC控制命令,需求量:=" + recipe.value);
//获取物料关联的料仓信息
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;
}
if (silos == null) {
MessageLog.ShowUserMessage(UserLogEnum.订单处理日志, message + "下发失败!物料没有管理料仓!");
} else {
MessageLog.ShowUserMessage(UserLogEnum.订单处理日志, message + "准备下发【" + silos.num + "】号料仓PLC控制命令,需求量:=" + recipe.value);
// DeviceData.Get().setDemandValue((short) recipe.value, silos.num, new IWriteCallBack() {
// @Override
// public void onSuccess() {
@@ -273,18 +285,18 @@ public class BusinessServer {
// MessageLog.ShowInfo(message+"下发失败!"+ErrorMsg);
// }
// });
Thread.sleep(1000);
}
}else if (materialType == 2)//果糖
{
Thread.sleep(1000);
}
} else if (materialType == 2)//果糖
{
// BPA_SUGAR bs = QueryDB.GetsugarId(recipe.materialID);
// ModbusTcpServer.get().WriteBool(bs.plcvar, true);
// Thread.sleep(200);
// ModbusTcpServer.get().WriteBool(bs.plcvar, false);
// MessageLog.ShowUserMessage(UserLogEnum.订单处理日志,message+"下发成功!");
}
}
}
//启动配料
//启动配料
// DeviceData.Get().setChargeMixtureStart(new IWriteCallBack() {
// @Override
// public void onSuccess() {
@@ -295,8 +307,8 @@ public class BusinessServer {
// MessageLog.ShowInfo("["+good.name+"]步骤【" + key+ "】启动配料失败!");
// }
// });
Thread.sleep(1000);
//等待配料完成,一直等待
Thread.sleep(1000);
//等待配料完成,一直等待
// final boolean[] IsComplete = {false};
// DeviceData.Get().OnChargeMixtureCompleteNotify = new IRun() {
// @Override
@@ -308,18 +320,23 @@ public class BusinessServer {
// while (!IsComplete[0]) {
// Thread.sleep(100);
// }
//更新缓存商品制作列表状态
count+=goodsRecipes.size();
DataBus.getInstance().UpdateGoodsMake(suborder.id,"步骤【" + key+ "】:"+RecipesNames+"-配料完成!",count);
MessageLog.ShowUserMessage(UserLogEnum.订单处理日志,"["+good.name+"]步骤【" + key + "】下发"+RecipesNames+"执行完成!");
//更新缓存商品制作列表状态
count += goodsRecipes.size();
DataBus.getInstance().UpdateGoodsMake(suborder.id, "步骤【" + key + "】:" + RecipesNames + "-配料完成!", count);
MessageLog.ShowUserMessage(UserLogEnum.订单处理日志, "[" + good.name + "]步骤【" + key + "】下发" + RecipesNames + "执行完成!");
}
//endregion
//5.设置数据中心商品已制作完成
DataBus.getInstance().DeleteGoodsMake(suborder.id);
MessageLog.ShowUserMessage(UserLogEnum.订单处理日志, "[" + good.name + "]-订单执行完成,请取餐!");
Commoditys.poll();
} catch (Exception ex) {
MessageLog.ShowInfo("异常信息!" + ex.getMessage());
}
//endregion
//5.设置数据中心商品已制作完成
DataBus.getInstance().DeleteGoodsMake(suborder.id);
MessageLog.ShowUserMessage(UserLogEnum.订单处理日志,"["+good.name+"]-订单执行完成,请取餐!");
}
Thread.sleep(1000);
}

@Override
public void RunComplete() throws InterruptedException {
}


Загрузка…
Отмена
Сохранить