bug修改

This commit is contained in:
jjLv 2025-08-07 16:22:50 +08:00
parent ef6fcf9df6
commit c338ca4314
6 changed files with 248 additions and 117 deletions

View File

@ -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<ActivityInspecti
List<MaterialRequesterBean> userList = new ArrayList<>();
List<WarehouseBean> 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<ActivityInspecti
.setType(true, true, true, false, false, false)
.build();
}
private void showDatePickerDialog1(OnDateSelectedListener listener) {
mDatePicker1 = new TimePickerBuilder(requireContext(), (date, v) -> {
String dayTime = DateTimeHelper.format(date, "yyyy-MM-dd");
@ -196,9 +200,11 @@ public class InspectionWarehousingFragment extends BaseFragment<ActivityInspecti
.setType(true, true, true, false, false, false)
.build();
}
List<GoodsBean> goodsList = new ArrayList<>();
List<SupplierBean> supplierList = new ArrayList<>();
String pageType;
@Override
protected void initViews() {
showDatePickerDialog(date -> {
@ -236,7 +242,7 @@ public class InspectionWarehousingFragment extends BaseFragment<ActivityInspecti
selectedGoods = args.getString("selectedGoods");
pageType = args.getString("pageType");
relateOrderGoodsId = args.getString("relateOrderGoodsId");
if (StringHelper.isEmptyAndNull(pageType)){
if (StringHelper.isEmptyAndNull(pageType)) {
pageType = ENTER; // 默认值为"enter"
}
}
@ -248,13 +254,18 @@ public class InspectionWarehousingFragment extends BaseFragment<ActivityInspecti
}
// 解析selectedGoods为GoodsBean列表
goodsList = JSON.parseArray(selectedGoods, GoodsBean.class);
goodsList = goodsList.stream().filter(name -> 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<ActivityInspecti
Log.e(TAG, "SurfaceView is null for page: " + mDestPage.getDisplayName());
}
}
}catch (Exception e){
} catch (Exception e) {
Log.e(TAG, "Error in onLayoutChange: ", e);
}
});
@ -296,6 +307,7 @@ public class InspectionWarehousingFragment extends BaseFragment<ActivityInspecti
initMaterialRequesterSpinner();
mHandler.postDelayed(this::initScale, 2000);
}
@Override
protected void initListeners() {
binding.clear.setOnClickListener(new DebounceClickListener() {
@ -384,25 +396,60 @@ public class InspectionWarehousingFragment extends BaseFragment<ActivityInspecti
binding.confirmEnterWarehouse.setOnClickListener(new DebounceClickListener() {
@Override
public void onDebouncedClick(View v) {
boolean isPass = handlerResultParameters(goodsList);
if (!isPass) {
if (isUpload){
return;
}
uploadEnterWarehouseData(goodsList, new ResponseCallBack() {
isUpload = true;
List<GoodsBean> emptyGoods = goodsList.stream()
.filter(goods -> StringHelper.isEmptyAndNull(goods.getWeight()) || Double.parseDouble(goods.getWeight()) <= 0)
.collect(Collectors.toList());
List<GoodsBean> 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<ActivityInspecti
}
});
}
private boolean handlerResultParameters(List<GoodsBean> selectedGoods) {
List<GoodsBean> filteredGoods = selectedGoods.stream()
.filter(goods -> !StringHelper.isEmptyAndNull(goods.getWeight()) && Double.parseDouble(goods.getWeight()) > 0)
.collect(Collectors.toList());
private boolean handlerResultParameters(List<GoodsBean> 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<ActivityInspecti
// return false;
// }
// }
if (filteredGoods.isEmpty()){
XToastUtils.info("至少选择一个货品并进行重量");
if (filteredGoods.isEmpty()) {
XToastUtils.info("先保存相关货品入库信息");
return false;
}
goodsList = new ArrayList<>(filteredGoods);
return true;
}
@ -473,8 +518,9 @@ public class InspectionWarehousingFragment extends BaseFragment<ActivityInspecti
});
}
private void initSupplierList(MaterialSpinner supplierSpinner) {
ThreadPoolManager.getExecutor().execute(() ->{
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<ActivityInspecti
}
});
}
private void initWarehouseSpinner(){
private void initWarehouseSpinner() {
ThreadPoolManager.getExecutor().execute(() -> {
String url = WorkConfig.getBaseUrl() + "/ims_warehouse_info/list?pageSize=" + 1000 + "&pageNum=" + 1;
String result = service.httpGet(url, requireContext());
@ -507,6 +554,7 @@ public class InspectionWarehousingFragment extends BaseFragment<ActivityInspecti
}
});
}
private void initInboundSpinners() {
//设置入库类型选择器
List<SpinnerBean> inboundTypes = new ArrayList<>();
@ -523,8 +571,9 @@ public class InspectionWarehousingFragment extends BaseFragment<ActivityInspecti
}
});
}
private void initMaterialRequesterSpinner(){
ThreadPoolManager.getExecutor().execute(() ->{
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<ActivityInspecti
}
String json = JSONObject.parseObject(result).getString("rows");
if (json != null && !json.isEmpty()) {
userList = new Gson().fromJson(json, new TypeToken<List<MaterialRequesterBean>>() {}.getType());
userList = new Gson().fromJson(json, new TypeToken<List<MaterialRequesterBean>>() {
}.getType());
Log.e(TAG, "User List: " + userList);
if (!userList.isEmpty()) {
requireActivity().runOnUiThread(() -> {
@ -546,6 +596,7 @@ public class InspectionWarehousingFragment extends BaseFragment<ActivityInspecti
}
});
}
private PagerAdapter mPagerAdapter = new PagerAdapter() {
@Override
public boolean isViewFromObject(@NonNull View view, @NonNull Object object) {
@ -623,14 +674,14 @@ public class InspectionWarehousingFragment extends BaseFragment<ActivityInspecti
price.setText(StringHelper.isEmptyAndNull(goodsBean.getUnitPrice()) ? "0" : new BigDecimal(goodsBean.getUnitPrice()).divide(BigDecimal.valueOf(100)).toString());
weight.setText("0");
enterWeight.setText("0");
if (!StringHelper.isEmptyAndNull(goodsBean.getSupplierName())){
if (!StringHelper.isEmptyAndNull(goodsBean.getSupplierName())) {
int index = supplierList.stream()
.map(SupplierBean::getSupplierName)
.collect(Collectors.toList())
.indexOf(goodsBean.getSupplierName());
// 设置供应商下拉框
supplierSpinner.setSelectedIndex(index);
}else{
} else {
supplierSpinner.setSelectedIndex(0); // 默认选择第一个供应商
}
@ -820,9 +871,9 @@ public class InspectionWarehousingFragment extends BaseFragment<ActivityInspecti
BigDecimal priceValue = new BigDecimal(goodsBean.getUnitPrice());
if (unit.getText().toString().equals("")) {
weightView.setText(String.valueOf(weight * 2));
if ("enter".equals(pageType)){
if ("enter".equals(pageType)) {
enterWeight.setText(String.valueOf(weight * 2));
}else{
} else {
BigDecimal rate = BigDecimal.valueOf(100).subtract(new BigDecimal(paramSettingInfo.getWeighDownwardRatio())).divide(BigDecimal.valueOf(100));
BigDecimal unInspectedGoodsNum = new BigDecimal(goodsBean.getTotalQualifiedNum()).subtract(new BigDecimal(goodsBean.getIntoNum()));
BigDecimal originalNum = unInspectedGoodsNum.multiply(rate);
@ -835,11 +886,11 @@ public class InspectionWarehousingFragment extends BaseFragment<ActivityInspecti
}
BigDecimal subtotalValue = new BigDecimal(enterWeight.getText().toString()).multiply(priceValue).divide(BigDecimal.valueOf(100));
subtotal.setText(subtotalValue + "");
}else{
} else {
weightView.setText(String.valueOf(weight));
if ("enter".equals(pageType)){
enterWeight.setText(String.valueOf(weight * 2));
}else{
if ("enter".equals(pageType)) {
enterWeight.setText(String.valueOf(weight));
} else {
BigDecimal rate = BigDecimal.valueOf(100).subtract(new BigDecimal(paramSettingInfo.getWeighDownwardRatio())).divide(BigDecimal.valueOf(100));
BigDecimal unInspectedGoodsNum = new BigDecimal(goodsBean.getTotalQualifiedNum()).subtract(new BigDecimal(goodsBean.getIntoNum()));
BigDecimal originalNum = unInspectedGoodsNum.multiply(rate);
@ -917,7 +968,7 @@ public class InspectionWarehousingFragment extends BaseFragment<ActivityInspecti
}
@SuppressLint("SetTextI18n")
public void roundOffWeight(){
public void roundOffWeight() {
if (mDestPage != null) {
View view = mPageMap.getOrDefault(mDestPage.getDisplayName(), null);
if (view != null) {
@ -947,6 +998,7 @@ public class InspectionWarehousingFragment extends BaseFragment<ActivityInspecti
Log.e(TAG, "Current page is null.");
}
}
public List<GoodsBean> getResult() {
if (goodsList.isEmpty()) {
XToastUtils.error("没有可用的货品数据");
@ -990,6 +1042,12 @@ public class InspectionWarehousingFragment extends BaseFragment<ActivityInspecti
XToastUtils.warning("请选择到期日期");
return;
}
//日期比对
if (DateTimeHelper.compareDate(productionDate.getText().toString(), dateTextView.getText().toString()) > 0) {
dialog.dismiss();
XToastUtils.warning("生产日期不能大于到期日期");
return;
}
if (subtotal.getText().toString().isEmpty()) {
dialog.dismiss();
XToastUtils.warning("小计不能为空");
@ -1236,6 +1294,7 @@ public class InspectionWarehousingFragment extends BaseFragment<ActivityInspecti
Log.e(TAG, "保存图片失败: " + e.getMessage());
}
}
/**
* 上传照片
* 使用OkHttpService上传图片到服务器
@ -1253,7 +1312,7 @@ public class InspectionWarehousingFragment extends BaseFragment<ActivityInspecti
if (!ObjectUtil.isEmpty(res)) {
JSONObject jsonObject = JSONObject.parseObject(res);
if (!jsonObject.containsKey("data")) {
if (jsonObject.getInteger("code") == 401){
if (jsonObject.getInteger("code") == 401) {
Intent intent = new Intent(requireActivity(), LoginActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(intent);
@ -1349,7 +1408,6 @@ public class InspectionWarehousingFragment extends BaseFragment<ActivityInspecti
}
// 尺寸比较器
class CompareSizesByArea implements Comparator<Size> {
@Override
@ -1446,7 +1504,9 @@ public class InspectionWarehousingFragment extends BaseFragment<ActivityInspecti
}
}
}
private MaterialDialog dialog;
/**
* 带圆形Loading的Dialog
*/

View File

@ -67,12 +67,14 @@ 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;
import com.bonus.canteen.db.entity.base.LoginInfo;
import com.bonus.canteen.db.entity.base.ParamSettingInfo;
import com.bonus.canteen.entity.GoodsBean;
import com.bonus.canteen.entity.GoodsUploadBean;
import com.bonus.canteen.entity.MaterialRequesterBean;
import com.bonus.canteen.entity.PhotoResponse;
import com.bonus.canteen.entity.SpinnerBean;
@ -165,13 +167,15 @@ public class InspectionWarehousingOutFragment extends BaseFragment<ActivityInspe
List<MaterialRequesterBean> userList = new ArrayList<>();
List<WarehouseBean> 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<GoodsBean> goodsList = new ArrayList<>();
@Override
@ -185,7 +189,7 @@ public class InspectionWarehousingOutFragment extends BaseFragment<ActivityInspe
fetchMaterialCode = args.getString("fetchMaterialCode");
fetchId = args.getString("fetchMaterialId");
fetchDetailId = args.getString("fetchDetailId");
if (StringHelper.isEmptyAndNull(pageType)){
if (StringHelper.isEmptyAndNull(pageType)) {
pageType = OUT;
}
binding.cancelEnterWarehouse.setText("取消出库");
@ -196,8 +200,12 @@ public class InspectionWarehousingOutFragment extends BaseFragment<ActivityInspe
return;
}
goodsList = JSON.parseArray(selectedGoods, GoodsBean.class);
goodsList = goodsList.stream().filter(name -> 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<ActivityInspe
Log.e(TAG, "SurfaceView is null for page: " + mDestPage.getDisplayName());
}
}
}catch (Exception e){
} catch (Exception e) {
Log.e(TAG, "Error in onLayoutChange: ", e);
}
});
@ -244,7 +252,8 @@ public class InspectionWarehousingOutFragment extends BaseFragment<ActivityInspe
initMaterialRequesterSpinner();
mHandler.postDelayed(this::initScale, 2000);
}
private void initWarehouseSpinner(){
private void initWarehouseSpinner() {
ThreadPoolManager.getExecutor().execute(() -> {
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<ActivityInspe
}
});
}
private void initOutboundSpinners() {
//设置入库类型选择器
List<SpinnerBean> inboundTypes = new ArrayList<>();
@ -281,8 +291,9 @@ public class InspectionWarehousingOutFragment extends BaseFragment<ActivityInspe
}
});
}
private void initMaterialRequesterSpinner(){
ThreadPoolManager.getExecutor().execute(() ->{
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<ActivityInspe
}
String json = JSONObject.parseObject(result).getString("rows");
if (json != null && !json.isEmpty()) {
userList = new Gson().fromJson(json, new TypeToken<List<MaterialRequesterBean>>() {}.getType());
userList = new Gson().fromJson(json, new TypeToken<List<MaterialRequesterBean>>() {
}.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<ActivityInspe
}
});
}
private PagerAdapter mPagerAdapter = new PagerAdapter() {
@Override
public boolean isViewFromObject(@NonNull View view, @NonNull Object object) {
@ -433,13 +446,7 @@ public class InspectionWarehousingOutFragment extends BaseFragment<ActivityInspe
View view = mPageMap.get(pages[currentTabIndex]);
if (view != null) {
TextView weightView = view.findViewById(R.id.weight);
TextView subtotal = view.findViewById(R.id.subtotal);
EditText dueDateEdit = view.findViewById(R.id.dueDate);
MaterialSpinner supplierSpinner = view.findViewById(R.id.supplier_spinner);
weightView.setText("0");
subtotal.setText("0");
dueDateEdit.setText("");
supplierSpinner.setSelectedIndex(0); // 重置为第一个供应商
GoodsBean goodsBean = goodsList.stream()
.filter(goods -> goods.getMaterialName().equals(pages[currentTabIndex]))
.findFirst()
@ -521,6 +528,7 @@ public class InspectionWarehousingOutFragment extends BaseFragment<ActivityInspe
completeWarehouseEntryFragment.setArguments(bundle);
switchPage(completeWarehouseEntryFragment, CompleteWarehouseEntryFragment.class);
}
@Override
public void onFail(String msg) {
requireActivity().runOnUiThread(() -> XToastUtils.error(msg));
@ -535,12 +543,13 @@ public class InspectionWarehousingOutFragment extends BaseFragment<ActivityInspe
}
});
}
private boolean handlerResultParameters(List<GoodsBean> selectedGoods) {
List<GoodsBean> 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<ActivityInspe
// }
return true;
}
private void uploadOutWarehouseData(List<GoodsBean> selectedGoods, ResponseCallBack callback) {
private void uploadOutWarehouseData(List<GoodsBean> list, ResponseCallBack callback) {
Log.e(TAG, "Uploading Out Warehouse Data: " + list);
List<GoodsUploadBean> 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<ActivityInspe
});
}
private void initScale() {
if (serialPort != null) {
serialPort.close();
@ -707,7 +729,13 @@ public class InspectionWarehousingOutFragment extends BaseFragment<ActivityInspe
if (mDestPage != null) {
View view = mPageMap.getOrDefault(mDestPage.getDisplayName(), null);
if (view != null) {
ParamSettingInfo paramSettingInfo = AppDatabase.getDatabase(requireContext()).parameterInfoDao().getOneInfo();
ParamSettingInfo paramSettingInfo;
try {
paramSettingInfo = AppDatabase.getDatabase(requireContext()).parameterInfoDao().getOneInfo();
} catch (Exception e) {
Log.e(TAG, "Error fetching parameter settings", e);
return;
}
requireActivity().runOnUiThread(() -> {
GoodsBean goodsBean = goodsList.stream()
.filter(goods -> goods.getMaterialName().equals(mDestPage.getDisplayName()))
@ -724,21 +752,21 @@ public class InspectionWarehousingOutFragment extends BaseFragment<ActivityInspe
TextView num = view.findViewById(R.id.num);
if (unit.getText().toString().equals("")) {
tvWeightView.setText(String.valueOf(weight * 2));
if ("out".equals(pageType)){
if ("out".equals(pageType)) {
if (new BigDecimal(weight * 2).compareTo(new BigDecimal(num.getText().toString())) > 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);
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<ActivityInspe
}
}
}else{
} else {
tvWeightView.setText(String.valueOf(weight));
if ("out".equals(pageType)){
if ("out".equals(pageType)) {
if (new BigDecimal(weight * 2).compareTo(new BigDecimal(num.getText().toString())) > 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);
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<ActivityInspe
XToastUtils.error("输出流未初始化");
}
}
public void roundOffWeight(){
public void roundOffWeight() {
if (mDestPage != null) {
View view = mPageMap.getOrDefault(mDestPage.getDisplayName(), null);
if (view != null) {
TextView weightView = view.findViewById(R.id.weight);
TextView subtotal = view.findViewById(R.id.subtotal);
TextView tvWeightView = view.findViewById(R.id.tv_weight);
if (!weightView.getText().toString().isEmpty()) {
double weight = Double.parseDouble(weightView.getText().toString());
BigDecimal roundedWeight = BigDecimal.valueOf(weight).setScale(0, RoundingMode.HALF_UP);
Log.e(TAG, "Rounded weight: " + roundedWeight);
weightView.setText(roundedWeight.toString());
GoodsBean goodsBean = goodsList.stream()
.filter(goods -> 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<ActivityInspe
Log.e(TAG, "Current page is null.");
}
}
public List<GoodsBean> getResult() {
if (goodsList.isEmpty()) {
XToastUtils.error("没有可用的货品数据");
@ -861,6 +883,7 @@ public class InspectionWarehousingOutFragment extends BaseFragment<ActivityInspe
if (view != null) {
TextView weightView = view.findViewById(R.id.weight);
TextView enterWeight = view.findViewById(R.id.enter_weight);
TextView num = view.findViewById(R.id.num);
GoodsBean goodsBean = goodsList.stream()
.filter(goods -> goods.getMaterialName().equals(mDestPage.getDisplayName()))
.findFirst()
@ -880,7 +903,15 @@ public class InspectionWarehousingOutFragment extends BaseFragment<ActivityInspe
XToastUtils.warning("称重结果必须大于0");
return;
}
Log.e(TAG, "WeightView: " + weightView.getText().toString());
Log.e(TAG, "EnterWeight: " + enterWeight.getText().toString());
Log.e(TAG, "Num: " + num.getText().toString());
if (new BigDecimal(weightView.getText().toString()).compareTo(new BigDecimal(enterWeight.getText().toString())) > 0) {
dialog.dismiss();
XToastUtils.warning("出库重量不能大于库存数量");
return;
}
//对list进行数据更新
goodsBean.setWeight(weightView.getText().toString());
goodsBean.setDeliveryNum(weightView.getText().toString());
@ -979,12 +1010,17 @@ public class InspectionWarehousingOutFragment extends BaseFragment<ActivityInspe
private void openCamera() {
if (isCameraOpen) return; // 防止重复打开
try {
if (ContextCompat.checkSelfPermission(requireContext(), Manifest.permission.CAMERA)
!= PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(requireActivity(),
new String[]{Manifest.permission.CAMERA}, REQUEST_CAMERA_PERMISSION);
return;
}
} catch (Exception e) {
Log.e(TAG, "请求相机权限失败: " + e.getMessage());
return;
}
CameraManager manager = (CameraManager) requireActivity().getSystemService(Context.CAMERA_SERVICE);
try {
@ -1115,6 +1151,7 @@ public class InspectionWarehousingOutFragment extends BaseFragment<ActivityInspe
Log.e(TAG, "保存图片失败: " + e.getMessage());
}
}
/**
* 上传照片
* 使用OkHttpService上传图片到服务器
@ -1132,7 +1169,7 @@ public class InspectionWarehousingOutFragment extends BaseFragment<ActivityInspe
if (!ObjectUtil.isEmpty(res)) {
JSONObject jsonObject = JSONObject.parseObject(res);
if (!jsonObject.containsKey("data")) {
if (jsonObject.getInteger("code") == 401){
if (jsonObject.getInteger("code") == 401) {
Intent intent = new Intent(requireActivity(), LoginActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(intent);
@ -1228,7 +1265,6 @@ public class InspectionWarehousingOutFragment extends BaseFragment<ActivityInspe
}
// 尺寸比较器
class CompareSizesByArea implements Comparator<Size> {
@Override
@ -1325,7 +1361,9 @@ public class InspectionWarehousingOutFragment extends BaseFragment<ActivityInspe
}
}
}
private MaterialDialog dialog;
/**
* 带圆形Loading的Dialog
*/

View File

@ -258,8 +258,8 @@ public class DocumentSelectionFragment extends BaseFragment<ActivityDocumentStro
jsonObject.put("pageNum", 1);
jsonObject.put("pageSize", 10);
jsonObject.put("ifAllInspect", 2);
jsonObject.put("endDateTime", DateTimeHelper.getNowDate() + " 00:00:00");
jsonObject.put("startDateTime", DateTimeHelper.getLastDate(-29) + " 23:59:59");
jsonObject.put("endDateTime", DateTimeHelper.getNowDate() + " 23:59:59");
jsonObject.put("startDateTime", DateTimeHelper.getLastDate(-29) + " 00:00:00");
String jsonString = jsonObject.toString();
Log.e(TAG, "jsonString==" + jsonString);
RequestBody body = RequestBody.create(mediaType, jsonString);
@ -418,17 +418,18 @@ public class DocumentSelectionFragment extends BaseFragment<ActivityDocumentStro
public void changeOutFragment(List<GoodsBean> 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("当前领料单暂无可出库货品!");
});
}
Log.e(TAG, "outNum==" + outNum);
Log.e(TAG, "totalNum==" + totalNum);
}else{
//展示出入库单据信息
showOutDetail(bean, goodsBeanList);
}
}
private void showOutDetail(DocumentOutBean bean, List<GoodsBean> goodsList) {
requireActivity().runOnUiThread(() -> {

View File

@ -412,4 +412,12 @@ public class ProductSelectionFragment extends BaseFragment<ActivityProductSelect
binding = null;
super.onDestroyView();
}
public void showToast(String text) {
if (isAdded()) {
XToastUtils.info(text);
} else {
Log.e(TAG, "showToast: Fragment is not added to the activity");
}
}
}

View File

@ -80,4 +80,18 @@ public class DateTimeHelper {
@SuppressLint("SimpleDateFormat") SimpleDateFormat sdf = new SimpleDateFormat("YYYY-MM-dd");
return sdf.format(calendar.getTime());
}
public static int compareDate(String start, String end) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
try {
Date startDate = sdf.parse(start);
Date endDate = sdf.parse(end);
if (startDate != null && endDate != null) {
return startDate.compareTo(endDate);
}
} catch (ParseException e) {
e.printStackTrace();
}
return 0;
}
}

View File

@ -23,6 +23,7 @@ import android.util.Base64;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.math.BigDecimal;
import java.nio.charset.Charset;
import java.util.Calendar;
import java.util.HashMap;
@ -44,6 +45,15 @@ public class StringHelper {
}
return false;
}
public static boolean isEmptyAndNullOrZero(String str) {
if (str == null || str.trim().equals("") || str.trim().equals("null")) {
return true;
}
if (new BigDecimal(str).compareTo(BigDecimal.ZERO) == 0) {
return true;
}
return false;
}
/**
* 验证手机格式