Commit 63c11ab4 by Wyh

1、打印改為Rx 2、供應鏈供應商信息存入購物車中

parent 19f0450f
...@@ -366,24 +366,26 @@ public abstract class PrinterRoot<T extends PrintContent> implements PrintExecut ...@@ -366,24 +366,26 @@ public abstract class PrinterRoot<T extends PrintContent> implements PrintExecut
if (executor == null) { if (executor == null) {
executor = new PrintExecutor() executor = new PrintExecutor()
.setOnStateChangedListener(state -> { .setOnStateChangedListener(state -> {
// switch (state) { switch (state) {
// case PrintSocketHolder.STATE_1: case PrintSocketHolder.STATE_0:
// tip = "開始創建連接"; LoganManager.w_printer(TAG, "打印機狀態 --> 生成页面数据");
// break; break;
// case PrintSocketHolder.STATE_2: case PrintSocketHolder.STATE_1:
// tip = "創建連接成功,開始發送數據"; LoganManager.w_printer(TAG, "打印機狀態 --> 创建Socket连接");
// break; break;
// case PrintSocketHolder.STATE_3: case PrintSocketHolder.STATE_2:
// tip = "開始寫入數據"; LoganManager.w_printer(TAG, "打印機狀態 --> 获取输出流");
// break; break;
// case PrintSocketHolder.STATE_4://关闭输出流 case PrintSocketHolder.STATE_3:
// tip = "關閉中"; LoganManager.w_printer(TAG, "打印機狀態 --> 写入页面数据");
// killMyself(); break;
// break; case PrintSocketHolder.STATE_4:
// default: LoganManager.w_printer(TAG, "打印機狀態 --> 关闭输出流");
// break; break;
// } default:
LogUtil.e("eee", "打印狀態:" + state); break;
}
LogUtil.e("eee", "executePrint----打印狀態:" + state);
if (state == PrintSocketHolder.STATE_4) { if (state == PrintSocketHolder.STATE_4) {
printSuccess(); printSuccess();
} }
......
...@@ -58,6 +58,16 @@ public class SupplierInfoBean implements Serializable { ...@@ -58,6 +58,16 @@ public class SupplierInfoBean implements Serializable {
public SupplierInfoBean() { public SupplierInfoBean() {
} }
public static SupplierInfoBean generateSupplierByFood(PurchaseFoodBean purchaseFoodBean) {
SupplierInfoBean supplierInfoBean = new SupplierInfoBean();
supplierInfoBean.setShipping(purchaseFoodBean.getShipping());
supplierInfoBean.setSupplierName(purchaseFoodBean.getSupplierName());
supplierInfoBean.setMinimumAmount(purchaseFoodBean.getMinimumAmount());
supplierInfoBean.setAddress(purchaseFoodBean.getAddress());
supplierInfoBean.setId(purchaseFoodBean.getSupplierId());
return supplierInfoBean;
}
@Data @Data
public static class SupplierContacts implements Serializable { public static class SupplierContacts implements Serializable {
private static final long serialVersionUID = -4586838211196656718L; private static final long serialVersionUID = -4586838211196656718L;
...@@ -89,6 +99,7 @@ public class SupplierInfoBean implements Serializable { ...@@ -89,6 +99,7 @@ public class SupplierInfoBean implements Serializable {
public final static int Kakao_Talk = 5; public final static int Kakao_Talk = 5;
public final static int SMS = 6; public final static int SMS = 6;
public final static int Efax = 7; public final static int Efax = 7;
public static String getContractTitleByType(int type) { public static String getContractTitleByType(int type) {
switch (type) { switch (type) {
case Email: case Email:
......
...@@ -2,12 +2,16 @@ package com.gingersoft.supply_chain.mvp.content; ...@@ -2,12 +2,16 @@ package com.gingersoft.supply_chain.mvp.content;
import com.gingersoft.supply_chain.mvp.bean.OrderCategoryBean; import com.gingersoft.supply_chain.mvp.bean.OrderCategoryBean;
import com.gingersoft.supply_chain.mvp.bean.PurchaseFoodBean; import com.gingersoft.supply_chain.mvp.bean.PurchaseFoodBean;
import com.gingersoft.supply_chain.mvp.bean.SupplierInfoBean;
import com.xuexiang.rxutil2.rxjava.RxJavaUtils; import com.xuexiang.rxutil2.rxjava.RxJavaUtils;
import com.xuexiang.rxutil2.rxjava.task.RxIOTask; import com.xuexiang.rxutil2.rxjava.task.RxIOTask;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**
* @author 宇航. * @author 宇航.
...@@ -22,6 +26,11 @@ public class SupplyShoppingCart { ...@@ -22,6 +26,11 @@ public class SupplyShoppingCart {
* value為食品信息 * value為食品信息
*/ */
private static List<PurchaseFoodBean> cartFoods; private static List<PurchaseFoodBean> cartFoods;
/**
* 供應商信息map
* 有時候PurchaseFoodBean中的供應商信息不可靠,比如:用戶將食品添加到購物車中,然後又去供應商列表修改供應商信息,這時候需要更新供應商信息
*/
private static Map<Integer, SupplierInfoBean> supplierInfoBeanMap;
private static SupplyShoppingCart shoppingCart; private static SupplyShoppingCart shoppingCart;
...@@ -39,12 +48,48 @@ public class SupplyShoppingCart { ...@@ -39,12 +48,48 @@ public class SupplyShoppingCart {
return cartFoods; return cartFoods;
} }
public Map<Integer, SupplierInfoBean> getSupplierInfoBeanMap(){
if(supplierInfoBeanMap == null){
supplierInfoBeanMap = new HashMap<>();
}
return supplierInfoBeanMap;
}
public SupplierInfoBean getSupplierById(int supplierId) {
return getSupplierInfoBeanMap().get(supplierId);
}
public void updateSupplier(SupplierInfoBean supplierInfoBean){
getSupplierInfoBeanMap().put(supplierInfoBean.getId(), supplierInfoBean);
}
public void addAllFood(Collection<PurchaseFoodBean> purchaseFoodBeans) {
for (PurchaseFoodBean purchaseFoodBean : purchaseFoodBeans) {
addFood(purchaseFoodBean);
}
}
/**
* 添加食品時記錄供應商信息,對供應商進行修改時,需要修改食材的供應商信息
*
* @param purchaseFoodBean
*/
public void addFood(PurchaseFoodBean purchaseFoodBean) {
addFood(getCartFoods().size(), purchaseFoodBean);
}
public void addFood(int index, PurchaseFoodBean purchaseFoodBean) {
getCartFoods().add(index, purchaseFoodBean);
if (getSupplierInfoBeanMap().get(purchaseFoodBean.getSupplierId()) == null) {
getSupplierInfoBeanMap().put(purchaseFoodBean.getSupplierId(), SupplierInfoBean.generateSupplierByFood(purchaseFoodBean));
}
}
public void clear() { public void clear() {
if (cartFoods == null) { if (cartFoods == null) {
return; return;
} }
cartFoods.clear(); cartFoods.clear();
cartFoods = null;
} }
...@@ -149,8 +194,4 @@ public class SupplyShoppingCart { ...@@ -149,8 +194,4 @@ public class SupplyShoppingCart {
} }
} }
public void setCartFoods(List<PurchaseFoodBean> cartFoods) {
SupplyShoppingCart.cartFoods = cartFoods;
}
} }
...@@ -203,7 +203,7 @@ public class FoodIngredientsPresenter extends BasePresenter<FoodIngredientsContr ...@@ -203,7 +203,7 @@ public class FoodIngredientsPresenter extends BasePresenter<FoodIngredientsContr
for (PurchaseFoodBean cartFood : SupplyShoppingCart.getInstance().getCartFoods()) { for (PurchaseFoodBean cartFood : SupplyShoppingCart.getInstance().getCartFoods()) {
//將購物車中的食品數量同步到當前數據中 //將購物車中的食品數量同步到當前數據中
for (PurchaseFoodBean purchaseFoodListVO : purchaseFoodListVOS) { for (PurchaseFoodBean purchaseFoodListVO : purchaseFoodListVOS) {
if (cartFood.getId() == purchaseFoodListVO.getId()) { if (cartFood.getId().equals(purchaseFoodListVO.getId())) {
//購物車裡的食品id和當前的食品id一樣,則將購物車中的食品數量賦值給當前食品 //購物車裡的食品id和當前的食品id一樣,則將購物車中的食品數量賦值給當前食品
purchaseFoodListVO.setFoodQuantity(cartFood.getFoodQuantity()); purchaseFoodListVO.setFoodQuantity(cartFood.getFoodQuantity());
totalCount += cartFood.getFoodQuantity(); totalCount += cartFood.getFoodQuantity();
...@@ -312,12 +312,10 @@ public class FoodIngredientsPresenter extends BasePresenter<FoodIngredientsContr ...@@ -312,12 +312,10 @@ public class FoodIngredientsPresenter extends BasePresenter<FoodIngredientsContr
integerMap.remove(purchaseFoodBean); integerMap.remove(purchaseFoodBean);
} }
} }
//把購物車的食品取出來 //把購物車的食品清空
List<PurchaseFoodBean> cartFoods = SupplyShoppingCart.getInstance().getCartFoods(); SupplyShoppingCart.getInstance().clear();
//清空
cartFoods.clear();
//將本次選擇的添加進去 //將本次選擇的添加進去
cartFoods.addAll(integerMap.values()); SupplyShoppingCart.getInstance().addAllFood(integerMap.values());
} }
/** /**
...@@ -633,7 +631,7 @@ public class FoodIngredientsPresenter extends BasePresenter<FoodIngredientsContr ...@@ -633,7 +631,7 @@ public class FoodIngredientsPresenter extends BasePresenter<FoodIngredientsContr
if (purchaseFoodBean.getFoodQuantity() > 0) { if (purchaseFoodBean.getFoodQuantity() > 0) {
boolean hasThisFood = false; boolean hasThisFood = false;
for (PurchaseFoodBean cartFood : SupplyShoppingCart.getInstance().getCartFoods()) { for (PurchaseFoodBean cartFood : SupplyShoppingCart.getInstance().getCartFoods()) {
if (purchaseFoodBean.getId() == cartFood.getId()) { if (purchaseFoodBean.getId().equals(cartFood.getId())) {
hasThisFood = true; hasThisFood = true;
purchaseFoodBean.setFoodQuantity(cartFood.getFoodQuantity()); purchaseFoodBean.setFoodQuantity(cartFood.getFoodQuantity());
if (integerMap != null) { if (integerMap != null) {
......
...@@ -27,6 +27,7 @@ import com.gingersoft.supply_chain.mvp.bean.OrderCategoryBean; ...@@ -27,6 +27,7 @@ import com.gingersoft.supply_chain.mvp.bean.OrderCategoryBean;
import com.gingersoft.supply_chain.mvp.bean.PurchaseFoodBean; import com.gingersoft.supply_chain.mvp.bean.PurchaseFoodBean;
import com.gingersoft.supply_chain.mvp.bean.SupplierInfoBean; import com.gingersoft.supply_chain.mvp.bean.SupplierInfoBean;
import com.gingersoft.supply_chain.mvp.content.Constant; import com.gingersoft.supply_chain.mvp.content.Constant;
import com.gingersoft.supply_chain.mvp.content.SupplyShoppingCart;
import com.gingersoft.supply_chain.mvp.contract.NewFoodIngredientsContract; import com.gingersoft.supply_chain.mvp.contract.NewFoodIngredientsContract;
import com.gingersoft.supply_chain.mvp.ui.fragment.category.CategorySelectFragment; import com.gingersoft.supply_chain.mvp.ui.fragment.category.CategorySelectFragment;
import com.gingersoft.supply_chain.mvp.ui.fragment.food.FoodUnitPageFragment; import com.gingersoft.supply_chain.mvp.ui.fragment.food.FoodUnitPageFragment;
...@@ -37,6 +38,8 @@ import com.jess.arms.http.imageloader.ImageLoader; ...@@ -37,6 +38,8 @@ import com.jess.arms.http.imageloader.ImageLoader;
import com.jess.arms.integration.AppManager; import com.jess.arms.integration.AppManager;
import com.jess.arms.mvp.BasePresenter; import com.jess.arms.mvp.BasePresenter;
import com.jess.arms.utils.RxLifecycleUtils; import com.jess.arms.utils.RxLifecycleUtils;
import com.xuexiang.rxutil2.rxjava.RxJavaUtils;
import com.xuexiang.rxutil2.rxjava.task.RxIOTask;
import java.io.File; import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
...@@ -413,6 +416,25 @@ public class NewFoodIngredientsPresenter extends BasePresenter<NewFoodIngredient ...@@ -413,6 +416,25 @@ public class NewFoodIngredientsPresenter extends BasePresenter<NewFoodIngredient
if (baseResult.isSuccess()) { if (baseResult.isSuccess()) {
mRootView.showMessage(Constant.UPDATE_SUCCESS); mRootView.showMessage(Constant.UPDATE_SUCCESS);
mRootView.updateFoodInfoSuccess(purchaseFoodBean.getSupplierName(), purchaseFoodBean.getFoodCategoryName()); mRootView.updateFoodInfoSuccess(purchaseFoodBean.getSupplierName(), purchaseFoodBean.getFoodCategoryName());
RxJavaUtils.doInIOThread(new RxIOTask<Object>(1) {
@Override
public Void doInIOThread(Object o) {
//修改完食品後,需要查看購物車中的這個食品,也要進行修改
List<PurchaseFoodBean> cartFoods = SupplyShoppingCart.getInstance().getCartFoods();
for (int i = 0; i < cartFoods.size(); i++) {
PurchaseFoodBean cartFood = cartFoods.get(i);
if (purchaseFoodBean.getId().equals(cartFood.getId())) {
//找到這個食品
int foodNum = cartFood.getFoodQuantity();
cartFoods.remove(cartFood);
purchaseFoodBean.setFoodQuantity(foodNum);
SupplyShoppingCart.getInstance().addFood(i, purchaseFoodBean);
return null;
}
}
return null;
}
});
} else if (TextUtil.isNotEmptyOrNullOrUndefined(baseResult.getErrMsg())) { } else if (TextUtil.isNotEmptyOrNullOrUndefined(baseResult.getErrMsg())) {
mRootView.showMessage(baseResult.getErrMsg()); mRootView.showMessage(baseResult.getErrMsg());
} else { } else {
......
...@@ -277,6 +277,7 @@ public class NewSupplierPresenter extends BasePresenter<NewSupplierContract.Mode ...@@ -277,6 +277,7 @@ public class NewSupplierPresenter extends BasePresenter<NewSupplierContract.Mode
supplierInfoBean.setSupplierContacts(null); supplierInfoBean.setSupplierContacts(null);
//修改供應商聯繫方式單獨在這個接口 //修改供應商聯繫方式單獨在這個接口
updateSupplierContact(); updateSupplierContact();
//如果供應商名稱沒有修改,就不傳給後台
if (supplierName.equals(supplierInfoBean.getSupplierName())) { if (supplierName.equals(supplierInfoBean.getSupplierName())) {
supplierInfoBean.setSupplierName(null); supplierInfoBean.setSupplierName(null);
} }
...@@ -295,8 +296,10 @@ public class NewSupplierPresenter extends BasePresenter<NewSupplierContract.Mode ...@@ -295,8 +296,10 @@ public class NewSupplierPresenter extends BasePresenter<NewSupplierContract.Mode
public void onNext(@NonNull BaseResult info) { public void onNext(@NonNull BaseResult info) {
if (info != null) { if (info != null) {
if (info.isSuccess()) { if (info.isSuccess()) {
//供應商信息修改後,將購物車食品信息刪除掉,不然食品信息中的採購金額和地址不對 //供應商信息修改後,將購物車中的供應商信息修改
SupplyShoppingCart.getInstance().removeFoodsBySupplier(supplierBean.getId()); supplierInfoBean.setSupplierName(supplierName);
SupplyShoppingCart.getInstance().updateSupplier(supplierInfoBean);
// SupplyShoppingCart.getInstance().removeFoodsBySupplier(supplierBean.getId());
mRootView.saveSuccess(); mRootView.saveSuccess();
} else if (TextUtil.isNotEmptyOrNullOrUndefined(info.getErrMsg())) { } else if (TextUtil.isNotEmptyOrNullOrUndefined(info.getErrMsg())) {
mRootView.showMessage(info.getErrMsg()); mRootView.showMessage(info.getErrMsg());
......
...@@ -301,7 +301,7 @@ public class OrderDetailsPresenter extends BasePresenter<OrderDetailsContract.Mo ...@@ -301,7 +301,7 @@ public class OrderDetailsPresenter extends BasePresenter<OrderDetailsContract.Mo
@Override @Override
public void onNext(BaseResult baseResult) { public void onNext(BaseResult baseResult) {
if (baseResult.isSuccess()) { if (baseResult.isSuccess()) {
List<PurchaseFoodBean> purchaseFoodBeans = GsonUtils.GsonToList(baseResult.getData(), PurchaseFoodBean.class); List<PurchaseFoodBean> purchaseFoodBeans = GsonUtils.jsonToList(baseResult.getData(), PurchaseFoodBean.class);
for (PurchaseFoodBean purchaseFoodBean : purchaseFoodBeans) { for (PurchaseFoodBean purchaseFoodBean : purchaseFoodBeans) {
for (PurchaseOrderDetailsBean.PurchaseOrderDetailsInfoVosBean item : data) { for (PurchaseOrderDetailsBean.PurchaseOrderDetailsInfoVosBean item : data) {
if (purchaseFoodBean.getId() == item.getPurchaseFoodId()) { if (purchaseFoodBean.getId() == item.getPurchaseFoodId()) {
...@@ -311,7 +311,7 @@ public class OrderDetailsPresenter extends BasePresenter<OrderDetailsContract.Mo ...@@ -311,7 +311,7 @@ public class OrderDetailsPresenter extends BasePresenter<OrderDetailsContract.Mo
} }
} }
SupplyShoppingCart.getInstance().clear(); SupplyShoppingCart.getInstance().clear();
SupplyShoppingCart.getInstance().getCartFoods().addAll(purchaseFoodBeans); SupplyShoppingCart.getInstance().addAllFood(purchaseFoodBeans);
mRootView.buyAgain(); mRootView.buyAgain();
} else { } else {
mRootView.showMessage(GET_INFO_ERROR); mRootView.showMessage(GET_INFO_ERROR);
......
...@@ -14,6 +14,7 @@ import com.gingersoft.supply_chain.mvp.bean.ConfirmOrderBean; ...@@ -14,6 +14,7 @@ import com.gingersoft.supply_chain.mvp.bean.ConfirmOrderBean;
import com.gingersoft.supply_chain.mvp.bean.NewPurchaseOrderBean; import com.gingersoft.supply_chain.mvp.bean.NewPurchaseOrderBean;
import com.gingersoft.supply_chain.mvp.bean.PurchaseFoodBean; import com.gingersoft.supply_chain.mvp.bean.PurchaseFoodBean;
import com.gingersoft.supply_chain.mvp.bean.ShoppingCartBean; import com.gingersoft.supply_chain.mvp.bean.ShoppingCartBean;
import com.gingersoft.supply_chain.mvp.bean.SupplierInfoBean;
import com.gingersoft.supply_chain.mvp.content.SupplyShoppingCart; import com.gingersoft.supply_chain.mvp.content.SupplyShoppingCart;
import com.gingersoft.supply_chain.mvp.contract.ShoppingCatContract; import com.gingersoft.supply_chain.mvp.contract.ShoppingCatContract;
import com.jess.arms.di.scope.FragmentScope; import com.jess.arms.di.scope.FragmentScope;
...@@ -99,12 +100,6 @@ public class ShoppingCatPresenter extends BasePresenter<ShoppingCatContract.Mode ...@@ -99,12 +100,6 @@ public class ShoppingCatPresenter extends BasePresenter<ShoppingCatContract.Mode
if (foods != null && foods.size() > 0) { if (foods != null && foods.size() > 0) {
//將供應商信息從食材中取出 //將供應商信息從食材中取出
PurchaseFoodBean food = foods.get(0); PurchaseFoodBean food = foods.get(0);
shoppingCartBean.setAddress(food.getAddress());
shoppingCartBean.setMinimumAmount(food.getMinimumAmount());
if (entry.getKey() != null) {
shoppingCartBean.setSupplierId(entry.getKey());
}
shoppingCartBean.setSupplierName(food.getSupplierName());
//統計當前供應商所選中食品的總金額 //統計當前供應商所選中食品的總金額
double supplierTotalAmount = 0; double supplierTotalAmount = 0;
//統計當前供應商選中食材的種類 //統計當前供應商選中食材的種類
...@@ -125,8 +120,28 @@ public class ShoppingCatPresenter extends BasePresenter<ShoppingCatContract.Mode ...@@ -125,8 +120,28 @@ public class ShoppingCatPresenter extends BasePresenter<ShoppingCatContract.Mode
if (MoneyUtil.compareTo(shoppingCartBean.getMinimumAmount(), supplierTotalAmount) == 1) { if (MoneyUtil.compareTo(shoppingCartBean.getMinimumAmount(), supplierTotalAmount) == 1) {
createBtnCheckable = false; createBtnCheckable = false;
} }
//以購物車中的供應商信息為准,如果購物車拿出來的供應商信息為空,就用食材本身的供應商信息
SupplierInfoBean supplierInfoBean = null;
if (food.getSupplierId() != null) {
supplierInfoBean = SupplyShoppingCart.getInstance().getSupplierById(food.getSupplierId());
}
if (supplierInfoBean != null) {
shoppingCartBean.setAddress(supplierInfoBean.getAddress());
shoppingCartBean.setMinimumAmount(supplierInfoBean.getMinimumAmount());
shoppingCartBean.setSupplierId(supplierInfoBean.getId());
shoppingCartBean.setSupplierName(supplierInfoBean.getSupplierName());
shoppingCartBean.setShipping(supplierInfoBean.getShipping());
} else {
shoppingCartBean.setAddress(food.getAddress());
shoppingCartBean.setMinimumAmount(food.getMinimumAmount());
if (entry.getKey() != null) {
shoppingCartBean.setSupplierId(entry.getKey());
}
shoppingCartBean.setSupplierName(food.getSupplierName());
shoppingCartBean.setShipping(shipping);
}
//運費 //運費
shoppingCartBean.setShipping(shipping); // shoppingCartBean.setShipping(shipping);
shoppingCartBean.setInitialShippingTime(TimeUtils.getNextDay(1)); shoppingCartBean.setInitialShippingTime(TimeUtils.getNextDay(1));
shoppingCartBean.setSelectFoodAmount(supplierTotalAmount); shoppingCartBean.setSelectFoodAmount(supplierTotalAmount);
shoppingCartBean.setSelectSpeciesNum(supplierTotalSpecies); shoppingCartBean.setSelectSpeciesNum(supplierTotalSpecies);
......
...@@ -125,7 +125,7 @@ public class WarehouseDetailsPresenter extends BasePresenter<WarehouseDetailsCon ...@@ -125,7 +125,7 @@ public class WarehouseDetailsPresenter extends BasePresenter<WarehouseDetailsCon
@Override @Override
public void onNext(BaseResult baseResult) { public void onNext(BaseResult baseResult) {
if (baseResult != null && baseResult.isSuccess()) { if (baseResult != null && baseResult.isSuccess()) {
List<ConsumeWareHousingBean> consumeWareHousingBeans = GsonUtils.GsonToList(baseResult.getData(), ConsumeWareHousingBean.class); List<ConsumeWareHousingBean> consumeWareHousingBeans = GsonUtils.jsonToList(baseResult.getData(), ConsumeWareHousingBean.class);
mRootView.loadAdapter(WarehouseDetailsBean.getWarehousingByConsumes(consumeWareHousingBeans)); mRootView.loadAdapter(WarehouseDetailsBean.getWarehousingByConsumes(consumeWareHousingBeans));
} else if (baseResult != null && TextUtil.isNotEmptyOrNullOrUndefined(baseResult.getErrMsg())) { } else if (baseResult != null && TextUtil.isNotEmptyOrNullOrUndefined(baseResult.getErrMsg())) {
mRootView.showMessage(baseResult.getErrMsg()); mRootView.showMessage(baseResult.getErrMsg());
...@@ -151,7 +151,7 @@ public class WarehouseDetailsPresenter extends BasePresenter<WarehouseDetailsCon ...@@ -151,7 +151,7 @@ public class WarehouseDetailsPresenter extends BasePresenter<WarehouseDetailsCon
@Override @Override
public void onNext(BaseResult baseResult) { public void onNext(BaseResult baseResult) {
if (baseResult != null && baseResult.isSuccess()) { if (baseResult != null && baseResult.isSuccess()) {
List<ConsumeReasonBean> consumeReasonBeans = GsonUtils.GsonToList(baseResult.getData(), ConsumeReasonBean.class); List<ConsumeReasonBean> consumeReasonBeans = GsonUtils.jsonToList(baseResult.getData(), ConsumeReasonBean.class);
mRootView.loadConsumeReason(consumeReasonBeans); mRootView.loadConsumeReason(consumeReasonBeans);
} else if (baseResult != null && TextUtil.isNotEmptyOrNullOrUndefined(baseResult.getErrMsg())) { } else if (baseResult != null && TextUtil.isNotEmptyOrNullOrUndefined(baseResult.getErrMsg())) {
mRootView.showMessage(baseResult.getErrMsg()); mRootView.showMessage(baseResult.getErrMsg());
......
...@@ -158,6 +158,7 @@ public class FoodUnitPageFragment extends BaseSupplyChainFragment<FoodUnitPagePr ...@@ -158,6 +158,7 @@ public class FoodUnitPageFragment extends BaseSupplyChainFragment<FoodUnitPagePr
if (position == basicUnitAdapter.getItemCount() - 1) { if (position == basicUnitAdapter.getItemCount() - 1) {
//新增 //新增
EditTextPopup popup = new EditTextPopup(requireContext(), new InputFilter[]{InputFilterUtils.getLengthFilter(mContext, 5), InputFilterUtils.getEnAndChInputFilter(mContext)}); EditTextPopup popup = new EditTextPopup(requireContext(), new InputFilter[]{InputFilterUtils.getLengthFilter(mContext, 5), InputFilterUtils.getEnAndChInputFilter(mContext)});
popup.setTitleContent("新增單位", "單位名稱:", "請輸入單位名稱");
popup.setListener(text -> { popup.setListener(text -> {
if (TextUtil.isNotEmptyOrNullOrUndefined(text)) { if (TextUtil.isNotEmptyOrNullOrUndefined(text)) {
mPresenter.addBasicUnit(text, basicUnitAdapter.getData()); mPresenter.addBasicUnit(text, basicUnitAdapter.getData());
......
...@@ -3,7 +3,6 @@ ...@@ -3,7 +3,6 @@
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:background="@color/white"
android:layout_height="wrap_content"> android:layout_height="wrap_content">
<androidx.cardview.widget.CardView <androidx.cardview.widget.CardView
...@@ -11,6 +10,7 @@ ...@@ -11,6 +10,7 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/dp_3" android:layout_marginLeft="@dimen/dp_3"
android:layout_marginRight="@dimen/dp_3" android:layout_marginRight="@dimen/dp_3"
android:background="@color/white"
app:cardCornerRadius="@dimen/dp_4" app:cardCornerRadius="@dimen/dp_4"
app:cardUseCompatPadding="true" app:cardUseCompatPadding="true"
app:elevation="@dimen/dp_4"> app:elevation="@dimen/dp_4">
......
...@@ -31,10 +31,10 @@ public class RestaurantInfoManager { ...@@ -31,10 +31,10 @@ public class RestaurantInfoManager {
if (restaurantInfo == null) { if (restaurantInfo == null) {
restaurantInfo = new RestaurantInfo(); restaurantInfo = new RestaurantInfo();
} }
brandInfo.setBrandId((Integer) SPUtils.get(UserConstans.brandId, 0)); brandInfo.setBrandId((Integer) SPUtils.get(UserConstans.brandId, 1));
brandInfo.setBrandName((String) SPUtils.get(UserConstans.brandName, "")); brandInfo.setBrandName((String) SPUtils.get(UserConstans.brandName, ""));
restaurantInfo.setGsPosShopId((String) SPUtils.get(UserConstans.gsPosShopId, "-1")); restaurantInfo.setGsPosShopId((String) SPUtils.get(UserConstans.gsPosShopId, "-1"));
restaurantInfo.setRestaurantId((Integer) SPUtils.get(UserConstans.restaurantId, 0)); restaurantInfo.setRestaurantId((Integer) SPUtils.get(UserConstans.restaurantId, 26));
restaurantInfo.setRestaurantName((String) SPUtils.get(UserConstans.restaurantName, "")); restaurantInfo.setRestaurantName((String) SPUtils.get(UserConstans.restaurantName, ""));
} }
......
...@@ -90,14 +90,14 @@ public class GsonUtils { ...@@ -90,14 +90,14 @@ public class GsonUtils {
* @param <T> * @param <T>
* @return * @return
*/ */
public static <T> List GsonToList(Object object, Class<T> cls) { // public static <T> List GsonToList(Object object, Class<T> cls) {
List<T> mList = new ArrayList<>(); // List<T> mList = new ArrayList<>();
JsonArray array = new JsonParser().parse(GsonString(object)).getAsJsonArray(); // JsonArray array = new JsonParser().parse(GsonString(object)).getAsJsonArray();
for (final JsonElement elem : array) { // for (final JsonElement elem : array) {
mList.add(gson.fromJson(elem, cls)); // mList.add(gson.fromJson(elem, cls));
} // }
return mList; // return mList;
} // }
// 有問題,轉換出來的類型不對 // 有問題,轉換出來的類型不對
......
...@@ -6,6 +6,7 @@ import com.gingersoft.gsa.cloud.common.logan.LoganManager; ...@@ -6,6 +6,7 @@ import com.gingersoft.gsa.cloud.common.logan.LoganManager;
import com.gingersoft.gsa.cloud.common.utils.log.LogUtil; import com.gingersoft.gsa.cloud.common.utils.log.LogUtil;
import com.gingersoft.gsa.cloud.print.impl.OnPrjPrintResultListener; import com.gingersoft.gsa.cloud.print.impl.OnPrjPrintResultListener;
import com.xuexiang.rxutil2.rxjava.RxJavaUtils; import com.xuexiang.rxutil2.rxjava.RxJavaUtils;
import com.xuexiang.rxutil2.rxjava.task.RxAsyncTask;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
...@@ -57,10 +58,12 @@ public class PrintExecutor { ...@@ -57,10 +58,12 @@ public class PrintExecutor {
* 异步执行打印请求 * 异步执行打印请求
*/ */
public void doPrinterRequestAsync(PrintDataMaker maker) { public void doPrinterRequestAsync(PrintDataMaker maker) {
holder.setOnStateChangedListener(listener);
if (printDataMakers.size() <= 0) { if (printDataMakers.size() <= 0) {
LogUtil.i("eee", "prj熱敏打印執行第一個任務"); LogUtil.i("eee", "prj熱敏打印執行第一個任務");
printDataMakers.add(maker); printDataMakers.add(maker);
new PrintTask().execute(maker); // new PrintTask().execute(maker);
executePrint(maker);
} else { } else {
//如果隊列裡有任務在執行,只添加進去,等待執行完成之後,再來執行這個 //如果隊列裡有任務在執行,只添加進去,等待執行完成之後,再來執行這個
LogUtil.i("eee", "prj熱敏打印添加隊列,前面還有" + printDataMakers.size() + "個任務"); LogUtil.i("eee", "prj熱敏打印添加隊列,前面還有" + printDataMakers.size() + "個任務");
...@@ -69,6 +72,39 @@ public class PrintExecutor { ...@@ -69,6 +72,39 @@ public class PrintExecutor {
} }
} }
private void executePrint(PrintDataMaker maker) {
RxJavaUtils.executeAsyncTask(new RxAsyncTask<PrintDataMaker, Integer>(maker) {
@Override
public Integer doInIOThread(PrintDataMaker o) {
LogUtil.i("eee", "executePrint----doInIOThread");
return doRequest(o);
}
@Override
public void doInUIThread(Integer i) {
LogUtil.i("eee", "executePrint----doInUIThread" + i);
if (resetPrintDis != null) {
resetPrintDis.dispose();
}
//移除掉當前任務
if (printDataMakers.size() > 0) {
printDataMakers.remove(0);
}
//執行下一個任務
if (printDataMakers.size() > 0) {
// new PrintTask().execute(printDataMakers.get(0));
executePrint(printDataMakers.get(0));
startReset();
}
LogUtil.d("eee", "executePrint----doInUIThread熱敏打印完成後,任務數量" + printDataMakers.size());
//返回結果
if (i != null) {
onResult(i);
}
}
});
}
private void startReset() { private void startReset() {
if (resetPrintDis != null) { if (resetPrintDis != null) {
resetPrintDis.dispose(); resetPrintDis.dispose();
...@@ -77,7 +113,8 @@ public class PrintExecutor { ...@@ -77,7 +113,8 @@ public class PrintExecutor {
//如果三十秒之後,任務還沒在打印完成方法中取消,可能打印程序卡住了,在這裡執行下一個任務 //如果三十秒之後,任務還沒在打印完成方法中取消,可能打印程序卡住了,在這裡執行下一個任務
LogUtil.e("eee", "prj熱敏打印等待時間超過三十秒,自動重新打印"); LogUtil.e("eee", "prj熱敏打印等待時間超過三十秒,自動重新打印");
if (printDataMakers.size() > 0) { if (printDataMakers.size() > 0) {
new PrintTask().execute(printDataMakers.get(0)); // new PrintTask().execute(printDataMakers.get(0));
executePrint(printDataMakers.get(0));
} }
}); });
} }
...@@ -112,25 +149,25 @@ public class PrintExecutor { ...@@ -112,25 +149,25 @@ public class PrintExecutor {
@Override @Override
protected void onPreExecute() { protected void onPreExecute() {
super.onPreExecute(); super.onPreExecute();
LogUtil.i("eee", "prj熱敏任務onPreExecute"); LogUtil.i("eee", "prjService熱敏任務onPreExecute");
holder.setOnStateChangedListener(this); holder.setOnStateChangedListener(this);
} }
@Override @Override
protected Integer doInBackground(PrintDataMaker... makers) { protected Integer doInBackground(PrintDataMaker... makers) {
LogUtil.i("eee", "prj熱敏任務開始"); LogUtil.i("eee", "prjService熱敏任務開始");
holder.closeSocket(); holder.closeSocket();
if (makers == null || makers.length < 1) { if (makers == null || makers.length < 1) {
return PrintSocketHolder.ERROR_0; return PrintSocketHolder.ERROR_0;
} }
LogUtil.e("eee", "prj熱敏任務開始" + makers[0].getPrjIds()); LogUtil.e("eee", "prjService熱敏任務開始,prjID為" + makers[0].getPrjIds());
return doRequest(makers[0]); return doRequest(makers[0]);
} }
@Override @Override
protected void onProgressUpdate(Integer... values) { protected void onProgressUpdate(Integer... values) {
super.onProgressUpdate(values); super.onProgressUpdate(values);
LogUtil.i("eee", "prj熱敏任務onProgressUpdate" + values); LogUtil.i("eee", "prjService熱敏任務onProgressUpdate" + values.toString());
if (values == null || values.length < 1) { if (values == null || values.length < 1) {
return; return;
} }
...@@ -142,7 +179,7 @@ public class PrintExecutor { ...@@ -142,7 +179,7 @@ public class PrintExecutor {
@Override @Override
protected void onPostExecute(Integer integer) { protected void onPostExecute(Integer integer) {
super.onPostExecute(integer); super.onPostExecute(integer);
LogUtil.i("eee", "prj熱敏任務onPostExecute" + integer); LogUtil.i("eee", "prjService熱敏任務onPostExecute" + integer);
if (resetPrintDis != null) { if (resetPrintDis != null) {
resetPrintDis.dispose(); resetPrintDis.dispose();
} }
...@@ -155,30 +192,13 @@ public class PrintExecutor { ...@@ -155,30 +192,13 @@ public class PrintExecutor {
new PrintTask().execute(printDataMakers.get(0)); new PrintTask().execute(printDataMakers.get(0));
startReset(); startReset();
} }
LogUtil.d("eee", "prj熱敏打印完成後,任務數量" + printDataMakers.size()); LogUtil.d("eee", "prjService熱敏打印完成後,任務數量" + printDataMakers.size());
//返回結果 //返回結果
if (integer != null) { if (integer != null) {
onResult(integer); onResult(integer);
} }
} }
/**
* 打印结果
*
* @param errorCode 错误代码
*/
private void onResult(int errorCode) {
try {
if (mListener != null) {
mListener.onResult(errorCode);
}
if (onPrjPrintResultListener != null) {
onPrjPrintResultListener.onResult(errorCode, prjIds);
}
} catch (Exception e) {
e.printStackTrace();
}
}
@Override @Override
public void onStateChanged(int state) { public void onStateChanged(int state) {
...@@ -206,6 +226,24 @@ public class PrintExecutor { ...@@ -206,6 +226,24 @@ public class PrintExecutor {
} }
/** /**
* 打印结果
*
* @param errorCode 错误代码
*/
private void onResult(int errorCode) {
try {
if (mListener != null) {
mListener.onResult(errorCode);
}
if (onPrjPrintResultListener != null) {
onPrjPrintResultListener.onResult(errorCode, prjIds);
}
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* 设置状态监听 * 设置状态监听
* *
* @param listener 监听 * @param listener 监听
......
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