Commit 7b3307da by Wyh

1、凍鏈的訂單碼調整 2、prj優化 3、供應鏈單位快捷輸入的刪除功能

parent 09fb6511
......@@ -372,7 +372,7 @@ public class ColdChainMainActivity extends BaseFragmentActivity<ColdChainMainPre
view.findViewById(R.id.layout_history_order).setOnClickListener(v1 -> {
CC.obtainBuilder(com.gingersoft.gsa.cloud.component.ComponentName.COMPONENT_DELIVERYPICK)
.setActionName("historyActivity")
.addParam(DeliveryPickConstans.ORDER_TYPE, "1")
.addParam(DeliveryPickConstans.ORDER_TYPE, DeliveryPickConstans.COLD_CHAIN_TYPE)
.build()
.call();
pop.dismiss();
......
......@@ -235,7 +235,7 @@ public class OrderDetailsActivity extends BaseActivity<OrderDetailsPresenter> im
mTvOrderStatus.setText("待確認訂單");
mTvOrderStatus.setTextColor(ContextCompat.getColor(mContext, R.color.order_state0_color));
}
mTvOrderNo.setText(getResources().getString(R.string.order_no) + bean.getORDER_NO());
mTvOrderNo.setText(getResources().getString(R.string.order_no) + bean.getID());
mTvCreateTime.setText(getResources().getString(R.string.create_order_time) + TimeUtils.parseTimeRepeat(bean.getCREATE_TIME(), TimeUtils.DEFAULT_DATE_FORMAT));
if (TextUtil.isNotEmptyOrNullOrUndefined(bean.getRECEIVER())) {
mTvReceiver.setText(bean.getRECEIVER());
......
......@@ -26,7 +26,7 @@ public class OrderListAdapter extends BaseQuickAdapter<OrderList.DataBeanX.DataB
public OrderListAdapter(@Nullable List<OrderList.DataBeanX.DataBean> data) {
super(R.layout.cold_chain_order_item2, data);
super(R.layout.cold_chain_order_item, data);
}
......@@ -48,7 +48,7 @@ public class OrderListAdapter extends BaseQuickAdapter<OrderList.DataBeanX.DataB
baseViewHolder.setText(R.id.tv_address, "地址:" + dataBean.getADDRESS_DETAIL());
baseViewHolder.setText(R.id.tv_delivery_state, getStatus(dataBean.getCurStat()));
baseViewHolder.setText(R.id.tv_order_amount, "$" + dataBean.getPAY_AMOUNT());
baseViewHolder.setText(R.id.tv_order_code, String.format(getContext().getString(R.string.str_order_code), dataBean.getTakeFoodCode()));
if (dataBean.getIsRead() == 0) {
baseViewHolder.setVisible(R.id.fl_border, true);
alphaAnimator(baseViewHolder.getView(R.id.fl_border));
......
......@@ -81,7 +81,7 @@
android:layout_height="wrap_content"
android:layout_margin="@dimen/other_order_info_dialog_content_marginLeft"
android:layout_marginTop="@dimen/dp_10"
tools:text="訂單號:" />
tools:text="訂單號:" />
<TextView
android:id="@+id/tv_create_time"
......@@ -149,7 +149,7 @@
style="@style/otherOrderReceiving_title_textStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="訂單:" />
android:text="訂單:" />
<TextView
android:id="@+id/tv_bill_num"
......
......@@ -3,36 +3,37 @@
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/dp_3"
android:layout_marginTop="@dimen/dp_7"
android:layout_marginRight="@dimen/dp_3">
android:layout_height="wrap_content">
<com.lihang.ShadowLayout
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:hl_cornerRadius="@dimen/dp_8"
app:hl_shadowLimit="@dimen/dp_3">
android:foreground="?attr/selectableItemBackground"
app:cardCornerRadius="@dimen/dp_8"
app:cardElevation="@dimen/dp_2"
app:cardPreventCornerOverlap="true"
app:cardUseCompatPadding="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingLeft="@dimen/dp_4"
android:orientation="horizontal"
android:paddingLeft="@dimen/dp_14"
android:paddingTop="@dimen/dp_10"
android:paddingRight="@dimen/dp_14"
android:paddingBottom="@dimen/dp_6">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/dp_3"
android:gravity="center_vertical"
android:orientation="horizontal">
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginRight="@dimen/dp_5"
android:layout_weight="2"
android:orientation="vertical">
<TextView
android:id="@+id/tv_pay_method"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:background="@drawable/shape_payments_btn"
android:gravity="left"
android:paddingLeft="@dimen/dp_8"
......@@ -41,147 +42,134 @@
android:paddingBottom="@dimen/dp_6"
android:textColor="@color/white"
android:textSize="@dimen/dp_14"
android:textStyle="bold"/>
android:textStyle="bold"
tools:text="支付方式" />
<View
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1" />
<TextView
android:id="@+id/tv_order_user_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="2"
android:textColor="@color/theme_text_color"
android:textSize="@dimen/sp_14"
android:textStyle="bold"
tools:text="用戶名+手機號(1234567862)安居房三級分類誰的簡歷福克斯就"
tools:textColor="@color/theme_333_color" />
<View
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1" />
<TextView
android:id="@+id/tv_order_code"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="1"
android:textColor="@color/theme_text_color"
android:textSize="@dimen/sp_14"
android:textStyle="bold"
tools:text="訂單碼:1002"
tools:textColor="@color/theme_333_color" />
<View
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1" />
<TextView
android:id="@+id/tv_address"
style="@style/order_item_info_textStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/color_3c"
tools:text="用戶收貨地址"
tools:textColor="#868686" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="right"
android:orientation="vertical">
<TextView
android:id="@+id/tv_order_time"
style="@style/order_item_twelve_textStyle"
android:layout_width="0dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/dp_5"
android:layout_marginRight="@dimen/dp_10"
android:layout_weight="1"
android:gravity="right"
android:text="@string/Key_add_10"
android:textSize="@dimen/dp_10"
tools:text="下單時間"
tools:text="2019-07-06 15:30:00"
tools:textColor="@color/theme_333_color" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
<TextView
android:id="@+id/tv_logistics_order_print_state"
style="@style/order_item_info_title_textStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginTop="@dimen/dp_14"
android:orientation="vertical">
<TextView
android:id="@+id/tv_order_user_name"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginTop="@dimen/dp_2"
android:layout_marginRight="@dimen/dp_10"
android:textColor="@color/theme_text_color"
android:textSize="@dimen/sp_14"
android:textStyle="bold"
tools:text="用戶名+手機號(1234567862)"
tools:textColor="@color/theme_333_color" />
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/dp_5">
<TextView
android:id="@+id/tv_address_text"
style="@style/order_item_info_title_textStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/dp_6"
android:layout_marginBottom="@dimen/dp_10"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:text="地址:"
tools:textColor="@color/theme_333_color" />
<TextView
android:id="@+id/tv_address"
style="@style/order_item_info_textStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintLeft_toRightOf="@id/tv_address_text"
app:layout_constraintTop_toTopOf="@id/tv_address_text"
tools:text="用戶收貨地址"
tools:textColor="#868686" />
</androidx.constraintlayout.widget.ConstraintLayout>
</LinearLayout>
<LinearLayout
android:layout_marginTop="@dimen/dp_9"
android:gravity="right"
android:text="物流單已打印"
android:textColor="@color/color_3c" />
<TextView
android:id="@+id/tv_delivery_state"
style="@style/order_item_info_title_textStyle"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:orientation="vertical">
<ImageView
android:id="@+id/ic_vehicle"
android:layout_width="@dimen/dp_26"
android:layout_height="@dimen/dp_26"
android:layout_marginLeft="@dimen/dp_5"
android:layout_marginRight="@dimen/dp_5" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/dp_2"
android:layout_weight="0.35"
android:gravity="center_horizontal"
android:orientation="vertical">
<TextView
android:id="@+id/tv_delivery_state"
style="@style/order_item_info_title_textStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/dp_15"
android:textColor="@color/color_3c"
tools:text="已通知物流"
tools:textColor="@color/theme_333_color" />
<TextView
android:id="@+id/tv_order_state"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/dp_11"
android:paddingLeft="@dimen/dp_13"
android:paddingTop="@dimen/dp_4"
android:paddingRight="@dimen/dp_13"
android:paddingBottom="@dimen/dp_4"
android:textColor="@color/white"
android:textSize="@dimen/dp_12"
tools:text="訂單狀態"
tools:textColor="@color/theme_333_color" />
<TextView
android:id="@+id/tv_order_amount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/dp_2"
android:gravity="center_horizontal"
android:textColor="@color/red_600"
android:textSize="@dimen/sp_16"
app:layout_constraintHorizontal_weight="1"
app:layout_constraintLeft_toRightOf="@id/tv_address"
app:layout_constraintRight_toRightOf="parent"
tools:text="$14141"
tools:textColor="@color/theme_333_color" />
</LinearLayout>
android:layout_marginTop="@dimen/dp_9"
android:gravity="right"
android:textColor="@color/color_3c"
tools:text="已通知物流"
tools:textColor="@color/theme_333_color" />
<TextView
android:id="@+id/tv_order_state"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/dp_3"
android:gravity="center"
android:paddingLeft="@dimen/dp_20"
android:paddingTop="@dimen/dp_8"
android:paddingRight="@dimen/dp_20"
android:paddingBottom="@dimen/dp_8"
android:textColor="@color/white"
android:textSize="@dimen/dp_12"
tools:text="訂單狀態"
tools:textColor="@color/theme_333_color" />
<TextView
android:id="@+id/tv_order_amount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/dp_7"
android:gravity="center_horizontal"
android:maxWidth="@dimen/dp_100"
android:textColor="@color/red_600"
android:textSize="@dimen/sp_16"
tools:text="$14141144"
tools:textColor="@color/theme_333_color" />
</LinearLayout>
</LinearLayout>
</com.lihang.ShadowLayout>
<FrameLayout
android:id="@+id/fl_border"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/shape_order_border"
android:visibility="gone" />
<FrameLayout
android:id="@+id/fl_border"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/shape_order_border"
android:visibility="gone" />
</androidx.cardview.widget.CardView>
</FrameLayout>
......@@ -73,21 +73,33 @@
app:layout_constraintRight_toLeftOf="@id/tv_order_state"
app:layout_constraintTop_toBottomOf="@id/tv_pay_method"
app:layout_constraintTop_toTopOf="@id/tv_order_state"
tools:text="用戶名+手機號(1234567862)安居房三級分類誰的簡歷福克斯就"
tools:textColor="@color/theme_333_color" />
<TextView
android:id="@+id/tv_order_code"
android:layout_width="0dp"
android:layout_height="match_parent"
android:ellipsize="end"
android:maxLines="1"
android:textColor="@color/theme_text_color"
android:textSize="@dimen/sp_14"
android:textStyle="bold"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toLeftOf="@id/tv_order_state"
app:layout_constraintTop_toBottomOf="@id/tv_order_user_name"
tools:text="用戶名+手機號(1234567862)"
tools:textColor="@color/theme_333_color" />
<TextView
android:id="@+id/tv_address"
style="@style/order_item_info_textStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/dp_15"
android:layout_marginRight="@dimen/dp_10"
android:textColor="@color/color_3c"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toLeftOf="@id/tv_order_amount"
app:layout_constraintTop_toBottomOf="@id/tv_order_user_name"
app:layout_constraintTop_toBottomOf="@id/tv_order_code"
app:layout_constraintVertical_bias="1"
tools:text="用戶收貨地址"
tools:textColor="#868686" />
......
......@@ -7,17 +7,17 @@
android:background="@color/white"
android:orientation="vertical">
<androidx.coordinatorlayout.widget.CoordinatorLayout
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/color_f0"
app:cardElevation="@dimen/dp_2"
tools:context=".ui.activity.DeliveryOrderMainActivity">
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white"
app:elevation="@dimen/dp_0">
android:background="@color/white">
<com.qmuiteam.qmui.widget.QMUITopBar
android:id="@+id/coldchain_main_top_bar"
......@@ -198,11 +198,10 @@
android:padding="@dimen/dp_10"
android:text="餘額:"
android:textColor="@color/theme_333_color"
android:textSize="@dimen/dp_16"
android:visibility="gone" />
android:textSize="@dimen/dp_16" />
</com.google.android.material.appbar.AppBarLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
</androidx.cardview.widget.CardView>
<androidx.viewpager.widget.ViewPager
android:id="@+id/view_pager"
......
<resources>
<string name="cold_chain_name">凍鏈</string>
<string name="str_order_code">訂單碼:%1$s</string>
</resources>
......@@ -6,6 +6,7 @@ import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.billy.cc.core.component.CC
import com.gingersoft.gsa.cloud.common.constans.DeliveryPickConstans
import com.gingersoft.gsa.cloud.common.core.restaurant.RestaurantInfoManager
import com.gingersoft.gsa.cloud.common.utils.time.TimeUtils
import com.gingersoft.gsa.cloud.common.utils.toast.ToastUtils
......@@ -26,8 +27,8 @@ class HistoryOrderViewModel(private val historyOrderRepository: HistoryOrderRepo
var historyEndTime = MutableLiveData<String>(TimeUtils.getOldDate(0)) //查詢結束時間
var status = MutableLiveData("4") //按類型查詢
var searchValue = MutableLiveData("")//按搜索內容查詢
var orderType = "2,7" //訂單類型 2 線上外賣訂單,7 自取訂單
var orderFrom = 0 //訂單來源 8 冷鏈用
var orderType = DeliveryPickConstans.DELIVERY_TYPE //訂單類型 2 線上外賣訂單,7 自取訂單
var orderFrom = 0 //訂單來源
fun getHistoryOrderList(pageIndex: String, orderNum: String = "", startDate: String, endDate: String, status: String) {
launch({
......
package com.joe.print.mvp.print.service;
import android.app.IntentService;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
......@@ -13,6 +12,8 @@ import android.util.Log;
import androidx.annotation.Nullable;
import io.reactivex.functions.Consumer;
import com.epson.epos2.Epos2Exception;
import com.epson.epos2.printer.Printer;
import com.epson.epos2.printer.PrinterStatusInfo;
......@@ -24,7 +25,6 @@ import com.gingersoft.gsa.cloud.common.core.user.UserContext;
import com.gingersoft.gsa.cloud.common.logan.LoganManager;
import com.gingersoft.gsa.cloud.common.printer.AidlUtil;
import com.gingersoft.gsa.cloud.common.printer.plugins.PrintPaperPlugins;
import com.gingersoft.gsa.cloud.common.utils.FileUtils;
import com.gingersoft.gsa.cloud.common.utils.JsonUtils;
import com.gingersoft.gsa.cloud.common.utils.gson.GsonUtils;
import com.gingersoft.gsa.cloud.common.utils.okhttpUtils.OkHttp3Utils;
......@@ -32,20 +32,17 @@ import com.gingersoft.gsa.cloud.common.utils.other.TextUtil;
import com.gingersoft.gsa.cloud.common.utils.threadPool.ThreadPoolManager;
import com.gingersoft.gsa.cloud.common.utils.time.TimeUtils;
import com.gingersoft.gsa.cloud.common.utils.toast.ToastUtils;
import com.gingersoft.gsa.cloud.common.utils.view.BitmapUtil;
import com.gingersoft.gsa.cloud.database.bean.PrintCurrencyBean;
import com.gingersoft.gsa.cloud.database.bean.PrinterDeviceBean;
import com.gingersoft.gsa.cloud.database.utils.PrinterDeviceDaoUtils;
import com.gingersoft.gsa.cloud.print.PrintExecutor;
import com.gingersoft.gsa.cloud.print.PrintSocketHolder;
import com.gingersoft.gsa.cloud.print.PrinterWriter58mm;
import com.gingersoft.gsa.cloud.print.bean.PrintContent;
import com.gingersoft.gsa.cloud.print.bean.PrjBean;
import com.gingersoft.gsa.cloud.print.bean.UpdateBean;
import com.hyweb.n5.lib.constant.PrinterConstant;
import com.hyweb.n5.lib.util.PrinterUtil;
import com.hyweb.n5.server.aidl.IOnPrintCallback;
import com.jess.arms.utils.RxLifecycleUtils;
import com.joe.print.mvp.print.PrintPrjKitchen;
import com.joe.print.mvp.print.PrinterRoot;
import com.joe.print.mvp.print.common.PrinterFinderCallback;
......@@ -58,13 +55,11 @@ import com.joe.print.mvp.print.usb.UsbPrinterFinder;
import com.joe.print.mvp.print.utils.MyPrintUtils;
import com.sunmi.peripheral.printer.InnerResultCallbcak;
import com.xuexiang.rxutil2.rxjava.RxJavaUtils;
import com.xuexiang.rxutil2.rxjava.task.RxIOTask;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.File;
import java.io.IOException;
import java.io.PrintStream;
import java.util.ArrayList;
......@@ -79,7 +74,6 @@ import io.reactivex.Observable;
import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Consumer;
import io.reactivex.schedulers.Schedulers;
import jcifs.smb.SmbFile;
import jcifs.smb.SmbFileOutputStream;
......@@ -90,48 +84,67 @@ import static com.gingersoft.gsa.cloud.database.bean.PrinterDeviceBean.PRINT_IP;
import static com.gingersoft.gsa.cloud.database.bean.PrinterDeviceBean.PRINT_LOCAL;
import static com.gingersoft.gsa.cloud.database.bean.PrinterDeviceBean.PRINT_PRJ_PC;
import static com.gingersoft.gsa.cloud.database.bean.PrinterDeviceBean.PRINT_USB;
import static com.gingersoft.gsa.cloud.print.bean.PrjBean.DataBean.Bean.PRJ_CUTE;
/**
* 在用戶登錄成功後,打開打印service,每隔3~5秒請求一次。請求到了數據就進行打印邏輯
*/
public class PrjService extends Service implements ReceiveListener {
// private static final String TAG = PrjService.class.getSimpleName();
private Disposable disposable;
private Disposable wakeDisposable;
/**
* 測試數據
*/
private String json = "{\"success\":true,\"sysTime\":1595066909048,\"data\":{\"K1\":[{\"id\":2461,\"printerDeviceId\":87,\"status\":1,\"orderNo\":\"153201882821850443\",\"orderTime\":2020,\"sender\":\"\",\"person\":0,\"number\":1,\"orderDetailsTime\":\"Jul 10, 2020 11:59:29 AM\",\"orderDetailsId\":48863119,\"productName\":\"紅棗銀耳湯\",\"parentId\":48863115,\"type\":4,\"createTime\":1595066908689,\"productId\":5189,\"requests\":1,\"actualPrinterDeviceId\":87,\"takeFoodCode\":\"H462\",\"billNo\":\"0643\",\"orderType\":7,\"userName\":\"stefan001\"},{\"id\":2461,\"printerDeviceId\":87,\"status\":1,\"orderNo\":\"153201882821850443\",\"orderTime\":2020,\"sender\":\"\",\"person\":0,\"number\":1,\"orderDetailsTime\":\"Jul 10, 2020 11:59:29 AM\",\"orderDetailsId\":48863119,\"productName\":\"紅棗銀耳湯\",\"parentId\":48863115,\"type\":4,\"createTime\":1595066908689,\"productId\":5189,\"requests\":1,\"actualPrinterDeviceId\":87,\"takeFoodCode\":\"H462\",\"billNo\":\"0643\",\"orderType\":7,\"userName\":\"stefan001\"}]}}";
/**
* 打印機列表
*/
private List<PrinterDeviceBean> printerDeviceBeans;
private List<PrjBean.DataBean.Bean> printDatas = new ArrayList<>();
// private Map<String, List<PrjBean.DataBean.Bean>> listMap = new HashMap<>();
private List<PrintCurrencyBean> printCurrencyBeans;//通用打印配置
/**
* 搜索USB打印機
*/
private UsbPrinterFinder printerFinder;
/**
* USB打印機列表
*/
private List<UsbPrinter> mUsbPrinters;
private Context mContext;
private String TAG = "Prj";
/**
* 本次打印prj總數
*/
private int totalPrj;
/**
* 當前prj下標,如果totalPrj為10,currentIndex 為1, 顯示頁數為 1/10
*/
private int currentIndex;
@Override
public void onCreate() {
super.onCreate();
mContext = this;
initUsbPrint();
LoganManager.w_printer(TAG, "currentThreadName: " + Thread.currentThread().getName());
LoganManager.w_printer(TAG, "開始請求 PRJ 數據");
//開始請求
startGetPrjInfo();
}
@Nullable
@Override
public IBinder onBind(Intent intent) {
return null;
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
mContext = this;
ThreadPoolManager.getInstence().putExecutableTasks(() -> {
LoganManager.w_printer(TAG, "currentThreadName: " + Thread.currentThread().getName());
LoganManager.w_printer(TAG, "開始請求 PRJ 數據");
getPrintList();
//開始請求
startGetPrjInfo();
});
return super.onStartCommand(intent, flags, startId);
}
private UsbPrinterFinder printerFinder;
private List<UsbPrinter> mUsbPrinters;
/**
* 初始化usb打印
*/
public void initUsbPrint() {
printerFinder = new UsbPrinterFinder(mContext, new PrinterFinderCallback<UsbPrinter>() {
@Override
......@@ -153,223 +166,45 @@ public class PrjService extends Service implements ReceiveListener {
printerFinder.startFinder();
}
private void getPrintList() {
if (printerDeviceBeans == null || printerDeviceBeans.size() == 0) {
PrinterDeviceDaoUtils printerDeviceDaoUtils = new PrinterDeviceDaoUtils(this);
printerDeviceBeans = printerDeviceDaoUtils.queryAllPrinterDeviceBean();
printerDeviceDaoUtils.closeConnection();
}
printCurrencyBeans = MyPrintUtils.getPrintCurrencyBeans(this);
}
@Nullable
@Override
public IBinder onBind(Intent intent) {
return null;
}
private Disposable polling;
/**
* 開啟輪詢查詢prj數據
*/
private void startGetPrjInfo() {
cancel(wakeDisposable);
cancel(disposable);
if (!UserContext.newInstance().isLogin()) {
return;
}
Observable.interval(10, 30, TimeUnit.SECONDS)
.subscribe(new Observer<Long>() {
@Override
public void onSubscribe(Disposable d) {
disposable = d;
LoganManager.w_printer(TAG, "startGetPrjInfo onSubscribe");
}
@Override
public void onNext(Long aLong) {
LoganManager.w_printer(TAG, "startGetPrjInfo onNext");
getPrjInfo();
}
@Override
public void onError(Throwable e) {
LoganManager.w_printer(TAG, "startGetPrjInfo onError:" + e.getMessage());
}
@Override
public void onComplete() {
LoganManager.w_printer(TAG, "startGetPrjInfo onComplete");
}
});
}
/**
* 請求prj數據
*/
private void getPrjInfo() {
OkHttp3Utils.get(HttpsConstans.ROOT_SERVER_ADDRESS_FORMAL + "printerRecording/get?restaurantId=" + RestaurantInfoManager.newInstance().getRestaurantId())
.subscribeOn(Schedulers.io())//切换到io线程進行網絡請求
.observeOn(Schedulers.io())//切換到io线程處理請求結果
.subscribe(new Observer<String>() {
@Override
public void onSubscribe(Disposable d) {
LoganManager.w_printer(TAG, "RxCurrentThreadName: " + Thread.currentThread().getName());
LoganManager.w_printer(TAG, "getPrjInfo onSubscribe");
}
@Override
public void onNext(String prjInfo) {
Consumer<Long> consumer = s -> {
Disposable subscribe = OkHttp3Utils.get(HttpsConstans.ROOT_SERVER_ADDRESS_FORMAL + "printerRecording/get?restaurantId=" + RestaurantInfoManager.newInstance().getRestaurantId())
.subscribe(prjInfo -> {
LoganManager.w_printer(TAG, "getPrjInfo onNext: " + prjInfo);
//請求到數據,停止輪詢,開始打印,在打印完之後再重新開始輪詢
// startPrint(s);
newPrint(prjInfo);
//開啟另一個定時,三十秒之後自動請求,避免上面的打印成功或失敗時沒有回調。
cancel(wakeDisposable);
Observable.timer(30, TimeUnit.SECONDS)
.subscribe(new Observer<Long>() {
@Override
public void onSubscribe(Disposable d) {
wakeDisposable = d;
LoganManager.w_printer(TAG, "getPrjInfo timer onSubscribe");
}
@Override
public void onNext(Long aLong) {
LoganManager.w_printer(TAG, "getPrjInfo timer onNext");
startGetPrjInfo();
}
@Override
public void onError(Throwable e) {
LoganManager.w_printer(TAG, "getPrjInfo timer onError: " + e.getMessage());
}
@Override
public void onComplete() {
LoganManager.w_printer(TAG, "getPrjInfo timer onComplete");
}
});
}
@Override
public void onError(Throwable e) {
LoganManager.w_printer(TAG, "getPrjInfo onError:" + e.getMessage());
}
@Override
public void onComplete() {
LoganManager.w_printer(TAG, "getPrjInfo onComplete");
}
});
}
/**
* 取消輪詢
*/
private void cancel(Disposable disposable) {
if (disposable != null) {
disposable.dispose();
});
};
//間隔30秒獲取一次
if (polling != null) {
polling.dispose();
}
polling = RxJavaUtils.polling(30, consumer);
}
private PrinterRoot printerInIt;
private String json = "{\"success\":true,\"sysTime\":1595066909048,\"data\":{\"K1\":[{\"id\":2461,\"printerDeviceId\":87,\"status\":1,\"orderNo\":\"153201882821850443\",\"orderTime\":2020,\"sender\":\"\",\"person\":0,\"number\":1,\"orderDetailsTime\":\"Jul 10, 2020 11:59:29 AM\",\"orderDetailsId\":48863119,\"productName\":\"紅棗銀耳湯\",\"parentId\":48863115,\"type\":4,\"createTime\":1595066908689,\"productId\":5189,\"requests\":1,\"actualPrinterDeviceId\":87,\"takeFoodCode\":\"H462\",\"billNo\":\"0643\",\"orderType\":7,\"userName\":\"stefan001\"},{\"id\":2461,\"printerDeviceId\":87,\"status\":1,\"orderNo\":\"153201882821850443\",\"orderTime\":2020,\"sender\":\"\",\"person\":0,\"number\":1,\"orderDetailsTime\":\"Jul 10, 2020 11:59:29 AM\",\"orderDetailsId\":48863119,\"productName\":\"紅棗銀耳湯\",\"parentId\":48863115,\"type\":4,\"createTime\":1595066908689,\"productId\":5189,\"requests\":1,\"actualPrinterDeviceId\":87,\"takeFoodCode\":\"H462\",\"billNo\":\"0643\",\"orderType\":7,\"userName\":\"stefan001\"}]}}";
/**
* 開始打印
* 處理獲取到的prj數據
*
* @param json prj
*/
// private void startPrint(String json) {
// printDatas.clear();
// listMap.clear();
// PrjBean prjBean = JsonUtils.parseObject(json, PrjBean.class);
// if (prjBean == null || prjBean.getData() == null) {
// return;
// }
// PrintCurrencyBean printCurrencyBean;
// //有數據,取消輪詢,等待打印結束。
// cancel(disposable);
// try {
// JSONObject jsonObject = new JSONObject(prjBean.getData());
// //通过迭代器获取这段json当中所有的key值
// Iterator keys = jsonObject.keys();
// //然后通过一个循环取出所有的key值
// while (keys.hasNext()) {
// String key = String.valueOf(keys.next());
// //最后就可以通过刚刚得到的key值去解析后面的json了
// JSONArray dataJson = (JSONArray) jsonObject.get(key);
// List<PrjBean.DataBean.Bean> datas = JsonUtils.parseArray(dataJson.toString(), PrjBean.DataBean.Bean.class);
// listMap.put(key, datas);//打印位置和需要打印的數據
// PrintPrjKitchen.getPrjMap().put(key, datas);
// printDatas.addAll(datas);
// }
// } catch (JSONException e) {
// e.printStackTrace();
// }
// if (printerInIt == null) {
// printerInIt = PrinterRoot.getPrinterByType(PRINT_KITCHEN);
// }
// //獲取打印機列表
// getPrintList();
//// for (Map.Entry<String, List<PrjBean.DataBean.Bean>> prjMap : listMap.entrySet()) {
//// for (PrinterDeviceBean deviceBean : printerDeviceBeans) {
//// if (prjMap.getKey().equalsIgnoreCase(deviceBean.getName())) {
//// if ((deviceBean.getPrinterName() != null && deviceBean.getPrinterName().toLowerCase().contains("EPSON".toLowerCase()))
//// && (deviceBean.getModel() != null && deviceBean.getModel().toLowerCase().contains("TM-U220B".toLowerCase()))) {
//// //針式打印
//// //Epson打印機打印,調用對應的方法
//// EpsonPrint mPrinter = EpsonPrint.getInstance();
//// mPrinter.initializeObject(GsaCloudApplication.getAppContext(), this);
//// int paperWidth = 42;
//// if (deviceBean.getPaperSpecification() != null) {
//// paperWidth = (int) (Double.parseDouble(deviceBean.getPaperSpecification()) / 6);
//// }
//// List<List<PrintInfoBean>> prjBeans = PrintInfoBean.transPrjBean(prjMap.getValue(), prjMap.getKey(), deviceBean, printCurrencyBean);
//// for (List<PrintInfoBean> prjPrintBean : prjBeans) {
//// mPrinter.putPrintString(deviceBean.getIp(), paperWidth, prjPrintBean);
//// }
//// }
//// }
//// }
//// }
// if (printerInIt != null) {
// printerInIt.setmContext(this);
// for (Map.Entry<String, List<Bitmap>> entry : printerInIt.getPrintBitmap(this, null).entrySet()) {
// //遍歷所有的需要打印的內容
// for (PrinterDeviceBean deviceBean : printerDeviceBeans) {
// //遍歷打印機列表,找到對應的打印機,沒找到的就不打印
// if (entry.getKey().toLowerCase().equals(deviceBean.getName().toLowerCase())) {
//// if ((deviceBean.getPrinterName() != null && deviceBean.getPrinterName().toLowerCase().contains("EPSON".toLowerCase()))
//// && (deviceBean.getModel() != null && deviceBean.getModel().toLowerCase().contains("TM-U220B".toLowerCase()))) {
//// //針式打印機在上面處理
//// } else {
// Log.e(TAG, entry.getKey() + "開始打印IP:" + deviceBean.getIp());
// printerInIt.ipDevicePrint(deviceBean, entry.getValue(), this, this);
// break;
//// }
// }
// }
// }
// }
// }
private int totalPrj;
private int currentIndex;
private void newPrint(String json) {
printDatas.clear();
Map<String, List<PrjBean.DataBean.Bean>> listMap = new HashMap<>();
currentIndex = 0;
totalPrj = 0;
PrjBean prjBean = JsonUtils.parseObject(json, PrjBean.class);
//判斷有沒有需要打印的
if (prjBean == null || prjBean.getData() == null) {
LoganManager.w_printer(TAG, "newPrint prjBean == null || prjBean.getData() == null ");
return;
}
//有數據,取消輪詢,等待打印結束。
cancel(disposable);
//第一步:解析PRJ數據,格式為 Map<廚房位置,需要打印的數據>
try {
JSONObject jsonObject = new JSONObject(prjBean.getData());
......@@ -404,23 +239,33 @@ public class PrjService extends Service implements ReceiveListener {
e.printStackTrace();
LoganManager.w_printer(TAG, "newPrint JSONException: " + e.getMessage());
}
//設置總頁數,當前頁數
setPrjIndex(listMap, totalPrj);
initPrinterDevices();
//獲取打印設備信息
getPrinterDevices();
foreachPrint(listMap);
}
private Map<String, List<PrjBean.DataBean.Bean>> setPrjIndex(Map<String, List<PrjBean.DataBean.Bean>> listMap, int totalPrj) {
/**
* 設置prj打印下標,頁數
*
* @param listMap 需要打印的數據
* @param totalPrj 總prj數量
*/
private void setPrjIndex(Map<String, List<PrjBean.DataBean.Bean>> listMap, int totalPrj) {
LoganManager.w_printer(TAG, "setPrjIndex totalPrj: " + totalPrj);
for (Map.Entry<String, List<PrjBean.DataBean.Bean>> prjMap : listMap.entrySet()) {
//上一個對象是否切紙
//上一個對象是否切紙,因為如果上一張要切紙,當前不切紙,就不+1,上一張不切紙,本次切紙,+1
boolean lastIsCute = false;
for (PrjBean.DataBean.Bean bean : prjMap.getValue()) {
//設置prj總數量
bean.setTotalPrj(totalPrj);
if (bean.getStatus() == 2) {
if (bean.getStatus() == PRJ_CUTE) {
//要切紙,紙張數+1
currentIndex++;
lastIsCute = true;
} else {
//顯示給用戶看,需要從1開始
if (currentIndex == 0) {
currentIndex = 1;
} else if (lastIsCute) {
......@@ -433,46 +278,13 @@ public class PrjService extends Service implements ReceiveListener {
}
currentIndex++;
}
return listMap;
}
private Map<String, List<PrjBean.DataBean.Bean>> printDataToMap(List<PrjBean.DataBean.Bean> printData) {
Map<String, List<PrjBean.DataBean.Bean>> map = new HashMap<>();
PrinterDeviceBean defaultPainter = null;
initPrinterDevices();
//獲得默認的打印機
for (PrinterDeviceBean printerDeviceBean : printerDeviceBeans) {
if (printerDeviceBean.getType() == 2) {
defaultPainter = printerDeviceBean;
break;
}
}
//將prj集合通過打印位置轉成map
for (PrjBean.DataBean.Bean bean : printData) {
if (TextUtil.isNotEmptyOrNullOrUndefined(bean.getPrintPosition())) {
List<PrjBean.DataBean.Bean> mapByKey = map.get(bean.getPrintPosition());
if (mapByKey != null) {
mapByKey.add(bean);
} else {
map.put(bean.getPrintPosition(), Collections.singletonList(bean));
}
} else if (defaultPainter != null) {
//沒有打印位置的,由默認的位置去打印
bean.setPrintPosition(defaultPainter.getName());
List<PrjBean.DataBean.Bean> mapByKey = map.get(bean.getPrintPosition());
if (mapByKey != null) {
mapByKey.add(bean);
} else {
map.put(bean.getPrintPosition(), Collections.singletonList(bean));
}
} else {
ToastUtils.show(this, "未配置打印機");
}
}
return map;
}
/**
* 遍歷需要打印的數據,找到對應的打印機,和通用打印設置數據合併
*
* @param listMap 需要打印的數據,key為廚房位置,value是prj數據
*/
private void foreachPrint(Map<String, List<PrjBean.DataBean.Bean>> listMap) {
LoganManager.w_printer(TAG, "foreachPrint");
//雙重遍歷可以以後優化
......@@ -495,16 +307,23 @@ public class PrjService extends Service implements ReceiveListener {
}
}
private void initPrinterDevices() {
/**
* 獲取打印機列表
*/
private void getPrinterDevices() {
LoganManager.w_printer(TAG, "initPrinterDevices");
//讀取打印機和通用配置,可以優化
//讀取打印機和通用配置,每次都去數據庫拿,為了保證用戶修改了打印機數據之後,打印機信息的一致性,可以優化
//獲取所有打印機
PrinterDeviceDaoUtils printerDeviceDaoUtils = new PrinterDeviceDaoUtils(this);
printerDeviceBeans = printerDeviceDaoUtils.queryAllPrinterDeviceBean();
//獲取所有通用配置
printCurrencyBeans = MyPrintUtils.getPrintCurrencyBeans(this);
}
/**
* 獲取打印機通用配置
*
* @param beans prj數據
* @return
*/
private PrintCurrencyBean getPrintCurrencyBean(List<PrjBean.DataBean.Bean> beans) {
PrintCurrencyBean printCurrencyBean = null;
if (beans != null && beans.size() > 0) {
......@@ -526,7 +345,6 @@ public class PrjService extends Service implements ReceiveListener {
* 生成用於打印的prj的Bitmap
*/
private void generatePrintData(String key, List<PrjBean.DataBean.Bean> beans, PrinterDeviceBean printerDeviceBean) {
LoganManager.w_printer(TAG, "generatePrintData PrinterDeviceBean deviceType: " + printerDeviceBean.getPrinterDeviceType()
+ " ip: " + printerDeviceBean.getIp());
......@@ -535,137 +353,104 @@ public class PrjService extends Service implements ReceiveListener {
orderType = beans.get(0).getOrderType();
}
PrintPaperPlugins.getOnPrinterFlowHandler().onPrinterDataBefore(orderType, GsonUtils.GsonString(beans), GsonUtils.GsonString(printerDeviceBean));
if (isPinPrinter(printerDeviceBean) && printerDeviceBean.getPrinterDeviceType() == PRINT_IP) {
//針式打印機並且打印機類型為IP打印,生成獨特的格式
//針式打印機並且打印機類型為IP打印
stylusPrinting(key, beans, printerDeviceBean);
} else if (printerDeviceBean.getPrinterDeviceType() == PRINT_PRJ_PC) {
//prj模式,生成文件到pc端,未完成
// prjPc(beans, printerDeviceBean);
} else if (printerDeviceBean.getPrinterDeviceType() == PRINT_LOCAL && PrintConstans.PRINT_MODEL_WISEPOS.contains(Build.MODEL)) {
//本機打印並且是BBPOS,還沒對接BBPOS的prj
} else {
//其他的都生成這種格式的,就放一起
List<Map<String, Bitmap>> bitmapMaps = generatePrintMaps(key, beans, printerDeviceBean);
EpsIds = getPrintIds(bitmapMaps);
//第一個參數是機型,第二個參數是語言,
Printer mPrinter = null;
try {
mPrinter = new Printer(Printer.TM_U220, Printer.MODEL_KOREAN, this);
mPrinter.setReceiveEventListener(this);
} catch (Epos2Exception e) {
e.printStackTrace();
updatePrjFailure(getPrintIds(bitmapMaps));
switch (printerDeviceBean.getPrinterDeviceType()) {
case PRINT_IP:
//IP打印
ipPrint(printerDeviceBean, bitmapMaps);
break;
case PRINT_LOCAL:
//本地N5或Sunmi打印
locationPrint(bitmapMaps);
break;
case PRINT_USB:
//USB打印
usbPrint(bitmapMaps);
break;
default:
break;
}
if (mPrinter != null) {
try {
mPrinter.clearCommandBuffer();
for (int i = 0; i < bitmapMaps.size(); i++) {
for (Map.Entry<String, Bitmap> mapEntry : bitmapMaps.get(i).entrySet()) {
mPrinter.addImage(mapEntry.getValue(), 0, 0,
mapEntry.getValue().getWidth(),
mapEntry.getValue().getHeight(),
Printer.COLOR_1,
Printer.MODE_MONO_HIGH_DENSITY,//高密度
Printer.HALFTONE_DITHER,//半色調抖動
Printer.PARAM_DEFAULT,
Printer.COMPRESS_NONE);//壓縮
mPrinter.addCut(Printer.CUT_FEED);
}
}
} catch (Epos2Exception e) {
e.printStackTrace();
updatePrjFailure(getPrintIds(bitmapMaps));
mPrinter.clearCommandBuffer();
}
try {
mPrinter.connect("TCP:" + printerDeviceBean.getIp(), Printer.PARAM_DEFAULT);
mPrinter.sendData(Printer.PARAM_DEFAULT);
} catch (Exception e) {
e.printStackTrace();
updatePrjFailure(getPrintIds(bitmapMaps));
while (true) {
try {
mPrinter.disconnect();
break;
} catch (final Exception ex) {
if (ex instanceof Epos2Exception) {
//Note: If printer is processing such as printing and so on, the disconnect API returns ERR_PROCESSING.
if (((Epos2Exception) ex).getErrorStatus() == Epos2Exception.ERR_PROCESSING) {
} else {
break;
}
} else {
break;
}
}
}
mPrinter.clearCommandBuffer();
mPrinter.setReceiveEventListener(null);
}
}
/**
* prj模式,生成prj文件到共享電腦上
*
* @param beans 需要打印的數據
* @param printerDeviceBean 打印設備信息
*/
private void prjPc(List<PrjBean.DataBean.Bean> beans, PrinterDeviceBean printerDeviceBean) {
//PRJ模式,生成PRJ文件到共享的電腦上
ThreadPoolManager.getInstence().putExecutableTasks(() -> {
List<PrjBean.DataBean.Bean> noCutList = new ArrayList<>();
List<PrjBean.DataBean.Bean> cutList = new ArrayList<>();
for (PrjBean.DataBean.Bean bean : beans) {
if (bean.getStatus() == 2) {
//需要切紙
cutList.add(bean);
} else {
//不需要切紙
noCutList.add(bean);
}
} else {
updatePrjFailure(EpsIds);
}
} else if (printerDeviceBean.getPrinterDeviceType() == PRINT_PRJ_PC) {
} else {
List<Map<String, Bitmap>> bitmapMaps = null;
if (printerDeviceBean.getPrinterDeviceType() == PRINT_LOCAL && PrintConstans.PRINT_MODEL_WISEPOS.contains(Build.MODEL)) {
//本機打印並且是BBPOS
} else if (printerDeviceBean.getPrinterDeviceType() == PRINT_PRJ_PC) {
//PRJ模式,生成PRJ文件到共享的電腦上
ThreadPoolManager.getInstence().putExecutableTasks(() -> {
List<PrjBean.DataBean.Bean> noCutList = new ArrayList<>();
List<PrjBean.DataBean.Bean> cutList = new ArrayList<>();
for (PrjBean.DataBean.Bean bean : beans) {
if (bean.getStatus() == 2) {
//需要切紙
cutList.add(bean);
} else {
//不需要切紙
noCutList.add(bean);
String rootPath = "smb://" + printerDeviceBean.getPrintPath() + "/";
try {
SmbFile smbFile = new SmbFile(rootPath);
smbFile.connect();
if (smbFile.isDirectory()) {
for (int i = 0; i < cutList.size(); i++) {
String newFilePath = rootPath + System.currentTimeMillis() + ".prj";
SmbFile createFile = new SmbFile(newFilePath);
createFile.createNewFile();
if (createFile.exists()) {
PrintStream ps = new PrintStream(new SmbFileOutputStream(createFile));
// 往文件里写入字符串
String prjInfo = "[printType]ptKitchen\n" +
"[table]4\n" +
"[date]落單時間:11-13 17:48\n" +
"[waiter]n5 收銀員\n" +
"[KP]K2烤爐\n" +
"[PAX]人數:2\n" +
"[line]\n" +
"[food_1]1 包子(主項)\n" +
"[food_1]1 包子(主項)\n" +
"[table2]4\n";
ps.println(prjInfo);
}
}
String rootPath = "smb://" + printerDeviceBean.getPrintPath() + "/";
try {
SmbFile smbFile = new SmbFile(rootPath);
smbFile.connect();
if (smbFile.isDirectory()) {
for (int i = 0; i < cutList.size(); i++) {
String newFilePath = rootPath + System.currentTimeMillis() + ".prj";
SmbFile createFile = new SmbFile(newFilePath);
createFile.createNewFile();
if (createFile.exists()) {
PrintStream ps = new PrintStream(new SmbFileOutputStream(createFile));
// 往文件里写入字符串
String prjInfo = "[printType]ptKitchen\n" +
"[table]4\n" +
"[date]落單時間:11-13 17:48\n" +
"[waiter]n5 收銀員\n" +
"[KP]K2烤爐\n" +
"[PAX]人數:2\n" +
"[line]\n" +
"[food_1]1 包子(主項)\n" +
"[food_1]1 包子(主項)\n" +
"[table2]4\n";
ps.println(prjInfo);
if (noCutList.size() > 0) {
String newFilePath = rootPath + System.currentTimeMillis() + ".prj";
SmbFile createFile = new SmbFile(newFilePath);
createFile.createNewFile();
if (createFile.exists()) {
PrintStream ps = new PrintStream(new SmbFileOutputStream(createFile));
PrjBean.DataBean.Bean bean = noCutList.get(0);
String tableName = "";
if (TextUtil.isEmptyOrNullOrUndefined(bean.getTableName())) {
if (bean.getOrderType() == 7) {
tableName = "自取";
} else {
tableName = "外賣";
}
} else {
tableName = bean.getTableName();
}
if (noCutList.size() > 0) {
String newFilePath = rootPath + System.currentTimeMillis() + ".prj";
SmbFile createFile = new SmbFile(newFilePath);
createFile.createNewFile();
if (createFile.exists()) {
PrintStream ps = new PrintStream(new SmbFileOutputStream(createFile));
PrjBean.DataBean.Bean bean = noCutList.get(0);
String tableName = "";
if (TextUtil.isEmptyOrNullOrUndefined(bean.getTableName())) {
if (bean.getOrderType() == 7) {
tableName = "自取";
} else {
tableName = "外賣";
}
} else {
tableName = bean.getTableName();
}
// 往文件里写入字符串
// 往文件里写入字符串
// String prjInfo = "[printType]ptKitchen\n" +
// "[table]4\n" +
// "[date]落單時間:11-13 17:48\n" +
......@@ -676,50 +461,101 @@ public class PrjService extends Service implements ReceiveListener {
// "[food_1]1 包子(主項)\n" +
// "[food_1]1 包子(主項)\n" +
// "[table2]4\n";
String prjInfo = "[printType]ptKitchen\n" +
"[table]" + tableName + "\n" +
"[date]落單時間:11-13 17:48\n" +
"[waiter]n5 收銀員\n" +
"[KP]K2烤爐\n" +
"[PAX]人數:2\n" +
"[line]\n" +
"[food_1]1 包子(主項)\n" +
"[food_1]1 包子(主項)\n" +
"[table2]" + tableName + "\n";
ps.println(prjInfo);
}
}
String prjInfo = "[printType]ptKitchen\n" +
"[table]" + tableName + "\n" +
"[date]落單時間:11-13 17:48\n" +
"[waiter]n5 收銀員\n" +
"[KP]K2烤爐\n" +
"[PAX]人數:2\n" +
"[line]\n" +
"[food_1]1 包子(主項)\n" +
"[food_1]1 包子(主項)\n" +
"[table2]" + tableName + "\n";
ps.println(prjInfo);
}
}
} else {
ToastUtils.show(this, "PRJ輸出路徑必須為文件夾");
}
} catch (IOException e) {
e.printStackTrace();
}
});
}
/**
* 針式打印機
*
* @param key 打印位置
* @param beans 打印信息
* @param printerDeviceBean 打印設備信息
*/
private void stylusPrinting(String key, List<PrjBean.DataBean.Bean> beans, PrinterDeviceBean printerDeviceBean) {
//針式打印機並且打印機類型為IP打印,生成獨特的格式
List<Map<String, Bitmap>> bitmapMaps = generatePrintMaps(key, beans, printerDeviceBean);
EpsIds = getPrintIds(bitmapMaps);
//第一個參數是機型,第二個參數是語言,
Printer mPrinter = null;
try {
mPrinter = new Printer(Printer.TM_U220, Printer.MODEL_KOREAN, this);
mPrinter.setReceiveEventListener(this);
} catch (Epos2Exception e) {
e.printStackTrace();
updatePrjFailure(getPrintIds(bitmapMaps));
}
if (mPrinter != null) {
try {
mPrinter.clearCommandBuffer();
for (int i = 0; i < bitmapMaps.size(); i++) {
for (Map.Entry<String, Bitmap> mapEntry : bitmapMaps.get(i).entrySet()) {
mPrinter.addImage(mapEntry.getValue(), 0, 0,
mapEntry.getValue().getWidth(),
mapEntry.getValue().getHeight(),
Printer.COLOR_1,
Printer.MODE_MONO_HIGH_DENSITY,//高密度
Printer.HALFTONE_DITHER,//半色調抖動
Printer.PARAM_DEFAULT,
Printer.COMPRESS_NONE);//壓縮
mPrinter.addCut(Printer.CUT_FEED);
}
}
} catch (Epos2Exception e) {
e.printStackTrace();
updatePrjFailure(getPrintIds(bitmapMaps));
mPrinter.clearCommandBuffer();
}
try {
mPrinter.connect("TCP:" + printerDeviceBean.getIp(), Printer.PARAM_DEFAULT);
mPrinter.sendData(Printer.PARAM_DEFAULT);
} catch (Exception e) {
e.printStackTrace();
updatePrjFailure(getPrintIds(bitmapMaps));
while (true) {
try {
mPrinter.disconnect();
break;
} catch (final Exception ex) {
if (ex instanceof Epos2Exception) {
//Note: If printer is processing such as printing and so on, the disconnect API returns ERR_PROCESSING.
if (((Epos2Exception) ex).getErrorStatus() == Epos2Exception.ERR_PROCESSING) {
} else {
break;
}
} else {
ToastUtils.show(this, "PRJ輸出路徑必須為文件夾");
break;
}
} catch (IOException e) {
e.printStackTrace();
}
});
} else {
bitmapMaps = generatePrintMaps(key, beans, printerDeviceBean);
switch (printerDeviceBean.getPrinterDeviceType()) {
case PRINT_IP:
//IP打印
ipPrint(printerDeviceBean, bitmapMaps);
break;
case PRINT_LOCAL:
//本地N5或Sunmi打印
locationPrint(bitmapMaps);
break;
case PRINT_USB:
//USB打印
usbPrint(bitmapMaps);
break;
default:
break;
}
mPrinter.clearCommandBuffer();
mPrinter.setReceiveEventListener(null);
}
} else {
updatePrjFailure(EpsIds);
}
}
/**
* ip設備打印
*/
......@@ -974,9 +810,6 @@ public class PrjService extends Service implements ReceiveListener {
* @param printState 打印狀態 1未打印 2打印中 3已打印
*/
private void updatePrjState(int printState, String ids) {
if (printDatas == null) {
return;
}
Long time = null;
if (printState == 3) {
time = TimeUtils.getCurrentTimeInLong();
......
......@@ -27,6 +27,7 @@ public class BasicUnitBean {
private long createTime;
private long updateTime;
private int updateUid;
private Integer id;
public BasicUnitBean() {
}
......
......@@ -40,6 +40,8 @@ public interface FoodUnitPageContract {
void callBackDeputyUnit(List<DeputyUnitBean> deputyUnitBeans);
void deleteDeputyUnit(int position);
void deleteUnitKey(int position);
}
//Model层定义接口,外部只需关心Model返回的数据,无需关心内部细节,即是否使用缓存
......@@ -69,5 +71,7 @@ public interface FoodUnitPageContract {
* @return
*/
Observable<BaseResult> addBasicUnit(RequestBody requestBody);
Observable<BaseResult> deleteUnitKey(int id);
}
}
......@@ -68,4 +68,10 @@ public class FoodUnitPageModel extends BaseModel implements FoodUnitPageContract
public Observable<BaseResult> addBasicUnit(RequestBody requestBody) {
return mRepositoryManager.obtainRetrofitService(SupplierServer.class).addDeputyUnitInput(requestBody);
}
@Override
public Observable<BaseResult> deleteUnitKey(int id) {
return mRepositoryManager.obtainRetrofitService(SupplierServer.class).deleteUnitKey(id);
}
}
\ No newline at end of file
......@@ -148,6 +148,10 @@ public class FoodUnitPagePresenter extends BasePresenter<FoodUnitPageContract.Mo
});
}
/**
* 新增基本單位
* @param data
*/
public void addDeputyUnit(List<DeputyUnitBean> data) {
//新增為false,修改為true
if (isUpdate) {
......@@ -290,4 +294,30 @@ public class FoodUnitPagePresenter extends BasePresenter<FoodUnitPageContract.Mo
});
}
/**
* 刪除基本單位快捷輸入的
* @param id 單位id
* @param position 單位下標,刪除成功後本地刷新
*/
public void deleteUnitKey(int id, int position){
mModel.deleteUnitKey(id)
.subscribeOn(Schedulers.io())
.doOnSubscribe(disposable -> mRootView.showLoading(Constant.SAVE_LOADING))
.subscribeOn(AndroidSchedulers.mainThread())
.observeOn(AndroidSchedulers.mainThread())
.doAfterTerminate(() -> mRootView.hideLoading())
.compose(RxLifecycleUtils.bindToLifecycle(mRootView))
.subscribe(new ErrorHandleSubscriber<BaseResult>(mErrorHandler) {
@Override
public void onNext(BaseResult baseResult) {
if (baseResult.isSuccess()) {
mRootView.deleteUnitKey(position);
} else if (TextUtil.isNotEmptyOrNullOrUndefined(baseResult.getErrMsg())) {
mRootView.showMessage(baseResult.getErrMsg());
} else {
mRootView.showMessage(GET_INFO_ERROR);
}
}
});
}
}
......@@ -273,6 +273,7 @@ public interface SupplierServer {
/**
* 修改採購單信息
*
* @param orderId 訂單id
* @return
*/
......@@ -393,6 +394,14 @@ public interface SupplierServer {
@POST("basicUnitType/add" + RetrofitUrlManager.IDENTIFICATION_PATH_SIZE + 2)
Observable<BaseResult> addDeputyUnitInput(@Body RequestBody requestBody);
/**
* 刪除副單位快捷輸入
*/
@Headers({"Domain-Name: ricepon-purchase"})
@FormUrlEncoded
@POST("basicUnitType/delete" + RetrofitUrlManager.IDENTIFICATION_PATH_SIZE + 2)
Observable<BaseResult> deleteUnitKey(@Field("id") int id);
/**
* 查詢入庫流水
......
......@@ -19,8 +19,11 @@ import java.util.List;
*/
public class BasicUnitAdapter extends BaseQuickAdapter<BasicUnitBean, BaseViewHolder> {
private boolean showDelete = false;
public BasicUnitAdapter(@Nullable List<BasicUnitBean> data) {
super(R.layout.item_basic_unit, data);
addChildClickViewIds(R.id.iv_delete_basic_unit);
}
@Override
......@@ -31,5 +34,16 @@ public class BasicUnitAdapter extends BaseQuickAdapter<BasicUnitBean, BaseViewHo
} else {
viewHolder.setTextColorRes(R.id.tv_basic_unit, R.color.color_3c);
}
//沒有id的,就是系統自帶的默認的單位,不能刪除
if (item.getId() != null) {
viewHolder.setGone(R.id.iv_delete_basic_unit, !showDelete);
} else {
viewHolder.setGone(R.id.iv_delete_basic_unit, true);
}
}
public void toggleDelete() {
this.showDelete = !showDelete;
notifyDataSetChanged();
}
}
......@@ -14,6 +14,8 @@ import androidx.fragment.app.FragmentActivity;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.listener.OnItemChildClickListener;
import com.gingersoft.gsa.cloud.common.utils.other.TextUtil;
import com.gingersoft.gsa.cloud.ui.utils.AppDialog;
import com.gingersoft.supply_chain.R;
......@@ -144,6 +146,11 @@ public class FoodUnitPageFragment extends BaseSupplyChainFragment<FoodUnitPagePr
@Override
public void loadBasicUnitAdapter(List<BasicUnitBean> basicUnitBeans) {
basicUnitAdapter = new BasicUnitAdapter(basicUnitBeans);
//獲取到基礎單位之後,才在標題欄中添加刪除按鈕
topBar.addRightImageButton(R.drawable.ic_white_delete,R.id.btn_delete).setOnClickListener(v -> {
//刪除
basicUnitAdapter.toggleDelete();
});
rvBasicUnitList.setLayoutManager(new GridLayoutManager(mContext, 5));
rvBasicUnitList.setAdapter(basicUnitAdapter);
basicUnitAdapter.setOnItemClickListener((adapter, view, position) -> {
......@@ -174,6 +181,13 @@ public class FoodUnitPageFragment extends BaseSupplyChainFragment<FoodUnitPagePr
}
}
});
basicUnitAdapter.setOnItemChildClickListener((adapter, view, position) -> {
if(view.getId() == R.id.iv_delete_basic_unit){
//刪除單位
mPresenter.deleteUnitKey(basicUnitAdapter.getItem(position).getId(), position);
}
});
}
@Override
......@@ -227,4 +241,9 @@ public class FoodUnitPageFragment extends BaseSupplyChainFragment<FoodUnitPagePr
public void deleteDeputyUnit(int position) {
deputyUnitAdapter.removeAt(position);
}
@Override
public void deleteUnitKey(int position) {
basicUnitAdapter.removeAt(position);
}
}
......@@ -44,6 +44,7 @@
android:imeOptions="actionSearch"
android:hint="搜索供應商"
android:maxLines="1"
android:textCursorDrawable="@drawable/cursor_theme"
android:inputType="text"
android:textColor="@color/theme_333_color"
android:textColorHint="@color/hint_color"
......
<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/dp_3"
android:layout_marginRight="@dimen/dp_3"
android:layout_marginTop="@dimen/dp_3"
android:layout_marginBottom="@dimen/dp_3"
android:background="@color/white"
app:cardCornerRadius="@dimen/dp_8"
app:elevation="@dimen/dp_10">
android:layout_height="wrap_content">
<TextView
android:id="@+id/tv_basic_unit"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center"
android:paddingTop="@dimen/dp_7"
android:paddingBottom="@dimen/dp_7"
android:textColor="@color/color_3c"
android:textSize="@dimen/dp_14"
tools:text="個" />
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/dp_3"
android:layout_marginRight="@dimen/dp_3"
android:background="@color/white"
app:cardCornerRadius="@dimen/dp_8"
app:cardUseCompatPadding="true"
app:elevation="@dimen/dp_4">
<TextView
android:id="@+id/tv_basic_unit"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center"
android:ellipsize="end"
android:maxLines="1"
android:paddingTop="@dimen/dp_7"
android:paddingBottom="@dimen/dp_7"
android:textColor="@color/color_3c"
android:textSize="@dimen/dp_14"
tools:text="個" />
</androidx.cardview.widget.CardView>
</androidx.cardview.widget.CardView>
\ No newline at end of file
<ImageView
android:id="@+id/iv_delete_basic_unit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:elevation="@dimen/dp_5"
android:src="@drawable/ic_red_circular_delete" />
</FrameLayout>
......@@ -3,6 +3,12 @@ package com.gingersoft.gsa.cloud.common.constans;
public class DeliveryPickConstans {
public static final String ORDER_TYPE = "orderType";
/**
* 訂單類型:凍鏈
*/
public static final String COLD_CHAIN_TYPE = "8";
/**
* 2 線上外賣訂單,7 自取訂單
*/
public static final String DELIVERY_TYPE = "2,7";
}
......@@ -42,6 +42,8 @@ public class PrjBean {
private int id;
private int printerDeviceId;
private int status;//為2是帶*,需要切紙的
public static final int PRJ_CUTE = 2;
private String tableName;
private String orderNo;
private int orderTime;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment