diff --git a/app/src/main/java/com/bonus/canteen/fragment/EnterFragment/InspectionWarehousingFragment.java b/app/src/main/java/com/bonus/canteen/fragment/EnterFragment/InspectionWarehousingFragment.java index d01822d..87d6f24 100644 --- a/app/src/main/java/com/bonus/canteen/fragment/EnterFragment/InspectionWarehousingFragment.java +++ b/app/src/main/java/com/bonus/canteen/fragment/EnterFragment/InspectionWarehousingFragment.java @@ -19,6 +19,7 @@ package com.bonus.canteen.fragment.EnterFragment; import android.Manifest; import android.annotation.SuppressLint; +import android.app.AlertDialog; import android.content.Context; import android.content.Intent; import android.content.pm.PackageManager; @@ -67,6 +68,7 @@ import androidx.viewpager.widget.ViewPager; import com.alibaba.fastjson2.JSON; import com.alibaba.fastjson2.JSONObject; import com.bonus.canteen.activity.LoginActivity; +import com.bonus.canteen.activity.MainActivity; import com.bonus.canteen.constants.AppConstants; import com.bonus.canteen.core.BaseFragment; import com.bonus.canteen.db.AppDatabase; @@ -168,6 +170,7 @@ public class InspectionWarehousingFragment extends BaseFragment userList = new ArrayList<>(); List warehouseList = new ArrayList<>(); String relateOrderGoodsId; + boolean isUpload = false; @NonNull @Override protected ActivityInspectionWarehouseBinding viewBindingInflate(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, boolean attachToRoot) { @@ -185,6 +188,7 @@ public class InspectionWarehousingFragment extends BaseFragment { String dayTime = DateTimeHelper.format(date, "yyyy-MM-dd"); @@ -196,9 +200,11 @@ public class InspectionWarehousingFragment extends BaseFragment goodsList = new ArrayList<>(); List supplierList = new ArrayList<>(); String pageType; + @Override protected void initViews() { showDatePickerDialog(date -> { @@ -236,7 +242,7 @@ public class InspectionWarehousingFragment extends BaseFragment name.getMaterialName() != null && !name.getMaterialName().isEmpty()) + .collect(Collectors.toList()); pages = goodsList.stream() - .map(GoodsBean::getMaterialName).toArray(String[]::new); + .map(GoodsBean::getMaterialName) + .filter(name -> name != null && !name.isEmpty()) + .toArray(String[]::new); pagesList = List.of(pages); MultiPage[] multiPages = MultiPage.fromList(pagesList); mDestPage = multiPages[0]; TAB_COUNT = pagesList.size(); + mCurrentItemCount = TAB_COUNT; mTabSegment = findViewById(R.id.tabSegment); mContentViewPager = findViewById(R.id.contentViewPager); @@ -287,7 +298,7 @@ public class InspectionWarehousingFragment extends BaseFragment XToastUtils.error(msg)); - } - }); + isUpload = true; + List emptyGoods = goodsList.stream() + .filter(goods -> StringHelper.isEmptyAndNull(goods.getWeight()) || Double.parseDouble(goods.getWeight()) <= 0) + .collect(Collectors.toList()); + List filteredGoods = goodsList.stream() + .filter(goods -> !StringHelper.isEmptyAndNull(goods.getWeight()) && Double.parseDouble(goods.getWeight()) > 0) + .collect(Collectors.toList()); + Log.e(TAG, "Empty Goods: " + emptyGoods); + boolean isPass = handlerResultParameters(filteredGoods); + if (!isPass) { + isUpload = false; + return; + } + if (!emptyGoods.isEmpty()) { + new MaterialDialog.Builder(requireContext()) + .iconRes(R.drawable.icon_tip) + .limitIconToDefaultSize() + .title("提示") + .content("当前有部分货品信息未填写完整,是否继续入库?") + .positiveText("继续") + .onPositive((poDialog,s) -> uploadEnterWarehouseData(new ArrayList<>(filteredGoods), new ResponseCallBack() { + @Override + public void onSuccess() { + isUpload = false; + XToastUtils.success("入库成功!"); + Bundle bundle = new Bundle(); + bundle.putString("pageType", pageType); + CompleteWarehouseEntryFragment completeWarehouseEntryFragment = new CompleteWarehouseEntryFragment(); + completeWarehouseEntryFragment.setArguments(bundle); + switchPage(completeWarehouseEntryFragment, CompleteWarehouseEntryFragment.class); + poDialog.dismiss(); + } + + @Override + public void onFail(String msg) { + isUpload = false; + requireActivity().runOnUiThread(() -> XToastUtils.error(msg)); + } + })) + .negativeText("取消") + .onNegative((dialog, which) -> { + isUpload = false; + dialog.dismiss(); + }) + .progress(true, 0) + .progressIndeterminateStyle(false) + .cancelable(false) + .show(); + }else { + isUpload = false; + } } }); binding.saveData.setOnClickListener(new DebounceClickListener() { @@ -412,10 +459,9 @@ public class InspectionWarehousingFragment extends BaseFragment selectedGoods) { - List filteredGoods = selectedGoods.stream() - .filter(goods -> !StringHelper.isEmptyAndNull(goods.getWeight()) && Double.parseDouble(goods.getWeight()) > 0) - .collect(Collectors.toList()); + + private boolean handlerResultParameters(List filteredGoods) { + // for (GoodsBean goods : selectedGoods) { // Log.e(TAG, "Selected Goods: " + goods); // if (StringHelper.isEmptyAndNull(goods.getWeight()) || Double.parseDouble(goods.getWeight()) <= 0) { @@ -427,11 +473,10 @@ public class InspectionWarehousingFragment extends BaseFragment(filteredGoods); return true; } @@ -473,8 +518,9 @@ public class InspectionWarehousingFragment extends BaseFragment{ + ThreadPoolManager.getExecutor().execute(() -> { String url = WorkConfig.getBaseUrl() + "/ims_supplier/list?pageSize=" + 1000 + "&pageNum=" + 1; String result = service.httpGet(url, requireContext()); Log.i(TAG, "result==" + result); @@ -487,7 +533,8 @@ public class InspectionWarehousingFragment extends BaseFragment { String url = WorkConfig.getBaseUrl() + "/ims_warehouse_info/list?pageSize=" + 1000 + "&pageNum=" + 1; String result = service.httpGet(url, requireContext()); @@ -497,16 +544,17 @@ public class InspectionWarehousingFragment extends BaseFragment>() { }.getType()); requireActivity().runOnUiThread(() -> { - if (isAdded()) { - binding.warehouseSpinner.setItems(warehouseList); - binding.warehouseSpinner.setSelectedIndex(0); // 默认选择第一个仓库 - } else { - Log.e(TAG, "Binding or warehouseSpinner is not available."); - } + if (isAdded()) { + binding.warehouseSpinner.setItems(warehouseList); + binding.warehouseSpinner.setSelectedIndex(0); // 默认选择第一个仓库 + } else { + Log.e(TAG, "Binding or warehouseSpinner is not available."); + } }); } }); } + private void initInboundSpinners() { //设置入库类型选择器 List inboundTypes = new ArrayList<>(); @@ -523,8 +571,9 @@ public class InspectionWarehousingFragment extends BaseFragment{ + + private void initMaterialRequesterSpinner() { + ThreadPoolManager.getExecutor().execute(() -> { String url = WorkConfig.getPrefixesUrl() + "/system/user/list?pageSize=" + 1000 + "&pageNum=" + 1 + "&roleIds=125"; String result = service.httpGet(url, requireContext()); Log.i(TAG, "result==" + result); @@ -535,7 +584,8 @@ public class InspectionWarehousingFragment extends BaseFragment>() {}.getType()); + userList = new Gson().fromJson(json, new TypeToken>() { + }.getType()); Log.e(TAG, "User List: " + userList); if (!userList.isEmpty()) { requireActivity().runOnUiThread(() -> { @@ -546,6 +596,7 @@ public class InspectionWarehousingFragment extends BaseFragment= originalNum.doubleValue()) { enterWeight.setText(unInspectedGoodsNum + ""); @@ -835,14 +886,14 @@ public class InspectionWarehousingFragment extends BaseFragment= originalNum.doubleValue()) { enterWeight.setText(unInspectedGoodsNum + ""); @@ -917,7 +968,7 @@ public class InspectionWarehousingFragment extends BaseFragment getResult() { if (goodsList.isEmpty()) { XToastUtils.error("没有可用的货品数据"); @@ -990,6 +1042,12 @@ public class InspectionWarehousingFragment extends BaseFragment 0) { + dialog.dismiss(); + XToastUtils.warning("生产日期不能大于到期日期"); + return; + } if (subtotal.getText().toString().isEmpty()) { dialog.dismiss(); XToastUtils.warning("小计不能为空"); @@ -1236,6 +1294,7 @@ public class InspectionWarehousingFragment extends BaseFragment XToastUtils.success("图片上传成功!")); + requireActivity().runOnUiThread(() -> XToastUtils.success("图片上传成功!")); } else { requireActivity().runOnUiThread(() -> XToastUtils.error("图片上传失败,请重试!")); @@ -1349,7 +1408,6 @@ public class InspectionWarehousingFragment extends BaseFragment { @Override @@ -1446,7 +1504,9 @@ public class InspectionWarehousingFragment extends BaseFragment userList = new ArrayList<>(); List warehouseList = new ArrayList<>(); String pageType; - String fetchMaterialCode,fetchId; + String fetchMaterialCode, fetchId; String fetchDetailId; + @NonNull @Override protected ActivityInspectionWarehouseBinding viewBindingInflate(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, boolean attachToRoot) { return ActivityInspectionWarehouseBinding.inflate(inflater, container, attachToRoot); } + List goodsList = new ArrayList<>(); @Override @@ -185,7 +189,7 @@ public class InspectionWarehousingOutFragment extends BaseFragment name.getMaterialName() != null && !name.getMaterialName().isEmpty()) + .collect(Collectors.toList()); pages = goodsList.stream() - .map(GoodsBean::getMaterialName).toArray(String[]::new); + .map(GoodsBean::getMaterialName) + .filter(name -> name != null && !name.isEmpty()) + .toArray(String[]::new); pagesList = List.of(pages); MultiPage[] multiPages = MultiPage.fromList(pagesList); mDestPage = multiPages[0]; @@ -235,7 +243,7 @@ public class InspectionWarehousingOutFragment extends BaseFragment { String url = WorkConfig.getBaseUrl() + "/ims_warehouse_info/list?pageSize=" + 1000 + "&pageNum=" + 1; String result = service.httpGet(url, requireContext()); @@ -264,6 +273,7 @@ public class InspectionWarehousingOutFragment extends BaseFragment inboundTypes = new ArrayList<>(); @@ -281,8 +291,9 @@ public class InspectionWarehousingOutFragment extends BaseFragment{ + + private void initMaterialRequesterSpinner() { + ThreadPoolManager.getExecutor().execute(() -> { String url = WorkConfig.getPrefixesUrl() + "/system/user/list?pageSize=" + 1000 + "&pageNum=" + 1 + "&roleIds=124"; String result = service.httpGet(url, requireContext()); Log.i(TAG, "result==" + result); @@ -293,11 +304,12 @@ public class InspectionWarehousingOutFragment extends BaseFragment>() {}.getType()); + userList = new Gson().fromJson(json, new TypeToken>() { + }.getType()); Log.e(TAG, "User List: " + userList); if (!userList.isEmpty()) { requireActivity().runOnUiThread(() -> { - if (isAdded()){ + if (isAdded()) { binding.enterPersonSpinner.setItems(userList); } }); @@ -306,6 +318,7 @@ public class InspectionWarehousingOutFragment extends BaseFragment goods.getMaterialName().equals(pages[currentTabIndex])) .findFirst() @@ -497,7 +504,7 @@ public class InspectionWarehousingOutFragment extends BaseFragment XToastUtils.error(msg)); @@ -535,12 +543,13 @@ public class InspectionWarehousingOutFragment extends BaseFragment selectedGoods) { List filteredGoods = new ArrayList<>(selectedGoods.stream() .filter(goods -> !StringHelper.isEmptyAndNull(goods.getFetchNum()) && Double.parseDouble(goods.getFetchNum()) > 0) .collect(Collectors.toMap(GoodsBean::getMaterialCode, goods -> goods, (g1, g2) -> g1)) .values()); - if (filteredGoods.isEmpty()){ + if (filteredGoods.isEmpty()) { XToastUtils.info("请至少选择一个货品并进行重量!"); return false; } @@ -554,19 +563,31 @@ public class InspectionWarehousingOutFragment extends BaseFragment selectedGoods, ResponseCallBack callback) { + + private void uploadOutWarehouseData(List list, ResponseCallBack callback) { + Log.e(TAG, "Uploading Out Warehouse Data: " + list); + List selectedGoods = list.stream() + .map(goods -> { + Gson gson = new Gson(); + GoodsUploadBean goodsUploadBean = gson.fromJson(gson.toJson(goods), GoodsUploadBean.class); + goodsUploadBean.setTotalPrice(new BigDecimal(goodsUploadBean.getTotalPrice()).setScale(0, RoundingMode.DOWN).toPlainString()); + return goodsUploadBean; + }).collect(Collectors.toList()); + Log.e(TAG, "Uploading Out Warehouse Data: " + selectedGoods); ThreadPoolManager.getExecutor().execute(() -> { + JSONObject json = new JSONObject(); String url = WorkConfig.getBaseUrl() + "/ims_fetch_material/app/outInventory"; - if ("out".equals(pageType)){ + if ("out".equals(pageType)) { url = WorkConfig.getBaseUrl() + "/ims/out-inventory"; } + Log.e(TAG, "uploadOutWarehouseData url: " + url); BigDecimal totalNum = BigDecimal.ZERO; BigDecimal totalAmount = BigDecimal.ZERO; - for (GoodsBean goods : selectedGoods) { + for (GoodsUploadBean goods : selectedGoods) { totalNum = totalNum.add(new BigDecimal(goods.getWeight())); totalAmount = totalAmount.add(new BigDecimal(goods.getTotalPrice())); } - JSONObject json = new JSONObject(); + json.put("warehouseId", ((WarehouseBean) binding.warehouseSpinner.getSelectedItem()).getWarehouseId()); json.put("fetchUserId", ((MaterialRequesterBean) binding.enterPersonSpinner.getSelectedItem()).getUserId()); json.put("outDate", DateTimeHelper.getTime()); @@ -597,6 +618,7 @@ public class InspectionWarehousingOutFragment extends BaseFragment { GoodsBean goodsBean = goodsList.stream() .filter(goods -> goods.getMaterialName().equals(mDestPage.getDisplayName())) @@ -724,21 +752,21 @@ public class InspectionWarehousingOutFragment extends BaseFragment 0) { enterWeight.setText(num.getText().toString()); weightView.setText(String.valueOf(weight * 2)); - }else{ + } else { enterWeight.setText(String.valueOf(weight * 2)); weightView.setText(String.valueOf(weight * 2)); } - } else{ + } else { BigDecimal unInspectedGoodsNum = new BigDecimal(goodsBean.getTotalQualifiedNum()).subtract(new BigDecimal(goodsBean.getOutCount())); BigDecimal rate = BigDecimal.valueOf(100).subtract(new BigDecimal(paramSettingInfo.getWeighDownwardRatio())).divide(BigDecimal.valueOf(100)); - BigDecimal originalNum = unInspectedGoodsNum.multiply(rate); - Log.e(TAG,"unInspectedGoodsNum=" + unInspectedGoodsNum); - Log.e(TAG,"weight=" + weight); - Log.e(TAG,"originalNum=" + originalNum); + BigDecimal originalNum = unInspectedGoodsNum.multiply(rate); + Log.e(TAG, "unInspectedGoodsNum=" + unInspectedGoodsNum); + Log.e(TAG, "weight=" + weight); + Log.e(TAG, "originalNum=" + originalNum); if (weight * 2 >= originalNum.doubleValue()) { enterWeight.setText(unInspectedGoodsNum + ""); weightView.setText(unInspectedGoodsNum + ""); @@ -748,26 +776,26 @@ public class InspectionWarehousingOutFragment extends BaseFragment 0) { enterWeight.setText(num.getText().toString()); weightView.setText(String.valueOf(weight)); - }else{ + } else { enterWeight.setText(String.valueOf(weight)); weightView.setText(String.valueOf(weight)); } - }else{ + } else { BigDecimal unInspectedGoodsNum = new BigDecimal(goodsBean.getMaterialTotalNum()).subtract(new BigDecimal(goodsBean.getOutCount())); BigDecimal rate = BigDecimal.valueOf(100).subtract(new BigDecimal(paramSettingInfo.getWeighDownwardRatio())).divide(BigDecimal.valueOf(100)); - BigDecimal originalNum = unInspectedGoodsNum.multiply(rate); - Log.e(TAG,"goodsBean=" + goodsBean); - Log.e(TAG,"getTotalQualifiedNum=" + goodsBean.getTotalQualifiedNum()); - Log.e(TAG,"getOutCount=" + goodsBean.getOutCount()); - Log.e(TAG,"unInspectedGoodsNum=" + unInspectedGoodsNum); - Log.e(TAG,"weight=" + weight); - Log.e(TAG,"originalNum=" + originalNum); + BigDecimal originalNum = unInspectedGoodsNum.multiply(rate); + Log.e(TAG, "goodsBean=" + goodsBean); + Log.e(TAG, "getTotalQualifiedNum=" + goodsBean.getTotalQualifiedNum()); + Log.e(TAG, "getOutCount=" + goodsBean.getOutCount()); + Log.e(TAG, "unInspectedGoodsNum=" + unInspectedGoodsNum); + Log.e(TAG, "weight=" + weight); + Log.e(TAG, "originalNum=" + originalNum); if (weight >= originalNum.doubleValue()) { enterWeight.setText(unInspectedGoodsNum + ""); weightView.setText(unInspectedGoodsNum + ""); @@ -815,26 +843,19 @@ public class InspectionWarehousingOutFragment extends BaseFragment goods.getMaterialName().equals(mDestPage.getDisplayName())) - .findFirst() - .orElse(null); - if (goodsBean != null) { - BigDecimal priceValue = new BigDecimal(goodsBean.getUnitPrice()); - BigDecimal subtotalValue = roundedWeight.multiply(priceValue).divide(BigDecimal.valueOf(100)); - subtotal.setText(subtotalValue.toString()); - } + tvWeightView.setText(roundedWeight.toString()); } else { XToastUtils.warning("请先称重"); } @@ -845,6 +866,7 @@ public class InspectionWarehousingOutFragment extends BaseFragment getResult() { if (goodsList.isEmpty()) { XToastUtils.error("没有可用的货品数据"); @@ -861,6 +883,7 @@ public class InspectionWarehousingOutFragment extends BaseFragment goods.getMaterialName().equals(mDestPage.getDisplayName())) .findFirst() @@ -880,7 +903,15 @@ public class InspectionWarehousingOutFragment extends BaseFragment 0) { + dialog.dismiss(); + XToastUtils.warning("出库重量不能大于库存数量"); + return; + } //对list进行数据更新 goodsBean.setWeight(weightView.getText().toString()); goodsBean.setDeliveryNum(weightView.getText().toString()); @@ -979,10 +1010,15 @@ public class InspectionWarehousingOutFragment extends BaseFragment XToastUtils.success("图片上传成功!")); + requireActivity().runOnUiThread(() -> XToastUtils.success("图片上传成功!")); } else { requireActivity().runOnUiThread(() -> XToastUtils.error("图片上传失败,请重试!")); @@ -1228,7 +1265,6 @@ public class InspectionWarehousingOutFragment extends BaseFragment { @Override @@ -1325,7 +1361,9 @@ public class InspectionWarehousingOutFragment extends BaseFragment goodsBeanList, DocumentOutBean bean) { BigDecimal outNum = new BigDecimal(bean.getOutNum()); BigDecimal totalNum = new BigDecimal(bean.getTotalNum()); + Log.e(TAG, "outNum==" + outNum); + Log.e(TAG, "totalNum==" + totalNum); if (totalNum.compareTo(outNum) == 0) { requireActivity().runOnUiThread(() -> { if (isDestroyed || !isAdded()) return; XToastUtils.success("当前领料单暂无可出库货品!"); }); + }else{ + //展示出入库单据信息 + showOutDetail(bean, goodsBeanList); } - Log.e(TAG, "outNum==" + outNum); - Log.e(TAG, "totalNum==" + totalNum); - //展示出入库单据信息 - showOutDetail(bean, goodsBeanList); } private void showOutDetail(DocumentOutBean bean, List goodsList) { diff --git a/app/src/main/java/com/bonus/canteen/fragment/commonFragment/ProductSelectionFragment.java b/app/src/main/java/com/bonus/canteen/fragment/commonFragment/ProductSelectionFragment.java index 415a711..ea6e5a8 100644 --- a/app/src/main/java/com/bonus/canteen/fragment/commonFragment/ProductSelectionFragment.java +++ b/app/src/main/java/com/bonus/canteen/fragment/commonFragment/ProductSelectionFragment.java @@ -412,4 +412,12 @@ public class ProductSelectionFragment extends BaseFragment