@@ -5,8 +5,10 @@ import com.jdzh.jdzhandroid.Enum.Status; | |||
import com.jdzh.jdzhandroid.Interface.IRunT; | |||
import com.jdzh.jdzhandroid.Sqlite.DAO.BPA_BatchingDao; | |||
import com.jdzh.jdzhandroid.Sqlite.DAO.BPA_RecipeConfigDetailDao; | |||
import com.jdzh.jdzhandroid.Sqlite.DAO.BPA_RecipeInfoDao; | |||
import com.jdzh.jdzhandroid.Sqlite.Model.BPA_Batching; | |||
import com.jdzh.jdzhandroid.Sqlite.Model.BPA_RecipeConfigDetail; | |||
import com.jdzh.jdzhandroid.Sqlite.Model.BPA_RecipeInfo; | |||
import com.jdzh.jdzhandroid.Sqlite.SqliteHelper; | |||
import com.jdzh.jdzhandroid.Task.TaskManager; | |||
import com.jdzh.jdzhandroid.UI.dialog.RecipeExecuteDialog; | |||
@@ -40,7 +42,7 @@ public class TaskControl { | |||
* 启动单通道配料 | |||
* @param callBack 任务执行反馈 | |||
*/ | |||
public static void startBatchList(String configId, RecipeExecuteDialog.ExecuteCallBack callBack){ | |||
public static void startBatchList(String recipeId,String configId, RecipeExecuteDialog.ExecuteCallBack callBack){ | |||
if(Config.isTest){ | |||
callBack.onSuccess(3200); | |||
return; | |||
@@ -50,6 +52,21 @@ public class TaskControl { | |||
LinkedHashMap<Integer,Integer> value = new LinkedHashMap<>(); | |||
int totalTime = 0; | |||
float scale = 1f; | |||
if(Config.getInstance().isWeight){ | |||
BPA_RecipeInfo recipeInfo = SqliteHelper.get().queryByBuilderEntity(BPA_RecipeInfo.class, | |||
BPA_RecipeInfoDao.Properties.Id.eq(recipeId)); | |||
float weight = recipeInfo.getReferenceWeight(); | |||
if(weight == 0){ | |||
ToastUtil.showError("基准克数不能为0!"); | |||
return; | |||
} | |||
if(Global.currentWeight.<Float>getValue()<RecipeExecuteDialog.baseWeight){ | |||
ToastUtil.showError("称重读数不准确!"); | |||
return; | |||
} | |||
scale = Global.currentWeight.<Float>getValue()/weight; | |||
} | |||
for(BPA_RecipeConfigDetail detail:detailList){ | |||
if(detail.getWeight()>0){ | |||
@@ -63,7 +80,7 @@ public class TaskControl { | |||
} | |||
return; | |||
}else { | |||
float time = PlcControl.get().getOutCalibrationTime(num,detail.getWeight()); | |||
float time = PlcControl.get().getOutCalibrationTime(num,detail.getWeight()*scale); | |||
value.put(num, (int) time); | |||
totalTime = totalTime+((int) time); | |||
} | |||
@@ -101,7 +101,15 @@ public class RecipeEditDialog extends Dialog { | |||
@Override | |||
public void onClick(View view) { | |||
if(binding.etRecipeName.getText().toString().trim().isEmpty()){ | |||
Toast.makeText(context,"不允许配方名称为空!",Toast.LENGTH_LONG).show(); | |||
ToastUtil.showWarn("不允许配方名称为空!"); | |||
return; | |||
} | |||
if(binding.etWeight.getText().toString().isEmpty() || binding.etWeight.getText().toString().equals("0")){ | |||
ToastUtil.showWarn("不允许基准克数为0!"); | |||
return; | |||
} | |||
if(Float.parseFloat(binding.etWeight.getText().toString())<100){ | |||
ToastUtil.showWarn("基准克数不能小于100!"); | |||
return; | |||
} | |||
recipeInfo.setName(binding.etRecipeName.getText().toString()); | |||
@@ -6,6 +6,9 @@ import android.graphics.drawable.ColorDrawable; | |||
import android.os.Build; | |||
import android.os.Bundle; | |||
import android.os.CountDownTimer; | |||
import android.os.Handler; | |||
import android.os.Looper; | |||
import android.os.Message; | |||
import android.util.Log; | |||
import android.view.Gravity; | |||
import android.view.LayoutInflater; | |||
@@ -21,6 +24,7 @@ import androidx.fragment.app.DialogFragment; | |||
import com.apkfuns.logutils.LogUtils; | |||
import com.jdzh.jdzhandroid.Business.ElectoronicScales; | |||
import com.jdzh.jdzhandroid.Business.Global; | |||
import com.jdzh.jdzhandroid.Business.PlcControl; | |||
import com.jdzh.jdzhandroid.Business.TaskControl; | |||
import com.jdzh.jdzhandroid.Enum.DialogButton; | |||
@@ -49,6 +53,7 @@ import com.jdzh.jdzhandroid.databinding.DialogRecipeExcuteBinding; | |||
import com.jdzh.jdzhandroid.util.Dialog.DialogManager; | |||
import com.jdzh.jdzhandroid.util.DisplayManager; | |||
import com.jdzh.jdzhandroid.util.ToastUtil; | |||
import com.jdzh.jdzhandroid.util.Util; | |||
import java.text.SimpleDateFormat; | |||
import java.util.ArrayList; | |||
@@ -59,7 +64,29 @@ public class RecipeExecuteDialog extends DialogFragment { | |||
private BPA_RecipeInfo recipe; | |||
private RecipeAttributeAdapter recipeAttributeAdapter; | |||
private DialogRecipeExcuteBinding binding; | |||
private boolean hasClear = false; | |||
public static int baseWeight = 100; | |||
private Handler handler = new Handler(Looper.getMainLooper()){ | |||
@Override | |||
public void handleMessage(@NonNull Message msg) { | |||
super.handleMessage(msg); | |||
if(msg.what==1){ | |||
if(hasMessages(1)){ | |||
removeMessages(1); | |||
} | |||
sendEmptyMessageDelayed(1,500); | |||
binding.tvWeight.setText("当前重量:"+Global.currentWeight.<Float>getValue()); | |||
if(hasClear){ | |||
if(Global.currentWeight.<Float>getValue()>baseWeight){ | |||
binding.llAttribute.setVisibility(View.VISIBLE); | |||
binding.llClear.setVisibility(View.GONE); | |||
removeMessages(1); | |||
} | |||
} | |||
} | |||
} | |||
}; | |||
@Override | |||
public void onCreate(@Nullable Bundle savedInstanceState) { | |||
super.onCreate(savedInstanceState); | |||
@@ -113,10 +140,60 @@ public class RecipeExecuteDialog extends DialogFragment { | |||
if(getArguments()!=null){ | |||
recipe = SqliteHelper.get().queryByBuilderEntity(BPA_RecipeInfo.class, BPA_RecipeInfoDao.Properties.Id.eq(getArguments().get("id"))); | |||
} | |||
initView(); | |||
} | |||
private void initView(){ | |||
if(Config.getInstance().isWeight){ | |||
binding.llClear.setVisibility(View.VISIBLE); | |||
binding.rlExecute.setVisibility(View.GONE); | |||
binding.llAttribute.setVisibility(View.GONE); | |||
handler.sendEmptyMessage(1); | |||
}else { | |||
binding.llClear.setVisibility(View.GONE); | |||
binding.rlExecute.setVisibility(View.GONE); | |||
binding.llAttribute.setVisibility(View.VISIBLE); | |||
} | |||
binding.llClear.setOnClickListener(v->{ | |||
binding.tvPut.setText("电子秤清零中..."); | |||
TaskManager.get().execute(new Runnable() { | |||
@Override | |||
public void run() { | |||
//电子秤清零 | |||
ElectoronicScales.get().clearZero((short) 1);//电子称去皮 | |||
boolean timeOutWeight = Util.WaitingConditions(()->{return Global.currentWeight.<Float>getValue()<=0.5f;},2000,null);//等待电子秤清零完成 | |||
if(!timeOutWeight){ | |||
if(handler!=null){ | |||
handler.post(new Runnable() { | |||
@Override | |||
public void run() { | |||
binding.tvPut.setText("电子秤清零失败,请重试"); | |||
} | |||
}); | |||
} | |||
}else { | |||
if(handler!=null){ | |||
handler.post(new Runnable() { | |||
@Override | |||
public void run() { | |||
hasClear = true; | |||
binding.tvPut.setText("请放入碗"); | |||
} | |||
}); | |||
} | |||
} | |||
} | |||
}); | |||
}); | |||
binding.btnCancel2.setOnClickListener(v->{ | |||
dismiss(); | |||
}); | |||
binding.tvRecipeMode.setText(!Config.getInstance().isWeight ?"配方模式":"计量模式"); | |||
binding.tvRecipe.setText(recipe.getName()); | |||
binding.tvRecipe2.setText(recipe.getName()); | |||
@@ -318,17 +395,33 @@ public class RecipeExecuteDialog extends DialogFragment { | |||
executeCallBack = new ExecuteCallBack() { | |||
@Override | |||
public void onSuccess(int time) { | |||
countDownTime(time); | |||
handler.post(new Runnable() { | |||
@Override | |||
public void run() { | |||
countDownTime(time); | |||
} | |||
}); | |||
} | |||
@Override | |||
public void onError(String tip) { | |||
ToastUtil.showError(tip); | |||
binding.llAttribute.setVisibility(View.VISIBLE); | |||
binding.rlExecute.setVisibility(View.GONE); | |||
handler.post(new Runnable() { | |||
@Override | |||
public void run() { | |||
ToastUtil.showError(tip); | |||
binding.llAttribute.setVisibility(View.VISIBLE); | |||
binding.rlExecute.setVisibility(View.GONE); | |||
} | |||
}); | |||
} | |||
}; | |||
TaskControl.startBatchList(configId,executeCallBack); | |||
TaskManager.get().execute(new Runnable() { | |||
@Override | |||
public void run() { | |||
TaskControl.startBatchList(recipe.getId(),configId,executeCallBack); | |||
} | |||
}); | |||
} | |||
private CountDownTimer countDownTimer = null;//计时器 | |||
@@ -365,6 +458,10 @@ public class RecipeExecuteDialog extends DialogFragment { | |||
if(countDownTimer!=null){ | |||
countDownTimer.cancel(); | |||
} | |||
if(handler!=null){ | |||
handler.removeCallbacksAndMessages(null); | |||
handler = null; | |||
} | |||
countDownTimer = null; | |||
executeCallBack = null; | |||
} | |||
@@ -2,9 +2,81 @@ | |||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" | |||
android:layout_width="match_parent" | |||
android:layout_height="match_parent" | |||
android:orientation="vertical" | |||
xmlns:tools="http://schemas.android.com/tools" | |||
android:background="@color/dialog_bg"> | |||
<LinearLayout | |||
android:id="@+id/ll_clear" | |||
android:layout_centerInParent="true" | |||
android:background="@color/white" | |||
android:orientation="vertical" | |||
android:layout_width="@dimen/dp_800" | |||
android:visibility="gone" | |||
tools:visibility="visible" | |||
android:layout_height="500dp"> | |||
<TextView | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:layout_marginLeft="@dimen/sp20" | |||
android:layout_marginTop="@dimen/sp10" | |||
android:text="计量模式" | |||
android:textColor="@color/black" | |||
android:textSize="@dimen/sp28"/> | |||
<Button | |||
android:id="@+id/btn_clear" | |||
android:textColor="@color/white" | |||
android:textSize="32sp" | |||
android:layout_gravity="center_horizontal" | |||
android:background="@drawable/btn_normal_bg" | |||
android:layout_width="200dp" | |||
android:layout_height="90dp" | |||
android:layout_marginTop="30dp" | |||
android:text="清零"/> | |||
<TextView | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:layout_marginTop="5dp" | |||
android:text="(清零前,请确认称上没有物体)" | |||
android:layout_gravity="center_horizontal" | |||
android:textColor="@color/black_overlay" | |||
android:textSize="@dimen/sp26"/> | |||
<TextView | |||
android:id="@+id/tv_put" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:layout_marginTop="20dp" | |||
android:text="请放入碗" | |||
android:layout_gravity="center_horizontal" | |||
android:textColor="@color/black" | |||
android:textSize="@dimen/sp_32"/> | |||
<TextView | |||
android:id="@+id/tv_weight" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:layout_marginTop="20dp" | |||
android:text="当前重量:0g" | |||
android:layout_gravity="center_horizontal" | |||
android:textColor="@color/black" | |||
android:textSize="@dimen/sp_32"/> | |||
<Button | |||
android:id="@+id/btn_cancel2" | |||
android:textColor="@color/white" | |||
android:textSize="32sp" | |||
android:layout_gravity="center_horizontal" | |||
android:background="@drawable/btn_normal_bg" | |||
android:layout_width="200dp" | |||
android:layout_height="90dp" | |||
android:layout_marginTop="20dp" | |||
android:text="取消"/> | |||
</LinearLayout> | |||
<RelativeLayout | |||
android:id="@+id/rl_execute" | |||
android:background="@color/white" | |||
@@ -12,7 +84,7 @@ | |||
android:orientation="vertical" | |||
android:layout_width="@dimen/dp_700" | |||
android:visibility="gone" | |||
tools:visibility="visible" | |||
tools:visibility="gone" | |||
android:layout_height="@dimen/dp_440"> | |||
<TextView | |||
@@ -112,7 +184,7 @@ | |||
android:layout_centerInParent="true" | |||
android:orientation="vertical" | |||
android:layout_width="@dimen/dp_800" | |||
tools:visibility="visible" | |||
tools:visibility="gone" | |||
android:layout_height="wrap_content"> | |||
<TextView | |||