|
|
@@ -6,10 +6,12 @@ import android.graphics.drawable.ColorDrawable;
|
|
|
import android.os.Bundle;
|
|
|
import android.text.TextUtils;
|
|
|
import android.util.Log;
|
|
|
+import android.view.KeyEvent;
|
|
|
import android.view.Gravity;
|
|
|
import android.view.View;
|
|
|
import android.view.Window;
|
|
|
import android.view.WindowManager;
|
|
|
+import android.widget.TextView;
|
|
|
|
|
|
import androidx.annotation.NonNull;
|
|
|
import androidx.appcompat.app.AppCompatDialog;
|
|
|
@@ -24,14 +26,19 @@ import com.rc.httpcore.bean.BelongingPersonBean;
|
|
|
import com.rc.httpcore.bean.HxpChemicalVo;
|
|
|
import com.rc.httpcore.bean.StockDetailsModel;
|
|
|
import com.rc.httpcore.bean.TopicDataBean;
|
|
|
+import com.rc.httpcore.client.ApiRepository;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.HashSet;
|
|
|
import java.util.List;
|
|
|
+import java.util.Set;
|
|
|
|
|
|
import xn.hxp.R;
|
|
|
import xn.hxp.databinding.DialogPrintLabelBinding;
|
|
|
import xn.hxp.ui.PrintBean;
|
|
|
-import xn.hxp.ui.adapter.LabelDialogAdapter;
|
|
|
+import xn.hxp.receiver.UhfRfidKeyEventHelper;
|
|
|
+import xn.hxp.receiver.UhfRfidManager;
|
|
|
+import xn.hxp.ui.adapter.PrintLabelAdapter;
|
|
|
import xn.hxp.ui.plan.room.bean.input_add.InventoryItemBean;
|
|
|
import xn.hxp.utils.PrintTool;
|
|
|
|
|
|
@@ -46,9 +53,16 @@ public class PrintLabelDialog extends AppCompatDialog {
|
|
|
private String planPath;
|
|
|
|
|
|
private List<StockDetailsModel> labelList = new ArrayList<>();
|
|
|
- private LabelDialogAdapter labelDialogAdapter;
|
|
|
+ private PrintLabelAdapter labelDialogAdapter;
|
|
|
+ private int selectedIndex = 0;
|
|
|
|
|
|
private boolean isPrint;
|
|
|
+ private Runnable hideTipRunnable;
|
|
|
+
|
|
|
+ private final UhfRfidKeyEventHelper uhfRfidKeyEventHelper = new UhfRfidKeyEventHelper(content -> {
|
|
|
+ updateRfid(selectedIndex, content);
|
|
|
+ return null;
|
|
|
+ });
|
|
|
|
|
|
/**
|
|
|
* @param inventoryItemBean 清单item
|
|
|
@@ -108,26 +122,17 @@ public class PrintLabelDialog extends AppCompatDialog {
|
|
|
@Override
|
|
|
public void onSuccess(Object result) {
|
|
|
binding.rvView.setLayoutManager(new LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false));
|
|
|
- labelDialogAdapter = new LabelDialogAdapter();
|
|
|
+ labelDialogAdapter = new PrintLabelAdapter();
|
|
|
binding.rvView.setAdapter(labelDialogAdapter);
|
|
|
labelDialogAdapter.setList(labelList);
|
|
|
- // 删除条目
|
|
|
+ // 删除/重新扫描
|
|
|
labelDialogAdapter.setOnItemChildClickListener((adapter, view, position) -> {
|
|
|
- if (view.getId() == R.id.imgDelete) {
|
|
|
- try {
|
|
|
- if (labelList.size() == 1) {
|
|
|
- throw new Exception();
|
|
|
- }
|
|
|
- labelList.remove(position);
|
|
|
- for (int i = 0; i < labelList.size(); i++) {
|
|
|
- labelList.get(i).setNo(++i);
|
|
|
- }
|
|
|
- labelDialogAdapter.setList(labelList);
|
|
|
- binding.sumTV.setText("共 " + labelList.size() + " 张");
|
|
|
- } catch (Exception e) {
|
|
|
- LogUtils.e(Log.getStackTraceString(e));
|
|
|
- PopTip.show("删除失败!");
|
|
|
- }
|
|
|
+ if (position < 0 || position >= labelList.size()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ selectedIndex = position;
|
|
|
+ if (view.getId() == R.id.rescanBtn || view.getId() == R.id.imgDelete) {
|
|
|
+ clearRfid(position);
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
@@ -146,72 +151,111 @@ public class PrintLabelDialog extends AppCompatDialog {
|
|
|
binding.determine.setOnClickListener(new ClickUtils.OnDebouncingClickListener() {
|
|
|
@Override
|
|
|
public void onDebouncingClick(View v) {
|
|
|
+ validateBeforeSubmit(chemicalName, hxpChemicalVo);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
|
|
|
- printState(true);
|
|
|
-
|
|
|
- ThreadUtils.executeByCached(new ThreadUtils.SimpleTask<Object>() {
|
|
|
- @Override
|
|
|
- public Object doInBackground() throws Throwable {
|
|
|
- for (int i = 0; i < labelList.size(); i++) {
|
|
|
- StockDetailsModel stockDetailsModel = labelList.get(i);
|
|
|
- PrintBean printBean = new PrintBean();
|
|
|
- // 化学品编码
|
|
|
- String tagCode = stockDetailsModel.getTagCode();
|
|
|
- printBean.setTag(TextUtils.isEmpty(tagCode) ? "" : tagCode);
|
|
|
- // 二维码
|
|
|
- String wxCode = stockDetailsModel.getWxCode();
|
|
|
- printBean.setWxCode(TextUtils.isEmpty(wxCode) ? "" : wxCode);
|
|
|
- // 化学品名
|
|
|
- printBean.setName(TextUtils.isEmpty(chemicalName) ? "" : chemicalName);
|
|
|
- // CAS
|
|
|
- String casNum = hxpChemicalVo.getCasNum();
|
|
|
- printBean.setCasNo(TextUtils.isEmpty(casNum) ? "" : casNum);
|
|
|
- int belongType = hxpChemicalVo.getBelongType();
|
|
|
- String name = "";
|
|
|
- // 归属人
|
|
|
- if (belongType == 2) {
|
|
|
- BelongingPersonBean belongingPersonBean = inventoryItemBean.getBelongingPersonBean();
|
|
|
- name = belongingPersonBean.getUserName();
|
|
|
- }
|
|
|
- // 课题组
|
|
|
- else if (belongType == 1) {
|
|
|
- TopicDataBean topicDataBean = inventoryItemBean.getTopicDataBean();
|
|
|
- name = topicDataBean.getTopicName();
|
|
|
- }
|
|
|
- printBean.setPerson(TextUtils.isEmpty(name) ? "" : name);
|
|
|
- // 管控非管控
|
|
|
-// int chemicalLevel = hxpChemicalVo.getChemicalLevel();
|
|
|
-// printBean.setLevel(1 == chemicalLevel ? "管控" : "非管控");
|
|
|
- // 化学品类型
|
|
|
- CharSequence chemicalCategory = hxpChemicalVo.getChemicalCategoryName();
|
|
|
- printBean.setTypes(TextUtils.isEmpty(chemicalCategory) ? "" : chemicalCategory.toString());
|
|
|
- // 打印
|
|
|
- if (isPrint) {
|
|
|
- LogUtils.json("打印机前", labelList);
|
|
|
- PrintTool.INSTANCE.print(hxpChemicalVo.isGr(), belongType == 2, printBean);
|
|
|
- }
|
|
|
- Thread.sleep(200);
|
|
|
- }
|
|
|
- return null;
|
|
|
- }
|
|
|
+ private void validateBeforeSubmit(String chemicalName, HxpChemicalVo hxpChemicalVo) {
|
|
|
+ Set<String> localRfidSet = new HashSet<>();
|
|
|
+ for (int i = 0; i < labelList.size(); i++) {
|
|
|
+ StockDetailsModel stockDetailsModel = labelList.get(i);
|
|
|
+ String rfid = stockDetailsModel.getRfidCode() == null ? "" : stockDetailsModel.getRfidCode().trim();
|
|
|
+ if (rfid.isEmpty()) {
|
|
|
+ showDialogTip("请先扫描RFID标签");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (!localRfidSet.add(rfid)) {
|
|
|
+ selectedIndex = i;
|
|
|
+ clearRfid(i);
|
|
|
+ showDialogTip("rfid标签不能重复,请重新扫描");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ printState(true);
|
|
|
+ checkRemoteRfid(0, chemicalName, hxpChemicalVo);
|
|
|
+ }
|
|
|
|
|
|
- @Override
|
|
|
- public void onSuccess(Object result) {
|
|
|
- printState(false);
|
|
|
- hxpChemicalVo.setStockDetailsModelList(labelList);
|
|
|
- printLabelCallBack.confirm();
|
|
|
- dismiss();
|
|
|
- }
|
|
|
+ private void checkRemoteRfid(int index, String chemicalName, HxpChemicalVo hxpChemicalVo) {
|
|
|
+ if (index >= labelList.size()) {
|
|
|
+ submitWithRfids(chemicalName, hxpChemicalVo);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ String rfid = labelList.get(index).getRfidCode();
|
|
|
+ ApiRepository.INSTANCE.checkRfids(rfid).subscribe(data -> {
|
|
|
+ if (Boolean.TRUE.equals(data)) {
|
|
|
+ printState(false);
|
|
|
+ selectedIndex = index;
|
|
|
+ clearRfid(index);
|
|
|
+ showDialogTip("rfid标签已存在,请重新扫描");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ checkRemoteRfid(index + 1, chemicalName, hxpChemicalVo);
|
|
|
+ }, throwable -> {
|
|
|
+ printState(false);
|
|
|
+ showDialogTip(TextUtils.isEmpty(throwable.getMessage()) ? "RFID校验失败,请重试" : throwable.getMessage());
|
|
|
+ LogUtils.e(Log.getStackTraceString(throwable));
|
|
|
+ });
|
|
|
+ }
|
|
|
|
|
|
- @Override
|
|
|
- public void onFail(Throwable t) {
|
|
|
- super.onFail(t);
|
|
|
- PopTip.show("打印失败,已打印标签无效,请重试!");
|
|
|
- printLabelCallBack.close();
|
|
|
- dismiss();
|
|
|
- LogUtils.e(Log.getStackTraceString(t));
|
|
|
+ private void submitWithRfids(String chemicalName, HxpChemicalVo hxpChemicalVo) {
|
|
|
+ ThreadUtils.executeByCached(new ThreadUtils.SimpleTask<Object>() {
|
|
|
+ @Override
|
|
|
+ public Object doInBackground() throws Throwable {
|
|
|
+ for (int i = 0; i < labelList.size(); i++) {
|
|
|
+ StockDetailsModel stockDetailsModel = labelList.get(i);
|
|
|
+ PrintBean printBean = new PrintBean();
|
|
|
+ // 化学品编码
|
|
|
+ String tagCode = stockDetailsModel.getTagCode();
|
|
|
+ printBean.setTag(TextUtils.isEmpty(tagCode) ? "" : tagCode);
|
|
|
+ // 二维码
|
|
|
+ String wxCode = stockDetailsModel.getWxCode();
|
|
|
+ printBean.setWxCode(TextUtils.isEmpty(wxCode) ? "" : wxCode);
|
|
|
+ // 化学品名
|
|
|
+ printBean.setName(TextUtils.isEmpty(chemicalName) ? "" : chemicalName);
|
|
|
+ // CAS
|
|
|
+ String casNum = hxpChemicalVo.getCasNum();
|
|
|
+ printBean.setCasNo(TextUtils.isEmpty(casNum) ? "" : casNum);
|
|
|
+ int belongType = hxpChemicalVo.getBelongType();
|
|
|
+ String name = "";
|
|
|
+ // 归属人
|
|
|
+ if (belongType == 2) {
|
|
|
+ BelongingPersonBean belongingPersonBean = inventoryItemBean.getBelongingPersonBean();
|
|
|
+ name = belongingPersonBean.getUserName();
|
|
|
}
|
|
|
- });
|
|
|
+ // 课题组
|
|
|
+ else if (belongType == 1) {
|
|
|
+ TopicDataBean topicDataBean = inventoryItemBean.getTopicDataBean();
|
|
|
+ name = topicDataBean.getTopicName();
|
|
|
+ }
|
|
|
+ printBean.setPerson(TextUtils.isEmpty(name) ? "" : name);
|
|
|
+ CharSequence chemicalCategory = hxpChemicalVo.getChemicalCategoryName();
|
|
|
+ printBean.setTypes(TextUtils.isEmpty(chemicalCategory) ? "" : chemicalCategory.toString());
|
|
|
+ if (isPrint) {
|
|
|
+ LogUtils.json("打印机前", labelList);
|
|
|
+ PrintTool.INSTANCE.print(hxpChemicalVo.isGr(), belongType == 2, printBean);
|
|
|
+ }
|
|
|
+ Thread.sleep(200);
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onSuccess(Object result) {
|
|
|
+ printState(false);
|
|
|
+ hxpChemicalVo.setStockDetailsModelList(labelList);
|
|
|
+ printLabelCallBack.confirm();
|
|
|
+ dismiss();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onFail(Throwable t) {
|
|
|
+ super.onFail(t);
|
|
|
+ printState(false);
|
|
|
+ PopTip.show("打印失败,已打印标签无效,请重试!");
|
|
|
+ printLabelCallBack.close();
|
|
|
+ dismiss();
|
|
|
+ LogUtils.e(Log.getStackTraceString(t));
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
@@ -232,6 +276,54 @@ public class PrintLabelDialog extends AppCompatDialog {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private void clearRfid(int position) {
|
|
|
+ if (position < 0 || position >= labelList.size()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ labelList.get(position).setRfidCode(null);
|
|
|
+ if (labelDialogAdapter != null) {
|
|
|
+ labelDialogAdapter.notifyItemChanged(position);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void updateRfid(int position, String rfid) {
|
|
|
+ if (position < 0 || position >= labelList.size()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ String cleanRfid = rfid == null ? "" : rfid.replace("\r", "").replace("\n", "").trim();
|
|
|
+ if (cleanRfid.isEmpty()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ labelList.get(position).setRfidCode(cleanRfid);
|
|
|
+ if (labelDialogAdapter != null) {
|
|
|
+ labelDialogAdapter.notifyItemChanged(position);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void showDialogTip(String message) {
|
|
|
+ TextView tipView = binding.tipTV;
|
|
|
+ tipView.setText(message);
|
|
|
+ tipView.setVisibility(View.VISIBLE);
|
|
|
+ tipView.bringToFront();
|
|
|
+ if (hideTipRunnable != null) {
|
|
|
+ tipView.removeCallbacks(hideTipRunnable);
|
|
|
+ }
|
|
|
+ hideTipRunnable = () -> tipView.setVisibility(View.GONE);
|
|
|
+ tipView.postDelayed(hideTipRunnable, 2500);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean dispatchKeyEvent(KeyEvent event) {
|
|
|
+ if (UhfRfidManager.INSTANCE.isEnabled(getContext())
|
|
|
+ && UhfRfidManager.INSTANCE.isUhfRfidEvent(getContext(), event)) {
|
|
|
+ if (UhfRfidManager.INSTANCE.isPageWhitelisted(getContext(), UhfRfidManager.PAGE_STORAGE_RFID)) {
|
|
|
+ uhfRfidKeyEventHelper.analysisKeyEvent(event);
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ return super.dispatchKeyEvent(event);
|
|
|
+ }
|
|
|
+
|
|
|
public interface PrintLabelCallBack {
|
|
|
void confirm();
|
|
|
|